@teamturing/react-kit 2.4.0 → 2.6.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.
- package/dist/core/Button/index.d.ts +1 -1
- package/dist/core/Dialog/index.d.ts +16 -0
- package/dist/core/DialogHandler/index.d.ts +13 -0
- package/dist/core/GradientText/index.d.ts +11 -12
- package/dist/core/Grid/index.d.ts +2 -2
- package/dist/core/IconButton/index.d.ts +1 -1
- package/dist/core/ItemList/index.d.ts +2 -2
- package/dist/core/MotionView/index.d.ts +3 -0
- package/dist/core/Spinner/index.d.ts +116 -116
- package/dist/core/Stack/index.d.ts +2 -2
- package/dist/core/TextInput/index.d.ts +39 -0
- package/dist/core/Textarea/index.d.ts +9 -0
- package/dist/hook/useDialogHandler.d.ts +6 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10732 -593
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/isFunction.d.ts +1 -0
- package/esm/_virtual/index.js +3 -0
- package/esm/_virtual/react-is.development.js +3 -0
- package/esm/_virtual/react-is.production.min.js +3 -0
- package/esm/core/Dialog/index.js +188 -0
- package/esm/core/DialogHandler/index.js +33 -0
- package/esm/core/MotionView/index.js +6 -0
- package/esm/core/TextInput/index.js +220 -0
- package/esm/core/Textarea/index.js +158 -0
- package/esm/hook/useDialogHandler.js +14 -0
- package/esm/index.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/instant.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/js/driver-frameloop.js +16 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/js/index.js +303 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/create-accelerated-animation.js +199 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/easing.js +31 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/index.js +23 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/utils/get-final-keyframe.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/inertia.js +87 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/keyframes.js +51 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/spring/find.js +89 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/spring/index.js +129 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/utils/calc-duration.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/utils/velocity.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/motion-value.js +101 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/single-value.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/visual-element-target.js +71 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/visual-element-variant.js +63 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/visual-element.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/animation/optimized-appear/data-id.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/default-transitions.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-animatable.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-animation-controls.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-keyframes-target.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-none.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/keyframes.js +45 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/transitions.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/PopChild.js +71 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/PresenceChild.js +56 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/index.js +158 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/use-presence.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/context/LayoutGroupContext.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/context/LazyContext.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionConfigContext.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionContext/create.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionContext/index.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionContext/utils.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/context/PresenceContext.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/context/SwitchLayoutGroupContext.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/debug/record.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/easing/anticipate.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/back.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/easing/circ.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/easing/cubic-bezier.js +51 -0
- package/esm/node_modules/framer-motion/dist/es/easing/ease.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/easing/modifiers/mirror.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/modifiers/reverse.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/utils/is-bezier-definition.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/easing/utils/is-easing-array.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/utils/map.js +37 -0
- package/esm/node_modules/framer-motion/dist/es/events/add-dom-event.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/events/add-pointer-event.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/events/event-info.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/events/utils/is-primary-pointer.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/frameloop/batcher.js +60 -0
- package/esm/node_modules/framer-motion/dist/es/frameloop/frame.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/frameloop/render-step.js +104 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/VisualElementDragControls.js +457 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/index.js +27 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/utils/constraints.js +125 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/utils/lock.js +53 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/focus.js +41 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/hover.js +32 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/pan/PanSession.js +148 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/pan/index.js +46 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/press.js +120 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/utils/is-node-or-child.js +20 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/Feature.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/animation/exit.js +31 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/animation/index.js +38 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/animations.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/definitions.js +28 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/drag.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/gestures.js +21 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/layout/MeasureLayout.js +131 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/layout.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/load-features.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/viewport/index.js +72 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/viewport/observers.js +49 -0
- package/esm/node_modules/framer-motion/dist/es/motion/index.js +79 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/is-forced-motion-value.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/symbol.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/use-motion-ref.js +33 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/use-visual-element.js +75 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/use-visual-state.js +81 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/valid-prop.js +59 -0
- package/esm/node_modules/framer-motion/dist/es/projection/animation/mix-values.js +93 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/conversion.js +33 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/copy.js +20 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/delta-apply.js +122 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/delta-calc.js +41 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/delta-remove.js +54 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/models.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/utils.js +25 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/DocumentProjectionNode.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/HTMLProjectionNode.js +27 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/create-projection-node.js +1494 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/state.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/projection/shared/stack.js +112 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/scale-border-radius.js +41 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/scale-box-shadow.js +35 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/scale-correction.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/transform.js +42 -0
- package/esm/node_modules/framer-motion/dist/es/projection/utils/each-axis.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/projection/utils/has-transform.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/projection/utils/measure.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/render/VisualElement.js +507 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/DOMVisualElement.js +48 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/create-visual-element.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/motion-proxy.js +47 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/motion.js +23 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/use-render.js +35 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/camel-to-dash.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/create-config.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/css-variables-conversion.js +89 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/filter-props.js +57 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/is-css-variable.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/is-svg-component.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/is-svg-element.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/parse-dom-variant.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/unit-conversion.js +230 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/animatable-none.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/defaults.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/dimensions.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/find.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/get-as-type.js +10 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/number.js +72 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/test.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/type-auto.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/type-int.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/HTMLVisualElement.js +55 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/config-motion.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/use-props.js +57 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/build-styles.js +74 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/build-transform.js +45 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/create-render-state.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/render.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/scrape-motion-values.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/transform.js +28 -0
- package/esm/node_modules/framer-motion/dist/es/render/store.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/SVGVisualElement.js +46 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/config-motion.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/lowercase-elements.js +33 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/use-props.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/build-attrs.js +52 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/camel-case-attrs.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/create-render-state.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/is-svg-tag.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/path.js +32 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/render.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/scrape-motion-values.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/transform-origin.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/animation-state.js +319 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/compare-by-depth.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/flat-tree.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/is-controlling-variants.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/is-variant-label.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/motion-values.js +63 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/resolve-dynamic-variants.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/resolve-variants.js +26 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/setters.js +101 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/variant-props.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/utils/array.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/clamp.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/utils/delay.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/utils/distance.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/utils/errors.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/utils/hsla-to-rgba.js +42 -0
- package/esm/node_modules/framer-motion/dist/es/utils/interpolate.js +92 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-browser.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-numerical-string.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-ref-object.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-zero-value-string.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/memo.js +10 -0
- package/esm/node_modules/framer-motion/dist/es/utils/mix-color.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/utils/mix-complex.js +64 -0
- package/esm/node_modules/framer-motion/dist/es/utils/mix.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/utils/noop.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/utils/offsets/default.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/utils/offsets/fill.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/utils/offsets/time.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/utils/pipe.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/progress.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/utils/reduced-motion/index.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/utils/reduced-motion/state.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/utils/resolve-value.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/shallow-compare.js +14 -0
- package/esm/node_modules/framer-motion/dist/es/utils/subscription-manager.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/utils/time-conversion.js +10 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-constant.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-force-update.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-instant-transition-state.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-is-mounted.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-isomorphic-effect.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-unmount-effect.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/utils/velocity-per-second.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/warn-once.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/value/index.js +331 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/hex.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/hsla.js +22 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/index.js +28 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/rgba.js +25 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/utils.js +23 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/complex/filter.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/complex/index.js +92 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/numbers/index.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/numbers/units.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/utils.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/value/use-will-change/is.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/value/utils/is-motion-value.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/value/utils/resolve-motion-value.js +16 -0
- package/esm/node_modules/react-is/cjs/react-is.development.js +211 -0
- package/esm/node_modules/react-is/cjs/react-is.production.min.js +123 -0
- package/esm/node_modules/react-is/index.js +12 -0
- package/esm/packages/icons/esm/Close.js +17 -0
- package/esm/packages/token-studio/esm/token/elevation/index.js +5 -1
- package/esm/utils/isFunction.js +3 -0
- package/package.json +5 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { animateValue } from './js/index.js';
|
|
2
|
+
import { noop } from '../../utils/noop.js';
|
|
3
|
+
|
|
4
|
+
function createInstantAnimation({ keyframes, delay, onUpdate, onComplete, }) {
|
|
5
|
+
const setValue = () => {
|
|
6
|
+
onUpdate && onUpdate(keyframes[keyframes.length - 1]);
|
|
7
|
+
onComplete && onComplete();
|
|
8
|
+
/**
|
|
9
|
+
* TODO: As this API grows it could make sense to always return
|
|
10
|
+
* animateValue. This will be a bigger project as animateValue
|
|
11
|
+
* is frame-locked whereas this function resolves instantly.
|
|
12
|
+
* This is a behavioural change and also has ramifications regarding
|
|
13
|
+
* assumptions within tests.
|
|
14
|
+
*/
|
|
15
|
+
return {
|
|
16
|
+
time: 0,
|
|
17
|
+
speed: 1,
|
|
18
|
+
duration: 0,
|
|
19
|
+
play: (noop),
|
|
20
|
+
pause: (noop),
|
|
21
|
+
stop: (noop),
|
|
22
|
+
then: (resolve) => {
|
|
23
|
+
resolve();
|
|
24
|
+
return Promise.resolve();
|
|
25
|
+
},
|
|
26
|
+
cancel: (noop),
|
|
27
|
+
complete: (noop),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
return delay
|
|
31
|
+
? animateValue({
|
|
32
|
+
keyframes: [0, 1],
|
|
33
|
+
duration: 0,
|
|
34
|
+
delay,
|
|
35
|
+
onComplete: setValue,
|
|
36
|
+
})
|
|
37
|
+
: setValue();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { createInstantAnimation };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { frame, cancelFrame, frameData } from '../../../frameloop/frame.js';
|
|
2
|
+
|
|
3
|
+
const frameloopDriver = (update) => {
|
|
4
|
+
const passTimestamp = ({ timestamp }) => update(timestamp);
|
|
5
|
+
return {
|
|
6
|
+
start: () => frame.update(passTimestamp, true),
|
|
7
|
+
stop: () => cancelFrame(passTimestamp),
|
|
8
|
+
/**
|
|
9
|
+
* If we're processing this frame we can use the
|
|
10
|
+
* framelocked timestamp to keep things in sync.
|
|
11
|
+
*/
|
|
12
|
+
now: () => frameData.isProcessing ? frameData.timestamp : performance.now(),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { frameloopDriver };
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { keyframes } from '../../generators/keyframes.js';
|
|
2
|
+
import { spring } from '../../generators/spring/index.js';
|
|
3
|
+
import { inertia } from '../../generators/inertia.js';
|
|
4
|
+
import { frameloopDriver } from './driver-frameloop.js';
|
|
5
|
+
import { interpolate } from '../../../utils/interpolate.js';
|
|
6
|
+
import { clamp } from '../../../utils/clamp.js';
|
|
7
|
+
import { millisecondsToSeconds, secondsToMilliseconds } from '../../../utils/time-conversion.js';
|
|
8
|
+
import { calcGeneratorDuration } from '../../generators/utils/calc-duration.js';
|
|
9
|
+
|
|
10
|
+
const types = {
|
|
11
|
+
decay: inertia,
|
|
12
|
+
inertia,
|
|
13
|
+
tween: keyframes,
|
|
14
|
+
keyframes: keyframes,
|
|
15
|
+
spring,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Animate a single value on the main thread.
|
|
19
|
+
*
|
|
20
|
+
* This function is written, where functionality overlaps,
|
|
21
|
+
* to be largely spec-compliant with WAAPI to allow fungibility
|
|
22
|
+
* between the two.
|
|
23
|
+
*/
|
|
24
|
+
function animateValue({ autoplay = true, delay = 0, driver = frameloopDriver, keyframes: keyframes$1, type = "keyframes", repeat = 0, repeatDelay = 0, repeatType = "loop", onPlay, onStop, onComplete, onUpdate, ...options }) {
|
|
25
|
+
let speed = 1;
|
|
26
|
+
let hasStopped = false;
|
|
27
|
+
let resolveFinishedPromise;
|
|
28
|
+
let currentFinishedPromise;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the current Promise every time we enter the
|
|
31
|
+
* finished state. This is WAAPI-compatible behaviour.
|
|
32
|
+
*/
|
|
33
|
+
const updateFinishedPromise = () => {
|
|
34
|
+
currentFinishedPromise = new Promise((resolve) => {
|
|
35
|
+
resolveFinishedPromise = resolve;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
// Create the first finished promise
|
|
39
|
+
updateFinishedPromise();
|
|
40
|
+
let animationDriver;
|
|
41
|
+
const generatorFactory = types[type] || keyframes;
|
|
42
|
+
/**
|
|
43
|
+
* If this isn't the keyframes generator and we've been provided
|
|
44
|
+
* strings as keyframes, we need to interpolate these.
|
|
45
|
+
* TODO: Support velocity for units and complex value types/
|
|
46
|
+
*/
|
|
47
|
+
let mapNumbersToKeyframes;
|
|
48
|
+
if (generatorFactory !== keyframes &&
|
|
49
|
+
typeof keyframes$1[0] !== "number") {
|
|
50
|
+
mapNumbersToKeyframes = interpolate([0, 100], keyframes$1, {
|
|
51
|
+
clamp: false,
|
|
52
|
+
});
|
|
53
|
+
keyframes$1 = [0, 100];
|
|
54
|
+
}
|
|
55
|
+
const generator = generatorFactory({ ...options, keyframes: keyframes$1 });
|
|
56
|
+
let mirroredGenerator;
|
|
57
|
+
if (repeatType === "mirror") {
|
|
58
|
+
mirroredGenerator = generatorFactory({
|
|
59
|
+
...options,
|
|
60
|
+
keyframes: [...keyframes$1].reverse(),
|
|
61
|
+
velocity: -(options.velocity || 0),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
let playState = "idle";
|
|
65
|
+
let holdTime = null;
|
|
66
|
+
let startTime = null;
|
|
67
|
+
let cancelTime = null;
|
|
68
|
+
/**
|
|
69
|
+
* If duration is undefined and we have repeat options,
|
|
70
|
+
* we need to calculate a duration from the generator.
|
|
71
|
+
*
|
|
72
|
+
* We set it to the generator itself to cache the duration.
|
|
73
|
+
* Any timeline resolver will need to have already precalculated
|
|
74
|
+
* the duration by this step.
|
|
75
|
+
*/
|
|
76
|
+
if (generator.calculatedDuration === null && repeat) {
|
|
77
|
+
generator.calculatedDuration = calcGeneratorDuration(generator);
|
|
78
|
+
}
|
|
79
|
+
const { calculatedDuration } = generator;
|
|
80
|
+
let resolvedDuration = Infinity;
|
|
81
|
+
let totalDuration = Infinity;
|
|
82
|
+
if (calculatedDuration !== null) {
|
|
83
|
+
resolvedDuration = calculatedDuration + repeatDelay;
|
|
84
|
+
totalDuration = resolvedDuration * (repeat + 1) - repeatDelay;
|
|
85
|
+
}
|
|
86
|
+
let currentTime = 0;
|
|
87
|
+
const tick = (timestamp) => {
|
|
88
|
+
if (startTime === null)
|
|
89
|
+
return;
|
|
90
|
+
/**
|
|
91
|
+
* requestAnimationFrame timestamps can come through as lower than
|
|
92
|
+
* the startTime as set by performance.now(). Here we prevent this,
|
|
93
|
+
* though in the future it could be possible to make setting startTime
|
|
94
|
+
* a pending operation that gets resolved here.
|
|
95
|
+
*/
|
|
96
|
+
if (speed > 0)
|
|
97
|
+
startTime = Math.min(startTime, timestamp);
|
|
98
|
+
if (speed < 0)
|
|
99
|
+
startTime = Math.min(timestamp - totalDuration / speed, startTime);
|
|
100
|
+
if (holdTime !== null) {
|
|
101
|
+
currentTime = holdTime;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Rounding the time because floating point arithmetic is not always accurate, e.g. 3000.367 - 1000.367 =
|
|
105
|
+
// 2000.0000000000002. This is a problem when we are comparing the currentTime with the duration, for
|
|
106
|
+
// example.
|
|
107
|
+
currentTime = Math.round(timestamp - startTime) * speed;
|
|
108
|
+
}
|
|
109
|
+
// Rebase on delay
|
|
110
|
+
const timeWithoutDelay = currentTime - delay * (speed >= 0 ? 1 : -1);
|
|
111
|
+
const isInDelayPhase = speed >= 0 ? timeWithoutDelay < 0 : timeWithoutDelay > totalDuration;
|
|
112
|
+
currentTime = Math.max(timeWithoutDelay, 0);
|
|
113
|
+
/**
|
|
114
|
+
* If this animation has finished, set the current time
|
|
115
|
+
* to the total duration.
|
|
116
|
+
*/
|
|
117
|
+
if (playState === "finished" && holdTime === null) {
|
|
118
|
+
currentTime = totalDuration;
|
|
119
|
+
}
|
|
120
|
+
let elapsed = currentTime;
|
|
121
|
+
let frameGenerator = generator;
|
|
122
|
+
if (repeat) {
|
|
123
|
+
/**
|
|
124
|
+
* Get the current progress (0-1) of the animation. If t is >
|
|
125
|
+
* than duration we'll get values like 2.5 (midway through the
|
|
126
|
+
* third iteration)
|
|
127
|
+
*/
|
|
128
|
+
const progress = currentTime / resolvedDuration;
|
|
129
|
+
/**
|
|
130
|
+
* Get the current iteration (0 indexed). For instance the floor of
|
|
131
|
+
* 2.5 is 2.
|
|
132
|
+
*/
|
|
133
|
+
let currentIteration = Math.floor(progress);
|
|
134
|
+
/**
|
|
135
|
+
* Get the current progress of the iteration by taking the remainder
|
|
136
|
+
* so 2.5 is 0.5 through iteration 2
|
|
137
|
+
*/
|
|
138
|
+
let iterationProgress = progress % 1.0;
|
|
139
|
+
/**
|
|
140
|
+
* If iteration progress is 1 we count that as the end
|
|
141
|
+
* of the previous iteration.
|
|
142
|
+
*/
|
|
143
|
+
if (!iterationProgress && progress >= 1) {
|
|
144
|
+
iterationProgress = 1;
|
|
145
|
+
}
|
|
146
|
+
iterationProgress === 1 && currentIteration--;
|
|
147
|
+
currentIteration = Math.min(currentIteration, repeat + 1);
|
|
148
|
+
/**
|
|
149
|
+
* Reverse progress if we're not running in "normal" direction
|
|
150
|
+
*/
|
|
151
|
+
const iterationIsOdd = Boolean(currentIteration % 2);
|
|
152
|
+
if (iterationIsOdd) {
|
|
153
|
+
if (repeatType === "reverse") {
|
|
154
|
+
iterationProgress = 1 - iterationProgress;
|
|
155
|
+
if (repeatDelay) {
|
|
156
|
+
iterationProgress -= repeatDelay / resolvedDuration;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (repeatType === "mirror") {
|
|
160
|
+
frameGenerator = mirroredGenerator;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let p = clamp(0, 1, iterationProgress);
|
|
164
|
+
if (currentTime > totalDuration) {
|
|
165
|
+
p = repeatType === "reverse" && iterationIsOdd ? 1 : 0;
|
|
166
|
+
}
|
|
167
|
+
elapsed = p * resolvedDuration;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* If we're in negative time, set state as the initial keyframe.
|
|
171
|
+
* This prevents delay: x, duration: 0 animations from finishing
|
|
172
|
+
* instantly.
|
|
173
|
+
*/
|
|
174
|
+
const state = isInDelayPhase
|
|
175
|
+
? { done: false, value: keyframes$1[0] }
|
|
176
|
+
: frameGenerator.next(elapsed);
|
|
177
|
+
if (mapNumbersToKeyframes) {
|
|
178
|
+
state.value = mapNumbersToKeyframes(state.value);
|
|
179
|
+
}
|
|
180
|
+
let { done } = state;
|
|
181
|
+
if (!isInDelayPhase && calculatedDuration !== null) {
|
|
182
|
+
done = speed >= 0 ? currentTime >= totalDuration : currentTime <= 0;
|
|
183
|
+
}
|
|
184
|
+
const isAnimationFinished = holdTime === null &&
|
|
185
|
+
(playState === "finished" || (playState === "running" && done));
|
|
186
|
+
if (onUpdate) {
|
|
187
|
+
onUpdate(state.value);
|
|
188
|
+
}
|
|
189
|
+
if (isAnimationFinished) {
|
|
190
|
+
finish();
|
|
191
|
+
}
|
|
192
|
+
return state;
|
|
193
|
+
};
|
|
194
|
+
const stopAnimationDriver = () => {
|
|
195
|
+
animationDriver && animationDriver.stop();
|
|
196
|
+
animationDriver = undefined;
|
|
197
|
+
};
|
|
198
|
+
const cancel = () => {
|
|
199
|
+
playState = "idle";
|
|
200
|
+
stopAnimationDriver();
|
|
201
|
+
resolveFinishedPromise();
|
|
202
|
+
updateFinishedPromise();
|
|
203
|
+
startTime = cancelTime = null;
|
|
204
|
+
};
|
|
205
|
+
const finish = () => {
|
|
206
|
+
playState = "finished";
|
|
207
|
+
onComplete && onComplete();
|
|
208
|
+
stopAnimationDriver();
|
|
209
|
+
resolveFinishedPromise();
|
|
210
|
+
};
|
|
211
|
+
const play = () => {
|
|
212
|
+
if (hasStopped)
|
|
213
|
+
return;
|
|
214
|
+
if (!animationDriver)
|
|
215
|
+
animationDriver = driver(tick);
|
|
216
|
+
const now = animationDriver.now();
|
|
217
|
+
onPlay && onPlay();
|
|
218
|
+
if (holdTime !== null) {
|
|
219
|
+
startTime = now - holdTime;
|
|
220
|
+
}
|
|
221
|
+
else if (!startTime || playState === "finished") {
|
|
222
|
+
startTime = now;
|
|
223
|
+
}
|
|
224
|
+
if (playState === "finished") {
|
|
225
|
+
updateFinishedPromise();
|
|
226
|
+
}
|
|
227
|
+
cancelTime = startTime;
|
|
228
|
+
holdTime = null;
|
|
229
|
+
/**
|
|
230
|
+
* Set playState to running only after we've used it in
|
|
231
|
+
* the previous logic.
|
|
232
|
+
*/
|
|
233
|
+
playState = "running";
|
|
234
|
+
animationDriver.start();
|
|
235
|
+
};
|
|
236
|
+
if (autoplay) {
|
|
237
|
+
play();
|
|
238
|
+
}
|
|
239
|
+
const controls = {
|
|
240
|
+
then(resolve, reject) {
|
|
241
|
+
return currentFinishedPromise.then(resolve, reject);
|
|
242
|
+
},
|
|
243
|
+
get time() {
|
|
244
|
+
return millisecondsToSeconds(currentTime);
|
|
245
|
+
},
|
|
246
|
+
set time(newTime) {
|
|
247
|
+
newTime = secondsToMilliseconds(newTime);
|
|
248
|
+
currentTime = newTime;
|
|
249
|
+
if (holdTime !== null || !animationDriver || speed === 0) {
|
|
250
|
+
holdTime = newTime;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
startTime = animationDriver.now() - newTime / speed;
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
get duration() {
|
|
257
|
+
const duration = generator.calculatedDuration === null
|
|
258
|
+
? calcGeneratorDuration(generator)
|
|
259
|
+
: generator.calculatedDuration;
|
|
260
|
+
return millisecondsToSeconds(duration);
|
|
261
|
+
},
|
|
262
|
+
get speed() {
|
|
263
|
+
return speed;
|
|
264
|
+
},
|
|
265
|
+
set speed(newSpeed) {
|
|
266
|
+
if (newSpeed === speed || !animationDriver)
|
|
267
|
+
return;
|
|
268
|
+
speed = newSpeed;
|
|
269
|
+
controls.time = millisecondsToSeconds(currentTime);
|
|
270
|
+
},
|
|
271
|
+
get state() {
|
|
272
|
+
return playState;
|
|
273
|
+
},
|
|
274
|
+
play,
|
|
275
|
+
pause: () => {
|
|
276
|
+
playState = "paused";
|
|
277
|
+
holdTime = currentTime;
|
|
278
|
+
},
|
|
279
|
+
stop: () => {
|
|
280
|
+
hasStopped = true;
|
|
281
|
+
if (playState === "idle")
|
|
282
|
+
return;
|
|
283
|
+
playState = "idle";
|
|
284
|
+
onStop && onStop();
|
|
285
|
+
cancel();
|
|
286
|
+
},
|
|
287
|
+
cancel: () => {
|
|
288
|
+
if (cancelTime !== null)
|
|
289
|
+
tick(cancelTime);
|
|
290
|
+
cancel();
|
|
291
|
+
},
|
|
292
|
+
complete: () => {
|
|
293
|
+
playState = "finished";
|
|
294
|
+
},
|
|
295
|
+
sample: (elapsed) => {
|
|
296
|
+
startTime = 0;
|
|
297
|
+
return tick(elapsed);
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
return controls;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export { animateValue };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { animateStyle } from './index.js';
|
|
2
|
+
import { isWaapiSupportedEasing } from './easing.js';
|
|
3
|
+
import { getFinalKeyframe } from './utils/get-final-keyframe.js';
|
|
4
|
+
import { animateValue } from '../js/index.js';
|
|
5
|
+
import { millisecondsToSeconds, secondsToMilliseconds } from '../../../utils/time-conversion.js';
|
|
6
|
+
import { memo } from '../../../utils/memo.js';
|
|
7
|
+
import { noop } from '../../../utils/noop.js';
|
|
8
|
+
import { frameData, frame, cancelFrame } from '../../../frameloop/frame.js';
|
|
9
|
+
|
|
10
|
+
const supportsWaapi = memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
|
|
11
|
+
/**
|
|
12
|
+
* A list of values that can be hardware-accelerated.
|
|
13
|
+
*/
|
|
14
|
+
const acceleratedValues = new Set([
|
|
15
|
+
"opacity",
|
|
16
|
+
"clipPath",
|
|
17
|
+
"filter",
|
|
18
|
+
"transform",
|
|
19
|
+
"backgroundColor",
|
|
20
|
+
]);
|
|
21
|
+
/**
|
|
22
|
+
* 10ms is chosen here as it strikes a balance between smooth
|
|
23
|
+
* results (more than one keyframe per frame at 60fps) and
|
|
24
|
+
* keyframe quantity.
|
|
25
|
+
*/
|
|
26
|
+
const sampleDelta = 10; //ms
|
|
27
|
+
/**
|
|
28
|
+
* Implement a practical max duration for keyframe generation
|
|
29
|
+
* to prevent infinite loops
|
|
30
|
+
*/
|
|
31
|
+
const maxDuration = 20000;
|
|
32
|
+
const requiresPregeneratedKeyframes = (valueName, options) => options.type === "spring" ||
|
|
33
|
+
valueName === "backgroundColor" ||
|
|
34
|
+
!isWaapiSupportedEasing(options.ease);
|
|
35
|
+
function createAcceleratedAnimation(value, valueName, { onUpdate, onComplete, ...options }) {
|
|
36
|
+
const canAccelerateAnimation = supportsWaapi() &&
|
|
37
|
+
acceleratedValues.has(valueName) &&
|
|
38
|
+
!options.repeatDelay &&
|
|
39
|
+
options.repeatType !== "mirror" &&
|
|
40
|
+
options.damping !== 0 &&
|
|
41
|
+
options.type !== "inertia";
|
|
42
|
+
if (!canAccelerateAnimation)
|
|
43
|
+
return false;
|
|
44
|
+
/**
|
|
45
|
+
* TODO: Unify with js/index
|
|
46
|
+
*/
|
|
47
|
+
let hasStopped = false;
|
|
48
|
+
let resolveFinishedPromise;
|
|
49
|
+
let currentFinishedPromise;
|
|
50
|
+
/**
|
|
51
|
+
* Resolve the current Promise every time we enter the
|
|
52
|
+
* finished state. This is WAAPI-compatible behaviour.
|
|
53
|
+
*/
|
|
54
|
+
const updateFinishedPromise = () => {
|
|
55
|
+
currentFinishedPromise = new Promise((resolve) => {
|
|
56
|
+
resolveFinishedPromise = resolve;
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
// Create the first finished promise
|
|
60
|
+
updateFinishedPromise();
|
|
61
|
+
let { keyframes, duration = 300, ease, times } = options;
|
|
62
|
+
/**
|
|
63
|
+
* If this animation needs pre-generated keyframes then generate.
|
|
64
|
+
*/
|
|
65
|
+
if (requiresPregeneratedKeyframes(valueName, options)) {
|
|
66
|
+
const sampleAnimation = animateValue({
|
|
67
|
+
...options,
|
|
68
|
+
repeat: 0,
|
|
69
|
+
delay: 0,
|
|
70
|
+
});
|
|
71
|
+
let state = { done: false, value: keyframes[0] };
|
|
72
|
+
const pregeneratedKeyframes = [];
|
|
73
|
+
/**
|
|
74
|
+
* Bail after 20 seconds of pre-generated keyframes as it's likely
|
|
75
|
+
* we're heading for an infinite loop.
|
|
76
|
+
*/
|
|
77
|
+
let t = 0;
|
|
78
|
+
while (!state.done && t < maxDuration) {
|
|
79
|
+
state = sampleAnimation.sample(t);
|
|
80
|
+
pregeneratedKeyframes.push(state.value);
|
|
81
|
+
t += sampleDelta;
|
|
82
|
+
}
|
|
83
|
+
times = undefined;
|
|
84
|
+
keyframes = pregeneratedKeyframes;
|
|
85
|
+
duration = t - sampleDelta;
|
|
86
|
+
ease = "linear";
|
|
87
|
+
}
|
|
88
|
+
const animation = animateStyle(value.owner.current, valueName, keyframes, {
|
|
89
|
+
...options,
|
|
90
|
+
duration,
|
|
91
|
+
/**
|
|
92
|
+
* This function is currently not called if ease is provided
|
|
93
|
+
* as a function so the cast is safe.
|
|
94
|
+
*
|
|
95
|
+
* However it would be possible for a future refinement to port
|
|
96
|
+
* in easing pregeneration from Motion One for browsers that
|
|
97
|
+
* support the upcoming `linear()` easing function.
|
|
98
|
+
*/
|
|
99
|
+
ease: ease,
|
|
100
|
+
times,
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* WAAPI animations don't resolve startTime synchronously. But a blocked
|
|
104
|
+
* thread could delay the startTime resolution by a noticeable amount.
|
|
105
|
+
* For synching handoff animations with the new Motion animation we want
|
|
106
|
+
* to ensure startTime is synchronously set.
|
|
107
|
+
*/
|
|
108
|
+
if (options.syncStart) {
|
|
109
|
+
animation.startTime = frameData.isProcessing
|
|
110
|
+
? frameData.timestamp
|
|
111
|
+
: document.timeline
|
|
112
|
+
? document.timeline.currentTime
|
|
113
|
+
: performance.now();
|
|
114
|
+
}
|
|
115
|
+
const cancelAnimation = () => animation.cancel();
|
|
116
|
+
const safeCancel = () => {
|
|
117
|
+
frame.update(cancelAnimation);
|
|
118
|
+
resolveFinishedPromise();
|
|
119
|
+
updateFinishedPromise();
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Prefer the `onfinish` prop as it's more widely supported than
|
|
123
|
+
* the `finished` promise.
|
|
124
|
+
*
|
|
125
|
+
* Here, we synchronously set the provided MotionValue to the end
|
|
126
|
+
* keyframe. If we didn't, when the WAAPI animation is finished it would
|
|
127
|
+
* be removed from the element which would then revert to its old styles.
|
|
128
|
+
*/
|
|
129
|
+
animation.onfinish = () => {
|
|
130
|
+
value.set(getFinalKeyframe(keyframes, options));
|
|
131
|
+
onComplete && onComplete();
|
|
132
|
+
safeCancel();
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Animation interrupt callback.
|
|
136
|
+
*/
|
|
137
|
+
const controls = {
|
|
138
|
+
then(resolve, reject) {
|
|
139
|
+
return currentFinishedPromise.then(resolve, reject);
|
|
140
|
+
},
|
|
141
|
+
attachTimeline(timeline) {
|
|
142
|
+
animation.timeline = timeline;
|
|
143
|
+
animation.onfinish = null;
|
|
144
|
+
return noop;
|
|
145
|
+
},
|
|
146
|
+
get time() {
|
|
147
|
+
return millisecondsToSeconds(animation.currentTime || 0);
|
|
148
|
+
},
|
|
149
|
+
set time(newTime) {
|
|
150
|
+
animation.currentTime = secondsToMilliseconds(newTime);
|
|
151
|
+
},
|
|
152
|
+
get speed() {
|
|
153
|
+
return animation.playbackRate;
|
|
154
|
+
},
|
|
155
|
+
set speed(newSpeed) {
|
|
156
|
+
animation.playbackRate = newSpeed;
|
|
157
|
+
},
|
|
158
|
+
get duration() {
|
|
159
|
+
return millisecondsToSeconds(duration);
|
|
160
|
+
},
|
|
161
|
+
play: () => {
|
|
162
|
+
if (hasStopped)
|
|
163
|
+
return;
|
|
164
|
+
animation.play();
|
|
165
|
+
/**
|
|
166
|
+
* Cancel any pending cancel tasks
|
|
167
|
+
*/
|
|
168
|
+
cancelFrame(cancelAnimation);
|
|
169
|
+
},
|
|
170
|
+
pause: () => animation.pause(),
|
|
171
|
+
stop: () => {
|
|
172
|
+
hasStopped = true;
|
|
173
|
+
if (animation.playState === "idle")
|
|
174
|
+
return;
|
|
175
|
+
/**
|
|
176
|
+
* WAAPI doesn't natively have any interruption capabilities.
|
|
177
|
+
*
|
|
178
|
+
* Rather than read commited styles back out of the DOM, we can
|
|
179
|
+
* create a renderless JS animation and sample it twice to calculate
|
|
180
|
+
* its current value, "previous" value, and therefore allow
|
|
181
|
+
* Motion to calculate velocity for any subsequent animation.
|
|
182
|
+
*/
|
|
183
|
+
const { currentTime } = animation;
|
|
184
|
+
if (currentTime) {
|
|
185
|
+
const sampleAnimation = animateValue({
|
|
186
|
+
...options,
|
|
187
|
+
autoplay: false,
|
|
188
|
+
});
|
|
189
|
+
value.setWithVelocity(sampleAnimation.sample(currentTime - sampleDelta).value, sampleAnimation.sample(currentTime).value, sampleDelta);
|
|
190
|
+
}
|
|
191
|
+
safeCancel();
|
|
192
|
+
},
|
|
193
|
+
complete: () => animation.finish(),
|
|
194
|
+
cancel: safeCancel,
|
|
195
|
+
};
|
|
196
|
+
return controls;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export { createAcceleratedAnimation };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isBezierDefinition } from '../../../easing/utils/is-bezier-definition.js';
|
|
2
|
+
|
|
3
|
+
function isWaapiSupportedEasing(easing) {
|
|
4
|
+
return Boolean(!easing ||
|
|
5
|
+
(typeof easing === "string" && supportedWaapiEasing[easing]) ||
|
|
6
|
+
isBezierDefinition(easing) ||
|
|
7
|
+
(Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
|
|
8
|
+
}
|
|
9
|
+
const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
|
|
10
|
+
const supportedWaapiEasing = {
|
|
11
|
+
linear: "linear",
|
|
12
|
+
ease: "ease",
|
|
13
|
+
easeIn: "ease-in",
|
|
14
|
+
easeOut: "ease-out",
|
|
15
|
+
easeInOut: "ease-in-out",
|
|
16
|
+
circIn: cubicBezierAsString([0, 0.65, 0.55, 1]),
|
|
17
|
+
circOut: cubicBezierAsString([0.55, 0, 1, 0.45]),
|
|
18
|
+
backIn: cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
|
|
19
|
+
backOut: cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
|
|
20
|
+
};
|
|
21
|
+
function mapEasingToNativeEasing(easing) {
|
|
22
|
+
if (!easing)
|
|
23
|
+
return undefined;
|
|
24
|
+
return isBezierDefinition(easing)
|
|
25
|
+
? cubicBezierAsString(easing)
|
|
26
|
+
: Array.isArray(easing)
|
|
27
|
+
? easing.map(mapEasingToNativeEasing)
|
|
28
|
+
: supportedWaapiEasing[easing];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { cubicBezierAsString, isWaapiSupportedEasing, mapEasingToNativeEasing, supportedWaapiEasing };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { mapEasingToNativeEasing } from './easing.js';
|
|
2
|
+
|
|
3
|
+
function animateStyle(element, valueName, keyframes, { delay = 0, duration, repeat = 0, repeatType = "loop", ease, times, } = {}) {
|
|
4
|
+
const keyframeOptions = { [valueName]: keyframes };
|
|
5
|
+
if (times)
|
|
6
|
+
keyframeOptions.offset = times;
|
|
7
|
+
const easing = mapEasingToNativeEasing(ease);
|
|
8
|
+
/**
|
|
9
|
+
* If this is an easing array, apply to keyframes, not animation as a whole
|
|
10
|
+
*/
|
|
11
|
+
if (Array.isArray(easing))
|
|
12
|
+
keyframeOptions.easing = easing;
|
|
13
|
+
return element.animate(keyframeOptions, {
|
|
14
|
+
delay,
|
|
15
|
+
duration,
|
|
16
|
+
easing: !Array.isArray(easing) ? easing : "linear",
|
|
17
|
+
fill: "both",
|
|
18
|
+
iterations: repeat + 1,
|
|
19
|
+
direction: repeatType === "reverse" ? "alternate" : "normal",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { animateStyle };
|