@gustavolmo/react-window-manager 0.3.1 → 0.4.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.
Files changed (67) hide show
  1. package/dist/index.css +1 -1
  2. package/dist/index.css.map +1 -1
  3. package/dist/index.js +1290 -735
  4. package/dist/index.js.map +1 -1
  5. package/dist/window-manager/internal/features/cursor/cursor-move-listener.d.ts.map +1 -1
  6. package/dist/window-manager/internal/features/cursor/cursor-state.d.ts +1 -2
  7. package/dist/window-manager/internal/features/cursor/cursor-state.d.ts.map +1 -1
  8. package/dist/window-manager/internal/features/docking/docking-api.d.ts +0 -2
  9. package/dist/window-manager/internal/features/docking/docking-api.d.ts.map +1 -1
  10. package/dist/window-manager/internal/features/docking/docking-controls.d.ts +1 -1
  11. package/dist/window-manager/internal/features/docking/docking-controls.d.ts.map +1 -1
  12. package/dist/window-manager/internal/features/drag/drag-api.d.ts +5 -0
  13. package/dist/window-manager/internal/features/drag/drag-api.d.ts.map +1 -0
  14. package/dist/window-manager/internal/features/drag/drag-handle.d.ts.map +1 -1
  15. package/dist/window-manager/internal/features/focus/focus-api.d.ts +5 -0
  16. package/dist/window-manager/internal/features/focus/focus-api.d.ts.map +1 -0
  17. package/dist/window-manager/internal/features/grid/grid-orchestrator.d.ts +4 -0
  18. package/dist/window-manager/internal/features/grid/grid-orchestrator.d.ts.map +1 -0
  19. package/dist/window-manager/internal/features/resizing/resizing-api.d.ts +3 -4
  20. package/dist/window-manager/internal/features/resizing/resizing-api.d.ts.map +1 -1
  21. package/dist/window-manager/internal/features/resizing/resizing-controls.d.ts.map +1 -1
  22. package/dist/window-manager/internal/features/stack/stack-api.d.ts +0 -2
  23. package/dist/window-manager/internal/features/stack/stack-api.d.ts.map +1 -1
  24. package/dist/window-manager/internal/features/window-button.d.ts +5 -3
  25. package/dist/window-manager/internal/features/window-button.d.ts.map +1 -1
  26. package/dist/window-manager/internal/features/window-layout.d.ts +14 -2
  27. package/dist/window-manager/internal/features/window-layout.d.ts.map +1 -1
  28. package/dist/window-manager/internal/features/workspace/workspace-api.d.ts +15 -3
  29. package/dist/window-manager/internal/features/workspace/workspace-api.d.ts.map +1 -1
  30. package/dist/window-manager/internal/features/workspace/workspace-resize-listener.d.ts +2 -0
  31. package/dist/window-manager/internal/features/workspace/workspace-resize-listener.d.ts.map +1 -0
  32. package/dist/window-manager/internal/features/workspace/workspace-state.d.ts.map +1 -1
  33. package/dist/window-manager/internal/runtime/dock-resolver/dock-commands.d.ts +10 -0
  34. package/dist/window-manager/internal/runtime/dock-resolver/dock-commands.d.ts.map +1 -0
  35. package/dist/window-manager/internal/runtime/drag-resolver/drag-commands.d.ts +7 -0
  36. package/dist/window-manager/internal/runtime/drag-resolver/drag-commands.d.ts.map +1 -0
  37. package/dist/window-manager/internal/runtime/drag-resolver/drag-loop.d.ts +6 -0
  38. package/dist/window-manager/internal/runtime/drag-resolver/drag-loop.d.ts.map +1 -0
  39. package/dist/window-manager/internal/runtime/focus-resolver/focus-commands.d.ts +6 -0
  40. package/dist/window-manager/internal/runtime/focus-resolver/focus-commands.d.ts.map +1 -0
  41. package/dist/window-manager/internal/runtime/resize-resolver/resize-commands.d.ts +7 -0
  42. package/dist/window-manager/internal/runtime/resize-resolver/resize-commands.d.ts.map +1 -0
  43. package/dist/window-manager/internal/runtime/resize-resolver/resize-loop.d.ts +6 -0
  44. package/dist/window-manager/internal/runtime/resize-resolver/resize-loop.d.ts.map +1 -0
  45. package/dist/window-manager/internal/runtime/rwm-runtime.d.ts +67 -0
  46. package/dist/window-manager/internal/runtime/rwm-runtime.d.ts.map +1 -0
  47. package/dist/window-manager/internal/runtime/stack-resolver/stack-commands.d.ts +6 -0
  48. package/dist/window-manager/internal/runtime/stack-resolver/stack-commands.d.ts.map +1 -0
  49. package/dist/window-manager/internal/runtime/workspace-resolver/workspace-commands.d.ts +12 -0
  50. package/dist/window-manager/internal/runtime/workspace-resolver/workspace-commands.d.ts.map +1 -0
  51. package/dist/window-manager/model/window-types.d.ts +14 -22
  52. package/dist/window-manager/model/window-types.d.ts.map +1 -1
  53. package/dist/window-manager/model/workspace-types.d.ts +18 -6
  54. package/dist/window-manager/model/workspace-types.d.ts.map +1 -1
  55. package/dist/window-manager/registration/window-registry.d.ts +3 -0
  56. package/dist/window-manager/registration/window-registry.d.ts.map +1 -0
  57. package/dist/window-manager/registration/window-store-factory.d.ts +1 -4
  58. package/dist/window-manager/registration/window-store-factory.d.ts.map +1 -1
  59. package/dist/window-manager/rwm.d.ts +25 -10
  60. package/dist/window-manager/rwm.d.ts.map +1 -1
  61. package/dist/window-manager/workspace-layout.d.ts +1 -13
  62. package/dist/window-manager/workspace-layout.d.ts.map +1 -1
  63. package/package.json +5 -4
  64. package/dist/window-manager/internal/features/grid/grid-api.d.ts +0 -4
  65. package/dist/window-manager/internal/features/grid/grid-api.d.ts.map +0 -1
  66. package/dist/window-manager/internal/features/view-port/view-port-resize-listener.d.ts +0 -2
  67. package/dist/window-manager/internal/features/view-port/view-port-resize-listener.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,104 +1,357 @@
1
- // src/window-manager/registration/window-store-factory.tsx
2
- import { create as create3 } from "zustand";
1
+ // src/window-manager/registration/window-registry.ts
2
+ var windowRegistry = {};
3
3
 
4
- // src/window-manager/internal/features/window-layout.tsx
5
- import { useEffect as useEffect3, useRef } from "react";
4
+ // src/window-manager/internal/features/workspace/workspace-state.ts
5
+ import { create } from "zustand";
6
+ var useWorkspaceState = create((set, get) => ({
7
+ wsElement: null,
8
+ setWsElement: (el) => set({ wsElement: el }),
9
+ isGridEnabled: true,
10
+ isDockPannelEnabled: true,
11
+ responsiveBreak: "sm",
12
+ isBelowBreakPoint: false,
13
+ activeWindowId: "react-dynamic-window-instance0",
14
+ wsRect: {
15
+ top: 0,
16
+ left: 0,
17
+ innerHeight: 0,
18
+ innerWidth: 0,
19
+ bottom: 0,
20
+ right: 0,
21
+ centerX: 0,
22
+ centerY: 0
23
+ }
24
+ }));
6
25
 
