@univerjs/sheets-drawing 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1 +1,678 @@
1
- import{CopySheetCommand as e,RemoveSheetCommand as t,SheetInterceptorService as n,convertPositionSheetOverGridToAbsolute as r}from"@univerjs/sheets";import{ArrangeTypeEnum as i,CommandType as a,DependentOn as o,Disposable as s,DrawingTypeEnum as c,ICommandService as l,IConfigService as u,IResourceManagerService as d,IUndoRedoService as f,IUniverInstanceService as p,Inject as m,Injector as h,Plugin as g,UniverInstanceType as _,createIdentifier as v,generateRandomId as y,merge as b,sequenceExecute as x}from"@univerjs/core";import{IDrawingManagerService as S,UnitDrawingService as C,UniverDrawingPlugin as w}from"@univerjs/drawing";import{IRenderManagerService as T}from"@univerjs/engine-render";function E(e,t){if(!t)return;let{unitId:n,sheetId:i,skeleton:a}=t,{from:o,to:s,flipY:c=!1,flipX:l=!1,angle:u=0,skewX:d=0,skewY:f=0}=e,{left:p,top:m,width:h,height:g}=r(n,i,{from:o,to:s},a),_=a.rowHeaderWidth+a.columnTotalWidth,v=a.columnHeaderHeight+a.rowTotalHeight;return p+h>_&&(p=_-h),m+g>v&&(m=v-g),{flipY:c,flipX:l,angle:u,skewX:d,skewY:f,left:p,top:m,width:h,height:g}}function D(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:l=0,skewY:u=0}=e;return{flipY:o,flipX:s,angle:c,skewX:l,skewY:u,from:t.getCellIndexAndOffsetByPosition(n,r),to:t.getCellIndexAndOffsetByPosition(n+i,r+a)}}function O(e,t){let{left:n=0,top:r=0,width:i=0,height:a=0,angle:o=0}=e,s=(o%360+360)%360;return D(s>=45&&s<135||s>=225&&s<315?{...e,left:n+i/2-a/2,top:r+a/2-i/2,width:a,height:i}:e,t)}let k=function(e){return e.Position=`0`,e.Both=`1`,e.None=`2`,e}({});var A=class extends C{};const j=v(`sheets-drawing.sheet-drawing.service`);let M=function(e){return e[e.INSERT=0]=`INSERT`,e[e.REMOVE=1]=`REMOVE`,e[e.UPDATE=2]=`UPDATE`,e[e.ARRANGE=3]=`ARRANGE`,e[e.GROUP=4]=`GROUP`,e[e.UNGROUP=5]=`UNGROUP`,e}({});const N={id:`sheet.mutation.set-drawing-apply`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(S),r=e.get(j),{op:i,unitId:a,subUnitId:o,type:s,objects:c}=t;switch(n.applyJson1(a,o,i),r.applyJson1(a,o,i),s){case M.INSERT:n.addNotification(c),r.addNotification(c);break;case M.REMOVE:n.removeNotification(c),r.removeNotification(c);break;case M.UPDATE:n.updateNotification(c),r.updateNotification(c);break;case M.ARRANGE:n.orderNotification(c),r.orderNotification(c);break;case M.GROUP:n.groupUpdateNotification(c),r.groupUpdateNotification(c);break;case M.UNGROUP:n.ungroupUpdateNotification(c),r.ungroupUpdateNotification(c);break}return!0}},P={id:`sheet.operation.clear-drawing-transformer`,type:a.MUTATION,handler:(e,t)=>{let n=e.get(T);return t.forEach(e=>{var t;(t=n.getRenderById(e))==null||(t=t.scene.getTransformer())==null||t.debounceRefreshControls()}),!0}},F={id:`sheet.command.insert-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),u=t.drawings,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchAddOp(u),_=c.onCommandExecute({id:F.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},I={id:`sheet.command.remove-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(n),c=e.get(j),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=c.getBatchRemoveOp(u),_=s.onCommandExecute({id:I.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.REMOVE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.INSERT}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}},L={id:`sheet.command.set-drawing-arrange`,type:a.COMMAND,handler:(e,t)=>{let n=e.get(l),r=e.get(f);if(!t)return!1;let a=e.get(j),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:u}=t,d={unitId:o,subUnitId:s,drawingIds:c},p;if(u===i.forward?p=a.getForwardDrawingsOp(d):u===i.backward?p=a.getBackwardDrawingOp(d):u===i.front?p=a.getFrontDrawingsOp(d):u===i.back&&(p=a.getBackDrawingsOp(d)),p==null)return!1;let{objects:m,redo:h,undo:g}=p;return n.syncExecuteCommand(N.id,{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE})?(r.pushUndoRedo({unitID:o,undoMutations:[{id:N.id,params:{op:g,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}],redoMutations:[{id:N.id,params:{op:h,unitId:o,subUnitId:s,objects:m,type:M.ARRANGE}}]}),!0):!1}},R={id:`sheet.command.set-sheet-image`,type:a.COMMAND,handler:(e,t)=>{var r,i;if(!t)return!1;let a=e.get(l),o=e.get(f),s=e.get(j),c=e.get(n),{drawings:u}=t,{unitId:d,subUnitId:p,undo:m,redo:h,objects:g}=s.getBatchUpdateOp(u),_=c.onCommandExecute({id:R.id,params:t}),v=[...(r=_.preRedos)==null?[]:r,{id:N.id,params:{unitId:d,subUnitId:p,op:h,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.redos],y=[...(i=_.preUndos)==null?[]:i,{id:N.id,params:{unitId:d,subUnitId:p,op:m,objects:g,type:M.UPDATE}},{id:P.id,params:[d]},..._.undos];return x(v,a)?(o.pushUndoRedo({unitID:d,undoMutations:y,redoMutations:v}),!0):!1}};function z(e,t){return function(n,r){t(n,r,e)}}function B(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}const V=`SHEET_DRAWING_PLUGIN`;let H=class extends s{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._commandService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._resourceManagerService=a,this._initCommands(),this._initSnapshot(),this._initSheetChange(),this.disposeWithMe(this._commandService.registerCommand(N))}_initCommands(){[R,F,I,L,P].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initSnapshot(){let e=(e,t)=>{let n=t||this._sheetDrawingService.getDrawingDataForUnit(e);return n?JSON.stringify(n):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:V,businesses:[_.UNIVER_SHEET],toJson:(t,n)=>e(t,n),parseJson:e=>t(e),onUnLoad:e=>{this._sheetDrawingService.removeDrawingDataForUnit(e),this._drawingManagerService.removeDrawingDataForUnit(e)},onLoad:(e,t)=>{this._sheetDrawingService.registerDrawingData(e,t),this._drawingManagerService.registerDrawingData(e,t)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>{if(n.id===t.id){var r;let e=n.params,t=e.unitId||this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getUnitId(),i=e.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!t||!i)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,i),o=Object.values(a).filter(e=>e.drawingType!==c.DRAWING_CHART);if(o.length===0)return{redos:[],undos:[]};let{unitId:s,subUnitId:l,undo:u,redo:d,objects:f}=this._sheetDrawingService.getBatchRemoveOp(o);return{redos:[{id:N.id,params:{op:d,unitId:s,subUnitId:l,objects:f,type:M.REMOVE}}],undos:[{id:N.id,params:{op:u,unitId:s,subUnitId:l,objects:f,type:M.INSERT}}]}}else if(n.id===e.id){let{unitId:e,subUnitId:t,targetSubUnitId:r}=n.params;if(!e||!t||!r)return{redos:[],undos:[]};let i=this._sheetDrawingService.getDrawingData(e,t),a=Object.values(i).filter(e=>e.drawingType!==c.DRAWING_CHART).map(e=>({...e,subUnitId:r,drawingId:y(6)}));if(a.length===0)return{redos:[],undos:[]};let{unitId:o,subUnitId:s,undo:l,redo:u,objects:d}=this._sheetDrawingService.getBatchAddOp(a);return{redos:[{id:N.id,params:{op:u,unitId:o,subUnitId:s,objects:d,type:M.INSERT}}],undos:[{id:N.id,params:{op:l,unitId:o,subUnitId:s,objects:d,type:M.REMOVE}}]}}return{redos:[],undos:[]}}}))}};H=B([z(0,m(n)),z(1,m(p)),z(2,l),z(3,j),z(4,S),z(5,d)],H);var U=`@univerjs/sheets-drawing`,W=`0.20.1`;const G=`sheets-drawing.config`;Symbol(G);const K={};function q(e){"@babel/helpers - typeof";return q=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},q(e)}function J(e,t){if(q(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(q(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Y(e){var t=J(e,`string`);return q(t)==`symbol`?t:t+``}function X(e,t,n){return(t=Y(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Z=class extends g{constructor(e=K,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=b({},K,this._config);this._configService.setConfig(G,r)}onStarting(){[[H],[j,{useClass:A}]].forEach(e=>this._injector.add(e)),this._injector.get(H)}};X(Z,`pluginName`,V),X(Z,`packageName`,U),X(Z,`version`,W),X(Z,`type`,_.UNIVER_SHEET),Z=B([o(w),z(1,m(h)),z(2,u)],Z);export{P as ClearSheetDrawingTransformerOperation,M as DrawingApplyType,j as ISheetDrawingService,F as InsertSheetDrawingCommand,I as RemoveSheetDrawingCommand,V as SHEET_DRAWING_PLUGIN,N as SetDrawingApplyMutation,L as SetDrawingArrangeCommand,R as SetSheetDrawingCommand,k as SheetDrawingAnchorType,Z as UniverSheetsDrawingPlugin,E as drawingPositionToTransform,O as transformToAxisAlignPosition,D as transformToDrawingPosition};
1
+ import { CopySheetCommand, RemoveSheetCommand, SheetInterceptorService, convertPositionSheetOverGridToAbsolute } from "@univerjs/sheets";
2
+ import { ArrangeTypeEnum, CommandType, DependentOn, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, Plugin, UniverInstanceType, createIdentifier, generateRandomId, merge, sequenceExecute } from "@univerjs/core";
3
+ import { IDrawingManagerService, UnitDrawingService, UniverDrawingPlugin } from "@univerjs/drawing";
4
+ import { IRenderManagerService } from "@univerjs/engine-render";
5
+
6
+ //#region src/basics/transform-position.ts
7
+ function drawingPositionToTransform(position, sheetSkeletonParam) {
8
+ if (!sheetSkeletonParam) return;
9
+ const { unitId, sheetId, skeleton } = sheetSkeletonParam;
10
+ const { from, to, flipY = false, flipX = false, angle = 0, skewX = 0, skewY = 0 } = position;
11
+ let { left, top, width, height } = convertPositionSheetOverGridToAbsolute(unitId, sheetId, {
12
+ from,
13
+ to
14
+ }, skeleton);
15
+ const sheetWidth = skeleton.rowHeaderWidth + skeleton.columnTotalWidth;
16
+ const sheetHeight = skeleton.columnHeaderHeight + skeleton.rowTotalHeight;
17
+ if (left + width > sheetWidth) left = sheetWidth - width;
18
+ if (top + height > sheetHeight) top = sheetHeight - height;
19
+ return {
20
+ flipY,
21
+ flipX,
22
+ angle,
23
+ skewX,
24
+ skewY,
25
+ left,
26
+ top,
27
+ width,
28
+ height
29
+ };
30
+ }
31
+ function transformToDrawingPosition(transform, skeleton) {
32
+ const { left = 0, top = 0, width = 0, height = 0, flipY = false, flipX = false, angle = 0, skewX = 0, skewY = 0 } = transform;
33
+ return {
34
+ flipY,
35
+ flipX,
36
+ angle,
37
+ skewX,
38
+ skewY,
39
+ from: skeleton.getCellIndexAndOffsetByPosition(left, top),
40
+ to: skeleton.getCellIndexAndOffsetByPosition(left + width, top + height)
41
+ };
42
+ }
43
+ /**
44
+ * In excel, the basic drawing with rotate bound use major axis switch, axis-aligned bound will bu used.That means the position bound of drawing element will save as nearly axis-aligned rectangle.
45
+ * Here is the rule to convert transform to axis-aligned position:
46
+ * [-45°, 45°): use the original bound
47
+ * [45°, 135°): rotate the bound 90° clockwise,and the left, top, bottom,right will use the rotated bound.
48
+ * [135°, 225°): use the original bound
49
+ * [225°, 315°): rotate the bound 90° counterclockwise, and the left, top, bottom, right will use the rotated bound.
50
+ * @return The axis-aligned position of the drawing element.
51
+ */
52
+ function transformToAxisAlignPosition(transform, skeleton) {
53
+ const { left = 0, top = 0, width = 0, height = 0, angle = 0 } = transform;
54
+ const norm = (angle % 360 + 360) % 360;
55
+ if (!(norm >= 45 && norm < 135 || norm >= 225 && norm < 315)) return transformToDrawingPosition(transform, skeleton);
56
+ return transformToDrawingPosition({
57
+ ...transform,
58
+ left: left + width / 2 - height / 2,
59
+ top: top + height / 2 - width / 2,
60
+ width: height,
61
+ height: width
62
+ }, skeleton);
63
+ }
64
+
65
+ //#endregion
66
+ //#region src/services/sheet-drawing.service.ts
67
+ let SheetDrawingAnchorType = /* @__PURE__ */ function(SheetDrawingAnchorType) {
68
+ /**
69
+ * Only the position of the drawing follows the cell changes. When rows or columns are inserted or deleted, the position of the drawing changes, but the size remains the same.
70
+ */
71
+ SheetDrawingAnchorType["Position"] = "0";
72
+ /**
73
+ * The size and position of the drawing follow the cell changes. When rows or columns are inserted or deleted, the size and position of the drawing change accordingly.
74
+ */
75
+ SheetDrawingAnchorType["Both"] = "1";
76
+ /**
77
+ * The size and position of the drawing do not follow the cell changes. When rows or columns are inserted or deleted, the position and size of the drawing remain unchanged.
78
+ */
79
+ SheetDrawingAnchorType["None"] = "2";
80
+ return SheetDrawingAnchorType;
81
+ }({});
82
+ var SheetDrawingService = class extends UnitDrawingService {};
83
+ const ISheetDrawingService = createIdentifier("sheets-drawing.sheet-drawing.service");
84
+
85
+ //#endregion
86
+ //#region src/commands/mutations/set-drawing-apply.mutation.ts
87
+ let DrawingApplyType = /* @__PURE__ */ function(DrawingApplyType) {
88
+ DrawingApplyType[DrawingApplyType["INSERT"] = 0] = "INSERT";
89
+ DrawingApplyType[DrawingApplyType["REMOVE"] = 1] = "REMOVE";
90
+ DrawingApplyType[DrawingApplyType["UPDATE"] = 2] = "UPDATE";
91
+ DrawingApplyType[DrawingApplyType["ARRANGE"] = 3] = "ARRANGE";
92
+ DrawingApplyType[DrawingApplyType["GROUP"] = 4] = "GROUP";
93
+ DrawingApplyType[DrawingApplyType["UNGROUP"] = 5] = "UNGROUP";
94
+ return DrawingApplyType;
95
+ }({});
96
+ const SetDrawingApplyMutation = {
97
+ id: "sheet.mutation.set-drawing-apply",
98
+ type: CommandType.MUTATION,
99
+ handler: (accessor, params) => {
100
+ const drawingManagerService = accessor.get(IDrawingManagerService);
101
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
102
+ const { op, unitId, subUnitId, type, objects } = params;
103
+ drawingManagerService.applyJson1(unitId, subUnitId, op);
104
+ sheetDrawingService.applyJson1(unitId, subUnitId, op);
105
+ switch (type) {
106
+ case DrawingApplyType.INSERT:
107
+ drawingManagerService.addNotification(objects);
108
+ sheetDrawingService.addNotification(objects);
109
+ break;
110
+ case DrawingApplyType.REMOVE:
111
+ drawingManagerService.removeNotification(objects);
112
+ sheetDrawingService.removeNotification(objects);
113
+ break;
114
+ case DrawingApplyType.UPDATE:
115
+ drawingManagerService.updateNotification(objects);
116
+ sheetDrawingService.updateNotification(objects);
117
+ break;
118
+ case DrawingApplyType.ARRANGE:
119
+ drawingManagerService.orderNotification(objects);
120
+ sheetDrawingService.orderNotification(objects);
121
+ break;
122
+ case DrawingApplyType.GROUP:
123
+ drawingManagerService.groupUpdateNotification(objects);
124
+ sheetDrawingService.groupUpdateNotification(objects);
125
+ break;
126
+ case DrawingApplyType.UNGROUP:
127
+ drawingManagerService.ungroupUpdateNotification(objects);
128
+ sheetDrawingService.ungroupUpdateNotification(objects);
129
+ break;
130
+ }
131
+ return true;
132
+ }
133
+ };
134
+
135
+ //#endregion
136
+ //#region src/commands/operations/clear-drawing-transformer.operation.ts
137
+ const ClearSheetDrawingTransformerOperation = {
138
+ id: "sheet.operation.clear-drawing-transformer",
139
+ type: CommandType.MUTATION,
140
+ handler: (accessor, params) => {
141
+ const renderManagerService = accessor.get(IRenderManagerService);
142
+ params.forEach((unitId) => {
143
+ var _renderManagerService;
144
+ (_renderManagerService = renderManagerService.getRenderById(unitId)) === null || _renderManagerService === void 0 || (_renderManagerService = _renderManagerService.scene.getTransformer()) === null || _renderManagerService === void 0 || _renderManagerService.debounceRefreshControls();
145
+ });
146
+ return true;
147
+ }
148
+ };
149
+
150
+ //#endregion
151
+ //#region src/commands/commands/insert-sheet-drawing.command.ts
152
+ const InsertSheetDrawingCommand = {
153
+ id: "sheet.command.insert-sheet-image",
154
+ type: CommandType.COMMAND,
155
+ handler: (accessor, params) => {
156
+ var _intercepted$preRedos, _intercepted$preUndos;
157
+ if (!params) return false;
158
+ const commandService = accessor.get(ICommandService);
159
+ const undoRedoService = accessor.get(IUndoRedoService);
160
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
161
+ const sheetInterceptorService = accessor.get(SheetInterceptorService);
162
+ const drawings = params.drawings;
163
+ const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchAddOp(drawings);
164
+ const intercepted = sheetInterceptorService.onCommandExecute({
165
+ id: InsertSheetDrawingCommand.id,
166
+ params
167
+ });
168
+ const redoMutations = [
169
+ ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
170
+ {
171
+ id: SetDrawingApplyMutation.id,
172
+ params: {
173
+ unitId,
174
+ subUnitId,
175
+ op: redo,
176
+ objects,
177
+ type: DrawingApplyType.INSERT
178
+ }
179
+ },
180
+ {
181
+ id: ClearSheetDrawingTransformerOperation.id,
182
+ params: [unitId]
183
+ },
184
+ ...intercepted.redos
185
+ ];
186
+ const undoMutations = [
187
+ ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
188
+ {
189
+ id: SetDrawingApplyMutation.id,
190
+ params: {
191
+ unitId,
192
+ subUnitId,
193
+ op: undo,
194
+ objects,
195
+ type: DrawingApplyType.REMOVE
196
+ }
197
+ },
198
+ {
199
+ id: ClearSheetDrawingTransformerOperation.id,
200
+ params: [unitId]
201
+ },
202
+ ...intercepted.undos
203
+ ];
204
+ if (sequenceExecute(redoMutations, commandService)) {
205
+ undoRedoService.pushUndoRedo({
206
+ unitID: unitId,
207
+ undoMutations,
208
+ redoMutations
209
+ });
210
+ return true;
211
+ }
212
+ return false;
213
+ }
214
+ };
215
+
216
+ //#endregion
217
+ //#region src/commands/commands/remove-sheet-drawing.command.ts
218
+ const RemoveSheetDrawingCommand = {
219
+ id: "sheet.command.remove-sheet-image",
220
+ type: CommandType.COMMAND,
221
+ handler: (accessor, params) => {
222
+ var _intercepted$preRedos, _intercepted$preUndos;
223
+ if (!params) return false;
224
+ const commandService = accessor.get(ICommandService);
225
+ const undoRedoService = accessor.get(IUndoRedoService);
226
+ const sheetInterceptorService = accessor.get(SheetInterceptorService);
227
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
228
+ const { drawings } = params;
229
+ const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchRemoveOp(drawings);
230
+ const intercepted = sheetInterceptorService.onCommandExecute({
231
+ id: RemoveSheetDrawingCommand.id,
232
+ params
233
+ });
234
+ const redoMutations = [
235
+ ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
236
+ {
237
+ id: SetDrawingApplyMutation.id,
238
+ params: {
239
+ unitId,
240
+ subUnitId,
241
+ op: redo,
242
+ objects,
243
+ type: DrawingApplyType.REMOVE
244
+ }
245
+ },
246
+ {
247
+ id: ClearSheetDrawingTransformerOperation.id,
248
+ params: [unitId]
249
+ },
250
+ ...intercepted.redos
251
+ ];
252
+ const undoMutations = [
253
+ ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
254
+ {
255
+ id: SetDrawingApplyMutation.id,
256
+ params: {
257
+ unitId,
258
+ subUnitId,
259
+ op: undo,
260
+ objects,
261
+ type: DrawingApplyType.INSERT
262
+ }
263
+ },
264
+ {
265
+ id: ClearSheetDrawingTransformerOperation.id,
266
+ params: [unitId]
267
+ },
268
+ ...intercepted.undos
269
+ ];
270
+ if (sequenceExecute(redoMutations, commandService)) {
271
+ undoRedoService.pushUndoRedo({
272
+ unitID: unitId,
273
+ undoMutations,
274
+ redoMutations
275
+ });
276
+ return true;
277
+ }
278
+ return false;
279
+ }
280
+ };
281
+
282
+ //#endregion
283
+ //#region src/commands/commands/set-drawing-arrange.command.ts
284
+ const SetDrawingArrangeCommand = {
285
+ id: "sheet.command.set-drawing-arrange",
286
+ type: CommandType.COMMAND,
287
+ handler: (accessor, params) => {
288
+ const commandService = accessor.get(ICommandService);
289
+ const undoRedoService = accessor.get(IUndoRedoService);
290
+ if (!params) return false;
291
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
292
+ const { unitId, subUnitId, drawingIds, arrangeType } = params;
293
+ const drawingOrderMapParam = {
294
+ unitId,
295
+ subUnitId,
296
+ drawingIds
297
+ };
298
+ let jsonOp;
299
+ if (arrangeType === ArrangeTypeEnum.forward) jsonOp = sheetDrawingService.getForwardDrawingsOp(drawingOrderMapParam);
300
+ else if (arrangeType === ArrangeTypeEnum.backward) jsonOp = sheetDrawingService.getBackwardDrawingOp(drawingOrderMapParam);
301
+ else if (arrangeType === ArrangeTypeEnum.front) jsonOp = sheetDrawingService.getFrontDrawingsOp(drawingOrderMapParam);
302
+ else if (arrangeType === ArrangeTypeEnum.back) jsonOp = sheetDrawingService.getBackDrawingsOp(drawingOrderMapParam);
303
+ if (jsonOp == null) return false;
304
+ const { objects, redo, undo } = jsonOp;
305
+ if (commandService.syncExecuteCommand(SetDrawingApplyMutation.id, {
306
+ op: redo,
307
+ unitId,
308
+ subUnitId,
309
+ objects,
310
+ type: DrawingApplyType.ARRANGE
311
+ })) {
312
+ undoRedoService.pushUndoRedo({
313
+ unitID: unitId,
314
+ undoMutations: [{
315
+ id: SetDrawingApplyMutation.id,
316
+ params: {
317
+ op: undo,
318
+ unitId,
319
+ subUnitId,
320
+ objects,
321
+ type: DrawingApplyType.ARRANGE
322
+ }
323
+ }],
324
+ redoMutations: [{
325
+ id: SetDrawingApplyMutation.id,
326
+ params: {
327
+ op: redo,
328
+ unitId,
329
+ subUnitId,
330
+ objects,
331
+ type: DrawingApplyType.ARRANGE
332
+ }
333
+ }]
334
+ });
335
+ return true;
336
+ }
337
+ return false;
338
+ }
339
+ };
340
+
341
+ //#endregion
342
+ //#region src/commands/commands/set-sheet-drawing.command.ts
343
+ const SetSheetDrawingCommand = {
344
+ id: "sheet.command.set-sheet-image",
345
+ type: CommandType.COMMAND,
346
+ handler: (accessor, params) => {
347
+ var _intercepted$preRedos, _intercepted$preUndos;
348
+ if (!params) return false;
349
+ const commandService = accessor.get(ICommandService);
350
+ const undoRedoService = accessor.get(IUndoRedoService);
351
+ const sheetDrawingService = accessor.get(ISheetDrawingService);
352
+ const sheetInterceptorService = accessor.get(SheetInterceptorService);
353
+ const { drawings } = params;
354
+ const { unitId, subUnitId, undo, redo, objects } = sheetDrawingService.getBatchUpdateOp(drawings);
355
+ const intercepted = sheetInterceptorService.onCommandExecute({
356
+ id: SetSheetDrawingCommand.id,
357
+ params
358
+ });
359
+ const redoMutations = [
360
+ ...(_intercepted$preRedos = intercepted.preRedos) !== null && _intercepted$preRedos !== void 0 ? _intercepted$preRedos : [],
361
+ {
362
+ id: SetDrawingApplyMutation.id,
363
+ params: {
364
+ unitId,
365
+ subUnitId,
366
+ op: redo,
367
+ objects,
368
+ type: DrawingApplyType.UPDATE
369
+ }
370
+ },
371
+ {
372
+ id: ClearSheetDrawingTransformerOperation.id,
373
+ params: [unitId]
374
+ },
375
+ ...intercepted.redos
376
+ ];
377
+ const undoMutations = [
378
+ ...(_intercepted$preUndos = intercepted.preUndos) !== null && _intercepted$preUndos !== void 0 ? _intercepted$preUndos : [],
379
+ {
380
+ id: SetDrawingApplyMutation.id,
381
+ params: {
382
+ unitId,
383
+ subUnitId,
384
+ op: undo,
385
+ objects,
386
+ type: DrawingApplyType.UPDATE
387
+ }
388
+ },
389
+ {
390
+ id: ClearSheetDrawingTransformerOperation.id,
391
+ params: [unitId]
392
+ },
393
+ ...intercepted.undos
394
+ ];
395
+ if (sequenceExecute(redoMutations, commandService)) {
396
+ undoRedoService.pushUndoRedo({
397
+ unitID: unitId,
398
+ undoMutations,
399
+ redoMutations
400
+ });
401
+ return true;
402
+ }
403
+ return false;
404
+ }
405
+ };
406
+
407
+ //#endregion
408
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
409
+ function __decorateParam(paramIndex, decorator) {
410
+ return function(target, key) {
411
+ decorator(target, key, paramIndex);
412
+ };
413
+ }
414
+
415
+ //#endregion
416
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
417
+ function __decorate(decorators, target, key, desc) {
418
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
419
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
420
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
421
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
422
+ }
423
+
424
+ //#endregion
425
+ //#region src/controllers/sheet-drawing.controller.ts
426
+ const SHEET_DRAWING_PLUGIN = "SHEET_DRAWING_PLUGIN";
427
+ let SheetsDrawingLoadController = class SheetsDrawingLoadController extends Disposable {
428
+ constructor(_sheetInterceptorService, _univerInstanceService, _commandService, _sheetDrawingService, _drawingManagerService, _resourceManagerService) {
429
+ super();
430
+ this._sheetInterceptorService = _sheetInterceptorService;
431
+ this._univerInstanceService = _univerInstanceService;
432
+ this._commandService = _commandService;
433
+ this._sheetDrawingService = _sheetDrawingService;
434
+ this._drawingManagerService = _drawingManagerService;
435
+ this._resourceManagerService = _resourceManagerService;
436
+ this._initCommands();
437
+ this._initSnapshot();
438
+ this._initSheetChange();
439
+ this.disposeWithMe(this._commandService.registerCommand(SetDrawingApplyMutation));
440
+ }
441
+ _initCommands() {
442
+ [
443
+ SetSheetDrawingCommand,
444
+ InsertSheetDrawingCommand,
445
+ RemoveSheetDrawingCommand,
446
+ SetDrawingArrangeCommand,
447
+ ClearSheetDrawingTransformerOperation
448
+ ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
449
+ }
450
+ _initSnapshot() {
451
+ const toJson = (unitId, model) => {
452
+ const map = model || this._sheetDrawingService.getDrawingDataForUnit(unitId);
453
+ if (map) return JSON.stringify(map);
454
+ return "";
455
+ };
456
+ const parseJson = (json) => {
457
+ if (!json) return {};
458
+ try {
459
+ return JSON.parse(json);
460
+ } catch {
461
+ return {};
462
+ }
463
+ };
464
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource({
465
+ pluginName: SHEET_DRAWING_PLUGIN,
466
+ businesses: [UniverInstanceType.UNIVER_SHEET],
467
+ toJson: (unitId, model) => toJson(unitId, model),
468
+ parseJson: (json) => parseJson(json),
469
+ onUnLoad: (unitId) => {
470
+ this._sheetDrawingService.removeDrawingDataForUnit(unitId);
471
+ this._drawingManagerService.removeDrawingDataForUnit(unitId);
472
+ },
473
+ onLoad: (unitId, value) => {
474
+ this._sheetDrawingService.registerDrawingData(unitId, value);
475
+ this._drawingManagerService.registerDrawingData(unitId, value);
476
+ }
477
+ }));
478
+ }
479
+ _initSheetChange() {
480
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
481
+ if (commandInfo.id === RemoveSheetCommand.id) {
482
+ var _getActiveSheet;
483
+ const params = commandInfo.params;
484
+ const unitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getUnitId();
485
+ const subUnitId = params.subUnitId || ((_getActiveSheet = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId());
486
+ if (!unitId || !subUnitId) return {
487
+ redos: [],
488
+ undos: []
489
+ };
490
+ const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
491
+ const drawings = Object.values(drawingData).filter((drawing) => {
492
+ if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) return false;
493
+ return true;
494
+ });
495
+ if (drawings.length === 0) return {
496
+ redos: [],
497
+ undos: []
498
+ };
499
+ const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = this._sheetDrawingService.getBatchRemoveOp(drawings);
500
+ return {
501
+ redos: [{
502
+ id: SetDrawingApplyMutation.id,
503
+ params: {
504
+ op: redo,
505
+ unitId: jsonOpUnitId,
506
+ subUnitId: jsonOpSubUnitId,
507
+ objects,
508
+ type: DrawingApplyType.REMOVE
509
+ }
510
+ }],
511
+ undos: [{
512
+ id: SetDrawingApplyMutation.id,
513
+ params: {
514
+ op: undo,
515
+ unitId: jsonOpUnitId,
516
+ subUnitId: jsonOpSubUnitId,
517
+ objects,
518
+ type: DrawingApplyType.INSERT
519
+ }
520
+ }]
521
+ };
522
+ } else if (commandInfo.id === CopySheetCommand.id) {
523
+ const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
524
+ if (!unitId || !subUnitId || !targetSubUnitId) return {
525
+ redos: [],
526
+ undos: []
527
+ };
528
+ const drawingData = this._sheetDrawingService.getDrawingData(unitId, subUnitId);
529
+ const drawings = Object.values(drawingData).filter((drawing) => {
530
+ if (drawing.drawingType === DrawingTypeEnum.DRAWING_CHART) return false;
531
+ return true;
532
+ }).map((drawing) => {
533
+ return {
534
+ ...drawing,
535
+ subUnitId: targetSubUnitId,
536
+ drawingId: generateRandomId(6)
537
+ };
538
+ });
539
+ if (drawings.length === 0) return {
540
+ redos: [],
541
+ undos: []
542
+ };
543
+ const { unitId: jsonOpUnitId, subUnitId: jsonOpSubUnitId, undo, redo, objects } = this._sheetDrawingService.getBatchAddOp(drawings);
544
+ return {
545
+ redos: [{
546
+ id: SetDrawingApplyMutation.id,
547
+ params: {
548
+ op: redo,
549
+ unitId: jsonOpUnitId,
550
+ subUnitId: jsonOpSubUnitId,
551
+ objects,
552
+ type: DrawingApplyType.INSERT
553
+ }
554
+ }],
555
+ undos: [{
556
+ id: SetDrawingApplyMutation.id,
557
+ params: {
558
+ op: undo,
559
+ unitId: jsonOpUnitId,
560
+ subUnitId: jsonOpSubUnitId,
561
+ objects,
562
+ type: DrawingApplyType.REMOVE
563
+ }
564
+ }]
565
+ };
566
+ }
567
+ return {
568
+ redos: [],
569
+ undos: []
570
+ };
571
+ } }));
572
+ }
573
+ };
574
+ SheetsDrawingLoadController = __decorate([
575
+ __decorateParam(0, Inject(SheetInterceptorService)),
576
+ __decorateParam(1, Inject(IUniverInstanceService)),
577
+ __decorateParam(2, ICommandService),
578
+ __decorateParam(3, ISheetDrawingService),
579
+ __decorateParam(4, IDrawingManagerService),
580
+ __decorateParam(5, IResourceManagerService)
581
+ ], SheetsDrawingLoadController);
582
+
583
+ //#endregion
584
+ //#region package.json
585
+ var name = "@univerjs/sheets-drawing";
586
+ var version = "0.21.0";
587
+
588
+ //#endregion
589
+ //#region src/config/config.ts
590
+ /**
591
+ * Copyright 2023-present DreamNum Co., Ltd.
592
+ *
593
+ * Licensed under the Apache License, Version 2.0 (the "License");
594
+ * you may not use this file except in compliance with the License.
595
+ * You may obtain a copy of the License at
596
+ *
597
+ * http://www.apache.org/licenses/LICENSE-2.0
598
+ *
599
+ * Unless required by applicable law or agreed to in writing, software
600
+ * distributed under the License is distributed on an "AS IS" BASIS,
601
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
602
+ * See the License for the specific language governing permissions and
603
+ * limitations under the License.
604
+ */
605
+ const SHEETS_DRAWING_PLUGIN_CONFIG_KEY = "sheets-drawing.config";
606
+ const configSymbol = Symbol(SHEETS_DRAWING_PLUGIN_CONFIG_KEY);
607
+ const defaultPluginConfig = {};
608
+
609
+ //#endregion
610
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
611
+ function _typeof(o) {
612
+ "@babel/helpers - typeof";
613
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
614
+ return typeof o;
615
+ } : function(o) {
616
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
617
+ }, _typeof(o);
618
+ }
619
+
620
+ //#endregion
621
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
622
+ function toPrimitive(t, r) {
623
+ if ("object" != _typeof(t) || !t) return t;
624
+ var e = t[Symbol.toPrimitive];
625
+ if (void 0 !== e) {
626
+ var i = e.call(t, r || "default");
627
+ if ("object" != _typeof(i)) return i;
628
+ throw new TypeError("@@toPrimitive must return a primitive value.");
629
+ }
630
+ return ("string" === r ? String : Number)(t);
631
+ }
632
+
633
+ //#endregion
634
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
635
+ function toPropertyKey(t) {
636
+ var i = toPrimitive(t, "string");
637
+ return "symbol" == _typeof(i) ? i : i + "";
638
+ }
639
+
640
+ //#endregion
641
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
642
+ function _defineProperty(e, r, t) {
643
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
644
+ value: t,
645
+ enumerable: !0,
646
+ configurable: !0,
647
+ writable: !0
648
+ }) : e[r] = t, e;
649
+ }
650
+
651
+ //#endregion
652
+ //#region src/plugin.ts
653
+ let UniverSheetsDrawingPlugin = class UniverSheetsDrawingPlugin extends Plugin {
654
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
655
+ super();
656
+ this._config = _config;
657
+ this._injector = _injector;
658
+ this._configService = _configService;
659
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
660
+ this._configService.setConfig(SHEETS_DRAWING_PLUGIN_CONFIG_KEY, rest);
661
+ }
662
+ onStarting() {
663
+ [[SheetsDrawingLoadController], [ISheetDrawingService, { useClass: SheetDrawingService }]].forEach((dependency) => this._injector.add(dependency));
664
+ this._injector.get(SheetsDrawingLoadController);
665
+ }
666
+ };
667
+ _defineProperty(UniverSheetsDrawingPlugin, "pluginName", SHEET_DRAWING_PLUGIN);
668
+ _defineProperty(UniverSheetsDrawingPlugin, "packageName", name);
669
+ _defineProperty(UniverSheetsDrawingPlugin, "version", version);
670
+ _defineProperty(UniverSheetsDrawingPlugin, "type", UniverInstanceType.UNIVER_SHEET);
671
+ UniverSheetsDrawingPlugin = __decorate([
672
+ DependentOn(UniverDrawingPlugin),
673
+ __decorateParam(1, Inject(Injector)),
674
+ __decorateParam(2, IConfigService)
675
+ ], UniverSheetsDrawingPlugin);
676
+
677
+ //#endregion
678
+ export { ClearSheetDrawingTransformerOperation, DrawingApplyType, ISheetDrawingService, InsertSheetDrawingCommand, RemoveSheetDrawingCommand, SHEET_DRAWING_PLUGIN, SetDrawingApplyMutation, SetDrawingArrangeCommand, SetSheetDrawingCommand, SheetDrawingAnchorType, UniverSheetsDrawingPlugin, drawingPositionToTransform, transformToAxisAlignPosition, transformToDrawingPosition };