web-annotation-renderer 0.5.1 → 0.5.2

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.
Files changed (71) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +39 -33
  4. package/dist/index.js.map +1 -1
  5. package/dist/index10.cjs +1 -1
  6. package/dist/index10.cjs.map +1 -1
  7. package/dist/index10.js +154 -119
  8. package/dist/index10.js.map +1 -1
  9. package/dist/index11.cjs +1 -1
  10. package/dist/index11.js +1 -1
  11. package/dist/index12.cjs +1 -1
  12. package/dist/index12.js +1 -1
  13. package/dist/index14.cjs +1 -1
  14. package/dist/index14.js +1 -1
  15. package/dist/index15.cjs +1 -1
  16. package/dist/index15.cjs.map +1 -1
  17. package/dist/index15.js +23 -117
  18. package/dist/index15.js.map +1 -1
  19. package/dist/index16.cjs +1 -1
  20. package/dist/index16.cjs.map +1 -1
  21. package/dist/index16.js +53 -103
  22. package/dist/index16.js.map +1 -1
  23. package/dist/index17.cjs +1 -1
  24. package/dist/index17.cjs.map +1 -1
  25. package/dist/index17.js +22 -57
  26. package/dist/index17.js.map +1 -1
  27. package/dist/index18.cjs +1 -1
  28. package/dist/index18.cjs.map +1 -1
  29. package/dist/index18.js +113 -136
  30. package/dist/index18.js.map +1 -1
  31. package/dist/index19.cjs +1 -1
  32. package/dist/index19.cjs.map +1 -1
  33. package/dist/index19.js +101 -35
  34. package/dist/index19.js.map +1 -1
  35. package/dist/index20.cjs +1 -1
  36. package/dist/index20.cjs.map +1 -1
  37. package/dist/index20.js +58 -36
  38. package/dist/index20.js.map +1 -1
  39. package/dist/index21.cjs +1 -1
  40. package/dist/index21.cjs.map +1 -1
  41. package/dist/index21.js +140 -37
  42. package/dist/index21.js.map +1 -1
  43. package/dist/index22.cjs +1 -1
  44. package/dist/index22.cjs.map +1 -1
  45. package/dist/index22.js +37 -21
  46. package/dist/index22.js.map +1 -1
  47. package/dist/index23.cjs +1 -1
  48. package/dist/index23.cjs.map +1 -1
  49. package/dist/index23.js +37 -5
  50. package/dist/index23.js.map +1 -1
  51. package/dist/index24.cjs +1 -1
  52. package/dist/index24.cjs.map +1 -1
  53. package/dist/index24.js +37 -4
  54. package/dist/index24.js.map +1 -1
  55. package/dist/index25.cjs +2 -0
  56. package/dist/index25.cjs.map +1 -0
  57. package/dist/index25.js +43 -0
  58. package/dist/index25.js.map +1 -0
  59. package/dist/index26.cjs +2 -0
  60. package/dist/index26.cjs.map +1 -0
  61. package/dist/index26.js +8 -0
  62. package/dist/index26.js.map +1 -0
  63. package/dist/index27.cjs +2 -0
  64. package/dist/index27.cjs.map +1 -0
  65. package/dist/index27.js +8 -0
  66. package/dist/index27.js.map +1 -0
  67. package/dist/index5.cjs +1 -1
  68. package/dist/index5.cjs.map +1 -1
  69. package/dist/index5.js +57 -36
  70. package/dist/index5.js.map +1 -1
  71. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index19.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';\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 default:\n throw new Error(`Unknown tool: ${name}. Supported tools: create_highlight_annotation, create_text_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","handleToolCalls","toolCalls","index"],"mappings":"4IAwCO,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,QACE,MAAM,IAAI,MAAM,iBAAiBF,CAAI,wEAAwE,CACnH,CACA,CAYO,SAASM,EAAgBC,EAAW,CACzC,GAAI,CAAC,MAAM,QAAQA,CAAS,EAC1B,MAAM,IAAI,MAAM,6BAA6B,EAG/C,OAAOA,EAAU,IAAI,CAACR,EAAUS,IAAU,CACxC,GAAI,CACF,OAAOV,EAAeC,CAAQ,CAChC,OAASI,EAAO,CACd,MAAM,IAAI,MAAM,uCAAuCK,CAAK,KAAKL,EAAM,OAAO,EAAE,CAClF,CACF,CAAC,CACH"}
