@gustavolmo/react-window-manager 0.2.1 → 0.3.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 (47) hide show
  1. package/dist/index.css +1 -644
  2. package/dist/index.css.map +1 -1
  3. package/dist/index.d.ts +7 -101
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +787 -678
  6. package/dist/index.js.map +1 -1
  7. package/dist/window-manager/internal/assets/svg-win-icons.d.ts +8 -0
  8. package/dist/window-manager/internal/assets/svg-win-icons.d.ts.map +1 -0
  9. package/dist/window-manager/internal/features/cursor/cursor-move-listener.d.ts +2 -0
  10. package/dist/window-manager/internal/features/cursor/cursor-move-listener.d.ts.map +1 -0
  11. package/dist/window-manager/internal/features/cursor/cursor-state.d.ts +9 -0
  12. package/dist/window-manager/internal/features/cursor/cursor-state.d.ts.map +1 -0
  13. package/dist/window-manager/internal/features/docking/docking-api.d.ts +15 -0
  14. package/dist/window-manager/internal/features/docking/docking-api.d.ts.map +1 -0
  15. package/dist/window-manager/internal/features/docking/docking-controls.d.ts +2 -0
  16. package/dist/window-manager/internal/features/docking/docking-controls.d.ts.map +1 -0
  17. package/dist/window-manager/internal/features/drag/drag-handle.d.ts +6 -0
  18. package/dist/window-manager/internal/features/drag/drag-handle.d.ts.map +1 -0
  19. package/dist/window-manager/internal/features/grid/grid-api.d.ts +4 -0
  20. package/dist/window-manager/internal/features/grid/grid-api.d.ts.map +1 -0
  21. package/dist/window-manager/internal/features/resizing/resizing-api.d.ts +7 -0
  22. package/dist/window-manager/internal/features/resizing/resizing-api.d.ts.map +1 -0
  23. package/dist/window-manager/internal/features/resizing/resizing-controls.d.ts +6 -0
  24. package/dist/window-manager/internal/features/resizing/resizing-controls.d.ts.map +1 -0
  25. package/dist/window-manager/internal/features/stack/stack-api.d.ts +6 -0
  26. package/dist/window-manager/internal/features/stack/stack-api.d.ts.map +1 -0
  27. package/dist/window-manager/internal/features/view-port/view-port-resize-listener.d.ts +2 -0
  28. package/dist/window-manager/internal/features/view-port/view-port-resize-listener.d.ts.map +1 -0
  29. package/dist/window-manager/internal/features/window-button.d.ts +11 -0
  30. package/dist/window-manager/internal/features/window-button.d.ts.map +1 -0
  31. package/dist/window-manager/internal/features/window-layout.d.ts +17 -0
  32. package/dist/window-manager/internal/features/window-layout.d.ts.map +1 -0
  33. package/dist/window-manager/internal/features/workspace/workspace-api.d.ts +6 -0
  34. package/dist/window-manager/internal/features/workspace/workspace-api.d.ts.map +1 -0
  35. package/dist/window-manager/internal/features/workspace/workspace-state.d.ts +3 -0
  36. package/dist/window-manager/internal/features/workspace/workspace-state.d.ts.map +1 -0
  37. package/dist/window-manager/model/window-types.d.ts +46 -0
  38. package/dist/window-manager/model/window-types.d.ts.map +1 -0
  39. package/dist/window-manager/model/workspace-types.d.ts +20 -0
  40. package/dist/window-manager/model/workspace-types.d.ts.map +1 -0
  41. package/dist/window-manager/registration/window-store-factory.d.ts +14 -0
  42. package/dist/window-manager/registration/window-store-factory.d.ts.map +1 -0
  43. package/dist/window-manager/rwm.d.ts +33 -0
  44. package/dist/window-manager/rwm.d.ts.map +1 -0
  45. package/dist/window-manager/workspace-layout.d.ts +19 -0
  46. package/dist/window-manager/workspace-layout.d.ts.map +1 -0
  47. package/package.json +6 -3
package/dist/index.js CHANGED
@@ -1,264 +1,13 @@
1
- // src/window-manager/window-store-factory.tsx
2
- import { create } from "zustand";
3
- var windowRegistry = {};
4
- var createWindowStore = (windowId, bottomOffsetPx) => {
5
- if (windowRegistry[windowId])
6
- console.error("This store ID is already in use: " + windowId);
7
- const zIndexAtLaunch = Object.keys(windowRegistry).length + 1;
8
- const storeInstance = create((set, get) => ({
9
- windowId,
10
- isActive: false,
11
- setIsActive: (isActive) => set({ isActive }),
12
- resetFlag: false,
13
- reset: () => set({ resetFlag: !get().resetFlag, isWinMinimized: true }),
14
- zIndex: zIndexAtLaunch,
15
- setZIndex: (newIndex) => set({ zIndex: newIndex }),
16
- self: void 0,
17
- setSelf: (ref) => set({ self: ref }),
18
- winVisualState: "demaximized",
19
- setWinVisualState: (newState) => set({ winVisualState: newState }),
20
- isWinMinimized: true,
21
- setIsWinMinimized: (isMini) => set({ isWinMinimized: isMini }),
22
- dragClickOffset: { pointX: 0, pointY: 0 },
23
- setDragClickOffset: (newCoord) => set({ dragClickOffset: { pointX: newCoord.pointX, pointY: newCoord.pointY } }),
24
- isDragging: false,
25
- setIsDragging: (updatedIsDragging) => set({ isDragging: updatedIsDragging }),
26
- winCoord: { pointX: 40, pointY: 40 },
27
- setWinCoord: (newWinCoord) => set({ winCoord: { pointX: newWinCoord.pointX, pointY: newWinCoord.pointY } }),
28
- isResizing: false,
29
- setIsResizing: (updatedIsResizing) => set({ isResizing: updatedIsResizing }),
30
- winWidth: window.innerWidth * 0.95,
31
- setWinWidth: (newWinWidth) => set({ winWidth: newWinWidth }),
32
- winHeight: window.innerHeight * 0.75,
33
- setWinHeight: (newWinHeight) => set({ winHeight: newWinHeight }),
34
- stopDragAndResize: () => set({ isDragging: false, isResizing: false }),
35
- maximizeWindow: () => {
36
- set({
37
- winCoord: { pointX: 0, pointY: 0 },
38
- winHeight: window.innerHeight - bottomOffsetPx,
39
- winWidth: window.innerWidth,
40
- winVisualState: "maximized"
41
- });
42
- },
43
- demaximizeWindow: () => {
44
- set({
45
- winCoord: { pointX: 40, pointY: 40 },
46
- winWidth: window.innerWidth * 0.95,
47
- winHeight: window.innerHeight * 0.75,
48
- winVisualState: "demaximized"
49
- });
50
- },
51
- minimizeWindow: () => set({ isWinMinimized: true }),
52
- openWindow: () => {
53
- const winRef = get().self;
54
- if (get().isWinMinimized && winRef?.current) {
55
- set({ isWinMinimized: false });
56
- winRef.current.style.transform = "translate(0, 0) scale(1)";
57
- }
58
- },
59
- dockWindowRight: () => {
60
- set({
61
- winCoord: { pointX: window.innerWidth / 2, pointY: 0 },
62
- winWidth: window.innerWidth / 2,
63
- winHeight: window.innerHeight - bottomOffsetPx,
64
- winVisualState: "demaximized"
65
- });
66
- },
67
- dockWindowLeft: () => {
68
- set({
69
- winCoord: { pointX: 0, pointY: 0 },
70
- winWidth: window.innerWidth / 2,
71
- winHeight: window.innerHeight - bottomOffsetPx,
72
- winVisualState: "demaximized"
73
- });
74
- },
75
- dockWindowTop: () => {
76
- set({
77
- winCoord: { pointX: 0, pointY: 0 },
78
- winWidth: window.innerWidth,
79
- winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
80
- winVisualState: "demaximized"
81
- });
82
- },
83
- dockWindowBottom: () => {
84
- set({
85
- winCoord: { pointX: 0, pointY: window.innerHeight / 2 - bottomOffsetPx / 2 },
86
- winWidth: window.innerWidth,
87
- winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
88
- winVisualState: "demaximized"
89
- });
90
- },
91
- dockWindowBottomRight: () => set({
92
- winCoord: {
93
- pointX: window.innerWidth / 2,
94
- pointY: window.innerHeight / 2 - bottomOffsetPx / 2
95
- },
96
- winWidth: window.innerWidth / 2,
97
- winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
98
- winVisualState: "demaximized"
99
- }),
100
- dockWindowTopRight: () => set({
101
- winCoord: { pointX: window.innerWidth / 2, pointY: 0 },
102
- winWidth: window.innerWidth / 2,
103
- winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
104
- winVisualState: "demaximized"
105
- }),
106
- dockWindowBottomLeft: () => set({
107
- winCoord: { pointX: 0, pointY: window.innerHeight / 2 - bottomOffsetPx / 2 },
108
- winWidth: window.innerWidth / 2,
109
- winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
110
- winVisualState: "demaximized"
111
- }),
112
- dockWindowTopLeft: () => set({
113
- winCoord: { pointX: 0, pointY: 0 },
114
- winWidth: window.innerWidth / 2,
115
- winHeight: window.innerHeight / 2 - bottomOffsetPx / 2,
116
- winVisualState: "demaximized"
117
- }),
118
- WIN_MIN_WIDTH: 232,
119
- WIN_MIN_HEIGHT: 128,
120
- setWIN_MIN_WIDTH: (w) => set({ WIN_MIN_WIDTH: w }),
121
- setWIN_MIN_HEIGHT: (h) => set({ WIN_MIN_HEIGHT: h })
122
- }));
123
- windowRegistry[windowId] = storeInstance;
124
- return storeInstance;
125
- };
1
+ // src/window-manager/registration/window-store-factory.tsx
2
+ import { create as create3 } from "zustand";
126
3
 
