@gisfun/maplibre-gl-components 0.15.0-alpha.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 (196) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1960 -0
  3. package/dist/ControlGrid-DN5md8hp.cjs +19636 -0
  4. package/dist/ControlGrid-rVNG7B9O.js +170422 -0
  5. package/dist/DuckDBConverter-B98M0DFs.cjs +23 -0
  6. package/dist/DuckDBConverter-RPq48-t0.js +434 -0
  7. package/dist/ShapefileConverter-AjbEjEyq.cjs +1 -0
  8. package/dist/ShapefileConverter-trvt8J3z.js +125 -0
  9. package/dist/decoder-CLokFc0V.js +8 -0
  10. package/dist/decoder-D9LU4bUo.cjs +1 -0
  11. package/dist/deflate-BA1jZeSX.js +10 -0
  12. package/dist/deflate-DEdCz12a.cjs +1 -0
  13. package/dist/geojson-BQSVgKFt.cjs +1 -0
  14. package/dist/geojson-BSUuDj5k.js +2551 -0
  15. package/dist/geotiff-De1w1lBy.cjs +8 -0
  16. package/dist/geotiff-o_Fq1Na4.js +3108 -0
  17. package/dist/index-8ZZtuDTp.js +705 -0
  18. package/dist/index-B-Nr9y7J.cjs +84 -0
  19. package/dist/index-B5NoFrpY.js +8892 -0
  20. package/dist/index-Bi1MMPUx.js +4163 -0
  21. package/dist/index-C9fk_HKR.js +167 -0
  22. package/dist/index-CBBRBJvR.cjs +274 -0
  23. package/dist/index-CZxPF1qt.js +4 -0
  24. package/dist/index-CiDPSJ9T.cjs +1 -0
  25. package/dist/index-CjM_nbxd.cjs +107 -0
  26. package/dist/index-DQXdX5y1.js +4666 -0
  27. package/dist/index-Dh1kpCb6.cjs +1 -0
  28. package/dist/index-IrsIiQNM.cjs +4 -0
  29. package/dist/index.cjs +3819 -0
  30. package/dist/index.mjs +19580 -0
  31. package/dist/jpeg-CF9OGQg_.js +533 -0
  32. package/dist/jpeg-JSQOxGHy.cjs +1 -0
  33. package/dist/lerc-7LlQoT6u.js +1032 -0
  34. package/dist/lerc-BIsodce9.cjs +1 -0
  35. package/dist/lzw-BZniWIYG.js +84 -0
  36. package/dist/lzw-BhML-BvT.cjs +1 -0
  37. package/dist/main-dist-Bymiy5aM.cjs +2 -0
  38. package/dist/main-dist-Cv8AKwrY.js +629 -0
  39. package/dist/maplibre-geoman.es-Bxdg-2EU.cjs +129 -0
  40. package/dist/maplibre-geoman.es-CFgM2ajb.js +22827 -0
  41. package/dist/maplibre-gl-components.css +1 -0
  42. package/dist/packbits-B9b7gX2c.cjs +1 -0
  43. package/dist/packbits-DWY5O-FG.js +24 -0
  44. package/dist/pako.esm-Bx5X36Wo.js +1074 -0
  45. package/dist/pako.esm-DZC2QrbJ.cjs +1 -0
  46. package/dist/raw-C3ARbSFo.cjs +1 -0
  47. package/dist/raw-DUslI1gr.js +9 -0
  48. package/dist/react.cjs +1 -0
  49. package/dist/react.mjs +1306 -0
  50. package/dist/types/index.d.ts +44 -0
  51. package/dist/types/index.d.ts.map +1 -0
  52. package/dist/types/lib/adapters/AddVectorAdapter.d.ts +66 -0
  53. package/dist/types/lib/adapters/AddVectorAdapter.d.ts.map +1 -0
  54. package/dist/types/lib/adapters/CogLayerAdapter.d.ts +126 -0
  55. package/dist/types/lib/adapters/CogLayerAdapter.d.ts.map +1 -0
  56. package/dist/types/lib/adapters/PMTilesLayerAdapter.d.ts +78 -0
  57. package/dist/types/lib/adapters/PMTilesLayerAdapter.d.ts.map +1 -0
  58. package/dist/types/lib/adapters/StacLayerAdapter.d.ts +71 -0
  59. package/dist/types/lib/adapters/StacLayerAdapter.d.ts.map +1 -0
  60. package/dist/types/lib/adapters/ZarrLayerAdapter.d.ts +72 -0
  61. package/dist/types/lib/adapters/ZarrLayerAdapter.d.ts.map +1 -0
  62. package/dist/types/lib/adapters/index.d.ts +7 -0
  63. package/dist/types/lib/adapters/index.d.ts.map +1 -0
  64. package/dist/types/lib/addControlGrid.d.ts +80 -0
  65. package/dist/types/lib/addControlGrid.d.ts.map +1 -0
  66. package/dist/types/lib/colormaps/diverging.d.ts +30 -0
  67. package/dist/types/lib/colormaps/diverging.d.ts.map +1 -0
  68. package/dist/types/lib/colormaps/index.d.ts +32 -0
  69. package/dist/types/lib/colormaps/index.d.ts.map +1 -0
  70. package/dist/types/lib/colormaps/misc.d.ts +38 -0
  71. package/dist/types/lib/colormaps/misc.d.ts.map +1 -0
  72. package/dist/types/lib/colormaps/sequential.d.ts +22 -0
  73. package/dist/types/lib/colormaps/sequential.d.ts.map +1 -0
  74. package/dist/types/lib/converters/DuckDBConverter.d.ts +112 -0
  75. package/dist/types/lib/converters/DuckDBConverter.d.ts.map +1 -0
  76. package/dist/types/lib/converters/ShapefileConverter.d.ts +56 -0
  77. package/dist/types/lib/converters/ShapefileConverter.d.ts.map +1 -0
  78. package/dist/types/lib/converters/index.d.ts +8 -0
  79. package/dist/types/lib/converters/index.d.ts.map +1 -0
  80. package/dist/types/lib/converters/types.d.ts +75 -0
  81. package/dist/types/lib/converters/types.d.ts.map +1 -0
  82. package/dist/types/lib/core/AddVector.d.ts +116 -0
  83. package/dist/types/lib/core/AddVector.d.ts.map +1 -0
  84. package/dist/types/lib/core/Basemap.d.ts +206 -0
  85. package/dist/types/lib/core/Basemap.d.ts.map +1 -0
  86. package/dist/types/lib/core/BasemapReact.d.ts +32 -0
  87. package/dist/types/lib/core/BasemapReact.d.ts.map +1 -0
  88. package/dist/types/lib/core/BookmarkControl.d.ts +180 -0
  89. package/dist/types/lib/core/BookmarkControl.d.ts.map +1 -0
  90. package/dist/types/lib/core/ChoroplethControl.d.ts +105 -0
  91. package/dist/types/lib/core/ChoroplethControl.d.ts.map +1 -0
  92. package/dist/types/lib/core/CogLayer.d.ts +139 -0
  93. package/dist/types/lib/core/CogLayer.d.ts.map +1 -0
  94. package/dist/types/lib/core/CogLayerReact.d.ts +32 -0
  95. package/dist/types/lib/core/CogLayerReact.d.ts.map +1 -0
  96. package/dist/types/lib/core/Colorbar.d.ts +133 -0
  97. package/dist/types/lib/core/Colorbar.d.ts.map +1 -0
  98. package/dist/types/lib/core/ColorbarGuiControl.d.ts +79 -0
  99. package/dist/types/lib/core/ColorbarGuiControl.d.ts.map +1 -0
  100. package/dist/types/lib/core/ColorbarReact.d.ts +34 -0
  101. package/dist/types/lib/core/ColorbarReact.d.ts.map +1 -0
  102. package/dist/types/lib/core/ControlGrid.d.ts +125 -0
  103. package/dist/types/lib/core/ControlGrid.d.ts.map +1 -0
  104. package/dist/types/lib/core/ControlGridReact.d.ts +32 -0
  105. package/dist/types/lib/core/ControlGridReact.d.ts.map +1 -0
  106. package/dist/types/lib/core/HtmlControl.d.ts +140 -0
  107. package/dist/types/lib/core/HtmlControl.d.ts.map +1 -0
  108. package/dist/types/lib/core/HtmlControlReact.d.ts +32 -0
  109. package/dist/types/lib/core/HtmlControlReact.d.ts.map +1 -0
  110. package/dist/types/lib/core/HtmlGuiControl.d.ts +68 -0
  111. package/dist/types/lib/core/HtmlGuiControl.d.ts.map +1 -0
  112. package/dist/types/lib/core/InspectControl.d.ts +202 -0
  113. package/dist/types/lib/core/InspectControl.d.ts.map +1 -0
  114. package/dist/types/lib/core/InspectControlReact.d.ts +32 -0
  115. package/dist/types/lib/core/InspectControlReact.d.ts.map +1 -0
  116. package/dist/types/lib/core/Legend.d.ts +142 -0
  117. package/dist/types/lib/core/Legend.d.ts.map +1 -0
  118. package/dist/types/lib/core/LegendGuiControl.d.ts +69 -0
  119. package/dist/types/lib/core/LegendGuiControl.d.ts.map +1 -0
  120. package/dist/types/lib/core/LegendReact.d.ts +34 -0
  121. package/dist/types/lib/core/LegendReact.d.ts.map +1 -0
  122. package/dist/types/lib/core/MeasureControl.d.ts +211 -0
  123. package/dist/types/lib/core/MeasureControl.d.ts.map +1 -0
  124. package/dist/types/lib/core/MinimapControl.d.ts +77 -0
  125. package/dist/types/lib/core/MinimapControl.d.ts.map +1 -0
  126. package/dist/types/lib/core/MinimapControlReact.d.ts +32 -0
  127. package/dist/types/lib/core/MinimapControlReact.d.ts.map +1 -0
  128. package/dist/types/lib/core/PMTilesLayer.d.ts +119 -0
  129. package/dist/types/lib/core/PMTilesLayer.d.ts.map +1 -0
  130. package/dist/types/lib/core/PrintControl.d.ts +226 -0
  131. package/dist/types/lib/core/PrintControl.d.ts.map +1 -0
  132. package/dist/types/lib/core/SearchControl.d.ts +172 -0
  133. package/dist/types/lib/core/SearchControl.d.ts.map +1 -0
  134. package/dist/types/lib/core/SearchControlReact.d.ts +32 -0
  135. package/dist/types/lib/core/SearchControlReact.d.ts.map +1 -0
  136. package/dist/types/lib/core/StacLayer.d.ts +107 -0
  137. package/dist/types/lib/core/StacLayer.d.ts.map +1 -0
  138. package/dist/types/lib/core/StacSearch.d.ts +109 -0
  139. package/dist/types/lib/core/StacSearch.d.ts.map +1 -0
  140. package/dist/types/lib/core/Terrain.d.ts +165 -0
  141. package/dist/types/lib/core/Terrain.d.ts.map +1 -0
  142. package/dist/types/lib/core/TerrainReact.d.ts +32 -0
  143. package/dist/types/lib/core/TerrainReact.d.ts.map +1 -0
  144. package/dist/types/lib/core/VectorDataset.d.ts +228 -0
  145. package/dist/types/lib/core/VectorDataset.d.ts.map +1 -0
  146. package/dist/types/lib/core/VectorDatasetReact.d.ts +31 -0
  147. package/dist/types/lib/core/VectorDatasetReact.d.ts.map +1 -0
  148. package/dist/types/lib/core/ViewStateControl.d.ts +205 -0
  149. package/dist/types/lib/core/ViewStateControl.d.ts.map +1 -0
  150. package/dist/types/lib/core/ViewStateControlReact.d.ts +32 -0
  151. package/dist/types/lib/core/ViewStateControlReact.d.ts.map +1 -0
  152. package/dist/types/lib/core/ZarrLayer.d.ts +110 -0
  153. package/dist/types/lib/core/ZarrLayer.d.ts.map +1 -0
  154. package/dist/types/lib/core/types.d.ts +2793 -0
  155. package/dist/types/lib/core/types.d.ts.map +1 -0
  156. package/dist/types/lib/hooks/index.d.ts +13 -0
  157. package/dist/types/lib/hooks/index.d.ts.map +1 -0
  158. package/dist/types/lib/hooks/useBasemap.d.ts +43 -0
  159. package/dist/types/lib/hooks/useBasemap.d.ts.map +1 -0
  160. package/dist/types/lib/hooks/useCogLayer.d.ts +44 -0
  161. package/dist/types/lib/hooks/useCogLayer.d.ts.map +1 -0
  162. package/dist/types/lib/hooks/useColorbar.d.ts +36 -0
  163. package/dist/types/lib/hooks/useColorbar.d.ts.map +1 -0
  164. package/dist/types/lib/hooks/useControlGrid.d.ts +41 -0
  165. package/dist/types/lib/hooks/useControlGrid.d.ts.map +1 -0
  166. package/dist/types/lib/hooks/useHtmlControl.d.ts +39 -0
  167. package/dist/types/lib/hooks/useHtmlControl.d.ts.map +1 -0
  168. package/dist/types/lib/hooks/useInspectControl.d.ts +49 -0
  169. package/dist/types/lib/hooks/useInspectControl.d.ts.map +1 -0
  170. package/dist/types/lib/hooks/useLegend.d.ts +41 -0
  171. package/dist/types/lib/hooks/useLegend.d.ts.map +1 -0
  172. package/dist/types/lib/hooks/useMinimapControl.d.ts +35 -0
  173. package/dist/types/lib/hooks/useMinimapControl.d.ts.map +1 -0
  174. package/dist/types/lib/hooks/useSearchControl.d.ts +43 -0
  175. package/dist/types/lib/hooks/useSearchControl.d.ts.map +1 -0
  176. package/dist/types/lib/hooks/useTerrain.d.ts +43 -0
  177. package/dist/types/lib/hooks/useTerrain.d.ts.map +1 -0
  178. package/dist/types/lib/hooks/useVectorDataset.d.ts +35 -0
  179. package/dist/types/lib/hooks/useVectorDataset.d.ts.map +1 -0
  180. package/dist/types/lib/hooks/useViewState.d.ts +43 -0
  181. package/dist/types/lib/hooks/useViewState.d.ts.map +1 -0
  182. package/dist/types/lib/utils/color.d.ts +47 -0
  183. package/dist/types/lib/utils/color.d.ts.map +1 -0
  184. package/dist/types/lib/utils/fileHelpers.d.ts +207 -0
  185. package/dist/types/lib/utils/fileHelpers.d.ts.map +1 -0
  186. package/dist/types/lib/utils/helpers.d.ts +48 -0
  187. package/dist/types/lib/utils/helpers.d.ts.map +1 -0
  188. package/dist/types/lib/utils/index.d.ts +4 -0
  189. package/dist/types/lib/utils/index.d.ts.map +1 -0
  190. package/dist/types/lib/utils/providers.d.ts +46 -0
  191. package/dist/types/lib/utils/providers.d.ts.map +1 -0
  192. package/dist/types/react.d.ts +15 -0
  193. package/dist/types/react.d.ts.map +1 -0
  194. package/dist/webimage-CBRffWZD.cjs +1 -0
  195. package/dist/webimage-ibSPOLHJ.js +19 -0
  196. package/package.json +137 -0
