antd-color-editor
Version:
An open-source color editor for designing color system
349 lines (347 loc) • 13.4 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name2 in all)
__defProp(target, name2, { get: all[name2], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/genScalesByConfig/index.tsx
var genScalesByConfig_exports = {};
__export(genScalesByConfig_exports, {
advanceConfig: () => advanceConfig,
cacheEditorConfig: () => cacheEditorConfig,
colorConfig: () => colorConfig,
colorTypes: () => colorTypes,
defineGenerateConfig: () => defineGenerateConfig,
displayConfig: () => displayConfig,
editConfig: () => editConfig,
genScales: () => genScales,
genScalesByConfig: () => genScalesByConfig,
getCacheEditorConfig: () => getCacheEditorConfig,
hueConfig: () => hueConfig,
neutralAdvanceConfig: () => neutralAdvanceConfig,
neutralConfig: () => neutralConfig,
patternConfig: () => patternConfig,
setForceConfig: () => setForceConfig,
stepConfig: () => stepConfig,
threeConfig: () => threeConfig,
tokenConfig: () => tokenConfig
});
module.exports = __toCommonJS(genScalesByConfig_exports);
var import_plugin_bezier = require("@leva-ui/plugin-bezier");
var import_react_icons = require("@radix-ui/react-icons");
var import_leva = require("leva");
var import_lodash_es = require("lodash-es");
var import__ = require("../index");
var import_defaultConfig = require("./defaultConfig");
__reExport(genScalesByConfig_exports, require("./defaultConfig"), module.exports);
var getCacheEditorConfig = () => {
const localConfig = localStorage.getItem("antd-color-config");
const cacheConfig = localConfig ? (0, import_lodash_es.merge)(import_defaultConfig.defaultEditorConfig, JSON.parse(localConfig).data) : import_defaultConfig.defaultEditorConfig;
return cacheConfig;
};
var setForceConfig = (forceConfig) => {
var _a;
if (((_a = forceConfig == null ? void 0 : forceConfig.data) == null ? void 0 : _a.generate) && (forceConfig == null ? void 0 : forceConfig.time) && (forceConfig == null ? void 0 : forceConfig.name)) {
let localConfig = localStorage.getItem("antd-color-config");
if (localConfig) {
localConfig = JSON.parse(localConfig);
if ((localConfig == null ? void 0 : localConfig.name) === name)
return;
}
localStorage.setItem("antd-color-config", JSON.stringify(forceConfig));
}
};
var cacheEditorConfig = getCacheEditorConfig();
var defineColorConfig = (defaultColorConfig) => ({
cTarget: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.BlendingModeIcon, null), title: "色度目标" }),
max: 120,
min: 1,
step: 1,
value: defaultColorConfig.cTarget
},
hRotate: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.ColorWheelIcon, null), title: "色相旋转" }),
max: 360,
min: -360,
step: 1,
value: defaultColorConfig.hRotate
},
tTarget: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.ShadowIcon, null), title: "明度目标" }),
max: 100,
min: 1,
step: 1,
value: defaultColorConfig.tTarget
}
});
var colorConfig = {
darkDown: defineColorConfig(cacheEditorConfig.generate.dark.down),
darkUp: defineColorConfig(cacheEditorConfig.generate.dark.up),
lightDown: defineColorConfig(cacheEditorConfig.generate.light.down),
lightUp: defineColorConfig(cacheEditorConfig.generate.light.up)
};
var defineAdvanceConfig = (defaultColorConfig) => ({
["明度曲线"]: (0, import_leva.folder)(
{
tEasing: (0, import_plugin_bezier.bezier)(defaultColorConfig.tEasing)
},
{ collapsed: true, color: "#8c92a4" }
),
["色度曲线"]: (0, import_leva.folder)(
{
cEasing: (0, import_plugin_bezier.bezier)(defaultColorConfig.cEasing)
},
{ collapsed: true, color: "#8c92a4" }
),
["色相曲线"]: (0, import_leva.folder)(
{
hEasing: (0, import_plugin_bezier.bezier)(defaultColorConfig.hEasing)
},
{ collapsed: true, color: "#8c92a4" }
)
});
var advanceConfig = {
darkDown: defineAdvanceConfig(cacheEditorConfig.generate.dark.down),
darkUp: defineAdvanceConfig(cacheEditorConfig.generate.dark.up),
lightDown: defineAdvanceConfig(cacheEditorConfig.generate.light.down),
lightUp: defineAdvanceConfig(cacheEditorConfig.generate.light.up)
};
var hueConfig = {
multiply: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.AngleIcon, null), title: "补偿乘阶" }),
max: 1,
min: -1,
value: cacheEditorConfig.generate.hue.multiply
},
segment: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.ColorWheelIcon, null), title: "补偿区间" }),
max: 360,
min: 0,
step: 1,
value: cacheEditorConfig.generate.hue.segment
}
};
var neutralConfig = {
cStart: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.BlendingModeIcon, null), title: "色度标准" }),
max: 36,
min: 1,
step: 1,
value: cacheEditorConfig.generate.neutral.cStart
},
cTarget: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.BlendingModeIcon, null), title: "色度目标" }),
max: 36,
min: 1,
step: 1,
value: cacheEditorConfig.generate.neutral.cTarget
},
standard: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.OpacityIcon, null), title: "明度标准" }),
value: cacheEditorConfig.generate.neutral.standard
}
};
var neutralAdvanceConfig = {
["上梯度 色度曲线"]: (0, import_leva.folder)(
{
cEasingUp: (0, import_plugin_bezier.bezier)(cacheEditorConfig.generate.neutral.cEasingUp)
},
{ collapsed: true, color: "#8c92a4" }
),
["下梯度 色度曲线"]: (0, import_leva.folder)(
{
cEasingDown: (0, import_plugin_bezier.bezier)(cacheEditorConfig.generate.neutral.cEasingDown)
},
{ collapsed: true, color: "#8c92a4" }
)
};
var patternConfig = {
displayFliterStep: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.EyeNoneIcon, null), title: "只显示筛选后梯度" }),
render: (get) => get("isFliterStep"),
value: cacheEditorConfig.system.pattern.displayFliterStep
},
isFliterStep: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.HobbyKnifeIcon, null), title: "开启梯度筛选" }),
value: cacheEditorConfig.system.pattern.isFliterStep
},
isolateDark: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.ComponentBooleanIcon, null), title: "亮暗主色分离" }),
value: cacheEditorConfig.system.pattern.isolateDark
}
};
var stepConfig = {
down: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.PinBottomIcon, null), title: "向下梯度" }),
min: 1,
step: 1,
value: cacheEditorConfig.generate.step.down
},
up: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.PinTopIcon, null), title: "向上梯度" }),
min: 1,
step: 1,
value: cacheEditorConfig.generate.step.up
}
};
var editConfig = {
isolateEdit: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.ComponentBooleanIcon, null), title: "亮暗调节分离" }),
value: cacheEditorConfig.system.edit.isolateEdit
}
};
var colorTypes = ["mix", "hex", "hct", "rgb", "hsl", "hsv", "cts"];
var displayConfig = {
colorType: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.TokensIcon, null), title: "色彩空间" }),
options: colorTypes,
value: "hct"
},
showDetail: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.AspectRatioIcon, null), title: "详细模式" }),
value: true
}
};
var threeConfig = {
autoRotate: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.UpdateIcon, null), title: "自动旋转" }),
value: true
},
hueZoom: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.EyeNoneIcon, null), title: "色相缩放" }),
max: 10,
min: 1,
step: 1,
value: 3.6
},
showFloor: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.EyeNoneIcon, null), title: "显示辅助线" }),
value: true
},
threeZoom: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.TransformIcon, null), title: "模型尺寸" }),
max: 100,
min: 1,
step: 1,
value: 8
}
};
var tokenConfig = {
codeType: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.CodeIcon, null), title: "变量格式" }),
options: ["css", "less", "scss", "js"],
value: "css"
},
colorType: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.TokensIcon, null), title: "色彩空间" }),
options: ["mix", "hex", "rgb", "hsl"],
value: "mix"
},
isolateDarkToken: {
label: /* @__PURE__ */ React.createElement(import__.Label, { icon: /* @__PURE__ */ React.createElement(import_react_icons.ComponentBooleanIcon, null), title: "亮暗变量分离" }),
value: true
}
};
var defineGenerateConfig = ({
edit,
step,
hue,
neutral,
neutralAdvance,
lightUp,
lightUpAdvance,
lightDown,
lightDownAdvance,
darkUp,
darkUpAdvance,
darkDown,
darkDownAdvance
}) => {
const config = {
dark: {
down: edit.isolateEdit ? { ...darkDown, darkDownAdvance } : { ...lightUp, ...lightUpAdvance },
up: edit.isolateEdit ? { ...darkUp, ...darkUpAdvance } : { ...lightDown, ...lightDownAdvance }
},
hue,
light: {
down: { ...lightDown, ...lightDownAdvance },
up: { ...lightUp, ...lightUpAdvance }
},
neutral: { ...neutral, ...neutralAdvance },
step
};
return JSON.parse(JSON.stringify(config));
};
var genScales = (color, config) => {
const { system, stepFliter, generate } = config;
const { pattern } = system;
const scaleGeneration = new import__.GenerateScale(generate);
let scales = {
dark: scaleGeneration.gen(pattern.isolateDark ? color.darkColor : color.color, {
neutral: color.type === "neutral",
theme: "dark"
}),
light: scaleGeneration.gen(color.color, { neutral: color.type === "neutral", theme: "light" })
};
const rawScales = scales;
if (pattern.isFliterStep && pattern.displayFliterStep && (stepFliter == null ? void 0 : stepFliter.length) > 0) {
scales = {
dark: scales.dark.filter((_, index) => stepFliter.includes(index)),
light: scales.light.filter((_, index) => stepFliter.includes(index))
};
}
return {
color: rawScales.light[generate.step.up],
darkColor: rawScales.dark[generate.step.up],
scales
};
};
var genScalesByConfig = (config) => {
const { colorList, ...rest } = config;
const data = {};
for (const color of colorList) {
const { dark, light } = genScales(color, rest).scales;
data[color.id.toLowerCase()] = {
dark,
darkA: dark.map((c) => (0, import__.colorTypeFormat)((0, import__.getAlphaColor)(c, "#000"), "rgb")),
light,
lightA: light.map((c) => (0, import__.colorTypeFormat)((0, import__.getAlphaColor)(c, "#fff"), "rgb"))
};
}
return data;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
advanceConfig,
cacheEditorConfig,
colorConfig,
colorTypes,
defineGenerateConfig,
displayConfig,
editConfig,
genScales,
genScalesByConfig,
getCacheEditorConfig,
hueConfig,
neutralAdvanceConfig,
neutralConfig,
patternConfig,
setForceConfig,
stepConfig,
threeConfig,
tokenConfig,
...require("./defaultConfig")
});