HCompElement.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {
  2. extendPrototype,
  3. } from '../../utils/functionExtensions';
  4. import {
  5. createSizedArray,
  6. } from '../../utils/helpers/arrays';
  7. import PropertyFactory from '../../utils/PropertyFactory';
  8. import HybridRendererBase from '../../renderers/HybridRendererBase';
  9. import HBaseElement from './HBaseElement';
  10. import ICompElement from '../CompElement';
  11. import SVGCompElement from '../svgElements/SVGCompElement';
  12. function HCompElement(data, globalData, comp) {
  13. this.layers = data.layers;
  14. this.supports3d = !data.hasMask;
  15. this.completeLayers = false;
  16. this.pendingElements = [];
  17. this.elements = this.layers ? createSizedArray(this.layers.length) : [];
  18. this.initElement(data, globalData, comp);
  19. this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true };
  20. }
  21. extendPrototype([HybridRendererBase, ICompElement, HBaseElement], HCompElement);
  22. HCompElement.prototype._createBaseContainerElements = HCompElement.prototype.createContainerElements;
  23. HCompElement.prototype.createContainerElements = function () {
  24. this._createBaseContainerElements();
  25. // divElement.style.clip = 'rect(0px, '+this.data.w+'px, '+this.data.h+'px, 0px)';
  26. if (this.data.hasMask) {
  27. this.svgElement.setAttribute('width', this.data.w);
  28. this.svgElement.setAttribute('height', this.data.h);
  29. this.transformedElement = this.baseElement;
  30. } else {
  31. this.transformedElement = this.layerElement;
  32. }
  33. };
  34. HCompElement.prototype.addTo3dContainer = function (elem, pos) {
  35. var j = 0;
  36. var nextElement;
  37. while (j < pos) {
  38. if (this.elements[j] && this.elements[j].getBaseElement) {
  39. nextElement = this.elements[j].getBaseElement();
  40. }
  41. j += 1;
  42. }
  43. if (nextElement) {
  44. this.layerElement.insertBefore(elem, nextElement);
  45. } else {
  46. this.layerElement.appendChild(elem);
  47. }
  48. };
  49. HCompElement.prototype.createComp = function (data) {
  50. if (!this.supports3d) {
  51. return new SVGCompElement(data, this.globalData, this);
  52. }
  53. return new HCompElement(data, this.globalData, this);
  54. };
  55. export default HCompElement;