2014-12-03 02:09:20 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import Base from './base.js';
|
|
|
|
|
|
|
|
export default _.extend({}, Base, {
|
2014-12-10 21:57:42 +00:00
|
|
|
type: 'match-fragment',
|
2014-12-06 17:34:00 +00:00
|
|
|
|
2014-12-11 00:01:57 +00:00
|
|
|
_render() {
|
2014-12-10 21:52:57 +00:00
|
|
|
if (this._repeat.textValue === '') {
|
2014-12-13 14:09:58 +00:00
|
|
|
return this.proxy(this._content);
|
2014-12-10 21:52:57 +00:00
|
|
|
} else {
|
2014-12-13 17:55:03 +00:00
|
|
|
return this._content.render(this.container.group())
|
|
|
|
.then((() => {
|
|
|
|
var box, paths = [];
|
|
|
|
|
|
|
|
this._content.transform(this._repeat.contentPosition());
|
|
|
|
|
|
|
|
box = this._content.getBBox();
|
|
|
|
|
|
|
|
if (this._repeat.hasSkip()) {
|
2014-12-16 02:51:17 +00:00
|
|
|
let vert = Math.max(0, box.ay - box.y - 10),
|
|
|
|
horiz = box.width - 10;
|
|
|
|
|
|
|
|
paths.push(`M0,${box.ay}q10,0 10,-10v${-vert}q0,-10 10,-10h${horiz}q10,0 10,10v${vert}q0,10 10,10`);
|
2014-12-15 17:43:13 +00:00
|
|
|
|
|
|
|
if (!this._repeat.greedy()) {
|
2014-12-16 02:51:17 +00:00
|
|
|
paths.push(`M10,${box.ay - 15}l5,5m-5,-5l-5,5`);
|
2014-12-15 17:43:13 +00:00
|
|
|
}
|
2014-12-13 17:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this._repeat.hasLoop()) {
|
2014-12-16 02:51:17 +00:00
|
|
|
let vert = box.y2 - box.ay - 10;
|
|
|
|
|
|
|
|
paths.push(`M${box.x},${box.ay}q-10,0 -10,10v${vert}q0,10 10,10h${box.width}q10,0 10,-10v${-vert}q0,-10 -10,-10`);
|
2014-12-15 17:43:13 +00:00
|
|
|
|
|
|
|
if (this._repeat.greedy()) {
|
2014-12-16 02:51:17 +00:00
|
|
|
paths.push(`M${box.x2 + 10},${box.ay + 15}l5,-5m-5,5l-5,-5`);
|
2014-12-15 17:43:13 +00:00
|
|
|
}
|
2014-12-13 17:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (paths.length) {
|
|
|
|
this.container.prepend(
|
|
|
|
this.container.path(paths.join('')));
|
|
|
|
}
|
2014-12-15 17:24:32 +00:00
|
|
|
}).bind(this))
|
|
|
|
.then((() => {
|
|
|
|
var labelStr = this._repeat.label(),
|
|
|
|
label,
|
|
|
|
labelBox,
|
|
|
|
labelShift = (this._repeat.hasSkip() ? 5 : 0),
|
|
|
|
box = this.getBBox();
|
|
|
|
|
|
|
|
if (labelStr) {
|
|
|
|
label = this.container.text(0, 0, labelStr)
|
|
|
|
.addClass('repeat-label');
|
|
|
|
labelBox = label.getBBox();
|
|
|
|
label.transform(Snap.matrix()
|
|
|
|
.translate(box.x2 - labelBox.width - labelShift, box.y2 + labelBox.height));
|
|
|
|
}
|
2014-12-13 17:55:03 +00:00
|
|
|
}).bind(this));
|
2014-12-06 17:34:00 +00:00
|
|
|
}
|
2014-12-15 00:08:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_getAnchor() {
|
|
|
|
var anchor = this._content.getAnchor(),
|
|
|
|
matrix = this.transform().localMatrix;
|
|
|
|
|
|
|
|
return _.extend(anchor, {
|
|
|
|
ax: matrix.x(anchor.ax, anchor.ay),
|
|
|
|
ax2: matrix.x(anchor.ax2, anchor.ay),
|
|
|
|
ay: matrix.y(anchor.ax, anchor.ay)
|
|
|
|
});
|
2014-12-06 17:34:00 +00:00
|
|
|
}
|
2014-12-03 02:09:20 +00:00
|
|
|
});
|