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.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +14 -0
  3. data/NOTICE +5 -0
  4. data/README.md +242 -0
  5. data/exe/ozdenui +17 -0
  6. data/lib/ozdenui/AGENTS.md +210 -0
  7. data/lib/ozdenui/COMPONENTS.md +3017 -0
  8. data/lib/ozdenui/app.rb +749 -0
  9. data/lib/ozdenui/command.rb +107 -0
  10. data/lib/ozdenui/components.rb +368 -0
  11. data/lib/ozdenui/dialogs.rb +212 -0
  12. data/lib/ozdenui/files.rb +124 -0
  13. data/lib/ozdenui/icon.png +0 -0
  14. data/lib/ozdenui/kit.json +1 -0
  15. data/lib/ozdenui/kit.rb +115 -0
  16. data/lib/ozdenui/look.rb +229 -0
  17. data/lib/ozdenui/objects.rb +652 -0
  18. data/lib/ozdenui/server.rb +270 -0
  19. data/lib/ozdenui/values.rb +273 -0
  20. data/lib/ozdenui/version.rb +15 -0
  21. data/lib/ozdenui/web/basic/LICENSE +14 -0
  22. data/lib/ozdenui/web/basic/basic.min.css +1 -0
  23. data/lib/ozdenui/web/basic/basic.min.js +78 -0
  24. data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
  25. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
  26. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
  27. data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
  28. data/lib/ozdenui/web/bridge.js +584 -0
  29. data/lib/ozdenui/web/comp/accordion.js +659 -0
  30. data/lib/ozdenui/web/comp/action-button/add.png +0 -0
  31. data/lib/ozdenui/web/comp/action-button.js +521 -0
  32. data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
  33. data/lib/ozdenui/web/comp/app-bar.js +237 -0
  34. data/lib/ozdenui/web/comp/badge.js +292 -0
  35. data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
  36. data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
  37. data/lib/ozdenui/web/comp/canvas.js +652 -0
  38. data/lib/ozdenui/web/comp/chat-view.js +827 -0
  39. data/lib/ozdenui/web/comp/check-box.js +490 -0
  40. data/lib/ozdenui/web/comp/code-editor.js +965 -0
  41. data/lib/ozdenui/web/comp/color-picker.js +636 -0
  42. data/lib/ozdenui/web/comp/context-menu.js +951 -0
  43. data/lib/ozdenui/web/comp/currency-field.js +209 -0
  44. data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
  45. data/lib/ozdenui/web/comp/data-table.js +937 -0
  46. data/lib/ozdenui/web/comp/date-picker.js +1055 -0
  47. data/lib/ozdenui/web/comp/dialog.js +992 -0
  48. data/lib/ozdenui/web/comp/email-field.js +65 -0
  49. data/lib/ozdenui/web/comp/file-picker.js +920 -0
  50. data/lib/ozdenui/web/comp/filters.js +807 -0
  51. data/lib/ozdenui/web/comp/form.js +602 -0
  52. data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
  53. data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
  54. data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
  55. data/lib/ozdenui/web/comp/gauge.js +439 -0
  56. data/lib/ozdenui/web/comp/graph-box.js +3911 -0
  57. data/lib/ozdenui/web/comp/grid-group.js +185 -0
  58. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
  59. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
  60. data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
  61. data/lib/ozdenui/web/comp/image-view.js +598 -0
  62. data/lib/ozdenui/web/comp/item-list.js +1740 -0
  63. data/lib/ozdenui/web/comp/json-editor.js +3221 -0
  64. data/lib/ozdenui/web/comp/json-view.js +597 -0
  65. data/lib/ozdenui/web/comp/label-editor.js +1140 -0
  66. data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
  67. data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
  68. data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
  69. data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
  70. data/lib/ozdenui/web/comp/left-menu.js +548 -0
  71. data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
  72. data/lib/ozdenui/web/comp/loading-screen.js +413 -0
  73. data/lib/ozdenui/web/comp/log-view.js +530 -0
  74. data/lib/ozdenui/web/comp/login-page.js +685 -0
  75. data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
  76. data/lib/ozdenui/web/comp/menu-bar.js +624 -0
  77. data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
  78. data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
  79. data/lib/ozdenui/web/comp/notice.js +229 -0
  80. data/lib/ozdenui/web/comp/number-field.js +128 -0
  81. data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
  82. data/lib/ozdenui/web/comp/page-control.js +762 -0
  83. data/lib/ozdenui/web/comp/page-header.js +191 -0
  84. data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
  85. data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
  86. data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
  87. data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
  88. data/lib/ozdenui/web/comp/password-field.js +192 -0
  89. data/lib/ozdenui/web/comp/period-bar.js +436 -0
  90. data/lib/ozdenui/web/comp/phone-field.js +322 -0
  91. data/lib/ozdenui/web/comp/progress-bar.js +992 -0
  92. data/lib/ozdenui/web/comp/property-panel.js +3639 -0
  93. data/lib/ozdenui/web/comp/radio-button.js +527 -0
  94. data/lib/ozdenui/web/comp/range-slider.js +569 -0
  95. data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
  96. data/lib/ozdenui/web/comp/scroll-area.js +308 -0
  97. data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
  98. data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
  99. data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
  100. data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
  101. data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
  102. data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
  103. data/lib/ozdenui/web/comp/search-input.js +725 -0
  104. data/lib/ozdenui/web/comp/search-results.js +596 -0
  105. data/lib/ozdenui/web/comp/select-box.js +1862 -0
  106. data/lib/ozdenui/web/comp/settings-row.js +299 -0
  107. data/lib/ozdenui/web/comp/side-panel.js +616 -0
  108. data/lib/ozdenui/web/comp/slider-field.js +952 -0
  109. data/lib/ozdenui/web/comp/slider.js +838 -0
  110. data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
  111. data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
  112. data/lib/ozdenui/web/comp/smart-button.js +981 -0
  113. data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
  114. data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
  115. data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
  116. data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
  117. data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
  118. data/lib/ozdenui/web/comp/smart-table.js +1883 -0
  119. data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
  120. data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
  121. data/lib/ozdenui/web/comp/splitter.js +411 -0
  122. data/lib/ozdenui/web/comp/status-bar.js +408 -0
  123. data/lib/ozdenui/web/comp/step-bar.js +345 -0
  124. data/lib/ozdenui/web/comp/stepper.js +753 -0
  125. data/lib/ozdenui/web/comp/tabs.js +1366 -0
  126. data/lib/ozdenui/web/comp/tag-input.js +1107 -0
  127. data/lib/ozdenui/web/comp/tap-effect.js +170 -0
  128. data/lib/ozdenui/web/comp/text-area-field.js +233 -0
  129. data/lib/ozdenui/web/comp/text-field.js +1006 -0
  130. data/lib/ozdenui/web/comp/time-line.js +398 -0
  131. data/lib/ozdenui/web/comp/time-picker.js +1032 -0
  132. data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
  133. data/lib/ozdenui/web/comp/tiny-select.js +322 -0
  134. data/lib/ozdenui/web/comp/tiny-table.js +283 -0
  135. data/lib/ozdenui/web/comp/toast.js +891 -0
  136. data/lib/ozdenui/web/comp/toggle.js +757 -0
  137. data/lib/ozdenui/web/comp/tool-bar.js +760 -0
  138. data/lib/ozdenui/web/comp/tooltip.js +534 -0
  139. data/lib/ozdenui/web/comp/tree-view.js +1179 -0
  140. data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
  141. data/lib/ozdenui/web/comp/ui-standards.js +403 -0
  142. data/lib/ozdenui/web/comp/url-field.js +190 -0
  143. data/lib/ozdenui/web/comp/web-view.js +588 -0
  144. data/lib/ozdenui/web/components.js +123 -0
  145. data/lib/ozdenui/web/index.html +39 -0
  146. data/lib/ozdenui/window.rb +188 -0
  147. data/lib/ozdenui/window_cocoa.rb +221 -0
  148. data/lib/ozdenui.rb +32 -0
  149. metadata +200 -0
