@shijiu/jsview 1.9.730 → 1.9.747
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.
- package/dom/jsv-browser-debug-dom.js +1 -1
- package/dom/jsv-dom.js +1 -1
- package/dom/jsv-engine-js-browser.js +1 -1
- package/dom/jsv-forge-define.js +1 -1
- package/package.json +14 -17
- package/patches/node_modules/vite/dist/node/chunks/dep-0fc8e132.js +8 -1
- package/patches/node_modules/vite/dist/node/jsview.vite.config.js +12 -6
- package/dom/jsview-dom/README.md +0 -5
- package/dom/jsview-dom/package-lock.json-perfect +0 -3898
- package/dom/jsview-dom/package.json +0 -23
- package/dom/jsview-dom/rollup/browser-debug-dom.rollup.config.js +0 -15
- package/dom/jsview-dom/rollup/dom.rollup.config.js +0 -14
- package/dom/jsview-dom/rollup/engine-js-browser.rollup.config.js +0 -14
- package/dom/jsview-dom/rollup/forge-define.rollup.config.js +0 -14
- package/dom/jsview-dom/scripts/release_dist.sh +0 -36
- package/dom/jsview-dom/src/dom-browser-hook/HookDocument.js +0 -118
- package/dom/jsview-dom/src/dom-browser-hook/OriginDocument.js +0 -19
- package/dom/jsview-dom/src/dom-browser-hook/StyleFormatCheck.js +0 -559
- package/dom/jsview-dom/src/dom-browser-hook/index.js +0 -6
- package/dom/jsview-dom/src/dom-wrapper/ForgeExtension.js +0 -226
- package/dom/jsview-dom/src/dom-wrapper/JsViewForgeApp.js +0 -85
- package/dom/jsview-dom/src/dom-wrapper/JsViewProxy.js +0 -51
- package/dom/jsview-dom/src/dom-wrapper/event/AnimationEvent.js +0 -7
- package/dom/jsview-dom/src/dom-wrapper/event/Event.js +0 -12
- package/dom/jsview-dom/src/dom-wrapper/event/FocusEvent.js +0 -9
- package/dom/jsview-dom/src/dom-wrapper/event/KeyboardEvent.js +0 -43
- package/dom/jsview-dom/src/dom-wrapper/event/LoadEvent.js +0 -8
- package/dom/jsview-dom/src/dom-wrapper/index.js +0 -16
- package/dom/jsview-dom/src/dom-wrapper/node/AnchorElement.js +0 -24
- package/dom/jsview-dom/src/dom-wrapper/node/AudioElement.js +0 -60
- package/dom/jsview-dom/src/dom-wrapper/node/Comment.js +0 -10
- package/dom/jsview-dom/src/dom-wrapper/node/DivElement.js +0 -498
- package/dom/jsview-dom/src/dom-wrapper/node/Document.js +0 -274
- package/dom/jsview-dom/src/dom-wrapper/node/Element.js +0 -852
- package/dom/jsview-dom/src/dom-wrapper/node/FDivElement.js +0 -48
- package/dom/jsview-dom/src/dom-wrapper/node/HeadElement.js +0 -47
- package/dom/jsview-dom/src/dom-wrapper/node/ImageElement.js +0 -203
- package/dom/jsview-dom/src/dom-wrapper/node/JsvAudioTrackElement.js +0 -22
- package/dom/jsview-dom/src/dom-wrapper/node/JsvElement.js +0 -40
- package/dom/jsview-dom/src/dom-wrapper/node/LinkElement.js +0 -48
- package/dom/jsview-dom/src/dom-wrapper/node/MediaElement.js +0 -230
- package/dom/jsview-dom/src/dom-wrapper/node/Node.js +0 -178
- package/dom/jsview-dom/src/dom-wrapper/node/SVGElement.js +0 -9
- package/dom/jsview-dom/src/dom-wrapper/node/ScriptElement.js +0 -45
- package/dom/jsview-dom/src/dom-wrapper/node/StyleElement.js +0 -33
- package/dom/jsview-dom/src/dom-wrapper/node/StyleElementCache.js +0 -41
- package/dom/jsview-dom/src/dom-wrapper/node/Text.js +0 -22
- package/dom/jsview-dom/src/dom-wrapper/node/UnknownElement.js +0 -4
- package/dom/jsview-dom/src/dom-wrapper/node/VideoElement.js +0 -237
- package/dom/jsview-dom/src/dom-wrapper/style/BorderImage.js +0 -25
- package/dom/jsview-dom/src/dom-wrapper/style/Inset.js +0 -26
- package/dom/jsview-dom/src/dom-wrapper/style/JsvStyleVariable.js +0 -65
- package/dom/jsview-dom/src/dom-wrapper/style/KeyframeRule.js +0 -11
- package/dom/jsview-dom/src/dom-wrapper/style/StyleDeclaration.js +0 -609
- package/dom/jsview-dom/src/dom-wrapper/style/StyleSheet.js +0 -51
- package/dom/jsview-dom/src/dom-wrapper/style/StyleValue.js +0 -385
- package/dom/jsview-dom/src/dom-wrapper/style/TextStylePackMap.js +0 -43
- package/dom/jsview-dom/src/dom-wrapper/style/URL.js +0 -144
- package/dom/jsview-dom/src/dom-wrapper/utils/EventHandler.js +0 -42
- package/dom/jsview-dom/src/dom-wrapper/utils/FDivRoot.js +0 -86
- package/dom/jsview-dom/src/dom-wrapper/utils/JsvLazySyncCache.js +0 -64
- package/dom/jsview-dom/src/dom-wrapper/utils/Log.js +0 -42
- package/dom/jsview-dom/src/dom-wrapper/utils/MutationObserver.js +0 -32
- package/dom/jsview-dom/src/dom-wrapper/utils/focusableNode.js +0 -715
- package/dom/jsview-dom/src/engine-js/ForgeDefine.js +0 -8
- package/dom/jsview-dom/src/engine-js/ForgeExtensionDefine.js +0 -14
- package/dom/jsview-dom/src/engine-js/browser/PlatformUtils.js +0 -100
- package/dom/jsview-dom/src/engine-js/browser/animation_base.js +0 -313
- package/dom/jsview-dom/src/engine-js/browser/animation_keyframe.js +0 -64
- package/dom/jsview-dom/src/engine-js/browser/animation_progress.js +0 -287
- package/dom/jsview-dom/src/engine-js/browser/animation_proxy.js +0 -906
- package/dom/jsview-dom/src/engine-js/browser/apic_decoder/demux.js +0 -143
- package/dom/jsview-dom/src/engine-js/browser/apic_decoder/gifDecoder.js +0 -12
- package/dom/jsview-dom/src/engine-js/browser/apic_decoder/libwebp-0.6.0.min.js +0 -160
- package/dom/jsview-dom/src/engine-js/browser/console_log.js +0 -25
- package/dom/jsview-dom/src/engine-js/browser/dynamic_key_frames.js +0 -95
- package/dom/jsview-dom/src/engine-js/browser/easing.js +0 -114
- package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/element_transform.js +0 -122
- package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/gjk.js +0 -450
- package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/mat.js +0 -102
- package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/range_model.js +0 -296
- package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/test_collide.js +0 -10
- package/dom/jsview-dom/src/engine-js/browser/index.js +0 -38
- package/dom/jsview-dom/src/engine-js/browser/latex_parse.js +0 -336
- package/dom/jsview-dom/src/engine-js/browser/layout_params.js +0 -113
- package/dom/jsview-dom/src/engine-js/browser/layout_view.js +0 -3545
- package/dom/jsview-dom/src/engine-js/browser/layout_view_debug.js +0 -15
- package/dom/jsview-dom/src/engine-js/browser/media.js +0 -379
- package/dom/jsview-dom/src/engine-js/browser/page_base.js +0 -941
- package/dom/jsview-dom/src/engine-js/browser/particle_view.js +0 -526
- package/dom/jsview-dom/src/engine-js/browser/platform_timer.js +0 -61
- package/dom/jsview-dom/src/engine-js/browser/react_utils.js +0 -5
- package/dom/jsview-dom/src/engine-js/browser/rect_utils.js +0 -91
- package/dom/jsview-dom/src/engine-js/browser/render_bridge.js +0 -128
- package/dom/jsview-dom/src/engine-js/browser/render_texture_proxy.js +0 -155
- package/dom/jsview-dom/src/engine-js/browser/renderer_deprecated.js +0 -75
- package/dom/jsview-dom/src/engine-js/browser/sound_pool.js +0 -139
- package/dom/jsview-dom/src/engine-js/browser/steps_animation.js +0 -192
- package/dom/jsview-dom/src/engine-js/browser/text_style_cache.js +0 -454
- package/dom/jsview-dom/src/engine-js/browser/text_utils.js +0 -299
- package/dom/jsview-dom/src/engine-js/browser/text_view.js +0 -428
- package/dom/jsview-dom/src/engine-js/browser/texture_manager.js +0 -1060
- package/dom/jsview-dom/src/engine-js/browser/url.js +0 -69
- package/dom/jsview-dom/src/engine-js/browser/velocity.js +0 -40
- package/dom/jsview-dom/src/engine-js/browser/view_sensor/autofroze_sensor.js +0 -77
- package/dom/jsview-dom/src/engine-js/browser/view_sensor/drag_impact_sensor.js +0 -67
- package/dom/jsview-dom/src/engine-js/browser/view_sensor/impact_sensor.js +0 -98
- package/dom/jsview-dom/src/engine-js/browser/view_sensor/impact_sensor_callback.js +0 -21
- package/dom/jsview-dom/src/engine-js/browser/view_sensor/impact_sensor_manager.js +0 -24
- package/dom/jsview-dom/src/engine-js/browser/view_sensor/index.js +0 -9
- package/dom/jsview-dom/src/engine-js/browser/view_sensor/view_sensor.js +0 -268
- package/dom/jsview-dom/src/engine-js/browser/view_sensor/view_sensor_manager.js +0 -84
- package/dom/jsview-dom/src/engine-js/browser/view_sensor/visible_sensor.js +0 -213
- package/dom/jsview-dom/src/engine-js/browser/view_store.js +0 -41
- package/dom/jsview-dom/src/engine-js/index.js +0 -2
- package/dom/jsview-dom/src/engine-js/native/README.md +0 -1
|
@@ -1,906 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
import Forge from "../ForgeDefine";
|
|
3
|
-
import { AnimationProgress, AnimationGroupProgress } from "./animation_progress";
|
|
4
|
-
import { convertTimingFunc, animationToStyle, getStaticFrameControl } from "./animation_keyframe";
|
|
5
|
-
|
|
6
|
-
let sKeyFrameTokenGenerator = 0;
|
|
7
|
-
|
|
8
|
-
Forge.AnimationDelegate = class extends Forge.AnimationBase {
|
|
9
|
-
constructor(type_name, duration, easing) {
|
|
10
|
-
super();
|
|
11
|
-
|
|
12
|
-
let easing_packed = null;
|
|
13
|
-
if (easing) {
|
|
14
|
-
easing_packed = easing.Package();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
this.typeName = type_name;
|
|
18
|
-
this.duration = duration;
|
|
19
|
-
this.easing = easing_packed;
|
|
20
|
-
this.repeatTimes = 1;
|
|
21
|
-
this.delayedTime = 0;
|
|
22
|
-
this.enableFlags = -1;// default invalid
|
|
23
|
-
this.enableStartPos = 0;
|
|
24
|
-
|
|
25
|
-
this._Progress = null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
EnableDelay(delay) {
|
|
29
|
-
this.delayedTime = delay;
|
|
30
|
-
return this; // 支持链式操作
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
SetStartPos(start_pos/* 取值0 - 1 */) {
|
|
34
|
-
this.enableStartPos = start_pos;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
EnableInfinite() {
|
|
38
|
-
this.repeatTimes = -1; // -1 相当于无限
|
|
39
|
-
return this; // 支持链式操作
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
SetRepeat(times) {
|
|
43
|
-
this.repeatTimes = times;
|
|
44
|
-
return this; // 支持链式操作
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
Enable(enable) {
|
|
48
|
-
this._EnableFlagsInner(enable);
|
|
49
|
-
return this; // 支持链式操作
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Override
|
|
53
|
-
OnNewListener(listener) {
|
|
54
|
-
let new_flags = 0;
|
|
55
|
-
if (listener.OnAnimFinal) {
|
|
56
|
-
new_flags |= Forge.AnimationEnable.AckFinalProgress;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (listener.OnAnimRepeat) {
|
|
60
|
-
new_flags |= Forge.AnimationEnable.AckRepeat;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (new_flags !== 0) {
|
|
64
|
-
this._EnableFlagsInner(new_flags);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
_EnableFlagsInner(new_flags) {
|
|
69
|
-
if (this.enableFlags !== -1) {
|
|
70
|
-
this.enableFlags |= new_flags;
|
|
71
|
-
} else {
|
|
72
|
-
// 首次设置
|
|
73
|
-
this.enableFlags = new_flags;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
_GetCSSKeyframesRule(name) {
|
|
78
|
-
let key_frames_rule = null;
|
|
79
|
-
// 获取所有的style
|
|
80
|
-
const ss = document.styleSheets;
|
|
81
|
-
for (let i = 0; i < ss.length; ++i) {
|
|
82
|
-
if (ss[i] && ss[i].cssRules) {
|
|
83
|
-
for (const obj in ss[i].cssRules) {
|
|
84
|
-
if (ss[i].cssRules[obj].name === name) {
|
|
85
|
-
key_frames_rule = ss[i].cssRules[obj];
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (key_frames_rule) {
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return key_frames_rule;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
CheckCssAnimationFormat(anim_name) {
|
|
98
|
-
const key_frames_rule = this._GetCSSKeyframesRule(anim_name);
|
|
99
|
-
if (key_frames_rule && key_frames_rule.cssRules) {
|
|
100
|
-
for (const obj in key_frames_rule.cssRules) {
|
|
101
|
-
if (!key_frames_rule.cssRules[obj] || !key_frames_rule.cssRules[obj].style) {
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (!key_frames_rule.cssRules[obj].style.opacity
|
|
105
|
-
&& !key_frames_rule.cssRules[obj].style.transform) {
|
|
106
|
-
// TODO: samples/Basic的动画会正常走到这里
|
|
107
|
-
// console.error(`@keyframe ${anim_name}, transform parse error! cssText:${key_frames_rule.cssText}`);
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const transform = key_frames_rule.cssRules[obj].style.transform;
|
|
112
|
-
if (!transform) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (transform.indexOf('rotate(') !== -1) {
|
|
117
|
-
console.error(`@keyframe ${anim_name}, only support rotate3d, current transform:${transform}`);
|
|
118
|
-
} else if (transform.indexOf('translate(') !== -1) {
|
|
119
|
-
console.error(`@keyframe ${anim_name}, only support translate3d, current transform:${transform}`);
|
|
120
|
-
} else if (transform.indexOf('scale(') !== -1) {
|
|
121
|
-
console.error(`@keyframe ${anim_name}, only support scale3d, current transform:${transform}`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
Forge.KeyFrameAnimation = class extends Forge.AnimationDelegate {
|
|
129
|
-
constructor(type, duration, easing) {
|
|
130
|
-
super(type, duration, easing);
|
|
131
|
-
this._KeyFrameNameToRecycle = null;
|
|
132
|
-
|
|
133
|
-
this._TestRepeat = this._TestRepeat.bind(this);
|
|
134
|
-
this._LatestProgressValue = 0;
|
|
135
|
-
|
|
136
|
-
const that = this;
|
|
137
|
-
this._OnEndEvent = (event) => {
|
|
138
|
-
event.stopPropagation();
|
|
139
|
-
that._PerformAnimationEnd(true);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
this._CurrentEndEventFunc = null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
Start(layout_view) {
|
|
146
|
-
super.Start(layout_view);
|
|
147
|
-
// Keyframe动画启动时,清理transform,以保证动画行为正确
|
|
148
|
-
layout_view.ResetCssTransform(null, null);
|
|
149
|
-
if (layout_view.Element) {
|
|
150
|
-
layout_view.Element.style.pointerEvents = "auto";
|
|
151
|
-
}
|
|
152
|
-
if (this.enableStartPos > 0) {
|
|
153
|
-
// 有启动进度偏移(例如以30%进度的位置开始启动)
|
|
154
|
-
this._EnableStarterAnimation();
|
|
155
|
-
} else {
|
|
156
|
-
this._EnableCssAnimation(this._BuildKeyFrame(), this._OnEndEvent, 0);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
Cancel() {
|
|
161
|
-
super.Cancel();
|
|
162
|
-
this._PerformAnimationEnd(false);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
_EnableStarterAnimation() {
|
|
166
|
-
let end_func = this._OnEndEvent;
|
|
167
|
-
if (this.repeatTimes !== 1) {
|
|
168
|
-
// 有动画Repeat处理
|
|
169
|
-
const that = this;
|
|
170
|
-
end_func = (event) => {
|
|
171
|
-
event.stopPropagation();
|
|
172
|
-
if (that._Progress !== null) {
|
|
173
|
-
that._Progress.Stop();
|
|
174
|
-
}
|
|
175
|
-
// 启动重复动画前清理延迟时间和repeat次数-1
|
|
176
|
-
that.delayedTime = 0;
|
|
177
|
-
if (that.repeatTimes > 0) {
|
|
178
|
-
that.repeatTimes -= 1;
|
|
179
|
-
}
|
|
180
|
-
this.OnRepeatEvent();
|
|
181
|
-
that._EnableCssAnimation(that._BuildKeyFrame(), that._OnEndEvent, 0);
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// 首次动画,repeat临时调成1次,在此动画结束后,再开始循环
|
|
186
|
-
const saved_repeat_time = this.repeatTimes;
|
|
187
|
-
const saved_duration = this.duration;
|
|
188
|
-
this.repeatTimes = 1;
|
|
189
|
-
this.duration *= (1 - this.enableStartPos);
|
|
190
|
-
|
|
191
|
-
this._EnableCssAnimation(this._BuildStarterKeyFrame(), end_func, this.enableStartPos);
|
|
192
|
-
|
|
193
|
-
// 恢复存储值
|
|
194
|
-
this.repeatTimes = saved_repeat_time;
|
|
195
|
-
this.duration = saved_duration;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
_EnableCssAnimation(animation, on_end_func, start_position) {
|
|
199
|
-
if (animation === null) return;
|
|
200
|
-
if (animation.keyFrameString !== null) {
|
|
201
|
-
getStaticFrameControl().insertRule(animation.keyFrameString);
|
|
202
|
-
this._KeyFrameNameToRecycle = animation.name;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const anim_name = animation.name;
|
|
206
|
-
// 检查css animation transform格式
|
|
207
|
-
this.CheckCssAnimationFormat(anim_name);
|
|
208
|
-
|
|
209
|
-
const html_element = this._LayoutViewRef.Element;
|
|
210
|
-
|
|
211
|
-
// 创建Progress跟踪器
|
|
212
|
-
if ((this.enableFlags & Forge.AnimationEnable.AckFinalProgress) !== 0
|
|
213
|
-
|| (this.enableFlags & Forge.AnimationEnable.KeepTransform) !== 0
|
|
214
|
-
|| (this.enableFlags & Forge.AnimationEnable.AckRepeat) !== 0) {
|
|
215
|
-
this._Progress = new AnimationProgress(this._LayoutViewRef);
|
|
216
|
-
this._Progress.Start(this, start_position, (progress) => {
|
|
217
|
-
this.OnAnimAdvance(progress);
|
|
218
|
-
});
|
|
219
|
-
if ((this.enableFlags & Forge.AnimationEnable.AckRepeat) !== 0) {
|
|
220
|
-
this._LatestProgressValue = 0;
|
|
221
|
-
Forge.sRenderBridge.RegisterPerFrameCallback(this._TestRepeat);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const style_animation = animationToStyle(this, anim_name);
|
|
226
|
-
|
|
227
|
-
// name duration timing-function delay iteration-count direction;
|
|
228
|
-
if (!window.jsvInAndroidWebView) {
|
|
229
|
-
html_element.style.animation = style_animation;
|
|
230
|
-
html_element.addEventListener("animationend", on_end_func);
|
|
231
|
-
} else {
|
|
232
|
-
html_element.style.webkitAnimation = style_animation;
|
|
233
|
-
html_element.addEventListener("webkitAnimationEnd", on_end_func);
|
|
234
|
-
}
|
|
235
|
-
this._CurrentEndEventFunc = on_end_func;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
_PerformAnimationEnd(on_end) {
|
|
239
|
-
// 清理OnEndListener监听,否则会重复收到
|
|
240
|
-
if (this._CurrentEndEventFunc !== null) {
|
|
241
|
-
const element = this._LayoutViewRef.Element;
|
|
242
|
-
const animate_end_callback = this._CurrentEndEventFunc;
|
|
243
|
-
// 异步进行removeEventListener处理,以解决event.stopPropagation不生效的问题
|
|
244
|
-
setTimeout(() => {
|
|
245
|
-
if (!window.jsvInAndroidWebView) {
|
|
246
|
-
element.removeEventListener("animationend", animate_end_callback);
|
|
247
|
-
} else {
|
|
248
|
-
element.removeEventListener("webkitAnimationEnd", animate_end_callback);
|
|
249
|
-
}
|
|
250
|
-
}, 0);
|
|
251
|
-
this._CurrentEndEventFunc = null;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (this._Progress === null) {
|
|
255
|
-
// 无进度跟进需求,直接结束
|
|
256
|
-
if (on_end) {
|
|
257
|
-
this.OnEnd();
|
|
258
|
-
}
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if ((this.enableFlags & Forge.AnimationEnable.AckRepeat) !== 0) {
|
|
263
|
-
Forge.sRenderBridge.UnregisterPerFrameCallback(this._TestRepeat);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
let progress = this._Progress.Stop();
|
|
267
|
-
if (on_end) {
|
|
268
|
-
// 修正可能产生的进度为0.999的异常数值
|
|
269
|
-
progress = 1;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// 根据进度状态,保持动画最后状态
|
|
273
|
-
if ((this.enableFlags & Forge.AnimationEnable.KeepTransform) !== 0) {
|
|
274
|
-
const frozen_transform = this._GetFrozenTransform(progress);
|
|
275
|
-
this._LayoutViewRef.ResetCssTransform(
|
|
276
|
-
frozen_transform.transform,
|
|
277
|
-
frozen_transform.transformOrigin);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// 注意: OnEnd处理放在transform制作之后
|
|
281
|
-
if (on_end) {
|
|
282
|
-
this.OnEnd();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// 进度信息要异步回调,模拟JsView native的场景
|
|
286
|
-
if ((this.enableFlags & Forge.AnimationEnable.AckFinalProgress) !== 0) {
|
|
287
|
-
window.setTimeout((() => {
|
|
288
|
-
this.OnFinalProgress(progress);
|
|
289
|
-
}), 0);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// 回收KeyFrame
|
|
293
|
-
if (this._KeyFrameNameToRecycle !== null) {
|
|
294
|
-
getStaticFrameControl().removeRule(this._KeyFrameNameToRecycle);
|
|
295
|
-
this._KeyFrameNameToRecycle = null;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
_TestRepeat() {
|
|
300
|
-
const progress_value = this._Progress.GetProgress();
|
|
301
|
-
if (this._LatestProgressValue > progress_value) {
|
|
302
|
-
this.OnRepeatEvent();
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
this._LatestProgressValue = progress_value;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// 由子类集成,创建动画对应的keyframe
|
|
309
|
-
_BuildStarterKeyFrame() {
|
|
310
|
-
// Should override
|
|
311
|
-
// 返回 {name:KeyFrame名称, keyFrameString:null 或者 keyFrame内容(不为null时,动画结束时会被自动从cssRules中清理)};
|
|
312
|
-
console.warn("Warning:Should override and return keyframe name");
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// 由子类集成,创建动画对应的keyframe
|
|
317
|
-
_BuildKeyFrame() {
|
|
318
|
-
// Should override
|
|
319
|
-
// 返回 {name:KeyFrame名称, keyFrameString:null 或者 keyFrame内容(不为null时,动画结束时会被自动从cssRules中清理)};
|
|
320
|
-
console.warn("Warning:Should override and return keyframe name");
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// 由子类集成,根据进度信息完成Keep Transform操作
|
|
324
|
-
_GetFrozenTransform(progress) {
|
|
325
|
-
// should override
|
|
326
|
-
console.warn("Warning:Should override and keep view transform by ResetCssTransform()");
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
Forge.TranslateAnimation = class extends Forge.KeyFrameAnimation {
|
|
331
|
-
constructor(start_x, end_x, start_y, end_y, duration, easing) {
|
|
332
|
-
super("TL", duration, easing);
|
|
333
|
-
|
|
334
|
-
this.startX = start_x;
|
|
335
|
-
this.startY = start_y;
|
|
336
|
-
this.endX = end_x;
|
|
337
|
-
this.endY = end_y;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Override
|
|
341
|
-
_BuildStarterKeyFrame() {
|
|
342
|
-
if (this.enableStartPos > 0) {
|
|
343
|
-
const start_x = (this.endX - this.startX) * this.enableStartPos + this.startX;
|
|
344
|
-
const start_y = (this.endY - this.startY) * this.enableStartPos + this.startY;
|
|
345
|
-
const keyframe_name = `_ForgeAnim_TL_${sKeyFrameTokenGenerator++}`;
|
|
346
|
-
const keyframe_string = `@keyframes ${keyframe_name} {`
|
|
347
|
-
+ `0%{transform:translate3d(${start_x}px,${start_y}px,0);}`
|
|
348
|
-
+ `100%{transform:translate3d(${this.endX}px,${this.endY}px,0);}}`;
|
|
349
|
-
return { name: keyframe_name, keyFrameString: keyframe_string };
|
|
350
|
-
}
|
|
351
|
-
console.error("Error: no enabled starter position");
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// Override
|
|
355
|
-
_BuildKeyFrame() {
|
|
356
|
-
const keyframe_name = `_ForgeAnim_TL_${sKeyFrameTokenGenerator++}`;
|
|
357
|
-
const keyframe_string = `@keyframes ${keyframe_name} {`
|
|
358
|
-
+ `0%{transform:translate3d(${this.startX}px,${this.startY}px,0);}`
|
|
359
|
-
+ `100%{transform:translate3d(${this.endX}px,${this.endY}px,0);}}`;
|
|
360
|
-
return { name: keyframe_name, keyFrameString: keyframe_string };
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// Override
|
|
364
|
-
_GetFrozenTransform(progress) {
|
|
365
|
-
const x = Math.floor((this.endX - this.startX) * progress + this.startX);
|
|
366
|
-
const y = Math.floor((this.endY - this.startY) * progress + this.startY);
|
|
367
|
-
const transform = `translate3d(${x}px,${y}px,0)`;
|
|
368
|
-
return { transform, transformOrigin: null };
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
Forge.FuncAnimation = class extends Forge.AnimationDelegate {
|
|
373
|
-
constructor(formula_string, duration, easing) {
|
|
374
|
-
super("FC2", duration, easing);
|
|
375
|
-
this.formula = formula_string;
|
|
376
|
-
console.warn("NO implemented");
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
Forge.RotateAnimation = class extends Forge.AnimationDelegate {
|
|
381
|
-
constructor(start_angle, offset_angle, anchor, axis, duration, easing) {
|
|
382
|
-
super("RO" /* [Ro]tate */, duration, easing);
|
|
383
|
-
|
|
384
|
-
if (!(anchor instanceof Forge.Vec3)) {
|
|
385
|
-
anchor = new Forge.Vec3(anchor);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
if (!(axis instanceof Forge.Vec3)) {
|
|
389
|
-
axis = new Forge.Vec3(axis);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
this.startAngle = start_angle;
|
|
393
|
-
this.offsetAngle = offset_angle;
|
|
394
|
-
this.anchorVec3 = anchor;
|
|
395
|
-
this.axisVec3 = axis;
|
|
396
|
-
console.warn("NO implemented");
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
Forge.BasicScaleAnimation = class extends Forge.AnimationDelegate {
|
|
401
|
-
constructor(from_width, from_height, target_width, target_height,
|
|
402
|
-
anchor_x_percent, anchor_y_percent,
|
|
403
|
-
duration, easing,
|
|
404
|
-
base_width, base_height) {
|
|
405
|
-
super("SC" /* [Sc]ale */, duration, easing);
|
|
406
|
-
console.warn("NO implemented");
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
Forge.ScaleAnimation = class extends Forge.BasicScaleAnimation {
|
|
411
|
-
constructor(start_scale, end_scale, anchor_x_percent, anchor_y_percent, duration, easing) {
|
|
412
|
-
const size = 200;
|
|
413
|
-
const from_width = start_scale * size;
|
|
414
|
-
const from_height = start_scale * size;
|
|
415
|
-
const target_width = end_scale * size;
|
|
416
|
-
const target_height = end_scale * size;
|
|
417
|
-
|
|
418
|
-
super(
|
|
419
|
-
from_width, from_height,
|
|
420
|
-
target_width, target_height,
|
|
421
|
-
anchor_x_percent, anchor_y_percent,
|
|
422
|
-
duration, easing,
|
|
423
|
-
200, 200
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
Forge.OpacityAnimation = class extends Forge.AnimationDelegate {
|
|
429
|
-
constructor(start_opacity, end_opacity, duration, easing) {
|
|
430
|
-
super("OP" /* [Op]acity */, duration, easing);
|
|
431
|
-
console.warn("NO implemented");
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
Forge.CssKeyframeAnimation = class extends Forge.KeyFrameAnimation {
|
|
436
|
-
constructor(keyframes_string, duration, easing, width, height) {
|
|
437
|
-
super("CK" /* [C]cs [K]eyframe */, duration, easing);
|
|
438
|
-
this._keyFramesSet = keyframes_string;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// Override
|
|
442
|
-
_BuildKeyFrame() {
|
|
443
|
-
// Keyframe配置,支持设置给LayoutView.Element(div)即可
|
|
444
|
-
const keyframes = this._keyFramesSet;
|
|
445
|
-
if (keyframes.indexOf("@keyframes") < 0 && keyframes.indexOf("@-webkit-keyframes") < 0) {
|
|
446
|
-
console.warn("Warning:keyframes array empty");
|
|
447
|
-
return null;
|
|
448
|
-
}
|
|
449
|
-
const keyframes_list = keyframes.split(" ");
|
|
450
|
-
let anim_name = keyframes_list[1];
|
|
451
|
-
if (anim_name.indexOf("{") >= 0) {
|
|
452
|
-
anim_name = anim_name.substr(0, anim_name.indexOf("{"));
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return { name: anim_name, keyFrameString: null };
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
_GetLastKeyframeTransform(keyframe) {
|
|
459
|
-
let startIndex = keyframe.indexOf("to");
|
|
460
|
-
if (startIndex < 0) {
|
|
461
|
-
startIndex = keyframe.indexOf("100%");
|
|
462
|
-
}
|
|
463
|
-
if (startIndex < 0) {
|
|
464
|
-
return ""
|
|
465
|
-
} else {
|
|
466
|
-
let transformIndex = keyframe.indexOf("transform:", startIndex);
|
|
467
|
-
if (transformIndex < 0) {
|
|
468
|
-
return ""
|
|
469
|
-
} else {
|
|
470
|
-
return keyframe.substring(transformIndex + 10, keyframe.indexOf(";", transformIndex));
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
_GetFrozenTransform(progress) {
|
|
476
|
-
let result = {
|
|
477
|
-
transform: "",
|
|
478
|
-
transformOrigin: null,
|
|
479
|
-
}
|
|
480
|
-
if (progress === 1) {
|
|
481
|
-
result = {
|
|
482
|
-
transform: this._GetLastKeyframeTransform(this._keyFramesSet),
|
|
483
|
-
transformOrigin: null,
|
|
484
|
-
}
|
|
485
|
-
} else {
|
|
486
|
-
console.warn("CssKeyframeAnimation can not get transform whill progress is not 1");
|
|
487
|
-
}
|
|
488
|
-
return result;
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
Forge.CssTransitionAnimation = class extends Forge.AnimationDelegate {
|
|
493
|
-
constructor(transition_array) {
|
|
494
|
-
super("CT" /* [C]cs [K]eyframe */, null, null);
|
|
495
|
-
this._transArray = transition_array;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
Start(layout_view) {
|
|
499
|
-
super.Start(layout_view);
|
|
500
|
-
|
|
501
|
-
const that = this;
|
|
502
|
-
const transitions = this._transArray;
|
|
503
|
-
const transition_map = {};
|
|
504
|
-
|
|
505
|
-
if (transitions.length === 0) {
|
|
506
|
-
console.warn("Warning:transition empty");
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
let transition_str = "";
|
|
511
|
-
for (let i = 0; i < transitions.length; i++) {
|
|
512
|
-
let timing_function = "linear";
|
|
513
|
-
const transition = transitions[i];
|
|
514
|
-
if (transition.tf) {
|
|
515
|
-
timing_function = convertTimingFunc(transition.tf);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
transition_str = `${transition.name} ${transition.dur / 1000}s ${
|
|
519
|
-
timing_function} ${
|
|
520
|
-
transition.dly / 1000}s`;
|
|
521
|
-
transition_map[transition.name] = transition_str;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
layout_view.ApplyStyleTransition(transition_map);
|
|
525
|
-
|
|
526
|
-
if (transition_str) {
|
|
527
|
-
// 注意:仅最后一个Transition动画的AnimationEnd时间被监听
|
|
528
|
-
layout_view.Element.addEventListener("transitionend", (event) => {
|
|
529
|
-
event.stopPropagation();
|
|
530
|
-
that.OnEnd(true);
|
|
531
|
-
});
|
|
532
|
-
layout_view.Element.addEventListener("webkitTransitionEnd", (event) => {
|
|
533
|
-
event.stopPropagation();
|
|
534
|
-
that.OnEnd(true);
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
Forge.KeyFrameGroupAnimation = class extends Forge.AnimationDelegate {
|
|
541
|
-
constructor(type) {
|
|
542
|
-
super(type, 0, null);
|
|
543
|
-
|
|
544
|
-
this._KeyFrameArray = null;
|
|
545
|
-
this._LatestProgressValue = 0;
|
|
546
|
-
this._CurrentEndEventFunc = null;
|
|
547
|
-
this._Progress = null;
|
|
548
|
-
this._AnimRunList = null;
|
|
549
|
-
this._AnimationRunIndex = 0;
|
|
550
|
-
|
|
551
|
-
const that = this;
|
|
552
|
-
this._OnEndEvent = (event) => {
|
|
553
|
-
event.stopPropagation();
|
|
554
|
-
if (this._TestFinalKeyFrame(event)) {
|
|
555
|
-
that._PerformAnimationEnd(true);
|
|
556
|
-
} else {
|
|
557
|
-
// 切换到下一个animation
|
|
558
|
-
this._AnimationRunIndex++;
|
|
559
|
-
this._LayoutViewRef.Element.style.animation = this._AnimRunList[this._AnimationRunIndex];
|
|
560
|
-
this._Progress.TriggerNextStep(this._AnimationRunIndex);
|
|
561
|
-
|
|
562
|
-
that._OnSubKeyFrameDone(event);
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
Start(layout_view) {
|
|
568
|
-
super.Start(layout_view);
|
|
569
|
-
// Keyframe动画启动时,清理transform,以保证动画行为正确
|
|
570
|
-
layout_view.ResetCssTransform(null, null);
|
|
571
|
-
if (layout_view.Element) {
|
|
572
|
-
layout_view.Element.style.pointerEvents = "auto";
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
this._EnableCssAnimation(this._BuildKeyFrameGroup(), this._OnEndEvent);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
Cancel() {
|
|
579
|
-
super.Cancel();
|
|
580
|
-
this._PerformAnimationEnd(false);
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
_EnableCssAnimation(animation_array, on_end_func) {
|
|
584
|
-
if (animation_array === null) return;
|
|
585
|
-
this._KeyFrameArray = new Array(animation_array.length);
|
|
586
|
-
const frame_control = getStaticFrameControl();
|
|
587
|
-
for (let i = 0; i < animation_array.length; i++) {
|
|
588
|
-
const animation = animation_array[i];
|
|
589
|
-
// 检查css animation transform格式
|
|
590
|
-
this.CheckCssAnimationFormat(animation.name);
|
|
591
|
-
|
|
592
|
-
this._KeyFrameArray[i] = {
|
|
593
|
-
name: animation.name,
|
|
594
|
-
easing: animation.ease.Package(),
|
|
595
|
-
duration: animation.duration,
|
|
596
|
-
needRecycle: false
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
// KeyFrame在此创建,也被此类回收
|
|
600
|
-
if (animation.keyFrameString !== null) {
|
|
601
|
-
frame_control.insertRule(animation.keyFrameString);
|
|
602
|
-
this._KeyFrameArray.needRecycle = true;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
const html_element = this._LayoutViewRef.Element;
|
|
607
|
-
|
|
608
|
-
// 创建Progress跟踪器
|
|
609
|
-
if ((this.enableFlags & Forge.AnimationEnable.AckFinalProgress) !== 0
|
|
610
|
-
|| (this.enableFlags & Forge.AnimationEnable.KeepTransform) !== 0) {
|
|
611
|
-
this._Progress = new AnimationGroupProgress(this._LayoutViewRef, this._KeyFrameArray.length);
|
|
612
|
-
this._Progress.Start(this._KeyFrameArray);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
this._AnimRunList = this._ConvertToAnimationStyle(this._KeyFrameArray);
|
|
616
|
-
this._AnimationRunIndex = 0;
|
|
617
|
-
|
|
618
|
-
// name duration timing-function delay iteration-count direction;
|
|
619
|
-
if (!window.jsvInAndroidWebView) {
|
|
620
|
-
html_element.style.animation = this._AnimRunList[0];
|
|
621
|
-
html_element.addEventListener("animationend", on_end_func);
|
|
622
|
-
|
|
623
|
-
} else {
|
|
624
|
-
html_element.style.webkitAnimation = this._AnimRunList[0];
|
|
625
|
-
html_element.addEventListener("webkitAnimationEnd", on_end_func);
|
|
626
|
-
}
|
|
627
|
-
this._CurrentEndEventFunc = on_end_func;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
_PerformAnimationEnd(on_end) {
|
|
631
|
-
// 清理OnEndListener监听,否则会重复收到
|
|
632
|
-
if (this._CurrentEndEventFunc !== null) {
|
|
633
|
-
const element = this._LayoutViewRef.Element;
|
|
634
|
-
const animate_end_callback = this._CurrentEndEventFunc;
|
|
635
|
-
// 异步进行removeEventListener处理,以解决event.stopPropagation不生效的问题
|
|
636
|
-
setTimeout(() => {
|
|
637
|
-
if (!window.jsvInAndroidWebView) {
|
|
638
|
-
element.removeEventListener("animationend", animate_end_callback);
|
|
639
|
-
} else {
|
|
640
|
-
element.removeEventListener("webkitAnimationEnd", animate_end_callback);
|
|
641
|
-
}
|
|
642
|
-
}, 0);
|
|
643
|
-
this._CurrentEndEventFunc = null;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
if (this._Progress === null) {
|
|
647
|
-
// 无进度跟进需求,直接结束
|
|
648
|
-
if (on_end) {
|
|
649
|
-
this.OnEnd();
|
|
650
|
-
}
|
|
651
|
-
return;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
let progress = this._Progress.Stop();
|
|
655
|
-
if (on_end) {
|
|
656
|
-
// 修正可能产生的进度为0.999的异常数值
|
|
657
|
-
progress = 1;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// 根据进度状态,保持动画最后状态
|
|
661
|
-
if ((this.enableFlags & Forge.AnimationEnable.KeepTransform) !== 0) {
|
|
662
|
-
const frozen_transform = this._GetFrozenTransform(progress);
|
|
663
|
-
this._LayoutViewRef.ResetCssTransform(
|
|
664
|
-
frozen_transform.transform,
|
|
665
|
-
frozen_transform.transformOrigin);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// 注意: OnEnd处理放在transform制作之后
|
|
669
|
-
if (on_end) {
|
|
670
|
-
this.OnEnd();
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
// 进度信息要异步回调,模拟JsView native的场景
|
|
674
|
-
if ((this.enableFlags & Forge.AnimationEnable.AckFinalProgress) !== 0) {
|
|
675
|
-
window.setTimeout((() => {
|
|
676
|
-
this.OnFinalProgress(progress);
|
|
677
|
-
}), 0);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
// 回收KeyFrame
|
|
681
|
-
const frame_control = getStaticFrameControl();
|
|
682
|
-
for (const key_frame of this._KeyFrameArray) {
|
|
683
|
-
if (key_frame.needRecycle) {
|
|
684
|
-
frame_control.removeRule(key_frame.name);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
this._KeyFrameArray = null;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
_ConvertToAnimationStyle(steps_settings) {
|
|
691
|
-
const style_animation_list = [];
|
|
692
|
-
for (let i = 0; i < steps_settings.length; i++) {
|
|
693
|
-
let timing_func = "linear";
|
|
694
|
-
const settings = steps_settings[i];
|
|
695
|
-
if (settings.easing) {
|
|
696
|
-
timing_func = convertTimingFunc(settings.easing);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
// const delay_start = (i !== 0 ? steps_settings[i - 1].duration : 0);
|
|
700
|
-
|
|
701
|
-
style_animation_list.push(`${settings.name} ${settings.duration / 1000}s ${timing_func}`);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
return style_animation_list;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
// 由子类复写,创建动画对应的keyframe
|
|
708
|
-
_BuildKeyFrameGroup() {
|
|
709
|
-
// Should override
|
|
710
|
-
// 返回 数组,每个元素内容为:
|
|
711
|
-
// {
|
|
712
|
-
// name:KeyFrame名称,
|
|
713
|
-
// keyFrameString:null 或者 keyFrame内容(不为null时,动画结束时会被自动从cssRules中清理)
|
|
714
|
-
// ease:xxx, 当前步骤的easing
|
|
715
|
-
// duration:xxx, 当前步骤的duration
|
|
716
|
-
// };
|
|
717
|
-
console.warn("Warning:Should override and return keyframe name");
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
// 由子类复写,根据进度信息完成Keep Transform操作
|
|
721
|
-
_GetFrozenTransform(progress) {
|
|
722
|
-
// should override
|
|
723
|
-
console.warn("Warning:Should override and keep view transform by ResetCssTransform()");
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// 由子类复写,进行检测这个animation end event是否是最后一个KeyFrame发起的
|
|
727
|
-
_TestFinalKeyFrame(event) {
|
|
728
|
-
// should override
|
|
729
|
-
console.warn("Warning:Should override");
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
// 由子类复写,进行检测这个animation end event是否是最后一个KeyFrame发起的
|
|
733
|
-
_OnSubKeyFrameDone(event) {
|
|
734
|
-
// should override
|
|
735
|
-
console.warn("Warning:Should override");
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
|
|
739
|
-
Forge.TranslateFrameAnimation = class extends Forge.TranslateAnimation {
|
|
740
|
-
constructor(start_pos, target_pos, speed, affect_x, origin_x, origin_y) {
|
|
741
|
-
// 在浏览器场合,使用匀速的Translate动画模拟TranslateFrame动画
|
|
742
|
-
let start_x = origin_x;
|
|
743
|
-
let start_y = origin_y;
|
|
744
|
-
let end_x = origin_x;
|
|
745
|
-
let end_y = origin_y;
|
|
746
|
-
|
|
747
|
-
if (affect_x) {
|
|
748
|
-
start_x = start_pos;
|
|
749
|
-
end_x = target_pos;
|
|
750
|
-
} else {
|
|
751
|
-
start_y = start_pos;
|
|
752
|
-
end_y = target_pos;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
const duration = Math.abs(Math.floor((target_pos - start_pos) / speed * 1000));
|
|
756
|
-
|
|
757
|
-
super(start_x, end_x, start_y, end_y, duration, null);
|
|
758
|
-
}
|
|
759
|
-
};
|
|
760
|
-
|
|
761
|
-
Forge.ThrowAnimation = class extends Forge.KeyFrameGroupAnimation {
|
|
762
|
-
constructor(from_x, from_y, x_or_y, init_v, acc, to, has_pole, pole_position) {
|
|
763
|
-
super("Thr"); // "Thr"ow
|
|
764
|
-
|
|
765
|
-
this._FromX = from_x;
|
|
766
|
-
this._FromY = from_y;
|
|
767
|
-
this._XorY = x_or_y;
|
|
768
|
-
this._InitV = init_v;
|
|
769
|
-
this._Acc = acc;
|
|
770
|
-
this._To = to;
|
|
771
|
-
this._HasPole = has_pole;
|
|
772
|
-
this._PoleCallback = null;
|
|
773
|
-
this._PolePosition = pole_position;
|
|
774
|
-
this._IsPositiveMove = (this._InitV > 0 || (this._InitV === 0 && this._Acc > 0)); // 是否朝正方向运动
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
SetPoleCallback(callback) {
|
|
778
|
-
this._PoleCallback = callback;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
_MakeTranslateString(keyframe_name, from, to) {
|
|
782
|
-
return `@keyframes ${keyframe_name} {`
|
|
783
|
-
+ `0%{transform:translate3d(${from.x.value}px,${from.y.value}px,0);}`
|
|
784
|
-
+ `100%{transform:translate3d(${to.x.value}px,${to.y.value}px,0);}}`;
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
_BuildKeyFrameGroup() {
|
|
788
|
-
const name_token = `${sKeyFrameTokenGenerator++}`;
|
|
789
|
-
|
|
790
|
-
// {
|
|
791
|
-
// name:KeyFrame名称,
|
|
792
|
-
// keyFrameString:null 或者 keyFrame内容(不为null时,动画结束时会被自动从cssRules中清理)
|
|
793
|
-
// ease:xxx, 当前步骤的easing
|
|
794
|
-
// duration:xxx, 当前步骤的duration
|
|
795
|
-
// };
|
|
796
|
-
const keyframe_array = [];
|
|
797
|
-
|
|
798
|
-
const start_vec2 = { x: { value: this._FromX }, y: { value: this._FromY } };
|
|
799
|
-
const end_vec2 = { x: { value: this._FromX }, y: { value: this._FromY } };
|
|
800
|
-
|
|
801
|
-
const start_ref = (this._XorY === 0 ? start_vec2.x : start_vec2.y);
|
|
802
|
-
const end_ref = (this._XorY === 0 ? end_vec2.x : end_vec2.y);
|
|
803
|
-
if (this._HasPole) {
|
|
804
|
-
// 有拐点时
|
|
805
|
-
|
|
806
|
-
// 运动处理,先从起始位置,到拐点
|
|
807
|
-
let keyframe_name = `_ForgeAnim_Thr_Forw_${name_token}`;
|
|
808
|
-
end_ref.value = this._PolePosition;
|
|
809
|
-
let keyframe_string = this._MakeTranslateString(keyframe_name, start_vec2, end_vec2);
|
|
810
|
-
keyframe_array.push({
|
|
811
|
-
name: keyframe_name,
|
|
812
|
-
keyFrameString: keyframe_string,
|
|
813
|
-
ease: Forge.Easing.Circular.Out, // 减速运动
|
|
814
|
-
duration: Math.floor(-(this._InitV / this._Acc) * 1000) // 单位毫秒
|
|
815
|
-
});
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
// 运动处理,再从拐点到最终点
|
|
819
|
-
keyframe_name = `_ForgeAnim_Thr_Backw_${name_token}`;
|
|
820
|
-
start_ref.value = this._PolePosition;
|
|
821
|
-
end_ref.value = this._To;
|
|
822
|
-
keyframe_string = this._MakeTranslateString(keyframe_name, start_vec2, end_vec2);
|
|
823
|
-
keyframe_array.push({
|
|
824
|
-
name: keyframe_name,
|
|
825
|
-
keyFrameString: keyframe_string,
|
|
826
|
-
ease: Forge.Easing.Circular.In, // 加速运动
|
|
827
|
-
duration: Math.floor(
|
|
828
|
-
Math.sqrt(2 * (this._To - this._PolePosition) / this._Acc) * 1000), // 单位毫秒
|
|
829
|
-
});
|
|
830
|
-
} else {
|
|
831
|
-
// 无拐点时
|
|
832
|
-
const keyframe_name = `_ForgeAnim_Thr_Forw_${name_token}`;
|
|
833
|
-
end_ref.value = this._To;
|
|
834
|
-
const keyframe_string = this._MakeTranslateString(keyframe_name, start_vec2, end_vec2);
|
|
835
|
-
|
|
836
|
-
// 转换坐标系,使运动始终向正方向以简化计算处理
|
|
837
|
-
const init_v = (this._IsPositiveMove ? this._InitV : -this._InitV);
|
|
838
|
-
const acc = (this._IsPositiveMove ? this._Acc : -this._Acc);
|
|
839
|
-
const distance = (this._IsPositiveMove ? (end_ref.value - start_ref.value) : (start_ref.value - end_ref.value));
|
|
840
|
-
|
|
841
|
-
keyframe_array.push({
|
|
842
|
-
name: keyframe_name,
|
|
843
|
-
keyFrameString: keyframe_string,
|
|
844
|
-
ease: (acc > 0 ? Forge.Easing.Circular.In : Forge.Easing.Circular.Out), // 根据加速度方向决定是加速运动还是减速运动
|
|
845
|
-
duration: Math.floor((Math.sqrt(init_v * init_v + 2 * acc * distance) - init_v) / acc * 1000)
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
return keyframe_array;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
// 由子类集成,根据进度信息完成Keep Transform操作
|
|
853
|
-
_GetFrozenTransform(progress) {
|
|
854
|
-
const position = { x: { value: this._FromX }, y: { value: this._FromY } };
|
|
855
|
-
let from = (this._XorY === 0 ? position.x.value : position.y.value);
|
|
856
|
-
const result_position_ref = (this._XorY === 0 ? position.x : position.y);
|
|
857
|
-
let result_pos_value = 0;
|
|
858
|
-
|
|
859
|
-
// 转换坐标系,使运动始终向正方向以简化计算处理
|
|
860
|
-
from = (this._IsPositiveMove ? from : -from);
|
|
861
|
-
const to = (this._IsPositiveMove ? this._To : -this._To);
|
|
862
|
-
const pole_position = (this._IsPositiveMove ? this._PolePosition : -this._PolePosition);
|
|
863
|
-
|
|
864
|
-
if (this._HasPole) {
|
|
865
|
-
const moved = (pole_position * 2 - from - to) * progress;
|
|
866
|
-
if (moved > (pole_position - from)) {
|
|
867
|
-
// 运动了超过了拐点的距离
|
|
868
|
-
result_pos_value = pole_position - (moved - (pole_position - from));
|
|
869
|
-
} else {
|
|
870
|
-
// 未到达拐点
|
|
871
|
-
result_pos_value = from + moved;
|
|
872
|
-
}
|
|
873
|
-
} else {
|
|
874
|
-
result_pos_value = from + (to - from) * progress;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
// 恢复坐标系
|
|
878
|
-
result_position_ref.value = Math.floor(this._IsPositiveMove ? result_pos_value : -result_pos_value);
|
|
879
|
-
|
|
880
|
-
const transform = `translate3d(${position.x.value}px,${position.y.value}px,0)`;
|
|
881
|
-
return { transform, transformOrigin: null };
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
// 由子类集成,进行检测这个animation end event是否是最后一个KeyFrame发起的
|
|
885
|
-
_TestFinalKeyFrame(event) {
|
|
886
|
-
if (this._HasPole) {
|
|
887
|
-
return (event.animationName.indexOf("_ForgeAnim_Thr_Backw_") >= 0);
|
|
888
|
-
}
|
|
889
|
-
return (event.animationName.indexOf("_ForgeAnim_Thr_Forw_") >= 0);
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
_OnSubKeyFrameDone(event) {
|
|
893
|
-
if (this._HasPole && this._PoleCallback) {
|
|
894
|
-
// 第一个动画结束,到达拐点,回报拐点事件
|
|
895
|
-
this._PoleCallback();
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
|
|
900
|
-
// enum
|
|
901
|
-
Forge.AnimationEnable = {
|
|
902
|
-
ReleaseAfterEndCallback: 1, // 0000 0000 0001
|
|
903
|
-
KeepTransform: 2, // 0000 0000 0010
|
|
904
|
-
AckFinalProgress: 4, // 0000 0000 0000 0100
|
|
905
|
-
AckRepeat: 8, // 0000 0000 0000 1000
|
|
906
|
-
};
|