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,1740 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ ItemList - v26.11
6
+
7
+ UI COMPONENT TEMPLATE
8
+ - NEW PROJECTS: use styleName "ozden" on a light page (the default: rows that are white with a thin line above
9
+ and under them under the mouse; its search box the ozden SearchInput in white) and "ozdenDark" on a dark page (02-comp-examples/item-list.htm), unless the user asks for
10
+ another look.
11
+ - A list of items: an icon, a title and a description on every row, or your own row (createItemView).
12
+ - Layouts: "vertical" (a list), "horizontal" (one row of tiles: categories, cards) and "grid" (tiles that
13
+ wrap: files, icons, pictures). setLayout() changes it later. style.tile.fitRow: 1: the tiles of a grid share the
14
+ whole row (as many as fit at tile.width, then wider), so no empty end is left before the scroll bar.
15
+ - Selection: "single", "multiple" or "none". The selected keys: getSelectedKeys(), the items: getSelected().
16
+ style.selected.canSelectAgain: 0 (ozden, ozdenDark; light and dark: 1): in a single list the selected row can not
17
+ be chosen again: a click, Enter or Space does nothing (no onItemClick), no look under the mouse, no hand cursor.
18
+ The keys can still go to it (its focus ring; a screen reader reads it as selected).
19
+ onChange(self, selectedItems) is NOT called at create time, by setItems() or with silent: 1.
20
+ - Search box: showSearch: 1 puts a SearchInput (comp/search-input.js, load it first) over the list;
21
+ its look is style.search, more params in searchParams (Ex: the icon paths for your page). box.searchInput.
22
+ - Search: search(text) shows only the matching items (text, description and searchText; Turkish letters are
23
+ matched without their marks: "isik" finds "Işık"). It returns the count of the shown items.
24
+ - Keyboard (a listbox): the arrow keys move the focus (Up / Down in a list, Left / Right in a row, all four in a
25
+ grid), Home / End, PageUp / PageDown (a page of rows), letters (type-ahead: the next item whose text starts with
26
+ them). Enter or Space is a click (onItemClick and the selection). Only one row is in the Tab order: the focused
27
+ one, or the first selected one, or the first one. multiple: Shift + a move, Shift + Space and Shift + click select
28
+ the rows from the last clicked one; Ctrl / Cmd + A selects all the shown items (again: none). With a search box:
29
+ the arrow down goes from it into the list, the arrow up from the first line back to it, Escape clears it.
30
+ - A combobox whose keyboard stays in its field (SelectBox) shows its active row with setActiveKey(key): the look of
31
+ the mouse (style.hover), also on a selected row, and only on that row. null: none.
32
+ - Items: strings or objects { key, text, description, iconFile, searchText, enabled }. Any other keys stay on the
33
+ item for your createItemView. An item without a key gets its index as its key. style.title and style.desc are the
34
+ look of its text and its description.
35
+ - Sections: an item { type: "section", text: "VIEWS" } is a title row between the items (style.section). It is
36
+ never selected, focused, hovered or clicked, the arrow keys skip it, and getSelected(), search() and the empty
37
+ text count only the items. It is shown while at least one item under it (until the next section) is shown: in
38
+ a search, only the sections with a match (a section without items is hidden too).
39
+ ItemList draws it, also with createItemView: createItemView gets only the items (a function written for your
40
+ items does not break on a title). Your own section row: createSectionView(item, row, self).
41
+ getItems() and forEach() give the sections too (item.type === "section").
42
+ - Pressed: style.pressed.color (null: none). A click, Enter or Space paints the row in this color at once, then
43
+ the row fades back to its look with the row motion (style.row.motion).
44
+ - animated: 1 -> addItem() and removeItem() move the other rows to their new places (FLIP: transform), a new row
45
+ fades in from a little higher, a removed row fades out and then leaves (its data and the counts change at once).
46
+ Nothing moves at create time, with setItems() or with a search. Off when the system asks for reduced motion.
47
+ setAnimated(0/1).
48
+ - height: "auto" -> The list grows with its rows (no scrolling). Otherwise it scrolls with basic/scroll-bar.js
49
+ (if it is loaded).
50
+ - Style packages: "ozden" (default; the name "classic" still works), "ozdenDark" (the same on a dark page), "gallery" and
51
+ "galleryDark" (pictures: layout "grid", a big photo on every tile with its title under it),
52
+ "light" and "dark" (the light and dark look of the kit: a white box with one thin line, flat 56 px rows, the
53
+ selected one in a tint of the accent with a full mark: _designs/item-list.htm), "minimal" and "minimalDark"
54
+ (lines, 28 px rows: _designs/minimal-theme.htm).
55
+ Select with styleName. (ItemList.styles)
56
+
57
+ USAGE:
58
+ const list = ItemList({
59
+ width: 360,
60
+ height: 400,
61
+ items: [
62
+ { key: "broccoli", text: "Broccoli", description: "Vegetable", iconFile: "assets/fruids/brokoli.png" },
63
+ { key: "strawberry", text: "Strawberry", description: "Fruit", iconFile: "assets/fruids/cilek.png" },
64
+ ],
65
+ onChange: function (self, selectedItems) { println(self.getSelectedKeys()); },
66
+ });
67
+ list.search("fruit"); // 1 (the count of the shown items)
68
+ list.setSelected(["broccoli"], 1); // silent: onChange is not called
69
+ list.addItem({ key: "tomato", text: "Tomato", description: "Vegetable" });
70
+ list.updateItem("tomato", { description: "Fruit, really" });
71
+ list.setLayout("grid");
72
+ ItemList({ selection: "multiple", styleName: "light" });
73
+ ItemList({ layout: "horizontal", height: 200, styleName: "dark" });
74
+ ItemList({ showSearch: 1, searchParams: { placeholder: "Ara" } });
75
+ ItemList({
76
+ style: { row: { height: "auto" } },
77
+ createItemView: function (item, row, self) { // Objects created here go into the row.
78
+ Label({ plainText: item.text, fontSize: 18 });
79
+ },
80
+ });
81
+ ItemList({ items: [{ type: "section", text: "FRUITS" }, "Apple", "Banana", { type: "section", text: "VEGETABLES" }, "Carrot"] });
82
+ ItemList({ style: { hover: {} } }); // No look under the mouse
83
+ ItemList({ selection: "none", style: { pressed: { color: Black(0.2) }, row: { motion: "background-color 0.3s" } } });
84
+ const animatedList = ItemList({ animated: 1, items: ["A", "B", "C"] });
85
+ animatedList.removeItem("0"); // "A" fades out, then "B" and "C" move up
86
+
87
+ Started Date: October 2026
88
+ Webpage: https://bug7a.github.io/js-components/
89
+
90
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
91
+ Licensed under the Apache License, Version 2.0
92
+ SPDX-License-Identifier: Apache-2.0
93
+
94
+ */
95
+
96
+ "use strict";
97
+
98
+ // Default values:
99
+ const ItemListDefaults = {
100
+ key: "0", // Your name for this object: read it in a callback (self.key)
101
+ width: 600,
102
+ height: 400, // "auto": grows with the rows (no scrolling)
103
+ items: [], // Strings or { key, text, description, iconFile, searchText, enabled }. A title row: { type: "section", text: "VIEWS" }
104
+ layout: "vertical", // "vertical", "horizontal", "grid"
105
+ selection: "single", // "single", "multiple", "none"
106
+ selectedKeys: [], // The keys selected at create time
107
+ scrollToSelected: 1, // 1: the list scrolls to the selected item at create time and after setSelected() / select()
108
+ createItemView: null, // function (item, row, self) { ... } Objects created here go into the row (instead of the icon and texts). Not called for a section.
109
+ createSectionView: null, // function (item, row, self) { ... } Your own section row (instead of its title)
110
+ animated: 0, // 1: addItem / removeItem move the rows (a new row fades in, a removed one fades out). setAnimated(0/1)
111
+ showSearch: 0, // 1: a search box over the list (comp/search-input.js SearchInput must be loaded)
112
+ searchParams: {}, // More params of the SearchInput. Ex: { placeholder: "Ara", searchIconFile: "comp/search-input/search.svg" }
113
+ emptyText: "No items",
114
+ noResultText: "No results",
115
+ enabled: 1,
116
+ useScrollBar: 1, // basic/scroll-bar.js. 0: the scrollbar of the browser.
117
+ ariaLabel: "List",
118
+ onItemClick: function (self, item, index, event) { },
119
+ onChange: function (self, selectedItems) { }, // Not at create time, not by setItems(), not with silent: 1
120
+ styleName: "ozden", // "ozden", "ozdenDark", "light", "dark", "gallery", "galleryDark", "minimal", "minimalDark" or a name added to ItemList.styles
121
+ style: { // The ozden style package (default)
122
+ box: {
123
+ color: "whitesmoke", // WHY: A row is white under the mouse: on a white page a list with no color of its own shows nothing.
124
+ border: 1,
125
+ borderColor: "rgba(20, 20, 20, 0.45)",
126
+ round: 6,
127
+ padding: 0, // Around the rows of the vertical layout
128
+ },
129
+ list: {
130
+ gap: 0, // Between the rows of the vertical layout
131
+ },
132
+ // A row of the vertical layout:
133
+ // as wide as the list, white under the mouse with a thin line above and under it, the selected one half transparent.
134
+ row: {
135
+ height: 80, // "auto": as high as its content (a createItemView)
136
+ padding: [20, 12],
137
+ gap: 15,
138
+ color: "transparent",
139
+ border: 0,
140
+ borderColor: "transparent",
141
+ round: 0,
142
+ opacity: 1,
143
+ boxShadow: "",
144
+ lineColor: "", // A line at the top and at the bottom of the row (1 px, inside it: no row moves). "": none
145
+ motion: "background-color 0.2s, box-shadow 0.2s", // WHY: box-shadow: the lines come and go with the color.
146
+ },
147
+ // An item of the horizontal and grid layouts: the icon on top, the texts under it
148
+ // (the category items of the home page of the template)
149
+ tile: {
150
+ width: 125,
151
+ height: 190, // "auto": as high as its content
152
+ padding: [4, 30],
153
+ gap: 15,
154
+ spacing: 4, // Between the tiles
155
+ listPadding: [12, 5], // Around the tiles
156
+ fitRow: 0, // 1 (layout "grid"): the tiles share a row: as many as fit at their width, then wider: no empty end
157
+ iconSize: 70,
158
+ frameSize: 90, // A circle behind the icon. 0: no circle
159
+ frameColor: White(0.3),
160
+ frameRound: 100,
161
+ iconFilter: "grayscale(100%)", // "": none
162
+ iconFit: "", // How a picture fills its square: "cover" (a photo), "contain". "": as the Icon does
163
+ iconMotion: "transform 0.3s",
164
+ hover: {}, // The look under the mouse (the rows use style.hover)
165
+ selectedColor: "white", // "": the color of style.selected (the rows)
166
+ selectedFrameColor: "transparent",
167
+ selectedIconScale: 1.5,
168
+ selectedIconFilter: "grayscale(30%)",
169
+ selectedFontFamily: "opensans-bold", // "": the font does not change
170
+ },
171
+ // A section: an item { type: "section", text: "VIEWS" }, a title between the items
172
+ section: {
173
+ height: "auto",
174
+ padding: [20, 8],
175
+ fontSize: 16,
176
+ fontFamily: "opensans-bold",
177
+ textColor: Black(0.4),
178
+ },
179
+ // A state: only the keys that change
180
+ hover: { color: "white", lineColor: Black(0.2) }, // style: { hover: {} }: no look under the mouse.
181
+ pressed: { color: null }, // A click, Enter or Space: this color at once, then it fades back (style.row.motion). null: none
182
+ // WHY: a selected row does not get the white and its lines under the mouse.
183
+ // canSelectAgain 0 (single, as SelectBox ozden): it can not be
184
+ // chosen again: a click, Enter or Space does nothing (no onItemClick), no look under the mouse, no hand.
185
+ selected: { color: "transparent", lineColor: "", opacity: 0.5, canSelectAgain: 0 },
186
+ disabled: { opacity: 0.4 },
187
+ focus: { ringColor: "rgba(55, 56, 54, 0.5)" }, // The ring of the keyboard focus
188
+ icon: { size: 50, round: 4, color: "transparent" },
189
+ title: { fontSize: 20, textColor: "rgba(0, 0, 0, 0.8)", fontFamily: "", selectedTextColor: "" },
190
+ desc: { fontSize: 14, textColor: "gray", marginTop: -4 }, // WHY -4: the title and the description overlap a little.
191
+ check: { visible: 0, size: 22, color: "#373836", iconColor: "white", borderColor: Black(0.25) }, // A mark on the selected rows
192
+ empty: { fontSize: 16, textColor: Black(0.4) },
193
+ // The search box (showSearch: 1): the params of SearchInput: its ozden package (its font and icon sizes, its
194
+ // icons, its bottom line), white, nearly square and without a border, 44 px high (ozdenDark takes it too).
195
+ search: {
196
+ styleName: "ozden", // A package of SearchInput.styles
197
+ height: 44,
198
+ padding: [0, 0, 0, 0], // left, top, right, bottom: 0, as wide as the list
199
+ color: "white",
200
+ border: 0, // WHY: the list has its own border: only the bottom line of the package
201
+ round: 2,
202
+ },
203
+ scrollBar: {
204
+ bar_border: 0,
205
+ bar_round: 3,
206
+ bar_borderColor: "rgba(0, 0, 0, 1)",
207
+ bar_width: 4,
208
+ bar_mouseOverWidth: 4,
209
+ bar_mouseOverColor: "#373836",
210
+ bar_opacity: 0.4,
211
+ bar_mouseOverOpacity: 0.9,
212
+ bar_padding: 2,
213
+ bar_color: "#373836",
214
+ neverHide: 1,
215
+ showDots: 1,
216
+ },
217
+ },
218
+ };
219
+
220
+ const ItemList = function (params = {}) {
221
+
222
+ // WHY read first: the merges below would fill an empty hover with the color of the package.
223
+ const givenHover = params.style && params.style.hover;
224
+ const isHoverOff = !!givenHover && Object.keys(givenHover).length === 0;
225
+
226
+ // Merge style package: params.style > ItemList.styles[styleName] > ItemListDefaults.style (ozden)
227
+ basic.applyStylePackage(params, ItemList.styles, ItemListDefaults);
228
+
229
+ // Merge params:
230
+ mergeIntoIfMissing(params, ItemListDefaults);
231
+ if (isHoverOff) params.style.hover = {};
232
+
233
+ // Edit params, if needed:
234
+ const startItems = Array.isArray(params.items) ? params.items.slice() : []; // WHY: A copy: the array of the caller does not change.
235
+ const startKeys = Array.isArray(params.selectedKeys) ? params.selectedKeys.slice() : [];
236
+ const isAutoHeight = (params.height === "auto"); // WHY: Read before startObject: box.height gives the measured height.
237
+
238
+ // BOX: Component container
239
+ let box = startObject(params);
240
+
241
+ // *** PRIVATE VARIABLES:
242
+ const _s = box.style;
243
+ let entries = []; // { key, item, data, row, isShown, isHover, isSection, isPressed, isLeaving }
244
+ let removedEntries = []; // animated: the removed items whose rows still fade out (they leave after the motion)
245
+ let selectedKeys = []; // Strings, in the order they were selected
246
+ let focusedKey = null;
247
+ let activeKey = null; // The active row of a combobox (setActiveKey)
248
+ let anchorKey = null; // multiple: a Shift range starts at this row (the last click, Enter or Space without Shift)
249
+ let rangeBaseKeys = []; // multiple: the selection at that time (a Shift range is added to it)
250
+ let typedText = ""; // Type-ahead: the letters typed one after the other
251
+ let cancelTypedText = null;
252
+ let searchText = "";
253
+ let wasAnimated = 0;
254
+ const EMPTY_TEXT_TOP = 24; // The "No results" text under the top of the list
255
+ const PRESS_HOLD_TIME = 50; // ms: the pressed color stays this long, then it fades back with the row motion
256
+ const TYPE_AHEAD_TIME = 600; // ms: the letters typed in this time make one word
257
+
258
+ // animated: 1
259
+ const MOTION_TIME = 0.25; // s
260
+ const MOTION_MS = MOTION_TIME * 1000;
261
+ const MOTION_EASE = "cubic-bezier(0.2, 0.8, 0.2, 1)"; // a fast start and a soft stop
262
+ const FADE_MOTION = "opacity " + MOTION_TIME + "s " + MOTION_EASE;
263
+ const MOVE_MOTION = "transform " + MOTION_TIME + "s " + MOTION_EASE;
264
+ const COMING_ROW_SHIFT = 6; // px: a new row comes from a little higher
265
+
266
+ // *** PUBLIC VARIABLES:
267
+ // NOTE: Default values are also public variables. (box.layout, box.selection, box.enabled...)
268
+
269
+ // *** PRIVATE FUNCTIONS:
270
+
271
+ const LAYOUTS = ["vertical", "horizontal", "grid"];
272
+
273
+ // WHY: An unknown layout was drawn as a list but the arrow keys moved like in a grid.
274
+ const normalizeLayout = function (layout) {
275
+ if (LAYOUTS.includes(layout)) return layout;
276
+ console.warn("ItemList: unknown layout \"" + layout + "\", \"vertical\" is used.");
277
+ return "vertical";
278
+ };
279
+
280
+ const isTileLayout = function () {
281
+ return box.layout === "horizontal" || box.layout === "grid";
282
+ };
283
+
284
+ const toItemObject = function (item) {
285
+ if (typeof item === "string") return { text: item };
286
+ return item || {};
287
+ };
288
+
289
+ // An item { type: "section" } is a title row between the items.
290
+ const isSectionData = function (data) {
291
+ return (data.type === "section") ? 1 : 0;
292
+ };
293
+
294
+ const toEntry = function (item, index) {
295
+ const object = toItemObject(item);
296
+ const key = (object.key !== undefined && object.key !== null) ? String(object.key) : String(index);
297
+ return { key: key, item: item, data: object, row: null, isShown: 1, isHover: 0, isSection: isSectionData(object) };
298
+ };
299
+
300
+ const findEntry = function (key) {
301
+ return entries.find(function (e) { return e.key === String(key); }) || null;
302
+ };
303
+
304
+ const indexOf = function (entry) {
305
+ return entries.indexOf(entry);
306
+ };
307
+
308
+ const isSelected = function (entry) {
309
+ return selectedKeys.includes(entry.key);
310
+ };
311
+
312
+ const isEntryEnabled = function (entry) {
313
+ return box.enabled == 1 && (entry.data.enabled === undefined || basic.isOn(entry.data.enabled));
314
+ };
315
+
316
+ // single, style.selected.canSelectAgain: 0 (ozden): the selected row can not be chosen again.
317
+ const isLockedEntry = function (entry) {
318
+ return box.selection === "single" && _s.selected.canSelectAgain == 0 && isSelected(entry);
319
+ };
320
+
321
+ // A row a click, Enter or Space chooses: enabled, not the locked selected one.
322
+ const isEntryChoosable = function (entry) {
323
+ return isEntryEnabled(entry) && !isLockedEntry(entry);
324
+ };
325
+
326
+ const getSelectedItems = function () {
327
+ return selectedKeys.map(findEntry).filter(Boolean).map(function (e) { return e.item; });
328
+ };
329
+
330
+ // The items (not the sections)
331
+ const getItemEntries = function () {
332
+ return entries.filter(function (e) { return !e.isSection; });
333
+ };
334
+
335
+ // *** SEARCH
336
+
337
+ // "Işık" and "isik" are the same for the search.
338
+ const normalizeText = function (text) {
339
+ return String(text || "")
340
+ .toLocaleLowerCase("tr")
341
+ .replace(/i̇/g, "i")
342
+ .replace(/ı/g, "i")
343
+ .replace(/ç/g, "c")
344
+ .replace(/ğ/g, "g")
345
+ .replace(/ş/g, "s")
346
+ .replace(/ü/g, "u")
347
+ .replace(/ö/g, "o");
348
+ };
349
+
350
+ const getSearchableText = function (entry) {
351
+ const data = entry.data;
352
+ return normalizeText([data.text, data.description, data.searchText].join(" "));
353
+ };
354
+
355
+ const isMatch = function (entry) {
356
+ if (!searchText) return 1;
357
+ return getSearchableText(entry).includes(searchText) ? 1 : 0;
358
+ };
359
+
360
+ // Which rows are shown: the items that match the search, and a section while an item under it is shown.
361
+ const computeShown = function () {
362
+ let section = null;
363
+ entries.forEach(function (e) {
364
+ if (e.isSection) {
365
+ section = e;
366
+ e.isShown = 0;
367
+ return;
368
+ }
369
+ e.isShown = isMatch(e);
370
+ if (e.isShown && section) section.isShown = 1;
371
+ });
372
+ };
373
+
374
+ // *** DRAWING
375
+
376
+ // The colors of a row in its state. A tile has its own hover and selected color (style.tile).
377
+ const getLook = function (entry, isOn) {
378
+ const isTile = entry.row.isTile;
379
+ const hoverLook = isTile ? _s.tile.hover : _s.hover;
380
+ const selectedLook = isTile ? { color: _s.tile.selectedColor || _s.selected.color, borderColor: _s.selected.borderColor } : _s.selected;
381
+ // WHY: The active row takes the look of the mouse after the selection: the keyboard sees it on a selected row too.
382
+ // WHY: The locked selected row gets no look of the mouse (canSelectAgain: 0).
383
+ const isLocked = isLockedEntry(entry);
384
+ const activeLook = (entry.key === activeKey && !isLocked) ? hoverLook : {};
385
+ const mouseLook = (entry.isHover && !isLocked) ? hoverLook : {};
386
+ const look = Object.assign({}, _s.row, mouseLook, isOn ? selectedLook : {}, activeLook);
387
+ if (look.opacity === undefined) look.opacity = 1;
388
+ // WHY: In the look, not only in the click: a paint of the selection or of the mouse keeps the pressed color.
389
+ if (entry.isPressed && _s.pressed.color) look.color = _s.pressed.color;
390
+ return look;
391
+ };
392
+
393
+ // The look of the state of one row: normal, hover, pressed, selected, disabled.
394
+ const paintRow = function (entry) {
395
+ const row = entry.row;
396
+ // WHY: A section has no state; a row that fades out keeps fading.
397
+ if (!row || entry.isSection || entry.isLeaving) return;
398
+ const isOn = isSelected(entry);
399
+ const look = getLook(entry, isOn);
400
+
401
+ row.color = look.color;
402
+ row.borderColor = look.borderColor;
403
+ paintLines(row, look.lineColor || "");
404
+ row.cursor = isEntryChoosable(entry) ? "pointer" : "default";
405
+ row.css.opacity = String(isEntryEnabled(entry) ? look.opacity : _s.disabled.opacity);
406
+ row.aria = { selected: isOn ? "true" : "false", disabled: isEntryEnabled(entry) ? "false" : "true" };
407
+
408
+ if (row.lblTitle) row.lblTitle.textColor = (isOn && _s.title.selectedTextColor) ? _s.title.selectedTextColor : _s.title.textColor;
409
+ if (row.check) paintCheck(row.check, isOn);
410
+ if (row.isTile) paintTile(row, isOn);
411
+ };
412
+
413
+ // The lines at the top and at the bottom of a row (look.lineColor): inset shadows, so no row moves.
414
+ // WHY: Only when the lines change: the own shadow of a row (style.row.boxShadow, or one set by createItemView)
415
+ // stays under them, and a package without lines never touches it.
416
+ const paintLines = function (row, lineColor) {
417
+ const shownLineColor = row.shownLineColor || "";
418
+ if (lineColor === shownLineColor) return;
419
+ if (!shownLineColor) row.ownShadow = row.boxShadow;
420
+ row.shownLineColor = lineColor;
421
+ const shadows = [];
422
+ if (lineColor) shadows.push("inset 0 1px 0 " + lineColor, "inset 0 -1px 0 " + lineColor);
423
+ if (row.ownShadow) shadows.push(row.ownShadow);
424
+ row.boxShadow = shadows.join(", ");
425
+ };
426
+
427
+ // The effects of a selected tile: the circle goes, the icon grows and gets its colors, the title is bold.
428
+ const paintTile = function (row, isOn) {
429
+ const tile = _s.tile;
430
+ if (row.iconFrame) row.iconFrame.color = isOn ? tile.selectedFrameColor : tile.frameColor;
431
+ if (row.icon) {
432
+ row.icon.css.filter = (isOn ? tile.selectedIconFilter : tile.iconFilter) || "none";
433
+ row.icon.css.transform = "scale(" + (isOn ? tile.selectedIconScale : 1) + ")";
434
+ }
435
+ if (row.lblTitle && tile.selectedFontFamily) {
436
+ row.lblTitle.fontFamily = isOn ? tile.selectedFontFamily : (_s.title.fontFamily || "opensans");
437
+ }
438
+ };
439
+
440
+ const paintCheck = function (check, isOn) {
441
+ check.color = isOn ? _s.check.color : "transparent";
442
+ check.borderColor = isOn ? _s.check.color : _s.check.borderColor;
443
+ check.text = isOn ? ItemList.getCheckSvg(_s.check.iconColor, _s.check.size * 0.6) : "";
444
+ };
445
+
446
+ const paintAll = function () {
447
+ entries.forEach(paintRow);
448
+ };
449
+
450
+ // The row of the Tab order: the focused one, or else the first selected shown one, or else the first shown one.
451
+ // WHY: A listbox is entered at its selection, not always at its top.
452
+ const getTabEntry = function () {
453
+ const focused = findEntry(focusedKey);
454
+ if (focused && focused.isShown) return focused;
455
+ const shown = getShownEntries();
456
+ return shown.find(isSelected) || shown[0] || null;
457
+ };
458
+
459
+ // Only one row is in the Tab order (getTabEntry).
460
+ const refreshTabOrder = function () {
461
+ const tabEntry = getTabEntry();
462
+ entries.forEach(function (e) {
463
+ // WHY: A section gets no tabIndex: even a click does not focus it.
464
+ if (!e.row || e.isSection) return;
465
+ e.row.tabIndex = (box.enabled == 1 && e === tabEntry) ? 0 : -1;
466
+ });
467
+ };
468
+
469
+ const createIcon = function (entry, size) {
470
+ if (!entry.data.iconFile) return null;
471
+ const icon = Icon({ width: size, height: size, color: _s.icon.color, round: _s.icon.round, position: "relative" });
472
+ icon.shrink = 0;
473
+ icon.load(entry.data.iconFile);
474
+ return icon;
475
+ };
476
+
477
+ const fitTileIcon = function (row) {
478
+ if (row.icon && _s.tile.iconFit) row.icon.imageFit = _s.tile.iconFit;
479
+ };
480
+
481
+ // A tile icon may sit in a circle (style.tile.frameSize).
482
+ const createTileIcon = function (row, entry) {
483
+ const tile = _s.tile;
484
+ if (!entry.data.iconFile) return;
485
+ if (!(tile.frameSize > 0)) {
486
+ row.icon = createIcon(entry, tile.iconSize);
487
+ fitTileIcon(row);
488
+ return;
489
+ }
490
+ // GROUP: The circle behind the icon
491
+ row.iconFrame = HGroup({ width: tile.frameSize, height: tile.frameSize, align: "center center", round: tile.frameRound, color: tile.frameColor });
492
+ row.iconFrame.position = "relative";
493
+ row.iconFrame.shrink = 0;
494
+ row.iconFrame.clipContent = 0; // WHY: The selected icon grows out of the circle.
495
+ row.iconFrame.setMotion("background-color 0.3s");
496
+ row.icon = createIcon(entry, tile.iconSize);
497
+ fitTileIcon(row);
498
+ endGroup();
499
+ };
500
+
501
+ const createTexts = function (row, entry, isTile) {
502
+ // GROUP: Title and description
503
+ row.texts = VGroup({ width: isTile ? "100%" : "auto", height: "auto", align: isTile ? "center top" : "left center", gap: 0 });
504
+ row.texts.css = { flex: isTile ? "" : "1 1 0", minWidth: "0", alignItems: "stretch" };
505
+
506
+ row.lblTitle = Label({ plainText: entry.data.text || "", width: "100%", fontSize: _s.title.fontSize, ellipsis: 1 });
507
+ if (_s.title.fontFamily) row.lblTitle.fontFamily = _s.title.fontFamily;
508
+
509
+ if (entry.data.description) {
510
+ row.lblDesc = Label({ plainText: entry.data.description, width: "100%", fontSize: _s.desc.fontSize, textColor: _s.desc.textColor, ellipsis: 1 });
511
+ row.lblDesc.css.marginTop = (_s.desc.marginTop || 0) + "px";
512
+ }
513
+
514
+ if (isTile) {
515
+ row.lblTitle.css.textAlign = "center";
516
+ if (row.lblDesc) row.lblDesc.css.textAlign = "center";
517
+ }
518
+
519
+ endGroup();
520
+ };
521
+
522
+ const createCheck = function (row, isTile) {
523
+ if (!basic.isOn(_s.check.visible) || box.selection === "none") return;
524
+ const size = _s.check.size;
525
+ row.check = Label({ width: size, height: size, round: 100, border: 2, text: "" });
526
+ row.check.shrink = 0;
527
+ row.check.css = { display: "flex", alignItems: "center", justifyContent: "center" };
528
+ row.check.aria = { hidden: "true" };
529
+ if (isTile) {
530
+ // WHY: A tile has no room at its side: the mark sits on its top right corner.
531
+ row.check.position = "absolute";
532
+ row.check.top = 6;
533
+ row.check.right = 6;
534
+ }
535
+ };
536
+
537
+ const createRowContent = function (row, entry, isTile) {
538
+ if (typeof box.createItemView === "function") {
539
+ box.createItemView(entry.item, row, box);
540
+ return;
541
+ }
542
+ if (isTile) createTileIcon(row, entry);
543
+ else row.icon = createIcon(entry, _s.icon.size);
544
+ createTexts(row, entry, isTile);
545
+ };
546
+
547
+ const isFitRowGrid = function () {
548
+ return box.layout === "grid" && basic.isOn(_s.tile.fitRow);
549
+ };
550
+
551
+ const createRowBox = function (isTile) {
552
+ if (isTile) {
553
+ // WHY "auto": a cell of the grid of fitRow gives the width (createListGroup)
554
+ const width = isFitRowGrid() ? "auto" : _s.tile.width;
555
+ return VGroup({ width: width, height: _s.tile.height, align: "center top", gap: _s.tile.gap, padding: _s.tile.padding });
556
+ }
557
+ return HGroup({ width: "100%", height: _s.row.height, align: "left center", gap: _s.row.gap, padding: _s.row.padding });
558
+ };
559
+
560
+ // The row of an item: an icon and its texts, or your own objects (createItemView).
561
+ const createItemRow = function (entry) {
562
+ const isTile = isTileLayout();
563
+
564
+ // GROUP: Row
565
+ const row = createRowBox(isTile);
566
+ row.isTile = isTile ? 1 : 0;
567
+ row.position = "relative";
568
+ row.shrink = 0;
569
+ row.round = _s.row.round;
570
+ row.border = _s.row.border;
571
+ row.clickable = 1;
572
+ row.clipContent = 0; // WHY: The focus ring is drawn on the edge of the row.
573
+ if (_s.row.boxShadow) row.boxShadow = _s.row.boxShadow;
574
+ setStartMotion(row, entry);
575
+ row.role = "option";
576
+ row.aria = { label: entry.data.text || entry.key };
577
+ row.setFocusRing(_s.focus.ringColor);
578
+
579
+ createRowContent(row, entry, isTile);
580
+ createCheck(row, isTile);
581
+
582
+ endGroup();
583
+ return row;
584
+ };
585
+
586
+ // A section: its title (style.section) or your own objects (createSectionView). It has no events: it is never
587
+ // selected, hovered or clicked.
588
+ const createSectionRow = function (entry) {
589
+ const section = _s.section;
590
+ // WHY: A whole line in a list and in a grid; in one row of tiles (horizontal), a title before its tiles.
591
+ const width = (box.layout === "horizontal") ? "auto" : "100%";
592
+
593
+ // GROUP: Section
594
+ const row = HGroup({ width: width, height: section.height, align: "left center", padding: section.padding });
595
+ row.position = "relative";
596
+ row.shrink = 0;
597
+ row.role = "presentation";
598
+ setStartMotion(row, entry);
599
+
600
+ if (typeof box.createSectionView === "function") {
601
+ box.createSectionView(entry.item, row, box);
602
+ } else {
603
+ row.lblTitle = Label({ plainText: entry.data.text || "", width: width, fontSize: section.fontSize, textColor: section.textColor, ellipsis: 1 });
604
+ if (section.fontFamily) row.lblTitle.fontFamily = section.fontFamily;
605
+ }
606
+
607
+ endGroup();
608
+ return row;
609
+ };
610
+
611
+ // WHY: setMotion() waits a moment: the first paint (a row selected at create time) does not move.
612
+ // Before createItemView, so a row motion set there wins.
613
+ const setStartMotion = function (row, entry) {
614
+ const motion = getRowMotion(entry, "rest");
615
+ if (motion) row.setMotion(motion);
616
+ };
617
+
618
+ const createRow = function (entry) {
619
+ entry.isHover = 0; // WHY: A new row is not under the mouse yet (its mouseleave would never come).
620
+ if (entry.isSection) {
621
+ entry.row = createSectionRow(entry);
622
+ return entry.row;
623
+ }
624
+ const row = createItemRow(entry);
625
+ entry.row = row;
626
+ bindRowEvents(entry);
627
+ paintRow(entry);
628
+ // WHY: The motion is set after the first paint: a tile selected at create time does not grow in front of the user.
629
+ if (row.isTile && row.icon && _s.tile.iconMotion) row.icon.setMotion(_s.tile.iconMotion);
630
+ return row;
631
+ };
632
+
633
+ const bindRowEvents = function (entry) {
634
+ const row = entry.row;
635
+ row.on("click", function (self, event) {
636
+ // WHY: A removed row that still fades out is not clicked (a button made in it by createItemView).
637
+ if (entry.isLeaving) return;
638
+ activateEntry(entry, event);
639
+ });
640
+ row.onHoverChange(function (self, isOver) {
641
+ entry.isHover = (isOver && isEntryEnabled(entry)) ? 1 : 0;
642
+ paintRow(entry);
643
+ });
644
+ row.on("keydown", function (self, event) {
645
+ onRowKeyDown(entry, event);
646
+ });
647
+ };
648
+
649
+ const createListGroup = function () {
650
+ if (box.layout === "horizontal") {
651
+ const group = HGroup({ width: "auto", height: "auto", align: "left top", gap: _s.tile.spacing, padding: _s.tile.listPadding });
652
+ group.css.width = "max-content"; // WHY: A flex group with width "auto" in a scrolling Box does not grow with its children.
653
+ return group;
654
+ }
655
+ if (box.layout === "grid") {
656
+ const grid = HGroup({ width: "100%", height: "auto", align: "left top", gap: _s.tile.spacing, padding: _s.tile.listPadding, wrap: 1 });
657
+ // tile.fitRow: columns of tile.width at least that fill the row (the browser counts them at every width)
658
+ if (isFitRowGrid()) grid.css = { display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(" + _s.tile.width + "px, 1fr))" };
659
+ return grid;
660
+ }
661
+ const group = VGroup({ width: "100%", height: "auto", align: "left top", gap: _s.list.gap, padding: _s.box.padding });
662
+ group.css.alignItems = "stretch";
663
+ return group;
664
+ };
665
+
666
+ const refreshScrollBar = function () {
667
+ if (box.scrollBar) box.scrollBar.refreshScroll();
668
+ };
669
+
670
+ // Shows "No items" / "No results" when no item is shown. (The sections are not counted.)
671
+ const refreshEmptyText = function () {
672
+ const shownCount = getShownEntries().length;
673
+ box.lblEmpty.visible = (shownCount === 0) ? 1 : 0;
674
+ box.lblEmpty.plainText = (getItemEntries().length === 0) ? box.emptyText : box.noResultText;
675
+ refreshScrollBar();
676
+ };
677
+
678
+ // Shows or hides a row by its isShown. withMotion (an animated addItem / removeItem): a row that goes (a section
679
+ // without a shown item) fades out first; a row that comes is faded in by playRowMoves().
680
+ const showRow = function (entry, withMotion) {
681
+ if (entry.isShown) {
682
+ if (entry.isLeaving) stopLeave(entry);
683
+ entry.row.visible = 1;
684
+ return;
685
+ }
686
+ if (withMotion && entry.row.visible == 1) {
687
+ if (!entry.isLeaving) fadeOutRow(entry, hideFadedRow);
688
+ return;
689
+ }
690
+ if (entry.isLeaving) stopLeave(entry);
691
+ entry.row.visible = 0;
692
+ };
693
+
694
+ const applySearch = function (withMotion = false) {
695
+ computeShown();
696
+ entries.forEach(function (e) {
697
+ if (e.row) showRow(e, withMotion);
698
+ });
699
+ refreshTabOrder();
700
+ refreshEmptyText();
701
+ };
702
+
703
+ // Draws all the rows again (setItems, setLayout).
704
+ const createRows = function () {
705
+ if (box.wrapper) box.wrapper.remove();
706
+ removedEntries = []; // WHY: Their rows go with the old group (their timers find them removed).
707
+ const host = isAutoHeight ? box : box.scrollBox;
708
+ createIn(host, function () {
709
+ // GROUP: Rows
710
+ box.wrapper = createListGroup();
711
+ box.wrapper.position = "relative"; // WHY: The scroll box (or the auto height box) grows with it.
712
+ box.wrapper.css.boxSizing = "border-box";
713
+ box.wrapper.clipContent = 0;
714
+ box.wrapper.role = "listbox";
715
+ box.wrapper.aria = {
716
+ label: box.ariaLabel,
717
+ multiselectable: (box.selection === "multiple") ? "true" : "false",
718
+ orientation: (box.layout === "horizontal") ? "horizontal" : null, // (the default of a listbox: vertical)
719
+ };
720
+ entries.forEach(createRow);
721
+ endGroup();
722
+ });
723
+ applySearch();
724
+ };
725
+
726
+ const refreshScrollAxes = function () {
727
+ if (isAutoHeight) return;
728
+ const isHorizontal = (box.layout === "horizontal");
729
+ box.scrollBox.scrollX = isHorizontal ? 1 : 0;
730
+ box.scrollBox.scrollY = isHorizontal ? 0 : 1;
731
+ };
732
+
733
+ // *** PRESSED (style.pressed.color)
734
+
735
+ // A click, Enter or Space: the row gets the pressed color at once, then it fades back to its look (the row motion).
736
+ const flashRow = function (entry) {
737
+ if (!_s.pressed.color) return;
738
+ if (entry.cancelFlash) entry.cancelFlash();
739
+ entry.isPressed = 1;
740
+ setRowMotion(entry, "rest");
741
+ paintRow(entry);
742
+ entry.cancelFlash = box.after(PRESS_HOLD_TIME, function () {
743
+ entry.cancelFlash = null;
744
+ entry.isPressed = 0;
745
+ if (entry.row.isRemoved) return;
746
+ setRowMotion(entry, "rest");
747
+ paintRow(entry);
748
+ });
749
+ };
750
+
751
+ // *** MOTION (animated: 1)
752
+
753
+ // WHY: A user who asked the system for less motion gets still rows.
754
+ const isMotionOn = function () {
755
+ if (box.animated != 1) return false;
756
+ const reduceMotion = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
757
+ return !reduceMotion;
758
+ };
759
+
760
+ // The transition of a row: the motion of its look (style.row.motion) and, when animated, its fade and its move.
761
+ // mode: "rest" (all of them), "placing" (no move: the row jumps to its start place), "still" (no fade, no move).
762
+ // WHY: A pressed row has no motion of its look: the pressed color comes at once.
763
+ const getRowMotion = function (entry, mode) {
764
+ const parts = [];
765
+ if (_s.row.motion && !entry.isSection && !entry.isPressed) parts.push(_s.row.motion);
766
+ if (isMotionOn() && mode !== "still") parts.push(FADE_MOTION);
767
+ if (isMotionOn() && mode === "rest") parts.push(MOVE_MOTION);
768
+ return parts.join(", ");
769
+ };
770
+
771
+ const setRowMotion = function (entry, mode) {
772
+ entry.row.setMotionNow(getRowMotion(entry, mode));
773
+ };
774
+
775
+ // How far the list is scrolled. (An "auto" height list does not scroll in itself.)
776
+ const getScroll = function () {
777
+ if (!box.scrollBox) return { left: 0, top: 0 };
778
+ return { left: box.scrollBox.elem.scrollLeft, top: box.scrollBox.elem.scrollTop };
779
+ };
780
+
781
+ // The place of a row in the list without its move: its place in the layout, minus the scroll.
782
+ // WHY: Not getBoundingClientRect(): a page zoomed by page.fit() is scaled, the moves would be too short or long.
783
+ const getLayoutPlace = function (entry) {
784
+ const scroll = getScroll();
785
+ return { left: entry.row.elem.offsetLeft - scroll.left, top: entry.row.elem.offsetTop - scroll.top };
786
+ };
787
+
788
+ // Where a row is seen now: its layout place and the part of its move that has not ended yet (transform).
789
+ const getSeenPlace = function (entry) {
790
+ const place = getLayoutPlace(entry);
791
+ const move = new DOMMatrixReadOnly(getComputedStyle(entry.row.elem).transform);
792
+ return { left: place.left + move.m41, top: place.top + move.m42 };
793
+ };
794
+
795
+ // The transform that puts a row back where it was seen. "": it has not moved.
796
+ const getMoveBack = function (first, last) {
797
+ const x = first.left - last.left;
798
+ const y = first.top - last.top;
799
+ if (x === 0 && y === 0) return "";
800
+ return "translate(" + x + "px, " + y + "px)";
801
+ };
802
+
803
+ // The rows on the screen: the shown ones and the ones that still fade out.
804
+ const getDisplayedEntries = function () {
805
+ return entries.concat(removedEntries).filter(function (e) {
806
+ return e.row && !e.row.isRemoved && e.row.visible == 1;
807
+ });
808
+ };
809
+
810
+ // FLIP, first: where every row on the screen is seen before a change. null: no motion.
811
+ const measureRows = function () {
812
+ if (!isMotionOn() || !box.wrapper) return null;
813
+ const places = new Map();
814
+ getDisplayedEntries().forEach(function (e) { places.set(e, getSeenPlace(e)); });
815
+ return places;
816
+ };
817
+
818
+ // The rest look of a row: the opacity of its state (an item) or 1 (a section).
819
+ const showRowLook = function (entry) {
820
+ entry.row.css.opacity = "";
821
+ paintRow(entry);
822
+ };
823
+
824
+ // FLIP, after a change: every row jumps back to where it was seen (no motion), then moves to its new place.
825
+ // A row that was not on the screen comes: it fades in from a little higher.
826
+ const playRowMoves = function (firstPlaces) {
827
+ if (!firstPlaces) return;
828
+ const displayed = getDisplayedEntries();
829
+ const moving = displayed.filter(function (e) { return firstPlaces.has(e); });
830
+ const coming = displayed.filter(function (e) { return !firstPlaces.has(e); });
831
+ const lastPlaces = moving.map(getLayoutPlace); // WHY: All the places are read before the writes: one layout.
832
+
833
+ moving.forEach(function (e, i) {
834
+ setRowMotion(e, "placing");
835
+ e.row.css.transform = getMoveBack(firstPlaces.get(e), lastPlaces[i]);
836
+ });
837
+ coming.forEach(function (e) {
838
+ setRowMotion(e, "still");
839
+ e.row.css.opacity = "0";
840
+ e.row.css.transform = "translateY(" + (-COMING_ROW_SHIFT) + "px)";
841
+ });
842
+
843
+ void box.wrapper.elem.offsetWidth; // WHY: The start places are drawn first, so the moves start from them.
844
+
845
+ displayed.forEach(function (e) {
846
+ setRowMotion(e, "rest");
847
+ e.row.css.transform = "";
848
+ });
849
+ coming.forEach(showRowLook);
850
+ };
851
+
852
+ // FLIP: change() moves rows in the layout; the rows on the screen move there from where they were seen.
853
+ const moveRowsAfter = function (change) {
854
+ const firstPlaces = measureRows();
855
+ change();
856
+ playRowMoves(firstPlaces);
857
+ };
858
+
859
+ // A row that goes: it fades out in its place (the rows around it stay), then gone(entry) takes it away (removed or
860
+ // hidden) and the rows under it move up (FLIP).
861
+ const fadeOutRow = function (entry, gone) {
862
+ if (entry.cancelLeave) entry.cancelLeave();
863
+ entry.isLeaving = 1;
864
+ entry.row.clickable = 0;
865
+ entry.row.aria = { hidden: "true" };
866
+ setRowMotion(entry, "rest");
867
+ entry.row.css.opacity = "0";
868
+ entry.cancelLeave = box.after(MOTION_MS, function () {
869
+ entry.cancelLeave = null;
870
+ if (entry.row.isRemoved) return; // WHY: setItems() or setLayout() made the rows again in the meantime.
871
+ moveRowsAfter(function () { gone(entry); });
872
+ refreshScrollBar();
873
+ });
874
+ };
875
+
876
+ // A row that faded out (or stopped fading) gets its look back.
877
+ const endLeaveLook = function (entry) {
878
+ entry.isLeaving = 0;
879
+ entry.row.aria = { hidden: null };
880
+ if (!entry.isSection) entry.row.clickable = 1;
881
+ showRowLook(entry);
882
+ };
883
+
884
+ // A row that was fading out stays after all: it is shown again, or hidden at once (a search, animated: 0).
885
+ const stopLeave = function (entry) {
886
+ if (entry.cancelLeave) entry.cancelLeave();
887
+ entry.cancelLeave = null;
888
+ endLeaveLook(entry);
889
+ };
890
+
891
+ // The end of the fade of a hidden row (a section without a shown item): hidden, with its look back for later.
892
+ const hideFadedRow = function (entry) {
893
+ entry.row.visible = 0;
894
+ endLeaveLook(entry);
895
+ };
896
+
897
+ const removeFadedRow = function (entry) {
898
+ removedEntries = removedEntries.filter(function (e) { return e !== entry; });
899
+ entry.row.remove();
900
+ };
901
+
902
+ // The row of a removed item: it fades out, then it leaves and the rows under it move up (animated: 1).
903
+ // Otherwise (or a hidden row) it is removed at once.
904
+ const takeOutRow = function (entry) {
905
+ if (!isMotionOn() || entry.row.visible != 1) {
906
+ entry.row.remove();
907
+ return;
908
+ }
909
+ removedEntries.push(entry);
910
+ if (!entry.isSection) entry.row.tabIndex = -1;
911
+ fadeOutRow(entry, removeFadedRow);
912
+ };
913
+
914
+ // The removed rows that still fade out are removed at once.
915
+ const removeFadingRows = function () {
916
+ removedEntries.forEach(function (e) {
917
+ if (e.cancelLeave) e.cancelLeave();
918
+ e.row.remove();
919
+ });
920
+ removedEntries = [];
921
+ };
922
+
923
+ // The transitions of the rows (setAnimated). Off: the rows that fade out go at once, the moves end.
924
+ const applyAnimated = function () {
925
+ const isOn = isMotionOn();
926
+ if (!isOn && !wasAnimated) return; // WHY: animated: 0 writes nothing.
927
+ wasAnimated = isOn ? 1 : 0;
928
+ if (!isOn) removeFadingRows();
929
+ entries.forEach(function (e) {
930
+ if (!e.row) return;
931
+ setRowMotion(e, "rest");
932
+ if (!isOn) e.row.css.transform = "";
933
+ });
934
+ if (!isOn) applySearch(); // WHY: A section that was fading out is hidden at once.
935
+ };
936
+
937
+ // *** SELECTION
938
+
939
+ const setSelectedKeys = function (keys, silent) {
940
+ const before = selectedKeys.join("\n");
941
+ selectedKeys = keys;
942
+ paintAll();
943
+ refreshTabOrder(); // WHY: The Tab order goes to the selection while no row was focused.
944
+ if (silent || before === selectedKeys.join("\n")) return;
945
+ box.onChange(box, getSelectedItems());
946
+ };
947
+
948
+ // A click, Enter or Space on a row: the pressed flash, onItemClick and the selection. With Shift in a multiple
949
+ // list: the rows from the anchor to this one (selectRange).
950
+ // WHY: Enter and Space did not call onItemClick: a list without selection (a menu) could not be used with keys.
951
+ const activateEntry = function (entry, event) {
952
+ if (!isEntryChoosable(entry)) return;
953
+ flashRow(entry);
954
+ focusedKey = entry.key;
955
+ refreshTabOrder();
956
+ box.onItemClick(box, entry.item, indexOf(entry), event);
957
+ if (isRangeEvent(event)) {
958
+ selectRange(entry, entry);
959
+ return;
960
+ }
961
+ toggleEntry(entry, 0);
962
+ setAnchor(entry);
963
+ };
964
+
965
+ const isRangeEvent = function (event) {
966
+ return box.selection === "multiple" && !!event && event.shiftKey;
967
+ };
968
+
969
+ // multiple: a Shift range starts at this row and is added to the selection of this time.
970
+ const setAnchor = function (entry) {
971
+ anchorKey = entry.key;
972
+ rangeBaseKeys = selectedKeys.slice();
973
+ };
974
+
975
+ // WHY: A selection changed by code: the next Shift range must not bring its old keys back.
976
+ const forgetAnchor = function () {
977
+ anchorKey = null;
978
+ rangeBaseKeys = [];
979
+ };
980
+
981
+ // multiple: the enabled shown rows from the anchor to this one are selected, over the selection of the anchor
982
+ // time. A Shift move back makes the range shorter (the rows it leaves are not selected any more).
983
+ // startEntry: the anchor when there is none yet (the row the Shift move started from).
984
+ const selectRange = function (entry, startEntry) {
985
+ const shown = getShownEntries();
986
+ const anchor = findEntry(anchorKey);
987
+ if (!anchor || !anchor.isShown) setAnchor(startEntry);
988
+ const from = shown.indexOf(findEntry(anchorKey));
989
+ const to = shown.indexOf(entry);
990
+ const rangeKeys = shown.slice(Math.min(from, to), Math.max(from, to) + 1)
991
+ .filter(isEntryEnabled)
992
+ .map(function (e) { return e.key; });
993
+ const newKeys = rangeKeys.filter(function (key) { return !rangeBaseKeys.includes(key); });
994
+ setSelectedKeys(rangeBaseKeys.concat(newKeys), 0);
995
+ };
996
+
997
+ // multiple: Ctrl / Cmd + A selects every shown enabled item; when they are all selected, none of them.
998
+ // The hidden ones (a search) keep their selection.
999
+ const toggleAllShown = function (shown) {
1000
+ const keys = shown.filter(isEntryEnabled).map(function (e) { return e.key; });
1001
+ const isAllSelected = keys.every(function (key) { return selectedKeys.includes(key); });
1002
+ const otherKeys = selectedKeys.filter(function (key) { return !keys.includes(key); });
1003
+ const newKeys = keys.filter(function (key) { return !selectedKeys.includes(key); });
1004
+ setSelectedKeys(isAllSelected ? otherKeys : selectedKeys.concat(newKeys), 0);
1005
+ forgetAnchor();
1006
+ };
1007
+
1008
+ // A click, Enter or Space on a row.
1009
+ const toggleEntry = function (entry, silent) {
1010
+ if (box.selection === "none" || entry.isSection) return;
1011
+ if (box.selection === "single") {
1012
+ setSelectedKeys([entry.key], silent);
1013
+ return;
1014
+ }
1015
+ const keys = isSelected(entry)
1016
+ ? selectedKeys.filter(function (key) { return key !== entry.key; })
1017
+ : selectedKeys.concat([entry.key]);
1018
+ setSelectedKeys(keys, silent);
1019
+ };
1020
+
1021
+ // A key of an item of the list. WHY: A section is never selected.
1022
+ const isSelectableKey = function (key) {
1023
+ const entry = findEntry(key);
1024
+ return !!entry && !entry.isSection;
1025
+ };
1026
+
1027
+ // Only the keys of the list; single selection keeps the last one.
1028
+ const cleanKeys = function (keys) {
1029
+ const known = (Array.isArray(keys) ? keys : [keys])
1030
+ .map(String)
1031
+ .filter(function (key, index, list) { return isSelectableKey(key) && list.indexOf(key) === index; });
1032
+ if (box.selection === "none") return [];
1033
+ if (box.selection === "single") return known.slice(-1);
1034
+ return known;
1035
+ };
1036
+
1037
+ // *** KEYBOARD
1038
+
1039
+ // The shown items (not the sections): the keyboard, the Tab order and the counts use them.
1040
+ const getShownEntries = function () {
1041
+ return entries.filter(function (e) { return e.isShown && !e.isSection; });
1042
+ };
1043
+
1044
+ // The shown section right before an item (null: none).
1045
+ const getSectionBefore = function (entry) {
1046
+ const before = entries[indexOf(entry) - 1];
1047
+ return (before && before.isSection && before.isShown) ? before : null;
1048
+ };
1049
+
1050
+ // Scrolls only the list (not the page around it) to show a row.
1051
+ // WHY: scrollIntoView() also scrolled the boxes around the list: the whole page jumped.
1052
+ const scrollRowIntoView = function (entry) {
1053
+ if (isAutoHeight || !entry || !entry.row || !entry.isShown) return;
1054
+ const area = box.scrollBox.elem;
1055
+ const row = entry.row.elem;
1056
+ // WHY: The first item of a section is shown with its title (Home, the arrow up).
1057
+ const firstRow = (getSectionBefore(entry) || entry).row.elem;
1058
+ const isHorizontal = (box.layout === "horizontal");
1059
+ const wrapperStart = isHorizontal ? box.wrapper.elem.offsetLeft : box.wrapper.elem.offsetTop;
1060
+ const start = (isHorizontal ? firstRow.offsetLeft : firstRow.offsetTop) + wrapperStart;
1061
+ const end = (isHorizontal ? row.offsetLeft + row.offsetWidth : row.offsetTop + row.offsetHeight) + wrapperStart;
1062
+ const position = isHorizontal ? area.scrollLeft : area.scrollTop;
1063
+ const visibleSize = isHorizontal ? area.clientWidth : area.clientHeight;
1064
+ let target = position;
1065
+ if (start < position) target = start;
1066
+ else if (end > position + visibleSize) target = end - visibleSize;
1067
+ if (isHorizontal) area.scrollLeft = target;
1068
+ else area.scrollTop = target;
1069
+ };
1070
+
1071
+ const scrollToFirstSelected = function () {
1072
+ if (box.scrollToSelected != 1 || selectedKeys.length === 0) return;
1073
+ scrollRowIntoView(findEntry(selectedKeys[0]));
1074
+ };
1075
+
1076
+ const focusEntry = function (entry) {
1077
+ if (!entry || !entry.row || entry.isSection) return;
1078
+ focusedKey = entry.key;
1079
+ refreshTabOrder();
1080
+ entry.row.elem.focus({ preventScroll: true });
1081
+ scrollRowIntoView(entry);
1082
+ };
1083
+
1084
+ // The nearest tile of a line of the grid to a side (left, in px).
1085
+ const getNearestInLine = function (line, left) {
1086
+ const distanceOf = function (e) { return Math.abs(e.row.elem.offsetLeft - left); };
1087
+ return line.reduce(function (nearest, e) {
1088
+ return (distanceOf(e) < distanceOf(nearest)) ? e : nearest;
1089
+ });
1090
+ };
1091
+
1092
+ // The tile on the next line of the grid (direction 1: down, -1: up), the nearest one to the side of this tile.
1093
+ // No line there: the last (or the first) tile.
1094
+ // WHY: Not a count of columns: a section starts a new line, so the lines of a grid are not all full.
1095
+ const getGridNeighbor = function (entry, shown, direction) {
1096
+ const top = entry.row.elem.offsetTop;
1097
+ const lineTops = shown
1098
+ .map(function (e) { return e.row.elem.offsetTop; })
1099
+ .filter(function (lineTop) { return (direction > 0) ? lineTop > top : lineTop < top; });
1100
+ if (lineTops.length === 0) return (direction > 0) ? shown[shown.length - 1] : shown[0];
1101
+ const nextTop = (direction > 0) ? Math.min(...lineTops) : Math.max(...lineTops);
1102
+ const line = shown.filter(function (e) { return e.row.elem.offsetTop === nextTop; });
1103
+ return getNearestInLine(line, entry.row.elem.offsetLeft);
1104
+ };
1105
+
1106
+ // How an arrow key moves the focus in this layout: 1 (next), -1 (previous), 0 (the key does nothing here).
1107
+ const getArrowStep = function (key) {
1108
+ const isVertical = (box.layout === "vertical");
1109
+ const isHorizontal = (box.layout === "horizontal");
1110
+ if (key === "ArrowDown") return isHorizontal ? 0 : 1;
1111
+ if (key === "ArrowUp") return isHorizontal ? 0 : -1;
1112
+ if (key === "ArrowRight") return isVertical ? 0 : 1;
1113
+ if (key === "ArrowLeft") return isVertical ? 0 : -1;
1114
+ return 0;
1115
+ };
1116
+
1117
+ // The row an arrow key moves the focus to. null: the key does nothing in this layout.
1118
+ const getArrowTarget = function (entry, key, shown) {
1119
+ const step = getArrowStep(key);
1120
+ if (step === 0) return null;
1121
+ const isLineMove = (key === "ArrowDown" || key === "ArrowUp");
1122
+ if (box.layout === "grid" && isLineMove) return getGridNeighbor(entry, shown, step);
1123
+ const position = shown.indexOf(entry);
1124
+ return shown[Math.max(0, Math.min(shown.length - 1, position + step))];
1125
+ };
1126
+
1127
+ // PageDown / PageUp: as many rows (in a grid: lines) as the list shows, less one. null: an "auto" height list
1128
+ // (it does not scroll in itself: the key scrolls the page).
1129
+ const getPageTarget = function (entry, shown, direction) {
1130
+ if (isAutoHeight) return null;
1131
+ const isHorizontal = (box.layout === "horizontal");
1132
+ const visibleSize = isHorizontal ? box.scrollBox.elem.clientWidth : box.scrollBox.elem.clientHeight;
1133
+ const rowSize = isHorizontal ? entry.row.elem.offsetWidth : entry.row.elem.offsetHeight;
1134
+ const count = Math.max(1, Math.floor(visibleSize / Math.max(1, rowSize)) - 1);
1135
+ if (box.layout === "grid") {
1136
+ let target = entry;
1137
+ for (let i = 0; i < count; i++) target = getGridNeighbor(target, shown, direction);
1138
+ return target;
1139
+ }
1140
+ const position = shown.indexOf(entry) + direction * count;
1141
+ return shown[Math.max(0, Math.min(shown.length - 1, position))];
1142
+ };
1143
+
1144
+ // The row a key moves the focus to: an arrow, Home / End, PageUp / PageDown. null: the key does not move it.
1145
+ const getMoveTarget = function (entry, key, shown) {
1146
+ if (key === "Home") return shown[0];
1147
+ if (key === "End") return shown[shown.length - 1];
1148
+ if (key === "PageDown") return getPageTarget(entry, shown, 1);
1149
+ if (key === "PageUp") return getPageTarget(entry, shown, -1);
1150
+ return getArrowTarget(entry, key, shown);
1151
+ };
1152
+
1153
+ // WHY: The arrow up from the first line of the list goes back to the search box over it.
1154
+ const isOnFirstLine = function (entry, shown) {
1155
+ if (box.layout === "horizontal") return true;
1156
+ return entry.row.elem.offsetTop === shown[0].row.elem.offsetTop;
1157
+ };
1158
+
1159
+ const isSelectAllKey = function (event) {
1160
+ const isCommand = event.ctrlKey || event.metaKey;
1161
+ return box.selection === "multiple" && isCommand && event.key.toLowerCase() === "a";
1162
+ };
1163
+
1164
+ // A letter of a word (type-ahead): not a key with Ctrl, Cmd or Alt.
1165
+ const isTypedLetter = function (event) {
1166
+ return event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey;
1167
+ };
1168
+
1169
+ // Type-ahead: the letters typed one after the other move the focus to the next item whose text starts with them
1170
+ // (Turkish letters without their marks). The same letter again goes on to the next item with that letter.
1171
+ const typeAhead = function (entry, letter, shown) {
1172
+ if (cancelTypedText) cancelTypedText();
1173
+ typedText += normalizeText(letter);
1174
+ cancelTypedText = box.after(TYPE_AHEAD_TIME, function () {
1175
+ typedText = "";
1176
+ cancelTypedText = null;
1177
+ });
1178
+ const isOneLetter = typedText.split("").every(function (c) { return c === typedText[0]; });
1179
+ const word = isOneLetter ? typedText[0] : typedText;
1180
+ // WHY: One letter starts after the focused row (the same letter goes on); a word may stay on it.
1181
+ const start = shown.indexOf(entry) + (isOneLetter ? 1 : 0);
1182
+ const ordered = shown.slice(start).concat(shown.slice(0, start));
1183
+ const target = ordered.find(function (e) { return normalizeText(e.data.text).startsWith(word); });
1184
+ if (target) focusEntry(target);
1185
+ };
1186
+
1187
+ const onRowKeyDown = function (entry, event) {
1188
+ // WHY: the keys of a field inside the row (createItemView) are its own: a space could not be typed in it
1189
+ if (event.target !== entry.row.elem) return;
1190
+ if (box.enabled != 1 || entry.isLeaving) return;
1191
+ const shown = getShownEntries();
1192
+
1193
+ if (isSelectAllKey(event)) {
1194
+ event.preventDefault();
1195
+ toggleAllShown(shown);
1196
+ return;
1197
+ }
1198
+ // WHY: A space while a word is typed is a letter of the word (type-ahead).
1199
+ const isSpace = (event.key === " " && typedText === "");
1200
+ if (event.key === "Enter" || isSpace) {
1201
+ event.preventDefault();
1202
+ // WHY: A key held down repeats: it would open an item again and again, or turn its selection on and off.
1203
+ if (event.repeat) return;
1204
+ activateEntry(entry, event);
1205
+ return;
1206
+ }
1207
+ if (event.key === "ArrowUp" && box.searchInput && isOnFirstLine(entry, shown)) {
1208
+ event.preventDefault();
1209
+ box.searchInput.focus();
1210
+ return;
1211
+ }
1212
+ const target = getMoveTarget(entry, event.key, shown);
1213
+ if (target) {
1214
+ event.preventDefault();
1215
+ focusEntry(target);
1216
+ if (isRangeEvent(event)) selectRange(target, entry);
1217
+ return;
1218
+ }
1219
+ if (isTypedLetter(event)) {
1220
+ event.preventDefault();
1221
+ typeAhead(entry, event.key, shown);
1222
+ }
1223
+ };
1224
+
1225
+ // The arrow down in the search box goes into the list: to its row of the Tab order (getTabEntry).
1226
+ const onSearchKeyDown = function (self, event) {
1227
+ if (event.key !== "ArrowDown") return;
1228
+ const tabEntry = getTabEntry();
1229
+ if (!tabEntry) return;
1230
+ event.preventDefault();
1231
+ focusEntry(tabEntry);
1232
+ };
1233
+
1234
+ // The search box over the list (showSearch: 1). Returns its height with its padding (0: no search box).
1235
+ const createSearch = function () {
1236
+ if (box.showSearch != 1) return 0;
1237
+ if (typeof SearchInput === "undefined") {
1238
+ console.warn("ItemList: showSearch needs comp/search-input.js (SearchInput).");
1239
+ return 0;
1240
+ }
1241
+ const search = _s.search;
1242
+ const padding = search.padding; // [left, top, right, bottom]
1243
+
1244
+ // GROUP: Search area
1245
+ box.searchArea = HGroup({ width: "100%", height: search.height + padding[1] + padding[3], align: "left top", padding: padding });
1246
+ if (isAutoHeight) box.searchArea.position = "relative";
1247
+ // WHY clearOnEscape: Escape clears the search (as the clear icon); searchParams can turn it off.
1248
+ const searchParams = Object.assign({ clearOnEscape: 1 }, search, box.searchParams);
1249
+ delete searchParams.padding;
1250
+ searchParams.width = "100%";
1251
+ searchParams.position = "relative";
1252
+ searchParams.onChange = function (self) { box.search(self.getSearchText()); };
1253
+ box.searchInput = SearchInput(searchParams);
1254
+ box.searchInput.txtSearch.on("keydown", onSearchKeyDown);
1255
+ endGroup();
1256
+
1257
+ return search.height + padding[1] + padding[3];
1258
+ };
1259
+
1260
+ // A search() from code shows its text in the search box too.
1261
+ // WHY: Only when it is another text: the box gives a lower case text to search(); it must not change what is typed.
1262
+ const syncSearchInput = function (text) {
1263
+ if (!box.searchInput) return;
1264
+ if (normalizeText(box.searchInput.value).trim() === normalizeText(text).trim()) return;
1265
+ box.searchInput.setValue(String(text || ""), 1);
1266
+ };
1267
+
1268
+ // *** PUBLIC FUNCTIONS:
1269
+
1270
+ box.setItems = function (items) {
1271
+ entries = (Array.isArray(items) ? items : []).map(toEntry);
1272
+ selectedKeys = selectedKeys.filter(isSelectableKey);
1273
+ if (!findEntry(focusedKey)) focusedKey = null;
1274
+ forgetAnchor();
1275
+ createRows();
1276
+ };
1277
+ // USAGE: list.setItems([{ key: "a", text: "A" }, "B"]) // onChange is not called. Selected keys that are still there stay selected.
1278
+
1279
+ box.getItems = function () {
1280
+ return entries.map(function (e) { return e.item; });
1281
+ };
1282
+ // USAGE: list.getItems() // The same strings / objects you gave (the sections too)
1283
+
1284
+ box.getItem = function (key) {
1285
+ const entry = findEntry(key);
1286
+ return entry ? entry.item : null;
1287
+ };
1288
+
1289
+ // The row object of an item (for your own changes on a createItemView row).
1290
+ box.getRow = function (key) {
1291
+ const entry = findEntry(key);
1292
+ return entry ? entry.row : null;
1293
+ };
1294
+
1295
+ // An item without a key gets the first free number as its key ("0", "1"...).
1296
+ // WHY: Not just the count of the items: after a removeItem() that number can already be a key.
1297
+ const getFreeIndexKey = function () {
1298
+ let number = entries.length;
1299
+ while (findEntry(number)) number++;
1300
+ return number;
1301
+ };
1302
+
1303
+ // index: the place in getItems() (the sections are counted). -1 or empty -> at the end.
1304
+ // animated: 1 -> the rows under it move down and it fades in.
1305
+ box.addItem = function (item, index = -1) {
1306
+ const entry = toEntry(item, getFreeIndexKey());
1307
+ if (findEntry(entry.key)) {
1308
+ console.warn("ItemList: the key is already in the list: " + entry.key);
1309
+ return;
1310
+ }
1311
+ const at = (index < 0 || index > entries.length) ? entries.length : index;
1312
+ moveRowsAfter(function () {
1313
+ entries.splice(at, 0, entry);
1314
+ createIn(box.wrapper, function () { createRow(entry); });
1315
+ const next = entries[at + 1];
1316
+ if (next && next.row) box.wrapper.elem.insertBefore(entry.row.elem, next.row.elem);
1317
+ applySearch(isMotionOn());
1318
+ });
1319
+ };
1320
+ // USAGE: list.addItem({ key: "x", text: "X" }) or list.addItem({ key: "y", text: "Y" }, 0)
1321
+
1322
+ // silent: 1 -> onChange is not called (when the removed item was selected). Returns the removed item.
1323
+ // animated: 1 -> its row fades out, then it leaves and the rows under it move up. (The data changes at once.)
1324
+ box.removeItem = function (key, silent = 0) {
1325
+ const entry = findEntry(key);
1326
+ if (!entry) return null;
1327
+ moveRowsAfter(function () {
1328
+ entries.splice(indexOf(entry), 1);
1329
+ takeOutRow(entry);
1330
+ if (focusedKey === entry.key) focusedKey = null;
1331
+ if (isSelected(entry)) {
1332
+ setSelectedKeys(selectedKeys.filter(function (k) { return k !== entry.key; }), silent);
1333
+ }
1334
+ applySearch(isMotionOn());
1335
+ });
1336
+ return entry.item;
1337
+ };
1338
+ // USAGE: list.removeItem("tomato")
1339
+
1340
+ // Changes the keys of an item object and draws its row again (the key itself does not change).
1341
+ box.updateItem = function (key, changes = {}) {
1342
+ const entry = findEntry(key);
1343
+ if (!entry || typeof entry.item !== "object") return;
1344
+ Object.assign(entry.item, changes, { key: entry.item.key });
1345
+ entry.data = entry.item;
1346
+ entry.isSection = isSectionData(entry.data);
1347
+ selectedKeys = selectedKeys.filter(isSelectableKey); // WHY: An item that became a section is not selected any more.
1348
+ const oldRow = entry.row;
1349
+ createIn(box.wrapper, function () { createRow(entry); });
1350
+ box.wrapper.elem.insertBefore(entry.row.elem, oldRow.elem);
1351
+ oldRow.remove();
1352
+ applySearch();
1353
+ };
1354
+ // USAGE: list.updateItem("tomato", { description: "Fruit", iconFile: "tomato.png" })
1355
+
1356
+ box.getSelectedKeys = function () {
1357
+ return selectedKeys.slice();
1358
+ };
1359
+
1360
+ box.getSelected = function () {
1361
+ return getSelectedItems();
1362
+ };
1363
+ // USAGE: list.getSelected() // [item, item] (the same objects / strings you gave)
1364
+
1365
+ // silent: 1 -> onChange is not called.
1366
+ box.setSelected = function (keys, silent = 0) {
1367
+ setSelectedKeys(cleanKeys(keys), silent);
1368
+ forgetAnchor();
1369
+ scrollToFirstSelected();
1370
+ };
1371
+ // USAGE: list.setSelected("broccoli") or list.setSelected(["a", "b"], 1)
1372
+
1373
+ box.select = function (key, silent = 0) {
1374
+ const entry = findEntry(key);
1375
+ if (!entry || entry.isSection || isSelected(entry)) return;
1376
+ toggleEntry(entry, silent);
1377
+ forgetAnchor();
1378
+ if (box.scrollToSelected == 1) scrollRowIntoView(entry);
1379
+ };
1380
+
1381
+ box.unselect = function (key, silent = 0) {
1382
+ setSelectedKeys(selectedKeys.filter(function (k) { return k !== String(key); }), silent);
1383
+ forgetAnchor();
1384
+ };
1385
+
1386
+ box.clearSelection = function (silent = 0) {
1387
+ setSelectedKeys([], silent);
1388
+ forgetAnchor();
1389
+ };
1390
+
1391
+ // Shows only the matching items (and the sections over them). Returns the count of the shown items. "": all of them.
1392
+ box.search = function (text) {
1393
+ searchText = normalizeText(text).trim();
1394
+ syncSearchInput(text);
1395
+ applySearch();
1396
+ return getShownEntries().length;
1397
+ };
1398
+ // USAGE: searchInput.onChange = function (self) { list.search(self.getSearchText()); };
1399
+
1400
+ box.setLayout = function (layout) {
1401
+ box.layout = normalizeLayout(layout);
1402
+ refreshScrollAxes();
1403
+ createRows();
1404
+ };
1405
+ // USAGE: list.setLayout("grid") // "vertical", "horizontal", "grid"
1406
+
1407
+ box.setSelection = function (selection) {
1408
+ box.selection = selection;
1409
+ selectedKeys = cleanKeys(selectedKeys);
1410
+ forgetAnchor();
1411
+ createRows(); // WHY: The check marks are made (or not) with the rows.
1412
+ };
1413
+ // USAGE: list.setSelection("multiple")
1414
+
1415
+ box.setEnabled = function (enabled) {
1416
+ box.enabled = basic.isOn(enabled) ? 1 : 0;
1417
+ box.aria = { disabled: (box.enabled == 1) ? "false" : "true" };
1418
+ refreshTabOrder();
1419
+ paintAll();
1420
+ };
1421
+ // USAGE: get: list.enabled, set: list.setEnabled(0)
1422
+
1423
+ box.setAnimated = function (value) {
1424
+ box.animated = basic.isOn(value) ? 1 : 0;
1425
+ applyAnimated();
1426
+ };
1427
+ // USAGE: get: list.animated, set: list.setAnimated(1)
1428
+
1429
+ box.scrollToItem = function (key) {
1430
+ scrollRowIntoView(findEntry(key));
1431
+ };
1432
+
1433
+ box.focusItem = function (key) {
1434
+ focusEntry(key === undefined ? getShownEntries()[0] : findEntry(key));
1435
+ };
1436
+
1437
+ // func(item, row, index) for every item (shown or not), the sections too (item.type === "section")
1438
+ box.forEach = function (func) {
1439
+ entries.forEach(function (e, index) { func(e.item, e.row, index); });
1440
+ };
1441
+
1442
+ box.refresh = function () {
1443
+ paintAll();
1444
+ refreshEmptyText();
1445
+ };
1446
+
1447
+ // The active row of a combobox (SelectBox: the row of its arrow keys) gets the look of the mouse (style.hover),
1448
+ // also when it is selected. It is then the only row with that look. null: none.
1449
+ // WHY: The keyboard stays in the field of the combobox: the list does not get the focus, it only shows the row.
1450
+ // The mouse makes its row active itself (SelectBox: mousemove), so the row under the mouse loses its look
1451
+ // when the arrow keys move the active row: two rows were white.
1452
+ box.setActiveKey = function (key) {
1453
+ const oldEntries = entries.filter(function (e) { return e.isHover || e.key === activeKey; });
1454
+ activeKey = (key === null || key === undefined) ? null : String(key);
1455
+ oldEntries.forEach(function (e) {
1456
+ e.isHover = 0;
1457
+ paintRow(e);
1458
+ });
1459
+ const entry = findEntry(activeKey);
1460
+ if (entry) paintRow(entry);
1461
+ };
1462
+
1463
+ // *** OBJECT VIEW:
1464
+
1465
+ box.color = _s.box.color;
1466
+ box.border = _s.box.border;
1467
+ box.borderColor = _s.box.borderColor;
1468
+ box.round = _s.box.round;
1469
+ box.css.boxSizing = "border-box";
1470
+
1471
+ const searchHeight = createSearch();
1472
+
1473
+ if (!isAutoHeight) {
1474
+ // BOX: Scrolling area (under the search box)
1475
+ box.scrollBox = Box(0, searchHeight, "100%", "calc(100% - " + searchHeight + "px)", { color: "transparent" });
1476
+ }
1477
+
1478
+ // LABEL: Empty / no result text
1479
+ box.lblEmpty = Label({
1480
+ plainText: box.emptyText,
1481
+ left: 0, // WHY: only top was set, so the text stayed at the left of basic.js (-1000), out of the list
1482
+ width: "100%",
1483
+ fontSize: _s.empty.fontSize,
1484
+ textColor: _s.empty.textColor,
1485
+ textAlign: "center",
1486
+ padding: [0, 20],
1487
+ visible: 0,
1488
+ });
1489
+ if (isAutoHeight) box.lblEmpty.position = "relative";
1490
+ else box.lblEmpty.top = searchHeight + EMPTY_TEXT_TOP;
1491
+
1492
+ if (!isAutoHeight && box.useScrollBar == 1 && typeof ScrollBar !== "undefined") {
1493
+ box.scrollBar = ScrollBar(Object.assign({ scrollableBox: box.scrollBox }, _s.scrollBar));
1494
+ }
1495
+
1496
+ // *** OBJECT INIT CODE:
1497
+
1498
+ box.layout = normalizeLayout(box.layout);
1499
+ refreshScrollAxes();
1500
+ entries = startItems.map(toEntry);
1501
+ selectedKeys = cleanKeys(startKeys);
1502
+ createRows();
1503
+ box.setEnabled(box.enabled);
1504
+ wasAnimated = isMotionOn() ? 1 : 0; // WHY: The rows were made with the transitions of the motion.
1505
+ // WHY: After the page has placed the list: the sizes are not known while it is created.
1506
+ box.after(0, scrollToFirstSelected);
1507
+
1508
+ return endObject(box);
1509
+
1510
+ };
1511
+
1512
+ // *** STATIC FUNCTIONS:
1513
+
1514
+ ItemList.getCheckSvg = function (color, size) {
1515
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="' + color + '" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>';
1516
+ };
1517
+
1518
+ // *** STYLE PACKAGES:
1519
+ // USAGE: ItemList({ styleName: "light" })
1520
+ // USAGE: ItemList({ styleName: "dark", style: { row: { round: 4 } } }) // Change only some keys.
1521
+ // USAGE: ItemList({ style: ItemList.styles.dark }) // The same as styleName: "dark". (The package is copied, never changed.)
1522
+ // NOTE: A new package needs only the keys that differ from the default (ozden) style.
1523
+ // USAGE: ItemList.styles.myStyle = { row: { color: "ivory" } };
1524
+ ItemList.styles = {
1525
+
1526
+ // The rows: white under the mouse, the selected one half transparent. The tiles: a grey icon in a circle that
1527
+ // grows when it is selected.
1528
+ ozden: ItemListDefaults.style,
1529
+
1530
+ // WHY: The old name of ozden: a page written with styleName: "classic" gets the same look without a warning.
1531
+ classic: ItemListDefaults.style,
1532
+
1533
+ // The dark theme of ozden: the same shapes on a dark page (#1A1A19). A row gets a lighter
1534
+ // gray with a thin light line above and under it under the mouse, the selected one is half transparent, the
1535
+ // search box is the ozdenDark SearchInput in the gray of the mouse.
1536
+ ozdenDark: {
1537
+ box: { color: "#1A1A19", borderColor: White(0.22) },
1538
+ hover: { color: "#262624", lineColor: White(0.14) },
1539
+ focus: { ringColor: White(0.5) },
1540
+ title: { textColor: White(0.88) },
1541
+ desc: { textColor: White(0.45) },
1542
+ section: { textColor: White(0.4) },
1543
+ check: { color: "#E6E6E4", iconColor: "#1A1A19", borderColor: White(0.3) },
1544
+ empty: { textColor: White(0.4) },
1545
+ tile: { frameColor: White(0.06), selectedColor: "#262624" },
1546
+ search: { styleName: "ozdenDark", color: "#262624" },
1547
+ scrollBar: { bar_color: "#CFCFCD", bar_mouseOverColor: "#CFCFCD" },
1548
+ },
1549
+
1550
+ // The light look of the kit (_designs/item-list.htm): a white box with one thin line and round 10 corners, flat
1551
+ // rows of 56 px; the row under the mouse in a soft gray, the selected one in a tint of the accent with a full
1552
+ // mark (an empty circle on the other rows).
1553
+ light: {
1554
+ box: { color: "#FFFFFF", border: 1, borderColor: Black(0.12), round: 10, padding: 6 },
1555
+ list: { gap: 2 }, // WHY: the colors of two rows never meet
1556
+ row: { height: 56, padding: [12, 10], gap: 12, color: "transparent", round: 8 },
1557
+ // WHY: The effects of the ozden tiles (a grey icon in a circle that grows) are turned off.
1558
+ tile: {
1559
+ width: 132,
1560
+ height: "auto",
1561
+ padding: [12, 14],
1562
+ gap: 8,
1563
+ spacing: 8,
1564
+ listPadding: 6, // as box.padding
1565
+ iconSize: 56,
1566
+ frameSize: 0,
1567
+ iconFilter: "",
1568
+ selectedIconScale: 1,
1569
+ selectedIconFilter: "",
1570
+ selectedFontFamily: "",
1571
+ selectedColor: "",
1572
+ hover: { color: "#F2F3F0" },
1573
+ },
1574
+ section: { padding: [12, 6], fontSize: 13, textColor: Black(0.55) }, // WHY 12: over the icons of the rows
1575
+ hover: { color: "#F2F3F0", lineColor: "" }, // WHY: "": the lines of ozden are not filled in.
1576
+ selected: { color: "#E4EFEB", opacity: 1, canSelectAgain: 1 }, // WHY 1: a click on it is an onItemClick again (the rule of ozden is its own)
1577
+ focus: { ringColor: "rgba(61, 122, 107, 0.5)" },
1578
+ icon: { size: 36, round: 8, color: "#F2F3F0" },
1579
+ title: { fontSize: 15, textColor: Black(0.88), fontFamily: "opensans" },
1580
+ desc: { fontSize: 13, textColor: Black(0.55), marginTop: 0 },
1581
+ check: { visible: 1, size: 20, color: "#3D7A6B", iconColor: "#FFFFFF", borderColor: Black(0.25) },
1582
+ empty: { fontSize: 14, textColor: Black(0.55) },
1583
+ // The search field of the light look: SearchInput light, round 8 as the rows.
1584
+ // WHY border and round: the search box of ozden (the default) has border 0 and round 2, and its keys fill
1585
+ // this package.
1586
+ search: {
1587
+ styleName: "light", // A package of SearchInput.styles
1588
+ padding: [6, 6, 6, 0], // left, top, right, bottom: as box.padding (the rows have their own 6 under it)
1589
+ border: 1,
1590
+ round: 8,
1591
+ },
1592
+ scrollBar: { bar_color: "#A0A0A0", bar_mouseOverColor: "#6E6E6C", neverHide: 0, showDots: 0 },
1593
+ },
1594
+
1595
+ // The dark look of the kit: the same shapes on the dark surface (#232322, on a #1A1A19 page).
1596
+ dark: {
1597
+ box: { color: "#232322", border: 1, borderColor: White(0.12), round: 10, padding: 6 },
1598
+ list: { gap: 2 },
1599
+ row: { height: 56, padding: [12, 10], gap: 12, color: "transparent", round: 8 },
1600
+ // WHY: The effects of the ozden tiles (a grey icon in a circle that grows) are turned off.
1601
+ tile: {
1602
+ width: 132,
1603
+ height: "auto",
1604
+ padding: [12, 14],
1605
+ gap: 8,
1606
+ spacing: 8,
1607
+ listPadding: 6, // as box.padding
1608
+ iconSize: 56,
1609
+ frameSize: 0,
1610
+ iconFilter: "",
1611
+ selectedIconScale: 1,
1612
+ selectedIconFilter: "",
1613
+ selectedFontFamily: "",
1614
+ selectedColor: "",
1615
+ hover: { color: White(0.07) },
1616
+ },
1617
+ section: { padding: [12, 6], fontSize: 13, textColor: White(0.55) }, // WHY 12: over the icons of the rows
1618
+ hover: { color: White(0.07), lineColor: "" }, // WHY: "": the lines of ozden are not filled in.
1619
+ selected: { color: "rgba(101, 162, 147, 0.2)", opacity: 1, canSelectAgain: 1 }, // WHY 1: as light
1620
+ focus: { ringColor: "rgba(101, 162, 147, 0.55)" },
1621
+ icon: { size: 36, round: 8, color: White(0.07) },
1622
+ title: { fontSize: 15, textColor: White(0.9), fontFamily: "opensans" },
1623
+ desc: { fontSize: 13, textColor: White(0.55), marginTop: 0 },
1624
+ check: { visible: 1, size: 20, color: "#65A293", iconColor: "#0F1F1B", borderColor: White(0.3) },
1625
+ empty: { fontSize: 14, textColor: White(0.55) },
1626
+ // The search field of the dark look: SearchInput dark, round 8 as the rows.
1627
+ // WHY color, border and round: the search box of ozden (the default) is white with border 0 and round 2, and
1628
+ // its keys fill this package.
1629
+ search: {
1630
+ styleName: "dark", // A package of SearchInput.styles
1631
+ padding: [6, 6, 6, 0], // left, top, right, bottom: as box.padding (the rows have their own 6 under it)
1632
+ color: "#232322",
1633
+ border: 1,
1634
+ round: 8,
1635
+ },
1636
+ scrollBar: { bar_color: "#8A8A88", bar_mouseOverColor: "#BFBFBD", neverHide: 0, showDots: 0 },
1637
+ },
1638
+
1639
+ // Pictures (layout "grid"): a big photo in its square with no filter, its title and description under it, a ring
1640
+ // around the selected one. A picture of any shape fills its square (cover).
1641
+ gallery: {
1642
+ box: { color: "transparent", border: 0, padding: 0 },
1643
+ tile: {
1644
+ width: 132, // WHY: two in a row on a phone too
1645
+ height: "auto",
1646
+ padding: [8, 8],
1647
+ gap: 6,
1648
+ spacing: 8,
1649
+ listPadding: 6,
1650
+ iconSize: 116,
1651
+ frameSize: 0,
1652
+ iconFilter: "",
1653
+ iconFit: "cover",
1654
+ iconMotion: "",
1655
+ selectedIconScale: 1,
1656
+ selectedIconFilter: "",
1657
+ selectedFontFamily: "",
1658
+ selectedColor: "",
1659
+ hover: { color: Black(0.05) },
1660
+ },
1661
+ row: { round: 10, border: 1, borderColor: "transparent", motion: "background-color 0.2s, border-color 0.2s" },
1662
+ hover: { color: Black(0.05), lineColor: "" }, // WHY: "": the lines of ozden are not filled in.
1663
+ selected: { color: "rgba(63, 141, 148, 0.1)", borderColor: "#3F8D94", opacity: 1, canSelectAgain: 1 },
1664
+ focus: { ringColor: "rgba(63, 141, 148, 0.8)" },
1665
+ icon: { round: 6, color: Black(0.05) },
1666
+ title: { fontSize: 14, textColor: Black(0.82), fontFamily: "" },
1667
+ desc: { fontSize: 12, textColor: Black(0.5), marginTop: 0 },
1668
+ empty: { fontSize: 14, textColor: Black(0.45) },
1669
+ },
1670
+
1671
+ // The pictures on a dark page.
1672
+ galleryDark: {
1673
+ box: { color: "transparent", border: 0, padding: 0 },
1674
+ tile: {
1675
+ width: 132, // WHY: two in a row on a phone too
1676
+ height: "auto",
1677
+ padding: [8, 8],
1678
+ gap: 6,
1679
+ spacing: 8,
1680
+ listPadding: 6,
1681
+ iconSize: 116,
1682
+ frameSize: 0,
1683
+ iconFilter: "",
1684
+ iconFit: "cover",
1685
+ iconMotion: "",
1686
+ selectedIconScale: 1,
1687
+ selectedIconFilter: "",
1688
+ selectedFontFamily: "",
1689
+ selectedColor: "",
1690
+ hover: { color: White(0.06) },
1691
+ },
1692
+ row: { round: 10, border: 1, borderColor: "transparent", motion: "background-color 0.2s, border-color 0.2s" },
1693
+ hover: { color: White(0.06), lineColor: "" },
1694
+ selected: { color: "rgba(91, 186, 193, 0.14)", borderColor: "#5BBAC1", opacity: 1, canSelectAgain: 1 },
1695
+ focus: { ringColor: "rgba(111, 198, 205, 0.8)" },
1696
+ icon: { round: 6, color: White(0.06) },
1697
+ title: { fontSize: 14, textColor: White(0.88), fontFamily: "" },
1698
+ desc: { fontSize: 12, textColor: White(0.5), marginTop: 0 },
1699
+ empty: { fontSize: 14, textColor: White(0.45) },
1700
+ check: { color: "#E6E6E4", iconColor: "#1A1A19", borderColor: White(0.3) },
1701
+ search: { styleName: "ozdenDark", color: "#262624" },
1702
+ scrollBar: { bar_color: "#CFCFCD", bar_mouseOverColor: "#CFCFCD" },
1703
+ },
1704
+
1705
+ };
1706
+
1707
+ // The minimal theme (_designs/minimal-theme.htm): no fill (the window shows through: its states are lines, so it
1708
+ // reads on any ground), a line around the list; 28 px rows with a 13 px title and a 14 px icon; a line around the
1709
+ // row under the mouse, an ink line, an ink title and a tick on the selected one; 2 px between the rows, so the lines
1710
+ // of two rows never meet. The search box is the head of the list, a line under it. A row with a description needs
1711
+ // more room: style: { row: { height: 44 } }. minimalDark: the same on a dark window.
1712
+ ItemList.createMinimalStyle = function (colors) {
1713
+ return {
1714
+ box: { color: "transparent", border: 1, borderColor: colors.line, round: 4, padding: 4 },
1715
+ list: { gap: 2 },
1716
+ row: { height: 28, padding: [8, 0], gap: 8, color: "transparent", border: 1, borderColor: "transparent", round: 3, lineColor: "" },
1717
+ section: { padding: [8, 6], fontSize: 11, fontFamily: "opensans-bold", textColor: colors.faintText },
1718
+ hover: { color: "transparent", lineColor: "", borderColor: colors.lineHover },
1719
+ selected: { color: "transparent", lineColor: "", borderColor: colors.ink, opacity: 1, canSelectAgain: 0 },
1720
+ disabled: { opacity: 0.4 },
1721
+ focus: { ringColor: colors.focus },
1722
+ icon: { size: 14, round: 0, color: "transparent" },
1723
+ title: { fontSize: 13, textColor: colors.text, selectedTextColor: colors.ink },
1724
+ desc: { fontSize: 12, textColor: colors.softText, marginTop: 0 },
1725
+ check: { visible: 1, size: 14, color: "transparent", iconColor: colors.ink, borderColor: "transparent" },
1726
+ empty: { fontSize: 12, textColor: colors.softText },
1727
+ search: { styleName: colors.searchStyleName, height: 30, padding: [0, 0, 0, 0], color: "transparent", border: 0, round: 0, borderBottomStyle: "1px solid " + colors.line, searchIconLeft: 13 },
1728
+ scrollBar: { bar_color: colors.scrollBar, bar_mouseOverColor: colors.scrollBar, bar_width: 3, bar_mouseOverWidth: 4, showDots: 0 },
1729
+ };
1730
+ };
1731
+ ItemList.MINIMAL_COLORS = {
1732
+ text: Black(0.85), softText: Black(0.55), faintText: Black(0.54), line: Black(0.2), lineHover: Black(0.45),
1733
+ ink: "#1F1F1F", focus: "#3D8BD9", searchStyleName: "minimal", scrollBar: "#373836",
1734
+ };
1735
+ ItemList.styles.minimal = ItemList.createMinimalStyle(ItemList.MINIMAL_COLORS);
1736
+ ItemList.MINIMAL_DARK_COLORS = {
1737
+ text: White(0.88), softText: White(0.55), faintText: White(0.48), line: White(0.18), lineHover: White(0.42),
1738
+ ink: "#EDEDEB", focus: "#7FB6DE", searchStyleName: "minimalDark", scrollBar: "#CFCFCD",
1739
+ };
1740
+ ItemList.styles.minimalDark = ItemList.createMinimalStyle(ItemList.MINIMAL_DARK_COLORS);