UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

71 lines (70 loc) 2.19 kB
import { __extends } from "../../../tslib/tslib.es6.mjs"; import Displayable, { DEFAULT_COMMON_STYLE, DEFAULT_COMMON_ANIMATION_PROPS } from "./Displayable.mjs"; import BoundingRect from "../core/BoundingRect.mjs"; import { defaults, createObject } from "../core/util.mjs"; var DEFAULT_IMAGE_STYLE = defaults({ x: 0, y: 0 }, DEFAULT_COMMON_STYLE); var DEFAULT_IMAGE_ANIMATION_PROPS = { style: defaults({ x: true, y: true, width: true, height: true, sx: true, sy: true, sWidth: true, sHeight: true }, DEFAULT_COMMON_ANIMATION_PROPS.style) }; function isImageLike(source) { return !!(source && typeof source !== "string" && source.width && source.height); } var ZRImage = function(_super) { __extends(ZRImage2, _super); function ZRImage2() { return _super !== null && _super.apply(this, arguments) || this; } ZRImage2.prototype.createStyle = function(obj) { return createObject(DEFAULT_IMAGE_STYLE, obj); }; ZRImage2.prototype._getSize = function(dim) { var style = this.style; var size = style[dim]; if (size != null) { return size; } var imageSource = isImageLike(style.image) ? style.image : this.__image; if (!imageSource) { return 0; } var otherDim = dim === "width" ? "height" : "width"; var otherDimSize = style[otherDim]; if (otherDimSize == null) { return imageSource[dim]; } else { return imageSource[dim] / imageSource[otherDim] * otherDimSize; } }; ZRImage2.prototype.getWidth = function() { return this._getSize("width"); }; ZRImage2.prototype.getHeight = function() { return this._getSize("height"); }; ZRImage2.prototype.getAnimationStyleProps = function() { return DEFAULT_IMAGE_ANIMATION_PROPS; }; ZRImage2.prototype.getBoundingRect = function() { var style = this.style; if (!this._rect) { this._rect = new BoundingRect(style.x || 0, style.y || 0, this.getWidth(), this.getHeight()); } return this._rect; }; return ZRImage2; }(Displayable); ZRImage.prototype.type = "image"; var ZRImage$1 = ZRImage; export { DEFAULT_IMAGE_ANIMATION_PROPS, DEFAULT_IMAGE_STYLE, ZRImage$1 as default };