chunk-6SASJ6IM.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. import {
  2. e
  3. } from "./chunk-3OHML7FO.js";
  4. import {
  5. d,
  6. f as f2,
  7. s as s3
  8. } from "./chunk-R5IG2D6H.js";
  9. import {
  10. r as r2
  11. } from "./chunk-Y3WMVFTW.js";
  12. import {
  13. T,
  14. f,
  15. g,
  16. k,
  17. m,
  18. p,
  19. r2 as r3,
  20. v
  21. } from "./chunk-ULGDPLM2.js";
  22. import {
  23. s,
  24. s3 as s2
  25. } from "./chunk-EMJ4ZSM2.js";
  26. import {
  27. a,
  28. a2,
  29. r
  30. } from "./chunk-GZT4BVFP.js";
  31. // node_modules/@arcgis/core/core/workers/utils.js
  32. var e2;
  33. !function(t) {
  34. t[t.HANDSHAKE = 0] = "HANDSHAKE", t[t.OPEN = 1] = "OPEN", t[t.OPENED = 2] = "OPENED", t[t.RESPONSE = 3] = "RESPONSE", t[t.INVOKE = 4] = "INVOKE", t[t.ABORT = 5] = "ABORT", t[t.CLOSE = 6] = "CLOSE", t[t.OPEN_PORT = 7] = "OPEN_PORT", t[t.ON = 8] = "ON";
  35. }(e2 || (e2 = {}));
  36. var r4 = 0;
  37. function n() {
  38. return r4++;
  39. }
  40. function s4(t) {
  41. return t && typeof t == "object" && ("result" in t || "transferList" in t);
  42. }
  43. function a3(t) {
  44. return t ? typeof t == "string" ? JSON.stringify({ name: "message", message: t }) : t.toJSON ? JSON.stringify(t) : JSON.stringify({ name: t.name, message: t.message, details: t.details || { stack: t.stack } }) : null;
  45. }
  46. function i(t, r5, n2, a4) {
  47. if (r5.type === e2.OPEN_PORT)
  48. return void t.postMessage(r5, [r5.port]);
  49. if (r5.type !== e2.INVOKE && r5.type !== e2.RESPONSE)
  50. return void t.postMessage(r5);
  51. let i2;
  52. s4(n2) ? (i2 = o(n2.transferList), r5.data = n2.result) : (i2 = o(a4), r5.data = n2), i2 ? t.postMessage(r5, i2) : t.postMessage(r5);
  53. }
  54. function f3(t) {
  55. if (!t)
  56. return null;
  57. const e3 = t.data;
  58. return e3 ? typeof e3 == "string" ? JSON.parse(e3) : e3 : null;
  59. }
  60. function o(e3) {
  61. if (!e3 || !e3.length)
  62. return null;
  63. if (a("esri-workers-arraybuffer-transfer"))
  64. return e3;
  65. const r5 = e3.filter((t) => !u(t));
  66. return r5.length ? r5 : null;
  67. }
  68. function u(t) {
  69. return t instanceof ArrayBuffer || t && t.constructor && t.constructor.name === "ArrayBuffer";
  70. }
  71. // node_modules/@arcgis/core/core/workers/RemoteClient.js
  72. var k2 = { statsWorker: () => import("./statsWorker-Z3SQUZHX.js"), geometryEngineWorker: () => import("./geometryEngineWorker-6Z5M6H2V.js"), CSVSourceWorker: () => import("./CSVSourceWorker-3RM7DFJI.js"), EdgeProcessingWorker: () => import("./EdgeProcessingWorker-UXPNBBU5.js"), ElevationSamplerWorker: () => import("./ElevationSamplerWorker-Z23AUMNI.js"), FeatureServiceSnappingSourceWorker: () => import("./FeatureServiceSnappingSourceWorker-O4IDMMDZ.js"), GeoJSONSourceWorker: () => import("./GeoJSONSourceWorker-NOAEMPL4.js"), LercWorker: () => import("./LercWorker-ISXTXRV5.js"), MemorySourceWorker: () => import("./MemorySourceWorker-O22FX6GJ.js"), PBFDecoderWorker: () => import("./PBFDecoderWorker-SIUZSYGK.js"), Pipeline: () => import("./Pipeline-FIWUDD7H.js"), PointCloudWorker: () => import("./PointCloudWorker-Z76DJAJC.js"), RasterWorker: () => import("./RasterWorker-7YM3XEAT.js"), SceneLayerSnappingSourceWorker: () => import("./SceneLayerSnappingSourceWorker-ZCIBJJSJ.js"), SceneLayerWorker: () => import("./SceneLayerWorker-SAXSQD5N.js"), WFSSourceWorker: () => import("./WFSSourceWorker-2XJ7RNZY.js"), WorkerTileHandler: () => import("./WorkerTileHandler-RHSUEZH4.js") };
  73. var { CLOSE: b, ABORT: v2, INVOKE: y, RESPONSE: j, OPEN_PORT: S, ON: f4 } = e2;
  74. var W = 2;
  75. var M = class {
  76. constructor(e3) {
  77. this._timer = null, this._cancelledJobIds = new Set(), this._invokeMessages = [], this._invoke = e3, this._timer = null, this._process = this._process.bind(this);
  78. }
  79. push(e3) {
  80. e3.type === e2.ABORT ? this._cancelledJobIds.add(e3.jobId) : (this._invokeMessages.push(e3), this._timer === null && (this._timer = setTimeout(this._process, 0)));
  81. }
  82. clear() {
  83. this._invokeMessages.length = 0, this._cancelledJobIds.clear(), this._timer = null;
  84. }
  85. _process() {
  86. this._timer = null;
  87. for (const e3 of this._invokeMessages)
  88. this._cancelledJobIds.has(e3.jobId) || this._invoke(e3);
  89. this._cancelledJobIds.clear(), this._invokeMessages.length = 0;
  90. }
  91. };
  92. var w = class {
  93. constructor(e3, s5, t) {
  94. this._port = e3, this._getNextJob = t, this._outJobs = new Map(), this._inJobs = new Map(), this._invokeQueue = new M((e4) => this._onInvokeMessage(e4)), this._client = s5.client, this._onMessage = this._onMessage.bind(this), this._channel = s5.channel, this._schedule = s5.schedule, this._port.addEventListener("message", this._onMessage), this._port.start();
  95. }
  96. static connect(e3) {
  97. const s5 = new MessageChannel();
  98. let t;
  99. t = typeof e3 == "function" ? new e3() : "default" in e3 && typeof e3.default == "function" ? new e3.default() : e3;
  100. const o2 = new w(s5.port1, { channel: s5, client: t }, () => null);
  101. return typeof t == "object" && "remoteClient" in t && (t.remoteClient = o2), w.clients.set(o2, t), s5.port2;
  102. }
  103. static loadWorker(e3) {
  104. const s5 = k2[e3];
  105. return s5 ? s5() : Promise.resolve(null);
  106. }
  107. close() {
  108. this._post({ type: b }), this._close();
  109. }
  110. isBusy() {
  111. return this._outJobs.size > 0;
  112. }
  113. invoke(e3, t, r5) {
  114. const c2 = r5 && r5.signal, l = r5 && r5.transferList;
  115. if (!this._port)
  116. return Promise.reject(new s2("worker:port-closed", `Cannot call invoke('${e3}'), port is closed`, { methodName: e3, data: t }));
  117. const h2 = n();
  118. return new Promise((s5, r6) => {
  119. if (p(c2))
  120. return this._processWork(), void r6(m());
  121. const p2 = v(c2, () => {
  122. const e4 = this._outJobs.get(h2);
  123. e4 && (this._outJobs.delete(h2), this._processWork(), a2(e4.abortHandle), this._post({ type: v2, jobId: h2 }), r6(m()));
  124. }), u2 = { resolve: s5, reject: r6, abortHandle: p2, debugInfo: e3 };
  125. this._outJobs.set(h2, u2), this._post({ type: y, jobId: h2, methodName: e3, abortable: c2 != null }, t, l);
  126. });
  127. }
  128. on(e3, s5) {
  129. const t = new MessageChannel();
  130. function o2(e4) {
  131. s5(e4.data);
  132. }
  133. return this._port.postMessage({ type: e2.ON, eventType: e3, port: t.port2 }, [t.port2]), t.port1.addEventListener("message", o2), t.port1.start(), { remove() {
  134. t.port1.postMessage({ type: e2.CLOSE }), t.port1.close(), t.port1.removeEventListener("message", o2);
  135. } };
  136. }
  137. jobAdded() {
  138. this._processWork();
  139. }
  140. openPort() {
  141. const e3 = new MessageChannel();
  142. return this._post({ type: S, port: e3.port2 }), e3.port1;
  143. }
  144. _processWork() {
  145. if (this._outJobs.size >= W)
  146. return;
  147. const e3 = this._getNextJob();
  148. if (!e3)
  149. return;
  150. const { methodName: s5, data: t, invokeOptions: o2, deferred: r5 } = e3;
  151. this.invoke(s5, t, o2).then((e4) => r5.resolve(e4)).catch((e4) => r5.reject(e4));
  152. }
  153. _close() {
  154. this._channel && (this._channel = null), this._port.removeEventListener("message", this._onMessage), this._port.close(), this._outJobs.forEach((e3) => {
  155. a2(e3.abortHandle), e3.reject(m(`Worker closing, aborting job calling '${e3.debugInfo}'`));
  156. }), this._inJobs.clear(), this._outJobs.clear(), this._invokeQueue.clear(), this._port = this._client = this._schedule = null;
  157. }
  158. _onMessage(e3) {
  159. r(this._schedule) ? this._schedule(() => this._processMessage(e3)) : this._processMessage(e3);
  160. }
  161. _processMessage(e3) {
  162. const s5 = f3(e3);
  163. if (s5)
  164. switch (s5.type) {
  165. case j:
  166. this._onResponseMessage(s5);
  167. break;
  168. case y:
  169. this._invokeQueue.push(s5);
  170. break;
  171. case v2:
  172. this._onAbortMessage(s5);
  173. break;
  174. case b:
  175. this._onCloseMessage();
  176. break;
  177. case S:
  178. this._onOpenPortMessage(s5);
  179. break;
  180. case f4:
  181. this._onOnMessage(s5);
  182. }
  183. }
  184. _onAbortMessage(e3) {
  185. const s5 = this._inJobs, t = e3.jobId, o2 = s5.get(t);
  186. this._invokeQueue.push(e3), o2 && (o2.controller && o2.controller.abort(), s5.delete(t));
  187. }
  188. _onCloseMessage() {
  189. const e3 = this._client;
  190. this._close(), e3 && "destroy" in e3 && w.clients.get(this) === e3 && e3.destroy(), w.clients.delete(this), e3 && e3.remoteClient && (e3.remoteClient = null);
  191. }
  192. _onInvokeMessage(e3) {
  193. const { methodName: s5, jobId: t, data: o2, abortable: r5 } = e3, i2 = r5 ? new AbortController() : null, n2 = this._inJobs;
  194. let a4, p2 = this._client, h2 = p2[s5];
  195. try {
  196. if (!h2 && s5 && s5.includes(".")) {
  197. const e4 = s5.split(".");
  198. for (let s6 = 0; s6 < e4.length - 1; s6++)
  199. p2 = p2[e4[s6]], h2 = p2[e4[s6 + 1]];
  200. }
  201. if (typeof h2 != "function")
  202. throw new TypeError(`${s5} is not a function`);
  203. a4 = h2.call(p2, o2, { client: this, signal: i2 ? i2.signal : null });
  204. } catch (u2) {
  205. return void this._post({ type: j, jobId: t, error: a3(u2) });
  206. }
  207. k(a4) ? (n2.set(t, { controller: i2, promise: a4 }), a4.then((e4) => {
  208. n2.has(t) && (n2.delete(t), this._post({ type: j, jobId: t }, e4));
  209. }, (e4) => {
  210. n2.has(t) && (n2.delete(t), g(e4) || this._post({ type: j, jobId: t, error: a3(e4 || { message: `Error encountered at method ${s5}` }) }));
  211. })) : this._post({ type: j, jobId: t }, a4);
  212. }
  213. _onOpenPortMessage(e3) {
  214. new w(e3.port, { client: this._client }, () => null);
  215. }
  216. _onOnMessage(e3) {
  217. const { port: s5 } = e3, o2 = this._client.on(e3.eventType, (e4) => {
  218. s5.postMessage(e4);
  219. }), r5 = r3(e3.port, "message", (e4) => {
  220. f3(e4).type === e2.CLOSE && (r5.remove(), o2.remove(), s5.close());
  221. });
  222. }
  223. _onResponseMessage(e3) {
  224. const { jobId: t, error: r5, data: i2 } = e3, n2 = this._outJobs;
  225. if (!n2.has(t))
  226. return;
  227. const a4 = n2.get(t);
  228. this._processWork(), n2.delete(t), a2(a4.abortHandle), r5 ? a4.reject(s2.fromJSON(JSON.parse(r5))) : a4.resolve(i2);
  229. }
  230. _post(e3, s5, t) {
  231. return i(this._port, e3, s5, t);
  232. }
  233. };
  234. w.kernelInfo = { revision: f2, version: s3, buildDate: d }, w.clients = new Map();
  235. // node_modules/@arcgis/core/core/workers/Connection.js
  236. var h = s.getLogger("esri.core.workers.Connection");
  237. var c = class {
  238. constructor() {
  239. this._inUseClients = new Array(), this._clients = new Array(), this._clientPromises = new Array(), this._ongoingJobsQueue = new e();
  240. }
  241. destroy() {
  242. this.close();
  243. }
  244. get closed() {
  245. return !this._clients || !this._clients.length;
  246. }
  247. open(e3, t) {
  248. return new Promise((n2, i2) => {
  249. let r5 = true;
  250. const h2 = (e4) => {
  251. f(t.signal), r5 && (r5 = false, e4());
  252. };
  253. this._clients.length = e3.length, this._clientPromises.length = e3.length, this._inUseClients.length = e3.length;
  254. for (let o2 = 0; o2 < e3.length; ++o2) {
  255. const r6 = e3[o2];
  256. k(r6) ? this._clientPromises[o2] = r6.then((e4) => (this._clients[o2] = new w(e4, t, () => this._ongoingJobsQueue.pop()), h2(n2), this._clients[o2]), () => (h2(i2), null)) : (this._clients[o2] = new w(r6, t, () => this._ongoingJobsQueue.pop()), this._clientPromises[o2] = Promise.resolve(this._clients[o2]), h2(n2));
  257. }
  258. });
  259. }
  260. broadcast(e3, t, s5) {
  261. const n2 = new Array(this._clientPromises.length);
  262. for (let i2 = 0; i2 < this._clientPromises.length; ++i2) {
  263. const o2 = this._clientPromises[i2];
  264. n2[i2] = o2.then((n3) => n3.invoke(e3, t, s5));
  265. }
  266. return n2;
  267. }
  268. close() {
  269. let e3;
  270. for (; e3 = this._ongoingJobsQueue.pop(); )
  271. e3.deferred.reject(m(`Worker closing, aborting job calling '${e3.methodName}'`));
  272. for (const t of this._clientPromises)
  273. t.then((e4) => e4.close());
  274. this._clients.length = 0, this._clientPromises.length = 0;
  275. }
  276. invoke(e3, t, s5) {
  277. let n2 = null;
  278. Array.isArray(s5) ? (h.warn("invoke()", "The transferList parameter is deprecated, use the options object instead"), n2 = { transferList: s5 }) : n2 = s5;
  279. const o2 = T();
  280. this._ongoingJobsQueue.push({ methodName: e3, data: t, invokeOptions: n2, deferred: o2 });
  281. for (let i2 = 0; i2 < this._clientPromises.length; i2++) {
  282. const e4 = this._clients[i2];
  283. e4 ? e4.jobAdded() : this._clientPromises[i2].then((e5) => e5.jobAdded());
  284. }
  285. return o2.promise;
  286. }
  287. on(t, s5) {
  288. return Promise.all(this._clientPromises).then(() => r2(this._clients.map((e3) => e3.on(t, s5))));
  289. }
  290. openPorts() {
  291. return new Promise((e3) => {
  292. const t = new Array(this._clientPromises.length);
  293. let s5 = t.length;
  294. for (let n2 = 0; n2 < this._clientPromises.length; ++n2) {
  295. this._clientPromises[n2].then((i2) => {
  296. t[n2] = i2.openPort(), --s5 == 0 && e3(t);
  297. });
  298. }
  299. });
  300. }
  301. get test() {
  302. return { numClients: this._clients.length };
  303. }
  304. };
  305. export {
  306. e2 as e,
  307. n,
  308. a3 as a,
  309. i,
  310. f3 as f,
  311. w,
  312. c
  313. };
  314. //# sourceMappingURL=chunk-6SASJ6IM.js.map