@linkurious/ogma-annotations-react 1.1.2 → 1.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.
@@ -1,5 +1,5 @@
1
1
  import Ae, { createContext as je, useContext as vr, useReducer as pr, useState as D, useEffect as re } from "react";
2
- import { Control as yr, isArrow as gr, isText as Er } from "@linkurious/ogma-annotations";
2
+ import { Control as yr, isArrow as Er, isText as gr } from "@linkurious/ogma-annotations";
3
3
  import { useOgma as hr } from "@linkurious/ogma-react";
4
4
  var te = { exports: {} }, $ = {};
5
5
  /**
@@ -16,7 +16,7 @@ function mr() {
16
16
  if (xe)
17
17
  return $;
18
18
  xe = 1;
19
- var f = Ae, s = Symbol.for("react.element"), y = Symbol.for("react.fragment"), S = Object.prototype.hasOwnProperty, g = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, x = { key: !0, ref: !0, __self: !0, __source: !0 };
19
+ var f = Ae, s = Symbol.for("react.element"), y = Symbol.for("react.fragment"), S = Object.prototype.hasOwnProperty, E = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, x = { key: !0, ref: !0, __self: !0, __source: !0 };
20
20
  function b(R, v, C) {
21
21
  var l, h = {}, _ = null, P = null;
22
22
  C !== void 0 && (_ = "" + C), v.key !== void 0 && (_ = "" + v.key), v.ref !== void 0 && (P = v.ref);
@@ -25,7 +25,7 @@ function mr() {
25
25
  if (R && R.defaultProps)
26
26
  for (l in v = R.defaultProps, v)
27
27
  h[l] === void 0 && (h[l] = v[l]);
28
- return { $$typeof: s, type: R, key: _, ref: P, props: h, _owner: g.current };
28
+ return { $$typeof: s, type: R, key: _, ref: P, props: h, _owner: E.current };
29
29
  }
30
30
  return $.Fragment = y, $.jsx = b, $.jsxs = b, $;
31
31
  }
@@ -42,7 +42,7 @@ var L = {};
42
42
  var Oe;
43
43
  function br() {
44
44
  return Oe || (Oe = 1, process.env.NODE_ENV !== "production" && function() {
45
- var f = Ae, s = Symbol.for("react.element"), y = Symbol.for("react.portal"), S = Symbol.for("react.fragment"), g = Symbol.for("react.strict_mode"), x = Symbol.for("react.profiler"), b = Symbol.for("react.provider"), R = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), C = Symbol.for("react.suspense"), l = Symbol.for("react.suspense_list"), h = Symbol.for("react.memo"), _ = Symbol.for("react.lazy"), P = Symbol.for("react.offscreen"), N = Symbol.iterator, Y = "@@iterator";
45
+ var f = Ae, s = Symbol.for("react.element"), y = Symbol.for("react.portal"), S = Symbol.for("react.fragment"), E = Symbol.for("react.strict_mode"), x = Symbol.for("react.profiler"), b = Symbol.for("react.provider"), R = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), C = Symbol.for("react.suspense"), l = Symbol.for("react.suspense_list"), h = Symbol.for("react.memo"), _ = Symbol.for("react.lazy"), P = Symbol.for("react.offscreen"), N = Symbol.iterator, Y = "@@iterator";
46
46
  function M(e) {
47
47
  if (e === null || typeof e != "object")
48
48
  return null;
@@ -70,7 +70,7 @@ function br() {
70
70
  var We = !1, Ie = !1, $e = !1, Le = !1, Ne = !1, ne;
71
71
  ne = Symbol.for("react.module.reference");
72
72
  function Ye(e) {
73
- return !!(typeof e == "string" || typeof e == "function" || e === S || e === x || Ne || e === g || e === C || e === l || Le || e === P || We || Ie || $e || typeof e == "object" && e !== null && (e.$$typeof === _ || e.$$typeof === h || e.$$typeof === b || e.$$typeof === R || e.$$typeof === v || // This needs to include all possible module reference object
73
+ return !!(typeof e == "string" || typeof e == "function" || e === S || e === x || Ne || e === E || e === C || e === l || Le || e === P || We || Ie || $e || typeof e == "object" && e !== null && (e.$$typeof === _ || e.$$typeof === h || e.$$typeof === b || e.$$typeof === R || e.$$typeof === v || // This needs to include all possible module reference object
74
74
  // types supported by any Flight configuration anywhere since
75
75
  // we don't know which Flight build this will end up being used
76
76
  // with.
@@ -100,7 +100,7 @@ function br() {
100
100
  return "Portal";
101
101
  case x:
102
102
  return "Profiler";
103
- case g:
103
+ case E:
104
104
  return "StrictMode";
105
105
  case C:
106
106
  return "Suspense";
@@ -261,14 +261,14 @@ function br() {
261
261
  } catch (w) {
262
262
  if (w && n && typeof w.stack == "string") {
263
263
  for (var a = w.stack.split(`
264
- `), E = n.stack.split(`
265
- `), c = a.length - 1, d = E.length - 1; c >= 1 && d >= 0 && a[c] !== E[d]; )
264
+ `), g = n.stack.split(`
265
+ `), c = a.length - 1, d = g.length - 1; c >= 1 && d >= 0 && a[c] !== g[d]; )
266
266
  d--;
267
267
  for (; c >= 1 && d >= 0; c--, d--)
268
- if (a[c] !== E[d]) {
268
+ if (a[c] !== g[d]) {
269
269
  if (c !== 1 || d !== 1)
270
270
  do
271
- if (c--, d--, d < 0 || a[c] !== E[d]) {
271
+ if (c--, d--, d < 0 || a[c] !== g[d]) {
272
272
  var m = `
273
273
  ` + a[c].replace(" at new ", " at ");
274
274
  return e.displayName && m.includes("<anonymous>") && (m = m.replace("<anonymous>", e.displayName)), typeof e == "function" && U.set(e, m), m;
@@ -335,8 +335,8 @@ function br() {
335
335
  var a = void 0;
336
336
  try {
337
337
  if (typeof e[o] != "function") {
338
- var E = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
339
- throw E.name = "Invariant Violation", E;
338
+ var g = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
339
+ throw g.name = "Invariant Violation", g;
340
340
  }
341
341
  a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
342
342
  } catch (c) {
@@ -358,17 +358,17 @@ function br() {
358
358
  }
359
359
  function Ke(e) {
360
360
  try {
361
- return ge(e), !1;
361
+ return Ee(e), !1;
362
362
  } catch {
363
363
  return !0;
364
364
  }
365
365
  }
366
- function ge(e) {
366
+ function Ee(e) {
367
367
  return "" + e;
368
368
  }
369
- function Ee(e) {
369
+ function ge(e) {
370
370
  if (Ke(e))
371
- return p("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", He(e)), ge(e);
371
+ return p("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", He(e)), Ee(e);
372
372
  }
373
373
  var I = O.ReactCurrentOwner, Xe = {
374
374
  key: !0,
@@ -452,8 +452,8 @@ function br() {
452
452
  };
453
453
  function ar(e, r, t, n, i) {
454
454
  {
455
- var u, o = {}, a = null, E = null;
456
- t !== void 0 && (Ee(t), a = "" + t), Qe(r) && (Ee(r.key), a = "" + r.key), Ze(r) && (E = r.ref, er(r, i));
455
+ var u, o = {}, a = null, g = null;
456
+ t !== void 0 && (ge(t), a = "" + t), Qe(r) && (ge(r.key), a = "" + r.key), Ze(r) && (g = r.ref, er(r, i));
457
457
  for (u in r)
458
458
  B.call(r, u) && !Xe.hasOwnProperty(u) && (o[u] = r[u]);
459
459
  if (e && e.defaultProps) {
@@ -461,11 +461,11 @@ function br() {
461
461
  for (u in c)
462
462
  o[u] === void 0 && (o[u] = c[u]);
463
463
  }
464
- if (a || E) {
464
+ if (a || g) {
465
465
  var d = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
466
- a && rr(o, d), E && tr(o, d);
466
+ a && rr(o, d), g && tr(o, d);
467
467
  }
468
- return nr(e, a, E, i, n, I.current, o);
468
+ return nr(e, a, g, i, n, I.current, o);
469
469
  }
470
470
  }
471
471
  var Z = O.ReactCurrentOwner, be = O.ReactDebugCurrentFrame;
@@ -592,8 +592,8 @@ Check the top-level render call using <` + t + ">.");
592
592
  if (!o) {
593
593
  var a = "";
594
594
  (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
595
- var E = or(i);
596
- E ? a += E : a += Re();
595
+ var g = or(i);
596
+ g ? a += g : a += Re();
597
597
  var c;
598
598
  e === null ? c = "null" : K(e) ? c = "array" : e !== void 0 && e.$$typeof === s ? (c = "<" + (T(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : c = typeof e, p("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", c, a);
599
599
  }
@@ -659,7 +659,7 @@ const Pe = [8, 10, 12, 14, 16, 24, 32, 48, 64, 72], Fe = "none", ke = "#333333",
659
659
  strokeWidth: 5
660
660
  }, Cr = 0.25, Tr = {
661
661
  font: "Roboto",
662
- fontSize: Pe[2].toString(),
662
+ fontSize: Pe[2],
663
663
  padding: Pe[2] * Cr,
664
664
  color: ke,
665
665
  strokeType: Fe,
@@ -705,7 +705,7 @@ const De = je(
705
705
  const s = hr(), [y, S] = pr(Sr, {
706
706
  type: "FeatureCollection",
707
707
  features: []
708
- }), [g, x] = D(null), [b, R] = D(_r), [v, C] = D(Tr), [l, h] = D(), [_, P] = D(1), [N, Y] = D(1);
708
+ }), [E, x] = D(null), [b, R] = D(_r), [v, C] = D(Tr), [l, h] = D(), [_, P] = D(1), [N, Y] = D(1);
709
709
  return re(() => {
710
710
  if (!s)
711
711
  return;
@@ -716,9 +716,9 @@ const De = je(
716
716
  ...b,
717
717
  strokeWidth: (b.strokeWidth || 1) * p
718
718
  }), P(p), Y(O), M.on("select", (F) => {
719
- gr(F) ? R({
719
+ Er(F) ? R({
720
720
  ...F.properties.style || {}
721
- }) : Er(F) && C({
721
+ }) : gr(F) && C({
722
722
  ...F.properties.style || {}
723
723
  }), x(F);
724
724
  }).on("unselect", () => {
@@ -727,16 +727,16 @@ const De = je(
727
727
  l == null || l.destroy();
728
728
  };
729
729
  }, [s]), re(() => {
730
- l && g && (g == null ? void 0 : g.properties.type) === "arrow" && l.updateStyle(g.id, b);
730
+ l && E && (E == null ? void 0 : E.properties.type) === "arrow" && l.updateStyle(E.id, b);
731
731
  }, [l, b]), re(() => {
732
- l && g && (g == null ? void 0 : g.properties.type) === "text" && l.updateStyle(g.id, v);
732
+ l && E && (E == null ? void 0 : E.properties.type) === "text" && l.updateStyle(E.id, v);
733
733
  }, [l, v]), /* @__PURE__ */ Rr.jsx(
734
734
  De.Provider,
735
735
  {
736
736
  value: {
737
737
  annotations: y,
738
738
  updateAnnotations: S,
739
- currentAnnotation: g,
739
+ currentAnnotation: E,
740
740
  setCurrentAnnotation: x,
741
741
  textStyle: v,
742
742
  setTextStyle: C,
@@ -24,4 +24,4 @@ Check the render method of \``+e+"`."}return""}}function Rr(e){{if(e!==void 0){v
24
24
 
25
25
  Check your code at `+r+":"+t+"."}return""}}var ke={};function br(e){{var r=je();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
26
26
 
27
- Check the top-level render call using <`+t+">.")}return r}}function De(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=br(r);if(ke[t])return;ke[t]=!0;var n="";e&&e._owner&&e._owner!==oe.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),D(e),E('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),D(null)}}function Ie(e,r){{if(typeof e!="object")return;if(ne(e))for(var t=0;t<e.length;t++){var n=e[t];ue(n)&&De(n,r)}else if(ue(e))e._store&&(e._store.validated=!0);else if(e){var i=U(e);if(typeof i=="function"&&i!==e.entries)for(var u=i.call(e),o;!(o=u.next()).done;)ue(o.value)&&De(o.value,r)}}}function _r(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===y||r.$$typeof===R))t=r.propTypes;else return;if(t){var n=w(r);sr(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ie){ie=!0;var i=w(r);E("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&E("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Cr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){D(e),E("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),D(null);break}}e.ref!==null&&(D(e),E("Invalid attribute `ref` supplied to `React.Fragment`."),D(null))}}function We(e,r,t,n,i,u){{var o=rr(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var m=Rr(i);m?a+=m:a+=je();var d;e===null?d="null":ne(e)?d="array":e!==void 0&&e.$$typeof===s?(d="<"+(w(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):d=typeof e,E("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",d,a)}var v=mr(e,r,t,i,u);if(v==null)return v;if(o){var b=r.children;if(b!==void 0)if(n)if(ne(b)){for(var I=0;I<b.length;I++)Ie(b[I],e);Object.freeze&&Object.freeze(b)}else E("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ie(b,e)}return e===O?Cr(v):_r(v),v}}function Tr(e,r,t){return We(e,r,t,!0)}function Sr(e,r,t){return We(e,r,t,!1)}var wr=Sr,Pr=Tr;N.Fragment=O,N.jsx=wr,N.jsxs=Pr}()),N}process.env.NODE_ENV==="production"?X.exports=Ye():X.exports=Me();var Ve=X.exports;const Z=[8,10,12,14,16,24,32,48,64,72],Q="none",q="#333333",Ue=["#FFFFFF","#F44E3B","#FE9200","#FCDC00","#A4DD00","#68CCCA","#73D8FF","#AEA1FF","#1E88E5","#333333","#808080","#cccccc"],ze=["Roboto","Helvetica Neue","Helvetica","Arial","sans-serif","Georgia, serif","Menlo","Monaco","Consolas","Courier New","monospace"].sort((c,s)=>c.toLocaleLowerCase().localeCompare(s.toLocaleLowerCase())),fe={head:"arrow",strokeColor:q,strokeWidth:5},ce=.25,de={font:"Roboto",fontSize:Z[2].toString(),padding:Z[2]*ce,color:q,strokeType:Q,background:Q};function ve(c){return c.reduce((s,g)=>s+g,0)/c.length}function Be(c,s=0,g=1){return s+(g-s)*c}function Ge(c,s=0,g=1){return(c-s)/(g-s)}function Je(){return p.createContext(null)}const $=p.createContext(void 0),He=()=>p.useContext($),Ke=(c,s)=>{switch(s.type){case"add":return{...c,features:[...c.features,s.payload]};case"remove":return{...c,features:c.features.filter(g=>g.id!==s.payload.id)};case"update":return{...c,features:c.features.map(g=>g.id===s.payload.id?s.payload:g)};default:return c}},Xe=({children:c})=>{const s=Le.useOgma(),[g,O]=p.useReducer(Ke,{type:"FeatureCollection",features:[]}),[h,x]=p.useState(null),[_,C]=p.useState(fe),[y,S]=p.useState(de),[l,R]=p.useState(),[T,F]=p.useState(1),[M,V]=p.useState(1);return p.useEffect(()=>{if(!s)return;const U=new K.Control(s,{minArrowHeight:1}),A=ve(s.getNodes().getAttribute("radius"))/5,E=T;return C({..._,strokeWidth:(_.strokeWidth||1)*E}),F(E),V(A),U.on("select",j=>{K.isArrow(j)?C({...j.properties.style||{}}):K.isText(j)&&S({...j.properties.style||{}}),x(j)}).on("unselect",()=>{x(null)}),R(U),()=>{l==null||l.destroy()}},[s]),p.useEffect(()=>{l&&h&&(h==null?void 0:h.properties.type)==="arrow"&&l.updateStyle(h.id,_)},[l,_]),p.useEffect(()=>{l&&h&&(h==null?void 0:h.properties.type)==="text"&&l.updateStyle(h.id,y)},[l,y]),Ve.jsx($.Provider,{value:{annotations:g,updateAnnotations:O,currentAnnotation:h,setCurrentAnnotation:x,textStyle:y,setTextStyle:S,arrowStyle:_,setArrowStyle:C,arrowWidthFactor:T,setArrowWidthFactor:F,textSizeFactor:M,setTextSizeFactor:V,editor:l,setEditor:R},children:c})};f.AnnotationsContext=$,f.AnnotationsContextProvider=Xe,f.BLACK=q,f.RELATIVE_PADDING=ce,f.TRANSPARENT=Q,f.createAnnotationsContext=Je,f.defaultArrowStyle=fe,f.defaultColors=Ue,f.defaultTextStyle=de,f.fontSizes=Z,f.fonts=ze,f.interpolate=Be,f.mean=ve,f.normalize=Ge,f.useAnnotationsContext=He,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
27
+ Check the top-level render call using <`+t+">.")}return r}}function De(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=br(r);if(ke[t])return;ke[t]=!0;var n="";e&&e._owner&&e._owner!==oe.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),D(e),E('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),D(null)}}function Ie(e,r){{if(typeof e!="object")return;if(ne(e))for(var t=0;t<e.length;t++){var n=e[t];ue(n)&&De(n,r)}else if(ue(e))e._store&&(e._store.validated=!0);else if(e){var i=U(e);if(typeof i=="function"&&i!==e.entries)for(var u=i.call(e),o;!(o=u.next()).done;)ue(o.value)&&De(o.value,r)}}}function _r(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===y||r.$$typeof===R))t=r.propTypes;else return;if(t){var n=w(r);sr(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ie){ie=!0;var i=w(r);E("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&E("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Cr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){D(e),E("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),D(null);break}}e.ref!==null&&(D(e),E("Invalid attribute `ref` supplied to `React.Fragment`."),D(null))}}function We(e,r,t,n,i,u){{var o=rr(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var m=Rr(i);m?a+=m:a+=je();var d;e===null?d="null":ne(e)?d="array":e!==void 0&&e.$$typeof===s?(d="<"+(w(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):d=typeof e,E("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",d,a)}var v=mr(e,r,t,i,u);if(v==null)return v;if(o){var b=r.children;if(b!==void 0)if(n)if(ne(b)){for(var I=0;I<b.length;I++)Ie(b[I],e);Object.freeze&&Object.freeze(b)}else E("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ie(b,e)}return e===O?Cr(v):_r(v),v}}function Tr(e,r,t){return We(e,r,t,!0)}function Sr(e,r,t){return We(e,r,t,!1)}var wr=Sr,Pr=Tr;N.Fragment=O,N.jsx=wr,N.jsxs=Pr}()),N}process.env.NODE_ENV==="production"?X.exports=Ye():X.exports=Me();var Ve=X.exports;const Z=[8,10,12,14,16,24,32,48,64,72],Q="none",q="#333333",Ue=["#FFFFFF","#F44E3B","#FE9200","#FCDC00","#A4DD00","#68CCCA","#73D8FF","#AEA1FF","#1E88E5","#333333","#808080","#cccccc"],ze=["Roboto","Helvetica Neue","Helvetica","Arial","sans-serif","Georgia, serif","Menlo","Monaco","Consolas","Courier New","monospace"].sort((c,s)=>c.toLocaleLowerCase().localeCompare(s.toLocaleLowerCase())),fe={head:"arrow",strokeColor:q,strokeWidth:5},ce=.25,de={font:"Roboto",fontSize:Z[2],padding:Z[2]*ce,color:q,strokeType:Q,background:Q};function ve(c){return c.reduce((s,g)=>s+g,0)/c.length}function Be(c,s=0,g=1){return s+(g-s)*c}function Ge(c,s=0,g=1){return(c-s)/(g-s)}function Je(){return p.createContext(null)}const $=p.createContext(void 0),He=()=>p.useContext($),Ke=(c,s)=>{switch(s.type){case"add":return{...c,features:[...c.features,s.payload]};case"remove":return{...c,features:c.features.filter(g=>g.id!==s.payload.id)};case"update":return{...c,features:c.features.map(g=>g.id===s.payload.id?s.payload:g)};default:return c}},Xe=({children:c})=>{const s=Le.useOgma(),[g,O]=p.useReducer(Ke,{type:"FeatureCollection",features:[]}),[h,x]=p.useState(null),[_,C]=p.useState(fe),[y,S]=p.useState(de),[l,R]=p.useState(),[T,F]=p.useState(1),[M,V]=p.useState(1);return p.useEffect(()=>{if(!s)return;const U=new K.Control(s,{minArrowHeight:1}),A=ve(s.getNodes().getAttribute("radius"))/5,E=T;return C({..._,strokeWidth:(_.strokeWidth||1)*E}),F(E),V(A),U.on("select",j=>{K.isArrow(j)?C({...j.properties.style||{}}):K.isText(j)&&S({...j.properties.style||{}}),x(j)}).on("unselect",()=>{x(null)}),R(U),()=>{l==null||l.destroy()}},[s]),p.useEffect(()=>{l&&h&&(h==null?void 0:h.properties.type)==="arrow"&&l.updateStyle(h.id,_)},[l,_]),p.useEffect(()=>{l&&h&&(h==null?void 0:h.properties.type)==="text"&&l.updateStyle(h.id,y)},[l,y]),Ve.jsx($.Provider,{value:{annotations:g,updateAnnotations:O,currentAnnotation:h,setCurrentAnnotation:x,textStyle:y,setTextStyle:S,arrowStyle:_,setArrowStyle:C,arrowWidthFactor:T,setArrowWidthFactor:F,textSizeFactor:M,setTextSizeFactor:V,editor:l,setEditor:R},children:c})};f.AnnotationsContext=$,f.AnnotationsContextProvider=Xe,f.BLACK=q,f.RELATIVE_PADDING=ce,f.TRANSPARENT=Q,f.createAnnotationsContext=Je,f.defaultArrowStyle=fe,f.defaultColors=Ue,f.defaultTextStyle=de,f.fontSizes=Z,f.fonts=ze,f.interpolate=Be,f.mean=ve,f.normalize=Ge,f.useAnnotationsContext=He,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linkurious/ogma-annotations-react",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "A react component to add ogma annotations with react",
5
5
  "main": "dist/ogma-annotations-react.mjs",
6
6
  "module": "dist/ogma-annotations-react.mjs",
@@ -48,8 +48,8 @@
48
48
  "author": "Linkurious SAS",
49
49
  "license": "Apache-2.0",
50
50
  "peerDependencies": {
51
- "@linkurious/ogma": "4.5.6",
52
- "@linkurious/ogma-annotations": "^1.1.2",
51
+ "@linkurious/ogma": ">=4.5.6",
52
+ "@linkurious/ogma-annotations": "^1.1.4",
53
53
  "@linkurious/ogma-react": ">=4.6.1",
54
54
  "react": "18.2.0"
55
55
  },