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,659 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Accordion - v26.11
6
+
7
+ UI COMPONENT
8
+ - Sections that fold: a row with a title, and under it the objects of the section. (Advanced settings in a small window,
9
+ the groups of a long form, questions and answers.)
10
+ - multiple: 1 (default): more than one section can be open. 0: a section that opens closes the others.
11
+ - A closed section keeps its objects: they keep their sizes, and can be made or changed while it is closed. It is only out
12
+ of sight and out of the reach of the keyboard. WHY not display: none: objects made in a hidden group are not in its flow.
13
+ - height: "auto" (default): it grows with its open sections. A number or "100%": the sections scroll inside it.
14
+ - Keyboard: Tab comes to the rows; Enter or Space opens and closes; ArrowUp, ArrowDown, Home and End move between the rows.
15
+ - animated: 1: the arrow turns, and the objects of a section fade in when it opens. Nothing moves at the first view, and
16
+ nothing with reduced motion. (context/basic-js-animated-rules.md: the height does not move.)
17
+ - Style packages: "light" (default), "dark", "minimal", "minimalDark". Select with styleName (Accordion.styles), or later
18
+ with setTheme().
19
+
20
+ A SECTION: { key, text, description, iconFile, icon, opened, enabled, data }
21
+ - A text is also accepted: "General" -> { key: "General", text: "General" }. Without a key: its text is its key.
22
+ - text, description: plain text (never read as HTML). description: a soft text at the end of the row (Ex: "3 files").
23
+ style.title and style.note are their look.
24
+ - icon: an SVG text (your own code, not a user text): it takes the color of style.icon (use stroke="currentColor" or
25
+ fill="currentColor"). iconFile: an image file.
26
+ - opened: 1 -> open at the start. enabled: 0 -> it does not open or close with the mouse and the keyboard.
27
+ - data: anything of yours.
28
+
29
+ USAGE:
30
+ const settings = Accordion({
31
+ sections: [{ key: "general", text: "General", opened: 1 }, { key: "advanced", text: "Advanced", description: "2 items" }],
32
+ onToggle: function (self, section) { println(section.key + ": " + section.opened); },
33
+ });
34
+ settings.startSection("general");
35
+ Label({ text: "The objects of this section, one under the other." });
36
+ settings.endSection();
37
+ createIn(settings.getContent("advanced"), function () { SmartButton({ labelText: "Reset" }); });
38
+ settings.open("advanced"); // onToggle is called
39
+ settings.close("advanced", 1); // silent
40
+ settings.toggle("general");
41
+ settings.isOpen("general");
42
+ settings.getOpenKeys(); // ["general"]
43
+ settings.addSection({ key: "more", text: "More" });
44
+ settings.setSectionDescription("more", "New");
45
+ settings.setTheme("dark");
46
+ Accordion({ multiple: 0, sections: ["One", "Two"], styleName: "dark", animated: 1 });
47
+
48
+ Started Date: November 2026
49
+ Webpage: https://bug7a.github.io/js-components/
50
+
51
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
52
+ Licensed under the Apache License, Version 2.0
53
+ SPDX-License-Identifier: Apache-2.0
54
+
55
+ */
56
+
57
+ "use strict";
58
+
59
+ // Default values:
60
+ const AccordionDefaults = {
61
+ key: "0", // Your name for this object: read it in a callback (self.key)
62
+ left: 0,
63
+ top: 0,
64
+ width: "100%",
65
+ height: "auto", // "auto": it grows with its open sections. A number or "100%": the sections scroll inside it.
66
+ sections: [], // [SECTION] (See A SECTION above)
67
+ multiple: 1, // 1: more than one section can be open. 0: a section that opens closes the others.
68
+ arrowSide: "right", // "right", "left": where the arrow of a row is
69
+ enabled: 1,
70
+ animated: 0, // 1: the arrow turns, the objects of a section fade in. setAnimated()
71
+ useScrollBar: 1, // basic/scroll-bar.js (when it is loaded), with a height that is not "auto". 0: the scrollbar of the browser.
72
+ onToggle: function (self, section) { }, // section.key, section.opened. (Not at create time, not with silent: 1)
73
+ styleName: "light", // "light", "dark", "minimal", "minimalDark" or a name added to Accordion.styles
74
+ style: { // Light style package (default)
75
+ box: { color: "white", border: 1, borderColor: Black(0.12), round: 10 },
76
+ row: { height: 44, padding: 14, gap: 10, color: "transparent", hoverColor: Black(0.04) },
77
+ title: { fontSize: 15, bold: 1, textColor: Black(0.82) },
78
+ note: { fontSize: 13, textColor: Black(0.5) },
79
+ icon: { size: 20, textColor: Black(0.6) },
80
+ arrow: { size: 14, textColor: Black(0.5) },
81
+ line: { size: 1, color: Black(0.1) }, // Between the sections
82
+ content: { color: "transparent", padding: [14, 12], gap: 12 },
83
+ disabled: { opacity: 0.4 },
84
+ focus: { ringColor: "rgba(63, 141, 148, 0.8)" },
85
+ scrollBar: { bar_color: "#9A9A98", bar_mouseOverColor: "#6A6A68", bar_width: 4, bar_round: 3 },
86
+ },
87
+ };
88
+
89
+ const Accordion = function (params = {}) {
90
+
91
+ // Merge style package: params.style > Accordion.styles[styleName] > AccordionDefaults.style (light)
92
+ const pageStyle = params.style; // WHY: setTheme() puts it over another package.
93
+ basic.applyStylePackage(params, Accordion.styles, AccordionDefaults);
94
+
95
+ // Merge params:
96
+ mergeIntoIfMissing(params, AccordionDefaults);
97
+
98
+ // WHY before startObject: box.height never reads "auto".
99
+ const isAutoHeight = (String(params.height) === "auto");
100
+
101
+ // BOX: Component container
102
+ const box = startObject(params);
103
+
104
+ // *** PRIVATE VARIABLES:
105
+ let _s = box.style;
106
+ const MOTION_TIME = 0.25; // s
107
+ const MOTION_EASE = "cubic-bezier(0.2, 0.8, 0.2, 1)"; // a fast start and a soft stop
108
+ const SPRING_TIME = 0.35; // s: the turn of the arrow
109
+ const SPRING_EASE = "cubic-bezier(0.34, 1.56, 0.64, 1)"; // a small overshoot, then back
110
+ const CLOSE_TIME = 0.15; // s: a section closes faster than it opens
111
+ const CONTENT_SHIFT = 6; // px: the objects come from this far when a section opens
112
+ const OPEN_ARROW = "rotate(180deg)";
113
+ const partsOf = new Map(); // section -> the objects of its row and its content
114
+ const startedSections = []; // the containers startSection() goes back to
115
+ let wasAnimated = 0;
116
+
117
+ // *** PUBLIC VARIABLES:
118
+ // NOTE: box.sections are the sections (see A SECTION), with section.opened 0 or 1. Default values are also public variables.
119
+
120
+ // *** PRIVATE FUNCTIONS:
121
+
122
+ // The style of a package, with the style of the page over it. (setTheme)
123
+ const styleOfPackage = function (styleName) {
124
+ const fresh = { styleName: styleName, style: pageStyle };
125
+ basic.applyStylePackage(fresh, Accordion.styles, AccordionDefaults);
126
+ mergeIntoIfMissing(fresh, AccordionDefaults);
127
+ return fresh.style;
128
+ };
129
+
130
+ const findSection = function (key) {
131
+ return box.sections.find(function (section) { return String(section.key) === String(key); });
132
+ };
133
+
134
+ const hasOpenSection = function () {
135
+ return box.sections.some(function (section) { return section.opened === 1; });
136
+ };
137
+
138
+ const isSectionEnabled = function (section) {
139
+ return (box.enabled == 1 && section.enabled === 1);
140
+ };
141
+
142
+ // A section from the page, as a plain object of its own (a text too).
143
+ const toSection = function (given) {
144
+ const isObject = (typeof given === "object" && given !== null);
145
+ const section = Object.assign({}, (isObject) ? given : { text: String(given) });
146
+ if (section.key === undefined || section.key === null) section.key = section.text;
147
+ if (section.text === undefined || section.text === null) section.text = String(section.key);
148
+ section.description = (section.description === undefined || section.description === null) ? "" : section.description;
149
+ section.opened = basic.isOn(section.opened) ? 1 : 0;
150
+ section.enabled = (section.enabled === undefined || basic.isOn(section.enabled)) ? 1 : 0;
151
+ if (box.multiple != 1 && hasOpenSection()) section.opened = 0;
152
+ return section;
153
+ };
154
+
155
+ const isMotionOn = function () {
156
+ if (box.animated != 1) return false;
157
+ const reduceMotion = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
158
+ return !reduceMotion;
159
+ };
160
+
161
+ const refreshScroll = function () {
162
+ if (box.scrollBar && box.scrollBar.refreshScroll) box.scrollBar.refreshScroll();
163
+ };
164
+
165
+ // PAINT: the look of a row: the mouse on it, enabled or not.
166
+ const paintRow = function (section) {
167
+ const parts = partsOf.get(section);
168
+ const isEnabled = isSectionEnabled(section);
169
+ parts.row.color = (parts.isHovered && isEnabled) ? _s.row.hoverColor : _s.row.color;
170
+ parts.row.opacity = (isEnabled) ? 1 : _s.disabled.opacity;
171
+ parts.row.cursor = (isEnabled) ? "pointer" : "default";
172
+ parts.row.tabIndex = (isEnabled) ? 0 : -1;
173
+ parts.row.aria = { disabled: (isEnabled) ? "false" : "true" };
174
+ };
175
+
176
+ // The texts of a row. WHY plainText: a title can be a text of a user.
177
+ const applyContent = function (section) {
178
+ const parts = partsOf.get(section);
179
+ parts.title.plainText = section.text;
180
+ parts.note.plainText = section.description;
181
+ parts.note.visible = (section.description === "") ? 0 : 1;
182
+ parts.frame.aria = { label: section.text };
183
+ };
184
+
185
+ // The look of a section that comes from the style (the first drawing and setTheme).
186
+ const applySectionLook = function (section) {
187
+ const parts = partsOf.get(section);
188
+ parts.line.props({ height: _s.line.size, color: _s.line.color });
189
+ parts.row.props({ height: _s.row.height, gap: _s.row.gap, padding: [_s.row.padding, 0] });
190
+ parts.row.setFocusRing(_s.focus.ringColor);
191
+ parts.title.props(_s.title);
192
+ parts.note.props(_s.note);
193
+ parts.arrow.props({ width: _s.arrow.size, height: _s.arrow.size, textColor: _s.arrow.textColor });
194
+ if (parts.icon) parts.icon.props({ width: _s.icon.size, height: _s.icon.size, textColor: _s.icon.textColor });
195
+ parts.content.props({ color: _s.content.color, gap: _s.content.gap, padding: _s.content.padding });
196
+ paintRow(section);
197
+ };
198
+
199
+ // The line is between the sections: the first one has none.
200
+ const refreshLines = function () {
201
+ box.sections.forEach(function (section, index) {
202
+ partsOf.get(section).line.visible = (index > 0) ? 1 : 0;
203
+ });
204
+ };
205
+
206
+ // The objects of a section fade and move when it opens and closes (with animated: 1).
207
+ const paintContentMotion = function (section) {
208
+ if (!isMotionOn()) return;
209
+ const parts = partsOf.get(section);
210
+ const isOpen = (section.opened === 1);
211
+ parts.content.css.transitionDuration = ((isOpen) ? MOTION_TIME : CLOSE_TIME) + "s";
212
+ parts.content.opacity = (isOpen) ? 1 : 0;
213
+ parts.content.css.transform = (isOpen) ? "none" : "translateY(" + (-CONTENT_SHIFT) + "px)";
214
+ };
215
+
216
+ const cancelClosing = function (parts) {
217
+ if (!parts.cancelClosing) return;
218
+ parts.cancelClosing();
219
+ parts.cancelClosing = null;
220
+ };
221
+
222
+ // The height of what folds. WHY after a moment: the objects fade out first.
223
+ const placeFrame = function (section) {
224
+ const parts = partsOf.get(section);
225
+ cancelClosing(parts);
226
+ if (section.opened === 1) {
227
+ parts.frame.height = "auto";
228
+ return;
229
+ }
230
+ if (!isMotionOn()) {
231
+ parts.frame.height = 0;
232
+ return;
233
+ }
234
+ parts.cancelClosing = box.after(CLOSE_TIME * 1000, function () {
235
+ parts.frame.height = 0;
236
+ parts.cancelClosing = null;
237
+ refreshScroll();
238
+ });
239
+ };
240
+
241
+ // Everything that follows open or closed. WHY one function: no setter can forget a part of it.
242
+ const showOpenState = function (section) {
243
+ const parts = partsOf.get(section);
244
+ const isOpen = (section.opened === 1);
245
+ parts.row.aria = { expanded: (isOpen) ? "true" : "false" };
246
+ parts.frame.aria = { hidden: (isOpen) ? "false" : "true" };
247
+ if (isOpen) parts.frame.elem.removeAttribute("inert");
248
+ else parts.frame.elem.setAttribute("inert", ""); // WHY: Tab must not reach the objects of a closed section.
249
+ parts.arrow.css.transform = (isOpen) ? OPEN_ARROW : "none";
250
+ paintContentMotion(section);
251
+ placeFrame(section);
252
+ refreshScroll();
253
+ };
254
+
255
+ const applySectionMotion = function (section) {
256
+ const parts = partsOf.get(section);
257
+ parts.arrow.setMotion("transform " + SPRING_TIME + "s " + SPRING_EASE);
258
+ parts.content.setMotion("opacity " + MOTION_TIME + "s " + MOTION_EASE + ", transform " + MOTION_TIME + "s " + MOTION_EASE);
259
+ paintContentMotion(section);
260
+ };
261
+
262
+ const removeSectionMotion = function (section) {
263
+ const parts = partsOf.get(section);
264
+ parts.arrow.setMotion("");
265
+ parts.content.setMotion("");
266
+ parts.content.opacity = 1;
267
+ parts.content.css.transform = "";
268
+ parts.content.css.transitionDuration = "";
269
+ placeFrame(section);
270
+ };
271
+
272
+ const applyAnimated = function () {
273
+ if (isMotionOn()) {
274
+ wasAnimated = 1;
275
+ box.sections.forEach(applySectionMotion);
276
+ return;
277
+ }
278
+ if (!wasAnimated) return;
279
+ wasAnimated = 0;
280
+ box.sections.forEach(removeSectionMotion);
281
+ };
282
+
283
+ const setOpened = function (section, opened, silent) {
284
+ if (section.opened === opened) return;
285
+ section.opened = opened;
286
+ showOpenState(section);
287
+ if (!silent) box.onToggle(box, section);
288
+ };
289
+
290
+ const openSection = function (section, silent) {
291
+ if (box.multiple != 1) {
292
+ box.sections.forEach(function (other) {
293
+ if (other !== section) setOpened(other, 0, silent);
294
+ });
295
+ }
296
+ setOpened(section, 1, silent);
297
+ };
298
+
299
+ const toggleSection = function (section, silent) {
300
+ if (section.opened === 1) setOpened(section, 0, silent);
301
+ else openSection(section, silent);
302
+ };
303
+
304
+ const enabledRows = function () {
305
+ return box.sections.filter(isSectionEnabled).map(function (section) { return partsOf.get(section).row; });
306
+ };
307
+
308
+ // The row a key goes to from a row, or null for another key.
309
+ const rowOfKey = function (row, key) {
310
+ const rows = enabledRows();
311
+ const place = rows.indexOf(row);
312
+ if (key === "ArrowDown") return rows[Math.min(place + 1, rows.length - 1)];
313
+ if (key === "ArrowUp") return rows[Math.max(place - 1, 0)];
314
+ if (key === "Home") return rows[0];
315
+ if (key === "End") return rows[rows.length - 1];
316
+ return null;
317
+ };
318
+
319
+ const onRowKeyDown = function (section, event) {
320
+ if (!isSectionEnabled(section)) return;
321
+ if (event.key === "Enter" || event.key === " ") {
322
+ event.preventDefault();
323
+ toggleSection(section, 0);
324
+ return;
325
+ }
326
+ const row = rowOfKey(partsOf.get(section).row, event.key);
327
+ if (!row) return;
328
+ event.preventDefault();
329
+ row.elem.focus();
330
+ };
331
+
332
+ const listenToRow = function (section) {
333
+ const parts = partsOf.get(section);
334
+ parts.row.on("click", function () {
335
+ if (isSectionEnabled(section)) toggleSection(section, 0);
336
+ });
337
+ parts.row.on("keydown", function (self, event) { onRowKeyDown(section, event); });
338
+ parts.row.onHoverChange(function (self, value) {
339
+ parts.isHovered = value;
340
+ paintRow(section);
341
+ });
342
+ };
343
+
344
+ // ICON: A picture file, or LABEL: an SVG text that takes the color of the style. None: no place.
345
+ const createRowIcon = function (section) {
346
+ if (section.iconFile) {
347
+ const icon = Icon({ shrink: 0, space: 0 });
348
+ icon.load(section.iconFile);
349
+ return icon;
350
+ }
351
+ if (!section.icon) return null;
352
+ basic.addCss("accordion-svg", ".accordion-svg svg { display: block; width: 100%; height: 100%; }");
353
+ const icon = Label({ text: section.icon, shrink: 0 });
354
+ icon.elem.classList.add("accordion-svg");
355
+ return icon;
356
+ };
357
+
358
+ const createRowArrow = function (parts) {
359
+ // LABEL: The arrow. WHY a Label: its SVG takes the color of its text.
360
+ parts.arrow = Label({ text: Accordion.getArrowSvg(), shrink: 0 });
361
+ };
362
+
363
+ // The objects of a section, at the end of the list.
364
+ const createSectionView = function (section) {
365
+ const parts = { isHovered: 0, cancelClosing: null };
366
+
367
+ // GROUP: A section
368
+ parts.group = VGroup({ width: "100%", height: "auto", align: "left top", shrink: 0 });
369
+
370
+ // BOX: The line over it
371
+ parts.line = Box({ width: "100%", shrink: 0 });
372
+
373
+ // GROUP: Its row
374
+ parts.row = HGroup({ width: "100%", align: "left center", shrink: 0 });
375
+ parts.row.role = "button";
376
+
377
+ if (box.arrowSide === "left") createRowArrow(parts);
378
+ parts.icon = createRowIcon(section);
379
+
380
+ // LABEL: Title. WHY width 0 and grow: a long title gives way to the note and is cut with an ellipsis.
381
+ parts.title = Label({ width: 0, grow: 1, shrink: 1, ellipsis: 1 });
382
+
383
+ // LABEL: Note
384
+ parts.note = Label({ shrink: 0 });
385
+ parts.note.css.whiteSpace = "nowrap";
386
+
387
+ if (box.arrowSide !== "left") createRowArrow(parts);
388
+
389
+ endGroup();
390
+
391
+ // GROUP: What folds. WHY a group around the content: its height goes to 0, the content keeps its own.
392
+ parts.frame = VGroup({ width: "100%", height: "auto", align: "left top", shrink: 0 });
393
+ parts.frame.role = "region";
394
+
395
+ // GROUP: The objects of the section
396
+ parts.content = VGroup({ width: "100%", height: "auto", align: "left top", shrink: 0, clipContent: 0 });
397
+ endGroup();
398
+
399
+ endGroup();
400
+
401
+ endGroup();
402
+
403
+ partsOf.set(section, parts);
404
+ };
405
+
406
+ const addSectionToList = function (given) {
407
+ const section = toSection(given);
408
+ if (findSection(section.key)) {
409
+ console.warn("Accordion: The key is used: " + section.key);
410
+ return null;
411
+ }
412
+ box.sections.push(section);
413
+ createIn(box.list, function () { createSectionView(section); });
414
+ listenToRow(section);
415
+ applyContent(section);
416
+ applySectionLook(section);
417
+ if (wasAnimated) applySectionMotion(section);
418
+ showOpenState(section);
419
+ refreshLines();
420
+ return section;
421
+ };
422
+
423
+ const removeSectionFromList = function (section) {
424
+ const parts = partsOf.get(section);
425
+ cancelClosing(parts);
426
+ parts.group.remove();
427
+ partsOf.delete(section);
428
+ box.sections.splice(box.sections.indexOf(section), 1);
429
+ };
430
+
431
+ // LOOK: what comes from the style (the first drawing and setTheme)
432
+ const applyLook = function () {
433
+ box.props(_s.box);
434
+ box.sections.forEach(applySectionLook);
435
+ };
436
+
437
+ // *** PUBLIC FUNCTIONS:
438
+
439
+ // silent: 1 -> onToggle is not called. These work on a disabled section too: only the mouse and the keyboard can not.
440
+ box.open = function (key, silent = 0) {
441
+ const section = findSection(key);
442
+ if (section) openSection(section, silent);
443
+ };
444
+ // USAGE: settings.open("advanced")
445
+
446
+ box.close = function (key, silent = 0) {
447
+ const section = findSection(key);
448
+ if (section) setOpened(section, 0, silent);
449
+ };
450
+ // USAGE: settings.close("advanced", 1)
451
+
452
+ box.toggle = function (key, silent = 0) {
453
+ const section = findSection(key);
454
+ if (section) toggleSection(section, silent);
455
+ };
456
+
457
+ // Only with multiple: 1: with multiple: 0 only one section can be open.
458
+ box.openAll = function (silent = 0) {
459
+ if (box.multiple != 1) return;
460
+ box.sections.forEach(function (section) { setOpened(section, 1, silent); });
461
+ };
462
+
463
+ box.closeAll = function (silent = 0) {
464
+ box.sections.forEach(function (section) { setOpened(section, 0, silent); });
465
+ };
466
+
467
+ box.isOpen = function (key) {
468
+ const section = findSection(key);
469
+ return (section && section.opened === 1) ? 1 : 0;
470
+ };
471
+
472
+ box.getOpenKeys = function () {
473
+ return box.sections.filter(function (section) { return section.opened === 1; }).map(function (section) { return section.key; });
474
+ };
475
+
476
+ box.getSection = function (key) {
477
+ return findSection(key) || null;
478
+ };
479
+
480
+ // The group of the objects of a section. USAGE: createIn(settings.getContent("general"), function () { Label({ text: "Hi" }); });
481
+ box.getContent = function (key) {
482
+ const section = findSection(key);
483
+ return (section) ? partsOf.get(section).content : null;
484
+ };
485
+
486
+ // The objects made until endSection() go into this section, one under the other.
487
+ // WHY a group in it: an endGroup() of the page goes back to this group, not to the box that was open before.
488
+ box.startSection = function (key) {
489
+ const section = findSection(key) || addSectionToList({ key: key });
490
+ startedSections.push(getDefaultContainerBox());
491
+ setDefaultContainerBox(partsOf.get(section).content);
492
+ return VGroup({ width: "100%", height: "auto", align: "left top", gap: _s.content.gap, shrink: 0, clipContent: 0 });
493
+ };
494
+
495
+ box.endSection = function () {
496
+ endGroup();
497
+ const previous = startedSections.pop();
498
+ if (previous) setDefaultContainerBox(previous);
499
+ };
500
+
501
+ box.addSection = function (section) {
502
+ return addSectionToList(section);
503
+ };
504
+ // USAGE: settings.addSection({ key: "more", text: "More", opened: 1 })
505
+
506
+ box.removeSection = function (key) {
507
+ const section = findSection(key);
508
+ if (!section) return;
509
+ removeSectionFromList(section);
510
+ refreshLines();
511
+ refreshScroll();
512
+ };
513
+
514
+ // New sections in the place of all of them (their objects go too).
515
+ box.setSections = function (sections) {
516
+ box.sections.slice().forEach(removeSectionFromList);
517
+ sections.forEach(addSectionToList);
518
+ refreshScroll();
519
+ };
520
+
521
+ box.setSectionText = function (key, text) {
522
+ const section = findSection(key);
523
+ if (!section) return;
524
+ section.text = text;
525
+ applyContent(section);
526
+ };
527
+
528
+ box.setSectionDescription = function (key, text) {
529
+ const section = findSection(key);
530
+ if (!section) return;
531
+ section.description = text;
532
+ applyContent(section);
533
+ };
534
+
535
+ box.setSectionEnabled = function (key, value) {
536
+ const section = findSection(key);
537
+ if (!section) return;
538
+ section.enabled = basic.isOn(value) ? 1 : 0;
539
+ paintRow(section);
540
+ };
541
+
542
+ box.setEnabled = function (value) {
543
+ box.enabled = basic.isOn(value) ? 1 : 0;
544
+ box.sections.forEach(paintRow);
545
+ };
546
+
547
+ box.setAnimated = function (value) {
548
+ box.animated = basic.isOn(value) ? 1 : 0;
549
+ applyAnimated();
550
+ };
551
+ // USAGE: settings.setAnimated(1)
552
+
553
+ // The row of a section takes the focus (no key: the first one that can).
554
+ box.focus = function (key) {
555
+ const section = findSection(key);
556
+ const row = (section) ? partsOf.get(section).row : enabledRows()[0];
557
+ if (row) row.elem.focus();
558
+ };
559
+
560
+ // Another style package while it is on the page. A style given by the page stays over it.
561
+ box.setTheme = function (styleName) {
562
+ box.styleName = styleName;
563
+ _s = styleOfPackage(styleName);
564
+ box.style = _s;
565
+ applyLook();
566
+ };
567
+ // USAGE: settings.setTheme("dark")
568
+
569
+ // *** OBJECT VIEW:
570
+
571
+ const createList = function () {
572
+ // GROUP: The sections. WHY position: a relative group makes a box of height "auto" wrap it.
573
+ box.list = VGroup({ width: "100%", height: "auto", align: "left top", position: "relative" });
574
+ endGroup();
575
+ };
576
+
577
+ if (isAutoHeight) {
578
+ createList();
579
+ } else {
580
+ // BOX: The place that scrolls
581
+ box.listArea = startBox({ left: 0, top: 0, width: "100%", height: "100%", color: "transparent" });
582
+ box.listArea.scrollY = 1;
583
+ createList();
584
+ endBox();
585
+ if (box.useScrollBar == 1 && typeof ScrollBar !== "undefined") {
586
+ box.scrollBar = ScrollBar(Object.assign({ scrollableBox: box.listArea, neverHide: 0, showDots: 0 }, _s.scrollBar));
587
+ }
588
+ }
589
+
590
+ // *** OBJECT INIT CODE:
591
+
592
+ box.enabled = basic.isOn(box.enabled) ? 1 : 0;
593
+ box.props(_s.box);
594
+
595
+ const givenSections = box.sections;
596
+ box.sections = [];
597
+ givenSections.forEach(addSectionToList);
598
+
599
+ applyAnimated();
600
+ if (!isAutoHeight) box.list.onResize(refreshScroll);
601
+
602
+ return endObject(box);
603
+
604
+ };
605
+
606
+ // *** STATIC FUNCTIONS:
607
+
608
+ // The arrow of a row: it looks down when closed, and turns when open. It takes the color of its text.
609
+ Accordion.getArrowSvg = function () {
610
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 12 12" fill="none" stroke="currentColor"' +
611
+ ' stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" style="display:block"><path d="M2.5 4.5 6 8l3.5-3.5"/></svg>';
612
+ };
613
+
614
+ // *** STYLE PACKAGES:
615
+ // USAGE: Accordion({ styleName: "dark" })
616
+ // USAGE: Accordion({ style: { box: { border: 0 }, row: { height: 52 } } }) // Change only some keys.
617
+ // NOTE: A new package needs only the keys that differ from the default (light) style.
618
+ // USAGE: Accordion.styles.myStyle = { title: { textColor: "tomato" } };
619
+ Accordion.styles = {
620
+
621
+ // White, a soft line between the sections.
622
+ light: AccordionDefaults.style,
623
+
624
+ // For a dark window: the colors of the fields of the kit.
625
+ dark: {
626
+ box: { color: "#232322", borderColor: White(0.12) },
627
+ row: { hoverColor: White(0.05) },
628
+ title: { textColor: White(0.9) },
629
+ note: { textColor: White(0.5) },
630
+ icon: { textColor: White(0.65) },
631
+ arrow: { textColor: White(0.55) },
632
+ line: { color: White(0.1) },
633
+ focus: { ringColor: "rgba(111, 198, 205, 0.8)" },
634
+ },
635
+
636
+ };
637
+
638
+ // The minimal theme (_designs/minimal-theme.htm): no fill (the ground of the window), a soft line around it and
639
+ // between the sections, 32 px rows with a 13 px title, a faint row under the mouse, small soft arrows and icons.
640
+ // minimalDark: the same on a dark window.
641
+ Accordion.createMinimalStyle = function (colors) {
642
+ return {
643
+ box: { color: "transparent", border: 1, borderColor: colors.line, round: 4 },
644
+ row: { height: 32, padding: 10, gap: 8, color: "transparent", hoverColor: colors.hover },
645
+ title: { fontSize: 13, bold: 1, textColor: colors.text },
646
+ note: { fontSize: 12, textColor: colors.softText },
647
+ icon: { size: 14, textColor: colors.softText },
648
+ arrow: { size: 12, textColor: colors.softText },
649
+ line: { size: 1, color: colors.line },
650
+ content: { color: "transparent", padding: [10, 10], gap: 10 },
651
+ disabled: { opacity: 0.4 },
652
+ focus: { ringColor: colors.focus },
653
+ scrollBar: { bar_color: colors.scrollBar, bar_mouseOverColor: colors.scrollBar, bar_width: 3, bar_round: 2 },
654
+ };
655
+ };
656
+ Accordion.MINIMAL_COLORS = { text: Black(0.85), softText: Black(0.55), line: Black(0.2), hover: Black(0.04), focus: "#3D8BD9", scrollBar: "#9A9A98" };
657
+ Accordion.styles.minimal = Accordion.createMinimalStyle(Accordion.MINIMAL_COLORS);
658
+ Accordion.MINIMAL_DARK_COLORS = { text: White(0.88), softText: White(0.55), line: White(0.18), hover: White(0.06), focus: "#7FB6DE", scrollBar: "#A0A0A0" };
659
+ Accordion.styles.minimalDark = Accordion.createMinimalStyle(Accordion.MINIMAL_DARK_COLORS);