7
- // src/window-manager/internal/assets/svg-win-icons.tsx
8
- import { jsx } from "react/jsx-runtime";
9
- function IconWinMaximize({ color }) {
10
- return /* @__PURE__ */ jsx(
11
- "svg",
12
- {
13
- xmlns: "http://www.w3.org/2000/svg",
14
- fill: "none",
15
- viewBox: "0 0 24 24",
16
- width: 24,
17
- height: 24,
18
- strokeWidth: 1.5,
19
- stroke: color ? color : "#cccccc",
20
- color: color ? color : "#cccccc",
21
- className: "size-6",
22
- children: /* @__PURE__ */ jsx(
23
- "path",
24
- {
25
- strokeLinecap: "round",
26
- strokeLinejoin: "round",
27
- d: "M5.25 7.5A2.25 2.25 0 0 1 7.5 5.25h9a2.25 2.25 0 0 1 2.25 2.25v9a2.25 2.25 0 0 1-2.25 2.25h-9a2.25 2.25 0 0 1-2.25-2.25v-9Z"
26
+ // src/window-manager/internal/runtime/dock-resolver/dock-commands.ts
27
+ var dockCommandResolver = {
28
+ DOCK_WINDOW_RIGHT: (targetWinId, wsRect) => {
29
+ return [
30
+ {
31
+ winId: targetWinId,
32
+ patch: {
33
+ winCoord: { pointX: wsRect.centerX, pointY: wsRect.top },
34
+ winWidth: wsRect.innerWidth / 2,
35
+ winHeight: wsRect.innerHeight,
36
+ winVisualState: "demaximized",
37
+ isDragging: false
28
38
  }
29
- )
30
- }
31
- );
32
- }
33
- function IconWinDemaximize({ color }) {
34
- return /* @__PURE__ */ jsx(
35
- "svg",
36
- {
37
- xmlns: "http://www.w3.org/2000/svg",
38
- fill: "none",
39
- viewBox: "0 0 24 24",
40
- width: 24,
41
- height: 24,
42
- strokeWidth: 1.5,
43
- stroke: color ? color : "#cccccc",
44
- color: color ? color : "#cccccc",
45
- className: "size-6",
46
- children: /* @__PURE__ */ jsx(
47
- "path",
48
- {
49
- strokeLinecap: "round",
50
- strokeLinejoin: "round",
51
- d: "M16.5 8.25V6a2.25 2.25 0 0 0-2.25-2.25H6A2.25 2.25 0 0 0 3.75 6v8.25A2.25 2.25 0 0 0 6 16.5h2.25m8.25-8.25H18a2.25 2.25 0 0 1 2.25 2.25V18A2.25 2.25 0 0 1 18 20.25h-7.5A2.25 2.25 0 0 1 8.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 0 0-2.25 2.25v6"
39
+ }
40
+ ];
41
+ },
42
+ DOCK_WINDOW_LEFT: (targetWinId, wsRect) => {
43
+ return [
44
+ {
45
+ winId: targetWinId,
46
+ patch: {
47
+ winCoord: { pointX: wsRect.left, pointY: wsRect.top },
48
+ winWidth: wsRect.innerWidth / 2,
49
+ winHeight: wsRect.innerHeight,
50
+ winVisualState: "demaximized",
51
+ isDragging: false
52
52
  }
53
- )
54
- }
55
- );
56
- }
57
- function IconWinMinimize({ color }) {
58
- return /* @__PURE__ */ jsx(
59
- "svg",
60
- {
61
- xmlns: "http://www.w3.org/2000/svg",
62
- fill: "none",
63
- viewBox: "0 0 24 24",
64
- width: 24,
65
- height: 24,
66
- strokeWidth: 1.5,
67
- stroke: color ? color : "#cccccc",
68
- color: color ? color : "#cccccc",
69
- className: "size-6",
70
- children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18 18 6M6 6l12 12" })
71
- }
72
- );
73
- }
53
+ }
54
+ ];
55
+ },
56
+ DOCK_WINDOW_TOP: (targetWinId, wsRect) => {
57
+ return [
58
+ {
59
+ winId: targetWinId,
60
+ patch: {
61
+ winCoord: { pointX: wsRect.left, pointY: wsRect.top },
62
+ winWidth: wsRect.innerWidth,
63
+ winHeight: wsRect.innerHeight / 2,
64
+ winVisualState: "demaximized",
65
+ isDragging: false
66
+ }
67
+ }
68
+ ];
69
+ },
70
+ DOCK_WINDOW_BOTTOM: (targetWinId, wsRect) => {
71
+ return [
72
+ {
73
+ winId: targetWinId,
74
+ patch: {
75
+ winCoord: { pointX: wsRect.left, pointY: wsRect.centerY },
76
+ winWidth: wsRect.innerWidth,
77
+ winHeight: wsRect.innerHeight / 2,
78
+ winVisualState: "demaximized",
79
+ isDragging: false
80
+ }
81
+ }
82
+ ];
83
+ },
84
+ DOCK_WINDOW_BOTTOM_RIGHT: (targetWinId, wsRect) => {
85
+ return [
86
+ {
87
+ winId: targetWinId,
88
+ patch: {
89
+ winCoord: {
90
+ pointX: wsRect.centerX,
91
+ pointY: wsRect.centerY
92
+ },
93
+ winWidth: wsRect.innerWidth / 2,
94
+ winHeight: wsRect.innerHeight / 2,
95
+ winVisualState: "demaximized",
96
+ isDragging: false
97
+ }
98
+ }
99
+ ];
100
+ },
101
+ DOCK_WINDOW_TOP_RIGHT: (targetWinId, wsRect) => {
102
+ return [
103
+ {
104
+ winId: targetWinId,
105
+ patch: {
106
+ winCoord: { pointX: wsRect.centerX, pointY: wsRect.top },
107
+ winWidth: wsRect.innerWidth / 2,
108
+ winHeight: wsRect.innerHeight / 2,
109
+ winVisualState: "demaximized",
110
+ isDragging: false
111
+ }
112
+ }
113
+ ];
114
+ },
115
+ DOCK_WINDOW_BOTTOM_LEFT: (targetWinId, wsRect) => {
116
+ return [
117
+ {
118
+ winId: targetWinId,
119
+ patch: {
120
+ winCoord: { pointX: wsRect.left, pointY: wsRect.centerY },
121
+ winWidth: wsRect.innerWidth / 2,
122
+ winHeight: wsRect.innerHeight / 2,
123
+ winVisualState: "demaximized",
124
+ isDragging: false
125
+ }
126
+ }
127
+ ];
128
+ },
129
+ DOCK_WINDOW_TOP_LEFT: (targetWinId, wsRect) => {
130
+ return [
131
+ {
132
+ winId: targetWinId,
133
+ patch: {
134
+ winCoord: { pointX: wsRect.left, pointY: wsRect.top },
135
+ winWidth: wsRect.innerWidth / 2,
136
+ winHeight: wsRect.innerHeight / 2,
137
+ winVisualState: "demaximized",
138
+ isDragging: false
139
+ }
140
+ }
141
+ ];
142
+ },
143
+ MAXIMIZE_WINDOW: (targetWinId, wsRect) => {
144
+ return [
145
+ {
146
+ winId: targetWinId,
147
+ patch: {
148
+ winCoord: { pointX: wsRect.left, pointY: wsRect.top },
149
+ winHeight: wsRect.innerHeight,
150
+ winWidth: wsRect.innerWidth,
151
+ winVisualState: "maximized",
152
+ isDragging: false
153
+ }
154
+ }
155
+ ];
156
+ },
157
+ DEMAXIMIZE_WINDOW: (targetWinId, wsRect) => {
158
+ return [
159
+ {
160
+ winId: targetWinId,
161
+ patch: {
162
+ winCoord: { pointX: wsRect.left + 16, pointY: wsRect.top + 16 },
163
+ winWidth: wsRect.innerWidth * 0.95,
164
+ winHeight: wsRect.innerHeight * 0.75,
165
+ winVisualState: "demaximized",
166
+ isDragging: false
167
+ }
168
+ }
169
+ ];
170
+ }
171
+ };
172
+ var getDockDependencies = () => {
173
+ const { wsRect } = useWorkspaceState.getState();
174
+ return { wsRect };
175
+ };
74
176
 
75
177
  // src/window-manager/internal/features/cursor/cursor-state.ts
76
- import { create } from "zustand";
77
- var useCursorState = create((set) => ({
178
+ import { create as create2 } from "zustand";
179
+ var useCursorState = create2((set) => ({
78
180
  x: 10,
79
181
  y: 10,
80
- setX: (newX) => set({ x: newX }),
81
- setY: (newY) => set({ y: newY })
182
+ setXY: (x, y) => set({ x, y })
82
183
  }));
83
184
 
84
- // src/window-manager/internal/features/resizing/resizing-controls.tsx
85
- import { useEffect } from "react";
185
+ // src/window-manager/internal/runtime/drag-resolver/drag-loop.ts
186
+ var rafDragLoopResolver = {
187
+ LOOP_DRAG: (targetWinId, commit) => {
188
+ const { x, y } = useCursorState.getState();
189
+ const { winCoord, isDragging, windowId } = windowRegistry[targetWinId].getState();
190
+ if (!isDragging)
191
+ throw new Error(`INIT_DRAG_LOOP called with isDragging false for winId: ${windowId}`);
192
+ const pointerOffset = {
193
+ left: x - winCoord.pointX,
194
+ top: y - winCoord.pointY
195
+ };
196
+ requestAnimationFrame(() => dragLoop(targetWinId, pointerOffset, commit));
197
+ }
198
+ };
199
+ var dragLoop = (targetWinId, pointerOffset, commit) => {
200
+ const { winCoord, isDragging } = windowRegistry[targetWinId].getState();
201
+ const { wsRect } = useWorkspaceState.getState();
202
+ const { x, y } = useCursorState.getState();
203
+ if (!isDragging)
204
+ return;
205
+ let adjustedX = x - pointerOffset.left;
206
+ if (x > wsRect.right || x < wsRect.left)
207
+ adjustedX = winCoord.pointX;
208
+ let adjustedY = y - pointerOffset.top;
209
+ if (y > wsRect.bottom || y < wsRect.top)
210
+ adjustedY = winCoord.pointY;
211
+ if (adjustedX !== winCoord.pointX || adjustedY !== winCoord.pointY) {
212
+ commit([
213
+ {
214
+ winId: targetWinId,
215
+ patch: { winCoord: { pointX: adjustedX, pointY: adjustedY } }
216
+ }
217
+ ]);
218
+ }
219
+ requestAnimationFrame(() => dragLoop(targetWinId, pointerOffset, commit));
220
+ };
86
221
 
87
- // src/window-manager/internal/features/workspace/workspace-state.ts
88
- import { create as create2 } from "zustand";
89
- var useWorkspaceState = create2((set) => ({
90
- ref: null,
91
- setRef: (newRef) => set({ ref: newRef }),
92
- activeWindowId: "react-dynamic-window-instance0",
93
- setActiveWindowId: (newId) => set({ activeWindowId: newId }),
94
- responsiveBreak: "sm",
95
- setResponsiveBreak: (breakPoint) => set({ responsiveBreak: breakPoint })
96
- }));
222
+ // src/window-manager/internal/runtime/drag-resolver/drag-commands.ts
223
+ var dragCommandResolver = {
224
+ ENABLE_DRAG: (targetWinId) => {
225
+ const { wsRect } = useWorkspaceState.getState();
226
+ const { winVisualState } = windowRegistry[targetWinId].getState();
227
+ const patch = winVisualState === "maximized" ? {
228
+ winCoord: { pointX: wsRect.left + 16, pointY: wsRect.top + 4 },
229
+ winWidth: wsRect.innerWidth * 0.95,
230
+ winHeight: wsRect.innerHeight * 0.75,
231
+ winVisualState: "demaximized",
232
+ isDragging: true
233
+ } : { isDragging: true };
234
+ return [
235
+ {
236
+ winId: targetWinId,
237
+ patch
238
+ }
239
+ ];
240
+ },
241
+ DISABLE_DRAG: (targetWinId) => {
242
+ return [
243
+ {
244
+ winId: targetWinId,
245
+ patch: {
246
+ isDragging: false
247
+ }
248
+ }
249
+ ];
250
+ }
251
+ };
252
+ var isDragAllowed = () => {
253
+ return !useWorkspaceState.getState().isBelowBreakPoint;
254
+ };
97
255
 
98
- // src/window-manager/internal/features/workspace/workspace-api.ts
99
- var wsApi = {
100
- getRect: () => {
101
- const rect = useWorkspaceState.getState().ref?.getBoundingClientRect();
256
+ // src/window-manager/internal/runtime/focus-resolver/focus-commands.ts
257
+ var focusCommandResolver = {
258
+ FOCUS_WINDOW: (targetWinId) => {
259
+ const targetWin = windowRegistry[targetWinId].getState();
260
+ if (targetWin.isActive && !targetWin.isWindowClosed)
261
+ return { win: [], ws: {} };
262
+ const newStackOrderUpdate = [];
263
+ const workspaceUpdate = { activeWindowId: targetWinId };
264
+ for (const key of Object.keys(windowRegistry)) {
265
+ const otherWin = windowRegistry[key].getState();
266
+ if (otherWin.windowId === targetWin.windowId)
267
+ continue;
268
+ const adjustedIndex = otherWin.zIndex >= targetWin.zIndex ? otherWin.zIndex - 1 : otherWin.zIndex;
269
+ newStackOrderUpdate.push({
270
+ winId: otherWin.windowId,
271
+ patch: {
272
+ isActive: false,
273
+ zIndex: adjustedIndex
274
+ }
275
+ });
276
+ }
277
+ newStackOrderUpdate.push({
278
+ winId: targetWin.windowId,
279
+ patch: {
280
+ isWindowClosed: false,
281
+ isActive: true,
282
+ zIndex: newStackOrderUpdate.length + 1
283
+ }
284
+ });
285
+ return {
286
+ win: newStackOrderUpdate,
287
+ ws: workspaceUpdate
288
+ };
289
+ },
290
+ CLOSE_WINDOW_AND_REFOCUS: (targetWinId) => {
291
+ const isTargetWinClosed = windowRegistry[targetWinId].getState().isWindowClosed;
292
+ if (isTargetWinClosed)
293
+ return { win: [], ws: {} };
294
+ let prevIndex = 0;
295
+ let highestIndexWinId = void 0;
296
+ for (const key of Object.keys(windowRegistry)) {
297
+ const { zIndex, windowId, isWindowClosed } = windowRegistry[key].getState();
298
+ if (windowId === targetWinId)
299
+ continue;
300
+ if (isWindowClosed)
301
+ continue;
302
+ if (zIndex > prevIndex) {
303
+ prevIndex = zIndex;
304
+ highestIndexWinId = windowId;
305
+ }
306
+ }
307
+ return !highestIndexWinId ? {
308
+ ws: {},
309
+ win: [
310
+ {
311
+ winId: targetWinId,
312
+ patch: { isActive: false, isWindowClosed: true }
313
+ }
314
+ ]
315
+ } : {
316
+ ws: { activeWindowId: highestIndexWinId },
317
+ win: [
318
+ {
319
+ winId: highestIndexWinId,
320
+ patch: { isActive: true }
321
+ },
322
+ {
323
+ winId: targetWinId,
324
+ patch: { isActive: false, isWindowClosed: true }
325
+ }
326
+ ]
327
+ };
328
+ }
329
+ };
330
+
331
+ // src/window-manager/internal/runtime/stack-resolver/stack-commands.ts
332
+ var stackCommandResolver = {
333
+ RESET_STACK: () => {
334
+ const batchUpdate = [];
335
+ for (const key of Object.keys(windowRegistry)) {
336
+ const { resetFlag } = windowRegistry[key].getState();
337
+ batchUpdate.push({
338
+ winId: key,
339
+ patch: {
340
+ resetFlag: !resetFlag,
341
+ // FIND ME: reset flag is anti-pattern
342
+ isWindowClosed: true,
343
+ isActive: false
344
+ }
345
+ });
346
+ }
347
+ return batchUpdate;
348
+ }
349
+ };
350
+
351
+ // src/window-manager/internal/runtime/workspace-resolver/workspace-commands.ts
352
+ var workspaceCommandResolver = {
353
+ UPDATE_WORKSPACE_RECT: () => {
354
+ const rect = useWorkspaceState.getState().wsElement?.getBoundingClientRect();
102
355
  const top = rect?.top ?? 0;
103
356
  const left = rect?.left ?? 0;
104
357
  const innerHeight = rect?.height ?? 0;
@@ -107,22 +360,36 @@ var wsApi = {
107
360
  const right = left + innerWidth;
108
361
  const centerX = left + innerWidth / 2;
109
362
  const centerY = top + innerHeight / 2;
110
- const wsWindow = {
111
- top,
112
- left,
113
- innerHeight,
114
- innerWidth,
115
- bottom,
116
- right,
117
- centerX,
118
- centerY
363
+ const breakPoint = useWorkspaceState.getState().responsiveBreak;
364
+ const isBelowBreakPoint = innerWidth < responsiveBreakInPx(breakPoint);
365
+ return {
366
+ isBelowBreakPoint,
367
+ wsRect: {
368
+ top,
369
+ left,
370
+ innerHeight,
371
+ innerWidth,
372
+ bottom,
373
+ right,
374
+ centerX,
375
+ centerY
376
+ }
119
377
  };
120
- return wsWindow;
121
378
  },
122
- isBelowBreakPoint: () => {
123
- const wsRect = wsApi.getRect();
124
- const breakPoint = useWorkspaceState.getState().responsiveBreak;
125
- return wsRect.innerWidth < responsiveBreakInPx(breakPoint);
379
+ SET_WORKSPACE_FEATURES: (_, ctx) => {
380
+ if (ctx?.isGridEnabled === void 0 || ctx?.isDockPannelEnabled === void 0)
381
+ throw new Error(`SET_WORKSPACE_FEATURES called without a ctx value`);
382
+ return {
383
+ isGridEnabled: ctx.isGridEnabled,
384
+ isDockPannelEnabled: ctx.isDockPannelEnabled
385
+ };
386
+ },
387
+ SET_RESPONSIVE_BREAK: (_, ctx) => {
388
+ if (ctx?.responsiveBreak === void 0 || ctx?.responsiveBreak === null)
389
+ throw new Error(`SET_RESPONSIVE_BREAK called without a ctx value`);
390
+ return {
391
+ responsiveBreak: ctx.responsiveBreak
392
+ };
126
393
  }
127
394
  };
128
395
  var responsiveBreakInPx = (breakPoint) => {
@@ -144,341 +411,948 @@ var responsiveBreakInPx = (breakPoint) => {
144
411
  }
145
412
  };
146
413
 
147
- // src/window-manager/internal/features/resizing/resizing-api.ts
148
- var resizeApi = {
149
- stopAllDragAndResize: () => {
150
- for (const key of Object.keys(windowRegistry)) {
151
- windowRegistry[key].getState().isDragging = false;
152
- windowRegistry[key].getState().resizeAction = false;
153
- }
154
- },
155
- setResizeAction: (winId, action) => {
156
- windowRegistry[winId].setState({ resizeAction: action });
414
+ // src/window-manager/internal/runtime/resize-resolver/resize-commands.ts
415
+ var resizeCommandResolver = {
416
+ ENABLE_RESIZE: (targetWinId, direction) => {
417
+ const currentResizeAction = windowRegistry[targetWinId].getState().resizeAction;
418
+ if (currentResizeAction)
419
+ throw new Error(`ENABLE_RESIZE called on a window that is already risizing`);
420
+ return [
421
+ {
422
+ winId: targetWinId,
423
+ patch: {
424
+ resizeAction: direction,
425
+ winVisualState: "demaximized"
426
+ }
427
+ }
428
+ ];
157
429
  },
158
- dispatchResizeAction: (winId) => {
159
- const ctx = getDependencies(winId);
160
- if (!ctx.win.resizeAction)
161
- return;
162
- ctx.win.setWinVisualState("demaximized");
163
- switch (ctx.win.resizeAction) {
164
- case "s":
165
- privateApi.resizeBottomWinHeight(ctx);
166
- break;
167
- case "n":
168
- privateApi.resizeTopWinHeight(ctx);
169
- break;
170
- case "e":
171
- privateApi.resizeRightWinWidth(ctx);
172
- break;
173
- case "w":
174
- privateApi.resizeLeftWinWidth(ctx);
175
- break;
176
- case "se":
177
- privateApi.resizeRightBottomWidthAndHeight(ctx);
178
- break;
179
- case "sw":
180
- privateApi.resizeLeftBottomWidthAndHeight(ctx);
181
- break;
182
- case "ne":
183
- privateApi.resizeRightTopWidthAndHeight(ctx);
184
- break;
185
- case "nw":
186
- privateApi.resizeLeftTopWidthAndHeight(ctx);
187
- break;
188
- }
430
+ DISABLE_RESIZE: (_) => {
431
+ const patch = [];
432
+ for (const key of Object.keys(windowRegistry))
433
+ patch.push({
434
+ winId: key,
435
+ patch: {
436
+ resizeAction: false
437
+ }
438
+ });
439
+ return patch;
189
440
  }
190
441
  };
191
- var privateApi = {
192
- resizeRightWinWidth: (resizeCtx) => {
193
- const { wsRect, win, winBox, x, y } = resizeCtx;
194
- if (!winBox)
442
+
443
+ // src/window-manager/internal/runtime/resize-resolver/resize-loop.ts
444
+ var rafResizeLoopResolver = {
445
+ LOOP_RESIZE: (targetWinId, commitCb) => {
446
+ const dep = getRafResizeDependencies(targetWinId);
447
+ const resizeDirection = dep.win.resizeAction;
448
+ if (!resizeDirection)
449
+ throw new Error(`LOOP_RESIZE called with resizeAction as false for winId: ${targetWinId}`);
450
+ const winElementBox = dep.winBox;
451
+ if (!winElementBox)
452
+ throw new Error(`LOOP_RESIZE called with null window element for winId: ${targetWinId}`);
453
+ requestAnimationFrame(
454
+ () => resizer[resizeDirection](getRafResizeDependencies(targetWinId), commitCb)
455
+ );
456
+ }
457
+ };
458
+ var resizer = {
459
+ e: (resizeDep, commit) => {
460
+ const { wsRect, win, winBox, x, y } = resizeDep;
461
+ if (!win.resizeAction)
195
462
  return;
196
- const minWinWidth = x - winBox.left < win.WIN_MIN_WIDTH;
197
- if (minWinWidth)
463
+ if (!winBox)
198
464
  return;
199
465
  const cursorOutOfBounds = x > wsRect.right || x < wsRect.left;
200
- if (cursorOutOfBounds)
201
- return;
466
+ const minWinWidth = x - winBox.left < win.WIN_MIN_WIDTH;
202
467
  const sizeDiff = x - winBox.right;
203
- win.setWinWidth(win.winWidth + sizeDiff);
468
+ if (!minWinWidth && !cursorOutOfBounds && sizeDiff !== 0) {
469
+ commit([
470
+ {
471
+ winId: win.windowId,
472
+ patch: { winWidth: win.winWidth + sizeDiff }
473
+ }
474
+ ]);
475
+ }
476
+ requestAnimationFrame(() => resizer.e(getRafResizeDependencies(win.windowId), commit));
204
477
  },
205
- resizeLeftWinWidth: (resizeCtx) => {
206
- const { wsRect, win, winBox, x, y } = resizeCtx;
478
+ w: (resizeDep, commit) => {
479
+ const { wsRect, win, winBox, x, y } = resizeDep;
480
+ if (!win.resizeAction)
481
+ return;
207
482
  if (!winBox)
208
483
  return;
209
484
  const minWinWidth = winBox.right - x <= win.WIN_MIN_WIDTH;
210
- if (minWinWidth)
211
- return;
212
485
  const cursorOutOfBounds = x > wsRect.right || x < wsRect.left;
213
- if (cursorOutOfBounds)
214
- return;
215
486
  const sizeDiff = winBox.left - x;
216
- win.setWinWidth(win.winWidth + sizeDiff);
217
- win.setWinCoord({ pointX: x, pointY: win.winCoord.pointY });
487
+ if (!minWinWidth && !cursorOutOfBounds && sizeDiff !== 0) {
488
+ commit([
489
+ {
490
+ winId: win.windowId,
491
+ patch: {
492
+ winWidth: win.winWidth + sizeDiff,
493
+ winCoord: { pointX: x, pointY: win.winCoord.pointY }
494
+ }
495
+ }
496
+ ]);
497
+ }
498
+ requestAnimationFrame(() => resizer.w(getRafResizeDependencies(win.windowId), commit));
218
499
  },
219
- resizeTopWinHeight: (resizeCtx) => {
220
- const { wsRect, win, winBox, x, y } = resizeCtx;
500
+ n: (resizeDep, commit) => {
501
+ const { wsRect, win, winBox, x, y } = resizeDep;
502
+ if (!win.resizeAction)
503
+ return;
221
504
  if (!winBox)
222
505
  return;
223
506
  const minWinHeight = winBox.bottom - y <= win.WIN_MIN_HEIGHT;
224
- if (minWinHeight)
225
- return;
226
507
  const cursorOutOfBounds = y > wsRect.bottom || y < wsRect.top;
227
- if (cursorOutOfBounds)
228
- return;
229
508
  const sizeDiff = winBox.top - y;
230
- win.setWinHeight(win.winHeight + sizeDiff);
231
- win.setWinCoord({ pointX: win.winCoord.pointX, pointY: y });
509
+ if (!minWinHeight && !cursorOutOfBounds && sizeDiff !== 0) {
510
+ commit([
511
+ {
512
+ winId: win.windowId,
513
+ patch: {
514
+ winHeight: win.winHeight + sizeDiff,
515
+ winCoord: { pointX: win.winCoord.pointX, pointY: y }
516
+ }
517
+ }
518
+ ]);
519
+ }
520
+ requestAnimationFrame(() => resizer.n(getRafResizeDependencies(win.windowId), commit));
232
521
  },
233
- resizeBottomWinHeight: (resizeCtx) => {
234
- const { wsRect, win, winBox, x, y } = resizeCtx;
522
+ s: (resizeDep, commit) => {
523
+ const { wsRect, win, winBox, x, y } = resizeDep;
524
+ if (!win.resizeAction)
525
+ return;
235
526
  if (!winBox)
236
527
  return;
237
528
  const minWinHeight = y - winBox.top < win.WIN_MIN_HEIGHT;
238
- if (minWinHeight)
239
- return;
240
529
  const cursorOutOfBounds = y > wsRect.bottom || y < wsRect.top;
241
- if (cursorOutOfBounds)
242
- return;
243
530
  const sizeDiff = y - winBox.bottom;
244
- win.setWinHeight(win.winHeight + sizeDiff);
245
- },
246
- resizeRightBottomWidthAndHeight: (resizeCtx) => {
247
- privateApi.resizeRightWinWidth(resizeCtx);
248
- privateApi.resizeBottomWinHeight(resizeCtx);
249
- },
250
- resizeLeftBottomWidthAndHeight: (resizeCtx) => {
251
- privateApi.resizeLeftWinWidth(resizeCtx);
252
- privateApi.resizeBottomWinHeight(resizeCtx);
253
- },
254
- resizeRightTopWidthAndHeight: (resizeCtx) => {
255
- privateApi.resizeRightWinWidth(resizeCtx);
256
- privateApi.resizeTopWinHeight(resizeCtx);
531
+ if (!minWinHeight && !cursorOutOfBounds && sizeDiff !== 0) {
532
+ commit([
533
+ {
534
+ winId: win.windowId,
535
+ patch: {
536
+ winHeight: win.winHeight + sizeDiff
537
+ }
538
+ }
539
+ ]);
540
+ }
541
+ requestAnimationFrame(() => resizer.s(getRafResizeDependencies(win.windowId), commit));
257
542
  },
258
- /**
259
- * @note this specific case needs it's own logic instead of simply calling
260
- * resizeLeftWinWidth & resizeTopWinHeight. Since both manipulate
261
- * winWidth, winHeight and winCoord, one's logic will override the other
262
- */
263
- resizeLeftTopWidthAndHeight: (resizeCtx) => {
264
- const { wsRect, win, winBox, x, y } = resizeCtx;
543
+ nw: (resizeDep, commit) => {
544
+ const { wsRect, win, winBox, x, y } = resizeDep;
545
+ if (!win.resizeAction)
546
+ return;
265
547
  if (!winBox)
266
548
  return;
267
549
  const cursorOutOfBoundsY = y > wsRect.bottom || y < wsRect.top;
268
550
  const cursorOutOfBoundsX = x > wsRect.right || x < wsRect.left;
269
- if (cursorOutOfBoundsY || cursorOutOfBoundsX)
270
- return;
551
+ const isCursorOutOfBounds = cursorOutOfBoundsY || cursorOutOfBoundsX;
552
+ if (isCursorOutOfBounds) {
553
+ requestAnimationFrame(() => resizer.nw(getRafResizeDependencies(win.windowId), commit));
554
+ }
271
555
  const minWinHeight = winBox.bottom - y <= win.WIN_MIN_HEIGHT;
272
556
  const minWinWidth = winBox.right - x <= win.WIN_MIN_WIDTH;
273
- win.setWinCoord({
274
- pointX: minWinWidth ? win.winCoord.pointX : x,
275
- pointY: minWinHeight ? win.winCoord.pointY : y
557
+ const sizeDiffY = winBox.top - y;
558
+ const sizeDiffX = winBox.left - x;
559
+ const stagedChagnes = [];
560
+ if (sizeDiffY !== 0 || sizeDiffX !== 0) {
561
+ stagedChagnes.push({
562
+ winId: win.windowId,
563
+ patch: {
564
+ winCoord: {
565
+ pointX: minWinWidth ? win.winCoord.pointX : x,
566
+ pointY: minWinHeight ? win.winCoord.pointY : y
567
+ }
568
+ }
569
+ });
570
+ }
571
+ if (!minWinHeight && sizeDiffY !== 0) {
572
+ stagedChagnes.push({
573
+ winId: win.windowId,
574
+ patch: { winHeight: win.winHeight + sizeDiffY }
575
+ });
576
+ }
577
+ if (!minWinWidth && sizeDiffX !== 0) {
578
+ stagedChagnes.push({
579
+ winId: win.windowId,
580
+ patch: { winWidth: win.winWidth + sizeDiffX }
581
+ });
582
+ }
583
+ commit(stagedChagnes);
584
+ requestAnimationFrame(() => resizer.nw(getRafResizeDependencies(win.windowId), commit));
585
+ },
586
+ se: (resizeDep, commit) => {
587
+ resizer.e(resizeDep, commit);
588
+ resizer.s(resizeDep, commit);
589
+ },
590
+ sw: (resizeDep, commit) => {
591
+ resizer.w(resizeDep, commit);
592
+ resizer.s(resizeDep, commit);
593
+ },
594
+ ne: (resizeDep, commit) => {
595
+ resizer.e(resizeDep, commit);
596
+ resizer.n(resizeDep, commit);
597
+ }
598
+ };
599
+ var getRafResizeDependencies = (winId) => {
600
+ const win = windowRegistry[winId].getState();
601
+ const winBox = win.winElement?.getBoundingClientRect();
602
+ const wsRect = useWorkspaceState.getState().wsRect;
603
+ const { x, y } = useCursorState.getState();
604
+ return { wsRect, win, winBox, x, y };
605
+ };
606
+
607
+ // src/window-manager/internal/runtime/rwm-runtime.ts
608
+ var rwmRuntime = {
609
+ dispatch: ({ subsystem, cmd, targetWinId, ctx }) => {
610
+ switch (subsystem) {
611
+ case "WORKSPACE": {
612
+ const stagedChanges = workspaceCommandResolver[cmd](targetWinId, ctx);
613
+ commitToWorkspace(stagedChanges);
614
+ break;
615
+ }
616
+ case "DRAG": {
617
+ if (!isDragAllowed())
618
+ return;
619
+ const stagedChanges = dragCommandResolver[cmd](targetWinId);
620
+ commitToWindow(stagedChanges);
621
+ break;
622
+ }
623
+ case "DOCK": {
624
+ const { wsRect } = getDockDependencies();
625
+ const stagedChanges = dockCommandResolver[cmd](targetWinId, wsRect);
626
+ commitToWindow(stagedChanges);
627
+ break;
628
+ }
629
+ case "RESIZE": {
630
+ const stagedChanges = resizeCommandResolver[cmd](targetWinId, ctx);
631
+ commitToWindow(stagedChanges);
632
+ break;
633
+ }
634
+ case "STACK": {
635
+ const stagedChanges = stackCommandResolver[cmd](targetWinId);
636
+ commitToWindow(stagedChanges);
637
+ break;
638
+ }
639
+ case "FOCUS": {
640
+ const stagedChanges = focusCommandResolver[cmd](targetWinId);
641
+ commitBatch(stagedChanges);
642
+ break;
643
+ }
644
+ }
645
+ }
646
+ };
647
+ var rafRuntime = {
648
+ dispatch: ({ subsystem, cmd, targetWinId }) => {
649
+ switch (subsystem) {
650
+ case "RAF_DRAG": {
651
+ if (!isDragAllowed())
652
+ return;
653
+ rafDragLoopResolver[cmd](targetWinId, commitToWindow);
654
+ break;
655
+ }
656
+ case "RAF_RESIZE": {
657
+ rafResizeLoopResolver[cmd](targetWinId, commitToWindow);
658
+ break;
659
+ }
660
+ }
661
+ }
662
+ };
663
+ function commitBatch({ win, ws }) {
664
+ commitToWorkspace(ws);
665
+ commitToWindow(win);
666
+ }
667
+ function commitToWindow(patchStack) {
668
+ patchStack.forEach(({ winId, patch }) => {
669
+ windowRegistry[winId].setState(patch);
670
+ });
671
+ }
672
+ function commitToWorkspace(patch) {
673
+ if (patch) {
674
+ useWorkspaceState.setState(patch);
675
+ }
676
+ }
677
+
678
+ // src/window-manager/internal/features/docking/docking-api.ts
679
+ var dockApi = {
680
+ dockWindowRight: (winId) => rwmRuntime.dispatch({
681
+ targetWinId: winId,
682
+ subsystem: "DOCK",
683
+ cmd: "DOCK_WINDOW_RIGHT"
684
+ }),
685
+ dockWindowLeft: (winId) => rwmRuntime.dispatch({
686
+ targetWinId: winId,
687
+ subsystem: "DOCK",
688
+ cmd: "DOCK_WINDOW_LEFT"
689
+ }),
690
+ dockWindowTop: (winId) => rwmRuntime.dispatch({
691
+ targetWinId: winId,
692
+ subsystem: "DOCK",
693
+ cmd: "DOCK_WINDOW_TOP"
694
+ }),
695
+ dockWindowBottom: (winId) => rwmRuntime.dispatch({
696
+ targetWinId: winId,
697
+ subsystem: "DOCK",
698
+ cmd: "DOCK_WINDOW_BOTTOM"
699
+ }),
700
+ dockWindowBottomRight: (winId) => rwmRuntime.dispatch({
701
+ targetWinId: winId,
702
+ subsystem: "DOCK",
703
+ cmd: "DOCK_WINDOW_BOTTOM_RIGHT"
704
+ }),
705
+ dockWindowTopRight: (winId) => rwmRuntime.dispatch({
706
+ targetWinId: winId,
707
+ subsystem: "DOCK",
708
+ cmd: "DOCK_WINDOW_TOP_RIGHT"
709
+ }),
710
+ dockWindowBottomLeft: (winId) => rwmRuntime.dispatch({
711
+ targetWinId: winId,
712
+ subsystem: "DOCK",
713
+ cmd: "DOCK_WINDOW_BOTTOM_LEFT"
714
+ }),
715
+ dockWindowTopLeft: (winId) => rwmRuntime.dispatch({
716
+ targetWinId: winId,
717
+ subsystem: "DOCK",
718
+ cmd: "DOCK_WINDOW_TOP_LEFT"
719
+ }),
720
+ maximizeWindow: (winId) => rwmRuntime.dispatch({
721
+ targetWinId: winId,
722
+ subsystem: "DOCK",
723
+ cmd: "MAXIMIZE_WINDOW"
724
+ }),
725
+ demaximizeWindow: (winId) => rwmRuntime.dispatch({
726
+ targetWinId: winId,
727
+ subsystem: "DOCK",
728
+ cmd: "DEMAXIMIZE_WINDOW"
729
+ })
730
+ };
731
+
732
+ // src/window-manager/internal/features/focus/focus-api.ts
733
+ var focusApi = {
734
+ bringWindowToFocus: (targetId) => {
735
+ rwmRuntime.dispatch({
736
+ targetWinId: targetId,
737
+ subsystem: "FOCUS",
738
+ cmd: "FOCUS_WINDOW"
739
+ });
740
+ },
741
+ closeWindowAndRefocus: (targetId) => {
742
+ rwmRuntime.dispatch({
743
+ targetWinId: targetId,
744
+ subsystem: "FOCUS",
745
+ cmd: "CLOSE_WINDOW_AND_REFOCUS"
746
+ });
747
+ }
748
+ };
749
+
750
+ // src/window-manager/internal/features/stack/stack-api.ts
751
+ var stackApi = {
752
+ resetStack: () => {
753
+ rwmRuntime.dispatch({ subsystem: "STACK", cmd: "RESET_STACK" });
754
+ }
755
+ };
756
+
757
+ // src/window-manager/internal/features/workspace/workspace-api.ts
758
+ var wsApi = {
759
+ /**
760
+ * Always relative to the WorkspaceLayout dimensions. Use `wsApi.setWsResponsiveBreak` to modify the value
761
+ * @default 'sm'
762
+ * @param sm uses mobile format at 640px
763
+ * @param md uses mobile format at 768px
764
+ * @param lg uses mobile format at 1024px
765
+ * @param xl uses mobile format at 1280px
766
+ * @param never never uses mobile format
767
+ * @param always always uses mobile format
768
+ * @param number set custom break point value in px */
769
+ setWsResponsiveBreak: (breakPoint) => {
770
+ rwmRuntime.dispatch({
771
+ subsystem: "WORKSPACE",
772
+ cmd: "SET_RESPONSIVE_BREAK",
773
+ ctx: { responsiveBreak: breakPoint }
774
+ });
775
+ },
776
+ setWsFeatures: ({ isDockPannelEnabled = true, isGridEnabled = true }) => {
777
+ rwmRuntime.dispatch({
778
+ subsystem: "WORKSPACE",
779
+ cmd: "SET_WORKSPACE_FEATURES",
780
+ ctx: { isDockPannelEnabled, isGridEnabled }
781
+ });
782
+ },
783
+ updateWsRect: () => {
784
+ rwmRuntime.dispatch({ subsystem: "WORKSPACE", cmd: "UPDATE_WORKSPACE_RECT" });
785
+ }
786
+ };
787
+
788
+ // src/window-manager/rwm.ts
789
+ var { updateWsRect, ...publicWsApi } = wsApi;
790
+ var rwm = {
791
+ dockApi,
792
+ focusApi,
793
+ stackApi,
794
+ workspaceApi: publicWsApi,
795
+ /**
796
+ * @about
797
+ * Zustand hook, can be used to access the current state of the workspace by either
798
+ * calling `const { <someState> } = worskpaceState()` inside a component or by calling
799
+ * `worskpaceState.getState()` anywhere.
800
+ *
801
+ * @note
802
+ * The hook also exposes the `setState()` method, however, this is highly discouraged. Prefer calling
803
+ * the exposed apis in rwm for state mutation.
804
+ */
805
+ worskpaceState: useWorkspaceState,
806
+ /**
807
+ * @about
808
+ * use the syntax `const { <someState> } = windowRegistry[<winId>]()` inside a component to access
809
+ * the zustand hook or `windowRegistry[<winId>].getState()` to get the current state of a window anywhere
810
+ *
811
+ * @note
812
+ * Each hook also exposes the `setState()` method, however, this is highly discouraged. Prefer calling
813
+ * the exposed apis in rwm for state mutation.
814
+ */
815
+ windowRegistry
816
+ };
817
+ var rwm_default = rwm;
818
+
819
+ // src/window-manager/workspace-layout.tsx
820
+ import { useEffect as useEffect3, useRef } from "react";
821
+
822
+ // src/window-manager/internal/features/docking/docking-controls.tsx
823
+ import { useState } from "react";
824
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
825
+ function DockingControls() {
826
+ const [isHovering, setIsHovering] = useState(false);
827
+ const { activeWindowId, isDockPannelEnabled, isBelowBreakPoint } = useWorkspaceState();
828
+ const { isDragging } = windowRegistry[activeWindowId]();
829
+ const cornerDockControl = /* @__PURE__ */ jsxs("div", { className: `flex xl:p-0 shrink-0 gap-0.5`, children: [
830
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col justify-center gap-0.5", children: [
831
+ /* @__PURE__ */ jsx(
832
+ "button",
833
+ {
834
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
835
+ onPointerUp: () => dockApi.dockWindowTopLeft(activeWindowId)
836
+ }
837
+ ),
838
+ /* @__PURE__ */ jsx(
839
+ "button",
840
+ {
841
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
842
+ onPointerUp: () => dockApi.dockWindowBottomLeft(activeWindowId)
843
+ }
844
+ )
845
+ ] }),
846
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col justify-center gap-0.5", children: [
847
+ /* @__PURE__ */ jsx(
848
+ "button",
849
+ {
850
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
851
+ onPointerUp: () => dockApi.dockWindowTopRight(activeWindowId)
852
+ }
853
+ ),
854
+ /* @__PURE__ */ jsx(
855
+ "button",
856
+ {
857
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
858
+ onPointerUp: () => dockApi.dockWindowBottomRight(activeWindowId)
859
+ }
860
+ )
861
+ ] })
862
+ ] });
863
+ const sideDideControl = /* @__PURE__ */ jsxs("div", { className: `flex shrink-0 items-center gap-0.5`, children: [
864
+ /* @__PURE__ */ jsx(
865
+ "button",
866
+ {
867
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-8 h-12 rounded-sm",
868
+ onPointerUp: () => dockApi.dockWindowLeft(activeWindowId)
869
+ }
870
+ ),
871
+ /* @__PURE__ */ jsx(
872
+ "button",
873
+ {
874
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-8 h-12 rounded-sm",
875
+ onPointerUp: () => dockApi.dockWindowRight(activeWindowId)
876
+ }
877
+ )
878
+ ] });
879
+ const horizontalDockControl = /* @__PURE__ */ jsxs("div", { className: `flex flex-col shrink-0 items-center gap-0.5`, children: [
880
+ /* @__PURE__ */ jsx(
881
+ "button",
882
+ {
883
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-14 h-6 rounded-sm",
884
+ onPointerUp: () => dockApi.dockWindowTop(activeWindowId)
885
+ }
886
+ ),
887
+ /* @__PURE__ */ jsx(
888
+ "button",
889
+ {
890
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-14 h-6 rounded-sm",
891
+ onPointerUp: () => dockApi.dockWindowBottom(activeWindowId)
892
+ }
893
+ )
894
+ ] });
895
+ const windowDockPannel = /* @__PURE__ */ jsx(
896
+ "span",
897
+ {
898
+ className: "pointer-events-auto px-4 pb-3",
899
+ onPointerOver: () => setIsHovering(true),
900
+ onPointerLeave: () => setIsHovering(false),
901
+ children: /* @__PURE__ */ jsxs(
902
+ "section",
903
+ {
904
+ className: `
905
+ flex w-fit border border-zinc-600 border-t-0 rounded-b-md bg-zinc-800
906
+ overflow-hidden px-8 gap-4 h-full py-4
907
+ `,
908
+ children: [
909
+ cornerDockControl,
910
+ horizontalDockControl,
911
+ sideDideControl
912
+ ]
913
+ }
914
+ )
915
+ }
916
+ );
917
+ if (isBelowBreakPoint)
918
+ return;
919
+ if (!isDockPannelEnabled)
920
+ return;
921
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
922
+ "div",
923
+ {
924
+ className: `
925
+ ${isDragging ? isHovering ? "top-0 opacity-50" : "top-[-68px] opacity-80" : "top-[-104px] opacity-0"}
926
+ transition-all duration-500
927
+ absolute z-50 flex items-center justify-center
928
+ w-full mx-auto pointer-events-none`,
929
+ children: windowDockPannel
930
+ }
931
+ ) });
932
+ }
933
+
934
+ // src/window-manager/internal/features/resizing/resizing-api.ts
935
+ var resizeApi = {
936
+ startResize: (winId, direction) => {
937
+ rwmRuntime.dispatch({
938
+ targetWinId: winId,
939
+ subsystem: "RESIZE",
940
+ cmd: "ENABLE_RESIZE",
941
+ ctx: direction
942
+ });
943
+ rafRuntime.dispatch({ targetWinId: winId, subsystem: "RAF_RESIZE", cmd: "LOOP_RESIZE" });
944
+ },
945
+ stopResize: (winId) => {
946
+ rwmRuntime.dispatch({
947
+ targetWinId: winId,
948
+ subsystem: "RESIZE",
949
+ cmd: "DISABLE_RESIZE",
950
+ ctx: false
951
+ });
952
+ }
953
+ };
954
+
955
+ // src/window-manager/internal/features/cursor/cursor-move-listener.tsx
956
+ import { useEffect } from "react";
957
+ import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
958
+ function CursorMoveListener() {
959
+ const { setXY } = useCursorState();
960
+ useEffect(() => {
961
+ const handleWindowPosition = (e) => {
962
+ e.preventDefault();
963
+ setXY(e.clientX, e.clientY);
964
+ };
965
+ window.addEventListener("pointermove", handleWindowPosition);
966
+ return () => window.removeEventListener("pointermove", handleWindowPosition);
967
+ }, [setXY]);
968
+ return /* @__PURE__ */ jsx2(Fragment2, {});
969
+ }
970
+
971
+ // src/window-manager/internal/features/workspace/workspace-resize-listener.tsx
972
+ import { useEffect as useEffect2 } from "react";
973
+ import { Fragment as Fragment3, jsx as jsx3 } from "react/jsx-runtime";
974
+ function WorkspaceResizeListener() {
975
+ const { wsElement } = useWorkspaceState();
976
+ useEffect2(() => {
977
+ if (!wsElement)
978
+ return;
979
+ const onResize = () => {
980
+ wsApi.updateWsRect();
981
+ stackApi.resetStack();
982
+ };
983
+ onResize();
984
+ const observer = new ResizeObserver(onResize);
985
+ observer.observe(wsElement);
986
+ return () => observer.disconnect();
987
+ }, [wsElement]);
988
+ return /* @__PURE__ */ jsx3(Fragment3, {});
989
+ }
990
+
991
+ // src/window-manager/internal/features/drag/drag-api.ts
992
+ var dragApi = {
993
+ startDrag: (targetWinId) => {
994
+ rwmRuntime.dispatch({
995
+ targetWinId,
996
+ subsystem: "DRAG",
997
+ cmd: "ENABLE_DRAG"
998
+ });
999
+ rafRuntime.dispatch({ targetWinId, subsystem: "RAF_DRAG", cmd: "LOOP_DRAG" });
1000
+ },
1001
+ stopDrag: (targetWinId) => {
1002
+ rwmRuntime.dispatch({
1003
+ targetWinId,
1004
+ subsystem: "DRAG",
1005
+ cmd: "DISABLE_DRAG"
276
1006
  });
277
- if (!minWinHeight) {
278
- const sizeDiffY = winBox.top - y;
279
- win.setWinHeight(win.winHeight + sizeDiffY);
1007
+ }
1008
+ };
1009
+
1010
+ // src/window-manager/workspace-layout.tsx
1011
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
1012
+ function WorkspaceLayout({ children, className }) {
1013
+ const { setWsElement, wsElement, isBelowBreakPoint, activeWindowId } = useWorkspaceState();
1014
+ const workspaceRef = useRef(null);
1015
+ useEffect3(() => {
1016
+ if (!workspaceRef.current)
1017
+ return;
1018
+ setWsElement(workspaceRef.current);
1019
+ }, [wsElement]);
1020
+ const disabledDragAndResize = () => {
1021
+ dragApi.stopDrag(activeWindowId);
1022
+ resizeApi.stopResize(activeWindowId);
1023
+ };
1024
+ return /* @__PURE__ */ jsxs2(
1025
+ "section",
1026
+ {
1027
+ id: "rwm-workspace-layout",
1028
+ ref: workspaceRef,
1029
+ onPointerLeave: disabledDragAndResize,
1030
+ onPointerUp: disabledDragAndResize,
1031
+ className: className ? className : "fixed overflow-hidden h-full w-full touch-none",
1032
+ children: [
1033
+ /* @__PURE__ */ jsx4(WorkspaceResizeListener, {}),
1034
+ /* @__PURE__ */ jsx4(CursorMoveListener, {}),
1035
+ /* @__PURE__ */ jsxs2("div", { className: " w-full h-full relative overflow-hidden", children: [
1036
+ !isBelowBreakPoint && /* @__PURE__ */ jsx4(DockingControls, {}),
1037
+ children
1038
+ ] })
1039
+ ]
1040
+ }
1041
+ );
1042
+ }
1043
+
1044
+ // src/window-manager/registration/window-store-factory.tsx
1045
+ import { create as create3 } from "zustand";
1046
+
1047
+ // src/window-manager/internal/features/window-layout.tsx
1048
+ import { useEffect as useEffect4, useRef as useRef2 } from "react";
1049
+
1050
+ // src/window-manager/internal/assets/svg-win-icons.tsx
1051
+ import { jsx as jsx5 } from "react/jsx-runtime";
1052
+ function IconWinMaximize({ color }) {
1053
+ return /* @__PURE__ */ jsx5(
1054
+ "svg",
1055
+ {
1056
+ xmlns: "http://www.w3.org/2000/svg",
1057
+ fill: "none",
1058
+ viewBox: "0 0 24 24",
1059
+ width: 24,
1060
+ height: 24,
1061
+ strokeWidth: 1.5,
1062
+ stroke: color ? color : "#cccccc",
1063
+ color: color ? color : "#cccccc",
1064
+ className: "size-6",
1065
+ children: /* @__PURE__ */ jsx5(
1066
+ "path",
1067
+ {
1068
+ strokeLinecap: "round",
1069
+ strokeLinejoin: "round",
1070
+ d: "M5.25 7.5A2.25 2.25 0 0 1 7.5 5.25h9a2.25 2.25 0 0 1 2.25 2.25v9a2.25 2.25 0 0 1-2.25 2.25h-9a2.25 2.25 0 0 1-2.25-2.25v-9Z"
1071
+ }
1072
+ )
1073
+ }
1074
+ );
1075
+ }
1076
+ function IconWinDemaximize({ color }) {
1077
+ return /* @__PURE__ */ jsx5(
1078
+ "svg",
1079
+ {
1080
+ xmlns: "http://www.w3.org/2000/svg",
1081
+ fill: "none",
1082
+ viewBox: "0 0 24 24",
1083
+ width: 24,
1084
+ height: 24,
1085
+ strokeWidth: 1.5,
1086
+ stroke: color ? color : "#cccccc",
1087
+ color: color ? color : "#cccccc",
1088
+ className: "size-6",
1089
+ children: /* @__PURE__ */ jsx5(
1090
+ "path",
1091
+ {
1092
+ strokeLinecap: "round",
1093
+ strokeLinejoin: "round",
1094
+ d: "M16.5 8.25V6a2.25 2.25 0 0 0-2.25-2.25H6A2.25 2.25 0 0 0 3.75 6v8.25A2.25 2.25 0 0 0 6 16.5h2.25m8.25-8.25H18a2.25 2.25 0 0 1 2.25 2.25V18A2.25 2.25 0 0 1 18 20.25h-7.5A2.25 2.25 0 0 1 8.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 0 0-2.25 2.25v6"
1095
+ }
1096
+ )
280
1097
  }
281
- if (!minWinWidth) {
282
- const sizeDiffX = winBox.left - x;
283
- win.setWinWidth(win.winWidth + sizeDiffX);
1098
+ );
1099
+ }
1100
+ function IconWinMinimize({ color }) {
1101
+ return /* @__PURE__ */ jsx5(
1102
+ "svg",
1103
+ {
1104
+ xmlns: "http://www.w3.org/2000/svg",
1105
+ fill: "none",
1106
+ viewBox: "0 0 24 24",
1107
+ width: 24,
1108
+ height: 24,
1109
+ strokeWidth: 1.5,
1110
+ stroke: color ? color : "#cccccc",
1111
+ color: color ? color : "#cccccc",
1112
+ className: "size-6",
1113
+ children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18 18 6M6 6l12 12" })
284
1114
  }
285
- }
286
- };
287
- var getDependencies = (winId) => {
288
- const wsRect = wsApi.getRect();
289
- const win = windowRegistry[winId].getState();
290
- const winBox = win.self?.current?.getBoundingClientRect();
291
- const { x, y } = useCursorState.getState();
292
- return { wsRect, win, winBox, x, y };
293
- };
1115
+ );
1116
+ }
294
1117
 
295
- // src/window-manager/internal/features/stack/stack-api.ts
296
- var stackApi = {
297
- bringTargetWindowToFront: (targetId) => {
298
- const targetWindow = windowRegistry[targetId].getState();
299
- for (const key of Object.keys(windowRegistry)) {
300
- const window2 = windowRegistry[key].getState();
301
- if (window2.windowId === targetWindow.windowId) {
302
- continue;
303
- }
304
- window2.setIsActive(false);
305
- if (window2.zIndex >= targetWindow.zIndex) {
306
- window2.setZIndex(window2.zIndex - 1);
307
- }
308
- }
309
- targetWindow.setZIndex(Object.keys(windowRegistry).length);
310
- targetWindow.setIsActive(true);
311
- },
312
- getOpenedWindowCount: () => {
313
- let openWnidowCount = 0;
314
- for (const key of Object.keys(windowRegistry))
315
- if (!windowRegistry[key].getState().isWindowClosed)
316
- openWnidowCount++;
317
- return openWnidowCount;
318
- },
319
- resetStack: () => {
320
- for (const key of Object.keys(windowRegistry)) {
321
- windowRegistry[key].getState().reset();
322
- }
1118
+ // src/window-manager/internal/features/grid/grid-orchestrator.ts
1119
+ var tolerance = 4;
1120
+ var gridOrchestrator = {
1121
+ attachAdjacentGridBehavior: (winId) => {
1122
+ if (!useWorkspaceState.getState().isGridEnabled)
1123
+ return;
1124
+ if (getOpenWinCount() < 1)
1125
+ throw new Error(`gridOrchestrator initalized but all windows are closed`);
1126
+ if (getDraggingWinCount() < 1)
1127
+ throw new Error(`gridOrchestrator initalized but no window is currently resizing`);
1128
+ attachAdjacentGridBehavior(winId);
323
1129
  }
324
1130
  };
325
-
326
- // src/window-manager/internal/features/grid/grid-api.ts
327
- var gridApi = {
328
- orchestrateGridResize: (winId) => orchestrationGridResize(winId)
329
- };
330
- var orchestrationGridResize = (winId) => {
331
- const tolerance = 4;
332
- const allowDistantResize = stackApi.getOpenedWindowCount() >= 3;
1131
+ var attachAdjacentGridBehavior = (winId, visited = /* @__PURE__ */ new Set()) => {
1132
+ if (visited.has(winId))
1133
+ return;
1134
+ else
1135
+ visited.add(winId);
333
1136
  const thisWin = windowRegistry[winId].getState();
334
1137
  const currentResize = thisWin.resizeAction;
335
1138
  for (const key of Object.keys(windowRegistry)) {
336
1139
  const remoteWin = windowRegistry[key].getState();
337
- if (remoteWin.windowId === thisWin.windowId) {
1140
+ if (remoteWin.windowId === thisWin.windowId)
338
1141
  continue;
339
- }
340
- const thisWinStartY = thisWin.winCoord.pointY;
341
- const thisWinEndY = thisWin.winCoord.pointY + thisWin.winHeight;
342
- const remoteWinStartY = remoteWin.winCoord.pointY;
343
- const remoteWinEndY = remoteWin.winCoord.pointY + remoteWin.winHeight;
344
- const thisWinStartX = thisWin.winCoord.pointX;
345
- const thisWinEndX = thisWin.winCoord.pointX + thisWin.winWidth;
346
- const remoteWinStartX = remoteWin.winCoord.pointX;
347
- const remoteWinEndX = remoteWin.winCoord.pointX + remoteWin.winWidth;
348
- const isRemoteOutside = remoteWinEndY !== thisWinEndY || remoteWinEndX !== thisWinEndX || remoteWinStartY !== thisWinStartY || remoteWinStartX !== thisWinStartX;
1142
+ if (remoteWin.isWindowClosed)
1143
+ continue;
1144
+ if (remoteWin.resizeAction)
1145
+ continue;
1146
+ if (visited.has(remoteWin.windowId))
1147
+ continue;
1148
+ const dependencies = buildDependencies(thisWin, remoteWin);
349
1149
  if (currentResize === "e") {
350
- const isEdgeAlignedOnXAxis = Math.abs(thisWinEndX - remoteWinStartX) <= tolerance;
351
- const isOverlapOnYAxis = thisWinStartY <= remoteWinEndY && thisWinEndY >= remoteWinStartY;
352
- const isEdgeResize = allowDistantResize ? isEdgeAlignedOnXAxis : isEdgeAlignedOnXAxis && isOverlapOnYAxis;
353
- if (isEdgeResize) {
354
- remoteWin.setResizeAction("w");
355
- }
356
- const isRemoteOnSameLane = Math.abs(thisWinEndX - remoteWinEndX) < tolerance && Math.abs(thisWinStartX - remoteWinStartX) < tolerance;
357
- const isRemoteEdgeConnected = Math.abs(thisWinEndY - remoteWinStartY) < tolerance || Math.abs(thisWinStartY - remoteWinEndY) < tolerance;
358
- const isStackResize = allowDistantResize ? isRemoteOnSameLane && isRemoteOutside : isRemoteOnSameLane && isRemoteEdgeConnected;
359
- if (isStackResize) {
360
- remoteWin.setResizeAction("e");
361
- }
1150
+ const isRemoteConneted = resizeCase.whenDraggingEast(dependencies);
1151
+ if (isRemoteConneted)
1152
+ attachAdjacentGridBehavior(remoteWin.windowId, visited);
362
1153
  }
363
1154
  if (currentResize === "w") {
364
- const isEdgeAlignedOnXAxis = Math.abs(thisWinStartX - remoteWinEndX) <= tolerance;
365
- const isOverlapOnYAxis = thisWinStartY <= remoteWinEndY && thisWinEndY >= remoteWinStartY;
366
- const isEdgeResize = allowDistantResize ? isEdgeAlignedOnXAxis : isEdgeAlignedOnXAxis && isOverlapOnYAxis;
367
- if (isEdgeResize) {
368
- remoteWin.setResizeAction("e");
369
- }
370
- const isRemoteOnSameLane = Math.abs(thisWinEndX - remoteWinEndX) < tolerance && Math.abs(thisWinStartX - remoteWinStartX) < tolerance;
371
- const isRemoteEdgeConnected = Math.abs(thisWinEndY - remoteWinStartY) < tolerance || Math.abs(thisWinStartY - remoteWinEndY) < tolerance;
372
- const isStackResize = allowDistantResize ? isRemoteOnSameLane && isRemoteOutside : isRemoteOnSameLane && isRemoteEdgeConnected;
373
- if (isStackResize) {
374
- remoteWin.setResizeAction("w");
375
- }
1155
+ const isRemoteConneted = resizeCase.whenDragginWest(dependencies);
1156
+ if (isRemoteConneted)
1157
+ attachAdjacentGridBehavior(remoteWin.windowId, visited);
376
1158
  }
377
1159
  if (currentResize === "n") {
378
- const isEdgeAlignedOnYAxis = Math.abs(thisWinStartY - remoteWinEndY) <= tolerance;
379
- const isOverlapOnXAxis = thisWinStartX <= remoteWinEndX && thisWinEndX >= remoteWinStartX;
380
- const isEdgeResize = allowDistantResize ? isEdgeAlignedOnYAxis : isEdgeAlignedOnYAxis && isOverlapOnXAxis;
381
- if (isEdgeResize) {
382
- remoteWin.setResizeAction("s");
383
- }
384
- const isRemoteOnSameLane = Math.abs(thisWinEndY - remoteWinEndY) < tolerance && Math.abs(thisWinStartY - remoteWinStartY) < tolerance;
385
- const isRemoteEdgeConnected = Math.abs(thisWinEndX - remoteWinStartX) < tolerance || Math.abs(thisWinStartX - remoteWinEndX) < tolerance;
386
- const isStackResize = allowDistantResize ? isRemoteOnSameLane && isRemoteOutside : isRemoteOnSameLane && isRemoteEdgeConnected;
387
- if (isStackResize) {
388
- remoteWin.setResizeAction("n");
389
- }
1160
+ const isRemoteConneted = resizeCase.whenDragginNorth(dependencies);
1161
+ if (isRemoteConneted)
1162
+ attachAdjacentGridBehavior(remoteWin.windowId, visited);
390
1163
  }
391
1164
  if (currentResize === "s") {
392
- const isEdgeAlignedOnYAxis = Math.abs(thisWinEndY - remoteWinStartY) <= tolerance;
393
- const isOverlapOnXAxis = thisWinStartX <= remoteWinEndX && thisWinEndX >= remoteWinStartX;
394
- const isEdgeResize = allowDistantResize ? isEdgeAlignedOnYAxis : isEdgeAlignedOnYAxis && isOverlapOnXAxis;
395
- if (isEdgeResize) {
396
- remoteWin.setResizeAction("n");
397
- }
398
- const isRemoteOnSameLane = Math.abs(thisWinEndY - remoteWinEndY) < tolerance && Math.abs(thisWinStartY - remoteWinStartY) < tolerance;
399
- const isRemoteEdgeConnected = Math.abs(thisWinEndX - remoteWinStartX) < tolerance || Math.abs(thisWinStartX - remoteWinEndX) < tolerance;
400
- const isStackResize = allowDistantResize ? isRemoteOnSameLane && isRemoteOutside : isRemoteOnSameLane && isRemoteEdgeConnected;
401
- if (isStackResize) {
402
- remoteWin.setResizeAction("s");
403
- }
1165
+ const isRemoteConneted = resizeCase.whenDraggingSouth(dependencies);
1166
+ if (isRemoteConneted)
1167
+ attachAdjacentGridBehavior(remoteWin.windowId, visited);
1168
+ }
1169
+ }
1170
+ };
1171
+ var resizeCase = {
1172
+ whenDraggingEast: (d) => {
1173
+ const isOppositeEdgeAlignedOnXAxis = Math.abs(d.thisWinEndX - d.remoteWinStartX) <= tolerance;
1174
+ const isOverlapOnYAxis = d.thisWinStartY <= d.remoteWinEndY && d.thisWinEndY >= d.remoteWinStartY;
1175
+ const isEdgeResize = isOppositeEdgeAlignedOnXAxis && isOverlapOnYAxis;
1176
+ if (isEdgeResize) {
1177
+ resizeApi.startResize(d.remoteId, "w");
1178
+ return true;
1179
+ }
1180
+ const isSameEdgeAlignedOnXAxis = Math.abs(d.thisWinEndX - d.remoteWinEndX) <= tolerance;
1181
+ const isRemoteNorthOrSouthEdgeConnected = Math.abs(d.thisWinEndY - d.remoteWinStartY) < tolerance || Math.abs(d.thisWinStartY - d.remoteWinEndY) < tolerance;
1182
+ const isStackResize = isSameEdgeAlignedOnXAxis && isRemoteNorthOrSouthEdgeConnected;
1183
+ if (isStackResize) {
1184
+ resizeApi.startResize(d.remoteId, "e");
1185
+ return true;
1186
+ }
1187
+ return false;
1188
+ },
1189
+ whenDragginWest: (d) => {
1190
+ const isOppositeEdgeAlignedOnXAxis = Math.abs(d.thisWinStartX - d.remoteWinEndX) <= tolerance;
1191
+ const isOverlapOnYAxis = d.thisWinStartY <= d.remoteWinEndY && d.thisWinEndY >= d.remoteWinStartY;
1192
+ const isEdgeResize = isOppositeEdgeAlignedOnXAxis && isOverlapOnYAxis;
1193
+ if (isEdgeResize) {
1194
+ resizeApi.startResize(d.remoteId, "e");
1195
+ return true;
1196
+ }
1197
+ const isSameEdgeAlignedOnXAxis = Math.abs(d.thisWinStartX - d.remoteWinStartX) <= tolerance;
1198
+ const isRemoteNorthOrSouthEdgeConnected = Math.abs(d.thisWinEndY - d.remoteWinStartY) < tolerance || Math.abs(d.thisWinStartY - d.remoteWinEndY) < tolerance;
1199
+ const isStackResize = isSameEdgeAlignedOnXAxis && isRemoteNorthOrSouthEdgeConnected;
1200
+ if (isStackResize) {
1201
+ resizeApi.startResize(d.remoteId, "w");
1202
+ return true;
404
1203
  }
1204
+ return false;
1205
+ },
1206
+ whenDragginNorth: (d) => {
1207
+ const isOppositeEdgeAlignedOnYAxis = Math.abs(d.thisWinStartY - d.remoteWinEndY) <= tolerance;
1208
+ const isOverlapOnXAxis = d.thisWinStartX <= d.remoteWinEndX && d.thisWinEndX >= d.remoteWinStartX;
1209
+ const isEdgeResize = isOppositeEdgeAlignedOnYAxis && isOverlapOnXAxis;
1210
+ if (isEdgeResize) {
1211
+ resizeApi.startResize(d.remoteId, "s");
1212
+ return true;
1213
+ }
1214
+ const isSameEdgeAlignedOnYAxis = Math.abs(d.thisWinStartY - d.remoteWinStartY) <= tolerance;
1215
+ const isRemoteEastOrWestEdgeConnected = Math.abs(d.thisWinEndX - d.remoteWinStartX) < tolerance || Math.abs(d.thisWinStartX - d.remoteWinEndX) < tolerance;
1216
+ const isStackResize = isSameEdgeAlignedOnYAxis && isRemoteEastOrWestEdgeConnected;
1217
+ if (isStackResize) {
1218
+ resizeApi.startResize(d.remoteId, "n");
1219
+ return true;
1220
+ }
1221
+ return false;
1222
+ },
1223
+ whenDraggingSouth: (d) => {
1224
+ const isOppositeEdgeAlignedOnYAxis = Math.abs(d.thisWinEndY - d.remoteWinStartY) <= tolerance;
1225
+ const isOverlapOnXAxis = d.thisWinStartX <= d.remoteWinEndX && d.thisWinEndX >= d.remoteWinStartX;
1226
+ const isEdgeResize = isOppositeEdgeAlignedOnYAxis && isOverlapOnXAxis;
1227
+ if (isEdgeResize) {
1228
+ resizeApi.startResize(d.remoteId, "n");
1229
+ return true;
1230
+ }
1231
+ const isSameEdgeAlignedOnYAxis = Math.abs(d.thisWinEndY - d.remoteWinEndY) <= tolerance;
1232
+ const isRemoteEastOrWestEdgeConnected = Math.abs(d.thisWinEndX - d.remoteWinStartX) < tolerance || Math.abs(d.thisWinStartX - d.remoteWinEndX) < tolerance;
1233
+ const isStackResize = isSameEdgeAlignedOnYAxis && isRemoteEastOrWestEdgeConnected;
1234
+ if (isStackResize) {
1235
+ resizeApi.startResize(d.remoteId, "s");
1236
+ return true;
1237
+ }
1238
+ return false;
405
1239
  }
406
1240
  };
1241
+ var buildDependencies = (thisWin, remoteWin) => {
1242
+ const thisWinStartY = thisWin.winCoord.pointY;
1243
+ const thisWinEndY = thisWin.winCoord.pointY + thisWin.winHeight;
1244
+ const remoteWinStartY = remoteWin.winCoord.pointY;
1245
+ const remoteWinEndY = remoteWin.winCoord.pointY + remoteWin.winHeight;
1246
+ const thisWinStartX = thisWin.winCoord.pointX;
1247
+ const thisWinEndX = thisWin.winCoord.pointX + thisWin.winWidth;
1248
+ const remoteWinStartX = remoteWin.winCoord.pointX;
1249
+ const remoteWinEndX = remoteWin.winCoord.pointX + remoteWin.winWidth;
1250
+ const isRemoteOutside = remoteWinEndY !== thisWinEndY || remoteWinEndX !== thisWinEndX || remoteWinStartY !== thisWinStartY || remoteWinStartX !== thisWinStartX;
1251
+ return {
1252
+ remoteId: remoteWin.windowId,
1253
+ thisWinStartY,
1254
+ thisWinEndY,
1255
+ remoteWinStartY,
1256
+ remoteWinEndY,
1257
+ thisWinStartX,
1258
+ thisWinEndX,
1259
+ remoteWinStartX,
1260
+ remoteWinEndX,
1261
+ isRemoteOutside
1262
+ };
1263
+ };
1264
+ var getDraggingWinCount = () => {
1265
+ let isWindowResizingCount = 0;
1266
+ for (const key of Object.keys(windowRegistry))
1267
+ if (windowRegistry[key].getState().resizeAction)
1268
+ isWindowResizingCount++;
1269
+ return isWindowResizingCount;
1270
+ };
1271
+ var getOpenWinCount = () => {
1272
+ let openWnidowCount = 0;
1273
+ for (const key of Object.keys(windowRegistry))
1274
+ if (!windowRegistry[key].getState().isWindowClosed)
1275
+ openWnidowCount++;
1276
+ return openWnidowCount;
1277
+ };
407
1278
 
408
1279
  // src/window-manager/internal/features/resizing/resizing-controls.tsx
409
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
1280
+ import { Fragment as Fragment4, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
410
1281
  function ResizingControls({ winId }) {
411
- const { x, y } = useCursorState();
412
1282
  const { winCoord, winWidth, winHeight, resizeAction } = windowRegistry[winId]();
413
- useEffect(() => {
414
- resizeApi.dispatchResizeAction(winId);
415
- }, [resizeAction, x, y]);
416
- const handleResizeClick = (resizeAction2) => {
417
- resizeApi.setResizeAction(winId, resizeAction2);
418
- gridApi.orchestrateGridResize(winId);
1283
+ const startResize = (direction) => {
1284
+ resizeApi.startResize(winId, direction);
1285
+ gridOrchestrator.attachAdjacentGridBehavior(winId);
419
1286
  };
420
- return /* @__PURE__ */ jsxs(Fragment, { children: [
421
- /* @__PURE__ */ jsx2(
1287
+ const stopResize = () => {
1288
+ resizeApi.stopResize(winId);
1289
+ };
1290
+ return /* @__PURE__ */ jsxs3(Fragment4, { children: [
1291
+ /* @__PURE__ */ jsx6(
422
1292
  "span",
423
1293
  {
424
- onMouseUp: () => handleResizeClick(false),
425
- onMouseDown: () => handleResizeClick("e"),
1294
+ onPointerUp: stopResize,
1295
+ onPointerDown: () => startResize("e"),
426
1296
  id: "win-resize-right-width",
427
- className: "fixed w-2 opacity-60 cursor-w-resize z-10",
1297
+ className: `fixed w-2 ${resizeAction === "e" ? "opacity-50" : ""} opacity-0 mix-blend-difference cursor-w-resize z-10 flex-col flex justify-center items-center overflow-hidden`,
428
1298
  style: {
429
1299
  top: `${winCoord.pointY}px`,
430
1300
  left: `${winCoord.pointX + winWidth - 4}px`,
431
1301
  height: `${winHeight}px`
432
- }
1302
+ },
1303
+ children: /* @__PURE__ */ jsx6("div", { className: `w-1 h-full bg-zinc-50` })
433
1304
  }
434
1305
  ),
435
- /* @__PURE__ */ jsx2(
1306
+ /* @__PURE__ */ jsx6(
436
1307
  "span",
437
1308
  {
438
- onMouseUp: () => handleResizeClick(false),
439
- onMouseDown: () => handleResizeClick("w"),
1309
+ onPointerUp: stopResize,
1310
+ onPointerDown: () => startResize("w"),
440
1311
  id: "win-resize-left-width",
441
- className: "fixed w-2 opacity-60 cursor-w-resize z-10",
1312
+ className: `fixed w-2 ${resizeAction === "w" ? "opacity-50" : ""} opacity-0 mix-blend-difference cursor-w-resize z-10 flex-col flex justify-center items-center`,
442
1313
  style: {
443
1314
  top: `${winCoord.pointY}px`,
444
1315
  left: `${winCoord.pointX - 4}px`,
445
1316
  height: `${winHeight}px`
446
- }
1317
+ },
1318
+ children: /* @__PURE__ */ jsx6("div", { className: `w-1 h-full bg-zinc-50` })
447
1319
  }
448
1320
  ),
449
- /* @__PURE__ */ jsx2(
1321
+ /* @__PURE__ */ jsx6(
450
1322
  "span",
451
1323
  {
452
- onMouseUp: () => handleResizeClick(false),
453
- onMouseDown: () => handleResizeClick("s"),
1324
+ onPointerUp: stopResize,
1325
+ onPointerDown: () => startResize("s"),
454
1326
  id: "win-resize-bottom-height",
455
- className: "fixed h-2 opacity-60 cursor-s-resize z-10",
1327
+ className: `fixed h-2 ${resizeAction === "s" ? "opacity-50" : ""} opacity-0 mix-blend-difference cursor-s-resize z-10 flex justify-center items-center`,
456
1328
  style: {
457
- top: `${winCoord.pointY + winHeight - 6}px`,
1329
+ top: `${winCoord.pointY + winHeight - 4}px`,
458
1330
  left: `${winCoord.pointX}px`,
459
1331
  width: `${winWidth}px`
460
- }
1332
+ },
1333
+ children: /* @__PURE__ */ jsx6("div", { className: `w-full h-1 bg-zinc-50` })
461
1334
  }
462
1335
  ),
463
- /* @__PURE__ */ jsx2(
1336
+ /* @__PURE__ */ jsx6(
464
1337
  "span",
465
1338
  {
466
- onMouseUp: () => handleResizeClick(false),
467
- onMouseDown: () => handleResizeClick("n"),
1339
+ onPointerUp: stopResize,
1340
+ onPointerDown: () => startResize("n"),
468
1341
  id: "win-resize-top-height",
469
- className: "fixed h-2 opacity-60 cursor-s-resize z-10",
1342
+ className: `fixed h-2 ${resizeAction === "n" ? "opacity-50" : ""} opacity-0 mix-blend-difference cursor-s-resize z-10 flex justify-center items-center`,
470
1343
  style: {
471
- top: `${winCoord.pointY - 6}px`,
1344
+ top: `${winCoord.pointY - 4}px`,
472
1345
  left: `${winCoord.pointX}px`,
473
1346
  width: `${winWidth}px`
474
- }
1347
+ },
1348
+ children: /* @__PURE__ */ jsx6("div", { className: `w-full h-1 bg-zinc-50` })
475
1349
  }
476
1350
  ),
477
- /* @__PURE__ */ jsx2(
1351
+ /* @__PURE__ */ jsx6(
478
1352
  "span",
479
1353
  {
480
- onMouseUp: () => handleResizeClick(false),
481
- onMouseDown: () => handleResizeClick("se"),
1354
+ onPointerUp: stopResize,
1355
+ onPointerDown: () => startResize("se"),
482
1356
  id: "win-resize-bottom-right-all",
483
1357
  className: "fixed h-3 w-3 opacity-60 cursor-se-resize z-20",
484
1358
  style: {
@@ -487,11 +1361,11 @@ function ResizingControls({ winId }) {
487
1361
  }
488
1362
  }
489
1363
  ),
490
- /* @__PURE__ */ jsx2(
1364
+ /* @__PURE__ */ jsx6(
491
1365
  "span",
492
1366
  {
493
- onMouseUp: () => handleResizeClick(false),
494
- onMouseDown: () => handleResizeClick("sw"),
1367
+ onPointerUp: stopResize,
1368
+ onPointerDown: () => startResize("sw"),
495
1369
  id: "win-resize-bottom-left-all",
496
1370
  className: "fixed h-3 w-3 opacity-60 cursor-sw-resize z-20",
497
1371
  style: {
@@ -500,11 +1374,11 @@ function ResizingControls({ winId }) {
500
1374
  }
501
1375
  }
502
1376
  ),
503
- /* @__PURE__ */ jsx2(
1377
+ /* @__PURE__ */ jsx6(
504
1378
  "span",
505
1379
  {
506
- onMouseUp: () => handleResizeClick(false),
507
- onMouseDown: () => handleResizeClick("ne"),
1380
+ onPointerUp: stopResize,
1381
+ onPointerDown: () => startResize("ne"),
508
1382
  id: "win-resize-top-right-all",
509
1383
  className: "fixed h-3 w-3 opacity-60 cursor-ne-resize z-20",
510
1384
  style: {
@@ -513,11 +1387,11 @@ function ResizingControls({ winId }) {
513
1387
  }
514
1388
  }
515
1389
  ),
516
- /* @__PURE__ */ jsx2(
1390
+ /* @__PURE__ */ jsx6(
517
1391
  "span",
518
1392
  {
519
- onMouseUp: () => handleResizeClick(false),
520
- onMouseDown: () => handleResizeClick("nw"),
1393
+ onPointerUp: stopResize,
1394
+ onPointerDown: () => startResize("nw"),
521
1395
  id: "win-resize-top-left-all",
522
1396
  className: "fixed h-3 w-3 opacity-60 cursor-nw-resize z-20",
523
1397
  style: {
@@ -530,48 +1404,23 @@ function ResizingControls({ winId }) {
530
1404
  }
531
1405
 
532
1406
  // src/window-manager/internal/features/drag/drag-handle.tsx
533
- import { useEffect as useEffect2, useState } from "react";
534
- import { jsx as jsx3 } from "react/jsx-runtime";
1407
+ import { jsx as jsx7 } from "react/jsx-runtime";
535
1408
  function DragHandle({ winId }) {
536
- const { x, y } = useCursorState();
537
- const { winVisualState, isDragging, winCoord, setWinCoord, setIsDragging } = windowRegistry[winId]();
538
- const [dragClickOffset, setDragClickOffset] = useState({
539
- pointX: wsApi.getRect().left,
540
- pointY: wsApi.getRect().top
541
- });
542
- useEffect2(() => {
543
- if (wsApi.isBelowBreakPoint())
544
- return;
545
- if (!isDragging)
546
- return;
547
- if (winVisualState === "maximized")
548
- dockApi.demaximizeWindow(winId);
549
- const wsRect = wsApi.getRect();
550
- let adjustedX = x - dragClickOffset.pointX;
551
- if (x > wsRect.right || x < wsRect.left)
552
- adjustedX = winCoord.pointX;
553
- let adjustedY = y - dragClickOffset.pointY;
554
- if (y > wsRect.bottom || y < wsRect.top)
555
- adjustedY = winCoord.pointY;
556
- setWinCoord({ pointX: adjustedX, pointY: adjustedY });
557
- }, [isDragging, x, y]);
558
- const startDrag = (isDragging2) => {
559
- setDragClickOffset({ pointX: x - winCoord.pointX, pointY: y - winCoord.pointY });
560
- setIsDragging(isDragging2);
561
- };
562
- return /* @__PURE__ */ jsx3(
1409
+ return /* @__PURE__ */ jsx7(
563
1410
  "div",
564
1411
  {
565
- onMouseDown: () => startDrag(true),
566
- onMouseUp: () => startDrag(false),
1412
+ onPointerDown: () => dragApi.startDrag(winId),
1413
+ onPointerUp: () => dragApi.stopDrag(winId),
567
1414
  onDoubleClick: () => dockApi.maximizeWindow(winId),
568
- className: "grow min-w-8 h-8 px-2 text-white flex items-center text-sm bg-white bg-opacity-0 hover:bg-opacity-5 mix-blend-difference"
1415
+ className: `
1416
+ grow min-w-8 h-8 px-2 text-white flex items-center text-sm bg-white bg-opacity-0
1417
+ hover:bg-opacity-5 mix-blend-difference`
569
1418
  }
570
1419
  );
571
1420
  }
572
1421
 
573
1422
  // src/window-manager/internal/features/window-layout.tsx
574
- import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
1423
+ import { Fragment as Fragment5, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
575
1424
  function WindowLayout({
576
1425
  children,
577
1426
  windowName,
@@ -580,13 +1429,13 @@ function WindowLayout({
580
1429
  defaultDock = "default",
581
1430
  style
582
1431
  }) {
583
- const { ref: wsRef } = useWorkspaceState();
584
- const windowRef = useRef(null);
1432
+ const { wsElement, wsRect, isBelowBreakPoint } = useWorkspaceState();
1433
+ const windowRef = useRef2(null);
585
1434
  const {
586
1435
  windowId,
587
1436
  zIndex,
588
1437
  isActive,
589
- setSelf,
1438
+ setWinElement,
590
1439
  resetFlag,
591
1440
  winVisualState,
592
1441
  isWindowClosed,
@@ -594,14 +1443,16 @@ function WindowLayout({
594
1443
  winWidth,
595
1444
  winHeight
596
1445
  } = windowRegistry[winId]();
597
- useEffect3(() => {
598
- setSelf(windowRef);
599
- if (wsApi.isBelowBreakPoint()) {
1446
+ useEffect4(() => {
1447
+ setWinElement(windowRef.current);
1448
+ }, [setWinElement, windowRef.current]);
1449
+ useEffect4(() => {
1450
+ if (isBelowBreakPoint) {
600
1451
  dockApi.maximizeWindow(winId);
601
- return;
1452
+ } else {
1453
+ dockingRoutes[defaultDock](winId);
602
1454
  }
603
- dockingRoutes[defaultDock](winId);
604
- }, [setSelf, windowRef, resetFlag, wsRef]);
1455
+ }, [wsElement, resetFlag]);
605
1456
  const dockingRoutes = {
606
1457
  right: dockApi.dockWindowRight,
607
1458
  left: dockApi.dockWindowLeft,
@@ -614,37 +1465,37 @@ function WindowLayout({
614
1465
  "bottom-left": dockApi.dockWindowBottomLeft,
615
1466
  default: dockApi.demaximizeWindow
616
1467
  };
617
- const maximizeControl = winVisualState === "maximized" ? /* @__PURE__ */ jsx4(
1468
+ const maximizeControl = winVisualState === "maximized" ? /* @__PURE__ */ jsx8(
618
1469
  "button",
619
1470
  {
620
1471
  className: `block hover:bg-gray-500 hover:bg-opacity-10 px-5 h-full`,
621
1472
  onClick: () => dockApi.demaximizeWindow(winId),
622
- children: /* @__PURE__ */ jsx4(IconWinDemaximize, { color: style?.navControlsColor })
1473
+ children: /* @__PURE__ */ jsx8(IconWinDemaximize, { color: style?.navControlsColor })
623
1474
  }
624
- ) : /* @__PURE__ */ jsx4(
1475
+ ) : /* @__PURE__ */ jsx8(
625
1476
  "button",
626
1477
  {
627
1478
  className: `block hover:bg-gray-500 hover:bg-opacity-10 px-5 h-full`,
628
1479
  onClick: () => dockApi.maximizeWindow(winId),
629
- children: /* @__PURE__ */ jsx4(IconWinMaximize, { color: style?.navControlsColor })
1480
+ children: /* @__PURE__ */ jsx8(IconWinMaximize, { color: style?.navControlsColor })
630
1481
  }
631
1482
  );
632
- const closeControl = /* @__PURE__ */ jsx4(
1483
+ const closeControl = /* @__PURE__ */ jsx8(
633
1484
  "button",
634
1485
  {
635
1486
  className: "hover:bg-red-500 hover:bg-opacity-20 px-5 h-full",
636
- onClick: () => dockApi.closeWindow(winId),
637
- children: /* @__PURE__ */ jsx4(IconWinMinimize, { color: style?.navControlsColor })
1487
+ onClick: () => focusApi.closeWindowAndRefocus(winId),
1488
+ children: /* @__PURE__ */ jsx8(IconWinMinimize, { color: style?.navControlsColor })
638
1489
  }
639
1490
  );
640
- return /* @__PURE__ */ jsxs2(Fragment2, { children: [
641
- /* @__PURE__ */ jsxs2(
1491
+ return /* @__PURE__ */ jsxs4(Fragment5, { children: [
1492
+ /* @__PURE__ */ jsxs4(
642
1493
  "div",
643
1494
  {
644
1495
  id: windowId,
645
1496
  ref: windowRef,
646
1497
  className: `fixed bg-white shadow-lg border border-zinc-600 rounded-sm overflow-hidden`,
647
- onMouseDown: () => stackApi.bringTargetWindowToFront(windowId),
1498
+ onPointerDown: () => focusApi.bringWindowToFocus(windowId),
648
1499
  style: {
649
1500
  backgroundColor: style?.windowBackgroundColor,
650
1501
  top: `${winCoord.pointY}px`,
@@ -655,11 +1506,11 @@ function WindowLayout({
655
1506
  /* MINIMIZE LOGIC */
656
1507
  transition: "transform 0.2s ease-in-out, opacity 0.3s ease-in-out",
657
1508
  opacity: isWindowClosed ? 0 : 1,
658
- transform: isWindowClosed ? `translate(${wsApi.getRect().innerWidth / 2 - winCoord.pointX - winWidth / 2}px,
659
- ${wsApi.getRect().innerHeight - winCoord.pointY - winHeight / 2}px) scale(0.02)` : ""
1509
+ transform: isWindowClosed ? `translate(${wsRect.innerWidth / 2 - winCoord.pointX - winWidth / 2}px,
1510
+ ${wsRect.innerHeight - winCoord.pointY - winHeight / 2}px) scale(0.02)` : ""
660
1511
  },
661
1512
  children: [
662
- /* @__PURE__ */ jsxs2(
1513
+ /* @__PURE__ */ jsxs4(
663
1514
  "nav",
664
1515
  {
665
1516
  style: {
@@ -669,16 +1520,16 @@ function WindowLayout({
669
1520
  h-[32px] w-full flex items-center bg-neutral-800
670
1521
  ${isActive ? "brightness-100 opacity-100" : "brightness-75 opacity-80"}`,
671
1522
  children: [
672
- /* @__PURE__ */ jsx4("div", { className: "w-fit shrink-0 h-8 px-2 text-white flex items-center text-sm truncate", children: windowName }),
673
- /* @__PURE__ */ jsx4("div", { className: "h-8 px-2 text-white flex items-center text-sm truncate", children: navbarChildren }),
674
- /* @__PURE__ */ jsx4(DragHandle, { winId }),
675
- !wsApi.isBelowBreakPoint() && maximizeControl,
1523
+ /* @__PURE__ */ jsx8("div", { className: "shrink h-8 px-2 text-white flex items-center text-sm truncate min-w-0", children: windowName }),
1524
+ /* @__PURE__ */ jsx8("div", { className: "h-8 px-2 text-white flex items-center text-sm truncate min-w-0", children: navbarChildren }),
1525
+ /* @__PURE__ */ jsx8(DragHandle, { winId }),
1526
+ !isBelowBreakPoint && maximizeControl,
676
1527
  closeControl
677
1528
  ]
678
1529
  }
679
1530
  ),
680
- !wsApi.isBelowBreakPoint() && /* @__PURE__ */ jsx4(ResizingControls, { winId }),
681
- /* @__PURE__ */ jsx4("div", { className: `relative w-full h-[calc(100%-32px)] overflow-auto`, children })
1531
+ /* @__PURE__ */ jsx8(ResizingControls, { winId }),
1532
+ /* @__PURE__ */ jsx8("div", { className: `relative w-full h-[calc(100%-32px)] overflow-auto`, children })
682
1533
  ]
683
1534
  }
684
1535
  ),
@@ -687,367 +1538,71 @@ function WindowLayout({
687
1538
  }
688
1539
 
689
1540
  // src/window-manager/internal/features/window-button.tsx
690
- import { jsx as jsx5 } from "react/jsx-runtime";
1541
+ import { jsx as jsx9 } from "react/jsx-runtime";
691
1542
  function WindowButton({
692
1543
  children,
693
1544
  winId,
694
1545
  className,
695
- isClosedClassName = "brightness-[85%]",
696
- isOpenClassName = "brightness-150"
1546
+ isClosedClassName = "brightness-[85%] border-t-2 border-t-transparent",
1547
+ isOpenClassName = "brightness-150 border-t-2 border-t-transparent",
1548
+ isActiveClassName = "brightness-150 border-t-2 border-zinc-400 bg-zinc-50/10"
697
1549
  }) {
698
1550
  const { isWindowClosed, windowId, isActive } = windowRegistry[winId]();
699
1551
  const handleOpenCloseWin = () => {
700
- if (isWindowClosed) {
701
- stackApi.bringTargetWindowToFront(windowId);
702
- dockApi.openWindow(winId);
703
- return;
1552
+ if (!isWindowClosed && isActive) {
1553
+ focusApi.closeWindowAndRefocus(windowId);
1554
+ } else {
1555
+ focusApi.bringWindowToFocus(windowId);
704
1556
  }
705
- if (isActive)
706
- dockApi.closeWindow(winId);
707
- stackApi.bringTargetWindowToFront(windowId);
708
1557
  };
709
- return /* @__PURE__ */ jsx5(
1558
+ return /* @__PURE__ */ jsx9(
710
1559
  "button",
711
1560
  {
712
1561
  id: `${windowId}_button`,
713
1562
  onClick: handleOpenCloseWin,
714
1563
  className: `
715
1564
  ${className}
716
- ${isWindowClosed ? isClosedClassName : isOpenClassName}`,
1565
+ ${isWindowClosed ? isClosedClassName : isActive ? isActiveClassName : isOpenClassName}`,
717
1566
  children
718
1567
  }
719
1568
  );
720
1569
  }
721
1570
 
722
1571
  // src/window-manager/registration/window-store-factory.tsx
723
- import { jsx as jsx6 } from "react/jsx-runtime";
724
- var windownMinWidth = 232;
725
- var windownMinHeight = 128;
726
- var windowRegistry = {};
1572
+ import { jsx as jsx10 } from "react/jsx-runtime";
1573
+ var defaultMinWidth = 232;
1574
+ var defaultMinHeight = 128;
727
1575
  var createWindowStore = () => {
728
1576
  const zIndexAtLaunch = Object.keys(windowRegistry).length + 1;
729
1577
  const windowInstanceId = `react-dynamic-window-instance${Object.keys(windowRegistry).length}`;
730
1578
  const storeInstance = create3((set, get) => ({
1579
+ setWinElement: (ref) => set({ winElement: ref }),
1580
+ winElement: void 0,
731
1581
  windowId: windowInstanceId,
732
- self: void 0,
733
- setSelf: (ref) => set({ self: ref }),
734
- WIN_MIN_WIDTH: windownMinWidth,
735
- setWIN_MIN_WIDTH: (w) => set({ WIN_MIN_WIDTH: w }),
736
- WIN_MIN_HEIGHT: windownMinHeight,
737
- setWIN_MIN_HEIGHT: (h) => set({ WIN_MIN_HEIGHT: h }),
738
- isActive: false,
739
- setIsActive: (isActive) => {
740
- useWorkspaceState.getState().setActiveWindowId(get().windowId);
741
- set({ isActive });
742
- },
743
1582
  resetFlag: false,
744
- reset: () => set({ resetFlag: !get().resetFlag, isWindowClosed: true }),
745
1583
  zIndex: zIndexAtLaunch,
746
- setZIndex: (newIndex) => set({ zIndex: newIndex }),
1584
+ winCoord: { pointX: 40, pointY: 40 },
747
1585
  winVisualState: "demaximized",
748
- setWinVisualState: (newState) => set({ winVisualState: newState }),
1586
+ isActive: false,
1587
+ isDragging: false,
749
1588
  isWindowClosed: true,
750
- setisWindowClosed: (isClosed) => set({ isWindowClosed: isClosed }),
751
- winCoord: { pointX: 40, pointY: 40 },
752
- setWinCoord: (newWinCoord) => set({ winCoord: { pointX: newWinCoord.pointX, pointY: newWinCoord.pointY } }),
753
- winWidth: windownMinWidth,
754
- setWinWidth: (newWinWidth) => set({ winWidth: newWinWidth }),
755
- winHeight: windownMinHeight,
756
- setWinHeight: (newWinHeight) => set({ winHeight: newWinHeight }),
757
1589
  resizeAction: false,
758
- setResizeAction: (updatedIsResizing) => set({ resizeAction: updatedIsResizing }),
759
- isDragging: false,
760
- setIsDragging: (updatedIsDragging) => set({ isDragging: updatedIsDragging })
1590
+ winWidth: defaultMinWidth,
1591
+ winHeight: defaultMinHeight,
1592
+ WIN_MIN_WIDTH: defaultMinWidth,
1593
+ WIN_MIN_HEIGHT: defaultMinHeight
761
1594
  }));
762
1595
  windowRegistry[windowInstanceId] = storeInstance;
763
1596
  return {
764
1597
  id: storeInstance.getState().windowId,
765
1598
  store: storeInstance,
766
- Window: (props) => /* @__PURE__ */ jsx6(WindowLayout, { ...props, winId: windowInstanceId }),
767
- Button: (props) => /* @__PURE__ */ jsx6(WindowButton, { ...props, winId: windowInstanceId })
1599
+ Window: (props) => /* @__PURE__ */ jsx10(WindowLayout, { ...props, winId: windowInstanceId }),
1600
+ Button: (props) => /* @__PURE__ */ jsx10(WindowButton, { ...props, winId: windowInstanceId })
768
1601
  };
769
1602
  };
770
-
771
- // src/window-manager/internal/features/docking/docking-api.ts
772
- var dockApi = {
773
- dockWindowRight: (winId) => {
774
- windowRegistry[winId].setState({
775
- winCoord: { pointX: wsApi.getRect().centerX, pointY: wsApi.getRect().top },
776
- winWidth: wsApi.getRect().innerWidth / 2,
777
- winHeight: wsApi.getRect().innerHeight,
778
- winVisualState: "demaximized"
779
- });
780
- },
781
- dockWindowLeft: (winId) => {
782
- windowRegistry[winId].setState({
783
- winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().top },
784
- winWidth: wsApi.getRect().innerWidth / 2,
785
- winHeight: wsApi.getRect().innerHeight,
786
- winVisualState: "demaximized"
787
- });
788
- },
789
- dockWindowTop: (winId) => {
790
- windowRegistry[winId].setState({
791
- winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().top },
792
- winWidth: wsApi.getRect().innerWidth,
793
- winHeight: wsApi.getRect().innerHeight / 2,
794
- winVisualState: "demaximized"
795
- });
796
- },
797
- dockWindowBottom: (winId) => {
798
- windowRegistry[winId].setState({
799
- winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().centerY },
800
- winWidth: wsApi.getRect().innerWidth,
801
- winHeight: wsApi.getRect().innerHeight / 2,
802
- winVisualState: "demaximized"
803
- });
804
- },
805
- dockWindowBottomRight: (winId) => {
806
- windowRegistry[winId].setState({
807
- winCoord: {
808
- pointX: wsApi.getRect().centerX,
809
- pointY: wsApi.getRect().centerY
810
- },
811
- winWidth: wsApi.getRect().innerWidth / 2,
812
- winHeight: wsApi.getRect().innerHeight / 2,
813
- winVisualState: "demaximized"
814
- });
815
- },
816
- dockWindowTopRight: (winId) => {
817
- windowRegistry[winId].setState({
818
- winCoord: { pointX: wsApi.getRect().centerX, pointY: wsApi.getRect().top },
819
- winWidth: wsApi.getRect().innerWidth / 2,
820
- winHeight: wsApi.getRect().innerHeight / 2,
821
- winVisualState: "demaximized"
822
- });
823
- },
824
- dockWindowBottomLeft: (winId) => {
825
- windowRegistry[winId].setState({
826
- winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().centerY },
827
- winWidth: wsApi.getRect().innerWidth / 2,
828
- winHeight: wsApi.getRect().innerHeight / 2,
829
- winVisualState: "demaximized"
830
- });
831
- },
832
- dockWindowTopLeft: (winId) => {
833
- windowRegistry[winId].setState({
834
- winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().top },
835
- winWidth: wsApi.getRect().innerWidth / 2,
836
- winHeight: wsApi.getRect().innerHeight / 2,
837
- winVisualState: "demaximized"
838
- });
839
- },
840
- maximizeWindow: (winId) => {
841
- windowRegistry[winId].setState({
842
- winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().top },
843
- winHeight: wsApi.getRect().innerHeight,
844
- winWidth: wsApi.getRect().innerWidth,
845
- winVisualState: "maximized"
846
- });
847
- },
848
- demaximizeWindow: (winId) => {
849
- windowRegistry[winId].setState({
850
- winCoord: { pointX: wsApi.getRect().left + 16, pointY: wsApi.getRect().top + 16 },
851
- winWidth: wsApi.getRect().innerWidth * 0.95,
852
- winHeight: wsApi.getRect().innerHeight * 0.75,
853
- winVisualState: "demaximized"
854
- });
855
- },
856
- closeWindow: (winId) => {
857
- windowRegistry[winId].setState({ isWindowClosed: true });
858
- },
859
- openWindow: (winId) => {
860
- const winState = windowRegistry[winId].getState();
861
- const winRef = winState.self;
862
- if (winState.isWindowClosed && winRef?.current) {
863
- windowRegistry[winId].setState({ isWindowClosed: false });
864
- winRef.current.style.transform = "translate(0, 0) scale(1)";
865
- }
866
- }
867
- };
868
-
869
- // src/window-manager/rwm.ts
870
- var rwm = {
871
- dockApi,
872
- resizeApi,
873
- stackApi,
874
- workspaceApi: wsApi,
875
- worskpaceState: useWorkspaceState
876
- };
877
- var rwm_default = rwm;
878
-
879
- // src/window-manager/workspace-layout.tsx
880
- import { useEffect as useEffect6, useRef as useRef2 } from "react";
881
-
882
- // src/window-manager/internal/features/docking/docking-controls.tsx
883
- import { useState as useState2 } from "react";
884
- import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
885
- function DockingControls() {
886
- const [isHovering, setIsHovering] = useState2(false);
887
- const { activeWindowId } = useWorkspaceState();
888
- const { isDragging } = windowRegistry[activeWindowId]();
889
- const cornerDockControl = /* @__PURE__ */ jsxs3("div", { className: `flex xl:p-0 shrink-0 gap-0.5`, children: [
890
- /* @__PURE__ */ jsxs3("div", { className: "flex flex-col justify-center gap-0.5", children: [
891
- /* @__PURE__ */ jsx7(
892
- "button",
893
- {
894
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
895
- onMouseUp: () => dockApi.dockWindowTopLeft(activeWindowId)
896
- }
897
- ),
898
- /* @__PURE__ */ jsx7(
899
- "button",
900
- {
901
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
902
- onMouseUp: () => dockApi.dockWindowBottomLeft(activeWindowId)
903
- }
904
- )
905
- ] }),
906
- /* @__PURE__ */ jsxs3("div", { className: "flex flex-col justify-center gap-0.5", children: [
907
- /* @__PURE__ */ jsx7(
908
- "button",
909
- {
910
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
911
- onMouseUp: () => dockApi.dockWindowTopRight(activeWindowId)
912
- }
913
- ),
914
- /* @__PURE__ */ jsx7(
915
- "button",
916
- {
917
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
918
- onMouseUp: () => dockApi.dockWindowBottomRight(activeWindowId)
919
- }
920
- )
921
- ] })
922
- ] });
923
- const sideDideControl = /* @__PURE__ */ jsxs3("div", { className: `flex shrink-0 items-center gap-0.5`, children: [
924
- /* @__PURE__ */ jsx7(
925
- "button",
926
- {
927
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-8 h-12 rounded-sm",
928
- onMouseUp: () => dockApi.dockWindowLeft(activeWindowId)
929
- }
930
- ),
931
- /* @__PURE__ */ jsx7(
932
- "button",
933
- {
934
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-8 h-12 rounded-sm",
935
- onMouseUp: () => dockApi.dockWindowRight(activeWindowId)
936
- }
937
- )
938
- ] });
939
- const horizontalDockControl = /* @__PURE__ */ jsxs3("div", { className: `flex flex-col shrink-0 items-center gap-0.5`, children: [
940
- /* @__PURE__ */ jsx7(
941
- "button",
942
- {
943
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-14 h-6 rounded-sm",
944
- onMouseUp: () => dockApi.dockWindowTop(activeWindowId)
945
- }
946
- ),
947
- /* @__PURE__ */ jsx7(
948
- "button",
949
- {
950
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-14 h-6 rounded-sm",
951
- onMouseUp: () => dockApi.dockWindowBottom(activeWindowId)
952
- }
953
- )
954
- ] });
955
- const windowDockPannel = /* @__PURE__ */ jsx7(
956
- "span",
957
- {
958
- className: "pointer-events-auto px-4 pb-2",
959
- onMouseOver: () => setIsHovering(true),
960
- onMouseLeave: () => setIsHovering(false),
961
- children: /* @__PURE__ */ jsxs3(
962
- "section",
963
- {
964
- className: `
965
- flex w-fit border border-zinc-600 border-t-0 rounded-b-md bg-zinc-800
966
- overflow-hidden px-8 gap-4 h-full py-4
967
- `,
968
- children: [
969
- cornerDockControl,
970
- horizontalDockControl,
971
- sideDideControl
972
- ]
973
- }
974
- )
975
- }
976
- );
977
- return /* @__PURE__ */ jsx7(
978
- "div",
979
- {
980
- className: `
981
- ${isDragging ? isHovering ? "top-0 opacity-50" : "top-[-68px] opacity-80" : "top-[-104px] opacity-0"}
982
- transition-all duration-500
983
- absolute z-50 flex items-center justify-center
984
- w-full mx-auto pointer-events-none`,
985
- children: windowDockPannel
986
- }
987
- );
988
- }
989
-
990
- // src/window-manager/internal/features/cursor/cursor-move-listener.tsx
991
- import { useEffect as useEffect4 } from "react";
992
- import { Fragment as Fragment3, jsx as jsx8 } from "react/jsx-runtime";
993
- function CursorMoveListener() {
994
- const { setX, setY } = useCursorState();
995
- useEffect4(() => {
996
- const handleWindowPosition = (e) => {
997
- e.preventDefault();
998
- setX(e.clientX);
999
- setY(e.clientY);
1000
- };
1001
- window.addEventListener("pointermove", handleWindowPosition);
1002
- return () => window.removeEventListener("pointermove", handleWindowPosition);
1003
- }, [setX, setY]);
1004
- return /* @__PURE__ */ jsx8(Fragment3, {});
1005
- }
1006
-
1007
- // src/window-manager/internal/features/view-port/view-port-resize-listener.tsx
1008
- import { useEffect as useEffect5 } from "react";
1009
- import { Fragment as Fragment4, jsx as jsx9 } from "react/jsx-runtime";
1010
- function ViewPortResizeListener() {
1011
- useEffect5(() => {
1012
- window.addEventListener("resize", stackApi.resetStack);
1013
- return () => window.removeEventListener("resize", stackApi.resetStack);
1014
- }, []);
1015
- return /* @__PURE__ */ jsx9(Fragment4, {});
1016
- }
1017
-
1018
- // src/window-manager/workspace-layout.tsx
1019
- import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
1020
- function WorkspaceLayout({ children, className, responsiveBreak = "sm" }) {
1021
- const workspaceRef = useRef2(null);
1022
- const { setRef, setResponsiveBreak } = useWorkspaceState();
1023
- useEffect6(() => {
1024
- setRef(workspaceRef.current);
1025
- }, []);
1026
- useEffect6(() => {
1027
- setResponsiveBreak(responsiveBreak);
1028
- }, [responsiveBreak]);
1029
- return /* @__PURE__ */ jsxs4(
1030
- "section",
1031
- {
1032
- ref: workspaceRef,
1033
- onMouseLeave: resizeApi.stopAllDragAndResize,
1034
- onMouseUp: resizeApi.stopAllDragAndResize,
1035
- className: className ? className : "fixed overflow-hidden h-full w-full touch-none",
1036
- children: [
1037
- /* @__PURE__ */ jsx10(ViewPortResizeListener, {}),
1038
- /* @__PURE__ */ jsx10(CursorMoveListener, {}),
1039
- /* @__PURE__ */ jsxs4("div", { className: " w-full h-full relative overflow-hidden", children: [
1040
- !wsApi.isBelowBreakPoint() && /* @__PURE__ */ jsx10(DockingControls, {}),
1041
- children
1042
- ] })
1043
- ]
1044
- }
1045
- );
1046
- }
1047
1603
  export {
1048
1604
  WorkspaceLayout,
1049
1605
  createWindowStore,
1050
- rwm_default as rwm,
1051
- windowRegistry
1606
+ rwm_default as rwm
1052
1607
  };
1053
1608
  //# sourceMappingURL=index.js.map