Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor(sheet): remove tiny color (#754)

Univer3a27cfe3b1fe
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 45c847c40b..5086cb7a74 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -67,7 +67,6 @@
"SUMIFS",
"Tahoma",
"TBRL",
- "tinycolor",
"undoredo",
"undos",
"unhine",
diff --git a/packages/core/src/shared/color/color-builder.ts b/packages/core/src/shared/color/color-builder.ts
deleted file mode 100644
index a852247d97..0000000000
--- a/packages/core/src/shared/color/color-builder.ts
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { Nullable } from '../../common/type-utils';
-import { ColorType, ThemeColors, ThemeColorType } from '../../types/enum';
-import type { Color } from './color';
-import { RgbColor, ThemeColor } from './color';
-
-export class ColorBuilder {
- private _themeValue: ThemeColorType = ThemeColorType.LIGHT1;
-
- private _themeColors: ThemeColors;
-
- private _themeTint: number;
-
- private _rgbValue: string = '';
-
- private _colorType: ColorType;
-
- constructor() {
- this._colorType = ColorType.UNSUPPORTED;
- this._themeColors = ThemeColors.OFFICE;
- this._themeTint = 0;
- }
-
- asRgbColor(): RgbColor {
- return new RgbColor(this._rgbValue, this);
- }
-
- asThemeColor(): ThemeColor {
- return new ThemeColor(this._themeValue, this._themeTint, this._themeColors, this);
- }
-
- build(): Nullable<Color> {
- switch (this._colorType) {
- case ColorType.THEME: {
- return this.asThemeColor();
- }
- case ColorType.RGB: {
- return this.asRgbColor();
- }
- case ColorType.UNSUPPORTED: {
- throw Error('unsupported color type');
- }
- }
- }
-
- setRgbColor(cssString: string): ColorBuilder {
- this._colorType = ColorType.RGB;
- this._rgbValue = cssString;
- return this;
- }
-
- setThemeColors(value: ThemeColors) {
- this._colorType = ColorType.THEME;
- this._themeColors = value;
- }
-
- setThemeTint(value: number) {
- this._colorType = ColorType.THEME;
- this._themeTint = value;
- }
-
- setThemeColor(theme: ThemeColorType): ColorBuilder {
- this._colorType = ColorType.THEME;
- this._themeValue = theme;
- return this;
- }
-
- getColorType(): ColorType {
- return this._colorType;
- }
-}
diff --git a/packages/core/src/shared/color/color-kit.ts b/packages/core/src/shared/color/color-kit.ts
new file mode 100644
index 0000000000..6887082d4f
--- /dev/null
+++ b/packages/core/src/shared/color/color-kit.ts
@@ -0,0 +1,857 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* eslint-disable no-magic-numbers */
+interface IRgbColor {
+ b: number;
+
+ g: number;
+
+ r: number;
+
+ a?: number;
+}
+
+interface IHslColor {
+ h: number;
+
+ l: number;
+
+ s: number;
+
+ a?: number;
+}
+
+interface IHsvColor {
+ h: number;
+
+ s: number;
+
+ v: number;
+
+ a?: number;
+}
+
+type Color = IRgbColor | IHslColor | IHsvColor;
+
+export const RGB_PAREN = 'rgb(';
+export const RGBA_PAREN = 'rgba(';
+export const COLORS: { [key: string]: number[] } = {
+ aliceBlue: [240, 248, 255],
+ antiqueWhite: [250, 235, 215],
+ aqua: [0, 255, 255],
+ aquamarine: [127, 255, 212],
+ azure: [240, 255, 255],
+ beige: [245, 245, 220],
+ bisque: [255, 228, 196],
+ black: [0, 0, 0],
+ blancheAlmond: [255, 235, 205],
+ blue: [0, 0, 255],
+ blueViolet: [138, 43, 226],
+ brown: [165, 42, 42],
+ burlyWood: [222, 184, 135],
+ cadetBlue: [95, 158, 160],
+ chartreuse: [127, 255, 0],
+ chocolate: [210, 105, 30],
+ coral: [255, 127, 80],
+ cornFlowerBlue: [100, 149, 237],
+ cornSilk: [255, 248, 220],
+ crimson: [220, 20, 60],
+ cyan: [0, 255, 255],
+ darkblue: [0, 0, 139],
+ darkCyan: [0, 139, 139],
+ darkGoldenrod: [184, 132, 11],
+ darkGray: [169, 169, 169],
+ darkGreen: [0, 100, 0],
+ darkGrey: [169, 169, 169],
+ darkKhaki: [189, 183, 107],
+ darkMagenta: [139, 0, 139],
+ darkOliveGreen: [85, 107, 47],
+ darkOrange: [255, 140, 0],
+ darkOrchid: [153, 50, 204],
+ darkRed: [139, 0, 0],
+ darkSalmon: [233, 150, 122],
+ darkSeaGreen: [143, 188, 143],
+ darkSlateBlue: [72, 61, 139],
+ darkSlateGray: [47, 79, 79],
+ darkSlateGrey: [47, 79, 79],
+ darkTurquoise: [0, 206, 209],
+ darkViolet: [148, 0, 211],
+ deepPink: [255, 20, 147],
+ deepSkyBlue: [0, 191, 255],
+ dimGray: [105, 105, 105],
+ dimGrey: [105, 105, 105],
+ dodgerBlue: [30, 144, 255],
+ firebrick: [178, 34, 34],
+ floralWhite: [255, 255, 240],
+ forestGreen: [34, 139, 34],
+ fuchsia: [255, 0, 255],
+ gainsboro: [220, 220, 220],
+ ghostWhite: [248, 248, 255],
+ gold: [255, 215, 0],
+ goldenrod: [218, 165, 32],
+ gray: [128, 128, 128],
+ green: [0, 128, 0],
+ greenYellow: [173, 255, 47],
+ grey: [128, 128, 128],
+ honeydew: [240, 255, 240],
+ hotPink: [255, 105, 180],
+ indianRed: [205, 92, 92],
+ indigo: [75, 0, 130],
+ ivory: [255, 255, 240],
+ khaki: [240, 230, 140],
+ lavender: [230, 230, 250],
+ lavenderBlush: [255, 240, 245],
+ lawnGreen: [124, 252, 0],
+ lemonChiffon: [255, 250, 205],
+ lightblue: [173, 216, 230],
+ lightCoral: [240, 128, 128],
+ lightCyan: [224, 255, 255],
+ lightGoldenrodYellow: [250, 250, 210],
+ lightGray: [211, 211, 211],
+ lightGreen: [144, 238, 144],
+ lightGrey: [211, 211, 211],
+ lightPink: [255, 182, 193],
+ lightSalmon: [255, 160, 122],
+ lightSeaGreen: [32, 178, 170],
+ lightSkyBlue: [135, 206, 250],
+ lightSlateGray: [119, 136, 153],
+ lightSlateGrey: [119, 136, 153],
+ lightSteelBlue: [176, 196, 222],
+ lightYellow: [255, 255, 224],
+ lime: [0, 255, 0],
+ limeGreen: [50, 205, 50],
+ linen: [250, 240, 230],
+ magenta: [255, 0, 255],
+ maroon: [128, 0, 0],
+ mediumAquamarine: [102, 205, 170],
+ mediumBlue: [0, 0, 205],
+ mediumOrchid: [186, 85, 211],
+ mediumPurple: [147, 112, 219],
+ mediumSeaGreen: [60, 179, 113],
+ mediumSlateBlue: [123, 104, 238],
+ mediumSpringGreen: [0, 250, 154],
+ mediumTurquoise: [72, 209, 204],
+ mediumVioletRed: [199, 21, 133],
+ midBightBlue: [25, 25, 112],
+ mintCream: [245, 255, 250],
+ mistyRose: [255, 228, 225],
+ moccasin: [255, 228, 181],
+ navajoWhite: [255, 222, 173],
+ navy: [0, 0, 128],
+ oldLace: [253, 245, 230],
+ olive: [128, 128, 0],
+ oliveDrab: [107, 142, 35],
+ orange: [255, 165, 0],
+ orangeRed: [255, 69, 0],
+ orchid: [218, 112, 214],
+ paleGoldenrod: [238, 232, 170],
+ paleGreen: [152, 251, 152],
+ paleTurquoise: [175, 238, 238],
+ paleVioletRed: [219, 112, 147],
+ papayaWhip: [255, 239, 213],
+ peachPuff: [255, 218, 185],
+ peru: [205, 133, 63],
+ pink: [255, 192, 203],
+ plum: [221, 160, 203],
+ powderBlue: [176, 224, 230],
+ purple: [128, 0, 128],
+ rebeccaPurple: [102, 51, 153],
+ red: [255, 0, 0],
+ rosyBrown: [188, 143, 143],
+ royalBlue: [65, 105, 225],
+ saddleBrown: [139, 69, 19],
+ salmon: [250, 128, 114],
+ sandyBrown: [244, 164, 96],
+ seaGreen: [46, 139, 87],
+ seashell: [255, 245, 238],
+ sienna: [160, 82, 45],
+ silver: [192, 192, 192],
+ skyBlue: [135, 206, 235],
+ slateBlue: [106, 90, 205],
+ slateGray: [119, 128, 144],
+ slateGrey: [119, 128, 144],
+ snow: [255, 255, 250],
+ springGreen: [0, 255, 127],
+ steelBlue: [70, 130, 180],
+ tan: [210, 180, 140],
+ teal: [0, 128, 128],
+ thistle: [216, 191, 216],
+ transparent: [255, 255, 255, 0],
+ tomato: [255, 99, 71],
+ turquoise: [64, 224, 208],
+ violet: [238, 130, 238],
+ wheat: [245, 222, 179],
+ white: [255, 255, 255],
+ whiteSmoke: [245, 245, 245],
+ yellow: [255, 255, 0],
+ yellowGreen: [154, 205, 5],
+};
+
+export class ColorKit {
+ private _color!: Color;
+
+ private _rgbColor!: IRgbColor;
+
+ private _isValid = false;
+
+ static mix(color1: string | Color | ColorKit, color2: string | Color | ColorKit, amount: number) {
+ amount = Math.min(1, Math.max(0, amount));
+
+ const rgb1 = new ColorKit(color1).toRgb();
+
+ const rgb2 = new ColorKit(color2).toRgb();
+
+ const alpha1 = rgb1.a ?? 1;
+
+ const alpha2 = rgb2.a ?? 1;
+
+ const rgba: IRgbColor = {
+ r: (rgb2.r - rgb1.r) * amount + rgb1.r,
+
+ g: (rgb2.g - rgb1.g) * amount + rgb1.g,
+
+ b: (rgb2.b - rgb1.b) * amount + rgb1.b,
+
+ a: (alpha2 - alpha1) * amount + alpha1,
+ };
+
+ return new ColorKit(rgba);
+ }
+
+ static getContrastRatio(foreground: string | Color | ColorKit, background: string | Color | ColorKit) {
+ const lumA = new ColorKit(foreground).getLuminance();
+
+ const lumB = new ColorKit(background).getLuminance();
+
+ return (Math.max(lumA, lumB) + 0.05) / (Math.min(lumA, lumB) + 0.05);
+ }
+
+ constructor(color: string | Color | ColorKit | undefined) {
+ if (color == null) {
+ this._setNullColor();
+ return;
+ }
+
+ if (color instanceof ColorKit) {
+ this._color = { ...color._color };
+
+ this._rgbColor = { ...color._rgbColor };
+
+ return;
+ }
+
+ const colorObject = toColor(color);
+
+ if (colorObject == null) {
+ this._setNullColor();
+ return;
+ }
+
+ this._color = colorObject;
+
+ const rgbColorObject = toRgbColor(this._color);
+
+ if (rgbColorObject == null) {
+ this._setNullColor();
+ return;
+ }
+
+ this._rgbColor = rgbColorObject;
+
+ this._isValid = true;
+ }
+
+ get isValid() {
+ return this._isValid;
+ }
+
+ toRgb() {
+ return this._rgbColor;
+ }
+
+ toRgbString() {
+ const { r, g, b, a = 1 } = this.toRgb();
+
+ const useAlpha = a < 1;
+
+ return `rgb${useAlpha ? 'a' : ''}(${r},${g},${b}${useAlpha ? `,${a}` : ''})`;
+ }
+
+ toString() {
+ return this.toRgbString();
+ }
+
+ toHexString(allowShort?: boolean) {
+ const { r, g, b, a = 1 } = this.toRgb();
+
+ const useAlpha = a < 1;
+
+ const hex = [
+ pad2(Math.round(r).toString(16)),
+
+ pad2(Math.round(g).toString(16)),
+
+ pad2(Math.round(b).toString(16)),
+
+ pad2(Math.round(a * 255).toString(16)),
+ ];
+
+ if (allowShort) {
+ if (
+ hex[0][0] === hex[0][1] &&
+ hex[1][0] === hex[1][1] &&
+ hex[2][0] === hex[2][1] &&
+ hex[3][0] === hex[3][1]
+ ) {
+ return useAlpha
+ ? `#${hex[0][0]}${hex[1][0]}${hex[2][0]}${hex[3][0]}`
+ : `#${hex[0][0]}${hex[1][0]}${hex[2][0]}`;
+ }
+ }
+
+ return useAlpha ? `#${hex[0]}${hex[1]}${hex[2]}${hex[3]}` : `#${hex[0]}${hex[1]}${hex[2]}`;
+ }
+
+ toHsv() {
+ return rgb2Hsv(this.toRgb());
+ }
+
+ toHsl() {
+ return rgb2Hsl(this.toRgb());
+ }
+
+ lighten(amount = 10) {
+ const hsl = this.toHsl();
+
+ hsl.l += amount;
+
+ hsl.l = Math.min(Math.max(hsl.l, 0), 100);
+
+ return new ColorKit(hsl);
+ }
+
+ darken(amount = 10) {
+ const hsl = this.toHsl();
+
+ hsl.l -= amount;
+
+ hsl.l = Math.min(Math.max(hsl.l, 0), 100);
+
+ return new ColorKit(hsl);
+ }
+
+ setAlpha(value: number) {
+ return new ColorKit({ ...this._rgbColor, a: value });
+ }
+
+ getLuminance() {
+ let { r, g, b } = this.toRgb();
+
+ r = rgbNormalize(r);
+
+ g = rgbNormalize(g);
+
+ b = rgbNormalize(b);
+
+ // Truncate at 3 digits
+
+ return Number((0.2126 * r + 0.7152 * g + 0.0722 * b).toFixed(3));
+ }
+
+ getBrightness() {
+ const { r, g, b } = this.toRgb();
+
+ return (r * 299 + g * 587 + b * 114) / 1000;
+ }
+
+ getAlpha() {
+ return this._color.a ?? 1;
+ }
+
+ isDark() {
+ return this.getBrightness() < 128;
+ }
+
+ isLight() {
+ return !this.isDark();
+ }
+
+ private _setNullColor() {
+ this._isValid = false;
+ this._color = {
+ r: 0,
+ g: 0,
+ b: 0,
+ a: 0,
+ };
+ this._rgbColor = {
+ r: 0,
+ g: 0,
+ b: 0,
+ a: 0,
+ };
+ }
+}
+
+const pad2 = (v: string) => {
+ return v.length === 1 ? `0${v}` : v;
+};
+
+const rgbNormalize = (val: number) => {
+ val /= 255;
+
+ return val <= 0.03928 ? val / 12.92 : ((val + 0.055) / 1.055) ** 2.4;
+};
+
+const toColor: (color: string | Color) => Color | undefined = (color) => {
+ if (isObject(color)) {
+ if ('r' in color) {
+ const rgb: IRgbColor = {
+ r: Math.round(color.r),
+
+ g: Math.round(color.g),
+
+ b: Math.round(color.b),
+ };
+
+ if (color.a !== undefined) {
+ rgb.a = color.a;
+ }
+
+ return rgb;
+ }
+
+ if ('l' in color) {
+ const hsl: IHslColor = {
+ h: Math.round(color.h),
+
+ s: color.s,
+
+ l: color.l,
+ };
+
+ if (color.a !== undefined) {
+ hsl.a = color.a;
+ }
+
+ return hsl;
+ }
+
+ const hsv: IHsvColor = {
+ h: Math.round(color.h),
+
+ s: color.s,
+
+ v: color.v,
+ };
+
+ if (color.a !== undefined) {
+ hsv.a = color.a;
+ }
+
+ return hsv;
+ }
+
+ const parsedColor = color.trim();
+
+ if (COLORS[parsedColor]) {
+ const colorArray = COLORS[parsedColor];
+ const rgb: IRgbColor = {
+ r: Math.round(colorArray[0]),
+
+ g: Math.round(colorArray[1]),
+
+ b: Math.round(colorArray[2]),
+ };
+
+ rgb.a = colorArray[3] || 1;
+
+ return rgb;
+ }
+
+ if (parsedColor.startsWith('#')) {
+ return hexToColor(parsedColor);
+ }
+
+ if (parsedColor.startsWith('rgb')) {
+ return rgbToColor(parsedColor);
+ }
+
+ if (parsedColor.startsWith('hsl')) {
+ return hslToColor(parsedColor);
+ }
+
+ if (parsedColor.startsWith('hsv')) {
+ return hsvToColor(parsedColor);
+ }
+};
+
+const hexToColor: (color: string) => Color = (color) => {
+ const parsedColor = color.substring(1);
+
+ const re = new RegExp(`.{1,${parsedColor.length >= 6 ? 2 : 1}}`, 'g');
+
+ let colors: string[] | RegExpMatchArray | null = parsedColor.match(re);
+
+ if (!colors || colors.length < 3) {
+ throw new Error(`The color '${color}' is illegal hex color`);
+ }
+
+ if (colors[0].length === 1) {
+ colors = colors.map((n) => n + n);
+ }
+
+ const rgbColor: IRgbColor = {
+ r: parseInt(colors[0], 16),
+
+ g: parseInt(colors[1], 16),
+
+ b: parseInt(colors[2], 16),
+ };
+
+ if (colors.length > 3) {
+ rgbColor.a = parseInt(colors[3], 16) / 255;
+ }
+
+ return rgbColor;
+};
+
+const rgbToColor: (color: string) => Color = (color) => {
+ const matcher = color.indexOf('(');
+
+ if (matcher === -1) {
+ throw new Error(`The color '${color}' is illegal rgb color`);
+ }
+
+ const values = color.substring(matcher + 1, color.length - 1).split(',');
+
+ if (values.length < 3) {
+ throw new Error(`The color '${color}' is illegal rgb color`);
+ }
+
+ const rgbColor: IRgbColor = {
+ r: parseInt(values[0], 10),
+
+ g: parseInt(values[1], 10),
+
+ b: parseInt(values[2], 10),
+ };
+
+ if (values.length > 3) {
+ rgbColor.a = parseFloat(values[3]);
+ }
+
+ return rgbColor;
+};
+
+const hslToColor: (color: string) => Color = (color) => {
+ const matcher = color.indexOf('(');
+
+ if (matcher === -1) {
+ throw new Error(`The color '${color}' is illegal hsl color`);
+ }
+
+ const values = color.substring(matcher + 1, color.length - 1).split(',');
+
+ if (values.length < 3) {
+ throw new Error(`The color '${color}' is illegal hsl color`);
+ }
+
+ const hslColor: IHslColor = {
+ h: parseInt(values[0], 10),
+
+ s: parseFloat(values[1]),
+
+ l: parseFloat(values[2]),
+ };
+
+ if (values.length > 3) {
+ hslColor.a = parseFloat(values[3]);
+ }
+
+ return hslColor;
+};
+
+const hsvToColor: (color: string) => Color = (color) => {
+ const matcher = color.indexOf('(');
+
+ if (matcher === -1) {
+ throw new Error(`The color '${color}' is illegal hsv color`);
+ }
+
+ const values = color.substring(matcher + 1, color.length - 1).split(',');
+
+ if (values.length < 3) {
+ throw new Error(`The color '${color}' is illegal hsv color`);
+ }
+
+ const hsvColor: IHsvColor = {
+ h: parseInt(values[0], 10),
+
+ s: parseFloat(values[1]),
+
+ v: parseFloat(values[2]),
+ };
+
+ if (values.length > 3) {
+ hsvColor.a = parseFloat(values[3]);
+ }
+
+ return hsvColor;
+};
+
+const toRgbColor: (color: string | Color) => IRgbColor | undefined = (color) => {
+ const obj = toColor(color);
+
+ if (obj == null) {
+ return;
+ }
+
+ if ('r' in obj) {
+ return obj;
+ }
+
+ if ('l' in obj) {
+ return hsl2Rgb(obj);
+ }
+
+ return hsv2Rgb(obj);
+};
+
+const hue2Rgb = (p: number, q: number, t: number) => {
+ if (t < 0) t += 1;
+
+ if (t > 1) t -= 1;
+
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
+
+ if (t < 1 / 2) return q;
+
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
+
+ return p;
+};
+
+const hsl2Rgb: (color: IHslColor) => IRgbColor = (color) => {
+ let { h, s, l } = color;
+
+ h /= 360;
+
+ s /= 100;
+
+ l /= 100;
+
+ let r = 0;
+
+ let g = 0;
+
+ let b = 0;
+
+ if (s === 0) {
+ r = g = b = l; // achromatic
+ } else {
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
+
+ const p = 2 * l - q;
+
+ r = hue2Rgb(p, q, h + 1 / 3);
+
+ g = hue2Rgb(p, q, h);
+
+ b = hue2Rgb(p, q, h - 1 / 3);
+ }
+
+ const IRgbColor: IRgbColor = {
+ r: Math.round(r * 255),
+
+ g: Math.round(g * 255),
+
+ b: Math.round(b * 255),
+ };
+
+ if (color.a !== undefined) {
+ IRgbColor.a = color.a;
+ }
+
+ return IRgbColor;
+};
+
+const hsv2Rgb: (color: IHsvColor) => IRgbColor = (color) => {
+ let { h, s, v } = color;
+
+ h = (h / 360) * 6;
+
+ s /= 100;
+
+ v /= 100;
+
+ const i = Math.floor(h);
+
+ const f = h - i;
+
+ const p = v * (1 - s);
+
+ const q = v * (1 - f * s);
+
+ const t = v * (1 - (1 - f) * s);
+
+ const mod = i % 6;
+
+ const r = [v, q, p, p, t, v][mod];
+
+ const g = [t, v, v, q, p, p][mod];
+
+ const b = [p, p, t, v, v, q][mod];
+
+ const IRgbColor: IRgbColor = {
+ r: r * 255,
+
+ g: g * 255,
+
+ b: b * 255,
+ };
+
+ if (color.a !== undefined) {
+ IRgbColor.a = color.a;
+ }
+
+ return IRgbColor;
+};
+
+const rgb2Hsl: (color: IRgbColor) => IHslColor = (color) => {
+ let { r, g, b } = color;
+
+ r /= 255;
+
+ g /= 255;
+
+ b /= 255;
+
+ const max = Math.max(r, g, b);
+
+ const min = Math.min(r, g, b);
+
+ const l = (max + min) / 2;
+
+ let h: number;
+
+ let s: number;
+
+ if (max === min) {
+ h = s = 0;
+ } else {
+ const d = max - min;
+
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
+
+ switch (max) {
+ case r:
+ h = (g - b) / d + (g < b ? 6 : 0);
+
+ break;
+
+ case g:
+ h = (b - r) / d + 2;
+
+ break;
+
+ default:
+ h = (r - g) / d + 4;
+
+ break;
+ }
+
+ h /= 6;
+ }
+
+ const hslColor: IHslColor = {
+ h: Math.round(h * 360),
+
+ s: Math.round(s * 100),
+
+ l: Math.round(l * 100),
+ };
+
+ if (color.a !== undefined) {
+ hslColor.a = color.a;
+ }
+
+ return hslColor;
+};
+
+const rgb2Hsv: (color: IRgbColor) => IHsvColor = (color) => {
+ let { r, g, b } = color;
+
+ r /= 255;
+
+ g /= 255;
+
+ b /= 255;
+
+ const max = Math.max(r, g, b);
+
+ const min = Math.min(r, g, b);
+
+ let h;
+
+ const v = max;
+
+ const d = max - min;
+
+ const s = max === 0 ? 0 : d / max;
+
+ if (max === min) {
+ h = 0; // achromatic
+ } else {
+ switch (max) {
+ case r:
+ h = (g - b) / d + (g < b ? 6 : 0);
+
+ break;
+
+ case g:
+ h = (b - r) / d + 2;
+
+ break;
+
+ default:
+ h = (r - g) / d + 4;
+
+ break;
+ }
+
+ h /= 6;
+ }
+
+ const hsvColor: IHsvColor = {
+ h: Math.round(h * 360),
+
+ s: Math.round(s * 100),
+
+ v: Math.round(v * 100),
+ };
+
+ if (color.a !== undefined) {
+ hsvColor.a = color.a;
+ }
+
+ return hsvColor;
+};
+
+const isUndefinedOrNull = (value: unknown): value is null | undefined => value == null;
+
+const isObject = (value: unknown): value is object => !isUndefinedOrNull(value) && typeof value === 'object';
diff --git a/packages/core/src/shared/color/color.ts b/packages/core/src/shared/color/color.ts
index cf6964d79b..6e36abcbac 100644
--- a/packages/core/src/shared/color/color.ts
+++ b/packages/core/src/shared/color/color.ts
@@ -16,9 +16,73 @@
import type { Nullable } from '../../common/type-utils';
import { THEME_COLORS } from '../../types/const/theme-color-map';
-import type { ThemeColors, ThemeColorType } from '../../types/enum';
-import { ColorType } from '../../types/enum';
-import { ColorBuilder } from './color-builder';
+import { ColorType, ThemeColors, ThemeColorType } from '../../types/enum';
+
+export class ColorBuilder {
+ private _themeValue: ThemeColorType = ThemeColorType.LIGHT1;
+
+ private _themeColors: ThemeColors;
+
+ private _themeTint: number;
+
+ private _rgbValue: string = '';
+
+ private _colorType: ColorType;
+
+ constructor() {
+ this._colorType = ColorType.UNSUPPORTED;
+ this._themeColors = ThemeColors.OFFICE;
+ this._themeTint = 0;
+ }
+
+ asRgbColor(): RgbColor {
+ return new RgbColor(this._rgbValue, this);
+ }
+
+ asThemeColor(): ThemeColor {
+ return new ThemeColor(this._themeValue, this._themeTint, this._themeColors, this);
+ }
+
+ build(): Nullable<Color> {
+ switch (this._colorType) {
+ case ColorType.THEME: {
+ return this.asThemeColor();
+ }
+ case ColorType.RGB: {
+ return this.asRgbColor();
+ }
+ case ColorType.UNSUPPORTED: {
+ throw Error('unsupported color type');
+ }
+ }
+ }
+
+ setRgbColor(cssString: string): ColorBuilder {
+ this._colorType = ColorType.RGB;
+ this._rgbValue = cssString;
+ return this;
+ }
+
+ setThemeColors(value: ThemeColors) {
+ this._colorType = ColorType.THEME;
+ this._themeColors = value;
+ }
+
+ setThemeTint(value: number) {
+ this._colorType = ColorType.THEME;
+ this._themeTint = value;
+ }
+
+ setThemeColor(theme: ThemeColorType): ColorBuilder {
+ this._colorType = ColorType.THEME;
+ this._themeValue = theme;
+ return this;
+ }
+
+ getColorType(): ColorType {
+ return this._colorType;
+ }
+}
export class Color {
protected _builder: ColorBuilder;
diff --git a/packages/core/src/shared/common.ts b/packages/core/src/shared/common.ts
index d4130dbbc0..243f31239c 100644
--- a/packages/core/src/shared/common.ts
+++ b/packages/core/src/shared/common.ts
@@ -27,7 +27,7 @@ import type { ICellData } from '../types/interfaces/i-cell-data';
import type { IDocumentData } from '../types/interfaces/i-document-data';
import type { IRangeWithCoord, ISelectionCell, ISelectionCellWithCoord } from '../types/interfaces/i-selection-data';
import type { IColorStyle, IStyleData } from '../types/interfaces/i-style-data';
-import { ColorBuilder } from './color/color-builder';
+import { ColorBuilder } from './color/color';
import { Tools } from './tools';
import type { Nullable } from './types';
diff --git a/packages/core/src/shared/index.ts b/packages/core/src/shared/index.ts
index 65f8592dd8..b5926defec 100644
--- a/packages/core/src/shared/index.ts
+++ b/packages/core/src/shared/index.ts
@@ -17,7 +17,7 @@
export * from './array-search';
export * from './blob';
export * from './color/color';
-export * from './color/color-builder';
+export { ColorKit, COLORS, RGB_PAREN, RGBA_PAREN } from './color/color-kit';
export * from './command-enum';
export * from './common';
export * from './compare';
diff --git a/packages/docs/package.json b/packages/docs/package.json
index d6ce7e0cfc..8d7c9a1875 100644
--- a/packages/docs/package.json
+++ b/packages/docs/package.json
@@ -43,7 +43,6 @@
"build": "tsc && vite build"
},
"devDependencies": {
- "@ctrl/tinycolor": "^4.0.2",
"@univerjs/core": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/sheets": "workspace:*",
@@ -60,7 +59,6 @@
"vitest": "^1.0.4"
},
"peerDependencies": {
- "@ctrl/tinycolor": ">=4.0.0",
"@univerjs/core": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/sheets": "workspace:*",
diff --git a/packages/docs/src/services/clipboard/html-to-udm/parse-node-style.ts b/packages/docs/src/services/clipboard/html-to-udm/parse-node-style.ts
index a743e36fa8..3b819ce153 100644
--- a/packages/docs/src/services/clipboard/html-to-udm/parse-node-style.ts
+++ b/packages/docs/src/services/clipboard/html-to-udm/parse-node-style.ts
@@ -14,9 +14,8 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
import type { ITextStyle } from '@univerjs/core';
-import { BaselineOffset, BooleanNumber } from '@univerjs/core';
+import { BaselineOffset, BooleanNumber, ColorKit } from '@univerjs/core';
import { ptToPixel } from './utils';
@@ -119,7 +118,7 @@ export function extractNodeStyle(node: HTMLElement): ITextStyle {
}
case 'color': {
- const color = new TinyColor(cssValue);
+ const color = new ColorKit(cssValue);
if (color.isValid) {
docStyles.cl = {
@@ -131,7 +130,7 @@ export function extractNodeStyle(node: HTMLElement): ITextStyle {
}
case 'background-color': {
- const color = new TinyColor(cssValue);
+ const color = new ColorKit(cssValue);
if (color.isValid) {
docStyles.bg = {
diff --git a/packages/docs/vite.config.ts b/packages/docs/vite.config.ts
index 70f12c1031..8a6884f614 100644
--- a/packages/docs/vite.config.ts
+++ b/packages/docs/vite.config.ts
@@ -29,7 +29,6 @@ export default defineConfig(({ mode }) => ({
},
rollupOptions: {
external: [
- '@ctrl/tinycolor',
'@univerjs/core',
'@univerjs/engine-render',
'@univerjs/sheets',
@@ -41,7 +40,6 @@ export default defineConfig(({ mode }) => ({
],
output: {
globals: {
- '@ctrl/tinycolor': 'tinycolor',
'@univerjs/core': 'UniverCore',
'@univerjs/engine-render': 'UniverEngineRender',
'@univerjs/sheets': 'UniverSheets',
diff --git a/packages/engine-render/src/basics/const.ts b/packages/engine-render/src/basics/const.ts
index 5bf218da79..0bcf841bcf 100644
--- a/packages/engine-render/src/basics/const.ts
+++ b/packages/engine-render/src/basics/const.ts
@@ -14,160 +14,6 @@
* limitations under the License.
*/
-export const RGB_PAREN = 'rgb(';
-export const RGBA_PAREN = 'rgba(';
-export const COLORS = {
- aliceBlue: [240, 248, 255],
- antiqueWhite: [250, 235, 215],
- aqua: [0, 255, 255],
- aquamarine: [127, 255, 212],
- azure: [240, 255, 255],
- beige: [245, 245, 220],
- bisque: [255, 228, 196],
- black: [0, 0, 0],
- blancheAlmond: [255, 235, 205],
- blue: [0, 0, 255],
- blueViolet: [138, 43, 226],
- brown: [165, 42, 42],
- burlyWood: [222, 184, 135],
- cadetBlue: [95, 158, 160],
- chartreuse: [127, 255, 0],
- chocolate: [210, 105, 30],
- coral: [255, 127, 80],
- cornFlowerBlue: [100, 149, 237],
- cornSilk: [255, 248, 220],
- crimson: [220, 20, 60],
- cyan: [0, 255, 255],
- darkblue: [0, 0, 139],
- darkCyan: [0, 139, 139],
- darkGoldenrod: [184, 132, 11],
- darkGray: [169, 169, 169],
- darkGreen: [0, 100, 0],
- darkGrey: [169, 169, 169],
- darkKhaki: [189, 183, 107],
- darkMagenta: [139, 0, 139],
- darkOliveGreen: [85, 107, 47],
- darkOrange: [255, 140, 0],
- darkOrchid: [153, 50, 204],
- darkRed: [139, 0, 0],
- darkSalmon: [233, 150, 122],
- darkSeaGreen: [143, 188, 143],
- darkSlateBlue: [72, 61, 139],
- darkSlateGray: [47, 79, 79],
- darkSlateGrey: [47, 79, 79],
- darkTurquoise: [0, 206, 209],
- darkViolet: [148, 0, 211],
- deepPink: [255, 20, 147],
- deepSkyBlue: [0, 191, 255],
- dimGray: [105, 105, 105],
- dimGrey: [105, 105, 105],
- dodgerBlue: [30, 144, 255],
- firebrick: [178, 34, 34],
- floralWhite: [255, 255, 240],
- forestGreen: [34, 139, 34],
- fuchsia: [255, 0, 255],
- gainsboro: [220, 220, 220],
- ghostWhite: [248, 248, 255],
- gold: [255, 215, 0],
- goldenrod: [218, 165, 32],
- gray: [128, 128, 128],
- green: [0, 128, 0],
- greenYellow: [173, 255, 47],
- grey: [128, 128, 128],
- honeydew: [240, 255, 240],
- hotPink: [255, 105, 180],
- indianRed: [205, 92, 92],
- indigo: [75, 0, 130],
- ivory: [255, 255, 240],
- khaki: [240, 230, 140],
- lavender: [230, 230, 250],
- lavenderBlush: [255, 240, 245],
- lawnGreen: [124, 252, 0],
- lemonChiffon: [255, 250, 205],
- lightblue: [173, 216, 230],
- lightCoral: [240, 128, 128],
- lightCyan: [224, 255, 255],
- lightGoldenrodYellow: [250, 250, 210],
- lightGray: [211, 211, 211],
- lightGreen: [144, 238, 144],
- lightGrey: [211, 211, 211],
- lightPink: [255, 182, 193],
- lightSalmon: [255, 160, 122],
- lightSeaGreen: [32, 178, 170],
- lightSkyBlue: [135, 206, 250],
- lightSlateGray: [119, 136, 153],
- lightSlateGrey: [119, 136, 153],
- lightSteelBlue: [176, 196, 222],
- lightYellow: [255, 255, 224],
- lime: [0, 255, 0],
- limeGreen: [50, 205, 50],
- linen: [250, 240, 230],
- magenta: [255, 0, 255],
- maroon: [128, 0, 0],
- mediumAquamarine: [102, 205, 170],
- mediumBlue: [0, 0, 205],
- mediumOrchid: [186, 85, 211],
- mediumPurple: [147, 112, 219],
- mediumSeaGreen: [60, 179, 113],
- mediumSlateBlue: [123, 104, 238],
- mediumSpringGreen: [0, 250, 154],
- mediumTurquoise: [72, 209, 204],
- mediumVioletRed: [199, 21, 133],
- midBightBlue: [25, 25, 112],
- mintCream: [245, 255, 250],
- mistyRose: [255, 228, 225],
- moccasin: [255, 228, 181],
- navajoWhite: [255, 222, 173],
- navy: [0, 0, 128],
- oldLace: [253, 245, 230],
- olive: [128, 128, 0],
- oliveDrab: [107, 142, 35],
- orange: [255, 165, 0],
- orangeRed: [255, 69, 0],
- orchid: [218, 112, 214],
- paleGoldenrod: [238, 232, 170],
- paleGreen: [152, 251, 152],
- paleTurquoise: [175, 238, 238],
- paleVioletRed: [219, 112, 147],
- papayaWhip: [255, 239, 213],
- peachPuff: [255, 218, 185],
- peru: [205, 133, 63],
- pink: [255, 192, 203],
- plum: [221, 160, 203],
- powderBlue: [176, 224, 230],
- purple: [128, 0, 128],
- rebeccaPurple: [102, 51, 153],
- red: [255, 0, 0],
- rosyBrown: [188, 143, 143],
- royalBlue: [65, 105, 225],
- saddleBrown: [139, 69, 19],
- salmon: [250, 128, 114],
- sandyBrown: [244, 164, 96],
- seaGreen: [46, 139, 87],
- seashell: [255, 245, 238],
- sienna: [160, 82, 45],
- silver: [192, 192, 192],
- skyBlue: [135, 206, 235],
- slateBlue: [106, 90, 205],
- slateGray: [119, 128, 144],
- slateGrey: [119, 128, 144],
- snow: [255, 255, 250],
- springGreen: [0, 255, 127],
- steelBlue: [70, 130, 180],
- tan: [210, 180, 140],
- teal: [0, 128, 128],
- thistle: [216, 191, 216],
- transparent: [255, 255, 255, 0],
- tomato: [255, 99, 71],
- turquoise: [64, 224, 208],
- violet: [238, 130, 238],
- wheat: [245, 222, 179],
- white: [255, 255, 255],
- whiteSmoke: [245, 245, 245],
- yellow: [255, 255, 0],
- yellowGreen: [154, 205, 5],
-};
-
export enum SHAPE_TYPE {
RECT = 'rect',
CIRCLE = 'circle',
diff --git a/packages/engine-render/src/components/docs/common/range.ts b/packages/engine-render/src/components/docs/common/range.ts
index 1b262e2c3f..4840b7c3bf 100644
--- a/packages/engine-render/src/components/docs/common/range.ts
+++ b/packages/engine-render/src/components/docs/common/range.ts
@@ -15,9 +15,8 @@
*/
import type { ITextRange, Nullable } from '@univerjs/core';
-import { Tools } from '@univerjs/core';
+import { COLORS, Tools } from '@univerjs/core';
-import { COLORS } from '../../../basics/const';
import type { INodePosition } from '../../../basics/interfaces';
import type { ISuccinctTextRangeParam, ITextSelectionStyle } from '../../../basics/range';
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE, RANGE_DIRECTION } from '../../../basics/range';
diff --git a/packages/engine-render/src/components/slides/slide.ts b/packages/engine-render/src/components/slides/slide.ts
index dffeb168cb..72eb8d5079 100644
--- a/packages/engine-render/src/components/slides/slide.ts
+++ b/packages/engine-render/src/components/slides/slide.ts
@@ -15,9 +15,9 @@
*/
import type { Nullable } from '@univerjs/core';
-import { Observable } from '@univerjs/core';
+import { COLORS, Observable } from '@univerjs/core';
-import { COLORS, CURSOR_TYPE } from '../../basics/const';
+import { CURSOR_TYPE } from '../../basics/const';
import type { IMouseEvent, IPointerEvent } from '../../basics/i-events';
import { attachObjectHover } from '../../basics/quick-event';
import { getColor } from '../../basics/tools';
diff --git a/packages/sheets-formula/package.json b/packages/sheets-formula/package.json
index e0668cf60e..7e41338399 100644
--- a/packages/sheets-formula/package.json
+++ b/packages/sheets-formula/package.json
@@ -45,7 +45,6 @@
"@univerjs/icons": "^0.1.18"
},
"devDependencies": {
- "@ctrl/tinycolor": "^4.0.2",
"@types/react": "^18.2.42",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
@@ -69,7 +68,6 @@
"vitest": "^1.0.4"
},
"peerDependencies": {
- "@ctrl/tinycolor": ">=4.0.0",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
diff --git a/packages/sheets-formula/src/common/selection.ts b/packages/sheets-formula/src/common/selection.ts
index 8e04f694f4..fd7f91d74a 100644
--- a/packages/sheets-formula/src/common/selection.ts
+++ b/packages/sheets-formula/src/common/selection.ts
@@ -14,15 +14,14 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
-import type { ThemeService } from '@univerjs/core';
+import { ColorKit, type ThemeService } from '@univerjs/core';
import type { ISelectionStyle } from '@univerjs/sheets';
export const FORMULA_REF_SELECTION_PLUGIN_NAME = 'formula_reference_selection_plugin_name';
export function getFormulaRefSelectionStyle(themeService: ThemeService, refColor: string, id: string): ISelectionStyle {
const style = themeService.getCurrentTheme();
- const fill = new TinyColor(refColor).setAlpha(0.05).toString();
+ const fill = new ColorKit(refColor).setAlpha(0.05).toRgbString();
return {
id,
strokeWidth: 1.5,
diff --git a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts b/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts
index 89e4cbe209..058b19c8cf 100644
--- a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts
+++ b/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
import type { ICellDataForSheetInterceptor, ICommandInfo, IRange, Nullable } from '@univerjs/core';
import {
+ ColorKit,
Disposable,
ICommandService,
LifecycleStages,
@@ -215,7 +215,7 @@ export class FormulaEditorShowController extends Disposable {
private _createArrayFormulaRangeShape(arrayRange: IRange, unitId: string) {
const styleSheet = this._themeService.getCurrentTheme();
- const fill = new TinyColor(styleSheet.colorWhite).setAlpha(0).toString();
+ const fill = new ColorKit(styleSheet.colorWhite).setAlpha(0).toString();
const style = {
strokeWidth: 1,
stroke: styleSheet.hyacinth700,
diff --git a/packages/sheets-formula/vite.config.ts b/packages/sheets-formula/vite.config.ts
index 8a7295a229..f76bac543b 100644
--- a/packages/sheets-formula/vite.config.ts
+++ b/packages/sheets-formula/vite.config.ts
@@ -37,7 +37,6 @@ export default defineConfig(({ mode }) => ({
},
rollupOptions: {
external: [
- '@ctrl/tinycolor',
'@univerjs/core',
'@univerjs/design',
'@univerjs/docs',
@@ -54,7 +53,6 @@ export default defineConfig(({ mode }) => ({
output: {
assetFileNames: 'index.css',
globals: {
- '@ctrl/tinycolor': 'tinycolor',
'@univerjs/core': 'UniverCore',
'@univerjs/design': 'UniverDesign',
'@univerjs/docs': 'UniverDocs',
diff --git a/packages/sheets-ui/package.json b/packages/sheets-ui/package.json
index 28fb0fb957..ea9e09daeb 100644
--- a/packages/sheets-ui/package.json
+++ b/packages/sheets-ui/package.json
@@ -50,7 +50,6 @@
"@univerjs/icons": "^0.1.18"
},
"devDependencies": {
- "@ctrl/tinycolor": "^4.0.2",
"@types/react": "^18.2.42",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
@@ -74,7 +73,6 @@
"vitest": "^1.0.4"
},
"peerDependencies": {
- "@ctrl/tinycolor": ">=4.0.0",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
diff --git a/packages/sheets-ui/src/controllers/freeze.controller.ts b/packages/sheets-ui/src/controllers/freeze.controller.ts
index 5b9fca99c5..014fd6db11 100644
--- a/packages/sheets-ui/src/controllers/freeze.controller.ts
+++ b/packages/sheets-ui/src/controllers/freeze.controller.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
import type { ICommandInfo, IStyleSheet, Nullable, Observer } from '@univerjs/core';
import {
+ ColorKit,
Disposable,
ICommandService,
IUniverInstanceService,
@@ -1017,9 +1017,9 @@ export class FreezeController extends Disposable {
private _themeChange(style: IStyleSheet) {
this._freeze_normal_header_color = style.grey400;
- this._freeze_normal_main_color = new TinyColor(style.grey400)
+ this._freeze_normal_main_color = new ColorKit(style.grey400)
.setAlpha(AUXILIARY_CLICK_HIDDEN_OBJECT_TRANSPARENCY)
- .toString();
+ .toRgbString();
this._freeze_active_color = style.primaryColor;
diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/parse-node-style.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/parse-node-style.ts
index a1610f7df3..523733d899 100644
--- a/packages/sheets-ui/src/services/clipboard/html-to-usm/parse-node-style.ts
+++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/parse-node-style.ts
@@ -14,9 +14,8 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
import type { ITextStyle } from '@univerjs/core';
-import { BaselineOffset, BooleanNumber } from '@univerjs/core';
+import { BaselineOffset, BooleanNumber, ColorKit } from '@univerjs/core';
import { ptToPixel } from './utils';
@@ -119,7 +118,7 @@ export function extractNodeStyle(node: HTMLElement): ITextStyle {
}
case 'color': {
- const color = new TinyColor(cssValue);
+ const color = new ColorKit(cssValue);
if (color.isValid) {
docStyles.cl = {
@@ -131,7 +130,7 @@ export function extractNodeStyle(node: HTMLElement): ITextStyle {
}
case 'background-color': {
- const color = new TinyColor(cssValue);
+ const color = new ColorKit(cssValue);
if (color.isValid) {
docStyles.bg = {
diff --git a/packages/sheets-ui/src/services/selection/selection-shape-extension.ts b/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
index 4aa6a005b9..585aff3035 100644
--- a/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
+++ b/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
-import type { IRangeWithCoord, Nullable, Observer, ThemeService } from '@univerjs/core';
+import { ColorKit, type IRangeWithCoord, type Nullable, type Observer, type ThemeService } from '@univerjs/core';
import type { IMouseEvent, IPointerEvent, Scene, SpreadsheetSkeleton } from '@univerjs/engine-render';
import { CURSOR_TYPE, isRectIntersect, Rect, ScrollTimer, Vector2 } from '@univerjs/engine-render';
import { getNormalSelectionStyle, SELECTION_CONTROL_BORDER_BUFFER_WIDTH } from '@univerjs/sheets';
@@ -638,9 +637,9 @@ export class SelectionShapeExtension {
if (isLighten) {
this._controlHandler((o, index) => {
- const newColor = new TinyColor(this._fillControlColors[index])
+ const newColor = new ColorKit(this._fillControlColors[index])
.lighten(SELECTION_CONTROL_DELETING_LIGHTEN)
- .toString();
+ .toRgbString();
o.setProps({
fill: newColor,
});
@@ -730,7 +729,7 @@ export class SelectionShapeExtension {
const SELECTION_CONTROL_BORDER_BUFFER_WIDTH_SCALE = SELECTION_CONTROL_BORDER_BUFFER_WIDTH / scale;
- const darkenColor = new TinyColor(stroke).darken(2).toString();
+ const darkenColor = new ColorKit(stroke).darken(2).toRgbString();
if (this.isHelperSelection) {
this._helperSelection = new Rect(HELPER_SELECTION_TEMP_NAME, {
diff --git a/packages/sheets-ui/src/services/selection/selection-shape.ts b/packages/sheets-ui/src/services/selection/selection-shape.ts
index 021bacced8..baaba611ea 100644
--- a/packages/sheets-ui/src/services/selection/selection-shape.ts
+++ b/packages/sheets-ui/src/services/selection/selection-shape.ts
@@ -14,9 +14,8 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
import type { IRangeWithCoord, ISelectionCellWithCoord, Nullable, ThemeService } from '@univerjs/core';
-import { RANGE_TYPE } from '@univerjs/core';
+import { ColorKit, RANGE_TYPE } from '@univerjs/core';
import type { Scene } from '@univerjs/engine-render';
import { DEFAULT_SELECTION_LAYER_INDEX, Group, Rect } from '@univerjs/engine-render';
import type { ISelectionStyle, ISelectionWidgetConfig, ISelectionWithCoordAndStyle } from '@univerjs/sheets';
@@ -728,7 +727,7 @@ export class SelectionShape {
if (hasColumnHeader === true) {
let highlightTitleColor = columnHeaderFill;
if (this._isHeaderHighlight && rangeType === RANGE_TYPE.COLUMN) {
- highlightTitleColor = new TinyColor(stroke).setAlpha(SELECTION_TITLE_HIGHLIGHT_ALPHA).toString();
+ highlightTitleColor = new ColorKit(stroke).setAlpha(SELECTION_TITLE_HIGHLIGHT_ALPHA).toString();
}
this._columnHeaderBackground.setProps({
fill: highlightTitleColor,
@@ -755,7 +754,7 @@ export class SelectionShape {
if (hasRowHeader === true) {
let highlightTitleColor = rowHeaderFill;
if (this._isHeaderHighlight && rangeType === RANGE_TYPE.ROW) {
- highlightTitleColor = new TinyColor(stroke).setAlpha(SELECTION_TITLE_HIGHLIGHT_ALPHA).toString();
+ highlightTitleColor = new ColorKit(stroke).setAlpha(SELECTION_TITLE_HIGHLIGHT_ALPHA).toString();
}
this._rowHeaderBackground.setProps({
fill: highlightTitleColor,
diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarItem.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarItem.tsx
index 7f75940829..d55b0ab53f 100644
--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarItem.tsx
+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarItem.tsx
@@ -14,9 +14,8 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
import type { BooleanNumber } from '@univerjs/core';
-import { ICommandService, ThemeService } from '@univerjs/core';
+import { ColorKit, ICommandService, ThemeService } from '@univerjs/core';
import { Dropdown } from '@univerjs/design';
import { Menu } from '@univerjs/ui';
import { useDependency } from '@wendellhu/redi/react-bindings';
@@ -58,7 +57,7 @@ export function SheetBarItem(props: IBaseSheetBarProps) {
const theme = themeService.getCurrentTheme();
const darkTextColor = theme.textColor;
const lightTextColor = theme.colorWhite;
- return new TinyColor(color).isDark() ? lightTextColor : darkTextColor;
+ return new ColorKit(color).isDark() ? lightTextColor : darkTextColor;
};
return (
diff --git a/packages/sheets-ui/vite.config.ts b/packages/sheets-ui/vite.config.ts
index 483423bce4..be1b3016e5 100644
--- a/packages/sheets-ui/vite.config.ts
+++ b/packages/sheets-ui/vite.config.ts
@@ -37,7 +37,6 @@ export default defineConfig(({ mode }) => ({
},
rollupOptions: {
external: [
- '@ctrl/tinycolor',
'@univerjs/core',
'@univerjs/design',
'@univerjs/docs',
@@ -55,7 +54,6 @@ export default defineConfig(({ mode }) => ({
output: {
assetFileNames: 'index.css',
globals: {
- '@ctrl/tinycolor': 'tinycolor',
'@univerjs/core': 'UniverCore',
'@univerjs/design': 'UniverDesign',
'@univerjs/docs': 'UniverDocs',
diff --git a/packages/sheets/package.json b/packages/sheets/package.json
index bea35718ec..c3c0108b70 100644
--- a/packages/sheets/package.json
+++ b/packages/sheets/package.json
@@ -43,7 +43,6 @@
"build": "tsc && vite build"
},
"devDependencies": {
- "@ctrl/tinycolor": "^4.0.2",
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
@@ -59,7 +58,6 @@
"vitest": "^1.0.4"
},
"peerDependencies": {
- "@ctrl/tinycolor": ">=4.0.0",
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
diff --git a/packages/sheets/src/basics/selection.ts b/packages/sheets/src/basics/selection.ts
index 0fd1565275..5b9cb9446a 100644
--- a/packages/sheets/src/basics/selection.ts
+++ b/packages/sheets/src/basics/selection.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
import type {
IRange,
ISelection,
@@ -23,7 +22,7 @@ import type {
Nullable,
ThemeService,
} from '@univerjs/core';
-import { makeCellRangeToRangeData } from '@univerjs/core';
+import { ColorKit, makeCellRangeToRangeData } from '@univerjs/core';
import { getCellInfoInMergeData } from '@univerjs/engine-render';
export const SELECTION_CONTROL_BORDER_BUFFER_WIDTH = 1; // The draggable range of the selection is too thin, making it easy for users to miss. Therefore, a buffer gap is provided to make it easier for users to select.
@@ -144,7 +143,7 @@ export interface ISelectionWithStyle extends ISelection {
// The default configuration of the selection.
export function getNormalSelectionStyle(themeService: ThemeService): ISelectionStyle {
const styleSheet = themeService.getCurrentTheme();
- const fill = new TinyColor(styleSheet.colorBlack).setAlpha(0.1).toString();
+ const fill = new ColorKit(styleSheet.colorBlack).setAlpha(0.1).toRgbString();
return {
strokeWidth: 1.5,
stroke: styleSheet.primaryColor,
diff --git a/packages/sheets/vite.config.ts b/packages/sheets/vite.config.ts
index 5dee4827c5..aca522727b 100644
--- a/packages/sheets/vite.config.ts
+++ b/packages/sheets/vite.config.ts
@@ -29,7 +29,6 @@ export default defineConfig(({ mode }) => ({
},
rollupOptions: {
external: [
- '@ctrl/tinycolor',
'@univerjs/core',
'@univerjs/engine-formula',
'@univerjs/engine-render',
@@ -39,7 +38,6 @@ export default defineConfig(({ mode }) => ({
],
output: {
globals: {
- '@ctrl/tinycolor': 'tinycolor',
'@univerjs/core': 'UniverCore',
'@univerjs/engine-formula': 'UniverEngineFormula',
'@univerjs/engine-render': 'UniverEngineRender',
diff --git a/packages/ui/package.json b/packages/ui/package.json
index a85d52c3a2..f8b635adc6 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -54,7 +54,6 @@
"rc-util": "^5.38.1"
},
"devDependencies": {
- "@ctrl/tinycolor": "^4.0.2",
"@testing-library/react": "^14.1.2",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
@@ -77,7 +76,6 @@
"vitest": "^1.0.4"
},
"peerDependencies": {
- "@ctrl/tinycolor": ">=4.0.0",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
diff --git a/packages/ui/src/components/custom-label/CustomLabel.tsx b/packages/ui/src/components/custom-label/CustomLabel.tsx
index 9c31361ce2..52622453ab 100644
--- a/packages/ui/src/components/custom-label/CustomLabel.tsx
+++ b/packages/ui/src/components/custom-label/CustomLabel.tsx
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-import { TinyColor } from '@ctrl/tinycolor';
-import { LocaleService } from '@univerjs/core';
+import { ColorKit, LocaleService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React from 'react';
import type { Observable } from 'rxjs';
@@ -59,7 +58,7 @@ export function CustomLabel(props: ICustomLabelProps): JSX.Element | null {
}
// if value is not valid, use primary color
- const { isValid } = new TinyColor(realValue);
+ const { isValid } = new ColorKit(realValue?.toString());
if (icon) {
const Icon = componentManager.get(realIcon ?? '');
diff --git a/packages/ui/vite.config.ts b/packages/ui/vite.config.ts
index bbc726e53a..19a73e5a9f 100644
--- a/packages/ui/vite.config.ts
+++ b/packages/ui/vite.config.ts
@@ -37,7 +37,6 @@ export default defineConfig(({ mode }) => ({
},
rollupOptions: {
external: [
- '@ctrl/tinycolor',
'@univerjs/core',
'@univerjs/design',
'@univerjs/engine-render',
@@ -52,7 +51,6 @@ export default defineConfig(({ mode }) => ({
output: {
assetFileNames: 'index.css',
globals: {
- '@ctrl/tinycolor': 'tinycolor',
'@univerjs/core': 'UniverCore',
'@univerjs/design': 'UniverDesign',
'@univerjs/engine-render': 'UniverEngineRender',
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index da2122974f..280a216fb2 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -560,9 +560,6 @@ importers:
packages/docs:
devDependencies:
- '@ctrl/tinycolor':
- specifier: ^4.0.2
- version: 4.0.2
'@univerjs/core':
specifier: workspace:*
version: link:../core
@@ -905,9 +902,6 @@ importers:
packages/sheets:
devDependencies:
- '@ctrl/tinycolor':
- specifier: ^4.0.2
- version: 4.0.2
'@univerjs/core':
specifier: workspace:*
version: link:../core
@@ -1008,9 +1002,6 @@ importers:
specifier: ^0.1.18
devDependencies:
- '@ctrl/tinycolor':
- specifier: ^4.0.2
- version: 4.0.2
'@types/react':
specifier: ^18.2.42
version: 18.2.42
@@ -1190,9 +1181,6 @@ importers:
specifier: ^0.1.18
devDependencies:
- '@ctrl/tinycolor':
- specifier: ^4.0.2
- version: 4.0.2
'@types/react':
specifier: ^18.2.42
version: 18.2.42
@@ -1368,9 +1356,6 @@ importers:
specifier: ^5.38.1
devDependencies:
- '@ctrl/tinycolor':
- specifier: ^4.0.2
- version: 4.0.2
'@testing-library/react':
specifier: ^14.1.2
@@ -4327,11 +4312,6 @@ packages:
engines: {node: '>=10'}
dev: false
- resolution: {integrity: sha512-fKQinXE9pJ83J1n+C3rDl2xNLJwfoYNvXLRy5cYZA9hBJJw2q+sbb/AOSNKmLxnTWyNTmy4994dueSwP4opi5g==}
- engines: {node: '>=14'}
- dev: true
-
/@discoveryjs/[email protected]:
resolution: {integrity: sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==}
engines: {node: '>=10.0.0'}
@@ -8219,7 +8199,7 @@ packages:
magicast: 0.3.2
picocolors: 1.0.0
test-exclude: 6.0.0
+ vitest: 1.0.4(@types/[email protected])
transitivePeerDependencies:
- supports-color
dev: true