@mirror-physics/fractal-ui 0.2.0-next.33 → 0.2.0-next.35

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.cjs CHANGED
@@ -1175,12 +1175,16 @@ var import_jsx_runtime18 = require("react/jsx-runtime");
1175
1175
  function ContentSwitcher({ items, value, onValueChange, ariaLabel, fullWidth = false, className }) {
1176
1176
  const switcherRef = React10.useRef(null);
1177
1177
  const buttonRefs = React10.useRef([]);
1178
+ const indicatorMotionReadyRef = React10.useRef(false);
1178
1179
  const activeIndex = items.findIndex((item) => item.value === value);
1179
1180
  React10.useLayoutEffect(() => {
1180
1181
  const switcher = switcherRef.current;
1181
1182
  const activeButton = buttonRefs.current[activeIndex];
1183
+ let motionFrame = 0;
1182
1184
  if (!switcher || !activeButton) {
1183
1185
  switcher?.removeAttribute("data-indicator-ready");
1186
+ switcher?.removeAttribute("data-indicator-animate");
1187
+ indicatorMotionReadyRef.current = false;
1184
1188
  return;
1185
1189
  }
1186
1190
  const updateIndicator = () => {
@@ -1191,15 +1195,29 @@ function ContentSwitcher({ items, value, onValueChange, ariaLabel, fullWidth = f
1191
1195
  switcher.style.setProperty("--fractal-content-switcher-indicator-width", `${activeButtonRect.width}px`);
1192
1196
  switcher.style.setProperty("--fractal-content-switcher-indicator-height", `${activeButtonRect.height}px`);
1193
1197
  switcher.setAttribute("data-indicator-ready", "true");
1198
+ if (!indicatorMotionReadyRef.current && motionFrame === 0) {
1199
+ motionFrame = window.requestAnimationFrame(() => {
1200
+ indicatorMotionReadyRef.current = true;
1201
+ switcher.setAttribute("data-indicator-animate", "true");
1202
+ motionFrame = 0;
1203
+ });
1204
+ }
1194
1205
  };
1195
1206
  updateIndicator();
1196
- if (typeof ResizeObserver === "undefined") return;
1207
+ if (typeof ResizeObserver === "undefined") {
1208
+ return () => {
1209
+ if (motionFrame !== 0) window.cancelAnimationFrame(motionFrame);
1210
+ };
1211
+ }
1197
1212
  const resizeObserver = new ResizeObserver(updateIndicator);
1198
1213
  resizeObserver.observe(switcher);
1199
1214
  buttonRefs.current.forEach((button) => {
1200
1215
  if (button) resizeObserver.observe(button);
1201
1216
  });
1202
- return () => resizeObserver.disconnect();
1217
+ return () => {
1218
+ resizeObserver.disconnect();
1219
+ if (motionFrame !== 0) window.cancelAnimationFrame(motionFrame);
1220
+ };
1203
1221
  }, [activeIndex, items.length]);
1204
1222
  const moveFocus = (index, direction) => {
1205
1223
  let nextIndex = index;