web-annotation-renderer 0.5.1 → 0.5.3

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
package/dist/index21.js CHANGED
@@ -1,41 +1,144 @@
1
- import { generateId as o } from "./index24.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 || "transparent";
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
- };
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 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.",
116
+ default: "transparent"
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
+ function o(e = []) {
130
+ if (!Array.isArray(e) || e.length === 0)
131
+ return [];
132
+ const n = {
133
+ highlight: "create_highlight_annotation",
134
+ text: "create_text_annotation"
135
+ }, i = e.map((t) => n[t]).filter(Boolean);
136
+ return r.filter(
137
+ (t) => i.includes(t.function.name)
138
+ );
37
139
  }
38
140
  export {
39
- i as createText
141
+ r as annotationTools,
142
+ o as getAnnotationTools
40
143
  };
41
144
  //# sourceMappingURL=index21.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index21.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='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":";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;"}
1
+ {"version":3,"file":"index21.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 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":"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;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,EACZ,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/index22.cjs CHANGED
@@ -1,2 +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"}};exports.BASE_DEFAULTS=t;exports.HIGHLIGHT_DEFAULTS=o;exports.TEXT_DEFAULTS=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index23.cjs"),c=require("./index24.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:e}=r.function;if(!t||typeof t!="string")throw new Error("Invalid tool call: missing or invalid function name");let n;try{n=typeof e=="string"?JSON.parse(e):e}catch(a){throw new Error(`Failed to parse tool call arguments: ${a.message}`)}switch(t){case"create_highlight_annotation":return i.createHighlight(n);case"create_text_annotation":return c.createText(n);default:throw new Error(`Unknown tool: ${t}. Supported tools: create_highlight_annotation, create_text_annotation`)}}function l(r){if(!Array.isArray(r))throw new Error("Tool calls must be an array");return r.map((t,e)=>{try{return o(t)}catch(n){throw new Error(`Error processing tool call at index ${e}: ${n.message}`)}})}exports.handleToolCall=o;exports.handleToolCalls=l;
2
2
  //# sourceMappingURL=index22.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index22.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"],"names":["BASE_DEFAULTS","HIGHLIGHT_DEFAULTS","TEXT_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"}
1
+ {"version":3,"file":"index22.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"}
package/dist/index22.js CHANGED
@@ -1,25 +1,41 @@
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
- }, e = {
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"
1
+ import { createHighlight as a } from "./index23.js";
2
+ import { createText as i } from "./index24.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}`);
18
16
  }
19
- };
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`);
24
+ }
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}`);
34
+ }
35
+ });
36
+ }
20
37
  export {
21
- o as BASE_DEFAULTS,
22
- t as HIGHLIGHT_DEFAULTS,
23
- e as TEXT_DEFAULTS
38
+ c as handleToolCall,
39
+ h as handleToolCalls
24
40
  };
25
41
  //# sourceMappingURL=index22.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index22.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"],"names":["BASE_DEFAULTS","HIGHLIGHT_DEFAULTS","TEXT_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;"}
