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,636 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Color Picker - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- A color picker: a field that opens a palette (popup), or an always visible palette (inline: 1).
|
|
9
|
+
- The palette is a simple grid of colors. A click selects the color and closes the panel.
|
|
10
|
+
- The selected color has a mark (a dot) in a color that can be seen on it (light or dark).
|
|
11
|
+
- Everything is drawn with code (no image files needed).
|
|
12
|
+
- Value: the color text. (Ex: "#3871E0")
|
|
13
|
+
- Style packages: "light" (default; the old name "classic" works too), "dark", "minimal", "minimalDark" (a package of
|
|
14
|
+
params: its height too). Select with styleName. (ColorPicker.styles)
|
|
15
|
+
|
|
16
|
+
Keyboard:
|
|
17
|
+
- Field: Enter, Space or ArrowDown opens the panel.
|
|
18
|
+
- Panel: Arrow keys select the color next to the selected one, Enter or Escape closes.
|
|
19
|
+
|
|
20
|
+
USAGE:
|
|
21
|
+
const picker = ColorPicker({
|
|
22
|
+
width: 170,
|
|
23
|
+
selectedColor: "#3871E0",
|
|
24
|
+
onChange: function (self) { page.color = self.value; },
|
|
25
|
+
});
|
|
26
|
+
picker.setColor("#D64545");
|
|
27
|
+
picker.setColors(["#000000", "#FFFFFF"]); // Your own palette
|
|
28
|
+
|
|
29
|
+
Started Date: September 2026
|
|
30
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
31
|
+
|
|
32
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
33
|
+
Licensed under the Apache License, Version 2.0
|
|
34
|
+
SPDX-License-Identifier: Apache-2.0
|
|
35
|
+
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
"use strict";
|
|
39
|
+
|
|
40
|
+
// Default values:
|
|
41
|
+
const ColorPickerDefaults = {
|
|
42
|
+
key: "0",
|
|
43
|
+
width: 170, // Field width (not used if inline: 1)
|
|
44
|
+
height: 44, // Field height (not used if inline: 1)
|
|
45
|
+
selectedColor: "", // "#3871E0" or "" (nothing is selected). WHY: not "color", Box.color is the background.
|
|
46
|
+
colors: [ // The palette. Any CSS color text is accepted. ("red", "rgb(0, 0, 0)"...)
|
|
47
|
+
"#141414", "#5A5A5A", "#9A9A9A", "#D0D0D0", "#FFFFFF",
|
|
48
|
+
"#D64545", "#E0A038", "#E8D44D", "#5DB182", "#3E8E62",
|
|
49
|
+
"#3871E0", "#5AA9E6", "#7B61D9", "#B45FC0", "#E06AA0",
|
|
50
|
+
"#8D6E63", "#C89F7B", "#2E4A7D", "#1F6F6B", "#7A8B2E",
|
|
51
|
+
],
|
|
52
|
+
columns: 5,
|
|
53
|
+
showText: 1, // 1: The color text is written in the field.
|
|
54
|
+
placeholder: "Select color",
|
|
55
|
+
inline: 0, // 1: The palette is always visible, no field.
|
|
56
|
+
enabled: 1,
|
|
57
|
+
closeOnSelect: 1,
|
|
58
|
+
onChange: function (self) { }, // self.value ("#3871E0" or "")
|
|
59
|
+
onOpen: function (self) { },
|
|
60
|
+
onClose: function (self) { },
|
|
61
|
+
styleName: "light", // "light" ("classic": its old name), "dark", "minimal", "minimalDark" or a name added to ColorPicker.styles
|
|
62
|
+
style: { // Light style package (default)
|
|
63
|
+
field: {
|
|
64
|
+
color: White(1),
|
|
65
|
+
border: 1,
|
|
66
|
+
borderColor: Black(0.2),
|
|
67
|
+
round: 6,
|
|
68
|
+
padding: [10, 0],
|
|
69
|
+
gap: 10,
|
|
70
|
+
},
|
|
71
|
+
fieldHover: {
|
|
72
|
+
borderColor: Black(0.5),
|
|
73
|
+
},
|
|
74
|
+
fieldFocus: {
|
|
75
|
+
borderColor: "#141414",
|
|
76
|
+
},
|
|
77
|
+
fieldText: {
|
|
78
|
+
fontSize: 15,
|
|
79
|
+
textColor: Black(0.85),
|
|
80
|
+
},
|
|
81
|
+
placeholder: {
|
|
82
|
+
textColor: Black(0.4),
|
|
83
|
+
},
|
|
84
|
+
fieldSwatch: {
|
|
85
|
+
width: 24,
|
|
86
|
+
height: 24,
|
|
87
|
+
round: 5,
|
|
88
|
+
},
|
|
89
|
+
panel: {
|
|
90
|
+
color: White(1),
|
|
91
|
+
border: 1,
|
|
92
|
+
borderColor: Black(0.12),
|
|
93
|
+
round: 10,
|
|
94
|
+
padding: 12,
|
|
95
|
+
shadow: "0 8px 24px rgba(0, 0, 0, 0.12)",
|
|
96
|
+
},
|
|
97
|
+
swatch: {
|
|
98
|
+
size: 28,
|
|
99
|
+
gap: 8,
|
|
100
|
+
round: 6,
|
|
101
|
+
border: 1,
|
|
102
|
+
borderColor: Black(0.15), // WHY: A white swatch is not visible on a white panel.
|
|
103
|
+
},
|
|
104
|
+
mark: {
|
|
105
|
+
size: 10, // The dot on the selected color
|
|
106
|
+
lightColor: White(0.95), // On a dark color
|
|
107
|
+
darkColor: Black(0.7), // On a light color
|
|
108
|
+
},
|
|
109
|
+
disabled: {
|
|
110
|
+
opacity: 0.4,
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const ColorPicker = function (params = {}) {
|
|
116
|
+
|
|
117
|
+
// Merge style package: params.style > ColorPicker.styles[styleName] > ColorPickerDefaults.style (light)
|
|
118
|
+
basic.applyStylePackage(params, ColorPicker.styles, ColorPickerDefaults);
|
|
119
|
+
|
|
120
|
+
// Merge params:
|
|
121
|
+
mergeIntoIfMissing(params, ColorPickerDefaults);
|
|
122
|
+
|
|
123
|
+
// Edit params, if needed:
|
|
124
|
+
params.color = "transparent";
|
|
125
|
+
if (params.inline == 1) {
|
|
126
|
+
params.width = "auto";
|
|
127
|
+
params.height = "auto";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// BOX: Component container
|
|
131
|
+
let box = startObject(params);
|
|
132
|
+
|
|
133
|
+
// *** PRIVATE VARIABLES:
|
|
134
|
+
const _s = box.style;
|
|
135
|
+
const swatchSize = _s.swatch.size;
|
|
136
|
+
const columns = Math.max(1, basic.num(box.columns) || 1);
|
|
137
|
+
const gridWidth = (swatchSize * columns) + (_s.swatch.gap * (columns - 1));
|
|
138
|
+
|
|
139
|
+
let isOpen = 0;
|
|
140
|
+
let isMouseOver = 0;
|
|
141
|
+
let swatches = []; // Created swatch boxes, in the order of box.colors
|
|
142
|
+
const PANEL_SPACE = 6; // Between the field and the panel
|
|
143
|
+
const PAGE_MARGIN = 8; // The panel stays this far from the edges of the page
|
|
144
|
+
const OVERLAY_Z_INDEX = 1000;
|
|
145
|
+
const PANEL_Z_INDEX = 1001; // Over the overlay
|
|
146
|
+
|
|
147
|
+
// *** PUBLIC VARIABLES:
|
|
148
|
+
// [var] Selected color: "#3871E0" or ""
|
|
149
|
+
box.value = ColorPicker.normalize(box.selectedColor);
|
|
150
|
+
|
|
151
|
+
// *** PRIVATE FUNCTIONS:
|
|
152
|
+
|
|
153
|
+
const updateField = function () {
|
|
154
|
+
|
|
155
|
+
if (box.inline == 1) return;
|
|
156
|
+
|
|
157
|
+
const hasValue = (box.value !== "");
|
|
158
|
+
box.fieldSwatch.visible = (hasValue) ? 1 : 0;
|
|
159
|
+
box.fieldSwatch.color = (hasValue) ? box.value : "transparent";
|
|
160
|
+
|
|
161
|
+
box.fieldText.visible = (box.showText == 1) ? 1 : 0;
|
|
162
|
+
box.fieldText.plainText = (hasValue) ? box.value : box.placeholder;
|
|
163
|
+
box.fieldText.textColor = (hasValue) ? _s.fieldText.textColor : _s.placeholder.textColor;
|
|
164
|
+
|
|
165
|
+
let borderColor = _s.field.borderColor;
|
|
166
|
+
if (isMouseOver && box.enabled == 1) borderColor = _s.fieldHover.borderColor;
|
|
167
|
+
if (isOpen) borderColor = _s.fieldFocus.borderColor;
|
|
168
|
+
box.field.borderColor = borderColor;
|
|
169
|
+
|
|
170
|
+
box.opacity = (box.enabled == 1) ? 1 : _s.disabled.opacity;
|
|
171
|
+
box.cursor = (box.enabled == 1) ? "pointer" : "default";
|
|
172
|
+
box.tabIndex = (box.enabled == 1) ? 0 : -1;
|
|
173
|
+
box.aria = {
|
|
174
|
+
expanded: (isOpen) ? "true" : "false",
|
|
175
|
+
disabled: (box.enabled == 1) ? "false" : "true",
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// Shows the mark on the selected swatch only.
|
|
181
|
+
const renderPanel = function () {
|
|
182
|
+
|
|
183
|
+
swatches.forEach(function (swatch) {
|
|
184
|
+
swatch.mark.visible = (swatch.colorText == box.value && box.value !== "") ? 1 : 0;
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
if (box.inline == 1) {
|
|
188
|
+
box.panel.opacity = (box.enabled == 1) ? 1 : _s.disabled.opacity;
|
|
189
|
+
box.panel.clickable = (box.enabled == 1) ? 1 : 0;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const createSwatch = function (colorText) {
|
|
195
|
+
|
|
196
|
+
// BOX: One color
|
|
197
|
+
const swatch = startBox({
|
|
198
|
+
width: swatchSize,
|
|
199
|
+
height: swatchSize,
|
|
200
|
+
color: colorText,
|
|
201
|
+
round: _s.swatch.round,
|
|
202
|
+
border: _s.swatch.border,
|
|
203
|
+
borderColor: _s.swatch.borderColor,
|
|
204
|
+
clickable: 1,
|
|
205
|
+
cursor: "pointer",
|
|
206
|
+
css: { flexShrink: "0" },
|
|
207
|
+
});
|
|
208
|
+
swatch.colorText = colorText;
|
|
209
|
+
swatch.elem.title = colorText;
|
|
210
|
+
swatch.role = "option";
|
|
211
|
+
|
|
212
|
+
// BOX: Selected mark
|
|
213
|
+
swatch.mark = Box({
|
|
214
|
+
width: _s.mark.size,
|
|
215
|
+
height: _s.mark.size,
|
|
216
|
+
round: 100,
|
|
217
|
+
color: (ColorPicker.isLight(colorText)) ? _s.mark.darkColor : _s.mark.lightColor,
|
|
218
|
+
visible: 0,
|
|
219
|
+
});
|
|
220
|
+
swatch.mark.center();
|
|
221
|
+
|
|
222
|
+
endBox();
|
|
223
|
+
|
|
224
|
+
swatch.on("click", function () {
|
|
225
|
+
if (box.enabled != 1) return;
|
|
226
|
+
box.setColor(colorText);
|
|
227
|
+
if (box.inline != 1 && box.closeOnSelect == 1) {
|
|
228
|
+
box.close();
|
|
229
|
+
box.elem.focus();
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
return swatch;
|
|
234
|
+
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const renderSwatches = function () {
|
|
238
|
+
|
|
239
|
+
swatches.forEach(function (swatch) { swatch.remove(); });
|
|
240
|
+
swatches = [];
|
|
241
|
+
|
|
242
|
+
// WHY: One createIn() for each swatch: the mark inside a swatch changes the default container.
|
|
243
|
+
swatches = box.colors.map(function (colorText) {
|
|
244
|
+
return createIn(box.grid, function () { return createSwatch(ColorPicker.normalize(colorText)); });
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
renderPanel();
|
|
248
|
+
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// Position the popup panel under (or above) the field.
|
|
252
|
+
const positionPanel = function () {
|
|
253
|
+
|
|
254
|
+
const rect = box.elem.getBoundingClientRect();
|
|
255
|
+
const panelWidth = box.panel.elem.offsetWidth;
|
|
256
|
+
const panelHeight = box.panel.elem.offsetHeight;
|
|
257
|
+
|
|
258
|
+
let left = withPageZoom(rect.left);
|
|
259
|
+
let top = withPageZoom(rect.bottom) + PANEL_SPACE;
|
|
260
|
+
|
|
261
|
+
if (top + panelHeight > page.height - PAGE_MARGIN) {
|
|
262
|
+
top = withPageZoom(rect.top) - panelHeight - PANEL_SPACE; // Open above
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
box.panel.left = Math.max(PAGE_MARGIN, Math.min(left, page.width - panelWidth - PAGE_MARGIN));
|
|
266
|
+
box.panel.top = Math.max(PAGE_MARGIN, top);
|
|
267
|
+
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const onPageResize = function () {
|
|
271
|
+
if (isOpen) box.close();
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// Select the color next to the selected one. (Keyboard)
|
|
275
|
+
const moveValue = function (step) {
|
|
276
|
+
|
|
277
|
+
if (!swatches.length) return;
|
|
278
|
+
|
|
279
|
+
const current = swatches.findIndex(function (swatch) { return swatch.colorText == box.value; });
|
|
280
|
+
let index = (current < 0) ? 0 : current + step;
|
|
281
|
+
|
|
282
|
+
if (index < 0 || index >= swatches.length) return;
|
|
283
|
+
box.setColor(swatches[index].colorText);
|
|
284
|
+
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const onKeyDown = function (self, event) {
|
|
288
|
+
|
|
289
|
+
if (box.enabled != 1) return;
|
|
290
|
+
|
|
291
|
+
// Field is focused and the panel is closed:
|
|
292
|
+
if (box.inline != 1 && !isOpen) {
|
|
293
|
+
if (event.key === "Enter" || event.key === " " || event.key === "ArrowDown") {
|
|
294
|
+
event.preventDefault();
|
|
295
|
+
box.open();
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (event.key === "Escape" || event.key === "Enter") {
|
|
301
|
+
if (box.inline == 1) return;
|
|
302
|
+
event.preventDefault();
|
|
303
|
+
box.close();
|
|
304
|
+
box.elem.focus();
|
|
305
|
+
} else if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
306
|
+
event.preventDefault();
|
|
307
|
+
moveValue((event.key === "ArrowLeft") ? -1 : 1);
|
|
308
|
+
} else if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
309
|
+
event.preventDefault();
|
|
310
|
+
moveValue((event.key === "ArrowUp") ? -columns : columns);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// *** PUBLIC FUNCTIONS:
|
|
316
|
+
|
|
317
|
+
box.setColor = function (colorText, silent = 0) {
|
|
318
|
+
|
|
319
|
+
const newColor = ColorPicker.normalize(colorText);
|
|
320
|
+
if (newColor === box.value) return;
|
|
321
|
+
|
|
322
|
+
box.value = newColor;
|
|
323
|
+
updateField();
|
|
324
|
+
renderPanel();
|
|
325
|
+
|
|
326
|
+
if (!silent) box.onChange(box);
|
|
327
|
+
|
|
328
|
+
};
|
|
329
|
+
// USAGE: get: picker.value, set: picker.setColor("#D64545"), picker.setColor("")
|
|
330
|
+
// NOTE: setColor(color, 1) changes the value without calling onChange.
|
|
331
|
+
|
|
332
|
+
box.getColor = function () {
|
|
333
|
+
return box.value;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// Change the palette. (The selected color is kept, even if it is not in the list.)
|
|
337
|
+
box.setColors = function (colors) {
|
|
338
|
+
box.colors = (colors || []).slice();
|
|
339
|
+
renderSwatches();
|
|
340
|
+
};
|
|
341
|
+
// USAGE: picker.setColors(["#000000", "#FFFFFF", "red"])
|
|
342
|
+
|
|
343
|
+
box.open = function () {
|
|
344
|
+
|
|
345
|
+
if (box.inline == 1 || isOpen || box.enabled != 1) return;
|
|
346
|
+
isOpen = 1;
|
|
347
|
+
|
|
348
|
+
// WHY at open: a field in a Dialog or a SidePanel (their layer is over 1001) opens its list over them
|
|
349
|
+
const layerZIndex = basic.zIndexAbove(box, OVERLAY_Z_INDEX);
|
|
350
|
+
box.overlay.zIndex = layerZIndex;
|
|
351
|
+
box.panel.zIndex = layerZIndex + 1;
|
|
352
|
+
box.overlay.visible = 1;
|
|
353
|
+
box.panel.visible = 1;
|
|
354
|
+
positionPanel();
|
|
355
|
+
box.panel.elem.focus({ preventScroll: true });
|
|
356
|
+
|
|
357
|
+
updateField();
|
|
358
|
+
box.onOpen(box);
|
|
359
|
+
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
box.close = function () {
|
|
363
|
+
|
|
364
|
+
if (box.inline == 1 || !isOpen) return;
|
|
365
|
+
isOpen = 0;
|
|
366
|
+
|
|
367
|
+
box.overlay.visible = 0;
|
|
368
|
+
box.panel.visible = 0;
|
|
369
|
+
|
|
370
|
+
updateField();
|
|
371
|
+
box.onClose(box);
|
|
372
|
+
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
box.toggle = function () {
|
|
376
|
+
if (isOpen) {
|
|
377
|
+
box.close();
|
|
378
|
+
} else {
|
|
379
|
+
box.open();
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
box.isOpen = function () {
|
|
384
|
+
return isOpen;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
box.setEnabled = function (enabled) {
|
|
388
|
+
box.enabled = basic.isOn(enabled) ? 1 : 0;
|
|
389
|
+
if (box.enabled != 1) box.close();
|
|
390
|
+
updateField();
|
|
391
|
+
renderPanel();
|
|
392
|
+
};
|
|
393
|
+
// USAGE: get: picker.enabled, set: picker.setEnabled(0)
|
|
394
|
+
|
|
395
|
+
box.refresh = function () {
|
|
396
|
+
updateField();
|
|
397
|
+
renderPanel();
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
// *** OBJECT VIEW:
|
|
402
|
+
box.css.outline = "none";
|
|
403
|
+
|
|
404
|
+
// FIELD: (only popup mode)
|
|
405
|
+
if (box.inline != 1) {
|
|
406
|
+
|
|
407
|
+
box.clickable = 1;
|
|
408
|
+
box.role = "combobox";
|
|
409
|
+
|
|
410
|
+
// GROUP: Field (swatch + text)
|
|
411
|
+
box.field = HGroup({
|
|
412
|
+
width: "100%",
|
|
413
|
+
height: "100%",
|
|
414
|
+
align: "left center",
|
|
415
|
+
gap: _s.field.gap,
|
|
416
|
+
color: _s.field.color,
|
|
417
|
+
border: _s.field.border,
|
|
418
|
+
borderColor: _s.field.borderColor,
|
|
419
|
+
round: _s.field.round,
|
|
420
|
+
padding: _s.field.padding,
|
|
421
|
+
});
|
|
422
|
+
box.field.setMotion("border-color 0.15s");
|
|
423
|
+
|
|
424
|
+
// BOX: Selected color
|
|
425
|
+
box.fieldSwatch = Box({
|
|
426
|
+
width: _s.fieldSwatch.width,
|
|
427
|
+
height: _s.fieldSwatch.height,
|
|
428
|
+
round: _s.fieldSwatch.round,
|
|
429
|
+
border: _s.swatch.border,
|
|
430
|
+
borderColor: _s.swatch.borderColor,
|
|
431
|
+
css: { flexShrink: "0" },
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// LABEL: Color text
|
|
435
|
+
box.fieldText = Label({
|
|
436
|
+
width: "auto",
|
|
437
|
+
fontSize: _s.fieldText.fontSize,
|
|
438
|
+
textColor: _s.fieldText.textColor,
|
|
439
|
+
ellipsis: 1,
|
|
440
|
+
grow: 1,
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
endGroup();
|
|
444
|
+
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// POPUP: Create the overlay and the panel on the page, over everything.
|
|
448
|
+
// WHY: Creating them directly on the page is safer than moving them later.
|
|
449
|
+
if (box.inline != 1) {
|
|
450
|
+
|
|
451
|
+
setDefaultContainerBox(page);
|
|
452
|
+
// NOTE: endGroup() of the panel below returns the default container to the component box.
|
|
453
|
+
|
|
454
|
+
// BOX: Transparent overlay (click outside: close)
|
|
455
|
+
// WHY a very big box and not 100% x 100%: with position "fixed" the "100%" is taken from the nearest parent
|
|
456
|
+
// that has a zoom or a transform (page.fit); there the overlay had no height and a click outside the
|
|
457
|
+
// panel did not close it (the same fix as SelectBox).
|
|
458
|
+
const OVERLAY_SIZE = 20000; // px
|
|
459
|
+
box.overlay = Box(-OVERLAY_SIZE, -OVERLAY_SIZE, OVERLAY_SIZE * 2, OVERLAY_SIZE * 2, { color: "transparent" });
|
|
460
|
+
box.overlay.css.position = "fixed";
|
|
461
|
+
box.overlay.zIndex = OVERLAY_Z_INDEX;
|
|
462
|
+
box.overlay.on("click", function () { box.close(); });
|
|
463
|
+
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// BOX: Palette panel
|
|
467
|
+
box.panel = VGroup({
|
|
468
|
+
width: gridWidth + (_s.panel.padding * 2) + (_s.panel.border * 2),
|
|
469
|
+
height: "auto",
|
|
470
|
+
align: "left top",
|
|
471
|
+
color: _s.panel.color,
|
|
472
|
+
border: _s.panel.border,
|
|
473
|
+
borderColor: _s.panel.borderColor,
|
|
474
|
+
round: _s.panel.round,
|
|
475
|
+
padding: _s.panel.padding,
|
|
476
|
+
boxShadow: _s.panel.shadow,
|
|
477
|
+
});
|
|
478
|
+
box.panel.css.outline = "none";
|
|
479
|
+
box.panel.tabIndex = -1;
|
|
480
|
+
box.panel.clickable = 1;
|
|
481
|
+
box.panel.role = "listbox";
|
|
482
|
+
|
|
483
|
+
// GROUP: Color grid (the swatches are created by renderSwatches)
|
|
484
|
+
box.grid = HGroup({
|
|
485
|
+
width: gridWidth,
|
|
486
|
+
height: "auto",
|
|
487
|
+
align: "left top",
|
|
488
|
+
gap: _s.swatch.gap,
|
|
489
|
+
wrap: 1, // WHY: The grid rows are made by the wrap, so any number of colors fits.
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
endGroup();
|
|
493
|
+
|
|
494
|
+
endGroup();
|
|
495
|
+
|
|
496
|
+
if (box.inline != 1) {
|
|
497
|
+
box.panel.zIndex = PANEL_Z_INDEX;
|
|
498
|
+
box.overlay.visible = 0;
|
|
499
|
+
box.panel.visible = 0;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// *** OBJECT INIT CODE:
|
|
503
|
+
|
|
504
|
+
if (box.inline != 1) {
|
|
505
|
+
|
|
506
|
+
box.on("click", function () { box.toggle(); });
|
|
507
|
+
box.on("keydown", onKeyDown);
|
|
508
|
+
|
|
509
|
+
box.on("mouseover", function () {
|
|
510
|
+
isMouseOver = 1;
|
|
511
|
+
updateField();
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
box.on("mouseout", function () {
|
|
515
|
+
isMouseOver = 0;
|
|
516
|
+
updateField();
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// (onPageResize / own: the overlay and the panel are on the page, they are removed with the box)
|
|
520
|
+
box.onPageResize(onPageResize);
|
|
521
|
+
box.own(box.overlay);
|
|
522
|
+
box.own(box.panel);
|
|
523
|
+
|
|
524
|
+
} else {
|
|
525
|
+
box.panel.tabIndex = 0;
|
|
526
|
+
// WHY: Component size is "auto". A relative panel makes the container wrap it.
|
|
527
|
+
box.panel.position = "relative";
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
box.panel.on("keydown", onKeyDown);
|
|
531
|
+
// WHY: Keep the keyboard focus on the panel when a swatch is clicked.
|
|
532
|
+
box.panel.on("mousedown", function (self, event) { event.preventDefault(); });
|
|
533
|
+
|
|
534
|
+
box.enabled = basic.isOn(box.enabled) ? 1 : 0;
|
|
535
|
+
|
|
536
|
+
box.setColors(params.colors); // WHY: Copy the array. The default list must not be shared between components.
|
|
537
|
+
updateField();
|
|
538
|
+
|
|
539
|
+
return endObject(box);
|
|
540
|
+
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
// *** STATIC FUNCTIONS:
|
|
544
|
+
|
|
545
|
+
// "#abc" -> "#AABBCC", "#aabbcc" -> "#AABBCC". Another color text ("red") is not changed.
|
|
546
|
+
ColorPicker.normalize = function (colorText) {
|
|
547
|
+
|
|
548
|
+
const text = String(colorText || "").trim();
|
|
549
|
+
if (text === "") return "";
|
|
550
|
+
|
|
551
|
+
const short = /^#([0-9a-fA-F]{3})$/.exec(text);
|
|
552
|
+
if (short) {
|
|
553
|
+
return "#" + short[1].toUpperCase().replace(/./g, function (char) { return char + char; });
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const long = /^#([0-9a-fA-F]{6})$/.exec(text);
|
|
557
|
+
return (long) ? "#" + long[1].toUpperCase() : text;
|
|
558
|
+
|
|
559
|
+
};
|
|
560
|
+
// USAGE: ColorPicker.normalize("#abc") -> "#AABBCC"
|
|
561
|
+
|
|
562
|
+
// Is a dark text readable on this color? (Any CSS color text is accepted.)
|
|
563
|
+
ColorPicker.isLight = function (colorText) {
|
|
564
|
+
const rgb = ColorPicker.toRgb(colorText);
|
|
565
|
+
return (rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114) > 160;
|
|
566
|
+
};
|
|
567
|
+
// USAGE: ColorPicker.isLight("#FFFFFF") -> true
|
|
568
|
+
|
|
569
|
+
// Any CSS color text -> { r, g, b }. (The browser does the work.)
|
|
570
|
+
ColorPicker.toRgb = function (colorText) {
|
|
571
|
+
|
|
572
|
+
const elem = document.createElement("div");
|
|
573
|
+
elem.style.display = "none";
|
|
574
|
+
elem.style.color = "rgb(0, 0, 0)";
|
|
575
|
+
elem.style.color = String(colorText); // WHY: An unknown color text is not written, black stays.
|
|
576
|
+
|
|
577
|
+
document.body.appendChild(elem);
|
|
578
|
+
const computed = getComputedStyle(elem).color;
|
|
579
|
+
document.body.removeChild(elem);
|
|
580
|
+
|
|
581
|
+
const parts = /(\d+)[^\d]+(\d+)[^\d]+(\d+)/.exec(computed);
|
|
582
|
+
if (!parts) return { r: 0, g: 0, b: 0 };
|
|
583
|
+
return { r: basic.num(parts[1]), g: basic.num(parts[2]), b: basic.num(parts[3]) };
|
|
584
|
+
|
|
585
|
+
};
|
|
586
|
+
// USAGE: ColorPicker.toRgb("gold") -> { r: 255, g: 215, b: 0 }
|
|
587
|
+
|
|
588
|
+
// *** STYLE PACKAGES:
|
|
589
|
+
// USAGE: ColorPicker({ styleName: "dark" })
|
|
590
|
+
// USAGE: ColorPicker({ styleName: "dark", style: { swatch: { round: 14 } } }) // Change only some keys.
|
|
591
|
+
// USAGE: ColorPicker({ style: ColorPicker.styles.dark }) // The same as styleName: "dark". (The package is copied, never changed.)
|
|
592
|
+
// NOTE: A new package needs only the keys that differ from the default (classic) style.
|
|
593
|
+
// USAGE: ColorPicker.styles.myStyle = { swatch: { round: 14 } };
|
|
594
|
+
ColorPicker.styles = {
|
|
595
|
+
|
|
596
|
+
// White, dark text, a soft line.
|
|
597
|
+
light: ColorPickerDefaults.style,
|
|
598
|
+
|
|
599
|
+
// Dark theme, same colors as SelectBox "dark".
|
|
600
|
+
dark: {
|
|
601
|
+
field: { color: "#232322", borderColor: "rgba(255, 255, 255, 0.10)", round: 8 },
|
|
602
|
+
fieldHover: { borderColor: "rgba(255, 255, 255, 0.30)" },
|
|
603
|
+
fieldFocus: { borderColor: "#65A293" },
|
|
604
|
+
fieldText: { fontSize: 15, textColor: "rgba(255, 255, 255, 0.90)" },
|
|
605
|
+
placeholder: { textColor: "rgba(255, 255, 255, 0.40)" },
|
|
606
|
+
panel: { color: "#232322", borderColor: "rgba(255, 255, 255, 0.12)", shadow: "0 8px 24px rgba(0, 0, 0, 0.5)" },
|
|
607
|
+
swatch: { borderColor: "rgba(255, 255, 255, 0.15)" }, // WHY: A dark swatch is not visible on a dark panel.
|
|
608
|
+
},
|
|
609
|
+
|
|
610
|
+
};
|
|
611
|
+
ColorPicker.styles.classic = ColorPicker.styles.light; // the old name of light: the pages made with it keep their look
|
|
612
|
+
|
|
613
|
+
// The minimal theme (_designs/minimal-theme.htm): a 28 px field as the other minimal fields with a 16 px swatch; the
|
|
614
|
+
// palette on the ground of the window with a line and no shadow, 22 px swatches with a soft line (a light color
|
|
615
|
+
// shows on a light window too). minimalDark: the same on a dark window.
|
|
616
|
+
ColorPicker.createMinimalStyle = function (colors) {
|
|
617
|
+
return {
|
|
618
|
+
height: 28,
|
|
619
|
+
style: {
|
|
620
|
+
field: { color: "transparent", border: 1, borderColor: colors.edge, round: 4, padding: [8, 0], gap: 8 },
|
|
621
|
+
fieldHover: { borderColor: colors.edgeHover },
|
|
622
|
+
fieldFocus: { borderColor: colors.ink },
|
|
623
|
+
fieldText: { fontSize: 13, textColor: colors.text },
|
|
624
|
+
placeholder: { textColor: colors.faintText },
|
|
625
|
+
fieldSwatch: { width: 16, height: 16, round: 3 },
|
|
626
|
+
panel: { color: colors.ground, border: 1, borderColor: colors.line, round: 4, padding: 8, shadow: "none" },
|
|
627
|
+
swatch: { size: 22, gap: 6, round: 4, border: 1, borderColor: colors.line },
|
|
628
|
+
mark: { size: 8 },
|
|
629
|
+
disabled: { opacity: 0.4 },
|
|
630
|
+
},
|
|
631
|
+
};
|
|
632
|
+
};
|
|
633
|
+
ColorPicker.MINIMAL_COLORS = { ground: "#FFFFFF", text: Black(0.85), softText: Black(0.55), faintText: Black(0.54), line: Black(0.2), edge: Black(0.45), edgeHover: Black(0.65), ink: "#1F1F1F", hover: Black(0.05), off: Black(0.25) };
|
|
634
|
+
ColorPicker.styles.minimal = ColorPicker.createMinimalStyle(ColorPicker.MINIMAL_COLORS);
|
|
635
|
+
ColorPicker.MINIMAL_DARK_COLORS = { ground: "#1A1A19", text: White(0.88), softText: White(0.55), faintText: White(0.48), line: White(0.18), edge: White(0.42), edgeHover: White(0.62), ink: "#EDEDEB", hover: White(0.07), off: White(0.25) };
|
|
636
|
+
ColorPicker.styles.minimalDark = ColorPicker.createMinimalStyle(ColorPicker.MINIMAL_DARK_COLORS);
|