@univerjs/sheets-drawing-ui 1.0.0-alpha.3 → 1.0.0-alpha.4

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
@@ -3,7 +3,7 @@ let _univerjs_core = require("@univerjs/core");
3
3
  let _univerjs_sheets_drawing = require("@univerjs/sheets-drawing");
4
4
  let _univerjs_engine_render = require("@univerjs/engine-render");
5
5
  let _univerjs_design = require("@univerjs/design");
6
- let _univerjs_docs_ui = require("@univerjs/docs-ui");
6
+ let _univerjs_docs = require("@univerjs/docs");
7
7
  let _univerjs_drawing = require("@univerjs/drawing");
8
8
  let _univerjs_sheets = require("@univerjs/sheets");
9
9
  let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
@@ -13,6 +13,7 @@ let rxjs = require("rxjs");
13
13
  let _univerjs_docs_drawing = require("@univerjs/docs-drawing");
14
14
  let react = require("react");
15
15
  let react_jsx_runtime = require("react/jsx-runtime");
16
+ let _univerjs_docs_ui = require("@univerjs/docs-ui");
16
17
 
17
18
  //#region src/commands/commands/delete-drawings.command.ts
18
19
  const DeleteDrawingsCommand = {
@@ -541,21 +542,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
541
542
  col
542
543
  }, width, height, 0);
543
544
  if (!imageSize) return false;
544
- const docTransform = {
545
- size: {
546
- width: imageSize.width,
547
- height: imageSize.height
548
- },
549
- positionH: {
550
- relativeFrom: _univerjs_core.ObjectRelativeFromH.PAGE,
551
- posOffset: 0
552
- },
553
- positionV: {
554
- relativeFrom: _univerjs_core.ObjectRelativeFromV.PARAGRAPH,
555
- posOffset: 0
556
- },
557
- angle: 0
558
- };
545
+ const docTransform = (0, _univerjs_docs.buildDocTransform)(imageSize.width, imageSize.height);
559
546
  const docDrawingParam = {
560
547
  unitId: docDataModel.getUnitId(),
561
548
  subUnitId: docDataModel.getUnitId(),
@@ -563,7 +550,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
563
550
  drawingType: _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE,
564
551
  imageSourceType,
565
552
  source,
566
- transform: (0, _univerjs_docs_ui.docDrawingPositionToTransform)(docTransform),
553
+ transform: (0, _univerjs_docs.docDrawingPositionToTransform)(docTransform),
567
554
  docTransform,
568
555
  behindDoc: _univerjs_core.BooleanNumber.FALSE,
569
556
  title: "",
@@ -617,21 +604,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
617
604
  col: selection.primary.actualColumn
618
605
  }, width, height, 0);
619
606
  if (!imageSize) return false;
