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,753 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Stepper - v26.09
6
+
7
+ UI COMPONENT TEMPLATE
8
+ - A number stepper: [ − ] value [ + ].
9
+ - minValue, maxValue, step and precision (decimals). Ex: 0.5 kg steps, 0.25 hours.
10
+ - Unit text after the value ("kg", "%", "pcs") and a valueFormat() for your own text ("1,250").
11
+ - Editable: click the value and type a number. Enter or blur applies it, Escape cancels. (editable: 1)
12
+ - Press and hold a button: the value keeps changing, faster after a while.
13
+ - Keyboard: ArrowUp / ArrowDown one step, PageUp / PageDown ten steps, Home / End min / max.
14
+ - wrap: 1 -> After max comes min (Ex: hours 0-23). Otherwise the buttons are disabled at the limits.
15
+ - Layout: "horizontal" (buttons at the sides, default) or "compact" (both buttons at the right, stacked).
16
+ - Everything is drawn with code (no image files needed). Accessibility: role="spinbutton", aria-valuenow...
17
+ - onChange is NOT called when the component is created or when the value is set with silent: 1.
18
+ - A line around the buttons: style.button.border and borderColor (0 and "transparent" by default: no line).
19
+ - style.button.opacity (1) / disabledOpacity: a button that can / can not be clicked (at min / max). fadeDuration:
20
+ the time of the fade between them (s). 0: at once (the default).
21
+ - Style packages: "light" (default; the old name "classic" works too), "modern", "dark", "ozden", "ozdenDark". Select with styleName. (Stepper.styles)
22
+ -- "ozden": for a 600 px design. "ozdenDark": ozden on a dark page.
23
+ It is a package of params (basic.js v26.10.27): it also gives the size, 150 x 50.
24
+
25
+ USAGE:
26
+ const qty = Stepper({ value: 1, minValue: 1, maxValue: 10, onChange: (self) => println(self.value) });
27
+ qty.setValue(5); // onChange is called
28
+ qty.setValue(5, 1); // silent
29
+ Stepper({ value: 2.5, minValue: 0, maxValue: 20, step: 0.5, precision: 1, unitText: " kg" });
30
+ Stepper({ value: 50, minValue: 0, maxValue: 100, step: 5, unitText: "%", editable: 0 });
31
+ Stepper({ value: 9, minValue: 0, maxValue: 23, wrap: 1, valueFormat: (value) => String(value).padStart(2, "0") + ":00" });
32
+ Stepper({ layout: "compact", width: 140 });
33
+ Stepper({ style: { button: { border: 1, borderColor: Black(0.3) } } }); // A line around the buttons
34
+ Stepper({ styleName: "ozden", value: 1, minValue: 1, maxValue: 10 });
35
+
36
+ Started Date: September 2026
37
+ Webpage: https://bug7a.github.io/js-components/
38
+
39
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
40
+ Licensed under the Apache License, Version 2.0
41
+ SPDX-License-Identifier: Apache-2.0
42
+
43
+ */
44
+
45
+ "use strict";
46
+
47
+ // Default values:
48
+ const StepperDefaults = {
49
+ key: "0",
50
+ width: 150,
51
+ height: 44,
52
+ value: 1,
53
+ minValue: 0,
54
+ maxValue: 10,
55
+ step: 1,
56
+ precision: 0, // Decimals shown and used for rounding. (step: 0.5 -> precision: 1)
57
+ unitText: "", // After the value. Ex: " kg" (with the space)
58
+ editable: 1, // 1: The value can be typed.
59
+ wrap: 0, // 1: After max comes min, before min comes max.
60
+ holdToRepeat: 1, // 1: Press and hold a button to change the value continuously.
61
+ layout: "horizontal", // "horizontal": [-] value [+], "compact": value [-+] stacked at the right (Only at create time)
62
+ enabled: 1,
63
+ ariaLabel: "Value",
64
+ valueFormat: function (value, self) { return self.formatNumber(value) + self.unitText; }, // Text of the value
65
+ onChange: function (self) { }, // self.value
66
+ onMinReached: function (self) { }, // Called when the value arrives at min
67
+ onMaxReached: function (self) { }, // Called when the value arrives at max
68
+ styleName: "light", // "light" ("classic": its old name), "modern", "dark", "ozden", "ozdenDark", "minimal", "minimalDark" or a name added to Stepper.styles
69
+ style: { // Light style package (default)
70
+ box: {
71
+ color: White(1),
72
+ border: 1,
73
+ borderColor: Black(0.2),
74
+ round: 8,
75
+ padding: 3, // Space between the border and the buttons
76
+ },
77
+ boxFocus: {
78
+ borderColor: "#141414",
79
+ },
80
+ button: {
81
+ width: 36, // horizontal layout (compact: the width of the stacked column)
82
+ color: Black(0.05),
83
+ hoverColor: Black(0.1),
84
+ activeColor: Black(0.16),
85
+ border: 0, // px: a line around the buttons. 0: no line
86
+ borderColor: "transparent",
87
+ round: 6,
88
+ iconColor: "#141414",
89
+ iconSize: 14,
90
+ opacity: 1, // A button that can be clicked
91
+ disabledOpacity: 0.3, // At min / max (wrap: 0) and when the stepper is disabled
92
+ fadeDuration: 0, // s: the buttons fade between opacity and disabledOpacity in this time. 0: at once
93
+ },
94
+ value: {
95
+ fontSize: 17,
96
+ textColor: "#141414",
97
+ fontFamily: "", // "": Default. Ex: "opensans-bold"
98
+ },
99
+ input: { // While editing
100
+ color: Black(0.04),
101
+ textColor: "#141414",
102
+ round: 4,
103
+ },
104
+ disabled: {
105
+ opacity: 0.5,
106
+ },
107
+ }
108
+ };
109
+
110
+ const Stepper = function (params = {}) {
111
+
112
+ // Merge style package: params.style > Stepper.styles[styleName] > StepperDefaults.style (light)
113
+ basic.applyStylePackage(params, Stepper.styles, StepperDefaults);
114
+
115
+ // Merge params:
116
+ mergeIntoIfMissing(params, StepperDefaults);
117
+
118
+ // Edit params, if needed:
119
+ const _bs = params.style.box;
120
+ params.color = _bs.color;
121
+ params.border = _bs.border;
122
+ params.borderColor = _bs.borderColor;
123
+ params.round = _bs.round;
124
+ const startValue = params.value;
125
+
126
+ // BOX: Component container
127
+ let box = startObject(params);
128
+
129
+ // *** PRIVATE VARIABLES:
130
+ const _s = box.style;
131
+ const isCompact = (box.layout === "compact");
132
+ let isEditing = 0;
133
+ let cancelHold = null; // (box.after: stopped by remove())
134
+ let holdCount = 0;
135
+ let isFocused = 0;
136
+ const PAGE_STEPS = 10; // PageUp / PageDown
137
+ // Hold to repeat: the first repeat waits (a normal click does not repeat), then it gets faster.
138
+ const HOLD_FIRST_DELAY = 400;
139
+ const HOLD_SLOW_DELAY = 400;
140
+ const HOLD_MEDIUM_DELAY = 120;
141
+ const HOLD_FAST_DELAY = 50;
142
+ const HOLD_SLOW_COUNT = 3; // Repeats before the medium speed
143
+ const HOLD_MEDIUM_COUNT = 12; // Repeats before the fast speed
144
+ const STACK_GAP = 2; // Between the stacked buttons (compact)
145
+ const BUTTON_COLOR_MOTION = "background-color 0.15s"; // The hover / press color of the buttons
146
+
147
+ // *** PUBLIC VARIABLES:
148
+ // NOTE: Default values are also public variables. (box.value, box.minValue, box.maxValue, box.step)
149
+
150
+ // *** PRIVATE FUNCTIONS:
151
+
152
+ const roundValue = function (value) {
153
+ const factor = Math.pow(10, Math.max(0, box.precision));
154
+ return Math.round(value * factor) / factor;
155
+ };
156
+
157
+ // Keeps the value in [min, max] (or wraps it).
158
+ const clampValue = function (value) {
159
+ value = Number(value);
160
+ if (isNaN(value)) value = box.minValue;
161
+ if (box.wrap == 1) {
162
+ const range = box.maxValue - box.minValue + box.step;
163
+ if (range > 0) {
164
+ if (value > box.maxValue) value = box.minValue + ((value - box.maxValue - box.step) % range);
165
+ if (value < box.minValue) value = box.maxValue - ((box.minValue - value - box.step) % range);
166
+ }
167
+ }
168
+ return roundValue(Math.min(Math.max(value, box.minValue), box.maxValue));
169
+ };
170
+
171
+ const canDecrease = function () {
172
+ return box.enabled == 1 && (box.wrap == 1 || box.value > box.minValue);
173
+ };
174
+
175
+ const canIncrease = function () {
176
+ return box.enabled == 1 && (box.wrap == 1 || box.value < box.maxValue);
177
+ };
178
+
179
+ const paintButton = function (button, isEnabled) {
180
+ button.css.opacity = String((isEnabled) ? _s.button.opacity : _s.button.disabledOpacity);
181
+ button.cursor = (isEnabled) ? "pointer" : "default";
182
+ button.aria = { disabled: (isEnabled) ? "false" : "true" };
183
+ if (!isEnabled) button.color = _s.button.color;
184
+ };
185
+
186
+ const updateView = function () {
187
+ const valueText = box.valueFormat(box.value, box);
188
+ box.lblValue.plainText = valueText;
189
+ paintButton(box.btnMinus, canDecrease());
190
+ paintButton(box.btnPlus, canIncrease());
191
+ box.aria = {
192
+ valuenow: String(box.value),
193
+ valuemin: String(box.minValue),
194
+ valuemax: String(box.maxValue),
195
+ valuetext: valueText,
196
+ };
197
+ };
198
+
199
+ const updateBorder = function () {
200
+ box.borderColor = (isFocused || isEditing) ? _s.boxFocus.borderColor : _s.box.borderColor;
201
+ };
202
+
203
+ // Changes the value by "steps" steps. Returns 1 when the value changed.
204
+ const stepValue = function (steps, silent = 0) {
205
+ if (box.enabled != 1) return 0;
206
+ const next = clampValue(box.value + steps * box.step);
207
+ if (next === box.value) return 0;
208
+ box.setValue(next, silent);
209
+ return 1;
210
+ };
211
+
212
+ // *** HOLD TO REPEAT:
213
+
214
+ const getHoldDelay = function () {
215
+ if (holdCount < HOLD_SLOW_COUNT) return HOLD_SLOW_DELAY;
216
+ if (holdCount < HOLD_MEDIUM_COUNT) return HOLD_MEDIUM_DELAY;
217
+ return HOLD_FAST_DELAY;
218
+ };
219
+
220
+ const startHold = function (direction) {
221
+ stopHold();
222
+ if (box.holdToRepeat != 1) return;
223
+ holdCount = 0;
224
+ const tick = function () {
225
+ holdCount++;
226
+ const delay = getHoldDelay();
227
+ if (!stepValue(direction)) {
228
+ stopHold();
229
+ return;
230
+ }
231
+ cancelHold = box.after(delay, tick);
232
+ };
233
+ cancelHold = box.after(HOLD_FIRST_DELAY, tick);
234
+ };
235
+
236
+ const stopHold = function () {
237
+ if (cancelHold) cancelHold();
238
+ cancelHold = null;
239
+ };
240
+
241
+ // *** EDIT (type the value):
242
+
243
+ const startEdit = function () {
244
+ if (box.editable != 1 || box.enabled != 1 || isEditing) return;
245
+ isEditing = 1;
246
+ box.input.text = box.formatNumber(box.value);
247
+ box.lblValue.visible = 0;
248
+ box.input.visible = 1;
249
+ box.input.inputElement.focus({ preventScroll: true });
250
+ box.input.inputElement.select();
251
+ updateBorder();
252
+ };
253
+
254
+ // apply: 1 -> The typed value is used. 0 -> Cancel.
255
+ const endEdit = function (apply) {
256
+ // WHY: Chrome fires blur when a focused field is removed: a half typed value went to onChange of a field that
257
+ // was removed (a panel built again while the user typed)
258
+ if (!isEditing || box.isRemoved) return;
259
+ isEditing = 0;
260
+ box.input.visible = 0;
261
+ box.lblValue.visible = 1;
262
+ if (apply) {
263
+ const text = String(box.input.text).trim().replace(",", ".");
264
+ const value = parseFloat(text);
265
+ if (!isNaN(value)) box.setValue(value);
266
+ }
267
+ updateBorder();
268
+ updateView();
269
+ };
270
+
271
+ // While editing: Enter applies, Escape cancels, the arrows apply and step.
272
+ const onEditKeyDown = function (event) {
273
+ const key = event.key;
274
+ if (key === "Enter" || key === "Escape") {
275
+ event.preventDefault();
276
+ endEdit((key === "Enter") ? 1 : 0);
277
+ box.focus();
278
+ return;
279
+ }
280
+ if (key === "ArrowUp" || key === "ArrowDown") {
281
+ event.preventDefault();
282
+ endEdit(1);
283
+ stepValue((key === "ArrowUp") ? 1 : -1);
284
+ startEdit();
285
+ }
286
+ };
287
+
288
+ const isNumberKey = function (key) {
289
+ return key.length === 1 && /[\d\-.,]/.test(key);
290
+ };
291
+
292
+ const onKeyDown = function (self, event) {
293
+
294
+ if (box.enabled != 1) return;
295
+ const key = event.key;
296
+
297
+ if (isEditing) {
298
+ onEditKeyDown(event);
299
+ return;
300
+ }
301
+
302
+ switch (key) {
303
+ case "ArrowUp":
304
+ case "ArrowRight":
305
+ event.preventDefault();
306
+ stepValue(1);
307
+ break;
308
+ case "ArrowDown":
309
+ case "ArrowLeft":
310
+ event.preventDefault();
311
+ stepValue(-1);
312
+ break;
313
+ case "PageUp":
314
+ event.preventDefault();
315
+ stepValue(PAGE_STEPS);
316
+ break;
317
+ case "PageDown":
318
+ event.preventDefault();
319
+ stepValue(-PAGE_STEPS);
320
+ break;
321
+ case "Home":
322
+ event.preventDefault();
323
+ box.setValue(box.minValue);
324
+ break;
325
+ case "End":
326
+ event.preventDefault();
327
+ box.setValue(box.maxValue);
328
+ break;
329
+ case "Enter":
330
+ case " ":
331
+ if (box.editable != 1) break;
332
+ event.preventDefault();
333
+ startEdit();
334
+ break;
335
+ default:
336
+ // Typing a digit starts the edit with that digit.
337
+ if (box.editable != 1 || !isNumberKey(key)) break;
338
+ event.preventDefault();
339
+ startEdit();
340
+ box.input.text = key;
341
+ }
342
+
343
+ };
344
+
345
+ // *** PUBLIC FUNCTIONS:
346
+
347
+ // silent: 1 -> onChange is not called.
348
+ box.setValue = function (value, silent = 0) {
349
+ const next = clampValue(value);
350
+ const changed = (next !== box.value);
351
+ box.value = next;
352
+ updateView();
353
+ if (changed && !silent) {
354
+ box.onChange(box);
355
+ if (box.value === box.minValue) box.onMinReached(box);
356
+ if (box.value === box.maxValue) box.onMaxReached(box);
357
+ }
358
+ return box.value;
359
+ };
360
+ // USAGE: get: stepper.value, set: stepper.setValue(5) // Out of range values are clamped.
361
+
362
+ box.getValue = function () {
363
+ return box.value;
364
+ };
365
+
366
+ box.increase = function (steps = 1) {
367
+ return stepValue(steps);
368
+ };
369
+ // USAGE: stepper.increase() or stepper.increase(5)
370
+
371
+ box.decrease = function (steps = 1) {
372
+ return stepValue(-steps);
373
+ };
374
+
375
+ box.setMinValue = function (value) {
376
+ box.minValue = Number(value) || 0;
377
+ if (box.maxValue < box.minValue) box.maxValue = box.minValue;
378
+ box.setValue(box.value, 1);
379
+ };
380
+
381
+ box.setMaxValue = function (value) {
382
+ box.maxValue = Number(value) || 0;
383
+ if (box.minValue > box.maxValue) box.minValue = box.maxValue;
384
+ box.setValue(box.value, 1);
385
+ };
386
+
387
+ box.setRange = function (minValue, maxValue) {
388
+ box.minValue = Number(minValue) || 0;
389
+ box.maxValue = Math.max(box.minValue, Number(maxValue) || 0);
390
+ box.setValue(box.value, 1);
391
+ };
392
+ // USAGE: stepper.setRange(0, 100)
393
+
394
+ box.setStep = function (step) {
395
+ box.step = Math.abs(Number(step)) || 1;
396
+ updateView();
397
+ };
398
+
399
+ box.setPrecision = function (precision) {
400
+ box.precision = Math.max(0, Number(precision) || 0);
401
+ box.setValue(box.value, 1);
402
+ };
403
+
404
+ box.setUnitText = function (text) {
405
+ box.unitText = text || "";
406
+ updateView();
407
+ };
408
+ // USAGE: stepper.setUnitText(" kg")
409
+
410
+ box.setEnabled = function (enabled) {
411
+ box.enabled = basic.isOn(enabled) ? 1 : 0;
412
+ const isEnabled = (box.enabled == 1);
413
+ if (!isEnabled) {
414
+ endEdit(0);
415
+ stopHold();
416
+ }
417
+ box.css.opacity = (isEnabled) ? "1" : String(_s.disabled.opacity);
418
+ box.tabIndex = (isEnabled) ? 0 : -1;
419
+ box.aria = { disabled: (isEnabled) ? "false" : "true" };
420
+ updateView();
421
+ };
422
+ // USAGE: get: stepper.enabled, set: stepper.setEnabled(0)
423
+
424
+ // Number text with the precision: 2.5 -> "2.5", 3 -> "3" (precision 0), 3 -> "3.0" (precision 1)
425
+ box.formatNumber = function (value) {
426
+ return Number(value).toFixed(Math.max(0, box.precision));
427
+ };
428
+
429
+ box.focus = function () {
430
+ box.elem.focus({ preventScroll: true });
431
+ };
432
+
433
+ box.refresh = function () {
434
+ updateView();
435
+ };
436
+
437
+
438
+ // *** OBJECT VIEW:
439
+
440
+ box.role = "spinbutton";
441
+ box.aria = { label: box.ariaLabel };
442
+ box.css = {
443
+ outline: "none",
444
+ boxSizing: "border-box",
445
+ transition: "border-color 0.15s",
446
+ };
447
+ box.clickable = 1;
448
+
449
+ const getButtonSvg = function (icon) {
450
+ if (icon === "plus") return Stepper.getPlusSvg(_s.button.iconColor, _s.button.iconSize);
451
+ return Stepper.getMinusSvg(_s.button.iconColor, _s.button.iconSize);
452
+ };
453
+
454
+ // LABEL: Button (- or +), drawn with SVG
455
+ const createStepButton = function (icon, ariaLabel, isStacked) {
456
+ const btn = Label({
457
+ text: getButtonSvg(icon),
458
+ width: (isStacked) ? "100%" : _s.button.width,
459
+ height: (isStacked) ? "auto" : "100%",
460
+ color: _s.button.color,
461
+ border: _s.button.border,
462
+ borderColor: _s.button.borderColor,
463
+ round: _s.button.round,
464
+ clickable: 1,
465
+ });
466
+ btn.elem.style.display = "flex";
467
+ btn.css = { alignItems: "center", justifyContent: "center" };
468
+ btn.lineHeight = "0";
469
+ btn.shrink = 0;
470
+ btn.cursor = "pointer";
471
+ btn.css = { userSelect: "none", transition: BUTTON_COLOR_MOTION };
472
+ // WHY: setMotion() starts after the first paint: a button that starts at min / max does not fade at the first view.
473
+ if (_s.button.fadeDuration > 0) btn.setMotion(BUTTON_COLOR_MOTION + ", opacity " + _s.button.fadeDuration + "s");
474
+ if (isStacked) btn.css.flex = "1 1 0"; // WHY: After shrink (flex sets it again): the stacked buttons share the height.
475
+ btn.role = "button";
476
+ btn.aria = { label: ariaLabel };
477
+ return btn;
478
+ };
479
+
480
+ // GROUP: Row (buttons and value)
481
+ box.row = HGroup({
482
+ width: "100%",
483
+ height: "100%",
484
+ align: "left center",
485
+ gap: _s.box.padding,
486
+ padding: _s.box.padding,
487
+ position: "relative",
488
+ });
489
+ box.row.css.boxSizing = "border-box";
490
+
491
+ if (!isCompact) box.btnMinus = createStepButton("minus", "Decrease", 0);
492
+
493
+ // BOX: Value area (label, and the input while editing)
494
+ box.valueBox = startBox({ width: "auto", height: "100%", color: "transparent" });
495
+ box.valueBox.css = { flex: "1 1 0", minWidth: "0" };
496
+ box.valueBox.cursor = (box.editable == 1) ? "text" : "default";
497
+ box.valueBox.clickable = 1;
498
+
499
+ // LABEL: Value text
500
+ box.lblValue = Label({
501
+ left: 0,
502
+ top: 0,
503
+ width: "100%",
504
+ height: "100%",
505
+ fontSize: _s.value.fontSize,
506
+ textColor: _s.value.textColor,
507
+ textAlign: "center",
508
+ });
509
+ box.lblValue.elem.style.display = "flex";
510
+ box.lblValue.css = { alignItems: "center", justifyContent: "center" };
511
+ box.lblValue.ellipsis = 1;
512
+ box.lblValue.css.userSelect = "none";
513
+ if (_s.value.fontFamily) box.lblValue.css.fontFamily = _s.value.fontFamily;
514
+
515
+ // INPUT: Typing the value (hidden until the edit starts)
516
+ box.input = Input({
517
+ left: 0,
518
+ top: 0,
519
+ width: "100%",
520
+ height: "100%",
521
+ minimal: 1,
522
+ color: _s.input.color,
523
+ fontSize: _s.value.fontSize,
524
+ textColor: _s.input.textColor,
525
+ textAlign: "center",
526
+ round: _s.input.round,
527
+ });
528
+ box.input.inputElement.style.padding = "0px 4px";
529
+ box.input.inputElement.style.width = "100%";
530
+ box.input.inputElement.style.height = "100%";
531
+ box.input.inputElement.style.boxSizing = "border-box";
532
+ box.input.inputElement.style.borderRadius = _s.input.round + "px";
533
+ box.input.inputElement.style.backgroundColor = _s.input.color;
534
+ box.input.inputElement.setAttribute("inputmode", "decimal");
535
+ box.input.inputElement.setAttribute("aria-label", box.ariaLabel);
536
+ if (_s.value.fontFamily) box.input.inputElement.style.fontFamily = _s.value.fontFamily;
537
+ box.input.visible = 0;
538
+
539
+ endBox();
540
+
541
+ if (isCompact) {
542
+ // GROUP: Stacked buttons (+ over -)
543
+ box.stack = VGroup({ width: _s.button.width, height: "100%", align: "center top", gap: STACK_GAP });
544
+ box.stack.shrink = 0;
545
+ box.stack.css.alignItems = "stretch";
546
+ box.btnPlus = createStepButton("plus", "Increase", 1);
547
+ box.btnMinus = createStepButton("minus", "Decrease", 1);
548
+ endGroup();
549
+ } else {
550
+ box.btnPlus = createStepButton("plus", "Increase", 0);
551
+ }
552
+
553
+ endGroup();
554
+
555
+ // *** OBJECT INIT CODE:
556
+
557
+ const bindButton = function (btn, direction) {
558
+ const isEnabled = function () { return (direction > 0) ? canIncrease() : canDecrease(); };
559
+ btn.on("mouseenter", function () { if (isEnabled()) btn.color = _s.button.hoverColor; });
560
+ btn.on("mouseleave", function () {
561
+ btn.color = _s.button.color;
562
+ stopHold();
563
+ });
564
+ btn.on("mousedown", function (self, event) {
565
+ if (event.button !== 0 || !isEnabled()) return;
566
+ event.preventDefault(); // WHY: Keeps the focus on the stepper, no text selection.
567
+ btn.color = _s.button.activeColor;
568
+ endEdit(1);
569
+ stepValue(direction);
570
+ startHold(direction);
571
+ });
572
+ btn.on("mouseup", function () {
573
+ btn.color = (isEnabled()) ? _s.button.hoverColor : _s.button.color;
574
+ stopHold();
575
+ });
576
+ btn.on("touchstart", function (self, event) {
577
+ if (!isEnabled()) return;
578
+ event.preventDefault();
579
+ endEdit(1);
580
+ stepValue(direction);
581
+ startHold(direction);
582
+ });
583
+ btn.on("touchend", stopHold);
584
+ btn.on("touchcancel", stopHold);
585
+ btn.on("click", function (self, event) {
586
+ event.stopPropagation();
587
+ box.focus();
588
+ });
589
+ };
590
+
591
+ bindButton(box.btnMinus, -1);
592
+ bindButton(box.btnPlus, 1);
593
+ box.listenTo(document, "mouseup", stopHold); // (removed with the box)
594
+ box.listenTo(document, "touchend", stopHold);
595
+
596
+ box.valueBox.on("click", function () { startEdit(); });
597
+ box.input.inputElement.addEventListener("blur", function () { endEdit(1); });
598
+ box.input.inputElement.addEventListener("keydown", function (event) { onKeyDown(box, event); });
599
+
600
+ box.on("keydown", function (self, event) {
601
+ if (event.target === box.input.inputElement) return; // WHY: The input has its own keydown (above).
602
+ onKeyDown(self, event);
603
+ });
604
+ box.on("focus", function () {
605
+ isFocused = 1;
606
+ updateBorder();
607
+ });
608
+ box.on("blur", function () {
609
+ isFocused = 0;
610
+ updateBorder();
611
+ });
612
+ // WHY: A click on the buttons must not open the edit. It is handled in bindButton with stopPropagation.
613
+
614
+ box.minValue = Number(box.minValue) || 0;
615
+ box.maxValue = Number(box.maxValue);
616
+ if (isNaN(box.maxValue)) box.maxValue = box.minValue;
617
+ if (box.maxValue < box.minValue) box.maxValue = box.minValue;
618
+ box.step = Math.abs(Number(box.step)) || 1;
619
+ box.precision = Math.max(0, Number(box.precision) || 0);
620
+ box.value = clampValue(startValue);
621
+ box.setEnabled(box.enabled);
622
+ updateView();
623
+
624
+ return endObject(box);
625
+
626
+ };
627
+
628
+ // *** STATIC FUNCTIONS:
629
+
630
+ // WHY: Label.text uses innerHTML. Texts must not be read as HTML.
631
+ Stepper.escapeHtml = basic.escapeHtml; // (the name is kept: other code may use it)
632
+
633
+ Stepper.getPlusSvg = function (color, size) {
634
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="' + color + '" stroke-width="2.6" stroke-linecap="round"><path d="M12 5v14M5 12h14"/></svg>';
635
+ };
636
+
637
+ Stepper.getMinusSvg = function (color, size) {
638
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="' + color + '" stroke-width="2.6" stroke-linecap="round"><path d="M5 12h14"/></svg>';
639
+ };
640
+
641
+ // *** STYLE PACKAGES:
642
+ // USAGE: Stepper({ styleName: "modern" })
643
+ // USAGE: Stepper({ styleName: "dark", style: { button: { iconColor: "tomato" } } }) // Change only some keys.
644
+ // USAGE: Stepper({ style: Stepper.styles.dark }) // The same as styleName: "dark". (The package is copied, never changed.)
645
+ // NOTE: A new package needs only the keys that differ from the default (classic) style.
646
+ // USAGE: Stepper.styles.myStyle = { button: { color: "gold" } };
647
+ // NOTE: A package with its own "style" key is a package of params (basic.js v26.10.27): its other keys fill the
648
+ // params you did not give (ozden: the size). Select it with styleName (style: Stepper.styles.ozden.style
649
+ // gives only its look).
650
+ // USAGE: Stepper({ styleName: "ozden", width: 180 }) // A param you give wins over the package.
651
+ Stepper.styles = {
652
+
653
+ // Gray buttons in a white box.
654
+ light: StepperDefaults.style,
655
+
656
+ // Round pill, cadetblue buttons. Same colors as the modern CheckBox, RadioButton, ProgressBar and Tabs.
657
+ modern: {
658
+ box: { color: White(1), border: 1, borderColor: "#D9DADB", round: 100, padding: 4 },
659
+ boxFocus: { borderColor: "cadetblue" },
660
+ button: { width: 36, color: "#DFECEC", hoverColor: "#CFE2E2", activeColor: "cadetblue", round: 100, iconColor: "#2F5F61", iconSize: 14, disabledOpacity: 0.3 },
661
+ value: { fontSize: 17, textColor: "#2F5F61", fontFamily: "opensans-bold" },
662
+ input: { color: "#EEF5F5", textColor: "#2F5F61", round: 100 },
663
+ disabled: { opacity: 0.5 },
664
+ },
665
+
666
+ // Dark theme, same colors as SelectBox, TagInput and Tabs "dark".
667
+ dark: {
668
+ box: { color: "#232322", border: 1, borderColor: "rgba(255, 255, 255, 0.10)", round: 8, padding: 3 },
669
+ boxFocus: { borderColor: "#65A293" },
670
+ button: { width: 36, color: "rgba(255, 255, 255, 0.08)", hoverColor: "rgba(255, 255, 255, 0.14)", activeColor: "#3D7A6B", round: 6, iconColor: "rgba(255, 255, 255, 0.85)", iconSize: 14, disabledOpacity: 0.3 },
671
+ value: { fontSize: 17, textColor: "rgba(255, 255, 255, 0.90)", fontFamily: "" },
672
+ input: { color: "rgba(255, 255, 255, 0.06)", textColor: "rgba(255, 255, 255, 0.90)", round: 4 },
673
+ disabled: { opacity: 0.4 },
674
+ },
675
+
676
+ // For a 600 px design:
677
+ // round white buttons with a dark line on a transparent box, the value between them; at min / max a button
678
+ // fades to 0.4. (Its name is not "light": that is the default look, and LabelEditor asks for it by name.)
679
+ ozden: {
680
+ width: 150,
681
+ height: 50, // WHY: 42 px buttons (50 - 2 x padding)
682
+ style: {
683
+ box: { color: "transparent", border: 0, round: 100, padding: 4 },
684
+ button: {
685
+ width: 42,
686
+ color: "white",
687
+ hoverColor: "#F4F4F4",
688
+ activeColor: "#E8E8E8",
689
+ border: 1,
690
+ borderColor: "rgba(0, 0, 0, 0.8)",
691
+ round: 21,
692
+ iconColor: "rgba(0, 0, 0, 0.65)",
693
+ iconSize: 24, // WHY: a + 16 px long, with a 2.7 px line
694
+ opacity: 0.9, // the line and the icon are a little lighter
695
+ disabledOpacity: 0.4,
696
+ fadeDuration: 0.2,
697
+ },
698
+ value: { fontSize: 22, textColor: "rgba(0, 0, 0, 0.8)", fontFamily: "" },
699
+ input: { textColor: "rgba(0, 0, 0, 0.8)" },
700
+ },
701
+ },
702
+
703
+ // ozden on a dark page: the same shape; the buttons in the ground of a dark card with a light line (on such a
704
+ // card they are rings, as the white buttons of ozden on white), a light value.
705
+ ozdenDark: {
706
+ width: 150,
707
+ height: 50, // WHY: 42 px buttons (50 - 2 x padding)
708
+ style: {
709
+ box: { color: "transparent", border: 0, round: 100, padding: 4 },
710
+ button: {
711
+ width: 42,
712
+ color: "#232322",
713
+ hoverColor: "#2E2E2D",
714
+ activeColor: "#393938",
715
+ border: 1,
716
+ borderColor: "rgba(255, 255, 255, 0.8)",
717
+ round: 21,
718
+ iconColor: "rgba(255, 255, 255, 0.7)",
719
+ iconSize: 24, // WHY: a + 16 px long, with a 2.7 px line
720
+ opacity: 0.9, // the line and the icon are a little softer
721
+ disabledOpacity: 0.4,
722
+ fadeDuration: 0.2,
723
+ },
724
+ value: { fontSize: 22, textColor: "rgba(255, 255, 255, 0.88)", fontFamily: "" },
725
+ input: { color: "rgba(255, 255, 255, 0.06)", textColor: "rgba(255, 255, 255, 0.88)" },
726
+ },
727
+ },
728
+
729
+ };
730
+ Stepper.styles.classic = Stepper.styles.light; // the old name of light: the pages made with it keep their look
731
+
732
+ // The minimal theme (_designs/minimal-theme.htm): 96 x 28, a line around it (ink while it is focused), no fill; the
733
+ // buttons have no fill either (a faint one under the mouse: a Stepper has no line of its own per button), a 12 px
734
+ // icon, a 13 px value. minimalDark: the same on a dark window.
735
+ Stepper.createMinimalStyle = function (colors) {
736
+ return {
737
+ width: 96,
738
+ height: 28,
739
+ style: {
740
+ box: { color: "transparent", border: 1, borderColor: colors.line, round: 4, padding: 0 },
741
+ boxFocus: { borderColor: colors.ink },
742
+ button: { width: 26, color: "transparent", hoverColor: colors.hover, activeColor: colors.active, border: 0, borderColor: "transparent", round: 3, iconColor: colors.text, iconSize: 12, opacity: 1, disabledOpacity: 0.3, fadeDuration: 0 },
743
+ value: { fontSize: 13, textColor: colors.text, fontFamily: "" },
744
+ input: { color: "transparent", textColor: colors.text, round: 0 },
745
+ disabled: { opacity: 0.4 },
746
+ },
747
+ };
748
+ };
749
+ // WHY a strong line: it shows the field of the stepper (3:1 at least, as WCAG asks of a control)
750
+ Stepper.MINIMAL_COLORS = { ink: "#1F1F1F", text: Black(0.85), line: Black(0.45), hover: Black(0.04), active: Black(0.08) };
751
+ Stepper.styles.minimal = Stepper.createMinimalStyle(Stepper.MINIMAL_COLORS);
752
+ Stepper.MINIMAL_DARK_COLORS = { ink: "#EDEDEB", text: White(0.88), line: White(0.42), hover: White(0.06), active: White(0.1) };
753
+ Stepper.styles.minimalDark = Stepper.createMinimalStyle(Stepper.MINIMAL_DARK_COLORS);