web-annotation-renderer 0.2.0 → 0.3.0
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.
- package/ai-tools.js +11 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -27
- package/dist/index.js.map +1 -1
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +1 -1
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +1 -1
- package/dist/index16.cjs +1 -1
- package/dist/index16.cjs.map +1 -1
- package/dist/index16.js +215 -31
- package/dist/index16.js.map +1 -1
- package/dist/index17.cjs +2 -0
- package/dist/index17.cjs.map +1 -0
- package/dist/index17.js +44 -0
- package/dist/index17.js.map +1 -0
- package/dist/index18.cjs +2 -0
- package/dist/index18.cjs.map +1 -0
- package/dist/index18.js +40 -0
- package/dist/index18.js.map +1 -0
- package/dist/index19.cjs +2 -0
- package/dist/index19.cjs.map +1 -0
- package/dist/index19.js +41 -0
- package/dist/index19.js.map +1 -0
- package/dist/index20.cjs +2 -0
- package/dist/index20.cjs.map +1 -0
- package/dist/index20.js +50 -0
- package/dist/index20.js.map +1 -0
- package/dist/index21.cjs +2 -0
- package/dist/index21.cjs.map +1 -0
- package/dist/index21.js +35 -0
- package/dist/index21.js.map +1 -0
- package/dist/index22.cjs +2 -0
- package/dist/index22.cjs.map +1 -0
- package/dist/index22.js +8 -0
- package/dist/index22.js.map +1 -0
- package/package.json +6 -1
package/ai-tools.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Tools Entry Point
|
|
3
|
+
*
|
|
4
|
+
* Provides AI annotation tools without PDF renderer dependencies.
|
|
5
|
+
* This file only re-exports the tools modules to avoid DOMMatrix issues in Node.js.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { annotationTools, getAnnotationTools } from './dist/index16.js';
|
|
9
|
+
export { createHighlight } from './dist/index18.js';
|
|
10
|
+
export { createText } from './dist/index19.js';
|
|
11
|
+
export { createInk } from './dist/index20.js';
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index2.cjs"),a=require("./index3.cjs"),o=require("./index4.cjs"),i=require("./index5.cjs"),l=require("./index6.cjs"),c=require("./index7.cjs"),s=require("./index8.cjs"),u=require("./index9.cjs"),d=require("./index10.cjs"),g=require("./index11.cjs"),e=require("./index12.cjs"),q=require("./index13.cjs"),y=require("./index14.cjs"),T=require("./index15.cjs"),r=require("./index16.cjs"),t=require("./index17.cjs"),h=require("./index18.cjs"),A=require("./index19.cjs"),x=require("./index20.cjs"),L="0.3.0",f="web-annotation-renderer";exports.AnnotationRenderer=n.AnnotationRenderer;exports.PDFRenderer=a.PDFRenderer;exports.LayerManager=o.LayerManager;exports.TimelineSync=i.TimelineSync;exports.BaseLayer=l.default;exports.HighlightLayer=c.default;exports.TextLayer=s.default;exports.DrawingLayer=u.default;exports.coordinateUtils=d;exports.viewportUtils=g;exports.extractAllBlocks=e.extractAllBlocks;exports.extractMultiplePages=e.extractMultiplePages;exports.extractPDFBlocks=e.extractAllBlocks;exports.normalizeAnnotationArray=q.normalizeAnnotationArray;exports.TypeValidators=y;exports.AnnotPdf=T.default;exports.annotationTools=r.annotationTools;exports.getAnnotationTools=r.getAnnotationTools;exports.handleToolCall=t.handleToolCall;exports.handleToolCalls=t.handleToolCalls;exports.createHighlight=h.createHighlight;exports.createText=A.createText;exports.createInk=x.createInk;exports.LIB_NAME=f;exports.VERSION=L;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["/**\n * @ai-annotator/renderer - Public API\n *\n * Single entry point for the Dynamic PDF Annotation Renderer library.\n * Exports all core subsystems, layers, utilities, and types.\n *\n * @module @ai-annotator/renderer\n */\n\n// ============================================================================\n// Core Rendering Engine\n// ============================================================================\n\n// Import statements\nimport { AnnotationRenderer } from './core/AnnotationRenderer.js';\nimport { PDFRenderer } from './core/PDFRenderer.js';\nimport { LayerManager } from './core/LayerManager.js';\nimport { TimelineSync } from './core/TimelineSync.js';\n\n// Export statements\nexport { AnnotationRenderer };\nexport { PDFRenderer };\nexport { LayerManager };\nexport { TimelineSync };\n\n// ============================================================================\n// Annotation Layers\n// ============================================================================\n\n// Framework-agnostic layer classes\n// BaseLayer: Abstract base class for creating custom layers\n// HighlightLayer, TextLayer, DrawingLayer: Built-in layer implementations\n\nimport BaseLayer from './layers/BaseLayer.js';\nimport HighlightLayer from './layers/HighlightLayer.js';\nimport TextLayer from './layers/TextLayer.js';\nimport DrawingLayer from './layers/DrawingLayer.js';\n\nexport { BaseLayer };\nexport { HighlightLayer };\nexport { TextLayer };\nexport { DrawingLayer };\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\nimport * as coordinateUtils from './utils/coordinateUtils.js';\nimport * as viewportUtils from './utils/viewportUtils.js';\n\nexport { coordinateUtils };\nexport { viewportUtils };\n\n// Future: colorUtils, validators\n// import * as colorUtils from './utils/colorUtils.js';\n// export { colorUtils };\n\n// ============================================================================\n// PDF Extraction Utilities\n// ============================================================================\n\n/**\n * PDF data extraction utilities for text and image blocks\n * Uses PDF.js getOperatorList() for efficient metadata extraction without rendering\n */\nimport { extractAllBlocks, extractMultiplePages } from './utils/pdfExtractor.js';\n\nexport { extractAllBlocks };\nexport { extractMultiplePages };\n\n// Alias for backwards compatibility and API consistency\nexport { extractAllBlocks as extractPDFBlocks };\n\n// ============================================================================\n// Type Definitions & Validators\n// ============================================================================\n\n// Type definitions in src/types/annotations.js\n\n/**\n * Type Validators - Optional data normalization\n *\n * Import separately to use defensive normalization for annotation data.\n * These validators are standalone utilities that do not modify the core system.\n */\nexport { normalizeAnnotationArray } from './types/validators.js';\n\n// Namespace export for all validator utilities\nexport * as TypeValidators from './types/index.js';\n\n// ============================================================================\n// Framework Adapters\n// ============================================================================\n// Declarative framework-specific wrappers for AnnotationRenderer\n// These provide idiomatic APIs for React, Vue, and other frameworks\n\n/**\n * React adapter component for declarative PDF annotation rendering\n * @see {@link AnnotPdf}\n */\nexport { AnnotPdf } from './adapters/index.js';\n\n// Future framework adapters will be exported here:\n// export { VuePdfViewer } from './adapters/index.js';\n// export { SveltePdfViewer } from './adapters/index.js';\n\n// ============================================================================\n// Package Metadata\n// ============================================================================\n\n/**\n * Library version\n * @constant {string}\n */\nexport const VERSION = '0.
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["/**\n * @ai-annotator/renderer - Public API\n *\n * Single entry point for the Dynamic PDF Annotation Renderer library.\n * Exports all core subsystems, layers, utilities, and types.\n *\n * @module @ai-annotator/renderer\n */\n\n// ============================================================================\n// Core Rendering Engine\n// ============================================================================\n\n// Import statements\nimport { AnnotationRenderer } from './core/AnnotationRenderer.js';\nimport { PDFRenderer } from './core/PDFRenderer.js';\nimport { LayerManager } from './core/LayerManager.js';\nimport { TimelineSync } from './core/TimelineSync.js';\n\n// Export statements\nexport { AnnotationRenderer };\nexport { PDFRenderer };\nexport { LayerManager };\nexport { TimelineSync };\n\n// ============================================================================\n// Annotation Layers\n// ============================================================================\n\n// Framework-agnostic layer classes\n// BaseLayer: Abstract base class for creating custom layers\n// HighlightLayer, TextLayer, DrawingLayer: Built-in layer implementations\n\nimport BaseLayer from './layers/BaseLayer.js';\nimport HighlightLayer from './layers/HighlightLayer.js';\nimport TextLayer from './layers/TextLayer.js';\nimport DrawingLayer from './layers/DrawingLayer.js';\n\nexport { BaseLayer };\nexport { HighlightLayer };\nexport { TextLayer };\nexport { DrawingLayer };\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\nimport * as coordinateUtils from './utils/coordinateUtils.js';\nimport * as viewportUtils from './utils/viewportUtils.js';\n\nexport { coordinateUtils };\nexport { viewportUtils };\n\n// Future: colorUtils, validators\n// import * as colorUtils from './utils/colorUtils.js';\n// export { colorUtils };\n\n// ============================================================================\n// PDF Extraction Utilities\n// ============================================================================\n\n/**\n * PDF data extraction utilities for text and image blocks\n * Uses PDF.js getOperatorList() for efficient metadata extraction without rendering\n */\nimport { extractAllBlocks, extractMultiplePages } from './utils/pdfExtractor.js';\n\nexport { extractAllBlocks };\nexport { extractMultiplePages };\n\n// Alias for backwards compatibility and API consistency\nexport { extractAllBlocks as extractPDFBlocks };\n\n// ============================================================================\n// Type Definitions & Validators\n// ============================================================================\n\n// Type definitions in src/types/annotations.js\n\n/**\n * Type Validators - Optional data normalization\n *\n * Import separately to use defensive normalization for annotation data.\n * These validators are standalone utilities that do not modify the core system.\n */\nexport { normalizeAnnotationArray } from './types/validators.js';\n\n// Namespace export for all validator utilities\nexport * as TypeValidators from './types/index.js';\n\n// ============================================================================\n// Framework Adapters\n// ============================================================================\n// Declarative framework-specific wrappers for AnnotationRenderer\n// These provide idiomatic APIs for React, Vue, and other frameworks\n\n/**\n * React adapter component for declarative PDF annotation rendering\n * @see {@link AnnotPdf}\n */\nexport { AnnotPdf } from './adapters/index.js';\n\n// Future framework adapters will be exported here:\n// export { VuePdfViewer } from './adapters/index.js';\n// export { SveltePdfViewer } from './adapters/index.js';\n\n// ============================================================================\n// AI Tools for Annotation Generation\n// ============================================================================\n\n/**\n * AI-powered annotation generation tools\n *\n * Provides OpenAI-compatible function calling schemas and handlers\n * for generating PDF annotations with AI models.\n *\n * @see {@link module:ai-tools}\n */\nexport {\n annotationTools,\n getAnnotationTools,\n handleToolCall,\n handleToolCalls,\n createHighlight,\n createText,\n createInk\n} from './ai-tools/index.js';\n\n// ============================================================================\n// Package Metadata\n// ============================================================================\n\n/**\n * Library version\n * @constant {string}\n */\nexport const VERSION = '0.3.0';\n\n/**\n * Library name\n * @constant {string}\n */\nexport const LIB_NAME = 'web-annotation-renderer';\n"],"names":["VERSION","LIB_NAME"],"mappings":"+kBAwIaA,EAAU,QAMVC,EAAW"}
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,48 @@
|
|
|
1
1
|
import { AnnotationRenderer as x } from "./index2.js";
|
|
2
|
-
import { PDFRenderer as
|
|
2
|
+
import { PDFRenderer as f } from "./index3.js";
|
|
3
3
|
import { LayerManager as i } from "./index4.js";
|
|
4
|
-
import { TimelineSync as
|
|
5
|
-
import { default as
|
|
6
|
-
import { default as
|
|
7
|
-
import { default as
|
|
8
|
-
import { default as
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
11
|
-
import { extractAllBlocks as
|
|
12
|
-
import { normalizeAnnotationArray as
|
|
13
|
-
import * as
|
|
14
|
-
import { default as
|
|
15
|
-
|
|
4
|
+
import { TimelineSync as c } from "./index5.js";
|
|
5
|
+
import { default as g } from "./index6.js";
|
|
6
|
+
import { default as A } from "./index7.js";
|
|
7
|
+
import { default as h } from "./index8.js";
|
|
8
|
+
import { default as L } from "./index9.js";
|
|
9
|
+
import * as o from "./index10.js";
|
|
10
|
+
import * as r from "./index11.js";
|
|
11
|
+
import { extractAllBlocks as k, extractMultiplePages as P, extractAllBlocks as w } from "./index12.js";
|
|
12
|
+
import { normalizeAnnotationArray as I } from "./index13.js";
|
|
13
|
+
import * as e from "./index14.js";
|
|
14
|
+
import { default as R } from "./index15.js";
|
|
15
|
+
import { annotationTools as E, getAnnotationTools as F } from "./index16.js";
|
|
16
|
+
import { handleToolCall as N, handleToolCalls as S } from "./index17.js";
|
|
17
|
+
import { createHighlight as V } from "./index18.js";
|
|
18
|
+
import { createText as v } from "./index19.js";
|
|
19
|
+
import { createInk as O } from "./index20.js";
|
|
20
|
+
const t = "0.3.0", a = "web-annotation-renderer";
|
|
16
21
|
export {
|
|
17
|
-
|
|
22
|
+
R as AnnotPdf,
|
|
18
23
|
x as AnnotationRenderer,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
g as BaseLayer,
|
|
25
|
+
L as DrawingLayer,
|
|
26
|
+
A as HighlightLayer,
|
|
22
27
|
a as LIB_NAME,
|
|
23
28
|
i as LayerManager,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
f as PDFRenderer,
|
|
30
|
+
h as TextLayer,
|
|
31
|
+
c as TimelineSync,
|
|
32
|
+
e as TypeValidators,
|
|
28
33
|
t as VERSION,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
E as annotationTools,
|
|
35
|
+
o as coordinateUtils,
|
|
36
|
+
V as createHighlight,
|
|
37
|
+
O as createInk,
|
|
38
|
+
v as createText,
|
|
39
|
+
k as extractAllBlocks,
|
|
40
|
+
P as extractMultiplePages,
|
|
41
|
+
w as extractPDFBlocks,
|
|
42
|
+
F as getAnnotationTools,
|
|
43
|
+
N as handleToolCall,
|
|
44
|
+
S as handleToolCalls,
|
|
45
|
+
I as normalizeAnnotationArray,
|
|
46
|
+
r as viewportUtils
|
|
35
47
|
};
|
|
36
48
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["/**\n * @ai-annotator/renderer - Public API\n *\n * Single entry point for the Dynamic PDF Annotation Renderer library.\n * Exports all core subsystems, layers, utilities, and types.\n *\n * @module @ai-annotator/renderer\n */\n\n// ============================================================================\n// Core Rendering Engine\n// ============================================================================\n\n// Import statements\nimport { AnnotationRenderer } from './core/AnnotationRenderer.js';\nimport { PDFRenderer } from './core/PDFRenderer.js';\nimport { LayerManager } from './core/LayerManager.js';\nimport { TimelineSync } from './core/TimelineSync.js';\n\n// Export statements\nexport { AnnotationRenderer };\nexport { PDFRenderer };\nexport { LayerManager };\nexport { TimelineSync };\n\n// ============================================================================\n// Annotation Layers\n// ============================================================================\n\n// Framework-agnostic layer classes\n// BaseLayer: Abstract base class for creating custom layers\n// HighlightLayer, TextLayer, DrawingLayer: Built-in layer implementations\n\nimport BaseLayer from './layers/BaseLayer.js';\nimport HighlightLayer from './layers/HighlightLayer.js';\nimport TextLayer from './layers/TextLayer.js';\nimport DrawingLayer from './layers/DrawingLayer.js';\n\nexport { BaseLayer };\nexport { HighlightLayer };\nexport { TextLayer };\nexport { DrawingLayer };\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\nimport * as coordinateUtils from './utils/coordinateUtils.js';\nimport * as viewportUtils from './utils/viewportUtils.js';\n\nexport { coordinateUtils };\nexport { viewportUtils };\n\n// Future: colorUtils, validators\n// import * as colorUtils from './utils/colorUtils.js';\n// export { colorUtils };\n\n// ============================================================================\n// PDF Extraction Utilities\n// ============================================================================\n\n/**\n * PDF data extraction utilities for text and image blocks\n * Uses PDF.js getOperatorList() for efficient metadata extraction without rendering\n */\nimport { extractAllBlocks, extractMultiplePages } from './utils/pdfExtractor.js';\n\nexport { extractAllBlocks };\nexport { extractMultiplePages };\n\n// Alias for backwards compatibility and API consistency\nexport { extractAllBlocks as extractPDFBlocks };\n\n// ============================================================================\n// Type Definitions & Validators\n// ============================================================================\n\n// Type definitions in src/types/annotations.js\n\n/**\n * Type Validators - Optional data normalization\n *\n * Import separately to use defensive normalization for annotation data.\n * These validators are standalone utilities that do not modify the core system.\n */\nexport { normalizeAnnotationArray } from './types/validators.js';\n\n// Namespace export for all validator utilities\nexport * as TypeValidators from './types/index.js';\n\n// ============================================================================\n// Framework Adapters\n// ============================================================================\n// Declarative framework-specific wrappers for AnnotationRenderer\n// These provide idiomatic APIs for React, Vue, and other frameworks\n\n/**\n * React adapter component for declarative PDF annotation rendering\n * @see {@link AnnotPdf}\n */\nexport { AnnotPdf } from './adapters/index.js';\n\n// Future framework adapters will be exported here:\n// export { VuePdfViewer } from './adapters/index.js';\n// export { SveltePdfViewer } from './adapters/index.js';\n\n// ============================================================================\n// Package Metadata\n// ============================================================================\n\n/**\n * Library version\n * @constant {string}\n */\nexport const VERSION = '0.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["/**\n * @ai-annotator/renderer - Public API\n *\n * Single entry point for the Dynamic PDF Annotation Renderer library.\n * Exports all core subsystems, layers, utilities, and types.\n *\n * @module @ai-annotator/renderer\n */\n\n// ============================================================================\n// Core Rendering Engine\n// ============================================================================\n\n// Import statements\nimport { AnnotationRenderer } from './core/AnnotationRenderer.js';\nimport { PDFRenderer } from './core/PDFRenderer.js';\nimport { LayerManager } from './core/LayerManager.js';\nimport { TimelineSync } from './core/TimelineSync.js';\n\n// Export statements\nexport { AnnotationRenderer };\nexport { PDFRenderer };\nexport { LayerManager };\nexport { TimelineSync };\n\n// ============================================================================\n// Annotation Layers\n// ============================================================================\n\n// Framework-agnostic layer classes\n// BaseLayer: Abstract base class for creating custom layers\n// HighlightLayer, TextLayer, DrawingLayer: Built-in layer implementations\n\nimport BaseLayer from './layers/BaseLayer.js';\nimport HighlightLayer from './layers/HighlightLayer.js';\nimport TextLayer from './layers/TextLayer.js';\nimport DrawingLayer from './layers/DrawingLayer.js';\n\nexport { BaseLayer };\nexport { HighlightLayer };\nexport { TextLayer };\nexport { DrawingLayer };\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\nimport * as coordinateUtils from './utils/coordinateUtils.js';\nimport * as viewportUtils from './utils/viewportUtils.js';\n\nexport { coordinateUtils };\nexport { viewportUtils };\n\n// Future: colorUtils, validators\n// import * as colorUtils from './utils/colorUtils.js';\n// export { colorUtils };\n\n// ============================================================================\n// PDF Extraction Utilities\n// ============================================================================\n\n/**\n * PDF data extraction utilities for text and image blocks\n * Uses PDF.js getOperatorList() for efficient metadata extraction without rendering\n */\nimport { extractAllBlocks, extractMultiplePages } from './utils/pdfExtractor.js';\n\nexport { extractAllBlocks };\nexport { extractMultiplePages };\n\n// Alias for backwards compatibility and API consistency\nexport { extractAllBlocks as extractPDFBlocks };\n\n// ============================================================================\n// Type Definitions & Validators\n// ============================================================================\n\n// Type definitions in src/types/annotations.js\n\n/**\n * Type Validators - Optional data normalization\n *\n * Import separately to use defensive normalization for annotation data.\n * These validators are standalone utilities that do not modify the core system.\n */\nexport { normalizeAnnotationArray } from './types/validators.js';\n\n// Namespace export for all validator utilities\nexport * as TypeValidators from './types/index.js';\n\n// ============================================================================\n// Framework Adapters\n// ============================================================================\n// Declarative framework-specific wrappers for AnnotationRenderer\n// These provide idiomatic APIs for React, Vue, and other frameworks\n\n/**\n * React adapter component for declarative PDF annotation rendering\n * @see {@link AnnotPdf}\n */\nexport { AnnotPdf } from './adapters/index.js';\n\n// Future framework adapters will be exported here:\n// export { VuePdfViewer } from './adapters/index.js';\n// export { SveltePdfViewer } from './adapters/index.js';\n\n// ============================================================================\n// AI Tools for Annotation Generation\n// ============================================================================\n\n/**\n * AI-powered annotation generation tools\n *\n * Provides OpenAI-compatible function calling schemas and handlers\n * for generating PDF annotations with AI models.\n *\n * @see {@link module:ai-tools}\n */\nexport {\n annotationTools,\n getAnnotationTools,\n handleToolCall,\n handleToolCalls,\n createHighlight,\n createText,\n createInk\n} from './ai-tools/index.js';\n\n// ============================================================================\n// Package Metadata\n// ============================================================================\n\n/**\n * Library version\n * @constant {string}\n */\nexport const VERSION = '0.3.0';\n\n/**\n * Library name\n * @constant {string}\n */\nexport const LIB_NAME = 'web-annotation-renderer';\n"],"names":["VERSION","LIB_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;AAwIY,MAACA,IAAU,SAMVC,IAAW;"}
|
package/dist/index13.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./index21.cjs");function a(t,n,o,s,e){let i=t;return typeof t=="string"&&(i=parseFloat(t)),typeof i!="number"||isNaN(i)?(e.push(`[${o}]: Field "${s}" invalid value "${t}", using default ${n}`),n):i<0?(e.push(`[${o}]: Field "${s}" value ${i} below range [0,1], clamping to 0`),0):i>1?(e.push(`[${o}]: Field "${s}" value ${i} exceeds range [0,1], clamping to 1`),1):i}function d(t,n,o,s){if(typeof t!="string"||t.trim().length===0)return s.push(`[${o}]: Invalid color format "${t}", using default ${n}`),n;const e=t.trim(),i=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/,r=/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*[\d.]+\s*)?\)$/,u=["red","blue","green","yellow","black","white","gray","grey","orange","purple","pink","brown","transparent"],h=i.test(e),$=r.test(e),A=u.includes(e.toLowerCase());return h||$||A?e:(s.push(`[${o}]: Invalid color format "${t}", using default ${n}`),n)}function f(t,n,o,s,e){let i=t;return typeof t=="string"&&(i=parseFloat(t)),typeof i!="number"||isNaN(i)||i<=0?(e.push(`[${o}]: Field "${s}" invalid value "${t}", using default ${n}`),n):i}function c(t,n,o){const s={};if(typeof t.id!="string"||t.id.trim().length===0){const e=Date.now(),i=Math.random().toString(36).substr(2,9);s.id=`anno-${e}-${i}`,o.push(`[${s.id}]: Auto-generated ID (original was missing or invalid)`)}else s.id=t.id.trim();return s.type=t.type,typeof t.page!="number"||t.page<1?(n.push(`[${s.id}]: Field "page" invalid value "${t.page}", using default ${l.BASE_DEFAULTS.page}`),s.page=l.BASE_DEFAULTS.page):s.page=Math.floor(t.page),typeof t.start!="number"||t.start<0?(n.push(`[${s.id}]: Field "start" invalid value "${t.start}", using default ${l.BASE_DEFAULTS.start}`),s.start=l.BASE_DEFAULTS.start):s.start=t.start,typeof t.end!="number"||t.end<0?(n.push(`[${s.id}]: Field "end" invalid value "${t.end}", using start value ${s.start}`),s.end=s.start):t.end<s.start?(n.push(`[${s.id}]: Field "end" (${t.end}) less than start (${s.start}), clamping to start`),s.end=s.start):s.end=t.end,s}function T(t,n,o){return!t||typeof t!="object"?(o.push(`[${n}]: Invalid quad object, using default`),{x:.1,y:.1,w:.8,h:.05}):{x:a(t.x,.1,n,"quad.x",o),y:a(t.y,.1,n,"quad.y",o),w:a(t.w,.8,n,"quad.w",o),h:a(t.h,.05,n,"quad.h",o)}}function p(t,n,o,s){const e={...t};n.mode!=="quads"?(o.push(`[${t.id}]: Field "mode" invalid value "${n.mode}", using default "${l.HIGHLIGHT_DEFAULTS.mode}"`),e.mode=l.HIGHLIGHT_DEFAULTS.mode):e.mode=n.mode,!Array.isArray(n.quads)||n.quads.length===0?(o.push(`[${t.id}]: Field "quads" missing or empty, using default`),e.quads=l.HIGHLIGHT_DEFAULTS.quads):e.quads=n.quads.map((r,u)=>T(r,t.id,o));const i=l.HIGHLIGHT_DEFAULTS.style.color;return!n.style||typeof n.style!="object"?(o.push(`[${t.id}]: Field "style" missing or invalid, using default`),e.style={color:i}):e.style={color:d(n.style.color,i,t.id,o)},e}function m(t,n,o,s){const e={...t};typeof n.content!="string"||n.content.trim().length===0?(o.push(`[${t.id}]: Field "content" missing or empty, using default "${l.TEXT_DEFAULTS.content}"`),e.content=l.TEXT_DEFAULTS.content):e.content=n.content,e.x=a(n.x,l.TEXT_DEFAULTS.x,t.id,"x",o),e.y=a(n.y,l.TEXT_DEFAULTS.y,t.id,"y",o),e.w=a(n.w,l.TEXT_DEFAULTS.w,t.id,"w",o),e.h=a(n.h,l.TEXT_DEFAULTS.h,t.id,"h",o);const i=l.TEXT_DEFAULTS.style.bg,r=l.TEXT_DEFAULTS.style.color;return!n.style||typeof n.style!="object"?(o.push(`[${t.id}]: Field "style" missing or invalid, using defaults`),e.style={bg:i,color:r}):e.style={bg:d(n.style.bg,i,t.id,o),color:d(n.style.color,r,t.id,o)},e}function F(t,n,o){return!t||typeof t!="object"?(o.push(`[${n}]: Invalid point object, using default`),{t:0,x:.1,y:.1}):{t:a(t.t,0,n,"point.t",o),x:a(t.x,.1,n,"point.x",o),y:a(t.y,.1,n,"point.y",o)}}function E(t,n,o){if(!t||typeof t!="object")return o.push(`[${n}]: Invalid stroke object, using default`),l.INK_DEFAULTS.strokes[0];const s={color:d(t.color,l.INK_DEFAULTS.strokes[0].color,n,o),size:f(t.size,l.INK_DEFAULTS.strokes[0].size,n,"stroke.size",o)};return!Array.isArray(t.points)||t.points.length===0?(o.push(`[${n}]: Stroke missing points array, using default`),s.points=l.INK_DEFAULTS.strokes[0].points):s.points=t.points.map(e=>F(e,n,o)),s}function g(t,n,o,s){const e={...t};return!Array.isArray(n.strokes)||n.strokes.length===0?(o.push(`[${t.id}]: Field "strokes" missing or empty, using default`),e.strokes=l.INK_DEFAULTS.strokes):e.strokes=n.strokes.map(i=>E(i,t.id,o)),e}function y(t,n){const o=[],s=[];if(!t||typeof t!="object")return{annotation:null,warnings:[],info:[],critical:`Annotation at index ${n}: Not a valid object`};if(typeof t.type!="string"||t.type.trim().length===0)return{annotation:null,warnings:[],info:[],critical:`Annotation at index ${n}: Missing or invalid type field`};const e=t.type.trim(),i=c(t,o,s);let r;if(e==="highlight")r=p(i,t,o);else if(e==="text")r=m(i,t,o);else if(e==="ink")r=g(i,t,o);else return{annotation:null,warnings:[],info:[],critical:`Annotation at index ${n}: Unsupported type "${e}"`};return{annotation:r,warnings:o,info:s,critical:null}}function z(t,n={}){n.skipInvalid;const o=n.warnInConsole!==!1,s=n.onWarning||null,e={normalized:[],warnings:[],info:[],skipped:[]};if(!Array.isArray(t)){const i="normalizeAnnotationArray: Input is not an array, returning empty result";return e.warnings.push(i),o&&console.warn(`[Annotation Normalizer] ${i}`),e}return t.forEach((i,r)=>{if(i==null){e.skipped.push({index:r,annotation:i,reason:"Annotation is null or undefined"});return}const u=y(i,r);if(u.critical){e.skipped.push({index:r,annotation:i,reason:u.critical}),o&&console.error(`[Annotation Normalizer] ${u.critical}`);return}e.normalized.push(u.annotation),e.warnings.push(...u.warnings),e.info.push(...u.info)}),o&&(e.warnings.length>0||e.info.length>0||e.skipped.length>0)&&(console.group("[Annotation Normalizer] Validation Summary"),e.normalized.length>0&&console.info(`✓ Normalized ${e.normalized.length} annotation(s)`),e.skipped.length>0&&(console.error(`✗ Skipped ${e.skipped.length} annotation(s)`),e.skipped.forEach(i=>{console.error(` Index ${i.index}: ${i.reason}`)})),e.warnings.length>0&&(console.warn(`⚠ ${e.warnings.length} warning(s):`),e.warnings.forEach(i=>console.warn(` ${i}`))),e.info.length>0&&(console.info(`ℹ ${e.info.length} info message(s):`),e.info.forEach(i=>console.info(` ${i}`))),console.groupEnd()),s&&typeof s=="function"&&s(e),e}exports.normalizeAnnotation=y;exports.normalizeAnnotationArray=z;exports.normalizeBaseFields=c;exports.normalizeColor=d;exports.normalizeCoordinate=a;exports.normalizeHighlight=p;exports.normalizeInk=g;exports.normalizePositiveNumber=f;exports.normalizeText=m;
|
|
2
2
|
//# sourceMappingURL=index13.cjs.map
|
package/dist/index13.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HIGHLIGHT_DEFAULTS as f, TEXT_DEFAULTS as a, INK_DEFAULTS as d, BASE_DEFAULTS as p } from "./
|
|
1
|
+
import { HIGHLIGHT_DEFAULTS as f, TEXT_DEFAULTS as a, INK_DEFAULTS as d, BASE_DEFAULTS as p } from "./index21.js";
|
|
2
2
|
function r(t, n, o, s, e) {
|
|
3
3
|
let i = t;
|
|
4
4
|
return typeof t == "string" && (i = parseFloat(t)), typeof i != "number" || isNaN(i) ? (e.push(
|
package/dist/index14.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index13.cjs"),e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index13.cjs"),e=require("./index21.cjs");exports.normalizeAnnotation=o.normalizeAnnotation;exports.normalizeAnnotationArray=o.normalizeAnnotationArray;exports.normalizeBaseFields=o.normalizeBaseFields;exports.normalizeColor=o.normalizeColor;exports.normalizeCoordinate=o.normalizeCoordinate;exports.normalizeHighlight=o.normalizeHighlight;exports.normalizeInk=o.normalizeInk;exports.normalizePositiveNumber=o.normalizePositiveNumber;exports.normalizeText=o.normalizeText;exports.BASE_DEFAULTS=e.BASE_DEFAULTS;exports.HIGHLIGHT_DEFAULTS=e.HIGHLIGHT_DEFAULTS;exports.INK_DEFAULTS=e.INK_DEFAULTS;exports.TEXT_DEFAULTS=e.TEXT_DEFAULTS;
|
|
2
2
|
//# sourceMappingURL=index14.cjs.map
|
package/dist/index14.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizeAnnotation as e, normalizeAnnotationArray as i, normalizeBaseFields as n, normalizeColor as a, normalizeCoordinate as l, normalizeHighlight as m, normalizeInk as t, normalizePositiveNumber as z, normalizeText as A } from "./index13.js";
|
|
2
|
-
import { BASE_DEFAULTS as E, HIGHLIGHT_DEFAULTS as F, INK_DEFAULTS as L, TEXT_DEFAULTS as S } from "./
|
|
2
|
+
import { BASE_DEFAULTS as E, HIGHLIGHT_DEFAULTS as F, INK_DEFAULTS as L, TEXT_DEFAULTS as S } from "./index21.js";
|
|
3
3
|
export {
|
|
4
4
|
E as BASE_DEFAULTS,
|
|
5
5
|
F as HIGHLIGHT_DEFAULTS,
|
package/dist/index16.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=[{type:"function",function:{name:"create_highlight_annotation",description:"Create a highlight annotation at specified coordinates on the PDF page. Use this to emphasize important text or regions. Highlights are rectangular regions that can span multiple lines.",parameters:{type:"object",properties:{quads:{type:"array",description:"Array of rectangular regions defining the highlight areas. Each quad is an object with normalized coordinates (0-1): {x, y, w, h}. Multiple quads can be used for multi-line highlights.",items:{type:"object",properties:{x:{type:"number",description:"Normalized x position (0 = left, 1 = right)",minimum:0,maximum:1},y:{type:"number",description:"Normalized y position (0 = top, 1 = bottom)",minimum:0,maximum:1},w:{type:"number",description:"Normalized width (0-1)",minimum:0,maximum:1},h:{type:"number",description:"Normalized height (0-1)",minimum:0,maximum:1}},required:["x","y","w","h"]},minItems:1},color:{type:"string",description:"Highlight color in rgba format (e.g., 'rgba(255, 255, 0, 0.3)'). Default is semi-transparent yellow. Use rgba for transparency control.",default:"rgba(255, 255, 0, 0.3)"},page:{type:"integer",description:"Page number (1-indexed) where the annotation appears",minimum:1},sentence_ref:{type:"string",description:"Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization",pattern:"^S\\d+$"}},required:["quads","page","sentence_ref"]}}},{type:"function",function:{name:"create_text_annotation",description:"Create a text box annotation with explanatory content. Use this to add clarifying notes, definitions, or explanations. Text boxes have background and appear as overlays.",parameters:{type:"object",properties:{content:{type:"string",description:"The text content of the annotation",minLength:1,maxLength:500},x:{type:"number",description:"Normalized x position (0 = left edge, 1 = right edge)",minimum:0,maximum:1},y:{type:"number",description:"Normalized y position (0 = top edge, 1 = bottom edge)",minimum:0,maximum:1},w:{type:"number",description:"Normalized width (0-1) of the text box",minimum:0,maximum:1},h:{type:"number",description:"Normalized height (0-1) of the text box",minimum:0,maximum:1},page:{type:"integer",description:"Page number (1-indexed) where the annotation appears",minimum:1},textColor:{type:"string",description:"Text color in hex format (e.g., '#000000' for black). Default is dark gray.",default:"#1f2937"},bgColor:{type:"string",description:"Background color in rgba format (e.g., 'rgba(255, 255, 255, 0.9)'). Default is semi-transparent white.",default:"rgba(255, 255, 255, 0.9)"},sentence_ref:{type:"string",description:"Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization",pattern:"^S\\d+$"}},required:["content","x","y","w","h","page","sentence_ref"]}}},{type:"function",function:{name:"create_ink_annotation",description:"Create a freehand drawing annotation with custom strokes. Use this to draw arrows, circles, underlines, or other visual markers. Each stroke can have its own color and width.",parameters:{type:"object",properties:{strokes:{type:"array",description:"Array of stroke objects. Each stroke defines a path with points that have time offsets for progressive drawing animation.",items:{type:"object",properties:{color:{type:"string",description:"Stroke color in hex format (e.g., '#FF0000' for red)",default:"#1f2937"},size:{type:"number",description:"Stroke width in pixels",minimum:1,maximum:10,default:3},points:{type:"array",description:"Array of points defining the stroke path. Each point has normalized coordinates (x, y) and a time offset (t) from 0 to stroke duration for progressive animation.",items:{type:"object",properties:{t:{type:"number",description:"Time offset in seconds from annotation start. Points are drawn progressively based on this value.",minimum:0},x:{type:"number",description:"Normalized x position (0-1)",minimum:0,maximum:1},y:{type:"number",description:"Normalized y position (0-1)",minimum:0,maximum:1}},required:["t","x","y"]},minItems:2}},required:["points"]},minItems:1},page:{type:"integer",description:"Page number (1-indexed) where the annotation appears",minimum:1},sentence_ref:{type:"string",description:"Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization",pattern:"^S\\d+$"}},required:["strokes","page","sentence_ref"]}}}];function o(e=[]){if(!Array.isArray(e)||e.length===0)return[];const n={highlight:"create_highlight_annotation",text:"create_text_annotation",ink:"create_ink_annotation"},r=e.map(t=>n[t]).filter(Boolean);return i.filter(t=>r.includes(t.function.name))}exports.annotationTools=i;exports.getAnnotationTools=o;
|
|
2
2
|
//# sourceMappingURL=index16.cjs.map
|
package/dist/index16.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index16.cjs","sources":["../src/types/defaults.js"],"sourcesContent":["/**\n * Default Values for Annotation Normalization\n *\n * This module defines default values used when annotation fields are missing\n * or invalid. These defaults ensure annotations render visibly and safely.\n *\n * @module types/defaults\n */\n\n/**\n * Default values for base annotation fields (common to all types)\n *\n * @constant {Object}\n * @property {number} page - Default page number (first page)\n * @property {number} start - Default start time (display immediately)\n * @property {number} end - Default end time (static display, no animation)\n */\nexport const BASE_DEFAULTS = {\n page: 1,\n start: 0,\n end: 0\n};\n\n/**\n * Default values for highlight annotations\n *\n * Creates a visible yellow highlight near the top of the page.\n *\n * @constant {Object}\n * @property {string} mode - Highlight mode (only 'quads' supported)\n * @property {Array<Object>} quads - Default rectangular regions\n * @property {Object} style - Default styling\n */\nexport const HIGHLIGHT_DEFAULTS = {\n mode: 'quads',\n quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],\n style: { color: 'rgba(255, 255, 0, 0.3)' }\n};\n\n/**\n * Default values for text annotations\n *\n * Creates a visible text box in the top-left with placeholder content.\n *\n * @constant {Object}\n * @property {string} content - Placeholder text\n * @property {number} x - Normalized x position (10% from left)\n * @property {number} y - Normalized y position (10% from top)\n * @property {number} w - Normalized width (30% of page width)\n * @property {number} h - Normalized height (10% of page height)\n * @property {Object} style - Default styling with white background and black text\n */\nexport const TEXT_DEFAULTS = {\n content: '[No content]',\n x: 0.1,\n y: 0.1,\n w: 0.3,\n h: 0.1,\n style: {\n bg: 'rgba(255, 255, 255, 0.9)',\n color: '#000000'\n }\n};\n\n/**\n * Default values for ink annotations\n *\n * Creates a visible diagonal line in dark gray.\n *\n * @constant {Object}\n * @property {Array<Object>} strokes - Default stroke with two points\n */\nexport const INK_DEFAULTS = {\n strokes: [{\n color: '#1f2937',\n size: 3,\n points: [\n { t: 0, x: 0.1, y: 0.1 },\n { t: 1, x: 0.2, y: 0.2 }\n ]\n }]\n};\n"],"names":["BASE_DEFAULTS","HIGHLIGHT_DEFAULTS","TEXT_DEFAULTS","INK_DEFAULTS"],"mappings":"gFAiBY,MAACA,EAAgB,CAC3B,KAAM,EACN,MAAO,EACP,IAAK,CACP,EAYaC,EAAqB,CAChC,KAAM,QACN,MAAO,CAAC,CAAE,EAAG,GAAK,EAAG,GAAK,EAAG,GAAK,EAAG,IAAM,EAC3C,MAAO,CAAE,MAAO,wBAAwB,CAC1C,EAeaC,EAAgB,CAC3B,QAAS,eACT,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,MAAO,CACL,GAAI,2BACJ,MAAO,SACX,CACA,EAUaC,EAAe,CAC1B,QAAS,CAAC,CACR,MAAO,UACP,KAAM,EACN,OAAQ,CACN,CAAE,EAAG,EAAG,EAAG,GAAK,EAAG,EAAG,EACtB,CAAE,EAAG,EAAG,EAAG,GAAK,EAAG,EAAG,CAC5B,CACA,CAAG,CACH"}
|
|
1
|
+
{"version":3,"file":"index16.cjs","sources":["../src/ai-tools/openai/schemas.js"],"sourcesContent":["/**\n * OpenAI Tool Schemas for PDF Annotation Generation\n *\n * Provides OpenAI-compatible function calling schemas for creating PDF annotations.\n * These schemas define the structure and parameters for AI-generated annotations.\n * Compatible with web-annotation-renderer library format.\n *\n * @module ai-tools/openai/schemas\n */\n\n/**\n * Complete set of annotation tools for OpenAI function calling\n *\n * Export this array to the OpenAI API's `tools` parameter to enable\n * AI-generated annotations.\n *\n * @constant {Array<Object>}\n * @example\n * ```javascript\n * import { annotationTools } from 'web-annotation-renderer/ai-tools';\n *\n * const response = await openai.chat.completions.create({\n * model: \"gpt-4\",\n * messages: [...],\n * tools: annotationTools\n * });\n * ```\n */\nexport const annotationTools = [\n {\n type: \"function\",\n function: {\n name: \"create_highlight_annotation\",\n description: \"Create a highlight annotation at specified coordinates on the PDF page. Use this to emphasize important text or regions. Highlights are rectangular regions that can span multiple lines.\",\n parameters: {\n type: \"object\",\n properties: {\n quads: {\n type: \"array\",\n description: \"Array of rectangular regions defining the highlight areas. Each quad is an object with normalized coordinates (0-1): {x, y, w, h}. Multiple quads can be used for multi-line highlights.\",\n items: {\n type: \"object\",\n properties: {\n x: {\n type: \"number\",\n description: \"Normalized x position (0 = left, 1 = right)\",\n minimum: 0,\n maximum: 1\n },\n y: {\n type: \"number\",\n description: \"Normalized y position (0 = top, 1 = bottom)\",\n minimum: 0,\n maximum: 1\n },\n w: {\n type: \"number\",\n description: \"Normalized width (0-1)\",\n minimum: 0,\n maximum: 1\n },\n h: {\n type: \"number\",\n description: \"Normalized height (0-1)\",\n minimum: 0,\n maximum: 1\n }\n },\n required: [\"x\", \"y\", \"w\", \"h\"]\n },\n minItems: 1\n },\n color: {\n type: \"string\",\n description: \"Highlight color in rgba format (e.g., 'rgba(255, 255, 0, 0.3)'). Default is semi-transparent yellow. Use rgba for transparency control.\",\n default: \"rgba(255, 255, 0, 0.3)\"\n },\n page: {\n type: \"integer\",\n description: \"Page number (1-indexed) where the annotation appears\",\n minimum: 1\n },\n sentence_ref: {\n type: \"string\",\n description: \"Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization\",\n pattern: \"^S\\\\d+$\"\n }\n },\n required: [\"quads\", \"page\", \"sentence_ref\"]\n }\n }\n },\n {\n type: \"function\",\n function: {\n name: \"create_text_annotation\",\n description: \"Create a text box annotation with explanatory content. Use this to add clarifying notes, definitions, or explanations. Text boxes have background and appear as overlays.\",\n parameters: {\n type: \"object\",\n properties: {\n content: {\n type: \"string\",\n description: \"The text content of the annotation\",\n minLength: 1,\n maxLength: 500\n },\n x: {\n type: \"number\",\n description: \"Normalized x position (0 = left edge, 1 = right edge)\",\n minimum: 0,\n maximum: 1\n },\n y: {\n type: \"number\",\n description: \"Normalized y position (0 = top edge, 1 = bottom edge)\",\n minimum: 0,\n maximum: 1\n },\n w: {\n type: \"number\",\n description: \"Normalized width (0-1) of the text box\",\n minimum: 0,\n maximum: 1\n },\n h: {\n type: \"number\",\n description: \"Normalized height (0-1) of the text box\",\n minimum: 0,\n maximum: 1\n },\n page: {\n type: \"integer\",\n description: \"Page number (1-indexed) where the annotation appears\",\n minimum: 1\n },\n textColor: {\n type: \"string\",\n description: \"Text color in hex format (e.g., '#000000' for black). Default is dark gray.\",\n default: \"#1f2937\"\n },\n bgColor: {\n type: \"string\",\n description: \"Background color in rgba format (e.g., 'rgba(255, 255, 255, 0.9)'). Default is semi-transparent white.\",\n default: \"rgba(255, 255, 255, 0.9)\"\n },\n sentence_ref: {\n type: \"string\",\n description: \"Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization\",\n pattern: \"^S\\\\d+$\"\n }\n },\n required: [\"content\", \"x\", \"y\", \"w\", \"h\", \"page\", \"sentence_ref\"]\n }\n }\n },\n {\n type: \"function\",\n function: {\n name: \"create_ink_annotation\",\n description: \"Create a freehand drawing annotation with custom strokes. Use this to draw arrows, circles, underlines, or other visual markers. Each stroke can have its own color and width.\",\n parameters: {\n type: \"object\",\n properties: {\n strokes: {\n type: \"array\",\n description: \"Array of stroke objects. Each stroke defines a path with points that have time offsets for progressive drawing animation.\",\n items: {\n type: \"object\",\n properties: {\n color: {\n type: \"string\",\n description: \"Stroke color in hex format (e.g., '#FF0000' for red)\",\n default: \"#1f2937\"\n },\n size: {\n type: \"number\",\n description: \"Stroke width in pixels\",\n minimum: 1,\n maximum: 10,\n default: 3\n },\n points: {\n type: \"array\",\n description: \"Array of points defining the stroke path. Each point has normalized coordinates (x, y) and a time offset (t) from 0 to stroke duration for progressive animation.\",\n items: {\n type: \"object\",\n properties: {\n t: {\n type: \"number\",\n description: \"Time offset in seconds from annotation start. Points are drawn progressively based on this value.\",\n minimum: 0\n },\n x: {\n type: \"number\",\n description: \"Normalized x position (0-1)\",\n minimum: 0,\n maximum: 1\n },\n y: {\n type: \"number\",\n description: \"Normalized y position (0-1)\",\n minimum: 0,\n maximum: 1\n }\n },\n required: [\"t\", \"x\", \"y\"]\n },\n minItems: 2\n }\n },\n required: [\"points\"]\n },\n minItems: 1\n },\n page: {\n type: \"integer\",\n description: \"Page number (1-indexed) where the annotation appears\",\n minimum: 1\n },\n sentence_ref: {\n type: \"string\",\n description: \"Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization\",\n pattern: \"^S\\\\d+$\"\n }\n },\n required: [\"strokes\", \"page\", \"sentence_ref\"]\n }\n }\n }\n];\n\n/**\n * Get filtered annotation tools based on enabled types\n *\n * @param {Array<string>} enabledTypes - Array of enabled tool types: ['highlight', 'text', 'ink']\n * @returns {Array<Object>} Filtered annotation tools\n * @example\n * ```javascript\n * // Only enable highlights and text notes\n * const tools = getAnnotationTools(['highlight', 'text']);\n * ```\n */\nexport function getAnnotationTools(enabledTypes = []) {\n if (!Array.isArray(enabledTypes) || enabledTypes.length === 0) {\n return [];\n }\n\n const typeMap = {\n 'highlight': 'create_highlight_annotation',\n 'text': 'create_text_annotation',\n 'ink': 'create_ink_annotation'\n };\n\n const enabledFunctionNames = enabledTypes\n .map(type => typeMap[type])\n .filter(Boolean);\n\n return annotationTools.filter(tool =>\n enabledFunctionNames.includes(tool.function.name)\n );\n}\n"],"names":["annotationTools","getAnnotationTools","enabledTypes","typeMap","enabledFunctionNames","type","tool"],"mappings":"gFA4BY,MAACA,EAAkB,CAC7B,CACE,KAAM,WACN,SAAU,CACR,KAAM,8BACN,YAAa,4LACb,WAAY,CACV,KAAM,SACN,WAAY,CACV,MAAO,CACL,KAAM,QACN,YAAa,2LACb,MAAO,CACL,KAAM,SACN,WAAY,CACV,EAAG,CACD,KAAM,SACN,YAAa,8CACb,QAAS,EACT,QAAS,CAC3B,EACgB,EAAG,CACD,KAAM,SACN,YAAa,8CACb,QAAS,EACT,QAAS,CAC3B,EACgB,EAAG,CACD,KAAM,SACN,YAAa,yBACb,QAAS,EACT,QAAS,CAC3B,EACgB,EAAG,CACD,KAAM,SACN,YAAa,0BACb,QAAS,EACT,QAAS,CAC3B,CACA,EACc,SAAU,CAAC,IAAK,IAAK,IAAK,GAAG,CAC3C,EACY,SAAU,CACtB,EACU,MAAO,CACL,KAAM,SACN,YAAa,0IACb,QAAS,wBACrB,EACU,KAAM,CACJ,KAAM,UACN,YAAa,uDACb,QAAS,CACrB,EACU,aAAc,CACZ,KAAM,SACN,YAAa,6EACb,QAAS,SACrB,CACA,EACQ,SAAU,CAAC,QAAS,OAAQ,cAAc,CAClD,CACA,CACA,EACE,CACE,KAAM,WACN,SAAU,CACR,KAAM,yBACN,YAAa,4KACb,WAAY,CACV,KAAM,SACN,WAAY,CACV,QAAS,CACP,KAAM,SACN,YAAa,qCACb,UAAW,EACX,UAAW,GACvB,EACU,EAAG,CACD,KAAM,SACN,YAAa,wDACb,QAAS,EACT,QAAS,CACrB,EACU,EAAG,CACD,KAAM,SACN,YAAa,wDACb,QAAS,EACT,QAAS,CACrB,EACU,EAAG,CACD,KAAM,SACN,YAAa,yCACb,QAAS,EACT,QAAS,CACrB,EACU,EAAG,CACD,KAAM,SACN,YAAa,0CACb,QAAS,EACT,QAAS,CACrB,EACU,KAAM,CACJ,KAAM,UACN,YAAa,uDACb,QAAS,CACrB,EACU,UAAW,CACT,KAAM,SACN,YAAa,8EACb,QAAS,SACrB,EACU,QAAS,CACP,KAAM,SACN,YAAa,yGACb,QAAS,0BACrB,EACU,aAAc,CACZ,KAAM,SACN,YAAa,6EACb,QAAS,SACrB,CACA,EACQ,SAAU,CAAC,UAAW,IAAK,IAAK,IAAK,IAAK,OAAQ,cAAc,CACxE,CACA,CACA,EACE,CACE,KAAM,WACN,SAAU,CACR,KAAM,wBACN,YAAa,iLACb,WAAY,CACV,KAAM,SACN,WAAY,CACV,QAAS,CACP,KAAM,QACN,YAAa,4HACb,MAAO,CACL,KAAM,SACN,WAAY,CACV,MAAO,CACL,KAAM,SACN,YAAa,uDACb,QAAS,SAC3B,EACgB,KAAM,CACJ,KAAM,SACN,YAAa,yBACb,QAAS,EACT,QAAS,GACT,QAAS,CAC3B,EACgB,OAAQ,CACN,KAAM,QACN,YAAa,oKACb,MAAO,CACL,KAAM,SACN,WAAY,CACV,EAAG,CACD,KAAM,SACN,YAAa,oGACb,QAAS,CACjC,EACsB,EAAG,CACD,KAAM,SACN,YAAa,8BACb,QAAS,EACT,QAAS,CACjC,EACsB,EAAG,CACD,KAAM,SACN,YAAa,8BACb,QAAS,EACT,QAAS,CACjC,CACA,EACoB,SAAU,CAAC,IAAK,IAAK,GAAG,CAC5C,EACkB,SAAU,CAC5B,CACA,EACc,SAAU,CAAC,QAAQ,CACjC,EACY,SAAU,CACtB,EACU,KAAM,CACJ,KAAM,UACN,YAAa,uDACb,QAAS,CACrB,EACU,aAAc,CACZ,KAAM,SACN,YAAa,6EACb,QAAS,SACrB,CACA,EACQ,SAAU,CAAC,UAAW,OAAQ,cAAc,CACpD,CACA,CACA,CACA,EAaO,SAASC,EAAmBC,EAAe,GAAI,CACpD,GAAI,CAAC,MAAM,QAAQA,CAAY,GAAKA,EAAa,SAAW,EAC1D,MAAO,CAAA,EAGT,MAAMC,EAAU,CACd,UAAa,8BACb,KAAQ,yBACR,IAAO,uBACX,EAEQC,EAAuBF,EAC1B,IAAIG,GAAQF,EAAQE,CAAI,CAAC,EACzB,OAAO,OAAO,EAEjB,OAAOL,EAAgB,OAAOM,GAC5BF,EAAqB,SAASE,EAAK,SAAS,IAAI,CACpD,CACA"}
|
package/dist/index16.js
CHANGED
|
@@ -1,35 +1,219 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
const r = [
|
|
2
|
+
{
|
|
3
|
+
type: "function",
|
|
4
|
+
function: {
|
|
5
|
+
name: "create_highlight_annotation",
|
|
6
|
+
description: "Create a highlight annotation at specified coordinates on the PDF page. Use this to emphasize important text or regions. Highlights are rectangular regions that can span multiple lines.",
|
|
7
|
+
parameters: {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
quads: {
|
|
11
|
+
type: "array",
|
|
12
|
+
description: "Array of rectangular regions defining the highlight areas. Each quad is an object with normalized coordinates (0-1): {x, y, w, h}. Multiple quads can be used for multi-line highlights.",
|
|
13
|
+
items: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
x: {
|
|
17
|
+
type: "number",
|
|
18
|
+
description: "Normalized x position (0 = left, 1 = right)",
|
|
19
|
+
minimum: 0,
|
|
20
|
+
maximum: 1
|
|
21
|
+
},
|
|
22
|
+
y: {
|
|
23
|
+
type: "number",
|
|
24
|
+
description: "Normalized y position (0 = top, 1 = bottom)",
|
|
25
|
+
minimum: 0,
|
|
26
|
+
maximum: 1
|
|
27
|
+
},
|
|
28
|
+
w: {
|
|
29
|
+
type: "number",
|
|
30
|
+
description: "Normalized width (0-1)",
|
|
31
|
+
minimum: 0,
|
|
32
|
+
maximum: 1
|
|
33
|
+
},
|
|
34
|
+
h: {
|
|
35
|
+
type: "number",
|
|
36
|
+
description: "Normalized height (0-1)",
|
|
37
|
+
minimum: 0,
|
|
38
|
+
maximum: 1
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
required: ["x", "y", "w", "h"]
|
|
42
|
+
},
|
|
43
|
+
minItems: 1
|
|
44
|
+
},
|
|
45
|
+
color: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "Highlight color in rgba format (e.g., 'rgba(255, 255, 0, 0.3)'). Default is semi-transparent yellow. Use rgba for transparency control.",
|
|
48
|
+
default: "rgba(255, 255, 0, 0.3)"
|
|
49
|
+
},
|
|
50
|
+
page: {
|
|
51
|
+
type: "integer",
|
|
52
|
+
description: "Page number (1-indexed) where the annotation appears",
|
|
53
|
+
minimum: 1
|
|
54
|
+
},
|
|
55
|
+
sentence_ref: {
|
|
56
|
+
type: "string",
|
|
57
|
+
description: "Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization",
|
|
58
|
+
pattern: "^S\\d+$"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
required: ["quads", "page", "sentence_ref"]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: "function",
|
|
67
|
+
function: {
|
|
68
|
+
name: "create_text_annotation",
|
|
69
|
+
description: "Create a text box annotation with explanatory content. Use this to add clarifying notes, definitions, or explanations. Text boxes have background and appear as overlays.",
|
|
70
|
+
parameters: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
content: {
|
|
74
|
+
type: "string",
|
|
75
|
+
description: "The text content of the annotation",
|
|
76
|
+
minLength: 1,
|
|
77
|
+
maxLength: 500
|
|
78
|
+
},
|
|
79
|
+
x: {
|
|
80
|
+
type: "number",
|
|
81
|
+
description: "Normalized x position (0 = left edge, 1 = right edge)",
|
|
82
|
+
minimum: 0,
|
|
83
|
+
maximum: 1
|
|
84
|
+
},
|
|
85
|
+
y: {
|
|
86
|
+
type: "number",
|
|
87
|
+
description: "Normalized y position (0 = top edge, 1 = bottom edge)",
|
|
88
|
+
minimum: 0,
|
|
89
|
+
maximum: 1
|
|
90
|
+
},
|
|
91
|
+
w: {
|
|
92
|
+
type: "number",
|
|
93
|
+
description: "Normalized width (0-1) of the text box",
|
|
94
|
+
minimum: 0,
|
|
95
|
+
maximum: 1
|
|
96
|
+
},
|
|
97
|
+
h: {
|
|
98
|
+
type: "number",
|
|
99
|
+
description: "Normalized height (0-1) of the text box",
|
|
100
|
+
minimum: 0,
|
|
101
|
+
maximum: 1
|
|
102
|
+
},
|
|
103
|
+
page: {
|
|
104
|
+
type: "integer",
|
|
105
|
+
description: "Page number (1-indexed) where the annotation appears",
|
|
106
|
+
minimum: 1
|
|
107
|
+
},
|
|
108
|
+
textColor: {
|
|
109
|
+
type: "string",
|
|
110
|
+
description: "Text color in hex format (e.g., '#000000' for black). Default is dark gray.",
|
|
111
|
+
default: "#1f2937"
|
|
112
|
+
},
|
|
113
|
+
bgColor: {
|
|
114
|
+
type: "string",
|
|
115
|
+
description: "Background color in rgba format (e.g., 'rgba(255, 255, 255, 0.9)'). Default is semi-transparent white.",
|
|
116
|
+
default: "rgba(255, 255, 255, 0.9)"
|
|
117
|
+
},
|
|
118
|
+
sentence_ref: {
|
|
119
|
+
type: "string",
|
|
120
|
+
description: "Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization",
|
|
121
|
+
pattern: "^S\\d+$"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
required: ["content", "x", "y", "w", "h", "page", "sentence_ref"]
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: "function",
|
|
130
|
+
function: {
|
|
131
|
+
name: "create_ink_annotation",
|
|
132
|
+
description: "Create a freehand drawing annotation with custom strokes. Use this to draw arrows, circles, underlines, or other visual markers. Each stroke can have its own color and width.",
|
|
133
|
+
parameters: {
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: {
|
|
136
|
+
strokes: {
|
|
137
|
+
type: "array",
|
|
138
|
+
description: "Array of stroke objects. Each stroke defines a path with points that have time offsets for progressive drawing animation.",
|
|
139
|
+
items: {
|
|
140
|
+
type: "object",
|
|
141
|
+
properties: {
|
|
142
|
+
color: {
|
|
143
|
+
type: "string",
|
|
144
|
+
description: "Stroke color in hex format (e.g., '#FF0000' for red)",
|
|
145
|
+
default: "#1f2937"
|
|
146
|
+
},
|
|
147
|
+
size: {
|
|
148
|
+
type: "number",
|
|
149
|
+
description: "Stroke width in pixels",
|
|
150
|
+
minimum: 1,
|
|
151
|
+
maximum: 10,
|
|
152
|
+
default: 3
|
|
153
|
+
},
|
|
154
|
+
points: {
|
|
155
|
+
type: "array",
|
|
156
|
+
description: "Array of points defining the stroke path. Each point has normalized coordinates (x, y) and a time offset (t) from 0 to stroke duration for progressive animation.",
|
|
157
|
+
items: {
|
|
158
|
+
type: "object",
|
|
159
|
+
properties: {
|
|
160
|
+
t: {
|
|
161
|
+
type: "number",
|
|
162
|
+
description: "Time offset in seconds from annotation start. Points are drawn progressively based on this value.",
|
|
163
|
+
minimum: 0
|
|
164
|
+
},
|
|
165
|
+
x: {
|
|
166
|
+
type: "number",
|
|
167
|
+
description: "Normalized x position (0-1)",
|
|
168
|
+
minimum: 0,
|
|
169
|
+
maximum: 1
|
|
170
|
+
},
|
|
171
|
+
y: {
|
|
172
|
+
type: "number",
|
|
173
|
+
description: "Normalized y position (0-1)",
|
|
174
|
+
minimum: 0,
|
|
175
|
+
maximum: 1
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
required: ["t", "x", "y"]
|
|
179
|
+
},
|
|
180
|
+
minItems: 2
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
required: ["points"]
|
|
184
|
+
},
|
|
185
|
+
minItems: 1
|
|
186
|
+
},
|
|
187
|
+
page: {
|
|
188
|
+
type: "integer",
|
|
189
|
+
description: "Page number (1-indexed) where the annotation appears",
|
|
190
|
+
minimum: 1
|
|
191
|
+
},
|
|
192
|
+
sentence_ref: {
|
|
193
|
+
type: "string",
|
|
194
|
+
description: "Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization",
|
|
195
|
+
pattern: "^S\\d+$"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
required: ["strokes", "page", "sentence_ref"]
|
|
199
|
+
}
|
|
200
|
+
}
|
|
18
201
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}]
|
|
28
|
-
|
|
202
|
+
];
|
|
203
|
+
function o(e = []) {
|
|
204
|
+
if (!Array.isArray(e) || e.length === 0)
|
|
205
|
+
return [];
|
|
206
|
+
const i = {
|
|
207
|
+
highlight: "create_highlight_annotation",
|
|
208
|
+
text: "create_text_annotation",
|
|
209
|
+
ink: "create_ink_annotation"
|
|
210
|
+
}, n = e.map((t) => i[t]).filter(Boolean);
|
|
211
|
+
return r.filter(
|
|
212
|
+
(t) => n.includes(t.function.name)
|
|
213
|
+
);
|
|
214
|
+
}
|
|
29
215
|
export {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
e as INK_DEFAULTS,
|
|
33
|
-
s as TEXT_DEFAULTS
|
|
216
|
+
r as annotationTools,
|
|
217
|
+
o as getAnnotationTools
|
|
34
218
|
};
|
|
35
219
|
//# sourceMappingURL=index16.js.map
|
package/dist/index16.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index16.js","sources":["../src/types/defaults.js"],"sourcesContent":["/**\n * Default Values for Annotation Normalization\n *\n * This module defines default values used when annotation fields are missing\n * or invalid. These defaults ensure annotations render visibly and safely.\n *\n * @module types/defaults\n */\n\n/**\n * Default values for base annotation fields (common to all types)\n *\n * @constant {Object}\n * @property {number} page - Default page number (first page)\n * @property {number} start - Default start time (display immediately)\n * @property {number} end - Default end time (static display, no animation)\n */\nexport const BASE_DEFAULTS = {\n page: 1,\n start: 0,\n end: 0\n};\n\n/**\n * Default values for highlight annotations\n *\n * Creates a visible yellow highlight near the top of the page.\n *\n * @constant {Object}\n * @property {string} mode - Highlight mode (only 'quads' supported)\n * @property {Array<Object>} quads - Default rectangular regions\n * @property {Object} style - Default styling\n */\nexport const HIGHLIGHT_DEFAULTS = {\n mode: 'quads',\n quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],\n style: { color: 'rgba(255, 255, 0, 0.3)' }\n};\n\n/**\n * Default values for text annotations\n *\n * Creates a visible text box in the top-left with placeholder content.\n *\n * @constant {Object}\n * @property {string} content - Placeholder text\n * @property {number} x - Normalized x position (10% from left)\n * @property {number} y - Normalized y position (10% from top)\n * @property {number} w - Normalized width (30% of page width)\n * @property {number} h - Normalized height (10% of page height)\n * @property {Object} style - Default styling with white background and black text\n */\nexport const TEXT_DEFAULTS = {\n content: '[No content]',\n x: 0.1,\n y: 0.1,\n w: 0.3,\n h: 0.1,\n style: {\n bg: 'rgba(255, 255, 255, 0.9)',\n color: '#000000'\n }\n};\n\n/**\n * Default values for ink annotations\n *\n * Creates a visible diagonal line in dark gray.\n *\n * @constant {Object}\n * @property {Array<Object>} strokes - Default stroke with two points\n */\nexport const INK_DEFAULTS = {\n strokes: [{\n color: '#1f2937',\n size: 3,\n points: [\n { t: 0, x: 0.1, y: 0.1 },\n { t: 1, x: 0.2, y: 0.2 }\n ]\n }]\n};\n"],"names":["BASE_DEFAULTS","HIGHLIGHT_DEFAULTS","TEXT_DEFAULTS","INK_DEFAULTS"],"mappings":"AAiBY,MAACA,IAAgB;AAAA,EAC3B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AACP,GAYaC,IAAqB;AAAA,EAChC,MAAM;AAAA,EACN,OAAO,CAAC,EAAE,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM;AAAA,EAC3C,OAAO,EAAE,OAAO,yBAAwB;AAC1C,GAeaC,IAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,OAAO;AAAA,IACL,IAAI;AAAA,IACJ,OAAO;AAAA,EACX;AACA,GAUaC,IAAe;AAAA,EAC1B,SAAS,CAAC;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,IAAG;AAAA,MACtB,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,IAAG;AAAA,IAC5B;AAAA,EACA,CAAG;AACH;"}
|
|
1
|
+
{"version":3,"file":"index16.js","sources":["../src/ai-tools/openai/schemas.js"],"sourcesContent":["/**\n * OpenAI Tool Schemas for PDF Annotation Generation\n *\n * Provides OpenAI-compatible function calling schemas for creating PDF annotations.\n * These schemas define the structure and parameters for AI-generated annotations.\n * Compatible with web-annotation-renderer library format.\n *\n * @module ai-tools/openai/schemas\n */\n\n/**\n * Complete set of annotation tools for OpenAI function calling\n *\n * Export this array to the OpenAI API's `tools` parameter to enable\n * AI-generated annotations.\n *\n * @constant {Array<Object>}\n * @example\n * ```javascript\n * import { annotationTools } from 'web-annotation-renderer/ai-tools';\n *\n * const response = await openai.chat.completions.create({\n * model: \"gpt-4\",\n * messages: [...],\n * tools: annotationTools\n * });\n * ```\n */\nexport const annotationTools = [\n {\n type: \"function\",\n function: {\n name: \"create_highlight_annotation\",\n description: \"Create a highlight annotation at specified coordinates on the PDF page. Use this to emphasize important text or regions. Highlights are rectangular regions that can span multiple lines.\",\n parameters: {\n type: \"object\",\n properties: {\n quads: {\n type: \"array\",\n description: \"Array of rectangular regions defining the highlight areas. Each quad is an object with normalized coordinates (0-1): {x, y, w, h}. Multiple quads can be used for multi-line highlights.\",\n items: {\n type: \"object\",\n properties: {\n x: {\n type: \"number\",\n description: \"Normalized x position (0 = left, 1 = right)\",\n minimum: 0,\n maximum: 1\n },\n y: {\n type: \"number\",\n description: \"Normalized y position (0 = top, 1 = bottom)\",\n minimum: 0,\n maximum: 1\n },\n w: {\n type: \"number\",\n description: \"Normalized width (0-1)\",\n minimum: 0,\n maximum: 1\n },\n h: {\n type: \"number\",\n description: \"Normalized height (0-1)\",\n minimum: 0,\n maximum: 1\n }\n },\n required: [\"x\", \"y\", \"w\", \"h\"]\n },\n minItems: 1\n },\n color: {\n type: \"string\",\n description: \"Highlight color in rgba format (e.g., 'rgba(255, 255, 0, 0.3)'). Default is semi-transparent yellow. Use rgba for transparency control.\",\n default: \"rgba(255, 255, 0, 0.3)\"\n },\n page: {\n type: \"integer\",\n description: \"Page number (1-indexed) where the annotation appears\",\n minimum: 1\n },\n sentence_ref: {\n type: \"string\",\n description: \"Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization\",\n pattern: \"^S\\\\d+$\"\n }\n },\n required: [\"quads\", \"page\", \"sentence_ref\"]\n }\n }\n },\n {\n type: \"function\",\n function: {\n name: \"create_text_annotation\",\n description: \"Create a text box annotation with explanatory content. Use this to add clarifying notes, definitions, or explanations. Text boxes have background and appear as overlays.\",\n parameters: {\n type: \"object\",\n properties: {\n content: {\n type: \"string\",\n description: \"The text content of the annotation\",\n minLength: 1,\n maxLength: 500\n },\n x: {\n type: \"number\",\n description: \"Normalized x position (0 = left edge, 1 = right edge)\",\n minimum: 0,\n maximum: 1\n },\n y: {\n type: \"number\",\n description: \"Normalized y position (0 = top edge, 1 = bottom edge)\",\n minimum: 0,\n maximum: 1\n },\n w: {\n type: \"number\",\n description: \"Normalized width (0-1) of the text box\",\n minimum: 0,\n maximum: 1\n },\n h: {\n type: \"number\",\n description: \"Normalized height (0-1) of the text box\",\n minimum: 0,\n maximum: 1\n },\n page: {\n type: \"integer\",\n description: \"Page number (1-indexed) where the annotation appears\",\n minimum: 1\n },\n textColor: {\n type: \"string\",\n description: \"Text color in hex format (e.g., '#000000' for black). Default is dark gray.\",\n default: \"#1f2937\"\n },\n bgColor: {\n type: \"string\",\n description: \"Background color in rgba format (e.g., 'rgba(255, 255, 255, 0.9)'). Default is semi-transparent white.\",\n default: \"rgba(255, 255, 255, 0.9)\"\n },\n sentence_ref: {\n type: \"string\",\n description: \"Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization\",\n pattern: \"^S\\\\d+$\"\n }\n },\n required: [\"content\", \"x\", \"y\", \"w\", \"h\", \"page\", \"sentence_ref\"]\n }\n }\n },\n {\n type: \"function\",\n function: {\n name: \"create_ink_annotation\",\n description: \"Create a freehand drawing annotation with custom strokes. Use this to draw arrows, circles, underlines, or other visual markers. Each stroke can have its own color and width.\",\n parameters: {\n type: \"object\",\n properties: {\n strokes: {\n type: \"array\",\n description: \"Array of stroke objects. Each stroke defines a path with points that have time offsets for progressive drawing animation.\",\n items: {\n type: \"object\",\n properties: {\n color: {\n type: \"string\",\n description: \"Stroke color in hex format (e.g., '#FF0000' for red)\",\n default: \"#1f2937\"\n },\n size: {\n type: \"number\",\n description: \"Stroke width in pixels\",\n minimum: 1,\n maximum: 10,\n default: 3\n },\n points: {\n type: \"array\",\n description: \"Array of points defining the stroke path. Each point has normalized coordinates (x, y) and a time offset (t) from 0 to stroke duration for progressive animation.\",\n items: {\n type: \"object\",\n properties: {\n t: {\n type: \"number\",\n description: \"Time offset in seconds from annotation start. Points are drawn progressively based on this value.\",\n minimum: 0\n },\n x: {\n type: \"number\",\n description: \"Normalized x position (0-1)\",\n minimum: 0,\n maximum: 1\n },\n y: {\n type: \"number\",\n description: \"Normalized y position (0-1)\",\n minimum: 0,\n maximum: 1\n }\n },\n required: [\"t\", \"x\", \"y\"]\n },\n minItems: 2\n }\n },\n required: [\"points\"]\n },\n minItems: 1\n },\n page: {\n type: \"integer\",\n description: \"Page number (1-indexed) where the annotation appears\",\n minimum: 1\n },\n sentence_ref: {\n type: \"string\",\n description: \"Reference to sentence marker (e.g., 'S1', 'S2') for timing synchronization\",\n pattern: \"^S\\\\d+$\"\n }\n },\n required: [\"strokes\", \"page\", \"sentence_ref\"]\n }\n }\n }\n];\n\n/**\n * Get filtered annotation tools based on enabled types\n *\n * @param {Array<string>} enabledTypes - Array of enabled tool types: ['highlight', 'text', 'ink']\n * @returns {Array<Object>} Filtered annotation tools\n * @example\n * ```javascript\n * // Only enable highlights and text notes\n * const tools = getAnnotationTools(['highlight', 'text']);\n * ```\n */\nexport function getAnnotationTools(enabledTypes = []) {\n if (!Array.isArray(enabledTypes) || enabledTypes.length === 0) {\n return [];\n }\n\n const typeMap = {\n 'highlight': 'create_highlight_annotation',\n 'text': 'create_text_annotation',\n 'ink': 'create_ink_annotation'\n };\n\n const enabledFunctionNames = enabledTypes\n .map(type => typeMap[type])\n .filter(Boolean);\n\n return annotationTools.filter(tool =>\n enabledFunctionNames.includes(tool.function.name)\n );\n}\n"],"names":["annotationTools","getAnnotationTools","enabledTypes","typeMap","enabledFunctionNames","type","tool"],"mappings":"AA4BY,MAACA,IAAkB;AAAA,EAC7B;AAAA,IACE,MAAM;AAAA,IACN,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aAAa;AAAA,MACb,YAAY;AAAA,QACV,MAAM;AAAA,QACN,YAAY;AAAA,UACV,OAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa;AAAA,YACb,OAAO;AAAA,cACL,MAAM;AAAA,cACN,YAAY;AAAA,gBACV,GAAG;AAAA,kBACD,MAAM;AAAA,kBACN,aAAa;AAAA,kBACb,SAAS;AAAA,kBACT,SAAS;AAAA,gBAC3B;AAAA,gBACgB,GAAG;AAAA,kBACD,MAAM;AAAA,kBACN,aAAa;AAAA,kBACb,SAAS;AAAA,kBACT,SAAS;AAAA,gBAC3B;AAAA,gBACgB,GAAG;AAAA,kBACD,MAAM;AAAA,kBACN,aAAa;AAAA,kBACb,SAAS;AAAA,kBACT,SAAS;AAAA,gBAC3B;AAAA,gBACgB,GAAG;AAAA,kBACD,MAAM;AAAA,kBACN,aAAa;AAAA,kBACb,SAAS;AAAA,kBACT,SAAS;AAAA,gBAC3B;AAAA,cACA;AAAA,cACc,UAAU,CAAC,KAAK,KAAK,KAAK,GAAG;AAAA,YAC3C;AAAA,YACY,UAAU;AAAA,UACtB;AAAA,UACU,OAAO;AAAA,YACL,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,UACrB;AAAA,UACU,MAAM;AAAA,YACJ,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,UACrB;AAAA,UACU,cAAc;AAAA,YACZ,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,UACrB;AAAA,QACA;AAAA,QACQ,UAAU,CAAC,SAAS,QAAQ,cAAc;AAAA,MAClD;AAAA,IACA;AAAA,EACA;AAAA,EACE;AAAA,IACE,MAAM;AAAA,IACN,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aAAa;AAAA,MACb,YAAY;AAAA,QACV,MAAM;AAAA,QACN,YAAY;AAAA,UACV,SAAS;AAAA,YACP,MAAM;AAAA,YACN,aAAa;AAAA,YACb,WAAW;AAAA,YACX,WAAW;AAAA,UACvB;AAAA,UACU,GAAG;AAAA,YACD,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,YACT,SAAS;AAAA,UACrB;AAAA,UACU,GAAG;AAAA,YACD,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,YACT,SAAS;AAAA,UACrB;AAAA,UACU,GAAG;AAAA,YACD,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,YACT,SAAS;AAAA,UACrB;AAAA,UACU,GAAG;AAAA,YACD,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,YACT,SAAS;AAAA,UACrB;AAAA,UACU,MAAM;AAAA,YACJ,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,UACrB;AAAA,UACU,WAAW;AAAA,YACT,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,UACrB;AAAA,UACU,SAAS;AAAA,YACP,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,UACrB;AAAA,UACU,cAAc;AAAA,YACZ,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,UACrB;AAAA,QACA;AAAA,QACQ,UAAU,CAAC,WAAW,KAAK,KAAK,KAAK,KAAK,QAAQ,cAAc;AAAA,MACxE;AAAA,IACA;AAAA,EACA;AAAA,EACE;AAAA,IACE,MAAM;AAAA,IACN,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aAAa;AAAA,MACb,YAAY;AAAA,QACV,MAAM;AAAA,QACN,YAAY;AAAA,UACV,SAAS;AAAA,YACP,MAAM;AAAA,YACN,aAAa;AAAA,YACb,OAAO;AAAA,cACL,MAAM;AAAA,cACN,YAAY;AAAA,gBACV,OAAO;AAAA,kBACL,MAAM;AAAA,kBACN,aAAa;AAAA,kBACb,SAAS;AAAA,gBAC3B;AAAA,gBACgB,MAAM;AAAA,kBACJ,MAAM;AAAA,kBACN,aAAa;AAAA,kBACb,SAAS;AAAA,kBACT,SAAS;AAAA,kBACT,SAAS;AAAA,gBAC3B;AAAA,gBACgB,QAAQ;AAAA,kBACN,MAAM;AAAA,kBACN,aAAa;AAAA,kBACb,OAAO;AAAA,oBACL,MAAM;AAAA,oBACN,YAAY;AAAA,sBACV,GAAG;AAAA,wBACD,MAAM;AAAA,wBACN,aAAa;AAAA,wBACb,SAAS;AAAA,sBACjC;AAAA,sBACsB,GAAG;AAAA,wBACD,MAAM;AAAA,wBACN,aAAa;AAAA,wBACb,SAAS;AAAA,wBACT,SAAS;AAAA,sBACjC;AAAA,sBACsB,GAAG;AAAA,wBACD,MAAM;AAAA,wBACN,aAAa;AAAA,wBACb,SAAS;AAAA,wBACT,SAAS;AAAA,sBACjC;AAAA,oBACA;AAAA,oBACoB,UAAU,CAAC,KAAK,KAAK,GAAG;AAAA,kBAC5C;AAAA,kBACkB,UAAU;AAAA,gBAC5B;AAAA,cACA;AAAA,cACc,UAAU,CAAC,QAAQ;AAAA,YACjC;AAAA,YACY,UAAU;AAAA,UACtB;AAAA,UACU,MAAM;AAAA,YACJ,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,UACrB;AAAA,UACU,cAAc;AAAA,YACZ,MAAM;AAAA,YACN,aAAa;AAAA,YACb,SAAS;AAAA,UACrB;AAAA,QACA;AAAA,QACQ,UAAU,CAAC,WAAW,QAAQ,cAAc;AAAA,MACpD;AAAA,IACA;AAAA,EACA;AACA;AAaO,SAASC,EAAmBC,IAAe,IAAI;AACpD,MAAI,CAAC,MAAM,QAAQA,CAAY,KAAKA,EAAa,WAAW;AAC1D,WAAO,CAAA;AAGT,QAAMC,IAAU;AAAA,IACd,WAAa;AAAA,IACb,MAAQ;AAAA,IACR,KAAO;AAAA,EACX,GAEQC,IAAuBF,EAC1B,IAAI,CAAAG,MAAQF,EAAQE,CAAI,CAAC,EACzB,OAAO,OAAO;AAEjB,SAAOL,EAAgB;AAAA,IAAO,CAAAM,MAC5BF,EAAqB,SAASE,EAAK,SAAS,IAAI;AAAA,EACpD;AACA;"}
|
package/dist/index17.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index18.cjs"),c=require("./index19.cjs"),l=require("./index20.cjs");function o(r){if(!r||typeof r!="object")throw new Error("Invalid tool call: must be an object");if(!r.function||typeof r.function!="object")throw new Error("Invalid tool call: missing function property");const{name:t,arguments:n}=r.function;if(!t||typeof t!="string")throw new Error("Invalid tool call: missing or invalid function name");let e;try{e=typeof n=="string"?JSON.parse(n):n}catch(a){throw new Error(`Failed to parse tool call arguments: ${a.message}`)}switch(t){case"create_highlight_annotation":return i.createHighlight(e);case"create_text_annotation":return c.createText(e);case"create_ink_annotation":return l.createInk(e);default:throw new Error(`Unknown tool: ${t}. Supported tools: create_highlight_annotation, create_text_annotation, create_ink_annotation`)}}function s(r){if(!Array.isArray(r))throw new Error("Tool calls must be an array");return r.map((t,n)=>{try{return o(t)}catch(e){throw new Error(`Error processing tool call at index ${n}: ${e.message}`)}})}exports.handleToolCall=o;exports.handleToolCalls=s;
|
|
2
|
+
//# sourceMappingURL=index17.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index17.cjs","sources":["../src/ai-tools/openai/handler.js"],"sourcesContent":["/**\n * OpenAI Tool Call Handler\n *\n * Processes OpenAI function calling responses and converts them into\n * valid annotation objects.\n *\n * @module ai-tools/openai/handler\n */\n\nimport { createHighlight } from '../creators/createHighlight.js';\nimport { createText } from '../creators/createText.js';\nimport { createInk } from '../creators/createInk.js';\n\n/**\n * Handle an OpenAI tool call and convert it to a valid annotation\n *\n * @param {Object} toolCall - Tool call object from OpenAI API response\n * @param {Object} toolCall.function - Function call details\n * @param {string} toolCall.function.name - Function name\n * @param {string} toolCall.function.arguments - JSON string of arguments\n * @returns {Object} Valid annotation object\n * @throws {Error} If tool call is invalid or unsupported\n * @example\n * ```javascript\n * import { handleToolCall } from 'web-annotation-renderer/ai-tools';\n *\n * const response = await openai.chat.completions.create({\n * model: \"gpt-4\",\n * messages: [...],\n * tools: annotationTools\n * });\n *\n * const annotations = [];\n * if (response.choices[0].message.tool_calls) {\n * for (const toolCall of response.choices[0].message.tool_calls) {\n * const annotation = handleToolCall(toolCall);\n * annotations.push(annotation);\n * }\n * }\n * ```\n */\nexport function handleToolCall(toolCall) {\n // Validate tool call structure\n if (!toolCall || typeof toolCall !== 'object') {\n throw new Error('Invalid tool call: must be an object');\n }\n\n if (!toolCall.function || typeof toolCall.function !== 'object') {\n throw new Error('Invalid tool call: missing function property');\n }\n\n const { name, arguments: argsString } = toolCall.function;\n\n if (!name || typeof name !== 'string') {\n throw new Error('Invalid tool call: missing or invalid function name');\n }\n\n // Parse arguments\n let args;\n try {\n args = typeof argsString === 'string' ? JSON.parse(argsString) : argsString;\n } catch (error) {\n throw new Error(`Failed to parse tool call arguments: ${error.message}`);\n }\n\n // Route to appropriate creator function\n switch (name) {\n case 'create_highlight_annotation':\n return createHighlight(args);\n\n case 'create_text_annotation':\n return createText(args);\n\n case 'create_ink_annotation':\n return createInk(args);\n\n default:\n throw new Error(`Unknown tool: ${name}. Supported tools: create_highlight_annotation, create_text_annotation, create_ink_annotation`);\n }\n}\n\n/**\n * Process multiple tool calls from an OpenAI response\n *\n * @param {Array<Object>} toolCalls - Array of tool call objects from OpenAI\n * @returns {Array<Object>} Array of valid annotation objects\n * @example\n * ```javascript\n * const annotations = handleToolCalls(response.choices[0].message.tool_calls);\n * ```\n */\nexport function handleToolCalls(toolCalls) {\n if (!Array.isArray(toolCalls)) {\n throw new Error('Tool calls must be an array');\n }\n\n return toolCalls.map((toolCall, index) => {\n try {\n return handleToolCall(toolCall);\n } catch (error) {\n throw new Error(`Error processing tool call at index ${index}: ${error.message}`);\n }\n });\n}\n"],"names":["handleToolCall","toolCall","name","argsString","args","error","createHighlight","createText","createInk","handleToolCalls","toolCalls","index"],"mappings":"uKAyCO,SAASA,EAAeC,EAAU,CAEvC,GAAI,CAACA,GAAY,OAAOA,GAAa,SACnC,MAAM,IAAI,MAAM,sCAAsC,EAGxD,GAAI,CAACA,EAAS,UAAY,OAAOA,EAAS,UAAa,SACrD,MAAM,IAAI,MAAM,8CAA8C,EAGhE,KAAM,CAAE,KAAAC,EAAM,UAAWC,CAAU,EAAKF,EAAS,SAEjD,GAAI,CAACC,GAAQ,OAAOA,GAAS,SAC3B,MAAM,IAAI,MAAM,qDAAqD,EAIvE,IAAIE,EACJ,GAAI,CACFA,EAAO,OAAOD,GAAe,SAAW,KAAK,MAAMA,CAAU,EAAIA,CACnE,OAASE,EAAO,CACd,MAAM,IAAI,MAAM,wCAAwCA,EAAM,OAAO,EAAE,CACzE,CAGA,OAAQH,EAAI,CACV,IAAK,8BACH,OAAOI,EAAAA,gBAAgBF,CAAI,EAE7B,IAAK,yBACH,OAAOG,EAAAA,WAAWH,CAAI,EAExB,IAAK,wBACH,OAAOI,EAAAA,UAAUJ,CAAI,EAEvB,QACE,MAAM,IAAI,MAAM,iBAAiBF,CAAI,+FAA+F,CAC1I,CACA,CAYO,SAASO,EAAgBC,EAAW,CACzC,GAAI,CAAC,MAAM,QAAQA,CAAS,EAC1B,MAAM,IAAI,MAAM,6BAA6B,EAG/C,OAAOA,EAAU,IAAI,CAACT,EAAUU,IAAU,CACxC,GAAI,CACF,OAAOX,EAAeC,CAAQ,CAChC,OAASI,EAAO,CACd,MAAM,IAAI,MAAM,uCAAuCM,CAAK,KAAKN,EAAM,OAAO,EAAE,CAClF,CACF,CAAC,CACH"}
|
package/dist/index17.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createHighlight as a } from "./index18.js";
|
|
2
|
+
import { createText as i } from "./index19.js";
|
|
3
|
+
import { createInk as c } from "./index20.js";
|
|
4
|
+
function s(r) {
|
|
5
|
+
if (!r || typeof r != "object")
|
|
6
|
+
throw new Error("Invalid tool call: must be an object");
|
|
7
|
+
if (!r.function || typeof r.function != "object")
|
|
8
|
+
throw new Error("Invalid tool call: missing function property");
|
|
9
|
+
const { name: t, arguments: e } = r.function;
|
|
10
|
+
if (!t || typeof t != "string")
|
|
11
|
+
throw new Error("Invalid tool call: missing or invalid function name");
|
|
12
|
+
let n;
|
|
13
|
+
try {
|
|
14
|
+
n = typeof e == "string" ? JSON.parse(e) : e;
|
|
15
|
+
} catch (o) {
|
|
16
|
+
throw new Error(`Failed to parse tool call arguments: ${o.message}`);
|
|
17
|
+
}
|
|
18
|
+
switch (t) {
|
|
19
|
+
case "create_highlight_annotation":
|
|
20
|
+
return a(n);
|
|
21
|
+
case "create_text_annotation":
|
|
22
|
+
return i(n);
|
|
23
|
+
case "create_ink_annotation":
|
|
24
|
+
return c(n);
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Unknown tool: ${t}. Supported tools: create_highlight_annotation, create_text_annotation, create_ink_annotation`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function g(r) {
|
|
30
|
+
if (!Array.isArray(r))
|
|
31
|
+
throw new Error("Tool calls must be an array");
|
|
32
|
+
return r.map((t, e) => {
|
|
33
|
+
try {
|
|
34
|
+
return s(t);
|
|
35
|
+
} catch (n) {
|
|
36
|
+
throw new Error(`Error processing tool call at index ${e}: ${n.message}`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
s as handleToolCall,
|
|
42
|
+
g as handleToolCalls
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=index17.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index17.js","sources":["../src/ai-tools/openai/handler.js"],"sourcesContent":["/**\n * OpenAI Tool Call Handler\n *\n * Processes OpenAI function calling responses and converts them into\n * valid annotation objects.\n *\n * @module ai-tools/openai/handler\n */\n\nimport { createHighlight } from '../creators/createHighlight.js';\nimport { createText } from '../creators/createText.js';\nimport { createInk } from '../creators/createInk.js';\n\n/**\n * Handle an OpenAI tool call and convert it to a valid annotation\n *\n * @param {Object} toolCall - Tool call object from OpenAI API response\n * @param {Object} toolCall.function - Function call details\n * @param {string} toolCall.function.name - Function name\n * @param {string} toolCall.function.arguments - JSON string of arguments\n * @returns {Object} Valid annotation object\n * @throws {Error} If tool call is invalid or unsupported\n * @example\n * ```javascript\n * import { handleToolCall } from 'web-annotation-renderer/ai-tools';\n *\n * const response = await openai.chat.completions.create({\n * model: \"gpt-4\",\n * messages: [...],\n * tools: annotationTools\n * });\n *\n * const annotations = [];\n * if (response.choices[0].message.tool_calls) {\n * for (const toolCall of response.choices[0].message.tool_calls) {\n * const annotation = handleToolCall(toolCall);\n * annotations.push(annotation);\n * }\n * }\n * ```\n */\nexport function handleToolCall(toolCall) {\n // Validate tool call structure\n if (!toolCall || typeof toolCall !== 'object') {\n throw new Error('Invalid tool call: must be an object');\n }\n\n if (!toolCall.function || typeof toolCall.function !== 'object') {\n throw new Error('Invalid tool call: missing function property');\n }\n\n const { name, arguments: argsString } = toolCall.function;\n\n if (!name || typeof name !== 'string') {\n throw new Error('Invalid tool call: missing or invalid function name');\n }\n\n // Parse arguments\n let args;\n try {\n args = typeof argsString === 'string' ? JSON.parse(argsString) : argsString;\n } catch (error) {\n throw new Error(`Failed to parse tool call arguments: ${error.message}`);\n }\n\n // Route to appropriate creator function\n switch (name) {\n case 'create_highlight_annotation':\n return createHighlight(args);\n\n case 'create_text_annotation':\n return createText(args);\n\n case 'create_ink_annotation':\n return createInk(args);\n\n default:\n throw new Error(`Unknown tool: ${name}. Supported tools: create_highlight_annotation, create_text_annotation, create_ink_annotation`);\n }\n}\n\n/**\n * Process multiple tool calls from an OpenAI response\n *\n * @param {Array<Object>} toolCalls - Array of tool call objects from OpenAI\n * @returns {Array<Object>} Array of valid annotation objects\n * @example\n * ```javascript\n * const annotations = handleToolCalls(response.choices[0].message.tool_calls);\n * ```\n */\nexport function handleToolCalls(toolCalls) {\n if (!Array.isArray(toolCalls)) {\n throw new Error('Tool calls must be an array');\n }\n\n return toolCalls.map((toolCall, index) => {\n try {\n return handleToolCall(toolCall);\n } catch (error) {\n throw new Error(`Error processing tool call at index ${index}: ${error.message}`);\n }\n });\n}\n"],"names":["handleToolCall","toolCall","name","argsString","args","error","createHighlight","createText","createInk","handleToolCalls","toolCalls","index"],"mappings":";;;AAyCO,SAASA,EAAeC,GAAU;AAEvC,MAAI,CAACA,KAAY,OAAOA,KAAa;AACnC,UAAM,IAAI,MAAM,sCAAsC;AAGxD,MAAI,CAACA,EAAS,YAAY,OAAOA,EAAS,YAAa;AACrD,UAAM,IAAI,MAAM,8CAA8C;AAGhE,QAAM,EAAE,MAAAC,GAAM,WAAWC,EAAU,IAAKF,EAAS;AAEjD,MAAI,CAACC,KAAQ,OAAOA,KAAS;AAC3B,UAAM,IAAI,MAAM,qDAAqD;AAIvE,MAAIE;AACJ,MAAI;AACF,IAAAA,IAAO,OAAOD,KAAe,WAAW,KAAK,MAAMA,CAAU,IAAIA;AAAA,EACnE,SAASE,GAAO;AACd,UAAM,IAAI,MAAM,wCAAwCA,EAAM,OAAO,EAAE;AAAA,EACzE;AAGA,UAAQH,GAAI;AAAA,IACV,KAAK;AACH,aAAOI,EAAgBF,CAAI;AAAA,IAE7B,KAAK;AACH,aAAOG,EAAWH,CAAI;AAAA,IAExB,KAAK;AACH,aAAOI,EAAUJ,CAAI;AAAA,IAEvB;AACE,YAAM,IAAI,MAAM,iBAAiBF,CAAI,+FAA+F;AAAA,EAC1I;AACA;AAYO,SAASO,EAAgBC,GAAW;AACzC,MAAI,CAAC,MAAM,QAAQA,CAAS;AAC1B,UAAM,IAAI,MAAM,6BAA6B;AAG/C,SAAOA,EAAU,IAAI,CAACT,GAAUU,MAAU;AACxC,QAAI;AACF,aAAOX,EAAeC,CAAQ;AAAA,IAChC,SAASI,GAAO;AACd,YAAM,IAAI,MAAM,uCAAuCM,CAAK,KAAKN,EAAM,OAAO,EAAE;AAAA,IAClF;AAAA,EACF,CAAC;AACH;"}
|
package/dist/index18.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index22.cjs");function h(e){if(!e.quads||!Array.isArray(e.quads)||e.quads.length===0)throw new Error("Highlight annotation requires at least one quad");if(!e.page||typeof e.page!="number"||e.page<1)throw new Error("Highlight annotation requires a valid page number (>= 1)");if(!e.sentence_ref||typeof e.sentence_ref!="string")throw new Error("Highlight annotation requires a sentence_ref for timing");e.quads.forEach((r,o)=>{if(typeof r!="object"||r===null||Array.isArray(r))throw new Error(`Quad at index ${o} must be an object with {x, y, w, h} properties`);const i=["x","y","w","h"];for(const t of i){if(typeof r[t]!="number")throw new Error(`Quad at index ${o} is missing required property '${t}' or it's not a number`);if(r[t]<0||r[t]>1)throw new Error(`Quad property '${t}' at index ${o} must be between 0 and 1 (got ${r[t]})`)}});const n=e.color||"rgba(255, 255, 0, 0.3)";return{id:a.generateId("highlight"),type:"highlight",mode:"quads",page:e.page,quads:e.quads,style:{color:n},sentence_ref:e.sentence_ref}}exports.createHighlight=h;
|
|
2
|
+
//# sourceMappingURL=index18.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index18.cjs","sources":["../src/ai-tools/creators/createHighlight.js"],"sourcesContent":["/**\n * Highlight Annotation Creator\n *\n * Converts AI-generated tool call arguments into valid highlight annotation objects\n * compatible with web-annotation-renderer library format.\n *\n * @module ai-tools/creators/createHighlight\n */\n\nimport { generateId } from '../../utils/idGenerator.js';\n\n/**\n * Create a highlight annotation from tool call arguments\n *\n * @param {Object} args - Tool call arguments from AI\n * @param {Array<Object>} args.quads - Rectangle objects with {x, y, w, h} (normalized 0-1)\n * @param {string} [args.color='rgba(255, 255, 0, 0.3)'] - Highlight color in rgba format\n * @param {number} args.page - Page number (1-indexed)\n * @param {string} args.sentence_ref - Sentence reference for timing (e.g., 'S1')\n * @returns {Object} Valid highlight annotation object\n * @example\n * ```javascript\n * const highlight = createHighlight({\n * quads: [{x: 0.1, y: 0.2, w: 0.8, h: 0.05}],\n * color: 'rgba(255, 255, 0, 0.3)',\n * page: 1,\n * sentence_ref: 'S2'\n * });\n * ```\n */\nexport function createHighlight(args) {\n // Validate required fields\n if (!args.quads || !Array.isArray(args.quads) || args.quads.length === 0) {\n throw new Error('Highlight annotation requires at least one quad');\n }\n\n if (!args.page || typeof args.page !== 'number' || args.page < 1) {\n throw new Error('Highlight annotation requires a valid page number (>= 1)');\n }\n\n if (!args.sentence_ref || typeof args.sentence_ref !== 'string') {\n throw new Error('Highlight annotation requires a sentence_ref for timing');\n }\n\n // Validate quad format - each quad must be an object with {x, y, w, h}\n args.quads.forEach((quad, index) => {\n if (typeof quad !== 'object' || quad === null || Array.isArray(quad)) {\n throw new Error(`Quad at index ${index} must be an object with {x, y, w, h} properties`);\n }\n\n const requiredProps = ['x', 'y', 'w', 'h'];\n for (const prop of requiredProps) {\n if (typeof quad[prop] !== 'number') {\n throw new Error(`Quad at index ${index} is missing required property '${prop}' or it's not a number`);\n }\n if (quad[prop] < 0 || quad[prop] > 1) {\n throw new Error(`Quad property '${prop}' at index ${index} must be between 0 and 1 (got ${quad[prop]})`);\n }\n }\n });\n\n // Validate color format (should be rgba)\n const color = args.color || 'rgba(255, 255, 0, 0.3)';\n\n // Create annotation object matching library format\n return {\n id: generateId('highlight'),\n type: 'highlight',\n mode: 'quads', // Required by HighlightLayer\n page: args.page,\n quads: args.quads, // Array of {x, y, w, h} objects\n style: {\n color: color // Color wrapped in style object\n },\n sentence_ref: args.sentence_ref,\n // Note: start/end will be added during timing sync phase\n };\n}\n"],"names":["createHighlight","args","quad","index","requiredProps","prop","color","generateId"],"mappings":"iHA8BO,SAASA,EAAgBC,EAAM,CAEpC,GAAI,CAACA,EAAK,OAAS,CAAC,MAAM,QAAQA,EAAK,KAAK,GAAKA,EAAK,MAAM,SAAW,EACrE,MAAM,IAAI,MAAM,iDAAiD,EAGnE,GAAI,CAACA,EAAK,MAAQ,OAAOA,EAAK,MAAS,UAAYA,EAAK,KAAO,EAC7D,MAAM,IAAI,MAAM,0DAA0D,EAG5E,GAAI,CAACA,EAAK,cAAgB,OAAOA,EAAK,cAAiB,SACrD,MAAM,IAAI,MAAM,yDAAyD,EAI3EA,EAAK,MAAM,QAAQ,CAACC,EAAMC,IAAU,CAClC,GAAI,OAAOD,GAAS,UAAYA,IAAS,MAAQ,MAAM,QAAQA,CAAI,EACjE,MAAM,IAAI,MAAM,iBAAiBC,CAAK,iDAAiD,EAGzF,MAAMC,EAAgB,CAAC,IAAK,IAAK,IAAK,GAAG,EACzC,UAAWC,KAAQD,EAAe,CAChC,GAAI,OAAOF,EAAKG,CAAI,GAAM,SACxB,MAAM,IAAI,MAAM,iBAAiBF,CAAK,kCAAkCE,CAAI,wBAAwB,EAEtG,GAAIH,EAAKG,CAAI,EAAI,GAAKH,EAAKG,CAAI,EAAI,EACjC,MAAM,IAAI,MAAM,kBAAkBA,CAAI,cAAcF,CAAK,iCAAiCD,EAAKG,CAAI,CAAC,GAAG,CAE3G,CACF,CAAC,EAGD,MAAMC,EAAQL,EAAK,OAAS,yBAG5B,MAAO,CACL,GAAIM,EAAAA,WAAW,WAAW,EAC1B,KAAM,YACN,KAAM,QACN,KAAMN,EAAK,KACX,MAAOA,EAAK,MACZ,MAAO,CACL,MAAOK,CACb,EACI,aAAcL,EAAK,YAEvB,CACA"}
|
package/dist/index18.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { generateId as h } from "./index22.js";
|
|
2
|
+
function p(e) {
|
|
3
|
+
if (!e.quads || !Array.isArray(e.quads) || e.quads.length === 0)
|
|
4
|
+
throw new Error("Highlight annotation requires at least one quad");
|
|
5
|
+
if (!e.page || typeof e.page != "number" || e.page < 1)
|
|
6
|
+
throw new Error("Highlight annotation requires a valid page number (>= 1)");
|
|
7
|
+
if (!e.sentence_ref || typeof e.sentence_ref != "string")
|
|
8
|
+
throw new Error("Highlight annotation requires a sentence_ref for timing");
|
|
9
|
+
e.quads.forEach((r, o) => {
|
|
10
|
+
if (typeof r != "object" || r === null || Array.isArray(r))
|
|
11
|
+
throw new Error(`Quad at index ${o} must be an object with {x, y, w, h} properties`);
|
|
12
|
+
const i = ["x", "y", "w", "h"];
|
|
13
|
+
for (const t of i) {
|
|
14
|
+
if (typeof r[t] != "number")
|
|
15
|
+
throw new Error(`Quad at index ${o} is missing required property '${t}' or it's not a number`);
|
|
16
|
+
if (r[t] < 0 || r[t] > 1)
|
|
17
|
+
throw new Error(`Quad property '${t}' at index ${o} must be between 0 and 1 (got ${r[t]})`);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const n = e.color || "rgba(255, 255, 0, 0.3)";
|
|
21
|
+
return {
|
|
22
|
+
id: h("highlight"),
|
|
23
|
+
type: "highlight",
|
|
24
|
+
mode: "quads",
|
|
25
|
+
// Required by HighlightLayer
|
|
26
|
+
page: e.page,
|
|
27
|
+
quads: e.quads,
|
|
28
|
+
// Array of {x, y, w, h} objects
|
|
29
|
+
style: {
|
|
30
|
+
color: n
|
|
31
|
+
// Color wrapped in style object
|
|
32
|
+
},
|
|
33
|
+
sentence_ref: e.sentence_ref
|
|
34
|
+
// Note: start/end will be added during timing sync phase
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
p as createHighlight
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index18.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index18.js","sources":["../src/ai-tools/creators/createHighlight.js"],"sourcesContent":["/**\n * Highlight Annotation Creator\n *\n * Converts AI-generated tool call arguments into valid highlight annotation objects\n * compatible with web-annotation-renderer library format.\n *\n * @module ai-tools/creators/createHighlight\n */\n\nimport { generateId } from '../../utils/idGenerator.js';\n\n/**\n * Create a highlight annotation from tool call arguments\n *\n * @param {Object} args - Tool call arguments from AI\n * @param {Array<Object>} args.quads - Rectangle objects with {x, y, w, h} (normalized 0-1)\n * @param {string} [args.color='rgba(255, 255, 0, 0.3)'] - Highlight color in rgba format\n * @param {number} args.page - Page number (1-indexed)\n * @param {string} args.sentence_ref - Sentence reference for timing (e.g., 'S1')\n * @returns {Object} Valid highlight annotation object\n * @example\n * ```javascript\n * const highlight = createHighlight({\n * quads: [{x: 0.1, y: 0.2, w: 0.8, h: 0.05}],\n * color: 'rgba(255, 255, 0, 0.3)',\n * page: 1,\n * sentence_ref: 'S2'\n * });\n * ```\n */\nexport function createHighlight(args) {\n // Validate required fields\n if (!args.quads || !Array.isArray(args.quads) || args.quads.length === 0) {\n throw new Error('Highlight annotation requires at least one quad');\n }\n\n if (!args.page || typeof args.page !== 'number' || args.page < 1) {\n throw new Error('Highlight annotation requires a valid page number (>= 1)');\n }\n\n if (!args.sentence_ref || typeof args.sentence_ref !== 'string') {\n throw new Error('Highlight annotation requires a sentence_ref for timing');\n }\n\n // Validate quad format - each quad must be an object with {x, y, w, h}\n args.quads.forEach((quad, index) => {\n if (typeof quad !== 'object' || quad === null || Array.isArray(quad)) {\n throw new Error(`Quad at index ${index} must be an object with {x, y, w, h} properties`);\n }\n\n const requiredProps = ['x', 'y', 'w', 'h'];\n for (const prop of requiredProps) {\n if (typeof quad[prop] !== 'number') {\n throw new Error(`Quad at index ${index} is missing required property '${prop}' or it's not a number`);\n }\n if (quad[prop] < 0 || quad[prop] > 1) {\n throw new Error(`Quad property '${prop}' at index ${index} must be between 0 and 1 (got ${quad[prop]})`);\n }\n }\n });\n\n // Validate color format (should be rgba)\n const color = args.color || 'rgba(255, 255, 0, 0.3)';\n\n // Create annotation object matching library format\n return {\n id: generateId('highlight'),\n type: 'highlight',\n mode: 'quads', // Required by HighlightLayer\n page: args.page,\n quads: args.quads, // Array of {x, y, w, h} objects\n style: {\n color: color // Color wrapped in style object\n },\n sentence_ref: args.sentence_ref,\n // Note: start/end will be added during timing sync phase\n };\n}\n"],"names":["createHighlight","args","quad","index","requiredProps","prop","color","generateId"],"mappings":";AA8BO,SAASA,EAAgBC,GAAM;AAEpC,MAAI,CAACA,EAAK,SAAS,CAAC,MAAM,QAAQA,EAAK,KAAK,KAAKA,EAAK,MAAM,WAAW;AACrE,UAAM,IAAI,MAAM,iDAAiD;AAGnE,MAAI,CAACA,EAAK,QAAQ,OAAOA,EAAK,QAAS,YAAYA,EAAK,OAAO;AAC7D,UAAM,IAAI,MAAM,0DAA0D;AAG5E,MAAI,CAACA,EAAK,gBAAgB,OAAOA,EAAK,gBAAiB;AACrD,UAAM,IAAI,MAAM,yDAAyD;AAI3E,EAAAA,EAAK,MAAM,QAAQ,CAACC,GAAMC,MAAU;AAClC,QAAI,OAAOD,KAAS,YAAYA,MAAS,QAAQ,MAAM,QAAQA,CAAI;AACjE,YAAM,IAAI,MAAM,iBAAiBC,CAAK,iDAAiD;AAGzF,UAAMC,IAAgB,CAAC,KAAK,KAAK,KAAK,GAAG;AACzC,eAAWC,KAAQD,GAAe;AAChC,UAAI,OAAOF,EAAKG,CAAI,KAAM;AACxB,cAAM,IAAI,MAAM,iBAAiBF,CAAK,kCAAkCE,CAAI,wBAAwB;AAEtG,UAAIH,EAAKG,CAAI,IAAI,KAAKH,EAAKG,CAAI,IAAI;AACjC,cAAM,IAAI,MAAM,kBAAkBA,CAAI,cAAcF,CAAK,iCAAiCD,EAAKG,CAAI,CAAC,GAAG;AAAA,IAE3G;AAAA,EACF,CAAC;AAGD,QAAMC,IAAQL,EAAK,SAAS;AAG5B,SAAO;AAAA,IACL,IAAIM,EAAW,WAAW;AAAA,IAC1B,MAAM;AAAA,IACN,MAAM;AAAA;AAAA,IACN,MAAMN,EAAK;AAAA,IACX,OAAOA,EAAK;AAAA;AAAA,IACZ,OAAO;AAAA,MACL,OAAOK;AAAA;AAAA,IACb;AAAA,IACI,cAAcL,EAAK;AAAA;AAAA,EAEvB;AACA;"}
|
package/dist/index19.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index22.cjs");function r(e){if(!e.content||typeof e.content!="string"||e.content.trim().length===0)throw new Error("Text annotation requires non-empty content");if(typeof e.x!="number"||e.x<0||e.x>1)throw new Error("Text annotation x position must be between 0 and 1");if(typeof e.y!="number"||e.y<0||e.y>1)throw new Error("Text annotation y position must be between 0 and 1");if(typeof e.w!="number"||e.w<0||e.w>1)throw new Error("Text annotation width (w) must be between 0 and 1");if(typeof e.h!="number"||e.h<0||e.h>1)throw new Error("Text annotation height (h) must be between 0 and 1");if(!e.page||typeof e.page!="number"||e.page<1)throw new Error("Text annotation requires a valid page number (>= 1)");if(!e.sentence_ref||typeof e.sentence_ref!="string")throw new Error("Text annotation requires a sentence_ref for timing");const t=e.textColor||"#1f2937",n=e.bgColor||"rgba(255, 255, 255, 0.9)";return{id:o.generateId("text"),type:"text",page:e.page,content:e.content.trim(),x:e.x,y:e.y,w:e.w,h:e.h,style:{bg:n,color:t},sentence_ref:e.sentence_ref}}exports.createText=r;
|
|
2
|
+
//# sourceMappingURL=index19.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index19.cjs","sources":["../src/ai-tools/creators/createText.js"],"sourcesContent":["/**\n * Text Annotation Creator\n *\n * Converts AI-generated tool call arguments into valid text annotation objects\n * compatible with web-annotation-renderer library format.\n *\n * @module ai-tools/creators/createText\n */\n\nimport { generateId } from '../../utils/idGenerator.js';\n\n/**\n * Create a text annotation from tool call arguments\n *\n * @param {Object} args - Tool call arguments from AI\n * @param {string} args.content - Text content\n * @param {number} args.x - Horizontal position (0-1)\n * @param {number} args.y - Vertical position (0-1)\n * @param {number} args.w - Width (0-1)\n * @param {number} args.h - Height (0-1)\n * @param {number} args.page - Page number (1-indexed)\n * @param {string} [args.textColor='#1f2937'] - Text color in hex format\n * @param {string} [args.bgColor='rgba(255, 255, 255, 0.9)'] - Background color in rgba format\n * @param {string} args.sentence_ref - Sentence reference for timing (e.g., 'S1')\n * @returns {Object} Valid text annotation object\n * @example\n * ```javascript\n * const textNote = createText({\n * content: 'This is important',\n * x: 0.1,\n * y: 0.5,\n * w: 0.3,\n * h: 0.1,\n * page: 1,\n * textColor: '#000000',\n * bgColor: 'rgba(255, 255, 255, 0.9)',\n * sentence_ref: 'S3'\n * });\n * ```\n */\nexport function createText(args) {\n // Validate required fields\n if (!args.content || typeof args.content !== 'string' || args.content.trim().length === 0) {\n throw new Error('Text annotation requires non-empty content');\n }\n\n if (typeof args.x !== 'number' || args.x < 0 || args.x > 1) {\n throw new Error('Text annotation x position must be between 0 and 1');\n }\n\n if (typeof args.y !== 'number' || args.y < 0 || args.y > 1) {\n throw new Error('Text annotation y position must be between 0 and 1');\n }\n\n if (typeof args.w !== 'number' || args.w < 0 || args.w > 1) {\n throw new Error('Text annotation width (w) must be between 0 and 1');\n }\n\n if (typeof args.h !== 'number' || args.h < 0 || args.h > 1) {\n throw new Error('Text annotation height (h) must be between 0 and 1');\n }\n\n if (!args.page || typeof args.page !== 'number' || args.page < 1) {\n throw new Error('Text annotation requires a valid page number (>= 1)');\n }\n\n if (!args.sentence_ref || typeof args.sentence_ref !== 'string') {\n throw new Error('Text annotation requires a sentence_ref for timing');\n }\n\n // Get colors with defaults\n const textColor = args.textColor || '#1f2937';\n const bgColor = args.bgColor || 'rgba(255, 255, 255, 0.9)';\n\n // Create annotation object matching library format\n return {\n id: generateId('text'),\n type: 'text', // Type name is 'text', not 'text_annotation'\n page: args.page,\n content: args.content.trim(),\n x: args.x, // Direct properties, not in position object\n y: args.y,\n w: args.w,\n h: args.h,\n style: { // Colors wrapped in style object\n bg: bgColor,\n color: textColor\n },\n sentence_ref: args.sentence_ref,\n // Note: start/end will be added during timing sync phase\n };\n}\n"],"names":["createText","args","textColor","bgColor","generateId"],"mappings":"iHAwCO,SAASA,EAAWC,EAAM,CAE/B,GAAI,CAACA,EAAK,SAAW,OAAOA,EAAK,SAAY,UAAYA,EAAK,QAAQ,OAAO,SAAW,EACtF,MAAM,IAAI,MAAM,4CAA4C,EAG9D,GAAI,OAAOA,EAAK,GAAM,UAAYA,EAAK,EAAI,GAAKA,EAAK,EAAI,EACvD,MAAM,IAAI,MAAM,oDAAoD,EAGtE,GAAI,OAAOA,EAAK,GAAM,UAAYA,EAAK,EAAI,GAAKA,EAAK,EAAI,EACvD,MAAM,IAAI,MAAM,oDAAoD,EAGtE,GAAI,OAAOA,EAAK,GAAM,UAAYA,EAAK,EAAI,GAAKA,EAAK,EAAI,EACvD,MAAM,IAAI,MAAM,mDAAmD,EAGrE,GAAI,OAAOA,EAAK,GAAM,UAAYA,EAAK,EAAI,GAAKA,EAAK,EAAI,EACvD,MAAM,IAAI,MAAM,oDAAoD,EAGtE,GAAI,CAACA,EAAK,MAAQ,OAAOA,EAAK,MAAS,UAAYA,EAAK,KAAO,EAC7D,MAAM,IAAI,MAAM,qDAAqD,EAGvE,GAAI,CAACA,EAAK,cAAgB,OAAOA,EAAK,cAAiB,SACrD,MAAM,IAAI,MAAM,oDAAoD,EAItE,MAAMC,EAAYD,EAAK,WAAa,UAC9BE,EAAUF,EAAK,SAAW,2BAGhC,MAAO,CACL,GAAIG,EAAAA,WAAW,MAAM,EACrB,KAAM,OACN,KAAMH,EAAK,KACX,QAASA,EAAK,QAAQ,KAAI,EAC1B,EAAGA,EAAK,EACR,EAAGA,EAAK,EACR,EAAGA,EAAK,EACR,EAAGA,EAAK,EACR,MAAO,CACL,GAAIE,EACJ,MAAOD,CACb,EACI,aAAcD,EAAK,YAEvB,CACA"}
|
package/dist/index19.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { generateId as o } from "./index22.js";
|
|
2
|
+
function i(e) {
|
|
3
|
+
if (!e.content || typeof e.content != "string" || e.content.trim().length === 0)
|
|
4
|
+
throw new Error("Text annotation requires non-empty content");
|
|
5
|
+
if (typeof e.x != "number" || e.x < 0 || e.x > 1)
|
|
6
|
+
throw new Error("Text annotation x position must be between 0 and 1");
|
|
7
|
+
if (typeof e.y != "number" || e.y < 0 || e.y > 1)
|
|
8
|
+
throw new Error("Text annotation y position must be between 0 and 1");
|
|
9
|
+
if (typeof e.w != "number" || e.w < 0 || e.w > 1)
|
|
10
|
+
throw new Error("Text annotation width (w) must be between 0 and 1");
|
|
11
|
+
if (typeof e.h != "number" || e.h < 0 || e.h > 1)
|
|
12
|
+
throw new Error("Text annotation height (h) must be between 0 and 1");
|
|
13
|
+
if (!e.page || typeof e.page != "number" || e.page < 1)
|
|
14
|
+
throw new Error("Text annotation requires a valid page number (>= 1)");
|
|
15
|
+
if (!e.sentence_ref || typeof e.sentence_ref != "string")
|
|
16
|
+
throw new Error("Text annotation requires a sentence_ref for timing");
|
|
17
|
+
const t = e.textColor || "#1f2937", n = e.bgColor || "rgba(255, 255, 255, 0.9)";
|
|
18
|
+
return {
|
|
19
|
+
id: o("text"),
|
|
20
|
+
type: "text",
|
|
21
|
+
// Type name is 'text', not 'text_annotation'
|
|
22
|
+
page: e.page,
|
|
23
|
+
content: e.content.trim(),
|
|
24
|
+
x: e.x,
|
|
25
|
+
// Direct properties, not in position object
|
|
26
|
+
y: e.y,
|
|
27
|
+
w: e.w,
|
|
28
|
+
h: e.h,
|
|
29
|
+
style: {
|
|
30
|
+
// Colors wrapped in style object
|
|
31
|
+
bg: n,
|
|
32
|
+
color: t
|
|
33
|
+
},
|
|
34
|
+
sentence_ref: e.sentence_ref
|
|
35
|
+
// Note: start/end will be added during timing sync phase
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
i as createText
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index19.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index19.js","sources":["../src/ai-tools/creators/createText.js"],"sourcesContent":["/**\n * Text Annotation Creator\n *\n * Converts AI-generated tool call arguments into valid text annotation objects\n * compatible with web-annotation-renderer library format.\n *\n * @module ai-tools/creators/createText\n */\n\nimport { generateId } from '../../utils/idGenerator.js';\n\n/**\n * Create a text annotation from tool call arguments\n *\n * @param {Object} args - Tool call arguments from AI\n * @param {string} args.content - Text content\n * @param {number} args.x - Horizontal position (0-1)\n * @param {number} args.y - Vertical position (0-1)\n * @param {number} args.w - Width (0-1)\n * @param {number} args.h - Height (0-1)\n * @param {number} args.page - Page number (1-indexed)\n * @param {string} [args.textColor='#1f2937'] - Text color in hex format\n * @param {string} [args.bgColor='rgba(255, 255, 255, 0.9)'] - Background color in rgba format\n * @param {string} args.sentence_ref - Sentence reference for timing (e.g., 'S1')\n * @returns {Object} Valid text annotation object\n * @example\n * ```javascript\n * const textNote = createText({\n * content: 'This is important',\n * x: 0.1,\n * y: 0.5,\n * w: 0.3,\n * h: 0.1,\n * page: 1,\n * textColor: '#000000',\n * bgColor: 'rgba(255, 255, 255, 0.9)',\n * sentence_ref: 'S3'\n * });\n * ```\n */\nexport function createText(args) {\n // Validate required fields\n if (!args.content || typeof args.content !== 'string' || args.content.trim().length === 0) {\n throw new Error('Text annotation requires non-empty content');\n }\n\n if (typeof args.x !== 'number' || args.x < 0 || args.x > 1) {\n throw new Error('Text annotation x position must be between 0 and 1');\n }\n\n if (typeof args.y !== 'number' || args.y < 0 || args.y > 1) {\n throw new Error('Text annotation y position must be between 0 and 1');\n }\n\n if (typeof args.w !== 'number' || args.w < 0 || args.w > 1) {\n throw new Error('Text annotation width (w) must be between 0 and 1');\n }\n\n if (typeof args.h !== 'number' || args.h < 0 || args.h > 1) {\n throw new Error('Text annotation height (h) must be between 0 and 1');\n }\n\n if (!args.page || typeof args.page !== 'number' || args.page < 1) {\n throw new Error('Text annotation requires a valid page number (>= 1)');\n }\n\n if (!args.sentence_ref || typeof args.sentence_ref !== 'string') {\n throw new Error('Text annotation requires a sentence_ref for timing');\n }\n\n // Get colors with defaults\n const textColor = args.textColor || '#1f2937';\n const bgColor = args.bgColor || 'rgba(255, 255, 255, 0.9)';\n\n // Create annotation object matching library format\n return {\n id: generateId('text'),\n type: 'text', // Type name is 'text', not 'text_annotation'\n page: args.page,\n content: args.content.trim(),\n x: args.x, // Direct properties, not in position object\n y: args.y,\n w: args.w,\n h: args.h,\n style: { // Colors wrapped in style object\n bg: bgColor,\n color: textColor\n },\n sentence_ref: args.sentence_ref,\n // Note: start/end will be added during timing sync phase\n };\n}\n"],"names":["createText","args","textColor","bgColor","generateId"],"mappings":";AAwCO,SAASA,EAAWC,GAAM;AAE/B,MAAI,CAACA,EAAK,WAAW,OAAOA,EAAK,WAAY,YAAYA,EAAK,QAAQ,OAAO,WAAW;AACtF,UAAM,IAAI,MAAM,4CAA4C;AAG9D,MAAI,OAAOA,EAAK,KAAM,YAAYA,EAAK,IAAI,KAAKA,EAAK,IAAI;AACvD,UAAM,IAAI,MAAM,oDAAoD;AAGtE,MAAI,OAAOA,EAAK,KAAM,YAAYA,EAAK,IAAI,KAAKA,EAAK,IAAI;AACvD,UAAM,IAAI,MAAM,oDAAoD;AAGtE,MAAI,OAAOA,EAAK,KAAM,YAAYA,EAAK,IAAI,KAAKA,EAAK,IAAI;AACvD,UAAM,IAAI,MAAM,mDAAmD;AAGrE,MAAI,OAAOA,EAAK,KAAM,YAAYA,EAAK,IAAI,KAAKA,EAAK,IAAI;AACvD,UAAM,IAAI,MAAM,oDAAoD;AAGtE,MAAI,CAACA,EAAK,QAAQ,OAAOA,EAAK,QAAS,YAAYA,EAAK,OAAO;AAC7D,UAAM,IAAI,MAAM,qDAAqD;AAGvE,MAAI,CAACA,EAAK,gBAAgB,OAAOA,EAAK,gBAAiB;AACrD,UAAM,IAAI,MAAM,oDAAoD;AAItE,QAAMC,IAAYD,EAAK,aAAa,WAC9BE,IAAUF,EAAK,WAAW;AAGhC,SAAO;AAAA,IACL,IAAIG,EAAW,MAAM;AAAA,IACrB,MAAM;AAAA;AAAA,IACN,MAAMH,EAAK;AAAA,IACX,SAASA,EAAK,QAAQ,KAAI;AAAA,IAC1B,GAAGA,EAAK;AAAA;AAAA,IACR,GAAGA,EAAK;AAAA,IACR,GAAGA,EAAK;AAAA,IACR,GAAGA,EAAK;AAAA,IACR,OAAO;AAAA;AAAA,MACL,IAAIE;AAAA,MACJ,OAAOD;AAAA,IACb;AAAA,IACI,cAAcD,EAAK;AAAA;AAAA,EAEvB;AACA;"}
|
package/dist/index20.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./index22.cjs");function w(e){if(!e.strokes||!Array.isArray(e.strokes)||e.strokes.length===0)throw new Error("Ink annotation requires at least one stroke");if(!e.page||typeof e.page!="number"||e.page<1)throw new Error("Ink annotation requires a valid page number (>= 1)");if(!e.sentence_ref||typeof e.sentence_ref!="string")throw new Error("Ink annotation requires a sentence_ref for timing");return e.strokes.forEach((r,o)=>{if(typeof r!="object"||r===null||Array.isArray(r))throw new Error(`Stroke at index ${o} must be an object with {color, size, points} properties`);if(!r.points||!Array.isArray(r.points)||r.points.length<2)throw new Error(`Stroke at index ${o} must have at least 2 points`);r.points.forEach((t,n)=>{if(typeof t!="object"||t===null)throw new Error(`Point at stroke[${o}][${n}] must be an object with {t, x, y} properties`);const a=["t","x","y"];for(const s of a)if(typeof t[s]!="number")throw new Error(`Point at stroke[${o}][${n}] is missing required property '${s}' or it's not a number`);if(t.t<0)throw new Error(`Point time offset (t) at stroke[${o}][${n}] must be >= 0 (got ${t.t})`);if(t.x<0||t.x>1)throw new Error(`Point x coordinate at stroke[${o}][${n}] must be between 0 and 1 (got ${t.x})`);if(t.y<0||t.y>1)throw new Error(`Point y coordinate at stroke[${o}][${n}] must be between 0 and 1 (got ${t.y})`)});const i=r.size||3;if(i<1||i>10)throw new Error(`Stroke size at index ${o} must be between 1 and 10 pixels (got ${i})`)}),{id:f.generateId("ink"),type:"ink",page:e.page,strokes:e.strokes.map(r=>({color:r.color||"#1f2937",size:r.size||3,points:r.points})),sentence_ref:e.sentence_ref}}exports.createInk=w;
|
|
2
|
+
//# sourceMappingURL=index20.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index20.cjs","sources":["../src/ai-tools/creators/createInk.js"],"sourcesContent":["/**\n * Ink Annotation Creator\n *\n * Converts AI-generated tool call arguments into valid ink/drawing annotation objects\n * compatible with web-annotation-renderer library format.\n *\n * @module ai-tools/creators/createInk\n */\n\nimport { generateId } from '../../utils/idGenerator.js';\n\n/**\n * Create an ink (drawing) annotation from tool call arguments\n *\n * @param {Object} args - Tool call arguments from AI\n * @param {Array<Object>} args.strokes - Array of stroke objects with color, size, and points\n * @param {number} args.page - Page number (1-indexed)\n * @param {string} args.sentence_ref - Sentence reference for timing (e.g., 'S1')\n * @returns {Object} Valid ink annotation object\n * @example\n * ```javascript\n * const drawing = createInk({\n * strokes: [\n * {\n * color: '#FF0000',\n * size: 2,\n * points: [\n * {t: 0, x: 0.1, y: 0.1},\n * {t: 0.5, x: 0.2, y: 0.2}\n * ]\n * }\n * ],\n * page: 1,\n * sentence_ref: 'S4'\n * });\n * ```\n */\nexport function createInk(args) {\n // Validate required fields\n if (!args.strokes || !Array.isArray(args.strokes) || args.strokes.length === 0) {\n throw new Error('Ink annotation requires at least one stroke');\n }\n\n if (!args.page || typeof args.page !== 'number' || args.page < 1) {\n throw new Error('Ink annotation requires a valid page number (>= 1)');\n }\n\n if (!args.sentence_ref || typeof args.sentence_ref !== 'string') {\n throw new Error('Ink annotation requires a sentence_ref for timing');\n }\n\n // Validate stroke format - each stroke must be an object\n args.strokes.forEach((stroke, index) => {\n if (typeof stroke !== 'object' || stroke === null || Array.isArray(stroke)) {\n throw new Error(`Stroke at index ${index} must be an object with {color, size, points} properties`);\n }\n\n // Validate points array\n if (!stroke.points || !Array.isArray(stroke.points) || stroke.points.length < 2) {\n throw new Error(`Stroke at index ${index} must have at least 2 points`);\n }\n\n // Validate each point\n stroke.points.forEach((point, pointIndex) => {\n if (typeof point !== 'object' || point === null) {\n throw new Error(`Point at stroke[${index}][${pointIndex}] must be an object with {t, x, y} properties`);\n }\n\n const requiredProps = ['t', 'x', 'y'];\n for (const prop of requiredProps) {\n if (typeof point[prop] !== 'number') {\n throw new Error(`Point at stroke[${index}][${pointIndex}] is missing required property '${prop}' or it's not a number`);\n }\n }\n\n // Validate time offset (t >= 0)\n if (point.t < 0) {\n throw new Error(`Point time offset (t) at stroke[${index}][${pointIndex}] must be >= 0 (got ${point.t})`);\n }\n\n // Validate x and y coordinates (0-1)\n if (point.x < 0 || point.x > 1) {\n throw new Error(`Point x coordinate at stroke[${index}][${pointIndex}] must be between 0 and 1 (got ${point.x})`);\n }\n if (point.y < 0 || point.y > 1) {\n throw new Error(`Point y coordinate at stroke[${index}][${pointIndex}] must be between 0 and 1 (got ${point.y})`);\n }\n });\n\n // Validate size\n const size = stroke.size || 3;\n if (size < 1 || size > 10) {\n throw new Error(`Stroke size at index ${index} must be between 1 and 10 pixels (got ${size})`);\n }\n });\n\n // Create annotation object matching library format\n return {\n id: generateId('ink'),\n type: 'ink',\n page: args.page,\n strokes: args.strokes.map(stroke => ({\n color: stroke.color || '#1f2937', // Default dark gray\n size: stroke.size || 3, // Default 3px\n points: stroke.points // Array of {t, x, y} objects\n })),\n sentence_ref: args.sentence_ref,\n // Note: start/end will be added during timing sync phase\n };\n}\n"],"names":["createInk","args","stroke","index","point","pointIndex","requiredProps","prop","size","generateId"],"mappings":"iHAqCO,SAASA,EAAUC,EAAM,CAE9B,GAAI,CAACA,EAAK,SAAW,CAAC,MAAM,QAAQA,EAAK,OAAO,GAAKA,EAAK,QAAQ,SAAW,EAC3E,MAAM,IAAI,MAAM,6CAA6C,EAG/D,GAAI,CAACA,EAAK,MAAQ,OAAOA,EAAK,MAAS,UAAYA,EAAK,KAAO,EAC7D,MAAM,IAAI,MAAM,oDAAoD,EAGtE,GAAI,CAACA,EAAK,cAAgB,OAAOA,EAAK,cAAiB,SACrD,MAAM,IAAI,MAAM,mDAAmD,EAIrE,OAAAA,EAAK,QAAQ,QAAQ,CAACC,EAAQC,IAAU,CACtC,GAAI,OAAOD,GAAW,UAAYA,IAAW,MAAQ,MAAM,QAAQA,CAAM,EACvE,MAAM,IAAI,MAAM,mBAAmBC,CAAK,0DAA0D,EAIpG,GAAI,CAACD,EAAO,QAAU,CAAC,MAAM,QAAQA,EAAO,MAAM,GAAKA,EAAO,OAAO,OAAS,EAC5E,MAAM,IAAI,MAAM,mBAAmBC,CAAK,8BAA8B,EAIxED,EAAO,OAAO,QAAQ,CAACE,EAAOC,IAAe,CAC3C,GAAI,OAAOD,GAAU,UAAYA,IAAU,KACzC,MAAM,IAAI,MAAM,mBAAmBD,CAAK,KAAKE,CAAU,+CAA+C,EAGxG,MAAMC,EAAgB,CAAC,IAAK,IAAK,GAAG,EACpC,UAAWC,KAAQD,EACjB,GAAI,OAAOF,EAAMG,CAAI,GAAM,SACzB,MAAM,IAAI,MAAM,mBAAmBJ,CAAK,KAAKE,CAAU,mCAAmCE,CAAI,wBAAwB,EAK1H,GAAIH,EAAM,EAAI,EACZ,MAAM,IAAI,MAAM,mCAAmCD,CAAK,KAAKE,CAAU,uBAAuBD,EAAM,CAAC,GAAG,EAI1G,GAAIA,EAAM,EAAI,GAAKA,EAAM,EAAI,EAC3B,MAAM,IAAI,MAAM,gCAAgCD,CAAK,KAAKE,CAAU,kCAAkCD,EAAM,CAAC,GAAG,EAElH,GAAIA,EAAM,EAAI,GAAKA,EAAM,EAAI,EAC3B,MAAM,IAAI,MAAM,gCAAgCD,CAAK,KAAKE,CAAU,kCAAkCD,EAAM,CAAC,GAAG,CAEpH,CAAC,EAGD,MAAMI,EAAON,EAAO,MAAQ,EAC5B,GAAIM,EAAO,GAAKA,EAAO,GACrB,MAAM,IAAI,MAAM,wBAAwBL,CAAK,yCAAyCK,CAAI,GAAG,CAEjG,CAAC,EAGM,CACL,GAAIC,EAAAA,WAAW,KAAK,EACpB,KAAM,MACN,KAAMR,EAAK,KACX,QAASA,EAAK,QAAQ,IAAIC,IAAW,CACnC,MAAOA,EAAO,OAAS,UACvB,KAAMA,EAAO,MAAQ,EACrB,OAAQA,EAAO,MACrB,EAAM,EACF,aAAcD,EAAK,YAEvB,CACA"}
|
package/dist/index20.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { generateId as f } from "./index22.js";
|
|
2
|
+
function c(e) {
|
|
3
|
+
if (!e.strokes || !Array.isArray(e.strokes) || e.strokes.length === 0)
|
|
4
|
+
throw new Error("Ink annotation requires at least one stroke");
|
|
5
|
+
if (!e.page || typeof e.page != "number" || e.page < 1)
|
|
6
|
+
throw new Error("Ink annotation requires a valid page number (>= 1)");
|
|
7
|
+
if (!e.sentence_ref || typeof e.sentence_ref != "string")
|
|
8
|
+
throw new Error("Ink annotation requires a sentence_ref for timing");
|
|
9
|
+
return e.strokes.forEach((r, o) => {
|
|
10
|
+
if (typeof r != "object" || r === null || Array.isArray(r))
|
|
11
|
+
throw new Error(`Stroke at index ${o} must be an object with {color, size, points} properties`);
|
|
12
|
+
if (!r.points || !Array.isArray(r.points) || r.points.length < 2)
|
|
13
|
+
throw new Error(`Stroke at index ${o} must have at least 2 points`);
|
|
14
|
+
r.points.forEach((t, n) => {
|
|
15
|
+
if (typeof t != "object" || t === null)
|
|
16
|
+
throw new Error(`Point at stroke[${o}][${n}] must be an object with {t, x, y} properties`);
|
|
17
|
+
const a = ["t", "x", "y"];
|
|
18
|
+
for (const i of a)
|
|
19
|
+
if (typeof t[i] != "number")
|
|
20
|
+
throw new Error(`Point at stroke[${o}][${n}] is missing required property '${i}' or it's not a number`);
|
|
21
|
+
if (t.t < 0)
|
|
22
|
+
throw new Error(`Point time offset (t) at stroke[${o}][${n}] must be >= 0 (got ${t.t})`);
|
|
23
|
+
if (t.x < 0 || t.x > 1)
|
|
24
|
+
throw new Error(`Point x coordinate at stroke[${o}][${n}] must be between 0 and 1 (got ${t.x})`);
|
|
25
|
+
if (t.y < 0 || t.y > 1)
|
|
26
|
+
throw new Error(`Point y coordinate at stroke[${o}][${n}] must be between 0 and 1 (got ${t.y})`);
|
|
27
|
+
});
|
|
28
|
+
const s = r.size || 3;
|
|
29
|
+
if (s < 1 || s > 10)
|
|
30
|
+
throw new Error(`Stroke size at index ${o} must be between 1 and 10 pixels (got ${s})`);
|
|
31
|
+
}), {
|
|
32
|
+
id: f("ink"),
|
|
33
|
+
type: "ink",
|
|
34
|
+
page: e.page,
|
|
35
|
+
strokes: e.strokes.map((r) => ({
|
|
36
|
+
color: r.color || "#1f2937",
|
|
37
|
+
// Default dark gray
|
|
38
|
+
size: r.size || 3,
|
|
39
|
+
// Default 3px
|
|
40
|
+
points: r.points
|
|
41
|
+
// Array of {t, x, y} objects
|
|
42
|
+
})),
|
|
43
|
+
sentence_ref: e.sentence_ref
|
|
44
|
+
// Note: start/end will be added during timing sync phase
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
c as createInk
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=index20.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index20.js","sources":["../src/ai-tools/creators/createInk.js"],"sourcesContent":["/**\n * Ink Annotation Creator\n *\n * Converts AI-generated tool call arguments into valid ink/drawing annotation objects\n * compatible with web-annotation-renderer library format.\n *\n * @module ai-tools/creators/createInk\n */\n\nimport { generateId } from '../../utils/idGenerator.js';\n\n/**\n * Create an ink (drawing) annotation from tool call arguments\n *\n * @param {Object} args - Tool call arguments from AI\n * @param {Array<Object>} args.strokes - Array of stroke objects with color, size, and points\n * @param {number} args.page - Page number (1-indexed)\n * @param {string} args.sentence_ref - Sentence reference for timing (e.g., 'S1')\n * @returns {Object} Valid ink annotation object\n * @example\n * ```javascript\n * const drawing = createInk({\n * strokes: [\n * {\n * color: '#FF0000',\n * size: 2,\n * points: [\n * {t: 0, x: 0.1, y: 0.1},\n * {t: 0.5, x: 0.2, y: 0.2}\n * ]\n * }\n * ],\n * page: 1,\n * sentence_ref: 'S4'\n * });\n * ```\n */\nexport function createInk(args) {\n // Validate required fields\n if (!args.strokes || !Array.isArray(args.strokes) || args.strokes.length === 0) {\n throw new Error('Ink annotation requires at least one stroke');\n }\n\n if (!args.page || typeof args.page !== 'number' || args.page < 1) {\n throw new Error('Ink annotation requires a valid page number (>= 1)');\n }\n\n if (!args.sentence_ref || typeof args.sentence_ref !== 'string') {\n throw new Error('Ink annotation requires a sentence_ref for timing');\n }\n\n // Validate stroke format - each stroke must be an object\n args.strokes.forEach((stroke, index) => {\n if (typeof stroke !== 'object' || stroke === null || Array.isArray(stroke)) {\n throw new Error(`Stroke at index ${index} must be an object with {color, size, points} properties`);\n }\n\n // Validate points array\n if (!stroke.points || !Array.isArray(stroke.points) || stroke.points.length < 2) {\n throw new Error(`Stroke at index ${index} must have at least 2 points`);\n }\n\n // Validate each point\n stroke.points.forEach((point, pointIndex) => {\n if (typeof point !== 'object' || point === null) {\n throw new Error(`Point at stroke[${index}][${pointIndex}] must be an object with {t, x, y} properties`);\n }\n\n const requiredProps = ['t', 'x', 'y'];\n for (const prop of requiredProps) {\n if (typeof point[prop] !== 'number') {\n throw new Error(`Point at stroke[${index}][${pointIndex}] is missing required property '${prop}' or it's not a number`);\n }\n }\n\n // Validate time offset (t >= 0)\n if (point.t < 0) {\n throw new Error(`Point time offset (t) at stroke[${index}][${pointIndex}] must be >= 0 (got ${point.t})`);\n }\n\n // Validate x and y coordinates (0-1)\n if (point.x < 0 || point.x > 1) {\n throw new Error(`Point x coordinate at stroke[${index}][${pointIndex}] must be between 0 and 1 (got ${point.x})`);\n }\n if (point.y < 0 || point.y > 1) {\n throw new Error(`Point y coordinate at stroke[${index}][${pointIndex}] must be between 0 and 1 (got ${point.y})`);\n }\n });\n\n // Validate size\n const size = stroke.size || 3;\n if (size < 1 || size > 10) {\n throw new Error(`Stroke size at index ${index} must be between 1 and 10 pixels (got ${size})`);\n }\n });\n\n // Create annotation object matching library format\n return {\n id: generateId('ink'),\n type: 'ink',\n page: args.page,\n strokes: args.strokes.map(stroke => ({\n color: stroke.color || '#1f2937', // Default dark gray\n size: stroke.size || 3, // Default 3px\n points: stroke.points // Array of {t, x, y} objects\n })),\n sentence_ref: args.sentence_ref,\n // Note: start/end will be added during timing sync phase\n };\n}\n"],"names":["createInk","args","stroke","index","point","pointIndex","requiredProps","prop","size","generateId"],"mappings":";AAqCO,SAASA,EAAUC,GAAM;AAE9B,MAAI,CAACA,EAAK,WAAW,CAAC,MAAM,QAAQA,EAAK,OAAO,KAAKA,EAAK,QAAQ,WAAW;AAC3E,UAAM,IAAI,MAAM,6CAA6C;AAG/D,MAAI,CAACA,EAAK,QAAQ,OAAOA,EAAK,QAAS,YAAYA,EAAK,OAAO;AAC7D,UAAM,IAAI,MAAM,oDAAoD;AAGtE,MAAI,CAACA,EAAK,gBAAgB,OAAOA,EAAK,gBAAiB;AACrD,UAAM,IAAI,MAAM,mDAAmD;AAIrE,SAAAA,EAAK,QAAQ,QAAQ,CAACC,GAAQC,MAAU;AACtC,QAAI,OAAOD,KAAW,YAAYA,MAAW,QAAQ,MAAM,QAAQA,CAAM;AACvE,YAAM,IAAI,MAAM,mBAAmBC,CAAK,0DAA0D;AAIpG,QAAI,CAACD,EAAO,UAAU,CAAC,MAAM,QAAQA,EAAO,MAAM,KAAKA,EAAO,OAAO,SAAS;AAC5E,YAAM,IAAI,MAAM,mBAAmBC,CAAK,8BAA8B;AAIxE,IAAAD,EAAO,OAAO,QAAQ,CAACE,GAAOC,MAAe;AAC3C,UAAI,OAAOD,KAAU,YAAYA,MAAU;AACzC,cAAM,IAAI,MAAM,mBAAmBD,CAAK,KAAKE,CAAU,+CAA+C;AAGxG,YAAMC,IAAgB,CAAC,KAAK,KAAK,GAAG;AACpC,iBAAWC,KAAQD;AACjB,YAAI,OAAOF,EAAMG,CAAI,KAAM;AACzB,gBAAM,IAAI,MAAM,mBAAmBJ,CAAK,KAAKE,CAAU,mCAAmCE,CAAI,wBAAwB;AAK1H,UAAIH,EAAM,IAAI;AACZ,cAAM,IAAI,MAAM,mCAAmCD,CAAK,KAAKE,CAAU,uBAAuBD,EAAM,CAAC,GAAG;AAI1G,UAAIA,EAAM,IAAI,KAAKA,EAAM,IAAI;AAC3B,cAAM,IAAI,MAAM,gCAAgCD,CAAK,KAAKE,CAAU,kCAAkCD,EAAM,CAAC,GAAG;AAElH,UAAIA,EAAM,IAAI,KAAKA,EAAM,IAAI;AAC3B,cAAM,IAAI,MAAM,gCAAgCD,CAAK,KAAKE,CAAU,kCAAkCD,EAAM,CAAC,GAAG;AAAA,IAEpH,CAAC;AAGD,UAAMI,IAAON,EAAO,QAAQ;AAC5B,QAAIM,IAAO,KAAKA,IAAO;AACrB,YAAM,IAAI,MAAM,wBAAwBL,CAAK,yCAAyCK,CAAI,GAAG;AAAA,EAEjG,CAAC,GAGM;AAAA,IACL,IAAIC,EAAW,KAAK;AAAA,IACpB,MAAM;AAAA,IACN,MAAMR,EAAK;AAAA,IACX,SAASA,EAAK,QAAQ,IAAI,CAAAC,OAAW;AAAA,MACnC,OAAOA,EAAO,SAAS;AAAA;AAAA,MACvB,MAAMA,EAAO,QAAQ;AAAA;AAAA,MACrB,QAAQA,EAAO;AAAA;AAAA,IACrB,EAAM;AAAA,IACF,cAAcD,EAAK;AAAA;AAAA,EAEvB;AACA;"}
|
package/dist/index21.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t={page:1,start:0,end:0},o={mode:"quads",quads:[{x:.1,y:.1,w:.8,h:.05}],style:{color:"rgba(255, 255, 0, 0.3)"}},e={content:"[No content]",x:.1,y:.1,w:.3,h:.1,style:{bg:"rgba(255, 255, 255, 0.9)",color:"#000000"}},s={strokes:[{color:"#1f2937",size:3,points:[{t:0,x:.1,y:.1},{t:1,x:.2,y:.2}]}]};exports.BASE_DEFAULTS=t;exports.HIGHLIGHT_DEFAULTS=o;exports.INK_DEFAULTS=s;exports.TEXT_DEFAULTS=e;
|
|
2
|
+
//# sourceMappingURL=index21.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index21.cjs","sources":["../src/types/defaults.js"],"sourcesContent":["/**\n * Default Values for Annotation Normalization\n *\n * This module defines default values used when annotation fields are missing\n * or invalid. These defaults ensure annotations render visibly and safely.\n *\n * @module types/defaults\n */\n\n/**\n * Default values for base annotation fields (common to all types)\n *\n * @constant {Object}\n * @property {number} page - Default page number (first page)\n * @property {number} start - Default start time (display immediately)\n * @property {number} end - Default end time (static display, no animation)\n */\nexport const BASE_DEFAULTS = {\n page: 1,\n start: 0,\n end: 0\n};\n\n/**\n * Default values for highlight annotations\n *\n * Creates a visible yellow highlight near the top of the page.\n *\n * @constant {Object}\n * @property {string} mode - Highlight mode (only 'quads' supported)\n * @property {Array<Object>} quads - Default rectangular regions\n * @property {Object} style - Default styling\n */\nexport const HIGHLIGHT_DEFAULTS = {\n mode: 'quads',\n quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],\n style: { color: 'rgba(255, 255, 0, 0.3)' }\n};\n\n/**\n * Default values for text annotations\n *\n * Creates a visible text box in the top-left with placeholder content.\n *\n * @constant {Object}\n * @property {string} content - Placeholder text\n * @property {number} x - Normalized x position (10% from left)\n * @property {number} y - Normalized y position (10% from top)\n * @property {number} w - Normalized width (30% of page width)\n * @property {number} h - Normalized height (10% of page height)\n * @property {Object} style - Default styling with white background and black text\n */\nexport const TEXT_DEFAULTS = {\n content: '[No content]',\n x: 0.1,\n y: 0.1,\n w: 0.3,\n h: 0.1,\n style: {\n bg: 'rgba(255, 255, 255, 0.9)',\n color: '#000000'\n }\n};\n\n/**\n * Default values for ink annotations\n *\n * Creates a visible diagonal line in dark gray.\n *\n * @constant {Object}\n * @property {Array<Object>} strokes - Default stroke with two points\n */\nexport const INK_DEFAULTS = {\n strokes: [{\n color: '#1f2937',\n size: 3,\n points: [\n { t: 0, x: 0.1, y: 0.1 },\n { t: 1, x: 0.2, y: 0.2 }\n ]\n }]\n};\n"],"names":["BASE_DEFAULTS","HIGHLIGHT_DEFAULTS","TEXT_DEFAULTS","INK_DEFAULTS"],"mappings":"gFAiBY,MAACA,EAAgB,CAC3B,KAAM,EACN,MAAO,EACP,IAAK,CACP,EAYaC,EAAqB,CAChC,KAAM,QACN,MAAO,CAAC,CAAE,EAAG,GAAK,EAAG,GAAK,EAAG,GAAK,EAAG,IAAM,EAC3C,MAAO,CAAE,MAAO,wBAAwB,CAC1C,EAeaC,EAAgB,CAC3B,QAAS,eACT,EAAG,GACH,EAAG,GACH,EAAG,GACH,EAAG,GACH,MAAO,CACL,GAAI,2BACJ,MAAO,SACX,CACA,EAUaC,EAAe,CAC1B,QAAS,CAAC,CACR,MAAO,UACP,KAAM,EACN,OAAQ,CACN,CAAE,EAAG,EAAG,EAAG,GAAK,EAAG,EAAG,EACtB,CAAE,EAAG,EAAG,EAAG,GAAK,EAAG,EAAG,CAC5B,CACA,CAAG,CACH"}
|
package/dist/index21.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const o = {
|
|
2
|
+
page: 1,
|
|
3
|
+
start: 0,
|
|
4
|
+
end: 0
|
|
5
|
+
}, t = {
|
|
6
|
+
mode: "quads",
|
|
7
|
+
quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],
|
|
8
|
+
style: { color: "rgba(255, 255, 0, 0.3)" }
|
|
9
|
+
}, s = {
|
|
10
|
+
content: "[No content]",
|
|
11
|
+
x: 0.1,
|
|
12
|
+
y: 0.1,
|
|
13
|
+
w: 0.3,
|
|
14
|
+
h: 0.1,
|
|
15
|
+
style: {
|
|
16
|
+
bg: "rgba(255, 255, 255, 0.9)",
|
|
17
|
+
color: "#000000"
|
|
18
|
+
}
|
|
19
|
+
}, e = {
|
|
20
|
+
strokes: [{
|
|
21
|
+
color: "#1f2937",
|
|
22
|
+
size: 3,
|
|
23
|
+
points: [
|
|
24
|
+
{ t: 0, x: 0.1, y: 0.1 },
|
|
25
|
+
{ t: 1, x: 0.2, y: 0.2 }
|
|
26
|
+
]
|
|
27
|
+
}]
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
o as BASE_DEFAULTS,
|
|
31
|
+
t as HIGHLIGHT_DEFAULTS,
|
|
32
|
+
e as INK_DEFAULTS,
|
|
33
|
+
s as TEXT_DEFAULTS
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index21.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index21.js","sources":["../src/types/defaults.js"],"sourcesContent":["/**\n * Default Values for Annotation Normalization\n *\n * This module defines default values used when annotation fields are missing\n * or invalid. These defaults ensure annotations render visibly and safely.\n *\n * @module types/defaults\n */\n\n/**\n * Default values for base annotation fields (common to all types)\n *\n * @constant {Object}\n * @property {number} page - Default page number (first page)\n * @property {number} start - Default start time (display immediately)\n * @property {number} end - Default end time (static display, no animation)\n */\nexport const BASE_DEFAULTS = {\n page: 1,\n start: 0,\n end: 0\n};\n\n/**\n * Default values for highlight annotations\n *\n * Creates a visible yellow highlight near the top of the page.\n *\n * @constant {Object}\n * @property {string} mode - Highlight mode (only 'quads' supported)\n * @property {Array<Object>} quads - Default rectangular regions\n * @property {Object} style - Default styling\n */\nexport const HIGHLIGHT_DEFAULTS = {\n mode: 'quads',\n quads: [{ x: 0.1, y: 0.1, w: 0.8, h: 0.05 }],\n style: { color: 'rgba(255, 255, 0, 0.3)' }\n};\n\n/**\n * Default values for text annotations\n *\n * Creates a visible text box in the top-left with placeholder content.\n *\n * @constant {Object}\n * @property {string} content - Placeholder text\n * @property {number} x - Normalized x position (10% from left)\n * @property {number} y - Normalized y position (10% from top)\n * @property {number} w - Normalized width (30% of page width)\n * @property {number} h - Normalized height (10% of page height)\n * @property {Object} style - Default styling with white background and black text\n */\nexport const TEXT_DEFAULTS = {\n content: '[No content]',\n x: 0.1,\n y: 0.1,\n w: 0.3,\n h: 0.1,\n style: {\n bg: 'rgba(255, 255, 255, 0.9)',\n color: '#000000'\n }\n};\n\n/**\n * Default values for ink annotations\n *\n * Creates a visible diagonal line in dark gray.\n *\n * @constant {Object}\n * @property {Array<Object>} strokes - Default stroke with two points\n */\nexport const INK_DEFAULTS = {\n strokes: [{\n color: '#1f2937',\n size: 3,\n points: [\n { t: 0, x: 0.1, y: 0.1 },\n { t: 1, x: 0.2, y: 0.2 }\n ]\n }]\n};\n"],"names":["BASE_DEFAULTS","HIGHLIGHT_DEFAULTS","TEXT_DEFAULTS","INK_DEFAULTS"],"mappings":"AAiBY,MAACA,IAAgB;AAAA,EAC3B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AACP,GAYaC,IAAqB;AAAA,EAChC,MAAM;AAAA,EACN,OAAO,CAAC,EAAE,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM;AAAA,EAC3C,OAAO,EAAE,OAAO,yBAAwB;AAC1C,GAeaC,IAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,OAAO;AAAA,IACL,IAAI;AAAA,IACJ,OAAO;AAAA,EACX;AACA,GAUaC,IAAe;AAAA,EAC1B,SAAS,CAAC;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,IAAG;AAAA,MACtB,EAAE,GAAG,GAAG,GAAG,KAAK,GAAG,IAAG;AAAA,IAC5B;AAAA,EACA,CAAG;AACH;"}
|
package/dist/index22.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index22.cjs","sources":["../src/utils/idGenerator.js"],"sourcesContent":["/**\n * ID Generator Utility\n *\n * Generates unique IDs for annotations.\n *\n * @module utils/idGenerator\n */\n\n/**\n * Generate a unique ID for an annotation\n *\n * @param {string} [prefix='anno'] - ID prefix (e.g., 'highlight', 'text', 'ink')\n * @returns {string} Unique annotation ID\n * @example\n * ```javascript\n * const id = generateId('highlight');\n * // Returns: \"highlight-1234567890abc\"\n * ```\n */\nexport function generateId(prefix = 'anno') {\n const timestamp = Date.now().toString(36);\n const random = Math.random().toString(36).substring(2, 9);\n return `${prefix}-${timestamp}${random}`;\n}\n"],"names":["generateId","prefix","timestamp","random"],"mappings":"gFAmBO,SAASA,EAAWC,EAAS,OAAQ,CAC1C,MAAMC,EAAY,KAAK,IAAG,EAAG,SAAS,EAAE,EAClCC,EAAS,KAAK,SAAS,SAAS,EAAE,EAAE,UAAU,EAAG,CAAC,EACxD,MAAO,GAAGF,CAAM,IAAIC,CAAS,GAAGC,CAAM,EACxC"}
|
package/dist/index22.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index22.js","sources":["../src/utils/idGenerator.js"],"sourcesContent":["/**\n * ID Generator Utility\n *\n * Generates unique IDs for annotations.\n *\n * @module utils/idGenerator\n */\n\n/**\n * Generate a unique ID for an annotation\n *\n * @param {string} [prefix='anno'] - ID prefix (e.g., 'highlight', 'text', 'ink')\n * @returns {string} Unique annotation ID\n * @example\n * ```javascript\n * const id = generateId('highlight');\n * // Returns: \"highlight-1234567890abc\"\n * ```\n */\nexport function generateId(prefix = 'anno') {\n const timestamp = Date.now().toString(36);\n const random = Math.random().toString(36).substring(2, 9);\n return `${prefix}-${timestamp}${random}`;\n}\n"],"names":["generateId","prefix","timestamp","random"],"mappings":"AAmBO,SAASA,EAAWC,IAAS,QAAQ;AAC1C,QAAMC,IAAY,KAAK,IAAG,EAAG,SAAS,EAAE,GAClCC,IAAS,KAAK,SAAS,SAAS,EAAE,EAAE,UAAU,GAAG,CAAC;AACxD,SAAO,GAAGF,CAAM,IAAIC,CAAS,GAAGC,CAAM;AACxC;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "web-annotation-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Framework-agnostic PDF annotation renderer with timeline synchronization for educational content and interactive documents",
|
|
6
6
|
"keywords": [
|
|
@@ -38,10 +38,15 @@
|
|
|
38
38
|
"import": "./dist/index.js",
|
|
39
39
|
"require": "./dist/index.cjs"
|
|
40
40
|
},
|
|
41
|
+
"./ai-tools": {
|
|
42
|
+
"import": "./ai-tools.js",
|
|
43
|
+
"require": "./dist/index16.cjs"
|
|
44
|
+
},
|
|
41
45
|
"./package.json": "./package.json"
|
|
42
46
|
},
|
|
43
47
|
"files": [
|
|
44
48
|
"dist/",
|
|
49
|
+
"ai-tools.js",
|
|
45
50
|
"README.md",
|
|
46
51
|
"LICENSE",
|
|
47
52
|
"CHANGELOG.md"
|