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,436 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ PeriodBar - v26.11
6
+
7
+ UI COMPONENT
8
+ - A month switcher: a white capsule with the selected month in its middle (a small title over a big name) and a
9
+ round button with a chevron at each side.
10
+ - The months are this month and the months before it (monthCount):
11
+ "TODAY" / "1 November" (this month, with the day of today), "LAST MONTH" / "October", "2 MONTHS AGO" / "September"...
12
+ A month of another year gets its year: "December 2025".
13
+ - language: "en" or "tr" (PeriodBar.TEXTS: the titles, the month names of basic.js, the aria labels).
14
+ Another language: PeriodBar.TEXTS.de = { today: "HEUTE", ... } (the keys of PeriodBar.TEXTS.en).
15
+ - value is the index of the selected month: 0 is the oldest one, monthCount - 1 is this month (the default).
16
+ - MOTIONS: the new month comes in from the side it goes to (the next one from the right), growing and
17
+ fading in, while the old one leaves to the other side, shrinking and fading out (0.2 s). setVisible(0 / 1): the bar
18
+ goes up / drops in from above, with a fade (0.3 s). Only transform and opacity move. No motion at the first view;
19
+ none when the system asks for reduced motion. (style.motion: the times; 0 -> no motion)
20
+ - KEYBOARD AND ACCESSIBILITY: Left / Right arrows when the bar has the focus (Tab reaches it; a ring around the capsule,
21
+ only for the keyboard). The buttons have the role "button", aria labels ("Previous month") and aria-disabled at the
22
+ first / last month. The month in the capsule is read by a screen reader when it changes (aria-live).
23
+ - THE SIZES are px of a 600 px design (the page is fitted with page.fit(600, 800)).
24
+ The capsule follows the size of the box (style.pill.space from its edges).
25
+ - onChange is NOT called when the component is created or when the value is set with silent: 1.
26
+ - NEEDS basic.js v26.10.23 (role, aria, tabIndex, basic.addCss, basic.isOn).
27
+
28
+ USAGE:
29
+ const periodBar = PeriodBar({
30
+ monthCount: 12,
31
+ language: "en",
32
+ onChange: function (self) {
33
+ const date = self.getSelectedDate(); // { year: 2026, month: 10 }
34
+ showSpending(date.year, date.month);
35
+ },
36
+ });
37
+ periodBar.selectPrevious(); // one month back (onChange is called)
38
+ periodBar.selectNext();
39
+ periodBar.setValue(0); // the oldest month
40
+ periodBar.setValue(11, 1); // silent: onChange is not called
41
+ periodBar.getSelectedDate(); // { year, month (1-12) }
42
+ periodBar.setVisible(0); // it goes up (setVisible(1): it drops in)
43
+ PeriodBar({ language: "tr", monthCount: 24 });
44
+
45
+ Started Date: November 2026
46
+ Webpage: https://bug7a.github.io/js-components/
47
+
48
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
49
+ Licensed under the Apache License, Version 2.0
50
+ SPDX-License-Identifier: Apache-2.0
51
+
52
+ */
53
+
54
+ "use strict";
55
+
56
+ // Default values:
57
+ const PeriodBarDefaults = {
58
+ key: "0", // Your name for this object: read it in a callback (self.key)
59
+ width: 600,
60
+ height: 160,
61
+ monthCount: 12, // This month and the months before it. (Only at create time)
62
+ language: "en", // "en", "tr" or a key added to PeriodBar.TEXTS (Only at create time)
63
+ value: null, // The index of the selected month: 0 the oldest, monthCount - 1 this month. null: this month
64
+ ariaLabel: "", // "": the name of the bar in the language ("Month")
65
+ onChange: function (self) { }, // self.value, self.previousValue, self.getSelectedDate()
66
+ style: {
67
+ pill: { // The white capsule
68
+ space: 20, // From the edges of the box
69
+ color: "white",
70
+ round: 100, // More than half of its height: a capsule
71
+ border: 1,
72
+ borderColor: "#141414",
73
+ },
74
+ title: { // "TODAY", "LAST MONTH", "2 MONTHS AGO"
75
+ top: 26, // In the capsule
76
+ fontSize: 20,
77
+ textColor: "#9B9B9B",
78
+ },
79
+ name: { // "1 November", "October", "December 2025"
80
+ top: 46,
81
+ fontSize: 35,
82
+ textColor: "#141414",
83
+ fontFamily: "opensans-bold",
84
+ },
85
+ button: { // The round buttons at the sides
86
+ size: 80,
87
+ side: 40, // From the side of the box
88
+ color: "#D8D8D8",
89
+ border: 1,
90
+ borderColor: "#141414",
91
+ round: 100,
92
+ iconColor: "#141414",
93
+ iconSize: 34,
94
+ iconLine: 2, // The line of the chevron (on a 24 px grid)
95
+ passiveOpacity: 0.2, // No month before (or after) the selected one
96
+ },
97
+ focus: { // A ring around the capsule while the keyboard focus is on the bar
98
+ ringColor: "rgba(64, 165, 175, 0.9)",
99
+ ringWidth: 3,
100
+ },
101
+ motion: {
102
+ itemTime: 0.2, // s: a month comes in and the old one leaves. 0: no motion
103
+ showTime: 0.3, // s: setVisible(). 0: no motion
104
+ itemScale: 0.1, // The size of a month out at a side
105
+ ease: "ease",
106
+ },
107
+ },
108
+ };
109
+
110
+ const PeriodBar = function (params = {}) {
111
+
112
+ // Merge params:
113
+ mergeIntoIfMissing(params, PeriodBarDefaults);
114
+
115
+ // Edit params, if needed:
116
+ params.color = "transparent";
117
+ params.monthCount = Math.max(1, Math.round(Number(params.monthCount)) || 1);
118
+
119
+ // BOX: Component container
120
+ const box = startObject(params);
121
+
122
+ // *** PRIVATE VARIABLES:
123
+ const _s = box.style;
124
+ const texts = PeriodBar.getTexts(box.language);
125
+ const periods = PeriodBar.getPeriods(box.monthCount, texts); // The oldest first
126
+ const lastIndex = periods.length - 1;
127
+ let itemList = []; // A Box for every month (its labels: lblTitle, lblName)
128
+
129
+ // *** PUBLIC VARIABLES:
130
+ box.previousValue = null;
131
+ box.isVisible = 1; // 0 after setVisible(0)
132
+ // NOTE: Default values are also public variables. (box.value, box.monthCount, box.language)
133
+
134
+ // *** PRIVATE FUNCTIONS:
135
+
136
+ // DRAWING: each function does one job:
137
+ // createItems() -> a Box for every month (the first drawing)
138
+ // moveItems() -> the new month comes in, the old one leaves (setValue)
139
+ // paintButtons() -> the buttons at the first / last month (setValue)
140
+ // showVisibility() -> the bar drops in / goes up (setVisible)
141
+
142
+ // An index of a month: a number in the list. null (or not a number): this month.
143
+ const toIndex = function (value) {
144
+ const index = Math.round(Number(value));
145
+ if (value === null || value === undefined || isNaN(index)) return lastIndex;
146
+ return basic.clamp(index, 0, lastIndex);
147
+ };
148
+
149
+ const isMotionOn = function () {
150
+ const reduceMotion = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
151
+ return !reduceMotion;
152
+ };
153
+
154
+ // The CSS transition of a motion: "none" when it is off.
155
+ const getTransition = function (seconds) {
156
+ if (!(seconds > 0) || !isMotionOn()) return "none";
157
+ const timing = seconds + "s " + _s.motion.ease;
158
+ return "transform " + timing + ", opacity " + timing;
159
+ };
160
+
161
+ // The places of a month: "center" (shown), "left" or "right" (out at a side, small and faded)
162
+ // WHY: translateX(100%) is the width of the month itself: no measuring, and only transform and opacity move.
163
+ const getItemTransform = function (place) {
164
+ if (place === "center") return "translateX(0px) scale(1)";
165
+ const side = (place === "left") ? "-100%" : "100%";
166
+ return "translateX(" + side + ") scale(" + _s.motion.itemScale + ")";
167
+ };
168
+
169
+ const placeItem = function (item, place, transition) {
170
+ const isShown = (place === "center");
171
+ item.setMotionNow(transition);
172
+ item.css.transform = getItemTransform(place);
173
+ item.opacity = (isShown) ? 1 : 0;
174
+ item.aria = { hidden: !isShown };
175
+ };
176
+
177
+ // DATA: one month, in the months box. (createIn)
178
+ const createItem = function (period) {
179
+ const item = startBox({ left: 0, top: 0, width: "100%", height: "100%", color: "transparent" });
180
+ // LABEL: Title ("LAST MONTH")
181
+ item.lblTitle = Label({ ..._s.title, left: 0, width: "100%", textAlign: "center", plainText: period.titleText });
182
+ // LABEL: Name ("October")
183
+ item.lblName = Label({ ..._s.name, left: 0, width: "100%", textAlign: "center", plainText: period.nameText });
184
+ endBox();
185
+ return item;
186
+ };
187
+
188
+ // DATA: the months; only the selected one is shown, without motion (the first view).
189
+ const createItems = function () {
190
+ itemList = periods.map(function (period) {
191
+ return createIn(box.itemsBox, function () { return createItem(period); });
192
+ });
193
+ itemList.forEach(function (item, index) {
194
+ placeItem(item, (index === box.value) ? "center" : "left", "none");
195
+ });
196
+ };
197
+
198
+ // The new month comes in from the side it goes to (a later month from the right), the old one leaves to the other side.
199
+ const moveItems = function (oldIndex, newIndex) {
200
+ const transition = getTransition(_s.motion.itemTime);
201
+ const isLater = (newIndex > oldIndex);
202
+ const newItem = itemList[newIndex];
203
+ placeItem(newItem, (isLater) ? "right" : "left", "none");
204
+ newItem.elem.offsetWidth; // WHY: A reflow: the browser takes the start place first, so the motion starts from it.
205
+ placeItem(newItem, "center", transition);
206
+ placeItem(itemList[oldIndex], (isLater) ? "left" : "right", transition);
207
+ };
208
+
209
+ const paintButton = function (button, canGo) {
210
+ button.opacity = (canGo) ? 1 : _s.button.passiveOpacity;
211
+ button.cursor = (canGo) ? "pointer" : "default";
212
+ button.aria = { disabled: !canGo };
213
+ };
214
+
215
+ const paintButtons = function () {
216
+ paintButton(box.btnPrevious, box.value > 0);
217
+ paintButton(box.btnNext, box.value < lastIndex);
218
+ };
219
+
220
+ // The bar drops in from above / goes up, with a fade. A hidden bar can not be clicked or focused (inert).
221
+ const showVisibility = function () {
222
+ box.setMotionNow(getTransition(_s.motion.showTime));
223
+ box.css.transform = (box.isVisible) ? "translateY(0px)" : "translateY(-100%)";
224
+ box.opacity = (box.isVisible) ? 1 : 0;
225
+ box.elem.inert = !box.isVisible;
226
+ box.aria = { hidden: !box.isVisible };
227
+ };
228
+
229
+ // LABEL: A round button at a side, with a chevron. side: "left" or "right"
230
+ const createSideButton = function (side) {
231
+ const _b = _s.button;
232
+ const button = Label({
233
+ top: "calc(50% - " + (_b.size / 2) + "px)", // WHY: In the middle of the height of the box.
234
+ width: _b.size,
235
+ height: _b.size,
236
+ color: _b.color,
237
+ border: _b.border,
238
+ borderColor: _b.borderColor,
239
+ round: _b.round,
240
+ text: PeriodBar.getChevronSvg(side, _b.iconColor, _b.iconSize, _b.iconLine),
241
+ lineHeight: "0",
242
+ clickable: 1,
243
+ css: { display: "flex", alignItems: "center", justifyContent: "center" },
244
+ });
245
+ button.role = "button";
246
+ button.aria = { label: (side === "left") ? texts.previous : texts.next };
247
+ if (side === "left") button.left = _b.side;
248
+ else button.right = _b.side;
249
+ return button;
250
+ };
251
+
252
+ const onKeyDown = function (self, event) {
253
+ if (event.key === "ArrowLeft") {
254
+ event.preventDefault();
255
+ box.selectPrevious();
256
+ return;
257
+ }
258
+ if (event.key === "ArrowRight") {
259
+ event.preventDefault();
260
+ box.selectNext();
261
+ }
262
+ };
263
+
264
+ // *** PUBLIC FUNCTIONS:
265
+
266
+ // silent: 1 -> onChange is not called. Returns 1 when another month is shown.
267
+ box.setValue = function (value, silent = 0) {
268
+ const index = toIndex(value);
269
+ if (index === box.value) return 0;
270
+ const oldIndex = box.value;
271
+ box.previousValue = oldIndex;
272
+ box.value = index;
273
+ moveItems(oldIndex, index);
274
+ paintButtons();
275
+ if (!silent) box.onChange(box);
276
+ return 1;
277
+ };
278
+ // USAGE: periodBar.setValue(0) // the oldest month. setValue(null): this month
279
+
280
+ box.selectNext = function (silent = 0) {
281
+ return box.setValue(box.value + 1, silent);
282
+ };
283
+
284
+ box.selectPrevious = function (silent = 0) {
285
+ return box.setValue(box.value - 1, silent);
286
+ };
287
+
288
+ // The year and the month (1-12) of the selected month.
289
+ box.getSelectedDate = function () {
290
+ const period = periods[box.value];
291
+ return { year: period.year, month: period.month };
292
+ };
293
+ // USAGE: const date = periodBar.getSelectedDate(); // { year: 2026, month: 10 }
294
+
295
+ // With motion: it drops in from above (1) / goes up (0). (box.visible: at once, without motion)
296
+ box.setVisible = function (isVisible) {
297
+ const value = basic.isOn(isVisible) ? 1 : 0;
298
+ if (box.isVisible === value) return;
299
+ box.isVisible = value;
300
+ showVisibility();
301
+ };
302
+ // USAGE: periodBar.setVisible(0)
303
+
304
+ box.focus = function () {
305
+ box.elem.focus({ preventScroll: true });
306
+ };
307
+
308
+ // *** OBJECT VIEW:
309
+
310
+ const pillSize = "calc(100% - " + (_s.pill.space * 2) + "px)";
311
+
312
+ // BOX: The white capsule
313
+ box.pill = Box({
314
+ left: _s.pill.space,
315
+ top: _s.pill.space,
316
+ width: pillSize,
317
+ height: pillSize,
318
+ color: _s.pill.color,
319
+ round: _s.pill.round,
320
+ border: _s.pill.border,
321
+ borderColor: _s.pill.borderColor,
322
+ });
323
+
324
+ // BOX: The months (over the capsule, in its shape: a month that comes in or leaves is cut at its edge)
325
+ box.itemsBox = Box({
326
+ left: _s.pill.space,
327
+ top: _s.pill.space,
328
+ width: pillSize,
329
+ height: pillSize,
330
+ color: "transparent",
331
+ round: _s.pill.round,
332
+ });
333
+ box.itemsBox.aria = { live: "polite" };
334
+
335
+ // LABEL: The buttons (over the months: a month passes under them)
336
+ box.btnPrevious = createSideButton("left");
337
+ box.btnNext = createSideButton("right");
338
+
339
+ // *** OBJECT INIT CODE:
340
+
341
+ box.role = "group";
342
+ box.aria = { label: box.ariaLabel || texts.group };
343
+ box.tabIndex = 0;
344
+
345
+ // WHY: The ring goes around the capsule, not around the transparent box: a :focus-visible rule of the box paints it.
346
+ basic.addCss("period-bar-css",
347
+ ".period-bar:focus { outline: none; }" +
348
+ ".period-bar:focus-visible > .period-bar-pill { box-shadow: var(--period-bar-ring); }");
349
+ box.elem.classList.add("period-bar");
350
+ box.pill.elem.classList.add("period-bar-pill");
351
+ box.css.setProperty("--period-bar-ring", "0 0 0 " + _s.focus.ringWidth + "px " + _s.focus.ringColor);
352
+
353
+ box.btnPrevious.on("click", function () { box.selectPrevious(); });
354
+ box.btnNext.on("click", function () { box.selectNext(); });
355
+ box.on("keydown", onKeyDown);
356
+ box.clickable = 0; // WHY: on() made the box clickable; its transparent sides must let the clicks go to the page.
357
+
358
+ box.value = toIndex(box.value); // WHY: null (or a number out of the list) becomes a month of the list.
359
+ createItems();
360
+ paintButtons();
361
+
362
+ return endObject(box);
363
+
364
+ };
365
+
366
+ // *** STATIC VARIABLES AND FUNCTIONS:
367
+
368
+ // The texts of a language. The month names are the ones of basic.js.
369
+ // USAGE: PeriodBar.TEXTS.de = { today: "HEUTE", lastMonth: "LETZTER MONAT", monthsAgo: "VOR {n} MONATEN", months: [...], ... }
370
+ PeriodBar.TEXTS = {
371
+ en: {
372
+ today: "TODAY",
373
+ lastMonth: "LAST MONTH",
374
+ monthsAgo: "{n} MONTHS AGO",
375
+ months: basic.months,
376
+ group: "Month",
377
+ previous: "Previous month",
378
+ next: "Next month",
379
+ },
380
+ tr: {
381
+ today: "BUGÜN",
382
+ lastMonth: "GEÇEN AY",
383
+ monthsAgo: "{n} AY ÖNCE",
384
+ months: basic.aylar,
385
+ group: "Ay",
386
+ previous: "Önceki ay",
387
+ next: "Sonraki ay",
388
+ },
389
+ };
390
+
391
+ PeriodBar.getTexts = function (language) {
392
+ const texts = PeriodBar.TEXTS[language];
393
+ if (texts) return texts;
394
+ console.warn("PeriodBar: No texts for the language: " + language);
395
+ return PeriodBar.TEXTS.en;
396
+ };
397
+
398
+ // The months of the bar, the oldest first: [{ year, month (1-12), titleText, nameText }]
399
+ // USAGE: PeriodBar.getPeriods(3, PeriodBar.TEXTS.en) // September, LAST MONTH October, TODAY 1 November
400
+ PeriodBar.getPeriods = function (monthCount, texts, today = new Date()) {
401
+ const periods = [];
402
+ for (let monthsAgo = monthCount - 1; monthsAgo >= 0; monthsAgo--) {
403
+ // WHY: Day 1: a month back from the 31st must not jump over a short month.
404
+ const date = new Date(today.getFullYear(), today.getMonth() - monthsAgo, 1);
405
+ periods.push({
406
+ year: date.getFullYear(),
407
+ month: date.getMonth() + 1,
408
+ titleText: PeriodBar.getTitleText(monthsAgo, texts),
409
+ nameText: PeriodBar.getNameText(date, monthsAgo, today, texts),
410
+ });
411
+ }
412
+ return periods;
413
+ };
414
+
415
+ // "TODAY", "LAST MONTH", "2 MONTHS AGO"
416
+ PeriodBar.getTitleText = function (monthsAgo, texts) {
417
+ if (monthsAgo === 0) return texts.today;
418
+ if (monthsAgo === 1) return texts.lastMonth;
419
+ return texts.monthsAgo.replace("{n}", monthsAgo);
420
+ };
421
+
422
+ // "1 November" (this month: the day of today), "October", "December 2025" (another year)
423
+ PeriodBar.getNameText = function (date, monthsAgo, today, texts) {
424
+ const monthName = texts.months[date.getMonth()];
425
+ if (monthsAgo === 0) return today.getDate() + " " + monthName;
426
+ if (date.getFullYear() !== today.getFullYear()) return monthName + " " + date.getFullYear();
427
+ return monthName;
428
+ };
429
+
430
+ // side: "left" or "right". line: the width of the line on a 24 px grid.
431
+ PeriodBar.getChevronSvg = function (side, color, size, line) {
432
+ const path = (side === "left") ? "M15.25 5.5 8.75 12l6.5 6.5" : "M8.75 5.5 15.25 12l-6.5 6.5";
433
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24"' +
434
+ ' fill="none" stroke="' + color + '" stroke-width="' + line + '" stroke-linecap="round" stroke-linejoin="round"' +
435
+ ' aria-hidden="true"><path d="' + path + '"/></svg>';
436
+ };