@@ -0,0 +1,1032 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Time Picker - v26.11
6
+
7
+ UI COMPONENT TEMPLATE
8
+ - A time picker: a field that opens a panel (popup), or an always visible panel (inline: 1).
9
+ - The panel has two scrollable columns: hours (00-23) and minutes (with minuteStep).
10
+ - The columns scroll with basic/scroll-bar.js (ScrollBar), not with the scrollbar of the browser.
11
+ (useScrollBar: 0, or the file is not loaded: the scrollbar of the browser is used.)
12
+ - Supports: minTime, maxTime (also over midnight: 22:00 - 02:00), minuteStep, format,
13
+ language (en, tr), Now/Clear buttons, enabled, keyboard navigation.
14
+ - Everything is drawn with code (no image files needed).
15
+ - Value: "HH:mm" text. (Ex: "19:30")
16
+ - Style packages: "light" (default; the old name "classic" works too), "dark", "minimal", "minimalDark" (a package of
17
+ params: its height too). Select with styleName. (TimePicker.styles)
18
+
19
+ Keyboard (when the panel is focused):
20
+ - ArrowUp/ArrowDown: change the value of the active column, ArrowLeft/ArrowRight: change the column,
21
+ Enter: close, Escape: close.
22
+
23
+ Started Date: September 2026
24
+ Webpage: https://bug7a.github.io/js-components/
25
+
26
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
27
+ Licensed under the Apache License, Version 2.0
28
+ SPDX-License-Identifier: Apache-2.0
29
+
30
+ */
31
+
32
+ "use strict";
33
+
34
+ // Default values:
35
+ const TimePickerDefaults = {
36
+ key: "0",
37
+ width: 160, // Field width (not used if inline: 1)
38
+ height: 44, // Field height (not used if inline: 1)
39
+ time: null, // "HH:mm", Date or null
40
+ minTime: null, // "HH:mm" or null
41
+ maxTime: null, // "HH:mm" or null. If it is smaller than minTime, the range goes over midnight.
42
+ minuteStep: 5, // 1, 5, 10, 15, 30...
43
+ format: "HH:mm", // Tokens: HH, H, hh, h, mm, A (AM/PM), a (am/pm)
44
+ language: "en", // "en", "tr"
45
+ placeholder: "", // Empty: uses the language text
46
+ inline: 0, // 1: Panel is always visible, no field.
47
+ enabled: 1,
48
+ closeOnSelect: 1, // 1: Close after a minute is selected.
49
+ useScrollBar: 1, // basic/scroll-bar.js. 0: the scrollbar of the browser.
50
+ showNowButton: 1,
51
+ showClearButton: 1,
52
+ onChange: function (self) { }, // self.value ("19:30" or ""), self.hours, self.minutes (number or null), self.timeText
53
+ onOpen: function (self) { },
54
+ onClose: function (self) { },
55
+ styleName: "light", // "light" ("classic": its old name), "dark", "minimal", "minimalDark" or a name added to TimePicker.styles
56
+ style: { // Light style package (default)
57
+ field: {
58
+ color: White(1),
59
+ border: 1,
60
+ borderColor: Black(0.2),
61
+ round: 6,
62
+ padding: [12, 0],
63
+ },
64
+ fieldHover: {
65
+ borderColor: Black(0.5),
66
+ },
67
+ fieldFocus: {
68
+ borderColor: "#141414",
69
+ },
70
+ fieldText: {
71
+ fontSize: 16,
72
+ textColor: Black(0.85),
73
+ },
74
+ placeholder: {
75
+ textColor: Black(0.4),
76
+ },
77
+ icon: {
78
+ color: Black(0.55),
79
+ svg: "", // An SVG text drawn in this color (stroke="currentColor"). "": the drawn clock
80
+ size: 18, // px of the SVG icon
81
+ },
82
+ panel: {
83
+ color: White(1),
84
+ border: 1,
85
+ borderColor: Black(0.12),
86
+ round: 10,
87
+ padding: 12,
88
+ shadow: "0 8px 24px rgba(0, 0, 0, 0.12)",
89
+ },
90
+ columnTitle: {
91
+ fontSize: 12,
92
+ textColor: Black(0.45),
93
+ activeTextColor: Black(0.85),
94
+ },
95
+ column: {
96
+ rows: 6, // Visible rows
97
+ gap: 8, // Space between the hours and minutes columns
98
+ barSpace: 0, // Room around the cells of a column for its scroll bar. 0: the bar is over the right side of the cells
99
+ },
100
+ scrollBar: { // basic/scroll-bar.js (ScrollBar) parameters of the columns
101
+ bar_color: "#141414",
102
+ bar_mouseOverColor: "#141414",
103
+ bar_width: 4,
104
+ bar_round: 3,
105
+ bar_opacity: 0.2,
106
+ bar_mouseOverOpacity: 0.5,
107
+ bar_padding: 2,
108
+ neverHide: 1, // The column is short: the bar says that there is more to see.
109
+ showDots: 0,
110
+ },
111
+ cell: {
112
+ width: 64,
113
+ height: 36,
114
+ round: 6,
115
+ fontSize: 15,
116
+ textColor: Black(0.85),
117
+ hoverColor: Black(0.06),
118
+ },
119
+ selectedCell: {
120
+ color: "#141414",
121
+ textColor: White(1),
122
+ },
123
+ disabledCell: {
124
+ textColor: Black(0.2),
125
+ },
126
+ footerButton: {
127
+ fontSize: 13,
128
+ textColor: "#3871E0",
129
+ },
130
+ divider: {
131
+ color: Black(0.08), // The line above the footer buttons
132
+ },
133
+ disabled: {
134
+ opacity: 0.4,
135
+ },
136
+ }
137
+ };
138
+
139
+ const TimePicker = function (params = {}) {
140
+
141
+ // Merge style package: params.style > TimePicker.styles[styleName] > TimePickerDefaults.style (light)
142
+ basic.applyStylePackage(params, TimePicker.styles, TimePickerDefaults);
143
+
144
+ // Merge params:
145
+ mergeIntoIfMissing(params, TimePickerDefaults);
146
+
147
+ // Edit params, if needed:
148
+ params.color = "transparent";
149
+ if (params.inline == 1) {
150
+ params.width = "auto";
151
+ params.height = "auto";
152
+ }
153
+
154
+ // BOX: Component container
155
+ let box = startObject(params);
156
+
157
+ // *** PRIVATE VARIABLES:
158
+ const texts = TimePicker.languages[box.language] || TimePicker.languages.en;
159
+ const _s = box.style;
160
+ const cellWidth = _s.cell.width;
161
+ const cellHeight = _s.cell.height;
162
+ const columnWidth = cellWidth + _s.column.barSpace;
163
+ const columnHeight = cellHeight * _s.column.rows;
164
+ const innerWidth = (columnWidth * 2) + _s.column.gap;
165
+
166
+ let isOpen = 0;
167
+ let isMouseOver = 0;
168
+ let activeColumn = "hours"; // "hours", "minutes" (keyboard)
169
+ let hourCells = []; // index: hour
170
+ let minuteCells = []; // index: position in minuteList
171
+ let minuteList = []; // [0, 5, 10, ...]
172
+ // WHY: The component works without basic/scroll-bar.js too, the file is not loaded on every page.
173
+ const useScrollBar = (box.useScrollBar == 1 && typeof ScrollBar !== "undefined");
174
+ const PANEL_GAP = 6; // px between the field and the panel
175
+ const SCREEN_MARGIN = 8; // px: the panel stays this far from the edges of the page
176
+ const OVERLAY_Z_INDEX = 1000;
177
+ const PANEL_Z_INDEX = 1001;
178
+
179
+ // *** PUBLIC VARIABLES:
180
+ // [var] Selected time: minutes from 00:00 (0 - 1439) or null
181
+ box.minutesOfDay = TimePicker.parse(box.time);
182
+ // [var] number or null
183
+ box.hours = null;
184
+ box.minutes = null;
185
+ // [var] "HH:mm" or ""
186
+ box.value = "";
187
+ // [var] Formatted text or "" (WHY: not "text", Box.text changes innerHTML)
188
+ box.timeText = "";
189
+
190
+ box.minTime = TimePicker.parse(box.minTime);
191
+ box.maxTime = TimePicker.parse(box.maxTime);
192
+ box.minuteStep = Math.max(1, Math.min(60, Math.floor(basic.num(box.minuteStep) || 1)));
193
+
194
+ // *** PRIVATE FUNCTIONS:
195
+
196
+ const isInRange = function (minutesOfDay) {
197
+ const min = box.minTime;
198
+ const max = box.maxTime;
199
+ if (min === null && max === null) return true;
200
+ if (min === null) return minutesOfDay <= max;
201
+ if (max === null) return minutesOfDay >= min;
202
+ if (min <= max) return minutesOfDay >= min && minutesOfDay <= max;
203
+ // WHY: Range over midnight. Ex: 22:00 - 02:00
204
+ return minutesOfDay >= min || minutesOfDay <= max;
205
+ };
206
+
207
+ const isHourEnabled = function (hour) {
208
+ return minuteList.some(function (minute) { return isInRange(hour * 60 + minute); });
209
+ };
210
+
211
+ const firstEnabledMinute = function (hour) {
212
+ const minute = minuteList.find(function (m) { return isInRange(hour * 60 + m); });
213
+ return (minute === undefined) ? null : minute;
214
+ };
215
+
216
+ const updateValue = function () {
217
+ const time = box.minutesOfDay;
218
+ box.hours = (time === null) ? null : Math.floor(time / 60);
219
+ box.minutes = (time === null) ? null : time % 60;
220
+ box.value = (time === null) ? "" : TimePicker.format(time, "HH:mm");
221
+ box.timeText = (time === null) ? "" : TimePicker.format(time, box.format);
222
+ };
223
+
224
+ const updateField = function () {
225
+
226
+ if (box.inline == 1) return;
227
+
228
+ if (box.minutesOfDay !== null) {
229
+ box.fieldText.plainText = box.timeText;
230
+ box.fieldText.textColor = _s.fieldText.textColor;
231
+ } else {
232
+ box.fieldText.plainText = box.placeholder || texts.placeholder;
233
+ box.fieldText.textColor = _s.placeholder.textColor;
234
+ }
235
+
236
+ let borderColor = _s.field.borderColor;
237
+ if (isMouseOver && box.enabled == 1) borderColor = _s.fieldHover.borderColor;
238
+ if (isOpen) borderColor = _s.fieldFocus.borderColor;
239
+ box.field.borderColor = borderColor;
240
+
241
+ box.opacity = (box.enabled == 1) ? 1 : _s.disabled.opacity;
242
+ box.cursor = (box.enabled == 1) ? "pointer" : "default";
243
+ box.tabIndex = (box.enabled == 1) ? 0 : -1;
244
+ box.aria = {
245
+ expanded: (isOpen) ? "true" : "false",
246
+ disabled: (box.enabled == 1) ? "false" : "true",
247
+ };
248
+
249
+ };
250
+
251
+ const createCell = function (text, onClick) {
252
+
253
+ const cell = Label({
254
+ width: cellWidth,
255
+ height: cellHeight,
256
+ text: text,
257
+ textAlign: "center",
258
+ fontSize: _s.cell.fontSize,
259
+ round: _s.cell.round,
260
+ textColor: _s.cell.textColor,
261
+ color: "transparent",
262
+ });
263
+ cell.lineHeight = cellHeight + "px";
264
+ cell.shrink = 0;
265
+ cell.setMotion("background-color 0.15s");
266
+ cell.isEnabled = 1;
267
+ cell.isSelected = 0;
268
+
269
+ cell.on("click", function () {
270
+ if (box.enabled == 1 && cell.isEnabled) onClick();
271
+ });
272
+ cell.on("mouseover", function () {
273
+ if (box.enabled == 1 && cell.isEnabled && !cell.isSelected) cell.color = _s.cell.hoverColor;
274
+ });
275
+ cell.on("mouseout", function () {
276
+ if (!cell.isSelected) cell.color = "transparent";
277
+ });
278
+
279
+ return cell;
280
+
281
+ };
282
+
283
+ const getCellTextColor = function (selected, enabled) {
284
+ if (selected) return _s.selectedCell.textColor;
285
+ if (enabled) return _s.cell.textColor;
286
+ return _s.disabledCell.textColor;
287
+ };
288
+
289
+ const paintCell = function (cell, selected, enabled) {
290
+ cell.isSelected = selected ? 1 : 0;
291
+ cell.isEnabled = enabled ? 1 : 0;
292
+ cell.color = (selected) ? _s.selectedCell.color : "transparent";
293
+ cell.textColor = getCellTextColor(selected, enabled);
294
+ cell.cursor = (enabled && box.enabled == 1) ? "pointer" : "default";
295
+ };
296
+
297
+ // A scrollable column with a title. Returns the column box.
298
+ const createColumn = function (title) {
299
+
300
+ const group = VGroup({
301
+ width: columnWidth,
302
+ height: "auto",
303
+ align: "center top",
304
+ gap: 4,
305
+ });
306
+
307
+ group.title = Label({
308
+ width: columnWidth,
309
+ text: title,
310
+ textAlign: "center",
311
+ fontSize: _s.columnTitle.fontSize,
312
+ textColor: _s.columnTitle.textColor,
313
+ });
314
+
315
+ // BOX: Scroll area. The scrolling box and its ScrollBar are in it.
316
+ // WHY: ScrollBar alines itself with the left / top of the scrolling box, inside the
317
+ // container box of it. A flex item has left = 0 and top = 0 (flex places it), so
318
+ // in the group the bar landed on the title. This box is the flex item instead.
319
+ group.scrollArea = startBox({
320
+ width: columnWidth,
321
+ height: columnHeight,
322
+ color: "transparent",
323
+ });
324
+
325
+ // BOX: Scrollable list
326
+ group.scrollBox = startBox(0, 0, columnWidth, columnHeight, {
327
+ color: "transparent",
328
+ scrollY: 1,
329
+ });
330
+ group.scrollBox.css.position = "relative";
331
+ // WHY: Narrow column. Mouse wheel and touch still scroll.
332
+ if (useScrollBar) group.scrollBox.css.scrollbarWidth = "none";
333
+
334
+ group.list = VGroup({
335
+ width: "100%",
336
+ height: "auto",
337
+ align: "center top",
338
+ gap: 0,
339
+ });
340
+
341
+ // NOTE: Cells are added by the caller.
342
+
343
+ endGroup();
344
+
345
+ endBox();
346
+
347
+ endBox();
348
+
349
+ endGroup();
350
+
351
+ // SCROLL BAR: basic/scroll-bar.js instead of the scrollbar of the browser.
352
+ if (useScrollBar) {
353
+ createIn(group.scrollArea, function () {
354
+ group.scrollBar = ScrollBar(Object.assign({ scrollableBox: group.scrollBox }, _s.scrollBar));
355
+ });
356
+ }
357
+
358
+ return group;
359
+
360
+ };
361
+
362
+ const createHourCells = function () {
363
+ createIn(box.hoursColumn.list, function () {
364
+ for (let hour = 0; hour < 24; hour++) {
365
+ hourCells.push(createCell(basic.twoDigitFormat(hour), function () { selectHour(hour); }));
366
+ }
367
+ });
368
+ };
369
+
370
+ const createMinuteCells = function () {
371
+ minuteCells.forEach(function (cell) { cell.remove(); });
372
+ minuteCells = [];
373
+ minuteList = [];
374
+ for (let minute = 0; minute < 60; minute += box.minuteStep) minuteList.push(minute);
375
+ createIn(box.minutesColumn.list, function () {
376
+ minuteList.forEach(function (minute) {
377
+ minuteCells.push(createCell(basic.twoDigitFormat(minute), function () { selectMinute(minute); }));
378
+ });
379
+ });
380
+ };
381
+
382
+ // Scroll the column so the cell is in the middle.
383
+ const scrollToCell = function (column, cell, smooth = 0) {
384
+ if (!cell) return;
385
+ const top = cell.elem.offsetTop - ((columnHeight - cellHeight) / 2);
386
+ column.scrollBox.elem.scrollTo({ top: Math.max(0, top), behavior: (smooth) ? "smooth" : "auto" });
387
+ };
388
+
389
+ const scrollToSelected = function (smooth = 0) {
390
+ const hour = (box.hours !== null) ? box.hours : new Date().getHours();
391
+ scrollToCell(box.hoursColumn, hourCells[hour], smooth);
392
+ const minute = (box.minutes !== null) ? box.minutes : 0;
393
+ const index = minuteList.indexOf(minute - (minute % box.minuteStep));
394
+ scrollToCell(box.minutesColumn, minuteCells[Math.max(0, index)], smooth);
395
+ };
396
+
397
+ // The bars can not measure a hidden panel (its size is 0), so they are refreshed after it is shown.
398
+ const refreshScrollBars = function () {
399
+ if (!useScrollBar) return;
400
+ if (box.hoursColumn && box.hoursColumn.scrollBar) box.hoursColumn.scrollBar.refreshScroll();
401
+ if (box.minutesColumn && box.minutesColumn.scrollBar) box.minutesColumn.scrollBar.refreshScroll();
402
+ };
403
+
404
+ const isMinuteEnabled = function (minute) {
405
+ if (box.hours !== null) return isInRange(box.hours * 60 + minute);
406
+ // WHY: No hour selected yet: a minute is enabled if it is valid for any hour.
407
+ return hourCells.some(function (c, hour) { return isInRange(hour * 60 + minute); });
408
+ };
409
+
410
+ const renderPanel = function () {
411
+
412
+ hourCells.forEach(function (cell, hour) {
413
+ paintCell(cell, box.hours === hour, isHourEnabled(hour));
414
+ });
415
+
416
+ minuteCells.forEach(function (cell, index) {
417
+ const minute = minuteList[index];
418
+ paintCell(cell, box.minutes === minute, isMinuteEnabled(minute));
419
+ });
420
+
421
+ const isKeyboardHours = (activeColumn == "hours");
422
+ box.hoursColumn.title.textColor = (isKeyboardHours) ? _s.columnTitle.activeTextColor : _s.columnTitle.textColor;
423
+ box.minutesColumn.title.textColor = (!isKeyboardHours) ? _s.columnTitle.activeTextColor : _s.columnTitle.textColor;
424
+
425
+ box.nowButton.visible = (box.showNowButton == 1 && isInRange(getNow())) ? 1 : 0;
426
+ box.clearButton.visible = (box.showClearButton == 1 && box.minutesOfDay !== null) ? 1 : 0;
427
+ box.footer.visible = (box.showNowButton == 1 || box.showClearButton == 1) ? 1 : 0;
428
+
429
+ if (box.inline == 1) {
430
+ box.panel.opacity = (box.enabled == 1) ? 1 : _s.disabled.opacity;
431
+ box.panel.clickable = (box.enabled == 1) ? 1 : 0;
432
+ }
433
+
434
+ };
435
+
436
+ // Now, rounded down to the minute step.
437
+ const getNow = function () {
438
+ const now = new Date();
439
+ const minute = now.getMinutes() - (now.getMinutes() % box.minuteStep);
440
+ return now.getHours() * 60 + minute;
441
+ };
442
+
443
+ // User clicked an hour: keep the minutes if they are valid for the new hour.
444
+ const selectHour = function (hour) {
445
+
446
+ if (!isHourEnabled(hour)) return;
447
+
448
+ let minute = (box.minutes !== null) ? box.minutes : 0;
449
+ if (!isInRange(hour * 60 + minute)) minute = firstEnabledMinute(hour);
450
+
451
+ activeColumn = "minutes";
452
+ box.setTime(hour * 60 + minute);
453
+ renderPanel(); // WHY: setTime does not render if the time did not change. The active column changed.
454
+ scrollToCell(box.minutesColumn, minuteCells[minuteList.indexOf(minute)], 1);
455
+
456
+ };
457
+
458
+ // WHY: No (valid) hour selected yet: use the current hour, or the first hour that is valid with this minute.
459
+ // Returns -1 if no hour is valid.
460
+ const findHourForMinute = function (minute) {
461
+ const nowHour = new Date().getHours();
462
+ if (isInRange(nowHour * 60 + minute)) return nowHour;
463
+ return hourCells.findIndex(function (c, h) { return isInRange(h * 60 + minute); });
464
+ };
465
+
466
+ // User clicked a minute: the time is complete.
467
+ const selectMinute = function (minute) {
468
+
469
+ let hour = box.hours;
470
+ if (hour === null || !isInRange(hour * 60 + minute)) {
471
+ hour = findHourForMinute(minute);
472
+ if (hour < 0) return;
473
+ scrollToCell(box.hoursColumn, hourCells[hour], 1);
474
+ }
475
+
476
+ box.setTime(hour * 60 + minute);
477
+ finishSelect();
478
+
479
+ };
480
+
481
+ const finishSelect = function () {
482
+ if (box.inline != 1 && box.closeOnSelect == 1) {
483
+ box.close();
484
+ box.elem.focus();
485
+ }
486
+ };
487
+
488
+ // Position the popup panel under (or above) the field.
489
+ const positionPanel = function () {
490
+
491
+ const rect = box.elem.getBoundingClientRect();
492
+ const panelWidth = box.panel.elem.offsetWidth;
493
+ const panelHeight = box.panel.elem.offsetHeight;
494
+
495
+ let left = withPageZoom(rect.left);
496
+ let top = withPageZoom(rect.bottom) + PANEL_GAP;
497
+
498
+ if (top + panelHeight > page.height - SCREEN_MARGIN) {
499
+ top = withPageZoom(rect.top) - panelHeight - PANEL_GAP; // Open above
500
+ }
501
+ top = Math.max(SCREEN_MARGIN, top);
502
+ left = Math.max(SCREEN_MARGIN, Math.min(left, page.width - panelWidth - SCREEN_MARGIN));
503
+
504
+ box.panel.left = left;
505
+ box.panel.top = top;
506
+
507
+ };
508
+
509
+ const onPageResize = function () {
510
+ if (isOpen) box.close();
511
+ };
512
+
513
+ // Hours column: the next enabled hour. The minutes are kept if they are valid for it.
514
+ const moveHour = function (direction) {
515
+ let hour = (box.hours !== null) ? box.hours : new Date().getHours() - direction;
516
+ for (let i = 0; i < 24; i++) {
517
+ hour = (hour + direction + 24) % 24;
518
+ if (isHourEnabled(hour)) break;
519
+ }
520
+ let minute = (box.minutes !== null) ? box.minutes : 0;
521
+ if (!isInRange(hour * 60 + minute)) minute = firstEnabledMinute(hour);
522
+ if (minute === null) return;
523
+ box.setTime(hour * 60 + minute);
524
+ scrollToCell(box.hoursColumn, hourCells[hour], 1);
525
+ };
526
+
527
+ // Minutes column: the next minute that is valid for the hour.
528
+ const moveMinute = function (direction) {
529
+ const hour = (box.hours !== null) ? box.hours : new Date().getHours();
530
+ const current = (box.minutes !== null) ? minuteList.indexOf(box.minutes - (box.minutes % box.minuteStep)) : -1;
531
+ let index = (current < 0 && direction < 0) ? minuteList.length : current;
532
+ for (let i = 0; i < minuteList.length; i++) {
533
+ index = (index + direction + minuteList.length) % minuteList.length;
534
+ if (isInRange(hour * 60 + minuteList[index])) {
535
+ box.setTime(hour * 60 + minuteList[index]);
536
+ scrollToCell(box.minutesColumn, minuteCells[index], 1);
537
+ return;
538
+ }
539
+ }
540
+ };
541
+
542
+ // Move the value of the active column one step. (Skips disabled values.)
543
+ const moveValue = function (direction) {
544
+ if (activeColumn == "hours") {
545
+ moveHour(direction);
546
+ return;
547
+ }
548
+ moveMinute(direction);
549
+ };
550
+
551
+ const onKeyDown = function (self, event) {
552
+
553
+ if (box.enabled != 1) return;
554
+
555
+ // Field is focused and panel is closed:
556
+ if (box.inline != 1 && !isOpen) {
557
+ if (event.key === "Enter" || event.key === " " || event.key === "ArrowDown") {
558
+ event.preventDefault();
559
+ box.open();
560
+ }
561
+ return;
562
+ }
563
+
564
+ if (event.key === "Escape" || event.key === "Enter") {
565
+ if (box.inline == 1) return;
566
+ event.preventDefault();
567
+ box.close();
568
+ box.elem.focus();
569
+ } else if (event.key === "ArrowUp" || event.key === "ArrowDown") {
570
+ event.preventDefault();
571
+ moveValue((event.key === "ArrowUp") ? -1 : 1);
572
+ } else if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
573
+ event.preventDefault();
574
+ activeColumn = (event.key === "ArrowLeft") ? "hours" : "minutes";
575
+ renderPanel();
576
+ }
577
+
578
+ };
579
+
580
+ // *** PUBLIC FUNCTIONS:
581
+
582
+ // time: "HH:mm", Date, minutes from 00:00 (1170) or null
583
+ box.setTime = function (time, silent = 0) {
584
+
585
+ const newTime = TimePicker.parse(time);
586
+ if (newTime !== null && !isInRange(newTime)) return false;
587
+ if (newTime === box.minutesOfDay) return true;
588
+
589
+ box.minutesOfDay = newTime;
590
+ updateValue();
591
+ updateField();
592
+ renderPanel();
593
+
594
+ if (!silent) box.onChange(box);
595
+ return true;
596
+
597
+ };
598
+ // USAGE: picker.setTime("19:30"), picker.setTime(new Date()), picker.setTime(null)
599
+ // NOTE: setTime(time, 1) changes the value without calling onChange. Returns false if out of range.
600
+
601
+ // Returns: { hours, minutes } or null
602
+ box.getTime = function () {
603
+ return (box.minutesOfDay === null) ? null : { hours: box.hours, minutes: box.minutes };
604
+ };
605
+
606
+ box.open = function () {
607
+
608
+ if (box.inline == 1 || isOpen || box.enabled != 1) return;
609
+ isOpen = 1;
610
+
611
+ activeColumn = "hours";
612
+ renderPanel();
613
+
614
+ // WHY at open: a field in a Dialog or a SidePanel (their layer is over 1001) opens its list over them
615
+ const layerZIndex = basic.zIndexAbove(box, OVERLAY_Z_INDEX);
616
+ box.overlay.zIndex = layerZIndex;
617
+ box.panel.zIndex = layerZIndex + 1;
618
+ box.overlay.visible = 1;
619
+ box.panel.visible = 1;
620
+ positionPanel();
621
+ scrollToSelected();
622
+ refreshScrollBars();
623
+ box.panel.elem.focus({ preventScroll: true });
624
+
625
+ updateField();
626
+ box.onOpen(box);
627
+
628
+ };
629
+
630
+ box.close = function () {
631
+
632
+ if (box.inline == 1 || !isOpen) return;
633
+ isOpen = 0;
634
+
635
+ box.overlay.visible = 0;
636
+ box.panel.visible = 0;
637
+
638
+ updateField();
639
+ box.onClose(box);
640
+
641
+ };
642
+
643
+ box.toggle = function () {
644
+ (isOpen) ? box.close() : box.open();
645
+ };
646
+
647
+ box.isOpen = function () {
648
+ return isOpen;
649
+ };
650
+
651
+ box.setEnabled = function (enabled) {
652
+ box.enabled = basic.isOn(enabled) ? 1 : 0;
653
+ if (box.enabled != 1) box.close();
654
+ updateField();
655
+ renderPanel();
656
+ };
657
+ // USAGE: get: picker.enabled, set: picker.setEnabled(0)
658
+
659
+ box.setMinTime = function (time) {
660
+ box.minTime = TimePicker.parse(time);
661
+ renderPanel();
662
+ };
663
+
664
+ box.setMaxTime = function (time) {
665
+ box.maxTime = TimePicker.parse(time);
666
+ renderPanel();
667
+ };
668
+
669
+ box.setMinuteStep = function (minuteStep) {
670
+ box.minuteStep = Math.max(1, Math.min(60, Math.floor(basic.num(minuteStep) || 1)));
671
+ createMinuteCells();
672
+ renderPanel();
673
+ if (isOpen || box.inline == 1) scrollToSelected();
674
+ refreshScrollBars();
675
+ };
676
+
677
+ box.refresh = function () {
678
+ updateValue();
679
+ updateField();
680
+ renderPanel();
681
+ refreshScrollBars();
682
+ };
683
+
684
+
685
+ // *** OBJECT VIEW:
686
+ box.css = { outline: "none", userSelect: "none" };
687
+
688
+ // FIELD: (only popup mode)
689
+ if (box.inline != 1) {
690
+
691
+ box.clickable = 1;
692
+ box.role = "combobox";
693
+
694
+ box.field = HGroup({
695
+ width: "100%",
696
+ height: "100%",
697
+ align: "left center",
698
+ gap: 8,
699
+ ..._s.field,
700
+ });
701
+ box.field.setMotion("border-color 0.15s");
702
+
703
+ // LABEL: Selected time text
704
+ box.fieldText = Label({
705
+ width: "auto",
706
+ fontSize: _s.fieldText.fontSize,
707
+ textColor: _s.fieldText.textColor,
708
+ });
709
+ that.css = { whiteSpace: "nowrap", textOverflow: "ellipsis" };
710
+ that.grow = 1;
711
+
712
+ // BOX: Clock icon: the SVG of the style, or drawn
713
+ if (_s.icon.svg) {
714
+ box.icon = Box({ width: _s.icon.size, height: _s.icon.size, color: "transparent", textColor: _s.icon.color });
715
+ box.icon.elem.innerHTML = _s.icon.svg;
716
+ } else {
717
+ box.icon = startBox({
718
+ width: 18,
719
+ height: 18,
720
+ color: "transparent",
721
+ border: 2,
722
+ borderColor: _s.icon.color,
723
+ round: 100,
724
+ });
725
+ Box({ left: 6, top: 2, width: 2, height: 6, color: _s.icon.color, round: 1 }); // Hour hand
726
+ Box({ left: 6, top: 6, width: 5, height: 2, color: _s.icon.color, round: 1 }); // Minute hand
727
+ endBox();
728
+ }
729
+ box.icon.shrink = 0;
730
+
731
+ endGroup();
732
+
733
+ }
734
+
735
+ // POPUP: Create the overlay and the panel on the page, over everything.
736
+ // WHY: Creating them directly on the page is safer than moving them later.
737
+ if (box.inline != 1) {
738
+
739
+ setDefaultContainerBox(page);
740
+ // NOTE: endGroup() of the panel below returns the default container to the component box.
741
+
742
+ // BOX: Transparent overlay (click outside: close)
743
+ // WHY a very big box and not 100% x 100%: with position "fixed" the "100%" is taken from the nearest parent
744
+ // that has a zoom or a transform (page.fit); there the overlay had no height and a click outside the
745
+ // panel did not close it (the same fix as SelectBox).
746
+ const OVERLAY_SIZE = 20000; // px
747
+ box.overlay = Box(-OVERLAY_SIZE, -OVERLAY_SIZE, OVERLAY_SIZE * 2, OVERLAY_SIZE * 2, { color: "transparent" });
748
+ box.overlay.css.position = "fixed";
749
+ box.overlay.zIndex = OVERLAY_Z_INDEX;
750
+ box.overlay.on("click", function () { box.close(); });
751
+
752
+ }
753
+
754
+ // BOX: Time panel
755
+ box.panel = VGroup({
756
+ width: innerWidth + (_s.panel.padding * 2) + (_s.panel.border * 2),
757
+ height: "auto",
758
+ align: "left top",
759
+ gap: 6,
760
+ color: _s.panel.color,
761
+ border: _s.panel.border,
762
+ borderColor: _s.panel.borderColor,
763
+ round: _s.panel.round,
764
+ padding: _s.panel.padding,
765
+ });
766
+ box.panel.boxShadow = _s.panel.shadow;
767
+ box.panel.css.outline = "none";
768
+ box.panel.tabIndex = -1;
769
+ box.panel.clickable = 1;
770
+ box.panel.role = "dialog";
771
+
772
+ // GROUP: Columns (hours, minutes)
773
+ HGroup({
774
+ width: innerWidth,
775
+ height: "auto",
776
+ align: "left top",
777
+ gap: _s.column.gap,
778
+ });
779
+
780
+ box.hoursColumn = createColumn(texts.hour);
781
+ box.minutesColumn = createColumn(texts.minute);
782
+
783
+ endGroup();
784
+
785
+ // GROUP: Footer (Now, Clear)
786
+ box.footer = HGroup({
787
+ width: innerWidth,
788
+ height: 38,
789
+ justifyContent: "space-between",
790
+ alignItems: "center",
791
+ });
792
+ box.footer.css = {
793
+ borderTop: "1px solid " + _s.divider.color,
794
+ paddingTop: "6px",
795
+ };
796
+
797
+ box.nowButton = Label({
798
+ text: texts.now,
799
+ padding: [8, 2],
800
+ round: 4,
801
+ ..._s.footerButton,
802
+ });
803
+ box.nowButton.cursor = "pointer";
804
+ box.nowButton.on("click", function () {
805
+ if (box.enabled != 1) return;
806
+ box.setTime(getNow());
807
+ scrollToSelected(1);
808
+ finishSelect();
809
+ });
810
+
811
+ box.clearButton = Label({
812
+ text: texts.clear,
813
+ padding: [8, 2],
814
+ round: 4,
815
+ ..._s.footerButton,
816
+ });
817
+ box.clearButton.cursor = "pointer";
818
+ box.clearButton.css.marginLeft = "auto";
819
+ box.clearButton.on("click", function () {
820
+ if (box.enabled != 1) return;
821
+ box.setTime(null);
822
+ activeColumn = "hours";
823
+ renderPanel();
824
+ if (box.inline != 1) {
825
+ box.close();
826
+ box.elem.focus();
827
+ }
828
+ });
829
+
830
+ endGroup();
831
+
832
+ endGroup();
833
+
834
+ createHourCells();
835
+ createMinuteCells();
836
+
837
+ if (box.inline != 1) {
838
+ box.panel.zIndex = PANEL_Z_INDEX;
839
+ box.overlay.visible = 0;
840
+ box.panel.visible = 0;
841
+ }
842
+
843
+ // *** OBJECT INIT CODE:
844
+
845
+ if (box.inline != 1) {
846
+
847
+ box.on("click", function () { box.toggle(); });
848
+ box.on("keydown", onKeyDown);
849
+
850
+ box.on("mouseover", function () {
851
+ isMouseOver = 1;
852
+ updateField();
853
+ });
854
+
855
+ box.on("mouseout", function () {
856
+ isMouseOver = 0;
857
+ updateField();
858
+ });
859
+
860
+ // (onPageResize / own: the overlay and the panel are on the page, they are removed with the box)
861
+ box.onPageResize(onPageResize);
862
+ box.own(box.overlay);
863
+ box.own(box.panel);
864
+
865
+ } else {
866
+ box.panel.tabIndex = 0;
867
+ // WHY: Component size is "auto". A relative panel makes the container wrap it.
868
+ box.panel.position = "relative";
869
+ }
870
+
871
+ box.panel.on("keydown", onKeyDown);
872
+ // WHY: Keep the keyboard focus on the panel when a cell is clicked.
873
+ box.panel.on("mousedown", function (self, event) { event.preventDefault(); });
874
+
875
+ box.enabled = basic.isOn(box.enabled) ? 1 : 0;
876
+ // WHY: A start time out of the range is not accepted.
877
+ if (box.minutesOfDay !== null && !isInRange(box.minutesOfDay)) box.minutesOfDay = null;
878
+
879
+ updateValue();
880
+ updateField();
881
+ renderPanel();
882
+
883
+ if (box.inline == 1) {
884
+ // WHY: Layout is not ready while the page is being created. Scroll after it.
885
+ box.after(0, function () {
886
+ scrollToSelected();
887
+ refreshScrollBars();
888
+ });
889
+ }
890
+
891
+ return endObject(box);
892
+
893
+ };
894
+
895
+ // *** STATIC FUNCTIONS AND DATA:
896
+
897
+ TimePicker.languages = {
898
+ en: {
899
+ placeholder: "Select time",
900
+ hour: "Hour",
901
+ minute: "Minute",
902
+ now: "Now",
903
+ clear: "Clear",
904
+ },
905
+ tr: {
906
+ placeholder: "Saat seçin",
907
+ hour: "Saat",
908
+ minute: "Dakika",
909
+ now: "Şimdi",
910
+ clear: "Temizle",
911
+ },
912
+ };
913
+ // NOTE: Add a new language: TimePicker.languages.de = { ... }
914
+
915
+ // Converts "HH:mm" (or "H:mm", "HH:mm:ss"), a Date or minutes from 00:00 to minutes from 00:00 (0 - 1439). Returns null if not valid.
916
+ TimePicker.parse = function (value) {
917
+
918
+ if (value === null || value === undefined || value === "") return null;
919
+
920
+ if (typeof value === "number") {
921
+ return (Number.isInteger(value) && value >= 0 && value < 1440) ? value : null;
922
+ }
923
+
924
+ if (value instanceof Date) {
925
+ return (isNaN(value)) ? null : value.getHours() * 60 + value.getMinutes();
926
+ }
927
+
928
+ const match = /^(\d{1,2}):(\d{2})(:\d{2})?$/.exec(String(value).trim());
929
+ if (!match) return null;
930
+
931
+ const hours = basic.num(match[1]);
932
+ const minutes = basic.num(match[2]);
933
+ if (hours > 23 || minutes > 59) return null;
934
+
935
+ return hours * 60 + minutes;
936
+
937
+ };
938
+ // USAGE: TimePicker.parse("19:30") -> 1170, TimePicker.parse(1170) -> 1170
939
+
940
+ // Formats minutes from 00:00. Tokens: HH, H, hh, h, mm, A (AM/PM), a (am/pm)
941
+ TimePicker.format = function (minutesOfDay, format = "HH:mm") {
942
+
943
+ if (minutesOfDay === null || minutesOfDay === undefined) return "";
944
+
945
+ const hours = Math.floor(minutesOfDay / 60);
946
+ const minutes = minutesOfDay % 60;
947
+ const hours12 = (hours % 12) || 12;
948
+
949
+ const tokens = {
950
+ HH: String(basic.twoDigitFormat(hours)),
951
+ H: String(hours),
952
+ hh: String(basic.twoDigitFormat(hours12)),
953
+ h: String(hours12),
954
+ mm: String(basic.twoDigitFormat(minutes)),
955
+ A: (hours < 12) ? "AM" : "PM",
956
+ a: (hours < 12) ? "am" : "pm",
957
+ };
958
+
959
+ return format.replace(/HH|H|hh|h|mm|A|a/g, function (token) {
960
+ return tokens[token];
961
+ });
962
+
963
+ };
964
+ // USAGE: TimePicker.format(1170, "h:mm A") -> "7:30 PM"
965
+
966
+ // *** STYLE PACKAGES:
967
+ // USAGE: TimePicker({ styleName: "dark" })
968
+ // USAGE: TimePicker({ styleName: "dark", style: { field: { round: 4 } } }) // Change only some keys.
969
+ // USAGE: TimePicker({ style: TimePicker.styles.dark }) // The same as styleName: "dark". (The package is copied, never changed.)
970
+ // NOTE: A new package needs only the keys that differ from the default (classic) style.
971
+ // USAGE: TimePicker.styles.myStyle = { field: { round: 4 } };
972
+ TimePicker.styles = {
973
+
974
+ // White, dark text, a soft line.
975
+ light: TimePickerDefaults.style,
976
+
977
+ // Dark theme, same colors as SelectBox "dark".
978
+ dark: {
979
+ field: { color: "#232322", borderColor: "rgba(255, 255, 255, 0.10)", round: 8 },
980
+ fieldHover: { borderColor: "rgba(255, 255, 255, 0.30)" },
981
+ fieldFocus: { borderColor: "#65A293" },
982
+ fieldText: { fontSize: 15, textColor: "rgba(255, 255, 255, 0.90)" },
983
+ placeholder: { textColor: "rgba(255, 255, 255, 0.40)" },
984
+ icon: { color: "rgba(255, 255, 255, 0.55)" },
985
+ panel: { color: "#232322", borderColor: "rgba(255, 255, 255, 0.12)", shadow: "0 8px 24px rgba(0, 0, 0, 0.5)" },
986
+ columnTitle: { textColor: "rgba(255, 255, 255, 0.45)", activeTextColor: "rgba(255, 255, 255, 0.90)" },
987
+ scrollBar: { bar_color: "#FFFFFF", bar_mouseOverColor: "#FFFFFF" },
988
+ cell: { textColor: "rgba(255, 255, 255, 0.85)", hoverColor: "rgba(255, 255, 255, 0.08)" },
989
+ selectedCell: { color: "#3D7A6B", textColor: "#FFFFFF" },
990
+ disabledCell: { textColor: "rgba(255, 255, 255, 0.20)" },
991
+ footerButton: { textColor: "#65A293" },
992
+ divider: { color: "rgba(255, 255, 255, 0.08)" },
993
+ },
994
+
995
+ };
996
+ TimePicker.styles.classic = TimePicker.styles.light; // the old name of light: the pages made with it keep their look
997
+
998
+ // The line clock of the minimal field (24 x 24 drawing, as the icons of the minimal SearchInput)
999
+ TimePicker.MINIMAL_ICON = '<svg viewBox="0 0 24 24" width="100%" height="100%" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display: block">' +
1000
+ '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>';
1001
+
1002
+ // The minimal theme (_designs/minimal-theme.htm): a 28 px field as the other minimal fields (a 14 px line icon); the
1003
+ // columns of the hours
1004
+ // and the minutes on the ground of the window with a line and no shadow, 28 px cells: the chosen one in ink (the one fill),
1005
+ // a faint fill under the mouse, a thin scroll bar. minimalDark: the same on a dark window.
1006
+ TimePicker.createMinimalStyle = function (colors) {
1007
+ return {
1008
+ height: 28,
1009
+ style: {
1010
+ field: { color: "transparent", border: 1, borderColor: colors.edge, round: 4, padding: [10, 0] },
1011
+ fieldHover: { borderColor: colors.edgeHover },
1012
+ fieldFocus: { borderColor: colors.ink },
1013
+ fieldText: { fontSize: 13, textColor: colors.text },
1014
+ placeholder: { textColor: colors.faintText },
1015
+ icon: { color: colors.softText, svg: TimePicker.MINIMAL_ICON, size: 14 },
1016
+ panel: { color: colors.ground, border: 1, borderColor: colors.line, round: 4, padding: 8, shadow: "none" },
1017
+ column: { gap: 4, barSpace: 14 }, // WHY barSpace: the bar must not cross the ink of the chosen hour
1018
+ columnTitle: { fontSize: 11, textColor: colors.softText, activeTextColor: colors.text },
1019
+ scrollBar: { bar_color: colors.scrollBar, bar_mouseOverColor: colors.scrollBar, bar_width: 3, bar_opacity: 0.3, bar_mouseOverOpacity: 0.6 },
1020
+ cell: { width: 52, height: 28, round: 4, fontSize: 13, textColor: colors.text, hoverColor: colors.hover },
1021
+ selectedCell: { color: colors.ink, textColor: colors.onInk },
1022
+ disabledCell: { textColor: colors.off },
1023
+ footerButton: { fontSize: 12, textColor: colors.ink },
1024
+ divider: { color: colors.line },
1025
+ disabled: { opacity: 0.4 },
1026
+ },
1027
+ };
1028
+ };
1029
+ TimePicker.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", onInk: "#FFFFFF", hover: Black(0.05), off: Black(0.25), scrollBar: "#141414" };
1030
+ TimePicker.styles.minimal = TimePicker.createMinimalStyle(TimePicker.MINIMAL_COLORS);
1031
+ TimePicker.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", onInk: "#1A1A19", hover: White(0.07), off: White(0.25), scrollBar: "#FFFFFF" };
1032
+ TimePicker.styles.minimalDark = TimePicker.createMinimalStyle(TimePicker.MINIMAL_DARK_COLORS);