tsviewer 1.0.28 → 1.0.30

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