127
- // src/window-manager/global-actions/window-global-actions.ts
128
- var stopAllDragAndResize = () => {
129
- for (const key of Object.keys(windowRegistry)) {
130
- windowRegistry[key].getState().stopDragAndResize();
131
- }
132
- };
133
- var resetAllWindows = () => {
134
- for (const key of Object.keys(windowRegistry)) {
135
- windowRegistry[key].getState().reset();
136
- }
137
- };
138
- var bringTargetWindowToFront = (targetId) => {
139
- const targetWindow = windowRegistry[targetId].getState();
140
- for (const key of Object.keys(windowRegistry)) {
141
- const window2 = windowRegistry[key].getState();
142
- if (window2.windowId === targetWindow.windowId) {
143
- continue;
144
- }
145
- window2.setIsActive(false);
146
- if (window2.zIndex >= targetWindow.zIndex) {
147
- window2.setZIndex(window2.zIndex - 1);
148
- }
149
- }
150
- targetWindow.setZIndex(Object.keys(windowRegistry).length);
151
- targetWindow.setIsActive(true);
152
- };
153
- var getOpenedWindowCount = () => {
154
- let openWnidowCount = 0;
155
- for (const key of Object.keys(windowRegistry)) {
156
- if (!windowRegistry[key].getState().isWinMinimized)
157
- openWnidowCount++;
158
- }
159
- return openWnidowCount;
160
- };
4
+ // src/window-manager/internal/features/window-layout.tsx
5
+ import { useEffect as useEffect3, useRef } from "react";
161
6
 
162
- // src/window-manager/window-button.tsx
7
+ // src/window-manager/internal/assets/svg-win-icons.tsx
163
8
  import { jsx } from "react/jsx-runtime";
