@tonconnect/ui 2.2.0 → 2.3.0-beta.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/lib/index.cjs CHANGED
@@ -18,6 +18,18 @@ var __spreadValues = (a2, b) => {
18
18
  return a2;
19
19
  };
20
20
  var __spreadProps = (a2, b) => __defProps(a2, __getOwnPropDescs(b));
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
21
33
  var __publicField = (obj, key, value) => {
22
34
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
23
35
  return value;
@@ -1825,8 +1837,10 @@ function fixMobileSafariActiveTransition() {
1825
1837
  }
1826
1838
  }
1827
1839
  function defineStylesRoot() {
1828
- customElements.define(globalStylesTag, class TcRootElement extends HTMLElement {
1829
- });
1840
+ if (!customElements.get("tc-root")) {
1841
+ customElements.define(globalStylesTag, class TcRootElement extends HTMLElement {
1842
+ });
1843
+ }
1830
1844
  }
1831
1845
  function createMacrotask(callback) {
1832
1846
  return __async(this, null, function* () {
@@ -3034,6 +3048,7 @@ function useDataAttributes(props) {
3034
3048
  const Button = (props) => {
3035
3049
  const dataAttrs = useDataAttributes(props);
3036
3050
  return createComponent(ButtonStyled$1, mergeProps({
3051
+ type: "button",
3037
3052
  get appearance() {
3038
3053
  return props.appearance || "primary";
3039
3054
  },
@@ -4915,16 +4930,16 @@ var qrcode$1 = { exports: {} };
4915
4930
  };
4916
4931
  return _this;
4917
4932
  }();
4918
- function qrPolynomial(num, shift) {
4933
+ function qrPolynomial(num, shift2) {
4919
4934
  if (typeof num.length == "undefined") {
4920
- throw num.length + "/" + shift;
4935
+ throw num.length + "/" + shift2;
4921
4936
  }
4922
4937
  var _num = function() {
4923
4938
  var offset = 0;
4924
4939
  while (offset < num.length && num[offset] == 0) {
4925
4940
  offset += 1;
4926
4941
  }
4927
- var _num2 = new Array(num.length - offset + shift);
4942
+ var _num2 = new Array(num.length - offset + shift2);
4928
4943
  for (var i2 = 0; i2 < num.length - offset; i2 += 1) {
4929
4944
  _num2[i2] = num[i2 + offset];
4930
4945
  }
@@ -7465,6 +7480,22 @@ const computePosition$1 = (reference, floating, config) => __async(exports, null
7465
7480
  middlewareData
7466
7481
  };
7467
7482
  });
7483
+ function expandPaddingObject(padding) {
7484
+ return __spreadValues({
7485
+ top: 0,
7486
+ right: 0,
7487
+ bottom: 0,
7488
+ left: 0
7489
+ }, padding);
7490
+ }
7491
+ function getSideObjectFromPadding(padding) {
7492
+ return typeof padding !== "number" ? expandPaddingObject(padding) : {
7493
+ top: padding,
7494
+ right: padding,
7495
+ bottom: padding,
7496
+ left: padding
7497
+ };
7498
+ }
7468
7499
  function rectToClientRect(rect) {
7469
7500
  return __spreadProps(__spreadValues({}, rect), {
7470
7501
  top: rect.y,
@@ -7473,6 +7504,270 @@ function rectToClientRect(rect) {
7473
7504
  bottom: rect.y + rect.height
7474
7505
  });
7475
7506
  }
7507
+ function detectOverflow(middlewareArguments, options) {
7508
+ return __async(this, null, function* () {
7509
+ var _await$platform$isEle;
7510
+ if (options === void 0) {
7511
+ options = {};
7512
+ }
7513
+ const {
7514
+ x,
7515
+ y,
7516
+ platform: platform2,
7517
+ rects,
7518
+ elements,
7519
+ strategy
7520
+ } = middlewareArguments;
7521
+ const {
7522
+ boundary = "clippingAncestors",
7523
+ rootBoundary = "viewport",
7524
+ elementContext = "floating",
7525
+ altBoundary = false,
7526
+ padding = 0
7527
+ } = options;
7528
+ const paddingObject = getSideObjectFromPadding(padding);
7529
+ const altContext = elementContext === "floating" ? "reference" : "floating";
7530
+ const element = elements[altBoundary ? altContext : elementContext];
7531
+ const clippingClientRect = rectToClientRect(yield platform2.getClippingRect({
7532
+ element: ((_await$platform$isEle = yield platform2.isElement == null ? void 0 : platform2.isElement(element)) != null ? _await$platform$isEle : true) ? element : element.contextElement || (yield platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)),
7533
+ boundary,
7534
+ rootBoundary,
7535
+ strategy
7536
+ }));
7537
+ const rect = elementContext === "floating" ? __spreadProps(__spreadValues({}, rects.floating), {
7538
+ x,
7539
+ y
7540
+ }) : rects.reference;
7541
+ const offsetParent = yield platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating);
7542
+ const offsetScale = (yield platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? (yield platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
7543
+ x: 1,
7544
+ y: 1
7545
+ } : {
7546
+ x: 1,
7547
+ y: 1
7548
+ };
7549
+ const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? yield platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
7550
+ rect,
7551
+ offsetParent,
7552
+ strategy
7553
+ }) : rect);
7554
+ return {
7555
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
7556
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
7557
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
7558
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
7559
+ };
7560
+ });
7561
+ }
7562
+ const min$1 = Math.min;
7563
+ const max$1 = Math.max;
7564
+ function within(min$1$1, value, max$1$1) {
7565
+ return max$1(min$1$1, min$1(value, max$1$1));
7566
+ }
7567
+ const hash$1 = {
7568
+ left: "right",
7569
+ right: "left",
7570
+ bottom: "top",
7571
+ top: "bottom"
7572
+ };
7573
+ function getOppositePlacement(placement) {
7574
+ return placement.replace(/left|right|bottom|top/g, (matched) => hash$1[matched]);
7575
+ }
7576
+ function getAlignmentSides(placement, rects, rtl) {
7577
+ if (rtl === void 0) {
7578
+ rtl = false;
7579
+ }
7580
+ const alignment = getAlignment(placement);
7581
+ const mainAxis = getMainAxisFromPlacement(placement);
7582
+ const length = getLengthFromAxis(mainAxis);
7583
+ let mainAlignmentSide = mainAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
7584
+ if (rects.reference[length] > rects.floating[length]) {
7585
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
7586
+ }
7587
+ return {
7588
+ main: mainAlignmentSide,
7589
+ cross: getOppositePlacement(mainAlignmentSide)
7590
+ };
7591
+ }
7592
+ const hash = {
7593
+ start: "end",
7594
+ end: "start"
7595
+ };
7596
+ function getOppositeAlignmentPlacement(placement) {
7597
+ return placement.replace(/start|end/g, (matched) => hash[matched]);
7598
+ }
7599
+ function getExpandedPlacements(placement) {
7600
+ const oppositePlacement = getOppositePlacement(placement);
7601
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
7602
+ }
7603
+ const flip = function(options) {
7604
+ if (options === void 0) {
7605
+ options = {};
7606
+ }
7607
+ return {
7608
+ name: "flip",
7609
+ options,
7610
+ fn(middlewareArguments) {
7611
+ return __async(this, null, function* () {
7612
+ var _middlewareData$flip;
7613
+ const {
7614
+ placement,
7615
+ middlewareData,
7616
+ rects,
7617
+ initialPlacement,
7618
+ platform: platform2,
7619
+ elements
7620
+ } = middlewareArguments;
7621
+ const _a3 = options, {
7622
+ mainAxis: checkMainAxis = true,
7623
+ crossAxis: checkCrossAxis = true,
7624
+ fallbackPlacements: specifiedFallbackPlacements,
7625
+ fallbackStrategy = "bestFit",
7626
+ flipAlignment = true
7627
+ } = _a3, detectOverflowOptions = __objRest(_a3, [
7628
+ "mainAxis",
7629
+ "crossAxis",
7630
+ "fallbackPlacements",
7631
+ "fallbackStrategy",
7632
+ "flipAlignment"
7633
+ ]);
7634
+ const side = getSide(placement);
7635
+ const isBasePlacement = side === initialPlacement;
7636
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
7637
+ const placements = [initialPlacement, ...fallbackPlacements];
7638
+ const overflow = yield detectOverflow(middlewareArguments, detectOverflowOptions);
7639
+ const overflows = [];
7640
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
7641
+ if (checkMainAxis) {
7642
+ overflows.push(overflow[side]);
7643
+ }
7644
+ if (checkCrossAxis) {
7645
+ const {
7646
+ main,
7647
+ cross
7648
+ } = getAlignmentSides(placement, rects, yield platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
7649
+ overflows.push(overflow[main], overflow[cross]);
7650
+ }
7651
+ overflowsData = [...overflowsData, {
7652
+ placement,
7653
+ overflows
7654
+ }];
7655
+ if (!overflows.every((side2) => side2 <= 0)) {
7656
+ var _middlewareData$flip$, _middlewareData$flip2;
7657
+ const nextIndex = ((_middlewareData$flip$ = (_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) != null ? _middlewareData$flip$ : 0) + 1;
7658
+ const nextPlacement = placements[nextIndex];
7659
+ if (nextPlacement) {
7660
+ return {
7661
+ data: {
7662
+ index: nextIndex,
7663
+ overflows: overflowsData
7664
+ },
7665
+ reset: {
7666
+ placement: nextPlacement
7667
+ }
7668
+ };
7669
+ }
7670
+ let resetPlacement = "bottom";
7671
+ switch (fallbackStrategy) {
7672
+ case "bestFit": {
7673
+ var _overflowsData$map$so;
7674
+ const placement2 = (_overflowsData$map$so = overflowsData.map((d) => [d, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a2, b) => a2[1] - b[1])[0]) == null ? void 0 : _overflowsData$map$so[0].placement;
7675
+ if (placement2) {
7676
+ resetPlacement = placement2;
7677
+ }
7678
+ break;
7679
+ }
7680
+ case "initialPlacement":
7681
+ resetPlacement = initialPlacement;
7682
+ break;
7683
+ }
7684
+ if (placement !== resetPlacement) {
7685
+ return {
7686
+ reset: {
7687
+ placement: resetPlacement
7688
+ }
7689
+ };
7690
+ }
7691
+ }
7692
+ return {};
7693
+ });
7694
+ }
7695
+ };
7696
+ };
7697
+ function getCrossAxis(axis) {
7698
+ return axis === "x" ? "y" : "x";
7699
+ }
7700
+ const shift = function(options) {
7701
+ if (options === void 0) {
7702
+ options = {};
7703
+ }
7704
+ return {
7705
+ name: "shift",
7706
+ options,
7707
+ fn(middlewareArguments) {
7708
+ return __async(this, null, function* () {
7709
+ const {
7710
+ x,
7711
+ y,
7712
+ placement
7713
+ } = middlewareArguments;
7714
+ const _a3 = options, {
7715
+ mainAxis: checkMainAxis = true,
7716
+ crossAxis: checkCrossAxis = false,
7717
+ limiter = {
7718
+ fn: (_ref) => {
7719
+ let {
7720
+ x: x2,
7721
+ y: y2
7722
+ } = _ref;
7723
+ return {
7724
+ x: x2,
7725
+ y: y2
7726
+ };
7727
+ }
7728
+ }
7729
+ } = _a3, detectOverflowOptions = __objRest(_a3, [
7730
+ "mainAxis",
7731
+ "crossAxis",
7732
+ "limiter"
7733
+ ]);
7734
+ const coords = {
7735
+ x,
7736
+ y
7737
+ };
7738
+ const overflow = yield detectOverflow(middlewareArguments, detectOverflowOptions);
7739
+ const mainAxis = getMainAxisFromPlacement(getSide(placement));
7740
+ const crossAxis = getCrossAxis(mainAxis);
7741
+ let mainAxisCoord = coords[mainAxis];
7742
+ let crossAxisCoord = coords[crossAxis];
7743
+ if (checkMainAxis) {
7744
+ const minSide = mainAxis === "y" ? "top" : "left";
7745
+ const maxSide = mainAxis === "y" ? "bottom" : "right";
7746
+ const min2 = mainAxisCoord + overflow[minSide];
7747
+ const max2 = mainAxisCoord - overflow[maxSide];
7748
+ mainAxisCoord = within(min2, mainAxisCoord, max2);
7749
+ }
7750
+ if (checkCrossAxis) {
7751
+ const minSide = crossAxis === "y" ? "top" : "left";
7752
+ const maxSide = crossAxis === "y" ? "bottom" : "right";
7753
+ const min2 = crossAxisCoord + overflow[minSide];
7754
+ const max2 = crossAxisCoord - overflow[maxSide];
7755
+ crossAxisCoord = within(min2, crossAxisCoord, max2);
7756
+ }
7757
+ const limitedCoords = limiter.fn(__spreadProps(__spreadValues({}, middlewareArguments), {
7758
+ [mainAxis]: mainAxisCoord,
7759
+ [crossAxis]: crossAxisCoord
7760
+ }));
7761
+ return __spreadProps(__spreadValues({}, limitedCoords), {
7762
+ data: {
7763
+ x: limitedCoords.x - x,
7764
+ y: limitedCoords.y - y
7765
+ }
7766
+ });
7767
+ });
7768
+ }
7769
+ };
7770
+ };
7476
7771
  function getWindow(node) {
7477
7772
  var _node$ownerDocument;
7478
7773
  return ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
@@ -8055,7 +8350,8 @@ const AccountButton = () => {
8055
8350
  const [anchor, setAnchor] = createSignal();
8056
8351
  const position = P(anchor, floating, {
8057
8352
  whileElementsMounted: autoUpdate,
8058
- placement: "bottom-end"
8353
+ placement: "bottom-end",
8354
+ middleware: [flip(), shift()]
8059
8355
  });
8060
8356
  const normalizedAddress = () => {
8061
8357
  const acc = account();
@@ -12157,7 +12453,7 @@ class TonConnectUITracker {
12157
12453
  }
12158
12454
  }
12159
12455
  }
12160
- const tonConnectUiVersion = "2.2.0";
12456
+ const tonConnectUiVersion = "2.3.0-beta.0";
12161
12457
  class TonConnectUI {
12162
12458
  constructor(options) {
12163
12459
  __publicField(this, "walletInfoStorage", new WalletInfoStorage());
@@ -12393,6 +12689,7 @@ class TonConnectUI {
12393
12689
  });
12394
12690
  const abortController = new AbortController();
12395
12691
  const onRequestSent = () => {
12692
+ var _a2;
12396
12693
  if (abortController.signal.aborted) {
12397
12694
  return;
12398
12695
  }
@@ -12406,6 +12703,20 @@ class TonConnectUI {
12406
12703
  returnStrategy,
12407
12704
  twaReturnUrl
12408
12705
  });
12706
+ let firstClick = true;
12707
+ const redirectToWallet2 = () => {
12708
+ if (abortController.signal.aborted) {
12709
+ return;
12710
+ }
12711
+ const forceRedirect = !firstClick;
12712
+ firstClick = false;
12713
+ this.redirectAfterRequestSent({
12714
+ returnStrategy,
12715
+ twaReturnUrl,
12716
+ forceRedirect
12717
+ });
12718
+ };
12719
+ (_a2 = options == null ? void 0 : options.onRequestSent) == null ? void 0 : _a2.call(options, redirectToWallet2);
12409
12720
  };
12410
12721
  const unsubscribe = this.onTransactionModalStateChange((action2) => {
12411
12722
  if (action2 == null ? void 0 : action2.openModal) {
@@ -12453,7 +12764,7 @@ class TonConnectUI {
12453
12764
  }
12454
12765
  });
12455
12766
  }
12456
- signData(data) {
12767
+ signData(data, options) {
12457
12768
  return __async(this, null, function* () {
12458
12769
  this.tracker.trackDataSentForSignature(this.wallet, data);
12459
12770
  if (!this.connected) {
@@ -12472,6 +12783,7 @@ class TonConnectUI {
12472
12783
  });
12473
12784
  const abortController = new AbortController();
12474
12785
  const onRequestSent = () => {
12786
+ var _a2;
12475
12787
  if (abortController.signal.aborted) {
12476
12788
  return;
12477
12789
  }
@@ -12485,6 +12797,20 @@ class TonConnectUI {
12485
12797
  returnStrategy,
12486
12798
  twaReturnUrl
12487
12799
  });
12800
+ let firstClick = true;
12801
+ const redirectToWallet2 = () => {
12802
+ if (abortController.signal.aborted) {
12803
+ return;
12804
+ }
12805
+ const forceRedirect = !firstClick;
12806
+ firstClick = false;
12807
+ this.redirectAfterRequestSent({
12808
+ returnStrategy,
12809
+ twaReturnUrl,
12810
+ forceRedirect
12811
+ });
12812
+ };
12813
+ (_a2 = options == null ? void 0 : options.onRequestSent) == null ? void 0 : _a2.call(options, redirectToWallet2);
12488
12814
  };
12489
12815
  const unsubscribe = this.onTransactionModalStateChange((action2) => {
12490
12816
  if (action2 == null ? void 0 : action2.openModal) {
@@ -12534,14 +12860,15 @@ class TonConnectUI {
12534
12860
  }
12535
12861
  redirectAfterRequestSent({
12536
12862
  returnStrategy,
12537
- twaReturnUrl
12863
+ twaReturnUrl,
12864
+ forceRedirect
12538
12865
  }) {
12539
12866
  if (this.walletInfo && "universalLink" in this.walletInfo && (this.walletInfo.openMethod === "universal-link" || this.walletInfo.openMethod === "custom-deeplink")) {
12540
12867
  if (sdk.isTelegramUrl(this.walletInfo.universalLink)) {
12541
12868
  redirectToTelegram(this.walletInfo.universalLink, {
12542
12869
  returnStrategy,
12543
12870
  twaReturnUrl: twaReturnUrl || appState.twaReturnUrl,
12544
- forceRedirect: false
12871
+ forceRedirect: forceRedirect || false
12545
12872
  });
12546
12873
  } else {
12547
12874
  redirectToWallet(
@@ -12549,7 +12876,7 @@ class TonConnectUI {
12549
12876
  this.walletInfo.deepLink,
12550
12877
  {
12551
12878
  returnStrategy,
12552
- forceRedirect: false
12879
+ forceRedirect: forceRedirect || false
12553
12880
  },
12554
12881
  () => {
12555
12882
  }