UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

361 lines (359 loc) • 14.5 kB
/** * DevExtreme (cjs/__internal/common/core/animation/presets/presets.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.presets = exports.PresetCollection = void 0; var _fx = _interopRequireDefault(require("../../../../../common/core/animation/fx")); var _devices = _interopRequireDefault(require("../../../../../core/devices")); var _iterator = require("../../../../../core/utils/iterator"); var _size = require("../../../../../core/utils/size"); var _component = require("../../../../core/widget/component"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const directionPostfixes = { forward: " dx-forward", backward: " dx-backward", none: " dx-no-direction", undefined: " dx-no-direction" }; const optionPrefix = "preset_"; const isAndroidDevice = () => !!(_devices.default.current().android || _devices.default.real.android); class AnimationPresetCollection extends _component.Component { constructor() { super(); this._registeredPresets = []; this.resetToDefaults() } _getDefaultOptions() { return Object.assign({}, super._getDefaultOptions(), { defaultAnimationDuration: 400, defaultAnimationDelay: 0, defaultStaggerAnimationDuration: 300, defaultStaggerAnimationDelay: 40, defaultStaggerAnimationStartDelay: 500 }) } _defaultOptionsRules() { return super._defaultOptionsRules().concat([{ device: device => !!device.phone, options: { defaultStaggerAnimationDuration: 350, defaultStaggerAnimationDelay: 50, defaultStaggerAnimationStartDelay: 0 } }, { device: () => isAndroidDevice(), options: { defaultAnimationDelay: 100 } }]) } _getPresetOptionName(animationName) { return `preset_${animationName}` } _createAndroidSlideAnimationConfig(throughOpacity, widthMultiplier) { const createBaseConfig = configModifier => ({ type: "slide", delay: void 0 === configModifier.delay ? this.option("defaultAnimationDelay") : configModifier.delay, duration: void 0 === configModifier.duration ? this.option("defaultAnimationDuration") : configModifier.duration }); return { enter: ($element, configModifier) => { const width = (0, _size.getWidth)($element.parent()) * widthMultiplier; const { direction: direction } = configModifier; const config = createBaseConfig(configModifier); config.to = { left: 0, opacity: 1 }; if ("forward" === direction) { config.from = { left: width, opacity: throughOpacity } } else if ("backward" === direction) { config.from = { left: -width, opacity: throughOpacity } } else { config.from = { left: 0, opacity: 0 } } return _fx.default.createAnimation($element, config) }, leave: ($element, configModifier) => { const width = (0, _size.getWidth)($element.parent()) * widthMultiplier; const { direction: direction } = configModifier; const config = createBaseConfig(configModifier); config.from = { left: 0, opacity: 1 }; switch (direction) { case "forward": config.to = { left: -width, opacity: throughOpacity }; break; case "backward": config.to = { left: width, opacity: throughOpacity }; break; default: config.to = { left: 0, opacity: 0 } } return _fx.default.createAnimation($element, config) } } } _createOpenDoorConfig() { const createBaseConfig = configModifier => ({ type: "css", extraCssClasses: "dx-opendoor-animation", delay: void 0 === configModifier.delay ? this.option("defaultAnimationDelay") : configModifier.delay, duration: void 0 === configModifier.duration ? this.option("defaultAnimationDuration") : configModifier.duration }); return { enter: ($element, configModifier) => { const { direction: direction } = configModifier; const config = createBaseConfig(configModifier); config.delay = "none" === direction ? config.delay : config.duration; config.from = `dx-enter dx-opendoor-animation${directionPostfixes[String(direction)]}`; config.to = "dx-enter-active"; return _fx.default.createAnimation($element, config) }, leave: ($element, configModifier) => { const { direction: direction } = configModifier; const config = createBaseConfig(configModifier); config.from = `dx-leave dx-opendoor-animation${directionPostfixes[String(direction)]}`; config.to = "dx-leave-active"; return _fx.default.createAnimation($element, config) } } } _createWinPopConfig() { const baseConfig = { type: "css", extraCssClasses: "dx-win-pop-animation", duration: this.option("defaultAnimationDuration") }; return { enter: ($element, configModifier) => { const config = baseConfig; const { direction: direction } = configModifier; config.delay = "none" === direction ? this.option("defaultAnimationDelay") : this.option("defaultAnimationDuration") / 2; config.from = `dx-enter dx-win-pop-animation${directionPostfixes[String(direction)]}`; config.to = "dx-enter-active"; return _fx.default.createAnimation($element, config) }, leave: ($element, configModifier) => { const config = baseConfig; const { direction: direction } = configModifier; config.delay = this.option("defaultAnimationDelay"); config.from = `dx-leave dx-win-pop-animation${directionPostfixes[String(direction)]}`; config.to = "dx-leave-active"; return _fx.default.createAnimation($element, config) } } } resetToDefaults() { this.clear(); this.registerDefaultPresets(); this.applyChanges() } clear(name) { const newRegisteredPresets = []; (0, _iterator.each)(this._registeredPresets, (index, preset) => { if (!name || name === preset.name) { this.option(this._getPresetOptionName(preset.name), void 0) } else { newRegisteredPresets.push(preset) } }); this._registeredPresets = newRegisteredPresets; this.applyChanges() } registerPreset(name, config) { this._registeredPresets.push({ name: name, config: config }) } applyChanges() { const customRules = []; (0, _iterator.each)(this._registeredPresets, (index, preset) => { const rule = { device: preset.config.device, options: {} }; rule.options[this._getPresetOptionName(preset.name)] = preset.config.animation; customRules.push(rule) }); this._setOptionsByDevice(customRules) } getPreset(name) { let result = name; while ("string" === typeof result) { result = this.option(this._getPresetOptionName(result)) } return result } registerDefaultPresets() { this.registerPreset("pop", { animation: { extraCssClasses: "dx-android-pop-animation", delay: this.option("defaultAnimationDelay"), duration: this.option("defaultAnimationDuration") } }); this.registerPreset("openDoor", { animation: this._createOpenDoorConfig() }); this.registerPreset("win-pop", { animation: this._createWinPopConfig() }); this.registerPreset("fade", { animation: { extraCssClasses: "dx-fade-animation", delay: this.option("defaultAnimationDelay"), duration: this.option("defaultAnimationDuration") } }); this.registerPreset("slide", { device: () => isAndroidDevice(), animation: this._createAndroidSlideAnimationConfig(1, 1) }); this.registerPreset("slide", { device: () => !isAndroidDevice(), animation: { extraCssClasses: "dx-slide-animation", delay: this.option("defaultAnimationDelay"), duration: this.option("defaultAnimationDuration") } }); this.registerPreset("ios7-slide", { animation: { extraCssClasses: "dx-ios7-slide-animation", delay: this.option("defaultAnimationDelay"), duration: this.option("defaultAnimationDuration") } }); this.registerPreset("overflow", { animation: { extraCssClasses: "dx-overflow-animation", delay: this.option("defaultAnimationDelay"), duration: this.option("defaultAnimationDuration") } }); this.registerPreset("ios7-toolbar", { device: () => !isAndroidDevice(), animation: { extraCssClasses: "dx-ios7-toolbar-animation", delay: this.option("defaultAnimationDelay"), duration: this.option("defaultAnimationDuration") } }); this.registerPreset("ios7-toolbar", { device: () => isAndroidDevice(), animation: this._createAndroidSlideAnimationConfig(0, .4) }); this.registerPreset("stagger-fade", { animation: { extraCssClasses: "dx-fade-animation", staggerDelay: this.option("defaultStaggerAnimationDelay"), duration: this.option("defaultStaggerAnimationDuration"), delay: this.option("defaultStaggerAnimationStartDelay") } }); this.registerPreset("stagger-slide", { animation: { extraCssClasses: "dx-slide-animation", staggerDelay: this.option("defaultStaggerAnimationDelay"), duration: this.option("defaultStaggerAnimationDuration"), delay: this.option("defaultStaggerAnimationStartDelay") } }); this.registerPreset("stagger-fade-slide", { animation: { extraCssClasses: "dx-fade-slide-animation", staggerDelay: this.option("defaultStaggerAnimationDelay"), duration: this.option("defaultStaggerAnimationDuration"), delay: this.option("defaultStaggerAnimationStartDelay") } }); this.registerPreset("stagger-drop", { animation: { extraCssClasses: "dx-drop-animation", staggerDelay: this.option("defaultStaggerAnimationDelay"), duration: this.option("defaultStaggerAnimationDuration"), delay: this.option("defaultStaggerAnimationStartDelay") } }); this.registerPreset("stagger-fade-drop", { animation: { extraCssClasses: "dx-fade-drop-animation", staggerDelay: this.option("defaultStaggerAnimationDelay"), duration: this.option("defaultStaggerAnimationDuration"), delay: this.option("defaultStaggerAnimationStartDelay") } }); this.registerPreset("stagger-fade-rise", { animation: { extraCssClasses: "dx-fade-rise-animation", staggerDelay: this.option("defaultStaggerAnimationDelay"), duration: this.option("defaultStaggerAnimationDuration"), delay: this.option("defaultStaggerAnimationStartDelay") } }); this.registerPreset("stagger-3d-drop", { animation: { extraCssClasses: "dx-3d-drop-animation", staggerDelay: this.option("defaultStaggerAnimationDelay"), duration: this.option("defaultStaggerAnimationDuration"), delay: this.option("defaultStaggerAnimationStartDelay") } }); this.registerPreset("stagger-fade-zoom", { animation: { extraCssClasses: "dx-fade-zoom-animation", staggerDelay: this.option("defaultStaggerAnimationDelay"), duration: this.option("defaultStaggerAnimationDuration"), delay: this.option("defaultStaggerAnimationStartDelay") } }) } } exports.PresetCollection = AnimationPresetCollection; const animationPresets = exports.presets = new AnimationPresetCollection;