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,490 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Check Box - v26.11
6
+
7
+ UI COMPONENT TEMPLATE
8
+ - A customizable check box with a label.
9
+ - Checkmark is drawn with code (no image files needed).
10
+ - Supports: checked, enabled, label position (left/right), keyboard (Space/Enter).
11
+ - wrapLabel: 1 -> a long label wraps to more lines (give the check box a width, or grow: 1 in an HGroup).
12
+ The label is HTML: a text of the user goes in with basic.escapeHtml(text).
13
+ - Whole object background can change on hover and checked states (style.hoverBox, style.checkedBox).
14
+ - The empty square under the mouse: style.hoverMark (its borderColor, and its color when given; v26.11).
15
+ - animated: 1 (context/basic-js-animated-rules.md): the square grows a little under the mouse
16
+ (1.05) and the tick draws in from 0.6 with a fade, in 0.25 s with a soft stop. Nothing moves at the first view; off
17
+ when the system asks for reduced motion. animated: 0 (default) keeps the short tick motion it always had.
18
+ setAnimated(0/1).
19
+ - style.focus.ringColor: the keyboard focus shows on the mark (its edge in this color, 2 px). "": none (the old
20
+ packages); "minimal" / "minimalDark" have it.
21
+ - Style packages: "light" (default; the old name "classic" works too), "modern", "dark", "minimal", "minimalDark". Select with styleName. (CheckBox.styles)
22
+ NEW PROJECTS: use "light" on a light page and "dark" on a dark page, unless the user
23
+ asks for another one ("modern" only when asked).
24
+
25
+ Started Date: September 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 CheckBoxDefaults = {
38
+ key: "0",
39
+ width: "auto",
40
+ height: "auto",
41
+ checked: 0, // 0, 1
42
+ enabled: 1, // 0, 1
43
+ labelText: "",
44
+ allowHtml: 0, // 1: labelText is HTML (only for your own texts)
45
+ labelPosition: "right", // "right", "left"
46
+ wrapLabel: 0, // 1: a long label wraps (the check box needs a width); 0: one line
47
+ animated: 0, // 1: the square grows a little under the mouse, the tick draws in (box.setAnimated(0/1))
48
+ onChange: function (self) { }, // self.checked
49
+ styleName: "light", // "light" ("classic": its old name), "modern", "dark", "minimal", "minimalDark" or a name added to CheckBox.styles
50
+ style: { // Light style package (default)
51
+ box: { // Whole object background
52
+ color: "transparent",
53
+ round: 0,
54
+ },
55
+ hoverBox: { // Mouse over (whole object background)
56
+ color: null, // null: uses box.color
57
+ },
58
+ checkedBox: { // Checked (whole object background)
59
+ color: null, // null: uses box.color
60
+ },
61
+ hoverCheckedBox: { // Checked and mouse over (whole object background)
62
+ color: null, // null: uses checkedBox.color
63
+ },
64
+ layout: {
65
+ gap: 10,
66
+ padding: [0, 4],
67
+ align: "left center",
68
+ },
69
+ mark: { // Unchecked square
70
+ width: 22,
71
+ height: 22,
72
+ color: White(1),
73
+ border: 2,
74
+ borderColor: Black(0.35),
75
+ round: 5,
76
+ },
77
+ checkedMark: { // Checked square
78
+ // #242424: a soft black
79
+ color: "#242424",
80
+ borderColor: "#242424",
81
+ },
82
+ hoverMark: { // Mouse over (the empty square)
83
+ color: null, // null: uses mark.color, so a package can change it
84
+ borderColor: Black(0.7),
85
+ },
86
+ tick: {
87
+ color: White(1),
88
+ thickness: 2,
89
+ },
90
+ label: {
91
+ fontSize: 16,
92
+ textColor: Black(0.8),
93
+ },
94
+ disabled: {
95
+ opacity: 0.4,
96
+ },
97
+ focus: { // The keyboard focus: the edge of the mark in this color, 2 px. "": no ring
98
+ ringColor: "",
99
+ },
100
+ }
101
+ };
102
+
103
+ const CheckBox = function (params = {}) {
104
+
105
+ // Merge style package: params.style > CheckBox.styles[styleName] > CheckBoxDefaults.style (light)
106
+ basic.applyStylePackage(params, CheckBox.styles, CheckBoxDefaults);
107
+
108
+ // Merge params:
109
+ mergeIntoIfMissing(params, CheckBoxDefaults);
110
+
111
+ // Edit params, if needed:
112
+ params.color = params.style.box.color;
113
+ params.round = params.style.box.round;
114
+
115
+ // BOX: Component container
116
+ let box = startObject(params);
117
+
118
+ // *** PRIVATE VARIABLES:
119
+ let isMouseOver = 0;
120
+ const MOTION_DURATION = "0.15s";
121
+ // The tick is a rotated corner (right and bottom borders), sized as a part of the inner square.
122
+ const TICK_WIDTH_RATIO = 0.3;
123
+ const TICK_HEIGHT_RATIO = 0.58;
124
+ const TICK_RAISE_RATIO = 0.06; // The tick is lifted a little above the center.
125
+ const TICK_HIDDEN_SCALE = 0.4; // The tick grows from this size when checked.
126
+ // MOTION (animated: 1)
127
+ const MOTION_TIME = "0.25s";
128
+ const MOTION_EASE = "cubic-bezier(0.2, 0.8, 0.2, 1)"; // a fast start, a soft stop
129
+ const HOVER_GROW = 1.05; // the square under the mouse
130
+ const TICK_COME_SCALE = 0.6; // the tick draws in from this size
131
+ let wasAnimated = 0;
132
+
133
+ // *** PUBLIC VARIABLES:
134
+ // NOTE: Default values are also public variables. (box.checked, box.enabled, box.labelText)
135
+
136
+ // *** PRIVATE FUNCTIONS:
137
+
138
+ const setText = function (label, text) {
139
+ const value = (text === undefined || text === null) ? "" : String(text);
140
+ if (box.allowHtml == 1) label.text = value;
141
+ else label.plainText = value;
142
+ };
143
+
144
+ // The keyboard focus (style.focus.ringColor) on the mark: its edge in that color and 1 px more inside it.
145
+ // WHY on the mark, inside it: a ring around the whole object hid its text, and an outer ring was cut by the groups.
146
+ // WHY a CSS rule: only :focus-visible knows a focus of the keyboard (not of a click).
147
+ const showFocusOnMark = function () {
148
+ const ringColor = box.style.focus.ringColor;
149
+ if (!ringColor) return;
150
+ CheckBox.addFocusCss();
151
+ box.elem.classList.add("check-box-focus");
152
+ box.mark.elem.classList.add("check-box-mark");
153
+ box.elem.style.setProperty("--check-box-focus", ringColor);
154
+ };
155
+
156
+ // The whole object background. A null color uses the color of the state below it.
157
+ const getBoxColor = function (isHover) {
158
+ const boxColor = box.style.box.color;
159
+ const checkedBoxColor = box.style.checkedBox.color || boxColor;
160
+ if (box.checked == 1) {
161
+ if (isHover) return box.style.hoverCheckedBox.color || checkedBoxColor;
162
+ return checkedBoxColor;
163
+ }
164
+ if (isHover) return box.style.hoverBox.color || boxColor;
165
+ return boxColor;
166
+ };
167
+
168
+ const paintMark = function (isHover) {
169
+ if (box.checked == 1) {
170
+ box.mark.color = box.style.checkedMark.color;
171
+ box.mark.borderColor = box.style.checkedMark.borderColor;
172
+ box.tick.css = { opacity: "1", transform: "rotate(45deg) scale(1)" };
173
+ return;
174
+ }
175
+ const hoverColor = box.style.hoverMark.color;
176
+ box.mark.color = (isHover && hoverColor) ? hoverColor : box.style.mark.color;
177
+ box.mark.borderColor = (isHover) ? box.style.hoverMark.borderColor : box.style.mark.borderColor;
178
+ const hiddenScale = (isMotionOn()) ? TICK_COME_SCALE : TICK_HIDDEN_SCALE;
179
+ box.tick.css = { opacity: "0", transform: "rotate(45deg) scale(" + hiddenScale + ")" };
180
+ };
181
+
182
+ const paintEnabled = function () {
183
+ const isEnabled = (box.enabled == 1);
184
+ box.opacity = (isEnabled) ? 1 : box.style.disabled.opacity;
185
+ box.cursor = (isEnabled) ? "pointer" : "default";
186
+ box.tabIndex = (isEnabled) ? 0 : -1;
187
+ };
188
+
189
+ // *** MOTION (animated: 1)
190
+
191
+ const isMotionOn = function () {
192
+ if (box.animated != 1) return false;
193
+ return !(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
194
+ };
195
+
196
+ const getMarkTransform = function () {
197
+ if (isMouseOver && box.enabled == 1) return "scale(" + HOVER_GROW + ")";
198
+ return "none";
199
+ };
200
+
201
+ const paintMotion = function () {
202
+ if (!isMotionOn()) return;
203
+ box.mark.css = { transform: getMarkTransform() };
204
+ };
205
+
206
+ // The transitions of the motion, or the still look again (only when it was animated)
207
+ const applyAnimated = function () {
208
+ const tickTime = (isMotionOn()) ? MOTION_TIME + " " + MOTION_EASE : MOTION_DURATION;
209
+ if (isMotionOn()) {
210
+ // WHY the origin at the side of the edge: the grown square does not go out of the box at that edge
211
+ box.mark.css = { transformOrigin: (box.labelPosition === "left") ? "right center" : "left center" };
212
+ box.mark.setMotion("background-color " + MOTION_DURATION + ", border-color " + MOTION_DURATION + ", transform " + MOTION_TIME + " " + MOTION_EASE);
213
+ box.tick.css = { transition: "transform " + tickTime + ", opacity " + tickTime };
214
+ wasAnimated = 1;
215
+ } else if (wasAnimated) {
216
+ // WHY Now: the still look comes back at once (setMotion waits a moment: it is for the first view)
217
+ box.mark.setMotionNow("background-color " + MOTION_DURATION + ", border-color " + MOTION_DURATION);
218
+ box.mark.css = { transform: "none" };
219
+ box.tick.css = { transition: "transform " + tickTime + ", opacity " + tickTime };
220
+ wasAnimated = 0;
221
+ }
222
+ paint();
223
+ };
224
+
225
+ // The look of the current state (checked, mouse over, enabled).
226
+ const paint = function () {
227
+ const isHover = (isMouseOver && box.enabled == 1);
228
+ box.color = getBoxColor(isHover);
229
+ paintMark(isHover);
230
+ paintEnabled();
231
+ paintMotion();
232
+ box.aria = { checked: (box.checked == 1), disabled: (box.enabled != 1) };
233
+ };
234
+
235
+ // *** PUBLIC FUNCTIONS:
236
+
237
+ box.setChecked = function (checked, silent = 0) {
238
+
239
+ checked = basic.isOn(checked) ? 1 : 0;
240
+ if (box.checked == checked) return;
241
+
242
+ box.checked = checked;
243
+ paint();
244
+
245
+ if (!silent) box.onChange(box);
246
+
247
+ };
248
+ // USAGE: get: checkBox.checked, set: checkBox.setChecked(1)
249
+ // NOTE: setChecked(1, 1) changes the value without calling onChange.
250
+
251
+ box.toggle = function () {
252
+ if (box.enabled != 1) return;
253
+ box.setChecked((box.checked == 1) ? 0 : 1);
254
+ };
255
+
256
+ box.setEnabled = function (enabled) {
257
+ box.enabled = basic.isOn(enabled) ? 1 : 0;
258
+ paint();
259
+ };
260
+ // USAGE: get: checkBox.enabled, set: checkBox.setEnabled(0)
261
+
262
+ box.setLabelText = function (text) {
263
+ box.labelText = text;
264
+ setText(box.label, text);
265
+ box.label.visible = (text) ? 1 : 0;
266
+ };
267
+ // USAGE: get: checkBox.labelText, set: checkBox.setLabelText("Remember me")
268
+
269
+ box.refresh = function () {
270
+ paint();
271
+ };
272
+
273
+ box.setAnimated = function (value) {
274
+ box.animated = (value == 1) ? 1 : 0;
275
+ applyAnimated();
276
+ };
277
+ // USAGE: checkBox.setAnimated(1)
278
+
279
+ // *** OBJECT VIEW:
280
+ box.clickable = 1;
281
+ box.role = "checkbox";
282
+ box.css = { outline: "none", userSelect: "none" };
283
+ box.setMotion("background-color " + MOTION_DURATION);
284
+
285
+ const isWrapLabel = basic.isOn(box.wrapLabel);
286
+ // WHY: a flex item does not get narrower than its content without minWidth 0 (the long label pushed the row out)
287
+ if (isWrapLabel) box.css = { minWidth: "0px" };
288
+
289
+ // GROUP: mark, label
290
+ box.contentBox = HGroup({
291
+ width: isWrapLabel ? "100%" : "auto",
292
+ height: "auto",
293
+ position: "relative",
294
+ ...box.style.layout,
295
+ });
296
+
297
+ // LABEL: label (left or right of the mark)
298
+ const createLabel = function () {
299
+ box.label = Label(box.style.label);
300
+ setText(box.label, box.labelText);
301
+ if (!box.labelText) box.label.visible = 0;
302
+ if (!isWrapLabel) {
303
+ box.label.css.whiteSpace = "nowrap";
304
+ return;
305
+ }
306
+ box.label.grow = 1;
307
+ box.label.css = { minWidth: "0px", whiteSpace: "normal", overflowWrap: "anywhere" };
308
+ };
309
+
310
+ if (box.labelPosition === "left") createLabel();
311
+
312
+ // BOX: mark (square)
313
+ box.mark = startBox({
314
+ width: box.style.mark.width,
315
+ height: box.style.mark.height,
316
+ color: box.style.mark.color,
317
+ border: box.style.mark.border,
318
+ borderColor: box.style.mark.borderColor,
319
+ round: box.style.mark.round,
320
+ });
321
+ box.mark.setMotion("background-color " + MOTION_DURATION + ", border-color " + MOTION_DURATION);
322
+ box.mark.css.boxSizing = "border-box";
323
+ showFocusOnMark();
324
+ box.mark.shrink = 0; // (a wrapping label must not squeeze the mark)
325
+
326
+ // BOX: tick (drawn with right and bottom borders, rotated 45deg)
327
+ const innerWidth = box.style.mark.width - (box.style.mark.border * 2);
328
+ const innerHeight = box.style.mark.height - (box.style.mark.border * 2);
329
+ const tickWidth = Math.round(innerWidth * TICK_WIDTH_RATIO);
330
+ const tickHeight = Math.round(innerHeight * TICK_HEIGHT_RATIO);
331
+ const tickBorder = box.style.tick.thickness + "px solid " + box.style.tick.color;
332
+
333
+ box.tick = Box({
334
+ left: Math.round((innerWidth - tickWidth) / 2),
335
+ top: Math.round((innerHeight - tickHeight) / 2) - Math.round(innerHeight * TICK_RAISE_RATIO),
336
+ width: tickWidth,
337
+ height: tickHeight,
338
+ color: "transparent",
339
+ });
340
+ box.tick.css = {
341
+ boxSizing: "border-box",
342
+ borderRight: tickBorder,
343
+ borderBottom: tickBorder,
344
+ transition: "transform " + MOTION_DURATION + ", opacity " + MOTION_DURATION,
345
+ };
346
+
347
+ endBox();
348
+
349
+ if (box.labelPosition !== "left") createLabel();
350
+
351
+ endGroup();
352
+
353
+ // *** OBJECT INIT CODE:
354
+
355
+ box.on("click", function (self, event) {
356
+ box.toggle();
357
+ });
358
+
359
+ box.on("keydown", function (self, event) {
360
+ if (event.key !== " " && event.key !== "Enter") return;
361
+ event.preventDefault();
362
+ if (event.repeat) return; // WHY: a held key flipped it again and again (its end state was a matter of luck)
363
+ box.toggle();
364
+ });
365
+
366
+ box.on("mouseover", function () {
367
+ isMouseOver = 1;
368
+ if (box.enabled == 1) paint();
369
+ });
370
+
371
+ box.on("mouseout", function () {
372
+ isMouseOver = 0;
373
+ paint();
374
+ });
375
+
376
+ box.checked = basic.isOn(box.checked) ? 1 : 0;
377
+ box.enabled = basic.isOn(box.enabled) ? 1 : 0;
378
+ applyAnimated(); // (it paints)
379
+
380
+ return endObject(box);
381
+
382
+ };
383
+
384
+ // *** STYLE PACKAGES:
385
+ // USAGE: CheckBox({ styleName: "modern" })
386
+ // USAGE: CheckBox({ styleName: "modern", style: { tick: { color: "tomato" } } }) // Change only some keys.
387
+ // USAGE: CheckBox({ style: CheckBox.styles.modern }) // The same as styleName: "modern". (The package is copied, never changed.)
388
+ // NOTE: A new package needs only the keys that differ from the default (classic) style.
389
+ // USAGE: CheckBox.styles.myStyle = { tick: { color: "red" } };
390
+ CheckBox.styles = {
391
+
392
+ // White box with a border. When checked, dark filled box with a white tick. No background.
393
+ light: CheckBoxDefaults.style,
394
+
395
+ // Light box, thin border. When checked, the tick on a white square with an edge.
396
+ modern: {
397
+ box: { // Whole object background
398
+ color: "transparent",
399
+ round: 8,
400
+ },
401
+ hoverBox: { // Mouse over (whole object background)
402
+ color: "whitesmoke", // null: uses box.color
403
+ },
404
+ checkedBox: { // Checked (whole object background)
405
+ color: "#EFF5F6", // 10% of tick color on white. null: uses box.color
406
+ },
407
+ hoverCheckedBox: { // Checked and mouse over (whole object background)
408
+ color: "#DFECEC", // 20% of tick color on white. null: uses checkedBox.color
409
+ },
410
+ layout: {
411
+ gap: 12,
412
+ padding: [12, 10],
413
+ align: "left center",
414
+ },
415
+ mark: { // Unchecked square
416
+ width: 22,
417
+ height: 22,
418
+ color: "whitesmoke",
419
+ border: 1,
420
+ borderColor: Black(0.7),
421
+ round: 4,
422
+ },
423
+ checkedMark: { // Checked square: white with an edge, behind the tick
424
+ color: "white",
425
+ borderColor: Black(0.7),
426
+ },
427
+ hoverMark: { // Mouse over: the empty square turns white
428
+ color: "white",
429
+ borderColor: Black(0.7),
430
+ },
431
+ tick: {
432
+ color: "cadetblue", // #5F9EA0
433
+ thickness: 3,
434
+ },
435
+ label: {
436
+ fontSize: 16,
437
+ textColor: Black(0.85),
438
+ },
439
+ disabled: {
440
+ opacity: 0.4,
441
+ },
442
+ },
443
+
444
+ // Dark theme (the Ozden Panel colors, same as SidePanel, Stepper and Tabs "dark"): the classic shape on a dark page.
445
+ // NOTE: Only the keys that differ from classic.
446
+ dark: {
447
+ mark: { // Unchecked square
448
+ color: "#2A2A29",
449
+ borderColor: White(0.3),
450
+ },
451
+ checkedMark: { // Checked square
452
+ color: "#3D7A6B",
453
+ borderColor: "#3D7A6B",
454
+ },
455
+ hoverMark: { // Mouse over (only border)
456
+ borderColor: White(0.6),
457
+ },
458
+ label: {
459
+ textColor: White(0.85),
460
+ },
461
+ },
462
+
463
+ };
464
+ CheckBox.styles.classic = CheckBox.styles.light; // the old name of light: the pages made with it keep their look
465
+
466
+ // The minimal theme (_designs/minimal-theme.htm): a 14 px square of a line, darker under the mouse; when checked an ink
467
+ // line and an ink tick inside it, no fill; a 13 px text.
468
+ // WHY a strong line: the line is the only thing that shows an empty mark (3:1 at least, as WCAG asks of a control)
469
+ CheckBox.createMinimalStyle = function (colors) {
470
+ return {
471
+ layout: { gap: 8, padding: [0, 2], align: "left center" },
472
+ mark: { width: 14, height: 14, color: "transparent", border: 1, borderColor: colors.line, round: 3 },
473
+ checkedMark: { color: "transparent", borderColor: colors.ink },
474
+ hoverMark: { color: null, borderColor: colors.lineHover },
475
+ tick: { color: colors.ink, thickness: 1.5 },
476
+ label: { fontSize: 13, textColor: colors.text },
477
+ disabled: { opacity: 0.4 },
478
+ focus: { ringColor: colors.focus },
479
+ };
480
+ };
481
+ CheckBox.MINIMAL_COLORS = { line: Black(0.45), lineHover: Black(0.65), ink: "#1F1F1F", text: Black(0.85), focus: "#3D8BD9" };
482
+ CheckBox.styles.minimal = CheckBox.createMinimalStyle(CheckBox.MINIMAL_COLORS);
483
+ CheckBox.MINIMAL_DARK_COLORS = { line: White(0.42), lineHover: White(0.62), ink: "#EDEDEB", text: White(0.88), focus: "#7FB6DE" };
484
+ CheckBox.styles.minimalDark = CheckBox.createMinimalStyle(CheckBox.MINIMAL_DARK_COLORS);
485
+
486
+ // The rule of the keyboard focus (style.focus.ringColor). WHY !important: the edge of the mark is an inline style.
487
+ CheckBox.addFocusCss = function () {
488
+ basic.addCss("check-box-focus", ".check-box-focus:focus { outline: none; }" +
489
+ ".check-box-focus:focus-visible .check-box-mark { border-color: var(--check-box-focus) !important; box-shadow: inset 0 0 0 1px var(--check-box-focus); }");
490
+ };