-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlayout_config.ts
More file actions
118 lines (108 loc) · 4.21 KB
/
layout_config.ts
File metadata and controls
118 lines (108 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░░░▄▀░█▀▄░█▀▀░█▀▀░█░█░█░░░█▀█░█▀▄░░░░░█░░░█▀█░█░█░█▀█░█░█░▀█▀░▀▄░░░░░░░░
// ░░░░░░░▀▄░░█▀▄░█▀▀░█░█░█░█░█░░░█▀█░█▀▄░▀▀▀░█░░░█▀█░░█░░█░█░█░█░░█░░░▄▀░░░░░░░
// ░░░░░░░░░▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀░▀░▀░▀░░░░░▀▀▀░▀░▀░░▀░░▀▀▀░▀▀▀░░▀░░▀░░░░░░░░░
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ * Copyright (c) 2026, the Regular Layout Authors. This file is part * ┃
// ┃ * of the Regular Layout library, distributed under the terms of the * ┃
// ┃ * [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). * ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
/**
* The overlay behavior type.
*/
export type OverlayMode = "grid" | "absolute";
/**
* The representation of a CSS grid, in JSON form.
*/
export type Layout = SplitLayout | TabLayout;
/**
* The orientation (of a `SplitPanel`).
*/
export type Orientation = "horizontal" | "vertical";
/**
* A logical rectange in percent-coordinates (of a (1, 1) square).
*/
export interface ViewWindow {
row_start: number;
row_end: number;
col_start: number;
col_end: number;
}
/**
* A split panel that divides space among multiple child layouts
* .
* Child panels are arranged either horizontally (side by side) or vertically
* (stacked), via the `orientation` property `"horizzontal"` and `"vertical"`
* (respectively).
*/
export interface SplitLayout {
type: "split-panel";
children: Layout[];
sizes: number[];
orientation: Orientation;
}
/**
* A leaf panel node that contains a single named child element.
*/
export interface TabLayout {
type: "child-panel";
child: string[];
selected?: number;
}
/**
* Represents a draggable divider between two panels in the layout.
*
* Used for hit detection.
*/
export interface LayoutDivider {
path: number[];
view_window: ViewWindow;
type: Orientation;
}
/**
* Represents a panel location result from hit detection.
*
* Contains both the panel identifier and its grid position in relative units.
* The generic parameter `T` allows DOM-only properties (e.g. `DOMRect`) to be
* shared in this cross-platform module.
*/
export interface LayoutPath<T = undefined> {
type: "layout-path";
slot: string;
panel: TabLayout;
path: number[];
view_window: ViewWindow;
column: number;
row: number;
column_offset: number;
row_offset: number;
orientation: Orientation;
is_edge: boolean;
box: T;
}
/**
* Recursively iterates over all child panel names in the layout tree, yielding
* panel names in depth-first order.
*
* @param panel - The layout tree to iterate over
* @returns Generator yielding child panel names
*/
export function* iter_panel_children(panel: Layout): Generator<string> {
if (panel.type === "split-panel") {
for (const child of panel.children) {
yield* iter_panel_children(child);
}
} else {
yield panel.child[panel.selected || 0];
}
}
/**
* An empty `Layout` with no panels.
*/
export const EMPTY_PANEL: Layout = {
type: "split-panel",
orientation: "horizontal",
sizes: [],
children: [],
};