@soomo/react-text-annotator 3.0.0-staging.29 → 3.0.0-staging.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.
Files changed (33) hide show
  1. package/dist/TextAnnotatorPopup.d.ts.map +1 -1
  2. package/dist/react-text-annotator.css +1 -1
  3. package/dist/react-text-annotator.es10.js +204 -200
  4. package/dist/react-text-annotator.es10.js.map +1 -1
  5. package/dist/react-text-annotator.es11.js +537 -211
  6. package/dist/react-text-annotator.es11.js.map +1 -1
  7. package/dist/react-text-annotator.es12.js +443 -535
  8. package/dist/react-text-annotator.es12.js.map +1 -1
  9. package/dist/react-text-annotator.es13.js +2 -487
  10. package/dist/react-text-annotator.es13.js.map +1 -1
  11. package/dist/react-text-annotator.es14.js +31 -2
  12. package/dist/react-text-annotator.es14.js.map +1 -1
  13. package/dist/react-text-annotator.es15.js +887 -20
  14. package/dist/react-text-annotator.es15.js.map +1 -1
  15. package/dist/react-text-annotator.es16.js +49 -896
  16. package/dist/react-text-annotator.es16.js.map +1 -1
  17. package/dist/react-text-annotator.es17.js +6 -7
  18. package/dist/react-text-annotator.es17.js.map +1 -1
  19. package/dist/react-text-annotator.es2.js +1 -1
  20. package/dist/react-text-annotator.es24.js +1 -39
  21. package/dist/react-text-annotator.es24.js.map +1 -1
  22. package/dist/react-text-annotator.es25.js +1 -98
  23. package/dist/react-text-annotator.es25.js.map +1 -1
  24. package/dist/react-text-annotator.es5.js +43 -52
  25. package/dist/react-text-annotator.es5.js.map +1 -1
  26. package/dist/react-text-annotator.es6.js +33 -33
  27. package/dist/react-text-annotator.es6.js.map +1 -1
  28. package/dist/react-text-annotator.es7.js +3 -3
  29. package/dist/react-text-annotator.es9.js +668 -23
  30. package/dist/react-text-annotator.es9.js.map +1 -1
  31. package/package.json +6 -6
  32. package/dist/utils.d.ts +0 -14
  33. package/dist/utils.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"TextAnnotatorPopup.d.ts","sourceRoot":"","sources":["../src/TextAnnotatorPopup.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AAW1E,UAAU,wBAAwB;IAEhC,KAAK,CAAC,KAAK,EAAE,uBAAuB,GAAG,SAAS,CAAC;CAElD;AAED,MAAM,WAAW,uBAAuB;IAEtC,QAAQ,EAAE;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CAEhE;AAED,eAAO,MAAM,kBAAkB,UAAW,wBAAwB,4CAsFjE,CAAA"}