1
+ {"version":3,"file":"index22.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;"}
package/dist/index23.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=JSON.parse(`{"0":{"width":0.5,"paths":[{"points":[[0.25,0],[0.1,0],[0,0.15],[0,0.85],[0.1,1],[0.4,1],[0.5,0.85],[0.5,0.15],[0.4,0],[0.25,0]]}]},"1":{"width":0.3,"paths":[{"points":[[0,0.2],[0.15,0],[0.15,1]]},{"points":[[0,1],[0.3,1]]}],"pathTiming":"sequential"},"2":{"width":0.5,"paths":[{"points":[[0,0.15],[0.1,0],[0.4,0],[0.5,0.15],[0.5,0.35],[0,1],[0.5,1]]}]},"3":{"width":0.5,"paths":[{"points":[[0,0.1],[0.15,0],[0.35,0],[0.5,0.15],[0.5,0.35],[0.35,0.5],[0.15,0.5]]},{"points":[[0.15,0.5],[0.35,0.5],[0.5,0.65],[0.5,0.85],[0.35,1],[0.15,1],[0,0.9]]}],"pathTiming":"sequential"},"4":{"width":0.5,"paths":[{"points":[[0.4,0],[0,0.7],[0.5,0.7]]},{"points":[[0.4,0],[0.4,1]]}],"pathTiming":"sequential"},"5":{"width":0.5,"paths":[{"points":[[0.5,0],[0,0],[0,0.45],[0.3,0.45],[0.5,0.6],[0.5,0.85],[0.35,1],[0.15,1],[0,0.9]]}]},"6":{"width":0.5,"paths":[{"points":[[0.4,0],[0.15,0],[0,0.2],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85],[0.5,0.6],[0.35,0.45],[0.15,0.45],[0,0.6]]}]},"7":{"width":0.5,"paths":[{"points":[[0,0],[0.5,0],[0.2,1]]}]},"8":{"width":0.5,"paths":[{"points":[[0.25,0.5],[0.1,0.5],[0,0.4],[0,0.15],[0.1,0],[0.4,0],[0.5,0.15],[0.5,0.4],[0.4,0.5],[0.25,0.5]]},{"points":[[0.25,0.5],[0.4,0.5],[0.5,0.6],[0.5,0.85],[0.4,1],[0.1,1],[0,0.85],[0,0.6],[0.1,0.5],[0.25,0.5]]}],"pathTiming":"sequential"},"9":{"width":0.5,"paths":[{"points":[[0.5,0.4],[0.35,0.55],[0.15,0.55],[0,0.4],[0,0.15],[0.15,0],[0.35,0],[0.5,0.15],[0.5,0.8],[0.35,1],[0.1,1]]}]},"A":{"width":0.7,"paths":[{"points":[[0,1],[0.35,0],[0.7,1]]},{"points":[[0.12,0.65],[0.58,0.65]]}],"pathTiming":"sequential"},"B":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.4,0],[0.55,0.1],[0.55,0.4],[0.4,0.5],[0,0.5]]},{"points":[[0,0.5],[0.45,0.5],[0.6,0.6],[0.6,0.9],[0.45,1],[0,1]]}],"pathTiming":"sequential"},"C":{"width":0.6,"paths":[{"points":[[0.6,0.15],[0.45,0],[0.15,0],[0,0.15],[0,0.85],[0.15,1],[0.45,1],[0.6,0.85]]}]},"D":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.35,0],[0.55,0.15],[0.6,0.5],[0.55,0.85],[0.35,1],[0,1]]}],"pathTiming":"sequential"},"E":{"width":0.55,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.55,0]]},{"points":[[0,0.5],[0.4,0.5]]},{"points":[[0,1],[0.55,1]]}],"pathTiming":"sequential"},"F":{"width":0.5,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.5,0]]},{"points":[[0,0.5],[0.35,0.5]]}],"pathTiming":"sequential"},"G":{"width":0.65,"paths":[{"points":[[0.65,0.15],[0.5,0],[0.15,0],[0,0.15],[0,0.85],[0.15,1],[0.5,1],[0.65,0.85],[0.65,0.55]]},{"points":[[0.35,0.55],[0.65,0.55]]}],"pathTiming":"sequential"},"H":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0.5],[0.6,0.5]]},{"points":[[0.6,0],[0.6,1]]}],"pathTiming":"sequential"},"I":{"width":0.35,"paths":[{"points":[[0,0],[0.35,0]]},{"points":[[0.175,0],[0.175,1]]},{"points":[[0,1],[0.35,1]]}],"pathTiming":"sequential"},"J":{"width":0.45,"paths":[{"points":[[0.1,0],[0.45,0]]},{"points":[[0.3,0],[0.3,0.85],[0.2,1],[0.08,1],[0,0.9]]}],"pathTiming":"sequential"},"K":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0.6,0],[0,0.55]]},{"points":[[0.2,0.4],[0.6,1]]}],"pathTiming":"sequential"},"L":{"width":0.5,"paths":[{"points":[[0,0],[0,1],[0.5,1]]}]},"M":{"width":0.75,"paths":[{"points":[[0,1],[0,0],[0.375,0.6],[0.75,0],[0.75,1]]}]},"N":{"width":0.6,"paths":[{"points":[[0,1],[0,0],[0.6,1],[0.6,0]]}]},"O":{"width":0.65,"paths":[{"points":[[0.325,0],[0.15,0],[0,0.15],[0,0.85],[0.15,1],[0.5,1],[0.65,0.85],[0.65,0.15],[0.5,0],[0.325,0]]}]},"P":{"width":0.55,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.4,0],[0.55,0.12],[0.55,0.38],[0.4,0.5],[0,0.5]]}],"pathTiming":"sequential"},"Q":{"width":0.65,"paths":[{"points":[[0.325,0],[0.15,0],[0,0.15],[0,0.85],[0.15,1],[0.5,1],[0.65,0.85],[0.65,0.15],[0.5,0],[0.325,0]]},{"points":[[0.4,0.75],[0.65,1.05]]}],"pathTiming":"sequential"},"R":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.4,0],[0.55,0.12],[0.55,0.38],[0.4,0.5],[0,0.5]]},{"points":[[0.3,0.5],[0.6,1]]}],"pathTiming":"sequential"},"S":{"width":0.55,"paths":[{"points":[[0.55,0.12],[0.4,0],[0.15,0],[0,0.12],[0,0.38],[0.15,0.5],[0.4,0.5],[0.55,0.62],[0.55,0.88],[0.4,1],[0.15,1],[0,0.88]]}]},"T":{"width":0.55,"paths":[{"points":[[0,0],[0.55,0]]},{"points":[[0.275,0],[0.275,1]]}],"pathTiming":"sequential"},"U":{"width":0.6,"paths":[{"points":[[0,0],[0,0.85],[0.15,1],[0.45,1],[0.6,0.85],[0.6,0]]}]},"V":{"width":0.65,"paths":[{"points":[[0,0],[0.325,1],[0.65,0]]}]},"W":{"width":0.85,"paths":[{"points":[[0,0],[0.2,1],[0.425,0.4],[0.65,1],[0.85,0]]}]},"X":{"width":0.6,"paths":[{"points":[[0,0],[0.6,1]]},{"points":[[0.6,0],[0,1]]}],"pathTiming":"sequential"},"Y":{"width":0.6,"paths":[{"points":[[0,0],[0.3,0.5]]},{"points":[[0.6,0],[0.3,0.5],[0.3,1]]}],"pathTiming":"sequential"},"Z":{"width":0.55,"paths":[{"points":[[0,0],[0.55,0],[0,1],[0.55,1]]}]},"a":{"width":0.5,"paths":[{"points":[[0.5,0.4],[0.5,1]]},{"points":[[0.5,0.55],[0.35,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85]]}],"pathTiming":"sequential"},"b":{"width":0.5,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0.55],[0.15,0.4],[0.35,0.4],[0.5,0.55],[0.5,0.85],[0.35,1],[0.15,1],[0,0.85]]}],"pathTiming":"sequential"},"c":{"width":0.45,"paths":[{"points":[[0.45,0.5],[0.3,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.3,1],[0.45,0.9]]}]},"d":{"width":0.5,"paths":[{"points":[[0.5,0],[0.5,1]]},{"points":[[0.5,0.55],[0.35,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85]]}],"pathTiming":"sequential"},"e":{"width":0.45,"paths":[{"points":[[0,0.7],[0.45,0.7],[0.45,0.55],[0.3,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.3,1],[0.45,0.9]]}]},"f":{"width":0.35,"paths":[{"points":[[0.35,0.1],[0.25,0],[0.15,0],[0.1,0.1],[0.1,1]]},{"points":[[0,0.4],[0.3,0.4]]}],"pathTiming":"sequential"},"g":{"width":0.5,"paths":[{"points":[[0.5,0.4],[0.5,1.15],[0.35,1.3],[0.15,1.3],[0,1.15]]},{"points":[[0.5,0.55],[0.35,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85]]}],"pathTiming":"sequential"},"h":{"width":0.45,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0.55],[0.15,0.4],[0.3,0.4],[0.45,0.55],[0.45,1]]}],"pathTiming":"sequential"},"i":{"width":0.15,"paths":[{"points":[[0.075,0.2],[0.075,0.25]]},{"points":[[0.075,0.4],[0.075,1]]}],"pathTiming":"sequential"},"j":{"width":0.2,"paths":[{"points":[[0.15,0.2],[0.15,0.25]]},{"points":[[0.15,0.4],[0.15,1.15],[0.05,1.3],[0,1.3]]}],"pathTiming":"sequential"},"k":{"width":0.45,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0.45,0.4],[0,0.7]]},{"points":[[0.15,0.6],[0.45,1]]}],"pathTiming":"sequential"},"l":{"width":0.15,"paths":[{"points":[[0.075,0],[0.075,1]]}]},"m":{"width":0.7,"paths":[{"points":[[0,0.4],[0,1]]},{"points":[[0,0.55],[0.1,0.4],[0.25,0.4],[0.35,0.55],[0.35,1]]},{"points":[[0.35,0.55],[0.45,0.4],[0.6,0.4],[0.7,0.55],[0.7,1]]}],"pathTiming":"sequential"},"n":{"width":0.45,"paths":[{"points":[[0,0.4],[0,1]]},{"points":[[0,0.55],[0.15,0.4],[0.3,0.4],[0.45,0.55],[0.45,1]]}],"pathTiming":"sequential"},"o":{"width":0.5,"paths":[{"points":[[0.25,0.4],[0.1,0.4],[0,0.55],[0,0.85],[0.1,1],[0.4,1],[0.5,0.85],[0.5,0.55],[0.4,0.4],[0.25,0.4]]}]},"p":{"width":0.5,"paths":[{"points":[[0,0.4],[0,1.3]]},{"points":[[0,0.55],[0.15,0.4],[0.35,0.4],[0.5,0.55],[0.5,0.85],[0.35,1],[0.15,1],[0,0.85]]}],"pathTiming":"sequential"},"q":{"width":0.5,"paths":[{"points":[[0.5,0.4],[0.5,1.3]]},{"points":[[0.5,0.55],[0.35,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85]]}],"pathTiming":"sequential"},"r":{"width":0.3,"paths":[{"points":[[0,0.4],[0,1]]},{"points":[[0,0.55],[0.1,0.4],[0.3,0.4]]}],"pathTiming":"sequential"},"s":{"width":0.4,"paths":[{"points":[[0.4,0.5],[0.3,0.4],[0.1,0.4],[0,0.5],[0,0.6],[0.1,0.7],[0.3,0.7],[0.4,0.8],[0.4,0.9],[0.3,1],[0.1,1],[0,0.9]]}]},"t":{"width":0.3,"paths":[{"points":[[0.1,0.15],[0.1,0.9],[0.2,1],[0.3,1]]},{"points":[[0,0.4],[0.25,0.4]]}],"pathTiming":"sequential"},"u":{"width":0.45,"paths":[{"points":[[0,0.4],[0,0.85],[0.15,1],[0.3,1],[0.45,0.85]]},{"points":[[0.45,0.4],[0.45,1]]}],"pathTiming":"sequential"},"v":{"width":0.45,"paths":[{"points":[[0,0.4],[0.225,1],[0.45,0.4]]}]},"w":{"width":0.65,"paths":[{"points":[[0,0.4],[0.15,1],[0.325,0.6],[0.5,1],[0.65,0.4]]}]},"x":{"width":0.4,"paths":[{"points":[[0,0.4],[0.4,1]]},{"points":[[0.4,0.4],[0,1]]}],"pathTiming":"sequential"},"y":{"width":0.45,"paths":[{"points":[[0,0.4],[0.225,0.85]]},{"points":[[0.45,0.4],[0.15,1],[0.05,1.2],[0,1.3]]}],"pathTiming":"sequential"},"z":{"width":0.4,"paths":[{"points":[[0,0.4],[0.4,0.4],[0,1],[0.4,1]]}]},".":{"width":0.12,"paths":[{"points":[[0.06,0.9],[0.06,0.92],[0.06,0.95],[0.06,1]]}]},",":{"width":0.12,"paths":[{"points":[[0.08,0.9],[0.06,1],[0,1.15]]}]},"!":{"width":0.12,"paths":[{"points":[[0.06,0],[0.06,0.7]]},{"points":[[0.06,0.9],[0.06,0.92],[0.06,0.95],[0.06,1]]}],"pathTiming":"sequential"},"?":{"width":0.45,"paths":[{"points":[[0,0.15],[0.1,0],[0.35,0],[0.45,0.15],[0.45,0.35],[0.3,0.5],[0.225,0.5],[0.225,0.7]]},{"points":[[0.225,0.9],[0.225,0.92],[0.225,0.95],[0.225,1]]}],"pathTiming":"sequential"},"'":{"width":0.1,"paths":[{"points":[[0.05,0],[0.05,0.1],[0.05,0.2]]}]},"\\"":{"width":0.25,"paths":[{"points":[[0.05,0],[0.05,0.1],[0.05,0.2]]},{"points":[[0.2,0],[0.2,0.1],[0.2,0.2]]}],"pathTiming":"parallel"},"-":{"width":0.3,"paths":[{"points":[[0,0.5],[0.1,0.5],[0.2,0.5],[0.3,0.5]]}]},"_":{"width":0.5,"paths":[{"points":[[0,1.05],[0.25,1.05],[0.5,1.05]]}]},":":{"width":0.12,"paths":[{"points":[[0.06,0.45],[0.06,0.48],[0.06,0.5]]},{"points":[[0.06,0.9],[0.06,0.93],[0.06,0.96],[0.06,1]]}],"pathTiming":"sequential"},";":{"width":0.12,"paths":[{"points":[[0.06,0.45],[0.06,0.48],[0.06,0.5]]},{"points":[[0.08,0.9],[0.06,1],[0,1.15]]}],"pathTiming":"sequential"},"(":{"width":0.25,"paths":[{"points":[[0.25,-0.1],[0.1,0.1],[0,0.35],[0,0.65],[0.1,0.9],[0.25,1.1]]}]},")":{"width":0.25,"paths":[{"points":[[0,-0.1],[0.15,0.1],[0.25,0.35],[0.25,0.65],[0.15,0.9],[0,1.1]]}]},"/":{"width":0.4,"paths":[{"points":[[0.4,-0.1],[0.2,0.5],[0,1.1]]}]},"+":{"width":0.45,"paths":[{"points":[[0.225,0.3],[0.225,0.7]]},{"points":[[0,0.5],[0.45,0.5]]}],"pathTiming":"sequential"},"=":{"width":0.45,"paths":[{"points":[[0,0.4],[0.45,0.4]]},{"points":[[0,0.6],[0.45,0.6]]}],"pathTiming":"sequential"}," ":{"width":0.3,"paths":[]}}`),i={glyphs:t};exports.default=i;exports.glyphs=t;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index27.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
2
  //# sourceMappingURL=index23.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index23.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"index23.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/index23.js CHANGED