164
- function WindowButton({
165
- children,
166
- useWindowStore,
167
- className,
168
- isClosedClassName = "brightness-[85%]",
169
- isOpenClassName = "brightness-150"
170
- }) {
171
- const { openWindow, minimizeWindow, isWinMinimized, windowId, isActive } = useWindowStore();
172
- const handleOpenCloseWin = () => {
173
- if (isWinMinimized) {
174
- bringTargetWindowToFront(windowId);
175
- openWindow();
176
- return;
177
- }
178
- if (isActive) {
179
- minimizeWindow();
180
- }
181
- bringTargetWindowToFront(windowId);
182
- };
9
+ function IconWinMaximize({ color }) {
183
10
  return /* @__PURE__ */ jsx(
184
- "button",
185
- {
186
- id: `${windowId}_button`,
187
- onClick: handleOpenCloseWin,
188
- className: `
189
- ${className}
190
- ${isWinMinimized ? isClosedClassName : isOpenClassName}`,
191
- children
192
- }
193
- );
194
- }
195
-
196
- // src/screen-manager/cursor-state.ts
197
- import { create as create2 } from "zustand";
198
- var useCursorState = create2((set) => ({
199
- x: 10,
200
- y: 10,
201
- setX: (newX) => set({ x: newX }),
202
- setY: (newY) => set({ y: newY })
203
- }));
204
-
205
- // src/screen-manager/screen-listeners.tsx
206
- import { useEffect } from "react";
207
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
208
- function ScreenListeners() {
209
- return /* @__PURE__ */ jsxs(Fragment, { children: [
210
- /* @__PURE__ */ jsx2(CursorCoordinates, {}),
211
- /* @__PURE__ */ jsx2(WindowResizeReset, {})
212
- ] });
213
- }
214
- function WindowResizeReset() {
215
- useEffect(() => {
216
- const handleWindowResize = () => {
217
- resetAllWindows();
218
- };
219
- window.addEventListener("resize", handleWindowResize);
220
- return () => document.removeEventListener("pointermove", handleWindowResize);
221
- }, []);
222
- return /* @__PURE__ */ jsx2(Fragment, {});
223
- }
224
- function CursorCoordinates() {
225
- const { setX, setY } = useCursorState();
226
- useEffect(() => {
227
- const handleWindowPosition = (e) => {
228
- e.preventDefault();
229
- setX(e.clientX);
230
- setY(e.clientY);
231
- };
232
- document.addEventListener("pointermove", handleWindowPosition);
233
- return () => document.removeEventListener("pointermove", handleWindowPosition);
234
- }, [setX, setY]);
235
- return /* @__PURE__ */ jsx2(Fragment, {});
236
- }
237
-
238
- // src/window-manager/workspace-layout.tsx
239
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
240
- function WorkspaceLayout({ children }) {
241
- return /* @__PURE__ */ jsxs2(
242
- "main",
243
- {
244
- onMouseLeave: stopAllDragAndResize,
245
- onMouseUp: stopAllDragAndResize,
246
- className: "absolute overflow-hidden h-full w-full touch-none",
247
- children: [
248
- /* @__PURE__ */ jsx3(ScreenListeners, {}),
249
- children
250
- ]
251
- }
252
- );
253
- }
254
-
255
- // src/window-manager/window-layout.tsx
256
- import { useEffect as useEffect4, useRef } from "react";
257
-
258
- // src/window-assets/svg-win-icons.tsx
259
- import { jsx as jsx4 } from "react/jsx-runtime";
260
- function iconWinMaximize(color) {
261
- return /* @__PURE__ */ jsx4(
262
11
  "svg",
263
12
  {
264
13
  xmlns: "http://www.w3.org/2000/svg",
@@ -270,7 +19,7 @@ function iconWinMaximize(color) {
270
19
  stroke: color ? color : "#cccccc",
271
20
  color: color ? color : "#cccccc",
272
21
  className: "size-6",
273
- children: /* @__PURE__ */ jsx4(
22
+ children: /* @__PURE__ */ jsx(
274
23
  "path",
275
24
  {
276
25
  strokeLinecap: "round",
@@ -281,8 +30,8 @@ function iconWinMaximize(color) {
281
30
  }
282
31
  );
283
32
  }
284
- function iconWinDemaximize(color) {
285
- return /* @__PURE__ */ jsx4(
33
+ function IconWinDemaximize({ color }) {
34
+ return /* @__PURE__ */ jsx(
286
35
  "svg",
287
36
  {
288
37
  xmlns: "http://www.w3.org/2000/svg",
@@ -294,7 +43,7 @@ function iconWinDemaximize(color) {
294
43
  stroke: color ? color : "#cccccc",
295
44
  color: color ? color : "#cccccc",
296
45
  className: "size-6",
297
- children: /* @__PURE__ */ jsx4(
46
+ children: /* @__PURE__ */ jsx(
298
47
  "path",
299
48
  {
300
49
  strokeLinecap: "round",
@@ -305,8 +54,8 @@ function iconWinDemaximize(color) {
305
54
  }
306
55
  );
307
56
  }
308
- function iconWinMinimize(color) {
309
- return /* @__PURE__ */ jsx4(
57
+ function IconWinMinimize({ color }) {
58
+ return /* @__PURE__ */ jsx(
310
59
  "svg",
311
60
  {
312
61
  xmlns: "http://www.w3.org/2000/svg",
@@ -318,354 +67,362 @@ function iconWinMinimize(color) {
318
67
  stroke: color ? color : "#cccccc",
319
68
  color: color ? color : "#cccccc",
320
69
  className: "size-6",
321
- children: /* @__PURE__ */ jsx4("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18 18 6M6 6l12 12" })
70
+ children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18 18 6M6 6l12 12" })
322
71
  }
323
72
  );
324
73
  }
325
74
 
326
- // src/window-manager/components/docking-controls.tsx
327
- import { useEffect as useEffect2, useState } from "react";
328
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
329
- function DockingControls({ useWindowStore }) {
330
- const {
331
- isDragging,
332
- dockWindowRight,
333
- dockWindowLeft,
334
- dockWindowBottom,
335
- dockWindowTop,
336
- dockWindowTopLeft,
337
- dockWindowBottomLeft,
338
- dockWindowTopRight,
339
- dockWindowBottomRight
340
- } = useWindowStore();
341
- const [isVisible, setIsVisible] = useState(false);
342
- const [isHovering, setIsHovering] = useState(false);
343
- useEffect2(() => {
344
- let dealy;
345
- if (isDragging) {
346
- dealy = setTimeout(() => {
347
- setIsVisible(true);
348
- }, 100);
349
- } else {
350
- setIsVisible(false);
351
- }
352
- return () => clearTimeout(dealy);
353
- }, [isDragging]);
354
- const cornerDockControl = /* @__PURE__ */ jsxs3("div", { className: `flex xl:p-0 shrink-0 gap-0.5`, children: [
355
- /* @__PURE__ */ jsxs3("div", { className: "flex flex-col justify-center gap-0.5", children: [
356
- /* @__PURE__ */ jsx5(
357
- "button",
358
- {
359
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
360
- onMouseUp: dockWindowTopLeft
361
- }
362
- ),
363
- /* @__PURE__ */ jsx5(
364
- "button",
365
- {
366
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
367
- onMouseUp: dockWindowBottomLeft
368
- }
369
- )
370
- ] }),
371
- /* @__PURE__ */ jsxs3("div", { className: "flex flex-col justify-center gap-0.5", children: [
372
- /* @__PURE__ */ jsx5(
373
- "button",
374
- {
375
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
376
- onMouseUp: dockWindowTopRight
377
- }
378
- ),
379
- /* @__PURE__ */ jsx5(
380
- "button",
381
- {
382
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
383
- onMouseUp: dockWindowBottomRight
384
- }
385
- )
386
- ] })
387
- ] });
388
- const sideDideControl = /* @__PURE__ */ jsxs3("div", { className: `flex shrink-0 items-center gap-0.5`, children: [
389
- /* @__PURE__ */ jsx5(
390
- "button",
391
- {
392
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-8 h-12 rounded-sm",
393
- onMouseUp: dockWindowLeft
394
- }
395
- ),
396
- /* @__PURE__ */ jsx5(
397
- "button",
398
- {
399
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-8 h-12 rounded-sm",
400
- onMouseUp: dockWindowRight
401
- }
402
- )
403
- ] });
404
- const horizontalDockControl = /* @__PURE__ */ jsxs3("div", { className: `flex flex-col shrink-0 items-center gap-0.5`, children: [
405
- /* @__PURE__ */ jsx5(
406
- "button",
407
- {
408
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-14 h-6 rounded-sm",
409
- onMouseUp: dockWindowTop
410
- }
411
- ),
412
- /* @__PURE__ */ jsx5(
413
- "button",
414
- {
415
- className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-14 h-6 rounded-sm",
416
- onMouseUp: dockWindowBottom
417
- }
418
- )
419
- ] });
420
- const windowDockPannel = /* @__PURE__ */ jsx5(
421
- "span",
422
- {
423
- className: "pointer-events-auto px-4 pb-4",
424
- onMouseOver: () => setIsHovering(true),
425
- onMouseLeave: () => setIsHovering(false),
426
- children: /* @__PURE__ */ jsxs3(
427
- "section",
428
- {
429
- className: `
430
- flex w-fit border border-zinc-600 border-t-0 rounded-b-md bg-zinc-800
431
- overflow-hidden px-8 gap-4 h-full py-4
432
- `,
433
- children: [
434
- cornerDockControl,
435
- horizontalDockControl,
436
- sideDideControl
437
- ]
438
- }
439
- )
440
- }
441
- );
442
- return /* @__PURE__ */ jsx5(
443
- "div",
444
- {
445
- className: `
446
- ${isVisible ? isHovering ? "top-0 opacity-50" : "top-[-68px] opacity-80" : "top-[-104px] opacity-0"}
447
- transition-all duration-500
448
- absolute z-50 flex items-center justify-center
449
- w-full mx-auto pointer-events-none`,
450
- children: windowDockPannel
451
- }
452
- );
453
- }
75
+ // src/window-manager/internal/features/cursor/cursor-state.ts
76
+ import { create } from "zustand";
77
+ var useCursorState = create((set) => ({
78
+ x: 10,
79
+ y: 10,
80
+ setX: (newX) => set({ x: newX }),
81
+ setY: (newY) => set({ y: newY })
82
+ }));
454
83
 
455
- // src/window-manager/components/resizing-controls.tsx
456
- import { useEffect as useEffect3 } from "react";
457
- import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
458
- function ResizingControls({ useWindowStore, windowRef }) {
459
- const { x, y } = useCursorState();
460
- const {
461
- windowId,
462
- setWinVisualState,
463
- winCoord,
464
- setWinCoord,
465
- isResizing,
466
- setIsResizing,
467
- winWidth,
468
- setWinWidth,
469
- winHeight,
470
- setWinHeight,
471
- WIN_MIN_WIDTH,
472
- WIN_MIN_HEIGHT
473
- } = useWindowStore();
474
- useEffect3(() => {
475
- if (!isResizing)
84
+ // src/window-manager/internal/features/resizing/resizing-controls.tsx
85
+ import { useEffect } from "react";
86
+
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
+ }));
97
+
98
+ // src/window-manager/internal/features/workspace/workspace-api.ts
99
+ var wsApi = {
100
+ getRect: () => {
101
+ const rect = useWorkspaceState.getState().ref?.getBoundingClientRect();
102
+ const top = rect?.top ?? 0;
103
+ const left = rect?.left ?? 0;
104
+ const innerHeight = rect?.height ?? 0;
105
+ const innerWidth = rect?.width ?? 0;
106
+ const bottom = top + innerHeight;
107
+ const right = left + innerWidth;
108
+ const centerX = left + innerWidth / 2;
109
+ const centerY = top + innerHeight / 2;
110
+ const wsWindow = {
111
+ top,
112
+ left,
113
+ innerHeight,
114
+ innerWidth,
115
+ bottom,
116
+ right,
117
+ centerX,
118
+ centerY
119
+ };
120
+ return wsWindow;
121
+ },
122
+ isBelowBreakPoint: () => {
123
+ const wSpace = wsApi.getRect();
124
+ const breakPoint = useWorkspaceState.getState().responsiveBreak;
125
+ return wSpace.innerWidth < responsiveBreakInPx(breakPoint);
126
+ }
127
+ };
128
+ var responsiveBreakInPx = (breakPoint) => {
129
+ switch (breakPoint) {
130
+ case "sm":
131
+ return 640;
132
+ case "md":
133
+ return 768;
134
+ case "lg":
135
+ return 1024;
136
+ case "xl":
137
+ return 1280;
138
+ case "never":
139
+ return 0;
140
+ case "always":
141
+ return Infinity;
142
+ default:
143
+ return breakPoint;
144
+ }
145
+ };
146
+
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 });
157
+ },
158
+ dispatchResizeAction: (winId) => {
159
+ const ctx = getDependencies(winId);
160
+ if (!ctx.win.resizeAction)
476
161
  return;
477
- setWinVisualState("demaximized");
478
- if (isResizing === "bottom-height")
479
- resizeBottomWinHeight();
480
- if (isResizing === "top-height")
481
- resizeTopWinHeight();
482
- if (isResizing === "right-width")
483
- resizeRightWinWidth();
484
- if (isResizing === "left-width")
485
- resizeLeftWinWidth();
486
- if (isResizing === "bottom-right-all")
487
- resizeRightBottomWidthAndHeight();
488
- if (isResizing === "bottom-left-all")
489
- resizeLeftBottomWidthAndHeight();
490
- if (isResizing === "top-right-all")
491
- resizeRightTopWidthAndHeight();
492
- if (isResizing === "top-left-all")
493
- resizeLeftTopWidthAndHeight();
494
- }, [isResizing, x, y]);
495
- const resizeRightWinWidth = () => {
496
- const winBox = windowRef.current?.getBoundingClientRect();
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
+ }
189
+ }
190
+ };
191
+ var privateApi = {
192
+ resizeRightWinWidth: (resizeCtx) => {
193
+ const { wsRect, win, winBox, x, y } = resizeCtx;
497
194
  if (!winBox)
498
195
  return;
499
- const minWinWidth = x - winBox.left < WIN_MIN_WIDTH;
196
+ const minWinWidth = x - winBox.left < win.WIN_MIN_WIDTH;
500
197
  if (minWinWidth)
501
198
  return;
502
- const cursorOutOfBounds = x > window.innerWidth || x < 0;
199
+ const cursorOutOfBounds = x > wsRect.right || x < wsRect.left;
503
200
  if (cursorOutOfBounds)
504
201
  return;
505
202
  const sizeDiff = x - winBox.right;
506
- setWinWidth(winWidth + sizeDiff);
507
- };
508
- const resizeLeftWinWidth = () => {
509
- const winBox = windowRef.current?.getBoundingClientRect();
203
+ win.setWinWidth(win.winWidth + sizeDiff);
204
+ },
205
+ resizeLeftWinWidth: (resizeCtx) => {
206
+ const { wsRect, win, winBox, x, y } = resizeCtx;
510
207
  if (!winBox)
511
208
  return;
512
- const minWinWidth = winBox.right - x <= WIN_MIN_WIDTH;
209
+ const minWinWidth = winBox.right - x <= win.WIN_MIN_WIDTH;
513
210
  if (minWinWidth)
514
211
  return;
515
- const cursorOutOfBounds = x > window.innerWidth || x < 0;
212
+ const cursorOutOfBounds = x > wsRect.right || x < wsRect.left;
516
213
  if (cursorOutOfBounds)
517
214
  return;
518
215
  const sizeDiff = winBox.left - x;
519
- setWinWidth(winWidth + sizeDiff);
520
- setWinCoord({ pointX: x, pointY: winCoord.pointY });
521
- };
522
- const resizeTopWinHeight = () => {
523
- const winBox = windowRef.current?.getBoundingClientRect();
216
+ win.setWinWidth(win.winWidth + sizeDiff);
217
+ win.setWinCoord({ pointX: x, pointY: win.winCoord.pointY });
218
+ },
219
+ resizeTopWinHeight: (resizeCtx) => {
220
+ const { wsRect, win, winBox, x, y } = resizeCtx;
524
221
  if (!winBox)
525
222
  return;
526
- const minWinHeight = winBox.bottom - y <= WIN_MIN_HEIGHT;
223
+ const minWinHeight = winBox.bottom - y <= win.WIN_MIN_HEIGHT;
527
224
  if (minWinHeight)
528
225
  return;
529
- const cursorOutOfBounds = y > window.innerHeight || y < 0;
226
+ const cursorOutOfBounds = y > wsRect.bottom || y < wsRect.top;
530
227
  if (cursorOutOfBounds)
531
228
  return;
532
229
  const sizeDiff = winBox.top - y;
533
- setWinHeight(winHeight + sizeDiff);
534
- setWinCoord({ pointX: winCoord.pointX, pointY: y });
535
- };
536
- const resizeBottomWinHeight = () => {
537
- const winBox = windowRef.current?.getBoundingClientRect();
230
+ win.setWinHeight(win.winHeight + sizeDiff);
231
+ win.setWinCoord({ pointX: win.winCoord.pointX, pointY: y });
232
+ },
233
+ resizeBottomWinHeight: (resizeCtx) => {
234
+ const { wsRect, win, winBox, x, y } = resizeCtx;
538
235
  if (!winBox)
539
236
  return;
540
- const minWinHeight = y - winBox.top < WIN_MIN_HEIGHT;
237
+ const minWinHeight = y - winBox.top < win.WIN_MIN_HEIGHT;
541
238
  if (minWinHeight)
542
239
  return;
543
- const cursorOutOfBounds = y > window.innerHeight || y < 0;
240
+ const cursorOutOfBounds = y > wsRect.bottom || y < wsRect.top;
544
241
  if (cursorOutOfBounds)
545
242
  return;
546
243
  const sizeDiff = y - winBox.bottom;
547
- setWinHeight(winHeight + sizeDiff);
548
- };
549
- const resizeRightBottomWidthAndHeight = () => {
550
- resizeRightWinWidth();
551
- resizeBottomWinHeight();
552
- };
553
- const resizeLeftBottomWidthAndHeight = () => {
554
- resizeLeftWinWidth();
555
- resizeBottomWinHeight();
556
- };
557
- const resizeRightTopWidthAndHeight = () => {
558
- resizeRightWinWidth();
559
- resizeTopWinHeight();
560
- };
561
- const resizeLeftTopWidthAndHeight = () => {
562
- const winBox = windowRef.current?.getBoundingClientRect();
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);
257
+ },
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;
563
265
  if (!winBox)
564
266
  return;
565
- const cursorOutOfBoundsY = y > window.innerHeight || y < 0;
566
- const cursorOutOfBoundsX = x > window.innerWidth || x < 0;
267
+ const cursorOutOfBoundsY = y > wsRect.bottom || y < wsRect.top;
268
+ const cursorOutOfBoundsX = x > wsRect.right || x < wsRect.left;
567
269
  if (cursorOutOfBoundsY || cursorOutOfBoundsX)
568
270
  return;
569
- const minWinHeight = winBox.bottom - y <= WIN_MIN_HEIGHT;
570
- const minWinWidth = winBox.right - x <= WIN_MIN_WIDTH;
571
- setWinCoord({
572
- pointX: minWinWidth ? winCoord.pointX : x,
573
- pointY: minWinHeight ? winCoord.pointY : y
271
+ const minWinHeight = winBox.bottom - y <= win.WIN_MIN_HEIGHT;
272
+ 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
574
276
  });
575
277
  if (!minWinHeight) {
576
278
  const sizeDiffY = winBox.top - y;
577
- setWinHeight(winHeight + sizeDiffY);
279
+ win.setWinHeight(win.winHeight + sizeDiffY);
578
280
  }
579
281
  if (!minWinWidth) {
580
282
  const sizeDiffX = winBox.left - x;
581
- setWinWidth(winWidth + sizeDiffX);
283
+ win.setWinWidth(win.winWidth + sizeDiffX);
582
284
  }
583
- };
584
- const handleResizeClick = (isResizing2) => {
585
- setIsResizing(isResizing2);
586
- setRemoteIsResizing(isResizing2);
587
- };
588
- const setRemoteIsResizing = (currentResize) => {
589
- const tolerance = 4;
590
- const allowDistantResize = getOpenedWindowCount() >= 3;
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
+ };
294
+
295
+ // src/window-manager/internal/features/stack/stack-api.ts
296
+ var stackApi = {
297
+ bringTargetWindowToFront: (targetId) => {
298
+ const targetWindow = windowRegistry[targetId].getState();
591
299
  for (const key of Object.keys(windowRegistry)) {
592
- const remoteWin = windowRegistry[key].getState();
593
- const thisWin = windowRegistry[windowId].getState();
594
- if (remoteWin.windowId === thisWin.windowId) {
300
+ const window2 = windowRegistry[key].getState();
301
+ if (window2.windowId === targetWindow.windowId) {
595
302
  continue;
596
303
  }
597
- const thisWinStartY = thisWin.winCoord.pointY;
598
- const thisWinEndY = thisWin.winCoord.pointY + thisWin.winHeight;
599
- const remoteWinStartY = remoteWin.winCoord.pointY;
600
- const remoteWinEndY = remoteWin.winCoord.pointY + remoteWin.winHeight;
601
- const thisWinStartX = thisWin.winCoord.pointX;
602
- const thisWinEndX = thisWin.winCoord.pointX + thisWin.winWidth;
603
- const remoteWinStartX = remoteWin.winCoord.pointX;
604
- const remoteWinEndX = remoteWin.winCoord.pointX + remoteWin.winWidth;
605
- const isRemoteOutside = remoteWinEndY !== thisWinEndY || remoteWinEndX !== thisWinEndX || remoteWinStartY !== thisWinStartY || remoteWinStartX !== thisWinStartX;
606
- if (currentResize === "right-width") {
607
- const isEdgeAlignedOnXAxis = Math.abs(thisWinEndX - remoteWinStartX) <= tolerance;
608
- const isOverlapOnYAxis = thisWinStartY <= remoteWinEndY && thisWinEndY >= remoteWinStartY;
609
- const isEdgeResize = allowDistantResize ? isEdgeAlignedOnXAxis : isEdgeAlignedOnXAxis && isOverlapOnYAxis;
610
- if (isEdgeResize) {
611
- remoteWin.setIsResizing("left-width");
612
- }
613
- const isRemoteOnSameLane = Math.abs(thisWinEndX - remoteWinEndX) < tolerance && Math.abs(thisWinStartX - remoteWinStartX) < tolerance;
614
- const isRemoteEdgeConnected = Math.abs(thisWinEndY - remoteWinStartY) < tolerance || Math.abs(thisWinStartY - remoteWinEndY) < tolerance;
615
- const isStackResize = allowDistantResize ? isRemoteOnSameLane && isRemoteOutside : isRemoteOnSameLane && isRemoteEdgeConnected;
616
- if (isStackResize) {
617
- remoteWin.setIsResizing("right-width");
618
- }
304
+ window2.setIsActive(false);
305
+ if (window2.zIndex >= targetWindow.zIndex) {
306
+ window2.setZIndex(window2.zIndex - 1);
619
307
  }
620
- if (currentResize === "left-width") {
621
- const isEdgeAlignedOnXAxis = Math.abs(thisWinStartX - remoteWinEndX) <= tolerance;
622
- const isOverlapOnYAxis = thisWinStartY <= remoteWinEndY && thisWinEndY >= remoteWinStartY;
623
- const isEdgeResize = allowDistantResize ? isEdgeAlignedOnXAxis : isEdgeAlignedOnXAxis && isOverlapOnYAxis;
624
- if (isEdgeResize) {
625
- remoteWin.setIsResizing("right-width");
626
- }
627
- const isRemoteOnSameLane = Math.abs(thisWinEndX - remoteWinEndX) < tolerance && Math.abs(thisWinStartX - remoteWinStartX) < tolerance;
628
- const isRemoteEdgeConnected = Math.abs(thisWinEndY - remoteWinStartY) < tolerance || Math.abs(thisWinStartY - remoteWinEndY) < tolerance;
629
- const isStackResize = allowDistantResize ? isRemoteOnSameLane && isRemoteOutside : isRemoteOnSameLane && isRemoteEdgeConnected;
630
- if (isStackResize) {
631
- remoteWin.setIsResizing("left-width");
632
- }
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
+ }
323
+ }
324
+ };
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;
333
+ const thisWin = windowRegistry[winId].getState();
334
+ const currentResize = thisWin.resizeAction;
335
+ for (const key of Object.keys(windowRegistry)) {
336
+ const remoteWin = windowRegistry[key].getState();
337
+ if (remoteWin.windowId === thisWin.windowId) {
338
+ 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;
349
+ 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");
633
355
  }
634
- if (currentResize === "top-height") {
635
- const isEdgeAlignedOnYAxis = Math.abs(thisWinStartY - remoteWinEndY) <= tolerance;
636
- const isOverlapOnXAxis = thisWinStartX <= remoteWinEndX && thisWinEndX >= remoteWinStartX;
637
- const isEdgeResize = allowDistantResize ? isEdgeAlignedOnYAxis : isEdgeAlignedOnYAxis && isOverlapOnXAxis;
638
- if (isEdgeResize) {
639
- remoteWin.setIsResizing("bottom-height");
640
- }
641
- const isRemoteOnSameLane = Math.abs(thisWinEndY - remoteWinEndY) < tolerance && Math.abs(thisWinStartY - remoteWinStartY) < tolerance;
642
- const isRemoteEdgeConnected = Math.abs(thisWinEndX - remoteWinStartX) < tolerance || Math.abs(thisWinStartX - remoteWinEndX) < tolerance;
643
- const isStackResize = allowDistantResize ? isRemoteOnSameLane && isRemoteOutside : isRemoteOnSameLane && isRemoteEdgeConnected;
644
- if (isStackResize) {
645
- remoteWin.setIsResizing("top-height");
646
- }
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");
647
361
  }
648
- if (currentResize === "bottom-height") {
649
- const isEdgeAlignedOnYAxis = Math.abs(thisWinEndY - remoteWinStartY) <= tolerance;
650
- const isOverlapOnXAxis = thisWinStartX <= remoteWinEndX && thisWinEndX >= remoteWinStartX;
651
- const isEdgeResize = allowDistantResize ? isEdgeAlignedOnYAxis : isEdgeAlignedOnYAxis && isOverlapOnXAxis;
652
- if (isEdgeResize) {
653
- remoteWin.setIsResizing("top-height");
654
- }
655
- const isRemoteOnSameLane = Math.abs(thisWinEndY - remoteWinEndY) < tolerance && Math.abs(thisWinStartY - remoteWinStartY) < tolerance;
656
- const isRemoteEdgeConnected = Math.abs(thisWinEndX - remoteWinStartX) < tolerance || Math.abs(thisWinStartX - remoteWinEndX) < tolerance;
657
- const isStackResize = allowDistantResize ? isRemoteOnSameLane && isRemoteOutside : isRemoteOnSameLane && isRemoteEdgeConnected;
658
- if (isStackResize) {
659
- remoteWin.setIsResizing("bottom-height");
660
- }
362
+ }
363
+ 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
+ }
376
+ }
377
+ 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");
661
389
  }
662
390
  }
391
+ 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
+ }
404
+ }
405
+ }
406
+ };
407
+
408
+ // src/window-manager/internal/features/resizing/resizing-controls.tsx
409
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
410
+ function ResizingControls({ winId }) {
411
+ const { x, y } = useCursorState();
412
+ 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);
663
419
  };
664
- return /* @__PURE__ */ jsxs4(Fragment2, { children: [
665
- /* @__PURE__ */ jsx6(
420
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
421
+ /* @__PURE__ */ jsx2(
666
422
  "span",
667
423
  {
668
- onMouseDown: () => handleResizeClick("right-width"),
424
+ onMouseUp: () => handleResizeClick(false),
425
+ onMouseDown: () => handleResizeClick("e"),
669
426
  id: "win-resize-right-width",
670
427
  className: "fixed w-2 opacity-60 cursor-w-resize z-10",
671
428
  style: {
@@ -675,10 +432,11 @@ function ResizingControls({ useWindowStore, windowRef }) {
675
432
  }
676
433
  }
677
434
  ),
678
- /* @__PURE__ */ jsx6(
435
+ /* @__PURE__ */ jsx2(
679
436
  "span",
680
437
  {
681
- onMouseDown: () => handleResizeClick("left-width"),
438
+ onMouseUp: () => handleResizeClick(false),
439
+ onMouseDown: () => handleResizeClick("w"),
682
440
  id: "win-resize-left-width",
683
441
  className: "fixed w-2 opacity-60 cursor-w-resize z-10",
684
442
  style: {
@@ -688,10 +446,11 @@ function ResizingControls({ useWindowStore, windowRef }) {
688
446
  }
689
447
  }
690
448
  ),
691
- /* @__PURE__ */ jsx6(
449
+ /* @__PURE__ */ jsx2(
692
450
  "span",
693
451
  {
694
- onMouseDown: () => handleResizeClick("bottom-height"),
452
+ onMouseUp: () => handleResizeClick(false),
453
+ onMouseDown: () => handleResizeClick("s"),
695
454
  id: "win-resize-bottom-height",
696
455
  className: "fixed h-2 opacity-60 cursor-s-resize z-10",
697
456
  style: {
@@ -701,10 +460,11 @@ function ResizingControls({ useWindowStore, windowRef }) {
701
460
  }
702
461
  }
703
462
  ),
704
- /* @__PURE__ */ jsx6(
463
+ /* @__PURE__ */ jsx2(
705
464
  "span",
706
465
  {
707
- onMouseDown: () => handleResizeClick("top-height"),
466
+ onMouseUp: () => handleResizeClick(false),
467
+ onMouseDown: () => handleResizeClick("n"),
708
468
  id: "win-resize-top-height",
709
469
  className: "fixed h-2 opacity-60 cursor-s-resize z-10",
710
470
  style: {
@@ -714,10 +474,11 @@ function ResizingControls({ useWindowStore, windowRef }) {
714
474
  }
715
475
  }
716
476
  ),
717
- /* @__PURE__ */ jsx6(
477
+ /* @__PURE__ */ jsx2(
718
478
  "span",
719
479
  {
720
- onMouseDown: () => handleResizeClick("bottom-right-all"),
480
+ onMouseUp: () => handleResizeClick(false),
481
+ onMouseDown: () => handleResizeClick("se"),
721
482
  id: "win-resize-bottom-right-all",
722
483
  className: "fixed h-3 w-3 opacity-60 cursor-se-resize z-20",
723
484
  style: {
@@ -726,10 +487,11 @@ function ResizingControls({ useWindowStore, windowRef }) {
726
487
  }
727
488
  }
728
489
  ),
729
- /* @__PURE__ */ jsx6(
490
+ /* @__PURE__ */ jsx2(
730
491
  "span",
731
492
  {
732
- onMouseDown: () => handleResizeClick("bottom-left-all"),
493
+ onMouseUp: () => handleResizeClick(false),
494
+ onMouseDown: () => handleResizeClick("sw"),
733
495
  id: "win-resize-bottom-left-all",
734
496
  className: "fixed h-3 w-3 opacity-60 cursor-sw-resize z-20",
735
497
  style: {
@@ -738,10 +500,11 @@ function ResizingControls({ useWindowStore, windowRef }) {
738
500
  }
739
501
  }
740
502
  ),
741
- /* @__PURE__ */ jsx6(
503
+ /* @__PURE__ */ jsx2(
742
504
  "span",
743
505
  {
744
- onMouseDown: () => handleResizeClick("top-right-all"),
506
+ onMouseUp: () => handleResizeClick(false),
507
+ onMouseDown: () => handleResizeClick("ne"),
745
508
  id: "win-resize-top-right-all",
746
509
  className: "fixed h-3 w-3 opacity-60 cursor-ne-resize z-20",
747
510
  style: {
@@ -750,10 +513,11 @@ function ResizingControls({ useWindowStore, windowRef }) {
750
513
  }
751
514
  }
752
515
  ),
753
- /* @__PURE__ */ jsx6(
516
+ /* @__PURE__ */ jsx2(
754
517
  "span",
755
518
  {
756
- onMouseDown: () => handleResizeClick("top-left-all"),
519
+ onMouseUp: () => handleResizeClick(false),
520
+ onMouseDown: () => handleResizeClick("nw"),
757
521
  id: "win-resize-top-left-all",
758
522
  className: "fixed h-3 w-3 opacity-60 cursor-nw-resize z-20",
759
523
  style: {
@@ -765,18 +529,57 @@ function ResizingControls({ useWindowStore, windowRef }) {
765
529
  ] });
766
530
  }
767
531
 
768
- // src/window-manager/window-layout.tsx
769
- import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
532
+ // 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";
535
+ 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(
563
+ "div",
564
+ {
565
+ onMouseDown: () => startDrag(true),
566
+ onMouseUp: () => startDrag(false),
567
+ 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"
569
+ }
570
+ );
571
+ }
572
+
573
+ // src/window-manager/internal/features/window-layout.tsx
574
+ import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
770
575
  function WindowLayout({
771
- responsiveBreak = "lg",
772
576
  children,
773
577
  windowName,
774
578
  navbarChildren,
775
- useWindowStore,
776
- defaultDock,
579
+ winId,
580
+ defaultDock = "default",
777
581
  style
778
582
  }) {
779
- const { x, y } = useCursorState();
780
583
  const windowRef = useRef(null);
781
584
  const {
782
585
  windowId,
@@ -785,107 +588,62 @@ function WindowLayout({
785
588
  setSelf,
786
589
  resetFlag,
787
590
  winVisualState,
788
- isWinMinimized,
789
- dragClickOffset,
790
- setDragClickOffset,
791
- isDragging,
792
- setIsDragging,
591
+ isWindowClosed,
793
592
  winCoord,
794
- setWinCoord,
795
- setIsResizing,
796
593
  winWidth,
797
- winHeight,
798
- minimizeWindow,
799
- maximizeWindow,
800
- demaximizeWindow,
801
- dockWindowRight,
802
- dockWindowLeft
803
- } = useWindowStore();
804
- useEffect4(() => {
594
+ winHeight
595
+ } = windowRegistry[winId]();
596
+ useEffect3(() => {
805
597
  setSelf(windowRef);
806
- if (isMobile())
807
- maximizeWindow();
808
- else if (defaultDock === "left")
809
- dockWindowLeft();
810
- else if (defaultDock === "right")
811
- dockWindowRight();
812
- else if (defaultDock === "full")
813
- maximizeWindow();
814
- else
815
- demaximizeWindow();
816
- }, [setSelf, windowRef, resetFlag]);
817
- useEffect4(() => {
818
- if (isMobile())
819
- return;
820
- if (!isDragging)
598
+ if (wsApi.isBelowBreakPoint()) {
599
+ dockApi.maximizeWindow(winId);
821
600
  return;
822
- if (winVisualState === "maximized")
823
- demaximizeWindow();
824
- let adjustedX = x - dragClickOffset.pointX;
825
- if (x > window.innerWidth || x < 0)
826
- adjustedX = winCoord.pointX;
827
- let adjustedY = y - dragClickOffset.pointY;
828
- if (y > window.innerHeight || y < 0)
829
- adjustedY = winCoord.pointY;
830
- setWinCoord({ pointX: adjustedX, pointY: adjustedY });
831
- }, [isDragging, x, y]);
832
- const responsiveBreakInPx = (breakPoint) => {
833
- switch (breakPoint) {
834
- case "sm":
835
- return 640;
836
- case "md":
837
- return 768;
838
- case "lg":
839
- return 1024;
840
- case "xl":
841
- return 1280;
842
- case "never":
843
- return 0;
844
- case "always":
845
- return Infinity;
846
- default:
847
- return breakPoint;
848
601
  }
602
+ dockingRoutes[defaultDock](winId);
603
+ }, [setSelf, windowRef, resetFlag]);
604
+ const dockingRoutes = {
605
+ right: dockApi.dockWindowRight,
606
+ left: dockApi.dockWindowLeft,
607
+ full: dockApi.maximizeWindow,
608
+ top: dockApi.dockWindowTop,
609
+ bottom: dockApi.dockWindowBottom,
610
+ "top-right": dockApi.dockWindowTopRight,
611
+ "top-left": dockApi.dockWindowTopLeft,
612
+ "bottom-right": dockApi.dockWindowBottomRight,
613
+ "bottom-left": dockApi.dockWindowBottomLeft,
614
+ default: dockApi.demaximizeWindow
849
615
  };
850
- const handleNavbarClick = (isDragging2) => {
851
- setDragClickOffset({ pointX: x - winCoord.pointX, pointY: y - winCoord.pointY });
852
- setIsDragging(isDragging2);
853
- };
854
- const isMobile = () => {
855
- return window.innerWidth < responsiveBreakInPx(responsiveBreak);
856
- };
857
- const handleResizeClick = (isResizing) => {
858
- setIsResizing(isResizing);
859
- };
860
- const maximizeControl = winVisualState === "maximized" ? /* @__PURE__ */ jsx7(
616
+ const maximizeControl = winVisualState === "maximized" ? /* @__PURE__ */ jsx4(
617
+ "button",
618
+ {
619
+ className: `block hover:bg-gray-500 hover:bg-opacity-10 px-5 h-full`,
620
+ onClick: () => dockApi.demaximizeWindow(winId),
621
+ children: /* @__PURE__ */ jsx4(IconWinDemaximize, { color: style?.navControlsColor })
622
+ }
623
+ ) : /* @__PURE__ */ jsx4(
861
624
  "button",
862
625
  {
863
- className: `block hover:bg-gray-100 hover:bg-opacity-20 px-5 h-full`,
864
- onClick: demaximizeWindow,
865
- children: iconWinDemaximize(style?.navControlsColor)
626
+ className: `block hover:bg-gray-500 hover:bg-opacity-10 px-5 h-full`,
627
+ onClick: () => dockApi.maximizeWindow(winId),
628
+ children: /* @__PURE__ */ jsx4(IconWinMaximize, { color: style?.navControlsColor })
866
629
  }
867
- ) : /* @__PURE__ */ jsx7(
630
+ );
631
+ const closeControl = /* @__PURE__ */ jsx4(
868
632
  "button",
869
633
  {
870
- className: `block hover:bg-gray-100 hover:bg-opacity-20 px-5 h-full`,
871
- onClick: maximizeWindow,
872
- children: iconWinMaximize(style?.navControlsColor)
634
+ className: "hover:bg-red-500 hover:bg-opacity-20 px-5 h-full",
635
+ onClick: () => dockApi.closeWindow(winId),
636
+ children: /* @__PURE__ */ jsx4(IconWinMinimize, { color: style?.navControlsColor })
873
637
  }
874
638
  );
875
- const minimizeControl = /* @__PURE__ */ jsx7("button", { className: "hover:bg-red-500 hover:bg-opacity-20 px-5 h-full", onClick: minimizeWindow, children: iconWinMinimize(style?.navControlsColor) });
876
- return /* @__PURE__ */ jsxs5(Fragment3, { children: [
877
- !isMobile() && /* @__PURE__ */ jsx7(DockingControls, { useWindowStore }),
878
- /* @__PURE__ */ jsxs5(
639
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
640
+ /* @__PURE__ */ jsxs2(
879
641
  "div",
880
642
  {
881
643
  id: windowId,
882
644
  ref: windowRef,
883
645
  className: `fixed bg-white shadow-lg border border-zinc-600 rounded-sm overflow-hidden`,
884
- onMouseDown: () => bringTargetWindowToFront(windowId),
885
- onMouseUp: () => {
886
- handleNavbarClick(false);
887
- handleResizeClick(false);
888
- },
646
+ onMouseDown: () => stackApi.bringTargetWindowToFront(windowId),
889
647
  style: {
890
648
  backgroundColor: style?.windowBackgroundColor,
891
649
  top: `${winCoord.pointY}px`,
@@ -895,12 +653,12 @@ function WindowLayout({
895
653
  zIndex: `${zIndex}`,
896
654
  /* MINIMIZE LOGIC */
897
655
  transition: "transform 0.2s ease-in-out, opacity 0.3s ease-in-out",
898
- opacity: isWinMinimized ? 0 : 1,
899
- transform: isWinMinimized ? `translate(${window.innerWidth / 2 - winCoord.pointX - winWidth / 2}px,
900
- ${window.innerHeight - winCoord.pointY - winHeight / 2}px) scale(0.02)` : ""
656
+ opacity: isWindowClosed ? 0 : 1,
657
+ transform: isWindowClosed ? `translate(${wsApi.getRect().innerWidth / 2 - winCoord.pointX - winWidth / 2}px,
658
+ ${wsApi.getRect().innerHeight - winCoord.pointY - winHeight / 2}px) scale(0.02)` : ""
901
659
  },
902
660
  children: [
903
- /* @__PURE__ */ jsxs5(
661
+ /* @__PURE__ */ jsxs2(
904
662
  "nav",
905
663
  {
906
664
  style: {
@@ -910,34 +668,385 @@ function WindowLayout({
910
668
  h-[32px] w-full flex items-center bg-neutral-800
911
669
  ${isActive ? "brightness-100 opacity-100" : "brightness-75 opacity-80"}`,
912
670
  children: [
913
- /* @__PURE__ */ jsx7("div", { className: "w-fit shrink-0 h-8 px-2 text-white flex items-center text-sm truncate", children: windowName }),
914
- /* @__PURE__ */ jsx7("div", { className: "h-8 px-2 text-white flex items-center text-sm truncate", children: navbarChildren }),
915
- /* @__PURE__ */ jsx7(
916
- "div",
917
- {
918
- onMouseDown: () => handleNavbarClick(true),
919
- onDoubleClick: maximizeWindow,
920
- className: "grow min-w-8 h-8 px-2 text-white flex items-center text-sm"
921
- }
922
- ),
923
- !isMobile() && maximizeControl,
924
- minimizeControl
671
+ /* @__PURE__ */ jsx4("div", { className: "w-fit shrink-0 h-8 px-2 text-white flex items-center text-sm truncate", children: windowName }),
672
+ /* @__PURE__ */ jsx4("div", { className: "h-8 px-2 text-white flex items-center text-sm truncate", children: navbarChildren }),
673
+ /* @__PURE__ */ jsx4(DragHandle, { winId }),
674
+ !wsApi.isBelowBreakPoint() && maximizeControl,
675
+ closeControl
925
676
  ]
926
677
  }
927
678
  ),
928
- !isMobile() && /* @__PURE__ */ jsx7(ResizingControls, { useWindowStore, windowRef }),
929
- /* @__PURE__ */ jsx7("div", { className: `relative w-full h-[calc(100%-32px)] overflow-auto`, children })
679
+ !wsApi.isBelowBreakPoint() && /* @__PURE__ */ jsx4(ResizingControls, { winId }),
680
+ /* @__PURE__ */ jsx4("div", { className: `relative w-full h-[calc(100%-32px)] overflow-auto`, children })
930
681
  ]
931
682
  }
932
683
  ),
933
684
  " "
934
685
  ] });
935
686
  }
687
+
688
+ // src/window-manager/internal/features/window-button.tsx
689
+ import { jsx as jsx5 } from "react/jsx-runtime";
690
+ function WindowButton({
691
+ children,
692
+ winId,
693
+ className,
694
+ isClosedClassName = "brightness-[85%]",
695
+ isOpenClassName = "brightness-150"
696
+ }) {
697
+ const { isWindowClosed, windowId, isActive } = windowRegistry[winId]();
698
+ const handleOpenCloseWin = () => {
699
+ if (isWindowClosed) {
700
+ stackApi.bringTargetWindowToFront(windowId);
701
+ dockApi.openWindow(winId);
702
+ return;
703
+ }
704
+ if (isActive)
705
+ dockApi.closeWindow(winId);
706
+ stackApi.bringTargetWindowToFront(windowId);
707
+ };
708
+ return /* @__PURE__ */ jsx5(
709
+ "button",
710
+ {
711
+ id: `${windowId}_button`,
712
+ onClick: handleOpenCloseWin,
713
+ className: `
714
+ ${className}
715
+ ${isWindowClosed ? isClosedClassName : isOpenClassName}`,
716
+ children
717
+ }
718
+ );
719
+ }
720
+
721
+ // src/window-manager/registration/window-store-factory.tsx
722
+ import { jsx as jsx6 } from "react/jsx-runtime";
723
+ var windownMinWidth = 232;
724
+ var windownMinHeight = 128;
725
+ var windowRegistry = {};
726
+ var createWindowStore = () => {
727
+ const zIndexAtLaunch = Object.keys(windowRegistry).length + 1;
728
+ const windowInstanceId = `react-dynamic-window-instance${Object.keys(windowRegistry).length}`;
729
+ const storeInstance = create3((set, get) => ({
730
+ windowId: windowInstanceId,
731
+ self: void 0,
732
+ setSelf: (ref) => set({ self: ref }),
733
+ WIN_MIN_WIDTH: windownMinWidth,
734
+ setWIN_MIN_WIDTH: (w) => set({ WIN_MIN_WIDTH: w }),
735
+ WIN_MIN_HEIGHT: windownMinHeight,
736
+ setWIN_MIN_HEIGHT: (h) => set({ WIN_MIN_HEIGHT: h }),
737
+ isActive: false,
738
+ setIsActive: (isActive) => {
739
+ useWorkspaceState.getState().setActiveWindowId(get().windowId);
740
+ set({ isActive });
741
+ },
742
+ resetFlag: false,
743
+ reset: () => set({ resetFlag: !get().resetFlag, isWindowClosed: true }),
744
+ zIndex: zIndexAtLaunch,
745
+ setZIndex: (newIndex) => set({ zIndex: newIndex }),
746
+ winVisualState: "demaximized",
747
+ setWinVisualState: (newState) => set({ winVisualState: newState }),
748
+ isWindowClosed: true,
749
+ setisWindowClosed: (isClosed) => set({ isWindowClosed: isClosed }),
750
+ winCoord: { pointX: 40, pointY: 40 },
751
+ setWinCoord: (newWinCoord) => set({ winCoord: { pointX: newWinCoord.pointX, pointY: newWinCoord.pointY } }),
752
+ winWidth: windownMinWidth,
753
+ setWinWidth: (newWinWidth) => set({ winWidth: newWinWidth }),
754
+ winHeight: windownMinHeight,
755
+ setWinHeight: (newWinHeight) => set({ winHeight: newWinHeight }),
756
+ resizeAction: false,
757
+ setResizeAction: (updatedIsResizing) => set({ resizeAction: updatedIsResizing }),
758
+ isDragging: false,
759
+ setIsDragging: (updatedIsDragging) => set({ isDragging: updatedIsDragging })
760
+ }));
761
+ windowRegistry[windowInstanceId] = storeInstance;
762
+ return {
763
+ id: storeInstance.getState().windowId,
764
+ store: storeInstance,
765
+ Window: (props) => /* @__PURE__ */ jsx6(WindowLayout, { ...props, winId: windowInstanceId }),
766
+ Button: (props) => /* @__PURE__ */ jsx6(WindowButton, { ...props, winId: windowInstanceId })
767
+ };
768
+ };
769
+
770
+ // src/window-manager/internal/features/docking/docking-api.ts
771
+ var dockApi = {
772
+ dockWindowRight: (winId) => {
773
+ windowRegistry[winId].setState({
774
+ winCoord: { pointX: wsApi.getRect().centerX, pointY: wsApi.getRect().top },
775
+ winWidth: wsApi.getRect().innerWidth / 2,
776
+ winHeight: wsApi.getRect().innerHeight,
777
+ winVisualState: "demaximized"
778
+ });
779
+ },
780
+ dockWindowLeft: (winId) => {
781
+ windowRegistry[winId].setState({
782
+ winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().top },
783
+ winWidth: wsApi.getRect().innerWidth / 2,
784
+ winHeight: wsApi.getRect().innerHeight,
785
+ winVisualState: "demaximized"
786
+ });
787
+ },
788
+ dockWindowTop: (winId) => {
789
+ windowRegistry[winId].setState({
790
+ winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().top },
791
+ winWidth: wsApi.getRect().innerWidth,
792
+ winHeight: wsApi.getRect().innerHeight / 2,
793
+ winVisualState: "demaximized"
794
+ });
795
+ },
796
+ dockWindowBottom: (winId) => {
797
+ windowRegistry[winId].setState({
798
+ winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().centerY },
799
+ winWidth: wsApi.getRect().innerWidth,
800
+ winHeight: wsApi.getRect().innerHeight / 2,
801
+ winVisualState: "demaximized"
802
+ });
803
+ },
804
+ dockWindowBottomRight: (winId) => {
805
+ windowRegistry[winId].setState({
806
+ winCoord: {
807
+ pointX: wsApi.getRect().centerX,
808
+ pointY: wsApi.getRect().centerY
809
+ },
810
+ winWidth: wsApi.getRect().innerWidth / 2,
811
+ winHeight: wsApi.getRect().innerHeight / 2,
812
+ winVisualState: "demaximized"
813
+ });
814
+ },
815
+ dockWindowTopRight: (winId) => {
816
+ windowRegistry[winId].setState({
817
+ winCoord: { pointX: wsApi.getRect().centerX, pointY: wsApi.getRect().top },
818
+ winWidth: wsApi.getRect().innerWidth / 2,
819
+ winHeight: wsApi.getRect().innerHeight / 2,
820
+ winVisualState: "demaximized"
821
+ });
822
+ },
823
+ dockWindowBottomLeft: (winId) => {
824
+ windowRegistry[winId].setState({
825
+ winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().centerY },
826
+ winWidth: wsApi.getRect().innerWidth / 2,
827
+ winHeight: wsApi.getRect().innerHeight / 2,
828
+ winVisualState: "demaximized"
829
+ });
830
+ },
831
+ dockWindowTopLeft: (winId) => {
832
+ windowRegistry[winId].setState({
833
+ winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().top },
834
+ winWidth: wsApi.getRect().innerWidth / 2,
835
+ winHeight: wsApi.getRect().innerHeight / 2,
836
+ winVisualState: "demaximized"
837
+ });
838
+ },
839
+ maximizeWindow: (winId) => {
840
+ windowRegistry[winId].setState({
841
+ winCoord: { pointX: wsApi.getRect().left, pointY: wsApi.getRect().top },
842
+ winHeight: wsApi.getRect().innerHeight,
843
+ winWidth: wsApi.getRect().innerWidth,
844
+ winVisualState: "maximized"
845
+ });
846
+ },
847
+ demaximizeWindow: (winId) => {
848
+ windowRegistry[winId].setState({
849
+ winCoord: { pointX: wsApi.getRect().left + 16, pointY: wsApi.getRect().top + 16 },
850
+ winWidth: wsApi.getRect().innerWidth * 0.95,
851
+ winHeight: wsApi.getRect().innerHeight * 0.75,
852
+ winVisualState: "demaximized"
853
+ });
854
+ },
855
+ closeWindow: (winId) => {
856
+ windowRegistry[winId].setState({ isWindowClosed: true });
857
+ },
858
+ openWindow: (winId) => {
859
+ const winState = windowRegistry[winId].getState();
860
+ const winRef = winState.self;
861
+ if (winState.isWindowClosed && winRef?.current) {
862
+ windowRegistry[winId].setState({ isWindowClosed: false });
863
+ winRef.current.style.transform = "translate(0, 0) scale(1)";
864
+ }
865
+ }
866
+ };
867
+
868
+ // src/window-manager/rwm.ts
869
+ var rwm = {
870
+ dockApi,
871
+ resizeApi,
872
+ stackApi,
873
+ workspaceApi: wsApi,
874
+ worskpaceState: useWorkspaceState
875
+ };
876
+ var rwm_default = rwm;
877
+
878
+ // src/window-manager/workspace-layout.tsx
879
+ import { useEffect as useEffect6, useRef as useRef2 } from "react";
880
+
881
+ // src/window-manager/internal/features/docking/docking-controls.tsx
882
+ import { useState as useState2 } from "react";
883
+ import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
884
+ function DockingControls() {
885
+ const [isHovering, setIsHovering] = useState2(false);
886
+ const { activeWindowId } = useWorkspaceState();
887
+ const { isDragging } = windowRegistry[activeWindowId]();
888
+ const cornerDockControl = /* @__PURE__ */ jsxs3("div", { className: `flex xl:p-0 shrink-0 gap-0.5`, children: [
889
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-col justify-center gap-0.5", children: [
890
+ /* @__PURE__ */ jsx7(
891
+ "button",
892
+ {
893
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
894
+ onMouseUp: () => dockApi.dockWindowTopLeft(activeWindowId)
895
+ }
896
+ ),
897
+ /* @__PURE__ */ jsx7(
898
+ "button",
899
+ {
900
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
901
+ onMouseUp: () => dockApi.dockWindowBottomLeft(activeWindowId)
902
+ }
903
+ )
904
+ ] }),
905
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-col justify-center gap-0.5", children: [
906
+ /* @__PURE__ */ jsx7(
907
+ "button",
908
+ {
909
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
910
+ onMouseUp: () => dockApi.dockWindowTopRight(activeWindowId)
911
+ }
912
+ ),
913
+ /* @__PURE__ */ jsx7(
914
+ "button",
915
+ {
916
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-10 h-6 rounded-sm",
917
+ onMouseUp: () => dockApi.dockWindowBottomRight(activeWindowId)
918
+ }
919
+ )
920
+ ] })
921
+ ] });
922
+ const sideDideControl = /* @__PURE__ */ jsxs3("div", { className: `flex shrink-0 items-center gap-0.5`, children: [
923
+ /* @__PURE__ */ jsx7(
924
+ "button",
925
+ {
926
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-8 h-12 rounded-sm",
927
+ onMouseUp: () => dockApi.dockWindowLeft(activeWindowId)
928
+ }
929
+ ),
930
+ /* @__PURE__ */ jsx7(
931
+ "button",
932
+ {
933
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-8 h-12 rounded-sm",
934
+ onMouseUp: () => dockApi.dockWindowRight(activeWindowId)
935
+ }
936
+ )
937
+ ] });
938
+ const horizontalDockControl = /* @__PURE__ */ jsxs3("div", { className: `flex flex-col shrink-0 items-center gap-0.5`, children: [
939
+ /* @__PURE__ */ jsx7(
940
+ "button",
941
+ {
942
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-14 h-6 rounded-sm",
943
+ onMouseUp: () => dockApi.dockWindowTop(activeWindowId)
944
+ }
945
+ ),
946
+ /* @__PURE__ */ jsx7(
947
+ "button",
948
+ {
949
+ className: "hover:bg-zinc-300 border border-zinc-500 bg-zinc-600 w-14 h-6 rounded-sm",
950
+ onMouseUp: () => dockApi.dockWindowBottom(activeWindowId)
951
+ }
952
+ )
953
+ ] });
954
+ const windowDockPannel = /* @__PURE__ */ jsx7(
955
+ "span",
956
+ {
957
+ className: "pointer-events-auto px-4 pb-2",
958
+ onMouseOver: () => setIsHovering(true),
959
+ onMouseLeave: () => setIsHovering(false),
960
+ children: /* @__PURE__ */ jsxs3(
961
+ "section",
962
+ {
963
+ className: `
964
+ flex w-fit border border-zinc-600 border-t-0 rounded-b-md bg-zinc-800
965
+ overflow-hidden px-8 gap-4 h-full py-4
966
+ `,
967
+ children: [
968
+ cornerDockControl,
969
+ horizontalDockControl,
970
+ sideDideControl
971
+ ]
972
+ }
973
+ )
974
+ }
975
+ );
976
+ return /* @__PURE__ */ jsx7(
977
+ "div",
978
+ {
979
+ className: `
980
+ ${isDragging ? isHovering ? "top-0 opacity-50" : "top-[-68px] opacity-80" : "top-[-104px] opacity-0"}
981
+ transition-all duration-500
982
+ absolute z-50 flex items-center justify-center
983
+ w-full mx-auto pointer-events-none`,
984
+ children: windowDockPannel
985
+ }
986
+ );
987
+ }
988
+
989
+ // src/window-manager/internal/features/cursor/cursor-move-listener.tsx
990
+ import { useEffect as useEffect4 } from "react";
991
+ import { Fragment as Fragment3, jsx as jsx8 } from "react/jsx-runtime";
992
+ function CursorMoveListener() {
993
+ const { setX, setY } = useCursorState();
994
+ useEffect4(() => {
995
+ const handleWindowPosition = (e) => {
996
+ e.preventDefault();
997
+ setX(e.clientX);
998
+ setY(e.clientY);
999
+ };
1000
+ window.addEventListener("pointermove", handleWindowPosition);
1001
+ return () => window.removeEventListener("pointermove", handleWindowPosition);
1002
+ }, [setX, setY]);
1003
+ return /* @__PURE__ */ jsx8(Fragment3, {});
1004
+ }
1005
+
1006
+ // src/window-manager/internal/features/view-port/view-port-resize-listener.tsx
1007
+ import { useEffect as useEffect5 } from "react";
1008
+ import { Fragment as Fragment4, jsx as jsx9 } from "react/jsx-runtime";
1009
+ function ViewPortResizeListener() {
1010
+ useEffect5(() => {
1011
+ window.addEventListener("resize", stackApi.resetStack);
1012
+ return () => window.removeEventListener("resize", stackApi.resetStack);
1013
+ }, []);
1014
+ return /* @__PURE__ */ jsx9(Fragment4, {});
1015
+ }
1016
+
1017
+ // src/window-manager/workspace-layout.tsx
1018
+ import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
1019
+ function WorkspaceLayout({ children, className, responsiveBreak = "sm" }) {
1020
+ const workspaceRef = useRef2(null);
1021
+ const { setRef, setResponsiveBreak } = useWorkspaceState();
1022
+ useEffect6(() => {
1023
+ setRef(workspaceRef.current);
1024
+ }, []);
1025
+ useEffect6(() => {
1026
+ setResponsiveBreak(responsiveBreak);
1027
+ }, [responsiveBreak]);
1028
+ return /* @__PURE__ */ jsxs4(
1029
+ "section",
1030
+ {
1031
+ ref: workspaceRef,
1032
+ onMouseLeave: resizeApi.stopAllDragAndResize,
1033
+ onMouseUp: resizeApi.stopAllDragAndResize,
1034
+ className: className ? className : "fixed overflow-hidden h-full w-full touch-none",
1035
+ children: [
1036
+ /* @__PURE__ */ jsx10(ViewPortResizeListener, {}),
1037
+ /* @__PURE__ */ jsx10(CursorMoveListener, {}),
1038
+ /* @__PURE__ */ jsxs4("div", { className: " w-full h-full relative overflow-hidden", children: [
1039
+ !wsApi.isBelowBreakPoint() && /* @__PURE__ */ jsx10(DockingControls, {}),
1040
+ children
1041
+ ] })
1042
+ ]
1043
+ }
1044
+ );
1045
+ }
936
1046
  export {
937
- WindowButton,
938
- WindowLayout,
939
1047
  WorkspaceLayout,
940
1048
  createWindowStore,
1049
+ rwm_default as rwm,
941
1050
  windowRegistry
942
1051
  };
943
1052
  //# sourceMappingURL=index.js.map