@pennsieve-viz/tsviewer 1.0.3 → 1.0.31

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 (41) hide show
  1. package/dist/{BFLibraryButton-BIHTpeNO.cjs → BFLibraryButton-CnSdxNr1.cjs} +1 -1
  2. package/dist/{BFLibraryButton-cj0cYcEU.js → BFLibraryButton-Dec5fit3.js} +14 -14
  3. package/dist/{IconSelection-DPzESQva.js → IconSelection-C_zQHxVs.js} +3 -3
  4. package/dist/{IconSelection-Clsng0MV.cjs → IconSelection-CxtyAEya.cjs} +1 -1
  5. package/dist/TSAnnotationCanvas-BuYjJ340.cjs +1 -0
  6. package/dist/TSAnnotationCanvas-DV93mqhV.js +778 -0
  7. package/dist/{TSAnnotationModal-D36kPDem.cjs → TSAnnotationModal-Bvz6Hr6c.cjs} +1 -1
  8. package/dist/{TSAnnotationModal-QTRsd7x7.js → TSAnnotationModal-Crb5zX1P.js} +13 -13
  9. package/dist/{TSFilterModal-PeYsMpbr.cjs → TSFilterModal-BA7WXDk1.cjs} +1 -1
  10. package/dist/{TSFilterModal-Dpohnnn3.js → TSFilterModal-DdNCo0nH.js} +8 -8
  11. package/dist/{TSScrubber-C99OFl1F.js → TSScrubber-BsoGLy_L.js} +3 -3
  12. package/dist/{TSScrubber-CIfQ9P9Q.cjs → TSScrubber-KnkoGu88.cjs} +1 -1
  13. package/dist/{TSViewerCanvas-B2JwW053.js → TSViewerCanvas-ByhDLibl.js} +11 -11
  14. package/dist/{TSViewerCanvas-D7w29Dvz.cjs → TSViewerCanvas-D_i1FrqG.cjs} +2 -2
  15. package/dist/{TSViewerLayerWindow-DkDO3dZb.cjs → TSViewerLayerWindow-4ckQFmUZ.cjs} +1 -1
  16. package/dist/{TSViewerLayerWindow-BsV_pDGS.js → TSViewerLayerWindow-Cf4J_lK_.js} +6 -6
  17. package/dist/{TSViewerToolbar-Rsz0-ujg.cjs → TSViewerToolbar-BLOSD8fd.cjs} +1 -1
  18. package/dist/{TSViewerToolbar-DoSJEPgd.js → TSViewerToolbar-BxAiyYi7.js} +13 -13
  19. package/dist/{TsAnnotationDeleteDialog-GSMBqEkE.cjs → TsAnnotationDeleteDialog-B_ZIUOh2.cjs} +1 -1
  20. package/dist/{TsAnnotationDeleteDialog-NGmIj7Nr.js → TsAnnotationDeleteDialog-Dm0rbNQr.js} +6 -6
  21. package/dist/{base-CEBDkSsZ.cjs → base-BQSnEcNP.cjs} +1 -1
  22. package/dist/{base-B8HYDRlA.js → base-VCnLhxie.js} +9 -9
  23. package/dist/el-input-CwVmeiqs.cjs +1 -0
  24. package/dist/{el-input-v5gK8U8C.js → el-input-DQtvBLS6.js} +1664 -1676
  25. package/dist/{el-input-number-F_eDnZFO.cjs → el-input-number-Cxwc3-EL.cjs} +1 -1
  26. package/dist/{el-input-number-DSVzNAfT.js → el-input-number-DXCID3jJ.js} +6 -6
  27. package/dist/{el-overlay-4ljdPakB.js → el-overlay-BMUWCEw_.js} +14 -14
  28. package/dist/{el-overlay-DFtIA0N9.cjs → el-overlay-D192MFpl.cjs} +1 -1
  29. package/dist/{index-BJOVbX31.js → index-BAtTJnp_.js} +1 -1
  30. package/dist/{index-DmPnHGWj.js → index-C3ilckwx.js} +28 -27
  31. package/dist/{index-B7L4A5WQ.cjs → index-D8lvFC22.cjs} +1 -1
  32. package/dist/{index-2QS1iKBu.cjs → index-TDc5sP-n.cjs} +1 -1
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.js +1 -1
  35. package/dist/{pathOr-Bcyi9PI-.js → pathOr-CC_5pAvC.js} +2 -2
  36. package/dist/{pathOr-CaQF9BY-.cjs → pathOr-D8CyYHmd.cjs} +1 -1
  37. package/dist/style.css +1 -1
  38. package/package.json +1 -1
  39. package/dist/TSAnnotationCanvas-CXAko3Ju.cjs +0 -1
  40. package/dist/TSAnnotationCanvas-Cx8ea7Mz.js +0 -730
  41. package/dist/el-input-DFAVTpkr.cjs +0 -1