620
- const docTransform = {
621
- size: {
622
- width: imageSize.width,
623
- height: imageSize.height
624
- },
625
- positionH: {
626
- relativeFrom: _univerjs_core.ObjectRelativeFromH.PAGE,
627
- posOffset: 0
628
- },
629
- positionV: {
630
- relativeFrom: _univerjs_core.ObjectRelativeFromV.PARAGRAPH,
631
- posOffset: 0
632
- },
633
- angle: 0
634
- };
607
+ const docTransform = (0, _univerjs_docs.buildDocTransform)(imageSize.width, imageSize.height);
635
608
  const docDrawingParam = {
636
609
  unitId: docDataModel.getUnitId(),
637
610
  subUnitId: docDataModel.getUnitId(),
@@ -639,7 +612,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends _u
639
612
  drawingType: _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE,
640
613
  imageSourceType: _univerjs_core.ImageSourceType.URL,
641
614
  source: url,
642
- transform: (0, _univerjs_docs_ui.docDrawingPositionToTransform)(docTransform),
615
+ transform: (0, _univerjs_docs.docDrawingPositionToTransform)(docTransform),
643
616
  docTransform,
644
617
  behindDoc: _univerjs_core.BooleanNumber.FALSE,
645
618
  title: "",
@@ -3491,7 +3464,7 @@ const menuSchema = {
3491
3464
  //#endregion
3492
3465
  //#region package.json
3493
3466
  var name = "@univerjs/sheets-drawing-ui";
3494
- var version = "1.0.0-alpha.3";
3467
+ var version = "1.0.0-alpha.4";
3495
3468
 
3496
3469
  //#endregion
3497
3470
  //#region src/config/config.ts
@@ -3633,14 +3606,11 @@ const SheetDrawingAnchor = (props) => {
3633
3606
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
3634
3607
  const { drawings } = props;
3635
3608
  const drawingParam = drawings[0];
3636
- if (drawingParam == null) return;
3637
- const { unitId } = drawingParam;
3638
- const renderObject = renderManagerService.getRenderById(unitId);
3609
+ const renderObject = drawingParam ? renderManagerService.getRenderById(drawingParam.unitId) : void 0;
3639
3610
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3640
- if (scene == null) return;
3641
- const transformer = scene.getTransformerByCreate();
3611
+ const transformer = scene === null || scene === void 0 ? void 0 : scene.getTransformerByCreate();
3642
3612
  const [anchorShow, setAnchorShow] = (0, react.useState)(true);
3643
- const [value, setValue] = (0, react.useState)((_drawingParam$anchorT = drawingParam.anchorType) !== null && _drawingParam$anchorT !== void 0 ? _drawingParam$anchorT : _univerjs_sheets_drawing.SheetDrawingAnchorType.Position);
3613
+ const [value, setValue] = (0, react.useState)((_drawingParam$anchorT = drawingParam === null || drawingParam === void 0 ? void 0 : drawingParam.anchorType) !== null && _drawingParam$anchorT !== void 0 ? _drawingParam$anchorT : _univerjs_sheets_drawing.SheetDrawingAnchorType.Position);
3644
3614
  function getUpdateParams(objects, drawingManagerService) {
3645
3615
  const params = [];
3646
3616
  objects.forEach((object) => {
@@ -3664,6 +3634,7 @@ const SheetDrawingAnchor = (props) => {
3664
3634
  return params;
3665
3635
  }
3666
3636
  (0, react.useEffect)(() => {
3637
+ if (!transformer) return;
3667
3638
  const onClearControlObserver = transformer.clearControl$.subscribe((changeSelf) => {
3668
3639
  if (changeSelf === true) setAnchorShow(false);
3669
3640
  });
@@ -3681,7 +3652,8 @@ const SheetDrawingAnchor = (props) => {
3681
3652
  onChangeStartObserver.unsubscribe();
3682
3653
  onClearControlObserver.unsubscribe();
3683
3654
  };
3684
- }, []);
3655
+ }, [drawingManagerService, transformer]);
3656
+ if (!drawingParam || !transformer) return null;
3685
3657
  function handleChange(value) {
3686
3658
  setValue(value);
3687
3659
  const focusDrawings = drawingManagerService.getFocusDrawings();
@@ -3728,17 +3700,24 @@ const SheetDrawingAnchor = (props) => {
3728
3700
 
3729
3701
  //#endregion
3730
3702
  //#region src/views/sheet-image-panel/SheetDrawingPanel.tsx
3703
+ /**
3704
+ * Copyright 2023-present DreamNum Co., Ltd.
3705
+ *
3706
+ * Licensed under the Apache License, Version 2.0 (the "License");
3707
+ * you may not use this file except in compliance with the License.
3708
+ * You may obtain a copy of the License at
3709
+ *
3710
+ * http://www.apache.org/licenses/LICENSE-2.0
3711
+ *
3712
+ * Unless required by applicable law or agreed to in writing, software
3713
+ * distributed under the License is distributed on an "AS IS" BASIS,
3714
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3715
+ * See the License for the specific language governing permissions and
3716
+ * limitations under the License.
3717
+ */
3731
3718
  const SheetDrawingPanel = () => {
3732
3719
  const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
3733
- const [drawings, setDrawings] = (0, react.useState)(drawingManagerService.getFocusDrawings());
3734
- (0, react.useEffect)(() => {
3735
- const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
3736
- setDrawings(drawings);
3737
- });
3738
- return () => {
3739
- focusDispose.unsubscribe();
3740
- };
3741
- }, []);
3720
+ const drawings = (0, _univerjs_ui.useObservable)(() => drawingManagerService.focus$, drawingManagerService.getFocusDrawings(), false, [drawingManagerService]);
3742
3721
  return !!(drawings === null || drawings === void 0 ? void 0 : drawings.length) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3743
3722
  className: "univer-text-sm",
3744
3723
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_drawing_ui.DrawingCommonPanel, { drawings }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetDrawingAnchor, { drawings })]
package/lib/es/index.js CHANGED
@@ -1,17 +1,18 @@
1
- import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, ObjectRelativeFromH, ObjectRelativeFromV, Optional, Plugin, PositionedObjectLayoutType, RANGE_TYPE, Rectangle, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
1
+ import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RANGE_TYPE, Rectangle, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
3
3
  import { CURSOR_TYPE, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_VIEWPORT_KEY, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { Button, Checkbox, CheckboxGroup, FormLayout, MessageType, Radio, RadioGroup, Select, clsx, render, unmount } from "@univerjs/design";
5
- import { InnerPasteCommand, docDrawingPositionToTransform } from "@univerjs/docs-ui";
5
+ import { buildDocTransform, docDrawingPositionToTransform } from "@univerjs/docs";
6
6
  import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, IDrawingManagerService, SetDrawingSelectedOperation, UniverDrawingPlugin, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize } from "@univerjs/drawing";
7
7
  import { COMMAND_LISTENER_SKELETON_CHANGE, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, IAutoFillService, INTERCEPTOR_POINT, InsertColCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, InterceptCellContentPriority, MoveColsCommand, MoveRangeCommand, MoveRowsCommand, RangeProtectionPermissionEditPoint, RemoveColCommand, RemoveRowCommand, SetColHiddenCommand, SetColHiddenMutation, SetColVisibleMutation, SetColWidthCommand, SetFrozenMutation, SetRangeValuesCommand, SetRowHeightCommand, SetRowHiddenCommand, SetRowHiddenMutation, SetRowVisibleMutation, SetSelectionsOperation, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetActiveOperation, SetWorksheetColWidthMutation, SetWorksheetRowAutoHeightMutation, SetWorksheetRowHeightMutation, SetWorksheetRowIsAutoHeightMutation, SheetInterceptorService, SheetPermissionCheckController, SheetSkeletonService, SheetsSelectionsService, WorkbookEditablePermission, WorkbookViewPermission, WorksheetEditPermission, WorksheetViewPermission, attachRangeWithCoord, discreteRangeToRange, getSheetCommandTarget } from "@univerjs/sheets";
8
8
  import { COPY_TYPE, EditingRenderController, HoverManagerService, IEditorBridgeService, ISheetClipboardService, ISheetSelectionRenderService, PREDEFINED_HOOK_NAME_PASTE, SetCellEditVisibleOperation, SetScrollOperation, SetZoomRatioOperation, SheetCanvasPopManagerService, SheetPrintInterceptorService, SheetSkeletonManagerService, getCurrentRangeDisable$, useHighlightRange, virtualizeDiscreteRanges } from "@univerjs/sheets-ui";
9
- import { CanvasFloatDomPreviewService, CanvasFloatDomService, ComponentManager, ContextMenuGroup, ContextMenuPosition, IClipboardInterfaceService, IContextMenuService, IDialogService, ILocalFileService, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, KeyCode, MenuItemType, PrintFloatDomSingle, RibbonInsertGroup, connectInjector, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
9
+ import { CanvasFloatDomPreviewService, CanvasFloatDomService, ComponentManager, ContextMenuGroup, ContextMenuPosition, IClipboardInterfaceService, IContextMenuService, IDialogService, ILocalFileService, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, KeyCode, MenuItemType, PrintFloatDomSingle, RibbonInsertGroup, connectInjector, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
10
10
  import { COMPONENT_IMAGE_POPUP_MENU, DrawingCommonPanel, DrawingRenderService, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation, UniverDrawingUIPlugin, disposeDrawingRenderObject, insertGroupObject } from "@univerjs/drawing-ui";
11
11
  import { BehaviorSubject, EMPTY, Subject, combineLatest, distinctUntilChanged, filter, map, of, switchMap, take, tap, throttleTime } from "rxjs";
12
12
  import { DocDrawingController, UniverDocsDrawingPlugin } from "@univerjs/docs-drawing";
13
13
  import { useCallback, useEffect, useMemo, useState } from "react";
14
14
  import { jsx, jsxs } from "react/jsx-runtime";
15
+ import { InnerPasteCommand } from "@univerjs/docs-ui";
15
16
 
16
17
  //#region src/commands/commands/delete-drawings.command.ts
17
18
  const DeleteDrawingsCommand = {
@@ -540,21 +541,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
540
541
  col
541
542
  }, width, height, 0);
542
543
  if (!imageSize) return false;
543
- const docTransform = {
544
- size: {
545
- width: imageSize.width,
546
- height: imageSize.height
547
- },
548
- positionH: {
549
- relativeFrom: ObjectRelativeFromH.PAGE,
550
- posOffset: 0
551
- },
552
- positionV: {
553
- relativeFrom: ObjectRelativeFromV.PARAGRAPH,
554
- posOffset: 0
555
- },
556
- angle: 0
557
- };
544
+ const docTransform = buildDocTransform(imageSize.width, imageSize.height);
558
545
  const docDrawingParam = {
559
546
  unitId: docDataModel.getUnitId(),
560
547
  subUnitId: docDataModel.getUnitId(),
@@ -616,21 +603,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
616
603
  col: selection.primary.actualColumn
617
604
  }, width, height, 0);
618
605
  if (!imageSize) return false;
619
- const docTransform = {
620
- size: {
621
- width: imageSize.width,
622
- height: imageSize.height
623
- },
624
- positionH: {
625
- relativeFrom: ObjectRelativeFromH.PAGE,
626
- posOffset: 0
627
- },
628
- positionV: {
629
- relativeFrom: ObjectRelativeFromV.PARAGRAPH,
630
- posOffset: 0
631
- },
632
- angle: 0
633
- };
606
+ const docTransform = buildDocTransform(imageSize.width, imageSize.height);
634
607
  const docDrawingParam = {
635
608
  unitId: docDataModel.getUnitId(),
636
609
  subUnitId: docDataModel.getUnitId(),
@@ -3490,7 +3463,7 @@ const menuSchema = {
3490
3463
  //#endregion
3491
3464
  //#region package.json
3492
3465
  var name = "@univerjs/sheets-drawing-ui";
3493
- var version = "1.0.0-alpha.3";
3466
+ var version = "1.0.0-alpha.4";
3494
3467
 
3495
3468
  //#endregion
3496
3469
  //#region src/config/config.ts
@@ -3632,14 +3605,11 @@ const SheetDrawingAnchor = (props) => {
3632
3605
  const renderManagerService = useDependency(IRenderManagerService);
3633
3606
  const { drawings } = props;
3634
3607
  const drawingParam = drawings[0];
3635
- if (drawingParam == null) return;
3636
- const { unitId } = drawingParam;
3637
- const renderObject = renderManagerService.getRenderById(unitId);
3608
+ const renderObject = drawingParam ? renderManagerService.getRenderById(drawingParam.unitId) : void 0;
3638
3609
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3639
- if (scene == null) return;
3640
- const transformer = scene.getTransformerByCreate();
3610
+ const transformer = scene === null || scene === void 0 ? void 0 : scene.getTransformerByCreate();
3641
3611
  const [anchorShow, setAnchorShow] = useState(true);
3642
- const [value, setValue] = useState((_drawingParam$anchorT = drawingParam.anchorType) !== null && _drawingParam$anchorT !== void 0 ? _drawingParam$anchorT : SheetDrawingAnchorType.Position);
3612
+ const [value, setValue] = useState((_drawingParam$anchorT = drawingParam === null || drawingParam === void 0 ? void 0 : drawingParam.anchorType) !== null && _drawingParam$anchorT !== void 0 ? _drawingParam$anchorT : SheetDrawingAnchorType.Position);
3643
3613
  function getUpdateParams(objects, drawingManagerService) {
3644
3614
  const params = [];
3645
3615
  objects.forEach((object) => {
@@ -3663,6 +3633,7 @@ const SheetDrawingAnchor = (props) => {
3663
3633
  return params;
3664
3634
  }
3665
3635
  useEffect(() => {
3636
+ if (!transformer) return;
3666
3637
  const onClearControlObserver = transformer.clearControl$.subscribe((changeSelf) => {
3667
3638
  if (changeSelf === true) setAnchorShow(false);
3668
3639
  });
@@ -3680,7 +3651,8 @@ const SheetDrawingAnchor = (props) => {
3680
3651
  onChangeStartObserver.unsubscribe();
3681
3652
  onClearControlObserver.unsubscribe();
3682
3653
  };
3683
- }, []);
3654
+ }, [drawingManagerService, transformer]);
3655
+ if (!drawingParam || !transformer) return null;
3684
3656
  function handleChange(value) {
3685
3657
  setValue(value);
3686
3658
  const focusDrawings = drawingManagerService.getFocusDrawings();
@@ -3727,17 +3699,24 @@ const SheetDrawingAnchor = (props) => {
3727
3699
 
3728
3700
  //#endregion
3729
3701
  //#region src/views/sheet-image-panel/SheetDrawingPanel.tsx
3702
+ /**
3703
+ * Copyright 2023-present DreamNum Co., Ltd.
3704
+ *
3705
+ * Licensed under the Apache License, Version 2.0 (the "License");
3706
+ * you may not use this file except in compliance with the License.
3707
+ * You may obtain a copy of the License at
3708
+ *
3709
+ * http://www.apache.org/licenses/LICENSE-2.0
3710
+ *
3711
+ * Unless required by applicable law or agreed to in writing, software
3712
+ * distributed under the License is distributed on an "AS IS" BASIS,
3713
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3714
+ * See the License for the specific language governing permissions and
3715
+ * limitations under the License.
3716
+ */
3730
3717
  const SheetDrawingPanel = () => {
3731
3718
  const drawingManagerService = useDependency(IDrawingManagerService);
3732
- const [drawings, setDrawings] = useState(drawingManagerService.getFocusDrawings());
3733
- useEffect(() => {
3734
- const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
3735
- setDrawings(drawings);
3736
- });
3737
- return () => {
3738
- focusDispose.unsubscribe();
3739
- };
3740
- }, []);
3719
+ const drawings = useObservable(() => drawingManagerService.focus$, drawingManagerService.getFocusDrawings(), false, [drawingManagerService]);
3741
3720
  return !!(drawings === null || drawings === void 0 ? void 0 : drawings.length) && /* @__PURE__ */ jsxs("div", {
3742
3721
  className: "univer-text-sm",
3743
3722
  children: [/* @__PURE__ */ jsx(DrawingCommonPanel, { drawings }), /* @__PURE__ */ jsx(SheetDrawingAnchor, { drawings })]
package/lib/index.js CHANGED
@@ -1,17 +1,18 @@
1
- import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, ObjectRelativeFromH, ObjectRelativeFromV, Optional, Plugin, PositionedObjectLayoutType, RANGE_TYPE, Rectangle, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
1
+ import { BooleanNumber, BuildTextUtils, CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_PANEL_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_SHEET, ICommandService, IConfigService, IContextService, IImageIoService, IPermissionService, IURLImageService, IUndoRedoService, IUniverInstanceService, ImageSourceType, ImageUploadStatusType, Inject, Injector, InterceptorEffectEnum, LifecycleService, LifecycleStages, LocaleService, ObjectMatrix, Optional, Plugin, PositionedObjectLayoutType, RANGE_TYPE, Rectangle, RxDisposable, Tools, UniverInstanceType, UserManagerService, WrapTextType, createDocumentModelWithStyle, createIdentifier, fromEventSubject, generateRandomId, merge, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, transformToAxisAlignPosition, transformToDrawingPosition } from "@univerjs/sheets-drawing";
3
3
  import { CURSOR_TYPE, DRAWING_OBJECT_LAYER_INDEX, IRenderManagerService, Image, ObjectType, Rect, SHEET_VIEWPORT_KEY, Vector2, getCurrentTypeOfRenderer, getGroupState, transformObjectOutOfGroup } from "@univerjs/engine-render";
4
4
  import { Button, Checkbox, CheckboxGroup, FormLayout, MessageType, Radio, RadioGroup, Select, clsx, render, unmount } from "@univerjs/design";
5
- import { InnerPasteCommand, docDrawingPositionToTransform } from "@univerjs/docs-ui";
5
+ import { buildDocTransform, docDrawingPositionToTransform } from "@univerjs/docs";
6
6
  import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, IDrawingManagerService, SetDrawingSelectedOperation, UniverDrawingPlugin, getDrawingImageAllowSize, getDrawingShapeKeyByDrawingSearch, getImageSize } from "@univerjs/drawing";
7
7
  import { COMMAND_LISTENER_SKELETON_CHANGE, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, IAutoFillService, INTERCEPTOR_POINT, InsertColCommand, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, InterceptCellContentPriority, MoveColsCommand, MoveRangeCommand, MoveRowsCommand, RangeProtectionPermissionEditPoint, RemoveColCommand, RemoveRowCommand, SetColHiddenCommand, SetColHiddenMutation, SetColVisibleMutation, SetColWidthCommand, SetFrozenMutation, SetRangeValuesCommand, SetRowHeightCommand, SetRowHiddenCommand, SetRowHiddenMutation, SetRowVisibleMutation, SetSelectionsOperation, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetActiveOperation, SetWorksheetColWidthMutation, SetWorksheetRowAutoHeightMutation, SetWorksheetRowHeightMutation, SetWorksheetRowIsAutoHeightMutation, SheetInterceptorService, SheetPermissionCheckController, SheetSkeletonService, SheetsSelectionsService, WorkbookEditablePermission, WorkbookViewPermission, WorksheetEditPermission, WorksheetViewPermission, attachRangeWithCoord, discreteRangeToRange, getSheetCommandTarget } from "@univerjs/sheets";
8
8
  import { COPY_TYPE, EditingRenderController, HoverManagerService, IEditorBridgeService, ISheetClipboardService, ISheetSelectionRenderService, PREDEFINED_HOOK_NAME_PASTE, SetCellEditVisibleOperation, SetScrollOperation, SetZoomRatioOperation, SheetCanvasPopManagerService, SheetPrintInterceptorService, SheetSkeletonManagerService, getCurrentRangeDisable$, useHighlightRange, virtualizeDiscreteRanges } from "@univerjs/sheets-ui";
9
- import { CanvasFloatDomPreviewService, CanvasFloatDomService, ComponentManager, ContextMenuGroup, ContextMenuPosition, IClipboardInterfaceService, IContextMenuService, IDialogService, ILocalFileService, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, KeyCode, MenuItemType, PrintFloatDomSingle, RibbonInsertGroup, connectInjector, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
9
+ import { CanvasFloatDomPreviewService, CanvasFloatDomService, ComponentManager, ContextMenuGroup, ContextMenuPosition, IClipboardInterfaceService, IContextMenuService, IDialogService, ILocalFileService, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, KeyCode, MenuItemType, PrintFloatDomSingle, RibbonInsertGroup, connectInjector, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
10
10
  import { COMPONENT_IMAGE_POPUP_MENU, DrawingCommonPanel, DrawingRenderService, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation, UniverDrawingUIPlugin, disposeDrawingRenderObject, insertGroupObject } from "@univerjs/drawing-ui";
11
11
  import { BehaviorSubject, EMPTY, Subject, combineLatest, distinctUntilChanged, filter, map, of, switchMap, take, tap, throttleTime } from "rxjs";
12
12
  import { DocDrawingController, UniverDocsDrawingPlugin } from "@univerjs/docs-drawing";
13
13
  import { useCallback, useEffect, useMemo, useState } from "react";
14
14
  import { jsx, jsxs } from "react/jsx-runtime";
15
+ import { InnerPasteCommand } from "@univerjs/docs-ui";
15
16
 
16
17
  //#region src/commands/commands/delete-drawings.command.ts
17
18
  const DeleteDrawingsCommand = {
@@ -540,21 +541,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
540
541
  col
541
542
  }, width, height, 0);
542
543
  if (!imageSize) return false;
543
- const docTransform = {
544
- size: {
545
- width: imageSize.width,
546
- height: imageSize.height
547
- },
548
- positionH: {
549
- relativeFrom: ObjectRelativeFromH.PAGE,
550
- posOffset: 0
551
- },
552
- positionV: {
553
- relativeFrom: ObjectRelativeFromV.PARAGRAPH,
554
- posOffset: 0
555
- },
556
- angle: 0
557
- };
544
+ const docTransform = buildDocTransform(imageSize.width, imageSize.height);
558
545
  const docDrawingParam = {
559
546
  unitId: docDataModel.getUnitId(),
560
547
  subUnitId: docDataModel.getUnitId(),
@@ -616,21 +603,7 @@ let SheetDrawingUpdateController = class SheetDrawingUpdateController extends Di
616
603
  col: selection.primary.actualColumn
617
604
  }, width, height, 0);
618
605
  if (!imageSize) return false;
619
- const docTransform = {
620
- size: {
621
- width: imageSize.width,
622
- height: imageSize.height
623
- },
624
- positionH: {
625
- relativeFrom: ObjectRelativeFromH.PAGE,
626
- posOffset: 0
627
- },
628
- positionV: {
629
- relativeFrom: ObjectRelativeFromV.PARAGRAPH,
630
- posOffset: 0
631
- },
632
- angle: 0
633
- };
606
+ const docTransform = buildDocTransform(imageSize.width, imageSize.height);
634
607
  const docDrawingParam = {
635
608
  unitId: docDataModel.getUnitId(),
636
609
  subUnitId: docDataModel.getUnitId(),
@@ -3490,7 +3463,7 @@ const menuSchema = {
3490
3463
  //#endregion
3491
3464
  //#region package.json
3492
3465
  var name = "@univerjs/sheets-drawing-ui";
3493
- var version = "1.0.0-alpha.3";
3466
+ var version = "1.0.0-alpha.4";
3494
3467
 
3495
3468
  //#endregion
3496
3469
  //#region src/config/config.ts
@@ -3632,14 +3605,11 @@ const SheetDrawingAnchor = (props) => {
3632
3605
  const renderManagerService = useDependency(IRenderManagerService);
3633
3606
  const { drawings } = props;
3634
3607
  const drawingParam = drawings[0];
3635
- if (drawingParam == null) return;
3636
- const { unitId } = drawingParam;
3637
- const renderObject = renderManagerService.getRenderById(unitId);
3608
+ const renderObject = drawingParam ? renderManagerService.getRenderById(drawingParam.unitId) : void 0;
3638
3609
  const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
3639
- if (scene == null) return;
3640
- const transformer = scene.getTransformerByCreate();
3610
+ const transformer = scene === null || scene === void 0 ? void 0 : scene.getTransformerByCreate();
3641
3611
  const [anchorShow, setAnchorShow] = useState(true);
3642
- const [value, setValue] = useState((_drawingParam$anchorT = drawingParam.anchorType) !== null && _drawingParam$anchorT !== void 0 ? _drawingParam$anchorT : SheetDrawingAnchorType.Position);
3612
+ const [value, setValue] = useState((_drawingParam$anchorT = drawingParam === null || drawingParam === void 0 ? void 0 : drawingParam.anchorType) !== null && _drawingParam$anchorT !== void 0 ? _drawingParam$anchorT : SheetDrawingAnchorType.Position);
3643
3613
  function getUpdateParams(objects, drawingManagerService) {
3644
3614
  const params = [];
3645
3615
  objects.forEach((object) => {
@@ -3663,6 +3633,7 @@ const SheetDrawingAnchor = (props) => {
3663
3633
  return params;
3664
3634
  }
3665
3635
  useEffect(() => {
3636
+ if (!transformer) return;
3666
3637
  const onClearControlObserver = transformer.clearControl$.subscribe((changeSelf) => {
3667
3638
  if (changeSelf === true) setAnchorShow(false);
3668
3639
  });
@@ -3680,7 +3651,8 @@ const SheetDrawingAnchor = (props) => {
3680
3651
  onChangeStartObserver.unsubscribe();
3681
3652
  onClearControlObserver.unsubscribe();
3682
3653
  };
3683
- }, []);
3654
+ }, [drawingManagerService, transformer]);
3655
+ if (!drawingParam || !transformer) return null;
3684
3656
  function handleChange(value) {
3685
3657
  setValue(value);
3686
3658
  const focusDrawings = drawingManagerService.getFocusDrawings();
@@ -3727,17 +3699,24 @@ const SheetDrawingAnchor = (props) => {
3727
3699
 
3728
3700
  //#endregion
3729
3701
  //#region src/views/sheet-image-panel/SheetDrawingPanel.tsx
3702
+ /**
3703
+ * Copyright 2023-present DreamNum Co., Ltd.
3704
+ *
3705
+ * Licensed under the Apache License, Version 2.0 (the "License");
3706
+ * you may not use this file except in compliance with the License.
3707
+ * You may obtain a copy of the License at
3708
+ *
3709
+ * http://www.apache.org/licenses/LICENSE-2.0
3710
+ *
3711
+ * Unless required by applicable law or agreed to in writing, software
3712
+ * distributed under the License is distributed on an "AS IS" BASIS,
3713
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3714
+ * See the License for the specific language governing permissions and
3715
+ * limitations under the License.
3716
+ */
3730
3717
  const SheetDrawingPanel = () => {
3731
3718
  const drawingManagerService = useDependency(IDrawingManagerService);
3732
- const [drawings, setDrawings] = useState(drawingManagerService.getFocusDrawings());
3733
- useEffect(() => {
3734
- const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
3735
- setDrawings(drawings);
3736
- });
3737
- return () => {
3738
- focusDispose.unsubscribe();
3739
- };
3740
- }, []);
3719
+ const drawings = useObservable(() => drawingManagerService.focus$, drawingManagerService.getFocusDrawings(), false, [drawingManagerService]);
3741
3720
  return !!(drawings === null || drawings === void 0 ? void 0 : drawings.length) && /* @__PURE__ */ jsxs("div", {
3742
3721
  className: "univer-text-sm",
3743
3722
  children: [/* @__PURE__ */ jsx(DrawingCommonPanel, { drawings }), /* @__PURE__ */ jsx(SheetDrawingAnchor, { drawings })]
@@ -17,4 +17,4 @@ import type { IDrawingParam } from '@univerjs/core';
17
17
  export interface ISheetDrawingAnchorProps {
18
18
  drawings: IDrawingParam[];
19
19
  }
20
- export declare const SheetDrawingAnchor: (props: ISheetDrawingAnchorProps) => import("react").JSX.Element | undefined;
20
+ export declare const SheetDrawingAnchor: (props: ISheetDrawingAnchorProps) => import("react").JSX.Element | null;
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/engine-render"),require("@univerjs/design"),require("@univerjs/docs-ui"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/drawing-ui"),require("rxjs"),require("@univerjs/docs-drawing"),require("react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-drawing`,`@univerjs/engine-render`,`@univerjs/design`,`@univerjs/docs-ui`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-ui`,`@univerjs/ui`,`@univerjs/drawing-ui`,`rxjs`,`@univerjs/docs-drawing`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawingUi={},e.UniverCore,e.UniverSheetsDrawing,e.UniverEngineRender,e.UniverDesign,e.UniverDocsUi,e.UniverDrawing,e.UniverSheets,e.UniverSheetsUi,e.UniverUi,e.UniverDrawingUi,e.rxjs,e.UniverDocsDrawing,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let h={id:`sheet.command.delete-drawing`,type:t.CommandType.COMMAND,handler:e=>{let r=e.get(t.ICommandService),i=e.get(n.ISheetDrawingService).getFocusDrawings();if(i.length===0)return!1;let a=i[0].unitId,o=i.map(e=>{let{unitId:t,subUnitId:n,drawingId:r,drawingType:i}=e;return{unitId:t,subUnitId:n,drawingId:r,drawingType:i}});return r.executeCommand(n.RemoveSheetDrawingCommand.id,{unitId:a,drawings:o})}};function g(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c}=i,l=(0,r.getGroupState)(0,0,a.map(e=>e.transform||{})),u=a.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,left:t.left,top:t.top},groupId:c}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,groupBaseBound:{...i.groupBaseBound},transform:l};n.push({parent:d,children:u})}),n}function _(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c,transform:l={width:0,height:0}}=i;if(l==null)return;let u=a.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:a,drawingId:o}=e;return{unitId:n,subUnitId:a,drawingId:o,transform:(0,r.transformObjectOutOfGroup)(t||{},l,l.width||0,l.height||0,i.groupBaseBound),groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:d,children:u})}),n}function v(e){var n;let r=new Map;(n=e.flatChildren)==null||n.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10))),e.groups.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10)));let i={};for(let[t,n]of Object.entries(e.nestedIdRecord)){var a,o;let e=(a=r.get(t))==null?t:a;i[e]={drawingId:e,children:(o=n.children)==null?void 0:o.map(e=>{var t;return(t=r.get(e))==null?e:t})}}let s=[],c=[];for(let t of e.groups){var l,u;let e=(l=r.get(t.drawingId))==null?t.drawingId:l,n=t.groupId?(u=r.get(t.groupId))==null?t.groupId:u:void 0;c.push(y(t,e,n))}for(let t of e.flatChildren||[]){var d,f;let e=(d=r.get(t.drawingId))==null?t.drawingId:d,n=t.groupId?(f=r.get(t.groupId))==null?t.groupId:f:void 0;s.push(y(t,e,n))}return{cloned:{nestedIdRecord:i,flatChildren:s,groups:c},idMap:r}}function y(e,t,n){let r={...e};return t&&(r.drawingId=t),n?r.groupId=n:delete r.groupId,JSON.parse(JSON.stringify(r))}let b={id:`sheet.command.group-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getGroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:_(f),type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}},x={id:`sheet.command.ungroup-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getUngroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:g(f),type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}};function S(e){"@babel/helpers - typeof";return S=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},S(e)}function C(e,t){if(S(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(S(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function w(e){var t=C(e,`string`);return S(t)==`symbol`?t:t+``}function T(e,t,n){return(t=w(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function E(e,t){return function(n,r){t(n,r,e)}}function D(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function O(e,t,n){let r=n*Math.PI/180;return{rotatedWidth:Math.abs(e*Math.cos(r))+Math.abs(t*Math.sin(r)),rotatedHeight:Math.abs(e*Math.sin(r))+Math.abs(t*Math.cos(r))}}function k(e,t,n,i,a){var o;let{rotatedHeight:s,rotatedWidth:l}=O(n,i,a),u=e.get(r.IRenderManagerService).getRenderById(t.unitId);if(!u)return!1;let d=(o=u.with(c.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:o.skeleton;if(d==null)return!1;let f=d.getCellByIndex(t.row,t.col),p=f.mergeInfo.endX-f.mergeInfo.startX-2,m=f.mergeInfo.endY-f.mergeInfo.startY-2,h=l/s,g=Math.ceil(Math.min(p,m*h))/l,_=!g||Number.isNaN(g)?.001:g;return{width:n*_,height:i*_}}let A=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){super(),this._context=e,this._commandService=t,this._sheetInterceptorService=n,this._selectionRenderService=r,this._imageIoService=i,this._fileOpenerService=a,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=c,this._messageService=l,this._localeService=u,this._sheetSkeletonService=f,this._injector=p,this._urlImageService=m,T(this,`_workbookSelections`,void 0),this._workbookSelections=d.getWorkbookSelections(this._context.unitId),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){let e=await this._fileOpenerService.openFile({multiple:!0,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}),t=e.length;return t>o.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxCount`,String(o.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(e.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){let e=(await this._fileOpenerService.openFile({multiple:!1,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){var r;let a;try{a=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/(1024*1024)))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(a==null)return;let{unitId:s,subUnitId:c}=this._getUnitInfo(),{imageId:l,imageSourceType:u,source:d,base64Cache:f}=a,{width:p,height:m,image:h}=await(0,o.getImageSize)(f||``),{width:g,height:_}=this._context.scene;this._imageIoService.addImageSourceCache(d,u,h);let v=1;if(p>o.DRAWING_IMAGE_WIDTH_LIMIT||m>o.DRAWING_IMAGE_HEIGHT_LIMIT){let e=o.DRAWING_IMAGE_WIDTH_LIMIT/p,t=o.DRAWING_IMAGE_HEIGHT_LIMIT/m;v=Math.max(e,t)}let y=this._sheetSkeletonService.getSkeletonParam(s,c);if(!y)return;let{skeleton:b}=y,x=this._getImagePosition(p*v,m*v,g,_,b);if(!x)return;let S=(0,n.drawingPositionToTransform)(x,y);if(!S)return;let C={unitId:s,subUnitId:c,drawingId:l,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:u,source:d,transform:S,sheetTransform:x,axisAlignSheetTransform:(r=(0,n.transformToAxisAlignPosition)(S,b))==null?x:r};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:s,drawings:[C]})}async _insertCellImage(e,n){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/(1024*1024)))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return!1;let{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``);this._imageIoService.addImageSourceCache(u,l,m);let h=this._workbookSelections.getCurrentLastSelection();if(!h)return!1;let g=h.primary.actualRow,_=h.primary.actualColumn;h.primary.isMerged&&(g=h.primary.startRow,_=h.primary.startColumn);let v=(0,t.createDocumentModelWithStyle)(``,{}),y=k(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:g,col:_},f,p,0);if(!y)return!1;let b={size:{width:y.width,height:y.height},positionH:{relativeFrom:t.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:t.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},x={unitId:v.getUnitId(),subUnitId:v.getUnitId(),drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:(0,a.docDrawingPositionToTransform)(b),docTransform:b,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=t.BuildTextUtils.drawing.add({documentDataModel:v,drawings:[x],selection:{collapsed:!0,startOffset:0,endOffset:0}});if(S){var C,w;return v.apply(S),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(C=n==null?void 0:n.row)==null?g:C]:{[(w=n==null?void 0:n.col)==null?_:w]:{p:v.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})}return!1}async insertCellImageByUrl(e,n){let r=e;try{r=await this._urlImageService.getImage(e)}catch(t){console.error(`Failed to get image from URLImageService: ${e}`,t)}let{width:i,height:c,image:l}=await(0,o.getImageSize)(r||``);this._imageIoService.addImageSourceCache(e,t.ImageSourceType.URL,l);let u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;let d=(0,t.createDocumentModelWithStyle)(``,{}),f=k(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},i,c,0);if(!f)return!1;let p={size:{width:f.width,height:f.height},positionH:{relativeFrom:t.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:t.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},m={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:(0,t.generateRandomId)(),drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t.ImageSourceType.URL,source:e,transform:(0,a.docDrawingPositionToTransform)(p),docTransform:p,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=t.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});if(h){var g,_;return d.apply(h),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(g=n==null?void 0:n.row)==null?u.primary.actualRow:g]:{[(_=n==null?void 0:n.col)==null?u.primary.actualColumn:_]:{p:d.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})}return!1}_getUnitInfo(){let e=this._context.unit,t=e.getActiveSheet();return{unitId:e.getUnitId(),subUnitId:t.getSheetId()}}_getImagePosition(e,t,n,r,i){let a=this._workbookSelections.getCurrentSelections(),o={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(o=a[a.length-1].range);let c=(0,s.attachRangeWithCoord)(i,o);if(c==null)return;let{startColumn:l,startRow:u,startX:d,startY:f}=c,p=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),p=!0),f+t>r&&(f=r-t,f<0&&(f=0,t=r),p=!0),p){let e=this._selectionRenderService.getCellWithCoordByOffset(d,f);if(e==null)return;d=e.startX,f=e.startY,l=e.actualColumn,u=e.actualRow}let m={column:l,columnOffset:0,row:u,rowOffset:0},h=this._selectionRenderService.getCellWithCoordByOffset(d+e,f+t);if(h!=null)return{from:m,to:{column:h.actualColumn,columnOffset:d+e-h.startX,row:h.actualRow,rowOffset:f+t-h.startY}}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{let{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a}=e;this._commandService.executeCommand(n.SetDrawingArrangeCommand.id,{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a})}))}_updateDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{let t=[];e.length!==0&&(e.forEach(e=>{let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeletonParam(r,i);if(!o||!s)return;let{skeleton:c}=s,l=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a});if(l==null||l.unitId!==this._context.unitId)return;let u=(0,n.transformToDrawingPosition)({...l.transform,...o},c),d=(0,n.transformToAxisAlignPosition)({...l.transform,...o},c);if(u==null||d==null)return;let f={...e,transform:{...l.transform,...o,...(0,n.drawingPositionToTransform)(u,s)},sheetTransform:{...u},axisAlignSheetTransform:{...d}};t.push(f)}),t.length>0&&this._commandService.executeCommand(n.SetSheetDrawingCommand.id,{unitId:e[0].unitId,drawings:t}))}))}_getSheetTransformByParam(e,t){let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeleton(r,i);if(!o||!s)return null;let c=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a}),l=c==null?void 0:c.transform;if(t&&(l={}),!t&&(!c||c.unitId!==this._context.unitId))return null;let u=(0,n.transformToDrawingPosition)({...l,...o},s),d=(0,n.transformToAxisAlignPosition)({...l,...o},s);return!u||!d?null:{sheetTransform:u,axisAlignSheetTransform:d}}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let e=n.parent,r=this._getSheetTransformByParam(e,!0),i=[];for(let e of n.children){let t=this._getSheetTransformByParam(e,!1);t!=null&&i.push({...e,sheetTransform:t.sheetTransform,axisAlignSheetTransform:t.axisAlignSheetTransform})}let a={parent:{...e,sheetTransform:r==null?void 0:r.sheetTransform,axisAlignSheetTransform:r==null?void 0:r.axisAlignSheetTransform},children:i};t.push(a)}if(t.length>0){this._commandService.executeCommand(b.id,t);let{unitId:n,subUnitId:r,drawingId:i}=e[0].parent;this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:r,drawingId:i}])}})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let{children:e}=n,r=[];for(let t of e){let e=this._getSheetTransformByParam(t,!1);e!=null&&r.push({...t,sheetTransform:e.sheetTransform,axisAlignSheetTransform:e.axisAlignSheetTransform})}t.push({...n,children:r})}this._commandService.executeCommand(x.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};A=D([E(1,t.ICommandService),E(2,(0,t.Inject)(s.SheetInterceptorService)),E(3,c.ISheetSelectionRenderService),E(4,t.IImageIoService),E(5,l.ILocalFileService),E(6,n.ISheetDrawingService),E(7,o.IDrawingManagerService),E(8,t.IContextService),E(9,l.IMessageService),E(10,(0,t.Inject)(t.LocaleService)),E(11,(0,t.Inject)(s.SheetsSelectionsService)),E(12,(0,t.Inject)(s.SheetSkeletonService)),E(13,(0,t.Inject)(t.Injector)),E(14,t.IURLImageService)],A);let j={id:`sheet.command.insert-float-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{var i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService),s=(i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(A);if(!s)return!1;let c=n==null?void 0:n.files;if(c){let e=c.map(e=>s.insertFloatImageByFile(e));return(await Promise.all(e)).every(e=>e)}else{var l;return(l=s.insertFloatImage())==null?!1:l}}},M={id:`sheet.command.insert-cell-image`,type:t.CommandType.COMMAND,handler:e=>{var n,i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService);return(n=(i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(A).insertCellImage())==null?!1:n}},N={id:`sheet.command.move-drawing`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(n.ISheetDrawingService),o=e.get(s.SheetSkeletonService),{direction:c}=r,l=a.getFocusDrawings();if(l.length===0)return!1;let u=l[0].unitId,d=l.map(e=>{let{transform:r,unitId:i,subUnitId:a}=e,s=o.getSkeleton(i,a);if(!r||!s)return null;let l={...r},{left:u=0,top:d=0}=r;return c===t.Direction.UP?l.top=d-1:c===t.Direction.DOWN?l.top=d+1:c===t.Direction.LEFT?l.left=u-1:c===t.Direction.RIGHT&&(l.left=u+1),{...e,transform:l,sheetTransform:(0,n.transformToDrawingPosition)(l,s),axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(l,s)}}).filter(e=>e!=null);return i.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:u,drawings:d})?(i.syncExecuteCommand(n.ClearSheetDrawingTransformerOperation.id,[u]),!0):!1}},P=function(e){return e.CELL_ADDRESS=`cellAddress`,e.COLUMN_VALUE=`columnValue`,e}({}),F=(0,t.createIdentifier)(`sheets-drawing-ui.batch-save-images.service`);function I(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function L(e,t){return`${I(t)}${e+1}`}function R(e){let t=L(e.startRow,e.startColumn),n=L(e.endRow,e.endColumn);return t===n?t:`${t}:${n}`}function z(e){var t,n;return!!(!(e==null||(t=e.p)==null||(t=t.drawingsOrder)==null)&&t.length&&(e==null||(n=e.p)==null||(n=n.drawingsOrder)==null?void 0:n.length)>0)}function B(e){var t,n;if(!(!((t=e.p)==null||(t=t.drawingsOrder)==null)&&t.length)||!((n=e.p)!=null&&n.drawings))return null;let r=e.p.drawingsOrder[0],i=e.p.drawings[r];return!i||!(`source`in i)||!(`imageSourceType`in i)?null:i}function V(e,n){if(n===t.ImageSourceType.BASE64){let t=e.match(/^data:image\/(\w+);/);if(t)return t[1]===`jpeg`?`jpg`:t[1]}if(n===t.ImageSourceType.URL){let t=e.match(/\.(\w+)(?:\?|$)/);if(t)return t[1].toLowerCase()}return`png`}async function H(e,n){if(n===t.ImageSourceType.BASE64||n===t.ImageSourceType.URL)return(await fetch(e)).blob();throw Error(`UUID image type requires additional handling`)}let U=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._selectionService=t,this._imageIoService=n,this._urlImageService=r}registerURLImageDownloader(e){return this._urlImageService.registerURLImageDownloader(e)}getCellImagesInSelection(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:o}=e.range;for(let e=t;e<=n;e++)for(let t=r;t<=o;t++){let n=i.getValue(e,t);if(z(n)){let r=B(n);r&&a.push({row:e,col:t,cellAddress:L(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return a}getCellImagesFromRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),s=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;for(let e=t;e<=n;e++)for(let t=r;t<=i;t++){let n=o.getValue(e,t);if(z(n)){let r=B(n);r&&s.push({row:e,col:t,cellAddress:L(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return s}getDataColumns(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=i.getDataRange(),o=1/0,s=-1/0,c=new Set;for(let e of r){o=Math.min(o,e.range.startRow),s=Math.max(s,e.range.endRow);for(let t=e.range.startColumn;t<=e.range.endColumn;t++)c.add(t)}let l=new Set;for(let e=a.startColumn;e<=a.endColumn;e++)if(!c.has(e))for(let t=o;t<=s;t++){let n=i.getValue(t,e);if(n){var u,d;if((u=n.v)!=null&&u.toString()||!((d=n.p)==null||(d=d.body)==null||(d=d.dataStream)==null)&&d.trim()){l.add(e);break}}}let f=[],p=Array.from(l).sort((e,t)=>e-t);for(let e of p)f.push({index:e,label:I(e)});return f}getDataColumnsForRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),s=o.getDataRange(),c=1/0,l=-1/0,u=new Set;for(let e of r){c=Math.min(c,e.startRow),l=Math.max(l,e.endRow);for(let t=e.startColumn;t<=e.endColumn;t++)u.add(t)}let d=new Set;for(let e=s.startColumn;e<=s.endColumn;e++)if(!u.has(e))for(let t=c;t<=l;t++){let n=o.getValue(t,e);if(n){var f,p;if((f=n.v)!=null&&f.toString()||!((p=n.p)==null||(p=p.body)==null||(p=p.dataStream)==null)&&p.trim()){d.add(e);break}}}let m=[],h=Array.from(d).sort((e,t)=>e-t);for(let e of h)m.push({index:e,label:I(e)});return m}getSelectionRangeNotation(){let e=this._selectionService.getCurrentSelections();return!e||e.length===0?``:e.map(e=>R(e.range)).join(`, `)}getSelectionRowRange(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return null;let t=1/0,n=-1/0;for(let r of e)t=Math.min(t,r.range.startRow),n=Math.max(n,r.range.endRow);return{startRow:t,endRow:n}}getSelectionColumnIndices(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return new Set;let t=new Set;for(let n of e)for(let e=n.range.startColumn;e<=n.range.endColumn;e++)t.add(e);return t}generateFileName(e,n){let r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),i=V(e.source,e.imageSourceType),a=[];for(let t of n.fileNameParts)if(t===`cellAddress`)a.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=r==null?void 0:r.getActiveSheet();if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var o,s;let e=((o=r.v)==null?void 0:o.toString())||((s=r.p)==null||(s=s.body)==null||(s=s.dataStream)==null?void 0:s.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&a.push(t)}}}}return a.length===0?`${e.cellAddress}.${i}`:`${a.join(`_`)}.${i}`}generateFileNameWithContext(e,n,r,i){let a=this._univerInstanceService.getUnit(r,t.UniverInstanceType.UNIVER_SHEET),o=V(e.source,e.imageSourceType),s=[];for(let t of n.fileNameParts)if(t===`cellAddress`)s.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=a==null?void 0:a.getSheetBySheetId(i);if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var c,l;let e=((c=r.v)==null?void 0:c.toString())||((l=r.p)==null||(l=l.body)==null||(l=l.dataStream)==null?void 0:l.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&s.push(t)}}}}return s.length===0?`${e.cellAddress}.${o}`:`${s.join(`_`)}.${o}`}async saveImages(e,t){let n=await window.showDirectoryPicker({mode:`readwrite`}),r=new Map;for(let a of e){var i;let e=this.generateFileName(a,t),o=e.replace(/\.\w+$/,``),s=((i=e.match(/\.\w+$/))==null?void 0:i[0])||`.png`,c=r.get(o)||0;c>0&&(e=`${o}_${c}${s}`),r.set(o,c+1);try{let t=await this._getImageBlob(a),r=await(await n.getFileHandle(e,{create:!0})).createWritable();await r.write(t),await r.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async saveImagesWithContext(e,t,n,r){let i=await window.showDirectoryPicker({mode:`readwrite`}),a=new Map;for(let s of e){var o;let e=this.generateFileNameWithContext(s,t,n,r),c=e.replace(/\.\w+$/,``),l=((o=e.match(/\.\w+$/))==null?void 0:o[0])||`.png`,u=a.get(c)||0;u>0&&(e=`${c}_${u}${l}`),a.set(c,u+1);try{let t=await this._getImageBlob(s),n=await(await i.getFileHandle(e,{create:!0})).createWritable();await n.write(t),await n.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async downloadSingleImage(e){let t=V(e.source,e.imageSourceType),n=`${e.cellAddress}.${t}`;try{let t=await this._getImageBlob(e),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}catch(e){throw console.error(`Failed to download image ${n}:`,e),e}}async _getImageBlob(e){return e.imageSourceType===t.ImageSourceType.UUID?H(await this._imageIoService.getImage(e.source),t.ImageSourceType.URL):e.imageSourceType===t.ImageSourceType.URL?this._urlImageService.downloadImage(e.source):H(e.source,e.imageSourceType)}};U=D([E(0,t.IUniverInstanceService),E(1,(0,t.Inject)(s.SheetsSelectionsService)),E(2,t.IImageIoService),E(3,t.IURLImageService)],U);let W=`sheet.dialog.batch-save-images`,G={id:`sheet.command.save-cell-images`,type:t.CommandType.COMMAND,handler:async e=>{let n=e.get(l.IDialogService),r=e.get(F),i=r.getCellImagesInSelection();if(i.length===1)try{return await r.downloadSingleImage(i[0]),!0}catch(e){return console.error(`Failed to download image:`,e),!1}let a=e.get(t.LocaleService),o=r.getSelectionRangeNotation(),s=`${a.t(`sheets-drawing-ui.save.title`)} (${o})`;return n.open({id:W,draggable:!0,width:360,title:{title:s},children:{label:W},destroyOnClose:!0,preservePositionOnDestroy:!0,onClose:()=>n.close(W)}),!0}},K=`COMPONENT_SHEET_DRAWING_PANEL`,q={id:`sidebar.operation.sheet-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{let r=e.get(l.ISidebarService),i=e.get(t.LocaleService),a=e.get(t.IUniverInstanceService),c=e.get(t.ICommandService);if(!(0,s.getSheetCommandTarget)(a))return!1;switch(n.value){case`open`:r.open({header:{title:i.t(`sheets-drawing-ui.panel.title`)},children:{label:K},onClose:()=>{c.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])},width:360});break;default:r.close();break}return!0}},J={id:`sheet.operation.edit-sheet-image`,type:t.CommandType.OPERATION,handler:(e,n)=>{let r=e.get(t.ICommandService);return n==null?!1:(r.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[n]),r.executeCommand(q.id,{value:`open`}),!0)}},Y=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],X=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._sheetDrawingService=r,this._drawingManagerService=i,T(this,`_featurePasteHooks`,[]),T(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:`SHEET_DRAWING_GROUP`,onBeforeCopy:(e,n)=>{this._copyInfo=null;let r=this._focusedDrawings;if(r.length===0)return;let i=r.find(e=>e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP);if(!i)return;let a=this._drawingManagerService.getDrawingsByGroupNested({unitId:i.unitId,subUnitId:i.subUnitId,drawingId:i.drawingId});a&&(this._copyInfo={unitId:i.unitId,subUnitId:i.subUnitId,groupNestedParam:a})},onPasteCells:(e,t,n,r)=>{if(!this._copyInfo)return{redos:[],undos:[]};let{pasteType:i}=r;return Y.includes(i)?{redos:[],undos:[]}:this._generateGroupPasteMutations(t)},onPasteUnrecognized:e=>this._copyInfo?this._generateGroupPasteMutations(e):{redos:[],undos:[]}})}registerFeaturePasteHook(e){this._featurePasteHooks.push(e)}_getGroupFeaturePasteMutations(e){let t=[],n=[];for(let r of this._featurePasteHooks){let i=r(e);t.push(...i.redos),n.push(...i.undos)}return{redos:t,undos:n}}_generateGroupPasteMutations(e){var t;if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:r,subUnitId:i,range:a}=e,o=this._sheetSkeletonService.getSkeleton(r,i);if(!o)return{redos:[],undos:[]};let{groupNestedParam:c}=this._copyInfo,l=c.groups[c.groups.length-1],{cloned:u,idMap:d}=v(c),f=u.groups[u.groups.length-1].drawingId,p=(0,s.discreteRangeToRange)(a),m=(0,s.attachRangeWithCoord)(o,{startRow:p.startRow,endRow:p.endRow,startColumn:p.startColumn,endColumn:p.endColumn});if(!m)return{redos:[],undos:[]};let h={...l.transform,left:m.startX,top:m.startY},g=[...((t=u.flatChildren)==null?[]:t).map(e=>({...e,unitId:r,subUnitId:i})),...u.groups.map(e=>{var t,a;return e.drawingId===f?{...e,unitId:r,subUnitId:i,transform:h,sheetTransform:(t=(0,n.transformToDrawingPosition)(h,o))==null?l.sheetTransform:t,axisAlignSheetTransform:(a=(0,n.transformToAxisAlignPosition)(h,o))==null?l.sheetTransform:a}:{...e,unitId:r,subUnitId:i}})],{undo:_,redo:y,objects:b}=this._sheetDrawingService.getBatchAddOp(g),x=[{id:n.SetDrawingApplyMutation.id,params:{op:y,unitId:r,subUnitId:i,objects:b,type:n.DrawingApplyType.INSERT}}],S=[{id:n.SetDrawingApplyMutation.id,params:{op:_,unitId:r,subUnitId:i,objects:b,type:n.DrawingApplyType.REMOVE}}],C=this._getGroupFeaturePasteMutations({fromUnitId:this._copyInfo.unitId,fromSubUnitId:this._copyInfo.subUnitId,toUnitId:r,toSubUnitId:i,idMap:d,cloned:u});return x.push(...C.redos),S.push(...C.undos),{redos:x,undos:S}}dispose(){this._copyInfo=null,this._featurePasteHooks.length=0,super.dispose()}};X=D([E(0,c.ISheetClipboardService),E(1,r.IRenderManagerService),E(2,(0,t.Inject)(s.SheetSkeletonService)),E(3,n.ISheetDrawingService),E(4,o.IDrawingManagerService)],X);let ee=Object.freeze({borderEnabled:!1,paintFirst:`stroke`,radius:8,rotateEnabled:!1,strokeWidth:1});var te;let ne=`univer-sheet-float-dom-`;function re(e,t,n){let r=new WeakRef(e),i=!1;return{id:t,dispose(){if(i)return;i=!0;let e=r.deref();e&&n(e,t)}}}let ie={borderEnabled:!0,borderStroke:`#4086f4`,borderStrokeWidth:1,borderSpacing:2,anchorFill:`#ffffff`,anchorStroke:`#4086f4`,anchorStrokeWidth:1.5,anchorSize:8,anchorCornerRadius:2,anchorStyle:`canva`,rotateEnabled:!1,resizeEnabled:!0,moveBoundaryEnabled:!1},ae={borderEnabled:!0,borderStroke:`#4086f4`,borderStrokeWidth:1,borderSpacing:2,anchorFill:`#ffffff`,anchorStroke:`#4086f4`,anchorStrokeWidth:1.5,anchorSize:8,anchorCornerRadius:2,anchorStyle:`canva`,rotateEnabled:!1,resizeEnabled:!0,keepRatio:!1,moveBoundaryEnabled:!1},oe=-100,se=`univer:embed-float-drag-handle:pointerdown`;function ce(e,t){return t.hostAnchorId===e.id&&(t.hostUnitId==null||t.hostUnitId===e.unitId)&&(t.button==null||t.button===0)&&typeof t.clientX==`number`&&typeof t.clientY==`number`}function le(e,t){var n,r;if(!(typeof t.clientX!=`number`||typeof t.clientY!=`number`))return{pointerId:t.pointerId,startClientX:t.clientX,startClientY:t.clientY,startLeft:Number((n=e.rect.left)==null?0:n),startTop:Number((r=e.rect.top)==null?0:r)}}function ue(e,t,n){let{scaleX:r,scaleY:i}=n.getAncestorScale();return{left:e.startLeft+(t.clientX-e.startClientX)/(r||1),top:e.startTop+(t.clientY-e.startClientY)/(i||1)}}function de(e,t){let n=t.data;if(!n||typeof n!=`object`)return;let r=n;r.version!==1||typeof r.embedId!=`string`||(e.transformerConfig={...ie,keepRatio:r.resizeBehavior===`aspect-ratio`})}function fe(e){e.transformerConfig={...e.transformerConfig,...ae}}function pe(e){if(!me(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType===t.UniverInstanceType.UNIVER_SHEET&&n.runtimeMountMode===`stage2`}function me(e){let t=e.data;if(!t||typeof t!=`object`)return!1;let n=t;return n.version===1&&typeof n.embedId==`string`}function he(e){if(!me(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType!=null}function ge(e,t=`inactive`){return{autoMountRuntime:!pe(e),passThroughRuntimeEvents:!(he(e)&&t===`stage2`),preserveOnFocusChange:me(e),usePreviewObject:pe(e)}}function _e(e){return ge(e).autoMountRuntime}function ve(e){return ge(e).preserveOnFocusChange}function ye(e){return ge(e).usePreviewObject}function be(e,t=`inactive`){return ge(e,t).passThroughRuntimeEvents}function xe(e){return me(e)&&!_e(e)}function Se(e,t){var n,r;if(!he(e))return!0;let i=t.target,a=i==null||(n=i.closest)==null?void 0:n.call(i,`[data-embed-float-dom="true"]`);return(a==null||(r=a.dataset)==null?void 0:r.embedFloatStage)!==`stage2`}function Ce(e){return e!==`stage2`}function we(e,t,n){if(t){if(e===`stage1`){var r,i;(r=(i=t.scene).attachTransformerTo)==null||r.call(i,n);return}if(e===`stage2`&&n.oKey){var a,o,s;t.transformer.clearControlByIds([n.oKey]),(a=(o=t.scene).getTransformer)==null||(a=a.call(o))==null||(s=a.clearSelectedObjects)==null||s.call(a)}}}function Te(e,t){return e.domLayers.some(([e])=>e===t)}function Ee(e){return e===t.DrawingTypeEnum.DRAWING_DOM||e===t.DrawingTypeEnum.DRAWING_BLOCK||e===t.DrawingTypeEnum.DRAWING_CHART}function De(e,t){if(e.runtimeMounted||e.runtimeStage!==`stage1`)return!1;let{offsetX:n,offsetY:r}=t;if(typeof n!=`number`||typeof r!=`number`)return!1;let i=e.position$.getValue();if(n>=Math.min(i.startX,i.endX)&&n<=Math.max(i.startX,i.endX)&&r>=Math.min(i.startY,i.endY)&&r<=Math.max(i.startY,i.endY))return!0;let a=e.rect;if(typeof a.isHit==`function`)try{return a.isHit({x:n,y:r})}catch{}return n>=a.left&&n<=a.left+a.width&&r>=a.top&&r<=a.top+a.height}function Oe(e,t){if(!(t.type!==`pointerdown`||!De(e,t)))return{pointerId:t.pointerId,startOffsetX:t.offsetX,startOffsetY:t.offsetY,startedAt:Date.now()}}function ke(e,t,n){return!t||n.type!==`pointerup`||t.pointerId!=null&&n.pointerId!=null&&t.pointerId!==n.pointerId||!De(e,n)?!1:Math.hypot(n.offsetX-t.startOffsetX,n.offsetY-t.startOffsetY)<=4}function Ae(e,n,i,a,o,s=!1){let{scaleX:c,scaleY:l}=n.getAncestorScale(),u=n.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN),{startColumn:d,startRow:f,xSplit:p,ySplit:m}=a.getFreeze(),h={left:!0,top:!0};if(!u)return{...e,absolute:h};let{left:g,right:_,top:v,bottom:y}=e,{top:b,left:x,viewportScrollX:S,viewportScrollY:C}=u,{boundsOfViewArea:w,scrollDirectionResponse:T}=o||{},{rowHeaderWidth:E,columnHeaderHeight:D}=i,O={top:s?0:D,left:s?0:E};w&&(t.Tools.isDefine(O.top)&&(O.top=w.top),t.Tools.isDefine(O.left)&&(O.left=w.left)),T===`HORIZONTAL`&&(C=0),T===`VERTICAL`&&(S=0);let k=0,A=0,j=i.rowStartY(f-m)+D,M=i.colStartX(d-p)+E,N=i.rowStartY(f)+D,P=i.colStartX(d)+E;if(p===0)h.left=!1,k=(g-S)*c,A=(_-S)*c;else{let e=g-(M-E),t=_-(M-E);_<P?(k=e*c,A=t*c):g<=P&&_>=P?(k=e*c,A=Math.max(x,(_-S)*c)):g>P&&(h.left=!1,k=Math.max((g-S)*c,x),A=Math.max((_-S)*c,x))}let F=0,I=0;if(m===0)h.top=!1,F=(v-C)*l,I=(y-C)*l;else{let e=v-(j-D),t=y-(j-D);y<N?(F=e*l,I=t*l):v<=N&&y>=N?(F=e*l,I=Math.max(b,(y-C)*l)):v>N&&(h.top=!1,F=Math.max((v-C)*l,b),I=Math.max((y-C)*l,b))}return k=Math.max(k,O.left),F=Math.max(F,O.top),A=Math.max(A,O.left),I=Math.max(I,O.top),{left:k,right:A,top:F,bottom:I,absolute:h}}let Z=(e,t,n,r,i)=>{let{left:a,top:o,width:s,height:c,angle:l}=e,u=Ae({left:a,right:a+s,top:o,bottom:o+c},t,n,r,i),{scaleX:d,scaleY:f}=t.getAncestorScale();return{startX:u.left,endX:u.right,startY:u.top,endY:u.bottom,rotate:l,width:s*d,height:c*f,absolute:u.absolute}},Q=te=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=r,this._canvasFloatDomService=i,this._sheetDrawingService=a,this._lifecycleService=o,this._canvasFloatDomPreviewService=s,T(this,`_domLayerInfoMap`,new Map),T(this,`_transformChange$`,new d.Subject),T(this,`transformChange$`,this._transformChange$.asObservable()),T(this,`_add$`,new d.Subject),T(this,`add$`,this._add$.asObservable()),T(this,`_remove$`,new d.Subject),T(this,`remove$`,this._remove$.asObservable()),T(this,`_renderObjectFactories`,new Map),this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent(),this._bindEmbedFloatDragHandleEvent()}registerRenderObjectFactory(e,t){var n;let r=(n=this._renderObjectFactories.get(e))==null?[]:n;return r.push(t),this._renderObjectFactories.set(e,r),{dispose:()=>{let n=this._renderObjectFactories.get(e);if(!n)return;let r=n.indexOf(t);r>=0&&n.splice(r,1),n.length===0&&this._renderObjectFactories.delete(e)}}}_createRenderObject(e){var t;let n=this._renderObjectFactories.get(e.drawingType),i=n==null?void 0:n[n.length-1];return(t=i==null?void 0:i(e))==null?new r.Rect(e.key,e.config):t}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe((0,d.filter)(e=>e===t.LifecycleStages.Rendered),(0,d.take)(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(e){return this._domLayerInfoMap.get(e)}getFloatDomsBySubUnitId(e,t){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===t&&n.unitId===e)}static _disposeExternalFloatDom(e,t){e._removeDom(t,!0)}_createFloatDomDisposable(e){return re(this,e,te._disposeExternalFloatDom)}_bindEmbedFloatDragHandleEvent(){if(typeof document>`u`)return;let e=e=>this._handleEmbedFloatDragHandlePointerDown(e);document.addEventListener(se,e),this.disposeWithMe(()=>document.removeEventListener(se,e))}_handleEmbedFloatDragHandlePointerDown(e){let t=e.detail;if(!(t!=null&&t.hostAnchorId))return;let n=this._domLayerInfoMap.get(t.hostAnchorId);if(!n||!ce(n,t))return;let r=le(n,t),i=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(!r||!i)return;let{scene:a,transformer:o}=i;if(n.rect.oKey){var s;o.clearControlByIds([n.rect.oKey]),(s=a.getTransformer())==null||s.clearSelectedObjects()}let c=e=>{if(r.pointerId!=null&&e.pointerId!==r.pointerId)return;e.preventDefault();let t=ue(r,e,a);n.rect.transformByState(t)},l=e=>{if(!(r.pointerId!=null&&e.pointerId!==r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),e.preventDefault(),(n.rect.left!==r.startLeft||n.rect.top!==r.startTop)&&this._commitFloatDomMove(n),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}},u=e=>{if(!(r.pointerId!=null&&e.pointerId!==r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),n.rect.transformByState({left:r.startLeft,top:r.startTop}),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}};window.addEventListener(`pointermove`,c,!0),window.addEventListener(`pointerup`,l,!0),window.addEventListener(`pointercancel`,u,!0)}_commitFloatDomMove(e){var t;let r=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(c.SheetSkeletonManagerService).getSkeletonParam(e.subUnitId),i=this._sheetDrawingService.getDrawingByParam({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.id});if(!r||!(i!=null&&i.transform))return;let a={...i.transform,left:e.rect.left,top:e.rect.top,width:e.rect.width,height:e.rect.height,angle:e.rect.angle,flipX:e.rect.flipX,flipY:e.rect.flipY,skewX:e.rect.skewX,skewY:e.rect.skewY},o=(0,n.transformToDrawingPosition)(a,r.skeleton),s=(0,n.transformToAxisAlignPosition)(a,r.skeleton);!o||!s||this._commandService.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:e.unitId,drawings:[{...i,transform:a,sheetTransform:o,axisAlignSheetTransform:s}]})}isFloatDomRuntimeMounted(e){var t;return((t=this._domLayerInfoMap.get(e))==null?void 0:t.runtimeMounted)===!0}_getFloatDomPreviewObjectKey(e){return`${e}__preview`}_syncPreviewObjectTransform(e,t){e==null||e.transformByState({left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY})}_requestFloatDomPreview(e,t,n){this._canvasFloatDomPreviewService&&this._canvasFloatDomPreviewService.requestPreview({id:e,width:t.width,height:t.height,data:n})}_upsertFloatDomPreviewObject(e,t,n,i,a){var o;let s=(o=this._canvasFloatDomPreviewService)==null?void 0:o.getPreview(i);if(!(s!=null&&s.image)){this._requestFloatDomPreview(i,t,a);return}let c=this._getFloatDomPreviewObjectKey(n),l=e.getObject(c);if(l instanceof r.Image)return l.changeSource(s.image),this._syncPreviewObjectTransform(l,t),l;let u=new r.Image(c,{left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY,url:s.image,evented:!1,rotateEnabled:!1,resizeEnabled:!1});return e.addObject(u,r.DRAWING_OBJECT_LAYER_INDEX),u}mountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);return t!=null&&t.floatDomConfig?t.runtimeMounted?!0:(Te(this._canvasFloatDomService,e)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}):this._canvasFloatDomService.addFloatDom({...t.floatDomConfig,eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}),t.runtimeMounted=!0,t.runtimeStage=`stage2`,!0):!1}unmountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);t!=null&&t.runtimeMounted&&(t.floatDomConfig&&!_e(t.floatDomConfig)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`inactive`),props:t.floatDomConfig.props}):this._canvasFloatDomService.removeFloatDom(e),t.runtimeMounted=!1,t.runtimeStage=`inactive`)}_syncFloatDomVisibilityForActiveSheet(e,t){Array.from(this._domLayerInfoMap.values()).filter(t=>t.unitId===e&&t.floatDomConfig).forEach(e=>{let n=e.subUnitId===t,r=Te(this._canvasFloatDomService,e.id);if(!n){r&&this._canvasFloatDomService.removeFloatDom(e.id),e.runtimeMounted=!1,e.runtimeStage=`inactive`;return}if(r||!e.floatDomConfig)return;this._canvasFloatDomService.addFloatDom(e.floatDomConfig);let i=_e(e.floatDomConfig);e.runtimeMounted=i,e.runtimeStage=me(e.floatDomConfig)?`inactive`:i?`stage2`:`inactive`})}promoteFloatDomRuntimeStage(e){let t=this._domLayerInfoMap.get(e);if(!(t!=null&&t.floatDomConfig))return;let n=he(t.floatDomConfig);return t.runtimeMounted&&!n?(t.runtimeStage=`stage2`,`stage2`):t.runtimeStage===`stage1`?t.runtimeMounted?(t.runtimeStage=`stage2`,xe(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`stage2`)}),`stage2`):(this.mountFloatDomRuntime(e),`stage2`):(t.runtimeStage=`stage1`,xe(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`stage1`)}),`stage1`)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return t==null||n==null?null:{scene:n,transformer:n.getTransformerByCreate(),renderUnit:t,canvas:t.engine.getCanvasElement()}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(e=>{var n;let{unitId:i,subUnitId:a,drawingId:l}=e,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:i,subUnitId:a}),p=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(n=this._renderManagerService.getRenderById(i))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!g)return;let{transform:_,drawingType:v,data:y,hidden:b,groupId:x}=p;if(!Ee(v))return;let S=this._getSceneAndTransformerByDrawingSearch(i);if(S==null||b)return;let{scene:C,canvas:w}=S;if(_==null)return!0;if(h!==a)return;let{left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}=_,P=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:l}),F=x?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:x}):void 0,I=this._getObjectIncludingGroup(C,P,F);if(I!=null&&(this._removeTopLevelDuplicateIfGrouped(C,P,I),de(I,p),v===t.DrawingTypeEnum.DRAWING_CHART&&fe(I),I.transformByState({left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}),this._syncFloatDomRect(l,I),ye(p)&&(this._syncPreviewObjectTransform(C.getObject(this._getFloatDomPreviewObjectKey(P)),I),this._requestFloatDomPreview(l,I,y)),this._domLayerInfoMap.has(l)))return;let L={left:T,top:E,width:D,height:O,zIndex:this._drawingManagerService.getDrawingOrder(i,a).length-1},R=v===t.DrawingTypeEnum.DRAWING_CHART;if(R){let e=this._getChartDataBackground(y);e!==void 0&&(L.fill=e),y&&y.border&&(L.stroke=y.border),Object.assign(L,ee)}else L.rotateEnabled=!1;let z=I==null?this._createRenderObject({key:P,config:L,unitId:i,subUnitId:a,drawingId:l,drawingType:v,data:y}):I;de(z,p),R&&fe(z),R?z.objectType=r.ObjectType.CHART:(v===t.DrawingTypeEnum.DRAWING_DOM||v===t.DrawingTypeEnum.DRAWING_BLOCK)&&(z.objectType=r.ObjectType.DRAWING_DOM),I||C.addObject(z,r.DRAWING_OBJECT_LAYER_INDEX),!I&&p.allowTransform!==!1&&C.attachTransformerTo(z),!I&&R&&x&&(0,u.insertGroupObject)({drawingId:x,unitId:i,subUnitId:a},z,C,this._drawingManagerService);let B=new t.DisposableCollection,V=ye(p),H=V?this._getFloatDomPreviewObjectKey(P):void 0;if(V){var U;this._upsertFloatDomPreviewObject(C,z,P,l,y);let e=(U=this._canvasFloatDomPreviewService)==null?void 0:U.previewUpdated$.subscribe(e=>{e.id===l&&this._upsertFloatDomPreviewObject(C,z,P,l,y)});e&&B.add(e)}let W=new d.BehaviorSubject(Z(z,S.renderUnit.scene,g.skeleton,f.worksheet)),G=`${ne}${(0,t.generateRandomId)(6)}`,K=_e(p),q=me(p),J,Y={position$:W,id:l,domId:G,componentKey:p.componentKey,eventPassThrough:be(p,`inactive`),preserveOnFocusChange:ve(p),onPointerDown:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onWheel:e=>{Se(p,e)&&w.dispatchEvent(new WheelEvent(e.type,e))},data:y,props:q?{onRuntimeStageEnter:e=>{J&&(J.runtimeStage=e,J.runtimeMounted=K||e===`stage2`,xe(p)&&this._canvasFloatDomService.updateFloatDom(l,{eventPassThrough:be(p,e)})),we(e,this._getSceneAndTransformerByDrawingSearch(i),z)}}:void 0,unitId:i};if(J={dispose:B,rect:z,position$:W,unitId:i,subUnitId:a,id:l,domId:G,floatDomConfig:Y,runtimeMounted:K,runtimeStage:q?`inactive`:K?`stage2`:`inactive`,previewObjectKey:H},this._canvasFloatDomService.addFloatDom(Y),!K){let e,t=t=>{if(e&&!(e.pointerId!=null&&t.pointerId!=null&&e.pointerId!==t.pointerId)){if(typeof t.offsetX!=`number`||typeof t.offsetY!=`number`){e=void 0;return}Math.hypot(t.offsetX-e.startOffsetX,t.offsetY-e.startOffsetY)>4&&(e=void 0)}},n=z.onPointerDown$.subscribeEvent({priority:oe,next:([t,n])=>{if((J==null?void 0:J.runtimeStage)===`stage1`){e=Oe(J,t);return}let r=this.promoteFloatDomRuntimeStage(l);r===`stage2`&&(we(r,S,z),n.skipNextObservers=!0),Ce(r)||n.stopPropagation()}}),r=C.onPointerDown$.subscribeEvent({priority:oe,next:([t])=>{J&&(e=Oe(J,t))}}),i=C.onPointerMove$.subscribeEvent({priority:oe,next:([e])=>{t(e)}}),a=C.onPointerUp$.subscribeEvent({priority:oe,next:([t,n])=>{let r=J&&ke(J,e,t);if(e=void 0,!r)return;let i=this.promoteFloatDomRuntimeStage(l);i===`stage2`&&(we(i,S,z),n.stopPropagation(),n.skipNextObservers=!0)}});B.add(n),B.add(r),B.add(i),B.add(a)}let X=z.onTransformChange$.subscribeEvent(()=>{let e=Z(z,S.renderUnit.scene,g.skeleton,f.worksheet);W.next(e),H&&this._syncPreviewObjectTransform(C.getObject(H),z)});B.add(()=>{this._canvasFloatDomService.removeFloatDom(l),H&&C.removeObject(H)}),X&&B.add(X),this._domLayerInfoMap.set(l,J)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{transformer:s,scene:c}=a,l=this._getObjectIncludingGroup(c,i);if(l!=null&&l.oKey){var u;s.clearControlByIds([l==null?void 0:l.oKey]),(u=c.getTransformer())==null||u.clearSelectedObjects()}})}))}_scrollUpdateListener(){let e=(e,t)=>{var n;let r=this._getSceneAndTransformerByDrawingSearch(e),i=Array.from(this._domLayerInfoMap.keys()).map(e=>({id:e,...this._domLayerInfoMap.get(e)})).filter(n=>n.subUnitId===t&&n.unitId===e).map(e=>e.id),a=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:t}),o=(n=this._renderManagerService.getRenderById(e))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(t);!r||!a||!o||i.forEach(e=>{let t=this._domLayerInfoMap.get(e);if(t){let e=Z(t.rect,r.renderUnit.scene,o.skeleton,a.worksheet,t);t.position$.next(e)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?e.activeSheet$:(0,d.of)(null))).subscribe(t=>{if(!t)return;let n=t.getUnitId(),r=t.getSheetId();this._syncFloatDomVisibilityForActiveSheet(n,r),e(n,r)})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?e.activeSheet$:(0,d.of)(null)),(0,d.map)(e=>{if(!e)return null;let t=e.getUnitId(),n=this._renderManagerService.getRenderById(t);return n?{render:n,unitId:t,subUnitId:e.getSheetId()}:null}),(0,d.switchMap)(e=>e?(0,t.fromEventSubject)(e.render.scene.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe((0,d.map)(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):(0,d.of)(null))).subscribe(t=>{if(!t)return;let{unitId:n,subUnitId:r}=t;e(n,r)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===c.SetZoomRatioOperation.id){let{unitId:n}=t.params;Array.from(this._domLayerInfoMap.values()).filter(e=>e.unitId===n).map(e=>e.subUnitId).forEach(t=>{e(n,t)})}else if(t.id===s.SetFrozenMutation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}else if(t.id===s.SetSelectionsOperation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}}))}updateFloatDomProps(e,t,n,i){let a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(e);if(a&&s){let{scene:a}=s,c=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),l=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),u=l!=null&&l.groupId?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:l.groupId}):void 0,d=this._getObjectIncludingGroup(a,c,u);d&&d instanceof r.Rect&&(this._removeTopLevelDuplicateIfGrouped(a,c,d),d.setProps(i),this._syncFloatDomRect(n,d))}}_getObjectIncludingGroup(e,t,n){var r,i,a,o;return(r=(i=(a=this._getChildObjectFromGroup(e,t,n))==null?(o=e.getObjectIncludeInGroup)==null?void 0:o.call(e,t):a)==null?e.getObject(t):i)==null?null:r}_getChildObjectFromGroup(e,t,n){var r,i;if(!n)return null;let a=(r=(i=e.getObjectIncludeInGroup)==null?void 0:i.call(e,n))==null?e.getObject(n):r;return this._findChildObject(a,t)}_findChildObject(e,t){if(!e)return null;let n=e.getObjects();for(let e of n){if(e.oKey===t)return e;let n=this._findChildObject(e,t);if(n)return n}return null}_removeTopLevelDuplicateIfGrouped(e,t,n){if(!n.isInGroup)return;let r=e.getObject(t);r&&r!==n&&e.removeObject(r)}_syncFloatDomRect(e,t){if(!(t instanceof r.Rect))return;let n=this._domLayerInfoMap.get(e);n&&(n.rect=t)}_getChartDataBackground(e){var t;if(!e||typeof e!=`object`||Array.isArray(e))return;let n=e,r=(t=n.backgroundColor)==null?n.background:t;return typeof r==`string`?r:void 0}_getPosition(e,t){var n;let{startX:r,endX:i,startY:a,endY:o}=e,s=(n=this._renderManagerService.getRenderById(t))==null?void 0:n.with(c.ISheetSelectionRenderService);if(s==null)return;let l=s.getCellWithCoordByOffset(r,a);if(l==null)return;let u={column:l.actualColumn,columnOffset:r-l.startX,row:l.actualRow,rowOffset:a-l.startY},d=s.getCellWithCoordByOffset(i,o);if(d!=null)return{from:u,to:{column:d.actualColumn,columnOffset:i-d.startX,row:d.actualRow,rowOffset:o-d.startY}}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let n=this._drawingManagerService.getDrawingByParam(e);if(!n||!Ee(n.drawingType))return;if(n.hidden){this._removeDom(e.drawingId);return}if(!this._domLayerInfoMap.has(e.drawingId)){this._drawingManagerService.addNotification([e]);return}let r={...n.transform};this._transformChange$.next({id:e.drawingId,value:r}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});let i=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(i&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART){let{scene:t}=i,r=this._domLayerInfoMap.get(e.drawingId);r!=null&&r.rect&&(n.allowTransform===!1?t.detachTransformerFrom(r.rect):t.attachTransformerTo(r.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(e,r){let i=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!i)throw Error(`cannot find current target!`);let{unitId:a,subUnitId:o}=i,{initPosition:c,componentKey:l,data:u,allowTransform:d=!0}=e,f=r==null?(0,t.generateRandomId)():r,p=this._getPosition(c,a);if(p==null)return;let m={unitId:a,subUnitId:o,drawingId:f,drawingType:e.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},axisAlignSheetTransform:p,data:u,allowTransform:d};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[m]}),this._add$.next({unitId:a,subUnitId:o,id:f}),this._createFloatDomDisposable(f)}_removeDom(e,t=!1){let r=this._domLayerInfoMap.get(e);if(!r)return;let{unitId:i,subUnitId:a}=r;this._domLayerInfoMap.delete(e),r.dispose.dispose();let o=this._getSceneAndTransformerByDrawingSearch(i);if(o){let{scene:t,transformer:n}=o;if((0,u.disposeDrawingRenderObject)(t,{unitId:i,subUnitId:a,drawingId:e})){var s;n.clearControlByIds([r.rect.oKey]),(s=t.getTransformer())==null||s.clearSelectedObjects()}}if(t){let t=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:e});if(!t)return;let{redo:r,objects:o}=this._sheetDrawingService.getBatchRemoveOp([t]);this._commandService.syncExecuteCommand(n.SetDrawingApplyMutation.id,{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE})}}removeFloatDom(e,t=!0){this._removeDom(e,t)}addFloatDomToRange(e,n,i,a){var l;let f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!f)throw Error(`cannot find current target!`);let{unitId:p,subUnitId:m}=f,h=this._getSceneAndTransformerByDrawingSearch(p);if(!h)return;let g=this._renderManagerService.getRenderById(p);if(!g)return;let _=(l=this._renderManagerService.getRenderById(p))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(m);if(!_)return;let{componentKey:v,data:y,allowTransform:b=!0}=n,x=a==null?(0,t.generateRandomId)():a,{position:S,position$:C}=this._createRangePositionObserver(e,g,_.skeleton),w=this._getPosition(S,p);if(w==null)return;let{scaleX:T}=h.scene.getAncestorScale(),E=Me(S,i,T),D={unitId:p,subUnitId:m,drawingId:x,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:v,sheetTransform:w,axisAlignSheetTransform:w,transform:{left:E.startX,top:E.startY,width:E.width,height:E.height},data:y,allowTransform:b};{var O,k;let{unitId:e,subUnitId:a,drawingId:l}=D,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),p=D,m=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(O=this._renderManagerService.getRenderById(e))==null?void 0:O.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,drawingType:y,data:b,groupId:w}=p;if(!Ee(y))return;let T=this._getSceneAndTransformerByDrawingSearch(e);if(T==null)return;let{scene:E,canvas:A}=T;if(v==null||h!==a)return;let{left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:R,skewY:z}=v,B=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),V=w?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:w}):void 0,H=this._getObjectIncludingGroup(E,B,V);if(H!=null){this._removeTopLevelDuplicateIfGrouped(E,B,H),y===t.DrawingTypeEnum.DRAWING_CHART&&fe(H),H.transformByState({left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:R,skewY:z}),this._syncFloatDomRect(l,H);return}let U={left:j,top:M,width:N,height:P,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1},W=y===t.DrawingTypeEnum.DRAWING_CHART;if(W){let e=this._getChartDataBackground(b);e!==void 0&&(U.fill=e),U.rotateEnabled=!1,b&&b.border&&(U.stroke=b.border),U.paintFirst=`stroke`,U.strokeWidth=1,U.radius=8}let G=this._createRenderObject({key:B,config:U,unitId:e,subUnitId:a,drawingId:l,drawingType:y,data:b});W&&(G.setObjectType(r.ObjectType.CHART),fe(G)),E.addObject(G,r.DRAWING_OBJECT_LAYER_INDEX),p.allowTransform!==!1&&E.attachTransformerTo(G),W&&w&&(0,u.insertGroupObject)({drawingId:w,unitId:e,subUnitId:a},G,E,this._drawingManagerService);let K=new t.DisposableCollection,q=E.getMainViewport(),{rowHeaderWidth:J,columnHeaderHeight:Y}=_.skeleton,X={dispose:K,rect:G,boundsOfViewArea:{top:Y,left:J,bottom:q.bottom,right:q.right},domAnchor:i,unitId:e,subUnitId:a,id:l},ee=new d.BehaviorSubject(Z(G,T.renderUnit.scene,_.skeleton,f.worksheet,X));X.position$=ee;let te={position$:ee,id:l,componentKey:p.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{A.dispatchEvent(new WheelEvent(e.type,e))},data:b,unitId:e};n.eventPassThrough&&(te={...te,onPointerDown:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{A.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(te),this.disposeWithMe(C.subscribe(t=>{var n,s,c,u;let d=Me({rotate:0,startX:t.startX,startY:t.startY,endX:t.endX,endY:t.endY,width:(n=i.width)==null?t.width:n,height:(s=i.height)==null?t.height:s,absolute:{left:S.absolute.left,top:S.absolute.top}},i),p=Z(new r.Rect((0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),{left:d.startX,top:d.startY,width:(c=i.width)==null?t.width:c,height:(u=i.height)==null?t.height:u,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),T.renderUnit.scene,_.skeleton,f.worksheet,X);ee.next(p)}));let ne=(k=this._renderManagerService.getRenderById(e))==null?void 0:k.with(c.SheetSkeletonManagerService),re=ne==null?void 0:ne.currentSkeleton$.subscribe(e=>{e&&_.sheetId!==e.sheetId&&this._removeDom(x,!0)});re&&K.add(re);let ie=G.onTransformChange$.subscribeEvent(()=>{let e=Z(G,T.renderUnit.scene,_.skeleton,f.worksheet,X);ee.next(e)});K.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),ie&&K.add(ie),this._domLayerInfoMap.set(l,X)}return this._createFloatDomDisposable(x)}addFloatDomToColumnHeader(e,n,i,a){var l;let u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!u)throw Error(`cannot find current target!`);let{unitId:f,subUnitId:p}=u;if(!this._getSceneAndTransformerByDrawingSearch(f))return;let m=this._renderManagerService.getRenderById(f);if(!m)return;let h=(l=this._renderManagerService.getRenderById(f))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(p);if(!h)return;let{componentKey:g,data:_,allowTransform:v=!0}=n,y=a==null?(0,t.generateRandomId)():a,{position:b,position$:x}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},m,h.skeleton),S=b;S.startY=0;let C=this._getPosition(b,f);if(C==null)return;let w={unitId:f,subUnitId:p,drawingId:y,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:C,axisAlignSheetTransform:C,transform:{left:S.startX,top:S.startY,width:S.width,height:S.height},data:_,allowTransform:v};{var T,E;let{unitId:e,subUnitId:a,drawingId:l}=w,u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),f=w,p=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!p)return;let m=p.getActiveSheet().getSheetId();if(!f||!u)return;let g=(T=this._renderManagerService.getRenderById(e))==null?void 0:T.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,data:C}=f,D=this._getSceneAndTransformerByDrawingSearch(e);if(D==null)return;let{scene:O,canvas:k}=D;if(v==null||m!==a)return;let{left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:R}=v,z=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),B=this._getObjectIncludingGroup(O,z);if(B!=null){this._removeTopLevelDuplicateIfGrouped(O,z,B),B.transformByState({left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:R}),this._syncFloatDomRect(l,B);return}let V=Me({rotate:0,startX:S.startX,startY:0,endX:b.endX,endY:b.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),H=new r.Rect(z,{left:V.startX,top:V.startY,width:V.width,height:V.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1});O.addObject(H,r.DRAWING_OBJECT_LAYER_INDEX),f.allowTransform!==!1&&O.attachTransformerTo(H);let U=new t.DisposableCollection,W=O.getMainViewport(),G={dispose:U,rect:H,unitId:e,subUnitId:a,id:l,boundsOfViewArea:{top:0,left:W.left,bottom:W.bottom,right:W.right},domAnchor:i,scrollDirectionResponse:`HORIZONTAL`},K=new d.BehaviorSubject(Z(H,D.renderUnit.scene,_.skeleton,u.worksheet,G));G.position$=K;let q={position$:K,id:l,componentKey:f.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{k.dispatchEvent(new WheelEvent(e.type,e))},data:C,unitId:e};n.eventPassThrough&&(q={...q,onPointerDown:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{k.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(q);let J=H.onTransformChange$.subscribeEvent(()=>{let e=Z(H,D.renderUnit.scene,_.skeleton,u.worksheet,G);K.next(e)});this.disposeWithMe(x.subscribe(t=>{let n=Me({rotate:0,startX:t.startX,startY:0,endX:t.endX,endY:t.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),s=Z(new r.Rect((0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),{left:n.startX,top:0,width:i.width,height:i.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),D.renderUnit.scene,_.skeleton,u.worksheet,G);K.next(s)}));let Y=(E=this._renderManagerService.getRenderById(e))==null?void 0:E.with(c.SheetSkeletonManagerService);Y==null||Y.currentSkeleton$.subscribe(e=>{e&&h.sheetId!==e.sheetId&&this._removeDom(y,!0)}),U.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),J&&U.add(J),this._domLayerInfoMap.set(l,G)}return this._createFloatDomDisposable(y)}_createRangePositionObserver(e,n,r){let{startRow:i,startColumn:a}=e,o=je(i,a,r),l=new d.BehaviorSubject(o),u=je(e.endRow,e.endColumn,r),f=new d.BehaviorSubject(u),p=()=>{let t=je(i,a,r),n=je(e.endRow,e.endColumn,r);l.next(t),f.next(n)},m=new t.DisposableCollection;return m.add(n.engine.clientRect$.subscribe({next:()=>p(),error:()=>{}})),m.add(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetRowAutoHeightMutation.id&&e.params.rowsAutoHeightInfo.findIndex(e=>e.row===i)>-1){p();return}(s.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(e.id)>-1||e.id===c.SetScrollOperation.id||e.id===c.SetZoomRatioOperation.id)&&p()})),{position$:l.pipe((0,d.map)(t=>{let n=je(e.endRow,e.endColumn,r);return{rotate:0,width:n.right-t.left,height:n.bottom-t.top,absolute:{left:!0,top:!0},startX:t.left,startY:t.top,endX:n.right,endY:n.bottom}})),position:{rotate:0,width:u.right-o.left,height:u.bottom-o.top,absolute:{left:!0,top:!0},startX:o.left,startY:o.top,endX:u.right,endY:u.bottom},updateRowCol:(e,t)=>{i=e,a=t,p()},topLeftPos$:l,rightBottomPos$:f,disposable:m}}};Q=te=D([E(0,(0,t.Inject)(r.IRenderManagerService)),E(1,t.IUniverInstanceService),E(2,(0,t.Inject)(t.ICommandService)),E(3,o.IDrawingManagerService),E(4,(0,t.Inject)(l.CanvasFloatDomService)),E(5,n.ISheetDrawingService),E(6,(0,t.Inject)(t.LifecycleService)),E(7,(0,t.Optional)(l.CanvasFloatDomPreviewService))],Q);function je(e,t,n){let r=n.getCellWithCoordByIndex(e,t),i=r.isMergedMainCell?r.mergeInfo:r;return{left:i.startX,right:i.endX,top:i.startY,bottom:i.endY}}function Me(e,t,n){var r,i,a;n=(r=n)==null?1:r;let o=e.endX-e.startX,s=e.endY-e.startY,c=(i=t==null?void 0:t.width)==null?o:i,l=(a=t==null?void 0:t.height)==null?s:a,u=0,d=0;if(t){if(t.horizonOffsetAlign===`right`){let r=Ne(t.marginX,o*n);u=e.endX-r-c}else u=e.startX+Ne(t.marginX,o);if(t.verticalOffsetAlign===`bottom`){let r=Ne(t.marginY,s*n);d=e.endY-r-l}else d=e.startY+Ne(t.marginY,s)}return{rotate:0,startX:u,startY:d,endX:e.endX,endY:e.endY,width:c,height:l,absolute:{left:e.absolute.left,top:e.absolute.top}}}function Ne(e,t){return e===void 0?0:typeof e==`number`?e:t*Number.parseFloat(e)/100}let Pe=[[Q]];function Fe(e){e.has(Q)||(0,t.registerDependencies)(e,Pe),Le(e)}function Ie(e){(0,t.touchDependencies)(e,[[Q]])}function Le(e){if(!e.has(t.LifecycleService)){Ie(e);return}let n=e.get(t.LifecycleService);if(n.stage>=t.LifecycleStages.Ready){Ie(e);return}n.onStage(t.LifecycleStages.Ready).then(()=>{Ie(e)})}let Re=`sheet.menu.image`;function ze(e){return{id:Re,type:l.MenuItemType.SUBITEMS,icon:`AddImageIcon`,tooltip:`sheets-drawing-ui.title`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission],rangeTypes:[s.RangeProtectionPermissionEditPoint]})}}function Be(e){return{id:j.id,title:`sheets-drawing-ui.upload.float`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function Ve(e){return{id:M.id,title:`sheets-drawing-ui.upload.cell`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function He(e){var t,n;return!!(!(e==null||(t=e.p)==null||(t=t.drawingsOrder)==null)&&t.length&&(e==null||(n=e.p)==null||(n=n.drawingsOrder)==null?void 0:n.length)>0)}function Ue(e,t){let n=e.getActiveSheet();if(!n)return!1;let r=n.getCellMatrix(),{startRow:i,endRow:a,startColumn:o,endColumn:s}=t;for(let e=i;e<=a;e++)for(let t=o;t<=s;t++)if(He(r.getValue(e,t)))return!0;return!1}function We(){return`showDirectoryPicker`in window}function Ge(e){let n=e.get(t.IUniverInstanceService),r=e.get(s.SheetsSelectionsService),i=(0,d.combineLatest)([(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),n.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?r.selectionMoveEnd$.pipe((0,d.map)(()=>{if(!We())return!0;let t=r.getCurrentSelections();if(!t||t.length===0)return!0;for(let n of t)if(Ue(e,n.range))return!1;return!0})):(0,d.of)(!0)))]).pipe((0,d.map)(([e,t])=>e||t));return{id:G.id,type:l.MenuItemType.BUTTON,icon:`DownloadImageIcon`,title:`sheets-drawing-ui.save.menuLabel`,hidden$:i}}let Ke={[l.RibbonInsertGroup.MEDIA]:{[Re]:{order:0,menuItemFactory:ze,[j.id]:{order:0,menuItemFactory:Be},[M.id]:{order:1,menuItemFactory:Ve}}},[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{[G.id]:{order:10,menuItemFactory:Ge}}},[l.ContextMenuPosition.COL_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[G.id]:{order:10,menuItemFactory:Ge}}},[l.ContextMenuPosition.ROW_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[G.id]:{order:10,menuItemFactory:Ge}}}};var qe=`@univerjs/sheets-drawing-ui`,Je=`1.0.0-alpha.3`;let Ye={};function Xe(){let e=(0,l.useDependency)(t.LocaleService),n=(0,l.useDependency)(l.IDialogService),r=(0,l.useDependency)(F),[a,o]=(0,p.useState)([`cellAddress`]),[s,u]=(0,p.useState)(!1),[d,f]=(0,p.useState)(null),h=(0,p.useMemo)(()=>r.getCellImagesInSelection(),[r]),g=(0,p.useMemo)(()=>r.getDataColumns(),[r]),_=(0,p.useMemo)(()=>r.getSelectionRowRange(),[r]),v=g.length>0,y=(0,p.useMemo)(()=>g.map(e=>({label:e.label,value:String(e.index)})),[g]),[b,x]=(0,p.useState)(()=>y.length>0?y[0].value:`0`);(0,c.useHighlightRange)((0,p.useMemo)(()=>{if(!a.includes(`columnValue`)||!_)return[];let e=Number(b);return[{startRow:_.startRow,endRow:_.endRow,startColumn:e,endColumn:e}]},[a,b,_]));let S=(0,p.useCallback)(e=>{e.length!==0&&o(e)},[]),C=(0,p.useCallback)(e=>{x(String(e))},[]),w=(0,p.useCallback)(()=>{n.close(W)},[n]),T=(0,p.useCallback)(async()=>{if(h.length!==0){u(!0),f(null);try{await r.saveImages(h,{fileNameParts:a,columnIndex:a.includes(`columnValue`)?Number(b):void 0}),n.close(W)}catch(t){console.error(`Failed to save images:`,t),f(e.t(`sheets-drawing-ui.save.error`))}finally{u(!1)}}},[r,h,a,b,n,e]),E=a.includes(`columnValue`);return(0,m.jsxs)(`div`,{className:`univer-flex univer-flex-col`,children:[(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.imageCount`),children:(0,m.jsx)(`div`,{className:`univer-text-sm univer-text-gray-600`,children:h.length})}),(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.fileNameConfig`),children:(0,m.jsxs)(i.CheckboxGroup,{value:a,onChange:S,direction:`vertical`,children:[(0,m.jsx)(i.Checkbox,{value:`cellAddress`,disabled:!v,children:e.t(`sheets-drawing-ui.save.useRowCol`)}),v&&(0,m.jsx)(i.Checkbox,{value:`columnValue`,children:e.t(`sheets-drawing-ui.save.useColumnValue`)})]})}),E&&(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.selectColumn`),children:(0,m.jsx)(i.Select,{value:b,options:y,onChange:C})}),d&&(0,m.jsx)(`div`,{className:`univer-text-xs univer-text-red-500`,children:d}),(0,m.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3`,children:[(0,m.jsx)(i.Button,{onClick:w,disabled:s,children:e.t(`sheets-drawing-ui.save.cancel`)}),(0,m.jsx)(i.Button,{variant:`primary`,onClick:T,disabled:s||h.length===0,children:s?e.t(`sheets-drawing-ui.save.saving`):e.t(`sheets-drawing-ui.save.confirm`)})]})]})}let Ze=e=>{var a;let s=(0,l.useDependency)(t.ICommandService),c=(0,l.useDependency)(t.LocaleService),u=(0,l.useDependency)(o.IDrawingManagerService),d=(0,l.useDependency)(r.IRenderManagerService),{drawings:f}=e,h=f[0];if(h==null)return;let{unitId:g}=h,_=d.getRenderById(g),v=_==null?void 0:_.scene;if(v==null)return;let y=v.getTransformerByCreate(),[b,x]=(0,p.useState)(!0),[S,C]=(0,p.useState)((a=h.anchorType)==null?n.SheetDrawingAnchorType.Position:a);function w(e,t){let n=[];return e.forEach(e=>{let{oKey:r}=e,i=t.getDrawingOKey(r);if(i==null)return n.push(null),!0;let{unitId:a,subUnitId:o,drawingId:s,drawingType:c,anchorType:l,sheetTransform:u,axisAlignSheetTransform:d}=i;n.push({unitId:a,subUnitId:o,drawingId:s,anchorType:l,sheetTransform:u,drawingType:c,axisAlignSheetTransform:d})}),n}(0,p.useEffect)(()=>{let e=y.clearControl$.subscribe(e=>{e===!0&&x(!1)}),t=y.changeStart$.subscribe(e=>{let{objects:t}=e,r=w(t,u);if(r.length===0)x(!1);else if(r.length>=1){var i;x(!0),C(((i=r[0])==null?void 0:i.anchorType)||n.SheetDrawingAnchorType.Position)}});return()=>{t.unsubscribe(),e.unsubscribe()}},[]);function T(e){C(e);let t=u.getFocusDrawings();if(t.length===0)return;let r=t.map(t=>({unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId,anchorType:e}));s.executeCommand(n.SetSheetDrawingCommand.id,{unitId:t[0].unitId,drawings:r})}return(0,m.jsxs)(`div`,{className:(0,i.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!b}),children:[(0,m.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,m.jsx)(`div`,{children:c.t(`sheets-drawing-ui.drawing-anchor.title`)})}),(0,m.jsx)(`div`,{children:(0,m.jsxs)(i.RadioGroup,{value:S,onChange:T,direction:`vertical`,children:[(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Both,children:c.t(`sheets-drawing-ui.drawing-anchor.both`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Position,children:c.t(`sheets-drawing-ui.drawing-anchor.position`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.None,children:c.t(`sheets-drawing-ui.drawing-anchor.none`)})]})})]})},Qe=()=>{let e=(0,l.useDependency)(o.IDrawingManagerService),[t,n]=(0,p.useState)(e.getFocusDrawings());return(0,p.useEffect)(()=>{let t=e.focus$.subscribe(e=>{n(e)});return()=>{t.unsubscribe()}},[]),!!(t!=null&&t.length)&&(0,m.jsxs)(`div`,{className:`univer-text-sm`,children:[(0,m.jsx)(u.DrawingCommonPanel,{drawings:t}),(0,m.jsx)(Ze,{drawings:t})]})},$e=class extends t.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(K,Qe)),this.disposeWithMe(this._componentManager.register(W,Xe))}};$e=D([E(0,(0,t.Inject)(l.ComponentManager))],$e);let et=(0,t.createIdentifier)(`sheets-drawing-ui.drawing-context-menu.service`);var tt=class extends t.Disposable{constructor(...e){super(...e),T(this,`_providers`,new Map)}registerProvider(e,n){return this._providers.set(e,n),(0,t.toDisposable)(()=>{this._providers.get(e)===n&&this._providers.delete(e)})}getContextMenuPosition(e){var t;return(t=this._providers.get(e.drawingType))==null?void 0:t.getContextMenuPosition(e)}};let nt=class extends t.RxDisposable{constructor(e,t,n,r,i){super(),this._drawingManagerService=e,this._contextMenuService=t,this._renderManagerService=n,this._univerInstanceService=r,this._drawingContextMenuService=i,this._init()}_init(){this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._contextMenuListener(e))}_contextMenuListener(e){var t;if(!e)return;let n=(t=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:t.scene;if(!n)return;let r=n.getTransformerByCreate();r&&this.disposeWithMe(r.changeEnd$.subscribe(e=>{let{event:t}=e;if(t.button!==2)return;let n=r.getSelectedObjectMap();if(n.size===0)return;let i=[];for(let e of n.values()){let t=e.oKey,n=this._drawingManagerService.getDrawingOKey(t);if(!n)return;i.push(n)}this._contextMenuService.triggerContextMenu(t,this._getContextMenuPosition(i))}))}_getContextMenuPosition(e){var t;if(e.length!==1)return l.ContextMenuPosition.DRAWING;let[n]=e;return(t=this._drawingContextMenuService.getContextMenuPosition({unitId:n.unitId,subUnitId:n.subUnitId,drawingId:n.drawingId,drawingType:n.drawingType,drawing:n}))==null?l.ContextMenuPosition.DRAWING:t}};nt=D([E(0,o.IDrawingManagerService),E(1,l.IContextMenuService),E(2,r.IRenderManagerService),E(3,t.IUniverInstanceService),E(4,et)],nt);let rt=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._hoverManagerService=t,this._selectionsService=n,this._drawingRenderService=r,this._sheetSkeletonManagerService=i,T(this,`_isSetCursor`,!1),this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe((0,d.throttleTime)(33)).subscribe(e=>{let t=[];if(e!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),(e==null?void 0:e.unitId)===this._context.unitId&&e!=null&&e.drawing&&t.length===1&&t[0].primary){let{row:n,col:i}=e,{actualRow:a,actualColumn:o,startRow:s,startColumn:c,endRow:l,endColumn:u,isMerged:d,isMergedMainCell:f}=t[0].primary;(d||f)&&n>=s&&n<=l&&i>=c&&i<=u||n===a&&i===o?(this._isSetCursor=!0,this._context.scene.setCursor(r.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}else this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(e=>{if(e!=null&&e.drawing&&this._isSetCursor){var t;let n=e.drawing.drawing.drawingOrigin,r=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(n.imageSourceType,n.source);if(!r)return;this._drawingRenderService.previewImage(`preview-cell-image`,r.src,r.width,r.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};rt=D([E(1,(0,t.Inject)(c.HoverManagerService)),E(2,(0,t.Inject)(s.SheetsSelectionsService)),E(3,(0,t.Inject)(u.DrawingRenderService)),E(4,(0,t.Inject)(c.SheetSkeletonManagerService))],rt);let it=class extends t.Disposable{constructor(e,t,n,r){super(),this._context=e,this._sheetDrawingService=t,this._drawingManagerService=n,this._sheetSkeletonService=r,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);let e=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(let t in e){let r=e[t];for(let e in r.data){let t=r.data[e],{unitId:i,subUnitId:a}=t,o=this._sheetSkeletonService.getSkeletonParam(i,a);o&&t.sheetTransform&&(t.transform=(0,n.drawingPositionToTransform)(t.sheetTransform,o))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};it=D([E(1,n.ISheetDrawingService),E(2,o.IDrawingManagerService),E(3,(0,t.Inject)(s.SheetSkeletonService))],it);function at(e,t,n){var r,i;if((n==null||(r=n.p)==null||(r=r.body)==null?void 0:r.dataStream.length)===3&&((i=n.p)==null||(i=i.drawingsOrder)==null?void 0:i.length)===1){let r=n.p.drawings[n.p.drawingsOrder[0]],i=k(e,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},r.docTransform.size.width,r.docTransform.size.height,r.docTransform.angle);if(i)return r.transform.width=i.width,r.transform.height=i.height,r.docTransform.size.width=i.width,r.docTransform.size.height=i.height,r.transform.left=0,r.transform.top=0,r.docTransform.positionH.posOffset=0,r.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let ot=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._injector=t,this._drawingManagerService=n,this._docDrawingController=r,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible?e.visible&&(this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(s.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:s.InterceptCellContentPriority.CELL_IMAGE,handler:(e,t,n)=>{var r;return e!=null&&e.p&&(r=e.p.drawingsOrder)!=null&&r.length&&(e===t.rawData&&(e={...t.rawData}),e.interceptorStyle||(e.interceptorStyle={}),e.interceptorStyle.tr={a:0},at(this._injector,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},e)),n(e)}}))}};ot=D([E(0,(0,t.Inject)(s.SheetInterceptorService)),E(1,(0,t.Inject)(t.Injector)),E(2,o.IDrawingManagerService),E(3,(0,t.Inject)(f.DocDrawingController)),E(4,(0,t.Inject)(c.IEditorBridgeService))],ot);let st=class extends t.Disposable{constructor(e,t){super(),this._autoFillService=e,this._injector=t,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:`sheet-cell-image-autofill`,onBeforeSubmit:(e,n,r,i)=>{new t.ObjectMatrix(i).forValue((t,n,r)=>{at(this._injector,{unitId:e.unitId,subUnitId:e.subUnitId,row:t,col:n},r)})}}))}};st=D([E(0,(0,t.Inject)(s.IAutoFillService)),E(1,(0,t.Inject)(t.Injector))],st);let ct=[t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],lt=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._commandService=e,this._univerInstanceService=t,this._dialogService=n,this._renderManagerService=r,this._localeService=i,this._initDocImageCopyPasteHooks()}_setCellImage(e){var n;let i=(0,t.createDocumentModelWithStyle)(``,{}),a=(n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(c.EditingRenderController),o=t.BuildTextUtils.drawing.add({documentDataModel:i,drawings:[e],selection:{collapsed:!0,startOffset:0,endOffset:0}});o&&(i.apply(o),a&&a.submitCellData(i))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===a.InnerPasteCommand.id){var n;let{doc:i}=e.params,a=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(a==null||!Object.keys((n=i.drawings)==null?{}:n).length)return;let o=a.getUnitId();if(ct.includes(o)){var r;let e=()=>{this._dialogService.close(`sheet-cell-image-copy-paste`),this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1})};((r=a.getBody())==null?void 0:r.dataStream)===`\r
2
- `?(this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(i.drawings)[0])):this._dialogService.open({id:`sheet-cell-image-copy-paste`,title:{label:this._localeService.t(`sheets-drawing-ui.cell-image.pasteTitle`)},children:{label:this._localeService.t(`sheets-drawing-ui.cell-image.pasteContent`)},width:320,destroyOnClose:!0,onClose:e,showOk:!0,showCancel:!0,onOk:()=>{e(),this._setCellImage(Object.values(i.drawings)[0])},onCancel:e})}}}))}};lt=D([E(0,t.ICommandService),E(1,t.IUniverInstanceService),E(2,l.IDialogService),E(3,r.IRenderManagerService),E(4,(0,t.Inject)(t.LocaleService))],lt);let ut=`image/png`;function dt(e){let t=e.split(`,`),n=atob(t[1]),r=n.length,i=new Uint8Array(r);for(let e=0;e<r;e++)i[e]=n.charCodeAt(e);return new Blob([i],{type:ut})}function ft(e){let t=new ClipboardItem({[ut]:dt(e)});navigator.clipboard.write([t]).catch(e=>{console.error(`Could not copy image using clipboard API: `,e)})}function pt(){function e(){let e=document.createElement(`input`);return e.style.position=`absolute`,e.style.height=`1px`,e.style.width=`1px`,e.style.opacity=`0`,e}let t=document.activeElement,n=e();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),t instanceof HTMLElement&&t.focus()}}let mt=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],ht=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._drawingService=r,this._clipboardInterfaceService=i,this._commandService=a,T(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:`SHEET_IMAGE_UI_PLUGIN`,onBeforeCopy:(e,r,i,a)=>{this._copyInfo=null;let o=this._focusedDrawings;if(o.length>0){let[r]=o;if(r.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)return;if(a===c.COPY_TYPE.CUT){let t={unitId:e,drawings:[r]};this._commandService.executeCommand(n.RemoveSheetDrawingCommand.id,t)}setTimeout(()=>{let e=pt();r.drawingType===t.DrawingTypeEnum.DRAWING_IMAGE&&r.imageSourceType===t.ImageSourceType.BASE64?ft(r.source):this._clipboardInterfaceService.writeText(``),e()},200);let i={unitId:r.unitId,subUnitId:r.subUnitId,drawings:[r]};this._copyInfo=i}else{let t=this._createDrawingsCopyInfoByRange(e,r,i);this._copyInfo=t}},onPasteCells:(e,t,n,r)=>{if(!this._copyInfo)return{redos:[],undos:[]};let{copyType:i=c.COPY_TYPE.COPY,pasteType:a}=r,{range:o,unitId:s,subUnitId:l}=e||{},{range:u,unitId:d,subUnitId:f}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({unitId:d,subUnitId:f,pasteRange:u,pasteType:a},{unitId:s,subUnitId:l,copyType:i,copyRange:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},c.COPY_TYPE.COPY)},onPastePlainText:(e,t)=>({undos:[],redos:[]}),onPasteUnrecognized:e=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:c.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},c.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(e,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:c.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},c.COPY_TYPE.COPY);{let e=t.filter(e=>e.type.includes(`image`));if(e.length)return{undos:[],redos:[{id:j.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(e,r,i){let a=this._sheetSkeletonService.getSkeleton(e,r);if(!a)return;let o=(0,s.attachRangeWithCoord)(a,i);if(!o)return;let{startX:c,endX:l,startY:u,endY:d}=o,f=this._drawingService.getDrawingData(e,r),p=this._focusedDrawings.slice();if(Object.keys(f).forEach(e=>{let r=f[e];if(r.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)return;let{transform:i}=r;if(r.anchorType!==n.SheetDrawingAnchorType.Both||!i)return;let{left:a=0,top:o=0,width:s=0,height:m=0}=i,{drawingStartX:h,drawingEndX:g,drawingStartY:_,drawingEndY:v}={drawingStartX:a,drawingEndX:a+s,drawingStartY:o,drawingEndY:o+m};c<=h&&g<=l&&u<=_&&v<=d&&p.push(r)}),p.length)return{copyRange:i,drawings:p,unitId:e,subUnitId:r}}_generateSingleDrawingPasteMutations(e,t){let{pasteType:r,pasteTo:i}=e;if(mt.includes(r))return{redos:[],undos:[]};let{unitId:a,subUnitId:o,range:l}=i,u=this._sheetSkeletonService.getSkeleton(a,o);if(!u)return{redos:[],undos:[]};let{drawings:d}=this._copyInfo,f=(0,s.discreteRangeToRange)(l);return this._generateMutations(d,{unitId:a,subUnitId:o,isCut:t===c.COPY_TYPE.CUT,getTransform:(e,t)=>{var r,i;let a=(0,s.attachRangeWithCoord)(u,{startRow:f.startRow,endRow:f.endRow,startColumn:f.startColumn,endColumn:f.endColumn}),o={...e,left:a==null?void 0:a.startX,top:a==null?void 0:a.startY};return{transform:o,sheetTransform:(r=(0,n.transformToDrawingPosition)(o,u))==null?t:r,axisAlignSheetTransform:(i=(0,n.transformToAxisAlignPosition)(o,u))==null?t:i}}})}_generateMutations(e,r){let{unitId:i,subUnitId:a,getTransform:o,isCut:s}=r,c=[],l=[],{_drawingService:u}=this;return e.forEach(e=>{let{transform:r,sheetTransform:d}=e;if(!r)return;let f=o(r,d),p={...e,unitId:i,subUnitId:a,drawingId:s?e.drawingId:(0,t.generateRandomId)(),transform:f.transform,sheetTransform:f.sheetTransform,axisAlignSheetTransform:f.axisAlignSheetTransform};if(s){let{undo:e,redo:t,objects:r}=u.getBatchUpdateOp([p]);c.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,type:n.DrawingApplyType.UPDATE,op:t,objects:r}}),l.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,type:n.DrawingApplyType.UPDATE,op:e,objects:r}})}else{let{undo:e,redo:t,objects:r}=u.getBatchAddOp([p]);c.push({id:n.SetDrawingApplyMutation.id,params:{op:t,unitId:i,subUnitId:a,objects:r,type:n.DrawingApplyType.INSERT}}),l.push({id:n.SetDrawingApplyMutation.id,params:{op:e,unitId:i,subUnitId:a,objects:r,type:n.DrawingApplyType.REMOVE}})}}),{redos:c,undos:l}}_generateRangeDrawingsPasteMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:r,subUnitId:i,pasteRange:a,pasteType:o}=e,{unitId:l,subUnitId:u,copyRange:d,copyType:f}=t;if(mt.includes(o))return{redos:[],undos:[]};let p=this._sheetSkeletonService.getSkeleton(r,i);if(!p)return{redos:[],undos:[]};let{drawings:m}=this._copyInfo;if(!d)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:r,subUnitId:i,range:(0,s.discreteRangeToRange)(a)},pasteType:o},f);let h=this._sheetSkeletonService.getSkeleton(l,u);if(!h)return{redos:[],undos:[]};let{ranges:[g,_],mapFunc:v}=(0,c.virtualizeDiscreteRanges)([d,a]),{row:y,col:b}=v(g.startRow,g.startColumn),{row:x,col:S}=v(_.startRow,_.startColumn),C=(0,s.attachRangeWithCoord)(h,{startRow:y,endRow:y,startColumn:b,endColumn:b}),w=(0,s.attachRangeWithCoord)(p,{startRow:x,endRow:x,startColumn:S,endColumn:S});if(!C||!w)return{redos:[],undos:[]};let T=w.startX-C.startX,E=w.startY-C.startY,D=x-y,O=S-b;return this._generateMutations(m,{unitId:r,subUnitId:i,getTransform:(e,t)=>{var r,i,a;let o={...e,left:((r=e==null?void 0:e.left)==null?0:r)+T,top:((i=e==null?void 0:e.top)==null?0:i)+E};return{transform:o,sheetTransform:{...t,to:{...t.to,row:t.to.row+D,column:t.to.column+O},from:{...t.from,row:t.from.row+D,column:t.from.column+O}},axisAlignSheetTransform:(a=(0,n.transformToAxisAlignPosition)(o,p))==null?t:a}},isCut:f===c.COPY_TYPE.CUT})}};ht=D([E(0,c.ISheetClipboardService),E(1,r.IRenderManagerService),E(2,(0,t.Inject)(s.SheetSkeletonService)),E(3,o.IDrawingManagerService),E(4,l.IClipboardInterfaceService),E(5,t.ICommandService)],ht);let gt=[r.ObjectType.IMAGE,r.ObjectType.SHAPE,r.ObjectType.CHART,r.ObjectType.DRAWING_DOM],_t=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._commandService=e,this._localeService=t,this._renderManagerService=n,this._permissionService=r,this._univerInstanceService=i,this._userManagerService=a,this._sheetPermissionCheckController=o,this._sheetDrawingService=s,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange(),this._initCommandPermissionCheck()}_initDrawingVisible(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$,r=(0,d.combineLatest)([e,n]);this.disposeWithMe(r.pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.tap)(t=>{if(!t){this._sheetDrawingService.setDrawingVisible(!1);return}let n=e.getUnitId(),r=t.getSheetId();this._permissionService.composePermission([new s.WorkbookViewPermission(n).id,new s.WorksheetViewPermission(n,r).id]).every(e=>e.value)?this._sheetDrawingService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,t)})):(this._sheetDrawingService.setDrawingVisible(!1),d.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(e,t){this._sheetDrawingService.setDrawingVisible(!1);let n=e.getUnitId(),r=t.getSheetId(),i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i),o=this._renderManagerService.getRenderById(n),s=o==null?void 0:o.scene;s&&s.getAllObjectsByOrder().forEach(e=>{gt.includes(e.objectType)&&a.some(t=>e.oKey.includes(t.drawingId))&&s.removeObject(e)})}_initDrawingEditable(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$,r=(0,d.combineLatest)([e,n]);this.disposeWithMe(r.pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.tap)(t=>{if(!t){this._sheetDrawingService.setDrawingEditable(!1);return}let n=e.getUnitId(),r=t.getSheetId();this._permissionService.composePermission([new s.WorkbookEditablePermission(n).id,new s.WorksheetEditPermission(n,r).id]).every(e=>e.value)?this._sheetDrawingService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,t)})):(this._sheetDrawingService.setDrawingEditable(!1),d.EMPTY))).subscribe())}_handleDrawingEditableFalse(e,t){this._sheetDrawingService.setDrawingEditable(!1);let n=e.getUnitId(),r=t.getSheetId(),i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i),o=this._renderManagerService.getRenderById(n),s=o==null?void 0:o.scene;s&&s.getAllObjectsByOrder().forEach(e=>{gt.includes(e.objectType)&&a.some(t=>e.oKey.includes(t.drawingId))&&s.detachTransformerFrom(e)})}_initViewPermissionChange(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$;this.disposeWithMe((0,d.combineLatest)([e,n]).pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=t.getSheetId(),i=this._renderManagerService.getRenderById(n),a=i==null?void 0:i.scene;if(!a)return d.EMPTY;let o=a.getTransformerByCreate();return this._permissionService.composePermission$([new s.WorkbookViewPermission(n).id,new s.WorksheetViewPermission(n,r).id]).pipe((0,d.map)(e=>e.every(e=>e.value)),(0,d.distinctUntilChanged)()).pipe((0,d.map)(e=>({permission:e,scene:a,transformer:o,unitId:n,subUnitId:r})))})):d.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:r,subUnitId:i})=>{this._sheetDrawingService.setDrawingVisible(e);let a=t.getAllObjectsByOrder(),o=this._sheetDrawingService.getDrawingData(r,i),s=Object.values(o);e?this._sheetDrawingService.addNotification(s):(a.forEach(e=>{gt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.removeObject(e)}),n.clearSelectedObjects())},complete:()=>{this._sheetDrawingService.setDrawingVisible(!0);let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),n=e==null?void 0:e.getActiveSheet(),r=e==null?void 0:e.getUnitId(),i=n==null?void 0:n.getSheetId();if(!r||!i)return;let a=this._sheetDrawingService.getDrawingData(r,i),o=Object.values(a);this._sheetDrawingService.addNotification(o)}}))}_initEditPermissionChange(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$;this.disposeWithMe((0,d.combineLatest)([e,n]).pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=t.getSheetId(),i=this._renderManagerService.getRenderById(n),a=i==null?void 0:i.scene;if(!a)return d.EMPTY;let o=a.getTransformerByCreate();return this._permissionService.composePermission$([new s.WorkbookEditablePermission(n).id,new s.WorksheetEditPermission(n,r).id]).pipe((0,d.map)(e=>e.every(e=>e.value)),(0,d.distinctUntilChanged)()).pipe((0,d.map)(e=>({permission:e,scene:a,transformer:o,unitId:n,subUnitId:r})))})):d.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:r,subUnitId:i})=>{this._sheetDrawingService.setDrawingEditable(e);let a=t.getAllObjectsByOrder(),o=this._sheetDrawingService.getDrawingData(r,i),s=Object.values(o);e?(a.forEach(e=>{gt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.attachTransformerTo(e)}),this._sheetDrawingService.addNotification(s)):(a.forEach(e=>{gt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.detachTransformerFrom(e)}),n.clearSelectedObjects())},complete:()=>{let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return;let n=e.getUnitId(),r=e.getActiveSheet();if(!r)return;let i=r.getSheetId(),a=this._renderManagerService.getRenderById(n),o=a==null?void 0:a.scene;if(!o)return;let s=this._sheetDrawingService.getDrawingData(n,i),c=Object.values(s);this._sheetDrawingService.setDrawingEditable(!0),o.getAllObjectsByOrder().forEach(e=>{gt.includes(e.objectType)&&c.some(t=>e.oKey.includes(t.drawingId))&&o.detachTransformerFrom(e)})}}))}_initCommandPermissionCheck(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let t,r;if(e.id===n.InsertSheetDrawingCommand.id||e.id===n.RemoveSheetDrawingCommand.id||e.id===n.SetSheetDrawingCommand.id){var i,a;let{drawings:n}=e.params;t=n==null||(i=n[0])==null?void 0:i.unitId,r=n==null||(a=n[0])==null?void 0:a.subUnitId}else if(e.id===n.SetDrawingArrangeCommand.id){let n=e.params;t=n.unitId,r=n.subUnitId}!t||!r||this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]},t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-drawing-ui.permission.dialog.editErr`))}))}};_t=D([E(0,(0,t.Inject)(t.ICommandService)),E(1,(0,t.Inject)(t.LocaleService)),E(2,r.IRenderManagerService),E(3,t.IPermissionService),E(4,t.IUniverInstanceService),E(5,(0,t.Inject)(t.UserManagerService)),E(6,(0,t.Inject)(s.SheetPermissionCheckController)),E(7,(0,t.Inject)(n.ISheetDrawingService))],_t);function vt(e,t,n,r){let{width:i,height:a,angle:o,left:s,top:c}=e.transform,l=Ae({left:s==null?0:s,right:(s==null?0:s)+(i==null?0:i),top:c==null?0:c,bottom:(c==null?0:c)+(a==null?0:a)},t,n,r,void 0,!0),{scaleX:u,scaleY:f}=t.getAncestorScale(),p={startX:l.left,endX:l.right,startY:l.top,endY:l.bottom,rotate:o,width:i*u,height:a*f,absolute:l.absolute},m={position$:new d.BehaviorSubject(p),position:p,id:e.drawingId,componentKey:e.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:e.unitId,data:e.data,props:e.props};return[e.drawingId,m]}let yt=e=>{let{floatDomInfos:t,scene:n,skeleton:r,worksheet:i}=e;return(0,m.jsx)(`div`,{style:{position:`absolute`,top:0,left:0},children:(0,p.useMemo)(()=>t.map(e=>vt(e,n,r,i)),[t,n,r,i]).map(([e,t])=>(0,m.jsx)(l.PrintFloatDomSingle,{layer:t,id:e,position:t.position},e))})};function bt(e,t,n){return(0,i.render)((0,m.jsx)((0,l.connectInjector)(yt,n),{...e}),t),()=>(0,i.unmount)(t)}let xt=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetPrintInterceptorService=e,this._drawingRenderService=t,this._drawingManagerService=n,this._renderManagerService=r,this._componetManager=i,this._injector=a,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,n,r)=>{let{unitId:i,scene:a,subUnitId:o,resourceCollector:s}=n,c=this._drawingManagerService.getDrawingDataForUnit(i),l=c==null?void 0:c[o];return l&&l.order.forEach(e=>{let n=l.data[e];if(!n.hidden&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART&&n.drawingType!==t.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==t.DrawingTypeEnum.DRAWING_BLOCK){let e=this._drawingRenderService.renderDrawing(n,a,{allowInactiveSheet:!0});e&&s.add(Promise.resolve(e))}}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(e,n,r)=>{let{unitId:i,subUnitId:a}=n,o=this._renderManagerService.getRenderById(i);if(!o)return r(e);let s=o.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!s)return r(e);let l=this._drawingManagerService.getDrawingDataForUnit(i),u=l==null?void 0:l[n.subUnitId];if(!u)return r(e);let{scaleX:d,scaleY:f}=o.scene,p=e?{...e}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=u.order.map(e=>u.data[e]);return m.length?(m.forEach(e=>{if(!e.hidden&&!e.groupId&&e.transform&&t.Tools.isDefine(e.transform.left)&&t.Tools.isDefine(e.transform.top)&&t.Tools.isDefine(e.transform.width)&&t.Tools.isDefine(e.transform.height)){let t=s.skeleton.getCellIndexByOffset(e.transform.left,e.transform.top,d,f,{x:0,y:0}),n=s.skeleton.getCellIndexByOffset(e.transform.left+e.transform.width,e.transform.top+e.transform.height,d,f,{x:0,y:0});t.column<p.startColumn&&(p.startColumn=t.column),t.row<p.startRow&&(p.startRow=t.row),p.endRow<n.row&&(p.endRow=n.row),p.endColumn<n.column&&(p.endColumn=n.column)}}),r(p)):r(e)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(e,n,r)=>{let{unitId:i,subUnitId:a}=n,o=this._drawingManagerService.getDrawingDataForUnit(i),s=o==null?void 0:o[a];if(s){let i=s.order.map(e=>{let n=s.data[e];if(n.hidden)return null;if(n.drawingType===t.DrawingTypeEnum.DRAWING_DOM||n.drawingType===t.DrawingTypeEnum.DRAWING_BLOCK){let e=this._sheetPrintInterceptorService.getPrintComponent(n.componentKey);return{...n,componentKey:this._componetManager.get(e||n.componentKey)}}return null}).filter(Boolean),a=document.createElement(`div`);a.style.position=`absolute`,a.style.inset=`0`,n.root.appendChild(a);let o=bt({floatDomInfos:i,scene:n.scene,skeleton:n.skeleton,worksheet:n.worksheet},a,this._injector);return e==null||e.add(()=>{a.remove(),queueMicrotask(o)}),r(e)}return r(e)}}))}};xt=D([E(0,(0,t.Inject)(c.SheetPrintInterceptorService)),E(1,(0,t.Inject)(u.DrawingRenderService)),E(2,o.IDrawingManagerService),E(3,r.IRenderManagerService),E(4,(0,t.Inject)(l.ComponentManager)),E(5,(0,t.Inject)(t.Injector))],xt);let St=[s.InsertRowCommand.id,s.InsertColCommand.id,s.RemoveRowCommand.id,s.RemoveColCommand.id,s.DeleteRangeMoveLeftCommand.id,s.DeleteRangeMoveUpCommand.id,s.InsertRangeMoveDownCommand.id,s.InsertRangeMoveRightCommand.id,s.DeltaRowHeightCommand.id,s.SetRowHeightCommand.id,s.DeltaColumnWidthCommand.id,s.SetColWidthCommand.id,s.SetRowHiddenCommand.id,s.SetSpecificRowsVisibleCommand.id,s.SetSpecificColsVisibleCommand.id,s.SetColHiddenCommand.id,s.MoveColsCommand.id,s.MoveRowsCommand.id,s.MoveRangeCommand.id],Ct=[s.SetRowVisibleMutation.id,s.SetRowHiddenMutation.id,s.SetColVisibleMutation.id,s.SetColHiddenMutation.id,s.SetWorksheetRowHeightMutation.id,s.SetWorksheetRowAutoHeightMutation.id,s.SetWorksheetRowIsAutoHeightMutation.id,s.SetWorksheetColWidthMutation.id],wt=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c){super(),this._context=e,this._commandService=t,this._sheetSkeletonService=n,this._selectionRenderService=r,this._sheetInterceptorService=i,this._selectionManagerService=a,this._sheetDrawingService=o,this._drawingManagerService=s,this._univerInstanceService=c,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({getMutations:e=>{let{id:n,params:r}=e;if(!St.includes(n)||!r)return{redos:[],undos:[]};if(n===s.InsertRowCommand.id)return this._moveRowInterceptor(r,`insert`);if([s.MoveColsCommand.id,s.MoveRowsCommand.id,s.MoveRangeCommand.id].includes(n)){let e;if(n===s.MoveRangeCommand.id){let t=r;if(t.toUnitId&&t.fromUnitId&&t.toUnitId!==t.fromUnitId||t.toSubUnitId&&t.fromSubUnitId&&t.toSubUnitId!==t.fromSubUnitId)return{redos:[],undos:[]};e=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:t.toUnitId,subUnitId:t.toSubUnitId})}else e=(0,s.getSheetCommandTarget)(this._univerInstanceService,r);if(!e)return{redos:[],undos:[]};let{unitId:t,subUnitId:i}=e,{fromRange:a,toRange:o}=r;return this._moveRangeInterceptor(t,i,a,o)}else if(n===s.InsertColCommand.id)return this._moveColInterceptor(r,`insert`);else if(n===s.RemoveRowCommand.id)return this._moveRowInterceptor(r,`remove`);else if(n===s.RemoveColCommand.id)return this._moveColInterceptor(r,`remove`);else if(n===s.DeleteRangeMoveLeftCommand.id){let{range:e}=r;return this._getRangeMoveUndo(e,0)}else if(n===s.DeleteRangeMoveUpCommand.id){let{range:e}=r;return this._getRangeMoveUndo(e,1)}else if(n===s.InsertRangeMoveDownCommand.id){let{range:e}=r;return this._getRangeMoveUndo(e,2)}else if(n===s.InsertRangeMoveRightCommand.id){let{range:e}=r;return this._getRangeMoveUndo(e,3)}else if(n===s.SetRowHiddenCommand.id||n===s.SetSpecificRowsVisibleCommand.id){var i;let e=r,n=(0,s.getSheetCommandTarget)(this._univerInstanceService,e);if(!n)return{redos:[],undos:[]};let{unitId:a,subUnitId:o}=n,c=e.ranges||((i=this._selectionManagerService.getCurrentSelections())==null?void 0:i.map(e=>e.range).filter(e=>e.rangeType===t.RANGE_TYPE.ROW));return!c||c.length===0?{redos:[],undos:[]}:this._getDrawingUndoForRowVisible(a,o,c)}else if(n===s.SetColHiddenCommand.id||n===s.SetSpecificColsVisibleCommand.id){var a;let e=r,n=(0,s.getSheetCommandTarget)(this._univerInstanceService,e);if(!n)return{redos:[],undos:[]};let{unitId:i,subUnitId:o}=n,c=e.ranges||((a=this._selectionManagerService.getCurrentSelections())==null?void 0:a.map(e=>e.range).filter(e=>e.rangeType===t.RANGE_TYPE.COLUMN));return!c||c.length===0?{redos:[],undos:[]}:this._getDrawingUndoForColVisible(i,o,c)}else if(n===s.DeltaRowHeightCommand.id||n===s.DeltaColumnWidthCommand.id){let e=(0,s.getSheetCommandTarget)(this._univerInstanceService);if(!e)return{redos:[],undos:[]};let{unitId:t,subUnitId:i,worksheet:a}=e,o=[];return n===s.DeltaRowHeightCommand.id?o.push({startRow:r.anchorRow,endRow:r.anchorRow,startColumn:0,endColumn:a.getColumnCount()-1}):o.push({startRow:0,endRow:a.getRowCount()-1,startColumn:r.anchorCol,endColumn:r.anchorCol}),this._getDrawingUndoForRowAndColSize(t,i,o)}else if(n===s.SetRowHeightCommand.id||n===s.SetColWidthCommand.id){var o;let e=r,t=(0,s.getSheetCommandTarget)(this._univerInstanceService,e);if(!t)return{redos:[],undos:[]};let{unitId:n,subUnitId:i}=t,a=e.ranges||((o=this._selectionManagerService.getCurrentSelections())==null?void 0:o.map(e=>e.range));return!a||a.length===0?{redos:[],undos:[]}:this._getDrawingUndoForRowAndColSize(n,i,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(e,t){let r=(0,s.getSheetCommandTarget)(this._univerInstanceService);if(!r)return{redos:[],undos:[]};let{unitId:i,subUnitId:a}=r,o=this._sheetDrawingService.getDrawingData(i,a),c=[],l=[],u=[],d=[];if(Object.keys(o).forEach(n=>{let r=o[n],{updateDrawings:i,deleteDrawings:a}=this._getUpdateOrDeleteDrawings(e,t,r);u.push(...i),d.push(...a)}),u.length===0&&d.length===0)return{redos:[],undos:[]};if(u.length>0){let{undo:e,redo:t,objects:r}=this._sheetDrawingService.getBatchUpdateOp(u);c.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:r,type:n.DrawingApplyType.UPDATE}}),l.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:e,objects:r,type:n.DrawingApplyType.UPDATE}})}if(d.length>0){let e=this._sheetDrawingService.getBatchRemoveOp(d),t=e.undo,r=e.redo,o=e.objects;c.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE}}),l.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:o,type:n.DrawingApplyType.INSERT}})}return c.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),l.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),{redos:c,undos:l}}_getUpdateOrDeleteDrawings(e,t,r){let i=[],a=[],{sheetTransform:o,anchorType:s=n.SheetDrawingAnchorType.Position,transform:c,unitId:l,subUnitId:u,drawingId:d}=r,f=this._sheetSkeletonService.getSkeletonParam(l,u);if(!o||!c||!f)return{updateDrawings:i,deleteDrawings:a};let{from:p,to:m}=o,{row:h,column:g}=p,{row:_,column:v}=m,{startRow:y,endRow:b,startColumn:x,endColumn:S}=e,C=null,w=null,T;if(t===0&&h>=y&&_<=b)if(g>=x&&v<=S)a.push({unitId:l,subUnitId:u,drawingId:d});else{var E;let e=this._shrinkCol(x,S,{sheetSkeletonParam:f,sheetTransform:o,transform:c,anchorType:s});C=e==null?void 0:e.newSheetTransform,w=e==null?void 0:e.newTransform,T=(E=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:E}else if(t===1&&g>=x&&v<=S)if(h>=y&&_<=b)a.push({unitId:l,subUnitId:u,drawingId:d});else{var D;let e=this._shrinkRow(y,b,{sheetSkeletonParam:f,sheetTransform:o,transform:c,anchorType:s});C=e==null?void 0:e.newSheetTransform,w=e==null?void 0:e.newTransform,T=(D=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:D}else if(t===2){var O;let e=this._expandRow(y,b,{sheetSkeletonParam:f,sheetTransform:o,transform:c,anchorType:s});C=e==null?void 0:e.newSheetTransform,w=e==null?void 0:e.newTransform,T=(O=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:O}else if(t===3){var k;let e=this._expandCol(x,S,{sheetSkeletonParam:f,sheetTransform:o,transform:c,anchorType:s});C=e==null?void 0:e.newSheetTransform,w=e==null?void 0:e.newTransform,T=(k=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:k}if(C&&w){let e=(0,n.drawingPositionToTransform)(C,f);i.push({...r,sheetTransform:C,transform:e,axisAlignSheetTransform:T})}return{updateDrawings:i,deleteDrawings:a}}_remainDrawingSize(e,t,r,i){let a=(0,n.transformToDrawingPosition)({...e},i);if(a){let o=(0,n.transformToAxisAlignPosition)({...e},i);t.push({...r,sheetTransform:a,axisAlignSheetTransform:o})}}_getDrawingUndoForColVisible(e,t,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return{redos:[],undos:[]};let a=this._drawingManagerService.getDrawingData(e,t),o=[],c=[];if(Object.keys(a).forEach(e=>{let t=a[e],{sheetTransform:l,transform:u,anchorType:d=n.SheetDrawingAnchorType.Position}=t;if(d===n.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,t,i);else{let{from:e,to:a}=l,{row:f,column:p}=e,{row:m,column:h}=a;for(let e=0;e<r.length;e++){let{startColumn:a,endColumn:l}=r[e];if(h<a)continue;if(d===n.SheetDrawingAnchorType.Position){let e=null,r=null;if(p>=a&&p<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:l,startRow:f,endRow:m});r={...u,left:e.startX}}if(r){e=(0,n.transformToDrawingPosition)(r,i);let a=(0,n.transformToAxisAlignPosition)(r,i);if(e&&r){o.push({...t,sheetTransform:e,transform:r,axisAlignSheetTransform:a});break}}continue}if(p>=a&&h<=l)continue;let g=null,_=null;if(p>=a&&p<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:l,startRow:f,endRow:m});_={...u,left:(e==null?void 0:e.startX)||0,width:((u==null?void 0:u.width)||0)-e.endX+e.startX}}else if(h>=a&&h<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:a,endColumn:h,startRow:f,endRow:m});_={...u,left:e.startX-((u==null?void 0:u.width)||0)}}else{let e=(0,s.attachRangeWithCoord)(i,{startColumn:a,endColumn:l,startRow:f,endRow:m});if(_={...u,width:((u==null?void 0:u.width)||0)-e.endX+e.startX},g=(0,n.transformToDrawingPosition)(_,i),g&&_){let e=(0,n.transformToAxisAlignPosition)(_,i);c.push({...t,sheetTransform:g,transform:_,axisAlignSheetTransform:e});break}}if(_&&(g=(0,n.transformToDrawingPosition)(_,i)),_&&g){let e=(0,n.transformToAxisAlignPosition)(_,i);o.push({...t,sheetTransform:g,transform:_,axisAlignSheetTransform:e});break}else this._remainDrawingSize(u,o,t,i)}}}),o.length===0&&c.length===0)return{redos:[],undos:[]};let{redos:l,undos:u}=this._createUndoAndRedoMutation(e,t,o),d=[],f=[];if(c.length>0){let{redos:n,undos:r}=this._createUndoAndRedoMutation(e,t,c);d.push(...n),f.push(...r)}return{redos:l,undos:u,preRedos:d,preUndos:f}}_createUndoAndRedoMutation(e,t,r){let{undo:i,redo:a,objects:o}=this._sheetDrawingService.getBatchUpdateOp(r);return{redos:[{id:n.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:a,objects:o,type:n.DrawingApplyType.UPDATE}},{id:n.ClearSheetDrawingTransformerOperation.id,params:[e]}],undos:[{id:n.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:i,objects:o,type:n.DrawingApplyType.UPDATE}},{id:n.ClearSheetDrawingTransformerOperation.id,params:[e]}]}}_getDrawingUndoForRowVisible(e,t,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return{redos:[],undos:[]};let a=this._drawingManagerService.getDrawingData(e,t),o=[],c=[];if(Object.keys(a).forEach(e=>{let t=a[e],{sheetTransform:l,transform:u,anchorType:d=n.SheetDrawingAnchorType.Position}=t;if(d===n.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,t,i);else{let{from:e,to:a}=l,{row:f,column:p}=e,{row:m,column:h}=a;for(let e=0;e<r.length;e++){let{startRow:a,endRow:l}=r[e];if(m<a)continue;if(d===n.SheetDrawingAnchorType.Position){let e=null,r=null;if(f>=a&&f<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:h,startRow:f,endRow:l});r={...u,top:e.startY}}if(r){e=(0,n.transformToDrawingPosition)(r,i);let a=(0,n.transformToAxisAlignPosition)(r,i);if(e&&r){o.push({...t,sheetTransform:e,transform:r,axisAlignSheetTransform:a});break}}continue}if(f>=a&&m<=l)continue;let g=null,_=null;if(f>=a&&f<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:h,startRow:f,endRow:l});_={...u,top:(e==null?void 0:e.startY)||0,height:((u==null?void 0:u.height)||0)-e.endY+e.startY}}else if(m>=a&&m<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:h,startRow:a,endRow:m});_={...u,top:e.startY-((u==null?void 0:u.height)||0)}}else{let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:h,startRow:a,endRow:l});if(_={...u,height:((u==null?void 0:u.height)||0)-e.endY+e.startY},g=(0,n.transformToDrawingPosition)(_,i),g&&_){let e=(0,n.transformToAxisAlignPosition)(_,i);c.push({...t,sheetTransform:g,transform:_,axisAlignSheetTransform:e});break}}if(_&&(g=(0,n.transformToDrawingPosition)(_,i)),_&&g){let e=(0,n.transformToAxisAlignPosition)(_,i);o.push({...t,sheetTransform:g,transform:_,axisAlignSheetTransform:e});break}else this._remainDrawingSize(u,o,t,i)}}}),o.length===0&&c.length===0)return{redos:[],undos:[]};let{redos:l,undos:u}=this._createUndoAndRedoMutation(e,t,o),d=[],f=[];if(c.length>0){let{redos:n,undos:r}=this._createUndoAndRedoMutation(e,t,c);d.push(...n),f.push(...r)}return{redos:l,undos:u,preRedos:d,preUndos:f}}_getDrawingUndoForRowAndColSize(e,t,r){let i=this._sheetSkeletonService.getSkeletonParam(e,t);if(!i)return{redos:[],undos:[]};let{skeleton:a}=i,o=this._drawingManagerService.getDrawingData(e,t),s=[];return Object.keys(o).forEach(e=>{let t=o[e],{sheetTransform:c,transform:l,anchorType:u=n.SheetDrawingAnchorType.Position}=t;if(u===n.SheetDrawingAnchorType.None)this._remainDrawingSize(l,s,t,a);else{let{from:e,to:o}=c,{row:d,column:f}=e,{row:p,column:m}=o;for(let e=0;e<r.length;e++){let{startRow:o,endRow:h,startColumn:g,endColumn:_}=r[e];if(p<o||m<g)continue;if(u===n.SheetDrawingAnchorType.Position&&(d<=o&&p>=h||f<=g&&m>=_)){this._remainDrawingSize(l,s,t,a);continue}let v=(0,n.drawingPositionToTransform)({...c},i);if(v){s.push({...t,transform:v});break}}}}),s.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(e,t,s)}_getUnitIdAndSubUnitId(e,t){let n;if(n=t===`insert`?(0,s.getSheetCommandTarget)(this._univerInstanceService,e):(0,s.getSheetCommandTarget)(this._univerInstanceService),!n)return;let{unitId:r,subUnitId:i}=n;return{unitId:r,subUnitId:i}}_moveRangeInterceptor(e,t,r,i){let a=this._sheetSkeletonService.getSkeletonParam(e,t);if(!a)return{redos:[],undos:[]};let{skeleton:o}=a,c=(0,s.attachRangeWithCoord)(o,r);if(!c)return{redos:[],undos:[]};let{startX:l,endX:u,startY:d,endY:f}=c,p=this._sheetDrawingService.getDrawingData(e,t),m=[];Object.keys(p).forEach(e=>{let t=p[e];if(t.anchorType!==n.SheetDrawingAnchorType.Both)return;let{transform:r}=t;if(!r)return;let{left:i=0,top:a=0,width:o=0,height:s=0}=r,{drawingStartX:c,drawingEndX:h,drawingStartY:g,drawingEndY:_}={drawingStartX:i,drawingEndX:i+o,drawingStartY:a,drawingEndY:a+s};l<=c&&h<=u&&d<=g&&_<=f&&m.push(t)});let h=[],g=[],_=i.startRow-r.startRow,v=i.startColumn-r.startColumn,y=m.map(r=>{let i=r.sheetTransform,o={to:{...i.to,row:i.to.row+_,column:i.to.column+v},from:{...i.from,row:i.from.row+_,column:i.from.column+v}},s=(0,n.drawingPositionToTransform)(o,a);return{unitId:e,subUnitId:t,drawingId:r.drawingId,transform:s,sheetTransform:o}});if(y.length){let{undo:r,redo:i,objects:a}=this._sheetDrawingService.getBatchUpdateOp(y);h.push({id:n.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:i,objects:a,type:n.DrawingApplyType.UPDATE}}),g.push({id:n.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:r,objects:a,type:n.DrawingApplyType.UPDATE}})}return{redos:h,undos:g}}_moveRowInterceptor(e,t){let r=this._getUnitIdAndSubUnitId(e,t);if(!r)return{redos:[],undos:[]};let{unitId:i,subUnitId:a}=r,o=this._sheetSkeletonService.getSkeletonParam(i,a);if(!o)return{redos:[],undos:[]};let{range:s}=e,c=s.startRow,l=s.endRow,u=[],d=[],f=this._sheetDrawingService.getDrawingData(i,a),p=[],m=[];if(Object.keys(f).forEach(e=>{let{sheetTransform:r,transform:s,anchorType:u=n.SheetDrawingAnchorType.Position}=f[e];if(!r||!s)return;let d,h,g;if(t===`insert`){var _;let e=this._expandRow(c,l,{sheetSkeletonParam:o,sheetTransform:r,transform:s,anchorType:u});d=e==null?void 0:e.newSheetTransform,h=e==null?void 0:e.newTransform,g=(_=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:_}else{let{from:t,to:f}=r,{row:p}=t,{row:_}=f;if(u===n.SheetDrawingAnchorType.Both&&p>=c&&_<=l)m.push({unitId:i,subUnitId:a,drawingId:e});else{var v;let e=this._shrinkRow(c,l,{sheetSkeletonParam:o,sheetTransform:r,transform:s,anchorType:u});d=e==null?void 0:e.newSheetTransform,h=e==null?void 0:e.newTransform,g=(v=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:v}}if(!d||!h)return;let y={unitId:i,subUnitId:a,drawingId:e,transform:h,sheetTransform:d,axisAlignSheetTransform:g};p.push(y)}),p.length===0&&m.length===0)return{redos:[],undos:[]};if(p.length>0){let{undo:e,redo:t,objects:r}=this._sheetDrawingService.getBatchUpdateOp(p);u.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:r,type:n.DrawingApplyType.UPDATE}}),d.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:e,objects:r,type:n.DrawingApplyType.UPDATE}})}if(m.length>0){let e=this._sheetDrawingService.getBatchRemoveOp(m),t=e.undo,r=e.redo,o=e.objects;u.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE}}),d.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:o,type:n.DrawingApplyType.INSERT}})}return u.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),d.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),{redos:u,undos:d}}_moveColInterceptor(e,t){let r=this._getUnitIdAndSubUnitId(e,t);if(!r)return{redos:[],undos:[]};let{unitId:i,subUnitId:a}=r,o=this._sheetSkeletonService.getSkeletonParam(i,a);if(!o)return{redos:[],undos:[]};let{range:s}=e,c=s.startColumn,l=s.endColumn,u=[],d=[],f=this._sheetDrawingService.getDrawingData(i,a),p=[],m=[];if(Object.keys(f).forEach(e=>{let{sheetTransform:r,transform:s,anchorType:u=n.SheetDrawingAnchorType.Position}=f[e];if(!r||!s)return;let d,h,g;if(t===`insert`){var _;let e=this._expandCol(c,l,{sheetSkeletonParam:o,sheetTransform:r,transform:s,anchorType:u});d=e==null?void 0:e.newSheetTransform,h=e==null?void 0:e.newTransform,g=(_=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:_}else{let{from:t,to:f}=r,{column:p}=t,{column:_}=f;if(u===n.SheetDrawingAnchorType.Both&&p>=c&&_<=l)m.push({unitId:i,subUnitId:a,drawingId:e});else{var v;let e=this._shrinkCol(c,l,{sheetSkeletonParam:o,sheetTransform:r,transform:s,anchorType:u});d=e==null?void 0:e.newSheetTransform,h=e==null?void 0:e.newTransform,g=(v=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:v}}if(!d||!h)return;let y={unitId:i,subUnitId:a,drawingId:e,transform:h,sheetTransform:d,axisAlignSheetTransform:g};p.push(y)}),p.length===0&&m.length===0)return{redos:[],undos:[]};if(p.length>0){let{undo:e,redo:t,objects:r}=this._sheetDrawingService.getBatchUpdateOp(p);u.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:r,type:n.DrawingApplyType.UPDATE}}),d.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:e,objects:r,type:n.DrawingApplyType.UPDATE}})}if(m.length>0){let e=this._sheetDrawingService.getBatchRemoveOp(m),t=e.undo,r=e.redo,o=e.objects;u.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE}}),d.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:o,type:n.DrawingApplyType.INSERT}})}return u.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),d.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),{redos:u,undos:d}}_expandCol(e,t,r){let{sheetSkeletonParam:i,sheetTransform:a,transform:o,anchorType:c=n.SheetDrawingAnchorType.Position}=r,{skeleton:l}=i,u=t-e+1,{from:d,to:f}=a,{column:p}=d,{column:m}=f;if(c===n.SheetDrawingAnchorType.None)return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};let h=null,g=null,_=null;if(p>=e){let r=(0,s.attachRangeWithCoord)(l,{startColumn:e,endColumn:t,startRow:d.row,endRow:f.row});g={...o,left:(o.left||0)+r.endX-r.startX},h=(0,n.transformToDrawingPosition)(g,l),_=(0,n.transformToAxisAlignPosition)(g,l)}else if(m>=t)if(c===n.SheetDrawingAnchorType.Both)h={from:{...d},to:{...f,column:m+u}},g=(0,n.drawingPositionToTransform)(h,i);else return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};return h&&g?{newSheetTransform:h,newTransform:g,axisAlignSheetTransform:_}:null}_shrinkCol(e,t,r){let{sheetSkeletonParam:i,sheetTransform:a,transform:o,anchorType:c=n.SheetDrawingAnchorType.Position}=r,{skeleton:l}=i,u=t-e+1,{from:d,to:f}=a,{column:p}=d,{column:m}=f;if(c===n.SheetDrawingAnchorType.None)return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};let h=null,g=null,_=null;if(p>t)h={from:{...d,column:p-u},to:{...f,column:m-u}},g=(0,n.drawingPositionToTransform)(h,i);else if(p>=e&&m<=t)return null;else if(p<e&&m>t)if(c===n.SheetDrawingAnchorType.Both)h={from:{...d},to:{...f,column:m-u}},g=(0,n.drawingPositionToTransform)(h,i);else return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};else if(p>=e&&p<=t){if(p===e)g={...o,left:(o.left||0)-a.from.columnOffset};else{let t=(0,s.attachRangeWithCoord)(l,{startColumn:e,endColumn:p-1,startRow:d.row,endRow:f.row});g={...o,left:(o.left||0)-t.endX+t.startX-a.from.columnOffset}}h=(0,n.transformToDrawingPosition)(g,l),_=(0,n.transformToAxisAlignPosition)(g,l)}else if(m>=e&&m<=t&&c===n.SheetDrawingAnchorType.Both){let t=(0,s.attachRangeWithCoord)(l,{startColumn:e-1,endColumn:e-1,startRow:d.row,endRow:f.row});h={from:{...d},to:{...f,column:e-1,columnOffset:t.endX-t.startX}},g=(0,n.drawingPositionToTransform)(h,i)}return h&&g?{newSheetTransform:h,newTransform:g,axisAlignSheetTransform:_}:null}_expandRow(e,t,r){let{sheetSkeletonParam:i,sheetTransform:a,transform:o,anchorType:c=n.SheetDrawingAnchorType.Position}=r,{skeleton:l}=i,u=t-e+1,{from:d,to:f}=a,{row:p}=d,{row:m}=f;if(c===n.SheetDrawingAnchorType.None)return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};let h=null,g=null,_=null;if(p>=e){let r=(0,s.attachRangeWithCoord)(l,{startRow:e,endRow:t,startColumn:d.column,endColumn:f.column});g={...o,top:(o.top||0)+r.endY-r.startY},h=(0,n.transformToDrawingPosition)(g,l),_=(0,n.transformToAxisAlignPosition)(g,l)}else if(m>=t)if(c===n.SheetDrawingAnchorType.Both)h={from:{...d},to:{...f,row:m+u}},g=(0,n.drawingPositionToTransform)(h,i);else return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};return h&&g?{newSheetTransform:h,newTransform:g,axisAlignSheetTransform:_}:null}_shrinkRow(e,t,r){let{sheetSkeletonParam:i,sheetTransform:a,transform:o,anchorType:c=n.SheetDrawingAnchorType.Position}=r,{skeleton:l}=i,u=t-e+1,{from:d,to:f}=a,{row:p}=d,{row:m}=f;if(c===n.SheetDrawingAnchorType.None)return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};let h=null,g=null,_=null;if(p>t)h={from:{...d,row:p-u},to:{...f,row:m-u}},g=(0,n.drawingPositionToTransform)(h,i);else if(p>=e&&m<=t)return null;else if(p<e&&m>t)if(c===n.SheetDrawingAnchorType.Both)h={from:{...d},to:{...f,row:m-u}},g=(0,n.drawingPositionToTransform)(h,i);else return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};else if(p>=e&&p<=t){if(p===e)g={...o,top:(o.top||0)-a.from.rowOffset};else{let t=(0,s.attachRangeWithCoord)(l,{startRow:e,endRow:p-1,startColumn:d.column,endColumn:f.column});g={...o,top:(o.top||0)-t.endY+t.startY-a.from.rowOffset}}h=(0,n.transformToDrawingPosition)(g,l),_=(0,n.transformToAxisAlignPosition)(g,l)}else if(m>=e&&m<=t&&c===n.SheetDrawingAnchorType.Both){let t=(0,s.attachRangeWithCoord)(l,{startColumn:d.column,endColumn:d.column,startRow:e-1,endRow:e-1});h={from:{...d},to:{...f,row:e-1,rowOffset:t.endY-t.startY}},g=(0,n.drawingPositionToTransform)(h,i)}return h&&g?{newSheetTransform:h,newTransform:g,axisAlignSheetTransform:_}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetActiveOperation.id){let{unitId:t,subUnitId:n}=e.params;this._updateDrawings(t,n)}})),this.disposeWithMe(this._context.activated$.subscribe(e=>{let{unit:t,unitId:n}=this._context;if(e){let e=t.getActiveSheet().getSheetId();this._updateDrawings(n,e)}else this._clearDrawings(n)}))}_clearDrawings(e){setTimeout(()=>{let t=this._drawingManagerService.drawingManagerData,n=[];Object.keys(t==null?{}:t).forEach(r=>{var i;let a=(i=t[r])==null?{}:i;Object.keys(a).forEach(t=>{var i,o;let s=(i=(o=a[t])==null?void 0:o.data)==null?{}:i;Object.keys(s).forEach(t=>{r===e&&n.push(s[t])})})}),this._sheetDrawingService.removeNotification(n),this._drawingManagerService.removeNotification(n)})}_updateDrawings(e,t){setTimeout(()=>{let r=this._sheetSkeletonService.getSkeletonParam(e,t),i=this._drawingManagerService.drawingManagerData,a=[],o=[];Object.keys(i==null?{}:i).forEach(s=>{var c;if(s!==e)return;let l=(c=i[s])==null?{}:c;Object.keys(l).forEach(i=>{var c,u;let d=(c=(u=l[i])==null?void 0:u.data)==null?{}:c;Object.keys(d).forEach(c=>{if(s===e&&i===t){let e=d[c];e.sheetTransform&&(e.transform=(0,n.drawingPositionToTransform)(e.sheetTransform,r)),a.push(d[c])}else o.push(d[c])})})}),this._sheetDrawingService.removeNotification(o),this._sheetDrawingService.addNotification(a),this._drawingManagerService.removeNotification(o),this._drawingManagerService.addNotification(a)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{Ct.includes(e.id)&&requestIdleCallback(()=>{let t=e.params,n=(0,s.getSheetCommandTarget)(this._univerInstanceService,t);if(!n)return;let{unitId:r,subUnitId:i,worksheet:a}=n,o=[];`ranges`in t?o=t.ranges:`rowsAutoHeightInfo`in t&&(o=t.rowsAutoHeightInfo.map(e=>({startRow:e.row,endRow:e.row,startColumn:0,endColumn:a.getColumnCount()-1}))),this._refreshDrawingTransform(r,i,o)})}))}_refreshDrawingTransform(e,r,i){var a;let o=this._sheetSkeletonService.getSkeletonParam(e,r),s=(a=this._drawingManagerService.getDrawingData(e,r))==null?{}:a,c=[];Object.keys(s).forEach(e=>{let r=s[e],{sheetTransform:a,transform:l,anchorType:u=n.SheetDrawingAnchorType.Position}=r;if(u===n.SheetDrawingAnchorType.None||!a)return!0;let{from:d,to:f}=a,{row:p,column:m}=d,{row:h,column:g}=f;for(let e=0;e<i.length;e++){let{startRow:s,endRow:d,startColumn:f,endColumn:_}=i[e];if(t.Rectangle.intersects({startRow:s,endRow:d,startColumn:f,endColumn:_},{startRow:p,endRow:h,startColumn:m,endColumn:g})||p>d||m>_){let e=u===n.SheetDrawingAnchorType.Position,t=(0,n.drawingPositionToTransform)(a,o);c.push({...r,transform:{...t,width:e?l==null?void 0:l.width:t==null?void 0:t.width,height:e?l==null?void 0:l.height:t==null?void 0:t.height}});break}}}),c.length!==0&&(this._sheetDrawingService.refreshTransform(c),this._drawingManagerService.refreshTransform(c),this._commandService.syncExecuteCommand(n.ClearSheetDrawingTransformerOperation.id,[e]))}};wt=D([E(1,t.ICommandService),E(2,(0,t.Inject)(s.SheetSkeletonService)),E(3,c.ISheetSelectionRenderService),E(4,(0,t.Inject)(s.SheetInterceptorService)),E(5,(0,t.Inject)(s.SheetsSelectionsService)),E(6,n.ISheetDrawingService),E(7,o.IDrawingManagerService),E(8,t.IUniverInstanceService)],wt);let Tt={id:`sheet.command.toggle-flip-drawings`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),c=e.get(n.ISheetDrawingService),l=e.get(s.SheetSkeletonService),{drawings:u}=r,d=r.flipH,f=r.flipV,p=[],m=[];for(let r of u){let{unitId:i,subUnitId:a,drawingId:s}=r;p.push(i);let u=c.getDrawingData(i,a),h=u==null?void 0:u[s];if(!h)continue;let g=l.getSkeleton(i,a);if(!g)continue;let _={...h.transform};d&&(_.flipX=!_.flipX),f&&(_.flipY=!_.flipY);let v=(0,n.transformToDrawingPosition)(_,g),y=(0,n.transformToAxisAlignPosition)(_,g),b={unitId:i,subUnitId:a,drawingType:h.drawingType,drawingId:s,transform:_,sheetTransform:v,axisAlignSheetTransform:y};if(h.drawingType===t.DrawingTypeEnum.DRAWING_IMAGE){let t=Et(e,i);if(t){let e=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:s}),n=t.getObject(e);if(n){let e=n.srcRect;if(e){let t,{left:n=0,top:r=0,right:i=0,bottom:a=0}=e;if(d){let e=n+(i-n)/2;t={left:e-(i-n)/2,top:r,right:e+(i-n)/2,bottom:a}}if(f){let e=r+(a-r)/2;t={left:n,top:e-(a-r)/2,right:i,bottom:e+(a-r)/2}}t&&(b.srcRect=t)}}}}m.push(b)}if(m.length===0)return!1;let{unitId:h,subUnitId:g,undo:_,redo:v,objects:y}=c.getBatchUpdateOp(m),b={id:n.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:g,op:v,objects:y,type:n.DrawingApplyType.UPDATE}},x={id:n.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:g,op:_,objects:y,type:n.DrawingApplyType.UPDATE}};return(0,t.sequenceExecute)([b],i).result?(a.pushUndoRedo({unitID:h,undoMutations:[x,{id:n.ClearSheetDrawingTransformerOperation.id,params:p}],redoMutations:[b,{id:n.ClearSheetDrawingTransformerOperation.id,params:p}]}),!0):!1}};function Et(e,t){let n=e.get(r.IRenderManagerService).getRenderById(t);return n?n.scene:null}function Dt(e){return e.getContextValue(t.FOCUSING_SHEET)&&!e.getContextValue(t.FOCUSING_FX_BAR_EDITOR)&&!e.getContextValue(t.FOCUSING_PANEL_EDITOR)&&e.getContextValue(t.FOCUSING_COMMON_DRAWINGS)&&!e.getContextValue(t.FOCUSING_SHAPE_TEXT_EDITOR)}let Ot={id:N.id,description:`sheets-drawing-ui.shortcut.drawing-move-down`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_DOWN,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.DOWN}},kt={id:N.id,description:`sheets-drawing-ui.shortcut.drawing-move-up`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_UP,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.UP}},At={id:N.id,description:`sheets-drawing-ui.shortcut.drawing-move-left`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_LEFT,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.LEFT}},jt={id:N.id,description:`sheets-drawing-ui.shortcut.drawing-move-right`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_RIGHT,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.RIGHT}},Mt={id:h.id,description:`sheets-drawing-ui.shortcut.drawing-delete`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,priority:100,preconditions:Dt,binding:l.KeyCode.DELETE,mac:l.KeyCode.BACKSPACE},Nt=class extends t.Disposable{constructor(e,t,n){super(),this._menuManagerService=e,this._commandService=t,this._shortcutService=n,this._init()}_initCustomComponents(){}_initMenus(){this._menuManagerService.mergeMenu(Ke)}_initCommands(){[j,M,q,J,b,x,N,h,G,Tt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[Ot,kt,At,jt,Mt].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Nt=D([E(0,l.IMenuManagerService),E(1,t.ICommandService),E(2,l.IShortcutService)],Nt);let Pt=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._injector=e,this._localeService=t,this._drawingManagerService=n,this._canvasPopManagerService=r,this._renderManagerService=i,this._univerInstanceService=a,this._messageService=o,this._contextService=s,this._ioService=c,this._commandService=l,T(this,`_initImagePopupMenu`,new Set),this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._create(e)),this._univerInstanceService.getTypeOfUnitDisposed$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._dispose(e)),this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._create(e)),this._setupLoadingStatus()}_setupLoadingStatus(){let e;this.disposeWithMe(this._ioService.change$.subscribe(t=>{t>0&&!e?e=this._messageService.show({id:`image-upload-loading`,type:i.MessageType.Loading,content:`${this._localeService.t(`sheets-drawing-ui.uploadLoading.loading`)}: ${t}`,duration:0}):t===0&&(e==null||e.dispose(),e=void 0)}))}_dispose(e){super.dispose();let t=e.getUnitId();this._renderManagerService.removeRender(t),this._initImagePopupMenu.delete(t)}_create(e){if(!e)return;let t=e.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof u.ImageCropperObject)return!0;return!1}_popupMenuListener(e){var n;let r=(n=this._renderManagerService.getRenderById(e))==null?void 0:n.scene;if(!r)return;let i=r.getTransformerByCreate();if(!i)return;let a;this.disposeWithMe(i.createControl$.subscribe(()=>{if(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))return;let e=i.getSelectedObjectMap();if(e.size>1){a==null||a.dispose();return}let n=e.values().next().value;if(!n)return;let o=n.oKey,s=this._drawingManagerService.getDrawingOKey(o);if(!s||s.drawingType===t.DrawingTypeEnum.DRAWING_SHAPE)return;let{unitId:c,subUnitId:l,drawingId:d,drawingType:f}=s,p=s.data;if(p&&(p.disablePopup||p.version===1&&typeof p.embedId==`string`))return;a==null||a.dispose();let m=this._canvasPopManagerService.getFeatureMenu(c,l,d,f);a=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(n,{componentKey:u.COMPONENT_IMAGE_POPUP_MENU,direction:`horizontal`,offset:[2,0],extraProps:{menuItems:m||this._getImageMenuItems(c,l,d,f)}}))})),this.disposeWithMe(i.clearControl$.subscribe(()=>{a==null||a.dispose(),this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(e=>{e[t.FOCUSING_COMMON_DRAWINGS]===!1&&(a==null||a.dispose())})),this.disposeWithMe(i.changing$.subscribe(()=>{a==null||a.dispose()}))}_getImageMenuItems(e,r,i,a){return[{label:`sheets-drawing-ui.image-popup.edit`,index:0,commandId:J.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.delete`,index:1,commandId:n.RemoveSheetDrawingCommand.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:!1},{label:`sheets-drawing-ui.image-popup.crop`,index:2,commandId:u.OpenImageCropOperation.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipH`,index:2,commandId:Tt.id,commandParams:{unitId:e,flipH:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipV`,index:2,commandId:Tt.id,commandParams:{unitId:e,flipV:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.reset`,index:3,commandId:u.ImageResetSizeOperation.id,commandParams:[{unitId:e,subUnitId:r,drawingId:i}],disable:a===t.DrawingTypeEnum.DRAWING_DOM}]}};Pt=D([E(0,(0,t.Inject)(t.Injector)),E(1,(0,t.Inject)(t.LocaleService)),E(2,o.IDrawingManagerService),E(3,(0,t.Inject)(c.SheetCanvasPopManagerService)),E(4,r.IRenderManagerService),E(5,t.IUniverInstanceService),E(6,l.IMessageService),E(7,t.IContextService),E(8,t.IImageIoService),E(9,t.ICommandService)],Pt);let Ft=class extends t.Disposable{constructor(e,t,n){super(),this._drawingManagerService=e,this._univerInstanceService=t,this._renderManagerService=n,T(this,`_onDoubleClick$`,new d.Subject),T(this,`onDoubleClick$`,this._onDoubleClick$.asObservable()),T(this,`_doubleClickDisposable`,null),T(this,`_boundRender`,null),T(this,`_boundScene`,null),this._init()}dispose(){this._disposeDoubleClickListener(),this._onDoubleClick$.complete(),super.dispose()}hitTestCurrentSheet(e,t){let n=this._getActiveSheetContext();return n?this.hitTest(n.unitId,n.subUnitId,e,t):null}hitTest(e,t,n,r){var i;let a=(i=this._renderManagerService.getRenderById(e))==null?void 0:i.scene;return a?this._hitTestScene(a,e,t,n,r):null}_init(){this.disposeWithMe((0,t.toDisposable)(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{this._bindDoubleClickListener()}))),this.disposeWithMe((0,t.toDisposable)(this._renderManagerService.created$.subscribe(e=>{let t=this._getActiveSheetContext();e.unitId===(t==null?void 0:t.unitId)&&this._bindDoubleClickListener()}))),this.disposeWithMe((0,t.toDisposable)(this._renderManagerService.disposed$.subscribe(e=>{var t;e===((t=this._boundRender)==null?void 0:t.unitId)&&this._disposeDoubleClickListener()}))),this._bindDoubleClickListener()}_bindDoubleClickListener(){let e=this._getActiveSheetContext();if(!e){this._disposeDoubleClickListener();return}let t=this._renderManagerService.getRenderById(e.unitId),n=t==null?void 0:t.scene;if(!t||!n){this._disposeDoubleClickListener();return}if(this._boundRender===t&&this._boundScene===n&&this._doubleClickDisposable)return;this._disposeDoubleClickListener();let r=n.onDblclick$.subscribeEvent(t=>{let r=this._getActiveSheetContext();if(!r||r.unitId!==e.unitId)return;let i=this._hitTestScene(n,r.unitId,r.subUnitId,t.offsetX,t.offsetY);i&&this._onDoubleClick$.next({...i,nativeEvent:t})});this._doubleClickDisposable={dispose:()=>r.unsubscribe()},this._boundRender=t,this._boundScene=n}_disposeDoubleClickListener(){var e;(e=this._doubleClickDisposable)==null||e.dispose(),this._doubleClickDisposable=null,this._boundRender=null,this._boundScene=null}_hitTestScene(e,t,n,i,a){let o=e.pick(r.Vector2.FromArray([i,a])),s=typeof(o==null?void 0:o.oKey)==`string`?o.oKey:null;if(!s)return null;let c=this._drawingManagerService.getDrawingOKey(s);return!c||c.unitId!==t||c.subUnitId!==n?null:{drawing:c,oKey:s,offsetX:i,offsetY:a}}_getActiveSheetContext(){var e;let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getUnitId(),i=n==null||(e=n.getActiveSheet())==null?void 0:e.getSheetId();return!r||!i?null:{unitId:r,subUnitId:i}}};Ft=D([E(0,o.IDrawingManagerService),E(1,t.IUniverInstanceService),E(2,r.IRenderManagerService)],Ft);let $=class extends t.Plugin{constructor(e=Ye,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},Ye,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`sheets-drawing-ui.config`,o)}onStarting(){(0,t.registerDependencies)(this._injector,[[$e],[Q],[Ft],[Nt],[Pt],[xt],[_t],[ht],[X],[ot],[st],[lt],[F,{useClass:U}],[et,{useClass:tt}],[nt]]),Le(this._injector),this._injector.get($e)}onReady(){(0,t.touchDependencies)(this._injector,[[ht],[lt],[X]])}onRendered(){this._registerRenderModules(),(0,t.touchDependencies)(this._injector,[[_t],[xt],[Nt],[ot],[st]])}onSteady(){this._injector.get(Pt),this._injector.get(nt)}_registerRenderModules(){[[A],[wt],[it],[rt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e))})}};T($,`type`,t.UniverInstanceType.UNIVER_SHEET),T($,`pluginName`,`SHEET_IMAGE_UI_PLUGIN`),T($,`packageName`,qe),T($,`version`,Je),$=D([(0,t.DependentOn)(o.UniverDrawingPlugin,f.UniverDocsDrawingPlugin,u.UniverDrawingUIPlugin,n.UniverSheetsDrawingPlugin),E(1,(0,t.Inject)(t.Injector)),E(2,r.IRenderManagerService),E(3,t.IConfigService)],$),Object.defineProperty(e,"BatchSaveImagesService",{enumerable:!0,get:function(){return U}}),e.DeleteDrawingsCommand=h,e.DrawingContextMenuService=tt,e.EditSheetDrawingOperation=J,e.FileNamePart=P,e.GroupSheetDrawingCommand=b,e.IBatchSaveImagesService=F,e.IDrawingContextMenuService=et,e.InsertFloatImageCommand=j,e.MoveDrawingsCommand=N,e.SHEETS_DRAWING_FLOATING_HOST_DEPENDENCIES=Pe,e.SHEETS_IMAGE_MENU_ID=Re,e.SHEET_CHART_RENDER_OBJECT_CONFIG=ee,e.SHEET_FLOAT_DOM_PREFIX=ne,e.SaveCellImagesCommand=G,Object.defineProperty(e,"SheetCanvasFloatDomManagerService",{enumerable:!0,get:function(){return Q}}),e.SheetDrawingAnchor=Ze,Object.defineProperty(e,"SheetDrawingHitTestService",{enumerable:!0,get:function(){return Ft}}),Object.defineProperty(e,"SheetDrawingUpdateController",{enumerable:!0,get:function(){return A}}),Object.defineProperty(e,"SheetsDrawingGroupCopyPasteController",{enumerable:!0,get:function(){return X}}),e.SheetsDrawingUIMenuSchema=Ke,e.SidebarSheetDrawingOperation=q,e.UngroupSheetDrawingCommand=x,Object.defineProperty(e,"UniverSheetsDrawingUIPlugin",{enumerable:!0,get:function(){return $}}),e.calcSheetFloatDomPosition=Z,e.registerSheetsDrawingFloatingHostCapability=Fe});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/engine-render"),require("@univerjs/design"),require("@univerjs/docs"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/drawing-ui"),require("rxjs"),require("@univerjs/docs-drawing"),require("react"),require("react/jsx-runtime"),require("@univerjs/docs-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-drawing`,`@univerjs/engine-render`,`@univerjs/design`,`@univerjs/docs`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-ui`,`@univerjs/ui`,`@univerjs/drawing-ui`,`rxjs`,`@univerjs/docs-drawing`,`react`,`react/jsx-runtime`,`@univerjs/docs-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawingUi={},e.UniverCore,e.UniverSheetsDrawing,e.UniverEngineRender,e.UniverDesign,e.UniverDocs,e.UniverDrawing,e.UniverSheets,e.UniverSheetsUi,e.UniverUi,e.UniverDrawingUi,e.rxjs,e.UniverDocsDrawing,e.React,e.React,e.UniverDocsUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let g={id:`sheet.command.delete-drawing`,type:t.CommandType.COMMAND,handler:e=>{let r=e.get(t.ICommandService),i=e.get(n.ISheetDrawingService).getFocusDrawings();if(i.length===0)return!1;let a=i[0].unitId,o=i.map(e=>{let{unitId:t,subUnitId:n,drawingId:r,drawingType:i}=e;return{unitId:t,subUnitId:n,drawingId:r,drawingType:i}});return r.executeCommand(n.RemoveSheetDrawingCommand.id,{unitId:a,drawings:o})}};function _(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c}=i,l=(0,r.getGroupState)(0,0,a.map(e=>e.transform||{})),u=a.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,left:t.left,top:t.top},groupId:c}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,groupBaseBound:{...i.groupBaseBound},transform:l};n.push({parent:d,children:u})}),n}function v(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c,transform:l={width:0,height:0}}=i;if(l==null)return;let u=a.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:a,drawingId:o}=e;return{unitId:n,subUnitId:a,drawingId:o,transform:(0,r.transformObjectOutOfGroup)(t||{},l,l.width||0,l.height||0,i.groupBaseBound),groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:d,children:u})}),n}function y(e){var n;let r=new Map;(n=e.flatChildren)==null||n.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10))),e.groups.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10)));let i={};for(let[t,n]of Object.entries(e.nestedIdRecord)){var a,o;let e=(a=r.get(t))==null?t:a;i[e]={drawingId:e,children:(o=n.children)==null?void 0:o.map(e=>{var t;return(t=r.get(e))==null?e:t})}}let s=[],c=[];for(let t of e.groups){var l,u;let e=(l=r.get(t.drawingId))==null?t.drawingId:l,n=t.groupId?(u=r.get(t.groupId))==null?t.groupId:u:void 0;c.push(b(t,e,n))}for(let t of e.flatChildren||[]){var d,f;let e=(d=r.get(t.drawingId))==null?t.drawingId:d,n=t.groupId?(f=r.get(t.groupId))==null?t.groupId:f:void 0;s.push(b(t,e,n))}return{cloned:{nestedIdRecord:i,flatChildren:s,groups:c},idMap:r}}function b(e,t,n){let r={...e};return t&&(r.drawingId=t),n?r.groupId=n:delete r.groupId,JSON.parse(JSON.stringify(r))}let x={id:`sheet.command.group-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getGroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:v(f),type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}},S={id:`sheet.command.ungroup-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getUngroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:_(f),type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}};function C(e){"@babel/helpers - typeof";return C=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function D(e,t){return function(n,r){t(n,r,e)}}function O(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function k(e,t,n){let r=n*Math.PI/180;return{rotatedWidth:Math.abs(e*Math.cos(r))+Math.abs(t*Math.sin(r)),rotatedHeight:Math.abs(e*Math.sin(r))+Math.abs(t*Math.cos(r))}}function A(e,t,n,i,a){var o;let{rotatedHeight:s,rotatedWidth:l}=k(n,i,a),u=e.get(r.IRenderManagerService).getRenderById(t.unitId);if(!u)return!1;let d=(o=u.with(c.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:o.skeleton;if(d==null)return!1;let f=d.getCellByIndex(t.row,t.col),p=f.mergeInfo.endX-f.mergeInfo.startX-2,m=f.mergeInfo.endY-f.mergeInfo.startY-2,h=l/s,g=Math.ceil(Math.min(p,m*h))/l,_=!g||Number.isNaN(g)?.001:g;return{width:n*_,height:i*_}}let j=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){super(),this._context=e,this._commandService=t,this._sheetInterceptorService=n,this._selectionRenderService=r,this._imageIoService=i,this._fileOpenerService=a,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=c,this._messageService=l,this._localeService=u,this._sheetSkeletonService=f,this._injector=p,this._urlImageService=m,E(this,`_workbookSelections`,void 0),this._workbookSelections=d.getWorkbookSelections(this._context.unitId),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){let e=await this._fileOpenerService.openFile({multiple:!0,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}),t=e.length;return t>o.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxCount`,String(o.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(e.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){let e=(await this._fileOpenerService.openFile({multiple:!1,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){var r;let a;try{a=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/(1024*1024)))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(a==null)return;let{unitId:s,subUnitId:c}=this._getUnitInfo(),{imageId:l,imageSourceType:u,source:d,base64Cache:f}=a,{width:p,height:m,image:h}=await(0,o.getImageSize)(f||``),{width:g,height:_}=this._context.scene;this._imageIoService.addImageSourceCache(d,u,h);let v=1;if(p>o.DRAWING_IMAGE_WIDTH_LIMIT||m>o.DRAWING_IMAGE_HEIGHT_LIMIT){let e=o.DRAWING_IMAGE_WIDTH_LIMIT/p,t=o.DRAWING_IMAGE_HEIGHT_LIMIT/m;v=Math.max(e,t)}let y=this._sheetSkeletonService.getSkeletonParam(s,c);if(!y)return;let{skeleton:b}=y,x=this._getImagePosition(p*v,m*v,g,_,b);if(!x)return;let S=(0,n.drawingPositionToTransform)(x,y);if(!S)return;let C={unitId:s,subUnitId:c,drawingId:l,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:u,source:d,transform:S,sheetTransform:x,axisAlignSheetTransform:(r=(0,n.transformToAxisAlignPosition)(S,b))==null?x:r};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:s,drawings:[C]})}async _insertCellImage(e,n){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/(1024*1024)))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return!1;let{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``);this._imageIoService.addImageSourceCache(u,l,m);let h=this._workbookSelections.getCurrentLastSelection();if(!h)return!1;let g=h.primary.actualRow,_=h.primary.actualColumn;h.primary.isMerged&&(g=h.primary.startRow,_=h.primary.startColumn);let v=(0,t.createDocumentModelWithStyle)(``,{}),y=A(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:g,col:_},f,p,0);if(!y)return!1;let b=(0,a.buildDocTransform)(y.width,y.height),x={unitId:v.getUnitId(),subUnitId:v.getUnitId(),drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:(0,a.docDrawingPositionToTransform)(b),docTransform:b,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=t.BuildTextUtils.drawing.add({documentDataModel:v,drawings:[x],selection:{collapsed:!0,startOffset:0,endOffset:0}});if(S){var C,w;return v.apply(S),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(C=n==null?void 0:n.row)==null?g:C]:{[(w=n==null?void 0:n.col)==null?_:w]:{p:v.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})}return!1}async insertCellImageByUrl(e,n){let r=e;try{r=await this._urlImageService.getImage(e)}catch(t){console.error(`Failed to get image from URLImageService: ${e}`,t)}let{width:i,height:c,image:l}=await(0,o.getImageSize)(r||``);this._imageIoService.addImageSourceCache(e,t.ImageSourceType.URL,l);let u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;let d=(0,t.createDocumentModelWithStyle)(``,{}),f=A(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},i,c,0);if(!f)return!1;let p=(0,a.buildDocTransform)(f.width,f.height),m={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:(0,t.generateRandomId)(),drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t.ImageSourceType.URL,source:e,transform:(0,a.docDrawingPositionToTransform)(p),docTransform:p,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=t.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});if(h){var g,_;return d.apply(h),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(g=n==null?void 0:n.row)==null?u.primary.actualRow:g]:{[(_=n==null?void 0:n.col)==null?u.primary.actualColumn:_]:{p:d.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})}return!1}_getUnitInfo(){let e=this._context.unit,t=e.getActiveSheet();return{unitId:e.getUnitId(),subUnitId:t.getSheetId()}}_getImagePosition(e,t,n,r,i){let a=this._workbookSelections.getCurrentSelections(),o={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(o=a[a.length-1].range);let c=(0,s.attachRangeWithCoord)(i,o);if(c==null)return;let{startColumn:l,startRow:u,startX:d,startY:f}=c,p=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),p=!0),f+t>r&&(f=r-t,f<0&&(f=0,t=r),p=!0),p){let e=this._selectionRenderService.getCellWithCoordByOffset(d,f);if(e==null)return;d=e.startX,f=e.startY,l=e.actualColumn,u=e.actualRow}let m={column:l,columnOffset:0,row:u,rowOffset:0},h=this._selectionRenderService.getCellWithCoordByOffset(d+e,f+t);if(h!=null)return{from:m,to:{column:h.actualColumn,columnOffset:d+e-h.startX,row:h.actualRow,rowOffset:f+t-h.startY}}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{let{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a}=e;this._commandService.executeCommand(n.SetDrawingArrangeCommand.id,{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a})}))}_updateDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{let t=[];e.length!==0&&(e.forEach(e=>{let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeletonParam(r,i);if(!o||!s)return;let{skeleton:c}=s,l=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a});if(l==null||l.unitId!==this._context.unitId)return;let u=(0,n.transformToDrawingPosition)({...l.transform,...o},c),d=(0,n.transformToAxisAlignPosition)({...l.transform,...o},c);if(u==null||d==null)return;let f={...e,transform:{...l.transform,...o,...(0,n.drawingPositionToTransform)(u,s)},sheetTransform:{...u},axisAlignSheetTransform:{...d}};t.push(f)}),t.length>0&&this._commandService.executeCommand(n.SetSheetDrawingCommand.id,{unitId:e[0].unitId,drawings:t}))}))}_getSheetTransformByParam(e,t){let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeleton(r,i);if(!o||!s)return null;let c=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a}),l=c==null?void 0:c.transform;if(t&&(l={}),!t&&(!c||c.unitId!==this._context.unitId))return null;let u=(0,n.transformToDrawingPosition)({...l,...o},s),d=(0,n.transformToAxisAlignPosition)({...l,...o},s);return!u||!d?null:{sheetTransform:u,axisAlignSheetTransform:d}}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let e=n.parent,r=this._getSheetTransformByParam(e,!0),i=[];for(let e of n.children){let t=this._getSheetTransformByParam(e,!1);t!=null&&i.push({...e,sheetTransform:t.sheetTransform,axisAlignSheetTransform:t.axisAlignSheetTransform})}let a={parent:{...e,sheetTransform:r==null?void 0:r.sheetTransform,axisAlignSheetTransform:r==null?void 0:r.axisAlignSheetTransform},children:i};t.push(a)}if(t.length>0){this._commandService.executeCommand(x.id,t);let{unitId:n,subUnitId:r,drawingId:i}=e[0].parent;this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:r,drawingId:i}])}})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let{children:e}=n,r=[];for(let t of e){let e=this._getSheetTransformByParam(t,!1);e!=null&&r.push({...t,sheetTransform:e.sheetTransform,axisAlignSheetTransform:e.axisAlignSheetTransform})}t.push({...n,children:r})}this._commandService.executeCommand(S.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};j=O([D(1,t.ICommandService),D(2,(0,t.Inject)(s.SheetInterceptorService)),D(3,c.ISheetSelectionRenderService),D(4,t.IImageIoService),D(5,l.ILocalFileService),D(6,n.ISheetDrawingService),D(7,o.IDrawingManagerService),D(8,t.IContextService),D(9,l.IMessageService),D(10,(0,t.Inject)(t.LocaleService)),D(11,(0,t.Inject)(s.SheetsSelectionsService)),D(12,(0,t.Inject)(s.SheetSkeletonService)),D(13,(0,t.Inject)(t.Injector)),D(14,t.IURLImageService)],j);let M={id:`sheet.command.insert-float-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{var i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService),s=(i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(j);if(!s)return!1;let c=n==null?void 0:n.files;if(c){let e=c.map(e=>s.insertFloatImageByFile(e));return(await Promise.all(e)).every(e=>e)}else{var l;return(l=s.insertFloatImage())==null?!1:l}}},N={id:`sheet.command.insert-cell-image`,type:t.CommandType.COMMAND,handler:e=>{var n,i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService);return(n=(i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(j).insertCellImage())==null?!1:n}},P={id:`sheet.command.move-drawing`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(n.ISheetDrawingService),o=e.get(s.SheetSkeletonService),{direction:c}=r,l=a.getFocusDrawings();if(l.length===0)return!1;let u=l[0].unitId,d=l.map(e=>{let{transform:r,unitId:i,subUnitId:a}=e,s=o.getSkeleton(i,a);if(!r||!s)return null;let l={...r},{left:u=0,top:d=0}=r;return c===t.Direction.UP?l.top=d-1:c===t.Direction.DOWN?l.top=d+1:c===t.Direction.LEFT?l.left=u-1:c===t.Direction.RIGHT&&(l.left=u+1),{...e,transform:l,sheetTransform:(0,n.transformToDrawingPosition)(l,s),axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(l,s)}}).filter(e=>e!=null);return i.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:u,drawings:d})?(i.syncExecuteCommand(n.ClearSheetDrawingTransformerOperation.id,[u]),!0):!1}},F=function(e){return e.CELL_ADDRESS=`cellAddress`,e.COLUMN_VALUE=`columnValue`,e}({}),I=(0,t.createIdentifier)(`sheets-drawing-ui.batch-save-images.service`);function L(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function R(e,t){return`${L(t)}${e+1}`}function z(e){let t=R(e.startRow,e.startColumn),n=R(e.endRow,e.endColumn);return t===n?t:`${t}:${n}`}function B(e){var t,n;return!!(!(e==null||(t=e.p)==null||(t=t.drawingsOrder)==null)&&t.length&&(e==null||(n=e.p)==null||(n=n.drawingsOrder)==null?void 0:n.length)>0)}function V(e){var t,n;if(!(!((t=e.p)==null||(t=t.drawingsOrder)==null)&&t.length)||!((n=e.p)!=null&&n.drawings))return null;let r=e.p.drawingsOrder[0],i=e.p.drawings[r];return!i||!(`source`in i)||!(`imageSourceType`in i)?null:i}function H(e,n){if(n===t.ImageSourceType.BASE64){let t=e.match(/^data:image\/(\w+);/);if(t)return t[1]===`jpeg`?`jpg`:t[1]}if(n===t.ImageSourceType.URL){let t=e.match(/\.(\w+)(?:\?|$)/);if(t)return t[1].toLowerCase()}return`png`}async function U(e,n){if(n===t.ImageSourceType.BASE64||n===t.ImageSourceType.URL)return(await fetch(e)).blob();throw Error(`UUID image type requires additional handling`)}let W=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._selectionService=t,this._imageIoService=n,this._urlImageService=r}registerURLImageDownloader(e){return this._urlImageService.registerURLImageDownloader(e)}getCellImagesInSelection(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:o}=e.range;for(let e=t;e<=n;e++)for(let t=r;t<=o;t++){let n=i.getValue(e,t);if(B(n)){let r=V(n);r&&a.push({row:e,col:t,cellAddress:R(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return a}getCellImagesFromRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),s=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;for(let e=t;e<=n;e++)for(let t=r;t<=i;t++){let n=o.getValue(e,t);if(B(n)){let r=V(n);r&&s.push({row:e,col:t,cellAddress:R(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return s}getDataColumns(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=i.getDataRange(),o=1/0,s=-1/0,c=new Set;for(let e of r){o=Math.min(o,e.range.startRow),s=Math.max(s,e.range.endRow);for(let t=e.range.startColumn;t<=e.range.endColumn;t++)c.add(t)}let l=new Set;for(let e=a.startColumn;e<=a.endColumn;e++)if(!c.has(e))for(let t=o;t<=s;t++){let n=i.getValue(t,e);if(n){var u,d;if((u=n.v)!=null&&u.toString()||!((d=n.p)==null||(d=d.body)==null||(d=d.dataStream)==null)&&d.trim()){l.add(e);break}}}let f=[],p=Array.from(l).sort((e,t)=>e-t);for(let e of p)f.push({index:e,label:L(e)});return f}getDataColumnsForRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),s=o.getDataRange(),c=1/0,l=-1/0,u=new Set;for(let e of r){c=Math.min(c,e.startRow),l=Math.max(l,e.endRow);for(let t=e.startColumn;t<=e.endColumn;t++)u.add(t)}let d=new Set;for(let e=s.startColumn;e<=s.endColumn;e++)if(!u.has(e))for(let t=c;t<=l;t++){let n=o.getValue(t,e);if(n){var f,p;if((f=n.v)!=null&&f.toString()||!((p=n.p)==null||(p=p.body)==null||(p=p.dataStream)==null)&&p.trim()){d.add(e);break}}}let m=[],h=Array.from(d).sort((e,t)=>e-t);for(let e of h)m.push({index:e,label:L(e)});return m}getSelectionRangeNotation(){let e=this._selectionService.getCurrentSelections();return!e||e.length===0?``:e.map(e=>z(e.range)).join(`, `)}getSelectionRowRange(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return null;let t=1/0,n=-1/0;for(let r of e)t=Math.min(t,r.range.startRow),n=Math.max(n,r.range.endRow);return{startRow:t,endRow:n}}getSelectionColumnIndices(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return new Set;let t=new Set;for(let n of e)for(let e=n.range.startColumn;e<=n.range.endColumn;e++)t.add(e);return t}generateFileName(e,n){let r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),i=H(e.source,e.imageSourceType),a=[];for(let t of n.fileNameParts)if(t===`cellAddress`)a.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=r==null?void 0:r.getActiveSheet();if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var o,s;let e=((o=r.v)==null?void 0:o.toString())||((s=r.p)==null||(s=s.body)==null||(s=s.dataStream)==null?void 0:s.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&a.push(t)}}}}return a.length===0?`${e.cellAddress}.${i}`:`${a.join(`_`)}.${i}`}generateFileNameWithContext(e,n,r,i){let a=this._univerInstanceService.getUnit(r,t.UniverInstanceType.UNIVER_SHEET),o=H(e.source,e.imageSourceType),s=[];for(let t of n.fileNameParts)if(t===`cellAddress`)s.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=a==null?void 0:a.getSheetBySheetId(i);if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var c,l;let e=((c=r.v)==null?void 0:c.toString())||((l=r.p)==null||(l=l.body)==null||(l=l.dataStream)==null?void 0:l.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&s.push(t)}}}}return s.length===0?`${e.cellAddress}.${o}`:`${s.join(`_`)}.${o}`}async saveImages(e,t){let n=await window.showDirectoryPicker({mode:`readwrite`}),r=new Map;for(let a of e){var i;let e=this.generateFileName(a,t),o=e.replace(/\.\w+$/,``),s=((i=e.match(/\.\w+$/))==null?void 0:i[0])||`.png`,c=r.get(o)||0;c>0&&(e=`${o}_${c}${s}`),r.set(o,c+1);try{let t=await this._getImageBlob(a),r=await(await n.getFileHandle(e,{create:!0})).createWritable();await r.write(t),await r.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async saveImagesWithContext(e,t,n,r){let i=await window.showDirectoryPicker({mode:`readwrite`}),a=new Map;for(let s of e){var o;let e=this.generateFileNameWithContext(s,t,n,r),c=e.replace(/\.\w+$/,``),l=((o=e.match(/\.\w+$/))==null?void 0:o[0])||`.png`,u=a.get(c)||0;u>0&&(e=`${c}_${u}${l}`),a.set(c,u+1);try{let t=await this._getImageBlob(s),n=await(await i.getFileHandle(e,{create:!0})).createWritable();await n.write(t),await n.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async downloadSingleImage(e){let t=H(e.source,e.imageSourceType),n=`${e.cellAddress}.${t}`;try{let t=await this._getImageBlob(e),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}catch(e){throw console.error(`Failed to download image ${n}:`,e),e}}async _getImageBlob(e){return e.imageSourceType===t.ImageSourceType.UUID?U(await this._imageIoService.getImage(e.source),t.ImageSourceType.URL):e.imageSourceType===t.ImageSourceType.URL?this._urlImageService.downloadImage(e.source):U(e.source,e.imageSourceType)}};W=O([D(0,t.IUniverInstanceService),D(1,(0,t.Inject)(s.SheetsSelectionsService)),D(2,t.IImageIoService),D(3,t.IURLImageService)],W);let G=`sheet.dialog.batch-save-images`,K={id:`sheet.command.save-cell-images`,type:t.CommandType.COMMAND,handler:async e=>{let n=e.get(l.IDialogService),r=e.get(I),i=r.getCellImagesInSelection();if(i.length===1)try{return await r.downloadSingleImage(i[0]),!0}catch(e){return console.error(`Failed to download image:`,e),!1}let a=e.get(t.LocaleService),o=r.getSelectionRangeNotation(),s=`${a.t(`sheets-drawing-ui.save.title`)} (${o})`;return n.open({id:G,draggable:!0,width:360,title:{title:s},children:{label:G},destroyOnClose:!0,preservePositionOnDestroy:!0,onClose:()=>n.close(G)}),!0}},q=`COMPONENT_SHEET_DRAWING_PANEL`,J={id:`sidebar.operation.sheet-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{let r=e.get(l.ISidebarService),i=e.get(t.LocaleService),a=e.get(t.IUniverInstanceService),c=e.get(t.ICommandService);if(!(0,s.getSheetCommandTarget)(a))return!1;switch(n.value){case`open`:r.open({header:{title:i.t(`sheets-drawing-ui.panel.title`)},children:{label:q},onClose:()=>{c.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])},width:360});break;default:r.close();break}return!0}},Y={id:`sheet.operation.edit-sheet-image`,type:t.CommandType.OPERATION,handler:(e,n)=>{let r=e.get(t.ICommandService);return n==null?!1:(r.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[n]),r.executeCommand(J.id,{value:`open`}),!0)}},X=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],Z=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._sheetDrawingService=r,this._drawingManagerService=i,E(this,`_featurePasteHooks`,[]),E(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:`SHEET_DRAWING_GROUP`,onBeforeCopy:(e,n)=>{this._copyInfo=null;let r=this._focusedDrawings;if(r.length===0)return;let i=r.find(e=>e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP);if(!i)return;let a=this._drawingManagerService.getDrawingsByGroupNested({unitId:i.unitId,subUnitId:i.subUnitId,drawingId:i.drawingId});a&&(this._copyInfo={unitId:i.unitId,subUnitId:i.subUnitId,groupNestedParam:a})},onPasteCells:(e,t,n,r)=>{if(!this._copyInfo)return{redos:[],undos:[]};let{pasteType:i}=r;return X.includes(i)?{redos:[],undos:[]}:this._generateGroupPasteMutations(t)},onPasteUnrecognized:e=>this._copyInfo?this._generateGroupPasteMutations(e):{redos:[],undos:[]}})}registerFeaturePasteHook(e){this._featurePasteHooks.push(e)}_getGroupFeaturePasteMutations(e){let t=[],n=[];for(let r of this._featurePasteHooks){let i=r(e);t.push(...i.redos),n.push(...i.undos)}return{redos:t,undos:n}}_generateGroupPasteMutations(e){var t;if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:r,subUnitId:i,range:a}=e,o=this._sheetSkeletonService.getSkeleton(r,i);if(!o)return{redos:[],undos:[]};let{groupNestedParam:c}=this._copyInfo,l=c.groups[c.groups.length-1],{cloned:u,idMap:d}=y(c),f=u.groups[u.groups.length-1].drawingId,p=(0,s.discreteRangeToRange)(a),m=(0,s.attachRangeWithCoord)(o,{startRow:p.startRow,endRow:p.endRow,startColumn:p.startColumn,endColumn:p.endColumn});if(!m)return{redos:[],undos:[]};let h={...l.transform,left:m.startX,top:m.startY},g=[...((t=u.flatChildren)==null?[]:t).map(e=>({...e,unitId:r,subUnitId:i})),...u.groups.map(e=>{var t,a;return e.drawingId===f?{...e,unitId:r,subUnitId:i,transform:h,sheetTransform:(t=(0,n.transformToDrawingPosition)(h,o))==null?l.sheetTransform:t,axisAlignSheetTransform:(a=(0,n.transformToAxisAlignPosition)(h,o))==null?l.sheetTransform:a}:{...e,unitId:r,subUnitId:i}})],{undo:_,redo:v,objects:b}=this._sheetDrawingService.getBatchAddOp(g),x=[{id:n.SetDrawingApplyMutation.id,params:{op:v,unitId:r,subUnitId:i,objects:b,type:n.DrawingApplyType.INSERT}}],S=[{id:n.SetDrawingApplyMutation.id,params:{op:_,unitId:r,subUnitId:i,objects:b,type:n.DrawingApplyType.REMOVE}}],C=this._getGroupFeaturePasteMutations({fromUnitId:this._copyInfo.unitId,fromSubUnitId:this._copyInfo.subUnitId,toUnitId:r,toSubUnitId:i,idMap:d,cloned:u});return x.push(...C.redos),S.push(...C.undos),{redos:x,undos:S}}dispose(){this._copyInfo=null,this._featurePasteHooks.length=0,super.dispose()}};Z=O([D(0,c.ISheetClipboardService),D(1,r.IRenderManagerService),D(2,(0,t.Inject)(s.SheetSkeletonService)),D(3,n.ISheetDrawingService),D(4,o.IDrawingManagerService)],Z);let ee=Object.freeze({borderEnabled:!1,paintFirst:`stroke`,radius:8,rotateEnabled:!1,strokeWidth:1});var te;let ne=`univer-sheet-float-dom-`;function re(e,t,n){let r=new WeakRef(e),i=!1;return{id:t,dispose(){if(i)return;i=!0;let e=r.deref();e&&n(e,t)}}}let ie={borderEnabled:!0,borderStroke:`#4086f4`,borderStrokeWidth:1,borderSpacing:2,anchorFill:`#ffffff`,anchorStroke:`#4086f4`,anchorStrokeWidth:1.5,anchorSize:8,anchorCornerRadius:2,anchorStyle:`canva`,rotateEnabled:!1,resizeEnabled:!0,moveBoundaryEnabled:!1},ae={borderEnabled:!0,borderStroke:`#4086f4`,borderStrokeWidth:1,borderSpacing:2,anchorFill:`#ffffff`,anchorStroke:`#4086f4`,anchorStrokeWidth:1.5,anchorSize:8,anchorCornerRadius:2,anchorStyle:`canva`,rotateEnabled:!1,resizeEnabled:!0,keepRatio:!1,moveBoundaryEnabled:!1},oe=-100,se=`univer:embed-float-drag-handle:pointerdown`;function ce(e,t){return t.hostAnchorId===e.id&&(t.hostUnitId==null||t.hostUnitId===e.unitId)&&(t.button==null||t.button===0)&&typeof t.clientX==`number`&&typeof t.clientY==`number`}function le(e,t){var n,r;if(!(typeof t.clientX!=`number`||typeof t.clientY!=`number`))return{pointerId:t.pointerId,startClientX:t.clientX,startClientY:t.clientY,startLeft:Number((n=e.rect.left)==null?0:n),startTop:Number((r=e.rect.top)==null?0:r)}}function ue(e,t,n){let{scaleX:r,scaleY:i}=n.getAncestorScale();return{left:e.startLeft+(t.clientX-e.startClientX)/(r||1),top:e.startTop+(t.clientY-e.startClientY)/(i||1)}}function de(e,t){let n=t.data;if(!n||typeof n!=`object`)return;let r=n;r.version!==1||typeof r.embedId!=`string`||(e.transformerConfig={...ie,keepRatio:r.resizeBehavior===`aspect-ratio`})}function fe(e){e.transformerConfig={...e.transformerConfig,...ae}}function pe(e){if(!me(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType===t.UniverInstanceType.UNIVER_SHEET&&n.runtimeMountMode===`stage2`}function me(e){let t=e.data;if(!t||typeof t!=`object`)return!1;let n=t;return n.version===1&&typeof n.embedId==`string`}function he(e){if(!me(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType!=null}function ge(e,t=`inactive`){return{autoMountRuntime:!pe(e),passThroughRuntimeEvents:!(he(e)&&t===`stage2`),preserveOnFocusChange:me(e),usePreviewObject:pe(e)}}function _e(e){return ge(e).autoMountRuntime}function ve(e){return ge(e).preserveOnFocusChange}function ye(e){return ge(e).usePreviewObject}function be(e,t=`inactive`){return ge(e,t).passThroughRuntimeEvents}function xe(e){return me(e)&&!_e(e)}function Se(e,t){var n,r;if(!he(e))return!0;let i=t.target,a=i==null||(n=i.closest)==null?void 0:n.call(i,`[data-embed-float-dom="true"]`);return(a==null||(r=a.dataset)==null?void 0:r.embedFloatStage)!==`stage2`}function Ce(e){return e!==`stage2`}function we(e,t,n){if(t){if(e===`stage1`){var r,i;(r=(i=t.scene).attachTransformerTo)==null||r.call(i,n);return}if(e===`stage2`&&n.oKey){var a,o,s;t.transformer.clearControlByIds([n.oKey]),(a=(o=t.scene).getTransformer)==null||(a=a.call(o))==null||(s=a.clearSelectedObjects)==null||s.call(a)}}}function Te(e,t){return e.domLayers.some(([e])=>e===t)}function Ee(e){return e===t.DrawingTypeEnum.DRAWING_DOM||e===t.DrawingTypeEnum.DRAWING_BLOCK||e===t.DrawingTypeEnum.DRAWING_CHART}function De(e,t){if(e.runtimeMounted||e.runtimeStage!==`stage1`)return!1;let{offsetX:n,offsetY:r}=t;if(typeof n!=`number`||typeof r!=`number`)return!1;let i=e.position$.getValue();if(n>=Math.min(i.startX,i.endX)&&n<=Math.max(i.startX,i.endX)&&r>=Math.min(i.startY,i.endY)&&r<=Math.max(i.startY,i.endY))return!0;let a=e.rect;if(typeof a.isHit==`function`)try{return a.isHit({x:n,y:r})}catch{}return n>=a.left&&n<=a.left+a.width&&r>=a.top&&r<=a.top+a.height}function Oe(e,t){if(!(t.type!==`pointerdown`||!De(e,t)))return{pointerId:t.pointerId,startOffsetX:t.offsetX,startOffsetY:t.offsetY,startedAt:Date.now()}}function ke(e,t,n){return!t||n.type!==`pointerup`||t.pointerId!=null&&n.pointerId!=null&&t.pointerId!==n.pointerId||!De(e,n)?!1:Math.hypot(n.offsetX-t.startOffsetX,n.offsetY-t.startOffsetY)<=4}function Ae(e,n,i,a,o,s=!1){let{scaleX:c,scaleY:l}=n.getAncestorScale(),u=n.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN),{startColumn:d,startRow:f,xSplit:p,ySplit:m}=a.getFreeze(),h={left:!0,top:!0};if(!u)return{...e,absolute:h};let{left:g,right:_,top:v,bottom:y}=e,{top:b,left:x,viewportScrollX:S,viewportScrollY:C}=u,{boundsOfViewArea:w,scrollDirectionResponse:T}=o||{},{rowHeaderWidth:E,columnHeaderHeight:D}=i,O={top:s?0:D,left:s?0:E};w&&(t.Tools.isDefine(O.top)&&(O.top=w.top),t.Tools.isDefine(O.left)&&(O.left=w.left)),T===`HORIZONTAL`&&(C=0),T===`VERTICAL`&&(S=0);let k=0,A=0,j=i.rowStartY(f-m)+D,M=i.colStartX(d-p)+E,N=i.rowStartY(f)+D,P=i.colStartX(d)+E;if(p===0)h.left=!1,k=(g-S)*c,A=(_-S)*c;else{let e=g-(M-E),t=_-(M-E);_<P?(k=e*c,A=t*c):g<=P&&_>=P?(k=e*c,A=Math.max(x,(_-S)*c)):g>P&&(h.left=!1,k=Math.max((g-S)*c,x),A=Math.max((_-S)*c,x))}let F=0,I=0;if(m===0)h.top=!1,F=(v-C)*l,I=(y-C)*l;else{let e=v-(j-D),t=y-(j-D);y<N?(F=e*l,I=t*l):v<=N&&y>=N?(F=e*l,I=Math.max(b,(y-C)*l)):v>N&&(h.top=!1,F=Math.max((v-C)*l,b),I=Math.max((y-C)*l,b))}return k=Math.max(k,O.left),F=Math.max(F,O.top),A=Math.max(A,O.left),I=Math.max(I,O.top),{left:k,right:A,top:F,bottom:I,absolute:h}}let Q=(e,t,n,r,i)=>{let{left:a,top:o,width:s,height:c,angle:l}=e,u=Ae({left:a,right:a+s,top:o,bottom:o+c},t,n,r,i),{scaleX:d,scaleY:f}=t.getAncestorScale();return{startX:u.left,endX:u.right,startY:u.top,endY:u.bottom,rotate:l,width:s*d,height:c*f,absolute:u.absolute}},$=te=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=r,this._canvasFloatDomService=i,this._sheetDrawingService=a,this._lifecycleService=o,this._canvasFloatDomPreviewService=s,E(this,`_domLayerInfoMap`,new Map),E(this,`_transformChange$`,new d.Subject),E(this,`transformChange$`,this._transformChange$.asObservable()),E(this,`_add$`,new d.Subject),E(this,`add$`,this._add$.asObservable()),E(this,`_remove$`,new d.Subject),E(this,`remove$`,this._remove$.asObservable()),E(this,`_renderObjectFactories`,new Map),this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent(),this._bindEmbedFloatDragHandleEvent()}registerRenderObjectFactory(e,t){var n;let r=(n=this._renderObjectFactories.get(e))==null?[]:n;return r.push(t),this._renderObjectFactories.set(e,r),{dispose:()=>{let n=this._renderObjectFactories.get(e);if(!n)return;let r=n.indexOf(t);r>=0&&n.splice(r,1),n.length===0&&this._renderObjectFactories.delete(e)}}}_createRenderObject(e){var t;let n=this._renderObjectFactories.get(e.drawingType),i=n==null?void 0:n[n.length-1];return(t=i==null?void 0:i(e))==null?new r.Rect(e.key,e.config):t}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe((0,d.filter)(e=>e===t.LifecycleStages.Rendered),(0,d.take)(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(e){return this._domLayerInfoMap.get(e)}getFloatDomsBySubUnitId(e,t){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===t&&n.unitId===e)}static _disposeExternalFloatDom(e,t){e._removeDom(t,!0)}_createFloatDomDisposable(e){return re(this,e,te._disposeExternalFloatDom)}_bindEmbedFloatDragHandleEvent(){if(typeof document>`u`)return;let e=e=>this._handleEmbedFloatDragHandlePointerDown(e);document.addEventListener(se,e),this.disposeWithMe(()=>document.removeEventListener(se,e))}_handleEmbedFloatDragHandlePointerDown(e){let t=e.detail;if(!(t!=null&&t.hostAnchorId))return;let n=this._domLayerInfoMap.get(t.hostAnchorId);if(!n||!ce(n,t))return;let r=le(n,t),i=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(!r||!i)return;let{scene:a,transformer:o}=i;if(n.rect.oKey){var s;o.clearControlByIds([n.rect.oKey]),(s=a.getTransformer())==null||s.clearSelectedObjects()}let c=e=>{if(r.pointerId!=null&&e.pointerId!==r.pointerId)return;e.preventDefault();let t=ue(r,e,a);n.rect.transformByState(t)},l=e=>{if(!(r.pointerId!=null&&e.pointerId!==r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),e.preventDefault(),(n.rect.left!==r.startLeft||n.rect.top!==r.startTop)&&this._commitFloatDomMove(n),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}},u=e=>{if(!(r.pointerId!=null&&e.pointerId!==r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),n.rect.transformByState({left:r.startLeft,top:r.startTop}),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}};window.addEventListener(`pointermove`,c,!0),window.addEventListener(`pointerup`,l,!0),window.addEventListener(`pointercancel`,u,!0)}_commitFloatDomMove(e){var t;let r=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(c.SheetSkeletonManagerService).getSkeletonParam(e.subUnitId),i=this._sheetDrawingService.getDrawingByParam({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.id});if(!r||!(i!=null&&i.transform))return;let a={...i.transform,left:e.rect.left,top:e.rect.top,width:e.rect.width,height:e.rect.height,angle:e.rect.angle,flipX:e.rect.flipX,flipY:e.rect.flipY,skewX:e.rect.skewX,skewY:e.rect.skewY},o=(0,n.transformToDrawingPosition)(a,r.skeleton),s=(0,n.transformToAxisAlignPosition)(a,r.skeleton);!o||!s||this._commandService.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:e.unitId,drawings:[{...i,transform:a,sheetTransform:o,axisAlignSheetTransform:s}]})}isFloatDomRuntimeMounted(e){var t;return((t=this._domLayerInfoMap.get(e))==null?void 0:t.runtimeMounted)===!0}_getFloatDomPreviewObjectKey(e){return`${e}__preview`}_syncPreviewObjectTransform(e,t){e==null||e.transformByState({left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY})}_requestFloatDomPreview(e,t,n){this._canvasFloatDomPreviewService&&this._canvasFloatDomPreviewService.requestPreview({id:e,width:t.width,height:t.height,data:n})}_upsertFloatDomPreviewObject(e,t,n,i,a){var o;let s=(o=this._canvasFloatDomPreviewService)==null?void 0:o.getPreview(i);if(!(s!=null&&s.image)){this._requestFloatDomPreview(i,t,a);return}let c=this._getFloatDomPreviewObjectKey(n),l=e.getObject(c);if(l instanceof r.Image)return l.changeSource(s.image),this._syncPreviewObjectTransform(l,t),l;let u=new r.Image(c,{left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY,url:s.image,evented:!1,rotateEnabled:!1,resizeEnabled:!1});return e.addObject(u,r.DRAWING_OBJECT_LAYER_INDEX),u}mountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);return t!=null&&t.floatDomConfig?t.runtimeMounted?!0:(Te(this._canvasFloatDomService,e)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}):this._canvasFloatDomService.addFloatDom({...t.floatDomConfig,eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}),t.runtimeMounted=!0,t.runtimeStage=`stage2`,!0):!1}unmountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);t!=null&&t.runtimeMounted&&(t.floatDomConfig&&!_e(t.floatDomConfig)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`inactive`),props:t.floatDomConfig.props}):this._canvasFloatDomService.removeFloatDom(e),t.runtimeMounted=!1,t.runtimeStage=`inactive`)}_syncFloatDomVisibilityForActiveSheet(e,t){Array.from(this._domLayerInfoMap.values()).filter(t=>t.unitId===e&&t.floatDomConfig).forEach(e=>{let n=e.subUnitId===t,r=Te(this._canvasFloatDomService,e.id);if(!n){r&&this._canvasFloatDomService.removeFloatDom(e.id),e.runtimeMounted=!1,e.runtimeStage=`inactive`;return}if(r||!e.floatDomConfig)return;this._canvasFloatDomService.addFloatDom(e.floatDomConfig);let i=_e(e.floatDomConfig);e.runtimeMounted=i,e.runtimeStage=me(e.floatDomConfig)?`inactive`:i?`stage2`:`inactive`})}promoteFloatDomRuntimeStage(e){let t=this._domLayerInfoMap.get(e);if(!(t!=null&&t.floatDomConfig))return;let n=he(t.floatDomConfig);return t.runtimeMounted&&!n?(t.runtimeStage=`stage2`,`stage2`):t.runtimeStage===`stage1`?t.runtimeMounted?(t.runtimeStage=`stage2`,xe(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`stage2`)}),`stage2`):(this.mountFloatDomRuntime(e),`stage2`):(t.runtimeStage=`stage1`,xe(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:be(t.floatDomConfig,`stage1`)}),`stage1`)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return t==null||n==null?null:{scene:n,transformer:n.getTransformerByCreate(),renderUnit:t,canvas:t.engine.getCanvasElement()}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(e=>{var n;let{unitId:i,subUnitId:a,drawingId:l}=e,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:i,subUnitId:a}),p=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(n=this._renderManagerService.getRenderById(i))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!g)return;let{transform:_,drawingType:v,data:y,hidden:b,groupId:x}=p;if(!Ee(v))return;let S=this._getSceneAndTransformerByDrawingSearch(i);if(S==null||b)return;let{scene:C,canvas:w}=S;if(_==null)return!0;if(h!==a)return;let{left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}=_,P=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:l}),F=x?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:x}):void 0,I=this._getObjectIncludingGroup(C,P,F);if(I!=null&&(this._removeTopLevelDuplicateIfGrouped(C,P,I),de(I,p),v===t.DrawingTypeEnum.DRAWING_CHART&&fe(I),I.transformByState({left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}),this._syncFloatDomRect(l,I),ye(p)&&(this._syncPreviewObjectTransform(C.getObject(this._getFloatDomPreviewObjectKey(P)),I),this._requestFloatDomPreview(l,I,y)),this._domLayerInfoMap.has(l)))return;let L={left:T,top:E,width:D,height:O,zIndex:this._drawingManagerService.getDrawingOrder(i,a).length-1},R=v===t.DrawingTypeEnum.DRAWING_CHART;if(R){let e=this._getChartDataBackground(y);e!==void 0&&(L.fill=e),y&&y.border&&(L.stroke=y.border),Object.assign(L,ee)}else L.rotateEnabled=!1;let z=I==null?this._createRenderObject({key:P,config:L,unitId:i,subUnitId:a,drawingId:l,drawingType:v,data:y}):I;de(z,p),R&&fe(z),R?z.objectType=r.ObjectType.CHART:(v===t.DrawingTypeEnum.DRAWING_DOM||v===t.DrawingTypeEnum.DRAWING_BLOCK)&&(z.objectType=r.ObjectType.DRAWING_DOM),I||C.addObject(z,r.DRAWING_OBJECT_LAYER_INDEX),!I&&p.allowTransform!==!1&&C.attachTransformerTo(z),!I&&R&&x&&(0,u.insertGroupObject)({drawingId:x,unitId:i,subUnitId:a},z,C,this._drawingManagerService);let B=new t.DisposableCollection,V=ye(p),H=V?this._getFloatDomPreviewObjectKey(P):void 0;if(V){var U;this._upsertFloatDomPreviewObject(C,z,P,l,y);let e=(U=this._canvasFloatDomPreviewService)==null?void 0:U.previewUpdated$.subscribe(e=>{e.id===l&&this._upsertFloatDomPreviewObject(C,z,P,l,y)});e&&B.add(e)}let W=new d.BehaviorSubject(Q(z,S.renderUnit.scene,g.skeleton,f.worksheet)),G=`${ne}${(0,t.generateRandomId)(6)}`,K=_e(p),q=me(p),J,Y={position$:W,id:l,domId:G,componentKey:p.componentKey,eventPassThrough:be(p,`inactive`),preserveOnFocusChange:ve(p),onPointerDown:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{Se(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onWheel:e=>{Se(p,e)&&w.dispatchEvent(new WheelEvent(e.type,e))},data:y,props:q?{onRuntimeStageEnter:e=>{J&&(J.runtimeStage=e,J.runtimeMounted=K||e===`stage2`,xe(p)&&this._canvasFloatDomService.updateFloatDom(l,{eventPassThrough:be(p,e)})),we(e,this._getSceneAndTransformerByDrawingSearch(i),z)}}:void 0,unitId:i};if(J={dispose:B,rect:z,position$:W,unitId:i,subUnitId:a,id:l,domId:G,floatDomConfig:Y,runtimeMounted:K,runtimeStage:q?`inactive`:K?`stage2`:`inactive`,previewObjectKey:H},this._canvasFloatDomService.addFloatDom(Y),!K){let e,t=t=>{if(e&&!(e.pointerId!=null&&t.pointerId!=null&&e.pointerId!==t.pointerId)){if(typeof t.offsetX!=`number`||typeof t.offsetY!=`number`){e=void 0;return}Math.hypot(t.offsetX-e.startOffsetX,t.offsetY-e.startOffsetY)>4&&(e=void 0)}},n=z.onPointerDown$.subscribeEvent({priority:oe,next:([t,n])=>{if((J==null?void 0:J.runtimeStage)===`stage1`){e=Oe(J,t);return}let r=this.promoteFloatDomRuntimeStage(l);r===`stage2`&&(we(r,S,z),n.skipNextObservers=!0),Ce(r)||n.stopPropagation()}}),r=C.onPointerDown$.subscribeEvent({priority:oe,next:([t])=>{J&&(e=Oe(J,t))}}),i=C.onPointerMove$.subscribeEvent({priority:oe,next:([e])=>{t(e)}}),a=C.onPointerUp$.subscribeEvent({priority:oe,next:([t,n])=>{let r=J&&ke(J,e,t);if(e=void 0,!r)return;let i=this.promoteFloatDomRuntimeStage(l);i===`stage2`&&(we(i,S,z),n.stopPropagation(),n.skipNextObservers=!0)}});B.add(n),B.add(r),B.add(i),B.add(a)}let X=z.onTransformChange$.subscribeEvent(()=>{let e=Q(z,S.renderUnit.scene,g.skeleton,f.worksheet);W.next(e),H&&this._syncPreviewObjectTransform(C.getObject(H),z)});B.add(()=>{this._canvasFloatDomService.removeFloatDom(l),H&&C.removeObject(H)}),X&&B.add(X),this._domLayerInfoMap.set(l,J)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{transformer:s,scene:c}=a,l=this._getObjectIncludingGroup(c,i);if(l!=null&&l.oKey){var u;s.clearControlByIds([l==null?void 0:l.oKey]),(u=c.getTransformer())==null||u.clearSelectedObjects()}})}))}_scrollUpdateListener(){let e=(e,t)=>{var n;let r=this._getSceneAndTransformerByDrawingSearch(e),i=Array.from(this._domLayerInfoMap.keys()).map(e=>({id:e,...this._domLayerInfoMap.get(e)})).filter(n=>n.subUnitId===t&&n.unitId===e).map(e=>e.id),a=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:t}),o=(n=this._renderManagerService.getRenderById(e))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(t);!r||!a||!o||i.forEach(e=>{let t=this._domLayerInfoMap.get(e);if(t){let e=Q(t.rect,r.renderUnit.scene,o.skeleton,a.worksheet,t);t.position$.next(e)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?e.activeSheet$:(0,d.of)(null))).subscribe(t=>{if(!t)return;let n=t.getUnitId(),r=t.getSheetId();this._syncFloatDomVisibilityForActiveSheet(n,r),e(n,r)})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?e.activeSheet$:(0,d.of)(null)),(0,d.map)(e=>{if(!e)return null;let t=e.getUnitId(),n=this._renderManagerService.getRenderById(t);return n?{render:n,unitId:t,subUnitId:e.getSheetId()}:null}),(0,d.switchMap)(e=>e?(0,t.fromEventSubject)(e.render.scene.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe((0,d.map)(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):(0,d.of)(null))).subscribe(t=>{if(!t)return;let{unitId:n,subUnitId:r}=t;e(n,r)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===c.SetZoomRatioOperation.id){let{unitId:n}=t.params;Array.from(this._domLayerInfoMap.values()).filter(e=>e.unitId===n).map(e=>e.subUnitId).forEach(t=>{e(n,t)})}else if(t.id===s.SetFrozenMutation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}else if(t.id===s.SetSelectionsOperation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}}))}updateFloatDomProps(e,t,n,i){let a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(e);if(a&&s){let{scene:a}=s,c=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),l=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),u=l!=null&&l.groupId?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:l.groupId}):void 0,d=this._getObjectIncludingGroup(a,c,u);d&&d instanceof r.Rect&&(this._removeTopLevelDuplicateIfGrouped(a,c,d),d.setProps(i),this._syncFloatDomRect(n,d))}}_getObjectIncludingGroup(e,t,n){var r,i,a,o;return(r=(i=(a=this._getChildObjectFromGroup(e,t,n))==null?(o=e.getObjectIncludeInGroup)==null?void 0:o.call(e,t):a)==null?e.getObject(t):i)==null?null:r}_getChildObjectFromGroup(e,t,n){var r,i;if(!n)return null;let a=(r=(i=e.getObjectIncludeInGroup)==null?void 0:i.call(e,n))==null?e.getObject(n):r;return this._findChildObject(a,t)}_findChildObject(e,t){if(!e)return null;let n=e.getObjects();for(let e of n){if(e.oKey===t)return e;let n=this._findChildObject(e,t);if(n)return n}return null}_removeTopLevelDuplicateIfGrouped(e,t,n){if(!n.isInGroup)return;let r=e.getObject(t);r&&r!==n&&e.removeObject(r)}_syncFloatDomRect(e,t){if(!(t instanceof r.Rect))return;let n=this._domLayerInfoMap.get(e);n&&(n.rect=t)}_getChartDataBackground(e){var t;if(!e||typeof e!=`object`||Array.isArray(e))return;let n=e,r=(t=n.backgroundColor)==null?n.background:t;return typeof r==`string`?r:void 0}_getPosition(e,t){var n;let{startX:r,endX:i,startY:a,endY:o}=e,s=(n=this._renderManagerService.getRenderById(t))==null?void 0:n.with(c.ISheetSelectionRenderService);if(s==null)return;let l=s.getCellWithCoordByOffset(r,a);if(l==null)return;let u={column:l.actualColumn,columnOffset:r-l.startX,row:l.actualRow,rowOffset:a-l.startY},d=s.getCellWithCoordByOffset(i,o);if(d!=null)return{from:u,to:{column:d.actualColumn,columnOffset:i-d.startX,row:d.actualRow,rowOffset:o-d.startY}}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let n=this._drawingManagerService.getDrawingByParam(e);if(!n||!Ee(n.drawingType))return;if(n.hidden){this._removeDom(e.drawingId);return}if(!this._domLayerInfoMap.has(e.drawingId)){this._drawingManagerService.addNotification([e]);return}let r={...n.transform};this._transformChange$.next({id:e.drawingId,value:r}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});let i=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(i&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART){let{scene:t}=i,r=this._domLayerInfoMap.get(e.drawingId);r!=null&&r.rect&&(n.allowTransform===!1?t.detachTransformerFrom(r.rect):t.attachTransformerTo(r.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(e,r){let i=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!i)throw Error(`cannot find current target!`);let{unitId:a,subUnitId:o}=i,{initPosition:c,componentKey:l,data:u,allowTransform:d=!0}=e,f=r==null?(0,t.generateRandomId)():r,p=this._getPosition(c,a);if(p==null)return;let m={unitId:a,subUnitId:o,drawingId:f,drawingType:e.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},axisAlignSheetTransform:p,data:u,allowTransform:d};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[m]}),this._add$.next({unitId:a,subUnitId:o,id:f}),this._createFloatDomDisposable(f)}_removeDom(e,t=!1){let r=this._domLayerInfoMap.get(e);if(!r)return;let{unitId:i,subUnitId:a}=r;this._domLayerInfoMap.delete(e),r.dispose.dispose();let o=this._getSceneAndTransformerByDrawingSearch(i);if(o){let{scene:t,transformer:n}=o;if((0,u.disposeDrawingRenderObject)(t,{unitId:i,subUnitId:a,drawingId:e})){var s;n.clearControlByIds([r.rect.oKey]),(s=t.getTransformer())==null||s.clearSelectedObjects()}}if(t){let t=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:e});if(!t)return;let{redo:r,objects:o}=this._sheetDrawingService.getBatchRemoveOp([t]);this._commandService.syncExecuteCommand(n.SetDrawingApplyMutation.id,{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE})}}removeFloatDom(e,t=!0){this._removeDom(e,t)}addFloatDomToRange(e,n,i,a){var l;let f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!f)throw Error(`cannot find current target!`);let{unitId:p,subUnitId:m}=f,h=this._getSceneAndTransformerByDrawingSearch(p);if(!h)return;let g=this._renderManagerService.getRenderById(p);if(!g)return;let _=(l=this._renderManagerService.getRenderById(p))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(m);if(!_)return;let{componentKey:v,data:y,allowTransform:b=!0}=n,x=a==null?(0,t.generateRandomId)():a,{position:S,position$:C}=this._createRangePositionObserver(e,g,_.skeleton),w=this._getPosition(S,p);if(w==null)return;let{scaleX:T}=h.scene.getAncestorScale(),E=Me(S,i,T),D={unitId:p,subUnitId:m,drawingId:x,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:v,sheetTransform:w,axisAlignSheetTransform:w,transform:{left:E.startX,top:E.startY,width:E.width,height:E.height},data:y,allowTransform:b};{var O,k;let{unitId:e,subUnitId:a,drawingId:l}=D,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),p=D,m=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(O=this._renderManagerService.getRenderById(e))==null?void 0:O.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,drawingType:y,data:b,groupId:w}=p;if(!Ee(y))return;let T=this._getSceneAndTransformerByDrawingSearch(e);if(T==null)return;let{scene:E,canvas:A}=T;if(v==null||h!==a)return;let{left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:R,skewY:z}=v,B=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),V=w?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:w}):void 0,H=this._getObjectIncludingGroup(E,B,V);if(H!=null){this._removeTopLevelDuplicateIfGrouped(E,B,H),y===t.DrawingTypeEnum.DRAWING_CHART&&fe(H),H.transformByState({left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:R,skewY:z}),this._syncFloatDomRect(l,H);return}let U={left:j,top:M,width:N,height:P,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1},W=y===t.DrawingTypeEnum.DRAWING_CHART;if(W){let e=this._getChartDataBackground(b);e!==void 0&&(U.fill=e),U.rotateEnabled=!1,b&&b.border&&(U.stroke=b.border),U.paintFirst=`stroke`,U.strokeWidth=1,U.radius=8}let G=this._createRenderObject({key:B,config:U,unitId:e,subUnitId:a,drawingId:l,drawingType:y,data:b});W&&(G.setObjectType(r.ObjectType.CHART),fe(G)),E.addObject(G,r.DRAWING_OBJECT_LAYER_INDEX),p.allowTransform!==!1&&E.attachTransformerTo(G),W&&w&&(0,u.insertGroupObject)({drawingId:w,unitId:e,subUnitId:a},G,E,this._drawingManagerService);let K=new t.DisposableCollection,q=E.getMainViewport(),{rowHeaderWidth:J,columnHeaderHeight:Y}=_.skeleton,X={dispose:K,rect:G,boundsOfViewArea:{top:Y,left:J,bottom:q.bottom,right:q.right},domAnchor:i,unitId:e,subUnitId:a,id:l},Z=new d.BehaviorSubject(Q(G,T.renderUnit.scene,_.skeleton,f.worksheet,X));X.position$=Z;let ee={position$:Z,id:l,componentKey:p.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{A.dispatchEvent(new WheelEvent(e.type,e))},data:b,unitId:e};n.eventPassThrough&&(ee={...ee,onPointerDown:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{A.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(ee),this.disposeWithMe(C.subscribe(t=>{var n,s,c,u;let d=Me({rotate:0,startX:t.startX,startY:t.startY,endX:t.endX,endY:t.endY,width:(n=i.width)==null?t.width:n,height:(s=i.height)==null?t.height:s,absolute:{left:S.absolute.left,top:S.absolute.top}},i),p=Q(new r.Rect((0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),{left:d.startX,top:d.startY,width:(c=i.width)==null?t.width:c,height:(u=i.height)==null?t.height:u,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),T.renderUnit.scene,_.skeleton,f.worksheet,X);Z.next(p)}));let te=(k=this._renderManagerService.getRenderById(e))==null?void 0:k.with(c.SheetSkeletonManagerService),ne=te==null?void 0:te.currentSkeleton$.subscribe(e=>{e&&_.sheetId!==e.sheetId&&this._removeDom(x,!0)});ne&&K.add(ne);let re=G.onTransformChange$.subscribeEvent(()=>{let e=Q(G,T.renderUnit.scene,_.skeleton,f.worksheet,X);Z.next(e)});K.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),re&&K.add(re),this._domLayerInfoMap.set(l,X)}return this._createFloatDomDisposable(x)}addFloatDomToColumnHeader(e,n,i,a){var l;let u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!u)throw Error(`cannot find current target!`);let{unitId:f,subUnitId:p}=u;if(!this._getSceneAndTransformerByDrawingSearch(f))return;let m=this._renderManagerService.getRenderById(f);if(!m)return;let h=(l=this._renderManagerService.getRenderById(f))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(p);if(!h)return;let{componentKey:g,data:_,allowTransform:v=!0}=n,y=a==null?(0,t.generateRandomId)():a,{position:b,position$:x}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},m,h.skeleton),S=b;S.startY=0;let C=this._getPosition(b,f);if(C==null)return;let w={unitId:f,subUnitId:p,drawingId:y,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:C,axisAlignSheetTransform:C,transform:{left:S.startX,top:S.startY,width:S.width,height:S.height},data:_,allowTransform:v};{var T,E;let{unitId:e,subUnitId:a,drawingId:l}=w,u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),f=w,p=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!p)return;let m=p.getActiveSheet().getSheetId();if(!f||!u)return;let g=(T=this._renderManagerService.getRenderById(e))==null?void 0:T.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,data:C}=f,D=this._getSceneAndTransformerByDrawingSearch(e);if(D==null)return;let{scene:O,canvas:k}=D;if(v==null||m!==a)return;let{left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:R}=v,z=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),B=this._getObjectIncludingGroup(O,z);if(B!=null){this._removeTopLevelDuplicateIfGrouped(O,z,B),B.transformByState({left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:R}),this._syncFloatDomRect(l,B);return}let V=Me({rotate:0,startX:S.startX,startY:0,endX:b.endX,endY:b.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),H=new r.Rect(z,{left:V.startX,top:V.startY,width:V.width,height:V.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1});O.addObject(H,r.DRAWING_OBJECT_LAYER_INDEX),f.allowTransform!==!1&&O.attachTransformerTo(H);let U=new t.DisposableCollection,W=O.getMainViewport(),G={dispose:U,rect:H,unitId:e,subUnitId:a,id:l,boundsOfViewArea:{top:0,left:W.left,bottom:W.bottom,right:W.right},domAnchor:i,scrollDirectionResponse:`HORIZONTAL`},K=new d.BehaviorSubject(Q(H,D.renderUnit.scene,_.skeleton,u.worksheet,G));G.position$=K;let q={position$:K,id:l,componentKey:f.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{k.dispatchEvent(new WheelEvent(e.type,e))},data:C,unitId:e};n.eventPassThrough&&(q={...q,onPointerDown:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{k.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(q);let J=H.onTransformChange$.subscribeEvent(()=>{let e=Q(H,D.renderUnit.scene,_.skeleton,u.worksheet,G);K.next(e)});this.disposeWithMe(x.subscribe(t=>{let n=Me({rotate:0,startX:t.startX,startY:0,endX:t.endX,endY:t.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),s=Q(new r.Rect((0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),{left:n.startX,top:0,width:i.width,height:i.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),D.renderUnit.scene,_.skeleton,u.worksheet,G);K.next(s)}));let Y=(E=this._renderManagerService.getRenderById(e))==null?void 0:E.with(c.SheetSkeletonManagerService);Y==null||Y.currentSkeleton$.subscribe(e=>{e&&h.sheetId!==e.sheetId&&this._removeDom(y,!0)}),U.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),J&&U.add(J),this._domLayerInfoMap.set(l,G)}return this._createFloatDomDisposable(y)}_createRangePositionObserver(e,n,r){let{startRow:i,startColumn:a}=e,o=je(i,a,r),l=new d.BehaviorSubject(o),u=je(e.endRow,e.endColumn,r),f=new d.BehaviorSubject(u),p=()=>{let t=je(i,a,r),n=je(e.endRow,e.endColumn,r);l.next(t),f.next(n)},m=new t.DisposableCollection;return m.add(n.engine.clientRect$.subscribe({next:()=>p(),error:()=>{}})),m.add(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetRowAutoHeightMutation.id&&e.params.rowsAutoHeightInfo.findIndex(e=>e.row===i)>-1){p();return}(s.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(e.id)>-1||e.id===c.SetScrollOperation.id||e.id===c.SetZoomRatioOperation.id)&&p()})),{position$:l.pipe((0,d.map)(t=>{let n=je(e.endRow,e.endColumn,r);return{rotate:0,width:n.right-t.left,height:n.bottom-t.top,absolute:{left:!0,top:!0},startX:t.left,startY:t.top,endX:n.right,endY:n.bottom}})),position:{rotate:0,width:u.right-o.left,height:u.bottom-o.top,absolute:{left:!0,top:!0},startX:o.left,startY:o.top,endX:u.right,endY:u.bottom},updateRowCol:(e,t)=>{i=e,a=t,p()},topLeftPos$:l,rightBottomPos$:f,disposable:m}}};$=te=O([D(0,(0,t.Inject)(r.IRenderManagerService)),D(1,t.IUniverInstanceService),D(2,(0,t.Inject)(t.ICommandService)),D(3,o.IDrawingManagerService),D(4,(0,t.Inject)(l.CanvasFloatDomService)),D(5,n.ISheetDrawingService),D(6,(0,t.Inject)(t.LifecycleService)),D(7,(0,t.Optional)(l.CanvasFloatDomPreviewService))],$);function je(e,t,n){let r=n.getCellWithCoordByIndex(e,t),i=r.isMergedMainCell?r.mergeInfo:r;return{left:i.startX,right:i.endX,top:i.startY,bottom:i.endY}}function Me(e,t,n){var r,i,a;n=(r=n)==null?1:r;let o=e.endX-e.startX,s=e.endY-e.startY,c=(i=t==null?void 0:t.width)==null?o:i,l=(a=t==null?void 0:t.height)==null?s:a,u=0,d=0;if(t){if(t.horizonOffsetAlign===`right`){let r=Ne(t.marginX,o*n);u=e.endX-r-c}else u=e.startX+Ne(t.marginX,o);if(t.verticalOffsetAlign===`bottom`){let r=Ne(t.marginY,s*n);d=e.endY-r-l}else d=e.startY+Ne(t.marginY,s)}return{rotate:0,startX:u,startY:d,endX:e.endX,endY:e.endY,width:c,height:l,absolute:{left:e.absolute.left,top:e.absolute.top}}}function Ne(e,t){return e===void 0?0:typeof e==`number`?e:t*Number.parseFloat(e)/100}let Pe=[[$]];function Fe(e){e.has($)||(0,t.registerDependencies)(e,Pe),Le(e)}function Ie(e){(0,t.touchDependencies)(e,[[$]])}function Le(e){if(!e.has(t.LifecycleService)){Ie(e);return}let n=e.get(t.LifecycleService);if(n.stage>=t.LifecycleStages.Ready){Ie(e);return}n.onStage(t.LifecycleStages.Ready).then(()=>{Ie(e)})}let Re=`sheet.menu.image`;function ze(e){return{id:Re,type:l.MenuItemType.SUBITEMS,icon:`AddImageIcon`,tooltip:`sheets-drawing-ui.title`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission],rangeTypes:[s.RangeProtectionPermissionEditPoint]})}}function Be(e){return{id:M.id,title:`sheets-drawing-ui.upload.float`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function Ve(e){return{id:N.id,title:`sheets-drawing-ui.upload.cell`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function He(e){var t,n;return!!(!(e==null||(t=e.p)==null||(t=t.drawingsOrder)==null)&&t.length&&(e==null||(n=e.p)==null||(n=n.drawingsOrder)==null?void 0:n.length)>0)}function Ue(e,t){let n=e.getActiveSheet();if(!n)return!1;let r=n.getCellMatrix(),{startRow:i,endRow:a,startColumn:o,endColumn:s}=t;for(let e=i;e<=a;e++)for(let t=o;t<=s;t++)if(He(r.getValue(e,t)))return!0;return!1}function We(){return`showDirectoryPicker`in window}function Ge(e){let n=e.get(t.IUniverInstanceService),r=e.get(s.SheetsSelectionsService),i=(0,d.combineLatest)([(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),n.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?r.selectionMoveEnd$.pipe((0,d.map)(()=>{if(!We())return!0;let t=r.getCurrentSelections();if(!t||t.length===0)return!0;for(let n of t)if(Ue(e,n.range))return!1;return!0})):(0,d.of)(!0)))]).pipe((0,d.map)(([e,t])=>e||t));return{id:K.id,type:l.MenuItemType.BUTTON,icon:`DownloadImageIcon`,title:`sheets-drawing-ui.save.menuLabel`,hidden$:i}}let Ke={[l.RibbonInsertGroup.MEDIA]:{[Re]:{order:0,menuItemFactory:ze,[M.id]:{order:0,menuItemFactory:Be},[N.id]:{order:1,menuItemFactory:Ve}}},[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{[K.id]:{order:10,menuItemFactory:Ge}}},[l.ContextMenuPosition.COL_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[K.id]:{order:10,menuItemFactory:Ge}}},[l.ContextMenuPosition.ROW_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[K.id]:{order:10,menuItemFactory:Ge}}}};var qe=`@univerjs/sheets-drawing-ui`,Je=`1.0.0-alpha.4`;let Ye={};function Xe(){let e=(0,l.useDependency)(t.LocaleService),n=(0,l.useDependency)(l.IDialogService),r=(0,l.useDependency)(I),[a,o]=(0,p.useState)([`cellAddress`]),[s,u]=(0,p.useState)(!1),[d,f]=(0,p.useState)(null),h=(0,p.useMemo)(()=>r.getCellImagesInSelection(),[r]),g=(0,p.useMemo)(()=>r.getDataColumns(),[r]),_=(0,p.useMemo)(()=>r.getSelectionRowRange(),[r]),v=g.length>0,y=(0,p.useMemo)(()=>g.map(e=>({label:e.label,value:String(e.index)})),[g]),[b,x]=(0,p.useState)(()=>y.length>0?y[0].value:`0`);(0,c.useHighlightRange)((0,p.useMemo)(()=>{if(!a.includes(`columnValue`)||!_)return[];let e=Number(b);return[{startRow:_.startRow,endRow:_.endRow,startColumn:e,endColumn:e}]},[a,b,_]));let S=(0,p.useCallback)(e=>{e.length!==0&&o(e)},[]),C=(0,p.useCallback)(e=>{x(String(e))},[]),w=(0,p.useCallback)(()=>{n.close(G)},[n]),T=(0,p.useCallback)(async()=>{if(h.length!==0){u(!0),f(null);try{await r.saveImages(h,{fileNameParts:a,columnIndex:a.includes(`columnValue`)?Number(b):void 0}),n.close(G)}catch(t){console.error(`Failed to save images:`,t),f(e.t(`sheets-drawing-ui.save.error`))}finally{u(!1)}}},[r,h,a,b,n,e]),E=a.includes(`columnValue`);return(0,m.jsxs)(`div`,{className:`univer-flex univer-flex-col`,children:[(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.imageCount`),children:(0,m.jsx)(`div`,{className:`univer-text-sm univer-text-gray-600`,children:h.length})}),(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.fileNameConfig`),children:(0,m.jsxs)(i.CheckboxGroup,{value:a,onChange:S,direction:`vertical`,children:[(0,m.jsx)(i.Checkbox,{value:`cellAddress`,disabled:!v,children:e.t(`sheets-drawing-ui.save.useRowCol`)}),v&&(0,m.jsx)(i.Checkbox,{value:`columnValue`,children:e.t(`sheets-drawing-ui.save.useColumnValue`)})]})}),E&&(0,m.jsx)(i.FormLayout,{label:e.t(`sheets-drawing-ui.save.selectColumn`),children:(0,m.jsx)(i.Select,{value:b,options:y,onChange:C})}),d&&(0,m.jsx)(`div`,{className:`univer-text-xs univer-text-red-500`,children:d}),(0,m.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3`,children:[(0,m.jsx)(i.Button,{onClick:w,disabled:s,children:e.t(`sheets-drawing-ui.save.cancel`)}),(0,m.jsx)(i.Button,{variant:`primary`,onClick:T,disabled:s||h.length===0,children:s?e.t(`sheets-drawing-ui.save.saving`):e.t(`sheets-drawing-ui.save.confirm`)})]})]})}let Ze=e=>{var a;let s=(0,l.useDependency)(t.ICommandService),c=(0,l.useDependency)(t.LocaleService),u=(0,l.useDependency)(o.IDrawingManagerService),d=(0,l.useDependency)(r.IRenderManagerService),{drawings:f}=e,h=f[0],g=h?d.getRenderById(h.unitId):void 0,_=g==null?void 0:g.scene,v=_==null?void 0:_.getTransformerByCreate(),[y,b]=(0,p.useState)(!0),[x,S]=(0,p.useState)((a=h==null?void 0:h.anchorType)==null?n.SheetDrawingAnchorType.Position:a);function C(e,t){let n=[];return e.forEach(e=>{let{oKey:r}=e,i=t.getDrawingOKey(r);if(i==null)return n.push(null),!0;let{unitId:a,subUnitId:o,drawingId:s,drawingType:c,anchorType:l,sheetTransform:u,axisAlignSheetTransform:d}=i;n.push({unitId:a,subUnitId:o,drawingId:s,anchorType:l,sheetTransform:u,drawingType:c,axisAlignSheetTransform:d})}),n}if((0,p.useEffect)(()=>{if(!v)return;let e=v.clearControl$.subscribe(e=>{e===!0&&b(!1)}),t=v.changeStart$.subscribe(e=>{let{objects:t}=e,r=C(t,u);if(r.length===0)b(!1);else if(r.length>=1){var i;b(!0),S(((i=r[0])==null?void 0:i.anchorType)||n.SheetDrawingAnchorType.Position)}});return()=>{t.unsubscribe(),e.unsubscribe()}},[u,v]),!h||!v)return null;function w(e){S(e);let t=u.getFocusDrawings();if(t.length===0)return;let r=t.map(t=>({unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId,anchorType:e}));s.executeCommand(n.SetSheetDrawingCommand.id,{unitId:t[0].unitId,drawings:r})}return(0,m.jsxs)(`div`,{className:(0,i.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!y}),children:[(0,m.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,m.jsx)(`div`,{children:c.t(`sheets-drawing-ui.drawing-anchor.title`)})}),(0,m.jsx)(`div`,{children:(0,m.jsxs)(i.RadioGroup,{value:x,onChange:w,direction:`vertical`,children:[(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Both,children:c.t(`sheets-drawing-ui.drawing-anchor.both`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Position,children:c.t(`sheets-drawing-ui.drawing-anchor.position`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.None,children:c.t(`sheets-drawing-ui.drawing-anchor.none`)})]})})]})},Qe=()=>{let e=(0,l.useDependency)(o.IDrawingManagerService),t=(0,l.useObservable)(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return!!(t!=null&&t.length)&&(0,m.jsxs)(`div`,{className:`univer-text-sm`,children:[(0,m.jsx)(u.DrawingCommonPanel,{drawings:t}),(0,m.jsx)(Ze,{drawings:t})]})},$e=class extends t.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(q,Qe)),this.disposeWithMe(this._componentManager.register(G,Xe))}};$e=O([D(0,(0,t.Inject)(l.ComponentManager))],$e);let et=(0,t.createIdentifier)(`sheets-drawing-ui.drawing-context-menu.service`);var tt=class extends t.Disposable{constructor(...e){super(...e),E(this,`_providers`,new Map)}registerProvider(e,n){return this._providers.set(e,n),(0,t.toDisposable)(()=>{this._providers.get(e)===n&&this._providers.delete(e)})}getContextMenuPosition(e){var t;return(t=this._providers.get(e.drawingType))==null?void 0:t.getContextMenuPosition(e)}};let nt=class extends t.RxDisposable{constructor(e,t,n,r,i){super(),this._drawingManagerService=e,this._contextMenuService=t,this._renderManagerService=n,this._univerInstanceService=r,this._drawingContextMenuService=i,this._init()}_init(){this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._contextMenuListener(e))}_contextMenuListener(e){var t;if(!e)return;let n=(t=this._renderManagerService.getRenderById(e.getUnitId()))==null?void 0:t.scene;if(!n)return;let r=n.getTransformerByCreate();r&&this.disposeWithMe(r.changeEnd$.subscribe(e=>{let{event:t}=e;if(t.button!==2)return;let n=r.getSelectedObjectMap();if(n.size===0)return;let i=[];for(let e of n.values()){let t=e.oKey,n=this._drawingManagerService.getDrawingOKey(t);if(!n)return;i.push(n)}this._contextMenuService.triggerContextMenu(t,this._getContextMenuPosition(i))}))}_getContextMenuPosition(e){var t;if(e.length!==1)return l.ContextMenuPosition.DRAWING;let[n]=e;return(t=this._drawingContextMenuService.getContextMenuPosition({unitId:n.unitId,subUnitId:n.subUnitId,drawingId:n.drawingId,drawingType:n.drawingType,drawing:n}))==null?l.ContextMenuPosition.DRAWING:t}};nt=O([D(0,o.IDrawingManagerService),D(1,l.IContextMenuService),D(2,r.IRenderManagerService),D(3,t.IUniverInstanceService),D(4,et)],nt);let rt=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._hoverManagerService=t,this._selectionsService=n,this._drawingRenderService=r,this._sheetSkeletonManagerService=i,E(this,`_isSetCursor`,!1),this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe((0,d.throttleTime)(33)).subscribe(e=>{let t=[];if(e!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),(e==null?void 0:e.unitId)===this._context.unitId&&e!=null&&e.drawing&&t.length===1&&t[0].primary){let{row:n,col:i}=e,{actualRow:a,actualColumn:o,startRow:s,startColumn:c,endRow:l,endColumn:u,isMerged:d,isMergedMainCell:f}=t[0].primary;(d||f)&&n>=s&&n<=l&&i>=c&&i<=u||n===a&&i===o?(this._isSetCursor=!0,this._context.scene.setCursor(r.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}else this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(e=>{if(e!=null&&e.drawing&&this._isSetCursor){var t;let n=e.drawing.drawing.drawingOrigin,r=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(n.imageSourceType,n.source);if(!r)return;this._drawingRenderService.previewImage(`preview-cell-image`,r.src,r.width,r.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};rt=O([D(1,(0,t.Inject)(c.HoverManagerService)),D(2,(0,t.Inject)(s.SheetsSelectionsService)),D(3,(0,t.Inject)(u.DrawingRenderService)),D(4,(0,t.Inject)(c.SheetSkeletonManagerService))],rt);let it=class extends t.Disposable{constructor(e,t,n,r){super(),this._context=e,this._sheetDrawingService=t,this._drawingManagerService=n,this._sheetSkeletonService=r,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);let e=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(let t in e){let r=e[t];for(let e in r.data){let t=r.data[e],{unitId:i,subUnitId:a}=t,o=this._sheetSkeletonService.getSkeletonParam(i,a);o&&t.sheetTransform&&(t.transform=(0,n.drawingPositionToTransform)(t.sheetTransform,o))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};it=O([D(1,n.ISheetDrawingService),D(2,o.IDrawingManagerService),D(3,(0,t.Inject)(s.SheetSkeletonService))],it);function at(e,t,n){var r,i;if((n==null||(r=n.p)==null||(r=r.body)==null?void 0:r.dataStream.length)===3&&((i=n.p)==null||(i=i.drawingsOrder)==null?void 0:i.length)===1){let r=n.p.drawings[n.p.drawingsOrder[0]],i=A(e,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},r.docTransform.size.width,r.docTransform.size.height,r.docTransform.angle);if(i)return r.transform.width=i.width,r.transform.height=i.height,r.docTransform.size.width=i.width,r.docTransform.size.height=i.height,r.transform.left=0,r.transform.top=0,r.docTransform.positionH.posOffset=0,r.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let ot=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._injector=t,this._drawingManagerService=n,this._docDrawingController=r,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible?e.visible&&(this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(s.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:s.InterceptCellContentPriority.CELL_IMAGE,handler:(e,t,n)=>{var r;return e!=null&&e.p&&(r=e.p.drawingsOrder)!=null&&r.length&&(e===t.rawData&&(e={...t.rawData}),e.interceptorStyle||(e.interceptorStyle={}),e.interceptorStyle.tr={a:0},at(this._injector,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},e)),n(e)}}))}};ot=O([D(0,(0,t.Inject)(s.SheetInterceptorService)),D(1,(0,t.Inject)(t.Injector)),D(2,o.IDrawingManagerService),D(3,(0,t.Inject)(f.DocDrawingController)),D(4,(0,t.Inject)(c.IEditorBridgeService))],ot);let st=class extends t.Disposable{constructor(e,t){super(),this._autoFillService=e,this._injector=t,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:`sheet-cell-image-autofill`,onBeforeSubmit:(e,n,r,i)=>{new t.ObjectMatrix(i).forValue((t,n,r)=>{at(this._injector,{unitId:e.unitId,subUnitId:e.subUnitId,row:t,col:n},r)})}}))}};st=O([D(0,(0,t.Inject)(s.IAutoFillService)),D(1,(0,t.Inject)(t.Injector))],st);let ct=[t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],lt=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._commandService=e,this._univerInstanceService=t,this._dialogService=n,this._renderManagerService=r,this._localeService=i,this._initDocImageCopyPasteHooks()}_setCellImage(e){var n;let i=(0,t.createDocumentModelWithStyle)(``,{}),a=(n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(c.EditingRenderController),o=t.BuildTextUtils.drawing.add({documentDataModel:i,drawings:[e],selection:{collapsed:!0,startOffset:0,endOffset:0}});o&&(i.apply(o),a&&a.submitCellData(i))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===h.InnerPasteCommand.id){var n;let{doc:i}=e.params,a=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(a==null||!Object.keys((n=i.drawings)==null?{}:n).length)return;let o=a.getUnitId();if(ct.includes(o)){var r;let e=()=>{this._dialogService.close(`sheet-cell-image-copy-paste`),this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1})};((r=a.getBody())==null?void 0:r.dataStream)===`\r
2
+ `?(this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(i.drawings)[0])):this._dialogService.open({id:`sheet-cell-image-copy-paste`,title:{label:this._localeService.t(`sheets-drawing-ui.cell-image.pasteTitle`)},children:{label:this._localeService.t(`sheets-drawing-ui.cell-image.pasteContent`)},width:320,destroyOnClose:!0,onClose:e,showOk:!0,showCancel:!0,onOk:()=>{e(),this._setCellImage(Object.values(i.drawings)[0])},onCancel:e})}}}))}};lt=O([D(0,t.ICommandService),D(1,t.IUniverInstanceService),D(2,l.IDialogService),D(3,r.IRenderManagerService),D(4,(0,t.Inject)(t.LocaleService))],lt);let ut=`image/png`;function dt(e){let t=e.split(`,`),n=atob(t[1]),r=n.length,i=new Uint8Array(r);for(let e=0;e<r;e++)i[e]=n.charCodeAt(e);return new Blob([i],{type:ut})}function ft(e){let t=new ClipboardItem({[ut]:dt(e)});navigator.clipboard.write([t]).catch(e=>{console.error(`Could not copy image using clipboard API: `,e)})}function pt(){function e(){let e=document.createElement(`input`);return e.style.position=`absolute`,e.style.height=`1px`,e.style.width=`1px`,e.style.opacity=`0`,e}let t=document.activeElement,n=e();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),t instanceof HTMLElement&&t.focus()}}let mt=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],ht=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._drawingService=r,this._clipboardInterfaceService=i,this._commandService=a,E(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:`SHEET_IMAGE_UI_PLUGIN`,onBeforeCopy:(e,r,i,a)=>{this._copyInfo=null;let o=this._focusedDrawings;if(o.length>0){let[r]=o;if(r.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)return;if(a===c.COPY_TYPE.CUT){let t={unitId:e,drawings:[r]};this._commandService.executeCommand(n.RemoveSheetDrawingCommand.id,t)}setTimeout(()=>{let e=pt();r.drawingType===t.DrawingTypeEnum.DRAWING_IMAGE&&r.imageSourceType===t.ImageSourceType.BASE64?ft(r.source):this._clipboardInterfaceService.writeText(``),e()},200);let i={unitId:r.unitId,subUnitId:r.subUnitId,drawings:[r]};this._copyInfo=i}else{let t=this._createDrawingsCopyInfoByRange(e,r,i);this._copyInfo=t}},onPasteCells:(e,t,n,r)=>{if(!this._copyInfo)return{redos:[],undos:[]};let{copyType:i=c.COPY_TYPE.COPY,pasteType:a}=r,{range:o,unitId:s,subUnitId:l}=e||{},{range:u,unitId:d,subUnitId:f}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({unitId:d,subUnitId:f,pasteRange:u,pasteType:a},{unitId:s,subUnitId:l,copyType:i,copyRange:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},c.COPY_TYPE.COPY)},onPastePlainText:(e,t)=>({undos:[],redos:[]}),onPasteUnrecognized:e=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:c.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},c.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(e,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:c.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},c.COPY_TYPE.COPY);{let e=t.filter(e=>e.type.includes(`image`));if(e.length)return{undos:[],redos:[{id:M.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(e,r,i){let a=this._sheetSkeletonService.getSkeleton(e,r);if(!a)return;let o=(0,s.attachRangeWithCoord)(a,i);if(!o)return;let{startX:c,endX:l,startY:u,endY:d}=o,f=this._drawingService.getDrawingData(e,r),p=this._focusedDrawings.slice();if(Object.keys(f).forEach(e=>{let r=f[e];if(r.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)return;let{transform:i}=r;if(r.anchorType!==n.SheetDrawingAnchorType.Both||!i)return;let{left:a=0,top:o=0,width:s=0,height:m=0}=i,{drawingStartX:h,drawingEndX:g,drawingStartY:_,drawingEndY:v}={drawingStartX:a,drawingEndX:a+s,drawingStartY:o,drawingEndY:o+m};c<=h&&g<=l&&u<=_&&v<=d&&p.push(r)}),p.length)return{copyRange:i,drawings:p,unitId:e,subUnitId:r}}_generateSingleDrawingPasteMutations(e,t){let{pasteType:r,pasteTo:i}=e;if(mt.includes(r))return{redos:[],undos:[]};let{unitId:a,subUnitId:o,range:l}=i,u=this._sheetSkeletonService.getSkeleton(a,o);if(!u)return{redos:[],undos:[]};let{drawings:d}=this._copyInfo,f=(0,s.discreteRangeToRange)(l);return this._generateMutations(d,{unitId:a,subUnitId:o,isCut:t===c.COPY_TYPE.CUT,getTransform:(e,t)=>{var r,i;let a=(0,s.attachRangeWithCoord)(u,{startRow:f.startRow,endRow:f.endRow,startColumn:f.startColumn,endColumn:f.endColumn}),o={...e,left:a==null?void 0:a.startX,top:a==null?void 0:a.startY};return{transform:o,sheetTransform:(r=(0,n.transformToDrawingPosition)(o,u))==null?t:r,axisAlignSheetTransform:(i=(0,n.transformToAxisAlignPosition)(o,u))==null?t:i}}})}_generateMutations(e,r){let{unitId:i,subUnitId:a,getTransform:o,isCut:s}=r,c=[],l=[],{_drawingService:u}=this;return e.forEach(e=>{let{transform:r,sheetTransform:d}=e;if(!r)return;let f=o(r,d),p={...e,unitId:i,subUnitId:a,drawingId:s?e.drawingId:(0,t.generateRandomId)(),transform:f.transform,sheetTransform:f.sheetTransform,axisAlignSheetTransform:f.axisAlignSheetTransform};if(s){let{undo:e,redo:t,objects:r}=u.getBatchUpdateOp([p]);c.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,type:n.DrawingApplyType.UPDATE,op:t,objects:r}}),l.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,type:n.DrawingApplyType.UPDATE,op:e,objects:r}})}else{let{undo:e,redo:t,objects:r}=u.getBatchAddOp([p]);c.push({id:n.SetDrawingApplyMutation.id,params:{op:t,unitId:i,subUnitId:a,objects:r,type:n.DrawingApplyType.INSERT}}),l.push({id:n.SetDrawingApplyMutation.id,params:{op:e,unitId:i,subUnitId:a,objects:r,type:n.DrawingApplyType.REMOVE}})}}),{redos:c,undos:l}}_generateRangeDrawingsPasteMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:r,subUnitId:i,pasteRange:a,pasteType:o}=e,{unitId:l,subUnitId:u,copyRange:d,copyType:f}=t;if(mt.includes(o))return{redos:[],undos:[]};let p=this._sheetSkeletonService.getSkeleton(r,i);if(!p)return{redos:[],undos:[]};let{drawings:m}=this._copyInfo;if(!d)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:r,subUnitId:i,range:(0,s.discreteRangeToRange)(a)},pasteType:o},f);let h=this._sheetSkeletonService.getSkeleton(l,u);if(!h)return{redos:[],undos:[]};let{ranges:[g,_],mapFunc:v}=(0,c.virtualizeDiscreteRanges)([d,a]),{row:y,col:b}=v(g.startRow,g.startColumn),{row:x,col:S}=v(_.startRow,_.startColumn),C=(0,s.attachRangeWithCoord)(h,{startRow:y,endRow:y,startColumn:b,endColumn:b}),w=(0,s.attachRangeWithCoord)(p,{startRow:x,endRow:x,startColumn:S,endColumn:S});if(!C||!w)return{redos:[],undos:[]};let T=w.startX-C.startX,E=w.startY-C.startY,D=x-y,O=S-b;return this._generateMutations(m,{unitId:r,subUnitId:i,getTransform:(e,t)=>{var r,i,a;let o={...e,left:((r=e==null?void 0:e.left)==null?0:r)+T,top:((i=e==null?void 0:e.top)==null?0:i)+E};return{transform:o,sheetTransform:{...t,to:{...t.to,row:t.to.row+D,column:t.to.column+O},from:{...t.from,row:t.from.row+D,column:t.from.column+O}},axisAlignSheetTransform:(a=(0,n.transformToAxisAlignPosition)(o,p))==null?t:a}},isCut:f===c.COPY_TYPE.CUT})}};ht=O([D(0,c.ISheetClipboardService),D(1,r.IRenderManagerService),D(2,(0,t.Inject)(s.SheetSkeletonService)),D(3,o.IDrawingManagerService),D(4,l.IClipboardInterfaceService),D(5,t.ICommandService)],ht);let gt=[r.ObjectType.IMAGE,r.ObjectType.SHAPE,r.ObjectType.CHART,r.ObjectType.DRAWING_DOM],_t=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._commandService=e,this._localeService=t,this._renderManagerService=n,this._permissionService=r,this._univerInstanceService=i,this._userManagerService=a,this._sheetPermissionCheckController=o,this._sheetDrawingService=s,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange(),this._initCommandPermissionCheck()}_initDrawingVisible(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$,r=(0,d.combineLatest)([e,n]);this.disposeWithMe(r.pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.tap)(t=>{if(!t){this._sheetDrawingService.setDrawingVisible(!1);return}let n=e.getUnitId(),r=t.getSheetId();this._permissionService.composePermission([new s.WorkbookViewPermission(n).id,new s.WorksheetViewPermission(n,r).id]).every(e=>e.value)?this._sheetDrawingService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,t)})):(this._sheetDrawingService.setDrawingVisible(!1),d.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(e,t){this._sheetDrawingService.setDrawingVisible(!1);let n=e.getUnitId(),r=t.getSheetId(),i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i),o=this._renderManagerService.getRenderById(n),s=o==null?void 0:o.scene;s&&s.getAllObjectsByOrder().forEach(e=>{gt.includes(e.objectType)&&a.some(t=>e.oKey.includes(t.drawingId))&&s.removeObject(e)})}_initDrawingEditable(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$,r=(0,d.combineLatest)([e,n]);this.disposeWithMe(r.pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.tap)(t=>{if(!t){this._sheetDrawingService.setDrawingEditable(!1);return}let n=e.getUnitId(),r=t.getSheetId();this._permissionService.composePermission([new s.WorkbookEditablePermission(n).id,new s.WorksheetEditPermission(n,r).id]).every(e=>e.value)?this._sheetDrawingService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,t)})):(this._sheetDrawingService.setDrawingEditable(!1),d.EMPTY))).subscribe())}_handleDrawingEditableFalse(e,t){this._sheetDrawingService.setDrawingEditable(!1);let n=e.getUnitId(),r=t.getSheetId(),i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i),o=this._renderManagerService.getRenderById(n),s=o==null?void 0:o.scene;s&&s.getAllObjectsByOrder().forEach(e=>{gt.includes(e.objectType)&&a.some(t=>e.oKey.includes(t.drawingId))&&s.detachTransformerFrom(e)})}_initViewPermissionChange(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$;this.disposeWithMe((0,d.combineLatest)([e,n]).pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=t.getSheetId(),i=this._renderManagerService.getRenderById(n),a=i==null?void 0:i.scene;if(!a)return d.EMPTY;let o=a.getTransformerByCreate();return this._permissionService.composePermission$([new s.WorkbookViewPermission(n).id,new s.WorksheetViewPermission(n,r).id]).pipe((0,d.map)(e=>e.every(e=>e.value)),(0,d.distinctUntilChanged)()).pipe((0,d.map)(e=>({permission:e,scene:a,transformer:o,unitId:n,subUnitId:r})))})):d.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:r,subUnitId:i})=>{this._sheetDrawingService.setDrawingVisible(e);let a=t.getAllObjectsByOrder(),o=this._sheetDrawingService.getDrawingData(r,i),s=Object.values(o);e?this._sheetDrawingService.addNotification(s):(a.forEach(e=>{gt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.removeObject(e)}),n.clearSelectedObjects())},complete:()=>{this._sheetDrawingService.setDrawingVisible(!0);let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),n=e==null?void 0:e.getActiveSheet(),r=e==null?void 0:e.getUnitId(),i=n==null?void 0:n.getSheetId();if(!r||!i)return;let a=this._sheetDrawingService.getDrawingData(r,i),o=Object.values(a);this._sheetDrawingService.addNotification(o)}}))}_initEditPermissionChange(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$;this.disposeWithMe((0,d.combineLatest)([e,n]).pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=t.getSheetId(),i=this._renderManagerService.getRenderById(n),a=i==null?void 0:i.scene;if(!a)return d.EMPTY;let o=a.getTransformerByCreate();return this._permissionService.composePermission$([new s.WorkbookEditablePermission(n).id,new s.WorksheetEditPermission(n,r).id]).pipe((0,d.map)(e=>e.every(e=>e.value)),(0,d.distinctUntilChanged)()).pipe((0,d.map)(e=>({permission:e,scene:a,transformer:o,unitId:n,subUnitId:r})))})):d.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:r,subUnitId:i})=>{this._sheetDrawingService.setDrawingEditable(e);let a=t.getAllObjectsByOrder(),o=this._sheetDrawingService.getDrawingData(r,i),s=Object.values(o);e?(a.forEach(e=>{gt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.attachTransformerTo(e)}),this._sheetDrawingService.addNotification(s)):(a.forEach(e=>{gt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.detachTransformerFrom(e)}),n.clearSelectedObjects())},complete:()=>{let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return;let n=e.getUnitId(),r=e.getActiveSheet();if(!r)return;let i=r.getSheetId(),a=this._renderManagerService.getRenderById(n),o=a==null?void 0:a.scene;if(!o)return;let s=this._sheetDrawingService.getDrawingData(n,i),c=Object.values(s);this._sheetDrawingService.setDrawingEditable(!0),o.getAllObjectsByOrder().forEach(e=>{gt.includes(e.objectType)&&c.some(t=>e.oKey.includes(t.drawingId))&&o.detachTransformerFrom(e)})}}))}_initCommandPermissionCheck(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let t,r;if(e.id===n.InsertSheetDrawingCommand.id||e.id===n.RemoveSheetDrawingCommand.id||e.id===n.SetSheetDrawingCommand.id){var i,a;let{drawings:n}=e.params;t=n==null||(i=n[0])==null?void 0:i.unitId,r=n==null||(a=n[0])==null?void 0:a.subUnitId}else if(e.id===n.SetDrawingArrangeCommand.id){let n=e.params;t=n.unitId,r=n.subUnitId}!t||!r||this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]},t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-drawing-ui.permission.dialog.editErr`))}))}};_t=O([D(0,(0,t.Inject)(t.ICommandService)),D(1,(0,t.Inject)(t.LocaleService)),D(2,r.IRenderManagerService),D(3,t.IPermissionService),D(4,t.IUniverInstanceService),D(5,(0,t.Inject)(t.UserManagerService)),D(6,(0,t.Inject)(s.SheetPermissionCheckController)),D(7,(0,t.Inject)(n.ISheetDrawingService))],_t);function vt(e,t,n,r){let{width:i,height:a,angle:o,left:s,top:c}=e.transform,l=Ae({left:s==null?0:s,right:(s==null?0:s)+(i==null?0:i),top:c==null?0:c,bottom:(c==null?0:c)+(a==null?0:a)},t,n,r,void 0,!0),{scaleX:u,scaleY:f}=t.getAncestorScale(),p={startX:l.left,endX:l.right,startY:l.top,endY:l.bottom,rotate:o,width:i*u,height:a*f,absolute:l.absolute},m={position$:new d.BehaviorSubject(p),position:p,id:e.drawingId,componentKey:e.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:e.unitId,data:e.data,props:e.props};return[e.drawingId,m]}let yt=e=>{let{floatDomInfos:t,scene:n,skeleton:r,worksheet:i}=e;return(0,m.jsx)(`div`,{style:{position:`absolute`,top:0,left:0},children:(0,p.useMemo)(()=>t.map(e=>vt(e,n,r,i)),[t,n,r,i]).map(([e,t])=>(0,m.jsx)(l.PrintFloatDomSingle,{layer:t,id:e,position:t.position},e))})};function bt(e,t,n){return(0,i.render)((0,m.jsx)((0,l.connectInjector)(yt,n),{...e}),t),()=>(0,i.unmount)(t)}let xt=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetPrintInterceptorService=e,this._drawingRenderService=t,this._drawingManagerService=n,this._renderManagerService=r,this._componetManager=i,this._injector=a,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,n,r)=>{let{unitId:i,scene:a,subUnitId:o,resourceCollector:s}=n,c=this._drawingManagerService.getDrawingDataForUnit(i),l=c==null?void 0:c[o];return l&&l.order.forEach(e=>{let n=l.data[e];if(!n.hidden&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART&&n.drawingType!==t.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==t.DrawingTypeEnum.DRAWING_BLOCK){let e=this._drawingRenderService.renderDrawing(n,a,{allowInactiveSheet:!0});e&&s.add(Promise.resolve(e))}}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(e,n,r)=>{let{unitId:i,subUnitId:a}=n,o=this._renderManagerService.getRenderById(i);if(!o)return r(e);let s=o.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!s)return r(e);let l=this._drawingManagerService.getDrawingDataForUnit(i),u=l==null?void 0:l[n.subUnitId];if(!u)return r(e);let{scaleX:d,scaleY:f}=o.scene,p=e?{...e}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=u.order.map(e=>u.data[e]);return m.length?(m.forEach(e=>{if(!e.hidden&&!e.groupId&&e.transform&&t.Tools.isDefine(e.transform.left)&&t.Tools.isDefine(e.transform.top)&&t.Tools.isDefine(e.transform.width)&&t.Tools.isDefine(e.transform.height)){let t=s.skeleton.getCellIndexByOffset(e.transform.left,e.transform.top,d,f,{x:0,y:0}),n=s.skeleton.getCellIndexByOffset(e.transform.left+e.transform.width,e.transform.top+e.transform.height,d,f,{x:0,y:0});t.column<p.startColumn&&(p.startColumn=t.column),t.row<p.startRow&&(p.startRow=t.row),p.endRow<n.row&&(p.endRow=n.row),p.endColumn<n.column&&(p.endColumn=n.column)}}),r(p)):r(e)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(e,n,r)=>{let{unitId:i,subUnitId:a}=n,o=this._drawingManagerService.getDrawingDataForUnit(i),s=o==null?void 0:o[a];if(s){let i=s.order.map(e=>{let n=s.data[e];if(n.hidden)return null;if(n.drawingType===t.DrawingTypeEnum.DRAWING_DOM||n.drawingType===t.DrawingTypeEnum.DRAWING_BLOCK){let e=this._sheetPrintInterceptorService.getPrintComponent(n.componentKey);return{...n,componentKey:this._componetManager.get(e||n.componentKey)}}return null}).filter(Boolean),a=document.createElement(`div`);a.style.position=`absolute`,a.style.inset=`0`,n.root.appendChild(a);let o=bt({floatDomInfos:i,scene:n.scene,skeleton:n.skeleton,worksheet:n.worksheet},a,this._injector);return e==null||e.add(()=>{a.remove(),queueMicrotask(o)}),r(e)}return r(e)}}))}};xt=O([D(0,(0,t.Inject)(c.SheetPrintInterceptorService)),D(1,(0,t.Inject)(u.DrawingRenderService)),D(2,o.IDrawingManagerService),D(3,r.IRenderManagerService),D(4,(0,t.Inject)(l.ComponentManager)),D(5,(0,t.Inject)(t.Injector))],xt);let St=[s.InsertRowCommand.id,s.InsertColCommand.id,s.RemoveRowCommand.id,s.RemoveColCommand.id,s.DeleteRangeMoveLeftCommand.id,s.DeleteRangeMoveUpCommand.id,s.InsertRangeMoveDownCommand.id,s.InsertRangeMoveRightCommand.id,s.DeltaRowHeightCommand.id,s.SetRowHeightCommand.id,s.DeltaColumnWidthCommand.id,s.SetColWidthCommand.id,s.SetRowHiddenCommand.id,s.SetSpecificRowsVisibleCommand.id,s.SetSpecificColsVisibleCommand.id,s.SetColHiddenCommand.id,s.MoveColsCommand.id,s.MoveRowsCommand.id,s.MoveRangeCommand.id],Ct=[s.SetRowVisibleMutation.id,s.SetRowHiddenMutation.id,s.SetColVisibleMutation.id,s.SetColHiddenMutation.id,s.SetWorksheetRowHeightMutation.id,s.SetWorksheetRowAutoHeightMutation.id,s.SetWorksheetRowIsAutoHeightMutation.id,s.SetWorksheetColWidthMutation.id],wt=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c){super(),this._context=e,this._commandService=t,this._sheetSkeletonService=n,this._selectionRenderService=r,this._sheetInterceptorService=i,this._selectionManagerService=a,this._sheetDrawingService=o,this._drawingManagerService=s,this._univerInstanceService=c,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({getMutations:e=>{let{id:n,params:r}=e;if(!St.includes(n)||!r)return{redos:[],undos:[]};if(n===s.InsertRowCommand.id)return this._moveRowInterceptor(r,`insert`);if([s.MoveColsCommand.id,s.MoveRowsCommand.id,s.MoveRangeCommand.id].includes(n)){let e;if(n===s.MoveRangeCommand.id){let t=r;if(t.toUnitId&&t.fromUnitId&&t.toUnitId!==t.fromUnitId||t.toSubUnitId&&t.fromSubUnitId&&t.toSubUnitId!==t.fromSubUnitId)return{redos:[],undos:[]};e=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:t.toUnitId,subUnitId:t.toSubUnitId})}else e=(0,s.getSheetCommandTarget)(this._univerInstanceService,r);if(!e)return{redos:[],undos:[]};let{unitId:t,subUnitId:i}=e,{fromRange:a,toRange:o}=r;return this._moveRangeInterceptor(t,i,a,o)}else if(n===s.InsertColCommand.id)return this._moveColInterceptor(r,`insert`);else if(n===s.RemoveRowCommand.id)return this._moveRowInterceptor(r,`remove`);else if(n===s.RemoveColCommand.id)return this._moveColInterceptor(r,`remove`);else if(n===s.DeleteRangeMoveLeftCommand.id){let{range:e}=r;return this._getRangeMoveUndo(e,0)}else if(n===s.DeleteRangeMoveUpCommand.id){let{range:e}=r;return this._getRangeMoveUndo(e,1)}else if(n===s.InsertRangeMoveDownCommand.id){let{range:e}=r;return this._getRangeMoveUndo(e,2)}else if(n===s.InsertRangeMoveRightCommand.id){let{range:e}=r;return this._getRangeMoveUndo(e,3)}else if(n===s.SetRowHiddenCommand.id||n===s.SetSpecificRowsVisibleCommand.id){var i;let e=r,n=(0,s.getSheetCommandTarget)(this._univerInstanceService,e);if(!n)return{redos:[],undos:[]};let{unitId:a,subUnitId:o}=n,c=e.ranges||((i=this._selectionManagerService.getCurrentSelections())==null?void 0:i.map(e=>e.range).filter(e=>e.rangeType===t.RANGE_TYPE.ROW));return!c||c.length===0?{redos:[],undos:[]}:this._getDrawingUndoForRowVisible(a,o,c)}else if(n===s.SetColHiddenCommand.id||n===s.SetSpecificColsVisibleCommand.id){var a;let e=r,n=(0,s.getSheetCommandTarget)(this._univerInstanceService,e);if(!n)return{redos:[],undos:[]};let{unitId:i,subUnitId:o}=n,c=e.ranges||((a=this._selectionManagerService.getCurrentSelections())==null?void 0:a.map(e=>e.range).filter(e=>e.rangeType===t.RANGE_TYPE.COLUMN));return!c||c.length===0?{redos:[],undos:[]}:this._getDrawingUndoForColVisible(i,o,c)}else if(n===s.DeltaRowHeightCommand.id||n===s.DeltaColumnWidthCommand.id){let e=(0,s.getSheetCommandTarget)(this._univerInstanceService);if(!e)return{redos:[],undos:[]};let{unitId:t,subUnitId:i,worksheet:a}=e,o=[];return n===s.DeltaRowHeightCommand.id?o.push({startRow:r.anchorRow,endRow:r.anchorRow,startColumn:0,endColumn:a.getColumnCount()-1}):o.push({startRow:0,endRow:a.getRowCount()-1,startColumn:r.anchorCol,endColumn:r.anchorCol}),this._getDrawingUndoForRowAndColSize(t,i,o)}else if(n===s.SetRowHeightCommand.id||n===s.SetColWidthCommand.id){var o;let e=r,t=(0,s.getSheetCommandTarget)(this._univerInstanceService,e);if(!t)return{redos:[],undos:[]};let{unitId:n,subUnitId:i}=t,a=e.ranges||((o=this._selectionManagerService.getCurrentSelections())==null?void 0:o.map(e=>e.range));return!a||a.length===0?{redos:[],undos:[]}:this._getDrawingUndoForRowAndColSize(n,i,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(e,t){let r=(0,s.getSheetCommandTarget)(this._univerInstanceService);if(!r)return{redos:[],undos:[]};let{unitId:i,subUnitId:a}=r,o=this._sheetDrawingService.getDrawingData(i,a),c=[],l=[],u=[],d=[];if(Object.keys(o).forEach(n=>{let r=o[n],{updateDrawings:i,deleteDrawings:a}=this._getUpdateOrDeleteDrawings(e,t,r);u.push(...i),d.push(...a)}),u.length===0&&d.length===0)return{redos:[],undos:[]};if(u.length>0){let{undo:e,redo:t,objects:r}=this._sheetDrawingService.getBatchUpdateOp(u);c.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:r,type:n.DrawingApplyType.UPDATE}}),l.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:e,objects:r,type:n.DrawingApplyType.UPDATE}})}if(d.length>0){let e=this._sheetDrawingService.getBatchRemoveOp(d),t=e.undo,r=e.redo,o=e.objects;c.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE}}),l.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:o,type:n.DrawingApplyType.INSERT}})}return c.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),l.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),{redos:c,undos:l}}_getUpdateOrDeleteDrawings(e,t,r){let i=[],a=[],{sheetTransform:o,anchorType:s=n.SheetDrawingAnchorType.Position,transform:c,unitId:l,subUnitId:u,drawingId:d}=r,f=this._sheetSkeletonService.getSkeletonParam(l,u);if(!o||!c||!f)return{updateDrawings:i,deleteDrawings:a};let{from:p,to:m}=o,{row:h,column:g}=p,{row:_,column:v}=m,{startRow:y,endRow:b,startColumn:x,endColumn:S}=e,C=null,w=null,T;if(t===0&&h>=y&&_<=b)if(g>=x&&v<=S)a.push({unitId:l,subUnitId:u,drawingId:d});else{var E;let e=this._shrinkCol(x,S,{sheetSkeletonParam:f,sheetTransform:o,transform:c,anchorType:s});C=e==null?void 0:e.newSheetTransform,w=e==null?void 0:e.newTransform,T=(E=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:E}else if(t===1&&g>=x&&v<=S)if(h>=y&&_<=b)a.push({unitId:l,subUnitId:u,drawingId:d});else{var D;let e=this._shrinkRow(y,b,{sheetSkeletonParam:f,sheetTransform:o,transform:c,anchorType:s});C=e==null?void 0:e.newSheetTransform,w=e==null?void 0:e.newTransform,T=(D=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:D}else if(t===2){var O;let e=this._expandRow(y,b,{sheetSkeletonParam:f,sheetTransform:o,transform:c,anchorType:s});C=e==null?void 0:e.newSheetTransform,w=e==null?void 0:e.newTransform,T=(O=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:O}else if(t===3){var k;let e=this._expandCol(x,S,{sheetSkeletonParam:f,sheetTransform:o,transform:c,anchorType:s});C=e==null?void 0:e.newSheetTransform,w=e==null?void 0:e.newTransform,T=(k=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:k}if(C&&w){let e=(0,n.drawingPositionToTransform)(C,f);i.push({...r,sheetTransform:C,transform:e,axisAlignSheetTransform:T})}return{updateDrawings:i,deleteDrawings:a}}_remainDrawingSize(e,t,r,i){let a=(0,n.transformToDrawingPosition)({...e},i);if(a){let o=(0,n.transformToAxisAlignPosition)({...e},i);t.push({...r,sheetTransform:a,axisAlignSheetTransform:o})}}_getDrawingUndoForColVisible(e,t,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return{redos:[],undos:[]};let a=this._drawingManagerService.getDrawingData(e,t),o=[],c=[];if(Object.keys(a).forEach(e=>{let t=a[e],{sheetTransform:l,transform:u,anchorType:d=n.SheetDrawingAnchorType.Position}=t;if(d===n.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,t,i);else{let{from:e,to:a}=l,{row:f,column:p}=e,{row:m,column:h}=a;for(let e=0;e<r.length;e++){let{startColumn:a,endColumn:l}=r[e];if(h<a)continue;if(d===n.SheetDrawingAnchorType.Position){let e=null,r=null;if(p>=a&&p<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:l,startRow:f,endRow:m});r={...u,left:e.startX}}if(r){e=(0,n.transformToDrawingPosition)(r,i);let a=(0,n.transformToAxisAlignPosition)(r,i);if(e&&r){o.push({...t,sheetTransform:e,transform:r,axisAlignSheetTransform:a});break}}continue}if(p>=a&&h<=l)continue;let g=null,_=null;if(p>=a&&p<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:l,startRow:f,endRow:m});_={...u,left:(e==null?void 0:e.startX)||0,width:((u==null?void 0:u.width)||0)-e.endX+e.startX}}else if(h>=a&&h<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:a,endColumn:h,startRow:f,endRow:m});_={...u,left:e.startX-((u==null?void 0:u.width)||0)}}else{let e=(0,s.attachRangeWithCoord)(i,{startColumn:a,endColumn:l,startRow:f,endRow:m});if(_={...u,width:((u==null?void 0:u.width)||0)-e.endX+e.startX},g=(0,n.transformToDrawingPosition)(_,i),g&&_){let e=(0,n.transformToAxisAlignPosition)(_,i);c.push({...t,sheetTransform:g,transform:_,axisAlignSheetTransform:e});break}}if(_&&(g=(0,n.transformToDrawingPosition)(_,i)),_&&g){let e=(0,n.transformToAxisAlignPosition)(_,i);o.push({...t,sheetTransform:g,transform:_,axisAlignSheetTransform:e});break}else this._remainDrawingSize(u,o,t,i)}}}),o.length===0&&c.length===0)return{redos:[],undos:[]};let{redos:l,undos:u}=this._createUndoAndRedoMutation(e,t,o),d=[],f=[];if(c.length>0){let{redos:n,undos:r}=this._createUndoAndRedoMutation(e,t,c);d.push(...n),f.push(...r)}return{redos:l,undos:u,preRedos:d,preUndos:f}}_createUndoAndRedoMutation(e,t,r){let{undo:i,redo:a,objects:o}=this._sheetDrawingService.getBatchUpdateOp(r);return{redos:[{id:n.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:a,objects:o,type:n.DrawingApplyType.UPDATE}},{id:n.ClearSheetDrawingTransformerOperation.id,params:[e]}],undos:[{id:n.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:i,objects:o,type:n.DrawingApplyType.UPDATE}},{id:n.ClearSheetDrawingTransformerOperation.id,params:[e]}]}}_getDrawingUndoForRowVisible(e,t,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return{redos:[],undos:[]};let a=this._drawingManagerService.getDrawingData(e,t),o=[],c=[];if(Object.keys(a).forEach(e=>{let t=a[e],{sheetTransform:l,transform:u,anchorType:d=n.SheetDrawingAnchorType.Position}=t;if(d===n.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,t,i);else{let{from:e,to:a}=l,{row:f,column:p}=e,{row:m,column:h}=a;for(let e=0;e<r.length;e++){let{startRow:a,endRow:l}=r[e];if(m<a)continue;if(d===n.SheetDrawingAnchorType.Position){let e=null,r=null;if(f>=a&&f<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:h,startRow:f,endRow:l});r={...u,top:e.startY}}if(r){e=(0,n.transformToDrawingPosition)(r,i);let a=(0,n.transformToAxisAlignPosition)(r,i);if(e&&r){o.push({...t,sheetTransform:e,transform:r,axisAlignSheetTransform:a});break}}continue}if(f>=a&&m<=l)continue;let g=null,_=null;if(f>=a&&f<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:h,startRow:f,endRow:l});_={...u,top:(e==null?void 0:e.startY)||0,height:((u==null?void 0:u.height)||0)-e.endY+e.startY}}else if(m>=a&&m<=l){let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:h,startRow:a,endRow:m});_={...u,top:e.startY-((u==null?void 0:u.height)||0)}}else{let e=(0,s.attachRangeWithCoord)(i,{startColumn:p,endColumn:h,startRow:a,endRow:l});if(_={...u,height:((u==null?void 0:u.height)||0)-e.endY+e.startY},g=(0,n.transformToDrawingPosition)(_,i),g&&_){let e=(0,n.transformToAxisAlignPosition)(_,i);c.push({...t,sheetTransform:g,transform:_,axisAlignSheetTransform:e});break}}if(_&&(g=(0,n.transformToDrawingPosition)(_,i)),_&&g){let e=(0,n.transformToAxisAlignPosition)(_,i);o.push({...t,sheetTransform:g,transform:_,axisAlignSheetTransform:e});break}else this._remainDrawingSize(u,o,t,i)}}}),o.length===0&&c.length===0)return{redos:[],undos:[]};let{redos:l,undos:u}=this._createUndoAndRedoMutation(e,t,o),d=[],f=[];if(c.length>0){let{redos:n,undos:r}=this._createUndoAndRedoMutation(e,t,c);d.push(...n),f.push(...r)}return{redos:l,undos:u,preRedos:d,preUndos:f}}_getDrawingUndoForRowAndColSize(e,t,r){let i=this._sheetSkeletonService.getSkeletonParam(e,t);if(!i)return{redos:[],undos:[]};let{skeleton:a}=i,o=this._drawingManagerService.getDrawingData(e,t),s=[];return Object.keys(o).forEach(e=>{let t=o[e],{sheetTransform:c,transform:l,anchorType:u=n.SheetDrawingAnchorType.Position}=t;if(u===n.SheetDrawingAnchorType.None)this._remainDrawingSize(l,s,t,a);else{let{from:e,to:o}=c,{row:d,column:f}=e,{row:p,column:m}=o;for(let e=0;e<r.length;e++){let{startRow:o,endRow:h,startColumn:g,endColumn:_}=r[e];if(p<o||m<g)continue;if(u===n.SheetDrawingAnchorType.Position&&(d<=o&&p>=h||f<=g&&m>=_)){this._remainDrawingSize(l,s,t,a);continue}let v=(0,n.drawingPositionToTransform)({...c},i);if(v){s.push({...t,transform:v});break}}}}),s.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(e,t,s)}_getUnitIdAndSubUnitId(e,t){let n;if(n=t===`insert`?(0,s.getSheetCommandTarget)(this._univerInstanceService,e):(0,s.getSheetCommandTarget)(this._univerInstanceService),!n)return;let{unitId:r,subUnitId:i}=n;return{unitId:r,subUnitId:i}}_moveRangeInterceptor(e,t,r,i){let a=this._sheetSkeletonService.getSkeletonParam(e,t);if(!a)return{redos:[],undos:[]};let{skeleton:o}=a,c=(0,s.attachRangeWithCoord)(o,r);if(!c)return{redos:[],undos:[]};let{startX:l,endX:u,startY:d,endY:f}=c,p=this._sheetDrawingService.getDrawingData(e,t),m=[];Object.keys(p).forEach(e=>{let t=p[e];if(t.anchorType!==n.SheetDrawingAnchorType.Both)return;let{transform:r}=t;if(!r)return;let{left:i=0,top:a=0,width:o=0,height:s=0}=r,{drawingStartX:c,drawingEndX:h,drawingStartY:g,drawingEndY:_}={drawingStartX:i,drawingEndX:i+o,drawingStartY:a,drawingEndY:a+s};l<=c&&h<=u&&d<=g&&_<=f&&m.push(t)});let h=[],g=[],_=i.startRow-r.startRow,v=i.startColumn-r.startColumn,y=m.map(r=>{let i=r.sheetTransform,o={to:{...i.to,row:i.to.row+_,column:i.to.column+v},from:{...i.from,row:i.from.row+_,column:i.from.column+v}},s=(0,n.drawingPositionToTransform)(o,a);return{unitId:e,subUnitId:t,drawingId:r.drawingId,transform:s,sheetTransform:o}});if(y.length){let{undo:r,redo:i,objects:a}=this._sheetDrawingService.getBatchUpdateOp(y);h.push({id:n.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:i,objects:a,type:n.DrawingApplyType.UPDATE}}),g.push({id:n.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:r,objects:a,type:n.DrawingApplyType.UPDATE}})}return{redos:h,undos:g}}_moveRowInterceptor(e,t){let r=this._getUnitIdAndSubUnitId(e,t);if(!r)return{redos:[],undos:[]};let{unitId:i,subUnitId:a}=r,o=this._sheetSkeletonService.getSkeletonParam(i,a);if(!o)return{redos:[],undos:[]};let{range:s}=e,c=s.startRow,l=s.endRow,u=[],d=[],f=this._sheetDrawingService.getDrawingData(i,a),p=[],m=[];if(Object.keys(f).forEach(e=>{let{sheetTransform:r,transform:s,anchorType:u=n.SheetDrawingAnchorType.Position}=f[e];if(!r||!s)return;let d,h,g;if(t===`insert`){var _;let e=this._expandRow(c,l,{sheetSkeletonParam:o,sheetTransform:r,transform:s,anchorType:u});d=e==null?void 0:e.newSheetTransform,h=e==null?void 0:e.newTransform,g=(_=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:_}else{let{from:t,to:f}=r,{row:p}=t,{row:_}=f;if(u===n.SheetDrawingAnchorType.Both&&p>=c&&_<=l)m.push({unitId:i,subUnitId:a,drawingId:e});else{var v;let e=this._shrinkRow(c,l,{sheetSkeletonParam:o,sheetTransform:r,transform:s,anchorType:u});d=e==null?void 0:e.newSheetTransform,h=e==null?void 0:e.newTransform,g=(v=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:v}}if(!d||!h)return;let y={unitId:i,subUnitId:a,drawingId:e,transform:h,sheetTransform:d,axisAlignSheetTransform:g};p.push(y)}),p.length===0&&m.length===0)return{redos:[],undos:[]};if(p.length>0){let{undo:e,redo:t,objects:r}=this._sheetDrawingService.getBatchUpdateOp(p);u.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:r,type:n.DrawingApplyType.UPDATE}}),d.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:e,objects:r,type:n.DrawingApplyType.UPDATE}})}if(m.length>0){let e=this._sheetDrawingService.getBatchRemoveOp(m),t=e.undo,r=e.redo,o=e.objects;u.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE}}),d.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:o,type:n.DrawingApplyType.INSERT}})}return u.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),d.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),{redos:u,undos:d}}_moveColInterceptor(e,t){let r=this._getUnitIdAndSubUnitId(e,t);if(!r)return{redos:[],undos:[]};let{unitId:i,subUnitId:a}=r,o=this._sheetSkeletonService.getSkeletonParam(i,a);if(!o)return{redos:[],undos:[]};let{range:s}=e,c=s.startColumn,l=s.endColumn,u=[],d=[],f=this._sheetDrawingService.getDrawingData(i,a),p=[],m=[];if(Object.keys(f).forEach(e=>{let{sheetTransform:r,transform:s,anchorType:u=n.SheetDrawingAnchorType.Position}=f[e];if(!r||!s)return;let d,h,g;if(t===`insert`){var _;let e=this._expandCol(c,l,{sheetSkeletonParam:o,sheetTransform:r,transform:s,anchorType:u});d=e==null?void 0:e.newSheetTransform,h=e==null?void 0:e.newTransform,g=(_=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:_}else{let{from:t,to:f}=r,{column:p}=t,{column:_}=f;if(u===n.SheetDrawingAnchorType.Both&&p>=c&&_<=l)m.push({unitId:i,subUnitId:a,drawingId:e});else{var v;let e=this._shrinkCol(c,l,{sheetSkeletonParam:o,sheetTransform:r,transform:s,anchorType:u});d=e==null?void 0:e.newSheetTransform,h=e==null?void 0:e.newTransform,g=(v=e==null?void 0:e.axisAlignSheetTransform)==null?void 0:v}}if(!d||!h)return;let y={unitId:i,subUnitId:a,drawingId:e,transform:h,sheetTransform:d,axisAlignSheetTransform:g};p.push(y)}),p.length===0&&m.length===0)return{redos:[],undos:[]};if(p.length>0){let{undo:e,redo:t,objects:r}=this._sheetDrawingService.getBatchUpdateOp(p);u.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:r,type:n.DrawingApplyType.UPDATE}}),d.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:e,objects:r,type:n.DrawingApplyType.UPDATE}})}if(m.length>0){let e=this._sheetDrawingService.getBatchRemoveOp(m),t=e.undo,r=e.redo,o=e.objects;u.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE}}),d.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,op:t,objects:o,type:n.DrawingApplyType.INSERT}})}return u.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),d.push({id:n.ClearSheetDrawingTransformerOperation.id,params:[i]}),{redos:u,undos:d}}_expandCol(e,t,r){let{sheetSkeletonParam:i,sheetTransform:a,transform:o,anchorType:c=n.SheetDrawingAnchorType.Position}=r,{skeleton:l}=i,u=t-e+1,{from:d,to:f}=a,{column:p}=d,{column:m}=f;if(c===n.SheetDrawingAnchorType.None)return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};let h=null,g=null,_=null;if(p>=e){let r=(0,s.attachRangeWithCoord)(l,{startColumn:e,endColumn:t,startRow:d.row,endRow:f.row});g={...o,left:(o.left||0)+r.endX-r.startX},h=(0,n.transformToDrawingPosition)(g,l),_=(0,n.transformToAxisAlignPosition)(g,l)}else if(m>=t)if(c===n.SheetDrawingAnchorType.Both)h={from:{...d},to:{...f,column:m+u}},g=(0,n.drawingPositionToTransform)(h,i);else return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};return h&&g?{newSheetTransform:h,newTransform:g,axisAlignSheetTransform:_}:null}_shrinkCol(e,t,r){let{sheetSkeletonParam:i,sheetTransform:a,transform:o,anchorType:c=n.SheetDrawingAnchorType.Position}=r,{skeleton:l}=i,u=t-e+1,{from:d,to:f}=a,{column:p}=d,{column:m}=f;if(c===n.SheetDrawingAnchorType.None)return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};let h=null,g=null,_=null;if(p>t)h={from:{...d,column:p-u},to:{...f,column:m-u}},g=(0,n.drawingPositionToTransform)(h,i);else if(p>=e&&m<=t)return null;else if(p<e&&m>t)if(c===n.SheetDrawingAnchorType.Both)h={from:{...d},to:{...f,column:m-u}},g=(0,n.drawingPositionToTransform)(h,i);else return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};else if(p>=e&&p<=t){if(p===e)g={...o,left:(o.left||0)-a.from.columnOffset};else{let t=(0,s.attachRangeWithCoord)(l,{startColumn:e,endColumn:p-1,startRow:d.row,endRow:f.row});g={...o,left:(o.left||0)-t.endX+t.startX-a.from.columnOffset}}h=(0,n.transformToDrawingPosition)(g,l),_=(0,n.transformToAxisAlignPosition)(g,l)}else if(m>=e&&m<=t&&c===n.SheetDrawingAnchorType.Both){let t=(0,s.attachRangeWithCoord)(l,{startColumn:e-1,endColumn:e-1,startRow:d.row,endRow:f.row});h={from:{...d},to:{...f,column:e-1,columnOffset:t.endX-t.startX}},g=(0,n.drawingPositionToTransform)(h,i)}return h&&g?{newSheetTransform:h,newTransform:g,axisAlignSheetTransform:_}:null}_expandRow(e,t,r){let{sheetSkeletonParam:i,sheetTransform:a,transform:o,anchorType:c=n.SheetDrawingAnchorType.Position}=r,{skeleton:l}=i,u=t-e+1,{from:d,to:f}=a,{row:p}=d,{row:m}=f;if(c===n.SheetDrawingAnchorType.None)return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};let h=null,g=null,_=null;if(p>=e){let r=(0,s.attachRangeWithCoord)(l,{startRow:e,endRow:t,startColumn:d.column,endColumn:f.column});g={...o,top:(o.top||0)+r.endY-r.startY},h=(0,n.transformToDrawingPosition)(g,l),_=(0,n.transformToAxisAlignPosition)(g,l)}else if(m>=t)if(c===n.SheetDrawingAnchorType.Both)h={from:{...d},to:{...f,row:m+u}},g=(0,n.drawingPositionToTransform)(h,i);else return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};return h&&g?{newSheetTransform:h,newTransform:g,axisAlignSheetTransform:_}:null}_shrinkRow(e,t,r){let{sheetSkeletonParam:i,sheetTransform:a,transform:o,anchorType:c=n.SheetDrawingAnchorType.Position}=r,{skeleton:l}=i,u=t-e+1,{from:d,to:f}=a,{row:p}=d,{row:m}=f;if(c===n.SheetDrawingAnchorType.None)return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};let h=null,g=null,_=null;if(p>t)h={from:{...d,row:p-u},to:{...f,row:m-u}},g=(0,n.drawingPositionToTransform)(h,i);else if(p>=e&&m<=t)return null;else if(p<e&&m>t)if(c===n.SheetDrawingAnchorType.Both)h={from:{...d},to:{...f,row:m-u}},g=(0,n.drawingPositionToTransform)(h,i);else return{newSheetTransform:(0,n.transformToDrawingPosition)({...o},l),newTransform:o,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)({...o},l)};else if(p>=e&&p<=t){if(p===e)g={...o,top:(o.top||0)-a.from.rowOffset};else{let t=(0,s.attachRangeWithCoord)(l,{startRow:e,endRow:p-1,startColumn:d.column,endColumn:f.column});g={...o,top:(o.top||0)-t.endY+t.startY-a.from.rowOffset}}h=(0,n.transformToDrawingPosition)(g,l),_=(0,n.transformToAxisAlignPosition)(g,l)}else if(m>=e&&m<=t&&c===n.SheetDrawingAnchorType.Both){let t=(0,s.attachRangeWithCoord)(l,{startColumn:d.column,endColumn:d.column,startRow:e-1,endRow:e-1});h={from:{...d},to:{...f,row:e-1,rowOffset:t.endY-t.startY}},g=(0,n.drawingPositionToTransform)(h,i)}return h&&g?{newSheetTransform:h,newTransform:g,axisAlignSheetTransform:_}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetActiveOperation.id){let{unitId:t,subUnitId:n}=e.params;this._updateDrawings(t,n)}})),this.disposeWithMe(this._context.activated$.subscribe(e=>{let{unit:t,unitId:n}=this._context;if(e){let e=t.getActiveSheet().getSheetId();this._updateDrawings(n,e)}else this._clearDrawings(n)}))}_clearDrawings(e){setTimeout(()=>{let t=this._drawingManagerService.drawingManagerData,n=[];Object.keys(t==null?{}:t).forEach(r=>{var i;let a=(i=t[r])==null?{}:i;Object.keys(a).forEach(t=>{var i,o;let s=(i=(o=a[t])==null?void 0:o.data)==null?{}:i;Object.keys(s).forEach(t=>{r===e&&n.push(s[t])})})}),this._sheetDrawingService.removeNotification(n),this._drawingManagerService.removeNotification(n)})}_updateDrawings(e,t){setTimeout(()=>{let r=this._sheetSkeletonService.getSkeletonParam(e,t),i=this._drawingManagerService.drawingManagerData,a=[],o=[];Object.keys(i==null?{}:i).forEach(s=>{var c;if(s!==e)return;let l=(c=i[s])==null?{}:c;Object.keys(l).forEach(i=>{var c,u;let d=(c=(u=l[i])==null?void 0:u.data)==null?{}:c;Object.keys(d).forEach(c=>{if(s===e&&i===t){let e=d[c];e.sheetTransform&&(e.transform=(0,n.drawingPositionToTransform)(e.sheetTransform,r)),a.push(d[c])}else o.push(d[c])})})}),this._sheetDrawingService.removeNotification(o),this._sheetDrawingService.addNotification(a),this._drawingManagerService.removeNotification(o),this._drawingManagerService.addNotification(a)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{Ct.includes(e.id)&&requestIdleCallback(()=>{let t=e.params,n=(0,s.getSheetCommandTarget)(this._univerInstanceService,t);if(!n)return;let{unitId:r,subUnitId:i,worksheet:a}=n,o=[];`ranges`in t?o=t.ranges:`rowsAutoHeightInfo`in t&&(o=t.rowsAutoHeightInfo.map(e=>({startRow:e.row,endRow:e.row,startColumn:0,endColumn:a.getColumnCount()-1}))),this._refreshDrawingTransform(r,i,o)})}))}_refreshDrawingTransform(e,r,i){var a;let o=this._sheetSkeletonService.getSkeletonParam(e,r),s=(a=this._drawingManagerService.getDrawingData(e,r))==null?{}:a,c=[];Object.keys(s).forEach(e=>{let r=s[e],{sheetTransform:a,transform:l,anchorType:u=n.SheetDrawingAnchorType.Position}=r;if(u===n.SheetDrawingAnchorType.None||!a)return!0;let{from:d,to:f}=a,{row:p,column:m}=d,{row:h,column:g}=f;for(let e=0;e<i.length;e++){let{startRow:s,endRow:d,startColumn:f,endColumn:_}=i[e];if(t.Rectangle.intersects({startRow:s,endRow:d,startColumn:f,endColumn:_},{startRow:p,endRow:h,startColumn:m,endColumn:g})||p>d||m>_){let e=u===n.SheetDrawingAnchorType.Position,t=(0,n.drawingPositionToTransform)(a,o);c.push({...r,transform:{...t,width:e?l==null?void 0:l.width:t==null?void 0:t.width,height:e?l==null?void 0:l.height:t==null?void 0:t.height}});break}}}),c.length!==0&&(this._sheetDrawingService.refreshTransform(c),this._drawingManagerService.refreshTransform(c),this._commandService.syncExecuteCommand(n.ClearSheetDrawingTransformerOperation.id,[e]))}};wt=O([D(1,t.ICommandService),D(2,(0,t.Inject)(s.SheetSkeletonService)),D(3,c.ISheetSelectionRenderService),D(4,(0,t.Inject)(s.SheetInterceptorService)),D(5,(0,t.Inject)(s.SheetsSelectionsService)),D(6,n.ISheetDrawingService),D(7,o.IDrawingManagerService),D(8,t.IUniverInstanceService)],wt);let Tt={id:`sheet.command.toggle-flip-drawings`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),c=e.get(n.ISheetDrawingService),l=e.get(s.SheetSkeletonService),{drawings:u}=r,d=r.flipH,f=r.flipV,p=[],m=[];for(let r of u){let{unitId:i,subUnitId:a,drawingId:s}=r;p.push(i);let u=c.getDrawingData(i,a),h=u==null?void 0:u[s];if(!h)continue;let g=l.getSkeleton(i,a);if(!g)continue;let _={...h.transform};d&&(_.flipX=!_.flipX),f&&(_.flipY=!_.flipY);let v=(0,n.transformToDrawingPosition)(_,g),y=(0,n.transformToAxisAlignPosition)(_,g),b={unitId:i,subUnitId:a,drawingType:h.drawingType,drawingId:s,transform:_,sheetTransform:v,axisAlignSheetTransform:y};if(h.drawingType===t.DrawingTypeEnum.DRAWING_IMAGE){let t=Et(e,i);if(t){let e=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:s}),n=t.getObject(e);if(n){let e=n.srcRect;if(e){let t,{left:n=0,top:r=0,right:i=0,bottom:a=0}=e;if(d){let e=n+(i-n)/2;t={left:e-(i-n)/2,top:r,right:e+(i-n)/2,bottom:a}}if(f){let e=r+(a-r)/2;t={left:n,top:e-(a-r)/2,right:i,bottom:e+(a-r)/2}}t&&(b.srcRect=t)}}}}m.push(b)}if(m.length===0)return!1;let{unitId:h,subUnitId:g,undo:_,redo:v,objects:y}=c.getBatchUpdateOp(m),b={id:n.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:g,op:v,objects:y,type:n.DrawingApplyType.UPDATE}},x={id:n.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:g,op:_,objects:y,type:n.DrawingApplyType.UPDATE}};return(0,t.sequenceExecute)([b],i).result?(a.pushUndoRedo({unitID:h,undoMutations:[x,{id:n.ClearSheetDrawingTransformerOperation.id,params:p}],redoMutations:[b,{id:n.ClearSheetDrawingTransformerOperation.id,params:p}]}),!0):!1}};function Et(e,t){let n=e.get(r.IRenderManagerService).getRenderById(t);return n?n.scene:null}function Dt(e){return e.getContextValue(t.FOCUSING_SHEET)&&!e.getContextValue(t.FOCUSING_FX_BAR_EDITOR)&&!e.getContextValue(t.FOCUSING_PANEL_EDITOR)&&e.getContextValue(t.FOCUSING_COMMON_DRAWINGS)&&!e.getContextValue(t.FOCUSING_SHAPE_TEXT_EDITOR)}let Ot={id:P.id,description:`sheets-drawing-ui.shortcut.drawing-move-down`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_DOWN,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.DOWN}},kt={id:P.id,description:`sheets-drawing-ui.shortcut.drawing-move-up`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_UP,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.UP}},At={id:P.id,description:`sheets-drawing-ui.shortcut.drawing-move-left`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_LEFT,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.LEFT}},jt={id:P.id,description:`sheets-drawing-ui.shortcut.drawing-move-right`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_RIGHT,priority:100,preconditions:Dt,staticParameters:{direction:t.Direction.RIGHT}},Mt={id:g.id,description:`sheets-drawing-ui.shortcut.drawing-delete`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,priority:100,preconditions:Dt,binding:l.KeyCode.DELETE,mac:l.KeyCode.BACKSPACE},Nt=class extends t.Disposable{constructor(e,t,n){super(),this._menuManagerService=e,this._commandService=t,this._shortcutService=n,this._init()}_initCustomComponents(){}_initMenus(){this._menuManagerService.mergeMenu(Ke)}_initCommands(){[M,N,J,Y,x,S,P,g,K,Tt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[Ot,kt,At,jt,Mt].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Nt=O([D(0,l.IMenuManagerService),D(1,t.ICommandService),D(2,l.IShortcutService)],Nt);let Pt=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._injector=e,this._localeService=t,this._drawingManagerService=n,this._canvasPopManagerService=r,this._renderManagerService=i,this._univerInstanceService=a,this._messageService=o,this._contextService=s,this._ioService=c,this._commandService=l,E(this,`_initImagePopupMenu`,new Set),this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._create(e)),this._univerInstanceService.getTypeOfUnitDisposed$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._dispose(e)),this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._create(e)),this._setupLoadingStatus()}_setupLoadingStatus(){let e;this.disposeWithMe(this._ioService.change$.subscribe(t=>{t>0&&!e?e=this._messageService.show({id:`image-upload-loading`,type:i.MessageType.Loading,content:`${this._localeService.t(`sheets-drawing-ui.uploadLoading.loading`)}: ${t}`,duration:0}):t===0&&(e==null||e.dispose(),e=void 0)}))}_dispose(e){super.dispose();let t=e.getUnitId();this._renderManagerService.removeRender(t),this._initImagePopupMenu.delete(t)}_create(e){if(!e)return;let t=e.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof u.ImageCropperObject)return!0;return!1}_popupMenuListener(e){var n;let r=(n=this._renderManagerService.getRenderById(e))==null?void 0:n.scene;if(!r)return;let i=r.getTransformerByCreate();if(!i)return;let a;this.disposeWithMe(i.createControl$.subscribe(()=>{if(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))return;let e=i.getSelectedObjectMap();if(e.size>1){a==null||a.dispose();return}let n=e.values().next().value;if(!n)return;let o=n.oKey,s=this._drawingManagerService.getDrawingOKey(o);if(!s||s.drawingType===t.DrawingTypeEnum.DRAWING_SHAPE)return;let{unitId:c,subUnitId:l,drawingId:d,drawingType:f}=s,p=s.data;if(p&&(p.disablePopup||p.version===1&&typeof p.embedId==`string`))return;a==null||a.dispose();let m=this._canvasPopManagerService.getFeatureMenu(c,l,d,f);a=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(n,{componentKey:u.COMPONENT_IMAGE_POPUP_MENU,direction:`horizontal`,offset:[2,0],extraProps:{menuItems:m||this._getImageMenuItems(c,l,d,f)}}))})),this.disposeWithMe(i.clearControl$.subscribe(()=>{a==null||a.dispose(),this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(e=>{e[t.FOCUSING_COMMON_DRAWINGS]===!1&&(a==null||a.dispose())})),this.disposeWithMe(i.changing$.subscribe(()=>{a==null||a.dispose()}))}_getImageMenuItems(e,r,i,a){return[{label:`sheets-drawing-ui.image-popup.edit`,index:0,commandId:Y.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.delete`,index:1,commandId:n.RemoveSheetDrawingCommand.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:!1},{label:`sheets-drawing-ui.image-popup.crop`,index:2,commandId:u.OpenImageCropOperation.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipH`,index:2,commandId:Tt.id,commandParams:{unitId:e,flipH:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipV`,index:2,commandId:Tt.id,commandParams:{unitId:e,flipV:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.reset`,index:3,commandId:u.ImageResetSizeOperation.id,commandParams:[{unitId:e,subUnitId:r,drawingId:i}],disable:a===t.DrawingTypeEnum.DRAWING_DOM}]}};Pt=O([D(0,(0,t.Inject)(t.Injector)),D(1,(0,t.Inject)(t.LocaleService)),D(2,o.IDrawingManagerService),D(3,(0,t.Inject)(c.SheetCanvasPopManagerService)),D(4,r.IRenderManagerService),D(5,t.IUniverInstanceService),D(6,l.IMessageService),D(7,t.IContextService),D(8,t.IImageIoService),D(9,t.ICommandService)],Pt);let Ft=class extends t.Disposable{constructor(e,t,n){super(),this._drawingManagerService=e,this._univerInstanceService=t,this._renderManagerService=n,E(this,`_onDoubleClick$`,new d.Subject),E(this,`onDoubleClick$`,this._onDoubleClick$.asObservable()),E(this,`_doubleClickDisposable`,null),E(this,`_boundRender`,null),E(this,`_boundScene`,null),this._init()}dispose(){this._disposeDoubleClickListener(),this._onDoubleClick$.complete(),super.dispose()}hitTestCurrentSheet(e,t){let n=this._getActiveSheetContext();return n?this.hitTest(n.unitId,n.subUnitId,e,t):null}hitTest(e,t,n,r){var i;let a=(i=this._renderManagerService.getRenderById(e))==null?void 0:i.scene;return a?this._hitTestScene(a,e,t,n,r):null}_init(){this.disposeWithMe((0,t.toDisposable)(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{this._bindDoubleClickListener()}))),this.disposeWithMe((0,t.toDisposable)(this._renderManagerService.created$.subscribe(e=>{let t=this._getActiveSheetContext();e.unitId===(t==null?void 0:t.unitId)&&this._bindDoubleClickListener()}))),this.disposeWithMe((0,t.toDisposable)(this._renderManagerService.disposed$.subscribe(e=>{var t;e===((t=this._boundRender)==null?void 0:t.unitId)&&this._disposeDoubleClickListener()}))),this._bindDoubleClickListener()}_bindDoubleClickListener(){let e=this._getActiveSheetContext();if(!e){this._disposeDoubleClickListener();return}let t=this._renderManagerService.getRenderById(e.unitId),n=t==null?void 0:t.scene;if(!t||!n){this._disposeDoubleClickListener();return}if(this._boundRender===t&&this._boundScene===n&&this._doubleClickDisposable)return;this._disposeDoubleClickListener();let r=n.onDblclick$.subscribeEvent(t=>{let r=this._getActiveSheetContext();if(!r||r.unitId!==e.unitId)return;let i=this._hitTestScene(n,r.unitId,r.subUnitId,t.offsetX,t.offsetY);i&&this._onDoubleClick$.next({...i,nativeEvent:t})});this._doubleClickDisposable={dispose:()=>r.unsubscribe()},this._boundRender=t,this._boundScene=n}_disposeDoubleClickListener(){var e;(e=this._doubleClickDisposable)==null||e.dispose(),this._doubleClickDisposable=null,this._boundRender=null,this._boundScene=null}_hitTestScene(e,t,n,i,a){let o=e.pick(r.Vector2.FromArray([i,a])),s=typeof(o==null?void 0:o.oKey)==`string`?o.oKey:null;if(!s)return null;let c=this._drawingManagerService.getDrawingOKey(s);return!c||c.unitId!==t||c.subUnitId!==n?null:{drawing:c,oKey:s,offsetX:i,offsetY:a}}_getActiveSheetContext(){var e;let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getUnitId(),i=n==null||(e=n.getActiveSheet())==null?void 0:e.getSheetId();return!r||!i?null:{unitId:r,subUnitId:i}}};Ft=O([D(0,o.IDrawingManagerService),D(1,t.IUniverInstanceService),D(2,r.IRenderManagerService)],Ft);let It=class extends t.Plugin{constructor(e=Ye,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},Ye,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`sheets-drawing-ui.config`,o)}onStarting(){(0,t.registerDependencies)(this._injector,[[$e],[$],[Ft],[Nt],[Pt],[xt],[_t],[ht],[Z],[ot],[st],[lt],[I,{useClass:W}],[et,{useClass:tt}],[nt]]),Le(this._injector),this._injector.get($e)}onReady(){(0,t.touchDependencies)(this._injector,[[ht],[lt],[Z]])}onRendered(){this._registerRenderModules(),(0,t.touchDependencies)(this._injector,[[_t],[xt],[Nt],[ot],[st]])}onSteady(){this._injector.get(Pt),this._injector.get(nt)}_registerRenderModules(){[[j],[wt],[it],[rt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e))})}};E(It,`type`,t.UniverInstanceType.UNIVER_SHEET),E(It,`pluginName`,`SHEET_IMAGE_UI_PLUGIN`),E(It,`packageName`,qe),E(It,`version`,Je),It=O([(0,t.DependentOn)(o.UniverDrawingPlugin,f.UniverDocsDrawingPlugin,u.UniverDrawingUIPlugin,n.UniverSheetsDrawingPlugin),D(1,(0,t.Inject)(t.Injector)),D(2,r.IRenderManagerService),D(3,t.IConfigService)],It),Object.defineProperty(e,"BatchSaveImagesService",{enumerable:!0,get:function(){return W}}),e.DeleteDrawingsCommand=g,e.DrawingContextMenuService=tt,e.EditSheetDrawingOperation=Y,e.FileNamePart=F,e.GroupSheetDrawingCommand=x,e.IBatchSaveImagesService=I,e.IDrawingContextMenuService=et,e.InsertFloatImageCommand=M,e.MoveDrawingsCommand=P,e.SHEETS_DRAWING_FLOATING_HOST_DEPENDENCIES=Pe,e.SHEETS_IMAGE_MENU_ID=Re,e.SHEET_CHART_RENDER_OBJECT_CONFIG=ee,e.SHEET_FLOAT_DOM_PREFIX=ne,e.SaveCellImagesCommand=K,Object.defineProperty(e,"SheetCanvasFloatDomManagerService",{enumerable:!0,get:function(){return $}}),e.SheetDrawingAnchor=Ze,Object.defineProperty(e,"SheetDrawingHitTestService",{enumerable:!0,get:function(){return Ft}}),Object.defineProperty(e,"SheetDrawingUpdateController",{enumerable:!0,get:function(){return j}}),Object.defineProperty(e,"SheetsDrawingGroupCopyPasteController",{enumerable:!0,get:function(){return Z}}),e.SheetsDrawingUIMenuSchema=Ke,e.SidebarSheetDrawingOperation=J,e.UngroupSheetDrawingCommand=S,Object.defineProperty(e,"UniverSheetsDrawingUIPlugin",{enumerable:!0,get:function(){return It}}),e.calcSheetFloatDomPosition=Q,e.registerSheetsDrawingFloatingHostCapability=Fe});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing-ui",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.4",
4
4
  "private": false,