@@ -0,0 +1,3108 @@
1
+ import { g as Ve } from "./ControlGrid-rVNG7B9O.js";
2
+ const L = {};
3
+ function T(r) {
4
+ return (e, ...t) => Ot(r, e, t);
5
+ }
6
+ function z(r, e) {
7
+ return T(
8
+ je(
9
+ r,
10
+ e
11
+ ).get
12
+ );
13
+ }
14
+ const {
15
+ apply: Ot,
16
+ getOwnPropertyDescriptor: je,
17
+ getPrototypeOf: De,
18
+ ownKeys: Pt
19
+ } = Reflect, {
20
+ iterator: J,
21
+ toStringTag: Ct
22
+ } = Symbol, Ft = Object, {
23
+ create: Ee,
24
+ defineProperty: kt
25
+ } = Ft, Rt = Array, Bt = Rt.prototype, He = Bt[J], Mt = T(He), Ye = ArrayBuffer, Gt = Ye.prototype;
26
+ z(Gt, "byteLength");
27
+ const Ge = typeof SharedArrayBuffer < "u" ? SharedArrayBuffer : null;
28
+ Ge && z(Ge.prototype, "byteLength");
29
+ const $e = De(Uint8Array);
30
+ $e.from;
31
+ const E = $e.prototype;
32
+ E[J];
33
+ T(E.keys);
34
+ T(
35
+ E.values
36
+ );
37
+ T(
38
+ E.entries
39
+ );
40
+ T(E.set);
41
+ T(
42
+ E.reverse
43
+ );
44
+ T(E.fill);
45
+ T(
46
+ E.copyWithin
47
+ );
48
+ T(E.sort);
49
+ T(E.slice);
50
+ T(
51
+ E.subarray
52
+ );
53
+ z(
54
+ E,
55
+ "buffer"
56
+ );
57
+ z(
58
+ E,
59
+ "byteOffset"
60
+ );
61
+ z(
62
+ E,
63
+ "length"
64
+ );
65
+ z(
66
+ E,
67
+ Ct
68
+ );
69
+ const Ut = Uint8Array, Xe = Uint16Array, Oe = Uint32Array, _t = Float32Array, Z = De([][J]()), Ze = T(Z.next), vt = T((function* () {
70
+ })().next), Lt = De(Z), Nt = DataView.prototype, Kt = T(
71
+ Nt.getUint16
72
+ ), Pe = WeakMap, Je = Pe.prototype, Qe = T(Je.get), zt = T(Je.set), We = new Pe(), qt = Ee(null, {
73
+ next: {
74
+ value: function() {
75
+ const e = Qe(We, this);
76
+ return Ze(e);
77
+ }
78
+ },
79
+ [J]: {
80
+ value: function() {
81
+ return this;
82
+ }
83
+ }
84
+ });
85
+ function Vt(r) {
86
+ if (r[J] === He && Z.next === Ze)
87
+ return r;
88
+ const e = Ee(qt);
89
+ return zt(We, e, Mt(r)), e;
90
+ }
91
+ const jt = new Pe(), Ht = Ee(Lt, {
92
+ next: {
93
+ value: function() {
94
+ const e = Qe(jt, this);
95
+ return vt(e);
96
+ },
97
+ writable: !0,
98
+ configurable: !0
99
+ }
100
+ });
101
+ for (const r of Pt(Z))
102
+ r !== "next" && kt(Ht, r, je(Z, r));
103
+ const et = new Ye(4), Yt = new _t(et), $t = new Oe(et), R = new Xe(512), B = new Ut(512);
104
+ for (let r = 0; r < 256; ++r) {
105
+ const e = r - 127;
106
+ e < -24 ? (R[r] = 0, R[r | 256] = 32768, B[r] = 24, B[r | 256] = 24) : e < -14 ? (R[r] = 1024 >> -e - 14, R[r | 256] = 1024 >> -e - 14 | 32768, B[r] = -e - 1, B[r | 256] = -e - 1) : e <= 15 ? (R[r] = e + 15 << 10, R[r | 256] = e + 15 << 10 | 32768, B[r] = 13, B[r | 256] = 13) : e < 128 ? (R[r] = 31744, R[r | 256] = 64512, B[r] = 24, B[r | 256] = 24) : (R[r] = 31744, R[r | 256] = 64512, B[r] = 13, B[r | 256] = 13);
107
+ }
108
+ const Ce = new Oe(2048);
109
+ for (let r = 1; r < 1024; ++r) {
110
+ let e = r << 13, t = 0;
111
+ for (; (e & 8388608) === 0; )
112
+ e <<= 1, t -= 8388608;
113
+ e &= -8388609, t += 947912704, Ce[r] = e | t;
114
+ }
115
+ for (let r = 1024; r < 2048; ++r)
116
+ Ce[r] = 939524096 + (r - 1024 << 13);
117
+ const q = new Oe(64);
118
+ for (let r = 1; r < 31; ++r)
119
+ q[r] = r << 23;
120
+ q[31] = 1199570944;
121
+ q[32] = 2147483648;
122
+ for (let r = 33; r < 63; ++r)
123
+ q[r] = 2147483648 + (r - 32 << 23);
124
+ q[63] = 3347054592;
125
+ const tt = new Xe(64);
126
+ for (let r = 1; r < 64; ++r)
127
+ r !== 32 && (tt[r] = 1024);
128
+ function Xt(r) {
129
+ const e = r >> 10;
130
+ return $t[0] = Ce[tt[e] + (r & 1023)] + q[e], Yt[0];
131
+ }
132
+ function rt(r, e, ...t) {
133
+ return Xt(
134
+ Kt(r, e, ...Vt(t))
135
+ );
136
+ }
137
+ var ie = { exports: {} }, Ue;
138
+ function Zt() {
139
+ if (Ue) return ie.exports;
140
+ Ue = 1;
141
+ function r(e, t, s) {
142
+ const i = s && s.debug || !1;
143
+ i && console.log("[xml-utils] getting " + t + " in " + e);
144
+ const n = typeof e == "object" ? e.outer : e, a = n.slice(0, n.indexOf(">") + 1), o = ['"', "'"];
145
+ for (let c = 0; c < o.length; c++) {
146
+ const l = o[c], f = t + "\\=" + l + "([^" + l + "]*)" + l;
147
+ i && console.log("[xml-utils] pattern:", f);
148
+ const u = new RegExp(f).exec(a);
149
+ if (i && console.log("[xml-utils] match:", u), u) return u[1];
150
+ }
151
+ }
152
+ return ie.exports = r, ie.exports.default = r, ie.exports;
153
+ }
154
+ var Jt = Zt();
155
+ const Se = /* @__PURE__ */ Ve(Jt);
156
+ var ne = { exports: {} }, oe = { exports: {} }, ae = { exports: {} }, _e;
157
+ function Qt() {
158
+ if (_e) return ae.exports;
159
+ _e = 1;
160
+ function r(e, t, s) {
161
+ const n = new RegExp(t).exec(e.slice(s));
162
+ return n ? s + n.index : -1;
163
+ }
164
+ return ae.exports = r, ae.exports.default = r, ae.exports;
165
+ }
166
+ var ce = { exports: {} }, ve;
167
+ function Wt() {
168
+ if (ve) return ce.exports;
169
+ ve = 1;
170
+ function r(e, t, s) {
171
+ const n = new RegExp(t).exec(e.slice(s));
172
+ return n ? s + n.index + n[0].length - 1 : -1;
173
+ }
174
+ return ce.exports = r, ce.exports.default = r, ce.exports;
175
+ }
176
+ var le = { exports: {} }, Le;
177
+ function er() {
178
+ if (Le) return le.exports;
179
+ Le = 1;
180
+ function r(e, t) {
181
+ const s = new RegExp(t, "g"), i = e.match(s);
182
+ return i ? i.length : 0;
183
+ }
184
+ return le.exports = r, le.exports.default = r, le.exports;
185
+ }
186
+ var Ne;
187
+ function tr() {
188
+ if (Ne) return oe.exports;
189
+ Ne = 1;
190
+ const r = Qt(), e = Wt(), t = er();
191
+ function s(i, n, a) {
192
+ const o = a && a.debug || !1, c = !(a && typeof a.nested === !1), l = a && a.startIndex || 0;
193
+ o && console.log("[xml-utils] starting findTagByName with", n, " and ", a);
194
+ const f = r(i, `<${n}[
195
+ >/]`, l);
196
+ if (o && console.log("[xml-utils] start:", f), f === -1) return;
197
+ const h = i.slice(f + n.length);
198
+ let u = e(h, "^[^<]*[ /]>", 0);
199
+ const d = u !== -1 && h[u - 1] === "/";
200
+ if (o && console.log("[xml-utils] selfClosing:", d), d === !1)
201
+ if (c) {
202
+ let x = 0, w = 1, S = 0;
203
+ for (; (u = e(h, "[ /]" + n + ">", x)) !== -1; ) {
204
+ const I = h.substring(x, u + 1);
205
+ if (w += t(I, "<" + n + `[
206
+ >]`), S += t(I, "</" + n + ">"), S >= w) break;
207
+ x = u;
208
+ }
209
+ } else
210
+ u = e(h, "[ /]" + n + ">", 0);
211
+ const g = f + n.length + u + 1;
212
+ if (o && console.log("[xml-utils] end:", g), g === -1) return;
213
+ const y = i.slice(f, g);
214
+ let p;
215
+ return d ? p = null : p = y.slice(y.indexOf(">") + 1, y.lastIndexOf("<")), { inner: p, outer: y, start: f, end: g };
216
+ }
217
+ return oe.exports = s, oe.exports.default = s, oe.exports;
218
+ }
219
+ var Ke;
220
+ function rr() {
221
+ if (Ke) return ne.exports;
222
+ Ke = 1;
223
+ const r = tr();
224
+ function e(t, s, i) {
225
+ const n = [], a = i && i.debug || !1, o = i && typeof i.nested == "boolean" ? i.nested : !0;
226
+ let c = i && i.startIndex || 0, l;
227
+ for (; l = r(t, s, { debug: a, startIndex: c }); )
228
+ o ? c = l.start + 1 + s.length : c = l.end, n.push(l);
229
+ return a && console.log("findTagsByName found", n.length, "tags"), n;
230
+ }
231
+ return ne.exports = e, ne.exports.default = e, ne.exports;
232
+ }
233
+ var sr = rr();
234
+ const ir = /* @__PURE__ */ Ve(sr), U = {
235
+ // TIFF Baseline
236
+ 315: "Artist",
237
+ 258: "BitsPerSample",
238
+ 265: "CellLength",
239
+ 264: "CellWidth",
240
+ 320: "ColorMap",
241
+ 259: "Compression",
242
+ 33432: "Copyright",
243
+ 306: "DateTime",
244
+ 338: "ExtraSamples",
245
+ 266: "FillOrder",
246
+ 289: "FreeByteCounts",
247
+ 288: "FreeOffsets",
248
+ 291: "GrayResponseCurve",
249
+ 290: "GrayResponseUnit",
250
+ 316: "HostComputer",
251
+ 270: "ImageDescription",
252
+ 257: "ImageLength",
253
+ 256: "ImageWidth",
254
+ 271: "Make",
255
+ 281: "MaxSampleValue",
256
+ 280: "MinSampleValue",
257
+ 272: "Model",
258
+ 254: "NewSubfileType",
259
+ 274: "Orientation",
260
+ 262: "PhotometricInterpretation",
261
+ 284: "PlanarConfiguration",
262
+ 296: "ResolutionUnit",
263
+ 278: "RowsPerStrip",
264
+ 277: "SamplesPerPixel",
265
+ 305: "Software",
266
+ 279: "StripByteCounts",
267
+ 273: "StripOffsets",
268
+ 255: "SubfileType",
269
+ 263: "Threshholding",
270
+ 282: "XResolution",
271
+ 283: "YResolution",
272
+ // TIFF Extended
273
+ 326: "BadFaxLines",
274
+ 327: "CleanFaxData",
275
+ 343: "ClipPath",
276
+ 328: "ConsecutiveBadFaxLines",
277
+ 433: "Decode",
278
+ 434: "DefaultImageColor",
279
+ 269: "DocumentName",
280
+ 336: "DotRange",
281
+ 321: "HalftoneHints",
282
+ 346: "Indexed",
283
+ 347: "JPEGTables",
284
+ 285: "PageName",
285
+ 297: "PageNumber",
286
+ 317: "Predictor",
287
+ 319: "PrimaryChromaticities",
288
+ 532: "ReferenceBlackWhite",
289
+ 339: "SampleFormat",
290
+ 340: "SMinSampleValue",
291
+ 341: "SMaxSampleValue",
292
+ 559: "StripRowCounts",
293
+ 330: "SubIFDs",
294
+ 292: "T4Options",
295
+ 293: "T6Options",
296
+ 325: "TileByteCounts",
297
+ 323: "TileLength",
298
+ 324: "TileOffsets",
299
+ 322: "TileWidth",
300
+ 301: "TransferFunction",
301
+ 318: "WhitePoint",
302
+ 344: "XClipPathUnits",
303
+ 286: "XPosition",
304
+ 529: "YCbCrCoefficients",
305
+ 531: "YCbCrPositioning",
306
+ 530: "YCbCrSubSampling",
307
+ 345: "YClipPathUnits",
308
+ 287: "YPosition",
309
+ // EXIF
310
+ 37378: "ApertureValue",
311
+ 40961: "ColorSpace",
312
+ 36868: "DateTimeDigitized",
313
+ 36867: "DateTimeOriginal",
314
+ 34665: "Exif IFD",
315
+ 36864: "ExifVersion",
316
+ 33434: "ExposureTime",
317
+ 41728: "FileSource",
318
+ 37385: "Flash",
319
+ 40960: "FlashpixVersion",
320
+ 33437: "FNumber",
321
+ 42016: "ImageUniqueID",
322
+ 37384: "LightSource",
323
+ 37500: "MakerNote",
324
+ 37377: "ShutterSpeedValue",
325
+ 37510: "UserComment",
326
+ // IPTC
327
+ 33723: "IPTC",
328
+ // ICC
329
+ 34675: "ICC Profile",
330
+ // XMP
331
+ 700: "XMP",
332
+ // GDAL
333
+ 42112: "GDAL_METADATA",
334
+ 42113: "GDAL_NODATA",
335
+ // Photoshop
336
+ 34377: "Photoshop",
337
+ // GeoTiff
338
+ 33550: "ModelPixelScale",
339
+ 33922: "ModelTiepoint",
340
+ 34264: "ModelTransformation",
341
+ 34735: "GeoKeyDirectory",
342
+ 34736: "GeoDoubleParams",
343
+ 34737: "GeoAsciiParams",
344
+ // LERC
345
+ 50674: "LercParameters"
346
+ }, F = {};
347
+ for (const r in U)
348
+ U.hasOwnProperty(r) && (F[U[r]] = parseInt(r, 10));
349
+ const ue = {
350
+ 256: "SHORT",
351
+ 257: "SHORT",
352
+ 258: "SHORT",
353
+ 259: "SHORT",
354
+ 262: "SHORT",
355
+ 273: "LONG",
356
+ 274: "SHORT",
357
+ 277: "SHORT",
358
+ 278: "LONG",
359
+ 279: "LONG",
360
+ 282: "RATIONAL",
361
+ 283: "RATIONAL",
362
+ 284: "SHORT",
363
+ 286: "SHORT",
364
+ 287: "RATIONAL",
365
+ 296: "SHORT",
366
+ 297: "SHORT",
367
+ 305: "ASCII",
368
+ 306: "ASCII",
369
+ 338: "SHORT",
370
+ 339: "SHORT",
371
+ 513: "LONG",
372
+ 514: "LONG",
373
+ 1024: "SHORT",
374
+ 1025: "SHORT",
375
+ 2048: "SHORT",
376
+ 2049: "ASCII",
377
+ 3072: "SHORT",
378
+ 3073: "ASCII",
379
+ 33550: "DOUBLE",
380
+ 33922: "DOUBLE",
381
+ 34264: "DOUBLE",
382
+ 34665: "LONG",
383
+ 34735: "SHORT",
384
+ 34736: "DOUBLE",
385
+ 34737: "ASCII",
386
+ 42113: "ASCII"
387
+ }, st = [
388
+ F.BitsPerSample,
389
+ F.ExtraSamples,
390
+ F.SampleFormat,
391
+ F.StripByteCounts,
392
+ F.StripOffsets,
393
+ F.StripRowCounts,
394
+ F.TileByteCounts,
395
+ F.TileOffsets,
396
+ F.SubIFDs
397
+ ], X = {
398
+ 1: "BYTE",
399
+ 2: "ASCII",
400
+ 3: "SHORT",
401
+ 4: "LONG",
402
+ 5: "RATIONAL",
403
+ 6: "SBYTE",
404
+ 7: "UNDEFINED",
405
+ 8: "SSHORT",
406
+ 9: "SLONG",
407
+ 10: "SRATIONAL",
408
+ 11: "FLOAT",
409
+ 12: "DOUBLE",
410
+ // IFD offset, suggested by https://owl.phy.queensu.ca/~phil/exiftool/standards.html
411
+ 13: "IFD",
412
+ // introduced by BigTIFF
413
+ 16: "LONG8",
414
+ 17: "SLONG8",
415
+ 18: "IFD8"
416
+ }, m = {};
417
+ for (const r in X)
418
+ X.hasOwnProperty(r) && (m[X[r]] = parseInt(r, 10));
419
+ const P = {
420
+ WhiteIsZero: 0,
421
+ BlackIsZero: 1,
422
+ RGB: 2,
423
+ Palette: 3,
424
+ TransparencyMask: 4,
425
+ CMYK: 5,
426
+ YCbCr: 6,
427
+ CIELab: 8,
428
+ ICCLab: 9
429
+ }, it = {
430
+ Unspecified: 0,
431
+ Assocalpha: 1,
432
+ Unassalpha: 2
433
+ }, nr = {
434
+ Version: 0,
435
+ AddCompression: 1
436
+ }, or = {
437
+ None: 0,
438
+ Deflate: 1,
439
+ Zstandard: 2
440
+ }, N = {
441
+ 1024: "GTModelTypeGeoKey",
442
+ 1025: "GTRasterTypeGeoKey",
443
+ 1026: "GTCitationGeoKey",
444
+ 2048: "GeographicTypeGeoKey",
445
+ 2049: "GeogCitationGeoKey",
446
+ 2050: "GeogGeodeticDatumGeoKey",
447
+ 2051: "GeogPrimeMeridianGeoKey",
448
+ 2052: "GeogLinearUnitsGeoKey",
449
+ 2053: "GeogLinearUnitSizeGeoKey",
450
+ 2054: "GeogAngularUnitsGeoKey",
451
+ 2055: "GeogAngularUnitSizeGeoKey",
452
+ 2056: "GeogEllipsoidGeoKey",
453
+ 2057: "GeogSemiMajorAxisGeoKey",
454
+ 2058: "GeogSemiMinorAxisGeoKey",
455
+ 2059: "GeogInvFlatteningGeoKey",
456
+ 2060: "GeogAzimuthUnitsGeoKey",
457
+ 2061: "GeogPrimeMeridianLongGeoKey",
458
+ 2062: "GeogTOWGS84GeoKey",
459
+ 3072: "ProjectedCSTypeGeoKey",
460
+ 3073: "PCSCitationGeoKey",
461
+ 3074: "ProjectionGeoKey",
462
+ 3075: "ProjCoordTransGeoKey",
463
+ 3076: "ProjLinearUnitsGeoKey",
464
+ 3077: "ProjLinearUnitSizeGeoKey",
465
+ 3078: "ProjStdParallel1GeoKey",
466
+ 3079: "ProjStdParallel2GeoKey",
467
+ 3080: "ProjNatOriginLongGeoKey",
468
+ 3081: "ProjNatOriginLatGeoKey",
469
+ 3082: "ProjFalseEastingGeoKey",
470
+ 3083: "ProjFalseNorthingGeoKey",
471
+ 3084: "ProjFalseOriginLongGeoKey",
472
+ 3085: "ProjFalseOriginLatGeoKey",
473
+ 3086: "ProjFalseOriginEastingGeoKey",
474
+ 3087: "ProjFalseOriginNorthingGeoKey",
475
+ 3088: "ProjCenterLongGeoKey",
476
+ 3089: "ProjCenterLatGeoKey",
477
+ 3090: "ProjCenterEastingGeoKey",
478
+ 3091: "ProjCenterNorthingGeoKey",
479
+ 3092: "ProjScaleAtNatOriginGeoKey",
480
+ 3093: "ProjScaleAtCenterGeoKey",
481
+ 3094: "ProjAzimuthAngleGeoKey",
482
+ 3095: "ProjStraightVertPoleLongGeoKey",
483
+ 3096: "ProjRectifiedGridAngleGeoKey",
484
+ 4096: "VerticalCSTypeGeoKey",
485
+ 4097: "VerticalCitationGeoKey",
486
+ 4098: "VerticalDatumGeoKey",
487
+ 4099: "VerticalUnitsGeoKey"
488
+ }, nt = {};
489
+ for (const r in N)
490
+ N.hasOwnProperty(r) && (nt[N[r]] = parseInt(r, 10));
491
+ const ar = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
492
+ __proto__: null,
493
+ ExtraSamplesValues: it,
494
+ LercAddCompression: or,
495
+ LercParameters: nr,
496
+ arrayFields: st,
497
+ fieldTagNames: U,
498
+ fieldTagTypes: ue,
499
+ fieldTags: F,
500
+ fieldTypeNames: X,
501
+ fieldTypes: m,
502
+ geoKeyNames: N,
503
+ geoKeys: nt,
504
+ photometricInterpretations: P
505
+ }, Symbol.toStringTag, { value: "Module" }));
506
+ function ot(r, e) {
507
+ const { width: t, height: s } = r, i = new Uint8Array(t * s * 3);
508
+ let n;
509
+ for (let a = 0, o = 0; a < r.length; ++a, o += 3)
510
+ n = 256 - r[a] / e * 256, i[o] = n, i[o + 1] = n, i[o + 2] = n;
511
+ return i;
512
+ }
513
+ function at(r, e) {
514
+ const { width: t, height: s } = r, i = new Uint8Array(t * s * 3);
515
+ let n;
516
+ for (let a = 0, o = 0; a < r.length; ++a, o += 3)
517
+ n = r[a] / e * 256, i[o] = n, i[o + 1] = n, i[o + 2] = n;
518
+ return i;
519
+ }
520
+ function ct(r, e) {
521
+ const { width: t, height: s } = r, i = new Uint8Array(t * s * 3), n = e.length / 3, a = e.length / 3 * 2;
522
+ for (let o = 0, c = 0; o < r.length; ++o, c += 3) {
523
+ const l = r[o];
524
+ i[c] = e[l] / 65536 * 256, i[c + 1] = e[l + n] / 65536 * 256, i[c + 2] = e[l + a] / 65536 * 256;
525
+ }
526
+ return i;
527
+ }
528
+ function lt(r) {
529
+ const { width: e, height: t } = r, s = new Uint8Array(e * t * 3);
530
+ for (let i = 0, n = 0; i < r.length; i += 4, n += 3) {
531
+ const a = r[i], o = r[i + 1], c = r[i + 2], l = r[i + 3];
532
+ s[n] = 255 * ((255 - a) / 256) * ((255 - l) / 256), s[n + 1] = 255 * ((255 - o) / 256) * ((255 - l) / 256), s[n + 2] = 255 * ((255 - c) / 256) * ((255 - l) / 256);
533
+ }
534
+ return s;
535
+ }
536
+ function ft(r) {
537
+ const { width: e, height: t } = r, s = new Uint8ClampedArray(e * t * 3);
538
+ for (let i = 0, n = 0; i < r.length; i += 3, n += 3) {
539
+ const a = r[i], o = r[i + 1], c = r[i + 2];
540
+ s[n] = a + 1.402 * (c - 128), s[n + 1] = a - 0.34414 * (o - 128) - 0.71414 * (c - 128), s[n + 2] = a + 1.772 * (o - 128);
541
+ }
542
+ return s;
543
+ }
544
+ const cr = 0.95047, lr = 1, fr = 1.08883;
545
+ function ht(r) {
546
+ const { width: e, height: t } = r, s = new Uint8Array(e * t * 3);
547
+ for (let i = 0, n = 0; i < r.length; i += 3, n += 3) {
548
+ const a = r[i + 0], o = r[i + 1] << 24 >> 24, c = r[i + 2] << 24 >> 24;
549
+ let l = (a + 16) / 116, f = o / 500 + l, h = l - c / 200, u, d, g;
550
+ f = cr * (f * f * f > 8856e-6 ? f * f * f : (f - 16 / 116) / 7.787), l = lr * (l * l * l > 8856e-6 ? l * l * l : (l - 16 / 116) / 7.787), h = fr * (h * h * h > 8856e-6 ? h * h * h : (h - 16 / 116) / 7.787), u = f * 3.2406 + l * -1.5372 + h * -0.4986, d = f * -0.9689 + l * 1.8758 + h * 0.0415, g = f * 0.0557 + l * -0.204 + h * 1.057, u = u > 31308e-7 ? 1.055 * u ** (1 / 2.4) - 0.055 : 12.92 * u, d = d > 31308e-7 ? 1.055 * d ** (1 / 2.4) - 0.055 : 12.92 * d, g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : 12.92 * g, s[n] = Math.max(0, Math.min(1, u)) * 255, s[n + 1] = Math.max(0, Math.min(1, d)) * 255, s[n + 2] = Math.max(0, Math.min(1, g)) * 255;
551
+ }
552
+ return s;
553
+ }
554
+ const hr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
555
+ __proto__: null,
556
+ fromBlackIsZero: at,
557
+ fromCIELab: ht,
558
+ fromCMYK: lt,
559
+ fromPalette: ct,
560
+ fromWhiteIsZero: ot,
561
+ fromYCbCr: ft
562
+ }, Symbol.toStringTag, { value: "Module" })), ut = /* @__PURE__ */ new Map();
563
+ function G(r, e) {
564
+ Array.isArray(r) || (r = [r]), r.forEach((t) => ut.set(t, e));
565
+ }
566
+ async function Fe(r) {
567
+ const e = ut.get(r.Compression);
568
+ if (!e)
569
+ throw new Error(`Unknown compression method identifier: ${r.Compression}`);
570
+ const t = await e();
571
+ return new t(r);
572
+ }
573
+ G([void 0, 1], () => import("./raw-DUslI1gr.js").then((r) => r.default));
574
+ G(5, () => import("./lzw-BZniWIYG.js").then((r) => r.default));
575
+ G(6, () => {
576
+ throw new Error("old style JPEG compression is not supported.");
577
+ });
578
+ G(7, () => import("./jpeg-CF9OGQg_.js").then((r) => r.default));
579
+ G([8, 32946], () => import("./deflate-BA1jZeSX.js").then((r) => r.default));
580
+ G(32773, () => import("./packbits-DWY5O-FG.js").then((r) => r.default));
581
+ G(
582
+ 34887,
583
+ () => import("./lerc-7LlQoT6u.js").then(async (r) => (await r.zstd.init(), r)).then((r) => r.default)
584
+ );
585
+ G(50001, () => import("./webimage-ibSPOLHJ.js").then((r) => r.default));
586
+ function ge(r, e, t, s = 1) {
587
+ return new (Object.getPrototypeOf(r)).constructor(e * t * s);
588
+ }
589
+ function ur(r, e, t, s, i) {
590
+ const n = e / s, a = t / i;
591
+ return r.map((o) => {
592
+ const c = ge(o, s, i);
593
+ for (let l = 0; l < i; ++l) {
594
+ const f = Math.min(Math.round(a * l), t - 1);
595
+ for (let h = 0; h < s; ++h) {
596
+ const u = Math.min(Math.round(n * h), e - 1), d = o[f * e + u];
597
+ c[l * s + h] = d;
598
+ }
599
+ }
600
+ return c;
601
+ });
602
+ }
603
+ function K(r, e, t) {
604
+ return (1 - t) * r + t * e;
605
+ }
606
+ function gr(r, e, t, s, i) {
607
+ const n = e / s, a = t / i;
608
+ return r.map((o) => {
609
+ const c = ge(o, s, i);
610
+ for (let l = 0; l < i; ++l) {
611
+ const f = a * l, h = Math.floor(f), u = Math.min(Math.ceil(f), t - 1);
612
+ for (let d = 0; d < s; ++d) {
613
+ const g = n * d, y = g % 1, p = Math.floor(g), x = Math.min(Math.ceil(g), e - 1), w = o[h * e + p], S = o[h * e + x], I = o[u * e + p], b = o[u * e + x], O = K(
614
+ K(w, S, y),
615
+ K(I, b, y),
616
+ f % 1
617
+ );
618
+ c[l * s + d] = O;
619
+ }
620
+ }
621
+ return c;
622
+ });
623
+ }
624
+ function dr(r, e, t, s, i, n = "nearest") {
625
+ switch (n.toLowerCase()) {
626
+ case "nearest":
627
+ return ur(r, e, t, s, i);
628
+ case "bilinear":
629
+ case "linear":
630
+ return gr(r, e, t, s, i);
631
+ default:
632
+ throw new Error(`Unsupported resampling method: '${n}'`);
633
+ }
634
+ }
635
+ function yr(r, e, t, s, i, n) {
636
+ const a = e / s, o = t / i, c = ge(r, s, i, n);
637
+ for (let l = 0; l < i; ++l) {
638
+ const f = Math.min(Math.round(o * l), t - 1);
639
+ for (let h = 0; h < s; ++h) {
640
+ const u = Math.min(Math.round(a * h), e - 1);
641
+ for (let d = 0; d < n; ++d) {
642
+ const g = r[f * e * n + u * n + d];
643
+ c[l * s * n + h * n + d] = g;
644
+ }
645
+ }
646
+ }
647
+ return c;
648
+ }
649
+ function pr(r, e, t, s, i, n) {
650
+ const a = e / s, o = t / i, c = ge(r, s, i, n);
651
+ for (let l = 0; l < i; ++l) {
652
+ const f = o * l, h = Math.floor(f), u = Math.min(Math.ceil(f), t - 1);
653
+ for (let d = 0; d < s; ++d) {
654
+ const g = a * d, y = g % 1, p = Math.floor(g), x = Math.min(Math.ceil(g), e - 1);
655
+ for (let w = 0; w < n; ++w) {
656
+ const S = r[h * e * n + p * n + w], I = r[h * e * n + x * n + w], b = r[u * e * n + p * n + w], O = r[u * e * n + x * n + w], V = K(
657
+ K(S, I, y),
658
+ K(b, O, y),
659
+ f % 1
660
+ );
661
+ c[l * s * n + d * n + w] = V;
662
+ }
663
+ }
664
+ }
665
+ return c;
666
+ }
667
+ function wr(r, e, t, s, i, n, a = "nearest") {
668
+ switch (a.toLowerCase()) {
669
+ case "nearest":
670
+ return yr(
671
+ r,
672
+ e,
673
+ t,
674
+ s,
675
+ i,
676
+ n
677
+ );
678
+ case "bilinear":
679
+ case "linear":
680
+ return pr(
681
+ r,
682
+ e,
683
+ t,
684
+ s,
685
+ i,
686
+ n
687
+ );
688
+ default:
689
+ throw new Error(`Unsupported resampling method: '${a}'`);
690
+ }
691
+ }
692
+ function mr(r, e, t) {
693
+ let s = 0;
694
+ for (let i = e; i < t; ++i)
695
+ s += r[i];
696
+ return s;
697
+ }
698
+ function Ie(r, e, t) {
699
+ switch (r) {
700
+ case 1:
701
+ if (e <= 8)
702
+ return new Uint8Array(t);
703
+ if (e <= 16)
704
+ return new Uint16Array(t);
705
+ if (e <= 32)
706
+ return new Uint32Array(t);
707
+ break;
708
+ case 2:
709
+ if (e === 8)
710
+ return new Int8Array(t);
711
+ if (e === 16)
712
+ return new Int16Array(t);
713
+ if (e === 32)
714
+ return new Int32Array(t);
715
+ break;
716
+ case 3:
717
+ switch (e) {
718
+ case 16:
719
+ case 32:
720
+ return new Float32Array(t);
721
+ case 64:
722
+ return new Float64Array(t);
723
+ }
724
+ break;
725
+ }
726
+ throw Error("Unsupported data format/bitsPerSample");
727
+ }
728
+ function xr(r, e) {
729
+ return (r === 1 || r === 2) && e <= 32 && e % 8 === 0 ? !1 : !(r === 3 && (e === 16 || e === 32 || e === 64));
730
+ }
731
+ function Sr(r, e, t, s, i, n, a) {
732
+ const o = new DataView(r), c = t === 2 ? a * n : a * n * s, l = t === 2 ? 1 : s, f = Ie(e, i, c), h = parseInt("1".repeat(i), 2);
733
+ if (e === 1) {
734
+ let u;
735
+ t === 1 ? u = s * i : u = i;
736
+ let d = n * u;
737
+ (d & 7) !== 0 && (d = d + 7 & -8);
738
+ for (let g = 0; g < a; ++g) {
739
+ const y = g * d;
740
+ for (let p = 0; p < n; ++p) {
741
+ const x = y + p * l * i;
742
+ for (let w = 0; w < l; ++w) {
743
+ const S = x + w * i, I = (g * n + p) * l + w, b = Math.floor(S / 8), O = S % 8;
744
+ if (O + i <= 8)
745
+ f[I] = o.getUint8(b) >> 8 - i - O & h;
746
+ else if (O + i <= 16)
747
+ f[I] = o.getUint16(b) >> 16 - i - O & h;
748
+ else if (O + i <= 24) {
749
+ const V = o.getUint16(b) << 8 | o.getUint8(b + 2);
750
+ f[I] = V >> 24 - i - O & h;
751
+ } else
752
+ f[I] = o.getUint32(b) >> 32 - i - O & h;
753
+ }
754
+ }
755
+ }
756
+ }
757
+ return f.buffer;
758
+ }
759
+ class ke {
760
+ /**
761
+ * @constructor
762
+ * @param {Object} fileDirectory The parsed file directory
763
+ * @param {Object} geoKeys The parsed geo-keys
764
+ * @param {DataView} dataView The DataView for the underlying file.
765
+ * @param {Boolean} littleEndian Whether the file is encoded in little or big endian
766
+ * @param {Boolean} cache Whether or not decoded tiles shall be cached
767
+ * @param {import('./source/basesource').BaseSource} source The datasource to read from
768
+ */
769
+ constructor(e, t, s, i, n, a) {
770
+ this.fileDirectory = e, this.geoKeys = t, this.dataView = s, this.littleEndian = i, this.tiles = n ? {} : null, this.isTiled = !e.StripOffsets;
771
+ const o = e.PlanarConfiguration;
772
+ if (this.planarConfiguration = typeof o > "u" ? 1 : o, this.planarConfiguration !== 1 && this.planarConfiguration !== 2)
773
+ throw new Error("Invalid planar configuration.");
774
+ this.source = a;
775
+ }
776
+ /**
777
+ * Returns the associated parsed file directory.
778
+ * @returns {Object} the parsed file directory
779
+ */
780
+ getFileDirectory() {
781
+ return this.fileDirectory;
782
+ }
783
+ /**
784
+ * Returns the associated parsed geo keys.
785
+ * @returns {Object} the parsed geo keys
786
+ */
787
+ getGeoKeys() {
788
+ return this.geoKeys;
789
+ }
790
+ /**
791
+ * Returns the width of the image.
792
+ * @returns {Number} the width of the image
793
+ */
794
+ getWidth() {
795
+ return this.fileDirectory.ImageWidth;
796
+ }
797
+ /**
798
+ * Returns the height of the image.
799
+ * @returns {Number} the height of the image
800
+ */
801
+ getHeight() {
802
+ return this.fileDirectory.ImageLength;
803
+ }
804
+ /**
805
+ * Returns the number of samples per pixel.
806
+ * @returns {Number} the number of samples per pixel
807
+ */
808
+ getSamplesPerPixel() {
809
+ return typeof this.fileDirectory.SamplesPerPixel < "u" ? this.fileDirectory.SamplesPerPixel : 1;
810
+ }
811
+ /**
812
+ * Returns the width of each tile.
813
+ * @returns {Number} the width of each tile
814
+ */
815
+ getTileWidth() {
816
+ return this.isTiled ? this.fileDirectory.TileWidth : this.getWidth();
817
+ }
818
+ /**
819
+ * Returns the height of each tile.
820
+ * @returns {Number} the height of each tile
821
+ */
822
+ getTileHeight() {
823
+ return this.isTiled ? this.fileDirectory.TileLength : typeof this.fileDirectory.RowsPerStrip < "u" ? Math.min(this.fileDirectory.RowsPerStrip, this.getHeight()) : this.getHeight();
824
+ }
825
+ getBlockWidth() {
826
+ return this.getTileWidth();
827
+ }
828
+ getBlockHeight(e) {
829
+ return this.isTiled || (e + 1) * this.getTileHeight() <= this.getHeight() ? this.getTileHeight() : this.getHeight() - e * this.getTileHeight();
830
+ }
831
+ /**
832
+ * Calculates the number of bytes for each pixel across all samples. Only full
833
+ * bytes are supported, an exception is thrown when this is not the case.
834
+ * @returns {Number} the bytes per pixel
835
+ */
836
+ getBytesPerPixel() {
837
+ let e = 0;
838
+ for (let t = 0; t < this.fileDirectory.BitsPerSample.length; ++t)
839
+ e += this.getSampleByteSize(t);
840
+ return e;
841
+ }
842
+ getSampleByteSize(e) {
843
+ if (e >= this.fileDirectory.BitsPerSample.length)
844
+ throw new RangeError(`Sample index ${e} is out of range.`);
845
+ return Math.ceil(this.fileDirectory.BitsPerSample[e] / 8);
846
+ }
847
+ getReaderForSample(e) {
848
+ const t = this.fileDirectory.SampleFormat ? this.fileDirectory.SampleFormat[e] : 1, s = this.fileDirectory.BitsPerSample[e];
849
+ switch (t) {
850
+ case 1:
851
+ if (s <= 8)
852
+ return DataView.prototype.getUint8;
853
+ if (s <= 16)
854
+ return DataView.prototype.getUint16;
855
+ if (s <= 32)
856
+ return DataView.prototype.getUint32;
857
+ break;
858
+ case 2:
859
+ if (s <= 8)
860
+ return DataView.prototype.getInt8;
861
+ if (s <= 16)
862
+ return DataView.prototype.getInt16;
863
+ if (s <= 32)
864
+ return DataView.prototype.getInt32;
865
+ break;
866
+ case 3:
867
+ switch (s) {
868
+ case 16:
869
+ return function(i, n) {
870
+ return rt(this, i, n);
871
+ };
872
+ case 32:
873
+ return DataView.prototype.getFloat32;
874
+ case 64:
875
+ return DataView.prototype.getFloat64;
876
+ }
877
+ break;
878
+ }
879
+ throw Error("Unsupported data format/bitsPerSample");
880
+ }
881
+ getSampleFormat(e = 0) {
882
+ return this.fileDirectory.SampleFormat ? this.fileDirectory.SampleFormat[e] : 1;
883
+ }
884
+ getBitsPerSample(e = 0) {
885
+ return this.fileDirectory.BitsPerSample[e];
886
+ }
887
+ getArrayForSample(e, t) {
888
+ const s = this.getSampleFormat(e), i = this.getBitsPerSample(e);
889
+ return Ie(s, i, t);
890
+ }
891
+ /**
892
+ * Returns the decoded strip or tile.
893
+ * @param {Number} x the strip or tile x-offset
894
+ * @param {Number} y the tile y-offset (0 for stripped images)
895
+ * @param {Number} sample the sample to get for separated samples
896
+ * @param {import("./geotiff").Pool|import("./geotiff").BaseDecoder} poolOrDecoder the decoder or decoder pool
897
+ * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
898
+ * to be aborted
899
+ * @returns {Promise.<ArrayBuffer>}
900
+ */
901
+ async getTileOrStrip(e, t, s, i, n) {
902
+ const a = Math.ceil(this.getWidth() / this.getTileWidth()), o = Math.ceil(this.getHeight() / this.getTileHeight());
903
+ let c;
904
+ const { tiles: l } = this;
905
+ this.planarConfiguration === 1 ? c = t * a + e : this.planarConfiguration === 2 && (c = s * a * o + t * a + e);
906
+ let f, h;
907
+ this.isTiled ? (f = this.fileDirectory.TileOffsets[c], h = this.fileDirectory.TileByteCounts[c]) : (f = this.fileDirectory.StripOffsets[c], h = this.fileDirectory.StripByteCounts[c]);
908
+ const u = (await this.source.fetch([{ offset: f, length: h }], n))[0];
909
+ let d;
910
+ return l === null || !l[c] ? (d = (async () => {
911
+ let g = await i.decode(this.fileDirectory, u);
912
+ const y = this.getSampleFormat(), p = this.getBitsPerSample();
913
+ return xr(y, p) && (g = Sr(
914
+ g,
915
+ y,
916
+ this.planarConfiguration,
917
+ this.getSamplesPerPixel(),
918
+ p,
919
+ this.getTileWidth(),
920
+ this.getBlockHeight(t)
921
+ )), g;
922
+ })(), l !== null && (l[c] = d)) : d = l[c], { x: e, y: t, sample: s, data: await d };
923
+ }
924
+ /**
925
+ * Internal read function.
926
+ * @private
927
+ * @param {Array} imageWindow The image window in pixel coordinates
928
+ * @param {Array} samples The selected samples (0-based indices)
929
+ * @param {TypedArray|TypedArray[]} valueArrays The array(s) to write into
930
+ * @param {Boolean} interleave Whether or not to write in an interleaved manner
931
+ * @param {import("./geotiff").Pool|AbstractDecoder} poolOrDecoder the decoder or decoder pool
932
+ * @param {number} width the width of window to be read into
933
+ * @param {number} height the height of window to be read into
934
+ * @param {number} resampleMethod the resampling method to be used when interpolating
935
+ * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
936
+ * to be aborted
937
+ * @returns {Promise<ReadRasterResult>}
938
+ */
939
+ async _readRaster(e, t, s, i, n, a, o, c, l) {
940
+ const f = this.getTileWidth(), h = this.getTileHeight(), u = this.getWidth(), d = this.getHeight(), g = Math.max(Math.floor(e[0] / f), 0), y = Math.min(
941
+ Math.ceil(e[2] / f),
942
+ Math.ceil(u / f)
943
+ ), p = Math.max(Math.floor(e[1] / h), 0), x = Math.min(
944
+ Math.ceil(e[3] / h),
945
+ Math.ceil(d / h)
946
+ ), w = e[2] - e[0];
947
+ let S = this.getBytesPerPixel();
948
+ const I = [], b = [];
949
+ for (let D = 0; D < t.length; ++D)
950
+ this.planarConfiguration === 1 ? I.push(mr(this.fileDirectory.BitsPerSample, 0, t[D]) / 8) : I.push(0), b.push(this.getReaderForSample(t[D]));
951
+ const O = [], { littleEndian: V } = this;
952
+ for (let D = p; D < x; ++D)
953
+ for (let W = g; W < y; ++W) {
954
+ let me;
955
+ this.planarConfiguration === 1 && (me = this.getTileOrStrip(W, D, 0, n, l));
956
+ for (let ee = 0; ee < t.length; ++ee) {
957
+ const te = ee, Be = t[ee];
958
+ this.planarConfiguration === 2 && (S = this.getSampleByteSize(Be), me = this.getTileOrStrip(W, D, Be, n, l));
959
+ const mt = me.then((j) => {
960
+ const xt = j.data, St = new DataView(xt), xe = this.getBlockHeight(j.y), H = j.y * h, re = j.x * f, It = H + xe, bt = (j.x + 1) * f, Tt = b[te], At = Math.min(xe, xe - (It - e[3]), d - H), Dt = Math.min(f, f - (bt - e[2]), u - re);
961
+ for (let Y = Math.max(0, e[1] - H); Y < At; ++Y)
962
+ for (let $ = Math.max(0, e[0] - re); $ < Dt; ++$) {
963
+ const Et = (Y * f + $) * S, Me = Tt.call(
964
+ St,
965
+ Et + I[te],
966
+ V
967
+ );
968
+ let se;
969
+ i ? (se = (Y + H - e[1]) * w * t.length + ($ + re - e[0]) * t.length + te, s[se] = Me) : (se = (Y + H - e[1]) * w + $ + re - e[0], s[te][se] = Me);
970
+ }
971
+ });
972
+ O.push(mt);
973
+ }
974
+ }
975
+ if (await Promise.all(O), a && e[2] - e[0] !== a || o && e[3] - e[1] !== o) {
976
+ let D;
977
+ return i ? D = wr(
978
+ s,
979
+ e[2] - e[0],
980
+ e[3] - e[1],
981
+ a,
982
+ o,
983
+ t.length,
984
+ c
985
+ ) : D = dr(
986
+ s,
987
+ e[2] - e[0],
988
+ e[3] - e[1],
989
+ a,
990
+ o,
991
+ c
992
+ ), D.width = a, D.height = o, D;
993
+ }
994
+ return s.width = a || e[2] - e[0], s.height = o || e[3] - e[1], s;
995
+ }
996
+ /**
997
+ * Reads raster data from the image. This function reads all selected samples
998
+ * into separate arrays of the correct type for that sample or into a single
999
+ * combined array when `interleave` is set. When provided, only a subset
1000
+ * of the raster is read for each sample.
1001
+ *
1002
+ * @param {ReadRasterOptions} [options={}] optional parameters
1003
+ * @returns {Promise<ReadRasterResult>} the decoded arrays as a promise
1004
+ */
1005
+ async readRasters({
1006
+ window: e,
1007
+ samples: t = [],
1008
+ interleave: s,
1009
+ pool: i = null,
1010
+ width: n,
1011
+ height: a,
1012
+ resampleMethod: o,
1013
+ fillValue: c,
1014
+ signal: l
1015
+ } = {}) {
1016
+ const f = e || [0, 0, this.getWidth(), this.getHeight()];
1017
+ if (f[0] > f[2] || f[1] > f[3])
1018
+ throw new Error("Invalid subsets");
1019
+ const h = f[2] - f[0], u = f[3] - f[1], d = h * u, g = this.getSamplesPerPixel();
1020
+ if (!t || !t.length)
1021
+ for (let w = 0; w < g; ++w)
1022
+ t.push(w);
1023
+ else
1024
+ for (let w = 0; w < t.length; ++w)
1025
+ if (t[w] >= g)
1026
+ return Promise.reject(new RangeError(`Invalid sample index '${t[w]}'.`));
1027
+ let y;
1028
+ if (s) {
1029
+ const w = this.fileDirectory.SampleFormat ? Math.max.apply(null, this.fileDirectory.SampleFormat) : 1, S = Math.max.apply(null, this.fileDirectory.BitsPerSample);
1030
+ y = Ie(w, S, d * t.length), c && y.fill(c);
1031
+ } else {
1032
+ y = [];
1033
+ for (let w = 0; w < t.length; ++w) {
1034
+ const S = this.getArrayForSample(t[w], d);
1035
+ Array.isArray(c) && w < c.length ? S.fill(c[w]) : c && !Array.isArray(c) && S.fill(c), y.push(S);
1036
+ }
1037
+ }
1038
+ const p = i || await Fe(this.fileDirectory);
1039
+ return await this._readRaster(
1040
+ f,
1041
+ t,
1042
+ y,
1043
+ s,
1044
+ p,
1045
+ n,
1046
+ a,
1047
+ o,
1048
+ l
1049
+ );
1050
+ }
1051
+ /**
1052
+ * Reads raster data from the image as RGB. The result is always an
1053
+ * interleaved typed array.
1054
+ * Colorspaces other than RGB will be transformed to RGB, color maps expanded.
1055
+ * When no other method is applicable, the first sample is used to produce a
1056
+ * grayscale image.
1057
+ * When provided, only a subset of the raster is read for each sample.
1058
+ *
1059
+ * @param {Object} [options] optional parameters
1060
+ * @param {Array<number>} [options.window] the subset to read data from in pixels.
1061
+ * @param {boolean} [options.interleave=true] whether the data shall be read
1062
+ * in one single array or separate
1063
+ * arrays.
1064
+ * @param {import("./geotiff").Pool} [options.pool=null] The optional decoder pool to use.
1065
+ * @param {number} [options.width] The desired width of the output. When the width is no the
1066
+ * same as the images, resampling will be performed.
1067
+ * @param {number} [options.height] The desired height of the output. When the width is no the
1068
+ * same as the images, resampling will be performed.
1069
+ * @param {string} [options.resampleMethod='nearest'] The desired resampling method.
1070
+ * @param {boolean} [options.enableAlpha=false] Enable reading alpha channel if present.
1071
+ * @param {AbortSignal} [options.signal] An AbortSignal that may be signalled if the request is
1072
+ * to be aborted
1073
+ * @returns {Promise<ReadRasterResult>} the RGB array as a Promise
1074
+ */
1075
+ async readRGB({
1076
+ window: e,
1077
+ interleave: t = !0,
1078
+ pool: s = null,
1079
+ width: i,
1080
+ height: n,
1081
+ resampleMethod: a,
1082
+ enableAlpha: o = !1,
1083
+ signal: c
1084
+ } = {}) {
1085
+ const l = e || [0, 0, this.getWidth(), this.getHeight()];
1086
+ if (l[0] > l[2] || l[1] > l[3])
1087
+ throw new Error("Invalid subsets");
1088
+ const f = this.fileDirectory.PhotometricInterpretation;
1089
+ if (f === P.RGB) {
1090
+ let x = [0, 1, 2];
1091
+ if (this.fileDirectory.ExtraSamples !== it.Unspecified && o) {
1092
+ x = [];
1093
+ for (let w = 0; w < this.fileDirectory.BitsPerSample.length; w += 1)
1094
+ x.push(w);
1095
+ }
1096
+ return this.readRasters({
1097
+ window: e,
1098
+ interleave: t,
1099
+ samples: x,
1100
+ pool: s,
1101
+ width: i,
1102
+ height: n,
1103
+ resampleMethod: a,
1104
+ signal: c
1105
+ });
1106
+ }
1107
+ let h;
1108
+ switch (f) {
1109
+ case P.WhiteIsZero:
1110
+ case P.BlackIsZero:
1111
+ case P.Palette:
1112
+ h = [0];
1113
+ break;
1114
+ case P.CMYK:
1115
+ h = [0, 1, 2, 3];
1116
+ break;
1117
+ case P.YCbCr:
1118
+ case P.CIELab:
1119
+ h = [0, 1, 2];
1120
+ break;
1121
+ default:
1122
+ throw new Error("Invalid or unsupported photometric interpretation.");
1123
+ }
1124
+ const u = {
1125
+ window: l,
1126
+ interleave: !0,
1127
+ samples: h,
1128
+ pool: s,
1129
+ width: i,
1130
+ height: n,
1131
+ resampleMethod: a,
1132
+ signal: c
1133
+ }, { fileDirectory: d } = this, g = await this.readRasters(u), y = 2 ** this.fileDirectory.BitsPerSample[0];
1134
+ let p;
1135
+ switch (f) {
1136
+ case P.WhiteIsZero:
1137
+ p = ot(g, y);
1138
+ break;
1139
+ case P.BlackIsZero:
1140
+ p = at(g, y);
1141
+ break;
1142
+ case P.Palette:
1143
+ p = ct(g, d.ColorMap);
1144
+ break;
1145
+ case P.CMYK:
1146
+ p = lt(g);
1147
+ break;
1148
+ case P.YCbCr:
1149
+ p = ft(g);
1150
+ break;
1151
+ case P.CIELab:
1152
+ p = ht(g);
1153
+ break;
1154
+ default:
1155
+ throw new Error("Unsupported photometric interpretation.");
1156
+ }
1157
+ if (!t) {
1158
+ const x = new Uint8Array(p.length / 3), w = new Uint8Array(p.length / 3), S = new Uint8Array(p.length / 3);
1159
+ for (let I = 0, b = 0; I < p.length; I += 3, ++b)
1160
+ x[b] = p[I], w[b] = p[I + 1], S[b] = p[I + 2];
1161
+ p = [x, w, S];
1162
+ }
1163
+ return p.width = g.width, p.height = g.height, p;
1164
+ }
1165
+ /**
1166
+ * Returns an array of tiepoints.
1167
+ * @returns {Object[]}
1168
+ */
1169
+ getTiePoints() {
1170
+ if (!this.fileDirectory.ModelTiepoint)
1171
+ return [];
1172
+ const e = [];
1173
+ for (let t = 0; t < this.fileDirectory.ModelTiepoint.length; t += 6)
1174
+ e.push({
1175
+ i: this.fileDirectory.ModelTiepoint[t],
1176
+ j: this.fileDirectory.ModelTiepoint[t + 1],
1177
+ k: this.fileDirectory.ModelTiepoint[t + 2],
1178
+ x: this.fileDirectory.ModelTiepoint[t + 3],
1179
+ y: this.fileDirectory.ModelTiepoint[t + 4],
1180
+ z: this.fileDirectory.ModelTiepoint[t + 5]
1181
+ });
1182
+ return e;
1183
+ }
1184
+ /**
1185
+ * Returns the parsed GDAL metadata items.
1186
+ *
1187
+ * If sample is passed to null, dataset-level metadata will be returned.
1188
+ * Otherwise only metadata specific to the provided sample will be returned.
1189
+ *
1190
+ * @param {number} [sample=null] The sample index.
1191
+ * @returns {Object}
1192
+ */
1193
+ getGDALMetadata(e = null) {
1194
+ const t = {};
1195
+ if (!this.fileDirectory.GDAL_METADATA)
1196
+ return null;
1197
+ const s = this.fileDirectory.GDAL_METADATA;
1198
+ let i = ir(s, "Item");
1199
+ e === null ? i = i.filter((n) => Se(n, "sample") === void 0) : i = i.filter((n) => Number(Se(n, "sample")) === e);
1200
+ for (let n = 0; n < i.length; ++n) {
1201
+ const a = i[n];
1202
+ t[Se(a, "name")] = a.inner;
1203
+ }
1204
+ return t;
1205
+ }
1206
+ /**
1207
+ * Returns the GDAL nodata value
1208
+ * @returns {number|null}
1209
+ */
1210
+ getGDALNoData() {
1211
+ if (!this.fileDirectory.GDAL_NODATA)
1212
+ return null;
1213
+ const e = this.fileDirectory.GDAL_NODATA;
1214
+ return Number(e.substring(0, e.length - 1));
1215
+ }
1216
+ /**
1217
+ * Returns the image origin as a XYZ-vector. When the image has no affine
1218
+ * transformation, then an exception is thrown.
1219
+ * @returns {Array<number>} The origin as a vector
1220
+ */
1221
+ getOrigin() {
1222
+ const e = this.fileDirectory.ModelTiepoint, t = this.fileDirectory.ModelTransformation;
1223
+ if (e && e.length === 6)
1224
+ return [
1225
+ e[3],
1226
+ e[4],
1227
+ e[5]
1228
+ ];
1229
+ if (t)
1230
+ return [
1231
+ t[3],
1232
+ t[7],
1233
+ t[11]
1234
+ ];
1235
+ throw new Error("The image does not have an affine transformation.");
1236
+ }
1237
+ /**
1238
+ * Returns the image resolution as a XYZ-vector. When the image has no affine
1239
+ * transformation, then an exception is thrown.
1240
+ * @param {GeoTIFFImage} [referenceImage=null] A reference image to calculate the resolution from
1241
+ * in cases when the current image does not have the
1242
+ * required tags on its own.
1243
+ * @returns {Array<number>} The resolution as a vector
1244
+ */
1245
+ getResolution(e = null) {
1246
+ const t = this.fileDirectory.ModelPixelScale, s = this.fileDirectory.ModelTransformation;
1247
+ if (t)
1248
+ return [
1249
+ t[0],
1250
+ -t[1],
1251
+ t[2]
1252
+ ];
1253
+ if (s)
1254
+ return s[1] === 0 && s[4] === 0 ? [
1255
+ s[0],
1256
+ -s[5],
1257
+ s[10]
1258
+ ] : [
1259
+ Math.sqrt(s[0] * s[0] + s[4] * s[4]),
1260
+ -Math.sqrt(s[1] * s[1] + s[5] * s[5]),
1261
+ s[10]
1262
+ ];
1263
+ if (e) {
1264
+ const [i, n, a] = e.getResolution();
1265
+ return [
1266
+ i * e.getWidth() / this.getWidth(),
1267
+ n * e.getHeight() / this.getHeight(),
1268
+ a * e.getWidth() / this.getWidth()
1269
+ ];
1270
+ }
1271
+ throw new Error("The image does not have an affine transformation.");
1272
+ }
1273
+ /**
1274
+ * Returns whether or not the pixels of the image depict an area (or point).
1275
+ * @returns {Boolean} Whether the pixels are a point
1276
+ */
1277
+ pixelIsArea() {
1278
+ return this.geoKeys.GTRasterTypeGeoKey === 1;
1279
+ }
1280
+ /**
1281
+ * Returns the image bounding box as an array of 4 values: min-x, min-y,
1282
+ * max-x and max-y. When the image has no affine transformation, then an
1283
+ * exception is thrown.
1284
+ * @param {boolean} [tilegrid=false] If true return extent for a tilegrid
1285
+ * without adjustment for ModelTransformation.
1286
+ * @returns {Array<number>} The bounding box
1287
+ */
1288
+ getBoundingBox(e = !1) {
1289
+ const t = this.getHeight(), s = this.getWidth();
1290
+ if (this.fileDirectory.ModelTransformation && !e) {
1291
+ const [i, n, a, o, c, l, f, h] = this.fileDirectory.ModelTransformation, d = [
1292
+ [0, 0],
1293
+ [0, t],
1294
+ [s, 0],
1295
+ [s, t]
1296
+ ].map(([p, x]) => [
1297
+ o + i * p + n * x,
1298
+ h + c * p + l * x
1299
+ ]), g = d.map((p) => p[0]), y = d.map((p) => p[1]);
1300
+ return [
1301
+ Math.min(...g),
1302
+ Math.min(...y),
1303
+ Math.max(...g),
1304
+ Math.max(...y)
1305
+ ];
1306
+ } else {
1307
+ const i = this.getOrigin(), n = this.getResolution(), a = i[0], o = i[1], c = a + n[0] * s, l = o + n[1] * t;
1308
+ return [
1309
+ Math.min(a, c),
1310
+ Math.min(o, l),
1311
+ Math.max(a, c),
1312
+ Math.max(o, l)
1313
+ ];
1314
+ }
1315
+ }
1316
+ }
1317
+ class Ir {
1318
+ constructor(e) {
1319
+ this._dataView = new DataView(e);
1320
+ }
1321
+ get buffer() {
1322
+ return this._dataView.buffer;
1323
+ }
1324
+ getUint64(e, t) {
1325
+ const s = this.getUint32(e, t), i = this.getUint32(e + 4, t);
1326
+ let n;
1327
+ if (t) {
1328
+ if (n = s + 2 ** 32 * i, !Number.isSafeInteger(n))
1329
+ throw new Error(
1330
+ `${n} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
1331
+ );
1332
+ return n;
1333
+ }
1334
+ if (n = 2 ** 32 * s + i, !Number.isSafeInteger(n))
1335
+ throw new Error(
1336
+ `${n} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
1337
+ );
1338
+ return n;
1339
+ }
1340
+ // adapted from https://stackoverflow.com/a/55338384/8060591
1341
+ getInt64(e, t) {
1342
+ let s = 0;
1343
+ const i = (this._dataView.getUint8(e + (t ? 7 : 0)) & 128) > 0;
1344
+ let n = !0;
1345
+ for (let a = 0; a < 8; a++) {
1346
+ let o = this._dataView.getUint8(e + (t ? a : 7 - a));
1347
+ i && (n ? o !== 0 && (o = ~(o - 1) & 255, n = !1) : o = ~o & 255), s += o * 256 ** a;
1348
+ }
1349
+ return i && (s = -s), s;
1350
+ }
1351
+ getUint8(e, t) {
1352
+ return this._dataView.getUint8(e, t);
1353
+ }
1354
+ getInt8(e, t) {
1355
+ return this._dataView.getInt8(e, t);
1356
+ }
1357
+ getUint16(e, t) {
1358
+ return this._dataView.getUint16(e, t);
1359
+ }
1360
+ getInt16(e, t) {
1361
+ return this._dataView.getInt16(e, t);
1362
+ }
1363
+ getUint32(e, t) {
1364
+ return this._dataView.getUint32(e, t);
1365
+ }
1366
+ getInt32(e, t) {
1367
+ return this._dataView.getInt32(e, t);
1368
+ }
1369
+ getFloat16(e, t) {
1370
+ return rt(this._dataView, e, t);
1371
+ }
1372
+ getFloat32(e, t) {
1373
+ return this._dataView.getFloat32(e, t);
1374
+ }
1375
+ getFloat64(e, t) {
1376
+ return this._dataView.getFloat64(e, t);
1377
+ }
1378
+ }
1379
+ class br {
1380
+ constructor(e, t, s, i) {
1381
+ this._dataView = new DataView(e), this._sliceOffset = t, this._littleEndian = s, this._bigTiff = i;
1382
+ }
1383
+ get sliceOffset() {
1384
+ return this._sliceOffset;
1385
+ }
1386
+ get sliceTop() {
1387
+ return this._sliceOffset + this.buffer.byteLength;
1388
+ }
1389
+ get littleEndian() {
1390
+ return this._littleEndian;
1391
+ }
1392
+ get bigTiff() {
1393
+ return this._bigTiff;
1394
+ }
1395
+ get buffer() {
1396
+ return this._dataView.buffer;
1397
+ }
1398
+ covers(e, t) {
1399
+ return this.sliceOffset <= e && this.sliceTop >= e + t;
1400
+ }
1401
+ readUint8(e) {
1402
+ return this._dataView.getUint8(
1403
+ e - this._sliceOffset,
1404
+ this._littleEndian
1405
+ );
1406
+ }
1407
+ readInt8(e) {
1408
+ return this._dataView.getInt8(
1409
+ e - this._sliceOffset,
1410
+ this._littleEndian
1411
+ );
1412
+ }
1413
+ readUint16(e) {
1414
+ return this._dataView.getUint16(
1415
+ e - this._sliceOffset,
1416
+ this._littleEndian
1417
+ );
1418
+ }
1419
+ readInt16(e) {
1420
+ return this._dataView.getInt16(
1421
+ e - this._sliceOffset,
1422
+ this._littleEndian
1423
+ );
1424
+ }
1425
+ readUint32(e) {
1426
+ return this._dataView.getUint32(
1427
+ e - this._sliceOffset,
1428
+ this._littleEndian
1429
+ );
1430
+ }
1431
+ readInt32(e) {
1432
+ return this._dataView.getInt32(
1433
+ e - this._sliceOffset,
1434
+ this._littleEndian
1435
+ );
1436
+ }
1437
+ readFloat32(e) {
1438
+ return this._dataView.getFloat32(
1439
+ e - this._sliceOffset,
1440
+ this._littleEndian
1441
+ );
1442
+ }
1443
+ readFloat64(e) {
1444
+ return this._dataView.getFloat64(
1445
+ e - this._sliceOffset,
1446
+ this._littleEndian
1447
+ );
1448
+ }
1449
+ readUint64(e) {
1450
+ const t = this.readUint32(e), s = this.readUint32(e + 4);
1451
+ let i;
1452
+ if (this._littleEndian) {
1453
+ if (i = t + 2 ** 32 * s, !Number.isSafeInteger(i))
1454
+ throw new Error(
1455
+ `${i} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
1456
+ );
1457
+ return i;
1458
+ }
1459
+ if (i = 2 ** 32 * t + s, !Number.isSafeInteger(i))
1460
+ throw new Error(
1461
+ `${i} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`
1462
+ );
1463
+ return i;
1464
+ }
1465
+ // adapted from https://stackoverflow.com/a/55338384/8060591
1466
+ readInt64(e) {
1467
+ let t = 0;
1468
+ const s = (this._dataView.getUint8(e + (this._littleEndian ? 7 : 0)) & 128) > 0;
1469
+ let i = !0;
1470
+ for (let n = 0; n < 8; n++) {
1471
+ let a = this._dataView.getUint8(
1472
+ e + (this._littleEndian ? n : 7 - n)
1473
+ );
1474
+ s && (i ? a !== 0 && (a = ~(a - 1) & 255, i = !1) : a = ~a & 255), t += a * 256 ** n;
1475
+ }
1476
+ return s && (t = -t), t;
1477
+ }
1478
+ readOffset(e) {
1479
+ return this._bigTiff ? this.readUint64(e) : this.readUint32(e);
1480
+ }
1481
+ }
1482
+ const Tr = typeof navigator < "u" && navigator.hardwareConcurrency || 2;
1483
+ class Ar {
1484
+ /**
1485
+ * @constructor
1486
+ * @param {Number} [size] The size of the pool. Defaults to the number of CPUs
1487
+ * available. When this parameter is `null` or 0, then the
1488
+ * decoding will be done in the main thread.
1489
+ * @param {function(): Worker} [createWorker] A function that creates the decoder worker.
1490
+ * Defaults to a worker with all decoders that ship with geotiff.js. The `createWorker()`
1491
+ * function is expected to return a `Worker` compatible with Web Workers. For code that
1492
+ * runs in Node, [web-worker](https://www.npmjs.com/package/web-worker) is a good choice.
1493
+ *
1494
+ * A worker that uses a custom lzw decoder would look like this `my-custom-worker.js` file:
1495
+ * ```js
1496
+ * import { addDecoder, getDecoder } from 'geotiff';
1497
+ * addDecoder(5, () => import ('./my-custom-lzw').then((m) => m.default));
1498
+ * self.addEventListener('message', async (e) => {
1499
+ * const { id, fileDirectory, buffer } = e.data;
1500
+ * const decoder = await getDecoder(fileDirectory);
1501
+ * const decoded = await decoder.decode(fileDirectory, buffer);
1502
+ * self.postMessage({ decoded, id }, [decoded]);
1503
+ * });
1504
+ * ```
1505
+ * The way the above code is built into a worker by the `createWorker()` function
1506
+ * depends on the used bundler. For most bundlers, something like this will work:
1507
+ * ```js
1508
+ * function createWorker() {
1509
+ * return new Worker(new URL('./my-custom-worker.js', import.meta.url));
1510
+ * }
1511
+ * ```
1512
+ */
1513
+ constructor(e = Tr, t) {
1514
+ this.workers = null, this._awaitingDecoder = null, this.size = e, this.messageId = 0, e && (this._awaitingDecoder = t ? Promise.resolve(t) : new Promise((s) => {
1515
+ import("./decoder-CLokFc0V.js").then((i) => {
1516
+ s(i.create);
1517
+ });
1518
+ }), this._awaitingDecoder.then((s) => {
1519
+ this._awaitingDecoder = null, this.workers = [];
1520
+ for (let i = 0; i < e; i++)
1521
+ this.workers.push({ worker: s(), idle: !0 });
1522
+ }));
1523
+ }
1524
+ /**
1525
+ * Decode the given block of bytes with the set compression method.
1526
+ * @param {ArrayBuffer} buffer the array buffer of bytes to decode.
1527
+ * @returns {Promise<ArrayBuffer>} the decoded result as a `Promise`
1528
+ */
1529
+ async decode(e, t) {
1530
+ return this._awaitingDecoder && await this._awaitingDecoder, this.size === 0 ? Fe(e).then((s) => s.decode(e, t)) : new Promise((s) => {
1531
+ const i = this.workers.find((o) => o.idle) || this.workers[Math.floor(Math.random() * this.size)];
1532
+ i.idle = !1;
1533
+ const n = this.messageId++, a = (o) => {
1534
+ o.data.id === n && (i.idle = !0, s(o.data.decoded), i.worker.removeEventListener("message", a));
1535
+ };
1536
+ i.worker.addEventListener("message", a), i.worker.postMessage({ fileDirectory: e, buffer: t, id: n }, [t]);
1537
+ });
1538
+ }
1539
+ destroy() {
1540
+ this.workers && (this.workers.forEach((e) => {
1541
+ e.worker.terminate();
1542
+ }), this.workers = null);
1543
+ }
1544
+ }
1545
+ const ze = `\r
1546
+ \r
1547
+ `;
1548
+ function gt(r) {
1549
+ if (typeof Object.fromEntries < "u")
1550
+ return Object.fromEntries(r);
1551
+ const e = {};
1552
+ for (const [t, s] of r)
1553
+ e[t.toLowerCase()] = s;
1554
+ return e;
1555
+ }
1556
+ function Dr(r) {
1557
+ const e = r.split(`\r
1558
+ `).map((t) => {
1559
+ const s = t.split(":").map((i) => i.trim());
1560
+ return s[0] = s[0].toLowerCase(), s;
1561
+ });
1562
+ return gt(e);
1563
+ }
1564
+ function Er(r) {
1565
+ const [e, ...t] = r.split(";").map((i) => i.trim()), s = t.map((i) => i.split("="));
1566
+ return { type: e, params: gt(s) };
1567
+ }
1568
+ function be(r) {
1569
+ let e, t, s;
1570
+ return r && ([, e, t, s] = r.match(/bytes (\d+)-(\d+)\/(\d+)/), e = parseInt(e, 10), t = parseInt(t, 10), s = parseInt(s, 10)), { start: e, end: t, total: s };
1571
+ }
1572
+ function Or(r, e) {
1573
+ let t = null;
1574
+ const s = new TextDecoder("ascii"), i = [], n = `--${e}`, a = `${n}--`;
1575
+ for (let o = 0; o < 10; ++o)
1576
+ s.decode(
1577
+ new Uint8Array(r, o, n.length)
1578
+ ) === n && (t = o);
1579
+ if (t === null)
1580
+ throw new Error("Could not find initial boundary");
1581
+ for (; t < r.byteLength; ) {
1582
+ const o = s.decode(
1583
+ new Uint8Array(
1584
+ r,
1585
+ t,
1586
+ Math.min(n.length + 1024, r.byteLength - t)
1587
+ )
1588
+ );
1589
+ if (o.length === 0 || o.startsWith(a))
1590
+ break;
1591
+ if (!o.startsWith(n))
1592
+ throw new Error("Part does not start with boundary");
1593
+ const c = o.substr(n.length + 2);
1594
+ if (c.length === 0)
1595
+ break;
1596
+ const l = c.indexOf(ze), f = Dr(c.substr(0, l)), { start: h, end: u, total: d } = be(f["content-range"]), g = t + n.length + l + ze.length, y = parseInt(u, 10) + 1 - parseInt(h, 10);
1597
+ i.push({
1598
+ headers: f,
1599
+ data: r.slice(g, g + y),
1600
+ offset: h,
1601
+ length: y,
1602
+ fileSize: d
1603
+ }), t = g + y + 4;
1604
+ }
1605
+ return i;
1606
+ }
1607
+ class Q {
1608
+ /**
1609
+ *
1610
+ * @param {Slice[]} slices
1611
+ * @returns {ArrayBuffer[]}
1612
+ */
1613
+ async fetch(e, t = void 0) {
1614
+ return Promise.all(
1615
+ e.map((s) => this.fetchSlice(s, t))
1616
+ );
1617
+ }
1618
+ /**
1619
+ *
1620
+ * @param {Slice} slice
1621
+ * @returns {ArrayBuffer}
1622
+ */
1623
+ async fetchSlice(e) {
1624
+ throw new Error(`fetching of slice ${e} not possible, not implemented`);
1625
+ }
1626
+ /**
1627
+ * Returns the filesize if already determined and null otherwise
1628
+ */
1629
+ get fileSize() {
1630
+ return null;
1631
+ }
1632
+ async close() {
1633
+ }
1634
+ }
1635
+ class Pr extends Map {
1636
+ constructor(e = {}) {
1637
+ if (super(), !(e.maxSize && e.maxSize > 0))
1638
+ throw new TypeError("`maxSize` must be a number greater than 0");
1639
+ if (typeof e.maxAge == "number" && e.maxAge === 0)
1640
+ throw new TypeError("`maxAge` must be a number greater than 0");
1641
+ this.maxSize = e.maxSize, this.maxAge = e.maxAge || Number.POSITIVE_INFINITY, this.onEviction = e.onEviction, this.cache = /* @__PURE__ */ new Map(), this.oldCache = /* @__PURE__ */ new Map(), this._size = 0;
1642
+ }
1643
+ // TODO: Use private class methods when targeting Node.js 16.
1644
+ _emitEvictions(e) {
1645
+ if (typeof this.onEviction == "function")
1646
+ for (const [t, s] of e)
1647
+ this.onEviction(t, s.value);
1648
+ }
1649
+ _deleteIfExpired(e, t) {
1650
+ return typeof t.expiry == "number" && t.expiry <= Date.now() ? (typeof this.onEviction == "function" && this.onEviction(e, t.value), this.delete(e)) : !1;
1651
+ }
1652
+ _getOrDeleteIfExpired(e, t) {
1653
+ if (this._deleteIfExpired(e, t) === !1)
1654
+ return t.value;
1655
+ }
1656
+ _getItemValue(e, t) {
1657
+ return t.expiry ? this._getOrDeleteIfExpired(e, t) : t.value;
1658
+ }
1659
+ _peek(e, t) {
1660
+ const s = t.get(e);
1661
+ return this._getItemValue(e, s);
1662
+ }
1663
+ _set(e, t) {
1664
+ this.cache.set(e, t), this._size++, this._size >= this.maxSize && (this._size = 0, this._emitEvictions(this.oldCache), this.oldCache = this.cache, this.cache = /* @__PURE__ */ new Map());
1665
+ }
1666
+ _moveToRecent(e, t) {
1667
+ this.oldCache.delete(e), this._set(e, t);
1668
+ }
1669
+ *_entriesAscending() {
1670
+ for (const e of this.oldCache) {
1671
+ const [t, s] = e;
1672
+ this.cache.has(t) || this._deleteIfExpired(t, s) === !1 && (yield e);
1673
+ }
1674
+ for (const e of this.cache) {
1675
+ const [t, s] = e;
1676
+ this._deleteIfExpired(t, s) === !1 && (yield e);
1677
+ }
1678
+ }
1679
+ get(e) {
1680
+ if (this.cache.has(e)) {
1681
+ const t = this.cache.get(e);
1682
+ return this._getItemValue(e, t);
1683
+ }
1684
+ if (this.oldCache.has(e)) {
1685
+ const t = this.oldCache.get(e);
1686
+ if (this._deleteIfExpired(e, t) === !1)
1687
+ return this._moveToRecent(e, t), t.value;
1688
+ }
1689
+ }
1690
+ set(e, t, { maxAge: s = this.maxAge } = {}) {
1691
+ const i = typeof s == "number" && s !== Number.POSITIVE_INFINITY ? Date.now() + s : void 0;
1692
+ return this.cache.has(e) ? this.cache.set(e, {
1693
+ value: t,
1694
+ expiry: i
1695
+ }) : this._set(e, { value: t, expiry: i }), this;
1696
+ }
1697
+ has(e) {
1698
+ return this.cache.has(e) ? !this._deleteIfExpired(e, this.cache.get(e)) : this.oldCache.has(e) ? !this._deleteIfExpired(e, this.oldCache.get(e)) : !1;
1699
+ }
1700
+ peek(e) {
1701
+ if (this.cache.has(e))
1702
+ return this._peek(e, this.cache);
1703
+ if (this.oldCache.has(e))
1704
+ return this._peek(e, this.oldCache);
1705
+ }
1706
+ delete(e) {
1707
+ const t = this.cache.delete(e);
1708
+ return t && this._size--, this.oldCache.delete(e) || t;
1709
+ }
1710
+ clear() {
1711
+ this.cache.clear(), this.oldCache.clear(), this._size = 0;
1712
+ }
1713
+ resize(e) {
1714
+ if (!(e && e > 0))
1715
+ throw new TypeError("`maxSize` must be a number greater than 0");
1716
+ const t = [...this._entriesAscending()], s = t.length - e;
1717
+ s < 0 ? (this.cache = new Map(t), this.oldCache = /* @__PURE__ */ new Map(), this._size = t.length) : (s > 0 && this._emitEvictions(t.slice(0, s)), this.oldCache = new Map(t.slice(s)), this.cache = /* @__PURE__ */ new Map(), this._size = 0), this.maxSize = e;
1718
+ }
1719
+ *keys() {
1720
+ for (const [e] of this)
1721
+ yield e;
1722
+ }
1723
+ *values() {
1724
+ for (const [, e] of this)
1725
+ yield e;
1726
+ }
1727
+ *[Symbol.iterator]() {
1728
+ for (const e of this.cache) {
1729
+ const [t, s] = e;
1730
+ this._deleteIfExpired(t, s) === !1 && (yield [t, s.value]);
1731
+ }
1732
+ for (const e of this.oldCache) {
1733
+ const [t, s] = e;
1734
+ this.cache.has(t) || this._deleteIfExpired(t, s) === !1 && (yield [t, s.value]);
1735
+ }
1736
+ }
1737
+ *entriesDescending() {
1738
+ let e = [...this.cache];
1739
+ for (let t = e.length - 1; t >= 0; --t) {
1740
+ const s = e[t], [i, n] = s;
1741
+ this._deleteIfExpired(i, n) === !1 && (yield [i, n.value]);
1742
+ }
1743
+ e = [...this.oldCache];
1744
+ for (let t = e.length - 1; t >= 0; --t) {
1745
+ const s = e[t], [i, n] = s;
1746
+ this.cache.has(i) || this._deleteIfExpired(i, n) === !1 && (yield [i, n.value]);
1747
+ }
1748
+ }
1749
+ *entriesAscending() {
1750
+ for (const [e, t] of this._entriesAscending())
1751
+ yield [e, t.value];
1752
+ }
1753
+ get size() {
1754
+ if (!this._size)
1755
+ return this.oldCache.size;
1756
+ let e = 0;
1757
+ for (const t of this.oldCache.keys())
1758
+ this.cache.has(t) || e++;
1759
+ return Math.min(this._size + e, this.maxSize);
1760
+ }
1761
+ entries() {
1762
+ return this.entriesAscending();
1763
+ }
1764
+ forEach(e, t = this) {
1765
+ for (const [s, i] of this.entriesAscending())
1766
+ e.call(t, i, s, this);
1767
+ }
1768
+ get [Symbol.toStringTag]() {
1769
+ return JSON.stringify([...this.entriesAscending()]);
1770
+ }
1771
+ }
1772
+ function dt(r, e) {
1773
+ for (const t in e)
1774
+ e.hasOwnProperty(t) && (r[t] = e[t]);
1775
+ }
1776
+ function yt(r, e) {
1777
+ return r.length < e.length ? !1 : r.substr(r.length - e.length) === e;
1778
+ }
1779
+ function Cr(r, e) {
1780
+ const { length: t } = r;
1781
+ for (let s = 0; s < t; s++)
1782
+ e(r[s], s);
1783
+ }
1784
+ function Re(r) {
1785
+ const e = {};
1786
+ for (const t in r)
1787
+ if (r.hasOwnProperty(t)) {
1788
+ const s = r[t];
1789
+ e[s] = t;
1790
+ }
1791
+ return e;
1792
+ }
1793
+ function C(r, e) {
1794
+ const t = [];
1795
+ for (let s = 0; s < r; s++)
1796
+ t.push(e(s));
1797
+ return t;
1798
+ }
1799
+ async function Fr(r) {
1800
+ return new Promise((e) => setTimeout(e, r));
1801
+ }
1802
+ function kr(r, e) {
1803
+ const t = Array.isArray(r) ? r : Array.from(r), s = Array.isArray(e) ? e : Array.from(e);
1804
+ return t.map((i, n) => [i, s[n]]);
1805
+ }
1806
+ class _ extends Error {
1807
+ constructor(e) {
1808
+ super(e), Error.captureStackTrace && Error.captureStackTrace(this, _), this.name = "AbortError";
1809
+ }
1810
+ }
1811
+ class Rr extends Error {
1812
+ constructor(e, t) {
1813
+ super(t), this.errors = e, this.message = t, this.name = "AggregateError";
1814
+ }
1815
+ }
1816
+ const Br = Rr;
1817
+ class Mr {
1818
+ /**
1819
+ *
1820
+ * @param {number} offset
1821
+ * @param {number} length
1822
+ * @param {ArrayBuffer} [data]
1823
+ */
1824
+ constructor(e, t, s = null) {
1825
+ this.offset = e, this.length = t, this.data = s;
1826
+ }
1827
+ /**
1828
+ * @returns {number} the top byte border
1829
+ */
1830
+ get top() {
1831
+ return this.offset + this.length;
1832
+ }
1833
+ }
1834
+ class qe {
1835
+ /**
1836
+ *
1837
+ * @param {number} offset
1838
+ * @param {number} length
1839
+ * @param {number[]} blockIds
1840
+ */
1841
+ constructor(e, t, s) {
1842
+ this.offset = e, this.length = t, this.blockIds = s;
1843
+ }
1844
+ }
1845
+ class Gr extends Q {
1846
+ /**
1847
+ *
1848
+ * @param {BaseSource} source The underlying source that shall be blocked and cached
1849
+ * @param {object} options
1850
+ * @param {number} [options.blockSize]
1851
+ * @param {number} [options.cacheSize]
1852
+ */
1853
+ constructor(e, { blockSize: t = 65536, cacheSize: s = 100 } = {}) {
1854
+ super(), this.source = e, this.blockSize = t, this.blockCache = new Pr({
1855
+ maxSize: s,
1856
+ onEviction: (i, n) => {
1857
+ this.evictedBlocks.set(i, n);
1858
+ }
1859
+ }), this.evictedBlocks = /* @__PURE__ */ new Map(), this.blockRequests = /* @__PURE__ */ new Map(), this.blockIdsToFetch = /* @__PURE__ */ new Set(), this.abortedBlockIds = /* @__PURE__ */ new Set();
1860
+ }
1861
+ get fileSize() {
1862
+ return this.source.fileSize;
1863
+ }
1864
+ /**
1865
+ *
1866
+ * @param {import("./basesource").Slice[]} slices
1867
+ */
1868
+ async fetch(e, t) {
1869
+ const s = [], i = [], n = [];
1870
+ this.evictedBlocks.clear();
1871
+ for (const { offset: u, length: d } of e) {
1872
+ let g = u + d;
1873
+ const { fileSize: y } = this;
1874
+ y !== null && (g = Math.min(g, y));
1875
+ const p = Math.floor(u / this.blockSize) * this.blockSize;
1876
+ for (let x = p; x < g; x += this.blockSize) {
1877
+ const w = Math.floor(x / this.blockSize);
1878
+ !this.blockCache.has(w) && !this.blockRequests.has(w) && (this.blockIdsToFetch.add(w), i.push(w)), this.blockRequests.has(w) && s.push(this.blockRequests.get(w)), n.push(w);
1879
+ }
1880
+ }
1881
+ await Fr(), this.fetchBlocks(t);
1882
+ const a = [];
1883
+ for (const u of i)
1884
+ this.blockRequests.has(u) && a.push(this.blockRequests.get(u));
1885
+ await Promise.allSettled(s), await Promise.allSettled(a);
1886
+ const o = [], c = n.filter((u) => this.abortedBlockIds.has(u) || !this.blockCache.has(u));
1887
+ if (c.forEach((u) => this.blockIdsToFetch.add(u)), c.length > 0 && t && !t.aborted) {
1888
+ this.fetchBlocks(null);
1889
+ for (const u of c) {
1890
+ const d = this.blockRequests.get(u);
1891
+ if (!d)
1892
+ throw new Error(`Block ${u} is not in the block requests`);
1893
+ o.push(d);
1894
+ }
1895
+ await Promise.allSettled(o);
1896
+ }
1897
+ if (t && t.aborted)
1898
+ throw new _("Request was aborted");
1899
+ const l = n.map((u) => this.blockCache.get(u) || this.evictedBlocks.get(u)), f = l.filter((u) => !u);
1900
+ if (f.length)
1901
+ throw new Br(f, "Request failed");
1902
+ const h = new Map(kr(n, l));
1903
+ return this.readSliceData(e, h);
1904
+ }
1905
+ /**
1906
+ *
1907
+ * @param {AbortSignal} signal
1908
+ */
1909
+ fetchBlocks(e) {
1910
+ if (this.blockIdsToFetch.size > 0) {
1911
+ const t = this.groupBlocks(this.blockIdsToFetch), s = this.source.fetch(t, e);
1912
+ for (let i = 0; i < t.length; ++i) {
1913
+ const n = t[i];
1914
+ for (const a of n.blockIds)
1915
+ this.blockRequests.set(a, (async () => {
1916
+ try {
1917
+ const o = (await s)[i], c = a * this.blockSize, l = c - o.offset, f = Math.min(l + this.blockSize, o.data.byteLength), h = o.data.slice(l, f), u = new Mr(
1918
+ c,
1919
+ h.byteLength,
1920
+ h,
1921
+ a
1922
+ );
1923
+ this.blockCache.set(a, u), this.abortedBlockIds.delete(a);
1924
+ } catch (o) {
1925
+ if (o.name === "AbortError")
1926
+ o.signal = e, this.blockCache.delete(a), this.abortedBlockIds.add(a);
1927
+ else
1928
+ throw o;
1929
+ } finally {
1930
+ this.blockRequests.delete(a);
1931
+ }
1932
+ })());
1933
+ }
1934
+ this.blockIdsToFetch.clear();
1935
+ }
1936
+ }
1937
+ /**
1938
+ *
1939
+ * @param {Set} blockIds
1940
+ * @returns {BlockGroup[]}
1941
+ */
1942
+ groupBlocks(e) {
1943
+ const t = Array.from(e).sort((a, o) => a - o);
1944
+ if (t.length === 0)
1945
+ return [];
1946
+ let s = [], i = null;
1947
+ const n = [];
1948
+ for (const a of t)
1949
+ i === null || i + 1 === a ? (s.push(a), i = a) : (n.push(new qe(
1950
+ s[0] * this.blockSize,
1951
+ s.length * this.blockSize,
1952
+ s
1953
+ )), s = [a], i = a);
1954
+ return n.push(new qe(
1955
+ s[0] * this.blockSize,
1956
+ s.length * this.blockSize,
1957
+ s
1958
+ )), n;
1959
+ }
1960
+ /**
1961
+ *
1962
+ * @param {import("./basesource").Slice[]} slices
1963
+ * @param {Map} blocks
1964
+ */
1965
+ readSliceData(e, t) {
1966
+ return e.map((s) => {
1967
+ let i = s.offset + s.length;
1968
+ this.fileSize !== null && (i = Math.min(this.fileSize, i));
1969
+ const n = Math.floor(s.offset / this.blockSize), a = Math.floor(i / this.blockSize), o = new ArrayBuffer(s.length), c = new Uint8Array(o);
1970
+ for (let l = n; l <= a; ++l) {
1971
+ const f = t.get(l), h = f.offset - s.offset, u = f.top - i;
1972
+ let d = 0, g = 0, y;
1973
+ h < 0 ? d = -h : h > 0 && (g = h), u < 0 ? y = f.length - d : y = i - f.offset - d;
1974
+ const p = new Uint8Array(f.data, d, y);
1975
+ c.set(p, g);
1976
+ }
1977
+ return o;
1978
+ });
1979
+ }
1980
+ }
1981
+ class de {
1982
+ /**
1983
+ * Returns whether the response has an ok'ish status code
1984
+ */
1985
+ get ok() {
1986
+ return this.status >= 200 && this.status <= 299;
1987
+ }
1988
+ /**
1989
+ * Returns the status code of the response
1990
+ */
1991
+ get status() {
1992
+ throw new Error("not implemented");
1993
+ }
1994
+ /**
1995
+ * Returns the value of the specified header
1996
+ * @param {string} headerName the header name
1997
+ * @returns {string} the header value
1998
+ */
1999
+ getHeader(e) {
2000
+ throw new Error("not implemented");
2001
+ }
2002
+ /**
2003
+ * @returns {ArrayBuffer} the response data of the request
2004
+ */
2005
+ async getData() {
2006
+ throw new Error("not implemented");
2007
+ }
2008
+ }
2009
+ class ye {
2010
+ constructor(e) {
2011
+ this.url = e;
2012
+ }
2013
+ /**
2014
+ * Send a request with the options
2015
+ * @param {{headers: HeadersInit, signal: AbortSignal}} [options={}]
2016
+ * @returns {Promise<BaseResponse>}
2017
+ */
2018
+ async request({ headers: e, signal: t } = {}) {
2019
+ throw new Error("request is not implemented");
2020
+ }
2021
+ }
2022
+ class Ur extends de {
2023
+ /**
2024
+ * BaseResponse facade for fetch API Response
2025
+ * @param {Response} response
2026
+ */
2027
+ constructor(e) {
2028
+ super(), this.response = e;
2029
+ }
2030
+ get status() {
2031
+ return this.response.status;
2032
+ }
2033
+ getHeader(e) {
2034
+ return this.response.headers.get(e);
2035
+ }
2036
+ async getData() {
2037
+ return this.response.arrayBuffer ? await this.response.arrayBuffer() : (await this.response.buffer()).buffer;
2038
+ }
2039
+ }
2040
+ class _r extends ye {
2041
+ constructor(e, t) {
2042
+ super(e), this.credentials = t;
2043
+ }
2044
+ /**
2045
+ * @param {{headers: HeadersInit, signal: AbortSignal}} [options={}]
2046
+ * @returns {Promise<FetchResponse>}
2047
+ */
2048
+ async request({ headers: e, signal: t } = {}) {
2049
+ const s = await fetch(this.url, {
2050
+ headers: e,
2051
+ credentials: this.credentials,
2052
+ signal: t
2053
+ });
2054
+ return new Ur(s);
2055
+ }
2056
+ }
2057
+ class vr extends de {
2058
+ /**
2059
+ * BaseResponse facade for XMLHttpRequest
2060
+ * @param {XMLHttpRequest} xhr
2061
+ * @param {ArrayBuffer} data
2062
+ */
2063
+ constructor(e, t) {
2064
+ super(), this.xhr = e, this.data = t;
2065
+ }
2066
+ get status() {
2067
+ return this.xhr.status;
2068
+ }
2069
+ getHeader(e) {
2070
+ return this.xhr.getResponseHeader(e);
2071
+ }
2072
+ async getData() {
2073
+ return this.data;
2074
+ }
2075
+ }
2076
+ class Lr extends ye {
2077
+ constructRequest(e, t) {
2078
+ return new Promise((s, i) => {
2079
+ const n = new XMLHttpRequest();
2080
+ n.open("GET", this.url), n.responseType = "arraybuffer";
2081
+ for (const [a, o] of Object.entries(e))
2082
+ n.setRequestHeader(a, o);
2083
+ n.onload = () => {
2084
+ const a = n.response;
2085
+ s(new vr(n, a));
2086
+ }, n.onerror = i, n.onabort = () => i(new _("Request aborted")), n.send(), t && (t.aborted && n.abort(), t.addEventListener("abort", () => n.abort()));
2087
+ });
2088
+ }
2089
+ async request({ headers: e, signal: t } = {}) {
2090
+ return await this.constructRequest(e, t);
2091
+ }
2092
+ }
2093
+ class Nr extends de {
2094
+ /**
2095
+ * BaseResponse facade for node HTTP/HTTPS API Response
2096
+ * @param {http.ServerResponse} response
2097
+ */
2098
+ constructor(e, t) {
2099
+ super(), this.response = e, this.dataPromise = t;
2100
+ }
2101
+ get status() {
2102
+ return this.response.statusCode;
2103
+ }
2104
+ getHeader(e) {
2105
+ return this.response.headers[e];
2106
+ }
2107
+ async getData() {
2108
+ return await this.dataPromise;
2109
+ }
2110
+ }
2111
+ class Kr extends ye {
2112
+ constructor(e) {
2113
+ super(e), this.parsedUrl = L.parse(this.url), this.httpApi = (this.parsedUrl.protocol === "http:", L);
2114
+ }
2115
+ constructRequest(e, t) {
2116
+ return new Promise((s, i) => {
2117
+ const n = this.httpApi.get(
2118
+ {
2119
+ ...this.parsedUrl,
2120
+ headers: e
2121
+ },
2122
+ (a) => {
2123
+ const o = new Promise((c) => {
2124
+ const l = [];
2125
+ a.on("data", (f) => {
2126
+ l.push(f);
2127
+ }), a.on("end", () => {
2128
+ const f = Buffer.concat(l).buffer;
2129
+ c(f);
2130
+ }), a.on("error", i);
2131
+ });
2132
+ s(new Nr(a, o));
2133
+ }
2134
+ );
2135
+ n.on("error", i), t && (t.aborted && n.destroy(new _("Request aborted")), t.addEventListener("abort", () => n.destroy(new _("Request aborted"))));
2136
+ });
2137
+ }
2138
+ async request({ headers: e, signal: t } = {}) {
2139
+ return await this.constructRequest(e, t);
2140
+ }
2141
+ }
2142
+ class pe extends Q {
2143
+ /**
2144
+ *
2145
+ * @param {BaseClient} client
2146
+ * @param {object} headers
2147
+ * @param {numbers} maxRanges
2148
+ * @param {boolean} allowFullFile
2149
+ */
2150
+ constructor(e, t, s, i) {
2151
+ super(), this.client = e, this.headers = t, this.maxRanges = s, this.allowFullFile = i, this._fileSize = null;
2152
+ }
2153
+ /**
2154
+ *
2155
+ * @param {Slice[]} slices
2156
+ */
2157
+ async fetch(e, t) {
2158
+ return this.maxRanges >= e.length ? this.fetchSlices(e, t) : (this.maxRanges > 0 && e.length > 1, Promise.all(
2159
+ e.map((s) => this.fetchSlice(s, t))
2160
+ ));
2161
+ }
2162
+ async fetchSlices(e, t) {
2163
+ const s = await this.client.request({
2164
+ headers: {
2165
+ ...this.headers,
2166
+ Range: `bytes=${e.map(({ offset: i, length: n }) => `${i}-${i + n}`).join(",")}`
2167
+ },
2168
+ signal: t
2169
+ });
2170
+ if (s.ok)
2171
+ if (s.status === 206) {
2172
+ const { type: i, params: n } = Er(s.getHeader("content-type"));
2173
+ if (i === "multipart/byteranges") {
2174
+ const h = Or(await s.getData(), n.boundary);
2175
+ return this._fileSize = h[0].fileSize || null, h;
2176
+ }
2177
+ const a = await s.getData(), { start: o, end: c, total: l } = be(s.getHeader("content-range"));
2178
+ this._fileSize = l || null;
2179
+ const f = [{
2180
+ data: a,
2181
+ offset: o,
2182
+ length: c - o
2183
+ }];
2184
+ if (e.length > 1) {
2185
+ const h = await Promise.all(e.slice(1).map((u) => this.fetchSlice(u, t)));
2186
+ return f.concat(h);
2187
+ }
2188
+ return f;
2189
+ } else {
2190
+ if (!this.allowFullFile)
2191
+ throw new Error("Server responded with full file");
2192
+ const i = await s.getData();
2193
+ return this._fileSize = i.byteLength, [{
2194
+ data: i,
2195
+ offset: 0,
2196
+ length: i.byteLength
2197
+ }];
2198
+ }
2199
+ else throw new Error("Error fetching data.");
2200
+ }
2201
+ async fetchSlice(e, t) {
2202
+ const { offset: s, length: i } = e, n = await this.client.request({
2203
+ headers: {
2204
+ ...this.headers,
2205
+ Range: `bytes=${s}-${s + i}`
2206
+ },
2207
+ signal: t
2208
+ });
2209
+ if (n.ok)
2210
+ if (n.status === 206) {
2211
+ const a = await n.getData(), { total: o } = be(n.getHeader("content-range"));
2212
+ return this._fileSize = o || null, {
2213
+ data: a,
2214
+ offset: s,
2215
+ length: i
2216
+ };
2217
+ } else {
2218
+ if (!this.allowFullFile)
2219
+ throw new Error("Server responded with full file");
2220
+ const a = await n.getData();
2221
+ return this._fileSize = a.byteLength, {
2222
+ data: a,
2223
+ offset: 0,
2224
+ length: a.byteLength
2225
+ };
2226
+ }
2227
+ else throw new Error("Error fetching data.");
2228
+ }
2229
+ get fileSize() {
2230
+ return this._fileSize;
2231
+ }
2232
+ }
2233
+ function we(r, { blockSize: e, cacheSize: t }) {
2234
+ return e === null ? r : new Gr(r, { blockSize: e, cacheSize: t });
2235
+ }
2236
+ function zr(r, { headers: e = {}, credentials: t, maxRanges: s = 0, allowFullFile: i = !1, ...n } = {}) {
2237
+ const a = new _r(r, t), o = new pe(a, e, s, i);
2238
+ return we(o, n);
2239
+ }
2240
+ function qr(r, { headers: e = {}, maxRanges: t = 0, allowFullFile: s = !1, ...i } = {}) {
2241
+ const n = new Lr(r), a = new pe(n, e, t, s);
2242
+ return we(a, i);
2243
+ }
2244
+ function Vr(r, { headers: e = {}, maxRanges: t = 0, allowFullFile: s = !1, ...i } = {}) {
2245
+ const n = new Kr(r), a = new pe(n, e, t, s);
2246
+ return we(a, i);
2247
+ }
2248
+ function jr(r, { headers: e = {}, maxRanges: t = 0, allowFullFile: s = !1, ...i } = {}) {
2249
+ const n = new pe(r, e, t, s);
2250
+ return we(n, i);
2251
+ }
2252
+ function Te(r, { forceXHR: e = !1, ...t } = {}) {
2253
+ return typeof fetch == "function" && !e ? zr(r, t) : typeof XMLHttpRequest < "u" ? qr(r, t) : Vr(r, t);
2254
+ }
2255
+ class Hr extends Q {
2256
+ constructor(e) {
2257
+ super(), this.arrayBuffer = e;
2258
+ }
2259
+ fetchSlice(e, t) {
2260
+ if (t && t.aborted)
2261
+ throw new _("Request aborted");
2262
+ return this.arrayBuffer.slice(e.offset, e.offset + e.length);
2263
+ }
2264
+ }
2265
+ function Yr(r) {
2266
+ return new Hr(r);
2267
+ }
2268
+ class $r extends Q {
2269
+ constructor(e) {
2270
+ super(), this.file = e;
2271
+ }
2272
+ async fetchSlice(e, t) {
2273
+ return new Promise((s, i) => {
2274
+ const n = this.file.slice(e.offset, e.offset + e.length), a = new FileReader();
2275
+ a.onload = (o) => s(o.target.result), a.onerror = i, a.onabort = i, a.readAsArrayBuffer(n), t && t.addEventListener("abort", () => a.abort());
2276
+ });
2277
+ }
2278
+ }
2279
+ function Xr(r) {
2280
+ return new $r(r);
2281
+ }
2282
+ function Zr(r) {
2283
+ return new Promise((e, t) => {
2284
+ L.close(r, (s) => {
2285
+ s ? t(s) : e();
2286
+ });
2287
+ });
2288
+ }
2289
+ function Jr(r, e, t = void 0) {
2290
+ return new Promise((s, i) => {
2291
+ L.open(r, e, t, (n, a) => {
2292
+ n ? i(n) : s(a);
2293
+ });
2294
+ });
2295
+ }
2296
+ function Qr(...r) {
2297
+ return new Promise((e, t) => {
2298
+ L.read(...r, (s, i, n) => {
2299
+ s ? t(s) : e({ bytesRead: i, buffer: n });
2300
+ });
2301
+ });
2302
+ }
2303
+ class Wr extends Q {
2304
+ constructor(e) {
2305
+ super(), this.path = e, this.openRequest = Jr(e, "r");
2306
+ }
2307
+ async fetchSlice(e) {
2308
+ const t = await this.openRequest, { buffer: s } = await Qr(
2309
+ t,
2310
+ Buffer.alloc(e.length),
2311
+ 0,
2312
+ e.length,
2313
+ e.offset
2314
+ );
2315
+ return s.buffer;
2316
+ }
2317
+ async close() {
2318
+ const e = await this.openRequest;
2319
+ await Zr(e);
2320
+ }
2321
+ }
2322
+ function es(r) {
2323
+ return new Wr(r);
2324
+ }
2325
+ const ts = Re(U), rs = Re(N), M = {};
2326
+ dt(M, ts);
2327
+ dt(M, rs);
2328
+ const ss = Re(X), he = 1e3, A = {
2329
+ nextZero: (r, e) => {
2330
+ let t = e;
2331
+ for (; r[t] !== 0; )
2332
+ t++;
2333
+ return t;
2334
+ },
2335
+ readUshort: (r, e) => r[e] << 8 | r[e + 1],
2336
+ readShort: (r, e) => {
2337
+ const t = A.ui8;
2338
+ return t[0] = r[e + 1], t[1] = r[e + 0], A.i16[0];
2339
+ },
2340
+ readInt: (r, e) => {
2341
+ const t = A.ui8;
2342
+ return t[0] = r[e + 3], t[1] = r[e + 2], t[2] = r[e + 1], t[3] = r[e + 0], A.i32[0];
2343
+ },
2344
+ readUint: (r, e) => {
2345
+ const t = A.ui8;
2346
+ return t[0] = r[e + 3], t[1] = r[e + 2], t[2] = r[e + 1], t[3] = r[e + 0], A.ui32[0];
2347
+ },
2348
+ readASCII: (r, e, t) => t.map((s) => String.fromCharCode(r[e + s])).join(""),
2349
+ readFloat: (r, e) => {
2350
+ const t = A.ui8;
2351
+ return C(4, (s) => {
2352
+ t[s] = r[e + 3 - s];
2353
+ }), A.fl32[0];
2354
+ },
2355
+ readDouble: (r, e) => {
2356
+ const t = A.ui8;
2357
+ return C(8, (s) => {
2358
+ t[s] = r[e + 7 - s];
2359
+ }), A.fl64[0];
2360
+ },
2361
+ writeUshort: (r, e, t) => {
2362
+ r[e] = t >> 8 & 255, r[e + 1] = t & 255;
2363
+ },
2364
+ writeUint: (r, e, t) => {
2365
+ r[e] = t >> 24 & 255, r[e + 1] = t >> 16 & 255, r[e + 2] = t >> 8 & 255, r[e + 3] = t >> 0 & 255;
2366
+ },
2367
+ writeASCII: (r, e, t) => {
2368
+ C(t.length, (s) => {
2369
+ r[e + s] = t.charCodeAt(s);
2370
+ });
2371
+ },
2372
+ ui8: new Uint8Array(8)
2373
+ };
2374
+ A.fl64 = new Float64Array(A.ui8.buffer);
2375
+ A.writeDouble = (r, e, t) => {
2376
+ A.fl64[0] = t, C(8, (s) => {
2377
+ r[e + s] = A.ui8[7 - s];
2378
+ });
2379
+ };
2380
+ const is = (r, e, t, s) => {
2381
+ let i = t;
2382
+ const n = Object.keys(s).filter((o) => o != null && o !== "undefined");
2383
+ r.writeUshort(e, i, n.length), i += 2;
2384
+ let a = i + 12 * n.length + 4;
2385
+ for (const o of n) {
2386
+ let c = null;
2387
+ typeof o == "number" ? c = o : typeof o == "string" && (c = parseInt(o, 10));
2388
+ const l = ue[c], f = ss[l];
2389
+ if (l == null || l === void 0 || typeof l > "u")
2390
+ throw new Error(`unknown type of tag: ${c}`);
2391
+ let h = s[o];
2392
+ if (h === void 0)
2393
+ throw new Error(`failed to get value for key ${o}`);
2394
+ l === "ASCII" && typeof h == "string" && yt(h, "\0") === !1 && (h += "\0");
2395
+ const u = h.length;
2396
+ r.writeUshort(e, i, c), i += 2, r.writeUshort(e, i, f), i += 2, r.writeUint(e, i, u), i += 4;
2397
+ let d = [-1, 1, 1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 8][f] * u, g = i;
2398
+ d > 4 && (r.writeUint(e, i, a), g = a), l === "ASCII" ? r.writeASCII(e, g, h) : l === "SHORT" ? C(u, (y) => {
2399
+ r.writeUshort(e, g + 2 * y, h[y]);
2400
+ }) : l === "LONG" ? C(u, (y) => {
2401
+ r.writeUint(e, g + 4 * y, h[y]);
2402
+ }) : l === "RATIONAL" ? C(u, (y) => {
2403
+ r.writeUint(e, g + 8 * y, Math.round(h[y] * 1e4)), r.writeUint(e, g + 8 * y + 4, 1e4);
2404
+ }) : l === "DOUBLE" && C(u, (y) => {
2405
+ r.writeDouble(e, g + 8 * y, h[y]);
2406
+ }), d > 4 && (d += d & 1, a += d), i += 4;
2407
+ }
2408
+ return [i, a];
2409
+ }, ns = (r) => {
2410
+ const e = new Uint8Array(he);
2411
+ let t = 4;
2412
+ const s = A;
2413
+ e[0] = 77, e[1] = 77, e[3] = 42;
2414
+ let i = 8;
2415
+ if (s.writeUint(e, t, i), t += 4, r.forEach((a, o) => {
2416
+ const c = is(s, e, i, a);
2417
+ i = c[1], o < r.length - 1 && s.writeUint(e, c[0], i);
2418
+ }), e.slice)
2419
+ return e.slice(0, i).buffer;
2420
+ const n = new Uint8Array(i);
2421
+ for (let a = 0; a < i; a++)
2422
+ n[a] = e[a];
2423
+ return n.buffer;
2424
+ }, os = (r, e, t, s) => {
2425
+ if (t == null)
2426
+ throw new Error(`you passed into encodeImage a width of type ${t}`);
2427
+ if (e == null)
2428
+ throw new Error(`you passed into encodeImage a width of type ${e}`);
2429
+ const i = {
2430
+ 256: [e],
2431
+ // ImageWidth
2432
+ 257: [t],
2433
+ // ImageLength
2434
+ 273: [he],
2435
+ // strips offset
2436
+ 278: [t],
2437
+ // RowsPerStrip
2438
+ 305: "geotiff.js"
2439
+ // no array for ASCII(Z)
2440
+ };
2441
+ if (s)
2442
+ for (const l in s)
2443
+ s.hasOwnProperty(l) && (i[l] = s[l]);
2444
+ const n = new Uint8Array(ns([i])), a = new Uint8Array(r), o = i[277], c = new Uint8Array(he + e * t * o);
2445
+ return C(n.length, (l) => {
2446
+ c[l] = n[l];
2447
+ }), Cr(a, (l, f) => {
2448
+ c[he + f] = l;
2449
+ }), c.buffer;
2450
+ }, as = (r) => {
2451
+ const e = {};
2452
+ for (const t in r)
2453
+ t !== "StripOffsets" && (M[t] || console.error(t, "not in name2code:", Object.keys(M)), e[M[t]] = r[t]);
2454
+ return e;
2455
+ }, cs = (r) => Array.isArray(r) ? r : [r], ls = [
2456
+ ["Compression", 1],
2457
+ // no compression
2458
+ ["PlanarConfiguration", 1],
2459
+ ["ExtraSamples", 0]
2460
+ ];
2461
+ function fs(r, e) {
2462
+ const t = typeof r[0] == "number";
2463
+ let s, i, n, a;
2464
+ t ? (s = e.height || e.ImageLength, n = e.width || e.ImageWidth, i = r.length / (s * n), a = r) : (i = r.length, s = r[0].length, n = r[0][0].length, a = [], C(s, (f) => {
2465
+ C(n, (h) => {
2466
+ C(i, (u) => {
2467
+ a.push(r[u][f][h]);
2468
+ });
2469
+ });
2470
+ })), e.ImageLength = s, delete e.height, e.ImageWidth = n, delete e.width, e.BitsPerSample || (e.BitsPerSample = C(i, () => 8)), ls.forEach((f) => {
2471
+ const h = f[0];
2472
+ if (!e[h]) {
2473
+ const u = f[1];
2474
+ e[h] = u;
2475
+ }
2476
+ }), e.PhotometricInterpretation || (e.PhotometricInterpretation = e.BitsPerSample.length === 3 ? 2 : 1), e.SamplesPerPixel || (e.SamplesPerPixel = [i]), e.StripByteCounts || (e.StripByteCounts = [i * s * n]), e.ModelPixelScale || (e.ModelPixelScale = [360 / n, 180 / s, 0]), e.SampleFormat || (e.SampleFormat = C(i, () => 1)), !e.hasOwnProperty("GeographicTypeGeoKey") && !e.hasOwnProperty("ProjectedCSTypeGeoKey") && (e.GeographicTypeGeoKey = 4326, e.ModelTiepoint = [0, 0, 0, -180, 90, 0], e.GeogCitationGeoKey = "WGS 84", e.GTModelTypeGeoKey = 2);
2477
+ const o = Object.keys(e).filter((f) => yt(f, "GeoKey")).sort((f, h) => M[f] - M[h]);
2478
+ if (!e.GeoAsciiParams) {
2479
+ let f = "";
2480
+ o.forEach((h) => {
2481
+ const u = Number(M[h]);
2482
+ ue[u] === "ASCII" && (f += `${e[h].toString()}\0`);
2483
+ }), f.length > 0 && (e.GeoAsciiParams = f);
2484
+ }
2485
+ if (!e.GeoKeyDirectory) {
2486
+ const h = [1, 1, 0, o.length];
2487
+ o.forEach((u) => {
2488
+ const d = Number(M[u]);
2489
+ h.push(d);
2490
+ let g, y, p;
2491
+ ue[d] === "SHORT" ? (g = 1, y = 0, p = e[u]) : u === "GeogCitationGeoKey" ? (g = e.GeoAsciiParams.length, y = Number(M.GeoAsciiParams), p = 0) : console.log(`[geotiff.js] couldn't get TIFFTagLocation for ${u}`), h.push(y), h.push(g), h.push(p);
2492
+ }), e.GeoKeyDirectory = h;
2493
+ }
2494
+ for (const f of o)
2495
+ e.hasOwnProperty(f) && delete e[f];
2496
+ [
2497
+ "Compression",
2498
+ "ExtraSamples",
2499
+ "GeographicTypeGeoKey",
2500
+ "GTModelTypeGeoKey",
2501
+ "GTRasterTypeGeoKey",
2502
+ "ImageLength",
2503
+ // synonym of ImageHeight
2504
+ "ImageWidth",
2505
+ "Orientation",
2506
+ "PhotometricInterpretation",
2507
+ "ProjectedCSTypeGeoKey",
2508
+ "PlanarConfiguration",
2509
+ "ResolutionUnit",
2510
+ "SamplesPerPixel",
2511
+ "XPosition",
2512
+ "YPosition",
2513
+ "RowsPerStrip"
2514
+ ].forEach((f) => {
2515
+ e[f] && (e[f] = cs(e[f]));
2516
+ });
2517
+ const c = as(e);
2518
+ return os(a, n, s, c);
2519
+ }
2520
+ class hs {
2521
+ log() {
2522
+ }
2523
+ debug() {
2524
+ }
2525
+ info() {
2526
+ }
2527
+ warn() {
2528
+ }
2529
+ error() {
2530
+ }
2531
+ time() {
2532
+ }
2533
+ timeEnd() {
2534
+ }
2535
+ }
2536
+ function us(r = new hs()) {
2537
+ }
2538
+ function gs(r, e) {
2539
+ let t = r.length - e, s = 0;
2540
+ do {
2541
+ for (let i = e; i > 0; i--)
2542
+ r[s + e] += r[s], s++;
2543
+ t -= e;
2544
+ } while (t > 0);
2545
+ }
2546
+ function ds(r, e, t) {
2547
+ let s = 0, i = r.length;
2548
+ const n = i / t;
2549
+ for (; i > e; ) {
2550
+ for (let o = e; o > 0; --o)
2551
+ r[s + e] += r[s], ++s;
2552
+ i -= e;
2553
+ }
2554
+ const a = r.slice();
2555
+ for (let o = 0; o < n; ++o)
2556
+ for (let c = 0; c < t; ++c)
2557
+ r[t * o + c] = a[(t - c - 1) * n + o];
2558
+ }
2559
+ function ys(r, e, t, s, i, n) {
2560
+ if (e === 1)
2561
+ return r;
2562
+ for (let c = 0; c < i.length; ++c) {
2563
+ if (i[c] % 8 !== 0)
2564
+ throw new Error("When decoding with predictor, only multiple of 8 bits are supported.");
2565
+ if (i[c] !== i[0])
2566
+ throw new Error("When decoding with predictor, all samples must have the same size.");
2567
+ }
2568
+ const a = i[0] / 8, o = n === 2 ? 1 : i.length;
2569
+ for (let c = 0; c < s && !(c * o * t * a >= r.byteLength); ++c) {
2570
+ let l;
2571
+ if (e === 2) {
2572
+ switch (i[0]) {
2573
+ case 8:
2574
+ l = new Uint8Array(
2575
+ r,
2576
+ c * o * t * a,
2577
+ o * t * a
2578
+ );
2579
+ break;
2580
+ case 16:
2581
+ l = new Uint16Array(
2582
+ r,
2583
+ c * o * t * a,
2584
+ o * t * a / 2
2585
+ );
2586
+ break;
2587
+ case 32:
2588
+ l = new Uint32Array(
2589
+ r,
2590
+ c * o * t * a,
2591
+ o * t * a / 4
2592
+ );
2593
+ break;
2594
+ default:
2595
+ throw new Error(`Predictor 2 not allowed with ${i[0]} bits per sample.`);
2596
+ }
2597
+ gs(l, o);
2598
+ } else e === 3 && (l = new Uint8Array(
2599
+ r,
2600
+ c * o * t * a,
2601
+ o * t * a
2602
+ ), ds(l, o, a));
2603
+ }
2604
+ return r;
2605
+ }
2606
+ class ps {
2607
+ async decode(e, t) {
2608
+ const s = await this.decodeBlock(t), i = e.Predictor || 1;
2609
+ if (i !== 1) {
2610
+ const n = !e.StripOffsets, a = n ? e.TileWidth : e.ImageWidth, o = n ? e.TileLength : e.RowsPerStrip || e.ImageLength;
2611
+ return ys(
2612
+ s,
2613
+ i,
2614
+ a,
2615
+ o,
2616
+ e.BitsPerSample,
2617
+ e.PlanarConfiguration
2618
+ );
2619
+ }
2620
+ return s;
2621
+ }
2622
+ }
2623
+ function Ae(r) {
2624
+ switch (r) {
2625
+ case m.BYTE:
2626
+ case m.ASCII:
2627
+ case m.SBYTE:
2628
+ case m.UNDEFINED:
2629
+ return 1;
2630
+ case m.SHORT:
2631
+ case m.SSHORT:
2632
+ return 2;
2633
+ case m.LONG:
2634
+ case m.SLONG:
2635
+ case m.FLOAT:
2636
+ case m.IFD:
2637
+ return 4;
2638
+ case m.RATIONAL:
2639
+ case m.SRATIONAL:
2640
+ case m.DOUBLE:
2641
+ case m.LONG8:
2642
+ case m.SLONG8:
2643
+ case m.IFD8:
2644
+ return 8;
2645
+ default:
2646
+ throw new RangeError(`Invalid field type: ${r}`);
2647
+ }
2648
+ }
2649
+ function ws(r) {
2650
+ const e = r.GeoKeyDirectory;
2651
+ if (!e)
2652
+ return null;
2653
+ const t = {};
2654
+ for (let s = 4; s <= e[3] * 4; s += 4) {
2655
+ const i = N[e[s]], n = e[s + 1] ? U[e[s + 1]] : null, a = e[s + 2], o = e[s + 3];
2656
+ let c = null;
2657
+ if (!n)
2658
+ c = o;
2659
+ else {
2660
+ if (c = r[n], typeof c > "u" || c === null)
2661
+ throw new Error(`Could not get value of geoKey '${i}'.`);
2662
+ typeof c == "string" ? c = c.substring(o, o + a - 1) : c.subarray && (c = c.subarray(o, o + a), a === 1 && (c = c[0]));
2663
+ }
2664
+ t[i] = c;
2665
+ }
2666
+ return t;
2667
+ }
2668
+ function v(r, e, t, s) {
2669
+ let i = null, n = null;
2670
+ const a = Ae(e);
2671
+ switch (e) {
2672
+ case m.BYTE:
2673
+ case m.ASCII:
2674
+ case m.UNDEFINED:
2675
+ i = new Uint8Array(t), n = r.readUint8;
2676
+ break;
2677
+ case m.SBYTE:
2678
+ i = new Int8Array(t), n = r.readInt8;
2679
+ break;
2680
+ case m.SHORT:
2681
+ i = new Uint16Array(t), n = r.readUint16;
2682
+ break;
2683
+ case m.SSHORT:
2684
+ i = new Int16Array(t), n = r.readInt16;
2685
+ break;
2686
+ case m.LONG:
2687
+ case m.IFD:
2688
+ i = new Uint32Array(t), n = r.readUint32;
2689
+ break;
2690
+ case m.SLONG:
2691
+ i = new Int32Array(t), n = r.readInt32;
2692
+ break;
2693
+ case m.LONG8:
2694
+ case m.IFD8:
2695
+ i = new Array(t), n = r.readUint64;
2696
+ break;
2697
+ case m.SLONG8:
2698
+ i = new Array(t), n = r.readInt64;
2699
+ break;
2700
+ case m.RATIONAL:
2701
+ i = new Uint32Array(t * 2), n = r.readUint32;
2702
+ break;
2703
+ case m.SRATIONAL:
2704
+ i = new Int32Array(t * 2), n = r.readInt32;
2705
+ break;
2706
+ case m.FLOAT:
2707
+ i = new Float32Array(t), n = r.readFloat32;
2708
+ break;
2709
+ case m.DOUBLE:
2710
+ i = new Float64Array(t), n = r.readFloat64;
2711
+ break;
2712
+ default:
2713
+ throw new RangeError(`Invalid field type: ${e}`);
2714
+ }
2715
+ if (e === m.RATIONAL || e === m.SRATIONAL)
2716
+ for (let o = 0; o < t; o += 2)
2717
+ i[o] = n.call(
2718
+ r,
2719
+ s + o * a
2720
+ ), i[o + 1] = n.call(
2721
+ r,
2722
+ s + (o * a + 4)
2723
+ );
2724
+ else
2725
+ for (let o = 0; o < t; ++o)
2726
+ i[o] = n.call(
2727
+ r,
2728
+ s + o * a
2729
+ );
2730
+ return e === m.ASCII ? new TextDecoder("utf-8").decode(i) : i;
2731
+ }
2732
+ class ms {
2733
+ constructor(e, t, s) {
2734
+ this.fileDirectory = e, this.geoKeyDirectory = t, this.nextIFDByteOffset = s;
2735
+ }
2736
+ }
2737
+ class fe extends Error {
2738
+ constructor(e) {
2739
+ super(`No image at index ${e}`), this.index = e;
2740
+ }
2741
+ }
2742
+ class pt {
2743
+ /**
2744
+ * (experimental) Reads raster data from the best fitting image. This function uses
2745
+ * the image with the lowest resolution that is still a higher resolution than the
2746
+ * requested resolution.
2747
+ * When specified, the `bbox` option is translated to the `window` option and the
2748
+ * `resX` and `resY` to `width` and `height` respectively.
2749
+ * Then, the [readRasters]{@link GeoTIFFImage#readRasters} method of the selected
2750
+ * image is called and the result returned.
2751
+ * @see GeoTIFFImage.readRasters
2752
+ * @param {import('./geotiffimage').ReadRasterOptions} [options={}] optional parameters
2753
+ * @returns {Promise<ReadRasterResult>} the decoded array(s), with `height` and `width`, as a promise
2754
+ */
2755
+ async readRasters(e = {}) {
2756
+ const { window: t, width: s, height: i } = e;
2757
+ let { resX: n, resY: a, bbox: o } = e;
2758
+ const c = await this.getImage();
2759
+ let l = c;
2760
+ const f = await this.getImageCount(), h = c.getBoundingBox();
2761
+ if (t && o)
2762
+ throw new Error('Both "bbox" and "window" passed.');
2763
+ if (s || i) {
2764
+ if (t) {
2765
+ const [g, y] = c.getOrigin(), [p, x] = c.getResolution();
2766
+ o = [
2767
+ g + t[0] * p,
2768
+ y + t[1] * x,
2769
+ g + t[2] * p,
2770
+ y + t[3] * x
2771
+ ];
2772
+ }
2773
+ const d = o || h;
2774
+ if (s) {
2775
+ if (n)
2776
+ throw new Error("Both width and resX passed");
2777
+ n = (d[2] - d[0]) / s;
2778
+ }
2779
+ if (i) {
2780
+ if (a)
2781
+ throw new Error("Both width and resY passed");
2782
+ a = (d[3] - d[1]) / i;
2783
+ }
2784
+ }
2785
+ if (n || a) {
2786
+ const d = [];
2787
+ for (let g = 0; g < f; ++g) {
2788
+ const y = await this.getImage(g), { SubfileType: p, NewSubfileType: x } = y.fileDirectory;
2789
+ (g === 0 || p === 2 || x & 1) && d.push(y);
2790
+ }
2791
+ d.sort((g, y) => g.getWidth() - y.getWidth());
2792
+ for (let g = 0; g < d.length; ++g) {
2793
+ const y = d[g], p = (h[2] - h[0]) / y.getWidth(), x = (h[3] - h[1]) / y.getHeight();
2794
+ if (l = y, n && n > p || a && a > x)
2795
+ break;
2796
+ }
2797
+ }
2798
+ let u = t;
2799
+ if (o) {
2800
+ const [d, g] = c.getOrigin(), [y, p] = l.getResolution(c);
2801
+ u = [
2802
+ Math.round((o[0] - d) / y),
2803
+ Math.round((o[1] - g) / p),
2804
+ Math.round((o[2] - d) / y),
2805
+ Math.round((o[3] - g) / p)
2806
+ ], u = [
2807
+ Math.min(u[0], u[2]),
2808
+ Math.min(u[1], u[3]),
2809
+ Math.max(u[0], u[2]),
2810
+ Math.max(u[1], u[3])
2811
+ ];
2812
+ }
2813
+ return l.readRasters({ ...e, window: u });
2814
+ }
2815
+ }
2816
+ class k extends pt {
2817
+ /**
2818
+ * @constructor
2819
+ * @param {*} source The datasource to read from.
2820
+ * @param {boolean} littleEndian Whether the image uses little endian.
2821
+ * @param {boolean} bigTiff Whether the image uses bigTIFF conventions.
2822
+ * @param {number} firstIFDOffset The numeric byte-offset from the start of the image
2823
+ * to the first IFD.
2824
+ * @param {GeoTIFFOptions} [options] further options.
2825
+ */
2826
+ constructor(e, t, s, i, n = {}) {
2827
+ super(), this.source = e, this.littleEndian = t, this.bigTiff = s, this.firstIFDOffset = i, this.cache = n.cache || !1, this.ifdRequests = [], this.ghostValues = null;
2828
+ }
2829
+ async getSlice(e, t) {
2830
+ const s = this.bigTiff ? 4048 : 1024;
2831
+ return new br(
2832
+ (await this.source.fetch([{
2833
+ offset: e,
2834
+ length: typeof t < "u" ? t : s
2835
+ }]))[0],
2836
+ e,
2837
+ this.littleEndian,
2838
+ this.bigTiff
2839
+ );
2840
+ }
2841
+ /**
2842
+ * Instructs to parse an image file directory at the given file offset.
2843
+ * As there is no way to ensure that a location is indeed the start of an IFD,
2844
+ * this function must be called with caution (e.g only using the IFD offsets from
2845
+ * the headers or other IFDs).
2846
+ * @param {number} offset the offset to parse the IFD at
2847
+ * @returns {Promise<ImageFileDirectory>} the parsed IFD
2848
+ */
2849
+ async parseFileDirectoryAt(e) {
2850
+ const t = this.bigTiff ? 20 : 12, s = this.bigTiff ? 8 : 2;
2851
+ let i = await this.getSlice(e);
2852
+ const n = this.bigTiff ? i.readUint64(e) : i.readUint16(e), a = n * t + (this.bigTiff ? 16 : 6);
2853
+ i.covers(e, a) || (i = await this.getSlice(e, a));
2854
+ const o = {};
2855
+ let c = e + (this.bigTiff ? 8 : 2);
2856
+ for (let h = 0; h < n; c += t, ++h) {
2857
+ const u = i.readUint16(c), d = i.readUint16(c + 2), g = this.bigTiff ? i.readUint64(c + 4) : i.readUint32(c + 4);
2858
+ let y, p;
2859
+ const x = Ae(d), w = c + (this.bigTiff ? 12 : 8);
2860
+ if (x * g <= (this.bigTiff ? 8 : 4))
2861
+ y = v(i, d, g, w);
2862
+ else {
2863
+ const S = i.readOffset(w), I = Ae(d) * g;
2864
+ if (i.covers(S, I))
2865
+ y = v(i, d, g, S);
2866
+ else {
2867
+ const b = await this.getSlice(S, I);
2868
+ y = v(b, d, g, S);
2869
+ }
2870
+ }
2871
+ g === 1 && st.indexOf(u) === -1 && !(d === m.RATIONAL || d === m.SRATIONAL) ? p = y[0] : p = y, o[U[u]] = p;
2872
+ }
2873
+ const l = ws(o), f = i.readOffset(
2874
+ e + s + t * n
2875
+ );
2876
+ return new ms(
2877
+ o,
2878
+ l,
2879
+ f
2880
+ );
2881
+ }
2882
+ async requestIFD(e) {
2883
+ if (this.ifdRequests[e])
2884
+ return this.ifdRequests[e];
2885
+ if (e === 0)
2886
+ return this.ifdRequests[e] = this.parseFileDirectoryAt(this.firstIFDOffset), this.ifdRequests[e];
2887
+ if (!this.ifdRequests[e - 1])
2888
+ try {
2889
+ this.ifdRequests[e - 1] = this.requestIFD(e - 1);
2890
+ } catch (t) {
2891
+ throw t instanceof fe ? new fe(e) : t;
2892
+ }
2893
+ return this.ifdRequests[e] = (async () => {
2894
+ const t = await this.ifdRequests[e - 1];
2895
+ if (t.nextIFDByteOffset === 0)
2896
+ throw new fe(e);
2897
+ return this.parseFileDirectoryAt(t.nextIFDByteOffset);
2898
+ })(), this.ifdRequests[e];
2899
+ }
2900
+ /**
2901
+ * Get the n-th internal subfile of an image. By default, the first is returned.
2902
+ *
2903
+ * @param {number} [index=0] the index of the image to return.
2904
+ * @returns {Promise<GeoTIFFImage>} the image at the given index
2905
+ */
2906
+ async getImage(e = 0) {
2907
+ const t = await this.requestIFD(e);
2908
+ return new ke(
2909
+ t.fileDirectory,
2910
+ t.geoKeyDirectory,
2911
+ this.dataView,
2912
+ this.littleEndian,
2913
+ this.cache,
2914
+ this.source
2915
+ );
2916
+ }
2917
+ /**
2918
+ * Returns the count of the internal subfiles.
2919
+ *
2920
+ * @returns {Promise<number>} the number of internal subfile images
2921
+ */
2922
+ async getImageCount() {
2923
+ let e = 0, t = !0;
2924
+ for (; t; )
2925
+ try {
2926
+ await this.requestIFD(e), ++e;
2927
+ } catch (s) {
2928
+ if (s instanceof fe)
2929
+ t = !1;
2930
+ else
2931
+ throw s;
2932
+ }
2933
+ return e;
2934
+ }
2935
+ /**
2936
+ * Get the values of the COG ghost area as a parsed map.
2937
+ * See https://gdal.org/drivers/raster/cog.html#header-ghost-area for reference
2938
+ * @returns {Promise<Object>} the parsed ghost area or null, if no such area was found
2939
+ */
2940
+ async getGhostValues() {
2941
+ const e = this.bigTiff ? 16 : 8;
2942
+ if (this.ghostValues)
2943
+ return this.ghostValues;
2944
+ const t = "GDAL_STRUCTURAL_METADATA_SIZE=", s = t.length + 100;
2945
+ let i = await this.getSlice(e, s);
2946
+ if (t === v(i, m.ASCII, t.length, e)) {
2947
+ const a = v(i, m.ASCII, s, e).split(`
2948
+ `)[0], o = Number(a.split("=")[1].split(" ")[0]) + a.length;
2949
+ o > s && (i = await this.getSlice(e, o));
2950
+ const c = v(i, m.ASCII, o, e);
2951
+ this.ghostValues = {}, c.split(`
2952
+ `).filter((l) => l.length > 0).map((l) => l.split("=")).forEach(([l, f]) => {
2953
+ this.ghostValues[l] = f;
2954
+ });
2955
+ }
2956
+ return this.ghostValues;
2957
+ }
2958
+ /**
2959
+ * Parse a (Geo)TIFF file from the given source.
2960
+ *
2961
+ * @param {*} source The source of data to parse from.
2962
+ * @param {GeoTIFFOptions} [options] Additional options.
2963
+ * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
2964
+ * to be aborted
2965
+ */
2966
+ static async fromSource(e, t, s) {
2967
+ const i = (await e.fetch([{ offset: 0, length: 1024 }], s))[0], n = new Ir(i), a = n.getUint16(0, 0);
2968
+ let o;
2969
+ if (a === 18761)
2970
+ o = !0;
2971
+ else if (a === 19789)
2972
+ o = !1;
2973
+ else
2974
+ throw new TypeError("Invalid byte order value.");
2975
+ const c = n.getUint16(2, o);
2976
+ let l;
2977
+ if (c === 42)
2978
+ l = !1;
2979
+ else if (c === 43) {
2980
+ if (l = !0, n.getUint16(4, o) !== 8)
2981
+ throw new Error("Unsupported offset byte-size.");
2982
+ } else
2983
+ throw new TypeError("Invalid magic number.");
2984
+ const f = l ? n.getUint64(8, o) : n.getUint32(4, o);
2985
+ return new k(e, o, l, f, t);
2986
+ }
2987
+ /**
2988
+ * Closes the underlying file buffer
2989
+ * N.B. After the GeoTIFF has been completely processed it needs
2990
+ * to be closed but only if it has been constructed from a file.
2991
+ */
2992
+ close() {
2993
+ return typeof this.source.close == "function" ? this.source.close() : !1;
2994
+ }
2995
+ }
2996
+ class wt extends pt {
2997
+ /**
2998
+ * Construct a new MultiGeoTIFF from a main and several overview files.
2999
+ * @param {GeoTIFF} mainFile The main GeoTIFF file.
3000
+ * @param {GeoTIFF[]} overviewFiles An array of overview files.
3001
+ */
3002
+ constructor(e, t) {
3003
+ super(), this.mainFile = e, this.overviewFiles = t, this.imageFiles = [e].concat(t), this.fileDirectoriesPerFile = null, this.fileDirectoriesPerFileParsing = null, this.imageCount = null;
3004
+ }
3005
+ async parseFileDirectoriesPerFile() {
3006
+ const e = [this.mainFile.parseFileDirectoryAt(this.mainFile.firstIFDOffset)].concat(this.overviewFiles.map((t) => t.parseFileDirectoryAt(t.firstIFDOffset)));
3007
+ return this.fileDirectoriesPerFile = await Promise.all(e), this.fileDirectoriesPerFile;
3008
+ }
3009
+ /**
3010
+ * Get the n-th internal subfile of an image. By default, the first is returned.
3011
+ *
3012
+ * @param {number} [index=0] the index of the image to return.
3013
+ * @returns {Promise<GeoTIFFImage>} the image at the given index
3014
+ */
3015
+ async getImage(e = 0) {
3016
+ await this.getImageCount(), await this.parseFileDirectoriesPerFile();
3017
+ let t = 0, s = 0;
3018
+ for (let i = 0; i < this.imageFiles.length; i++) {
3019
+ const n = this.imageFiles[i];
3020
+ for (let a = 0; a < this.imageCounts[i]; a++) {
3021
+ if (e === t) {
3022
+ const o = await n.requestIFD(s);
3023
+ return new ke(
3024
+ o.fileDirectory,
3025
+ o.geoKeyDirectory,
3026
+ n.dataView,
3027
+ n.littleEndian,
3028
+ n.cache,
3029
+ n.source
3030
+ );
3031
+ }
3032
+ t++, s++;
3033
+ }
3034
+ s = 0;
3035
+ }
3036
+ throw new RangeError("Invalid image index");
3037
+ }
3038
+ /**
3039
+ * Returns the count of the internal subfiles.
3040
+ *
3041
+ * @returns {Promise<number>} the number of internal subfile images
3042
+ */
3043
+ async getImageCount() {
3044
+ if (this.imageCount !== null)
3045
+ return this.imageCount;
3046
+ const e = [this.mainFile.getImageCount()].concat(this.overviewFiles.map((t) => t.getImageCount()));
3047
+ return this.imageCounts = await Promise.all(e), this.imageCount = this.imageCounts.reduce((t, s) => t + s, 0), this.imageCount;
3048
+ }
3049
+ }
3050
+ async function xs(r, e = {}, t) {
3051
+ return k.fromSource(Te(r, e), t);
3052
+ }
3053
+ async function Ss(r, e = {}, t) {
3054
+ return k.fromSource(jr(r, e), t);
3055
+ }
3056
+ async function Is(r, e) {
3057
+ return k.fromSource(Yr(r), e);
3058
+ }
3059
+ async function bs(r, e) {
3060
+ return k.fromSource(es(r), e);
3061
+ }
3062
+ async function Ts(r, e) {
3063
+ return k.fromSource(Xr(r), e);
3064
+ }
3065
+ async function As(r, e = [], t = {}, s) {
3066
+ const i = await k.fromSource(Te(r, t), s), n = await Promise.all(
3067
+ e.map((a) => k.fromSource(Te(a, t)))
3068
+ );
3069
+ return new wt(i, n);
3070
+ }
3071
+ function Ds(r, e) {
3072
+ return fs(r, e);
3073
+ }
3074
+ const Os = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3075
+ __proto__: null,
3076
+ BaseClient: ye,
3077
+ BaseDecoder: ps,
3078
+ BaseResponse: de,
3079
+ GeoTIFF: k,
3080
+ GeoTIFFImage: ke,
3081
+ MultiGeoTIFF: wt,
3082
+ Pool: Ar,
3083
+ addDecoder: G,
3084
+ default: k,
3085
+ fromArrayBuffer: Is,
3086
+ fromBlob: Ts,
3087
+ fromCustomClient: Ss,
3088
+ fromFile: bs,
3089
+ fromUrl: xs,
3090
+ fromUrls: As,
3091
+ getDecoder: Fe,
3092
+ globals: ar,
3093
+ rgb: hr,
3094
+ setLogger: us,
3095
+ writeArrayBuffer: Ds
3096
+ }, Symbol.toStringTag, { value: "Module" }));
3097
+ export {
3098
+ ps as B,
3099
+ nr as L,
3100
+ Ar as P,
3101
+ or as a,
3102
+ Is as b,
3103
+ Ts as c,
3104
+ ye as d,
3105
+ Ss as e,
3106
+ xs as f,
3107
+ Os as g
3108
+ };