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,308 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ ScrollArea - v26.11
6
+
7
+ UI COMPONENT
8
+ - A box whose content scrolls: the page of a window, a list between a bar at the top and a bar at the bottom. Start it
9
+ like VGroup and close it with endGroup(): the objects go into its content (a VGroup: align, gap, padding), one under
10
+ the other, and they scroll when they are taller than the area.
11
+ - On a box (the page): it fills it (0, 0, 100%, 100%). In a group: it takes the room the other objects leave (the height
12
+ left in a VGroup, the width left in an HGroup), so a column of a MenuBar, a ScrollArea and a StatusBar needs no css.
13
+ A size of its own (height: 300) wins. (A group with height: "auto" leaves no room: give the area a height there.)
14
+ - scrollY: 1 (default) scrolls down. scrollX: 1 scrolls to the side too: what can wrap (a text, a group with wrap: 1)
15
+ wraps at the width of the area, what can not (a wide table, a row of tiles) scrolls.
16
+ - The scroll bar of the kit (basic/scroll-bar.js), when it is loaded. Without it the area scrolls with the wheel and the
17
+ finger, with no bar (basic.css hides the bar of the browser).
18
+ - Objects added later: createIn(area.content, function () { ... }). The place: scrollToTop(), scrollToEnd(),
19
+ scrollToObject(obj), getScrollTop() / setScrollTop(), onScroll.
20
+ - The look of the area is the one of a Box (color, border, round): give it in the params. Its padding is the one of the
21
+ content: it scrolls with it.
22
+ - Style packages (the scroll bar): "light" (default), "dark" (a light bar), "minimal", "minimalDark" (a thin bar
23
+ without the dots). Select with styleName. (ScrollArea.styles)
24
+
25
+ USAGE:
26
+ ScrollArea({ align: "center top", gap: 20, padding: 40 }); // the whole window
27
+ Label({ text: "A long page" });
28
+ endGroup();
29
+
30
+ VGroup({ gap: 0 });
31
+ MenuBar({ menus: [{ text: "File", items: ["Open", "Save"] }] });
32
+ ScrollArea({ gap: 8, padding: 16 }); // the height between the two bars
33
+ Label({ text: "A row" });
34
+ endGroup();
35
+ StatusBar({ messageText: "Ready" });
36
+ endGroup();
37
+
38
+ const list = ScrollArea({ height: 300, styleName: "dark", onScroll: function (self) { println(self.getScrollTop()); } });
39
+ endGroup();
40
+ createIn(list.content, function () { Label({ text: "Added later" }); });
41
+ list.scrollToEnd();
42
+
43
+ ScrollArea({ height: 120, scrollX: 1, scrollY: 0 }); // only to the side
44
+ HGroup({ hug: 1, gap: 8 });
45
+ Label({ text: "A wide row" });
46
+ endGroup();
47
+ endGroup();
48
+
49
+ Started Date: November 2026
50
+ Webpage: https://bug7a.github.io/js-components/
51
+
52
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
53
+ Licensed under the Apache License, Version 2.0
54
+ SPDX-License-Identifier: Apache-2.0
55
+
56
+ */
57
+
58
+ "use strict";
59
+
60
+ // Default values:
61
+ const ScrollAreaDefaults = {
62
+ key: "0", // Your name for this object: read it in a callback (self.key)
63
+ left: 0, // The place on a box (the page). In a group, the group places it.
64
+ top: 0,
65
+ width: "100%", // "100%" in an HGroup: the width the other objects leave.
66
+ height: "100%", // "100%" in a VGroup: the height the other objects leave.
67
+ align: "left top", // The content, as in a VGroup: "center top", "center center" (in the middle while it fits)...
68
+ gap: 0, // px between the objects of the content
69
+ padding: 0, // Around the content, it scrolls with it: 40, [x, y] or [left, top, right, bottom]
70
+ scrollY: 1, // 1: it scrolls down.
71
+ scrollX: 0, // 1: it scrolls to the side too.
72
+ useScrollBar: 1, // 1: the ScrollBar of the kit, when basic/scroll-bar.js is loaded. (Only at create time)
73
+ onScroll: function (self) { }, // The content moved. (self.getScrollTop())
74
+ styleName: "light", // "light", "dark", "minimal", "minimalDark" or a name added to ScrollArea.styles
75
+ style: { // Light style package (default)
76
+ scrollBar: {}, // The params of ScrollBar (basic/scroll-bar.js). {}: its own look, the bar of the pages of the kit.
77
+ },
78
+ };
79
+
80
+ const ScrollArea = function (params = {}) {
81
+
82
+ // Merge style package: params.style > ScrollArea.styles[styleName] > ScrollAreaDefaults.style (light)
83
+ basic.applyStylePackage(params, ScrollArea.styles, ScrollAreaDefaults);
84
+
85
+ // Merge params:
86
+ mergeIntoIfMissing(params, ScrollAreaDefaults);
87
+
88
+ // Edit params, if needed:
89
+ // WHY here: after startObject() the open container is the area, and box.width / box.height are measured numbers.
90
+ const flow = ScrollArea.flowOf(getDefaultContainerBox());
91
+ const isFillingHeight = (flow === "column" && String(params.height) === "100%");
92
+ const isFillingWidth = (flow === "row" && String(params.width) === "100%");
93
+
94
+ // BOX: Component container (the frame of the area: its place and its look)
95
+ let box = startObject(params);
96
+
97
+ // NOTE: Parent container is box.containerBox
98
+
99
+ // *** PRIVATE VARIABLES:
100
+ const _s = box.style;
101
+
102
+ // *** PUBLIC VARIABLES:
103
+ box.scrollBox = null; // The Box that scrolls
104
+ box.content = null; // The VGroup of the objects: createIn(area.content, fn)
105
+ box.scrollBar = null; // The ScrollBar, or null (useScrollBar: 0, or no basic/scroll-bar.js)
106
+ // NOTE: Default values are also public variables. (box.align, box.gap, box.scrollY...)
107
+
108
+ // *** PRIVATE FUNCTIONS:
109
+
110
+ // LAYOUT: in a group the area takes the room the other objects leave.
111
+ // WHY flex-basis 0 and the minimum 0: otherwise a flex item is as large as its content; the content must scroll in
112
+ // the room, not make it larger.
113
+ const fillTheRoom = function () {
114
+ box.grow = 1;
115
+ if (isFillingHeight) {
116
+ box.height = "auto";
117
+ box.css = { flexBasis: "0px", minHeight: "0px" };
118
+ }
119
+ if (isFillingWidth) {
120
+ box.width = "auto";
121
+ box.css = { flexBasis: "0px", minWidth: "0px" };
122
+ }
123
+ };
124
+
125
+ // The content goes into the box that scrolls and stays started: the objects until endGroup() go into it.
126
+ // WHY made in the container of the area, then moved: endGroup() goes back to the box that was open when the group
127
+ // was started (the start stack of basic.js), so the next objects of the page go there, not into the area.
128
+ // WHY saveCurrentThat: "that" stays the area, as after any component.
129
+ // WHY clipContent 0: the box that scrolls cuts at the edges of the area; the content does not cut a second time.
130
+ const startContent = function () {
131
+ saveCurrentThat();
132
+ box.content = VGroup({ width: "100%", height: "auto", align: box.align, gap: box.gap, color: "transparent", clipContent: 0 });
133
+ box.scrollBox.add(box.content);
134
+ box.content.position = "absolute";
135
+ box.content.left = 0;
136
+ box.content.top = 0;
137
+ // WHY the minimum: an align "... center" puts a short content in the middle; a tall one grows and scrolls.
138
+ box.content.css.minHeight = "100%";
139
+ restoreThatFromSaved();
140
+ };
141
+
142
+ // PADDING: the one of the content, which scrolls with it.
143
+ // WHY not on the area too: a padding keeps a box at least as large as it. (area.padding keeps the value of the page.)
144
+ const applyPadding = function () {
145
+ box.css.padding = "0px";
146
+ box.content.padding = box.padding;
147
+ };
148
+
149
+ // SCROLL: the box that scrolls takes the axes of the area. (The area keeps them too, so area.scrollY reads them; it
150
+ // has nothing to scroll itself.) An axis that is turned off goes back to its start.
151
+ // WHY "fit-content" to the side: what can wrap (a text, a group with wrap: 1) still wraps at the width of the area,
152
+ // what can not (a wide table, a row of tiles) makes the content wider, so it scrolls and nothing in the middle
153
+ // is cut on the left. ("max-content" would put every wrap on one line.)
154
+ // WHY not clickable: scrollY / scrollX make the area clickable (basic.js); the box that scrolls over it takes the
155
+ // mouse, the area is only its frame.
156
+ const applyScrollAxes = function () {
157
+ box.clickable = 0;
158
+ box.scrollBox.scrollY = box.scrollY;
159
+ box.scrollBox.scrollX = box.scrollX;
160
+ if (box.scrollY != 1) box.scrollBox.elem.scrollTop = 0;
161
+ if (box.scrollX != 1) box.scrollBox.elem.scrollLeft = 0;
162
+ box.content.width = (box.scrollX == 1) ? "fit-content" : "100%";
163
+ box.content.css.minWidth = (box.scrollX == 1) ? "100%" : "";
164
+ if (box.scrollBar) box.scrollBar.refreshScroll();
165
+ };
166
+
167
+ // *** PUBLIC FUNCTIONS:
168
+
169
+ box.setAlign = function (value) {
170
+ box.align = value;
171
+ box.content.align = value;
172
+ };
173
+ // USAGE: area.setAlign("center center") // a short content in the middle
174
+
175
+ box.setGap = function (value) {
176
+ box.gap = value;
177
+ box.content.gap = value;
178
+ };
179
+ // USAGE: area.setGap(12)
180
+
181
+ box.setPadding = function (value) {
182
+ box.padding = value;
183
+ applyPadding();
184
+ };
185
+ // USAGE: area.setPadding([16, 24]) // [x, y]
186
+
187
+ box.setScrollY = function (value) {
188
+ box.scrollY = basic.isOn(value) ? 1 : 0;
189
+ applyScrollAxes();
190
+ };
191
+ // USAGE: area.setScrollY(0) // it does not scroll down any more
192
+
193
+ box.setScrollX = function (value) {
194
+ box.scrollX = basic.isOn(value) ? 1 : 0;
195
+ applyScrollAxes();
196
+ };
197
+ // USAGE: area.setScrollX(1) // to the side too
198
+
199
+ box.getScrollTop = function () {
200
+ return box.scrollBox.elem.scrollTop;
201
+ };
202
+
203
+ box.setScrollTop = function (value) {
204
+ box.scrollBox.elem.scrollTop = value;
205
+ };
206
+ // USAGE: const top = area.getScrollTop(); ... area.setScrollTop(top) // back to the same place
207
+
208
+ box.scrollToTop = function () {
209
+ box.scrollBox.elem.scrollTop = 0;
210
+ box.scrollBox.elem.scrollLeft = 0;
211
+ };
212
+
213
+ // The end of the content: its bottom (an area that scrolls only to the side: its right end).
214
+ box.scrollToEnd = function () {
215
+ const elem = box.scrollBox.elem;
216
+ if (box.scrollY == 1) {
217
+ elem.scrollTop = elem.scrollHeight;
218
+ return;
219
+ }
220
+ elem.scrollLeft = elem.scrollWidth;
221
+ };
222
+ // USAGE: chat.scrollToEnd() // the last message
223
+
224
+ // An object of the content comes into view, and the area moves as little as it can.
225
+ // WHY not elem.scrollIntoView(): it moves the page and every box that scrolls around the area too.
226
+ box.scrollToObject = function (obj) {
227
+ const elem = box.scrollBox.elem;
228
+ if (!obj || !obj.elem || !elem.contains(obj.elem)) return;
229
+ const view = elem.getBoundingClientRect();
230
+ const place = obj.elem.getBoundingClientRect();
231
+ elem.scrollTop += ScrollArea.distanceToShow(place.top - view.top, place.bottom - view.top, elem.clientHeight);
232
+ elem.scrollLeft += ScrollArea.distanceToShow(place.left - view.left, place.right - view.left, elem.clientWidth);
233
+ };
234
+ // USAGE: form.scrollToObject(nameField) // the first field to fill
235
+
236
+ // *** OBJECT VIEW:
237
+
238
+ if (isFillingHeight || isFillingWidth) fillTheRoom();
239
+
240
+ // BOX: The box that scrolls (the content is moved into it by startContent)
241
+ box.scrollBox = Box(0, 0, "100%", "100%", { color: "transparent" });
242
+
243
+ // SCROLL BAR: the one of the kit, over the box that scrolls. (It is made in the area, so remove() takes it.)
244
+ if (box.useScrollBar == 1 && typeof ScrollBar !== "undefined") {
245
+ box.scrollBar = ScrollBar(Object.assign({ scrollableBox: box.scrollBox }, _s.scrollBar));
246
+ }
247
+
248
+ // *** OBJECT INIT CODE:
249
+
250
+ box.scrollBox.on("scroll", function () {
251
+ box.onScroll(box);
252
+ });
253
+
254
+ endObject(box);
255
+
256
+ // GROUP: The content, left started for the objects of the page (endGroup() closes it)
257
+ startContent();
258
+ applyPadding();
259
+ applyScrollAxes();
260
+
261
+ return box;
262
+
263
+ };
264
+
265
+ // *** STATIC VARIABLES AND FUNCTIONS:
266
+
267
+ // The flow of the container an object is made in: "column" (a VGroup), "row" (an HGroup) or "" (a box, the page).
268
+ ScrollArea.flowOf = function (container) {
269
+ const direction = (container && container.elem) ? container.elem.style.flexDirection : "";
270
+ if (direction.indexOf("column") === 0) return "column";
271
+ if (direction.indexOf("row") === 0) return "row";
272
+ return "";
273
+ };
274
+
275
+ // How far an area moves so that a part (from start to end: px from its top or its left) is seen in its size.
276
+ // A part larger than the area shows its start.
277
+ ScrollArea.distanceToShow = function (start, end, size) {
278
+ if (start < 0) return start;
279
+ if (end > size) return Math.min(end - size, start);
280
+ return 0;
281
+ };
282
+
283
+ // *** STYLE PACKAGES:
284
+ // USAGE: ScrollArea({ styleName: "dark" })
285
+ // USAGE: ScrollArea({ style: { scrollBar: { neverHide: 0 } } }) // any param of ScrollBar
286
+ ScrollArea.styles = {
287
+
288
+ // The bar of the pages of the kit: dark gray, a dot at each end.
289
+ light: ScrollAreaDefaults.style,
290
+
291
+ // For a dark page: a light bar.
292
+ dark: {
293
+ scrollBar: { bar_color: "#CFCFCD", bar_mouseOverColor: "#CFCFCD" },
294
+ },
295
+
296
+ };
297
+
298
+ // The minimal theme (_designs/minimal-theme.htm): a thin bar without the dots. MinimalAccent makes the packages of a
299
+ // color of the page with the same function (the bar stays gray).
300
+ ScrollArea.createMinimalStyle = function (colors) {
301
+ return {
302
+ scrollBar: { bar_color: colors.scrollBar, bar_mouseOverColor: colors.scrollBar, bar_width: 3, bar_mouseOverWidth: 4, showDots: 0 },
303
+ };
304
+ };
305
+ ScrollArea.MINIMAL_COLORS = { scrollBar: "#373836" };
306
+ ScrollArea.styles.minimal = ScrollArea.createMinimalStyle(ScrollArea.MINIMAL_COLORS);
307
+ ScrollArea.MINIMAL_DARK_COLORS = { scrollBar: "#CFCFCD" };
308
+ ScrollArea.styles.minimalDark = ScrollArea.createMinimalStyle(ScrollArea.MINIMAL_DARK_COLORS);
@@ -0,0 +1,297 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Scrolling Text - v26.10
6
+
7
+ A one line text that slides to show its end when it does not fit in its box (a long name, a title, a cell).
8
+ The text waits at its start, slides to its end, waits, and goes back.
9
+ - mode "always": it slides again and again (the faded edges show that there is more text).
10
+ - The edges: the left one is clear while the text is at its start, the right one fades where the text goes on; at
11
+ the end the text slides a little more (fade.width), so its last letters are clear too.
12
+ - mode "hover": "..." at the end while it waits. The mouse comes: the right edge fades over the "..." (0.3 s), then
13
+ the whole text slides at once; the mouse leaves: it goes back in 0.3 s and "..." comes again
14
+ (Ex: the cells of comp/tiny-table.js).
15
+ - A text that fits never moves. The speed is in px per second, so a long text takes longer, not faster.
16
+ - The texts are plain text; allowHtml: 1 lets them be HTML (only for texts of your own code).
17
+ - No motion when the system asks for reduced motion: the text ends with "...".
18
+
19
+ USAGE:
20
+ ScrollingText({ width: 200, labelText: "Start. Vegetables are healthy. End." });
21
+ ScrollingText({ width: 120, labelText: "A long name of a file.pdf", mode: "hover" });
22
+ ScrollingText({ width: 200, labelText: "A long title", waitTime: 2, minWaitTime: 0.8, fullWaitDistance: 200 });
23
+ text.setLabelText("Another text");
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 ScrollingTextDefaults = {
38
+ width: 200,
39
+ height: "auto", // As high as the text (with the padding)
40
+ labelText: "",
41
+ allowHtml: 0, // 1: the text is HTML (only for your own texts)
42
+ mode: "always", // "always": it slides again and again; "hover": only while the mouse is over it
43
+ speed: 40, // px in a second
44
+ waitTime: 1.2, // s: at the start and at the end (the longest wait: a short slide waits less)
45
+ minWaitTime: 0.5, // s: the wait of a very short slide (a few hidden letters are read quickly, but not in a blink)
46
+ fullWaitDistance: 120, // px: a slide this long (or longer) waits the whole waitTime; a shorter one waits less
47
+ styleName: "classic", // "classic" or a name added to ScrollingText.styles
48
+ style: {
49
+ box: { color: "transparent", padding: [0, 0] }, // padding: [x, y] around the text
50
+ label: { fontSize: 16, textColor: Black(0.8) },
51
+ fade: { width: 10 }, // px: the faded edges while the text is longer than the box
52
+ },
53
+ };
54
+
55
+ const ScrollingText = function (params = {}) {
56
+
57
+ // Merge style package: params.style > ScrollingText.styles[styleName] > ScrollingTextDefaults.style
58
+ basic.applyStylePackage(params, ScrollingText.styles, ScrollingTextDefaults);
59
+
60
+ // Merge params:
61
+ mergeIntoIfMissing(params, ScrollingTextDefaults);
62
+
63
+ // BOX: Component container
64
+ let box = startObject(params);
65
+
66
+ // *** PRIVATE VARIABLES:
67
+ const _s = box.style;
68
+ const EDGE_TIME = 300; // ms: the faded edges come and go, and the text goes back (soft, not slow)
69
+ let motion = null; // The Web Animation of the label (its slide)
70
+ let edgeMotion = null; // The Web Animation of the left edge (it fades while the text is away from its start)
71
+ let isHover = 0;
72
+ let isOpen = 0; // 1: the whole text is shown (it slides); 0: it ends with "..."
73
+ let cancelOpen = null; // "hover": the text opens when the right edge has faded
74
+
75
+ // *** PUBLIC VARIABLES:
76
+ box.isLonger = 0; // 1: the text does not fit (it can slide)
77
+
78
+ // *** PRIVATE FUNCTIONS:
79
+
80
+ const isReducedMotion = function () {
81
+ return window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
82
+ };
83
+
84
+ const canSlide = function () {
85
+ return box.isLonger && !isReducedMotion();
86
+ };
87
+
88
+ // How many px the text is longer than its place
89
+ const getOverflow = function () {
90
+ return Math.max(0, box.label.elem.scrollWidth - box.viewport.elem.clientWidth);
91
+ };
92
+
93
+ // The edges of the mask (1: clear, 0: faded); a CSS variable of the viewport
94
+ const setEdge = function (side, value) {
95
+ box.viewport.elem.style.setProperty("--scrolling-text-" + side, String(value));
96
+ };
97
+
98
+ const getEdge = function (side) {
99
+ return parseFloat(getComputedStyle(box.viewport.elem).getPropertyValue("--scrolling-text-" + side)) || 0;
100
+ };
101
+
102
+ const stopMotion = function () {
103
+ if (motion) motion.cancel();
104
+ if (edgeMotion) edgeMotion.cancel();
105
+ motion = null;
106
+ edgeMotion = null;
107
+ };
108
+
109
+ // A short slide shows only a few letters, so it waits less at its ends (a long round for 3 letters was tiring)
110
+ const getWaitTime = function (distance) {
111
+ const part = (box.fullWaitDistance > 0) ? Math.min(1, distance / box.fullWaitDistance) : 1;
112
+ return Math.min(box.waitTime, Math.max(box.minWaitTime, box.waitTime * part));
113
+ };
114
+
115
+ // Wait, slide to the end, wait, slide back: one round (it repeats). The waits are in the keyframe offsets.
116
+ // skipFirstWait: "hover" starts at once (its wait was the fading of the right edge).
117
+ const startMotion = function (skipFirstWait) {
118
+
119
+ stopMotion();
120
+ if (!canSlide()) return;
121
+
122
+ // WHY + fade: at the end the last letters come out of the faded right edge, so they are read clearly
123
+ const fade = _s.fade.width;
124
+ const distance = getOverflow() + fade;
125
+ const slideTime = distance / box.speed;
126
+ const waitTime = getWaitTime(distance);
127
+ const roundTime = 2 * slideTime + 2 * waitTime;
128
+ const waitPart = waitTime / roundTime;
129
+ const slidePart = slideTime / roundTime;
130
+ const end = "translateX(-" + distance + "px)";
131
+ const timing = {
132
+ duration: roundTime * 1000,
133
+ iterations: Infinity,
134
+ easing: "linear",
135
+ // WHY a negative delay: the round starts at the end of its first wait
136
+ delay: skipFirstWait ? -waitTime * 1000 : 0,
137
+ };
138
+
139
+ motion = box.label.elem.animate([
140
+ { transform: "translateX(0)", offset: 0 },
141
+ { transform: "translateX(0)", offset: waitPart },
142
+ { transform: end, offset: waitPart + slidePart },
143
+ { transform: end, offset: 2 * waitPart + slidePart },
144
+ { transform: "translateX(0)", offset: 1 },
145
+ ], timing);
146
+
147
+ // The left edge is clear while the text is at its start (its first letters are read), and fades in the
148
+ // first fade px of the slide: the same timing, so it moves with the text
149
+ const edgePart = slidePart * Math.min(1, fade / distance);
150
+ edgeMotion = box.viewport.elem.animate([
151
+ { "--scrolling-text-left": 1, offset: 0 },
152
+ { "--scrolling-text-left": 1, offset: waitPart },
153
+ { "--scrolling-text-left": 0, offset: waitPart + edgePart },
154
+ { "--scrolling-text-left": 0, offset: 1 - edgePart },
155
+ { "--scrolling-text-left": 1, offset: 1 },
156
+ ], timing);
157
+
158
+ };
159
+
160
+ // The text: the whole text (it slides) or "..." at the end
161
+ const setOpen = function (value) {
162
+ isOpen = value ? 1 : 0;
163
+ box.label.width = isOpen ? "auto" : "100%";
164
+ box.label.css = { textOverflow: isOpen ? "clip" : "ellipsis" };
165
+ };
166
+
167
+ // The mask and the text for the state (no motion here)
168
+ const paint = function () {
169
+ const fade = _s.fade.width + "px";
170
+ const left = "rgba(0, 0, 0, var(--scrolling-text-left))";
171
+ const right = "rgba(0, 0, 0, var(--scrolling-text-right))";
172
+ const mask = canSlide() ? "linear-gradient(to right, " + left + ", black " + fade + ", black calc(100% - " + fade + "), " + right + ")" : "none";
173
+ box.viewport.css = { maskImage: mask, webkitMaskImage: mask };
174
+ setEdge("left", 1);
175
+ setEdge("right", (canSlide() && (box.mode == "always" || isHover)) ? 0 : 1);
176
+ setOpen(canSlide() && (box.mode == "always" || isOpen));
177
+ };
178
+
179
+ // "hover": the right edge fades over the "..." first (EDGE_TIME), then the whole text comes and slides at once
180
+ const openOnHover = function () {
181
+ paint();
182
+ if (!canSlide()) return;
183
+ cancelOpen = box.after(EDGE_TIME, function () {
184
+ cancelOpen = null;
185
+ setOpen(1);
186
+ startMotion(1);
187
+ });
188
+ };
189
+
190
+ // "hover": the text and its left edge go back from where they are, then "..." comes under the clear right edge
191
+ const closeOnHover = function () {
192
+ if (cancelOpen) cancelOpen();
193
+ cancelOpen = null;
194
+ if (!motion) {
195
+ paint();
196
+ return;
197
+ }
198
+ const transform = getComputedStyle(box.label.elem).transform;
199
+ const leftEdge = getEdge("left");
200
+ stopMotion();
201
+ const back = { duration: EDGE_TIME, easing: "ease-out" };
202
+ box.viewport.elem.animate([{ "--scrolling-text-left": leftEdge }, { "--scrolling-text-left": 1 }], back);
203
+ box.label.elem.animate([{ transform: transform }, { transform: "translateX(0)" }], back).onfinish = function () {
204
+ if (!box || isHover) return;
205
+ setOpen(0);
206
+ paint();
207
+ };
208
+ };
209
+
210
+ // Measures again: does the text fit? (a new text, a new size)
211
+ const refreshLayout = function () {
212
+ if (!box) return;
213
+ box.label.width = "auto";
214
+ box.isLonger = (getOverflow() > 0) ? 1 : 0;
215
+ paint();
216
+ // WHY: a new text under the mouse (a short one before it closed the slide) opens like a new hover
217
+ if (box.mode == "hover" && isHover && !isOpen) {
218
+ if (!cancelOpen) openOnHover();
219
+ return;
220
+ }
221
+ if (box.mode == "always" || isOpen) startMotion(isOpen && box.mode == "hover");
222
+ else stopMotion();
223
+ };
224
+
225
+ // *** PUBLIC FUNCTIONS:
226
+
227
+ box.setLabelText = function (text) {
228
+ if (!box) return;
229
+ box.labelText = (text === undefined || text === null) ? "" : String(text);
230
+ if (box.allowHtml == 1) box.label.text = box.labelText;
231
+ else box.label.plainText = box.labelText;
232
+ refreshLayout();
233
+ };
234
+ // USAGE: get: text.labelText, set: text.setLabelText("A long text")
235
+
236
+ box.refresh = function () {
237
+ refreshLayout();
238
+ };
239
+
240
+ // REMOVE: the endless Web Animations ("always") are cancelled (basic.js remove() does not know them)
241
+ const superRemove = box.remove;
242
+ box.superRemove = superRemove;
243
+ box.remove = function () {
244
+ if (!box) return;
245
+ stopMotion();
246
+ superRemove.call(box);
247
+ box = null;
248
+ };
249
+
250
+ // *** OBJECT VIEW:
251
+
252
+ // WHY @property: only a registered variable is a number that can change softly (a plain one jumps)
253
+ basic.addCss("scrolling-text-edge",
254
+ "@property --scrolling-text-left { syntax: '<number>'; inherits: false; initial-value: 1; }" +
255
+ "@property --scrolling-text-right { syntax: '<number>'; inherits: false; initial-value: 1; }");
256
+
257
+ box.props({ color: _s.box.color, padding: _s.box.padding });
258
+
259
+ // BOX: The place of the text (it cuts the sliding text; the padding of the box stays empty)
260
+ box.viewport = startBox({ width: "100%", height: "auto", color: "transparent", position: "relative", clipContent: 1 });
261
+ box.viewport.css = { transition: "--scrolling-text-right " + EDGE_TIME + "ms" };
262
+
263
+ // LABEL: Text
264
+ box.label = Label({
265
+ ..._s.label,
266
+ position: "relative",
267
+ // WHY inline-block: a block label is as wide as its place even with width "auto": the sliding text was cut at that width
268
+ css: { whiteSpace: "nowrap", overflow: "hidden", display: "inline-block", verticalAlign: "top", maxWidth: "none", willChange: "transform" },
269
+ });
270
+
271
+ endBox();
272
+
273
+ // *** OBJECT INIT CODE:
274
+
275
+ box.onHoverChange(function (self, isOver) {
276
+ if (box.mode != "hover") return;
277
+ isHover = isOver ? 1 : 0;
278
+ if (isHover) openOnHover();
279
+ else closeOnHover();
280
+ });
281
+ if (box.mode == "hover") box.clickable = 1; // WHY: a basic.js box gets no mouse events by default
282
+
283
+ box.onResize(refreshLayout);
284
+ box.setLabelText(box.labelText);
285
+ // WHY: the text is measured again when the font is loaded (a fixed width box gets no resize then)
286
+ if (document.fonts) document.fonts.ready.then(function () { if (box) refreshLayout(); });
287
+
288
+ return endObject(box);
289
+
290
+ };
291
+
292
+ // *** STYLE PACKAGES:
293
+ // USAGE: ScrollingText({ style: { label: { fontSize: 14 } } })
294
+ // NOTE: A new package needs only the keys that differ from the classic style.
295
+ ScrollingText.styles = {
296
+ classic: ScrollingTextDefaults.style,
297
+ };
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="12" r="11" fill="#FFFFFF" stroke="rgba(0,0,0,0.12)" stroke-width="1"/><path d="M8 8l8 8M16 8l-8 8" fill="none" stroke="#333333" stroke-width="2" stroke-linecap="round"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="m336-280 144-144 144 144 56-56-144-144 144-144-56-56-144 144-144-144-56 56 144 144-144 144 56 56ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg id="Layer_1" height="512" viewBox="0 0 24 24" width="512" xmlns="http://www.w3.org/2000/svg" data-name="Layer 1"><path d="m14 24a1 1 0 0 1 -.6-.2l-4-3a1 1 0 0 1 -.4-.8v-5.62l-7.016-7.893a3.9 3.9 0 0 1 2.916-6.487h14.2a3.9 3.9 0 0 1 2.913 6.488l-7.013 7.892v8.62a1 1 0 0 1 -1 1zm-3-4.5 2 1.5v-7a1 1 0 0 1 .253-.664l7.268-8.177a1.9 1.9 0 0 0 -1.421-3.159h-14.2a1.9 1.9 0 0 0 -1.421 3.158l7.269 8.178a1 1 0 0 1 .252.664z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M23.707 22.293l-5.969-5.969a10.016 10.016 0 10-1.414 1.414l5.969 5.969a1 1 0 001.414-1.414zM10 18a8 8 0 118-8 8.009 8.009 0 01-8 8z"/></svg>