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.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,992 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Progress Bar - v26.09
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- A horizontal progress bar with a title and a value text.
|
|
9
|
+
- Determinate: value / maxValue (smooth animation when the value changes).
|
|
10
|
+
- Indeterminate: a moving bar, when the progress is not known. (Ex: "Connecting...")
|
|
11
|
+
- Status colors: "normal", "success", "error".
|
|
12
|
+
- Value text position: "top" (right of the title), "right" (right of the bar), "none".
|
|
13
|
+
- TWO PARTS: secondValue is a second part after the value (Ex: 70 done + 5 on the way);
|
|
14
|
+
its own color (style.secondBar). The value text and onComplete are of the value only. It is drawn from 0 under the
|
|
15
|
+
bar: a second part that is not transparent ("ozden") looks like a second bar next to it; bar.joinEdge: 0 leaves
|
|
16
|
+
out the edge of the bar between them, the two colors meet ("ozden").
|
|
17
|
+
- STRIPES: stripes: 1 (the value) and secondStripes: 1 (the second part) draw light diagonal stripes that move
|
|
18
|
+
slowly (a job is running); setStripes() / setSecondStripes(). Still with prefers-reduced-motion. (style.stripes)
|
|
19
|
+
- LIMITS: limits: [80] or [{ value: 30, color: "#7BA7D9" }, { value: 80, text: "80" }]: marks at these values (in
|
|
20
|
+
the units of value / maxValue), a text under a mark (style.limit); setLimits(). limit.shape "line": a line over the
|
|
21
|
+
bar, a little longer than it; "dot" ("ozden"): a dot inside the track that has the color of
|
|
22
|
+
the part under it (limit.barColor on the bar, secondBarColor on the second part, color on the track; on a dark
|
|
23
|
+
track darkTrack.limitColor), half and half while the end of the bar goes over it. The own color of a limit is
|
|
24
|
+
its color on the track. limit.dotOpacity: every dot ("ozden": 0.85).
|
|
25
|
+
- Style packages: "light" (default; the old name "classic" works too) and "dark" (the light and dark look of the kit: a
|
|
26
|
+
thin round track of 10 px with no edge, the bar in the accent: _designs/progress-bar.htm), "modern", "ozden" (the bar is a cyan SmartButton
|
|
27
|
+
ozden, with its edge and its line at the bottom; a round track, the second part a light bar next to it; a dark
|
|
28
|
+
limit line with a text). "ozdenDark" (for a dark page). Select with styleName.
|
|
29
|
+
(ProgressBar.styles)
|
|
30
|
+
- THE ENDS: an end of a bar at an end of the track is as round as the track; an end in the middle of the track has
|
|
31
|
+
style.bar.innerRound ("": as round as the track; "ozden": 0, straight).
|
|
32
|
+
- A DARK TRACK: darkTrack: 1 gives the track the colors of style.darkTrack (#242424 with a faint white edge;
|
|
33
|
+
"ozden": Black(0.85) with no edge); the bars keep theirs. setDarkTrack().
|
|
34
|
+
- THE TRACK of the base (ProgressBarDefaults.style): 16 px, #F2F2F2, a 2 px light gray edge, round 4 ("light",
|
|
35
|
+
"dark" and "modern" have their own: 10 px, no edge, round ends; "ozden" has round ends).
|
|
36
|
+
- Everything is drawn with code (no image files needed).
|
|
37
|
+
|
|
38
|
+
NOTE: comp/line-progress-bar.js (vertical lines style) is named LineProgressBar, so both can be loaded on the same page.
|
|
39
|
+
|
|
40
|
+
Started Date: September 2026
|
|
41
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
42
|
+
|
|
43
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
44
|
+
Licensed under the Apache License, Version 2.0
|
|
45
|
+
SPDX-License-Identifier: Apache-2.0
|
|
46
|
+
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
"use strict";
|
|
50
|
+
|
|
51
|
+
// Default values:
|
|
52
|
+
const ProgressBarDefaults = {
|
|
53
|
+
key: "0",
|
|
54
|
+
width: 320,
|
|
55
|
+
height: "auto",
|
|
56
|
+
value: 0, // 0 - maxValue
|
|
57
|
+
secondValue: 0, // A second part after the value (value + secondValue <= maxValue). 0: none
|
|
58
|
+
maxValue: 100,
|
|
59
|
+
stripes: 0, // 1: moving stripes on the value part
|
|
60
|
+
secondStripes: 0, // 1: moving stripes on the second part
|
|
61
|
+
limits: [], // Lines at these values: [80] or [{ value: 80, color: "indianred" }]
|
|
62
|
+
darkTrack: 0, // 1: the track in the colors of style.darkTrack (the bars keep theirs)
|
|
63
|
+
indeterminate: 0, // 1: Progress is not known, show a moving bar.
|
|
64
|
+
status: "normal", // "normal", "success", "error"
|
|
65
|
+
titleText: "",
|
|
66
|
+
allowHtml: 0, // 1: titleText and the text of valueFormat are HTML (only for your own texts)
|
|
67
|
+
valuePosition: "top", // "top", "right", "none" (Only at create time)
|
|
68
|
+
valueFormat: function (self) { // Returns the value text.
|
|
69
|
+
return Math.round(self.getPercent()) + "%";
|
|
70
|
+
},
|
|
71
|
+
onChange: function (self) { }, // self.value
|
|
72
|
+
onComplete: function (self) { }, // Called once when the value reaches maxValue.
|
|
73
|
+
styleName: "light", // "light" ("classic": its old name), "dark", "modern", "ozden", "ozdenDark", "minimal", "minimalDark" or a name added to ProgressBar.styles
|
|
74
|
+
style: { // The base of every package (a thin dark bar on a light gray track): a package changes only some keys
|
|
75
|
+
layout: {
|
|
76
|
+
gap: 6, // Space between the title row and the bar
|
|
77
|
+
},
|
|
78
|
+
track: { // Background of the bar
|
|
79
|
+
height: 16,
|
|
80
|
+
color: "#F2F2F2",
|
|
81
|
+
round: 4,
|
|
82
|
+
border: 2,
|
|
83
|
+
borderColor: "rgba(0, 0, 0, 0.1)",
|
|
84
|
+
css: {}, // Ex: { backgroundImage: "linear-gradient(#EEE, #D0D0D0)" }
|
|
85
|
+
},
|
|
86
|
+
darkTrack: { // The track with darkTrack: 1 (its size and its round are of track)
|
|
87
|
+
color: "#242424",
|
|
88
|
+
borderColor: White(0.4),
|
|
89
|
+
limitColor: White(0.7), // a limit dot on it (limit.shape "dot")
|
|
90
|
+
},
|
|
91
|
+
bar: {
|
|
92
|
+
color: "#141414", // the main color (also of the edge, when borderColor is "")
|
|
93
|
+
fillOpacity: 1, // the inside of the bar: the main color at this opacity (Ex: 0.5 with an edge of 1)
|
|
94
|
+
border: 0,
|
|
95
|
+
borderColor: "", // "": the main color (of the status too)
|
|
96
|
+
boxShadow: "none", // of both parts (Ex: "inset 0 -2px 0 rgba(0, 0, 0, 0.25)": a line at the bottom)
|
|
97
|
+
innerRound: "", // px: an end in the middle of the track (0: straight). "": as round as the track
|
|
98
|
+
joinEdge: 1, // 0: no edge of the bar where the second part starts (the two colors meet)
|
|
99
|
+
motion: 0.3, // Seconds. 0: No animation
|
|
100
|
+
},
|
|
101
|
+
secondBar: { // The second part (secondValue)
|
|
102
|
+
color: Black(0.35), // "": the main color, lighter (it follows the main color: fillOpacity or lighten)
|
|
103
|
+
fillOpacity: 0.2, // (color "") the main color at this opacity
|
|
104
|
+
lighten: 0, // 0 - 1 (color ""): the main color mixed with this much white, not transparent; 0: fillOpacity
|
|
105
|
+
borderOpacity: 0.45, // its edge (when the bar has one): the main color at this opacity
|
|
106
|
+
},
|
|
107
|
+
stripes: {
|
|
108
|
+
color: "rgba(255, 255, 255, 0.35)",
|
|
109
|
+
size: 14, // px: one stripe and its gap
|
|
110
|
+
speed: 0.8, // seconds for one step of the stripes
|
|
111
|
+
},
|
|
112
|
+
limit: {
|
|
113
|
+
shape: "line", // "line": over the track, a little longer; "dot": inside the track, in the color of the part under it
|
|
114
|
+
color: "indianred", // (a limit can have its own color) a dot: on the track
|
|
115
|
+
width: 1, // px (a line)
|
|
116
|
+
round: 0,
|
|
117
|
+
overhang: 6, // px over and under the track (a line)
|
|
118
|
+
dotSize: 6, // px (a dot)
|
|
119
|
+
dotOpacity: 1, // a dot, on every part (Ex: 0.85: a little softer)
|
|
120
|
+
barColor: "white", // a dot on the bar
|
|
121
|
+
secondBarColor: "", // a dot on the second part ("": the main color)
|
|
122
|
+
textSize: 13, // the text of a limit ({ value, text }) under it
|
|
123
|
+
textColor: Black(0.7),
|
|
124
|
+
textSpace: 6, // px between the line (or the track) and its text
|
|
125
|
+
},
|
|
126
|
+
successBar: {
|
|
127
|
+
color: "#2E9E5B",
|
|
128
|
+
},
|
|
129
|
+
errorBar: {
|
|
130
|
+
color: "#D64545",
|
|
131
|
+
},
|
|
132
|
+
title: {
|
|
133
|
+
fontSize: 14,
|
|
134
|
+
textColor: Black(0.8),
|
|
135
|
+
},
|
|
136
|
+
valueText: {
|
|
137
|
+
fontSize: 14,
|
|
138
|
+
textColor: Black(0.55),
|
|
139
|
+
},
|
|
140
|
+
indeterminate: {
|
|
141
|
+
barWidth: 35, // Percent of the track width
|
|
142
|
+
duration: 1.4, // Seconds for one move
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const ProgressBar = function (params = {}) {
|
|
148
|
+
|
|
149
|
+
// Merge style package: params.style > ProgressBar.styles[styleName] > ProgressBarDefaults.style (the base)
|
|
150
|
+
basic.applyStylePackage(params, ProgressBar.styles, ProgressBarDefaults);
|
|
151
|
+
|
|
152
|
+
// Merge params:
|
|
153
|
+
mergeIntoIfMissing(params, ProgressBarDefaults);
|
|
154
|
+
|
|
155
|
+
// Edit params, if needed:
|
|
156
|
+
params.color = "transparent";
|
|
157
|
+
|
|
158
|
+
// BOX: Component container
|
|
159
|
+
let box = startObject(params);
|
|
160
|
+
|
|
161
|
+
// *** PRIVATE VARIABLES:
|
|
162
|
+
let moveAnimation = null; // Indeterminate animation (Web Animations API)
|
|
163
|
+
const ROW_GAP = 10; // Space between the title and the value text, the track and the value text
|
|
164
|
+
const COLOR_MOTION = "background-color 0.2s";
|
|
165
|
+
|
|
166
|
+
// *** PUBLIC VARIABLES:
|
|
167
|
+
// NOTE: Default values are also public variables. (box.value, box.maxValue, box.status)
|
|
168
|
+
|
|
169
|
+
// *** PRIVATE FUNCTIONS:
|
|
170
|
+
|
|
171
|
+
const setText = function (label, text) {
|
|
172
|
+
const value = (text === undefined || text === null) ? "" : String(text);
|
|
173
|
+
if (box.allowHtml == 1) label.text = value;
|
|
174
|
+
else label.plainText = value;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const clampValue = function (value) {
|
|
178
|
+
value = Number(value);
|
|
179
|
+
if (isNaN(value)) value = 0;
|
|
180
|
+
return Math.min(Math.max(value, 0), box.maxValue);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const getBarMotion = function () {
|
|
184
|
+
return "width " + box.style.bar.motion + "s, " + COLOR_MOTION;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Change the bar size without animation. (Ex: from the moving bar to the value)
|
|
188
|
+
const updateViewWithoutMotion = function () {
|
|
189
|
+
box.bar.setMotionNow("none");
|
|
190
|
+
box.secondBar.setMotionNow("none");
|
|
191
|
+
updateView();
|
|
192
|
+
box.bar.elem.offsetWidth; // WHY: Apply the new width before the motion is turned on again.
|
|
193
|
+
box.bar.setMotionNow(getBarMotion());
|
|
194
|
+
box.secondBar.setMotionNow(getBarMotion());
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// The second part fits in what the value leaves (value + secondValue <= maxValue)
|
|
198
|
+
const clampSecondValue = function (value) {
|
|
199
|
+
value = Number(value);
|
|
200
|
+
if (isNaN(value) || value < 0) value = 0;
|
|
201
|
+
return Math.min(value, Math.max(0, box.maxValue - box.value));
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const toPercent = function (value) {
|
|
205
|
+
return (box.maxValue > 0) ? (value / box.maxValue) * 100 : 0;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// The inside and the edge of a part from its main color (a status changes the main color)
|
|
209
|
+
const paintPart = function (bar, mainColor, fillOpacity, edgeColor) {
|
|
210
|
+
bar.color = (fillOpacity < 1) ? Alpha(mainColor, fillOpacity) : mainColor;
|
|
211
|
+
if (box.style.bar.border) bar.borderColor = edgeColor;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const paintBars = function () {
|
|
215
|
+
const _b = box.style.bar;
|
|
216
|
+
const mainColor = getBarColor();
|
|
217
|
+
paintPart(box.bar, mainColor, Number(_b.fillOpacity), _b.borderColor || mainColor);
|
|
218
|
+
paintSecondBar(mainColor);
|
|
219
|
+
box.bar.boxShadow = _b.boxShadow;
|
|
220
|
+
box.secondBar.boxShadow = _b.boxShadow;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// WHY color "": the second part follows the main color (one color to change for a new look)
|
|
224
|
+
const paintSecondBar = function (mainColor) {
|
|
225
|
+
const _b = box.style.bar;
|
|
226
|
+
const _sb = box.style.secondBar;
|
|
227
|
+
if (_sb.color) {
|
|
228
|
+
paintPart(box.secondBar, _sb.color, 1, _b.borderColor || mainColor);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (Number(_sb.lighten) > 0) {
|
|
232
|
+
paintPart(box.secondBar, mixWithWhite(mainColor, Number(_sb.lighten)), 1, _b.borderColor || mainColor);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
paintPart(box.secondBar, mainColor, Number(_sb.fillOpacity), _b.borderColor || Alpha(mainColor, Number(_sb.borderOpacity)));
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// A lighter color that is not transparent: the track does not show through it (Ex: a dark track)
|
|
239
|
+
const mixWithWhite = function (color, whiteShare) {
|
|
240
|
+
const colorPercent = Math.round((1 - whiteShare) * 100);
|
|
241
|
+
return "color-mix(in srgb, " + color + " " + colorPercent + "%, white)";
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// The track: its own colors, or the dark ones (darkTrack: 1)
|
|
245
|
+
const paintTrack = function () {
|
|
246
|
+
const colors = (box.darkTrack == 1) ? box.style.darkTrack : box.style.track;
|
|
247
|
+
box.track.color = colors.color;
|
|
248
|
+
box.track.borderColor = colors.borderColor;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// THE ENDS: an end at an end of the track is as round as the track (its edge follows the round of the track);
|
|
252
|
+
// an end in the middle of the track has bar.innerRound. The moving bar of indeterminate is round at both ends.
|
|
253
|
+
const paintEnds = function () {
|
|
254
|
+
const isBarAtRightEnd = (box.indeterminate == 1) || (box.value >= box.maxValue);
|
|
255
|
+
const isSecondAtRightEnd = (box.value + box.secondValue >= box.maxValue);
|
|
256
|
+
setEnds(box.bar, 1, isBarAtRightEnd);
|
|
257
|
+
setEnds(box.secondBar, 1, isSecondAtRightEnd);
|
|
258
|
+
paintJoin();
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// bar.joinEdge 0: where the second part starts, the bar has no edge: the two colors meet
|
|
262
|
+
const paintJoin = function () {
|
|
263
|
+
const hasSecondAfter = (box.indeterminate != 1) && (box.value > 0) && (box.secondValue > 0);
|
|
264
|
+
const isSeamless = hasSecondAfter && (box.style.bar.joinEdge == 0);
|
|
265
|
+
box.bar.css = { borderRightWidth: (isSeamless ? 0 : box.style.bar.border) + "px" };
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const setEnds = function (bar, isLeftAtEnd, isRightAtEnd) {
|
|
269
|
+
const left = (isLeftAtEnd ? box.style.track.round : getInnerRound()) + "px";
|
|
270
|
+
const right = (isRightAtEnd ? box.style.track.round : getInnerRound()) + "px";
|
|
271
|
+
bar.css = { borderRadius: left + " " + right + " " + right + " " + left };
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const getInnerRound = function () {
|
|
275
|
+
const innerRound = box.style.bar.innerRound;
|
|
276
|
+
if (innerRound === "" || innerRound === undefined || innerRound === null) return box.style.track.round;
|
|
277
|
+
return Number(innerRound);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// The moving stripes: a CSS class with the colors of style.stripes (css variables)
|
|
281
|
+
const paintStripes = function (bar, isOn) {
|
|
282
|
+
ProgressBar.injectCss();
|
|
283
|
+
const _st = box.style.stripes;
|
|
284
|
+
bar.elem.classList.toggle("progress-bar-stripes", !!isOn);
|
|
285
|
+
bar.elem.style.setProperty("--progress-stripe-color", _st.color);
|
|
286
|
+
bar.elem.style.setProperty("--progress-stripe-size", _st.size + "px");
|
|
287
|
+
bar.elem.style.setProperty("--progress-stripe-speed", _st.speed + "s");
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// LIMITS: lines over the track (limit.shape "line") or dots inside it ("dot"), and their texts
|
|
291
|
+
const drawLimits = function () {
|
|
292
|
+
box.limitLines.forEach(function (line) { line.remove(); });
|
|
293
|
+
box.limitDots.forEach(function (item) { item.dot.remove(); });
|
|
294
|
+
box.limitLines = [];
|
|
295
|
+
box.limitDots = [];
|
|
296
|
+
if (isDotLimit()) drawLimitDots();
|
|
297
|
+
else drawLimitLines();
|
|
298
|
+
drawLimitTexts();
|
|
299
|
+
layoutTrackArea();
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const drawLimitLines = function () {
|
|
303
|
+
const _l = box.style.limit;
|
|
304
|
+
const lineHeight = box.style.track.height + _l.overhang * 2;
|
|
305
|
+
createIn(box.trackArea, function () {
|
|
306
|
+
getLimitList().forEach(function (limit) {
|
|
307
|
+
const line = Box({ top: 0, width: _l.width, height: lineHeight, color: limit.color || _l.color, round: _l.round });
|
|
308
|
+
line.css = { left: "calc(" + getLimitLeft(limit) + " - " + (_l.width / 2) + "px)" };
|
|
309
|
+
box.limitLines.push(line);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// A dot for each limit in each holder of dots: the holder of the track is under the bars, the others are inside
|
|
315
|
+
// the bars. So a bar shows its own dots where it is (also half a dot at its end) and covers the dots of the track.
|
|
316
|
+
const drawLimitDots = function () {
|
|
317
|
+
const holders = { track: box.trackDots, second: box.secondDots, bar: box.barDots };
|
|
318
|
+
Object.keys(holders).forEach(function (part) {
|
|
319
|
+
const edge = (part === "track") ? 0 : box.style.bar.border; // (a holder in a bar starts inside its edge)
|
|
320
|
+
createIn(holders[part], function () {
|
|
321
|
+
getLimitList().forEach(function (limit) {
|
|
322
|
+
box.limitDots.push({ dot: createLimitDot(limit, edge), part: part, limit: limit });
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
paintLimitDots();
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// BOX: A dot in the middle of the track, at the place of its limit.
|
|
330
|
+
// WHY cqw: the bar layer is a size container, so a dot inside a bar is placed on the width of the track
|
|
331
|
+
const createLimitDot = function (limit, edge) {
|
|
332
|
+
const size = box.style.limit.dotSize;
|
|
333
|
+
const dot = Box({ top: (box.style.track.height - size) / 2 - edge, width: size, height: size, round: size / 2, opacity: box.style.limit.dotOpacity });
|
|
334
|
+
dot.css = { left: "calc(" + getLimitPercent(limit) + "cqw - " + (edge + size / 2) + "px)" };
|
|
335
|
+
return dot;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// LABEL: the text of a limit, under its line (or under the track)
|
|
339
|
+
const drawLimitTexts = function () {
|
|
340
|
+
const _l = box.style.limit;
|
|
341
|
+
const top = box.style.track.height + getOverhang() * 2 + _l.textSpace;
|
|
342
|
+
createIn(box.trackArea, function () {
|
|
343
|
+
getLimitList().forEach(function (limit) {
|
|
344
|
+
if (limit.text === undefined || limit.text === "") return;
|
|
345
|
+
const text = Label({ top: top, fontSize: _l.textSize, textColor: limit.color || _l.textColor });
|
|
346
|
+
text.plainText = limit.text;
|
|
347
|
+
text.css = { left: getLimitLeft(limit), transform: "translateX(-50%)", whiteSpace: "nowrap" };
|
|
348
|
+
box.limitLines.push(text);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const isDotLimit = function () {
|
|
354
|
+
return box.style.limit.shape === "dot";
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// A limit is a number or { value, color, text }; one without a number value is left out
|
|
358
|
+
const getLimitList = function () {
|
|
359
|
+
const list = box.limits.map(function (limit) {
|
|
360
|
+
return (typeof limit === "object" && limit !== null) ? limit : { value: limit };
|
|
361
|
+
});
|
|
362
|
+
return list.filter(function (limit) { return !isNaN(Number(limit.value)); });
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const getLimitPercent = function (limit) {
|
|
366
|
+
return toPercent(Math.min(Math.max(Number(limit.value), 0), box.maxValue));
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const getLimitLeft = function (limit) {
|
|
370
|
+
return getLimitPercent(limit) + "%";
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// px of a limit line over and under the track (a dot is inside it)
|
|
374
|
+
const getOverhang = function () {
|
|
375
|
+
const hasLines = (box.limits.length > 0) && !isDotLimit();
|
|
376
|
+
return hasLines ? box.style.limit.overhang : 0;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// The color of a dot is of the part under it; the own color of a limit is its color on the track
|
|
380
|
+
const paintLimitDots = function () {
|
|
381
|
+
box.limitDots.forEach(function (item) {
|
|
382
|
+
item.dot.color = getDotColor(item.part, item.limit);
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const getDotColor = function (part, limit) {
|
|
387
|
+
const _l = box.style.limit;
|
|
388
|
+
if (part === "bar") return _l.barColor;
|
|
389
|
+
if (part === "second") return _l.secondBarColor || getBarColor();
|
|
390
|
+
if (limit.color) return limit.color;
|
|
391
|
+
return (box.darkTrack == 1) ? box.style.darkTrack.limitColor : _l.color;
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// BOX: A holder of the limit dots, as big as the bar (or the track) it is in
|
|
395
|
+
const createDotHolder = function () {
|
|
396
|
+
return Box({ left: 0, top: 0, width: "100%", height: "100%", color: "transparent" });
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// The track (and the bars over it) are in the middle of the area; the area is taller with limit lines, and
|
|
400
|
+
// with room for their texts
|
|
401
|
+
const layoutTrackArea = function () {
|
|
402
|
+
const _t = box.style.track;
|
|
403
|
+
const _l = box.style.limit;
|
|
404
|
+
const hasText = box.limits.some(function (limit) { return limit && typeof limit === "object" && limit.text !== undefined && limit.text !== ""; });
|
|
405
|
+
const overhang = getOverhang();
|
|
406
|
+
box.trackArea.height = _t.height + overhang * 2 + (hasText ? _l.textSpace + Math.ceil(_l.textSize * 1.4) : 0);
|
|
407
|
+
box.track.top = overhang;
|
|
408
|
+
box.barLayer.top = overhang;
|
|
409
|
+
alignRightValue(overhang, hasText);
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// WHY: the room of the limit texts is under the track; a value text at the right stays in line with the track
|
|
413
|
+
const alignRightValue = function (overhang, hasText) {
|
|
414
|
+
if (!box.valueLabel || box.valuePosition !== "right") return;
|
|
415
|
+
if (!hasText) {
|
|
416
|
+
box.valueLabel.css = { alignSelf: "", marginTop: "" };
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const LINE_HEIGHT = 1.36; // of the font size (Open Sans)
|
|
420
|
+
const textHeight = box.style.valueText.fontSize * LINE_HEIGHT;
|
|
421
|
+
box.valueLabel.css = { alignSelf: "flex-start", marginTop: Math.round(overhang + (box.style.track.height - textHeight) / 2) + "px" };
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
const getBarColor = function () {
|
|
425
|
+
if (box.status === "success") return box.style.successBar.color;
|
|
426
|
+
if (box.status === "error") return box.style.errorBar.color;
|
|
427
|
+
return box.style.bar.color;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const startMoveAnimation = function () {
|
|
431
|
+
if (moveAnimation || !box.bar.elem.animate) return;
|
|
432
|
+
// WHY: translateX(%) is relative to the bar width. The bar starts outside on the left and ends outside on the right.
|
|
433
|
+
const _endPercent = Math.ceil(100 / box.style.indeterminate.barWidth * 100);
|
|
434
|
+
moveAnimation = box.bar.elem.animate([
|
|
435
|
+
{ transform: "translateX(-100%)" },
|
|
436
|
+
{ transform: "translateX(" + _endPercent + "%)" },
|
|
437
|
+
], {
|
|
438
|
+
duration: box.style.indeterminate.duration * 1000,
|
|
439
|
+
iterations: Infinity,
|
|
440
|
+
easing: "ease-in-out",
|
|
441
|
+
});
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const stopMoveAnimation = function () {
|
|
445
|
+
if (!moveAnimation) return;
|
|
446
|
+
moveAnimation.cancel();
|
|
447
|
+
moveAnimation = null;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
// Update the view according to the current state.
|
|
451
|
+
const updateView = function () {
|
|
452
|
+
|
|
453
|
+
paintBars();
|
|
454
|
+
|
|
455
|
+
if (box.indeterminate == 1) {
|
|
456
|
+
box.bar.visible = 1;
|
|
457
|
+
box.bar.width = box.style.indeterminate.barWidth + "%";
|
|
458
|
+
box.secondBar.visible = 0;
|
|
459
|
+
box.barDots.visible = 0; // WHY: the moving bar would carry the dots of the limits with it
|
|
460
|
+
startMoveAnimation();
|
|
461
|
+
box.aria = { valuenow: null };
|
|
462
|
+
} else {
|
|
463
|
+
stopMoveAnimation();
|
|
464
|
+
box.bar.width = box.getPercent() + "%";
|
|
465
|
+
box.bar.visible = (box.value > 0) ? 1 : 0; // WHY: a bar with an edge was a thin line at 0
|
|
466
|
+
box.barDots.visible = 1;
|
|
467
|
+
// WHY from 0: the second bar is under the first one, so their round ends meet as one bar
|
|
468
|
+
box.secondValue = clampSecondValue(box.secondValue);
|
|
469
|
+
box.secondBar.width = toPercent(box.value + box.secondValue) + "%";
|
|
470
|
+
box.secondBar.visible = (box.secondValue > 0) ? 1 : 0;
|
|
471
|
+
box.aria = { valuenow: String(box.value) };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
paintEnds();
|
|
475
|
+
paintLimitDots();
|
|
476
|
+
|
|
477
|
+
if (box.valueLabel) {
|
|
478
|
+
setText(box.valueLabel, (box.indeterminate == 1) ? "" : box.valueFormat(box));
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
box.aria = { valuemax: String(box.maxValue) };
|
|
482
|
+
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// *** PUBLIC FUNCTIONS:
|
|
486
|
+
|
|
487
|
+
box.getPercent = function () {
|
|
488
|
+
return (box.maxValue > 0) ? (box.value / box.maxValue) * 100 : 0;
|
|
489
|
+
};
|
|
490
|
+
// USAGE: progressBar.getPercent() // 0 - 100
|
|
491
|
+
|
|
492
|
+
box.setValue = function (value, silent = 0) {
|
|
493
|
+
|
|
494
|
+
value = clampValue(value);
|
|
495
|
+
if (box.value == value && box.indeterminate != 1) return;
|
|
496
|
+
|
|
497
|
+
const _wasComplete = (box.value >= box.maxValue);
|
|
498
|
+
box.value = value;
|
|
499
|
+
|
|
500
|
+
if (box.indeterminate == 1) {
|
|
501
|
+
box.indeterminate = 0; // A known value ends the indeterminate mode.
|
|
502
|
+
updateViewWithoutMotion();
|
|
503
|
+
} else {
|
|
504
|
+
updateView();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (!silent) {
|
|
508
|
+
box.onChange(box);
|
|
509
|
+
if (!_wasComplete && box.value >= box.maxValue) box.onComplete(box);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
};
|
|
513
|
+
// USAGE: get: progressBar.value, set: progressBar.setValue(40)
|
|
514
|
+
// NOTE: setValue(40, 1) changes the value without calling onChange and onComplete.
|
|
515
|
+
|
|
516
|
+
box.setSecondValue = function (value) {
|
|
517
|
+
box.secondValue = clampSecondValue(value);
|
|
518
|
+
updateView();
|
|
519
|
+
};
|
|
520
|
+
// USAGE: get: progressBar.secondValue, set: progressBar.setSecondValue(5) // Ex: 70 + 5
|
|
521
|
+
|
|
522
|
+
// Both parts at once (Ex: setValues(70, 5))
|
|
523
|
+
box.setValues = function (value, secondValue, silent = 0) {
|
|
524
|
+
box.secondValue = 0; // WHY: the value is set first, the second part fits in what it leaves
|
|
525
|
+
box.setValue(value, silent);
|
|
526
|
+
box.setSecondValue(secondValue);
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
box.setStripes = function (value) {
|
|
530
|
+
box.stripes = basic.isOn(value) ? 1 : 0;
|
|
531
|
+
paintStripes(box.bar, box.stripes);
|
|
532
|
+
};
|
|
533
|
+
// USAGE: get: progressBar.stripes, set: progressBar.setStripes(1)
|
|
534
|
+
|
|
535
|
+
box.setSecondStripes = function (value) {
|
|
536
|
+
box.secondStripes = basic.isOn(value) ? 1 : 0;
|
|
537
|
+
paintStripes(box.secondBar, box.secondStripes);
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
box.setDarkTrack = function (value) {
|
|
541
|
+
box.darkTrack = basic.isOn(value) ? 1 : 0;
|
|
542
|
+
paintTrack();
|
|
543
|
+
paintLimitDots();
|
|
544
|
+
};
|
|
545
|
+
// USAGE: get: progressBar.darkTrack, set: progressBar.setDarkTrack(1) // the colors of style.darkTrack
|
|
546
|
+
|
|
547
|
+
box.setLimits = function (limits) {
|
|
548
|
+
box.limits = Array.isArray(limits) ? limits.slice() : [];
|
|
549
|
+
drawLimits();
|
|
550
|
+
};
|
|
551
|
+
// USAGE: progressBar.setLimits([{ value: 30, color: "#7BA7D9" }, 80])
|
|
552
|
+
|
|
553
|
+
box.addValue = function (step = 1) {
|
|
554
|
+
box.setValue(box.value + step);
|
|
555
|
+
};
|
|
556
|
+
// USAGE: progressBar.addValue(10)
|
|
557
|
+
|
|
558
|
+
box.setMaxValue = function (value) {
|
|
559
|
+
value = Number(value);
|
|
560
|
+
box.maxValue = (isNaN(value) || value < 0) ? 0 : value;
|
|
561
|
+
box.value = clampValue(box.value);
|
|
562
|
+
updateView();
|
|
563
|
+
drawLimits(); // (the places of the limits are relative to maxValue)
|
|
564
|
+
};
|
|
565
|
+
// USAGE: get: progressBar.maxValue, set: progressBar.setMaxValue(20) // Ex: 20 files
|
|
566
|
+
|
|
567
|
+
box.setIndeterminate = function (indeterminate) {
|
|
568
|
+
box.indeterminate = basic.isOn(indeterminate) ? 1 : 0;
|
|
569
|
+
updateViewWithoutMotion(); // WHY: No width animation between the moving bar size and the value.
|
|
570
|
+
};
|
|
571
|
+
// USAGE: get: progressBar.indeterminate, set: progressBar.setIndeterminate(1)
|
|
572
|
+
|
|
573
|
+
box.setStatus = function (status) {
|
|
574
|
+
box.status = (status === "success" || status === "error") ? status : "normal";
|
|
575
|
+
updateView();
|
|
576
|
+
};
|
|
577
|
+
// USAGE: get: progressBar.status, set: progressBar.setStatus("success")
|
|
578
|
+
|
|
579
|
+
box.setTitleText = function (text) {
|
|
580
|
+
box.titleText = text;
|
|
581
|
+
setText(box.titleLabel, text);
|
|
582
|
+
box.titleLabel.visible = (text) ? 1 : 0;
|
|
583
|
+
updateTopRow();
|
|
584
|
+
};
|
|
585
|
+
// USAGE: get: progressBar.titleText, set: progressBar.setTitleText("Uploading...")
|
|
586
|
+
|
|
587
|
+
box.reset = function () {
|
|
588
|
+
box.indeterminate = 0;
|
|
589
|
+
box.status = "normal";
|
|
590
|
+
box.value = 0;
|
|
591
|
+
box.secondValue = 0;
|
|
592
|
+
updateViewWithoutMotion();
|
|
593
|
+
};
|
|
594
|
+
// USAGE: progressBar.reset() // value: 0, status: "normal"
|
|
595
|
+
|
|
596
|
+
box.refresh = function () {
|
|
597
|
+
paintTrack();
|
|
598
|
+
updateView();
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
// *** OBJECT VIEW:
|
|
603
|
+
box.role = "progressbar";
|
|
604
|
+
box.aria = { valuemin: "0" };
|
|
605
|
+
|
|
606
|
+
// GROUP: Top row, bar row
|
|
607
|
+
box.contentBox = VGroup({
|
|
608
|
+
width: "100%",
|
|
609
|
+
height: "auto",
|
|
610
|
+
align: "left top",
|
|
611
|
+
gap: box.style.layout.gap,
|
|
612
|
+
position: "relative",
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
// GROUP: Top row (title, value text)
|
|
616
|
+
box.topRow = HGroup({
|
|
617
|
+
width: "100%",
|
|
618
|
+
height: "auto",
|
|
619
|
+
align: "left center",
|
|
620
|
+
gap: ROW_GAP,
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// LABEL: Title
|
|
624
|
+
box.titleLabel = Label(box.style.title);
|
|
625
|
+
setText(box.titleLabel, box.titleText);
|
|
626
|
+
box.titleLabel.css = { flex: "1 1 auto", minWidth: "0" };
|
|
627
|
+
box.titleLabel.ellipsis = 1;
|
|
628
|
+
if (!box.titleText) box.titleLabel.visible = 0;
|
|
629
|
+
|
|
630
|
+
// LABEL: Value text (top)
|
|
631
|
+
if (box.valuePosition === "top") {
|
|
632
|
+
box.valueLabel = Label(box.style.valueText);
|
|
633
|
+
box.valueLabel.css = {
|
|
634
|
+
marginLeft: "auto", // WHY: At the right side, also without a title.
|
|
635
|
+
whiteSpace: "nowrap",
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
endGroup();
|
|
640
|
+
|
|
641
|
+
// GROUP: Bar row (track, value text)
|
|
642
|
+
box.barRow = HGroup({
|
|
643
|
+
width: "100%",
|
|
644
|
+
height: "auto",
|
|
645
|
+
align: "left center",
|
|
646
|
+
gap: ROW_GAP,
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
// BOX: Track area (the track and the limit lines over it; the lines are longer than the track)
|
|
650
|
+
box.trackArea = startBox({ width: "auto", height: box.style.track.height, color: "transparent" });
|
|
651
|
+
box.trackArea.clipContent = 0;
|
|
652
|
+
box.trackArea.css = { flex: "1 1 0", minWidth: "0", position: "relative" };
|
|
653
|
+
|
|
654
|
+
// BOX: Track
|
|
655
|
+
box.track = startBox({
|
|
656
|
+
left: 0,
|
|
657
|
+
top: 0,
|
|
658
|
+
width: "100%",
|
|
659
|
+
height: box.style.track.height,
|
|
660
|
+
color: box.style.track.color,
|
|
661
|
+
round: box.style.track.round,
|
|
662
|
+
border: box.style.track.border,
|
|
663
|
+
borderColor: box.style.track.borderColor,
|
|
664
|
+
});
|
|
665
|
+
box.track.css = box.style.track.css || {};
|
|
666
|
+
|
|
667
|
+
endBox();
|
|
668
|
+
|
|
669
|
+
// BOX: Bar layer (over the track, as big as it: a bar covers the edge of the track; it clips the
|
|
670
|
+
// moving bar of indeterminate)
|
|
671
|
+
box.barLayer = startBox({
|
|
672
|
+
left: 0,
|
|
673
|
+
top: 0,
|
|
674
|
+
width: "100%",
|
|
675
|
+
height: box.style.track.height,
|
|
676
|
+
color: "transparent",
|
|
677
|
+
round: box.style.track.round,
|
|
678
|
+
});
|
|
679
|
+
box.barLayer.clipContent = 1;
|
|
680
|
+
box.barLayer.css = { containerType: "inline-size" }; // WHY: the dots of the limits are placed in cqw
|
|
681
|
+
|
|
682
|
+
// BOX: The dots of the limits on the track (limit.shape "dot"), under the bars
|
|
683
|
+
box.trackDots = createDotHolder();
|
|
684
|
+
|
|
685
|
+
// BOX: Second part (under the bar, from 0 to value + secondValue)
|
|
686
|
+
box.secondBar = startBox({
|
|
687
|
+
left: 0,
|
|
688
|
+
top: 0,
|
|
689
|
+
width: "0%",
|
|
690
|
+
height: "100%",
|
|
691
|
+
color: box.style.secondBar.color,
|
|
692
|
+
round: box.style.track.round,
|
|
693
|
+
border: box.style.bar.border,
|
|
694
|
+
borderColor: box.style.bar.borderColor,
|
|
695
|
+
});
|
|
696
|
+
box.secondDots = createDotHolder();
|
|
697
|
+
endBox();
|
|
698
|
+
|
|
699
|
+
// BOX: Bar
|
|
700
|
+
box.bar = startBox({
|
|
701
|
+
left: 0,
|
|
702
|
+
top: 0,
|
|
703
|
+
width: "0%",
|
|
704
|
+
height: "100%",
|
|
705
|
+
color: getBarColor(),
|
|
706
|
+
round: box.style.track.round,
|
|
707
|
+
border: box.style.bar.border,
|
|
708
|
+
borderColor: box.style.bar.borderColor,
|
|
709
|
+
});
|
|
710
|
+
box.barDots = createDotHolder();
|
|
711
|
+
endBox();
|
|
712
|
+
|
|
713
|
+
endBox();
|
|
714
|
+
|
|
715
|
+
endBox();
|
|
716
|
+
|
|
717
|
+
// LABEL: Value text (right)
|
|
718
|
+
if (box.valuePosition === "right") {
|
|
719
|
+
box.valueLabel = Label(box.style.valueText);
|
|
720
|
+
box.valueLabel.css = {
|
|
721
|
+
whiteSpace: "nowrap",
|
|
722
|
+
minWidth: "3em", // WHY: The bar width does not jump when the text changes. (9% -> 10%)
|
|
723
|
+
};
|
|
724
|
+
box.valueLabel.textAlign = "right";
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
endGroup();
|
|
728
|
+
|
|
729
|
+
endGroup();
|
|
730
|
+
|
|
731
|
+
// Hide the top row when it is empty.
|
|
732
|
+
const updateTopRow = function () {
|
|
733
|
+
box.topRow.visible = (box.titleText || box.valuePosition === "top") ? 1 : 0;
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
// *** OBJECT INIT CODE:
|
|
737
|
+
|
|
738
|
+
box.maxValue = (Number(box.maxValue) >= 0) ? Number(box.maxValue) : 100;
|
|
739
|
+
box.value = clampValue(box.value);
|
|
740
|
+
box.indeterminate = basic.isOn(box.indeterminate) ? 1 : 0;
|
|
741
|
+
box.status = (box.status === "success" || box.status === "error") ? box.status : "normal";
|
|
742
|
+
|
|
743
|
+
box.limits = Array.isArray(box.limits) ? box.limits.slice() : [];
|
|
744
|
+
box.limitLines = [];
|
|
745
|
+
box.limitDots = [];
|
|
746
|
+
|
|
747
|
+
box.darkTrack = basic.isOn(box.darkTrack) ? 1 : 0;
|
|
748
|
+
|
|
749
|
+
updateTopRow();
|
|
750
|
+
paintTrack();
|
|
751
|
+
updateView();
|
|
752
|
+
drawLimits();
|
|
753
|
+
paintStripes(box.bar, box.stripes == 1);
|
|
754
|
+
paintStripes(box.secondBar, box.secondStripes == 1);
|
|
755
|
+
|
|
756
|
+
// NOTE: setMotion() waits a short time, so the bar does not grow from 0 when it is created.
|
|
757
|
+
box.bar.setMotion(getBarMotion());
|
|
758
|
+
box.secondBar.setMotion(getBarMotion());
|
|
759
|
+
|
|
760
|
+
return endObject(box);
|
|
761
|
+
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
// *** STYLE PACKAGES:
|
|
765
|
+
// USAGE: ProgressBar({ styleName: "modern" })
|
|
766
|
+
// USAGE: ProgressBar({ styleName: "modern", style: { bar: { color: "tomato" } } }) // Change only some keys.
|
|
767
|
+
// USAGE: ProgressBar({ style: ProgressBar.styles.modern }) // The same as styleName: "modern". (The package is copied, never changed.)
|
|
768
|
+
// NOTE: A new package needs only the keys that differ from ProgressBarDefaults.style (the base of every package).
|
|
769
|
+
// USAGE: ProgressBar.styles.myStyle = { bar: { color: "red" } };
|
|
770
|
+
ProgressBar.styles = {
|
|
771
|
+
|
|
772
|
+
// The light look of the kit (_designs/progress-bar.htm), the default: a thin round track of 10 px with no edge, the
|
|
773
|
+
// bar in the accent, the second part the accent at 35 %, a limit a 2 px soft gray line with its text under it, a
|
|
774
|
+
// 14 px title and a 13 px value.
|
|
775
|
+
light: {
|
|
776
|
+
layout: { gap: 6 },
|
|
777
|
+
track: { height: 10, color: "#E6E7E3", round: 100, border: 0, borderColor: "transparent" },
|
|
778
|
+
darkTrack: { color: "#2E2E2D", borderColor: "transparent", limitColor: White(0.7) },
|
|
779
|
+
bar: { color: "#3D7A6B", fillOpacity: 1, border: 0, borderColor: "", boxShadow: "none", innerRound: "", joinEdge: 1, motion: 0.3 },
|
|
780
|
+
secondBar: { color: "", fillOpacity: 0.35, lighten: 0, borderOpacity: 0.45 }, // the main color at 35 %
|
|
781
|
+
stripes: { color: "rgba(255, 255, 255, 0.35)", size: 14, speed: 0.8 },
|
|
782
|
+
limit: { shape: "line", color: Black(0.45), width: 2, round: 1, overhang: 4, dotSize: 6, dotOpacity: 1, barColor: "white", secondBarColor: "", textSize: 12, textColor: Black(0.55), textSpace: 6 },
|
|
783
|
+
successBar: { color: "#5DB36B" },
|
|
784
|
+
errorBar: { color: "#D9534F" },
|
|
785
|
+
title: { fontSize: 14, textColor: Black(0.88) },
|
|
786
|
+
valueText: { fontSize: 13, textColor: Black(0.55) },
|
|
787
|
+
},
|
|
788
|
+
|
|
789
|
+
// The dark look of the kit: the same shapes on a dark page.
|
|
790
|
+
dark: {
|
|
791
|
+
layout: { gap: 6 },
|
|
792
|
+
track: { height: 10, color: "#363635", round: 100, border: 0, borderColor: "transparent" },
|
|
793
|
+
darkTrack: { color: "#111110", borderColor: White(0.2), limitColor: White(0.7) },
|
|
794
|
+
bar: { color: "#65A293", fillOpacity: 1, border: 0, borderColor: "", boxShadow: "none", innerRound: "", joinEdge: 1, motion: 0.3 },
|
|
795
|
+
secondBar: { color: "", fillOpacity: 0.35, lighten: 0, borderOpacity: 0.45 },
|
|
796
|
+
stripes: { color: "rgba(255, 255, 255, 0.25)", size: 14, speed: 0.8 },
|
|
797
|
+
limit: { shape: "line", color: White(0.5), width: 2, round: 1, overhang: 4, dotSize: 6, dotOpacity: 1, barColor: "#141414", secondBarColor: "", textSize: 12, textColor: White(0.55), textSpace: 6 },
|
|
798
|
+
successBar: { color: "#7FCB8F" },
|
|
799
|
+
errorBar: { color: "#FF7B72" },
|
|
800
|
+
title: { fontSize: 14, textColor: White(0.9) },
|
|
801
|
+
valueText: { fontSize: 13, textColor: White(0.55) },
|
|
802
|
+
},
|
|
803
|
+
|
|
804
|
+
// The ozden bar: the colors of
|
|
805
|
+
// SmartButton. The bar is a cyan SmartButton ozden (its edge and its line at the bottom: it looks raised);
|
|
806
|
+
// the track keeps the colors of the default (#F2F2F2, a 2 px light gray edge) and its two ends are round; an end
|
|
807
|
+
// in the middle of the track is straight. darkTrack: 1 is a soft black with no edge. The second part is a second
|
|
808
|
+
// bar next to the bar, the main color mixed with white (not transparent). A limit is a dot, a little soft.
|
|
809
|
+
// The main color can change (style.bar.color: the second part follows it); the tones of SmartButton fit.
|
|
810
|
+
ozden: {
|
|
811
|
+
layout: {
|
|
812
|
+
gap: 8,
|
|
813
|
+
},
|
|
814
|
+
track: {
|
|
815
|
+
round: 100, // the two ends are half circles
|
|
816
|
+
},
|
|
817
|
+
darkTrack: {
|
|
818
|
+
color: Black(0.85),
|
|
819
|
+
borderColor: "transparent", // no edge: the color of the track fills its place (the same size)
|
|
820
|
+
limitColor: White(0.7),
|
|
821
|
+
},
|
|
822
|
+
bar: {
|
|
823
|
+
color: "#5BBAC1", // cyan (SmartButton.tones.cyan)
|
|
824
|
+
fillOpacity: 1,
|
|
825
|
+
border: 1, // the edge and the bottom line of SmartButton ozden
|
|
826
|
+
borderColor: "rgba(0, 0, 0, 0.35)",
|
|
827
|
+
boxShadow: "inset 0 -2px 0 rgba(0, 0, 0, 0.25)",
|
|
828
|
+
innerRound: 0, // straight in the middle of the track
|
|
829
|
+
joinEdge: 0, // no edge between the bar and the second part
|
|
830
|
+
motion: 0.3,
|
|
831
|
+
},
|
|
832
|
+
secondBar: {
|
|
833
|
+
color: "", // the main color, lighter
|
|
834
|
+
lighten: 0.5, // half white: not transparent, so it looks like a second bar next to the bar
|
|
835
|
+
},
|
|
836
|
+
stripes: {
|
|
837
|
+
color: "rgba(255, 255, 255, 0.55)",
|
|
838
|
+
size: 14,
|
|
839
|
+
speed: 0.8,
|
|
840
|
+
},
|
|
841
|
+
successBar: {
|
|
842
|
+
color: "#7BC362", // green (SmartButton.tones.green)
|
|
843
|
+
},
|
|
844
|
+
errorBar: {
|
|
845
|
+
color: "#DE815B", // orange (SmartButton.tones.orange)
|
|
846
|
+
},
|
|
847
|
+
limit: {
|
|
848
|
+
shape: "dot", // a dot inside the track, in the color of the part under it
|
|
849
|
+
color: "rgba(0, 0, 0, 0.7)", // on the track
|
|
850
|
+
dotSize: 6,
|
|
851
|
+
dotOpacity: 0.85, // every dot
|
|
852
|
+
barColor: "white", // on the bar
|
|
853
|
+
secondBarColor: "", // on the second part: the main color
|
|
854
|
+
width: 4, // shape "line"
|
|
855
|
+
round: 2,
|
|
856
|
+
overhang: 4,
|
|
857
|
+
textSize: 14,
|
|
858
|
+
textColor: "rgba(0, 0, 0, 0.7)",
|
|
859
|
+
textSpace: 8,
|
|
860
|
+
},
|
|
861
|
+
title: {
|
|
862
|
+
fontSize: 15,
|
|
863
|
+
textColor: "#232323",
|
|
864
|
+
},
|
|
865
|
+
valueText: {
|
|
866
|
+
fontSize: 14,
|
|
867
|
+
textColor: "rgba(35, 35, 35, 0.6)",
|
|
868
|
+
},
|
|
869
|
+
},
|
|
870
|
+
|
|
871
|
+
// The ozden bar for a dark page: a dark track with a soft edge, the bar in the main color of the kit.
|
|
872
|
+
ozdenDark: {
|
|
873
|
+
layout: {
|
|
874
|
+
gap: 8,
|
|
875
|
+
},
|
|
876
|
+
track: {
|
|
877
|
+
color: "#2A2A29",
|
|
878
|
+
borderColor: White(0.18),
|
|
879
|
+
},
|
|
880
|
+
bar: {
|
|
881
|
+
color: "#5BBAC1",
|
|
882
|
+
fillOpacity: 0.5,
|
|
883
|
+
border: 2,
|
|
884
|
+
borderColor: "", // the main color
|
|
885
|
+
motion: 0.3,
|
|
886
|
+
},
|
|
887
|
+
secondBar: {
|
|
888
|
+
color: "", // the main color, lighter
|
|
889
|
+
fillOpacity: 0.2,
|
|
890
|
+
borderOpacity: 0.45,
|
|
891
|
+
},
|
|
892
|
+
stripes: {
|
|
893
|
+
color: White(0.25),
|
|
894
|
+
size: 14,
|
|
895
|
+
speed: 0.8,
|
|
896
|
+
},
|
|
897
|
+
successBar: {
|
|
898
|
+
color: "#40A5AF",
|
|
899
|
+
},
|
|
900
|
+
errorBar: {
|
|
901
|
+
color: "#FE5D49",
|
|
902
|
+
},
|
|
903
|
+
limit: {
|
|
904
|
+
color: White(0.75),
|
|
905
|
+
width: 4,
|
|
906
|
+
round: 2,
|
|
907
|
+
overhang: 4,
|
|
908
|
+
textSize: 14,
|
|
909
|
+
textColor: White(0.75),
|
|
910
|
+
textSpace: 8,
|
|
911
|
+
},
|
|
912
|
+
title: {
|
|
913
|
+
fontSize: 15,
|
|
914
|
+
textColor: White(0.88),
|
|
915
|
+
},
|
|
916
|
+
valueText: {
|
|
917
|
+
fontSize: 14,
|
|
918
|
+
textColor: White(0.6),
|
|
919
|
+
},
|
|
920
|
+
},
|
|
921
|
+
|
|
922
|
+
// Thicker round bar, same colors as the modern CheckBox and RadioButton.
|
|
923
|
+
modern: {
|
|
924
|
+
layout: {
|
|
925
|
+
gap: 8,
|
|
926
|
+
},
|
|
927
|
+
track: {
|
|
928
|
+
height: 10,
|
|
929
|
+
color: "#DFECEC", // 20% of bar color on white
|
|
930
|
+
round: 100,
|
|
931
|
+
border: 0, // WHY: no edge (the default has one)
|
|
932
|
+
borderColor: "transparent",
|
|
933
|
+
},
|
|
934
|
+
bar: {
|
|
935
|
+
color: "cadetblue", // #5F9EA0
|
|
936
|
+
motion: 0.3,
|
|
937
|
+
},
|
|
938
|
+
successBar: {
|
|
939
|
+
color: "#6FCF97",
|
|
940
|
+
},
|
|
941
|
+
errorBar: {
|
|
942
|
+
color: "tomato",
|
|
943
|
+
},
|
|
944
|
+
title: {
|
|
945
|
+
fontSize: 16,
|
|
946
|
+
textColor: Black(0.85),
|
|
947
|
+
},
|
|
948
|
+
valueText: {
|
|
949
|
+
fontSize: 14,
|
|
950
|
+
textColor: "cadetblue",
|
|
951
|
+
},
|
|
952
|
+
indeterminate: {
|
|
953
|
+
barWidth: 35,
|
|
954
|
+
duration: 1.4,
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
|
|
958
|
+
};
|
|
959
|
+
ProgressBar.styles.classic = ProgressBar.styles.light; // the old name of light
|
|
960
|
+
|
|
961
|
+
// The moving stripes (a class can have an animation; its colors are css variables of the bar)
|
|
962
|
+
ProgressBar.injectCss = function () {
|
|
963
|
+
basic.addCss("progress-bar-css",
|
|
964
|
+
// WHY this gradient in a square tile: its stripes meet at the edges of the tile (no seam while it moves)
|
|
965
|
+
".progress-bar-stripes { background-image: linear-gradient(45deg, var(--progress-stripe-color) 25%, transparent 25%, transparent 50%," +
|
|
966
|
+
" var(--progress-stripe-color) 50%, var(--progress-stripe-color) 75%, transparent 75%, transparent);" +
|
|
967
|
+
" background-size: var(--progress-stripe-size) var(--progress-stripe-size);" +
|
|
968
|
+
" animation: progress-bar-stripes var(--progress-stripe-speed) linear infinite; }" +
|
|
969
|
+
"@keyframes progress-bar-stripes { to { background-position: var(--progress-stripe-size) 0; } }" +
|
|
970
|
+
"@media (prefers-reduced-motion: reduce) { .progress-bar-stripes { animation: none; } }");
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
// The minimal theme (_designs/minimal-theme.htm): a 2 px track with no edge, the bar in ink, a 12 px title and value;
|
|
974
|
+
// an error in the danger color. minimalDark: the same on a dark window.
|
|
975
|
+
ProgressBar.createMinimalStyle = function (colors) {
|
|
976
|
+
return {
|
|
977
|
+
layout: { gap: 6 },
|
|
978
|
+
track: { height: 2, color: colors.track, round: 1, border: 0, borderColor: "transparent" },
|
|
979
|
+
darkTrack: { color: colors.track, borderColor: "transparent", limitColor: colors.ink },
|
|
980
|
+
bar: { color: colors.ink, fillOpacity: 1, border: 0, borderColor: "", boxShadow: "none", innerRound: "", joinEdge: 0, motion: 0.3 },
|
|
981
|
+
secondBar: { color: colors.softText, fillOpacity: 1, lighten: 0, borderOpacity: 0 },
|
|
982
|
+
limit: { shape: "line", color: colors.danger, width: 1, overhang: 4, textSize: 11, textColor: colors.softText },
|
|
983
|
+
successBar: { color: colors.ink },
|
|
984
|
+
errorBar: { color: colors.danger },
|
|
985
|
+
title: { fontSize: 12, textColor: colors.text },
|
|
986
|
+
valueText: { fontSize: 12, textColor: colors.softText },
|
|
987
|
+
};
|
|
988
|
+
};
|
|
989
|
+
ProgressBar.MINIMAL_COLORS = { ink: "#1F1F1F", track: Black(0.12), text: Black(0.85), softText: Black(0.55), danger: "#C24A36" };
|
|
990
|
+
ProgressBar.styles.minimal = ProgressBar.createMinimalStyle(ProgressBar.MINIMAL_COLORS);
|
|
991
|
+
ProgressBar.MINIMAL_DARK_COLORS = { ink: "#EDEDEB", track: White(0.14), text: White(0.88), softText: White(0.55), danger: "#FF9F93" };
|
|
992
|
+
ProgressBar.styles.minimalDark = ProgressBar.createMinimalStyle(ProgressBar.MINIMAL_DARK_COLORS);
|