@univerjs/docs-drawing-ui 0.1.16 → 0.1.17

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
@@ -1 +1 @@
1
- "use strict";var fe=Object.defineProperty;var Ie=(e,n,t)=>n in e?fe(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var W=(e,n,t)=>Ie(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),O=require("@wendellhu/redi"),P=require("@univerjs/engine-render"),L=require("@univerjs/drawing-ui"),Z=require("rxjs"),G=require("@univerjs/docs-ui"),I=require("@univerjs/drawing"),m=require("@univerjs/docs-drawing"),S=require("@univerjs/ui"),b=require("@wendellhu/redi/react-bindings"),v=require("react"),F=require("clsx"),V=require("@univerjs/design"),Y=require("@univerjs/docs"),y={id:"sheet.operation.clear-drawing-transformer",type:a.CommandType.MUTATION,handler:(e,n)=>{const t=e.get(P.IRenderManagerService);return n.forEach(i=>{var r,o;(o=(r=t.getRenderById(i))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},k={id:"doc.command.remove-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(h=>{const{unitId:D}=h;s.push(D)});const c=r.getBatchRemoveOp(o),{unitId:d,subUnitId:u,undo:l,redo:g,objects:p}=c;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:d,subUnitId:u,op:g,objects:p,type:m.DocDrawingApplyType.REMOVE})?(i.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:l,objects:p,type:m.DocDrawingApplyType.INSERT}},{id:y.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:u,op:g,objects:p,type:m.DocDrawingApplyType.REMOVE}},{id:y.id,params:s}]}),!0):!1}},J="COMPONENT_DOC_DRAWING_PANEL",ee={id:"sidebar.operation.doc-image",type:a.CommandType.COMMAND,handler:async(e,n)=>{const t=e.get(S.ISidebarService),i=e.get(a.LocaleService),r=e.get(I.IDrawingManagerService);switch(n.value){case"open":t.open({header:{title:i.t("docImage.panel.title")},children:{label:J},onClose:()=>{r.focusDrawing(null)},width:360});break;case"close":default:t.close();break}return!0}},ne={id:"sheet.operation.edit-sheet-image",type:a.CommandType.OPERATION,handler:(e,n)=>{const t=e.get(I.IDrawingManagerService),i=e.get(a.ICommandService);return n==null?!1:(t.focusDrawing([n]),i.executeCommand(ee.id,{value:"open"}),!0)}};var he=Object.defineProperty,De=Object.getOwnPropertyDescriptor,ve=(e,n,t,i)=>{for(var r=i>1?void 0:i?De(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&he(n,t,r),r},U=(e,n)=>(t,i)=>n(t,i,e);let B=class extends a.RxDisposable{constructor(n,t,i,r,o){super();W(this,"_initImagePopupMenu",new Set);this._drawingManagerService=n,this._canvasPopManagerService=t,this._renderManagerService=i,this._univerInstanceService=r,this._contextService=o,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(Z.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(Z.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_DOC).forEach(n=>this._create(n))}_dispose(n){const t=n.getUnitId();this._renderManagerService.removeRender(t)}_create(n){if(!n)return;const t=n.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(n){const t=n.getAllObjects();for(const i of t)if(i instanceof L.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const t=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!t)return;const i=t.getTransformerByCreate();if(!i)return;const r=[];this.disposeWithMe(a.toDisposable(i.onCreateControlObservable.add(()=>{if(this._hasCropObject(t))return;const s=i.getSelectedObjectMap();if(s.size>1){r.forEach(f=>f.dispose());return}const c=s.values().next().value;if(!c)return;const d=c.oKey,u=this._drawingManagerService.getDrawingOKey(d);if(!u)return;const{unitId:l,subUnitId:g,drawingId:p}=u;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:L.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,g,p)}}))),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:g,drawingId:p}])}))),this.disposeWithMe(a.toDisposable(i.onClearControlObservable.add(()=>{r.forEach(s=>s.dispose()),this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(a.toDisposable(i.onChangingObservable.add(()=>{r.forEach(s=>s.dispose())})))}_getImageMenuItems(n,t,i){return[{label:"image-popup.edit",index:0,commandId:ne.id,commandParams:{unitId:n,subUnitId:t,drawingId:i},disable:!1},{label:"image-popup.delete",index:1,commandId:k.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:t,drawingId:i}]},disable:!1},{label:"image-popup.crop",index:2,commandId:L.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:t,drawingId:i},disable:!1},{label:"image-popup.reset",index:3,commandId:L.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:t,drawingId:i}],disable:!1}]}};B=ve([a.OnLifecycle(a.LifecycleStages.Rendered,B),U(0,I.IDrawingManagerService),U(1,O.Inject(G.DocCanvasPopManagerService)),U(2,P.IRenderManagerService),U(3,a.IUniverInstanceService),U(4,a.IContextService)],B);var _=function(){return _=Object.assign||function(e){for(var n,t=1,i=arguments.length;t<i;t++){n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},_.apply(this,arguments)},Se=function(e,n){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&n.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)n.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(t[i[r]]=e[i[r]]);return t},te=v.forwardRef(function(e,n){var t=e.icon,i=e.id,r=e.className,o=e.extend,s=Se(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),d=v.useRef("_".concat(ye()));return ie(t,"".concat(i),{defIds:t.defIds,idSuffix:d.current},_({ref:n,className:c},s),o)});function ie(e,n,t,i,r){return v.createElement(e.tag,_(_({key:n},we(e,t,r)),i),(_e(e,t).children||[]).map(function(o,s){return ie(o,"".concat(n,"-").concat(e.tag,"-").concat(s),t,void 0,r)}))}function we(e,n,t){var i=_({},e.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1);var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+n.idSuffix),Object.entries(i).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(i[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),i}function _e(e,n){var t,i=n.defIds;return!i||i.length===0?e:e.tag==="defs"&&(!((t=e.children)===null||t===void 0)&&t.length)?_(_({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?_(_({},r),{attrs:_(_({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function ye(){return Math.random().toString(36).substring(2,8)}te.displayName="UniverIcon";var Ce={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},re=v.forwardRef(function(e,n){return v.createElement(te,Object.assign({},e,{id:"add-image-single",ref:n,icon:Ce}))});re.displayName="AddImageSingle";const K={id:"doc.operation.insert-float-image",type:a.CommandType.OPERATION,handler:(e,n)=>!0},Me="univer-upload-file-menu",Oe="univer-upload-file-menu-input",Q={uploadFileMenu:Me,uploadFileMenuInput:Oe},Te=()=>{const e=b.useDependency(a.ICommandService),n=v.useRef(null),t=()=>{var o;(o=n.current)==null||o.click()},i=I.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(o=>`.${o.replace("image/","")}`).join(","),r=o=>{const s=o.target.files;if(s==null)return;const c=Array.from(s);e.executeCommand(K.id,{files:c}),n.current&&(n.current.value="")};return v.createElement("div",{onClick:t,className:Q.uploadFileMenu},v.createElement("input",{type:"file",className:Q.uploadFileMenuInput,ref:n,onChange:r,accept:i,multiple:!0}))},oe="COMPONENT_DOC_UPLOAD_FILE_MENU",ae="addition-and-subtraction-single",se="doc.menu.image";function Pe(e){return{id:se,type:S.MenuItemType.SUBITEMS,positions:[S.MenuPosition.TOOLBAR_START],group:S.MenuGroup.TOOLBAR_LAYOUT,icon:ae,tooltip:"docImage.title",hidden$:S.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}function Ee(e){return{id:K.id,title:"docImage.upload.float",type:S.MenuItemType.SELECTOR,label:{name:oe},positions:[se],hidden$:S.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_DOC)}}const Re="univer-image-common-panel",be="univer-image-common-panel-grid",Ae="univer-image-common-panel-border",Ue="univer-image-common-panel-title",Ne="univer-image-common-panel-row",Le="univer-image-common-panel-row-vertical",Ge="univer-image-common-panel-column",je="univer-image-common-panel-column-center",xe="univer-image-common-panel-inline",We="univer-image-common-panel-span2",Fe="univer-image-common-panel-span3",Ve="univer-image-common-panel-input",$e="univer-sheet-image-menu",Be="univer-sheet-image-menu-input",T={imageCommonPanel:Re,imageCommonPanelGrid:be,imageCommonPanelBorder:Ae,imageCommonPanelTitle:Ue,imageCommonPanelRow:Ne,imageCommonPanelRowVertical:Le,imageCommonPanelColumn:Ge,imageCommonPanelColumnCenter:je,imageCommonPanelInline:xe,imageCommonPanelSpan2:We,imageCommonPanelSpan3:Fe,imageCommonPanelInput:Ve,sheetImageMenu:$e,sheetImageMenuInput:Be},z={id:"doc.command.set-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,s=r.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:u,redo:l,objects:g}=s;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:g,type:m.DocDrawingApplyType.UPDATE})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:u,objects:g,type:m.DocDrawingApplyType.UPDATE}},{id:y.id,params:[c]}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:g,type:m.DocDrawingApplyType.UPDATE}},{id:y.id,params:[c]}]}),!0):!1}},He=e=>{b.useDependency(a.ICommandService);const n=b.useDependency(a.LocaleService),t=b.useDependency(I.IDrawingManagerService),i=b.useDependency(P.IRenderManagerService),{drawings:r}=e,o=r[0];if(o==null)return;const{unitId:s}=o,c=i.getRenderById(s),d=c==null?void 0:c.scene;if(d==null)return;const u=d.getTransformerByCreate(),[l,g]=v.useState(!0);v.useState("");function p(h,D){const w=[];return h.forEach(M=>{const{oKey:E}=M;if(D.getDrawingOKey(E)==null)return w.push(null),!0}),w}v.useEffect(()=>{const h=u.onClearControlObservable.add(w=>{w===!0&&g(!1)}),D=u.onChangeStartObservable.add(w=>{const{objects:M}=w;p(M,t)});return()=>{D==null||D.dispose(),h==null||h.dispose()}},[]);const f=h=>h?"block":"none";return v.createElement("div",{className:F(T.imageCommonPanelGrid,T.imageCommonPanelBorder),style:{display:f(l)}},v.createElement("div",{className:T.imageCommonPanelRow},v.createElement("div",{className:F(T.imageCommonPanelColumn,T.imageCommonPanelTitle)},v.createElement("div",null,n.t("drawing-anchor.title")))),v.createElement("div",{className:F(T.imageCommonPanelRow)},v.createElement("div",{className:F(T.imageCommonPanelColumn)})))},qe=()=>{const e=b.useDependency(I.IDrawingManagerService),n=e.getFocusDrawings(),[t,i]=v.useState(n);return v.useEffect(()=>{const r=e.focus$.subscribe(o=>{i(o)});return()=>{r.unsubscribe()}},[]),!!(t!=null&&t.length)&&v.createElement("div",{className:T.imageCommonPanel},v.createElement(L.DrawingCommonPanel,{drawings:t}),v.createElement(He,{drawings:t}))},j={id:"doc.command.move-drawing",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(m.IDocDrawingService),{direction:r}=n,o=i.getFocusDrawings();if(o.length===0)return!1;const s=o[0].unitId,c=o.map(u=>{const{transform:l}=u;if(l==null)return null;const g={...l},{left:p=0,top:f=0}=l;return r===a.Direction.UP?g.top=f-1:r===a.Direction.DOWN?g.top=f+1:r===a.Direction.LEFT?g.left=p-1:r===a.Direction.RIGHT&&(g.left=p+1),{...u,transform:g,docTransform:G.transformToDocDrawingPosition(g)}}).filter(u=>u!=null);return t.syncExecuteCommand(z.id,{unitId:s,drawings:c})?(t.syncExecuteCommand(y.id,[s]),!0):!1}},ce={id:"doc.command.delete-drawing",type:a.CommandType.COMMAND,handler:e=>{const n=e.get(a.ICommandService),i=e.get(m.IDocDrawingService).getFocusDrawings();if(i.length===0)return!1;const r=i[0].unitId,o=i.map(s=>{const{unitId:c,subUnitId:d,drawingId:u,drawingType:l}=s;return{unitId:c,subUnitId:d,drawingId:u,drawingType:l}});return n.executeCommand(k.id,{unitId:r,drawings:o})}},de={id:"doc.command.set-drawing-arrange",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService);if(!n)return!1;const r=e.get(m.IDocDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=n,u={unitId:o,subUnitId:s,drawingIds:c};let l;if(d===I.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(u):d===I.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(u):d===I.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(u):d===I.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(u)),l==null)return!1;const{objects:g,redo:p,undo:f}=l;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:p,unitId:o,subUnitId:s,objects:g,type:m.DocDrawingApplyType.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:f,unitId:o,subUnitId:s,objects:g,type:m.DocDrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:s,objects:g,type:m.DocDrawingApplyType.ARRANGE}}]}),!0):!1}};function Ke(e){const n=[];return e.forEach(t=>{const{parent:i,children:r}=t,{unitId:o,subUnitId:s,drawingId:c}=i,d=P.getGroupState(0,0,r.map(g=>g.transform||{})),u=r.map(g=>{const p=g.transform||{left:0,top:0},{unitId:f,subUnitId:h,drawingId:D}=g;return{unitId:f,subUnitId:h,drawingId:D,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:c}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:l,children:u})}),n}function ke(e){const n=[];return e.forEach(t=>{const{parent:i,children:r}=t,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=i;if(d==null)return;const u=r.map(g=>{const{transform:p}=g,{unitId:f,subUnitId:h,drawingId:D}=g,w=P.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:f,subUnitId:h,drawingId:D,transform:w,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:u})}),n}const ue={id:"doc.command.ungroup-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:f,children:h})=>{o.push(f.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:l,objects:g}=s;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.UNGROUP})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:Ke(g),type:m.DocDrawingApplyType.GROUP}},{id:y.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.UNGROUP}},{id:y.id,params:o}]}),!0):!1}},ge={id:"doc.command.group-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:f,children:h})=>{o.push(f.unitId),h.forEach(D=>{o.push(D.unitId)})});const s=r.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:u,redo:l,objects:g}=s;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.GROUP})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:d,objects:ke(g),type:m.DocDrawingApplyType.UNGROUP}},{id:y.id,params:o}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:g,type:m.DocDrawingApplyType.GROUP}},{id:y.id,params:o}]}),!0):!1}},me={id:"doc.command.insert-doc-image",type:a.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(a.ICommandService),i=e.get(a.IUndoRedoService),r=e.get(m.IDocDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(h=>h.unitId),c=r.getBatchAddOp(o),{unitId:d,subUnitId:u,undo:l,redo:g,objects:p}=c;return t.syncExecuteCommand(m.SetDocDrawingApplyMutation.id,{op:g,unitId:d,subUnitId:u,objects:p,type:m.DocDrawingApplyType.INSERT})?(i.pushUndoRedo({unitID:d,undoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:l,unitId:d,subUnitId:u,objects:p,type:m.DocDrawingApplyType.REMOVE}},{id:y.id,params:s}],redoMutations:[{id:m.SetDocDrawingApplyMutation.id,params:{op:g,unitId:d,subUnitId:u,objects:p,type:m.DocDrawingApplyType.INSERT}},{id:y.id,params:s}]}),!0):!1}};function x(e){return!e.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}const ze={id:j.id,description:"shortcut.doc.drawing-move-down",group:"4_doc-drawing-view",binding:S.KeyCode.ARROW_DOWN,priority:100,preconditions:x,staticParameters:{direction:a.Direction.DOWN}},Ze={id:j.id,description:"shortcut.doc.drawing-move-up",group:"4_doc-drawing-view",binding:S.KeyCode.ARROW_UP,priority:100,preconditions:x,staticParameters:{direction:a.Direction.UP}},Ye={id:j.id,description:"shortcut.doc.drawing-move-left",group:"4_doc-drawing-view",binding:S.KeyCode.ARROW_LEFT,priority:100,preconditions:x,staticParameters:{direction:a.Direction.LEFT}},Qe={id:j.id,description:"shortcut.doc.drawing-move-right",group:"4_doc-drawing-view",binding:S.KeyCode.ARROW_RIGHT,priority:100,preconditions:x,staticParameters:{direction:a.Direction.RIGHT}},Xe={id:ce.id,description:"shortcut.doc.drawing-delete",group:"4_doc-drawing-view",preconditions:x,binding:S.KeyCode.DELETE,mac:S.KeyCode.BACKSPACE};var Je=Object.defineProperty,en=Object.getOwnPropertyDescriptor,nn=(e,n,t,i)=>{for(var r=i>1?void 0:i?en(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&Je(n,t,r),r},N=(e,n)=>(t,i)=>n(t,i,e);let H=class extends a.Disposable{constructor(e,n,t,i,r){super(),this._injector=e,this._componentManager=n,this._menuService=t,this._commandService=i,this._shortcutService=r,this._init()}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(ae,re)),this.disposeWithMe(e.register(oe,Te)),this.disposeWithMe(e.register(J,qe))}_initMenus(){[Pe,Ee].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),{}))})}_initCommands(){[K,me,k,z,ee,y,ne,ge,ue,j,ce,de].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[ze,Ze,Ye,Qe,Xe].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};H=nn([a.OnLifecycle(a.LifecycleStages.Ready,H),N(0,O.Inject(O.Injector)),N(1,O.Inject(S.ComponentManager)),N(2,S.IMenuService),N(3,a.ICommandService),N(4,S.IShortcutService)],H);var tn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,on=(e,n,t,i)=>{for(var r=i>1?void 0:i?rn(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&tn(n,t,r),r},C=(e,n)=>(t,i)=>n(t,i,e);let q=class extends a.Disposable{constructor(e,n,t,i,r,o,s,c,d,u,l){super(),this._commandService=e,this._univerInstanceService=n,this._textSelectionManagerService=t,this._imageIoService=i,this._sheetDrawingService=r,this._drawingManagerService=o,this._contextService=s,this._messageService=c,this._localeService=d,this._docSkeletonManagerService=u,this._renderManagerService=l,this._init()}_init(){this._initCommandListeners(),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async e=>{if(e.id===K.id){const n=e.params;if(n.files==null)return;const t=n.files.length;if(t>I.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(I.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(t),n.files.forEach(async i=>{await this._insertFloatImage(i)})}}))}async _insertFloatImage(e){var E;let n;try{n=await this._imageIoService.saveImage(e)}catch(A){const R=A.message;R===I.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(I.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===I.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===I.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const t=this._getUnitInfo();if(t==null)return;const{unitId:i,subUnitId:r}=t,{imageId:o,imageSourceType:s,source:c,base64Cache:d}=n,{width:u,height:l,image:g}=await I.getImageSize(d||""),p=this._renderManagerService.getRenderById(i);if(p==null)return;const{width:f,height:h}=p.scene;this._imageIoService.addImageSourceCache(o,s,g);let D=1;if(u>I.DRAWING_IMAGE_WIDTH_LIMIT||l>I.DRAWING_IMAGE_HEIGHT_LIMIT){const A=I.DRAWING_IMAGE_WIDTH_LIMIT/u,R=I.DRAWING_IMAGE_HEIGHT_LIMIT/l;D=Math.max(A,R)}const w=this._getImagePosition(u*D,l*D,f,h);if(w==null)return;const M={unitId:i,subUnitId:r,drawingId:o,drawingType:I.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:c,transform:G.docDrawingPositionToTransform(w),docTransform:w,title:"",description:"",layoutType:a.PositionedObjectLayoutType.WRAP_SQUARE};this._commandService.executeCommand(me.id,{unitId:i,drawings:[M]}),(E=this._docSkeletonManagerService.getCurrent())==null||E.skeleton.calculate()}_getUnitInfo(){const e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(e==null)return;const n=e.getUnitId();return{unitId:n,subUnitId:n}}_getImagePosition(e,n,t,i){const r=this._textSelectionManagerService.getActiveTextRange(),o=(r==null?void 0:r.getAbsolutePosition())||{left:0,top:0};return{size:{width:e,height:n},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:o.left},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:o.top},angle:0}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t,drawingIds:i,arrangeType:r}=e;this._commandService.executeCommand(de.id,{unitId:n,subUnitId:t,drawingIds:i,arrangeType:r})})}_updateDrawingListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const n=[];e.length!==0&&(e.forEach(t=>{const{unitId:i,subUnitId:r,drawingId:o,drawingType:s,transform:c}=t;if(c==null)return;const d=this._sheetDrawingService.getDrawingByParam({unitId:i,subUnitId:r,drawingId:o});if(d==null)return;const u=G.transformToDocDrawingPosition({...d.transform,...c});if(u==null)return;const l={...t,transform:{...c,...G.docDrawingPositionToTransform(u)},docTransform:{...u}};n.push(l)}),n.length>0&&(this._commandService.syncExecuteCommand(z.id,{unitId:e[0].unitId,drawings:n}),this._refreshDocSkeleton()))})}_getDocsOffsetInfo(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{unitId:n,skeleton:t}=e,i=this._renderManagerService.getRenderById(n),r=t==null?void 0:t.getSkeletonData();if(i==null||!r)return{pageMarginCache:new Map,docsLeft:0,docsTop:0};const{mainComponent:o}=i,s=o,{left:c,top:d,pageLayoutType:u,pageMarginLeft:l,pageMarginTop:g}=s,{pages:p}=r,f=new P.Liquid,h=new Map;for(let D=0,w=p.length;D<w;D++){const M=p[D],{skeDrawings:E,marginLeft:A,marginTop:R}=M;f.translatePagePadding(M),E.forEach(le=>{const{aLeft:un,aTop:gn,height:mn,width:ln,drawingId:pe,drawingOrigin:pn}=le;h.set(pe,{marginLeft:f.x,marginTop:f.y})}),f.restorePagePadding(M),f.translatePage(M,u,l,g)}return{pageMarginCache:h,docsLeft:c,docsTop:d}}_refreshDocSkeleton(){const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:n,skeleton:t}=e,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:r}=i;t==null||t.calculate(),r==null||r.makeDirty()}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ge.id,e)}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(ue.id,e)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};q=on([a.OnLifecycle(a.LifecycleStages.Rendered,q),C(0,a.ICommandService),C(1,a.IUniverInstanceService),C(2,O.Inject(Y.TextSelectionManagerService)),C(3,I.IImageIoService),C(4,m.IDocDrawingService),C(5,I.IDrawingManagerService),C(6,a.IContextService),C(7,S.IMessageService),C(8,O.Inject(a.LocaleService)),C(9,O.Inject(Y.DocSkeletonManagerService)),C(10,P.IRenderManagerService)],q);var an=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,cn=(e,n,t,i)=>{for(var r=i>1?void 0:i?sn(n,t):n,o=e.length-1,s;o>=0;o--)(s=e[o])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&an(n,t,r),r},X=(e,n)=>(t,i)=>n(t,i,e);const dn="Docs_Drawing_UI_PLUGIN";var $;exports.UniverDocsDrawingUIPlugin=($=class extends a.Plugin{constructor(n,t,i){super(),this._injector=t,this._localeService=i}onStarting(n){this._initDependencies(n)}_initDependencies(n){[[H],[q],[B]].forEach(i=>n.add(i))}},W($,"type",a.UniverInstanceType.UNIVER_DOC),W($,"pluginName",dn),$);exports.UniverDocsDrawingUIPlugin=cn([X(1,O.Inject(O.Injector)),X(2,O.Inject(a.LocaleService))],exports.UniverDocsDrawingUIPlugin);
1
+ "use strict";var ue=Object.defineProperty;var me=(e,n,t)=>n in e?ue(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var V=(e,n,t)=>me(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),C=require("@wendellhu/redi"),O=require("@univerjs/drawing-ui"),I=require("@univerjs/drawing"),u=require("@univerjs/docs-drawing"),E=require("@univerjs/engine-render"),B=require("rxjs"),A=require("@univerjs/docs-ui"),v=require("@univerjs/ui"),P=require("@wendellhu/redi/react-bindings"),f=require("react"),N=require("clsx"),G=require("@univerjs/design"),H=require("@univerjs/docs"),_={id:"sheet.operation.clear-drawing-transformer",type:s.CommandType.MUTATION,handler:(e,n)=>{const t=e.get(E.IRenderManagerService);return n.forEach(i=>{var r,o;(o=(r=t.getRenderById(i))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},F={id:"doc.command.remove-doc-image",type:s.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(s.ICommandService),i=e.get(s.IUndoRedoService),r=e.get(u.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,a=[];o.forEach(h=>{const{unitId:w}=h;a.push(w)});const c=r.getBatchRemoveOp(o),{unitId:d,subUnitId:g,undo:l,redo:m,objects:p}=c;return t.syncExecuteCommand(u.SetDocDrawingApplyMutation.id,{unitId:d,subUnitId:g,op:m,objects:p,type:u.DocDrawingApplyType.REMOVE})?(i.pushUndoRedo({unitID:d,undoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:g,op:l,objects:p,type:u.DocDrawingApplyType.INSERT}},{id:_.id,params:a}],redoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{unitId:d,subUnitId:g,op:m,objects:p,type:u.DocDrawingApplyType.REMOVE}},{id:_.id,params:a}]}),!0):!1}},z="COMPONENT_DOC_DRAWING_PANEL",Z={id:"sidebar.operation.doc-image",type:s.CommandType.COMMAND,handler:async(e,n)=>{const t=e.get(v.ISidebarService),i=e.get(s.LocaleService),r=e.get(I.IDrawingManagerService);switch(n.value){case"open":t.open({header:{title:i.t("docImage.panel.title")},children:{label:z},onClose:()=>{r.focusDrawing(null)},width:360});break;case"close":default:t.close();break}return!0}},k={id:"sheet.operation.edit-sheet-image",type:s.CommandType.OPERATION,handler:(e,n)=>{const t=e.get(I.IDrawingManagerService),i=e.get(s.ICommandService);return n==null?!1:(t.focusDrawing([n]),i.executeCommand(Z.id,{value:"open"}),!0)}};var ge=Object.defineProperty,le=Object.getOwnPropertyDescriptor,pe=(e,n,t,i)=>{for(var r=i>1?void 0:i?le(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=(i?a(n,t,r):a(r))||r);return i&&r&&ge(n,t,r),r},T=(e,n)=>(t,i)=>n(t,i,e);let x=class extends s.RxDisposable{constructor(n,t,i,r,o){super();V(this,"_initImagePopupMenu",new Set);this._drawingManagerService=n,this._canvasPopManagerService=t,this._renderManagerService=i,this._univerInstanceService=r,this._contextService=o,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(s.UniverInstanceType.UNIVER_DOC).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(s.UniverInstanceType.UNIVER_DOC).forEach(n=>this._create(n))}_dispose(n){const t=n.getUnitId();this._renderManagerService.removeRender(t)}_create(n){if(!n)return;const t=n.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(n){const t=n.getAllObjects();for(const i of t)if(i instanceof O.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const t=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!t)return;const i=t.getTransformerByCreate();if(!i)return;const r=[];this.disposeWithMe(s.toDisposable(i.createControl$.subscribe(()=>{if(this._hasCropObject(t))return;const a=i.getSelectedObjectMap();if(a.size>1){r.forEach(D=>D.dispose());return}const c=a.values().next().value;if(!c)return;const d=c.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:l,subUnitId:m,drawingId:p}=g;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:O.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,m,p)}}))),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:m,drawingId:p}])}))),this.disposeWithMe(i.clearControl$.subscribe(()=>{r.forEach(a=>a.dispose()),this._contextService.setContextValue(s.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(i.changing$.subscribe(()=>{r.forEach(a=>a.dispose())}))}_getImageMenuItems(n,t,i){return[{label:"image-popup.edit",index:0,commandId:k.id,commandParams:{unitId:n,subUnitId:t,drawingId:i},disable:!1},{label:"image-popup.delete",index:1,commandId:F.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:t,drawingId:i}]},disable:!1},{label:"image-popup.crop",index:2,commandId:O.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:t,drawingId:i},disable:!1},{label:"image-popup.reset",index:3,commandId:O.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:t,drawingId:i}],disable:!1}]}};x=pe([s.OnLifecycle(s.LifecycleStages.Rendered,x),T(0,I.IDrawingManagerService),T(1,C.Inject(A.DocCanvasPopManagerService)),T(2,E.IRenderManagerService),T(3,s.IUniverInstanceService),T(4,s.IContextService)],x);var S=function(){return S=Object.assign||function(e){for(var n,t=1,i=arguments.length;t<i;t++){n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},S.apply(this,arguments)},Ie=function(e,n){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&n.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)n.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(t[i[r]]=e[i[r]]);return t},Y=f.forwardRef(function(e,n){var t=e.icon,i=e.id,r=e.className,o=e.extend,a=Ie(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),d=f.useRef("_".concat(ve()));return Q(t,"".concat(i),{defIds:t.defIds,idSuffix:d.current},S({ref:n,className:c},a),o)});function Q(e,n,t,i,r){return f.createElement(e.tag,S(S({key:n},fe(e,t,r)),i),(De(e,t).children||[]).map(function(o,a){return Q(o,"".concat(n,"-").concat(e.tag,"-").concat(a),t,void 0,r)}))}function fe(e,n,t){var i=S({},e.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1);var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+n.idSuffix),Object.entries(i).forEach(function(o){var a=o[0],c=o[1];typeof c=="string"&&(i[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),i}function De(e,n){var t,i=n.defIds;return!i||i.length===0?e:e.tag==="defs"&&(!((t=e.children)===null||t===void 0)&&t.length)?S(S({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?S(S({},r),{attrs:S(S({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function ve(){return Math.random().toString(36).substring(2,8)}Y.displayName="UniverIcon";var he={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},X=f.forwardRef(function(e,n){return f.createElement(Y,Object.assign({},e,{id:"add-image-single",ref:n,icon:he}))});X.displayName="AddImageSingle";const j={id:"doc.operation.insert-float-image",type:s.CommandType.OPERATION,handler:()=>!0},we="univer-upload-file-menu",Se="univer-upload-file-menu-input",q={uploadFileMenu:we,uploadFileMenuInput:Se},_e=()=>{const e=P.useDependency(s.ICommandService),n=f.useRef(null),t=()=>{var o;(o=n.current)==null||o.click()},i=I.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(o=>`.${o.replace("image/","")}`).join(","),r=o=>{const a=o.target.files;if(a==null)return;const c=Array.from(a);e.executeCommand(j.id,{files:c}),n.current&&(n.current.value="")};return f.createElement("div",{onClick:t,className:q.uploadFileMenu},f.createElement("input",{type:"file",className:q.uploadFileMenuInput,ref:n,onChange:r,accept:i,multiple:!0}))},J="COMPONENT_DOC_UPLOAD_FILE_MENU",ee="addition-and-subtraction-single",ne="doc.menu.image";function ye(e){return{id:ne,type:v.MenuItemType.SUBITEMS,positions:[v.MenuPosition.TOOLBAR_START],group:v.MenuGroup.TOOLBAR_LAYOUT,icon:ee,tooltip:"docImage.title",hidden$:v.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_DOC)}}function Ce(e){return{id:j.id,title:"docImage.upload.float",type:v.MenuItemType.SELECTOR,label:{name:J},positions:[ne],hidden$:v.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_DOC)}}const Me="univer-image-common-panel",Oe="univer-image-common-panel-grid",Pe="univer-image-common-panel-border",Ee="univer-image-common-panel-title",Te="univer-image-common-panel-row",Re="univer-image-common-panel-row-vertical",Ae="univer-image-common-panel-column",be="univer-image-common-panel-column-center",Ue="univer-image-common-panel-inline",Ne="univer-image-common-panel-span2",Ge="univer-image-common-panel-span3",xe="univer-image-common-panel-input",Le="univer-sheet-image-menu",je="univer-sheet-image-menu-input",M={imageCommonPanel:Me,imageCommonPanelGrid:Oe,imageCommonPanelBorder:Pe,imageCommonPanelTitle:Ee,imageCommonPanelRow:Te,imageCommonPanelRowVertical:Re,imageCommonPanelColumn:Ae,imageCommonPanelColumnCenter:be,imageCommonPanelInline:Ue,imageCommonPanelSpan2:Ne,imageCommonPanelSpan3:Ge,imageCommonPanelInput:xe,sheetImageMenu:Le,sheetImageMenuInput:je},$={id:"doc.command.set-doc-image",type:s.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(s.ICommandService),i=e.get(s.IUndoRedoService),r=e.get(u.IDocDrawingService);if(!n)return!1;const{drawings:o}=n,a=r.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:g,redo:l,objects:m}=a;return t.syncExecuteCommand(u.SetDocDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:m,type:u.DocDrawingApplyType.UPDATE})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:g,objects:m,type:u.DocDrawingApplyType.UPDATE}},{id:_.id,params:[c]}],redoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:m,type:u.DocDrawingApplyType.UPDATE}},{id:_.id,params:[c]}]}),!0):!1}},We=e=>{P.useDependency(s.ICommandService);const n=P.useDependency(s.LocaleService);P.useDependency(I.IDrawingManagerService);const t=P.useDependency(E.IRenderManagerService),{drawings:i}=e,r=i[0];if(r==null)return;const{unitId:o}=r,a=t.getRenderById(o),c=a==null?void 0:a.scene;if(c==null)return;const d=c.getTransformerByCreate(),[g,l]=f.useState(!0);f.useState(""),f.useEffect(()=>{const p=d.clearControl$.subscribe(D=>{D===!0&&l(!1)});return()=>{p.unsubscribe()}},[]);const m=p=>p?"block":"none";return f.createElement("div",{className:N(M.imageCommonPanelGrid,M.imageCommonPanelBorder),style:{display:m(g)}},f.createElement("div",{className:M.imageCommonPanelRow},f.createElement("div",{className:N(M.imageCommonPanelColumn,M.imageCommonPanelTitle)},f.createElement("div",null,n.t("drawing-anchor.title")))),f.createElement("div",{className:N(M.imageCommonPanelRow)},f.createElement("div",{className:N(M.imageCommonPanelColumn)})))},Fe=()=>{const e=P.useDependency(I.IDrawingManagerService),n=e.getFocusDrawings(),[t,i]=f.useState(n);return f.useEffect(()=>{const r=e.focus$.subscribe(o=>{i(o)});return()=>{r.unsubscribe()}},[]),!!(t!=null&&t.length)&&f.createElement("div",{className:M.imageCommonPanel},f.createElement(O.DrawingCommonPanel,{drawings:t}),f.createElement(We,{drawings:t}))},b={id:"doc.command.move-drawing",type:s.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(s.ICommandService),i=e.get(u.IDocDrawingService),{direction:r}=n,o=i.getFocusDrawings();if(o.length===0)return!1;const a=o[0].unitId,c=o.map(g=>{const{transform:l}=g;if(l==null)return null;const m={...l},{left:p=0,top:D=0}=l;return r===s.Direction.UP?m.top=D-1:r===s.Direction.DOWN?m.top=D+1:r===s.Direction.LEFT?m.left=p-1:r===s.Direction.RIGHT&&(m.left=p+1),{...g,transform:m,docTransform:A.transformToDocDrawingPosition(m)}}).filter(g=>g!=null);return t.syncExecuteCommand($.id,{unitId:a,drawings:c})?(t.syncExecuteCommand(_.id,[a]),!0):!1}},te={id:"doc.command.delete-drawing",type:s.CommandType.COMMAND,handler:e=>{const n=e.get(s.ICommandService),i=e.get(u.IDocDrawingService).getFocusDrawings();if(i.length===0)return!1;const r=i[0].unitId,o=i.map(a=>{const{unitId:c,subUnitId:d,drawingId:g,drawingType:l}=a;return{unitId:c,subUnitId:d,drawingId:g,drawingType:l}});return n.executeCommand(F.id,{unitId:r,drawings:o})}},ie={id:"doc.command.set-drawing-arrange",type:s.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(s.ICommandService),i=e.get(s.IUndoRedoService);if(!n)return!1;const r=e.get(u.IDocDrawingService),{unitId:o,subUnitId:a,drawingIds:c,arrangeType:d}=n,g={unitId:o,subUnitId:a,drawingIds:c};let l;if(d===I.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(g):d===I.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(g):d===I.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(g):d===I.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(g)),l==null)return!1;const{objects:m,redo:p,undo:D}=l;return t.syncExecuteCommand(u.SetDocDrawingApplyMutation.id,{op:p,unitId:o,subUnitId:a,objects:m,type:u.DocDrawingApplyType.ARRANGE})?(i.pushUndoRedo({unitID:o,undoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{op:D,unitId:o,subUnitId:a,objects:m,type:u.DocDrawingApplyType.ARRANGE}}],redoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:a,objects:m,type:u.DocDrawingApplyType.ARRANGE}}]}),!0):!1}};function $e(e){const n=[];return e.forEach(t=>{const{parent:i,children:r}=t,{unitId:o,subUnitId:a,drawingId:c}=i,d=E.getGroupState(0,0,r.map(m=>m.transform||{})),g=r.map(m=>{const p=m.transform||{left:0,top:0},{unitId:D,subUnitId:h,drawingId:w}=m;return{unitId:D,subUnitId:h,drawingId:w,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:c}}),l={unitId:o,subUnitId:a,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:l,children:g})}),n}function Ve(e){const n=[];return e.forEach(t=>{const{parent:i,children:r}=t,{unitId:o,subUnitId:a,drawingId:c,transform:d={width:0,height:0}}=i;if(d==null)return;const g=r.map(m=>{const{transform:p}=m,{unitId:D,subUnitId:h,drawingId:w}=m,de=E.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:D,subUnitId:h,drawingId:w,transform:de,groupId:void 0}}),l={unitId:o,subUnitId:a,drawingId:c,drawingType:I.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:g})}),n}const re={id:"doc.command.ungroup-doc-image",type:s.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(s.ICommandService),i=e.get(s.IUndoRedoService),r=e.get(u.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:D,children:h})=>{o.push(D.unitId),h.forEach(w=>{o.push(w.unitId)})});const a=r.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:g,redo:l,objects:m}=a;return t.syncExecuteCommand(u.SetDocDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:m,type:u.DocDrawingApplyType.UNGROUP})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{op:g,unitId:c,subUnitId:d,objects:$e(m),type:u.DocDrawingApplyType.GROUP}},{id:_.id,params:o}],redoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:m,type:u.DocDrawingApplyType.UNGROUP}},{id:_.id,params:o}]}),!0):!1}},oe={id:"doc.command.group-doc-image",type:s.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(s.ICommandService),i=e.get(s.IUndoRedoService),r=e.get(u.IDocDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:D,children:h})=>{o.push(D.unitId),h.forEach(w=>{o.push(w.unitId)})});const a=r.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:g,redo:l,objects:m}=a;return t.syncExecuteCommand(u.SetDocDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:m,type:u.DocDrawingApplyType.GROUP})?(i.pushUndoRedo({unitID:c,undoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{op:g,unitId:c,subUnitId:d,objects:Ve(m),type:u.DocDrawingApplyType.UNGROUP}},{id:_.id,params:o}],redoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:m,type:u.DocDrawingApplyType.GROUP}},{id:_.id,params:o}]}),!0):!1}},ae={id:"doc.command.insert-doc-image",type:s.CommandType.COMMAND,handler:(e,n)=>{const t=e.get(s.ICommandService),i=e.get(s.IUndoRedoService),r=e.get(u.IDocDrawingService);if(!n)return!1;const o=n.drawings,a=o.map(h=>h.unitId),c=r.getBatchAddOp(o),{unitId:d,subUnitId:g,undo:l,redo:m,objects:p}=c;return t.syncExecuteCommand(u.SetDocDrawingApplyMutation.id,{op:m,unitId:d,subUnitId:g,objects:p,type:u.DocDrawingApplyType.INSERT})?(i.pushUndoRedo({unitID:d,undoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{op:l,unitId:d,subUnitId:g,objects:p,type:u.DocDrawingApplyType.REMOVE}},{id:_.id,params:a}],redoMutations:[{id:u.SetDocDrawingApplyMutation.id,params:{op:m,unitId:d,subUnitId:g,objects:p,type:u.DocDrawingApplyType.INSERT}},{id:_.id,params:a}]}),!0):!1}};function U(e){return!e.getContextValue(s.FOCUSING_UNIVER_EDITOR)&&e.getContextValue(s.FOCUSING_COMMON_DRAWINGS)}const Be={id:b.id,description:"shortcut.doc.drawing-move-down",group:"4_doc-drawing-view",binding:v.KeyCode.ARROW_DOWN,priority:100,preconditions:U,staticParameters:{direction:s.Direction.DOWN}},He={id:b.id,description:"shortcut.doc.drawing-move-up",group:"4_doc-drawing-view",binding:v.KeyCode.ARROW_UP,priority:100,preconditions:U,staticParameters:{direction:s.Direction.UP}},qe={id:b.id,description:"shortcut.doc.drawing-move-left",group:"4_doc-drawing-view",binding:v.KeyCode.ARROW_LEFT,priority:100,preconditions:U,staticParameters:{direction:s.Direction.LEFT}},Ke={id:b.id,description:"shortcut.doc.drawing-move-right",group:"4_doc-drawing-view",binding:v.KeyCode.ARROW_RIGHT,priority:100,preconditions:U,staticParameters:{direction:s.Direction.RIGHT}},ze={id:te.id,description:"shortcut.doc.drawing-delete",group:"4_doc-drawing-view",preconditions:U,binding:v.KeyCode.DELETE,mac:v.KeyCode.BACKSPACE};var Ze=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,Ye=(e,n,t,i)=>{for(var r=i>1?void 0:i?ke(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=(i?a(n,t,r):a(r))||r);return i&&r&&Ze(n,t,r),r},R=(e,n)=>(t,i)=>n(t,i,e);let L=class extends s.Disposable{constructor(e,n,t,i,r){super(),this._injector=e,this._componentManager=n,this._menuService=t,this._commandService=i,this._shortcutService=r,this._init()}_initCustomComponents(){const e=this._componentManager;this.disposeWithMe(e.register(ee,X)),this.disposeWithMe(e.register(J,_e)),this.disposeWithMe(e.register(z,Fe))}_initMenus(){[ye,Ce].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e),{}))})}_initCommands(){[j,ae,F,$,Z,_,k,oe,re,b,te,ie].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[Be,He,qe,Ke,ze].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};L=Ye([s.OnLifecycle(s.LifecycleStages.Ready,L),R(0,C.Inject(C.Injector)),R(1,C.Inject(v.ComponentManager)),R(2,v.IMenuService),R(3,s.ICommandService),R(4,v.IShortcutService)],L);var Qe=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Je=(e,n,t,i)=>{for(var r=i>1?void 0:i?Xe(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=(i?a(n,t,r):a(r))||r);return i&&r&&Qe(n,t,r),r},y=(e,n)=>(t,i)=>n(t,i,e);let W=class extends s.Disposable{constructor(e,n,t,i,r,o,a,c,d,g){super(),this._context=e,this._commandService=n,this._textSelectionManagerService=t,this._docSkeletonManagerService=i,this._sheetDrawingService=r,this._imageIoService=o,this._drawingManagerService=a,this._contextService=c,this._messageService=d,this._localeService=g,this._initCommandListeners(),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async e=>{if(e.id===j.id){const n=e.params;if(n.files==null)return;const t=n.files.length;if(t>I.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(I.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(t),n.files.forEach(async i=>{await this._insertFloatImage(i)})}}))}async _insertFloatImage(e){var D;let n;try{n=await this._imageIoService.saveImage(e)}catch(h){const w=h.message;w===I.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(I.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):w===I.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):w===I.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{unitId:t}=this._context,{imageId:i,imageSourceType:r,source:o,base64Cache:a}=n,{width:c,height:d,image:g}=await I.getImageSize(a||"");this._imageIoService.addImageSourceCache(i,r,g);let l=1;if(c>I.DRAWING_IMAGE_WIDTH_LIMIT||d>I.DRAWING_IMAGE_HEIGHT_LIMIT){const h=I.DRAWING_IMAGE_WIDTH_LIMIT/c,w=I.DRAWING_IMAGE_HEIGHT_LIMIT/d;l=Math.max(h,w)}const m=this._getImagePosition(c*l,d*l);if(m==null)return;const p={unitId:t,subUnitId:t,drawingId:i,drawingType:I.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:r,source:o,transform:A.docDrawingPositionToTransform(m),docTransform:m,title:"",description:"",layoutType:s.PositionedObjectLayoutType.WRAP_SQUARE};this._commandService.executeCommand(ae.id,{unitId:t,drawings:[p]}),(D=this._docSkeletonManagerService.getSkeleton())==null||D.calculate()}_getImagePosition(e,n){const t=this._textSelectionManagerService.getActiveTextRange(),i=(t==null?void 0:t.getAbsolutePosition())||{left:0,top:0};return{size:{width:e,height:n},positionH:{relativeFrom:s.ObjectRelativeFromH.MARGIN,posOffset:i.left},positionV:{relativeFrom:s.ObjectRelativeFromV.PAGE,posOffset:i.top},angle:0}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t,drawingIds:i,arrangeType:r}=e;this._commandService.executeCommand(ie.id,{unitId:n,subUnitId:t,drawingIds:i,arrangeType:r})})}_updateDrawingListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{if(e.length===0)return;const n=[];if(e.forEach(t=>{const{unitId:i,subUnitId:r,drawingId:o,transform:a}=t;if(a==null)return;const c=this._sheetDrawingService.getDrawingByParam({unitId:i,subUnitId:r,drawingId:o});if(c==null)return;const d=A.transformToDocDrawingPosition({...c.transform,...a});if(d==null)return;const g={...t,transform:{...a,...A.docDrawingPositionToTransform(d)},docTransform:{...d}};n.push(g)}),n.length>0){const t=e[0].unitId;this._commandService.syncExecuteCommand($.id,{unitId:t,drawings:n}),this._refreshDocSkeleton()}})}_refreshDocSkeleton(){const e=this._docSkeletonManagerService.getSkeleton(),{mainComponent:n}=this._context;e==null||e.calculate(),n==null||n.makeDirty()}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{this._commandService.executeCommand(oe.id,e)}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{this._commandService.executeCommand(re.id,e)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(s.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(s.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};W=Je([y(1,s.ICommandService),y(2,C.Inject(H.TextSelectionManagerService)),y(3,C.Inject(H.DocSkeletonManagerService)),y(4,u.IDocDrawingService),y(5,I.IImageIoService),y(6,I.IDrawingManagerService),y(7,s.IContextService),y(8,v.IMessageService),y(9,C.Inject(s.LocaleService))],W);var se=Object.defineProperty,en=Object.getOwnPropertyDescriptor,nn=(e,n,t)=>n in e?se(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,tn=(e,n,t,i)=>{for(var r=i>1?void 0:i?en(n,t):n,o=e.length-1,a;o>=0;o--)(a=e[o])&&(r=(i?a(n,t,r):a(r))||r);return i&&r&&se(n,t,r),r},K=(e,n)=>(t,i)=>n(t,i,e),ce=(e,n,t)=>nn(e,typeof n!="symbol"?n+"":n,t);const rn="DOCS_DRAWING_UI_PLUGIN";exports.UniverDocsDrawingUIPlugin=class extends s.Plugin{constructor(n,t,i){super(),this._injector=t,this._renderManagerSrv=i}onStarting(n){[[L],[x]].forEach(i=>n.add(i))}onReady(){[W].forEach(n=>this._renderManagerSrv.registerRenderModule(s.UniverInstanceType.UNIVER_DOC,n))}};ce(exports.UniverDocsDrawingUIPlugin,"type",s.UniverInstanceType.UNIVER_DOC);ce(exports.UniverDocsDrawingUIPlugin,"pluginName",rn);exports.UniverDocsDrawingUIPlugin=tn([s.DependentOn(O.UniverDrawingUIPlugin,I.UniverDrawingPlugin,u.UniverDocsDrawingPlugin),K(1,C.Inject(C.Injector)),K(2,E.IRenderManagerService)],exports.UniverDocsDrawingUIPlugin);