@warp-ds/elements 2.0.1 → 2.0.2-next.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.
@@ -645,13 +645,13 @@ var require_moo = __commonJS({
645
645
  line: this.line,
646
646
  col: this.col
647
647
  };
648
- var size2 = text.length;
649
- this.index += size2;
648
+ var size3 = text.length;
649
+ this.index += size3;
650
650
  this.line += lineBreaks;
651
651
  if (lineBreaks !== 0) {
652
- this.col = size2 - nl + 1;
652
+ this.col = size3 - nl + 1;
653
653
  } else {
654
- this.col += size2;
654
+ this.col += size3;
655
655
  }
656
656
  if (group.shouldThrow) {
657
657
  var err = new Error(this.formatError(token, "invalid syntax"));
@@ -2004,6 +2004,151 @@ var offset = function(options) {
2004
2004
  }
2005
2005
  };
2006
2006
  };
2007
+ var shift = function(options) {
2008
+ if (options === void 0) {
2009
+ options = {};
2010
+ }
2011
+ return {
2012
+ name: "shift",
2013
+ options,
2014
+ async fn(state) {
2015
+ const {
2016
+ x,
2017
+ y,
2018
+ placement
2019
+ } = state;
2020
+ const _a = evaluate(options, state), {
2021
+ mainAxis: checkMainAxis = true,
2022
+ crossAxis: checkCrossAxis = false,
2023
+ limiter = {
2024
+ fn: (_ref) => {
2025
+ let {
2026
+ x: x2,
2027
+ y: y2
2028
+ } = _ref;
2029
+ return {
2030
+ x: x2,
2031
+ y: y2
2032
+ };
2033
+ }
2034
+ }
2035
+ } = _a, detectOverflowOptions = __objRest(_a, [
2036
+ "mainAxis",
2037
+ "crossAxis",
2038
+ "limiter"
2039
+ ]);
2040
+ const coords = {
2041
+ x,
2042
+ y
2043
+ };
2044
+ const overflow = await detectOverflow(state, detectOverflowOptions);
2045
+ const crossAxis = getSideAxis(getSide(placement));
2046
+ const mainAxis = getOppositeAxis(crossAxis);
2047
+ let mainAxisCoord = coords[mainAxis];
2048
+ let crossAxisCoord = coords[crossAxis];
2049
+ if (checkMainAxis) {
2050
+ const minSide = mainAxis === "y" ? "top" : "left";
2051
+ const maxSide = mainAxis === "y" ? "bottom" : "right";
2052
+ const min2 = mainAxisCoord + overflow[minSide];
2053
+ const max2 = mainAxisCoord - overflow[maxSide];
2054
+ mainAxisCoord = clamp(min2, mainAxisCoord, max2);
2055
+ }
2056
+ if (checkCrossAxis) {
2057
+ const minSide = crossAxis === "y" ? "top" : "left";
2058
+ const maxSide = crossAxis === "y" ? "bottom" : "right";
2059
+ const min2 = crossAxisCoord + overflow[minSide];
2060
+ const max2 = crossAxisCoord - overflow[maxSide];
2061
+ crossAxisCoord = clamp(min2, crossAxisCoord, max2);
2062
+ }
2063
+ const limitedCoords = limiter.fn(__spreadProps(__spreadValues({}, state), {
2064
+ [mainAxis]: mainAxisCoord,
2065
+ [crossAxis]: crossAxisCoord
2066
+ }));
2067
+ return __spreadProps(__spreadValues({}, limitedCoords), {
2068
+ data: {
2069
+ x: limitedCoords.x - x,
2070
+ y: limitedCoords.y - y
2071
+ }
2072
+ });
2073
+ }
2074
+ };
2075
+ };
2076
+ var size = function(options) {
2077
+ if (options === void 0) {
2078
+ options = {};
2079
+ }
2080
+ return {
2081
+ name: "size",
2082
+ options,
2083
+ async fn(state) {
2084
+ const {
2085
+ placement,
2086
+ rects,
2087
+ platform: platform2,
2088
+ elements
2089
+ } = state;
2090
+ const _a = evaluate(options, state), {
2091
+ apply = () => {
2092
+ }
2093
+ } = _a, detectOverflowOptions = __objRest(_a, [
2094
+ "apply"
2095
+ ]);
2096
+ const overflow = await detectOverflow(state, detectOverflowOptions);
2097
+ const side2 = getSide(placement);
2098
+ const alignment = getAlignment(placement);
2099
+ const isYAxis = getSideAxis(placement) === "y";
2100
+ const {
2101
+ width,
2102
+ height
2103
+ } = rects.floating;
2104
+ let heightSide;
2105
+ let widthSide;
2106
+ if (side2 === "top" || side2 === "bottom") {
2107
+ heightSide = side2;
2108
+ widthSide = alignment === (await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating)) ? "start" : "end") ? "left" : "right";
2109
+ } else {
2110
+ widthSide = side2;
2111
+ heightSide = alignment === "end" ? "top" : "bottom";
2112
+ }
2113
+ const maximumClippingHeight = height - overflow.top - overflow.bottom;
2114
+ const maximumClippingWidth = width - overflow.left - overflow.right;
2115
+ const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
2116
+ const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
2117
+ const noShift = !state.middlewareData.shift;
2118
+ let availableHeight = overflowAvailableHeight;
2119
+ let availableWidth = overflowAvailableWidth;
2120
+ if (isYAxis) {
2121
+ availableWidth = alignment || noShift ? min(overflowAvailableWidth, maximumClippingWidth) : maximumClippingWidth;
2122
+ } else {
2123
+ availableHeight = alignment || noShift ? min(overflowAvailableHeight, maximumClippingHeight) : maximumClippingHeight;
2124
+ }
2125
+ if (noShift && !alignment) {
2126
+ const xMin = max(overflow.left, 0);
2127
+ const xMax = max(overflow.right, 0);
2128
+ const yMin = max(overflow.top, 0);
2129
+ const yMax = max(overflow.bottom, 0);
2130
+ if (isYAxis) {
2131
+ availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
2132
+ } else {
2133
+ availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
2134
+ }
2135
+ }
2136
+ await apply(__spreadProps(__spreadValues({}, state), {
2137
+ availableWidth,
2138
+ availableHeight
2139
+ }));
2140
+ const nextDimensions = await platform2.getDimensions(elements.floating);
2141
+ if (width !== nextDimensions.width || height !== nextDimensions.height) {
2142
+ return {
2143
+ reset: {
2144
+ rects: true
2145
+ }
2146
+ };
2147
+ }
2148
+ return {};
2149
+ }
2150
+ };
2151
+ };
2007
2152
 
