regexper-static/src/js/parser/javascript/subexp.js
Jeff Avallone 5917d2b035 Updating getBBox and anchor code to improve performance
This change will reduce the number of calls to this.container.getBBox
when calculating the bounding box of a node
2015-04-16 17:13:12 -04:00

63 lines
1.5 KiB
JavaScript

import _ from 'lodash';
export default {
type: 'subexp',
definedProperties: {
_anchor: {
get: function() {
var anchor = this.regexp.getBBox(),
matrix = this.transform().localMatrix;
return {
ax: matrix.x(anchor.ax, anchor.ay),
ax2: matrix.x(anchor.ax2, anchor.ay),
ay: matrix.y(anchor.ax, anchor.ay)
};
}
}
},
labelMap: {
'?:': '',
'?=': 'positive lookahead',
'?!': 'negative lookahead'
},
_render() {
// NOTE: this.label() MUST be called here, in _render and before any child
// nodes are rendered. This is to keep the group numbers in the correct
// order.
var label = this.label();
return this.regexp.render(this.container.group())
.then(() => {
return this.renderLabeledBox(label, this.regexp, {
padding: 10
});
});
},
label() {
if (typeof this._label === 'undefined') {
if (_.has(this.labelMap, this.properties.capture.textValue)) {
this._label = this.labelMap[this.properties.capture.textValue];
} else {
this._label = 'group #' + (this.state.groupCounter++);
}
}
return this._label;
},
setup() {
// NOTE: DO NOT call this.label() in setup. It will lead to groups being
// numbered in reverse order
this.regexp = this.properties.regexp;
if (this.properties.capture.textValue == '?:') {
this.proxy = this.regexp;
}
}
};