Skip to content

Commit 702a455

Browse files
authored
revert: "fix(docs): follow theme colors on canvas surfaces" (#7515)
1 parent e0b1e27 commit 702a455

8 files changed

Lines changed: 85 additions & 25 deletions

File tree

packages/docs-ui/src/controllers/__tests__/doc-header-footer.controller.spec.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
LocaleService,
2323
} from '@univerjs/core';
2424
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
25-
import { DocumentEditArea, IRenderManagerService, Path } from '@univerjs/engine-render';
25+
import { DocumentEditArea, IRenderManagerService, Path, Rect } from '@univerjs/engine-render';
2626
import { BehaviorSubject, Subject } from 'rxjs';
2727
import { afterEach, describe, expect, it, vi } from 'vitest';
2828
import { CloseHeaderFooterCommand } from '../../commands/commands/doc-header-footer.command';
@@ -151,8 +151,46 @@ describe('DocHeaderFooterController', () => {
151151
controller.dispose();
152152
});
153153

154-
it('draws header/footer guides while editing header or footer', () => {
154+
it('covers header and footer areas while editing the document body', () => {
155+
const { controller, pageRender$ } = createController({ editArea: DocumentEditArea.BODY });
156+
const rectSpy = vi.spyOn(Rect, 'drawWith').mockImplementation(() => undefined);
157+
const pathSpy = vi.spyOn(Path, 'drawWith').mockImplementation(() => undefined);
158+
const textSpy = vi.spyOn(TextBubbleShape, 'drawWith').mockImplementation(() => undefined);
159+
const ctx = createCtx();
160+
161+
pageRender$.next({
162+
ctx,
163+
pageLeft: 12,
164+
pageTop: 24,
165+
page: {
166+
pageWidth: 200,
167+
pageHeight: 300,
168+
marginTop: 30,
169+
marginBottom: 40,
170+
},
171+
});
172+
173+
expect(ctx.translate).toHaveBeenCalledWith(11.5, 23.5);
174+
expect(rectSpy).toHaveBeenCalledTimes(2);
175+
expect(rectSpy.mock.calls[0][1]).toMatchObject({
176+
width: 200,
177+
height: 30,
178+
fill: 'alpha(white, 0.5)',
179+
});
180+
expect(rectSpy.mock.calls[1][1]).toMatchObject({
181+
width: 200,
182+
height: 40,
183+
fill: 'alpha(white, 0.5)',
184+
});
185+
expect(pathSpy).not.toHaveBeenCalled();
186+
expect(textSpy).not.toHaveBeenCalled();
187+
188+
controller.dispose();
189+
});
190+
191+
it('covers the body and draws header/footer guides while editing header or footer', () => {
155192
const { controller, pageRender$ } = createController({ editArea: DocumentEditArea.HEADER });
193+
const rectSpy = vi.spyOn(Rect, 'drawWith').mockImplementation(() => undefined);
156194
const pathSpy = vi.spyOn(Path, 'drawWith').mockImplementation(() => undefined);
157195
const textSpy = vi.spyOn(TextBubbleShape, 'drawWith').mockImplementation(() => undefined);
158196
const ctx = createCtx();
@@ -169,6 +207,11 @@ describe('DocHeaderFooterController', () => {
169207
},
170208
});
171209

210+
expect(rectSpy).toHaveBeenCalledWith(ctx, expect.objectContaining({
211+
top: 30,
212+
width: 200,
213+
height: 230,
214+
}));
172215
expect(pathSpy).toHaveBeenCalledTimes(2);
173216
expect(pathSpy).toHaveBeenCalledWith(ctx, expect.objectContaining({ stroke: 'primary.600' }));
174217
expect(textSpy).toHaveBeenCalledWith(ctx, expect.objectContaining({

packages/docs-ui/src/controllers/__tests__/doc-render-controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function createControllerFixture(options?: {
235235
describe('doc render controller', () => {
236236
it.each([
237237
[DocumentFlavor.TRADITIONAL, 'gray.100'],
238-
[DocumentFlavor.MODERN, 'token(white)'],
238+
[DocumentFlavor.MODERN, 'white'],
239239
])('resolves the %s workspace background again when dark mode changes', (documentFlavor, backgroundToken) => {
240240
const { canvasColorService, canvasElement, darkMode$ } = createControllerFixture({ documentFlavor });
241241
canvasColorService.getRenderColor.mockImplementation((color: string) => `dark:${color}`);

packages/docs-ui/src/controllers/doc-header-footer.controller.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ import {
4141
UniverInstanceType,
4242
} from '@univerjs/core';
4343
import { DocSkeletonManagerService, HeaderFooterType, RichTextEditingMutation } from '@univerjs/docs';
44-
import { DocumentEditArea, IRenderManagerService, PageLayoutType, Path, Vector2 } from '@univerjs/engine-render';
44+
import { DocumentEditArea, IRenderManagerService, PageLayoutType, Path, Rect, Vector2 } from '@univerjs/engine-render';
4545
import { neoGetDocObject } from '../basics/component-tools';
4646
import { CloseHeaderFooterCommand, CoreHeaderFooterCommand } from '../commands/commands/doc-header-footer.command';
4747
import { IEditorService } from '../services/editor/editor-manager.service';
4848
import { DocSelectionRenderService } from '../services/selection/doc-selection-render.service';
4949
import { getDocPageSectionContext } from '../utils/section-header-footer';
5050
import { TextBubbleShape } from '../views/header-footer/text-bubble';
5151

52+
const HEADER_FOOTER_COVER_COLOR = 'alpha(white, 0.5)';
5253
const HEADER_FOOTER_STROKE_COLOR = 'primary.600';
5354
const HEADER_FOOTER_LABEL_COLOR = 'alpha(primary.600, 0.08)';
5455

@@ -306,6 +307,7 @@ export class DocHeaderFooterController extends Disposable implements IRenderModu
306307

307308
this.disposeWithMe(
308309
toDisposable(
310+
// eslint-disable-next-line max-lines-per-function
309311
docsComponent.pageRender$.subscribe((config: IPageRenderConfig) => {
310312
if (this._editorService.isEditor(unitId)) {
311313
return;
@@ -325,6 +327,38 @@ export class DocHeaderFooterController extends Disposable implements IRenderModu
325327
ctx.save();
326328
ctx.translate(pageLeft - 0.5, pageTop - 0.5);
327329

330+
// Cover header and footer.
331+
if (isEditBody) {
332+
Rect.drawWith(ctx, {
333+
left: 0,
334+
top: 0,
335+
width: pageWidth,
336+
height: marginTop,
337+
fill: HEADER_FOOTER_COVER_COLOR,
338+
});
339+
ctx.save();
340+
ctx.translate(0, pageHeight - marginBottom);
341+
Rect.drawWith(ctx, {
342+
left: 0,
343+
top: 0,
344+
width: pageWidth,
345+
height: marginBottom,
346+
fill: HEADER_FOOTER_COVER_COLOR,
347+
});
348+
ctx.restore();
349+
} else { // Cover body.
350+
ctx.save();
351+
ctx.translate(0, marginTop);
352+
Rect.drawWith(ctx, {
353+
left: 0,
354+
top: marginTop,
355+
width: pageWidth,
356+
height: pageHeight - marginTop - marginBottom,
357+
fill: HEADER_FOOTER_COVER_COLOR,
358+
});
359+
ctx.restore();
360+
}
361+
328362
if (!isEditBody) {
329363
const headerPathConfigIPathProps = {
330364
dataArray: [{

packages/docs-ui/src/services/doc-render-background.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const DOC_MODERN_WORKSPACE_BACKGROUND_COLOR = 'var(--univer-white)';
2222
const DOC_UNSPECIFIED_WORKSPACE_BACKGROUND_COLOR = 'var(--univer-gray-100)';
2323
const DOC_EDITOR_INTERNAL_BACKGROUND_COLOR = 'transparent';
2424
const DOC_TRADITIONAL_WORKSPACE_BACKGROUND_TOKEN = 'gray.100';
25-
const DOC_MODERN_WORKSPACE_BACKGROUND_TOKEN = 'token(white)';
25+
const DOC_MODERN_WORKSPACE_BACKGROUND_TOKEN = 'white';
2626

2727
export interface IResolveDocRenderBackgroundOptions {
2828
documentFlavor?: DocumentFlavor;

packages/engine-render/src/components/docs/__tests__/doc-background.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('DocBackground', () => {
7575
background.draw(createCtx());
7676

7777
expect(rectDraw.mock.calls[0][1]).toMatchObject({ fill: 'gray.100' });
78-
expect(rectDraw.mock.calls[1][1]).toMatchObject({ fill: 'token(white)' });
78+
expect(rectDraw.mock.calls[1][1]).toMatchObject({ fill: 'white' });
7979

8080
background.dispose();
8181
});
@@ -91,7 +91,7 @@ describe('DocBackground', () => {
9191
background.draw(createCtx());
9292

9393
expect(rectDraw).toHaveBeenCalledTimes(1);
94-
expect(rectDraw.mock.calls[0][1]).toMatchObject({ fill: 'token(white)' });
94+
expect(rectDraw.mock.calls[0][1]).toMatchObject({ fill: 'white' });
9595

9696
background.dispose();
9797
});

packages/engine-render/src/components/docs/doc-background.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { DocComponent } from './doc-component';
2525
import { Liquid } from './liquid';
2626

2727
const PAGE_STROKE_COLOR = 'gray.200';
28-
const PAGE_FILL_COLOR = 'token(white)';
28+
const PAGE_FILL_COLOR = 'white';
2929
const UNSPECIFIED_PAGE_FILL_COLOR = 'gray.50';
3030
const DOCS_WORKSPACE_FILL_COLOR = 'gray.100';
3131
const MARGIN_STROKE_COLOR = 'gray.300';

packages/engine-render/src/services/__tests__/canvas-color.service.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,16 @@ describe('CanvasColorService', () => {
5353

5454
expect(service.getRenderColor('gray.50')).toBe('#0d1422');
5555
expect(service.getRenderColor('white')).toBe('white');
56-
expect(service.getRenderColor('token(white)')).toBe('#07111f');
5756

5857
themeService.setTheme({
5958
...theme,
60-
white: '#050914',
6159
gray: {
6260
...theme.gray,
6361
50: '#101827',
6462
},
6563
});
6664

6765
expect(service.getRenderColor('gray.50')).toBe('#101827');
68-
expect(service.getRenderColor('token(white)')).toBe('#050914');
6966
});
7067

7168
it('applies dark rendering to resolved design tokens', () => {
@@ -164,7 +161,6 @@ describe('CanvasColorService', () => {
164161

165162
expect(() => service.getRenderColor('alpha(gray.50, 1.1)')).toThrow('[CanvasColorService]: illegal color');
166163
expect(() => service.getRenderColor('alpha(not-a-color, 0.5)')).toThrow('[CanvasColorService]: illegal color');
167-
expect(() => service.getRenderColor('token(not-a-color)')).toThrow('[CanvasColorService]: illegal color');
168164
});
169165

170166
it('maps render colors for dark mode rendering', () => {

packages/engine-render/src/services/canvas-color.service.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ const DARK_RENDER_COLOR_OVERRIDES: Record<string, string> = {
7171

7272
const COLOR_MIX_REGEXP = /^mix\(\s*([^,()]+)\s*,\s*([^,()]+)\s*,\s*(0(?:\.\d+)?|1(?:\.0+)?)\s*\)$/;
7373
const COLOR_ALPHA_REGEXP = /^alpha\(\s*([^,()]+)\s*,\s*(0(?:\.\d+)?|1(?:\.0+)?)\s*\)$/;
74-
const THEME_TOKEN_REGEXP = /^token\(\s*([^,()]+)\s*\)$/;
7574

7675
/**
7776
* This service inverts a color for dark mode. This service is exposed
@@ -152,18 +151,6 @@ export class CanvasColorService extends Disposable implements ICanvasColorServic
152151
return cachedColor;
153152
}
154153

155-
const tokenMatch = inputColor.match(THEME_TOKEN_REGEXP);
156-
if (tokenMatch) {
157-
const token = tokenMatch[1].trim();
158-
const color = this._themeService.getColorFromTheme<unknown>(token);
159-
if (typeof color !== 'string' || !this._themeService.isValidThemeColor(token)) {
160-
throw new Error(`[CanvasColorService]: illegal color "${inputColor}"`);
161-
}
162-
163-
this._resolvedColorCache.set(inputColor, color);
164-
return color;
165-
}
166-
167154
const mixMatch = inputColor.match(COLOR_MIX_REGEXP);
168155
if (mixMatch) {
169156
const color1 = this._resolveThemeColor(mixMatch[1].trim());

0 commit comments

Comments
 (0)