@univerjs/engine-render 0.4.0-alpha.1 → 0.4.0-experimental.d7288c0-20241017

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.
package/lib/es/index.js CHANGED
@@ -4286,6 +4286,9 @@ const _Canvas = class _Canvas {
4286
4286
  getHeight() {
4287
4287
  return this._height;
4288
4288
  }
4289
+ setId(id) {
4290
+ this._canvasEle.id = id;
4291
+ }
4289
4292
  setSize(width, height, pixelRatioParam) {
4290
4293
  var _a10;
4291
4294
  this._pixelRatio = pixelRatioParam || getDevicePixelRatio();
@@ -25808,9 +25811,9 @@ const UNIQUE_KEY$6 = "DefaultFontExtension", _Font = class _Font extends SheetEx
25808
25811
  renderFontContext.cellInfo = cellInfo, this.renderFontEachCell(renderFontContext, range.startRow, range.startColumn, fontMatrix);
25809
25812
  }), ctx.restore();
25810
25813
  }
25811
- renderFontEachCell(renderFontContext, row, col, fontMatrix) {
25814
+ renderFontEachCell(renderFontCtx, row, col, fontMatrix) {
25812
25815
  var _a10;
25813
- const { ctx, viewRanges, diffRanges, spreadsheetSkeleton, cellInfo } = renderFontContext;
25816
+ const { ctx, viewRanges, diffRanges, spreadsheetSkeleton, cellInfo } = renderFontCtx;
25814
25817
  let { startY, endY, startX, endX } = cellInfo;
25815
25818
  const { isMerged, isMergedMainCell, mergeInfo } = cellInfo;
25816
25819
  if (isMerged && !isMergedMainCell)
@@ -25826,9 +25829,16 @@ const UNIQUE_KEY$6 = "DefaultFontExtension", _Font = class _Font extends SheetEx
25826
25829
  const cellData = spreadsheetSkeleton.worksheet.getCell(row, col) || {};
25827
25830
  if ((_a10 = cellData.fontRenderExtension) != null && _a10.isSkip)
25828
25831
  return !0;
25829
- ctx.save(), ctx.beginPath(), renderFontContext.overflowRectangle = overflowRange, renderFontContext.cellData = cellData, renderFontContext.startX = startX, renderFontContext.startY = startY, renderFontContext.endX = endX, renderFontContext.endY = endY, this._clipTextOverflow(renderFontContext, row, col, fontMatrix), ctx.translate(startX + FIX_ONE_PIXEL_BLUR_OFFSET, startY + FIX_ONE_PIXEL_BLUR_OFFSET), this._renderDocuments(ctx, fontsConfig, startX, startY, endX, endY, row, col, spreadsheetSkeleton.overflowCache), ctx.closePath(), ctx.restore();
25832
+ ctx.save(), ctx.beginPath(), renderFontCtx.overflowRectangle = overflowRange, renderFontCtx.cellData = cellData, renderFontCtx.startX = startX, renderFontCtx.startY = startY, renderFontCtx.endX = endX, renderFontCtx.endY = endY, this._setFontRenderBounds(renderFontCtx, row, col, fontMatrix), ctx.translate(startX + FIX_ONE_PIXEL_BLUR_OFFSET, startY + FIX_ONE_PIXEL_BLUR_OFFSET), this._renderDocuments(ctx, fontsConfig, renderFontCtx.startX, renderFontCtx.startY, renderFontCtx.endX, renderFontCtx.endY, row, col, spreadsheetSkeleton.overflowCache), ctx.closePath(), ctx.restore();
25830
25833
  }
25831
- _clipTextOverflow(renderFontContext, row, col, fontMatrix) {
25834
+ /**
25835
+ * Change font render bounds, for overflow and filter icon & custom render.
25836
+ * @param renderFontContext
25837
+ * @param row
25838
+ * @param col
25839
+ * @param fontMatrix
25840
+ */
25841
+ _setFontRenderBounds(renderFontContext, row, col, fontMatrix) {
25832
25842
  var _a10, _b, _c, _d;
25833
25843
  const { ctx, scale, overflowRectangle, rowHeightAccumulation, columnWidthAccumulation, cellData } = renderFontContext;
25834
25844
  let { startX, endX, startY, endY } = renderFontContext;
@@ -25876,14 +25886,15 @@ const UNIQUE_KEY$6 = "DefaultFontExtension", _Font = class _Font extends SheetEx
25876
25886
  );
25877
25887
  } else
25878
25888
  ctx.rectByPrecision(startX + 1 / scale, startY + 1 / scale, cellWidth - 2 / scale, cellHeight - 2 / scale), ctx.clip();
25889
+ renderFontContext.startX = startX, renderFontContext.startY = startY, renderFontContext.endX = endX, renderFontContext.endY = endY;
25879
25890
  }
