mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Use Item#type instead of instanceof checks for better performance.
This commit is contained in:
parent
bf9acd4499
commit
98f7c020bd
3 changed files with 4 additions and 5 deletions
|
@ -1779,7 +1779,7 @@ var Item = this.Item = Base.extend(Callback, {
|
|||
// Find group parents. Check for parent._parent, since don't want
|
||||
// top level layers, because they also inherit from Group
|
||||
if (parent._parent
|
||||
&& (parent instanceof Group || parent instanceof CompoundPath)
|
||||
&& /^(group|layer|compound-path)$/.test(parent._type)
|
||||
&& item.isDescendant(parent))
|
||||
return true;
|
||||
// Keep walking up otherwise
|
||||
|
|
|
@ -89,7 +89,7 @@ new function() {
|
|||
if (childNode.nodeType == 1 && (child = importSvg(childNode))) {
|
||||
// If adding CompoundPaths to other CompoundPaths,
|
||||
// we need to "unbox" them first:
|
||||
if (clip && child instanceof CompoundPath) {
|
||||
if (clip && child._type === 'compound-path') {
|
||||
item.addChildren(child.removeChildren());
|
||||
child.remove();
|
||||
} else if (!(child instanceof Symbol)) {
|
||||
|
|
|
@ -181,10 +181,9 @@ var ToolEvent = this.ToolEvent = Event.extend(/** @lends ToolEvent# */{
|
|||
var result = this.tool._scope.project.hitTest(this.getPoint());
|
||||
if (result) {
|
||||
var item = result.item,
|
||||
// Find group parent
|
||||
// Find group parent, but exclude layers
|
||||
parent = item._parent;
|
||||
while ((parent instanceof Group && !(parent instanceof Layer))
|
||||
|| parent instanceof CompoundPath) {
|
||||
while (/^(group|compound-path)$/.test(parent._type)) {
|
||||
item = parent;
|
||||
parent = parent._parent;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue