agent-ui-annotation 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +109 -9
  2. package/dist/adapters/angular/annotation.module.d.ts +1 -1
  3. package/dist/adapters/angular/annotation.module.d.ts.map +1 -1
  4. package/dist/adapters/react/AgentUIAnnotation.d.ts +4 -1
  5. package/dist/adapters/react/AgentUIAnnotation.d.ts.map +1 -1
  6. package/dist/adapters/react/AgentUIAnnotation.js +55 -51
  7. package/dist/adapters/react/AgentUIAnnotation.js.map +1 -1
  8. package/dist/adapters/svelte/index.js +56 -54
  9. package/dist/adapters/svelte/index.js.map +1 -1
  10. package/dist/adapters/svelte/types.d.ts +4 -1
  11. package/dist/adapters/svelte/types.d.ts.map +1 -1
  12. package/dist/adapters/vanilla/index.d.ts +19 -17
  13. package/dist/adapters/vanilla/index.d.ts.map +1 -1
  14. package/dist/adapters/vanilla/index.js +35 -34
  15. package/dist/adapters/vanilla/index.js.map +1 -1
  16. package/dist/adapters/vue/AgentUIAnnotation.vue.d.ts +9 -7
  17. package/dist/adapters/vue/AgentUIAnnotation.vue.d.ts.map +1 -1
  18. package/dist/adapters/vue/index.js +42 -39
  19. package/dist/adapters/vue/index.js.map +1 -1
  20. package/dist/adapters/vue/types.d.ts +4 -1
  21. package/dist/adapters/vue/types.d.ts.map +1 -1
  22. package/dist/adapters/vue/useAgentUIAnnotation.d.ts.map +1 -1
  23. package/dist/agent-ui-annotation.js +15 -15
  24. package/dist/agent-ui-annotation.js.map +1 -1
  25. package/dist/annotation-element-CZQRsI-4.js +4400 -0
  26. package/dist/annotation-element-CZQRsI-4.js.map +1 -0
  27. package/dist/core/annotations/annotation.d.ts +66 -0
  28. package/dist/core/annotations/annotation.d.ts.map +1 -0
  29. package/dist/core/annotations/index.d.ts +7 -0
  30. package/dist/core/annotations/index.d.ts.map +1 -0
  31. package/dist/core/annotations/output.d.ts +14 -0
  32. package/dist/core/annotations/output.d.ts.map +1 -0
  33. package/dist/core/annotations/persistence.d.ts +42 -0
  34. package/dist/core/annotations/persistence.d.ts.map +1 -0
  35. package/dist/core/controller.d.ts +17 -15
  36. package/dist/core/controller.d.ts.map +1 -1
  37. package/dist/core/dom/events.d.ts +2 -2
  38. package/dist/core/dom/events.d.ts.map +1 -1
  39. package/dist/core/dom/hover-detection.d.ts.map +1 -1
  40. package/dist/core/element/component-path.d.ts +9 -0
  41. package/dist/core/element/component-path.d.ts.map +1 -0
  42. package/dist/core/element/index.d.ts.map +1 -1
  43. package/dist/core/i18n/locales/en.d.ts.map +1 -1
  44. package/dist/core/i18n/locales/zh-CN.d.ts.map +1 -1
  45. package/dist/core/i18n/types.d.ts +6 -5
  46. package/dist/core/i18n/types.d.ts.map +1 -1
  47. package/dist/core/index.d.ts +3 -3
  48. package/dist/core/index.d.ts.map +1 -1
  49. package/dist/core/state.d.ts +5 -5
  50. package/dist/core/state.d.ts.map +1 -1
  51. package/dist/core/types.d.ts +72 -36
  52. package/dist/core/types.d.ts.map +1 -1
  53. package/dist/element/annotation-element.d.ts +55 -20
  54. package/dist/element/annotation-element.d.ts.map +1 -1
  55. package/dist/element/styles.d.ts +2 -2
  56. package/dist/element/styles.d.ts.map +1 -1
  57. package/dist/element/templates/marker.d.ts +3 -3
  58. package/dist/element/templates/marker.d.ts.map +1 -1
  59. package/dist/element/templates/popup.d.ts +2 -2
  60. package/dist/element/templates/popup.d.ts.map +1 -1
  61. package/dist/element/templates/toolbar.d.ts +3 -3
  62. package/dist/element/templates/toolbar.d.ts.map +1 -1
  63. package/dist/element/templates/tooltip.d.ts.map +1 -1
  64. package/dist/index.d.ts +5 -5
  65. package/dist/index.d.ts.map +1 -1
  66. package/package.json +9 -6
  67. package/dist/annotation-element-z6TdBGsn.js +0 -3494
  68. package/dist/annotation-element-z6TdBGsn.js.map +0 -1
  69. package/dist/core/scopes/index.d.ts +0 -7
  70. package/dist/core/scopes/index.d.ts.map +0 -1
  71. package/dist/core/scopes/output.d.ts +0 -14
  72. package/dist/core/scopes/output.d.ts.map +0 -1
  73. package/dist/core/scopes/persistence.d.ts +0 -42
  74. package/dist/core/scopes/persistence.d.ts.map +0 -1
  75. package/dist/core/scopes/scope.d.ts +0 -55
  76. package/dist/core/scopes/scope.d.ts.map +0 -1
package/README.md CHANGED
@@ -18,7 +18,7 @@ When working with AI coding agents, communicating which visual element needs mod
18
18
 
19
19
  1. Click any element on a web page
20
20
  2. Add feedback or notes
21
- 3. Export structured markdown with element identifiers, CSS selectors, and context
21
+ 3. Export structured markdown with element identifiers, CSS selectors, framework component paths, and context
22
22
 
23
23
  The exported markdown gives AI agents the precise information needed to locate elements in code.
24
24
 
@@ -46,6 +46,13 @@ import { createAnnotation } from 'agent-ui-annotation';
46
46
 
47
47
  const annotation = createAnnotation({
48
48
  theme: 'auto',
49
+ // Add custom context to every annotation
50
+ onBeforeAnnotationCreate: (data) => ({
51
+ context: {
52
+ route: window.location.pathname,
53
+ timestamp: new Date().toISOString(),
54
+ },
55
+ }),
49
56
  onAnnotationCreate: (annotation) => console.log('Created:', annotation),
50
57
  onCopy: (markdown) => console.log('Copied:', markdown),
51
58
  });