25880
- _renderDocuments(ctx, docsConfig, startX, startY, endX, endY, row, column, overflowCache) {
25891
+ _renderDocuments(ctx, docsConfig, startX, startY, endX, endY, row, col, overflowCache) {
25881
25892
  const documents = this.getDocuments();
25882
25893
  if (documents == null)
25883
25894
  throw new Error("documents is null");
25884
25895
  const { documentSkeleton, vertexAngle = 0, wrapStrategy } = docsConfig, cellHeight = endY - startY, cellWidth = endX - startX;
25885
25896
  wrapStrategy === WrapStrategy.WRAP && vertexAngle === 0 ? (documentSkeleton.getViewModel().getDataModel().updateDocumentDataPageSize(cellWidth), documentSkeleton.calculate()) : documentSkeleton.getViewModel().getDataModel().updateDocumentDataPageSize(Number.POSITIVE_INFINITY);
25886
- const overflowRectangle = overflowCache.getValue(row, column);
25897
+ const overflowRectangle = overflowCache.getValue(row, col);
25887
25898
  if (!(wrapStrategy === WrapStrategy.WRAP && !overflowRectangle && vertexAngle === 0)) {
25888
25899
  const contentSize = getDocsSkeletonPageSize(documentSkeleton), documentStyle = documentSkeleton.getViewModel().getDataModel().getSnapshot().documentStyle;
25889
25900
  if (contentSize && documentStyle) {
@@ -26232,7 +26243,7 @@ const UNIQUE_KEY$2 = "DefaultDocsBorderExtension", _Border = class _Border exten
26232
26243
  __name(_Border, "Border");
26233
26244
  let Border = _Border;
26234
26245
  DocumentsSpanAndLineExtensionRegistry.add(new Border());
26235
- const SHAPE_OBJECT_ARRAY = [
26246
+ const BASE_OBJECT_ARRAY_Set = new Set(BASE_OBJECT_ARRAY), SHAPE_OBJECT_ARRAY = [
26236
26247
  "hoverCursor",
26237
26248
  "moveCursor",
26238
26249
  "fillRule",
@@ -26410,7 +26421,7 @@ const SHAPE_OBJECT_ARRAY = [
26410
26421
  return themeKeys.length === 0 ? this : (themeKeys.forEach((key) => {
26411
26422
  if (props[key] === void 0)
26412
26423
  return !0;
26413
- BASE_OBJECT_ARRAY.indexOf(key) === -1 && (this[`_${key}`] = props[key]);
26424
+ BASE_OBJECT_ARRAY_Set.has(key) || (this[`_${key}`] = props[key]);
26414
26425
  }), this.makeDirty(!0), this);
26415
26426
  }
26416
26427
  toJson() {
@@ -26432,10 +26443,15 @@ const SHAPE_OBJECT_ARRAY = [
26432
26443
  return;
26433
26444
  const transformState = {};
26434
26445
  let hasTransformState = !1;
26446
+ const hasRotateEnabled = (props == null ? void 0 : props.rotateEnabled) !== void 0, hasResizeEnabled = (props == null ? void 0 : props.resizeEnabled) !== void 0;
26447
+ if (hasRotateEnabled || hasResizeEnabled) {
26448
+ const transformerConfig = this.transformerConfig || {};
26449
+ hasRotateEnabled && (transformerConfig.rotateEnabled = props == null ? void 0 : props.rotateEnabled), hasResizeEnabled && (transformerConfig.resizeEnabled = props == null ? void 0 : props.resizeEnabled), this.transformerConfig = { ...transformerConfig };
26450
+ }
26435
26451
  themeKeys.forEach((key) => {
26436
26452
  if (props[key] === void 0)
26437
26453
  return !0;
26438
- BASE_OBJECT_ARRAY.indexOf(key) > -1 ? (transformState[key] = props[key], hasTransformState = !0) : this[`_${key}`] = props[key];
26454
+ BASE_OBJECT_ARRAY_Set.has(key) ? (transformState[key] = props[key], hasTransformState = !0) : this[`_${key}`] = props[key];
26439
26455
  }), hasTransformState && this.transformByState(transformState), this.makeDirty(!0);
26440
26456
  }
26441
26457
  };
@@ -27907,9 +27923,10 @@ const UNIQUE_KEY$1 = "DefaultDocsFontAndBaseLineExtension", DOC_EXTENSION_Z_INDE
27907
27923
  else {
27908
27924
  const CHECKED_GLYPH = "☑";
27909
27925
  if ((content === "☐" || content === CHECKED_GLYPH) && glyph.glyphType === GlyphType.LIST) {
27910
- ctx.save();
27911
27926
  const size = Math.ceil(((_b = (_a10 = glyph.ts) == null ? void 0 : _a10.fs) != null ? _b : 12) * 1.2);
27912
- ctx.translate(spanPointWithFont.x, spanPointWithFont.y - size), Checkbox.drawWith(ctx, {
27927
+ ctx.save();
27928
+ const fontHeight = glyph.bBox.aba - glyph.bBox.abd, bottom = spanPointWithFont.y, top = bottom - fontHeight, left = spanPointWithFont.x, topOffset = top + (bottom - top - size) / 2, leftOffset = left, BORDER_WIDTH = 1;
27929
+ ctx.translate(leftOffset - BORDER_WIDTH / 2, topOffset - BORDER_WIDTH / 2), Checkbox.drawWith(ctx, {
27913
27930
  width: size,
27914
27931
  height: size,
27915
27932
  checked: content === CHECKED_GLYPH
@@ -27934,11 +27951,11 @@ const UNIQUE_KEY = "DefaultDocsLineExtension", DOC_EXTENSION_Z_INDEX = 40, _Line
27934
27951
  }
27935
27952
  draw(ctx, parentScale, glyph) {
27936
27953
  var _a10;
27937
- const line2 = (_a10 = glyph.parent) == null ? void 0 : _a10.parent, { ts: textStyle, bBox, content } = glyph;
27954
+ const line2 = (_a10 = glyph.parent) == null ? void 0 : _a10.parent, { renderConfig } = this.extensionOffset, vertexAngle = (renderConfig == null ? void 0 : renderConfig.vertexAngle) || 0, drawStrikeAndUnderline = !(((renderConfig == null ? void 0 : renderConfig.centerAngle) || 0) === 0 && vertexAngle !== 0 && vertexAngle % 90 === 0), { ts: textStyle, bBox, content } = glyph;
27938
27955
  if (line2 == null || textStyle == null || content === "\r")
27939
27956
  return;
27940
27957
  const { asc, dsc } = line2, { sp: strikeoutPosition, spo, sbo, bd } = bBox, scale = getScale(parentScale), DELTA = 0.5, { ul: underline, st: strikethrough, ol: overline, va: baselineOffset, bbl: bottomBorderLine } = textStyle;
27941
- if (underline) {
27958
+ if (drawStrikeAndUnderline && underline) {
27942
27959
  const startY = asc + dsc;
27943
27960
  this._drawLine(ctx, glyph, underline, startY, scale);
27944
27961
  }
@@ -27946,7 +27963,7 @@ const UNIQUE_KEY = "DefaultDocsLineExtension", DOC_EXTENSION_Z_INDEX = 40, _Line
27946
27963
  const startY = asc + dsc + 3;
27947
27964
  this._drawLine(ctx, glyph, bottomBorderLine, startY, scale, 2);
27948
27965
  }
27949
- if (strikethrough) {
27966
+ if (drawStrikeAndUnderline && strikethrough) {
27950
27967
  let startY = asc + bd - strikeoutPosition - DELTA;
27951
27968
  baselineOffset === BaselineOffset.SUPERSCRIPT ? startY -= spo : baselineOffset === BaselineOffset.SUBSCRIPT && (startY += sbo), this._drawLine(ctx, glyph, strikethrough, startY, scale);
27952
27969
  }
@@ -29428,6 +29445,7 @@ const _ThinEngine = class _ThinEngine extends Disposable {
29428
29445
  __name(_ThinEngine, "ThinEngine");
29429
29446
  let ThinEngine = _ThinEngine;
29430
29447
  const _Engine = class _Engine extends ThinEngine {
29448
+ // unitId
29431
29449
  constructor(elemWidth = 1, elemHeight = 1, pixelRatio, mode) {
29432
29450
  super();
29433
29451
  __publicField(this, "renderEvenInBackground", !0);
@@ -29479,6 +29497,7 @@ const _Engine = class _Engine extends ThinEngine {
29479
29497
  __publicField(this, "_isUsingFirefox", navigator.userAgent.indexOf("Firefox") !== -1);
29480
29498
  __publicField(this, "_previousWidth", -1e3);
29481
29499
  __publicField(this, "_previousHeight", -1e3);
29500
+ __publicField(this, "_unitId", "");
29482
29501
  this._canvas = new Canvas({
29483
29502
  mode,
29484
29503
  width: elemWidth,
@@ -31322,7 +31341,7 @@ const TransformerManagerTypeArray = [
31322
31341
  }), this._transformerControlMap.clear();
31323
31342
  }
31324
31343
  _createControl(applyObject, isSkipOnCropper = !0) {
31325
- const { left = 0, top = 0, height = 0, width = 0 } = applyObject.getState(), angle = applyObject.angle, { isCropper, resizeEnabled, rotateAnchorOffset, rotateSize, rotateCornerRadius, borderEnabled, borderStroke, borderStrokeWidth, borderSpacing, enabledAnchors } = this._getConfig(applyObject);
31344
+ const { left = 0, top = 0, height = 0, width = 0 } = applyObject.getState(), angle = applyObject.angle, { isCropper, resizeEnabled, rotateEnabled, rotateAnchorOffset, rotateSize, rotateCornerRadius, borderEnabled, borderStroke, borderStrokeWidth, borderSpacing, enabledAnchors } = this._getConfig(applyObject);
31326
31345
  if (isSkipOnCropper && isCropper)
31327
31346
  return;
31328
31347
  const oKey = applyObject.oKey, zIndex = this._selectedObjectMap.size + applyObject.maxZIndex + DEFAULT_CONTROL_PLUS_INDEX, layerIndex = applyObject.getLayerIndex() || DEFAULT_TRANSFORMER_LAYER_INDEX, groupElements = [];
@@ -31342,29 +31361,32 @@ const TransformerManagerTypeArray = [
31342
31361
  height,
31343
31362
  width,
31344
31363
  applyObject
31345
- ), rotateLine = new Rect(`__SpreadsheetTransformerRotateLine___${zIndex}`, {
31346
- zIndex: zIndex - 1,
31347
- evented: !1,
31348
- left: lineLeft,
31349
- top: lineTop,
31350
- height: rotateAnchorOffset,
31351
- width: 1,
31352
- strokeWidth: borderStrokeWidth,
31353
- stroke: borderStroke
31354
- }), { left: left2, top: top2 } = this._getRotateAnchorPosition("__SpreadsheetTransformerRotate__", height, width, applyObject), cursor = this._getRotateAnchorCursor(
31355
- "__SpreadsheetTransformerRotate__"
31356
- /* ROTATE */
31357
- ), rotate = new Rect(`__SpreadsheetTransformerRotate___${zIndex}`, {
31358
- zIndex: zIndex - 1,
31359
- left: left2,
31360
- top: top2,
31361
- height: rotateSize,
31362
- width: rotateSize,
31363
- radius: rotateCornerRadius,
31364
- strokeWidth: borderStrokeWidth * 2,
31365
- stroke: borderStroke
31366
- });
31367
- this._attachEventToRotate(rotate, applyObject), this._attachHover(rotate, cursor, CURSOR_TYPE.DEFAULT), groupElements.push(rotateLine, rotate);
31364
+ );
31365
+ if (rotateEnabled) {
31366
+ const rotateLine = new Rect(`__SpreadsheetTransformerRotateLine___${zIndex}`, {
31367
+ zIndex: zIndex - 1,
31368
+ evented: !1,
31369
+ left: lineLeft,
31370
+ top: lineTop,
31371
+ height: rotateAnchorOffset,
31372
+ width: 1,
31373
+ strokeWidth: borderStrokeWidth,
31374
+ stroke: borderStroke
31375
+ }), { left: left2, top: top2 } = this._getRotateAnchorPosition("__SpreadsheetTransformerRotate__", height, width, applyObject), cursor = this._getRotateAnchorCursor(
31376
+ "__SpreadsheetTransformerRotate__"
31377
+ /* ROTATE */
31378
+ ), rotate = new Rect(`__SpreadsheetTransformerRotate___${zIndex}`, {
31379
+ zIndex: zIndex - 1,
31380
+ left: left2,
31381
+ top: top2,
31382
+ height: rotateSize,
31383
+ width: rotateSize,
31384
+ radius: rotateCornerRadius,
31385
+ strokeWidth: borderStrokeWidth * 2,
31386
+ stroke: borderStroke
31387
+ });
31388
+ this._attachEventToRotate(rotate, applyObject), this._attachHover(rotate, cursor, CURSOR_TYPE.DEFAULT), groupElements.push(rotateLine, rotate);
31389
+ }
31368
31390
  }
31369
31391
  if (resizeEnabled)
31370
31392
  for (let i = 0, len = enabledAnchors.length; i < len; i++) {
@@ -19,6 +19,7 @@ interface ICanvasProps {
19
19
  height?: number;
20
20
  pixelRatio?: number;
21
21
  mode?: CanvasRenderMode;
22
+ id?: string;
22
23
  }
23
24
  /**
24
25
  * View Renderer constructor. It is a wrapper around native canvas element.
@@ -48,6 +49,7 @@ export declare class Canvas {
48
49
  getPixelRatio(): number;
49
50
  getWidth(): number;
50
51
  getHeight(): number;
52
+ setId(id: string): void;
51
53
  setSize(width?: number, height?: number, pixelRatioParam?: number): void;
52
54
  setPixelRatio(pixelRatio: number): void;
53
55
  dispose(): void;
@@ -1,7 +1,7 @@
1
1
  import { IScale } from '@univerjs/core';
2
- import { docExtension } from '../doc-extension';
3
2
  import { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';
4
3
  import { UniverRenderingContext } from '../../../context';
4
+ import { docExtension } from '../doc-extension';
5
5
  export declare class FontAndBaseLine extends docExtension {
6
6
  uKey: string;
7
7
  Z_INDEX: number;
@@ -28,8 +28,15 @@ export declare class Font extends SheetExtension {
28
28
  Z_INDEX: number;
29
29
  getDocuments(): any;
30
30
  draw(ctx: UniverRenderingContext, parentScale: IScale, spreadsheetSkeleton: SpreadsheetSkeleton, diffRanges: IRange[], moreBoundsInfo: IDrawInfo): void;
31
- renderFontEachCell(renderFontContext: IRenderFontContext, row: number, col: number, fontMatrix: ObjectMatrix<IFontCacheItem>): true | undefined;
32
- private _clipTextOverflow;
31
+ renderFontEachCell(renderFontCtx: IRenderFontContext, row: number, col: number, fontMatrix: ObjectMatrix<IFontCacheItem>): true | undefined;
32
+ /**
33
+ * Change font render bounds, for overflow and filter icon & custom render.
34
+ * @param renderFontContext
35
+ * @param row
36
+ * @param col
37
+ * @param fontMatrix
38
+ */
39
+ private _setFontRenderBounds;
33
40
  private _renderDocuments;
34
41
  private _clipRectangleForOverflow;
35
42
  }
@@ -54,6 +54,7 @@ export declare class Engine extends ThinEngine<Scene> {
54
54
  private _isUsingFirefox;
55
55
  private _previousWidth;
56
56
  private _previousHeight;
57
+ private _unitId;
57
58
  constructor(elemWidth?: number, elemHeight?: number, pixelRatio?: number, mode?: CanvasRenderMode);
58
59
  _init(): void;
59
60
  get elapsedTime(): number;
@@ -1,11 +1,11 @@
1
- import { Disposable, Injector, IUniverInstanceService, UniverInstanceType, Dependency, DependencyIdentifier, IDisposable, Nullable, UnitModel, UnitType } from '@univerjs/core';
1
+ import { Dependency, DependencyIdentifier, IDisposable, Nullable, UnitModel, UnitType, Disposable, Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
2
2
  import { Observable } from 'rxjs';
3
- import { Engine } from '../engine';
4
- import { IRender, RenderUnit } from './render-unit';
5
3
  import { BaseObject } from '../base-object';
6
4
  import { DocComponent } from '../components/docs/doc-component';
7
5
  import { SheetComponent } from '../components/sheets/sheet-component';
8
6
  import { Slide } from '../components/slides/slide';
7
+ import { Engine } from '../engine';
8
+ import { IRender, RenderUnit } from './render-unit';
9
9
  export type RenderComponentType = SheetComponent | DocComponent | Slide | BaseObject;
10
10
  export interface IRenderManagerService extends IDisposable {
11
11
  /** @deprecated */
@@ -1,9 +1,9 @@
1
1
  import { Nullable, Disposable } from '@univerjs/core';
2
2
  import { BaseObject } from './base-object';
3
3
  import { IMouseEvent, IPointerEvent } from './basics/i-events';
4
- import { Group } from './group';
5
- import { Scene } from './scene';
6
4
  import { ITransformerConfig } from './basics/transformer-config';
5
+ import { Scene } from './scene';
6
+ import { Group } from './group';
7
7
  declare enum MoveObserverType {
8
8
  MOVE_START = 0,
9
9
  MOVING = 1,
@@ -1,7 +1,7 @@
1
1
  import { Nullable } from '@univerjs/core';
2
- import { ObjectType } from '../base-object';
3
- import { Shape, IShapeProps } from './shape';
4
2
  import { UniverRenderingContext } from '../context';
3
+ import { IShapeProps, Shape } from './shape';
4
+ import { ObjectType } from '../base-object';
5
5
  export interface IRectProps extends IShapeProps {
6
6
  radius?: number;
7
7
  visualHeight?: number;
@@ -1,12 +1,14 @@
1
1
  import { IOffset, IScale, ISize, Nullable } from '@univerjs/core';
2
- import { BaseObject, ObjectType } from '../base-object';
3
2
  import { IObjectFullState } from '../basics/interfaces';
4
3
  import { IViewportInfo, Vector2 } from '../basics/vector2';
5
4
  import { UniverRenderingContext } from '../context';
5
+ import { BaseObject, ObjectType } from '../base-object';
6
6
  export type LineJoin = 'round' | 'bevel' | 'miter';
7
7
  export type LineCap = 'butt' | 'round' | 'square';
8
8
  export type PaintFirst = 'fill' | 'stroke';
9
9
  export interface IShapeProps extends IObjectFullState, ISize, IOffset, IScale {
10
+ rotateEnabled?: boolean;
11
+ resizeEnabled?: boolean;
10
12
  hoverCursor?: Nullable<string>;
11
13
  moveCursor?: string | null;
12
14
  fillRule?: string;