presets.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /**
  2. * DevExtreme (animation/presets/presets.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var Component = require("../../core/component");
  11. var each = require("../../core/utils/iterator").each;
  12. var extend = require("../../core/utils/extend").extend;
  13. var devices = require("../../core/devices");
  14. var fx = require("../fx");
  15. var directionPostfixes = {
  16. forward: " dx-forward",
  17. backward: " dx-backward",
  18. none: " dx-no-direction",
  19. undefined: " dx-no-direction"
  20. };
  21. var optionPrefix = "preset_";
  22. var AnimationPresetCollection = Component.inherit({
  23. ctor: function() {
  24. this.callBase.apply(this, arguments);
  25. this._registeredPresets = [];
  26. this.resetToDefaults()
  27. },
  28. _getDefaultOptions: function() {
  29. return extend(this.callBase(), {
  30. defaultAnimationDuration: 400,
  31. defaultAnimationDelay: 0,
  32. defaultStaggerAnimationDuration: 300,
  33. defaultStaggerAnimationDelay: 40,
  34. defaultStaggerAnimationStartDelay: 500
  35. })
  36. },
  37. _defaultOptionsRules: function() {
  38. return this.callBase().concat([{
  39. device: function(_device) {
  40. return _device.phone
  41. },
  42. options: {
  43. defaultStaggerAnimationDuration: 350,
  44. defaultStaggerAnimationDelay: 50,
  45. defaultStaggerAnimationStartDelay: 0
  46. }
  47. }, {
  48. device: function() {
  49. return devices.current().android || devices.real.android
  50. },
  51. options: {
  52. defaultAnimationDelay: 100
  53. }
  54. }])
  55. },
  56. _getPresetOptionName: function(animationName) {
  57. return optionPrefix + animationName
  58. },
  59. _createAndroidSlideAnimationConfig: function(throughOpacity, widthMultiplier) {
  60. var that = this;
  61. var createBaseConfig = function(configModifier) {
  62. return {
  63. type: "slide",
  64. delay: void 0 === configModifier.delay ? that.option("defaultAnimationDelay") : configModifier.delay,
  65. duration: void 0 === configModifier.duration ? that.option("defaultAnimationDuration") : configModifier.duration
  66. }
  67. };
  68. return {
  69. enter: function($element, configModifier) {
  70. var width = $element.parent().width() * widthMultiplier;
  71. var direction = configModifier.direction;
  72. var config = createBaseConfig(configModifier);
  73. config.to = {
  74. left: 0,
  75. opacity: 1
  76. };
  77. if ("forward" === direction) {
  78. config.from = {
  79. left: width,
  80. opacity: throughOpacity
  81. }
  82. } else {
  83. if ("backward" === direction) {
  84. config.from = {
  85. left: -width,
  86. opacity: throughOpacity
  87. }
  88. } else {
  89. config.from = {
  90. left: 0,
  91. opacity: 0
  92. }
  93. }
  94. }
  95. return fx.createAnimation($element, config)
  96. },
  97. leave: function($element, configModifier) {
  98. var width = $element.parent().width() * widthMultiplier;
  99. var direction = configModifier.direction;
  100. var config = createBaseConfig(configModifier);
  101. config.from = {
  102. left: 0,
  103. opacity: 1
  104. };
  105. if ("forward" === direction) {
  106. config.to = {
  107. left: -width,
  108. opacity: throughOpacity
  109. }
  110. } else {
  111. if ("backward" === direction) {
  112. config.to = {
  113. left: width,
  114. opacity: throughOpacity
  115. }
  116. } else {
  117. config.to = {
  118. left: 0,
  119. opacity: 0
  120. }
  121. }
  122. }
  123. return fx.createAnimation($element, config)
  124. }
  125. }
  126. },
  127. _createOpenDoorConfig: function() {
  128. var that = this;
  129. var createBaseConfig = function(configModifier) {
  130. return {
  131. type: "css",
  132. extraCssClasses: "dx-opendoor-animation",
  133. delay: void 0 === configModifier.delay ? that.option("defaultAnimationDelay") : configModifier.delay,
  134. duration: void 0 === configModifier.duration ? that.option("defaultAnimationDuration") : configModifier.duration
  135. }
  136. };
  137. return {
  138. enter: function($element, configModifier) {
  139. var direction = configModifier.direction;
  140. var config = createBaseConfig(configModifier);
  141. config.delay = "none" === direction ? config.delay : config.duration;
  142. config.from = "dx-enter dx-opendoor-animation" + directionPostfixes[direction];
  143. config.to = "dx-enter-active";
  144. return fx.createAnimation($element, config)
  145. },
  146. leave: function($element, configModifier) {
  147. var direction = configModifier.direction;
  148. var config = createBaseConfig(configModifier);
  149. config.from = "dx-leave dx-opendoor-animation" + directionPostfixes[direction];
  150. config.to = "dx-leave-active";
  151. return fx.createAnimation($element, config)
  152. }
  153. }
  154. },
  155. _createWinPopConfig: function() {
  156. var that = this;
  157. var baseConfig = {
  158. type: "css",
  159. extraCssClasses: "dx-win-pop-animation",
  160. duration: that.option("defaultAnimationDuration")
  161. };
  162. return {
  163. enter: function($element, configModifier) {
  164. var config = baseConfig;
  165. var direction = configModifier.direction;
  166. config.delay = "none" === direction ? that.option("defaultAnimationDelay") : that.option("defaultAnimationDuration") / 2;
  167. config.from = "dx-enter dx-win-pop-animation" + directionPostfixes[direction];
  168. config.to = "dx-enter-active";
  169. return fx.createAnimation($element, config)
  170. },
  171. leave: function($element, configModifier) {
  172. var config = baseConfig;
  173. var direction = configModifier.direction;
  174. config.delay = that.option("defaultAnimationDelay");
  175. config.from = "dx-leave dx-win-pop-animation" + directionPostfixes[direction];
  176. config.to = "dx-leave-active";
  177. return fx.createAnimation($element, config)
  178. }
  179. }
  180. },
  181. resetToDefaults: function() {
  182. this.clear();
  183. this.registerDefaultPresets();
  184. this.applyChanges()
  185. },
  186. clear: function(name) {
  187. var that = this;
  188. var newRegisteredPresets = [];
  189. each(this._registeredPresets, function(index, preset) {
  190. if (!name || name === preset.name) {
  191. that.option(that._getPresetOptionName(preset.name), void 0)
  192. } else {
  193. newRegisteredPresets.push(preset)
  194. }
  195. });
  196. this._registeredPresets = newRegisteredPresets;
  197. this.applyChanges()
  198. },
  199. registerPreset: function(name, config) {
  200. this._registeredPresets.push({
  201. name: name,
  202. config: config
  203. })
  204. },
  205. applyChanges: function() {
  206. var that = this;
  207. var customRules = [];
  208. each(this._registeredPresets, function(index, preset) {
  209. var rule = {
  210. device: preset.config.device,
  211. options: {}
  212. };
  213. rule.options[that._getPresetOptionName(preset.name)] = preset.config.animation;
  214. customRules.push(rule)
  215. });
  216. this._setOptionsByDevice(customRules)
  217. },
  218. getPreset: function(name) {
  219. var result = name;
  220. while ("string" === typeof result) {
  221. result = this.option(this._getPresetOptionName(result))
  222. }
  223. return result
  224. },
  225. registerDefaultPresets: function() {
  226. this.registerPreset("pop", {
  227. animation: {
  228. extraCssClasses: "dx-android-pop-animation",
  229. delay: this.option("defaultAnimationDelay"),
  230. duration: this.option("defaultAnimationDuration")
  231. }
  232. });
  233. this.registerPreset("openDoor", {
  234. animation: this._createOpenDoorConfig()
  235. });
  236. this.registerPreset("win-pop", {
  237. animation: this._createWinPopConfig()
  238. });
  239. this.registerPreset("fade", {
  240. animation: {
  241. extraCssClasses: "dx-fade-animation",
  242. delay: this.option("defaultAnimationDelay"),
  243. duration: this.option("defaultAnimationDuration")
  244. }
  245. });
  246. this.registerPreset("slide", {
  247. device: function() {
  248. return devices.current().android || devices.real.android
  249. },
  250. animation: this._createAndroidSlideAnimationConfig(1, 1)
  251. });
  252. this.registerPreset("slide", {
  253. device: function() {
  254. return !devices.current().android && !devices.real.android
  255. },
  256. animation: {
  257. extraCssClasses: "dx-slide-animation",
  258. delay: this.option("defaultAnimationDelay"),
  259. duration: this.option("defaultAnimationDuration")
  260. }
  261. });
  262. this.registerPreset("ios7-slide", {
  263. animation: {
  264. extraCssClasses: "dx-ios7-slide-animation",
  265. delay: this.option("defaultAnimationDelay"),
  266. duration: this.option("defaultAnimationDuration")
  267. }
  268. });
  269. this.registerPreset("overflow", {
  270. animation: {
  271. extraCssClasses: "dx-overflow-animation",
  272. delay: this.option("defaultAnimationDelay"),
  273. duration: this.option("defaultAnimationDuration")
  274. }
  275. });
  276. this.registerPreset("ios7-toolbar", {
  277. device: function() {
  278. return !devices.current().android && !devices.real.android
  279. },
  280. animation: {
  281. extraCssClasses: "dx-ios7-toolbar-animation",
  282. delay: this.option("defaultAnimationDelay"),
  283. duration: this.option("defaultAnimationDuration")
  284. }
  285. });
  286. this.registerPreset("ios7-toolbar", {
  287. device: function() {
  288. return devices.current().android || devices.real.android
  289. },
  290. animation: this._createAndroidSlideAnimationConfig(0, .4)
  291. });
  292. this.registerPreset("stagger-fade", {
  293. animation: {
  294. extraCssClasses: "dx-fade-animation",
  295. staggerDelay: this.option("defaultStaggerAnimationDelay"),
  296. duration: this.option("defaultStaggerAnimationDuration"),
  297. delay: this.option("defaultStaggerAnimationStartDelay")
  298. }
  299. });
  300. this.registerPreset("stagger-slide", {
  301. animation: {
  302. extraCssClasses: "dx-slide-animation",
  303. staggerDelay: this.option("defaultStaggerAnimationDelay"),
  304. duration: this.option("defaultStaggerAnimationDuration"),
  305. delay: this.option("defaultStaggerAnimationStartDelay")
  306. }
  307. });
  308. this.registerPreset("stagger-fade-slide", {
  309. animation: {
  310. extraCssClasses: "dx-fade-slide-animation",
  311. staggerDelay: this.option("defaultStaggerAnimationDelay"),
  312. duration: this.option("defaultStaggerAnimationDuration"),
  313. delay: this.option("defaultStaggerAnimationStartDelay")
  314. }
  315. });
  316. this.registerPreset("stagger-drop", {
  317. animation: {
  318. extraCssClasses: "dx-drop-animation",
  319. staggerDelay: this.option("defaultStaggerAnimationDelay"),
  320. duration: this.option("defaultStaggerAnimationDuration"),
  321. delay: this.option("defaultStaggerAnimationStartDelay")
  322. }
  323. });
  324. this.registerPreset("stagger-fade-drop", {
  325. animation: {
  326. extraCssClasses: "dx-fade-drop-animation",
  327. staggerDelay: this.option("defaultStaggerAnimationDelay"),
  328. duration: this.option("defaultStaggerAnimationDuration"),
  329. delay: this.option("defaultStaggerAnimationStartDelay")
  330. }
  331. });
  332. this.registerPreset("stagger-fade-rise", {
  333. animation: {
  334. extraCssClasses: "dx-fade-rise-animation",
  335. staggerDelay: this.option("defaultStaggerAnimationDelay"),
  336. duration: this.option("defaultStaggerAnimationDuration"),
  337. delay: this.option("defaultStaggerAnimationStartDelay")
  338. }
  339. });
  340. this.registerPreset("stagger-3d-drop", {
  341. animation: {
  342. extraCssClasses: "dx-3d-drop-animation",
  343. staggerDelay: this.option("defaultStaggerAnimationDelay"),
  344. duration: this.option("defaultStaggerAnimationDuration"),
  345. delay: this.option("defaultStaggerAnimationStartDelay")
  346. }
  347. });
  348. this.registerPreset("stagger-fade-zoom", {
  349. animation: {
  350. extraCssClasses: "dx-fade-zoom-animation",
  351. staggerDelay: this.option("defaultStaggerAnimationDelay"),
  352. duration: this.option("defaultStaggerAnimationDuration"),
  353. delay: this.option("defaultStaggerAnimationStartDelay")
  354. }
  355. })
  356. }
  357. });
  358. exports.PresetCollection = AnimationPresetCollection;
  359. var animationPresets = new AnimationPresetCollection;
  360. exports.presets = animationPresets;