proto-sudoku-wc 0.0.803 → 0.0.805

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.
@@ -2,13 +2,119 @@ const NAMESPACE = 'proto-sudoku-wc';
2
2
  const BUILD = /* proto-sudoku-wc */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: false, cmpDidLoad: true, cmpDidRender: false, cmpDidUnload: false, cmpDidUpdate: false, cmpShouldUpdate: false, cmpWillLoad: false, cmpWillRender: false, cmpWillUpdate: false, connectedCallback: false, constructableCSS: true, cssAnnotations: true, devTools: false, disconnectedCallback: false, element: false, event: false, experimentalScopedSlotChanges: false, experimentalSlotFixes: false, formAssociated: false, hasRenderFn: true, hostListener: false, hostListenerTarget: false, hostListenerTargetBody: false, hostListenerTargetDocument: false, hostListenerTargetParent: false, hostListenerTargetWindow: false, hotModuleReplacement: false, hydrateClientSide: false, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, hydratedSelectorName: "hydrated", initializeNextTick: false, invisiblePrehydration: true, isDebug: false, isDev: false, isTesting: false, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: false, member: true, method: false, mode: false, observeAttribute: true, profile: false, prop: true, propBoolean: false, propMutable: false, propNumber: false, propString: true, reflect: false, scoped: false, scopedSlotTextContentFix: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: true, slot: false, slotChildNodesFix: false, slotRelocation: false, state: false, style: true, svg: true, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: true, vdomListener: true, vdomPropOrAttr: true, vdomRef: false, vdomRender: true, vdomStyle: false, vdomText: true, vdomXlink: false, watchCallback: false };
3
3
 
4
4
  /*
5
- Stencil Client Platform v4.18.3 | MIT Licensed | https://stenciljs.com
5
+ Stencil Client Platform v4.19.0 | MIT Licensed | https://stenciljs.com
6
6
  */
7
7
  var __defProp = Object.defineProperty;
8
8
  var __export = (target, all) => {
9
9
  for (var name in all)
10
10
  __defProp(target, name, { get: all[name], enumerable: true });
11
11
  };
12
+ var hostRefs = /* @__PURE__ */ new WeakMap();
13
+ var getHostRef = (ref) => hostRefs.get(ref);
14
+ var registerInstance = (lazyInstance, hostRef) => hostRefs.set(hostRef.$lazyInstance$ = lazyInstance, hostRef);
15
+ var registerHost = (hostElement, cmpMeta) => {
16
+ const hostRef = {
17
+ $flags$: 0,
18
+ $hostElement$: hostElement,
19
+ $cmpMeta$: cmpMeta,
20
+ $instanceValues$: /* @__PURE__ */ new Map()
21
+ };
22
+ {
23
+ hostRef.$onReadyPromise$ = new Promise((r) => hostRef.$onReadyResolve$ = r);
24
+ hostElement["s-p"] = [];
25
+ hostElement["s-rc"] = [];
26
+ }
27
+ return hostRefs.set(hostElement, hostRef);
28
+ };
29
+ var isMemberInElement = (elm, memberName) => memberName in elm;
30
+ var consoleError = (e, el) => (0, console.error)(e, el);
31
+
32
+ // src/client/client-load-module.ts
33
+ var cmpModules = /* @__PURE__ */ new Map();
34
+ var loadModule = (cmpMeta, hostRef, hmrVersionId) => {
35
+ const exportName = cmpMeta.$tagName$.replace(/-/g, "_");
36
+ const bundleId = cmpMeta.$lazyBundleId$;
37
+ if (!bundleId) {
38
+ return void 0;
39
+ }
40
+ const module = cmpModules.get(bundleId) ;
41
+ if (module) {
42
+ return module[exportName];
43
+ }
44
+ /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
45
+ return import(
46
+ /* @vite-ignore */
47
+ /* webpackInclude: /\.entry\.js$/ */
48
+ /* webpackExclude: /\.system\.entry\.js$/ */
49
+ /* webpackMode: "lazy" */
50
+ `./${bundleId}.entry.js${""}`
51
+ ).then((importedModule) => {
52
+ {
53
+ cmpModules.set(bundleId, importedModule);
54
+ }
55
+ return importedModule[exportName];
56
+ }, consoleError);
57
+ };
58
+
59
+ // src/client/client-style.ts
60
+ var styles = /* @__PURE__ */ new Map();
61
+ var HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
62
+ var SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
63
+ var win = typeof window !== "undefined" ? window : {};
64
+ var doc = win.document || { head: {} };
65
+ var plt = {
66
+ $flags$: 0,
67
+ $resourcesUrl$: "",
68
+ jmp: (h2) => h2(),
69
+ raf: (h2) => requestAnimationFrame(h2),
70
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
71
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
72
+ ce: (eventName, opts) => new CustomEvent(eventName, opts)
73
+ };
74
+ var promiseResolve = (v) => Promise.resolve(v);
75
+ var supportsConstructableStylesheets = /* @__PURE__ */ (() => {
76
+ try {
77
+ new CSSStyleSheet();
78
+ return typeof new CSSStyleSheet().replaceSync === "function";
79
+ } catch (e) {
80
+ }
81
+ return false;
82
+ })() ;
83
+ var queuePending = false;
84
+ var queueDomReads = [];
85
+ var queueDomWrites = [];
86
+ var queueTask = (queue, write) => (cb) => {
87
+ queue.push(cb);
88
+ if (!queuePending) {
89
+ queuePending = true;
90
+ if (write && plt.$flags$ & 4 /* queueSync */) {
91
+ nextTick(flush);
92
+ } else {
93
+ plt.raf(flush);
94
+ }
95
+ }
96
+ };
97
+ var consume = (queue) => {
98
+ for (let i2 = 0; i2 < queue.length; i2++) {
99
+ try {
100
+ queue[i2](performance.now());
101
+ } catch (e) {
102
+ consoleError(e);
103
+ }
104
+ }
105
+ queue.length = 0;
106
+ };
107
+ var flush = () => {
108
+ consume(queueDomReads);
109
+ {
110
+ consume(queueDomWrites);
111
+ if (queuePending = queueDomReads.length > 0) {
112
+ plt.raf(flush);
113
+ }
114
+ }
115
+ };
116
+ var nextTick = (cb) => promiseResolve().then(cb);
117
+ var writeTask = /* @__PURE__ */ queueTask(queueDomWrites, true);
12
118
 
