@sanity/client 6.15.20-canary.2 → 6.16.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 (38) hide show
  1. package/README.md +2 -2
  2. package/dist/_chunks-cjs/{vercelStegaCleanAll.cjs → stegaClean.cjs} +12 -9
  3. package/dist/_chunks-cjs/stegaClean.cjs.map +1 -0
  4. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +2 -2
  5. package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
  6. package/dist/_chunks-es/{vercelStegaCleanAll.js → stegaClean.js} +12 -9
  7. package/dist/_chunks-es/stegaClean.js.map +1 -0
  8. package/dist/_chunks-es/stegaEncodeSourceMap.js +2 -2
  9. package/dist/index.browser.cjs +10 -10
  10. package/dist/index.browser.cjs.map +1 -1
  11. package/dist/index.browser.js +10 -10
  12. package/dist/index.browser.js.map +1 -1
  13. package/dist/index.cjs +11 -11
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.js +11 -11
  16. package/dist/index.js.map +1 -1
  17. package/dist/stega.browser.cjs +3 -2
  18. package/dist/stega.browser.cjs.map +1 -1
  19. package/dist/stega.browser.d.cts +9 -1
  20. package/dist/stega.browser.d.ts +9 -1
  21. package/dist/stega.browser.js +2 -1
  22. package/dist/stega.browser.js.map +1 -1
  23. package/dist/stega.cjs +3 -2
  24. package/dist/stega.cjs.map +1 -1
  25. package/dist/stega.d.cts +9 -1
  26. package/dist/stega.d.ts +9 -1
  27. package/dist/stega.js +2 -1
  28. package/dist/stega.js.map +1 -1
  29. package/package.json +12 -12
  30. package/src/data/dataMethods.ts +2 -2
  31. package/src/data/listen.ts +4 -5
  32. package/src/stega/index.ts +1 -1
  33. package/src/stega/stegaClean.ts +22 -0
  34. package/umd/sanityClient.js +1138 -450
  35. package/umd/sanityClient.min.js +3 -3
  36. package/dist/_chunks-cjs/vercelStegaCleanAll.cjs.map +0 -1
  37. package/dist/_chunks-es/vercelStegaCleanAll.js.map +0 -1
  38. package/src/stega/vercelStegaCleanAll.ts +0 -19
@@ -57,7 +57,7 @@
57
57
  if (!validUrl.test(options.url))
58
58
  throw new Error(`"${options.url}" is not a valid URL`);
59
59
  };
60
- function getDefaultExportFromCjs(x) {
60
+ function getDefaultExportFromCjs$1(x) {
61
61
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x.default : x;
62
62
  }
63
63
 
@@ -166,45 +166,45 @@
166
166
  typeof result[key] > "u" ? result[key] = value : isArray$3(result[key]) ? result[key].push(value) : result[key] = [result[key], value];
167
167
  }
168
168
  return result;
