@tutti-os/workbench-surface 0.0.11 → 0.0.12

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
@@ -2643,6 +2643,14 @@ function resolveWorkbenchCaptureElement(windowElement) {
2643
2643
  '[data-workbench-window-capture="true"]'
2644
2644
  ) ?? windowElement.querySelector(".workbench-window") ?? windowElement;
2645
2645
  }
2646
+ function waitForNextAnimationFrame() {
2647
+ return new Promise((resolve) => {
2648
+ window.requestAnimationFrame(() => resolve());
2649
+ });
2650
+ }
2651
+ function isFocusedWorkbenchNode(controller, nodeID) {
2652
+ return controller.getSnapshot().nodeStack.at(-1) === nodeID;
2653
+ }
2646
2654
  function shouldReduceMotion() {
2647
2655
  return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
2648
2656
  }
@@ -3113,9 +3121,7 @@ function useWorkbenchGenieAnimation({
3113
3121
  showNodeForGenie(nodeID);
3114
3122
  return;
3115
3123
  }
3116
- await new Promise((resolve) => {
3117
- window.requestAnimationFrame(() => resolve());
3118
- });
3124
+ await waitForNextAnimationFrame();
3119
3125
  if (generation !== animationGenerationRef.current) {
3120
3126
  return;
3121
3127
  }
@@ -3218,6 +3224,16 @@ function useWorkbenchGenieAnimation({
3218
3224
  }
3219
3225
  const runMinimize = minimize ?? (() => controller.commands.minimizeNode(nodeID));
3220
3226
  if (shouldReduceMotion()) {
3227
+ const wasFocusedForCapture2 = isFocusedWorkbenchNode(
3228
+ controller,
3229
+ nodeID
3230
+ );
3231
+ if (!wasFocusedForCapture2) {
3232
+ flushSync(() => {
3233
+ controller.commands.focusNode(nodeID);
3234
+ });
3235
+ await waitForNextAnimationFrame();
3236
+ }
3221
3237
  await captureWorkbenchNodePreviewImageForNode(target, {
3222
3238
  captureNodePreviewImage,
3223
3239
  dockPreviewCache,
@@ -3239,6 +3255,16 @@ function useWorkbenchGenieAnimation({
3239
3255
  runMinimize();
3240
3256
  return;
3241
3257
  }
3258
+ const wasFocusedForCapture = isFocusedWorkbenchNode(controller, nodeID);
3259
+ if (!wasFocusedForCapture) {
3260
+ flushSync(() => {
3261
+ controller.commands.focusNode(nodeID);
3262
+ });
3263
+ await waitForNextAnimationFrame();
3264
+ if (generation !== animationGenerationRef.current) {
3265
+ return;
3266
+ }
3267
+ }
3242
3268
  const previewImageUrlPromise = Promise.resolve(
3243
3269
  captureNodePreviewImage?.(target) ?? null
3244
3270
  ).catch(() => null);
@@ -3288,9 +3314,7 @@ function useWorkbenchGenieAnimation({
3288
3314
  hideNodeForGenie(nodeID);
3289
3315
  runMinimize();
3290
3316
  });
3291
- await new Promise((resolve) => {
3292
- window.requestAnimationFrame(() => resolve());
3293
- });
3317
+ await waitForNextAnimationFrame();
3294
3318
  if (generation !== animationGenerationRef.current) {
3295
3319
  releaseMinimizedDockEnterAnimation(nodeID);
3296
3320
  return;