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,807 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Filters - v26.11
6
+
7
+ UI COMPONENT
8
+ - A filter menu: a "Filters" button, and under it a panel with a search field, groups of options with check
9
+ boxes and a footer with the number of the selected options and "Clear all".
10
+ - The groups (sections) open and close (a click, or Enter / Space on the title); the search shows the options with
11
+ the text; every change of the selection goes to onChange (not at create time, not with silent: 1).
12
+ - The fields of the kit: the search field is a SearchInput (comp/search-input.js, its
13
+ params: searchInputParams, "ozden" by default) and every option is a CheckBox (comp/check-box.js, its params:
14
+ checkBoxParams, "light" by default; the row is the check box, its checked mark takes the accent). Load them
15
+ before this file; without them a plain field and a plain check are drawn.
16
+ - animated: 1: the panel and an opened section come with a fade and a short slide (they go faster),
17
+ the arrows turn with a small spring, and the search field and the check boxes get their own motions (SearchInput,
18
+ CheckBox). Nothing moves at the first view; off when the system asks for reduced motion. setAnimated(0/1).
19
+ - The icon of the button is two-tone: sliders on a light box, in the accent (style.buttonIcon).
20
+ - Style packages: "light" (default). Select with styleName. (Filters.styles)
21
+
22
+ USAGE:
23
+ const filters = Filters({
24
+ sections: [
25
+ { key: "type", text: "Type", opened: 1, options: [
26
+ { key: "car", text: "Car" },
27
+ { key: "truck", text: "Truck", checked: 1 },
28
+ ] },
29
+ { key: "status", text: "Status", opened: 0, options: ["Online", "Offline"] }, // a text: its key is the text
30
+ ],
31
+ onChange: function (self) { println(JSON.stringify(self.getSelected())); }, // { type: ["truck"], status: [] }
32
+ });
33
+ filters.setSelected("status", ["Online"]); // onChange is called; setSelected("status", ["Online"], 1): silent
34
+ filters.clearAll();
35
+ filters.setSectionOpened("status", 1);
36
+ filters.openPanel(); filters.closePanel(); filters.togglePanel();
37
+ filters.search("tru"); // the search field does it too
38
+ filters.setSections([...]); // new data (the selection comes from the data)
39
+ Filters({ panelOpened: 0 }); // only the button: a click opens the panel
40
+ Filters({ panelMode: "popup", panelOpened: 0 }); // the panel opens over the page; a click outside / Escape closes it
41
+ Filters({ style: { accentColor: "#2E7D5B" } }); // change only some keys of the style
42
+ Filters({ animated: 1 }); // the motions (filters.setAnimated(0) stops them)
43
+ Filters({ checkBoxParams: { styleName: "modern" }, searchInputParams: { styleName: "light" } });
44
+
45
+ Started Date: October 2026
46
+ Webpage: https://bug7a.github.io/js-components/
47
+
48
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
49
+ Licensed under the Apache License, Version 2.0
50
+ SPDX-License-Identifier: Apache-2.0
51
+
52
+ */
53
+
54
+ "use strict";
55
+
56
+ // Default values:
57
+ const FiltersDefaults = {
58
+ key: "0", // Your name for this object: read it in a callback (self.key)
59
+ width: 380, // The width of the panel (the button stands at its right)
60
+ height: "auto", // The button and the panel
61
+ panelHeight: 620,
62
+ panelOpened: 1, // 0: only the button; a click opens the panel
63
+ // "inline": the panel is under the button, in the layout of the page (it moves the objects under it).
64
+ // "popup": the panel opens over the page, under the right edge of the button (above it, when there is no
65
+ // space below); a click outside it or Escape closes it.
66
+ panelMode: "inline",
67
+ buttonText: "Filters",
68
+ searchPlaceholder: "Search",
69
+ selectedText: "Selected",
70
+ clearText: "Clear all",
71
+ noResultText: "No results",
72
+ // [{ key, text, opened, options: [{ key, text, checked }] or ["text"] }]
73
+ sections: [],
74
+ animated: 0, // 1: the panel and an opened section come in, the arrows turn (box.setAnimated(0/1))
75
+ // The search field: the params of its SearchInput (comp/search-input.js). Its
76
+ // placeholder is searchPlaceholder; its animated is the animated of Filters (unless it is given here).
77
+ searchInputParams: { styleName: "ozden", width: "100%", height: 50, fontSize: 18, searchIconSize: 20 },
78
+ // The check boxes: the params of every CheckBox (comp/check-box.js). The row look is
79
+ // style.row and the checked mark is the accent; a style given here wins. Their animated is the animated of
80
+ // Filters (unless it is given here).
81
+ checkBoxParams: { styleName: "light", style: {} },
82
+ onChange: function (self) { }, // The selection changed: self.getSelected(). (Not at create time, not with silent: 1)
83
+ onPanelToggle: function (self) { }, // The panel opened / closed: self.panelOpened
84
+ styleName: "light", // "light" or a name added to Filters.styles
85
+ style: { // Light style package (default)
86
+ accentColor: "#2F5BD3", // a checked box, "Clear all", the icon of the button
87
+ textColor: "#1F1F1E",
88
+ softTextColor: "#8C8B88", // the titles of the sections, "Selected", the search icon
89
+ fontSize: 18,
90
+ button: { color: "#E2E1DD", height: 50, round: 12, padding: [16, 0], gap: 8 },
91
+ // The two-tone icon of the button: sliders on a light box. "": the accent, and a light tone of it.
92
+ buttonIcon: { strongColor: "", lightColor: "" },
93
+ panel: { color: "#F7F6F3", border: 1, borderColor: "#E4E3DF", round: 18, padding: 8, gap: 6, shadow: "0 10px 30px rgba(0, 0, 0, 0.08)" },
94
+ field: { color: "#EDECE8", height: 50, round: 12, padding: [14, 0], gap: 10 }, // the plain field (no SearchInput)
95
+ header: { height: 44, padding: [12, 0], gap: 8 },
96
+ row: { color: "white", height: 48, round: 12, padding: [12, 0], gap: 14, hoverColor: "#FBFBFA" },
97
+ check: { size: 22, round: 6, color: "#EDECE8", markColor: "white" }, // the plain check (no CheckBox)
98
+ badge: { color: "#E6E5E1", fontSize: 14, round: 11, padding: [8, 2] },
99
+ footer: { height: 56, padding: [12, 0], gap: 8 },
100
+ listGap: 6,
101
+ scrollBar: { bar_color: "#8C8B88", bar_width: 4, bar_round: 3, bar_opacity: 0.4, bar_mouseOverOpacity: 0.9 },
102
+ },
103
+ };
104
+
105
+ const Filters = function (params = {}) {
106
+
107
+ // Merge style package: params.style > Filters.styles[styleName] > FiltersDefaults.style (light)
108
+ basic.applyStylePackage(params, Filters.styles, FiltersDefaults);
109
+
110
+ // Merge params:
111
+ mergeIntoIfMissing(params, FiltersDefaults);
112
+
113
+ // Edit params, if needed:
114
+ params.sections = Filters.normalizeSections(params.sections); // WHY: A copy: the data of the caller does not change.
115
+ const isPopup = (params.panelMode === "popup");
116
+ const panelWidth = params.width;
117
+ if (isPopup) params.width = "auto"; // WHY: Only the button is in the box; the panel is on the page.
118
+
119
+ // BOX: Component container
120
+ const box = startObject(params);
121
+
122
+ // *** PRIVATE VARIABLES:
123
+ const _s = box.style;
124
+ const ICON_SIZE = 20;
125
+ const MARK_SIZE = 16;
126
+ const LIST_GAPS = 12; // the gaps between the field, the list and the footer in the panel
127
+ const PANEL_GAP = 10; // between the button and the panel
128
+ const PANEL_Z_INDEX = 1001; // a popup panel over the page (like the list of SelectBox)
129
+ const SCREEN_MARGIN = 8; // a popup panel stays this far from the edges of the screen
130
+ // MOTION (animated: 1; context/basic-js-animated-rules.md)
131
+ const MOTION_TIME = "0.25s";
132
+ const MOTION_EASE = "cubic-bezier(0.2, 0.8, 0.2, 1)"; // a fast start, a soft stop
133
+ const SPRING_TIME = "0.35s"; // WHY: an arrow that turns to show a new state ends with a small overshoot
134
+ const SPRING_EASE = "cubic-bezier(0.34, 1.56, 0.64, 1)";
135
+ const ARROW_MOTION = "transform " + SPRING_TIME + " " + SPRING_EASE;
136
+ const CLOSE_TIME = 150; // ms: a panel goes faster than it comes
137
+ const OPEN_MOVE = 6; // px: a panel and the options of an opened section come from here
138
+ const hasSearchInput = (typeof SearchInput !== "undefined");
139
+ const hasCheckBox = (typeof CheckBox !== "undefined");
140
+ let searchText = "";
141
+ let isCreated = 0; // WHY: nothing moves at the first view
142
+ let wasAnimated = 0;
143
+ let cancelPanelHide = null;
144
+
145
+ // *** PUBLIC VARIABLES:
146
+ box.sectionViews = []; // [{ section, header, lblCount, lblArrow, body, rows: [{ option, row, checkBox | check, mark }] }]
147
+ // NOTE: Default values are also public variables. (box.sections, box.panelOpened, box.buttonText...)
148
+
149
+ // *** PRIVATE FUNCTIONS:
150
+
151
+ // LABEL: an icon (an SVG in the color of the label)
152
+ const createIcon = function (svg, color) {
153
+ const icon = Label({ text: svg, textColor: color, lineHeight: "0" });
154
+ icon.shrink = 0;
155
+ return icon;
156
+ };
157
+
158
+ // BOX: a space that takes the rest of a row
159
+ const createSpace = function () {
160
+ const space = Box({ width: 1, height: 1, color: "transparent" });
161
+ space.grow = 1;
162
+ return space;
163
+ };
164
+
165
+ // LABEL: a number in a small round badge
166
+ const createBadge = function () {
167
+ const badge = Label({ text: "", fontSize: _s.badge.fontSize, textColor: _s.softTextColor, color: _s.badge.color, round: _s.badge.round, padding: _s.badge.padding });
168
+ badge.shrink = 0;
169
+ return badge;
170
+ };
171
+
172
+ const countChecked = function (section) {
173
+ return section.options.filter(function (option) { return option.checked; }).length;
174
+ };
175
+
176
+ const matchesSearch = function (option) {
177
+ if (!searchText) return true;
178
+ return option.text.toLocaleLowerCase().indexOf(searchText) !== -1;
179
+ };
180
+
181
+ // *** MOTION
182
+
183
+ const isMotionOn = function () {
184
+ if (box.animated != 1) return false;
185
+ return !(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
186
+ };
187
+
188
+ // An object comes: from a fade and a short slide (move px) to its place
189
+ const comeIn = function (obj, move) {
190
+ obj.setMotionNow("none");
191
+ obj.opacity = 0;
192
+ obj.css = { transform: "translateY(" + move + "px)" };
193
+ void obj.elem.offsetHeight; // WHY: the start look must be drawn before the motion is turned on
194
+ obj.setMotionNow("opacity " + MOTION_TIME + " " + MOTION_EASE + ", transform " + MOTION_TIME + " " + MOTION_EASE);
195
+ obj.opacity = 1;
196
+ obj.css = { transform: "none" };
197
+ };
198
+
199
+ // An object goes, faster: it fades and slides away (the caller hides it after CLOSE_TIME)
200
+ const goOut = function (obj, move) {
201
+ obj.setMotionNow("opacity " + CLOSE_TIME + "ms " + MOTION_EASE + ", transform " + CLOSE_TIME + "ms " + MOTION_EASE);
202
+ obj.opacity = 0;
203
+ obj.css = { transform: "translateY(" + move + "px)" };
204
+ };
205
+
206
+ // The still look (a hidden object comes in again from it)
207
+ const stopMotion = function (obj) {
208
+ obj.setMotionNow("none");
209
+ obj.opacity = 1;
210
+ obj.css = { transform: "none" };
211
+ };
212
+
213
+ // The arrows turn with a spring. (setMotion waits a moment: the first paint does not move.)
214
+ const setArrowMotions = function () {
215
+ if (!isMotionOn()) return;
216
+ box.sectionViews.forEach(function (view) { view.lblArrow.setMotion(ARROW_MOTION); });
217
+ box.lblButtonArrow.setMotion(ARROW_MOTION);
218
+ };
219
+
220
+ // The arrow of a section: animated, one down arrow that turns; still, an up or a down icon (as before)
221
+ const paintArrow = function (arrow, isOpened) {
222
+ if (isMotionOn()) {
223
+ if (!arrow.isTurningArrow) arrow.text = Filters.icon("down", ICON_SIZE);
224
+ arrow.isTurningArrow = 1;
225
+ arrow.css = { transform: (isOpened) ? "rotate(180deg)" : "none" };
226
+ return;
227
+ }
228
+ if (arrow.isTurningArrow) arrow.css = { transform: "none" };
229
+ arrow.isTurningArrow = 0;
230
+ arrow.text = Filters.icon((isOpened) ? "up" : "down", ICON_SIZE);
231
+ };
232
+
233
+ // The arrow of the button turns while the panel is open (only animated: a still arrow always looks down)
234
+ const paintButtonArrow = function () {
235
+ if (isMotionOn()) {
236
+ box.lblButtonArrow.css = { transform: (box.panelOpened) ? "rotate(180deg)" : "none" };
237
+ return;
238
+ }
239
+ if (wasAnimated) box.lblButtonArrow.css = { transform: "none" };
240
+ };
241
+
242
+ const applyAnimated = function () {
243
+ if (box.searchInput) box.searchInput.setAnimated(box.animated);
244
+ box.sectionViews.forEach(function (view) {
245
+ view.rows.forEach(function (rowView) {
246
+ if (rowView.checkBox) rowView.checkBox.setAnimated(box.animated);
247
+ });
248
+ });
249
+ if (isMotionOn()) {
250
+ setArrowMotions();
251
+ wasAnimated = 1;
252
+ } else if (wasAnimated) {
253
+ box.sectionViews.forEach(function (view) {
254
+ stopMotion(view.lblArrow);
255
+ stopMotion(view.body);
256
+ });
257
+ stopMotion(box.lblButtonArrow);
258
+ stopMotion(box.panel);
259
+ wasAnimated = 0;
260
+ }
261
+ paintButtonArrow();
262
+ paint();
263
+ };
264
+
265
+ // *** ROWS AND SECTIONS
266
+
267
+ // The look of an option row over the check box params of the page (a style given there wins)
268
+ const getCheckBoxStyle = function () {
269
+ const style = JSON.parse(JSON.stringify(box.checkBoxParams.style || {}));
270
+ mergeIntoIfMissing(style, {
271
+ box: { color: _s.row.color, round: _s.row.round },
272
+ hoverBox: { color: _s.row.hoverColor },
273
+ hoverCheckedBox: { color: _s.row.hoverColor },
274
+ layout: { gap: _s.row.gap, padding: _s.row.padding, align: "left center" },
275
+ checkedMark: { color: _s.accentColor, borderColor: _s.accentColor },
276
+ label: { fontSize: _s.fontSize, textColor: _s.textColor },
277
+ });
278
+ return style;
279
+ };
280
+
281
+ // CHECK BOX: one option of a section; the check box is the row
282
+ const createCheckBoxRow = function (option, checkBoxStyle) {
283
+ const checkBox = CheckBox(Object.assign({}, box.checkBoxParams, {
284
+ width: "100%",
285
+ height: _s.row.height,
286
+ labelText: basic.escapeHtml(option.text), // WHY: the label of a CheckBox is HTML
287
+ checked: option.checked ? 1 : 0,
288
+ animated: (box.checkBoxParams.animated !== undefined) ? box.checkBoxParams.animated : box.animated,
289
+ style: checkBoxStyle,
290
+ onChange: function (self) {
291
+ option.checked = self.checked ? 1 : 0;
292
+ paint();
293
+ box.onChange(box);
294
+ },
295
+ }));
296
+ checkBox.shrink = 0;
297
+ // WHY: the content of a CheckBox stands at its top; it fills the height of the row (its align centers it)
298
+ checkBox.contentBox.height = "100%";
299
+ return { option: option, row: checkBox, checkBox: checkBox };
300
+ };
301
+
302
+ // GROUP: one option of a section without CheckBox: a plain check and its text
303
+ const createPlainRow = function (option) {
304
+ const row = HGroup({ width: "100%", height: _s.row.height, align: "left center", gap: _s.row.gap, padding: _s.row.padding, color: _s.row.color, round: _s.row.round });
305
+ row.shrink = 0;
306
+ row.clickable = 1;
307
+ row.cursor = "pointer";
308
+ row.role = "checkbox";
309
+ row.tabIndex = 0;
310
+ // GROUP: Check box (a mark on the accent when it is checked)
311
+ const check = HGroup({ width: _s.check.size, height: _s.check.size, round: _s.check.round });
312
+ check.shrink = 0;
313
+ const mark = createIcon(Filters.icon("check", MARK_SIZE, 3), _s.check.markColor);
314
+ endGroup();
315
+ Label({ plainText: option.text, fontSize: _s.fontSize, textColor: _s.textColor });
316
+ endGroup();
317
+ const rowView = { option: option, row: row, check: check, mark: mark };
318
+ row.onHoverChange(function (self, isOver) { row.color = (isOver) ? _s.row.hoverColor : _s.row.color; });
319
+ row.on("click", function () { toggleOption(rowView); });
320
+ row.on("keydown", function (self, event) {
321
+ if (event.key !== " " && event.key !== "Enter") return;
322
+ event.preventDefault();
323
+ toggleOption(rowView);
324
+ });
325
+ return rowView;
326
+ };
327
+
328
+ const toggleSection = function (section) {
329
+ box.setSectionOpened(section.key, !section.opened);
330
+ };
331
+
332
+ // GROUP: the title of a section (its name, the number of the checked options, open / closed) and its options
333
+ const createSection = function (section, checkBoxStyle) {
334
+ const view = { section: section, rows: [], isClosing: 0, cancelClose: null };
335
+ view.header = HGroup({ width: "100%", height: _s.header.height, align: "left center", gap: _s.header.gap, padding: _s.header.padding });
336
+ view.header.shrink = 0;
337
+ view.header.clickable = 1;
338
+ view.header.cursor = "pointer";
339
+ view.header.role = "button";
340
+ view.header.tabIndex = 0;
341
+ Label({ plainText: section.text, fontSize: _s.fontSize, textColor: _s.softTextColor });
342
+ view.lblCount = createBadge();
343
+ createSpace();
344
+ view.lblArrow = createIcon("", _s.textColor);
345
+ endGroup();
346
+ view.header.on("click", function () { toggleSection(section); });
347
+ view.header.on("keydown", function (self, event) {
348
+ if (event.key !== " " && event.key !== "Enter") return;
349
+ event.preventDefault();
350
+ toggleSection(section);
351
+ });
352
+ // GROUP: the options (one group: it comes and goes as one)
353
+ view.body = VGroup({ width: "100%", height: "auto", align: "left top", gap: _s.listGap });
354
+ view.body.shrink = 0;
355
+ view.rows = section.options.map(function (option) {
356
+ return (hasCheckBox) ? createCheckBoxRow(option, checkBoxStyle) : createPlainRow(option);
357
+ });
358
+ endGroup();
359
+ return view;
360
+ };
361
+
362
+ // DATA: the sections and their options (made again in the list)
363
+ const createSections = function () {
364
+ if (box.listGroup) box.listGroup.remove();
365
+ const checkBoxStyle = (hasCheckBox) ? getCheckBoxStyle() : null;
366
+ box.listGroup = createIn(box.listBox, function () {
367
+ const group = VGroup({ width: "100%", height: "auto", align: "left top", gap: _s.listGap, position: "relative" });
368
+ box.sectionViews = box.sections.map(function (section) { return createSection(section, checkBoxStyle); });
369
+ box.lblNoResult = Label({ plainText: box.noResultText, fontSize: _s.fontSize, textColor: _s.softTextColor, padding: [12, 12] });
370
+ endGroup();
371
+ return group;
372
+ });
373
+ if (box.lblButtonArrow) setArrowMotions();
374
+ };
375
+
376
+ const paintCheck = function (rowView) {
377
+ const isChecked = rowView.option.checked ? 1 : 0;
378
+ if (rowView.checkBox) {
379
+ if (rowView.checkBox.checked != isChecked) rowView.checkBox.setChecked(isChecked, 1);
380
+ return;
381
+ }
382
+ rowView.check.color = (isChecked) ? _s.accentColor : _s.check.color;
383
+ rowView.mark.visible = isChecked;
384
+ rowView.row.aria = { checked: isChecked ? "true" : "false" };
385
+ };
386
+
387
+ // PAINT: the checks, the counts, the arrows, what the search and the closed sections hide
388
+ const paint = function () {
389
+ let shownCount = 0;
390
+ box.sectionViews.forEach(function (view) {
391
+ const checkedCount = countChecked(view.section);
392
+ view.lblCount.plainText = String(checkedCount);
393
+ view.lblCount.visible = (checkedCount) ? 1 : 0;
394
+ paintArrow(view.lblArrow, view.section.opened);
395
+ view.header.aria = { expanded: view.section.opened ? "true" : "false" };
396
+ let sectionMatches = 0;
397
+ view.rows.forEach(function (rowView) {
398
+ paintCheck(rowView);
399
+ const isMatch = matchesSearch(rowView.option);
400
+ if (isMatch) sectionMatches++;
401
+ rowView.row.visible = (isMatch) ? 1 : 0;
402
+ });
403
+ // WHY: While searching, the matches are shown also in a closed section; a closing one stays until its
404
+ // options are gone.
405
+ const isBodyShown = (view.section.opened || searchText || view.isClosing);
406
+ view.body.visible = (isBodyShown && sectionMatches) ? 1 : 0;
407
+ view.header.visible = (!searchText || sectionMatches) ? 1 : 0;
408
+ shownCount += sectionMatches;
409
+ });
410
+ box.lblNoResult.visible = (searchText && !shownCount) ? 1 : 0;
411
+ const total = box.getSelectedCount();
412
+ box.lblSelectedCount.plainText = String(total);
413
+ box.lblSelectedCount.visible = (total) ? 1 : 0;
414
+ box.lblClear.opacity = (total) ? 1 : 0.4;
415
+ };
416
+
417
+ const toggleOption = function (rowView) {
418
+ rowView.option.checked = rowView.option.checked ? 0 : 1;
419
+ paint();
420
+ box.onChange(box);
421
+ };
422
+
423
+ const findSection = function (sectionKey) {
424
+ return box.sections.find(function (section) { return section.key === sectionKey; }) || null;
425
+ };
426
+
427
+ const findView = function (sectionKey) {
428
+ return box.sectionViews.find(function (view) { return view.section.key === String(sectionKey); }) || null;
429
+ };
430
+
431
+ // The options of a section come (a fade and a short slide)
432
+ const openSection = function (view) {
433
+ if (view.cancelClose) view.cancelClose();
434
+ view.cancelClose = null;
435
+ view.isClosing = 0;
436
+ paint();
437
+ comeIn(view.body, -OPEN_MOVE);
438
+ };
439
+
440
+ // The options of a section go (faster); the section is drawn closed when they are gone. (Its arrow turns at once.)
441
+ const closeSection = function (view) {
442
+ view.isClosing = 1;
443
+ paint();
444
+ goOut(view.body, -OPEN_MOVE);
445
+ view.cancelClose = view.body.after(CLOSE_TIME, function () {
446
+ view.cancelClose = null;
447
+ view.isClosing = 0;
448
+ stopMotion(view.body);
449
+ paint();
450
+ });
451
+ };
452
+
453
+ // *** THE SEARCH FIELD
454
+
455
+ // A SearchInput (comp/search-input.js); without it, a plain field
456
+ const createSearchField = function () {
457
+ if (!hasSearchInput) {
458
+ createPlainSearchField();
459
+ return;
460
+ }
461
+ const searchParams = Object.assign({}, box.searchInputParams);
462
+ searchParams.placeholder = box.searchPlaceholder;
463
+ if (searchParams.animated === undefined) searchParams.animated = box.animated;
464
+ // WHY value, not getSearchText(): that one is in lower case, and the field must keep what is typed
465
+ searchParams.onChange = function () { box.search(box.searchInput.value); };
466
+ box.searchInput = SearchInput(searchParams);
467
+ box.searchInput.shrink = 0;
468
+ };
469
+
470
+ // GROUP: the plain field (without SearchInput): a search icon and an input on a rounded box
471
+ const createPlainSearchField = function () {
472
+ box.searchField = HGroup({ width: "100%", height: _s.field.height, align: "left center", gap: _s.field.gap, padding: _s.field.padding, color: _s.field.color, round: _s.field.round });
473
+ createIcon(Filters.icon("search", ICON_SIZE), _s.softTextColor);
474
+ box.inpSearch = Input({ height: _s.field.height - 10, fontSize: _s.fontSize, textColor: _s.textColor, minimal: 1, color: "transparent", placeholder: box.searchPlaceholder });
475
+ box.inpSearch.grow = 1;
476
+ endGroup();
477
+ box.listenTo(box.inpSearch.inputElement, "input", function () { box.search(box.inpSearch.text); });
478
+ };
479
+
480
+ const getSearchFieldHeight = function () {
481
+ if (box.searchInput) return box.searchInput.height;
482
+ return _s.field.height;
483
+ };
484
+
485
+ // GROUP: the panel: search field, the sections (they scroll), footer
486
+ const createPanel = function () {
487
+
488
+ box.panel = VGroup({
489
+ width: panelWidth,
490
+ height: box.panelHeight,
491
+ align: "left top",
492
+ gap: _s.panel.gap,
493
+ padding: _s.panel.padding,
494
+ color: _s.panel.color,
495
+ round: _s.panel.round,
496
+ border: _s.panel.border,
497
+ borderColor: _s.panel.borderColor,
498
+ boxShadow: _s.panel.shadow,
499
+ });
500
+
501
+ // Search field
502
+ createSearchField();
503
+
504
+ // BOX: The sections (they scroll)
505
+ const listHeight = box.panelHeight - getSearchFieldHeight() - _s.footer.height - _s.panel.padding * 2 - LIST_GAPS;
506
+ box.listBox = startBox(0, 0, "100%", listHeight, { color: "transparent", scrollY: 1 });
507
+ box.listBox.position = "relative";
508
+ endBox();
509
+
510
+ // GROUP: Footer
511
+ box.footer = HGroup({ width: "100%", height: _s.footer.height, align: "left center", gap: _s.footer.gap, padding: _s.footer.padding });
512
+ Label({ plainText: box.selectedText, fontSize: _s.fontSize, textColor: _s.softTextColor });
513
+ box.lblSelectedCount = createBadge();
514
+ createSpace();
515
+ box.lblClear = Label({ plainText: box.clearText, fontSize: _s.fontSize, textColor: _s.accentColor });
516
+ box.lblClear.clickable = 1;
517
+ box.lblClear.cursor = "pointer";
518
+ box.lblClear.role = "button";
519
+ endGroup();
520
+
521
+ endGroup();
522
+
523
+ // WHY: Out of the groups: a ScrollBar made in a group would be a part of its layout. It moves itself over the list.
524
+ if (typeof ScrollBar !== "undefined") box.scrollBar = ScrollBar(Object.assign({ scrollableBox: box.listBox }, _s.scrollBar));
525
+
526
+ };
527
+
528
+ // POPUP: the panel under the button, its right edge at the right edge of the button.
529
+ // Above the button when there is no space below and more space above.
530
+ const placePanel = function () {
531
+ if (!isPopup || !box.panelOpened) return;
532
+ const rect = box.btnFilters.elem.getBoundingClientRect();
533
+ const buttonTop = withPageZoom(rect.top);
534
+ const buttonBottom = withPageZoom(rect.bottom);
535
+ const spaceBelow = page.height - buttonBottom - PANEL_GAP - SCREEN_MARGIN;
536
+ const spaceAbove = buttonTop - PANEL_GAP - SCREEN_MARGIN;
537
+ let top = buttonBottom + PANEL_GAP;
538
+ if (box.panelHeight > spaceBelow && spaceAbove > spaceBelow) top = buttonTop - PANEL_GAP - box.panelHeight;
539
+ const left = withPageZoom(rect.right) - panelWidth;
540
+ box.panel.left = Math.max(SCREEN_MARGIN, Math.min(left, page.width - panelWidth - SCREEN_MARGIN));
541
+ box.panel.top = Math.max(SCREEN_MARGIN, top);
542
+ };
543
+
544
+ // The panel comes from its button: down from it, or up when a popup opens above the button
545
+ const getPanelMove = function () {
546
+ if (!isPopup) return -OPEN_MOVE;
547
+ const buttonTop = withPageZoom(box.btnFilters.elem.getBoundingClientRect().top);
548
+ return (box.panel.top < buttonTop) ? OPEN_MOVE : -OPEN_MOVE;
549
+ };
550
+
551
+ const showPanel = function () {
552
+ if (cancelPanelHide) cancelPanelHide();
553
+ cancelPanelHide = null;
554
+ box.panel.visible = 1;
555
+ placePanel();
556
+ if (isCreated && isMotionOn()) comeIn(box.panel, getPanelMove());
557
+ };
558
+
559
+ const hidePanel = function () {
560
+ if (!isCreated || !isMotionOn()) {
561
+ box.panel.visible = 0;
562
+ return;
563
+ }
564
+ goOut(box.panel, getPanelMove());
565
+ cancelPanelHide = box.panel.after(CLOSE_TIME, function () {
566
+ cancelPanelHide = null;
567
+ box.panel.visible = 0;
568
+ stopMotion(box.panel);
569
+ });
570
+ };
571
+
572
+ const isInside = function (obj, target) {
573
+ return obj.elem.contains(target);
574
+ };
575
+
576
+ const closeOnOutsideClick = function (self, event) {
577
+ if (!box.panelOpened) return;
578
+ if (isInside(box.panel, event.target)) return;
579
+ if (isInside(box.btnFilters, event.target)) return; // WHY: The click of the button toggles it.
580
+ box.closePanel();
581
+ };
582
+
583
+ const closeOnEscape = function (self, event) {
584
+ if (event.key !== "Escape" || !box.panelOpened) return;
585
+ box.closePanel();
586
+ box.btnFilters.elem.focus();
587
+ };
588
+
589
+ // WHY: The page under the panel scrolls (a scrolling box of the page): the panel goes with the button.
590
+ const placeOnScroll = function (self, event) {
591
+ if (isInside(box.panel, event.target)) return;
592
+ placePanel();
593
+ };
594
+
595
+ // The two-tone icon of the button (style.buttonIcon; "": from the accent)
596
+ const getButtonIcon = function () {
597
+ const strongColor = _s.buttonIcon.strongColor || _s.accentColor;
598
+ const lightColor = _s.buttonIcon.lightColor || Filters.lightTone(strongColor);
599
+ return Filters.twoToneIcon("filter", ICON_SIZE, strongColor, lightColor);
600
+ };
601
+
602
+ // *** PUBLIC FUNCTIONS:
603
+
604
+ // { sectionKey: [optionKeys] } of the checked options
605
+ box.getSelected = function () {
606
+ const selected = {};
607
+ box.sections.forEach(function (section) {
608
+ selected[section.key] = section.options.filter(function (option) { return option.checked; }).map(function (option) { return option.key; });
609
+ });
610
+ return selected;
611
+ };
612
+
613
+ box.getSelectedCount = function () {
614
+ return box.sections.reduce(function (sum, section) { return sum + countChecked(section); }, 0);
615
+ };
616
+
617
+ // The checked options of a section (the others are unchecked). silent: 1 -> onChange is not called.
618
+ box.setSelected = function (sectionKey, optionKeys, silent = 0) {
619
+ const section = findSection(sectionKey);
620
+ if (!section) return;
621
+ const keys = (optionKeys || []).map(String);
622
+ section.options.forEach(function (option) { option.checked = (keys.indexOf(option.key) !== -1) ? 1 : 0; });
623
+ paint();
624
+ if (!silent) box.onChange(box);
625
+ };
626
+ // USAGE: filters.setSelected("status", ["online"])
627
+
628
+ box.clearAll = function (silent = 0) {
629
+ if (!box.getSelectedCount()) return;
630
+ box.sections.forEach(function (section) { section.options.forEach(function (option) { option.checked = 0; }); });
631
+ paint();
632
+ if (!silent) box.onChange(box);
633
+ };
634
+
635
+ box.setSectionOpened = function (sectionKey, isOpened) {
636
+ const view = findView(sectionKey);
637
+ if (!view) return;
638
+ const value = (isOpened) ? 1 : 0;
639
+ const isChange = (value !== view.section.opened);
640
+ view.section.opened = value;
641
+ // WHY not while searching: the options of a closed section are shown then too (nothing comes or goes)
642
+ if (!isChange || !isCreated || !isMotionOn() || searchText) {
643
+ paint();
644
+ return;
645
+ }
646
+ if (value) openSection(view);
647
+ else closeSection(view);
648
+ };
649
+
650
+ box.setSections = function (sections) {
651
+ box.sections = Filters.normalizeSections(sections);
652
+ createSections();
653
+ paint();
654
+ };
655
+
656
+ box.search = function (text) {
657
+ const value = String(text || "");
658
+ searchText = value.trim().toLocaleLowerCase();
659
+ if (box.searchInput && box.searchInput.value !== value) box.searchInput.setValue(value, 1);
660
+ if (box.inpSearch && box.inpSearch.text !== value) box.inpSearch.text = value;
661
+ paint();
662
+ };
663
+
664
+ box.openPanel = function () { box.setPanelOpened(1); };
665
+ box.closePanel = function () { box.setPanelOpened(0); };
666
+ box.togglePanel = function () { box.setPanelOpened(!box.panelOpened); };
667
+
668
+ // silent: 1 -> onPanelToggle is not called.
669
+ box.setPanelOpened = function (isOpened, silent = 0) {
670
+ const value = (isOpened) ? 1 : 0;
671
+ if (value === box.panelOpened) return;
672
+ box.panelOpened = value;
673
+ if (value && isPopup) box.panel.zIndex = basic.zIndexAbove(box, PANEL_Z_INDEX); // WHY: over a Dialog that holds the filters
674
+ if (value) showPanel();
675
+ else hidePanel();
676
+ box.btnFilters.aria = { expanded: value ? "true" : "false" };
677
+ paintButtonArrow();
678
+ if (!silent) box.onPanelToggle(box);
679
+ };
680
+
681
+ box.setButtonText = function (text) {
682
+ box.buttonText = text;
683
+ box.lblButton.plainText = text;
684
+ };
685
+
686
+ box.setAnimated = function (value) {
687
+ box.animated = (value == 1) ? 1 : 0;
688
+ applyAnimated();
689
+ };
690
+ // USAGE: filters.setAnimated(1)
691
+
692
+ // *** OBJECT VIEW:
693
+
694
+ // GROUP: Layout (the button at the right; the panel under it in the "inline" mode)
695
+ box.layout = VGroup({ width: (isPopup) ? "auto" : panelWidth, height: "auto", align: "right top", gap: PANEL_GAP, position: "relative" });
696
+ box.clipContent = 0; // WHY: The shadow of the panel stands out of the box and of the layout.
697
+ box.layout.clipContent = 0;
698
+
699
+ // GROUP: Filters button
700
+ box.btnFilters = HGroup({ width: "auto", height: _s.button.height, gap: _s.button.gap, padding: _s.button.padding, color: _s.button.color, round: _s.button.round });
701
+ box.btnFilters.clickable = 1;
702
+ box.btnFilters.cursor = "pointer";
703
+ box.btnFilters.role = "button";
704
+ box.btnFilters.tabIndex = 0;
705
+ createIcon(getButtonIcon(), _s.textColor);
706
+ box.lblButton = Label({ plainText: box.buttonText, fontSize: _s.fontSize, textColor: _s.textColor });
707
+ box.lblButtonArrow = createIcon(Filters.icon("down", ICON_SIZE), _s.textColor);
708
+ endGroup();
709
+
710
+ if (!isPopup) createPanel();
711
+
712
+ endGroup();
713
+
714
+ // POPUP: the panel on the page, over everything (removed with the box: own)
715
+ if (isPopup) {
716
+ createIn(page, createPanel);
717
+ box.panel.zIndex = PANEL_Z_INDEX;
718
+ box.own(box.panel);
719
+ }
720
+
721
+ // *** OBJECT INIT CODE:
722
+
723
+ box.btnFilters.on("click", box.togglePanel);
724
+ box.btnFilters.on("keydown", function (self, event) {
725
+ if (event.key !== "Enter" && event.key !== " ") return;
726
+ event.preventDefault();
727
+ box.togglePanel();
728
+ });
729
+ box.lblClear.on("click", function () { box.clearAll(); });
730
+
731
+ if (isPopup) {
732
+ box.listenTo(document, "pointerdown", closeOnOutsideClick, true);
733
+ box.listenTo(document, "keydown", closeOnEscape);
734
+ box.listenTo(document, "scroll", placeOnScroll, true); // WHY: capture: the scroll of a box does not bubble.
735
+ box.onPageResize(placePanel);
736
+ }
737
+
738
+ createSections();
739
+ box.panelOpened = 0;
740
+ box.panel.visible = 0; // WHY: Hidden after its children are made.
741
+ box.setPanelOpened(params.panelOpened, 1);
742
+ applyAnimated(); // (it paints)
743
+ isCreated = 1;
744
+
745
+ return endObject(box);
746
+
747
+ };
748
+
749
+ // *** STATIC FUNCTIONS:
750
+
751
+ // The sections with every value filled: keys as texts, opened / checked as 1 / 0, a text option -> { key, text }.
752
+ Filters.normalizeSections = function (sections) {
753
+ return (Array.isArray(sections) ? sections : []).map(function (section, index) {
754
+ const options = (Array.isArray(section.options) ? section.options : []).map(function (option) {
755
+ if (typeof option !== "object") return { key: String(option), text: String(option), checked: 0 };
756
+ return { key: String(option.key !== undefined ? option.key : option.text), text: String(option.text || ""), checked: option.checked ? 1 : 0 };
757
+ });
758
+ return { key: String(section.key !== undefined ? section.key : index), text: String(section.text || ""), opened: section.opened ? 1 : 0, options: options };
759
+ });
760
+ };
761
+
762
+ // An icon: lines in the color of its label (currentColor). name: "search", "down", "up", "check"
763
+ Filters.ICON_PATHS = {
764
+ search: '<circle cx="11" cy="11" r="6.5"/><path d="M16 16l4 4"/>',
765
+ down: '<path d="M6 9l6 6 6-6"/>',
766
+ up: '<path d="M6 15l6-6 6 6"/>',
767
+ check: '<path d="M5 12.5l4.5 4.5L19 7.5"/>',
768
+ };
769
+
770
+ Filters.icon = function (name, size, strokeWidth = 2) {
771
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="' + strokeWidth + '" stroke-linecap="round" stroke-linejoin="round">' + Filters.ICON_PATHS[name] + '</svg>';
772
+ };
773
+
774
+ // A two-tone icon (the style of 02-comp-examples/smart-button-alternatif.htm): a big LIGHT shape
775
+ // with STRONG details; the two colors are filled in. name: "filter" (sliders on a light box)
776
+ Filters.TWO_TONE_PATHS = {
777
+ filter: '<rect x="2.5" y="2.5" width="19" height="19" rx="3" fill="LIGHT"/>' +
778
+ '<path d="M7 8.5h10M7 15.5h10" fill="none" stroke="STRONG" stroke-width="2" stroke-linecap="round"/>' +
779
+ '<circle cx="10" cy="8.5" r="2.2" fill="STRONG"/><circle cx="14.5" cy="15.5" r="2.2" fill="STRONG"/>',
780
+ };
781
+
782
+ Filters.twoToneIcon = function (name, size, strongColor, lightColor) {
783
+ const body = Filters.TWO_TONE_PATHS[name].split("STRONG").join(strongColor).split("LIGHT").join(lightColor);
784
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24">' + body + '</svg>';
785
+ };
786
+
787
+ // The light tone of a color for a two-tone icon: a hex color mixed with white; another color made transparent
788
+ Filters.LIGHT_TONE = 0.32; // the part of the color in its light tone
789
+
790
+ Filters.lightTone = function (color) {
791
+ const match = /^#([0-9a-f]{6})$/i.exec(String(color).trim());
792
+ if (!match) return Alpha(color, Filters.LIGHT_TONE);
793
+ const channels = [0, 2, 4].map(function (start) { return parseInt(match[1].substr(start, 2), 16); });
794
+ const mixed = channels.map(function (channel) { return Math.round(channel * Filters.LIGHT_TONE + 255 * (1 - Filters.LIGHT_TONE)); });
795
+ return "#" + mixed.map(function (channel) { return channel.toString(16).padStart(2, "0"); }).join("");
796
+ };
797
+
798
+ // *** STYLE PACKAGES:
799
+ // USAGE: Filters({ styleName: "light" })
800
+ // USAGE: Filters({ style: { accentColor: "#2E7D5B" } }) // Change only some keys.
801
+ // USAGE: Filters.styles.myStyle = { accentColor: "tomato", panel: { color: "white" } };
802
+ Filters.styles = {
803
+
804
+ // The look of the picture: warm grays, white rows, a blue accent.
805
+ light: FiltersDefaults.style,
806
+
807
+ };