Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(sheet): editor dev
dream-num5f0a70935720
diff --git a/packages/base-docs/src/Basic/DemoData.ts b/packages/base-docs/src/Basic/DemoData.tsindex e497d1c745..9fcfd56a70 100644--- a/packages/base-docs/src/Basic/DemoData.ts+++ b/packages/base-docs/src/Basic/DemoData.ts@@ -125,7 +125,7 @@ export const docsDemoData: IDocumentData = {oneParagraph: {blockId: 'oneParagraph',st: 0,- ed: 15,+ ed: 59,blockType: BlockType.PARAGRAPH,paragraph: {bullet: {@@ -156,8 +156,8 @@ export const docsDemoData: IDocumentData = {},smallSub: {eId: 'smallSub',- st: 0,- ed: 15,+ st: 16,+ ed: 17,et: ParagraphElementType.TEXT_RUN,tr: {ct: '上标',@@ -175,8 +175,8 @@ export const docsDemoData: IDocumentData = {},twoElement: {eId: 'twoElement',- st: 0,- ed: 15,+ st: 18,+ ed: 59,et: ParagraphElementType.TEXT_RUN,tr: {ct: '日期列单元格数据验证,限制只能输入日期(介于1949年1月1日至2099年1月1日)',@@ -214,8 +214,8 @@ export const docsDemoData: IDocumentData = {},twoParagraph: {blockId: 'twoParagraph',- st: 0,- ed: 15,+ st: 60,+ ed: 88,blockType: BlockType.PARAGRAPH,paragraph: {bullet: {@@ -228,8 +228,8 @@ export const docsDemoData: IDocumentData = {elements: {oneElement: {eId: 'oneElement',- st: 0,- ed: 15,+ st: 60,+ ed: 74,et: ParagraphElementType.TEXT_RUN,tr: {ct: '细化埋点上报链路和指标方案梳理',@@ -237,8 +237,8 @@ export const docsDemoData: IDocumentData = {},twoElement: {eId: 'twoElement',- st: 0,- ed: 15,+ st: 75,+ ed: 88,et: ParagraphElementType.TEXT_RUN,tr: {ct: '目前通过每日定时任务发送报告',@@ -259,8 +259,8 @@ export const docsDemoData: IDocumentData = {},threeParagraph: {blockId: 'threeParagraph',- st: 0,- ed: 15,+ st: 89,+ ed: 230,blockType: BlockType.PARAGRAPH,paragraph: {bullet: {@@ -273,8 +273,8 @@ export const docsDemoData: IDocumentData = {elements: {oneElement: {eId: 'oneElement',- st: 0,- ed: 15,+ st: 89,+ ed: 138,et: ParagraphElementType.TEXT_RUN,tr: {ct: '自2018年首届进博会举办以来,进博会已经成为全球新品的首发地、前沿技术的首选地、创新服务的首推地。',@@ -282,8 +282,8 @@ export const docsDemoData: IDocumentData = {},twoElement: {eId: 'twoElement',- st: 0,- ed: 15,+ st: 139,+ ed: 230,et: ParagraphElementType.TEXT_RUN,tr: {ct: '中国这十年”对外开放成就展湖北展区主要以图文、图表、数据、视频、企业展品、实物模型、光电科技等体现湖北十年开放成就、重大开放平台及产业。湖北省共计17家企业、机构的展品将在这一展区展示',@@ -304,8 +304,8 @@ export const docsDemoData: IDocumentData = {},fourParagraph: {blockId: 'fourParagraph',- st: 0,- ed: 15,+ st: 230,+ ed: 321,blockType: BlockType.PARAGRAPH,paragraph: {bullet: {@@ -318,8 +318,8 @@ export const docsDemoData: IDocumentData = {elements: {oneElement: {eId: 'oneElement',- st: 0,- ed: 15,+ st: 230,+ ed: 285,et: ParagraphElementType.TEXT_RUN,tr: {ct: '国家主席习近平以视频方式出席在上海举行的第五届中国国际进口博览会开幕式并发表题为《共创开放繁荣的美好未来》的致辞',@@ -327,8 +327,8 @@ export const docsDemoData: IDocumentData = {},twoElement: {eId: 'twoElement',- st: 0,- ed: 15,+ st: 286,+ ed: 321,et: ParagraphElementType.TEXT_RUN,tr: {ct: '中国将推动各国各方共享深化国际合作机遇,全面深入参与世界贸易组织改革谈判',@@ -349,8 +349,8 @@ export const docsDemoData: IDocumentData = {},fiveParagraph: {blockId: 'fiveParagraph',- st: 0,- ed: 15,+ st: 322,+ ed: 399,blockType: BlockType.PARAGRAPH,paragraph: {bullet: {@@ -363,8 +363,8 @@ export const docsDemoData: IDocumentData = {elements: {oneElement: {eId: 'oneElement',- st: 0,- ed: 15,+ st: 322,+ ed: 359,et: ParagraphElementType.TEXT_RUN,tr: {ct: '中国男排两名现役国手彭世坤和张秉龙分别效力的三得利太阳鸟和东京大熊本轮遭遇。',@@ -372,8 +372,8 @@ export const docsDemoData: IDocumentData = {},twoElement: {eId: 'twoElement',- st: 0,- ed: 15,+ st: 360,+ ed: 399,et: ParagraphElementType.TEXT_RUN,tr: {ct: '双方经过激战,主场作战的卫冕冠军三得利技高一筹3-2逆转击败对手,力夺第3场胜利',diff --git a/packages/base-docs/src/View/Render/Views/DocsView.ts b/packages/base-docs/src/View/Render/Views/DocsView.tsindex f18b521bbf..0ae280eec2 100644--- a/packages/base-docs/src/View/Render/Views/DocsView.ts+++ b/packages/base-docs/src/View/Render/Views/DocsView.ts@@ -60,7 +60,7 @@ export class DocsView extends BaseView {sceneHeight = docsHeight + pageMarginTop * 2;}- scene.resize(sceneWidth, sceneHeight);+ scene.resize(sceneWidth, sceneHeight + 200);documents.translate(docsLeft, docsTop);}diff --git a/packages/base-render/src/BaseObject.ts b/packages/base-render/src/BaseObject.tsindex ebd98b77b9..d6365df39c 100644--- a/packages/base-render/src/BaseObject.ts+++ b/packages/base-render/src/BaseObject.ts@@ -265,6 +265,14 @@ export abstract class BaseObject {return this;}+ private _makeDirtyMix() {+ if (this.debounceParentDirty) {+ this.makeDirty(true);+ } else {+ this.makeDirtyNoDebounce(true);+ }+ }+protected _setTransForm() {const composeResult = Transform.create().composeMatrix({left: this.left + this.strokeWidth / 2,@@ -278,11 +286,7 @@ export abstract class BaseObject {flipY: this.flipY,});this.transform = composeResult;- if (this.debounceParentDirty) {- this.makeDirty(true);- } else {- this.makeDirtyNoDebounce(true);- }+ this._makeDirtyMix();}get top(): number {@@ -465,10 +469,12 @@ export abstract class BaseObject {hide() {this._visible = false;+ this._makeDirtyMix();}show() {this._visible = true;+ this._makeDirtyMix();}render(ctx: CanvasRenderingContext2D, bounds?: IBoundRect) {diff --git a/packages/base-render/src/Basics/Position.ts b/packages/base-render/src/Basics/Position.tsindex e5014104e9..04febc7624 100644--- a/packages/base-render/src/Basics/Position.ts+++ b/packages/base-render/src/Basics/Position.ts@@ -1,4 +1,6 @@+import { BaseObject } from '../BaseObject';import { ScrollTimer } from '../ScrollTimer';+import { IBoundRect } from './Vector2';export function getCurrentScrollXY(scrollTimer: ScrollTimer) {const scene = scrollTimer.getScene();@@ -17,3 +19,43 @@ export function getCurrentScrollXY(scrollTimer: ScrollTimer) {scrollY: actualScroll.y,};}++export function getOffsetRectForDom(ele: HTMLElement) {+ let box = ele.getBoundingClientRect();+ let body = document.body;+ let docElem = document.documentElement;+ //获取页面的scrollTop,scrollLeft(兼容性写法)+ let scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop;+ let scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft;+ let clientTop = docElem.clientTop || body.clientTop;+ let clientLeft = docElem.clientLeft || body.clientLeft;+ let top = box.top + scrollTop - clientTop;+ let left = box.left + scrollLeft - clientLeft;+ return {+ //Math.round 兼容火狐浏览器bug+ top,+ left,+ };+}++export function transformBoundingCoord(object: BaseObject, bounds: IBoundRect) {+ const tl = object.transform.clone().invert().applyPoint(bounds.tl);+ const tr = object.transform.clone().invert().applyPoint(bounds.tr);+ const bl = object.transform.clone().invert().applyPoint(bounds.bl);+ const br = object.transform.clone().invert().applyPoint(bounds.br);++ const xList = [tl.x, tr.x, bl.x, br.x];+ const yList = [tl.y, tr.y, bl.y, br.y];++ const maxX = Math.max(...xList);+ const minX = Math.min(...xList);+ const maxY = Math.max(...yList);+ const minY = Math.min(...yList);++ return {+ minX,+ maxX,+ minY,+ maxY,+ };+}diff --git a/packages/base-render/src/Basics/Tools.ts b/packages/base-render/src/Basics/Tools.tsindex fad10613ec..26743107d3 100644--- a/packages/base-render/src/Basics/Tools.ts+++ b/packages/base-render/src/Basics/Tools.ts@@ -23,7 +23,7 @@ export const getColor = (RgbArray: number[], opacity?: number): string => {return `${RGB_PAREN}0,0,0)`;}- if (opacity) {+ if (opacity != null) {return `${RGBA_PAREN + RgbArray.join(',')},${opacity})`;}return `${RGB_PAREN + RgbArray.join(',')})`;@@ -586,3 +586,13 @@ export function injectStyle(styles: string[]) {styleSheet?.insertRule(style, styleSheet.cssRules.length);}}++export function checkStyle(content: string) {+ for (let i = 0, len = document.head.childNodes.length; i < len; i++) {+ const node = document.head.childNodes[i];+ if (node.nodeName === 'STYLE' && node.textContent && node.textContent.indexOf(content) > -1) {+ return true;+ }+ }+ return false;+}diff --git a/packages/base-render/src/Component/Docs/Common/TextSelection.ts b/packages/base-render/src/Component/Docs/Common/TextSelection.tsindex 0276a8015b..29b0d7302b 100644--- a/packages/base-render/src/Component/Docs/Common/TextSelection.ts+++ b/packages/base-render/src/Component/Docs/Common/TextSelection.ts@@ -1,10 +1,18 @@import { IPosition, Nullable } from '@univer/core';import { nanoid } from 'nanoid';import { COLORS } from '../../../Basics/Const';-import { IDocumentSkeletonColumn, IDocumentSkeletonDivide, IDocumentSkeletonLine, IDocumentSkeletonPage, IDocumentSkeletonSection } from '../../../Basics/IDocumentSkeletonCached';+import {+ IDocumentSkeletonColumn,+ IDocumentSkeletonDivide,+ IDocumentSkeletonLine,+ IDocumentSkeletonPage,+ IDocumentSkeletonSection,+ SpanType,+} from '../../../Basics/IDocumentSkeletonCached';import { getColor } from '../../../Basics/Tools';import { IPoint } from '../../../Basics/Vector2';import { Scene } from '../../../Scene';+import { Rect } from '../../../Shape/Rect';import { RegularPolygon } from '../../../Shape/RegularPolygon';import { DocumentSkeleton } from '../DocSkeleton';import { Documents } from '../Document';@@ -43,7 +51,9 @@ interface ICurrentNodePositionState {span: NodePositionStateType;}-const TEXT_POLYGON_KEY_PREFIX = '__TestSelection__';+const TEXT_RANGE_KEY_PREFIX = '__TestSelectionRange__';++const TEXT_ANCHOR_KEY_PREFIX = '__TestSelectionAnchor__';export interface INodePosition {page: number;@@ -52,6 +62,7 @@ export interface INodePosition {line: number;divide: number;span: number;+ isBack: boolean;}export class TextSelection {@@ -59,7 +70,9 @@ export class TextSelection {private _Liquid = new Liquid();- private _polygon: Nullable<RegularPolygon>;+ private _rangeShape: Nullable<RegularPolygon>;++ private _anchorShape: Nullable<Rect>;private _currentStartState: ICurrentNodePositionState = {page: NodePositionStateType.NORMAL,@@ -79,19 +92,7 @@ export class TextSelection {span: NodePositionStateType.NORMAL,};- constructor(private _scene: Scene, public startNodePosition?: INodePosition, public endNodePosition?: INodePosition) {}-- isActive() {- return this._current === true;- }-- activate() {- this._current = true;- }-- deactivate() {- this._current = false;- }+ constructor(private _scene: Scene, public startNodePosition?: Nullable<INodePosition>, public endNodePosition?: Nullable<INodePosition>) {}private _resetCurrentNodePositionState() {this._currentStartState = {@@ -113,6 +114,72 @@ export class TextSelection {};}+ private _compareNodePositionLogic(pos1: INodePosition, pos2: INodePosition) {+ if (pos1.page > pos2.page) {+ return false;+ }++ if (pos1.page < pos2.page) {+ return true;+ }++ if (pos1.section > pos2.section) {+ return false;+ }++ if (pos1.section < pos2.section) {+ return true;+ }++ if (pos1.column > pos2.column) {+ return false;+ }++ if (pos1.column < pos2.column) {+ return true;+ }++ if (pos1.line > pos2.line) {+ return false;+ }++ if (pos1.line < pos2.line) {+ return true;+ }++ if (pos1.divide > pos2.divide) {+ return false;+ }++ if (pos1.divide < pos2.divide) {+ return true;+ }++ if (pos1.span > pos2.span) {+ return false;+ }++ if (pos1.span < pos2.span) {+ return true;+ }++ return true;+ }++ private _compareNodePosition(pos1: INodePosition, pos2: INodePosition) {+ const compare = this._compareNodePositionLogic(pos1, pos2);+ if (compare) {+ return {+ start: pos1,+ end: pos2,+ };+ }+ return {+ start: pos2,+ end: pos1,+ };+ }+private _setNodePositionState(type = NodePositionType.page, start: number, end: number, current: number) {if (current === start) {this._currentStartState[type] = NodePositionStateType.START;@@ -223,53 +290,12 @@ export class TextSelection {return points;}- isEmpty() {- return this.startNodePosition === undefined && this.endNodePosition === undefined;- }-- isCollapsed() {- if (this.startNodePosition !== undefined && this.endNodePosition === undefined) {- return true;- }-- if (this.isSamePosition()) {- return true;- }-- return false;- }-- isRange() {- const start = this.startNodePosition;-- const end = this.endNodePosition;-- if (start === undefined || end === undefined) {- return false;- }-- if (this.isSamePosition()) {- return false;- }-- return true;- }-- dispose() {- this._polygon?.dispose();- this._polygon = null;- }-- isIntersection(textSelection: TextSelection) {- return false;- }-private isSamePosition() {const start = this.startNodePosition;const end = this.endNodePosition;- if (start === undefined || end === undefined) {+ if (start == null || end == null) {return false;}@@ -287,14 +313,15 @@ export class TextSelection {return true;}- private _createAndUpdatePolygon(pointsGroup: IPoint[][], left: number, top: number) {- if (this._polygon) {- this._polygon.translate(left, top);- this._polygon.updatePointGroup(pointsGroup);+ private _createAndUpdateRange(pointsGroup: IPoint[][], left: number, top: number) {+ if (this._rangeShape) {+ this._rangeShape.translate(left, top);+ this._rangeShape.updatePointGroup(pointsGroup);+ this._rangeShape.show();return;}- const polygon = new RegularPolygon(TEXT_POLYGON_KEY_PREFIX + nanoid(6), {+ const polygon = new RegularPolygon(TEXT_RANGE_KEY_PREFIX + nanoid(6), {pointsGroup,fill: getColor(COLORS.black, 0.2),left,@@ -302,58 +329,97 @@ export class TextSelection {evented: false,});- this._polygon = polygon;+ this._rangeShape = polygon;this._scene.addObject(polygon, 2);}- generate(documents: Documents) {- const skeleton = documents.getSkeleton();+ private _getAnchorBounding(pointsGroup: IPoint[][]) {+ const points = pointsGroup[0];+ const startPoint = points[0];+ const endPoint = points[2];- if (!skeleton) {+ const { x: startX, y: startY } = startPoint;++ const { x: endX, y: endY } = endPoint;++ return {+ left: startX,+ top: startY,+ width: endX - startX,+ height: endY - startY,+ };+ }++ private _createAndUpdateAnchor(pointsGroup: IPoint[][], docsLeft: number, docsTop: number) {+ const bounding = this._getAnchorBounding(pointsGroup);+ const { left, top, width, height } = bounding;+ if (this._anchorShape) {+ this._anchorShape.transformByState({ left: left + docsLeft, top: top + docsTop, height });+ this._anchorShape.show();return;}- const pointGroup: IPoint[][] = [];+ const anchor = new Rect(TEXT_ANCHOR_KEY_PREFIX + nanoid(6), {+ left: left + docsLeft,+ top: top + docsTop,+ height,+ strokeWidth: 1,+ stroke: getColor(COLORS.black),+ evented: false,+ });- const start = this.startNodePosition;+ this._anchorShape = anchor;- const end = this.endNodePosition;+ this._scene.addObject(anchor, 2);+ }- if (this.isEmpty()) {- return pointGroup;- }+ private _getRangePointData(startOrigin: INodePosition, endOrigin: INodePosition, skeleton: DocumentSkeleton) {+ const pointGroup: IPoint[][] = [];- if (this.isCollapsed()) {+ if (startOrigin == null || endOrigin == null) {return;}+ const { start, end } = this._compareNodePosition(startOrigin, endOrigin);++ const isStartBack = start.isBack;++ const isEndBack = end.isBack;+this._selectionIterator(start!, end!, skeleton, (start_sp, end_sp, divide, line) => {const { lineHeight } = line;const spanGroup = divide.spanGroup;- const { width: divideWidth } = divide;-const { x: startX, y: startY } = this._Liquid;let position: IPosition;++ const firstSpan = spanGroup[start_sp];+ const lastSpan = spanGroup[end_sp];++ const firstSpanLeft = firstSpan?.left || 0;+ const firstSpanWidth = firstSpan?.width || 0;++ const lastSpanLeft = lastSpan?.left || 0;+ const lastSpanWidth = lastSpan?.width || 0;++ let isList = firstSpan?.spanType === SpanType.LIST;+if (start_sp === 0 && end_sp === spanGroup.length - 1) {position = {- startX,+ startX: startX + firstSpanLeft + (isList ? firstSpanWidth : 0),startY,- endX: startX + divideWidth,+ endX: startX + lastSpanLeft + lastSpanWidth,endY: startY + lineHeight,};} else {- const firstSpan = spanGroup[start_sp];- const lastSpan = spanGroup[end_sp];-// console.log('span', firstSpan, lastSpan, start_sp, end_sp);position = {- startX: startX + firstSpan.left,+ startX: startX + firstSpanLeft + ((isStartBack || start_sp === 0) && !isList ? 0 : firstSpanWidth),startY,- endX: startX + lastSpan.left + lastSpan.width,+ endX: startX + lastSpanLeft + (!isEndBack || end_sp === spanGroup.length - 1 ? lastSpanWidth : 0),endY: startY + lineHeight,};@@ -365,8 +431,6 @@ export class TextSelection {pointGroup.push(this._pushToPoints(position));});- // console.log('pointGroup', pointGroup);- this._createAndUpdatePolygon(pointGroup, documents.left, documents.top);return pointGroup;}@@ -452,4 +516,118 @@ export class TextSelection {}}}++ getAnchor() {+ return this._anchorShape;+ }++ activeStatic() {+ this._anchorShape?.setProps({+ stroke: getColor(COLORS.black, 1),+ });+ }++ deactivateStatic() {+ this._anchorShape?.setProps({+ stroke: getColor(COLORS.black, 0),+ });+ }++ isActive() {+ return this._current === true;+ }++ activate() {+ this._current = true;+ }++ deactivate() {+ this._current = false;+ }++ isEmpty() {+ return this.startNodePosition == null && this.endNodePosition == null;+ }++ isCollapsed() {+ if (this.startNodePosition != null && this.endNodePosition == null) {+ return true;+ }++ if (this.isSamePosition()) {+ return true;+ }++ return false;+ }++ isRange() {+ const start = this.startNodePosition;++ const end = this.endNodePosition;++ if (start == null || end == null) {+ return false;+ }++ if (this.isSamePosition()) {+ return false;+ }++ return true;+ }++ dispose() {+ this._rangeShape?.dispose();+ this._rangeShape = null;+ this._anchorShape?.dispose();+ this._anchorShape = null;+ }++ isIntersection(textSelection: TextSelection) {+ return false;+ }++ refresh(documents: Documents) {+ const skeleton = documents.getSkeleton();++ if (!skeleton) {+ return;+ }++ const start = this.startNodePosition;++ const end = this.endNodePosition;++ this._anchorShape?.hide();+ this._rangeShape?.hide();++ if (this.isEmpty()) {+ return;+ }++ if (this.isCollapsed()) {+ const pointGroup = this._getRangePointData(start!, start!, skeleton);+ pointGroup && this._createAndUpdateAnchor(pointGroup, documents.left, documents.top);+ return;+ }++ const pointGroup = this._getRangePointData(start!, end!, skeleton);++ pointGroup && this._createAndUpdateRange(pointGroup, documents.left, documents.top);+ }++ getStart() {+ if (this.startNodePosition == null) {+ return this.endNodePosition;+ }++ if (this.endNodePosition == null) {+ return this.startNodePosition;+ }++ const { start } = this._compareNodePosition(this.startNodePosition, this.endNodePosition);++ return start;+ }}diff --git a/packages/base-render/src/Component/Docs/Document.Editor.ts b/packages/base-render/src/Component/Docs/Document.Editor.tsindex 11da794ead..01f57ee396 100644--- a/packages/base-render/src/Component/Docs/Document.Editor.ts+++ b/packages/base-render/src/Component/Docs/Document.Editor.ts@@ -1,13 +1,22 @@import { Nullable, Observer } from '@univer/core';-import { IDocumentSkeletonSpan } from '../../Basics/IDocumentSkeletonCached';+import { IDocumentSkeletonCached, IDocumentSkeletonSpan } from '../../Basics/IDocumentSkeletonCached';import { CURSOR_TYPE } from '../../Basics/Const';-import { injectStyle } from '../../Basics/Tools';import { IMouseEvent, IPointerEvent } from '../../Basics/IEvents';-import { getCurrentScrollXY } from '../../Basics/Position';+import { getCurrentScrollXY, getOffsetRectForDom, transformBoundingCoord } from '../../Basics/Position';import { ScrollTimer } from '../../ScrollTimer';import { Documents } from './Document';import { INodePosition, TextSelection } from './Common/TextSelection';+import { IScrollObserverParam, Viewport } from '../../Viewport';+import { checkStyle, injectStyle } from '../../Basics/Tools';++import { Vector2 } from '../../Basics';++interface INodeInfo {+ node: IDocumentSkeletonSpan;+ ratioX: number;+ ratioY: number;+}export class DocsEditor {private _container: HTMLDivElement;@@ -28,6 +37,8 @@ export class DocsEditor {private _moveOutObserver: Nullable<Observer<IPointerEvent | IMouseEvent>>;+ private _skeletonObserver: Nullable<Observer<IDocumentSkeletonCached>>;+private _startOffsetX: number;private _startOffsetY: number;@@ -40,9 +51,21 @@ export class DocsEditor {private _startNodePosition: INodePosition;+ private _activeViewport: Nullable<Viewport>;++ private _viewPortObserverMap = new Map<+ string,+ {+ scrollStop: Nullable<Observer<IScrollObserverParam>>;+ scrollBefore: Nullable<Observer<IScrollObserverParam>>;+ }+ >();+constructor(private _documents?: Documents) {this._initialDom();+ this.activeViewport = this._documents?.getFirstViewport();+if (this._documents) {this.changeDocuments(this._documents);}@@ -61,10 +84,10 @@ export class DocsEditor {const inputParent = document.createElement('div');const inputDom = document.createElement('div');- inputParent.appendChild(inputDom);-const cursorDom = document.createElement('div');+ inputParent.appendChild(inputDom);+container.appendChild(inputParent);container.appendChild(cursorDom);@@ -76,7 +99,9 @@ export class DocsEditor {this._initialInput();- this._initialCursor();+ this._initialCursorDom();++ this._attachInputEvent();document.body.appendChild(container);}@@ -105,7 +130,7 @@ export class DocsEditor {`;}- private _initialCursor() {+ private _initialCursorDom() {this._cursor.style.cssText = `visibility: visible;position: absolute;@@ -120,35 +145,50 @@ export class DocsEditor {display: none`;- if (!DocsEditor.isInsertKeyFrame) {- DocsEditor.isInsertKeyFrame = true;+ if (!checkStyle('keyframes univer_cursor_blinkStyle')) {const styles = [`- @-webkit-keyframes univer-blinkStyle {+ @-webkit-keyframes univer_cursor_blinkStyle {0% {opacity: 1;}+ 13% {+ opacity: 0;+ }+50% {opacity: 0;}++ 63% {+ opacity: 1;+ }- to {+ 100% {opacity: 1;}}`,`- @keyframes univer-blinkStyle {+ @keyframes univer_cursor_blinkStyle {0% {opacity: 1;}+ 13% {+ opacity: 0;+ }+50% {opacity: 0;}++ 63% {+ opacity: 1;+ }- to {+ 100% {opacity: 1;}}@@ -158,31 +198,17 @@ export class DocsEditor {}}- active(x: number, y: number) {- this._container.style.left = `${x}px`;- this._container.style.top = `${y}px`;-- this._cursor.style.animation = 'univer-blinkStyle 1s steps(1) infinity';- this._cursor.style.display = 'revert';- }-- deactivate() {- this._container.style.left = `0px`;- this._container.style.top = `0px`;-- this._cursor.style.animation = '';- this._cursor.style.display = 'none';- }-private _getSkeletonData() {return this._documents?.getSkeleton()?.getSkeletonData();}- private _getNodePosition(span: IDocumentSkeletonSpan | false) {- if (span === false) {+ private _getNodePosition(node: INodeInfo | false) {+ if (node === false) {return;}+ const { node: span, ratioX, ratioY } = node;+const divide = span.parent;const line = divide?.parent;@@ -218,61 +244,10 @@ export class DocsEditor {column: columnIndex,section: sectionIndex,page: pageIndex,+ isBack: ratioX < 0.5,};}- private _compareNodePosition(pos1: INodePosition, pos2: INodePosition) {- if (pos1.page > pos2.page) {- return false;- }-- if (pos1.page < pos2.page) {- return true;- }-- if (pos1.section > pos2.section) {- return false;- }-- if (pos1.section < pos2.section) {- return true;- }-- if (pos1.column > pos2.column) {- return false;- }-- if (pos1.column < pos2.column) {- return true;- }-- if (pos1.line > pos2.line) {- return false;- }-- if (pos1.line < pos2.line) {- return true;- }-- if (pos1.divide > pos2.divide) {- return false;- }-- if (pos1.divide < pos2.divide) {- return true;- }-- if (pos1.span > pos2.span) {- return false;- }-- if (pos1.span < pos2.span) {- return true;- }-- return true;- }-private _interactTextSelection(activeTextSelection: TextSelection) {const newTextSelection: TextSelection[] = [];let hasIntersection = false;@@ -296,6 +271,7 @@ export class DocsEditor {this._textSelectionList.forEach((textSelection) => {textSelection.dispose();});+ this._textSelectionList = [];}private _deactivateTextSelection() {@@ -311,16 +287,17 @@ export class DocsEditor {}private _updateTextSelection(position: INodePosition) {+ if (!this._documents) {+ return;+ }let lastTextSelection = this._textSelectionList.pop();if (!lastTextSelection) {- if (!this._documents) {- return;- }lastTextSelection = new TextSelection(this._documents.getScene(), position);}this._deleteAllTextSelection();lastTextSelection.activate();lastTextSelection.startNodePosition = position;+ lastTextSelection.endNodePosition = null;this._textSelectionList = [lastTextSelection];}@@ -337,6 +314,49 @@ export class DocsEditor {return this._textSelectionList.length === 0;}+ private _getCanvasOffset() {+ const engine = this._documents?.getEngine();+ const canvas = engine?.getCanvas()?.getCanvasEle();++ if (!canvas) {+ return {+ left: 0,+ top: 0,+ };+ }++ const { top, left } = getOffsetRectForDom(canvas);++ return {+ left,+ top,+ };+ }++ private _syncDomToSelection() {+ const activeTextSelection = this._getActiveTextSelection();+ const anchor = activeTextSelection?.getAnchor();+ if (!anchor || (anchor && !anchor.visible)) {+ return;+ }++ const { height, left, top } = anchor;++ const absoluteCoord = this._activeViewport?.getAbsoluteVector(Vector2.FromArray([left, top]));++ this._cursor.style.height = `${height}px`;++ console.log('_syncDomToSelection', left, top, absoluteCoord?.x || 0, absoluteCoord?.y || 0);++ let { left: canvasLeft, top: canvasTop } = this._getCanvasOffset();++ canvasLeft += absoluteCoord?.x || 0;++ canvasTop += absoluteCoord?.y || 0;++ this.active(canvasLeft, canvasTop);+ }+private _moving(moveOffsetX: number, moveOffsetY: number, scrollTimer: ScrollTimer) {const { scrollX, scrollY } = getCurrentScrollXY(scrollTimer);const endX = moveOffsetX - this._viewportScrollX + scrollX;@@ -346,7 +366,7 @@ export class DocsEditor {return;}- const endNode = this._documents.findNodeByCoord(endX, endY);+ const endNode = this._documents.findNodeByCoord(moveOffsetX, moveOffsetY);const endPosition = this._getNodePosition(endNode);@@ -362,33 +382,117 @@ export class DocsEditor {return;}- const compare = this._compareNodePosition(this._startNodePosition, endPosition);+ activeTextSelection.endNodePosition = endPosition;- if (!compare) {- activeTextSelection.startNodePosition = endPosition;- activeTextSelection.endNodePosition = this._startNodePosition;- } else {- activeTextSelection.endNodePosition = endPosition;+ activeTextSelection.refresh(this._documents);++ this._interactTextSelection(activeTextSelection);+ }++ private _attachScrollEvent(viewport: Nullable<Viewport>) {+ if (!viewport) {+ return;}+ const key = viewport.viewPortKey;+ if (this._viewPortObserverMap.has(key)) {+ return;+ }++ const scrollBefore = viewport.onScrollBeforeObserver.add((param: IScrollObserverParam) => {+ const viewport = param.viewport;+ if (!viewport) {+ return;+ }- activeTextSelection.generate(this._documents);+ const textSelection = this._getActiveTextSelection();- this._interactTextSelection(activeTextSelection);+ textSelection?.activeStatic();++ this._cursor.style.display = 'none';+ });++ const scrollStop = viewport.onScrollStopObserver.add((param: IScrollObserverParam) => {+ const viewport = param.viewport;+ if (!viewport) {+ return;+ }++ const bounds = viewport.getBounding();++ const textSelection = this._getActiveTextSelection();++ const anchor = textSelection?.getAnchor();++ if (!anchor) {+ return;+ }++ if (bounds) {+ const { minX, maxX, minY, maxY } = transformBoundingCoord(anchor, bounds);++ if (anchor.strokeWidth < minX || maxX < 0 || anchor.strokeWidth < minY || maxY < 0) {+ return;+ }+ }++ this._syncDomToSelection();++ textSelection?.deactivateStatic();++ this._cursor.style.display = 'revert';+ });++ this._viewPortObserverMap.set(key, {+ scrollBefore,+ scrollStop,+ });+ }++ private _isIMEInputApply = false;++ private _attachInputEvent() {+ this._input.addEventListener('input', (e) => {+ if (this._isIMEInputApply) {+ return;+ }++ const content = this._input.innerHTML;- // const points = this._generatePoints(this._startNodePosition, endPosition);+ const selection = this._getActiveTextSelection();- // const startCoord = this._documents!.getInverseCoord(Vector2.FromArray([this._startOffsetX, this._startOffsetY]));+ const inputStart = selection?.getStart();- // const endCoord = this._documents!.getInverseCoord(Vector2.FromArray([endX, endY]));+ if (!inputStart) {+ return;+ }++ console.log(1);+ });- // const moveLeft = x - this._startOffsetX;- // const moveTop = y - this._startOffsetY;+ this._input.addEventListener('compositionstart', (e) => {+ this._isIMEInputApply = true;+ });- // this._startOffsetX = x;- // this._startOffsetY = y;+ this._input.addEventListener('compositionend', (e) => {+ this._isIMEInputApply = false;+ const content = this._input.innerHTML;+ });++ this._input.addEventListener('compositionupdate', (e) => {+ console.log('onCompositionUpdate', this._input.innerHTML);+ const content = this._input.innerHTML;+ // ctx.fillText(content, 10, 90);+ // const measure = ctx.measureText(content);+ // const { width, fontBoundingBoxAscent, fontBoundingBoxDescent } = measure;+ // ctx.beginPath();+ // ctx.setLineDash([1, 2]);+ // ctx.moveTo(10, 90 + fontBoundingBoxDescent);+ // ctx.lineTo(10 + width, 90 + fontBoundingBoxDescent);+ // ctx.stroke();+ });}- private _attachEvent(documents: Documents) {+ private _attachSelectionEvent(documents: Documents) {this._moveInObserver = documents.onPointerEnterObserver.add(() => {documents.cursor = CURSOR_TYPE.TEXT;});@@ -398,21 +502,6 @@ export class DocsEditor {scene.resetCursor();});const scene = documents.getScene();- // this._downObserver = documents.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent, state) => {- // const { offsetX: evtOffsetX, offsetY: evtOffsetY } = evt;- // this._startOffsetX = evtOffsetX;- // this._startOffsetY = evtOffsetY;-- // if (!this._documents) {- // return;- // }-- // const startNode = this._documents.findNodeByCoord(evtOffsetX, evtOffsetY);-- // const position = this._getNodePosition(startNode);-- // console.log('startNode', startNode);- // });this._downObserver = documents.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent, state) => {const { offsetX: evtOffsetX, offsetY: evtOffsetY } = evt;@@ -423,6 +512,8 @@ export class DocsEditor {return;}+ this.activeViewport = this._documents.getActiveViewportByCoord(evtOffsetX, evtOffsetY);+const startNode = this._documents.findNodeByCoord(evtOffsetX, evtOffsetY);const position = this._getNodePosition(startNode);@@ -441,6 +532,10 @@ export class DocsEditor {this._updateTextSelection(position);}+ this._activeSelectionRefresh();++ this._syncDomToSelection();+this._startNodePosition = position;scene.disableEvent();@@ -456,9 +551,9 @@ export class DocsEditor {this._moveObserver = scene.onPointerMoveObserver.add((moveEvt: IPointerEvent | IMouseEvent) => {const { offsetX: moveOffsetX, offsetY: moveOffsetY } = moveEvt;this._moving(moveOffsetX, moveOffsetY, scrollTimer);- // scrollTimer.scrolling(moveOffsetX, moveOffsetY, () => {- // this._moving(moveOffsetX, moveOffsetY, scrollTimer);- // });+ scrollTimer.scrolling(moveOffsetX, moveOffsetY, () => {+ this._moving(moveOffsetX, moveOffsetY, scrollTimer);+ });scene.setCursor(CURSOR_TYPE.TEXT);});@@ -470,7 +565,7 @@ export class DocsEditor {scrollTimer.stopScroll();});- state.stopPropagation();+ // state.stopPropagation();});}@@ -478,6 +573,38 @@ export class DocsEditor {documents.onPointerEnterObserver.remove(this._moveInObserver);documents.onPointerLeaveObserver.remove(this._moveOutObserver);documents.onPointerDownObserver.remove(this._downObserver);+ documents.getSkeleton()?.onRecalculateChangeObservable.remove(this._skeletonObserver);+ }++ private _activeSelectionRefresh() {+ if (!this._documents) {+ return;+ }+ const activeSelection = this._getActiveTextSelection();++ activeSelection?.refresh(this._documents);+ }++ active(x: number, y: number) {+ this._container.style.left = `${x}px`;+ this._container.style.top = `${y}px`;++ this._cursor.style.animation = 'univer_cursor_blinkStyle 1s steps(1) infinite';+ this._cursor.style.display = 'revert';++ setTimeout(() => {+ this._input.focus();+ }, 0);+ }++ deactivate() {+ this._container.style.left = `0px`;+ this._container.style.top = `0px`;++ this._cursor.style.animation = '';+ this._cursor.style.display = 'none';++ this._input.blur();}changeDocuments(documents: Documents) {@@ -486,12 +613,23 @@ export class DocsEditor {}this._documents = documents;- this._attachEvent(this._documents);+ this._skeletonObserver = documents.getSkeleton()?.onRecalculateChangeObservable.add((data: IDocumentSkeletonCached) => {+ this._deleteAllTextSelection();+ });+ this._attachSelectionEvent(this._documents);}- dispose() {}+ dispose() {+ if (this._documents) {+ this._detachEvent(this._documents);+ }+ this._container.remove();+ }- static isInsertKeyFrame = false;+ set activeViewport(viewport: Nullable<Viewport>) {+ this._attachScrollEvent(viewport);+ this._activeViewport = viewport;+ }static create(documents?: Documents) {return new DocsEditor(documents);diff --git a/packages/base-render/src/Component/Docs/Document.ts b/packages/base-render/src/Component/Docs/Document.tsindex b766b33161..249da54a11 100644--- a/packages/base-render/src/Component/Docs/Document.ts+++ b/packages/base-render/src/Component/Docs/Document.ts@@ -127,6 +127,78 @@ export class Documents extends DocComponent {});}+ private _addSkeletonChangeObserver(skeleton?: DocumentSkeleton) {+ if (!skeleton) {+ return;+ }++ this._skeletonObserver = skeleton.onRecalculateChangeObservable.add((data) => {+ const pages = data.pages;+ let width = 0;+ let height = 0;+ for (let i = 0, len = pages.length; i < len; i++) {+ const page = pages[i];+ const { pageWidth, pageHeight } = page;+ if (this.pageLayoutType === PageLayoutType.VERTICAL) {+ height += pageHeight;+ if (i !== len - 1) {+ height += this.pageMarginTop;+ }+ width = Math.max(width, pageWidth);+ } else if (this.pageLayoutType === PageLayoutType.HORIZONTAL) {+ width += pageWidth;+ if (i !== len - 1) {+ width += this.pageMarginLeft;+ }+ height = Math.max(height, pageHeight);+ }+ }++ this.resize(width, height);+ });+ }++ private _disposeSkeletonChangeObserver(skeleton?: DocumentSkeleton) {+ if (!skeleton) {+ return;+ }+ skeleton.onRecalculateChangeObservable.remove(this._skeletonObserver);+ }++ private _getPageBoundingBox(page: IDocumentSkeletonPage) {+ const { pageWidth, pageHeight } = page;+ let { x: startX, y: startY } = this._findLiquid;++ let endX = -1;+ let endY = -1;+ if (this.pageLayoutType === PageLayoutType.VERTICAL) {+ endX = pageWidth;+ endY = startY + pageHeight;+ } else if (this.pageLayoutType === PageLayoutType.HORIZONTAL) {+ endX = startX + pageWidth;+ endY = pageHeight;+ }++ return {+ startX,+ startY,+ endX,+ endY,+ };+ }++ getFirstViewport() {+ return (this.getScene() as Scene).getViewports()[0];+ }++ getActiveViewportByCoord(offsetX: number, offsetY: number) {+ return (this.getScene() as Scene).getActiveViewportByCoord(Vector2.FromArray([offsetX, offsetY]));+ }++ getEngine() {+ return (this.getScene() as Scene).getEngine();+ }+enableEditor() {if (this._hasEditor) {return;@@ -354,44 +426,6 @@ export class Documents extends DocComponent {}}- private _addSkeletonChangeObserver(skeleton?: DocumentSkeleton) {- if (!skeleton) {- return;- }-- this._skeletonObserver = skeleton.onRecalculateChangeObservable.add((data) => {- const pages = data.pages;- let width = 0;- let height = 0;- for (let i = 0, len = pages.length; i < len; i++) {- const page = pages[i];- const { pageWidth, pageHeight } = page;- if (this.pageLayoutType === PageLayoutType.VERTICAL) {- height += pageHeight;- if (i !== len - 1) {- height += this.pageMarginTop;- }- width = Math.max(width, pageWidth);- } else if (this.pageLayoutType === PageLayoutType.HORIZONTAL) {- width += pageWidth;- if (i !== len - 1) {- width += this.pageMarginLeft;- }- height = Math.max(height, pageHeight);- }- }-- this.resize(width, height);- });- }-- private _disposeSkeletonChangeObserver(skeleton?: DocumentSkeleton) {- if (!skeleton) {- return;- }- skeleton.onRecalculateChangeObservable.remove(this._skeletonObserver);- }-changeSkeleton(newSkeleton: DocumentSkeleton) {this._disposeSkeletonChangeObserver(this.getSkeleton());this.setSkeleton(newSkeleton);@@ -399,28 +433,6 @@ export class Documents extends DocComponent {return this;}- private _getPageBoundingBox(page: IDocumentSkeletonPage) {- const { pageWidth, pageHeight } = page;- let { x: startX, y: startY } = this._findLiquid;-- let endX = -1;- let endY = -1;- if (this.pageLayoutType === PageLayoutType.VERTICAL) {- endX = pageWidth;- endY = startY + pageHeight;- } else if (this.pageLayoutType === PageLayoutType.HORIZONTAL) {- endX = startX + pageWidth;- endY = pageHeight;- }-- return {- startX,- startY,- endX,- endY,- };- }-findNodeByCoord(offsetX: number, offsetY: number) {const scene = this.getScene() as Scene;const originCoord = scene.transformToSceneCoord(Vector2.FromArray([offsetX, offsetY]));@@ -491,7 +503,11 @@ export class Documents extends DocComponent {const { y: startY } = this._findLiquid;- if (!(y >= startY && y <= startY + lineHeight)) {+ const startY_fin = startY;++ const endY_fin = startY + lineHeight;++ if (!(y >= startY_fin && y <= endY_fin)) {this._findLiquid.translateRestore();continue;}@@ -518,11 +534,19 @@ export class Documents extends DocComponent {const { width: spanWidth, left: spanLeft } = span;- if (!(x >= startX + spanLeft && x <= startX + spanLeft + spanWidth)) {+ const startX_fin = startX + spanLeft;++ const endX_fin = startX + spanLeft + spanWidth;++ if (!(x >= startX_fin && x <= endX_fin)) {continue;}- return span;+ return {+ node: span,+ ratioX: x / (startX_fin + endX_fin),+ ratioY: y / (startY_fin + endY_fin),+ };}this._findLiquid.translateRestore();}diff --git a/packages/base-render/src/Component/Sheets/SheetSkeleton.ts b/packages/base-render/src/Component/Sheets/SheetSkeleton.tsindex 750e4e833b..6b263de4d4 100644--- a/packages/base-render/src/Component/Sheets/SheetSkeleton.ts+++ b/packages/base-render/src/Component/Sheets/SheetSkeleton.ts@@ -104,8 +104,8 @@ export class SpreadsheetSkeleton extends Skeleton {constructor(private _config: IWorksheetConfig, private _cellData: ObjectMatrix<ICellData>, private _styles: Styles, context: SheetContext) {super(context);- this.updateMatrix();- this.updateDataMergeCacheAll();+ this.updateLayout();+ this.updateDataMerge();}getWorksheetConfig() {@@ -169,7 +169,7 @@ export class SpreadsheetSkeleton extends Skeleton {return;}- this.dirty && this.updateMatrix();+ this.updateLayout();if (!this._rowHeightAccumulation || !this._columnWidthAccumulation) {return;@@ -184,7 +184,7 @@ export class SpreadsheetSkeleton extends Skeleton {return this;}- updateMatrix() {+ updateLayout() {if (!this.dirty) {return;}@@ -205,7 +205,7 @@ export class SpreadsheetSkeleton extends Skeleton {return this;}- updateDataMergeCacheAll() {+ updateDataMerge() {const { mergeData } = this._config;this._dataMergeCacheAll = mergeData && this._getMergeCells(mergeData);}diff --git a/packages/base-render/src/Custom/CustomObject.ts b/packages/base-render/src/Custom/CustomObject.tsindex f855e3e6f8..ce539c8614 100644--- a/packages/base-render/src/Custom/CustomObject.ts+++ b/packages/base-render/src/Custom/CustomObject.ts@@ -1,5 +1,6 @@import { BaseObject } from '../BaseObject';import { IBoundRect, Vector2 } from '../Basics';+import { transformBoundingCoord } from '../Basics/Position';export class CustomObject extends BaseObject {constructor(key?: string, private _render = (mainCtx: CanvasRenderingContext2D) => {}, private _isHitCustom?: (coord: Vector2) => boolean) {@@ -20,18 +21,7 @@ export class CustomObject extends BaseObject {// Temporarily ignore the on-demand display of elements within a group:this.isInGroupif (bounds && !this.isInGroup) {- const tl = this.transform.clone().invert().applyPoint(bounds.tl);- const tr = this.transform.clone().invert().applyPoint(bounds.tr);- const bl = this.transform.clone().invert().applyPoint(bounds.bl);- const br = this.transform.clone().invert().applyPoint(bounds.br);-- const xList = [tl.x, tr.x, bl.x, br.x];- const yList = [tl.y, tr.y, bl.y, br.y];-- const maxX = Math.max(...xList);- const minX = Math.min(...xList);- const maxY = Math.max(...yList);- const minY = Math.min(...yList);+ const { minX, maxX, minY, maxY } = transformBoundingCoord(this, bounds);if (this.width + this.strokeWidth < minX || maxX < 0 || this.height + this.strokeWidth < minY || maxY < 0) {// console.warn('ignore object', this);diff --git a/packages/base-render/src/Scene.ts b/packages/base-render/src/Scene.tsindex 44eaf41e5e..bb670e7b62 100644--- a/packages/base-render/src/Scene.ts+++ b/packages/base-render/src/Scene.ts@@ -588,17 +588,18 @@ export class Scene {return this._transformer;}+ getActiveViewportByCoord(coord: Vector2) {+ return this._viewports.find((vp) => vp.isHit(coord));+ }+transformToSceneCoord(coord: Vector2) {- const pickedViewport = this._viewports.find((vp) => vp.isHit(coord));- if (!pickedViewport) {- return;- }- return pickedViewport.getRelativeVector(coord);+ const pickedViewport = this.getActiveViewportByCoord(coord);+ return pickedViewport?.getRelativeVector(coord);}// Determine the only object selectedpick(coord: Vector2): Nullable<BaseObject | Scene> {- const pickedViewport = this._viewports.find((vp) => vp.isHit(coord));+ const pickedViewport = this.getActiveViewportByCoord(coord);if (!this._evented || !pickedViewport) {return;}diff --git a/packages/base-render/src/SceneViewer.ts b/packages/base-render/src/SceneViewer.tsindex 72885487ea..dc4c9ca4ff 100644--- a/packages/base-render/src/SceneViewer.ts+++ b/packages/base-render/src/SceneViewer.ts@@ -3,6 +3,7 @@ import { BaseObject } from './BaseObject';import { Scene } from './Scene';import { IObjectFullState } from './Basics/Interfaces';import { RENDER_CLASS_TYPE } from './Basics/Const';+import { transformBoundingCoord } from './Basics/Position';export class SceneViewer extends BaseObject {private _childrenScene: Scene;@@ -31,18 +32,7 @@ export class SceneViewer extends BaseObject {}if (bounds) {- const tl = this.transform.clone().invert().applyPoint(bounds.tl);- const tr = this.transform.clone().invert().applyPoint(bounds.tr);- const bl = this.transform.clone().invert().applyPoint(bounds.bl);- const br = this.transform.clone().invert().applyPoint(bounds.br);-- const xList = [tl.x, tr.x, bl.x, br.x];- const yList = [tl.y, tr.y, bl.y, br.y];-- const maxX = Math.max(...xList);- const minX = Math.min(...xList);- const maxY = Math.max(...yList);- const minY = Math.min(...yList);+ const { minX, maxX, minY, maxY } = transformBoundingCoord(this, bounds);if (this.width + this.strokeWidth < minX || maxX < 0 || this.height + this.strokeWidth < minY || maxY < 0) {// console.warn('ignore object', this);diff --git a/packages/base-render/src/Shape/RichText.ts b/packages/base-render/src/Shape/RichText.tsindex c22ac371f4..19af491a4a 100644--- a/packages/base-render/src/Shape/RichText.ts+++ b/packages/base-render/src/Shape/RichText.ts@@ -4,6 +4,7 @@ import { BlockType, SheetContext, IDocumentData, IKeyValue, ParagraphElementTypeimport { Canvas } from '..';import { BaseObject } from '../BaseObject';import { IBoundRect, IObjectFullState, TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '../Basics';+import { transformBoundingCoord } from '../Basics/Position';import { Documents, DocumentSkeleton } from '../Component';export interface IRichTextProps extends IObjectFullState {@@ -175,18 +176,7 @@ export class RichText extends BaseObject {// Temporarily ignore the on-demand display of elements within a group:this.isInGroupif (bounds && !this.isInGroup) {- const tl = this.transform.clone().invert().applyPoint(bounds.tl);- const tr = this.transform.clone().invert().applyPoint(bounds.tr);- const bl = this.transform.clone().invert().applyPoint(bounds.bl);- const br = this.transform.clone().invert().applyPoint(bounds.br);-- const xList = [tl.x, tr.x, bl.x, br.x];- const yList = [tl.y, tr.y, bl.y, br.y];-- const maxX = Math.max(...xList);- const minX = Math.min(...xList);- const maxY = Math.max(...yList);- const minY = Math.min(...yList);+ const { minX, maxX, minY, maxY } = transformBoundingCoord(this, bounds);if (this.width + this.strokeWidth < minX || maxX < 0 || this.height + this.strokeWidth < minY || maxY < 0) {// console.warn('ignore object', this);diff --git a/packages/base-render/src/Shape/Shape.ts b/packages/base-render/src/Shape/Shape.tsindex b95498eb6d..c84c53c6f7 100644--- a/packages/base-render/src/Shape/Shape.ts+++ b/packages/base-render/src/Shape/Shape.ts@@ -4,6 +4,7 @@ import { BaseObject, BASE_OBJECT_ARRAY } from '../BaseObject';import { IBoundRect, Vector2 } from '../Basics/Vector2';import { IObjectFullState, IScale } from '../Basics/Interfaces';import { SHAPE_TYPE } from '../Basics/Const';+import { transformBoundingCoord } from '../Basics/Position';export type LineJoin = 'round' | 'bevel' | 'miter';export type LineCap = 'butt' | 'round' | 'square';@@ -238,18 +239,7 @@ export abstract class Shape<T> extends BaseObject {// Temporarily ignore the on-demand display of elements within a group:this.isInGroupif (bounds && !this.isInGroup) {- const tl = this.transform.clone().invert().applyPoint(bounds.tl);- const tr = this.transform.clone().invert().applyPoint(bounds.tr);- const bl = this.transform.clone().invert().applyPoint(bounds.bl);- const br = this.transform.clone().invert().applyPoint(bounds.br);-- const xList = [tl.x, tr.x, bl.x, br.x];- const yList = [tl.y, tr.y, bl.y, br.y];-- const maxX = Math.max(...xList);- const minX = Math.min(...xList);- const maxY = Math.max(...yList);- const minY = Math.min(...yList);+ const { minX, maxX, minY, maxY } = transformBoundingCoord(this, bounds);if (this.width + this.strokeWidth < minX || maxX < 0 || this.height + this.strokeWidth < minY || maxY < 0) {// console.warn('ignore object', this);diff --git a/packages/base-render/src/Viewport.ts b/packages/base-render/src/Viewport.tsindex 815c8ab310..cb6b033690 100644--- a/packages/base-render/src/Viewport.ts+++ b/packages/base-render/src/Viewport.ts@@ -95,6 +95,8 @@ export class Viewport {private _allowCache: boolean = false;+ private _scrollStopNum: number;+scrollX: number = 0;scrollY: number = 0;@@ -342,6 +344,30 @@ export class Viewport {};}+ private _triggerScrollStop(+ scroll: {+ x: number;+ y: number;+ },+ x?: number,+ y?: number+ ) {+ window.clearTimeout(this._scrollStopNum);+ this._scrollStopNum = window.setTimeout(() => {+ this.onScrollStopObserver.notifyObservers({+ viewport: this,+ scrollX: this.scrollX,+ scrollY: this.scrollY,+ x,+ y,+ actualScrollX: scroll.x,+ actualScrollY: scroll.y,+ limitX: this._scrollBar?.limitX,+ limitY: this._scrollBar?.limitY,+ });+ }, 0);+ }+private _scroll(scrollType: SCROLL_TYPE, pos: IScrollBarPosition) {const { x, y } = pos;if (x !== undefined) {@@ -394,6 +420,8 @@ export class Viewport {limitY: this._scrollBar?.limitY,});+ this._triggerScrollStop(scroll, x, y);+return limited;}@@ -510,6 +538,10 @@ export class Viewport {this._scrollRendered();}+ getBounding() {+ return this._calViewportRelativeBounding();+ }+private _calViewportRelativeBounding() {let ratioScrollX = this._scrollBar?.ratioScrollX ?? 1;let ratioScrollY = this._scrollBar?.ratioScrollY ?? 1;@@ -554,6 +586,14 @@ export class Viewport {return svCoord;}+ getAbsoluteVector(coord: Vector2) {+ const sceneTrans = this.scene.transform.clone();+ const scroll = this.transformScroll();++ const svCoord = sceneTrans.applyPoint(coord).subtract(Vector2.FromArray([scroll.x, scroll.y]));+ return svCoord;+ }+private drawScrollbar(ctx: CanvasRenderingContext2D) {if (!this._scrollBar) {return;@@ -694,4 +734,6 @@ export class Viewport {onScrollAfterObserver = new Observable<IScrollObserverParam>();onScrollBeforeObserver = new Observable<IScrollObserverParam>();++ onScrollStopObserver = new Observable<IScrollObserverParam>();}