@@ -1,8 +1,40 @@
1
- const t = /* @__PURE__ */ JSON.parse(`{"0":{"width":0.5,"paths":[{"points":[[0.25,0],[0.1,0],[0,0.15],[0,0.85],[0.1,1],[0.4,1],[0.5,0.85],[0.5,0.15],[0.4,0],[0.25,0]]}]},"1":{"width":0.3,"paths":[{"points":[[0,0.2],[0.15,0],[0.15,1]]},{"points":[[0,1],[0.3,1]]}],"pathTiming":"sequential"},"2":{"width":0.5,"paths":[{"points":[[0,0.15],[0.1,0],[0.4,0],[0.5,0.15],[0.5,0.35],[0,1],[0.5,1]]}]},"3":{"width":0.5,"paths":[{"points":[[0,0.1],[0.15,0],[0.35,0],[0.5,0.15],[0.5,0.35],[0.35,0.5],[0.15,0.5]]},{"points":[[0.15,0.5],[0.35,0.5],[0.5,0.65],[0.5,0.85],[0.35,1],[0.15,1],[0,0.9]]}],"pathTiming":"sequential"},"4":{"width":0.5,"paths":[{"points":[[0.4,0],[0,0.7],[0.5,0.7]]},{"points":[[0.4,0],[0.4,1]]}],"pathTiming":"sequential"},"5":{"width":0.5,"paths":[{"points":[[0.5,0],[0,0],[0,0.45],[0.3,0.45],[0.5,0.6],[0.5,0.85],[0.35,1],[0.15,1],[0,0.9]]}]},"6":{"width":0.5,"paths":[{"points":[[0.4,0],[0.15,0],[0,0.2],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85],[0.5,0.6],[0.35,0.45],[0.15,0.45],[0,0.6]]}]},"7":{"width":0.5,"paths":[{"points":[[0,0],[0.5,0],[0.2,1]]}]},"8":{"width":0.5,"paths":[{"points":[[0.25,0.5],[0.1,0.5],[0,0.4],[0,0.15],[0.1,0],[0.4,0],[0.5,0.15],[0.5,0.4],[0.4,0.5],[0.25,0.5]]},{"points":[[0.25,0.5],[0.4,0.5],[0.5,0.6],[0.5,0.85],[0.4,1],[0.1,1],[0,0.85],[0,0.6],[0.1,0.5],[0.25,0.5]]}],"pathTiming":"sequential"},"9":{"width":0.5,"paths":[{"points":[[0.5,0.4],[0.35,0.55],[0.15,0.55],[0,0.4],[0,0.15],[0.15,0],[0.35,0],[0.5,0.15],[0.5,0.8],[0.35,1],[0.1,1]]}]},"A":{"width":0.7,"paths":[{"points":[[0,1],[0.35,0],[0.7,1]]},{"points":[[0.12,0.65],[0.58,0.65]]}],"pathTiming":"sequential"},"B":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.4,0],[0.55,0.1],[0.55,0.4],[0.4,0.5],[0,0.5]]},{"points":[[0,0.5],[0.45,0.5],[0.6,0.6],[0.6,0.9],[0.45,1],[0,1]]}],"pathTiming":"sequential"},"C":{"width":0.6,"paths":[{"points":[[0.6,0.15],[0.45,0],[0.15,0],[0,0.15],[0,0.85],[0.15,1],[0.45,1],[0.6,0.85]]}]},"D":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.35,0],[0.55,0.15],[0.6,0.5],[0.55,0.85],[0.35,1],[0,1]]}],"pathTiming":"sequential"},"E":{"width":0.55,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.55,0]]},{"points":[[0,0.5],[0.4,0.5]]},{"points":[[0,1],[0.55,1]]}],"pathTiming":"sequential"},"F":{"width":0.5,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.5,0]]},{"points":[[0,0.5],[0.35,0.5]]}],"pathTiming":"sequential"},"G":{"width":0.65,"paths":[{"points":[[0.65,0.15],[0.5,0],[0.15,0],[0,0.15],[0,0.85],[0.15,1],[0.5,1],[0.65,0.85],[0.65,0.55]]},{"points":[[0.35,0.55],[0.65,0.55]]}],"pathTiming":"sequential"},"H":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0.5],[0.6,0.5]]},{"points":[[0.6,0],[0.6,1]]}],"pathTiming":"sequential"},"I":{"width":0.35,"paths":[{"points":[[0,0],[0.35,0]]},{"points":[[0.175,0],[0.175,1]]},{"points":[[0,1],[0.35,1]]}],"pathTiming":"sequential"},"J":{"width":0.45,"paths":[{"points":[[0.1,0],[0.45,0]]},{"points":[[0.3,0],[0.3,0.85],[0.2,1],[0.08,1],[0,0.9]]}],"pathTiming":"sequential"},"K":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0.6,0],[0,0.55]]},{"points":[[0.2,0.4],[0.6,1]]}],"pathTiming":"sequential"},"L":{"width":0.5,"paths":[{"points":[[0,0],[0,1],[0.5,1]]}]},"M":{"width":0.75,"paths":[{"points":[[0,1],[0,0],[0.375,0.6],[0.75,0],[0.75,1]]}]},"N":{"width":0.6,"paths":[{"points":[[0,1],[0,0],[0.6,1],[0.6,0]]}]},"O":{"width":0.65,"paths":[{"points":[[0.325,0],[0.15,0],[0,0.15],[0,0.85],[0.15,1],[0.5,1],[0.65,0.85],[0.65,0.15],[0.5,0],[0.325,0]]}]},"P":{"width":0.55,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.4,0],[0.55,0.12],[0.55,0.38],[0.4,0.5],[0,0.5]]}],"pathTiming":"sequential"},"Q":{"width":0.65,"paths":[{"points":[[0.325,0],[0.15,0],[0,0.15],[0,0.85],[0.15,1],[0.5,1],[0.65,0.85],[0.65,0.15],[0.5,0],[0.325,0]]},{"points":[[0.4,0.75],[0.65,1.05]]}],"pathTiming":"sequential"},"R":{"width":0.6,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0],[0.4,0],[0.55,0.12],[0.55,0.38],[0.4,0.5],[0,0.5]]},{"points":[[0.3,0.5],[0.6,1]]}],"pathTiming":"sequential"},"S":{"width":0.55,"paths":[{"points":[[0.55,0.12],[0.4,0],[0.15,0],[0,0.12],[0,0.38],[0.15,0.5],[0.4,0.5],[0.55,0.62],[0.55,0.88],[0.4,1],[0.15,1],[0,0.88]]}]},"T":{"width":0.55,"paths":[{"points":[[0,0],[0.55,0]]},{"points":[[0.275,0],[0.275,1]]}],"pathTiming":"sequential"},"U":{"width":0.6,"paths":[{"points":[[0,0],[0,0.85],[0.15,1],[0.45,1],[0.6,0.85],[0.6,0]]}]},"V":{"width":0.65,"paths":[{"points":[[0,0],[0.325,1],[0.65,0]]}]},"W":{"width":0.85,"paths":[{"points":[[0,0],[0.2,1],[0.425,0.4],[0.65,1],[0.85,0]]}]},"X":{"width":0.6,"paths":[{"points":[[0,0],[0.6,1]]},{"points":[[0.6,0],[0,1]]}],"pathTiming":"sequential"},"Y":{"width":0.6,"paths":[{"points":[[0,0],[0.3,0.5]]},{"points":[[0.6,0],[0.3,0.5],[0.3,1]]}],"pathTiming":"sequential"},"Z":{"width":0.55,"paths":[{"points":[[0,0],[0.55,0],[0,1],[0.55,1]]}]},"a":{"width":0.5,"paths":[{"points":[[0.5,0.4],[0.5,1]]},{"points":[[0.5,0.55],[0.35,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85]]}],"pathTiming":"sequential"},"b":{"width":0.5,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0.55],[0.15,0.4],[0.35,0.4],[0.5,0.55],[0.5,0.85],[0.35,1],[0.15,1],[0,0.85]]}],"pathTiming":"sequential"},"c":{"width":0.45,"paths":[{"points":[[0.45,0.5],[0.3,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.3,1],[0.45,0.9]]}]},"d":{"width":0.5,"paths":[{"points":[[0.5,0],[0.5,1]]},{"points":[[0.5,0.55],[0.35,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85]]}],"pathTiming":"sequential"},"e":{"width":0.45,"paths":[{"points":[[0,0.7],[0.45,0.7],[0.45,0.55],[0.3,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.3,1],[0.45,0.9]]}]},"f":{"width":0.35,"paths":[{"points":[[0.35,0.1],[0.25,0],[0.15,0],[0.1,0.1],[0.1,1]]},{"points":[[0,0.4],[0.3,0.4]]}],"pathTiming":"sequential"},"g":{"width":0.5,"paths":[{"points":[[0.5,0.4],[0.5,1.15],[0.35,1.3],[0.15,1.3],[0,1.15]]},{"points":[[0.5,0.55],[0.35,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85]]}],"pathTiming":"sequential"},"h":{"width":0.45,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0,0.55],[0.15,0.4],[0.3,0.4],[0.45,0.55],[0.45,1]]}],"pathTiming":"sequential"},"i":{"width":0.15,"paths":[{"points":[[0.075,0.2],[0.075,0.25]]},{"points":[[0.075,0.4],[0.075,1]]}],"pathTiming":"sequential"},"j":{"width":0.2,"paths":[{"points":[[0.15,0.2],[0.15,0.25]]},{"points":[[0.15,0.4],[0.15,1.15],[0.05,1.3],[0,1.3]]}],"pathTiming":"sequential"},"k":{"width":0.45,"paths":[{"points":[[0,0],[0,1]]},{"points":[[0.45,0.4],[0,0.7]]},{"points":[[0.15,0.6],[0.45,1]]}],"pathTiming":"sequential"},"l":{"width":0.15,"paths":[{"points":[[0.075,0],[0.075,1]]}]},"m":{"width":0.7,"paths":[{"points":[[0,0.4],[0,1]]},{"points":[[0,0.55],[0.1,0.4],[0.25,0.4],[0.35,0.55],[0.35,1]]},{"points":[[0.35,0.55],[0.45,0.4],[0.6,0.4],[0.7,0.55],[0.7,1]]}],"pathTiming":"sequential"},"n":{"width":0.45,"paths":[{"points":[[0,0.4],[0,1]]},{"points":[[0,0.55],[0.15,0.4],[0.3,0.4],[0.45,0.55],[0.45,1]]}],"pathTiming":"sequential"},"o":{"width":0.5,"paths":[{"points":[[0.25,0.4],[0.1,0.4],[0,0.55],[0,0.85],[0.1,1],[0.4,1],[0.5,0.85],[0.5,0.55],[0.4,0.4],[0.25,0.4]]}]},"p":{"width":0.5,"paths":[{"points":[[0,0.4],[0,1.3]]},{"points":[[0,0.55],[0.15,0.4],[0.35,0.4],[0.5,0.55],[0.5,0.85],[0.35,1],[0.15,1],[0,0.85]]}],"pathTiming":"sequential"},"q":{"width":0.5,"paths":[{"points":[[0.5,0.4],[0.5,1.3]]},{"points":[[0.5,0.55],[0.35,0.4],[0.15,0.4],[0,0.55],[0,0.85],[0.15,1],[0.35,1],[0.5,0.85]]}],"pathTiming":"sequential"},"r":{"width":0.3,"paths":[{"points":[[0,0.4],[0,1]]},{"points":[[0,0.55],[0.1,0.4],[0.3,0.4]]}],"pathTiming":"sequential"},"s":{"width":0.4,"paths":[{"points":[[0.4,0.5],[0.3,0.4],[0.1,0.4],[0,0.5],[0,0.6],[0.1,0.7],[0.3,0.7],[0.4,0.8],[0.4,0.9],[0.3,1],[0.1,1],[0,0.9]]}]},"t":{"width":0.3,"paths":[{"points":[[0.1,0.15],[0.1,0.9],[0.2,1],[0.3,1]]},{"points":[[0,0.4],[0.25,0.4]]}],"pathTiming":"sequential"},"u":{"width":0.45,"paths":[{"points":[[0,0.4],[0,0.85],[0.15,1],[0.3,1],[0.45,0.85]]},{"points":[[0.45,0.4],[0.45,1]]}],"pathTiming":"sequential"},"v":{"width":0.45,"paths":[{"points":[[0,0.4],[0.225,1],[0.45,0.4]]}]},"w":{"width":0.65,"paths":[{"points":[[0,0.4],[0.15,1],[0.325,0.6],[0.5,1],[0.65,0.4]]}]},"x":{"width":0.4,"paths":[{"points":[[0,0.4],[0.4,1]]},{"points":[[0.4,0.4],[0,1]]}],"pathTiming":"sequential"},"y":{"width":0.45,"paths":[{"points":[[0,0.4],[0.225,0.85]]},{"points":[[0.45,0.4],[0.15,1],[0.05,1.2],[0,1.3]]}],"pathTiming":"sequential"},"z":{"width":0.4,"paths":[{"points":[[0,0.4],[0.4,0.4],[0,1],[0.4,1]]}]},".":{"width":0.12,"paths":[{"points":[[0.06,0.9],[0.06,0.92],[0.06,0.95],[0.06,1]]}]},",":{"width":0.12,"paths":[{"points":[[0.08,0.9],[0.06,1],[0,1.15]]}]},"!":{"width":0.12,"paths":[{"points":[[0.06,0],[0.06,0.7]]},{"points":[[0.06,0.9],[0.06,0.92],[0.06,0.95],[0.06,1]]}],"pathTiming":"sequential"},"?":{"width":0.45,"paths":[{"points":[[0,0.15],[0.1,0],[0.35,0],[0.45,0.15],[0.45,0.35],[0.3,0.5],[0.225,0.5],[0.225,0.7]]},{"points":[[0.225,0.9],[0.225,0.92],[0.225,0.95],[0.225,1]]}],"pathTiming":"sequential"},"'":{"width":0.1,"paths":[{"points":[[0.05,0],[0.05,0.1],[0.05,0.2]]}]},"\\"":{"width":0.25,"paths":[{"points":[[0.05,0],[0.05,0.1],[0.05,0.2]]},{"points":[[0.2,0],[0.2,0.1],[0.2,0.2]]}],"pathTiming":"parallel"},"-":{"width":0.3,"paths":[{"points":[[0,0.5],[0.1,0.5],[0.2,0.5],[0.3,0.5]]}]},"_":{"width":0.5,"paths":[{"points":[[0,1.05],[0.25,1.05],[0.5,1.05]]}]},":":{"width":0.12,"paths":[{"points":[[0.06,0.45],[0.06,0.48],[0.06,0.5]]},{"points":[[0.06,0.9],[0.06,0.93],[0.06,0.96],[0.06,1]]}],"pathTiming":"sequential"},";":{"width":0.12,"paths":[{"points":[[0.06,0.45],[0.06,0.48],[0.06,0.5]]},{"points":[[0.08,0.9],[0.06,1],[0,1.15]]}],"pathTiming":"sequential"},"(":{"width":0.25,"paths":[{"points":[[0.25,-0.1],[0.1,0.1],[0,0.35],[0,0.65],[0.1,0.9],[0.25,1.1]]}]},")":{"width":0.25,"paths":[{"points":[[0,-0.1],[0.15,0.1],[0.25,0.35],[0.25,0.65],[0.15,0.9],[0,1.1]]}]},"/":{"width":0.4,"paths":[{"points":[[0.4,-0.1],[0.2,0.5],[0,1.1]]}]},"+":{"width":0.45,"paths":[{"points":[[0.225,0.3],[0.225,0.7]]},{"points":[[0,0.5],[0.45,0.5]]}],"pathTiming":"sequential"},"=":{"width":0.45,"paths":[{"points":[[0,0.4],[0.45,0.4]]},{"points":[[0,0.6],[0.45,0.6]]}],"pathTiming":"sequential"}," ":{"width":0.3,"paths":[]}}`), i = {
2
- glyphs: t
3
- };
1
+ import { generateId as h } from "./index27.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
+ }
4
37
  export {
5
- i as default,
6
- t as glyphs
38
+ p as createHighlight
7
39
  };
8
40
  //# sourceMappingURL=index23.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index23.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
1
+ {"version":3,"file":"index23.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/index24.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(t="anno"){const n=Date.now().toString(36),e=Math.random().toString(36).substring(2,9);return`${t}-${n}${e}`}exports.generateId=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index27.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;
2
2
  //# sourceMappingURL=index24.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index24.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"}
1
+ {"version":3,"file":"index24.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"}
package/dist/index24.js CHANGED
@@ -1,8 +1,41 @@
1
- function r(t = "anno") {
2
- const n = Date.now().toString(36), o = Math.random().toString(36).substring(2, 9);
3
- return `${t}-${n}${o}`;
1
+ import { generateId as o } from "./index27.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 || "transparent";
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
+ };
4
37
  }
5
38
  export {
6
- r as generateId
39
+ i as createText
7
40
  };
8
41
  //# sourceMappingURL=index24.js.map