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,185 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ GridGroup - v26.11
6
+
7
+ UI COMPONENT
8
+ - A group whose objects stand in columns and rows: a form of titles and fields, the keys of a calculator, tiles. Start it
9
+ like HGroup and VGroup, and close it with endGroup(). The objects go into the cells in order, left to right.
10
+ - columns: 3: three equal columns. [120, "1fr", "auto"]: px, a part of the room, the width of its content. A text is CSS as
11
+ it is: "repeat(auto-fill, minmax(160px, 1fr))": as many columns as fit (a width of a phone too).
12
+ - rows: none: as many as the objects need, each as high as its content. 4, or a list or a text, as columns. With a height
13
+ (height: "100%", rows: 4) equal rows fill it.
14
+ - gap: 8, or [column gap, row gap].
15
+ - align: where each object stands in its cell: "left center", "center". None: it fills the cell. An object with a width of
16
+ its own keeps it: width: "100%" fills the cell.
17
+ - place(obj, { column, row, columnSpan, rowSpan, align }): one object in a cell of its own (from 0), over more than one cell.
18
+ - It has no look of its own, so no style package: color, round and padding are the ones of every group.
19
+ - clipContent: 0 by default: a button that lifts under the mouse is not cut at the edge of the group.
20
+
21
+ USAGE:
22
+ GridGroup({ columns: 3, gap: 8 });
23
+ Label({ text: "Name" });
24
+ Label({ text: "Size" });
25
+ Label({ text: "Date" });
26
+ endGroup();
27
+
28
+ const form = GridGroup({ columns: ["auto", "1fr"], gap: [12, 8], align: "left center" });
29
+ Label({ text: "Name" });
30
+ Input({ width: "100%", height: 36 });
31
+ endGroup();
32
+
33
+ const keys = GridGroup({ columns: 4, gap: 8 });
34
+ const zero = SmartButton({ labelText: "0", width: "100%" });
35
+ keys.place(zero, { columnSpan: 2 });
36
+ endGroup();
37
+
38
+ keys.setColumns(3);
39
+ keys.setGap([4, 8]);
40
+
41
+ Started Date: November 2026
42
+ Webpage: https://bug7a.github.io/js-components/
43
+
44
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
45
+ Licensed under the Apache License, Version 2.0
46
+ SPDX-License-Identifier: Apache-2.0
47
+
48
+ */
49
+
50
+ "use strict";
51
+
52
+ // Default values:
53
+ const GridGroupDefaults = {
54
+ width: "100%",
55
+ height: "auto", // "auto": as high as its rows.
56
+ columns: 2, // A number, a list ([120, "1fr", "auto"]) or a text (CSS)
57
+ rows: null, // null: as many as the objects need. A number, a list or a text, as columns.
58
+ gap: 0, // px, or [column gap, row gap]
59
+ align: "", // "": the objects fill their cells. "left center", "center"...: where each one stands in its cell.
60
+ clipContent: 0,
61
+ };
62
+
63
+ const GridGroup = function (params = {}) {
64
+
65
+ // Merge params:
66
+ mergeIntoIfMissing(params, GridGroupDefaults);
67
+
68
+ // WHY a copy without align: for HGroup it is where the objects stand in the group; here it is in their cells.
69
+ const groupProps = Object.assign({}, params, { gap: GridGroup.toGapText(params.gap) });
70
+ delete groupProps.align;
71
+
72
+ // GROUP: The grid. WHY HGroup: its objects take their places in its flow, and endGroup() closes it.
73
+ const box = HGroup(groupProps);
74
+
75
+ // *** PRIVATE FUNCTIONS:
76
+
77
+ const applyTracks = function () {
78
+ box.css = {
79
+ gridTemplateColumns: GridGroup.toTracks(box.columns),
80
+ gridTemplateRows: GridGroup.toTracks(box.rows),
81
+ };
82
+ };
83
+
84
+ const applyAlign = function () {
85
+ const place = GridGroup.toCellPlace(box._align);
86
+ box.css = { justifyItems: place.horizontal, alignItems: place.vertical };
87
+ };
88
+
89
+ // *** PUBLIC FUNCTIONS:
90
+
91
+ box.setColumns = function (columns) {
92
+ box.columns = columns;
93
+ applyTracks();
94
+ };
95
+ // USAGE: grid.setColumns(3) / grid.setColumns([120, "1fr"])
96
+
97
+ box.setRows = function (rows) {
98
+ box.rows = rows;
99
+ applyTracks();
100
+ };
101
+
102
+ box.setGap = function (gap) {
103
+ box.gap = GridGroup.toGapText(gap);
104
+ };
105
+ // USAGE: grid.setGap(8) / grid.setGap([12, 4])
106
+
107
+ box.setAlign = function (align) {
108
+ box._align = align;
109
+ applyAlign();
110
+ };
111
+ // USAGE: grid.setAlign("left center")
112
+
113
+ // One object in a cell of its own. column, row: from 0; not given: the next free cell. columnSpan, rowSpan: how many cells it takes.
114
+ box.place = function (obj, where = {}) {
115
+ obj.css = {
116
+ gridColumn: GridGroup.toCellLine(where.column, where.columnSpan),
117
+ gridRow: GridGroup.toCellLine(where.row, where.rowSpan),
118
+ };
119
+ if (where.align) {
120
+ const place = GridGroup.toCellPlace(where.align);
121
+ obj.css = { justifySelf: place.horizontal, alignSelf: place.vertical };
122
+ }
123
+ return obj;
124
+ };
125
+ // USAGE: grid.place(zero, { columnSpan: 2 }) / grid.place(title, { column: 1, row: 0 })
126
+
127
+ // *** OBJECT INIT CODE:
128
+
129
+ // WHY start: the flex group centers its lines; the rows and the columns start at the corner of the grid.
130
+ box.css = { display: "grid", justifyContent: "start", alignContent: "start" };
131
+ box._align = params.align;
132
+ applyTracks();
133
+ applyAlign();
134
+
135
+ // WHY again: writing the display brought a hidden group back. (visible keeps the display it finds: "grid")
136
+ if (params.visible !== undefined) box.visible = params.visible;
137
+
138
+ return box;
139
+
140
+ };
141
+
142
+ // *** STATIC FUNCTIONS:
143
+
144
+ // WHY minmax(0, ...): a part of the room would grow with a long content, and the columns would not stay equal.
145
+ GridGroup.toTrack = function (track) {
146
+ if (typeof track === "number") return track + "px";
147
+ return (/^[\d.]+fr$/.test(track)) ? "minmax(0, " + track + ")" : track;
148
+ };
149
+
150
+ // columns or rows as CSS: 3 -> three equal ones, a list -> one by one, a text -> as it is. null: as the objects need.
151
+ GridGroup.toTracks = function (tracks) {
152
+ if (tracks === null || tracks === undefined) return "";
153
+ if (typeof tracks === "number") return "repeat(" + tracks + ", minmax(0, 1fr))";
154
+ if (Array.isArray(tracks)) return tracks.map(GridGroup.toTrack).join(" ");
155
+ return String(tracks);
156
+ };
157
+
158
+ // 8 -> "8px", [12, 4] (column, row) -> "4px 12px" (CSS: row, column)
159
+ GridGroup.toGapText = function (gap) {
160
+ if (Array.isArray(gap)) return gap[1] + "px " + gap[0] + "px";
161
+ return (typeof gap === "number") ? gap + "px" : gap;
162
+ };
163
+
164
+ // A column or a row of an object as CSS: from 0, and how many cells it takes.
165
+ GridGroup.toCellLine = function (start, span) {
166
+ const spanText = "span " + (span || 1);
167
+ if (start === null || start === undefined) return spanText;
168
+ return (start + 1) + " / " + spanText;
169
+ };
170
+
171
+ GridGroup.CELL_PLACES = { left: "start", right: "end", top: "start", bottom: "end" };
172
+
173
+ // "left center" -> { horizontal: "start", vertical: "center" }. A side that is not named fills the cell.
174
+ GridGroup.toCellPlace = function (align) {
175
+ const words = String(align || "").split(" ");
176
+ const hasCenter = words.includes("center");
177
+ const placeOf = function (word) {
178
+ if (word) return GridGroup.CELL_PLACES[word];
179
+ return (hasCenter) ? "center" : "stretch";
180
+ };
181
+ return {
182
+ horizontal: placeOf(words.find(function (word) { return word === "left" || word === "right"; })),
183
+ vertical: placeOf(words.find(function (word) { return word === "top" || word === "bottom"; })),
184
+ };
185
+ };
@@ -0,0 +1,289 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Hold To Confirm Button - v26.01
6
+
7
+ - A button that runs its action only after it is held down (holdDuration ms): a red layer fills it from the left.
8
+ - Released early: the layer goes back. Done: the completed text is shown, resetDelay ms later the button is ready again.
9
+
10
+ USAGE:
11
+ HoldToConfirmButton({
12
+ labelText: "Hold to Delete",
13
+ completedText: "DELETED",
14
+ onConfirm: function (self) { println("deleted"); },
15
+ onReset: function (self) { println("ready again"); },
16
+ });
17
+
18
+ Started Date: January 2026
19
+ Webpage: https://bug7a.github.io/js-components/
20
+
21
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
22
+ Licensed under the Apache License, Version 2.0
23
+ SPDX-License-Identifier: Apache-2.0
24
+
25
+
26
+ Design inspired by a layout seen on Pinterest
27
+ Source: https://tr.pinterest.com/pin/528187862570909645/
28
+
29
+ */
30
+
31
+ "use strict";
32
+
33
+ // Default values:
34
+ const HoldToConfirmButtonDefaults = {
35
+ key: "0",
36
+ width: "auto",
37
+ height: 50,
38
+ labelText: "Hold to Delete", // Hold to Vanish, Hold to Delete
39
+ completedText: "DELETED", // Poof! And it's gone. // DELETED // REMOVED
40
+ allowHtml: 0, // 1: labelText and completedText are HTML (only for your own texts)
41
+ iconFile: "data:image/svg+xml;utf8," + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 144" preserveAspectRatio="none" fill="none" stroke="#141414" stroke-width="9" stroke-linecap="round" stroke-linejoin="round"><path d="M56.5 22.5H87.5M30.5 27H113.5M34.5 31V112A9.5 9.5 0 0 0 44 121.5H100A9.5 9.5 0 0 0 109.5 112V31M59.5 48.5V99.5M84.5 48.5V99.5"/></svg>'), // a bin (a page can give its own picture)
42
+ holdingIconFile: "data:image/svg+xml;utf8," + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 144" preserveAspectRatio="none" fill="none" stroke="#FE5D49" stroke-width="9" stroke-linecap="round" stroke-linejoin="round"><path d="M56.5 22.5H87.5M30.5 27H113.5M34.5 31V112A9.5 9.5 0 0 0 44 121.5H100A9.5 9.5 0 0 0 109.5 112V31M59.5 48.5V99.5M84.5 48.5V99.5"/></svg>'), // the bin in red while it is held
43
+ onConfirm: function (self) { },
44
+ onReset: function (self) {},
45
+ holdDuration: 3000, // ms
46
+ resetDelay: 3000, // ms: the completed text stays this long
47
+ style: {
48
+ layout: {
49
+ gap: 4,
50
+ padding: [18, 5],
51
+ },
52
+ icon: {
53
+ width: 32,
54
+ height: 32,
55
+ },
56
+ label: {
57
+ fontSize: 20,
58
+ textColor: Black(0.7),
59
+ },
60
+ holdingLabel: {
61
+ fontSize: 20,
62
+ textColor: "#FE5D49",
63
+ },
64
+ completedLabel: {
65
+ fontSize: 20,
66
+ textColor: "#5DB182",
67
+ },
68
+ box: {
69
+ color: Black(0.05),
70
+ border: 1,
71
+ borderColor: Black(0.3),
72
+ round: 8,
73
+ },
74
+ holdingBox: {
75
+ color: "#FFD1CB",
76
+ border: 1,
77
+ borderColor: "#FE5D49",
78
+ rightBorderColor: "#FE5D4944", // "transparent", "#FE5D4944", Black(0.2),
79
+ round: 8,
80
+ },
81
+ completedBox: {
82
+ color: "#DFEFE6",
83
+ opacity: 0,
84
+ border: 1,
85
+ borderColor: "#5DB182",
86
+ round: 8,
87
+ },
88
+ }
89
+ };
90
+
91
+ const HoldToConfirmButton = function (params = {}) {
92
+
93
+ // Merge params:
94
+ mergeIntoIfMissing(params, HoldToConfirmButtonDefaults);
95
+
96
+ // Edit params, if needed:
97
+ params.color = "transparent"; // WHY: The look is on box.contentBox (style.box), the box only holds the layers.
98
+
99
+ // BOX: Component container
100
+ const box = startObject(params);
101
+
102
+ // NOTE: Parent container is box.containerBox
103
+
104
+ // *** PRIVATE VARIABLES:
105
+ const COLOR_MOTION = "background-color 0.2s";
106
+ const CANCEL_MOTION_DURATION = "0.3s"; // The red layer goes back faster than it fills.
107
+ const RED_BORDER_INSET = 2; // px: the red line stands this much inside the right end of the red layer.
108
+ const CONTENT_ALIGN = "left center"; // The normal button and the red layer place their icon and label the same way.
109
+
110
+ // *** PUBLIC VARIABLES:
111
+ box.holdDurationString = (box.holdDuration / 1000) + "s";
112
+ box.publicVar = 1;
113
+ box.holdTimer = null; // The cancel function of the waiting hold (box.after), null: not holding.
114
+ box.resetTimer = null; // The cancel function of the waiting reset (box.after)
115
+
116
+ // *** PRIVATE FUNCTIONS:
117
+
118
+ const setText = function (label, text) {
119
+ const value = (text === undefined || text === null) ? "" : String(text);
120
+ if (box.allowHtml == 1) label.text = value;
121
+ else label.plainText = value;
122
+ };
123
+
124
+ // The red layer is as wide as the normal button. Its icon and label are placed by the same group layout.
125
+ // WHY: aline() copied whole pixels (offsetTop), but the flex layout puts the label at 10.25 px:
126
+ // the red label stood 0.25 px higher and the text moved a little under the moving edge of the mask.
127
+ // WHY: box.contentBox.width is rounded; the computed style keeps the part after the point (208.047px).
128
+ const syncHoldingLayer = function () {
129
+ const widthNow = window.getComputedStyle(box.contentBox.elem).getPropertyValue("width");
130
+ box.holdingBox.width = basic.num(widthNow);
131
+ };
132
+
133
+ const moveRedBorderToMaskEnd = function () {
134
+ // WHY: box.maskBox.width is the end value of its motion; the computed style is the width on the screen now.
135
+ const widthNow = window.getComputedStyle(box.maskBox.elem).getPropertyValue("width");
136
+ box.redBorder.left = basic.num(widthNow) - RED_BORDER_INSET;
137
+ };
138
+
139
+ // *** PUBLIC FUNCTIONS:
140
+
141
+ box.startHold = function (self, event) {
142
+ if (box.holdTimer) return;
143
+ // WHY: a right click (or Ctrl+click on a Mac) started the hold, and its menu took the mouseup: it deleted
144
+ if (event && event.type === "mousedown" && (event.button !== 0 || event.ctrlKey)) return;
145
+
146
+ box.maskBox.setMotion(COLOR_MOTION + ", width " + box.holdDurationString);
147
+ box.maskBox.withMotion(function () {
148
+ box.maskBox.width = box.contentBox.width;
149
+ });
150
+
151
+ // NOTE: box.after() is a timer of the box: it can not run after remove().
152
+ box.holdTimer = box.after(box.holdDuration, function () {
153
+ box.onHoldComplete();
154
+ });
155
+ };
156
+
157
+ box.cancelHold = function () {
158
+ if (box.holdTimer) {
159
+ box.holdTimer();
160
+ box.holdTimer = null;
161
+ }
162
+
163
+ box.maskBox.setMotion(COLOR_MOTION + ", width " + CANCEL_MOTION_DURATION);
164
+ box.maskBox.withMotion(function () {
165
+ box.maskBox.width = 0;
166
+ });
167
+ };
168
+
169
+ box.onHoldComplete = function () {
170
+ box.holdTimer = null;
171
+ box.maskBox.dontMotion();
172
+ box.maskBox.width = 0;
173
+ box.clickable = 0;
174
+
175
+ box.completedBox.dontMotion();
176
+ box.completedBox.opacity = 1;
177
+
178
+ box.resetTimer = box.after(box.resetDelay, function () {
179
+ box.resetTimer = null;
180
+ box.clickable = 1;
181
+ box.completedBox.opacity = 0;
182
+ box.onReset(box);
183
+ });
184
+
185
+ if (box.onConfirm) box.onConfirm(box);
186
+ };
187
+
188
+ box.refresh = function () {
189
+ // NOTE: Nothing to draw again: the view follows the hold by itself.
190
+ };
191
+
192
+ // NOTE: No remove() of its own: the timers are box.after() timers, remove() stops them.
193
+
194
+ // *** OBJECT VIEW:
195
+ box.cursor = "pointer";
196
+ box.clickable = 1;
197
+
198
+ // GROUP: The normal button (icon, label). Its size is the size of the component.
199
+ box.contentBox = HGroup({
200
+ width: "auto",
201
+ height: "100%",
202
+ gap: box.style.layout.gap,
203
+ position: "relative",
204
+ padding: box.style.layout.padding,
205
+ align: CONTENT_ALIGN,
206
+ ...box.style.box,
207
+ });
208
+
209
+ // ICON
210
+ box.icon = Icon(0, 0, box.style.icon);
211
+ box.icon.setMotion("opacity 0.2s");
212
+ box.icon.load(box.iconFile);
213
+
214
+ // LABEL
215
+ box.label = Label(0, 0, box.style.label);
216
+ box.label.setMotion("opacity 0.2s");
217
+ setText(box.label, box.labelText);
218
+ box.label.css.whiteSpace = "nowrap";
219
+
220
+ endGroup();
221
+
222
+ // BOX: The mask grows from the left while the button is held. It shows that much of the red layer.
223
+ box.maskBox = startBox(0, 0, 0, "100%", {
224
+ color: "transparent",
225
+ });
226
+
227
+ // GROUP: The red layer (as wide as the normal button, with the same layout)
228
+ box.holdingBox = HGroup({
229
+ width: 0,
230
+ height: "100%",
231
+ gap: box.style.layout.gap,
232
+ padding: box.style.layout.padding,
233
+ align: CONTENT_ALIGN,
234
+ ...box.style.holdingBox,
235
+ });
236
+
237
+ // ICON: red
238
+ box.iconRed = Icon(0, 0, box.style.icon);
239
+ box.iconRed.load(box.holdingIconFile);
240
+
241
+ // LABEL: red
242
+ box.labelRed = Label(0, 0, box.style.holdingLabel);
243
+ setText(box.labelRed, box.labelText);
244
+ box.labelRed.css.whiteSpace = "nowrap";
245
+
246
+ // BOX: The line at the moving end of the red layer (not a part of the layout)
247
+ box.redBorder = Box({
248
+ position: "absolute",
249
+ left: 0,
250
+ top: 0,
251
+ width: 1,
252
+ height: "100%",
253
+ color: box.style.holdingBox.rightBorderColor,
254
+ });
255
+
256
+ endGroup();
257
+
258
+ endBox();
259
+
260
+ box.maskBox.onResize(moveRedBorderToMaskEnd);
261
+
262
+ syncHoldingLayer();
263
+ box.contentBox.onResize(syncHoldingLayer);
264
+
265
+ // BOX: The completed layer (shown after a full hold)
266
+ box.completedBox = startBox(0, 0, "100%", "100%", box.style.completedBox);
267
+ box.completedBox.setMotion("opacity 0.3s");
268
+
269
+ HGroup();
270
+
271
+ // LABEL: Completed text
272
+ Label(box.style.completedLabel);
273
+ setText(that, box.completedText);
274
+ that.css.whiteSpace = "nowrap";
275
+
276
+ endGroup();
277
+
278
+ endBox();
279
+
280
+ // *** OBJECT INIT CODE:
281
+
282
+ ["mousedown", "touchstart"].forEach(eventName => box.on(eventName, box.startHold));
283
+ // WHY touchcancel / contextmenu: a touch the browser cancelled (a long press) and a menu gave no touchend /
284
+ // mouseup, so the timer went on and the delete was confirmed after the user let go
285
+ ["mouseup", "touchend", "touchcancel", "mouseleave", "contextmenu"].forEach(eventName => box.on(eventName, box.cancelHold));
286
+
287
+ return endObject(box);
288
+
289
+ };