@pear-protocol/hyperliquid-sdk 0.0.1

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.
package/dist/index.js ADDED
@@ -0,0 +1,2824 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var axios = require('axios');
6
+ var require$$0 = require('react');
7
+ var require$$1 = require('react-dom');
8
+
9
+ /**
10
+ * Main SDK client for Pear Protocol Hyperliquid API integration
11
+ */
12
+ class PearHyperliquidClient {
13
+ constructor(config) {
14
+ this.baseUrl = config.baseUrl.replace(/\/$/, ''); // Remove trailing slash
15
+ this.httpClient = axios.create({
16
+ baseURL: this.baseUrl,
17
+ timeout: config.timeout || 30000,
18
+ headers: {
19
+ 'Content-Type': 'application/json',
20
+ ...config.headers,
21
+ },
22
+ });
23
+ // Add response interceptor for error handling
24
+ this.httpClient.interceptors.response.use((response) => response, (error) => {
25
+ var _a, _b, _c, _d, _e;
26
+ const apiError = {
27
+ statusCode: ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
28
+ message: ((_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || error.message,
29
+ error: (_e = (_d = error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.error,
30
+ };
31
+ return Promise.reject(apiError);
32
+ });
33
+ }
34
+ /**
35
+ * Get the configured base URL
36
+ */
37
+ getBaseUrl() {
38
+ return this.baseUrl;
39
+ }
40
+ /**
41
+ * Update request headers
42
+ */
43
+ setHeaders(headers) {
44
+ this.httpClient.defaults.headers = {
45
+ ...this.httpClient.defaults.headers,
46
+ ...headers,
47
+ };
48
+ }
49
+ /**
50
+ * Set authorization header
51
+ */
52
+ setAuthToken(token) {
53
+ this.setHeaders({ Authorization: `Bearer ${token}` });
54
+ }
55
+ /**
56
+ * Make a generic HTTP request
57
+ */
58
+ async makeRequest(method, endpoint, data) {
59
+ const response = await this.httpClient.request({
60
+ method,
61
+ url: endpoint,
62
+ data,
63
+ });
64
+ return {
65
+ data: response.data,
66
+ status: response.status,
67
+ headers: response.headers,
68
+ };
69
+ }
70
+ /**
71
+ * Sync trade history data from old database structure to new database format
72
+ * @param payload - Trade history data with user address
73
+ * @returns Promise with sync result
74
+ */
75
+ async syncTradeHistory(payload) {
76
+ return this.makeRequest('POST', '/syncer/trade-histories', payload);
77
+ }
78
+ /**
79
+ * Sync open positions data from old database structure to new database format
80
+ * @param payload - Open positions data with user address
81
+ * @returns Promise with sync result
82
+ */
83
+ async syncOpenPositions(payload) {
84
+ return this.makeRequest('POST', '/syncer/open-positions', payload);
85
+ }
86
+ /**
87
+ * Sync open orders data from old database structure to new database format
88
+ * @param payload - Open orders data with user address
89
+ * @returns Promise with sync result
90
+ */
91
+ async syncOpenOrders(payload) {
92
+ return this.makeRequest('POST', '/syncer/open-orders', payload);
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Main Migration SDK Class - Simple request/response pattern
98
+ */
99
+ class PearMigrationSDK {
100
+ constructor(client) {
101
+ this.isSyncRunning = false;
102
+ this.client = client;
103
+ }
104
+ /**
105
+ * Sync trade history data - can only run one at a time
106
+ * If called while already running, returns immediately without making request
107
+ */
108
+ async syncTradeHistory(payload) {
109
+ // If sync is already running, return immediately
110
+ if (this.isSyncRunning) {
111
+ return null;
112
+ }
113
+ try {
114
+ this.isSyncRunning = true;
115
+ const response = await this.client.syncTradeHistory(payload);
116
+ return response;
117
+ }
118
+ finally {
119
+ this.isSyncRunning = false;
120
+ }
121
+ }
122
+ /**
123
+ * Sync open positions data - can only run one at a time
124
+ * If called while already running, returns immediately without making request
125
+ */
126
+ async syncOpenPositions(payload) {
127
+ // If sync is already running, return immediately
128
+ if (this.isSyncRunning) {
129
+ return null;
130
+ }
131
+ try {
132
+ this.isSyncRunning = true;
133
+ const response = await this.client.syncOpenPositions(payload);
134
+ return response;
135
+ }
136
+ finally {
137
+ this.isSyncRunning = false;
138
+ }
139
+ }
140
+ /**
141
+ * Sync open orders data - can only run one at a time
142
+ * If called while already running, returns immediately without making request
143
+ */
144
+ async syncOpenOrders(payload) {
145
+ // If sync is already running, return immediately
146
+ if (this.isSyncRunning) {
147
+ return null;
148
+ }
149
+ try {
150
+ this.isSyncRunning = true;
151
+ const response = await this.client.syncOpenOrders(payload);
152
+ return response;
153
+ }
154
+ finally {
155
+ this.isSyncRunning = false;
156
+ }
157
+ }
158
+ /**
159
+ * Check if sync is currently running
160
+ */
161
+ isSyncInProgress() {
162
+ return this.isSyncRunning;
163
+ }
164
+ /**
165
+ * Get the underlying client instance
166
+ */
167
+ getClient() {
168
+ return this.client;
169
+ }
170
+ /**
171
+ * Set authorization token on the client
172
+ */
173
+ setAuthToken(token) {
174
+ this.client.setAuthToken(token);
175
+ }
176
+ /**
177
+ * Set custom headers on the client
178
+ */
179
+ setHeaders(headers) {
180
+ this.client.setHeaders(headers);
181
+ }
182
+ /**
183
+ * Get base URL from client
184
+ */
185
+ getBaseUrl() {
186
+ return this.client.getBaseUrl();
187
+ }
188
+ }
189
+
190
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
191
+
192
+ function getDefaultExportFromCjs (x) {
193
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
194
+ }
195
+
196
+ var jsxRuntime = {exports: {}};
197
+
198
+ var reactJsxRuntime_production_min = {};
199
+
200
+ /**
201
+ * @license React
202
+ * react-jsx-runtime.production.min.js
203
+ *
204
+ * Copyright (c) Facebook, Inc. and its affiliates.
205
+ *
206
+ * This source code is licensed under the MIT license found in the
207
+ * LICENSE file in the root directory of this source tree.
208
+ */
209
+
210
+ var hasRequiredReactJsxRuntime_production_min;
211
+
212
+ function requireReactJsxRuntime_production_min () {
213
+ if (hasRequiredReactJsxRuntime_production_min) return reactJsxRuntime_production_min;
214
+ hasRequiredReactJsxRuntime_production_min = 1;
215
+ var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};
216
+ function q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=""+g);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return {$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}reactJsxRuntime_production_min.Fragment=l;reactJsxRuntime_production_min.jsx=q;reactJsxRuntime_production_min.jsxs=q;
217
+ return reactJsxRuntime_production_min;
218
+ }
219
+
220
+ var reactJsxRuntime_development = {};
221
+
222
+ /**
223
+ * @license React
224
+ * react-jsx-runtime.development.js
225
+ *
226
+ * Copyright (c) Facebook, Inc. and its affiliates.
227
+ *
228
+ * This source code is licensed under the MIT license found in the
229
+ * LICENSE file in the root directory of this source tree.
230
+ */
231
+
232
+ var hasRequiredReactJsxRuntime_development;
233
+
234
+ function requireReactJsxRuntime_development () {
235
+ if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
236
+ hasRequiredReactJsxRuntime_development = 1;
237
+
238
+ if (process.env.NODE_ENV !== "production") {
239
+ (function() {
240
+
241
+ var React = require$$0;
242
+
243
+ // ATTENTION
244
+ // When adding new symbols to this file,
245
+ // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
246
+ // The Symbol used to tag the ReactElement-like types.
247
+ var REACT_ELEMENT_TYPE = Symbol.for('react.element');
248
+ var REACT_PORTAL_TYPE = Symbol.for('react.portal');
249
+ var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
250
+ var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
251
+ var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
252
+ var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
253
+ var REACT_CONTEXT_TYPE = Symbol.for('react.context');
254
+ var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
255
+ var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
256
+ var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
257
+ var REACT_MEMO_TYPE = Symbol.for('react.memo');
258
+ var REACT_LAZY_TYPE = Symbol.for('react.lazy');
259
+ var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
260
+ var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
261
+ var FAUX_ITERATOR_SYMBOL = '@@iterator';
262
+ function getIteratorFn(maybeIterable) {
263
+ if (maybeIterable === null || typeof maybeIterable !== 'object') {
264
+ return null;
265
+ }
266
+
267
+ var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
268
+
269
+ if (typeof maybeIterator === 'function') {
270
+ return maybeIterator;
271
+ }
272
+
273
+ return null;
274
+ }
275
+
276
+ var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
277
+
278
+ function error(format) {
279
+ {
280
+ {
281
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
282
+ args[_key2 - 1] = arguments[_key2];
283
+ }
284
+
285
+ printWarning('error', format, args);
286
+ }
287
+ }
288
+ }
289
+
290
+ function printWarning(level, format, args) {
291
+ // When changing this logic, you might want to also
292
+ // update consoleWithStackDev.www.js as well.
293
+ {
294
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
295
+ var stack = ReactDebugCurrentFrame.getStackAddendum();
296
+
297
+ if (stack !== '') {
298
+ format += '%s';
299
+ args = args.concat([stack]);
300
+ } // eslint-disable-next-line react-internal/safe-string-coercion
301
+
302
+
303
+ var argsWithFormat = args.map(function (item) {
304
+ return String(item);
305
+ }); // Careful: RN currently depends on this prefix
306
+
307
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
308
+ // breaks IE9: https://github.com/facebook/react/issues/13610
309
+ // eslint-disable-next-line react-internal/no-production-logging
310
+
311
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
312
+ }
313
+ }
314
+
315
+ // -----------------------------------------------------------------------------
316
+
317
+ var enableScopeAPI = false; // Experimental Create Event Handle API.
318
+ var enableCacheElement = false;
319
+ var enableTransitionTracing = false; // No known bugs, but needs performance testing
320
+
321
+ var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in Fiber
322
+ // stuff. Intended to enable React core members to more easily debug scheduling
323
+ // issues in DEV builds.
324
+
325
+ var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
326
+
327
+ var REACT_MODULE_REFERENCE;
328
+
329
+ {
330
+ REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
331
+ }
332
+
333
+ function isValidElementType(type) {
334
+ if (typeof type === 'string' || typeof type === 'function') {
335
+ return true;
336
+ } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
337
+
338
+
339
+ if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || enableDebugTracing || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || enableLegacyHidden || type === REACT_OFFSCREEN_TYPE || enableScopeAPI || enableCacheElement || enableTransitionTracing ) {
340
+ return true;
341
+ }
342
+
343
+ if (typeof type === 'object' && type !== null) {
344
+ if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
345
+ // types supported by any Flight configuration anywhere since
346
+ // we don't know which Flight build this will end up being used
347
+ // with.
348
+ type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
349
+ return true;
350
+ }
351
+ }
352
+
353
+ return false;
354
+ }
355
+
356
+ function getWrappedName(outerType, innerType, wrapperName) {
357
+ var displayName = outerType.displayName;
358
+
359
+ if (displayName) {
360
+ return displayName;
361
+ }
362
+
363
+ var functionName = innerType.displayName || innerType.name || '';
364
+ return functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName;
365
+ } // Keep in sync with react-reconciler/getComponentNameFromFiber
366
+
367
+
368
+ function getContextName(type) {
369
+ return type.displayName || 'Context';
370
+ } // Note that the reconciler package should generally prefer to use getComponentNameFromFiber() instead.
371
+
372
+
373
+ function getComponentNameFromType(type) {
374
+ if (type == null) {
375
+ // Host root, text node or just invalid type.
376
+ return null;
377
+ }
378
+
379
+ {
380
+ if (typeof type.tag === 'number') {
381
+ error('Received an unexpected object in getComponentNameFromType(). ' + 'This is likely a bug in React. Please file an issue.');
382
+ }
383
+ }
384
+
385
+ if (typeof type === 'function') {
386
+ return type.displayName || type.name || null;
387
+ }
388
+
389
+ if (typeof type === 'string') {
390
+ return type;
391
+ }
392
+
393
+ switch (type) {
394
+ case REACT_FRAGMENT_TYPE:
395
+ return 'Fragment';
396
+
397
+ case REACT_PORTAL_TYPE:
398
+ return 'Portal';
399
+
400
+ case REACT_PROFILER_TYPE:
401
+ return 'Profiler';
402
+
403
+ case REACT_STRICT_MODE_TYPE:
404
+ return 'StrictMode';
405
+
406
+ case REACT_SUSPENSE_TYPE:
407
+ return 'Suspense';
408
+
409
+ case REACT_SUSPENSE_LIST_TYPE:
410
+ return 'SuspenseList';
411
+
412
+ }
413
+
414
+ if (typeof type === 'object') {
415
+ switch (type.$$typeof) {
416
+ case REACT_CONTEXT_TYPE:
417
+ var context = type;
418
+ return getContextName(context) + '.Consumer';
419
+
420
+ case REACT_PROVIDER_TYPE:
421
+ var provider = type;
422
+ return getContextName(provider._context) + '.Provider';
423
+
424
+ case REACT_FORWARD_REF_TYPE:
425
+ return getWrappedName(type, type.render, 'ForwardRef');
426
+
427
+ case REACT_MEMO_TYPE:
428
+ var outerName = type.displayName || null;
429
+
430
+ if (outerName !== null) {
431
+ return outerName;
432
+ }
433
+
434
+ return getComponentNameFromType(type.type) || 'Memo';
435
+
436
+ case REACT_LAZY_TYPE:
437
+ {
438
+ var lazyComponent = type;
439
+ var payload = lazyComponent._payload;
440
+ var init = lazyComponent._init;
441
+
442
+ try {
443
+ return getComponentNameFromType(init(payload));
444
+ } catch (x) {
445
+ return null;
446
+ }
447
+ }
448
+
449
+ // eslint-disable-next-line no-fallthrough
450
+ }
451
+ }
452
+
453
+ return null;
454
+ }
455
+
456
+ var assign = Object.assign;
457
+
458
+ // Helpers to patch console.logs to avoid logging during side-effect free
459
+ // replaying on render function. This currently only patches the object
460
+ // lazily which won't cover if the log function was extracted eagerly.
461
+ // We could also eagerly patch the method.
462
+ var disabledDepth = 0;
463
+ var prevLog;
464
+ var prevInfo;
465
+ var prevWarn;
466
+ var prevError;
467
+ var prevGroup;
468
+ var prevGroupCollapsed;
469
+ var prevGroupEnd;
470
+
471
+ function disabledLog() {}
472
+
473
+ disabledLog.__reactDisabledLog = true;
474
+ function disableLogs() {
475
+ {
476
+ if (disabledDepth === 0) {
477
+ /* eslint-disable react-internal/no-production-logging */
478
+ prevLog = console.log;
479
+ prevInfo = console.info;
480
+ prevWarn = console.warn;
481
+ prevError = console.error;
482
+ prevGroup = console.group;
483
+ prevGroupCollapsed = console.groupCollapsed;
484
+ prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
485
+
486
+ var props = {
487
+ configurable: true,
488
+ enumerable: true,
489
+ value: disabledLog,
490
+ writable: true
491
+ }; // $FlowFixMe Flow thinks console is immutable.
492
+
493
+ Object.defineProperties(console, {
494
+ info: props,
495
+ log: props,
496
+ warn: props,
497
+ error: props,
498
+ group: props,
499
+ groupCollapsed: props,
500
+ groupEnd: props
501
+ });
502
+ /* eslint-enable react-internal/no-production-logging */
503
+ }
504
+
505
+ disabledDepth++;
506
+ }
507
+ }
508
+ function reenableLogs() {
509
+ {
510
+ disabledDepth--;
511
+
512
+ if (disabledDepth === 0) {
513
+ /* eslint-disable react-internal/no-production-logging */
514
+ var props = {
515
+ configurable: true,
516
+ enumerable: true,
517
+ writable: true
518
+ }; // $FlowFixMe Flow thinks console is immutable.
519
+
520
+ Object.defineProperties(console, {
521
+ log: assign({}, props, {
522
+ value: prevLog
523
+ }),
524
+ info: assign({}, props, {
525
+ value: prevInfo
526
+ }),
527
+ warn: assign({}, props, {
528
+ value: prevWarn
529
+ }),
530
+ error: assign({}, props, {
531
+ value: prevError
532
+ }),
533
+ group: assign({}, props, {
534
+ value: prevGroup
535
+ }),
536
+ groupCollapsed: assign({}, props, {
537
+ value: prevGroupCollapsed
538
+ }),
539
+ groupEnd: assign({}, props, {
540
+ value: prevGroupEnd
541
+ })
542
+ });
543
+ /* eslint-enable react-internal/no-production-logging */
544
+ }
545
+
546
+ if (disabledDepth < 0) {
547
+ error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
548
+ }
549
+ }
550
+ }
551
+
552
+ var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
553
+ var prefix;
554
+ function describeBuiltInComponentFrame(name, source, ownerFn) {
555
+ {
556
+ if (prefix === undefined) {
557
+ // Extract the VM specific prefix used by each line.
558
+ try {
559
+ throw Error();
560
+ } catch (x) {
561
+ var match = x.stack.trim().match(/\n( *(at )?)/);
562
+ prefix = match && match[1] || '';
563
+ }
564
+ } // We use the prefix to ensure our stacks line up with native stack frames.
565
+
566
+
567
+ return '\n' + prefix + name;
568
+ }
569
+ }
570
+ var reentry = false;
571
+ var componentFrameCache;
572
+
573
+ {
574
+ var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
575
+ componentFrameCache = new PossiblyWeakMap();
576
+ }
577
+
578
+ function describeNativeComponentFrame(fn, construct) {
579
+ // If something asked for a stack inside a fake render, it should get ignored.
580
+ if ( !fn || reentry) {
581
+ return '';
582
+ }
583
+
584
+ {
585
+ var frame = componentFrameCache.get(fn);
586
+
587
+ if (frame !== undefined) {
588
+ return frame;
589
+ }
590
+ }
591
+
592
+ var control;
593
+ reentry = true;
594
+ var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
595
+
596
+ Error.prepareStackTrace = undefined;
597
+ var previousDispatcher;
598
+
599
+ {
600
+ previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
601
+ // for warnings.
602
+
603
+ ReactCurrentDispatcher.current = null;
604
+ disableLogs();
605
+ }
606
+
607
+ try {
608
+ // This should throw.
609
+ if (construct) {
610
+ // Something should be setting the props in the constructor.
611
+ var Fake = function () {
612
+ throw Error();
613
+ }; // $FlowFixMe
614
+
615
+
616
+ Object.defineProperty(Fake.prototype, 'props', {
617
+ set: function () {
618
+ // We use a throwing setter instead of frozen or non-writable props
619
+ // because that won't throw in a non-strict mode function.
620
+ throw Error();
621
+ }
622
+ });
623
+
624
+ if (typeof Reflect === 'object' && Reflect.construct) {
625
+ // We construct a different control for this case to include any extra
626
+ // frames added by the construct call.
627
+ try {
628
+ Reflect.construct(Fake, []);
629
+ } catch (x) {
630
+ control = x;
631
+ }
632
+
633
+ Reflect.construct(fn, [], Fake);
634
+ } else {
635
+ try {
636
+ Fake.call();
637
+ } catch (x) {
638
+ control = x;
639
+ }
640
+
641
+ fn.call(Fake.prototype);
642
+ }
643
+ } else {
644
+ try {
645
+ throw Error();
646
+ } catch (x) {
647
+ control = x;
648
+ }
649
+
650
+ fn();
651
+ }
652
+ } catch (sample) {
653
+ // This is inlined manually because closure doesn't do it for us.
654
+ if (sample && control && typeof sample.stack === 'string') {
655
+ // This extracts the first frame from the sample that isn't also in the control.
656
+ // Skipping one frame that we assume is the frame that calls the two.
657
+ var sampleLines = sample.stack.split('\n');
658
+ var controlLines = control.stack.split('\n');
659
+ var s = sampleLines.length - 1;
660
+ var c = controlLines.length - 1;
661
+
662
+ while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
663
+ // We expect at least one stack frame to be shared.
664
+ // Typically this will be the root most one. However, stack frames may be
665
+ // cut off due to maximum stack limits. In this case, one maybe cut off
666
+ // earlier than the other. We assume that the sample is longer or the same
667
+ // and there for cut off earlier. So we should find the root most frame in
668
+ // the sample somewhere in the control.
669
+ c--;
670
+ }
671
+
672
+ for (; s >= 1 && c >= 0; s--, c--) {
673
+ // Next we find the first one that isn't the same which should be the
674
+ // frame that called our sample function and the control.
675
+ if (sampleLines[s] !== controlLines[c]) {
676
+ // In V8, the first line is describing the message but other VMs don't.
677
+ // If we're about to return the first line, and the control is also on the same
678
+ // line, that's a pretty good indicator that our sample threw at same line as
679
+ // the control. I.e. before we entered the sample frame. So we ignore this result.
680
+ // This can happen if you passed a class to function component, or non-function.
681
+ if (s !== 1 || c !== 1) {
682
+ do {
683
+ s--;
684
+ c--; // We may still have similar intermediate frames from the construct call.
685
+ // The next one that isn't the same should be our match though.
686
+
687
+ if (c < 0 || sampleLines[s] !== controlLines[c]) {
688
+ // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
689
+ var _frame = '\n' + sampleLines[s].replace(' at new ', ' at '); // If our component frame is labeled "<anonymous>"
690
+ // but we have a user-provided "displayName"
691
+ // splice it in to make the stack more readable.
692
+
693
+
694
+ if (fn.displayName && _frame.includes('<anonymous>')) {
695
+ _frame = _frame.replace('<anonymous>', fn.displayName);
696
+ }
697
+
698
+ {
699
+ if (typeof fn === 'function') {
700
+ componentFrameCache.set(fn, _frame);
701
+ }
702
+ } // Return the line we found.
703
+
704
+
705
+ return _frame;
706
+ }
707
+ } while (s >= 1 && c >= 0);
708
+ }
709
+
710
+ break;
711
+ }
712
+ }
713
+ }
714
+ } finally {
715
+ reentry = false;
716
+
717
+ {
718
+ ReactCurrentDispatcher.current = previousDispatcher;
719
+ reenableLogs();
720
+ }
721
+
722
+ Error.prepareStackTrace = previousPrepareStackTrace;
723
+ } // Fallback to just using the name if we couldn't make it throw.
724
+
725
+
726
+ var name = fn ? fn.displayName || fn.name : '';
727
+ var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
728
+
729
+ {
730
+ if (typeof fn === 'function') {
731
+ componentFrameCache.set(fn, syntheticFrame);
732
+ }
733
+ }
734
+
735
+ return syntheticFrame;
736
+ }
737
+ function describeFunctionComponentFrame(fn, source, ownerFn) {
738
+ {
739
+ return describeNativeComponentFrame(fn, false);
740
+ }
741
+ }
742
+
743
+ function shouldConstruct(Component) {
744
+ var prototype = Component.prototype;
745
+ return !!(prototype && prototype.isReactComponent);
746
+ }
747
+
748
+ function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
749
+
750
+ if (type == null) {
751
+ return '';
752
+ }
753
+
754
+ if (typeof type === 'function') {
755
+ {
756
+ return describeNativeComponentFrame(type, shouldConstruct(type));
757
+ }
758
+ }
759
+
760
+ if (typeof type === 'string') {
761
+ return describeBuiltInComponentFrame(type);
762
+ }
763
+
764
+ switch (type) {
765
+ case REACT_SUSPENSE_TYPE:
766
+ return describeBuiltInComponentFrame('Suspense');
767
+
768
+ case REACT_SUSPENSE_LIST_TYPE:
769
+ return describeBuiltInComponentFrame('SuspenseList');
770
+ }
771
+
772
+ if (typeof type === 'object') {
773
+ switch (type.$$typeof) {
774
+ case REACT_FORWARD_REF_TYPE:
775
+ return describeFunctionComponentFrame(type.render);
776
+
777
+ case REACT_MEMO_TYPE:
778
+ // Memo may contain any component type so we recursively resolve it.
779
+ return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
780
+
781
+ case REACT_LAZY_TYPE:
782
+ {
783
+ var lazyComponent = type;
784
+ var payload = lazyComponent._payload;
785
+ var init = lazyComponent._init;
786
+
787
+ try {
788
+ // Lazy may contain any component type so we recursively resolve it.
789
+ return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
790
+ } catch (x) {}
791
+ }
792
+ }
793
+ }
794
+
795
+ return '';
796
+ }
797
+
798
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
799
+
800
+ var loggedTypeFailures = {};
801
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
802
+
803
+ function setCurrentlyValidatingElement(element) {
804
+ {
805
+ if (element) {
806
+ var owner = element._owner;
807
+ var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
808
+ ReactDebugCurrentFrame.setExtraStackFrame(stack);
809
+ } else {
810
+ ReactDebugCurrentFrame.setExtraStackFrame(null);
811
+ }
812
+ }
813
+ }
814
+
815
+ function checkPropTypes(typeSpecs, values, location, componentName, element) {
816
+ {
817
+ // $FlowFixMe This is okay but Flow doesn't know it.
818
+ var has = Function.call.bind(hasOwnProperty);
819
+
820
+ for (var typeSpecName in typeSpecs) {
821
+ if (has(typeSpecs, typeSpecName)) {
822
+ var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
823
+ // fail the render phase where it didn't fail before. So we log it.
824
+ // After these have been cleaned up, we'll let them throw.
825
+
826
+ try {
827
+ // This is intentionally an invariant that gets caught. It's the same
828
+ // behavior as without this statement except with a better message.
829
+ if (typeof typeSpecs[typeSpecName] !== 'function') {
830
+ // eslint-disable-next-line react-internal/prod-error-codes
831
+ var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.');
832
+ err.name = 'Invariant Violation';
833
+ throw err;
834
+ }
835
+
836
+ error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
837
+ } catch (ex) {
838
+ error$1 = ex;
839
+ }
840
+
841
+ if (error$1 && !(error$1 instanceof Error)) {
842
+ setCurrentlyValidatingElement(element);
843
+
844
+ error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1);
845
+
846
+ setCurrentlyValidatingElement(null);
847
+ }
848
+
849
+ if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
850
+ // Only monitor this failure once because there tends to be a lot of the
851
+ // same error.
852
+ loggedTypeFailures[error$1.message] = true;
853
+ setCurrentlyValidatingElement(element);
854
+
855
+ error('Failed %s type: %s', location, error$1.message);
856
+
857
+ setCurrentlyValidatingElement(null);
858
+ }
859
+ }
860
+ }
861
+ }
862
+ }
863
+
864
+ var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
865
+
866
+ function isArray(a) {
867
+ return isArrayImpl(a);
868
+ }
869
+
870
+ /*
871
+ * The `'' + value` pattern (used in in perf-sensitive code) throws for Symbol
872
+ * and Temporal.* types. See https://github.com/facebook/react/pull/22064.
873
+ *
874
+ * The functions in this module will throw an easier-to-understand,
875
+ * easier-to-debug exception with a clear errors message message explaining the
876
+ * problem. (Instead of a confusing exception thrown inside the implementation
877
+ * of the `value` object).
878
+ */
879
+ // $FlowFixMe only called in DEV, so void return is not possible.
880
+ function typeName(value) {
881
+ {
882
+ // toStringTag is needed for namespaced types like Temporal.Instant
883
+ var hasToStringTag = typeof Symbol === 'function' && Symbol.toStringTag;
884
+ var type = hasToStringTag && value[Symbol.toStringTag] || value.constructor.name || 'Object';
885
+ return type;
886
+ }
887
+ } // $FlowFixMe only called in DEV, so void return is not possible.
888
+
889
+
890
+ function willCoercionThrow(value) {
891
+ {
892
+ try {
893
+ testStringCoercion(value);
894
+ return false;
895
+ } catch (e) {
896
+ return true;
897
+ }
898
+ }
899
+ }
900
+
901
+ function testStringCoercion(value) {
902
+ // If you ended up here by following an exception call stack, here's what's
903
+ // happened: you supplied an object or symbol value to React (as a prop, key,
904
+ // DOM attribute, CSS property, string ref, etc.) and when React tried to
905
+ // coerce it to a string using `'' + value`, an exception was thrown.
906
+ //
907
+ // The most common types that will cause this exception are `Symbol` instances
908
+ // and Temporal objects like `Temporal.Instant`. But any object that has a
909
+ // `valueOf` or `[Symbol.toPrimitive]` method that throws will also cause this
910
+ // exception. (Library authors do this to prevent users from using built-in
911
+ // numeric operators like `+` or comparison operators like `>=` because custom
912
+ // methods are needed to perform accurate arithmetic or comparison.)
913
+ //
914
+ // To fix the problem, coerce this object or symbol value to a string before
915
+ // passing it to React. The most reliable way is usually `String(value)`.
916
+ //
917
+ // To find which value is throwing, check the browser or debugger console.
918
+ // Before this exception was thrown, there should be `console.error` output
919
+ // that shows the type (Symbol, Temporal.PlainDate, etc.) that caused the
920
+ // problem and how that type was used: key, atrribute, input value prop, etc.
921
+ // In most cases, this console output also shows the component and its
922
+ // ancestor components where the exception happened.
923
+ //
924
+ // eslint-disable-next-line react-internal/safe-string-coercion
925
+ return '' + value;
926
+ }
927
+ function checkKeyStringCoercion(value) {
928
+ {
929
+ if (willCoercionThrow(value)) {
930
+ error('The provided key is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', typeName(value));
931
+
932
+ return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
933
+ }
934
+ }
935
+ }
936
+
937
+ var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
938
+ var RESERVED_PROPS = {
939
+ key: true,
940
+ ref: true,
941
+ __self: true,
942
+ __source: true
943
+ };
944
+ var specialPropKeyWarningShown;
945
+ var specialPropRefWarningShown;
946
+ var didWarnAboutStringRefs;
947
+
948
+ {
949
+ didWarnAboutStringRefs = {};
950
+ }
951
+
952
+ function hasValidRef(config) {
953
+ {
954
+ if (hasOwnProperty.call(config, 'ref')) {
955
+ var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
956
+
957
+ if (getter && getter.isReactWarning) {
958
+ return false;
959
+ }
960
+ }
961
+ }
962
+
963
+ return config.ref !== undefined;
964
+ }
965
+
966
+ function hasValidKey(config) {
967
+ {
968
+ if (hasOwnProperty.call(config, 'key')) {
969
+ var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
970
+
971
+ if (getter && getter.isReactWarning) {
972
+ return false;
973
+ }
974
+ }
975
+ }
976
+
977
+ return config.key !== undefined;
978
+ }
979
+
980
+ function warnIfStringRefCannotBeAutoConverted(config, self) {
981
+ {
982
+ if (typeof config.ref === 'string' && ReactCurrentOwner.current && self && ReactCurrentOwner.current.stateNode !== self) {
983
+ var componentName = getComponentNameFromType(ReactCurrentOwner.current.type);
984
+
985
+ if (!didWarnAboutStringRefs[componentName]) {
986
+ error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref', getComponentNameFromType(ReactCurrentOwner.current.type), config.ref);
987
+
988
+ didWarnAboutStringRefs[componentName] = true;
989
+ }
990
+ }
991
+ }
992
+ }
993
+
994
+ function defineKeyPropWarningGetter(props, displayName) {
995
+ {
996
+ var warnAboutAccessingKey = function () {
997
+ if (!specialPropKeyWarningShown) {
998
+ specialPropKeyWarningShown = true;
999
+
1000
+ error('%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
1001
+ }
1002
+ };
1003
+
1004
+ warnAboutAccessingKey.isReactWarning = true;
1005
+ Object.defineProperty(props, 'key', {
1006
+ get: warnAboutAccessingKey,
1007
+ configurable: true
1008
+ });
1009
+ }
1010
+ }
1011
+
1012
+ function defineRefPropWarningGetter(props, displayName) {
1013
+ {
1014
+ var warnAboutAccessingRef = function () {
1015
+ if (!specialPropRefWarningShown) {
1016
+ specialPropRefWarningShown = true;
1017
+
1018
+ error('%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
1019
+ }
1020
+ };
1021
+
1022
+ warnAboutAccessingRef.isReactWarning = true;
1023
+ Object.defineProperty(props, 'ref', {
1024
+ get: warnAboutAccessingRef,
1025
+ configurable: true
1026
+ });
1027
+ }
1028
+ }
1029
+ /**
1030
+ * Factory method to create a new React element. This no longer adheres to
1031
+ * the class pattern, so do not use new to call it. Also, instanceof check
1032
+ * will not work. Instead test $$typeof field against Symbol.for('react.element') to check
1033
+ * if something is a React Element.
1034
+ *
1035
+ * @param {*} type
1036
+ * @param {*} props
1037
+ * @param {*} key
1038
+ * @param {string|object} ref
1039
+ * @param {*} owner
1040
+ * @param {*} self A *temporary* helper to detect places where `this` is
1041
+ * different from the `owner` when React.createElement is called, so that we
1042
+ * can warn. We want to get rid of owner and replace string `ref`s with arrow
1043
+ * functions, and as long as `this` and owner are the same, there will be no
1044
+ * change in behavior.
1045
+ * @param {*} source An annotation object (added by a transpiler or otherwise)
1046
+ * indicating filename, line number, and/or other information.
1047
+ * @internal
1048
+ */
1049
+
1050
+
1051
+ var ReactElement = function (type, key, ref, self, source, owner, props) {
1052
+ var element = {
1053
+ // This tag allows us to uniquely identify this as a React Element
1054
+ $$typeof: REACT_ELEMENT_TYPE,
1055
+ // Built-in properties that belong on the element
1056
+ type: type,
1057
+ key: key,
1058
+ ref: ref,
1059
+ props: props,
1060
+ // Record the component responsible for creating this element.
1061
+ _owner: owner
1062
+ };
1063
+
1064
+ {
1065
+ // The validation flag is currently mutative. We put it on
1066
+ // an external backing store so that we can freeze the whole object.
1067
+ // This can be replaced with a WeakMap once they are implemented in
1068
+ // commonly used development environments.
1069
+ element._store = {}; // To make comparing ReactElements easier for testing purposes, we make
1070
+ // the validation flag non-enumerable (where possible, which should
1071
+ // include every environment we run tests in), so the test framework
1072
+ // ignores it.
1073
+
1074
+ Object.defineProperty(element._store, 'validated', {
1075
+ configurable: false,
1076
+ enumerable: false,
1077
+ writable: true,
1078
+ value: false
1079
+ }); // self and source are DEV only properties.
1080
+
1081
+ Object.defineProperty(element, '_self', {
1082
+ configurable: false,
1083
+ enumerable: false,
1084
+ writable: false,
1085
+ value: self
1086
+ }); // Two elements created in two different places should be considered
1087
+ // equal for testing purposes and therefore we hide it from enumeration.
1088
+
1089
+ Object.defineProperty(element, '_source', {
1090
+ configurable: false,
1091
+ enumerable: false,
1092
+ writable: false,
1093
+ value: source
1094
+ });
1095
+
1096
+ if (Object.freeze) {
1097
+ Object.freeze(element.props);
1098
+ Object.freeze(element);
1099
+ }
1100
+ }
1101
+
1102
+ return element;
1103
+ };
1104
+ /**
1105
+ * https://github.com/reactjs/rfcs/pull/107
1106
+ * @param {*} type
1107
+ * @param {object} props
1108
+ * @param {string} key
1109
+ */
1110
+
1111
+ function jsxDEV(type, config, maybeKey, source, self) {
1112
+ {
1113
+ var propName; // Reserved names are extracted
1114
+
1115
+ var props = {};
1116
+ var key = null;
1117
+ var ref = null; // Currently, key can be spread in as a prop. This causes a potential
1118
+ // issue if key is also explicitly declared (ie. <div {...props} key="Hi" />
1119
+ // or <div key="Hi" {...props} /> ). We want to deprecate key spread,
1120
+ // but as an intermediary step, we will use jsxDEV for everything except
1121
+ // <div {...props} key="Hi" />, because we aren't currently able to tell if
1122
+ // key is explicitly declared to be undefined or not.
1123
+
1124
+ if (maybeKey !== undefined) {
1125
+ {
1126
+ checkKeyStringCoercion(maybeKey);
1127
+ }
1128
+
1129
+ key = '' + maybeKey;
1130
+ }
1131
+
1132
+ if (hasValidKey(config)) {
1133
+ {
1134
+ checkKeyStringCoercion(config.key);
1135
+ }
1136
+
1137
+ key = '' + config.key;
1138
+ }
1139
+
1140
+ if (hasValidRef(config)) {
1141
+ ref = config.ref;
1142
+ warnIfStringRefCannotBeAutoConverted(config, self);
1143
+ } // Remaining properties are added to a new props object
1144
+
1145
+
1146
+ for (propName in config) {
1147
+ if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
1148
+ props[propName] = config[propName];
1149
+ }
1150
+ } // Resolve default props
1151
+
1152
+
1153
+ if (type && type.defaultProps) {
1154
+ var defaultProps = type.defaultProps;
1155
+
1156
+ for (propName in defaultProps) {
1157
+ if (props[propName] === undefined) {
1158
+ props[propName] = defaultProps[propName];
1159
+ }
1160
+ }
1161
+ }
1162
+
1163
+ if (key || ref) {
1164
+ var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
1165
+
1166
+ if (key) {
1167
+ defineKeyPropWarningGetter(props, displayName);
1168
+ }
1169
+
1170
+ if (ref) {
1171
+ defineRefPropWarningGetter(props, displayName);
1172
+ }
1173
+ }
1174
+
1175
+ return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
1176
+ }
1177
+ }
1178
+
1179
+ var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
1180
+ var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
1181
+
1182
+ function setCurrentlyValidatingElement$1(element) {
1183
+ {
1184
+ if (element) {
1185
+ var owner = element._owner;
1186
+ var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
1187
+ ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
1188
+ } else {
1189
+ ReactDebugCurrentFrame$1.setExtraStackFrame(null);
1190
+ }
1191
+ }
1192
+ }
1193
+
1194
+ var propTypesMisspellWarningShown;
1195
+
1196
+ {
1197
+ propTypesMisspellWarningShown = false;
1198
+ }
1199
+ /**
1200
+ * Verifies the object is a ReactElement.
1201
+ * See https://reactjs.org/docs/react-api.html#isvalidelement
1202
+ * @param {?object} object
1203
+ * @return {boolean} True if `object` is a ReactElement.
1204
+ * @final
1205
+ */
1206
+
1207
+
1208
+ function isValidElement(object) {
1209
+ {
1210
+ return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
1211
+ }
1212
+ }
1213
+
1214
+ function getDeclarationErrorAddendum() {
1215
+ {
1216
+ if (ReactCurrentOwner$1.current) {
1217
+ var name = getComponentNameFromType(ReactCurrentOwner$1.current.type);
1218
+
1219
+ if (name) {
1220
+ return '\n\nCheck the render method of `' + name + '`.';
1221
+ }
1222
+ }
1223
+
1224
+ return '';
1225
+ }
1226
+ }
1227
+
1228
+ function getSourceInfoErrorAddendum(source) {
1229
+ {
1230
+ if (source !== undefined) {
1231
+ var fileName = source.fileName.replace(/^.*[\\\/]/, '');
1232
+ var lineNumber = source.lineNumber;
1233
+ return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
1234
+ }
1235
+
1236
+ return '';
1237
+ }
1238
+ }
1239
+ /**
1240
+ * Warn if there's no key explicitly set on dynamic arrays of children or
1241
+ * object keys are not valid. This allows us to keep track of children between
1242
+ * updates.
1243
+ */
1244
+
1245
+
1246
+ var ownerHasKeyUseWarning = {};
1247
+
1248
+ function getCurrentComponentErrorInfo(parentType) {
1249
+ {
1250
+ var info = getDeclarationErrorAddendum();
1251
+
1252
+ if (!info) {
1253
+ var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
1254
+
1255
+ if (parentName) {
1256
+ info = "\n\nCheck the top-level render call using <" + parentName + ">.";
1257
+ }
1258
+ }
1259
+
1260
+ return info;
1261
+ }
1262
+ }
1263
+ /**
1264
+ * Warn if the element doesn't have an explicit key assigned to it.
1265
+ * This element is in an array. The array could grow and shrink or be
1266
+ * reordered. All children that haven't already been validated are required to
1267
+ * have a "key" property assigned to it. Error statuses are cached so a warning
1268
+ * will only be shown once.
1269
+ *
1270
+ * @internal
1271
+ * @param {ReactElement} element Element that requires a key.
1272
+ * @param {*} parentType element's parent's type.
1273
+ */
1274
+
1275
+
1276
+ function validateExplicitKey(element, parentType) {
1277
+ {
1278
+ if (!element._store || element._store.validated || element.key != null) {
1279
+ return;
1280
+ }
1281
+
1282
+ element._store.validated = true;
1283
+ var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
1284
+
1285
+ if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
1286
+ return;
1287
+ }
1288
+
1289
+ ownerHasKeyUseWarning[currentComponentErrorInfo] = true; // Usually the current owner is the offender, but if it accepts children as a
1290
+ // property, it may be the creator of the child that's responsible for
1291
+ // assigning it a key.
1292
+
1293
+ var childOwner = '';
1294
+
1295
+ if (element && element._owner && element._owner !== ReactCurrentOwner$1.current) {
1296
+ // Give the component that originally created this child.
1297
+ childOwner = " It was passed a child from " + getComponentNameFromType(element._owner.type) + ".";
1298
+ }
1299
+
1300
+ setCurrentlyValidatingElement$1(element);
1301
+
1302
+ error('Each child in a list should have a unique "key" prop.' + '%s%s See https://reactjs.org/link/warning-keys for more information.', currentComponentErrorInfo, childOwner);
1303
+
1304
+ setCurrentlyValidatingElement$1(null);
1305
+ }
1306
+ }
1307
+ /**
1308
+ * Ensure that every element either is passed in a static location, in an
1309
+ * array with an explicit keys property defined, or in an object literal
1310
+ * with valid key property.
1311
+ *
1312
+ * @internal
1313
+ * @param {ReactNode} node Statically passed child of any type.
1314
+ * @param {*} parentType node's parent's type.
1315
+ */
1316
+
1317
+
1318
+ function validateChildKeys(node, parentType) {
1319
+ {
1320
+ if (typeof node !== 'object') {
1321
+ return;
1322
+ }
1323
+
1324
+ if (isArray(node)) {
1325
+ for (var i = 0; i < node.length; i++) {
1326
+ var child = node[i];
1327
+
1328
+ if (isValidElement(child)) {
1329
+ validateExplicitKey(child, parentType);
1330
+ }
1331
+ }
1332
+ } else if (isValidElement(node)) {
1333
+ // This element was passed in a valid location.
1334
+ if (node._store) {
1335
+ node._store.validated = true;
1336
+ }
1337
+ } else if (node) {
1338
+ var iteratorFn = getIteratorFn(node);
1339
+
1340
+ if (typeof iteratorFn === 'function') {
1341
+ // Entry iterators used to provide implicit keys,
1342
+ // but now we print a separate warning for them later.
1343
+ if (iteratorFn !== node.entries) {
1344
+ var iterator = iteratorFn.call(node);
1345
+ var step;
1346
+
1347
+ while (!(step = iterator.next()).done) {
1348
+ if (isValidElement(step.value)) {
1349
+ validateExplicitKey(step.value, parentType);
1350
+ }
1351
+ }
1352
+ }
1353
+ }
1354
+ }
1355
+ }
1356
+ }
1357
+ /**
1358
+ * Given an element, validate that its props follow the propTypes definition,
1359
+ * provided by the type.
1360
+ *
1361
+ * @param {ReactElement} element
1362
+ */
1363
+
1364
+
1365
+ function validatePropTypes(element) {
1366
+ {
1367
+ var type = element.type;
1368
+
1369
+ if (type === null || type === undefined || typeof type === 'string') {
1370
+ return;
1371
+ }
1372
+
1373
+ var propTypes;
1374
+
1375
+ if (typeof type === 'function') {
1376
+ propTypes = type.propTypes;
1377
+ } else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here.
1378
+ // Inner props are checked in the reconciler.
1379
+ type.$$typeof === REACT_MEMO_TYPE)) {
1380
+ propTypes = type.propTypes;
1381
+ } else {
1382
+ return;
1383
+ }
1384
+
1385
+ if (propTypes) {
1386
+ // Intentionally inside to avoid triggering lazy initializers:
1387
+ var name = getComponentNameFromType(type);
1388
+ checkPropTypes(propTypes, element.props, 'prop', name, element);
1389
+ } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
1390
+ propTypesMisspellWarningShown = true; // Intentionally inside to avoid triggering lazy initializers:
1391
+
1392
+ var _name = getComponentNameFromType(type);
1393
+
1394
+ error('Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', _name || 'Unknown');
1395
+ }
1396
+
1397
+ if (typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved) {
1398
+ error('getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.');
1399
+ }
1400
+ }
1401
+ }
1402
+ /**
1403
+ * Given a fragment, validate that it can only be provided with fragment props
1404
+ * @param {ReactElement} fragment
1405
+ */
1406
+
1407
+
1408
+ function validateFragmentProps(fragment) {
1409
+ {
1410
+ var keys = Object.keys(fragment.props);
1411
+
1412
+ for (var i = 0; i < keys.length; i++) {
1413
+ var key = keys[i];
1414
+
1415
+ if (key !== 'children' && key !== 'key') {
1416
+ setCurrentlyValidatingElement$1(fragment);
1417
+
1418
+ error('Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key);
1419
+
1420
+ setCurrentlyValidatingElement$1(null);
1421
+ break;
1422
+ }
1423
+ }
1424
+
1425
+ if (fragment.ref !== null) {
1426
+ setCurrentlyValidatingElement$1(fragment);
1427
+
1428
+ error('Invalid attribute `ref` supplied to `React.Fragment`.');
1429
+
1430
+ setCurrentlyValidatingElement$1(null);
1431
+ }
1432
+ }
1433
+ }
1434
+
1435
+ var didWarnAboutKeySpread = {};
1436
+ function jsxWithValidation(type, props, key, isStaticChildren, source, self) {
1437
+ {
1438
+ var validType = isValidElementType(type); // We warn in this case but don't throw. We expect the element creation to
1439
+ // succeed and there will likely be errors in render.
1440
+
1441
+ if (!validType) {
1442
+ var info = '';
1443
+
1444
+ if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
1445
+ info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
1446
+ }
1447
+
1448
+ var sourceInfo = getSourceInfoErrorAddendum(source);
1449
+
1450
+ if (sourceInfo) {
1451
+ info += sourceInfo;
1452
+ } else {
1453
+ info += getDeclarationErrorAddendum();
1454
+ }
1455
+
1456
+ var typeString;
1457
+
1458
+ if (type === null) {
1459
+ typeString = 'null';
1460
+ } else if (isArray(type)) {
1461
+ typeString = 'array';
1462
+ } else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
1463
+ typeString = "<" + (getComponentNameFromType(type.type) || 'Unknown') + " />";
1464
+ info = ' Did you accidentally export a JSX literal instead of a component?';
1465
+ } else {
1466
+ typeString = typeof type;
1467
+ }
1468
+
1469
+ error('React.jsx: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
1470
+ }
1471
+
1472
+ var element = jsxDEV(type, props, key, source, self); // The result can be nullish if a mock or a custom function is used.
1473
+ // TODO: Drop this when these are no longer allowed as the type argument.
1474
+
1475
+ if (element == null) {
1476
+ return element;
1477
+ } // Skip key warning if the type isn't valid since our key validation logic
1478
+ // doesn't expect a non-string/function type and can throw confusing errors.
1479
+ // We don't want exception behavior to differ between dev and prod.
1480
+ // (Rendering will throw with a helpful message and as soon as the type is
1481
+ // fixed, the key warnings will appear.)
1482
+
1483
+
1484
+ if (validType) {
1485
+ var children = props.children;
1486
+
1487
+ if (children !== undefined) {
1488
+ if (isStaticChildren) {
1489
+ if (isArray(children)) {
1490
+ for (var i = 0; i < children.length; i++) {
1491
+ validateChildKeys(children[i], type);
1492
+ }
1493
+
1494
+ if (Object.freeze) {
1495
+ Object.freeze(children);
1496
+ }
1497
+ } else {
1498
+ error('React.jsx: Static children should always be an array. ' + 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' + 'Use the Babel transform instead.');
1499
+ }
1500
+ } else {
1501
+ validateChildKeys(children, type);
1502
+ }
1503
+ }
1504
+ }
1505
+
1506
+ {
1507
+ if (hasOwnProperty.call(props, 'key')) {
1508
+ var componentName = getComponentNameFromType(type);
1509
+ var keys = Object.keys(props).filter(function (k) {
1510
+ return k !== 'key';
1511
+ });
1512
+ var beforeExample = keys.length > 0 ? '{key: someKey, ' + keys.join(': ..., ') + ': ...}' : '{key: someKey}';
1513
+
1514
+ if (!didWarnAboutKeySpread[componentName + beforeExample]) {
1515
+ var afterExample = keys.length > 0 ? '{' + keys.join(': ..., ') + ': ...}' : '{}';
1516
+
1517
+ error('A props object containing a "key" prop is being spread into JSX:\n' + ' let props = %s;\n' + ' <%s {...props} />\n' + 'React keys must be passed directly to JSX without using spread:\n' + ' let props = %s;\n' + ' <%s key={someKey} {...props} />', beforeExample, componentName, afterExample, componentName);
1518
+
1519
+ didWarnAboutKeySpread[componentName + beforeExample] = true;
1520
+ }
1521
+ }
1522
+ }
1523
+
1524
+ if (type === REACT_FRAGMENT_TYPE) {
1525
+ validateFragmentProps(element);
1526
+ } else {
1527
+ validatePropTypes(element);
1528
+ }
1529
+
1530
+ return element;
1531
+ }
1532
+ } // These two functions exist to still get child warnings in dev
1533
+ // even with the prod transform. This means that jsxDEV is purely
1534
+ // opt-in behavior for better messages but that we won't stop
1535
+ // giving you warnings if you use production apis.
1536
+
1537
+ function jsxWithValidationStatic(type, props, key) {
1538
+ {
1539
+ return jsxWithValidation(type, props, key, true);
1540
+ }
1541
+ }
1542
+ function jsxWithValidationDynamic(type, props, key) {
1543
+ {
1544
+ return jsxWithValidation(type, props, key, false);
1545
+ }
1546
+ }
1547
+
1548
+ var jsx = jsxWithValidationDynamic ; // we may want to special case jsxs internally to take advantage of static children.
1549
+ // for now we can ship identical prod functions
1550
+
1551
+ var jsxs = jsxWithValidationStatic ;
1552
+
1553
+ reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
1554
+ reactJsxRuntime_development.jsx = jsx;
1555
+ reactJsxRuntime_development.jsxs = jsxs;
1556
+ })();
1557
+ }
1558
+ return reactJsxRuntime_development;
1559
+ }
1560
+
1561
+ if (process.env.NODE_ENV === 'production') {
1562
+ jsxRuntime.exports = requireReactJsxRuntime_production_min();
1563
+ } else {
1564
+ jsxRuntime.exports = requireReactJsxRuntime_development();
1565
+ }
1566
+
1567
+ var jsxRuntimeExports = jsxRuntime.exports;
1568
+
1569
+ var dist = {};
1570
+
1571
+ var useWebsocket = {};
1572
+
1573
+ var constants = {};
1574
+
1575
+ (function (exports) {
1576
+ Object.defineProperty(exports, "__esModule", { value: true });
1577
+ exports.isEventSourceSupported = exports.isReactNative = exports.ReadyState = exports.DEFAULT_HEARTBEAT = exports.UNPARSABLE_JSON_OBJECT = exports.DEFAULT_RECONNECT_INTERVAL_MS = exports.DEFAULT_RECONNECT_LIMIT = exports.SOCKET_IO_PING_CODE = exports.SOCKET_IO_PATH = exports.SOCKET_IO_PING_INTERVAL = exports.DEFAULT_EVENT_SOURCE_OPTIONS = exports.EMPTY_EVENT_HANDLERS = exports.DEFAULT_OPTIONS = void 0;
1578
+ var MILLISECONDS = 1;
1579
+ var SECONDS = 1000 * MILLISECONDS;
1580
+ exports.DEFAULT_OPTIONS = {};
1581
+ exports.EMPTY_EVENT_HANDLERS = {};
1582
+ exports.DEFAULT_EVENT_SOURCE_OPTIONS = {
1583
+ withCredentials: false,
1584
+ events: exports.EMPTY_EVENT_HANDLERS,
1585
+ };
1586
+ exports.SOCKET_IO_PING_INTERVAL = 25 * SECONDS;
1587
+ exports.SOCKET_IO_PATH = '/socket.io/?EIO=3&transport=websocket';
1588
+ exports.SOCKET_IO_PING_CODE = '2';
1589
+ exports.DEFAULT_RECONNECT_LIMIT = 20;
1590
+ exports.DEFAULT_RECONNECT_INTERVAL_MS = 5000;
1591
+ exports.UNPARSABLE_JSON_OBJECT = {};
1592
+ exports.DEFAULT_HEARTBEAT = {
1593
+ message: 'ping',
1594
+ timeout: 60000,
1595
+ interval: 25000,
1596
+ };
1597
+ var ReadyState;
1598
+ (function (ReadyState) {
1599
+ ReadyState[ReadyState["UNINSTANTIATED"] = -1] = "UNINSTANTIATED";
1600
+ ReadyState[ReadyState["CONNECTING"] = 0] = "CONNECTING";
1601
+ ReadyState[ReadyState["OPEN"] = 1] = "OPEN";
1602
+ ReadyState[ReadyState["CLOSING"] = 2] = "CLOSING";
1603
+ ReadyState[ReadyState["CLOSED"] = 3] = "CLOSED";
1604
+ })(ReadyState || (exports.ReadyState = ReadyState = {}));
1605
+ var eventSourceSupported = function () {
1606
+ try {
1607
+ return 'EventSource' in globalThis;
1608
+ }
1609
+ catch (e) {
1610
+ return false;
1611
+ }
1612
+ };
1613
+ exports.isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
1614
+ exports.isEventSourceSupported = !exports.isReactNative && eventSourceSupported();
1615
+
1616
+ } (constants));
1617
+
1618
+ var createOrJoin = {};
1619
+
1620
+ var globals = {};
1621
+
1622
+ (function (exports) {
1623
+ Object.defineProperty(exports, "__esModule", { value: true });
1624
+ exports.resetWebSockets = exports.sharedWebSockets = void 0;
1625
+ exports.sharedWebSockets = {};
1626
+ var resetWebSockets = function (url) {
1627
+ if (url && exports.sharedWebSockets.hasOwnProperty(url)) {
1628
+ delete exports.sharedWebSockets[url];
1629
+ }
1630
+ else {
1631
+ for (var url_1 in exports.sharedWebSockets) {
1632
+ if (exports.sharedWebSockets.hasOwnProperty(url_1)) {
1633
+ delete exports.sharedWebSockets[url_1];
1634
+ }
1635
+ }
1636
+ }
1637
+ };
1638
+ exports.resetWebSockets = resetWebSockets;
1639
+
1640
+ } (globals));
1641
+
1642
+ var attachListener = {};
1643
+
1644
+ var socketIo = {};
1645
+
1646
+ Object.defineProperty(socketIo, "__esModule", { value: true });
1647
+ socketIo.setUpSocketIOPing = socketIo.appendQueryParams = socketIo.parseSocketIOUrl = void 0;
1648
+ var constants_1$7 = constants;
1649
+ var parseSocketIOUrl = function (url) {
1650
+ if (url) {
1651
+ var isSecure = /^https|wss/.test(url);
1652
+ var strippedProtocol = url.replace(/^(https?|wss?)(:\/\/)?/, '');
1653
+ var removedFinalBackSlack = strippedProtocol.replace(/\/$/, '');
1654
+ var protocol = isSecure ? 'wss' : 'ws';
1655
+ return "".concat(protocol, "://").concat(removedFinalBackSlack).concat(constants_1$7.SOCKET_IO_PATH);
1656
+ }
1657
+ else if (url === '') {
1658
+ var isSecure = /^https/.test(window.location.protocol);
1659
+ var protocol = isSecure ? 'wss' : 'ws';
1660
+ var port = window.location.port ? ":".concat(window.location.port) : '';
1661
+ return "".concat(protocol, "://").concat(window.location.hostname).concat(port).concat(constants_1$7.SOCKET_IO_PATH);
1662
+ }
1663
+ return url;
1664
+ };
1665
+ socketIo.parseSocketIOUrl = parseSocketIOUrl;
1666
+ var appendQueryParams = function (url, params) {
1667
+ if (params === void 0) { params = {}; }
1668
+ var hasParamsRegex = /\?([\w]+=[\w]+)/;
1669
+ var alreadyHasParams = hasParamsRegex.test(url);
1670
+ var stringified = "".concat(Object.entries(params).reduce(function (next, _a) {
1671
+ var key = _a[0], value = _a[1];
1672
+ return next + "".concat(key, "=").concat(value, "&");
1673
+ }, '').slice(0, -1));
1674
+ return "".concat(url).concat(alreadyHasParams ? '&' : '?').concat(stringified);
1675
+ };
1676
+ socketIo.appendQueryParams = appendQueryParams;
1677
+ var setUpSocketIOPing = function (sendMessage, interval) {
1678
+ if (interval === void 0) { interval = constants_1$7.SOCKET_IO_PING_INTERVAL; }
1679
+ var ping = function () { return sendMessage(constants_1$7.SOCKET_IO_PING_CODE); };
1680
+ return window.setInterval(ping, interval);
1681
+ };
1682
+ socketIo.setUpSocketIOPing = setUpSocketIOPing;
1683
+
1684
+ var heartbeat$1 = {};
1685
+
1686
+ Object.defineProperty(heartbeat$1, "__esModule", { value: true });
1687
+ heartbeat$1.heartbeat = heartbeat;
1688
+ var constants_1$6 = constants;
1689
+ function getLastMessageTime(lastMessageTime) {
1690
+ if (Array.isArray(lastMessageTime)) {
1691
+ return lastMessageTime.reduce(function (p, c) { return (p.current > c.current) ? p : c; }).current;
1692
+ }
1693
+ return lastMessageTime.current;
1694
+ }
1695
+ function heartbeat(ws, lastMessageTime, options) {
1696
+ var _a = options || {}, _b = _a.interval, interval = _b === void 0 ? constants_1$6.DEFAULT_HEARTBEAT.interval : _b, _c = _a.timeout, timeout = _c === void 0 ? constants_1$6.DEFAULT_HEARTBEAT.timeout : _c, _d = _a.message, message = _d === void 0 ? constants_1$6.DEFAULT_HEARTBEAT.message : _d;
1697
+ // how often check interval between ping messages
1698
+ // minimum is 100ms
1699
+ // maximum is ${interval / 10}ms
1700
+ var intervalCheck = Math.max(100, interval / 10);
1701
+ var lastPingSentAt = Date.now();
1702
+ var heartbeatInterval = setInterval(function () {
1703
+ var timeNow = Date.now();
1704
+ var lastMessageReceivedAt = getLastMessageTime(lastMessageTime);
1705
+ if (lastMessageReceivedAt + timeout <= timeNow) {
1706
+ console.warn("Heartbeat timed out, closing connection, last message received ".concat(timeNow - lastMessageReceivedAt, "ms ago, last ping sent ").concat(timeNow - lastPingSentAt, "ms ago"));
1707
+ ws.close();
1708
+ }
1709
+ else {
1710
+ if (lastMessageReceivedAt + interval <= timeNow && lastPingSentAt + interval <= timeNow) {
1711
+ try {
1712
+ if (typeof message === 'function') {
1713
+ ws.send(message());
1714
+ }
1715
+ else {
1716
+ ws.send(message);
1717
+ }
1718
+ lastPingSentAt = timeNow;
1719
+ }
1720
+ catch (err) {
1721
+ console.error("Heartbeat failed, closing connection", err instanceof Error ? err.message : err);
1722
+ ws.close();
1723
+ }
1724
+ }
1725
+ }
1726
+ }, intervalCheck);
1727
+ ws.addEventListener("close", function () {
1728
+ clearInterval(heartbeatInterval);
1729
+ });
1730
+ return function () { };
1731
+ }
1732
+
1733
+ var util = {};
1734
+
1735
+ var manageSubscribers = {};
1736
+
1737
+ (function (exports) {
1738
+ Object.defineProperty(exports, "__esModule", { value: true });
1739
+ exports.resetSubscribers = exports.removeSubscriber = exports.addSubscriber = exports.hasSubscribers = exports.getSubscribers = void 0;
1740
+ var subscribers = {};
1741
+ var EMPTY_LIST = [];
1742
+ var getSubscribers = function (url) {
1743
+ if ((0, exports.hasSubscribers)(url)) {
1744
+ return Array.from(subscribers[url]);
1745
+ }
1746
+ return EMPTY_LIST;
1747
+ };
1748
+ exports.getSubscribers = getSubscribers;
1749
+ var hasSubscribers = function (url) {
1750
+ var _a;
1751
+ return ((_a = subscribers[url]) === null || _a === void 0 ? void 0 : _a.size) > 0;
1752
+ };
1753
+ exports.hasSubscribers = hasSubscribers;
1754
+ var addSubscriber = function (url, subscriber) {
1755
+ subscribers[url] = subscribers[url] || new Set();
1756
+ subscribers[url].add(subscriber);
1757
+ };
1758
+ exports.addSubscriber = addSubscriber;
1759
+ var removeSubscriber = function (url, subscriber) {
1760
+ subscribers[url].delete(subscriber);
1761
+ };
1762
+ exports.removeSubscriber = removeSubscriber;
1763
+ var resetSubscribers = function (url) {
1764
+ if (url && subscribers.hasOwnProperty(url)) {
1765
+ delete subscribers[url];
1766
+ }
1767
+ else {
1768
+ for (var url_1 in subscribers) {
1769
+ if (subscribers.hasOwnProperty(url_1)) {
1770
+ delete subscribers[url_1];
1771
+ }
1772
+ }
1773
+ }
1774
+ };
1775
+ exports.resetSubscribers = resetSubscribers;
1776
+
1777
+ } (manageSubscribers));
1778
+
1779
+ Object.defineProperty(util, "__esModule", { value: true });
1780
+ util.assertIsWebSocket = assertIsWebSocket;
1781
+ util.resetGlobalState = resetGlobalState;
1782
+ var globals_1$2 = globals;
1783
+ var manage_subscribers_1$2 = manageSubscribers;
1784
+ function assertIsWebSocket(webSocketInstance, skip) {
1785
+ if (!skip && webSocketInstance instanceof WebSocket === false)
1786
+ throw new Error('');
1787
+ }
1788
+ function resetGlobalState(url) {
1789
+ (0, manage_subscribers_1$2.resetSubscribers)(url);
1790
+ (0, globals_1$2.resetWebSockets)(url);
1791
+ }
1792
+
1793
+ var __assign$4 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1794
+ __assign$4 = Object.assign || function(t) {
1795
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1796
+ s = arguments[i];
1797
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
1798
+ t[p] = s[p];
1799
+ }
1800
+ return t;
1801
+ };
1802
+ return __assign$4.apply(this, arguments);
1803
+ };
1804
+ Object.defineProperty(attachListener, "__esModule", { value: true });
1805
+ attachListener.attachListeners = void 0;
1806
+ var socket_io_1$1 = socketIo;
1807
+ var heartbeat_1$1 = heartbeat$1;
1808
+ var constants_1$5 = constants;
1809
+ var util_1$1 = util;
1810
+ var bindMessageHandler$1 = function (webSocketInstance, optionsRef, setLastMessage, lastMessageTime) {
1811
+ webSocketInstance.onmessage = function (message) {
1812
+ var _a;
1813
+ optionsRef.current.onMessage && optionsRef.current.onMessage(message);
1814
+ if (typeof (lastMessageTime === null || lastMessageTime === void 0 ? void 0 : lastMessageTime.current) === 'number') {
1815
+ lastMessageTime.current = Date.now();
1816
+ }
1817
+ if (typeof optionsRef.current.filter === 'function' && optionsRef.current.filter(message) !== true) {
1818
+ return;
1819
+ }
1820
+ if (optionsRef.current.heartbeat &&
1821
+ typeof optionsRef.current.heartbeat !== "boolean" &&
1822
+ ((_a = optionsRef.current.heartbeat) === null || _a === void 0 ? void 0 : _a.returnMessage) === message.data) {
1823
+ return;
1824
+ }
1825
+ setLastMessage(message);
1826
+ };
1827
+ };
1828
+ var bindOpenHandler$1 = function (webSocketInstance, optionsRef, setReadyState, reconnectCount, lastMessageTime) {
1829
+ webSocketInstance.onopen = function (event) {
1830
+ optionsRef.current.onOpen && optionsRef.current.onOpen(event);
1831
+ reconnectCount.current = 0;
1832
+ setReadyState(constants_1$5.ReadyState.OPEN);
1833
+ //start heart beat here
1834
+ if (optionsRef.current.heartbeat && webSocketInstance instanceof WebSocket) {
1835
+ var heartbeatOptions = typeof optionsRef.current.heartbeat === "boolean"
1836
+ ? undefined
1837
+ : optionsRef.current.heartbeat;
1838
+ lastMessageTime.current = Date.now();
1839
+ (0, heartbeat_1$1.heartbeat)(webSocketInstance, lastMessageTime, heartbeatOptions);
1840
+ }
1841
+ };
1842
+ };
1843
+ var bindCloseHandler$1 = function (webSocketInstance, optionsRef, setReadyState, reconnect, reconnectCount) {
1844
+ if (constants_1$5.isEventSourceSupported && webSocketInstance instanceof EventSource) {
1845
+ return function () { };
1846
+ }
1847
+ (0, util_1$1.assertIsWebSocket)(webSocketInstance, optionsRef.current.skipAssert);
1848
+ var reconnectTimeout;
1849
+ webSocketInstance.onclose = function (event) {
1850
+ var _a;
1851
+ optionsRef.current.onClose && optionsRef.current.onClose(event);
1852
+ setReadyState(constants_1$5.ReadyState.CLOSED);
1853
+ if (optionsRef.current.shouldReconnect && optionsRef.current.shouldReconnect(event)) {
1854
+ var reconnectAttempts = (_a = optionsRef.current.reconnectAttempts) !== null && _a !== void 0 ? _a : constants_1$5.DEFAULT_RECONNECT_LIMIT;
1855
+ if (reconnectCount.current < reconnectAttempts) {
1856
+ var nextReconnectInterval = typeof optionsRef.current.reconnectInterval === 'function' ?
1857
+ optionsRef.current.reconnectInterval(reconnectCount.current) :
1858
+ optionsRef.current.reconnectInterval;
1859
+ reconnectTimeout = window.setTimeout(function () {
1860
+ reconnectCount.current++;
1861
+ reconnect();
1862
+ }, nextReconnectInterval !== null && nextReconnectInterval !== void 0 ? nextReconnectInterval : constants_1$5.DEFAULT_RECONNECT_INTERVAL_MS);
1863
+ }
1864
+ else {
1865
+ optionsRef.current.onReconnectStop && optionsRef.current.onReconnectStop(reconnectAttempts);
1866
+ console.warn("Max reconnect attempts of ".concat(reconnectAttempts, " exceeded"));
1867
+ }
1868
+ }
1869
+ };
1870
+ return function () { return reconnectTimeout && window.clearTimeout(reconnectTimeout); };
1871
+ };
1872
+ var bindErrorHandler$1 = function (webSocketInstance, optionsRef, setReadyState, reconnect, reconnectCount) {
1873
+ var reconnectTimeout;
1874
+ webSocketInstance.onerror = function (error) {
1875
+ var _a;
1876
+ optionsRef.current.onError && optionsRef.current.onError(error);
1877
+ if (constants_1$5.isEventSourceSupported && webSocketInstance instanceof EventSource) {
1878
+ optionsRef.current.onClose && optionsRef.current.onClose(__assign$4(__assign$4({}, error), { code: 1006, reason: "An error occurred with the EventSource: ".concat(error), wasClean: false }));
1879
+ setReadyState(constants_1$5.ReadyState.CLOSED);
1880
+ webSocketInstance.close();
1881
+ }
1882
+ if (optionsRef.current.retryOnError) {
1883
+ if (reconnectCount.current < ((_a = optionsRef.current.reconnectAttempts) !== null && _a !== void 0 ? _a : constants_1$5.DEFAULT_RECONNECT_LIMIT)) {
1884
+ var nextReconnectInterval = typeof optionsRef.current.reconnectInterval === 'function' ?
1885
+ optionsRef.current.reconnectInterval(reconnectCount.current) :
1886
+ optionsRef.current.reconnectInterval;
1887
+ reconnectTimeout = window.setTimeout(function () {
1888
+ reconnectCount.current++;
1889
+ reconnect();
1890
+ }, nextReconnectInterval !== null && nextReconnectInterval !== void 0 ? nextReconnectInterval : constants_1$5.DEFAULT_RECONNECT_INTERVAL_MS);
1891
+ }
1892
+ else {
1893
+ optionsRef.current.onReconnectStop && optionsRef.current.onReconnectStop(optionsRef.current.reconnectAttempts);
1894
+ console.warn("Max reconnect attempts of ".concat(optionsRef.current.reconnectAttempts, " exceeded"));
1895
+ }
1896
+ }
1897
+ };
1898
+ return function () { return reconnectTimeout && window.clearTimeout(reconnectTimeout); };
1899
+ };
1900
+ var attachListeners = function (webSocketInstance, setters, optionsRef, reconnect, reconnectCount, lastMessageTime, sendMessage) {
1901
+ var setLastMessage = setters.setLastMessage, setReadyState = setters.setReadyState;
1902
+ var interval;
1903
+ var cancelReconnectOnClose;
1904
+ var cancelReconnectOnError;
1905
+ if (optionsRef.current.fromSocketIO) {
1906
+ interval = (0, socket_io_1$1.setUpSocketIOPing)(sendMessage);
1907
+ }
1908
+ bindMessageHandler$1(webSocketInstance, optionsRef, setLastMessage, lastMessageTime);
1909
+ bindOpenHandler$1(webSocketInstance, optionsRef, setReadyState, reconnectCount, lastMessageTime);
1910
+ cancelReconnectOnClose = bindCloseHandler$1(webSocketInstance, optionsRef, setReadyState, reconnect, reconnectCount);
1911
+ cancelReconnectOnError = bindErrorHandler$1(webSocketInstance, optionsRef, setReadyState, reconnect, reconnectCount);
1912
+ return function () {
1913
+ setReadyState(constants_1$5.ReadyState.CLOSING);
1914
+ cancelReconnectOnClose();
1915
+ cancelReconnectOnError();
1916
+ webSocketInstance.close();
1917
+ if (interval)
1918
+ clearInterval(interval);
1919
+ };
1920
+ };
1921
+ attachListener.attachListeners = attachListeners;
1922
+
1923
+ var attachSharedListeners$1 = {};
1924
+
1925
+ var __assign$3 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1926
+ __assign$3 = Object.assign || function(t) {
1927
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1928
+ s = arguments[i];
1929
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
1930
+ t[p] = s[p];
1931
+ }
1932
+ return t;
1933
+ };
1934
+ return __assign$3.apply(this, arguments);
1935
+ };
1936
+ Object.defineProperty(attachSharedListeners$1, "__esModule", { value: true });
1937
+ attachSharedListeners$1.attachSharedListeners = void 0;
1938
+ var globals_1$1 = globals;
1939
+ var constants_1$4 = constants;
1940
+ var manage_subscribers_1$1 = manageSubscribers;
1941
+ var socket_io_1 = socketIo;
1942
+ var heartbeat_1 = heartbeat$1;
1943
+ var bindMessageHandler = function (webSocketInstance, url, heartbeatOptions) {
1944
+ webSocketInstance.onmessage = function (message) {
1945
+ (0, manage_subscribers_1$1.getSubscribers)(url).forEach(function (subscriber) {
1946
+ var _a;
1947
+ if (subscriber.optionsRef.current.onMessage) {
1948
+ subscriber.optionsRef.current.onMessage(message);
1949
+ }
1950
+ if (typeof ((_a = subscriber === null || subscriber === void 0 ? void 0 : subscriber.lastMessageTime) === null || _a === void 0 ? void 0 : _a.current) === 'number') {
1951
+ subscriber.lastMessageTime.current = Date.now();
1952
+ }
1953
+ if (typeof subscriber.optionsRef.current.filter === 'function' &&
1954
+ subscriber.optionsRef.current.filter(message) !== true) {
1955
+ return;
1956
+ }
1957
+ if (heartbeatOptions &&
1958
+ typeof heartbeatOptions !== "boolean" &&
1959
+ (heartbeatOptions === null || heartbeatOptions === void 0 ? void 0 : heartbeatOptions.returnMessage) === message.data)
1960
+ return;
1961
+ subscriber.setLastMessage(message);
1962
+ });
1963
+ };
1964
+ };
1965
+ var bindOpenHandler = function (webSocketInstance, url, heartbeatOptions) {
1966
+ webSocketInstance.onopen = function (event) {
1967
+ var subscribers = (0, manage_subscribers_1$1.getSubscribers)(url);
1968
+ subscribers.forEach(function (subscriber) {
1969
+ subscriber.reconnectCount.current = 0;
1970
+ if (subscriber.optionsRef.current.onOpen) {
1971
+ subscriber.optionsRef.current.onOpen(event);
1972
+ }
1973
+ subscriber.setReadyState(constants_1$4.ReadyState.OPEN);
1974
+ if (heartbeatOptions && webSocketInstance instanceof WebSocket) {
1975
+ subscriber.lastMessageTime.current = Date.now();
1976
+ }
1977
+ });
1978
+ if (heartbeatOptions && webSocketInstance instanceof WebSocket) {
1979
+ (0, heartbeat_1.heartbeat)(webSocketInstance, subscribers.map(function (subscriber) { return subscriber.lastMessageTime; }), typeof heartbeatOptions === 'boolean' ? undefined : heartbeatOptions);
1980
+ }
1981
+ };
1982
+ };
1983
+ var bindCloseHandler = function (webSocketInstance, url) {
1984
+ if (webSocketInstance instanceof WebSocket) {
1985
+ webSocketInstance.onclose = function (event) {
1986
+ (0, manage_subscribers_1$1.getSubscribers)(url).forEach(function (subscriber) {
1987
+ if (subscriber.optionsRef.current.onClose) {
1988
+ subscriber.optionsRef.current.onClose(event);
1989
+ }
1990
+ subscriber.setReadyState(constants_1$4.ReadyState.CLOSED);
1991
+ });
1992
+ delete globals_1$1.sharedWebSockets[url];
1993
+ (0, manage_subscribers_1$1.getSubscribers)(url).forEach(function (subscriber) {
1994
+ var _a;
1995
+ if (subscriber.optionsRef.current.shouldReconnect &&
1996
+ subscriber.optionsRef.current.shouldReconnect(event)) {
1997
+ var reconnectAttempts = (_a = subscriber.optionsRef.current.reconnectAttempts) !== null && _a !== void 0 ? _a : constants_1$4.DEFAULT_RECONNECT_LIMIT;
1998
+ if (subscriber.reconnectCount.current < reconnectAttempts) {
1999
+ var nextReconnectInterval = typeof subscriber.optionsRef.current.reconnectInterval === 'function' ?
2000
+ subscriber.optionsRef.current.reconnectInterval(subscriber.reconnectCount.current) :
2001
+ subscriber.optionsRef.current.reconnectInterval;
2002
+ setTimeout(function () {
2003
+ subscriber.reconnectCount.current++;
2004
+ subscriber.reconnect.current();
2005
+ }, nextReconnectInterval !== null && nextReconnectInterval !== void 0 ? nextReconnectInterval : constants_1$4.DEFAULT_RECONNECT_INTERVAL_MS);
2006
+ }
2007
+ else {
2008
+ subscriber.optionsRef.current.onReconnectStop && subscriber.optionsRef.current.onReconnectStop(subscriber.optionsRef.current.reconnectAttempts);
2009
+ console.warn("Max reconnect attempts of ".concat(reconnectAttempts, " exceeded"));
2010
+ }
2011
+ }
2012
+ });
2013
+ };
2014
+ }
2015
+ };
2016
+ var bindErrorHandler = function (webSocketInstance, url) {
2017
+ webSocketInstance.onerror = function (error) {
2018
+ (0, manage_subscribers_1$1.getSubscribers)(url).forEach(function (subscriber) {
2019
+ if (subscriber.optionsRef.current.onError) {
2020
+ subscriber.optionsRef.current.onError(error);
2021
+ }
2022
+ if (constants_1$4.isEventSourceSupported && webSocketInstance instanceof EventSource) {
2023
+ subscriber.optionsRef.current.onClose && subscriber.optionsRef.current.onClose(__assign$3(__assign$3({}, error), { code: 1006, reason: "An error occurred with the EventSource: ".concat(error), wasClean: false }));
2024
+ subscriber.setReadyState(constants_1$4.ReadyState.CLOSED);
2025
+ }
2026
+ });
2027
+ if (constants_1$4.isEventSourceSupported && webSocketInstance instanceof EventSource) {
2028
+ webSocketInstance.close();
2029
+ }
2030
+ };
2031
+ };
2032
+ var attachSharedListeners = function (webSocketInstance, url, optionsRef, sendMessage) {
2033
+ var interval;
2034
+ if (optionsRef.current.fromSocketIO) {
2035
+ interval = (0, socket_io_1.setUpSocketIOPing)(sendMessage);
2036
+ }
2037
+ bindMessageHandler(webSocketInstance, url, optionsRef.current.heartbeat);
2038
+ bindCloseHandler(webSocketInstance, url);
2039
+ bindOpenHandler(webSocketInstance, url, optionsRef.current.heartbeat);
2040
+ bindErrorHandler(webSocketInstance, url);
2041
+ return function () {
2042
+ if (interval)
2043
+ clearInterval(interval);
2044
+ };
2045
+ };
2046
+ attachSharedListeners$1.attachSharedListeners = attachSharedListeners;
2047
+
2048
+ Object.defineProperty(createOrJoin, "__esModule", { value: true });
2049
+ createOrJoin.createOrJoinSocket = void 0;
2050
+ var globals_1 = globals;
2051
+ var constants_1$3 = constants;
2052
+ var attach_listener_1 = attachListener;
2053
+ var attach_shared_listeners_1 = attachSharedListeners$1;
2054
+ var manage_subscribers_1 = manageSubscribers;
2055
+ //TODO ensure that all onClose callbacks are called
2056
+ var cleanSubscribers = function (url, subscriber, optionsRef, setReadyState, clearSocketIoPingInterval) {
2057
+ return function () {
2058
+ (0, manage_subscribers_1.removeSubscriber)(url, subscriber);
2059
+ if (!(0, manage_subscribers_1.hasSubscribers)(url)) {
2060
+ try {
2061
+ var socketLike = globals_1.sharedWebSockets[url];
2062
+ if (socketLike instanceof WebSocket) {
2063
+ socketLike.onclose = function (event) {
2064
+ if (optionsRef.current.onClose) {
2065
+ optionsRef.current.onClose(event);
2066
+ }
2067
+ setReadyState(constants_1$3.ReadyState.CLOSED);
2068
+ };
2069
+ }
2070
+ socketLike.close();
2071
+ }
2072
+ catch (e) {
2073
+ }
2074
+ if (clearSocketIoPingInterval)
2075
+ clearSocketIoPingInterval();
2076
+ delete globals_1.sharedWebSockets[url];
2077
+ }
2078
+ };
2079
+ };
2080
+ var createOrJoinSocket = function (webSocketRef, url, setReadyState, optionsRef, setLastMessage, startRef, reconnectCount, lastMessageTime, sendMessage) {
2081
+ if (!constants_1$3.isEventSourceSupported && optionsRef.current.eventSourceOptions) {
2082
+ if (constants_1$3.isReactNative) {
2083
+ throw new Error('EventSource is not supported in ReactNative');
2084
+ }
2085
+ else {
2086
+ throw new Error('EventSource is not supported');
2087
+ }
2088
+ }
2089
+ if (optionsRef.current.share) {
2090
+ var clearSocketIoPingInterval = null;
2091
+ if (globals_1.sharedWebSockets[url] === undefined) {
2092
+ globals_1.sharedWebSockets[url] = optionsRef.current.eventSourceOptions ?
2093
+ new EventSource(url, optionsRef.current.eventSourceOptions) :
2094
+ new WebSocket(url, optionsRef.current.protocols);
2095
+ webSocketRef.current = globals_1.sharedWebSockets[url];
2096
+ setReadyState(constants_1$3.ReadyState.CONNECTING);
2097
+ clearSocketIoPingInterval = (0, attach_shared_listeners_1.attachSharedListeners)(globals_1.sharedWebSockets[url], url, optionsRef, sendMessage);
2098
+ }
2099
+ else {
2100
+ webSocketRef.current = globals_1.sharedWebSockets[url];
2101
+ setReadyState(globals_1.sharedWebSockets[url].readyState);
2102
+ }
2103
+ var subscriber = {
2104
+ setLastMessage: setLastMessage,
2105
+ setReadyState: setReadyState,
2106
+ optionsRef: optionsRef,
2107
+ reconnectCount: reconnectCount,
2108
+ lastMessageTime: lastMessageTime,
2109
+ reconnect: startRef,
2110
+ };
2111
+ (0, manage_subscribers_1.addSubscriber)(url, subscriber);
2112
+ return cleanSubscribers(url, subscriber, optionsRef, setReadyState, clearSocketIoPingInterval);
2113
+ }
2114
+ else {
2115
+ webSocketRef.current = optionsRef.current.eventSourceOptions ?
2116
+ new EventSource(url, optionsRef.current.eventSourceOptions) :
2117
+ new WebSocket(url, optionsRef.current.protocols);
2118
+ setReadyState(constants_1$3.ReadyState.CONNECTING);
2119
+ if (!webSocketRef.current) {
2120
+ throw new Error('WebSocket failed to be created');
2121
+ }
2122
+ return (0, attach_listener_1.attachListeners)(webSocketRef.current, {
2123
+ setLastMessage: setLastMessage,
2124
+ setReadyState: setReadyState
2125
+ }, optionsRef, startRef.current, reconnectCount, lastMessageTime, sendMessage);
2126
+ }
2127
+ };
2128
+ createOrJoin.createOrJoinSocket = createOrJoinSocket;
2129
+
2130
+ var getUrl = {};
2131
+
2132
+ (function (exports) {
2133
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2134
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2135
+ return new (P || (P = Promise))(function (resolve, reject) {
2136
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2137
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2138
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2139
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2140
+ });
2141
+ };
2142
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
2143
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
2144
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2145
+ function verb(n) { return function (v) { return step([n, v]); }; }
2146
+ function step(op) {
2147
+ if (f) throw new TypeError("Generator is already executing.");
2148
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
2149
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
2150
+ if (y = 0, t) op = [op[0] & 2, t.value];
2151
+ switch (op[0]) {
2152
+ case 0: case 1: t = op; break;
2153
+ case 4: _.label++; return { value: op[1], done: false };
2154
+ case 5: _.label++; y = op[1]; op = [0]; continue;
2155
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
2156
+ default:
2157
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2158
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2159
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2160
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2161
+ if (t[2]) _.ops.pop();
2162
+ _.trys.pop(); continue;
2163
+ }
2164
+ op = body.call(thisArg, _);
2165
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2166
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2167
+ }
2168
+ };
2169
+ var __spreadArray = (commonjsGlobal && commonjsGlobal.__spreadArray) || function (to, from, pack) {
2170
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
2171
+ if (ar || !(i in from)) {
2172
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
2173
+ ar[i] = from[i];
2174
+ }
2175
+ }
2176
+ return to.concat(ar || Array.prototype.slice.call(from));
2177
+ };
2178
+ Object.defineProperty(exports, "__esModule", { value: true });
2179
+ exports.getUrl = void 0;
2180
+ var socket_io_1 = socketIo;
2181
+ var constants_1 = constants;
2182
+ var waitFor = function (duration) { return new Promise(function (resolve) { return window.setTimeout(resolve, duration); }); };
2183
+ var getUrl = function (url_1, optionsRef_1) {
2184
+ var args_1 = [];
2185
+ for (var _i = 2; _i < arguments.length; _i++) {
2186
+ args_1[_i - 2] = arguments[_i];
2187
+ }
2188
+ return __awaiter(void 0, __spreadArray([url_1, optionsRef_1], args_1, true), void 0, function (url, optionsRef, retriedAttempts) {
2189
+ var convertedUrl, reconnectLimit, nextReconnectInterval, parsedUrl, parsedWithQueryParams;
2190
+ var _a, _b, _c;
2191
+ if (retriedAttempts === void 0) { retriedAttempts = 0; }
2192
+ return __generator(this, function (_d) {
2193
+ switch (_d.label) {
2194
+ case 0:
2195
+ if (!(typeof url === 'function')) return [3 /*break*/, 10];
2196
+ _d.label = 1;
2197
+ case 1:
2198
+ _d.trys.push([1, 3, , 9]);
2199
+ return [4 /*yield*/, url()];
2200
+ case 2:
2201
+ convertedUrl = _d.sent();
2202
+ return [3 /*break*/, 9];
2203
+ case 3:
2204
+ _d.sent();
2205
+ if (!optionsRef.current.retryOnError) return [3 /*break*/, 7];
2206
+ reconnectLimit = (_a = optionsRef.current.reconnectAttempts) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_RECONNECT_LIMIT;
2207
+ if (!(retriedAttempts < reconnectLimit)) return [3 /*break*/, 5];
2208
+ nextReconnectInterval = typeof optionsRef.current.reconnectInterval === 'function' ?
2209
+ optionsRef.current.reconnectInterval(retriedAttempts) :
2210
+ optionsRef.current.reconnectInterval;
2211
+ return [4 /*yield*/, waitFor(nextReconnectInterval !== null && nextReconnectInterval !== void 0 ? nextReconnectInterval : constants_1.DEFAULT_RECONNECT_INTERVAL_MS)];
2212
+ case 4:
2213
+ _d.sent();
2214
+ return [2 /*return*/, (0, exports.getUrl)(url, optionsRef, retriedAttempts + 1)];
2215
+ case 5:
2216
+ (_c = (_b = optionsRef.current).onReconnectStop) === null || _c === void 0 ? void 0 : _c.call(_b, retriedAttempts);
2217
+ return [2 /*return*/, null];
2218
+ case 6: return [3 /*break*/, 8];
2219
+ case 7: return [2 /*return*/, null];
2220
+ case 8: return [3 /*break*/, 9];
2221
+ case 9: return [3 /*break*/, 11];
2222
+ case 10:
2223
+ convertedUrl = url;
2224
+ _d.label = 11;
2225
+ case 11:
2226
+ parsedUrl = optionsRef.current.fromSocketIO ?
2227
+ (0, socket_io_1.parseSocketIOUrl)(convertedUrl) :
2228
+ convertedUrl;
2229
+ parsedWithQueryParams = optionsRef.current.queryParams ?
2230
+ (0, socket_io_1.appendQueryParams)(parsedUrl, optionsRef.current.queryParams) :
2231
+ parsedUrl;
2232
+ return [2 /*return*/, parsedWithQueryParams];
2233
+ }
2234
+ });
2235
+ });
2236
+ };
2237
+ exports.getUrl = getUrl;
2238
+
2239
+ } (getUrl));
2240
+
2241
+ var proxy = {};
2242
+
2243
+ (function (exports) {
2244
+ Object.defineProperty(exports, "__esModule", { value: true });
2245
+ exports.websocketWrapper = void 0;
2246
+ var websocketWrapper = function (webSocket, start) {
2247
+ return new Proxy(webSocket, {
2248
+ get: function (obj, key) {
2249
+ var val = obj[key];
2250
+ if (key === 'reconnect')
2251
+ return start;
2252
+ if (typeof val === 'function') {
2253
+ console.error('Calling methods directly on the websocket is not supported at this moment. You must use the methods returned by useWebSocket.');
2254
+ //Prevent error thrown by invoking a non-function
2255
+ return function () { };
2256
+ }
2257
+ else {
2258
+ return val;
2259
+ }
2260
+ },
2261
+ set: function (obj, key, val) {
2262
+ if (/^on/.test(key)) {
2263
+ console.warn('The websocket\'s event handlers should be defined through the options object passed into useWebSocket.');
2264
+ return false;
2265
+ }
2266
+ else {
2267
+ obj[key] = val;
2268
+ return true;
2269
+ }
2270
+ },
2271
+ });
2272
+ };
2273
+ exports.websocketWrapper = websocketWrapper;
2274
+ exports.default = exports.websocketWrapper;
2275
+
2276
+ } (proxy));
2277
+
2278
+ var __assign$2 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
2279
+ __assign$2 = Object.assign || function(t) {
2280
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
2281
+ s = arguments[i];
2282
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
2283
+ t[p] = s[p];
2284
+ }
2285
+ return t;
2286
+ };
2287
+ return __assign$2.apply(this, arguments);
2288
+ };
2289
+ var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
2290
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2291
+ return new (P || (P = Promise))(function (resolve, reject) {
2292
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2293
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2294
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2295
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2296
+ });
2297
+ };
2298
+ var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
2299
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
2300
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2301
+ function verb(n) { return function (v) { return step([n, v]); }; }
2302
+ function step(op) {
2303
+ if (f) throw new TypeError("Generator is already executing.");
2304
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
2305
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
2306
+ if (y = 0, t) op = [op[0] & 2, t.value];
2307
+ switch (op[0]) {
2308
+ case 0: case 1: t = op; break;
2309
+ case 4: _.label++; return { value: op[1], done: false };
2310
+ case 5: _.label++; y = op[1]; op = [0]; continue;
2311
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
2312
+ default:
2313
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2314
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2315
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2316
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2317
+ if (t[2]) _.ops.pop();
2318
+ _.trys.pop(); continue;
2319
+ }
2320
+ op = body.call(thisArg, _);
2321
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2322
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2323
+ }
2324
+ };
2325
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
2326
+ return (mod && mod.__esModule) ? mod : { "default": mod };
2327
+ };
2328
+ Object.defineProperty(useWebsocket, "__esModule", { value: true });
2329
+ useWebsocket.useWebSocket = void 0;
2330
+ var react_1$2 = require$$0;
2331
+ var react_dom_1 = require$$1;
2332
+ var constants_1$2 = constants;
2333
+ var create_or_join_1 = createOrJoin;
2334
+ var get_url_1 = getUrl;
2335
+ var proxy_1 = __importDefault(proxy);
2336
+ var util_1 = util;
2337
+ var useWebSocket$1 = function (url, options, connect) {
2338
+ if (options === void 0) { options = constants_1$2.DEFAULT_OPTIONS; }
2339
+ if (connect === void 0) { connect = true; }
2340
+ var _a = (0, react_1$2.useState)(null), lastMessage = _a[0], setLastMessage = _a[1];
2341
+ var _b = (0, react_1$2.useState)({}), readyState = _b[0], setReadyState = _b[1];
2342
+ var lastJsonMessage = (0, react_1$2.useMemo)(function () {
2343
+ if (!options.disableJson && lastMessage) {
2344
+ try {
2345
+ return JSON.parse(lastMessage.data);
2346
+ }
2347
+ catch (e) {
2348
+ return constants_1$2.UNPARSABLE_JSON_OBJECT;
2349
+ }
2350
+ }
2351
+ return null;
2352
+ }, [lastMessage, options.disableJson]);
2353
+ var convertedUrl = (0, react_1$2.useRef)(null);
2354
+ var webSocketRef = (0, react_1$2.useRef)(null);
2355
+ var startRef = (0, react_1$2.useRef)(function () { return void 0; });
2356
+ var reconnectCount = (0, react_1$2.useRef)(0);
2357
+ var lastMessageTime = (0, react_1$2.useRef)(Date.now());
2358
+ var messageQueue = (0, react_1$2.useRef)([]);
2359
+ var webSocketProxy = (0, react_1$2.useRef)(null);
2360
+ var optionsCache = (0, react_1$2.useRef)(options);
2361
+ optionsCache.current = options;
2362
+ var readyStateFromUrl = convertedUrl.current && readyState[convertedUrl.current] !== undefined ?
2363
+ readyState[convertedUrl.current] :
2364
+ url !== null && connect === true ?
2365
+ constants_1$2.ReadyState.CONNECTING :
2366
+ constants_1$2.ReadyState.UNINSTANTIATED;
2367
+ var stringifiedQueryParams = options.queryParams ? JSON.stringify(options.queryParams) : null;
2368
+ var sendMessage = (0, react_1$2.useCallback)(function (message, keep) {
2369
+ var _a;
2370
+ if (keep === void 0) { keep = true; }
2371
+ if (constants_1$2.isEventSourceSupported && webSocketRef.current instanceof EventSource) {
2372
+ console.warn('Unable to send a message from an eventSource');
2373
+ return;
2374
+ }
2375
+ if (((_a = webSocketRef.current) === null || _a === void 0 ? void 0 : _a.readyState) === constants_1$2.ReadyState.OPEN) {
2376
+ (0, util_1.assertIsWebSocket)(webSocketRef.current, optionsCache.current.skipAssert);
2377
+ webSocketRef.current.send(message);
2378
+ }
2379
+ else if (keep) {
2380
+ messageQueue.current.push(message);
2381
+ }
2382
+ }, []);
2383
+ var sendJsonMessage = (0, react_1$2.useCallback)(function (message, keep) {
2384
+ if (keep === void 0) { keep = true; }
2385
+ sendMessage(JSON.stringify(message), keep);
2386
+ }, [sendMessage]);
2387
+ var getWebSocket = (0, react_1$2.useCallback)(function () {
2388
+ if (optionsCache.current.share !== true || (constants_1$2.isEventSourceSupported && webSocketRef.current instanceof EventSource)) {
2389
+ return webSocketRef.current;
2390
+ }
2391
+ if (webSocketProxy.current === null && webSocketRef.current) {
2392
+ (0, util_1.assertIsWebSocket)(webSocketRef.current, optionsCache.current.skipAssert);
2393
+ webSocketProxy.current = (0, proxy_1.default)(webSocketRef.current, startRef);
2394
+ }
2395
+ return webSocketProxy.current;
2396
+ }, []);
2397
+ (0, react_1$2.useEffect)(function () {
2398
+ if (url !== null && connect === true) {
2399
+ var removeListeners_1;
2400
+ var expectClose_1 = false;
2401
+ var createOrJoin_1 = true;
2402
+ var start_1 = function () { return __awaiter(void 0, void 0, void 0, function () {
2403
+ var _a, protectedSetLastMessage, protectedSetReadyState;
2404
+ return __generator(this, function (_b) {
2405
+ switch (_b.label) {
2406
+ case 0:
2407
+ _a = convertedUrl;
2408
+ return [4 /*yield*/, (0, get_url_1.getUrl)(url, optionsCache)];
2409
+ case 1:
2410
+ _a.current = _b.sent();
2411
+ if (convertedUrl.current === null) {
2412
+ console.error('Failed to get a valid URL. WebSocket connection aborted.');
2413
+ convertedUrl.current = 'ABORTED';
2414
+ (0, react_dom_1.flushSync)(function () { return setReadyState(function (prev) { return (__assign$2(__assign$2({}, prev), { ABORTED: constants_1$2.ReadyState.CLOSED })); }); });
2415
+ return [2 /*return*/];
2416
+ }
2417
+ protectedSetLastMessage = function (message) {
2418
+ if (!expectClose_1) {
2419
+ (0, react_dom_1.flushSync)(function () { return setLastMessage(message); });
2420
+ }
2421
+ };
2422
+ protectedSetReadyState = function (state) {
2423
+ if (!expectClose_1) {
2424
+ (0, react_dom_1.flushSync)(function () { return setReadyState(function (prev) {
2425
+ var _a;
2426
+ return (__assign$2(__assign$2({}, prev), (convertedUrl.current && (_a = {}, _a[convertedUrl.current] = state, _a))));
2427
+ }); });
2428
+ }
2429
+ };
2430
+ if (createOrJoin_1) {
2431
+ removeListeners_1 = (0, create_or_join_1.createOrJoinSocket)(webSocketRef, convertedUrl.current, protectedSetReadyState, optionsCache, protectedSetLastMessage, startRef, reconnectCount, lastMessageTime, sendMessage);
2432
+ }
2433
+ return [2 /*return*/];
2434
+ }
2435
+ });
2436
+ }); };
2437
+ startRef.current = function () {
2438
+ if (!expectClose_1) {
2439
+ if (webSocketProxy.current)
2440
+ webSocketProxy.current = null;
2441
+ removeListeners_1 === null || removeListeners_1 === void 0 ? void 0 : removeListeners_1();
2442
+ start_1();
2443
+ }
2444
+ };
2445
+ start_1();
2446
+ return function () {
2447
+ expectClose_1 = true;
2448
+ createOrJoin_1 = false;
2449
+ if (webSocketProxy.current)
2450
+ webSocketProxy.current = null;
2451
+ removeListeners_1 === null || removeListeners_1 === void 0 ? void 0 : removeListeners_1();
2452
+ setLastMessage(null);
2453
+ };
2454
+ }
2455
+ else if (url === null || connect === false) {
2456
+ reconnectCount.current = 0; // reset reconnection attempts
2457
+ setReadyState(function (prev) {
2458
+ var _a;
2459
+ return (__assign$2(__assign$2({}, prev), (convertedUrl.current && (_a = {}, _a[convertedUrl.current] = constants_1$2.ReadyState.CLOSED, _a))));
2460
+ });
2461
+ }
2462
+ }, [url, connect, stringifiedQueryParams, sendMessage]);
2463
+ (0, react_1$2.useEffect)(function () {
2464
+ if (readyStateFromUrl === constants_1$2.ReadyState.OPEN) {
2465
+ messageQueue.current.splice(0).forEach(function (message) {
2466
+ sendMessage(message);
2467
+ });
2468
+ }
2469
+ }, [readyStateFromUrl]);
2470
+ return {
2471
+ sendMessage: sendMessage,
2472
+ sendJsonMessage: sendJsonMessage,
2473
+ lastMessage: lastMessage,
2474
+ lastJsonMessage: lastJsonMessage,
2475
+ readyState: readyStateFromUrl,
2476
+ getWebSocket: getWebSocket,
2477
+ };
2478
+ };
2479
+ useWebsocket.useWebSocket = useWebSocket$1;
2480
+
2481
+ var useSocketIo = {};
2482
+
2483
+ var __assign$1 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
2484
+ __assign$1 = Object.assign || function(t) {
2485
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
2486
+ s = arguments[i];
2487
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
2488
+ t[p] = s[p];
2489
+ }
2490
+ return t;
2491
+ };
2492
+ return __assign$1.apply(this, arguments);
2493
+ };
2494
+ Object.defineProperty(useSocketIo, "__esModule", { value: true });
2495
+ useSocketIo.useSocketIO = void 0;
2496
+ var react_1$1 = require$$0;
2497
+ var use_websocket_1$1 = useWebsocket;
2498
+ var constants_1$1 = constants;
2499
+ var emptyEvent = {
2500
+ type: 'empty',
2501
+ payload: null,
2502
+ };
2503
+ var getSocketData = function (event) {
2504
+ if (!event || !event.data) {
2505
+ return emptyEvent;
2506
+ }
2507
+ var match = event.data.match(/\[.*]/);
2508
+ if (!match) {
2509
+ return emptyEvent;
2510
+ }
2511
+ var data = JSON.parse(match);
2512
+ if (!Array.isArray(data) || !data[1]) {
2513
+ return emptyEvent;
2514
+ }
2515
+ return {
2516
+ type: data[0],
2517
+ payload: data[1],
2518
+ };
2519
+ };
2520
+ var useSocketIO = function (url, options, connect) {
2521
+ if (options === void 0) { options = constants_1$1.DEFAULT_OPTIONS; }
2522
+ if (connect === void 0) { connect = true; }
2523
+ var optionsWithSocketIO = (0, react_1$1.useMemo)(function () { return (__assign$1(__assign$1({}, options), { fromSocketIO: true })); }, []);
2524
+ var _a = (0, use_websocket_1$1.useWebSocket)(url, optionsWithSocketIO, connect), sendMessage = _a.sendMessage, sendJsonMessage = _a.sendJsonMessage, lastMessage = _a.lastMessage, readyState = _a.readyState, getWebSocket = _a.getWebSocket;
2525
+ var socketIOLastMessage = (0, react_1$1.useMemo)(function () {
2526
+ return getSocketData(lastMessage);
2527
+ }, [lastMessage]);
2528
+ return {
2529
+ sendMessage: sendMessage,
2530
+ sendJsonMessage: sendJsonMessage,
2531
+ lastMessage: socketIOLastMessage,
2532
+ lastJsonMessage: socketIOLastMessage,
2533
+ readyState: readyState,
2534
+ getWebSocket: getWebSocket,
2535
+ };
2536
+ };
2537
+ useSocketIo.useSocketIO = useSocketIO;
2538
+
2539
+ var useEventSource$1 = {};
2540
+
2541
+ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
2542
+ __assign = Object.assign || function(t) {
2543
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
2544
+ s = arguments[i];
2545
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
2546
+ t[p] = s[p];
2547
+ }
2548
+ return t;
2549
+ };
2550
+ return __assign.apply(this, arguments);
2551
+ };
2552
+ var __rest = (commonjsGlobal && commonjsGlobal.__rest) || function (s, e) {
2553
+ var t = {};
2554
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2555
+ t[p] = s[p];
2556
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
2557
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
2558
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
2559
+ t[p[i]] = s[p[i]];
2560
+ }
2561
+ return t;
2562
+ };
2563
+ Object.defineProperty(useEventSource$1, "__esModule", { value: true });
2564
+ useEventSource$1.useEventSource = void 0;
2565
+ var react_1 = require$$0;
2566
+ var use_websocket_1 = useWebsocket;
2567
+ var constants_1 = constants;
2568
+ var useEventSource = function (url, _a, connect) {
2569
+ if (_a === void 0) { _a = constants_1.DEFAULT_EVENT_SOURCE_OPTIONS; }
2570
+ var withCredentials = _a.withCredentials, events = _a.events, options = __rest(_a, ["withCredentials", "events"]);
2571
+ if (connect === void 0) { connect = true; }
2572
+ var optionsWithEventSource = __assign(__assign({}, options), { eventSourceOptions: {
2573
+ withCredentials: withCredentials,
2574
+ } });
2575
+ var eventsRef = (0, react_1.useRef)(constants_1.EMPTY_EVENT_HANDLERS);
2576
+ if (events) {
2577
+ eventsRef.current = events;
2578
+ }
2579
+ var _b = (0, use_websocket_1.useWebSocket)(url, optionsWithEventSource, connect), lastMessage = _b.lastMessage, readyState = _b.readyState, getWebSocket = _b.getWebSocket;
2580
+ (0, react_1.useEffect)(function () {
2581
+ if (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) {
2582
+ Object.entries(eventsRef.current).forEach(function (_a) {
2583
+ var type = _a[0], handler = _a[1];
2584
+ if (type === lastMessage.type) {
2585
+ handler(lastMessage);
2586
+ }
2587
+ });
2588
+ }
2589
+ }, [lastMessage]);
2590
+ return {
2591
+ lastEvent: lastMessage,
2592
+ readyState: readyState,
2593
+ getEventSource: getWebSocket,
2594
+ };
2595
+ };
2596
+ useEventSource$1.useEventSource = useEventSource;
2597
+
2598
+ (function (exports) {
2599
+ Object.defineProperty(exports, "__esModule", { value: true });
2600
+ exports.resetGlobalState = exports.useEventSource = exports.ReadyState = exports.useSocketIO = exports.default = void 0;
2601
+ var use_websocket_1 = useWebsocket;
2602
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return use_websocket_1.useWebSocket; } });
2603
+ var use_socket_io_1 = useSocketIo;
2604
+ Object.defineProperty(exports, "useSocketIO", { enumerable: true, get: function () { return use_socket_io_1.useSocketIO; } });
2605
+ var constants_1 = constants;
2606
+ Object.defineProperty(exports, "ReadyState", { enumerable: true, get: function () { return constants_1.ReadyState; } });
2607
+ var use_event_source_1 = useEventSource$1;
2608
+ Object.defineProperty(exports, "useEventSource", { enumerable: true, get: function () { return use_event_source_1.useEventSource; } });
2609
+ var util_1 = util;
2610
+ Object.defineProperty(exports, "resetGlobalState", { enumerable: true, get: function () { return util_1.resetGlobalState; } });
2611
+
2612
+ } (dist));
2613
+
2614
+ var useWebSocket = /*@__PURE__*/getDefaultExportFromCjs(dist);
2615
+
2616
+ const PearHyperliquidContext = require$$0.createContext(undefined);
2617
+ /**
2618
+ * React Provider for PearHyperliquidClient
2619
+ */
2620
+ const PearHyperliquidProvider = ({ config, wsUrl = 'wss://hl-v2.pearprotocol.io/ws', children, }) => {
2621
+ const client = require$$0.useMemo(() => new PearHyperliquidClient(config), [config]);
2622
+ const migrationSDK = require$$0.useMemo(() => new PearMigrationSDK(client), [client]);
2623
+ // Address state
2624
+ const [address, setAddress] = require$$0.useState(null);
2625
+ // WebSocket data state
2626
+ const [data, setData] = require$$0.useState({
2627
+ tradeHistories: null,
2628
+ openPositions: null,
2629
+ openOrders: null,
2630
+ accountSummary: null,
2631
+ });
2632
+ const [lastError, setLastError] = require$$0.useState(null);
2633
+ // WebSocket connection
2634
+ const { lastMessage, readyState, sendMessage } = useWebSocket(address ? wsUrl : null, // Only connect when address is set
2635
+ {
2636
+ shouldReconnect: () => true,
2637
+ reconnectAttempts: 5,
2638
+ reconnectInterval: 3000,
2639
+ });
2640
+ const isConnected = readyState === dist.ReadyState.OPEN;
2641
+ // Handle incoming WebSocket messages
2642
+ require$$0.useEffect(() => {
2643
+ if (lastMessage !== null) {
2644
+ try {
2645
+ const message = JSON.parse(lastMessage.data);
2646
+ // Handle subscription responses
2647
+ if ('success' in message || 'error' in message) {
2648
+ if (message.error) {
2649
+ setLastError(message.error);
2650
+ }
2651
+ else {
2652
+ setLastError(null);
2653
+ }
2654
+ return;
2655
+ }
2656
+ // Handle channel data messages
2657
+ if ('channel' in message && 'data' in message) {
2658
+ const dataMessage = message;
2659
+ switch (dataMessage.channel) {
2660
+ case 'trade-histories':
2661
+ setData(prev => ({
2662
+ ...prev,
2663
+ tradeHistories: dataMessage.data
2664
+ }));
2665
+ break;
2666
+ case 'open-positions':
2667
+ setData(prev => ({
2668
+ ...prev,
2669
+ openPositions: dataMessage.data
2670
+ }));
2671
+ break;
2672
+ case 'open-orders':
2673
+ setData(prev => ({
2674
+ ...prev,
2675
+ openOrders: dataMessage.data
2676
+ }));
2677
+ break;
2678
+ case 'account-summary':
2679
+ setData(prev => ({
2680
+ ...prev,
2681
+ accountSummary: dataMessage.data
2682
+ }));
2683
+ break;
2684
+ }
2685
+ }
2686
+ }
2687
+ catch (error) {
2688
+ setLastError(`Failed to parse message: ${error instanceof Error ? error.message : String(error)}`);
2689
+ }
2690
+ }
2691
+ }, [lastMessage]);
2692
+ // Handle address changes - subscribe/unsubscribe
2693
+ require$$0.useEffect(() => {
2694
+ if (isConnected && address) {
2695
+ // Subscribe to new address
2696
+ sendMessage(JSON.stringify({
2697
+ action: 'subscribe',
2698
+ address: address
2699
+ }));
2700
+ // Clear previous data
2701
+ setData({
2702
+ tradeHistories: null,
2703
+ openPositions: null,
2704
+ openOrders: null,
2705
+ accountSummary: null,
2706
+ });
2707
+ setLastError(null);
2708
+ }
2709
+ else if (isConnected && !address) {
2710
+ // Clear data when address is removed
2711
+ setData({
2712
+ tradeHistories: null,
2713
+ openPositions: null,
2714
+ openOrders: null,
2715
+ accountSummary: null,
2716
+ });
2717
+ }
2718
+ }, [isConnected, address, sendMessage]);
2719
+ const contextValue = require$$0.useMemo(() => ({
2720
+ // Existing clients
2721
+ client,
2722
+ migrationSDK,
2723
+ // Address management
2724
+ address,
2725
+ setAddress,
2726
+ // WebSocket state
2727
+ connectionStatus: readyState,
2728
+ isConnected,
2729
+ // WebSocket data
2730
+ data,
2731
+ lastError,
2732
+ }), [client, migrationSDK, address, readyState, isConnected, data, lastError]);
2733
+ return (jsxRuntimeExports.jsx(PearHyperliquidContext.Provider, { value: contextValue, children: children }));
2734
+ };
2735
+ /**
2736
+ * Hook to use PearHyperliquidClient from context
2737
+ */
2738
+ const usePearHyperliquidClient = () => {
2739
+ const context = require$$0.useContext(PearHyperliquidContext);
2740
+ if (!context) {
2741
+ throw new Error('usePearHyperliquidClient must be used within a PearHyperliquidProvider');
2742
+ }
2743
+ return context.client;
2744
+ };
2745
+ /**
2746
+ * Hook to use migration SDK from context
2747
+ */
2748
+ const useMigrationSDK = () => {
2749
+ const context = require$$0.useContext(PearHyperliquidContext);
2750
+ if (!context) {
2751
+ throw new Error('useMigrationSDK must be used within a PearHyperliquidProvider');
2752
+ }
2753
+ return context.migrationSDK;
2754
+ };
2755
+
2756
+ /**
2757
+ * Hook to manage address (login/logout functionality)
2758
+ */
2759
+ const useAddress = () => {
2760
+ const context = require$$0.useContext(PearHyperliquidContext);
2761
+ if (!context) {
2762
+ throw new Error('useAddress must be used within a PearHyperliquidProvider');
2763
+ }
2764
+ return {
2765
+ address: context.address,
2766
+ setAddress: context.setAddress,
2767
+ clearAddress: () => context.setAddress(null),
2768
+ isLoggedIn: !!context.address,
2769
+ };
2770
+ };
2771
+
2772
+ /**
2773
+ * Hook to access trade histories
2774
+ */
2775
+ const useTradeHistories = () => {
2776
+ const context = require$$0.useContext(PearHyperliquidContext);
2777
+ if (!context) {
2778
+ throw new Error('useTradeHistories must be used within a PearHyperliquidProvider');
2779
+ }
2780
+ return context.data.tradeHistories;
2781
+ };
2782
+ /**
2783
+ * Hook to access open positions
2784
+ */
2785
+ const useOpenPositions = () => {
2786
+ const context = require$$0.useContext(PearHyperliquidContext);
2787
+ if (!context) {
2788
+ throw new Error('useOpenPositions must be used within a PearHyperliquidProvider');
2789
+ }
2790
+ return context.data.openPositions;
2791
+ };
2792
+ /**
2793
+ * Hook to access open orders
2794
+ */
2795
+ const useOpenOrders = () => {
2796
+ const context = require$$0.useContext(PearHyperliquidContext);
2797
+ if (!context) {
2798
+ throw new Error('useOpenOrders must be used within a PearHyperliquidProvider');
2799
+ }
2800
+ return context.data.openOrders;
2801
+ };
2802
+ /**
2803
+ * Hook to access account summary
2804
+ */
2805
+ const useAccountSummary = () => {
2806
+ const context = require$$0.useContext(PearHyperliquidContext);
2807
+ if (!context) {
2808
+ throw new Error('useAccountSummary must be used within a PearHyperliquidProvider');
2809
+ }
2810
+ return context.data.accountSummary;
2811
+ };
2812
+
2813
+ exports.PearHyperliquidClient = PearHyperliquidClient;
2814
+ exports.PearHyperliquidProvider = PearHyperliquidProvider;
2815
+ exports.PearMigrationSDK = PearMigrationSDK;
2816
+ exports.default = PearHyperliquidClient;
2817
+ exports.useAccountSummary = useAccountSummary;
2818
+ exports.useAddress = useAddress;
2819
+ exports.useMigrationSDK = useMigrationSDK;
2820
+ exports.useOpenOrders = useOpenOrders;
2821
+ exports.useOpenPositions = useOpenPositions;
2822
+ exports.usePearHyperliquidClient = usePearHyperliquidClient;
2823
+ exports.useTradeHistories = useTradeHistories;
2824
+ //# sourceMappingURL=index.js.map