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,1097 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
UIEffects - v26.09
|
|
6
|
+
|
|
7
|
+
Button, hover and attention effects for basic.js objects (Button, Box, groups, Label, Input, Icon).
|
|
8
|
+
- No CSS file. The effects set the styles of the object and use the Web Animations API.
|
|
9
|
+
- press(obj, type): hover + press effects and a pointer cursor. For a Button, a Box (a card that is a button),
|
|
10
|
+
a Label...
|
|
11
|
+
- hover(obj, type): a hover effect only, to show that the pointer is over the object.
|
|
12
|
+
- Several effects can be used together: press(btn, ["lift", "ripple"]). Their transform, filter and
|
|
13
|
+
box-shadow values are combined, so they do not overwrite each other.
|
|
14
|
+
- play(obj, name) plays an animation one time, loop(obj, name) repeats it until stop().
|
|
15
|
+
- press(), hover(), focusGroup() and loop() return a function that removes the effect: off() / stop().
|
|
16
|
+
- button() is the same function as press() and attention() is the same as loop(). They stay for the old code.
|
|
17
|
+
- Hover effects do not run for touch (no sticky hover on phones). Press effects do.
|
|
18
|
+
- A disabled button (btn.enabled = 0) has no effects.
|
|
19
|
+
- play() and loop() do nothing when the user prefers reduced motion (UIEffects.reduceMotion).
|
|
20
|
+
|
|
21
|
+
PRESS TYPES (press and hover):
|
|
22
|
+
default, press, lift, glow, ripple, shine, push, fill, ring, jelly, pop
|
|
23
|
+
HOVER TYPES (hover and press):
|
|
24
|
+
brighten, darken, grow, fade, color, border, underline, tilt, spotlight (and lift, glow, ring, shine)
|
|
25
|
+
ANIMATIONS (play and loop):
|
|
26
|
+
shake, jelly, pop, bounce, tada, heartbeat, wiggle, flash, pulse, breathe, glow
|
|
27
|
+
|
|
28
|
+
USAGE:
|
|
29
|
+
UIEffects.press(btn); // The first effect of UIEffects: brightness + press.
|
|
30
|
+
UIEffects.press(btn, "ripple", { color: White(0.5) });
|
|
31
|
+
UIEffects.press(btn, ["lift", "ripple"]);
|
|
32
|
+
UIEffects.press(card, "lift"); // A Box as a button.
|
|
33
|
+
UIEffects.hover(card, "ring", { color: "#4A90E2" });
|
|
34
|
+
UIEffects.hover(lblLink, "underline", { color: "#4A90E2" });
|
|
35
|
+
UIEffects.hover(card, "tilt", { angle: 10 });
|
|
36
|
+
const off = UIEffects.hover(box, "grow"); off(); // Removes the effect.
|
|
37
|
+
UIEffects.focusGroup([card1, card2, card3]); // Dims the others while one is hovered.
|
|
38
|
+
UIEffects.play(txtPassword, "shake"); // One time. Returns the Animation (or null).
|
|
39
|
+
const stop = UIEffects.loop(btnNew, "pulse"); stop(); // Repeats until stop().
|
|
40
|
+
|
|
41
|
+
NOTES:
|
|
42
|
+
- Call the effect after setMotion(): setMotion() replaces the transition of the object. (The effect adds its
|
|
43
|
+
transition again at the next hover.)
|
|
44
|
+
- Set elem.style.boxShadow / transform / filter before the effect is added. The effect keeps those values
|
|
45
|
+
and adds its own to them.
|
|
46
|
+
- A shadow, lift or ring outside the object is clipped by a parent box that clips its content (the default
|
|
47
|
+
of a Box). Give the parent some padding or clipContent: 0.
|
|
48
|
+
- ripple, shine and spotlight add a <span> into the object for a short time (not on Icon and Input).
|
|
49
|
+
- Add your own type: UIEffects.types.myType = function (obj, o, fx) { return { motion: [...], render: function (st) {} }; };
|
|
50
|
+
|
|
51
|
+
Started Date: 2025
|
|
52
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
53
|
+
|
|
54
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
55
|
+
Licensed under the Apache License, Version 2.0
|
|
56
|
+
SPDX-License-Identifier: Apache-2.0
|
|
57
|
+
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
"use strict";
|
|
61
|
+
|
|
62
|
+
const UIEffects = function () {};
|
|
63
|
+
|
|
64
|
+
// *** SETTINGS:
|
|
65
|
+
UIEffects.duration = 0.2; // Default transition time (seconds).
|
|
66
|
+
UIEffects.easing = "cubic-bezier(0.25, 0.8, 0.25, 1)";
|
|
67
|
+
UIEffects.reduceMotion = (window.matchMedia) ? window.matchMedia("(prefers-reduced-motion: reduce)").matches : false;
|
|
68
|
+
|
|
69
|
+
// *** PUBLIC FUNCTIONS:
|
|
70
|
+
|
|
71
|
+
// Hover + press effect. The object gets a pointer cursor.
|
|
72
|
+
UIEffects.press = function (obj, type = "default", options = {}) {
|
|
73
|
+
obj.elem.style.cursor = "pointer";
|
|
74
|
+
return UIEffects._add(obj, type, options, 1);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// The old name of press(): the old code keeps working.
|
|
78
|
+
UIEffects.button = UIEffects.press;
|
|
79
|
+
|
|
80
|
+
// Hover effect only (no press state).
|
|
81
|
+
UIEffects.hover = function (obj, type = "brighten", options = {}) {
|
|
82
|
+
return UIEffects._add(obj, type, options, 0);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// While an object of the list is hovered, the others are dimmed.
|
|
86
|
+
// options: dim (opacity of the others, 0.45), scale (of the hovered one, 1), blur (px, 0), grayscale (0-1, 0), duration
|
|
87
|
+
UIEffects.focusGroup = function (list, options = {}) {
|
|
88
|
+
|
|
89
|
+
const id = UIEffects._newId();
|
|
90
|
+
const removers = [];
|
|
91
|
+
const dim = options.dim ?? 0.45;
|
|
92
|
+
const scale = options.scale ?? 1;
|
|
93
|
+
const blur = options.blur ?? 0;
|
|
94
|
+
const grayscale = options.grayscale ?? 0;
|
|
95
|
+
const duration = options.duration ?? 0.3;
|
|
96
|
+
const LEAVE_WAIT_MS = 80;
|
|
97
|
+
let leaveTimer = null;
|
|
98
|
+
|
|
99
|
+
const filterOf = function (isDim) {
|
|
100
|
+
let value = "opacity(" + (isDim ? dim : 1) + ")";
|
|
101
|
+
if (blur) value += " blur(" + (isDim ? blur : 0) + "px)";
|
|
102
|
+
if (grayscale) value += " grayscale(" + (isDim ? grayscale : 0) + ")";
|
|
103
|
+
return value;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const apply = function (active) {
|
|
107
|
+
list.forEach(function (item) {
|
|
108
|
+
const isActive = (active && item === active);
|
|
109
|
+
UIEffects._addMotion(item, ["filter", "transform"], duration);
|
|
110
|
+
UIEffects._setPart(item, "filter", id, filterOf(active && item !== active));
|
|
111
|
+
UIEffects._setPart(item, "transform", id, "scale(" + (isActive ? scale : 1) + ")");
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
list.forEach(function (item) {
|
|
116
|
+
removers.push(item.on("pointerenter", function (self, event) {
|
|
117
|
+
if (event.pointerType === "touch") return;
|
|
118
|
+
clearTimeout(leaveTimer);
|
|
119
|
+
apply(item);
|
|
120
|
+
}));
|
|
121
|
+
removers.push(item.on("pointerleave", function () {
|
|
122
|
+
clearTimeout(leaveTimer);
|
|
123
|
+
// WHY: Moving to the next item fires leave and then enter. Without the wait, all items flash.
|
|
124
|
+
leaveTimer = setTimeout(function () { apply(null); }, LEAVE_WAIT_MS);
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return function off() {
|
|
129
|
+
clearTimeout(leaveTimer);
|
|
130
|
+
removers.forEach(function (remove) { remove(); });
|
|
131
|
+
removers.length = 0;
|
|
132
|
+
list.forEach(function (item) { UIEffects._clearParts(item, id); });
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// Plays an animation one time. Returns the Animation (animation.finished is a Promise) or null.
|
|
138
|
+
// options: duration (seconds), color, size (for pulse and glow)
|
|
139
|
+
UIEffects.play = function (obj, name = "pop", options = {}) {
|
|
140
|
+
|
|
141
|
+
if (UIEffects.reduceMotion) return null;
|
|
142
|
+
const definition = UIEffects._getAnimation(obj, name, options);
|
|
143
|
+
if (!definition) return null;
|
|
144
|
+
|
|
145
|
+
return obj.elem.animate(definition.keyframes, {
|
|
146
|
+
duration: (options.duration ?? definition.duration) * 1000,
|
|
147
|
+
easing: definition.easing || "ease",
|
|
148
|
+
composite: definition.composite || "add",
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// Repeats an animation to take attention (a new message, the next step). Returns stop().
|
|
154
|
+
// options: pause (seconds between two plays), duration, color, size
|
|
155
|
+
UIEffects.loop = function (obj, name = "pulse", options = {}) {
|
|
156
|
+
|
|
157
|
+
if (UIEffects.reduceMotion) return function stop() {};
|
|
158
|
+
const definition = UIEffects._getAnimation(obj, name, options);
|
|
159
|
+
if (!definition) return function stop() {};
|
|
160
|
+
|
|
161
|
+
const duration = options.duration ?? definition.duration;
|
|
162
|
+
const pause = options.pause ?? definition.pause ?? 1;
|
|
163
|
+
const hasPause = (pause > 0);
|
|
164
|
+
const easing = definition.easing || "ease";
|
|
165
|
+
const keyframes = (hasPause) ? UIEffects._withPause(definition.keyframes, duration, pause, easing) : definition.keyframes;
|
|
166
|
+
|
|
167
|
+
// WHY: With a pause, the easing is in each keyframe (_withPause), so the whole loop runs linear.
|
|
168
|
+
const animation = obj.elem.animate(keyframes, {
|
|
169
|
+
duration: (duration + Math.max(0, pause)) * 1000,
|
|
170
|
+
easing: (hasPause) ? "linear" : easing,
|
|
171
|
+
composite: definition.composite || "add",
|
|
172
|
+
iterations: Infinity,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return function stop() {
|
|
176
|
+
animation.cancel();
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// The first name of loop().
|
|
182
|
+
UIEffects.attention = UIEffects.loop;
|
|
183
|
+
|
|
184
|
+
// *** EFFECT TYPES:
|
|
185
|
+
// Each type returns: motion (transitioned CSS properties), render(st, event) (st.over, st.down),
|
|
186
|
+
// and optionally: duration, pressTime (min press time, ms), move(event), off().
|
|
187
|
+
// fx.set(prop, value): sets this effect's part of "transform", "filter" or "boxShadow".
|
|
188
|
+
|
|
189
|
+
UIEffects.types = {};
|
|
190
|
+
|
|
191
|
+
// The first effect of UIEffects: brightness on hover, a short press.
|
|
192
|
+
UIEffects.types.default = function (obj, o, fx) {
|
|
193
|
+
return {
|
|
194
|
+
motion: ["filter", "transform"],
|
|
195
|
+
pressTime: 200,
|
|
196
|
+
render: function (st) {
|
|
197
|
+
fx.set("filter", "brightness(" + UIEffects._byState(st, { down: 0.8, over: 1.2, normal: 1 }) + ")");
|
|
198
|
+
fx.set("transform", "scale(" + (st.down ? (o.scale ?? 0.95) : 1) + ")");
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// Pressed in, a little brighter on hover.
|
|
204
|
+
UIEffects.types.press = function (obj, o, fx) {
|
|
205
|
+
return {
|
|
206
|
+
motion: ["filter", "transform"],
|
|
207
|
+
duration: 0.15,
|
|
208
|
+
render: function (st) {
|
|
209
|
+
fx.set("filter", "brightness(" + UIEffects._byState(st, { down: 0.92, over: 1.08, normal: 1 }) + ")");
|
|
210
|
+
fx.set("transform", "scale(" + (st.down ? (o.scale ?? 0.94) : 1) + ")");
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// Rises with a shadow. options: distance (px, 4), shadowColor
|
|
216
|
+
UIEffects.types.lift = function (obj, o, fx) {
|
|
217
|
+
const distance = o.distance ?? 4;
|
|
218
|
+
const shadowColor = o.shadowColor || Black(0.22);
|
|
219
|
+
const pressedShadow = "0px 2px 6px 0px " + shadowColor;
|
|
220
|
+
const liftedShadow = "0px " + (distance * 2 + 2) + "px " + (distance * 4 + 6) + "px 0px " + shadowColor;
|
|
221
|
+
const noShadow = "0px 0px 0px 0px transparent";
|
|
222
|
+
return {
|
|
223
|
+
motion: ["transform", "box-shadow"],
|
|
224
|
+
duration: 0.25,
|
|
225
|
+
render: function (st) {
|
|
226
|
+
const y = UIEffects._byState(st, { down: -1, over: -distance, normal: 0 });
|
|
227
|
+
fx.set("transform", "translateY(" + y + "px)");
|
|
228
|
+
fx.set("boxShadow", UIEffects._byState(st, { down: pressedShadow, over: liftedShadow, normal: noShadow }));
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// A soft light around it. options: color (the background color of the object), size (px, 16)
|
|
234
|
+
UIEffects.types.glow = function (obj, o, fx) {
|
|
235
|
+
const color = o.color || UIEffects._backgroundColor(obj, "rgba(66, 133, 244, 0.8)");
|
|
236
|
+
const size = o.size ?? 16;
|
|
237
|
+
return {
|
|
238
|
+
motion: ["transform", "box-shadow", "filter"],
|
|
239
|
+
duration: 0.3,
|
|
240
|
+
render: function (st) {
|
|
241
|
+
const isOn = st.over || st.down;
|
|
242
|
+
fx.set("boxShadow", isOn ? "0px 0px " + size + "px 2px " + color : "0px 0px 0px 0px transparent");
|
|
243
|
+
fx.set("filter", "brightness(" + (st.over ? 1.05 : 1) + ")");
|
|
244
|
+
fx.set("transform", "scale(" + (st.down ? 0.97 : 1) + ")");
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// A wave from the pressed point (Material style). options: color (White(0.45)), time (seconds, 0.6)
|
|
250
|
+
UIEffects.types.ripple = function (obj, o, fx) {
|
|
251
|
+
const color = o.color || White(0.45);
|
|
252
|
+
return {
|
|
253
|
+
motion: ["filter"],
|
|
254
|
+
render: function (st, event) {
|
|
255
|
+
fx.set("filter", "brightness(" + (st.over ? 1.06 : 1) + ")");
|
|
256
|
+
if (st.down && event && event.type === "pointerdown") UIEffects._ripple(obj, event, color, o.time ?? 0.6);
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// A light passes over it on hover. options: color (White(0.5)), time (seconds, 0.7)
|
|
262
|
+
UIEffects.types.shine = function (obj, o, fx) {
|
|
263
|
+
const color = o.color || White(0.5);
|
|
264
|
+
let wasOver = 0;
|
|
265
|
+
return {
|
|
266
|
+
motion: ["filter", "transform"],
|
|
267
|
+
render: function (st) {
|
|
268
|
+
if (st.over && !wasOver) UIEffects._shine(obj, color, o.time ?? 0.7);
|
|
269
|
+
wasOver = st.over;
|
|
270
|
+
fx.set("filter", "brightness(" + (st.over ? 1.05 : 1) + ")");
|
|
271
|
+
fx.set("transform", "scale(" + (st.down ? 0.97 : 1) + ")");
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// A 3D key: it has a hard shadow below and goes down when it is pressed. options: depth (px, 5), shadowColor
|
|
277
|
+
UIEffects.types.push = function (obj, o, fx) {
|
|
278
|
+
const depth = o.depth ?? 5;
|
|
279
|
+
const shadowColor = o.shadowColor || Black(0.3);
|
|
280
|
+
return {
|
|
281
|
+
motion: ["transform", "box-shadow", "filter"],
|
|
282
|
+
duration: 0.08,
|
|
283
|
+
render: function (st) {
|
|
284
|
+
const y = UIEffects._byState(st, { down: depth - 1, over: -1, normal: 0 });
|
|
285
|
+
const shadowY = UIEffects._byState(st, { down: 1, over: depth + 1, normal: depth });
|
|
286
|
+
fx.set("transform", "translateY(" + y + "px)");
|
|
287
|
+
fx.set("boxShadow", "0px " + shadowY + "px 0px 0px " + shadowColor);
|
|
288
|
+
fx.set("filter", "brightness(" + (st.over ? 1.04 : 1) + ")");
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// The background fills with a color from one side. Good for outline buttons.
|
|
294
|
+
// options: color (Black(0.15)), textColor (text color while filled), direction ("left", "right", "up", "down")
|
|
295
|
+
UIEffects.types.fill = function (obj, o, fx) {
|
|
296
|
+
const color = o.color || Black(0.15);
|
|
297
|
+
const direction = o.direction || "left";
|
|
298
|
+
let savedTextColor = null;
|
|
299
|
+
const setFilledTextColor = function (isOn) {
|
|
300
|
+
if (isOn && savedTextColor === null) {
|
|
301
|
+
savedTextColor = obj.elem.style.color;
|
|
302
|
+
obj.elem.style.color = o.textColor;
|
|
303
|
+
} else if (!isOn && savedTextColor !== null) {
|
|
304
|
+
obj.elem.style.color = savedTextColor;
|
|
305
|
+
savedTextColor = null;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
return {
|
|
309
|
+
motion: ["box-shadow", "color", "transform"],
|
|
310
|
+
duration: 0.35,
|
|
311
|
+
render: function (st) {
|
|
312
|
+
const isOn = st.over || st.down;
|
|
313
|
+
const width = obj.elem.offsetWidth;
|
|
314
|
+
const height = obj.elem.offsetHeight;
|
|
315
|
+
let x = 0;
|
|
316
|
+
let y = 0;
|
|
317
|
+
if (isOn) {
|
|
318
|
+
if (direction === "right") x = -width;
|
|
319
|
+
else if (direction === "up") y = -height;
|
|
320
|
+
else if (direction === "down") y = height;
|
|
321
|
+
else x = width;
|
|
322
|
+
}
|
|
323
|
+
fx.set("boxShadow", "inset " + x + "px " + y + "px 0px 0px " + color);
|
|
324
|
+
fx.set("transform", "scale(" + (st.down ? 0.97 : 1) + ")");
|
|
325
|
+
if (o.textColor) setFilledTextColor(isOn);
|
|
326
|
+
},
|
|
327
|
+
off: function () {
|
|
328
|
+
if (savedTextColor !== null) obj.elem.style.color = savedTextColor;
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// A focus ring around it. options: color ("#4A90E2"), width (px, 2), offset (px, 3)
|
|
334
|
+
UIEffects.types.ring = function (obj, o, fx) {
|
|
335
|
+
const elem = obj.elem;
|
|
336
|
+
const color = o.color || "#4A90E2";
|
|
337
|
+
const offset = o.offset ?? 3;
|
|
338
|
+
const savedOutline = elem.style.outline;
|
|
339
|
+
const savedOutlineOffset = elem.style.outlineOffset;
|
|
340
|
+
elem.style.outline = (o.width ?? 2) + "px solid transparent";
|
|
341
|
+
elem.style.outlineOffset = "0px";
|
|
342
|
+
return {
|
|
343
|
+
motion: ["outline-color", "outline-offset", "transform"],
|
|
344
|
+
render: function (st) {
|
|
345
|
+
const isOn = st.over || st.down;
|
|
346
|
+
elem.style.outlineColor = isOn ? color : "transparent";
|
|
347
|
+
elem.style.outlineOffset = UIEffects._byState(st, { down: 1, over: offset, normal: 0 }) + "px";
|
|
348
|
+
fx.set("transform", "scale(" + (st.down ? 0.98 : 1) + ")");
|
|
349
|
+
},
|
|
350
|
+
off: function () {
|
|
351
|
+
elem.style.outline = savedOutline;
|
|
352
|
+
elem.style.outlineOffset = savedOutlineOffset;
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// Shakes like a jelly when it is released.
|
|
358
|
+
UIEffects.types.jelly = function (obj, o, fx) {
|
|
359
|
+
let wasDown = 0;
|
|
360
|
+
return {
|
|
361
|
+
motion: ["filter"],
|
|
362
|
+
pressTime: 0,
|
|
363
|
+
render: function (st) {
|
|
364
|
+
if (wasDown && !st.down) UIEffects.play(obj, "jelly");
|
|
365
|
+
wasDown = st.down;
|
|
366
|
+
fx.set("filter", "brightness(" + UIEffects._byState(st, { down: 0.95, over: 1.06, normal: 1 }) + ")");
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// Pops when it is released.
|
|
372
|
+
UIEffects.types.pop = function (obj, o, fx) {
|
|
373
|
+
let wasDown = 0;
|
|
374
|
+
return {
|
|
375
|
+
motion: ["filter", "transform"],
|
|
376
|
+
pressTime: 0,
|
|
377
|
+
render: function (st) {
|
|
378
|
+
if (wasDown && !st.down) UIEffects.play(obj, "pop");
|
|
379
|
+
wasDown = st.down;
|
|
380
|
+
fx.set("filter", "brightness(" + (st.over ? 1.06 : 1) + ")");
|
|
381
|
+
fx.set("transform", "scale(" + (st.down ? 0.94 : 1) + ")");
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// HOVER TYPES:
|
|
387
|
+
|
|
388
|
+
// options: amount (1.1)
|
|
389
|
+
UIEffects.types.brighten = function (obj, o, fx) {
|
|
390
|
+
return {
|
|
391
|
+
motion: ["filter", "transform"],
|
|
392
|
+
render: function (st) {
|
|
393
|
+
fx.set("filter", "brightness(" + (st.over ? (o.amount ?? 1.1) : 1) + ")");
|
|
394
|
+
fx.set("transform", "scale(" + (st.down ? 0.97 : 1) + ")");
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// options: amount (0.9)
|
|
400
|
+
UIEffects.types.darken = function (obj, o, fx) {
|
|
401
|
+
return {
|
|
402
|
+
motion: ["filter", "transform"],
|
|
403
|
+
render: function (st) {
|
|
404
|
+
fx.set("filter", "brightness(" + ((st.over || st.down) ? (o.amount ?? 0.9) : 1) + ")");
|
|
405
|
+
fx.set("transform", "scale(" + (st.down ? 0.97 : 1) + ")");
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// options: scale (1.05)
|
|
411
|
+
UIEffects.types.grow = function (obj, o, fx) {
|
|
412
|
+
return {
|
|
413
|
+
motion: ["transform"],
|
|
414
|
+
duration: 0.25,
|
|
415
|
+
render: function (st) {
|
|
416
|
+
fx.set("transform", "scale(" + UIEffects._byState(st, { down: 0.98, over: o.scale ?? 1.05, normal: 1 }) + ")");
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// Becomes transparent. options: amount (0.7)
|
|
422
|
+
UIEffects.types.fade = function (obj, o, fx) {
|
|
423
|
+
return {
|
|
424
|
+
motion: ["filter"],
|
|
425
|
+
render: function (st) {
|
|
426
|
+
fx.set("filter", "opacity(" + ((st.over || st.down) ? (o.amount ?? 0.7) : 1) + ")");
|
|
427
|
+
},
|
|
428
|
+
};
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// The background color changes. options: color (Black(0.06) over the current color), textColor
|
|
432
|
+
UIEffects.types.color = function (obj, o, fx) {
|
|
433
|
+
const elem = obj.elem;
|
|
434
|
+
let saved = null;
|
|
435
|
+
return {
|
|
436
|
+
motion: ["background-color", "color", "box-shadow"],
|
|
437
|
+
render: function (st) {
|
|
438
|
+
const isOn = st.over || st.down;
|
|
439
|
+
if (o.color) {
|
|
440
|
+
if (isOn && saved === null) {
|
|
441
|
+
saved = { background: elem.style.backgroundColor, text: elem.style.color };
|
|
442
|
+
elem.style.backgroundColor = o.color;
|
|
443
|
+
if (o.textColor) elem.style.color = o.textColor;
|
|
444
|
+
} else if (!isOn && saved !== null) {
|
|
445
|
+
elem.style.backgroundColor = saved.background;
|
|
446
|
+
elem.style.color = saved.text;
|
|
447
|
+
saved = null;
|
|
448
|
+
}
|
|
449
|
+
} else {
|
|
450
|
+
// WHY: Without a color, a thin dark layer (inset shadow) works on every background color.
|
|
451
|
+
const layerColor = UIEffects._byState(st, { down: Black(0.1), over: Black(0.06), normal: "transparent" });
|
|
452
|
+
fx.set("boxShadow", "inset 0px 0px 0px 2000px " + layerColor);
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
off: function () {
|
|
456
|
+
if (saved !== null) {
|
|
457
|
+
elem.style.backgroundColor = saved.background;
|
|
458
|
+
elem.style.color = saved.text;
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
// The border color changes. The object needs a border. options: color ("#4A90E2")
|
|
465
|
+
UIEffects.types.border = function (obj, o, fx) {
|
|
466
|
+
const elem = obj.elem;
|
|
467
|
+
let saved = null;
|
|
468
|
+
return {
|
|
469
|
+
motion: ["border-color"],
|
|
470
|
+
render: function (st) {
|
|
471
|
+
const isOn = st.over || st.down;
|
|
472
|
+
if (isOn && saved === null) {
|
|
473
|
+
saved = elem.style.borderColor;
|
|
474
|
+
elem.style.borderColor = o.color || "#4A90E2";
|
|
475
|
+
} else if (!isOn && saved !== null) {
|
|
476
|
+
elem.style.borderColor = saved;
|
|
477
|
+
saved = null;
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
off: function () {
|
|
481
|
+
if (saved !== null) elem.style.borderColor = saved;
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// A line grows from the left under the text (for a Label used as a link). options: color, width (px, 2)
|
|
487
|
+
UIEffects.types.underline = function (obj, o, fx) {
|
|
488
|
+
const elem = obj.elem;
|
|
489
|
+
const color = o.color || "currentColor";
|
|
490
|
+
const saved = {
|
|
491
|
+
image: elem.style.backgroundImage,
|
|
492
|
+
repeat: elem.style.backgroundRepeat,
|
|
493
|
+
position: elem.style.backgroundPosition,
|
|
494
|
+
size: elem.style.backgroundSize,
|
|
495
|
+
};
|
|
496
|
+
const lineWidth = o.width ?? 2;
|
|
497
|
+
elem.style.backgroundImage = "linear-gradient(" + color + ", " + color + ")";
|
|
498
|
+
elem.style.backgroundRepeat = "no-repeat";
|
|
499
|
+
elem.style.backgroundPosition = "0% 100%";
|
|
500
|
+
elem.style.backgroundSize = "0% " + lineWidth + "px";
|
|
501
|
+
return {
|
|
502
|
+
motion: ["background-size"],
|
|
503
|
+
duration: 0.3,
|
|
504
|
+
render: function (st) {
|
|
505
|
+
elem.style.backgroundSize = ((st.over || st.down) ? 100 : 0) + "% " + lineWidth + "px";
|
|
506
|
+
},
|
|
507
|
+
off: function () {
|
|
508
|
+
elem.style.backgroundImage = saved.image;
|
|
509
|
+
elem.style.backgroundRepeat = saved.repeat;
|
|
510
|
+
elem.style.backgroundPosition = saved.position;
|
|
511
|
+
elem.style.backgroundSize = saved.size;
|
|
512
|
+
},
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
// Turns in 3D to the pointer. options: angle (degrees, 8), scale (1.03), perspective (px, 700), glare (1)
|
|
517
|
+
UIEffects.types.tilt = function (obj, o, fx) {
|
|
518
|
+
const angle = o.angle ?? 8;
|
|
519
|
+
const scale = o.scale ?? 1.03;
|
|
520
|
+
const perspective = o.perspective ?? 700;
|
|
521
|
+
const useGlare = (o.glare ?? 1) && !UIEffects.reduceMotion;
|
|
522
|
+
const GLARE_FADE_MS = 300;
|
|
523
|
+
let glare = null;
|
|
524
|
+
const setTilt = function (rotateX, rotateY, tiltScale) {
|
|
525
|
+
const transform = "perspective(" + perspective + "px) rotateX(" + rotateX + "deg) rotateY(" + rotateY + "deg)";
|
|
526
|
+
fx.set("transform", transform + " scale(" + tiltScale + ")");
|
|
527
|
+
};
|
|
528
|
+
// px, py: the pointer in the object, from -0.5 to 0.5.
|
|
529
|
+
const showGlare = function (px, py) {
|
|
530
|
+
if (!glare || glare.parentNode !== obj.elem) {
|
|
531
|
+
glare = UIEffects._overlay(obj);
|
|
532
|
+
if (glare) glare.style.transition = "opacity " + (GLARE_FADE_MS / 1000) + "s";
|
|
533
|
+
}
|
|
534
|
+
if (!glare) return;
|
|
535
|
+
const center = ((px + 0.5) * 100) + "% " + ((py + 0.5) * 100) + "%";
|
|
536
|
+
glare.style.opacity = 1;
|
|
537
|
+
glare.style.background = "radial-gradient(circle at " + center + ", " + White(0.25) + ", transparent 60%)";
|
|
538
|
+
};
|
|
539
|
+
return {
|
|
540
|
+
motion: ["transform"],
|
|
541
|
+
duration: 0.15,
|
|
542
|
+
render: function (st) {
|
|
543
|
+
if (!st.over) setTilt(0, 0, st.down ? 0.98 : 1);
|
|
544
|
+
if (glare && !st.over) {
|
|
545
|
+
const oldGlare = glare;
|
|
546
|
+
glare = null;
|
|
547
|
+
oldGlare.style.opacity = 0;
|
|
548
|
+
setTimeout(function () { oldGlare.remove(); }, GLARE_FADE_MS);
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
move: function (event) {
|
|
552
|
+
if (UIEffects.reduceMotion) return;
|
|
553
|
+
const rect = obj.elem.getBoundingClientRect();
|
|
554
|
+
if (!rect.width || !rect.height) return;
|
|
555
|
+
const px = (event.clientX - rect.left) / rect.width - 0.5;
|
|
556
|
+
const py = (event.clientY - rect.top) / rect.height - 0.5;
|
|
557
|
+
setTilt((-py * 2 * angle).toFixed(2), (px * 2 * angle).toFixed(2), scale);
|
|
558
|
+
if (useGlare) showGlare(px, py);
|
|
559
|
+
},
|
|
560
|
+
off: function () {
|
|
561
|
+
if (glare) glare.remove();
|
|
562
|
+
},
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// A light follows the pointer. options: color (White(0.25)), size (px, 180)
|
|
567
|
+
UIEffects.types.spotlight = function (obj, o, fx) {
|
|
568
|
+
const color = o.color || White(0.25);
|
|
569
|
+
const size = o.size ?? 180;
|
|
570
|
+
const LIGHT_FADE_MS = 300;
|
|
571
|
+
let light = null;
|
|
572
|
+
const fadingLights = new Set(); // the lights that fade out (removed after LIGHT_FADE_MS)
|
|
573
|
+
return {
|
|
574
|
+
motion: [],
|
|
575
|
+
render: function (st) {
|
|
576
|
+
if (!light) return;
|
|
577
|
+
light.style.opacity = st.over ? 1 : 0;
|
|
578
|
+
// WHY: The light is removed after it fades out. It is a child of the object (button.text reads it too).
|
|
579
|
+
if (!st.over) {
|
|
580
|
+
const oldLight = light;
|
|
581
|
+
light = null;
|
|
582
|
+
fadingLights.add(oldLight);
|
|
583
|
+
setTimeout(function () {
|
|
584
|
+
oldLight.remove();
|
|
585
|
+
fadingLights.delete(oldLight);
|
|
586
|
+
}, LIGHT_FADE_MS);
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
move: function (event) {
|
|
590
|
+
// WHY no clearTimeout of the fading light here: it cancelled its removal, so every quick out-and-in left
|
|
591
|
+
// a span in the object for good (button.text returned "Save<span ...>")
|
|
592
|
+
// WHY: button.text = "..." clears the button's HTML, so the light is created again when it is lost.
|
|
593
|
+
if (!light || light.parentNode !== obj.elem) {
|
|
594
|
+
light = UIEffects._overlay(obj);
|
|
595
|
+
if (!light) return;
|
|
596
|
+
light.style.transition = "opacity " + (LIGHT_FADE_MS / 1000) + "s";
|
|
597
|
+
}
|
|
598
|
+
const point = UIEffects._localPoint(obj, event);
|
|
599
|
+
const center = point.x + "px " + point.y + "px";
|
|
600
|
+
light.style.opacity = 1;
|
|
601
|
+
light.style.background = "radial-gradient(circle " + size + "px at " + center + ", " + color + ", transparent)";
|
|
602
|
+
},
|
|
603
|
+
off: function () {
|
|
604
|
+
fadingLights.forEach(function (oldLight) { oldLight.remove(); });
|
|
605
|
+
fadingLights.clear();
|
|
606
|
+
if (light) light.remove();
|
|
607
|
+
},
|
|
608
|
+
};
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
// *** ANIMATIONS (play and loop):
|
|
612
|
+
// Each one returns: keyframes, duration (seconds), easing, composite ("add": added to the current transform),
|
|
613
|
+
// pause (seconds between two plays in loop()).
|
|
614
|
+
|
|
615
|
+
UIEffects.animations = {};
|
|
616
|
+
|
|
617
|
+
UIEffects.animations.shake = function () {
|
|
618
|
+
return {
|
|
619
|
+
keyframes: ["0", "-8", "8", "-6", "6", "-3", "3", "0"].map(function (x) { return { transform: "translateX(" + x + "px)" }; }),
|
|
620
|
+
duration: 0.5,
|
|
621
|
+
pause: 2,
|
|
622
|
+
};
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
UIEffects.animations.wiggle = function () {
|
|
626
|
+
return {
|
|
627
|
+
keyframes: ["0", "-8", "8", "-6", "6", "-3", "0"].map(function (r) { return { transform: "rotate(" + r + "deg)" }; }),
|
|
628
|
+
duration: 0.6,
|
|
629
|
+
pause: 2,
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
UIEffects.animations.jelly = function () {
|
|
634
|
+
return {
|
|
635
|
+
keyframes: [
|
|
636
|
+
{ transform: "scale(1, 1)" },
|
|
637
|
+
{ transform: "scale(1.15, 0.85)", offset: 0.3 },
|
|
638
|
+
{ transform: "scale(0.9, 1.1)", offset: 0.5 },
|
|
639
|
+
{ transform: "scale(1.05, 0.95)", offset: 0.7 },
|
|
640
|
+
{ transform: "scale(1, 1)" },
|
|
641
|
+
],
|
|
642
|
+
duration: 0.5,
|
|
643
|
+
pause: 1.5,
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
UIEffects.animations.pop = function () {
|
|
648
|
+
return {
|
|
649
|
+
keyframes: [
|
|
650
|
+
{ transform: "scale(1)" },
|
|
651
|
+
{ transform: "scale(1.12)", offset: 0.4 },
|
|
652
|
+
{ transform: "scale(0.96)", offset: 0.7 },
|
|
653
|
+
{ transform: "scale(1)" },
|
|
654
|
+
],
|
|
655
|
+
duration: 0.35,
|
|
656
|
+
easing: "ease-out",
|
|
657
|
+
pause: 1.5,
|
|
658
|
+
};
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
UIEffects.animations.bounce = function () {
|
|
662
|
+
return {
|
|
663
|
+
keyframes: [
|
|
664
|
+
{ transform: "translateY(0px)", easing: "ease-out" },
|
|
665
|
+
{ transform: "translateY(-12px)", offset: 0.3, easing: "ease-in" },
|
|
666
|
+
{ transform: "translateY(0px)", offset: 0.55, easing: "ease-out" },
|
|
667
|
+
{ transform: "translateY(-5px)", offset: 0.75, easing: "ease-in" },
|
|
668
|
+
{ transform: "translateY(0px)" },
|
|
669
|
+
],
|
|
670
|
+
duration: 0.6,
|
|
671
|
+
easing: "linear",
|
|
672
|
+
pause: 1.2,
|
|
673
|
+
};
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
UIEffects.animations.tada = function () {
|
|
677
|
+
return {
|
|
678
|
+
keyframes: [
|
|
679
|
+
{ transform: "scale(1) rotate(0deg)" },
|
|
680
|
+
{ transform: "scale(0.9) rotate(-3deg)", offset: 0.1 },
|
|
681
|
+
{ transform: "scale(0.9) rotate(-3deg)", offset: 0.2 },
|
|
682
|
+
{ transform: "scale(1.1) rotate(3deg)", offset: 0.3 },
|
|
683
|
+
{ transform: "scale(1.1) rotate(-3deg)", offset: 0.45 },
|
|
684
|
+
{ transform: "scale(1.1) rotate(3deg)", offset: 0.6 },
|
|
685
|
+
{ transform: "scale(1.1) rotate(-3deg)", offset: 0.75 },
|
|
686
|
+
{ transform: "scale(1) rotate(0deg)" },
|
|
687
|
+
],
|
|
688
|
+
duration: 0.9,
|
|
689
|
+
pause: 2,
|
|
690
|
+
};
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
UIEffects.animations.heartbeat = function () {
|
|
694
|
+
return {
|
|
695
|
+
keyframes: [
|
|
696
|
+
{ transform: "scale(1)" },
|
|
697
|
+
{ transform: "scale(1.15)", offset: 0.15 },
|
|
698
|
+
{ transform: "scale(1)", offset: 0.3 },
|
|
699
|
+
{ transform: "scale(1.15)", offset: 0.45 },
|
|
700
|
+
{ transform: "scale(1)", offset: 0.7 },
|
|
701
|
+
{ transform: "scale(1)" },
|
|
702
|
+
],
|
|
703
|
+
duration: 1,
|
|
704
|
+
easing: "ease-in-out",
|
|
705
|
+
pause: 0.3,
|
|
706
|
+
};
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
UIEffects.animations.flash = function () {
|
|
710
|
+
return {
|
|
711
|
+
keyframes: [{ opacity: 1 }, { opacity: 0.25 }, { opacity: 1 }, { opacity: 0.25 }, { opacity: 1 }],
|
|
712
|
+
duration: 0.8,
|
|
713
|
+
composite: "replace",
|
|
714
|
+
pause: 2,
|
|
715
|
+
};
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
// A ring grows out of it and fades. options: color, size (px, 14)
|
|
719
|
+
UIEffects.animations.pulse = function (obj, o) {
|
|
720
|
+
const color = o.color || UIEffects._backgroundColor(obj, "rgba(66, 133, 244, 1)");
|
|
721
|
+
const size = o.size ?? 14;
|
|
722
|
+
return {
|
|
723
|
+
keyframes: [
|
|
724
|
+
{ boxShadow: "0px 0px 0px 0px " + UIEffects._alpha(color, 0.6) },
|
|
725
|
+
{ boxShadow: "0px 0px 0px " + size + "px " + UIEffects._alpha(color, 0) },
|
|
726
|
+
],
|
|
727
|
+
duration: 1.5,
|
|
728
|
+
easing: "ease-out",
|
|
729
|
+
pause: 0,
|
|
730
|
+
};
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
// Slowly grows and shrinks. options: scale (1.05)
|
|
734
|
+
UIEffects.animations.breathe = function (obj, o) {
|
|
735
|
+
return {
|
|
736
|
+
keyframes: [
|
|
737
|
+
{ transform: "scale(1)" },
|
|
738
|
+
{ transform: "scale(" + (o.scale ?? 1.05) + ")" },
|
|
739
|
+
{ transform: "scale(1)" },
|
|
740
|
+
],
|
|
741
|
+
duration: 2,
|
|
742
|
+
easing: "ease-in-out",
|
|
743
|
+
pause: 0,
|
|
744
|
+
};
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
// A light around it comes and goes. options: color, size (px, 18)
|
|
748
|
+
UIEffects.animations.glow = function (obj, o) {
|
|
749
|
+
const color = o.color || UIEffects._backgroundColor(obj, "rgba(66, 133, 244, 1)");
|
|
750
|
+
const size = o.size ?? 18;
|
|
751
|
+
return {
|
|
752
|
+
keyframes: [
|
|
753
|
+
{ boxShadow: "0px 0px 0px 0px " + UIEffects._alpha(color, 0) },
|
|
754
|
+
{ boxShadow: "0px 0px " + size + "px 3px " + UIEffects._alpha(color, 0.8) },
|
|
755
|
+
{ boxShadow: "0px 0px 0px 0px " + UIEffects._alpha(color, 0) },
|
|
756
|
+
],
|
|
757
|
+
duration: 2,
|
|
758
|
+
easing: "ease-in-out",
|
|
759
|
+
pause: 0,
|
|
760
|
+
};
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
// *** PRIVATE FUNCTIONS:
|
|
764
|
+
|
|
765
|
+
UIEffects._idCounter = 0;
|
|
766
|
+
|
|
767
|
+
UIEffects._newId = function () {
|
|
768
|
+
UIEffects._idCounter++;
|
|
769
|
+
return "fx" + UIEffects._idCounter + "_";
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
UIEffects._add = function (obj, type, options, usePress) {
|
|
773
|
+
|
|
774
|
+
// Several types: press(btn, ["lift", "ripple"])
|
|
775
|
+
if (Array.isArray(type)) {
|
|
776
|
+
const offList = type.map(function (item) { return UIEffects._add(obj, item, options, usePress); });
|
|
777
|
+
return function off() {
|
|
778
|
+
offList.forEach(function (offItem) { offItem(); });
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const typeFunc = UIEffects.types[type];
|
|
783
|
+
if (!typeFunc) {
|
|
784
|
+
println("UIEffects: Unknown effect type: " + type, "error");
|
|
785
|
+
return function off() {};
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
const id = UIEffects._newId();
|
|
789
|
+
const fx = {
|
|
790
|
+
id: id,
|
|
791
|
+
set: function (prop, value) { UIEffects._setPart(obj, prop, id, value); },
|
|
792
|
+
};
|
|
793
|
+
const effect = typeFunc(obj, options, fx);
|
|
794
|
+
const duration = options.duration ?? effect.duration ?? UIEffects.duration;
|
|
795
|
+
const st = { over: 0, down: 0 };
|
|
796
|
+
const removers = [];
|
|
797
|
+
let pressTimer = null;
|
|
798
|
+
|
|
799
|
+
// WHY: The transition is added before every change, because setMotion() can replace it at any time.
|
|
800
|
+
const update = function (event) {
|
|
801
|
+
UIEffects._addMotion(obj, effect.motion || [], duration);
|
|
802
|
+
effect.render(st, event);
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
// The first state, without motion.
|
|
806
|
+
effect.render(st, null);
|
|
807
|
+
|
|
808
|
+
// HOVER:
|
|
809
|
+
removers.push(obj.on("pointerenter", function (self, event) {
|
|
810
|
+
if (event.pointerType === "touch" || UIEffects._isDisabled(obj)) return;
|
|
811
|
+
st.over = 1;
|
|
812
|
+
update(event);
|
|
813
|
+
}));
|
|
814
|
+
|
|
815
|
+
removers.push(obj.on("pointerleave", function (self, event) {
|
|
816
|
+
if (!st.over) return;
|
|
817
|
+
st.over = 0;
|
|
818
|
+
update(event);
|
|
819
|
+
}));
|
|
820
|
+
|
|
821
|
+
if (effect.move) {
|
|
822
|
+
removers.push(obj.on("pointermove", function (self, event) {
|
|
823
|
+
if (st.over) effect.move(event);
|
|
824
|
+
}));
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// PRESS:
|
|
828
|
+
if (usePress) {
|
|
829
|
+
|
|
830
|
+
const DEFAULT_PRESS_TIME_MS = 120;
|
|
831
|
+
const pressTime = options.pressTime ?? effect.pressTime ?? DEFAULT_PRESS_TIME_MS;
|
|
832
|
+
let downTime = 0;
|
|
833
|
+
|
|
834
|
+
removers.push(obj.on("pointerdown", function (self, event) {
|
|
835
|
+
if (event.button > 0 || UIEffects._isDisabled(obj)) return;
|
|
836
|
+
clearTimeout(pressTimer);
|
|
837
|
+
st.down = 1;
|
|
838
|
+
downTime = Date.now();
|
|
839
|
+
update(event);
|
|
840
|
+
}));
|
|
841
|
+
|
|
842
|
+
const release = function (self, event) {
|
|
843
|
+
if (!st.down) return;
|
|
844
|
+
// WHY: A quick tap is shorter than the transition. The pressed state is kept for a short time, so it is seen.
|
|
845
|
+
const wait = Math.max(0, pressTime - (Date.now() - downTime));
|
|
846
|
+
clearTimeout(pressTimer);
|
|
847
|
+
pressTimer = setTimeout(function () {
|
|
848
|
+
st.down = 0;
|
|
849
|
+
update(event);
|
|
850
|
+
}, wait);
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
removers.push(obj.on("pointerup", release));
|
|
854
|
+
removers.push(obj.on("pointerleave", release));
|
|
855
|
+
removers.push(obj.on("pointercancel", release));
|
|
856
|
+
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
return function off() {
|
|
860
|
+
clearTimeout(pressTimer);
|
|
861
|
+
removers.forEach(function (remove) { remove(); });
|
|
862
|
+
removers.length = 0;
|
|
863
|
+
if (effect.off) effect.off();
|
|
864
|
+
UIEffects._clearParts(obj, id);
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
// The value for the state of an effect: values.down while pressed, values.over while hovered, else values.normal.
|
|
870
|
+
UIEffects._byState = function (st, values) {
|
|
871
|
+
if (st.down) return values.down;
|
|
872
|
+
if (st.over) return values.over;
|
|
873
|
+
return values.normal;
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
UIEffects._isDisabled = function (obj) {
|
|
877
|
+
return obj.elem.disabled === true || obj.enabled === 0;
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
// The transform, filter and box-shadow values of all effects on an object are kept in parts and combined.
|
|
881
|
+
UIEffects._state = function (obj) {
|
|
882
|
+
if (!obj._uiEffects) {
|
|
883
|
+
const elem = obj.elem;
|
|
884
|
+
const computedShadow = getComputedStyle(elem).boxShadow;
|
|
885
|
+
const hasComputedShadow = (computedShadow && computedShadow !== "none");
|
|
886
|
+
obj._uiEffects = {
|
|
887
|
+
base: {
|
|
888
|
+
transform: elem.style.transform || "",
|
|
889
|
+
filter: elem.style.filter || "",
|
|
890
|
+
// WHY: A Button has an inset shadow in basic.css. The effects must keep it.
|
|
891
|
+
boxShadow: elem.style.boxShadow || ((hasComputedShadow) ? computedShadow : ""),
|
|
892
|
+
},
|
|
893
|
+
parts: { transform: {}, filter: {}, boxShadow: {} },
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
return obj._uiEffects;
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
UIEffects._setPart = function (obj, prop, key, value) {
|
|
900
|
+
const state = UIEffects._state(obj);
|
|
901
|
+
// WHY: A transform or filter (even scale(1)) makes the object the container of its position: fixed children
|
|
902
|
+
// (popups, menus). So a value that changes nothing is not written.
|
|
903
|
+
const isKept = value && (prop === "boxShadow" || !UIEffects._isNeutral(value));
|
|
904
|
+
if (isKept) state.parts[prop][key] = value;
|
|
905
|
+
else delete state.parts[prop][key];
|
|
906
|
+
const list = [];
|
|
907
|
+
if (state.base[prop]) list.push(state.base[prop]);
|
|
908
|
+
for (const partKey in state.parts[prop]) list.push(state.parts[prop][partKey]);
|
|
909
|
+
obj.elem.style[prop] = list.join((prop === "boxShadow") ? ", " : " ");
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
// scale(1), translateY(0px), brightness(1), blur(0px)... -> true
|
|
913
|
+
UIEffects._isNeutral = function (value) {
|
|
914
|
+
const funcs = value.match(/[a-zA-Z]+\([^)]*\)/g);
|
|
915
|
+
if (!funcs) return false;
|
|
916
|
+
return funcs.every(function (func) {
|
|
917
|
+
const name = func.substr(0, func.indexOf("("));
|
|
918
|
+
const args = func.slice(name.length + 1, -1).split(",").map(function (arg) { return parseFloat(arg); });
|
|
919
|
+
if (name === "perspective") return true;
|
|
920
|
+
const isOneNeutral = /^(scale|brightness|opacity|contrast|saturate)/.test(name);
|
|
921
|
+
if (isOneNeutral) return args.every(function (arg) { return arg === 1; });
|
|
922
|
+
return args.every(function (arg) { return arg === 0; }); // translate, rotate, skew, blur, grayscale...
|
|
923
|
+
});
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
UIEffects._clearParts = function (obj, id) {
|
|
927
|
+
const state = obj._uiEffects;
|
|
928
|
+
if (!state) return;
|
|
929
|
+
["transform", "filter", "boxShadow"].forEach(function (prop) {
|
|
930
|
+
let isChanged = 0;
|
|
931
|
+
for (const partKey in state.parts[prop]) {
|
|
932
|
+
if (partKey.indexOf(id) === 0) {
|
|
933
|
+
delete state.parts[prop][partKey];
|
|
934
|
+
isChanged = 1;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
if (isChanged) UIEffects._setPart(obj, prop, "", "");
|
|
938
|
+
});
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
// Adds the missing properties to the transition of the object. It keeps the existing ones (setMotion).
|
|
942
|
+
UIEffects._addMotion = function (obj, props, duration) {
|
|
943
|
+
if (!props.length) return;
|
|
944
|
+
const elem = obj.elem;
|
|
945
|
+
const current = elem.style.transition || "";
|
|
946
|
+
if (/(^|,)\s*all(\s|,|$)/.test(current)) return;
|
|
947
|
+
// WHY: Split by the commas that are not in parentheses: cubic-bezier(0.25, 0.8, 0.25, 1)
|
|
948
|
+
const parts = (current) ? current.split(/,(?![^(]*\))/) : [];
|
|
949
|
+
const items = parts.map(function (item) { return item.trim(); }).filter(Boolean);
|
|
950
|
+
const names = items.map(function (item) { return item.split(/\s+/)[0]; });
|
|
951
|
+
let isChanged = 0;
|
|
952
|
+
props.forEach(function (prop) {
|
|
953
|
+
if (names.indexOf(prop) === -1) {
|
|
954
|
+
items.push(prop + " " + duration + "s " + UIEffects.easing);
|
|
955
|
+
names.push(prop);
|
|
956
|
+
isChanged = 1;
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
if (isChanged) elem.style.transition = items.join(", ");
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
// A layer on the object for ripple, shine, spotlight and the tilt glare. (Not possible in <img> and <input>.)
|
|
963
|
+
UIEffects._overlay = function (obj) {
|
|
964
|
+
const elem = obj.elem;
|
|
965
|
+
if (elem.tagName === "IMG" || elem.tagName === "INPUT" || obj._type === "textbox") return null;
|
|
966
|
+
const layer = document.createElement("span");
|
|
967
|
+
layer.style.cssText = "position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: hidden; border-radius: inherit; pointer-events: none;";
|
|
968
|
+
elem.appendChild(layer);
|
|
969
|
+
return layer;
|
|
970
|
+
};
|
|
971
|
+
|
|
972
|
+
// The pointer position in the object (px), also when the page is zoomed (page.fit) or the object is scaled.
|
|
973
|
+
UIEffects._localPoint = function (obj, event) {
|
|
974
|
+
const elem = obj.elem;
|
|
975
|
+
const rect = elem.getBoundingClientRect();
|
|
976
|
+
const scaleX = rect.width ? elem.offsetWidth / rect.width : 1;
|
|
977
|
+
const scaleY = rect.height ? elem.offsetHeight / rect.height : 1;
|
|
978
|
+
if (event.clientX === undefined) return { x: elem.offsetWidth / 2, y: elem.offsetHeight / 2 };
|
|
979
|
+
return {
|
|
980
|
+
x: (event.clientX - rect.left) * scaleX - elem.clientLeft,
|
|
981
|
+
y: (event.clientY - rect.top) * scaleY - elem.clientTop,
|
|
982
|
+
};
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
UIEffects._ripple = function (obj, event, color, time) {
|
|
986
|
+
if (UIEffects.reduceMotion) return;
|
|
987
|
+
const layer = UIEffects._overlay(obj);
|
|
988
|
+
if (!layer) return;
|
|
989
|
+
const elem = obj.elem;
|
|
990
|
+
const point = UIEffects._localPoint(obj, event);
|
|
991
|
+
// WHY: The radius reaches the farthest corner, so the wave covers the whole object.
|
|
992
|
+
const farthestX = Math.max(point.x, elem.clientWidth - point.x);
|
|
993
|
+
const farthestY = Math.max(point.y, elem.clientHeight - point.y);
|
|
994
|
+
const radius = Math.sqrt(Math.pow(farthestX, 2) + Math.pow(farthestY, 2));
|
|
995
|
+
|
|
996
|
+
const dot = document.createElement("span");
|
|
997
|
+
dot.style.cssText = "position: absolute; border-radius: 50%; pointer-events: none;"
|
|
998
|
+
+ "left: " + (point.x - radius) + "px; top: " + (point.y - radius) + "px;"
|
|
999
|
+
+ " width: " + (radius * 2) + "px; height: " + (radius * 2) + "px; background: " + color + ";";
|
|
1000
|
+
layer.appendChild(dot);
|
|
1001
|
+
|
|
1002
|
+
const animation = dot.animate([
|
|
1003
|
+
{ transform: "scale(0)", opacity: 1 },
|
|
1004
|
+
{ transform: "scale(1)", opacity: 0.7, offset: 0.6 },
|
|
1005
|
+
{ transform: "scale(1)", opacity: 0 },
|
|
1006
|
+
], { duration: time * 1000, easing: "cubic-bezier(0.2, 0.6, 0.35, 1)" });
|
|
1007
|
+
UIEffects._removeAfter(layer, animation, time);
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
UIEffects._shine = function (obj, color, time) {
|
|
1011
|
+
if (UIEffects.reduceMotion) return;
|
|
1012
|
+
const layer = UIEffects._overlay(obj);
|
|
1013
|
+
if (!layer) return;
|
|
1014
|
+
const width = obj.elem.offsetWidth;
|
|
1015
|
+
const streakWidth = Math.max(30, width * 0.4);
|
|
1016
|
+
|
|
1017
|
+
const streak = document.createElement("span");
|
|
1018
|
+
streak.style.cssText = "position: absolute; top: -20%; bottom: -20%; left: 0px; pointer-events: none;"
|
|
1019
|
+
+ "width: " + streakWidth + "px; background: linear-gradient(90deg, transparent, " + color + ", transparent);";
|
|
1020
|
+
layer.appendChild(streak);
|
|
1021
|
+
|
|
1022
|
+
const animation = streak.animate([
|
|
1023
|
+
{ transform: "translateX(" + (-streakWidth * 1.5) + "px) skewX(-20deg)" },
|
|
1024
|
+
{ transform: "translateX(" + (width + streakWidth * 0.5) + "px) skewX(-20deg)" },
|
|
1025
|
+
], { duration: time * 1000, easing: "ease-in-out" });
|
|
1026
|
+
UIEffects._removeAfter(layer, animation, time);
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
// WHY: A hidden tab does not play animations (no finish event), so a timer removes the layer too.
|
|
1030
|
+
UIEffects._removeAfter = function (layer, animation, time) {
|
|
1031
|
+
const remove = function () { layer.remove(); };
|
|
1032
|
+
animation.onfinish = remove;
|
|
1033
|
+
animation.oncancel = remove;
|
|
1034
|
+
setTimeout(remove, time * 1000 + 100);
|
|
1035
|
+
};
|
|
1036
|
+
|
|
1037
|
+
UIEffects._getAnimation = function (obj, name, options) {
|
|
1038
|
+
const func = UIEffects.animations[name];
|
|
1039
|
+
if (!func) {
|
|
1040
|
+
println("UIEffects: Unknown animation: " + name, "error");
|
|
1041
|
+
return null;
|
|
1042
|
+
}
|
|
1043
|
+
return func(obj, options);
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
// Puts the keyframes in the first part of the time, and waits in the rest.
|
|
1047
|
+
UIEffects._withPause = function (keyframes, duration, pause, easing) {
|
|
1048
|
+
const ratio = duration / (duration + pause);
|
|
1049
|
+
const count = keyframes.length;
|
|
1050
|
+
// The offset of a keyframe in the animation without the pause (0-1). Without an offset: evenly spaced.
|
|
1051
|
+
const getOffset = function (frame, index) {
|
|
1052
|
+
if (frame.offset !== undefined) return frame.offset;
|
|
1053
|
+
if (count > 1) return index / (count - 1);
|
|
1054
|
+
return 0;
|
|
1055
|
+
};
|
|
1056
|
+
const result = keyframes.map(function (frame, index) {
|
|
1057
|
+
const copy = Object.assign({}, frame);
|
|
1058
|
+
if (!copy.easing) copy.easing = easing;
|
|
1059
|
+
copy.offset = getOffset(frame, index) * ratio;
|
|
1060
|
+
return copy;
|
|
1061
|
+
});
|
|
1062
|
+
const last = Object.assign({}, keyframes[count - 1]);
|
|
1063
|
+
delete last.easing;
|
|
1064
|
+
last.offset = 1;
|
|
1065
|
+
result.push(last);
|
|
1066
|
+
return result;
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
// The background color of the object, if it is not transparent.
|
|
1070
|
+
UIEffects._backgroundColor = function (obj, fallback) {
|
|
1071
|
+
const color = getComputedStyle(obj.elem).backgroundColor;
|
|
1072
|
+
if (!color || color === "transparent" || /rgba\(.*,\s*0\)$/.test(color)) return fallback;
|
|
1073
|
+
return color;
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
// Any CSS color with a new alpha: _alpha("#4A90E2", 0.5) -> "rgba(74, 144, 226, 0.5)"
|
|
1077
|
+
UIEffects._alpha = function (color, alpha) {
|
|
1078
|
+
if (!UIEffects._colorContext) UIEffects._colorContext = document.createElement("canvas").getContext("2d");
|
|
1079
|
+
const ctx = UIEffects._colorContext;
|
|
1080
|
+
ctx.fillStyle = "#000000";
|
|
1081
|
+
ctx.fillStyle = color;
|
|
1082
|
+
const value = ctx.fillStyle; // "#rrggbb" or "rgba(r, g, b, a)"
|
|
1083
|
+
let r = 0;
|
|
1084
|
+
let g = 0;
|
|
1085
|
+
let b = 0;
|
|
1086
|
+
if (value.charAt(0) === "#") {
|
|
1087
|
+
r = parseInt(value.substr(1, 2), 16);
|
|
1088
|
+
g = parseInt(value.substr(3, 2), 16);
|
|
1089
|
+
b = parseInt(value.substr(5, 2), 16);
|
|
1090
|
+
} else {
|
|
1091
|
+
const numbers = value.match(/[\d.]+/g) || [0, 0, 0];
|
|
1092
|
+
r = numbers[0];
|
|
1093
|
+
g = numbers[1];
|
|
1094
|
+
b = numbers[2];
|
|
1095
|
+
}
|
|
1096
|
+
return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
|
|
1097
|
+
};
|