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,521 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ ActionButton - v26.10
6
+
7
+ UI COMPONENT
8
+ - A floating action button at the bottom right of its container (the page): a round button with a + icon.
9
+ A click opens the menu of actions at its left side; a click on an action, on the button again, outside the
10
+ menu or Escape closes it. With fewer than 2 actions the button runs onAction at once (no menu).
11
+ - The component covers its container (100% x 100%) but lets the mouse through: only the button, the open menu
12
+ and its cover (to close it) catch clicks.
13
+ - Style packages: "classic" (default), "ozden" (an ink button with a white icon, a
14
+ white menu with a shadow, animated: 1). Select with styleName. (ActionButton.styles)
15
+ - animated: 1 (context/basic-js-animated-rules.md): the button grows a little with a soft shadow under the mouse
16
+ and gets smaller when pressed, the menu grows out of the button and closes faster, its actions come in one
17
+ after the other and get a soft tint under the mouse. Only transform, opacity and box-shadow change; nothing at
18
+ the first view; off when the system asks for reduced motion. (box.setAnimated(0 / 1)) The turn of the icon ends
19
+ with a small spring (the rules: a toggle icon).
20
+
21
+ USAGE:
22
+ const fab = ActionButton({
23
+ items: [
24
+ { key: "photo", text: "Take a Photo" },
25
+ { key: "gallery", text: "Add from Gallery" },
26
+ "Add from URL", // a text: its key is the text
27
+ ],
28
+ onAction: function (self, key) { println("Action: " + key); },
29
+ });
30
+ fab.setItems([...]);
31
+ fab.openMenu(); fab.closeMenu(); fab.toggleMenu();
32
+ fab.setButtonColor("#8BC34A");
33
+ fab.setAnimated(1);
34
+ ActionButton({ animated: 1, items: [...] }); // small, smooth motions
35
+ ActionButton({ onAction: function () { addNewNote(); } }); // no items: a direct button
36
+ ActionButton({ style: { button: { color: "#8BC34A" } } }); // Change only some keys of the style.
37
+
38
+ Started Date: October 2026
39
+ Webpage: https://bug7a.github.io/js-components/
40
+
41
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
42
+ Licensed under the Apache License, Version 2.0
43
+ SPDX-License-Identifier: Apache-2.0
44
+
45
+ */
46
+
47
+ "use strict";
48
+
49
+ // Default values:
50
+ const ActionButtonDefaults = {
51
+ key: "0", // Your name for this object: read it in a callback (self.key)
52
+ left: 0,
53
+ top: 0,
54
+ width: "100%",
55
+ height: "100%",
56
+ items: [], // [{ key, text }] or ["text"]
57
+ iconFile: "data:image/svg+xml;utf8," + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" preserveAspectRatio="none" fill="#000000"><path d="M231 0H281V512H231ZM0 231H512V281H0Z"/></svg>'), // a plus (a page can give its own picture)
58
+ openIconFile: "", // "": iconFile. The icon while the menu is open.
59
+ iconSize: 30,
60
+ iconRotate: 0, // deg
61
+ openIconRotate: 45, // deg: the + turns into ×
62
+ rightSpace: 40, // The button from the right side of the container
63
+ bottomSpace: 40, // The button from the bottom of the container
64
+ menuWidth: 280,
65
+ menuGap: 20, // Between the menu and the button
66
+ animated: 0, // 1: small hover / press / open motions (context/basic-js-animated-rules.md). (box.setAnimated(0/1))
67
+ onAction: function (self, key) { }, // An action was chosen (no items: key is "", one item: its key)
68
+ onMenuToggle: function (self) { }, // The menu opened / closed: self.menuOpened
69
+ styleName: "classic", // "classic", "ozden" or a name added to ActionButton.styles
70
+ style: { // Classic style package (default)
71
+ button: {
72
+ size: 90,
73
+ color: "#FFD541",
74
+ openColor: "lightgray",
75
+ border: 4,
76
+ borderColor: "rgba(0, 0, 0, 0.2)",
77
+ iconOpacity: 0.4,
78
+ invertIcon: 0, // 1: a white icon (from the black add.png) on a dark button
79
+ shadow: "", // "": none. Ex: "0px 4px 12px rgba(0, 0, 0, 0.18)"
80
+ hoverShadow: "0px 6px 16px rgba(0, 0, 0, 0.15)", // animated: under the mouse
81
+ },
82
+ menu: {
83
+ color: "whitesmoke", // The lines between the actions
84
+ round: 13,
85
+ border: 2,
86
+ borderColor: "rgba(0, 0, 0, 0.2)",
87
+ hiddenScale: 0.4, // The menu grows from this size
88
+ shadow: "", // "": none
89
+ },
90
+ item: {
91
+ height: 50,
92
+ gap: 1,
93
+ color: "white",
94
+ textColor: "", // "": the color of a basic.js Button
95
+ fontSize: 0, // 0: the size of a basic.js Button
96
+ hoverTint: "rgba(0, 0, 0, 0.04)", // animated: over an action under the mouse
97
+ },
98
+ cover: {
99
+ color: "rgba(0, 0, 0, 0)", // Behind the open menu (a click on it closes the menu)
100
+ },
101
+ },
102
+ };
103
+
104
+ const ActionButton = function (params = {}) {
105
+
106
+ // Merge style package: params.style > ActionButton.styles[styleName] > ActionButtonDefaults.style (classic)
107
+ basic.applyStylePackage(params, ActionButton.styles, ActionButtonDefaults);
108
+
109
+ // Merge params:
110
+ mergeIntoIfMissing(params, ActionButtonDefaults);
111
+
112
+ // Edit params, if needed:
113
+ params.items = ActionButton.normalizeItems(params.items); // WHY: A copy: the data of the caller does not change.
114
+
115
+ // BOX: Component container
116
+ const box = startObject(params);
117
+
118
+ // *** PRIVATE VARIABLES:
119
+ const _s = box.style;
120
+ const BUTTON_MOTION = "background-color 0.3s";
121
+ const ICON_MOTION = "transform 0.3s";
122
+ const MENU_MOTION_MS = 200;
123
+ const MENU_MOTION = "opacity 0.2s, transform 0.2s";
124
+ let cancelHide = null;
125
+
126
+ // animated: 1
127
+ const MOTION_TIME = 0.25; // s
128
+ const MOTION_EASE = "cubic-bezier(0.2, 0.8, 0.2, 1)"; // a fast start and a soft stop
129
+ const SPRING_TIME = 0.35; // s: the turn of the icon
130
+ const SPRING_EASE = "cubic-bezier(0.34, 1.56, 0.64, 1)"; // a small overshoot, then back (the rules: a toggle icon)
131
+ const CLOSE_TIME = 0.15; // s: the menu closes faster than it opens
132
+ const HOVER_GROW = 1.05;
133
+ const PRESS_SCALE = 0.95;
134
+ const ICON_OPACITY_GAIN = 0.25;
135
+ const MENU_HIDDEN_SCALE = 0.96;
136
+ const MENU_HIDDEN_SHIFT = 8; // px, toward the button
137
+ const ITEM_HIDDEN_SHIFT = 6; // px, from under
138
+ const ITEM_DELAY = 0.03; // s, between the actions coming in
139
+ let isHovered = 0;
140
+ let isPressed = 0;
141
+ let wasAnimated = 0;
142
+
143
+ // *** PUBLIC VARIABLES:
144
+ box.menuOpened = 0;
145
+ box.itemButtons = [];
146
+ // NOTE: Default values are also public variables. (box.items, box.iconFile, box.menuWidth...)
147
+
148
+ // *** PRIVATE FUNCTIONS:
149
+
150
+ const getOpenIconFile = function () {
151
+ return box.openIconFile || box.iconFile;
152
+ };
153
+
154
+ // The look of the button: open (1) or closed (0).
155
+ const paintButton = function () {
156
+ const isOpen = box.menuOpened;
157
+ box.btnAction.color = (isOpen) ? _s.button.openColor : _s.button.color;
158
+ box.imgIcon.rotate = (isOpen) ? box.openIconRotate : box.iconRotate;
159
+ const iconFile = (isOpen) ? getOpenIconFile() : box.iconFile;
160
+ if (box.imgIcon.imageElement.getAttribute("src") !== iconFile) box.imgIcon.load(iconFile);
161
+ box.btnAction.aria = { expanded: (isOpen) ? "true" : "false" };
162
+ };
163
+
164
+ // BUTTON: One action of the menu.
165
+ const createItemButton = function (item) {
166
+ const btn = Button({ width: "100%", height: _s.item.height, minimal: 1, color: _s.item.color });
167
+ btn.shrink = 0;
168
+ btn.plainText = item.text;
169
+ if (_s.item.textColor) btn.textColor = _s.item.textColor;
170
+ if (_s.item.fontSize) btn.fontSize = _s.item.fontSize;
171
+ btn.on("click", function () { chooseAction(item.key); });
172
+ btn.onHoverChange(function (self, isOver) { paintItemHover(btn, isOver); });
173
+ return btn;
174
+ };
175
+
176
+ // The menu buttons, made again from box.items.
177
+ const createItems = function () {
178
+ box.itemButtons.forEach(function (btn) { btn.remove(); });
179
+ box.itemButtons = createIn(box.menu, function () {
180
+ return box.items.map(createItemButton);
181
+ });
182
+ prepareItems();
183
+ };
184
+
185
+ const chooseAction = function (key) {
186
+ // WHY: the menu fades for a moment after it closes; a double click ran onAction twice
187
+ if (!box.menuOpened) return;
188
+ box.closeMenu();
189
+ box.onAction(box, key);
190
+ };
191
+
192
+ // WHY: A user who asked the system for less motion gets the still menu and button.
193
+ const isMotionOn = function () {
194
+ if (box.animated != 1) return false;
195
+ const reduceMotion = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
196
+ return !reduceMotion;
197
+ };
198
+
199
+ const motionOf = function (properties, seconds, delay = 0) {
200
+ return properties.map(function (property) {
201
+ return property + " " + seconds + "s " + MOTION_EASE + " " + delay + "s";
202
+ }).join(", ");
203
+ };
204
+
205
+ // The menu while it is closed: small and see-through. (animated: a little smaller, beside the button)
206
+ const getHiddenMenuTransform = function () {
207
+ if (!isMotionOn()) return "scale(" + _s.menu.hiddenScale + ")";
208
+ return "translateX(" + MENU_HIDDEN_SHIFT + "px) scale(" + MENU_HIDDEN_SCALE + ")";
209
+ };
210
+
211
+ // The shadow of the button when the mouse is not over it. (A transparent one: the hover shadow fades from it.)
212
+ const getStillShadow = function () {
213
+ return _s.button.shadow || "0px 0px 0px 0px transparent";
214
+ };
215
+
216
+ const getButtonTransform = function () {
217
+ if (isPressed) return "scale(" + PRESS_SCALE + ")";
218
+ if (isHovered) return "scale(" + HOVER_GROW + ")";
219
+ return "none";
220
+ };
221
+
222
+ // The look of the hover / press state of the button. (Nothing when animated is off.)
223
+ const paintMotion = function () {
224
+ if (!isMotionOn()) return;
225
+ box.btnAction.css.transform = getButtonTransform();
226
+ box.btnAction.boxShadow = (isHovered && !isPressed) ? _s.button.hoverShadow : getStillShadow();
227
+ box.imgIcon.opacity = Math.min(1, _s.button.iconOpacity + ((isHovered) ? ICON_OPACITY_GAIN : 0));
228
+ };
229
+
230
+ // animated: the actions wait under their place, see-through, until the menu opens.
231
+ const hideItems = function () {
232
+ if (!isMotionOn()) return;
233
+ box.itemButtons.forEach(function (btn) {
234
+ btn.css = { transition: "none", opacity: "0", transform: "translateY(" + ITEM_HIDDEN_SHIFT + "px)" };
235
+ });
236
+ };
237
+
238
+ // animated: the actions come in one after the other, the one next to the button first.
239
+ const showItems = function () {
240
+ if (!isMotionOn()) return;
241
+ const count = box.itemButtons.length;
242
+ box.itemButtons.forEach(function (btn, index) {
243
+ const delay = (count - 1 - index) * ITEM_DELAY;
244
+ btn.css = { transition: motionOf(["opacity", "transform"], MOTION_TIME, delay), opacity: "1", transform: "none" };
245
+ });
246
+ };
247
+
248
+ // The menu: from small and see-through to its size (and back).
249
+ const showMenu = function () {
250
+ if (cancelHide) cancelHide();
251
+ cancelHide = null;
252
+ if (isMotionOn()) box.menu.setMotionNow(motionOf(["opacity", "transform"], MOTION_TIME));
253
+ box.menu.visible = 1;
254
+ box.menu.withMotion(function () {
255
+ box.menu.opacity = 1;
256
+ box.menu.css.transform = "scale(1)";
257
+ showItems();
258
+ });
259
+ };
260
+
261
+ const hideMenu = function () {
262
+ const isMotion = isMotionOn();
263
+ if (isMotion) box.menu.setMotionNow(motionOf(["opacity", "transform"], CLOSE_TIME));
264
+ box.menu.opacity = 0;
265
+ box.menu.css.transform = getHiddenMenuTransform();
266
+ if (cancelHide) cancelHide();
267
+ const hideTime = (isMotion) ? CLOSE_TIME * 1000 : MENU_MOTION_MS;
268
+ cancelHide = box.after(hideTime, function () {
269
+ cancelHide = null;
270
+ box.menu.visible = 0;
271
+ hideItems();
272
+ });
273
+ };
274
+
275
+ // animated: a soft tint over an action under the mouse.
276
+ // WHY: on the <button> of the Button: its white background covers a shadow of the outer box.
277
+ const paintItemHover = function (btn, isOver) {
278
+ if (!isMotionOn()) return;
279
+ btn.buttonElement.style.boxShadow = (isOver) ? "inset 0 0 0 100px " + _s.item.hoverTint : "inset 0 0 0 100px transparent";
280
+ };
281
+
282
+ // Back to the still look, after setAnimated(0).
283
+ const removeMotion = function () {
284
+ wasAnimated = 0;
285
+ box.btnAction.setMotion(BUTTON_MOTION);
286
+ box.btnAction.css.transform = "";
287
+ box.btnAction.boxShadow = _s.button.shadow;
288
+ box.imgIcon.setMotion(ICON_MOTION);
289
+ box.imgIcon.opacity = _s.button.iconOpacity;
290
+ box.menu.setMotion(MENU_MOTION);
291
+ box.menu.css.transformOrigin = "";
292
+ if (!box.menuOpened) box.menu.css.transform = getHiddenMenuTransform();
293
+ box.itemButtons.forEach(function (btn) {
294
+ btn.css = { transition: "", opacity: "", transform: "" };
295
+ btn.buttonElement.style.transition = "";
296
+ btn.buttonElement.style.boxShadow = "";
297
+ });
298
+ };
299
+
300
+ // The transitions of animated: 1 (or the still look back).
301
+ const applyAnimated = function () {
302
+ if (!isMotionOn()) {
303
+ if (wasAnimated) removeMotion();
304
+ return;
305
+ }
306
+ wasAnimated = 1;
307
+ box.btnAction.setMotion(motionOf(["background-color", "transform", "box-shadow"], MOTION_TIME));
308
+ box.imgIcon.setMotion("transform " + SPRING_TIME + "s " + SPRING_EASE + ", " + motionOf(["opacity"], MOTION_TIME));
309
+ box.menu.css.transformOrigin = "right bottom"; // WHY: The menu grows out of the button.
310
+ if (!box.menuOpened) box.menu.css.transform = getHiddenMenuTransform();
311
+ prepareItems();
312
+ paintMotion();
313
+ };
314
+
315
+ // animated: the transition of the tint of each action, and the closed look of the actions.
316
+ const prepareItems = function () {
317
+ if (!isMotionOn()) return;
318
+ box.itemButtons.forEach(function (btn) {
319
+ btn.buttonElement.style.transition = motionOf(["box-shadow"], MOTION_TIME);
320
+ });
321
+ if (!box.menuOpened) hideItems();
322
+ };
323
+
324
+ const setMenuOpened = function (isOpened) {
325
+ const value = (isOpened) ? 1 : 0;
326
+ if (value === box.menuOpened) return;
327
+ box.menuOpened = value;
328
+ box.cover.visible = value;
329
+ box.cover.clickable = value;
330
+ paintButton();
331
+ if (value) showMenu();
332
+ else hideMenu();
333
+ box.onMenuToggle(box);
334
+ };
335
+
336
+ // *** PUBLIC FUNCTIONS:
337
+
338
+ box.openMenu = function () { setMenuOpened(1); };
339
+ box.closeMenu = function () { setMenuOpened(0); };
340
+ box.toggleMenu = function () { setMenuOpened(!box.menuOpened); };
341
+
342
+ // The button: with 2 or more actions it opens the menu, else it runs the action at once.
343
+ box.press = function () {
344
+ if (box.items.length >= 2) {
345
+ box.toggleMenu();
346
+ return;
347
+ }
348
+ const onlyItem = box.items[0];
349
+ box.onAction(box, (onlyItem) ? onlyItem.key : "");
350
+ };
351
+
352
+ box.setItems = function (items) {
353
+ box.items = ActionButton.normalizeItems(items);
354
+ if (box.items.length < 2) box.closeMenu();
355
+ createItems();
356
+ };
357
+
358
+ box.setAnimated = function (value) {
359
+ box.animated = (value == 1) ? 1 : 0;
360
+ applyAnimated();
361
+ };
362
+
363
+ box.setButtonColor = function (color) {
364
+ _s.button.color = color;
365
+ paintButton();
366
+ };
367
+
368
+ // *** OBJECT VIEW:
369
+
370
+ // BOX: Cover (a click outside the menu closes it)
371
+ box.cover = Box(0, 0, "100%", "100%", { color: _s.cover.color });
372
+ box.cover.visible = 0;
373
+ box.cover.clickable = 0;
374
+
375
+ // BOX: Action button
376
+ box.btnAction = Box({
377
+ right: box.rightSpace,
378
+ bottom: box.bottomSpace,
379
+ width: _s.button.size,
380
+ height: _s.button.size,
381
+ color: _s.button.color,
382
+ round: _s.button.size / 2,
383
+ border: _s.button.border,
384
+ borderColor: _s.button.borderColor,
385
+ });
386
+ if (_s.button.shadow) box.btnAction.boxShadow = _s.button.shadow;
387
+ box.btnAction.setMotion(BUTTON_MOTION);
388
+ box.btnAction.clickable = 1;
389
+ box.btnAction.cursor = "pointer";
390
+ box.btnAction.role = "button";
391
+ box.btnAction.tabIndex = 0;
392
+ box.btnAction.aria = { label: "Actions", haspopup: "menu", expanded: "false" };
393
+
394
+ // ICON: Action button icon
395
+ box.imgIcon = createIn(box.btnAction, function () {
396
+ return Icon(0, 0, box.iconSize, box.iconSize);
397
+ });
398
+ box.imgIcon.load(box.iconFile);
399
+ box.imgIcon.opacity = _s.button.iconOpacity;
400
+ if (_s.button.invertIcon == 1) box.imgIcon.css.filter = "invert(100%)";
401
+ box.imgIcon.setMotion(ICON_MOTION);
402
+ box.imgIcon.center();
403
+
404
+ // GROUP: Menu (at the left side of the button, bottoms in one line)
405
+ box.menu = VGroup({
406
+ right: box.rightSpace + _s.button.size + box.menuGap,
407
+ bottom: box.bottomSpace,
408
+ width: box.menuWidth,
409
+ height: "auto",
410
+ align: "left top",
411
+ gap: _s.item.gap,
412
+ padding: [0, 0, 0, _s.item.gap], // WHY: one line under the last action too.
413
+ color: _s.menu.color,
414
+ round: _s.menu.round,
415
+ border: _s.menu.border,
416
+ borderColor: _s.menu.borderColor,
417
+ });
418
+ box.menu.role = "menu";
419
+ if (_s.menu.shadow) box.menu.boxShadow = _s.menu.shadow;
420
+ endGroup();
421
+
422
+ // *** OBJECT INIT CODE:
423
+
424
+ // WHY: The component covers its container; the objects of the page under it must still be clickable.
425
+ box.clickable = 0;
426
+
427
+ createItems();
428
+ box.menu.opacity = 0;
429
+ box.menu.css.transform = "scale(" + _s.menu.hiddenScale + ")";
430
+ box.menu.setMotion(MENU_MOTION);
431
+ box.menu.visible = 0; // WHY: Hidden after its children are made.
432
+
433
+ box.btnAction.on("click", box.press);
434
+ box.btnAction.on("keydown", function (self, event) {
435
+ if (event.key !== "Enter" && event.key !== " ") return;
436
+ event.preventDefault();
437
+ box.press();
438
+ });
439
+ box.cover.on("click", box.closeMenu);
440
+
441
+ // animated: the mouse over the button and the press (painted only when animated is on)
442
+ box.btnAction.onHoverChange(function (self, isOver) {
443
+ isHovered = isOver;
444
+ if (!isOver) isPressed = 0;
445
+ paintMotion();
446
+ });
447
+ box.btnAction.on("pointerdown", function () {
448
+ isPressed = 1;
449
+ paintMotion();
450
+ });
451
+ box.listenTo(document, "pointerup", function () {
452
+ if (!isPressed) return;
453
+ isPressed = 0;
454
+ paintMotion();
455
+ });
456
+ box.listenTo(document, "keydown", function (self, event) {
457
+ if (event.key !== "Escape" || !box.menuOpened) return;
458
+ box.closeMenu();
459
+ box.btnAction.elem.focus();
460
+ });
461
+
462
+ // WHY: setMotion waits a moment before it starts: the first view does not move.
463
+ applyAnimated();
464
+
465
+ return endObject(box);
466
+
467
+ };
468
+
469
+ // *** STATIC FUNCTIONS:
470
+
471
+ // The items with every value filled: a text -> { key: text, text: text }; without a key, its text is its key.
472
+ ActionButton.normalizeItems = function (items) {
473
+ return (Array.isArray(items) ? items : []).map(function (item) {
474
+ if (typeof item !== "object" || item === null) return { key: String(item), text: String(item) };
475
+ const text = String(item.text || "");
476
+ return { key: String((item.key !== undefined) ? item.key : text), text: text };
477
+ });
478
+ };
479
+
480
+ // *** STYLE PACKAGES:
481
+ // USAGE: ActionButton({ styleName: "classic" })
482
+ // USAGE: ActionButton({ style: { button: { color: "#8BC34A" } } }) // Change only some keys.
483
+ ActionButton.styles = {
484
+
485
+ // A yellow round button, a white menu with thin lines.
486
+ classic: ActionButtonDefaults.style,
487
+
488
+ // Bugra's style: an ink round button with a white +, a white rounded menu with a soft shadow, animated.
489
+ // A package of params (it has "style"): animated and the icon size are params, not style keys.
490
+ ozden: {
491
+ animated: 1,
492
+ iconSize: 24,
493
+ menuGap: 16,
494
+ style: {
495
+ button: {
496
+ size: 64,
497
+ color: "#232323", // ink
498
+ openColor: "#3C4043", // slate
499
+ border: 0,
500
+ iconOpacity: 0.9,
501
+ invertIcon: 1,
502
+ shadow: "0px 4px 12px rgba(0, 0, 0, 0.18)",
503
+ hoverShadow: "0px 10px 24px rgba(0, 0, 0, 0.24)",
504
+ },
505
+ menu: {
506
+ color: "#F0F0F0", // the lines between the actions
507
+ round: 16,
508
+ border: 1,
509
+ borderColor: "rgba(0, 0, 0, 0.08)",
510
+ shadow: "0px 10px 30px rgba(0, 0, 0, 0.12)",
511
+ },
512
+ item: {
513
+ height: 48,
514
+ textColor: "#232323",
515
+ fontSize: 17,
516
+ hoverTint: "rgba(0, 0, 0, 0.04)",
517
+ },
518
+ },
519
+ },
520
+
521
+ };