@univerjs/preset-sheets-drawing 0.6.10 → 0.7.0-beta.1
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.css +1 -1
- package/lib/umd/index.js +24 -4
- package/package.json +10 -9
package/lib/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.univer-
|
|
1
|
+
.univer-h-9{height:36px}.univer-w-1\/2{width:50%}.univer-justify-center{justify-content:center}.univer-justify-between{justify-content:space-between}.univer-gap-2{gap:8px}.univer-rounded{border-radius:4px}.univer-border{border-width:1px}.univer-border-t-gray-200{border-top-color:var(--univer-gray-200)}.univer-bg-gray-100{background-color:var(--univer-gray-100)}.univer-bg-white{background-color:var(--univer-white)}.univer-fill-primary-600{fill:var(--univer-primary-600)}.univer-p-1{padding:4px}.univer-text-gray-900{color:var(--univer-gray-900)}.hover\:univer-bg-gray-100:hover{background-color:var(--univer-gray-100)}.univer-relative{position:relative}.univer-mt-2\.5{margin-top:10px}.univer-mt-5{margin-top:20px}.univer-flex{display:flex}.univer-h-full{height:100%}.univer-w-full{width:100%}.univer-items-start{align-items:flex-start}.univer-items-center{align-items:center}.univer-justify-start{justify-content:flex-start}.univer-gap-1{gap:4px}.univer-border-b-0{border-bottom-width:0px}.univer-border-l-0{border-left-width:0px}.univer-border-r-0{border-right-width:0px}.univer-border-t{border-top-width:1px}.univer-border-solid{border-style:solid}.univer-border-gray-200{border-color:var(--univer-gray-200)}.univer-p-2{padding:8px}.univer-text-left{text-align:left}.univer-text-center{text-align:center}.univer-text-sm{font-size:14px;line-height:20px}.univer-text-gray-400{color:var(--univer-gray-400)}
|
package/lib/umd/index.js
CHANGED
|
@@ -3,11 +3,24 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
// @univerjs/drawing-ui/index
|
|
6
|
-
(function(D,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react/jsx-runtime"),require("react"),require("@univerjs/design"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/drawing","@univerjs/engine-render","@univerjs/ui","react/jsx-runtime","react","@univerjs/design","rxjs"],h):(D=typeof globalThis<"u"?globalThis:D||self,h(D.UniverDrawingUi={},D.UniverCore,D.UniverDrawing,D.UniverEngineRender,D.UniverUi,D.React,D.React,D.UniverDesign,D.rxjs))})(this,function(D,h,M,b,V,l,_,I,Me){"use strict";var Rn=Object.defineProperty;var Ln=(D,h,M)=>h in D?Rn(D,h,{enumerable:!0,configurable:!0,writable:!0,value:M}):D[h]=M;var ee=(D,h,M)=>Ln(D,typeof h!="symbol"?h+"":h,M);var Pe;function Oe(a,t,n,e){const r=e.getDrawingByParam(a);if(r==null)return;const s=M.getDrawingShapeKeyByDrawingSearch(a),i=n.getObject(s);if(i&&!(i instanceof b.Group))return;if(i!=null){i.addObject(t);return}const o=new b.Group(s);n.addObject(o,b.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(o),o.addObject(t);const{transform:c}=r;c&&o.transformByState({left:c.left,top:c.top,angle:c.angle})}function Ne(a,t){var s;const n=t?a.getUnit(t):a.getFocusedUnit();if(n==null)return;const e=n.getUnitId();let r;return n.type===h.UniverInstanceType.UNIVER_SHEET?r=(s=n.getActiveSheet())==null?void 0:s.getSheetId():(n.type===h.UniverInstanceType.UNIVER_DOC||n.type===h.UniverInstanceType.UNIVER_SLIDE)&&(r=e),{unitId:e,subUnitId:r,current:n}}const Ee="COMPONENT_IMAGE_VIEWER";var Ye=Object.getOwnPropertyDescriptor,Ze=(a,t,n,e)=>{for(var r=e>1?void 0:e?Ye(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},ye=(a,t)=>(n,e)=>t(n,e,a);const Te=50;D.DrawingRenderService=class{constructor(t,n,e){this._drawingManagerService=t,this._imageIoService=n,this._dialogService=e}async renderImages(t,n){const{transform:e,drawingType:r,source:s,imageSourceType:i,srcRect:o,prstGeom:c,groupId:g,unitId:d,subUnitId:u,drawingId:f,isMultiTransform:p,transforms:S}=t;if(r!==h.DrawingTypeEnum.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||e==null)return;const v=p&&S?S:[e],C=[];for(const P of v){const{left:y,top:U,width:O,height:R,angle:T,flipX:N,flipY:E,skewX:B,skewY:j}=P,G=v.indexOf(P),x=M.getDrawingShapeKeyByDrawingSearch({unitId:d,subUnitId:u,drawingId:f},p?G:void 0),F=n.getObject(x);if(F!=null){F.transformByState({left:y,top:U,width:O,height:R,angle:T,flipX:N,flipY:E,skewX:B,skewY:j});continue}const z=this._drawingManagerService.getDrawingOrder(d,u),ce=z.indexOf(f),ae={...P,zIndex:ce===-1?z.length-1:ce},ie=this._imageIoService.getImageSourceCache(s,i);let le=!1;if(ie!=null)ae.image=ie;else{if(i===M.ImageSourceType.UUID)try{ae.url=await this._imageIoService.getImage(s)}catch(De){console.error(De);continue}else ae.url=s;le=!0}if(n.getObject(x))continue;ae.printable=!0;const J=new b.Image(x,ae);le&&this._imageIoService.addImageSourceCache(s,i,J.getNative()),this._drawingManagerService.getDrawingVisible()&&(n.addObject(J,b.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&n.attachTransformerTo(J),g&&Oe({drawingId:g,unitId:d,subUnitId:u},J,n,this._drawingManagerService),c!=null&&J.setPrstGeom(c),o!=null&&J.setSrcRect(o),C.push(J))}return C}renderFloatDom(t,n){const{transform:e,drawingType:r,groupId:s,unitId:i,subUnitId:o,drawingId:c,isMultiTransform:g,transforms:d}=t;if(r!==h.DrawingTypeEnum.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||e==null)return;const u=g&&d?d:[e],f=[];for(const p of u){const{left:S,top:v,width:C,height:P,angle:y,flipX:U,flipY:O,skewX:R,skewY:T}=p,N=u.indexOf(p),E=M.getDrawingShapeKeyByDrawingSearch({unitId:i,subUnitId:o,drawingId:c},g?N:void 0),B=n.getObject(E);if(B!=null){B.transformByState({left:S,top:v,width:C,height:P,angle:y,flipX:U,flipY:O,skewX:R,skewY:T});continue}const j=this._drawingManagerService.getDrawingOrder(i,o),G=j.indexOf(c),x={...p,zIndex:G===-1?j.length-1:G};if(n.getObject(E))continue;x.printable=!1;const F=new b.Rect(E,x);this._drawingManagerService.getDrawingVisible()&&(n.addObject(F,b.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&t.allowTransform!==!1&&n.attachTransformerTo(F),s&&Oe({drawingId:s,unitId:i,subUnitId:o},F,n,this._drawingManagerService),f.push(F))}return f}renderDrawing(t,n){const e=this._drawingManagerService.getDrawingByParam(t);if(e!=null)switch(e.drawingType){case h.DrawingTypeEnum.DRAWING_IMAGE:return this.renderImages(e,n)}}previewImage(t,n,e,r){const s=`${t}-viewer-dialog`,i=window.innerWidth-Te,o=window.innerHeight-Te,c=this._adjustImageSize(e,r,i,o),g=this._dialogService.open({width:Math.max(c.width,200),id:s,style:{margin:"0",top:"50%",left:"50%",transform:"translate(-50%, -50%)"},children:{label:{name:Ee,props:{src:n,width:c.width,height:c.height}}},destroyOnClose:!0,draggable:!1,onClose:()=>{this._dialogService.close(s),g.dispose()}})}_adjustImageSize(t,n,e,r){if(t<=e&&n<=r)return{width:t,height:n};const s=e/t,i=r/n,o=Math.min(s,i);return{width:Math.floor(t*o),height:Math.floor(n*o)}}},D.DrawingRenderService=Ze([ye(0,M.IDrawingManagerService),ye(1,M.IImageIoService),ye(2,V.IDialogService)],D.DrawingRenderService);function ge(a,t){const n=[];return a.forEach(e=>{const{oKey:r,left:s,top:i,height:o,width:c,angle:g}=e,d=t.getDrawingOKey(r);if(d==null)return n.push(null),!0;const{unitId:u,subUnitId:f,drawingId:p,drawingType:S}=d,v={unitId:u,subUnitId:f,drawingId:p,drawingType:S,transform:{left:s,top:i,height:o,width:c,angle:g}};S===h.DrawingTypeEnum.DRAWING_IMAGE&&(v.srcRect=e.srcRect),n.push(v)}),n}var A=(a=>(a.default="0",a.left="1",a.center="2",a.right="3",a.top="4",a.middle="5",a.bottom="6",a.horizon="7",a.vertical="8",a))(A||{});const fe={id:"sheet.operation.set-image-align",type:h.CommandType.OPERATION,handler:(a,t)=>!0},m={imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input"},Xe=a=>{const t=V.useDependency(h.ICommandService),n=V.useDependency(h.LocaleService),{alignShow:e}=a,[r,s]=_.useState(A.default),i=[{label:n.t("image-panel.align.default"),value:A.default},{options:[{label:n.t("image-panel.align.left"),value:A.left},{label:n.t("image-panel.align.center"),value:A.center},{label:n.t("image-panel.align.right"),value:A.right}]},{options:[{label:n.t("image-panel.align.top"),value:A.top},{label:n.t("image-panel.align.middle"),value:A.middle},{label:n.t("image-panel.align.bottom"),value:A.bottom}]},{options:[{label:n.t("image-panel.align.horizon"),value:A.horizon},{label:n.t("image-panel.align.vertical"),value:A.vertical}]}];function o(g){s(g),t.executeCommand(fe.id,{alignType:g})}const c=g=>g?"block":"none";return l.jsxs("div",{className:I.clsx(m.imageCommonPanelGrid,m.imageCommonPanelBorder),style:{display:c(e)},children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelTitle),children:l.jsx("div",{children:n.t("image-panel.align.title")})})}),l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn),children:l.jsx(I.Select,{value:r,options:i,onChange:o})})})]})};var K=function(){return K=Object.assign||function(a){for(var t,n=1,e=arguments.length;n<e;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(a[r]=t[r])}return a},K.apply(this,arguments)},qe=function(a,t){var n={};for(var e in a)Object.prototype.hasOwnProperty.call(a,e)&&t.indexOf(e)<0&&(n[e]=a[e]);if(a!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,e=Object.getOwnPropertySymbols(a);r<e.length;r++)t.indexOf(e[r])<0&&Object.prototype.propertyIsEnumerable.call(a,e[r])&&(n[e[r]]=a[e[r]]);return n},X=_.forwardRef(function(a,t){var n=a.icon,e=a.id,r=a.className,s=a.extend,i=qe(a,["icon","id","className","extend"]),o="univerjs-icon univerjs-icon-".concat(e," ").concat(r||"").trim(),c=_.useRef("_".concat(en()));return Be(n,"".concat(e),{defIds:n.defIds,idSuffix:c.current},K({ref:t,className:o},i),s)});function Be(a,t,n,e,r){return _.createElement(a.tag,K(K({key:t},Je(a,n,r)),e),(Qe(a,n).children||[]).map(function(s,i){return Be(s,"".concat(t,"-").concat(a.tag,"-").concat(i),n,void 0,r)}))}function Je(a,t,n){var e=K({},a.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1),a.tag==="mask"&&e.id&&(e.id=e.id+t.idSuffix),Object.entries(e).forEach(function(s){var i=s[0],o=s[1];i==="mask"&&typeof o=="string"&&(e[i]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.length===0||(a.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+t.idSuffix),Object.entries(e).forEach(function(s){var i=s[0],o=s[1];typeof o=="string"&&(e[i]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),e}function Qe(a,t){var n,e=t.defIds;return!e||e.length===0?a:a.tag==="defs"&&(!((n=a.children)===null||n===void 0)&&n.length)?K(K({},a),{children:a.children.map(function(r){return typeof r.attrs.id=="string"&&e&&e.indexOf(r.attrs.id)>-1?K(K({},r),{attrs:K(K({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):a}function en(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";var nn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365zM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377zM2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365zM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647zM9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635zM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ue=_.forwardRef(function(a,t){return _.createElement(X,Object.assign({},a,{id:"autofill",ref:t,icon:nn}))});Ue.displayName="Autofill";var tn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.0045 4.4334C14.8881 4.4334 15.6045 3.71705 15.6045 2.8334 15.6045 1.94974 14.8881 1.2334 14.0045 1.2334H3.70449C2.82084 1.2334 2.10449 1.94974 2.10449 2.8334 2.10449 3.71705 2.82084 4.4334 3.70449 4.4334H14.0045zM14.4045 2.8334C14.4045 3.05431 14.2254 3.2334 14.0045 3.2334H3.70449C3.48358 3.2334 3.30449 3.05431 3.30449 2.8334 3.30449 2.61248 3.48358 2.4334 3.70449 2.4334H14.0045C14.2254 2.4334 14.4045 2.61249 14.4045 2.8334zM14.1544 8.5999C15.038 8.5999 15.7544 7.88356 15.7544 6.9999 15.7544 6.11625 15.038 5.3999 14.1544 5.3999H3.85439C2.97074 5.3999 2.25439 6.11625 2.25439 6.9999 2.25439 7.88356 2.97074 8.5999 3.85439 8.5999H14.1544zM14.5544 6.9999C14.5544 7.22082 14.3753 7.3999 14.1544 7.3999H3.85439C3.63348 7.3999 3.45439 7.22082 3.45439 6.9999 3.45439 6.77899 3.63348 6.5999 3.85439 6.5999H14.1544C14.3753 6.5999 14.5544 6.77899 14.5544 6.9999z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.57975 14.5902L6.58023 12.5907C6.34591 12.3564 6.34591 11.9765 6.58023 11.7421 6.81454 11.5078 7.19444 11.5078 7.42876 11.7421L8.40449 12.7179V10.1664C8.40449 9.83504 8.67312 9.56641 9.00449 9.56641 9.33586 9.56641 9.60449 9.83504 9.60449 10.1664V12.7179L10.5802 11.7421C10.8145 11.5078 11.1944 11.5078 11.4288 11.7421 11.6631 11.9765 11.6631 12.3564 11.4288 12.5907L9.42923 14.5902M8.57975 14.5902C8.58121 14.5917 8.58268 14.5931 8.58416 14.5946 8.64077 14.6502 8.70566 14.6923 8.77482 14.7209 8.84557 14.7502 8.92314 14.7664 9.00449 14.7664 9.08585 14.7664 9.16342 14.7502 9.23416 14.7209 9.30332 14.6923 9.36821 14.6502 9.42482 14.5946"}}]},je=_.forwardRef(function(a,t){return _.createElement(X,Object.assign({},a,{id:"bottom-single",ref:t,icon:tn}))});je.displayName="BottomSingle";var rn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.97705 7.51296C5.97705 7.18159 6.24568 6.91296 6.57705 6.91296H8.48632C8.81769 6.91296 9.08632 7.18159 9.08632 7.51296 9.08632 7.84433 8.81769 8.11296 8.48632 8.11296H6.57705C6.24568 8.11296 5.97705 7.84433 5.97705 7.51296zM6.57705 9.41028C6.24568 9.41028 5.97705 9.67891 5.97705 10.0103 5.97705 10.3416 6.24568 10.6103 6.57705 10.6103H10.8199C11.1512 10.6103 11.4199 10.3416 11.4199 10.0103 11.4199 9.67891 11.1512 9.41028 10.8199 9.41028H6.57705z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.51074 2.37063C3.51074 1.48697 4.22709 0.77063 5.11074 0.77063H9.80318L9.81294 0.770708C9.97168 0.768161 10.1311 0.82824 10.2511 0.95055L14.4317 5.21408C14.5165 5.30049 14.5697 5.406 14.5917 5.51645C14.6041 5.5644 14.6106 5.61467 14.6106 5.66648V11.6406C14.6106 12.5243 13.8943 13.2406 13.0106 13.2406H5.11074C4.22709 13.2406 3.51074 12.5243 3.51074 11.6406V2.37063ZM10.4032 4.66648V2.81964L12.6063 5.06648H10.8032C10.5823 5.06648 10.4032 4.88739 10.4032 4.66648ZM5.11074 1.97063C4.88983 1.97063 4.71074 2.14972 4.71074 2.37063V11.6406C4.71074 11.8615 4.88983 12.0406 5.11074 12.0406H13.0106C13.2316 12.0406 13.4106 11.8615 13.4106 11.6406V6.26648H10.8032C9.91953 6.26648 9.20318 5.55013 9.20318 4.66648V1.97063H5.11074Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.58916 6.6741C2.58916 6.34273 2.32053 6.0741 1.98916 6.0741C1.65779 6.0741 1.38916 6.34273 1.38916 6.6741V12.6294C1.38916 14.0653 2.55322 15.2294 3.98916 15.2294H9.41408C9.74545 15.2294 10.0141 14.9607 10.0141 14.6294C10.0141 14.298 9.74545 14.0294 9.41408 14.0294H3.98916C3.21596 14.0294 2.58916 13.4026 2.58916 12.6294V6.6741Z"}}]},Ae=_.forwardRef(function(a,t){return _.createElement(X,Object.assign({},a,{id:"create-copy-single",ref:t,icon:rn}))});Ae.displayName="CreateCopySingle";var an={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.38125 1.16211C6.49759 1.16211 5.78125 1.87845 5.78125 2.76211V5.6377H2.87783C1.99418 5.6377 1.27783 6.35404 1.27783 7.2377V13.2377C1.27783 14.1214 1.99418 14.8377 2.87783 14.8377H8.87783C9.76149 14.8377 10.4778 14.1214 10.4778 13.2377V10.3621H13.3813C14.2649 10.3621 14.9813 9.64577 14.9813 8.76211V2.76211C14.9813 1.87845 14.2649 1.16211 13.3813 1.16211H7.38125ZM10.4778 9.16211H13.3813C13.6022 9.16211 13.7812 8.98302 13.7812 8.76211V2.76211C13.7812 2.5412 13.6022 2.36211 13.3813 2.36211H7.38125C7.16034 2.36211 6.98125 2.5412 6.98125 2.76211V5.6377H8.87783C9.76149 5.6377 10.4778 6.35404 10.4778 7.2377V9.16211ZM6.98125 6.8377H8.87783C9.09875 6.8377 9.27783 7.01678 9.27783 7.2377V9.16211H7.38125C7.16034 9.16211 6.98125 8.98302 6.98125 8.76211V6.8377ZM5.78125 6.8377V8.76211C5.78125 9.64577 6.49759 10.3621 7.38125 10.3621H9.27783V13.2377C9.27783 13.4586 9.09875 13.6377 8.87783 13.6377H2.87783C2.65692 13.6377 2.47783 13.4586 2.47783 13.2377V7.2377C2.47783 7.01678 2.65692 6.8377 2.87783 6.8377H5.78125Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Re=_.forwardRef(function(a,t){return _.createElement(X,Object.assign({},a,{id:"group-single",ref:t,icon:an}))});Re.displayName="GroupSingle";var sn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Le=_.forwardRef(function(a,t){return _.createElement(X,Object.assign({},a,{id:"more-down-single",ref:t,icon:sn}))});Le.displayName="MoreDownSingle";var on={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.25 2.96401C1.25 3.84767 1.96634 4.56401 2.85 4.56401H13.15C14.0337 4.56401 14.75 3.84767 14.75 2.96401C14.75 2.08036 14.0337 1.36401 13.15 1.36401H2.85C1.96635 1.36401 1.25 2.08036 1.25 2.96401ZM2.85 3.36401C2.62909 3.36401 2.45 3.18493 2.45 2.96401C2.45 2.7431 2.62909 2.56401 2.85 2.56401H13.15C13.3709 2.56401 13.55 2.7431 13.55 2.96401C13.55 3.18493 13.3709 3.36401 13.15 3.36401H2.85Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.57564 11.6118C5.80995 11.3774 6.18985 11.3774 6.42417 11.6118L7.3999 12.5875V6.36951C7.3999 6.03814 7.66853 5.76951 7.9999 5.76951C8.33127 5.76951 8.5999 6.03814 8.5999 6.36951V12.5875L9.57564 11.6118C9.80995 11.3774 10.1899 11.3774 10.4242 11.6118C10.6585 11.8461 10.6585 12.226 10.4242 12.4603L8.4324 14.452C8.32324 14.5655 8.16982 14.6362 7.9999 14.6362C7.82998 14.6362 7.67655 14.5655 7.56739 14.452L5.57564 12.4603C5.34132 12.226 5.34132 11.8461 5.57564 11.6118Z"}}]},xe=_.forwardRef(function(a,t){return _.createElement(X,Object.assign({},a,{id:"move-down-single",ref:t,icon:on}))});xe.displayName="MoveDownSingle";var cn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.25 13.036C1.25 12.1523 1.96634 11.436 2.85 11.436H13.15C14.0337 11.436 14.75 12.1523 14.75 13.036C14.75 13.9196 14.0337 14.636 13.15 14.636H2.85C1.96635 14.636 1.25 13.9196 1.25 13.036ZM2.85 12.636C2.62909 12.636 2.45 12.8151 2.45 13.036C2.45 13.2569 2.62909 13.436 2.85 13.436H13.15C13.3709 13.436 13.55 13.2569 13.55 13.036C13.55 12.8151 13.3709 12.636 13.15 12.636H2.85Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.57564 4.38825C5.80995 4.62256 6.18985 4.62256 6.42417 4.38825L7.3999 3.41251V9.63049C7.3999 9.96186 7.66853 10.2305 7.9999 10.2305C8.33127 10.2305 8.5999 9.96186 8.5999 9.63049V3.41251L9.57564 4.38825C9.80995 4.62256 10.1899 4.62256 10.4242 4.38825C10.6585 4.15393 10.6585 3.77403 10.4242 3.53972L8.4324 1.54796C8.32324 1.43445 8.16982 1.36382 7.9999 1.36382C7.82998 1.36382 7.67655 1.43446 7.56739 1.54797L5.57564 3.53972C5.34132 3.77403 5.34132 4.15393 5.57564 4.38825Z"}}]},He=_.forwardRef(function(a,t){return _.createElement(X,Object.assign({},a,{id:"move-up-single",ref:t,icon:cn}))});He.displayName="MoveUpSingle";var ln={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.82994 1.40913C7.88746 1.35161 7.95376 1.30821 8.02453 1.27893C8.09527 1.24959 8.17285 1.2334 8.2542 1.2334C8.33555 1.2334 8.41313 1.24959 8.48387 1.27893C8.55464 1.30821 8.62094 1.35161 8.67846 1.40913L10.6785 3.40913C10.9128 3.64345 10.9128 4.02335 10.6785 4.25766C10.4441 4.49198 10.0642 4.49198 9.82994 4.25766L8.8542 3.28193V5.8334C8.8542 6.16477 8.58557 6.4334 8.2542 6.4334C7.92283 6.4334 7.6542 6.16477 7.6542 5.8334V3.28193L6.67846 4.25766C6.44415 4.49198 6.06425 4.49198 5.82994 4.25766C5.59562 4.02335 5.59562 3.64345 5.82994 3.40913L7.82994 1.40913Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.50439 9C1.50439 8.11634 2.22074 7.4 3.10439 7.4H13.4044C14.288 7.4 15.0044 8.11634 15.0044 9 15.0044 9.88366 14.2881 10.6 13.4044 10.6H3.1044C2.22074 10.6 1.50439 9.88366 1.50439 9zM3.10439 8.6C2.88348 8.6 2.70439 8.77909 2.70439 9 2.70439 9.22091 2.88348 9.4 3.1044 9.4H13.4044C13.6253 9.4 13.8044 9.22091 13.8044 9 13.8044 8.77909 13.6253 8.6 13.4044 8.6H3.10439zM1.6543 13.1665C1.6543 12.2828 2.37064 11.5665 3.2543 11.5665H13.5543C14.438 11.5665 15.1543 12.2828 15.1543 13.1665 15.1543 14.0502 14.438 14.7665 13.5543 14.7665H3.2543C2.37064 14.7665 1.6543 14.0502 1.6543 13.1665zM3.2543 12.7665C3.03338 12.7665 2.8543 12.9456 2.8543 13.1665 2.8543 13.3874 3.03338 13.5665 3.2543 13.5665H13.5543C13.7752 13.5665 13.9543 13.3874 13.9543 13.1665 13.9543 12.9456 13.7752 12.7665 13.5543 12.7665H3.2543z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ge=_.forwardRef(function(a,t){return _.createElement(X,Object.assign({},a,{id:"topmost-single",ref:t,icon:ln}))});Ge.displayName="TopmostSingle";var gn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.46855 2.83731C7.46855 2.61639 7.64764 2.4373 7.86855 2.4373H13.8603C14.0812 2.4373 14.2603 2.61639 14.2603 2.8373V9.5049C14.2603 9.72581 14.0812 9.90489 13.8603 9.90489H12.866C12.5346 9.90489 12.266 10.1735 12.266 10.5049C12.266 10.8363 12.5346 11.1049 12.866 11.1049H13.8603C14.7439 11.1049 15.4603 10.3886 15.4603 9.5049V2.8373C15.4603 1.95365 14.7439 1.2373 13.8603 1.2373H7.86855C6.9849 1.2373 6.26855 1.95365 6.26855 2.83731V3.48688C6.26855 3.81825 6.53718 4.08688 6.86855 4.08688C7.19993 4.08688 7.46855 3.81825 7.46855 3.48688V2.83731Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.19888 5.56299C2.31522 5.56299 1.59888 6.27933 1.59888 7.16299V13.163C1.59888 14.0466 2.31522 14.763 3.19888 14.763H9.19888C10.0825 14.763 10.7989 14.0466 10.7989 13.163V7.16299C10.7989 6.27933 10.0825 5.56299 9.19888 5.56299H3.19888ZM2.79888 7.16299C2.79888 6.94207 2.97796 6.76299 3.19888 6.76299H9.19888C9.41979 6.76299 9.59888 6.94207 9.59888 7.16299V13.163C9.59888 13.3839 9.41979 13.563 9.19888 13.563H3.19888C2.97796 13.563 2.79888 13.3839 2.79888 13.163V7.16299Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ve=_.forwardRef(function(a,t){return _.createElement(X,Object.assign({},a,{id:"ungroup-single",ref:t,icon:gn}))});Ve.displayName="UngroupSingle";const mn=a=>{const{arrangeShow:t,drawings:n}=a,e=V.useDependency(h.LocaleService),r=V.useDependency(M.IDrawingManagerService),s=g=>g?"block":"none",[i,o]=_.useState(n);_.useEffect(()=>{const g=r.focus$.subscribe(d=>{o(d)});return()=>{g.unsubscribe()}},[]);const c=g=>{const d=i[0].unitId,u=i[0].subUnitId,f=i.map(p=>p.drawingId);r.featurePluginOrderUpdateNotification({unitId:d,subUnitId:u,drawingIds:f,arrangeType:g})};return l.jsxs("div",{className:m.imageCommonPanelGrid,style:{display:s(t)},children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelTitle),children:l.jsx("div",{children:e.t("image-panel.arrange.title")})})}),l.jsxs("div",{className:m.imageCommonPanelRow,children:[l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan2),children:l.jsx(I.Button,{onClick:()=>{c(h.ArrangeTypeEnum.forward)},children:l.jsxs("span",{className:m.imageCommonPanelInline,children:[l.jsx(He,{}),e.t("image-panel.arrange.forward")]})})}),l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan2),children:l.jsx(I.Button,{onClick:()=>{c(h.ArrangeTypeEnum.backward)},children:l.jsxs("span",{className:m.imageCommonPanelInline,children:[l.jsx(xe,{}),e.t("image-panel.arrange.backward")]})})})]}),l.jsxs("div",{className:m.imageCommonPanelRow,children:[l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan2),children:l.jsx(I.Button,{onClick:()=>{c(h.ArrangeTypeEnum.front)},children:l.jsxs("span",{className:m.imageCommonPanelInline,children:[l.jsx(Ge,{}),e.t("image-panel.arrange.front")]})})}),l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan2),children:l.jsx(I.Button,{onClick:()=>{c(h.ArrangeTypeEnum.back)},children:l.jsxs("span",{className:m.imageCommonPanelInline,children:[l.jsx(je,{}),e.t("image-panel.arrange.back")]})})})]})]})},dn=a=>{const t=V.useDependency(h.LocaleService),n=V.useDependency(b.IRenderManagerService),e=V.useDependency(M.IDrawingManagerService),{hasGroup:r,drawings:s}=a,[i,o]=_.useState(!1),[c,g]=_.useState(!0),[d,u]=_.useState(!0),f=C=>C?"block":"none",p=()=>{const C=e.getFocusDrawings(),{unitId:P,subUnitId:y}=C[0],U=h.Tools.generateRandomId(10),O=b.getGroupState(0,0,C.map(N=>N.transform||{})),R={unitId:P,subUnitId:y,drawingId:U,drawingType:h.DrawingTypeEnum.DRAWING_GROUP,transform:O},T=C.map(N=>{const E=N.transform||{left:0,top:0},{unitId:B,subUnitId:j,drawingId:G}=N;return{unitId:B,subUnitId:j,drawingId:G,transform:{...E,left:E.left-O.left,top:E.top-O.top},groupId:U}});e.featurePluginGroupUpdateNotification([{parent:R,children:T}])},S=C=>{if(C.drawingType!==h.DrawingTypeEnum.DRAWING_GROUP)return;const{unitId:P,subUnitId:y,drawingId:U,transform:O={width:0,height:0}}=C;if(O==null)return;const R=e.getDrawingsByGroup({unitId:P,subUnitId:y,drawingId:U});if(R.length===0)return;const T=R.map(N=>{const{transform:E}=N,{unitId:B,subUnitId:j,drawingId:G}=N,x=b.transformObjectOutOfGroup(E||{},O,O.width||0,O.height||0);return{unitId:B,subUnitId:j,drawingId:G,transform:{...E,...x},groupId:void 0}});return{parent:C,children:T}},v=()=>{const P=e.getFocusDrawings().map(y=>S(y)).filter(y=>y!=null);P.length!==0&&e.featurePluginUngroupUpdateNotification(P)};return _.useEffect(()=>{const C=s[0];if(C==null)return;const{unitId:P}=C,y=n.getRenderById(P),U=y==null?void 0:y.scene;if(U==null)return;const O=U.getTransformerByCreate(),R=O.clearControl$.subscribe(N=>{N===!0&&o(!1)}),T=O.changeStart$.subscribe(N=>{const{objects:E}=N,B=ge(E,e),j=B.filter(z=>(z==null?void 0:z.drawingType)===h.DrawingTypeEnum.DRAWING_GROUP);let G=!1,x=!1;B.length>1&&(G=!0),j.length>0&&(x=!0),o(G||x),g(G),u(x)});return()=>{T.unsubscribe(),R.unsubscribe()}},[]),l.jsxs("div",{className:I.clsx(m.imageCommonPanelGrid,m.imageCommonPanelBorder),style:{display:f(r===!0?i:!1)},children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelTitle),children:l.jsx("div",{children:t.t("image-panel.group.title")})})}),l.jsxs("div",{className:m.imageCommonPanelRow,children:[l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan2,m.imageCommonPanelColumnCenter),children:l.jsx(I.Button,{style:{display:f(c)},onClick:p,children:l.jsxs("span",{className:m.imageCommonPanelInline,children:[l.jsx(Re,{}),t.t("image-panel.group.group")]})})}),l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan2,m.imageCommonPanelColumnCenter),children:l.jsx(I.Button,{style:{display:f(d)},onClick:v,children:l.jsxs("span",{className:m.imageCommonPanelInline,children:[l.jsx(Ve,{}),t.t("image-panel.group.unGroup")]})})})]})]})},te=20,un=20,hn=[-3600,3600],pe=300,fn=a=>{var Fe;const t=V.useDependency(h.LocaleService),n=V.useDependency(M.IDrawingManagerService),e=V.useDependency(b.IRenderManagerService),{drawings:r,transformShow:s}=a,i=r[0];if(i==null)return;const o=i.transform;if(o==null)return;const{unitId:c,subUnitId:g,drawingId:d,drawingType:u}=i,f=e.getRenderById(c),p=f==null?void 0:f.scene;if(p==null)return;const S=(Fe=p.getEngine())==null?void 0:Fe.activeScene;if(S==null)return;const v=p.getTransformerByCreate(),{width:C=0,height:P=0,left:y=0,top:U=0,angle:O=0}=o,[R,T]=_.useState(C),[N,E]=_.useState(P),[B,j]=_.useState(y),[G,x]=_.useState(U),[F,z]=_.useState(O),[ce,ae]=_.useState(v.keepRatio),ie=(w,L,W,$)=>{const{width:k,height:Q}=S,{ancestorLeft:Y,ancestorTop:Z}=p;let q=w,se=L,ue=W,he=$;return w+Y<0&&(q=-Y),L+Z<0&&(se=-Z),ue=k-q-Y,ue<te&&(ue=te),he=Q-se-Z,he<te&&(he=te),w+ue+Y>k&&(q=k-W-Y),L+he+Z>Q&&(se=Q-$-Z),{limitLeft:q,limitTop:se,limitWidth:ue,limitHeight:he}},le=w=>{const{objects:L}=w,W=ge(L,n);if(W.length!==1)return;const $=W[0];if($==null)return;const{transform:k}=$;if(k==null)return;const{width:Q,height:Y,left:Z,top:q,angle:se}=k;Q!=null&&T(Q),Y!=null&&E(Y),Z!=null&&j(Z),q!=null&&x(q),se!=null&&z(se)};_.useEffect(()=>{const w=[v.changeStart$.subscribe(L=>{le(L)}),v.changing$.subscribe(L=>{le(L)}),v.changeEnd$.subscribe(L=>{le(L)}),n.focus$.subscribe(L=>{if(L.length!==1)return;const W=n.getDrawingByParam(L[0]);if(W==null)return;const $=W.transform;if($==null)return;const{width:k,height:Q,left:Y,top:Z,angle:q}=$;k!=null&&T(k),Q!=null&&E(Q),Y!=null&&j(Y),Z!=null&&x(Z),q!=null&&z(q)})];return()=>{w.forEach(L=>L.unsubscribe())}},[]);const J=h.debounce(w=>{if(w==null)return;w=Math.max(w,te);const{limitWidth:L,limitHeight:W}=ie(B,G,w,N);w=Math.min(w,L);const $={unitId:c,subUnitId:g,drawingId:d,drawingType:u,transform:{width:w}};if(ce){let k=w/R*N;if(k=Math.max(k,un),k>W)return;E(k),$.transform.height=k}T(w),n.featurePluginUpdateNotification([$]),v.refreshControls().changeNotification()},pe),De=h.debounce(w=>{if(w==null)return;w=Math.max(w,te);const{limitHeight:L,limitWidth:W}=ie(B,G,R,w);w=Math.min(w,L);const $={unitId:c,subUnitId:g,drawingId:d,drawingType:u,transform:{height:w}};if(ce){let k=w/N*R;if(k=Math.max(k,te),k>W)return;T(k),$.transform.width=k}E(w),n.featurePluginUpdateNotification([$]),v.refreshControls().changeNotification()},pe),Tn=h.debounce(w=>{if(w==null)return;const{limitLeft:L}=ie(w,G,R,N);w=L;const W={unitId:c,subUnitId:g,drawingId:d,drawingType:u,transform:{left:w}};j(w),n.featurePluginUpdateNotification([W]),v.refreshControls().changeNotification()},pe),Bn=h.debounce(w=>{if(w==null)return;const{limitTop:L}=ie(B,w,R,N);w=L;const W={unitId:c,subUnitId:g,drawingId:d,drawingType:u,transform:{top:w}};x(w),n.featurePluginUpdateNotification([W]),v.refreshControls().changeNotification()},pe),Un=w=>{if(w==null)return;const[L,W]=hn;w<L&&(w=L),w>W&&(w=W);const $={unitId:c,subUnitId:g,drawingId:d,drawingType:u,transform:{angle:w}};z(w),n.featurePluginUpdateNotification([$]),v.refreshControls().changeNotification()},jn=w=>{ae(w),v.keepRatio=w},An=w=>w?"block":"none";return l.jsxs("div",{className:I.clsx(m.imageCommonPanelGrid,m.imageCommonPanelBorder),style:{display:An(s)},children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelTitle),children:l.jsx("div",{children:t.t("image-panel.transform.title")})})}),l.jsxs("div",{className:m.imageCommonPanelRow,children:[l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan3),children:l.jsxs("label",{children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:t.t("image-panel.transform.width")})}),l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:l.jsx(I.InputNumber,{precision:1,value:R,onChange:w=>{J(w)},className:m.imageCommonPanelInput})})})]})}),l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan3),children:l.jsxs("label",{children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:t.t("image-panel.transform.height")})}),l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:l.jsx(I.InputNumber,{precision:1,value:N,onChange:w=>{De(w)},className:m.imageCommonPanelInput})})})]})}),l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan3),children:l.jsxs("label",{children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:t.t("image-panel.transform.lock")})}),l.jsx("div",{className:I.clsx(m.imageCommonPanelRow,m.imageCommonPanelRowVertical),children:l.jsx("div",{className:m.imageCommonPanelColumn,children:l.jsx(I.Checkbox,{checked:ce,onChange:jn})})})]})})]}),l.jsxs("div",{className:m.imageCommonPanelRow,children:[l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan3),children:l.jsxs("label",{children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:t.t("image-panel.transform.x")})}),l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:l.jsx(I.InputNumber,{precision:1,value:B,onChange:w=>{Tn(w)},className:m.imageCommonPanelInput})})})]})}),l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan3),children:l.jsxs("label",{children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:t.t("image-panel.transform.y")})}),l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:l.jsx(I.InputNumber,{precision:1,value:G,onChange:w=>{Bn(w)},className:m.imageCommonPanelInput})})})]})}),l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan3),children:l.jsxs("label",{children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:t.t("image-panel.transform.rotate")})}),l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:m.imageCommonPanelColumn,children:l.jsx(I.InputNumber,{precision:1,value:F,onChange:Un,className:m.imageCommonPanelInput})})})]})})]})]})},Ce={id:"sheet.operation.open-image-crop",type:h.CommandType.OPERATION,handler:(a,t)=>!0},ne={id:"sheet.operation.close-image-crop",type:h.CommandType.OPERATION,handler:(a,t)=>!0};var H=(a=>(a.FREE="0",a.R1_1="1",a.R16_9="2",a.R9_16="3",a.R5_4="4",a.R4_5="5",a.R4_3="6",a.R3_4="7",a.R3_2="8",a.R2_3="9",a))(H||{});const me={id:"sheet.operation.Auto-image-crop",type:h.CommandType.OPERATION,handler:(a,t)=>!0},pn=a=>{const t=V.useDependency(h.ICommandService),n=V.useDependency(h.LocaleService),{drawings:e,cropperShow:r}=a;if(e[0]==null)return;const[i,o]=_.useState(H.FREE),c=_.useRef(!1),g=[{label:n.t("image-panel.crop.mode"),value:H.FREE},{label:"1:1",value:H.R1_1},{label:"16:9",value:H.R16_9},{label:"9:16",value:H.R9_16},{label:"5:4",value:H.R5_4},{label:"4:5",value:H.R4_5},{label:"4:3",value:H.R4_3},{label:"3:4",value:H.R3_4},{label:"3:2",value:H.R3_2},{label:"2:3",value:H.R2_3}];_.useEffect(()=>{const p=t.onCommandExecuted(S=>{if(S.id===ne.id){const v=S.params;v!=null&&v.isAuto||(c.current=!1)}});return()=>{p==null||p.dispose()}},[]);function d(p){o(p),c.current&&t.executeCommand(me.id,{cropType:p})}const u=p=>p?"block":"none",f=p=>{t.executeCommand(me.id,{cropType:p}),c.current=!0};return l.jsxs("div",{className:I.clsx(m.imageCommonPanelGrid,m.imageCommonPanelBorder),style:{display:u(r)},children:[l.jsx("div",{className:m.imageCommonPanelRow,children:l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelTitle),children:l.jsx("div",{children:n.t("image-panel.crop.title")})})}),l.jsxs("div",{className:I.clsx(m.imageCommonPanelRow,m.imageCommonPanelRowVertical),children:[l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan2),children:l.jsx(I.Button,{onClick:()=>{f(i)},children:l.jsxs("span",{className:m.imageCommonPanelInline,children:[l.jsx(Ae,{}),n.t("image-panel.crop.start")]})})}),l.jsx("div",{className:I.clsx(m.imageCommonPanelColumn,m.imageCommonPanelSpan2),children:l.jsx(I.Select,{value:i,options:g,onChange:d})})]})]})},Cn=a=>{const t=V.useDependency(M.IDrawingManagerService),n=V.useDependency(b.IRenderManagerService),e=V.useDependency(h.LocaleService),{drawings:r,hasArrange:s=!0,hasTransform:i=!0,hasAlign:o=!0,hasCropper:c=!0,hasGroup:g=!0}=a,d=r[0];if(d==null)return;const{unitId:u}=d,f=n.getRenderById(u),p=f==null?void 0:f.scene;if(p==null)return;const S=p.getTransformerByCreate(),[v,C]=_.useState(!0),[P,y]=_.useState(!0),[U,O]=_.useState(!1),[R,T]=_.useState(!0),[N,E]=_.useState(!1);return _.useEffect(()=>{const B=S.clearControl$.subscribe(x=>{x===!0&&(C(!1),y(!1),O(!1),T(!1),E(!0))}),j=S.changeStart$.subscribe(x=>{const{objects:F}=x,z=ge(F,t);z.length===0?(C(!1),y(!1),O(!1),T(!1),E(!0)):z.length===1?(C(!0),y(!0),O(!1),T(!0),E(!1)):(C(!0),y(!1),O(!0),T(!1),E(!1))}),G=t.focus$.subscribe(x=>{x.length===0?(C(!1),y(!1),O(!1),T(!1),E(!0)):x.length===1?(C(!0),y(!0),O(!1),T(!0),E(!1)):(C(!0),y(!1),O(!0),T(!1),E(!1))});return()=>{j.unsubscribe(),B.unsubscribe(),G.unsubscribe()}},[]),l.jsxs(l.Fragment,{children:[l.jsx("div",{style:{display:N===!0?"block":"none",height:"100%"},children:l.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",top:"50%",marginTop:"-100px"},children:l.jsx("span",{children:e.t("image-panel.null")})})}),l.jsx(mn,{arrangeShow:s===!0?v:!1,drawings:r}),l.jsx(fn,{transformShow:i===!0?P:!1,drawings:r}),l.jsx(Xe,{alignShow:o===!0?U:!1,drawings:r}),l.jsx(pn,{cropperShow:c===!0?R:!1,drawings:r}),l.jsx(dn,{hasGroup:g,drawings:r})]})},ke=a=>{var v;const{popup:t}=a,n=(v=t==null?void 0:t.extraProps)==null?void 0:v.menuItems;if(!n)return null;const e=V.useDependency(h.ICommandService),r=V.useDependency(h.LocaleService),[s,i]=_.useState(!1),[o,c]=_.useState(!1),g=()=>{c(!0)},d=()=>{c(!1)},u=C=>{i(C)},f=C=>{e.executeCommand(C.commandId,C.commandParams),i(!1)},p=s||o,S=n.filter(C=>!C.disable);return l.jsx("div",{onMouseEnter:g,onMouseLeave:d,children:l.jsx(I.DropdownMenu,{align:"start",items:S.map(C=>({type:"item",children:r.t(C.label),onSelect:()=>f(C)})),open:s,onOpenChange:u,children:l.jsxs("div",{className:I.clsx(`
|
|
6
|
+
(function(I,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react/jsx-runtime"),require("react"),require("@univerjs/design"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/drawing","@univerjs/engine-render","@univerjs/ui","react/jsx-runtime","react","@univerjs/design","rxjs"],h):(I=typeof globalThis<"u"?globalThis:I||self,h(I.UniverDrawingUi={},I.UniverCore,I.UniverDrawing,I.UniverEngineRender,I.UniverUi,I.React,I.React,I.UniverDesign,I.rxjs))})(this,function(I,h,D,y,V,c,_,P,Ee){"use strict";var jt=Object.defineProperty;var At=(I,h,D)=>h in I?jt(I,h,{enumerable:!0,configurable:!0,writable:!0,value:D}):I[h]=D;var te=(I,h,D)=>At(I,typeof h!="symbol"?h+"":h,D);var Oe;function Te(i,r,t,e){const n=e.getDrawingByParam(i);if(n==null)return;const s=D.getDrawingShapeKeyByDrawingSearch(i),a=t.getObject(s);if(a&&!(a instanceof y.Group))return;if(a!=null){a.addObject(r);return}const o=new y.Group(s);t.addObject(o,y.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(o),o.addObject(r);const{transform:l}=n;l&&o.transformByState({left:l.left,top:l.top,angle:l.angle})}function Pe(i,r){var s;const t=r?i.getUnit(r):i.getFocusedUnit();if(t==null)return;const e=t.getUnitId();let n;return t.type===h.UniverInstanceType.UNIVER_SHEET?n=(s=t.getActiveSheet())==null?void 0:s.getSheetId():(t.type===h.UniverInstanceType.UNIVER_DOC||t.type===h.UniverInstanceType.UNIVER_SLIDE)&&(n=e),{unitId:e,subUnitId:n,current:t}}var Ye=Object.getOwnPropertyDescriptor,Ze=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ye(r,t):r,s=i.length-1,a;s>=0;s--)(a=i[s])&&(n=a(n)||n);return n},De=(i,r)=>(t,e)=>r(t,e,i);I.DrawingRenderService=class{constructor(r,t,e){this._drawingManagerService=r,this._imageIoService=t,this._galleryService=e}async renderImages(r,t){const{transform:e,drawingType:n,source:s,imageSourceType:a,srcRect:o,prstGeom:l,groupId:d,unitId:u,subUnitId:g,drawingId:f,isMultiTransform:p,transforms:S}=r;if(n!==h.DrawingTypeEnum.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||e==null)return;const w=p&&S?S:[e],m=[];for(const b of w){const{left:C,top:B,width:M,height:A,angle:E,flipX:O,flipY:N,skewX:T,skewY:U}=b,R=w.indexOf(b),x=D.getDrawingShapeKeyByDrawingSearch({unitId:u,subUnitId:g,drawingId:f},p?R:void 0),Y=t.getObject(x);if(Y!=null){Y.transformByState({left:C,top:B,width:M,height:A,angle:E,flipX:O,flipY:N,skewX:T,skewY:U});continue}const K=this._drawingManagerService.getDrawingOrder(u,g),de=K.indexOf(f),se={...b,zIndex:de===-1?K.length-1:de},oe=this._imageIoService.getImageSourceCache(s,a);let ue=!1;if(oe!=null)se.image=oe;else{if(a===D.ImageSourceType.UUID)try{se.url=await this._imageIoService.getImage(s)}catch(Ne){console.error(Ne);continue}else se.url=s;ue=!0}if(t.getObject(x))continue;se.printable=!0;const Q=new y.Image(x,se);ue&&this._imageIoService.addImageSourceCache(s,a,Q.getNative()),this._drawingManagerService.getDrawingVisible()&&(t.addObject(Q,y.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&t.attachTransformerTo(Q),d&&Te({drawingId:d,unitId:u,subUnitId:g},Q,t,this._drawingManagerService),l!=null&&Q.setPrstGeom(l),o!=null&&Q.setSrcRect(o),m.push(Q))}return m}renderFloatDom(r,t){const{transform:e,drawingType:n,groupId:s,unitId:a,subUnitId:o,drawingId:l,isMultiTransform:d,transforms:u}=r;if(n!==h.DrawingTypeEnum.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||e==null)return;const g=d&&u?u:[e],f=[];for(const p of g){const{left:S,top:w,width:m,height:b,angle:C,flipX:B,flipY:M,skewX:A,skewY:E}=p,O=g.indexOf(p),N=D.getDrawingShapeKeyByDrawingSearch({unitId:a,subUnitId:o,drawingId:l},d?O:void 0),T=t.getObject(N);if(T!=null){T.transformByState({left:S,top:w,width:m,height:b,angle:C,flipX:B,flipY:M,skewX:A,skewY:E});continue}const U=this._drawingManagerService.getDrawingOrder(a,o),R=U.indexOf(l),x={...p,zIndex:R===-1?U.length-1:R};if(t.getObject(N))continue;x.printable=!1;const Y=new y.Rect(N,x);this._drawingManagerService.getDrawingVisible()&&(t.addObject(Y,y.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&r.allowTransform!==!1&&t.attachTransformerTo(Y),s&&Te({drawingId:s,unitId:a,subUnitId:o},Y,t,this._drawingManagerService),f.push(Y))}return f}renderDrawing(r,t){const e=this._drawingManagerService.getDrawingByParam(r);if(e!=null)switch(e.drawingType){case h.DrawingTypeEnum.DRAWING_IMAGE:return this.renderImages(e,t)}}previewImage(r,t,e,n){this._galleryService.open({images:[t],onOpenChange:s=>{s||this._galleryService.close()}})}_adjustImageSize(r,t,e,n){if(r<=e&&t<=n)return{width:r,height:t};const s=e/r,a=n/t,o=Math.min(s,a);return{width:Math.floor(r*o),height:Math.floor(t*o)}}},I.DrawingRenderService=Ze([De(0,D.IDrawingManagerService),De(1,D.IImageIoService),De(2,V.IGalleryService)],I.DrawingRenderService);function ge(i,r){const t=[];return i.forEach(e=>{const{oKey:n,left:s,top:a,height:o,width:l,angle:d}=e,u=r.getDrawingOKey(n);if(u==null)return t.push(null),!0;const{unitId:g,subUnitId:f,drawingId:p,drawingType:S}=u,w={unitId:g,subUnitId:f,drawingId:p,drawingType:S,transform:{left:s,top:a,height:o,width:l,angle:d}};S===h.DrawingTypeEnum.DRAWING_IMAGE&&(w.srcRect=e.srcRect),t.push(w)}),t}var j=(i=>(i.default="0",i.left="1",i.center="2",i.right="3",i.top="4",i.middle="5",i.bottom="6",i.horizon="7",i.vertical="8",i))(j||{});const ve={id:"sheet.operation.set-image-align",type:h.CommandType.OPERATION,handler:(i,r)=>!0},Xe=i=>{const r=V.useDependency(h.ICommandService),t=V.useDependency(h.LocaleService),{alignShow:e}=i,[n,s]=_.useState(j.default),a=[{label:t.t("image-panel.align.default"),value:j.default},{options:[{label:t.t("image-panel.align.left"),value:j.left},{label:t.t("image-panel.align.center"),value:j.center},{label:t.t("image-panel.align.right"),value:j.right}]},{options:[{label:t.t("image-panel.align.top"),value:j.top},{label:t.t("image-panel.align.middle"),value:j.middle},{label:t.t("image-panel.align.bottom"),value:j.bottom}]},{options:[{label:t.t("image-panel.align.horizon"),value:j.horizon},{label:t.t("image-panel.align.vertical"),value:j.vertical}]}];function o(d){s(d),r.executeCommand(ve.id,{alignType:d})}const l=d=>d?"block":"none";return c.jsxs("div",{className:`
|
|
7
|
+
univer-relative univer-w-full univer-border-l-0 univer-border-r-0 univer-border-t univer-border-solid
|
|
8
|
+
univer-border-gray-200
|
|
9
|
+
`,style:{display:l(e)},children:[c.jsx("div",{className:`
|
|
10
|
+
univer-relative univer-mt-2.5 univer-flex univer-h-full univer-items-start univer-justify-start
|
|
11
|
+
`,children:c.jsx("div",{className:"univer-w-full univer-text-gray-900",children:c.jsx("div",{children:t.t("image-panel.align.title")})})}),c.jsx("div",{className:`
|
|
12
|
+
univer-relative univer-mt-2.5 univer-flex univer-h-full univer-items-start univer-justify-start
|
|
13
|
+
`,children:c.jsx("div",{className:"univer-w-full univer-text-gray-900",children:c.jsx(P.Select,{value:n,options:a,onChange:o})})})]})};var F=function(){return F=Object.assign||function(i){for(var r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},F.apply(this,arguments)},qe=function(i,r){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(i);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(i,e[n])&&(t[e[n]]=i[e[n]]);return t},q=_.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,s=i.extend,a=qe(i,["icon","id","className","extend"]),o="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),l=_.useRef("_".concat(et()));return Be(t,"".concat(e),{defIds:t.defIds,idSuffix:l.current},F({ref:r,className:o},a),s)});function Be(i,r,t,e,n){return _.createElement(i.tag,F(F({key:r},Je(i,t,n)),e),(Qe(i,t).children||[]).map(function(s,a){return Be(s,"".concat(r,"-").concat(i.tag,"-").concat(a),t,void 0,n)}))}function Je(i,r,t){var e=F({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(s){var a=s[0],o=s[1];a==="mask"&&typeof o=="string"&&(e[a]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(s){var a=s[0],o=s[1];typeof o=="string"&&(e[a]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Qe(i,r){var t,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?F(F({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?F(F({},n),{attrs:F(F({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function et(){return Math.random().toString(36).substring(2,8)}q.displayName="UniverIcon";var tt={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365zM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377zM2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365zM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647zM9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635zM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ue=_.forwardRef(function(i,r){return _.createElement(q,Object.assign({},i,{id:"autofill",ref:r,icon:tt}))});Ue.displayName="Autofill";var rt={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.0045 4.4334C14.8881 4.4334 15.6045 3.71705 15.6045 2.8334 15.6045 1.94974 14.8881 1.2334 14.0045 1.2334H3.70449C2.82084 1.2334 2.10449 1.94974 2.10449 2.8334 2.10449 3.71705 2.82084 4.4334 3.70449 4.4334H14.0045zM14.4045 2.8334C14.4045 3.05431 14.2254 3.2334 14.0045 3.2334H3.70449C3.48358 3.2334 3.30449 3.05431 3.30449 2.8334 3.30449 2.61248 3.48358 2.4334 3.70449 2.4334H14.0045C14.2254 2.4334 14.4045 2.61249 14.4045 2.8334zM14.1544 8.5999C15.038 8.5999 15.7544 7.88356 15.7544 6.9999 15.7544 6.11625 15.038 5.3999 14.1544 5.3999H3.85439C2.97074 5.3999 2.25439 6.11625 2.25439 6.9999 2.25439 7.88356 2.97074 8.5999 3.85439 8.5999H14.1544zM14.5544 6.9999C14.5544 7.22082 14.3753 7.3999 14.1544 7.3999H3.85439C3.63348 7.3999 3.45439 7.22082 3.45439 6.9999 3.45439 6.77899 3.63348 6.5999 3.85439 6.5999H14.1544C14.3753 6.5999 14.5544 6.77899 14.5544 6.9999z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.57975 14.5902L6.58023 12.5907C6.34591 12.3564 6.34591 11.9765 6.58023 11.7421 6.81454 11.5078 7.19444 11.5078 7.42876 11.7421L8.40449 12.7179V10.1664C8.40449 9.83504 8.67312 9.56641 9.00449 9.56641 9.33586 9.56641 9.60449 9.83504 9.60449 10.1664V12.7179L10.5802 11.7421C10.8145 11.5078 11.1944 11.5078 11.4288 11.7421 11.6631 11.9765 11.6631 12.3564 11.4288 12.5907L9.42923 14.5902M8.57975 14.5902C8.58121 14.5917 8.58268 14.5931 8.58416 14.5946 8.64077 14.6502 8.70566 14.6923 8.77482 14.7209 8.84557 14.7502 8.92314 14.7664 9.00449 14.7664 9.08585 14.7664 9.16342 14.7502 9.23416 14.7209 9.30332 14.6923 9.36821 14.6502 9.42482 14.5946"}}]},je=_.forwardRef(function(i,r){return _.createElement(q,Object.assign({},i,{id:"bottom-single",ref:r,icon:rt}))});je.displayName="BottomSingle";var nt={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.97705 7.51296C5.97705 7.18159 6.24568 6.91296 6.57705 6.91296H8.48632C8.81769 6.91296 9.08632 7.18159 9.08632 7.51296 9.08632 7.84433 8.81769 8.11296 8.48632 8.11296H6.57705C6.24568 8.11296 5.97705 7.84433 5.97705 7.51296zM6.57705 9.41028C6.24568 9.41028 5.97705 9.67891 5.97705 10.0103 5.97705 10.3416 6.24568 10.6103 6.57705 10.6103H10.8199C11.1512 10.6103 11.4199 10.3416 11.4199 10.0103 11.4199 9.67891 11.1512 9.41028 10.8199 9.41028H6.57705z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.51074 2.37063C3.51074 1.48697 4.22709 0.77063 5.11074 0.77063H9.80318L9.81294 0.770708C9.97168 0.768161 10.1311 0.82824 10.2511 0.95055L14.4317 5.21408C14.5165 5.30049 14.5697 5.406 14.5917 5.51645C14.6041 5.5644 14.6106 5.61467 14.6106 5.66648V11.6406C14.6106 12.5243 13.8943 13.2406 13.0106 13.2406H5.11074C4.22709 13.2406 3.51074 12.5243 3.51074 11.6406V2.37063ZM10.4032 4.66648V2.81964L12.6063 5.06648H10.8032C10.5823 5.06648 10.4032 4.88739 10.4032 4.66648ZM5.11074 1.97063C4.88983 1.97063 4.71074 2.14972 4.71074 2.37063V11.6406C4.71074 11.8615 4.88983 12.0406 5.11074 12.0406H13.0106C13.2316 12.0406 13.4106 11.8615 13.4106 11.6406V6.26648H10.8032C9.91953 6.26648 9.20318 5.55013 9.20318 4.66648V1.97063H5.11074Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.58916 6.6741C2.58916 6.34273 2.32053 6.0741 1.98916 6.0741C1.65779 6.0741 1.38916 6.34273 1.38916 6.6741V12.6294C1.38916 14.0653 2.55322 15.2294 3.98916 15.2294H9.41408C9.74545 15.2294 10.0141 14.9607 10.0141 14.6294C10.0141 14.298 9.74545 14.0294 9.41408 14.0294H3.98916C3.21596 14.0294 2.58916 13.4026 2.58916 12.6294V6.6741Z"}}]},Ae=_.forwardRef(function(i,r){return _.createElement(q,Object.assign({},i,{id:"create-copy-single",ref:r,icon:nt}))});Ae.displayName="CreateCopySingle";var it={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.38125 1.16211C6.49759 1.16211 5.78125 1.87845 5.78125 2.76211V5.6377H2.87783C1.99418 5.6377 1.27783 6.35404 1.27783 7.2377V13.2377C1.27783 14.1214 1.99418 14.8377 2.87783 14.8377H8.87783C9.76149 14.8377 10.4778 14.1214 10.4778 13.2377V10.3621H13.3813C14.2649 10.3621 14.9813 9.64577 14.9813 8.76211V2.76211C14.9813 1.87845 14.2649 1.16211 13.3813 1.16211H7.38125ZM10.4778 9.16211H13.3813C13.6022 9.16211 13.7812 8.98302 13.7812 8.76211V2.76211C13.7812 2.5412 13.6022 2.36211 13.3813 2.36211H7.38125C7.16034 2.36211 6.98125 2.5412 6.98125 2.76211V5.6377H8.87783C9.76149 5.6377 10.4778 6.35404 10.4778 7.2377V9.16211ZM6.98125 6.8377H8.87783C9.09875 6.8377 9.27783 7.01678 9.27783 7.2377V9.16211H7.38125C7.16034 9.16211 6.98125 8.98302 6.98125 8.76211V6.8377ZM5.78125 6.8377V8.76211C5.78125 9.64577 6.49759 10.3621 7.38125 10.3621H9.27783V13.2377C9.27783 13.4586 9.09875 13.6377 8.87783 13.6377H2.87783C2.65692 13.6377 2.47783 13.4586 2.47783 13.2377V7.2377C2.47783 7.01678 2.65692 6.8377 2.87783 6.8377H5.78125Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Le=_.forwardRef(function(i,r){return _.createElement(q,Object.assign({},i,{id:"group-single",ref:r,icon:it}))});Le.displayName="GroupSingle";var at={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},xe=_.forwardRef(function(i,r){return _.createElement(q,Object.assign({},i,{id:"more-down-single",ref:r,icon:at}))});xe.displayName="MoreDownSingle";var st={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.25 2.96401C1.25 3.84767 1.96634 4.56401 2.85 4.56401H13.15C14.0337 4.56401 14.75 3.84767 14.75 2.96401C14.75 2.08036 14.0337 1.36401 13.15 1.36401H2.85C1.96635 1.36401 1.25 2.08036 1.25 2.96401ZM2.85 3.36401C2.62909 3.36401 2.45 3.18493 2.45 2.96401C2.45 2.7431 2.62909 2.56401 2.85 2.56401H13.15C13.3709 2.56401 13.55 2.7431 13.55 2.96401C13.55 3.18493 13.3709 3.36401 13.15 3.36401H2.85Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.57564 11.6118C5.80995 11.3774 6.18985 11.3774 6.42417 11.6118L7.3999 12.5875V6.36951C7.3999 6.03814 7.66853 5.76951 7.9999 5.76951C8.33127 5.76951 8.5999 6.03814 8.5999 6.36951V12.5875L9.57564 11.6118C9.80995 11.3774 10.1899 11.3774 10.4242 11.6118C10.6585 11.8461 10.6585 12.226 10.4242 12.4603L8.4324 14.452C8.32324 14.5655 8.16982 14.6362 7.9999 14.6362C7.82998 14.6362 7.67655 14.5655 7.56739 14.452L5.57564 12.4603C5.34132 12.226 5.34132 11.8461 5.57564 11.6118Z"}}]},He=_.forwardRef(function(i,r){return _.createElement(q,Object.assign({},i,{id:"move-down-single",ref:r,icon:st}))});He.displayName="MoveDownSingle";var ot={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.25 13.036C1.25 12.1523 1.96634 11.436 2.85 11.436H13.15C14.0337 11.436 14.75 12.1523 14.75 13.036C14.75 13.9196 14.0337 14.636 13.15 14.636H2.85C1.96635 14.636 1.25 13.9196 1.25 13.036ZM2.85 12.636C2.62909 12.636 2.45 12.8151 2.45 13.036C2.45 13.2569 2.62909 13.436 2.85 13.436H13.15C13.3709 13.436 13.55 13.2569 13.55 13.036C13.55 12.8151 13.3709 12.636 13.15 12.636H2.85Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.57564 4.38825C5.80995 4.62256 6.18985 4.62256 6.42417 4.38825L7.3999 3.41251V9.63049C7.3999 9.96186 7.66853 10.2305 7.9999 10.2305C8.33127 10.2305 8.5999 9.96186 8.5999 9.63049V3.41251L9.57564 4.38825C9.80995 4.62256 10.1899 4.62256 10.4242 4.38825C10.6585 4.15393 10.6585 3.77403 10.4242 3.53972L8.4324 1.54796C8.32324 1.43445 8.16982 1.36382 7.9999 1.36382C7.82998 1.36382 7.67655 1.43446 7.56739 1.54797L5.57564 3.53972C5.34132 3.77403 5.34132 4.15393 5.57564 4.38825Z"}}]},ke=_.forwardRef(function(i,r){return _.createElement(q,Object.assign({},i,{id:"move-up-single",ref:r,icon:ot}))});ke.displayName="MoveUpSingle";var ct={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.82994 1.40913C7.88746 1.35161 7.95376 1.30821 8.02453 1.27893C8.09527 1.24959 8.17285 1.2334 8.2542 1.2334C8.33555 1.2334 8.41313 1.24959 8.48387 1.27893C8.55464 1.30821 8.62094 1.35161 8.67846 1.40913L10.6785 3.40913C10.9128 3.64345 10.9128 4.02335 10.6785 4.25766C10.4441 4.49198 10.0642 4.49198 9.82994 4.25766L8.8542 3.28193V5.8334C8.8542 6.16477 8.58557 6.4334 8.2542 6.4334C7.92283 6.4334 7.6542 6.16477 7.6542 5.8334V3.28193L6.67846 4.25766C6.44415 4.49198 6.06425 4.49198 5.82994 4.25766C5.59562 4.02335 5.59562 3.64345 5.82994 3.40913L7.82994 1.40913Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.50439 9C1.50439 8.11634 2.22074 7.4 3.10439 7.4H13.4044C14.288 7.4 15.0044 8.11634 15.0044 9 15.0044 9.88366 14.2881 10.6 13.4044 10.6H3.1044C2.22074 10.6 1.50439 9.88366 1.50439 9zM3.10439 8.6C2.88348 8.6 2.70439 8.77909 2.70439 9 2.70439 9.22091 2.88348 9.4 3.1044 9.4H13.4044C13.6253 9.4 13.8044 9.22091 13.8044 9 13.8044 8.77909 13.6253 8.6 13.4044 8.6H3.10439zM1.6543 13.1665C1.6543 12.2828 2.37064 11.5665 3.2543 11.5665H13.5543C14.438 11.5665 15.1543 12.2828 15.1543 13.1665 15.1543 14.0502 14.438 14.7665 13.5543 14.7665H3.2543C2.37064 14.7665 1.6543 14.0502 1.6543 13.1665zM3.2543 12.7665C3.03338 12.7665 2.8543 12.9456 2.8543 13.1665 2.8543 13.3874 3.03338 13.5665 3.2543 13.5665H13.5543C13.7752 13.5665 13.9543 13.3874 13.9543 13.1665 13.9543 12.9456 13.7752 12.7665 13.5543 12.7665H3.2543z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ge=_.forwardRef(function(i,r){return _.createElement(q,Object.assign({},i,{id:"topmost-single",ref:r,icon:ct}))});Ge.displayName="TopmostSingle";var lt={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.46855 2.83731C7.46855 2.61639 7.64764 2.4373 7.86855 2.4373H13.8603C14.0812 2.4373 14.2603 2.61639 14.2603 2.8373V9.5049C14.2603 9.72581 14.0812 9.90489 13.8603 9.90489H12.866C12.5346 9.90489 12.266 10.1735 12.266 10.5049C12.266 10.8363 12.5346 11.1049 12.866 11.1049H13.8603C14.7439 11.1049 15.4603 10.3886 15.4603 9.5049V2.8373C15.4603 1.95365 14.7439 1.2373 13.8603 1.2373H7.86855C6.9849 1.2373 6.26855 1.95365 6.26855 2.83731V3.48688C6.26855 3.81825 6.53718 4.08688 6.86855 4.08688C7.19993 4.08688 7.46855 3.81825 7.46855 3.48688V2.83731Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.19888 5.56299C2.31522 5.56299 1.59888 6.27933 1.59888 7.16299V13.163C1.59888 14.0466 2.31522 14.763 3.19888 14.763H9.19888C10.0825 14.763 10.7989 14.0466 10.7989 13.163V7.16299C10.7989 6.27933 10.0825 5.56299 9.19888 5.56299H3.19888ZM2.79888 7.16299C2.79888 6.94207 2.97796 6.76299 3.19888 6.76299H9.19888C9.41979 6.76299 9.59888 6.94207 9.59888 7.16299V13.163C9.59888 13.3839 9.41979 13.563 9.19888 13.563H3.19888C2.97796 13.563 2.79888 13.3839 2.79888 13.163V7.16299Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Re=_.forwardRef(function(i,r){return _.createElement(q,Object.assign({},i,{id:"ungroup-single",ref:r,icon:lt}))});Re.displayName="UngroupSingle";const H="univer-relative univer-mt-2.5 univer-flex univer-h-full univer-items-start univer-justify-between univer-gap-2 univer-flex-no-wrap",k="univer-w-full univer-text-left univer-text-gray-400",re="univer-flex univer-items-center univer-gap-1",dt=i=>{const{arrangeShow:r,drawings:t}=i,e=V.useDependency(h.LocaleService),n=V.useDependency(D.IDrawingManagerService),s=d=>d?"block":"none",[a,o]=_.useState(t);_.useEffect(()=>{const d=n.focus$.subscribe(u=>{o(u)});return()=>{d.unsubscribe()}},[]);const l=d=>{const u=a[0].unitId,g=a[0].subUnitId,f=a.map(p=>p.drawingId);n.featurePluginOrderUpdateNotification({unitId:u,subUnitId:g,drawingIds:f,arrangeType:d})};return c.jsxs("div",{className:"univer-relative univer-mt-5 univer-w-full",style:{display:s(r)},children:[c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:c.jsx("div",{children:e.t("image-panel.arrange.title")})})}),c.jsxs("div",{className:H,children:[c.jsx("div",{className:"univer-w-1/2",children:c.jsx(P.Button,{onClick:()=>{l(h.ArrangeTypeEnum.forward)},children:c.jsxs("span",{className:re,children:[c.jsx(ke,{}),e.t("image-panel.arrange.forward")]})})}),c.jsx("div",{className:"univer-w-1/2",children:c.jsx(P.Button,{onClick:()=>{l(h.ArrangeTypeEnum.backward)},children:c.jsxs("span",{className:re,children:[c.jsx(He,{}),e.t("image-panel.arrange.backward")]})})})]}),c.jsxs("div",{className:H,children:[c.jsx("div",{className:"univer-w-1/2",children:c.jsx(P.Button,{onClick:()=>{l(h.ArrangeTypeEnum.front)},children:c.jsxs("span",{className:re,children:[c.jsx(Ge,{}),e.t("image-panel.arrange.front")]})})}),c.jsx("div",{className:"univer-w-1/2",children:c.jsx(P.Button,{onClick:()=>{l(h.ArrangeTypeEnum.back)},children:c.jsxs("span",{className:re,children:[c.jsx(je,{}),e.t("image-panel.arrange.back")]})})})]})]})},ut=i=>{const r=V.useDependency(h.LocaleService),t=V.useDependency(y.IRenderManagerService),e=V.useDependency(D.IDrawingManagerService),{hasGroup:n,drawings:s}=i,[a,o]=_.useState(!1),[l,d]=_.useState(!0),[u,g]=_.useState(!0),f=m=>m?"block":"none",p=()=>{const m=e.getFocusDrawings(),{unitId:b,subUnitId:C}=m[0],B=h.Tools.generateRandomId(10),M=y.getGroupState(0,0,m.map(O=>O.transform||{})),A={unitId:b,subUnitId:C,drawingId:B,drawingType:h.DrawingTypeEnum.DRAWING_GROUP,transform:M},E=m.map(O=>{const N=O.transform||{left:0,top:0},{unitId:T,subUnitId:U,drawingId:R}=O;return{unitId:T,subUnitId:U,drawingId:R,transform:{...N,left:N.left-M.left,top:N.top-M.top},groupId:B}});e.featurePluginGroupUpdateNotification([{parent:A,children:E}])},S=m=>{if(m.drawingType!==h.DrawingTypeEnum.DRAWING_GROUP)return;const{unitId:b,subUnitId:C,drawingId:B,transform:M={width:0,height:0}}=m;if(M==null)return;const A=e.getDrawingsByGroup({unitId:b,subUnitId:C,drawingId:B});if(A.length===0)return;const E=A.map(O=>{const{transform:N}=O,{unitId:T,subUnitId:U,drawingId:R}=O,x=y.transformObjectOutOfGroup(N||{},M,M.width||0,M.height||0);return{unitId:T,subUnitId:U,drawingId:R,transform:{...N,...x},groupId:void 0}});return{parent:m,children:E}},w=()=>{const b=e.getFocusDrawings().map(C=>S(C)).filter(C=>C!=null);b.length!==0&&e.featurePluginUngroupUpdateNotification(b)};return _.useEffect(()=>{const m=s[0];if(m==null)return;const{unitId:b}=m,C=t.getRenderById(b),B=C==null?void 0:C.scene;if(B==null)return;const M=B.getTransformerByCreate(),A=M.clearControl$.subscribe(O=>{O===!0&&o(!1)}),E=M.changeStart$.subscribe(O=>{const{objects:N}=O,T=ge(N,e),U=T.filter(K=>(K==null?void 0:K.drawingType)===h.DrawingTypeEnum.DRAWING_GROUP);let R=!1,x=!1;T.length>1&&(R=!0),U.length>0&&(x=!0),o(R||x),d(R),g(x)});return()=>{E.unsubscribe(),A.unsubscribe()}},[]),c.jsxs("div",{className:"univer-relative univer-mt-5 univer-w-full",style:{display:f(n===!0?a:!1)},children:[c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:c.jsx("div",{children:r.t("image-panel.group.title")})})}),c.jsxs("div",{className:H,children:[c.jsx("div",{className:P.clsx(re,"univer-justify-center"),children:c.jsx(P.Button,{style:{display:f(l)},onClick:p,children:c.jsxs("span",{className:"univer-flex univer-items-center univer-gap-1",children:[c.jsx(Le,{}),r.t("image-panel.group.group")]})})}),c.jsx("div",{className:P.clsx(re,"univer-justify-center"),children:c.jsx(P.Button,{style:{display:f(u)},onClick:w,children:c.jsxs("span",{className:"univer-flex univer-items-center univer-gap-1",children:[c.jsx(Re,{}),r.t("image-panel.group.unGroup")]})})})]})]})},ie=20,gt=20,ht=[-3600,3600],we=300,ft=i=>{var Fe;const r=V.useDependency(h.LocaleService),t=V.useDependency(D.IDrawingManagerService),e=V.useDependency(y.IRenderManagerService),{drawings:n,transformShow:s}=i,a=n[0];if(a==null)return;const o=a.transform;if(o==null)return;const{unitId:l,subUnitId:d,drawingId:u,drawingType:g}=a,f=e.getRenderById(l),p=f==null?void 0:f.scene;if(p==null)return;const S=(Fe=p.getEngine())==null?void 0:Fe.activeScene;if(S==null)return;const w=p.getTransformerByCreate(),{width:m=0,height:b=0,left:C=0,top:B=0,angle:M=0}=o,[A,E]=_.useState(m),[O,N]=_.useState(b),[T,U]=_.useState(C),[R,x]=_.useState(B),[Y,K]=_.useState(M),[de,se]=_.useState(w.keepRatio),oe=(v,L,$,z)=>{const{width:W,height:ee}=S,{ancestorLeft:Z,ancestorTop:X}=p;let J=v,ce=L,pe=$,me=z;return v+Z<0&&(J=-Z),L+X<0&&(ce=-X),pe=W-J-Z,pe<ie&&(pe=ie),me=ee-ce-X,me<ie&&(me=ie),v+pe+Z>W&&(J=W-$-Z),L+me+X>ee&&(ce=ee-z-X),{limitLeft:J,limitTop:ce,limitWidth:pe,limitHeight:me}},ue=v=>{const{objects:L}=v,$=ge(L,t);if($.length!==1)return;const z=$[0];if(z==null)return;const{transform:W}=z;if(W==null)return;const{width:ee,height:Z,left:X,top:J,angle:ce}=W;ee!=null&&E(ee),Z!=null&&N(Z),X!=null&&U(X),J!=null&&x(J),ce!=null&&K(ce)};_.useEffect(()=>{const v=[w.changeStart$.subscribe(L=>{ue(L)}),w.changing$.subscribe(L=>{ue(L)}),w.changeEnd$.subscribe(L=>{ue(L)}),t.focus$.subscribe(L=>{if(L.length!==1)return;const $=t.getDrawingByParam(L[0]);if($==null)return;const z=$.transform;if(z==null)return;const{width:W,height:ee,left:Z,top:X,angle:J}=z;W!=null&&E(W),ee!=null&&N(ee),Z!=null&&U(Z),X!=null&&x(X),J!=null&&K(J)})];return()=>{v.forEach(L=>L.unsubscribe())}},[]);const Q=h.debounce(v=>{if(v==null)return;v=Math.max(v,ie);const{limitWidth:L,limitHeight:$}=oe(T,R,v,O);v=Math.min(v,L);const z={unitId:l,subUnitId:d,drawingId:u,drawingType:g,transform:{width:v}};if(de){let W=v/A*O;if(W=Math.max(W,gt),W>$)return;N(W),z.transform.height=W}E(v),t.featurePluginUpdateNotification([z]),w.refreshControls().changeNotification()},we),Ne=h.debounce(v=>{if(v==null)return;v=Math.max(v,ie);const{limitHeight:L,limitWidth:$}=oe(T,R,A,v);v=Math.min(v,L);const z={unitId:l,subUnitId:d,drawingId:u,drawingType:g,transform:{height:v}};if(de){let W=v/O*A;if(W=Math.max(W,ie),W>$)return;E(W),z.transform.width=W}N(v),t.featurePluginUpdateNotification([z]),w.refreshControls().changeNotification()},we),Et=h.debounce(v=>{if(v==null)return;const{limitLeft:L}=oe(v,R,A,O);v=L;const $={unitId:l,subUnitId:d,drawingId:u,drawingType:g,transform:{left:v}};U(v),t.featurePluginUpdateNotification([$]),w.refreshControls().changeNotification()},we),Tt=h.debounce(v=>{if(v==null)return;const{limitTop:L}=oe(T,v,A,O);v=L;const $={unitId:l,subUnitId:d,drawingId:u,drawingType:g,transform:{top:v}};x(v),t.featurePluginUpdateNotification([$]),w.refreshControls().changeNotification()},we),Pt=v=>{if(v==null)return;const[L,$]=ht;v<L&&(v=L),v>$&&(v=$);const z={unitId:l,subUnitId:d,drawingId:u,drawingType:g,transform:{angle:v}};K(v),t.featurePluginUpdateNotification([z]),w.refreshControls().changeNotification()},Bt=v=>{se(v),w.keepRatio=v},Ut=v=>v?"block":"none";return c.jsxs("div",{className:`
|
|
14
|
+
univer-relative univer-mt-5 univer-w-full univer-border-b-0 univer-border-l-0 univer-border-r-0
|
|
15
|
+
univer-border-t univer-border-solid univer-border-t-gray-200
|
|
16
|
+
`,style:{display:Ut(s)},children:[c.jsx("div",{className:H,children:c.jsx("div",{className:P.clsx(k),children:c.jsx("div",{children:r.t("image-panel.transform.title")})})}),c.jsxs("div",{className:H,children:[c.jsx("div",{className:P.clsx(k),children:c.jsxs("label",{children:[c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:r.t("image-panel.transform.width")})}),c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:c.jsx(P.InputNumber,{precision:1,value:A,onChange:v=>{Q(v)}})})})]})}),c.jsx("div",{className:P.clsx(k),children:c.jsxs("label",{children:[c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:r.t("image-panel.transform.height")})}),c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:c.jsx(P.InputNumber,{precision:1,value:O,onChange:v=>{Ne(v)}})})})]})}),c.jsx("div",{className:P.clsx(k),children:c.jsxs("label",{children:[c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:r.t("image-panel.transform.lock")})}),c.jsx("div",{className:P.clsx(H,"univer-h-9 univer-items-center univer-justify-center"),children:c.jsx("div",{className:k,children:c.jsx(P.Checkbox,{checked:de,onChange:Bt})})})]})})]}),c.jsxs("div",{className:H,children:[c.jsx("div",{className:P.clsx(k),children:c.jsxs("label",{children:[c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:r.t("image-panel.transform.x")})}),c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:c.jsx(P.InputNumber,{precision:1,value:T,onChange:v=>{Et(v)}})})})]})}),c.jsx("div",{className:P.clsx(k),children:c.jsxs("label",{children:[c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:r.t("image-panel.transform.y")})}),c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:c.jsx(P.InputNumber,{precision:1,value:R,onChange:v=>{Tt(v)}})})})]})}),c.jsx("div",{className:P.clsx(k),children:c.jsxs("label",{children:[c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:r.t("image-panel.transform.rotate")})}),c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:c.jsx(P.InputNumber,{precision:1,value:Y,onChange:Pt})})})]})})]})]})},Se={id:"sheet.operation.open-image-crop",type:h.CommandType.OPERATION,handler:(i,r)=>!0},ne={id:"sheet.operation.close-image-crop",type:h.CommandType.OPERATION,handler:(i,r)=>!0};var G=(i=>(i.FREE="0",i.R1_1="1",i.R16_9="2",i.R9_16="3",i.R5_4="4",i.R4_5="5",i.R4_3="6",i.R3_4="7",i.R3_2="8",i.R2_3="9",i))(G||{});const he={id:"sheet.operation.Auto-image-crop",type:h.CommandType.OPERATION,handler:(i,r)=>!0},pt=i=>{const r=V.useDependency(h.ICommandService),t=V.useDependency(h.LocaleService),{drawings:e,cropperShow:n}=i;if(e[0]==null)return;const[a,o]=_.useState(G.FREE),l=_.useRef(!1),d=[{label:t.t("image-panel.crop.mode"),value:G.FREE},{label:"1:1",value:G.R1_1},{label:"16:9",value:G.R16_9},{label:"9:16",value:G.R9_16},{label:"5:4",value:G.R5_4},{label:"4:5",value:G.R4_5},{label:"4:3",value:G.R4_3},{label:"3:4",value:G.R3_4},{label:"3:2",value:G.R3_2},{label:"2:3",value:G.R2_3}];_.useEffect(()=>{const p=r.onCommandExecuted(S=>{if(S.id===ne.id){const w=S.params;w!=null&&w.isAuto||(l.current=!1)}});return()=>{p==null||p.dispose()}},[]);function u(p){o(p),l.current&&r.executeCommand(he.id,{cropType:p})}const g=p=>p?"block":"none",f=p=>{r.executeCommand(he.id,{cropType:p}),l.current=!0};return c.jsxs("div",{className:`
|
|
17
|
+
univer-relative univer-mt-5 univer-w-full univer-border-b-0 univer-border-l-0 univer-border-r-0
|
|
18
|
+
univer-border-t univer-border-solid univer-border-t-gray-200
|
|
19
|
+
`,style:{display:g(n)},children:[c.jsx("div",{className:H,children:c.jsx("div",{className:k,children:c.jsx("div",{children:t.t("image-panel.crop.title")})})}),c.jsxs("div",{className:H,children:[c.jsx("div",{className:re,children:c.jsx(P.Button,{onClick:()=>{f(a)},children:c.jsxs("span",{className:"univer-flex univer-items-center univer-gap-1",children:[c.jsx(Ae,{}),t.t("image-panel.crop.start")]})})}),c.jsx("div",{className:re,children:c.jsx(P.Select,{value:a,options:d,onChange:u})})]})]})},mt=i=>{const r=V.useDependency(D.IDrawingManagerService),t=V.useDependency(y.IRenderManagerService),e=V.useDependency(h.LocaleService),{drawings:n,hasArrange:s=!0,hasTransform:a=!0,hasAlign:o=!0,hasCropper:l=!0,hasGroup:d=!0}=i,u=n[0];if(u==null)return;const{unitId:g}=u,f=t.getRenderById(g),p=f==null?void 0:f.scene;if(p==null)return;const S=p.getTransformerByCreate(),[w,m]=_.useState(!0),[b,C]=_.useState(!0),[B,M]=_.useState(!1),[A,E]=_.useState(!0),[O,N]=_.useState(!1);return _.useEffect(()=>{const T=S.clearControl$.subscribe(x=>{x===!0&&(m(!1),C(!1),M(!1),E(!1),N(!0))}),U=S.changeStart$.subscribe(x=>{const{objects:Y}=x,K=ge(Y,r);K.length===0?(m(!1),C(!1),M(!1),E(!1),N(!0)):K.length===1?(m(!0),C(!0),M(!1),E(!0),N(!1)):(m(!0),C(!1),M(!0),E(!1),N(!1))}),R=r.focus$.subscribe(x=>{x.length===0?(m(!1),C(!1),M(!1),E(!1),N(!0)):x.length===1?(m(!0),C(!0),M(!1),E(!0),N(!1)):(m(!0),C(!1),M(!0),E(!1),N(!1))});return()=>{U.unsubscribe(),T.unsubscribe(),R.unsubscribe()}},[]),c.jsxs(c.Fragment,{children:[c.jsx("div",{style:{display:O===!0?"block":"none",height:"100%"},children:c.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",top:"50%",marginTop:"-100px"},children:c.jsx("span",{children:e.t("image-panel.null")})})}),c.jsx(dt,{arrangeShow:s===!0?w:!1,drawings:n}),c.jsx(ft,{transformShow:a===!0?b:!1,drawings:n}),c.jsx(Xe,{alignShow:o===!0?B:!1,drawings:n}),c.jsx(pt,{cropperShow:l===!0?A:!1,drawings:n}),c.jsx(ut,{hasGroup:d,drawings:n})]})},Ve=i=>{var w;const{popup:r}=i,t=(w=r==null?void 0:r.extraProps)==null?void 0:w.menuItems;if(!t)return null;const e=V.useDependency(h.ICommandService),n=V.useDependency(h.LocaleService),[s,a]=_.useState(!1),[o,l]=_.useState(!1),d=()=>{l(!0)},u=()=>{l(!1)},g=m=>{a(m)},f=m=>{e.executeCommand(m.commandId,m.commandParams),a(!1)},p=s||o,S=t.filter(m=>!m.disable);return c.jsx("div",{onMouseEnter:d,onMouseLeave:u,children:c.jsx(P.DropdownMenu,{align:"start",items:S.map(m=>({type:"item",children:n.t(m.label),onSelect:()=>f(m)})),open:s,onOpenChange:g,children:c.jsxs("div",{className:P.clsx(`
|
|
7
20
|
univer-flex univer-items-center univer-gap-2 univer-rounded univer-border univer-border-solid
|
|
8
21
|
univer-border-gray-200 univer-p-1
|
|
9
22
|
hover:univer-bg-gray-100
|
|
10
|
-
`,{"univer-bg-gray-100":s,"univer-bg-white":!s}),children:[l.jsx(Ue,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),p&&l.jsx(Le,{className:"univer-text-[10px] univer-text-gray-400"})]})})})},We="COMPONENT_IMAGE_POPUP_MENU",wn="drawing-ui.config",$e={},be={id:"sheet.operation.image-reset-size",type:h.CommandType.OPERATION,handler:(a,t)=>!0},vn=a=>{const{src:t}=a;return t?l.jsx("div",{children:l.jsx("img",{src:t,alt:"Univer Image Viewer",style:{width:"100%",height:"100%",position:"relative"}})}):null};var Sn=Object.getOwnPropertyDescriptor,_n=(a,t,n,e)=>{for(var r=e>1?void 0:e?Sn(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},ze=(a,t)=>(n,e)=>t(n,e,a);let we=class extends h.Disposable{constructor(a,t){super(),this._componentManager=a,this._commandService=t,this._init()}_initCustomComponents(){const a=this._componentManager;this.disposeWithMe(a.register(We,ke)),this.disposeWithMe(a.register(Ee,vn))}_initCommands(){[Ce,ne,be,fe,me].forEach(a=>this.disposeWithMe(this._commandService.registerCommand(a)))}_init(){this._initCommands(),this._initCustomComponents()}};we=_n([ze(0,h.Inject(V.ComponentManager)),ze(1,h.ICommandService)],we);var In=Object.getOwnPropertyDescriptor,yn=(a,t,n,e)=>{for(var r=e>1?void 0:e?In(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},ve=(a,t)=>(n,e)=>t(n,e,a);let Se=class extends h.Disposable{constructor(t,n,e,r){super();ee(this,"_sceneListenerOnDrawingMap",new WeakSet);this._currentUniverService=t,this._commandService=n,this._renderManagerService=e,this._drawingManagerService=r,this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){const t=this._drawingManagerService.drawingManagerData,n=Ne(this._currentUniverService);if(n==null)return;const{unitId:e,subUnitId:r}=n;Object.keys(t).forEach(s=>{Object.keys(t[s]).forEach(i=>{const o=t[s][i].data;o==null||s!==e||i!==r||Object.keys(o).forEach(c=>{o[c]&&this._insertDrawing([{unitId:s,subUnitId:i,drawingId:c}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===fe.id){const n=t.params;if(n==null)return;this._drawingAlign(n)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(t=>{this._groupDrawings(t)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(t=>{this._ungroupDrawings(t)}))}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const n=this._renderManagerService.getRenderById(t),e=n==null?void 0:n.scene;if(e==null)return null;const r=e.getTransformerByCreate();return{scene:e,transformer:r}}_groupDrawings(t){t.forEach(n=>{this._groupDrawing(n)})}_groupDrawing(t){const{parent:n,children:e}=t,{unitId:r,subUnitId:s,drawingId:i}=n,o=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(o==null)return;const{scene:c,transformer:g}=o;this._commandService.syncExecuteCommand(ne.id);const d=[];if(e.forEach(p=>{const S=M.getDrawingShapeKeyByDrawingSearch(p),v=c.getObjectIncludeInGroup(S);if(v==null||d.includes(v))return;d.push(v);const{transform:C}=p;C!=null&&(v.classType===b.RENDER_CLASS_TYPE.GROUP?v.transformByState({left:C.left,top:C.top}):v.transformByState(C))}),d.length===0)return;const u=M.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:s,drawingId:i}),f=new b.Group(u);c.addObject(f,b.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(f),f.addObjects(...d),n.transform&&f.transformByState({left:n.transform.left,top:n.transform.top}),g.clearSelectedObjects(),g.setSelectedControl(f)}_ungroupDrawings(t){t.forEach(n=>{this._ungroupDrawing(n)})}_ungroupDrawing(t){const{parent:n,children:e}=t,r=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(r==null)return;const{scene:s,transformer:i}=r;e.forEach(u=>{const f=M.getDrawingShapeKeyByDrawingSearch(u),p=s.getObjectIncludeInGroup(f);if(p==null)return!0;if(p==null)return;const{transform:S}=u;S!=null&&(p.classType===b.RENDER_CLASS_TYPE.GROUP?p.transformByState({left:S.left,top:S.top}):p.transformByState(S))});const o=M.getDrawingShapeKeyByDrawingSearch(n),c=s.getObject(o),{width:g,height:d}=c;c.getObjects().forEach(u=>{c.removeSelfObjectAndTransform(u.oKey,g,d)}),c.dispose(),i.clearSelectedObjects()}_drawingAlign(t){const{alignType:n}=t,e=this._drawingManagerService.getFocusDrawings();if(n===A.default)return;const r=[];let s=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY,g=0;e.forEach(d=>{const{unitId:u,subUnitId:f,drawingId:p,drawingType:S}=d,v=this._drawingManagerService.getDrawingByParam({unitId:u,subUnitId:f,drawingId:p});if(v==null||v.transform==null)return;r.push({unitId:u,subUnitId:f,drawingId:p,drawingType:S,transform:v.transform});const{left:C=0,top:P=0,width:y=0,height:U=0}=v.transform;s=Math.min(s,C),i=Math.min(i,P),o=Math.max(o,C+y),c=Math.max(c,P+U),g++}),g!==0&&(this._sortDrawingTransform(r,n),this._applyAlignType(r,n,s,i,o,c,g))}_applyAlignType(t,n,e,r,s,i,o){const c=Math.round((s-e)/o*10)/10,g=Math.round((i-r)/o*10)/10,d=[],u=this._getSceneAndTransformerByDrawingSearch(t[0].unitId);if(u==null)return;const{scene:f,transformer:p}=u;t.forEach((S,v)=>{const{unitId:C,subUnitId:P,drawingId:y,transform:U,drawingType:O}=S,{left:R=0,top:T=0,width:N=0,height:E=0}=U;let B=R,j=T;switch(n){case A.left:B=e;break;case A.center:B=e+(s-e)/2-N/2;break;case A.right:B=s-N;break;case A.top:j=r;break;case A.middle:j=r+(i-r)/2-E/2;break;case A.bottom:j=i-E;break;case A.horizon:B=e+c*v;break;case A.vertical:j=r+g*v;break}(B!==R||j!==T)&&d.push({unitId:C,subUnitId:P,drawingId:y,drawingType:O,transform:{left:B,top:j}})}),this._drawingManagerService.featurePluginUpdateNotification(d),p.refreshControls().changeNotification()}_sortDrawingTransform(t,n){t.sort((e,r)=>{const s=e.transform,i=r.transform,{left:o=0,top:c=0,width:g=0,height:d=0}=s,{left:u=0,top:f=0,width:p=0,height:S=0}=i;switch(n){case A.left:return o-u;case A.center:return o+g/2-(u+p/2);case A.right:return o+g-(u+p);case A.top:return c-f;case A.middle:return c+d/2-(f+S/2);case A.bottom:return c+d-(f+S);case A.horizon:return o+g/2-(u+p/2);case A.vertical:return c+d/2-(f+S/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(t=>{this._drawingArrange(t)}))}_drawingArrange(t){const{unitId:n,subUnitId:e,drawingIds:r}=t,s=this._getSceneAndTransformerByDrawingSearch(n);if(s==null)return;const{scene:i}=s;r.forEach(o=>{const c=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:o}),g=i.fuzzyMathObjects(c,!0);if(g==null||g.length===0)return;const d=this._drawingManagerService.getDrawingOrder(n,e).indexOf(o);for(const u of g)u.setProps({zIndex:d}),u.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{this._insertDrawing(t)}))}_insertDrawing(t){const n=[];t.forEach(e=>{const{unitId:r}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;const i=this._getSceneAndTransformerByDrawingSearch(r);if(i==null)return;const{scene:o}=i;n.includes(o)||n.push(o)}),n.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(n=>{var d;const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._getSceneAndTransformerByDrawingSearch(e);if(i==null)return;const{scene:o}=i,c=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),g=o.fuzzyMathObjects(c,!0);if(g.length>0){for(const u of g)u.dispose();(d=o.getTransformer())==null||d.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(n=>{var N;const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._drawingManagerService.getDrawingByParam(n);if(i==null)return;const{transform:o,drawingType:c}=i,g=this._getSceneAndTransformerByDrawingSearch(e);if(g==null)return;const{scene:d,transformer:u}=g;if(o==null)return!0;const{left:f=0,top:p=0,width:S=0,height:v=0,angle:C=0,flipX:P=!1,flipY:y=!1,skewX:U=0,skewY:O=0}=o,R=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),T=d.getObject(R);if(T==null)return!0;T.transformByState({left:f,top:p,width:S,height:v,angle:C,flipX:P,flipY:y,skewX:U,skewY:O}),(N=d.getTransformer())==null||N.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(t=>{t.forEach(n=>{const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._getSceneAndTransformerByDrawingSearch(e);if(i==null)return;const o=this._drawingManagerService.getDrawingByParam(n);if(o==null)return;const{transform:c}=o,{scene:g}=i,d=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),u=g.getObject(d);if(u==null||c==null)return!0;const{left:f=0,top:p=0,width:S=0,height:v=0,angle:C=0,flipX:P=!1,flipY:y=!1,skewX:U=0,skewY:O=0}=c;u.transformByState({left:f,top:p,width:S,height:v,angle:C,flipX:P,flipY:y,skewX:U,skewY:O})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(t=>{t.forEach(n=>{const{unitId:e,subUnitId:r,drawingId:s,visible:i}=n,o=this._getSceneAndTransformerByDrawingSearch(e);if(o==null)return;const{scene:c}=o,g=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),d=c.getObject(g);if(d==null)return!0;i?d.show():d.hide()})}))}_filterUpdateParams(t,n){return t.filter((e,r)=>{if(e==null)return!1;const{transform:s}=e;return h.checkIfMove(s,n==null?void 0:n[r])})}_addListenerOnDrawing(t){const n=t.getTransformerByCreate();let e=null;this.disposeWithMe(h.toDisposable(n.changeStart$.subscribe(r=>{const{objects:s}=r,i=Array.from(s.values()),o=[];e=i.map(c=>{const{left:g,top:d,height:u,width:f,angle:p,oKey:S,isInGroup:v}=c,C=this._drawingManagerService.getDrawingOKey(S);if(v||c instanceof b.Group){let P=c.ancestorGroup;if(P==null&&c instanceof b.Group&&(P=c),P==null)return null;const y=this._drawingManagerService.getDrawingOKey(P.oKey);if(y){const{unitId:U,subUnitId:O,drawingId:R}=y;o.push({unitId:U,subUnitId:O,drawingId:R});const{left:T,top:N,height:E,width:B,angle:j}=P;return{left:T,top:N,height:E,width:B,angle:j}}}else if(C!=null){const{unitId:P,subUnitId:y,drawingId:U}=C;return o.push({unitId:P,subUnitId:y,drawingId:U}),{left:g,top:d,height:u,width:f,angle:p}}return null}).filter(c=>c!=null),o.length>0?this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,o):this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,[])}))),this.disposeWithMe(h.toDisposable(n.changeEnd$.subscribe(r=>{const{objects:s}=r,i=this._filterUpdateParams(ge(s,this._drawingManagerService),e);i.length>0&&this._drawingManagerService.featurePluginUpdateNotification(i)})))}};Se=yn([ve(0,h.IUniverInstanceService),ve(1,h.ICommandService),ve(2,b.IRenderManagerService),ve(3,M.IDrawingManagerService)],Se);class de extends b.Shape{constructor(n,e){e==null&&(e={}),e.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:"rgb(0, 0, 0)",anchorStroke:"rgb(255, 255, 255)",anchorSize:24};super(n,e);ee(this,"_srcRect");ee(this,"_prstGeom");ee(this,"_applyTransform");ee(this,"_dragPadding",8);ee(this,"_cacheCanvas");e!=null&&e.srcRect&&(this._srcRect=e.srcRect),e!=null&&e.prstGeom&&(this._prstGeom=e.prstGeom),e!=null&&e.applyTransform&&(this._applyTransform=e.applyTransform),e!=null&&e.dragPadding&&(this._dragPadding=e.dragPadding),this._applyProps()}refreshSrcRect(n,e){this._srcRect=n,this._applyTransform=e,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var n;super.dispose(),(n=this._cacheCanvas)==null||n.dispose(),this._srcRect=null}isHit(n){const e=this.getInverseCoord(n);return e.x>=-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2&&e.y>=-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2&&!this._inSurround(e)}_inSurround(n){const e=this._dragPadding;return n.x>=e-this.strokeWidth/2&&n.x<=this.width+this.strokeWidth/2-e&&n.y>=e-this.strokeWidth/2&&n.y<=this.height+this.strokeWidth/2-e}render(n,e){return this.visible?(n.save(),this._draw(n),n.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(n){var c,g;const r=this.getScene().getEngine(),{width:s,height:i}=r;this._initialCacheCanvas(),(c=this._cacheCanvas)==null||c.clear();const o=(g=this._cacheCanvas)==null?void 0:g.getContext();o!=null&&(o.save(),b.Rect.drawWith(o,{left:0,top:0,width:s,height:i,fill:"rgba(0, 0, 0, 0.5)"}),o.setTransform(n.getTransform()),this._clipForApplyObject(o),this._applyCache(n),o.restore())}_clipForApplyObject(n){let e=0;if(this._prstGeom!=null&&(e=1),n.globalCompositeOperation="destination-out",n.beginPath(),e===0){const r=this.transform.getMatrix();n.transform(r[0],r[1],r[2],r[3],r[4],r[5]),n.rect(0,0,this.width,this.height),n.fill()}}_applyProps(){if(this._applyTransform==null)return;let n=0,e=0,r=0,s=0;const{left:i=0,top:o=0,width:c=0,height:g=0,angle:d}=this._applyTransform;if(this._srcRect!=null){const{left:p=0,top:S=0,right:v=0,bottom:C=0}=this._srcRect;n=p,e=S,r=v,s=C}const u=i+n,f=o+e;this.transformByState({left:u,top:f,width:i+c-r-u,height:o+g-s-f,angle:d})}_applyCache(n){if(!n||this._cacheCanvas==null)return;const e=this._cacheCanvas.getContext();e.save(),n.save(),n.setTransform(1,0,0,1,0,0),e.setTransform(1,0,0,1,0,0),n.drawImage(this._cacheCanvas.getCanvasEle(),0,0),n.restore(),e.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;const n=this.getScene();if(n==null)return;this._cacheCanvas=new b.Canvas;const e=n.getEngine();this._cacheCanvas.setSize(e.width,e.height),e.onTransformChange$.subscribeEvent(()=>{var r;(r=this._cacheCanvas)==null||r.setSize(e.width,e.height),this.makeDirty(!0)})}}var bn=Object.getOwnPropertyDescriptor,Pn=(a,t,n,e)=>{for(var r=e>1?void 0:e?bn(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},oe=(a,t)=>(n,e)=>t(n,e,a);let _e=class extends h.Disposable{constructor(t,n,e,r,s,i){super();ee(this,"_sceneListenerOnImageMap",new WeakSet);this._commandService=t,this._drawingManagerService=n,this._renderManagerService=e,this._univerInstanceService=r,this._messageService=s,this._localeService=i,this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==me.id)return;const n=t.params;if(n==null)return;const{cropType:e}=n,r=this._drawingManagerService.getFocusDrawings();if(r.length!==1)return;const s=r[0],{unitId:i,subUnitId:o,drawingId:c}=s,g=this._renderManagerService.getRenderById(i),d=g==null?void 0:g.scene;if(d==null)return!0;this._searchCropObject(d)!=null&&this._commandService.syncExecuteCommand(ne.id,{isAuto:!0});const f=M.getDrawingShapeKeyByDrawingSearch({unitId:i,subUnitId:o,drawingId:c}),p=d.getObject(f);if(!(p instanceof b.Image)){this._messageService.show({type:I.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}p!=null&&(this._updateCropperObject(e,p),this._commandService.executeCommand(Ce.id,{unitId:i,subUnitId:o,drawingId:c}))}))}_calculateSrcRectByRatio(t,n,e,r,s,i){const o=e/r,c=s/i;let g=e,d=r;o>c?g=r*c:d=e/c;const u=(e-g)/2,f=(r-d)/2;return{left:b.precisionTo(u,1),top:b.precisionTo(f,1),right:b.precisionTo(e-(u+g),1),bottom:b.precisionTo(r-(f+d),1)}}_updateCropperObject(t,n){const{left:e,top:r,width:s,height:i}=n.calculateTransformWithSrcRect();let o;switch(t){case H.R1_1:o=this._calculateSrcRectByRatio(e,r,s,i,1,1);break;case H.R16_9:o=this._calculateSrcRectByRatio(e,r,s,i,16,9);break;case H.R9_16:o=this._calculateSrcRectByRatio(e,r,s,i,9,16);break;case H.R5_4:o=this._calculateSrcRectByRatio(e,r,s,i,5,4);break;case H.R4_5:o=this._calculateSrcRectByRatio(e,r,s,i,4,5);break;case H.R4_3:o=this._calculateSrcRectByRatio(e,r,s,i,4,3);break;case H.R3_4:o=this._calculateSrcRectByRatio(e,r,s,i,3,4);break;case H.R3_2:o=this._calculateSrcRectByRatio(e,r,s,i,3,2);break;case H.R2_3:o=this._calculateSrcRectByRatio(e,r,s,i,2,3);break;case H.FREE:}if(o==null)return;n.setSrcRect(o);const{left:c=0,top:g=0,bottom:d=0,right:u=0}=o;n.transformByStateCloseCropper({left:e+c,top:r+g,width:s-u-c,height:i-d-g})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==Ce.id)return;const n=t.params;if(n==null)return;const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._renderManagerService.getRenderById(e),o=i==null?void 0:i.scene;if(o==null)return!0;if(this._sceneListenerOnImageMap.has(o)||(this._addListenerOnImage(o),this._sceneListenerOnImageMap.add(o)),this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:r,drawingId:s})==null)return;const g=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),d=o.getObject(g);if(d==null)return;if(!(d instanceof b.Image)){this._messageService.show({type:I.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}const u=o.getTransformer();u==null||u.clearControls();const f=new de(`${g}-crop`,{srcRect:d.srcRect,prstGeom:d.prstGeom,applyTransform:d.calculateTransformWithSrcRect()});o.addObject(f,d.getLayerIndex()+1).attachTransformerTo(f),u==null||u.createControlForCopper(f),this._addHoverForImageCopper(f),d.openRenderByCropper(),u==null||u.refreshControls(),f.makeDirty(!0),this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:r,drawingId:s}])}))}_searchCropObject(t){const n=t.getAllObjectsByOrder();for(const e of n)if(e instanceof de)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id!==ne.id)return;const e=this._univerInstanceService.getFocusedUnit();if(e==null)return;const r=e.getUnitId(),s=this._renderManagerService.getRenderById(r),i=s==null?void 0:s.scene;if(i==null)return!0;const o=this._searchCropObject(i);if(o==null)return;const c=this._getApplyObjectByCropObject(o);if(c==null)return;const g=i.getTransformerByCreate();g.detachFrom(o),g.clearCopperControl();const d=this._getSrcRectByTransformState(c,o),u=this._drawingManagerService.getDrawingOKey(c.oKey);if(u!=null){const{left:f,top:p,height:S,width:v}=o;this._drawingManagerService.featurePluginUpdateNotification([{...u,transform:{...u.transform,left:f,top:p,height:S,width:v},srcRect:d.srcRectAngle}])}c.setSrcRect({...d.srcRectAngle}),c.closeRenderByCropper(),c.makeDirty(!0),o==null||o.dispose()}));const t=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET).pipe(Me.switchMap(n=>n?n.activeSheet$:Me.of(null)));this.disposeWithMe(t.subscribe(()=>{this._commandService.syncExecuteCommand(ne.id)}))}_getApplyObjectByCropObject(t){const n=t.oKey,e=n.slice(0,n.length-5),r=t.getScene();if(!r)return null;const s=r.getObject(e);return s==null?null:s}_addListenerOnImage(t){const n=t.getTransformerByCreate();let e=null;this.disposeWithMe(n.changeStart$.subscribe(r=>{const{objects:s}=r,i=s.values().next().value;if(i==null||!(i instanceof de))return;const{left:o,top:c,height:g,width:d,angle:u}=i;e={left:o,top:c,height:g,width:d,angle:u},n.clearCopperControl()})),this.disposeWithMe(n.changeEnd$.subscribe(r=>{const{objects:s}=r,i=s.values().next().value;if(i==null||!(i instanceof de))return;const{left:o,top:c,height:g,width:d,angle:u}=i;if(!h.checkIfMove({left:o,top:c,height:g,width:d,angle:u},e))return;const f=this._getApplyObjectByCropObject(i);if(f==null)return;const p=this._getSrcRectByTransformState(f,i);i.refreshSrcRect(p.srcRect,f.getState()),n.createControlForCopper(i)})),this._endCropListener(t)}_addHoverForImageCopper(t){this.disposeWithMe(t.onPointerEnter$.subscribeEvent(()=>{t.cursor=b.CURSOR_TYPE.MOVE})),this.disposeWithMe(t.onPointerLeave$.subscribeEvent(()=>{t.cursor=b.CURSOR_TYPE.DEFAULT}))}_endCropListener(t){const n=t.getTransformerByCreate();this.disposeWithMe(n.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(ne.id)}))}_getSrcRectByTransformState(t,n){const{left:e,top:r,height:s,width:i,strokeWidth:o,angle:c}=n,{left:g,top:d,width:u,height:f,angle:p,strokeWidth:S}=t,v=e-g,C=r-d,P={left:v,top:C,right:u-v-i,bottom:f-C-s},y={...P};if(p!==0){const U=e+i/2,O=r+s/2,R=new b.Vector2(U,O),T=u/2+g,N=f/2+d,E=new b.Vector2(T,N),B=new b.Vector2(g,d);B.rotateByPoint(b.degToRad(p),E);const j=B.clone();j.rotateByPoint(b.degToRad(-p),R);const G=e-j.x,x=r-j.y;y.left=G,y.top=x,y.right=u-G-i,y.bottom=f-x-s}return{srcRect:P,srcRectAngle:y}}};_e=Pn([oe(0,h.ICommandService),oe(1,M.IDrawingManagerService),oe(2,b.IRenderManagerService),oe(3,h.IUniverInstanceService),oe(4,V.IMessageService),oe(5,h.Inject(h.LocaleService))],_e);var Dn=Object.getOwnPropertyDescriptor,Mn=(a,t,n,e)=>{for(var r=e>1?void 0:e?Dn(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},re=(a,t)=>(n,e)=>t(n,e,a);let Ie=class extends h.Disposable{constructor(a,t,n,e,r,s,i){super(),this._commandService=a,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=e,this._imageIoService=r,this._currentUniverService=s,this._drawingRenderService=i,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(a=>{if(a.id===be.id){const t=a.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(a){if(a==null)return;const t=this._renderManagerService.getRenderById(a),n=t==null?void 0:t.scene;if(n==null)return null;const e=n.getTransformerByCreate();return{scene:n,transformer:e}}_resetImageSize(a){const t=[],n=[];a.forEach(e=>{const{unitId:r,subUnitId:s,drawingId:i}=e,o=this._getSceneAndTransformerByDrawingSearch(r);if(o==null)return;const{scene:c}=o,g=M.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:s,drawingId:i}),d=c.getObject(g);if(d==null)return!0;const u=this._drawingManagerService.getDrawingByParam(e);if(u==null)return!0;if(u.drawingType!==h.DrawingTypeEnum.DRAWING_IMAGE)return;d.resetSize();const{width:f,height:p}=d.getNativeSize();n.includes(c)===!1&&n.push(c),t.push({...u,transform:{...u.transform,height:p,width:f,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(t),n.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,a)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(a=>{this._insertImages(a)}))}_insertImages(a){a.forEach(async t=>{var c;const{unitId:n,subUnitId:e}=t,r=this._getSceneAndTransformerByDrawingSearch(n),s=(c=Ne(this._currentUniverService,n))==null?void 0:c.subUnitId;if(r==null||s!==e)return;const i=this._drawingManagerService.getDrawingByParam(t);if(i==null)return;const o=await this._drawingRenderService.renderImages(i,r.scene);if(this._drawingManagerService.refreshTransform([i]),!(o==null||o.length===0))for(const g of o)this._addHoverForImage(g),this._addDialogForImage(g)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(a=>{a.forEach(t=>{const{unitId:n,subUnitId:e,drawingId:r}=t,s=this._drawingManagerService.getDrawingByParam(t);if(s==null)return;const{transform:i,drawingType:o,srcRect:c,prstGeom:g,source:d,imageSourceType:u}=s;if(o!==h.DrawingTypeEnum.DRAWING_IMAGE)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:p,transformer:S}=f;if(i==null)return!0;const v=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:r}),C=p.getObject(v);if(C==null)return!0;C.setSrcRect(c),C.setPrstGeom(g),d!=null&&d.length>0&&(u===h.ImageSourceType.BASE64||u===h.ImageSourceType.URL)&&C.changeSource(d)})}))}_addHoverForImage(a){this.disposeWithMe(h.toDisposable(a.onPointerEnter$.subscribeEvent(()=>{a.cursor=b.CURSOR_TYPE.GRAB}))),this.disposeWithMe(h.toDisposable(a.onPointerLeave$.subscribeEvent(()=>{a.cursor=b.CURSOR_TYPE.DEFAULT})))}_addDialogForImage(a){this.disposeWithMe(h.toDisposable(a.onDblclick$.subscribeEvent(()=>{const t=`${a.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(t,a.getNative().src,a.getNativeSize().width,a.getNativeSize().height)})))}};Ie=Mn([re(0,h.ICommandService),re(1,b.IRenderManagerService),re(2,M.IDrawingManagerService),re(3,V.IDialogService),re(4,M.IImageIoService),re(5,h.IUniverInstanceService),re(6,h.Inject(D.DrawingRenderService))],Ie);var On=Object.getOwnPropertyDescriptor,Nn=(a,t,n,e)=>{for(var r=e>1?void 0:e?On(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},Ke=(a,t)=>(n,e)=>t(n,e,a);const En="UNIVER_DRAWING_UI_PLUGIN";D.UniverDrawingUIPlugin=(Pe=class extends h.Plugin{constructor(t=$e,n,e){super(),this._config=t,this._injector=n,this._configService=e;const{menu:r,...s}=h.merge({},$e,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(wn,s)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(Se),this._injector.get(we),this._injector.get(_e),this._injector.get(Ie)}_initDependencies(){[[D.DrawingRenderService],[Se],[we],[_e],[Ie]].forEach(n=>this._injector.add(n))}},ee(Pe,"pluginName",En),Pe),D.UniverDrawingUIPlugin=Nn([Ke(1,h.Inject(h.Injector)),Ke(2,h.IConfigService)],D.UniverDrawingUIPlugin),D.AutoImageCropOperation=me,D.COMPONENT_IMAGE_POPUP_MENU=We,D.CloseImageCropOperation=ne,D.DrawingCommonPanel=Cn,D.ImageCropperObject=de,D.ImagePopupMenu=ke,D.ImageResetSizeOperation=be,D.OpenImageCropOperation=Ce,D.SetDrawingAlignOperation=fe,D.getUpdateParams=ge,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
23
|
+
`,{"univer-bg-gray-100":s,"univer-bg-white":!s}),children:[c.jsx(Ue,{className:"univer-fill-primary-600 univer-text-gray-900"}),p&&c.jsx(xe,{})]})})})},We="COMPONENT_IMAGE_POPUP_MENU",vt="drawing-ui.config",$e={},Me={id:"sheet.operation.image-reset-size",type:h.CommandType.OPERATION,handler:(i,r)=>!0};var wt=Object.getOwnPropertyDescriptor,St=(i,r,t,e)=>{for(var n=e>1?void 0:e?wt(r,t):r,s=i.length-1,a;s>=0;s--)(a=i[s])&&(n=a(n)||n);return n},ze=(i,r)=>(t,e)=>r(t,e,i);let _e=class extends h.Disposable{constructor(i,r){super(),this._componentManager=i,this._commandService=r,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(We,Ve))}_initCommands(){[Se,ne,Me,ve,he].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_init(){this._initCommands(),this._initCustomComponents()}};_e=St([ze(0,h.Inject(V.ComponentManager)),ze(1,h.ICommandService)],_e);var _t=Object.getOwnPropertyDescriptor,Ct=(i,r,t,e)=>{for(var n=e>1?void 0:e?_t(r,t):r,s=i.length-1,a;s>=0;s--)(a=i[s])&&(n=a(n)||n);return n},Ce=(i,r)=>(t,e)=>r(t,e,i);let ye=class extends h.Disposable{constructor(r,t,e,n){super();te(this,"_sceneListenerOnDrawingMap",new WeakSet);this._currentUniverService=r,this._commandService=t,this._renderManagerService=e,this._drawingManagerService=n,this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){const r=this._drawingManagerService.drawingManagerData,t=Pe(this._currentUniverService);if(t==null)return;const{unitId:e,subUnitId:n}=t;Object.keys(r).forEach(s=>{Object.keys(r[s]).forEach(a=>{const o=r[s][a].data;o==null||s!==e||a!==n||Object.keys(o).forEach(l=>{o[l]&&this._insertDrawing([{unitId:s,subUnitId:a,drawingId:l}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===ve.id){const t=r.params;if(t==null)return;this._drawingAlign(t)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(r=>{this._groupDrawings(r)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(r=>{this._ungroupDrawings(r)}))}_getSceneAndTransformerByDrawingSearch(r){if(r==null)return;const t=this._renderManagerService.getRenderById(r),e=t==null?void 0:t.scene;if(e==null)return null;const n=e.getTransformerByCreate();return{scene:e,transformer:n}}_groupDrawings(r){r.forEach(t=>{this._groupDrawing(t)})}_groupDrawing(r){const{parent:t,children:e}=r,{unitId:n,subUnitId:s,drawingId:a}=t,o=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(o==null)return;const{scene:l,transformer:d}=o;this._commandService.syncExecuteCommand(ne.id);const u=[];if(e.forEach(p=>{const S=D.getDrawingShapeKeyByDrawingSearch(p),w=l.getObjectIncludeInGroup(S);if(w==null||u.includes(w))return;u.push(w);const{transform:m}=p;m!=null&&(w.classType===y.RENDER_CLASS_TYPE.GROUP?w.transformByState({left:m.left,top:m.top}):w.transformByState(m))}),u.length===0)return;const g=D.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:a}),f=new y.Group(g);l.addObject(f,y.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(f),f.addObjects(...u),t.transform&&f.transformByState({left:t.transform.left,top:t.transform.top}),d.clearSelectedObjects(),d.setSelectedControl(f)}_ungroupDrawings(r){r.forEach(t=>{this._ungroupDrawing(t)})}_ungroupDrawing(r){const{parent:t,children:e}=r,n=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(n==null)return;const{scene:s,transformer:a}=n;e.forEach(g=>{const f=D.getDrawingShapeKeyByDrawingSearch(g),p=s.getObjectIncludeInGroup(f);if(p==null)return!0;if(p==null)return;const{transform:S}=g;S!=null&&(p.classType===y.RENDER_CLASS_TYPE.GROUP?p.transformByState({left:S.left,top:S.top}):p.transformByState(S))});const o=D.getDrawingShapeKeyByDrawingSearch(t),l=s.getObject(o),{width:d,height:u}=l;l.getObjects().forEach(g=>{l.removeSelfObjectAndTransform(g.oKey,d,u)}),l.dispose(),a.clearSelectedObjects()}_drawingAlign(r){const{alignType:t}=r,e=this._drawingManagerService.getFocusDrawings();if(t===j.default)return;const n=[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY,d=0;e.forEach(u=>{const{unitId:g,subUnitId:f,drawingId:p,drawingType:S}=u,w=this._drawingManagerService.getDrawingByParam({unitId:g,subUnitId:f,drawingId:p});if(w==null||w.transform==null)return;n.push({unitId:g,subUnitId:f,drawingId:p,drawingType:S,transform:w.transform});const{left:m=0,top:b=0,width:C=0,height:B=0}=w.transform;s=Math.min(s,m),a=Math.min(a,b),o=Math.max(o,m+C),l=Math.max(l,b+B),d++}),d!==0&&(this._sortDrawingTransform(n,t),this._applyAlignType(n,t,s,a,o,l,d))}_applyAlignType(r,t,e,n,s,a,o){const l=Math.round((s-e)/o*10)/10,d=Math.round((a-n)/o*10)/10,u=[],g=this._getSceneAndTransformerByDrawingSearch(r[0].unitId);if(g==null)return;const{scene:f,transformer:p}=g;r.forEach((S,w)=>{const{unitId:m,subUnitId:b,drawingId:C,transform:B,drawingType:M}=S,{left:A=0,top:E=0,width:O=0,height:N=0}=B;let T=A,U=E;switch(t){case j.left:T=e;break;case j.center:T=e+(s-e)/2-O/2;break;case j.right:T=s-O;break;case j.top:U=n;break;case j.middle:U=n+(a-n)/2-N/2;break;case j.bottom:U=a-N;break;case j.horizon:T=e+l*w;break;case j.vertical:U=n+d*w;break}(T!==A||U!==E)&&u.push({unitId:m,subUnitId:b,drawingId:C,drawingType:M,transform:{left:T,top:U}})}),this._drawingManagerService.featurePluginUpdateNotification(u),p.refreshControls().changeNotification()}_sortDrawingTransform(r,t){r.sort((e,n)=>{const s=e.transform,a=n.transform,{left:o=0,top:l=0,width:d=0,height:u=0}=s,{left:g=0,top:f=0,width:p=0,height:S=0}=a;switch(t){case j.left:return o-g;case j.center:return o+d/2-(g+p/2);case j.right:return o+d-(g+p);case j.top:return l-f;case j.middle:return l+u/2-(f+S/2);case j.bottom:return l+u-(f+S);case j.horizon:return o+d/2-(g+p/2);case j.vertical:return l+u/2-(f+S/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(r=>{this._drawingArrange(r)}))}_drawingArrange(r){const{unitId:t,subUnitId:e,drawingIds:n}=r,s=this._getSceneAndTransformerByDrawingSearch(t);if(s==null)return;const{scene:a}=s;n.forEach(o=>{const l=D.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:o}),d=a.fuzzyMathObjects(l,!0);if(d==null||d.length===0)return;const u=this._drawingManagerService.getDrawingOrder(t,e).indexOf(o);for(const g of d)g.setProps({zIndex:u}),g.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(r=>{this._insertDrawing(r)}))}_insertDrawing(r){const t=[];r.forEach(e=>{const{unitId:n}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;const a=this._getSceneAndTransformerByDrawingSearch(n);if(a==null)return;const{scene:o}=a;t.includes(o)||t.push(o)}),t.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(t=>{var u;const{unitId:e,subUnitId:n,drawingId:s}=t,a=this._getSceneAndTransformerByDrawingSearch(e);if(a==null)return;const{scene:o}=a,l=D.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:s}),d=o.fuzzyMathObjects(l,!0);if(d.length>0){for(const g of d)g.dispose();(u=o.getTransformer())==null||u.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(r=>{r.forEach(t=>{var O;const{unitId:e,subUnitId:n,drawingId:s}=t,a=this._drawingManagerService.getDrawingByParam(t);if(a==null)return;const{transform:o,drawingType:l}=a,d=this._getSceneAndTransformerByDrawingSearch(e);if(d==null)return;const{scene:u,transformer:g}=d;if(o==null)return!0;const{left:f=0,top:p=0,width:S=0,height:w=0,angle:m=0,flipX:b=!1,flipY:C=!1,skewX:B=0,skewY:M=0}=o,A=D.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:s}),E=u.getObject(A);if(E==null)return!0;E.transformByState({left:f,top:p,width:S,height:w,angle:m,flipX:b,flipY:C,skewX:B,skewY:M}),(O=u.getTransformer())==null||O.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(r=>{r.forEach(t=>{const{unitId:e,subUnitId:n,drawingId:s}=t,a=this._getSceneAndTransformerByDrawingSearch(e);if(a==null)return;const o=this._drawingManagerService.getDrawingByParam(t);if(o==null)return;const{transform:l}=o,{scene:d}=a,u=D.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:s}),g=d.getObject(u);if(g==null||l==null)return!0;const{left:f=0,top:p=0,width:S=0,height:w=0,angle:m=0,flipX:b=!1,flipY:C=!1,skewX:B=0,skewY:M=0}=l;g.transformByState({left:f,top:p,width:S,height:w,angle:m,flipX:b,flipY:C,skewX:B,skewY:M})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(r=>{r.forEach(t=>{const{unitId:e,subUnitId:n,drawingId:s,visible:a}=t,o=this._getSceneAndTransformerByDrawingSearch(e);if(o==null)return;const{scene:l}=o,d=D.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:s}),u=l.getObject(d);if(u==null)return!0;a?u.show():u.hide()})}))}_filterUpdateParams(r,t){return r.filter((e,n)=>{if(e==null)return!1;const{transform:s}=e;return h.checkIfMove(s,t==null?void 0:t[n])})}_addListenerOnDrawing(r){const t=r.getTransformerByCreate();let e=null;this.disposeWithMe(h.toDisposable(t.changeStart$.subscribe(n=>{const{objects:s}=n,a=Array.from(s.values()),o=[];e=a.map(l=>{const{left:d,top:u,height:g,width:f,angle:p,oKey:S,isInGroup:w}=l,m=this._drawingManagerService.getDrawingOKey(S);if(w||l instanceof y.Group){let b=l.ancestorGroup;if(b==null&&l instanceof y.Group&&(b=l),b==null)return null;const C=this._drawingManagerService.getDrawingOKey(b.oKey);if(C){const{unitId:B,subUnitId:M,drawingId:A}=C;o.push({unitId:B,subUnitId:M,drawingId:A});const{left:E,top:O,height:N,width:T,angle:U}=b;return{left:E,top:O,height:N,width:T,angle:U}}}else if(m!=null){const{unitId:b,subUnitId:C,drawingId:B}=m;return o.push({unitId:b,subUnitId:C,drawingId:B}),{left:d,top:u,height:g,width:f,angle:p}}return null}).filter(l=>l!=null),o.length>0?this._commandService.syncExecuteCommand(D.SetDrawingSelectedOperation.id,o):this._commandService.syncExecuteCommand(D.SetDrawingSelectedOperation.id,[])}))),this.disposeWithMe(h.toDisposable(t.changeEnd$.subscribe(n=>{const{objects:s}=n,a=this._filterUpdateParams(ge(s,this._drawingManagerService),e);a.length>0&&this._drawingManagerService.featurePluginUpdateNotification(a)})))}};ye=Ct([Ce(0,h.IUniverInstanceService),Ce(1,h.ICommandService),Ce(2,y.IRenderManagerService),Ce(3,D.IDrawingManagerService)],ye);class fe extends y.Shape{constructor(t,e){e==null&&(e={}),e.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:"rgb(0, 0, 0)",anchorStroke:"rgb(255, 255, 255)",anchorSize:24};super(t,e);te(this,"_srcRect");te(this,"_prstGeom");te(this,"_applyTransform");te(this,"_dragPadding",8);te(this,"_cacheCanvas");e!=null&&e.srcRect&&(this._srcRect=e.srcRect),e!=null&&e.prstGeom&&(this._prstGeom=e.prstGeom),e!=null&&e.applyTransform&&(this._applyTransform=e.applyTransform),e!=null&&e.dragPadding&&(this._dragPadding=e.dragPadding),this._applyProps()}refreshSrcRect(t,e){this._srcRect=t,this._applyTransform=e,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var t;super.dispose(),(t=this._cacheCanvas)==null||t.dispose(),this._srcRect=null}isHit(t){const e=this.getInverseCoord(t);return e.x>=-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2&&e.y>=-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2&&!this._inSurround(e)}_inSurround(t){const e=this._dragPadding;return t.x>=e-this.strokeWidth/2&&t.x<=this.width+this.strokeWidth/2-e&&t.y>=e-this.strokeWidth/2&&t.y<=this.height+this.strokeWidth/2-e}render(t,e){return this.visible?(t.save(),this._draw(t),t.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(t){var l,d;const n=this.getScene().getEngine(),{width:s,height:a}=n;this._initialCacheCanvas(),(l=this._cacheCanvas)==null||l.clear();const o=(d=this._cacheCanvas)==null?void 0:d.getContext();o!=null&&(o.save(),y.Rect.drawWith(o,{left:0,top:0,width:s,height:a,fill:"rgba(0, 0, 0, 0.5)"}),o.setTransform(t.getTransform()),this._clipForApplyObject(o),this._applyCache(t),o.restore())}_clipForApplyObject(t){let e=0;if(this._prstGeom!=null&&(e=1),t.globalCompositeOperation="destination-out",t.beginPath(),e===0){const n=this.transform.getMatrix();t.transform(n[0],n[1],n[2],n[3],n[4],n[5]),t.rect(0,0,this.width,this.height),t.fill()}}_applyProps(){if(this._applyTransform==null)return;let t=0,e=0,n=0,s=0;const{left:a=0,top:o=0,width:l=0,height:d=0,angle:u}=this._applyTransform;if(this._srcRect!=null){const{left:p=0,top:S=0,right:w=0,bottom:m=0}=this._srcRect;t=p,e=S,n=w,s=m}const g=a+t,f=o+e;this.transformByState({left:g,top:f,width:a+l-n-g,height:o+d-s-f,angle:u})}_applyCache(t){if(!t||this._cacheCanvas==null)return;const e=this._cacheCanvas.getContext();e.save(),t.save(),t.setTransform(1,0,0,1,0,0),e.setTransform(1,0,0,1,0,0),t.drawImage(this._cacheCanvas.getCanvasEle(),0,0),t.restore(),e.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;const t=this.getScene();if(t==null)return;this._cacheCanvas=new y.Canvas;const e=t.getEngine();this._cacheCanvas.setSize(e.width,e.height),e.onTransformChange$.subscribeEvent(()=>{var n;(n=this._cacheCanvas)==null||n.setSize(e.width,e.height),this.makeDirty(!0)})}}var yt=Object.getOwnPropertyDescriptor,bt=(i,r,t,e)=>{for(var n=e>1?void 0:e?yt(r,t):r,s=i.length-1,a;s>=0;s--)(a=i[s])&&(n=a(n)||n);return n},le=(i,r)=>(t,e)=>r(t,e,i);let be=class extends h.Disposable{constructor(r,t,e,n,s,a){super();te(this,"_sceneListenerOnImageMap",new WeakSet);this._commandService=r,this._drawingManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._messageService=s,this._localeService=a,this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id!==he.id)return;const t=r.params;if(t==null)return;const{cropType:e}=t,n=this._drawingManagerService.getFocusDrawings();if(n.length!==1)return;const s=n[0],{unitId:a,subUnitId:o,drawingId:l}=s,d=this._renderManagerService.getRenderById(a),u=d==null?void 0:d.scene;if(u==null)return!0;this._searchCropObject(u)!=null&&this._commandService.syncExecuteCommand(ne.id,{isAuto:!0});const f=D.getDrawingShapeKeyByDrawingSearch({unitId:a,subUnitId:o,drawingId:l}),p=u.getObject(f);if(!(p instanceof y.Image)){this._messageService.show({type:P.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}p!=null&&(this._updateCropperObject(e,p),this._commandService.executeCommand(Se.id,{unitId:a,subUnitId:o,drawingId:l}))}))}_calculateSrcRectByRatio(r,t,e,n,s,a){const o=e/n,l=s/a;let d=e,u=n;o>l?d=n*l:u=e/l;const g=(e-d)/2,f=(n-u)/2;return{left:y.precisionTo(g,1),top:y.precisionTo(f,1),right:y.precisionTo(e-(g+d),1),bottom:y.precisionTo(n-(f+u),1)}}_updateCropperObject(r,t){const{left:e,top:n,width:s,height:a}=t.calculateTransformWithSrcRect();let o;switch(r){case G.R1_1:o=this._calculateSrcRectByRatio(e,n,s,a,1,1);break;case G.R16_9:o=this._calculateSrcRectByRatio(e,n,s,a,16,9);break;case G.R9_16:o=this._calculateSrcRectByRatio(e,n,s,a,9,16);break;case G.R5_4:o=this._calculateSrcRectByRatio(e,n,s,a,5,4);break;case G.R4_5:o=this._calculateSrcRectByRatio(e,n,s,a,4,5);break;case G.R4_3:o=this._calculateSrcRectByRatio(e,n,s,a,4,3);break;case G.R3_4:o=this._calculateSrcRectByRatio(e,n,s,a,3,4);break;case G.R3_2:o=this._calculateSrcRectByRatio(e,n,s,a,3,2);break;case G.R2_3:o=this._calculateSrcRectByRatio(e,n,s,a,2,3);break;case G.FREE:}if(o==null)return;t.setSrcRect(o);const{left:l=0,top:d=0,bottom:u=0,right:g=0}=o;t.transformByStateCloseCropper({left:e+l,top:n+d,width:s-g-l,height:a-u-d})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id!==Se.id)return;const t=r.params;if(t==null)return;const{unitId:e,subUnitId:n,drawingId:s}=t,a=this._renderManagerService.getRenderById(e),o=a==null?void 0:a.scene;if(o==null)return!0;if(this._sceneListenerOnImageMap.has(o)||(this._addListenerOnImage(o),this._sceneListenerOnImageMap.add(o)),this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:n,drawingId:s})==null)return;const d=D.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:s}),u=o.getObject(d);if(u==null)return;if(!(u instanceof y.Image)){this._messageService.show({type:P.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}const g=o.getTransformer();g==null||g.clearControls();const f=new fe(`${d}-crop`,{srcRect:u.srcRect,prstGeom:u.prstGeom,applyTransform:u.calculateTransformWithSrcRect()});o.addObject(f,u.getLayerIndex()+1).attachTransformerTo(f),g==null||g.createControlForCopper(f),this._addHoverForImageCopper(f),u.openRenderByCropper(),g==null||g.refreshControls(),f.makeDirty(!0),this._commandService.syncExecuteCommand(D.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:s}])}))}_searchCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof fe)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==ne.id)return;const e=this._univerInstanceService.getFocusedUnit();if(e==null)return;const n=e.getUnitId(),s=this._renderManagerService.getRenderById(n),a=s==null?void 0:s.scene;if(a==null)return!0;const o=this._searchCropObject(a);if(o==null)return;const l=this._getApplyObjectByCropObject(o);if(l==null)return;const d=a.getTransformerByCreate();d.detachFrom(o),d.clearCopperControl();const u=this._getSrcRectByTransformState(l,o),g=this._drawingManagerService.getDrawingOKey(l.oKey);if(g!=null){const{left:f,top:p,height:S,width:w}=o;this._drawingManagerService.featurePluginUpdateNotification([{...g,transform:{...g.transform,left:f,top:p,height:S,width:w},srcRect:u.srcRectAngle}])}l.setSrcRect({...u.srcRectAngle}),l.closeRenderByCropper(),l.makeDirty(!0),o==null||o.dispose()}));const r=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET).pipe(Ee.switchMap(t=>t?t.activeSheet$:Ee.of(null)));this.disposeWithMe(r.subscribe(()=>{this._commandService.syncExecuteCommand(ne.id)}))}_getApplyObjectByCropObject(r){const t=r.oKey,e=t.slice(0,t.length-5),n=r.getScene();if(!n)return null;const s=n.getObject(e);return s==null?null:s}_addListenerOnImage(r){const t=r.getTransformerByCreate();let e=null;this.disposeWithMe(t.changeStart$.subscribe(n=>{const{objects:s}=n,a=s.values().next().value;if(a==null||!(a instanceof fe))return;const{left:o,top:l,height:d,width:u,angle:g}=a;e={left:o,top:l,height:d,width:u,angle:g},t.clearCopperControl()})),this.disposeWithMe(t.changeEnd$.subscribe(n=>{const{objects:s}=n,a=s.values().next().value;if(a==null||!(a instanceof fe))return;const{left:o,top:l,height:d,width:u,angle:g}=a;if(!h.checkIfMove({left:o,top:l,height:d,width:u,angle:g},e))return;const f=this._getApplyObjectByCropObject(a);if(f==null)return;const p=this._getSrcRectByTransformState(f,a);a.refreshSrcRect(p.srcRect,f.getState()),t.createControlForCopper(a)})),this._endCropListener(r)}_addHoverForImageCopper(r){this.disposeWithMe(r.onPointerEnter$.subscribeEvent(()=>{r.cursor=y.CURSOR_TYPE.MOVE})),this.disposeWithMe(r.onPointerLeave$.subscribeEvent(()=>{r.cursor=y.CURSOR_TYPE.DEFAULT}))}_endCropListener(r){const t=r.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(ne.id)}))}_getSrcRectByTransformState(r,t){const{left:e,top:n,height:s,width:a,strokeWidth:o,angle:l}=t,{left:d,top:u,width:g,height:f,angle:p,strokeWidth:S}=r,w=e-d,m=n-u,b={left:w,top:m,right:g-w-a,bottom:f-m-s},C={...b};if(p!==0){const B=e+a/2,M=n+s/2,A=new y.Vector2(B,M),E=g/2+d,O=f/2+u,N=new y.Vector2(E,O),T=new y.Vector2(d,u);T.rotateByPoint(y.degToRad(p),N);const U=T.clone();U.rotateByPoint(y.degToRad(-p),A);const R=e-U.x,x=n-U.y;C.left=R,C.top=x,C.right=g-R-a,C.bottom=f-x-s}return{srcRect:b,srcRectAngle:C}}};be=bt([le(0,h.ICommandService),le(1,D.IDrawingManagerService),le(2,y.IRenderManagerService),le(3,h.IUniverInstanceService),le(4,V.IMessageService),le(5,h.Inject(h.LocaleService))],be);var It=Object.getOwnPropertyDescriptor,Dt=(i,r,t,e)=>{for(var n=e>1?void 0:e?It(r,t):r,s=i.length-1,a;s>=0;s--)(a=i[s])&&(n=a(n)||n);return n},ae=(i,r)=>(t,e)=>r(t,e,i);let Ie=class extends h.Disposable{constructor(i,r,t,e,n,s,a){super(),this._commandService=i,this._renderManagerService=r,this._drawingManagerService=t,this._dialogService=e,this._imageIoService=n,this._currentUniverService=s,this._drawingRenderService=a,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===Me.id){const r=i.params;if(r==null)return;this._resetImageSize(r)}}))}_getSceneAndTransformerByDrawingSearch(i){if(i==null)return;const r=this._renderManagerService.getRenderById(i),t=r==null?void 0:r.scene;if(t==null)return null;const e=t.getTransformerByCreate();return{scene:t,transformer:e}}_resetImageSize(i){const r=[],t=[];i.forEach(e=>{const{unitId:n,subUnitId:s,drawingId:a}=e,o=this._getSceneAndTransformerByDrawingSearch(n);if(o==null)return;const{scene:l}=o,d=D.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:a}),u=l.getObject(d);if(u==null)return!0;const g=this._drawingManagerService.getDrawingByParam(e);if(g==null)return!0;if(g.drawingType!==h.DrawingTypeEnum.DRAWING_IMAGE)return;u.resetSize();const{width:f,height:p}=u.getNativeSize();t.includes(l)===!1&&t.push(l),r.push({...g,transform:{...g.transform,height:p,width:f,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(r),t.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(D.SetDrawingSelectedOperation.id,i)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(i=>{this._insertImages(i)}))}_insertImages(i){i.forEach(async r=>{var l;const{unitId:t,subUnitId:e}=r,n=this._getSceneAndTransformerByDrawingSearch(t),s=(l=Pe(this._currentUniverService,t))==null?void 0:l.subUnitId;if(n==null||s!==e)return;const a=this._drawingManagerService.getDrawingByParam(r);if(a==null)return;const o=await this._drawingRenderService.renderImages(a,n.scene);if(this._drawingManagerService.refreshTransform([a]),!(o==null||o.length===0))for(const d of o)this._addHoverForImage(d),this._addDialogForImage(d)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(i=>{i.forEach(r=>{const{unitId:t,subUnitId:e,drawingId:n}=r,s=this._drawingManagerService.getDrawingByParam(r);if(s==null)return;const{transform:a,drawingType:o,srcRect:l,prstGeom:d,source:u,imageSourceType:g}=s;if(o!==h.DrawingTypeEnum.DRAWING_IMAGE)return;const f=this._getSceneAndTransformerByDrawingSearch(t);if(f==null)return;const{scene:p,transformer:S}=f;if(a==null)return!0;const w=D.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),m=p.getObject(w);if(m==null)return!0;m.setSrcRect(l),m.setPrstGeom(d),u!=null&&u.length>0&&(g===h.ImageSourceType.BASE64||g===h.ImageSourceType.URL)&&m.changeSource(u)})}))}_addHoverForImage(i){this.disposeWithMe(h.toDisposable(i.onPointerEnter$.subscribeEvent(()=>{i.cursor=y.CURSOR_TYPE.GRAB}))),this.disposeWithMe(h.toDisposable(i.onPointerLeave$.subscribeEvent(()=>{i.cursor=y.CURSOR_TYPE.DEFAULT})))}_addDialogForImage(i){this.disposeWithMe(h.toDisposable(i.onDblclick$.subscribeEvent(()=>{const r=`${i.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(r,i.getNative().src,i.getNativeSize().width,i.getNativeSize().height)})))}};Ie=Dt([ae(0,h.ICommandService),ae(1,y.IRenderManagerService),ae(2,D.IDrawingManagerService),ae(3,V.IDialogService),ae(4,D.IImageIoService),ae(5,h.IUniverInstanceService),ae(6,h.Inject(I.DrawingRenderService))],Ie);var Mt=Object.getOwnPropertyDescriptor,Ot=(i,r,t,e)=>{for(var n=e>1?void 0:e?Mt(r,t):r,s=i.length-1,a;s>=0;s--)(a=i[s])&&(n=a(n)||n);return n},Ke=(i,r)=>(t,e)=>r(t,e,i);const Nt="UNIVER_DRAWING_UI_PLUGIN";I.UniverDrawingUIPlugin=(Oe=class extends h.Plugin{constructor(r=$e,t,e){super(),this._config=r,this._injector=t,this._configService=e;const{menu:n,...s}=h.merge({},$e,this._config);n&&this._configService.setConfig("menu",n,{merge:!0}),this._configService.setConfig(vt,s)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(ye),this._injector.get(_e),this._injector.get(be),this._injector.get(Ie)}_initDependencies(){[[I.DrawingRenderService],[ye],[_e],[be],[Ie]].forEach(t=>this._injector.add(t))}},te(Oe,"pluginName",Nt),Oe),I.UniverDrawingUIPlugin=Ot([Ke(1,h.Inject(h.Injector)),Ke(2,h.IConfigService)],I.UniverDrawingUIPlugin),I.AutoImageCropOperation=he,I.COMPONENT_IMAGE_POPUP_MENU=We,I.CloseImageCropOperation=ne,I.DrawingCommonPanel=mt,I.ImageCropperObject=fe,I.ImagePopupMenu=Ve,I.ImageResetSizeOperation=Me,I.OpenImageCropOperation=Se,I.SetDrawingAlignOperation=ve,I.getUpdateParams=ge,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
|
|
11
24
|
|
|
12
25
|
|
|
13
26
|
// @univerjs/sheets-drawing/index
|
|
@@ -15,8 +28,15 @@
|
|
|
15
28
|
|
|
16
29
|
|
|
17
30
|
// @univerjs/sheets-drawing-ui/index
|
|
18
|
-
(function(O,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react/jsx-runtime"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react/jsx-runtime","react","@univerjs/docs-ui","@univerjs/design"],c):(O=typeof globalThis<"u"?globalThis:O||self,c(O.UniverSheetsDrawingUi={},O.UniverCore,O.UniverDocsDrawing,O.UniverDrawing,O.UniverDrawingUi,O.UniverEngineRender,O.UniverSheetsDrawing,O.UniverSheetsUi,O.UniverUi,O.rxjs,O.UniverSheets,O.React,O.React,O.UniverDocsUi,O.UniverDesign))})(this,function(O,c,pe,k,ue,W,p,E,B,N,C,G,x,Le,q){"use strict";var qn=Object.defineProperty;var Jn=(O,c,pe)=>c in O?qn(O,c,{enumerable:!0,configurable:!0,writable:!0,value:pe}):O[c]=pe;var oe=(O,c,pe)=>Jn(O,typeof c!="symbol"?c+"":c,pe);const $t="sheets-drawing-ui.config",Dt={},H={id:"sheet.operation.clear-drawing-transformer",type:c.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(W.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},we={id:"sheet.command.remove-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var _,D,b;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(C.SheetInterceptorService),o=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(y=>{const{unitId:T}=y;s.push(T)});const l=o.getBatchRemoveOp(a),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=l,f=n.onCommandExecute({id:we.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:m,objects:h,type:p.DrawingApplyType.REMOVE}},w={id:p.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:p.DrawingApplyType.INSERT}};return c.sequenceExecute([...(_=f.preRedos)!=null?_:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(D=f.preUndos)!=null?D:[],w,...f.undos,{id:H.id,params:s}],redoMutations:[...(b=f.preRedos)!=null?b:[],S,...f.redos,{id:H.id,params:s}]}),!0):!1}},Mt="COMPONENT_SHEET_DRAWING_PANEL",dt={id:"sidebar.operation.sheet-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(B.ISidebarService),e=i.get(c.LocaleService),n=i.get(c.IUniverInstanceService),o=i.get(c.ICommandService);if(!C.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Mt},onClose:()=>{o.syncExecuteCommand(k.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},lt={id:"sheet.operation.edit-sheet-image",type:c.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(c.ICommandService);return r==null?!1:(t.syncExecuteCommand(k.SetDrawingSelectedOperation.id,[r]),t.executeCommand(dt.id,{value:"open"}),!0)}},Ye={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Ft=()=>{const i=B.useDependency(k.IImageIoService),r=B.useDependency(c.LocaleService),[t,e]=x.useState(0);return x.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[i]),G.jsx("div",{style:{display:t>0?"block":"none"},className:Ye.uploadLoading,children:G.jsxs("div",{className:Ye.uploadLoadingBody,children:[G.jsx("div",{className:Ye.uploadLoadingBodyAnimation}),G.jsx("div",{className:Ye.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var Gt=Object.getOwnPropertyDescriptor,Ht=(i,r,t,e)=>{for(var n=e>1?void 0:e?Gt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ge=(i,r)=>(t,e)=>r(t,e,i);let $e=class extends c.RxDisposable{constructor(r,t,e,n,o,a,s,l){super();oe(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=l,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(c.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(B.BuiltInUIPart.CONTENT,()=>B.connectInjector(Ft,this._injector))}_dispose(r){const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof ue.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(c.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const a=e.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const l=s.oKey,g=this._drawingManagerService.getDrawingOKey(l);if(!g)return;const{unitId:u,subUnitId:d,drawingId:m,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,m,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ue.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,m,h)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(k.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[c.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:lt.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:we.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ue.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ue.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===c.DrawingTypeEnum.DRAWING_DOM}]}};$e=Ht([ge(0,c.Inject(c.Injector)),ge(1,k.IDrawingManagerService),ge(2,c.Inject(E.SheetCanvasPopManagerService)),ge(3,W.IRenderManagerService),ge(4,c.IUniverInstanceService),ge(5,c.IContextService),ge(6,c.Inject(B.IUIPartsService)),ge(7,c.ICommandService)],$e);var Xt=Object.getOwnPropertyDescriptor,Vt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Xt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Fe=(i,r)=>(t,e)=>r(t,e,i);let ut=class extends c.Disposable{constructor(r,t,e,n,o){super();oe(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(N.throttleTime(33)).subscribe(r=>{var e,n;let t=[];r!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),t.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(W.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};ut=Vt([Fe(1,c.Inject(E.HoverManagerService)),Fe(2,c.Inject(C.SheetsSelectionsService)),Fe(3,c.Inject(ue.DrawingRenderService)),Fe(4,c.Inject(E.SheetSkeletonManagerService))],ut);function J(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:l=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const d=E.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:m,top:h,width:f,height:S}=d;const w=t.getCurrentSkeleton(),v=w.rowHeaderWidth+w.columnTotalWidth,_=w.columnHeaderHeight+w.rowTotalHeight;return m+f>v&&(m=v-f),h+S>_&&(h=_-S),{flipY:o,flipX:a,angle:s,skewX:l,skewY:g,left:m,top:h,width:f,height:S}}function X(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:l=0,skewX:g=0,skewY:u=0}=i,d=r.getCellWithCoordByOffset(t,e);if(d==null)return;const m={column:d.actualColumn,columnOffset:W.precisionTo(t-d.startX,1),row:d.actualRow,rowOffset:W.precisionTo(e-d.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:W.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:W.precisionTo(e+o-h.startY,1)};return{flipY:a,flipX:s,angle:l,skewX:g,skewY:u,from:m,to:f}}var xt=Object.getOwnPropertyDescriptor,Kt=(i,r,t,e)=>{for(var n=e>1?void 0:e?xt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ge=(i,r)=>(t,e)=>r(t,e,i);let gt=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=J(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};gt=Kt([Ge(1,p.ISheetDrawingService),Ge(2,k.IDrawingManagerService),Ge(3,c.Inject(E.ISheetSelectionRenderService)),Ge(4,c.Inject(E.SheetSkeletonManagerService))],gt);function zt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s}=e,l=W.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const m=d.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:S}=d;return{unitId:h,subUnitId:f,drawingId:S,transform:{...m,left:m.left-l.left,top:m.top-l.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:g})}),r}function Zt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s,transform:l={width:0,height:0}}=e;if(l==null)return;const g=n.map(d=>{const{transform:m}=d,{unitId:h,subUnitId:f,drawingId:S}=d,w=W.transformObjectOutOfGroup(m||{},l,l.width||0,l.height||0);return{unitId:h,subUnitId:f,drawingId:S,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const ht={id:"sheet.command.group-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getGroupDrawingOp(r),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:d,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:l,objects:Zt(d),type:p.DrawingApplyType.UNGROUP}},{id:H.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:d,type:p.DrawingApplyType.GROUP}},{id:H.id,params:o}]}),!0):!1}},Re={id:"sheet.command.insert-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var _,D,b;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(p.ISheetDrawingService),o=i.get(C.SheetInterceptorService);if(!r)return!1;const a=r.drawings,s=a.map(y=>y.unitId),l=n.getBatchAddOp(a),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=l,f=o.onCommandExecute({id:Re.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:g,subUnitId:u,objects:h,type:p.DrawingApplyType.INSERT}},w={id:p.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:p.DrawingApplyType.REMOVE}};return c.sequenceExecute([...(_=f.preRedos)!=null?_:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(D=f.preUndos)!=null?D:[],w,...f.undos,{id:H.id,params:s}],redoMutations:[...(b=f.preRedos)!=null?b:[],S,...f.redos,{id:H.id,params:s}]}),!0):!1}},mt={id:"sheet.command.set-drawing-arrange",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService);if(!r)return!1;const n=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:l}=r,g={unitId:o,subUnitId:a,drawingIds:s};let u;if(l===c.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):l===c.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):l===c.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):l===c.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:m,undo:h}=u;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:a,objects:d,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:d,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:d,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ee={id:"sheet.command.set-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:s,subUnitId:l,op:u,objects:d,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:g,objects:d,type:p.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:u,objects:d,type:p.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}]}),!0):!1}},pt={id:"sheet.command.ungroup-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getUngroupDrawingOp(r),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:d,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:l,objects:zt(d),type:p.DrawingApplyType.GROUP}},{id:H.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:d,type:p.DrawingApplyType.UNGROUP}},{id:H.id,params:o}]}),!0):!1}};var qt=Object.getOwnPropertyDescriptor,Jt=(i,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ee=(i,r)=>(t,e)=>r(t,e,i);function Qt(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:o}}function ft(i,r,t,e,n){var _;const{rotatedHeight:o,rotatedWidth:a}=Qt(t,e,n),l=i.get(W.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(_=l.with(E.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:_.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),m=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,f=a/o,w=Math.ceil(Math.min(m,h*f))/a,v=!w||Number.isNaN(w)?.001:w;return{width:t*v,height:e*v}}O.SheetDrawingUpdateController=class extends c.Disposable{constructor(t,e,n,o,a,s,l,g,u,d,m,h,f){super();oe(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=o,this._imageIoService=a,this._fileOpenerService=s,this._sheetDrawingService=l,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=m,this._injector=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:k.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>k.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(k.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:k.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(D){const b=D.message;b===k.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(k.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):b===k.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):b===k.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:a}=n,{imageId:s,imageSourceType:l,source:g,base64Cache:u}=e,{width:d,height:m,image:h}=await k.getImageSize(u||""),{width:f,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,l,h);let w=1;if(d>k.DRAWING_IMAGE_WIDTH_LIMIT||m>k.DRAWING_IMAGE_HEIGHT_LIMIT){const D=k.DRAWING_IMAGE_WIDTH_LIMIT/d,b=k.DRAWING_IMAGE_HEIGHT_LIMIT/m;w=Math.max(D,b)}const v=this._getImagePosition(d*w,m*w,f,S);if(v==null)return;const _={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:g,transform:J(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};return this._commandService.executeCommand(Re.id,{unitId:o,drawings:[_]})}async _insertCellImage(t,e){var _,D;let n;try{n=await this._imageIoService.saveImage(t)}catch(b){const y=b.message;y===k.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(k.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===k.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===k.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:a,source:s,base64Cache:l}=n,{width:g,height:u,image:d}=await k.getImageSize(l||"");this._imageIoService.addImageSourceCache(s,a,d);const m=this._workbookSelections.getCurrentLastSelection();if(!m)return!1;const h=c.createDocumentModelWithStyle("",{}),f=ft(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:m.primary.actualRow,col:m.primary.actualColumn},g,u,0);if(!f)return!1;const S={size:{width:f.width,height:f.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},w={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:o,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:Le.docDrawingPositionToTransform(S),docTransform:S,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},v=c.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[w],selection:{collapsed:!0,startOffset:0,endOffset:0}});return v?(h.apply(v),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(_=e==null?void 0:e.row)!=null?_:m.primary.actualRow]:{[(D=e==null?void 0:e.col)!=null?D:m.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:o,image:a}=await k.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,c.ImageSourceType.URL,a);const s=this._workbookSelections.getCurrentLastSelection();if(!s)return!1;const l=c.createDocumentModelWithStyle("",{}),g=ft(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:s.primary.actualRow,col:s.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},d={unitId:l.getUnitId(),subUnitId:l.getUnitId(),drawingId:c.generateRandomId(),drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c.ImageSourceType.URL,source:t,transform:Le.docDrawingPositionToTransform(u),docTransform:u,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},m=c.BuildTextUtils.drawing.add({documentDataModel:l,drawings:[d],selection:{collapsed:!0,startOffset:0,endOffset:0}});return m?(l.apply(m),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:s.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:s.primary.actualColumn]:{p:l.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),o=e.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(t,e,n,o){const a=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(s=a[a.length-1].range);const l=E.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(l==null)return;let{startColumn:g,startRow:u,startX:d,startY:m}=l,h=!1;if(d+t>n&&(d=n-t,d<0&&(d=0,t=n),h=!0),m+e>o&&(m=o-e,m<0&&(m=0,e=o),h=!0),h){const v=this._selectionRenderService.getCellWithCoordByOffset(d,m);if(v==null)return;d=v.startX,m=v.startY,g=v.actualColumn,u=v.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(d+t,m+e);if(S==null)return;const w={column:S.actualColumn,columnOffset:d+t-S.startX,row:S.actualRow,rowOffset:m+e-S.startY};return{from:f,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a}=t;this._commandService.executeCommand(mt.id,{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:o,subUnitId:a,drawingId:s,drawingType:l,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:s});if(u==null||u.unitId!==this._context.unitId)return;const d=X({...u.transform,...g},this._selectionRenderService);if(d==null)return;const m={...n,transform:{...u.transform,...g,...J(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};e.push(m)}),e.length>0&&this._commandService.executeCommand(Ee.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(ht.id,t);const{unitId:e,subUnitId:n,drawingId:o}=t[0].parent;this._commandService.syncExecuteCommand(k.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(pt.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},O.SheetDrawingUpdateController=Jt([ee(1,c.Inject(E.SheetSkeletonManagerService)),ee(2,c.ICommandService),ee(3,E.ISheetSelectionRenderService),ee(4,k.IImageIoService),ee(5,B.ILocalFileService),ee(6,p.ISheetDrawingService),ee(7,k.IDrawingManagerService),ee(8,c.IContextService),ee(9,B.IMessageService),ee(10,c.Inject(c.LocaleService)),ee(11,c.Inject(C.SheetsSelectionsService)),ee(12,c.Inject(c.Injector))],O.SheetDrawingUpdateController);var en=Object.getOwnPropertyDescriptor,tn=(i,r,t,e)=>{for(var n=e>1?void 0:e?en(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ve=(i,r)=>(t,e)=>r(t,e,i);function Tt(i,r,t){var e,n,o,a;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((a=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=t.p.drawings[t.p.drawingsOrder[0]],l=ft(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(l)return s.transform.width=l.width,s.transform.height=l.height,s.docTransform.size.width=l.width,s.docTransform.size.height=l.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let He=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Le.ReplaceSnapshotCommand.id&&i.params.unitId===c.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:C.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Tt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};He=tn([ve(0,c.ICommandService),ve(1,c.Inject(C.SheetInterceptorService)),ve(2,c.Inject(c.Injector)),ve(3,k.IDrawingManagerService),ve(4,c.Inject(pe.DocDrawingController)),ve(5,c.Inject(E.IEditorBridgeService))],He);var nn=Object.getOwnPropertyDescriptor,rn=(i,r,t,e)=>{for(var n=e>1?void 0:e?nn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},bt=(i,r)=>(t,e)=>r(t,e,i);let Xe=class extends c.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new c.ObjectMatrix(e).forValue((n,o,a)=>{Tt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},a)})}}))}};Xe=rn([bt(0,c.Inject(E.IAutoFillService)),bt(1,c.Inject(c.Injector))],Xe);var on=Object.getOwnPropertyDescriptor,an=(i,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Oe=(i,r)=>(t,e)=>r(t,e,i);const sn=[c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,c.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Ve=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=c.createDocumentModelWithStyle("",{}),t=(n=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(E.EditingRenderController),e=c.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,t;if(i.id===Le.InnerPasteCommand.id){const e=i.params,{doc:n}=e,o=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_DOC);if(o==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const a=o.getUnitId();if(sn.includes(a)){if(a!==c.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const s=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1})};((t=o.getBody())==null?void 0:t.dataStream)===`\r
|
|
19
|
-
`?(this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:s,showOk:!0,showCancel:!0,onOk:()=>{s(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:s})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Ve=an([Oe(0,c.ICommandService),Oe(1,c.IUniverInstanceService),Oe(2,B.IDialogService),Oe(3,W.IRenderManagerService),Oe(4,c.Inject(c.LocaleService))],Ve);const Pe={id:"sheet.command.insert-float-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{var a,s;const t=i.get(c.IUniverInstanceService),e=i.get(W.IRenderManagerService),n=(a=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:a.with(O.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const l=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(l)).every(g=>g)}else return(s=n.insertFloatImage())!=null?s:!1}},St={id:"sheet.command.insert-cell-image",type:c.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(c.IUniverInstanceService),t=i.get(W.IRenderManagerService);return(n=(e=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(O.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var cn=Object.getOwnPropertyDescriptor,dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?cn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ae=(i,r)=>(t,e)=>r(t,e,i);const Rt="image/png";function ln(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:Rt})}function un(i){const r=new ClipboardItem({[Rt]:ln(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function gn(){function i(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=i();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Et=[E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let xe=class extends c.Disposable{constructor(r,t,e,n,o){super();oe(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(n===E.COPY_TYPE.CUT){const l={unitId:r,drawings:[a]};this._commandService.executeCommand(we.id,l)}setTimeout(()=>{const l=gn();a.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===k.ImageSourceType.BASE64?un(a.source):this._clipboardInterfaceService.writeText(""),l()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=a}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=E.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=r||{},{range:l,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:g,subUnitId:u,pasteRange:l},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},E.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Pe.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(E.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:l,endY:g}=o,u=this._drawingService.getDrawingData(r,t),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:S}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:v=0,width:_=0,height:D=0}=S,{drawingStartX:b,drawingEndX:y,drawingStartY:T,drawingEndY:I}={drawingStartX:w,drawingEndX:w+_,drawingStartY:v,drawingEndY:v+D};a<=b&&y<=s&&l<=T&&I<=g&&d.push(f)}),d.length)return{copyRange:e,drawings:d,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Et.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=n,l=this._renderManagerService.getRenderById(o),g=l==null?void 0:l.with(E.SheetSkeletonManagerService),u=l==null?void 0:l.with(E.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:m}=d,h=E.discreteRangeToRange(s);return this._generateMutations(m,{unitId:o,subUnitId:a,isCut:t===E.COPY_TYPE.CUT,getTransform:(f,S)=>{var _;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...f,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:v,sheetTransform:(_=X(v,u))!=null?_:S}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:o,isCut:a}=t,s=[],l=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:m}=u;if(!d)return;const h=o(d,m),f={...u,unitId:e,subUnitId:n,drawingId:a?u.drawingId:c.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(a){const{undo:S,redo:w,objects:v}=g.getBatchUpdateOp([f]);s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:w,objects:v}}),l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:p.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:w,objects:v}=g.getBatchAddOp([f]);s.push({id:p.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:v,type:p.DrawingApplyType.INSERT}}),l.push({id:p.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:v,type:p.DrawingApplyType.REMOVE}})}}),{redos:s,undos:l}}_generateRangeDrawingsPasteMutations(r,t){var A;const{unitId:e,subUnitId:n,pasteType:o,pasteRange:a}=r,{copyRange:s,copyType:l}=t;if(Et.includes(o))return{redos:[],undos:[]};const g=(A=this._renderManagerService.getRenderById(e))==null?void 0:A.with(E.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:E.discreteRangeToRange(a)},pasteType:o},l);const{ranges:[d,m],mapFunc:h}=E.virtualizeDiscreteRanges([s,a]),{row:f,col:S}=h(d.startRow,d.startColumn),{row:w,col:v}=h(m.startRow,m.startColumn),_=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),D=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:v,endColumn:v});if(!_||!D||!this._copyInfo)return{redos:[],undos:[]};const b=D.startX-_.startX,y=D.startY-_.startY,T=w-f,I=v-S;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(R,U)=>{var j,P;return{transform:{...R,left:((j=R==null?void 0:R.left)!=null?j:0)+b,top:((P=R==null?void 0:R.top)!=null?P:0)+y},sheetTransform:{...U,to:{...U.to,row:U.to.row+T,column:U.to.column+I},from:{...U.from,row:U.from.row+T,column:U.from.column+I}}}},isCut:l===E.COPY_TYPE.CUT})}};xe=dn([Ae(0,E.ISheetClipboardService),Ae(1,W.IRenderManagerService),Ae(2,k.IDrawingManagerService),Ae(3,B.IClipboardInterfaceService),Ae(4,c.ICommandService)],xe);var hn=Object.getOwnPropertyDescriptor,mn=(i,r,t,e)=>{for(var n=e>1?void 0:e?hn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ue=(i,r)=>(t,e)=>r(t,e,i);let Ke=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new C.WorkbookViewPermission(a).id,new C.WorksheetViewPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,o)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new C.WorkbookEditablePermission(a).id,new C.WorksheetEditPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,o)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),l=s==null?void 0:s.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookViewPermission(o).id,new C.WorksheetViewPermission(o,a).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingVisible(t);const s=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,a),g=Object.values(l);t?this._drawingManagerService.addNotification(g):(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),o=e==null?void 0:e.getSheetId();if(!n||!o)return;const a=this._drawingManagerService.getDrawingData(n,o),s=Object.values(a);this._drawingManagerService.addNotification(s)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),l=s==null?void 0:s.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookEditablePermission(o).id,new C.WorksheetEditPermission(o,a).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingEditable(t);const s=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,a),g=Object.values(l);t?(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(s.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const o=n.getSheetId(),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;const l=this._drawingManagerService.getDrawingData(e,o),g=Object.values(l);this._drawingManagerService.setDrawingEditable(!0),s.getAllObjectsByOrder().forEach(d=>{d.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>d.oKey.includes(m.drawingId))&&s.detachTransformerFrom(d)})}}))}};Ke=mn([Ue(0,k.IDrawingManagerService),Ue(1,W.IRenderManagerService),Ue(2,c.IPermissionService),Ue(3,c.IUniverInstanceService),Ue(4,c.Inject(c.UserManagerService))],Ke);var pn=Object.getOwnPropertyDescriptor,fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?pn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},fe=(i,r)=>(t,e)=>r(t,e,i);function Ot(i,r,t,e,n,o=!1){const{scaleX:a,scaleY:s}=r.getAncestorScale(),l=r.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:d,xSplit:m,ySplit:h}=g,f={left:!0,top:!0};if(!l)return{...i,absolute:f};const{left:S,right:w,top:v,bottom:_}=i;let{top:D,left:b,viewportScrollX:y,viewportScrollY:T}=l;const{boundsOfViewArea:I,scrollDirectionResponse:A}=n||{},{rowHeaderWidth:R,columnHeaderHeight:U}=t,j={top:o?0:U,left:o?0:R};I&&(c.Tools.isDefine(j.top)&&(j.top=I.top),c.Tools.isDefine(j.left)&&(j.left=I.left)),A==="HORIZONTAL"&&(T=0),A==="VERTICAL"&&(y=0);let P=0,M=0;const L=t.rowStartY(d-h)+U,F=t.colStartX(u-m)+R,Q=t.rowStartY(d)+U,ne=t.colStartX(u)+R;if(m===0)f.left=!1,P=(S-y)*a,M=(w-y)*a;else{const z=S-(F-R),Y=w-(F-R);w<ne?(P=z*a,M=Y*a):S<=ne&&w>=ne?(P=z*a,M=Math.max(b,(w-y)*a)):S>ne&&(f.left=!1,P=Math.max((S-y)*a,b),M=Math.max((w-y)*a,b))}let K=0,Z=0;if(h===0)f.top=!1,K=(v-T)*s,Z=(_-T)*s;else{const z=v-(L-U),Y=_-(L-U);_<Q?(K=z*s,Z=Y*s):v<=Q&&_>=Q?(K=z*s,Z=Math.max(D,(_-T)*s)):v>Q&&(f.top=!1,K=Math.max((v-T)*s,D),Z=Math.max((_-T)*s,D))}return P=Math.max(P,j.left),K=Math.max(K,j.top),M=Math.max(M,j.left),Z=Math.max(Z,j.top),{left:P,right:M,top:K,bottom:Z,absolute:f}}const ae=(i,r,t,e,n)=>{const{left:o,top:a,width:s,height:l,angle:g}=i,u={left:o,right:o+s,top:a,bottom:a+l},d=Ot(u,r,t,e,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:s*m,height:l*h,absolute:d.absolute}};O.SheetCanvasFloatDomManagerService=class extends c.Disposable{constructor(t,e,n,o,a,s,l){super();oe(this,"_domLayerInfoMap",new Map);oe(this,"_transformChange$",new N.Subject);oe(this,"transformChange$",this._transformChange$.asObservable());oe(this,"_add$",new N.Subject);oe(this,"add$",this._add$.asObservable());oe(this,"_remove$",new N.Subject);oe(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(t=>t===c.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:e,canvas:a}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var z;const{unitId:n,subUnitId:o,drawingId:a}=e,s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,c.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!l||!s)return;const d=(z=this._renderManagerService.getRenderById(n))==null?void 0:z.with(E.SheetSkeletonManagerService).getSkeletonParam(o);if(!d)return;const{transform:m,drawingType:h,data:f}=l;if(h!==c.DrawingTypeEnum.DRAWING_DOM&&h!==c.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:w,canvas:v}=S;if(m==null)return!0;if(u!==o)return;const{left:_,top:D,width:b,height:y,angle:T,flipX:I,flipY:A,skewX:R,skewY:U}=m,j=k.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),P=w.getObject(j);if(P!=null){P.transformByState({left:_,top:D,width:b,height:y,angle:T,flipX:I,flipY:A,skewX:R,skewY:U});return}const M={left:_,top:D,width:b,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},L=h===c.DrawingTypeEnum.DRAWING_CHART;if(M.rotateEnabled=!1,L){const Y=f?f.backgroundColor:"white";M.fill=Y,f&&f.border&&(M.stroke=f.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const F=new W.Rect(j,M);L&&F.setObjectType(W.ObjectType.CHART),w.addObject(F,W.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&w.attachTransformerTo(F);const Q=new c.DisposableCollection,ne=ae(F,S.renderUnit.scene,d.skeleton,s.worksheet),K=new N.BehaviorSubject(ne),Z={dispose:Q,rect:F,position$:K,unitId:n,subUnitId:o,id:a};this._canvasFloatDomService.addFloatDom({position$:K,id:a,componentKey:l.componentKey,onPointerDown:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{v.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{v.dispatchEvent(new WheelEvent(Y.type,Y))},data:f,unitId:n});const re=F.onTransformChange$.subscribeEvent(()=>{const Y=ae(F,S.renderUnit.scene,d.skeleton,s.worksheet);K.next(Y)});Q.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),re&&Q.add(re),this._domLayerInfoMap.set(a,Z)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:a}=e,s=k.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),l=this._getSceneAndTransformerByDrawingSearch(n);if(l==null)return;const{transformer:g,scene:u}=l,d=u.getObject(s);d!=null&&d.oKey&&g.clearControlByIds([d==null?void 0:d.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(e),a=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),l=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!o||!s||!l||a.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const m=ae(d.rect,o.renderUnit.scene,l.skeleton,s.worksheet,d);d.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(e=>e?e.activeSheet$:N.of(null)),N.map(e=>{if(!e)return null;const n=e.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:e.getSheetId()}:null}),N.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):N.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:o}=e;t(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:o}=n;Array.from(this._domLayerInfoMap.values()).filter(s=>s.unitId===o).map(s=>s.subUnitId).forEach(s=>{t(o,s)})}else if(e.id===C.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=e.params;t(n,o)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:a,endY:s}=t,l=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(l==null)return;const g=l.getCellWithCoordByOffset(n,a);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:a-g.startY},d=l.getCellWithCoordByOffset(o,s);if(d==null)return;const m={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:s-d.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==c.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(t);if(a&&s){const{scene:l}=s,g=k.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=l.getObject(g);u&&u instanceof W.Rect&&u.setProps(o)}}addFloatDomToPosition(t,e){const n=C.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=n,{initPosition:s,componentKey:l,data:g,allowTransform:u=!0}=t,d=e!=null?e:c.generateRandomId(),m=this._getPosition(s,o);if(m==null)return;const h={unitId:o,subUnitId:a,drawingId:d,drawingType:t.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:m,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Re.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:a,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),e){const l=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:t});if(!l)return;const g=this._sheetDrawingService.getBatchRemoveOp([l]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:u,objects:d,type:p.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,o){var I,A,R;const a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a,g=this._getSceneAndTransformerByDrawingSearch(s);if(!g)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(I=this._renderManagerService.getRenderById(s))==null?void 0:I.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver(t,u,d.skeleton);if(this._getPosition(w,s)==null)return;const D=g.scene,{scaleX:b}=D.getAncestorScale(),y=ze(w,n,b),T={unitId:s,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:f};{const{unitId:U,subUnitId:j,drawingId:P}=T,M=C.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:j}),L=T,F=this._univerInstanceService.getUnit(U,c.UniverInstanceType.UNIVER_SHEET);if(!F)return;const Q=F.getActiveSheet().getSheetId();if(!L||!M)return;const ne=(A=this._renderManagerService.getRenderById(U))==null?void 0:A.with(E.SheetSkeletonManagerService);if(!ne)return;const K=ne.getWorksheetSkeleton(j);if(!K)return;const{transform:Z,drawingType:re,data:z}=L;if(re!==c.DrawingTypeEnum.DRAWING_DOM&&re!==c.DrawingTypeEnum.DRAWING_CHART)return;const Y=this._getSceneAndTransformerByDrawingSearch(U);if(Y==null)return;const{scene:ye,canvas:Ce}=Y;if(Z==null||Q!==j)return;const{left:Qe,top:et,width:tt,height:nt,angle:yt,flipX:Ct,flipY:rt,skewX:it,skewY:De}=Z,ot=k.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:j,drawingId:P}),se=ye.getObject(ot);if(se!=null){se.transformByState({left:Qe,top:et,width:tt,height:nt,angle:yt,flipX:Ct,flipY:rt,skewX:it,skewY:De});return}const ie={left:Qe,top:et,width:tt,height:nt,zIndex:this._drawingManagerService.getDrawingOrder(U,j).length-1},Me=re===c.DrawingTypeEnum.DRAWING_CHART;if(Me){const $=z?z.backgroundColor:"white";ie.fill=$,ie.rotateEnabled=!1,z&&z.border&&(ie.stroke=z.border),ie.paintFirst="stroke",ie.strokeWidth=1,ie.borderEnabled=!1,ie.radius=8}const ce=new W.Rect(ot,ie);Me&&ce.setObjectType(W.ObjectType.CHART),ye.addObject(ce,W.DRAWING_OBJECT_LAYER_INDEX),L.allowTransform!==!1&&ye.attachTransformerTo(ce);const de=new c.DisposableCollection,at=ye.getMainViewport(),{rowHeaderWidth:Te,columnHeaderHeight:je}=K.skeleton,st={top:je,left:Te,bottom:at.bottom,right:at.right},le={dispose:de,rect:ce,boundsOfViewArea:st,domAnchor:n,unitId:U,subUnitId:j},V=ae(ce,Y.renderUnit.scene,K.skeleton,M.worksheet,le),be=new N.BehaviorSubject(V);le.position$=be;let We={position$:be,id:P,componentKey:L.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Ce.dispatchEvent(new WheelEvent($.type,$))},data:z,unitId:U};e.eventPassThrough&&(We={...We,onPointerDown:$=>{Ce.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Ce.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Ce.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(We),this.disposeWithMe(v.subscribe($=>{var Wt,Bt,Lt,Yt;const jt=ze({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Wt=n.width)!=null?Wt:$.width,height:(Bt=n.height)!=null?Bt:$.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Kn=k.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:j,drawingId:P}),zn=new W.Rect(Kn,{left:jt.startX,top:jt.startY,width:(Lt=n.width)!=null?Lt:$.width,height:(Yt=n.height)!=null?Yt:$.height,zIndex:this._drawingManagerService.getDrawingOrder(U,j).length-1}),Zn=ae(zn,Y.renderUnit.scene,K.skeleton,M.worksheet,le);be.next(Zn)}));const Be=(R=this._renderManagerService.getRenderById(U))==null?void 0:R.with(E.SheetSkeletonManagerService);Be==null||Be.currentSkeleton$.subscribe($=>{$&&K.sheetId!==$.sheetId&&this._removeDom(S,!0)});const ct=ce.onTransformChange$.subscribeEvent(()=>{const $=ae(ce,Y.renderUnit.scene,K.skeleton,M.worksheet,le);be.next($)});de.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),ct&&de.add(ct),this._domLayerInfoMap.set(P,le)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var y,T,I;const a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(y=this._renderManagerService.getRenderById(s))==null?void 0:y.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:m,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),_=w;if(_.startY=0,this._getPosition(w,s)==null)return;const b={unitId:s,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:_.startX,top:_.startY,width:_.width,height:_.height},data:h,allowTransform:f};{const{unitId:A,subUnitId:R,drawingId:U}=b,j=C.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:R}),P=b,M=this._univerInstanceService.getUnit(A,c.UniverInstanceType.UNIVER_SHEET);if(!M)return;const L=M.getActiveSheet().getSheetId();if(!P||!j)return;const F=(T=this._renderManagerService.getRenderById(A))==null?void 0:T.with(E.SheetSkeletonManagerService);if(!F)return;const Q=F.getWorksheetSkeleton(R);if(!Q)return;const{transform:ne,data:K}=P,Z=this._getSceneAndTransformerByDrawingSearch(A);if(Z==null)return;const{scene:re,canvas:z}=Z;if(ne==null||L!==R)return;const{left:Y,top:ye,width:Ce,height:Qe,angle:et,flipX:tt,flipY:nt,skewX:yt,skewY:Ct}=ne,rt=k.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:R,drawingId:U}),it=re.getObject(rt);if(it!=null){it.transformByState({left:Y,top:ye,width:Ce,height:Qe,angle:et,flipX:tt,flipY:nt,skewX:yt,skewY:Ct});return}const De=ze({startX:_.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),ot={left:De.startX,top:De.startY,width:De.width,height:De.height,zIndex:this._drawingManagerService.getDrawingOrder(A,R).length-1},se=new W.Rect(rt,ot);re.addObject(se,W.DRAWING_OBJECT_LAYER_INDEX),P.allowTransform!==!1&&re.attachTransformerTo(se);const ie=new c.DisposableCollection,Me=re.getMainViewport(),ce={top:0,left:Me.left,bottom:Me.bottom,right:Me.right},de={dispose:ie,rect:se,unitId:A,subUnitId:R,boundsOfViewArea:ce,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},at=ae(se,Z.renderUnit.scene,Q.skeleton,j.worksheet,de),Te=new N.BehaviorSubject(at);de.position$=Te;let je={position$:Te,id:U,componentKey:P.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:V=>{z.dispatchEvent(new WheelEvent(V.type,V))},data:K,unitId:A};e.eventPassThrough&&(je={...je,onPointerDown:V=>{z.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{z.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{z.dispatchEvent(new PointerEvent(V.type,V))}}),this._canvasFloatDomService.addFloatDom(je);const st=se.onTransformChange$.subscribeEvent(()=>{const V=ae(se,Z.renderUnit.scene,Q.skeleton,j.worksheet,de);Te.next(V)});this.disposeWithMe(v.subscribe(V=>{const be=ze({startX:V.startX,startY:0,endX:V.endX,endY:V.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),We=k.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:R,drawingId:U}),Be=new W.Rect(We,{left:be.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(A,R).length-1}),ct=ae(Be,Z.renderUnit.scene,Q.skeleton,j.worksheet,de);Te.next(ct)}));const le=(I=this._renderManagerService.getRenderById(A))==null?void 0:I.with(E.SheetSkeletonManagerService);le==null||le.currentSkeleton$.subscribe(V=>{V&&d.sheetId!==V.sheetId&&this._removeDom(S,!0)}),ie.add(()=>{this._canvasFloatDomService.removeFloatDom(U)}),st&&ie.add(st),this._domLayerInfoMap.set(U,de)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:a}=t;const s=Ne(o,a,n),l=new N.BehaviorSubject(s),g=Ne(t.endRow,t.endColumn,n),u=new N.BehaviorSubject(g),d=()=>{const v=Ne(o,a,n),_=Ne(t.endRow,t.endColumn,n);l.next(v),u.next(_)},m=new c.DisposableCollection;m.add(e.engine.clientRect$.subscribe(()=>d())),m.add(this._commandService.onCommandExecuted(v=>{if(v.id===C.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(D=>D.row===o)>-1){d();return}(C.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===E.SetScrollOperation.id||v.id===E.SetZoomRatioOperation.id)&&d()}));const h=(v,_)=>{o=v,a=_,d()},f=()=>({rotate:0,width:g.right-s.left,height:g.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:g.right,endY:g.bottom}),S=l.pipe(N.map(v=>{const _=Ne(t.endRow,t.endColumn,n);return{rotate:0,width:_.right-v.left,height:_.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:_.right,endY:_.bottom}})),w=f();return{position$:S,position:w,updateRowCol:h,topLeftPos$:l,rightBottomPos$:u,disposable:m}}},O.SheetCanvasFloatDomManagerService=fn([fe(0,c.Inject(W.IRenderManagerService)),fe(1,c.IUniverInstanceService),fe(2,c.Inject(c.ICommandService)),fe(3,k.IDrawingManagerService),fe(4,c.Inject(B.CanvasFloatDomService)),fe(5,p.ISheetDrawingService),fe(6,c.Inject(c.LifecycleService))],O.SheetCanvasFloatDomManagerService);function Ne(i,r,t){const e=t.getCellWithCoordByIndex(i,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function ze(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:e,a=(u=r==null?void 0:r.height)!=null?u:n;let s=0,l=0;if(r){if(r.horizonOffsetAlign==="right"){const d=Ze(r.marginX,e*t);s=i.endX-d-o}else s=i.startX+Ze(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const d=Ze(r.marginY,n*t);l=i.endY-d-a}else l=i.startY+Ze(r.marginY,n)}return{rotate:0,startX:s,startY:l,endX:i.endX,endY:i.endY,width:o,height:a,absolute:{left:i.absolute.left,top:i.absolute.top}}}function Ze(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}const Sn=x.memo(i=>{var S,w;const{layer:r,id:t,position:e}=i,n=B.useDependency(c.IUniverInstanceService),o=x.useRef(null),a=x.useRef(null),s=x.useRef(`transform: rotate(${e==null?void 0:e.rotate}deg) translate(${e==null?void 0:e.startX}px, ${e==null?void 0:e.startY}px)`),l=x.useRef((S=e==null?void 0:e.startY)!=null?S:0),g=x.useRef((w=e==null?void 0:e.startX)!=null?w:0),u=typeof r.componentKey=="string"?B.useDependency(B.ComponentManager).get(r.componentKey):r.componentKey,d=x.useMemo(()=>({data:r.data,...r.props}),[r.data,r.props]),m={width:`${e.width-4}px`,height:`${e.height-4}px`,left:`${e.absolute.left?0:"auto"}`,top:`${e.absolute.top?0:"auto"}`,right:`${e.absolute.left?"auto":0}`,bottom:`${e.absolute.top?"auto":0}`};s.current=`rotate(${e.rotate}deg)`,l.current=e.startY,g.current=e.startX;const h=n.getUnit(r.unitId),f=x.useMemo(()=>u?G.jsx(u,{...d,unitId:r.unitId,unit:h,floatDomId:r.id,context:{root:a}}):null,[u,d]);return e?G.jsx("div",{ref:o,className:"univer-z-10",style:{position:"absolute",top:l.current,left:g.current,width:Math.max(e.endX-e.startX-2,0),height:Math.max(e.endY-e.startY-2,0),transform:s.current,overflow:"hidden",transformOrigin:"center center"},onPointerMove:v=>{r.onPointerMove(v.nativeEvent)},onPointerDown:v=>{r.onPointerDown(v.nativeEvent)},onPointerUp:v=>{r.onPointerUp(v.nativeEvent)},onWheel:v=>{r.onWheel(v.nativeEvent)},children:G.jsx("div",{id:t,ref:a,className:"univer-overflow-hidden",style:{position:"absolute",...m},children:f})}):null}),wn=i=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=i,o=x.useMemo(()=>r.map(a=>{const{width:s,height:l,angle:g,left:u,top:d}=a.transform,m=Ot({left:u!=null?u:0,right:(u!=null?u:0)+(s!=null?s:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(l!=null?l:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:f}=t.getAncestorScale(),S={startX:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:s*h,height:l*f,absolute:m.absolute},w={position$:new N.BehaviorSubject(S),position:S,id:a.drawingId,componentKey:a.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:a.unitId};return[a.drawingId,w]}),[r,t,e,n]);return G.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([a,s])=>G.jsx(Sn,{layer:s,id:a,position:s.position},a))})};var vn=Object.getOwnPropertyDescriptor,_n=(i,r,t,e)=>{for(var n=e>1?void 0:e?vn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Se=(i,r)=>(t,e)=>r(t,e,i);let qe=class extends c.Disposable{constructor(i,r,t,e,n,o,a){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=a,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(l=>{const g=s.data[l];g.drawingType!==c.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const a=o.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!a)return t(i);const s=this._drawingManagerService.getDrawingDataForUnit(e),l=s==null?void 0:s[r.subUnitId];if(!l)return t(i);const{scaleX:g,scaleY:u}=o.scene,d=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=l.order.map(h=>l.data[h]);return m.length?(m.forEach(h=>{if(!h.groupId&&h.transform&&c.Tools.isDefine(h.transform.left)&&c.Tools.isDefine(h.transform.top)&&c.Tools.isDefine(h.transform.width)&&c.Tools.isDefine(h.transform.height)){const f=a.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<d.startColumn&&(d.startColumn=f.column),f.row<d.startRow&&(d.startRow=f.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),t(d)):t(i)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._drawingManagerService.getDrawingDataForUnit(e),a=o==null?void 0:o[n];if(a){const s=a.order.map(g=>{const u=a.data[g];return u.drawingType===c.DrawingTypeEnum.DRAWING_CHART?{...u,componentKey:this._componetManager.get(c.PRINT_CHART_COMPONENT_KEY)}:u.drawingType===c.DrawingTypeEnum.DRAWING_DOM?{...u,componentKey:this._componetManager.get(u.componentKey)}:null}).filter(Boolean),l=B.connectInjector(wn,this._injector);return q.render(G.jsx(l,{floatDomInfos:s,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{q.unmount(r.root)}),t(i)}}}))}};qe=_n([Se(0,c.Inject(E.SheetPrintInterceptorService)),Se(1,c.Inject(ue.DrawingRenderService)),Se(2,k.IDrawingManagerService),Se(3,W.IRenderManagerService),Se(4,c.Inject(O.SheetCanvasFloatDomManagerService)),Se(5,c.Inject(B.ComponentManager)),Se(6,c.Inject(c.Injector))],qe);var In=Object.getOwnPropertyDescriptor,yn=(i,r,t,e)=>{for(var n=e>1?void 0:e?In(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},he=(i,r)=>(t,e)=>r(t,e,i);const Cn=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id,C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id],Dn=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let wt=class extends c.Disposable{constructor(i,r,t,e,n,o,a,s,l){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!Cn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===C.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===C.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===C.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===C.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===C.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===C.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===C.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===C.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===C.SetRowHiddenCommand.id||r===C.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===C.SetSpecificColsVisibleCommand.id||r===C.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}else if(r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id||r===C.DeltaColumnWidthCommand.id||r===C.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t,a=r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=C.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,n),l=[],g=[];if(Object.keys(s).forEach(u=>{const d=s[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,d);l.push(...m),g.push(...h)}),l.length===0&&g.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:d,redo:m,objects:h}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,m=u.redo,h=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:m,objects:h,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:H.id,params:[e]}),a.push({id:H.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:s,unitId:l,subUnitId:g,drawingId:u}=t,{from:d,to:m}=o,{row:h,column:f}=d,{row:S,column:w}=m;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:v,endRow:_,startColumn:D,endColumn:b}=i;let y=null,T=null;if(r===0&&h>=v&&S<=_)if(f>=D&&w<=b)n.push({unitId:l,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(o,s,D,b,a);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===1&&f>=D&&w<=b)if(h>=v&&S<=_)n.push({unitId:l,subUnitId:g,drawingId:u});else{const I=this._shrinkRow(o,s,v,_,a);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,s,v,_,a);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,s,D,b,a);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(y!=null&&T!=null){const I=J(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:I})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=X({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=d;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=m,{row:v,column:_}=S,{row:D,column:b}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:I,endRow:A,startColumn:R,endColumn:U}=T;if(b<R)continue;if(f===p.SheetDrawingAnchorType.Position){let M=null,L=null;if(_>=R&&_<=U){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:U,startRow:S.row,endRow:w.row});if(F==null)return;L={...h,left:F.startX}}if(L!=null&&(M=X(L,this._selectionRenderService),M!=null&&L!=null)){n.push({...d,sheetTransform:M,transform:L});break}this._remainDrawingSize(h,n,d);continue}if(_>=R&&b<=U)continue;let j=null,P=null;if(_>=R&&_<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:U,startRow:S.row,endRow:w.row});if(M==null)return;P={...h,left:(M==null?void 0:M.startX)||0,width:((h==null?void 0:h.width)||0)-M.endX+M.startX}}else if(b>=R&&b<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:b,startRow:S.row,endRow:w.row});if(M==null)return;P={...h,left:M.startX-((h==null?void 0:h.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:R,endColumn:U,startRow:S.row,endRow:w.row});if(M==null)return;if(P={...h,width:((h==null?void 0:h.width)||0)-M.endX+M.startX},j=X(P,this._selectionRenderService),j!=null&&P!=null){o.push({...d,sheetTransform:j,transform:P});break}}if(P!=null&&(j=X(P,this._selectionRenderService)),P!=null&&j!=null){n.push({...d,sheetTransform:j,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:l,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:a}=e,s=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:H.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:a,type:p.DrawingApplyType.UPDATE}},{id:H.id,params:[i]}];return{redos:s,undos:l}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:m,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=d;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=m,{row:v,column:_}=S,{row:D,column:b}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:I,endRow:A,startColumn:R,endColumn:U}=T;if(D<I)continue;if(f===p.SheetDrawingAnchorType.Position){let M=null,L=null;if(v>=I&&v<=A){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:A});if(F==null)return;L={...h,top:F.startY}}if(L!=null&&(M=X(L,this._selectionRenderService),M!=null&&L!=null)){n.push({...d,sheetTransform:M,transform:L});break}this._remainDrawingSize(h,n,d);continue}if(v>=I&&D<=A)continue;let j=null,P=null;if(v>=I&&v<=A){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:A});if(M==null)return;P={...h,top:(M==null?void 0:M.startY)||0,height:((h==null?void 0:h.height)||0)-M.endY+M.startY}}else if(D>=I&&D<=A){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:D});if(M==null)return;P={...h,top:M.startY-((h==null?void 0:h.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:A});if(M==null)return;if(P={...h,height:((h==null?void 0:h.height)||0)-M.endY+M.startY},j=X(P,this._selectionRenderService),j!=null&&P!=null){o.push({...d,sheetTransform:j,transform:P});break}}if(P!=null&&(j=X(P,this._selectionRenderService)),P!=null&&j!=null){n.push({...d,sheetTransform:j,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:l,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:l,transform:g,anchorType:u=p.SheetDrawingAnchorType.Position}=s;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,s);else{const{from:d,to:m}=l,{row:h,column:f}=d,{row:S,column:w}=m;for(let v=0;v<t.length;v++){const _=t[v],{startRow:D,endRow:b,startColumn:y,endColumn:T}=_;if(S<D||w<y)continue;if(u===p.SheetDrawingAnchorType.Position&&(h<=D&&S>=b||f<=y&&w>=T)){this._remainDrawingSize(g,o,s);continue}const I=J({...l},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...s,transform:I});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=C.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var D,b;const{toRange:r,fromRange:t}=i,e=C.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=e,a=(b=(D=this._renderManagerService.getRenderById(n))==null?void 0:D.with(E.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=E.attachRangeWithCoord(a,t);if(!s)return{redos:[],undos:[]};const{startX:l,endX:g,startY:u,endY:d}=s,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(y=>{const T=m[y];if(T.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:I}=T;if(!I)return;const{left:A=0,top:R=0,width:U=0,height:j=0}=I,{drawingStartX:P,drawingEndX:M,drawingStartY:L,drawingEndY:F}={drawingStartX:A,drawingEndX:A+U,drawingStartY:R,drawingEndY:R+j};l<=P&&M<=g&&u<=L&&F<=d&&h.push(T)});const f=[],S=[],w=r.startRow-t.startRow,v=r.startColumn-t.startColumn,_=h.map(y=>{const T=y.sheetTransform,I={to:{...T.to,row:T.to.row+w,column:T.to.column+v},from:{...T.from,row:T.from.row+w,column:T.from.column+v}},A=J(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:y.drawingId,transform:A,sheetTransform:I}});if(_.length){const y=this._sheetDrawingService.getBatchUpdateOp(_),{undo:T,redo:I,objects:A}=y;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:A,type:p.DrawingApplyType.UPDATE}}),S.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:T,objects:A,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startRow,s=o.endRow,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=p.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let _,D;if(r==="insert"){const y=this._expandRow(S,w,a,s,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{row:I}=y,{row:A}=T;if(v===p.SheetDrawingAnchorType.Both&&I>=a&&A<=s)m.push({unitId:e,subUnitId:n,drawingId:h});else{const R=this._shrinkRow(S,w,a,s,v);_=R==null?void 0:R.newSheetTransform,D=R==null?void 0:R.newTransform}}if(!_||!D)return;const b={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};d.push(b)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,S=h.redo,w=h.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:H.id,params:[e]}),g.push({id:H.id,params:[e]}),{redos:l,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startColumn,s=o.endColumn,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],m=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=p.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let _,D;if(r==="insert"){const y=this._expandCol(S,w,a,s,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{column:I}=y,{column:A}=T;if(v===p.SheetDrawingAnchorType.Both&&I>=a&&A<=s)m.push({unitId:e,subUnitId:n,drawingId:h});else{const R=this._shrinkCol(S,w,a,s,v);_=R==null?void 0:R.newSheetTransform,D=R==null?void 0:R.newTransform}}if(!_||!D)return;const b={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};d.push(b)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),f=h.undo,S=h.redo,w=h.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.REMOVE}}),g.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.INSERT}})}return l.push({id:H.id,params:[e]}),g.push({id:H.id,params:[e]}),{redos:l,undos:g}}_expandCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:X({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:a.row,endRow:s.row});if(m==null)return;d={...r,left:(r.left||0)+m.endX-m.startX},u=X(d,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g+o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:X({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:X({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...a,column:l-o},to:{...s,column:g-o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g-o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:X({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,left:(r.left||0)-i.from.columnOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:l-1,startRow:a.row,endRow:s.row});if(m==null)return;d={...r,left:(r.left||0)-m.endX+m.startX-i.from.columnOffset}}u=X(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:a.row,endRow:s.row});if(m==null)return;u={from:{...a},to:{...s,column:t-1,columnOffset:m.endX-m.startX}},d=J(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:X({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:a.column,endColumn:s.column});if(m==null)return;d={...r,top:(r.top||0)+m.endY-m.startY},u=X(d,this._selectionRenderService)}else if(g>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g+o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:X({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:g}=s;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:X({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...a,row:l-o},to:{...s,row:g-o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g-o}},d=J(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:X({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,top:(r.top||0)-i.from.rowOffset};else{const m=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:l-1,startColumn:a.column,endColumn:s.column});if(m==null)return;d={...r,top:(r.top||0)-m.endY+m.startY-i.from.rowOffset}}u=X(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===p.SheetDrawingAnchorType.Both){const m=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:t-1,endRow:t-1});if(m==null)return;u={from:{...a},to:{...s,row:t-1,rowOffset:m.endY-m.startY}},d=J(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===C.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=i.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:t}=this._context;if(i){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(o=>{const a=n[o].data;a!=null&&Object.keys(a).forEach(s=>{e===i&&t.push(a[s])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(o=>{const a=t[o];a!=null&&Object.keys(a).forEach(s=>{const l=a[s].data;l!=null&&Object.keys(l).forEach(g=>{if(o===i&&s===r){const u=l[g];u.transform=J(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(l[g])}else n.push(l[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Dn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:l,anchorType:g=p.SheetDrawingAnchorType.Position}=a;if(g===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:m,column:h}=u,{row:f,column:S}=d;for(let w=0;w<t.length;w++){const v=t[w],{startRow:_,endRow:D,startColumn:b,endColumn:y}=v;if(c.Rectangle.intersects({startRow:_,endRow:D,startColumn:b,endColumn:y},{startRow:m,endRow:f,startColumn:h,endColumn:S})||m>D||h>y){const T=g===p.SheetDrawingAnchorType.Position,I=J(s,this._selectionRenderService,this._skeletonManagerService);n.push({...a,transform:{...I,width:T?l==null?void 0:l.width:I==null?void 0:I.width,height:T?l==null?void 0:l.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(H.id,[i]))}};wt=yn([he(1,W.IRenderManagerService),he(2,c.ICommandService),he(3,E.ISheetSelectionRenderService),he(4,c.Inject(E.SheetSkeletonManagerService)),he(5,c.Inject(C.SheetInterceptorService)),he(6,p.ISheetDrawingService),he(7,k.IDrawingManagerService),he(8,c.IUniverInstanceService)],wt);var te=function(){return te=Object.assign||function(i){for(var r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},te.apply(this,arguments)},Mn=function(i,r){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(i);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(i,e[n])&&(t[e[n]]=i[e[n]]);return t},Pt=x.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,a=Mn(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),l=x.useRef("_".concat(Rn()));return At(t,"".concat(e),{defIds:t.defIds,idSuffix:l.current},te({ref:r,className:s},a),o)});function At(i,r,t,e,n){return x.createElement(i.tag,te(te({key:r},Tn(i,t,n)),e),(bn(i,t).children||[]).map(function(o,a){return At(o,"".concat(r,"-").concat(i.tag,"-").concat(a),t,void 0,n)}))}function Tn(i,r,t){var e=te({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];a==="mask"&&typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function bn(i,r){var t,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?te(te({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?te(te({},n),{attrs:te(te({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function Rn(){return Math.random().toString(36).substring(2,8)}Pt.displayName="UniverIcon";var En={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"}}]},Ut=x.forwardRef(function(i,r){return x.createElement(Pt,Object.assign({},i,{id:"add-image-single",ref:r,icon:En}))});Ut.displayName="AddImageSingle";const vt={id:"sheet.command.delete-drawing",type:c.CommandType.COMMAND,handler:i=>{const r=i.get(c.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:l,drawingId:g,drawingType:u}=a;return{unitId:s,subUnitId:l,drawingId:g,drawingType:u}});return r.executeCommand(we.id,{unitId:n,drawings:o})}},_e={id:"sheet.command.move-drawing",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(p.ISheetDrawingService),n=i.get(E.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,l=a.map(u=>{const{transform:d}=u;if(d==null)return null;const m={...d},{left:h=0,top:f=0}=d;return o===c.Direction.UP?m.top=f-1:o===c.Direction.DOWN?m.top=f+1:o===c.Direction.LEFT?m.left=h-1:o===c.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:X(m,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Ee.id,{unitId:s,drawings:l})?(t.syncExecuteCommand(H.id,[s]),!0):!1}},Nt="addition-and-subtraction-single",_t="sheet.menu.image";function On(i){return{id:_t,type:B.MenuItemType.SUBITEMS,icon:Nt,tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(i,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]})}}function Pn(i){return{id:Pe.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}function An(i){return{id:St.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}const me={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelColumn:"univer-image-common-panel-column"},Un=i=>{var D;const r=B.useDependency(c.ICommandService),t=B.useDependency(c.LocaleService),e=B.useDependency(k.IDrawingManagerService),n=B.useDependency(W.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,l=n.getRenderById(s),g=l==null?void 0:l.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,m]=x.useState(!0),h=(D=a.anchorType)!=null?D:p.SheetDrawingAnchorType.Position,[f,S]=x.useState(h);function w(b,y){const T=[];return b.forEach(I=>{const{oKey:A}=I,R=y.getDrawingOKey(A);if(R==null)return T.push(null),!0;const{unitId:U,subUnitId:j,drawingId:P,drawingType:M,anchorType:L,sheetTransform:F}=R;T.push({unitId:U,subUnitId:j,drawingId:P,anchorType:L,sheetTransform:F,drawingType:M})}),T}x.useEffect(()=>{const b=u.clearControl$.subscribe(T=>{T===!0&&m(!1)}),y=u.changeStart$.subscribe(T=>{var R;const{objects:I}=T,A=w(I,e);if(A.length===0)m(!1);else if(A.length>=1){m(!0);const U=((R=A[0])==null?void 0:R.anchorType)||p.SheetDrawingAnchorType.Position;S(U)}});return()=>{y.unsubscribe(),b.unsubscribe()}},[]);function v(b){S(b);const y=e.getFocusDrawings();if(y.length===0)return;const T=y.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:b}));r.executeCommand(Ee.id,{unitId:y[0].unitId,drawings:T})}const _=b=>b?"block":"none";return G.jsxs("div",{className:q.clsx(me.imageCommonPanelGrid,me.imageCommonPanelBorder),style:{display:_(d)},children:[G.jsx("div",{className:me.imageCommonPanelRow,children:G.jsx("div",{className:q.clsx(me.imageCommonPanelColumn,me.imageCommonPanelTitle),children:G.jsx("div",{children:t.t("drawing-anchor.title")})})}),G.jsx("div",{className:q.clsx(me.imageCommonPanelRow),children:G.jsx("div",{className:q.clsx(me.imageCommonPanelColumn),children:G.jsxs(q.RadioGroup,{value:f,onChange:v,direction:"vertical",children:[G.jsx(q.Radio,{value:p.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),G.jsx(q.Radio,{value:p.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),G.jsx(q.Radio,{value:p.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Nn=()=>{const i=B.useDependency(k.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=x.useState(r);return x.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&G.jsxs("div",{className:me.imageCommonPanel,children:[G.jsx(ue.DrawingCommonPanel,{drawings:t}),G.jsx(Un,{drawings:t})]})},kn={[B.RibbonStartGroup.FORMULAS_INSERT]:{[_t]:{order:3,menuItemFactory:On,[Pe.id]:{order:0,menuItemFactory:Pn},[St.id]:{order:1,menuItemFactory:An}}}};function ke(i){return!i.getContextValue(c.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(c.EDITOR_ACTIVATED)&&!i.getContextValue(c.FOCUSING_PANEL_EDITOR)&&i.getContextValue(c.FOCUSING_COMMON_DRAWINGS)}const jn={id:_e.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.DOWN}},Wn={id:_e.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.UP}},Bn={id:_e.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.LEFT}},Ln={id:_e.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:c.Direction.RIGHT}},Yn={id:vt.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:ke,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var $n=Object.getOwnPropertyDescriptor,Fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?$n(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ie=(i,r)=>(t,e)=>r(t,e,i);let Je=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Nt,Ut)),this.disposeWithMe(i.register(Mt,Nn))}_initMenus(){this._menuManagerService.mergeMenu(kn)}_initCommands(){[Pe,St,Re,we,Ee,dt,H,lt,ht,pt,_e,vt,mt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[jn,Wn,Bn,Ln,Yn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Je=Fn([Ie(0,c.Inject(B.ComponentManager)),Ie(1,B.IMenuManagerService),Ie(2,c.ICommandService),Ie(3,B.IShortcutService),Ie(4,k.IDrawingManagerService),Ie(5,c.Inject(C.SheetsSelectionsService))],Je);var Gn=Object.defineProperty,Hn=Object.getOwnPropertyDescriptor,Xn=(i,r,t)=>r in i?Gn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Vn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Hn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},It=(i,r)=>(t,e)=>r(t,e,i),kt=(i,r,t)=>Xn(i,typeof r!="symbol"?r+"":r,t);const xn="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends c.Plugin{constructor(r=Dt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...a}=c.merge({},Dt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig($t,a)}onStarting(){c.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[Je],[$e],[qe],[Ke],[xe],[He],[Xe],[Ve]]),c.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){c.touchDependencies(this._injector,[[xe],[Ve]])}onRendered(){this._registerRenderModules(),c.touchDependencies(this._injector,[[Ke],[qe],[Je],[He],[Xe]])}onSteady(){this._injector.get($e)}_registerRenderModules(){[[O.SheetDrawingUpdateController],[wt],[gt],[ut]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,r))})}},kt(O.UniverSheetsDrawingUIPlugin,"type",c.UniverInstanceType.UNIVER_SHEET),kt(O.UniverSheetsDrawingUIPlugin,"pluginName",xn),O.UniverSheetsDrawingUIPlugin=Vn([c.DependentOn(k.UniverDrawingPlugin,pe.UniverDocsDrawingPlugin,ue.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),It(1,c.Inject(c.Injector)),It(2,W.IRenderManagerService),It(3,c.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=H,O.DeleteDrawingsCommand=vt,O.EditSheetDrawingOperation=lt,O.GroupSheetDrawingCommand=ht,O.InsertFloatImageCommand=Pe,O.InsertSheetDrawingCommand=Re,O.MoveDrawingsCommand=_e,O.RemoveSheetDrawingCommand=we,O.SHEETS_IMAGE_MENU_ID=_t,O.SetDrawingArrangeCommand=mt,O.SetSheetDrawingCommand=Ee,O.SidebarSheetDrawingOperation=dt,O.UngroupSheetDrawingCommand=pt,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
|
|
31
|
+
(function(O,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/design"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/docs-ui"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/design","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","@univerjs/docs-ui","react/jsx-runtime","react"],c):(O=typeof globalThis<"u"?globalThis:O||self,c(O.UniverSheetsDrawingUi={},O.UniverCore,O.UniverDocsDrawing,O.UniverDrawing,O.UniverDrawingUi,O.UniverEngineRender,O.UniverSheetsDrawing,O.UniverDesign,O.UniverSheetsUi,O.UniverUi,O.rxjs,O.UniverSheets,O.UniverDocsUi,O.React,O.React))})(this,function(O,c,pe,j,ge,W,m,J,E,B,N,C,Be,z,oe){"use strict";var Kn=Object.defineProperty;var xn=(O,c,pe)=>c in O?Kn(O,c,{enumerable:!0,configurable:!0,writable:!0,value:pe}):O[c]=pe;var ie=(O,c,pe)=>xn(O,typeof c!="symbol"?c+"":c,pe);const Yt="sheets-drawing-ui.config",yt={},G={id:"sheet.operation.clear-drawing-transformer",type:c.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(W.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Se={id:"sheet.command.remove-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var _,D,R;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(C.SheetInterceptorService),o=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(y=>{const{unitId:T}=y;a.push(T)});const l=o.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,f=n.onCommandExecute({id:Se.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:m.DrawingApplyType.INSERT}};return c.sequenceExecute([...(_=f.preRedos)!=null?_:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(D=f.preUndos)!=null?D:[],w,...f.undos,{id:G.id,params:a}],redoMutations:[...(R=f.preRedos)!=null?R:[],S,...f.redos,{id:G.id,params:a}]}),!0):!1}},Ct="COMPONENT_SHEET_DRAWING_PANEL",at={id:"sidebar.operation.sheet-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(B.ISidebarService),e=i.get(c.LocaleService),n=i.get(c.IUniverInstanceService),o=i.get(c.ICommandService);if(!C.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Ct},onClose:()=>{o.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},ct={id:"sheet.operation.edit-sheet-image",type:c.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(c.ICommandService);return r==null?!1:(t.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[r]),t.executeCommand(at.id,{value:"open"}),!0)}};var Lt=Object.getOwnPropertyDescriptor,Ft=(i,r,t,e)=>{for(var n=e>1?void 0:e?Lt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},se=(i,r)=>(t,e)=>r(t,e,i);let Ye=class extends c.RxDisposable{constructor(r,t,e,n,o,s,a,l,g,u){super();ie(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=o,this._univerInstanceService=s,this._messageService=a,this._contextService=l,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(c.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._setupLoadingStatus()}_setupLoadingStatus(){const r="image-upload-loading";let t;this.disposeWithMe(this._ioService.change$.subscribe(e=>{e>0&&!t?t=this._messageService.show({id:r,type:J.MessageType.Loading,content:`${this._localeService.t("uploadLoading.loading")}: ${e}`,duration:0}):e===0&&(t==null||t.dispose(),t=void 0)}))}_dispose(r){super.dispose();const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof ge.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const s=e.getSelectedObjectMap();if(s.size>1){n==null||n.dispose();return}const a=s.values().next().value;if(!a)return;const l=a.oKey,g=this._drawingManagerService.getDrawingOKey(l);if(!g)return;const{unitId:u,subUnitId:d,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,p,h)}}))})),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[c.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:ct.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Se.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ge.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===c.DrawingTypeEnum.DRAWING_DOM}]}};Ye=Ft([se(0,c.Inject(c.Injector)),se(1,c.Inject(c.LocaleService)),se(2,j.IDrawingManagerService),se(3,c.Inject(E.SheetCanvasPopManagerService)),se(4,W.IRenderManagerService),se(5,c.IUniverInstanceService),se(6,B.IMessageService),se(7,c.IContextService),se(8,c.IImageIoService),se(9,c.ICommandService)],Ye);var $t=Object.getOwnPropertyDescriptor,Gt=(i,r,t,e)=>{for(var n=e>1?void 0:e?$t(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Le=(i,r)=>(t,e)=>r(t,e,i);let dt=class extends c.Disposable{constructor(r,t,e,n,o){super();ie(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(N.throttleTime(33)).subscribe(r=>{var e,n;let t=[];r!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),t.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(W.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};dt=Gt([Le(1,c.Inject(E.HoverManagerService)),Le(2,c.Inject(C.SheetsSelectionsService)),Le(3,c.Inject(ge.DrawingRenderService)),Le(4,c.Inject(E.SheetSkeletonManagerService))],dt);function Z(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:s=!1,angle:a=0,skewX:l=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const d=E.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:S}=d;const w=t.getCurrentSkeleton(),v=w.rowHeaderWidth+w.columnTotalWidth,_=w.columnHeaderHeight+w.rowTotalHeight;return p+f>v&&(p=v-f),h+S>_&&(h=_-S),{flipY:o,flipX:s,angle:a,skewX:l,skewY:g,left:p,top:h,width:f,height:S}}function H(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:s=!1,flipX:a=!1,angle:l=0,skewX:g=0,skewY:u=0}=i,d=r.getCellWithCoordByOffset(t,e);if(d==null)return;const p={column:d.actualColumn,columnOffset:W.precisionTo(t-d.startX,1),row:d.actualRow,rowOffset:W.precisionTo(e-d.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:W.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:W.precisionTo(e+o-h.startY,1)};return{flipY:s,flipX:a,angle:l,skewX:g,skewY:u,from:p,to:f}}var Ht=Object.getOwnPropertyDescriptor,Vt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ht(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Fe=(i,r)=>(t,e)=>r(t,e,i);let lt=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=Z(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};lt=Vt([Fe(1,m.ISheetDrawingService),Fe(2,j.IDrawingManagerService),Fe(3,c.Inject(E.ISheetSelectionRenderService)),Fe(4,c.Inject(E.SheetSkeletonManagerService))],lt);function Xt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:s,drawingId:a}=e,l=W.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const p=d.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:S}=d;return{unitId:h,subUnitId:f,drawingId:S,transform:{...p,left:p.left-l.left,top:p.top-l.top},groupId:a}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:g})}),r}function Kt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:s,drawingId:a,transform:l={width:0,height:0}}=e;if(l==null)return;const g=n.map(d=>{const{transform:p}=d,{unitId:h,subUnitId:f,drawingId:S}=d,w=W.transformObjectOutOfGroup(p||{},l,l.width||0,l.height||0);return{unitId:h,subUnitId:f,drawingId:S,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const ut={id:"sheet.command.group-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const s=n.getGroupDrawingOp(r),{unitId:a,subUnitId:l,undo:g,redo:u,objects:d}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:l,objects:Kt(d),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},Re={id:"sheet.command.insert-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var _,D,R;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService),o=i.get(C.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(y=>y.unitId),l=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,f=o.onCommandExecute({id:Re.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},w={id:m.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return c.sequenceExecute([...(_=f.preRedos)!=null?_:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(D=f.preUndos)!=null?D:[],w,...f.undos,{id:G.id,params:a}],redoMutations:[...(R=f.preRedos)!=null?R:[],S,...f.redos,{id:G.id,params:a}]}),!0):!1}},gt={id:"sheet.command.set-drawing-arrange",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService);if(!r)return!1;const n=i.get(m.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:l}=r,g={unitId:o,subUnitId:s,drawingIds:a};let u;if(l===c.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):l===c.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):l===c.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):l===c.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:o,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},be={id:"sheet.command.set-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,s=n.getBatchUpdateOp(o),{unitId:a,subUnitId:l,undo:g,redo:u,objects:d}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:l,op:g,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},ht={id:"sheet.command.ungroup-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const s=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:l,undo:g,redo:u,objects:d}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:l,objects:Xt(d),type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var xt=Object.getOwnPropertyDescriptor,zt=(i,r,t,e)=>{for(var n=e>1?void 0:e?xt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Q=(i,r)=>(t,e)=>r(t,e,i);function Zt(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:o}}function pt(i,r,t,e,n){var _;const{rotatedHeight:o,rotatedWidth:s}=Zt(t,e,n),l=i.get(W.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(_=l.with(E.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:_.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),p=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,f=s/o,w=Math.ceil(Math.min(p,h*f))/s,v=!w||Number.isNaN(w)?.001:w;return{width:t*v,height:e*v}}O.SheetDrawingUpdateController=class extends c.Disposable{constructor(t,e,n,o,s,a,l,g,u,d,p,h,f){super();ie(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=o,this._imageIoService=s,this._fileOpenerService=a,this._sheetDrawingService=l,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=p,this._injector=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:j.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>j.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(j.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:j.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(D){const R=D.message;R===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(j.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:s}=n,{imageId:a,imageSourceType:l,source:g,base64Cache:u}=e,{width:d,height:p,image:h}=await j.getImageSize(u||""),{width:f,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,l,h);let w=1;if(d>j.DRAWING_IMAGE_WIDTH_LIMIT||p>j.DRAWING_IMAGE_HEIGHT_LIMIT){const D=j.DRAWING_IMAGE_WIDTH_LIMIT/d,R=j.DRAWING_IMAGE_HEIGHT_LIMIT/p;w=Math.max(D,R)}const v=this._getImagePosition(d*w,p*w,f,S);if(v==null)return;const _={unitId:o,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:g,transform:Z(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};return this._commandService.executeCommand(Re.id,{unitId:o,drawings:[_]})}async _insertCellImage(t,e){var _,D;let n;try{n=await this._imageIoService.saveImage(t)}catch(R){const y=R.message;y===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(j.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:s,source:a,base64Cache:l}=n,{width:g,height:u,image:d}=await j.getImageSize(l||"");this._imageIoService.addImageSourceCache(a,s,d);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;const h=c.createDocumentModelWithStyle("",{}),f=pt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:p.primary.actualRow,col:p.primary.actualColumn},g,u,0);if(!f)return!1;const S={size:{width:f.width,height:f.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},w={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:o,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:Be.docDrawingPositionToTransform(S),docTransform:S,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},v=c.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[w],selection:{collapsed:!0,startOffset:0,endOffset:0}});return v?(h.apply(v),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(_=e==null?void 0:e.row)!=null?_:p.primary.actualRow]:{[(D=e==null?void 0:e.col)!=null?D:p.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:o,image:s}=await j.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,c.ImageSourceType.URL,s);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const l=c.createDocumentModelWithStyle("",{}),g=pt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},d={unitId:l.getUnitId(),subUnitId:l.getUnitId(),drawingId:c.generateRandomId(),drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c.ImageSourceType.URL,source:t,transform:Be.docDrawingPositionToTransform(u),docTransform:u,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=c.BuildTextUtils.drawing.add({documentDataModel:l,drawings:[d],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(l.apply(p),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:a.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:a.primary.actualColumn]:{p:l.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),o=e.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(t,e,n,o){const s=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};s&&s.length>0&&(a=s[s.length-1].range);const l=E.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(l==null)return;let{startColumn:g,startRow:u,startX:d,startY:p}=l,h=!1;if(d+t>n&&(d=n-t,d<0&&(d=0,t=n),h=!0),p+e>o&&(p=o-e,p<0&&(p=0,e=o),h=!0),h){const v=this._selectionRenderService.getCellWithCoordByOffset(d,p);if(v==null)return;d=v.startX,p=v.startY,g=v.actualColumn,u=v.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(d+t,p+e);if(S==null)return;const w={column:S.actualColumn,columnOffset:d+t-S.startX,row:S.actualRow,rowOffset:p+e-S.startY};return{from:f,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:o,arrangeType:s}=t;this._commandService.executeCommand(gt.id,{unitId:e,subUnitId:n,drawingIds:o,arrangeType:s})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:o,subUnitId:s,drawingId:a,drawingType:l,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const d=H({...u.transform,...g},this._selectionRenderService);if(d==null)return;const p={...n,transform:{...u.transform,...g,...Z(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};e.push(p)}),e.length>0&&this._commandService.executeCommand(be.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(ut.id,t);const{unitId:e,subUnitId:n,drawingId:o}=t[0].parent;this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(ht.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},O.SheetDrawingUpdateController=zt([Q(1,c.Inject(E.SheetSkeletonManagerService)),Q(2,c.ICommandService),Q(3,E.ISheetSelectionRenderService),Q(4,j.IImageIoService),Q(5,B.ILocalFileService),Q(6,m.ISheetDrawingService),Q(7,j.IDrawingManagerService),Q(8,c.IContextService),Q(9,B.IMessageService),Q(10,c.Inject(c.LocaleService)),Q(11,c.Inject(C.SheetsSelectionsService)),Q(12,c.Inject(c.Injector))],O.SheetDrawingUpdateController);var qt=Object.getOwnPropertyDescriptor,Jt=(i,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},we=(i,r)=>(t,e)=>r(t,e,i);function Dt(i,r,t){var e,n,o,s;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((s=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:s.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],l=pt(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(l)return a.transform.width=l.width,a.transform.height=l.height,a.docTransform.size.width=l.width,a.docTransform.size.height=l.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let $e=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Be.ReplaceSnapshotCommand.id&&i.params.unitId===c.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:C.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Dt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};$e=Jt([we(0,c.ICommandService),we(1,c.Inject(C.SheetInterceptorService)),we(2,c.Inject(c.Injector)),we(3,j.IDrawingManagerService),we(4,c.Inject(pe.DocDrawingController)),we(5,c.Inject(E.IEditorBridgeService))],$e);var Qt=Object.getOwnPropertyDescriptor,en=(i,r,t,e)=>{for(var n=e>1?void 0:e?Qt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Mt=(i,r)=>(t,e)=>r(t,e,i);let Ge=class extends c.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new c.ObjectMatrix(e).forValue((n,o,s)=>{Dt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},s)})}}))}};Ge=en([Mt(0,c.Inject(E.IAutoFillService)),Mt(1,c.Inject(c.Injector))],Ge);var tn=Object.getOwnPropertyDescriptor,nn=(i,r,t,e)=>{for(var n=e>1?void 0:e?tn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ee=(i,r)=>(t,e)=>r(t,e,i);const rn=[c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,c.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let He=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=c.createDocumentModelWithStyle("",{}),t=(n=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(E.EditingRenderController),e=c.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,t;if(i.id===Be.InnerPasteCommand.id){const e=i.params,{doc:n}=e,o=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_DOC);if(o==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const s=o.getUnitId();if(rn.includes(s)){if(s!==c.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1})};((t=o.getBody())==null?void 0:t.dataStream)===`\r
|
|
32
|
+
`?(this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};He=nn([Ee(0,c.ICommandService),Ee(1,c.IUniverInstanceService),Ee(2,B.IDialogService),Ee(3,W.IRenderManagerService),Ee(4,c.Inject(c.LocaleService))],He);const Oe={id:"sheet.command.insert-float-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{var s,a;const t=i.get(c.IUniverInstanceService),e=i.get(W.IRenderManagerService),n=(s=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:s.with(O.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const l=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(l)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},mt={id:"sheet.command.insert-cell-image",type:c.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(c.IUniverInstanceService),t=i.get(W.IRenderManagerService);return(n=(e=W.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(O.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var on=Object.getOwnPropertyDescriptor,sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ae=(i,r)=>(t,e)=>r(t,e,i);const Tt="image/png";function an(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:Tt})}function cn(i){const r=new ClipboardItem({[Tt]:an(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function dn(){function i(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=i();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Rt=[E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ve=class extends c.Disposable{constructor(r,t,e,n,o){super();ie(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const o=this._focusedDrawings;if(o.length>0){const[s]=o;if(n===E.COPY_TYPE.CUT){const l={unitId:r,drawings:[s]};this._commandService.executeCommand(Se.id,l)}setTimeout(()=>{const l=dn();s.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===j.ImageSourceType.BASE64?cn(s.source):this._clipboardInterfaceService.writeText(""),l()},200);const a={unitId:s.unitId,subUnitId:s.subUnitId,drawings:[s]};this._copyInfo=a}else{const s=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=s}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=E.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:l,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:l},{copyRange:a,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:s},E.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Oe.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(E.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:s,endX:a,startY:l,endY:g}=o,u=this._drawingService.getDrawingData(r,t),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:S}=f;if(f.anchorType!==m.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:v=0,width:_=0,height:D=0}=S,{drawingStartX:R,drawingEndX:y,drawingStartY:T,drawingEndY:I}={drawingStartX:w,drawingEndX:w+_,drawingStartY:v,drawingEndY:v+D};s<=R&&y<=a&&l<=T&&I<=g&&d.push(f)}),d.length)return{copyRange:e,drawings:d,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Rt.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:s,range:a}=n,l=this._renderManagerService.getRenderById(o),g=l==null?void 0:l.with(E.SheetSkeletonManagerService),u=l==null?void 0:l.with(E.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=d,h=E.discreteRangeToRange(a);return this._generateMutations(p,{unitId:o,subUnitId:s,isCut:t===E.COPY_TYPE.CUT,getTransform:(f,S)=>{var _;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...f,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:v,sheetTransform:(_=H(v,u))!=null?_:S}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:o,isCut:s}=t,a=[],l=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:p}=u;if(!d)return;const h=o(d,p),f={...u,unitId:e,subUnitId:n,drawingId:s?u.drawingId:c.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:S,redo:w,objects:v}=g.getBatchUpdateOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:v}}),l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:w,objects:v}=g.getBatchAddOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:v,type:m.DrawingApplyType.INSERT}}),l.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:v,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:l}}_generateRangeDrawingsPasteMutations(r,t){var U;const{unitId:e,subUnitId:n,pasteType:o,pasteRange:s}=r,{copyRange:a,copyType:l}=t;if(Rt.includes(o))return{redos:[],undos:[]};const g=(U=this._renderManagerService.getRenderById(e))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:E.discreteRangeToRange(s)},pasteType:o},l);const{ranges:[d,p],mapFunc:h}=E.virtualizeDiscreteRanges([a,s]),{row:f,col:S}=h(d.startRow,d.startColumn),{row:w,col:v}=h(p.startRow,p.startColumn),_=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),D=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:v,endColumn:v});if(!_||!D||!this._copyInfo)return{redos:[],undos:[]};const R=D.startX-_.startX,y=D.startY-_.startY,T=w-f,I=v-S;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(b,P)=>{var k,A;return{transform:{...b,left:((k=b==null?void 0:b.left)!=null?k:0)+R,top:((A=b==null?void 0:b.top)!=null?A:0)+y},sheetTransform:{...P,to:{...P.to,row:P.to.row+T,column:P.to.column+I},from:{...P.from,row:P.from.row+T,column:P.from.column+I}}}},isCut:l===E.COPY_TYPE.CUT})}};Ve=sn([Ae(0,E.ISheetClipboardService),Ae(1,W.IRenderManagerService),Ae(2,j.IDrawingManagerService),Ae(3,B.IClipboardInterfaceService),Ae(4,c.ICommandService)],Ve);var ln=Object.getOwnPropertyDescriptor,un=(i,r,t,e)=>{for(var n=e>1?void 0:e?ln(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ue=(i,r)=>(t,e)=>r(t,e,i);let Xe=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const s=e.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new C.WorkbookViewPermission(s).id,new C.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,o)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const s=e.getUnitId(),a=o.getSheetId();this._permissionService.composePermission([new C.WorkbookEditablePermission(s).id,new C.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,o)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===W.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),l=a==null?void 0:a.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookViewPermission(o).id,new C.WorksheetViewPermission(o,s).id]).pipe(N.map(d=>d.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:s})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,s),g=Object.values(l);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),o=e==null?void 0:e.getSheetId();if(!n||!o)return;const s=this._drawingManagerService.getDrawingData(n,o),a=Object.values(s);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),l=a==null?void 0:a.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookEditablePermission(o).id,new C.WorksheetEditPermission(o,s).id]).pipe(N.map(d=>d.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:s})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,s),g=Object.values(l);t?(a.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const o=n.getSheetId(),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;const l=this._drawingManagerService.getDrawingData(e,o),g=Object.values(l);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(d=>{d.classType===W.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>d.oKey.includes(p.drawingId))&&a.detachTransformerFrom(d)})}}))}};Xe=un([Ue(0,j.IDrawingManagerService),Ue(1,W.IRenderManagerService),Ue(2,c.IPermissionService),Ue(3,c.IUniverInstanceService),Ue(4,c.Inject(c.UserManagerService))],Xe);var gn=Object.getOwnPropertyDescriptor,hn=(i,r,t,e)=>{for(var n=e>1?void 0:e?gn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},me=(i,r)=>(t,e)=>r(t,e,i);function bt(i,r,t,e,n,o=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),l=r.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:d,xSplit:p,ySplit:h}=g,f={left:!0,top:!0};if(!l)return{...i,absolute:f};const{left:S,right:w,top:v,bottom:_}=i;let{top:D,left:R,viewportScrollX:y,viewportScrollY:T}=l;const{boundsOfViewArea:I,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:b,columnHeaderHeight:P}=t,k={top:o?0:P,left:o?0:b};I&&(c.Tools.isDefine(k.top)&&(k.top=I.top),c.Tools.isDefine(k.left)&&(k.left=I.left)),U==="HORIZONTAL"&&(T=0),U==="VERTICAL"&&(y=0);let A=0,M=0;const Y=t.rowStartY(d-h)+P,$=t.colStartX(u-p)+b,q=t.rowStartY(d)+P,te=t.colStartX(u)+b;if(p===0)f.left=!1,A=(S-y)*s,M=(w-y)*s;else{const K=S-($-b),L=w-($-b);w<te?(A=K*s,M=L*s):S<=te&&w>=te?(A=K*s,M=Math.max(R,(w-y)*s)):S>te&&(f.left=!1,A=Math.max((S-y)*s,R),M=Math.max((w-y)*s,R))}let X=0,x=0;if(h===0)f.top=!1,X=(v-T)*a,x=(_-T)*a;else{const K=v-(Y-P),L=_-(Y-P);_<q?(X=K*a,x=L*a):v<=q&&_>=q?(X=K*a,x=Math.max(D,(_-T)*a)):v>q&&(f.top=!1,X=Math.max((v-T)*a,D),x=Math.max((_-T)*a,D))}return A=Math.max(A,k.left),X=Math.max(X,k.top),M=Math.max(M,k.left),x=Math.max(x,k.top),{left:A,right:M,top:X,bottom:x,absolute:f}}const ae=(i,r,t,e,n)=>{const{left:o,top:s,width:a,height:l,angle:g}=i,u={left:o,right:o+a,top:s,bottom:s+l},d=bt(u,r,t,e,n),{scaleX:p,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:a*p,height:l*h,absolute:d.absolute}};O.SheetCanvasFloatDomManagerService=class extends c.Disposable{constructor(t,e,n,o,s,a,l){super();ie(this,"_domLayerInfoMap",new Map);ie(this,"_transformChange$",new N.Subject);ie(this,"transformChange$",this._transformChange$.asObservable());ie(this,"_add$",new N.Subject);ie(this,"add$",this._add$.asObservable());ie(this,"_remove$",new N.Subject);ie(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(t=>t===c.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var K;const{unitId:n,subUnitId:o,drawingId:s}=e,a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,c.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!l||!a)return;const d=(K=this._renderManagerService.getRenderById(n))==null?void 0:K.with(E.SheetSkeletonManagerService).getSkeletonParam(o);if(!d)return;const{transform:p,drawingType:h,data:f}=l;if(h!==c.DrawingTypeEnum.DRAWING_DOM&&h!==c.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:w,canvas:v}=S;if(p==null)return!0;if(u!==o)return;const{left:_,top:D,width:R,height:y,angle:T,flipX:I,flipY:U,skewX:b,skewY:P}=p,k=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),A=w.getObject(k);if(A!=null){A.transformByState({left:_,top:D,width:R,height:y,angle:T,flipX:I,flipY:U,skewX:b,skewY:P});return}const M={left:_,top:D,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},Y=h===c.DrawingTypeEnum.DRAWING_CHART;if(M.rotateEnabled=!1,Y){const L=f?f.backgroundColor:"white";M.fill=L,f&&f.border&&(M.stroke=f.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const $=new W.Rect(k,M);Y&&$.setObjectType(W.ObjectType.CHART),w.addObject($,W.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&w.attachTransformerTo($);const q=new c.DisposableCollection,te=ae($,S.renderUnit.scene,d.skeleton,a.worksheet),X=new N.BehaviorSubject(te),x={dispose:q,rect:$,position$:X,unitId:n,subUnitId:o,id:s};this._canvasFloatDomService.addFloatDom({position$:X,id:s,componentKey:l.componentKey,onPointerDown:L=>{v.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{v.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{v.dispatchEvent(new PointerEvent(L.type,L))},onWheel:L=>{v.dispatchEvent(new WheelEvent(L.type,L))},data:f,unitId:n});const ne=$.onTransformChange$.subscribeEvent(()=>{const L=ae($,S.renderUnit.scene,d.skeleton,a.worksheet);X.next(L)});q.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),ne&&q.add(ne),this._domLayerInfoMap.set(s,x)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:o,drawingId:s}=e,a=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),l=this._getSceneAndTransformerByDrawingSearch(n);if(l==null)return;const{transformer:g,scene:u}=l,d=u.getObject(a);d!=null&&d.oKey&&(g.clearControlByIds([d==null?void 0:d.oKey]),(p=u.getTransformer())==null||p.clearSelectedObjects())})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(e),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),l=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!o||!a||!l||s.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const p=ae(d.rect,o.renderUnit.scene,l.skeleton,a.worksheet,d);d.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(e=>e?e.activeSheet$:N.of(null)),N.map(e=>{if(!e)return null;const n=e.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:e.getSheetId()}:null}),N.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):N.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:o}=e;t(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:o}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===o).map(a=>a.subUnitId).forEach(a=>{t(o,a)})}else if(e.id===C.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=e.params;t(n,o)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:s,endY:a}=t,l=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(l==null)return;const g=l.getCellWithCoordByOffset(n,s);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:s-g.startY},d=l.getCellWithCoordByOffset(o,a);if(d==null)return;const p={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:a-d.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==c.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(s&&a){const{scene:l}=a,g=j.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=l.getObject(g);u&&u instanceof W.Rect&&u.setProps(o)}}addFloatDomToPosition(t,e){const n=C.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:s}=n,{initPosition:a,componentKey:l,data:g,allowTransform:u=!0}=t,d=e!=null?e:c.generateRandomId(),p=this._getPosition(a,o);if(p==null)return;const h={unitId:o,subUnitId:s,drawingId:d,drawingType:t.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Re.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:s,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:s}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(n.rect),e){const l=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:t});if(!l)return;const g=this._sheetDrawingService.getBatchRemoveOp([l]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:u,objects:d,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,o){var I,U,b;const s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:l}=s,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(I=this._renderManagerService.getRenderById(a))==null?void 0:I.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver(t,u,d.skeleton);if(this._getPosition(w,a)==null)return;const D=g.scene,{scaleX:R}=D.getAncestorScale(),y=Ke(w,n,R),T={unitId:a,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:f};{const{unitId:P,subUnitId:k,drawingId:A}=T,M=C.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:k}),Y=T,$=this._univerInstanceService.getUnit(P,c.UniverInstanceType.UNIVER_SHEET);if(!$)return;const q=$.getActiveSheet().getSheetId();if(!Y||!M)return;const te=(U=this._renderManagerService.getRenderById(P))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!te)return;const X=te.getWorksheetSkeleton(k);if(!X)return;const{transform:x,drawingType:ne,data:K}=Y;if(ne!==c.DrawingTypeEnum.DRAWING_DOM&&ne!==c.DrawingTypeEnum.DRAWING_CHART)return;const L=this._getSceneAndTransformerByDrawingSearch(P);if(L==null)return;const{scene:Ie,canvas:ye}=L;if(x==null||q!==k)return;const{left:qe,top:Je,width:Qe,height:et,angle:_t,flipX:It,flipY:tt,skewX:nt,skewY:Ce}=x,rt=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:k,drawingId:A}),ce=Ie.getObject(rt);if(ce!=null){ce.transformByState({left:qe,top:Je,width:Qe,height:et,angle:_t,flipX:It,flipY:tt,skewX:nt,skewY:Ce});return}const re={left:qe,top:Je,width:Qe,height:et,zIndex:this._drawingManagerService.getDrawingOrder(P,k).length-1},De=ne===c.DrawingTypeEnum.DRAWING_CHART;if(De){const F=K?K.backgroundColor:"white";re.fill=F,re.rotateEnabled=!1,K&&K.border&&(re.stroke=K.border),re.paintFirst="stroke",re.strokeWidth=1,re.borderEnabled=!1,re.radius=8}const de=new W.Rect(rt,re);De&&de.setObjectType(W.ObjectType.CHART),Ie.addObject(de,W.DRAWING_OBJECT_LAYER_INDEX),Y.allowTransform!==!1&&Ie.attachTransformerTo(de);const le=new c.DisposableCollection,it=Ie.getMainViewport(),{rowHeaderWidth:Me,columnHeaderHeight:ke}=X.skeleton,ot={top:ke,left:Me,bottom:it.bottom,right:it.right},ue={dispose:le,rect:de,boundsOfViewArea:ot,domAnchor:n,unitId:P,subUnitId:k},V=ae(de,L.renderUnit.scene,X.skeleton,M.worksheet,ue),Te=new N.BehaviorSubject(V);ue.position$=Te;let je={position$:Te,id:A,componentKey:Y.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:F=>{ye.dispatchEvent(new WheelEvent(F.type,F))},data:K,unitId:P};e.eventPassThrough&&(je={...je,onPointerDown:F=>{ye.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{ye.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{ye.dispatchEvent(new PointerEvent(F.type,F))}}),this._canvasFloatDomService.addFloatDom(je),this.disposeWithMe(v.subscribe(F=>{var kt,jt,Wt,Bt;const Nt=Ke({startX:F.startX,startY:F.startY,endX:F.endX,endY:F.endY,width:(kt=n.width)!=null?kt:F.width,height:(jt=n.height)!=null?jt:F.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Hn=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:k,drawingId:A}),Vn=new W.Rect(Hn,{left:Nt.startX,top:Nt.startY,width:(Wt=n.width)!=null?Wt:F.width,height:(Bt=n.height)!=null?Bt:F.height,zIndex:this._drawingManagerService.getDrawingOrder(P,k).length-1}),Xn=ae(Vn,L.renderUnit.scene,X.skeleton,M.worksheet,ue);Te.next(Xn)}));const We=(b=this._renderManagerService.getRenderById(P))==null?void 0:b.with(E.SheetSkeletonManagerService);We==null||We.currentSkeleton$.subscribe(F=>{F&&X.sheetId!==F.sheetId&&this._removeDom(S,!0)});const st=de.onTransformChange$.subscribeEvent(()=>{const F=ae(de,L.renderUnit.scene,X.skeleton,M.worksheet,ue);Te.next(F)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(A)}),st&&le.add(st),this._domLayerInfoMap.set(A,ue)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var y,T,I;const s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:l}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),_=w;if(_.startY=0,this._getPosition(w,a)==null)return;const R={unitId:a,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:_.startX,top:_.startY,width:_.width,height:_.height},data:h,allowTransform:f};{const{unitId:U,subUnitId:b,drawingId:P}=R,k=C.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:b}),A=R,M=this._univerInstanceService.getUnit(U,c.UniverInstanceType.UNIVER_SHEET);if(!M)return;const Y=M.getActiveSheet().getSheetId();if(!A||!k)return;const $=(T=this._renderManagerService.getRenderById(U))==null?void 0:T.with(E.SheetSkeletonManagerService);if(!$)return;const q=$.getWorksheetSkeleton(b);if(!q)return;const{transform:te,data:X}=A,x=this._getSceneAndTransformerByDrawingSearch(U);if(x==null)return;const{scene:ne,canvas:K}=x;if(te==null||Y!==b)return;const{left:L,top:Ie,width:ye,height:qe,angle:Je,flipX:Qe,flipY:et,skewX:_t,skewY:It}=te,tt=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),nt=ne.getObject(tt);if(nt!=null){nt.transformByState({left:L,top:Ie,width:ye,height:qe,angle:Je,flipX:Qe,flipY:et,skewX:_t,skewY:It});return}const Ce=Ke({startX:_.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),rt={left:Ce.startX,top:Ce.startY,width:Ce.width,height:Ce.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1},ce=new W.Rect(tt,rt);ne.addObject(ce,W.DRAWING_OBJECT_LAYER_INDEX),A.allowTransform!==!1&&ne.attachTransformerTo(ce);const re=new c.DisposableCollection,De=ne.getMainViewport(),de={top:0,left:De.left,bottom:De.bottom,right:De.right},le={dispose:re,rect:ce,unitId:U,subUnitId:b,boundsOfViewArea:de,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},it=ae(ce,x.renderUnit.scene,q.skeleton,k.worksheet,le),Me=new N.BehaviorSubject(it);le.position$=Me;let ke={position$:Me,id:P,componentKey:A.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:V=>{K.dispatchEvent(new WheelEvent(V.type,V))},data:X,unitId:U};e.eventPassThrough&&(ke={...ke,onPointerDown:V=>{K.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{K.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{K.dispatchEvent(new PointerEvent(V.type,V))}}),this._canvasFloatDomService.addFloatDom(ke);const ot=ce.onTransformChange$.subscribeEvent(()=>{const V=ae(ce,x.renderUnit.scene,q.skeleton,k.worksheet,le);Me.next(V)});this.disposeWithMe(v.subscribe(V=>{const Te=Ke({startX:V.startX,startY:0,endX:V.endX,endY:V.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),je=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),We=new W.Rect(je,{left:Te.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1}),st=ae(We,x.renderUnit.scene,q.skeleton,k.worksheet,le);Me.next(st)}));const ue=(I=this._renderManagerService.getRenderById(U))==null?void 0:I.with(E.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(V=>{V&&d.sheetId!==V.sheetId&&this._removeDom(S,!0)}),re.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),ot&&re.add(ot),this._domLayerInfoMap.set(P,le)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:s}=t;const a=Pe(o,s,n),l=new N.BehaviorSubject(a),g=Pe(t.endRow,t.endColumn,n),u=new N.BehaviorSubject(g),d=()=>{const v=Pe(o,s,n),_=Pe(t.endRow,t.endColumn,n);l.next(v),u.next(_)},p=new c.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>d())),p.add(this._commandService.onCommandExecuted(v=>{if(v.id===C.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(D=>D.row===o)>-1){d();return}(C.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===E.SetScrollOperation.id||v.id===E.SetZoomRatioOperation.id)&&d()}));const h=(v,_)=>{o=v,s=_,d()},f=()=>({rotate:0,width:g.right-a.left,height:g.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:g.right,endY:g.bottom}),S=l.pipe(N.map(v=>{const _=Pe(t.endRow,t.endColumn,n);return{rotate:0,width:_.right-v.left,height:_.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:_.right,endY:_.bottom}})),w=f();return{position$:S,position:w,updateRowCol:h,topLeftPos$:l,rightBottomPos$:u,disposable:p}}},O.SheetCanvasFloatDomManagerService=hn([me(0,c.Inject(W.IRenderManagerService)),me(1,c.IUniverInstanceService),me(2,c.Inject(c.ICommandService)),me(3,j.IDrawingManagerService),me(4,c.Inject(B.CanvasFloatDomService)),me(5,m.ISheetDrawingService),me(6,c.Inject(c.LifecycleService))],O.SheetCanvasFloatDomManagerService);function Pe(i,r,t){const e=t.getCellWithCoordByIndex(i,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ke(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:e,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,l=0;if(r){if(r.horizonOffsetAlign==="right"){const d=xe(r.marginX,e*t);a=i.endX-d-o}else a=i.startX+xe(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const d=xe(r.marginY,n*t);l=i.endY-d-s}else l=i.startY+xe(r.marginY,n)}return{rotate:0,startX:a,startY:l,endX:i.endX,endY:i.endY,width:o,height:s,absolute:{left:i.absolute.left,top:i.absolute.top}}}function xe(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}const pn=i=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=i,o=oe.useMemo(()=>r.map(s=>{const{width:a,height:l,angle:g,left:u,top:d}=s.transform,p=bt({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(l!=null?l:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:f}=t.getAncestorScale(),S={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:l*f,absolute:p.absolute},w={position$:new N.BehaviorSubject(S),position:S,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId,data:s.data};return[s.drawingId,w]}),[r,t,e,n]);return z.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([s,a])=>z.jsx(B.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var mn=Object.getOwnPropertyDescriptor,fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?mn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},fe=(i,r)=>(t,e)=>r(t,e,i);let ze=class extends c.Disposable{constructor(i,r,t,e,n,o,s){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[o];return a&&a.order.forEach(l=>{const g=a.data[l];g.drawingType!==c.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const s=o.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)return t(i);const a=this._drawingManagerService.getDrawingDataForUnit(e),l=a==null?void 0:a[r.subUnitId];if(!l)return t(i);const{scaleX:g,scaleY:u}=o.scene,d=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=l.order.map(h=>l.data[h]);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&c.Tools.isDefine(h.transform.left)&&c.Tools.isDefine(h.transform.top)&&c.Tools.isDefine(h.transform.width)&&c.Tools.isDefine(h.transform.height)){const f=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<d.startColumn&&(d.startColumn=f.column),f.row<d.startRow&&(d.startRow=f.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),t(d)):t(i)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._drawingManagerService.getDrawingDataForUnit(e),s=o==null?void 0:o[n];if(s){const a=s.order.map(g=>{const u=s.data[g];if(u.drawingType===c.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(c.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===c.DrawingTypeEnum.DRAWING_DOM){const d=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(d||u.componentKey)}}return null}).filter(Boolean),l=B.connectInjector(pn,this._injector);return J.render(z.jsx(l,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{J.unmount(r.root)}),t(i)}}}))}};ze=fn([fe(0,c.Inject(E.SheetPrintInterceptorService)),fe(1,c.Inject(ge.DrawingRenderService)),fe(2,j.IDrawingManagerService),fe(3,W.IRenderManagerService),fe(4,c.Inject(O.SheetCanvasFloatDomManagerService)),fe(5,c.Inject(B.ComponentManager)),fe(6,c.Inject(c.Injector))],ze);var Sn=Object.getOwnPropertyDescriptor,wn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Sn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},he=(i,r)=>(t,e)=>r(t,e,i);const vn=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id,C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id],_n=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let ft=class extends c.Disposable{constructor(i,r,t,e,n,o,s,a,l){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!vn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===C.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([C.MoveColsCommand.id,C.MoveRowsCommand.id,C.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===C.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===C.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===C.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===C.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===C.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===C.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===C.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===C.SetRowHiddenCommand.id||r===C.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===C.SetSpecificColsVisibleCommand.id||r===C.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}else if(r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id||r===C.DeltaColumnWidthCommand.id||r===C.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t,s=r===C.DeltaRowHeightCommand.id||r===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=C.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(e,n),l=[],g=[];if(Object.keys(a).forEach(u=>{const d=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,d);l.push(...p),g.push(...h)}),l.length===0&&g.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:d,redo:p,objects:h}=u;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,p=u.redo,h=u.objects;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:m.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),s.push({id:G.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:s=m.SheetDrawingAnchorType.Position,transform:a,unitId:l,subUnitId:g,drawingId:u}=t,{from:d,to:p}=o,{row:h,column:f}=d,{row:S,column:w}=p;if(o==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:v,endRow:_,startColumn:D,endColumn:R}=i;let y=null,T=null;if(r===0&&h>=v&&S<=_)if(f>=D&&w<=R)n.push({unitId:l,subUnitId:g,drawingId:u});else{const I=this._shrinkCol(o,a,D,R,s);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===1&&f>=D&&w<=R)if(h>=v&&S<=_)n.push({unitId:l,subUnitId:g,drawingId:u});else{const I=this._shrinkRow(o,a,v,_,s);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,a,v,_,s);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,a,D,R,s);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(y!=null&&T!=null){const I=Z(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:I})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=H({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=d;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=p,{row:v,column:_}=S,{row:D,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:I,endRow:U,startColumn:b,endColumn:P}=T;if(R<b)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(_>=b&&_<=P){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:P,startRow:S.row,endRow:w.row});if($==null)return;Y={...h,left:$.startX}}if(Y!=null&&(M=H(Y,this._selectionRenderService),M!=null&&Y!=null)){n.push({...d,sheetTransform:M,transform:Y});break}this._remainDrawingSize(h,n,d);continue}if(_>=b&&R<=P)continue;let k=null,A=null;if(_>=b&&_<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:P,startRow:S.row,endRow:w.row});if(M==null)return;A={...h,left:(M==null?void 0:M.startX)||0,width:((h==null?void 0:h.width)||0)-M.endX+M.startX}}else if(R>=b&&R<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:R,startRow:S.row,endRow:w.row});if(M==null)return;A={...h,left:M.startX-((h==null?void 0:h.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:P,startRow:S.row,endRow:w.row});if(M==null)return;if(A={...h,width:((h==null?void 0:h.width)||0)-M.endX+M.startX},k=H(A,this._selectionRenderService),k!=null&&A!=null){o.push({...d,sheetTransform:k,transform:A});break}}if(A!=null&&(k=H(A,this._selectionRenderService)),A!=null&&k!=null){n.push({...d,sheetTransform:k,transform:A});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:l,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:s}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:s,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],l=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:s,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:a,undos:l}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=d;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=p,{row:v,column:_}=S,{row:D,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:I,endRow:U,startColumn:b,endColumn:P}=T;if(D<I)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(v>=I&&v<=U){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:U});if($==null)return;Y={...h,top:$.startY}}if(Y!=null&&(M=H(Y,this._selectionRenderService),M!=null&&Y!=null)){n.push({...d,sheetTransform:M,transform:Y});break}this._remainDrawingSize(h,n,d);continue}if(v>=I&&D<=U)continue;let k=null,A=null;if(v>=I&&v<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:U});if(M==null)return;A={...h,top:(M==null?void 0:M.startY)||0,height:((h==null?void 0:h.height)||0)-M.endY+M.startY}}else if(D>=I&&D<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:D});if(M==null)return;A={...h,top:M.startY-((h==null?void 0:h.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:U});if(M==null)return;if(A={...h,height:((h==null?void 0:h.height)||0)-M.endY+M.startY},k=H(A,this._selectionRenderService),k!=null&&A!=null){o.push({...d,sheetTransform:k,transform:A});break}}if(A!=null&&(k=H(A,this._selectionRenderService)),A!=null&&k!=null){n.push({...d,sheetTransform:k,transform:A});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:l,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:l,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,a);else{const{from:d,to:p}=l,{row:h,column:f}=d,{row:S,column:w}=p;for(let v=0;v<t.length;v++){const _=t[v],{startRow:D,endRow:R,startColumn:y,endColumn:T}=_;if(S<D||w<y)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=D&&S>=R||f<=y&&w>=T)){this._remainDrawingSize(g,o,a);continue}const I=Z({...l},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...a,transform:I});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=C.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var D,R;const{toRange:r,fromRange:t}=i,e=C.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=e,s=(R=(D=this._renderManagerService.getRenderById(n))==null?void 0:D.with(E.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=E.attachRangeWithCoord(s,t);if(!a)return{redos:[],undos:[]};const{startX:l,endX:g,startY:u,endY:d}=a,p=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(p).forEach(y=>{const T=p[y];if(T.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:I}=T;if(!I)return;const{left:U=0,top:b=0,width:P=0,height:k=0}=I,{drawingStartX:A,drawingEndX:M,drawingStartY:Y,drawingEndY:$}={drawingStartX:U,drawingEndX:U+P,drawingStartY:b,drawingEndY:b+k};l<=A&&M<=g&&u<=Y&&$<=d&&h.push(T)});const f=[],S=[],w=r.startRow-t.startRow,v=r.startColumn-t.startColumn,_=h.map(y=>{const T=y.sheetTransform,I={to:{...T.to,row:T.to.row+w,column:T.to.column+v},from:{...T.from,row:T.from.row+w,column:T.from.column+v}},U=Z(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:y.drawingId,transform:U,sheetTransform:I}});if(_.length){const y=this._sheetDrawingService.getBatchUpdateOp(_),{undo:T,redo:I,objects:U}=y;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:U,type:m.DrawingApplyType.UPDATE}}),S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:T,objects:U,type:m.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,s=o.startRow,a=o.endRow,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let _,D;if(r==="insert"){const y=this._expandRow(S,w,s,a,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{row:I}=y,{row:U}=T;if(v===m.SheetDrawingAnchorType.Both&&I>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkRow(S,w,s,a,v);_=b==null?void 0:b.newSheetTransform,D=b==null?void 0:b.newTransform}}if(!_||!D)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,S=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,s=o.startColumn,a=o.endColumn,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let _,D;if(r==="insert"){const y=this._expandCol(S,w,s,a,v);_=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{column:I}=y,{column:U}=T;if(v===m.SheetDrawingAnchorType.Both&&I>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkCol(S,w,s,a,v);_=b==null?void 0:b.newSheetTransform,D=b==null?void 0:b.newTransform}}if(!_||!D)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:_};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,S=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_expandCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{column:l}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:a.row});if(p==null)return;d={...r,left:(r.left||0)+p.endX-p.startX},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+o}},d=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{column:l}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...s,column:l-o},to:{...a,column:g-o}},d=Z(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-o}},d=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,left:(r.left||0)-i.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:l-1,startRow:s.row,endRow:a.row});if(p==null)return;d={...r,left:(r.left||0)-p.endX+p.startX-i.from.columnOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:a.row});if(p==null)return;u={from:{...s},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},d=Z(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{row:l}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:a.column});if(p==null)return;d={...r,top:(r.top||0)+p.endY-p.startY},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+o}},d=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{row:l}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...s,row:l-o},to:{...a,row:g-o}},d=Z(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-o}},d=Z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,top:(r.top||0)-i.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:l-1,startColumn:s.column,endColumn:a.column});if(p==null)return;d={...r,top:(r.top||0)-p.endY+p.startY-i.from.rowOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...s},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},d=Z(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===C.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=i.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:t}=this._context;if(i){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(o=>{const s=n[o].data;s!=null&&Object.keys(s).forEach(a=>{e===i&&t.push(s[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(o=>{const s=t[o];s!=null&&Object.keys(s).forEach(a=>{const l=s[a].data;l!=null&&Object.keys(l).forEach(g=>{if(o===i&&a===r){const u=l[g];u.transform=Z(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(l[g])}else n.push(l[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{_n.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(o=>{const s=e[o],{sheetTransform:a,transform:l,anchorType:g=m.SheetDrawingAnchorType.Position}=s;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=a,{row:p,column:h}=u,{row:f,column:S}=d;for(let w=0;w<t.length;w++){const v=t[w],{startRow:_,endRow:D,startColumn:R,endColumn:y}=v;if(c.Rectangle.intersects({startRow:_,endRow:D,startColumn:R,endColumn:y},{startRow:p,endRow:f,startColumn:h,endColumn:S})||p>D||h>y){const T=g===m.SheetDrawingAnchorType.Position,I=Z(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...I,width:T?l==null?void 0:l.width:I==null?void 0:I.width,height:T?l==null?void 0:l.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};ft=wn([he(1,W.IRenderManagerService),he(2,c.ICommandService),he(3,E.ISheetSelectionRenderService),he(4,c.Inject(E.SheetSkeletonManagerService)),he(5,c.Inject(C.SheetInterceptorService)),he(6,m.ISheetDrawingService),he(7,j.IDrawingManagerService),he(8,c.IUniverInstanceService)],ft);var ee=function(){return ee=Object.assign||function(i){for(var r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},ee.apply(this,arguments)},In=function(i,r){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(i);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(i,e[n])&&(t[e[n]]=i[e[n]]);return t},Et=oe.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,s=In(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),l=oe.useRef("_".concat(Dn()));return Ot(t,"".concat(e),{defIds:t.defIds,idSuffix:l.current},ee({ref:r,className:a},s),o)});function Ot(i,r,t,e,n){return oe.createElement(i.tag,ee(ee({key:r},yn(i,t,n)),e),(Cn(i,t).children||[]).map(function(o,s){return Ot(o,"".concat(r,"-").concat(i.tag,"-").concat(s),t,void 0,n)}))}function yn(i,r,t){var e=ee({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];s==="mask"&&typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Cn(i,r){var t,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?ee(ee({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?ee(ee({},n),{attrs:ee(ee({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function Dn(){return Math.random().toString(36).substring(2,8)}Et.displayName="UniverIcon";var Mn={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"}}]},At=oe.forwardRef(function(i,r){return oe.createElement(Et,Object.assign({},i,{id:"add-image-single",ref:r,icon:Mn}))});At.displayName="AddImageSingle";const St={id:"sheet.command.delete-drawing",type:c.CommandType.COMMAND,handler:i=>{const r=i.get(c.ICommandService),e=i.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(s=>{const{unitId:a,subUnitId:l,drawingId:g,drawingType:u}=s;return{unitId:a,subUnitId:l,drawingId:g,drawingType:u}});return r.executeCommand(Se.id,{unitId:n,drawings:o})}},ve={id:"sheet.command.move-drawing",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(m.ISheetDrawingService),n=i.get(E.ISheetSelectionRenderService),{direction:o}=r,s=e.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,l=s.map(u=>{const{transform:d}=u;if(d==null)return null;const p={...d},{left:h=0,top:f=0}=d;return o===c.Direction.UP?p.top=f-1:o===c.Direction.DOWN?p.top=f+1:o===c.Direction.LEFT?p.left=h-1:o===c.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:H(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(be.id,{unitId:a,drawings:l})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},Ut="addition-and-subtraction-single",wt="sheet.menu.image";function Tn(i){return{id:wt,type:B.MenuItemType.SUBITEMS,icon:Ut,tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(i,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]})}}function Rn(i){return{id:Oe.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}function bn(i){return{id:mt.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}const En=i=>{var D;const r=B.useDependency(c.ICommandService),t=B.useDependency(c.LocaleService),e=B.useDependency(j.IDrawingManagerService),n=B.useDependency(W.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,l=n.getRenderById(a),g=l==null?void 0:l.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,p]=oe.useState(!0),h=(D=s.anchorType)!=null?D:m.SheetDrawingAnchorType.Position,[f,S]=oe.useState(h);function w(R,y){const T=[];return R.forEach(I=>{const{oKey:U}=I,b=y.getDrawingOKey(U);if(b==null)return T.push(null),!0;const{unitId:P,subUnitId:k,drawingId:A,drawingType:M,anchorType:Y,sheetTransform:$}=b;T.push({unitId:P,subUnitId:k,drawingId:A,anchorType:Y,sheetTransform:$,drawingType:M})}),T}oe.useEffect(()=>{const R=u.clearControl$.subscribe(T=>{T===!0&&p(!1)}),y=u.changeStart$.subscribe(T=>{var b;const{objects:I}=T,U=w(I,e);if(U.length===0)p(!1);else if(U.length>=1){p(!0);const P=((b=U[0])==null?void 0:b.anchorType)||m.SheetDrawingAnchorType.Position;S(P)}});return()=>{y.unsubscribe(),R.unsubscribe()}},[]);function v(R){S(R);const y=e.getFocusDrawings();if(y.length===0)return;const T=y.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:R}));r.executeCommand(be.id,{unitId:y[0].unitId,drawings:T})}const _=R=>R?"block":"none";return z.jsxs("div",{className:`
|
|
33
|
+
univer-relative univer-mt-5 univer-w-full univer-border-b-0 univer-border-l-0 univer-border-r-0
|
|
34
|
+
univer-border-t univer-border-solid univer-border-gray-200
|
|
35
|
+
`,style:{display:_(d)},children:[z.jsx("div",{className:`
|
|
36
|
+
univer-relative univer-mt-2.5 univer-flex univer-h-full univer-items-start univer-justify-start
|
|
37
|
+
`,children:z.jsx("div",{className:"univer-w-full univer-text-left univer-text-gray-400",children:z.jsx("div",{children:t.t("drawing-anchor.title")})})}),z.jsx("div",{className:`
|
|
38
|
+
univer-relative univer-mt-2.5 univer-flex univer-h-full univer-items-start univer-justify-start
|
|
39
|
+
`,children:z.jsx("div",{className:"univer-flex univer-items-center univer-gap-1",children:z.jsxs(J.RadioGroup,{value:f,onChange:v,direction:"vertical",children:[z.jsx(J.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),z.jsx(J.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),z.jsx(J.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},On=()=>{const i=B.useDependency(j.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=oe.useState(r);return oe.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&z.jsxs("div",{className:"univer-p-2 univer-text-center univer-text-sm",children:[z.jsx(ge.DrawingCommonPanel,{drawings:t}),z.jsx(En,{drawings:t})]})},An={[B.RibbonStartGroup.FORMULAS_INSERT]:{[wt]:{order:3,menuItemFactory:Tn,[Oe.id]:{order:0,menuItemFactory:Rn},[mt.id]:{order:1,menuItemFactory:bn}}}};function Ne(i){return!i.getContextValue(c.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(c.EDITOR_ACTIVATED)&&!i.getContextValue(c.FOCUSING_PANEL_EDITOR)&&i.getContextValue(c.FOCUSING_COMMON_DRAWINGS)}const Un={id:ve.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:Ne,staticParameters:{direction:c.Direction.DOWN}},Pn={id:ve.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:Ne,staticParameters:{direction:c.Direction.UP}},Nn={id:ve.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:Ne,staticParameters:{direction:c.Direction.LEFT}},kn={id:ve.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:Ne,staticParameters:{direction:c.Direction.RIGHT}},jn={id:St.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:Ne,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var Wn=Object.getOwnPropertyDescriptor,Bn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Wn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},_e=(i,r)=>(t,e)=>r(t,e,i);let Ze=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ut,At)),this.disposeWithMe(i.register(Ct,On))}_initMenus(){this._menuManagerService.mergeMenu(An)}_initCommands(){[Oe,mt,Re,Se,be,at,G,ct,ut,ht,ve,St,gt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[Un,Pn,Nn,kn,jn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Ze=Bn([_e(0,c.Inject(B.ComponentManager)),_e(1,B.IMenuManagerService),_e(2,c.ICommandService),_e(3,B.IShortcutService),_e(4,j.IDrawingManagerService),_e(5,c.Inject(C.SheetsSelectionsService))],Ze);var Yn=Object.defineProperty,Ln=Object.getOwnPropertyDescriptor,Fn=(i,r,t)=>r in i?Yn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,$n=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ln(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},vt=(i,r)=>(t,e)=>r(t,e,i),Pt=(i,r,t)=>Fn(i,typeof r!="symbol"?r+"":r,t);const Gn="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends c.Plugin{constructor(r=yt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...s}=c.merge({},yt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Yt,s)}onStarting(){c.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[Ze],[Ye],[ze],[Xe],[Ve],[$e],[Ge],[He]]),c.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){c.touchDependencies(this._injector,[[Ve],[He]])}onRendered(){this._registerRenderModules(),c.touchDependencies(this._injector,[[Xe],[ze],[Ze],[$e],[Ge]])}onSteady(){this._injector.get(Ye)}_registerRenderModules(){[[O.SheetDrawingUpdateController],[ft],[lt],[dt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,r))})}},Pt(O.UniverSheetsDrawingUIPlugin,"type",c.UniverInstanceType.UNIVER_SHEET),Pt(O.UniverSheetsDrawingUIPlugin,"pluginName",Gn),O.UniverSheetsDrawingUIPlugin=$n([c.DependentOn(j.UniverDrawingPlugin,pe.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),vt(1,c.Inject(c.Injector)),vt(2,W.IRenderManagerService),vt(3,c.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=G,O.DeleteDrawingsCommand=St,O.EditSheetDrawingOperation=ct,O.GroupSheetDrawingCommand=ut,O.InsertFloatImageCommand=Oe,O.InsertSheetDrawingCommand=Re,O.MoveDrawingsCommand=ve,O.RemoveSheetDrawingCommand=Se,O.SHEETS_IMAGE_MENU_ID=wt,O.SetDrawingArrangeCommand=gt,O.SetSheetDrawingCommand=be,O.SidebarSheetDrawingOperation=at,O.UngroupSheetDrawingCommand=ht,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
|
|
20
40
|
|
|
21
41
|
|
|
22
42
|
// @univerjs/sheets-drawing-ui/facade
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/preset-sheets-drawing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -57,18 +57,19 @@
|
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/docs-drawing": "0.
|
|
61
|
-
"@univerjs/drawing": "0.
|
|
62
|
-
"@univerjs/drawing-ui": "0.
|
|
63
|
-
"@univerjs/sheets-drawing": "0.
|
|
64
|
-
"@univerjs/sheets-drawing-ui": "0.
|
|
60
|
+
"@univerjs/docs-drawing": "0.7.0-beta.1",
|
|
61
|
+
"@univerjs/drawing": "0.7.0-beta.1",
|
|
62
|
+
"@univerjs/drawing-ui": "0.7.0-beta.1",
|
|
63
|
+
"@univerjs/sheets-drawing": "0.7.0-beta.1",
|
|
64
|
+
"@univerjs/sheets-drawing-ui": "0.7.0-beta.1",
|
|
65
|
+
"rxjs": ">=7.0.0"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
|
-
"@univerjs/core": "0.
|
|
68
|
+
"@univerjs/core": "0.7.0-beta.1",
|
|
68
69
|
"react": "18.3.1",
|
|
69
70
|
"react-dom": "18.3.1",
|
|
70
|
-
"typescript": "^5.8.
|
|
71
|
-
"@univerjs-infra/shared": "0.
|
|
71
|
+
"typescript": "^5.8.3",
|
|
72
|
+
"@univerjs-infra/shared": "0.7.0-beta.1"
|
|
72
73
|
},
|
|
73
74
|
"scripts": {
|
|
74
75
|
"prebuild:preset": "tsx prepare.ts",
|