1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
/*
* Copyright (C) 2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
WI.Animation = class Animation extends WI.Object
{
constructor(animationId, {name, cssAnimationName, cssTransitionProperty, stackTrace} = {})
{
super();
console.assert(animationId);
console.assert((!cssAnimationName && !cssTransitionProperty) || !!cssAnimationName !== !!cssTransitionProperty);
console.assert(!stackTrace || stackTrace instanceof WI.StackTrace, stackTrace);
this._animationId = animationId;
this._name = name || null;
this._cssAnimationName = cssAnimationName || null;
this._cssTransitionProperty = cssTransitionProperty || null;
this._stackTrace = stackTrace || null;
this._effect = null;
this._ensureEffectCallbacks = null;
this._effectTarget = undefined;
this._requestEffectTargetCallbacks = null;
}
// Static
static fromPayload(payload)
{
// COMPATIBILITY (macOS 13.0, iOS 16.0): `backtrace` was renamed to `stackTrace`.
if (payload.backtrace)
payload.stackTrace = {callFrames: payload.backtrace};
let animation = new WI.Animation(payload.animationId, {
name: payload.name,
cssAnimationName: payload.cssAnimationName,
cssTransitionProperty: payload.cssTransitionProperty,
stackTrace: WI.StackTrace.fromPayload(WI.assumingMainTarget(), payload.stackTrace),
});
// COMPATIBILITY (iOS 18.X, macOS 15.X): `Animation` removed the `effect` property in favor of `Animation.requestEffect`.
if (payload.effect)
animation.effectChanged(payload.effect);
return animation;
}
static displayNameForAnimationType(animationType, plural)
{
switch (animationType) {
case WI.Animation.Type.WebAnimation:
return plural ? WI.UIString("Web Animations") : WI.UIString("Web Animation");
case WI.Animation.Type.CSSAnimation:
return plural ? WI.UIString("CSS Animations") : WI.UIString("CSS Animation");
case WI.Animation.Type.CSSTransition:
return plural ? WI.UIString("CSS Transitions") : WI.UIString("CSS Transition");
}
console.assert(false, "Unknown animation type", animationType);
return null;
}
static displayNameForPlaybackDirection(playbackDirection)
{
switch (playbackDirection) {
case WI.Animation.PlaybackDirection.Normal:
return WI.UIString("Normal", "Web Animation Playback Direction Normal", "Indicates that the playback direction of this web animation is normal (e.g. forwards)");
case WI.Animation.PlaybackDirection.Reverse:
return WI.UIString("Reverse", "Web Animation Playback Direction Reverse", "Indicates that the playback direction of this web animation is reversed (e.g. backwards)");
case WI.Animation.PlaybackDirection.Alternate:
return WI.UIString("Alternate", "Web Animation Playback Direction Alternate", "Indicates that the playback direction of this web animation alternates between normal and reversed on each iteration");
case WI.Animation.PlaybackDirection.AlternateReverse:
return WI.UIString("Alternate Reverse", "Web Animation Playback Direction Alternate Reverse", "Indicates that the playback direction of this web animation alternates between reversed and normal on each iteration");
}
console.assert(false, "Unknown playback direction", playbackDirection);
return null;
}
static displayNameForFillMode(fillMode)
{
switch (fillMode) {
case WI.Animation.FillMode.None:
return WI.UIString("None", "Web Animation Fill Mode None", "Indicates that this web animation does not apply any styles before it begins and after it ends");
case WI.Animation.FillMode.Forwards:
return WI.UIString("Forwards", "Web Animation Fill Mode Forwards", "Indicates that this web animation also applies styles after it ends");
case WI.Animation.FillMode.Backwards:
return WI.UIString("Backwards", "Web Animation Fill Mode Backwards", "Indicates that this web animation also applies styles before it begins");
case WI.Animation.FillMode.Both:
return WI.UIString("Both", "Web Animation Fill Mode Both", "Indicates that this web animation also applies styles before it begins and after it ends");
case WI.Animation.FillMode.Auto:
return WI.UIString("Auto", "Web Animation Fill Mode Auto", "Indicates that this web animation either does not apply any styles before it begins and after it ends or that it applies to both, depending on it's configuration");
}
console.assert(false, "Unknown fill mode", fillMode);
return null;
}
static resetUniqueDisplayNameNumbers()
{
WI.Animation._nextUniqueDisplayNameNumber = 1;
}
// Public
get animationId() { return this._animationId; }
get name() { return this._name; }
get cssAnimationName() { return this._cssAnimationName; }
get cssTransitionProperty() { return this._cssTransitionProperty; }
get stackTrace() { return this._stackTrace; }
get animationType()
{
if (this._cssAnimationName)
return WI.Animation.Type.CSSAnimation;
if (this._cssTransitionProperty)
return WI.Animation.Type.CSSTransition;
return WI.Animation.Type.WebAnimation;
}
get startDelay()
{
return (this._effect && "startDelay" in this._effect) ? this._effect.startDelay : NaN;
}
get endDelay()
{
return (this._effect && "endDelay" in this._effect) ? this._effect.endDelay : NaN;
}
get iterationCount()
{
return (this._effect && "iterationCount" in this._effect) ? this._effect.iterationCount : NaN;
}
get iterationStart()
{
return (this._effect && "iterationStart" in this._effect) ? this._effect.iterationStart : NaN;
}
get iterationDuration()
{
return (this._effect && "iterationDuration" in this._effect) ? this._effect.iterationDuration : NaN;
}
get timingFunction()
{
return (this._effect && "timingFunction" in this._effect) ? this._effect.timingFunction : null;
}
get playbackDirection()
{
return (this._effect && "playbackDirection" in this._effect) ? this._effect.playbackDirection : null;
}
get fillMode()
{
return (this._effect && "fillMode" in this._effect) ? this._effect.fillMode : null;
}
get keyframes()
{
return (this._effect && "keyframes" in this._effect) ? this._effect.keyframes : [];
}
get displayName()
{
if (this._name)
return this._name;
if (this._cssAnimationName)
return this._cssAnimationName;
if (this._cssTransitionProperty)
return this._cssTransitionProperty;
if (!this._uniqueDisplayNameNumber)
this._uniqueDisplayNameNumber = WI.Animation._nextUniqueDisplayNameNumber++;
return WI.UIString("Animation %d").format(this._uniqueDisplayNameNumber);
}
ensureEffect(callback)
{
if (this._effect) {
if (callback) {
callback();
return;
}
return Promise.resolve();
}
let promise = undefined;
if (!callback) {
promise = new Promise((resolve, reject) => {
callback = resolve;
});
}
if (this._ensureEffectCallbacks) {
this._ensureEffectCallbacks.push(callback);
return promise;
}
this._ensureEffectCallbacks = [callback];
let target = WI.assumingMainTarget();
target.AnimationAgent.requestEffect(this._animationId, (error, effect) => {
if (error) {
WI.reportInternalError(error);
return;
}
this._updateEffect(effect);
});
return promise;
}
requestEffectTarget(callback)
{
if (this._effectTarget !== undefined) {
callback(this._effectTarget);
return;
}
if (this._requestEffectTargetCallbacks) {
this._requestEffectTargetCallbacks.push(callback);
return;
}
this._requestEffectTargetCallbacks = [callback];
WI.domManager.ensureDocument();
let target = WI.assumingMainTarget();
target.AnimationAgent.requestEffectTarget(this._animationId, (error, effectTarget) => {
// COMPATIBILITY (iOS 15.4): nodeId was renamed to effectTarget and changed from DOM.NodeId to DOM.Styleable.
if (!isNaN(effectTarget))
effectTarget = {nodeId: effectTarget};
this._effectTarget = !error ? WI.DOMStyleable.fromPayload(effectTarget) : null;
for (let requestEffectTargetCallback of this._requestEffectTargetCallbacks)
requestEffectTargetCallback(this._effectTarget);
this._requestEffectTargetCallbacks = null;
});
}
// AnimationManager
nameChanged(name)
{
this._name = name || null;
this.dispatchEventToListeners(WI.Animation.Event.NameChanged);
}
effectChanged(effect)
{
this._effect = null;
// COMPATIBILITY (iOS 18.X, macOS 15.X): `Animation.effectChanged` removed the `effect` parameter in favor of `Animation.requestEffect`.
if (!InspectorBackend.hasCommand("Animation.requestEffect"))
this._updateEffect(effect);
this.dispatchEventToListeners(WI.Animation.Event.EffectChanged);
}
targetChanged()
{
this._effectTarget = undefined;
this.dispatchEventToListeners(WI.Animation.Event.TargetChanged);
}
// Private
_updateEffect(effect)
{
this._effect = effect || {};
if ("iterationCount" in this._effect) {
if (this._effect.iterationCount === -1)
this._effect.iterationCount = Infinity;
else if (this._effect.iterationCount === null) {
// COMPATIBILITY (iOS 14): an iteration count of `Infinity` was not properly handled.
this._effect.iterationCount = Infinity;
}
}
if ("timingFunction" in this._effect) {
let timingFunction = this._effect.timingFunction;
this._effect.timingFunction = WI.CubicBezierTimingFunction.fromString(timingFunction) || WI.LinearTimingFunction.fromString(timingFunction) || WI.StepsTimingFunction.fromString(timingFunction) || WI.SpringTimingFunction.fromString(timingFunction);
console.assert(this._effect.timingFunction, timingFunction);
}
if ("keyframes" in this._effect) {
for (let keyframe of this._effect.keyframes) {
if (keyframe.easing) {
let easing = keyframe.easing;
keyframe.easing = WI.CubicBezierTimingFunction.fromString(easing) || WI.LinearTimingFunction.fromString(easing) || WI.StepsTimingFunction.fromString(easing) || WI.SpringTimingFunction.fromString(easing);
console.assert(keyframe.easing, easing);
}
if (keyframe.style)
keyframe.style = keyframe.style.replaceAll(/;\s+/g, ";\n");
}
}
if (this._ensureEffectCallbacks) {
for (let requestEffectCallback of this._ensureEffectCallbacks)
requestEffectCallback();
this._ensureEffectCallbacks = null;
}
}
};
WI.Animation._nextUniqueDisplayNameNumber = 1;
WI.Animation.Type = {
WebAnimation: "web-animation",
CSSAnimation: "css-animation",
CSSTransition: "css-transition",
};
WI.Animation.PlaybackDirection = {
Normal: "normal",
Reverse: "reverse",
Alternate: "alternate",
AlternateReverse: "alternate-reverse",
};
WI.Animation.FillMode = {
None: "none",
Forwards: "forwards",
Backwards: "backwards",
Both: "both",
Auto: "auto",
};
WI.Animation.Event = {
NameChanged: "animation-name-changed",
EffectChanged: "animation-effect-changed",
TargetChanged: "animation-target-changed",
};
|