13
119
  // src/utils/constants.ts
14
120
  var EMPTY_OBJ = {};
@@ -90,8 +196,6 @@ var uniqueTime = (key, measureText) => {
90
196
  };
91
197
  }
92
198
  };
93
- var HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
94
- var SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
95
199
  var h = (nodeName, vnodeData, ...children) => {
96
200
  let child = null;
97
201
  let key = null;
@@ -224,12 +328,13 @@ var registerStyle = (scopeId2, cssText, allowCS) => {
224
328
  };
225
329
  var addStyle = (styleContainerNode, cmpMeta, mode) => {
226
330
  var _a;
331
+ const styleContainerDocument = styleContainerNode;
227
332
  const scopeId2 = getScopeId(cmpMeta);
228
333
  const style = styles.get(scopeId2);
229
334
  styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
230
335
  if (style) {
231
336
  if (typeof style === "string") {
232
- styleContainerNode = styleContainerNode.head || styleContainerNode;
337
+ styleContainerNode = styleContainerDocument.head || styleContainerNode;
233
338
  let appliedStyles = rootAppliedStyles.get(styleContainerNode);
234
339
  let styleElm;
235
340
  if (!appliedStyles) {
@@ -252,8 +357,8 @@ var addStyle = (styleContainerNode, cmpMeta, mode) => {
252
357
  appliedStyles.add(scopeId2);
253
358
  }
254
359
  }
255
- } else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
256
- styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
360
+ } else if (!styleContainerDocument.adoptedStyleSheets.includes(style)) {
361
+ styleContainerDocument.adoptedStyleSheets = [...styleContainerDocument.adoptedStyleSheets, style];
257
362
  }
258
363
  }
259
364
  return scopeId2;
@@ -367,6 +472,7 @@ function sortedAttrNames(attrNames) {
367
472
  // src/runtime/vdom/vdom-render.ts
368
473
  var scopeId;
369
474
  var hostTagName;
475
+ var useNativeShadowDom = false;
370
476
  var isSvgMode = false;
371
477
  var createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
372
478
  const newVNode2 = newParentVNode.$children$[childIndex];
@@ -381,7 +487,7 @@ var createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
381
487
  }
382
488
  elm = newVNode2.$elm$ = doc.createElementNS(
383
489
  isSvgMode ? SVG_NS : HTML_NS,
384
- newVNode2.$tag$
490
+ !useNativeShadowDom && BUILD.slotRelocation && newVNode2.$flags$ & 2 /* isSlotFallback */ ? "slot-fb" : newVNode2.$tag$
385
491
  ) ;
386
492
  if (isSvgMode && newVNode2.$tag$ === "foreignObject") {
387
493
  isSvgMode = false;
@@ -569,6 +675,7 @@ var insertBefore = (parent, newNode, reference) => {
569
675
  };
570
676
  var renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
571
677
  const hostElm = hostRef.$hostElement$;
678
+ const cmpMeta = hostRef.$cmpMeta$;
572
679
  const oldVNode = hostRef.$vnode$ || newVNode(null, null);
573
680
  const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
574
681
  hostTagName = hostElm.tagName;
@@ -586,6 +693,7 @@ var renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
586
693
  {
587
694
  scopeId = hostElm["s-sc"];
588
695
  }
696
+ useNativeShadowDom = (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) !== 0;
589
697
  patch(oldVNode, rootVnode, isInitialLoad);
590
698
  };
591
699
 
@@ -620,7 +728,10 @@ var dispatchHooks = (hostRef, isInitialLoad) => {
620
728
  endSchedule();
621
729
  return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
622
730
  };
623
- var enqueue = (maybePromise, fn) => isPromisey(maybePromise) ? maybePromise.then(fn) : fn();
731
+ var enqueue = (maybePromise, fn) => isPromisey(maybePromise) ? maybePromise.then(fn).catch((err2) => {
732
+ console.error(err2);
733
+ fn();
734
+ }) : fn();
624
735
  var isPromisey = (maybePromise) => maybePromise instanceof Promise || maybePromise && maybePromise.then && typeof maybePromise.then === "function";
625
736
  var updateComponent = async (hostRef, instance, isInitialLoad) => {
626
737
  var _a;
@@ -770,10 +881,10 @@ var setValue = (ref, propName, newVal, cmpMeta) => {
770
881
 
771
882
  // src/runtime/proxy-component.ts
772
883
  var proxyComponent = (Cstr, cmpMeta, flags) => {
773
- var _a;
884
+ var _a, _b;
774
885
  const prototype = Cstr.prototype;
775
- if (cmpMeta.$members$) {
776
- const members = Object.entries(cmpMeta.$members$);
886
+ if (cmpMeta.$members$ || BUILD.watchCallback ) {
887
+ const members = Object.entries((_a = cmpMeta.$members$) != null ? _a : {});
777
888
  members.map(([memberName, [memberFlags]]) => {
778
889
  if ((memberFlags & 31 /* Prop */ || (flags & 2 /* proxyState */) && memberFlags & 32 /* State */)) {
779
890
  Object.defineProperty(prototype, memberName, {
@@ -818,7 +929,7 @@ var proxyComponent = (Cstr, cmpMeta, flags) => {
818
929
  };
819
930
  Cstr.observedAttributes = Array.from(
820
931
  /* @__PURE__ */ new Set([
821
- ...Object.keys((_a = cmpMeta.$watchers$) != null ? _a : {}),
932
+ ...Object.keys((_b = cmpMeta.$watchers$) != null ? _b : {}),
822
933
  ...members.filter(([_, m]) => m[0] & 15 /* HasAttribute */).map(([propName, m]) => {
823
934
  const attrName = m[1] || propName;
824
935
  attrNameToPropName.set(attrName, propName);
@@ -872,7 +983,10 @@ var initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
872
983
  customElements.whenDefined(cmpTag).then(() => hostRef.$flags$ |= 128 /* isWatchReady */);
873
984
  }
874
985
  if (Cstr && Cstr.style) {
875
- let style = Cstr.style;
986
+ let style;
987
+ if (typeof Cstr.style === "string") {
988
+ style = Cstr.style;
989
+ }
876
990
  const scopeId2 = getScopeId(cmpMeta);
877
991
  if (!styles.has(scopeId2)) {
878
992
  const endRegisterStyles = createTime("registerStyles", cmpMeta.$tagName$);
@@ -975,17 +1089,30 @@ var bootstrapLazy = (lazyBundles, options = {}) => {
975
1089
  // StencilLazyHost
976
1090
  constructor(self) {
977
1091
  super(self);
1092
+ this.hasRegisteredEventListeners = false;
978
1093
  self = this;
979
1094
  registerHost(self, cmpMeta);
980
1095
  if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
981
1096
  {
982
- {
983
- self.attachShadow({ mode: "open" });
1097
+ if (!self.shadowRoot) {
1098
+ {
1099
+ self.attachShadow({ mode: "open" });
1100
+ }
1101
+ } else {
1102
+ if (self.shadowRoot.mode !== "open") {
1103
+ throw new Error(
1104
+ `Unable to re-use existing shadow root for ${cmpMeta.$tagName$}! Mode is set to ${self.shadowRoot.mode} but Stencil only supports open shadow roots.`
1105
+ );
1106
+ }
984
1107
  }
985
1108
  }
986
1109
  }
987
1110
  }
988
1111
  connectedCallback() {
1112
+ getHostRef(this);
1113
+ if (!this.hasRegisteredEventListeners) {
1114
+ this.hasRegisteredEventListeners = true;
1115
+ }
989
1116
  if (appLoadFallback) {
990
1117
  clearTimeout(appLoadFallback);
991
1118
  appLoadFallback = null;
@@ -1018,7 +1145,7 @@ var bootstrapLazy = (lazyBundles, options = {}) => {
1018
1145
  dataStyles.textContent += SLOT_FB_CSS;
1019
1146
  }
1020
1147
  {
1021
- dataStyles.textContent += cmpTags + HYDRATED_CSS;
1148
+ dataStyles.textContent += cmpTags.sort() + HYDRATED_CSS;
1022
1149
  }
1023
1150
  if (dataStyles.innerHTML.length) {
1024
1151
  dataStyles.setAttribute("data-styles", "");
@@ -1043,110 +1170,4 @@ var bootstrapLazy = (lazyBundles, options = {}) => {
1043
1170
  // src/runtime/nonce.ts
1044
1171
  var setNonce = (nonce) => plt.$nonce$ = nonce;
1045
1172
 
1046
- // src/client/client-host-ref.ts
1047
- var hostRefs = /* @__PURE__ */ new WeakMap();
1048
- var getHostRef = (ref) => hostRefs.get(ref);
1049
- var registerInstance = (lazyInstance, hostRef) => hostRefs.set(hostRef.$lazyInstance$ = lazyInstance, hostRef);
1050
- var registerHost = (hostElement, cmpMeta) => {
1051
- const hostRef = {
1052
- $flags$: 0,
1053
- $hostElement$: hostElement,
1054
- $cmpMeta$: cmpMeta,
1055
- $instanceValues$: /* @__PURE__ */ new Map()
1056
- };
1057
- {
1058
- hostRef.$onReadyPromise$ = new Promise((r) => hostRef.$onReadyResolve$ = r);
1059
- hostElement["s-p"] = [];
1060
- hostElement["s-rc"] = [];
1061
- }
1062
- return hostRefs.set(hostElement, hostRef);
1063
- };
1064
- var isMemberInElement = (elm, memberName) => memberName in elm;
1065
- var consoleError = (e, el) => (0, console.error)(e, el);
1066
-
1067
- // src/client/client-load-module.ts
1068
- var cmpModules = /* @__PURE__ */ new Map();
1069
- var loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1070
- const exportName = cmpMeta.$tagName$.replace(/-/g, "_");
1071
- const bundleId = cmpMeta.$lazyBundleId$;
1072
- if (!bundleId) {
1073
- return void 0;
1074
- }
1075
- const module = cmpModules.get(bundleId) ;
1076
- if (module) {
1077
- return module[exportName];
1078
- }
1079
- /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
1080
- return import(
1081
- /* @vite-ignore */
1082
- /* webpackInclude: /\.entry\.js$/ */
1083
- /* webpackExclude: /\.system\.entry\.js$/ */
1084
- /* webpackMode: "lazy" */
1085
- `./${bundleId}.entry.js${""}`
1086
- ).then((importedModule) => {
1087
- {
1088
- cmpModules.set(bundleId, importedModule);
1089
- }
1090
- return importedModule[exportName];
1091
- }, consoleError);
1092
- };
1093
-
1094
- // src/client/client-style.ts
1095
- var styles = /* @__PURE__ */ new Map();
1096
- var win = typeof window !== "undefined" ? window : {};
1097
- var doc = win.document || { head: {} };
1098
- var plt = {
1099
- $flags$: 0,
1100
- $resourcesUrl$: "",
1101
- jmp: (h2) => h2(),
1102
- raf: (h2) => requestAnimationFrame(h2),
1103
- ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1104
- rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
1105
- ce: (eventName, opts) => new CustomEvent(eventName, opts)
1106
- };
1107
- var promiseResolve = (v) => Promise.resolve(v);
1108
- var supportsConstructableStylesheets = /* @__PURE__ */ (() => {
1109
- try {
1110
- new CSSStyleSheet();
1111
- return typeof new CSSStyleSheet().replaceSync === "function";
1112
- } catch (e) {
1113
- }
1114
- return false;
1115
- })() ;
1116
- var queuePending = false;
1117
- var queueDomReads = [];
1118
- var queueDomWrites = [];
1119
- var queueTask = (queue, write) => (cb) => {
1120
- queue.push(cb);
1121
- if (!queuePending) {
1122
- queuePending = true;
1123
- if (write && plt.$flags$ & 4 /* queueSync */) {
1124
- nextTick(flush);
1125
- } else {
1126
- plt.raf(flush);
1127
- }
1128
- }
1129
- };
1130
- var consume = (queue) => {
1131
- for (let i2 = 0; i2 < queue.length; i2++) {
1132
- try {
1133
- queue[i2](performance.now());
1134
- } catch (e) {
1135
- consoleError(e);
1136
- }
1137
- }
1138
- queue.length = 0;
1139
- };
1140
- var flush = () => {
1141
- consume(queueDomReads);
1142
- {
1143
- consume(queueDomWrites);
1144
- if (queuePending = queueDomReads.length > 0) {
1145
- plt.raf(flush);
1146
- }
1147
- }
1148
- };
1149
- var nextTick = (cb) => promiseResolve().then(cb);
1150
- var writeTask = /* @__PURE__ */ queueTask(queueDomWrites, true);
1151
-
1152
1173
  export { bootstrapLazy as b, forceUpdate as f, getRenderingRef as g, h, promiseResolve as p, registerInstance as r, setNonce as s };
@@ -1,5 +1,5 @@
1
- import { b as bootstrapLazy } from './index-21d9a03a.js';
2
- export { s as setNonce } from './index-21d9a03a.js';
1
+ import { b as bootstrapLazy } from './index-16e3375c.js';
2
+ export { s as setNonce } from './index-16e3375c.js';
3
3
  import { g as globalScripts } from './app-globals-0f993ce5.js';
4
4
 
5
5
  const defineCustomElements = async (win, options) => {
@@ -1,9 +1,9 @@
1
- import { p as promiseResolve, b as bootstrapLazy } from './index-21d9a03a.js';
2
- export { s as setNonce } from './index-21d9a03a.js';
1
+ import { p as promiseResolve, b as bootstrapLazy } from './index-16e3375c.js';
2
+ export { s as setNonce } from './index-16e3375c.js';
3
3
  import { g as globalScripts } from './app-globals-0f993ce5.js';
4
4
 
5
5
  /*
6
- Stencil Client Patch Browser v4.18.3 | MIT Licensed | https://stenciljs.com
6
+ Stencil Client Patch Browser v4.19.0 | MIT Licensed | https://stenciljs.com
7
7
  */
8
8
  var patchBrowser = () => {
9
9
  const importMeta = import.meta.url;
@@ -1,4 +1,4 @@
1
- import { h, g as getRenderingRef, f as forceUpdate, r as registerInstance } from './index-21d9a03a.js';
1
+ import { h, g as getRenderingRef, f as forceUpdate, r as registerInstance } from './index-16e3375c.js';
2
2
 
3
3
  const Alien = props => {
4
4
  const hex = props.hex || 'currentColor';
@@ -253,7 +253,7 @@ class HTTPError extends Error {
253
253
  const title = response.statusText || '';
254
254
  const status = `${code} ${title}`.trim();
255
255
  const reason = status ? `status code ${status}` : 'an unknown error';
256
- super(`Request failed with ${reason}`);
256
+ super(`Request failed with ${reason}: ${request.method} ${request.url}`);
257
257
  Object.defineProperty(this, "response", {
258
258
  enumerable: true,
259
259
  configurable: true,
@@ -281,7 +281,7 @@ class HTTPError extends Error {
281
281
 
282
282
  class TimeoutError extends Error {
283
283
  constructor(request) {
284
- super('Request timed out');
284
+ super(`Request timed out: ${request.method} ${request.url}`);
285
285
  Object.defineProperty(this, "request", {
286
286
  enumerable: true,
287
287
  configurable: true,
@@ -351,15 +351,24 @@ const supportsRequestStreams = (() => {
351
351
  const supportsReadableStream = typeof globalThis.ReadableStream === 'function';
352
352
  const supportsRequest = typeof globalThis.Request === 'function';
353
353
  if (supportsReadableStream && supportsRequest) {
354
- hasContentType = new globalThis.Request('https://empty.invalid', {
355
- body: new globalThis.ReadableStream(),
356
- method: 'POST',
357
- // @ts-expect-error - Types are outdated.
358
- get duplex() {
359
- duplexAccessed = true;
360
- return 'half';
361
- },
362
- }).headers.has('Content-Type');
354
+ try {
355
+ hasContentType = new globalThis.Request('https://empty.invalid', {
356
+ body: new globalThis.ReadableStream(),
357
+ method: 'POST',
358
+ // @ts-expect-error - Types are outdated.
359
+ get duplex() {
360
+ duplexAccessed = true;
361
+ return 'half';
362
+ },
363
+ }).headers.has('Content-Type');
364
+ }
365
+ catch (error) {
366
+ // QQBrowser on iOS throws "unsupported BodyInit type" error (see issue #581)
367
+ if (error instanceof Error && error.message === 'unsupported BodyInit type') {
368
+ return false;
369
+ }
370
+ throw error;
371
+ }
363
372
  }
364
373
  return duplexAccessed && !hasContentType;
365
374
  })();
@@ -634,6 +643,10 @@ class Ky {
634
643
  // @ts-expect-error - Types are outdated.
635
644
  this._options.duplex = 'half';
636
645
  }
646
+ if (this._options.json !== undefined) {
647
+ this._options.body = this._options.stringifyJson?.(this._options.json) ?? JSON.stringify(this._options.json);
648
+ this._options.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');
649
+ }
637
650
  this.request = new globalThis.Request(this._input, this._options);
638
651
  if (this._options.searchParams) {
639
652
  // eslint-disable-next-line unicorn/prevent-abbreviations
@@ -651,11 +664,6 @@ class Ky {
651
664
  // The spread of `this.request` is required as otherwise it misses the `duplex` option for some reason and throws.
652
665
  this.request = new globalThis.Request(new globalThis.Request(url, { ...this.request }), this._options);
653
666
  }
654
- if (this._options.json !== undefined) {
655
- this._options.body = this._options.stringifyJson?.(this._options.json) ?? JSON.stringify(this._options.json);
656
- this.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');
657
- this.request = new globalThis.Request(this.request, { body: this._options.body });
658
- }
659
667
  }
660
668
  _calculateRetryDelay(error) {
661
669
  this._retryCount++;
@@ -666,17 +674,12 @@ class Ky {
666
674
  }
667
675
  const retryAfter = error.response.headers.get('Retry-After');
668
676
  if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
669
- let after = Number(retryAfter);
677
+ let after = Number(retryAfter) * 1000;
670
678
  if (Number.isNaN(after)) {
671
679
  after = Date.parse(retryAfter) - Date.now();
672
680
  }
673
- else {
674
- after *= 1000;
675
- }
676
- if (this._options.retry.maxRetryAfter !== undefined && after > this._options.retry.maxRetryAfter) {
677
- return 0;
678
- }
679
- return after;
681
+ const max = this._options.retry.maxRetryAfter ?? after;
682
+ return after < max ? after : max;
680
683
  }
681
684
  if (error.response.status === 413) {
682
685
  return 0;
@@ -732,10 +735,13 @@ class Ky {
732
735
  }
733
736
  }
734
737
  const nonRequestOptions = findUnknownOptions(this.request, this._options);
738
+ // Cloning is done here to prepare in advance for retries
739
+ const mainRequest = this.request;
740
+ this.request = mainRequest.clone();
735
741
  if (this._options.timeout === false) {
736
- return this._options.fetch(this.request.clone(), nonRequestOptions);
742
+ return this._options.fetch(mainRequest, nonRequestOptions);
737
743
  }
738
- return timeout(this.request.clone(), nonRequestOptions, this.abortController, this._options);
744
+ return timeout(mainRequest, nonRequestOptions, this.abortController, this._options);
739
745
  }
740
746
  /* istanbul ignore next */
741
747
  _stream(response, onDownloadProgress) {