Skip to content

Commit

Permalink
feat(editor): store real color values in edgeless
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Dec 27, 2024
1 parent 37d772c commit ca19347
Show file tree
Hide file tree
Showing 291 changed files with 2,242 additions and 1,538 deletions.
2 changes: 1 addition & 1 deletion blocksuite/affine/block-frame/src/frame-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class FrameBlockComponent extends GfxBlockComponent<FrameBlockModel> {
const { model, showBorder, std } = this;
const backgroundColor = std
.get(ThemeProvider)
.generateColorProperty(model.background, '--affine-platte-transparent');
.generateColorProperty(model.background, 'transparent');
const _isNavigator =
this.gfx.tool.currentToolName$.value === 'frameNavigator';
const frameIndex = this.gfx.layer.getZIndex(model);
Expand Down
18 changes: 13 additions & 5 deletions blocksuite/affine/block-note/src/note-edgeless-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
import { MoreIndicatorIcon } from '@blocksuite/affine-components/icons';
import type { NoteBlockModel } from '@blocksuite/affine-model';
import {
DEFAULT_NOTE_BACKGROUND_COLOR,
DefaultTheme,
NoteDisplayMode,
StrokeStyle,
} from '@blocksuite/affine-model';
Expand All @@ -24,6 +24,7 @@ import {
WithDisposable,
} from '@blocksuite/global/utils';
import type { BlockModel } from '@blocksuite/store';
import { computed } from '@preact/signals-core';
import { css, html, nothing } from 'lit';
import { property, query, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
Expand Down Expand Up @@ -141,6 +142,16 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent(
}
`;

private readonly _backgroundColor$ = computed(() => {
const themeProvider = this.std.get(ThemeProvider);
const theme = themeProvider.theme$.value;
return themeProvider.generateColorProperty(
this.model.background$.value,
DefaultTheme.noteBackgrounColor,
theme
);
});

private get _isShowCollapsedContent() {
return this.model.edgeless.collapse && (this._isResizing || this._isHover);
}
Expand Down Expand Up @@ -406,9 +417,6 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent(
};

const extra = this._editing ? ACTIVE_NOTE_EXTRA_PADDING : 0;
const backgroundColor = this.std
.get(ThemeProvider)
.generateColorProperty(model.background, DEFAULT_NOTE_BACKGROUND_COLOR);

const backgroundStyle = {
position: 'absolute',
Expand All @@ -420,7 +428,7 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent(
transition: this._editing
? 'left 0.3s, top 0.3s, width 0.3s, height 0.3s'
: 'none',
backgroundColor,
backgroundColor: this._backgroundColor$.value,
border: `${borderSize}px ${
borderStyle === StrokeStyle.Dash ? 'dashed' : borderStyle
} var(--affine-black-10)`,
Expand Down
11 changes: 5 additions & 6 deletions blocksuite/affine/block-surface/src/renderer/canvas-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import type { ElementRenderer } from './elements/index.js';
import type { Overlay } from './overlay.js';

type EnvProvider = {
generateColorProperty: (color: Color, fallback: string) => string;
generateColorProperty: (color: Color, fallback?: Color) => string;
getColorScheme: () => ColorScheme;
getColorValue: (color: Color, fallback?: string, real?: boolean) => string;
getColorValue: (color: Color, fallback?: Color, real?: boolean) => string;
getPropertyValue: (property: string) => string;
selectedElements?: () => string[];
};
Expand Down Expand Up @@ -368,10 +368,9 @@ export class CanvasRenderer {
this._disposables.dispose();
}

generateColorProperty(color: Color, fallback: string) {
generateColorProperty(color: Color, fallback?: Color) {
return (
this.provider.generateColorProperty?.(color, fallback) ??
(fallback.startsWith('--') ? `var(${fallback})` : fallback)
this.provider.generateColorProperty?.(color, fallback) ?? 'transparent'
);
}

Expand Down Expand Up @@ -409,7 +408,7 @@ export class CanvasRenderer {
return this.provider.getColorScheme?.() ?? ColorScheme.Light;
}

getColorValue(color: Color, fallback?: string, real?: boolean) {
getColorValue(color: Color, fallback?: Color, real?: boolean) {
return (
this.provider.getColorValue?.(color, fallback, real) ?? 'transparent'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BrushElementModel } from '@blocksuite/affine-model';
import { type BrushElementModel, DefaultTheme } from '@blocksuite/affine-model';

import type { CanvasRenderer } from '../../canvas-renderer.js';

Expand All @@ -17,7 +17,7 @@ export function brush(
matrix.translateSelf(cx, cy).rotateSelf(rotate).translateSelf(-cx, -cy)
);

const color = renderer.getColorValue(model.color, '#000000', true);
const color = renderer.getColorValue(model.color, DefaultTheme.black, true);

ctx.fillStyle = color;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type ConnectorElementModel,
ConnectorMode,
DefaultTheme,
type LocalConnectorElementModel,
type PointStyle,
} from '@blocksuite/affine-model';
Expand Down Expand Up @@ -75,7 +76,11 @@ export function connector(
ctx.clip(path, 'evenodd');
}

const strokeColor = renderer.getColorValue(model.stroke, '#000000', true);
const strokeColor = renderer.getColorValue(
model.stroke,
DefaultTheme.connectorColor,
true
);

renderPoints(
model,
Expand Down Expand Up @@ -249,7 +254,7 @@ function renderLabel(
ctx.font = font;
ctx.textAlign = textAlign;
ctx.textBaseline = 'middle';
ctx.fillStyle = renderer.getColorValue(color, '#000000', true);
ctx.fillStyle = renderer.getColorValue(color, DefaultTheme.black, true);

let textMaxWidth = textAlign === 'center' ? 0 : getMaxTextWidth(lines, font);
if (hasMaxWidth && maxWidth > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import type {
ShapeElementModel,
ShapeType,
} from '@blocksuite/affine-model';
import {
DEFAULT_SHAPE_FILL_COLOR,
DEFAULT_SHAPE_STROKE_COLOR,
DEFAULT_SHAPE_TEXT_COLOR,
TextAlign,
} from '@blocksuite/affine-model';
import { DefaultTheme, TextAlign } from '@blocksuite/affine-model';
import type { IBound } from '@blocksuite/global/utils';
import { Bound } from '@blocksuite/global/utils';
import { deltaInsertsToChunks } from '@blocksuite/inline';
Expand Down Expand Up @@ -55,17 +50,17 @@ export function shape(
) {
const color = renderer.getColorValue(
model.color,
DEFAULT_SHAPE_TEXT_COLOR,
DefaultTheme.shapeTextColor,
true
);
const fillColor = renderer.getColorValue(
model.fillColor,
DEFAULT_SHAPE_FILL_COLOR,
DefaultTheme.shapeFillColor,
true
);
const strokeColor = renderer.getColorValue(
model.strokeColor,
DEFAULT_SHAPE_STROKE_COLOR,
DefaultTheme.shapeStrokeColor,
true
);
const colors = { color, fillColor, strokeColor };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TextElementModel } from '@blocksuite/affine-model';
import { DefaultTheme, type TextElementModel } from '@blocksuite/affine-model';
import { deltaInsertsToChunks } from '@blocksuite/inline';

import type { CanvasRenderer } from '../../canvas-renderer.js';
Expand Down Expand Up @@ -39,7 +39,11 @@ export function text(
const horizontalOffset =
textAlign === 'center' ? w / 2 : textAlign === 'right' ? w : 0;

const color = renderer.getColorValue(model.color, '#000000', true);
const color = renderer.getColorValue(
model.color,
DefaultTheme.textColor,
true
);

ctx.font = font;
ctx.fillStyle = color;
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/block-surface/src/surface-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ export class SurfaceBlockComponent extends BlockComponent<
gridManager: gfx.grid,
enableStackingCanvas: true,
provider: {
generateColorProperty: (color: Color, fallback: string) =>
generateColorProperty: (color: Color, fallback?: Color) =>
themeService.generateColorProperty(
color,
fallback,
themeService.edgelessTheme
),
getColorValue: (color: Color, fallback?: string, real?: boolean) =>
getColorValue: (color: Color, fallback?: Color, real?: boolean) =>
themeService.getColorValue(
color,
fallback,
Expand Down
1 change: 1 addition & 0 deletions blocksuite/affine/components/src/toolbar/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { unsafeCSS } from 'lit';
const toolbarColorKeys: Array<keyof AffineCssVariables> = [
'--affine-background-overlay-panel-color',
'--affine-v2-layer-background-overlayPanel' as never,
'--affine-v2-layer-insideBorder-blackBorder' as never,
'--affine-background-error-color',
'--affine-background-primary-color',
'--affine-background-tertiary-color',
Expand Down
2 changes: 1 addition & 1 deletion blocksuite/affine/model/src/blocks/frame/frame-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { Bound } from '@blocksuite/global/utils';
import { BlockModel, defineBlockSchema, type Text } from '@blocksuite/store';

import type { Color } from '../../consts/index.js';
import type { Color } from '../../themes/index.js';

export type FrameBlockProps = {
title: Text;
Expand Down
5 changes: 2 additions & 3 deletions blocksuite/affine/model/src/blocks/note/note-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { Bound } from '@blocksuite/global/utils';
import { BlockModel, defineBlockSchema } from '@blocksuite/store';

import {
type Color,
DEFAULT_NOTE_BACKGROUND_COLOR,
DEFAULT_NOTE_BORDER_SIZE,
DEFAULT_NOTE_BORDER_STYLE,
DEFAULT_NOTE_CORNER,
Expand All @@ -18,12 +16,13 @@ import {
NoteDisplayMode,
type StrokeStyle,
} from '../../consts/index.js';
import { type Color, DefaultTheme } from '../../themes/index.js';

export const NoteBlockSchema = defineBlockSchema({
flavour: 'affine:note',
props: (): NoteProps => ({
xywh: `[0,0,${DEFAULT_NOTE_WIDTH},${DEFAULT_NOTE_HEIGHT}]`,
background: DEFAULT_NOTE_BACKGROUND_COLOR,
background: DefaultTheme.noteBackgrounColor,
index: 'a0',
lockedBySelf: false,
hidden: false,
Expand Down
3 changes: 0 additions & 3 deletions blocksuite/affine/model/src/consts/brush.ts

This file was deleted.

97 changes: 0 additions & 97 deletions blocksuite/affine/model/src/consts/color.ts

This file was deleted.

5 changes: 0 additions & 5 deletions blocksuite/affine/model/src/consts/connector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createEnumMap } from '../utils/enum.js';
import { StrokeColor } from './color.js';

export enum ConnectorEndpoint {
Front = 'Front',
Expand All @@ -16,10 +15,6 @@ export enum PointStyle {

export const PointStyleMap = createEnumMap(PointStyle);

export const DEFAULT_CONNECTOR_COLOR = StrokeColor.Grey;

export const DEFAULT_CONNECTOR_TEXT_COLOR = StrokeColor.Black;

export const DEFAULT_FRONT_END_POINT_STYLE = PointStyle.None;

export const DEFAULT_REAR_END_POINT_STYLE = PointStyle.Arrow;
Expand Down
3 changes: 0 additions & 3 deletions blocksuite/affine/model/src/consts/frame.ts

This file was deleted.

3 changes: 0 additions & 3 deletions blocksuite/affine/model/src/consts/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export * from './brush.js';
export * from './color.js';
export * from './connector.js';
export * from './doc.js';
export * from './frame.js';
export * from './image.js';
export * from './line.js';
export * from './mindmap.js';
Expand Down
Loading

0 comments on commit ca19347

Please sign in to comment.