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,1366 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Tabs - v26.10
6
+
7
+ UI COMPONENT TEMPLATE
8
+ - THE CONTENT OF THE TABS (new pages): Tabs is the bar; the pages under it are a PageControl (comp/page-control.js),
9
+ one page for each tab with the same key, and the onChange of the tabs opens it:
10
+ const pages = PageControl({ width: "100%", height: 400, transition: "fade", pages: ["home", "orders"] });
11
+ Tabs({ tabs: ["home", "orders"], value: "home", onChange: (self) => pages.open(self.value) });
12
+ PageControl gives the pages their motion (slide, fade), hides the inactive ones from the keyboard and the screen
13
+ readers and can be swiped. (panels: 1 stays for the pages made with it.)
14
+ - A tab bar: one tab is active, the others can be clicked. An animated indicator moves to the active tab.
15
+ - Variants: "underline" (a line under the active tab, default) and "pill" (a filled shape behind the active tab,
16
+ like a segmented control).
17
+ - Tabs can have an icon, a count ("Orders 12"), a badge dot (something new), and can be disabled or closable (x).
18
+ - Add button ("+") at the end of the bar (addButton: 1) -> onAdd.
19
+ - Many tabs: the bar scrolls sideways (the scroll bar is hidden), arrow buttons appear at the sides, the mouse wheel scrolls
20
+ and the active tab is scrolled into view.
21
+ - fullWidth: 1 -> the tabs share the bar width equally.
22
+ - vertical: 1 -> the tabs are stacked (Ex: settings sections). The indicator is on the left side.
23
+ - panels: 1 -> a content Box for every tab under the bar. Only the active one is shown. (New pages: a PageControl, above.)
24
+ Fill a panel with setPanelContent(key, fn) or startPanel(key) ... endPanel(), or get it with getPanel(key).
25
+ - Keyboard: ArrowLeft / ArrowRight (ArrowUp / ArrowDown when vertical), Home, End move between the tabs. Enter / Space
26
+ activates, Delete closes a closable tab. Tab key moves the focus out of the bar (roving tabindex).
27
+ - Accessibility: tablist / tab / tabpanel roles, aria-selected, aria-controls.
28
+ - onChange is NOT called when the component is created or when the value is set with silent: 1.
29
+ - Style packages: "light" (default; the old name "classic" works too), "modern", "dark". Select with styleName. (Tabs.styles)
30
+ - Everything is drawn with code (no image files needed).
31
+ - scale: multiplies every size (the style, width / height / barWidth / panelHeight, the spaces in the code).
32
+ Its default is basic.uiScale: on a page fitted with page.fit() (basic.uiScale = 1 / page.zoom) the tabs keep
33
+ their size on the screen. (Needs basic.js v26.11.01 for a scale other than 1.)
34
+
35
+ TAB: { key, text, iconFile, count, badge, disabled, closable, selectedColor, selectedTextColor, selectedIconFile, ariaLabel }
36
+ - text: "": a tab with only an icon. ariaLabel: its name for a screen reader.
37
+ - selectedColor: Indicator color when the tab is active. (pill: the shape, underline: the line)
38
+ - selectedTextColor: Text color when the tab is active.
39
+ - selectedIconFile: Icon when the tab is active. (Ex: a filled version of the icon)
40
+ - A string is also accepted: "Orders" -> { key: "Orders", text: "Orders" }
41
+
42
+ USAGE:
43
+ const tabs = Tabs({
44
+ tabs: ["All", { key: "open", text: "Open", count: 12 }, { key: "done", text: "Done", badge: 1 }],
45
+ value: "open",
46
+ onChange: (self) => println(self.value),
47
+ });
48
+ tabs.setValue("done"); // onChange is called
49
+ tabs.setValue("All", 1); // silent
50
+ tabs.setCount("open", 13);
51
+ tabs.addTab({ key: "new", text: "New tab", closable: 1 });
52
+ tabs.removeTab("new");
53
+
54
+ const pages = Tabs({ width: "100%", panels: 1, panelHeight: 300, tabs: ["Details", "History"] });
55
+ pages.startPanel("Details");
56
+ Label({ text: "Details content" });
57
+ pages.endPanel();
58
+ pages.setPanelContent("History", function () {
59
+ Label({ text: "History content" });
60
+ });
61
+
62
+ Tabs({ variant: "pill", tabs: ["Day", "Week", "Month"] });
63
+ Tabs({ vertical: 1, width: 200, tabs: ["General", "Security", "Billing"] });
64
+
65
+ Started Date: September 2026
66
+ Webpage: https://bug7a.github.io/js-components/
67
+
68
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
69
+ Licensed under the Apache License, Version 2.0
70
+ SPDX-License-Identifier: Apache-2.0
71
+
72
+ */
73
+
74
+ "use strict";
75
+
76
+ // Default values:
77
+ const TabsDefaults = {
78
+ key: "0", // Your name for this object: read it in a callback (self.key)
79
+ width: "auto",
80
+ height: "auto",
81
+ tabs: [], // [{ key, text, iconFile, count, badge, disabled, closable, selectedColor, selectedTextColor, selectedIconFile }] or ["A", "B"]
82
+ value: null, // Key of the active tab. null: the first enabled tab.
83
+ variant: "underline", // "underline", "pill" (Only at create time)
84
+ vertical: 0, // 1: Tabs are stacked. (Only at create time)
85
+ fullWidth: 0, // 1: Tabs share the bar width equally. (Only at create time)
86
+ closable: 0, // 1: Every tab has a close (x) button. (A tab can also set its own "closable".)
87
+ addButton: 0, // 1: "+" button at the end of the bar.
88
+ showArrows: "auto", // "auto": Arrow buttons when the tabs do not fit. 0: Never.
89
+ panels: 0, // 1: A content Box for every tab. (Only at create time)
90
+ panelHeight: "auto", // Height of the panels area. Ex: 300 or "auto" (grows with the content)
91
+ barWidth: 200, // vertical + panels: Width of the tab bar. (The panels take the rest.)
92
+ scale: null, // Multiplies every size. null: basic.uiScale (1, or 1 / page.zoom on a fitted page). (Only at create time)
93
+ enabled: 1,
94
+ ariaLabel: "Tabs",
95
+ onChange: function (self) { }, // self.value, self.previousValue, self.getActiveTab()
96
+ onClose: function (self, tab) { }, // Return false to keep the tab.
97
+ onAdd: function (self) { },
98
+ styleName: "light", // "light" ("classic": its old name), "modern", "dark", "minimal", "minimalDark" or a name added to Tabs.styles
99
+ style: { // Light style package (default)
100
+ bar: { // Underline variant
101
+ color: "transparent",
102
+ padding: [0, 0], // [x, y]
103
+ gap: 4,
104
+ round: 0,
105
+ dividerColor: Black(0.12), // Line under the tabs (vertical: line on the left)
106
+ dividerWidth: 1,
107
+ },
108
+ pillBar: { // Pill variant
109
+ color: Black(0.06),
110
+ padding: [4, 4],
111
+ gap: 2,
112
+ round: 8,
113
+ border: 0,
114
+ borderColor: "transparent",
115
+ },
116
+ tab: {
117
+ fontSize: 14,
118
+ textColor: Black(0.55),
119
+ padding: [14, 10], // [x, y]
120
+ round: 6,
121
+ gap: 8, // Between the icon, the text, the count...
122
+ minHeight: 40,
123
+ },
124
+ tabHover: {
125
+ color: Black(0.04),
126
+ textColor: Black(0.8),
127
+ },
128
+ tabActive: { // Underline variant
129
+ color: "transparent",
130
+ textColor: "#141414",
131
+ },
132
+ pillActive: { // Pill variant
133
+ textColor: "#141414",
134
+ },
135
+ tabDisabled: {
136
+ opacity: 0.4,
137
+ },
138
+ indicator: { // Underline variant
139
+ color: "#141414",
140
+ thickness: 2,
141
+ round: 2,
142
+ motion: 0.25, // Seconds. 0: No animation
143
+ },
144
+ pillIndicator: { // Pill variant
145
+ color: White(1),
146
+ round: 6,
147
+ shadow: "0 1px 3px rgba(0, 0, 0, 0.12)",
148
+ motion: 0.25,
149
+ },
150
+ icon: {
151
+ size: 16,
152
+ passiveOpacity: 0.7, // Icon of a passive tab. (Active or hover: 1)
153
+ },
154
+ count: {
155
+ fontSize: 11,
156
+ color: Black(0.08),
157
+ textColor: Black(0.6),
158
+ activeColor: "#141414",
159
+ activeTextColor: White(1),
160
+ round: 10,
161
+ padding: [6, 1],
162
+ },
163
+ badge: {
164
+ color: "#D64545",
165
+ size: 7,
166
+ },
167
+ close: {
168
+ color: Black(0.4),
169
+ hoverColor: "#D64545",
170
+ size: 14,
171
+ round: 3,
172
+ },
173
+ addButton: {
174
+ color: Black(0.5),
175
+ hoverColor: "#141414",
176
+ hoverBackground: Black(0.05),
177
+ size: 16,
178
+ padding: 6, // Around the icon. (The button: size + 2 * padding)
179
+ round: 6,
180
+ },
181
+ arrow: {
182
+ color: Black(0.5),
183
+ background: White(1),
184
+ size: 16,
185
+ padding: 4,
186
+ round: 4,
187
+ },
188
+ focus: {
189
+ outlineColor: Black(0), // Ring around the focused tab (keyboard). Hidden by default. Ex: Black(0.1)
190
+ ringWidth: 2,
191
+ },
192
+ panel: {
193
+ color: "transparent",
194
+ padding: [0, 16],
195
+ round: 0,
196
+ border: 0,
197
+ borderColor: "transparent",
198
+ },
199
+ disabled: {
200
+ opacity: 0.5,
201
+ },
202
+ }
203
+ };
204
+
205
+ const Tabs = function (params = {}) {
206
+
207
+ // Merge style package: params.style > Tabs.styles[styleName] > TabsDefaults.style (light)
208
+ basic.applyStylePackage(params, Tabs.styles, TabsDefaults);
209
+
210
+ // Merge params:
211
+ mergeIntoIfMissing(params, TabsDefaults);
212
+
213
+ // Scale: the sizes of the style and of the params are multiplied. (A page fitted with page.fit() sets basic.uiScale.)
214
+ Tabs.applyScale(params);
215
+
216
+ // Edit params, if needed:
217
+ params.color = "transparent";
218
+ const initialTabs = params.tabs;
219
+ const initialValue = params.value;
220
+ params.tabs = [];
221
+ params.value = null;
222
+
223
+ // BOX: Component container
224
+ let box = startObject(params);
225
+
226
+ // *** PRIVATE VARIABLES:
227
+ const _s = box.style;
228
+ const id = "tabs-" + (Tabs._counter++);
229
+ const isPill = (box.variant === "pill");
230
+ const isVertical = basic.isOn(box.vertical);
231
+ const hasPanels = basic.isOn(box.panels);
232
+ const isFullWidth = basic.isOn(box.fullWidth);
233
+ let items = []; // [{ tab, group, label, countLabel, badgeDot, closeButton, icon, panel, isHovered }]
234
+ let panelStack = []; // startPanel() / endPanel()
235
+ let isIndicatorMoving = 0; // the indicator moves with a motion (startIndicatorMotion: the first change of the tab)
236
+ let isFirstViewDone = 0; // the bar has been drawn once
237
+ let shownValue = null; // the tab the indicator shows
238
+ const scale = box.scale; // The px of the code below are multiplied by it, like the style.
239
+ const SCROLL_SPACE_X = 24 * scale; // Space next to the active tab when the strip scrolls to it.
240
+ const SCROLL_SPACE_Y = 8 * scale;
241
+ const ARROW_PASSIVE_OPACITY = 0.3; // An arrow that can not scroll more.
242
+ const SCROLL_STEP_RATIO = 0.6; // An arrow click scrolls 60% of the strip,
243
+ const MIN_SCROLL_STEP = 80 * scale; // but at least this.
244
+ const FADE_TIME = "0.15s"; // The color and opacity changes of hover and active.
245
+ const ADD_BUTTON_SPACE = 4 * scale; // Between the strip and the add button.
246
+
247
+ // *** PUBLIC VARIABLES:
248
+ box.previousValue = null;
249
+ // NOTE: Default values are also public variables. (box.tabs, box.value, box.enabled)
250
+
251
+ // *** PRIVATE FUNCTIONS:
252
+ // NOTE: An "item" holds the objects of one tab (group, label...), item.tab is its data.
253
+
254
+ // DRAWING: each function does one job, and a change calls only the one it needs:
255
+ // createTabs() -> all the tabs are made again from the data (setTabs)
256
+ // createTab() -> one tab: its view, events, panel and content (addTab)
257
+ // applyTabContent() -> the text, count, badge and close button of one tab (updateTab)
258
+ // paintTab() -> the look of one tab (active, hover, disabled) (the mouse on it)
259
+ // showActiveTab() -> after box.value or the list changed: the look of all the tabs, the indicator,
260
+ // the active panel and the Tab order (setValue, add, remove...)
261
+ // refreshLayout() -> the indicator and the arrows follow the sizes (resize, fonts)
262
+ // drawAll() -> the content of every tab + showActiveTab() (box.refresh)
263
+
264
+ const findItem = function (key) {
265
+ return items.find(function (item) { return item.tab.key === key; }) || null;
266
+ };
267
+
268
+ const getEnabledItems = function () {
269
+ return items.filter(function (item) { return !item.tab.disabled; });
270
+ };
271
+
272
+ const isClosable = function (tab) {
273
+ if (basic.isOn(tab.closable)) return true;
274
+ const closedByTab = (tab.closable === 0 || tab.closable === false);
275
+ return basic.isOn(box.closable) && !closedByTab;
276
+ };
277
+
278
+ // The key of a tab that can be active: the given one, or the first enabled tab.
279
+ const resolveActiveKey = function (key) {
280
+ const item = (key !== null && key !== undefined) ? findItem(key) : null;
281
+ if (item && !item.tab.disabled) return item.tab.key;
282
+ const firstItem = getEnabledItems()[0];
283
+ return (firstItem) ? firstItem.tab.key : null;
284
+ };
285
+
286
+ // PAINT: the look of one tab (active, hover, disabled)
287
+
288
+ const getTabColor = function (isActive, isHovered) {
289
+ if (isActive && isPill) return "transparent"; // WHY: The pill indicator is the background.
290
+ if (isActive) return _s.tabActive.color;
291
+ if (isHovered) return _s.tabHover.color;
292
+ return "transparent";
293
+ };
294
+
295
+ const getTabTextColor = function (tab, isActive, isHovered) {
296
+ const activeStyle = (isPill) ? _s.pillActive : _s.tabActive;
297
+ if (isActive) return tab.selectedTextColor || activeStyle.textColor;
298
+ if (isHovered) return _s.tabHover.textColor;
299
+ return _s.tab.textColor;
300
+ };
301
+
302
+ const paintIcon = function (item, isActive, isHovered) {
303
+ const tab = item.tab;
304
+ const iconFile = (isActive && tab.selectedIconFile) ? tab.selectedIconFile : tab.iconFile;
305
+ item.icon.opacity = (isActive || isHovered) ? 1 : _s.icon.passiveOpacity;
306
+ item.icon.visible = (iconFile) ? 1 : 0;
307
+ if (!iconFile || item.icon._loadedFile === iconFile) return;
308
+ item.icon.load(iconFile);
309
+ item.icon._loadedFile = iconFile;
310
+ };
311
+
312
+ const paintTab = function (item) {
313
+
314
+ const tab = item.tab;
315
+ const isActive = (tab.key === box.value);
316
+ const isHovered = item.isHovered && !isActive && !tab.disabled;
317
+
318
+ item.group.color = getTabColor(isActive, isHovered);
319
+ item.group.opacity = (tab.disabled) ? _s.tabDisabled.opacity : 1;
320
+ item.group.cursor = (tab.disabled) ? "default" : "pointer";
321
+ item.label.textColor = getTabTextColor(tab, isActive, isHovered);
322
+
323
+ item.group.aria = { selected: isActive, disabled: basic.isOn(tab.disabled) };
324
+
325
+ item.countLabel.color = (isActive) ? _s.count.activeColor : _s.count.color;
326
+ item.countLabel.textColor = (isActive) ? _s.count.activeTextColor : _s.count.textColor;
327
+
328
+ if (item.icon) paintIcon(item, isActive, isHovered);
329
+
330
+ };
331
+
332
+ const paintTabs = function () {
333
+ items.forEach(paintTab);
334
+ };
335
+
336
+ // LAYOUT: the indicator and the arrows follow the sizes of the tabs.
337
+
338
+ // Moves the indicator to the active tab.
339
+ const moveIndicator = function () {
340
+
341
+ const item = findItem(box.value);
342
+ const indicator = box.indicator;
343
+
344
+ if (!item || item.group.visible != 1) {
345
+ indicator.opacity = 0;
346
+ return;
347
+ }
348
+
349
+ const tabElement = item.group.elem;
350
+ const thickness = _s.indicator.thickness;
351
+
352
+ if (isPill) {
353
+ indicator.left = tabElement.offsetLeft;
354
+ indicator.top = tabElement.offsetTop;
355
+ indicator.width = tabElement.offsetWidth;
356
+ indicator.height = tabElement.offsetHeight;
357
+ } else if (isVertical) {
358
+ indicator.left = 0;
359
+ indicator.top = tabElement.offsetTop;
360
+ indicator.width = thickness;
361
+ indicator.height = tabElement.offsetHeight;
362
+ } else {
363
+ indicator.left = tabElement.offsetLeft;
364
+ indicator.top = box.stripInner.elem.offsetHeight - thickness;
365
+ indicator.width = tabElement.offsetWidth;
366
+ indicator.height = thickness;
367
+ }
368
+
369
+ const indicatorColor = (isPill) ? _s.pillIndicator.color : _s.indicator.color;
370
+ indicator.color = item.tab.selectedColor || indicatorColor;
371
+ indicator.opacity = 1;
372
+
373
+ };
374
+
375
+ // The indicator moves with a motion from one tab to another, after the first view.
376
+ // WHY not from its first place: the tab of the login pages grew with a motion when the
377
+ // page opened: the first size was measured before the fonts and the page were ready, and the motion that was
378
+ // on followed the right size. Its first place and the sizes before the first change are drawn at once.
379
+ const startIndicatorMotion = function () {
380
+ if (isIndicatorMoving || !isFirstViewDone) return;
381
+ isIndicatorMoving = 1;
382
+ box.indicator.setMotionNow(getIndicatorMotion());
383
+ };
384
+
385
+ const getIndicatorMotion = function () {
386
+ const seconds = (isPill) ? _s.pillIndicator.motion : _s.indicator.motion;
387
+ if (!seconds) return "none";
388
+ const moving = ["left", "top", "width", "height", "background-color"];
389
+ const motions = moving.map(function (name) { return name + " " + seconds + "s"; });
390
+ return motions.join(", ") + ", opacity " + FADE_TIME;
391
+ };
392
+
393
+ // The arrows are shown when the tabs do not fit; an arrow that can not scroll more is pale.
394
+ const paintArrows = function () {
395
+
396
+ if (isVertical || box.showArrows === 0 || box.showArrows === "0") return;
397
+
398
+ const strip = box.strip.elem;
399
+ const hasOverflow = (strip.scrollWidth > strip.clientWidth + 1);
400
+ box.leftArrow.visible = (hasOverflow) ? 1 : 0;
401
+ box.rightArrow.visible = (hasOverflow) ? 1 : 0;
402
+ if (!hasOverflow) return;
403
+
404
+ // WHY: + 1 / - 1: the scroll position can be a fraction of a pixel at the ends.
405
+ const canScrollLeft = (strip.scrollLeft > 1);
406
+ const canScrollRight = (strip.scrollLeft + strip.clientWidth < strip.scrollWidth - 1);
407
+ box.leftArrow.opacity = (canScrollLeft) ? 1 : ARROW_PASSIVE_OPACITY;
408
+ box.rightArrow.opacity = (canScrollRight) ? 1 : ARROW_PASSIVE_OPACITY;
409
+
410
+ };
411
+
412
+ // The indicator and the arrows after a size change (texts, fonts, window).
413
+ const refreshLayout = function () {
414
+ moveIndicator();
415
+ paintArrows();
416
+ };
417
+
418
+ const showActivePanel = function () {
419
+ if (!hasPanels) return;
420
+ items.forEach(function (item) {
421
+ item.panel.visible = (item.tab.key === box.value) ? 1 : 0;
422
+ });
423
+ };
424
+
425
+ // Roving tabindex: only one tab is in the Tab order (the active one, or the one the arrow keys moved to).
426
+ // WHY: The only place that sets the tabIndex of the tabs: with two places, two tabs could be in the Tab order.
427
+ const makeTabbable = function (tabbableItem) {
428
+ items.forEach(function (item) {
429
+ item.group.tabIndex = (item === tabbableItem) ? 0 : -1;
430
+ });
431
+ };
432
+
433
+ // THE ACTIVE TAB IS SHOWN: after box.value or the list of the tabs changed.
434
+ // WHY: One place, so a change can not forget its panel or its place in the Tab order.
435
+ const showActiveTab = function () {
436
+ paintTabs();
437
+ if (shownValue !== null && shownValue !== box.value) startIndicatorMotion();
438
+ shownValue = box.value;
439
+ refreshLayout();
440
+ showActivePanel();
441
+ makeTabbable(findItem(box.value));
442
+ };
443
+
444
+ // Everything that is shown, from the data of the tabs. (box.refresh)
445
+ const drawAll = function () {
446
+ items.forEach(applyTabContent);
447
+ showActiveTab();
448
+ };
449
+
450
+ // WHY: New tabs: the indicator jumps to its first place, it does not fly from the old one.
451
+ const resetIndicator = function () {
452
+ isIndicatorMoving = 0;
453
+ box.indicator.setMotionNow("none");
454
+ };
455
+
456
+ // SCROLL:
457
+
458
+ // Scrolls the strip only as much as needed to show the active tab, with a little space next to it.
459
+ const scrollToActiveTab = function () {
460
+
461
+ const item = findItem(box.value);
462
+ if (!item) return;
463
+
464
+ const strip = box.strip.elem;
465
+ const tabElement = item.group.elem;
466
+
467
+ if (isVertical) {
468
+ const tabTop = tabElement.offsetTop;
469
+ const tabBottom = tabTop + tabElement.offsetHeight;
470
+ const viewBottom = strip.scrollTop + strip.clientHeight;
471
+ if (tabTop < strip.scrollTop) strip.scrollTop = tabTop - SCROLL_SPACE_Y;
472
+ else if (tabBottom > viewBottom) strip.scrollTop = tabBottom - strip.clientHeight + SCROLL_SPACE_Y;
473
+ return;
474
+ }
475
+
476
+ const tabLeft = tabElement.offsetLeft;
477
+ const tabRight = tabLeft + tabElement.offsetWidth;
478
+ const viewRight = strip.scrollLeft + strip.clientWidth;
479
+ if (tabLeft < strip.scrollLeft) strip.scrollLeft = tabLeft - SCROLL_SPACE_X;
480
+ else if (tabRight > viewRight) strip.scrollLeft = tabRight - strip.clientWidth + SCROLL_SPACE_X;
481
+
482
+ };
483
+
484
+ const scrollStrip = function (direction) {
485
+ const strip = box.strip.elem;
486
+ const step = Math.max(MIN_SCROLL_STEP, Math.round(strip.clientWidth * SCROLL_STEP_RATIO));
487
+ const amount = step * direction;
488
+ if (strip.scrollBy) strip.scrollBy({ left: amount, behavior: "smooth" });
489
+ else strip.scrollLeft += amount;
490
+ };
491
+
492
+ // KEYBOARD AND ACTIONS:
493
+
494
+ const focusTab = function (item) {
495
+ if (!item) return;
496
+ makeTabbable(item);
497
+ item.group.elem.focus({ preventScroll: true });
498
+ item.group.elem.scrollIntoView({ block: "nearest", inline: "nearest" });
499
+ };
500
+
501
+ // The enabled tab that is step places away. (step: 1 next, -1 previous)
502
+ const getNeighborItem = function (item, step) {
503
+ const enabledItems = getEnabledItems();
504
+ const count = enabledItems.length;
505
+ const index = enabledItems.indexOf(item);
506
+ return enabledItems[(index + step + count) % count]; // WHY: % wraps around at both ends.
507
+ };
508
+
509
+ // Delete key: the focus goes to the tab that takes the place of the closed one.
510
+ const closeTabByKeyboard = function (item) {
511
+ const index = getEnabledItems().indexOf(item);
512
+ closeTab(item);
513
+ const remainingItems = getEnabledItems();
514
+ if (!remainingItems.length) return;
515
+ focusTab(remainingItems[Math.min(index, remainingItems.length - 1)]);
516
+ };
517
+
518
+ const onTabKeyDown = function (item, event) {
519
+
520
+ if (box.enabled != 1) return;
521
+ const key = event.key;
522
+ const enabledItems = getEnabledItems();
523
+ const prevKey = (isVertical) ? "ArrowUp" : "ArrowLeft";
524
+ const nextKey = (isVertical) ? "ArrowDown" : "ArrowRight";
525
+
526
+ if (key === prevKey) focusTab(getNeighborItem(item, -1));
527
+ else if (key === nextKey) focusTab(getNeighborItem(item, 1));
528
+ else if (key === "Home") focusTab(enabledItems[0]);
529
+ else if (key === "End") focusTab(enabledItems[enabledItems.length - 1]);
530
+ else if (key === "Enter" || key === " ") box.setValue(item.tab.key);
531
+ else if (key === "Delete" && isClosable(item.tab)) closeTabByKeyboard(item);
532
+ else return; // Another key: the browser keeps it.
533
+
534
+ event.preventDefault();
535
+
536
+ };
537
+
538
+ // Close (x): onClose can return false to keep the tab.
539
+ const closeTab = function (item) {
540
+ if (box.onClose(box, item.tab) === false) return;
541
+ box.removeTab(item.tab.key);
542
+ };
543
+
544
+ // The add button (+) does not add a tab: it asks the page with onAdd.
545
+ const requestAddTab = function () {
546
+ if (box.enabled == 1) box.onAdd(box);
547
+ };
548
+
549
+ // A small button with an SVG icon: the arrows and the add button. The icon takes the textColor.
550
+ const createIconButton = function (props) {
551
+ return Label({
552
+ text: props.svg,
553
+ width: props.size,
554
+ height: props.size,
555
+ round: props.round,
556
+ textColor: props.color,
557
+ clickable: 1,
558
+ cursor: "pointer",
559
+ shrink: 0,
560
+ lineHeight: "0",
561
+ css: { display: "flex", alignItems: "center", justifyContent: "center" },
562
+ aria: { label: props.ariaLabel },
563
+ });
564
+ };
565
+
566
+ // ONE TAB: createTab() = createTabView() + bindTabEvents() + createTabPanel() + applyTabContent()
567
+
568
+ // The objects of one tab in the strip. Returns the item.
569
+ const createTabView = function (tab) {
570
+
571
+ const item = { tab: tab, icon: null, panel: null, isHovered: 0 };
572
+
573
+ // WHY: createIn() puts the container back after it (also on an error). setDefaultContainerBox() did not:
574
+ // after addTab() / setTabs() of the page, its next objects went into the strip of the tabs.
575
+ createIn(box.stripInner, function () {
576
+
577
+ // GROUP: Tab
578
+ item.group = HGroup({
579
+ width: (isVertical || isFullWidth) ? "100%" : "auto",
580
+ height: "auto",
581
+ align: (isVertical) ? "left center" : "center center",
582
+ gap: _s.tab.gap,
583
+ padding: _s.tab.padding,
584
+ round: _s.tab.round,
585
+ color: "transparent",
586
+ clickable: 1,
587
+ shrink: 0,
588
+ css: {
589
+ minHeight: _s.tab.minHeight + "px",
590
+ transition: "background-color " + FADE_TIME,
591
+ outline: "none",
592
+ boxSizing: "border-box",
593
+ whiteSpace: "nowrap",
594
+ },
595
+ });
596
+ item.group.elem.id = id + "-tab-" + Tabs.toId(tab.key);
597
+ item.group.role = "tab";
598
+ if (hasPanels) item.group.aria = { controls: id + "-panel-" + Tabs.toId(tab.key) };
599
+ if (isFullWidth && !isVertical) item.group.css.flex = "1 1 0";
600
+
601
+ // ICON:
602
+ if (tab.iconFile || tab.selectedIconFile) {
603
+ item.icon = Icon({
604
+ width: _s.icon.size,
605
+ height: _s.icon.size,
606
+ alt: "",
607
+ shrink: 0,
608
+ css: { transition: "opacity " + FADE_TIME },
609
+ });
610
+ item.icon.aria = { hidden: true };
611
+ // WHY: The selected icon is loaded before the first click, so it does not flash in.
612
+ if (tab.selectedIconFile) (new Image()).src = tab.selectedIconFile;
613
+ }
614
+
615
+ // LABEL: Text
616
+ item.label = Label({
617
+ fontSize: _s.tab.fontSize,
618
+ textColor: _s.tab.textColor,
619
+ ellipsis: 1,
620
+ css: { transition: "color " + FADE_TIME, minWidth: "0" },
621
+ });
622
+ if (isVertical) item.label.css.flex = "1 1 auto";
623
+
624
+ // LABEL: Count
625
+ item.countLabel = Label({
626
+ fontSize: _s.count.fontSize,
627
+ textColor: _s.count.textColor,
628
+ color: _s.count.color,
629
+ round: _s.count.round,
630
+ padding: _s.count.padding,
631
+ lineHeight: "1.4",
632
+ shrink: 0,
633
+ css: { transition: "background-color " + FADE_TIME + ", color " + FADE_TIME },
634
+ visible: 0,
635
+ });
636
+
637
+ // BOX: Badge dot
638
+ item.badgeDot = Box({
639
+ width: _s.badge.size,
640
+ height: _s.badge.size,
641
+ color: _s.badge.color,
642
+ round: _s.badge.size,
643
+ shrink: 0,
644
+ aria: { label: "New" },
645
+ visible: 0,
646
+ });
647
+
648
+ // LABEL: Close (x)
649
+ item.closeButton = Label({
650
+ text: Tabs.getCloseSvg("currentColor", _s.close.size),
651
+ width: _s.close.size,
652
+ height: _s.close.size,
653
+ round: _s.close.round,
654
+ textColor: _s.close.color,
655
+ clickable: 1,
656
+ cursor: "pointer",
657
+ shrink: 0,
658
+ lineHeight: "0",
659
+ visible: 0,
660
+ });
661
+ item.closeButton.role = "button";
662
+ item.closeButton.tabIndex = -1; // WHY: Delete closes the focused tab; the x is for the mouse.
663
+ if (isVertical) item.closeButton.css.marginLeft = "auto";
664
+
665
+ endGroup();
666
+
667
+ });
668
+
669
+ // NOTE: The indicator stays under the tabs: it was created first, so the tabs are painted over it.
670
+ return item;
671
+
672
+ };
673
+
674
+ const bindTabEvents = function (item) {
675
+
676
+ const tab = item.tab;
677
+ const group = item.group;
678
+ const focusRing = "inset 0 0 0 " + _s.focus.ringWidth + "px " + _s.focus.outlineColor;
679
+
680
+ group.on("click", function () {
681
+ if (box.enabled != 1 || tab.disabled) return;
682
+ box.setValue(tab.key);
683
+ focusTab(item);
684
+ });
685
+ group.onHoverChange(function (self, isOver) {
686
+ item.isHovered = isOver;
687
+ paintTab(item);
688
+ });
689
+ group.on("keydown", function (self, event) { onTabKeyDown(item, event); });
690
+ // WHY :focus-visible: the ring is for the keyboard. A click focuses the tab after its mousedown, so clearing the
691
+ // ring at mousedown did not stop it (a click on a tab showed the ring).
692
+ group.on("focus", function () { group.boxShadow = group.elem.matches(":focus-visible") ? focusRing : "none"; });
693
+ group.on("blur", function () { group.boxShadow = "none"; });
694
+
695
+ // Middle mouse button closes a closable tab (like a browser).
696
+ group.on("auxclick", function (self, event) {
697
+ if (event.button !== 1 || !isClosable(tab) || box.enabled != 1) return;
698
+ event.preventDefault();
699
+ closeTab(item);
700
+ });
701
+
702
+ item.closeButton.onHoverChange(function (self, isOver) {
703
+ item.closeButton.textColor = (isOver) ? _s.close.hoverColor : _s.close.color;
704
+ });
705
+ item.closeButton.on("click", function (self, event) {
706
+ event.stopPropagation();
707
+ if (box.enabled != 1) return;
708
+ closeTab(item);
709
+ });
710
+
711
+ };
712
+
713
+ // The content Box of one tab. (panels: 1)
714
+ const createTabPanel = function (item) {
715
+
716
+ if (!hasPanels) return;
717
+
718
+ createIn(box.panelsBox, function () {
719
+ item.panel = Box({
720
+ width: "100%",
721
+ height: (box.panelHeight === "auto") ? "auto" : "100%",
722
+ color: _s.panel.color,
723
+ round: _s.panel.round,
724
+ border: _s.panel.border,
725
+ borderColor: _s.panel.borderColor,
726
+ visible: 0,
727
+ position: "relative",
728
+ });
729
+ });
730
+
731
+ const panel = item.panel;
732
+ panel.elem.id = id + "-panel-" + Tabs.toId(item.tab.key);
733
+ panel.role = "tabpanel";
734
+ panel.aria = { labelledby: item.group.elem.id };
735
+ panel.css = {
736
+ boxSizing: "border-box",
737
+ padding: _s.panel.padding[1] + "px " + _s.panel.padding[0] + "px",
738
+ };
739
+ // WHY: A fixed height: the panels lie on top of each other and each one scrolls its own content.
740
+ if (box.panelHeight !== "auto") {
741
+ panel.css = { position: "absolute", left: "0px", top: "0px" };
742
+ panel.scrollX = 1;
743
+ panel.scrollY = 1;
744
+ }
745
+
746
+ };
747
+
748
+ // Applies text, count, badge, close and disabled of the tab data to the objects.
749
+ const applyTabContent = function (item) {
750
+ const tab = item.tab;
751
+ item.label.plainText = tab.text;
752
+ // WHY: An empty label still takes a gap, so the icon of an icon only tab would not be in the middle.
753
+ item.label.visible = (tab.text !== "") ? 1 : 0;
754
+ item.group.aria = { label: tab.ariaLabel || tab.text || tab.key };
755
+ const hasCount = (tab.count !== undefined && tab.count !== null && tab.count !== "");
756
+ item.countLabel.plainText = (hasCount) ? tab.count : "";
757
+ item.countLabel.visible = (hasCount) ? 1 : 0;
758
+ item.badgeDot.visible = basic.isOn(tab.badge) ? 1 : 0;
759
+ item.closeButton.visible = (isClosable(tab)) ? 1 : 0;
760
+ item.closeButton.aria = { label: "Close " + tab.text };
761
+ // NOTE: The look (and the icon) is painted by showActiveTab(), which runs after every change of the content.
762
+ };
763
+
764
+ const createTab = function (tab) {
765
+ const item = createTabView(tab);
766
+ bindTabEvents(item);
767
+ createTabPanel(item);
768
+ applyTabContent(item);
769
+ return item;
770
+ };
771
+
772
+ const removeTabObjects = function (item) {
773
+ item.group.remove();
774
+ if (item.panel) item.panel.remove();
775
+ };
776
+
777
+ // All the tabs are made again. (The objects of the old ones are removed.)
778
+ const createTabs = function (tabs) {
779
+ items.forEach(removeTabObjects);
780
+ items = Tabs.normalizeTabs(tabs).map(createTab);
781
+ box.tabs = box.getTabs();
782
+ };
783
+
784
+ // The tab to activate when the active one is removed: the next enabled tab, or the previous one.
785
+ // index: where the removed tab was. (items does not have it any more)
786
+ const findReplacementItem = function (index) {
787
+ const isEnabled = function (item) { return !item.tab.disabled; };
788
+ const nextEnabledItem = items.slice(index).find(isEnabled);
789
+ const previousEnabledItem = items.slice(0, index).reverse().find(isEnabled);
790
+ return nextEnabledItem || previousEnabledItem || null;
791
+ };
792
+
793
+ // *** PUBLIC FUNCTIONS:
794
+
795
+ // silent: 1 -> onChange is not called.
796
+ box.setValue = function (value, silent = 0) {
797
+ const item = findItem(value);
798
+ if (!item || item.tab.disabled) return 0;
799
+ if (box.value === value) return 1;
800
+ box.previousValue = box.value;
801
+ box.value = value;
802
+ showActiveTab();
803
+ scrollToActiveTab();
804
+ if (!silent) box.onChange(box);
805
+ return 1;
806
+ };
807
+ // USAGE: tabs.setValue("open") // Returns 1 when the tab exists and is enabled.
808
+
809
+ box.getValue = function () {
810
+ return box.value;
811
+ };
812
+
813
+ box.getActiveTab = function () {
814
+ const item = findItem(box.value);
815
+ return (item) ? item.tab : null;
816
+ };
817
+ // USAGE: tabs.getActiveTab() // { key, text, count, ... }
818
+
819
+ box.getTab = function (key) {
820
+ const item = findItem(key);
821
+ return (item) ? item.tab : null;
822
+ };
823
+
824
+ box.getTabs = function () {
825
+ return items.map(function (item) { return item.tab; });
826
+ };
827
+
828
+ box.getIndex = function (key = box.value) {
829
+ return items.findIndex(function (item) { return item.tab.key === key; });
830
+ };
831
+ // USAGE: tabs.getIndex() // Index of the active tab
832
+
833
+ // Replaces all tabs. The active tab is kept when it still exists.
834
+ box.setTabs = function (tabs, silent = 1) {
835
+
836
+ const oldValue = box.value;
837
+ createTabs(tabs);
838
+ box.value = resolveActiveKey(oldValue);
839
+ resetIndicator();
840
+ showActiveTab();
841
+
842
+ if (silent || box.value === oldValue) return;
843
+ box.previousValue = oldValue;
844
+ box.onChange(box);
845
+
846
+ };
847
+ // USAGE: tabs.setTabs(["A", "B", { key: "c", text: "C", count: 3 }])
848
+
849
+ // index: Position of the new tab. (Default: the end)
850
+ box.addTab = function (tab, index = -1, silent = 1) {
851
+
852
+ tab = Tabs.normalizeTabs([tab])[0];
853
+ if (findItem(tab.key)) {
854
+ console.warn("Tabs: A tab with this key exists: " + tab.key);
855
+ return null;
856
+ }
857
+
858
+ const item = createTab(tab);
859
+ const isInside = (index >= 0 && index < items.length);
860
+ if (isInside) {
861
+ const itemAfter = items[index];
862
+ box.stripInner.elem.insertBefore(item.group.elem, itemAfter.group.elem);
863
+ if (item.panel) box.panelsBox.elem.insertBefore(item.panel.elem, itemAfter.panel.elem);
864
+ items.splice(index, 0, item);
865
+ } else {
866
+ items.push(item);
867
+ }
868
+
869
+ box.tabs = box.getTabs();
870
+ if (box.value === null) box.value = resolveActiveKey(null);
871
+ showActiveTab();
872
+
873
+ if (!silent && box.value === tab.key) box.onChange(box);
874
+ return tab;
875
+
876
+ };
877
+ // USAGE: tabs.addTab({ key: "new", text: "New", closable: 1 }) // Returns the tab data.
878
+
879
+ // When the active tab is removed, the next tab (or the previous one) becomes active.
880
+ box.removeTab = function (key, silent = 0) {
881
+
882
+ const index = box.getIndex(key);
883
+ if (index < 0) return 0;
884
+
885
+ const wasActive = (box.value === key);
886
+ removeTabObjects(items[index]);
887
+ items.splice(index, 1);
888
+ box.tabs = box.getTabs();
889
+
890
+ if (wasActive) {
891
+ const replacementItem = findReplacementItem(index);
892
+ box.previousValue = key;
893
+ box.value = (replacementItem) ? replacementItem.tab.key : null;
894
+ }
895
+ showActiveTab();
896
+
897
+ if (wasActive && !silent) box.onChange(box);
898
+ return 1;
899
+
900
+ };
901
+ // USAGE: tabs.removeTab("new")
902
+
903
+ // Changes some fields of a tab. USAGE: tabs.updateTab("open", { text: "Open orders", count: 5 })
904
+ box.updateTab = function (key, changes) {
905
+
906
+ const item = findItem(key);
907
+ if (!item) return 0;
908
+
909
+ const fields = changes || {};
910
+ Object.assign(item.tab, fields);
911
+ item.tab.disabled = basic.isOn(item.tab.disabled) ? 1 : 0;
912
+
913
+ const changesIcon = (fields.iconFile !== undefined || fields.selectedIconFile !== undefined);
914
+ if (changesIcon && !item.icon) {
915
+ console.warn("Tabs: An icon can only be changed on a tab that was created with an iconFile.");
916
+ }
917
+
918
+ applyTabContent(item);
919
+ // NOTE: A disabled tab can not stay active. (No onChange: the page disabled it.)
920
+ if (item.tab.disabled && box.value === key) box.value = resolveActiveKey(null);
921
+ showActiveTab();
922
+ return 1;
923
+
924
+ };
925
+
926
+ box.setCount = function (key, count) {
927
+ return box.updateTab(key, { count: count });
928
+ };
929
+ // USAGE: tabs.setCount("open", 12) // tabs.setCount("open", "") removes the count
930
+
931
+ box.setBadge = function (key, badge = 1) {
932
+ return box.updateTab(key, { badge: basic.isOn(badge) ? 1 : 0 });
933
+ };
934
+ // USAGE: tabs.setBadge("done") / tabs.setBadge("done", 0)
935
+
936
+ box.setTabEnabled = function (key, enabled) {
937
+ return box.updateTab(key, { disabled: basic.isOn(enabled) ? 0 : 1 });
938
+ };
939
+
940
+ box.setEnabled = function (enabled) {
941
+ box.enabled = basic.isOn(enabled) ? 1 : 0;
942
+ box.opacity = (box.enabled == 1) ? 1 : _s.disabled.opacity;
943
+ box.css.pointerEvents = (box.enabled == 1) ? "" : "none";
944
+ };
945
+ // USAGE: get: tabs.enabled, set: tabs.setEnabled(0)
946
+
947
+ box.getPanel = function (key = box.value) {
948
+ const item = findItem(key);
949
+ return (item) ? item.panel : null;
950
+ };
951
+ // USAGE: const panel = tabs.getPanel("Details") // A Box. (panels: 1)
952
+
953
+ // Objects created between startPanel(key) and endPanel() go into the panel of that tab.
954
+ // NOTE: The old content of the panel is removed. (The same as setPanelContent)
955
+ box.startPanel = function (key) {
956
+ const panel = box.getPanel(key);
957
+ if (!panel) {
958
+ console.error("Tabs: startPanel(): No panel for the key: " + key + ". (panels: 1 is needed.)");
959
+ return null;
960
+ }
961
+ panelStack.push(getDefaultContainerBox());
962
+ if (panel.wrapper) panel.wrapper.remove();
963
+ setDefaultContainerBox(panel);
964
+ panel.wrapper = VGroup({
965
+ width: "100%",
966
+ height: "auto",
967
+ align: "left top",
968
+ gap: 0,
969
+ position: "relative",
970
+ css: { alignItems: "stretch" },
971
+ });
972
+ return panel.wrapper;
973
+ };
974
+ // USAGE: tabs.startPanel("Details"); Label({ text: "..." }); tabs.endPanel();
975
+
976
+ box.endPanel = function () {
977
+ endGroup();
978
+ const previous = panelStack.pop();
979
+ if (previous) setDefaultContainerBox(previous);
980
+ };
981
+
982
+ // Replaces the content of a panel with the objects created in createContent(wrapper).
983
+ // WHY: finally: endPanel() runs also on an error, so the next objects of the page do not go into the panel.
984
+ box.setPanelContent = function (key, createContent) {
985
+ const wrapper = box.startPanel(key);
986
+ if (!wrapper) return null;
987
+ try {
988
+ createContent(wrapper);
989
+ } finally {
990
+ box.endPanel();
991
+ }
992
+ return wrapper;
993
+ };
994
+ // USAGE: tabs.setPanelContent("Details", function () { Label({ text: "..." }); });
995
+
996
+ // Draws everything again from the data. (Ex: after a tab object or the width was changed by code)
997
+ box.refresh = function () {
998
+ drawAll();
999
+ };
1000
+ // USAGE: tabs.getTab("open").text = "Open orders"; tabs.refresh();
1001
+
1002
+ box.focus = function () {
1003
+ const item = findItem(box.value) || getEnabledItems()[0];
1004
+ if (item) focusTab(item);
1005
+ };
1006
+
1007
+
1008
+ // *** OBJECT VIEW:
1009
+ Tabs.injectCss();
1010
+
1011
+ const barStyle = (isPill) ? _s.pillBar : _s.bar;
1012
+ const dividerLine = _s.bar.dividerWidth + "px solid " + _s.bar.dividerColor;
1013
+
1014
+ // GROUP: Root (vertical: bar | panels, horizontal: bar / panels)
1015
+ const rootProps = {
1016
+ width: "100%",
1017
+ height: "auto",
1018
+ align: "left top",
1019
+ gap: 0,
1020
+ position: "relative",
1021
+ css: { alignItems: "stretch" },
1022
+ };
1023
+ box.contentBox = (isVertical) ? HGroup(rootProps) : VGroup(rootProps);
1024
+
1025
+ // GROUP: Bar row (arrow, strip, arrow, add)
1026
+ if (isVertical) {
1027
+ box.barRow = VGroup({
1028
+ width: (hasPanels) ? box.barWidth : "100%",
1029
+ height: "auto",
1030
+ align: "left top",
1031
+ gap: 0,
1032
+ css: { alignItems: "stretch", minWidth: "0" },
1033
+ });
1034
+ } else {
1035
+ box.barRow = HGroup({
1036
+ width: "100%",
1037
+ height: "auto",
1038
+ align: "left center",
1039
+ gap: 0,
1040
+ css: { minWidth: "0" },
1041
+ });
1042
+ }
1043
+
1044
+ // LABEL: Left arrow
1045
+ box.leftArrow = createIconButton({
1046
+ svg: Tabs.getArrowSvg("left", "currentColor", _s.arrow.size),
1047
+ size: _s.arrow.size + _s.arrow.padding * 2,
1048
+ round: _s.arrow.round,
1049
+ color: _s.arrow.color,
1050
+ ariaLabel: "Scroll left",
1051
+ });
1052
+
1053
+ // BOX: Strip (scrolls)
1054
+ box.strip = startBox({
1055
+ width: (isVertical) ? "100%" : "auto",
1056
+ height: "auto",
1057
+ color: barStyle.color,
1058
+ round: barStyle.round,
1059
+ border: (isPill) ? barStyle.border : 0,
1060
+ borderColor: (isPill) ? barStyle.borderColor : "transparent",
1061
+ css: { boxSizing: "border-box" },
1062
+ });
1063
+ box.strip.elem.classList.add("tabs-strip");
1064
+ if (isVertical) {
1065
+ box.strip.scrollY = 1;
1066
+ if (!isPill) box.strip.css.borderLeft = dividerLine;
1067
+ } else {
1068
+ box.strip.css = { flex: "1 1 0", minWidth: "0", overflowY: "hidden" };
1069
+ box.strip.scrollX = 1;
1070
+ if (!isPill) box.strip.css.borderBottom = dividerLine;
1071
+ }
1072
+
1073
+ // GROUP: Strip inner (indicator + tabs)
1074
+ const stripInnerProps = {
1075
+ height: "auto",
1076
+ gap: barStyle.gap,
1077
+ padding: barStyle.padding,
1078
+ position: "relative",
1079
+ };
1080
+ if (isVertical) {
1081
+ box.stripInner = VGroup({
1082
+ ...stripInnerProps,
1083
+ width: "100%",
1084
+ align: "left top",
1085
+ css: { boxSizing: "border-box", alignItems: "stretch" },
1086
+ });
1087
+ box.stripInner.aria = { orientation: "vertical" };
1088
+ } else {
1089
+ // WHY: With width: auto the inner group stays as wide as the strip and the extra tabs are clipped.
1090
+ // max-content grows with the tabs, so the strip can scroll.
1091
+ box.stripInner = HGroup({
1092
+ ...stripInnerProps,
1093
+ width: (isFullWidth) ? "100%" : "auto",
1094
+ align: "left center",
1095
+ css: { boxSizing: "border-box", width: (isFullWidth) ? "100%" : "max-content" },
1096
+ });
1097
+ }
1098
+ box.stripInner.role = "tablist";
1099
+ box.stripInner.aria = { label: box.ariaLabel };
1100
+
1101
+ // BOX: Indicator (under the active tab)
1102
+ box.indicator = Box({
1103
+ left: 0,
1104
+ top: 0,
1105
+ width: 0,
1106
+ height: (isPill) ? 0 : _s.indicator.thickness,
1107
+ color: (isPill) ? _s.pillIndicator.color : _s.indicator.color,
1108
+ round: (isPill) ? _s.pillIndicator.round : _s.indicator.round,
1109
+ opacity: 0,
1110
+ css: { position: "absolute", pointerEvents: "none" },
1111
+ });
1112
+ if (isPill) box.indicator.boxShadow = _s.pillIndicator.shadow;
1113
+
1114
+ endGroup();
1115
+
1116
+ endBox();
1117
+
1118
+ // LABEL: Right arrow
1119
+ box.rightArrow = createIconButton({
1120
+ svg: Tabs.getArrowSvg("right", "currentColor", _s.arrow.size),
1121
+ size: _s.arrow.size + _s.arrow.padding * 2,
1122
+ round: _s.arrow.round,
1123
+ color: _s.arrow.color,
1124
+ ariaLabel: "Scroll right",
1125
+ });
1126
+
1127
+ // LABEL: Add (+)
1128
+ box.addTabButton = createIconButton({
1129
+ svg: Tabs.getPlusSvg("currentColor", _s.addButton.size),
1130
+ size: _s.addButton.size + _s.addButton.padding * 2,
1131
+ round: _s.addButton.round,
1132
+ color: _s.addButton.color,
1133
+ ariaLabel: "Add",
1134
+ });
1135
+ box.addTabButton.css = {
1136
+ marginLeft: (isVertical) ? "0px" : ADD_BUTTON_SPACE + "px",
1137
+ transition: "background-color " + FADE_TIME,
1138
+ };
1139
+ box.addTabButton.role = "button";
1140
+ box.addTabButton.tabIndex = 0;
1141
+
1142
+ endGroup();
1143
+
1144
+ // BOX: Panels area
1145
+ if (hasPanels) {
1146
+ box.panelsBox = Box({
1147
+ width: (isVertical) ? "auto" : "100%",
1148
+ height: (box.panelHeight === "auto") ? "auto" : box.panelHeight,
1149
+ color: "transparent",
1150
+ position: "relative",
1151
+ });
1152
+ if (isVertical) box.panelsBox.css = { flex: "1 1 0", minWidth: "0" };
1153
+ }
1154
+
1155
+ endGroup();
1156
+
1157
+ // WHY: visible: 0 at create time would be undone by display = "flex" above. Hide them after the display type is set.
1158
+ box.leftArrow.visible = 0;
1159
+ box.rightArrow.visible = 0;
1160
+ box.addTabButton.visible = (box.addButton == 1) ? 1 : 0;
1161
+
1162
+ // *** OBJECT INIT CODE:
1163
+
1164
+ box.leftArrow.on("click", function () { scrollStrip(-1); });
1165
+ box.rightArrow.on("click", function () { scrollStrip(1); });
1166
+ box.strip.on("scroll", paintArrows);
1167
+ // Mouse wheel: vertical wheel scrolls the strip sideways.
1168
+ box.strip.on("wheel", function (self, event) {
1169
+ if (isVertical) return;
1170
+ const strip = box.strip.elem;
1171
+ if (strip.scrollWidth <= strip.clientWidth + 1) return;
1172
+ if (Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return;
1173
+ event.preventDefault();
1174
+ strip.scrollLeft += event.deltaY;
1175
+ });
1176
+
1177
+ box.addTabButton.onHoverChange(function (self, isOver) {
1178
+ box.addTabButton.color = (isOver) ? _s.addButton.hoverBackground : "transparent";
1179
+ box.addTabButton.textColor = (isOver) ? _s.addButton.hoverColor : _s.addButton.color;
1180
+ });
1181
+ box.addTabButton.on("click", requestAddTab);
1182
+ box.addTabButton.on("keydown", function (self, event) {
1183
+ if (event.key !== "Enter" && event.key !== " ") return;
1184
+ event.preventDefault();
1185
+ requestAddTab();
1186
+ });
1187
+
1188
+ // The indicator follows size changes (texts, fonts, window).
1189
+ box.stripInner.onResize(refreshLayout);
1190
+ box.onResize(refreshLayout);
1191
+ if (document.fonts && document.fonts.ready) {
1192
+ document.fonts.ready.then(function () {
1193
+ if (!box.isRemoved) refreshLayout();
1194
+ });
1195
+ }
1196
+
1197
+ // NOTE: The first drawing: the tabs (with their content), then the active tab.
1198
+ createTabs(initialTabs);
1199
+ box.value = resolveActiveKey(initialValue);
1200
+ box.setEnabled(box.enabled);
1201
+ showActiveTab();
1202
+ requestAnimationFrame(function () {
1203
+ isFirstViewDone = 1; // (a change of the tab before it is not a move: startIndicatorMotion)
1204
+ });
1205
+
1206
+ return endObject(box);
1207
+
1208
+ };
1209
+
1210
+ // *** STATIC VARIABLES AND FUNCTIONS:
1211
+
1212
+ Tabs._counter = 1;
1213
+
1214
+ // scale: every size of the style and of the size params is multiplied (params is changed). Scale 1 changes nothing.
1215
+ // WHY: The default (null) is read when a tab bar is made, not when this file is loaded: the page sets
1216
+ // basic.uiScale later (page.fit(600, 800); basic.uiScale = 1 / page.zoom).
1217
+ Tabs.applyScale = function (params) {
1218
+ const givenScale = Number(params.scale);
1219
+ params.scale = (givenScale > 0) ? givenScale : (basic.uiScale || 1);
1220
+ if (params.scale === 1) return;
1221
+ params.style = basic.scaleStyle(params.style, params.scale);
1222
+ const pillIndicatorStyle = params.style.pillIndicator;
1223
+ pillIndicatorStyle.shadow = basic.scaleCssText(pillIndicatorStyle.shadow, params.scale);
1224
+ ["width", "height", "barWidth", "panelHeight"].forEach(function (name) {
1225
+ params[name] = basic.scaleSize(params[name], params.scale);
1226
+ });
1227
+ };
1228
+
1229
+ // "Orders" -> { key: "Orders", text: "Orders", iconFile: "", count: null, badge: 0, disabled: 0, closable: undefined }
1230
+ Tabs.normalizeTabs = function (tabs) {
1231
+ return (tabs || []).map(function (tab) {
1232
+ if (tab === null || typeof tab !== "object") {
1233
+ return { key: tab, text: String(tab), iconFile: "", count: null, badge: 0, disabled: 0 };
1234
+ }
1235
+ const result = { ...tab };
1236
+ result.key = (tab.key !== undefined) ? tab.key : tab.text;
1237
+ result.text = String(tab.text ?? tab.key);
1238
+ result.iconFile = tab.iconFile || "";
1239
+ result.count = (tab.count !== undefined) ? tab.count : null;
1240
+ result.badge = basic.isOn(tab.badge) ? 1 : 0;
1241
+ result.disabled = basic.isOn(tab.disabled) ? 1 : 0;
1242
+ return result;
1243
+ });
1244
+ };
1245
+
1246
+ // Element id from a key. "Open orders" -> "Open-orders"
1247
+ Tabs.toId = function (key) {
1248
+ return String(key).replace(/[^\w-]/g, "-");
1249
+ };
1250
+
1251
+ // WHY: Label.text uses innerHTML. Texts must not be read as HTML.
1252
+ Tabs.escapeHtml = basic.escapeHtml; // (the name is kept: other code may use it)
1253
+
1254
+ // SVG icons. color: "currentColor" -> the icon takes the textColor of its Label (a hover changes only textColor).
1255
+ Tabs.getLineSvg = function (path, color, size, strokeWidth) {
1256
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24"' +
1257
+ ' fill="none" stroke="' + color + '" stroke-width="' + strokeWidth + '" stroke-linecap="round" stroke-linejoin="round">' +
1258
+ '<path d="' + path + '"/></svg>';
1259
+ };
1260
+
1261
+ Tabs.getCloseSvg = function (color, size) {
1262
+ return Tabs.getLineSvg("M6 6l12 12M18 6 6 18", color, size, 2.4);
1263
+ };
1264
+
1265
+ Tabs.getPlusSvg = function (color, size) {
1266
+ return Tabs.getLineSvg("M12 5v14M5 12h14", color, size, 2.2);
1267
+ };
1268
+
1269
+ Tabs.getArrowSvg = function (direction, color, size) {
1270
+ const path = (direction === "left") ? "m15 6-6 6 6 6" : "m9 6 6 6-6 6";
1271
+ return Tabs.getLineSvg(path, color, size, 2.2);
1272
+ };
1273
+
1274
+ // The scroll bar of the strip can not be hidden with inline styles.
1275
+ Tabs.injectCss = function () {
1276
+ basic.addCss("tabs-css",
1277
+ ".tabs-strip { scrollbar-width: none; -ms-overflow-style: none; scroll-behavior: smooth; }" +
1278
+ ".tabs-strip::-webkit-scrollbar { display: none; }");
1279
+ };
1280
+
1281
+ // *** STYLE PACKAGES:
1282
+ // USAGE: Tabs({ styleName: "modern" })
1283
+ // USAGE: Tabs({ styleName: "dark", style: { indicator: { color: "tomato" } } }) // Change only some keys.
1284
+ // USAGE: Tabs({ style: Tabs.styles.dark }) // The same as styleName: "dark". (The package is copied, never changed.)
1285
+ // NOTE: A new package needs only the keys that differ from the default (classic) style.
1286
+ // USAGE: Tabs.styles.myStyle = { indicator: { color: "red" } };
1287
+ Tabs.styles = {
1288
+
1289
+ // Dark text and a dark line on a light page.
1290
+ light: TabsDefaults.style,
1291
+
1292
+ // Cadetblue, same colors as the modern CheckBox, RadioButton, ProgressBar and TagInput.
1293
+ modern: {
1294
+ bar: { color: "transparent", padding: [0, 0], gap: 6, round: 0, dividerColor: "#D9DADB", dividerWidth: 1 },
1295
+ pillBar: { color: "#DFECEC", padding: [4, 4], gap: 2, round: 100, border: 0, borderColor: "transparent" },
1296
+ tab: { fontSize: 15, textColor: Black(0.5), padding: [16, 10], round: 100, gap: 8, minHeight: 42 },
1297
+ tabHover: { color: "#EEF5F5", textColor: "#2F5F61" },
1298
+ tabActive: { color: "transparent", textColor: "cadetblue" },
1299
+ pillActive: { textColor: White(1) },
1300
+ tabDisabled: { opacity: 0.4 },
1301
+ indicator: { color: "cadetblue", thickness: 3, round: 3, motion: 0.25 },
1302
+ pillIndicator: { color: "cadetblue", round: 100, shadow: "none", motion: 0.25 },
1303
+ icon: { size: 16 },
1304
+ count: { fontSize: 11, color: "#DFECEC", textColor: "#2F5F61", activeColor: "cadetblue", activeTextColor: White(1), round: 10, padding: [7, 1] },
1305
+ badge: { color: "tomato", size: 7 },
1306
+ close: { color: Black(0.35), hoverColor: "tomato", size: 14 },
1307
+ addButton: { color: "cadetblue", hoverColor: "#2F5F61", hoverBackground: "#EEF5F5", size: 16 },
1308
+ arrow: { color: "cadetblue", background: White(1), size: 16 },
1309
+ focus: { outlineColor: Black(0) },
1310
+ panel: { color: "transparent", padding: [0, 16], round: 0, border: 0, borderColor: "transparent" },
1311
+ disabled: { opacity: 0.5 },
1312
+ },
1313
+
1314
+ // Dark theme, same colors as SelectBox and TagInput "dark".
1315
+ dark: {
1316
+ bar: { color: "transparent", padding: [0, 0], gap: 4, round: 0, dividerColor: "rgba(255, 255, 255, 0.10)", dividerWidth: 1 },
1317
+ pillBar: { color: "rgba(255, 255, 255, 0.06)", padding: [4, 4], gap: 2, round: 8, border: 1, borderColor: "rgba(255, 255, 255, 0.08)" },
1318
+ tab: { fontSize: 14, textColor: "rgba(255, 255, 255, 0.55)", padding: [14, 10], round: 6, gap: 8, minHeight: 40 },
1319
+ tabHover: { color: "rgba(255, 255, 255, 0.05)", textColor: "rgba(255, 255, 255, 0.85)" },
1320
+ tabActive: { color: "transparent", textColor: "#FFFFFF" },
1321
+ pillActive: { textColor: "#FFFFFF" },
1322
+ tabDisabled: { opacity: 0.35 },
1323
+ indicator: { color: "#65A293", thickness: 2, round: 2, motion: 0.25 },
1324
+ pillIndicator: { color: "#3D7A6B", round: 6, shadow: "none", motion: 0.25 },
1325
+ icon: { size: 16 },
1326
+ count: { fontSize: 11, color: "rgba(255, 255, 255, 0.10)", textColor: "rgba(255, 255, 255, 0.7)", activeColor: "#65A293", activeTextColor: "#FFFFFF", round: 10, padding: [6, 1] },
1327
+ badge: { color: "#E66767", size: 7 },
1328
+ close: { color: "rgba(255, 255, 255, 0.45)", hoverColor: "#E66767", size: 14 },
1329
+ addButton: { color: "rgba(255, 255, 255, 0.55)", hoverColor: "#FFFFFF", hoverBackground: "rgba(255, 255, 255, 0.08)", size: 16 },
1330
+ arrow: { color: "rgba(255, 255, 255, 0.6)", background: "#232322", size: 16 },
1331
+ focus: { outlineColor: White(0) },
1332
+ panel: { color: "transparent", padding: [0, 16], round: 0, border: 0, borderColor: "transparent" },
1333
+ disabled: { opacity: 0.4 },
1334
+ },
1335
+
1336
+ };
1337
+ Tabs.styles.classic = Tabs.styles.light; // the old name of light: the pages made with it keep their look
1338
+
1339
+ // The minimal theme (_designs/minimal-theme.htm): a 13 px text, a 2 px ink line under the selected tab on one thin
1340
+ // line, no fill under the mouse (the text gets darker); the pill variant: a line around the bar and an ink line
1341
+ // around the selected tab. minimalDark: the same on a dark window.
1342
+ Tabs.createMinimalStyle = function (colors) {
1343
+ return {
1344
+ bar: { color: "transparent", padding: [0, 0], gap: 2, round: 0, dividerColor: colors.line, dividerWidth: 1 },
1345
+ pillBar: { color: "transparent", padding: [2, 2], gap: 2, round: 4, border: 1, borderColor: colors.line },
1346
+ tab: { fontSize: 13, textColor: colors.softText, padding: [10, 6], round: 3, gap: 6, minHeight: 30 },
1347
+ tabHover: { color: "transparent", textColor: colors.text },
1348
+ tabActive: { color: "transparent", textColor: colors.ink },
1349
+ pillActive: { textColor: colors.ink },
1350
+ tabDisabled: { opacity: 0.4 },
1351
+ indicator: { color: colors.ink, thickness: 2, round: 1, motion: 0.25 },
1352
+ pillIndicator: { color: "transparent", round: 3, shadow: "inset 0 0 0 1px " + colors.ink, motion: 0.25 },
1353
+ icon: { size: 14 },
1354
+ count: { fontSize: 11, color: "transparent", textColor: colors.softText, activeColor: colors.ink, activeTextColor: colors.onInk, round: 8, padding: [5, 0] },
1355
+ close: { color: colors.softText, hoverColor: colors.danger, size: 12 },
1356
+ addButton: { color: colors.softText, hoverColor: colors.ink, hoverBackground: "transparent", size: 14 },
1357
+ arrow: { color: colors.softText, background: colors.ground, size: 14 },
1358
+ focus: { outlineColor: colors.focus },
1359
+ panel: { color: "transparent", padding: [0, 12], round: 0, border: 0, borderColor: "transparent" },
1360
+ disabled: { opacity: 0.4 },
1361
+ };
1362
+ };
1363
+ Tabs.MINIMAL_COLORS = { ground: "#FFFFFF", ink: "#1F1F1F", onInk: "#FFFFFF", text: Black(0.85), softText: Black(0.55), line: Black(0.2), danger: "#C24A36", focus: "#3D8BD9" };
1364
+ Tabs.styles.minimal = Tabs.createMinimalStyle(Tabs.MINIMAL_COLORS);
1365
+ Tabs.MINIMAL_DARK_COLORS = { ground: "#1A1A19", ink: "#EDEDEB", onInk: "#1A1A19", text: White(0.88), softText: White(0.55), line: White(0.18), danger: "#FF9F93", focus: "#7FB6DE" };
1366
+ Tabs.styles.minimalDark = Tabs.createMinimalStyle(Tabs.MINIMAL_DARK_COLORS);