image-js 1.0.0 → 1.2.0

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 (140) hide show
  1. package/dist/image-js.esm.js +1041 -245
  2. package/dist/image-js.esm.js.map +1 -1
  3. package/dist/image-js.esm.min.js +2 -2
  4. package/dist/image-js.esm.min.js.map +1 -1
  5. package/dist/image-js.umd.js +1009 -211
  6. package/dist/image-js.umd.js.map +1 -1
  7. package/dist/image-js.umd.min.js +2 -2
  8. package/dist/image-js.umd.min.js.map +1 -1
  9. package/dist-types/image-js.d.ts +4 -5
  10. package/lib/Mask.d.ts +1 -1
  11. package/lib/Mask.js +1 -1
  12. package/lib/draw/drawLineOnImage.d.ts.map +1 -1
  13. package/lib/draw/drawLineOnImage.js.map +1 -1
  14. package/lib/extra/draw/draw_text.d.ts +47 -0
  15. package/lib/extra/draw/draw_text.d.ts.map +1 -0
  16. package/lib/extra/draw/draw_text.js +108 -0
  17. package/lib/extra/draw/draw_text.js.map +1 -0
  18. package/lib/extra/draw/index.d.ts +3 -0
  19. package/lib/extra/draw/index.d.ts.map +1 -0
  20. package/lib/extra/draw/index.js +3 -0
  21. package/lib/extra/draw/index.js.map +1 -0
  22. package/lib/{ssim → extra/ssim}/compute_dssim.d.ts +2 -2
  23. package/lib/extra/ssim/compute_dssim.d.ts.map +1 -0
  24. package/lib/{ssim → extra/ssim}/compute_dssim.js +1 -1
  25. package/lib/extra/ssim/compute_dssim.js.map +1 -0
  26. package/lib/{ssim → extra/ssim}/compute_ssim.d.ts +1 -1
  27. package/lib/extra/ssim/compute_ssim.d.ts.map +1 -0
  28. package/lib/{ssim → extra/ssim}/compute_ssim.js +2 -2
  29. package/lib/extra/ssim/compute_ssim.js.map +1 -0
  30. package/lib/extra/ssim/index.d.ts +3 -0
  31. package/lib/extra/ssim/index.d.ts.map +1 -0
  32. package/lib/extra/ssim/index.js +3 -0
  33. package/lib/extra/ssim/index.js.map +1 -0
  34. package/lib/featureMatching/matching/filterEuclideanDistance.d.ts.map +1 -1
  35. package/lib/featureMatching/matching/filterEuclideanDistance.js +6 -7
  36. package/lib/featureMatching/matching/filterEuclideanDistance.js.map +1 -1
  37. package/lib/featureMatching/matching/filterSmallestDistanceMatches.d.ts.map +1 -1
  38. package/lib/featureMatching/matching/filterSmallestDistanceMatches.js +6 -3
  39. package/lib/featureMatching/matching/filterSmallestDistanceMatches.js.map +1 -1
  40. package/lib/featureMatching/utils/sortByDistance.d.ts.map +1 -1
  41. package/lib/featureMatching/utils/sortByDistance.js +3 -1
  42. package/lib/featureMatching/utils/sortByDistance.js.map +1 -1
  43. package/lib/featureMatching/utils/sortBySourceDest.d.ts.map +1 -1
  44. package/lib/featureMatching/utils/sortBySourceDest.js +6 -2
  45. package/lib/featureMatching/utils/sortBySourceDest.js.map +1 -1
  46. package/lib/index_browser.d.ts +3 -0
  47. package/lib/index_browser.d.ts.map +1 -0
  48. package/lib/index_browser.js +5 -0
  49. package/lib/index_browser.js.map +1 -0
  50. package/lib/index_full.d.ts +4 -0
  51. package/lib/index_full.d.ts.map +1 -0
  52. package/lib/index_full.js +5 -0
  53. package/lib/index_full.js.map +1 -0
  54. package/lib/load/decode.d.ts.map +1 -1
  55. package/lib/load/decode.js +2 -0
  56. package/lib/load/decode.js.map +1 -1
  57. package/lib/load/decodeBmp.d.ts +8 -0
  58. package/lib/load/decodeBmp.d.ts.map +1 -0
  59. package/lib/load/decodeBmp.js +36 -0
  60. package/lib/load/decodeBmp.js.map +1 -0
  61. package/lib/load/decodePng.d.ts.map +1 -1
  62. package/lib/load/decodePng.js +29 -5
  63. package/lib/load/decodePng.js.map +1 -1
  64. package/lib/load/decodeTiff.d.ts.map +1 -1
  65. package/lib/load/decodeTiff.js +44 -21
  66. package/lib/load/decodeTiff.js.map +1 -1
  67. package/lib/load/read.d.ts +1 -1
  68. package/lib/load/read.js +1 -1
  69. package/lib/maskAnalysis/utils/getMbrAngle.d.ts.map +1 -1
  70. package/lib/maskAnalysis/utils/getMbrAngle.js +2 -1
  71. package/lib/maskAnalysis/utils/getMbrAngle.js.map +1 -1
  72. package/lib/maskAnalysis/utils/monotoneChainConvexHull.d.ts.map +1 -1
  73. package/lib/maskAnalysis/utils/monotoneChainConvexHull.js +2 -1
  74. package/lib/maskAnalysis/utils/monotoneChainConvexHull.js.map +1 -1
  75. package/lib/save/encodeBmp.d.ts +4 -4
  76. package/lib/save/encodeBmp.d.ts.map +1 -1
  77. package/lib/save/encodeBmp.js +22 -14
  78. package/lib/save/encodeBmp.js.map +1 -1
  79. package/lib/save/write.d.ts +1 -1
  80. package/lib/save/write.js +1 -1
  81. package/lib/stack/load/decodeApng.d.ts +8 -0
  82. package/lib/stack/load/decodeApng.d.ts.map +1 -0
  83. package/lib/stack/load/decodeApng.js +60 -0
  84. package/lib/stack/load/decodeApng.js.map +1 -0
  85. package/lib/stack/load/decodeStack.d.ts.map +1 -1
  86. package/lib/stack/load/decodeStack.js +2 -0
  87. package/lib/stack/load/decodeStack.js.map +1 -1
  88. package/lib/utils/cross_platform.d.ts +8 -0
  89. package/lib/utils/cross_platform.d.ts.map +1 -1
  90. package/lib/utils/cross_platform.js +34 -2
  91. package/lib/utils/cross_platform.js.map +1 -1
  92. package/lib/utils/geometry/points.d.ts.map +1 -1
  93. package/lib/utils/geometry/points.js +3 -1
  94. package/lib/utils/geometry/points.js.map +1 -1
  95. package/lib/utils/geometry/removeClosePoints.d.ts.map +1 -1
  96. package/lib/utils/geometry/removeClosePoints.js +2 -1
  97. package/lib/utils/geometry/removeClosePoints.js.map +1 -1
  98. package/lib/utils/setBlendedPixel.d.ts +1 -1
  99. package/lib/utils/setBlendedPixel.js +1 -1
  100. package/lib/utils/setBlendedVisiblePixel.d.ts +1 -1
  101. package/lib/utils/setBlendedVisiblePixel.js +1 -1
  102. package/package.json +43 -29
  103. package/src/Mask.ts +1 -1
  104. package/src/draw/drawLineOnImage.ts +0 -1
  105. package/src/extra/draw/draw_text.ts +194 -0
  106. package/src/extra/draw/index.ts +2 -0
  107. package/src/{ssim → extra/ssim}/compute_dssim.ts +3 -3
  108. package/src/{ssim → extra/ssim}/compute_ssim.ts +3 -3
  109. package/src/extra/ssim/index.ts +2 -0
  110. package/src/featureMatching/matching/filterEuclideanDistance.ts +6 -13
  111. package/src/featureMatching/matching/filterSmallestDistanceMatches.ts +6 -9
  112. package/src/featureMatching/utils/sortByDistance.ts +3 -1
  113. package/src/featureMatching/utils/sortBySourceDest.ts +6 -2
  114. package/src/index_browser.ts +4 -0
  115. package/src/index_full.ts +4 -0
  116. package/src/load/decode.ts +2 -1
  117. package/src/load/decodeBmp.ts +37 -0
  118. package/src/load/decodePng.ts +39 -7
  119. package/src/load/decodeTiff.ts +53 -22
  120. package/src/load/read.ts +1 -1
  121. package/src/maskAnalysis/utils/getMbrAngle.ts +2 -1
  122. package/src/maskAnalysis/utils/monotoneChainConvexHull.ts +2 -1
  123. package/src/save/encodeBmp.ts +22 -15
  124. package/src/save/write.ts +1 -1
  125. package/src/stack/load/decodeApng.ts +71 -0
  126. package/src/stack/load/decodeStack.ts +2 -0
  127. package/src/utils/cross_platform.ts +47 -4
  128. package/src/utils/geometry/points.ts +3 -1
  129. package/src/utils/geometry/removeClosePoints.ts +2 -1
  130. package/src/utils/setBlendedPixel.ts +1 -1
  131. package/src/utils/setBlendedVisiblePixel.ts +1 -1
  132. package/lib/ssim/compute_dssim.d.ts.map +0 -1
  133. package/lib/ssim/compute_dssim.js.map +0 -1
  134. package/lib/ssim/compute_ssim.d.ts.map +0 -1
  135. package/lib/ssim/compute_ssim.js.map +0 -1
  136. package/lib/ssim/index.d.ts +0 -3
  137. package/lib/ssim/index.d.ts.map +0 -1
  138. package/lib/ssim/index.js +0 -3
  139. package/lib/ssim/index.js.map +0 -1
  140. package/src/ssim/index.ts +0 -2
@@ -1,5 +1,5 @@
1
1
  /*
2
- * image-js v1.0.0
2
+ * image-js v1.2.0
3
3
  * Image processing and manipulation in JavaScript
4
4
  * https://github.com/image-js/image-js#readme
5
5
  *
@@ -5109,11 +5109,11 @@ matrix.solve = solve;
5109
5109
  matrix.wrap = wrap;
5110
5110
 
5111
5111
  const EigenvalueDecomposition = EigenvalueDecomposition_1;
5112
- const Matrix = Matrix_1;
5112
+ const Matrix$1 = Matrix_1;
5113
5113
  const SVD = SVD$1;
5114
5114
  const SingularValueDecomposition = SingularValueDecomposition_1;
5115
5115
  const WrapperMatrix1D = WrapperMatrix1D_1;
5116
- var Matrix$1 = _default.Matrix ? _default.Matrix : Matrix_1;
5116
+ var Matrix = _default.Matrix ? _default.Matrix : Matrix_1;
5117
5117
  const determinant = determinant_1;
5118
5118
  const inverse = inverse_1;
5119
5119
  const pseudoInverse = pseudoInverse_1;
@@ -5125,7 +5125,7 @@ const pseudoInverse = pseudoInverse_1;
5125
5125
  * @returns The centroid.
5126
5126
  */