1
+ {"version":3,"file":"TextAnnotatorPopup.d.ts","sourceRoot":"","sources":["../src/TextAnnotatorPopup.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkD,MAAM,OAAO,CAAC;AAElF,OAAO,EAAE,KAAK,cAAc,EAAsB,MAAM,uBAAuB,CAAC;AAYhF,UAAU,wBAAwB;IAEhC,KAAK,CAAC,KAAK,EAAE,uBAAuB,GAAG,SAAS,CAAC;CAElD;AAED,MAAM,WAAW,uBAAuB;IAEtC,QAAQ,EAAE;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CAEhE;AAED,eAAO,MAAM,kBAAkB,UAAW,wBAAwB,4CAuEjE,CAAA"}
@@ -1 +1 @@
1
- .r6o-canvas-highlight-layer{position:fixed;top:0;bottom:0;left:0;width:100vw;height:100vh;pointer-events:none}.r6o-canvas-highlight-layer.bg{mix-blend-mode:multiply;z-index:1}.r6o-annotatable .r6o-span-highlight-layer{position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none}.r6o-annotatable .r6o-span-highlight-layer.hidden{display:none}.r6o-annotatable .r6o-span-highlight-layer .r6o-annotation{position:absolute;display:block;border-width:0;border-style:solid}.r6o-annotation{box-sizing:content-box}.r6o-presence-layer{left:0;position:fixed;top:0;bottom:0;width:100vw;pointer-events:none}html,body{overscroll-behavior-y:none}.r6o-annotatable{-webkit-tap-highlight-color:transparent}.r6o-annotatable,.r6o-annotatable *{position:relative}.hovered *{cursor:pointer}*::selection,::selection{background:#0080ff2e}::-moz-selection{background:#0080ff2e}
1
+ .r6o-canvas-highlight-layer{position:fixed;top:0;bottom:0;left:0;width:100vw;height:100vh;pointer-events:none}.r6o-canvas-highlight-layer.bg{mix-blend-mode:multiply;z-index:1}.r6o-annotatable .r6o-span-highlight-layer{position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none}.r6o-annotatable .r6o-span-highlight-layer.hidden{display:none}.r6o-annotatable .r6o-span-highlight-layer .r6o-annotation{position:absolute;display:block;border-width:0;border-style:solid}.r6o-annotation{box-sizing:content-box}.r6o-presence-layer{left:0;position:fixed;top:0;bottom:0;width:100vw;pointer-events:none}html,body{overscroll-behavior-y:none}.r6o-annotatable{position:relative;-webkit-tap-highlight-color:transparent}.hovered *{cursor:pointer}*::selection,::selection{background:#0080ff2e}::-moz-selection{background:#0080ff2e}
@@ -1,235 +1,239 @@
1
+ import { computePosition, offset as offset$1, shift as shift$1, inline as inline$1 } from "./react-text-annotator.es11.js";
2
+ import { autoUpdate, platform } from "./react-text-annotator.es11.js";
1
3
  import * as React from "react";
2
4
  import { useLayoutEffect, useEffect } from "react";
3
- import { isElement } from "./react-text-annotator.es17.js";
4
- import { getOverflowAncestors } from "./react-text-annotator.es17.js";
5
- import "react-dom";
6
- import { useFloating as useFloating$1 } from "./react-text-annotator.es11.js";
7
- import { autoPlacement, inline, offset, shift } from "./react-text-annotator.es11.js";
8
- const SafeReact = {
9
- ...React
10
- };
11
- const useInsertionEffect = SafeReact.useInsertionEffect;
12
- const useSafeInsertionEffect = useInsertionEffect || ((fn) => fn());
13
- function useEffectEvent(callback) {
14
- const ref = React.useRef(() => {
15
- if (process.env.NODE_ENV !== "production") {
16
- throw new Error("Cannot call an event handler while rendering.");
5
+ import * as ReactDOM from "react-dom";
6
+ var index = typeof document !== "undefined" ? useLayoutEffect : useEffect;
7
+ function deepEqual(a, b) {
8
+ if (a === b) {
9
+ return true;
10
+ }
11
+ if (typeof a !== typeof b) {
12
+ return false;
13
+ }
14
+ if (typeof a === "function" && a.toString() === b.toString()) {
15
+ return true;
16
+ }
17
+ let length;
18
+ let i;
19
+ let keys;
20
+ if (a && b && typeof a === "object") {
21
+ if (Array.isArray(a)) {
22
+ length = a.length;
23
+ if (length !== b.length) return false;
24
+ for (i = length; i-- !== 0; ) {
25
+ if (!deepEqual(a[i], b[i])) {
26
+ return false;
27
+ }
28
+ }
29
+ return true;
17
30
  }
18
- });
19
- useSafeInsertionEffect(() => {
20
- ref.current = callback;
21
- });
22
- return React.useCallback(function() {
23
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
24
- args[_key] = arguments[_key];
31
+ keys = Object.keys(a);
32
+ length = keys.length;
33
+ if (length !== Object.keys(b).length) {
34
+ return false;
25
35
  }
26
- return ref.current == null ? void 0 : ref.current(...args);
27
- }, []);
28
- }
29
- var index = typeof document !== "undefined" ? useLayoutEffect : useEffect;
30
- let serverHandoffComplete = false;
31
- let count = 0;
32
- const genId = () => (
33
- // Ensure the id is unique with multiple independent versions of Floating UI
34
- // on <React 18
35
- "floating-ui-" + Math.random().toString(36).slice(2, 6) + count++
36
- );
37
- function useFloatingId() {
38
- const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : void 0);
39
- index(() => {
40
- if (id == null) {
41
- setId(genId());
36
+ for (i = length; i-- !== 0; ) {
37
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
38
+ return false;
39
+ }
42
40
  }
43
- }, []);
44
- React.useEffect(() => {
45
- serverHandoffComplete = true;
46
- }, []);
47
- return id;
48
- }
49
- const useReactId = SafeReact.useId;
50
- const useId = useReactId || useFloatingId;
51
- let devMessageSet;
52
- if (process.env.NODE_ENV !== "production") {
53
- devMessageSet = /* @__PURE__ */ new Set();
54
- }
55
- function error() {
56
- var _devMessageSet3;
57
- for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
58
- messages[_key2] = arguments[_key2];
41
+ for (i = length; i-- !== 0; ) {
42
+ const key = keys[i];
43
+ if (key === "_owner" && a.$$typeof) {
44
+ continue;
45
+ }
46
+ if (!deepEqual(a[key], b[key])) {
47
+ return false;
48
+ }
49
+ }
50
+ return true;
59
51
  }
60
- const message = "Floating UI: " + messages.join(" ");
61
- if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
62
- var _devMessageSet4;
63
- (_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
64
- console.error(message);
52
+ return a !== a && b !== b;
53
+ }
54
+ function getDPR(element) {
55
+ if (typeof window === "undefined") {
56
+ return 1;
65
57
  }
58
+ const win = element.ownerDocument.defaultView || window;
59
+ return win.devicePixelRatio || 1;
66
60
  }
67
- function createPubSub() {
68
- const map = /* @__PURE__ */ new Map();
69
- return {
70
- emit(event, data) {
71
- var _map$get;
72
- (_map$get = map.get(event)) == null || _map$get.forEach((handler) => handler(data));
73
- },
74
- on(event, listener) {
75
- map.set(event, [...map.get(event) || [], listener]);
76
- },
77
- off(event, listener) {
78
- var _map$get2;
79
- map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter((l) => l !== listener)) || []);
80
- }
81
- };
61
+ function roundByDPR(element, value) {
62
+ const dpr = getDPR(element);
63
+ return Math.round(value * dpr) / dpr;
82
64
  }
83
- const FloatingNodeContext = /* @__PURE__ */ React.createContext(null);
84
- const FloatingTreeContext = /* @__PURE__ */ React.createContext(null);
85
- const useFloatingParentNodeId = () => {
86
- var _React$useContext;
87
- return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
88
- };
89
- const useFloatingTree = () => React.useContext(FloatingTreeContext);
90
- function useFloatingRootContext(options) {
91
- const {
92
- open = false,
93
- onOpenChange: onOpenChangeProp,
94
- elements: elementsProp
95
- } = options;
96
- const floatingId = useId();
97
- const dataRef = React.useRef({});
98
- const [events] = React.useState(() => createPubSub());
99
- const nested = useFloatingParentNodeId() != null;
100
- if (process.env.NODE_ENV !== "production") {
101
- const optionDomReference = elementsProp.reference;
102
- if (optionDomReference && !isElement(optionDomReference)) {
103
- error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
104
- }
105
- }
106
- const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
107
- const onOpenChange = useEffectEvent((open2, event, reason) => {
108
- dataRef.current.openEvent = open2 ? event : void 0;
109
- events.emit("openchange", {
110
- open: open2,
111
- event,
112
- reason,
113
- nested
114
- });
115
- onOpenChangeProp == null || onOpenChangeProp(open2, event, reason);
65
+ function useLatestRef(value) {
66
+ const ref = React.useRef(value);
67
+ index(() => {
68
+ ref.current = value;
116
69
  });
117
- const refs = React.useMemo(() => ({
118
- setPositionReference
119
- }), []);
120
- const elements = React.useMemo(() => ({
121
- reference: positionReference || elementsProp.reference || null,
122
- floating: elementsProp.floating || null,
123
- domReference: elementsProp.reference
124
- }), [positionReference, elementsProp.reference, elementsProp.floating]);
125
- return React.useMemo(() => ({
126
- dataRef,
127
- open,
128
- onOpenChange,
129
- elements,
130
- events,
131
- floatingId,
132
- refs
133
- }), [open, onOpenChange, elements, events, floatingId, refs]);
70
+ return ref;
134
71
  }
135
72
  function useFloating(options) {
136
73
  if (options === void 0) {
137
74
  options = {};
138
75
  }
139
76
  const {
140
- nodeId
141
- } = options;
142
- const internalRootContext = useFloatingRootContext({
143
- ...options,
77
+ placement = "bottom",
78
+ strategy = "absolute",
79
+ middleware = [],
80
+ platform: platform2,
144
81
  elements: {
145
- reference: null,
146
- floating: null,
147
- ...options.elements
148
- }
82
+ reference: externalReference,
83
+ floating: externalFloating
84
+ } = {},
85
+ transform = true,
86
+ whileElementsMounted,
87
+ open
88
+ } = options;
89
+ const [data, setData] = React.useState({
90
+ x: 0,
91
+ y: 0,
92
+ strategy,
93
+ placement,
94
+ middlewareData: {},
95
+ isPositioned: false
149
96
  });
150
- const rootContext = options.rootContext || internalRootContext;
151
- const computedElements = rootContext.elements;
152
- const [_domReference, setDomReference] = React.useState(null);
153
- const [positionReference, _setPositionReference] = React.useState(null);
154
- const optionDomReference = computedElements == null ? void 0 : computedElements.reference;
155
- const domReference = optionDomReference || _domReference;
156
- const domReferenceRef = React.useRef(null);
157
- const tree = useFloatingTree();
158
- index(() => {
159
- if (domReference) {
160
- domReferenceRef.current = domReference;
97
+ const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
98
+ if (!deepEqual(latestMiddleware, middleware)) {
99
+ setLatestMiddleware(middleware);
100
+ }
101
+ const [_reference, _setReference] = React.useState(null);
102
+ const [_floating, _setFloating] = React.useState(null);
103
+ const setReference = React.useCallback((node) => {
104
+ if (node !== referenceRef.current) {
105
+ referenceRef.current = node;
106
+ _setReference(node);
161
107
  }
162
- }, [domReference]);
163
- const position = useFloating$1({
164
- ...options,
165
- elements: {
166
- ...computedElements,
167
- ...positionReference && {
168
- reference: positionReference
169
- }
108
+ }, []);
109
+ const setFloating = React.useCallback((node) => {
110
+ if (node !== floatingRef.current) {
111
+ floatingRef.current = node;
112
+ _setFloating(node);
170
113
  }
171
- });
172
- const setPositionReference = React.useCallback((node) => {
173
- const computedPositionReference = isElement(node) ? {
174
- getBoundingClientRect: () => node.getBoundingClientRect(),
175
- contextElement: node
176
- } : node;
177
- _setPositionReference(computedPositionReference);
178
- position.refs.setReference(computedPositionReference);
179
- }, [position.refs]);
180
- const setReference = React.useCallback((node) => {
181
- if (isElement(node) || node === null) {
182
- domReferenceRef.current = node;
183
- setDomReference(node);
114
+ }, []);
115
+ const referenceEl = externalReference || _reference;
116
+ const floatingEl = externalFloating || _floating;
117
+ const referenceRef = React.useRef(null);
118
+ const floatingRef = React.useRef(null);
119
+ const dataRef = React.useRef(data);
120
+ const hasWhileElementsMounted = whileElementsMounted != null;
121
+ const whileElementsMountedRef = useLatestRef(whileElementsMounted);
122
+ const platformRef = useLatestRef(platform2);
123
+ const update = React.useCallback(() => {
124
+ if (!referenceRef.current || !floatingRef.current) {
125
+ return;
184
126
  }
185
- if (isElement(position.refs.reference.current) || position.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
186
- // `null` to support `positionReference` + an unstable `reference`
187
- // callback ref.
188
- node !== null && !isElement(node)) {
189
- position.refs.setReference(node);
127
+ const config = {
128
+ placement,
129
+ strategy,
130
+ middleware: latestMiddleware
131
+ };
132
+ if (platformRef.current) {
133
+ config.platform = platformRef.current;
190
134
  }
191
- }, [position.refs]);
135
+ computePosition(referenceRef.current, floatingRef.current, config).then((data2) => {
136
+ const fullData = {
137
+ ...data2,
138
+ isPositioned: true
139
+ };
140
+ if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
141
+ dataRef.current = fullData;
142
+ ReactDOM.flushSync(() => {
143
+ setData(fullData);
144
+ });
145
+ }
146
+ });
147
+ }, [latestMiddleware, placement, strategy, platformRef]);
148
+ index(() => {
149
+ if (open === false && dataRef.current.isPositioned) {
150
+ dataRef.current.isPositioned = false;
151
+ setData((data2) => ({
152
+ ...data2,
153
+ isPositioned: false
154
+ }));
155
+ }
156
+ }, [open]);
157
+ const isMountedRef = React.useRef(false);
158
+ index(() => {
159
+ isMountedRef.current = true;
160
+ return () => {
161
+ isMountedRef.current = false;
162
+ };
163
+ }, []);
164
+ index(() => {
165
+ if (referenceEl) referenceRef.current = referenceEl;
166
+ if (floatingEl) floatingRef.current = floatingEl;
167
+ if (referenceEl && floatingEl) {
168
+ if (whileElementsMountedRef.current) {
169
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
170
+ }
171
+ update();
172
+ }
173
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
192
174
  const refs = React.useMemo(() => ({
193
- ...position.refs,
175
+ reference: referenceRef,
176
+ floating: floatingRef,
194
177
  setReference,
195
- setPositionReference,
196
- domReference: domReferenceRef
197
- }), [position.refs, setReference, setPositionReference]);
178
+ setFloating
179
+ }), [setReference, setFloating]);
198
180
  const elements = React.useMemo(() => ({
199
- ...position.elements,
200
- domReference
201
- }), [position.elements, domReference]);
202
- const context = React.useMemo(() => ({
203
- ...position,
204
- ...rootContext,
205
- refs,
206
- elements,
207
- nodeId
208
- }), [position, refs, elements, nodeId, rootContext]);
209
- index(() => {
210
- rootContext.dataRef.current.floatingContext = context;
211
- const node = tree == null ? void 0 : tree.nodesRef.current.find((node2) => node2.id === nodeId);
212
- if (node) {
213
- node.context = context;
181
+ reference: referenceEl,
182
+ floating: floatingEl
183
+ }), [referenceEl, floatingEl]);
184
+ const floatingStyles = React.useMemo(() => {
185
+ const initialStyles = {
186
+ position: strategy,
187
+ left: 0,
188
+ top: 0
189
+ };
190
+ if (!elements.floating) {
191
+ return initialStyles;
214
192
  }
215
- });
193
+ const x = roundByDPR(elements.floating, data.x);
194
+ const y = roundByDPR(elements.floating, data.y);
195
+ if (transform) {
196
+ return {
197
+ ...initialStyles,
198
+ transform: "translate(" + x + "px, " + y + "px)",
199
+ ...getDPR(elements.floating) >= 1.5 && {
200
+ willChange: "transform"
201
+ }
202
+ };
203
+ }
204
+ return {
205
+ position: strategy,
206
+ left: x,
207
+ top: y
208
+ };
209
+ }, [strategy, transform, elements.floating, data.x, data.y]);
216
210
  return React.useMemo(() => ({
217
- ...position,
218
- context,
211
+ ...data,
212
+ update,
219
213
  refs,
220
- elements
221
- }), [position, refs, elements, context]);
214
+ elements,
215
+ floatingStyles
216
+ }), [data, update, refs, elements, floatingStyles]);
222
217
  }
218
+ const offset = (options, deps) => ({
219
+ ...offset$1(options),
220
+ options: [options, deps]
221
+ });
222
+ const shift = (options, deps) => ({
223
+ ...shift$1(options),
224
+ options: [options, deps]
225
+ });
226
+ const inline = (options, deps) => ({
227
+ ...inline$1(options),
228
+ options: [options, deps]
229
+ });
223
230
  export {
224
- autoPlacement,
225
- getOverflowAncestors,
231
+ autoUpdate,
232
+ computePosition,
226
233
  inline,
227
234
  offset,
235
+ platform,
228
236
  shift,
229
- useFloating,
230
- useFloatingParentNodeId,
231
- useFloatingRootContext,
232
- useFloatingTree,
233
- useId
237
+ useFloating
234
238
  };
235
239
  //# sourceMappingURL=react-text-annotator.es10.js.map