@annotorious/react 3.0.22 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
- import { useState as c, useRef as n, useEffect as s } from "react";
2
- const m = (e, t) => {
3
- const [u, o] = c(e), r = n();
4
- return s(() => (r.current = setTimeout(() => o(e), t), () => {
5
- clearTimeout(r.current);
6
- }), [e, t]), u;
1
+ import { useState as o, useRef as c, useEffect as s } from "react";
2
+ const i = (e, t) => {
3
+ const [r, n] = o(e), u = c(void 0);
4
+ return s(() => (u.current = setTimeout(() => n(e), t), () => {
5
+ clearTimeout(u.current);
6
+ }), [e, t]), r;
7
7
  };
8
8
  export {
9
- m as useDebounce
9
+ i as useDebounce
10
10
  };
11
11
  //# sourceMappingURL=annotorious-react.es12.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotorious-react.es12.js","sources":["../src/useDebounce.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nexport const useDebounce = (value: any, delay: number) => {\n const [debouncedValue, setDebouncedValue] = useState<any>(value);\n\n const timerRef = useRef<ReturnType<typeof setTimeout>>();\n\n useEffect(() => {\n timerRef.current = \n setTimeout(() => setDebouncedValue(value), delay);\n\n return () => {\n clearTimeout(timerRef.current);\n };\n }, [value, delay]);\n\n return debouncedValue;\n}"],"names":["useDebounce","value","delay","debouncedValue","setDebouncedValue","useState","timerRef","useRef","useEffect"],"mappings":";AAEa,MAAAA,IAAc,CAACC,GAAYC,MAAkB;AACxD,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAcJ,CAAK,GAEzDK,IAAWC,EAAsC;AAEvD,SAAAC,EAAU,OACRF,EAAS,UACP,WAAW,MAAMF,EAAkBH,CAAK,GAAGC,CAAK,GAE3C,MAAM;AACX,iBAAaI,EAAS,OAAO;AAAA,EAC/B,IACC,CAACL,GAAOC,CAAK,CAAC,GAEVC;AACT;"}
1
+ {"version":3,"file":"annotorious-react.es12.js","sources":["../src/useDebounce.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nexport const useDebounce = (value: any, delay: number) => {\n const [debouncedValue, setDebouncedValue] = useState<any>(value);\n\n const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined);\n\n useEffect(() => {\n timerRef.current = \n setTimeout(() => setDebouncedValue(value), delay);\n\n return () => {\n clearTimeout(timerRef.current);\n };\n }, [value, delay]);\n\n return debouncedValue;\n}"],"names":["useDebounce","value","delay","debouncedValue","setDebouncedValue","useState","timerRef","useRef","useEffect"],"mappings":";AAEa,MAAAA,IAAc,CAACC,GAAYC,MAAkB;AACxD,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAAcJ,CAAK,GAEzDK,IAAWC,EAAsC,MAAS;AAEhE,SAAAC,EAAU,OACRF,EAAS,UACP,WAAW,MAAMF,EAAkBH,CAAK,GAAGC,CAAK,GAE3C,MAAM;AACX,iBAAaI,EAAS,OAAO;AAAA,EAC/B,IACC,CAACL,GAAOC,CAAK,CAAC,GAEVC;AACT;"}
@@ -1,275 +1,269 @@
1
- import * as o from "react";
2
- import { useLayoutEffect as q, useEffect as Q } from "react";
3
- import { getComputedStyle as Z, isElement as I } from "./annotorious-react.es21.js";
4
- import { getOverflowAncestors as Re } from "./annotorious-react.es21.js";
1
+ import * as s from "react";
2
+ import { useLayoutEffect as k, useEffect as q } from "react";
3
+ import { j as F } from "./annotorious-react.es11.js";
4
+ import { getComputedStyle as Q, isElement as P } from "./annotorious-react.es21.js";
5
+ import { getOverflowAncestors as xe } from "./annotorious-react.es21.js";
5
6
  import "react-dom";
6
- import { useFloating as z } from "./annotorious-react.es15.js";
7
- import { arrow as Ee, flip as ve, inline as we, offset as Ce, shift as Se } from "./annotorious-react.es15.js";
7
+ import { useFloating as Z } from "./annotorious-react.es15.js";
8
+ import { arrow as ve, flip as we, inline as Ee, offset as Se, shift as Ie } from "./annotorious-react.es15.js";
8
9
  const $ = {
9
- ...o
10
- }, G = $.useInsertionEffect, J = G || ((t) => t());
11
- function K(t) {
12
- const n = o.useRef(() => {
10
+ ...s
11
+ }, z = $.useInsertionEffect, G = z || ((t) => t());
12
+ function J(t) {
13
+ const n = s.useRef(() => {
13
14
  if (process.env.NODE_ENV !== "production")
14
15
  throw new Error("Cannot call an event handler while rendering.");
15
16
  });
16
- return J(() => {
17
+ return G(() => {
17
18
  n.current = t;
18
- }), o.useCallback(function() {
19
- for (var s = arguments.length, e = new Array(s), r = 0; r < s; r++)
20
- e[r] = arguments[r];
19
+ }), s.useCallback(function() {
20
+ for (var c = arguments.length, e = new Array(c), o = 0; o < c; o++)
21
+ e[o] = arguments[o];
21
22
  return n.current == null ? void 0 : n.current(...e);
22
23
  }, []);
23
24
  }
24
- var b = typeof document < "u" ? q : Q;
25
- function D() {
26
- return D = Object.assign ? Object.assign.bind() : function(t) {
27
- for (var n = 1; n < arguments.length; n++) {
28
- var s = arguments[n];
29
- for (var e in s)
30
- Object.prototype.hasOwnProperty.call(s, e) && (t[e] = s[e]);
31
- }
32
- return t;
33
- }, D.apply(this, arguments);
34
- }
35
- let V = !1, k = 0;
25
+ var M = typeof document < "u" ? k : q;
26
+ let y = !1, K = 0;
36
27
  const W = () => (
37
28
  // Ensure the id is unique with multiple independent versions of Floating UI
38
29
  // on <React 18
39
- "floating-ui-" + Math.random().toString(36).slice(2, 6) + k++
30
+ "floating-ui-" + Math.random().toString(36).slice(2, 6) + K++
40
31
  );
41
32
  function _() {
42
- const [t, n] = o.useState(() => V ? W() : void 0);
43
- return b(() => {
33
+ const [t, n] = s.useState(() => y ? W() : void 0);
34
+ return M(() => {
44
35
  t == null && n(W());
45
- }, []), o.useEffect(() => {
46
- V = !0;
36
+ }, []), s.useEffect(() => {
37
+ y = !0;
47
38
  }, []), t;
48
39
  }
49
40
  const ee = $.useId, B = ee || _;
50
- let P;
51
- process.env.NODE_ENV !== "production" && (P = /* @__PURE__ */ new Set());
41
+ let O;
42
+ process.env.NODE_ENV !== "production" && (O = /* @__PURE__ */ new Set());
52
43
  function te() {
53
- for (var t, n = arguments.length, s = new Array(n), e = 0; e < n; e++)
54
- s[e] = arguments[e];
55
- const r = "Floating UI: " + s.join(" ");
56
- if (!((t = P) != null && t.has(r))) {
57
- var l;
58
- (l = P) == null || l.add(r), console.warn(r);
44
+ for (var t, n = arguments.length, c = new Array(n), e = 0; e < n; e++)
45
+ c[e] = arguments[e];
46
+ const o = "Floating UI: " + c.join(" ");
47
+ if (!((t = O) != null && t.has(o))) {
48
+ var i;
49
+ (i = O) == null || i.add(o), console.warn(o);
59
50
  }
60
51
  }
61
52
  function ne() {
62
- for (var t, n = arguments.length, s = new Array(n), e = 0; e < n; e++)
63
- s[e] = arguments[e];
64
- const r = "Floating UI: " + s.join(" ");
65
- if (!((t = P) != null && t.has(r))) {
66
- var l;
67
- (l = P) == null || l.add(r), console.error(r);
53
+ for (var t, n = arguments.length, c = new Array(n), e = 0; e < n; e++)
54
+ c[e] = arguments[e];
55
+ const o = "Floating UI: " + c.join(" ");
56
+ if (!((t = O) != null && t.has(o))) {
57
+ var i;
58
+ (i = O) == null || i.add(o), console.error(o);
68
59
  }
69
60
  }
70
- const me = /* @__PURE__ */ o.forwardRef(function(n, s) {
61
+ const ge = /* @__PURE__ */ s.forwardRef(function(n, c) {
71
62
  const {
72
63
  context: {
73
64
  placement: e,
74
65
  elements: {
75
- floating: r
66
+ floating: o
76
67
  },
77
68
  middlewareData: {
78
- arrow: l,
79
- shift: u
69
+ arrow: i,
70
+ shift: a
80
71
  }
81
72
  },
82
- width: i = 14,
83
- height: a = 7,
84
- tipRadius: O = 0,
73
+ width: l = 14,
74
+ height: u = 7,
75
+ tipRadius: I = 0,
85
76
  strokeWidth: d = 0,
86
77
  staticOffset: g,
87
78
  stroke: h,
88
- d: c,
79
+ d: r,
89
80
  style: {
90
81
  transform: p,
91
82
  ...R
92
83
  } = {},
93
84
  ...x
94
85
  } = n;
95
- process.env.NODE_ENV !== "production" && (s || te("The `ref` prop is required for `FloatingArrow`."));
96
- const E = B(), [C, f] = o.useState(!1);
97
- if (b(() => {
98
- if (!r) return;
99
- Z(r).direction === "rtl" && f(!0);
100
- }, [r]), !r)
86
+ process.env.NODE_ENV !== "production" && (c || te("The `ref` prop is required for `FloatingArrow`."));
87
+ const C = B(), [E, f] = s.useState(!1);
88
+ if (M(() => {
89
+ if (!o) return;
90
+ Q(o).direction === "rtl" && f(!0);
91
+ }, [o]), !o)
101
92
  return null;
102
- const [m, F] = e.split("-"), M = m === "top" || m === "bottom";
93
+ const [m, b] = e.split("-"), j = m === "top" || m === "bottom";
103
94
  let S = g;
104
- (M && u != null && u.x || !M && u != null && u.y) && (S = null);
105
- const v = d * 2, N = v / 2, A = i / 2 * (O / -8 + 1), T = a / 2 * O / 4, w = !!c, U = S && F === "end" ? "bottom" : "top";
106
- let j = S && F === "end" ? "right" : "left";
107
- S && C && (j = F === "end" ? "left" : "right");
108
- const H = (l == null ? void 0 : l.x) != null ? S || l.x : "", X = (l == null ? void 0 : l.y) != null ? S || l.y : "", y = c || "M0,0" + (" H" + i) + (" L" + (i - A) + "," + (a - T)) + (" Q" + i / 2 + "," + a + " " + A + "," + (a - T)) + " Z", Y = {
95
+ (j && a != null && a.x || !j && a != null && a.y) && (S = null);
96
+ const v = d * 2, D = v / 2, N = l / 2 * (I / -8 + 1), A = u / 2 * I / 4, w = !!r, U = S && b === "end" ? "bottom" : "top";
97
+ let T = S && b === "end" ? "right" : "left";
98
+ S && E && (T = b === "end" ? "left" : "right");
99
+ const H = (i == null ? void 0 : i.x) != null ? S || i.x : "", X = (i == null ? void 0 : i.y) != null ? S || i.y : "", L = r || "M0,0" + (" H" + l) + (" L" + (l - N) + "," + (u - A)) + (" Q" + l / 2 + "," + u + " " + N + "," + (u - A)) + " Z", Y = {
109
100
  top: w ? "rotate(180deg)" : "",
110
101
  left: w ? "rotate(90deg)" : "rotate(-90deg)",
111
102
  bottom: w ? "" : "rotate(180deg)",
112
103
  right: w ? "rotate(-90deg)" : "rotate(90deg)"
113
104
  }[m];
114
- return /* @__PURE__ */ o.createElement("svg", D({}, x, {
105
+ return /* @__PURE__ */ F.jsxs("svg", {
106
+ ...x,
115
107
  "aria-hidden": !0,
116
- ref: s,
117
- width: w ? i : i + v,
118
- height: i,
119
- viewBox: "0 0 " + i + " " + (a > i ? a : i),
108
+ ref: c,
109
+ width: w ? l : l + v,
110
+ height: l,
111
+ viewBox: "0 0 " + l + " " + (u > l ? u : l),
120
112
  style: {
121
113
  position: "absolute",
122
114
  pointerEvents: "none",
123
- [j]: H,
115
+ [T]: H,
124
116
  [U]: X,
125
- [m]: M || w ? "100%" : "calc(100% - " + v / 2 + "px)",
126
- transform: [Y, p].filter((L) => !!L).join(" "),
117
+ [m]: j || w ? "100%" : "calc(100% - " + v / 2 + "px)",
118
+ transform: [Y, p].filter((V) => !!V).join(" "),
127
119
  ...R
128
- }
129
- }), v > 0 && /* @__PURE__ */ o.createElement("path", {
130
- clipPath: "url(#" + E + ")",
131
- fill: "none",
132
- stroke: h,
133
- strokeWidth: v + (c ? 0 : 1),
134
- d: y
135
- }), /* @__PURE__ */ o.createElement("path", {
136
- stroke: v && !c ? x.fill : "none",
137
- d: y
138
- }), /* @__PURE__ */ o.createElement("clipPath", {
139
- id: E
140
- }, /* @__PURE__ */ o.createElement("rect", {
141
- x: -N,
142
- y: N * (w ? -1 : 1),
143
- width: i + v,
144
- height: i
145
- })));
120
+ },
121
+ children: [v > 0 && /* @__PURE__ */ F.jsx("path", {
122
+ clipPath: "url(#" + C + ")",
123
+ fill: "none",
124
+ stroke: h,
125
+ strokeWidth: v + (r ? 0 : 1),
126
+ d: L
127
+ }), /* @__PURE__ */ F.jsx("path", {
128
+ stroke: v && !r ? x.fill : "none",
129
+ d: L
130
+ }), /* @__PURE__ */ F.jsx("clipPath", {
131
+ id: C,
132
+ children: /* @__PURE__ */ F.jsx("rect", {
133
+ x: -D,
134
+ y: D * (w ? -1 : 1),
135
+ width: l + v,
136
+ height: l
137
+ })
138
+ })]
139
+ });
146
140
  });
147
141
  function oe() {
148
142
  const t = /* @__PURE__ */ new Map();
149
143
  return {
150
- emit(n, s) {
144
+ emit(n, c) {
151
145
  var e;
152
- (e = t.get(n)) == null || e.forEach((r) => r(s));
146
+ (e = t.get(n)) == null || e.forEach((o) => o(c));
153
147
  },
154
- on(n, s) {
155
- t.set(n, [...t.get(n) || [], s]);
148
+ on(n, c) {
149
+ t.set(n, [...t.get(n) || [], c]);
156
150
  },
157
- off(n, s) {
151
+ off(n, c) {
158
152
  var e;
159
- t.set(n, ((e = t.get(n)) == null ? void 0 : e.filter((r) => r !== s)) || []);
153
+ t.set(n, ((e = t.get(n)) == null ? void 0 : e.filter((o) => o !== c)) || []);
160
154
  }
161
155
  };
162
156
  }
163
- const re = /* @__PURE__ */ o.createContext(null), se = /* @__PURE__ */ o.createContext(null), ce = () => {
157
+ const re = /* @__PURE__ */ s.createContext(null), se = /* @__PURE__ */ s.createContext(null), ce = () => {
164
158
  var t;
165
- return ((t = o.useContext(re)) == null ? void 0 : t.id) || null;
166
- }, le = () => o.useContext(se);
167
- function ie(t) {
159
+ return ((t = s.useContext(re)) == null ? void 0 : t.id) || null;
160
+ }, ie = () => s.useContext(se);
161
+ function le(t) {
168
162
  const {
169
163
  open: n = !1,
170
- onOpenChange: s,
164
+ onOpenChange: c,
171
165
  elements: e
172
- } = t, r = B(), l = o.useRef({}), [u] = o.useState(() => oe()), i = ce() != null;
166
+ } = t, o = B(), i = s.useRef({}), [a] = s.useState(() => oe()), l = ce() != null;
173
167
  if (process.env.NODE_ENV !== "production") {
174
- const c = e.reference;
175
- c && !I(c) && ne("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
168
+ const r = e.reference;
169
+ r && !P(r) && ne("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
176
170
  }
177
- const [a, O] = o.useState(e.reference), d = K((c, p, R) => {
178
- l.current.openEvent = c ? p : void 0, u.emit("openchange", {
179
- open: c,
171
+ const [u, I] = s.useState(e.reference), d = J((r, p, R) => {
172
+ i.current.openEvent = r ? p : void 0, a.emit("openchange", {
173
+ open: r,
180
174
  event: p,
181
175
  reason: R,
182
- nested: i
183
- }), s == null || s(c, p, R);
184
- }), g = o.useMemo(() => ({
185
- setPositionReference: O
186
- }), []), h = o.useMemo(() => ({
187
- reference: a || e.reference || null,
176
+ nested: l
177
+ }), c == null || c(r, p, R);
178
+ }), g = s.useMemo(() => ({
179
+ setPositionReference: I
180
+ }), []), h = s.useMemo(() => ({
181
+ reference: u || e.reference || null,
188
182
  floating: e.floating || null,
189
183
  domReference: e.reference
190
- }), [a, e.reference, e.floating]);
191
- return o.useMemo(() => ({
192
- dataRef: l,
184
+ }), [u, e.reference, e.floating]);
185
+ return s.useMemo(() => ({
186
+ dataRef: i,
193
187
  open: n,
194
188
  onOpenChange: d,
195
189
  elements: h,
196
- events: u,
197
- floatingId: r,
190
+ events: a,
191
+ floatingId: o,
198
192
  refs: g
199
- }), [n, d, h, u, r, g]);
193
+ }), [n, d, h, a, o, g]);
200
194
  }
201
- function ge(t) {
195
+ function pe(t) {
202
196
  t === void 0 && (t = {});
203
197
  const {
204
198
  nodeId: n
205
- } = t, s = ie({
199
+ } = t, c = le({
206
200
  ...t,
207
201
  elements: {
208
202
  reference: null,
209
203
  floating: null,
210
204
  ...t.elements
211
205
  }
212
- }), e = t.rootContext || s, r = e.elements, [l, u] = o.useState(null), [i, a] = o.useState(null), d = (r == null ? void 0 : r.domReference) || l, g = o.useRef(null), h = le();
213
- b(() => {
206
+ }), e = t.rootContext || c, o = e.elements, [i, a] = s.useState(null), [l, u] = s.useState(null), d = (o == null ? void 0 : o.domReference) || i, g = s.useRef(null), h = ie();
207
+ M(() => {
214
208
  d && (g.current = d);
215
209
  }, [d]);
216
- const c = z({
210
+ const r = Z({
217
211
  ...t,
218
212
  elements: {
219
- ...r,
220
- ...i && {
221
- reference: i
213
+ ...o,
214
+ ...l && {
215
+ reference: l
222
216
  }
223
217
  }
224
- }), p = o.useCallback((f) => {
225
- const m = I(f) ? {
218
+ }), p = s.useCallback((f) => {
219
+ const m = P(f) ? {
226
220
  getBoundingClientRect: () => f.getBoundingClientRect(),
227
221
  contextElement: f
228
222
  } : f;
229
- a(m), c.refs.setReference(m);
230
- }, [c.refs]), R = o.useCallback((f) => {
231
- (I(f) || f === null) && (g.current = f, u(f)), (I(c.refs.reference.current) || c.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
223
+ u(m), r.refs.setReference(m);
224
+ }, [r.refs]), R = s.useCallback((f) => {
225
+ (P(f) || f === null) && (g.current = f, a(f)), (P(r.refs.reference.current) || r.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
232
226
  // `null` to support `positionReference` + an unstable `reference`
233
227
  // callback ref.
234
- f !== null && !I(f)) && c.refs.setReference(f);
235
- }, [c.refs]), x = o.useMemo(() => ({
236
- ...c.refs,
228
+ f !== null && !P(f)) && r.refs.setReference(f);
229
+ }, [r.refs]), x = s.useMemo(() => ({
230
+ ...r.refs,
237
231
  setReference: R,
238
232
  setPositionReference: p,
239
233
  domReference: g
240
- }), [c.refs, R, p]), E = o.useMemo(() => ({
241
- ...c.elements,
234
+ }), [r.refs, R, p]), C = s.useMemo(() => ({
235
+ ...r.elements,
242
236
  domReference: d
243
- }), [c.elements, d]), C = o.useMemo(() => ({
244
- ...c,
237
+ }), [r.elements, d]), E = s.useMemo(() => ({
238
+ ...r,
245
239
  ...e,
246
240
  refs: x,
247
- elements: E,
241
+ elements: C,
248
242
  nodeId: n
249
- }), [c, x, E, n, e]);
250
- return b(() => {
251
- e.dataRef.current.floatingContext = C;
243
+ }), [r, x, C, n, e]);
244
+ return M(() => {
245
+ e.dataRef.current.floatingContext = E;
252
246
  const f = h == null ? void 0 : h.nodesRef.current.find((m) => m.id === n);
253
- f && (f.context = C);
254
- }), o.useMemo(() => ({
255
- ...c,
256
- context: C,
247
+ f && (f.context = E);
248
+ }), s.useMemo(() => ({
249
+ ...r,
250
+ context: E,
257
251
  refs: x,
258
- elements: E
259
- }), [c, x, E, C]);
252
+ elements: C
253
+ }), [r, x, C, E]);
260
254
  }
261
255
  export {
262
- me as FloatingArrow,
263
- Ee as arrow,
264
- ve as flip,
265
- Re as getOverflowAncestors,
266
- we as inline,
267
- Ce as offset,
268
- Se as shift,
269
- ge as useFloating,
256
+ ge as FloatingArrow,
257
+ ve as arrow,
258
+ we as flip,
259
+ xe as getOverflowAncestors,
260
+ Ee as inline,
261
+ Se as offset,
262
+ Ie as shift,
263
+ pe as useFloating,
270
264
  ce as useFloatingParentNodeId,
271
- ie as useFloatingRootContext,
272
- le as useFloatingTree,
265
+ le as useFloatingRootContext,
266
+ ie as useFloatingTree,
273
267
  B as useId
274
268
  };
275
269
  //# sourceMappingURL=annotorious-react.es13.js.map