5127
5127
  function getCentroid(points) {
5128
- let result = new Matrix$1(3, 1);
5128
+ let result = new Matrix(3, 1);
5129
5129
  const nbPoints = points.columns;
5130
5130
  let xSum = 0;
5131
5131
  let ySum = 0;
@@ -5166,7 +5166,7 @@ function getAffineTransform$1(source, destination) {
5166
5166
  ratioSum += getDistanceToOrigin(destinationPoint) / getDistanceToOrigin(sourcePoint);
5167
5167
  }
5168
5168
  const scale = ratioSum / nbPoints;
5169
- const scaledSource = Matrix$1.mul(translatedSource, scale);
5169
+ const scaledSource = Matrix.mul(translatedSource, scale);
5170
5170
  // computing rotation
5171
5171
  const covarianceMatrix = scaledSource.mmul(translatedDestination.transpose());
5172
5172
  const svd = new SingularValueDecomposition(covarianceMatrix);
@@ -5182,7 +5182,7 @@ function getAffineTransform$1(source, destination) {
5182
5182
  angleDegrees = 180;
5183
5183
  }
5184
5184
  // computing translation
5185
- const translation = Matrix$1.sub(destinationCentroid, Matrix$1.mul(rotation.mmul(sourceCentroid), scale));
5185
+ const translation = Matrix.sub(destinationCentroid, Matrix.mul(rotation.mmul(sourceCentroid), scale));
5186
5186
  return {
5187
5187
  translation: {
5188
5188
  x: translation.get(0, 0),
@@ -5694,11 +5694,13 @@ function rotate$1(radians, points) {
5694
5694
  * @returns Sorted points.
5695
5695
  */
5696
5696
  function sortByColumnRow(points) {
5697
- return points.slice().sort((point1, point2) => {
5697
+ const sortedPoints = points.slice();
5698
+ sortedPoints.sort((point1, point2) => {
5698
5699
  if (point1.column < point2.column) return -1;
5699
5700
  if (point1.column > point2.column) return 1;
5700
5701
  return point1.row - point2.row;
5701
5702
  });
5703
+ return sortedPoints;
5702
5704
  }
5703
5705
 
5704
5706
  /**
@@ -5790,35 +5792,35 @@ const t$2 = Symbol.for("@ts-pattern/matcher"),
5790
5792
  if (!Array.isArray(s)) return false;
5791
5793
  let t = [],
5792
5794
  r = [],
5793
- a = [];
5795
+ u = [];
5794
5796
  for (const o of n.keys()) {
5795
5797
  const s = n[o];
5796
- i$2(s) && s[e$2] ? a.push(s) : a.length ? r.push(s) : t.push(s);
5798
+ i$2(s) && s[e$2] ? u.push(s) : u.length ? r.push(s) : t.push(s);
5797
5799
  }
5798
- if (a.length) {
5799
- if (a.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
5800
+ if (u.length) {
5801
+ if (u.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
5800
5802
  if (s.length < t.length + r.length) return false;
5801
5803
  const e = s.slice(0, t.length),
5802
5804
  n = 0 === r.length ? [] : s.slice(-r.length),
5803
5805
  i = s.slice(t.length, 0 === r.length ? Infinity : -r.length);
5804
- return t.every((t, n) => o$2(t, e[n], c)) && r.every((t, e) => o$2(t, n[e], c)) && (0 === a.length || o$2(a[0], i, c));
5806
+ return t.every((t, n) => o$2(t, e[n], c)) && r.every((t, e) => o$2(t, n[e], c)) && (0 === u.length || o$2(u[0], i, c));
5805
5807
  }
5806
5808
  return n.length === s.length && n.every((t, e) => o$2(t, s[e], c));
5807
5809
  }
5808
5810
  return Reflect.ownKeys(n).every(e => {
5809
5811
  const r = n[e];
5810
- return (e in s || i$2(a = r) && "optional" === a[t$2]().matcherType) && o$2(r, s[e], c);
5811
- var a;
5812
+ return (e in s || i$2(u = r) && "optional" === u[t$2]().matcherType) && o$2(r, s[e], c);
5813
+ var u;
5812
5814
  });
5813
5815
  }
5814
5816
  return Object.is(s, n);
5815
5817
  },
5816
5818
  s$1 = e => {
5817
- var n, o, a;
5818
- return r$2(e) ? i$2(e) ? null != (n = null == (o = (a = e[t$2]()).getSelectionKeys) ? void 0 : o.call(a)) ? n : [] : Array.isArray(e) ? c$1(e, s$1) : c$1(Object.values(e), s$1) : [];
5819
+ var n, o, u;
5820
+ return r$2(e) ? i$2(e) ? null != (n = null == (o = (u = e[t$2]()).getSelectionKeys) ? void 0 : o.call(u)) ? n : [] : Array.isArray(e) ? c$1(e, s$1) : c$1(Object.values(e), s$1) : [];
5819
5821
  },
5820
5822
  c$1 = (t, e) => t.reduce((t, n) => t.concat(e(n)), []);
5821
- function a$2(...t) {
5823
+ function u$2(...t) {
5822
5824
  if (1 === t.length) {
5823
5825
  const [e] = t;
5824
5826
  return t => o$2(e, t, () => {});
@@ -5829,15 +5831,15 @@ function a$2(...t) {
5829
5831
  }
5830
5832
  throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`);
5831
5833
  }
5832
- function u$2(t) {
5834
+ function a$2(t) {
5833
5835
  return Object.assign(t, {
5834
- optional: () => l$2(t),
5835
- and: e => m$1(t, e),
5836
- or: e => d$1(t, e),
5837
- select: e => void 0 === e ? y$1(t) : y$1(e, t)
5836
+ optional: () => h$2(t),
5837
+ and: e => d$1(t, e),
5838
+ or: e => y$1(t, e),
5839
+ select: e => void 0 === e ? v$1(t) : v$1(e, t)
5838
5840
  });
5839
5841
  }
5840
- function h$2(t) {
5842
+ function l$2(t) {
5841
5843
  return Object.assign((t => Object.assign(t, {
5842
5844
  [Symbol.iterator]() {
5843
5845
  let n = 0;
@@ -5858,12 +5860,12 @@ function h$2(t) {
5858
5860
  };
5859
5861
  }
5860
5862
  }))(t), {
5861
- optional: () => h$2(l$2(t)),
5862
- select: e => h$2(void 0 === e ? y$1(t) : y$1(e, t))
5863
+ optional: () => l$2(h$2(t)),
5864
+ select: e => l$2(void 0 === e ? v$1(t) : v$1(e, t))
5863
5865
  });
5864
5866
  }
5865
- function l$2(e) {
5866
- return u$2({
5867
+ function h$2(e) {
5868
+ return a$2({
5867
5869
  [t$2]: () => ({
5868
5870
  match: t => {
5869
5871
  let n = {};
@@ -5890,9 +5892,14 @@ const f$1 = (t, e) => {
5890
5892
  g$1 = (t, e) => {
5891
5893
  for (const [n, r] of t.entries()) if (!e(r, n)) return false;
5892
5894
  return true;
5895
+ },
5896
+ m$1 = (t, e) => {
5897
+ const n = Reflect.ownKeys(t);
5898
+ for (const r of n) if (!e(r, t[r])) return false;
5899
+ return true;
5893
5900
  };
5894
- function m$1(...e) {
5895
- return u$2({
5901
+ function d$1(...e) {
5902
+ return a$2({
5896
5903
  [t$2]: () => ({
5897
5904
  match: t => {
5898
5905
  let n = {};
@@ -5909,8 +5916,8 @@ function m$1(...e) {
5909
5916
  })
5910
5917
  });
5911
5918
  }
5912
- function d$1(...e) {
5913
- return u$2({
5919
+ function y$1(...e) {
5920
+ return a$2({
5914
5921
  [t$2]: () => ({
5915
5922
  match: t => {
5916
5923
  let n = {};
@@ -5936,10 +5943,10 @@ function p$2(e) {
5936
5943
  })
5937
5944
  };
5938
5945
  }
5939
- function y$1(...e) {
5946
+ function v$1(...e) {
5940
5947
  const r = "string" == typeof e[0] ? e[0] : void 0,
5941
5948
  i = 2 === e.length ? e[1] : "string" == typeof e[0] ? void 0 : e[0];
5942
- return u$2({
5949
+ return a$2({
5943
5950
  [t$2]: () => ({
5944
5951
  match: t => {
5945
5952
  let e = {
@@ -5956,81 +5963,83 @@ function y$1(...e) {
5956
5963
  })
5957
5964
  });
5958
5965
  }
5959
- function v$1(t) {
5966
+ function b$2(t) {
5967
+ return true;
5968
+ }
5969
+ function w$2(t) {
5960
5970
  return "number" == typeof t;
5961
5971
  }
5962
- function b$2(t) {
5972
+ function S$1(t) {
5963
5973
  return "string" == typeof t;
5964
5974
  }
5965
- function w$2(t) {
5975
+ function j$1(t) {
5966
5976
  return "bigint" == typeof t;
5967
5977
  }
5968
- const S$1 = u$2(p$2(function (t) {
5969
- return true;
5970
- })),
5971
- O = S$1,
5972
- j$1 = t => Object.assign(u$2(t), {
5978
+ const K = a$2(p$2(b$2)),
5979
+ O = a$2(p$2(b$2)),
5980
+ E = K,
5981
+ x$1 = t => Object.assign(a$2(t), {
5973
5982
  startsWith: e => {
5974
- return j$1(m$1(t, (n = e, p$2(t => b$2(t) && t.startsWith(n)))));
5983
+ return x$1(d$1(t, (n = e, p$2(t => S$1(t) && t.startsWith(n)))));
5975
5984
  var n;
5976
5985
  },
5977
5986
  endsWith: e => {
5978
- return j$1(m$1(t, (n = e, p$2(t => b$2(t) && t.endsWith(n)))));
5987
+ return x$1(d$1(t, (n = e, p$2(t => S$1(t) && t.endsWith(n)))));
5979
5988
  var n;
5980
5989
  },
5981
- minLength: e => j$1(m$1(t, (t => p$2(e => b$2(e) && e.length >= t))(e))),
5982
- length: e => j$1(m$1(t, (t => p$2(e => b$2(e) && e.length === t))(e))),
5983
- maxLength: e => j$1(m$1(t, (t => p$2(e => b$2(e) && e.length <= t))(e))),
5990
+ minLength: e => x$1(d$1(t, (t => p$2(e => S$1(e) && e.length >= t))(e))),
5991
+ length: e => x$1(d$1(t, (t => p$2(e => S$1(e) && e.length === t))(e))),
5992
+ maxLength: e => x$1(d$1(t, (t => p$2(e => S$1(e) && e.length <= t))(e))),
5984
5993
  includes: e => {
5985
- return j$1(m$1(t, (n = e, p$2(t => b$2(t) && t.includes(n)))));
5994
+ return x$1(d$1(t, (n = e, p$2(t => S$1(t) && t.includes(n)))));
5986
5995
  var n;
5987
5996
  },
5988
5997
  regex: e => {
5989
- return j$1(m$1(t, (n = e, p$2(t => b$2(t) && Boolean(t.match(n))))));
5998
+ return x$1(d$1(t, (n = e, p$2(t => S$1(t) && Boolean(t.match(n))))));
5990
5999
  var n;
5991
6000
  }
5992
6001
  }),
5993
- K = j$1(p$2(b$2)),
5994
- x$2 = t => Object.assign(u$2(t), {
5995
- between: (e, n) => x$2(m$1(t, ((t, e) => p$2(n => v$1(n) && t <= n && e >= n))(e, n))),
5996
- lt: e => x$2(m$1(t, (t => p$2(e => v$1(e) && e < t))(e))),
5997
- gt: e => x$2(m$1(t, (t => p$2(e => v$1(e) && e > t))(e))),
5998
- lte: e => x$2(m$1(t, (t => p$2(e => v$1(e) && e <= t))(e))),
5999
- gte: e => x$2(m$1(t, (t => p$2(e => v$1(e) && e >= t))(e))),
6000
- int: () => x$2(m$1(t, p$2(t => v$1(t) && Number.isInteger(t)))),
6001
- finite: () => x$2(m$1(t, p$2(t => v$1(t) && Number.isFinite(t)))),
6002
- positive: () => x$2(m$1(t, p$2(t => v$1(t) && t > 0))),
6003
- negative: () => x$2(m$1(t, p$2(t => v$1(t) && t < 0)))
6002
+ A = x$1(p$2(S$1)),
6003
+ N$1 = t => Object.assign(a$2(t), {
6004
+ between: (e, n) => N$1(d$1(t, ((t, e) => p$2(n => w$2(n) && t <= n && e >= n))(e, n))),
6005
+ lt: e => N$1(d$1(t, (t => p$2(e => w$2(e) && e < t))(e))),
6006
+ gt: e => N$1(d$1(t, (t => p$2(e => w$2(e) && e > t))(e))),
6007
+ lte: e => N$1(d$1(t, (t => p$2(e => w$2(e) && e <= t))(e))),
6008
+ gte: e => N$1(d$1(t, (t => p$2(e => w$2(e) && e >= t))(e))),
6009
+ int: () => N$1(d$1(t, p$2(t => w$2(t) && Number.isInteger(t)))),
6010
+ finite: () => N$1(d$1(t, p$2(t => w$2(t) && Number.isFinite(t)))),
6011
+ positive: () => N$1(d$1(t, p$2(t => w$2(t) && t > 0))),
6012
+ negative: () => N$1(d$1(t, p$2(t => w$2(t) && t < 0)))
6004
6013
  }),
6005
- E = x$2(p$2(v$1)),
6006
- A = t => Object.assign(u$2(t), {
6007
- between: (e, n) => A(m$1(t, ((t, e) => p$2(n => w$2(n) && t <= n && e >= n))(e, n))),
6008
- lt: e => A(m$1(t, (t => p$2(e => w$2(e) && e < t))(e))),
6009
- gt: e => A(m$1(t, (t => p$2(e => w$2(e) && e > t))(e))),
6010
- lte: e => A(m$1(t, (t => p$2(e => w$2(e) && e <= t))(e))),
6011
- gte: e => A(m$1(t, (t => p$2(e => w$2(e) && e >= t))(e))),
6012
- positive: () => A(m$1(t, p$2(t => w$2(t) && t > 0))),
6013
- negative: () => A(m$1(t, p$2(t => w$2(t) && t < 0)))
6014
+ P = N$1(p$2(w$2)),
6015
+ k$1 = t => Object.assign(a$2(t), {
6016
+ between: (e, n) => k$1(d$1(t, ((t, e) => p$2(n => j$1(n) && t <= n && e >= n))(e, n))),
6017
+ lt: e => k$1(d$1(t, (t => p$2(e => j$1(e) && e < t))(e))),
6018
+ gt: e => k$1(d$1(t, (t => p$2(e => j$1(e) && e > t))(e))),
6019
+ lte: e => k$1(d$1(t, (t => p$2(e => j$1(e) && e <= t))(e))),
6020
+ gte: e => k$1(d$1(t, (t => p$2(e => j$1(e) && e >= t))(e))),
6021
+ positive: () => k$1(d$1(t, p$2(t => j$1(t) && t > 0))),
6022
+ negative: () => k$1(d$1(t, p$2(t => j$1(t) && t < 0)))
6014
6023
  }),
6015
- P = A(p$2(w$2)),
6016
- T$1 = u$2(p$2(function (t) {
6024
+ T = k$1(p$2(j$1)),
6025
+ B = a$2(p$2(function (t) {
6017
6026
  return "boolean" == typeof t;
6018
6027
  })),
6019
- B = u$2(p$2(function (t) {
6028
+ _ = a$2(p$2(function (t) {
6020
6029
  return "symbol" == typeof t;
6021
6030
  })),
6022
- _ = u$2(p$2(function (t) {
6031
+ W = a$2(p$2(function (t) {
6023
6032
  return null == t;
6024
6033
  })),
6025
- k$1 = u$2(p$2(function (t) {
6034
+ $$1 = a$2(p$2(function (t) {
6026
6035
  return null != t;
6027
6036
  }));
6028
- var N$1 = {
6037
+ var z = {
6029
6038
  __proto__: null,
6030
6039
  matcher: t$2,
6031
- optional: l$2,
6040
+ optional: h$2,
6032
6041
  array: function (...e) {
6033
- return h$2({
6042
+ return l$2({
6034
6043
  [t$2]: () => ({
6035
6044
  match: t => {
6036
6045
  if (!Array.isArray(t)) return {
@@ -6060,7 +6069,7 @@ var N$1 = {
6060
6069
  });
6061
6070
  },
6062
6071
  set: function (...e) {
6063
- return u$2({
6072
+ return a$2({
6064
6073
  [t$2]: () => ({
6065
6074
  match: t => {
6066
6075
  if (!(t instanceof Set)) return {
@@ -6088,7 +6097,7 @@ var N$1 = {
6088
6097
  });
6089
6098
  },
6090
6099
  map: function (...e) {
6091
- return u$2({
6100
+ return a$2({
6092
6101
  [t$2]: () => ({
6093
6102
  match: t => {
6094
6103
  if (!(t instanceof Map)) return {
@@ -6121,10 +6130,39 @@ var N$1 = {
6121
6130
  })
6122
6131
  });
6123
6132
  },
6124
- intersection: m$1,
6125
- union: d$1,
6133
+ record: function (...e) {
6134
+ return a$2({
6135
+ [t$2]: () => ({
6136
+ match: t => {
6137
+ if (null === t || "object" != typeof t || Array.isArray(t)) return {
6138
+ matched: false
6139
+ };
6140
+ var n;
6141
+ if (0 === e.length) throw new Error(`\`P.record\` wasn't given enough arguments. Expected (value) or (key, value), received ${null == (n = e[0]) ? void 0 : n.toString()}`);
6142
+ let r = {};
6143
+ const i = (t, e) => {
6144
+ r[t] = (r[t] || []).concat([e]);
6145
+ },
6146
+ [s, c] = 1 === e.length ? [A, e[0]] : e;
6147
+ return {
6148
+ matched: m$1(t, (t, e) => {
6149
+ const n = "string" != typeof t || Number.isNaN(Number(t)) ? null : Number(t),
6150
+ r = null !== n && o$2(s, n, i),
6151
+ u = o$2(s, t, i),
6152
+ a = o$2(c, e, i);
6153
+ return (u || r) && a;
6154
+ }),
6155
+ selections: r
6156
+ };
6157
+ },
6158
+ getSelectionKeys: () => 0 === e.length ? [] : [...s$1(e[0]), ...s$1(e[1])]
6159
+ })
6160
+ });
6161
+ },
6162
+ intersection: d$1,
6163
+ union: y$1,
6126
6164
  not: function (e) {
6127
- return u$2({
6165
+ return a$2({
6128
6166
  [t$2]: () => ({
6129
6167
  match: t => ({
6130
6168
  matched: !o$2(e, t, () => {})
@@ -6135,26 +6173,27 @@ var N$1 = {
6135
6173
  });
6136
6174
  },
6137
6175
  when: p$2,
6138
- select: y$1,
6139
- any: S$1,
6140
- _: O,
6141
- string: K,
6142
- number: E,
6143
- bigint: P,
6144
- boolean: T$1,
6145
- symbol: B,
6146
- nullish: _,
6147
- nonNullable: k$1,
6176
+ select: v$1,
6177
+ any: K,
6178
+ unknown: O,
6179
+ _: E,
6180
+ string: A,
6181
+ number: P,
6182
+ bigint: T,
6183
+ boolean: B,
6184
+ symbol: _,
6185
+ nullish: W,
6186
+ nonNullable: $$1,
6148
6187
  instanceOf: function (t) {
6149
- return u$2(p$2(function (t) {
6188
+ return a$2(p$2(function (t) {
6150
6189
  return e => e instanceof t;
6151
6190
  }(t)));
6152
6191
  },
6153
6192
  shape: function (t) {
6154
- return u$2(p$2(a$2(t)));
6193
+ return a$2(p$2(u$2(t)));
6155
6194
  }
6156
6195
  };
6157
- class W extends Error {
6196
+ class I extends Error {
6158
6197
  constructor(t) {
6159
6198
  let e;
6160
6199
  try {
@@ -6165,14 +6204,14 @@ class W extends Error {
6165
6204
  super(`Pattern matching error: no pattern matches value ${e}`), this.input = void 0, this.input = t;
6166
6205
  }
6167
6206
  }
6168
- const $$1 = {
6207
+ const L = {
6169
6208
  matched: false,
6170
6209
  value: void 0
6171
6210
  };
6172
- function z(t) {
6173
- return new I(t, $$1);
6211
+ function M$2(t) {
6212
+ return new R(t, L);
6174
6213
  }
6175
- class I {
6214
+ class R {
6176
6215
  constructor(t, e) {
6177
6216
  this.input = void 0, this.state = void 0, this.input = t, this.state = e;
6178
6217
  }
@@ -6184,27 +6223,27 @@ class I {
6184
6223
  3 === t.length && "function" == typeof t[1] ? i = t[1] : t.length > 2 && r.push(...t.slice(1, t.length - 1));
6185
6224
  let s = false,
6186
6225
  c = {};
6187
- const a = (t, e) => {
6226
+ const u = (t, e) => {
6188
6227
  s = true, c[t] = e;
6189
6228
  },
6190
- u = !r.some(t => o$2(t, this.input, a)) || i && !Boolean(i(this.input)) ? $$1 : {
6229
+ a = !r.some(t => o$2(t, this.input, u)) || i && !Boolean(i(this.input)) ? L : {
6191
6230
  matched: true,
6192
6231
  value: e(s ? n$2 in c ? c[n$2] : c : this.input, this.input)
6193
6232
  };
6194
- return new I(this.input, u);
6233
+ return new R(this.input, a);
6195
6234
  }
6196
6235
  when(t, e) {
6197
6236
  if (this.state.matched) return this;
6198
6237
  const n = Boolean(t(this.input));
6199
- return new I(this.input, n ? {
6238
+ return new R(this.input, n ? {
6200
6239
  matched: true,
6201
6240
  value: e(this.input, this.input)
6202
- } : $$1);
6241
+ } : L);
6203
6242
  }
6204
6243
  otherwise(t) {
6205
6244
  return this.state.matched ? this.state.value : t(this.input);
6206
6245
  }
6207
- exhaustive(t = L) {
6246
+ exhaustive(t = F) {
6208
6247
  return this.state.matched ? this.state.value : t(this.input);
6209
6248
  }
6210
6249
  run() {
@@ -6217,34 +6256,377 @@ class I {
6217
6256
  return this;
6218
6257
  }
6219
6258
  }
6220
- function L(t) {
6221
- throw new W(t);
6222
- }
6223
-
6224
- function T(f, a, i, t, M) {
6225
- const h = Math.abs(i - f),
6226
- o = f < i ? 1 : -1,
6227
- e = -Math.abs(t - a),
6228
- l = a < t ? 1 : -1;
6229
- let r = h + e,
6230
- n;
6231
- for (;;) {
6232
- if (M(f, a), n = 2 * r, n >= e) {
6233
- if (f === i) break;
6234
- r += e, f += o;
6235
- }
6236
- if (n <= h) {
6237
- if (a === t) break;
6238
- r += h, a += l;
6239
- }
6240
- }
6241
- }
6242
- function x$1(f, a, i, t) {
6243
- var M = -i,
6244
- h = 0,
6245
- o = 2 - 2 * i;
6246
- do t(f - M, a + h), t(f - h, a - M), t(f + M, a - h), t(f + h, a + M), i = o, i <= h && (o += ++h * 2 + 1), (i > M || o > h) && (o += ++M * 2 + 1); while (M < 0);
6247
- }
6259
+ function F(t) {
6260
+ throw new I(t);
6261
+ }
6262
+
6263
+ var index_umd$1 = {exports: {}};
6264
+
6265
+ var index_umd = index_umd$1.exports;
6266
+ (function (module, exports$1) {
6267
+ (function (N, J) {
6268
+ J(exports$1) ;
6269
+ })(index_umd, function (N) {
6270
+
6271
+ function J(f, a, o, t, e) {
6272
+ const h = Math.abs(o - f),
6273
+ r = f < o ? 1 : -1,
6274
+ l = -Math.abs(t - a),
6275
+ M = a < t ? 1 : -1;
6276
+ let i = h + l,
6277
+ n;
6278
+ for (;;) {
6279
+ if (e(f, a), n = 2 * i, n >= l) {
6280
+ if (f === o) break;
6281
+ i += l, f += r;
6282
+ }
6283
+ if (n <= h) {
6284
+ if (a === t) break;
6285
+ i += h, a += M;
6286
+ }
6287
+ }
6288
+ }
6289
+ function U(f, a, o, t, e) {
6290
+ const h = f < o ? 1 : -1,
6291
+ r = a < t ? 1 : -1;
6292
+ let l,
6293
+ M = Math.abs(o - f),
6294
+ i = Math.abs(t - a),
6295
+ n = M * M + i * i,
6296
+ c = n === 0 ? 1 : 1 / Math.sqrt(n);
6297
+ for (M *= c, i *= c, n = M - i;;) {
6298
+ if (e(f, a, Math.abs(n - (M + i)) >> 16), c = n, l = f, 2 * c >= -M) {
6299
+ if (f === o) break;
6300
+ c + i < 16711680 && e(f, a + r, c + i >> 16), n -= i, f += h;
6301
+ }
6302
+ if (2 * c <= i) {
6303
+ if (a === t) break;
6304
+ M - c < 16711680 && e(l + h, a, M - c >> 16), n += M, a += r;
6305
+ }
6306
+ }
6307
+ }
6308
+ function w(f, a, o, t, e, h) {
6309
+ let r = Math.abs(o - f),
6310
+ l = f < o ? 1 : -1,
6311
+ M = Math.abs(t - a),
6312
+ i = a < t ? 1 : -1,
6313
+ n = r - M,
6314
+ c,
6315
+ q,
6316
+ d,
6317
+ b = r + M == 0 ? 1 : Math.sqrt(r * r + M * M);
6318
+ for (e = (e + 1) / 2;;) {
6319
+ if (h(f, a, Math.max(0, 255 * (Math.abs(n - r + M) / b - e + 1))), c = n, q = f, 2 * c >= -r) {
6320
+ for (c += M, d = a; c < b * e && (t != d || r > M); c += r) h(f, d += i, Math.max(0, 255 * (Math.abs(c) / b - e + 1)));
6321
+ if (f == o) break;
6322
+ c = n, n -= M, f += l;
6323
+ }
6324
+ if (2 * c <= M) {
6325
+ for (c = r - c; c < b * e && (o != q || r < M); c += M) h(q += l, a, Math.max(0, 255 * (Math.abs(c) / b - e + 1)));
6326
+ if (a == t) break;
6327
+ n += r, a += i;
6328
+ }
6329
+ }
6330
+ }
6331
+ function I(f, a = "assert error") {
6332
+ if (!f) throw new Error(a);
6333
+ }
6334
+ function P(f, a, o, t, e, h, r, l) {
6335
+ var M = f - 2 * o + e,
6336
+ i = a - 2 * t + h,
6337
+ n = f - o,
6338
+ c = a - t,
6339
+ q,
6340
+ d,
6341
+ b;
6342
+ I(r >= 0, "width is negative"), n * (e - o) > 0 && (c * (h - t) > 0 && Math.abs(n * i) > Math.abs(c * M) && (f = e, e = n + o, a = h, h = c + t), f == e || r == 1 ? d = (f - o) / M : (b = Math.sqrt(4 * r * r * (f - o) * (e - o) + (e - f) * (e - f)), o < f && (b = -b), d = (2 * r * (f - o) - f + e + b) / (2 * (1 - r) * (e - f))), b = 1 / (2 * d * (1 - d) * (r - 1) + 1), n = (d * d * (f - 2 * r * o + e) + 2 * d * (r * o - f) + f) * b, c = (d * d * (a - 2 * r * t + h) + 2 * d * (r * t - a) + a) * b, q = d * (r - 1) + 1, q *= q * b, r = ((1 - d) * (r - 1) + 1) * Math.sqrt(b), M = Math.floor(n + .5), i = Math.floor(c + .5), c = (n - f) * (t - a) / (o - f) + a, H(f, a, M, Math.floor(c + .5), M, i, q, l), c = (n - e) * (t - h) / (o - e) + h, t = Math.floor(c + .5), f = o = M, a = i), (a - t) * (h - t) > 0 && (a == h || r == 1 ? d = (a - t) / (a - 2 * t + h) : (b = Math.sqrt(4 * r * r * (a - t) * (h - t) + (h - a) * (h - a)), t < a && (b = -b), d = (2 * r * (a - t) - a + h + b) / (2 * (1 - r) * (h - a))), b = 1 / (2 * d * (1 - d) * (r - 1) + 1), n = (d * d * (f - 2 * r * o + e) + 2 * d * (r * o - f) + f) * b, c = (d * d * (a - 2 * r * t + h) + 2 * d * (r * t - a) + a) * b, q = d * (r - 1) + 1, q *= q * b, r = ((1 - d) * (r - 1) + 1) * Math.sqrt(b), M = Math.floor(n + .5), i = Math.floor(c + .5), n = (o - f) * (c - a) / (t - a) + f, H(f, a, Math.floor(n + .5), i, M, i, q, l), n = (o - e) * (c - h) / (t - h) + e, o = Math.floor(n + .5), f = M, a = t = i), H(f, a, o, t, e, h, r * r, l);
6343
+ }
6344
+ function H(f, a, o, t, e, h, r, l) {
6345
+ var M = e - o,
6346
+ i = h - t,
6347
+ n = f - e,
6348
+ c = a - h,
6349
+ q = f - o,
6350
+ d = a - t,
6351
+ b = q * i + d * M,
6352
+ s = q * i - d * M,
6353
+ u;
6354
+ if (I(q * M <= 0 && d * i <= 0, "sign of gradient must not change"), s != 0 && r > 0) {
6355
+ if (M * M + i * i > q * q + d * d && (e = f, f -= n, h = a, a -= c, s = -s), q = 2 * (4 * r * M * q + n * n), d = 2 * (4 * r * i * d + c * c), M = f < e ? 1 : -1, i = a < h ? 1 : -1, b = -2 * M * i * (2 * r * b + n * c), s * M * i < 0 && (q = -q, d = -d, b = -b, s = -s), n = 4 * r * (o - f) * i * s + q / 2 + b, c = 4 * r * (a - t) * M * s + d / 2 + b, r < .5 && (c > b || n < b)) {
6356
+ s = (r + 1) / 2, r = Math.sqrt(r), b = 1 / (r + 1), M = Math.floor((f + 2 * r * o + e) * b / 2 + .5), i = Math.floor((a + 2 * r * t + h) * b / 2 + .5), n = Math.floor((r * o + f) * b + .5), c = Math.floor((t * r + a) * b + .5), H(f, a, n, c, M, i, s, l), n = Math.floor((r * o + e) * b + .5), c = Math.floor((t * r + h) * b + .5), H(M, i, n, c, e, h, s, l);
6357
+ return;
6358
+ }
6359
+ u = n + c - b;
6360
+ do {
6361
+ if (l(f, a), f == e && a == h) return;
6362
+ o = 2 * u > c ? 1 : 0, t = 2 * (u + d) < -c ? 1 : 0, (2 * u < n || t) && (a += i, c += b, u += n += q), (2 * u > n || o) && (f += M, n += b, u += c += d);
6363
+ } while (c <= b && n >= b);
6364
+ }
6365
+ J(f, a, e, h, l);
6366
+ }
6367
+ function V(f, a, o, t, e, h, r, l) {
6368
+ var M = e - o,
6369
+ i = h - t,
6370
+ n = f - e,
6371
+ c = a - h,
6372
+ q = f - o,
6373
+ d = a - t,
6374
+ b = q * i + d * M,
6375
+ s = q * i - d * M,
6376
+ u,
6377
+ z,
6378
+ j;
6379
+ if (I(q * M <= 0 && d * i <= 0), s != 0 && r > 0) {
6380
+ if (M * M + i * i > q * q + d * d && (e = f, f -= n, h = a, a -= c, s = -s), q = 2 * (4 * r * M * q + n * n), d = 2 * (4 * r * i * d + c * c), M = f < e ? 1 : -1, i = a < h ? 1 : -1, b = -2 * M * i * (2 * r * b + n * c), s * M * i < 0 && (q = -q, d = -d, s = -s, b = -b), n = 4 * r * (o - f) * i * s + q / 2 + b, c = 4 * r * (a - t) * M * s + d / 2 + b, r < .5 && c > n) return s = (r + 1) / 2, r = Math.sqrt(r), b = 1 / (r + 1), M = Math.floor((f + 2 * r * o + e) * b / 2 + .5), i = Math.floor((a + 2 * r * t + h) * b / 2 + .5), n = Math.floor((r * o + f) * b + .5), c = Math.floor((t * r + a) * b + .5), V(f, a, n, c, M, i, s, l), n = Math.floor((r * o + e) * b + .5), c = Math.floor((t * r + h) * b + .5), V(M, i, n, c, e, h, s, l);
6381
+ u = n + c - b;
6382
+ do {
6383
+ if (s = Math.min(n - b, b - c), z = Math.max(n - b, b - c), z += 2 * z * s * s / (4 * z * z + s * s), o = 255 * Math.abs(u - n - c + b) / z, o < 256 && l(f, a, o), j = 2 * u + c < 0) {
6384
+ if (a == h) return;
6385
+ n - u < z && l(f + M, a, 255 * Math.abs(n - u) / z);
6386
+ }
6387
+ if (2 * u + n > 0) {
6388
+ if (f == e) return;
6389
+ u - c < z && l(f, a + i, 255 * Math.abs(u - c) / z), f += M, n += b, u += c += d;
6390
+ }
6391
+ j && (a += i, c += b, u += n += q);
6392
+ } while (c < n);
6393
+ }
6394
+ U(f, a, e, h, l);
6395
+ }
6396
+ function y(f, a, o, t, e) {
6397
+ let h = -o,
6398
+ r = 0,
6399
+ l = t * t,
6400
+ M = h * (2 * l + h) + l;
6401
+ do e(f - h, a + r), e(f + h, a + r), e(f + h, a - r), e(f - h, a - r), l = 2 * M, l >= (h * 2 + 1) * t * t && (M += (++h * 2 + 1) * t * t), l <= (r * 2 + 1) * o * o && (M += (++r * 2 + 1) * o * o); while (h <= 0);
6402
+ for (; r++ < t;) e(f, a + r), e(f, a - r);
6403
+ }
6404
+ function x(f, a, o, t, e, h) {
6405
+ let r = o * o,
6406
+ l = t * t;
6407
+ const M = Math.sin(e);
6408
+ let i = (r - l) * M;
6409
+ r = Math.sqrt(r - i * M), l = Math.sqrt(l + i * M), o = r + .5, t = l + .5, i = i * o * t / (r * l), Y(f - o, a - t, f + o, a + t, 4 * i * Math.cos(e), h);
6410
+ }
6411
+ function Y(f, a, o, t, e, h) {
6412
+ let r = o - f,
6413
+ l = t - a,
6414
+ M = r * l;
6415
+ if (e === 0) return Z(f, a, o, t, h);
6416
+ M !== 0 && (M = (M - e) / (M + M)), I(M <= 1 && M >= 0, "limit angle to |zd|<=xd*yd"), r = Math.floor(r * M + .5), l = Math.floor(l * M + .5), H(f, a + l, f, a, f + r, a, 1 - M, h), H(f, a + l, f, t, o - r, t, M, h), H(o, t - l, o, t, o - r, t, 1 - M, h), H(o, t - l, o, a, f + r, a, M, h);
6417
+ }
6418
+ function Z(f, a, o, t, e) {
6419
+ let h = Math.abs(o - f),
6420
+ r = Math.abs(t - a),
6421
+ l = r & 1,
6422
+ M = 4 * (1 - h) * r * r,
6423
+ i = 4 * (l + 1) * h * h,
6424
+ n = M + i + l * h * h,
6425
+ c;
6426
+ f > o && (f = o, o += h), a > t && (a = t), a += (r + 1) / 2, t = a - l, h = 8 * h * h, l = 8 * r * r;
6427
+ do e(o, a), e(f, a), e(f, t), e(o, t), c = 2 * n, c <= i && (a++, t--, n += i += h), (c >= M || 2 * n > i) && (f++, o--, n += M += l); while (f <= o);
6428
+ for (; a - t <= r;) e(f - 1, a), e(o + 1, a++), e(f - 1, t), e(o + 1, t--);
6429
+ }
6430
+ function aa(f, a, o, t) {
6431
+ var e = -o,
6432
+ h = 0,
6433
+ r = 2 - 2 * o;
6434
+ do t(f - e, a + h), t(f - h, a - e), t(f + e, a - h), t(f + h, a + e), o = r, o <= h && (r += ++h * 2 + 1), (o > e || r > h) && (r += ++e * 2 + 1); while (e < 0);
6435
+ }
6436
+ function fa(f, a, o, t) {
6437
+ var e = -o,
6438
+ h = 0,
6439
+ r,
6440
+ l,
6441
+ M,
6442
+ i = 2 - 2 * o;
6443
+ o = 1 - i;
6444
+ do r = 255 * Math.abs(i - 2 * (e + h) - 2) / o, t(f - e, a + h, r), t(f - h, a - e, r), t(f + e, a - h, r), t(f + h, a + e, r), M = i, l = e, i + h > 0 && (r = 255 * (i - 2 * e - 1) / o, r < 256 && (t(f - e, a + h + 1, r), t(f - h - 1, a - e, r), t(f + e, a - h - 1, r), t(f + h + 1, a + e, r)), i += ++e * 2 + 1), M + l <= 0 && (r = 255 * (2 * h + 3 - M) / o, r < 256 && (t(f - l - 1, a + h, r), t(f - h, a - l - 1, r), t(f + l + 1, a - h, r), t(f + h, a + l + 1, r)), i += ++h * 2 + 1); while (e < 0);
6445
+ }
6446
+ function ta(f, a, o, t, e, h, r) {
6447
+ var l = f - o,
6448
+ M = a - t,
6449
+ i = f - 2 * o + e,
6450
+ n;
6451
+ l * (e - o) > 0 && (M * (h - t) > 0 && Math.abs((a - 2 * t + h) / i * l) > Math.abs(M) && (f = e, e = l + o, a = h, h = M + t), i = (f - o) / i, n = (1 - i) * ((1 - i) * a + 2 * i * t) + i * i * h, i = (f * e - o * o) * i / (f - o), l = Math.floor(i + .5), M = Math.floor(n + .5), n = (t - a) * (i - f) / (o - f) + a, L(f, a, l, Math.floor(n + .5), l, M, r), n = (t - h) * (i - e) / (o - e) + h, f = o = l, a = M, t = Math.floor(n + .5)), (a - t) * (h - t) > 0 && (i = a - 2 * t + h, i = (a - t) / i, n = (1 - i) * ((1 - i) * f + 2 * i * o) + i * i * e, i = (a * h - t * t) * i / (a - t), l = Math.floor(n + .5), M = Math.floor(i + .5), n = (o - f) * (i - a) / (t - a) + f, L(f, a, Math.floor(n + .5), M, l, M, r), n = (o - e) * (i - h) / (t - h) + e, f = l, o = Math.floor(n + .5), a = t = M), L(f, a, o, t, e, h, r);
6452
+ }
6453
+ function L(f, a, o, t, e, h, r) {
6454
+ var l = e - o,
6455
+ M = h - t,
6456
+ i = f - o,
6457
+ n = a - t,
6458
+ c,
6459
+ q,
6460
+ d,
6461
+ b,
6462
+ s = i * M - n * l;
6463
+ if (I(i * l <= 0 && n * M <= 0, "sign of gradient must not change"), l * l + M * M > i * i + n * n && (e = f, f = l + o, h = a, a = M + t, s = -s), s != 0) {
6464
+ i += l, i *= l = f < e ? 1 : -1, n += M, n *= M = a < h ? 1 : -1, c = 2 * i * n, i *= i, n *= n, s * l * M < 0 && (i = -i, n = -n, c = -c, s = -s), q = 4 * M * s * (o - f) + i - c, d = 4 * l * s * (a - t) + n - c, i += i, n += n, b = q + d + c;
6465
+ do {
6466
+ if (r(f, a), f == e && a == h) return;
6467
+ t = +(2 * b < q), 2 * b > d && (f += l, q -= c, b += d += n), t && (a += M, d -= c, b += q += i);
6468
+ } while (d < 0 && q > 0);
6469
+ }
6470
+ J(f, a, e, h, r);
6471
+ }
6472
+ function ia(f, a, o, t, e, h, r) {
6473
+ var l = f - o,
6474
+ M = a - t,
6475
+ i = f - 2 * o + e,
6476
+ n;
6477
+ l * (e - o) > 0 && (M * (h - t) > 0 && Math.abs((a - 2 * t + h) / i * l) > Math.abs(M) && (f = e, e = l + o, a = h, h = M + t), i = (f - o) / i, n = (1 - i) * ((1 - i) * a + 2 * i * t) + i * i * h, i = (f * e - o * o) * i / (f - o), l = Math.floor(i + .5), M = Math.floor(n + .5), n = (t - a) * (i - f) / (o - f) + a, Q(f, a, l, Math.floor(n + .5), l, M, r), n = (t - h) * (i - e) / (o - e) + h, f = o = l, a = M, t = Math.floor(n + .5)), (a - t) * (h - t) > 0 && (i = a - 2 * t + h, i = (a - t) / i, n = (1 - i) * ((1 - i) * f + 2 * i * o) + i * i * e, i = (a * h - t * t) * i / (a - t), l = Math.floor(n + .5), M = Math.floor(i + .5), n = (o - f) * (i - a) / (t - a) + f, Q(f, a, Math.floor(n + .5), M, l, M, r), n = (o - e) * (i - h) / (t - h) + e, f = l, o = Math.floor(n + .5), a = t = M), Q(f, a, o, t, e, h, r);
6478
+ }
6479
+ function Q(f, a, o, t, e, h, r) {
6480
+ var l = e - o,
6481
+ M = h - t,
6482
+ i = f - o,
6483
+ n = a - t,
6484
+ c,
6485
+ q,
6486
+ d,
6487
+ b,
6488
+ s,
6489
+ u = i * M - n * l;
6490
+ if (l * l + M * M > i * i + n * n && (e = f, f = l + o, h = a, a = M + t, u = -u), u != 0) {
6491
+ i += l, i *= l = f < e ? 1 : -1, n += M, n *= M = a < h ? 1 : -1, c = 2 * i * n, i *= i, n *= n, u * l * M < 0 && (i = -i, n = -n, c = -c, u = -u), q = 4 * M * (o - f) * u + i - c, d = 4 * l * (a - t) * u + n - c, i += i, n += n, b = q + d + c;
6492
+ do {
6493
+ if (u = Math.min(q + c, -c - d), s = Math.max(q + c, -c - d), s += 2 * s * u * u / (4 * s * s + u * u), r(f, a, 255 * Math.abs(b - q - d - c) / s), f == e || a == h) break;
6494
+ o = f, u = q - b, t = +(2 * b + d < 0), 2 * b + q > 0 && (b - d < s && r(f, a + M, 255 * Math.abs(b - d) / s), f += l, q -= c, b += d += n), t && (u < s && r(o + l, a, 255 * Math.abs(u) / s), a += M, d -= c, b += q += i);
6495
+ } while (d < q);
6496
+ }
6497
+ U(f, a, e, h, r);
6498
+ }
6499
+ function _(f, a, o, t, e, h, r, l, M) {
6500
+ var i,
6501
+ n,
6502
+ c,
6503
+ q = 1;
6504
+ let d = f < r ? 1 : -1,
6505
+ b = a < l ? 1 : -1,
6506
+ s = -Math.abs(f + o - e - r),
6507
+ u = s - 4 * d * (o - e),
6508
+ z = d * (f - o - e + r),
6509
+ j = -Math.abs(a + t - h - l),
6510
+ B = j - 4 * b * (t - h),
6511
+ R = b * (a - t - h + l),
6512
+ p,
6513
+ S,
6514
+ W,
6515
+ T,
6516
+ G,
6517
+ E,
6518
+ O,
6519
+ v,
6520
+ g,
6521
+ k,
6522
+ F,
6523
+ D = .01;
6524
+ if (I((o - f) * (e - r) < D && ((r - f) * (o - e) < D || z * z < u * s + D), "slope change"), I((t - a) * (h - l) < D && ((l - a) * (t - h) < D || R * R < B * j + D), "slope change"), u == 0 && B == 0) return d = Math.floor((3 * o - f + 1) / 2), b = Math.floor((3 * t - a + 1) / 2), L(f, a, d, b, r, l, M);
6525
+ o = (o - f) * (o - f) + (t - a) * (t - a) + 1, e = (e - r) * (e - r) + (h - l) * (h - l) + 1;
6526
+ do {
6527
+ p = u * R - z * B, S = u * j - s * B, W = z * j - s * R, k = p * (p + S - 3 * W) + S * S, i = k > 0 ? 1 : Math.sqrt(1 + 1024 / o), p *= i, S *= i, W *= i, k *= i * i, E = 9 * (p + S + W) / 8, T = 8 * (u - B), v = 27 * (8 * p * (R * R - B * j) + k * (B + 2 * R + j)) / 64 - B * B * (E - B), g = 27 * (8 * p * (z * z - u * s) - k * (u + 2 * z + s)) / 64 - u * u * (E + u), G = 3 * (3 * p * (3 * R * R - B * B - 2 * B * j) - B * (3 * S * (B + R) + B * T)) / 4, O = 3 * (3 * p * (3 * z * z - u * u - 2 * u * s) - u * (3 * S * (u + z) + u * T)) / 4, E = u * B * (6 * p + 6 * S - 3 * W + T), S = B * B, T = u * u, E = 3 * (E + 9 * i * (T * R * j - z * s * S) - 18 * z * R * p) / 8, k < 0 && (v = -v, g = -g, G = -G, O = -O, E = -E, S = -S, T = -T), p = 6 * B * S, S = -6 * u * S, W = 6 * B * T, T = -6 * u * T, v += E, k = v + g, g += E;
6528
+ a: for (F = E, n = c = i; f != r && a != l;) {
6529
+ M(f, a);
6530
+ do {
6531
+ if (v > F || g < F) break a;
6532
+ t = 2 * k - g, 2 * k >= v && (n--, k += v += G, g += E += S, O += W, G += p), t <= 0 && (c--, k += g += O, v += E += W, G += S, O += T);
6533
+ } while (n > 0 && c > 0);
6534
+ 2 * n <= i && (f += d, n += i), 2 * c <= i && (a += b, c += i), F == E && v < 0 && g > 0 && (F = D);
6535
+ }
6536
+ G = f, f = r, r = G, d = -d, z = -z, O = a, a = l, l = O, b = -b, R = -R, o = e;
6537
+ } while (q--);
6538
+ J(f, a, r, l, M);
6539
+ }
6540
+ function $(f, a, o, t, e, h, r, l, M) {
6541
+ let i,
6542
+ n,
6543
+ c,
6544
+ q = 1,
6545
+ d = f < r ? 1 : -1,
6546
+ b = a < l ? 1 : -1,
6547
+ s = -Math.abs(f + o - e - r),
6548
+ u = s - 4 * d * (o - e),
6549
+ z = d * (f - o - e + r),
6550
+ j = -Math.abs(a + t - h - l),
6551
+ B = j - 4 * b * (t - h),
6552
+ R = b * (a - t - h + l),
6553
+ p,
6554
+ S,
6555
+ W,
6556
+ T,
6557
+ G,
6558
+ E,
6559
+ O,
6560
+ v,
6561
+ g,
6562
+ k,
6563
+ F,
6564
+ D,
6565
+ C,
6566
+ A;
6567
+ const K = .01;
6568
+ if (I((o - f) * (e - r) < K && ((r - f) * (o - e) < K || z * z < u * s + K)), I((t - a) * (h - l) < K && ((l - a) * (t - h) < K || R * R < B * j + K)), u === 0 && B === 0) return d = Math.floor((3 * o - f + 1) / 2), b = Math.floor((3 * t - a + 1) / 2), Q(f, a, d, b, r, l, M);
6569
+ o = (o - f) * (o - f) + (t - a) * (t - a) + 1, e = (e - r) * (e - r) + (h - l) * (h - l) + 1;
6570
+ do {
6571
+ p = u * R - z * B, S = u * j - s * B, W = z * j - s * R, A = 4 * p * W - S * S, k = p * (p + S - 3 * W) + S * S, i = k > 0 ? 1 : Math.sqrt(1 + 1024 / o), p *= i, S *= i, W *= i, k *= i * i, E = 9 * (p + S + W) / 8, T = 8 * (u - B), v = 27 * (8 * p * (R * R - B * j) + k * (B + 2 * R + j)) / 64 - B * B * (E - B), g = 27 * (8 * p * (z * z - u * s) - k * (u + 2 * z + s)) / 64 - u * u * (E + u), G = 3 * (3 * p * (3 * R * R - B * B - 2 * B * j) - B * (3 * S * (B + R) + B * T)) / 4, O = 3 * (3 * p * (3 * z * z - u * u - 2 * u * s) - u * (3 * S * (u + z) + u * T)) / 4, E = u * B * (6 * p + 6 * S - 3 * W + T), S = B * B, T = u * u, E = 3 * (E + 9 * i * (T * R * j - z * s * S) - 18 * z * R * p) / 8, k < 0 && (v = -v, g = -g, G = -G, O = -O, E = -E, S = -S, T = -T), p = 6 * B * S, S = -6 * u * S, W = 6 * B * T, T = -6 * u * T, v += E, k = v + g, g += E;
6572
+ let X = false;
6573
+ a: for (n = c = i; f !== r && a !== l;) {
6574
+ t = Math.min(Math.abs(E - v), Math.abs(g - E)), C = Math.max(Math.abs(E - v), Math.abs(g - E)), C = i * (C + 2 * C * t * t / (4 * C * C + t * t)), t = 255 * Math.abs(k - (i - n + 1) * v - (i - c + 1) * g + i * E) / C, t < 256 && M(f, a, t), F = Math.abs(k - (i - n + 1) * v + (c - 1) * g), D = Math.abs(k + (n - 1) * v - (i - c + 1) * g), h = a;
6575
+ do {
6576
+ if (A >= -K && (v + G > E || g + O < E)) {
6577
+ X = true;
6578
+ break a;
6579
+ }
6580
+ if (t = 2 * k + v, 2 * k + g > 0) n--, k += v += G, g += E += S, O += W, G += p;else if (t > 0) {
6581
+ X = true;
6582
+ break a;
6583
+ }
6584
+ t <= 0 && (c--, k += g += O, v += E += W, G += S, O += T);
6585
+ } while (n > 0 && c > 0);
6586
+ 2 * c <= i && (D < C && M(f + d, a, 255 * D / C), a += b, c += i), 2 * n <= i && (F < C && M(f, h + b, 255 * F / C), f += d, n += i);
6587
+ }
6588
+ X && (2 * k < g && 2 * c <= i + 2 && (D < C && M(f + d, a, 255 * D / C), a += b), 2 * k > v && 2 * n <= i + 2 && (F < C && M(f, h + b, 255 * F / C), f += d), G = f, f = r, r = G, d = -d, z = -z, O = a, a = l, l = O, b = -b, R = -R, o = e);
6589
+ break;
6590
+ } while (q--);
6591
+ U(Math.floor(f), Math.floor(a), Math.floor(r), Math.floor(l), M);
6592
+ }
6593
+ function m(f, a, o, t, e, h, r, l, M, i) {
6594
+ let n = 0,
6595
+ c = 0,
6596
+ q = f + o - e - r,
6597
+ d = q - 4 * (o - e),
6598
+ b = f - o - e + r,
6599
+ s = b + 4 * (o + e),
6600
+ u = a + t - h - l,
6601
+ z = u - 4 * (t - h),
6602
+ j = a - t - h + l,
6603
+ B = j + 4 * (t + h);
6604
+ var R = f,
6605
+ p,
6606
+ S,
6607
+ W,
6608
+ T = a,
6609
+ G,
6610
+ E,
6611
+ O;
6612
+ let v = b * b - d * q,
6613
+ g;
6614
+ const k = [0, 0, 0, 0, 0];
6615
+ for (d == 0 ? Math.abs(q) < 2 * Math.abs(b) && (k[n++] = q / (2 * b)) : v > 0 && (g = Math.sqrt(v), v = (b - g) / d, Math.abs(v) < 1 && (k[n++] = v), v = (b + g) / d, Math.abs(v) < 1 && (k[n++] = v)), v = j * j - z * u, z == 0 ? Math.abs(u) < 2 * Math.abs(j) && (k[n++] = u / (2 * j)) : v > 0 && (g = Math.sqrt(v), v = (j - g) / z, Math.abs(v) < 1 && (k[n++] = v), v = (j + g) / z, Math.abs(v) < 1 && (k[n++] = v)), c = 1; c < n; c++) (v = k[c - 1]) > k[c] && (k[c - 1] = k[c], k[c] = v, c = 0);
6616
+ for (v = -1, k[n] = 1, c = 0; c <= n; c++) g = k[c], p = (v * (v * b - 2 * q) - g * (v * (v * d - 2 * b) + q) + s) / 8 - R, G = (v * (v * j - 2 * u) - g * (v * (v * z - 2 * j) + u) + B) / 8 - T, S = (g * (g * b - 2 * q) - v * (g * (g * d - 2 * b) + q) + s) / 8 - R, E = (g * (g * j - 2 * u) - v * (g * (g * z - 2 * j) + u) + B) / 8 - T, R -= W = (g * (g * (3 * b - g * d) - 3 * q) + s) / 8, T -= O = (g * (g * (3 * j - g * z) - 3 * u) + B) / 8, r = Math.floor(W + .5), l = Math.floor(O + .5), R != 0 && (p *= R = (f - r) / R, S *= R), T != 0 && (G *= T = (a - l) / T, E *= T), (f != r || a != l) && M(f, a, f + p, a + G, f + S, a + E, r, l, i), f = r, a = l, R = W, T = O, v = g;
6617
+ }
6618
+ function ra(f, a, o, t, e, h, r, l, M) {
6619
+ m(f, a, o, t, e, h, r, l, _, M);
6620
+ }
6621
+ function oa(f, a, o, t, e, h, r, l, M) {
6622
+ m(f, a, o, t, e, h, r, l, $, M);
6623
+ }
6624
+ N.circle = aa, N.circleAA = fa, N.cubicBezier = ra, N.cubicBezierAA = oa, N.cubicBezierSegment = _, N.cubicBezierSegmentAA = $, N.ellipse = y, N.ellipseRect = Z, N.line = J, N.lineAA = U, N.lineWidth = w, N.quadBezier = ta, N.quadBezierAA = ia, N.quadBezierSegment = L, N.quadBezierSegmentAA = Q, N.quadRationalBezier = P, N.quadRationalBezierSegment = H, N.quadRationalBezierSegmentAA = V, N.rotatedEllipse = x, N.rotatedEllipseRect = Y, Object.defineProperty(N, Symbol.toStringTag, {
6625
+ value: "Module"
6626
+ });
6627
+ });
6628
+ })(index_umd$1, index_umd$1.exports);
6629
+ var index_umdExports = index_umd$1.exports;
6248
6630
 
6249
6631
  /**
6250
6632
  * Remove duplicate points from array.
@@ -6271,7 +6653,7 @@ function deleteDuplicates(points) {
6271
6653
  */
6272
6654
  function getCirclePoints(radius) {
6273
6655
  const circlePoints = [];
6274
- x$1(radius, radius, radius, (column, row) => {
6656
+ index_umdExports.circle(radius, radius, radius, (column, row) => {
6275
6657
  circlePoints.push({
6276
6658
  row: row - radius,
6277
6659
  column: column - radius
@@ -6307,7 +6689,7 @@ function getFilledCirclePoints(radius, center = zeroPoint) {
6307
6689
  if (radius === 1) {
6308
6690
  circlePoints.push(center);
6309
6691
  }
6310
- x$1(center.column, center.row, radius, (column, row) => {
6692
+ index_umdExports.circle(center.column, center.row, radius, (column, row) => {
6311
6693
  circlePoints.push({
6312
6694
  row,
6313
6695
  column
@@ -6341,7 +6723,7 @@ function getFilledCirclePoints(radius, center = zeroPoint) {
6341
6723
  */
6342
6724
  function getLinePoints(from, to) {
6343
6725
  const linePoints = [];
6344
- T(from.column, from.row, to.column, to.row, (column, row) => {
6726
+ index_umdExports.line(from.column, from.row, to.column, to.row, (column, row) => {
6345
6727
  linePoints.push({
6346
6728
  row,
6347
6729
  column
@@ -6356,7 +6738,7 @@ function getLinePoints(from, to) {
6356
6738
  * @returns The coordinates of the compass points.
6357
6739
  */
6358
6740
  function getCompassPoints(radius) {
6359
- x$1(radius, radius, radius, (column, row) => {
6741
+ index_umdExports.circle(radius, radius, radius, (column, row) => {
6360
6742
  });
6361
6743
  return [{
6362
6744
  row: 0,
@@ -6567,7 +6949,7 @@ function getHarrisScore(image, origin, options = {}) {
6567
6949
  const xxSum = xx.sum();
6568
6950
  const xySum = xy.sum();
6569
6951
  const yySum = yy.sum();
6570
- const structureTensor = new Matrix([[xxSum, xySum], [xySum, yySum]]);
6952
+ const structureTensor = new Matrix$1([[xxSum, xySum], [xySum, yySum]]);
6571
6953
  const eigenValues = new EigenvalueDecomposition(structureTensor).realEigenvalues;
6572
6954
  return eigenValues[0] * eigenValues[1] - harrisConstant * (eigenValues[0] + eigenValues[1]) ** 2;
6573
6955
  }
@@ -6667,7 +7049,7 @@ function getFastKeypoints(image, options = {}) {
6667
7049
  channels: [1],
6668
7050
  alpha: false
6669
7051
  });
6670
- const getScore = z(scoreAlgorithm).with('HARRIS', () => {
7052
+ const getScore = M$2(scoreAlgorithm).with('HARRIS', () => {
6671
7053
  return (image, corner) => getHarrisScore(image, corner, harrisScoreOptions);
6672
7054
  }).with('FAST', () => {
6673
7055
  return (image, corner) => getFastScore(image, corner, threshold, circlePoints);
@@ -8049,11 +8431,13 @@ function bruteForceOneMatch(source, destination, options = {}) {
8049
8431
  * @returns Sorted copy of the array of matches.
8050
8432
  */
8051
8433
  function sortBySourceDest(matches) {
8052
- return matches.slice().sort((match1, match2) => {
8434
+ const sorted = matches.slice();
8435
+ sorted.sort((match1, match2) => {
8053
8436
  if (match1.sourceIndex < match2.sourceIndex) return -1;
8054
8437
  if (match1.sourceIndex > match2.sourceIndex) return 1;
8055
8438
  return match1.destinationIndex - match2.destinationIndex;
8056
8439
  });
8440
+ return sorted;
8057
8441
  }
8058
8442
  /**
8059
8443
  * Sort array of matches by destination index and then source index.
@@ -8061,11 +8445,13 @@ function sortBySourceDest(matches) {
8061
8445
  * @returns Sorted copy of the array of matches.
8062
8446
  */
8063
8447
  function sortByDestSource(matches) {
8064
- return matches.slice().sort((match1, match2) => {
8448
+ const sorted = matches.slice();
8449
+ sorted.sort((match1, match2) => {
8065
8450
  if (match1.destinationIndex < match2.destinationIndex) return -1;
8066
8451
  if (match1.destinationIndex > match2.destinationIndex) return 1;
8067
8452
  return match1.sourceIndex - match2.sourceIndex;
8068
8453
  });
8454
+ return sorted;
8069
8455
  }
8070
8456
 
8071
8457
  /**
@@ -8268,7 +8654,7 @@ function computePsnr(image, otherImage) {
8268
8654
  * @returns Default color.
8269
8655
  */
8270
8656
  function getDefaultColor(image) {
8271
- return z(image.colorModel).with('GREY', () => [0]).with('GREYA', () => [0, image.maxValue]).with('RGB', () => [0, 0, 0]).with('RGBA', () => [0, 0, 0, image.maxValue]).with('BINARY', () => [1]).exhaustive();
8657
+ return M$2(image.colorModel).with('GREY', () => [0]).with('GREYA', () => [0, image.maxValue]).with('RGB', () => [0, 0, 0]).with('RGBA', () => [0, 0, 0, image.maxValue]).with('BINARY', () => [1]).exhaustive();
8272
8658
  }
8273
8659
 
8274
8660
  /**
@@ -8276,7 +8662,7 @@ function getDefaultColor(image) {
8276
8662
  * @param image - The image with which to blend.
8277
8663
  * @param column - Column of the target pixel.
8278
8664
  * @param row - Row of the target pixel.
8279
- * @param color - Color with which to blend the image pixel. @default `'Opaque black'`.
8665
+ * @param color - Color with which to blend the image pixel. Default: `Opaque black`.
8280
8666
  */
8281
8667
  function setBlendedPixel(image, column, row, color) {
8282
8668
  color = color ?? getDefaultColor(image);
@@ -8306,7 +8692,7 @@ function setBlendedPixel(image, column, row, color) {
8306
8692
  * @param image - The image with which to blend.
8307
8693
  * @param column - Column of the target pixel.
8308
8694
  * @param row - Row of the target pixel.
8309
- * @param color - Color with which to blend the image pixel. @default `'Opaque black'`.
8695
+ * @param color - Color with which to blend the image pixel. Default: `Opaque black`.
8310
8696
  */
8311
8697
  function setBlendedVisiblePixel(image, column, row, color) {
8312
8698
  if (column >= 0 && column < image.width && row >= 0 && row < image.height) {
@@ -8356,7 +8742,7 @@ function drawCircleOnImage(image, center, radius, options = {}) {
8356
8742
  return newImage;
8357
8743
  }
8358
8744
  if (!fillColor) {
8359
- x$1(center.column, center.row, radius, (column, row) => {
8745
+ index_umdExports.circle(center.column, center.row, radius, (column, row) => {
8360
8746
  setBlendedVisiblePixel(newImage, column, row, strokeColor);
8361
8747
  });
8362
8748
  } else {
@@ -8366,7 +8752,7 @@ function drawCircleOnImage(image, center, radius, options = {}) {
8366
8752
  //Starting points for the top and bottom row of the circle.
8367
8753
  let prevRow = center.row + radius;
8368
8754
  let index = 0;
8369
- x$1(center.column, center.row, radius, (column, row) => {
8755
+ index_umdExports.circle(center.column, center.row, radius, (column, row) => {
8370
8756
  setBlendedVisiblePixel(newImage, column, row, strokeColor);
8371
8757
  // Filling the first line of the circle.
8372
8758
  if (index === 0) {
@@ -8439,7 +8825,7 @@ function drawLineOnImage(image, from, to, options = {}) {
8439
8825
  checkProcessable$1(newImage, {
8440
8826
  bitDepth: [8, 16]
8441
8827
  });
8442
- T(Math.round(origin.column + from.column), Math.round(origin.row + from.row), Math.round(origin.column + to.column), Math.round(origin.row + to.row), (column, row) => {
8828
+ index_umdExports.line(Math.round(origin.column + from.column), Math.round(origin.row + from.row), Math.round(origin.column + to.column), Math.round(origin.row + to.row), (column, row) => {
8443
8829
  setBlendedVisiblePixel(newImage, column, row, strokeColor);
8444
8830
  });
8445
8831
  return newImage;
@@ -8463,7 +8849,7 @@ function drawLineOnMask(mask, from, to, options = {}) {
8463
8849
  const newMask = maskToOutputMask(mask, options, {
8464
8850
  clone: true
8465
8851
  });
8466
- T(Math.round(origin.column + from.column), Math.round(origin.row + from.row), Math.round(origin.column + to.column), Math.round(origin.row + to.row), (column, row) => {
8852
+ index_umdExports.line(Math.round(origin.column + from.column), Math.round(origin.row + from.row), Math.round(origin.column + to.column), Math.round(origin.row + to.row), (column, row) => {
8467
8853
  newMask.setVisiblePixel(column, row, [1]);
8468
8854
  });
8469
8855
  return newMask;
@@ -9058,9 +9444,9 @@ function robustSubtract(e, f) {
9058
9444
  })(orientation);
9059
9445
  var orientationExports = orientation.exports;
9060
9446
 
9061
- var robustPnp = robustPointInPolygon;
9447
+ var robustPnp = robustPointInPolygon$1;
9062
9448
  var orient = orientationExports;
9063
- function robustPointInPolygon(vs, point) {
9449
+ function robustPointInPolygon$1(vs, point) {
9064
9450
  var x = point[0];
9065
9451
  var y = point[1];
9066
9452
  var n = vs.length;
@@ -9156,7 +9542,7 @@ function robustPointInPolygon(vs, point) {
9156
9542
  }
9157
9543
  return 2 * inside - 1;
9158
9544
  }
9159
- var robustPointInPolygon$1 = /*@__PURE__*/getDefaultExportFromCjs(robustPnp);
9545
+ var robustPointInPolygon = /*@__PURE__*/getDefaultExportFromCjs(robustPnp);
9160
9546
 
9161
9547
  /**
9162
9548
  * Convert object points into array points.
@@ -9204,7 +9590,7 @@ function drawPolygonOnImage(image, points, options = {}) {
9204
9590
  const arrayPoints = arrayPointsToObjects(filteredPoints);
9205
9591
  for (let row = 0; row < newImage.height; row++) {
9206
9592
  for (let column = 0; column < newImage.width; column++) {
9207
- if (robustPointInPolygon$1(arrayPoints, [column, row]) === -1) {
9593
+ if (robustPointInPolygon(arrayPoints, [column, row]) === -1) {
9208
9594
  setBlendedVisiblePixel(newImage, Math.round(origin.column) + column, Math.round(origin.row) + row, fillColor);
9209
9595
  }
9210
9596
  }
@@ -9245,7 +9631,7 @@ function drawPolygonOnMask(mask, points, options = {}) {
9245
9631
  const arrayPoints = arrayPointsToObjects(filteredPoints);
9246
9632
  for (let row = 0; row < newMask.height; row++) {
9247
9633
  for (let column = 0; column < newMask.width; column++) {
9248
- if (robustPointInPolygon$1(arrayPoints, [column, row]) === -1) {
9634
+ if (robustPointInPolygon(arrayPoints, [column, row]) === -1) {
9249
9635
  newMask.setBit(Math.round(origin.column) + column, Math.round(origin.row) + row, 1);
9250
9636
  }
9251
9637
  }
@@ -9569,7 +9955,7 @@ const BorderType = {
9569
9955
  * @returns The border interpolation function.
9570
9956
  */
9571
9957
  function getBorderInterpolation(type, value) {
9572
- return z(type).with('constant', () => getInterpolateConstant(value)).with('replicate', () => interpolateReplicate).with('reflect', () => interpolateReflect).with('reflect101', () => interpolateReflect101).with('wrap', () => interpolateWrap).exhaustive();
9958
+ return M$2(type).with('constant', () => getInterpolateConstant(value)).with('replicate', () => interpolateReplicate).with('reflect', () => interpolateReflect).with('reflect101', () => interpolateReflect101).with('wrap', () => interpolateWrap).exhaustive();
9573
9959
  }
9574
9960
  function checkRange(point, length) {
9575
9961
  if (point <= 0 - length || point >= length + length - 1) {
@@ -9969,7 +10355,7 @@ function derivativeFilter(image, options = {}) {
9969
10355
  const {
9970
10356
  filter = 'sobel'
9971
10357
  } = options;
9972
- const kernels = z(filter).with('sobel', () => ({
10358
+ const kernels = M$2(filter).with('sobel', () => ({
9973
10359
  kernelX: SOBEL_X,
9974
10360
  kernelY: SOBEL_Y
9975
10361
  })).with('scharr', () => ({
@@ -11553,7 +11939,7 @@ function computeThreshold(image, options = {}) {
11553
11939
  slots
11554
11940
  });
11555
11941
  const scale = slots ? 2 ** image.bitDepth / slots : 1;
11556
- return z(algorithm).with('huang', () => huang(histogram) * scale).with('intermodes', () => intermodes(histogram) * scale).with('isodata', () => isodata(histogram) * scale).with('li', () => li(histogram, image.size) * scale).with('maxEntropy', () => maxEntropy(histogram, image.size) * scale).with('mean', () => mean$1(histogram, image.size) * scale).with('minimum', () => minimum(histogram) * scale).with('minError', () => minError(histogram, image.size) * scale).with('moments', () => moments(histogram, image.size) * scale).with('otsu', () => otsu(histogram, image.size) * scale).with('percentile', () => percentile(histogram) * scale).with('renyiEntropy', () => renyiEntropy(histogram, image.size) * scale).with('shanbhag', () => shanbhag(histogram, image.size) * scale).with('triangle', () => triangle(histogram) * scale).with('yen', () => yen(histogram, image.size) * scale).exhaustive();
11942
+ return M$2(algorithm).with('huang', () => huang(histogram) * scale).with('intermodes', () => intermodes(histogram) * scale).with('isodata', () => isodata(histogram) * scale).with('li', () => li(histogram, image.size) * scale).with('maxEntropy', () => maxEntropy(histogram, image.size) * scale).with('mean', () => mean$1(histogram, image.size) * scale).with('minimum', () => minimum(histogram) * scale).with('minError', () => minError(histogram, image.size) * scale).with('moments', () => moments(histogram, image.size) * scale).with('otsu', () => otsu(histogram, image.size) * scale).with('percentile', () => percentile(histogram) * scale).with('renyiEntropy', () => renyiEntropy(histogram, image.size) * scale).with('shanbhag', () => shanbhag(histogram, image.size) * scale).with('triangle', () => triangle(histogram) * scale).with('yen', () => yen(histogram, image.size) * scale).exhaustive();
11557
11943
  }
11558
11944
  // See: https://docs.opencv.org/4.0.1/d7/d1b/group__imgproc__misc.html#gaa9e58d2860d4afa658ef70a9b1115576
11559
11945
  /**
@@ -12064,7 +12450,7 @@ const InterpolationType = {
12064
12450
  * @returns The interpolation function.
12065
12451
  */
12066
12452
  function getInterpolationFunction(interpolationType) {
12067
- return z(interpolationType).with('nearest', () => interpolateNearest).with('bilinear', () => interpolateBilinear).with('bicubic', () => interpolateBicubic).exhaustive();
12453
+ return M$2(interpolationType).with('nearest', () => interpolateNearest).with('bilinear', () => interpolateBilinear).with('bicubic', () => interpolateBicubic).exhaustive();
12068
12454
  }
12069
12455
  /**
12070
12456
  * Interpolate using nearest neighbor.
@@ -12220,7 +12606,7 @@ function transform(image, transformMatrix, options = {}) {
12220
12606
  height = Math.round(height);
12221
12607
  }
12222
12608
  if (!options.inverse) {
12223
- transformMatrix = inverse(new Matrix(transformMatrix)).to2DArray();
12609
+ transformMatrix = inverse(new Matrix$1(transformMatrix)).to2DArray();
12224
12610
  }
12225
12611
  const newImage = Image.createFrom(image, {
12226
12612
  width,
@@ -12459,8 +12845,8 @@ function getPerspectiveWarp(pts, options = {}) {
12459
12845
  const [x2, y2] = [widthRect - 1, 0];
12460
12846
  const [x3, y3] = [widthRect - 1, heightRect - 1];
12461
12847
  const [x4, y4] = [0, heightRect - 1];
12462
- const S = new Matrix([[x1, y1, 1, 0, 0, 0, -x1 * tl.column, -y1 * tl.column], [x2, y2, 1, 0, 0, 0, -x2 * tr.column, -y2 * tr.column], [x3, y3, 1, 0, 0, 0, -x3 * br.column, -y3 * br.column], [x4, y4, 1, 0, 0, 0, -x4 * bl.column, -y4 * bl.column], [0, 0, 0, x1, y1, 1, -x1 * tl.row, -y1 * tl.row], [0, 0, 0, x2, y2, 1, -x2 * tr.row, -y2 * tr.row], [0, 0, 0, x3, y3, 1, -x3 * br.row, -y3 * br.row], [0, 0, 0, x4, y4, 1, -x4 * bl.row, -y4 * bl.row]]);
12463
- const D = Matrix.columnVector([tl.column, tr.column, br.column, bl.column, tl.row, tr.row, br.row, bl.row]);
12848
+ const S = new Matrix$1([[x1, y1, 1, 0, 0, 0, -x1 * tl.column, -y1 * tl.column], [x2, y2, 1, 0, 0, 0, -x2 * tr.column, -y2 * tr.column], [x3, y3, 1, 0, 0, 0, -x3 * br.column, -y3 * br.column], [x4, y4, 1, 0, 0, 0, -x4 * bl.column, -y4 * bl.column], [0, 0, 0, x1, y1, 1, -x1 * tl.row, -y1 * tl.row], [0, 0, 0, x2, y2, 1, -x2 * tr.row, -y2 * tr.row], [0, 0, 0, x3, y3, 1, -x3 * br.row, -y3 * br.row], [0, 0, 0, x4, y4, 1, -x4 * bl.row, -y4 * bl.row]]);
12849
+ const D = Matrix$1.columnVector([tl.column, tr.column, br.column, bl.column, tl.row, tr.row, br.row, bl.row]);
12464
12850
  const svd = new SingularValueDecomposition(S);
12465
12851
  const T = svd.solve(D).to1DArray(); // solve S*T = D
12466
12852
  T.push(1);
@@ -12855,7 +13241,7 @@ class PolynomialRegression2D extends BaseRegression2D {
12855
13241
  // @ts-expect-error internal use only
12856
13242
  if (inputs === true) {
12857
13243
  // @ts-expect-error internal use only
12858
- this.coefficients = Matrix.columnVector(outputs.coefficients);
13244
+ this.coefficients = Matrix$1.columnVector(outputs.coefficients);
12859
13245
  // @ts-expect-error internal use only
12860
13246
  this.order = outputs.order;
12861
13247
  // @ts-expect-error internal use only
@@ -12970,8 +13356,8 @@ function powColVector(x, power) {
12970
13356
  * @param y - A vector of the prediction values.
12971
13357
  */
12972
13358
  function train(input, y, order) {
12973
- if (!Matrix.isMatrix(y)) y = Matrix.columnVector(y);
12974
- const x = new Matrix(y.rows, 2);
13359
+ if (!Matrix$1.isMatrix(y)) y = Matrix$1.columnVector(y);
13360
+ const x = new Matrix$1(y.rows, 2);
12975
13361
  x.setColumn(0, input.x);
12976
13362
  x.setColumn(1, input.y);
12977
13363
  if (y.rows !== x.rows) {
@@ -12996,7 +13382,7 @@ function train(input, y, order) {
12996
13382
  x1.mulColumn(0, scaleX1);
12997
13383
  x2.mulColumn(0, scaleX2);
12998
13384
  y.mulColumn(0, scaleY);
12999
- const A = new Matrix(examples, nbCoefficients);
13385
+ const A = new Matrix$1(examples, nbCoefficients);
13000
13386
  let col = 0;
13001
13387
  for (let i = 0; i <= order; ++i) {
13002
13388
  const limit = order - i;
@@ -13011,11 +13397,11 @@ function train(input, y, order) {
13011
13397
  computeRightSingularVectors: true,
13012
13398
  autoTranspose: false
13013
13399
  });
13014
- let qqs = Matrix.rowVector(svd.diagonal);
13400
+ let qqs = Matrix$1.rowVector(svd.diagonal);
13015
13401
  qqs = qqs.apply((i, j) => {
13016
13402
  if (qqs.get(i, j) >= 1e-15) qqs.set(i, j, 1 / qqs.get(i, j));else qqs.set(i, j, 0);
13017
13403
  });
13018
- const qqs1 = Matrix.zeros(examples, nbCoefficients);
13404
+ const qqs1 = Matrix$1.zeros(examples, nbCoefficients);
13019
13405
  for (let i = 0; i < nbCoefficients; ++i) {
13020
13406
  qqs1.set(i, i, qqs.get(0, i));
13021
13407
  }
@@ -13567,7 +13953,8 @@ function monotoneChainConvexHull(points, options = {}) {
13567
13953
  sorted = false
13568
13954
  } = options;
13569
13955
  if (!sorted) {
13570
- points = points.slice().sort(byXThenY);
13956
+ points = points.slice();
13957
+ points.sort(byXThenY);
13571
13958
  }
13572
13959
  const n = points.length;
13573
13960
  const result = new Array(n * 2);
@@ -13830,7 +14217,8 @@ const topFirst = (mbrPoint1, mbrPoint2) => mbrPoint1.row >= mbrPoint2.row ? -1 :
13830
14217
  * @returns The angle in degrees.
13831
14218
  */
13832
14219
  function getMbrAngle(mbr) {
13833
- const sorted = mbr.slice().sort(leftFirst);
14220
+ const sorted = mbr.slice();
14221
+ sorted.sort(leftFirst);
13834
14222
  const left = sorted.slice(0, 2);
13835
14223
  const right = sorted.slice(2, 4);
13836
14224
  left.sort(topFirst);
@@ -15015,7 +15403,7 @@ class Mask {
15015
15403
  }
15016
15404
  /**
15017
15405
  * Get the number of pixels that do not have the value 0.
15018
- * @returns
15406
+ * @returns The number of non-zero pixels.
15019
15407
  */
15020
15408
  getNbNonZeroPixels() {
15021
15409
  let count = 0;
@@ -15681,8 +16069,8 @@ class MultivariateLinearRegression {
15681
16069
  this.outputs = y.outputs;
15682
16070
  this.intercept = y.intercept;
15683
16071
  } else {
15684
- x = new Matrix(x);
15685
- y = new Matrix(y);
16072
+ x = new Matrix$1(x);
16073
+ y = new Matrix$1(y);
15686
16074
  if (intercept) {
15687
16075
  x.addColumn(new Array(x.rows).fill(1));
15688
16076
  }
@@ -15724,8 +16112,8 @@ class MultivariateLinearRegression {
15724
16112
  }
15725
16113
  return y;
15726
16114
  }
15727
- } else if (Matrix.isMatrix(x)) {
15728
- const y = new Matrix(x.rows, this.outputs);
16115
+ } else if (Matrix$1.isMatrix(x)) {
16116
+ const y = new Matrix$1(x.rows, this.outputs);
15729
16117
  for (let i = 0; i < x.rows; i++) {
15730
16118
  y.setRow(i, this._predict(x.getRow(i)));
15731
16119
  }
@@ -16788,7 +17176,7 @@ class Image {
16788
17176
  * @returns Coordinates of the point in the format [column, row].
16789
17177
  */
16790
17178
  getCoordinates(coordinates, round = false) {
16791
- return z(coordinates).with('center', () => {
17179
+ return M$2(coordinates).with('center', () => {
16792
17180
  const centerX = (this.width - 1) / 2;
16793
17181
  const centerY = (this.height - 1) / 2;
16794
17182
  if (round) {
@@ -17207,7 +17595,7 @@ class Image {
17207
17595
  */
17208
17596
  function createPixelArray(size, channels, alpha, bitDepth, maxValue) {
17209
17597
  const length = channels * size;
17210
- const arr = z(bitDepth).with(8, () => new Uint8Array(length)).with(16, () => new Uint16Array(length)).otherwise(() => {
17598
+ const arr = M$2(bitDepth).with(8, () => new Uint8Array(length)).with(16, () => new Uint16Array(length)).otherwise(() => {
17211
17599
  throw new RangeError(`invalid bitDepth: ${bitDepth}`);
17212
17600
  });
17213
17601
  // Alpha channel is 100% by default.
@@ -17536,9 +17924,11 @@ function getMatchColor(matches, index, colors) {
17536
17924
  * @returns Sorted copy of the array of matches.
17537
17925
  */
17538
17926
  function sortByDistance(matches) {
17539
- return matches.slice().sort((match1, match2) => {
17927
+ const sorted = matches.slice();
17928
+ sorted.sort((match1, match2) => {
17540
17929
  return match1.distance - match2.distance;
17541
17930
  });
17931
+ return sorted;
17542
17932
  }
17543
17933
 
17544
17934
  /**
@@ -17797,7 +18187,8 @@ function filterEuclideanDistance(matches, sourceKeypoints, destinationKeypoints,
17797
18187
  row: 0
17798
18188
  }
17799
18189
  } = options;
17800
- const sorted = matches.sort((a, b) => a.destinationIndex - b.destinationIndex);
18190
+ const sorted = matches.slice();
18191
+ sorted.sort((a, b) => a.destinationIndex - b.destinationIndex);
17801
18192
  const result = [];
17802
18193
  let sameDestMatches = [];
17803
18194
  let currentIndex = sorted[0].destinationIndex;
@@ -17805,12 +18196,14 @@ function filterEuclideanDistance(matches, sourceKeypoints, destinationKeypoints,
17805
18196
  if (match.destinationIndex === currentIndex) {
17806
18197
  sameDestMatches.push(match);
17807
18198
  } else {
17808
- result.push(...sameDestMatches.sort((a, b) => distanceSquared(a) - distanceSquared(b)).slice(0, 1));
18199
+ sameDestMatches.sort((a, b) => distanceSquared(a) - distanceSquared(b));
18200
+ result.push(...sameDestMatches.slice(0, 1));
17809
18201
  currentIndex = match.destinationIndex;
17810
18202
  sameDestMatches = [match];
17811
18203
  }
17812
18204
  }
17813
- result.push(...sameDestMatches.sort((a, b) => distanceSquared(a) - distanceSquared(b)).slice(0, 1));
18205
+ sameDestMatches.sort((a, b) => distanceSquared(a) - distanceSquared(b));
18206
+ result.push(...sameDestMatches.slice(0, 1));
17814
18207
  return result;
17815
18208
  function distanceSquared(match) {
17816
18209
  return (sourceKeypoints[match.sourceIndex].origin.row - (destinationKeypoints[match.destinationIndex].origin.row - origin.row)) ** 2 + (sourceKeypoints[match.sourceIndex].origin.column - destinationKeypoints[match.destinationIndex].origin.column - origin.column) ** 2;
@@ -17823,7 +18216,7 @@ function filterEuclideanDistance(matches, sourceKeypoints, destinationKeypoints,
17823
18216
  * @param encoding - Text encoding
17824
18217
  * @returns The decoded text
17825
18218
  */
17826
- function decode$3(bytes, encoding = 'utf8') {
18219
+ function decode$4(bytes, encoding = 'utf8') {
17827
18220
  const decoder = new TextDecoder(encoding);
17828
18221
  return decoder.decode(bytes);
17829
18222
  }
@@ -18219,7 +18612,7 @@ class IOBuffer {
18219
18612
  * @returns The decoded string.
18220
18613
  */
18221
18614
  readUtf8(n = 1) {
18222
- return decode$3(this.readBytes(n));
18615
+ return decode$4(this.readBytes(n));
18223
18616
  }
18224
18617
  /**
18225
18618
  * Read the next `n` bytes, return a string decoded with `encoding` and move pointer
@@ -18230,7 +18623,7 @@ class IOBuffer {
18230
18623
  * @returns The decoded string.
18231
18624
  */
18232
18625
  decodeText(n = 1, encoding = 'utf8') {
18233
- return decode$3(this.readBytes(n), encoding);
18626
+ return decode$4(this.readBytes(n), encoding);
18234
18627
  }
18235
18628
  /**
18236
18629
  * Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer
@@ -18451,6 +18844,117 @@ class IOBuffer {
18451
18844
  }
18452
18845
  }
18453
18846
 
18847
+ class BMPDecoder {
18848
+ bufferData;
18849
+ pixelDataOffset;
18850
+ width;
18851
+ height;
18852
+ bitsPerPixel;
18853
+ xPixelsPerMeter;
18854
+ yPixelsPerMeter;
18855
+ compression;
18856
+ colorMasks;
18857
+ constructor(bufferData) {
18858
+ this.bufferData = new IOBuffer(bufferData);
18859
+ const formatCheck = this.bufferData.readBytes(2);
18860
+ if (formatCheck[0] !== 0x42 && formatCheck[1] !== 0x4d) {
18861
+ throw new Error('This is not a BMP image or the encoding is not correct.');
18862
+ }
18863
+ this.pixelDataOffset = this.bufferData.skip(8).readUint32();
18864
+ this.width = this.bufferData.skip(4).readUint32();
18865
+ this.height = this.bufferData.readUint32();
18866
+ this.bitsPerPixel = this.bufferData.seek(28).readUint16();
18867
+ if (this.bitsPerPixel !== 1 && this.bitsPerPixel !== 8 && this.bitsPerPixel !== 24 && this.bitsPerPixel !== 32) {
18868
+ throw new Error(`Invalid number of bits per pixel. Supported number of bits per pixel: 1, 8, 24, 32. Received: ${this.bitsPerPixel}`);
18869
+ }
18870
+ this.compression = this.bufferData.readUint32();
18871
+ if (this.compression !== 0 && this.compression !== 3) {
18872
+ throw new Error(`Only BI_RGB and BI_BITFIELDS compression methods are allowed. `);
18873
+ }
18874
+ this.colorMasks = [this.bufferData.seek(54).readUint32(), this.bufferData.readUint32(), this.bufferData.readUint32()];
18875
+ if (this.bitsPerPixel === 32 && (this.colorMasks[0] !== 0x00ff0000 || this.colorMasks[1] !== 0x0000ff00 || this.colorMasks[2] !== 0x000000ff)) {
18876
+ throw new Error(`Unsupported color masks detected in 32-bit BMP image. Only standard RGBA (${0x00ff0000.toString(16)}, ${0x0000ff00.toString(16)}, ${0x000000ff.toString(16)}) masks are supported. Received: ${this.colorMasks[0].toString(16)},${this.colorMasks[1].toString(16)},${this.colorMasks[2].toString(16)}.`);
18877
+ }
18878
+ this.bufferData.skip(1); // skipping image size.
18879
+ this.xPixelsPerMeter = this.bufferData.seek(38).readInt32();
18880
+ this.yPixelsPerMeter = this.bufferData.readInt32();
18881
+ this.bufferData.skip(1);
18882
+ }
18883
+ decode() {
18884
+ this.bufferData.seek(this.pixelDataOffset);
18885
+ this.bufferData.setBigEndian();
18886
+ const channels = Math.ceil(this.bitsPerPixel / 8);
18887
+ const components = channels % 2 === 0 ? channels - 1 : channels;
18888
+ const data = this.decodePixelData(channels, components);
18889
+ return {
18890
+ width: this.width,
18891
+ height: this.height,
18892
+ bitsPerPixel: this.bitsPerPixel,
18893
+ compression: this.compression,
18894
+ colorMasks: this.colorMasks,
18895
+ channels,
18896
+ components,
18897
+ data,
18898
+ yPixelsPerMeter: this.yPixelsPerMeter,
18899
+ xPixelsPerMeter: this.xPixelsPerMeter
18900
+ };
18901
+ }
18902
+ decodePixelData(channels, components) {
18903
+ const data = new Uint8Array(this.height * this.width * channels);
18904
+ if (this.bitsPerPixel === 1) {
18905
+ this.decodeBitDepth1Pixels(data);
18906
+ } else if (channels === components) {
18907
+ this.decodeStandardPixels(data, channels);
18908
+ } else {
18909
+ this.decodePixelsWithAlpha(data, channels, components);
18910
+ }
18911
+ return data;
18912
+ }
18913
+ decodeBitDepth1Pixels(data) {
18914
+ let currentNumber = 0;
18915
+ for (let row = 0; row < this.height; row++) {
18916
+ for (let col = 0; col < this.width; col++) {
18917
+ const bitIndex = col % 32;
18918
+ if (bitIndex === 0) {
18919
+ currentNumber = this.bufferData.readUint32();
18920
+ }
18921
+ if (currentNumber & 1 << 31 - bitIndex) {
18922
+ data[(this.height - row - 1) * this.width + col] = 1;
18923
+ }
18924
+ }
18925
+ }
18926
+ }
18927
+ decodeStandardPixels(data, channels) {
18928
+ const padding = this.calculatePadding(channels);
18929
+ for (let row = 0; row < this.height; row++) {
18930
+ const rowOffset = (this.height - row - 1) * this.width;
18931
+ for (let col = 0; col < this.width; col++) {
18932
+ for (let channel = channels - 1; channel >= 0; channel--) {
18933
+ data[(rowOffset + col) * channels + channel] = this.bufferData.readByte();
18934
+ }
18935
+ }
18936
+ this.bufferData.skip(padding);
18937
+ }
18938
+ }
18939
+ decodePixelsWithAlpha(data, channels, components) {
18940
+ for (let row = 0; row < this.height; row++) {
18941
+ const rowOffset = (this.height - row - 1) * this.width;
18942
+ for (let col = 0; col < this.width; col++) {
18943
+ const pixelBaseIndex = (rowOffset + col) * channels;
18944
+ // Decode color components
18945
+ for (let component = components - 1; component >= 0; component--) {
18946
+ data[pixelBaseIndex + component] = this.bufferData.readByte();
18947
+ }
18948
+ // Decode alpha channel
18949
+ data[pixelBaseIndex + components] = this.bufferData.readByte();
18950
+ }
18951
+ }
18952
+ }
18953
+ calculatePadding(channels) {
18954
+ return this.width * channels % 4 === 0 ? 0 : 4 - this.width * channels % 4;
18955
+ }
18956
+ }
18957
+
18454
18958
  const BITMAPV5HEADER = {
18455
18959
  LogicalColorSpace: {
18456
18960
  LCS_sRGB: 0x73524742},
@@ -18612,25 +19116,41 @@ function encode$2(data) {
18612
19116
  const encoder = new BMPEncoder(data);
18613
19117
  return encoder.encode();
18614
19118
  }
19119
+ /**
19120
+ * Decodes BMP format image into data.
19121
+ * @param data - Buffer with image data.
19122
+ * @returns - Decoded data.
19123
+ */
19124
+ function decode$3(data) {
19125
+ const decoder = new BMPDecoder(data);
19126
+ return decoder.decode();
19127
+ }
18615
19128
 
18616
19129
  /**
18617
19130
  * Creates a BMP buffer from a mask.
18618
- * @param mask - The mask instance.
19131
+ * @param image - The mask instance.
18619
19132
  * @returns The buffer.
18620
19133
  */
18621
- function encodeBmp(mask) {
18622
- if (!(mask instanceof Mask)) {
18623
- throw new TypeError('Image bmp encoding is not implemented.');
19134
+ function encodeBmp(image) {
19135
+ if (image instanceof Image) {
19136
+ return encode$2({
19137
+ width: image.width,
19138
+ height: image.height,
19139
+ components: image.components,
19140
+ bitsPerPixel: image.channels * image.bitDepth,
19141
+ channels: image.channels,
19142
+ data: image.getRawImage().data
19143
+ });
19144
+ } else {
19145
+ return encode$2({
19146
+ width: image.width,
19147
+ height: image.height,
19148
+ components: 1,
19149
+ bitsPerPixel: 1,
19150
+ channels: 1,
19151
+ data: image.getRawImage().data
19152
+ });
18624
19153
  }
18625
- const imageData = mask.getRawImage();
18626
- return encode$2({
18627
- width: imageData.width,
18628
- height: imageData.height,
18629
- components: 1,
18630
- bitsPerPixel: 1,
18631
- channels: 1,
18632
- data: imageData.data
18633
- });
18634
19154
  }
18635
19155
 
18636
19156
  var encoder = {exports: {}};
@@ -28097,6 +28617,10 @@ function encodePng$1(png, options) {
28097
28617
  const encoder = new PngEncoder(png, options);
28098
28618
  return encoder.encode();
28099
28619
  }
28620
+ function decodeApng(data, options) {
28621
+ const decoder = new PngDecoder(data, options);
28622
+ return decoder.decodeApng();
28623
+ }
28100
28624
 
28101
28625
  /**
28102
28626
  * Creates a PNG buffer from an image.
@@ -28134,10 +28658,10 @@ const defaultPng = {
28134
28658
  * @returns The encoded image.
28135
28659
  */
28136
28660
  function encode(image, options = defaultPng) {
28137
- return z(options).with({
28661
+ return M$2(options).with({
28138
28662
  format: 'png'
28139
28663
  }, options => encodePng(image, options.encoderOptions)).with({
28140
- format: N$1.union('jpg', 'jpeg')
28664
+ format: z.union('jpg', 'jpeg')
28141
28665
  }, options => encodeJpeg(image, options.encoderOptions)).with({
28142
28666
  format: 'bmp'
28143
28667
  }, () => encodeBmp(image)).exhaustive();
@@ -28149,7 +28673,7 @@ function encode(image, options = defaultPng) {
28149
28673
  * @returns - The `fs`, `path` and `url` Node.js modules.
28150
28674
  */
28151
28675
  function getNodeApiOrThrow(methodName) {
28152
- if (typeof process === 'undefined' || typeof process.getBuiltinModule !== 'function') {
28676
+ if (!isNode()) {
28153
28677
  throw new Error(`${methodName} is only implemented for Node.js`);
28154
28678
  }
28155
28679
  return {
@@ -28158,6 +28682,35 @@ function getNodeApiOrThrow(methodName) {
28158
28682
  url: process.getBuiltinModule('node:url')
28159
28683
  };
28160
28684
  }
28685
+ let CanvasCtorBrowser;
28686
+ let CanvasCtorNode;
28687
+ /**
28688
+ * Returns a 2D canvas context for rendering on the browser or Node.js.
28689
+ * @param width - Width of the canvas.
28690
+ * @param height - Height of the canvas.
28691
+ * @returns The initialised canvas context.
28692
+ */
28693
+ function getCanvasContext(width, height) {
28694
+ if (isNode()) {
28695
+ CanvasCtorNode ??= getRequireFn()('skia-canvas').Canvas;
28696
+ return new CanvasCtorNode(width, height).getContext('2d');
28697
+ } else {
28698
+ CanvasCtorBrowser ??= globalThis.OffscreenCanvas;
28699
+ const context = new CanvasCtorBrowser(width, height).getContext('2d');
28700
+ if (!context) {
28701
+ throw new Error('Failed to create canvas context');
28702
+ }
28703
+ return context;
28704
+ }
28705
+ }
28706
+ function isNode() {
28707
+ return typeof process !== 'undefined' && typeof process.getBuiltinModule === 'function';
28708
+ }
28709
+ let requireFn;
28710
+ function getRequireFn() {
28711
+ requireFn ??= process.getBuiltinModule('node:module').createRequire(import.meta.url);
28712
+ return requireFn;
28713
+ }
28161
28714
 
28162
28715
  /**
28163
28716
  * Asynchronously write an image to the disk.
@@ -28184,7 +28737,7 @@ async function write(path, image, options) {
28184
28737
  await nodeApi.fs.promises.writeFile(path, toWrite);
28185
28738
  }
28186
28739
  /**
28187
- * Synchronous version of @see {@link write}.
28740
+ * Synchronous version of {@link write}.
28188
28741
  * This method is only implemented for Node.js.
28189
28742
  * @param path - Path where the image should be written.
28190
28743
  * @param image - Image to save.
@@ -28334,7 +28887,7 @@ function encodeDataURL(image, options = defaultPng) {
28334
28887
  * @returns The matrix.
28335
28888
  */
28336
28889
  function getMatrixFromPoints(points) {
28337
- const matrix = new Matrix(3, points.length);
28890
+ const matrix = new Matrix$1(3, points.length);
28338
28891
  for (let i = 0; i < points.length; i++) {
28339
28892
  matrix.set(0, i, points[i].column);
28340
28893
  matrix.set(1, i, points[i].row);
@@ -28655,7 +29208,8 @@ function removeClosePoints(points, image, options) {
28655
29208
  }
28656
29209
  const channel = options?.channel || 0;
28657
29210
  const isMax = kind === 'maximum';
28658
- const sortedPoints = points.slice().sort(getSort(image, channel, isMax));
29211
+ const sortedPoints = points.slice();
29212
+ sortedPoints.sort(getSort(image, channel, isMax));
28659
29213
  if (distance > 0) {
28660
29214
  for (let i = 0; i < sortedPoints.length; i++) {
28661
29215
  for (let j = i + 1; j < sortedPoints.length; j++) {
@@ -29643,18 +30197,50 @@ var fileTypeExports = fileType$1.exports;
29643
30197
 
29644
30198
  const fileType = fileTypeExports;
29645
30199
  const imageExts = new Set(['jpg', 'png', 'gif', 'webp', 'flif', 'cr2', 'tif', 'bmp', 'jxr', 'psd', 'ico', 'bpg', 'jp2', 'jpm', 'jpx', 'heic', 'cur', 'dcm']);
29646
- const imageType = input => {
30200
+ const imageType$1 = input => {
29647
30201
  const ret = fileType(input);
29648
30202
  return imageExts.has(ret && ret.ext) ? ret : null;
29649
30203
  };
29650
- imageType$2.exports = imageType;
30204
+ imageType$2.exports = imageType$1;
29651
30205
  // TODO: Remove this for the next major release
29652
- imageType$2.exports.default = imageType;
29653
- Object.defineProperty(imageType, 'minimumBytes', {
30206
+ imageType$2.exports.default = imageType$1;
30207
+ Object.defineProperty(imageType$1, 'minimumBytes', {
29654
30208
  value: fileType.minimumBytes
29655
30209
  });
29656
30210
  var imageTypeExports = imageType$2.exports;
29657
- var imageType$1 = /*@__PURE__*/getDefaultExportFromCjs(imageTypeExports);
30211
+ var imageType = /*@__PURE__*/getDefaultExportFromCjs(imageTypeExports);
30212
+
30213
+ /**
30214
+ * Decode a BMP. See the fast-bmp npm module.
30215
+ * @param data - The data to decode.
30216
+ * @returns The decoded image or mask.
30217
+ */
30218
+ function decodeBmp(data) {
30219
+ const decodedData = decode$3(data);
30220
+ if (decodedData.bitsPerPixel === 1) {
30221
+ const mask = new Mask(decodedData.width, decodedData.height, {
30222
+ data: decodedData.data
30223
+ });
30224
+ return mask.convertColor('GREY');
30225
+ } else {
30226
+ let colorModel;
30227
+ switch (decodedData.channels) {
30228
+ case 1:
30229
+ colorModel = 'GREY';
30230
+ break;
30231
+ case 3:
30232
+ colorModel = 'RGB';
30233
+ break;
30234
+ default:
30235
+ colorModel = 'RGBA';
30236
+ break;
30237
+ }
30238
+ return new Image(decodedData.width, decodedData.height, {
30239
+ colorModel,
30240
+ data: decodedData.data
30241
+ });
30242
+ }
30243
+ }
29658
30244
 
29659
30245
  const tagsById$2 = {
29660
30246
  0x829a: 'ExposureTime',
@@ -30374,7 +30960,7 @@ class TiffIfd extends IFD {
30374
30960
  return this.get('SamplesPerPixel') || 1;
30375
30961
  }
30376
30962
  get rowsPerStrip() {
30377
- return this.get('RowsPerStrip');
30963
+ return this.get('RowsPerStrip') || 2 ** 32 - 1;
30378
30964
  }
30379
30965
  get stripByteCounts() {
30380
30966
  return alwaysArray(this.get('StripByteCounts'));
@@ -30928,10 +31514,16 @@ function decodeJpeg(buffer) {
30928
31514
  function decodePng(buffer) {
30929
31515
  const png = decodePng$1(buffer);
30930
31516
  let colorModel;
30931
- const bitDepth = png.depth === 16 ? 16 : 8;
31517
+ const bitDepth = png.depth;
30932
31518
  if (png.palette) {
30933
31519
  return loadPalettePng(png);
30934
31520
  }
31521
+ if (bitDepth === 1) {
31522
+ return new Image(png.width, png.height, {
31523
+ data: decodeBinary(png),
31524
+ colorModel: 'GREY'
31525
+ });
31526
+ }
30935
31527
  switch (png.channels) {
30936
31528
  case 1:
30937
31529
  colorModel = 'GREY';
@@ -30962,7 +31554,7 @@ function decodePng(buffer) {
30962
31554
  function loadPalettePng(png) {
30963
31555
  assert(png.palette);
30964
31556
  const pixels = png.width * png.height;
30965
- const data = new Uint8Array(pixels * 3);
31557
+ const data = new Uint8Array(pixels * png.palette[0].length);
30966
31558
  const pixelsPerByte = 8 / png.depth;
30967
31559
  const factor = png.depth < 8 ? pixelsPerByte : 1;
30968
31560
  const mask = Number.parseInt('1'.repeat(png.depth), 2);
@@ -30974,14 +31566,32 @@ function loadPalettePng(png) {
30974
31566
  value = value >>> png.depth * (pixelsPerByte - 1 - i % pixelsPerByte) & mask;
30975
31567
  }
30976
31568
  const paletteValue = png.palette[value];
30977
- data[dataIndex++] = paletteValue[0];
30978
- data[dataIndex++] = paletteValue[1];
30979
- data[dataIndex++] = paletteValue[2];
31569
+ for (const paletteChannel of paletteValue) {
31570
+ data[dataIndex++] = paletteChannel;
31571
+ }
30980
31572
  }
30981
31573
  return new Image(png.width, png.height, {
30982
- data
31574
+ data,
31575
+ colorModel: png.palette[0].length === 4 ? 'RGBA' : 'RGB'
30983
31576
  });
30984
31577
  }
31578
+ function decodeBinary(png) {
31579
+ const totalPixels = png.width * png.height;
31580
+ const result = new Uint8Array(totalPixels);
31581
+ const pngData = png.data;
31582
+ const padding = png.width % 8;
31583
+ const bytesPerLine = Math.ceil(png.width / 8);
31584
+ let pixelIndex = 0;
31585
+ for (let byteIndex = 0; byteIndex < pngData.length && pixelIndex < totalPixels; byteIndex++) {
31586
+ const byte = pngData[byteIndex];
31587
+ const limit = byteIndex % bytesPerLine === 0 ? 8 - padding : 0;
31588
+ for (let bitIndex = 7; bitIndex >= limit && pixelIndex < totalPixels; bitIndex--) {
31589
+ const bit = byte >> bitIndex & 1;
31590
+ result[pixelIndex++] = bit * 255;
31591
+ }
31592
+ }
31593
+ return result;
31594
+ }
30985
31595
 
30986
31596
  /**
30987
31597
  * Decode a TIFF. See the tiff module.
@@ -30989,9 +31599,10 @@ function loadPalettePng(png) {
30989
31599
  * @returns The decoded image.
30990
31600
  */
30991
31601
  function decodeTiff(buffer) {
30992
- const result = decodeTIFF(buffer);
31602
+ const result = decodeTIFF(buffer, {
31603
+ pages: [0]
31604
+ });
30993
31605
  return getImageFromIFD(result[0]);
30994
- // TODO: optimize not to decode whole file
30995
31606
  }
30996
31607
  /**
30997
31608
  * Create image from a single IFD.
@@ -30999,32 +31610,59 @@ function decodeTiff(buffer) {
30999
31610
  * @returns The decoded image.
31000
31611
  */
31001
31612
  function getImageFromIFD(ifd) {
31613
+ if (ifd.data instanceof Float32Array || ifd.data instanceof Float64Array) {
31614
+ throw new Error('Float TIFF data is not supported.');
31615
+ }
31002
31616
  if (ifd.type === 3) {
31003
- // Palette
31004
- const data = new Uint16Array(3 * ifd.width * ifd.height);
31617
+ const hasAlpha = ifd.samplesPerPixel === 2;
31618
+ const pixelLength = hasAlpha ? 4 : 3;
31619
+ const data = new Uint16Array(pixelLength * ifd.width * ifd.height);
31005
31620
  const palette = ifd.palette;
31006
31621
  let ptr = 0;
31007
- for (const index of ifd.data) {
31008
- const color = palette[index];
31009
- data[ptr++] = color[0];
31010
- data[ptr++] = color[1];
31011
- data[ptr++] = color[2];
31622
+ if (hasAlpha) {
31623
+ for (let index = 0; index < ifd.data.length; index += ifd.samplesPerPixel) {
31624
+ const color = palette[ifd.data[index]];
31625
+ data[ptr++] = color[0];
31626
+ data[ptr++] = color[1];
31627
+ data[ptr++] = color[2];
31628
+ // To ensure that the value is 16 bits.
31629
+ data[ptr++] = Math.round(ifd.data[index + 1] / 2 ** ifd.bitsPerSample * 65535);
31630
+ }
31631
+ } else {
31632
+ for (let index = 0; index < ifd.data.length; index += ifd.samplesPerPixel) {
31633
+ const color = palette[ifd.data[index]];
31634
+ data[ptr++] = color[0];
31635
+ data[ptr++] = color[1];
31636
+ data[ptr++] = color[2];
31637
+ }
31012
31638
  }
31013
31639
  return new Image(ifd.width, ifd.height, {
31014
31640
  data,
31015
- // TODO: handle alpha properly
31016
- colorModel: ifd.alpha ? 'RGBA' : 'RGB',
31017
- // TODO: handle other bit depths
31641
+ colorModel: hasAlpha ? 'RGBA' : 'RGB',
31018
31642
  bitDepth: 16,
31019
31643
  meta: getMetadata(ifd)
31020
31644
  });
31645
+ } else if (ifd.type === 1 || ifd.type === 0) {
31646
+ if (ifd.bitsPerSample !== 1) {
31647
+ return new Image(ifd.width, ifd.height, {
31648
+ data: ifd.data,
31649
+ bitDepth: ifd.bitsPerSample,
31650
+ colorModel: ifd.alpha ? 'GREYA' : 'GREY',
31651
+ meta: getMetadata(ifd)
31652
+ });
31653
+ } else {
31654
+ return new Image(ifd.width, ifd.height, {
31655
+ data: ifd.data.map(pixel => pixel * 255),
31656
+ bitDepth: 8,
31657
+ colorModel: 'GREY',
31658
+ meta: getMetadata(ifd)
31659
+ });
31660
+ }
31021
31661
  } else {
31022
31662
  return new Image(ifd.width, ifd.height, {
31023
- // TODO: handle float data
31024
- // @ts-expect-error float data not handled yet
31025
31663
  data: ifd.data,
31026
31664
  bitDepth: ifd.bitsPerSample,
31027
- colorModel: ifd.type === 2 ? ifd.alpha ? 'RGBA' : 'RGB' : ifd.alpha ? 'GREYA' : 'GREY',
31665
+ colorModel: ifd.alpha ? 'RGBA' : 'RGB',
31028
31666
  meta: getMetadata(ifd)
31029
31667
  });
31030
31668
  }
@@ -31038,14 +31676,16 @@ function getImageFromIFD(ifd) {
31038
31676
  */
31039
31677
  function decode(data) {
31040
31678
  const typedArray = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
31041
- const type = imageType$1(typedArray);
31042
- return z(type).with({
31679
+ const type = imageType(typedArray);
31680
+ return M$2(type).with({
31043
31681
  mime: 'image/png'
31044
31682
  }, () => decodePng(typedArray)).with({
31045
31683
  mime: 'image/jpeg'
31046
31684
  }, () => decodeJpeg(typedArray)).with({
31047
31685
  mime: 'image/tiff'
31048
- }, () => decodeTiff(typedArray)).otherwise(() => {
31686
+ }, () => decodeTiff(typedArray)).with({
31687
+ mime: 'image/bmp'
31688
+ }, () => decodeBmp(typedArray)).otherwise(() => {
31049
31689
  throw new RangeError(`invalid data format: ${type?.mime}`);
31050
31690
  });
31051
31691
  }
@@ -31063,7 +31703,7 @@ async function read(path) {
31063
31703
  return decode(data);
31064
31704
  }
31065
31705
  /**
31066
- * Synchronous version of @see {@link read}.
31706
+ * Synchronous version of {@link read}.
31067
31707
  * This method is only implemented for Node.js.
31068
31708
  * @param path - The path to the image.
31069
31709
  * @returns Image instance.
@@ -31217,7 +31857,7 @@ function getRainbowMap(options) {
31217
31857
  } = options;
31218
31858
  const colorMap = new Uint32Array(nbNegative + nbPositive + 1);
31219
31859
  const hueRange = 360;
31220
- const step = z(roiKind).with('bw', () => hueRange / (nbNegative + nbPositive)).with('black', () => hueRange / nbNegative).with('white', () => hueRange / nbPositive).exhaustive();
31860
+ const step = M$2(roiKind).with('bw', () => hueRange / (nbNegative + nbPositive)).with('black', () => hueRange / nbNegative).with('white', () => hueRange / nbPositive).exhaustive();
31221
31861
  // negative values
31222
31862
  let hue = 0;
31223
31863
  if (roiKind === 'bw' || roiKind === 'black') {
@@ -31287,7 +31927,7 @@ function getColorMap(options) {
31287
31927
  roiKind: 'bw',
31288
31928
  ...options
31289
31929
  };
31290
- return z(mode).with('binary', () => getBinaryMap(options)).with('saturation', () => getSaturationMap(options)).with('rainbow', () => getRainbowMap(options)).exhaustive();
31930
+ return M$2(mode).with('binary', () => getBinaryMap(options)).with('saturation', () => getSaturationMap(options)).with('rainbow', () => getRainbowMap(options)).exhaustive();
31291
31931
  }
31292
31932
 
31293
31933
  const RoisColorMode = {
@@ -32102,7 +32742,7 @@ function getRois(roiMapManager, options = {}) {
32102
32742
  if (roiMapManager.blackRois.length === 0 && roiMapManager.whiteRois.length === 0) {
32103
32743
  computeRois(roiMapManager);
32104
32744
  }
32105
- const rois = z(kind).with('black', () => roiMapManager.blackRois).with('white', () => roiMapManager.whiteRois).with('bw', () => [...roiMapManager.whiteRois, ...roiMapManager.blackRois]).exhaustive();
32745
+ const rois = M$2(kind).with('black', () => roiMapManager.blackRois).with('white', () => roiMapManager.whiteRois).with('bw', () => [...roiMapManager.whiteRois, ...roiMapManager.blackRois]).exhaustive();
32106
32746
  return rois.filter(roi => roi.surface >= minSurface && roi.surface <= maxSurface);
32107
32747
  }
32108
32748
 
@@ -32136,7 +32776,7 @@ class RoiMapManager {
32136
32776
  * @returns The ROI map matrix.
32137
32777
  */
32138
32778
  getMapMatrix() {
32139
- return Matrix.from1DArray(this.map.height, this.map.width, this.map.data).to2DArray();
32779
+ return Matrix$1.from1DArray(this.map.height, this.map.width, this.map.data).to2DArray();
32140
32780
  }
32141
32781
  getRois(options = {}) {
32142
32782
  return getRois(this, options);
@@ -32276,7 +32916,7 @@ function commonjsRequire(path) {
32276
32916
 
32277
32917
  var priorityQueue = {exports: {}};
32278
32918
 
32279
- (function (module, exports) {
32919
+ (function (module, exports$1) {
32280
32920
  (function (f) {
32281
32921
  {
32282
32922
  module.exports = f();
@@ -32306,7 +32946,7 @@ var priorityQueue = {exports: {}};
32306
32946
  for (var o = 0; o < r.length; o++) s(r[o]);
32307
32947
  return s;
32308
32948
  }({
32309
- 1: [function (_dereq_, module, exports) {
32949
+ 1: [function (_dereq_, module, exports$1) {
32310
32950
  var AbstractPriorityQueue,
32311
32951
  ArrayStrategy,
32312
32952
  BHeapStrategy,
@@ -32351,7 +32991,7 @@ var priorityQueue = {exports: {}};
32351
32991
  "./PriorityQueue/BHeapStrategy": 4,
32352
32992
  "./PriorityQueue/BinaryHeapStrategy": 5
32353
32993
  }],
32354
- 2: [function (_dereq_, module, exports) {
32994
+ 2: [function (_dereq_, module, exports$1) {
32355
32995
  module.exports = function () {
32356
32996
  function AbstractPriorityQueue(options) {
32357
32997
  var ref;
@@ -32389,7 +33029,7 @@ var priorityQueue = {exports: {}};
32389
33029
  return AbstractPriorityQueue;
32390
33030
  }();
32391
33031
  }, {}],
32392
- 3: [function (_dereq_, module, exports) {
33032
+ 3: [function (_dereq_, module, exports$1) {
32393
33033
  var binarySearchForIndexReversed;
32394
33034
  binarySearchForIndexReversed = function (array, value, comparator) {
32395
33035
  var high, low, mid;
@@ -32432,7 +33072,7 @@ var priorityQueue = {exports: {}};
32432
33072
  return ArrayStrategy;
32433
33073
  }();
32434
33074
  }, {}],
32435
- 4: [function (_dereq_, module, exports) {
33075
+ 4: [function (_dereq_, module, exports$1) {
32436
33076
  module.exports = function () {
32437
33077
  function BHeapStrategy(options) {
32438
33078
  var arr, j, k, len, ref, ref1, shift, value;
@@ -32570,7 +33210,7 @@ var priorityQueue = {exports: {}};
32570
33210
  return BHeapStrategy;
32571
33211
  }();
32572
33212
  }, {}],
32573
- 5: [function (_dereq_, module, exports) {
33213
+ 5: [function (_dereq_, module, exports$1) {
32574
33214
  module.exports = function () {
32575
33215
  function BinaryHeapStrategy(options) {
32576
33216
  var ref;
@@ -32892,6 +33532,61 @@ function medianImage(stack) {
32892
33532
  return result;
32893
33533
  }
32894
33534
 
33535
+ /**
33536
+ * Decodes APNG image into a Stack
33537
+ * @param data - APNG data.
33538
+ * @returns stack of frames.
33539
+ */
33540
+ function decodeStackFromApng(data) {
33541
+ const decodedApng = decodeApng(data);
33542
+ const images = [];
33543
+ let colorModel;
33544
+ switch (decodedApng.channels) {
33545
+ case 1:
33546
+ if (decodedApng.palette) {
33547
+ colorModel = decodedApng.palette[0].length === 3 ? 'RGB' : 'RGBA';
33548
+ } else {
33549
+ colorModel = 'GREY';
33550
+ }
33551
+ break;
33552
+ case 2:
33553
+ colorModel = 'GREYA';
33554
+ break;
33555
+ case 3:
33556
+ colorModel = 'RGB';
33557
+ break;
33558
+ default:
33559
+ colorModel = 'RGBA';
33560
+ break;
33561
+ }
33562
+ if (decodedApng.palette) {
33563
+ for (const image of decodedApng.frames) {
33564
+ images.push(new Image(decodedApng.width, decodedApng.height, {
33565
+ data: convertIndexedData(image.data, decodedApng.palette),
33566
+ colorModel
33567
+ }));
33568
+ }
33569
+ } else {
33570
+ for (const image of decodedApng.frames) {
33571
+ images.push(new Image(decodedApng.width, decodedApng.height, {
33572
+ data: image.data,
33573
+ colorModel
33574
+ }));
33575
+ }
33576
+ }
33577
+ const stack = new Stack(images);
33578
+ return stack;
33579
+ }
33580
+ function convertIndexedData(data, palette) {
33581
+ const result = new Uint8Array(data.length * palette[0].length);
33582
+ for (let i = 0; i < data.length; i++) {
33583
+ for (let channel = 0; channel < palette[0].length; channel++) {
33584
+ result[i * palette[0].length + channel] = palette[data[i]][channel];
33585
+ }
33586
+ }
33587
+ return result;
33588
+ }
33589
+
32895
33590
  /**
32896
33591
  * Decode a TIFF and create a stack of images.
32897
33592
  * @param buffer - The data to decode.
@@ -32914,10 +33609,12 @@ function decodeStackFromTiff(buffer) {
32914
33609
  */
32915
33610
  function decodeStack(data) {
32916
33611
  const typedArray = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
32917
- const type = imageType$1(typedArray);
32918
- return z(type).with({
33612
+ const type = imageType(typedArray);
33613
+ return M$2(type).with({
32919
33614
  mime: 'image/tiff'
32920
- }, () => decodeStackFromTiff(typedArray)).otherwise(() => {
33615
+ }, () => decodeStackFromTiff(typedArray)).with({
33616
+ mime: 'image/png'
33617
+ }, () => decodeStackFromApng(typedArray)).otherwise(() => {
32921
33618
  throw new RangeError(`invalid data format: ${type?.mime}`);
32922
33619
  });
32923
33620
  }
@@ -33175,5 +33872,104 @@ const channelLabels = {
33175
33872
  BINARY: ['Mask']
33176
33873
  };
33177
33874
 
33178
- export { BorderType, DerivativeFilter, GreyAlgorithm, Image, ImageColorModel, ImageCoordinates, ImageFormat, InterpolationType, Mask, Montage, MontageDisposition, Roi, RoiKind, RoiMapManager, RoisColorMode, Stack, ThresholdAlgorithm, add, alignMinDifference, and, blur, bottomHat, bruteForceOneMatch, cannyEdgeDetector, channelLabels, clearBorder, close, colorModels, colorRois, computeConvolutionValue, computeMse, computePsnr, computeRmse, computeRois, computeThreshold, convertBinaryToGrey, convertBinaryToRgb, convertBitDepth, convertColor, copyAlpha, copyTo, correctBackground, correctColor, crop, cropAlpha, cropRectangle, crosscheck, decode, decodeJpeg, decodePng, decodeStack, decodeTiff, defaultPng, derivativeFilter, dilate, directConvolution, divide, drawCircleOnImage, drawKeypoints, drawLineOnImage, drawLineOnMask, drawMarker, drawMarkers, drawMatches, drawPoints, drawPolygonOnImage, drawPolygonOnMask, drawPolylineOnImage, drawPolylineOnMask, drawRectangle, encode, encodeDataURL, encodeJpeg, encodePng, erode, extendBorders, extract, fetchURL, flip, floodFill, fromMask, gaussianBlur, getAffineTransform, getBestKeypointsInRadius, getBorderPoints, getBriefDescriptors, getCrosscheckMatches, getDirection, getExtrema, getFastKeypoints, getImageFromIFD, getIntensityCentroid, getMask, getOrientedFastKeypoints, getPerspectiveWarp, getRegressionVariables, getRois, gradientFilter, grey, histogram$1 as histogram, hypotenuse, increaseContrast, invert, level, mean, median, medianFilter, merge, morphologicalGradient, multiply, open, or, order4Points, overlapImages, paintMaskOnImage, paintMaskOnMask, pixelate, rawDirectConvolution, read, readCanvas, readImg, readSync, removeClosePoints, resize, rotate, separableConvolution, solidFill, split, subtract, threshold, topHat, transform, transformRotate, variance, waterShed, write, writeCanvas, writeSync };
33875
+ /**
33876
+ * Draws text on an image.
33877
+ * @param image - Image to write text on.
33878
+ * @param text - Text to write on the image.
33879
+ * @param options - Out Options
33880
+ * @returns Image with drawn text.
33881
+ */
33882
+ function drawText(image, text, options) {
33883
+ if (Array.isArray(text) && text.length === 0) {
33884
+ throw new Error('At least one text element must be provided');
33885
+ }
33886
+ const newImage = getOutputImage(image, options, {
33887
+ clone: true
33888
+ });
33889
+ const defaultFont = options?.font ?? '12px Helvetica';
33890
+ const defaultColor = options?.fontColor ?? [255, 255, 255, 255];
33891
+ const ctx = getCanvasContext(image.width, image.height);
33892
+ if (!Array.isArray(text)) {
33893
+ drawTextElement(image, ctx, text, defaultFont, defaultColor);
33894
+ } else {
33895
+ for (const label of text) {
33896
+ drawTextElement(image, ctx, label, defaultFont, defaultColor);
33897
+ }
33898
+ }
33899
+ layerCanvas(newImage.getRawImage().data, ctx.getImageData(0, 0, image.width, image.height).data, image.channels, image.bitDepth);
33900
+ return newImage;
33901
+ }
33902
+ function drawTextElement(image, ctx, text, defaultFont, defaultColor) {
33903
+ ctx.font = text.font ?? defaultFont;
33904
+ const fontColor = text.fontColor ?? defaultColor;
33905
+ validateValues(fontColor, image);
33906
+ const alpha = fontColor[3] ? fontColor[3] / 255 : 1;
33907
+ const normalizedColor = [fontColor[0] ?? 0, fontColor[1] ?? 0, fontColor[2] ?? 0, alpha];
33908
+ ctx.fillStyle = `rgba(${normalizedColor.join(',')})`;
33909
+ ctx.fillText(String(text.content), text.position.column, text.position.row);
33910
+ }
33911
+ /**
33912
+ * Draws labels on the image data from canvas.
33913
+ * @param imageData - Image data to draw text on.
33914
+ * @param canvasData - Canvas data to draw on the image.
33915
+ * @param numberOfChannels - Number of channels of the initial image.
33916
+ * @param bitDepth - Bit depth of the initial image.
33917
+ */
33918
+ function layerCanvas(imageData, canvasData, numberOfChannels, bitDepth) {
33919
+ const config = CHANNEL_CONFIGS[numberOfChannels] || CHANNEL_CONFIGS[1];
33920
+ const pixelCount = canvasData.length >>> 2;
33921
+ const bitShift = bitDepth - 8;
33922
+ let imageIndex = 0;
33923
+ let canvasIndex = 0;
33924
+ for (let pixel = 0; pixel < pixelCount; pixel++) {
33925
+ const canvasAlpha = canvasData[canvasIndex + 3] / 255;
33926
+ // Skip transparent canvas pixels completely
33927
+ if (canvasAlpha === 0) {
33928
+ imageIndex += numberOfChannels;
33929
+ canvasIndex += 4;
33930
+ continue;
33931
+ }
33932
+ const invAlpha = 1 - canvasAlpha;
33933
+ for (const channel of config.channelOffsets) {
33934
+ const targetIndex = imageIndex + channel;
33935
+ imageData[targetIndex] = Math.round(canvasData[canvasIndex + channel] * canvasAlpha + imageData[targetIndex] * invAlpha) << bitShift;
33936
+ }
33937
+ if (config.hasAlpha) {
33938
+ const alphaIndex = imageIndex + config.alphaOffset;
33939
+ const imageAlpha = (imageData[alphaIndex] >>> bitShift) / 255;
33940
+ const newAlpha = canvasAlpha + imageAlpha * (1 - canvasAlpha);
33941
+ imageData[alphaIndex] = Math.round(newAlpha * 255) << bitShift;
33942
+ }
33943
+ imageIndex += numberOfChannels;
33944
+ canvasIndex += 4;
33945
+ }
33946
+ }
33947
+ const CHANNEL_CONFIGS = {
33948
+ // GREY
33949
+ 1: {
33950
+ channelOffsets: [0],
33951
+ hasAlpha: false,
33952
+ alphaOffset: undefined
33953
+ },
33954
+ // GREYA
33955
+ 2: {
33956
+ channelOffsets: [0],
33957
+ hasAlpha: true,
33958
+ alphaOffset: 1
33959
+ },
33960
+ 3: {
33961
+ // RGB
33962
+ channelOffsets: [0, 1, 2],
33963
+ hasAlpha: false,
33964
+ alphaOffset: undefined
33965
+ },
33966
+ 4: {
33967
+ // RGBA
33968
+ channelOffsets: [0, 1, 2],
33969
+ hasAlpha: true,
33970
+ alphaOffset: 3
33971
+ }
33972
+ };
33973
+
33974
+ export { BorderType, DerivativeFilter, GreyAlgorithm, Image, ImageColorModel, ImageCoordinates, ImageFormat, InterpolationType, Mask, Montage, MontageDisposition, Roi, RoiKind, RoiMapManager, RoisColorMode, Stack, ThresholdAlgorithm, add, alignMinDifference, and, blur, bottomHat, bruteForceOneMatch, cannyEdgeDetector, channelLabels, clearBorder, close, colorModels, colorRois, computeConvolutionValue, computeMse, computePsnr, computeRmse, computeRois, computeThreshold, convertBinaryToGrey, convertBinaryToRgb, convertBitDepth, convertColor, copyAlpha, copyTo, correctBackground, correctColor, crop, cropAlpha, cropRectangle, crosscheck, decode, decodeJpeg, decodePng, decodeStack, decodeTiff, defaultPng, derivativeFilter, dilate, directConvolution, divide, drawCircleOnImage, drawKeypoints, drawLineOnImage, drawLineOnMask, drawMarker, drawMarkers, drawMatches, drawPoints, drawPolygonOnImage, drawPolygonOnMask, drawPolylineOnImage, drawPolylineOnMask, drawRectangle, drawText, encode, encodeDataURL, encodeJpeg, encodePng, erode, extendBorders, extract, fetchURL, flip, floodFill, fromMask, gaussianBlur, getAffineTransform, getBestKeypointsInRadius, getBorderPoints, getBriefDescriptors, getCrosscheckMatches, getDirection, getExtrema, getFastKeypoints, getImageFromIFD, getIntensityCentroid, getMask, getOrientedFastKeypoints, getPerspectiveWarp, getRegressionVariables, getRois, gradientFilter, grey, histogram$1 as histogram, hypotenuse, increaseContrast, invert, level, mean, median, medianFilter, merge, morphologicalGradient, multiply, open, or, order4Points, overlapImages, paintMaskOnImage, paintMaskOnMask, pixelate, rawDirectConvolution, read, readCanvas, readImg, readSync, removeClosePoints, resize, rotate, separableConvolution, solidFill, split, subtract, threshold, topHat, transform, transformRotate, variance, waterShed, write, writeCanvas, writeSync };
33179
33975
  //# sourceMappingURL=image-js.esm.js.map