shape.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  4. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  5. var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  6. function _createSuper(Derived) { return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
  7. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8. var Util = require('../util/common');
  9. var Element = require('./element');
  10. var Shape = /*#__PURE__*/function (_Element) {
  11. (0, _inheritsLoose2["default"])(Shape, _Element);
  12. var _super = _createSuper(Shape);
  13. function Shape() {
  14. return _Element.apply(this, arguments) || this;
  15. }
  16. var _proto = Shape.prototype;
  17. _proto._initProperties = function _initProperties() {
  18. this._attrs = {
  19. zIndex: 0,
  20. visible: true,
  21. destroyed: false,
  22. isShape: true,
  23. attrs: {}
  24. };
  25. };
  26. _proto.getType = function getType() {
  27. return this._attrs.type;
  28. };
  29. _proto.drawInner = function drawInner(context) {
  30. var self = this;
  31. var attrs = self.get('attrs');
  32. self.createPath(context);
  33. var originOpacity = context.globalAlpha;
  34. if (self.hasFill()) {
  35. var fillOpacity = attrs.fillOpacity;
  36. if (!Util.isNil(fillOpacity) && fillOpacity !== 1) {
  37. context.globalAlpha = fillOpacity;
  38. context.fill();
  39. context.globalAlpha = originOpacity;
  40. } else {
  41. context.fill();
  42. }
  43. }
  44. if (self.hasStroke()) {
  45. var lineWidth = attrs.lineWidth;
  46. if (lineWidth > 0) {
  47. var strokeOpacity = attrs.strokeOpacity;
  48. if (!Util.isNil(strokeOpacity) && strokeOpacity !== 1) {
  49. context.globalAlpha = strokeOpacity;
  50. }
  51. context.stroke();
  52. }
  53. }
  54. };
  55. _proto.getBBox = function getBBox() {
  56. var bbox = this._attrs.bbox;
  57. if (!bbox) {
  58. bbox = this.calculateBox();
  59. if (bbox) {
  60. bbox.x = bbox.minX;
  61. bbox.y = bbox.minY;
  62. bbox.width = bbox.maxX - bbox.minX;
  63. bbox.height = bbox.maxY - bbox.minY;
  64. }
  65. this._attrs.bbox = bbox;
  66. }
  67. return bbox;
  68. };
  69. _proto.calculateBox = function calculateBox() {
  70. return null;
  71. };
  72. _proto.createPath = function createPath() {};
  73. return Shape;
  74. }(Element);
  75. module.exports = Shape;