agent-ui-annotation 0.4.0 → 0.4.1

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.
@@ -1,5 +1,5 @@
1
1
  import b, { useRef as h, useEffect as I, useCallback as d } from "react";
2
- import { r as R } from "../../annotation-element-CJm7-qrT.js";
2
+ import { r as R } from "../../annotation-element-z6TdBGsn.js";
3
3
  R();
4
4
  const y = ({
5
5
  theme: c = "auto",
@@ -1,8 +1,8 @@
1
1
  import "svelte/internal/disclose-version";
2
2
  import * as e from "svelte/internal/client";
3
3
  import { onMount as C } from "svelte";
4
- import { r as b } from "../../annotation-element-CJm7-qrT.js";
5
- import { A as k } from "../../annotation-element-CJm7-qrT.js";
4
+ import { r as b } from "../../annotation-element-z6TdBGsn.js";
5
+ import { A as k } from "../../annotation-element-z6TdBGsn.js";
6
6
  var U = e.from_html("<agent-ui-annotation></agent-ui-annotation>", 2);
7
7
  function M(n, a) {
8
8
  e.push(a, !0);
@@ -1,5 +1,5 @@
1
- import { r as A, h as g } from "../../annotation-element-CJm7-qrT.js";
2
- import { A as b } from "../../annotation-element-CJm7-qrT.js";
1
+ import { r as A, h as g } from "../../annotation-element-z6TdBGsn.js";
2
+ import { A as b } from "../../annotation-element-z6TdBGsn.js";
3
3
  A();
4
4
  function E(n = {}) {
5
5
  const {
@@ -1,5 +1,5 @@
1
- import { r as p } from "../../annotation-element-CJm7-qrT.js";
2
- import { A as P } from "../../annotation-element-CJm7-qrT.js";
1
+ import { r as p } from "../../annotation-element-z6TdBGsn.js";
2
+ import { A as P } from "../../annotation-element-z6TdBGsn.js";
3
3
  import { defineComponent as f, ref as m, onMounted as y, onUnmounted as A, watch as E, resolveComponent as L, openBlock as O, createBlock as h } from "vue";
4
4
  const R = /* @__PURE__ */ f({
5
5
  __name: "AgentUIAnnotation",
@@ -1,5 +1,5 @@
1
- import { r as e } from "./annotation-element-CJm7-qrT.js";
2
- import { A as o, S as r, c as s, a as i, b as c, d as l, e as m, g as f, f as A, i as E, h as g, j as p, k as C, t as S, l as h, z as O } from "./annotation-element-CJm7-qrT.js";
1
+ import { r as e } from "./annotation-element-z6TdBGsn.js";
2
+ import { A as o, S as r, c as s, a as i, b as c, d as l, e as m, g as f, f as A, i as E, h as g, j as p, k as C, t as S, l as h, z as O } from "./annotation-element-z6TdBGsn.js";
3
3
  import { createAnnotation as x, init as d } from "./adapters/vanilla/index.js";
4
4
  e();
5
5
  export {
@@ -1,6 +1,6 @@
1
1
  var Tt = Object.defineProperty;
2
2
  var Lt = (t, n, e) => n in t ? Tt(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
3
- var A = (t, n, e) => Lt(t, typeof n != "symbol" ? n + "" : n, e);
3
+ var $ = (t, n, e) => Lt(t, typeof n != "symbol" ? n + "" : n, e);
4
4
  function Ft(t) {
5
5
  let n = { ...t };
6
6
  const e = /* @__PURE__ */ new Set();
@@ -113,7 +113,7 @@ const ft = {
113
113
  x: 20,
114
114
  y: 20
115
115
  };
116
- function Yt(t) {
116
+ function Rt(t) {
117
117
  return {
118
118
  scopes: /* @__PURE__ */ new Map(),
119
119
  selectedAnnotationId: null,
@@ -151,8 +151,8 @@ function Yt(t) {
151
151
  ...t
152
152
  };
153
153
  }
154
- const Rt = 40;
155
- function k(t, n = Rt) {
154
+ const Yt = 40;
155
+ function k(t, n = Yt) {
156
156
  const e = t.trim().replace(/\s+/g, " ");
157
157
  return e.length <= n ? e : e.slice(0, n - 3) + "...";
158
158
  }
@@ -982,7 +982,7 @@ function Pe() {
982
982
  return console.error("[Annotation] Failed to load settings:", t), null;
983
983
  }
984
984
  }
985
- function Ye(t, n = 1e3) {
985
+ function Re(t, n = 1e3) {
986
986
  let e = null;
987
987
  const o = () => {
988
988
  e !== null && (clearTimeout(e), e = null), Le(t());
@@ -1096,7 +1096,7 @@ const B = {
1096
1096
  no: "No",
1097
1097
  none: "none"
1098
1098
  }
1099
- }, Re = {
1099
+ }, Ye = {
1100
1100
  toolbar: {
1101
1101
  activate: "激活 agent-ui-annotation",
1102
1102
  freeze: "冻结动画",
@@ -1201,7 +1201,7 @@ const B = {
1201
1201
  }
1202
1202
  }, wt = /* @__PURE__ */ new Map([
1203
1203
  ["en", B],
1204
- ["zh-CN", Re]
1204
+ ["zh-CN", Ye]
1205
1205
  ]);
1206
1206
  let O = B, $t = !1;
1207
1207
  const Z = B;
@@ -1362,7 +1362,7 @@ async function Be(t) {
1362
1362
  }
1363
1363
  }
1364
1364
  const J = "data-annotation-toolbar", Q = "data-annotation-marker", tt = "data-annotation-popup", et = "data-annotation-settings";
1365
- function R(t) {
1365
+ function Y(t) {
1366
1366
  return t ? t.tagName.toLowerCase() === "agent-ui-annotation" || t.closest("agent-ui-annotation") ? !0 : t.hasAttribute(J) || t.hasAttribute(Q) || t.hasAttribute(tt) || t.hasAttribute(et) || t.closest(`[${J}], [${Q}], [${tt}], [${et}]`) !== null : !1;
1367
1367
  }
1368
1368
  function We(t) {
@@ -1374,7 +1374,7 @@ function We(t) {
1374
1374
  }
1375
1375
  function Ue(t) {
1376
1376
  const n = t.target;
1377
- return R(n) ? null : n;
1377
+ return Y(n) ? null : n;
1378
1378
  }
1379
1379
  function qe(t, n) {
1380
1380
  let e = !1;
@@ -1394,7 +1394,7 @@ function qe(t, n) {
1394
1394
  }, a = (p) => {
1395
1395
  if (t.getState().mode !== "multi-select") return;
1396
1396
  const c = p.target;
1397
- if (R(c)) return;
1397
+ if (Y(c)) return;
1398
1398
  const m = {
1399
1399
  x: p.clientX,
1400
1400
  y: p.clientY
@@ -1440,7 +1440,7 @@ function Ge(t) {
1440
1440
  height: window.innerHeight
1441
1441
  }, d = [];
1442
1442
  for (const h of r) {
1443
- if (R(h)) continue;
1443
+ if (Y(h)) continue;
1444
1444
  const u = h.getBoundingClientRect();
1445
1445
  u.right < n || u.left > e || u.bottom < o || u.top > a || u.width > i.width * 0.8 && u.height > i.height * 0.5 || u.width < 10 || u.height < 10 || d.push(h);
1446
1446
  }
@@ -1456,11 +1456,11 @@ function Ke(t, n, e = {}) {
1456
1456
  const S = r;
1457
1457
  r = null, t(...S);
1458
1458
  }, u = (v) => {
1459
- const S = i !== null ? v - i : 0, $ = v - d;
1460
- return i === null || S >= n || S < 0 || $ >= n;
1459
+ const S = i !== null ? v - i : 0, A = v - d;
1460
+ return i === null || S >= n || S < 0 || A >= n;
1461
1461
  }, p = (v) => {
1462
- const S = i !== null ? v - i : 0, $ = n - S;
1463
- return Math.max(0, $);
1462
+ const S = i !== null ? v - i : 0, A = n - S;
1463
+ return Math.max(0, A);
1464
1464
  }, l = () => {
1465
1465
  const v = Date.now();
1466
1466
  if (u(v))
@@ -1473,8 +1473,8 @@ function Ke(t, n, e = {}) {
1473
1473
  }, y = () => {
1474
1474
  s !== null && c(Date.now());
1475
1475
  }, b = (...v) => {
1476
- const S = Date.now(), $ = u(S);
1477
- r = v, i = S, $ && s === null && (o && h(S), s = setTimeout(l, n));
1476
+ const S = Date.now(), A = u(S);
1477
+ r = v, i = S, A && s === null && (o && h(S), s = setTimeout(l, n));
1478
1478
  };
1479
1479
  return b.cancel = m, b.flush = y, b;
1480
1480
  }
@@ -1493,7 +1493,7 @@ function Je(t, n) {
1493
1493
  if (p.popupVisible || p.settingsPanelVisible)
1494
1494
  return;
1495
1495
  const l = u.target;
1496
- if (R(l)) {
1496
+ if (Y(l)) {
1497
1497
  o !== null && (o = null, t.setState({
1498
1498
  hoveredElement: null,
1499
1499
  hoveredElementInfo: null
@@ -1548,8 +1548,8 @@ function tn(t, n) {
1548
1548
  e = b, o = !1;
1549
1549
  }, d = (b) => {
1550
1550
  if (!e) return;
1551
- const v = b.clientX - e.x, S = b.clientY - e.y, $ = Math.sqrt(v * v + S * S);
1552
- if (!o && $ > Qe) {
1551
+ const v = b.clientX - e.x, S = b.clientY - e.y, A = Math.sqrt(v * v + S * S);
1552
+ if (!o && A > Qe) {
1553
1553
  o = !0, s();
1554
1554
  const I = {
1555
1555
  startX: e.x,
@@ -1582,8 +1582,8 @@ function tn(t, n) {
1582
1582
  selectionRect: null,
1583
1583
  selectionPreviewElements: []
1584
1584
  }), !v) return [];
1585
- const $ = Math.abs(v.endX - v.startX), I = Math.abs(v.endY - v.startY);
1586
- return $ < it && I < it ? [] : S.length > 0 ? S : U(v);
1585
+ const A = Math.abs(v.endX - v.startX), I = Math.abs(v.endY - v.startY);
1586
+ return A < it && I < it ? [] : S.length > 0 ? S : U(v);
1587
1587
  }, u = () => {
1588
1588
  e = null, o = !1, r(), t.setState({
1589
1589
  isSelecting: !1,
@@ -1594,7 +1594,7 @@ function tn(t, n) {
1594
1594
  const v = t.getState();
1595
1595
  if (v.mode !== "select" && v.mode !== "multi-select" || v.popupVisible) return;
1596
1596
  const S = b.target;
1597
- R(S) || b.button === 0 && i({ x: b.clientX, y: b.clientY });
1597
+ Y(S) || b.button === 0 && i({ x: b.clientX, y: b.clientY });
1598
1598
  }, l = (b) => {
1599
1599
  e && d(b);
1600
1600
  }, c = () => {
@@ -1620,7 +1620,7 @@ function U(t) {
1620
1620
  height: window.innerHeight
1621
1621
  }, d = [];
1622
1622
  for (const h of r) {
1623
- if (R(h)) continue;
1623
+ if (Y(h)) continue;
1624
1624
  const u = h.getBoundingClientRect();
1625
1625
  !(u.right >= n && u.left <= e && u.bottom >= o && u.top <= a) || u.width > i.width * 0.8 && u.height > i.height * 0.5 || u.width < 10 || u.height < 10 || d.push(h);
1626
1626
  }
@@ -1751,24 +1751,24 @@ function pn(t = {}) {
1751
1751
  ...h,
1752
1752
  ...n
1753
1753
  }, l = Ft(
1754
- Yt({
1754
+ Rt({
1755
1755
  settings: p,
1756
1756
  scopes: u
1757
1757
  })
1758
- ), c = zt(), m = Ae(l, c), y = an(l, c), b = qe(l, c), v = Je(l, c), S = tn(l, c), $ = Ye(() => l.getState().scopes, 1e3);
1759
- o && c.on("scope:create", ({ scope: g }) => o(g)), a && c.on("scope:update", ({ scope: g }) => a(g)), s && c.on("scope:delete", ({ id: g }) => s(g)), r && c.on("scopes:clear", ({ scopes: g }) => r(g)), c.on("scope:create", () => $.save()), c.on("scope:update", () => $.save()), c.on("scope:delete", () => $.save()), c.on("scopes:clear", () => $.save()), c.on("settings:change", ({ settings: g }) => {
1758
+ ), c = zt(), m = Ae(l, c), y = an(l, c), b = qe(l, c), v = Je(l, c), S = tn(l, c), A = Re(() => l.getState().scopes, 1e3);
1759
+ o && c.on("scope:create", ({ scope: g }) => o(g)), a && c.on("scope:update", ({ scope: g }) => a(g)), s && c.on("scope:delete", ({ id: g }) => s(g)), r && c.on("scopes:clear", ({ scopes: g }) => r(g)), c.on("scope:create", () => A.save()), c.on("scope:update", () => A.save()), c.on("scope:delete", () => A.save()), c.on("scopes:clear", () => A.save()), c.on("settings:change", ({ settings: g }) => {
1760
1760
  const w = l.getState().settings;
1761
1761
  ze({ ...w, ...g });
1762
1762
  }), c.on("element:click", ({ element: g, elementInfo: w, clickX: E, clickY: T }) => {
1763
1763
  if (l.getState().mode === "disabled") return;
1764
- const Y = w.isFixed ? T : T - window.scrollY;
1764
+ const R = w.isFixed ? T : T - window.scrollY;
1765
1765
  l.setState({
1766
1766
  popupVisible: !0,
1767
1767
  popupAnnotationId: null,
1768
1768
  popupElementInfo: w,
1769
1769
  popupClickX: E,
1770
1770
  // X is always viewport-relative
1771
- popupClickY: Y,
1771
+ popupClickY: R,
1772
1772
  // Convert to viewport for popup positioning
1773
1773
  pendingMarkerX: E,
1774
1774
  // Document coords for marker
@@ -1779,7 +1779,7 @@ function pn(t = {}) {
1779
1779
  });
1780
1780
  }), c.on("multiselect:end", ({ elements: g }) => {
1781
1781
  if (g.length === 0) return;
1782
- const E = l.getState().settings.outputLevel === "forensic", T = g.map((L) => _(L, E)), F = g.map((L) => L.getBoundingClientRect()), Y = Math.min(...F.map((L) => L.left)), At = Math.max(...F.map((L) => L.right)), Ct = Math.min(...F.map((L) => L.top)), Et = Math.max(...F.map((L) => L.bottom)), Mt = (Y + At) / 2, It = (Ct + Et) / 2;
1782
+ const E = l.getState().settings.outputLevel === "forensic", T = g.map((L) => _(L, E)), F = g.map((L) => L.getBoundingClientRect()), R = Math.min(...F.map((L) => L.left)), At = Math.max(...F.map((L) => L.right)), Ct = Math.min(...F.map((L) => L.top)), Et = Math.max(...F.map((L) => L.bottom)), Mt = (R + At) / 2, It = (Ct + Et) / 2;
1783
1783
  l.setState({
1784
1784
  popupVisible: !0,
1785
1785
  popupAnnotationId: null,
@@ -1851,10 +1851,10 @@ function pn(t = {}) {
1851
1851
  getSettings: () => l.getState().settings,
1852
1852
  copyOutput: async (g) => {
1853
1853
  const w = l.getState(), E = g || w.settings.outputLevel, T = m.getAllScopes(), F = rt(T, E);
1854
- let Y = !0;
1855
- return d && (Y = await Be(F)), Y && (l.setState({ showCopiedFeedback: !0 }), setTimeout(() => {
1854
+ let R = !0;
1855
+ return d && (R = await Be(F)), R && (l.setState({ showCopiedFeedback: !0 }), setTimeout(() => {
1856
1856
  l.setState({ showCopiedFeedback: !1 });
1857
- }, 2e3), i && i(F, E), c.emit("output:copy", { content: F, level: E }), w.settings.autoClearAfterCopy && m.clearAllScopes()), Y;
1857
+ }, 2e3), i && i(F, E), c.emit("output:copy", { content: F, level: E }), w.settings.autoClearAfterCopy && m.clearAllScopes()), R;
1858
1858
  },
1859
1859
  getOutput: (g) => {
1860
1860
  const w = l.getState(), E = g || w.settings.outputLevel, T = m.getAllScopes();
@@ -1895,7 +1895,7 @@ function pn(t = {}) {
1895
1895
  },
1896
1896
  subscribe: (g) => l.subscribe(g),
1897
1897
  destroy: () => {
1898
- H(), $.flush(), $.destroy(), y.destroy(), c.destroy(), l.destroy();
1898
+ H(), A.flush(), A.destroy(), y.destroy(), c.destroy(), l.destroy();
1899
1899
  }
1900
1900
  };
1901
1901
  }
@@ -3091,26 +3091,30 @@ function Mn(t) {
3091
3091
  class In extends HTMLElement {
3092
3092
  constructor() {
3093
3093
  super();
3094
- A(this, "core", null);
3095
- A(this, "shadow");
3096
- A(this, "unsubscribe", null);
3097
- A(this, "styleElement");
3098
- A(this, "contentElement");
3094
+ $(this, "core", null);
3095
+ $(this, "shadow");
3096
+ $(this, "unsubscribe", null);
3097
+ $(this, "styleElement");
3098
+ $(this, "contentElement");
3099
3099
  // Popup state
3100
- A(this, "isComposing", !1);
3101
- A(this, "popupShaking", !1);
3100
+ $(this, "isComposing", !1);
3101
+ $(this, "popupShaking", !1);
3102
3102
  // Hover tracking
3103
- A(this, "mouseX", 0);
3104
- A(this, "mouseY", 0);
3105
- A(this, "hoveredMarkerId", null);
3103
+ $(this, "mouseX", 0);
3104
+ $(this, "mouseY", 0);
3105
+ $(this, "hoveredMarkerId", null);
3106
3106
  // Track if toolbar has been shown before (to prevent re-animation)
3107
- A(this, "toolbarShownOnce", !1);
3107
+ $(this, "toolbarShownOnce", !1);
3108
3108
  // Track if settings panel has animated (to prevent re-animation on state changes)
3109
- A(this, "settingsPanelAnimated", !1);
3109
+ $(this, "settingsPanelAnimated", !1);
3110
3110
  // Track which marker tooltip has animated (to prevent re-animation)
3111
- A(this, "animatedMarkerTooltipId", null);
3111
+ $(this, "animatedMarkerTooltipId", null);
3112
+ // Bound handlers for cleanup in disconnectedCallback
3113
+ $(this, "boundHandleResize", () => this.handleWindowResize());
3114
+ $(this, "boundHandleMouseMove", (e) => this.handleMouseMove(e));
3115
+ $(this, "boundHandleDocumentClick", (e) => this.handleDocumentClick(e));
3112
3116
  // Track last rendered settings to avoid unnecessary re-renders when settings panel is open
3113
- A(this, "lastRenderedSettings", null);
3117
+ $(this, "lastRenderedSettings", null);
3114
3118
  this.shadow = this.attachShadow({ mode: "open" }), this.styleElement = document.createElement("style"), this.styleElement.textContent = mn, this.contentElement = document.createElement("div"), this.contentElement.className = "annotation-root", this.shadow.appendChild(this.styleElement), this.shadow.appendChild(this.contentElement);
3115
3119
  }
3116
3120
  static get observedAttributes() {
@@ -3128,7 +3132,7 @@ class In extends HTMLElement {
3128
3132
  }), this.unsubscribe = this.core.subscribe((e) => this.render(e)), this.setupEventListeners(), this.render(this.core.store.getState()), this.updateThemeAttribute();
3129
3133
  }
3130
3134
  disconnectedCallback() {
3131
- this.unsubscribe && (this.unsubscribe(), this.unsubscribe = null), this.core && (this.core.destroy(), this.core = null);
3135
+ this.unsubscribe && (this.unsubscribe(), this.unsubscribe = null), window.removeEventListener("resize", this.boundHandleResize), document.removeEventListener("mousemove", this.boundHandleMouseMove), document.removeEventListener("click", this.boundHandleDocumentClick), this.core && (this.core.destroy(), this.core = null);
3132
3136
  }
3133
3137
  attributeChangedCallback(e, o, a) {
3134
3138
  if (!(o === a || !this.core))
@@ -3191,11 +3195,23 @@ class In extends HTMLElement {
3191
3195
  this.setAttribute("data-theme", e), e === "auto" && this.setAttribute("data-resolved-theme", o);
3192
3196
  }
3193
3197
  setupEventListeners() {
3194
- this.shadow.addEventListener("click", this.handleClick.bind(this)), this.shadow.addEventListener("mouseover", this.handleMouseOver.bind(this)), this.shadow.addEventListener("mouseout", this.handleMouseOut.bind(this)), document.addEventListener("mousemove", this.handleMouseMove.bind(this)), this.shadow.addEventListener("keydown", this.handleKeyDown.bind(this)), this.shadow.addEventListener("compositionstart", () => {
3198
+ this.shadow.addEventListener("click", this.handleClick.bind(this)), this.shadow.addEventListener("mouseover", this.handleMouseOver.bind(this)), this.shadow.addEventListener("mouseout", this.handleMouseOut.bind(this)), document.addEventListener("mousemove", this.boundHandleMouseMove), this.shadow.addEventListener("keydown", this.handleKeyDown.bind(this)), this.shadow.addEventListener("compositionstart", () => {
3195
3199
  this.isComposing = !0;
3196
3200
  }), this.shadow.addEventListener("compositionend", () => {
3197
- this.isComposing = !1;
3198
- }), this.shadow.addEventListener("change", this.handleChange.bind(this)), document.addEventListener("click", this.handleDocumentClick.bind(this));
3201
+ this.isComposing = !1, this.core && this.render(this.core.store.getState());
3202
+ }), this.shadow.addEventListener("change", this.handleChange.bind(this)), document.addEventListener("click", this.boundHandleDocumentClick), window.addEventListener("resize", this.boundHandleResize);
3203
+ }
3204
+ handleWindowResize() {
3205
+ if (!this.core) return;
3206
+ const e = this.core.store.getState();
3207
+ let o = !1;
3208
+ const a = new Map(e.scopes);
3209
+ for (const [s, r] of a) {
3210
+ if (!r.element || !r.element.isConnected) continue;
3211
+ const i = r.element.getBoundingClientRect(), d = i.left + i.width / 2, h = i.top + i.height / 2, u = d, p = r.elementInfo.isFixed ? h : h + window.scrollY;
3212
+ (u !== r.clickX || p !== r.clickY) && (a.set(s, { ...r, clickX: u, clickY: p }), o = !0);
3213
+ }
3214
+ o && this.core.store.setState({ scopes: a }), this.render(this.core.store.getState());
3199
3215
  }
3200
3216
  handleDocumentClick(e) {
3201
3217
  if (!this.core || !this.core.store.getState().settingsPanelVisible) return;
@@ -3332,6 +3348,8 @@ class In extends HTMLElement {
3332
3348
  }
3333
3349
  render(e) {
3334
3350
  const o = e.settings, a = Array.from(e.scopes.values()).sort((i, d) => i.number - d.number), s = G(o.theme);
3351
+ if (this.isComposing && e.popupVisible)
3352
+ return;
3335
3353
  if (e.settingsPanelVisible) {
3336
3354
  const i = JSON.stringify({
3337
3355
  settings: o,
@@ -3471,6 +3489,6 @@ export {
3471
3489
  f as l,
3472
3490
  Wn as r,
3473
3491
  x as t,
3474
- Re as z
3492
+ Ye as z
3475
3493
  };
3476
- //# sourceMappingURL=annotation-element-CJm7-qrT.js.map
3494
+ //# sourceMappingURL=annotation-element-z6TdBGsn.js.map