ozdenui 0.1.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.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Splitter - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT
|
|
8
|
+
- Two areas with a line between them: a drag of the line changes their sizes (a list of files and the content).
|
|
9
|
+
- direction: "horizontal" (side by side, default), "vertical" (one under the other).
|
|
10
|
+
- firstSize: the size of the first area: px (240), or a part of the box ("30%"). A part stays a part when the box
|
|
11
|
+
changes, px stay px. secondSize (px or a part) instead: the second area keeps its size (an output under the content).
|
|
12
|
+
- minFirst, minSecond: the areas do not get smaller than this (px), also when the box gets smaller.
|
|
13
|
+
- box.first and box.second are groups, one object under the other: objects go into them with createIn().
|
|
14
|
+
- Keyboard: Tab comes to the line; the arrows move it, Home and End go to its limits; Enter, or a double click, puts it
|
|
15
|
+
back where it was at the start.
|
|
16
|
+
- setAreaVisible("first", 0) hides an area and the line; the other one takes the whole box.
|
|
17
|
+
- Style packages: "light" (default), "dark", "minimal", "minimalDark". Select with styleName (Splitter.styles), or later
|
|
18
|
+
with setTheme().
|
|
19
|
+
|
|
20
|
+
USAGE:
|
|
21
|
+
const split = Splitter({ firstSize: 240, onChangeEnd: function (self) { println(self.getFirstSize()); } });
|
|
22
|
+
createIn(split.first, function () { TreeView({ width: "100%", height: "100%" }); });
|
|
23
|
+
createIn(split.second, function () { LogView({ width: "100%", height: "100%" }); });
|
|
24
|
+
split.setFirstSize(300);
|
|
25
|
+
split.setFirstSize("40%");
|
|
26
|
+
split.getFirstSize(); // px
|
|
27
|
+
split.setAreaVisible("first", 0);
|
|
28
|
+
split.setTheme("dark");
|
|
29
|
+
Splitter({ direction: "vertical", secondSize: 160, minFirst: 100, minSecond: 60, styleName: "dark" });
|
|
30
|
+
|
|
31
|
+
Started Date: November 2026
|
|
32
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
33
|
+
|
|
34
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
35
|
+
Licensed under the Apache License, Version 2.0
|
|
36
|
+
SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
"use strict";
|
|
41
|
+
|
|
42
|
+
// Default values:
|
|
43
|
+
const SplitterDefaults = {
|
|
44
|
+
key: "0", // Your name for this object: read it in a callback (self.key)
|
|
45
|
+
left: 0,
|
|
46
|
+
top: 0,
|
|
47
|
+
width: "100%",
|
|
48
|
+
height: "100%",
|
|
49
|
+
direction: "horizontal", // "horizontal": side by side, "vertical": one under the other
|
|
50
|
+
firstSize: "30%", // px or a part of the box
|
|
51
|
+
secondSize: null, // px or a part of the box: the second area keeps its size (firstSize is not used)
|
|
52
|
+
minFirst: 60, // px
|
|
53
|
+
minSecond: 60, // px
|
|
54
|
+
keyStep: 16, // px: an arrow key moves the line this much
|
|
55
|
+
ariaLabel: "Change the sizes of the areas",
|
|
56
|
+
onChange: function (self) { }, // The line moves. (Not at create time, not with silent: 1)
|
|
57
|
+
onChangeEnd: function (self) { }, // The line is let go.
|
|
58
|
+
styleName: "light", // "light", "dark", "minimal", "minimalDark" or a name added to Splitter.styles
|
|
59
|
+
style: { // Light style package (default)
|
|
60
|
+
line: { size: 1, color: Black(0.14) }, // The line that is seen
|
|
61
|
+
grip: { size: 9 }, // The place around the line that takes the mouse
|
|
62
|
+
lineHover: { size: 3, color: "#5BBAC1" },
|
|
63
|
+
lineFocus: { size: 0, color: "" }, // The line while the keyboard is on it. "": the ring of focus.ringColor instead
|
|
64
|
+
focus: { ringColor: "rgba(63, 141, 148, 0.8)" },
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const Splitter = function (params = {}) {
|
|
69
|
+
|
|
70
|
+
// Merge style package: params.style > Splitter.styles[styleName] > SplitterDefaults.style (light)
|
|
71
|
+
const pageStyle = params.style; // WHY: setTheme() puts it over another package.
|
|
72
|
+
basic.applyStylePackage(params, Splitter.styles, SplitterDefaults);
|
|
73
|
+
|
|
74
|
+
// Merge params:
|
|
75
|
+
mergeIntoIfMissing(params, SplitterDefaults);
|
|
76
|
+
|
|
77
|
+
// BOX: Component container
|
|
78
|
+
const box = startObject(params);
|
|
79
|
+
|
|
80
|
+
// *** PRIVATE VARIABLES:
|
|
81
|
+
let _s = box.style;
|
|
82
|
+
const isVertical = (box.direction === "vertical");
|
|
83
|
+
const POINT_KEY = (isVertical) ? "clientY" : "clientX";
|
|
84
|
+
const FORWARD_KEY = (isVertical) ? "ArrowDown" : "ArrowRight";
|
|
85
|
+
const BACK_KEY = (isVertical) ? "ArrowUp" : "ArrowLeft";
|
|
86
|
+
const FIRST_SIZE_AT_START = box.firstSize;
|
|
87
|
+
const SECOND_SIZE_AT_START = box.secondSize;
|
|
88
|
+
let isFirstVisible = 1;
|
|
89
|
+
let isSecondVisible = 1;
|
|
90
|
+
let isOver = 0;
|
|
91
|
+
let isKeyFocus = 0; // the keyboard is on the line (lineFocus)
|
|
92
|
+
let dragPointerId = null;
|
|
93
|
+
let dragStartPoint = 0;
|
|
94
|
+
let dragStartSize = 0;
|
|
95
|
+
let firstPixels = 0; // The size of the first area now
|
|
96
|
+
|
|
97
|
+
// *** PUBLIC VARIABLES:
|
|
98
|
+
// NOTE: box.first and box.second are the groups of the areas. Default values are also public variables.
|
|
99
|
+
|
|
100
|
+
// *** PRIVATE FUNCTIONS:
|
|
101
|
+
|
|
102
|
+
// The style of a package, with the style of the page over it. (setTheme)
|
|
103
|
+
const styleOfPackage = function (styleName) {
|
|
104
|
+
const fresh = { styleName: styleName, style: pageStyle };
|
|
105
|
+
basic.applyStylePackage(fresh, Splitter.styles, SplitterDefaults);
|
|
106
|
+
mergeIntoIfMissing(fresh, SplitterDefaults);
|
|
107
|
+
return fresh.style;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const isPart = function (size) {
|
|
111
|
+
return (typeof size === "string" && size.trim().endsWith("%"));
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// px or "30%" of a length, in px
|
|
115
|
+
const sizeInPixels = function (size, length) {
|
|
116
|
+
return (isPart(size)) ? (parseFloat(size) / 100) * length : (parseFloat(size) || 0);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const boxLength = function () {
|
|
120
|
+
return (isVertical) ? box.elem.clientHeight : box.elem.clientWidth;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// The room of the two areas
|
|
124
|
+
const roomForAreas = function () {
|
|
125
|
+
return Math.max(0, boxLength() - _s.line.size);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const keepsSecondSize = function () {
|
|
129
|
+
return (box.secondSize !== null && box.secondSize !== undefined);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// The size of the first area from the params, inside its limits
|
|
133
|
+
const wantedFirstPixels = function () {
|
|
134
|
+
const room = roomForAreas();
|
|
135
|
+
const wanted = (keepsSecondSize()) ? room - sizeInPixels(box.secondSize, room) : sizeInPixels(box.firstSize, room);
|
|
136
|
+
return limitFirstPixels(wanted);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const limitFirstPixels = function (pixels) {
|
|
140
|
+
const room = roomForAreas();
|
|
141
|
+
const highest = Math.max(box.minFirst, room - box.minSecond);
|
|
142
|
+
return Math.min(room, basic.clamp(pixels, box.minFirst, highest));
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// WHY the same kind: a part stays a part when the box changes later, px stay px.
|
|
146
|
+
const keepPixelsAsSize = function (pixels) {
|
|
147
|
+
const room = roomForAreas();
|
|
148
|
+
if (keepsSecondSize()) {
|
|
149
|
+
const second = room - pixels;
|
|
150
|
+
box.secondSize = (isPart(box.secondSize) && room > 0) ? ((second / room) * 100) + "%" : second;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
box.firstSize = (isPart(box.firstSize) && room > 0) ? ((pixels / room) * 100) + "%" : pixels;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// One area: its place and its size on the line of the direction, the whole box on the other one.
|
|
157
|
+
const placeArea = function (area, start, length) {
|
|
158
|
+
if (isVertical) {
|
|
159
|
+
area.props({ left: 0, top: start, width: "100%", height: length });
|
|
160
|
+
} else {
|
|
161
|
+
area.props({ left: start, top: 0, width: length, height: "100%" });
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const placeGrip = function () {
|
|
166
|
+
const gripStart = firstPixels + (_s.line.size - _s.grip.size) / 2;
|
|
167
|
+
if (isVertical) {
|
|
168
|
+
box.grip.props({ left: 0, top: gripStart, width: "100%", height: _s.grip.size });
|
|
169
|
+
} else {
|
|
170
|
+
box.grip.props({ left: gripStart, top: 0, width: _s.grip.size, height: "100%" });
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// PAINT: the line: the mouse on it, or a drag
|
|
175
|
+
const lineLookNow = function () {
|
|
176
|
+
if (isOver || dragPointerId !== null) return _s.lineHover;
|
|
177
|
+
if (isKeyFocus && _s.lineFocus.color) return _s.lineFocus;
|
|
178
|
+
return _s.line;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const paintLine = function () {
|
|
182
|
+
const look = lineLookNow();
|
|
183
|
+
const size = look.size;
|
|
184
|
+
const start = (_s.grip.size - size) / 2;
|
|
185
|
+
box.line.color = look.color;
|
|
186
|
+
if (isVertical) {
|
|
187
|
+
box.line.props({ left: 0, top: start, width: "100%", height: size });
|
|
188
|
+
} else {
|
|
189
|
+
box.line.props({ left: start, top: 0, width: size, height: "100%" });
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// LAYOUT: what depends on the sizes
|
|
194
|
+
const refreshLayout = function () {
|
|
195
|
+
const isOneArea = (!isFirstVisible || !isSecondVisible);
|
|
196
|
+
box.grip.visible = (isOneArea) ? 0 : 1;
|
|
197
|
+
box.first.visible = (isFirstVisible) ? 1 : 0;
|
|
198
|
+
box.second.visible = (isSecondVisible) ? 1 : 0;
|
|
199
|
+
if (isOneArea) {
|
|
200
|
+
placeArea((isFirstVisible) ? box.first : box.second, 0, boxLength());
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const room = roomForAreas();
|
|
204
|
+
firstPixels = wantedFirstPixels();
|
|
205
|
+
placeArea(box.first, 0, firstPixels);
|
|
206
|
+
placeArea(box.second, firstPixels + _s.line.size, room - firstPixels);
|
|
207
|
+
placeGrip();
|
|
208
|
+
const percent = (room > 0) ? Math.round((firstPixels / room) * 100) : 0;
|
|
209
|
+
box.grip.aria = { valuenow: String(percent) };
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// LOOK: everything that comes from the style (the first drawing and setTheme)
|
|
213
|
+
const applyLook = function () {
|
|
214
|
+
// WHY no ring with lineFocus: the line itself shows the keyboard (and no outline of the browser either)
|
|
215
|
+
const isLineFocus = !!_s.lineFocus.color;
|
|
216
|
+
box.grip.setFocusRing((isLineFocus) ? "" : _s.focus.ringColor);
|
|
217
|
+
box.grip.css.outline = (isLineFocus) ? "none" : "";
|
|
218
|
+
paintLine();
|
|
219
|
+
refreshLayout();
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const movedTo = function (pixels) {
|
|
223
|
+
keepPixelsAsSize(limitFirstPixels(pixels));
|
|
224
|
+
refreshLayout();
|
|
225
|
+
box.onChange(box);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// A point of an event. WHY the scale: on a page fitted with page.fit() a screen px is not a px of the box.
|
|
229
|
+
const pointOf = function (event) {
|
|
230
|
+
const width = box.elem.offsetWidth;
|
|
231
|
+
const scale = (width > 0) ? box.elem.getBoundingClientRect().width / width : 1;
|
|
232
|
+
return event[POINT_KEY] / scale;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const onPointerDown = function (self, event) {
|
|
236
|
+
if (event.button !== 0) return;
|
|
237
|
+
try {
|
|
238
|
+
box.grip.elem.setPointerCapture(event.pointerId); // WHY: The drag goes on over the objects of the areas.
|
|
239
|
+
} catch (error) {
|
|
240
|
+
return; // WHY: A pointer that has just ended makes the browser throw.
|
|
241
|
+
}
|
|
242
|
+
dragPointerId = event.pointerId;
|
|
243
|
+
dragStartPoint = pointOf(event);
|
|
244
|
+
dragStartSize = firstPixels;
|
|
245
|
+
paintLine();
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const onPointerMove = function (self, event) {
|
|
249
|
+
if (event.pointerId !== dragPointerId) return;
|
|
250
|
+
movedTo(dragStartSize + pointOf(event) - dragStartPoint);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const onPointerEnd = function (self, event) {
|
|
254
|
+
if (event.pointerId !== dragPointerId) return;
|
|
255
|
+
dragPointerId = null;
|
|
256
|
+
paintLine();
|
|
257
|
+
box.onChangeEnd(box);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const backToStart = function () {
|
|
261
|
+
box.firstSize = FIRST_SIZE_AT_START;
|
|
262
|
+
box.secondSize = SECOND_SIZE_AT_START;
|
|
263
|
+
refreshLayout();
|
|
264
|
+
box.onChange(box);
|
|
265
|
+
box.onChangeEnd(box);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const onKeyDown = function (self, event) {
|
|
269
|
+
isKeyFocus = 1; // WHY: a key after a click shows where the keyboard is too
|
|
270
|
+
paintLine();
|
|
271
|
+
let target = null;
|
|
272
|
+
if (event.key === FORWARD_KEY) target = firstPixels + box.keyStep;
|
|
273
|
+
else if (event.key === BACK_KEY) target = firstPixels - box.keyStep;
|
|
274
|
+
else if (event.key === "Home") target = 0;
|
|
275
|
+
else if (event.key === "End") target = roomForAreas();
|
|
276
|
+
|
|
277
|
+
if (event.key === "Enter") {
|
|
278
|
+
event.preventDefault();
|
|
279
|
+
backToStart();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (target === null) return;
|
|
283
|
+
event.preventDefault();
|
|
284
|
+
movedTo(target);
|
|
285
|
+
box.onChangeEnd(box);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// *** PUBLIC FUNCTIONS:
|
|
289
|
+
|
|
290
|
+
// size: px or a part of the box ("40%"). silent: 1 -> onChange and onChangeEnd are not called.
|
|
291
|
+
box.setFirstSize = function (size, silent = 0) {
|
|
292
|
+
box.secondSize = null;
|
|
293
|
+
box.firstSize = size;
|
|
294
|
+
refreshLayout();
|
|
295
|
+
if (silent) return;
|
|
296
|
+
box.onChange(box);
|
|
297
|
+
box.onChangeEnd(box);
|
|
298
|
+
};
|
|
299
|
+
// USAGE: split.setFirstSize(300) / split.setFirstSize("40%")
|
|
300
|
+
|
|
301
|
+
// The size of the first area now, in px.
|
|
302
|
+
box.getFirstSize = function () {
|
|
303
|
+
return firstPixels;
|
|
304
|
+
};
|
|
305
|
+
// USAGE: split.getFirstSize()
|
|
306
|
+
|
|
307
|
+
box.setAreaVisible = function (areaName, value) {
|
|
308
|
+
const isVisible = basic.isOn(value) ? 1 : 0;
|
|
309
|
+
if (areaName === "first") isFirstVisible = isVisible;
|
|
310
|
+
else isSecondVisible = isVisible;
|
|
311
|
+
refreshLayout();
|
|
312
|
+
};
|
|
313
|
+
// USAGE: split.setAreaVisible("first", 0)
|
|
314
|
+
|
|
315
|
+
// Another style package while it is on the page. A style given by the page stays over it.
|
|
316
|
+
box.setTheme = function (styleName) {
|
|
317
|
+
box.styleName = styleName;
|
|
318
|
+
_s = styleOfPackage(styleName);
|
|
319
|
+
box.style = _s;
|
|
320
|
+
applyLook();
|
|
321
|
+
};
|
|
322
|
+
// USAGE: split.setTheme("dark")
|
|
323
|
+
|
|
324
|
+
// *** OBJECT VIEW:
|
|
325
|
+
|
|
326
|
+
// GROUP: The areas
|
|
327
|
+
box.first = VGroup({ left: 0, top: 0, align: "left top" });
|
|
328
|
+
endGroup();
|
|
329
|
+
|
|
330
|
+
box.second = VGroup({ left: 0, top: 0, align: "left top" });
|
|
331
|
+
endGroup();
|
|
332
|
+
|
|
333
|
+
// BOX: The place around the line that takes the mouse (over the edges of the areas)
|
|
334
|
+
box.grip = startBox({ color: "transparent", zIndex: 1 });
|
|
335
|
+
box.grip.cursor = (isVertical) ? "row-resize" : "col-resize";
|
|
336
|
+
box.grip.css.touchAction = "none";
|
|
337
|
+
box.grip.tabIndex = 0;
|
|
338
|
+
box.grip.role = "separator";
|
|
339
|
+
box.grip.aria = {
|
|
340
|
+
label: box.ariaLabel,
|
|
341
|
+
orientation: (isVertical) ? "horizontal" : "vertical", // WHY: The direction of the line, not of the areas.
|
|
342
|
+
valuemin: "0",
|
|
343
|
+
valuemax: "100",
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// BOX: The line that is seen
|
|
347
|
+
box.line = Box({ left: 0, top: 0 });
|
|
348
|
+
|
|
349
|
+
endBox();
|
|
350
|
+
|
|
351
|
+
// *** OBJECT INIT CODE:
|
|
352
|
+
|
|
353
|
+
box.grip.onHoverChange(function (self, value) {
|
|
354
|
+
isOver = value;
|
|
355
|
+
paintLine();
|
|
356
|
+
});
|
|
357
|
+
box.grip.on("pointerdown", onPointerDown);
|
|
358
|
+
box.grip.on("pointermove", onPointerMove);
|
|
359
|
+
box.grip.on("pointerup", onPointerEnd);
|
|
360
|
+
box.grip.on("pointercancel", onPointerEnd);
|
|
361
|
+
box.grip.on("keydown", onKeyDown);
|
|
362
|
+
box.grip.on("focus", function () {
|
|
363
|
+
isKeyFocus = box.grip.elem.matches(":focus-visible") ? 1 : 0;
|
|
364
|
+
paintLine();
|
|
365
|
+
});
|
|
366
|
+
box.grip.on("blur", function () {
|
|
367
|
+
isKeyFocus = 0;
|
|
368
|
+
paintLine();
|
|
369
|
+
});
|
|
370
|
+
box.grip.on("dblclick", backToStart);
|
|
371
|
+
box.onResize(refreshLayout);
|
|
372
|
+
|
|
373
|
+
applyLook();
|
|
374
|
+
|
|
375
|
+
return endObject(box);
|
|
376
|
+
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// *** STYLE PACKAGES:
|
|
380
|
+
// USAGE: Splitter({ styleName: "dark" })
|
|
381
|
+
// USAGE: Splitter({ style: { lineHover: { color: "tomato" } } }) // Change only some keys.
|
|
382
|
+
// NOTE: A new package needs only the keys that differ from the default (light) style.
|
|
383
|
+
// USAGE: Splitter.styles.myStyle = { line: { color: "tomato" } };
|
|
384
|
+
Splitter.styles = {
|
|
385
|
+
|
|
386
|
+
// A soft line; in the color of the kit under the mouse.
|
|
387
|
+
light: SplitterDefaults.style,
|
|
388
|
+
|
|
389
|
+
// For a dark window.
|
|
390
|
+
dark: {
|
|
391
|
+
line: { color: White(0.12) },
|
|
392
|
+
lineHover: { color: "#6FC6CD" },
|
|
393
|
+
focus: { ringColor: "rgba(111, 198, 205, 0.8)" },
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// The minimal theme (_designs/minimal-theme.htm): the soft line of the theme, a 2 px ink line under the mouse.
|
|
399
|
+
// minimalDark: the same on a dark window.
|
|
400
|
+
Splitter.createMinimalStyle = function (colors) {
|
|
401
|
+
return {
|
|
402
|
+
line: { size: 1, color: colors.line },
|
|
403
|
+
lineHover: { size: 2, color: colors.ink },
|
|
404
|
+
lineFocus: { size: 2, color: colors.focus },
|
|
405
|
+
focus: { ringColor: colors.focus },
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
Splitter.MINIMAL_COLORS = { line: Black(0.2), ink: "#1F1F1F", focus: "#3D8BD9" };
|
|
409
|
+
Splitter.styles.minimal = Splitter.createMinimalStyle(Splitter.MINIMAL_COLORS);
|
|
410
|
+
Splitter.MINIMAL_DARK_COLORS = { line: White(0.18), ink: "#EDEDEB", focus: "#7FB6DE" };
|
|
411
|
+
Splitter.styles.minimalDark = Splitter.createMinimalStyle(Splitter.MINIMAL_DARK_COLORS);
|