@univerjs/docs-drawing-ui 1.0.0-alpha.7 → 1.0.0-beta.0

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/cjs/index.js CHANGED
@@ -74,7 +74,7 @@ const UngroupDocDrawingCommand = {
74
74
  };
75
75
 
76
76
  //#endregion
77
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
77
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
78
78
  function _typeof(o) {
79
79
  "@babel/helpers - typeof";
80
80
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -85,7 +85,7 @@ function _typeof(o) {
85
85
  }
86
86
 
87
87
  //#endregion
88
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
88
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
89
89
  function toPrimitive(t, r) {
90
90
  if ("object" != _typeof(t) || !t) return t;
91
91
  var e = t[Symbol.toPrimitive];
@@ -98,14 +98,14 @@ function toPrimitive(t, r) {
98
98
  }
99
99
 
100
100
  //#endregion
101
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
101
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
102
102
  function toPropertyKey(t) {
103
103
  var i = toPrimitive(t, "string");
104
104
  return "symbol" == _typeof(i) ? i : i + "";
105
105
  }
106
106
 
107
107
  //#endregion
108
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
108
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
109
109
  function _defineProperty(e, r, t) {
110
110
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
111
111
  value: t,
@@ -128,7 +128,7 @@ var DocRefreshDrawingsService = class {
128
128
  };
129
129
 
130
130
  //#endregion
131
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
131
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
132
132
  function __decorateParam(paramIndex, decorator) {
133
133
  return function(target, key) {
134
134
  decorator(target, key, paramIndex);
@@ -136,7 +136,7 @@ function __decorateParam(paramIndex, decorator) {
136
136
  }
137
137
 
138
138
  //#endregion
139
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
139
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
140
140
  function __decorate(decorators, target, key, desc) {
141
141
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
142
142
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -227,7 +227,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
227
227
  const scaleHeight = _univerjs_drawing.DRAWING_IMAGE_HEIGHT_LIMIT / height;
228
228
  scale = Math.min(scaleWidth, scaleHeight);
229
229
  }
230
- const imagePosition = insertPosition !== null && insertPosition !== void 0 ? insertPosition : this._getCurrentImageInsertPosition();
230
+ const imagePosition = insertPosition ?? this._getCurrentImageInsertPosition();
231
231
  const docTransform = this._getImagePosition(width * scale, height * scale, imagePosition);
232
232
  if (docTransform == null) return;
233
233
  const transform = (0, _univerjs_docs.docDrawingPositionToTransform)(docTransform);
@@ -265,13 +265,12 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
265
265
  _isInsertInHeaderFooter() {
266
266
  var _this$_renderManagerS;
267
267
  const { unitId } = this._context;
268
- const viewModel = (_this$_renderManagerS = this._renderManagerSrv.getRenderById(unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs.DocSkeletonManagerService).getViewModel();
268
+ const viewModel = (_this$_renderManagerS = this._renderManagerSrv.getRenderUnitById(unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs.DocSkeletonManagerService).getViewModel();
269
269
  const editArea = viewModel === null || viewModel === void 0 ? void 0 : viewModel.getEditArea();
270
270
  return editArea === _univerjs_engine_render.DocumentEditArea.HEADER || editArea === _univerjs_engine_render.DocumentEditArea.FOOTER;
271
271
  }
272
272
  _getImagePosition(imageWidth, imageHeight, insertPosition) {
273
- var _ref;
274
- return (0, _univerjs_docs.buildDocTransform)(imageWidth, imageHeight, { left: ((_ref = insertPosition !== null && insertPosition !== void 0 ? insertPosition : this._getCurrentImageInsertPosition()) !== null && _ref !== void 0 ? _ref : {
273
+ return (0, _univerjs_docs.buildDocTransform)(imageWidth, imageHeight, { left: (insertPosition ?? this._getCurrentImageInsertPosition() ?? {
275
274
  left: 0,
276
275
  top: 0
277
276
  }).left });
@@ -325,8 +324,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
325
324
  }
326
325
  _focusDrawingListener() {
327
326
  this.disposeWithMe(this._drawingManagerService.focus$.subscribe((params) => {
328
- var _this$_getCurrentScen;
329
- const { transformer, docsLeft, docsTop } = (_this$_getCurrentScen = this._getCurrentSceneAndTransformer()) !== null && _this$_getCurrentScen !== void 0 ? _this$_getCurrentScen : {};
327
+ const { transformer, docsLeft, docsTop } = this._getCurrentSceneAndTransformer() ?? {};
330
328
  if (params == null || params.length === 0) {
331
329
  this._contextService.setContextValue(_univerjs_core.FOCUSING_COMMON_DRAWINGS, false);
332
330
  this._docDrawingService.focusDrawing([]);
@@ -350,10 +348,9 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
350
348
  }));
351
349
  }
352
350
  _findSegmentIdByDrawingId(drawingId) {
353
- var _body$customBlocks;
354
351
  const { unit: DocDataModel } = this._context;
355
352
  const { body, headers = {}, footers = {} } = DocDataModel.getSnapshot();
356
- if (((_body$customBlocks = body === null || body === void 0 ? void 0 : body.customBlocks) !== null && _body$customBlocks !== void 0 ? _body$customBlocks : []).some((b) => b.blockId === drawingId)) return "";
353
+ if (((body === null || body === void 0 ? void 0 : body.customBlocks) ?? []).some((b) => b.blockId === drawingId)) return "";
357
354
  for (const headerId of Object.keys(headers)) {
358
355
  var _headers$headerId$bod;
359
356
  if ((_headers$headerId$bod = headers[headerId].body.customBlocks) === null || _headers$headerId$bod === void 0 ? void 0 : _headers$headerId$bod.some((b) => b.blockId === drawingId)) return headerId;
@@ -368,7 +365,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
368
365
  var _this$_renderManagerS2;
369
366
  if (!this._context) return;
370
367
  const { unit: docDataModel, scene, unitId } = this._context;
371
- const viewModel = (_this$_renderManagerS2 = this._renderManagerSrv.getRenderById(unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs.DocSkeletonManagerService).getViewModel();
368
+ const viewModel = (_this$_renderManagerS2 = this._renderManagerSrv.getRenderUnitById(unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs.DocSkeletonManagerService).getViewModel();
372
369
  if (viewModel == null || docDataModel == null) return;
373
370
  const { drawings = {} } = docDataModel.getSnapshot();
374
371
  const isEditBody = viewModel.getEditArea() === _univerjs_engine_render.DocumentEditArea.BODY;
@@ -399,7 +396,7 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
399
396
  _editAreaChangeListener() {
400
397
  var _this$_renderManagerS3;
401
398
  const { unitId } = this._context;
402
- const viewModel = (_this$_renderManagerS3 = this._renderManagerSrv.getRenderById(unitId)) === null || _this$_renderManagerS3 === void 0 ? void 0 : _this$_renderManagerS3.with(_univerjs_docs.DocSkeletonManagerService).getViewModel();
399
+ const viewModel = (_this$_renderManagerS3 = this._renderManagerSrv.getRenderUnitById(unitId)) === null || _this$_renderManagerS3 === void 0 ? void 0 : _this$_renderManagerS3.with(_univerjs_docs.DocSkeletonManagerService).getViewModel();
403
400
  if (viewModel == null) return;
404
401
  this._updateDrawingsEditStatus();
405
402
  this.disposeWithMe(viewModel.editAreaChange$.subscribe(() => {
@@ -427,9 +424,9 @@ let DocDrawingUpdateRenderController = class DocDrawingUpdateRenderController ex
427
424
  }));
428
425
  }
429
426
  _setDrawingSelections(params) {
430
- var _unit$getSnapshot$bod, _unit$getSnapshot$bod2;
427
+ var _unit$getSnapshot$bod;
431
428
  const { unit } = this._context;
432
- const customBlocks = (_unit$getSnapshot$bod = (_unit$getSnapshot$bod2 = unit.getSnapshot().body) === null || _unit$getSnapshot$bod2 === void 0 ? void 0 : _unit$getSnapshot$bod2.customBlocks) !== null && _unit$getSnapshot$bod !== void 0 ? _unit$getSnapshot$bod : [];
429
+ const customBlocks = ((_unit$getSnapshot$bod = unit.getSnapshot().body) === null || _unit$getSnapshot$bod === void 0 ? void 0 : _unit$getSnapshot$bod.customBlocks) ?? [];
433
430
  const ranges = params.map((item) => {
434
431
  const id = item.drawingId;
435
432
  const block = customBlocks.find((b) => b.blockId === id);
@@ -463,10 +460,10 @@ const InsertDocImageCommand = {
463
460
  id: "doc.command.insert-float-image",
464
461
  type: _univerjs_core.CommandType.COMMAND,
465
462
  handler: (accessor) => {
466
- var _getCurrentTypeOfRend, _getCurrentTypeOfRend2;
463
+ var _getCurrentTypeOfRend;
467
464
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
468
465
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
469
- return (_getCurrentTypeOfRend = (_getCurrentTypeOfRend2 = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_DOC, univerInstanceService, renderManagerService)) === null || _getCurrentTypeOfRend2 === void 0 ? void 0 : _getCurrentTypeOfRend2.with(DocDrawingUpdateRenderController).insertDocImage()) !== null && _getCurrentTypeOfRend !== void 0 ? _getCurrentTypeOfRend : false;
466
+ return ((_getCurrentTypeOfRend = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_DOC, univerInstanceService, renderManagerService)) === null || _getCurrentTypeOfRend === void 0 ? void 0 : _getCurrentTypeOfRend.with(DocDrawingUpdateRenderController).insertDocImage()) ?? false;
470
467
  }
471
468
  };
472
469
 
@@ -530,7 +527,7 @@ const MoveDocDrawingsCommand = {
530
527
  const drawings = docDrawingService.getFocusDrawings();
531
528
  if (drawings.length === 0) return false;
532
529
  const unitId = drawings[0].unitId;
533
- const renderObject = renderManagerService.getRenderById(unitId);
530
+ const renderObject = renderManagerService.getRenderUnitById(unitId);
534
531
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
535
532
  if (scene == null) return false;
536
533
  const transformer = scene.getTransformerByCreate();
@@ -543,19 +540,10 @@ const MoveDocDrawingsCommand = {
543
540
  const { positionH, positionV } = drawingData.docTransform;
544
541
  const newPositionH = { ...positionH };
545
542
  const newPositionV = { ...positionV };
546
- if (direction === _univerjs_core.Direction.UP) {
547
- var _newPositionV$posOffs;
548
- newPositionV.posOffset = ((_newPositionV$posOffs = newPositionV.posOffset) !== null && _newPositionV$posOffs !== void 0 ? _newPositionV$posOffs : 0) - 2;
549
- } else if (direction === _univerjs_core.Direction.DOWN) {
550
- var _newPositionV$posOffs2;
551
- newPositionV.posOffset = ((_newPositionV$posOffs2 = newPositionV.posOffset) !== null && _newPositionV$posOffs2 !== void 0 ? _newPositionV$posOffs2 : 0) + 2;
552
- } else if (direction === _univerjs_core.Direction.LEFT) {
553
- var _newPositionH$posOffs;
554
- newPositionH.posOffset = ((_newPositionH$posOffs = newPositionH.posOffset) !== null && _newPositionH$posOffs !== void 0 ? _newPositionH$posOffs : 0) - 2;
555
- } else if (direction === _univerjs_core.Direction.RIGHT) {
556
- var _newPositionH$posOffs2;
557
- newPositionH.posOffset = ((_newPositionH$posOffs2 = newPositionH.posOffset) !== null && _newPositionH$posOffs2 !== void 0 ? _newPositionH$posOffs2 : 0) + 2;
558
- }
543
+ if (direction === _univerjs_core.Direction.UP) newPositionV.posOffset = (newPositionV.posOffset ?? 0) - 2;
544
+ else if (direction === _univerjs_core.Direction.DOWN) newPositionV.posOffset = (newPositionV.posOffset ?? 0) + 2;
545
+ else if (direction === _univerjs_core.Direction.LEFT) newPositionH.posOffset = (newPositionH.posOffset ?? 0) - 2;
546
+ else if (direction === _univerjs_core.Direction.RIGHT) newPositionH.posOffset = (newPositionH.posOffset ?? 0) + 2;
559
547
  return {
560
548
  drawingId,
561
549
  key: direction === _univerjs_core.Direction.UP || direction === _univerjs_core.Direction.DOWN ? "positionV" : "positionH",
@@ -582,7 +570,7 @@ const ClearDocDrawingTransformerOperation = {
582
570
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
583
571
  params.forEach((unitId) => {
584
572
  var _renderManagerService;
585
- (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 || (_renderManagerService = _renderManagerService.scene.getTransformer()) === null || _renderManagerService === void 0 || _renderManagerService.debounceRefreshControls();
573
+ (_renderManagerService = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService === void 0 || (_renderManagerService = _renderManagerService.scene.getTransformer()) === null || _renderManagerService === void 0 || _renderManagerService.debounceRefreshControls();
586
574
  });
587
575
  return true;
588
576
  }
@@ -670,7 +658,7 @@ function calcDocFloatDomPositionByRect(rect, scene, opacity = 1, angle = 0) {
670
658
  left: false,
671
659
  top: false
672
660
  },
673
- opacity: opacity !== null && opacity !== void 0 ? opacity : 1
661
+ opacity: opacity ?? 1
674
662
  };
675
663
  }
676
664
  function calcDocFloatDomPosition(object, renderUnit) {
@@ -697,6 +685,9 @@ function pickValidCustomBlockRenderViewport(viewport) {
697
685
  if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.contentHeight)) result.contentHeight = viewport.contentHeight;
698
686
  if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.contentWidth)) result.contentWidth = viewport.contentWidth;
699
687
  if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.height)) result.height = viewport.height;
688
+ if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.pageContentWidth)) result.pageContentWidth = viewport.pageContentWidth;
689
+ const viewScale = viewport === null || viewport === void 0 ? void 0 : viewport.viewScale;
690
+ if (isPositiveNumber(viewScale)) result.viewScale = viewScale;
700
691
  if (isPositiveNumber(viewport === null || viewport === void 0 ? void 0 : viewport.viewportHeight)) result.viewportHeight = viewport.viewportHeight;
701
692
  return Object.keys(result).length ? result : void 0;
702
693
  }
@@ -728,7 +719,7 @@ let DocFloatDomController = class DocFloatDomController extends _univerjs_core.D
728
719
  }
729
720
  _getSceneAndTransformerByDrawingSearch(unitId) {
730
721
  if (unitId == null) return;
731
- const renderObject = this._renderManagerService.getRenderById(unitId);
722
+ const renderObject = this._renderManagerService.getRenderUnitById(unitId);
732
723
  if (renderObject == null) return null;
733
724
  const scene = renderObject.scene;
734
725
  return {
@@ -783,6 +774,10 @@ let DocFloatDomController = class DocFloatDomController extends _univerjs_core.D
783
774
  position$,
784
775
  id: rectParam.drawingId,
785
776
  componentKey: rectParam.componentKey,
777
+ contentBox: isSheetLikeEmbedFloatDomRuntimeParam(runtimeParam) ? {
778
+ contentInset: 0,
779
+ wrapperInset: 0
780
+ } : void 0,
786
781
  eventPassThrough: preserveRuntimeGeometry ? false : void 0,
787
782
  preserveOnFocusChange: preserveRuntimeGeometry,
788
783
  onPointerDown: (evt) => {
@@ -820,7 +815,7 @@ let DocFloatDomController = class DocFloatDomController extends _univerjs_core.D
820
815
  params.forEach((param) => {
821
816
  var _this$_canvasFloatDom;
822
817
  const floatDomInfo = this._domLayerInfoMap.get(param.drawingId);
823
- if (!floatDomInfo) return;
818
+ if (!floatDomInfo || floatDomInfo.unitId !== param.unitId) return;
824
819
  const runtimeParam = param;
825
820
  const runtimeViewport = pickValidCustomBlockRenderViewport(runtimeParam.customBlockRenderViewport);
826
821
  if (runtimeViewport) floatDomInfo.runtimeViewport = runtimeViewport;
@@ -864,7 +859,7 @@ let DocFloatDomController = class DocFloatDomController extends _univerjs_core.D
864
859
  this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).pipe((0, rxjs.map)((documentDataModel) => {
865
860
  if (!documentDataModel) return null;
866
861
  const unitId = documentDataModel.getUnitId();
867
- const render = this._renderManagerService.getRenderById(unitId);
862
+ const render = this._renderManagerService.getRenderUnitById(unitId);
868
863
  return render ? {
869
864
  render,
870
865
  unitId
@@ -877,12 +872,14 @@ let DocFloatDomController = class DocFloatDomController extends _univerjs_core.D
877
872
  this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
878
873
  if (commandInfo.id === _univerjs_docs_ui.SetDocZoomRatioOperation.id) {
879
874
  const { unitId } = commandInfo.params;
880
- updateDoc(unitId);
875
+ globalThis.queueMicrotask(() => {
876
+ if (!this._disposed) updateDoc(unitId);
877
+ });
881
878
  }
882
879
  }));
883
880
  }
884
881
  insertFloatDom(floatDom, opts) {
885
- var _skeleton$getSkeleton, _opts$width, _opts$drawingId;
882
+ var _skeleton$getSkeleton;
886
883
  const currentDoc = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
887
884
  if (!currentDoc) return false;
888
885
  const render = this._getSceneAndTransformerByDrawingSearch(currentDoc.getUnitId());
@@ -893,7 +890,7 @@ let DocFloatDomController = class DocFloatDomController extends _univerjs_core.D
893
890
  const width = pageWidth - marginLeft - marginRight;
894
891
  const docTransform = {
895
892
  size: {
896
- width: (_opts$width = opts.width) !== null && _opts$width !== void 0 ? _opts$width : width,
893
+ width: opts.width ?? width,
897
894
  height: opts.height
898
895
  },
899
896
  positionH: {
@@ -906,7 +903,7 @@ let DocFloatDomController = class DocFloatDomController extends _univerjs_core.D
906
903
  },
907
904
  angle: 0
908
905
  };
909
- const drawingId = (_opts$drawingId = opts.drawingId) !== null && _opts$drawingId !== void 0 ? _opts$drawingId : (0, _univerjs_core.generateRandomId)();
906
+ const drawingId = opts.drawingId ?? (0, _univerjs_core.generateRandomId)();
910
907
  const params = {
911
908
  unitId: currentDoc.getUnitId(),
912
909
  drawings: [{
@@ -941,20 +938,16 @@ function syncRectWithRuntimeParam(rect, param, fallbackViewport, fallbackTransfo
941
938
  return true;
942
939
  }
943
940
  function getRuntimeTransform(param, rect, fallbackViewport, fallbackTransform, preserveRuntimeGeometry) {
944
- var _param$transform, _param$transforms, _param$customBlockRen, _runtimeViewport$heig2;
945
- const transform = (_param$transform = param.transform) !== null && _param$transform !== void 0 ? _param$transform : (_param$transforms = param.transforms) === null || _param$transforms === void 0 ? void 0 : _param$transforms[0];
946
- const runtimeViewport = (_param$customBlockRen = param.customBlockRenderViewport) !== null && _param$customBlockRen !== void 0 ? _param$customBlockRen : fallbackViewport;
947
- if (!param.customBlockRenderViewport && preserveRuntimeGeometry && fallbackTransform && transform) {
948
- var _fallbackTransform$wi, _fallbackTransform$he;
949
- return {
950
- ...transform,
951
- width: (_fallbackTransform$wi = fallbackTransform.width) !== null && _fallbackTransform$wi !== void 0 ? _fallbackTransform$wi : transform.width,
952
- height: (_fallbackTransform$he = fallbackTransform.height) !== null && _fallbackTransform$he !== void 0 ? _fallbackTransform$he : transform.height
953
- };
954
- }
941
+ var _param$transforms;
942
+ const transform = param.transform ?? ((_param$transforms = param.transforms) === null || _param$transforms === void 0 ? void 0 : _param$transforms[0]);
943
+ const runtimeViewport = param.customBlockRenderViewport ?? fallbackViewport;
944
+ if (!param.customBlockRenderViewport && preserveRuntimeGeometry && fallbackTransform && transform) return {
945
+ ...transform,
946
+ width: fallbackTransform.width ?? transform.width,
947
+ height: fallbackTransform.height ?? transform.height
948
+ };
955
949
  if (!transform) {
956
- var _runtimeViewport$heig;
957
- const height = (_runtimeViewport$heig = runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.height) !== null && _runtimeViewport$heig !== void 0 ? _runtimeViewport$heig : runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.contentHeight;
950
+ const height = (runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.height) ?? (runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.contentHeight);
958
951
  if (!isPositiveNumber(height)) return;
959
952
  return {
960
953
  left: rect.left,
@@ -964,7 +957,7 @@ function getRuntimeTransform(param, rect, fallbackViewport, fallbackTransform, p
964
957
  angle: rect.angle
965
958
  };
966
959
  }
967
- const height = (_runtimeViewport$heig2 = runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.height) !== null && _runtimeViewport$heig2 !== void 0 ? _runtimeViewport$heig2 : runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.contentHeight;
960
+ const height = (runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.height) ?? (runtimeViewport === null || runtimeViewport === void 0 ? void 0 : runtimeViewport.contentHeight);
968
961
  if (!isPositiveNumber(height)) return transform;
969
962
  return {
970
963
  ...transform,
@@ -977,6 +970,11 @@ function isEmbedFloatDomRuntimeParam(param) {
977
970
  const candidate = data;
978
971
  return candidate.version === 1 && typeof candidate.embedId === "string" && typeof candidate.hostAnchorId === "string";
979
972
  }
973
+ function isSheetLikeEmbedFloatDomRuntimeParam(param) {
974
+ if (!isEmbedFloatDomRuntimeParam(param)) return false;
975
+ const data = param.data;
976
+ return !!data && typeof data === "object" && "childType" in data && typeof data.childType === "number" && (0, _univerjs_docs.isSheetLikeDocsCustomBlockChildType)(data.childType);
977
+ }
980
978
  function createTransformFromRect(rect) {
981
979
  return {
982
980
  angle: rect.angle,
@@ -1197,7 +1195,7 @@ const menuSchema = {
1197
1195
  //#endregion
1198
1196
  //#region package.json
1199
1197
  var name = "@univerjs/docs-drawing-ui";
1200
- var version = "1.0.0-alpha.7";
1198
+ var version = "1.0.0-beta.0";
1201
1199
 
1202
1200
  //#endregion
1203
1201
  //#region src/config/config.ts
@@ -1228,7 +1226,7 @@ const DocDrawingPosition = (props) => {
1228
1226
  var _renderManagerService;
1229
1227
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
1230
1228
  const drawingParam = props.drawings[0];
1231
- const scene = drawingParam ? (_renderManagerService = renderManagerService.getRenderById(drawingParam.unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.scene : void 0;
1229
+ const scene = drawingParam ? (_renderManagerService = renderManagerService.getRenderUnitById(drawingParam.unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.scene : void 0;
1232
1230
  return drawingParam && scene ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocDrawingPositionContent, { ...props }) : null;
1233
1231
  };
1234
1232
  function DocDrawingPositionContent(props) {
@@ -1241,7 +1239,7 @@ function DocDrawingPositionContent(props) {
1241
1239
  const { unitId } = drawings[0];
1242
1240
  const documentDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
1243
1241
  const documentFlavor = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot().documentStyle.documentFlavor;
1244
- const transformer = renderManagerService.getRenderById(unitId).scene.getTransformerByCreate();
1242
+ const transformer = renderManagerService.getRenderUnitById(unitId).scene.getTransformerByCreate();
1245
1243
  const HORIZONTAL_RELATIVE_FROM = [
1246
1244
  {
1247
1245
  label: localeService.t("docs-drawing-ui.image-position.column"),
@@ -1310,7 +1308,7 @@ function DocDrawingPositionContent(props) {
1310
1308
  value
1311
1309
  }))
1312
1310
  });
1313
- const docSelectionRenderService = (_renderManagerService2 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(_univerjs_docs_ui.DocSelectionRenderService);
1311
+ const docSelectionRenderService = (_renderManagerService2 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.with(_univerjs_docs_ui.DocSelectionRenderService);
1314
1312
  if (docSelectionRenderService) docSelectionRenderService.blur();
1315
1313
  transformer.refreshControls();
1316
1314
  }
@@ -1326,7 +1324,7 @@ function DocDrawingPositionContent(props) {
1326
1324
  const unitId = focusDrawings[0].unitId;
1327
1325
  let drawing = null;
1328
1326
  let pageMarginLeft = 0;
1329
- const skeleton = (_renderManagerService3 = renderManagerService.getRenderById(unitId)) === null || _renderManagerService3 === void 0 ? void 0 : _renderManagerService3.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
1327
+ const skeleton = (_renderManagerService3 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService3 === void 0 ? void 0 : _renderManagerService3.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
1330
1328
  const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
1331
1329
  if (skeletonData == null) return;
1332
1330
  const { pages, skeHeaders, skeFooters } = skeletonData;
@@ -1360,7 +1358,7 @@ function DocDrawingPositionContent(props) {
1360
1358
  else if (relativeFrom === _univerjs_core.ObjectRelativeFromH.PAGE) {}
1361
1359
  handlePositionChange("positionH", {
1362
1360
  relativeFrom,
1363
- posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
1361
+ posOffset: (prevPosOffset ?? 0) - delta
1364
1362
  });
1365
1363
  }
1366
1364
  function handleVerticalRelativeFromChange(value) {
@@ -1395,7 +1393,7 @@ function DocDrawingPositionContent(props) {
1395
1393
  else if (relativeFrom === _univerjs_core.ObjectRelativeFromV.PAGE) delta -= page.marginTop;
1396
1394
  handlePositionChange("positionV", {
1397
1395
  relativeFrom,
1398
- posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
1396
+ posOffset: (prevPosOffset ?? 0) - delta
1399
1397
  });
1400
1398
  }
1401
1399
  function updateState(drawingParam) {
@@ -1707,7 +1705,7 @@ const IMoveInlineDrawingCommand = {
1707
1705
  id: "doc.command.move-inline-drawing",
1708
1706
  type: _univerjs_core.CommandType.COMMAND,
1709
1707
  handler: (accessor, params) => {
1710
- var _renderManagerService, _docSelectionRenderSe;
1708
+ var _renderManagerService;
1711
1709
  if (params == null) return false;
1712
1710
  const { drawing, unitId, offset, segmentId: newSegmentId, segmentPage, needRefreshDrawings } = params;
1713
1711
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
@@ -1728,7 +1726,7 @@ const IMoveInlineDrawingCommand = {
1728
1726
  }
1729
1727
  const rawActions = [];
1730
1728
  const { drawingId } = drawing;
1731
- const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, (_docSelectionRenderSe = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
1729
+ const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, docSelectionRenderService.getSegment() ?? "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
1732
1730
  if (actions == null || actions.length === 0) {
1733
1731
  docRefreshDrawingsService.refreshDrawings(skeleton);
1734
1732
  transformer.refreshControls();
@@ -1758,7 +1756,7 @@ const ITransformNonInlineDrawingCommand = {
1758
1756
  id: "doc.command.transform-non-inline-drawing",
1759
1757
  type: _univerjs_core.CommandType.COMMAND,
1760
1758
  handler: (accessor, params) => {
1761
- var _renderManagerService2, _docSelectionRenderSe2;
1759
+ var _renderManagerService2;
1762
1760
  if (params == null) return false;
1763
1761
  const { drawing, unitId, offset, docTransform, segmentId: newSegmentId, segmentPage } = params;
1764
1762
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
@@ -1772,7 +1770,7 @@ const ITransformNonInlineDrawingCommand = {
1772
1770
  if (documentDataModel == null) return false;
1773
1771
  const rawActions = [];
1774
1772
  const { drawingId } = drawing;
1775
- const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, (_docSelectionRenderSe2 = docSelectionRenderService.getSegment()) !== null && _docSelectionRenderSe2 !== void 0 ? _docSelectionRenderSe2 : "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
1773
+ const actions = getDeleteAndInsertCustomBlockActions(newSegmentId, docSelectionRenderService.getSegment() ?? "", segmentPage, offset, drawingId, documentDataModel, docSelectionRenderService);
1776
1774
  if (actions == null) return false;
1777
1775
  if (actions.length > 0) rawActions.push(...actions);
1778
1776
  const jsonX = _univerjs_core.JSONX.getInstance();
@@ -1902,10 +1900,11 @@ function DocDrawingTextWrapContent(props) {
1902
1900
  }
1903
1901
  function handleDistToTextChange(value, direction) {
1904
1902
  if (value == null) return;
1905
- setDistToText({
1903
+ const newDistToText = {
1906
1904
  ...distToText,
1907
1905
  [direction]: value
1908
- });
1906
+ };
1907
+ setDistToText(newDistToText);
1909
1908
  const focusDrawings = drawingManagerService.getFocusDrawings();
1910
1909
  if (focusDrawings.length === 0) return;
1911
1910
  const drawings = focusDrawings.map((drawing) => {
@@ -2267,7 +2266,7 @@ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends
2267
2266
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2268
2267
  if (command.id !== _univerjs_docs_drawing.UpdateDrawingDocTransformCommand.id && command.id !== _univerjs_docs_drawing.UpdateDocDrawingWrappingStyleCommand.id) return;
2269
2268
  const { unitId } = command.params;
2270
- const renderObject = this._renderManagerService.getRenderById(unitId);
2269
+ const renderObject = this._renderManagerService.getRenderUnitById(unitId);
2271
2270
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
2272
2271
  if (renderObject == null || scene == null) return;
2273
2272
  this._docRefreshDrawingsService.refreshDrawings(renderObject.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton());
@@ -2281,23 +2280,23 @@ let DocDrawingAddRemoveController = class DocDrawingAddRemoveController extends
2281
2280
  if (unitId == null || focusedDrawings.length === 0) return;
2282
2281
  const renderObject = this._renderManagerService.getRenderUnitById(unitId);
2283
2282
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
2284
- if (scene == null) return false;
2283
+ if (renderObject == null || scene == null) return false;
2284
+ this._docRefreshDrawingsService.refreshDrawings(renderObject.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton());
2285
2285
  scene.getTransformerByCreate().refreshControls();
2286
2286
  }));
2287
2287
  }
2288
2288
  _preserveWrappingStylePosition(params) {
2289
- var _documentDataModel$ge;
2290
2289
  if (params.wrappingStyle === _univerjs_docs_drawing.TextWrappingStyle.INLINE) return;
2291
2290
  const { unitId } = params;
2292
2291
  const documentDataModel = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
2293
- const renderObject = this._renderManagerService.getRenderById(unitId);
2292
+ const renderObject = this._renderManagerService.getRenderUnitById(unitId);
2294
2293
  const skeletonManager = renderObject === null || renderObject === void 0 ? void 0 : renderObject.with(_univerjs_docs.DocSkeletonManagerService);
2295
2294
  const skeletonData = skeletonManager === null || skeletonManager === void 0 ? void 0 : skeletonManager.getSkeleton().getSkeletonData();
2296
2295
  const viewModel = skeletonManager === null || skeletonManager === void 0 ? void 0 : skeletonManager.getViewModel();
2297
2296
  if (!documentDataModel || !skeletonData || !viewModel) return;
2298
2297
  const editArea = viewModel.getEditArea();
2299
2298
  const { pages, skeHeaders, skeFooters } = skeletonData;
2300
- const oldDrawings = (_documentDataModel$ge = documentDataModel.getDrawings()) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : {};
2299
+ const oldDrawings = documentDataModel.getDrawings() ?? {};
2301
2300
  params.drawings = params.drawings.map((drawing) => {
2302
2301
  const oldDrawing = oldDrawings[drawing.drawingId];
2303
2302
  if (!oldDrawing) return drawing;
@@ -2595,8 +2594,7 @@ function getDocsTableCellDrawingOffset(unitId, table, row, cell) {
2595
2594
  };
2596
2595
  }
2597
2596
  function hasHorizontalTableViewport(viewport) {
2598
- var _viewport$leadingInse, _viewport$trailingIns;
2599
- return viewport != null && ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0) + viewport.contentWidth + ((_viewport$trailingIns = viewport.trailingInsetRight) !== null && _viewport$trailingIns !== void 0 ? _viewport$trailingIns : 0) > viewport.viewportWidth;
2597
+ return viewport != null && (viewport.leadingInsetLeft ?? 0) + viewport.contentWidth + (viewport.trailingInsetRight ?? 0) > viewport.viewportWidth;
2600
2598
  }
2601
2599
  let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateController extends _univerjs_core.Disposable {
2602
2600
  constructor(_context, _docSkeletonManagerService, _commandService, _editorService, _drawingManagerService, _docRefreshDrawingsService, _univerInstanceService, _lifecycleService) {
@@ -2616,7 +2614,7 @@ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateControl
2616
2614
  _initialize() {
2617
2615
  this._initialRenderRefresh();
2618
2616
  this._drawingInitializeListener();
2619
- this._initResize();
2617
+ this._initTransformRefresh();
2620
2618
  }
2621
2619
  _initialRenderRefresh() {
2622
2620
  this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((documentSkeleton) => {
@@ -2645,8 +2643,8 @@ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateControl
2645
2643
  }
2646
2644
  }));
2647
2645
  }
2648
- _initResize() {
2649
- this.disposeWithMe((0, _univerjs_core.fromEventSubject)(this._context.engine.onTransformChange$).pipe((0, rxjs.filter)((evt) => evt.type === _univerjs_engine_render.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize), (0, rxjs.debounceTime)(16)).subscribe(() => {
2646
+ _initTransformRefresh() {
2647
+ this.disposeWithMe((0, rxjs.merge)((0, _univerjs_core.fromEventSubject)(this._context.engine.onTransformChange$).pipe((0, rxjs.filter)((evt) => evt.type === _univerjs_engine_render.TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)), (0, _univerjs_core.fromEventSubject)(this._context.scene.onTransformChange$).pipe((0, rxjs.filter)((evt) => evt.type === _univerjs_engine_render.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale))).pipe((0, rxjs.debounceTime)(16)).subscribe(() => {
2650
2648
  var _scene$getTransformer;
2651
2649
  const skeleton = this._docSkeletonManagerService.getSkeleton();
2652
2650
  const { scene } = this._context;
@@ -2700,21 +2698,17 @@ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateControl
2700
2698
  this._handleMultiDrawingsTransform(multiDrawings);
2701
2699
  }
2702
2700
  _getStaleNonMultiDrawings(unitId, updateDrawingMap) {
2703
- var _this$_drawingManager;
2704
- const drawingData = (_this$_drawingManager = this._drawingManagerService.getDrawingData(unitId, unitId)) !== null && _this$_drawingManager !== void 0 ? _this$_drawingManager : {};
2705
- return Object.values(drawingData).filter((drawing) => drawing.isMultiTransform !== _univerjs_core.BooleanNumber.TRUE).filter((drawing) => updateDrawingMap[drawing.drawingId] == null).map((drawing) => {
2706
- var _drawing$transforms, _drawing$isMultiTrans;
2707
- return {
2708
- unitId,
2709
- subUnitId: unitId,
2710
- drawingId: drawing.drawingId,
2711
- behindText: false,
2712
- hidden: true,
2713
- transform: drawing.transform,
2714
- transforms: (_drawing$transforms = drawing.transforms) !== null && _drawing$transforms !== void 0 ? _drawing$transforms : [],
2715
- isMultiTransform: (_drawing$isMultiTrans = drawing.isMultiTransform) !== null && _drawing$isMultiTrans !== void 0 ? _drawing$isMultiTrans : _univerjs_core.BooleanNumber.FALSE
2716
- };
2717
- });
2701
+ const drawingData = this._drawingManagerService.getDrawingData(unitId, unitId) ?? {};
2702
+ return Object.values(drawingData).filter((drawing) => drawing.isMultiTransform !== _univerjs_core.BooleanNumber.TRUE).filter((drawing) => updateDrawingMap[drawing.drawingId] == null).map((drawing) => ({
2703
+ unitId,
2704
+ subUnitId: unitId,
2705
+ drawingId: drawing.drawingId,
2706
+ behindText: false,
2707
+ hidden: true,
2708
+ transform: drawing.transform,
2709
+ transforms: drawing.transforms ?? [],
2710
+ isMultiTransform: drawing.isMultiTransform ?? _univerjs_core.BooleanNumber.FALSE
2711
+ }));
2718
2712
  }
2719
2713
  _handleMultiDrawingsTransform(multiDrawings) {
2720
2714
  const { scene, unitId } = this._context;
@@ -2786,8 +2780,8 @@ let DocDrawingTransformUpdateController = class DocDrawingTransformUpdateControl
2786
2780
  height
2787
2781
  }) : void 0;
2788
2782
  const transform = {
2789
- left: (pageRelativeLeft !== null && pageRelativeLeft !== void 0 ? pageRelativeLeft : aLeft) + docsLeft + (pageRelativeLeft == null ? this._liquid.x : pageOffsetLeft),
2790
- top: (pageRelativeTop !== null && pageRelativeTop !== void 0 ? pageRelativeTop : aTop) + docsTop + (pageRelativeTop == null ? this._liquid.y : pageOffsetTop),
2783
+ left: (pageRelativeLeft ?? aLeft) + docsLeft + (pageRelativeLeft == null ? this._liquid.x : pageOffsetLeft),
2784
+ top: (pageRelativeTop ?? aTop) + docsTop + (pageRelativeTop == null ? this._liquid.y : pageOffsetTop),
2791
2785
  width,
2792
2786
  height,
2793
2787
  angle,
@@ -2868,6 +2862,28 @@ function getDocsTableCellAnchorContext(unitId, cell) {
2868
2862
  table
2869
2863
  };
2870
2864
  }
2865
+ function shouldUseDocsDrawingOuterPageOrigin(config) {
2866
+ const { drawing, height, hostPage, page, width } = config;
2867
+ if (drawing.layoutType !== _univerjs_core.PositionedObjectLayoutType.WRAP_NONE) return false;
2868
+ return getDocsPageRelativeDrawingAnchorPage({
2869
+ page,
2870
+ clipPage: getDocsDrawingClipPage({
2871
+ drawing: {
2872
+ behindText: getDocsDrawingBehindText({
2873
+ drawingOrigin: drawing,
2874
+ hostPage
2875
+ }),
2876
+ transform: {
2877
+ width,
2878
+ height
2879
+ }
2880
+ },
2881
+ hostPage,
2882
+ page
2883
+ }),
2884
+ hostPage
2885
+ }) != null;
2886
+ }
2871
2887
  let DocDrawingTransformerController = class DocDrawingTransformerController extends _univerjs_core.Disposable {
2872
2888
  constructor(_commandService, _univerInstanceService, _drawingManagerService, _renderManagerService) {
2873
2889
  super();
@@ -2924,7 +2940,6 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
2924
2940
  }
2925
2941
  })));
2926
2942
  const throttleMultipleDrawingUpdate = (0, _univerjs_core.throttle)(this._updateMultipleDrawingDocTransform.bind(this), 50);
2927
- (0, _univerjs_core.throttle)(this._nonInlineDrawingTransform.bind(this), 50);
2928
2943
  this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.changing$.subscribe((state) => {
2929
2944
  const { objects, offsetX, offsetY } = state;
2930
2945
  if (objects.size > 1) throttleMultipleDrawingUpdate(objects);
@@ -2932,7 +2947,6 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
2932
2947
  const drawingCache = this._transformerCache.values().next().value;
2933
2948
  const { width, height, top, left, angle } = objects.values().next().value;
2934
2949
  if (drawingCache && width === drawingCache.width && height === drawingCache.height && top === drawingCache.top && left === drawingCache.left && angle === drawingCache.angle) return;
2935
- if (drawingCache && drawingCache.drawing.layoutType !== _univerjs_core.PositionedObjectLayoutType.INLINE) {}
2936
2950
  if (drawingCache && drawingCache.drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE && offsetX != null && offsetY != null) this._updateInlineDrawingAnchor(drawingCache.drawing, offsetX, offsetY);
2937
2951
  }
2938
2952
  })));
@@ -3026,15 +3040,14 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3026
3040
  this._getDrawingAnchor(drawingCache.drawing, object);
3027
3041
  }
3028
3042
  _updateInlineDrawingAnchor(drawing, offsetX, offsetY) {
3029
- var _this$_getInlineDrawi;
3030
3043
  if (this._transformerCache.size !== 1) return;
3031
- const { contentBoxPointGroup } = (_this$_getInlineDrawi = this._getInlineDrawingAnchor(drawing, offsetX, offsetY)) !== null && _this$_getInlineDrawi !== void 0 ? _this$_getInlineDrawi : {};
3044
+ const { contentBoxPointGroup } = this._getInlineDrawingAnchor(drawing, offsetX, offsetY) ?? {};
3032
3045
  if (contentBoxPointGroup == null) return;
3033
3046
  this._createOrUpdateInlineAnchor(drawing.unitId, contentBoxPointGroup);
3034
3047
  }
3035
3048
  _getInlineDrawingAnchor(drawing, offsetX, offsetY) {
3036
- var _this$_renderManagerS, _getOneTextSelectionR;
3037
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3049
+ var _this$_renderManagerS;
3050
+ const currentRender = this._renderManagerService.getRenderUnitById(drawing.unitId);
3038
3051
  const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
3039
3052
  if (currentRender == null) return;
3040
3053
  const { mainComponent, scene } = currentRender;
@@ -3048,7 +3061,7 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3048
3061
  const HALF = .5;
3049
3062
  const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, offsetX, offsetY);
3050
3063
  if (coord == null) return;
3051
- const docSelectionRenderService = (_this$_renderManagerS = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs_ui.DocSelectionRenderService);
3064
+ const docSelectionRenderService = (_this$_renderManagerS = this._renderManagerService.getRenderUnitById(drawing.unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs_ui.DocSelectionRenderService);
3052
3065
  if (docSelectionRenderService == null) return;
3053
3066
  const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
3054
3067
  strict: false,
@@ -3064,14 +3077,14 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3064
3077
  }
3065
3078
  if (glyphAnchor == null) return;
3066
3079
  const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPageIndex);
3067
- const docObject = this._getDocObject();
3068
- if (nodePosition == null || skeleton == null || docObject == null) return;
3080
+ const docObject = (0, _univerjs_docs_ui.neoGetDocObject)(currentRender);
3081
+ if (nodePosition == null || skeleton == null) return;
3069
3082
  const positionWithIsBack = {
3070
3083
  ...nodePosition,
3071
3084
  isBack
3072
3085
  };
3073
3086
  const { cursorList, contentBoxPointGroup } = new _univerjs_docs_ui.NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
3074
- const { startOffset } = (_getOneTextSelectionR = (0, _univerjs_docs_ui.getOneTextSelectionRange)(cursorList)) !== null && _getOneTextSelectionR !== void 0 ? _getOneTextSelectionR : {};
3087
+ const { startOffset } = (0, _univerjs_docs_ui.getOneTextSelectionRange)(cursorList) ?? {};
3075
3088
  if (startOffset == null) return;
3076
3089
  return {
3077
3090
  offset: startOffset,
@@ -3081,8 +3094,8 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3081
3094
  };
3082
3095
  }
3083
3096
  _getDrawingAnchor(drawing, object) {
3084
- var _this$_renderManagerS2, _glyphAnchor$parent, _column$parent$top, _column$parent, _column$lines$find, _column$parent2, _tableCellContext$hos, _getOneTextSelectionR2;
3085
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3097
+ var _this$_renderManagerS2, _glyphAnchor$parent, _column$parent, _column$parent2;
3098
+ const currentRender = this._renderManagerService.getRenderUnitById(drawing.unitId);
3086
3099
  const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
3087
3100
  const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
3088
3101
  if (skeletonData == null || currentRender == null) return;
@@ -3112,7 +3125,7 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3112
3125
  const { x, y } = scene.getViewportScrollXY(activeViewport);
3113
3126
  const coord = this._getTransformCoordForDocumentOffset(documentComponent, activeViewport, left - x, top - y);
3114
3127
  if (coord == null) return;
3115
- const docSelectionRenderService = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(drawing.unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs_ui.DocSelectionRenderService);
3128
+ const docSelectionRenderService = (_this$_renderManagerS2 = this._renderManagerService.getRenderUnitById(drawing.unitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs_ui.DocSelectionRenderService);
3116
3129
  if (docSelectionRenderService == null) return;
3117
3130
  const nodeInfo = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findNodeByCoord(coord, pageLayoutType, pageMarginLeft, pageMarginTop, {
3118
3131
  strict: false,
@@ -3128,18 +3141,30 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3128
3141
  if (glyphAnchor == null) return;
3129
3142
  const line = (_glyphAnchor$parent = glyphAnchor.parent) === null || _glyphAnchor$parent === void 0 ? void 0 : _glyphAnchor$parent.parent;
3130
3143
  const column = line === null || line === void 0 ? void 0 : line.parent;
3131
- const sectionTop = (_column$parent$top = column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.top) !== null && _column$parent$top !== void 0 ? _column$parent$top : 0;
3132
- const paragraphStartLine = (_column$lines$find = column === null || column === void 0 ? void 0 : column.lines.find((l) => l.paragraphIndex === (line === null || line === void 0 ? void 0 : line.paragraphIndex) && l.paragraphStart)) !== null && _column$lines$find !== void 0 ? _column$lines$find : column === null || column === void 0 ? void 0 : column.lines[0];
3144
+ const sectionTop = (column === null || column === void 0 || (_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : _column$parent.top) ?? 0;
3145
+ const paragraphStartLine = (column === null || column === void 0 ? void 0 : column.lines.find((l) => l.paragraphIndex === (line === null || line === void 0 ? void 0 : line.paragraphIndex) && l.paragraphStart)) ?? (column === null || column === void 0 ? void 0 : column.lines[0]);
3133
3146
  const page = column === null || column === void 0 || (_column$parent2 = column.parent) === null || _column$parent2 === void 0 ? void 0 : _column$parent2.parent;
3134
3147
  if (line == null || column == null || paragraphStartLine == null || page == null) return;
3135
3148
  this._liquid.reset();
3136
3149
  const tableCellContext = page.type === _univerjs_engine_render.DocumentSkeletonPageType.CELL ? getDocsTableCellAnchorContext(drawing.unitId, page) : null;
3137
- const anchorPage = (_tableCellContext$hos = tableCellContext === null || tableCellContext === void 0 ? void 0 : tableCellContext.hostPage) !== null && _tableCellContext$hos !== void 0 ? _tableCellContext$hos : page;
3150
+ const anchorPage = (tableCellContext === null || tableCellContext === void 0 ? void 0 : tableCellContext.hostPage) ?? page;
3138
3151
  const pageType = anchorPage.type;
3152
+ const drawingHostPage = (page.type === _univerjs_engine_render.DocumentSkeletonPageType.HEADER || page.type === _univerjs_engine_render.DocumentSkeletonPageType.FOOTER) && segmentPage > -1 ? pages[segmentPage] : void 0;
3153
+ const useOuterPageOrigin = shouldUseDocsDrawingOuterPageOrigin({
3154
+ drawing,
3155
+ height: object.height,
3156
+ hostPage: drawingHostPage,
3157
+ page,
3158
+ width: object.width
3159
+ });
3160
+ let pageOffsetLeft = this._liquid.x;
3161
+ let pageOffsetTop = this._liquid.y;
3139
3162
  for (const p of pages) {
3140
3163
  const { headerId, footerId, pageHeight, pageWidth, marginLeft, marginBottom } = p;
3141
3164
  const pIndex = pages.indexOf(p);
3142
3165
  if (segmentPage > -1 && pIndex === segmentPage) {
3166
+ pageOffsetLeft = this._liquid.x;
3167
+ pageOffsetTop = this._liquid.y;
3143
3168
  switch (pageType) {
3144
3169
  case _univerjs_engine_render.DocumentSkeletonPageType.HEADER: {
3145
3170
  var _skeHeaders$get;
@@ -3167,6 +3192,10 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3167
3192
  }
3168
3193
  break;
3169
3194
  }
3195
+ if (p === anchorPage) {
3196
+ pageOffsetLeft = this._liquid.x;
3197
+ pageOffsetTop = this._liquid.y;
3198
+ }
3170
3199
  this._liquid.translatePagePadding(p);
3171
3200
  if (p === anchorPage) break;
3172
3201
  this._liquid.restorePagePadding(p);
@@ -3175,14 +3204,17 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3175
3204
  if (tableCellContext) this._liquid.translate(tableCellContext.offset.left, tableCellContext.offset.top);
3176
3205
  if (positionV.relativeFrom === _univerjs_core.ObjectRelativeFromV.LINE) glyphAnchor = line.divides[0].glyphGroup[0];
3177
3206
  else {
3178
- var _paragraphStartLine$d, _paragraphStartLine$d2;
3179
- glyphAnchor = (_paragraphStartLine$d = (_paragraphStartLine$d2 = paragraphStartLine.divides) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2[0]) === null || _paragraphStartLine$d2 === void 0 || (_paragraphStartLine$d2 = _paragraphStartLine$d2.glyphGroup) === null || _paragraphStartLine$d2 === void 0 ? void 0 : _paragraphStartLine$d2[0]) !== null && _paragraphStartLine$d !== void 0 ? _paragraphStartLine$d : glyphAnchor;
3207
+ var _paragraphStartLine$d;
3208
+ glyphAnchor = ((_paragraphStartLine$d = paragraphStartLine.divides) === null || _paragraphStartLine$d === void 0 || (_paragraphStartLine$d = _paragraphStartLine$d[0]) === null || _paragraphStartLine$d === void 0 || (_paragraphStartLine$d = _paragraphStartLine$d.glyphGroup) === null || _paragraphStartLine$d === void 0 ? void 0 : _paragraphStartLine$d[0]) ?? glyphAnchor;
3180
3209
  }
3181
3210
  docTransform.positionH = {
3182
3211
  relativeFrom: positionH.relativeFrom,
3183
3212
  posOffset: left - this._liquid.x - docsLeft
3184
3213
  };
3185
3214
  switch (positionH.relativeFrom) {
3215
+ case _univerjs_core.ObjectRelativeFromH.PAGE:
3216
+ if (useOuterPageOrigin) docTransform.positionH.posOffset = left - pageOffsetLeft - docsLeft;
3217
+ break;
3186
3218
  case _univerjs_core.ObjectRelativeFromH.MARGIN:
3187
3219
  docTransform.positionH.posOffset = left - this._liquid.x - docsLeft - page.marginLeft;
3188
3220
  break;
@@ -3196,7 +3228,7 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3196
3228
  };
3197
3229
  switch (positionV.relativeFrom) {
3198
3230
  case _univerjs_core.ObjectRelativeFromV.PAGE:
3199
- docTransform.positionV.posOffset = top - this._liquid.y - docsTop - page.marginTop;
3231
+ docTransform.positionV.posOffset = useOuterPageOrigin ? top - pageOffsetTop - docsTop : top - this._liquid.y - docsTop + page.marginTop;
3200
3232
  break;
3201
3233
  case _univerjs_core.ObjectRelativeFromV.LINE:
3202
3234
  docTransform.positionV.posOffset = top - this._liquid.y - docsTop - sectionTop - line.top;
@@ -3207,14 +3239,14 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3207
3239
  }
3208
3240
  if (glyphAnchor == null) return;
3209
3241
  const nodePosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.findPositionByGlyph(glyphAnchor, segmentPage);
3210
- const docObject = this._getDocObject();
3211
- if (nodePosition == null || skeleton == null || docObject == null) return;
3242
+ const docObject = (0, _univerjs_docs_ui.neoGetDocObject)(currentRender);
3243
+ if (nodePosition == null || skeleton == null) return;
3212
3244
  const positionWithIsBack = {
3213
3245
  ...nodePosition,
3214
3246
  isBack
3215
3247
  };
3216
3248
  const { cursorList } = new _univerjs_docs_ui.NodePositionConvertToCursor(docObject.document.getOffsetConfig(), skeleton).getRangePointData(positionWithIsBack, positionWithIsBack);
3217
- const { startOffset } = (_getOneTextSelectionR2 = (0, _univerjs_docs_ui.getOneTextSelectionRange)(cursorList)) !== null && _getOneTextSelectionR2 !== void 0 ? _getOneTextSelectionR2 : {};
3249
+ const { startOffset } = (0, _univerjs_docs_ui.getOneTextSelectionRange)(cursorList) ?? {};
3218
3250
  if (startOffset == null) return;
3219
3251
  return {
3220
3252
  offset: startOffset,
@@ -3251,8 +3283,7 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3251
3283
  });
3252
3284
  }
3253
3285
  _moveInlineDrawing(drawing, offsetX, offsetY) {
3254
- const anchor = this._getInlineDrawingAnchor(drawing, offsetX, offsetY);
3255
- const { offset, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
3286
+ const { offset, segmentId, segmentPage } = this._getInlineDrawingAnchor(drawing, offsetX, offsetY) ?? {};
3256
3287
  return this._commandService.executeCommand(IMoveInlineDrawingCommand.id, {
3257
3288
  unitId: drawing.unitId,
3258
3289
  subUnitId: drawing.unitId,
@@ -3264,11 +3295,11 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3264
3295
  });
3265
3296
  }
3266
3297
  _limitDrawingInPage(drawing, object) {
3267
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3298
+ const currentRender = this._renderManagerService.getRenderUnitById(drawing.unitId);
3268
3299
  const { left, top, width, height, angle } = object;
3269
3300
  const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
3270
3301
  const skeletonData = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getSkeletonData();
3271
- const { pages } = skeletonData !== null && skeletonData !== void 0 ? skeletonData : {};
3302
+ const { pages } = skeletonData ?? {};
3272
3303
  if (skeletonData == null || currentRender == null || pages == null) return {
3273
3304
  left,
3274
3305
  top,
@@ -3299,8 +3330,7 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3299
3330
  _nonInlineDrawingTransform(drawing, object, isMoving = false) {
3300
3331
  const objectPosition = drawing.isMultiTransform === _univerjs_core.BooleanNumber.TRUE ? object : this._limitDrawingInPage(drawing, object);
3301
3332
  if (isMoving && objectPosition.top !== object.top) return;
3302
- const anchor = this._getDrawingAnchor(drawing, objectPosition);
3303
- const { offset, docTransform, segmentId, segmentPage } = anchor !== null && anchor !== void 0 ? anchor : {};
3333
+ const { offset, docTransform, segmentId, segmentPage } = this._getDrawingAnchor(drawing, objectPosition) ?? {};
3304
3334
  if (offset == null || docTransform == null) return this._updateMultipleDrawingDocTransform(/* @__PURE__ */ new Map([[drawing.drawingId, object]]));
3305
3335
  return this._commandService.executeCommand(ITransformNonInlineDrawingCommand.id, {
3306
3336
  unitId: drawing.unitId,
@@ -3314,7 +3344,7 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3314
3344
  }
3315
3345
  _getSceneAndTransformerByDrawingSearch(unitId) {
3316
3346
  if (unitId == null) return;
3317
- const renderObject = this._renderManagerService.getRenderById(unitId);
3347
+ const renderObject = this._renderManagerService.getRenderUnitById(unitId);
3318
3348
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3319
3349
  if (scene == null) return;
3320
3350
  return {
@@ -3329,7 +3359,7 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3329
3359
  return documentTransform.clone().invert().applyPoint(originCoord);
3330
3360
  }
3331
3361
  _createOrUpdateInlineAnchor(unitId, pointsGroup) {
3332
- const currentRender = this._renderManagerService.getRenderById(unitId);
3362
+ const currentRender = this._renderManagerService.getRenderUnitById(unitId);
3333
3363
  if (currentRender == null) return;
3334
3364
  const { mainComponent, scene } = currentRender;
3335
3365
  const { docsLeft, docsTop } = mainComponent.getOffsetConfig();
@@ -3356,11 +3386,8 @@ let DocDrawingTransformerController = class DocDrawingTransformerController exte
3356
3386
  this._anchorShape = anchor;
3357
3387
  scene.addObject(anchor, _univerjs_docs_ui.TEXT_RANGE_LAYER_INDEX);
3358
3388
  }
3359
- _getDocObject() {
3360
- return (0, _univerjs_docs_ui.getDocObject)(this._univerInstanceService, this._renderManagerService);
3361
- }
3362
3389
  _getPageContentSize(drawing) {
3363
- const currentRender = this._renderManagerService.getRenderById(drawing.unitId);
3390
+ const currentRender = this._renderManagerService.getRenderUnitById(drawing.unitId);
3364
3391
  const skeleton = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
3365
3392
  const MAX_WIDTH = 500;
3366
3393
  const MAX_HEIGHT = 500;
@@ -3607,7 +3634,7 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
3607
3634
  }
3608
3635
  _popupMenuListener(unitId) {
3609
3636
  var _this$_renderManagerS;
3610
- const scene = (_this$_renderManagerS = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.scene;
3637
+ const scene = (_this$_renderManagerS = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.scene;
3611
3638
  if (!scene) return;
3612
3639
  const transformer = scene.getTransformerByCreate();
3613
3640
  if (!transformer) return;
@@ -3663,7 +3690,6 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
3663
3690
  }));
3664
3691
  }
3665
3692
  _getDrawingPopupMenuItems(unitId, subUnitId, drawingId, drawingType) {
3666
- var _editCommandInfo$labe, _editCommandInfo$comm, _editCommandInfo$comm2, _editCommandInfo$disa;
3667
3693
  const drawing = this._drawingManagerService.getDrawingByParam({
3668
3694
  unitId,
3669
3695
  subUnitId,
@@ -3682,15 +3708,15 @@ let DocDrawingPopupMenuController = class DocDrawingPopupMenuController extends
3682
3708
  }) : null;
3683
3709
  return [
3684
3710
  {
3685
- label: (_editCommandInfo$labe = editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.label) !== null && _editCommandInfo$labe !== void 0 ? _editCommandInfo$labe : "docs-drawing-ui.image-popup.edit",
3711
+ label: (editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.label) ?? "docs-drawing-ui.image-popup.edit",
3686
3712
  index: 0,
3687
- commandId: (_editCommandInfo$comm = editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.commandId) !== null && _editCommandInfo$comm !== void 0 ? _editCommandInfo$comm : EditDocDrawingOperation.id,
3688
- commandParams: (_editCommandInfo$comm2 = editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.commandParams) !== null && _editCommandInfo$comm2 !== void 0 ? _editCommandInfo$comm2 : {
3713
+ commandId: (editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.commandId) ?? EditDocDrawingOperation.id,
3714
+ commandParams: (editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.commandParams) ?? {
3689
3715
  unitId,
3690
3716
  subUnitId,
3691
3717
  drawingId
3692
3718
  },
3693
- disable: (_editCommandInfo$disa = editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.disable) !== null && _editCommandInfo$disa !== void 0 ? _editCommandInfo$disa : drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_DOM,
3719
+ disable: (editCommandInfo === null || editCommandInfo === void 0 ? void 0 : editCommandInfo.disable) ?? drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_DOM,
3694
3720
  hideOnClick: true,
3695
3721
  icon: "DrawingEditIcon"
3696
3722
  },
@@ -3789,7 +3815,7 @@ _defineProperty(UniverDocsDrawingUIPlugin, "pluginName", "DOC_DRAWING_UI_PLUGIN"
3789
3815
  _defineProperty(UniverDocsDrawingUIPlugin, "packageName", name);
3790
3816
  _defineProperty(UniverDocsDrawingUIPlugin, "version", version);
3791
3817
  UniverDocsDrawingUIPlugin = __decorate([
3792
- (0, _univerjs_core.DependentOn)(_univerjs_drawing_ui.UniverDrawingUIPlugin, _univerjs_drawing.UniverDrawingPlugin, _univerjs_docs_drawing.UniverDocsDrawingPlugin, _univerjs_ui.UniverUIPlugin),
3818
+ (0, _univerjs_core.DependentOn)(_univerjs_docs.UniverDocsPlugin, _univerjs_drawing.UniverDrawingPlugin, _univerjs_engine_render.UniverRenderEnginePlugin, _univerjs_docs_drawing.UniverDocsDrawingPlugin, _univerjs_docs_ui.UniverDocsUIPlugin, _univerjs_drawing_ui.UniverDrawingUIPlugin),
3793
3819
  __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3794
3820
  __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
3795
3821
  __decorateParam(3, _univerjs_core.IConfigService)