@@ -0,0 +1,778 @@
1
+ import { ref as I, computed as x, watch as ee, onMounted as ce, createElementBlock as ue, openBlock as de, normalizeStyle as fe, unref as te, nextTick as ve } from "vue";
2
+ import { o as he, m as ge, u as W, p as J, h as H, j as B, i as _, g as ye } from "./index-C3ilckwx.js";
3
+ import { storeToRefs as le } from "pinia";
4
+ import { f as me, h as we } from "./TSViewerCanvas-ByhDLibl.js";
5
+ import { p as K } from "./pathOr-CC_5pAvC.js";
6
+ import { g as Te } from "./_commonjsHelpers-DaMA6jEr.js";
7
+ const N = (t, u) => {
8
+ let l;
9
+ if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(t))
10
+ return l = t.substring(1).split(""), l.length === 3 && (l = [l[0], l[0], l[1], l[1], l[2], l[2]]), l = "0x" + l.join(""), "rgba(" + [l >> 16 & 255, l >> 8 & 255, l & 255].join(",") + "," + u + ")";
11
+ throw new Error("Bad Hex");
12
+ }, pe = (t) => {
13
+ t.sort((u, l) => u.start < l.start ? -1 : u.start > l.start ? 1 : 0);
14
+ }, ne = (t, u) => {
15
+ const l = (t == null ? void 0 : t.layer_id) || 0;
16
+ return he({}, me(ge("id", l), u));
17
+ }, oe = (t, u, l, n = 0, c = !1) => {
18
+ let h;
19
+ return c ? h = Y(t, u, n, t.length - 1, l) : h = Q(t, u, n, t.length - 1, l), h === -1 ? h = 0 : h < 0 && (h = -h - 2), h;
20
+ }, Q = (t, u, l, n, c) => {
21
+ if (n < l) {
22
+ let w = n >= 0 ? n : -n - 2;
23
+ if (w === -1) return w;
24
+ const p = t[w].start;
25
+ for (; w >= 0 && t[w].start === p; )
26
+ w--;
27
+ return -w - 2;
28
+ }
29
+ const h = parseInt((l + n) / 2);
30
+ if (t[h].start > u)
31
+ return Q(t, u, l, h - 1, c);
32
+ if (t[h].start < u)
33
+ return Q(t, u, h + 1, n, c);
34
+ {
35
+ let w = h;
36
+ if (c) {
37
+ for (; w >= 0 && t[w].start === u; )
38
+ w--;
39
+ w++;
40
+ } else {
41
+ for (; w < t.length && t[w].start === u; )
42
+ w++;
43
+ w--;
44
+ }
45
+ return w;
46
+ }
47
+ }, Y = (t, u, l, n, c) => {
48
+ if (n < l) {
49
+ let p = n >= 0 ? n : -n - 2;
50
+ if (p === -1) return p;
51
+ const M = t[p].start + t[p].duration;
52
+ for (; p >= 0 && t[p].start + t[p].duration === M; )
53
+ p--;
54
+ return -p - 2;
55
+ }
56
+ const h = parseInt((l + n) / 2), w = t[h].start + t[h].duration;
57
+ if (w > u)
58
+ return Y(t, u, l, h - 1, c);
59
+ if (w < u)
60
+ return Y(t, u, h + 1, n, c);
61
+ {
62
+ let p = h;
63
+ if (c) {
64
+ for (; p >= 0 && t[p].start + t[p].duration === u; )
65
+ p--;
66
+ p++;
67
+ } else {
68
+ for (; p < t.length && t[p].start + t[p].duration === u; )
69
+ p++;
70
+ p--;
71
+ }
72
+ return p;
73
+ }
74
+ }, ae = (t, u, l = 0) => u * (t + l);
75
+ function Le() {
76
+ const t = W(), { viewerChannels: u, viewerAnnotations: l, viewerMontageScheme: n } = le(t), c = I([]), h = I([]), w = (m) => {
77
+ const f = n.value !== "NOT_MONTAGED";
78
+ let e = J("", "id", m);
79
+ if (f) {
80
+ const o = e.split("_");
81
+ e = o.length ? we(o) : e;
82
+ }
83
+ return e;
84
+ }, p = async (m, f, e, o, d) => {
85
+ var s, v;
86
+ if (!((s = o == null ? void 0 : o.content) != null && s.id)) {
87
+ console.warn("[useAnnotationData] checkAnnotationRange called with invalid activeViewer, skipping");
88
+ return;
89
+ }
90
+ if (!((v = t.config) != null && v.apiUrl)) {
91
+ console.warn("[useAnnotationData] checkAnnotationRange called without apiUrl config, skipping");
92
+ return;
93
+ }
94
+ if (typeof m != "number" || typeof e.tsEnd != "number") {
95
+ console.warn("[useAnnotationData] checkAnnotationRange called with invalid time range, skipping");
96
+ return;
97
+ }
98
+ const a = [];
99
+ a.push({ start: m, end: e.tsEnd });
100
+ let i = 0;
101
+ for (let r = 0; r < c.value.length; r++) {
102
+ const y = c.value[r];
103
+ if (m >= y.start && f <= y.end)
104
+ return;
105
+ if (a[0].start > f)
106
+ break;
107
+ if (y.start <= a[0].start && y.end >= m)
108
+ i = r + 1, a[0].start = y.end;
109
+ else if (y.start > a[0].start) {
110
+ i = r;
111
+ break;
112
+ }
113
+ }
114
+ const g = l.value.reduce((r, y) => r + y.annotations.length, 0);
115
+ if (a[0].start >= a[0].end && g > 0)
116
+ return;
117
+ const T = 0;
118
+ for (let r = i; r < c.value.length; r++)
119
+ if (c.value[r].start >= a[T].start)
120
+ if (a[T].end = c.value[r].start, c.value[r].end < f)
121
+ a.push({ start: c.value[r].end, end: e.tsEnd });
122
+ else
123
+ break;
124
+ if (!(a[0].start >= a[0].end && g > 0) && a.length > 0) {
125
+ u.value.map((r) => w(r));
126
+ for (const r of a) {
127
+ for (const y of l.value) {
128
+ if (!y.id) {
129
+ console.warn("Layer ID is undefined, skipping annotation request for layer:", y);
130
+ continue;
131
+ }
132
+ const k = Math.floor(r.end), C = {
133
+ id: o.content.id,
134
+ start: Math.floor(r.start),
135
+ end: k,
136
+ layerId: y.id,
137
+ limit: e.constants.LIMITANNFETCH
138
+ };
139
+ try {
140
+ const O = await H(), S = `${t.config.apiUrl}/timeseries/${o.content.id}/layers/${y.id}/annotations?api_key=${O}`, F = Object.keys(C).map((P) => `&${P}=${C[P]}`).join(""), R = `${S}${F}`, $ = await fetch(R, {
141
+ method: "GET",
142
+ headers: { "Content-type": "application/json" }
143
+ });
144
+ if ($.status >= 400)
145
+ throw new Error($.status);
146
+ const G = await $.json();
147
+ await M(G, d);
148
+ } catch (O) {
149
+ B(O);
150
+ }
151
+ }
152
+ c.value.push({
153
+ start: Math.floor(r.start),
154
+ end: Math.floor(r.end)
155
+ });
156
+ }
157
+ c.value.sort((r, y) => r.start < y.start ? -1 : r.start > y.start ? 1 : 0);
158
+ }
159
+ }, M = async (m, f) => {
160
+ const e = J({}, "linkedPackages", m);
161
+ let o = K([], ["annotations", "results"], m);
162
+ if (o.length >= 500) {
163
+ let a = 0;
164
+ for (const i of o)
165
+ i.start > a && (a = i.start);
166
+ for (const i of c.value)
167
+ if (i.end > a && i.start < a) {
168
+ i.end = a;
169
+ break;
170
+ }
171
+ }
172
+ const d = n.value !== "NOT_MONTAGED";
173
+ if (o.length > 0) {
174
+ const a = o.map((i) => {
175
+ const g = {
176
+ name: "",
177
+ id: i.id,
178
+ label: i.label,
179
+ description: i.description,
180
+ start: i.start,
181
+ duration: i.end - i.start,
182
+ end: i.end,
183
+ cStart: null,
184
+ cEnd: null,
185
+ selected: !1,
186
+ channelIds: i.channelIds,
187
+ allChannels: !1,
188
+ layer_id: i.layerId,
189
+ userId: i.userId
190
+ };
191
+ if (i.linkedPackage) {
192
+ const T = i.linkedPackage;
193
+ g.linkedPackage = K("", ["content", "id"], e[T]), g.linkedPackageDTO = e[T];
194
+ }
195
+ return (!d && g.channelIds.length === u.value.length || d && g.channelIds.length > u.value.length) && (g.allChannels = !0), g;
196
+ });
197
+ l.value.forEach((i) => {
198
+ const g = i.annotations, T = a.filter((s) => i.id === s.layer_id);
199
+ i.annotations = g.concat(T), t.updateLayer(i);
200
+ });
201
+ }
202
+ f("annotationsReceived");
203
+ };
204
+ return {
205
+ cachedAnnRange: c,
206
+ annLayerInfo: h,
207
+ checkAnnotationRange: p,
208
+ findNextAnnotation: (m) => {
209
+ const f = t.getViewerActiveLayer(), e = oe(f.annotations, m, !1);
210
+ return e < f.annotations.length ? f.annotations[e].start > m ? f.annotations[e] : f.annotations[e + 1] || f.annotations[e] : f.annotations[e];
211
+ },
212
+ findPreviousAnnotation: (m) => {
213
+ const f = t.getViewerActiveLayer(), e = oe(f.annotations, m, !0);
214
+ return f.annotations[e].start < m ? f.annotations[e] : e > 0 ? f.annotations[e - 1] : f.annotations[e];
215
+ },
216
+ getChannelId: w
217
+ };
218
+ }
219
+ function ke() {
220
+ const t = W(), { viewerAnnotations: u, viewerChannels: l } = le(t), n = I([]), c = I([]), h = I(null), w = I(["#FFFF4E"]), p = (e, o) => {
221
+ var g, T;
222
+ const a = (((g = o.constants) == null ? void 0 : g.ANNOTATIONLABELHEIGHT) || 20) / 2 | 0, i = ((T = o.constants) == null ? void 0 : T.XOFFSET) || 0;
223
+ for (const s of e) {
224
+ let v = s.start, r = s.duration;
225
+ s.duration < 0 && (v = s.start + s.duration, r = -s.duration);
226
+ const y = i + (v - o.start) / o.rsPeriod;
227
+ if (s.cStart = y | 0, s.duration !== 0) {
228
+ const k = i + (v + r - o.start) / o.rsPeriod;
229
+ s.cEnd = k | 0;
230
+ } else
231
+ s.cEnd = s.cStart + o.cWidth / 40 | 0;
232
+ if (s.allChannels)
233
+ s.allOffsets = [a], s.cY = a;
234
+ else {
235
+ s.allOffsets = [], s.minOffset = o.cHeight | 0, s.maxOffset = 0;
236
+ const k = l.value;
237
+ for (const C of s.channelIds) {
238
+ let O = null;
239
+ for (const b of k)
240
+ if (b.id === C && b.visible) {
241
+ O = b.rowBaseline | 0, O < s.minOffset && (s.minOffset = O), O > s.maxOffset && (s.maxOffset = O), s.allOffsets.push(O);
242
+ break;
243
+ }
244
+ }
245
+ c.value.indexOf(s.minOffset) < 0 && c.value.push(s.minOffset), s.cY = s.minOffset;
246
+ }
247
+ }
248
+ }, M = (e, o, d, a) => {
249
+ var T, s;
250
+ const i = ((T = d.constants) == null ? void 0 : T.ANNOTATIONLABELHEIGHT) || 20, g = i / 2 | 0;
251
+ e.setTransform(d.pixelRatio, 0, 0, d.pixelRatio, 0, 0), e.save(), e.lineWidth = 1, e.setLineDash([8, 5]), e.strokeStyle = "rgba(0,0,0, 0.6)", e.fillStyle = "rgba(0,0,0,0.05)";
252
+ for (const v of o) {
253
+ const r = ne(v, u.value);
254
+ v.selected && (e.save(), e.strokeStyle = r.selColor, e.fillStyle = r.bkColor, e.lineWidth = 1);
255
+ const y = Math.round(v.cStart) + 0.5, k = Math.round(v.cEnd) + 0.5;
256
+ v.allChannels ? v.duration === 0 ? (e.beginPath(), e.moveTo(y + 1, i), e.lineTo(y, a), e.stroke()) : (e.fillRect(y, i, k - y, a - i), e.beginPath(), e.moveTo(y, i), e.lineTo(y, a), e.moveTo(k, i), e.lineTo(k, a), e.stroke()) : ((s = v == null ? void 0 : v.channelIds) == null ? void 0 : s.length) === 1 ? v.duration === 0 && (e.beginPath(), e.moveTo(y, v.minOffset + g), e.lineTo(y, v.minOffset + g + 8), e.stroke()) : v.duration === 0 ? (e.beginPath(), e.moveTo(y, v.minOffset + g), e.lineTo(y, v.maxOffset - g), e.stroke()) : (e.fillRect(
257
+ y - 1,
258
+ v.minOffset + g,
259
+ k - y + 1,
260
+ v.maxOffset - v.minOffset - i
261
+ ), e.beginPath(), e.moveTo(y, v.minOffset + g), e.lineTo(y, v.maxOffset - g), e.moveTo(k, v.minOffset + g), e.lineTo(k, v.maxOffset - g), e.stroke()), v.selected && e.restore();
262
+ }
263
+ e.restore();
264
+ }, D = async (e, o, d, a, i, g) => {
265
+ var v;
266
+ const T = ((v = d.constants) == null ? void 0 : v.ANNOTATIONLABELHEIGHT) || 20, s = T / 2 | 0;
267
+ e.setTransform(d.pixelRatio, 0, 0, d.pixelRatio, 0, 0), e.save(), e.lineWidth = 2, e.font = "14px sans-serif", e.textAlign = "left";
268
+ for (const r of o) {
269
+ const y = ne(r, u.value);
270
+ if (r === h.value && a)
271
+ continue;
272
+ r.selected ? (e.fillStyle = y.selColor || "rgba(51,204,102, 0.8)", e.strokeStyle = "white") : (e.fillStyle = y.color || "rgba(51,204,102,0.8)", e.strokeStyle = r === h.value ? "white" : "rgba(255,255,255,0.8)");
273
+ const k = Math.round(r.cStart) + 1, C = Math.round(r.cEnd);
274
+ let O = 0;
275
+ for (let F = 0; F < r.allOffsets.length; F++)
276
+ e.fillRect(
277
+ k - 1,
278
+ r.allOffsets[F] - s,
279
+ C - k + 2,
280
+ T
281
+ ), r.allOffsets[F] === r.minOffset && (O = F);
282
+ const b = r.allOffsets[O];
283
+ if (["annSelect", "annResize-left", "annResize-right"].includes(i) && g === "annotate" && (e.beginPath(), r.duration !== 0 && (e.moveTo(C - 3, b - s + 3), e.lineTo(C - 3, b + s - 3)), e.moveTo(k + 3, b - s + 3), e.lineTo(k + 3, b + s - 3), e.stroke()), C - k > r.label.length * 8 + 10) {
284
+ e.fillStyle = w.value.indexOf(y.hexColor) >= 0 ? "black" : "white";
285
+ const F = r.linkedPackage ? k + 30 : k + 10, R = r.linkedPackage ? b + s - s / 2 : b + s - 6;
286
+ e.fillText(r.label, F, R);
287
+ }
288
+ const S = r.linkedPackageDTO;
289
+ S && C - k >= 30 && await L(e, S, k, b, s, T);
290
+ }
291
+ e.restore();
292
+ }, L = async (e, o, d, a, i, g) => {
293
+ const T = K({}, ["objects", "view", 1, "content"], o), s = J("", "fileType", T), v = new Image();
294
+ if (s === "PNG") {
295
+ const { id: r, packageId: y } = T, k = t.config.apiUrl;
296
+ try {
297
+ const C = await H();
298
+ v.src = `${k}/packages/${y}/files/${r}/presign/?api_key=${C}`, v.complete ? e.drawImage(v, d, a - i, 27, g) : v.addEventListener("load", () => {
299
+ e.drawImage(v, d, a - i, 27, g);
300
+ }, { once: !0 });
301
+ } catch (C) {
302
+ console.error("Error loading image:", C);
303
+ }
304
+ } else
305
+ v.src = m(), e.drawImage(v, d + 5, a - i, 20, 20);
306
+ }, m = (e) => "/path/to/default/icon.png";
307
+ return {
308
+ renderAnn: n,
309
+ hoverOffsets: c,
310
+ focusedAnn: h,
311
+ render: (e, o, d, a) => {
312
+ var r, y, k, C;
313
+ if (!o) {
314
+ console.warn("TSAnnotationCanvas: annotationsCanvas prop is undefined or null");
315
+ return;
316
+ }
317
+ const i = o.getContext("2d"), g = d.getContext("2d");
318
+ i.setTransform(e.pixelRatio, 0, 0, e.pixelRatio, 0, 0), g.setTransform(e.pixelRatio, 0, 0, e.pixelRatio, 0, 0), c.value = [(((r = e.constants) == null ? void 0 : r.ANNOTATIONLABELHEIGHT) || 20) / 2], i.clearRect(0, 0, e.cWidth, e.cHeight), g.clearRect(0, 0, e.cWidth, e.cHeight), n.value = [];
319
+ const T = e.duration && e.duration > 0 ? e.duration : 15e6, s = e.start || 0, v = s + T;
320
+ console.log("🎨 Annotation render debug:", {
321
+ start: s,
322
+ duration: T,
323
+ end: v,
324
+ layerCount: ((y = u.value) == null ? void 0 : y.length) || 0,
325
+ totalAnnotations: ((k = u.value) == null ? void 0 : k.reduce((O, b) => {
326
+ var S;
327
+ return O + (((S = b.annotations) == null ? void 0 : S.length) || 0);
328
+ }, 0)) || 0
329
+ });
330
+ for (const O of u.value)
331
+ if (O.visible && ((C = O.annotations) == null ? void 0 : C.length) > 0) {
332
+ console.log(`🔍 Processing layer "${O.name}" with ${O.annotations.length} annotations`);
333
+ const b = O.annotations.filter((S) => {
334
+ const F = S.start, R = S.end || S.start + (S.duration || 0), $ = F < v && R > s;
335
+ return $ && console.log(` ✅ Including annotation "${S.label}": ${F} - ${R}`), $;
336
+ });
337
+ console.log(` 📊 Found ${b.length} annotations in viewport`), b.length > 0 && (b.sort((S, F) => S.start - F.start), n.value.push(...b));
338
+ }
339
+ if (console.log(`🎯 Total annotations to render: ${n.value.length}`), n.value.length === 0) {
340
+ console.log("⚠️ No annotations found in viewport");
341
+ return;
342
+ }
343
+ pe(n.value), p(n.value, e), M(i, n.value, e, a), D(g, n.value, e, !0, e.pointerMode, e.viewerActiveTool), h.value && D(g, [h.value], e, !1, e.pointerMode, e.viewerActiveTool), console.log(`✅ Rendered ${n.value.length} annotations successfully`);
344
+ },
345
+ computeRenderOptions: p,
346
+ renderAnnotationAreas: M,
347
+ renderAnnotationLabels: D
348
+ };
349
+ }
350
+ function Ee(t, u, l) {
351
+ const n = W(), c = I([0, 0]), h = (e, o) => {
352
+ const a = ((o == null ? void 0 : o.ANNOTATIONLABELHEIGHT) || 20) / 2;
353
+ for (const i of l.value)
354
+ if (e >= i - a && e <= i + a)
355
+ return !0;
356
+ return !1;
357
+ }, w = (e, o, d) => {
358
+ var g;
359
+ const i = ((d == null ? void 0 : d.ANNOTATIONLABELHEIGHT) || 20) / 2;
360
+ for (let T = 0; T < (((g = u.value) == null ? void 0 : g.length) || 0); T++) {
361
+ const s = u.value[T];
362
+ if (s.cStart < e && s.cEnd > e) {
363
+ if (o > s.cY - i && o < s.cY + i)
364
+ return T;
365
+ } else if (s.cStart > e)
366
+ break;
367
+ }
368
+ return null;
369
+ }, p = (e, o, d) => {
370
+ if (!d) return o;
371
+ switch (o) {
372
+ case "annotate":
373
+ return e <= d.cStart + 10 ? "annResize-left" : e >= d.cEnd - 10 && d.duration > 0 ? "annResize-right" : "annSelect";
374
+ case "pointer":
375
+ return "annSelect";
376
+ default:
377
+ return o;
378
+ }
379
+ };
380
+ return {
381
+ mouseDownPosition: c,
382
+ shouldCheckAnnotationHover: h,
383
+ findAnnotationAtPosition: w,
384
+ determinePointerMode: p,
385
+ resetFocusedAnnotation: () => {
386
+ var e;
387
+ ((e = t.value) == null ? void 0 : e.oldStart) !== void 0 && (t.value.start = t.value.oldStart, t.value.duration = t.value.oldDuration, t.value.end = t.value.start + t.value.duration);
388
+ },
389
+ selectFocusedAnnotation: () => t.value ? (n.setActiveAnnotation(t.value), !0) : !1,
390
+ onMouseDown: (e, o, d) => {
391
+ t.value && ["annResize-left", "annResize-right"].includes(d) && (t.value.oldStart = t.value.start, t.value.oldDuration = t.value.duration, c.value = [e, o]);
392
+ },
393
+ onMouseMove: (e, o, d, a, i) => {
394
+ let g = d;
395
+ if (a && c.value) {
396
+ const T = (e - c.value[0]) * i.rsPeriod;
397
+ switch (d) {
398
+ case "annResize-left":
399
+ t.value.oldDuration > 0 ? (t.value.start = t.value.oldStart + T, t.value.duration = t.value.oldDuration - T, t.value.end = t.value.start + t.value.duration) : t.value.start = t.value.oldStart + T;
400
+ break;
401
+ case "annResize-right":
402
+ t.value.duration = t.value.oldDuration + T, t.value.end = t.value.start + t.value.duration;
403
+ break;
404
+ }
405
+ } else {
406
+ const T = h(o, i.constants);
407
+ if (g = i.viewerActiveTool, T) {
408
+ const s = w(e, o, i.constants);
409
+ if (s !== null) {
410
+ const v = t.value, r = u.value[s];
411
+ (!v || e < t.value.cStart || e > t.value.cEnd) && (t.value = r), g = p(e, i.viewerActiveTool, t.value);
412
+ } else
413
+ t.value = null;
414
+ } else
415
+ t.value = null, g = i.viewerActiveTool;
416
+ }
417
+ return g;
418
+ },
419
+ onMouseUp: (e, o) => {
420
+ if (t.value && ["annResize-left", "annResize-right"].includes(e)) {
421
+ if (t.value.duration < 0) {
422
+ const d = -t.value.duration, a = t.value.start - d;
423
+ t.value.start = a, t.value.duration = d, t.value.end = a + d;
424
+ }
425
+ n.setActiveAnnotation(t.value), o("updateAnnotation", t.value);
426
+ }
427
+ }
428
+ };
429
+ }
430
+ var z = { exports: {} }, ie;
431
+ function Ae() {
432
+ if (ie) return z.exports;
433
+ ie = 1;
434
+ function t() {
435
+ }
436
+ return t.prototype = {
437
+ on: function(u, l, n) {
438
+ var c = this.e || (this.e = {});
439
+ return (c[u] || (c[u] = [])).push({
440
+ fn: l,
441
+ ctx: n
442
+ }), this;
443
+ },
444
+ once: function(u, l, n) {
445
+ var c = this;
446
+ function h() {
447
+ c.off(u, h), l.apply(n, arguments);
448
+ }
449
+ return h._ = l, this.on(u, h, n);
450
+ },
451
+ emit: function(u) {
452
+ var l = [].slice.call(arguments, 1), n = ((this.e || (this.e = {}))[u] || []).slice(), c = 0, h = n.length;
453
+ for (c; c < h; c++)
454
+ n[c].fn.apply(n[c].ctx, l);
455
+ return this;
456
+ },
457
+ off: function(u, l) {
458
+ var n = this.e || (this.e = {}), c = n[u], h = [];
459
+ if (c && l)
460
+ for (var w = 0, p = c.length; w < p; w++)
461
+ c[w].fn !== l && c[w].fn._ !== l && h.push(c[w]);
462
+ return h.length ? n[u] = h : delete n[u], this;
463
+ }
464
+ }, z.exports = t, z.exports.TinyEmitter = t, z.exports;
465
+ }
466
+ var q, se;
467
+ function Oe() {
468
+ if (se) return q;
469
+ se = 1;
470
+ var t = Ae();
471
+ return q = new t(), q;
472
+ }
473
+ var be = Oe();
474
+ const j = /* @__PURE__ */ Te(be), re = {
475
+ $emit: (...t) => j.emit(...t),
476
+ $on: (...t) => j.on(...t),
477
+ $off: (...t) => j.off(...t),
478
+ $once: (...t) => j.once(...t)
479
+ };
480
+ function Ce() {
481
+ const t = W(), u = I([]), l = I([
482
+ "#18BA62",
483
+ "#FFBC27",
484
+ "#E94B4B",
485
+ "#0D4EFF",
486
+ "#FF4FFF",
487
+ "#50FFFF",
488
+ "#FFFF4E",
489
+ "#512BAF",
490
+ "#8A6ECF",
491
+ "#389BAD",
492
+ "#187D46",
493
+ "#B12800",
494
+ "#0C2475",
495
+ "#FF5321",
496
+ "#FF99CC",
497
+ "#DCC180",
498
+ "#FF6C21",
499
+ "#000000",
500
+ "#9B9B9B",
501
+ "#00FF00",
502
+ "#FA8072",
503
+ "#808000",
504
+ "#A0522D",
505
+ "#2760FF"
506
+ ]), n = async (L, m) => {
507
+ const f = [];
508
+ if (L.results.length === 0)
509
+ await c({
510
+ name: "Default",
511
+ color: "#18BA62",
512
+ description: "Default Annotation Layer"
513
+ }, null, m);
514
+ else {
515
+ for (let e = 0; e < L.results.length; e++) {
516
+ const o = L.results[e];
517
+ let d = o.color || l.value[e % l.value.length];
518
+ const a = {
519
+ id: o.id,
520
+ name: o.name,
521
+ description: o.description,
522
+ visible: !0,
523
+ selected: e === 0,
524
+ // First layer is selected by default
525
+ annotations: [],
526
+ color: N(d, 0.7),
527
+ hexColor: d,
528
+ bkColor: N(d, 0.15),
529
+ selColor: N(d, 0.9)
530
+ };
531
+ f.push(a);
532
+ }
533
+ t.setAnnotations(f), m("annLayersInitialized");
534
+ }
535
+ u.value = L.results;
536
+ }, c = async (L, m, f) => {
537
+ try {
538
+ const e = await H(), o = `${t.config.apiUrl}/timeseries/${m.content.id}/layers?api_key=${e}`, d = await _(o, {
539
+ method: "POST",
540
+ body: {
541
+ name: L.name,
542
+ color: L.color,
543
+ description: L.description || L.name
544
+ }
545
+ }), a = {
546
+ ...d,
547
+ annotations: [],
548
+ hexColor: d.color,
549
+ color: N(d.color, 0.7),
550
+ bkColor: N(d.color, 0.15),
551
+ selColor: N(d.color, 0.9),
552
+ visible: !0,
553
+ selected: !0
554
+ };
555
+ return t.createLayer(a), t.setActiveAnnotationLayer(a.id), re.$emit("toast", {
556
+ detail: {
557
+ msg: `'${a.name}' Layer Created`
558
+ }
559
+ }), a;
560
+ } catch (e) {
561
+ throw B(e), e;
562
+ } finally {
563
+ f && f("closeAnnotationLayerWindow");
564
+ }
565
+ };
566
+ return {
567
+ annLayerInfo: u,
568
+ defaultColors: l,
569
+ initializeLayers: n,
570
+ createAnnotationLayer: c,
571
+ updateLayerVisibility: (L, m) => {
572
+ console.log(`[useAnnotationLayers] Updating layer ${L} visibility to:`, m);
573
+ const f = t.viewerAnnotations.find((e) => e.id === L);
574
+ if (f) {
575
+ console.log("[useAnnotationLayers] Found layer:", f.name, "current visible:", f.visible), f.visible = m, t.updateLayer(f), console.log("[useAnnotationLayers] Updated layer:", f.name, "new visible:", f.visible);
576
+ const e = t.viewerAnnotations.find((o) => o.id === L);
577
+ console.log("[useAnnotationLayers] Verification - layer visible is now:", e == null ? void 0 : e.visible);
578
+ } else
579
+ console.error("[useAnnotationLayers] Layer not found with ID:", L), console.log("[useAnnotationLayers] Available layers:", t.viewerAnnotations.map((e) => ({ id: e.id, name: e.name })));
580
+ },
581
+ selectLayer: (L) => {
582
+ t.viewerAnnotations.forEach((f) => {
583
+ f.selected = !1, t.updateLayer(f);
584
+ });
585
+ const m = t.viewerAnnotations.find((f) => f.id === L);
586
+ m && (m.selected = !0, t.updateLayer(m), t.setActiveAnnotationLayer(L));
587
+ },
588
+ deleteLayer: async (L, m) => {
589
+ try {
590
+ const f = await H(), e = `${t.config.apiUrl}/timeseries/${m.content.id}/layers/${L}?api_key=${f}`;
591
+ await _(e, { method: "DELETE" }), t.removeLayer(L), re.$emit("toast", {
592
+ detail: {
593
+ msg: "Layer deleted successfully"
594
+ }
595
+ });
596
+ } catch (f) {
597
+ throw B(f), f;
598
+ }
599
+ },
600
+ updateLayerColor: async (L, m, f) => {
601
+ try {
602
+ const e = await H(), o = `${t.config.apiUrl}/timeseries/${f.content.id}/layers/${L}?api_key=${e}`, d = await _(o, {
603
+ method: "PUT",
604
+ body: { color: m }
605
+ }), a = t.viewerAnnotations.find((i) => i.id === L);
606
+ return a && (a.hexColor = m, a.color = N(m, 0.7), a.bkColor = N(m, 0.15), a.selColor = N(m, 0.9), t.updateLayer(a)), d;
607
+ } catch (e) {
608
+ throw B(e), e;
609
+ }
610
+ },
611
+ loadLayers: async (L, m) => {
612
+ var f, e;
613
+ if (!((f = L == null ? void 0 : L.content) != null && f.id))
614
+ return console.warn("[useAnnotationLayers] loadLayers called with invalid activeViewer, skipping"), null;
615
+ if (!((e = t.config) != null && e.apiUrl))
616
+ return console.warn("[useAnnotationLayers] loadLayers called without apiUrl config, skipping"), null;
617
+ try {
618
+ const o = await H(), d = `${t.config.apiUrl}/timeseries/${L.content.id}/layers?api_key=${o}`, a = await _(d);
619
+ return await n(a, m), a;
620
+ } catch (o) {
621
+ throw B(o), o;
622
+ }
623
+ }
624
+ };
625
+ }
626
+ const Se = ["width", "height"], Fe = {
627
+ __name: "TSAnnotationCanvas",
628
+ props: {
629
+ cWidth: { type: Number, default: 0 },
630
+ cHeight: Number,
631
+ start: Number,
632
+ duration: Number,
633
+ tsEnd: Number,
634
+ rsPeriod: Number,
635
+ pixelRatio: Number,
636
+ constants: {
637
+ type: Object,
638
+ default: () => ({
639
+ ANNOTATIONLABELHEIGHT: 20,
640
+ XOFFSET: 0,
641
+ LIMITANNFETCH: 500
642
+ })
643
+ },
644
+ pointerMode: String,
645
+ annotationsCanvas: [HTMLCanvasElement, Object],
646
+ activeViewer: { type: Object, required: !0 },
647
+ viewerActiveTool: String
648
+ },
649
+ emits: [
650
+ "annLayersInitialized",
651
+ "annotationsReceived",
652
+ "closeAnnotationLayerWindow",
653
+ "updateAnnotation"
654
+ ],
655
+ setup(t, { expose: u, emit: l }) {
656
+ const n = t, c = l, h = I(null), {
657
+ checkAnnotationRange: w,
658
+ findNextAnnotation: p,
659
+ findPreviousAnnotation: M
660
+ } = Le(), {
661
+ renderAnn: D,
662
+ hoverOffsets: L,
663
+ focusedAnn: m,
664
+ render: f
665
+ } = ke(), {
666
+ resetFocusedAnnotation: e,
667
+ selectFocusedAnnotation: o,
668
+ onMouseDown: d,
669
+ onMouseMove: a,
670
+ onMouseUp: i
671
+ } = Ee(m, D, L), {
672
+ createAnnotationLayer: g,
673
+ loadLayers: T
674
+ } = Ce(), s = x(() => n.cHeight - 20), v = x(() => ({
675
+ width: n.cWidth + "px",
676
+ height: s.value + "px"
677
+ })), r = () => {
678
+ f(n, n.annotationsCanvas, h.value, s.value);
679
+ }, y = (E, A) => {
680
+ d(E, A, n.pointerMode);
681
+ }, k = (E, A, Z, U) => a(E, A, Z, U, n), C = () => {
682
+ i(n.pointerMode, c);
683
+ }, O = () => {
684
+ o() && ve(() => r());
685
+ }, b = async (E) => {
686
+ try {
687
+ await g(E, n.activeViewer, c);
688
+ } catch (A) {
689
+ console.error("Error creating layer:", A);
690
+ }
691
+ }, S = (E) => {
692
+ var A;
693
+ return ((A = E == null ? void 0 : E.content) == null ? void 0 : A.id) != null;
694
+ }, F = () => typeof n.start == "number" && typeof n.tsEnd == "number" && n.tsEnd > 0, R = I(!1), $ = I(null), G = async (E) => {
695
+ if (!S(E))
696
+ return console.log("[TSAnnotationCanvas] Waiting for activeViewer to be ready..."), !1;
697
+ if ($.value !== E.content.id && (R.value = !1, $.value = E.content.id), R.value)
698
+ return !0;
699
+ console.log("[TSAnnotationCanvas] activeViewer ready, loading layers");
700
+ try {
701
+ const A = await T(E, c);
702
+ return R.value = !!A, R.value;
703
+ } catch (A) {
704
+ return console.error("[TSAnnotationCanvas] Error loading layers:", A), !1;
705
+ }
706
+ }, P = async () => {
707
+ if (!R.value) {
708
+ console.log("[TSAnnotationCanvas] Layers not loaded yet, skipping annotation fetch");
709
+ return;
710
+ }
711
+ if (!F()) {
712
+ console.log("[TSAnnotationCanvas] Time range not ready yet, skipping annotation fetch");
713
+ return;
714
+ }
715
+ console.log("[TSAnnotationCanvas] Fetching annotations for time range:", {
716
+ start: n.start,
717
+ end: n.start + n.duration,
718
+ tsEnd: n.tsEnd
719
+ });
720
+ try {
721
+ await w(
722
+ n.start,
723
+ n.start + n.duration,
724
+ n,
725
+ n.activeViewer,
726
+ c
727
+ );
728
+ } catch (E) {
729
+ console.error("[TSAnnotationCanvas] Error fetching annotations:", E);
730
+ }
731
+ };
732
+ return ee(
733
+ () => n.activeViewer,
734
+ async (E, A) => {
735
+ var U, V, X;
736
+ if (((U = A == null ? void 0 : A.content) == null ? void 0 : U.id) === ((V = E == null ? void 0 : E.content) == null ? void 0 : V.id) && ((X = A == null ? void 0 : A.content) == null ? void 0 : X.id) != null)
737
+ return;
738
+ await G(E) && await P();
739
+ },
740
+ { immediate: !0, deep: !0 }
741
+ ), ee(
742
+ () => n.tsEnd,
743
+ async (E, A) => {
744
+ typeof E == "number" && E > 0 && A !== E && (console.log("[TSAnnotationCanvas] tsEnd became valid:", E), await P());
745
+ }
746
+ ), ce(() => {
747
+ console.log("TSAnnotationCanvas mounted with props:", {
748
+ constants: n.constants,
749
+ annotationsCanvas: n.annotationsCanvas,
750
+ viewerActiveTool: n.viewerActiveTool,
751
+ activeViewerReady: S(n.activeViewer),
752
+ timeRangeReady: F()
753
+ });
754
+ }), u({
755
+ render: r,
756
+ resetFocusedAnnotation: e,
757
+ findNextAnnotation: p,
758
+ findPreviousAnnotation: M,
759
+ checkAnnotationRange: (E, A) => w(E, A, n, n.activeViewer, c),
760
+ selectFocusedAnn: O,
761
+ createAnnotationLayer: b,
762
+ onMouseDown: y,
763
+ onMouseMove: k,
764
+ onMouseUp: C
765
+ }), (E, A) => (de(), ue("canvas", {
766
+ id: "annLabelArea",
767
+ ref_key: "annLabelArea",
768
+ ref: h,
769
+ class: "timeseries-annotation-canvas",
770
+ width: te(ae)(t.cWidth, t.pixelRatio, 0),
771
+ height: te(ae)(s.value, t.pixelRatio, 0),
772
+ style: fe(v.value)
773
+ }, null, 12, Se));
774
+ }
775
+ }, He = /* @__PURE__ */ ye(Fe, [["__scopeId", "data-v-e9cfe856"]]);
776
+ export {
777
+ He as default
778
+ };