2008
2153
  // node_modules/.pnpm/@floating-ui+utils@0.2.7/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs
2009
2154
  function getNodeName(node) {
@@ -2541,7 +2686,9 @@ var platform = {
2541
2686
  isRTL
2542
2687
  };
2543
2688
  var offset2 = offset;
2689
+ var shift2 = shift;
2544
2690
  var flip2 = flip;
2691
+ var size2 = size;
2545
2692
  var hide2 = hide;
2546
2693
  var arrow2 = arrow;
2547
2694
  var computePosition2 = (reference, floating, options) => {
@@ -2557,7 +2704,7 @@ var computePosition2 = (reference, floating, options) => {
2557
2704
  }));
2558
2705
  };
2559
2706
 
2560
- // node_modules/.pnpm/@warp-ds+core@1.1.5_@floating-ui+dom@1.6.10/node_modules/@warp-ds/core/dist/attention/utils/helpers.js
2707
+ // node_modules/.pnpm/@warp-ds+core@1.1.7_@floating-ui+dom@1.6.10/node_modules/@warp-ds/core/dist/attention/utils/helpers.js
2561
2708
  var TOP_START = "top-start";
2562
2709
  var TOP = "top";
2563
2710
  var TOP_END = "top-end";
@@ -2634,6 +2781,8 @@ var applyArrowStyles = (arrowEl, arrowRotation2, dir) => {
2634
2781
  transform: `rotate(${arrowRotation2}deg)`
2635
2782
  });
2636
2783
  };
2784
+ var ELEMENT_PADDING = 8;
2785
+ var ARROW_OFFSET = 24;
2637
2786
  async function useRecompute(state) {
2638
2787
  var _a, _b, _c;
2639
2788
  if (!(state == null ? void 0 : state.isShowing))
@@ -2657,8 +2806,18 @@ async function useRecompute(state) {
2657
2806
  fallbackPlacements: state == null ? void 0 : state.fallbackPlacements
2658
2807
  }),
