@univerjs/engine-render 0.6.10 → 0.7.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import { ICanvasColorService } from './services/canvas-color.service';
1
2
  import { UniverRenderingContext } from './context';
2
3
  /**
3
4
  * canvas render mode
@@ -15,11 +16,12 @@ export declare enum CanvasRenderMode {
15
16
  Printing = 1
16
17
  }
17
18
  interface ICanvasProps {
19
+ colorService?: ICanvasColorService;
20
+ id?: string;
18
21
  width?: number;
19
22
  height?: number;
20
23
  pixelRatio?: number;
21
24
  mode?: CanvasRenderMode;
22
- id?: string;
23
25
  }
24
26
  /**
25
27
  * View Renderer constructor. It is a wrapper around native canvas element.
@@ -38,7 +40,7 @@ export declare class Canvas {
38
40
  private _context;
39
41
  private _width;
40
42
  private _height;
41
- constructor(props?: ICanvasProps);
43
+ constructor(_props?: ICanvasProps);
42
44
  getCanvasEle(): HTMLCanvasElement;
43
45
  /**
44
46
  * get canvas context
@@ -1,4 +1,8 @@
1
+ import { ICanvasColorService } from './services/canvas-color.service';
1
2
  import { IRenderConfig } from './services/render-config';
3
+ export interface IUniverRenderingContextOptions {
4
+ canvasColorService?: ICanvasColorService;
5
+ }
2
6
  export declare class UniverRenderingContext2D implements CanvasRenderingContext2D {
3
7
  __mode: string;
4
8
  private _transformCache;
@@ -7,7 +11,8 @@ export declare class UniverRenderingContext2D implements CanvasRenderingContext2
7
11
  private _systemType;
8
12
  private _browserType;
9
13
  renderConfig: Readonly<IRenderConfig>;
10
- constructor(context: CanvasRenderingContext2D);
14
+ private _canvasColorService?;
15
+ constructor(context: CanvasRenderingContext2D, options?: IUniverRenderingContextOptions);
11
16
  private _id;
12
17
  getId(): string;
13
18
  setId(id: string): void;
@@ -6,6 +6,7 @@ import { Scene } from './scene';
6
6
  import { Disposable, EventSubject } from '@univerjs/core';
7
7
  import { Observable, Subject } from 'rxjs';
8
8
  import { Canvas, CanvasRenderMode } from './canvas';
9
+ import { ICanvasColorService } from './services/canvas-color.service';
9
10
  export interface IEngineOption {
10
11
  elementWidth: number;
11
12
  elementHeight: number;
@@ -13,6 +14,7 @@ export interface IEngineOption {
13
14
  renderMode?: CanvasRenderMode;
14
15
  }
15
16
  export declare class Engine extends Disposable {
17
+ readonly canvasColorService?: ICanvasColorService | undefined;
16
18
  renderEvenInBackground: boolean;
17
19
  private readonly _beginFrame$;
18
20
  readonly beginFrame$: Observable<number>;
@@ -23,8 +25,8 @@ export declare class Engine extends Disposable {
23
25
  /**
24
26
  * Pass event to scene.input-manager
25
27
  */
26
- onInputChanged$: EventSubject<IEvent>;
27
- onTransformChange$: EventSubject<ITransformChangeState>;
28
+ readonly onInputChanged$: EventSubject<IEvent>;
29
+ readonly onTransformChange$: EventSubject<ITransformChangeState>;
28
30
  private _scenes;
29
31
  private _activeScene;
30
32
  /**
@@ -38,9 +40,6 @@ export declare class Engine extends Disposable {
38
40
  private _renderingQueueLaunched;
39
41
  private _renderFrameTasks;
40
42
  private _requestNewFrameHandler;
41
- /**
42
- * frameCount
43
- */
44
43
  private _frameId;
45
44
  private _usingSafari;
46
45
  private _resizeObserver;