@@ -74,6 +81,9 @@ function App() {
74
81
  <AgentUIAnnotation
75
82
  theme="auto"
76
83
  outputLevel="standard"
84
+ onBeforeAnnotationCreate={(data) => ({
85
+ context: { route: window.location.pathname },
86
+ })}
77
87
  onAnnotationCreate={(annotation) => console.log('Created:', annotation)}
78
88
  onCopy={(markdown) => console.log('Copied:', markdown)}
79
89
  />
@@ -86,10 +96,14 @@ function App() {
86
96
  ```vue
87
97
  <script setup lang="ts">
88
98
  import { AgentUIAnnotation, useAgentUIAnnotation } from 'agent-ui-annotation/vue';
89
- import type { Annotation } from 'agent-ui-annotation/vue';
99
+ import type { Annotation, BeforeAnnotationCreateResult } from 'agent-ui-annotation/vue';
90
100
 
91
101
  const { ref: annotationRef, activate, copyOutput } = useAgentUIAnnotation();
92
102
 
103
+ function handleBeforeCreate(): BeforeAnnotationCreateResult {
104
+ return { context: { route: window.location.pathname } };
105
+ }
106
+
93
107
  function handleCreate(annotation: Annotation) {
94
108
  console.log('Created:', annotation);
95
109
  }
@@ -104,6 +118,7 @@ function handleCopy(markdown: string) {
104
118
  ref="annotationRef"
105
119
  theme="auto"
106
120
  output-level="standard"
121
+ :on-before-annotation-create="handleBeforeCreate"
107
122
  @annotation-create="handleCreate"
108
123
  @copy="handleCopy"
109
124
  />
@@ -117,10 +132,13 @@ function handleCopy(markdown: string) {
117
132
  ```svelte
118
133
  <script lang="ts">
119
134
  import { AgentUIAnnotation } from 'agent-ui-annotation/svelte';
120
- import type { Annotation } from 'agent-ui-annotation/svelte';
135
+ import type { Annotation, BeforeAnnotationCreateResult } from 'agent-ui-annotation/svelte';
121
136
 
122
137
  let annotation: AgentUIAnnotation;
123
138
 
139
+ const onBeforeAnnotationCreate = (): BeforeAnnotationCreateResult => ({
140
+ context: { route: window.location.pathname },
141
+ });
124
142
  const onAnnotationCreate = (a: Annotation) => console.log('Created:', a);
125
143
  const onCopy = (content: string) => console.log('Copied:', content);
126
144
  </script>
@@ -129,6 +147,7 @@ function handleCopy(markdown: string) {
129
147
  bind:this={annotation}
130
148
  theme="auto"
131
149
  outputLevel="standard"
150
+ {onBeforeAnnotationCreate}
132
151
  {onAnnotationCreate}
133
152
  {onCopy}
134
153
  />
@@ -156,9 +175,16 @@ export class App {
156
175
 
157
176
  constructor() {
158
177
  afterNextRender(() => {
159
- this.annotationRef()?.nativeElement.addEventListener('annotation:create', (e: Event) => {
160
- console.log('Created:', (e as CustomEvent).detail.annotation);
161
- });
178
+ const element = this.annotationRef()?.nativeElement;
179
+ if (element) {
180
+ // Add custom context to annotations
181
+ element.setBeforeCreateHook((data) => ({
182
+ context: { route: window.location.pathname },
183
+ }));
184
+ element.addEventListener('annotation:create', (e: Event) => {
185
+ console.log('Created:', (e as CustomEvent).detail.annotation);
186
+ });
187
+ }
162
188
  });
163
189
  }
164
190
 
@@ -179,6 +205,19 @@ Generates human-readable names like `button "Save"` or `input [email]` that AI a
179
205
  ### CSS Selector Paths
180
206
  Creates CSS selectors (e.g., `form > .actions > button`) for precise element location.
181
207
 
208
+ ### Framework Component Paths
209
+ Automatically detects and displays the framework component hierarchy for annotated elements. Works with React, Vue, Svelte, and Angular in development mode.
210
+
211
+ | Framework | Example Output |
212
+ |-----------|---------------|
213
+ | React 18 | `App (App.tsx:7) > LandingPage (App.tsx:54) > CTAButton (App.tsx:38)` |
214
+ | React 19 | `App > LandingPage > CTAButton` (names only, no file/line) |
215
+ | Vue | `App (App.vue) > LandingPage (LandingPage.vue) > CTAButton (CTAButton.vue)` |
216
+ | Svelte | `LandingPage.svelte:5 > HeroSection.svelte:5 > CTAButton.svelte:5` |
217
+ | Angular | `_App > _LandingPageComponent > _CTAButtonComponent` |
218
+
219
+ Component paths appear in the popup, hover tooltip, and markdown output (standard level and above).
220
+
182
221
  ### Multi-Select
183
222
  Hold and drag to select multiple elements at once.
184
223
 
@@ -193,13 +232,51 @@ When active, clicks are blocked from triggering buttons/links while annotating (
193
232
  | Level | Description |
194
233
  |-------|-------------|
195
234
  | Compact | `1. **button "Save"**: Change color to blue` |
196
- | Standard | Element + path + comment with headers |
197
- | Detailed | + classes, position, nearby context |
198
- | Forensic | + full DOM path, computed styles, accessibility info |
235
+ | Standard | Element + path + component path + comment with headers |
236
+ | Detailed | + framework prefix, classes, position, nearby context, custom context |
237
+ | Forensic | + full DOM path, computed styles, accessibility info, custom context |
199
238
 
200
239
  ### Persistence
201
240
  Annotations are saved to localStorage and persist across page reloads (7-day retention).
202
241
 
242
+ ### Custom Context Hook
243
+
244
+ The `onBeforeAnnotationCreate` hook lets you inject custom context (route info, user data, app state) into annotations before they're created. You can also modify the comment or cancel annotation creation.
245
+
246
+ ```typescript
247
+ // Add route and user context to every annotation
248
+ const annotation = createAnnotation({
249
+ onBeforeAnnotationCreate: (data) => ({
250
+ context: {
251
+ route: window.location.pathname,
252
+ params: Object.fromEntries(new URLSearchParams(window.location.search)),
253
+ userId: getCurrentUserId(),
254
+ timestamp: new Date().toISOString(),
255
+ },
256
+ }),
257
+ });
258
+
259
+ // Conditionally cancel annotation creation
260
+ const annotation = createAnnotation({
261
+ onBeforeAnnotationCreate: (data) => {
262
+ // Don't annotate elements inside specific containers
263
+ if (data.element.closest('.no-annotate')) {
264
+ return { cancel: true };
265
+ }
266
+ return { context: { route: window.location.pathname } };
267
+ },
268
+ });
269
+
270
+ // Modify the comment
271
+ const annotation = createAnnotation({
272
+ onBeforeAnnotationCreate: (data) => ({
273
+ comment: `[${window.location.pathname}] ${data.comment}`,
274
+ }),
275
+ });
276
+ ```
277
+
278
+ The custom context appears in the markdown output at detailed and forensic levels.
279
+
203
280
  ## Internationalization (i18n)
204
281
 
205
282
  agent-ui-annotation supports multiple languages with built-in English and Simplified Chinese translations.
@@ -336,6 +413,7 @@ interface AnnotationOptions {
336
413
  theme?: 'light' | 'dark' | 'auto';
337
414
  outputLevel?: 'compact' | 'standard' | 'detailed' | 'forensic';
338
415
  annotationColor?: string;
416
+ onBeforeAnnotationCreate?: BeforeAnnotationCreateHook; // Hook to add context/modify/cancel
339
417
  onAnnotationCreate?: (annotation: Annotation) => void;
340
418
  onAnnotationUpdate?: (annotation: Annotation) => void;
341
419
  onAnnotationDelete?: (id: string) => void;
@@ -343,6 +421,27 @@ interface AnnotationOptions {
343
421
  onCopy?: (content: string, level: OutputLevel) => void;
344
422
  }
345
423
 
424
+ // Hook types for onBeforeAnnotationCreate
425
+ interface BeforeAnnotationCreateData {
426
+ element: Element; // The DOM element being annotated
427
+ elementInfo: ElementInfo; // Collected element information
428
+ comment: string; // User's comment
429
+ selectedText: string | null; // Selected text on page (if any)
430
+ isMultiSelect: boolean; // Whether part of multi-select batch
431
+ clickX: number; // Click X coordinate
432
+ clickY: number; // Click Y coordinate
433
+ }
434
+
435
+ interface BeforeAnnotationCreateResult {
436
+ context?: Record<string, unknown>; // Custom data to attach
437
+ comment?: string; // Override the comment
438
+ cancel?: boolean; // Set true to cancel creation
439
+ }
440
+
441
+ type BeforeAnnotationCreateHook = (
442
+ data: BeforeAnnotationCreateData
443
+ ) => BeforeAnnotationCreateResult | Promise<BeforeAnnotationCreateResult> | void | Promise<void>;
444
+
346
445
  // i18n is configured separately via initI18n()
347
446
  interface I18nOptions {
348
447
  locale?: string; // e.g., 'en', 'zh-CN'
@@ -402,6 +501,7 @@ interface AnnotationInstance {
402
501
 
403
502
  ### 1. button "Save"
404
503
  **Location:** form > .actions > button
504
+ **Component:** App (App.tsx:12) > SaveForm (SaveForm.tsx:8)
405
505
  **Feedback:** Change color to blue
406
506
 
407
507
  ---
@@ -1,5 +1,5 @@
1
1
  import { I18nOptions } from '../../core/i18n';
2
- export type { Annotation, AnnotationId, OutputLevel, ThemeMode, Settings, PartialTranslationStrings, I18nOptions } from '../../core/types';
2
+ export type { Annotation, AnnotationId, OutputLevel, ThemeMode, Settings, PartialTranslationStrings, I18nOptions, BeforeAnnotationCreateHook, BeforeAnnotationCreateData, BeforeAnnotationCreateResult } from '../../core/types';
3
3
  export { AnnotationElement } from '../../element/annotation-element';
4
4
  export { initI18n } from '../../core/i18n';
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"annotation.module.d.ts","sourceRoot":"","sources":["../../../src/adapters/angular/annotation.module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAGH,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAM7D,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3I,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,CAAC,EAAE,WAAW,QAK9D"}
1
+ {"version":3,"file":"annotation.module.d.ts","sourceRoot":"","sources":["../../../src/adapters/angular/annotation.module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAGH,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAM7D,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,yBAAyB,EAAE,WAAW,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AACjO,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,CAAC,EAAE,WAAW,QAK9D"}
@@ -1,5 +1,5 @@
1
1
  import { default as React, FC } from 'react';
2
- import { Annotation, AnnotationId, OutputLevel, ThemeMode } from '../../core/types';
2
+ import { Annotation, AnnotationId, OutputLevel, ThemeMode, BeforeAnnotationCreateHook, BeforeAnnotationCreateData, BeforeAnnotationCreateResult } from '../../core/types';
3
3
  import { AnnotationElement } from '../../element/annotation-element';
4
4
  declare global {
5
5
  namespace JSX {
@@ -23,6 +23,8 @@ export interface AgentUIAnnotationProps {
23
23
  annotationColor?: string;
24
24
  /** Whether the tool is disabled */
25
25
  disabled?: boolean;
26
+ /** Hook called before creating an annotation - can add context, modify comment, or cancel */
27
+ onBeforeAnnotationCreate?: BeforeAnnotationCreateHook;
26
28
  /** Callback when an annotation is created */
27
29
  onAnnotationCreate?: (annotation: Annotation) => void;
28
30
  /** Callback when an annotation is updated */
@@ -61,4 +63,5 @@ export declare function useAgentUIAnnotation(): {
61
63
  clearAll: () => void;
62
64
  };
63
65
  export default AgentUIAnnotation;
66
+ export type { BeforeAnnotationCreateHook, BeforeAnnotationCreateData, BeforeAnnotationCreateResult };
64
67
  //# sourceMappingURL=AgentUIAnnotation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AgentUIAnnotation.d.ts","sourceRoot":"","sources":["../../../src/adapters/react/AgentUIAnnotation.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,EAAkC,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAA6B,KAAK,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAMrG,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,qBAAqB,EAAE,KAAK,CAAC,iBAAiB,CAC5C,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG;gBAClC,KAAK,CAAC,EAAE,MAAM,CAAC;gBACf,cAAc,CAAC,EAAE,MAAM,CAAC;gBACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;gBAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAClB,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;aACpC,EACD,WAAW,CACZ,CAAC;SACH;KACF;CACF;AAED,MAAM,WAAW,sBAAsB;IACrC,iBAAiB;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,0BAA0B;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,8BAA8B;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mCAAmC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6CAA6C;IAC7C,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IACtD,6CAA6C;IAC7C,kBAAkB,CAAC,EAAE,CAAC,U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AGjC,YAAY,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,CAAC"}
@@ -1,83 +1,87 @@
1
- import b, { useRef as h, useEffect as I, useCallback as d } from "react";
2
- import { r as R } from "../../annotation-element-z6TdBGsn.js";
1
+ import I, { useRef as b, useEffect as O, useCallback as u } from "react";
2
+ import { r as R } from "../../annotation-element-CZQRsI-4.js";
3
3
  R();
4
- const y = ({
4
+ const H = ({
5
5
  theme: c = "auto",
6
- outputLevel: i = "standard",
7
- annotationColor: v,
8
- disabled: E = !1,
6
+ outputLevel: v = "standard",
7
+ annotationColor: f,
8
+ disabled: m = !1,
9
+ onBeforeAnnotationCreate: d,
9
10
  onAnnotationCreate: s,
10
11
  onAnnotationUpdate: l,
11
- onAnnotationDelete: u,
12
- onAnnotationsClear: e,
13
- onCopy: a,
14
- className: O
12
+ onAnnotationDelete: e,
13
+ onAnnotationsClear: r,
14
+ onCopy: i,
15
+ className: k
15
16
  }) => {
16
- const f = h(null);
17
- return I(() => {
18
- const t = f.current;
17
+ const E = b(null);
18
+ return O(() => {
19
+ const t = E.current;
20
+ t && t.setBeforeCreateHook(d ?? null);
21
+ }, [d]), O(() => {
22
+ const t = E.current;
19
23
  if (!t) return;
20
- const m = (n) => {
21
- const r = n.detail;
22
- s == null || s(r.annotation);
23
- }, g = (n) => {
24
- const r = n.detail;
25
- l == null || l(r.annotation);
24
+ const g = (n) => {
25
+ const a = n.detail;
26
+ s == null || s(a.annotation);
26
27
  }, o = (n) => {
27
- const r = n.detail;
28
- u == null || u(r.id);
28
+ const a = n.detail;
29
+ l == null || l(a.annotation);
29
30
  }, L = (n) => {
30
- const r = n.detail;
31
- e == null || e(r.annotations);
31
+ const a = n.detail;
32
+ e == null || e(a.id);
32
33
  }, p = (n) => {
33
- const r = n.detail;
34
- a == null || a(r.content, r.level);
34
+ const a = n.detail;
35
+ r == null || r(a.annotations);
36
+ }, h = (n) => {
37
+ const a = n.detail;
38
+ i == null || i(a.content, a.level);
35
39
  };
36
- return t.addEventListener("annotation:create", m), t.addEventListener("annotation:update", g), t.addEventListener("annotation:delete", o), t.addEventListener("annotation:clear", L), t.addEventListener("annotation:copy", p), () => {
37
- t.removeEventListener("annotation:create", m), t.removeEventListener("annotation:update", g), t.removeEventListener("annotation:delete", o), t.removeEventListener("annotation:clear", L), t.removeEventListener("annotation:copy", p);
40
+ return t.addEventListener("annotation:create", g), t.addEventListener("annotation:update", o), t.addEventListener("annotation:delete", L), t.addEventListener("annotation:clear", p), t.addEventListener("annotation:copy", h), () => {
41
+ t.removeEventListener("annotation:create", g), t.removeEventListener("annotation:update", o), t.removeEventListener("annotation:delete", L), t.removeEventListener("annotation:clear", p), t.removeEventListener("annotation:copy", h);
38
42
  };
39
- }, [s, l, u, e, a]), b.createElement("agent-ui-annotation", {
40
- ref: f,
43
+ }, [s, l, e, r, i]), I.createElement("agent-ui-annotation", {
44
+ ref: E,
41
45
  theme: c,
42
- "output-level": i,
43
- "annotation-color": v,
44
- disabled: E ? "" : void 0,
45
- class: O
46
+ "output-level": v,
47
+ "annotation-color": f,
48
+ disabled: m ? "" : void 0,
49
+ class: k
46
50
  });
47
51
  };
48
52
  function j() {
49
- const c = h(null), i = d(() => {
53
+ const c = b(null), v = u(() => {
50
54
  var e;
51
55
  (e = c.current) == null || e.activate();
52
- }, []), v = d(() => {
56
+ }, []), f = u(() => {
53
57
  var e;
54
58
  (e = c.current) == null || e.deactivate();
55
- }, []), E = d(() => {
59
+ }, []), m = u(() => {
56
60
  var e;
57
61
  (e = c.current) == null || e.toggle();
58
- }, []), s = d(async (e) => {
59
- var a;
60
- return ((a = c.current) == null ? void 0 : a.copyOutput(e)) ?? !1;
61
- }, []), l = d((e) => {
62
- var a;
63
- return ((a = c.current) == null ? void 0 : a.getOutput(e)) ?? "";
64
- }, []), u = d(() => {
62
+ }, []), d = u(async (e) => {
63
+ var r;
64
+ return ((r = c.current) == null ? void 0 : r.copyOutput(e)) ?? !1;
65
+ }, []), s = u((e) => {
66
+ var r;
67
+ return ((r = c.current) == null ? void 0 : r.getOutput(e)) ?? "";
68
+ }, []), l = u(() => {
65
69
  var e;
66
70
  (e = c.current) == null || e.clearAll();
67
71
  }, []);
68
72
  return {
69
73
  ref: c,
70
- activate: i,
71
- deactivate: v,
72
- toggle: E,
73
- copyOutput: s,
74
- getOutput: l,
75
- clearAll: u
74
+ activate: v,
75
+ deactivate: f,
76
+ toggle: m,
77
+ copyOutput: d,
78
+ getOutput: s,
79
+ clearAll: l
76
80
  };
77
81
  }
78
82
  export {
79
- y as AgentUIAnnotation,
80
- y as default,
83
+ H as AgentUIAnnotation,
84
+ H as default,
81
85
  j as useAgentUIAnnotation
82
86
  };
83
87
  //# sourceMappingURL=AgentUIAnnotation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AgentUIAnnotation.js","sources":["../../../src/adapters/react/AgentUIAnnotation.tsx"],"sourcesContent":["/**\n * React adapter for agent-ui-annotation\n */\n\nimport React, { useEffect, useRef, useCallback, type FC } from 'react';\nimport type { Annotation, AnnotationId, OutputLevel, ThemeMode } from '../../core/types';\nimport { registerAnnotationElement, type AnnotationElement } from '../../element/annotation-element';\n\n// Ensure custom element is registered\nregisterAnnotationElement();\n\n// Extend JSX types for the custom element\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'agent-ui-annotation': React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement> & {\n theme?: string;\n 'output-level'?: string;\n 'annotation-color'?: string;\n disabled?: string;\n ref?: React.Ref<AnnotationElement>;\n },\n HTMLElement\n >;\n }\n }\n}\n\nexport interface AgentUIAnnotationProps {\n /** Theme mode */\n theme?: ThemeMode;\n /** Output detail level */\n outputLevel?: OutputLevel;\n /** Annotation marker color */\n annotationColor?: string;\n /** Whether the tool is disabled */\n disabled?: boolean;\n /** Callback when an annotation is created */\n onAnnotationCreate?: (annotation: Annotation) => void;\n /** Callback when an annotation is updated */\n onAnnotationUpdate?: (annotation: Annotation) => void;\n /** Callback when an annotation is deleted */\n onAnnotationDelete?: (id: AnnotationId) => void;\n /** Callback when all annotations are cleared */\n onAnnotationsClear?: (annotations: Annotation[]) => void;\n /** Callback when output is copied */\n onCopy?: (content: string, level: OutputLevel) => void;\n /** Additional class name */\n className?: string;\n}\n\nexport interface AgentUIAnnotationRef {\n activate: () => void;\n deactivate: () => void;\n toggle: () => void;\n copyOutput: (level?: OutputLevel) => Promise<boolean>;\n getOutput: (level?: OutputLevel) => string;\n clearAll: () => void;\n}\n\n/**\n * React component wrapper for agent-ui-annotation\n */\nexport const AgentUIAnnotation: FC<AgentUIAnnotationProps> = ({\n theme = 'auto',\n outputLevel = 'standard',\n annotationColor,\n disabled = false,\n onAnnotationCreate,\n onAnnotationUpdate,\n onAnnotationDelete,\n onAnnotationsClear,\n onCopy,\n className,\n}) => {\n const ref = useRef<AnnotationElement>(null);\n\n // Handle events\n useEffect(() => {\n const element = ref.current;\n if (!element) return;\n\n const handleCreate = (e: Event) => {\n const detail = (e as CustomEvent).detail as { annotation: Annotation };\n onAnnotationCreate?.(detail.annotation);\n };\n\n const handleUpdate = (e: Event) => {\n const detail = (e as CustomEvent).detail as { annotation: Annotation };\n onAnnotationUpdate?.(detail.annotation);\n };\n\n const handleDelete = (e: Event) => {\n const detail = (e as CustomEvent).detail as { id: AnnotationId };\n onAnnotationDelete?.(detail.id);\n };\n\n const handleClear = (e: Event) => {\n const detail = (e as CustomEvent).detail as { annotations: Annotation[] };\n onAnnotationsClear?.(detail.annotations);\n };\n\n const handleCopy = (e: Event) => {\n const detail = (e as CustomEvent).detail as { content: string; level: OutputLevel };\n onCopy?.(detail.content, detail.level);\n };\n\n element.addEventListener('annotation:create', handleCreate);\n element.addEventListener('annotation:update', handleUpdate);\n element.addEventListener('annotation:delete', handleDelete);\n element.addEventListener('annotation:clear', handleClear);\n element.addEventListener('annotation:copy', handleCopy);\n\n return () => {\n element.removeEventListener('annotation:create', handleCreate);\n element.removeEventListener('annotation:update', handleUpdate);\n element.removeEventListener('annotation:delete', handleDelete);\n element.removeEventListener('annotation:clear', handleClear);\n element.removeEventListener('annotation:copy', handleCopy);\n };\n }, [onAnnotationCreate, onAnnotationUpdate, onAnnotationDelete, onAnnotationsClear, onCopy]);\n\n return React.createElement('agent-ui-annotation', {\n ref,\n theme,\n 'output-level': outputLevel,\n 'annotation-color': annotationColor,\n disabled: disabled ? '' : undefined,\n class: className,\n });\n};\n\n/**\n * Hook for using agent-ui-annotation imperatively\n */\nexport function useAgentUIAnnotation(): {\n ref: React.RefObject<AnnotationElement | null>;\n activate: () => void;\n deactivate: () => void;\n toggle: () => void;\n copyOutput: (level?: OutputLevel) => Promise<boolean>;\n getOutput: (level?: OutputLevel) => string;\n clearAll: () => void;\n} {\n const ref = useRef<AnnotationElement | null>(null);\n\n const activate = useCallback(() => {\n ref.current?.activate();\n }, []);\n\n const deactivate = useCallback(() => {\n ref.current?.deactivate();\n }, []);\n\n const toggle = useCallback(() => {\n ref.current?.toggle();\n }, []);\n\n const copyOutput = useCallback(async (level?: OutputLevel) => {\n return ref.current?.copyOutput(level) ?? false;\n }, []);\n\n const getOutput = useCallback((level?: OutputLevel) => {\n return ref.current?.getOutput(level) ?? '';\n }, []);\n\n const clearAll = useCallback(() => {\n ref.current?.clearAll();\n }, []);\n\n return {\n ref,\n activate,\n deactivate,\n toggle,\n copyOutput,\n getOutput,\n clearAll,\n };\n}\n\nexport default AgentUIAnnotation;\n"],"names":["registerAnnotationElement","AgentUIAnnotation","theme","outputLevel","annotationColor","disabled","onAnnotationCreate","onAnnotationUpdate","onAnnotationDelete","onAnnotationsClear","onCopy","className","ref","useRef","useEffect","element","handleCreate","e","detail","handleUpdate","handleDelete","handleClear","handleCopy","React","useAgentUIAnnotation","activate","useCallback","_a","deactivate","toggle","copyOutput","level","getOutput","clearAll"],"mappings":";;AASAA,EAAA;AAwDO,MAAMC,IAAgD,CAAC;AAAA,EAC5D,OAAAC,IAAQ;AAAA,EACR,aAAAC,IAAc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x"],"sourcesContent":["/**\n * React adapter for agent-ui-annotation\n */\n\nimport React, { useEffect, useRef, useCallback, type FC } from 'react';\nimport type { Annotation, AnnotationId, OutputLevel, ThemeMode, BeforeAnnotationCreateHook, BeforeAnnotationCreateData, BeforeAnnotationCreateResult } from '../../core/types';\nimport { registerAnnotationElement, type AnnotationElement } from '../../element/annotation-element';\n\n// Ensure custom element is registered\nregisterAnnotationElement();\n\n// Extend JSX types for the custom element\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n 'agent-ui-annotation': React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLElement> & {\n theme?: string;\n 'output-level'?: string;\n 'annotation-color'?: string;\n disabled?: string;\n ref?: React.Ref<AnnotationElement>;\n },\n HTMLElement\n >;\n }\n }\n}\n\nexport interface AgentUIAnnotationProps {\n /** Theme mode */\n theme?: ThemeMode;\n /** Output detail level */\n outputLevel?: OutputLevel;\n /** Annotation marker color */\n annotationColor?: string;\n /** Whether the tool is disabled */\n disabled?: boolean;\n /** Hook called before creating an annotation - can add context, modify comment, or cancel */\n onBeforeAnnotationCreate?: BeforeAnnotationCreateHook;\n /** Callback when an annotation is created */\n onAnnotationCreate?: (annotation: Annotation) => void;\n /** Callback when an annotation is updated */\n onAnnotationUpdate?: (annotation: Annotation) => void;\n /** Callback when an annotation is deleted */\n onAnnotationDelete?: (id: AnnotationId) => void;\n /** Callback when all annotations are cleared */\n onAnnotationsClear?: (annotations: Annotation[]) => void;\n /** Callback when output is copied */\n onCopy?: (content: string, level: OutputLevel) => void;\n /** Additional class name */\n className?: string;\n}\n\nexport interface AgentUIAnnotationRef {\n activate: () => void;\n deactivate: () => void;\n toggle: () => void;\n copyOutput: (level?: OutputLevel) => Promise<boolean>;\n getOutput: (level?: OutputLevel) => string;\n clearAll: () => void;\n}\n\n/**\n * React component wrapper for agent-ui-annotation\n */\nexport const AgentUIAnnotation: FC<AgentUIAnnotationProps> = ({\n theme = 'auto',\n outputLevel = 'standard',\n annotationColor,\n disabled = false,\n onBeforeAnnotationCreate,\n onAnnotationCreate,\n onAnnotationUpdate,\n onAnnotationDelete,\n onAnnotationsClear,\n onCopy,\n className,\n}) => {\n const ref = useRef<AnnotationElement>(null);\n\n // Set up the before create hook\n useEffect(() => {\n const element = ref.current;\n if (!element) return;\n\n element.setBeforeCreateHook(onBeforeAnnotationCreate ?? null);\n }, [onBeforeAnnotationCreate]);\n\n // Handle events\n useEffect(() => {\n const element = ref.current;\n if (!element) return;\n\n const handleCreate = (e: Event) => {\n const detail = (e as CustomEvent).detail as { annotation: Annotation };\n onAnnotationCreate?.(detail.annotation);\n };\n\n const handleUpdate = (e: Event) => {\n const detail = (e as CustomEvent).detail as { annotation: Annotation };\n onAnnotationUpdate?.(detail.annotation);\n };\n\n const handleDelete = (e: Event) => {\n const detail = (e as CustomEvent).detail as { id: AnnotationId };\n onAnnotationDelete?.(detail.id);\n };\n\n const handleClear = (e: Event) => {\n const detail = (e as CustomEvent).detail as { annotations: Annotation[] };\n onAnnotationsClear?.(detail.annotations);\n };\n\n const handleCopy = (e: Event) => {\n const detail = (e as CustomEvent).detail as { content: string; level: OutputLevel };\n onCopy?.(detail.content, detail.level);\n };\n\n element.addEventListener('annotation:create', handleCreate);\n element.addEventListener('annotation:update', handleUpdate);\n element.addEventListener('annotation:delete', handleDelete);\n element.addEventListener('annotation:clear', handleClear);\n element.addEventListener('annotation:copy', handleCopy);\n\n return () => {\n element.removeEventListener('annotation:create', handleCreate);\n element.removeEventListener('annotation:update', handleUpdate);\n element.removeEventListener('annotation:delete', handleDelete);\n element.removeEventListener('annotation:clear', handleClear);\n element.removeEventListener('annotation:copy', handleCopy);\n };\n }, [onAnnotationCreate, onAnnotationUpdate, onAnnotationDelete, onAnnotationsClear, onCopy]);\n\n return React.createElement('agent-ui-annotation', {\n ref,\n theme,\n 'output-level': outputLevel,\n 'annotation-color': annotationColor,\n disabled: disabled ? '' : undefined,\n class: className,\n });\n};\n\n/**\n * Hook for using agent-ui-annotation imperatively\n */\nexport function useAgentUIAnnotation(): {\n ref: React.RefObject<AnnotationElement | null>;\n activate: () => void;\n deactivate: () => void;\n toggle: () => void;\n copyOutput: (level?: OutputLevel) => Promise<boolean>;\n getOutput: (level?: OutputLevel) => string;\n clearAll: () => void;\n} {\n const ref = useRef<AnnotationElement | null>(null);\n\n const activate = useCallback(() => {\n ref.current?.activate();\n }, []);\n\n const deactivate = useCallback(() => {\n ref.current?.deactivate();\n }, []);\n\n const toggle = useCallback(() => {\n ref.current?.toggle();\n }, []);\n\n const copyOutput = useCallback(async (level?: OutputLevel) => {\n return ref.current?.copyOutput(level) ?? false;\n }, []);\n\n const getOutput = useCallback((level?: OutputLevel) => {\n return ref.current?.getOutput(level) ?? '';\n }, []);\n\n const clearAll = useCallback(() => {\n ref.current?.clearAll();\n }, []);\n\n return {\n ref,\n activate,\n deactivate,\n toggle,\n copyOutput,\n getOutput,\n clearAll,\n };\n}\n\nexport default AgentUIAnnotation;\n\n// Re-export hook types for convenience\nexport type { BeforeAnnotationCreateHook, BeforeAnnotationCreateData, BeforeAnnotationCreateResult };\n"],"names":["registerAnnotationElement","AgentUIAnnotation","theme","outputLevel","annotationColor","disabled","onBeforeAnnotationCreate","onAnnotationCreate","onAnnotationUpdate","onAnnotationDelete","onAnnotationsClear","onCopy","className","ref","useRef","useEffect","element","handleCreate","e","detail","handleUpdate","handleDelete","handleClear","handleCopy","React","useAgentUIAnnotation","activate","useCallback","_a","deactivate","toggle","copyOutput","level","getOutput","clearAll"],"mappings":";;AASAA,EAAA;AA0DO,MAAMC,IAAgD,CAAC;AAAA,EAC5D,OAAAC,IAAQ;AAAA,EACR,aAAAC,IAAc;AAAA,EACd,iBAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,0BAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,QAAAC;AAAA,EACA,WAAAC;AACF,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D;AAAA,EACF,GAAG,CAAChB,GAAoBC,GAAoBC,GAAoBC,GAAoBC,CAAM,CAAC,GAEpFa,EAAM,cAAc,uBAAuB;AAAA,IAChD,KAAAX;AAAA,IACA,OAAAX;AAAA,IACA,gBAAgBC;AAAA,IAChB,oBAAoBC;AAAA,IACpB,UAAUC,IAAW,KAAK;AAAA,IAC1B,OAAOO;AAAA,EAAA,CACR;AACH;AAKO,SAASa,IAQd;AACA,QAAMZ,IAAMC,EAAiC,IAAI,GAE3CY,IAAWC,EAAY,MAAM;;AACjC,KAAAC,IAAAf,EAAI,YAAJ,QAAAe,EAAa;AAAA,EACf,GAAG,CAAA,CAAE,GAECC,IAAaF,EAAY,MAAM;;AACnC,KAAAC,IAAAf,EAAI,YAAJ,QAAAe,EAAa;AAAA,EACf,GAAG,CAAA,CAAE,GAECE,IAASH,EAAY,MAAM;;AAC/B,KAAAC,IAAAf,EAAI,YAAJ,QAAAe,EAAa;AAAA,EACf,GAAG,CAAA,CAAE,GAECG,IAAaJ,EAAY,OAAOK,MAAwB;;AAC5D,aAAOJ,IAAAf,EAAI,YAAJ,gBAAAe,EAAa,WAAWI,OAAU;AAAA,EAC3C,GAAG,CAAA,CAAE,GAECC,IAAYN,EAAY,CAACK,MAAwB;;AACrD,aAAOJ,IAAAf,EAAI,YAAJ,gBAAAe,EAAa,UAAUI,OAAU;AAAA,EAC1C,GAAG,CAAA,CAAE,GAECE,IAAWP,EAAY,MAAM;;AACjC,KAAAC,IAAAf,EAAI,YAAJ,QAAAe,EAAa;AAAA,EACf,GAAG,CAAA,CAAE;AAEL,SAAO;AAAA,IACL,KAAAf;AAAA,IACA,UAAAa;AAAA,IACA,YAAAG;AAAA,IACA,QAAAC;AAAA,IACA,YAAAC;AAAA,IACA,WAAAE;AAAA,IACA,UAAAC;AAAA,EAAA;AAEJ;"}
@@ -1,109 +1,111 @@
1
1
  import "svelte/internal/disclose-version";
2
2
  import * as e from "svelte/internal/client";
3
- import { onMount as C } from "svelte";
4
- import { r as b } from "../../annotation-element-z6TdBGsn.js";
5
- import { A as k } from "../../annotation-element-z6TdBGsn.js";
6
- var U = e.from_html("<agent-ui-annotation></agent-ui-annotation>", 2);
7
- function M(n, a) {
8
- e.push(a, !0);
9
- let f = e.prop(a, "theme", 3, "auto"), s = e.prop(a, "outputLevel", 3, "standard"), d = e.prop(a, "disabled", 3, !1), l = e.state(void 0);
10
- const r = (t) => {
11
- var i;
3
+ import { onMount as O } from "svelte";
4
+ import { r as B } from "../../annotation-element-CZQRsI-4.js";
5
+ import { a as P } from "../../annotation-element-CZQRsI-4.js";
6
+ var b = e.from_html("<agent-ui-annotation></agent-ui-annotation>", 2);
7
+ function D(a, n) {
8
+ e.push(n, !0);
9
+ let f = e.prop(n, "theme", 3, "auto"), v = e.prop(n, "outputLevel", 3, "standard"), r = e.prop(n, "disabled", 3, !1), i = e.state(void 0);
10
+ const d = (t) => {
11
+ var l;
12
12
  const o = t.detail;
13
- (i = a.onAnnotationCreate) == null || i.call(a, o.annotation);
13
+ (l = n.onAnnotationCreate) == null || l.call(n, o.annotation);
14
14
  }, u = (t) => {
15
- var i;
15
+ var l;
16
16
  const o = t.detail;
17
- (i = a.onAnnotationUpdate) == null || i.call(a, o.annotation);
18
- }, v = (t) => {
19
- var i;
20
- const o = t.detail;
21
- (i = a.onAnnotationDelete) == null || i.call(a, o.id);
17
+ (l = n.onAnnotationUpdate) == null || l.call(n, o.annotation);
22
18
  }, g = (t) => {
23
- var i;
19
+ var l;
20
+ const o = t.detail;
21
+ (l = n.onAnnotationDelete) == null || l.call(n, o.id);
22
+ }, s = (t) => {
23
+ var l;
24
24
  const o = t.detail;
25
- (i = a.onAnnotationsClear) == null || i.call(a, o.annotations);
25
+ (l = n.onAnnotationsClear) == null || l.call(n, o.annotations);
26
26
  }, m = (t) => {
27
- var i;
27
+ var l;
28
28
  const o = t.detail;
29
- (i = a.onCopy) == null || i.call(a, o.content, o.level);
29
+ (l = n.onCopy) == null || l.call(n, o.content, o.level);
30
30
  };
31
- C(() => {
32
- b();
33
- const t = e.get(l);
31
+ O(() => {
32
+ B();
33
+ const t = e.get(i);
34
34
  if (!t) return;
35
- t.addEventListener("annotation:scope", r), t.addEventListener("annotation:update", u), t.addEventListener("annotation:delete", v), t.addEventListener("annotation:clear", g), t.addEventListener("annotation:copy", m);
35
+ n.onBeforeAnnotationCreate && t.setBeforeCreateHook(n.onBeforeAnnotationCreate), t.addEventListener("annotation:create", d), t.addEventListener("annotation:update", u), t.addEventListener("annotation:delete", g), t.addEventListener("annotation:clear", s), t.addEventListener("annotation:copy", m);
36
36
  const o = e.effect_root(() => {
37
37
  e.user_effect(() => {
38
- d() && e.get(l) && e.get(l).deactivate();
38
+ r() && e.get(i) && e.get(i).deactivate();
39
+ }), e.user_effect(() => {
40
+ e.get(i) && e.get(i).setBeforeCreateHook(n.onBeforeAnnotationCreate ?? null);
39
41
  });
40
42
  });
41
43
  return () => {
42
- t.removeEventListener("annotation:scope", r), t.removeEventListener("annotation:update", u), t.removeEventListener("annotation:delete", v), t.removeEventListener("annotation:clear", g), t.removeEventListener("annotation:copy", m), o();
44
+ t.removeEventListener("annotation:create", d), t.removeEventListener("annotation:update", u), t.removeEventListener("annotation:delete", g), t.removeEventListener("annotation:clear", s), t.removeEventListener("annotation:copy", m), o();
43
45
  };
44
46
  });
45
47
  function _() {
46
48
  var t;
47
- (t = e.get(l)) == null || t.activate();
49
+ (t = e.get(i)) == null || t.activate();
48
50
  }
49
51
  function A() {
50
52
  var t;
51
- (t = e.get(l)) == null || t.deactivate();
53
+ (t = e.get(i)) == null || t.deactivate();
52
54
  }
53
55
  function E() {
54
56
  var t;
55
- (t = e.get(l)) == null || t.toggle();
57
+ (t = e.get(i)) == null || t.toggle();
56
58
  }
57
- async function L(t) {
59
+ async function C(t) {
58
60
  var o;
59
- return ((o = e.get(l)) == null ? void 0 : o.copyOutput(t)) ?? !1;
61
+ return ((o = e.get(i)) == null ? void 0 : o.copyOutput(t)) ?? !1;
60
62
  }
61
- function h(t) {
63
+ function L(t) {
62
64
  var o;
63
- return ((o = e.get(l)) == null ? void 0 : o.getOutput(t)) ?? "";
65
+ return ((o = e.get(i)) == null ? void 0 : o.getOutput(t)) ?? "";
64
66
  }
65
- function y() {
67
+ function h() {
66
68
  var t;
67
- (t = e.get(l)) == null || t.clearAll();
69
+ (t = e.get(i)) == null || t.clearAll();
68
70
  }
69
- var O = {
71
+ var y = {
70
72
  activate: _,
71
73
  deactivate: A,
72
74
  toggle: E,
73
- copyOutput: L,
74
- getOutput: h,
75
- clearAll: y
76
- }, c = U();
77
- return e.template_effect(() => e.set_custom_element_data(c, "theme", f())), e.template_effect(() => e.set_custom_element_data(c, "output-level", s())), e.template_effect(() => e.set_custom_element_data(c, "annotation-color", a.annotationColor)), e.template_effect(() => e.set_custom_element_data(c, "disabled", d() ? "" : void 0)), e.bind_this(c, (t) => e.set(l, t), () => e.get(l)), e.append(n, c), e.pop(O);
75
+ copyOutput: C,
76
+ getOutput: L,
77
+ clearAll: h
78
+ }, c = b();
79
+ return e.template_effect(() => e.set_custom_element_data(c, "theme", f())), e.template_effect(() => e.set_custom_element_data(c, "output-level", v())), e.template_effect(() => e.set_custom_element_data(c, "annotation-color", n.annotationColor)), e.template_effect(() => e.set_custom_element_data(c, "disabled", r() ? "" : void 0)), e.bind_this(c, (t) => e.set(i, t), () => e.get(i)), e.append(a, c), e.pop(y);
78
80
  }
79
- function P() {
80
- let n = null;
81
+ function H() {
82
+ let a = null;
81
83
  return {
82
84
  get ref() {
83
- return n;
85
+ return a;
84
86
  },
85
87
  set ref(u) {
86
- n = u;
88
+ a = u;
87
89
  },
88
90
  activate: () => {
89
- n == null || n.activate();
91
+ a == null || a.activate();
90
92
  },
91
93
  deactivate: () => {
92
- n == null || n.deactivate();
94
+ a == null || a.deactivate();
93
95
  },
94
96
  toggle: () => {
95
- n == null || n.toggle();
97
+ a == null || a.toggle();
96
98
  },
97
- copyOutput: async (u) => (n == null ? void 0 : n.copyOutput(u)) ?? Promise.resolve(!1),
98
- getOutput: (u) => (n == null ? void 0 : n.getOutput(u)) ?? "",
99
+ copyOutput: async (u) => (a == null ? void 0 : a.copyOutput(u)) ?? Promise.resolve(!1),
100
+ getOutput: (u) => (a == null ? void 0 : a.getOutput(u)) ?? "",
99
101
  clearAll: () => {
100
- n == null || n.clearAll();
102
+ a == null || a.clearAll();
101
103
  }
102
104
  };
103
105
  }
104
106
  export {
105
- M as AgentUIAnnotation,
106
- k as AnnotationElement,
107
- P as useAgentUIAnnotation
107
+ D as AgentUIAnnotation,
108
+ P as AnnotationElement,
109
+ H as useAgentUIAnnotation
108
110
  };
109
111
  //# sourceMappingURL=index.js.map