UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

46 lines (45 loc) 1.46 kB
import { each, isArray } from "../../../../zrender/lib/core/util.mjs"; import { normalizeToArray } from "../../util/model.mjs"; var DEFAULT_TOOLBOX_BTNS = ["rect", "polygon", "keep", "clear"]; function brushPreprocessor(option, isNew) { var brushComponents = normalizeToArray(option ? option.brush : []); if (!brushComponents.length) { return; } var brushComponentSpecifiedBtns = []; each(brushComponents, function(brushOpt) { var tbs = brushOpt.hasOwnProperty("toolbox") ? brushOpt.toolbox : []; if (tbs instanceof Array) { brushComponentSpecifiedBtns = brushComponentSpecifiedBtns.concat(tbs); } }); var toolbox = option && option.toolbox; if (isArray(toolbox)) { toolbox = toolbox[0]; } if (!toolbox) { toolbox = { feature: {} }; option.toolbox = [toolbox]; } var toolboxFeature = toolbox.feature || (toolbox.feature = {}); var toolboxBrush = toolboxFeature.brush || (toolboxFeature.brush = {}); var brushTypes = toolboxBrush.type || (toolboxBrush.type = []); brushTypes.push.apply(brushTypes, brushComponentSpecifiedBtns); removeDuplicate(brushTypes); if (isNew && !brushTypes.length) { brushTypes.push.apply(brushTypes, DEFAULT_TOOLBOX_BTNS); } } function removeDuplicate(arr) { var map = {}; each(arr, function(val) { map[val] = 1; }); arr.length = 0; each(map, function(flag, val) { arr.push(val); }); } export { brushPreprocessor as default };