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,530 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ LogView - v26.11
6
+
7
+ UI COMPONENT
8
+ - The output of a program: one line for each message, colored by its level (info, success, warn, error, debug),
9
+ with its time and the name of its level.
10
+ - It follows the last line. A scroll up stops that (the lines being read stay in place); a small "12 new" button
11
+ goes back to the end. It also waits while a text is selected.
12
+ - The texts are shown as they are (never as HTML), they can be selected and copied, and their spaces are kept.
13
+ A text with many lines becomes many lines. A long line wraps under its own text (wrapLines: 0: it does not wrap,
14
+ the view scrolls sideways).
15
+ - maxLines: the oldest lines go, so a program that writes for days does not fill the memory.
16
+ - A fast program does not draw for each line: the lines that come together are drawn together.
17
+ - setLevels(["warn", "error"]) shows only those levels.
18
+ - Uses ScrollBar (basic/scroll-bar.js) if the page has loaded it; it works without it too.
19
+ - Style packages: "light" (default), "dark". Select with styleName (LogView.styles), or later with setTheme().
20
+
21
+ USAGE:
22
+ const log = LogView({ width: 600, height: 300 });
23
+ log.addLine("Reading config.json");
24
+ log.success("14 files found");
25
+ log.warn("photo.jpg is very large");
26
+ log.error("disk.bin can not be read");
27
+ log.debug("cache: 31 items");
28
+ log.addLine("A line of a level of your own", "myLevel"); // its look: style.levels.myLevel (or info)
29
+ log.clearLines();
30
+ log.getText(); // all the lines that are shown, as a text
31
+ log.setLevels(["warn", "error"]); log.setLevels([]); // [] : all of them
32
+ log.setShowTime(0);
33
+ log.setShowLevel(0);
34
+ log.setWrapLines(0);
35
+ log.setAutoScroll(0); // it does not follow the last line
36
+ log.setTheme("dark"); // the lines stay
37
+ log.scrollToEnd(); // goes to the end, and follows again
38
+ LogView({ styleName: "dark", lines: ["First line", { text: "Second line", level: "warn" }] });
39
+ LogView({ levelTexts: { info: "BİLGİ", warn: "UYARI", error: "HATA" }, emptyText: "Henüz çıktı yok.", newLinesText: "{count} yeni" });
40
+
41
+ Started Date: November 2026
42
+ Webpage: https://bug7a.github.io/js-components/
43
+
44
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
45
+ Licensed under the Apache License, Version 2.0
46
+ SPDX-License-Identifier: Apache-2.0
47
+
48
+ */
49
+
50
+ "use strict";
51
+
52
+ // Default values:
53
+ const LogViewDefaults = {
54
+ key: "0", // Your name for this object: read it in a callback (self.key)
55
+ width: "100%",
56
+ height: 260,
57
+ lines: [], // The first lines: "Text" or { text, level, time }
58
+ maxLines: 1000, // The oldest lines go. 0: no limit
59
+ autoScroll: 1, // 1: follows the last line
60
+ showTime: 1,
61
+ showLevel: 1,
62
+ wrapLines: 1,
63
+ emptyText: "No output yet.",
64
+ newLinesText: "{count} new", // The button that goes back to the end
65
+ levelTexts: { info: "INFO", success: "OK", warn: "WARN", error: "ERROR", debug: "DEBUG" },
66
+ ariaLabel: "Output",
67
+ styleName: "light", // "light", "dark" or a name added to LogView.styles
68
+ style: { // Light style package (default)
69
+ box: { color: "white", border: 1, borderColor: Black(0.14), round: 8 },
70
+ line: {
71
+ fontSize: 13,
72
+ lineHeight: 20,
73
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace',
74
+ paddingX: 10,
75
+ space: 1, // Space above and below the text of a line
76
+ },
77
+ area: { paddingY: 6 },
78
+ time: { textColor: Black(0.5) },
79
+ // text: the text of the line, tag: the name of its level, color: the ground of the line
80
+ levels: {
81
+ info: { text: Black(0.84), tag: "#2467B8", color: "transparent" },
82
+ success: { text: "#1F7A5C", tag: "#1F7A5C", color: "transparent" },
83
+ warn: { text: "#7A5000", tag: "#7A5000", color: "rgba(241, 199, 74, 0.2)" },
84
+ error: { text: "#B93226", tag: "#B93226", color: "rgba(232, 121, 109, 0.14)" },
85
+ debug: { text: Black(0.55), tag: Black(0.55), color: "transparent" },
86
+ },
87
+ empty: { fontSize: 13, textColor: Black(0.45) },
88
+ newLines: {
89
+ color: "#37474A",
90
+ hoverColor: "#2A383B",
91
+ textColor: "white",
92
+ fontSize: 12,
93
+ height: 28,
94
+ paddingX: 12,
95
+ round: 14,
96
+ bottom: 10,
97
+ shadow: "0 2px 8px " + Black(0.25),
98
+ },
99
+ scrollBar: { bar_color: "#9A9A98", bar_mouseOverColor: "#6A6A68", neverHide: 0, showDots: 0 },
100
+ focus: { ringColor: "rgba(63, 141, 148, 0.8)" },
101
+ },
102
+ };
103
+
104
+ const LogView = function (params = {}) {
105
+
106
+ // Merge style package: params.style > LogView.styles[styleName] > LogViewDefaults.style (light)
107
+ const pageStyle = params.style; // WHY: setTheme() puts it over another package.
108
+ basic.applyStylePackage(params, LogView.styles, LogViewDefaults);
109
+
110
+ // Merge params:
111
+ mergeIntoIfMissing(params, LogViewDefaults);
112
+
113
+ // Edit params, if needed:
114
+ const firstLines = (Array.isArray(params.lines)) ? params.lines : [];
115
+ params.lines = []; // WHY: The first lines are added below, like every other line.
116
+
117
+ // BOX: Component container
118
+ const box = startObject(params);
119
+
120
+ // *** PRIVATE VARIABLES:
121
+ let _s = box.style;
122
+ const BOTTOM_SPACE = 4; // px: this near to the end counts as the end
123
+ const TIME_LENGTH = 8; // "12:03:41"
124
+ let shownLevels = []; // []: all of them
125
+ let isFollowing = 1; // 0: the reader scrolled up
126
+ let newLineCount = 0; // The lines that came after the reader scrolled up
127
+ let lastScrollTop = 0; // The place the last scroll event saw
128
+ let cancelDraw = null; // The cancel function of the waiting drawing
129
+
130
+ // *** PUBLIC VARIABLES:
131
+ // NOTE: box.lines: [{ text, level, time }]: all the lines. (Read only: change them with addLine() and clearLines().)
132
+ // NOTE: Default values are also public variables. (box.maxLines, box.autoScroll, box.showTime...)
133
+
134
+ // *** PRIVATE FUNCTIONS:
135
+
136
+ // The style of a package, with the style of the page over it. (setTheme)
137
+ const styleOfPackage = function (styleName) {
138
+ const fresh = { styleName: styleName, style: pageStyle };
139
+ basic.applyStylePackage(fresh, LogView.styles, LogViewDefaults);
140
+ mergeIntoIfMissing(fresh, LogViewDefaults);
141
+ return fresh.style;
142
+ };
143
+
144
+ const lookOfLevel = function (level) {
145
+ return _s.levels[level] || _s.levels.info;
146
+ };
147
+
148
+ const isLevelShown = function (level) {
149
+ return (shownLevels.length == 0 || shownLevels.indexOf(level) >= 0);
150
+ };
151
+
152
+ const currentTime = function () {
153
+ const now = new Date();
154
+ return [now.getHours(), now.getMinutes(), now.getSeconds()].map(basic.twoDigitFormat).join(":");
155
+ };
156
+
157
+ // WHY: All the names have the same length, so the texts of the lines start at the same place.
158
+ const tagLength = function () {
159
+ const texts = Object.keys(box.levelTexts).map(function (level) { return box.levelTexts[level]; });
160
+ return Math.max.apply(null, texts.map(function (text) { return text.length; }));
161
+ };
162
+
163
+ const tagOfLine = function (line) {
164
+ const text = box.levelTexts[line.level] || String(line.level).toUpperCase();
165
+ return text.padEnd(tagLength());
166
+ };
167
+
168
+ // The letters in front of the text of a line
169
+ const prefixLength = function () {
170
+ const timeLength = (box.showTime == 1) ? TIME_LENGTH + 1 : 0;
171
+ const levelLength = (box.showLevel == 1) ? tagLength() + 1 : 0;
172
+ return timeLength + levelLength;
173
+ };
174
+
175
+ const coloredText = function (text, color) {
176
+ return '<span style="color: ' + color + '">' + basic.escapeHtml(text) + "</span>";
177
+ };
178
+
179
+ // CONTENT: the time, the name of the level and the text of a line
180
+ const rowText = function (line) {
181
+ let html = "";
182
+ if (box.showTime == 1) html += coloredText(line.time, _s.time.textColor) + " ";
183
+ if (box.showLevel == 1) html += coloredText(tagOfLine(line), lookOfLevel(line.level).tag) + " ";
184
+ return html + basic.escapeHtml(line.text);
185
+ };
186
+
187
+ // WHY: A long line wraps under its own text, not under its time: the letters of the mono font have one width.
188
+ const hangingIndent = function () {
189
+ const length = prefixLength();
190
+ return {
191
+ paddingLeft: "calc(" + length + "ch + " + _s.line.paddingX + "px)",
192
+ textIndent: (-length) + "ch",
193
+ };
194
+ };
195
+
196
+ // PAINT: everything of the row of a line that comes from the style and the params
197
+ const paintRow = function (line) {
198
+ const look = lookOfLevel(line.level);
199
+ line.row.props({
200
+ fontSize: _s.line.fontSize,
201
+ lineHeight: _s.line.lineHeight,
202
+ fontFamily: _s.line.fontFamily,
203
+ textColor: look.text,
204
+ color: look.color,
205
+ });
206
+ // WHY: pre-wrap keeps the spaces of the output (a table written with spaces); anywhere breaks a long path.
207
+ line.row.css = {
208
+ whiteSpace: (box.wrapLines == 1) ? "pre-wrap" : "pre",
209
+ overflowWrap: "anywhere",
210
+ padding: _s.line.space + "px " + _s.line.paddingX + "px",
211
+ ...hangingIndent(),
212
+ };
213
+ line.row.text = rowText(line);
214
+ line.row.visible = isLevelShown(line.level) ? 1 : 0;
215
+ };
216
+
217
+ // DATA: the object of one line. Its container must be set. (createIn)
218
+ const createRow = function (line) {
219
+ line.row = Label({ width: "auto", selectable: 1, cursor: "text", shrink: 0 });
220
+ paintRow(line);
221
+ };
222
+
223
+ const isSelectingText = function () {
224
+ const selection = window.getSelection();
225
+ return !!(selection && !selection.isCollapsed && box.elem.contains(selection.anchorNode));
226
+ };
227
+
228
+ // Lines are being read: they stay where they are.
229
+ const isViewHeld = function () {
230
+ return (box.autoScroll != 1 || !isFollowing || isSelectingText());
231
+ };
232
+
233
+ // The oldest lines go. The lines being read stay where they are.
234
+ const dropOldLines = function () {
235
+ if (box.maxLines <= 0 || box.lines.length <= box.maxLines) return;
236
+ const elem = box.scrollArea.elem;
237
+ const heightBefore = elem.scrollHeight;
238
+ box.lines.splice(0, box.lines.length - box.maxLines).forEach(function (line) {
239
+ if (line.row) line.row.remove();
240
+ });
241
+ if (isViewHeld()) elem.scrollTop -= (heightBefore - elem.scrollHeight);
242
+ };
243
+
244
+ // PAINT: the text of an empty view and the button that goes back to the end
245
+ const paintNotes = function () {
246
+ const hasShownLine = box.lines.some(function (line) { return isLevelShown(line.level); });
247
+ box.emptyGroup.visible = (hasShownLine) ? 0 : 1;
248
+ box.btnNewLines.visible = (newLineCount > 0) ? 1 : 0;
249
+ box.btnNewLines.plainText = "↓ " + box.newLinesText.split("{count}").join(newLineCount);
250
+ };
251
+
252
+ const isAtEnd = function () {
253
+ const elem = box.scrollArea.elem;
254
+ return (elem.scrollHeight - elem.scrollTop - elem.clientHeight <= BOTTOM_SPACE);
255
+ };
256
+
257
+ const followLastLine = function () {
258
+ if (isViewHeld()) return;
259
+ box.scrollArea.elem.scrollTop = box.scrollArea.elem.scrollHeight;
260
+ };
261
+
262
+ // WHY: A fast program writes many lines at once. They are drawn together, and only the last maxLines of them.
263
+ const drawNewLines = function () {
264
+ cancelDraw = null;
265
+ dropOldLines();
266
+ const newLines = box.lines.filter(function (line) { return !line.row; });
267
+ createIn(box.lineGroup, function () {
268
+ newLines.forEach(createRow);
269
+ });
270
+ if (box.autoScroll == 1 && !isFollowing) {
271
+ newLineCount += newLines.filter(function (line) { return isLevelShown(line.level); }).length;
272
+ }
273
+ paintNotes();
274
+ followLastLine();
275
+ };
276
+
277
+ const scheduleDraw = function () {
278
+ if (!cancelDraw) cancelDraw = box.after(0, drawNewLines);
279
+ };
280
+
281
+ const addLines = function (text, level, time) {
282
+ // WHY: The last end of line of a printed text is not one more empty line.
283
+ String(text).replace(/\r?\n$/, "").split(/\r?\n/).forEach(function (lineText) {
284
+ box.lines.push({ text: lineText, level: level, time: time, row: null });
285
+ });
286
+ };
287
+
288
+ // Everything of the rows that depends on a param (setShowTime, setShowLevel, setWrapLines, setLevels)
289
+ const refreshRows = function () {
290
+ box.lineGroup.css.width = (box.wrapLines == 1) ? "100%" : "max-content";
291
+ box.lines.forEach(function (line) {
292
+ if (line.row) paintRow(line);
293
+ });
294
+ paintNotes();
295
+ followLastLine();
296
+ };
297
+
298
+ // LOOK: everything that comes from the style (the first drawing and setTheme)
299
+ const applyLook = function () {
300
+ const look = _s.newLines;
301
+ box.props(_s.box);
302
+ box.scrollArea.setFocusRing(_s.focus.ringColor);
303
+ box.lineGroup.padding = [0, _s.area.paddingY];
304
+ box.lblEmpty.props(_s.empty);
305
+ box.btnNewLines.props({
306
+ height: look.height,
307
+ fontSize: look.fontSize,
308
+ color: look.color,
309
+ textColor: look.textColor,
310
+ round: look.round,
311
+ boxShadow: look.shadow,
312
+ });
313
+ box.btnNewLines.css.padding = "0 " + look.paddingX + "px";
314
+ box.btnNewLines.css.bottom = look.bottom + "px";
315
+ box.btnNewLines.setFocusRing(_s.focus.ringColor);
316
+ applyScrollBarLook();
317
+ refreshRows();
318
+ };
319
+
320
+ const applyScrollBarLook = function () {
321
+ if (!box.scrollBar) return;
322
+ Object.assign(box.scrollBar, _s.scrollBar);
323
+ box.scrollBar.boxScrollBarTop.color = _s.scrollBar.bar_color;
324
+ box.scrollBar.boxScrollBarLeft.color = _s.scrollBar.bar_color;
325
+ };
326
+
327
+ // The reader moved: at the end the view follows again, above it the view stays.
328
+ const onScroll = function () {
329
+ // WHY: A scroll event comes a frame late. If lines came meanwhile and nothing moved, it would look like a scroll up.
330
+ if (box.scrollArea.elem.scrollTop === lastScrollTop) return;
331
+ lastScrollTop = box.scrollArea.elem.scrollTop;
332
+ const wasFollowing = isFollowing;
333
+ isFollowing = isAtEnd() ? 1 : 0;
334
+ if (isFollowing && !wasFollowing) {
335
+ newLineCount = 0;
336
+ paintNotes();
337
+ }
338
+ };
339
+
340
+ // *** PUBLIC FUNCTIONS:
341
+
342
+ // WHY the name: box.add() is a function of every Box (a ScrollBar calls it on its parent).
343
+ // time: "12:03:41" (when it was not written just now). "": the time of now.
344
+ box.addLine = function (text, level = "info", time = "") {
345
+ addLines(text, level, time || currentTime());
346
+ scheduleDraw();
347
+ };
348
+ // USAGE: log.addLine("Reading config.json") / log.addLine("Hello", "success")
349
+
350
+ box.info = function (text) { box.addLine(text, "info"); };
351
+ box.success = function (text) { box.addLine(text, "success"); };
352
+ box.warn = function (text) { box.addLine(text, "warn"); };
353
+ box.error = function (text) { box.addLine(text, "error"); };
354
+ box.debug = function (text) { box.addLine(text, "debug"); };
355
+
356
+ box.clearLines = function () {
357
+ box.lines.forEach(function (line) {
358
+ if (line.row) line.row.remove();
359
+ });
360
+ box.lines = [];
361
+ newLineCount = 0;
362
+ isFollowing = 1;
363
+ box.scrollArea.elem.scrollTop = 0;
364
+ lastScrollTop = 0;
365
+ paintNotes();
366
+ };
367
+ // USAGE: log.clearLines()
368
+
369
+ // All the lines that are shown, as they look: for a Copy button or a file.
370
+ box.getText = function () {
371
+ return box.lines.filter(function (line) { return isLevelShown(line.level); }).map(function (line) {
372
+ const time = (box.showTime == 1) ? line.time + " " : "";
373
+ const tag = (box.showLevel == 1) ? tagOfLine(line) + " " : "";
374
+ return time + tag + line.text;
375
+ }).join("\n");
376
+ };
377
+ // USAGE: navigator.clipboard.writeText(log.getText())
378
+
379
+ // Goes to the end and follows the last line again.
380
+ box.scrollToEnd = function () {
381
+ isFollowing = 1;
382
+ newLineCount = 0;
383
+ box.scrollArea.elem.scrollTop = box.scrollArea.elem.scrollHeight;
384
+ paintNotes();
385
+ };
386
+
387
+ box.setAutoScroll = function (value) {
388
+ box.autoScroll = basic.isOn(value) ? 1 : 0;
389
+ if (box.autoScroll == 1) box.scrollToEnd();
390
+ };
391
+ // USAGE: get: log.autoScroll, set: log.setAutoScroll(0)
392
+
393
+ box.setShowTime = function (value) {
394
+ box.showTime = basic.isOn(value) ? 1 : 0;
395
+ refreshRows();
396
+ };
397
+ // USAGE: log.setShowTime(0)
398
+
399
+ box.setShowLevel = function (value) {
400
+ box.showLevel = basic.isOn(value) ? 1 : 0;
401
+ refreshRows();
402
+ };
403
+ // USAGE: log.setShowLevel(0)
404
+
405
+ box.setWrapLines = function (value) {
406
+ box.wrapLines = basic.isOn(value) ? 1 : 0;
407
+ box.scrollArea.scrollX = (box.wrapLines == 1) ? 0 : 1;
408
+ refreshRows();
409
+ };
410
+ // USAGE: log.setWrapLines(0)
411
+
412
+ box.setMaxLines = function (value) {
413
+ box.maxLines = value;
414
+ dropOldLines();
415
+ paintNotes();
416
+ };
417
+ // USAGE: log.setMaxLines(200)
418
+
419
+ box.setLevels = function (levels) {
420
+ shownLevels = (Array.isArray(levels)) ? levels.slice() : [];
421
+ newLineCount = 0;
422
+ refreshRows();
423
+ };
424
+ // USAGE: log.setLevels(["warn", "error"]) / log.setLevels([]) // all of them
425
+
426
+ // Another style package while it is on the page. A style given by the page stays over it.
427
+ box.setTheme = function (styleName) {
428
+ box.styleName = styleName;
429
+ _s = styleOfPackage(styleName);
430
+ box.style = _s;
431
+ applyLook();
432
+ };
433
+ // USAGE: log.setTheme("dark")
434
+
435
+ // *** OBJECT VIEW:
436
+
437
+ // BOX: The lines scroll in it
438
+ box.scrollArea = startBox(0, 0, "100%", "100%", { color: "transparent", scrollY: 1 });
439
+ box.scrollArea.scrollX = (box.wrapLines == 1) ? 0 : 1;
440
+ // WHY: dropOldLines() keeps the place of the reader itself; the browser must not do it a second time.
441
+ box.scrollArea.css.overflowAnchor = "none";
442
+ box.scrollArea.role = "log";
443
+ box.scrollArea.aria = { label: box.ariaLabel };
444
+ box.scrollArea.tabIndex = 0; // WHY: The keys of a focused box scroll it (arrows, Page Up, Home, End).
445
+
446
+ // GROUP: The lines
447
+ box.lineGroup = VGroup({
448
+ width: (box.wrapLines == 1) ? "100%" : "max-content",
449
+ height: "auto",
450
+ align: "left top",
451
+ gap: 0,
452
+ css: { minWidth: "100%", boxSizing: "border-box", alignItems: "stretch" },
453
+ });
454
+ endGroup();
455
+
456
+ endBox();
457
+
458
+ // GROUP: The text of an empty view, in the middle at every size
459
+ box.emptyGroup = VGroup({ left: 0, top: 0, width: "100%", height: "100%", align: "center center", padding: 12 });
460
+ box.lblEmpty = Label({ plainText: box.emptyText, textAlign: "center" });
461
+ endGroup();
462
+
463
+ // BUTTON: Goes back to the end
464
+ box.btnNewLines = Button({
465
+ width: "auto",
466
+ css: {
467
+ whiteSpace: "nowrap",
468
+ left: "50%",
469
+ top: "auto",
470
+ transform: "translateX(-50%)", // WHY: In the middle at every width of its text.
471
+ },
472
+ visible: 0,
473
+ });
474
+ box.btnNewLines.minimal = 1;
475
+
476
+ if (typeof ScrollBar !== "undefined") {
477
+ box.scrollBar = ScrollBar(Object.assign({ scrollableBox: box.scrollArea }, _s.scrollBar));
478
+ }
479
+
480
+ // *** OBJECT INIT CODE:
481
+
482
+ box.scrollArea.on("scroll", onScroll);
483
+ box.btnNewLines.on("click", box.scrollToEnd);
484
+ box.btnNewLines.onHoverChange(function (self, isOver) {
485
+ self.color = (isOver) ? _s.newLines.hoverColor : _s.newLines.color;
486
+ });
487
+
488
+ // WHY: A narrower box wraps more lines, and a hidden box has no end to go to: the end is found again.
489
+ box.onResize(followLastLine);
490
+
491
+ firstLines.forEach(function (line) {
492
+ if (line && typeof line == "object") addLines(line.text, line.level || "info", line.time || currentTime());
493
+ else addLines(line, "info", currentTime());
494
+ });
495
+ applyLook();
496
+ drawNewLines();
497
+
498
+ return endObject(box);
499
+
500
+ };
501
+
502
+ // *** STYLE PACKAGES:
503
+ // USAGE: LogView({ styleName: "dark" })
504
+ // USAGE: LogView({ styleName: "dark", style: { line: { fontSize: 12 } } }) // Change only some keys.
505
+ // USAGE: LogView({ style: { levels: { myLevel: { text: "purple", tag: "purple", color: "transparent" } } } })
506
+ // NOTE: A new package needs only the keys that differ from the default (light) style.
507
+ // USAGE: LogView.styles.myStyle = { box: { color: "#FFFDF5" } };
508
+ LogView.styles = {
509
+
510
+ // A white panel, dark text; a warning and an error also have a soft ground.
511
+ light: LogViewDefaults.style,
512
+
513
+ // For a dark window.
514
+ dark: {
515
+ box: { color: "#1C1C1B", borderColor: White(0.1) },
516
+ time: { textColor: White(0.48) },
517
+ levels: {
518
+ info: { text: White(0.86), tag: "#7DBBEB", color: "transparent" },
519
+ success: { text: "#7FE3B5", tag: "#7FE3B5", color: "transparent" },
520
+ warn: { text: "#F1C74A", tag: "#F1C74A", color: "rgba(241, 199, 74, 0.1)" },
521
+ error: { text: "#FF9F93", tag: "#FF9F93", color: "rgba(232, 121, 109, 0.14)" },
522
+ debug: { text: White(0.52), tag: White(0.52), color: "transparent" },
523
+ },
524
+ empty: { textColor: White(0.5) },
525
+ newLines: { color: "#DDE5E6", hoverColor: "#F2F6F6", textColor: "#1C1C1B", shadow: "0 2px 8px " + Black(0.5) },
526
+ scrollBar: { bar_color: "#8A8A88", bar_mouseOverColor: "#BFBFBD" },
527
+ focus: { ringColor: "rgba(111, 198, 205, 0.8)" },
528
+ },
529
+
530
+ };