");
+ const fragment = BI.Widget._renderEngine.createElement("
");
fragment.append(text.element[0]);
newNode.text = fragment.html();
// // 处理标红
@@ -376,21 +400,22 @@ BI.TreeView = BI.inherit(BI.Pane, {
// n.text = BI.htmlEncode(BI.Text.formatText(n.text + ""));
// }
// }
+
return newNode;
});
- },
+ }
- _loadMore: function () {
- var self = this, o = this.options;
+ _loadMore() {
+ const self = this, o = this.options;
this.tip.setLoading();
- var op = BI.extend({}, o.paras, {
- times: ++this.times
+ const op = extend({}, o.paras, {
+ times: ++this.times,
});
- o.itemsCreator(op, function (res) {
+ o.itemsCreator(op, res => {
if (self._stop === true) {
return;
}
- var hasNext = !!res.hasNext, nodes = res.items || [];
+ const hasNext = !!res.hasNext, nodes = res.items || [];
if (!hasNext) {
self.tip.setEnd();
@@ -401,32 +426,34 @@ BI.TreeView = BI.inherit(BI.Pane, {
self.nodes.addNodes(null, self._dealWidthNodes(nodes));
}
});
- },
+ }
// 生成树内部方法
- _initTree: function (setting) {
- var self = this, o = this.options;
- self.fireEvent(BI.Events.INIT);
+ _initTree(setting) {
+ const self = this, o = this.options;
+ self.fireEvent(Events.INIT);
this.times = 1;
- var tree = this.tree;
+ const tree = this.tree;
tree.empty();
this.loading();
this.tip.setVisible(false);
- var callback = function (nodes) {
+
+ function callback(nodes) {
if (self._stop === true) {
return;
}
self.nodes = BI.$.fn.zTree.init(tree.element, setting, nodes);
- };
- var op = BI.extend({}, o.paras, {
- times: 1
+ }
+
+ const op = extend({}, o.paras, {
+ times: 1,
});
- o.itemsCreator(op, function (res) {
+ o.itemsCreator(op, res => {
if (self._stop === true) {
return;
}
- var hasNext = !!res.hasNext, nodes = res.items || [];
+ const hasNext = !!res.hasNext, nodes = res.items || [];
if (nodes.length > 0) {
callback(self._dealWidthNodes(nodes));
}
@@ -437,68 +464,69 @@ BI.TreeView = BI.inherit(BI.Pane, {
} else {
self.tip.setLoaded();
}
- op.times === 1 && self.fireEvent(BI.Events.AFTERINIT);
+ op.times === 1 && self.fireEvent(Events.AFTERINIT);
});
- },
+ }
// 构造树结构,
- initTree: function (nodes, setting) {
- var setting = setting || {
+ initTree(nodes, setting) {
+ const defaultSetting = {
async: {
- enable: false
+ enable: false,
},
check: {
- enable: false
+ enable: false,
},
data: {
key: {
title: "title",
- name: "text"
+ name: "text",
},
simpleData: {
- enable: true
- }
+ enable: true,
+ },
},
view: {
showIcon: false,
expandSpeed: "",
- nameIsHTML: true
+ nameIsHTML: true,
},
- callback: {}
+ callback: {},
};
- this.nodes = BI.$.fn.zTree.init(this.tree.element, setting, nodes);
- },
+ this.nodes = BI.$.fn.zTree.init(this.tree.element, setting || defaultSetting, nodes);
+ }
- start: function () {
+ start() {
this._stop = false;
- },
+ }
- stop: function () {
+ stop() {
this._stop = true;
- },
+ }
// 生成树方法
- stroke: function (config) {
+ stroke(config) {
delete this.options.keyword;
- BI.extend(this.options.paras, config);
- var setting = this._configSetting();
+ extend(this.options.paras, config);
+ const setting = this._configSetting();
this._createTree();
this.start();
this._initTree(setting);
- },
+ }
+
+ populate() {
+ this.stroke(...arguments);
+ }
- populate: function () {
- this.stroke.apply(this, arguments);
- },
+ hasChecked() {
+ const treeObj = this.nodes;
- hasChecked: function () {
- var treeObj = this.nodes;
return treeObj.getCheckedNodes(true).length > 0;
- },
+ }
- checkAll: function (checked) {
+ checkAll(checked) {
function setNode(children) {
- BI.each(children, function (i, child) {
+ each(children, (i, child) => {
child.halfCheck = false;
setNode(child.children);
});
@@ -508,68 +536,58 @@ BI.TreeView = BI.inherit(BI.Pane, {
return;
}
- BI.each(this.nodes.getNodes(), function (i, node) {
+ each(this.nodes.getNodes(), (i, node) => {
node.halfCheck = false;
setNode(node.children);
});
this.nodes.checkAllNodes(checked);
- },
+ }
- expandAll: function (flag) {
+ expandAll(flag) {
this.nodes && this.nodes.expandAll(flag);
- },
+ }
// 设置树节点的状态
- setValue: function (value, param) {
+ setValue(value, param) {
this.checkAll(false);
this.updateValue(value, param);
this.refresh();
- },
+ }
- setSelectedValue: function (value) {
- this.options.paras.selectedValues = BI.deepClone(value || {});
- },
+ setSelectedValue(value) {
+ this.options.paras.selectedValues = deepClone(value || {});
+ }
- updateValue: function (values, param) {
+ updateValue(values, param) {
if (!this.nodes) {
return;
}
param || (param = "value");
- var treeObj = this.nodes;
- BI.each(values, function (v, op) {
- var nodes = treeObj.getNodesByParam(param, v, null);
- BI.each(nodes, function (j, node) {
- BI.extend(node, { checked: true }, op);
+ const treeObj = this.nodes;
+ each(values, (v, op) => {
+ const nodes = treeObj.getNodesByParam(param, v, null);
+ each(nodes, (j, node) => {
+ extend(node, { checked: true }, op);
treeObj.updateNode(node);
});
});
- },
+ }
- refresh: function () {
+ refresh() {
this.nodes && this.nodes.refresh();
- },
+ }
- getValue: function () {
+ getValue() {
if (!this.nodes) {
return null;
}
+
return this._getSelectedValues();
- },
+ }
- destroyed: function () {
+ destroyed() {
this.stop();
this.nodes && this.nodes.destroy();
}
-});
-BI.extend(BI.TreeView, {
- REQ_TYPE_INIT_DATA: 1,
- REQ_TYPE_ADJUST_DATA: 2,
- REQ_TYPE_SELECT_DATA: 3,
- REQ_TYPE_GET_SELECTED_DATA: 4
-});
-
-BI.TreeView.EVENT_CHANGE = "EVENT_CHANGE";
-BI.TreeView.EVENT_INIT = BI.Events.INIT;
-BI.TreeView.EVENT_AFTERINIT = BI.Events.AFTERINIT;
-
-BI.shortcut("bi.tree_view", BI.TreeView);
+}
+
diff --git a/src/core/platform/web/index.js b/src/core/platform/web/index.js
index db216134b..054b6dede 100644
--- a/src/core/platform/web/index.js
+++ b/src/core/platform/web/index.js
@@ -1,4 +1,3 @@
-export * as DOM from "./dom";
export * from "./detectElementResize";
export * from "./function";
export * from "./load";
diff --git a/src/core/platform/web/jquery/jquery.mousewheel.js b/src/core/platform/web/jquery/jquery.mousewheel.js
index 557fe35e4..576658a56 100644
--- a/src/core/platform/web/jquery/jquery.mousewheel.js
+++ b/src/core/platform/web/jquery/jquery.mousewheel.js
@@ -1,3 +1,4 @@
+/* eslint-disable */
/* !
* jQuery Mousewheel 3.1.13
*
@@ -21,15 +22,15 @@
// }
}(function ($) {
- var toFix = ["wheel", "mousewheel", "DOMMouseScroll", "MozMousePixelScroll"],
- toBind = ( "onwheel" in document || document.documentMode >= 9 ) ?
+ var toFix = ["wheel", "mousewheel", "DOMMouseScroll", "MozMousePixelScroll"],
+ toBind = ("onwheel" in document || document.documentMode >= 9) ?
["wheel"] : ["mousewheel", "DomMouseScroll", "MozMousePixelScroll"],
- slice = Array.prototype.slice,
+ slice = Array.prototype.slice,
nullLowestDeltaTimeout, lowestDelta;
- if ( $.event.fixHooks ) {
- for ( var i = toFix.length; i; ) {
- $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
+ if ($.event.fixHooks) {
+ for (var i = toFix.length; i;) {
+ $.event.fixHooks[toFix[--i]] = $.event.mouseHooks;
}
}
@@ -37,9 +38,9 @@
version: "3.1.12",
setup: function () {
- if ( this.addEventListener ) {
- for ( var i = toBind.length; i; ) {
- this.addEventListener( toBind[--i], handler, false );
+ if (this.addEventListener) {
+ for (var i = toBind.length; i;) {
+ this.addEventListener(toBind[--i], handler, false);
}
} else {
this.onmousewheel = handler;
@@ -47,9 +48,9 @@
},
teardown: function () {
- if ( this.removeEventListener ) {
- for ( var i = toBind.length; i; ) {
- this.removeEventListener( toBind[--i], handler, false );
+ if (this.removeEventListener) {
+ for (var i = toBind.length; i;) {
+ this.removeEventListener(toBind[--i], handler, false);
}
} else {
this.onmousewheel = null;
@@ -73,26 +74,34 @@
});
- function handler (event) {
- var orgEvent = event || _global.event,
- args = slice.call(arguments, 1),
- delta = 0,
- deltaX = 0,
- deltaY = 0,
- absDelta = 0,
- offsetX = 0,
- offsetY = 0;
+ function handler(event) {
+ var orgEvent = event || _global.event,
+ args = slice.call(arguments, 1),
+ delta = 0,
+ deltaX = 0,
+ deltaY = 0,
+ absDelta = 0,
+ offsetX = 0,
+ offsetY = 0;
event = $.event.fix(orgEvent);
event.type = "mousewheel";
// Old school scrollwheel delta
- if ( "detail" in orgEvent ) { deltaY = orgEvent.detail * -1; }
- if ( "wheelDelta" in orgEvent ) { deltaY = orgEvent.wheelDelta; }
- if ( "wheelDeltaY" in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
- if ( "wheelDeltaX" in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
+ if ("detail" in orgEvent) {
+ deltaY = orgEvent.detail * -1;
+ }
+ if ("wheelDelta" in orgEvent) {
+ deltaY = orgEvent.wheelDelta;
+ }
+ if ("wheelDeltaY" in orgEvent) {
+ deltaY = orgEvent.wheelDeltaY;
+ }
+ if ("wheelDeltaX" in orgEvent) {
+ deltaX = orgEvent.wheelDeltaX * -1;
+ }
// Firefox < 17 horizontal scrolling related to DOMMouseScroll event
- if ( "axis" in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
+ if ("axis" in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS) {
deltaX = deltaY * -1;
deltaY = 0;
}
@@ -101,62 +110,66 @@
delta = deltaY === 0 ? deltaX : deltaY;
// New school wheel delta (wheel event)
- if ( "deltaY" in orgEvent ) {
+ if ("deltaY" in orgEvent) {
deltaY = orgEvent.deltaY * -1;
- delta = deltaY;
+ delta = deltaY;
}
- if ( "deltaX" in orgEvent ) {
+ if ("deltaX" in orgEvent) {
deltaX = orgEvent.deltaX;
- if ( deltaY === 0 ) { delta = deltaX * -1; }
+ if (deltaY === 0) {
+ delta = deltaX * -1;
+ }
}
// No change actually happened, no reason to go any further
- if ( deltaY === 0 && deltaX === 0 ) { return; }
+ if (deltaY === 0 && deltaX === 0) {
+ return;
+ }
// Need to convert lines and pages to pixels if we aren't already in pixels
// There are three delta modes:
// * deltaMode 0 is by pixels, nothing to do
// * deltaMode 1 is by lines
// * deltaMode 2 is by pages
- if ( orgEvent.deltaMode === 1 ) {
+ if (orgEvent.deltaMode === 1) {
var lineHeight = 40;
- delta *= lineHeight;
+ delta *= lineHeight;
deltaY *= lineHeight;
deltaX *= lineHeight;
- } else if ( orgEvent.deltaMode === 2 ) {
+ } else if (orgEvent.deltaMode === 2) {
var pageHeight = 800;
- delta *= pageHeight;
+ delta *= pageHeight;
deltaY *= pageHeight;
deltaX *= pageHeight;
}
// Store lowest absolute delta to normalize the delta values
- absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
+ absDelta = Math.max(Math.abs(deltaY), Math.abs(deltaX));
- if ( !lowestDelta || absDelta < lowestDelta ) {
+ if (!lowestDelta || absDelta < lowestDelta) {
lowestDelta = absDelta;
// Adjust older deltas if necessary
- if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
+ if (shouldAdjustOldDeltas(orgEvent, absDelta)) {
lowestDelta /= 40;
}
}
// Adjust older deltas if necessary
- if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
+ if (shouldAdjustOldDeltas(orgEvent, absDelta)) {
// Divide all the things by 40!
- delta /= 40;
+ delta /= 40;
deltaX /= 40;
deltaY /= 40;
}
// Get a whole, normalized value for the deltas
- delta = Math[ delta >= 1 ? "floor" : "ceil" ](delta / lowestDelta);
- deltaX = Math[ deltaX >= 1 ? "floor" : "ceil" ](deltaX / lowestDelta);
- deltaY = Math[ deltaY >= 1 ? "floor" : "ceil" ](deltaY / lowestDelta);
+ delta = Math[delta >= 1 ? "floor" : "ceil"](delta / lowestDelta);
+ deltaX = Math[deltaX >= 1 ? "floor" : "ceil"](deltaX / lowestDelta);
+ deltaY = Math[deltaY >= 1 ? "floor" : "ceil"](deltaY / lowestDelta);
// Normalise offsetX and offsetY properties
- if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {
+ if (special.settings.normalizeOffset && this.getBoundingClientRect) {
var boundingRect = this.getBoundingClientRect();
offsetX = event.clientX - boundingRect.left;
offsetY = event.clientY - boundingRect.top;
@@ -180,17 +193,19 @@
// handle multiple device types that give different
// a different lowestDelta
// Ex: trackpad = 3 and mouse wheel = 120
- if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
+ if (nullLowestDeltaTimeout) {
+ clearTimeout(nullLowestDeltaTimeout);
+ }
nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
return ($.event.dispatch || $.event.handle).apply(this, args);
}
- function nullLowestDelta () {
+ function nullLowestDelta() {
lowestDelta = null;
}
- function shouldAdjustOldDeltas (orgEvent, absDelta) {
+ function shouldAdjustOldDeltas(orgEvent, absDelta) {
// If this is an older event and the delta is divisable by 120,
// then we are assuming that the browser is treating this as an
// older mouse wheel event and that we should divide the deltas
@@ -201,4 +216,4 @@
return special.settings.adjustOldDeltas && orgEvent.type === "mousewheel" && absDelta % 120 === 0;
}
-}));
\ No newline at end of file
+}));
diff --git a/src/core/utils/color.js b/src/core/utils/color.js
index a219a4f7d..718a9e74b 100644
--- a/src/core/utils/color.js
+++ b/src/core/utils/color.js
@@ -1,204 +1,206 @@
import { parseInt, parseFloat, isNull, isKey } from "../2.base";
-import * as DOMUtils from "../platform/web/dom";
-
-export const DOM = {
- isColor(color) {
- return color && (this.isRGBColor(color) || this.isHexColor(color));
- },
-
- isRGBColor(color) {
- if (!color) {
- return false;
- }
-
- return color.substr(0, 3) === "rgb";
- },
-
- isHexColor(color) {
- if (!color) {
- return false;
- }
-
- return color[0] === "#" && color.length === 7;
- },
-
- isDarkColor(hex) {
- if (!hex || !this.isHexColor(hex)) {
- return false;
- }
- const rgb = this.rgb2json(this.hex2rgb(hex));
- const grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114);
- if (grayLevel < 192/** 网上给的是140**/) {
- return true;
- }
-
+
+export function isColor(color) {
+ return color && (isRGBColor(color) || isHexColor(color));
+}
+
+export function isRGBColor(color) {
+ if (!color) {
+ return false;
+ }
+
+ return color.substr(0, 3) === "rgb";
+}
+
+export function isHexColor(color) {
+ if (!color) {
return false;
- },
-
- // 获取对比颜色
- getContrastColor(color) {
- if (!color || !this.isColor(color)) {
- return "";
- }
- if (this.isDarkColor(color)) {
- return "#FFFFFF";
- }
-
- return "#3D4D66";
- },
-
- rgb2hex(rgbColour) {
- if (!rgbColour || rgbColour.substr(0, 3) !== "rgb") {
- return "";
- }
- const rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
- const red = parseInt(rgbValues[0]);
- const green = parseInt(rgbValues[1]);
- const blue = parseInt(rgbValues[2]);
-
- const hexColour = `#${this.int2hex(red)}${this.int2hex(green)}${this.int2hex(blue)}`;
-
- return hexColour;
- },
-
- _hue2rgb(m1, m2, h) {
- h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
- if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
- if (h * 2 < 1) return m2;
- if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
-
- return m1;
- },
-
- hsl2rgb(hsl) {
- const h = hsl[0], s = hsl[1], l = hsl[2];
- const m2 = (l <= 0.5) ? l * (s + 1) : l + s - l * s;
- const m1 = l * 2 - m2;
-
- return [this._hue2rgb(m1, m2, h + 0.33333),
- this._hue2rgb(m1, m2, h),
- this._hue2rgb(m1, m2, h - 0.33333)];
- },
-
- rgb2hsl(rgb) {
- let h, s;
- const r = rgb[0], g = rgb[1], b = rgb[2];
- const min = Math.min(r, Math.min(g, b));
- const max = Math.max(r, Math.max(g, b));
- const delta = max - min;
- const l = (min + max) / 2;
- s = 0;
- if (l > 0 && l < 1) {
- s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
- }
- h = 0;
- if (delta > 0) {
- if (max === r && max !== g) h += (g - b) / delta;
- if (max === g && max !== b) h += (2 + (b - r) / delta);
- if (max === b && max !== r) h += (4 + (r - g) / delta);
- h /= 6;
- }
-
- return [h, s, l];
- },
-
- rgb2json(rgbColour) {
- if (!rgbColour) {
- return {};
- }
- if (!this.isRGBColor(rgbColour)) {
- return {};
- }
- const rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
-
- return {
- r: parseInt(rgbValues[0]),
- g: parseInt(rgbValues[1]),
- b: parseInt(rgbValues[2]),
- };
- },
-
- rgba2json(rgbColour) {
- if (!rgbColour) {
- return {};
- }
- const rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
-
- return {
- r: parseInt(rgbValues[0]),
- g: parseInt(rgbValues[1]),
- b: parseInt(rgbValues[2]),
- a: parseFloat(rgbValues[3]),
- };
- },
-
- json2rgb(rgb) {
- if (!isKey(rgb.r) || !isKey(rgb.g) || !isKey(rgb.b)) {
- return "";
- }
-
- return `rgb(${rgb.r},${rgb.g},${rgb.b})`;
- },
-
- json2rgba(rgba) {
- if (!isKey(rgba.r) || !isKey(rgba.g) || !isKey(rgba.b)) {
- return "";
- }
-
- return `rgba(${rgba.r},${rgba.g},${rgba.b},${rgba.a})`;
- },
-
- int2hex(strNum) {
- const hexdig = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
-
- return `${hexdig[strNum >>> 4]}${hexdig[strNum & 15]}`;
- },
-
- hex2rgb(color) {
- if (!color) {
- return "";
- }
- if (!this.isHexColor(color)) {
- return color;
- }
- let tempValue = "rgb(", colorArray;
-
- if (color.length === 7) {
- colorArray = [parseInt(`0x${color.substring(1, 3)}`),
- parseInt(`0x${color.substring(3, 5)}`),
- parseInt(`0x${color.substring(5, 7)}`)];
- } else if (color.length === 4) {
- colorArray = [parseInt(`0x${color.substring(1, 2)}`),
- parseInt(`0x${color.substring(2, 3)}`),
- parseInt(`0x${color.substring(3, 4)}`)];
- }
- tempValue += `${colorArray[0]},`;
- tempValue += `${colorArray[1]},`;
- tempValue += `${colorArray[2]})`;
-
- return tempValue;
- },
-
- rgba2rgb(rgbColor, bgColor) {
- if (isNull(bgColor)) {
- bgColor = 1;
- }
- if (rgbColor.substr(0, 4) !== "rgba") {
- return "";
- }
- const rgbValues = rgbColor.match(/\d+(\.\d+)?/g);
- if (rgbValues.length < 4) {
- return "";
- }
- const R = parseFloat(rgbValues[0]);
- const G = parseFloat(rgbValues[1]);
- const B = parseFloat(rgbValues[2]);
- const A = parseFloat(rgbValues[3]);
-
- return `rgb(${Math.floor(255 * (bgColor * (1 - A)) + R * A)},${
- Math.floor(255 * (bgColor * (1 - A)) + G * A)},${
- Math.floor(255 * (bgColor * (1 - A)) + B * A)})`;
- },
-
- ...DOMUtils,
-};
+ }
+
+ return color[0] === "#" && color.length === 7;
+}
+
+export function isDarkColor(hex) {
+ if (!hex || !isHexColor(hex)) {
+ return false;
+ }
+ const rgb = rgb2json(hex2rgb(hex));
+ const grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114);
+ if (grayLevel < 192/** 网上给的是140**/) {
+ return true;
+ }
+
+ return false;
+}
+
+// 获取对比颜色
+export function getContrastColor(color) {
+ if (!color || !isColor(color)) {
+ return "";
+ }
+ if (isDarkColor(color)) {
+ return "#FFFFFF";
+ }
+
+ return "#3D4D66";
+}
+
+export function rgb2hex(rgbColour) {
+ if (!rgbColour || rgbColour.substr(0, 3) !== "rgb") {
+ return "";
+ }
+ const rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
+ const red = parseInt(rgbValues[0]);
+ const green = parseInt(rgbValues[1]);
+ const blue = parseInt(rgbValues[2]);
+
+ const hexColour = `#${int2hex(red)}${int2hex(green)}${int2hex(blue)}`;
+
+ return hexColour;
+}
+
+function _hue2rgb(m1, m2, h) {
+ h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
+ if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
+ if (h * 2 < 1) return m2;
+ if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
+
+ return m1;
+}
+
+export function hsl2rgb(hsl) {
+ const h = hsl[0], s = hsl[1], l = hsl[2];
+ const m2 = (l <= 0.5) ? l * (s + 1) : l + s - l * s;
+ const m1 = l * 2 - m2;
+
+ return [
+ _hue2rgb(m1, m2, h + 0.33333),
+ _hue2rgb(m1, m2, h),
+ _hue2rgb(m1, m2, h - 0.33333)
+ ];
+}
+
+export function rgb2hsl(rgb) {
+ let h, s;
+ const r = rgb[0], g = rgb[1], b = rgb[2];
+ const min = Math.min(r, Math.min(g, b));
+ const max = Math.max(r, Math.max(g, b));
+ const delta = max - min;
+ const l = (min + max) / 2;
+ s = 0;
+ if (l > 0 && l < 1) {
+ s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
+ }
+ h = 0;
+ if (delta > 0) {
+ if (max === r && max !== g) h += (g - b) / delta;
+ if (max === g && max !== b) h += (2 + (b - r) / delta);
+ if (max === b && max !== r) h += (4 + (r - g) / delta);
+ h /= 6;
+ }
+
+ return [h, s, l];
+}
+
+export function rgb2json(rgbColour) {
+ if (!rgbColour) {
+ return {};
+ }
+ if (!isRGBColor(rgbColour)) {
+ return {};
+ }
+ const rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
+
+ return {
+ r: parseInt(rgbValues[0]),
+ g: parseInt(rgbValues[1]),
+ b: parseInt(rgbValues[2]),
+ };
+}
+
+export function rgba2json(rgbColour) {
+ if (!rgbColour) {
+ return {};
+ }
+ const rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
+
+ return {
+ r: parseInt(rgbValues[0]),
+ g: parseInt(rgbValues[1]),
+ b: parseInt(rgbValues[2]),
+ a: parseFloat(rgbValues[3]),
+ };
+}
+
+export function json2rgb(rgb) {
+ if (!isKey(rgb.r) || !isKey(rgb.g) || !isKey(rgb.b)) {
+ return "";
+ }
+
+ return `rgb(${rgb.r},${rgb.g},${rgb.b})`;
+}
+
+export function json2rgba(rgba) {
+ if (!isKey(rgba.r) || !isKey(rgba.g) || !isKey(rgba.b)) {
+ return "";
+ }
+
+ return `rgba(${rgba.r},${rgba.g},${rgba.b},${rgba.a})`;
+}
+
+export function int2hex(strNum) {
+ const hexdig = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
+
+ return `${hexdig[strNum >>> 4]}${hexdig[strNum & 15]}`;
+}
+
+export function hex2rgb(color) {
+ if (!color) {
+ return "";
+ }
+ if (!isHexColor(color)) {
+ return color;
+ }
+ let tempValue = "rgb(", colorArray;
+
+ if (color.length === 7) {
+ colorArray = [
+ parseInt(`0x${color.substring(1, 3)}`),
+ parseInt(`0x${color.substring(3, 5)}`),
+ parseInt(`0x${color.substring(5, 7)}`)
+ ];
+ } else if (color.length === 4) {
+ colorArray = [
+ parseInt(`0x${color.substring(1, 2)}`),
+ parseInt(`0x${color.substring(2, 3)}`),
+ parseInt(`0x${color.substring(3, 4)}`)
+ ];
+ }
+ tempValue += `${colorArray[0]},`;
+ tempValue += `${colorArray[1]},`;
+ tempValue += `${colorArray[2]})`;
+
+ return tempValue;
+}
+
+export function rgba2rgb(rgbColor, bgColor) {
+ if (isNull(bgColor)) {
+ bgColor = 1;
+ }
+ if (rgbColor.substr(0, 4) !== "rgba") {
+ return "";
+ }
+ const rgbValues = rgbColor.match(/\d+(\.\d+)?/g);
+ if (rgbValues.length < 4) {
+ return "";
+ }
+ const R = parseFloat(rgbValues[0]);
+ const G = parseFloat(rgbValues[1]);
+ const B = parseFloat(rgbValues[2]);
+ const A = parseFloat(rgbValues[3]);
+
+ return `rgb(${Math.floor(255 * (bgColor * (1 - A)) + R * A)},${
+ Math.floor(255 * (bgColor * (1 - A)) + G * A)},${
+ Math.floor(255 * (bgColor * (1 - A)) + B * A)})`;
+}
+
diff --git a/src/core/platform/web/dom.js b/src/core/utils/dom.js
similarity index 73%
rename from src/core/platform/web/dom.js
rename to src/core/utils/dom.js
index 1fca2871b..c356b9b50 100644
--- a/src/core/platform/web/dom.js
+++ b/src/core/utils/dom.js
@@ -1,7 +1,7 @@
/**
* 对DOM操作的通用函数
*/
-import { each, isEmpty, isNull } from "../../2.base";
+import { each, isEmpty, isNull } from "../2.base";
export function ready(fn) {
BI.Widget._renderEngine.createElement(document).ready(fn);
@@ -502,208 +502,208 @@ export function getComboPositionByDirections(combo, popup, extraWidth, extraHeig
for (i = 0; i < directions.length; i++) {
direct = directions[i];
switch (direct) {
- case "left":
- leftRight.push(direct);
- break;
- case "right":
- leftRight.push(direct);
- break;
- case "top":
- topBottom.push(direct);
- break;
- case "bottom":
- topBottom.push(direct);
- break;
- case "innerLeft":
- innerLeftRight.push(direct);
- break;
- case "innerRight":
- innerLeftRight.push(direct);
- break;
- default:
- break;
+ case "left":
+ leftRight.push(direct);
+ break;
+ case "right":
+ leftRight.push(direct);
+ break;
+ case "top":
+ topBottom.push(direct);
+ break;
+ case "bottom":
+ topBottom.push(direct);
+ break;
+ case "innerLeft":
+ innerLeftRight.push(direct);
+ break;
+ case "innerRight":
+ innerLeftRight.push(direct);
+ break;
+ default:
+ break;
}
}
for (i = 0; i < directions.length; i++) {
let tW, tH;
direct = directions[i];
switch (direct) {
- case "left":
- if (!isNeedAdaptHeight) {
- tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight;
- if (isLeftSpaceEnough(combo, popup, tW)) {
- left = getLeftPosition(combo, popup, tW, container).left;
- if (topBottom[0] === "bottom") {
- pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight, container);
- } else {
- pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight, container);
+ case "left":
+ if (!isNeedAdaptHeight) {
+ tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight;
+ if (isLeftSpaceEnough(combo, popup, tW)) {
+ left = getLeftPosition(combo, popup, tW, container).left;
+ if (topBottom[0] === "bottom") {
+ pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight, container);
+ } else {
+ pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight, container);
+ }
+ pos.dir = `left,${pos.dir}`;
+ if (tbFirst) {
+ pos.change = "left";
+ }
+ pos.left = left;
+
+ return pos;
}
- pos.dir = `left,${pos.dir}`;
- if (tbFirst) {
- pos.change = "left";
+ }
+ lrFirst = true;
+ break;
+ case "right":
+ if (!isNeedAdaptHeight) {
+ tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight;
+ if (isRightSpaceEnough(combo, popup, tW)) {
+ left = getRightPosition(combo, popup, tW, container).left;
+ if (topBottom[0] === "bottom") {
+ pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight, container);
+ } else {
+ pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight, container);
+ }
+ pos.dir = `right,${pos.dir}`;
+ if (tbFirst) {
+ pos.change = "right";
+ }
+ pos.left = left;
+
+ return pos;
}
- pos.left = left;
-
- return pos;
}
- }
- lrFirst = true;
- break;
- case "right":
- if (!isNeedAdaptHeight) {
- tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight;
- if (isRightSpaceEnough(combo, popup, tW)) {
- left = getRightPosition(combo, popup, tW, container).left;
- if (topBottom[0] === "bottom") {
- pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight, container);
+ lrFirst = true;
+ break;
+ case "top":
+ tW = lrFirst ? extraHeight : extraWidth, tH = lrFirst ? extraWidth : extraHeight;
+ if (isTopSpaceEnough(combo, popup, tH)) {
+ top = getTopPosition(combo, popup, tH, container).top;
+ if (leftRight[0] === "right") {
+ pos = getLeftAlignPosition(combo, popup, tW, container);
} else {
- pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight, container);
+ pos = getRightAlignPosition(combo, popup, tW, container);
}
- pos.dir = `right,${pos.dir}`;
- if (tbFirst) {
- pos.change = "right";
+ pos.dir = `top,${pos.dir}`;
+ if (lrFirst) {
+ pos.change = "top";
}
- pos.left = left;
+ pos.top = top;
return pos;
}
- }
- lrFirst = true;
- break;
- case "top":
- tW = lrFirst ? extraHeight : extraWidth, tH = lrFirst ? extraWidth : extraHeight;
- if (isTopSpaceEnough(combo, popup, tH)) {
- top = getTopPosition(combo, popup, tH, container).top;
- if (leftRight[0] === "right") {
- pos = getLeftAlignPosition(combo, popup, tW, container);
- } else {
- pos = getRightAlignPosition(combo, popup, tW, container);
- }
- pos.dir = `top,${pos.dir}`;
- if (lrFirst) {
- pos.change = "top";
+ if (needAdaptHeight) {
+ isNeedAdaptHeight = true;
}
- pos.top = top;
-
- return pos;
- }
- if (needAdaptHeight) {
- isNeedAdaptHeight = true;
- }
- tbFirst = true;
- break;
- case "bottom":
- tW = lrFirst ? extraHeight : extraWidth, tH = lrFirst ? extraWidth : extraHeight;
- if (isBottomSpaceEnough(combo, popup, tH)) {
- top = getBottomPosition(combo, popup, tH, container).top;
- if (leftRight[0] === "right") {
- pos = getLeftAlignPosition(combo, popup, tW, container);
- } else {
- pos = getRightAlignPosition(combo, popup, tW, container);
- }
- pos.dir = `bottom,${pos.dir}`;
- if (lrFirst) {
- pos.change = "bottom";
- }
- pos.top = top;
-
- return pos;
- }
- if (needAdaptHeight) {
- isNeedAdaptHeight = true;
- }
- tbFirst = true;
- break;
- case "innerLeft":
- if (!isNeedAdaptHeight) {
- tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight;
- if (isInnerLeftSpaceEnough(combo, popup, tW)) {
- left = getInnerLeftPosition(combo, popup, tW).left;
- if (topBottom[0] === "bottom") {
- pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight);
+ tbFirst = true;
+ break;
+ case "bottom":
+ tW = lrFirst ? extraHeight : extraWidth, tH = lrFirst ? extraWidth : extraHeight;
+ if (isBottomSpaceEnough(combo, popup, tH)) {
+ top = getBottomPosition(combo, popup, tH, container).top;
+ if (leftRight[0] === "right") {
+ pos = getLeftAlignPosition(combo, popup, tW, container);
} else {
- pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight);
+ pos = getRightAlignPosition(combo, popup, tW, container);
}
- pos.dir = `innerLeft,${pos.dir}`;
- if (tbFirst) {
- pos.change = "innerLeft";
+ pos.dir = `bottom,${pos.dir}`;
+ if (lrFirst) {
+ pos.change = "bottom";
}
- pos.left = left;
+ pos.top = top;
return pos;
}
- }
- lrFirst = true;
- break;
- case "innerRight":
- if (!isNeedAdaptHeight) {
- tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight;
- if (isInnerRightSpaceEnough(combo, popup, tW)) {
- left = getInnerRightPosition(combo, popup, tW).left;
- if (topBottom[0] === "bottom") {
- pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight);
- } else {
- pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight);
+ if (needAdaptHeight) {
+ isNeedAdaptHeight = true;
+ }
+ tbFirst = true;
+ break;
+ case "innerLeft":
+ if (!isNeedAdaptHeight) {
+ tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? 0 : extraHeight;
+ if (isInnerLeftSpaceEnough(combo, popup, tW)) {
+ left = getInnerLeftPosition(combo, popup, tW).left;
+ if (topBottom[0] === "bottom") {
+ pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight);
+ } else {
+ pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight);
+ }
+ pos.dir = `innerLeft,${pos.dir}`;
+ if (tbFirst) {
+ pos.change = "innerLeft";
+ }
+ pos.left = left;
+
+ return pos;
}
- pos.dir = `innerLeft,${pos.dir}`;
- if (tbFirst) {
- pos.change = "innerRight";
+ }
+ lrFirst = true;
+ break;
+ case "innerRight":
+ if (!isNeedAdaptHeight) {
+ tW = tbFirst ? extraHeight : extraWidth, tH = tbFirst ? extraWidth : extraHeight;
+ if (isInnerRightSpaceEnough(combo, popup, tW)) {
+ left = getInnerRightPosition(combo, popup, tW).left;
+ if (topBottom[0] === "bottom") {
+ pos = getTopAlignPosition(combo, popup, tH, needAdaptHeight);
+ } else {
+ pos = getBottomAlignPosition(combo, popup, tH, needAdaptHeight);
+ }
+ pos.dir = `innerLeft,${pos.dir}`;
+ if (tbFirst) {
+ pos.change = "innerRight";
+ }
+ pos.left = left;
+
+ return pos;
}
- pos.left = left;
-
- return pos;
}
- }
- break;
- default:
- break;
+ break;
+ default:
+ break;
}
}
// 此处为四个方向放不下时挑空间最大的方向去放置, 也就是说我设置了弹出方向为"bottom,left",
// 最后发现实际弹出方向可能是"top,left",那么此时外界获取popup的方向应该是"top,left"
switch (directions[0]) {
- case "left":
- case "right":
- if (isRightSpaceLarger(combo)) {
- left = getRightAdaptPosition(combo, popup, extraWidth, container).left;
- firstDir = "right";
- } else {
- left = getLeftAdaptPosition(combo, popup, extraWidth, container).left;
- firstDir = "left";
- }
- if (topBottom[0] === "bottom") {
- pos = getTopAlignPosition(combo, popup, extraHeight, needAdaptHeight);
+ case "left":
+ case "right":
+ if (isRightSpaceLarger(combo)) {
+ left = getRightAdaptPosition(combo, popup, extraWidth, container).left;
+ firstDir = "right";
+ } else {
+ left = getLeftAdaptPosition(combo, popup, extraWidth, container).left;
+ firstDir = "left";
+ }
+ if (topBottom[0] === "bottom") {
+ pos = getTopAlignPosition(combo, popup, extraHeight, needAdaptHeight);
+ pos.left = left;
+ pos.dir = `${firstDir},${pos.dir}`;
+
+ return pos;
+ }
+ pos = getBottomAlignPosition(combo, popup, extraHeight, needAdaptHeight);
pos.left = left;
pos.dir = `${firstDir},${pos.dir}`;
return pos;
- }
- pos = getBottomAlignPosition(combo, popup, extraHeight, needAdaptHeight);
- pos.left = left;
- pos.dir = `${firstDir},${pos.dir}`;
-
- return pos;
- default :
- if (isBottomSpaceLarger(combo)) {
- top = getBottomAdaptPosition(combo, popup, extraHeight, needAdaptHeight, container).top;
- firstDir = "bottom";
- } else {
- top = getTopAdaptPosition(combo, popup, extraHeight, needAdaptHeight, container).top;
- firstDir = "top";
- }
- if (leftRight[0] === "right") {
- pos = getLeftAlignPosition(combo, popup, extraWidth, container);
+ default :
+ if (isBottomSpaceLarger(combo)) {
+ top = getBottomAdaptPosition(combo, popup, extraHeight, needAdaptHeight, container).top;
+ firstDir = "bottom";
+ } else {
+ top = getTopAdaptPosition(combo, popup, extraHeight, needAdaptHeight, container).top;
+ firstDir = "top";
+ }
+ if (leftRight[0] === "right") {
+ pos = getLeftAlignPosition(combo, popup, extraWidth, container);
+ pos.top = top;
+ pos.dir = `${firstDir},${pos.dir}`;
+
+ return pos;
+ }
+ pos = getRightAlignPosition(combo, popup, extraWidth, container);
pos.top = top;
pos.dir = `${firstDir},${pos.dir}`;
return pos;
- }
- pos = getRightAlignPosition(combo, popup, extraWidth, container);
- pos.top = top;
- pos.dir = `${firstDir},${pos.dir}`;
-
- return pos;
}
}
@@ -716,26 +716,26 @@ export function getComboPosition(combo, popup, extraWidth, extraHeight, needAdap
popup.resetHeight && popup.resetHeight(maxHeight);
const position = getComboPositionByDirections(combo, popup, extraWidth, extraHeight, needAdaptHeight, directions || ["bottom", "top", "right", "left"], positionRelativeElement);
switch (offsetStyle) {
- case "center":
- if (position.change) {
- const p = getMiddleAdaptPosition(combo, popup, positionRelativeElement);
- position.top = p.top;
- } else {
- const p = getCenterAdaptPosition(combo, popup, positionRelativeElement);
- position.left = p.left;
- }
- break;
- case "middle":
- if (position.change) {
- const p = getCenterAdaptPosition(combo, popup, positionRelativeElement);
- position.left = p.left;
- } else {
- const p = getMiddleAdaptPosition(combo, popup, positionRelativeElement);
- position.top = p.top;
- }
- break;
- default:
- break;
+ case "center":
+ if (position.change) {
+ const p = getMiddleAdaptPosition(combo, popup, positionRelativeElement);
+ position.top = p.top;
+ } else {
+ const p = getCenterAdaptPosition(combo, popup, positionRelativeElement);
+ position.left = p.left;
+ }
+ break;
+ case "middle":
+ if (position.change) {
+ const p = getCenterAdaptPosition(combo, popup, positionRelativeElement);
+ position.left = p.left;
+ } else {
+ const p = getMiddleAdaptPosition(combo, popup, positionRelativeElement);
+ position.top = p.top;
+ }
+ break;
+ default:
+ break;
}
if (needAdaptHeight === true) {
popup.resetHeight && popup.resetHeight(Math.min(viewportBounds.height - position.top - (positionRelativeElement ? positionRelativeElement.getBoundingClientRect().top : 0), maxHeight));
diff --git a/src/core/utils/index.js b/src/core/utils/index.js
index 059be17e4..0937fcd71 100644
--- a/src/core/utils/index.js
+++ b/src/core/utils/index.js
@@ -1,4 +1,12 @@
export * from "./events";
export * from "./i18n";
export { makeFirstPY } from "./chinesePY";
-export { DOM } from "./color";
+
+import * as platformDom from "./dom";
+import * as colorDom from "./color";
+
+
+export const DOM = {
+ ...platformDom,
+ ...colorDom
+};