Skip to content

Commit

Permalink
fix: vd的type
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Nov 16, 2020
1 parent 1a3bd9d commit 5fcd40e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 29 deletions.
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12631,7 +12631,6 @@

if (renderMode === mode.SVG) {
virtualDom = this.__virtualDom = {
type: 'dom',
bb: [],
children: [],
visibility: 'visible'
Expand Down Expand Up @@ -14430,12 +14429,6 @@
lastMcIndex = i - 1;
mcHash[lastMcIndex] = [item];
hasMc = true;

if (item.isMask) {
children[i - 1].__hasMask = true;
} else {
children[i - 1].__hasClip = true;
}
}
} else {
lastMcIndex = undefined;
Expand Down Expand Up @@ -15932,6 +15925,17 @@
item.__computeMeasure(renderMode, ctx, false, cb);
});
}
}, {
key: "render",
value: function render(renderMode, lv, ctx, defs, cache) {
var res = _get(_getPrototypeOf(Dom.prototype), "render", this).call(this, renderMode, lv, ctx, defs, cache);

if (renderMode === mode.SVG) {
this.virtualDom.type = 'dom';
}

return res;
}
}, {
key: "__destroy",
value: function __destroy() {
Expand Down
2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

29 changes: 9 additions & 20 deletions src/node/Dom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Xom from './Xom';
import Text from './Text';
import mode from './mode';
import LineGroup from './LineGroup';
import Component from './Component';
import tag from './tag';
Expand Down Expand Up @@ -36,12 +37,6 @@ function genZIndexChildren(dom) {
lastMcIndex = i - 1;
mcHash[lastMcIndex] = [item];
hasMc = true;
if(item.isMask) {
children[i - 1].__hasMask = true;
}
else {
children[i - 1].__hasClip = true;
}
}
}
else {
Expand Down Expand Up @@ -90,20 +85,6 @@ function genZIndexChildren(dom) {
return res;
}

function getMaskChildren(dom) {
let list = [];
dom.children.forEach(item => {
let child = item;
if(item instanceof Component) {
item = item.shadowRoot;
}
if(item.isMask || item.isClip) {
list.push(child);
}
});
return list;
}

class Dom extends Xom {
constructor(tagName, props, children) {
super(tagName, props);
Expand Down Expand Up @@ -1405,6 +1386,14 @@ class Dom extends Xom {
});
}

render(renderMode, lv, ctx, defs, cache) {
let res = super.render(renderMode, lv, ctx, defs, cache);
if(renderMode === mode.SVG) {
this.virtualDom.type = 'dom';
}
return res;
}

__destroy() {
if(this.isDestroyed) {
return;
Expand Down
1 change: 0 additions & 1 deletion src/node/Xom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,6 @@ class Xom extends Node {
// svg设置vd上的lv属性标明<REPAINT时应用缓存,初始化肯定没有
if(renderMode === mode.SVG) {
virtualDom = this.__virtualDom = {
type: 'dom',
bb: [],
children: [],
visibility: 'visible',
Expand Down
14 changes: 14 additions & 0 deletions test/struct-mask-svg/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=0"/>
<title>test</title>
</head>
<body>
<div id="test"></div>
<input id="base64" type="text" value=""/>
<script src="../../index.js"></script>
<script src="script.js"></script>
</body>
</html>
12 changes: 12 additions & 0 deletions test/struct-mask-svg/script.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let o = karas.render(
<svg width="360" height="360">
<div>123</div>
<$circle mask="1"/>
</svg>,
'#test'
);
let input = document.querySelector('#base64');
input.value = JSON.stringify(o.__structs.map(item => {
item.node = item.node.tagName || 'text';
return item;
}));
12 changes: 12 additions & 0 deletions test/struct-mask-svg/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let path = require('path');
let fs = require('fs');

module.exports = {
'init': function(browser) {
browser
.url('file://' + path.join(__dirname, 'index.html'))
.waitForElementVisible('body', 1000)
.assert.value('input', '[{"node":"svg","index":0,"lv":0,"num":2,"total":3},{"node":"div","index":1,"childIndex":0,"lv":1,"hasMask":1,"num":1,"total":1},{"node":"text","index":2,"childIndex":0,"lv":2},{"node":"$circle","index":3,"childIndex":1,"lv":1}]')
.end();
}
};

1 comment on commit 5fcd40e

@army8735
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.