5
5
  "description": "Drawing UI integration for Univer Sheets.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -68,26 +68,27 @@
68
68
  "rxjs": ">=7.0.0"
69
69
  },
70
70
  "dependencies": {
71
- "@univerjs/core": "1.0.0-alpha.3",
72
- "@univerjs/docs-drawing": "1.0.0-alpha.3",
73
- "@univerjs/design": "1.0.0-alpha.3",
74
- "@univerjs/drawing": "1.0.0-alpha.3",
75
- "@univerjs/drawing-ui": "1.0.0-alpha.3",
76
- "@univerjs/docs-ui": "1.0.0-alpha.3",
77
- "@univerjs/engine-render": "1.0.0-alpha.3",
78
- "@univerjs/sheets": "1.0.0-alpha.3",
79
- "@univerjs/sheets-drawing": "1.0.0-alpha.3",
80
- "@univerjs/ui": "1.0.0-alpha.3",
81
- "@univerjs/sheets-ui": "1.0.0-alpha.3"
71
+ "@univerjs/core": "1.0.0-alpha.4",
72
+ "@univerjs/docs": "1.0.0-alpha.4",
73
+ "@univerjs/docs-drawing": "1.0.0-alpha.4",
74
+ "@univerjs/docs-ui": "1.0.0-alpha.4",
75
+ "@univerjs/drawing": "1.0.0-alpha.4",
76
+ "@univerjs/design": "1.0.0-alpha.4",
77
+ "@univerjs/drawing-ui": "1.0.0-alpha.4",
78
+ "@univerjs/engine-render": "1.0.0-alpha.4",
79
+ "@univerjs/sheets": "1.0.0-alpha.4",
80
+ "@univerjs/sheets-drawing": "1.0.0-alpha.4",
81
+ "@univerjs/sheets-ui": "1.0.0-alpha.4",
82
+ "@univerjs/ui": "1.0.0-alpha.4"
82
83
  },
83
84
  "devDependencies": {
84
- "postcss": "^8.5.16",
85
+ "postcss": "^8.5.19",
85
86
  "react": "18.3.1",
86
87
  "rxjs": "^7.8.2",
87
88
  "tailwindcss": "3.4.18",
88
89
  "typescript": "^6.0.3",
89
90
  "vitest": "^4.1.10",
90
- "@univerjs-infra/shared": "1.0.0-alpha.3"
91
+ "@univerjs-infra/shared": "1.0.0-alpha.4"
91
92
  },
92
93
  "scripts": {
93
94
  "test": "vitest run",