169
- }, parseHeaders$1 = /* @__PURE__ */ getDefaultExportFromCjs(parseHeaders), __defProp$6 = Object.defineProperty, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$6 = (obj, key, value) => (__defNormalProp$6(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$8 = (obj, member, msg) => {
169
+ }, parseHeaders$1 = /* @__PURE__ */ getDefaultExportFromCjs$1(parseHeaders), __defProp$5 = Object.defineProperty, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$5 = (obj, key, value) => (__defNormalProp$5(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$7 = (obj, member, msg) => {
170
170
  if (!member.has(obj))
171
171
  throw TypeError("Cannot " + msg);
172
- }, __privateGet$8 = (obj, member, getter) => (__accessCheck$8(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$8 = (obj, member, value) => {
172
+ }, __privateGet$7 = (obj, member, getter) => (__accessCheck$7(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$7 = (obj, member, value) => {
173
173
  if (member.has(obj))
174
174
  throw TypeError("Cannot add the same private member more than once");
175
175
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
176
- }, __privateSet$8 = (obj, member, value, setter) => (__accessCheck$8(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value), _method, _url$1, _resHeaders, _headers, _controller, _init, _useAbortSignal;
176
+ }, __privateSet$7 = (obj, member, value, setter) => (__accessCheck$7(obj, member, "write to private field"), member.set(obj, value), value), _method, _url, _resHeaders, _headers, _controller, _init, _useAbortSignal;
177
177
  class FetchXhr {
178
178
  constructor() {
179
- __publicField$6(this, "onabort"), __publicField$6(this, "onerror"), __publicField$6(this, "onreadystatechange"), __publicField$6(this, "ontimeout"), __publicField$6(this, "readyState", 0), __publicField$6(this, "response"), __publicField$6(this, "responseText", ""), __publicField$6(this, "responseType", ""), __publicField$6(this, "status"), __publicField$6(this, "statusText"), __publicField$6(this, "withCredentials"), __privateAdd$8(this, _method, void 0), __privateAdd$8(this, _url$1, void 0), __privateAdd$8(this, _resHeaders, void 0), __privateAdd$8(this, _headers, {}), __privateAdd$8(this, _controller, void 0), __privateAdd$8(this, _init, {}), __privateAdd$8(this, _useAbortSignal, void 0);
179
+ __publicField$5(this, "onabort"), __publicField$5(this, "onerror"), __publicField$5(this, "onreadystatechange"), __publicField$5(this, "ontimeout"), __publicField$5(this, "readyState", 0), __publicField$5(this, "response"), __publicField$5(this, "responseText", ""), __publicField$5(this, "responseType", ""), __publicField$5(this, "status"), __publicField$5(this, "statusText"), __publicField$5(this, "withCredentials"), __privateAdd$7(this, _method, void 0), __privateAdd$7(this, _url, void 0), __privateAdd$7(this, _resHeaders, void 0), __privateAdd$7(this, _headers, {}), __privateAdd$7(this, _controller, void 0), __privateAdd$7(this, _init, {}), __privateAdd$7(this, _useAbortSignal, void 0);
180
180
  }
181
181
  // eslint-disable-next-line @typescript-eslint/no-unused-vars -- _async is only declared for typings compatibility
182
182
  open(method, url, _async) {
183
183
  var _a;
184
- __privateSet$8(this, _method, method), __privateSet$8(this, _url$1, url), __privateSet$8(this, _resHeaders, ""), this.readyState = 1, (_a = this.onreadystatechange) == null || _a.call(this), __privateSet$8(this, _controller, void 0);
184
+ __privateSet$7(this, _method, method), __privateSet$7(this, _url, url), __privateSet$7(this, _resHeaders, ""), this.readyState = 1, (_a = this.onreadystatechange) == null || _a.call(this), __privateSet$7(this, _controller, void 0);
185
185
  }
186
186
  abort() {
187
- __privateGet$8(this, _controller) && __privateGet$8(this, _controller).abort();
187
+ __privateGet$7(this, _controller) && __privateGet$7(this, _controller).abort();
188
188
  }
189
189
  getAllResponseHeaders() {
190
- return __privateGet$8(this, _resHeaders);
190
+ return __privateGet$7(this, _resHeaders);
191
191
  }
192
192
  setRequestHeader(name, value) {
193
- __privateGet$8(this, _headers)[name] = value;
193
+ __privateGet$7(this, _headers)[name] = value;
194
194
  }
195
195
  // Allow setting extra fetch init options, needed for runtimes such as Vercel Edge to set `cache` and other options in React Server Components
196
196
  setInit(init, useAbortSignal = !0) {
197
- __privateSet$8(this, _init, init), __privateSet$8(this, _useAbortSignal, useAbortSignal);
197
+ __privateSet$7(this, _init, init), __privateSet$7(this, _useAbortSignal, useAbortSignal);
198
198
  }
199
199
  send(body) {
200
200
  const textBody = this.responseType !== "arraybuffer", options = {
201
- ...__privateGet$8(this, _init),
202
- method: __privateGet$8(this, _method),
203
- headers: __privateGet$8(this, _headers),
201
+ ...__privateGet$7(this, _init),
202
+ method: __privateGet$7(this, _method),
203
+ headers: __privateGet$7(this, _headers),
204
204
  body
205
205
  };
206
- typeof AbortController == "function" && __privateGet$8(this, _useAbortSignal) && (__privateSet$8(this, _controller, new AbortController()), typeof EventTarget < "u" && __privateGet$8(this, _controller).signal instanceof EventTarget && (options.signal = __privateGet$8(this, _controller).signal)), typeof document < "u" && (options.credentials = this.withCredentials ? "include" : "omit"), fetch(__privateGet$8(this, _url$1), options).then((res) => (res.headers.forEach((value, key) => {
207
- __privateSet$8(this, _resHeaders, __privateGet$8(this, _resHeaders) + `${key}: ${value}\r
206
+ typeof AbortController == "function" && __privateGet$7(this, _useAbortSignal) && (__privateSet$7(this, _controller, new AbortController()), typeof EventTarget < "u" && __privateGet$7(this, _controller).signal instanceof EventTarget && (options.signal = __privateGet$7(this, _controller).signal)), typeof document < "u" && (options.credentials = this.withCredentials ? "include" : "omit"), fetch(__privateGet$7(this, _url), options).then((res) => (res.headers.forEach((value, key) => {
207
+ __privateSet$7(this, _resHeaders, __privateGet$7(this, _resHeaders) + `${key}: ${value}\r
208
208
  `);
209
209
  }), this.status = res.status, this.statusText = res.statusText, this.readyState = 3, textBody ? res.text() : res.arrayBuffer())).then((resBody) => {
210
210
  var _a;
@@ -219,7 +219,7 @@
219
219
  });
220
220
  }
221
221
  }
222
- _method = /* @__PURE__ */ new WeakMap(), _url$1 = /* @__PURE__ */ new WeakMap(), _resHeaders = /* @__PURE__ */ new WeakMap(), _headers = /* @__PURE__ */ new WeakMap(), _controller = /* @__PURE__ */ new WeakMap(), _init = /* @__PURE__ */ new WeakMap(), _useAbortSignal = /* @__PURE__ */ new WeakMap();
222
+ _method = /* @__PURE__ */ new WeakMap(), _url = /* @__PURE__ */ new WeakMap(), _resHeaders = /* @__PURE__ */ new WeakMap(), _headers = /* @__PURE__ */ new WeakMap(), _controller = /* @__PURE__ */ new WeakMap(), _init = /* @__PURE__ */ new WeakMap(), _useAbortSignal = /* @__PURE__ */ new WeakMap();
223
223
  const adapter = typeof XMLHttpRequest == "function" ? "xhr" : "fetch", XmlHttpRequest = adapter === "xhr" ? XMLHttpRequest : FetchXhr, httpRequester = (context, callback) => {
224
224
  var _a;
225
225
  const opts = context.options, options = context.applyMiddleware("finalizeOptions", opts), timers = {}, injectedResponse = context.applyMiddleware("interceptRequest", void 0, {
@@ -305,7 +305,7 @@
305
305
  }
306
306
  }, getIt = (initMiddleware = [], httpRequest = httpRequester) => createRequester(initMiddleware, httpRequest), environment = "browser";
307
307
 
308
- var browser$1 = { exports: {} }, ms, hasRequiredMs;
308
+ var browser$3 = { exports: {} }, ms, hasRequiredMs;
309
309
  function requireMs() {
310
310
  if (hasRequiredMs)
311
311
  return ms;
@@ -602,7 +602,7 @@
602
602
  return "[UnexpectedJSONParseError]: " + error.message;
603
603
  }
604
604
  };
605
- })(browser$1, browser$1.exports);
605
+ })(browser$3, browser$3.exports);
606
606
  const isBuffer = typeof Buffer > "u" ? () => !1 : (obj) => Buffer.isBuffer(obj);
607
607
  /*!
608
608
  * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
@@ -640,7 +640,7 @@
640
640
  function jsonResponse(opts) {
641
641
  return {
642
642
  onResponse: (response) => {
643
- const contentType = response.headers["content-type"] || "", shouldDecode = opts && opts.force || contentType.indexOf("application/json") !== -1;
643
+ const contentType = response.headers["content-type"] || "", shouldDecode = contentType.indexOf("application/json") !== -1;
644
644
  return !response.body || !contentType || !shouldDecode ? response : Object.assign({}, response, { body: tryParse(response.body) });
645
645
  },
646
646
  processOptions: (options) => Object.assign({}, options, {
@@ -697,10 +697,10 @@
697
697
  }
698
698
  };
699
699
  }
700
- var __defProp$5 = Object.defineProperty, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$5 = (obj, key, value) => (__defNormalProp$5(obj, typeof key != "symbol" ? key + "" : key, value), value);
700
+ var __defProp$4 = Object.defineProperty, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$4 = (obj, key, value) => (__defNormalProp$4(obj, typeof key != "symbol" ? key + "" : key, value), value);
701
701
  class Cancel {
702
702
  constructor(message) {
703
- __publicField$5(this, "__CANCEL__", !0), __publicField$5(this, "message"), this.message = message;
703
+ __publicField$4(this, "__CANCEL__", !0), __publicField$4(this, "message"), this.message = message;
704
704
  }
705
705
  toString() {
706
706
  return `Cancel${this.message ? `: ${this.message}` : ""}`;
@@ -708,7 +708,7 @@
708
708
  }
709
709
  const _CancelToken = class {
710
710
  constructor(executor) {
711
- if (__publicField$5(this, "promise"), __publicField$5(this, "reason"), typeof executor != "function")
711
+ if (__publicField$4(this, "promise"), __publicField$4(this, "reason"), typeof executor != "function")
712
712
  throw new TypeError("executor must be a function.");
713
713
  let resolvePromise = null;
714
714
  this.promise = new Promise((resolve) => {
@@ -718,7 +718,7 @@
718
718
  });
719
719
  }
720
720
  };
721
- __publicField$5(_CancelToken, "source", () => {
721
+ __publicField$4(_CancelToken, "source", () => {
722
722
  let cancel;
723
723
  return {
724
724
  token: new _CancelToken((can) => {
@@ -1656,142 +1656,8 @@
1656
1656
  });
1657
1657
  }
1658
1658
 
1659
- function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
1660
- if (delay === void 0) { delay = 0; }
1661
- if (repeat === void 0) { repeat = false; }
1662
- var scheduleSubscription = scheduler.schedule(function () {
1663
- work();
1664
- if (repeat) {
1665
- parentSubscription.add(this.schedule(null, delay));
1666
- }
1667
- else {
1668
- this.unsubscribe();
1669
- }
1670
- }, delay);
1671
- parentSubscription.add(scheduleSubscription);
1672
- if (!repeat) {
1673
- return scheduleSubscription;
1674
- }
1675
- }
1676
-
1677
- function observeOn(scheduler, delay) {
1678
- if (delay === void 0) { delay = 0; }
1679
- return operate(function (source, subscriber) {
1680
- source.subscribe(createOperatorSubscriber(subscriber, function (value) { return executeSchedule(subscriber, scheduler, function () { return subscriber.next(value); }, delay); }, function () { return executeSchedule(subscriber, scheduler, function () { return subscriber.complete(); }, delay); }, function (err) { return executeSchedule(subscriber, scheduler, function () { return subscriber.error(err); }, delay); }));
1681
- });
1682
- }
1683
-
1684
- function subscribeOn(scheduler, delay) {
1685
- if (delay === void 0) { delay = 0; }
1686
- return operate(function (source, subscriber) {
1687
- subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
1688
- });
1689
- }
1690
-
1691
- function scheduleObservable(input, scheduler) {
1692
- return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
1693
- }
1694
-
1695
- function schedulePromise(input, scheduler) {
1696
- return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
1697
- }
1698
-
1699
- function scheduleArray(input, scheduler) {
1700
- return new Observable(function (subscriber) {
1701
- var i = 0;
1702
- return scheduler.schedule(function () {
1703
- if (i === input.length) {
1704
- subscriber.complete();
1705
- }
1706
- else {
1707
- subscriber.next(input[i++]);
1708
- if (!subscriber.closed) {
1709
- this.schedule();
1710
- }
1711
- }
1712
- });
1713
- });
1714
- }
1715
-
1716
- function scheduleIterable(input, scheduler) {
1717
- return new Observable(function (subscriber) {
1718
- var iterator$1;
1719
- executeSchedule(subscriber, scheduler, function () {
1720
- iterator$1 = input[iterator]();
1721
- executeSchedule(subscriber, scheduler, function () {
1722
- var _a;
1723
- var value;
1724
- var done;
1725
- try {
1726
- (_a = iterator$1.next(), value = _a.value, done = _a.done);
1727
- }
1728
- catch (err) {
1729
- subscriber.error(err);
1730
- return;
1731
- }
1732
- if (done) {
1733
- subscriber.complete();
1734
- }
1735
- else {
1736
- subscriber.next(value);
1737
- }
1738
- }, 0, true);
1739
- });
1740
- return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
1741
- });
1742
- }
1743
-
1744
- function scheduleAsyncIterable(input, scheduler) {
1745
- if (!input) {
1746
- throw new Error('Iterable cannot be null');
1747
- }
1748
- return new Observable(function (subscriber) {
1749
- executeSchedule(subscriber, scheduler, function () {
1750
- var iterator = input[Symbol.asyncIterator]();
1751
- executeSchedule(subscriber, scheduler, function () {
1752
- iterator.next().then(function (result) {
1753
- if (result.done) {
1754
- subscriber.complete();
1755
- }
1756
- else {
1757
- subscriber.next(result.value);
1758
- }
1759
- });
1760
- }, 0, true);
1761
- });
1762
- });
1763
- }
1764
-
1765
- function scheduleReadableStreamLike(input, scheduler) {
1766
- return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
1767
- }
1768
-
1769
- function scheduled(input, scheduler) {
1770
- if (input != null) {
1771
- if (isInteropObservable(input)) {
1772
- return scheduleObservable(input, scheduler);
1773
- }
1774
- if (isArrayLike(input)) {
1775
- return scheduleArray(input, scheduler);
1776
- }
1777
- if (isPromise(input)) {
1778
- return schedulePromise(input, scheduler);
1779
- }
1780
- if (isAsyncIterable(input)) {
1781
- return scheduleAsyncIterable(input, scheduler);
1782
- }
1783
- if (isIterable(input)) {
1784
- return scheduleIterable(input, scheduler);
1785
- }
1786
- if (isReadableStreamLike(input)) {
1787
- return scheduleReadableStreamLike(input, scheduler);
1788
- }
1789
- }
1790
- throw createInvalidObservableTypeError(input);
1791
- }
1792
-
1793
1659
  function from(input, scheduler) {
1794
- return scheduler ? scheduled(input, scheduler) : innerFrom(input);
1660
+ return innerFrom(input);
1795
1661
  }
1796
1662
 
1797
1663
  var EmptyError = createErrorClass(function (_super) { return function EmptyErrorImpl() {
@@ -1801,7 +1667,6 @@
1801
1667
  }; });
1802
1668
 
1803
1669
  function lastValueFrom(source, config) {
1804
- var hasConfig = typeof config === 'object';
1805
1670
  return new Promise(function (resolve, reject) {
1806
1671
  var _hasValue = false;
1807
1672
  var _value;
@@ -1815,9 +1680,6 @@
1815
1680
  if (_hasValue) {
1816
1681
  resolve(_value);
1817
1682
  }
1818
- else if (hasConfig) {
1819
- resolve(config.defaultValue);
1820
- }
1821
1683
  else {
1822
1684
  reject(new EmptyError());
1823
1685
  }
@@ -1853,7 +1715,7 @@
1853
1715
  var remainingFirstValues = length;
1854
1716
  var _loop_1 = function (i) {
1855
1717
  maybeSchedule(scheduler, function () {
1856
- var source = from(observables[i], scheduler);
1718
+ var source = from(observables[i]);
1857
1719
  var hasFirstValue = false;
1858
1720
  source.subscribe(createOperatorSubscriber(subscriber, function (value) {
1859
1721
  values[i] = value;
@@ -1874,14 +1736,11 @@
1874
1736
  for (var i = 0; i < length; i++) {
1875
1737
  _loop_1(i);
1876
1738
  }
1877
- }, subscriber);
1739
+ });
1878
1740
  };
1879
1741
  }
1880
1742
  function maybeSchedule(scheduler, execute, subscription) {
1881
- if (scheduler) {
1882
- executeSchedule(subscription, scheduler, execute);
1883
- }
1884
- else {
1743
+ {
1885
1744
  execute();
1886
1745
  }
1887
1746
  }
@@ -1940,21 +1799,22 @@
1940
1799
  }
1941
1800
  return !0;
1942
1801
  }
1943
- function b(t, e, r = "auto") {
1802
+ function C(t, e, r = "auto") {
1944
1803
  return r === !0 || r === "auto" && (I(t) || x(t)) ? t : `${t}${E(e)}`;
1945
1804
  }
1946
1805
  Object.fromEntries(Object.entries(c).map((t) => t.reverse()));
1947
1806
  Object.fromEntries(Object.entries(s).map((t) => t.reverse()));
1948
- var S = `${Object.values(s).map((t) => `\\u{${t.toString(16)}}`).join("")}`, f = new RegExp(`[${S}]{4,}`, "gu");
1949
- function X(t) {
1807
+ var T = `${Object.values(s).map((t) => `\\u{${t.toString(16)}}`).join("")}`, f = new RegExp(`[${T}]{4,}`, "gu");
1808
+ function _(t) {
1950
1809
  var e;
1951
1810
  return { cleaned: t.replace(f, ""), encoded: ((e = t.match(f)) == null ? void 0 : e[0]) || "" };
1952
1811
  }
1953
- function vercelStegaCleanAll(result) {
1812
+ function O(t) {
1813
+ return JSON.parse(_(JSON.stringify(t)).cleaned);
1814
+ }
1815
+ function stegaClean(result) {
1954
1816
  try {
1955
- return JSON.parse(
1956
- JSON.stringify(result, (key, value) => typeof value != "string" ? value : X(value).cleaned)
1957
- );
1817
+ return O(result);
1958
1818
  } catch {
1959
1819
  return result;
1960
1820
  }
@@ -2107,7 +1967,7 @@ ${selectionOpts}`);
2107
1967
  if (member.has(obj))
2108
1968
  throw TypeError("Cannot add the same private member more than once");
2109
1969
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2110
- }, __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
1970
+ }, __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
2111
1971
  class BasePatch {
2112
1972
  constructor(selection, operations = {}) {
2113
1973
  __publicField$2(this, "selection"), __publicField$2(this, "operations"), this.selection = selection, this.operations = operations;
@@ -2292,7 +2152,7 @@ ${selectionOpts}`);
2292
2152
  if (member.has(obj))
2293
2153
  throw TypeError("Cannot add the same private member more than once");
2294
2154
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2295
- }, __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
2155
+ }, __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
2296
2156
  const defaultMutateOptions = { returnDocuments: !1 };
2297
2157
  class BaseTransaction {
2298
2158
  constructor(operations = [], transactionId) {
@@ -2563,7 +2423,7 @@ ${selectionOpts}`);
2563
2423
  const stega = "stega" in options ? {
2564
2424
  ..._stega || {},
2565
2425
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
2566
- } : _stega, params = stega.enabled ? vercelStegaCleanAll(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
2426
+ } : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
2567
2427
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
2568
2428
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
2569
2429
  useAbortSignal: typeof options.signal < "u",
@@ -2735,7 +2595,7 @@ ${selectionOpts}`);
2735
2595
  if (member.has(obj))
2736
2596
  throw TypeError("Cannot add the same private member more than once");
2737
2597
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2738
- }, __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value), _client$3, _httpRequest$4;
2598
+ }, __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value), _client$3, _httpRequest$4;
2739
2599
  class ObservableAssetsClient {
2740
2600
  constructor(client, httpRequest) {
2741
2601
  __privateAdd$4(this, _client$3, void 0), __privateAdd$4(this, _httpRequest$4, void 0), __privateSet$4(this, _client$3, client), __privateSet$4(this, _httpRequest$4, httpRequest);
@@ -2839,7 +2699,7 @@ ${selectionOpts}`);
2839
2699
  shouldEmitReconnect && observer.next({ type: "reconnect" });
2840
2700
  }
2841
2701
  async function getEventSource() {
2842
- const { EventSource } = await Promise.resolve().then(function () { return browser; }), evs = new EventSource(uri, esOptions);
2702
+ const { default: EventSource } = await Promise.resolve().then(function () { return browser$2; }), evs = new EventSource(uri, esOptions);
2843
2703
  return evs.addEventListener("error", onError), evs.addEventListener("channelError", onChannelError), evs.addEventListener("disconnect", onDisconnect), listenFor.forEach((type) => evs.addEventListener(type, onMessage)), evs;
2844
2704
  }
2845
2705
  function open() {
@@ -2879,7 +2739,7 @@ ${selectionOpts}`);
2879
2739
  if (member.has(obj))
2880
2740
  throw TypeError("Cannot add the same private member more than once");
2881
2741
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2882
- }, __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value), _client$2, _httpRequest$3;
2742
+ }, __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value), _client$2, _httpRequest$3;
2883
2743
  class ObservableDatasetsClient {
2884
2744
  constructor(client, httpRequest) {
2885
2745
  __privateAdd$3(this, _client$2, void 0), __privateAdd$3(this, _httpRequest$3, void 0), __privateSet$3(this, _client$2, client), __privateSet$3(this, _httpRequest$3, httpRequest);
@@ -2981,7 +2841,7 @@ ${selectionOpts}`);
2981
2841
  if (member.has(obj))
2982
2842
  throw TypeError("Cannot add the same private member more than once");
2983
2843
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2984
- }, __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value), _client$1, _httpRequest$2;
2844
+ }, __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value), _client$1, _httpRequest$2;
2985
2845
  class ObservableProjectsClient {
2986
2846
  constructor(client, httpRequest) {
2987
2847
  __privateAdd$2(this, _client$1, void 0), __privateAdd$2(this, _httpRequest$2, void 0), __privateSet$2(this, _client$1, client), __privateSet$2(this, _httpRequest$2, httpRequest);
@@ -3028,7 +2888,7 @@ ${selectionOpts}`);
3028
2888
  if (member.has(obj))
3029
2889
  throw TypeError("Cannot add the same private member more than once");
3030
2890
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3031
- }, __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value), _client, _httpRequest$1;
2891
+ }, __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value), _client, _httpRequest$1;
3032
2892
  class ObservableUsersClient {
3033
2893
  constructor(client, httpRequest) {
3034
2894
  __privateAdd$1(this, _client, void 0), __privateAdd$1(this, _httpRequest$1, void 0), __privateSet$1(this, _client, client), __privateSet$1(this, _httpRequest$1, httpRequest);
@@ -3066,32 +2926,32 @@ ${selectionOpts}`);
3066
2926
  }
3067
2927
  }
3068
2928
  _client2 = /* @__PURE__ */ new WeakMap(), _httpRequest2$1 = /* @__PURE__ */ new WeakMap();
3069
- var __defProp$4 = Object.defineProperty, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$4 = (obj, key, value) => (__defNormalProp$4(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$7 = (obj, member, msg) => {
2929
+ var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => (__defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck = (obj, member, msg) => {
3070
2930
  if (!member.has(obj))
3071
2931
  throw TypeError("Cannot " + msg);
3072
- }, __privateGet$7 = (obj, member, getter) => (__accessCheck$7(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$7 = (obj, member, value) => {
2932
+ }, __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd = (obj, member, value) => {
3073
2933
  if (member.has(obj))
3074
2934
  throw TypeError("Cannot add the same private member more than once");
3075
2935
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3076
- }, __privateSet$7 = (obj, member, value, setter) => (__accessCheck$7(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value), _clientConfig, _httpRequest;
2936
+ }, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), _clientConfig, _httpRequest;
3077
2937
  const _ObservableSanityClient = class _ObservableSanityClient2 {
3078
2938
  constructor(httpRequest, config = defaultConfig) {
3079
- __publicField$4(this, "assets"), __publicField$4(this, "datasets"), __publicField$4(this, "projects"), __publicField$4(this, "users"), __privateAdd$7(this, _clientConfig, void 0), __privateAdd$7(this, _httpRequest, void 0), __publicField$4(this, "listen", _listen), this.config(config), __privateSet$7(this, _httpRequest, httpRequest), this.assets = new ObservableAssetsClient(this, __privateGet$7(this, _httpRequest)), this.datasets = new ObservableDatasetsClient(this, __privateGet$7(this, _httpRequest)), this.projects = new ObservableProjectsClient(this, __privateGet$7(this, _httpRequest)), this.users = new ObservableUsersClient(this, __privateGet$7(this, _httpRequest));
2939
+ __publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "projects"), __publicField(this, "users"), __privateAdd(this, _clientConfig, void 0), __privateAdd(this, _httpRequest, void 0), __publicField(this, "listen", _listen), this.config(config), __privateSet(this, _httpRequest, httpRequest), this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest)), this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest)), this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest)), this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
3080
2940
  }
3081
2941
  /**
3082
2942
  * Clone the client - returns a new instance
3083
2943
  */
3084
2944
  clone() {
3085
- return new _ObservableSanityClient2(__privateGet$7(this, _httpRequest), this.config());
2945
+ return new _ObservableSanityClient2(__privateGet(this, _httpRequest), this.config());
3086
2946
  }
3087
2947
  config(newConfig) {
3088
2948
  if (newConfig === void 0)
3089
- return { ...__privateGet$7(this, _clientConfig) };
3090
- if (__privateGet$7(this, _clientConfig) && __privateGet$7(this, _clientConfig).allowReconfigure === !1)
2949
+ return { ...__privateGet(this, _clientConfig) };
2950
+ if (__privateGet(this, _clientConfig) && __privateGet(this, _clientConfig).allowReconfigure === !1)
3091
2951
  throw new Error(
3092
2952
  "Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
3093
2953
  );
3094
- return __privateSet$7(this, _clientConfig, initConfig(newConfig, __privateGet$7(this, _clientConfig) || {})), this;
2954
+ return __privateSet(this, _clientConfig, initConfig(newConfig, __privateGet(this, _clientConfig) || {})), this;
3095
2955
  }
3096
2956
  /**
3097
2957
  * Clone the client with a new (partial) configuration.
@@ -3100,7 +2960,7 @@ ${selectionOpts}`);
3100
2960
  */
3101
2961
  withConfig(newConfig) {
3102
2962
  const thisConfig = this.config();
3103
- return new _ObservableSanityClient2(__privateGet$7(this, _httpRequest), {
2963
+ return new _ObservableSanityClient2(__privateGet(this, _httpRequest), {
3104
2964
  ...thisConfig,
3105
2965
  ...newConfig,
3106
2966
  stega: {
@@ -3112,8 +2972,8 @@ ${selectionOpts}`);
3112
2972
  fetch(query, params, options) {
3113
2973
  return _fetch(
3114
2974
  this,
3115
- __privateGet$7(this, _httpRequest),
3116
- __privateGet$7(this, _clientConfig).stega,
2975
+ __privateGet(this, _httpRequest),
2976
+ __privateGet(this, _clientConfig).stega,
3117
2977
  query,
3118
2978
  params,
3119
2979
  options
@@ -3126,7 +2986,7 @@ ${selectionOpts}`);
3126
2986
  * @param options - Request options
3127
2987
  */
3128
2988
  getDocument(id, options) {
3129
- return _getDocument(this, __privateGet$7(this, _httpRequest), id, options);
2989
+ return _getDocument(this, __privateGet(this, _httpRequest), id, options);
3130
2990
  }
3131
2991
  /**
3132
2992
  * Fetch multiple documents in one request.
@@ -3138,22 +2998,22 @@ ${selectionOpts}`);
3138
2998
  * @param options - Request options
3139
2999
  */
3140
3000
  getDocuments(ids, options) {
3141
- return _getDocuments(this, __privateGet$7(this, _httpRequest), ids, options);
3001
+ return _getDocuments(this, __privateGet(this, _httpRequest), ids, options);
3142
3002
  }
3143
3003
  create(document, options) {
3144
- return _create(this, __privateGet$7(this, _httpRequest), document, "create", options);
3004
+ return _create(this, __privateGet(this, _httpRequest), document, "create", options);
3145
3005
  }
3146
3006
  createIfNotExists(document, options) {
3147
- return _createIfNotExists(this, __privateGet$7(this, _httpRequest), document, options);
3007
+ return _createIfNotExists(this, __privateGet(this, _httpRequest), document, options);
3148
3008
  }
3149
3009
  createOrReplace(document, options) {
3150
- return _createOrReplace(this, __privateGet$7(this, _httpRequest), document, options);
3010
+ return _createOrReplace(this, __privateGet(this, _httpRequest), document, options);
3151
3011
  }
3152
3012
  delete(selection, options) {
3153
- return _delete(this, __privateGet$7(this, _httpRequest), selection, options);
3013
+ return _delete(this, __privateGet(this, _httpRequest), selection, options);
3154
3014
  }
3155
3015
  mutate(operations, options) {
3156
- return _mutate(this, __privateGet$7(this, _httpRequest), operations, options);
3016
+ return _mutate(this, __privateGet(this, _httpRequest), operations, options);
3157
3017
  }
3158
3018
  /**
3159
3019
  * Create a new buildable patch of operations to perform
@@ -3179,7 +3039,7 @@ ${selectionOpts}`);
3179
3039
  * @param options - Request options
3180
3040
  */
3181
3041
  request(options) {
3182
- return _request(this, __privateGet$7(this, _httpRequest), options);
3042
+ return _request(this, __privateGet(this, _httpRequest), options);
3183
3043
  }
3184
3044
  /**
3185
3045
  * Get a Sanity API URL for the URI provided
@@ -3205,22 +3065,22 @@ ${selectionOpts}`);
3205
3065
  var _clientConfig2, _httpRequest2;
3206
3066
  const _SanityClient = class _SanityClient2 {
3207
3067
  constructor(httpRequest, config = defaultConfig) {
3208
- __publicField$4(this, "assets"), __publicField$4(this, "datasets"), __publicField$4(this, "projects"), __publicField$4(this, "users"), __publicField$4(this, "observable"), __privateAdd$7(this, _clientConfig2, void 0), __privateAdd$7(this, _httpRequest2, void 0), __publicField$4(this, "listen", _listen), this.config(config), __privateSet$7(this, _httpRequest2, httpRequest), this.assets = new AssetsClient(this, __privateGet$7(this, _httpRequest2)), this.datasets = new DatasetsClient(this, __privateGet$7(this, _httpRequest2)), this.projects = new ProjectsClient(this, __privateGet$7(this, _httpRequest2)), this.users = new UsersClient(this, __privateGet$7(this, _httpRequest2)), this.observable = new ObservableSanityClient(httpRequest, config);
3068
+ __publicField(this, "assets"), __publicField(this, "datasets"), __publicField(this, "projects"), __publicField(this, "users"), __publicField(this, "observable"), __privateAdd(this, _clientConfig2, void 0), __privateAdd(this, _httpRequest2, void 0), __publicField(this, "listen", _listen), this.config(config), __privateSet(this, _httpRequest2, httpRequest), this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2)), this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2)), this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2)), this.users = new UsersClient(this, __privateGet(this, _httpRequest2)), this.observable = new ObservableSanityClient(httpRequest, config);
3209
3069
  }
3210
3070
  /**
3211
3071
  * Clone the client - returns a new instance
3212
3072
  */
3213
3073
  clone() {
3214
- return new _SanityClient2(__privateGet$7(this, _httpRequest2), this.config());
3074
+ return new _SanityClient2(__privateGet(this, _httpRequest2), this.config());
3215
3075
  }
3216
3076
  config(newConfig) {
3217
3077
  if (newConfig === void 0)
3218
- return { ...__privateGet$7(this, _clientConfig2) };
3219
- if (__privateGet$7(this, _clientConfig2) && __privateGet$7(this, _clientConfig2).allowReconfigure === !1)
3078
+ return { ...__privateGet(this, _clientConfig2) };
3079
+ if (__privateGet(this, _clientConfig2) && __privateGet(this, _clientConfig2).allowReconfigure === !1)
3220
3080
  throw new Error(
3221
3081
  "Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
3222
3082
  );
3223
- return this.observable && this.observable.config(newConfig), __privateSet$7(this, _clientConfig2, initConfig(newConfig, __privateGet$7(this, _clientConfig2) || {})), this;
3083
+ return this.observable && this.observable.config(newConfig), __privateSet(this, _clientConfig2, initConfig(newConfig, __privateGet(this, _clientConfig2) || {})), this;
3224
3084
  }
3225
3085
  /**
3226
3086
  * Clone the client with a new (partial) configuration.
@@ -3229,7 +3089,7 @@ ${selectionOpts}`);
3229
3089
  */
3230
3090
  withConfig(newConfig) {
3231
3091
  const thisConfig = this.config();
3232
- return new _SanityClient2(__privateGet$7(this, _httpRequest2), {
3092
+ return new _SanityClient2(__privateGet(this, _httpRequest2), {
3233
3093
  ...thisConfig,
3234
3094
  ...newConfig,
3235
3095
  stega: {
@@ -3242,8 +3102,8 @@ ${selectionOpts}`);
3242
3102
  return lastValueFrom(
3243
3103
  _fetch(
3244
3104
  this,
3245
- __privateGet$7(this, _httpRequest2),
3246
- __privateGet$7(this, _clientConfig2).stega,
3105
+ __privateGet(this, _httpRequest2),
3106
+ __privateGet(this, _clientConfig2).stega,
3247
3107
  query,
3248
3108
  params,
3249
3109
  options
@@ -3257,7 +3117,7 @@ ${selectionOpts}`);
3257
3117
  * @param options - Request options
3258
3118
  */
3259
3119
  getDocument(id, options) {
3260
- return lastValueFrom(_getDocument(this, __privateGet$7(this, _httpRequest2), id, options));
3120
+ return lastValueFrom(_getDocument(this, __privateGet(this, _httpRequest2), id, options));
3261
3121
  }
3262
3122
  /**
3263
3123
  * Fetch multiple documents in one request.
@@ -3269,28 +3129,28 @@ ${selectionOpts}`);
3269
3129
  * @param options - Request options
3270
3130
  */
3271
3131
  getDocuments(ids, options) {
3272
- return lastValueFrom(_getDocuments(this, __privateGet$7(this, _httpRequest2), ids, options));
3132
+ return lastValueFrom(_getDocuments(this, __privateGet(this, _httpRequest2), ids, options));
3273
3133
  }
3274
3134
  create(document, options) {
3275
3135
  return lastValueFrom(
3276
- _create(this, __privateGet$7(this, _httpRequest2), document, "create", options)
3136
+ _create(this, __privateGet(this, _httpRequest2), document, "create", options)
3277
3137
  );
3278
3138
  }
3279
3139
  createIfNotExists(document, options) {
3280
3140
  return lastValueFrom(
3281
- _createIfNotExists(this, __privateGet$7(this, _httpRequest2), document, options)
3141
+ _createIfNotExists(this, __privateGet(this, _httpRequest2), document, options)
3282
3142
  );
3283
3143
  }
3284
3144
  createOrReplace(document, options) {
3285
3145
  return lastValueFrom(
3286
- _createOrReplace(this, __privateGet$7(this, _httpRequest2), document, options)
3146
+ _createOrReplace(this, __privateGet(this, _httpRequest2), document, options)
3287
3147
  );
3288
3148
  }
3289
3149
  delete(selection, options) {
3290
- return lastValueFrom(_delete(this, __privateGet$7(this, _httpRequest2), selection, options));
3150
+ return lastValueFrom(_delete(this, __privateGet(this, _httpRequest2), selection, options));
3291
3151
  }
3292
3152
  mutate(operations, options) {
3293
- return lastValueFrom(_mutate(this, __privateGet$7(this, _httpRequest2), operations, options));
3153
+ return lastValueFrom(_mutate(this, __privateGet(this, _httpRequest2), operations, options));
3294
3154
  }
3295
3155
  /**
3296
3156
  * Create a new buildable patch of operations to perform
@@ -3318,7 +3178,7 @@ ${selectionOpts}`);
3318
3178
  * @returns Promise resolving to the response body
3319
3179
  */
3320
3180
  request(options) {
3321
- return lastValueFrom(_request(this, __privateGet$7(this, _httpRequest2), options));
3181
+ return lastValueFrom(_request(this, __privateGet(this, _httpRequest2), options));
3322
3182
  }
3323
3183
  /**
3324
3184
  * Perform an HTTP request a `/data` sub-endpoint
@@ -3331,7 +3191,7 @@ ${selectionOpts}`);
3331
3191
  * @internal
3332
3192
  */
3333
3193
  dataRequest(endpoint, body, options) {
3334
- return lastValueFrom(_dataRequest(this, __privateGet$7(this, _httpRequest2), endpoint, body, options));
3194
+ return lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
3335
3195
  }
3336
3196
  /**
3337
3197
  * Get a Sanity API URL for the URI provided
@@ -3659,7 +3519,7 @@ ${selectionOpts}`);
3659
3519
  if (!baseUrl)
3660
3520
  return value;
3661
3521
  const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
3662
- return b(
3522
+ return C(
3663
3523
  value,
3664
3524
  {
3665
3525
  origin: "sanity.io",
@@ -3708,239 +3568,1067 @@ ${selectionOpts}`);
3708
3568
  s: stegaEncodeSourceMap
3709
3569
  });
3710
3570
 
3711
- var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => (__defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck = (obj, member, msg) => {
3712
- if (!member.has(obj))
3713
- throw TypeError("Cannot " + msg);
3714
- }, __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd = (obj, member, value) => {
3715
- if (member.has(obj))
3716
- throw TypeError("Cannot add the same private member more than once");
3717
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3718
- }, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
3719
- /** @license
3720
- * eventsource.js
3721
- * Available under MIT License (MIT)
3722
- * https://github.com/Yaffle/EventSource/
3723
- */
3724
- const contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
3725
- class FetchTransport {
3726
- open(onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
3727
- let reader = null;
3728
- const controller = new AbortController(), { signal } = controller, textDecoder = new TextDecoder();
3729
- return fetch(url, {
3730
- headers,
3731
- credentials: withCredentials ? "include" : "same-origin",
3732
- signal,
3733
- cache: "no-store"
3734
- }).then(function(response) {
3735
- return reader = response.body.getReader(), onStartCallback(
3736
- response.status,
3737
- response.statusText,
3738
- response.headers.get("Content-Type"),
3739
- response.headers
3740
- ), new Promise(function(resolve, reject) {
3741
- let readNextChunk = function() {
3742
- reader.read().then(function(result) {
3743
- if (result.done)
3744
- resolve(void 0);
3745
- else {
3746
- let chunk = textDecoder.decode(result.value, { stream: !0 });
3747
- onProgressCallback(chunk), readNextChunk();
3748
- }
3749
- }).catch(function(error) {
3750
- reject(error);
3751
- });
3752
- };
3753
- readNextChunk();
3754
- });
3755
- }).catch(function(error) {
3756
- if (error.name !== "AbortError")
3757
- return error;
3758
- }).then(function(error) {
3759
- onFinishCallback(error);
3760
- }), {
3761
- signal,
3762
- abort: function() {
3763
- reader != null && reader.cancel(), controller.abort();
3764
- }
3765
- };
3766
- }
3767
- }
3768
- class ConnectionEvent extends Event {
3769
- constructor(type, options) {
3770
- super(type), __publicField(this, "status"), __publicField(this, "statusText"), __publicField(this, "headers"), this.status = options.status, this.statusText = options.statusText, this.headers = options.headers;
3771
- }
3772
- }
3773
- function parseDuration(value, def) {
3774
- let n = value == null ? def : parseInt(value, 10);
3775
- return n !== n && (n = def), clampDuration(n);
3776
- }
3777
- function clampDuration(n) {
3778
- return Math.min(Math.max(n, 1e3), 18e6);
3779
- }
3780
- var _readyState, _url, _withCredentials;
3781
- class EventSource extends EventTarget {
3782
- constructor(url, options = {}) {
3783
- super(), __publicField(this, "onerror", null), __publicField(this, "onmessage", null), __publicField(this, "onopen", null), __publicField(this, "CLOSED", 2), __publicField(this, "CONNECTING", 0), __publicField(this, "OPEN", 1), __privateAdd(this, _readyState, 0), __privateAdd(this, _url, void 0), __privateAdd(this, _withCredentials, void 0);
3784
- const { headers = {} } = options;
3785
- __privateSet(this, _url, String(url)), __privateSet(this, _withCredentials, !!options.withCredentials), __privateSet(this, _readyState, 0);
3786
- const lastEventIdQueryParameterName = "lastEventId";
3787
- let initialRetry = clampDuration(1e3), heartbeatTimeout = parseDuration(null, 45e3), lastEventId = "", retry = initialRetry, wasActivity = !1, textLength = 0;
3788
- const transport = new FetchTransport();
3789
- let abortController, timeout = 0, currentState = -1, dataBuffer = "", lastEventIdBuffer = "", eventTypeBuffer = "", textBuffer = "", state = 0, fieldStart = 0, valueStart = 0;
3790
- const fire = (listener, event) => {
3791
- try {
3792
- typeof listener == "function" && listener.call(this, event);
3793
- } catch (e) {
3794
- setTimeout(function() {
3795
- throw e;
3796
- }, 0);
3797
- }
3798
- }, onStart = (status, statusText, contentType, responseHeaders) => {
3799
- if (currentState === 0)
3800
- if (status === 200 && contentType != null && contentTypeRegExp.test(contentType)) {
3801
- currentState = 1, wasActivity = Date.now(), retry = initialRetry, __privateSet(this, _readyState, 1);
3802
- let event = new ConnectionEvent("open", {
3803
- status,
3804
- statusText,
3805
- headers: responseHeaders
3806
- });
3807
- this.dispatchEvent(event), fire(this.onopen, event);
3808
- } else {
3809
- let message = "";
3810
- status !== 200 ? (statusText && (statusText = statusText.replace(/\s+/g, " ")), message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.") : message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == null ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.", close();
3811
- let event = new ConnectionEvent("error", {
3812
- status,
3813
- statusText,
3814
- headers: responseHeaders
3815
- });
3816
- this.dispatchEvent(event), fire(this.onerror, event), console.error(message);
3817
- }
3818
- };
3819
- let onProgress = (textChunk) => {
3820
- if (currentState === 1) {
3821
- let n = -1;
3822
- for (let i = 0; i < textChunk.length; i += 1) {
3823
- var c = textChunk.charCodeAt(i);
3824
- (c === 10 || c === 13) && (n = i);
3825
- }
3826
- let chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
3827
- textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1), textChunk !== "" && (wasActivity = Date.now(), textLength += textChunk.length);
3828
- for (let position = 0; position < chunk.length; position += 1) {
3829
- let c2 = chunk.charCodeAt(position);
3830
- if (state === -1 && c2 === 10)
3831
- state = 0;
3832
- else if (state === -1 && (state = 0), c2 === 13 || c2 === 10) {
3833
- if (state !== 0) {
3834
- state === 1 && (valueStart = position + 1);
3835
- let field = chunk.slice(fieldStart, valueStart - 1), value = chunk.slice(
3836
- valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === 32 ? 1 : 0),
3837
- position
3838
- );
3839
- field === "data" ? (dataBuffer += `
3840
- `, dataBuffer += value) : field === "id" ? lastEventIdBuffer = value : field === "event" ? eventTypeBuffer = value : field === "retry" ? (initialRetry = parseDuration(value, initialRetry), retry = initialRetry) : field === "heartbeatTimeout" && (heartbeatTimeout = parseDuration(value, heartbeatTimeout), timeout !== 0 && (clearTimeout(timeout), timeout = setTimeout(function() {
3841
- onTimeout();
3842
- }, heartbeatTimeout)));
3843
- }
3844
- if (state === 0) {
3845
- if (dataBuffer !== "") {
3846
- lastEventId = lastEventIdBuffer, eventTypeBuffer === "" && (eventTypeBuffer = "message");
3847
- let event = new MessageEvent(eventTypeBuffer, {
3848
- data: dataBuffer.slice(1),
3849
- lastEventId: lastEventIdBuffer
3850
- });
3851
- if (this.dispatchEvent(event), eventTypeBuffer === "open" ? fire(this.onopen, event) : eventTypeBuffer === "message" ? fire(this.onmessage, event) : eventTypeBuffer === "error" && fire(this.onerror, event), currentState === 2)
3852
- return;
3853
- }
3854
- dataBuffer = "", eventTypeBuffer = "";
3855
- }
3856
- state = c2 === 13 ? -1 : 0;
3857
- } else
3858
- state === 0 && (fieldStart = position, state = 1), state === 1 ? c2 === 58 && (valueStart = position + 1, state = 2) : state === 2 && (state = 3);
3859
- }
3860
- }
3861
- };
3862
- const onFinish = (error) => {
3863
- if (currentState === 1 || currentState === 0) {
3864
- currentState = -1, timeout !== 0 && (clearTimeout(timeout), timeout = 0), timeout = setTimeout(function() {
3865
- onTimeout();
3866
- }, retry), retry = clampDuration(Math.min(initialRetry * 16, retry * 2)), __privateSet(this, _readyState, 0);
3867
- var event = new ErrorEvent("error", { error });
3868
- this.dispatchEvent(event), fire(this.onerror, event), error != null && console.error(error);
3869
- }
3870
- };
3871
- let onTimeout = () => {
3872
- if (timeout = 0, currentState !== -1) {
3873
- if (!wasActivity && abortController != null)
3874
- onFinish(
3875
- new Error(
3876
- "No activity within " + heartbeatTimeout + " milliseconds. " + (currentState === 0 ? "No response received." : textLength + " chars received.") + " Reconnecting."
3877
- )
3878
- ), abortController != null && (abortController.abort(), abortController = void 0);
3879
- else {
3880
- var nextHeartbeat = Math.max(
3881
- (wasActivity !== !1 ? wasActivity : Date.now()) + heartbeatTimeout - Date.now(),
3882
- 1
3883
- );
3884
- wasActivity = !1, timeout = setTimeout(function() {
3885
- onTimeout();
3886
- }, nextHeartbeat);
3887
- }
3888
- return;
3889
- }
3890
- wasActivity = !1, textLength = 0, timeout = setTimeout(function() {
3891
- onTimeout();
3892
- }, heartbeatTimeout), currentState = 0, dataBuffer = "", eventTypeBuffer = "", lastEventIdBuffer = lastEventId, textBuffer = "", fieldStart = 0, valueStart = 0, state = 0;
3893
- let requestURL = url;
3894
- if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:" && lastEventId !== "") {
3895
- var i = url.indexOf("?");
3896
- requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function(p, paramName) {
3897
- return paramName === lastEventIdQueryParameterName ? "" : p;
3898
- }), requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName + "=" + encodeURIComponent(lastEventId);
3899
- }
3900
- let requestHeaders = {};
3901
- if (requestHeaders.Accept = "text/event-stream", headers != null)
3902
- for (let name in headers)
3903
- Object.prototype.hasOwnProperty.call(headers, name) && (requestHeaders[name] = headers[name]);
3904
- try {
3905
- abortController = transport.open(
3906
- onStart,
3907
- onProgress,
3908
- onFinish,
3909
- requestURL,
3910
- this.withCredentials,
3911
- requestHeaders
3912
- );
3913
- } catch (error) {
3914
- throw close(), error;
3915
- }
3916
- };
3917
- onTimeout(), this.close = () => {
3918
- currentState = 2, abortController != null && (abortController.abort(), abortController = void 0), timeout !== 0 && (clearTimeout(timeout), timeout = 0), __privateSet(this, _readyState, 2);
3919
- };
3920
- }
3921
- get readyState() {
3922
- return __privateGet(this, _readyState);
3923
- }
3924
- get url() {
3925
- return __privateGet(this, _url);
3926
- }
3927
- get withCredentials() {
3928
- return __privateGet(this, _withCredentials);
3929
- }
3930
- close() {
3931
- }
3932
- addEventListener(type, listener, options) {
3933
- super.addEventListener(type, listener, options);
3934
- }
3935
- removeEventListener(type, listener, options) {
3936
- super.removeEventListener(type, listener, options);
3937
- }
3571
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3572
+
3573
+ function getDefaultExportFromCjs (x) {
3574
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3938
3575
  }
3939
- _readyState = /* @__PURE__ */ new WeakMap(), _url = /* @__PURE__ */ new WeakMap(), _withCredentials = /* @__PURE__ */ new WeakMap(), __publicField(EventSource, "CLOSED", 2), __publicField(EventSource, "CONNECTING", 0), __publicField(EventSource, "OPEN", 1);
3940
3576
 
3941
- var browser = /*#__PURE__*/Object.freeze({
3577
+ var eventsource = {exports: {}};
3578
+
3579
+ /** @license
3580
+ * eventsource.js
3581
+ * Available under MIT License (MIT)
3582
+ * https://github.com/Yaffle/EventSource/
3583
+ */
3584
+
3585
+ (function (module, exports) {
3586
+ /*jslint indent: 2, vars: true, plusplus: true */
3587
+ /*global setTimeout, clearTimeout */
3588
+
3589
+ (function (global) {
3590
+
3591
+ var setTimeout = global.setTimeout;
3592
+ var clearTimeout = global.clearTimeout;
3593
+ var XMLHttpRequest = global.XMLHttpRequest;
3594
+ var XDomainRequest = global.XDomainRequest;
3595
+ var ActiveXObject = global.ActiveXObject;
3596
+ var NativeEventSource = global.EventSource;
3597
+
3598
+ var document = global.document;
3599
+ var Promise = global.Promise;
3600
+ var fetch = global.fetch;
3601
+ var Response = global.Response;
3602
+ var TextDecoder = global.TextDecoder;
3603
+ var TextEncoder = global.TextEncoder;
3604
+ var AbortController = global.AbortController;
3605
+
3606
+ if (typeof window !== "undefined" && typeof document !== "undefined" && !("readyState" in document) && document.body == null) { // Firefox 2
3607
+ document.readyState = "loading";
3608
+ window.addEventListener("load", function (event) {
3609
+ document.readyState = "complete";
3610
+ }, false);
3611
+ }
3612
+
3613
+ if (XMLHttpRequest == null && ActiveXObject != null) { // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest_in_IE6
3614
+ XMLHttpRequest = function () {
3615
+ return new ActiveXObject("Microsoft.XMLHTTP");
3616
+ };
3617
+ }
3618
+
3619
+ if (Object.create == undefined) {
3620
+ Object.create = function (C) {
3621
+ function F(){}
3622
+ F.prototype = C;
3623
+ return new F();
3624
+ };
3625
+ }
3626
+
3627
+ if (!Date.now) {
3628
+ Date.now = function now() {
3629
+ return new Date().getTime();
3630
+ };
3631
+ }
3632
+
3633
+ // see #118 (Promise#finally with polyfilled Promise)
3634
+ // see #123 (data URLs crash Edge)
3635
+ // see #125 (CSP violations)
3636
+ // see pull/#138
3637
+ // => No way to polyfill Promise#finally
3638
+
3639
+ if (AbortController == undefined) {
3640
+ var originalFetch2 = fetch;
3641
+ fetch = function (url, options) {
3642
+ var signal = options.signal;
3643
+ return originalFetch2(url, {headers: options.headers, credentials: options.credentials, cache: options.cache}).then(function (response) {
3644
+ var reader = response.body.getReader();
3645
+ signal._reader = reader;
3646
+ if (signal._aborted) {
3647
+ signal._reader.cancel();
3648
+ }
3649
+ return {
3650
+ status: response.status,
3651
+ statusText: response.statusText,
3652
+ headers: response.headers,
3653
+ body: {
3654
+ getReader: function () {
3655
+ return reader;
3656
+ }
3657
+ }
3658
+ };
3659
+ });
3660
+ };
3661
+ AbortController = function () {
3662
+ this.signal = {
3663
+ _reader: null,
3664
+ _aborted: false
3665
+ };
3666
+ this.abort = function () {
3667
+ if (this.signal._reader != null) {
3668
+ this.signal._reader.cancel();
3669
+ }
3670
+ this.signal._aborted = true;
3671
+ };
3672
+ };
3673
+ }
3674
+
3675
+ function TextDecoderPolyfill() {
3676
+ this.bitsNeeded = 0;
3677
+ this.codePoint = 0;
3678
+ }
3679
+
3680
+ TextDecoderPolyfill.prototype.decode = function (octets) {
3681
+ function valid(codePoint, shift, octetsCount) {
3682
+ if (octetsCount === 1) {
3683
+ return codePoint >= 0x0080 >> shift && codePoint << shift <= 0x07FF;
3684
+ }
3685
+ if (octetsCount === 2) {
3686
+ return codePoint >= 0x0800 >> shift && codePoint << shift <= 0xD7FF || codePoint >= 0xE000 >> shift && codePoint << shift <= 0xFFFF;
3687
+ }
3688
+ if (octetsCount === 3) {
3689
+ return codePoint >= 0x010000 >> shift && codePoint << shift <= 0x10FFFF;
3690
+ }
3691
+ throw new Error();
3692
+ }
3693
+ function octetsCount(bitsNeeded, codePoint) {
3694
+ if (bitsNeeded === 6 * 1) {
3695
+ return codePoint >> 6 > 15 ? 3 : codePoint > 31 ? 2 : 1;
3696
+ }
3697
+ if (bitsNeeded === 6 * 2) {
3698
+ return codePoint > 15 ? 3 : 2;
3699
+ }
3700
+ if (bitsNeeded === 6 * 3) {
3701
+ return 3;
3702
+ }
3703
+ throw new Error();
3704
+ }
3705
+ var REPLACER = 0xFFFD;
3706
+ var string = "";
3707
+ var bitsNeeded = this.bitsNeeded;
3708
+ var codePoint = this.codePoint;
3709
+ for (var i = 0; i < octets.length; i += 1) {
3710
+ var octet = octets[i];
3711
+ if (bitsNeeded !== 0) {
3712
+ if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
3713
+ bitsNeeded = 0;
3714
+ codePoint = REPLACER;
3715
+ string += String.fromCharCode(codePoint);
3716
+ }
3717
+ }
3718
+ if (bitsNeeded === 0) {
3719
+ if (octet >= 0 && octet <= 127) {
3720
+ bitsNeeded = 0;
3721
+ codePoint = octet;
3722
+ } else if (octet >= 192 && octet <= 223) {
3723
+ bitsNeeded = 6 * 1;
3724
+ codePoint = octet & 31;
3725
+ } else if (octet >= 224 && octet <= 239) {
3726
+ bitsNeeded = 6 * 2;
3727
+ codePoint = octet & 15;
3728
+ } else if (octet >= 240 && octet <= 247) {
3729
+ bitsNeeded = 6 * 3;
3730
+ codePoint = octet & 7;
3731
+ } else {
3732
+ bitsNeeded = 0;
3733
+ codePoint = REPLACER;
3734
+ }
3735
+ if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
3736
+ bitsNeeded = 0;
3737
+ codePoint = REPLACER;
3738
+ }
3739
+ } else {
3740
+ bitsNeeded -= 6;
3741
+ codePoint = codePoint << 6 | octet & 63;
3742
+ }
3743
+ if (bitsNeeded === 0) {
3744
+ if (codePoint <= 0xFFFF) {
3745
+ string += String.fromCharCode(codePoint);
3746
+ } else {
3747
+ string += String.fromCharCode(0xD800 + (codePoint - 0xFFFF - 1 >> 10));
3748
+ string += String.fromCharCode(0xDC00 + (codePoint - 0xFFFF - 1 & 0x3FF));
3749
+ }
3750
+ }
3751
+ }
3752
+ this.bitsNeeded = bitsNeeded;
3753
+ this.codePoint = codePoint;
3754
+ return string;
3755
+ };
3756
+
3757
+ // Firefox < 38 throws an error with stream option
3758
+ var supportsStreamOption = function () {
3759
+ try {
3760
+ return new TextDecoder().decode(new TextEncoder().encode("test"), {stream: true}) === "test";
3761
+ } catch (error) {
3762
+ console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
3763
+ }
3764
+ return false;
3765
+ };
3766
+
3767
+ // IE, Edge
3768
+ if (TextDecoder == undefined || TextEncoder == undefined || !supportsStreamOption()) {
3769
+ TextDecoder = TextDecoderPolyfill;
3770
+ }
3771
+
3772
+ var k = function () {
3773
+ };
3774
+
3775
+ function XHRWrapper(xhr) {
3776
+ this.withCredentials = false;
3777
+ this.readyState = 0;
3778
+ this.status = 0;
3779
+ this.statusText = "";
3780
+ this.responseText = "";
3781
+ this.onprogress = k;
3782
+ this.onload = k;
3783
+ this.onerror = k;
3784
+ this.onreadystatechange = k;
3785
+ this._contentType = "";
3786
+ this._xhr = xhr;
3787
+ this._sendTimeout = 0;
3788
+ this._abort = k;
3789
+ }
3790
+
3791
+ XHRWrapper.prototype.open = function (method, url) {
3792
+ this._abort(true);
3793
+
3794
+ var that = this;
3795
+ var xhr = this._xhr;
3796
+ var state = 1;
3797
+ var timeout = 0;
3798
+
3799
+ this._abort = function (silent) {
3800
+ if (that._sendTimeout !== 0) {
3801
+ clearTimeout(that._sendTimeout);
3802
+ that._sendTimeout = 0;
3803
+ }
3804
+ if (state === 1 || state === 2 || state === 3) {
3805
+ state = 4;
3806
+ xhr.onload = k;
3807
+ xhr.onerror = k;
3808
+ xhr.onabort = k;
3809
+ xhr.onprogress = k;
3810
+ xhr.onreadystatechange = k;
3811
+ // IE 8 - 9: XDomainRequest#abort() does not fire any event
3812
+ // Opera < 10: XMLHttpRequest#abort() does not fire any event
3813
+ xhr.abort();
3814
+ if (timeout !== 0) {
3815
+ clearTimeout(timeout);
3816
+ timeout = 0;
3817
+ }
3818
+ if (!silent) {
3819
+ that.readyState = 4;
3820
+ that.onabort(null);
3821
+ that.onreadystatechange();
3822
+ }
3823
+ }
3824
+ state = 0;
3825
+ };
3826
+
3827
+ var onStart = function () {
3828
+ if (state === 1) {
3829
+ //state = 2;
3830
+ var status = 0;
3831
+ var statusText = "";
3832
+ var contentType = undefined;
3833
+ if (!("contentType" in xhr)) {
3834
+ try {
3835
+ status = xhr.status;
3836
+ statusText = xhr.statusText;
3837
+ contentType = xhr.getResponseHeader("Content-Type");
3838
+ } catch (error) {
3839
+ // IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
3840
+ // Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
3841
+ // https://bugs.webkit.org/show_bug.cgi?id=29121
3842
+ status = 0;
3843
+ statusText = "";
3844
+ contentType = undefined;
3845
+ // Firefox < 14, Chrome ?, Safari ?
3846
+ // https://bugs.webkit.org/show_bug.cgi?id=29658
3847
+ // https://bugs.webkit.org/show_bug.cgi?id=77854
3848
+ }
3849
+ } else {
3850
+ status = 200;
3851
+ statusText = "OK";
3852
+ contentType = xhr.contentType;
3853
+ }
3854
+ if (status !== 0) {
3855
+ state = 2;
3856
+ that.readyState = 2;
3857
+ that.status = status;
3858
+ that.statusText = statusText;
3859
+ that._contentType = contentType;
3860
+ that.onreadystatechange();
3861
+ }
3862
+ }
3863
+ };
3864
+ var onProgress = function () {
3865
+ onStart();
3866
+ if (state === 2 || state === 3) {
3867
+ state = 3;
3868
+ var responseText = "";
3869
+ try {
3870
+ responseText = xhr.responseText;
3871
+ } catch (error) {
3872
+ // IE 8 - 9 with XMLHttpRequest
3873
+ }
3874
+ that.readyState = 3;
3875
+ that.responseText = responseText;
3876
+ that.onprogress();
3877
+ }
3878
+ };
3879
+ var onFinish = function (type, event) {
3880
+ if (event == null || event.preventDefault == null) {
3881
+ event = {
3882
+ preventDefault: k
3883
+ };
3884
+ }
3885
+ // Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
3886
+ // IE 8 fires "onload" without "onprogress"
3887
+ onProgress();
3888
+ if (state === 1 || state === 2 || state === 3) {
3889
+ state = 4;
3890
+ if (timeout !== 0) {
3891
+ clearTimeout(timeout);
3892
+ timeout = 0;
3893
+ }
3894
+ that.readyState = 4;
3895
+ if (type === "load") {
3896
+ that.onload(event);
3897
+ } else if (type === "error") {
3898
+ that.onerror(event);
3899
+ } else if (type === "abort") {
3900
+ that.onabort(event);
3901
+ } else {
3902
+ throw new TypeError();
3903
+ }
3904
+ that.onreadystatechange();
3905
+ }
3906
+ };
3907
+ var onReadyStateChange = function (event) {
3908
+ if (xhr != undefined) { // Opera 12
3909
+ if (xhr.readyState === 4) {
3910
+ if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
3911
+ onFinish(xhr.responseText === "" ? "error" : "load", event);
3912
+ }
3913
+ } else if (xhr.readyState === 3) {
3914
+ if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
3915
+ // and in Firefox 3.6
3916
+ onProgress();
3917
+ }
3918
+ } else if (xhr.readyState === 2) {
3919
+ onStart();
3920
+ }
3921
+ }
3922
+ };
3923
+ var onTimeout = function () {
3924
+ timeout = setTimeout(function () {
3925
+ onTimeout();
3926
+ }, 500);
3927
+ if (xhr.readyState === 3) {
3928
+ onProgress();
3929
+ }
3930
+ };
3931
+
3932
+ // XDomainRequest#abort removes onprogress, onerror, onload
3933
+ if ("onload" in xhr) {
3934
+ xhr.onload = function (event) {
3935
+ onFinish("load", event);
3936
+ };
3937
+ }
3938
+ if ("onerror" in xhr) {
3939
+ xhr.onerror = function (event) {
3940
+ onFinish("error", event);
3941
+ };
3942
+ }
3943
+ // improper fix to match Firefox behaviour, but it is better than just ignore abort
3944
+ // see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
3945
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=880200
3946
+ // https://code.google.com/p/chromium/issues/detail?id=153570
3947
+ // IE 8 fires "onload" without "onprogress
3948
+ if ("onabort" in xhr) {
3949
+ xhr.onabort = function (event) {
3950
+ onFinish("abort", event);
3951
+ };
3952
+ }
3953
+
3954
+ if ("onprogress" in xhr) {
3955
+ xhr.onprogress = onProgress;
3956
+ }
3957
+
3958
+ // IE 8 - 9 (XMLHTTPRequest)
3959
+ // Opera < 12
3960
+ // Firefox < 3.5
3961
+ // Firefox 3.5 - 3.6 - ? < 9.0
3962
+ // onprogress is not fired sometimes or delayed
3963
+ // see also #64 (significant lag in IE 11)
3964
+ if ("onreadystatechange" in xhr) {
3965
+ xhr.onreadystatechange = function (event) {
3966
+ onReadyStateChange(event);
3967
+ };
3968
+ }
3969
+
3970
+ if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
3971
+ url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
3972
+ }
3973
+ xhr.open(method, url, true);
3974
+
3975
+ if ("readyState" in xhr) {
3976
+ // workaround for Opera 12 issue with "progress" events
3977
+ // #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
3978
+ timeout = setTimeout(function () {
3979
+ onTimeout();
3980
+ }, 0);
3981
+ }
3982
+ };
3983
+ XHRWrapper.prototype.abort = function () {
3984
+ this._abort(false);
3985
+ };
3986
+ XHRWrapper.prototype.getResponseHeader = function (name) {
3987
+ return this._contentType;
3988
+ };
3989
+ XHRWrapper.prototype.setRequestHeader = function (name, value) {
3990
+ var xhr = this._xhr;
3991
+ if ("setRequestHeader" in xhr) {
3992
+ xhr.setRequestHeader(name, value);
3993
+ }
3994
+ };
3995
+ XHRWrapper.prototype.getAllResponseHeaders = function () {
3996
+ // XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
3997
+ return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
3998
+ };
3999
+ XHRWrapper.prototype.send = function () {
4000
+ // loading indicator in Safari < ? (6), Chrome < 14, Firefox
4001
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=736723
4002
+ if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
4003
+ document != undefined &&
4004
+ document.readyState != undefined &&
4005
+ document.readyState !== "complete") {
4006
+ var that = this;
4007
+ that._sendTimeout = setTimeout(function () {
4008
+ that._sendTimeout = 0;
4009
+ that.send();
4010
+ }, 4);
4011
+ return;
4012
+ }
4013
+
4014
+ var xhr = this._xhr;
4015
+ // withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
4016
+ if ("withCredentials" in xhr) {
4017
+ xhr.withCredentials = this.withCredentials;
4018
+ }
4019
+ try {
4020
+ // xhr.send(); throws "Not enough arguments" in Firefox 3.0
4021
+ xhr.send(undefined);
4022
+ } catch (error1) {
4023
+ // Safari 5.1.7, Opera 12
4024
+ throw error1;
4025
+ }
4026
+ };
4027
+
4028
+ function toLowerCase(name) {
4029
+ return name.replace(/[A-Z]/g, function (c) {
4030
+ return String.fromCharCode(c.charCodeAt(0) + 0x20);
4031
+ });
4032
+ }
4033
+
4034
+ function HeadersPolyfill(all) {
4035
+ // Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
4036
+ var map = Object.create(null);
4037
+ var array = all.split("\r\n");
4038
+ for (var i = 0; i < array.length; i += 1) {
4039
+ var line = array[i];
4040
+ var parts = line.split(": ");
4041
+ var name = parts.shift();
4042
+ var value = parts.join(": ");
4043
+ map[toLowerCase(name)] = value;
4044
+ }
4045
+ this._map = map;
4046
+ }
4047
+ HeadersPolyfill.prototype.get = function (name) {
4048
+ return this._map[toLowerCase(name)];
4049
+ };
4050
+
4051
+ if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
4052
+ XMLHttpRequest.HEADERS_RECEIVED = 2;
4053
+ }
4054
+
4055
+ function XHRTransport() {
4056
+ }
4057
+
4058
+ XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
4059
+ xhr.open("GET", url);
4060
+ var offset = 0;
4061
+ xhr.onprogress = function () {
4062
+ var responseText = xhr.responseText;
4063
+ var chunk = responseText.slice(offset);
4064
+ offset += chunk.length;
4065
+ onProgressCallback(chunk);
4066
+ };
4067
+ xhr.onerror = function (event) {
4068
+ event.preventDefault();
4069
+ onFinishCallback(new Error("NetworkError"));
4070
+ };
4071
+ xhr.onload = function () {
4072
+ onFinishCallback(null);
4073
+ };
4074
+ xhr.onabort = function () {
4075
+ onFinishCallback(null);
4076
+ };
4077
+ xhr.onreadystatechange = function () {
4078
+ if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
4079
+ var status = xhr.status;
4080
+ var statusText = xhr.statusText;
4081
+ var contentType = xhr.getResponseHeader("Content-Type");
4082
+ var headers = xhr.getAllResponseHeaders();
4083
+ onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
4084
+ }
4085
+ };
4086
+ xhr.withCredentials = withCredentials;
4087
+ for (var name in headers) {
4088
+ if (Object.prototype.hasOwnProperty.call(headers, name)) {
4089
+ xhr.setRequestHeader(name, headers[name]);
4090
+ }
4091
+ }
4092
+ xhr.send();
4093
+ return xhr;
4094
+ };
4095
+
4096
+ function HeadersWrapper(headers) {
4097
+ this._headers = headers;
4098
+ }
4099
+ HeadersWrapper.prototype.get = function (name) {
4100
+ return this._headers.get(name);
4101
+ };
4102
+
4103
+ function FetchTransport() {
4104
+ }
4105
+
4106
+ FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
4107
+ var reader = null;
4108
+ var controller = new AbortController();
4109
+ var signal = controller.signal;
4110
+ var textDecoder = new TextDecoder();
4111
+ fetch(url, {
4112
+ headers: headers,
4113
+ credentials: withCredentials ? "include" : "same-origin",
4114
+ signal: signal,
4115
+ cache: "no-store"
4116
+ }).then(function (response) {
4117
+ reader = response.body.getReader();
4118
+ onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
4119
+ // see https://github.com/promises-aplus/promises-spec/issues/179
4120
+ return new Promise(function (resolve, reject) {
4121
+ var readNextChunk = function () {
4122
+ reader.read().then(function (result) {
4123
+ if (result.done) {
4124
+ //Note: bytes in textDecoder are ignored
4125
+ resolve(undefined);
4126
+ } else {
4127
+ var chunk = textDecoder.decode(result.value, {stream: true});
4128
+ onProgressCallback(chunk);
4129
+ readNextChunk();
4130
+ }
4131
+ })["catch"](function (error) {
4132
+ reject(error);
4133
+ });
4134
+ };
4135
+ readNextChunk();
4136
+ });
4137
+ })["catch"](function (error) {
4138
+ if (error.name === "AbortError") {
4139
+ return undefined;
4140
+ } else {
4141
+ return error;
4142
+ }
4143
+ }).then(function (error) {
4144
+ onFinishCallback(error);
4145
+ });
4146
+ return {
4147
+ abort: function () {
4148
+ if (reader != null) {
4149
+ reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
4150
+ }
4151
+ controller.abort();
4152
+ }
4153
+ };
4154
+ };
4155
+
4156
+ function EventTarget() {
4157
+ this._listeners = Object.create(null);
4158
+ }
4159
+
4160
+ function throwError(e) {
4161
+ setTimeout(function () {
4162
+ throw e;
4163
+ }, 0);
4164
+ }
4165
+
4166
+ EventTarget.prototype.dispatchEvent = function (event) {
4167
+ event.target = this;
4168
+ var typeListeners = this._listeners[event.type];
4169
+ if (typeListeners != undefined) {
4170
+ var length = typeListeners.length;
4171
+ for (var i = 0; i < length; i += 1) {
4172
+ var listener = typeListeners[i];
4173
+ try {
4174
+ if (typeof listener.handleEvent === "function") {
4175
+ listener.handleEvent(event);
4176
+ } else {
4177
+ listener.call(this, event);
4178
+ }
4179
+ } catch (e) {
4180
+ throwError(e);
4181
+ }
4182
+ }
4183
+ }
4184
+ };
4185
+ EventTarget.prototype.addEventListener = function (type, listener) {
4186
+ type = String(type);
4187
+ var listeners = this._listeners;
4188
+ var typeListeners = listeners[type];
4189
+ if (typeListeners == undefined) {
4190
+ typeListeners = [];
4191
+ listeners[type] = typeListeners;
4192
+ }
4193
+ var found = false;
4194
+ for (var i = 0; i < typeListeners.length; i += 1) {
4195
+ if (typeListeners[i] === listener) {
4196
+ found = true;
4197
+ }
4198
+ }
4199
+ if (!found) {
4200
+ typeListeners.push(listener);
4201
+ }
4202
+ };
4203
+ EventTarget.prototype.removeEventListener = function (type, listener) {
4204
+ type = String(type);
4205
+ var listeners = this._listeners;
4206
+ var typeListeners = listeners[type];
4207
+ if (typeListeners != undefined) {
4208
+ var filtered = [];
4209
+ for (var i = 0; i < typeListeners.length; i += 1) {
4210
+ if (typeListeners[i] !== listener) {
4211
+ filtered.push(typeListeners[i]);
4212
+ }
4213
+ }
4214
+ if (filtered.length === 0) {
4215
+ delete listeners[type];
4216
+ } else {
4217
+ listeners[type] = filtered;
4218
+ }
4219
+ }
4220
+ };
4221
+
4222
+ function Event(type) {
4223
+ this.type = type;
4224
+ this.target = undefined;
4225
+ }
4226
+
4227
+ function MessageEvent(type, options) {
4228
+ Event.call(this, type);
4229
+ this.data = options.data;
4230
+ this.lastEventId = options.lastEventId;
4231
+ }
4232
+
4233
+ MessageEvent.prototype = Object.create(Event.prototype);
4234
+
4235
+ function ConnectionEvent(type, options) {
4236
+ Event.call(this, type);
4237
+ this.status = options.status;
4238
+ this.statusText = options.statusText;
4239
+ this.headers = options.headers;
4240
+ }
4241
+
4242
+ ConnectionEvent.prototype = Object.create(Event.prototype);
4243
+
4244
+ function ErrorEvent(type, options) {
4245
+ Event.call(this, type);
4246
+ this.error = options.error;
4247
+ }
4248
+
4249
+ ErrorEvent.prototype = Object.create(Event.prototype);
4250
+
4251
+ var WAITING = -1;
4252
+ var CONNECTING = 0;
4253
+ var OPEN = 1;
4254
+ var CLOSED = 2;
4255
+
4256
+ var AFTER_CR = -1;
4257
+ var FIELD_START = 0;
4258
+ var FIELD = 1;
4259
+ var VALUE_START = 2;
4260
+ var VALUE = 3;
4261
+
4262
+ var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
4263
+
4264
+ var MINIMUM_DURATION = 1000;
4265
+ var MAXIMUM_DURATION = 18000000;
4266
+
4267
+ var parseDuration = function (value, def) {
4268
+ var n = value == null ? def : parseInt(value, 10);
4269
+ if (n !== n) {
4270
+ n = def;
4271
+ }
4272
+ return clampDuration(n);
4273
+ };
4274
+ var clampDuration = function (n) {
4275
+ return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
4276
+ };
4277
+
4278
+ var fire = function (that, f, event) {
4279
+ try {
4280
+ if (typeof f === "function") {
4281
+ f.call(that, event);
4282
+ }
4283
+ } catch (e) {
4284
+ throwError(e);
4285
+ }
4286
+ };
4287
+
4288
+ function EventSourcePolyfill(url, options) {
4289
+ EventTarget.call(this);
4290
+ options = options || {};
4291
+
4292
+ this.onopen = undefined;
4293
+ this.onmessage = undefined;
4294
+ this.onerror = undefined;
4295
+
4296
+ this.url = undefined;
4297
+ this.readyState = undefined;
4298
+ this.withCredentials = undefined;
4299
+ this.headers = undefined;
4300
+
4301
+ this._close = undefined;
4302
+
4303
+ start(this, url, options);
4304
+ }
4305
+
4306
+ function getBestXHRTransport() {
4307
+ return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
4308
+ ? new XMLHttpRequest()
4309
+ : new XDomainRequest();
4310
+ }
4311
+
4312
+ var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
4313
+
4314
+ function start(es, url, options) {
4315
+ url = String(url);
4316
+ var withCredentials = Boolean(options.withCredentials);
4317
+ var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
4318
+
4319
+ var initialRetry = clampDuration(1000);
4320
+ var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
4321
+
4322
+ var lastEventId = "";
4323
+ var retry = initialRetry;
4324
+ var wasActivity = false;
4325
+ var textLength = 0;
4326
+ var headers = options.headers || {};
4327
+ var TransportOption = options.Transport;
4328
+ var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
4329
+ var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
4330
+ var abortController = undefined;
4331
+ var timeout = 0;
4332
+ var currentState = WAITING;
4333
+ var dataBuffer = "";
4334
+ var lastEventIdBuffer = "";
4335
+ var eventTypeBuffer = "";
4336
+
4337
+ var textBuffer = "";
4338
+ var state = FIELD_START;
4339
+ var fieldStart = 0;
4340
+ var valueStart = 0;
4341
+
4342
+ var onStart = function (status, statusText, contentType, headers) {
4343
+ if (currentState === CONNECTING) {
4344
+ if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
4345
+ currentState = OPEN;
4346
+ wasActivity = Date.now();
4347
+ retry = initialRetry;
4348
+ es.readyState = OPEN;
4349
+ var event = new ConnectionEvent("open", {
4350
+ status: status,
4351
+ statusText: statusText,
4352
+ headers: headers
4353
+ });
4354
+ es.dispatchEvent(event);
4355
+ fire(es, es.onopen, event);
4356
+ } else {
4357
+ var message = "";
4358
+ if (status !== 200) {
4359
+ if (statusText) {
4360
+ statusText = statusText.replace(/\s+/g, " ");
4361
+ }
4362
+ message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
4363
+ } else {
4364
+ message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
4365
+ }
4366
+ close();
4367
+ var event = new ConnectionEvent("error", {
4368
+ status: status,
4369
+ statusText: statusText,
4370
+ headers: headers
4371
+ });
4372
+ es.dispatchEvent(event);
4373
+ fire(es, es.onerror, event);
4374
+ console.error(message);
4375
+ }
4376
+ }
4377
+ };
4378
+
4379
+ var onProgress = function (textChunk) {
4380
+ if (currentState === OPEN) {
4381
+ var n = -1;
4382
+ for (var i = 0; i < textChunk.length; i += 1) {
4383
+ var c = textChunk.charCodeAt(i);
4384
+ if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
4385
+ n = i;
4386
+ }
4387
+ }
4388
+ var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
4389
+ textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
4390
+ if (textChunk !== "") {
4391
+ wasActivity = Date.now();
4392
+ textLength += textChunk.length;
4393
+ }
4394
+ for (var position = 0; position < chunk.length; position += 1) {
4395
+ var c = chunk.charCodeAt(position);
4396
+ if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
4397
+ state = FIELD_START;
4398
+ } else {
4399
+ if (state === AFTER_CR) {
4400
+ state = FIELD_START;
4401
+ }
4402
+ if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
4403
+ if (state !== FIELD_START) {
4404
+ if (state === FIELD) {
4405
+ valueStart = position + 1;
4406
+ }
4407
+ var field = chunk.slice(fieldStart, valueStart - 1);
4408
+ var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
4409
+ if (field === "data") {
4410
+ dataBuffer += "\n";
4411
+ dataBuffer += value;
4412
+ } else if (field === "id") {
4413
+ lastEventIdBuffer = value;
4414
+ } else if (field === "event") {
4415
+ eventTypeBuffer = value;
4416
+ } else if (field === "retry") {
4417
+ initialRetry = parseDuration(value, initialRetry);
4418
+ retry = initialRetry;
4419
+ } else if (field === "heartbeatTimeout") {
4420
+ heartbeatTimeout = parseDuration(value, heartbeatTimeout);
4421
+ if (timeout !== 0) {
4422
+ clearTimeout(timeout);
4423
+ timeout = setTimeout(function () {
4424
+ onTimeout();
4425
+ }, heartbeatTimeout);
4426
+ }
4427
+ }
4428
+ }
4429
+ if (state === FIELD_START) {
4430
+ if (dataBuffer !== "") {
4431
+ lastEventId = lastEventIdBuffer;
4432
+ if (eventTypeBuffer === "") {
4433
+ eventTypeBuffer = "message";
4434
+ }
4435
+ var event = new MessageEvent(eventTypeBuffer, {
4436
+ data: dataBuffer.slice(1),
4437
+ lastEventId: lastEventIdBuffer
4438
+ });
4439
+ es.dispatchEvent(event);
4440
+ if (eventTypeBuffer === "open") {
4441
+ fire(es, es.onopen, event);
4442
+ } else if (eventTypeBuffer === "message") {
4443
+ fire(es, es.onmessage, event);
4444
+ } else if (eventTypeBuffer === "error") {
4445
+ fire(es, es.onerror, event);
4446
+ }
4447
+ if (currentState === CLOSED) {
4448
+ return;
4449
+ }
4450
+ }
4451
+ dataBuffer = "";
4452
+ eventTypeBuffer = "";
4453
+ }
4454
+ state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
4455
+ } else {
4456
+ if (state === FIELD_START) {
4457
+ fieldStart = position;
4458
+ state = FIELD;
4459
+ }
4460
+ if (state === FIELD) {
4461
+ if (c === ":".charCodeAt(0)) {
4462
+ valueStart = position + 1;
4463
+ state = VALUE_START;
4464
+ }
4465
+ } else if (state === VALUE_START) {
4466
+ state = VALUE;
4467
+ }
4468
+ }
4469
+ }
4470
+ }
4471
+ }
4472
+ };
4473
+
4474
+ var onFinish = function (error) {
4475
+ if (currentState === OPEN || currentState === CONNECTING) {
4476
+ currentState = WAITING;
4477
+ if (timeout !== 0) {
4478
+ clearTimeout(timeout);
4479
+ timeout = 0;
4480
+ }
4481
+ timeout = setTimeout(function () {
4482
+ onTimeout();
4483
+ }, retry);
4484
+ retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
4485
+
4486
+ es.readyState = CONNECTING;
4487
+ var event = new ErrorEvent("error", {error: error});
4488
+ es.dispatchEvent(event);
4489
+ fire(es, es.onerror, event);
4490
+ if (error != undefined) {
4491
+ console.error(error);
4492
+ }
4493
+ }
4494
+ };
4495
+
4496
+ var close = function () {
4497
+ currentState = CLOSED;
4498
+ if (abortController != undefined) {
4499
+ abortController.abort();
4500
+ abortController = undefined;
4501
+ }
4502
+ if (timeout !== 0) {
4503
+ clearTimeout(timeout);
4504
+ timeout = 0;
4505
+ }
4506
+ es.readyState = CLOSED;
4507
+ };
4508
+
4509
+ var onTimeout = function () {
4510
+ timeout = 0;
4511
+
4512
+ if (currentState !== WAITING) {
4513
+ if (!wasActivity && abortController != undefined) {
4514
+ onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
4515
+ if (abortController != undefined) {
4516
+ abortController.abort();
4517
+ abortController = undefined;
4518
+ }
4519
+ } else {
4520
+ var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
4521
+ wasActivity = false;
4522
+ timeout = setTimeout(function () {
4523
+ onTimeout();
4524
+ }, nextHeartbeat);
4525
+ }
4526
+ return;
4527
+ }
4528
+
4529
+ wasActivity = false;
4530
+ textLength = 0;
4531
+ timeout = setTimeout(function () {
4532
+ onTimeout();
4533
+ }, heartbeatTimeout);
4534
+
4535
+ currentState = CONNECTING;
4536
+ dataBuffer = "";
4537
+ eventTypeBuffer = "";
4538
+ lastEventIdBuffer = lastEventId;
4539
+ textBuffer = "";
4540
+ fieldStart = 0;
4541
+ valueStart = 0;
4542
+ state = FIELD_START;
4543
+
4544
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=428916
4545
+ // Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
4546
+ var requestURL = url;
4547
+ if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
4548
+ if (lastEventId !== "") {
4549
+ // Remove the lastEventId parameter if it's already part of the request URL.
4550
+ var i = url.indexOf("?");
4551
+ requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
4552
+ return paramName === lastEventIdQueryParameterName ? '' : p;
4553
+ });
4554
+ // Append the current lastEventId to the request URL.
4555
+ requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
4556
+ }
4557
+ }
4558
+ var withCredentials = es.withCredentials;
4559
+ var requestHeaders = {};
4560
+ requestHeaders["Accept"] = "text/event-stream";
4561
+ var headers = es.headers;
4562
+ if (headers != undefined) {
4563
+ for (var name in headers) {
4564
+ if (Object.prototype.hasOwnProperty.call(headers, name)) {
4565
+ requestHeaders[name] = headers[name];
4566
+ }
4567
+ }
4568
+ }
4569
+ try {
4570
+ abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
4571
+ } catch (error) {
4572
+ close();
4573
+ throw error;
4574
+ }
4575
+ };
4576
+
4577
+ es.url = url;
4578
+ es.readyState = CONNECTING;
4579
+ es.withCredentials = withCredentials;
4580
+ es.headers = headers;
4581
+ es._close = close;
4582
+
4583
+ onTimeout();
4584
+ }
4585
+
4586
+ EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
4587
+ EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
4588
+ EventSourcePolyfill.prototype.OPEN = OPEN;
4589
+ EventSourcePolyfill.prototype.CLOSED = CLOSED;
4590
+ EventSourcePolyfill.prototype.close = function () {
4591
+ this._close();
4592
+ };
4593
+
4594
+ EventSourcePolyfill.CONNECTING = CONNECTING;
4595
+ EventSourcePolyfill.OPEN = OPEN;
4596
+ EventSourcePolyfill.CLOSED = CLOSED;
4597
+ EventSourcePolyfill.prototype.withCredentials = undefined;
4598
+
4599
+ var R = NativeEventSource;
4600
+ if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
4601
+ // Why replace a native EventSource ?
4602
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=444328
4603
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=831392
4604
+ // https://code.google.com/p/chromium/issues/detail?id=260144
4605
+ // https://code.google.com/p/chromium/issues/detail?id=225654
4606
+ // ...
4607
+ R = EventSourcePolyfill;
4608
+ }
4609
+
4610
+ (function (factory) {
4611
+ {
4612
+ var v = factory(exports);
4613
+ if (v !== undefined) module.exports = v;
4614
+ }
4615
+ })(function (exports) {
4616
+ exports.EventSourcePolyfill = EventSourcePolyfill;
4617
+ exports.NativeEventSource = NativeEventSource;
4618
+ exports.EventSource = R;
4619
+ });
4620
+ }(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : commonjsGlobal) : globalThis));
4621
+ } (eventsource, eventsource.exports));
4622
+
4623
+ var eventsourceExports = eventsource.exports;
4624
+
4625
+ var browser = eventsourceExports.EventSourcePolyfill;
4626
+
4627
+ var browser$1 = /*@__PURE__*/getDefaultExportFromCjs(browser);
4628
+
4629
+ var browser$2 = /*#__PURE__*/Object.freeze({
3942
4630
  __proto__: null,
3943
- EventSource: EventSource
4631
+ default: browser$1
3944
4632
  });
3945
4633
 
3946
4634
  exports.BasePatch = BasePatch;