@@ -70,16 +69,13 @@ export declare class Engine extends Disposable {
70
69
  private _previousWidth;
71
70
  private _previousHeight;
72
71
  private _unitId;
73
- constructor();
74
- constructor(unitId: string, options?: IEngineOption);
75
- constructor(elemW: number, elemH: number, dpr?: number, renderMode?: CanvasRenderMode);
76
- _init(): void;
77
72
  get unitId(): string;
78
73
  get elapsedTime(): number;
79
74
  get width(): number;
80
75
  get height(): number;
81
76
  get classType(): RENDER_CLASS_TYPE;
82
77
  get activeScene(): Scene | null;
78
+ constructor(unitId?: string, _options?: IEngineOption, canvasColorService?: ICanvasColorService | undefined);
83
79
  getScenes(): {
84
80
  [sceneKey: string]: Scene;
85
81
  };
@@ -18,7 +18,6 @@ export * from './basics';
18
18
  export { getOffsetRectForDom } from './basics/position';
19
19
  export * from './canvas';
20
20
  export * from './components';
21
- export { UniverRenderConfigService } from './services/render-config.service';
22
21
  export { DocBackground } from './components/docs/doc-background';
23
22
  export { Documents } from './components/docs/document';
24
23
  export type { IPageRenderConfig } from './components/docs/document';
@@ -40,7 +39,8 @@ export * from './engine';
40
39
  export * from './group';
41
40
  export * from './layer';
42
41
  export { IRenderingEngine, UniverRenderEnginePlugin } from './plugin';
43
- export { getCurrentTypeOfRenderer, IRenderManagerService, type RenderComponentType, RenderManagerService, withCurrentTypeOfRenderer } from './render-manager/render-manager.service';
42
+ export { getCurrentTypeOfRenderer, IRenderManagerService, type RenderComponentType, RenderManagerService, withCurrentTypeOfRenderer, } from './render-manager/render-manager.service';
43
+ export { CanvasColorService, DumbCanvasColorService, ICanvasColorService } from './services/canvas-color.service';
44
44
  export { type IRender, type IRenderContext, type IRenderModule, RenderUnit } from './render-manager/render-unit';
45
45
  export * from './scene';
46
46
  export { type IChangeObserverConfig } from './scene.transformer';
@@ -3,6 +3,8 @@ import { IConfigService, Injector, Plugin } from '@univerjs/core';
3
3
  import { Engine } from './engine';
4
4
  /**
5
5
  * The global rendering engine.
6
+ *
7
+ * @deprecated There will be no more default global render engine in the future.
6
8
  */
7
9
  export declare const IRenderingEngine: import('@wendellhu/redi').IdentifierDecorator<Engine>;
8
10
  export declare class UniverRenderEnginePlugin extends Plugin {
@@ -11,4 +13,5 @@ export declare class UniverRenderEnginePlugin extends Plugin {
11
13
  private readonly _configService;
12
14
  static pluginName: string;
13
15
  constructor(_config: Partial<IUniverEngineRenderConfig> | undefined, _injector: Injector, _configService: IConfigService);
16
+ onStarting(): void;
14
17
  }
@@ -44,8 +44,8 @@ export interface IRenderManagerService extends IDisposable {
44
44
  registerRenderModule<T extends UnitModel>(type: UnitType, dep: Dependency<T>): IDisposable;
45
45
  }
46
46
  export declare class RenderManagerService extends Disposable implements IRenderManagerService {
47
- private readonly _injector;
48
- private readonly _univerInstanceService;
47
+ protected readonly _injector: Injector;
48
+ protected readonly _univerInstanceService: IUniverInstanceService;
49
49
  private _defaultEngine;
50
50
  private _renderMap;
51
51
  private readonly _createRender$;
@@ -305,7 +305,6 @@ export declare class Scene extends Disposable {
305
305
  triggerDragOver(evt: IDragEvent): boolean;
306
306
  triggerDragEnter(evt: IDragEvent): boolean;
307
307
  triggerDrop(evt: IDragEvent): boolean;
308
- private _createDefaultLayer;
309
308
  /**
310
309
  * Triggered when scale, resize of scene.
311
310
  * origin name: _setTransForm
@@ -0,0 +1,25 @@
1
+ import { RGBColor } from './utils';
2
+ import { Disposable, ThemeService } from '@univerjs/core';
3
+ export declare const ICanvasColorService: import('@wendellhu/redi').IdentifierDecorator<ICanvasColorService>;
4
+ /**
5
+ * This service maps a color or a theme-token to a color for rendering. Univer supports themes for rendering
6
+ * and dark mode. This services is responsible for abstract this complexity for rendering components.
7
+ */
8
+ export interface ICanvasColorService {
9
+ getRenderColor(color: string): string;
10
+ }
11
+ export declare class DumbCanvasColorService implements ICanvasColorService {
12
+ getRenderColor(color: string): string;
13
+ }
14
+ /**
15
+ * This service inverts a color for dark mode. This service is exposed
16
+ */
17
+ export declare class CanvasColorService extends Disposable implements ICanvasColorService {
18
+ private readonly _themeService;
19
+ private readonly _cache;
20
+ private _invertAlgo;
21
+ constructor(_themeService: ThemeService);
22
+ getRenderColor(color: string): string;
23
+ }
24
+ export declare function hexToRgb(_hex: string): RGBColor;
25
+ export declare function rgbToHex(rgbColor: RGBColor): string;
@@ -0,0 +1,3 @@
1
+ import { RGBColor } from './utils';
2
+ export declare function stringToRgb(color: string): RGBColor;
3
+ export declare function invertColorByHSL(color: RGBColor): RGBColor;
@@ -0,0 +1,7 @@
1
+ import { RGBColor } from './utils';
2
+ /**
3
+ * Invert a color by RGB matrix method.
4
+ * @param color The color to invert. Note that this color is already normalized.
5
+ * @returns The inverted color.
6
+ */
7
+ export declare function invertColorByMatrix(color: RGBColor): RGBColor;
@@ -16,6 +16,8 @@
16
16
  /**
17
17
  * This service carries managers render config that would be passed
18
18
  * to every widget, so some rendering could be optimized.
19
+ *
20
+ * @deprecated Will be replaced by ICanvasColorService.
19
21
  */
20
22
  export declare class UniverRenderConfigService {
21
23
  private readonly _renderConfig;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export type RGBColor = [number, number, number];
17
+ export type HSLColor = RGBColor;
18
+ export declare function normalizeRGBColor(color: RGBColor): RGBColor;
19
+ export declare function denormalizeRGBColor(color: RGBColor): RGBColor;
@@ -178,7 +178,7 @@ export declare class Viewport {
178
178
  bufferEdgeX: number;
179
179
  bufferEdgeY: number;
180
180
  constructor(viewportKey: string, scene: Scene, props?: IViewProps);
181
- initCacheCanvas(props?: IViewProps): void;
181
+ initCacheCanvas(props: IViewProps | undefined, scene: Scene): void;
182
182
  get scene(): Scene;
183
183
  get width(): Nullable<number>;
184
184
  get height(): Nullable<number>;