1
+ {"version":3,"file":"index19.cjs","sources":["../src/pen/StrokeDrawer.js"],"sourcesContent":["/**\n * StrokeDrawer - Low-level canvas stroke drawing utilities\n *\n * Handles the actual drawing of strokes on canvas with support for:\n * - Progressive stroke reveal (partial drawing based on progress)\n * - Normalized to pixel coordinate conversion\n * - Variable width based on pressure data\n * - Smooth line rendering with round caps/joins\n */\nclass StrokeDrawer {\n /**\n * Creates a new StrokeDrawer instance\n *\n * @param {CanvasRenderingContext2D} ctx - Canvas 2D rendering context\n * @param {Object} viewport - Viewport dimensions for coordinate conversion\n * @param {number} viewport.width - Viewport width in pixels\n * @param {number} viewport.height - Viewport height in pixels\n */\n constructor(ctx, viewport) {\n this.ctx = ctx;\n this.viewport = viewport;\n }\n\n /**\n * Updates the viewport dimensions\n *\n * @param {Object} viewport - New viewport dimensions\n */\n setViewport(viewport) {\n this.viewport = viewport;\n }\n\n /**\n * Draws a stroke with optional progress for progressive reveal\n *\n * @param {Object} stroke - Stroke command object\n * @param {Array} stroke.points - Array of [x, y] normalized coordinates\n * @param {string} stroke.color - Stroke color (CSS color string)\n * @param {number} stroke.width - Base stroke width in pixels\n * @param {Array} [stroke.pressures] - Optional pressure values for variable width\n * @param {number} [progress=1.0] - Progress from 0 to 1 (for progressive reveal)\n */\n drawStroke(stroke, progress = 1.0) {\n const { points, color, width, pressures } = stroke;\n\n if (!points || points.length < 2) return;\n\n // Calculate how many points to draw based on progress\n const pointCount = Math.max(2, Math.floor(points.length * progress));\n const visiblePoints = points.slice(0, pointCount);\n\n // Configure stroke style\n this.ctx.strokeStyle = color || 'rgba(0, 0, 0, 0.5)';\n this.ctx.lineCap = 'round';\n this.ctx.lineJoin = 'round';\n\n // Draw with variable width if pressures provided\n if (pressures && pressures.length >= visiblePoints.length) {\n this._drawVariableWidthStroke(visiblePoints, width, pressures.slice(0, pointCount));\n } else {\n this._drawConstantWidthStroke(visiblePoints, width);\n }\n }\n\n /**\n * Draws a stroke with constant width\n *\n * @private\n * @param {Array} points - Array of [x, y] normalized coordinates\n * @param {number} width - Stroke width in pixels\n */\n _drawConstantWidthStroke(points, width) {\n this.ctx.lineWidth = width || 2;\n this.ctx.beginPath();\n\n for (let i = 0; i < points.length; i++) {\n const [px, py] = this._normalizedToPixel(points[i]);\n\n if (i === 0) {\n this.ctx.moveTo(px, py);\n } else {\n this.ctx.lineTo(px, py);\n }\n }\n\n this.ctx.stroke();\n }\n\n /**\n * Draws a stroke with variable width based on pressure\n *\n * Uses multiple line segments with varying widths for natural pen feel.\n *\n * @private\n * @param {Array} points - Array of [x, y] normalized coordinates\n * @param {number} baseWidth - Base stroke width in pixels\n * @param {Array} pressures - Pressure values (0-1) for each point\n */\n _drawVariableWidthStroke(points, baseWidth, pressures) {\n for (let i = 1; i < points.length; i++) {\n const [x1, y1] = this._normalizedToPixel(points[i - 1]);\n const [x2, y2] = this._normalizedToPixel(points[i]);\n\n // Average pressure between two points\n const p1 = pressures[i - 1] || 1;\n const p2 = pressures[i] || 1;\n const avgPressure = (p1 + p2) / 2;\n\n // Apply pressure to width (min 0.5, max 2x base width)\n const width = Math.max(0.5, baseWidth * avgPressure);\n\n this.ctx.lineWidth = width;\n this.ctx.beginPath();\n this.ctx.moveTo(x1, y1);\n this.ctx.lineTo(x2, y2);\n this.ctx.stroke();\n }\n }\n\n /**\n * Draws a single point (dot)\n *\n * Useful for single-point strokes or debugging.\n *\n * @param {number} x - Normalized x coordinate (0-1)\n * @param {number} y - Normalized y coordinate (0-1)\n * @param {number} radius - Dot radius in pixels\n * @param {string} color - Fill color\n */\n drawPoint(x, y, radius, color) {\n const [px, py] = this._normalizedToPixel([x, y]);\n\n this.ctx.fillStyle = color || 'rgba(0, 0, 0, 0.5)';\n this.ctx.beginPath();\n this.ctx.arc(px, py, radius, 0, Math.PI * 2);\n this.ctx.fill();\n }\n\n /**\n * Clears the entire canvas\n */\n clear() {\n const dpr = window.devicePixelRatio || 1;\n this.ctx.clearRect(0, 0, this.viewport.width * dpr, this.viewport.height * dpr);\n }\n\n /**\n * Converts normalized coordinates (0-1) to pixel coordinates\n *\n * @private\n * @param {Array} point - [x, y] normalized coordinates\n * @returns {Array} [x, y] pixel coordinates\n */\n _normalizedToPixel(point) {\n const [normX, normY] = point;\n return [\n normX * this.viewport.width,\n normY * this.viewport.height\n ];\n }\n}\n\nexport default StrokeDrawer;\n"],"names":["StrokeDrawer","ctx","viewport","stroke","progress","points","color","width","pressures","pointCount","visiblePoints","px","py","baseWidth","i","x1","y1","x2","y2","p1","p2","avgPressure","x","y","radius","dpr","point","normX","normY"],"mappings":"4GASA,MAAMA,CAAa,CASjB,YAAYC,EAAKC,EAAU,CACzB,KAAK,IAAMD,EACX,KAAK,SAAWC,CAClB,CAOA,YAAYA,EAAU,CACpB,KAAK,SAAWA,CAClB,CAYA,WAAWC,EAAQC,EAAW,EAAK,CACjC,KAAM,CAAE,OAAAC,EAAQ,MAAAC,EAAO,MAAAC,EAAO,UAAAC,CAAS,EAAKL,EAE5C,GAAI,CAACE,GAAUA,EAAO,OAAS,EAAG,OAGlC,MAAMI,EAAa,KAAK,IAAI,EAAG,KAAK,MAAMJ,EAAO,OAASD,CAAQ,CAAC,EAC7DM,EAAgBL,EAAO,MAAM,EAAGI,CAAU,EAGhD,KAAK,IAAI,YAAcH,GAAS,qBAChC,KAAK,IAAI,QAAU,QACnB,KAAK,IAAI,SAAW,QAGhBE,GAAaA,EAAU,QAAUE,EAAc,OACjD,KAAK,yBAAyBA,EAAeH,EAAOC,EAAU,MAAM,EAAGC,CAAU,CAAC,EAElF,KAAK,yBAAyBC,EAAeH,CAAK,CAEtD,CASA,yBAAyBF,EAAQE,EAAO,CACtC,KAAK,IAAI,UAAYA,GAAS,EAC9B,KAAK,IAAI,UAAS,EAElB,QAAS,EAAI,EAAG,EAAIF,EAAO,OAAQ,IAAK,CACtC,KAAM,CAACM,EAAIC,CAAE,EAAI,KAAK,mBAAmBP,EAAO,CAAC,CAAC,EAE9C,IAAM,EACR,KAAK,IAAI,OAAOM,EAAIC,CAAE,EAEtB,KAAK,IAAI,OAAOD,EAAIC,CAAE,CAE1B,CAEA,KAAK,IAAI,OAAM,CACjB,CAYA,yBAAyBP,EAAQQ,EAAWL,EAAW,CACrD,QAASM,EAAI,EAAGA,EAAIT,EAAO,OAAQS,IAAK,CACtC,KAAM,CAACC,EAAIC,CAAE,EAAI,KAAK,mBAAmBX,EAAOS,EAAI,CAAC,CAAC,EAChD,CAACG,EAAIC,CAAE,EAAI,KAAK,mBAAmBb,EAAOS,CAAC,CAAC,EAG5CK,EAAKX,EAAUM,EAAI,CAAC,GAAK,EACzBM,EAAKZ,EAAUM,CAAC,GAAK,EACrBO,GAAeF,EAAKC,GAAM,EAG1Bb,EAAQ,KAAK,IAAI,GAAKM,EAAYQ,CAAW,EAEnD,KAAK,IAAI,UAAYd,EACrB,KAAK,IAAI,UAAS,EAClB,KAAK,IAAI,OAAOQ,EAAIC,CAAE,EACtB,KAAK,IAAI,OAAOC,EAAIC,CAAE,EACtB,KAAK,IAAI,OAAM,CACjB,CACF,CAYA,UAAUI,EAAGC,EAAGC,EAAQlB,EAAO,CAC7B,KAAM,CAACK,EAAIC,CAAE,EAAI,KAAK,mBAAmB,CAACU,EAAGC,CAAC,CAAC,EAE/C,KAAK,IAAI,UAAYjB,GAAS,qBAC9B,KAAK,IAAI,UAAS,EAClB,KAAK,IAAI,IAAIK,EAAIC,EAAIY,EAAQ,EAAG,KAAK,GAAK,CAAC,EAC3C,KAAK,IAAI,KAAI,CACf,CAKA,OAAQ,CACN,MAAMC,EAAM,OAAO,kBAAoB,EACvC,KAAK,IAAI,UAAU,EAAG,EAAG,KAAK,SAAS,MAAQA,EAAK,KAAK,SAAS,OAASA,CAAG,CAChF,CASA,mBAAmBC,EAAO,CACxB,KAAM,CAACC,EAAOC,CAAK,EAAIF,EACvB,MAAO,CACLC,EAAQ,KAAK,SAAS,MACtBC,EAAQ,KAAK,SAAS,MAC5B,CACE,CACF"}
package/dist/index19.js CHANGED
@@ -1,41 +1,107 @@
1
- import { createHighlight as a } from "./index20.js";
2
- import { createText as i } from "./index21.js";
3
- function c(r) {
4
- if (!r || typeof r != "object")
5
- throw new Error("Invalid tool call: must be an object");
6
- if (!r.function || typeof r.function != "object")
7
- throw new Error("Invalid tool call: missing function property");
8
- const { name: t, arguments: o } = r.function;
9
- if (!t || typeof t != "string")
10
- throw new Error("Invalid tool call: missing or invalid function name");
11
- let n;
12
- try {
13
- n = typeof o == "string" ? JSON.parse(o) : o;
14
- } catch (e) {
15
- throw new Error(`Failed to parse tool call arguments: ${e.message}`);
16
- }
17
- switch (t) {
18
- case "create_highlight_annotation":
19
- return a(n);
20
- case "create_text_annotation":
21
- return i(n);
22
- default:
23
- throw new Error(`Unknown tool: ${t}. Supported tools: create_highlight_annotation, create_text_annotation`);
1
+ class w {
2
+ /**
3
+ * Creates a new StrokeDrawer instance
4
+ *
5
+ * @param {CanvasRenderingContext2D} ctx - Canvas 2D rendering context
6
+ * @param {Object} viewport - Viewport dimensions for coordinate conversion
7
+ * @param {number} viewport.width - Viewport width in pixels
8
+ * @param {number} viewport.height - Viewport height in pixels
9
+ */
10
+ constructor(t, o) {
11
+ this.ctx = t, this.viewport = o;
24
12
  }
25
- }
26
- function h(r) {
27
- if (!Array.isArray(r))
28
- throw new Error("Tool calls must be an array");
29
- return r.map((t, o) => {
30
- try {
31
- return c(t);
32
- } catch (n) {
33
- throw new Error(`Error processing tool call at index ${o}: ${n.message}`);
13
+ /**
14
+ * Updates the viewport dimensions
15
+ *
16
+ * @param {Object} viewport - New viewport dimensions
17
+ */
18
+ setViewport(t) {
19
+ this.viewport = t;
20
+ }
21
+ /**
22
+ * Draws a stroke with optional progress for progressive reveal
23
+ *
24
+ * @param {Object} stroke - Stroke command object
25
+ * @param {Array} stroke.points - Array of [x, y] normalized coordinates
26
+ * @param {string} stroke.color - Stroke color (CSS color string)
27
+ * @param {number} stroke.width - Base stroke width in pixels
28
+ * @param {Array} [stroke.pressures] - Optional pressure values for variable width
29
+ * @param {number} [progress=1.0] - Progress from 0 to 1 (for progressive reveal)
30
+ */
31
+ drawStroke(t, o = 1) {
32
+ const { points: i, color: e, width: s, pressures: h } = t;
33
+ if (!i || i.length < 2) return;
34
+ const n = Math.max(2, Math.floor(i.length * o)), r = i.slice(0, n);
35
+ this.ctx.strokeStyle = e || "rgba(0, 0, 0, 0.5)", this.ctx.lineCap = "round", this.ctx.lineJoin = "round", h && h.length >= r.length ? this._drawVariableWidthStroke(r, s, h.slice(0, n)) : this._drawConstantWidthStroke(r, s);
36
+ }
37
+ /**
38
+ * Draws a stroke with constant width
39
+ *
40
+ * @private
41
+ * @param {Array} points - Array of [x, y] normalized coordinates
42
+ * @param {number} width - Stroke width in pixels
43
+ */
44
+ _drawConstantWidthStroke(t, o) {
45
+ this.ctx.lineWidth = o || 2, this.ctx.beginPath();
46
+ for (let i = 0; i < t.length; i++) {
47
+ const [e, s] = this._normalizedToPixel(t[i]);
48
+ i === 0 ? this.ctx.moveTo(e, s) : this.ctx.lineTo(e, s);
49
+ }
50
+ this.ctx.stroke();
51
+ }
52
+ /**
53
+ * Draws a stroke with variable width based on pressure
54
+ *
55
+ * Uses multiple line segments with varying widths for natural pen feel.
56
+ *
57
+ * @private
58
+ * @param {Array} points - Array of [x, y] normalized coordinates
59
+ * @param {number} baseWidth - Base stroke width in pixels
60
+ * @param {Array} pressures - Pressure values (0-1) for each point
61
+ */
62
+ _drawVariableWidthStroke(t, o, i) {
63
+ for (let e = 1; e < t.length; e++) {
64
+ const [s, h] = this._normalizedToPixel(t[e - 1]), [n, r] = this._normalizedToPixel(t[e]), l = i[e - 1] || 1, c = i[e] || 1, a = (l + c) / 2, x = Math.max(0.5, o * a);
65
+ this.ctx.lineWidth = x, this.ctx.beginPath(), this.ctx.moveTo(s, h), this.ctx.lineTo(n, r), this.ctx.stroke();
34
66
  }
35
- });
67
+ }
68
+ /**
69
+ * Draws a single point (dot)
70
+ *
71
+ * Useful for single-point strokes or debugging.
72
+ *
73
+ * @param {number} x - Normalized x coordinate (0-1)
74
+ * @param {number} y - Normalized y coordinate (0-1)
75
+ * @param {number} radius - Dot radius in pixels
76
+ * @param {string} color - Fill color
77
+ */
78
+ drawPoint(t, o, i, e) {
79
+ const [s, h] = this._normalizedToPixel([t, o]);
80
+ this.ctx.fillStyle = e || "rgba(0, 0, 0, 0.5)", this.ctx.beginPath(), this.ctx.arc(s, h, i, 0, Math.PI * 2), this.ctx.fill();
81
+ }
82
+ /**
83
+ * Clears the entire canvas
84
+ */
85
+ clear() {
86
+ const t = window.devicePixelRatio || 1;
87
+ this.ctx.clearRect(0, 0, this.viewport.width * t, this.viewport.height * t);
88
+ }
89
+ /**
90
+ * Converts normalized coordinates (0-1) to pixel coordinates
91
+ *
92
+ * @private
93
+ * @param {Array} point - [x, y] normalized coordinates
94
+ * @returns {Array} [x, y] pixel coordinates
95
+ */
96
+ _normalizedToPixel(t) {
97
+ const [o, i] = t;
98
+ return [
99
+ o * this.viewport.width,
100
+ i * this.viewport.height
101
+ ];
102
+ }
36
103
  }
37
104
  export {
38
- c as handleToolCall,
39
- h as handleToolCalls
105
+ w as default
40
106
  };
41
107
  //# sourceMappingURL=index19.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index19.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';\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 default:\n throw new Error(`Unknown tool: ${name}. Supported tools: create_highlight_annotation, create_text_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","handleToolCalls","toolCalls","index"],"mappings":";;AAwCO,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;AACE,YAAM,IAAI,MAAM,iBAAiBF,CAAI,wEAAwE;AAAA,EACnH;AACA;AAYO,SAASM,EAAgBC,GAAW;AACzC,MAAI,CAAC,MAAM,QAAQA,CAAS;AAC1B,UAAM,IAAI,MAAM,6BAA6B;AAG/C,SAAOA,EAAU,IAAI,CAACR,GAAUS,MAAU;AACxC,QAAI;AACF,aAAOV,EAAeC,CAAQ;AAAA,IAChC,SAASI,GAAO;AACd,YAAM,IAAI,MAAM,uCAAuCK,CAAK,KAAKL,EAAM,OAAO,EAAE;AAAA,IAClF;AAAA,EACF,CAAC;AACH;"}
1
+ {"version":3,"file":"index19.js","sources":["../src/pen/StrokeDrawer.js"],"sourcesContent":["/**\n * StrokeDrawer - Low-level canvas stroke drawing utilities\n *\n * Handles the actual drawing of strokes on canvas with support for:\n * - Progressive stroke reveal (partial drawing based on progress)\n * - Normalized to pixel coordinate conversion\n * - Variable width based on pressure data\n * - Smooth line rendering with round caps/joins\n */\nclass StrokeDrawer {\n /**\n * Creates a new StrokeDrawer instance\n *\n * @param {CanvasRenderingContext2D} ctx - Canvas 2D rendering context\n * @param {Object} viewport - Viewport dimensions for coordinate conversion\n * @param {number} viewport.width - Viewport width in pixels\n * @param {number} viewport.height - Viewport height in pixels\n */\n constructor(ctx, viewport) {\n this.ctx = ctx;\n this.viewport = viewport;\n }\n\n /**\n * Updates the viewport dimensions\n *\n * @param {Object} viewport - New viewport dimensions\n */\n setViewport(viewport) {\n this.viewport = viewport;\n }\n\n /**\n * Draws a stroke with optional progress for progressive reveal\n *\n * @param {Object} stroke - Stroke command object\n * @param {Array} stroke.points - Array of [x, y] normalized coordinates\n * @param {string} stroke.color - Stroke color (CSS color string)\n * @param {number} stroke.width - Base stroke width in pixels\n * @param {Array} [stroke.pressures] - Optional pressure values for variable width\n * @param {number} [progress=1.0] - Progress from 0 to 1 (for progressive reveal)\n */\n drawStroke(stroke, progress = 1.0) {\n const { points, color, width, pressures } = stroke;\n\n if (!points || points.length < 2) return;\n\n // Calculate how many points to draw based on progress\n const pointCount = Math.max(2, Math.floor(points.length * progress));\n const visiblePoints = points.slice(0, pointCount);\n\n // Configure stroke style\n this.ctx.strokeStyle = color || 'rgba(0, 0, 0, 0.5)';\n this.ctx.lineCap = 'round';\n this.ctx.lineJoin = 'round';\n\n // Draw with variable width if pressures provided\n if (pressures && pressures.length >= visiblePoints.length) {\n this._drawVariableWidthStroke(visiblePoints, width, pressures.slice(0, pointCount));\n } else {\n this._drawConstantWidthStroke(visiblePoints, width);\n }\n }\n\n /**\n * Draws a stroke with constant width\n *\n * @private\n * @param {Array} points - Array of [x, y] normalized coordinates\n * @param {number} width - Stroke width in pixels\n */\n _drawConstantWidthStroke(points, width) {\n this.ctx.lineWidth = width || 2;\n this.ctx.beginPath();\n\n for (let i = 0; i < points.length; i++) {\n const [px, py] = this._normalizedToPixel(points[i]);\n\n if (i === 0) {\n this.ctx.moveTo(px, py);\n } else {\n this.ctx.lineTo(px, py);\n }\n }\n\n this.ctx.stroke();\n }\n\n /**\n * Draws a stroke with variable width based on pressure\n *\n * Uses multiple line segments with varying widths for natural pen feel.\n *\n * @private\n * @param {Array} points - Array of [x, y] normalized coordinates\n * @param {number} baseWidth - Base stroke width in pixels\n * @param {Array} pressures - Pressure values (0-1) for each point\n */\n _drawVariableWidthStroke(points, baseWidth, pressures) {\n for (let i = 1; i < points.length; i++) {\n const [x1, y1] = this._normalizedToPixel(points[i - 1]);\n const [x2, y2] = this._normalizedToPixel(points[i]);\n\n // Average pressure between two points\n const p1 = pressures[i - 1] || 1;\n const p2 = pressures[i] || 1;\n const avgPressure = (p1 + p2) / 2;\n\n // Apply pressure to width (min 0.5, max 2x base width)\n const width = Math.max(0.5, baseWidth * avgPressure);\n\n this.ctx.lineWidth = width;\n this.ctx.beginPath();\n this.ctx.moveTo(x1, y1);\n this.ctx.lineTo(x2, y2);\n this.ctx.stroke();\n }\n }\n\n /**\n * Draws a single point (dot)\n *\n * Useful for single-point strokes or debugging.\n *\n * @param {number} x - Normalized x coordinate (0-1)\n * @param {number} y - Normalized y coordinate (0-1)\n * @param {number} radius - Dot radius in pixels\n * @param {string} color - Fill color\n */\n drawPoint(x, y, radius, color) {\n const [px, py] = this._normalizedToPixel([x, y]);\n\n this.ctx.fillStyle = color || 'rgba(0, 0, 0, 0.5)';\n this.ctx.beginPath();\n this.ctx.arc(px, py, radius, 0, Math.PI * 2);\n this.ctx.fill();\n }\n\n /**\n * Clears the entire canvas\n */\n clear() {\n const dpr = window.devicePixelRatio || 1;\n this.ctx.clearRect(0, 0, this.viewport.width * dpr, this.viewport.height * dpr);\n }\n\n /**\n * Converts normalized coordinates (0-1) to pixel coordinates\n *\n * @private\n * @param {Array} point - [x, y] normalized coordinates\n * @returns {Array} [x, y] pixel coordinates\n */\n _normalizedToPixel(point) {\n const [normX, normY] = point;\n return [\n normX * this.viewport.width,\n normY * this.viewport.height\n ];\n }\n}\n\nexport default StrokeDrawer;\n"],"names":["StrokeDrawer","ctx","viewport","stroke","progress","points","color","width","pressures","pointCount","visiblePoints","px","py","baseWidth","i","x1","y1","x2","y2","p1","p2","avgPressure","x","y","radius","dpr","point","normX","normY"],"mappings":"AASA,MAAMA,EAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASjB,YAAYC,GAAKC,GAAU;AACzB,SAAK,MAAMD,GACX,KAAK,WAAWC;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAYA,GAAU;AACpB,SAAK,WAAWA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,WAAWC,GAAQC,IAAW,GAAK;AACjC,UAAM,EAAE,QAAAC,GAAQ,OAAAC,GAAO,OAAAC,GAAO,WAAAC,EAAS,IAAKL;AAE5C,QAAI,CAACE,KAAUA,EAAO,SAAS,EAAG;AAGlC,UAAMI,IAAa,KAAK,IAAI,GAAG,KAAK,MAAMJ,EAAO,SAASD,CAAQ,CAAC,GAC7DM,IAAgBL,EAAO,MAAM,GAAGI,CAAU;AAGhD,SAAK,IAAI,cAAcH,KAAS,sBAChC,KAAK,IAAI,UAAU,SACnB,KAAK,IAAI,WAAW,SAGhBE,KAAaA,EAAU,UAAUE,EAAc,SACjD,KAAK,yBAAyBA,GAAeH,GAAOC,EAAU,MAAM,GAAGC,CAAU,CAAC,IAElF,KAAK,yBAAyBC,GAAeH,CAAK;AAAA,EAEtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,yBAAyBF,GAAQE,GAAO;AACtC,SAAK,IAAI,YAAYA,KAAS,GAC9B,KAAK,IAAI,UAAS;AAElB,aAAS,IAAI,GAAG,IAAIF,EAAO,QAAQ,KAAK;AACtC,YAAM,CAACM,GAAIC,CAAE,IAAI,KAAK,mBAAmBP,EAAO,CAAC,CAAC;AAElD,MAAI,MAAM,IACR,KAAK,IAAI,OAAOM,GAAIC,CAAE,IAEtB,KAAK,IAAI,OAAOD,GAAIC,CAAE;AAAA,IAE1B;AAEA,SAAK,IAAI,OAAM;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,yBAAyBP,GAAQQ,GAAWL,GAAW;AACrD,aAASM,IAAI,GAAGA,IAAIT,EAAO,QAAQS,KAAK;AACtC,YAAM,CAACC,GAAIC,CAAE,IAAI,KAAK,mBAAmBX,EAAOS,IAAI,CAAC,CAAC,GAChD,CAACG,GAAIC,CAAE,IAAI,KAAK,mBAAmBb,EAAOS,CAAC,CAAC,GAG5CK,IAAKX,EAAUM,IAAI,CAAC,KAAK,GACzBM,IAAKZ,EAAUM,CAAC,KAAK,GACrBO,KAAeF,IAAKC,KAAM,GAG1Bb,IAAQ,KAAK,IAAI,KAAKM,IAAYQ,CAAW;AAEnD,WAAK,IAAI,YAAYd,GACrB,KAAK,IAAI,UAAS,GAClB,KAAK,IAAI,OAAOQ,GAAIC,CAAE,GACtB,KAAK,IAAI,OAAOC,GAAIC,CAAE,GACtB,KAAK,IAAI,OAAM;AAAA,IACjB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,UAAUI,GAAGC,GAAGC,GAAQlB,GAAO;AAC7B,UAAM,CAACK,GAAIC,CAAE,IAAI,KAAK,mBAAmB,CAACU,GAAGC,CAAC,CAAC;AAE/C,SAAK,IAAI,YAAYjB,KAAS,sBAC9B,KAAK,IAAI,UAAS,GAClB,KAAK,IAAI,IAAIK,GAAIC,GAAIY,GAAQ,GAAG,KAAK,KAAK,CAAC,GAC3C,KAAK,IAAI,KAAI;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ;AACN,UAAMC,IAAM,OAAO,oBAAoB;AACvC,SAAK,IAAI,UAAU,GAAG,GAAG,KAAK,SAAS,QAAQA,GAAK,KAAK,SAAS,SAASA,CAAG;AAAA,EAChF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,mBAAmBC,GAAO;AACxB,UAAM,CAACC,GAAOC,CAAK,IAAIF;AACvB,WAAO;AAAA,MACLC,IAAQ,KAAK,SAAS;AAAA,MACtBC,IAAQ,KAAK,SAAS;AAAA,IAC5B;AAAA,EACE;AACF;"}
package/dist/index20.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index24.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;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e={name:"default",highlight:{color:"rgba(255, 255, 0, 0.3)",width:24},handText:{color:"rgba(220, 20, 60, 1.0)",width:2},ink:{color:"rgba(31, 41, 55, 1.0)",width:3}},r={name:"blue",highlight:{color:"rgba(100, 149, 237, 0.35)",width:24},handText:{color:"rgba(30, 64, 175, 1.0)",width:2},ink:{color:"rgba(30, 64, 175, 1.0)",width:3}},o={name:"minimal",highlight:{color:"rgba(156, 163, 175, 0.25)",width:20},handText:{color:"rgba(75, 85, 99, 1.0)",width:1.5},ink:{color:"rgba(75, 85, 99, 1.0)",width:2}},t={default:e,blue:r,minimal:o};function a(i){return t[i]||t.default}function l(){return Object.keys(t)}exports.BLUE_PRESET=r;exports.DEFAULT_PRESET=e;exports.MINIMAL_PRESET=o;exports.default=t;exports.getPreset=a;exports.getPresetNames=l;
2
2
  //# sourceMappingURL=index20.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index20.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"}
1
+ {"version":3,"file":"index20.cjs","sources":["../src/pen/presets.js"],"sourcesContent":["/**\n * Client-side style presets for Digital Pen\n *\n * These presets mirror the backend presets and are used for\n * client-side preview or when backend presets aren't available.\n */\n\n/**\n * Default preset - Yellow highlights, crimson handwriting\n */\nexport const DEFAULT_PRESET = {\n name: 'default',\n highlight: {\n color: 'rgba(255, 255, 0, 0.3)',\n width: 24\n },\n handText: {\n color: 'rgba(220, 20, 60, 1.0)',\n width: 2\n },\n ink: {\n color: 'rgba(31, 41, 55, 1.0)',\n width: 3\n }\n};\n\n/**\n * Blue preset - Blue highlights and handwriting\n */\nexport const BLUE_PRESET = {\n name: 'blue',\n highlight: {\n color: 'rgba(100, 149, 237, 0.35)',\n width: 24\n },\n handText: {\n color: 'rgba(30, 64, 175, 1.0)',\n width: 2\n },\n ink: {\n color: 'rgba(30, 64, 175, 1.0)',\n width: 3\n }\n};\n\n/**\n * Minimal preset - Subtle gray, less visible effects\n */\nexport const MINIMAL_PRESET = {\n name: 'minimal',\n highlight: {\n color: 'rgba(156, 163, 175, 0.25)',\n width: 20\n },\n handText: {\n color: 'rgba(75, 85, 99, 1.0)',\n width: 1.5\n },\n ink: {\n color: 'rgba(75, 85, 99, 1.0)',\n width: 2\n }\n};\n\n/**\n * Preset registry\n */\nconst PRESETS = {\n default: DEFAULT_PRESET,\n blue: BLUE_PRESET,\n minimal: MINIMAL_PRESET\n};\n\n/**\n * Get a preset by name\n *\n * @param {string} name - Preset name\n * @returns {Object} Preset configuration\n */\nexport function getPreset(name) {\n return PRESETS[name] || PRESETS.default;\n}\n\n/**\n * Get all available preset names\n *\n * @returns {string[]} Array of preset names\n */\nexport function getPresetNames() {\n return Object.keys(PRESETS);\n}\n\nexport default PRESETS;\n"],"names":["DEFAULT_PRESET","BLUE_PRESET","MINIMAL_PRESET","PRESETS","getPreset","name","getPresetNames"],"mappings":"4GAUY,MAACA,EAAiB,CAC5B,KAAM,UACN,UAAW,CACT,MAAO,yBACP,MAAO,EACX,EACE,SAAU,CACR,MAAO,yBACP,MAAO,CACX,EACE,IAAK,CACH,MAAO,wBACP,MAAO,CACX,CACA,EAKaC,EAAc,CACzB,KAAM,OACN,UAAW,CACT,MAAO,4BACP,MAAO,EACX,EACE,SAAU,CACR,MAAO,yBACP,MAAO,CACX,EACE,IAAK,CACH,MAAO,yBACP,MAAO,CACX,CACA,EAKaC,EAAiB,CAC5B,KAAM,UACN,UAAW,CACT,MAAO,4BACP,MAAO,EACX,EACE,SAAU,CACR,MAAO,wBACP,MAAO,GACX,EACE,IAAK,CACH,MAAO,wBACP,MAAO,CACX,CACA,EAKMC,EAAU,CACd,QAASH,EACT,KAAMC,EACN,QAASC,CACX,EAQO,SAASE,EAAUC,EAAM,CAC9B,OAAOF,EAAQE,CAAI,GAAKF,EAAQ,OAClC,CAOO,SAASG,GAAiB,CAC/B,OAAO,OAAO,KAAKH,CAAO,CAC5B"}
package/dist/index20.js CHANGED
@@ -1,40 +1,62 @@
1
- import { generateId as h } from "./index24.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
- };
1
+ const r = {
2
+ name: "default",
3
+ highlight: {
4
+ color: "rgba(255, 255, 0, 0.3)",
5
+ width: 24
6
+ },
7
+ handText: {
8
+ color: "rgba(220, 20, 60, 1.0)",
9
+ width: 2
10
+ },
11
+ ink: {
12
+ color: "rgba(31, 41, 55, 1.0)",
13
+ width: 3
14
+ }
15
+ }, e = {
16
+ name: "blue",
17
+ highlight: {
18
+ color: "rgba(100, 149, 237, 0.35)",
19
+ width: 24
20
+ },
21
+ handText: {
22
+ color: "rgba(30, 64, 175, 1.0)",
23
+ width: 2
24
+ },
25
+ ink: {
26
+ color: "rgba(30, 64, 175, 1.0)",
27
+ width: 3
28
+ }
29
+ }, i = {
30
+ name: "minimal",
31
+ highlight: {
32
+ color: "rgba(156, 163, 175, 0.25)",
33
+ width: 20
34
+ },
35
+ handText: {
36
+ color: "rgba(75, 85, 99, 1.0)",
37
+ width: 1.5
38
+ },
39
+ ink: {
40
+ color: "rgba(75, 85, 99, 1.0)",
41
+ width: 2
42
+ }
43
+ }, t = {
44
+ default: r,
45
+ blue: e,
46
+ minimal: i
47
+ };
48
+ function a(o) {
49
+ return t[o] || t.default;
50
+ }
51
+ function h() {
52
+ return Object.keys(t);
36
53
  }
37
54
  export {
38
- p as createHighlight
55
+ e as BLUE_PRESET,
56
+ r as DEFAULT_PRESET,
57
+ i as MINIMAL_PRESET,
58
+ t as default,
59
+ a as getPreset,
60
+ h as getPresetNames
39
61
  };
40
62
  //# sourceMappingURL=index20.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index20.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;"}
1
+ {"version":3,"file":"index20.js","sources":["../src/pen/presets.js"],"sourcesContent":["/**\n * Client-side style presets for Digital Pen\n *\n * These presets mirror the backend presets and are used for\n * client-side preview or when backend presets aren't available.\n */\n\n/**\n * Default preset - Yellow highlights, crimson handwriting\n */\nexport const DEFAULT_PRESET = {\n name: 'default',\n highlight: {\n color: 'rgba(255, 255, 0, 0.3)',\n width: 24\n },\n handText: {\n color: 'rgba(220, 20, 60, 1.0)',\n width: 2\n },\n ink: {\n color: 'rgba(31, 41, 55, 1.0)',\n width: 3\n }\n};\n\n/**\n * Blue preset - Blue highlights and handwriting\n */\nexport const BLUE_PRESET = {\n name: 'blue',\n highlight: {\n color: 'rgba(100, 149, 237, 0.35)',\n width: 24\n },\n handText: {\n color: 'rgba(30, 64, 175, 1.0)',\n width: 2\n },\n ink: {\n color: 'rgba(30, 64, 175, 1.0)',\n width: 3\n }\n};\n\n/**\n * Minimal preset - Subtle gray, less visible effects\n */\nexport const MINIMAL_PRESET = {\n name: 'minimal',\n highlight: {\n color: 'rgba(156, 163, 175, 0.25)',\n width: 20\n },\n handText: {\n color: 'rgba(75, 85, 99, 1.0)',\n width: 1.5\n },\n ink: {\n color: 'rgba(75, 85, 99, 1.0)',\n width: 2\n }\n};\n\n/**\n * Preset registry\n */\nconst PRESETS = {\n default: DEFAULT_PRESET,\n blue: BLUE_PRESET,\n minimal: MINIMAL_PRESET\n};\n\n/**\n * Get a preset by name\n *\n * @param {string} name - Preset name\n * @returns {Object} Preset configuration\n */\nexport function getPreset(name) {\n return PRESETS[name] || PRESETS.default;\n}\n\n/**\n * Get all available preset names\n *\n * @returns {string[]} Array of preset names\n */\nexport function getPresetNames() {\n return Object.keys(PRESETS);\n}\n\nexport default PRESETS;\n"],"names":["DEFAULT_PRESET","BLUE_PRESET","MINIMAL_PRESET","PRESETS","getPreset","name","getPresetNames"],"mappings":"AAUY,MAACA,IAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,WAAW;AAAA,IACT,OAAO;AAAA,IACP,OAAO;AAAA,EACX;AAAA,EACE,UAAU;AAAA,IACR,OAAO;AAAA,IACP,OAAO;AAAA,EACX;AAAA,EACE,KAAK;AAAA,IACH,OAAO;AAAA,IACP,OAAO;AAAA,EACX;AACA,GAKaC,IAAc;AAAA,EACzB,MAAM;AAAA,EACN,WAAW;AAAA,IACT,OAAO;AAAA,IACP,OAAO;AAAA,EACX;AAAA,EACE,UAAU;AAAA,IACR,OAAO;AAAA,IACP,OAAO;AAAA,EACX;AAAA,EACE,KAAK;AAAA,IACH,OAAO;AAAA,IACP,OAAO;AAAA,EACX;AACA,GAKaC,IAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,WAAW;AAAA,IACT,OAAO;AAAA,IACP,OAAO;AAAA,EACX;AAAA,EACE,UAAU;AAAA,IACR,OAAO;AAAA,IACP,OAAO;AAAA,EACX;AAAA,EACE,KAAK;AAAA,IACH,OAAO;AAAA,IACP,OAAO;AAAA,EACX;AACA,GAKMC,IAAU;AAAA,EACd,SAASH;AAAA,EACT,MAAMC;AAAA,EACN,SAASC;AACX;AAQO,SAASE,EAAUC,GAAM;AAC9B,SAAOF,EAAQE,CAAI,KAAKF,EAAQ;AAClC;AAOO,SAASG,IAAiB;AAC/B,SAAO,OAAO,KAAKH,CAAO;AAC5B;"}
package/dist/index21.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index24.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||"transparent";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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=[{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 or 'transparent' (e.g., 'rgba(255, 255, 255, 0.9)' or 'transparent'). Default is transparent for better visibility of underlying content. Use rgba format when background is needed.",default:"transparent"},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"]}}}];function o(e=[]){if(!Array.isArray(e)||e.length===0)return[];const i={highlight:"create_highlight_annotation",text:"create_text_annotation"},r=e.map(t=>i[t]).filter(Boolean);return n.filter(t=>r.includes(t.function.name))}exports.annotationTools=n;exports.getAnnotationTools=o;
2
2
  //# sourceMappingURL=index21.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index21.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='transparent'] - Background color (transparent by default, or 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: 'transparent', // or use rgba format like '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 (transparent background for better visibility)\n const textColor = args.textColor || '#1f2937';\n const bgColor = args.bgColor || 'transparent';\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,cAGhC,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"}
1
+ {"version":3,"file":"index21.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 or 'transparent' (e.g., 'rgba(255, 255, 255, 0.9)' or 'transparent'). Default is transparent for better visibility of underlying content. Use rgba format when background is needed.\",\n default: \"transparent\"\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\n/**\n * Get filtered annotation tools based on enabled types\n *\n * @param {Array<string>} enabledTypes - Array of enabled tool types: ['highlight', 'text']\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 };\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,uNACb,QAAS,aACrB,EACU,aAAc,CACZ,KAAM,SACN,YAAa,6EACb,QAAS,SACrB,CACA,EACQ,SAAU,CAAC,UAAW,IAAK,IAAK,IAAK,IAAK,OAAQ,cAAc,CACxE,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,wBACZ,EAEQC,EAAuBF,EAC1B,IAAIG,GAAQF,EAAQE,CAAI,CAAC,EACzB,OAAO,OAAO,EAEjB,OAAOL,EAAgB,OAAOM,GAC5BF,EAAqB,SAASE,EAAK,SAAS,IAAI,CACpD,CACA"}