ImageElement.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {
  2. extendPrototype,
  3. } from '../utils/functionExtensions';
  4. import createNS from '../utils/helpers/svg_elements';
  5. import BaseElement from './BaseElement';
  6. import TransformElement from './helpers/TransformElement';
  7. import SVGBaseElement from './svgElements/SVGBaseElement';
  8. import HierarchyElement from './helpers/HierarchyElement';
  9. import FrameElement from './helpers/FrameElement';
  10. import RenderableDOMElement from './helpers/RenderableDOMElement';
  11. function IImageElement(data, globalData, comp) {
  12. this.assetData = globalData.getAssetData(data.refId);
  13. if (this.assetData && this.assetData.sid) {
  14. this.assetData = globalData.slotManager.getProp(this.assetData);
  15. }
  16. this.initElement(data, globalData, comp);
  17. this.sourceRect = {
  18. top: 0, left: 0, width: this.assetData.w, height: this.assetData.h,
  19. };
  20. }
  21. extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement);
  22. IImageElement.prototype.createContent = function () {
  23. var assetPath = this.globalData.getAssetsPath(this.assetData);
  24. this.innerElem = createNS('image');
  25. this.innerElem.setAttribute('width', this.assetData.w + 'px');
  26. this.innerElem.setAttribute('height', this.assetData.h + 'px');
  27. this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio);
  28. this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath);
  29. this.layerElement.appendChild(this.innerElem);
  30. };
  31. IImageElement.prototype.sourceRectAtTime = function () {
  32. return this.sourceRect;
  33. };
  34. export default IImageElement;