prepare.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { customInnerStore, TRANSFORM_PROPS } from './CustomSeries';
  41. import { normalizeToArray } from '../../util/model';
  42. import { assert, hasOwn, indexOf, isArrayLike, keys } from 'zrender/lib/core/util';
  43. import { cloneValue } from 'zrender/lib/animation/Animator';
  44. var LEGACY_TRANSFORM_PROPS = {
  45. position: ['x', 'y'],
  46. scale: ['scaleX', 'scaleY'],
  47. origin: ['originX', 'originY']
  48. };
  49. function setLegacyTransformProp(elOption, targetProps, legacyName) {
  50. var legacyArr = elOption[legacyName];
  51. var xyName = LEGACY_TRANSFORM_PROPS[legacyName];
  52. if (legacyArr) {
  53. targetProps[xyName[0]] = legacyArr[0];
  54. targetProps[xyName[1]] = legacyArr[1];
  55. }
  56. }
  57. function setTransformProp(elOption, allProps, name) {
  58. if (elOption[name] != null) {
  59. allProps[name] = elOption[name];
  60. }
  61. }
  62. function setTransformPropToTransitionFrom(transitionFrom, name, fromTransformable // If provided, retrieve from the element.
  63. ) {
  64. if (fromTransformable) {
  65. transitionFrom[name] = fromTransformable[name];
  66. }
  67. } // See [STRATEGY_TRANSITION]
  68. export function prepareShapeOrExtraTransitionFrom(mainAttr, fromEl, elOption, transFromProps, isInit) {
  69. var attrOpt = elOption[mainAttr];
  70. if (!attrOpt) {
  71. return;
  72. }
  73. var elPropsInAttr = fromEl[mainAttr];
  74. var transFromPropsInAttr;
  75. var enterFrom = attrOpt.enterFrom;
  76. if (isInit && enterFrom) {
  77. !transFromPropsInAttr && (transFromPropsInAttr = transFromProps[mainAttr] = {});
  78. var enterFromKeys = keys(enterFrom);
  79. for (var i = 0; i < enterFromKeys.length; i++) {
  80. // `enterFrom` props are not necessarily also declared in `shape`/`style`/...,
  81. // for example, `opacity` can only declared in `enterFrom` but not in `style`.
  82. var key = enterFromKeys[i]; // Do not clone, animator will perform that clone.
  83. transFromPropsInAttr[key] = enterFrom[key];
  84. }
  85. }
  86. if (!isInit && elPropsInAttr) {
  87. if (attrOpt.transition) {
  88. !transFromPropsInAttr && (transFromPropsInAttr = transFromProps[mainAttr] = {});
  89. var transitionKeys = normalizeToArray(attrOpt.transition);
  90. for (var i = 0; i < transitionKeys.length; i++) {
  91. var key = transitionKeys[i];
  92. var elVal = elPropsInAttr[key];
  93. if (process.env.NODE_ENV !== 'production') {
  94. checkNonStyleTansitionRefer(key, attrOpt[key], elVal);
  95. } // Do not clone, see `checkNonStyleTansitionRefer`.
  96. transFromPropsInAttr[key] = elVal;
  97. }
  98. } else if (indexOf(elOption.transition, mainAttr) >= 0) {
  99. !transFromPropsInAttr && (transFromPropsInAttr = transFromProps[mainAttr] = {});
  100. var elPropsInAttrKeys = keys(elPropsInAttr);
  101. for (var i = 0; i < elPropsInAttrKeys.length; i++) {
  102. var key = elPropsInAttrKeys[i];
  103. var elVal = elPropsInAttr[key];
  104. if (isNonStyleTransitionEnabled(attrOpt[key], elVal)) {
  105. transFromPropsInAttr[key] = elVal;
  106. }
  107. }
  108. }
  109. }
  110. var leaveTo = attrOpt.leaveTo;
  111. if (leaveTo) {
  112. var leaveToProps = getOrCreateLeaveToPropsFromEl(fromEl);
  113. var leaveToPropsInAttr = leaveToProps[mainAttr] || (leaveToProps[mainAttr] = {});
  114. var leaveToKeys = keys(leaveTo);
  115. for (var i = 0; i < leaveToKeys.length; i++) {
  116. var key = leaveToKeys[i];
  117. leaveToPropsInAttr[key] = leaveTo[key];
  118. }
  119. }
  120. }
  121. export function prepareShapeOrExtraAllPropsFinal(mainAttr, elOption, allProps) {
  122. var attrOpt = elOption[mainAttr];
  123. if (!attrOpt) {
  124. return;
  125. }
  126. var allPropsInAttr = allProps[mainAttr] = {};
  127. var keysInAttr = keys(attrOpt);
  128. for (var i = 0; i < keysInAttr.length; i++) {
  129. var key = keysInAttr[i]; // To avoid share one object with different element, and
  130. // to avoid user modify the object inexpectedly, have to clone.
  131. allPropsInAttr[key] = cloneValue(attrOpt[key]);
  132. }
  133. } // See [STRATEGY_TRANSITION].
  134. export function prepareTransformTransitionFrom(el, elOption, transFromProps, isInit) {
  135. var enterFrom = elOption.enterFrom;
  136. if (isInit && enterFrom) {
  137. var enterFromKeys = keys(enterFrom);
  138. for (var i = 0; i < enterFromKeys.length; i++) {
  139. var key = enterFromKeys[i];
  140. if (process.env.NODE_ENV !== 'production') {
  141. checkTransformPropRefer(key, 'el.enterFrom');
  142. } // Do not clone, animator will perform that clone.
  143. transFromProps[key] = enterFrom[key];
  144. }
  145. }
  146. if (!isInit) {
  147. if (elOption.transition) {
  148. var transitionKeys = normalizeToArray(elOption.transition);
  149. for (var i = 0; i < transitionKeys.length; i++) {
  150. var key = transitionKeys[i];
  151. if (key === 'style' || key === 'shape' || key === 'extra') {
  152. continue;
  153. }
  154. var elVal = el[key];
  155. if (process.env.NODE_ENV !== 'production') {
  156. checkTransformPropRefer(key, 'el.transition');
  157. checkNonStyleTansitionRefer(key, elOption[key], elVal);
  158. } // Do not clone, see `checkNonStyleTansitionRefer`.
  159. transFromProps[key] = elVal;
  160. }
  161. } // This default transition see [STRATEGY_TRANSITION]
  162. else {
  163. setTransformPropToTransitionFrom(transFromProps, 'x', el);
  164. setTransformPropToTransitionFrom(transFromProps, 'y', el);
  165. }
  166. }
  167. var leaveTo = elOption.leaveTo;
  168. if (leaveTo) {
  169. var leaveToProps = getOrCreateLeaveToPropsFromEl(el);
  170. var leaveToKeys = keys(leaveTo);
  171. for (var i = 0; i < leaveToKeys.length; i++) {
  172. var key = leaveToKeys[i];
  173. if (process.env.NODE_ENV !== 'production') {
  174. checkTransformPropRefer(key, 'el.leaveTo');
  175. }
  176. leaveToProps[key] = leaveTo[key];
  177. }
  178. }
  179. }
  180. export function prepareTransformAllPropsFinal(el, elOption, allProps) {
  181. setLegacyTransformProp(elOption, allProps, 'position');
  182. setLegacyTransformProp(elOption, allProps, 'scale');
  183. setLegacyTransformProp(elOption, allProps, 'origin');
  184. setTransformProp(elOption, allProps, 'x');
  185. setTransformProp(elOption, allProps, 'y');
  186. setTransformProp(elOption, allProps, 'scaleX');
  187. setTransformProp(elOption, allProps, 'scaleY');
  188. setTransformProp(elOption, allProps, 'originX');
  189. setTransformProp(elOption, allProps, 'originY');
  190. setTransformProp(elOption, allProps, 'rotation');
  191. } // See [STRATEGY_TRANSITION].
  192. export function prepareStyleTransitionFrom(fromEl, elOption, styleOpt, transFromProps, isInit) {
  193. if (!styleOpt) {
  194. return;
  195. }
  196. var fromElStyle = fromEl.style;
  197. var transFromStyleProps;
  198. var enterFrom = styleOpt.enterFrom;
  199. if (isInit && enterFrom) {
  200. var enterFromKeys = keys(enterFrom);
  201. !transFromStyleProps && (transFromStyleProps = transFromProps.style = {});
  202. for (var i = 0; i < enterFromKeys.length; i++) {
  203. var key = enterFromKeys[i]; // Do not clone, animator will perform that clone.
  204. transFromStyleProps[key] = enterFrom[key];
  205. }
  206. }
  207. if (!isInit && fromElStyle) {
  208. if (styleOpt.transition) {
  209. var transitionKeys = normalizeToArray(styleOpt.transition);
  210. !transFromStyleProps && (transFromStyleProps = transFromProps.style = {});
  211. for (var i = 0; i < transitionKeys.length; i++) {
  212. var key = transitionKeys[i];
  213. var elVal = fromElStyle[key]; // Do not clone, see `checkNonStyleTansitionRefer`.
  214. transFromStyleProps[key] = elVal;
  215. }
  216. } else if (fromEl.getAnimationStyleProps && indexOf(elOption.transition, 'style') >= 0) {
  217. var animationProps = fromEl.getAnimationStyleProps();
  218. var animationStyleProps = animationProps ? animationProps.style : null;
  219. if (animationStyleProps) {
  220. !transFromStyleProps && (transFromStyleProps = transFromProps.style = {});
  221. var styleKeys = keys(styleOpt);
  222. for (var i = 0; i < styleKeys.length; i++) {
  223. var key = styleKeys[i];
  224. if (animationStyleProps[key]) {
  225. var elVal = fromElStyle[key];
  226. transFromStyleProps[key] = elVal;
  227. }
  228. }
  229. }
  230. }
  231. }
  232. var leaveTo = styleOpt.leaveTo;
  233. if (leaveTo) {
  234. var leaveToKeys = keys(leaveTo);
  235. var leaveToProps = getOrCreateLeaveToPropsFromEl(fromEl);
  236. var leaveToStyleProps = leaveToProps.style || (leaveToProps.style = {});
  237. for (var i = 0; i < leaveToKeys.length; i++) {
  238. var key = leaveToKeys[i];
  239. leaveToStyleProps[key] = leaveTo[key];
  240. }
  241. }
  242. }
  243. var checkNonStyleTansitionRefer;
  244. if (process.env.NODE_ENV !== 'production') {
  245. checkNonStyleTansitionRefer = function (propName, optVal, elVal) {
  246. if (!isArrayLike(optVal)) {
  247. assert(optVal != null && isFinite(optVal), 'Prop `' + propName + '` must refer to a finite number or ArrayLike for transition.');
  248. } else {
  249. // Try not to copy array for performance, but if user use the same object in different
  250. // call of `renderItem`, it will casue animation transition fail.
  251. assert(optVal !== elVal, 'Prop `' + propName + '` must use different Array object each time for transition.');
  252. }
  253. };
  254. }
  255. function isNonStyleTransitionEnabled(optVal, elVal) {
  256. // The same as `checkNonStyleTansitionRefer`.
  257. return !isArrayLike(optVal) ? optVal != null && isFinite(optVal) : optVal !== elVal;
  258. }
  259. var checkTransformPropRefer;
  260. if (process.env.NODE_ENV !== 'production') {
  261. checkTransformPropRefer = function (key, usedIn) {
  262. assert(hasOwn(TRANSFORM_PROPS, key), 'Prop `' + key + '` is not a permitted in `' + usedIn + '`. ' + 'Only `' + keys(TRANSFORM_PROPS).join('`, `') + '` are permitted.');
  263. };
  264. }
  265. function getOrCreateLeaveToPropsFromEl(el) {
  266. var innerEl = customInnerStore(el);
  267. return innerEl.leaveToProps || (innerEl.leaveToProps = {});
  268. }