@linkurious/ogma-annotations 2.1.3 → 2.1.4
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.
- package/dist/{Polygon-C9ZkyU-t.js → Polygon-BmJ_q7qz.js} +141 -132
- package/dist/index.js +3 -3
- package/dist/index.mjs +736 -702
- package/dist/types/{Control-BiYdzv0K.d.ts → Control-Cv1I3e3C.d.ts} +12 -0
- package/dist/types/index.d.ts +17 -3
- package/dist/types/ui.d.ts +13 -0
- package/dist/ui-styles.css +8 -0
- package/dist/ui.js +25 -25
- package/dist/ui.mjs +312 -278
- package/package.json +3 -1
package/dist/ui.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var _ = Object.defineProperty;
|
|
2
|
-
var R = (
|
|
3
|
-
var
|
|
2
|
+
var R = (s, t, e) => t in s ? _(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
+
var c = (s, t, e) => R(s, typeof t != "symbol" ? t + "" : t, e);
|
|
4
4
|
import { RgbaBase as z } from "vanilla-colorful/lib/entrypoints/rgba";
|
|
5
|
-
import { j as w, s as
|
|
6
|
-
const
|
|
5
|
+
import { j as w, s as k, t as T, i as B, v as E, h as S, L as y, aO as F, F as x, ao as P, aj as M, G as q, u as W, M as V, am as $, aN as U } from "./Polygon-BmJ_q7qz.js";
|
|
6
|
+
const A = "rgba-color-picker";
|
|
7
7
|
class Y extends z {
|
|
8
8
|
}
|
|
9
9
|
function N() {
|
|
10
|
-
return customElements.get(
|
|
10
|
+
return customElements.get(A) || customElements.define(A, Y), document.createElement(A);
|
|
11
11
|
}
|
|
12
12
|
const j = [
|
|
13
13
|
{ value: "#f5f5f5", style: "--circle-color: #f5f5f5;" },
|
|
@@ -30,16 +30,16 @@ const j = [
|
|
|
30
30
|
{ value: "plain", icon: "circle" },
|
|
31
31
|
{ value: "dashed", icon: "circle-dashed" }
|
|
32
32
|
], J = ["#0099FF", "#FF7523", "#44AA99"];
|
|
33
|
-
function
|
|
34
|
-
return `rgba(${
|
|
33
|
+
function O(s) {
|
|
34
|
+
return `rgba(${s.r}, ${s.g}, ${s.b}, ${s.a})`;
|
|
35
35
|
}
|
|
36
36
|
const K = 3;
|
|
37
37
|
function Z() {
|
|
38
38
|
return { colors: [...J], activeIndex: 0 };
|
|
39
39
|
}
|
|
40
|
-
function Q(
|
|
41
|
-
const e =
|
|
42
|
-
return e === -1 ? { colors: [t, ...
|
|
40
|
+
function Q(s, t) {
|
|
41
|
+
const e = s.colors.indexOf(t);
|
|
42
|
+
return e === -1 ? { colors: [t, ...s.colors].slice(0, K), activeIndex: 0 } : { colors: s.colors, activeIndex: e };
|
|
43
43
|
}
|
|
44
44
|
const tt = {
|
|
45
45
|
"chevron-down": '<path d="m6 9 6 6 6-6"/>',
|
|
@@ -70,95 +70,104 @@ const tt = {
|
|
|
70
70
|
"rotate-ccw": '<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/>',
|
|
71
71
|
minimize: '<path d="M8 3v3a2 2 0 0 1-2 2H3"/><path d="M21 8h-3a2 2 0 0 1-2-2V3"/><path d="M3 16h3a2 2 0 0 1 2 2v3"/><path d="M16 21v-3a2 2 0 0 1 2-2h3"/>'
|
|
72
72
|
};
|
|
73
|
-
function
|
|
74
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${tt[
|
|
73
|
+
function v(s, t = 18) {
|
|
74
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${tt[s]}</svg>`;
|
|
75
75
|
}
|
|
76
76
|
const et = 150;
|
|
77
|
-
function
|
|
78
|
-
const
|
|
79
|
-
let
|
|
80
|
-
const
|
|
77
|
+
function D(s, { onShow: t, onHide: e, hideWhenNotEditable: o = !0 }) {
|
|
78
|
+
const i = (p) => !o || s.isAnnotationEditable(p);
|
|
79
|
+
let n = null, r = null, d = null, h = null;
|
|
80
|
+
const a = () => {
|
|
81
81
|
h !== null && (clearTimeout(h), h = null);
|
|
82
82
|
}, l = () => {
|
|
83
|
-
if (
|
|
84
|
-
const p =
|
|
85
|
-
|
|
83
|
+
if (a(), n) {
|
|
84
|
+
const p = n;
|
|
85
|
+
n = null, i(p.id) ? (r = p, t(p)) : u();
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
if (!
|
|
89
|
-
const p =
|
|
90
|
-
p &&
|
|
88
|
+
if (!r && d != null) {
|
|
89
|
+
const p = s.getAnnotation(d);
|
|
90
|
+
p && i(p.id) && (r = p, t(p));
|
|
91
91
|
}
|
|
92
92
|
}, u = () => {
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
if (
|
|
96
|
-
const
|
|
97
|
-
if (!
|
|
98
|
-
if (d = p.ids[0],
|
|
99
|
-
|
|
93
|
+
a(), n = null, r = null, e();
|
|
94
|
+
}, m = (p) => {
|
|
95
|
+
if (a(), p.ids.length === 1) {
|
|
96
|
+
const g = s.getAnnotation(p.ids[0]);
|
|
97
|
+
if (!g) return;
|
|
98
|
+
if (d = p.ids[0], n = g, s.isDrawing()) {
|
|
99
|
+
s.once("cancelDrawing", l), s.once("completeDrawing", l);
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
h = setTimeout(l, et);
|
|
103
103
|
} else
|
|
104
104
|
d = null, u();
|
|
105
|
-
},
|
|
106
|
-
const
|
|
107
|
-
|
|
105
|
+
}, b = () => u(), f = (p) => {
|
|
106
|
+
const g = n ?? r;
|
|
107
|
+
g && !p.ids.includes(g.id) || (d = null, u());
|
|
108
108
|
};
|
|
109
|
-
return
|
|
110
|
-
|
|
109
|
+
return s.on("select", m), s.on("click", l), s.on("dragend", l), s.on("dragstart", b), s.on("unselect", f), () => {
|
|
110
|
+
a(), s.off("select", m), s.off("click", l), s.off("dragend", l), s.off("dragstart", b), s.off("unselect", f), s.off("cancelDrawing", l), s.off("completeDrawing", l);
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
const ot = "right",
|
|
113
|
+
const ot = "right", it = "vertical", nt = [
|
|
114
114
|
"arrow",
|
|
115
115
|
"text",
|
|
116
116
|
"box",
|
|
117
117
|
"comment",
|
|
118
118
|
"polygon"
|
|
119
119
|
];
|
|
120
|
-
function
|
|
121
|
-
return w(
|
|
120
|
+
function rt(s) {
|
|
121
|
+
return w(s) ? "arrow" : k(s) ? "text" : T(s) ? "box" : B(s) ? "comment" : E(s) ? "polygon" : null;
|
|
122
122
|
}
|
|
123
123
|
class kt {
|
|
124
124
|
constructor(t) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
125
|
+
c(this, "control");
|
|
126
|
+
c(this, "panel");
|
|
127
|
+
c(this, "panelBody");
|
|
128
|
+
c(this, "mode", null);
|
|
129
|
+
c(this, "currentAnnotation", null);
|
|
130
|
+
c(this, "currentColor", "#0099FF");
|
|
131
|
+
c(this, "recent", Z());
|
|
132
|
+
c(this, "colorCircles", []);
|
|
133
|
+
c(this, "colorPickerOverlay", null);
|
|
134
|
+
c(this, "colorPicker", null);
|
|
135
|
+
c(this, "detachVisibility");
|
|
136
|
+
c(this, "documentClickHandler");
|
|
137
|
+
c(this, "enabledTypes");
|
|
138
|
+
c(this, "hide", () => {
|
|
139
139
|
this.panel.style.display = "none", this.closeColorPicker(), this.currentAnnotation = null, this.mode = null;
|
|
140
140
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
var i, n, r, d;
|
|
142
|
+
this.control = t.control, this.enabledTypes = t.enabledTypes ?? nt;
|
|
143
|
+
const e = t.container ?? document.body, o = (d = (r = (n = (i = this.control).getOgma) == null ? void 0 : n.call(i)) == null ? void 0 : r.getContainer) == null ? void 0 : d.call(r);
|
|
144
|
+
!t.container && o && o !== document.body && console.error(
|
|
145
|
+
"[ogma-annotations-control] AnnotationPanel: no `container` option given, defaulting to document.body. If this panel should dock to the Ogma graph area (e.g. it is embedded in a smaller/offset div), pass `container: control.getOgma().getContainer()` and give that container `position: relative`."
|
|
146
|
+
), this.panel = document.createElement("div"), this.panel.className = "annotation-panel", this.panel.setAttribute("role", "region"), this.panel.setAttribute("aria-label", "Annotation style panel"), this.panel.style.display = "none", this.panel.dataset.placement = t.placement ?? ot, this.panel.dataset.orientation = t.orientation ?? it, this.panelBody = document.createElement("div"), this.panelBody.className = "panel-body", this.panel.appendChild(this.panelBody), e.appendChild(this.panel), this.detachVisibility = D(this.control, {
|
|
147
|
+
onShow: (h) => {
|
|
148
|
+
const a = rt(h);
|
|
149
|
+
if (!a || !this.enabledTypes.includes(a)) {
|
|
147
150
|
this.hide();
|
|
148
151
|
return;
|
|
149
152
|
}
|
|
150
|
-
this.setAnnotation(
|
|
153
|
+
this.setAnnotation(h), this.show();
|
|
151
154
|
},
|
|
152
155
|
onHide: this.hide,
|
|
153
156
|
hideWhenNotEditable: t.hideWhenNotEditable
|
|
154
157
|
}), ["click", "mousedown", "mousemove"].forEach(
|
|
155
|
-
(
|
|
156
|
-
), this.documentClickHandler = (
|
|
157
|
-
this.colorPickerOverlay && !this.colorPickerOverlay.contains(
|
|
158
|
+
(h) => this.panel.addEventListener(h, (a) => a.stopPropagation())
|
|
159
|
+
), this.documentClickHandler = (h) => {
|
|
160
|
+
this.colorPickerOverlay && !this.colorPickerOverlay.contains(h.target) && !this.colorCircles.some((a) => a.contains(h.target)) && this.closeColorPicker(), this.panelBody.querySelectorAll(".custom-select").forEach((a) => {
|
|
161
|
+
var l;
|
|
162
|
+
a.classList.remove("open"), (l = a.querySelector(".custom-select-trigger")) == null || l.setAttribute(
|
|
163
|
+
"aria-expanded",
|
|
164
|
+
"false"
|
|
165
|
+
);
|
|
166
|
+
});
|
|
158
167
|
}, document.addEventListener("click", this.documentClickHandler);
|
|
159
168
|
}
|
|
160
169
|
setAnnotation(t) {
|
|
161
|
-
this.currentAnnotation = t, w(t) ? (this.mode = "arrow", this.renderArrow(t)) :
|
|
170
|
+
this.currentAnnotation = t, w(t) ? (this.mode = "arrow", this.renderArrow(t)) : k(t) || T(t) || B(t) ? (this.mode = "text", this.renderText(t)) : E(t) && (this.mode = "polygon", this.renderPolygon(t));
|
|
162
171
|
}
|
|
163
172
|
renderArrow(t) {
|
|
164
173
|
const e = t.properties.style || {};
|
|
@@ -179,14 +188,14 @@ class kt {
|
|
|
179
188
|
}
|
|
180
189
|
renderText(t) {
|
|
181
190
|
const e = t.properties.style || {};
|
|
182
|
-
this.updateColorFromAnnotation(e.color ||
|
|
183
|
-
const o = typeof e.fontSize == "number" ? e.fontSize : typeof
|
|
191
|
+
this.updateColorFromAnnotation(e.color || y.color);
|
|
192
|
+
const o = typeof e.fontSize == "number" ? e.fontSize : typeof y.fontSize == "number" ? y.fontSize : 18;
|
|
184
193
|
this.panelBody.innerHTML = `
|
|
185
194
|
${this.section("Color", this.colorSelector())}
|
|
186
|
-
${this.section("Background", this.backgroundSelector(e.background ||
|
|
187
|
-
${this.section("Font", `<div class="custom-select-section">${this.fontSelector(e.font ||
|
|
195
|
+
${this.section("Background", this.backgroundSelector(e.background || y.background))}
|
|
196
|
+
${this.section("Font", `<div class="custom-select-section">${this.fontSelector(e.font || y.font)}</div>`)}
|
|
188
197
|
${this.slider("Font size", "font-size", o, 8, 72)}
|
|
189
|
-
${this.slider("Stroke width", "line-width", e.strokeWidth ||
|
|
198
|
+
${this.slider("Stroke width", "line-width", e.strokeWidth || y.strokeWidth, 1, 20)}
|
|
190
199
|
${this.lineTypeButtons(e.strokeType || "plain")}
|
|
191
200
|
`, this.bind();
|
|
192
201
|
}
|
|
@@ -194,7 +203,7 @@ class kt {
|
|
|
194
203
|
const e = t.properties.style || {};
|
|
195
204
|
this.updateColorFromAnnotation(e.strokeColor || "#000000"), this.panelBody.innerHTML = `
|
|
196
205
|
${this.section("Color", this.colorSelector())}
|
|
197
|
-
${this.section("Fill", this.backgroundSelector(e.background || "transparent"))}
|
|
206
|
+
${this.section("Fill", this.backgroundSelector(e.background || "transparent", "Fill"))}
|
|
198
207
|
${this.slider("Stroke width", "line-width", e.strokeWidth || 2, 1, 20)}
|
|
199
208
|
${this.lineTypeButtons(e.strokeType || "plain")}
|
|
200
209
|
`, this.bind();
|
|
@@ -204,22 +213,22 @@ class kt {
|
|
|
204
213
|
return `<div class="section-header"><h3>${t}</h3></div>${e}`;
|
|
205
214
|
}
|
|
206
215
|
icon(t, e = !1) {
|
|
207
|
-
return e ? `<span style="display:inline-flex;transform:rotate(180deg)">${
|
|
216
|
+
return e ? `<span style="display:inline-flex;transform:rotate(180deg)">${v(t)}</span>` : v(t);
|
|
208
217
|
}
|
|
209
218
|
colorSelector() {
|
|
210
|
-
return `<div class="color-selector">${this.recent.colors.map(
|
|
219
|
+
return `<div class="color-selector" role="group" aria-label="Color">${this.recent.colors.map(
|
|
211
220
|
(t, e) => `
|
|
212
|
-
<button class="color-circle ${e === 0 ? "color-circle-primary" : ""}" data-index="${e}" data-color="${t}">
|
|
221
|
+
<button type="button" class="color-circle ${e === 0 ? "color-circle-primary" : ""}" data-index="${e}" data-color="${t}" aria-label="Set color to ${t}" aria-pressed="${e === 0}">
|
|
213
222
|
<div class="color-inner"></div>
|
|
214
223
|
</button>
|
|
215
224
|
`
|
|
216
225
|
).join("")}</div>`;
|
|
217
226
|
}
|
|
218
|
-
backgroundSelector(t) {
|
|
219
|
-
return `<div class="color-selector">${j.map(
|
|
220
|
-
({ value:
|
|
221
|
-
<button class="color-circle ${
|
|
222
|
-
<div class="color-inner" style="${
|
|
227
|
+
backgroundSelector(t, e = "Background") {
|
|
228
|
+
return `<div class="color-selector" role="group" aria-label="${e}">${j.map(
|
|
229
|
+
({ value: o, style: i }) => `
|
|
230
|
+
<button type="button" class="color-circle ${o === t ? "color-circle-primary" : ""}" data-background-color="${o}" aria-label="${o === "transparent" ? "No background" : `Background ${o}`}" aria-pressed="${o === t}">
|
|
231
|
+
<div class="color-inner" style="${i}"></div>
|
|
223
232
|
</button>
|
|
224
233
|
`
|
|
225
234
|
).join("")}</div>`;
|
|
@@ -233,37 +242,38 @@ class kt {
|
|
|
233
242
|
);
|
|
234
243
|
}
|
|
235
244
|
extremitySelector(t, e) {
|
|
236
|
-
var
|
|
237
|
-
const o = ((
|
|
245
|
+
var r;
|
|
246
|
+
const o = ((r = e.properties.style) == null ? void 0 : r[t]) || "none", i = G.map((d) => ({
|
|
238
247
|
...d,
|
|
239
248
|
icon: d.value === "arrow" && t === "tail" ? "arrow-left" : d.value === "arrow" ? "arrow-right" : d.icon,
|
|
240
249
|
selected: d.value === o,
|
|
241
250
|
rotate: d.value === "arrow-plain" && t === "tail"
|
|
242
|
-
})),
|
|
243
|
-
return `<div class="extremity-wrapper"><label>${t}</label>${this.dropdown(t,
|
|
251
|
+
})), n = i.find((d) => d.selected) || i[0];
|
|
252
|
+
return `<div class="extremity-wrapper"><label>${t}</label>${this.dropdown(t, n, i, `data-end="${t}"`)}</div>`;
|
|
244
253
|
}
|
|
245
|
-
dropdown(t, e, o,
|
|
246
|
-
|
|
247
|
-
|
|
254
|
+
dropdown(t, e, o, i = "") {
|
|
255
|
+
const n = t === "font" ? "Font" : t;
|
|
256
|
+
return `<div class="custom-select" data-type="${t}" ${i}>
|
|
257
|
+
<button type="button" class="custom-select-trigger" aria-haspopup="listbox" aria-expanded="false" aria-label="${n}: ${e.label}">
|
|
248
258
|
${this.icon(e.icon, e.rotate)}
|
|
249
259
|
<span>${e.label}</span>
|
|
250
260
|
${this.icon("chevron-down")}
|
|
251
|
-
</
|
|
252
|
-
<div class="custom-select-options">${o.map(
|
|
253
|
-
(
|
|
254
|
-
<
|
|
255
|
-
${this.icon(
|
|
256
|
-
<span>${
|
|
257
|
-
</
|
|
261
|
+
</button>
|
|
262
|
+
<div class="custom-select-options" role="listbox" aria-label="${n} options">${o.map(
|
|
263
|
+
(r) => `
|
|
264
|
+
<button type="button" role="option" aria-selected="${r.selected ? "true" : "false"}" class="custom-select-option ${r.selected ? "selected" : ""}" data-value="${r.value}" data-icon="${r.icon}" data-rotate="${r.rotate ? "1" : ""}" title="${r.label}">
|
|
265
|
+
${this.icon(r.icon, r.rotate)}
|
|
266
|
+
<span>${r.label}</span>
|
|
267
|
+
</button>
|
|
258
268
|
`
|
|
259
269
|
).join("")}</div>
|
|
260
270
|
</div>`;
|
|
261
271
|
}
|
|
262
|
-
slider(t, e, o,
|
|
272
|
+
slider(t, e, o, i, n) {
|
|
263
273
|
return `${this.section(
|
|
264
274
|
t,
|
|
265
275
|
`<div class="slider-section">
|
|
266
|
-
<input type="range" id="${e}-slider" class="slider" min="${
|
|
276
|
+
<input type="range" id="${e}-slider" class="slider" aria-label="${t}" min="${i}" max="${n}" value="${o}">
|
|
267
277
|
<div class="slider-value"><span id="${e}-value">${o}</span></div>
|
|
268
278
|
</div>`
|
|
269
279
|
)}`;
|
|
@@ -271,9 +281,9 @@ class kt {
|
|
|
271
281
|
lineTypeButtons(t) {
|
|
272
282
|
return `${this.section(
|
|
273
283
|
"Line type",
|
|
274
|
-
`<div class="linetype-section">${X.map(
|
|
284
|
+
`<div class="linetype-section" role="group" aria-label="Line type">${X.map(
|
|
275
285
|
({ value: e, icon: o }) => `
|
|
276
|
-
<button class="linetype-button ${t === e ? "active" : ""}" data-linetype="${e}" title="${e}">
|
|
286
|
+
<button type="button" class="linetype-button ${t === e ? "active" : ""}" data-linetype="${e}" title="${e}" aria-label="${e} line" aria-pressed="${t === e}">
|
|
277
287
|
${this.icon(o)}
|
|
278
288
|
</button>
|
|
279
289
|
`
|
|
@@ -287,8 +297,8 @@ class kt {
|
|
|
287
297
|
), this.colorCircles.forEach((t, e) => {
|
|
288
298
|
t.addEventListener("click", (o) => {
|
|
289
299
|
o.stopPropagation();
|
|
290
|
-
const
|
|
291
|
-
this.recent = { ...this.recent, activeIndex: e }, this.currentColor = this.recent.colors[e], this.updateColorCircles(),
|
|
300
|
+
const i = this.recent.activeIndex === e && t.classList.contains("color-circle-primary");
|
|
301
|
+
this.recent = { ...this.recent, activeIndex: e }, this.currentColor = this.recent.colors[e], this.updateColorCircles(), i ? this.toggleColorPicker(t) : this.mode === "arrow" ? this.updateStyle({ strokeColor: this.currentColor }) : this.mode === "text" && this.updateStyle({ strokeColor: this.currentColor });
|
|
292
302
|
});
|
|
293
303
|
}), this.updateColorCircles(), this.panelBody.querySelectorAll("[data-background-color]").forEach((t) => {
|
|
294
304
|
t.addEventListener(
|
|
@@ -300,20 +310,28 @@ class kt {
|
|
|
300
310
|
".custom-select-trigger"
|
|
301
311
|
), o = t.querySelectorAll(
|
|
302
312
|
".custom-select-option"
|
|
303
|
-
);
|
|
313
|
+
), i = t.dataset.type === "font" ? "Font" : t.dataset.type;
|
|
304
314
|
e.addEventListener("click", (n) => {
|
|
305
|
-
n.stopPropagation(), this.panelBody.querySelectorAll(".custom-select").forEach((
|
|
306
|
-
|
|
307
|
-
|
|
315
|
+
n.stopPropagation(), this.panelBody.querySelectorAll(".custom-select").forEach((d) => {
|
|
316
|
+
var h;
|
|
317
|
+
d !== t && (d.classList.remove("open"), (h = d.querySelector(".custom-select-trigger")) == null || h.setAttribute(
|
|
318
|
+
"aria-expanded",
|
|
319
|
+
"false"
|
|
320
|
+
));
|
|
321
|
+
});
|
|
322
|
+
const r = !t.classList.contains("open");
|
|
323
|
+
t.classList.toggle("open", r), e.setAttribute("aria-expanded", String(r));
|
|
308
324
|
}), o.forEach((n) => {
|
|
309
|
-
n.addEventListener("click", (
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
o.forEach((
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
u
|
|
325
|
+
n.addEventListener("click", (r) => {
|
|
326
|
+
r.stopPropagation();
|
|
327
|
+
const d = n.dataset.value;
|
|
328
|
+
o.forEach((f) => {
|
|
329
|
+
f.classList.remove("selected"), f.setAttribute("aria-selected", "false");
|
|
330
|
+
}), n.classList.add("selected"), n.setAttribute("aria-selected", "true");
|
|
331
|
+
const h = n.dataset.icon, a = n.dataset.rotate === "1", l = n.querySelector("span").textContent || "", u = e.querySelector("svg, span[style]");
|
|
332
|
+
u && (u.outerHTML = this.icon(h, a)), e.querySelector("span").textContent = l, e.setAttribute("aria-label", `${i}: ${l}`), t.classList.remove("open"), e.setAttribute("aria-expanded", "false");
|
|
333
|
+
const m = t.dataset.type, b = t.dataset.end;
|
|
334
|
+
m === "font" ? this.updateStyle({ font: d }) : b === "head" ? this.updateStyle({ head: d }) : b === "tail" && this.updateStyle({ tail: d });
|
|
317
335
|
});
|
|
318
336
|
});
|
|
319
337
|
}), ["line-width", "font-size"].forEach((t) => {
|
|
@@ -321,15 +339,17 @@ class kt {
|
|
|
321
339
|
`#${t}-slider`
|
|
322
340
|
), o = this.panelBody.querySelector(`#${t}-value`);
|
|
323
341
|
e && o && e.addEventListener("input", () => {
|
|
324
|
-
const
|
|
325
|
-
o.textContent =
|
|
326
|
-
this.mode === "text" ? { strokeWidth:
|
|
327
|
-
) : t === "font-size" && this.updateStyle({ fontSize:
|
|
342
|
+
const i = parseInt(e.value, 10);
|
|
343
|
+
o.textContent = i.toString(), t === "line-width" ? this.updateStyle(
|
|
344
|
+
this.mode === "text" ? { strokeWidth: i, strokeColor: this.currentColor } : { strokeWidth: i }
|
|
345
|
+
) : t === "font-size" && this.updateStyle({ fontSize: i });
|
|
328
346
|
});
|
|
329
347
|
}), this.panelBody.querySelectorAll(".linetype-button").forEach((t) => {
|
|
330
348
|
t.addEventListener("click", () => {
|
|
331
349
|
const e = t.dataset.linetype;
|
|
332
|
-
this.panelBody.querySelectorAll(".linetype-button").forEach((o) =>
|
|
350
|
+
this.panelBody.querySelectorAll(".linetype-button").forEach((o) => {
|
|
351
|
+
o.classList.remove("active"), o.setAttribute("aria-pressed", "false");
|
|
352
|
+
}), t.classList.add("active"), t.setAttribute("aria-pressed", "true"), this.updateStyle({ strokeType: e });
|
|
333
353
|
});
|
|
334
354
|
});
|
|
335
355
|
}
|
|
@@ -339,10 +359,9 @@ class kt {
|
|
|
339
359
|
}
|
|
340
360
|
updateColorCircles() {
|
|
341
361
|
this.colorCircles.forEach((t, e) => {
|
|
342
|
-
t.setAttribute("data-color", this.recent.colors[e]), t.style.setProperty("--circle-color", this.recent.colors[e])
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
);
|
|
362
|
+
t.setAttribute("data-color", this.recent.colors[e]), t.setAttribute("aria-label", `Set color to ${this.recent.colors[e]}`), t.style.setProperty("--circle-color", this.recent.colors[e]);
|
|
363
|
+
const o = e === this.recent.activeIndex;
|
|
364
|
+
t.classList.toggle("color-circle-primary", o), t.setAttribute("aria-pressed", String(o));
|
|
346
365
|
});
|
|
347
366
|
}
|
|
348
367
|
toggleColorPicker(t) {
|
|
@@ -350,10 +369,10 @@ class kt {
|
|
|
350
369
|
this.closeColorPicker();
|
|
351
370
|
return;
|
|
352
371
|
}
|
|
353
|
-
this.colorPickerOverlay = document.createElement("div"), this.colorPickerOverlay.className = "color-picker-overlay", document.body.appendChild(this.colorPickerOverlay), this.colorPicker = N(), this.colorPicker.color = F(this.currentColor), this.colorPickerOverlay.appendChild(this.colorPicker);
|
|
372
|
+
this.colorPickerOverlay = document.createElement("div"), this.colorPickerOverlay.className = "color-picker-overlay", this.colorPickerOverlay.setAttribute("role", "dialog"), this.colorPickerOverlay.setAttribute("aria-label", "Custom color picker"), document.body.appendChild(this.colorPickerOverlay), this.colorPicker = N(), this.colorPicker.color = F(this.currentColor), this.colorPickerOverlay.appendChild(this.colorPicker);
|
|
354
373
|
const e = t.getBoundingClientRect();
|
|
355
374
|
this.colorPickerOverlay.style.right = `${window.innerWidth - e.right}px`, this.colorPickerOverlay.style.top = `${e.bottom + 10}px`, this.colorPicker.addEventListener("color-changed", (o) => {
|
|
356
|
-
this.currentColor =
|
|
375
|
+
this.currentColor = O(o.detail.value), this.recent.colors[this.recent.activeIndex] = this.currentColor, this.updateColorCircles(), this.mode === "arrow" ? this.updateStyle({ strokeColor: this.currentColor }) : this.mode === "text" ? this.updateStyle({ color: this.currentColor }) : this.mode === "polygon" && this.updateStyle({ strokeColor: this.currentColor });
|
|
357
376
|
});
|
|
358
377
|
}
|
|
359
378
|
closeColorPicker() {
|
|
@@ -378,7 +397,7 @@ class kt {
|
|
|
378
397
|
this.closeColorPicker(), this.detachVisibility(), document.removeEventListener("click", this.documentClickHandler), this.panel.remove();
|
|
379
398
|
}
|
|
380
399
|
}
|
|
381
|
-
const
|
|
400
|
+
const st = "bottom", at = "horizontal", L = [
|
|
382
401
|
"arrow",
|
|
383
402
|
"comment",
|
|
384
403
|
"sticky-note",
|
|
@@ -386,26 +405,29 @@ const rt = "bottom", lt = "horizontal", T = [
|
|
|
386
405
|
"text",
|
|
387
406
|
"polygon"
|
|
388
407
|
];
|
|
389
|
-
class
|
|
408
|
+
class At {
|
|
390
409
|
constructor(t) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
410
|
+
c(this, "control");
|
|
411
|
+
c(this, "root");
|
|
412
|
+
c(this, "activeButton", null);
|
|
413
|
+
c(this, "undoButton");
|
|
414
|
+
c(this, "redoButton");
|
|
415
|
+
c(this, "handleDrawingEnd", () => this.setActiveMode(null));
|
|
416
|
+
c(this, "handleHistory", () => this.updateUndoRedo());
|
|
417
|
+
var d, h, a, l;
|
|
398
418
|
this.control = t.control;
|
|
399
|
-
const e = t.container ?? document.body;
|
|
400
|
-
|
|
401
|
-
|
|
419
|
+
const e = t.container ?? document.body, o = (l = (a = (h = (d = this.control).getOgma) == null ? void 0 : h.call(d)) == null ? void 0 : a.getContainer) == null ? void 0 : l.call(a);
|
|
420
|
+
!t.container && o && o !== document.body && console.error(
|
|
421
|
+
"[ogma-annotations-control] AnnotationToolbar: no `container` option given, defaulting to document.body. If this toolbar should dock to the Ogma graph area (e.g. it is embedded in a smaller/offset div), pass `container: control.getOgma().getContainer()` and give that container `position: relative`."
|
|
422
|
+
), this.root = document.createElement("div"), this.root.className = "annotation-toolbar oa-toolbar oa-toolbar-bar", this.root.setAttribute("role", "group"), this.root.setAttribute("aria-label", "Annotation tools"), this.root.dataset.placement = t.placement ?? st, this.root.dataset.orientation = t.orientation ?? at, e.appendChild(this.root), ["click", "mousedown", "mousemove"].forEach(
|
|
423
|
+
(u) => this.root.addEventListener(u, (m) => m.stopPropagation())
|
|
402
424
|
);
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
(
|
|
406
|
-
),
|
|
407
|
-
const
|
|
408
|
-
(
|
|
425
|
+
const i = t.enabledTypes ?? L, n = t.styles ?? {};
|
|
426
|
+
L.filter((u) => i.includes(u)).forEach(
|
|
427
|
+
(u) => this.root.appendChild(this.drawingButton(u, n))
|
|
428
|
+
), i.length > 0 && this.root.appendChild(this.separator()), this.undoButton = this.button(null, "undo", "Undo", () => this.control.undo()), this.redoButton = this.button(null, "redo", "Redo", () => this.control.redo()), this.root.appendChild(this.undoButton), this.root.appendChild(this.redoButton);
|
|
429
|
+
const r = t.deleteMode ?? "erase";
|
|
430
|
+
(r === "erase" || r === "both") && (this.root.appendChild(this.separator()), this.root.appendChild(
|
|
409
431
|
this.button(
|
|
410
432
|
"erase",
|
|
411
433
|
"eraser",
|
|
@@ -414,18 +436,18 @@ class Ct {
|
|
|
414
436
|
this.control.isEraseModeActive() ? (this.control.disableEraseMode(), this.setActiveMode(null)) : (this.control.enableEraseMode(), this.setActiveMode("erase"));
|
|
415
437
|
}
|
|
416
438
|
)
|
|
417
|
-
)), (
|
|
439
|
+
)), (r === "select" || r === "both") && (r === "select" && this.root.appendChild(this.separator()), this.root.appendChild(
|
|
418
440
|
this.button(null, "trash", "Delete selected", () => {
|
|
419
|
-
const
|
|
420
|
-
(
|
|
441
|
+
const m = this.control.getSelectedAnnotations().features.filter(
|
|
442
|
+
(b) => this.control.isAnnotationEditable(b.id)
|
|
421
443
|
);
|
|
422
|
-
|
|
444
|
+
m.length > 0 && this.control.remove({ type: "FeatureCollection", features: m });
|
|
423
445
|
})
|
|
424
446
|
)), (t.onJsonExport || t.onSvgExport) && (this.root.appendChild(this.separator()), t.onJsonExport && this.root.appendChild(
|
|
425
447
|
this.button(null, "download", "Export annotations", t.onJsonExport)
|
|
426
448
|
), t.onSvgExport && this.root.appendChild(
|
|
427
449
|
this.button(null, "camera", "Export SVG", t.onSvgExport)
|
|
428
|
-
)), this.control.on(x, this.handleDrawingEnd), this.control.on(
|
|
450
|
+
)), this.control.on(x, this.handleDrawingEnd), this.control.on(P, this.handleDrawingEnd), this.control.on(M, this.handleHistory), this.updateUndoRedo();
|
|
429
451
|
}
|
|
430
452
|
drawingButton(t, e) {
|
|
431
453
|
switch (t) {
|
|
@@ -441,8 +463,8 @@ class Ct {
|
|
|
441
463
|
});
|
|
442
464
|
case "comment":
|
|
443
465
|
return this.button("comment", "message-square", "Add comment", () => {
|
|
444
|
-
var
|
|
445
|
-
const o = (
|
|
466
|
+
var n, r, d, h;
|
|
467
|
+
const o = (n = e.comment) == null ? void 0 : n.commentStyle, i = (r = e.comment) == null ? void 0 : r.arrowStyle;
|
|
446
468
|
this.control.enableCommentDrawing({
|
|
447
469
|
offsetX: ((d = e.comment) == null ? void 0 : d.offsetX) ?? 200,
|
|
448
470
|
offsetY: ((h = e.comment) == null ? void 0 : h.offsetY) ?? -150,
|
|
@@ -458,13 +480,13 @@ class Ct {
|
|
|
458
480
|
}
|
|
459
481
|
},
|
|
460
482
|
arrowStyle: {
|
|
461
|
-
...
|
|
483
|
+
...i,
|
|
462
484
|
style: {
|
|
463
485
|
strokeType: "plain",
|
|
464
486
|
strokeColor: "#3A03CF",
|
|
465
487
|
strokeWidth: 2,
|
|
466
488
|
head: "halo-dot",
|
|
467
|
-
...
|
|
489
|
+
...i == null ? void 0 : i.style
|
|
468
490
|
}
|
|
469
491
|
}
|
|
470
492
|
}), this.setActiveMode("comment");
|
|
@@ -517,16 +539,16 @@ class Ct {
|
|
|
517
539
|
);
|
|
518
540
|
}
|
|
519
541
|
}
|
|
520
|
-
button(t, e, o,
|
|
521
|
-
const
|
|
522
|
-
return
|
|
542
|
+
button(t, e, o, i) {
|
|
543
|
+
const n = document.createElement("button");
|
|
544
|
+
return n.type = "button", n.className = "oa-toolbar-button", n.dataset.tooltip = o, n.setAttribute("aria-label", o), t && n.setAttribute("aria-pressed", "false"), n.innerHTML = v(e, 16), n.addEventListener("click", i), t && (n.dataset.mode = t), n;
|
|
523
545
|
}
|
|
524
546
|
separator() {
|
|
525
547
|
const t = document.createElement("span");
|
|
526
548
|
return t.className = "oa-toolbar-separator", t;
|
|
527
549
|
}
|
|
528
550
|
setActiveMode(t) {
|
|
529
|
-
this.activeButton && this.activeButton.classList.remove("active"), this.activeButton = t ? this.root.querySelector(`[data-mode="${t}"]`) : null, this.activeButton && this.activeButton.classList.add("active");
|
|
551
|
+
this.activeButton && (this.activeButton.classList.remove("active"), this.activeButton.setAttribute("aria-pressed", "false")), this.activeButton = t ? this.root.querySelector(`[data-mode="${t}"]`) : null, this.activeButton && (this.activeButton.classList.add("active"), this.activeButton.setAttribute("aria-pressed", "true"));
|
|
530
552
|
}
|
|
531
553
|
updateUndoRedo() {
|
|
532
554
|
this.undoButton.disabled = !this.control.canUndo(), this.redoButton.disabled = !this.control.canRedo();
|
|
@@ -539,16 +561,16 @@ class Ct {
|
|
|
539
561
|
this.root.dataset.orientation = t;
|
|
540
562
|
}
|
|
541
563
|
destroy() {
|
|
542
|
-
this.control.off(x, this.handleDrawingEnd), this.control.off(
|
|
564
|
+
this.control.off(x, this.handleDrawingEnd), this.control.off(P, this.handleDrawingEnd), this.control.off(M, this.handleHistory), this.root.remove();
|
|
543
565
|
}
|
|
544
566
|
}
|
|
545
|
-
class
|
|
567
|
+
class lt {
|
|
546
568
|
constructor(t, e) {
|
|
547
|
-
|
|
548
|
-
|
|
569
|
+
c(this, "element");
|
|
570
|
+
c(this, "onClick", () => {
|
|
549
571
|
this.item.action(this.ctx);
|
|
550
572
|
});
|
|
551
|
-
this.ctx = t, this.item = e, this.element = document.createElement("button"), this.element.type = "button", this.element.className = e.danger ? "oa-toolbar-button oa-toolbar-button-danger" : "oa-toolbar-button", this.element.dataset.tooltip = e.title, this.element.innerHTML =
|
|
573
|
+
this.ctx = t, this.item = e, this.element = document.createElement("button"), this.element.type = "button", this.element.className = e.danger ? "oa-toolbar-button oa-toolbar-button-danger" : "oa-toolbar-button", this.element.dataset.tooltip = e.title, this.element.setAttribute("aria-label", e.title), this.element.innerHTML = v(e.icon, 16), this.element.addEventListener("click", this.onClick);
|
|
552
574
|
}
|
|
553
575
|
update(t) {
|
|
554
576
|
if (!this.item.isActive) return;
|
|
@@ -559,48 +581,57 @@ class at {
|
|
|
559
581
|
this.element.removeEventListener("click", this.onClick);
|
|
560
582
|
}
|
|
561
583
|
}
|
|
562
|
-
function I(
|
|
584
|
+
function I(s, t) {
|
|
563
585
|
const e = document.createElement("div");
|
|
564
586
|
e.className = "oa-toolbar-dropdown";
|
|
565
587
|
const o = document.createElement("button");
|
|
566
|
-
o.type = "button", o.className = "oa-toolbar-button oa-toolbar-dropdown-trigger", o.dataset.tooltip =
|
|
588
|
+
o.type = "button", o.className = "oa-toolbar-button oa-toolbar-dropdown-trigger", o.dataset.tooltip = s, o.setAttribute("aria-haspopup", "listbox"), o.setAttribute("aria-expanded", "false"), o.setAttribute("aria-label", s);
|
|
589
|
+
const i = document.createElement("span");
|
|
590
|
+
i.className = "oa-toolbar-dropdown-label", i.textContent = t;
|
|
567
591
|
const n = document.createElement("span");
|
|
568
|
-
n.className = "oa-toolbar-dropdown-
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
return o.addEventListener("click", (
|
|
575
|
-
var
|
|
576
|
-
|
|
577
|
-
const
|
|
578
|
-
(
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
592
|
+
n.className = "oa-toolbar-dropdown-chevron", n.innerHTML = v("chevron-down", 14), o.appendChild(i), o.appendChild(n);
|
|
593
|
+
const r = document.createElement("div");
|
|
594
|
+
r.className = "oa-toolbar-dropdown-panel", r.setAttribute("role", "listbox"), r.setAttribute("aria-label", `${s} options`);
|
|
595
|
+
const d = (a) => o.setAttribute("aria-expanded", String(a)), h = () => {
|
|
596
|
+
e.classList.remove("open"), d(!1);
|
|
597
|
+
};
|
|
598
|
+
return o.addEventListener("click", (a) => {
|
|
599
|
+
var u;
|
|
600
|
+
a.stopPropagation();
|
|
601
|
+
const l = !e.classList.contains("open");
|
|
602
|
+
(u = e.closest(".annotation-style-toolbar")) == null || u.querySelectorAll(".oa-toolbar-dropdown.open").forEach((m) => {
|
|
603
|
+
var b;
|
|
604
|
+
m !== e && (m.classList.remove("open"), (b = m.querySelector(".oa-toolbar-dropdown-trigger")) == null || b.setAttribute("aria-expanded", "false"));
|
|
605
|
+
}), e.classList.toggle("open", l), d(l);
|
|
606
|
+
}), e.appendChild(o), e.appendChild(r), {
|
|
582
607
|
element: e,
|
|
583
|
-
panel:
|
|
584
|
-
close:
|
|
585
|
-
setLabel: (
|
|
586
|
-
|
|
608
|
+
panel: r,
|
|
609
|
+
close: h,
|
|
610
|
+
setLabel: (a) => {
|
|
611
|
+
i.textContent = a, o.setAttribute("aria-label", `${s}: ${a || t}`);
|
|
587
612
|
}
|
|
588
613
|
};
|
|
589
614
|
}
|
|
590
615
|
class ct {
|
|
591
616
|
constructor(t, e) {
|
|
592
|
-
|
|
593
|
-
|
|
617
|
+
c(this, "element");
|
|
618
|
+
c(this, "dropdown");
|
|
619
|
+
c(this, "optionElements", []);
|
|
594
620
|
this.ctx = t, this.item = e, this.dropdown = I(e.title, ""), this.element = this.dropdown.element, e.options.forEach((o) => {
|
|
595
|
-
const
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
}), this.dropdown.panel.appendChild(
|
|
621
|
+
const i = document.createElement("button");
|
|
622
|
+
i.type = "button", i.className = "oa-toolbar-dropdown-option", i.setAttribute("role", "option"), i.setAttribute("aria-selected", "false"), i.textContent = o.label, o.style && Object.assign(i.style, o.style), i.addEventListener("click", (n) => {
|
|
623
|
+
n.stopPropagation(), e.onSelect(o.value, this.ctx), this.dropdown.close();
|
|
624
|
+
}), this.dropdown.panel.appendChild(i), this.optionElements.push(i);
|
|
599
625
|
});
|
|
600
626
|
}
|
|
601
627
|
update(t) {
|
|
602
|
-
const e = this.item.getValue(t), o = this.item.options.find((
|
|
603
|
-
this.dropdown.setLabel(
|
|
628
|
+
const e = this.item.getValue(t), o = this.item.options.find((n) => n.value === e), i = this.item.getLabel ? this.item.getLabel(e, t) : (o == null ? void 0 : o.label) ?? `${e}`;
|
|
629
|
+
this.dropdown.setLabel(i), this.element.title = (o == null ? void 0 : o.label) ?? `${e}`, this.optionElements.forEach((n, r) => {
|
|
630
|
+
n.setAttribute(
|
|
631
|
+
"aria-selected",
|
|
632
|
+
String(this.item.options[r].value === e)
|
|
633
|
+
);
|
|
634
|
+
});
|
|
604
635
|
}
|
|
605
636
|
destroy() {
|
|
606
637
|
}
|
|
@@ -608,11 +639,11 @@ class ct {
|
|
|
608
639
|
const dt = 12;
|
|
609
640
|
class ht {
|
|
610
641
|
constructor(t, e) {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
642
|
+
c(this, "control");
|
|
643
|
+
c(this, "ogma");
|
|
644
|
+
c(this, "options");
|
|
645
|
+
c(this, "annotationId");
|
|
646
|
+
c(this, "overlay");
|
|
616
647
|
/** The element handed to `addOverlay` - Ogma writes its own
|
|
617
648
|
* `style.transform` (translate/rotate/scale, recomputed on every
|
|
618
649
|
* viewChanged/zoom/rotate/move) directly onto this node to place it at
|
|
@@ -620,28 +651,28 @@ class ht {
|
|
|
620
651
|
* assignment clobbers it (inline style, last writer wins - there's no way
|
|
621
652
|
* to compose two separate `transform` writers on one element). Zero-size
|
|
622
653
|
* and otherwise unstyled; it exists purely as the anchor point. */
|
|
623
|
-
|
|
654
|
+
c(this, "anchor");
|
|
624
655
|
/** The actual visible pill - a child of `anchor`, `position: absolute`
|
|
625
656
|
* with its own `transform: translate(-50%, -100%)` (see `styles.css`) to
|
|
626
657
|
* center horizontally and sit fully above the anchor point. This is where
|
|
627
658
|
* our own positioning lives, kept off `anchor` for exactly that reason. */
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
659
|
+
c(this, "root");
|
|
660
|
+
c(this, "cells", []);
|
|
661
|
+
c(this, "documentClickHandler", (t) => {
|
|
631
662
|
this.root.contains(t.target) || this.root.querySelectorAll(".oa-toolbar-dropdown.open").forEach((e) => e.classList.remove("open"));
|
|
632
663
|
});
|
|
633
|
-
this.control = t.control, this.options = t, this.ogma = this.control.getOgma(), this.annotationId = e.id, this.anchor = document.createElement("div"), this.anchor.className = "annotation-style-toolbar-anchor", this.root = document.createElement("div"), this.root.className = "annotation-style-toolbar oa-toolbar oa-toolbar-bar", this.anchor.appendChild(this.root), ["click", "mousedown", "mousemove"].forEach(
|
|
634
|
-
(
|
|
664
|
+
this.control = t.control, this.options = t, this.ogma = this.control.getOgma(), this.annotationId = e.id, this.anchor = document.createElement("div"), this.anchor.className = "annotation-style-toolbar-anchor", this.root = document.createElement("div"), this.root.className = "annotation-style-toolbar oa-toolbar oa-toolbar-bar", this.root.setAttribute("role", "group"), this.root.setAttribute("aria-label", "Text style toolbar"), this.anchor.appendChild(this.root), ["click", "mousedown", "mousemove"].forEach(
|
|
665
|
+
(i) => this.root.addEventListener(i, (n) => n.stopPropagation())
|
|
635
666
|
);
|
|
636
667
|
const o = {
|
|
637
668
|
getAnnotation: () => this.control.getAnnotation(this.annotationId),
|
|
638
|
-
updateStyle: (
|
|
669
|
+
updateStyle: (i) => this.control.updateStyle(this.annotationId, i),
|
|
639
670
|
deleteAnnotation: () => {
|
|
640
|
-
const
|
|
641
|
-
|
|
671
|
+
const i = this.control.getAnnotation(this.annotationId);
|
|
672
|
+
i && this.control.remove(i);
|
|
642
673
|
}
|
|
643
674
|
};
|
|
644
|
-
this.setItems(this.getItems(o), o), this.cells.forEach((
|
|
675
|
+
this.setItems(this.getItems(o), o), this.cells.forEach((i) => i.update(e)), this.overlay = this.ogma.layers.addOverlay({
|
|
645
676
|
element: this.anchor,
|
|
646
677
|
position: this.getAnchor(e),
|
|
647
678
|
scaled: !1
|
|
@@ -658,7 +689,7 @@ class ht {
|
|
|
658
689
|
case "custom":
|
|
659
690
|
return t.build(e);
|
|
660
691
|
case "button":
|
|
661
|
-
return new
|
|
692
|
+
return new lt(e, t);
|
|
662
693
|
case "dropdown":
|
|
663
694
|
return new ct(e, t);
|
|
664
695
|
}
|
|
@@ -666,12 +697,12 @@ class ht {
|
|
|
666
697
|
setItems(t, e) {
|
|
667
698
|
this.cells = [], t.forEach((o) => {
|
|
668
699
|
if (o.kind === "separator") {
|
|
669
|
-
const
|
|
670
|
-
|
|
700
|
+
const n = document.createElement("span");
|
|
701
|
+
n.className = "oa-toolbar-separator", this.root.appendChild(n);
|
|
671
702
|
return;
|
|
672
703
|
}
|
|
673
|
-
const
|
|
674
|
-
this.cells.push(
|
|
704
|
+
const i = this.buildCell(o, e);
|
|
705
|
+
this.cells.push(i), this.root.appendChild(i.element);
|
|
675
706
|
});
|
|
676
707
|
}
|
|
677
708
|
/**
|
|
@@ -683,13 +714,13 @@ class ht {
|
|
|
683
714
|
*/
|
|
684
715
|
getAnchor(t) {
|
|
685
716
|
var l;
|
|
686
|
-
const e = this.control.getZoom(), o = this.control.getRotation(),
|
|
687
|
-
let { height:
|
|
688
|
-
|
|
689
|
-
const
|
|
717
|
+
const e = this.control.getZoom(), o = this.control.getRotation(), i = ((l = t.properties.style) == null ? void 0 : l.fixedSize) === !0;
|
|
718
|
+
let { height: n } = q(t);
|
|
719
|
+
i && (n /= e);
|
|
720
|
+
const r = W(t), d = -(n / 2 + dt / e), h = Math.sin(o), a = Math.cos(o);
|
|
690
721
|
return {
|
|
691
|
-
x:
|
|
692
|
-
y:
|
|
722
|
+
x: r.x - d * h,
|
|
723
|
+
y: r.y + d * a
|
|
693
724
|
};
|
|
694
725
|
}
|
|
695
726
|
/** Refreshes every cell and repositions the pill for `annotation` -
|
|
@@ -703,25 +734,28 @@ class ht {
|
|
|
703
734
|
document.removeEventListener("click", this.documentClickHandler), this.cells.forEach((t) => t.destroy()), this.overlay.destroy();
|
|
704
735
|
}
|
|
705
736
|
}
|
|
706
|
-
class
|
|
737
|
+
class ut {
|
|
707
738
|
constructor(t, e) {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
739
|
+
c(this, "element");
|
|
740
|
+
c(this, "dropdown");
|
|
741
|
+
c(this, "swatch");
|
|
742
|
+
c(this, "more");
|
|
743
|
+
c(this, "morePicker", null);
|
|
744
|
+
c(this, "morePickerHost", null);
|
|
714
745
|
this.ctx = t, this.options = e;
|
|
715
746
|
const { swatches: o } = e;
|
|
716
747
|
this.dropdown = I("Color", ""), this.element = this.dropdown.element, this.element.classList.add("oa-toolbar-color-cell"), this.swatch = document.createElement("span"), this.swatch.className = "oa-toolbar-swatch", this.dropdown.element.querySelector(".oa-toolbar-dropdown-trigger").insertBefore(this.swatch, this.dropdown.element.querySelector(".oa-toolbar-dropdown-label"));
|
|
717
|
-
const
|
|
718
|
-
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
748
|
+
const i = document.createElement("div");
|
|
749
|
+
i.className = "oa-toolbar-swatch-grid", o.forEach((n) => {
|
|
750
|
+
const r = document.createElement("button");
|
|
751
|
+
r.type = "button", r.className = "oa-toolbar-swatch-cell", r.classList.toggle("oa-toolbar-swatch-cell-transparent", n.fill === "transparent"), r.title = n.fill, r.setAttribute(
|
|
752
|
+
"aria-label",
|
|
753
|
+
n.fill === "transparent" ? "No background" : `Background ${n.fill}`
|
|
754
|
+
), r.style.setProperty("--oa-swatch-fill", n.fill), r.style.setProperty("--oa-swatch-stroke", n.stroke), r.addEventListener("click", (d) => {
|
|
755
|
+
d.stopPropagation(), this.pick(n.fill), this.dropdown.close();
|
|
756
|
+
}), i.appendChild(r);
|
|
757
|
+
}), this.dropdown.panel.appendChild(i), this.more = document.createElement("button"), this.more.type = "button", this.more.className = "oa-toolbar-more-colors", this.more.textContent = "More colors…", this.more.addEventListener("click", (n) => {
|
|
758
|
+
n.stopPropagation(), this.openMorePicker();
|
|
725
759
|
}), this.dropdown.panel.appendChild(this.more);
|
|
726
760
|
}
|
|
727
761
|
pick(t) {
|
|
@@ -738,9 +772,9 @@ class pt {
|
|
|
738
772
|
return;
|
|
739
773
|
}
|
|
740
774
|
this.morePickerHost = document.createElement("div"), this.morePickerHost.className = "oa-toolbar-more-colors-host", this.morePicker = N();
|
|
741
|
-
const t = ((e = this.ctx.getAnnotation().properties.style) == null ? void 0 : e.background) ||
|
|
775
|
+
const t = ((e = this.ctx.getAnnotation().properties.style) == null ? void 0 : e.background) || y.background;
|
|
742
776
|
this.morePicker.color = F(t), this.morePicker.addEventListener("color-changed", (o) => {
|
|
743
|
-
this.pick(
|
|
777
|
+
this.pick(O(o.detail.value));
|
|
744
778
|
}), this.morePickerHost.appendChild(this.morePicker), this.dropdown.panel.appendChild(this.morePickerHost);
|
|
745
779
|
}
|
|
746
780
|
closeMorePicker() {
|
|
@@ -749,14 +783,14 @@ class pt {
|
|
|
749
783
|
}
|
|
750
784
|
update(t) {
|
|
751
785
|
var o;
|
|
752
|
-
const e = ((o = t.properties.style) == null ? void 0 : o.background) ||
|
|
786
|
+
const e = ((o = t.properties.style) == null ? void 0 : o.background) || y.background;
|
|
753
787
|
this.swatch.style.setProperty("--oa-swatch-fill", e), this.swatch.classList.toggle("oa-toolbar-swatch-transparent", e === "transparent");
|
|
754
788
|
}
|
|
755
789
|
destroy() {
|
|
756
790
|
this.closeMorePicker();
|
|
757
791
|
}
|
|
758
792
|
}
|
|
759
|
-
const
|
|
793
|
+
const pt = [
|
|
760
794
|
{ fill: "#FFE49B", stroke: "#D9A926" },
|
|
761
795
|
{ fill: "#FFC8A7", stroke: "#CC8C66" },
|
|
762
796
|
{ fill: "#FFA7B5", stroke: "#C2707D" },
|
|
@@ -780,15 +814,15 @@ const ut = [
|
|
|
780
814
|
label: "IBM Plex Mono",
|
|
781
815
|
style: { fontFamily: "IBM Plex Mono" }
|
|
782
816
|
}
|
|
783
|
-
],
|
|
817
|
+
], bt = [12, 14, 16, 18, 24, 32, 48, 64];
|
|
784
818
|
class H extends ht {
|
|
785
819
|
getItems(t) {
|
|
786
820
|
var d, h;
|
|
787
|
-
const e = this.options.fonts ?? mt, o = this.options.fontSizes ??
|
|
821
|
+
const e = this.options.fonts ?? mt, o = this.options.fontSizes ?? bt, i = this.options.swatches ?? pt, n = this.options.onMoreColors, r = [
|
|
788
822
|
{
|
|
789
823
|
kind: "custom",
|
|
790
824
|
id: "color",
|
|
791
|
-
build: (
|
|
825
|
+
build: (a) => new ut(a, { swatches: i, onMoreColors: n })
|
|
792
826
|
},
|
|
793
827
|
{ kind: "separator" },
|
|
794
828
|
{
|
|
@@ -796,33 +830,33 @@ class H extends ht {
|
|
|
796
830
|
id: "font",
|
|
797
831
|
title: "Font",
|
|
798
832
|
options: e,
|
|
799
|
-
getValue: (
|
|
833
|
+
getValue: (a) => {
|
|
800
834
|
var l;
|
|
801
|
-
return ((l =
|
|
835
|
+
return ((l = a.properties.style) == null ? void 0 : l.font) || y.font;
|
|
802
836
|
},
|
|
803
837
|
getLabel: () => "Aa",
|
|
804
838
|
// `fonts` entries are always string values (font-family names) -
|
|
805
839
|
// ToolbarDropdownValue is string | number only because the size
|
|
806
840
|
// cell also uses this same item shape with numbers.
|
|
807
|
-
onSelect: (
|
|
841
|
+
onSelect: (a, l) => l.updateStyle({ font: `${a}` })
|
|
808
842
|
},
|
|
809
843
|
{
|
|
810
844
|
kind: "dropdown",
|
|
811
845
|
id: "fontSize",
|
|
812
846
|
title: "Font size",
|
|
813
|
-
options: o.map((
|
|
814
|
-
getValue: (
|
|
815
|
-
const l =
|
|
847
|
+
options: o.map((a) => ({ value: a, label: `${a}` })),
|
|
848
|
+
getValue: (a) => {
|
|
849
|
+
const l = a.properties.style;
|
|
816
850
|
return Math.round(
|
|
817
|
-
|
|
818
|
-
(l == null ? void 0 : l.fontSize) ??
|
|
851
|
+
V(
|
|
852
|
+
(l == null ? void 0 : l.fontSize) ?? y.fontSize,
|
|
819
853
|
l == null ? void 0 : l.fontScale
|
|
820
854
|
)
|
|
821
855
|
);
|
|
822
856
|
},
|
|
823
857
|
// Setting fontSize directly (not fontScale) resets any accumulated
|
|
824
858
|
// resize-driven scale, matching what picking an explicit size means.
|
|
825
|
-
onSelect: (
|
|
859
|
+
onSelect: (a, l) => l.updateStyle({ fontSize: a, fontScale: 1 })
|
|
826
860
|
},
|
|
827
861
|
{ kind: "separator" },
|
|
828
862
|
{
|
|
@@ -830,14 +864,14 @@ class H extends ht {
|
|
|
830
864
|
id: "bold",
|
|
831
865
|
title: "Bold",
|
|
832
866
|
icon: "bold",
|
|
833
|
-
isActive: (
|
|
867
|
+
isActive: (a) => {
|
|
834
868
|
var l;
|
|
835
|
-
return ((l =
|
|
869
|
+
return ((l = a.properties.style) == null ? void 0 : l.fontWeight) === "bold";
|
|
836
870
|
},
|
|
837
|
-
action: (
|
|
871
|
+
action: (a) => {
|
|
838
872
|
var u;
|
|
839
|
-
const l = ((u =
|
|
840
|
-
|
|
873
|
+
const l = ((u = a.getAnnotation().properties.style) == null ? void 0 : u.fontWeight) === "bold";
|
|
874
|
+
a.updateStyle({ fontWeight: l ? "normal" : "bold" });
|
|
841
875
|
}
|
|
842
876
|
},
|
|
843
877
|
{ kind: "separator" },
|
|
@@ -846,14 +880,14 @@ class H extends ht {
|
|
|
846
880
|
id: "showAuthor",
|
|
847
881
|
title: "Show author",
|
|
848
882
|
icon: "user",
|
|
849
|
-
isActive: (
|
|
883
|
+
isActive: (a) => {
|
|
850
884
|
var l;
|
|
851
|
-
return ((l =
|
|
885
|
+
return ((l = a.properties.style) == null ? void 0 : l.showAuthor) === !0;
|
|
852
886
|
},
|
|
853
|
-
action: (
|
|
887
|
+
action: (a) => {
|
|
854
888
|
var u;
|
|
855
|
-
const l = ((u =
|
|
856
|
-
|
|
889
|
+
const l = ((u = a.getAnnotation().properties.style) == null ? void 0 : u.showAuthor) === !0;
|
|
890
|
+
a.updateStyle({ showAuthor: !l });
|
|
857
891
|
}
|
|
858
892
|
},
|
|
859
893
|
{ kind: "separator" },
|
|
@@ -863,35 +897,35 @@ class H extends ht {
|
|
|
863
897
|
title: "Delete",
|
|
864
898
|
icon: "trash",
|
|
865
899
|
danger: !0,
|
|
866
|
-
action: (
|
|
900
|
+
action: (a) => a.deleteAnnotation()
|
|
867
901
|
}
|
|
868
902
|
];
|
|
869
|
-
return ((h = (d = this.options).items) == null ? void 0 : h.call(d,
|
|
903
|
+
return ((h = (d = this.options).items) == null ? void 0 : h.call(d, r, t)) ?? r;
|
|
870
904
|
}
|
|
871
905
|
}
|
|
872
|
-
class
|
|
906
|
+
class yt extends H {
|
|
873
907
|
}
|
|
874
|
-
class
|
|
908
|
+
class Ct {
|
|
875
909
|
constructor(t) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
this.current && t.id === this.current.annotationId &&
|
|
910
|
+
c(this, "control");
|
|
911
|
+
c(this, "options");
|
|
912
|
+
c(this, "current", null);
|
|
913
|
+
c(this, "detachVisibility");
|
|
914
|
+
c(this, "handleUpdate", (t) => {
|
|
915
|
+
this.current && t.id === this.current.annotationId && k(t) && this.current.update(t);
|
|
882
916
|
});
|
|
883
|
-
this.control = t.control, this.options = t, this.detachVisibility =
|
|
917
|
+
this.control = t.control, this.options = t, this.detachVisibility = D(this.control, {
|
|
884
918
|
onShow: (e) => this.show(e),
|
|
885
919
|
onHide: () => this.hide(),
|
|
886
920
|
hideWhenNotEditable: t.hideWhenNotEditable
|
|
887
|
-
}), this.control.on(
|
|
921
|
+
}), this.control.on($, this.handleUpdate);
|
|
888
922
|
}
|
|
889
923
|
show(t) {
|
|
890
|
-
if (!
|
|
924
|
+
if (!k(t)) {
|
|
891
925
|
this.hide();
|
|
892
926
|
return;
|
|
893
927
|
}
|
|
894
|
-
const e = U(t) ?
|
|
928
|
+
const e = U(t) ? yt : H;
|
|
895
929
|
if (this.current && this.current.annotationId === t.id && this.current instanceof e) {
|
|
896
930
|
this.current.update(t);
|
|
897
931
|
return;
|
|
@@ -903,37 +937,37 @@ class wt {
|
|
|
903
937
|
(t = this.current) == null || t.destroy(), this.current = null;
|
|
904
938
|
}
|
|
905
939
|
destroy() {
|
|
906
|
-
this.detachVisibility(), this.control.off(
|
|
940
|
+
this.detachVisibility(), this.control.off($, this.handleUpdate), this.hide();
|
|
907
941
|
}
|
|
908
942
|
}
|
|
909
943
|
export {
|
|
910
|
-
|
|
944
|
+
nt as ALL_PANEL_ANNOTATION_TYPES,
|
|
911
945
|
kt as AnnotationPanel,
|
|
912
946
|
ht as AnnotationStyleToolbar,
|
|
913
|
-
|
|
947
|
+
At as AnnotationToolbar,
|
|
914
948
|
j as BACKGROUNDS,
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
949
|
+
lt as ButtonItemCell,
|
|
950
|
+
ut as ColorCell,
|
|
951
|
+
it as DEFAULT_PANEL_ORIENTATION,
|
|
918
952
|
ot as DEFAULT_PANEL_PLACEMENT,
|
|
919
953
|
J as DEFAULT_RECENT_COLORS,
|
|
920
954
|
mt as DEFAULT_TOOLBAR_FONTS,
|
|
921
|
-
|
|
955
|
+
bt as DEFAULT_TOOLBAR_FONT_SIZES,
|
|
922
956
|
ct as DropdownItemCell,
|
|
923
957
|
G as EXTREMITY_OPTIONS,
|
|
924
958
|
C as FONTS,
|
|
925
959
|
tt as ICON_PATHS,
|
|
926
960
|
X as LINE_TYPES,
|
|
927
961
|
K as MAX_RECENT_COLORS,
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
962
|
+
pt as STICKY_SWATCHES,
|
|
963
|
+
yt as StickyNoteStyleToolbar,
|
|
964
|
+
Ct as TextAnnotationToolbar,
|
|
931
965
|
H as TextStyleToolbar,
|
|
932
|
-
|
|
933
|
-
|
|
966
|
+
D as attachPanelVisibility,
|
|
967
|
+
rt as classifyPanelAnnotationType,
|
|
934
968
|
N as createRgbaColorPicker,
|
|
935
969
|
Z as initialRecentColors,
|
|
936
|
-
|
|
937
|
-
|
|
970
|
+
O as rgbaToString,
|
|
971
|
+
v as svgIcon,
|
|
938
972
|
Q as withColorFromAnnotation
|
|
939
973
|
};
|