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