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,229 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Notice - v26.10
6
+
7
+ A short message in the middle of the screen over a soft dark cover: "Process completed", "No internet connection".
8
+ It comes in, stays a moment (displayTime) and goes. The look:
9
+ a round box with a thin line and a soft shadow, a big text, a color by its type, an icon at the left.
10
+ - Notice.show({ messageText, descriptionText, type, iconFile, displayTime }) makes it on page. Only one at a time: a new
11
+ notice takes the place of the one that is seen.
12
+ - type: "info" (white), "warning" (yellow), "error" (red), "note" (blue), "success" (green). Notice.COLORS
13
+ - descriptionText: a smaller second line. The texts are plain text (allowHtml: 1: HTML, only for your own texts).
14
+ - A click (on the cover or the message) or Escape closes it before its time. displayTime 0: it stays until then.
15
+ - Motion: it grows in from a little smaller with a fade in 0.2 s and goes at once; none with reduced motion.
16
+ - Accessibility: role "status" (an error: "alert"), so a screen reader reads it.
17
+
18
+ USAGE:
19
+ Notice.show({ messageText: "Process completed" });
20
+ Notice.show({ messageText: "No internet connection.", descriptionText: "Please, try again later.", type: "warning" });
21
+ Notice.show({ messageText: "Failed to copy", type: "error", iconFile: "../assets/icons/alert.png" });
22
+ const notice = Notice.show({ messageText: "Saving...", displayTime: 0 }); notice.close();
23
+ Notice.close(); // the notice that is seen
24
+
25
+ Started Date: October 2026
26
+ Webpage: https://bug7a.github.io/js-components/
27
+
28
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
29
+ Licensed under the Apache License, Version 2.0
30
+ SPDX-License-Identifier: Apache-2.0
31
+
32
+ */
33
+
34
+ "use strict";
35
+
36
+ // Default values:
37
+ const NoticeDefaults = {
38
+ left: 0,
39
+ top: 0,
40
+ width: "100%",
41
+ height: "100%",
42
+ messageText: "No message",
43
+ descriptionText: "", // "": no second line
44
+ type: "info", // "info", "warning", "error", "note", "success"
45
+ iconFile: "", // "": no icon
46
+ allowHtml: 0, // 1: the texts are HTML (only for your own texts)
47
+ displayTime: 2000, // ms; 0: it stays until a click or Escape
48
+ closeOnClick: 1,
49
+ onClose: function (self) {},
50
+ styleName: "classic", // "classic" or a name added to Notice.styles
51
+ style: { // Classic style package
52
+ cover: { color: "rgba(0, 0, 0, 0.2)", zIndex: 50000 }, // WHY: over the dialogs (Dialog, Modal: 4000 and up), under Tooltip (100000)
53
+ message: { round: 8, border: 2, borderColor: "rgba(0, 0, 0, 0.2)", padding: [24, 18], gap: 20, maxWidth: 480, boxShadow: "0px 0px 12px rgba(0, 0, 0, 0.1)" },
54
+ text: { fontSize: 20, textColor: "rgba(0, 0, 0, 0.8)", fontFamily: "opensans" },
55
+ desc: { fontSize: 17, opacity: 0.8 },
56
+ icon: { size: 28, opacity: 0.95 },
57
+ motion: { startScale: 0.9 }, // it grows in from this size
58
+ },
59
+ };
60
+
61
+ const Notice = function (params = {}) {
62
+
63
+ // Merge style package: params.style > Notice.styles[styleName] > NoticeDefaults.style
64
+ basic.applyStylePackage(params, Notice.styles, NoticeDefaults);
65
+
66
+ // Merge params:
67
+ mergeIntoIfMissing(params, NoticeDefaults);
68
+
69
+ // BOX: Component container (the cover of the page)
70
+ let box = startObject(params);
71
+
72
+ // *** PRIVATE VARIABLES:
73
+ const _s = box.style;
74
+ const SHOW_MOTION = "transform 0.2s, opacity 0.2s";
75
+ let isClosed = 0;
76
+
77
+ // *** PRIVATE FUNCTIONS:
78
+
79
+ const isReducedMotion = function () {
80
+ return window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
81
+ };
82
+
83
+ const setText = function (label, text) {
84
+ if (box.allowHtml == 1) label.text = text;
85
+ else label.plainText = text;
86
+ };
87
+
88
+ // It grows in from a little smaller with a fade (at once: no timer of basic.js).
89
+ const showWithMotion = function () {
90
+ if (isReducedMotion()) return;
91
+ const message = box.message;
92
+ message.opacity = 0;
93
+ message.css = { transform: "scale(" + _s.motion.startScale + ")" };
94
+ box.opacity = 0;
95
+ // WHY: the start look must be drawn before the motion is turned on, or it is seen at once
96
+ void message.elem.offsetHeight;
97
+ message.setMotionNow(SHOW_MOTION);
98
+ box.setMotionNow("opacity 0.2s");
99
+ message.opacity = 1;
100
+ message.css = { transform: "none" };
101
+ box.opacity = 1;
102
+ };
103
+
104
+ // *** PUBLIC FUNCTIONS:
105
+
106
+ // It goes at once.
107
+ box.close = function () {
108
+ if (!box || isClosed) return;
109
+ isClosed = 1;
110
+ if (Notice.current == box) Notice.current = null;
111
+ box.onClose(box);
112
+ box.remove();
113
+ };
114
+ // USAGE: notice.close()
115
+
116
+ // REMOVE: the static Notice.current must not keep a removed notice.
117
+ const superRemove = box.remove;
118
+ box.superRemove = superRemove;
119
+ box.remove = function () {
120
+ if (!box) return;
121
+ if (Notice.current == box) Notice.current = null;
122
+ superRemove.call(box);
123
+ box = null;
124
+ };
125
+
126
+ // *** OBJECT VIEW:
127
+
128
+ const look = Notice.COLORS[box.type] || Notice.COLORS.info;
129
+
130
+ box.color = _s.cover.color;
131
+ box.zIndex = _s.cover.zIndex;
132
+ box.clickable = 1; // WHY: a click on the page under it must not happen while it is seen
133
+ box.role = (box.type == "error") ? "alert" : "status";
134
+ box.aria = { live: (box.type == "error") ? "assertive" : "polite" };
135
+
136
+ // GROUP: Page (the message in the middle)
137
+ HGroup({ align: "center", clipContent: 0 });
138
+
139
+ // GROUP: Message (an icon, the texts)
140
+ box.message = HGroup({
141
+ hug: 1,
142
+ align: "left center",
143
+ gap: _s.message.gap,
144
+ padding: _s.message.padding,
145
+ color: look.color,
146
+ round: _s.message.round,
147
+ border: _s.message.border,
148
+ borderColor: _s.message.borderColor,
149
+ boxShadow: _s.message.boxShadow,
150
+ css: { maxWidth: "min(" + _s.message.maxWidth + "px, calc(100% - 40px))" },
151
+ });
152
+
153
+ if (box.iconFile) {
154
+ // ICON
155
+ box.icon = Icon({ width: _s.icon.size, height: _s.icon.size, opacity: _s.icon.opacity });
156
+ box.icon.load(box.iconFile);
157
+ box.icon.shrink = 0;
158
+ }
159
+
160
+ // GROUP: Texts
161
+ VGroup({ hug: 1, align: (box.iconFile ? "left" : "center") + " center", gap: 2 });
162
+ that.css = { minWidth: "0px" };
163
+
164
+ // LABEL: Message
165
+ box.lblMessage = Label({ ..._s.text, textColor: look.textColor || _s.text.textColor, textAlign: box.iconFile ? "left" : "center" });
166
+ box.lblMessage.css = { whiteSpace: "normal" };
167
+ setText(box.lblMessage, box.messageText);
168
+
169
+ // LABEL: Second line
170
+ box.lblDesc = Label({ ..._s.text, fontSize: _s.desc.fontSize, opacity: _s.desc.opacity, textColor: look.textColor || _s.text.textColor, textAlign: box.iconFile ? "left" : "center" });
171
+ box.lblDesc.css = { whiteSpace: "normal" };
172
+ setText(box.lblDesc, box.descriptionText);
173
+ box.lblDesc.visible = (box.descriptionText !== "" && box.descriptionText !== null && box.descriptionText !== undefined) ? 1 : 0; // (0 is a text too)
174
+
175
+ endGroup();
176
+
177
+ endGroup();
178
+
179
+ endGroup();
180
+
181
+ // *** OBJECT INIT CODE:
182
+
183
+ if (box.closeOnClick == 1) box.on("click", function () { box.close(); });
184
+ // WHY capture on window: it runs before the Escape of a Dialog (document) under the notice; only the notice closes
185
+ box.listenTo(window, "keydown", function (self, event) {
186
+ if (event.key != "Escape") return;
187
+ event.preventDefault();
188
+ event.stopImmediatePropagation();
189
+ box.close();
190
+ }, true);
191
+ if (box.displayTime > 0) box.after(box.displayTime, function () { box.close(); });
192
+
193
+ showWithMotion();
194
+
195
+ return endObject(box);
196
+
197
+ };
198
+
199
+ // *** STATIC VARIABLES AND FUNCTIONS:
200
+
201
+ // The colors of the types. textColor: "" -> style.text.textColor
202
+ Notice.COLORS = {
203
+ info: { color: "white", textColor: "" },
204
+ warning: { color: "#FFD541", textColor: "#141414" },
205
+ error: { color: "#EE7553", textColor: "#141414" },
206
+ note: { color: "#689BD2", textColor: "white" },
207
+ success: { color: "seagreen", textColor: "white" },
208
+ };
209
+
210
+ Notice.current = null; // The notice that is seen
211
+
212
+ // Makes a notice on page (the one that is seen goes). Returns it.
213
+ Notice.show = function (params = {}) {
214
+ // WHY a loop: the onClose of the old notice may show another one
215
+ while (Notice.current) Notice.close();
216
+ Notice.current = createIn(page, function () { return Notice(params); });
217
+ return Notice.current;
218
+ };
219
+
220
+ // Closes the notice that is seen.
221
+ Notice.close = function () {
222
+ if (Notice.current) Notice.current.close();
223
+ };
224
+
225
+ // *** STYLE PACKAGES:
226
+ // USAGE: Notice.show({ messageText: "Hi", style: { message: { round: 20, border: 0 } } }) // Change only some keys.
227
+ Notice.styles = {
228
+ classic: NoticeDefaults.style,
229
+ };
@@ -0,0 +1,128 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ NumberField - v26.11
6
+
7
+ UI COMPONENT TEMPLATE
8
+ - You can customize, this template code as you need:
9
+ - NEW PROJECTS: styleName "light" (the default) on a light page, "dark" on a dark page (the packages
10
+ of TextField, comp/text-field.js; the look of 02-comp-examples/text-field-8-light-dark.htm), unless the user asks for another one.
11
+
12
+
13
+ Started Date: June 2024
14
+ Webpage: https://bug7a.github.io/js-components/
15
+
16
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
17
+ Licensed under the Apache License, Version 2.0
18
+ SPDX-License-Identifier: Apache-2.0
19
+
20
+ */
21
+
22
+ "use strict";
23
+
24
+ // Default values
25
+ const NumberFieldDefaults = {
26
+ required: 0,
27
+ type: "number",
28
+ titleText: "NUMERIC",
29
+ maxLength: 35,
30
+ placeholder: "(auto)",
31
+ allowNegative: 0,
32
+ allowDecimal: 1,
33
+ decimalSeparator: ".", // ","
34
+ maxDecimalDigits: 2,
35
+ };
36
+
37
+ const NumberField = function(params = {}) {
38
+
39
+ // Merge params first
40
+ mergeIntoIfMissing(params, NumberFieldDefaults);
41
+
42
+ // BOX: Component container
43
+ const box = startExtendedObject(TextField, params);
44
+
45
+ // *** PRIVATE VARIABLES:
46
+
47
+ // *** PUBLIC VARIABLES:
48
+
49
+ // *** PRIVATE FUNCTIONS:
50
+ const makeExamplePlaceholder = function() {
51
+
52
+ let value = "";
53
+ if (box.allowNegative) {
54
+ value = "-";
55
+ }
56
+ value = value + "100";
57
+ if (box.allowDecimal) {
58
+ value = value + box.decimalSeparator + "0".repeat(box.maxDecimalDigits);
59
+ }
60
+ return value;
61
+
62
+ };
63
+
64
+ // *** PUBLIC FUNCTIONS:
65
+ box.applyFormattedValueToInput = function() { // OVERRIDE
66
+
67
+ let value = box.getValue();
68
+
69
+ // 1. The characters that may be typed
70
+ let allowedChars = "0-9";
71
+ if (box.allowNegative) allowedChars += "-";
72
+ if (box.allowDecimal) allowedChars += "\\" + box.decimalSeparator;
73
+
74
+ const regex = new RegExp(`[^${allowedChars}]`, "g");
75
+ value = value.replace(regex, "");
76
+
77
+ // 2. "-" only at the start: the others go
78
+ if (box.allowNegative) {
79
+ value = value.replace(/(?!^)-/g, "");
80
+ }
81
+
82
+ // 3. The decimal mark only once
83
+ if (box.allowDecimal) {
84
+ const separator = box.decimalSeparator;
85
+ const parts = value.split(separator);
86
+ // WHY the first one stays and no digit goes: the value was built again from two parts, so "12.5" with a
87
+ // "." typed after the 1 became "1.2", and a pasted "1.234.567" "1.23"
88
+ if (parts.length > 2) {
89
+ parts.splice(1, parts.length - 1, parts.slice(1).join(""));
90
+ value = parts[0] + separator + parts[1];
91
+ }
92
+ if (parts.length == 2 && box.maxDecimalDigits >= 0) {
93
+ parts[1] = parts[1].substring(0, box.maxDecimalDigits);
94
+ value = parts[0] + separator + parts[1];
95
+ }
96
+ }
97
+
98
+ // More than one "0": "00*" -> "0"
99
+ if (parseFloat(value) == 0 && !value.includes(box.decimalSeparator) && !value.includes("-")) {
100
+ value = "0";
101
+ }
102
+
103
+ // It starts with ".": "0."
104
+ if (value == box.decimalSeparator) {
105
+ value = "0" + box.decimalSeparator;
106
+ }
107
+
108
+ // It starts with "-.": "-0."
109
+ if (value == ("-"+box.decimalSeparator)) {
110
+ value = "-0" + box.decimalSeparator;
111
+ }
112
+
113
+ box.setValue(value); // Put back formatted value.
114
+
115
+ }
116
+
117
+ // *** OBJECT VIEW:
118
+
119
+ // *** OBJECT INIT CODE:
120
+
121
+ // Show example placeholder
122
+ if (box.placeholder == "(auto)") {
123
+ box.setPlaceholder(makeExamplePlaceholder());
124
+ }
125
+
126
+ return endExtendedObject(box);
127
+
128
+ };
@@ -0,0 +1,298 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Numeric Keyboard - v26.10
6
+
7
+ Number keys on the screen (a PIN, an amount, a kiosk, a touch screen): a title, the typed value, the keys.
8
+ The look: white keys with a thin
9
+ dark line and round corners, a big bold value, a small gray title.
10
+ - keyLayout "wide": two rows (1 2 3 4 5 ⌫ / 6 7 8 9 0). "phone": 1-9 in three rows, then ⌫ 0 ✓ (onEnter).
11
+ - maxLength: the most digits; mask: 1 shows • for each digit (a PIN).
12
+ - The keyboard of the computer works too while the component has the focus: the digits, Backspace, Enter.
13
+ - The backspace key is drawn with SVG (no image file).
14
+ - onChange(self) at every change of self.value; onEnter(self): the ✓ key or Enter.
15
+
16
+ USAGE:
17
+ const pin = NumericKeyboard({ titleText: "PIN", maxLength: 4, mask: 1, onChange: function (self) { println(self.value); } });
18
+ NumericKeyboard({ keyLayout: "phone", titleText: "AMOUNT", maxLength: 8, onEnter: function (self) { pay(self.value); } });
19
+ pin.setValue("12");
20
+ pin.clear();
21
+
22
+ Started Date: October 2026
23
+ Webpage: https://bug7a.github.io/js-components/
24
+
25
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
26
+ Licensed under the Apache License, Version 2.0
27
+ SPDX-License-Identifier: Apache-2.0
28
+
29
+ */
30
+
31
+ "use strict";
32
+
33
+ // Default values:
34
+ const NumericKeyboardDefaults = {
35
+ width: "auto", // As wide as the keys
36
+ height: "auto",
37
+ keyLayout: "wide", // "wide": two rows; "phone": a 3 x 4 grid with an enter key
38
+ titleText: "PIN", // "": no title
39
+ value: "",
40
+ maxLength: 4,
41
+ mask: 0, // 1: a • for each digit (a PIN)
42
+ showValue: 1, // 0: only the keys (the value is shown somewhere else)
43
+ onChange: function (self) {},
44
+ onEnter: function (self) {},
45
+ styleName: "light", // "light" ("classic": its old name), "dark" or a name added to NumericKeyboard.styles
46
+ style: { // Classic style package
47
+ box: { color: "transparent" },
48
+ layout: { gap: 10, padding: [35, 20] },
49
+ title: { fontSize: 18, textColor: "rgba(20, 20, 20, 0.5)" },
50
+ value: { fontSize: 35, textColor: "rgba(20, 20, 20, 0.9)", fontFamily: "opensans-bold", height: 50 },
51
+ key: { size: 80, gap: 10, round: 14, color: "white", border: 1, borderColor: "rgba(0, 0, 0, 0.7)", fontSize: 35, textColor: "#141414" },
52
+ keyHover: { color: "#F7F7F7" },
53
+ keyPressed: { color: "#E9E9E9" },
54
+ enterKey: { color: "#141414", textColor: "white" },
55
+ focus: { ringColor: "rgba(95, 158, 160, 0.6)" },
56
+ },
57
+ };
58
+
59
+ const NumericKeyboard = function (params = {}) {
60
+
61
+ // Merge style package: params.style > NumericKeyboard.styles[styleName] > NumericKeyboardDefaults.style
62
+ basic.applyStylePackage(params, NumericKeyboard.styles, NumericKeyboardDefaults);
63
+
64
+ // Merge params:
65
+ mergeIntoIfMissing(params, NumericKeyboardDefaults);
66
+
67
+ // BOX: Component container
68
+ let box = startObject(params);
69
+
70
+ // *** PRIVATE VARIABLES:
71
+ const _s = box.style;
72
+ const BACKSPACE = "back";
73
+ const ENTER = "enter";
74
+ const ROWS = {
75
+ wide: [["1", "2", "3", "4", "5", BACKSPACE], ["6", "7", "8", "9", "0"]],
76
+ phone: [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], [BACKSPACE, "0", ENTER]],
77
+ };
78
+ const ICONS = {
79
+ back: '<svg viewBox="0 0 24 24" width="38" height="38" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round" style="display: block"><path d="M9 5h11v14H9l-6-7z"/><path d="M12 9.5l5 5M17 9.5l-5 5"/></svg>',
80
+ enter: '<svg viewBox="0 0 24 24" width="34" height="34" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" stroke-linecap="round" style="display: block"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>',
81
+ };
82
+
83
+ // *** PUBLIC VARIABLES:
84
+ box.keyList = []; // The key boxes (key.keyValue: "0".."9", "back", "enter")
85
+ // NOTE: Default values are also public variables. (box.value, box.maxLength...)
86
+
87
+ // *** PRIVATE FUNCTIONS:
88
+
89
+ const showValue = function () {
90
+ if (!box.lblValue) return;
91
+ box.lblValue.plainText = box.mask ? "•".repeat(box.value.length) : box.value;
92
+ };
93
+
94
+ // The only way the value changes: it is shown and onChange runs (not with silent: 1).
95
+ const changeValue = function (value, silent) {
96
+ value = String(value === undefined || value === null ? "" : value).replace(/\D/g, "").slice(0, box.maxLength);
97
+ if (value === box.value) return;
98
+ box.value = value;
99
+ showValue();
100
+ if (!silent) box.onChange(box);
101
+ };
102
+
103
+ const pressKey = function (keyValue) {
104
+ if (keyValue == ENTER) {
105
+ box.onEnter(box);
106
+ return;
107
+ }
108
+ if (keyValue == BACKSPACE) {
109
+ changeValue(box.value.slice(0, -1));
110
+ return;
111
+ }
112
+ if (box.value.length >= box.maxLength) return;
113
+ changeValue(box.value + keyValue);
114
+ };
115
+
116
+ const ENTER_PRESSED_OPACITY = 0.8;
117
+
118
+ const paintKey = function (key) {
119
+ const isEnter = (key.keyValue == ENTER);
120
+ let color = isEnter ? _s.enterKey.color : _s.key.color;
121
+ if (key.isPressed && !isEnter) color = _s.keyPressed.color;
122
+ else if (key.isHover && !isEnter) color = _s.keyHover.color;
123
+ key.color = color;
124
+ // WHY: the pressed color of the keys hid the text of the Enter key (white on light gray); it fades instead
125
+ if (isEnter) key.opacity = key.isPressed ? ENTER_PRESSED_OPACITY : 1;
126
+ };
127
+
128
+ // BOX: One key. Its container must be set.
129
+ const createKey = function (keyValue, width) {
130
+
131
+ const isEnter = (keyValue == ENTER);
132
+ const key = Label({
133
+ width: width,
134
+ height: _s.key.size,
135
+ round: _s.key.round,
136
+ border: _s.key.border,
137
+ borderColor: _s.key.borderColor,
138
+ fontSize: _s.key.fontSize,
139
+ textColor: isEnter ? _s.enterKey.textColor : _s.key.textColor,
140
+ clickable: 1,
141
+ cursor: "pointer",
142
+ role: "button",
143
+ aria: { label: (keyValue == BACKSPACE) ? "Delete" : (isEnter ? "Enter" : keyValue) },
144
+ css: { display: "flex", alignItems: "center", justifyContent: "center", flexShrink: "0" },
145
+ });
146
+ key.text = ICONS[keyValue] || keyValue;
147
+ key.keyValue = keyValue;
148
+ key.isHover = 0;
149
+ key.isPressed = 0;
150
+
151
+ key.onHoverChange(function (self, isOver) {
152
+ key.isHover = isOver;
153
+ if (!isOver) key.isPressed = 0;
154
+ paintKey(key);
155
+ });
156
+ key.on("pointerdown", function () {
157
+ key.isPressed = 1;
158
+ paintKey(key);
159
+ });
160
+ // WHY pointercancel: a touch that turns into a scroll gives no pointerup
161
+ const release = function () {
162
+ key.isPressed = 0;
163
+ paintKey(key);
164
+ };
165
+ key.on("pointerup", release);
166
+ key.on("pointercancel", release);
167
+ key.on("click", function () {
168
+ pressKey(keyValue);
169
+ });
170
+
171
+ paintKey(key);
172
+ return key;
173
+
174
+ };
175
+
176
+ // The keys of the computer while the component has the focus
177
+ const onKeyDown = function (self, event) {
178
+ if (event.ctrlKey || event.metaKey || event.altKey) return; // WHY: the shortcuts of the browser (Cmd+1...)
179
+ if (/^[0-9]$/.test(event.key)) {
180
+ pressKey(event.key);
181
+ event.preventDefault();
182
+ return;
183
+ }
184
+ if (event.key == "Backspace" || event.key == "Delete") {
185
+ pressKey(BACKSPACE);
186
+ event.preventDefault();
187
+ return;
188
+ }
189
+ if (event.key == "Enter") {
190
+ event.preventDefault();
191
+ if (!event.repeat) pressKey(ENTER); // WHY: a held Enter must not call onEnter (Ex: pay) again and again
192
+ }
193
+ };
194
+
195
+ // *** PUBLIC FUNCTIONS:
196
+
197
+ // silent: 1 -> onChange is not called.
198
+ box.setValue = function (value, silent = 0) {
199
+ changeValue(value, silent);
200
+ };
201
+ // USAGE: get: keyboard.value, set: keyboard.setValue("12")
202
+
203
+ box.getValue = function () {
204
+ return box.value;
205
+ };
206
+
207
+ box.clear = function (silent = 0) {
208
+ changeValue("", silent);
209
+ };
210
+
211
+ box.setTitleText = function (text) {
212
+ box.titleText = text;
213
+ box.aria = { label: text || "Numeric keyboard" };
214
+ if (!box.lblTitle) return;
215
+ box.lblTitle.plainText = text;
216
+ box.lblTitle.visible = text ? 1 : 0;
217
+ };
218
+
219
+ // *** OBJECT VIEW:
220
+
221
+ box.props(_s.box);
222
+ box.tabIndex = 0;
223
+ box.role = "group";
224
+ box.aria = { label: box.titleText || "Numeric keyboard" };
225
+ box.setFocusRing(_s.focus.ringColor);
226
+
227
+ const rows = ROWS[box.keyLayout] || ROWS.wide;
228
+ const columnCount = Math.max.apply(null, rows.map(function (row) { return row.length; }));
229
+
230
+ // GROUP: Layout (the title, the value, the keys)
231
+ box.layout = VGroup({ hug: 1, align: "center top", gap: 0, padding: _s.layout.padding, position: "relative", clipContent: 0 });
232
+
233
+ if (box.showValue == 1) {
234
+
235
+ // LABEL: Title
236
+ box.lblTitle = Label({ ..._s.title, textAlign: "center" });
237
+ box.setTitleText(box.titleText);
238
+
239
+ // LABEL: Value
240
+ // WHY a fixed height: the keys must not move when the first digit comes (an empty label is lower)
241
+ box.lblValue = Label({ ..._s.value, textAlign: "center", css: { lineHeight: _s.value.height + "px", minHeight: _s.value.height + "px", whiteSpace: "nowrap" } });
242
+ box.lblValue.css = { marginBottom: _s.layout.gap + "px" };
243
+
244
+ }
245
+
246
+ // GROUP: Keys (a row group for each row of keys)
247
+ VGroup({ hug: 1, align: "left top", gap: _s.key.gap, clipContent: 0 });
248
+
249
+ rows.forEach(function (row) {
250
+
251
+ HGroup({ hug: 1, align: "left top", gap: _s.key.gap, clipContent: 0 });
252
+ row.forEach(function (keyValue, i) {
253
+ // WHY: the last key of a shorter row ("0" of "wide") takes the room of the missing keys
254
+ const isLastOfShortRow = (i == row.length - 1) && (row.length < columnCount);
255
+ const span = isLastOfShortRow ? columnCount - row.length + 1 : 1;
256
+ const width = span * _s.key.size + (span - 1) * _s.key.gap;
257
+ box.keyList.push(createKey(keyValue, width));
258
+ });
259
+ endGroup();
260
+
261
+ });
262
+
263
+ endGroup();
264
+
265
+ endGroup();
266
+
267
+ // *** OBJECT INIT CODE:
268
+
269
+ box.on("keydown", onKeyDown);
270
+ const startValue = box.value;
271
+ box.value = "";
272
+ changeValue(startValue, 1);
273
+ showValue();
274
+
275
+ return endObject(box);
276
+
277
+ };
278
+
279
+ // *** STYLE PACKAGES:
280
+ // USAGE: NumericKeyboard({ styleName: "dark" })
281
+ // NOTE: A new package needs only the keys that differ from the light style.
282
+ NumericKeyboard.styles = {
283
+
284
+ light: NumericKeyboardDefaults.style,
285
+
286
+ // For a dark page.
287
+ dark: {
288
+ title: { fontSize: 18, textColor: "rgba(255, 255, 255, 0.5)" },
289
+ value: { fontSize: 35, textColor: "rgba(255, 255, 255, 0.92)", fontFamily: "opensans-bold", height: 50 },
290
+ key: { size: 80, gap: 10, round: 14, color: "#2B2D31", border: 1, borderColor: "rgba(255, 255, 255, 0.18)", fontSize: 35, textColor: "rgba(255, 255, 255, 0.9)" },
291
+ keyHover: { color: "#33353A" },
292
+ keyPressed: { color: "#3C3E44" },
293
+ enterKey: { color: "#F2C14E", textColor: "#1B2632" },
294
+ focus: { ringColor: "rgba(95, 179, 181, 0.7)" },
295
+ },
296
+
297
+ };
298
+ NumericKeyboard.styles.classic = NumericKeyboard.styles.light; // the old name of light: the pages made with it keep their look