Comparing version 2.0.3 to 2.0.4
{ | ||
"name": "@antv/g", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "A canvas library which providing 2d draw for G2.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -0,1 +1,3 @@ | ||
const Util = require('./common'); | ||
const TABLE = document.createElement('table'); | ||
@@ -15,12 +17,15 @@ const TABLE_TR = document.createElement('tr'); | ||
module.exports = { | ||
getBoundingClientRect(node) { | ||
const rect = node.getBoundingClientRect(); | ||
const top = document.documentElement.clientTop; | ||
const left = document.documentElement.clientLeft; | ||
return { | ||
top: rect.top - top, | ||
bottom: rect.bottom - top, | ||
left: rect.left - left, | ||
right: rect.right - left | ||
}; | ||
getBoundingClientRect(node, defaultValue) { | ||
if (node && node.getBoundingClientRect) { | ||
const rect = node.getBoundingClientRect(); | ||
const top = document.documentElement.clientTop; | ||
const left = document.documentElement.clientLeft; | ||
return { | ||
top: rect.top - top, | ||
bottom: rect.bottom - top, | ||
left: rect.left - left, | ||
right: rect.right - left | ||
}; | ||
} | ||
return defaultValue || null; | ||
}, | ||
@@ -31,14 +36,24 @@ /** | ||
* @param {String} name 样式名 | ||
* @param {Any} defaultValue 默认值 | ||
* @return {String} 属性值 | ||
*/ | ||
getStyle(dom, name) { | ||
if (window.getComputedStyle) { | ||
return window.getComputedStyle(dom, null)[name]; | ||
getStyle(dom, name, defaultValue) { | ||
try { | ||
if (window.getComputedStyle) { | ||
return window.getComputedStyle(dom, null)[name]; | ||
} | ||
return dom.currentStyle[name]; | ||
} catch (e) { | ||
if (!Util.isNil(defaultValue)) { | ||
return defaultValue; | ||
} | ||
return null; | ||
} | ||
return dom.currentStyle[name]; | ||
}, | ||
modifyCSS(dom, css) { | ||
for (const key in css) { | ||
if (css.hasOwnProperty(key)) { | ||
dom.style[key] = css[key]; | ||
if (dom) { | ||
for (const key in css) { | ||
if (css.hasOwnProperty(key)) { | ||
dom.style[key] = css[key]; | ||
} | ||
} | ||
@@ -69,6 +84,7 @@ } | ||
* @param {HTMLElement} el dom节点 | ||
* @param {Number} defaultValue 默认值 | ||
* @return {Number} 宽度 | ||
*/ | ||
getWidth(el) { | ||
let width = this.getStyle(el, 'width'); | ||
getWidth(el, defaultValue) { | ||
let width = this.getStyle(el, 'width', defaultValue); | ||
if (width === 'auto') { | ||
@@ -82,6 +98,7 @@ width = el.offsetWidth; | ||
* @param {HTMLElement} el dom节点 | ||
* @param {Number} defaultValue 默认值 | ||
* @return {Number} 高度 | ||
*/ | ||
getHeight(el) { | ||
let height = this.getStyle(el, 'height'); | ||
getHeight(el, defaultValue) { | ||
let height = this.getStyle(el, 'height', defaultValue); | ||
if (height === 'auto') { | ||
@@ -95,9 +112,10 @@ height = el.offsetHeight; | ||
* @param {HTMLElement} el dom节点 | ||
* @param {Number} defaultValue 默认值 | ||
* @return {Number} 高度 | ||
*/ | ||
getOuterHeight(el) { | ||
const height = this.getHeight(el); | ||
getOuterHeight(el, defaultValue) { | ||
const height = this.getHeight(el, defaultValue); | ||
const bTop = parseFloat(this.getStyle(el, 'borderTopWidth')) || 0; | ||
const pTop = parseFloat(this.getStyle(el, 'paddingTop')); | ||
const pBottom = parseFloat(this.getStyle(el, 'paddingBottom')); | ||
const pTop = parseFloat(this.getStyle(el, 'paddingTop')) || 0; | ||
const pBottom = parseFloat(this.getStyle(el, 'paddingBottom')) || 0; | ||
const bBottom = parseFloat(this.getStyle(el, 'borderBottomWidth')) || 0; | ||
@@ -109,9 +127,10 @@ return height + bTop + bBottom + pTop + pBottom; | ||
* @param {HTMLElement} el dom节点 | ||
* @param {Number} defaultValue 默认值 | ||
* @return {Number} 宽度 | ||
*/ | ||
getOuterWidth(el) { | ||
const width = this.getWidth(el); | ||
getOuterWidth(el, defaultValue) { | ||
const width = this.getWidth(el, defaultValue); | ||
const bLeft = parseFloat(this.getStyle(el, 'borderLeftWidth')) || 0; | ||
const pLeft = parseFloat(this.getStyle(el, 'paddingLeft')); | ||
const pRight = parseFloat(this.getStyle(el, 'paddingRight')); | ||
const pLeft = parseFloat(this.getStyle(el, 'paddingLeft')) || 0; | ||
const pRight = parseFloat(this.getStyle(el, 'paddingRight')) || 0; | ||
const bRight = parseFloat(this.getStyle(el, 'borderRightWidth')) || 0; | ||
@@ -128,16 +147,18 @@ return width + bLeft + bRight + pLeft + pRight; | ||
addEventListener(target, eventType, callback) { | ||
if (target.addEventListener) { | ||
target.addEventListener(eventType, callback, false); | ||
return { | ||
remove() { | ||
target.removeEventListener(eventType, callback, false); | ||
} | ||
}; | ||
} else if (target.attachEvent) { | ||
target.attachEvent('on' + eventType, callback); | ||
return { | ||
remove() { | ||
target.detachEvent('on' + eventType, callback); | ||
} | ||
}; | ||
if (target) { | ||
if (target.addEventListener) { | ||
target.addEventListener(eventType, callback, false); | ||
return { | ||
remove() { | ||
target.removeEventListener(eventType, callback, false); | ||
} | ||
}; | ||
} else if (target.attachEvent) { | ||
target.attachEvent('on' + eventType, callback); | ||
return { | ||
remove() { | ||
target.detachEvent('on' + eventType, callback); | ||
} | ||
}; | ||
} | ||
} | ||
@@ -144,0 +165,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
844986
21158