2659
2808
  !(state == null ? void 0 : state.noArrow) && (state == null ? void 0 : state.arrowEl) && arrow2({ element: state == null ? void 0 : state.arrowEl }),
2660
- hide2()
2809
+ (state == null ? void 0 : state.flip) && shift2({ crossAxis: true }),
2810
+ // shifts the attentionEl to make sure that it stays in view
2811
+ hide2(),
2661
2812
  // will hide the attentionEl when it appears detached from the targetEl. Can be called multiple times in the middleware-array if you want to use several strategies. Default strategy is 'referenceHidden'.
2813
+ size2({
2814
+ apply() {
2815
+ Object.assign(attentionEl.style, {
2816
+ paddingRight: `${ELEMENT_PADDING}px`,
2817
+ paddingLeft: `${ELEMENT_PADDING}px`
2818
+ });
2819
+ }
2820
+ })
2662
2821
  ]
2663
2822
  }).then(({ x, y, middlewareData, placement }) => {
2664
2823
  state.actualDirection = placement;
@@ -2674,29 +2833,30 @@ async function useRecompute(state) {
2674
2833
  visibility: referenceHidden ? "hidden" : ""
2675
2834
  });
2676
2835
  }
2677
- const isRtl = window.getComputedStyle(attentionEl).direction === "rtl";
2678
- const arrowPlacement = arrowDirection(placement).split("-")[1];
2679
2836
  if ((middlewareData == null ? void 0 : middlewareData.arrow) && (state == null ? void 0 : state.arrowEl)) {
2680
2837
  const arrowEl = state == null ? void 0 : state.arrowEl;
2681
2838
  const { x: arrowX, y: arrowY } = middlewareData.arrow;
2682
- let top = "";
2683
- let right = "";
2684
- let bottom = "";
2685
- let left = "";
2839
+ const isRtl = window.getComputedStyle(attentionEl).direction === "rtl";
2840
+ const arrowPlacement = arrowDirection(placement).split("-")[1];
2841
+ let top = "", right = "", bottom = "", left = "";
2686
2842
  if (arrowPlacement === "start") {
2687
- const value = typeof arrowX === "number" ? `calc(24px - ${arrowEl.offsetWidth / 2}px)` : "";
2688
- top = typeof arrowY === "number" ? `calc(24px - ${arrowEl.offsetWidth / 2}px)` : "";
2843
+ const value = typeof arrowX === "number" ? `calc(${ARROW_OFFSET}px - ${arrowEl.offsetWidth / 2}px)` : "";
2844
+ top = typeof arrowY === "number" ? `calc(${ARROW_OFFSET}px - ${arrowEl.offsetWidth / 2}px)` : "";
2689
2845
  right = isRtl ? value : "";
2690
2846
  left = isRtl ? "" : value;
2691
2847
  } else if (arrowPlacement === "end") {
2692
- const value = typeof arrowX === "number" ? `calc(24px - ${arrowEl.offsetWidth / 2}px)` : "";
2848
+ const value = typeof arrowX === "number" ? `calc(${ARROW_OFFSET}px - ${arrowEl.offsetWidth / 2}px)` : "";
2693
2849
  right = isRtl ? "" : value;
2694
2850
  left = isRtl ? value : "";
2695
- bottom = typeof arrowY === "number" ? `calc(24px - ${arrowEl.offsetWidth / 2}px)` : "";
2851
+ bottom = typeof arrowY === "number" ? `calc(${ARROW_OFFSET}px - ${arrowEl.offsetWidth / 2}px)` : "";
2696
2852
  } else {
2697
2853
  left = typeof arrowX === "number" ? `${arrowX}px` : "";
2698
2854
  top = typeof arrowY === "number" ? `${arrowY}px` : "";
2699
2855
  }
2856
+ const { x: shiftX } = middlewareData.shift || {};
2857
+ if (typeof shiftX === "number") {
2858
+ left = typeof arrowX === "number" ? `${arrowX - shiftX}px` : left;
2859
+ }
2700
2860
  Object.assign(arrowEl.style, {
2701
2861
  top,
2702
2862
  right,