117 lines
3.5 KiB
JavaScript
117 lines
3.5 KiB
JavaScript
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
|
|
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
|
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
|
|
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; } }
|
|
|
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
|
|
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
|
|
|
var Util = require('../util');
|
|
|
|
var Guide = require('./base');
|
|
|
|
var Image = /*#__PURE__*/function (_Guide) {
|
|
_inheritsLoose(Image, _Guide);
|
|
|
|
var _super = _createSuper(Image);
|
|
|
|
function Image() {
|
|
return _Guide.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = Image.prototype;
|
|
|
|
_proto.getDefaultCfg = function getDefaultCfg() {
|
|
var cfg = _Guide.prototype.getDefaultCfg.call(this);
|
|
|
|
return Util.mix({}, cfg, {
|
|
type: 'image',
|
|
|
|
/**
|
|
* the start of image
|
|
* @type {Object | Function | Array}
|
|
*/
|
|
start: null,
|
|
|
|
/**
|
|
* the end of image
|
|
* @type {Object | Function | Array}
|
|
*/
|
|
end: null,
|
|
|
|
/**
|
|
* image url
|
|
* @type {String}
|
|
*/
|
|
src: null,
|
|
|
|
/**
|
|
* Horizontal offset
|
|
* @type {Number}
|
|
*/
|
|
offsetX: null,
|
|
|
|
/**
|
|
* Vertical offset
|
|
* @type {Number}
|
|
*/
|
|
offsetY: null
|
|
});
|
|
};
|
|
|
|
_proto.render = function render(coord, group) {
|
|
var self = this;
|
|
var start = self.parsePoint(coord, self.get('start'));
|
|
|
|
if (!start) {
|
|
return;
|
|
}
|
|
|
|
var cfg = {
|
|
x: start.x,
|
|
y: start.y
|
|
};
|
|
cfg.img = self.get('src');
|
|
|
|
if (!self.get('end')) {
|
|
// 如果咩有指定结束点,则 start 为图片的左上角坐标
|
|
cfg.width = self.get('width') || 32;
|
|
cfg.height = self.get('height') || 32;
|
|
} else {
|
|
var end = self.parsePoint(coord, self.get('end'));
|
|
|
|
if (!end) {
|
|
return;
|
|
} // cfg.width = Math.abs(end.x - start.x);
|
|
// cfg.height = Math.abs(end.y - start.y);
|
|
|
|
|
|
cfg.width = end.x - start.x;
|
|
cfg.height = end.y - start.y;
|
|
}
|
|
|
|
if (self.get('offsetX')) {
|
|
cfg.x += self.get('offsetX');
|
|
}
|
|
|
|
if (self.get('offsetY')) {
|
|
cfg.y += self.get('offsetY');
|
|
}
|
|
|
|
var imgGuide = group.addShape('Image', {
|
|
zIndex: 1,
|
|
attrs: cfg
|
|
});
|
|
imgGuide.name = 'guide-image';
|
|
self.get('appendInfo') && imgGuide.setSilent('appendInfo', self.get('appendInfo'));
|
|
self.set('el', imgGuide);
|
|
};
|
|
|
|
return Image;
|
|
}(Guide);
|
|
|
|
module.exports = Image; |