Skip to content

开源白板工具(SaaS),一体化白板,包含思维导图、流程图、自由画等。All in one open-source whiteboard tool with mind, flowchart, freehand and etc.

feat: support opacity for color property (#16)

pubuzhixing8c824763154cf
diff --git a/packages/drawnix/src/components/color-picker.tsx b/packages/drawnix/src/components/color-picker.tsx
index 474da7e..825df0c 100644
--- a/packages/drawnix/src/components/color-picker.tsx
+++ b/packages/drawnix/src/components/color-picker.tsx
@@ -2,27 +2,17 @@ import { useState } from 'react';
import { Check, TransparentIcon } from './icons';
import Stack from '../components/stack';
import './color-picker.scss';
-import { splitRows } from '../utils';
+import { splitRows } from '../utils/common';
+import {
+ applyOpacityToHex,
+ hexAlphaToOpacity,
+ isDefaultStroke,
+ isTransparent,
+ removeHexAlpha,
+} from '../utils/color';
import React from 'react';
import { SizeSlider } from './size-slider';
-
-const CLASSIC_COLORS = [
- { name: 'Transparent', value: 'transparent' },
- { name: 'Black', value: '#000000' },
- { name: 'White', value: '#FFFFFF' },
- { name: 'Gray', value: '#808080' },
- { name: 'Deep Blue', value: '#1E90FF' },
- { name: 'Red', value: '#FF4500' },
- { name: 'Green', value: '#2ECC71' },
- { name: 'Yellow', value: '#FFD700' },
- { name: 'Purple', value: '#8A2BE2' },
- { name: 'Orange', value: '#FFA500' },
- { name: 'Pastel Pink', value: '#FFB3BA' },
- { name: 'Cyan', value: '#00CED1' },
- { name: 'Brown', value: '#8B4513' },
- { name: 'Forest Green', value: '#228B22' },
- { name: 'Light Gray', value: '#D3D3D3' },
-];
+import { CLASSIC_COLORS, DEFAULT_COLOR, WHITE } from '../constants/color';
const ROWS_CLASSIC_COLORS = splitRows(CLASSIC_COLORS, 4);
@@ -34,15 +24,22 @@ export type ColorPickerProps = {
export const ColorPicker = React.forwardRef((props: ColorPickerProps, ref) => {
const { onSelect, currentColor } = props;
const [selectedColor, setSelectedColor] = useState(
- currentColor || ROWS_CLASSIC_COLORS[0][0].value
+ removeHexAlpha(currentColor || ROWS_CLASSIC_COLORS[0][0].value)
+ );
+ const [opacity, setOpacity] = useState(
+ hexAlphaToOpacity(currentColor || ROWS_CLASSIC_COLORS[0][0].value)
);
return (
<>
<Stack.Col gap={3}>
<SizeSlider
step={5}
- defaultValue={100}
- onChange={(value) => {}}
+ defaultValue={opacity}
+ onChange={(value) => {
+ setOpacity(value);
+ onSelect(applyOpacityToHex(selectedColor, value));
+ }}
+ disabled={selectedColor === CLASSIC_COLORS[0]['value']}
></SizeSlider>
<Stack.Col gap={2}>
{ROWS_CLASSIC_COLORS.map((colors, index) => (
@@ -53,18 +50,24 @@ export const ColorPicker = React.forwardRef((props: ColorPickerProps, ref) => {
key={color.value}
className={`color-select-item ${
selectedColor === color.value ? 'active' : ''
- } ${color.value === 'transparent' ? 'transparent' : ''}`}
+ } ${isTransparent(color.value) ? 'transparent' : ''}`}
style={{
backgroundColor: color.value,
- color: color.value === '#000000' ? '#FFFFFF' : '#000000',
+ color: isDefaultStroke(color.value)
+ ? WHITE
+ : DEFAULT_COLOR,
}}
onClick={() => {
setSelectedColor(color.value);
- onSelect(color.value);
+ if (opacity !== 100) {
+ onSelect(applyOpacityToHex(color.value, opacity));
+ } else {
+ onSelect(color.value);
+ }
}}
title={color.name}
>
- {color.value === 'transparent' && TransparentIcon}
+ {isTransparent(color.value) && TransparentIcon}
{selectedColor === color.value && Check}
</button>
);
diff --git a/packages/drawnix/src/components/dropdown-menu/common.ts b/packages/drawnix/src/components/dropdown-menu/common.ts
index c595845..237a753 100644
--- a/packages/drawnix/src/components/dropdown-menu/common.ts
+++ b/packages/drawnix/src/components/dropdown-menu/common.ts
@@ -1,6 +1,6 @@
import React, { useContext } from "react";
import { EVENT } from "../../constants";
-import { composeEventHandlers } from "../../utils";
+import { composeEventHandlers } from "../../utils/common";
export const DropdownMenuContentPropsContext = React.createContext<{
onSelect?: (event: Event) => void;
diff --git a/packages/drawnix/src/components/icons.tsx b/packages/drawnix/src/components/icons.tsx
index b019012..cea34b4 100644
--- a/packages/drawnix/src/components/icons.tsx
+++ b/packages/drawnix/src/components/icons.tsx
@@ -234,14 +234,12 @@ export const OpenFileIcon = createIcon(
);
export const BackgroundColorIcon = createIcon(
- <svg viewBox="0 0 24 24" className="background-color-icon">
- <g
- xmlns="http://www.w3.org/2000/svg"
- transform="translate(1 1)"
- fillRule="evenodd"
- fill="#000"
- stroke="none"
- >
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 24 24"
+ className="background-color-icon"
+ >
+ <g transform="translate(1 1)" fillRule="evenodd" fill="#000" stroke="none">
<circle fillOpacity=".04" r="11" cy="11" cx="11"></circle>
<path
d="M17 20.221V17h3.221A11.06 11.06 0 0 1 17 20.221zm-12 0A11.06 11.06 0 0 1 1.779 17H5v3.221zM20.221 5H17V1.779A11.06 11.06 0 0 1 20.221 5zM9 .181V1H6.411A10.919 10.919 0 0 1 9 .181zM15.589 1H13V.181c.907.167 1.775.445 2.589.819zM13 21.819V21h2.589c-.814.374-1.682.652-2.589.819zm-4 0A10.919 10.919 0 0 1 6.411 21H9v.819zm-8-6.23A10.919 10.919 0 0 1 .181 13H1v2.589zm0-9.178V9H.181C.348 8.093.626 7.225 1 6.411zM21.819 9H21V6.411c.374.814.652 1.682.819 2.589zM21 15.589V13h.819A10.919 10.919 0 0 1 21 15.589zM5 1.779V5H1.779A11.06 11.06 0 0 1 5 1.779zM5 13h4v4H5v-4zm8 0h4v4h-4v-4zM5 5h4v4H5V5zm8 0h4v4h-4V5zm0 12v4H9v-4h4zm8-8v4h-4V9h4zm-8 0v4H9V9h4zM5 9v4H1V9h4zm8-8v4H9V1h4z"
@@ -301,6 +299,33 @@ export const StrokeIcon = createIcon(
</svg>
);
+export const StrokeWhiteIcon = createIcon(
+ <svg viewBox="0 0 24 24" className="transparent-icon">
+ <g
+ xmlns="http://www.w3.org/2000/svg"
+ id="icon-border-white"
+ stroke="none"
+ strokeWidth="1"
+ fill="none"
+ fillRule="evenodd"
+ opacity="0.1"
+ >
+ <g id="Group">
+ <path
+ d="M12,22 C17.5228475,22 22,17.5228475 22,12 C22,6.4771525 17.5228475,2 12,2 C6.4771525,2 2,6.4771525 2,12 C2,17.5228475 6.4771525,22 12,22 Z M12,23 C5.92486775,23 1,18.0751322 1,12 C1,5.92486775 5.92486775,1 12,1 C18.0751322,1 23,5.92486775 23,12 C23,18.0751322 18.0751322,23 12,23 Z"
+ fill="#000000"
+ fillRule="nonzero"
+ />
+ <path
+ d="M12,19 C15.8659932,19 19,15.8659932 19,12 C19,8.13400675 15.8659932,5 12,5 C8.13400675,5 5,8.13400675 5,12 C5,15.8659932 8.13400675,19 12,19 Z M12,20 C7.581722,20 4,16.418278 4,12 C4,7.581722 7.581722,4 12,4 C16.418278,4 20,7.581722 20,12 C20,16.418278 16.418278,20 12,20 Z"
+ fill="#000000"
+ fillRule="nonzero"
+ />
+ </g>
+ </g>
+ </svg>
+);
+
export const StrokeStyleNormalIcon = createIcon(
<svg viewBox="0 0 24 32" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(0 14)" fillRule="evenodd" fill="none">
diff --git a/packages/drawnix/src/components/main-menu/default-items.tsx b/packages/drawnix/src/components/main-menu/default-items.tsx
index 5aa7203..d6f4fa0 100644
--- a/packages/drawnix/src/components/main-menu/default-items.tsx
+++ b/packages/drawnix/src/components/main-menu/default-items.tsx
@@ -21,7 +21,7 @@ import {
updateViewportOffset,
Viewport,
} from '@plait/core';
-import { base64ToBlob, boardToImage, download } from '../../utils';
+import { base64ToBlob, boardToImage, download } from '../../utils/common';
import { loadFromJSON, saveAsJSON } from '../../data/json';
export const SaveToFile = () => {
diff --git a/packages/drawnix/src/components/main-menu/main-menu.tsx b/packages/drawnix/src/components/main-menu/main-menu.tsx
index 3e6eba7..054f5c0 100644
--- a/packages/drawnix/src/components/main-menu/main-menu.tsx
+++ b/packages/drawnix/src/components/main-menu/main-menu.tsx
@@ -3,7 +3,7 @@ import classNames from 'classnames';
import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';
import DropdownMenu from '../dropdown-menu/DropdownMenu';
import { MenuIcon } from '../icons';
-import { composeEventHandlers } from '../../utils';
+import { composeEventHandlers } from '../../utils/common';
import { OpenFile, SaveAsImage, SaveToFile, Socials } from './default-items';
type MainMenuProps = {
diff --git a/packages/drawnix/src/components/popup-toolbar/fill-button.tsx b/packages/drawnix/src/components/popup-toolbar/fill-button.tsx
index 190d09f..7236f03 100644
--- a/packages/drawnix/src/components/popup-toolbar/fill-button.tsx
+++ b/packages/drawnix/src/components/popup-toolbar/fill-button.tsx
@@ -14,10 +14,11 @@ import {
import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';
import { Island } from '../island';
import { ColorPicker } from '../color-picker';
+import { isTransparent, removeHexAlpha } from '../../utils/color';
+import { BackgroundColorIcon } from '../icons';
export type PopupFillButtonProps = {
currentColor: string | undefined;
- transparentIcon: ReactNode;
title: string;
children?: React.ReactNode;
onColorSelect: (selectedColor: string) => void;
@@ -25,7 +26,6 @@ export type PopupFillButtonProps = {
export const PopupFillButton: React.FC<PopupFillButtonProps> = ({
currentColor,
- transparentIcon,
title,
children,
onColorSelect,
@@ -45,23 +45,24 @@ export const PopupFillButton: React.FC<PopupFillButtonProps> = ({
const { getReferenceProps } = useInteractions([click, dismiss, role]);
+ const hexColor = currentColor && removeHexAlpha(currentColor);
+
+ let icon =
+ !hexColor || isTransparent(hexColor) ? BackgroundColorIcon : undefined;
+
return (
<>
<ToolButton
className={classNames(`property-button`)}
visible={true}
- icon={
- currentColor && currentColor !== 'transparent'
- ? undefined
- : transparentIcon
- }
+ icon={icon}
type="button"
title={title}
aria-label={title}
ref={refs.setReference}
{...getReferenceProps()}
>
- {currentColor && currentColor !== 'transparent' && children}
+ {!icon && children}
</ToolButton>
{isOpen && (
<Island
diff --git a/packages/drawnix/src/components/popup-toolbar/popup-toolbar.scss b/packages/drawnix/src/components/popup-toolbar/popup-toolbar.scss
index 80eb975..0ae42e4 100644
--- a/packages/drawnix/src/components/popup-toolbar/popup-toolbar.scss
+++ b/packages/drawnix/src/components/popup-toolbar/popup-toolbar.scss
@@ -7,8 +7,8 @@
}
.fill-label {
display: inline-block;
- width: var(--xlg-icon-size);
- height: var(--xlg-icon-size);
+ width: var(--popup-label-size);
+ height: var(--popup-label-size);
border-radius: 50%;
&.color-white {
border: 1px solid var(--color-gray-30);
@@ -16,8 +16,8 @@
}
.stroke-label {
border-radius: 50%;
- width: calc(var(--xlg-icon-size) - var(--border-radius-lg));
- height: calc(var(--xlg-icon-size) - var(--border-radius-lg));
+ width: calc(var(--popup-label-size) - var(--border-radius-lg));
+ height: calc(var(--popup-label-size) - var(--border-radius-lg));
border-width: var(--border-radius-sm);
border-style: solid;
}
diff --git a/packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsx b/packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsx
index 0ebedf0..ccd0117 100644
--- a/packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsx
+++ b/packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsx
@@ -1,5 +1,5 @@
import Stack from '../stack';
-import { BackgroundColorIcon, FontColorIcon, StrokeIcon } from '../icons';
+import { FontColorIcon } from '../icons';
import {
ATTACHED_ELEMENT_CLASS_NAME,
getSelectedElements,
@@ -38,6 +38,7 @@ import {
import { PopupFontColorButton } from './font-color-button';
import { PopupStrokeButton } from './stroke-button';
import { PopupFillButton } from './fill-button';
+import { isWhite } from '../../utils/color';
export type PopupToolbarProps = {};
@@ -147,7 +148,7 @@ export const PopupToolbar: React.FC<PopupToolbarProps> = ({}) => {
{state.hasFontColor && (
<PopupFontColorButton
key={0}
- currentColor={state.fontColor}
+ currentColor={state.marks?.color}
title={`Font Color`}
fontColorIcon={
<FontColorIcon currentColor={state.marks?.color} />
@@ -165,9 +166,7 @@ export const PopupToolbar: React.FC<PopupToolbarProps> = ({}) => {
<PopupStrokeButton
key={1}
currentColor={state.strokeColor}
- // currentOpacity={state}
title={`Stroke`}
- transparentIcon={StrokeIcon}
onColorSelect={(selectedColor: string) => {
console.log(`selectedColor: ${selectedColor}`);
PropertyTransforms.setStrokeColor(board, selectedColor, {
@@ -176,9 +175,7 @@ export const PopupToolbar: React.FC<PopupToolbarProps> = ({}) => {
}}
>
<label
- className={classNames('stroke-label', 'color-label', {
- 'color-white': state.fill === '#FFFFFF',
- })}
+ className={classNames('stroke-label', 'color-label')}
style={{ borderColor: state.strokeColor }}
></label>
</PopupStrokeButton>
@@ -187,7 +184,6 @@ export const PopupToolbar: React.FC<PopupToolbarProps> = ({}) => {
key={2}
currentColor={state.fill}
title={`Fill Color`}
- transparentIcon={BackgroundColorIcon}
onColorSelect={(selectedColor: string) => {
PropertyTransforms.setFillColor(board, selectedColor, {
getMemorizeKey,
@@ -216,7 +212,7 @@ export const PopupToolbar: React.FC<PopupToolbarProps> = ({}) => {
>
<label
className={classNames('fill-label', 'color-label', {
- 'color-white': state.fill === '#FFFFFF',
+ 'color-white': isWhite(state.fill),
})}
style={{ backgroundColor: state.fill }}
></label>
diff --git a/packages/drawnix/src/components/popup-toolbar/stroke-button.tsx b/packages/drawnix/src/components/popup-toolbar/stroke-button.tsx
index 10108d9..1552aaf 100644
--- a/packages/drawnix/src/components/popup-toolbar/stroke-button.tsx
+++ b/packages/drawnix/src/components/popup-toolbar/stroke-button.tsx
@@ -14,10 +14,11 @@ import {
import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';
import { Island } from '../island';
import { ColorPicker } from '../color-picker';
+import { isTransparent, isWhite, removeHexAlpha } from '../../utils/color';
+import { StrokeIcon, StrokeWhiteIcon } from '../icons';
export type PopupStrokeButtonProps = {
currentColor: string | undefined;
- transparentIcon: ReactNode;
title: string;
children?: React.ReactNode;
onColorSelect: (selectedColor: string) => void;
@@ -25,7 +26,6 @@ export type PopupStrokeButtonProps = {
export const PopupStrokeButton: React.FC<PopupStrokeButtonProps> = ({
currentColor,
- transparentIcon,
title,
children,
onColorSelect,
@@ -45,23 +45,27 @@ export const PopupStrokeButton: React.FC<PopupStrokeButtonProps> = ({
const { getReferenceProps } = useInteractions([click, dismiss, role]);
+ const hexColor = currentColor && removeHexAlpha(currentColor);
+
+ let icon = isTransparent(hexColor)
+ ? StrokeIcon
+ : isWhite(hexColor)
+ ? StrokeWhiteIcon
+ : undefined;
+
return (
<>
<ToolButton
className={classNames(`property-button`)}
visible={true}
- icon={
- currentColor && currentColor !== 'transparent'
- ? undefined
- : transparentIcon
- }
+ icon={icon}
type="button"
title={title}
aria-label={title}
ref={refs.setReference}
{...getReferenceProps()}
>
- {currentColor && currentColor !== 'transparent' && children}
+ {!icon && children}
</ToolButton>
{isOpen && (
<Island
diff --git a/packages/drawnix/src/components/size-slider.scss b/packages/drawnix/src/components/size-slider.scss
index e6851d3..a9e6f61 100644
--- a/packages/drawnix/src/components/size-slider.scss
+++ b/packages/drawnix/src/components/size-slider.scss
@@ -2,6 +2,9 @@
.slider-container {
padding: 10px 0px;
+ &.disabled {
+ opacity: 50%;
+ }
.slider-track {
position: relative;
height: 4px;
diff --git a/packages/drawnix/src/components/size-slider.tsx b/packages/drawnix/src/components/size-slider.tsx
index e2105c7..42f52c5 100644
--- a/packages/drawnix/src/components/size-slider.tsx
+++ b/packages/drawnix/src/components/size-slider.tsx
@@ -1,12 +1,14 @@
import React, { useState, useRef, useCallback, useEffect } from 'react';
import { toFixed } from '@plait/core';
import './size-slider.scss';
+import classNames from 'classnames';
interface SliderProps {
min?: number;
max?: number;
step?: number;
defaultValue?: number;
+ disabled?: boolean;
onChange?: (value: number) => void;
}
@@ -15,21 +17,23 @@ export const SizeSlider: React.FC<SliderProps> = ({
max = 100,
step = 1,
defaultValue = 100,
+ disabled = false,
onChange,
}) => {
const [value, setValue] = useState(defaultValue);
- const [thumbPercentage, setThumbPercentage] = useState(defaultValue);
+ const thumbPercentageRef = useRef(0);
const sliderRef = useRef<HTMLDivElement>(null);
const thumbRef = useRef<HTMLDivElement>(null);
+
useEffect(() => {
if (sliderRef.current && thumbRef.current) {
const sliderRect = sliderRef.current.getBoundingClientRect();
const thumbRect = thumbRef.current.getBoundingClientRect();
- setThumbPercentage(
- toFixed((thumbRect.width / 2 / sliderRect.width) * 100)
+ thumbPercentageRef.current = toFixed(
+ (thumbRect.width / 2 / sliderRect.width) * 100
);
}
- }, [thumbRef.current, sliderRef.current]);
+ }, [thumbRef, sliderRef]);
const handleSliderChange = useCallback(
(event: React.MouseEvent<HTMLDivElement> | MouseEvent) => {
@@ -37,14 +41,15 @@ export const SizeSlider: React.FC<SliderProps> = ({
const sliderRect = sliderRef.current.getBoundingClientRect();
const x = event.clientX - sliderRect.left;
let percentage = Math.min(Math.max(x / sliderRect.width, 0), 1);
- if (percentage >= (100 - thumbPercentage) / 100) {
+ if (percentage >= (100 - thumbPercentageRef.current) / 100) {
percentage = 1;
- } else if (percentage <= thumbPercentage / 100) {
+ } else if (percentage <= thumbPercentageRef.current / 100) {
percentage = 0;
}
const newValue =
Math.round((percentage * (max - min)) / step) * step + min;
setValue(newValue);
+ console.log(`newValue: ${newValue}`);
onChange && onChange(newValue);
}
},
@@ -63,21 +68,29 @@ export const SizeSlider: React.FC<SliderProps> = ({
}, [handleSliderChange]);
let percentage = ((value - min) / (max - min)) * 100;
- if (percentage >= 100 - thumbPercentage) {
- percentage = 100 - thumbPercentage;
+ if (percentage >= 100 - thumbPercentageRef.current) {
+ percentage = 100 - thumbPercentageRef.current;
}
- if (percentage <= thumbPercentage) {
- percentage = thumbPercentage;
+ if (percentage <= thumbPercentageRef.current) {
+ percentage = thumbPercentageRef.current;
}
return (
- <div className="slider-container">
+ <div className={classNames('slider-container', { disabled: disabled })}>
<div
ref={sliderRef}
className="slider-track"
- onClick={handleSliderChange}
+ onClick={(event) => {
+ if (disabled) {
+ return;
+ }
+ handleSliderChange(event);
+ }}
onPointerDown={(event) => {
event.preventDefault();
+ if (disabled) {
+ return;
+ }
handlePointerDown();
}}
>
diff --git a/packages/drawnix/src/components/tool-button.tsx b/packages/drawnix/src/components/tool-button.tsx
index ba1aeab..df5d403 100644
--- a/packages/drawnix/src/components/tool-button.tsx
+++ b/packages/drawnix/src/components/tool-button.tsx
@@ -4,7 +4,7 @@ import './tool-icon.scss';
import type { CSSProperties } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { AbortError } from '../errors';
-import { isPromiseLike } from '../utils';
+import { isPromiseLike } from '../utils/common';
import classNames from 'classnames';
import { EventPointerType } from '../types';
diff --git a/packages/drawnix/src/components/toolbar/shape-panel.tsx b/packages/drawnix/src/components/toolbar/shape-panel.tsx
index 0d472c0..386059e 100644
--- a/packages/drawnix/src/components/toolbar/shape-panel.tsx
+++ b/packages/drawnix/src/components/toolbar/shape-panel.tsx
@@ -15,7 +15,7 @@ import React from 'react';
import { BoardCreationMode, setCreationMode } from '@plait/common';
import { BasicShapes, DrawPointerType } from '@plait/draw';
import { useBoard } from '@plait/react-board';
-import { splitRows } from '../../utils';
+import { splitRows } from '../../utils/common';
export interface ShapeProps {
icon: React.ReactNode;
diff --git a/packages/drawnix/src/constants/color.ts b/packages/drawnix/src/constants/color.ts
new file mode 100644
index 0000000..a435f03
--- /dev/null
+++ b/packages/drawnix/src/constants/color.ts
@@ -0,0 +1,23 @@
+export const TRANSPARENT = 'TRANSPARENT';
+
+export const DEFAULT_COLOR = '#333333';
+
+export const WHITE = '#FFFFFF';
+
+export const CLASSIC_COLORS = [
+ { name: 'Transparent', value: TRANSPARENT },
+ { name: 'Default', value: DEFAULT_COLOR },
+ { name: 'White', value: WHITE },
+ { name: 'Gray', value: '#808080' },
+ { name: 'Deep Blue', value: '#1E90FF' },
+ { name: 'Red', value: '#FF4500' },
+ { name: 'Green', value: '#2ECC71' },
+ { name: 'Yellow', value: '#FFD700' },
+ { name: 'Purple', value: '#8A2BE2' },
+ { name: 'Orange', value: '#FFA500' },
+ { name: 'Pastel Pink', value: '#FFB3BA' },
+ { name: 'Cyan', value: '#00CED1' },
+ { name: 'Brown', value: '#8B4513' },
+ { name: 'Forest Green', value: '#228B22' },
+ { name: 'Light Gray', value: '#D3D3D3' },
+];
diff --git a/packages/drawnix/src/styles/theme.scss b/packages/drawnix/src/styles/theme.scss
index 4177c22..7030f55 100644
--- a/packages/drawnix/src/styles/theme.scss
+++ b/packages/drawnix/src/styles/theme.scss
@@ -16,7 +16,8 @@
--default-icon-size: 1rem;
--lg-button-size: 2.25rem;
--lg-icon-size: 1.125rem;
- --xlg-icon-size: 1.375rem;
+ --xlg-icon-size: 1.5rem;
+ --popup-label-size: 1.375rem;
--editor-container-padding: 1rem;
@media screen and (min-device-width: 1921px) {
diff --git a/packages/drawnix/src/utils/color.ts b/packages/drawnix/src/utils/color.ts
new file mode 100644
index 0000000..d2267b5
--- /dev/null
+++ b/packages/drawnix/src/utils/color.ts
@@ -0,0 +1,66 @@
+import { DEFAULT_COLOR, TRANSPARENT, WHITE } from '../constants/color';
+
+// 将 0-100 的透明度转换为 0-255 的整数
+function transparencyToAlpha255(transparency: number) {
+ return Math.round(((100 - transparency) / 100) * 255);
+}
+
+// 将 0-255 的 alpha 值转换为 0-100 的透明度
+function alpha255ToTransparency(alpha255: number) {
+ return Math.round((1 - alpha255 / 255) * 100);
+}
+
+export function applyOpacityToHex(hexColor: string, opacity: number) {
+ const alpha = transparencyToAlpha255(100 - opacity);
+ const alphaHex = alpha.toString(16).padStart(2, '0');
+ return `${hexColor}${alphaHex}`;
+}
+
+export function hexAlphaToOpacity(hexColor: string) {
+ // 移除可能存在的 # 前缀
+ hexColor = hexColor.replace(/^#/, '');
+
+ let alpha;
+ if (hexColor.length === 8) {
+ // 8位十六进制,提取最后两位作为 alpha 值
+ alpha = parseInt(hexColor.slice(6, 8), 16);
+ } else if (hexColor.length === 4) {
+ // 4位十六进制(简写形式),提取最后一位并重复
+ alpha = parseInt(hexColor.slice(3, 4).repeat(2), 16);
+ } else {
+ // 如果没有 alpha 通道,则认为是完全不透明
+ return 100;
+ }
+
+ return 100 - alpha255ToTransparency(alpha);
+}
+
+export function removeHexAlpha(hexColor: string) {
+ // 移除可能存在的 # 前缀,并转换为大写
+ const hexColorClone = hexColor.replace(/^#/, '').toUpperCase();
+
+ if (hexColorClone.length === 8) {
+ // 8位十六进制,移除最后两位
+ return '#' + hexColorClone.slice(0, 6);
+ } else if (hexColorClone.length === 4) {
+ // 4位十六进制(简写形式),移除最后一位
+ return '#' + hexColorClone.slice(0, 3);
+ } else if (hexColorClone.length === 6 || hexColorClone.length === 3) {
+ // 已经是标准的 6 位或 3 位形式,直接返回
+ return '#' + hexColorClone;
+ } else {
+ return hexColor;
+ }
+}
+
+export function isTransparent(color?: string) {
+ return color === TRANSPARENT;
+}
+
+export function isWhite(color?: string) {
+ return color === WHITE;
+}
+
+export function isDefaultStroke(color?: string) {
+ return !color || color === DEFAULT_COLOR;
+}
diff --git a/packages/drawnix/src/utils.ts b/packages/drawnix/src/utils/common.ts
similarity index 100%
rename from packages/drawnix/src/utils.ts
rename to packages/drawnix/src/utils/common.ts
diff --git a/packages/drawnix/src/utility-types.ts b/packages/drawnix/src/utils/utility-types.ts
similarity index 100%
rename from packages/drawnix/src/utility-types.ts
rename to packages/drawnix/src/utils/utility-types.ts