@annotorious/react 3.1.4 → 3.1.6

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,394 +1,200 @@
1
- import { offset as ot, shift as st, flip as rt, inline as ct, arrow as lt, computePosition as ft } from "./annotorious-react.es22.js";
2
- import { createCoords as m, rectToClientRect as J, round as H, floor as A, max as E, min as z } from "./annotorious-react.es21.js";
3
- import { getOverflowAncestors as $, isElement as v, getWindow as L, getFrameElement as K, getComputedStyle as R, getDocumentElement as O, isHTMLElement as b, isWebKit as Q, isTopLayer as M, getNodeName as S, isOverflowElement as _, getNodeScroll as I, getParentNode as W, isLastTraversableNode as N, isTableElement as ut, isContainingBlock as Y, getContainingBlock as ht } from "./annotorious-react.es17.js";
4
- function Z(t) {
5
- const e = R(t);
6
- let n = parseFloat(e.width) || 0, i = parseFloat(e.height) || 0;
7
- const o = b(t), r = o ? t.offsetWidth : n, s = o ? t.offsetHeight : i, c = H(n) !== r || H(i) !== s;
8
- return c && (n = r, i = s), {
9
- width: n,
10
- height: i,
11
- $: c
12
- };
13
- }
14
- function q(t) {
15
- return v(t) ? t : t.contextElement;
16
- }
17
- function F(t) {
18
- const e = q(t);
19
- if (!b(e))
20
- return m(1);
21
- const n = e.getBoundingClientRect(), {
22
- width: i,
23
- height: o,
24
- $: r
25
- } = Z(e);
26
- let s = (r ? H(n.width) : n.width) / i, c = (r ? H(n.height) : n.height) / o;
27
- return (!s || !Number.isFinite(s)) && (s = 1), (!c || !Number.isFinite(c)) && (c = 1), {
28
- x: s,
29
- y: c
30
- };
31
- }
32
- const at = /* @__PURE__ */ m(0);
33
- function X(t) {
34
- const e = L(t);
35
- return !Q() || !e.visualViewport ? at : {
36
- x: e.visualViewport.offsetLeft,
37
- y: e.visualViewport.offsetTop
38
- };
39
- }
40
- function dt(t, e, n) {
41
- return e === void 0 && (e = !1), !n || e && n !== L(t) ? !1 : e;
42
- }
43
- function T(t, e, n, i) {
44
- e === void 0 && (e = !1), n === void 0 && (n = !1);
45
- const o = t.getBoundingClientRect(), r = q(t);
46
- let s = m(1);
47
- e && (i ? v(i) && (s = F(i)) : s = F(t));
48
- const c = dt(r, n, i) ? X(r) : m(0);
49
- let l = (o.left + c.x) / s.x, f = (o.top + c.y) / s.y, u = o.width / s.x, h = o.height / s.y;
50
- if (r) {
51
- const p = L(r), a = i && v(i) ? L(i) : i;
52
- let y = p, g = K(y);
53
- for (; g && i && a !== y; ) {
54
- const w = F(g), d = g.getBoundingClientRect(), x = R(g), C = d.left + (g.clientLeft + parseFloat(x.paddingLeft)) * w.x, B = d.top + (g.clientTop + parseFloat(x.paddingTop)) * w.y;
55
- l *= w.x, f *= w.y, u *= w.x, h *= w.y, l += C, f += B, y = L(g), g = K(y);
1
+ import { inline as I, offset as J, flip as K, shift as N, arrow as v, computePosition as Q } from "./annotorious-react.es14.js";
2
+ import { autoUpdate as le, platform as ce } from "./annotorious-react.es14.js";
3
+ import * as f from "react";
4
+ import { useLayoutEffect as T, useEffect as X } from "react";
5
+ import * as Y from "react-dom";
6
+ var R = typeof document < "u" ? T : X;
7
+ function h(e, t) {
8
+ if (e === t)
9
+ return !0;
10
+ if (typeof e != typeof t)
11
+ return !1;
12
+ if (typeof e == "function" && e.toString() === t.toString())
13
+ return !0;
14
+ let n, r, s;
15
+ if (e && t && typeof e == "object") {
16
+ if (Array.isArray(e)) {
17
+ if (n = e.length, n !== t.length) return !1;
18
+ for (r = n; r-- !== 0; )
19
+ if (!h(e[r], t[r]))
20
+ return !1;
21
+ return !0;
56
22
  }
23
+ if (s = Object.keys(e), n = s.length, n !== Object.keys(t).length)
24
+ return !1;
25
+ for (r = n; r-- !== 0; )
26
+ if (!{}.hasOwnProperty.call(t, s[r]))
27
+ return !1;
28
+ for (r = n; r-- !== 0; ) {
29
+ const p = s[r];
30
+ if (!(p === "_owner" && e.$$typeof) && !h(e[p], t[p]))
31
+ return !1;
32
+ }
33
+ return !0;
57
34
  }
58
- return J({
59
- width: u,
60
- height: h,
61
- x: l,
62
- y: f
63
- });
64
- }
65
- function k(t, e) {
66
- const n = I(t).scrollLeft;
67
- return e ? e.left + n : T(O(t)).left + n;
68
- }
69
- function tt(t, e, n) {
70
- n === void 0 && (n = !1);
71
- const i = t.getBoundingClientRect(), o = i.left + e.scrollLeft - (n ? 0 : (
72
- // RTL <body> scrollbar.
73
- k(t, i)
74
- )), r = i.top + e.scrollTop;
75
- return {
76
- x: o,
77
- y: r
78
- };
79
- }
80
- function gt(t) {
81
- let {
82
- elements: e,
83
- rect: n,
84
- offsetParent: i,
85
- strategy: o
86
- } = t;
87
- const r = o === "fixed", s = O(i), c = e ? M(e.floating) : !1;
88
- if (i === s || c && r)
89
- return n;
90
- let l = {
91
- scrollLeft: 0,
92
- scrollTop: 0
93
- }, f = m(1);
94
- const u = m(0), h = b(i);
95
- if ((h || !h && !r) && ((S(i) !== "body" || _(s)) && (l = I(i)), b(i))) {
96
- const a = T(i);
97
- f = F(i), u.x = a.x + i.clientLeft, u.y = a.y + i.clientTop;
98
- }
99
- const p = s && !h && !r ? tt(s, l, !0) : m(0);
100
- return {
101
- width: n.width * f.x,
102
- height: n.height * f.y,
103
- x: n.x * f.x - l.scrollLeft * f.x + u.x + p.x,
104
- y: n.y * f.y - l.scrollTop * f.y + u.y + p.y
105
- };
106
- }
107
- function pt(t) {
108
- return Array.from(t.getClientRects());
109
- }
110
- function wt(t) {
111
- const e = O(t), n = I(t), i = t.ownerDocument.body, o = E(e.scrollWidth, e.clientWidth, i.scrollWidth, i.clientWidth), r = E(e.scrollHeight, e.clientHeight, i.scrollHeight, i.clientHeight);
112
- let s = -n.scrollLeft + k(t);
113
- const c = -n.scrollTop;
114
- return R(i).direction === "rtl" && (s += E(e.clientWidth, i.clientWidth) - o), {
115
- width: o,
116
- height: r,
117
- x: s,
118
- y: c
119
- };
120
- }
121
- function mt(t, e) {
122
- const n = L(t), i = O(t), o = n.visualViewport;
123
- let r = i.clientWidth, s = i.clientHeight, c = 0, l = 0;
124
- if (o) {
125
- r = o.width, s = o.height;
126
- const f = Q();
127
- (!f || f && e === "fixed") && (c = o.offsetLeft, l = o.offsetTop);
128
- }
129
- return {
130
- width: r,
131
- height: s,
132
- x: c,
133
- y: l
134
- };
135
- }
136
- function yt(t, e) {
137
- const n = T(t, !0, e === "fixed"), i = n.top + t.clientTop, o = n.left + t.clientLeft, r = b(t) ? F(t) : m(1), s = t.clientWidth * r.x, c = t.clientHeight * r.y, l = o * r.x, f = i * r.y;
138
- return {
139
- width: s,
140
- height: c,
141
- x: l,
142
- y: f
143
- };
144
- }
145
- function j(t, e, n) {
146
- let i;
147
- if (e === "viewport")
148
- i = mt(t, n);
149
- else if (e === "document")
150
- i = wt(O(t));
151
- else if (v(e))
152
- i = yt(e, n);
153
- else {
154
- const o = X(t);
155
- i = {
156
- x: e.x - o.x,
157
- y: e.y - o.y,
158
- width: e.width,
159
- height: e.height
160
- };
161
- }
162
- return J(i);
35
+ return e !== e && t !== t;
163
36
  }
164
- function et(t, e) {
165
- const n = W(t);
166
- return n === e || !v(n) || N(n) ? !1 : R(n).position === "fixed" || et(n, e);
37
+ function q(e) {
38
+ return typeof window > "u" ? 1 : (e.ownerDocument.defaultView || window).devicePixelRatio || 1;
167
39
  }
168
- function xt(t, e) {
169
- const n = e.get(t);
170
- if (n)
171
- return n;
172
- let i = $(t, [], !1).filter((c) => v(c) && S(c) !== "body"), o = null;
173
- const r = R(t).position === "fixed";
174
- let s = r ? W(t) : t;
175
- for (; v(s) && !N(s); ) {
176
- const c = R(s), l = Y(s);
177
- !l && c.position === "fixed" && (o = null), (r ? !l && !o : !l && c.position === "static" && !!o && ["absolute", "fixed"].includes(o.position) || _(s) && !l && et(t, s)) ? i = i.filter((u) => u !== s) : o = c, s = W(s);
178
- }
179
- return e.set(t, i), i;
40
+ function A(e, t) {
41
+ const n = q(e);
42
+ return Math.round(t * n) / n;
180
43
  }
181
- function vt(t) {
182
- let {
183
- element: e,
184
- boundary: n,
185
- rootBoundary: i,
186
- strategy: o
187
- } = t;
188
- const s = [...n === "clippingAncestors" ? M(e) ? [] : xt(e, this._c) : [].concat(n), i], c = s[0], l = s.reduce((f, u) => {
189
- const h = j(e, u, o);
190
- return f.top = E(h.top, f.top), f.right = z(h.right, f.right), f.bottom = z(h.bottom, f.bottom), f.left = E(h.left, f.left), f;
191
- }, j(e, c, o));
192
- return {
193
- width: l.right - l.left,
194
- height: l.bottom - l.top,
195
- x: l.left,
196
- y: l.top
197
- };
44
+ function $(e) {
45
+ const t = f.useRef(e);
46
+ return R(() => {
47
+ t.current = e;
48
+ }), t;
198
49
  }
199
- function Rt(t) {
50
+ function te(e) {
51
+ e === void 0 && (e = {});
200
52
  const {
201
- width: e,
202
- height: n
203
- } = Z(t);
204
- return {
205
- width: e,
206
- height: n
207
- };
208
- }
209
- function Ot(t, e, n) {
210
- const i = b(e), o = O(e), r = n === "fixed", s = T(t, !0, r, e);
211
- let c = {
212
- scrollLeft: 0,
213
- scrollTop: 0
214
- };
215
- const l = m(0);
216
- if (i || !i && !r)
217
- if ((S(e) !== "body" || _(o)) && (c = I(e)), i) {
218
- const p = T(e, !0, r, e);
219
- l.x = p.x + e.clientLeft, l.y = p.y + e.clientTop;
220
- } else o && (l.x = k(o));
221
- const f = o && !i && !r ? tt(o, c) : m(0), u = s.left + c.scrollLeft - l.x - f.x, h = s.top + c.scrollTop - l.y - f.y;
222
- return {
223
- x: u,
224
- y: h,
225
- width: s.width,
226
- height: s.height
227
- };
228
- }
229
- function V(t) {
230
- return R(t).position === "static";
231
- }
232
- function G(t, e) {
233
- if (!b(t) || R(t).position === "fixed")
234
- return null;
235
- if (e)
236
- return e(t);
237
- let n = t.offsetParent;
238
- return O(t) === n && (n = n.ownerDocument.body), n;
239
- }
240
- function nt(t, e) {
241
- const n = L(t);
242
- if (M(t))
243
- return n;
244
- if (!b(t)) {
245
- let o = W(t);
246
- for (; o && !N(o); ) {
247
- if (v(o) && !V(o))
248
- return o;
249
- o = W(o);
250
- }
251
- return n;
252
- }
253
- let i = G(t, e);
254
- for (; i && ut(i) && V(i); )
255
- i = G(i, e);
256
- return i && N(i) && V(i) && !Y(i) ? n : i || ht(t) || n;
257
- }
258
- const bt = async function(t) {
259
- const e = this.getOffsetParent || nt, n = this.getDimensions, i = await n(t.floating);
260
- return {
261
- reference: Ot(t.reference, await e(t.floating), t.strategy),
262
- floating: {
263
- x: 0,
264
- y: 0,
265
- width: i.width,
266
- height: i.height
267
- }
268
- };
269
- };
270
- function Ct(t) {
271
- return R(t).direction === "rtl";
272
- }
273
- const Lt = {
274
- convertOffsetParentRelativeRectToViewportRelativeRect: gt,
275
- getDocumentElement: O,
276
- getClippingRect: vt,
277
- getOffsetParent: nt,
278
- getElementRects: bt,
279
- getClientRects: pt,
280
- getDimensions: Rt,
281
- getScale: F,
282
- isElement: v,
283
- isRTL: Ct
284
- };
285
- function it(t, e) {
286
- return t.x === e.x && t.y === e.y && t.width === e.width && t.height === e.height;
287
- }
288
- function Tt(t, e) {
289
- let n = null, i;
290
- const o = O(t);
291
- function r() {
292
- var c;
293
- clearTimeout(i), (c = n) == null || c.disconnect(), n = null;
294
- }
295
- function s(c, l) {
296
- c === void 0 && (c = !1), l === void 0 && (l = 1), r();
297
- const f = t.getBoundingClientRect(), {
298
- left: u,
299
- top: h,
300
- width: p,
301
- height: a
302
- } = f;
303
- if (c || e(), !p || !a)
53
+ placement: t = "bottom",
54
+ strategy: n = "absolute",
55
+ middleware: r = [],
56
+ platform: s,
57
+ elements: {
58
+ reference: p,
59
+ floating: B
60
+ } = {},
61
+ transform: k = !0,
62
+ whileElementsMounted: D,
63
+ open: x
64
+ } = e, [i, O] = f.useState({
65
+ x: 0,
66
+ y: 0,
67
+ strategy: n,
68
+ placement: t,
69
+ middlewareData: {},
70
+ isPositioned: !1
71
+ }), [M, U] = f.useState(r);
72
+ h(M, r) || U(r);
73
+ const [V, W] = f.useState(null), [z, G] = f.useState(null), _ = f.useCallback((o) => {
74
+ o !== a.current && (a.current = o, W(o));
75
+ }, []), C = f.useCallback((o) => {
76
+ o !== d.current && (d.current = o, G(o));
77
+ }, []), u = p || V, l = B || z, a = f.useRef(null), d = f.useRef(null), y = f.useRef(i), H = D != null, P = $(D), S = $(s), F = $(x), g = f.useCallback(() => {
78
+ if (!a.current || !d.current)
304
79
  return;
305
- const y = A(h), g = A(o.clientWidth - (u + p)), w = A(o.clientHeight - (h + a)), d = A(u), C = {
306
- rootMargin: -y + "px " + -g + "px " + -w + "px " + -d + "px",
307
- threshold: E(0, z(1, l)) || 1
80
+ const o = {
81
+ placement: t,
82
+ strategy: n,
83
+ middleware: M
308
84
  };
309
- let B = !0;
310
- function P(U) {
311
- const D = U[0].intersectionRatio;
312
- if (D !== l) {
313
- if (!B)
314
- return s();
315
- D ? s(!1, D) : i = setTimeout(() => {
316
- s(!1, 1e-7);
317
- }, 1e3);
318
- }
319
- D === 1 && !it(f, t.getBoundingClientRect()) && s(), B = !1;
85
+ S.current && (o.platform = S.current), Q(a.current, d.current, o).then((w) => {
86
+ const m = {
87
+ ...w,
88
+ // The floating element's position may be recomputed while it's closed
89
+ // but still mounted (such as when transitioning out). To ensure
90
+ // `isPositioned` will be `false` initially on the next open, avoid
91
+ // setting it to `true` when `open === false` (must be specified).
92
+ isPositioned: F.current !== !1
93
+ };
94
+ E.current && !h(y.current, m) && (y.current = m, Y.flushSync(() => {
95
+ O(m);
96
+ }));
97
+ });
98
+ }, [M, t, n, S, F]);
99
+ R(() => {
100
+ x === !1 && y.current.isPositioned && (y.current.isPositioned = !1, O((o) => ({
101
+ ...o,
102
+ isPositioned: !1
103
+ })));
104
+ }, [x]);
105
+ const E = f.useRef(!1);
106
+ R(() => (E.current = !0, () => {
107
+ E.current = !1;
108
+ }), []), R(() => {
109
+ if (u && (a.current = u), l && (d.current = l), u && l) {
110
+ if (P.current)
111
+ return P.current(u, l, g);
112
+ g();
320
113
  }
321
- try {
322
- n = new IntersectionObserver(P, {
323
- ...C,
324
- // Handle <iframe>s
325
- root: o.ownerDocument
326
- });
327
- } catch {
328
- n = new IntersectionObserver(P, C);
329
- }
330
- n.observe(t);
331
- }
332
- return s(!0), r;
333
- }
334
- function Bt(t, e, n, i) {
335
- i === void 0 && (i = {});
336
- const {
337
- ancestorScroll: o = !0,
338
- ancestorResize: r = !0,
339
- elementResize: s = typeof ResizeObserver == "function",
340
- layoutShift: c = typeof IntersectionObserver == "function",
341
- animationFrame: l = !1
342
- } = i, f = q(t), u = o || r ? [...f ? $(f) : [], ...$(e)] : [];
343
- u.forEach((d) => {
344
- o && d.addEventListener("scroll", n, {
345
- passive: !0
346
- }), r && d.addEventListener("resize", n);
347
- });
348
- const h = f && c ? Tt(f, n) : null;
349
- let p = -1, a = null;
350
- s && (a = new ResizeObserver((d) => {
351
- let [x] = d;
352
- x && x.target === f && a && (a.unobserve(e), cancelAnimationFrame(p), p = requestAnimationFrame(() => {
353
- var C;
354
- (C = a) == null || C.observe(e);
355
- })), n();
356
- }), f && !l && a.observe(f), a.observe(e));
357
- let y, g = l ? T(t) : null;
358
- l && w();
359
- function w() {
360
- const d = T(t);
361
- g && !it(g, d) && n(), g = d, y = requestAnimationFrame(w);
114
+ }, [u, l, g, P, H]);
115
+ const j = f.useMemo(() => ({
116
+ reference: a,
117
+ floating: d,
118
+ setReference: _,
119
+ setFloating: C
120
+ }), [_, C]), c = f.useMemo(() => ({
121
+ reference: u,
122
+ floating: l
123
+ }), [u, l]), L = f.useMemo(() => {
124
+ const o = {
125
+ position: n,
126
+ left: 0,
127
+ top: 0
128
+ };
129
+ if (!c.floating)
130
+ return o;
131
+ const w = A(c.floating, i.x), m = A(c.floating, i.y);
132
+ return k ? {
133
+ ...o,
134
+ transform: "translate(" + w + "px, " + m + "px)",
135
+ ...q(c.floating) >= 1.5 && {
136
+ willChange: "transform"
137
+ }
138
+ } : {
139
+ position: n,
140
+ left: w,
141
+ top: m
142
+ };
143
+ }, [n, k, c.floating, i.x, i.y]);
144
+ return f.useMemo(() => ({
145
+ ...i,
146
+ update: g,
147
+ refs: j,
148
+ elements: c,
149
+ floatingStyles: L
150
+ }), [i, g, j, c, L]);
151
+ }
152
+ const Z = (e) => {
153
+ function t(n) {
154
+ return {}.hasOwnProperty.call(n, "current");
362
155
  }
363
- return n(), () => {
364
- var d;
365
- u.forEach((x) => {
366
- o && x.removeEventListener("scroll", n), r && x.removeEventListener("resize", n);
367
- }), h == null || h(), (d = a) == null || d.disconnect(), a = null, l && cancelAnimationFrame(y);
368
- };
369
- }
370
- const Dt = ot, At = st, Ht = rt, Nt = lt, It = ct, Vt = (t, e, n) => {
371
- const i = /* @__PURE__ */ new Map(), o = {
372
- platform: Lt,
373
- ...n
374
- }, r = {
375
- ...o.platform,
376
- _c: i
156
+ return {
157
+ name: "arrow",
158
+ options: e,
159
+ fn(n) {
160
+ const {
161
+ element: r,
162
+ padding: s
163
+ } = typeof e == "function" ? e(n) : e;
164
+ return r && t(r) ? r.current != null ? v({
165
+ element: r.current,
166
+ padding: s
167
+ }).fn(n) : {} : r ? v({
168
+ element: r,
169
+ padding: s
170
+ }).fn(n) : {};
171
+ }
377
172
  };
378
- return ft(t, e, {
379
- ...o,
380
- platform: r
381
- });
382
- };
173
+ }, ne = (e, t) => ({
174
+ ...J(e),
175
+ options: [e, t]
176
+ }), re = (e, t) => ({
177
+ ...N(e),
178
+ options: [e, t]
179
+ }), fe = (e, t) => ({
180
+ ...K(e),
181
+ options: [e, t]
182
+ }), oe = (e, t) => ({
183
+ ...I(e),
184
+ options: [e, t]
185
+ }), se = (e, t) => ({
186
+ ...Z(e),
187
+ options: [e, t]
188
+ });
383
189
  export {
384
- Nt as arrow,
385
- Bt as autoUpdate,
386
- Vt as computePosition,
387
- Ht as flip,
388
- $ as getOverflowAncestors,
389
- It as inline,
390
- Dt as offset,
391
- Lt as platform,
392
- At as shift
190
+ se as arrow,
191
+ le as autoUpdate,
192
+ Q as computePosition,
193
+ fe as flip,
194
+ oe as inline,
195
+ ne as offset,
196
+ ce as platform,
197
+ re as shift,
198
+ te as useFloating
393
199
  };
394
200
  //# sourceMappingURL=annotorious-react.es15.js.map