@trade-it/react 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,56 +1,1269 @@
1
- import { TradeLinkParam, getTradeItErrorMessage, getTradeItErrorMessage as getTradeItErrorMessage$1, getUrlOrigin, getUrlOrigin as getUrlOrigin$1, isTradeItEvent, isTradeItEvent as isTradeItEvent$1, resolveLaunchUrl, resolveLaunchUrl as resolveLaunchUrl$1 } from "@trade-it/core";
2
- import { useCallback, useEffect, useMemo, useState } from "react";
1
+ import { EmbedEventType, EmbedEventType as EmbedEventType$1, TradeLinkParam, getTradeItErrorMessage, getTradeItErrorMessage as getTradeItErrorMessage$1, getUrlOrigin, getUrlOrigin as getUrlOrigin$1, isTradeItAuthorization, isTradeItAuthorization as isTradeItAuthorization$1, isTradeItEvent, isTradeItEvent as isTradeItEvent$1, resolveLaunchUrl, resolveLaunchUrl as resolveLaunchUrl$1 } from "@trade-it/core";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { createPortal } from "react-dom";
4
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
5
 
6
- //#region src/LoaderCircleSpinner.tsx
7
- const SPINNER_WRAPPER_SIZE = 44;
8
- const SPINNER_ICON_SIZE = 32;
9
- const SPINNER_WRAPPER_STYLE = {
10
- width: SPINNER_WRAPPER_SIZE,
11
- height: SPINNER_WRAPPER_SIZE,
12
- display: "flex",
13
- alignItems: "center",
14
- justifyContent: "center",
15
- animation: "tradeItSdkSpin 0.9s linear infinite",
16
- transformOrigin: "50% 50%"
6
+ //#region src/TradeItLogoLoader.tsx
7
+ function fibDir(i, n) {
8
+ const golden = Math.PI * (3 - Math.sqrt(5));
9
+ const y = 1 - 2 * (i + .5) / n;
10
+ const rad = Math.sqrt(1 - y * y);
11
+ const a = i * golden;
12
+ return [
13
+ rad * Math.cos(a),
14
+ y,
15
+ rad * Math.sin(a)
16
+ ];
17
+ }
18
+ function makeProj(yaw, tilt, cx, cy, scale) {
19
+ const st = Math.sin(tilt);
20
+ const ct = Math.cos(tilt);
21
+ const sy = Math.sin(yaw);
22
+ const cyw = Math.cos(yaw);
23
+ return (x, y, z) => {
24
+ const x1 = x * cyw + z * sy;
25
+ const z1 = -x * sy + z * cyw;
26
+ const y1 = y * ct - z1 * st;
27
+ const z2 = y * st + z1 * ct;
28
+ return [
29
+ cx + x1 * scale,
30
+ cy - y1 * scale,
31
+ z2
32
+ ];
33
+ };
34
+ }
35
+ function paint(ctx, dots) {
36
+ for (const dot of dots) {
37
+ const alpha = dot.a ?? 1;
38
+ ctx.fillStyle = `rgba(240,240,242,${alpha})`;
39
+ ctx.beginPath();
40
+ ctx.arc(dot.x, dot.y, dot.r, 0, Math.PI * 2);
41
+ ctx.fill();
42
+ }
43
+ }
44
+ function paintLines(ctx, lines) {
45
+ for (const line of lines) {
46
+ const alpha = line.a ?? 1;
47
+ ctx.strokeStyle = `rgba(240,240,242,${alpha})`;
48
+ ctx.lineWidth = line.w;
49
+ ctx.beginPath();
50
+ ctx.moveTo(line.x1, line.y1);
51
+ ctx.lineTo(line.x2, line.y2);
52
+ ctx.stroke();
53
+ }
54
+ }
55
+ function finalizeFrame(dots, lines, rMin = .3) {
56
+ const visible = [];
57
+ for (const d of dots) {
58
+ if ((d.a ?? 1) < .02) continue;
59
+ d.r = Math.max(rMin, d.r);
60
+ visible.push(d);
61
+ }
62
+ visible.sort((a, b) => a.z - b.z);
63
+ return {
64
+ dots: visible,
65
+ lines: lines.filter((l) => (l.a ?? 1) >= .02)
66
+ };
67
+ }
68
+ function paintFrame(ctx, frame) {
69
+ if (frame.lines.length) paintLines(ctx, frame.lines);
70
+ paint(ctx, frame.dots);
71
+ }
72
+ function radiusScale(size, pow) {
73
+ return (size / 300) ** pow;
74
+ }
75
+ const TURN = Math.PI * 2;
76
+ function clamp01(x) {
77
+ return x < 0 ? 0 : x > 1 ? 1 : x;
78
+ }
79
+ function empty() {
80
+ return {
81
+ dots: [],
82
+ lines: []
83
+ };
84
+ }
85
+ function inkOf(o, zx, edge) {
86
+ const far = o.inkFar ?? .6;
87
+ const span = o.inkSpan ?? .5;
88
+ const rim = o.inkRim ?? .16;
89
+ return far - span * zx - rim * (1 - edge);
90
+ }
91
+ function expoInOut(x) {
92
+ if (x <= 0) return 0;
93
+ if (x >= 1) return 1;
94
+ return x < .5 ? 2 ** (20 * x - 10) / 2 : (2 - 2 ** (-20 * x + 10)) / 2;
95
+ }
96
+ function morphEase(x, expo) {
97
+ const smooth = x * x * x * (x * (x * 6 - 15) + 10);
98
+ return smooth + (expoInOut(x) - smooth) * expo;
99
+ }
100
+ function cruise(x, edge) {
101
+ const a = Math.min(.49, Math.max(.001, edge));
102
+ const v = 1 / (1 - a);
103
+ if (x <= 0) return 0;
104
+ if (x >= 1) return 1;
105
+ if (x < a) {
106
+ const u = x / a;
107
+ return v * a * (u * u * u - u * u * u * u / 2);
108
+ }
109
+ if (x > 1 - a) {
110
+ const u = (1 - x) / a;
111
+ return 1 - v * a * (u * u * u - u * u * u * u / 2);
112
+ }
113
+ return v * (a * .5 + (x - a));
114
+ }
115
+ function beatAt(t, dwell, morph, turns, settle, expo = .3) {
116
+ const cycle = dwell + morph * 2;
117
+ const local = t % cycle;
118
+ const spinSpan = dwell + morph * settle;
119
+ const spun = turns * cruise(Math.min(1, local / spinSpan), .22);
120
+ if (local < dwell) return {
121
+ m: 0,
122
+ turns: spun,
123
+ workT: local,
124
+ local,
125
+ cycle
126
+ };
127
+ const intoMorph = local - dwell;
128
+ if (intoMorph < morph) return {
129
+ m: morphEase(intoMorph / morph, expo),
130
+ turns: spun,
131
+ workT: -1,
132
+ local,
133
+ cycle
134
+ };
135
+ return {
136
+ m: morphEase(1 - (intoMorph - morph) / morph, expo),
137
+ turns: spun,
138
+ workT: -1,
139
+ local,
140
+ cycle
141
+ };
142
+ }
143
+ const frameLogoWait = (size, t, o, logo) => {
144
+ if (!logo) return empty();
145
+ const { p, e, n } = logo.points;
146
+ const seats = logo.seats;
147
+ const cx = size / 2;
148
+ const R = size / 2 * .82;
149
+ const rs = radiusScale(size, o.rsPow ?? .6);
150
+ const b = beatAt(t, o.dwell ?? 5.5, o.morph ?? 1.9, o.turns ?? 0, o.settle ?? .1, o.expo ?? .3);
151
+ const m = 1 - b.m;
152
+ const c = 1 - m;
153
+ const pt = makeProj((o.yawAmp ?? .22) * Math.sin(t * (o.yawRate ?? .3)) * c, (o.tilt ?? .42) * c, cx, cx, R);
154
+ const rings = Math.max(3, Math.round(o.rings ?? 9));
155
+ const perRing = Math.ceil(n / rings);
156
+ const breath = Math.sin(t * (o.breatheRate ?? .75));
157
+ const amp = o.breatheAmp ?? .2;
158
+ const height = (o.height ?? 1.5) * (1 + amp * breath);
159
+ const wide = (o.wide ?? .82) * (1 - amp * .72 * breath);
160
+ const spin = t * (o.spin ?? .16);
161
+ const dots = [];
162
+ for (let i = 0; i < n; i++) {
163
+ const seat = seats[i];
164
+ const ring = seat % rings;
165
+ const u = rings > 1 ? ring / (rings - 1) - .5 : 0;
166
+ const taper = Math.cos(u * Math.PI * (o.taper ?? .78));
167
+ const rad = wide * taper;
168
+ const ang = Math.floor(seat / rings) / perRing * Math.PI * 2 + spin;
169
+ const bx = Math.cos(ang) * rad;
170
+ const by = u * height;
171
+ const bz = Math.sin(ang) * rad;
172
+ const lx = p[i * 3];
173
+ const ly = p[i * 3 + 1];
174
+ const lz = p[i * 3 + 2];
175
+ const x = lx + (bx - lx) * c;
176
+ const y = ly + (by - ly) * c;
177
+ const z3 = lz + (bz - lz) * c;
178
+ const [px, py, z] = pt(x, y, z3);
179
+ const zx = clamp01((z + 1) / 2);
180
+ const loud = clamp01(taper);
181
+ dots.push({
182
+ x: px,
183
+ y: py,
184
+ z,
185
+ r: ((o.rBase ?? .55) + (o.rDepth ?? 1.4) * zx + (o.loudR ?? .25) * loud * c) * rs,
186
+ white: inkOf(o, zx, e[i] * m + (1 - m)) - (o.loudInk ?? .12) * loud * c
187
+ });
188
+ }
189
+ return finalizeFrame(dots, [], o.rMin);
17
190
  };
18
- const SPINNER_SVG_STYLE = {
19
- display: "block",
20
- width: SPINNER_ICON_SIZE,
21
- height: SPINNER_ICON_SIZE,
22
- color: "#111827"
191
+ const POINTS = {
192
+ n: 239,
193
+ p: Float32Array.from([
194
+ -.012,
195
+ .809,
196
+ .108,
197
+ -.03,
198
+ .718,
199
+ .23,
200
+ -.132,
201
+ .666,
202
+ .237,
203
+ -.095,
204
+ .713,
205
+ .199,
206
+ -.029,
207
+ .651,
208
+ .168,
209
+ -.11,
210
+ .61,
211
+ .163,
212
+ -.147,
213
+ .748,
214
+ .07,
215
+ -.171,
216
+ .567,
217
+ .152,
218
+ .082,
219
+ .724,
220
+ .177,
221
+ -.243,
222
+ .587,
223
+ .226,
224
+ .041,
225
+ .622,
226
+ .135,
227
+ -.307,
228
+ .658,
229
+ .1,
230
+ -.231,
231
+ .689,
232
+ .115,
233
+ .107,
234
+ .6,
235
+ .157,
236
+ -.281,
237
+ .514,
238
+ .152,
239
+ .217,
240
+ .591,
241
+ .226,
242
+ -.349,
243
+ .618,
244
+ .141,
245
+ -.095,
246
+ .778,
247
+ 0,
248
+ .037,
249
+ .77,
250
+ .135,
251
+ .179,
252
+ .673,
253
+ .191,
254
+ -.344,
255
+ .561,
256
+ .226,
257
+ .119,
258
+ .667,
259
+ .237,
260
+ .242,
261
+ .648,
262
+ .172,
263
+ .267,
264
+ .536,
265
+ .182,
266
+ -.186,
267
+ .638,
268
+ .23,
269
+ .174,
270
+ .733,
271
+ 0,
272
+ -.204,
273
+ .519,
274
+ 0,
275
+ -.417,
276
+ .603,
277
+ .1,
278
+ .294,
279
+ .589,
280
+ .223,
281
+ -.407,
282
+ .543,
283
+ .207,
284
+ .154,
285
+ .55,
286
+ .081,
287
+ .343,
288
+ .633,
289
+ .1,
290
+ .347,
291
+ .528,
292
+ .226,
293
+ .379,
294
+ .581,
295
+ .177,
296
+ .447,
297
+ .595,
298
+ .07,
299
+ .315,
300
+ .471,
301
+ .081,
302
+ .452,
303
+ .498,
304
+ .23,
305
+ -.435,
306
+ .456,
307
+ .177,
308
+ -.337,
309
+ .488,
310
+ .141,
311
+ .397,
312
+ .447,
313
+ .135,
314
+ -.519,
315
+ .556,
316
+ .081,
317
+ -.529,
318
+ .414,
319
+ .233,
320
+ .462,
321
+ .399,
322
+ .199,
323
+ -.481,
324
+ .498,
325
+ .215,
326
+ -.569,
327
+ .462,
328
+ .172,
329
+ -.482,
330
+ .377,
331
+ .223,
332
+ -.568,
333
+ .523,
334
+ .1,
335
+ -.57,
336
+ .365,
337
+ .172,
338
+ .565,
339
+ .501,
340
+ .152,
341
+ .559,
342
+ .424,
343
+ .172,
344
+ .494,
345
+ .451,
346
+ .26,
347
+ .559,
348
+ .357,
349
+ .177,
350
+ .443,
351
+ .34,
352
+ .172,
353
+ -.529,
354
+ .303,
355
+ .233,
356
+ .489,
357
+ .299,
358
+ .07,
359
+ .409,
360
+ .293,
361
+ .07,
362
+ .502,
363
+ .542,
364
+ .135,
365
+ -.58,
366
+ .26,
367
+ .157,
368
+ -.461,
369
+ .239,
370
+ .07,
371
+ .404,
372
+ .388,
373
+ .07,
374
+ -.431,
375
+ .305,
376
+ .122,
377
+ -.593,
378
+ .203,
379
+ .122,
380
+ -.612,
381
+ .308,
382
+ .07,
383
+ -.534,
384
+ .204,
385
+ .07,
386
+ -.035,
387
+ .316,
388
+ .108,
389
+ -.02,
390
+ .251,
391
+ .195,
392
+ .023,
393
+ .163,
394
+ .195,
395
+ -.104,
396
+ .232,
397
+ .191,
398
+ -.054,
399
+ .149,
400
+ .29,
401
+ -.133,
402
+ .131,
403
+ .287,
404
+ -.098,
405
+ .289,
406
+ .07,
407
+ -.16,
408
+ .219,
409
+ .163,
410
+ .054,
411
+ .219,
412
+ .07,
413
+ .025,
414
+ .077,
415
+ .244,
416
+ -.001,
417
+ 0,
418
+ .312,
419
+ -.046,
420
+ .089,
421
+ .315,
422
+ -.243,
423
+ .159,
424
+ .195,
425
+ .092,
426
+ .116,
427
+ .108,
428
+ -.05,
429
+ .03,
430
+ .29,
431
+ -.298,
432
+ .06,
433
+ .276,
434
+ -.127,
435
+ .044,
436
+ .279,
437
+ .029,
438
+ -.062,
439
+ .312,
440
+ -.101,
441
+ -.026,
442
+ .195,
443
+ .103,
444
+ .038,
445
+ .191,
446
+ -.061,
447
+ -.124,
448
+ .168,
449
+ .086,
450
+ -.03,
451
+ .29,
452
+ -.182,
453
+ .096,
454
+ .301,
455
+ .199,
456
+ .08,
457
+ .115,
458
+ -.174,
459
+ -.024,
460
+ .186,
461
+ .264,
462
+ .022,
463
+ .244,
464
+ .134,
465
+ -.082,
466
+ .312,
467
+ -.236,
468
+ .056,
469
+ .307,
470
+ -.352,
471
+ .034,
472
+ .279,
473
+ -.045,
474
+ -.045,
475
+ .244,
476
+ .214,
477
+ -.112,
478
+ .251,
479
+ -.183,
480
+ .16,
481
+ .226,
482
+ .223,
483
+ -.026,
484
+ .287,
485
+ .146,
486
+ -.164,
487
+ .223,
488
+ .327,
489
+ -.051,
490
+ .244,
491
+ .129,
492
+ -.225,
493
+ .135,
494
+ -.021,
495
+ -.173,
496
+ .191,
497
+ .16,
498
+ -.021,
499
+ .266,
500
+ .042,
501
+ -.131,
502
+ .287,
503
+ .056,
504
+ -.198,
505
+ .24,
506
+ .244,
507
+ -.184,
508
+ .1,
509
+ .006,
510
+ -.246,
511
+ .177,
512
+ -.282,
513
+ .202,
514
+ 0,
515
+ .286,
516
+ .115,
517
+ .07,
518
+ -.299,
519
+ .121,
520
+ .199,
521
+ .286,
522
+ -.129,
523
+ .163,
524
+ .347,
525
+ .031,
526
+ .263,
527
+ -.316,
528
+ -.018,
529
+ .254,
530
+ -.242,
531
+ -.093,
532
+ .07,
533
+ -.253,
534
+ -.007,
535
+ .24,
536
+ -.366,
537
+ .126,
538
+ .141,
539
+ .352,
540
+ .092,
541
+ .177,
542
+ -.217,
543
+ .227,
544
+ .07,
545
+ -.405,
546
+ .072,
547
+ .199,
548
+ -.113,
549
+ -.086,
550
+ .115,
551
+ .344,
552
+ -.131,
553
+ .108,
554
+ -.307,
555
+ -.077,
556
+ .152,
557
+ -.429,
558
+ .013,
559
+ .254,
560
+ .061,
561
+ -.29,
562
+ .07,
563
+ -.003,
564
+ -.306,
565
+ .108,
566
+ .458,
567
+ .091,
568
+ .223,
569
+ -.484,
570
+ -.028,
571
+ .276,
572
+ .263,
573
+ -.075,
574
+ .254,
575
+ .401,
576
+ .136,
577
+ .122,
578
+ .431,
579
+ -.09,
580
+ .1,
581
+ .413,
582
+ .051,
583
+ .26,
584
+ .421,
585
+ -.023,
586
+ .226,
587
+ .512,
588
+ .027,
589
+ .226,
590
+ -.481,
591
+ .06,
592
+ .152,
593
+ -.054,
594
+ -.22,
595
+ .07,
596
+ .505,
597
+ -.041,
598
+ .135,
599
+ .579,
600
+ .045,
601
+ .215,
602
+ .517,
603
+ .09,
604
+ .247,
605
+ .602,
606
+ .142,
607
+ .219,
608
+ .575,
609
+ -.032,
610
+ .07,
611
+ -.38,
612
+ -.04,
613
+ .251,
614
+ -.471,
615
+ -.091,
616
+ .203,
617
+ -.572,
618
+ .021,
619
+ .141,
620
+ -.549,
621
+ -.038,
622
+ .251,
623
+ -.38,
624
+ -.128,
625
+ .1,
626
+ .479,
627
+ .169,
628
+ .07,
629
+ -.671,
630
+ -.021,
631
+ .135,
632
+ .66,
633
+ .029,
634
+ .129,
635
+ -.433,
636
+ .126,
637
+ .07,
638
+ .692,
639
+ .087,
640
+ .191,
641
+ -.64,
642
+ -.096,
643
+ .257,
644
+ .626,
645
+ .079,
646
+ .226,
647
+ .73,
648
+ .194,
649
+ .172,
650
+ -.711,
651
+ -.176,
652
+ .172,
653
+ -.529,
654
+ -.109,
655
+ .207,
656
+ .742,
657
+ .115,
658
+ .199,
659
+ .664,
660
+ .165,
661
+ .207,
662
+ .587,
663
+ .206,
664
+ .07,
665
+ .801,
666
+ .106,
667
+ .141,
668
+ -.742,
669
+ -.055,
670
+ .129,
671
+ -.563,
672
+ -.165,
673
+ .122,
674
+ -.783,
675
+ -.161,
676
+ .135,
677
+ .54,
678
+ .143,
679
+ .186,
680
+ -.7,
681
+ -.119,
682
+ .251,
683
+ -.613,
684
+ -.039,
685
+ .211,
686
+ .761,
687
+ .059,
688
+ .07,
689
+ -.633,
690
+ -.162,
691
+ .168,
692
+ -.478,
693
+ -.153,
694
+ .07,
695
+ .806,
696
+ .173,
697
+ .081,
698
+ .861,
699
+ .131,
700
+ .07,
701
+ -.827,
702
+ -.099,
703
+ .135,
704
+ .645,
705
+ .223,
706
+ .07,
707
+ .574,
708
+ -.176,
709
+ .081,
710
+ .493,
711
+ -.215,
712
+ .07,
713
+ .565,
714
+ -.281,
715
+ .172,
716
+ .519,
717
+ -.338,
718
+ .244,
719
+ .42,
720
+ -.269,
721
+ .108,
722
+ .442,
723
+ -.356,
724
+ .172,
725
+ .502,
726
+ -.277,
727
+ .195,
728
+ .552,
729
+ -.39,
730
+ .186,
731
+ .495,
732
+ -.416,
733
+ .251,
734
+ .415,
735
+ -.422,
736
+ .135,
737
+ .601,
738
+ -.339,
739
+ .07,
740
+ .395,
741
+ -.493,
742
+ .226,
743
+ .483,
744
+ -.53,
745
+ .157,
746
+ .357,
747
+ -.59,
748
+ .157,
749
+ .531,
750
+ -.486,
751
+ .191,
752
+ .316,
753
+ -.495,
754
+ .163,
755
+ .226,
756
+ -.494,
757
+ .07,
758
+ .415,
759
+ -.55,
760
+ .186,
761
+ .358,
762
+ -.427,
763
+ .07,
764
+ .577,
765
+ -.443,
766
+ .141,
767
+ .272,
768
+ -.554,
769
+ .226,
770
+ .198,
771
+ -.593,
772
+ .23,
773
+ .104,
774
+ -.581,
775
+ .129,
776
+ .184,
777
+ -.703,
778
+ .1,
779
+ .135,
780
+ -.64,
781
+ .244,
782
+ .162,
783
+ -.532,
784
+ .081,
785
+ .119,
786
+ -.726,
787
+ .129,
788
+ .035,
789
+ -.595,
790
+ .07,
791
+ .218,
792
+ -.648,
793
+ .182,
794
+ .585,
795
+ -.519,
796
+ .07,
797
+ .015,
798
+ -.683,
799
+ .23,
800
+ .081,
801
+ -.671,
802
+ .244,
803
+ .33,
804
+ -.648,
805
+ .07,
806
+ .039,
807
+ -.75,
808
+ .157,
809
+ -.089,
810
+ -.662,
811
+ .24,
812
+ -.019,
813
+ -.757,
814
+ .177,
815
+ -.064,
816
+ -.721,
817
+ .199,
818
+ -.133,
819
+ -.701,
820
+ .172,
821
+ -.043,
822
+ -.619,
823
+ .141,
824
+ -.125,
825
+ -.575,
826
+ .141,
827
+ -.148,
828
+ -.644,
829
+ .244,
830
+ -.252,
831
+ -.662,
832
+ .135,
833
+ -.192,
834
+ -.569,
835
+ .191,
836
+ -.189,
837
+ -.715,
838
+ .1,
839
+ -.27,
840
+ -.589,
841
+ .237,
842
+ -.29,
843
+ -.512,
844
+ .177,
845
+ -.211,
846
+ -.504,
847
+ 0,
848
+ -.325,
849
+ -.608,
850
+ .163,
851
+ -.372,
852
+ -.563,
853
+ .199,
854
+ -.365,
855
+ -.491,
856
+ .199,
857
+ -.454,
858
+ -.547,
859
+ .163,
860
+ -.431,
861
+ -.48,
862
+ .223,
863
+ -.489,
864
+ -.484,
865
+ .226,
866
+ -.514,
867
+ -.407,
868
+ .254,
869
+ -.538,
870
+ -.302,
871
+ .1,
872
+ -.378,
873
+ -.429,
874
+ .081,
875
+ -.391,
876
+ -.621,
877
+ .07,
878
+ -.457,
879
+ -.301,
880
+ .141,
881
+ -.321,
882
+ -.451,
883
+ .07,
884
+ -.457,
885
+ -.426,
886
+ .191,
887
+ -.578,
888
+ -.491,
889
+ .152,
890
+ -.582,
891
+ -.37,
892
+ .141,
893
+ -.413,
894
+ -.373,
895
+ .07,
896
+ -.494,
897
+ -.353,
898
+ .219,
899
+ -.598,
900
+ -.427,
901
+ .1,
902
+ -.514,
903
+ -.542,
904
+ .115,
905
+ .27,
906
+ -.621,
907
+ .172,
908
+ -.105,
909
+ -.762,
910
+ .07
911
+ ]),
912
+ e: Float32Array.from([
913
+ .1,
914
+ .457,
915
+ .486,
916
+ .343,
917
+ .243,
918
+ .229,
919
+ .043,
920
+ .2,
921
+ .271,
922
+ .443,
923
+ .157,
924
+ .086,
925
+ .114,
926
+ .214,
927
+ .2,
928
+ .443,
929
+ .171,
930
+ 0,
931
+ .157,
932
+ .314,
933
+ .443,
934
+ .486,
935
+ .257,
936
+ .286,
937
+ .457,
938
+ 0,
939
+ 0,
940
+ .086,
941
+ .429,
942
+ .371,
943
+ .057,
944
+ .086,
945
+ .443,
946
+ .271,
947
+ .043,
948
+ .057,
949
+ .457,
950
+ .271,
951
+ .171,
952
+ .157,
953
+ .057,
954
+ .471,
955
+ .343,
956
+ .4,
957
+ .257,
958
+ .429,
959
+ .086,
960
+ .257,
961
+ .2,
962
+ .257,
963
+ .586,
964
+ .271,
965
+ .257,
966
+ .471,
967
+ .043,
968
+ .043,
969
+ .157,
970
+ .214,
971
+ .043,
972
+ .043,
973
+ .129,
974
+ .129,
975
+ .043,
976
+ .043,
977
+ .1,
978
+ .329,
979
+ .329,
980
+ .314,
981
+ .729,
982
+ .714,
983
+ .043,
984
+ .229,
985
+ .043,
986
+ .514,
987
+ .843,
988
+ .857,
989
+ .329,
990
+ .1,
991
+ .729,
992
+ .657,
993
+ .671,
994
+ .843,
995
+ .329,
996
+ .314,
997
+ .243,
998
+ .729,
999
+ .786,
1000
+ .114,
1001
+ .3,
1002
+ .514,
1003
+ .843,
1004
+ .814,
1005
+ .671,
1006
+ .514,
1007
+ .543,
1008
+ .443,
1009
+ .714,
1010
+ .429,
1011
+ .514,
1012
+ .157,
1013
+ .314,
1014
+ .614,
1015
+ .714,
1016
+ .5,
1017
+ .086,
1018
+ .271,
1019
+ 0,
1020
+ .043,
1021
+ .343,
1022
+ .229,
1023
+ .6,
1024
+ .557,
1025
+ .043,
1026
+ .5,
1027
+ .171,
1028
+ .271,
1029
+ .043,
1030
+ .343,
1031
+ .114,
1032
+ .1,
1033
+ .2,
1034
+ .557,
1035
+ .043,
1036
+ .1,
1037
+ .429,
1038
+ .657,
1039
+ .557,
1040
+ .129,
1041
+ .086,
1042
+ .586,
1043
+ .443,
1044
+ .443,
1045
+ .2,
1046
+ .043,
1047
+ .157,
1048
+ .4,
1049
+ .529,
1050
+ .414,
1051
+ .043,
1052
+ .543,
1053
+ .357,
1054
+ .171,
1055
+ .543,
1056
+ .086,
1057
+ .043,
1058
+ .157,
1059
+ .143,
1060
+ .043,
1061
+ .314,
1062
+ .571,
1063
+ .443,
1064
+ .257,
1065
+ .257,
1066
+ .371,
1067
+ .343,
1068
+ .371,
1069
+ .043,
1070
+ .171,
1071
+ .143,
1072
+ .129,
1073
+ .157,
1074
+ .3,
1075
+ .543,
1076
+ .386,
1077
+ .043,
1078
+ .243,
1079
+ .043,
1080
+ .057,
1081
+ .043,
1082
+ .157,
1083
+ .043,
1084
+ .057,
1085
+ .043,
1086
+ .257,
1087
+ .514,
1088
+ .1,
1089
+ .257,
1090
+ .329,
1091
+ .3,
1092
+ .543,
1093
+ .157,
1094
+ .043,
1095
+ .443,
1096
+ .214,
1097
+ .214,
1098
+ .314,
1099
+ .229,
1100
+ .043,
1101
+ .3,
1102
+ .043,
1103
+ .171,
1104
+ .443,
1105
+ .457,
1106
+ .143,
1107
+ .086,
1108
+ .514,
1109
+ .057,
1110
+ .143,
1111
+ .043,
1112
+ .286,
1113
+ .043,
1114
+ .457,
1115
+ .514,
1116
+ .043,
1117
+ .214,
1118
+ .5,
1119
+ .271,
1120
+ .343,
1121
+ .257,
1122
+ .171,
1123
+ .171,
1124
+ .514,
1125
+ .157,
1126
+ .314,
1127
+ .086,
1128
+ .486,
1129
+ .271,
1130
+ 0,
1131
+ .229,
1132
+ .343,
1133
+ .343,
1134
+ .229,
1135
+ .429,
1136
+ .443,
1137
+ .557,
1138
+ .086,
1139
+ .057,
1140
+ .043,
1141
+ .171,
1142
+ .043,
1143
+ .314,
1144
+ .2,
1145
+ .171,
1146
+ .043,
1147
+ .414,
1148
+ .086,
1149
+ .114,
1150
+ .257,
1151
+ .043
1152
+ ])
23
1153
  };
24
- const SPINNER_KEYFRAMES_CSS = `
25
- @keyframes tradeItSdkSpin {
26
- from { transform: rotate(0deg); }
27
- to { transform: rotate(360deg); }
28
- }
29
- @media (prefers-reduced-motion: reduce) {
30
- .tradeit-sdk-spinner {
31
- animation: none !important;
32
- }
1154
+ const OPTS = {
1155
+ dwell: 1,
1156
+ morph: 1.7,
1157
+ expo: .3,
1158
+ settle: .1,
1159
+ turns: 0,
1160
+ yawAmp: .22,
1161
+ yawRate: .3,
1162
+ tilt: .42,
1163
+ rings: 9,
1164
+ height: 1.5,
1165
+ wide: .82,
1166
+ taper: .78,
1167
+ breatheRate: .75,
1168
+ breatheAmp: .2,
1169
+ spin: .16,
1170
+ loudR: .25,
1171
+ loudInk: .12,
1172
+ rBase: .55,
1173
+ rDepth: 1.4,
1174
+ inkFar: .6,
1175
+ inkSpan: .5,
1176
+ inkRim: .16,
1177
+ rsPow: .6,
1178
+ rMin: .3
1179
+ };
1180
+ function seatMap(points) {
1181
+ const n = points.n;
1182
+ const byLogo = new Uint32Array(n);
1183
+ const bySeat = new Uint32Array(n);
1184
+ const logoAng = new Float32Array(n);
1185
+ const seatAng = new Float32Array(n);
1186
+ for (let i = 0; i < n; i++) {
1187
+ byLogo[i] = i;
1188
+ bySeat[i] = i;
1189
+ logoAng[i] = Math.atan2(points.p[i * 3 + 1], points.p[i * 3]);
1190
+ const [sx, sy] = fibDir(i, n);
1191
+ seatAng[i] = Math.atan2(sy, sx);
1192
+ }
1193
+ byLogo.sort((a, b) => logoAng[a] - logoAng[b]);
1194
+ bySeat.sort((a, b) => seatAng[a] - seatAng[b]);
1195
+ const seats = new Uint32Array(n);
1196
+ for (let k = 0; k < n; k++) seats[byLogo[k]] = bySeat[k];
1197
+ return seats;
33
1198
  }
34
- `;
35
- function LoaderCircleSpinner() {
36
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("style", { children: SPINNER_KEYFRAMES_CSS }), /* @__PURE__ */ jsx("div", {
37
- className: "tradeit-sdk-spinner",
38
- style: SPINNER_WRAPPER_STYLE,
1199
+ const BINDING = {
1200
+ points: POINTS,
1201
+ seats: seatMap(POINTS)
1202
+ };
1203
+ function TradeItLogoLoader({ size = 120 }) {
1204
+ const ref = useRef(null);
1205
+ useEffect(() => {
1206
+ const canvas = ref.current;
1207
+ if (!canvas) return;
1208
+ const dpr = Math.min(2, devicePixelRatio || 1);
1209
+ canvas.width = Math.round(size * dpr);
1210
+ canvas.height = Math.round(size * dpr);
1211
+ const ctx = canvas.getContext("2d");
1212
+ if (!ctx) return;
1213
+ const render = (t) => {
1214
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1215
+ ctx.clearRect(0, 0, size, size);
1216
+ const frame = frameLogoWait(size, t, OPTS, BINDING);
1217
+ paintFrame(ctx, frame);
1218
+ };
1219
+ if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
1220
+ render(0);
1221
+ return;
1222
+ }
1223
+ let raf = 0;
1224
+ let running = false;
1225
+ const startedAt = performance.now();
1226
+ const loop = (now) => {
1227
+ render((now - startedAt) / 1e3);
1228
+ if (running) raf = requestAnimationFrame(loop);
1229
+ };
1230
+ const start = () => {
1231
+ if (running) return;
1232
+ running = true;
1233
+ raf = requestAnimationFrame(loop);
1234
+ };
1235
+ const stop = () => {
1236
+ running = false;
1237
+ cancelAnimationFrame(raf);
1238
+ };
1239
+ render(0);
1240
+ let visible = true;
1241
+ const io = new IntersectionObserver(([entry]) => {
1242
+ visible = entry.isIntersecting;
1243
+ if (visible && document.visibilityState !== "hidden") start();
1244
+ else stop();
1245
+ });
1246
+ io.observe(canvas);
1247
+ const onVis = () => {
1248
+ if (document.visibilityState === "hidden") stop();
1249
+ else if (visible) start();
1250
+ };
1251
+ document.addEventListener("visibilitychange", onVis);
1252
+ return () => {
1253
+ stop();
1254
+ io.disconnect();
1255
+ document.removeEventListener("visibilitychange", onVis);
1256
+ };
1257
+ }, [size]);
1258
+ return /* @__PURE__ */ jsx("canvas", {
1259
+ ref,
39
1260
  "aria-hidden": "true",
40
- children: /* @__PURE__ */ jsx("svg", {
41
- xmlns: "http://www.w3.org/2000/svg",
42
- width: SPINNER_ICON_SIZE,
43
- height: SPINNER_ICON_SIZE,
44
- viewBox: "0 0 24 24",
45
- fill: "none",
46
- stroke: "currentColor",
47
- strokeWidth: "2",
48
- strokeLinecap: "round",
49
- strokeLinejoin: "round",
50
- style: SPINNER_SVG_STYLE,
51
- children: /* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
52
- })
53
- })] });
1261
+ style: {
1262
+ width: size,
1263
+ height: size,
1264
+ display: "block"
1265
+ }
1266
+ });
54
1267
  }
55
1268
 
56
1269
  //#endregion
@@ -58,7 +1271,7 @@ function LoaderCircleSpinner() {
58
1271
  const LOADING_STYLE = {
59
1272
  position: "absolute",
60
1273
  inset: 0,
61
- background: "#ffffff"
1274
+ background: "#0e1011"
62
1275
  };
63
1276
  const LOADING_CONTENT_STYLE = {
64
1277
  position: "relative",
@@ -77,7 +1290,7 @@ function TradeItModalLoader() {
77
1290
  "aria-busy": "true",
78
1291
  children: /* @__PURE__ */ jsx("div", {
79
1292
  style: LOADING_CONTENT_STYLE,
80
- children: /* @__PURE__ */ jsx(LoaderCircleSpinner, {})
1293
+ children: /* @__PURE__ */ jsx(TradeItLogoLoader, {})
81
1294
  })
82
1295
  });
83
1296
  }
@@ -98,16 +1311,23 @@ const DIALOG_DESKTOP_STYLE = {
98
1311
  position: "relative",
99
1312
  width: "min(960px, calc(100vw - 24px))",
100
1313
  height: "min(760px, calc(100vh - 24px))",
101
- background: "#fff",
1314
+ boxSizing: "border-box",
1315
+ background: "#0e1011",
1316
+ colorScheme: "dark",
102
1317
  borderRadius: 18,
103
1318
  boxShadow: "0 24px 80px rgba(2, 6, 23, 0.28)",
104
- border: "1px solid rgba(148, 163, 184, 0.35)",
1319
+ border: "1px solid rgba(255, 255, 255, 0.14)",
105
1320
  overflow: "hidden"
106
1321
  };
1322
+ const CONNECT_DIALOG_DESKTOP_STYLE = {
1323
+ ...DIALOG_DESKTOP_STYLE,
1324
+ width: "min(736px, 100%)",
1325
+ height: "min(835px, 100%)"
1326
+ };
107
1327
  const DIALOG_MOBILE_STYLE = {
108
1328
  ...DIALOG_DESKTOP_STYLE,
109
- width: "100vw",
110
- height: "100vh",
1329
+ width: "100%",
1330
+ height: "100%",
111
1331
  borderRadius: 0,
112
1332
  border: 0
113
1333
  };
@@ -119,9 +1339,12 @@ const CLOSE_BUTTON_STYLE = {
119
1339
  width: 34,
120
1340
  height: 34,
121
1341
  borderRadius: 999,
122
- border: "1px solid rgba(148,163,184,0.45)",
123
- background: "rgba(255,255,255,0.92)",
124
- color: "#0f172a",
1342
+ border: "1px solid rgba(255, 255, 255, 0.22)",
1343
+ background: "rgba(9, 11, 12, 0.64)",
1344
+ color: "#f0f0f2",
1345
+ backdropFilter: "blur(16px)",
1346
+ WebkitBackdropFilter: "blur(16px)",
1347
+ boxShadow: "0 8px 24px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.12)",
125
1348
  cursor: "pointer",
126
1349
  fontSize: 18,
127
1350
  lineHeight: "32px",
@@ -132,7 +1355,8 @@ const IFRAME_STYLE = {
132
1355
  width: "100%",
133
1356
  height: "100%",
134
1357
  border: 0,
135
- background: "#fff"
1358
+ background: "#0e1011",
1359
+ colorScheme: "dark"
136
1360
  };
137
1361
  function useIsMobile(maxWidth = 640) {
138
1362
  const [isMobile, setIsMobile] = useState(false);
@@ -141,20 +1365,23 @@ function useIsMobile(maxWidth = 640) {
141
1365
  const mediaQuery = window.matchMedia(`(max-width: ${maxWidth}px)`);
142
1366
  const onChange = () => setIsMobile(mediaQuery.matches);
143
1367
  onChange();
144
- if (typeof mediaQuery.addEventListener === "function") {
145
- mediaQuery.addEventListener("change", onChange);
146
- return () => mediaQuery.removeEventListener("change", onChange);
147
- }
148
- mediaQuery.addListener(onChange);
149
- return () => mediaQuery.removeListener(onChange);
1368
+ mediaQuery.addEventListener("change", onChange);
1369
+ return () => mediaQuery.removeEventListener("change", onChange);
150
1370
  }, [maxWidth]);
151
1371
  return isMobile;
152
1372
  }
153
1373
  function TradeItModal(props) {
154
- const { open, onOpenChange, onEvent, onError, iframeTitle, keepMounted = false, closeOnEscape = true, closeOnOverlayClick = true, closeOnCloseRequestedEvent = true, showCloseButton = true, zIndex = 9999, title, className } = props;
1374
+ const { open, onOpenChange, onEvent, onAuthorization, onError, iframeTitle, keepMounted = false, closeOnEscape = true, closeOnOverlayClick = true, closeOnCloseRequestedEvent = true, showCloseButton = true, zIndex = 9999, title, className } = props;
155
1375
  const isMobile = useIsMobile();
156
1376
  const [isMounted, setIsMounted] = useState(false);
157
1377
  const [iframeLoaded, setIframeLoaded] = useState(false);
1378
+ const iframeRef = useRef(null);
1379
+ const authorizationRef = useRef({
1380
+ code: "",
1381
+ pending: false,
1382
+ failed: false,
1383
+ closeRequested: false
1384
+ });
158
1385
  const resolved = useMemo(() => {
159
1386
  try {
160
1387
  return {
@@ -178,6 +1405,12 @@ function TradeItModal(props) {
178
1405
  useEffect(() => {
179
1406
  if (!open) return;
180
1407
  setIframeLoaded(false);
1408
+ authorizationRef.current = {
1409
+ code: "",
1410
+ pending: false,
1411
+ failed: false,
1412
+ closeRequested: false
1413
+ };
181
1414
  }, [open, resolved.url]);
182
1415
  useEffect(() => {
183
1416
  if (!open || !closeOnEscape) return;
@@ -205,10 +1438,54 @@ function TradeItModal(props) {
205
1438
  if (!expectedOrigin) return;
206
1439
  const handleMessage = (event) => {
207
1440
  if (event.origin !== expectedOrigin) return;
1441
+ if (event.source !== iframeRef.current?.contentWindow) return;
208
1442
  if (!isTradeItEvent$1(event.data)) return;
1443
+ if (event.data.type === EmbedEventType$1.Authorization) {
1444
+ if (!isTradeItAuthorization$1(event.data.payload)) return;
1445
+ const authorization = event.data.payload;
1446
+ if (authorizationRef.current.code === authorization.code) return;
1447
+ const delivery = {
1448
+ code: authorization.code,
1449
+ pending: true,
1450
+ failed: false,
1451
+ closeRequested: false
1452
+ };
1453
+ authorizationRef.current = delivery;
1454
+ const frameWindow = iframeRef.current?.contentWindow;
1455
+ const reply = (success) => {
1456
+ if (authorizationRef.current !== delivery || iframeRef.current?.contentWindow !== frameWindow) return;
1457
+ delivery.pending = false;
1458
+ delivery.failed = !success;
1459
+ frameWindow?.postMessage({
1460
+ source: "tradeit",
1461
+ version: 1,
1462
+ type: EmbedEventType$1.AuthorizationResult,
1463
+ payload: {
1464
+ state: authorization.state,
1465
+ success
1466
+ }
1467
+ }, expectedOrigin);
1468
+ if (success && delivery.closeRequested) onOpenChange?.(false);
1469
+ };
1470
+ Promise.resolve().then(() => {
1471
+ if (!onAuthorization) throw new Error("Configure onAuthorization to save the user's OAuth grant.");
1472
+ return onAuthorization(authorization);
1473
+ }).then(() => reply(true), (error) => {
1474
+ reply(false);
1475
+ onError?.(error instanceof Error ? error : new Error("Could not save the OAuth grant."));
1476
+ });
1477
+ return;
1478
+ }
209
1479
  onEvent?.(event.data);
210
- if (event.data.type === "tradeit.error") onError?.(new Error(getTradeItErrorMessage$1(event.data)));
211
- if (event.data.type === "tradeit.close_requested" && closeOnCloseRequestedEvent) onOpenChange?.(false);
1480
+ if (event.data.type === EmbedEventType$1.Error) onError?.(new Error(getTradeItErrorMessage$1(event.data)));
1481
+ if (event.data.type === EmbedEventType$1.CloseRequested && closeOnCloseRequestedEvent) {
1482
+ if (authorizationRef.current.failed) return;
1483
+ if (authorizationRef.current.pending) {
1484
+ authorizationRef.current.closeRequested = true;
1485
+ return;
1486
+ }
1487
+ onOpenChange?.(false);
1488
+ }
212
1489
  };
213
1490
  window.addEventListener("message", handleMessage);
214
1491
  return () => window.removeEventListener("message", handleMessage);
@@ -216,6 +1493,7 @@ function TradeItModal(props) {
216
1493
  open,
217
1494
  resolved.url,
218
1495
  onEvent,
1496
+ onAuthorization,
219
1497
  onError,
220
1498
  closeOnCloseRequestedEvent,
221
1499
  onOpenChange
@@ -223,9 +1501,16 @@ function TradeItModal(props) {
223
1501
  if (!isMounted) return null;
224
1502
  if (!open && !keepMounted) return null;
225
1503
  if (!resolved.url) return null;
226
- const dialogStyle = isMobile ? DIALOG_MOBILE_STYLE : DIALOG_DESKTOP_STYLE;
1504
+ const isConnectFlow = props.launch.mode === "connect";
1505
+ let dialogStyle = DIALOG_DESKTOP_STYLE;
1506
+ if (isMobile) dialogStyle = DIALOG_MOBILE_STYLE;
1507
+ else if (isConnectFlow) dialogStyle = CONNECT_DIALOG_DESKTOP_STYLE;
1508
+ let overlayPadding = 12;
1509
+ if (isMobile) overlayPadding = 0;
1510
+ else if (isConnectFlow) overlayPadding = "0 4px";
227
1511
  const overlayStyle = {
228
1512
  ...OVERLAY_STYLE,
1513
+ padding: overlayPadding,
229
1514
  zIndex
230
1515
  };
231
1516
  const dialogLabel = title ?? iframeTitle ?? "Trade It";
@@ -256,6 +1541,7 @@ function TradeItModal(props) {
256
1541
  }),
257
1542
  !iframeLoaded && /* @__PURE__ */ jsx(TradeItModalLoader, {}),
258
1543
  /* @__PURE__ */ jsx("iframe", {
1544
+ ref: iframeRef,
259
1545
  title: dialogLabel,
260
1546
  src: resolved.url,
261
1547
  style: IFRAME_STYLE,
@@ -384,4 +1670,4 @@ let TradeType = /* @__PURE__ */ function(TradeType$1) {
384
1670
  }({});
385
1671
 
386
1672
  //#endregion
387
- export { LegType, OrderDirection, OrderType, PositionEffect, TimeInForce, TradeAction, TradeItModal, TradeLinkParam, TradeType, TradeUnit, TriggerUnit, getTradeItErrorMessage, getUrlOrigin, isTradeItEvent, resolveLaunchUrl, useTradeIt };
1673
+ export { EmbedEventType, LegType, OrderDirection, OrderType, PositionEffect, TimeInForce, TradeAction, TradeItModal, TradeLinkParam, TradeType, TradeUnit, TriggerUnit, getTradeItErrorMessage, getUrlOrigin, isTradeItAuthorization, isTradeItEvent, resolveLaunchUrl, useTradeIt };