@univerjs/preset-sheets-drawing 0.7.0-nightly.202505121607 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.css CHANGED
@@ -1 +1 @@
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-bg-gray-100{background-color:var(--univer-gray-100)}.univer-bg-gray-800{background-color:var(--univer-gray-800)}.univer-bg-gray-900{background-color:var(--univer-gray-900)}.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)}.dark\:univer-bg-gray-800:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-800)}.dark\:univer-bg-gray-900:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-900)}.dark\:univer-text-white:where(.univer-dark,.univer-dark *){color:var(--univer-white)}.dark\:hover\:univer-bg-gray-800:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-800)}.univer-relative{position:relative}.univer-mt-2\.5{margin-top:10px}.univer-mt-5{margin-top:20px}.univer-flex{display:flex}.univer-hidden{display:none}.univer-h-full{height:100%}.univer-w-full{width:100%}.univer-items-center{align-items:center}.univer-gap-1{gap:4px}.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)}
1
+ .univer-relative{position:relative}.univer-mt-2\.5{margin-top:10px}.univer-flex{display:flex}.univer-h-full{height:100%}.univer-w-full{width:100%}.univer-grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.univer-grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.univer-items-center{align-items:center}.univer-justify-center{justify-content:center}.univer-rounded{border-radius:4px}.univer-bg-gray-100{background-color:var(--univer-gray-100)}.univer-bg-gray-800{background-color:var(--univer-gray-800)}.univer-bg-gray-900{background-color:var(--univer-gray-900)}.univer-bg-white{background-color:var(--univer-white)}.univer-fill-primary-600{fill:var(--univer-primary-600)}.univer-p-1{padding:4px}.univer-px-8{padding-left:32px;padding-right:32px}.univer-text-center{text-align:center}.univer-text-gray-900{color:var(--univer-gray-900)}.hover\:univer-bg-gray-100:hover{background-color:var(--univer-gray-100)}.dark\:univer-bg-gray-800:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-800)}.dark\:univer-bg-gray-900:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-900)}.dark\:univer-text-white:where(.univer-dark,.univer-dark *){color:var(--univer-white)}.dark\:hover\:univer-bg-gray-800:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-800)}.\[\&\>div\]\:univer-grid>div{display:grid}.\[\&\>div\]\:univer-gap-2>div{gap:8px}.univer-grid{display:grid}.univer-hidden{display:none}.univer-gap-2{gap:8px}.univer-py-2{padding-top:8px;padding-bottom:8px}.univer-text-sm{font-size:14px;line-height:20px}.univer-text-gray-400{color:var(--univer-gray-400)}.univer-text-gray-600{color:var(--univer-gray-600)}.dark\:univer-text-gray-200:where(.univer-dark,.univer-dark *){color:var(--univer-gray-200)}
package/lib/umd/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
  // @univerjs/drawing-ui/index
6
- (function(I,f){typeof exports=="object"&&typeof module<"u"?f(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"],f):(I=typeof globalThis<"u"?globalThis:I||self,f(I.UniverDrawingUi={},I.UniverCore,I.UniverDrawing,I.UniverEngineRender,I.UniverUi,I.React,I.React,I.UniverDesign,I.rxjs))})(this,function(I,f,M,y,V,c,_,D,Te){"use strict";var Ut=Object.defineProperty;var jt=(I,f,M)=>f in I?Ut(I,f,{enumerable:!0,configurable:!0,writable:!0,value:M}):I[f]=M;var te=(I,f,M)=>jt(I,typeof f!="symbol"?f+"":f,M);var Oe;function Ee(i,r,t,e){const n=e.getDrawingByParam(i);if(n==null)return;const a=M.getDrawingShapeKeyByDrawingSearch(i),s=t.getObject(a);if(s&&!(s instanceof y.Group))return;if(s!=null){s.addObject(r);return}const o=new y.Group(a);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 a;const t=r?i.getUnit(r):i.getFocusedUnit();if(t==null)return;const e=t.getUnitId();let n;return t.type===f.UniverInstanceType.UNIVER_SHEET?n=(a=t.getActiveSheet())==null?void 0:a.getSheetId():(t.type===f.UniverInstanceType.UNIVER_DOC||t.type===f.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,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(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:a,imageSourceType:s,srcRect:o,prstGeom:l,groupId:u,unitId:d,subUnitId:g,drawingId:h,isMultiTransform:p,transforms:S}=r;if(n!==f.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:O,height:A,angle:E,flipX:N,flipY:T,skewX:P,skewY:U}=b,R=w.indexOf(b),x=M.getDrawingShapeKeyByDrawingSearch({unitId:d,subUnitId:g,drawingId:h},p?R:void 0),Y=t.getObject(x);if(Y!=null){Y.transformByState({left:C,top:B,width:O,height:A,angle:E,flipX:N,flipY:T,skewX:P,skewY:U});continue}const K=this._drawingManagerService.getDrawingOrder(d,g),de=K.indexOf(h),se={...b,zIndex:de===-1?K.length-1:de},oe=this._imageIoService.getImageSourceCache(a,s);let ue=!1;if(oe!=null)se.image=oe;else{if(s===M.ImageSourceType.UUID)try{se.url=await this._imageIoService.getImage(a)}catch(Ne){console.error(Ne);continue}else se.url=a;ue=!0}if(t.getObject(x))continue;se.printable=!0;const Q=new y.Image(x,se);ue&&this._imageIoService.addImageSourceCache(a,s,Q.getNative()),this._drawingManagerService.getDrawingVisible()&&(t.addObject(Q,y.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&t.attachTransformerTo(Q),u&&Ee({drawingId:u,unitId:d,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:a,unitId:s,subUnitId:o,drawingId:l,isMultiTransform:u,transforms:d}=r;if(n!==f.DrawingTypeEnum.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||e==null)return;const g=u&&d?d:[e],h=[];for(const p of g){const{left:S,top:w,width:m,height:b,angle:C,flipX:B,flipY:O,skewX:A,skewY:E}=p,N=g.indexOf(p),T=M.getDrawingShapeKeyByDrawingSearch({unitId:s,subUnitId:o,drawingId:l},u?N:void 0),P=t.getObject(T);if(P!=null){P.transformByState({left:S,top:w,width:m,height:b,angle:C,flipX:B,flipY:O,skewX:A,skewY:E});continue}const U=this._drawingManagerService.getDrawingOrder(s,o),R=U.indexOf(l),x={...p,zIndex:R===-1?U.length-1:R};if(t.getObject(T))continue;x.printable=!1;const Y=new y.Rect(T,x);this._drawingManagerService.getDrawingVisible()&&(t.addObject(Y,y.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&r.allowTransform!==!1&&t.attachTransformerTo(Y),a&&Ee({drawingId:a,unitId:s,subUnitId:o},Y,t,this._drawingManagerService),h.push(Y))}return h}renderDrawing(r,t){const e=this._drawingManagerService.getDrawingByParam(r);if(e!=null)switch(e.drawingType){case f.DrawingTypeEnum.DRAWING_IMAGE:return this.renderImages(e,t)}}previewImage(r,t,e,n){this._galleryService.open({images:[t],onOpenChange:a=>{a||this._galleryService.close()}})}_adjustImageSize(r,t,e,n){if(r<=e&&t<=n)return{width:r,height:t};const a=e/r,s=n/t,o=Math.min(a,s);return{width:Math.floor(r*o),height:Math.floor(t*o)}}},I.DrawingRenderService=Ze([De(0,M.IDrawingManagerService),De(1,M.IImageIoService),De(2,V.IGalleryService)],I.DrawingRenderService);function ge(i,r){const t=[];return i.forEach(e=>{const{oKey:n,left:a,top:s,height:o,width:l,angle:u}=e,d=r.getDrawingOKey(n);if(d==null)return t.push(null),!0;const{unitId:g,subUnitId:h,drawingId:p,drawingType:S}=d,w={unitId:g,subUnitId:h,drawingId:p,drawingType:S,transform:{left:a,top:s,height:o,width:l,angle:u}};S===f.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:f.CommandType.OPERATION,handler:(i,r)=>!0},Xe=i=>{const r=V.useDependency(f.ICommandService),t=V.useDependency(f.LocaleService),{alignShow:e}=i,[n,a]=_.useState(j.default),s=[{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(l){a(l),r.executeCommand(ve.id,{alignType:l})}return c.jsxs("div",{className:D.clsx("univer-relative univer-w-full",D.borderTopClassName,{"univer-hidden":!e}),children:[c.jsx("div",{className:"univer-relative univer-mt-2.5 univer-flex univer-h-full",children:c.jsx("div",{className:"univer-w-full univer-text-gray-900 dark:univer-text-white",children:c.jsx("div",{children:t.t("image-panel.align.title")})})}),c.jsx("div",{className:"univer-relative univer-mt-2.5 univer-flex univer-h-full",children:c.jsx("div",{className:"univer-w-full univer-text-gray-900 dark:univer-text-white",children:c.jsx(D.Select,{value:n,options:s,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,a=i.extend,s=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},s),a)});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(a,s){return Be(a,"".concat(r,"-").concat(i.tag,"-").concat(s),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(a){var s=a[0],o=a[1];s==="mask"&&typeof o=="string"&&(e[s]=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(a){var s=a[0],o=a[1];typeof o=="string"&&(e[s]=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-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(f.LocaleService),n=V.useDependency(M.IDrawingManagerService),[a,s]=_.useState(t);_.useEffect(()=>{const l=n.focus$.subscribe(u=>{s(u)});return()=>{l.unsubscribe()}},[]);const o=l=>{const u=a[0].unitId,d=a[0].subUnitId,g=a.map(h=>h.drawingId);n.featurePluginOrderUpdateNotification({unitId:u,subUnitId:d,drawingIds:g,arrangeType:l})};return c.jsxs("div",{className:D.clsx("univer-relative univer-mt-5 univer-w-full",{"univer-hidden":!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(D.Button,{onClick:()=>{o(f.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(D.Button,{onClick:()=>{o(f.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(D.Button,{onClick:()=>{o(f.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(D.Button,{onClick:()=>{o(f.ArrangeTypeEnum.back)},children:c.jsxs("span",{className:re,children:[c.jsx(je,{}),e.t("image-panel.arrange.back")]})})})]})]})},ut=i=>{const r=V.useDependency(f.LocaleService),t=V.useDependency(y.IRenderManagerService),e=V.useDependency(M.IDrawingManagerService),{hasGroup:n,drawings:a}=i,[s,o]=_.useState(!1),[l,u]=_.useState(!0),[d,g]=_.useState(!0),h=m=>m?"block":"none",p=()=>{const m=e.getFocusDrawings(),{unitId:b,subUnitId:C}=m[0],B=f.Tools.generateRandomId(10),O=y.getGroupState(0,0,m.map(N=>N.transform||{})),A={unitId:b,subUnitId:C,drawingId:B,drawingType:f.DrawingTypeEnum.DRAWING_GROUP,transform:O},E=m.map(N=>{const T=N.transform||{left:0,top:0},{unitId:P,subUnitId:U,drawingId:R}=N;return{unitId:P,subUnitId:U,drawingId:R,transform:{...T,left:T.left-O.left,top:T.top-O.top},groupId:B}});e.featurePluginGroupUpdateNotification([{parent:A,children:E}])},S=m=>{if(m.drawingType!==f.DrawingTypeEnum.DRAWING_GROUP)return;const{unitId:b,subUnitId:C,drawingId:B,transform:O={width:0,height:0}}=m;if(O==null)return;const A=e.getDrawingsByGroup({unitId:b,subUnitId:C,drawingId:B});if(A.length===0)return;const E=A.map(N=>{const{transform:T}=N,{unitId:P,subUnitId:U,drawingId:R}=N,x=y.transformObjectOutOfGroup(T||{},O,O.width||0,O.height||0);return{unitId:P,subUnitId:U,drawingId:R,transform:{...T,...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=a[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 O=B.getTransformerByCreate(),A=O.clearControl$.subscribe(N=>{N===!0&&o(!1)}),E=O.changeStart$.subscribe(N=>{const{objects:T}=N,P=ge(T,e),U=P.filter(K=>(K==null?void 0:K.drawingType)===f.DrawingTypeEnum.DRAWING_GROUP);let R=!1,x=!1;P.length>1&&(R=!0),U.length>0&&(x=!0),o(R||x),u(R),g(x)});return()=>{E.unsubscribe(),A.unsubscribe()}},[]),c.jsxs("div",{className:"univer-relative univer-mt-5 univer-w-full",style:{display:h(n===!0?s:!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:D.clsx(re,"univer-justify-center"),children:c.jsx(D.Button,{style:{display:h(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:D.clsx(re,"univer-justify-center"),children:c.jsx(D.Button,{style:{display:h(d)},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(f.LocaleService),t=V.useDependency(M.IDrawingManagerService),e=V.useDependency(y.IRenderManagerService),{drawings:n,transformShow:a}=i,s=n[0];if(s==null)return;const o=s.transform;if(o==null)return;const{unitId:l,subUnitId:u,drawingId:d,drawingType:g}=s,h=e.getRenderById(l),p=h==null?void 0:h.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:O=0}=o,[A,E]=_.useState(m),[N,T]=_.useState(b),[P,U]=_.useState(C),[R,x]=_.useState(B),[Y,K]=_.useState(O),[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&&T(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&&T(ee),Z!=null&&U(Z),X!=null&&x(X),J!=null&&K(J)})];return()=>{v.forEach(L=>L.unsubscribe())}},[]);const Q=f.debounce(v=>{if(v==null)return;v=Math.max(v,ie);const{limitWidth:L,limitHeight:$}=oe(P,R,v,N);v=Math.min(v,L);const z={unitId:l,subUnitId:u,drawingId:d,drawingType:g,transform:{width:v}};if(de){let W=v/A*N;if(W=Math.max(W,gt),W>$)return;T(W),z.transform.height=W}E(v),t.featurePluginUpdateNotification([z]),w.refreshControls().changeNotification()},we),Ne=f.debounce(v=>{if(v==null)return;v=Math.max(v,ie);const{limitHeight:L,limitWidth:$}=oe(P,R,A,v);v=Math.min(v,L);const z={unitId:l,subUnitId:u,drawingId:d,drawingType:g,transform:{height:v}};if(de){let W=v/N*A;if(W=Math.max(W,ie),W>$)return;E(W),z.transform.width=W}T(v),t.featurePluginUpdateNotification([z]),w.refreshControls().changeNotification()},we),Tt=f.debounce(v=>{if(v==null)return;const{limitLeft:L}=oe(v,R,A,N);v=L;const $={unitId:l,subUnitId:u,drawingId:d,drawingType:g,transform:{left:v}};U(v),t.featurePluginUpdateNotification([$]),w.refreshControls().changeNotification()},we),Et=f.debounce(v=>{if(v==null)return;const{limitTop:L}=oe(P,v,A,N);v=L;const $={unitId:l,subUnitId:u,drawingId:d,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:u,drawingId:d,drawingType:g,transform:{angle:v}};K(v),t.featurePluginUpdateNotification([z]),w.refreshControls().changeNotification()},Bt=v=>{se(v),w.keepRatio=v};return c.jsxs("div",{className:D.clsx("univer-relative univer-mt-5 univer-w-full",D.borderTopClassName,{"univer-hidden":!a}),children:[c.jsx("div",{className:H,children:c.jsx("div",{className:D.clsx(k),children:c.jsx("div",{children:r.t("image-panel.transform.title")})})}),c.jsxs("div",{className:H,children:[c.jsx("div",{className:D.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(D.InputNumber,{precision:1,value:A,onChange:v=>{Q(v)}})})})]})}),c.jsx("div",{className:D.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(D.InputNumber,{precision:1,value:N,onChange:v=>{Ne(v)}})})})]})}),c.jsx("div",{className:D.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:D.clsx(H,"univer-h-9 univer-items-center univer-justify-center"),children:c.jsx("div",{className:k,children:c.jsx(D.Checkbox,{checked:de,onChange:Bt})})})]})})]}),c.jsxs("div",{className:H,children:[c.jsx("div",{className:D.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(D.InputNumber,{precision:1,value:P,onChange:v=>{Tt(v)}})})})]})}),c.jsx("div",{className:D.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(D.InputNumber,{precision:1,value:R,onChange:v=>{Et(v)}})})})]})}),c.jsx("div",{className:D.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(D.InputNumber,{precision:1,value:Y,onChange:Pt})})})]})})]})]})},Se={id:"sheet.operation.open-image-crop",type:f.CommandType.OPERATION,handler:(i,r)=>!0},ne={id:"sheet.operation.close-image-crop",type:f.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:f.CommandType.OPERATION,handler:(i,r)=>!0},pt=i=>{const r=V.useDependency(f.ICommandService),t=V.useDependency(f.LocaleService),{drawings:e,cropperShow:n}=i;if(e[0]==null)return;const[s,o]=_.useState(G.FREE),l=_.useRef(!1),u=[{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 h=r.onCommandExecuted(p=>{if(p.id===ne.id){const S=p.params;S!=null&&S.isAuto||(l.current=!1)}});return()=>{h==null||h.dispose()}},[]);function d(h){o(h),l.current&&r.executeCommand(he.id,{cropType:h})}const g=h=>{r.executeCommand(he.id,{cropType:h}),l.current=!0};return c.jsxs("div",{className:D.clsx("univer-relative univer-mt-5 univer-w-full",D.borderTopClassName,{"univer-hidden":!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(D.Button,{onClick:()=>{g(s)},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(D.Select,{value:s,options:u,onChange:d})})]})]})},mt=i=>{const r=V.useDependency(M.IDrawingManagerService),t=V.useDependency(y.IRenderManagerService),e=V.useDependency(f.LocaleService),{drawings:n,hasArrange:a=!0,hasTransform:s=!0,hasAlign:o=!0,hasCropper:l=!0,hasGroup:u=!0}=i,d=n[0];if(d==null)return;const{unitId:g}=d,h=t.getRenderById(g),p=h==null?void 0:h.scene;if(p==null)return;const S=p.getTransformerByCreate(),[w,m]=_.useState(!0),[b,C]=_.useState(!0),[B,O]=_.useState(!1),[A,E]=_.useState(!0),[N,T]=_.useState(!1);return _.useEffect(()=>{const P=S.clearControl$.subscribe(x=>{x===!0&&(m(!1),C(!1),O(!1),E(!1),T(!0))}),U=S.changeStart$.subscribe(x=>{const{objects:Y}=x,K=ge(Y,r);K.length===0?(m(!1),C(!1),O(!1),E(!1),T(!0)):K.length===1?(m(!0),C(!0),O(!1),E(!0),T(!1)):(m(!0),C(!1),O(!0),E(!1),T(!1))}),R=r.focus$.subscribe(x=>{x.length===0?(m(!1),C(!1),O(!1),E(!1),T(!0)):x.length===1?(m(!0),C(!0),O(!1),E(!0),T(!1)):(m(!0),C(!1),O(!0),E(!1),T(!1))});return()=>{U.unsubscribe(),P.unsubscribe(),R.unsubscribe()}},[]),c.jsxs(c.Fragment,{children:[c.jsx("div",{style:{display:N===!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:a===!0?w:!1,drawings:n}),c.jsx(ft,{transformShow:s===!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:u,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(f.ICommandService),n=V.useDependency(f.LocaleService),[a,s]=_.useState(!1),[o,l]=_.useState(!1),u=()=>{l(!0)},d=()=>{l(!1)},g=m=>{s(m)},h=m=>{e.executeCommand(m.commandId,m.commandParams),s(!1)},p=a||o,S=t.filter(m=>!m.disable);return c.jsx("div",{onMouseEnter:u,onMouseLeave:d,children:c.jsx(D.DropdownMenu,{align:"start",items:S.map(m=>({type:"item",children:n.t(m.label),onSelect:()=>h(m)})),open:a,onOpenChange:g,children:c.jsxs("div",{className:D.clsx("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 dark:hover:univer-bg-gray-800 hover:univer-bg-gray-100",D.borderClassName,{"univer-bg-gray-100 dark:univer-bg-gray-800":a,"univer-bg-white dark:univer-bg-gray-900":!a}),children:[c.jsx(Ue,{className:"univer-fill-primary-600 univer-text-gray-900 dark:univer-text-white"}),p&&c.jsx(xe,{className:"dark:univer-text-white"})]})})})},We="COMPONENT_IMAGE_POPUP_MENU",vt="drawing-ui.config",$e={},Me={id:"sheet.operation.image-reset-size",type:f.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,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},ze=(i,r)=>(t,e)=>r(t,e,i);let _e=class extends f.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,f.Inject(V.ComponentManager)),ze(1,f.ICommandService)],_e);var _t=Object.getOwnPropertyDescriptor,Ct=(i,r,t,e)=>{for(var n=e>1?void 0:e?_t(r,t):r,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},Ce=(i,r)=>(t,e)=>r(t,e,i);let ye=class extends f.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(a=>{Object.keys(r[a]).forEach(s=>{const o=r[a][s].data;o==null||a!==e||s!==n||Object.keys(o).forEach(l=>{o[l]&&this._insertDrawing([{unitId:a,subUnitId:s,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:a,drawingId:s}=t,o=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(o==null)return;const{scene:l,transformer:u}=o;this._commandService.syncExecuteCommand(ne.id);const d=[];if(e.forEach(p=>{const S=M.getDrawingShapeKeyByDrawingSearch(p),w=l.getObjectIncludeInGroup(S);if(w==null||d.includes(w))return;d.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))}),d.length===0)return;const g=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:a,drawingId:s}),h=new y.Group(g);l.addObject(h,y.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(h),h.addObjects(...d),t.transform&&h.transformByState({left:t.transform.left,top:t.transform.top}),u.clearSelectedObjects(),u.setSelectedControl(h)}_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:a,transformer:s}=n;e.forEach(g=>{const h=M.getDrawingShapeKeyByDrawingSearch(g),p=a.getObjectIncludeInGroup(h);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=M.getDrawingShapeKeyByDrawingSearch(t),l=a.getObject(o),{width:u,height:d}=l;l.getObjects().forEach(g=>{l.removeSelfObjectAndTransform(g.oKey,u,d)}),l.dispose(),s.clearSelectedObjects()}_drawingAlign(r){const{alignType:t}=r,e=this._drawingManagerService.getFocusDrawings();if(t===j.default)return;const n=[];let a=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY,u=0;e.forEach(d=>{const{unitId:g,subUnitId:h,drawingId:p,drawingType:S}=d,w=this._drawingManagerService.getDrawingByParam({unitId:g,subUnitId:h,drawingId:p});if(w==null||w.transform==null)return;n.push({unitId:g,subUnitId:h,drawingId:p,drawingType:S,transform:w.transform});const{left:m=0,top:b=0,width:C=0,height:B=0}=w.transform;a=Math.min(a,m),s=Math.min(s,b),o=Math.max(o,m+C),l=Math.max(l,b+B),u++}),u!==0&&(this._sortDrawingTransform(n,t),this._applyAlignType(n,t,a,s,o,l,u))}_applyAlignType(r,t,e,n,a,s,o){const l=Math.round((a-e)/o*10)/10,u=Math.round((s-n)/o*10)/10,d=[],g=this._getSceneAndTransformerByDrawingSearch(r[0].unitId);if(g==null)return;const{scene:h,transformer:p}=g;r.forEach((S,w)=>{const{unitId:m,subUnitId:b,drawingId:C,transform:B,drawingType:O}=S,{left:A=0,top:E=0,width:N=0,height:T=0}=B;let P=A,U=E;switch(t){case j.left:P=e;break;case j.center:P=e+(a-e)/2-N/2;break;case j.right:P=a-N;break;case j.top:U=n;break;case j.middle:U=n+(s-n)/2-T/2;break;case j.bottom:U=s-T;break;case j.horizon:P=e+l*w;break;case j.vertical:U=n+u*w;break}(P!==A||U!==E)&&d.push({unitId:m,subUnitId:b,drawingId:C,drawingType:O,transform:{left:P,top:U}})}),this._drawingManagerService.featurePluginUpdateNotification(d),p.refreshControls().changeNotification()}_sortDrawingTransform(r,t){r.sort((e,n)=>{const a=e.transform,s=n.transform,{left:o=0,top:l=0,width:u=0,height:d=0}=a,{left:g=0,top:h=0,width:p=0,height:S=0}=s;switch(t){case j.left:return o-g;case j.center:return o+u/2-(g+p/2);case j.right:return o+u-(g+p);case j.top:return l-h;case j.middle:return l+d/2-(h+S/2);case j.bottom:return l+d-(h+S);case j.horizon:return o+u/2-(g+p/2);case j.vertical:return l+d/2-(h+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,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;const{scene:s}=a;n.forEach(o=>{const l=M.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:o}),u=s.fuzzyMathObjects(l,!0);if(u==null||u.length===0)return;const d=this._drawingManagerService.getDrawingOrder(t,e).indexOf(o);for(const g of u)g.setProps({zIndex:d}),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 s=this._getSceneAndTransformerByDrawingSearch(n);if(s==null)return;const{scene:o}=s;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 d;const{unitId:e,subUnitId:n,drawingId:a}=t,s=this._getSceneAndTransformerByDrawingSearch(e);if(s==null)return;const{scene:o}=s,l=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),u=o.fuzzyMathObjects(l,!0);if(u.length>0){for(const g of u)g.dispose();(d=o.getTransformer())==null||d.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(r=>{r.forEach(t=>{var N;const{unitId:e,subUnitId:n,drawingId:a}=t,s=this._drawingManagerService.getDrawingByParam(t);if(s==null)return;const{transform:o,drawingType:l}=s,u=this._getSceneAndTransformerByDrawingSearch(e);if(u==null)return;const{scene:d,transformer:g}=u;if(o==null)return!0;const{left:h=0,top:p=0,width:S=0,height:w=0,angle:m=0,flipX:b=!1,flipY:C=!1,skewX:B=0,skewY:O=0}=o,A=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),E=d.getObject(A);if(E==null)return!0;E.transformByState({left:h,top:p,width:S,height:w,angle:m,flipX:b,flipY:C,skewX:B,skewY:O}),(N=d.getTransformer())==null||N.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(r=>{r.forEach(t=>{const{unitId:e,subUnitId:n,drawingId:a}=t,s=this._getSceneAndTransformerByDrawingSearch(e);if(s==null)return;const o=this._drawingManagerService.getDrawingByParam(t);if(o==null)return;const{transform:l}=o,{scene:u}=s,d=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),g=u.getObject(d);if(g==null||l==null)return!0;const{left:h=0,top:p=0,width:S=0,height:w=0,angle:m=0,flipX:b=!1,flipY:C=!1,skewX:B=0,skewY:O=0}=l;g.transformByState({left:h,top:p,width:S,height:w,angle:m,flipX:b,flipY:C,skewX:B,skewY:O})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(r=>{r.forEach(t=>{const{unitId:e,subUnitId:n,drawingId:a,visible:s}=t,o=this._getSceneAndTransformerByDrawingSearch(e);if(o==null)return;const{scene:l}=o,u=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),d=l.getObject(u);if(d==null)return!0;s?d.show():d.hide()})}))}_filterUpdateParams(r,t){return r.filter((e,n)=>{if(e==null)return!1;const{transform:a}=e;return f.checkIfMove(a,t==null?void 0:t[n])})}_addListenerOnDrawing(r){const t=r.getTransformerByCreate();let e=null;this.disposeWithMe(f.toDisposable(t.changeStart$.subscribe(n=>{const{objects:a}=n,s=Array.from(a.values()),o=[];e=s.map(l=>{const{left:u,top:d,height:g,width:h,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:O,drawingId:A}=C;o.push({unitId:B,subUnitId:O,drawingId:A});const{left:E,top:N,height:T,width:P,angle:U}=b;return{left:E,top:N,height:T,width:P,angle:U}}}else if(m!=null){const{unitId:b,subUnitId:C,drawingId:B}=m;return o.push({unitId:b,subUnitId:C,drawingId:B}),{left:u,top:d,height:g,width:h,angle:p}}return null}).filter(l=>l!=null),o.length>0?this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,o):this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,[])}))),this.disposeWithMe(f.toDisposable(t.changeEnd$.subscribe(n=>{const{objects:a}=n,s=this._filterUpdateParams(ge(a,this._drawingManagerService),e);s.length>0&&this._drawingManagerService.featurePluginUpdateNotification(s)})))}};ye=Ct([Ce(0,f.IUniverInstanceService),Ce(1,f.ICommandService),Ce(2,y.IRenderManagerService),Ce(3,M.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,u;const n=this.getScene().getEngine(),{width:a,height:s}=n;this._initialCacheCanvas(),(l=this._cacheCanvas)==null||l.clear();const o=(u=this._cacheCanvas)==null?void 0:u.getContext();o!=null&&(o.save(),y.Rect.drawWith(o,{left:0,top:0,width:a,height:s,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,a=0;const{left:s=0,top:o=0,width:l=0,height:u=0,angle:d}=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,a=m}const g=s+t,h=o+e;this.transformByState({left:g,top:h,width:s+l-n-g,height:o+u-a-h,angle:d})}_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,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},le=(i,r)=>(t,e)=>r(t,e,i);let be=class extends f.Disposable{constructor(r,t,e,n,a,s){super();te(this,"_sceneListenerOnImageMap",new WeakSet);this._commandService=r,this._drawingManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._messageService=a,this._localeService=s,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 a=n[0],{unitId:s,subUnitId:o,drawingId:l}=a,u=this._renderManagerService.getRenderById(s),d=u==null?void 0:u.scene;if(d==null)return!0;this._searchCropObject(d)!=null&&this._commandService.syncExecuteCommand(ne.id,{isAuto:!0});const h=M.getDrawingShapeKeyByDrawingSearch({unitId:s,subUnitId:o,drawingId:l}),p=d.getObject(h);if(!(p instanceof y.Image)){this._messageService.show({type:D.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}p!=null&&(this._updateCropperObject(e,p),this._commandService.executeCommand(Se.id,{unitId:s,subUnitId:o,drawingId:l}))}))}_calculateSrcRectByRatio(r,t,e,n,a,s){const o=e/n,l=a/s;let u=e,d=n;o>l?u=n*l:d=e/l;const g=(e-u)/2,h=(n-d)/2;return{left:y.precisionTo(g,1),top:y.precisionTo(h,1),right:y.precisionTo(e-(g+u),1),bottom:y.precisionTo(n-(h+d),1)}}_updateCropperObject(r,t){const{left:e,top:n,width:a,height:s}=t.calculateTransformWithSrcRect();let o;switch(r){case G.R1_1:o=this._calculateSrcRectByRatio(e,n,a,s,1,1);break;case G.R16_9:o=this._calculateSrcRectByRatio(e,n,a,s,16,9);break;case G.R9_16:o=this._calculateSrcRectByRatio(e,n,a,s,9,16);break;case G.R5_4:o=this._calculateSrcRectByRatio(e,n,a,s,5,4);break;case G.R4_5:o=this._calculateSrcRectByRatio(e,n,a,s,4,5);break;case G.R4_3:o=this._calculateSrcRectByRatio(e,n,a,s,4,3);break;case G.R3_4:o=this._calculateSrcRectByRatio(e,n,a,s,3,4);break;case G.R3_2:o=this._calculateSrcRectByRatio(e,n,a,s,3,2);break;case G.R2_3:o=this._calculateSrcRectByRatio(e,n,a,s,2,3);break;case G.FREE:}if(o==null)return;t.setSrcRect(o);const{left:l=0,top:u=0,bottom:d=0,right:g=0}=o;t.transformByStateCloseCropper({left:e+l,top:n+u,width:a-g-l,height:s-d-u})}_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:a}=t,s=this._renderManagerService.getRenderById(e),o=s==null?void 0:s.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:a})==null)return;const u=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),d=o.getObject(u);if(d==null)return;if(!(d instanceof y.Image)){this._messageService.show({type:D.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}const g=o.getTransformer();g==null||g.clearControls();const h=new fe(`${u}-crop`,{srcRect:d.srcRect,prstGeom:d.prstGeom,applyTransform:d.calculateTransformWithSrcRect()});o.addObject(h,d.getLayerIndex()+1).attachTransformerTo(h),g==null||g.createControlForCopper(h),this._addHoverForImageCopper(h),d.openRenderByCropper(),g==null||g.refreshControls(),h.makeDirty(!0),this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:a}])}))}_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(),a=this._renderManagerService.getRenderById(n),s=a==null?void 0:a.scene;if(s==null)return!0;const o=this._searchCropObject(s);if(o==null)return;const l=this._getApplyObjectByCropObject(o);if(l==null)return;const u=s.getTransformerByCreate();u.detachFrom(o),u.clearCopperControl();const d=this._getSrcRectByTransformState(l,o),g=this._drawingManagerService.getDrawingOKey(l.oKey);if(g!=null){const{left:h,top:p,height:S,width:w}=o;this._drawingManagerService.featurePluginUpdateNotification([{...g,transform:{...g.transform,left:h,top:p,height:S,width:w},srcRect:d.srcRectAngle}])}l.setSrcRect({...d.srcRectAngle}),l.closeRenderByCropper(),l.makeDirty(!0),o==null||o.dispose()}));const r=this._univerInstanceService.getCurrentTypeOfUnit$(f.UniverInstanceType.UNIVER_SHEET).pipe(Te.switchMap(t=>t?t.activeSheet$:Te.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 a=n.getObject(e);return a==null?null:a}_addListenerOnImage(r){const t=r.getTransformerByCreate();let e=null;this.disposeWithMe(t.changeStart$.subscribe(n=>{const{objects:a}=n,s=a.values().next().value;if(s==null||!(s instanceof fe))return;const{left:o,top:l,height:u,width:d,angle:g}=s;e={left:o,top:l,height:u,width:d,angle:g},t.clearCopperControl()})),this.disposeWithMe(t.changeEnd$.subscribe(n=>{const{objects:a}=n,s=a.values().next().value;if(s==null||!(s instanceof fe))return;const{left:o,top:l,height:u,width:d,angle:g}=s;if(!f.checkIfMove({left:o,top:l,height:u,width:d,angle:g},e))return;const h=this._getApplyObjectByCropObject(s);if(h==null)return;const p=this._getSrcRectByTransformState(h,s);s.refreshSrcRect(p.srcRect,h.getState()),t.createControlForCopper(s)})),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:a,width:s,strokeWidth:o,angle:l}=t,{left:u,top:d,width:g,height:h,angle:p,strokeWidth:S}=r,w=e-u,m=n-d,b={left:w,top:m,right:g-w-s,bottom:h-m-a},C={...b};if(p!==0){const B=e+s/2,O=n+a/2,A=new y.Vector2(B,O),E=g/2+u,N=h/2+d,T=new y.Vector2(E,N),P=new y.Vector2(u,d);P.rotateByPoint(y.degToRad(p),T);const U=P.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-s,C.bottom=h-x-a}return{srcRect:b,srcRectAngle:C}}};be=bt([le(0,f.ICommandService),le(1,M.IDrawingManagerService),le(2,y.IRenderManagerService),le(3,f.IUniverInstanceService),le(4,V.IMessageService),le(5,f.Inject(f.LocaleService))],be);var It=Object.getOwnPropertyDescriptor,Dt=(i,r,t,e)=>{for(var n=e>1?void 0:e?It(r,t):r,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},ae=(i,r)=>(t,e)=>r(t,e,i);let Ie=class extends f.Disposable{constructor(i,r,t,e,n,a,s){super(),this._commandService=i,this._renderManagerService=r,this._drawingManagerService=t,this._dialogService=e,this._imageIoService=n,this._currentUniverService=a,this._drawingRenderService=s,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:a,drawingId:s}=e,o=this._getSceneAndTransformerByDrawingSearch(n);if(o==null)return;const{scene:l}=o,u=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:a,drawingId:s}),d=l.getObject(u);if(d==null)return!0;const g=this._drawingManagerService.getDrawingByParam(e);if(g==null)return!0;if(g.drawingType!==f.DrawingTypeEnum.DRAWING_IMAGE)return;d.resetSize();const{width:h,height:p}=d.getNativeSize();t.includes(l)===!1&&t.push(l),r.push({...g,transform:{...g.transform,height:p,width:h,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(r),t.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(M.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),a=(l=Pe(this._currentUniverService,t))==null?void 0:l.subUnitId;if(n==null||a!==e)return;const s=this._drawingManagerService.getDrawingByParam(r);if(s==null)return;const o=await this._drawingRenderService.renderImages(s,n.scene);if(this._drawingManagerService.refreshTransform([s]),!(o==null||o.length===0))for(const u of o)this._addHoverForImage(u),this._addDialogForImage(u)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(i=>{i.forEach(r=>{const{unitId:t,subUnitId:e,drawingId:n}=r,a=this._drawingManagerService.getDrawingByParam(r);if(a==null)return;const{transform:s,drawingType:o,srcRect:l,prstGeom:u,source:d,imageSourceType:g}=a;if(o!==f.DrawingTypeEnum.DRAWING_IMAGE)return;const h=this._getSceneAndTransformerByDrawingSearch(t);if(h==null)return;const{scene:p,transformer:S}=h;if(s==null)return!0;const w=M.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),m=p.getObject(w);if(m==null)return!0;m.setSrcRect(l),m.setPrstGeom(u),d!=null&&d.length>0&&(g===f.ImageSourceType.BASE64||g===f.ImageSourceType.URL)&&m.changeSource(d)})}))}_addHoverForImage(i){this.disposeWithMe(f.toDisposable(i.onPointerEnter$.subscribeEvent(()=>{i.cursor=y.CURSOR_TYPE.GRAB}))),this.disposeWithMe(f.toDisposable(i.onPointerLeave$.subscribeEvent(()=>{i.cursor=y.CURSOR_TYPE.DEFAULT})))}_addDialogForImage(i){this.disposeWithMe(f.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,f.ICommandService),ae(1,y.IRenderManagerService),ae(2,M.IDrawingManagerService),ae(3,V.IDialogService),ae(4,M.IImageIoService),ae(5,f.IUniverInstanceService),ae(6,f.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,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},Ke=(i,r)=>(t,e)=>r(t,e,i);const Nt="UNIVER_DRAWING_UI_PLUGIN";I.UniverDrawingUIPlugin=(Oe=class extends f.Plugin{constructor(r=$e,t,e){super(),this._config=r,this._injector=t,this._configService=e;const{menu:n,...a}=f.merge({},$e,this._config);n&&this._configService.setConfig("menu",n,{merge:!0}),this._configService.setConfig(vt,a)}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,f.Inject(f.Injector)),Ke(2,f.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"})});
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("@univerjs/design"),require("react"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/drawing","@univerjs/engine-render","@univerjs/ui","react/jsx-runtime","@univerjs/design","react","rxjs"],h):(D=typeof globalThis<"u"?globalThis:D||self,h(D.UniverDrawingUi={},D.UniverCore,D.UniverDrawing,D.UniverEngineRender,D.UniverUi,D.React,D.UniverDesign,D.React,D.rxjs))})(this,function(D,h,M,I,x,f,U,_,Me){"use strict";var Pt=Object.defineProperty;var Nt=(D,h,M)=>h in D?Pt(D,h,{enumerable:!0,configurable:!0,writable:!0,value:M}):D[h]=M;var Q=(D,h,M)=>Nt(D,typeof h!="symbol"?h+"":h,M);var be;function Oe(i,r,t,e){const n=e.getDrawingByParam(i);if(n==null)return;const a=M.getDrawingShapeKeyByDrawingSearch(i),s=t.getObject(a);if(s&&!(s instanceof I.Group))return;if(s!=null){s.addObject(r);return}const o=new I.Group(a);t.addObject(o,I.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(o),o.addObject(r);const{transform:c}=n;c&&o.transformByState({left:c.left,top:c.top,angle:c.angle})}function Ee(i,r){var a;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=(a=t.getActiveSheet())==null?void 0:a.getSheetId():(t.type===h.UniverInstanceType.UNIVER_DOC||t.type===h.UniverInstanceType.UNIVER_SLIDE)&&(n=e),{unitId:e,subUnitId:n,current:t}}var ze=Object.getOwnPropertyDescriptor,Ke=(i,r,t,e)=>{for(var n=e>1?void 0:e?ze(r,t):r,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},ye=(i,r)=>(t,e)=>r(t,e,i);D.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:a,imageSourceType:s,srcRect:o,prstGeom:c,groupId:u,unitId:l,subUnitId:g,drawingId:d,isMultiTransform:p,transforms:S}=r;if(n!==h.DrawingTypeEnum.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||e==null)return;const m=p&&S?S:[e],v=[];for(const C of m){const{left:y,top:O,width:N,height:R,angle:b,flipX:T,flipY:E,skewX:B,skewY:P}=C,G=m.indexOf(C),H=M.getDrawingShapeKeyByDrawingSearch({unitId:l,subUnitId:g,drawingId:d},p?G:void 0),$=t.getObject(H);if($!=null){$.transformByState({left:y,top:O,width:N,height:R,angle:b,flipX:T,flipY:E,skewX:B,skewY:P});continue}const X=this._drawingManagerService.getDrawingOrder(l,g),oe=X.indexOf(d),ne={...C,zIndex:oe===-1?X.length-1:oe},ie=this._imageIoService.getImageSourceCache(a,s);let ce=!1;if(ie!=null)ne.image=ie;else{if(s===M.ImageSourceType.UUID)try{ne.url=await this._imageIoService.getImage(a)}catch(De){console.error(De);continue}else ne.url=a;ce=!0}if(t.getObject(H))continue;ne.printable=!0;const q=new I.Image(H,ne);ce&&this._imageIoService.addImageSourceCache(a,s,q.getNative()),this._drawingManagerService.getDrawingVisible()&&(t.addObject(q,I.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&t.attachTransformerTo(q),u&&Oe({drawingId:u,unitId:l,subUnitId:g},q,t,this._drawingManagerService),c!=null&&q.setPrstGeom(c),o!=null&&q.setSrcRect(o),v.push(q))}return v}renderFloatDom(r,t){const{transform:e,drawingType:n,groupId:a,unitId:s,subUnitId:o,drawingId:c,isMultiTransform:u,transforms:l}=r;if(n!==h.DrawingTypeEnum.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||e==null)return;const g=u&&l?l:[e],d=[];for(const p of g){const{left:S,top:m,width:v,height:C,angle:y,flipX:O,flipY:N,skewX:R,skewY:b}=p,T=g.indexOf(p),E=M.getDrawingShapeKeyByDrawingSearch({unitId:s,subUnitId:o,drawingId:c},u?T:void 0),B=t.getObject(E);if(B!=null){B.transformByState({left:S,top:m,width:v,height:C,angle:y,flipX:O,flipY:N,skewX:R,skewY:b});continue}const P=this._drawingManagerService.getDrawingOrder(s,o),G=P.indexOf(c),H={...p,zIndex:G===-1?P.length-1:G};if(t.getObject(E))continue;H.printable=!1;const $=new I.Rect(E,H);this._drawingManagerService.getDrawingVisible()&&(t.addObject($,I.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&r.allowTransform!==!1&&t.attachTransformerTo($),a&&Oe({drawingId:a,unitId:s,subUnitId:o},$,t,this._drawingManagerService),d.push($))}return d}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:a=>{a||this._galleryService.close()}})}_adjustImageSize(r,t,e,n){if(r<=e&&t<=n)return{width:r,height:t};const a=e/r,s=n/t,o=Math.min(a,s);return{width:Math.floor(r*o),height:Math.floor(t*o)}}},D.DrawingRenderService=Ke([ye(0,M.IDrawingManagerService),ye(1,M.IImageIoService),ye(2,x.IGalleryService)],D.DrawingRenderService);function le(i,r){const t=[];return i.forEach(e=>{const{oKey:n,left:a,top:s,height:o,width:c,angle:u}=e,l=r.getDrawingOKey(n);if(l==null)return t.push(null),!0;const{unitId:g,subUnitId:d,drawingId:p,drawingType:S}=l,m={unitId:g,subUnitId:d,drawingId:p,drawingType:S,transform:{left:a,top:s,height:o,width:c,angle:u}};S===h.DrawingTypeEnum.DRAWING_IMAGE&&(m.srcRect=e.srcRect),t.push(m)}),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 fe={id:"sheet.operation.set-image-align",type:h.CommandType.OPERATION,handler:(i,r)=>!0},Fe=i=>{const r=x.useDependency(h.ICommandService),t=x.useDependency(h.LocaleService),{alignShow:e}=i,[n,a]=_.useState(j.default),s=[{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(c){a(c),r.executeCommand(fe.id,{alignType:c})}return f.jsxs("div",{className:U.clsx("univer-relative univer-w-full",{"univer-hidden":!e}),children:[f.jsx("header",{className:"univer-text-gray-600 dark:univer-text-gray-200",children:f.jsx("div",{children:t.t("image-panel.align.title")})}),f.jsx("div",{className:"univer-relative univer-mt-2.5 univer-flex univer-h-full",children:f.jsx("div",{className:"univer-w-full univer-text-gray-900 dark:univer-text-white",children:f.jsx(U.Select,{value:n,options:s,onChange:o})})})]})};var z=function(){return z=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},z.apply(this,arguments)},Ye=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},Y=_.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,a=i.extend,s=Ye(i,["icon","id","className","extend"]),o="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),c=_.useRef("_".concat(qe()));return Te(t,"".concat(e),{defIds:t.defIds,idSuffix:c.current},z({ref:r,className:o},s),a)});function Te(i,r,t,e,n){return _.createElement(i.tag,z(z({key:r},Ze(i,t,n)),e),(Xe(i,t).children||[]).map(function(a,s){return Te(a,"".concat(r,"-").concat(i.tag,"-").concat(s),t,void 0,n)}))}function Ze(i,r,t){var e=z({},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(a){var s=a[0],o=a[1];s==="mask"&&typeof o=="string"&&(e[s]=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(a){var s=a[0],o=a[1];typeof o=="string"&&(e[s]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Xe(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)?z(z({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?z(z({},n),{attrs:z(z({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function qe(){return Math.random().toString(36).substring(2,8)}Y.displayName="UniverIcon";var Je={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"}}]},Pe=_.forwardRef(function(i,r){return _.createElement(Y,Object.assign({},i,{id:"autofill",ref:r,icon:Je}))});Pe.displayName="Autofill";var Qe={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"}}]},Ne=_.forwardRef(function(i,r){return _.createElement(Y,Object.assign({},i,{id:"bottom-single",ref:r,icon:Qe}))});Ne.displayName="BottomSingle";var et={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"}}]},Be=_.forwardRef(function(i,r){return _.createElement(Y,Object.assign({},i,{id:"create-copy-single",ref:r,icon:et}))});Be.displayName="CreateCopySingle";var tt={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"}}]},Ue=_.forwardRef(function(i,r){return _.createElement(Y,Object.assign({},i,{id:"group-single",ref:r,icon:tt}))});Ue.displayName="GroupSingle";var rt={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"}}]},je=_.forwardRef(function(i,r){return _.createElement(Y,Object.assign({},i,{id:"more-down-single",ref:r,icon:rt}))});je.displayName="MoreDownSingle";var nt={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"}}]},Re=_.forwardRef(function(i,r){return _.createElement(Y,Object.assign({},i,{id:"move-down-single",ref:r,icon:nt}))});Re.displayName="MoveDownSingle";var it={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"}}]},Ae=_.forwardRef(function(i,r){return _.createElement(Y,Object.assign({},i,{id:"move-up-single",ref:r,icon:it}))});Ae.displayName="MoveUpSingle";var at={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"}}]},Le=_.forwardRef(function(i,r){return _.createElement(Y,Object.assign({},i,{id:"topmost-single",ref:r,icon:at}))});Le.displayName="TopmostSingle";var st={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"}}]},xe=_.forwardRef(function(i,r){return _.createElement(Y,Object.assign({},i,{id:"ungroup-single",ref:r,icon:st}))});xe.displayName="UngroupSingle";const ot=i=>{const{arrangeShow:r,drawings:t}=i,e=x.useDependency(h.LocaleService),n=x.useDependency(M.IDrawingManagerService),[a,s]=_.useState(t);_.useEffect(()=>{const c=n.focus$.subscribe(u=>{s(u)});return()=>{c.unsubscribe()}},[]);const o=c=>{const u=a[0].unitId,l=a[0].subUnitId,g=a.map(d=>d.drawingId);n.featurePluginOrderUpdateNotification({unitId:u,subUnitId:l,drawingIds:g,arrangeType:c})};return f.jsxs("div",{className:U.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!r}),children:[f.jsx("header",{className:"univer-text-gray-600 dark:univer-text-gray-200",children:f.jsx("div",{children:e.t("image-panel.arrange.title")})}),f.jsxs("div",{className:"univer-grid univer-grid-cols-2 univer-gap-2 univer-px-8",children:[f.jsxs(U.Button,{onClick:()=>{o(h.ArrangeTypeEnum.forward)},children:[f.jsx(Ae,{}),e.t("image-panel.arrange.forward")]}),f.jsxs(U.Button,{onClick:()=>{o(h.ArrangeTypeEnum.backward)},children:[f.jsx(Re,{}),e.t("image-panel.arrange.backward")]}),f.jsxs(U.Button,{onClick:()=>{o(h.ArrangeTypeEnum.front)},children:[f.jsx(Le,{}),e.t("image-panel.arrange.front")]}),f.jsxs(U.Button,{onClick:()=>{o(h.ArrangeTypeEnum.back)},children:[f.jsx(Ne,{}),e.t("image-panel.arrange.back")]})]})]})},ct=i=>{const r=x.useDependency(h.LocaleService),t=x.useDependency(I.IRenderManagerService),e=x.useDependency(M.IDrawingManagerService),{hasGroup:n,drawings:a}=i,[s,o]=_.useState(!1),[c,u]=_.useState(!0),[l,g]=_.useState(!0),d=()=>{const m=e.getFocusDrawings(),{unitId:v,subUnitId:C}=m[0],y=h.Tools.generateRandomId(10),O=I.getGroupState(0,0,m.map(b=>b.transform||{})),N={unitId:v,subUnitId:C,drawingId:y,drawingType:h.DrawingTypeEnum.DRAWING_GROUP,transform:O},R=m.map(b=>{const T=b.transform||{left:0,top:0},{unitId:E,subUnitId:B,drawingId:P}=b;return{unitId:E,subUnitId:B,drawingId:P,transform:{...T,left:T.left-O.left,top:T.top-O.top},groupId:y}});e.featurePluginGroupUpdateNotification([{parent:N,children:R}])},p=m=>{if(m.drawingType!==h.DrawingTypeEnum.DRAWING_GROUP)return;const{unitId:v,subUnitId:C,drawingId:y,transform:O={width:0,height:0}}=m;if(O==null)return;const N=e.getDrawingsByGroup({unitId:v,subUnitId:C,drawingId:y});if(N.length===0)return;const R=N.map(b=>{const{transform:T}=b,{unitId:E,subUnitId:B,drawingId:P}=b,G=I.transformObjectOutOfGroup(T||{},O,O.width||0,O.height||0);return{unitId:E,subUnitId:B,drawingId:P,transform:{...T,...G},groupId:void 0}});return{parent:m,children:R}},S=()=>{const v=e.getFocusDrawings().map(C=>p(C)).filter(C=>C!=null);v.length!==0&&e.featurePluginUngroupUpdateNotification(v)};return _.useEffect(()=>{const m=a[0];if(m==null)return;const{unitId:v}=m,C=t.getRenderById(v),y=C==null?void 0:C.scene;if(y==null)return;const O=y.getTransformerByCreate(),N=O.clearControl$.subscribe(b=>{b===!0&&o(!1)}),R=O.changeStart$.subscribe(b=>{const{objects:T}=b,E=le(T,e),B=E.filter($=>($==null?void 0:$.drawingType)===h.DrawingTypeEnum.DRAWING_GROUP);let P=!1,G=!1;E.length>1&&(P=!0),B.length>0&&(G=!0),o(P||G),u(P),g(G)});return()=>{R.unsubscribe(),N.unsubscribe()}},[]),f.jsxs("div",{className:U.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":n===!0&&s===!1||n===!1}),children:[f.jsx("header",{className:"univer-text-gray-600 dark:univer-text-gray-200",children:f.jsx("div",{children:r.t("image-panel.group.title")})}),f.jsxs("div",{className:"univer-flex univer-items-center univer-justify-center univer-gap-2",children:[f.jsxs(U.Button,{className:U.clsx({"univer-hidden":!c}),onClick:d,children:[f.jsx(Ue,{}),r.t("image-panel.group.group")]}),f.jsxs(U.Button,{className:U.clsx({"univer-hidden":!l}),onClick:S,children:[f.jsx(xe,{}),r.t("image-panel.group.unGroup")]})]})]})},te=20,lt=20,ut=[-3600,3600],pe=300,gt=i=>{var $e;const r=x.useDependency(h.LocaleService),t=x.useDependency(M.IDrawingManagerService),e=x.useDependency(I.IRenderManagerService),{drawings:n,transformShow:a}=i,s=n[0];if(s==null)return;const o=s.transform;if(o==null)return;const{unitId:c,subUnitId:u,drawingId:l,drawingType:g}=s,d=e.getRenderById(c),p=d==null?void 0:d.scene;if(p==null)return;const S=($e=p.getEngine())==null?void 0:$e.activeScene;if(S==null)return;const m=p.getTransformerByCreate(),{width:v=0,height:C=0,left:y=0,top:O=0,angle:N=0}=o,[R,b]=_.useState(v),[T,E]=_.useState(C),[B,P]=_.useState(y),[G,H]=_.useState(O),[$,X]=_.useState(N),[oe,ne]=_.useState(m.keepRatio),ie=(w,A,V,W)=>{const{width:k,height:J}=S,{ancestorLeft:K,ancestorTop:F}=p;let Z=w,ae=A,de=V,he=W;return w+K<0&&(Z=-K),A+F<0&&(ae=-F),de=k-Z-K,de<te&&(de=te),he=J-ae-F,he<te&&(he=te),w+de+K>k&&(Z=k-V-K),A+he+F>J&&(ae=J-W-F),{limitLeft:Z,limitTop:ae,limitWidth:de,limitHeight:he}},ce=w=>{const{objects:A}=w,V=le(A,t);if(V.length!==1)return;const W=V[0];if(W==null)return;const{transform:k}=W;if(k==null)return;const{width:J,height:K,left:F,top:Z,angle:ae}=k;J!=null&&b(J),K!=null&&E(K),F!=null&&P(F),Z!=null&&H(Z),ae!=null&&X(ae)};_.useEffect(()=>{const w=[m.changeStart$.subscribe(A=>{ce(A)}),m.changing$.subscribe(A=>{ce(A)}),m.changeEnd$.subscribe(A=>{ce(A)}),t.focus$.subscribe(A=>{if(A.length!==1)return;const V=t.getDrawingByParam(A[0]);if(V==null)return;const W=V.transform;if(W==null)return;const{width:k,height:J,left:K,top:F,angle:Z}=W;k!=null&&b(k),J!=null&&E(J),K!=null&&P(K),F!=null&&H(F),Z!=null&&X(Z)})];return()=>{w.forEach(A=>A.unsubscribe())}},[]);const q=h.debounce(w=>{if(w==null)return;w=Math.max(w,te);const{limitWidth:A,limitHeight:V}=ie(B,G,w,T);w=Math.min(w,A);const W={unitId:c,subUnitId:u,drawingId:l,drawingType:g,transform:{width:w}};if(oe){let k=w/R*T;if(k=Math.max(k,lt),k>V)return;E(k),W.transform.height=k}b(w),t.featurePluginUpdateNotification([W]),m.refreshControls().changeNotification()},pe),De=h.debounce(w=>{if(w==null)return;w=Math.max(w,te);const{limitHeight:A,limitWidth:V}=ie(B,G,R,w);w=Math.min(w,A);const W={unitId:c,subUnitId:u,drawingId:l,drawingType:g,transform:{height:w}};if(oe){let k=w/T*R;if(k=Math.max(k,te),k>V)return;b(k),W.transform.width=k}E(w),t.featurePluginUpdateNotification([W]),m.refreshControls().changeNotification()},pe),Mt=h.debounce(w=>{if(w==null)return;const{limitLeft:A}=ie(w,G,R,T);w=A;const V={unitId:c,subUnitId:u,drawingId:l,drawingType:g,transform:{left:w}};P(w),t.featurePluginUpdateNotification([V]),m.refreshControls().changeNotification()},pe),Ot=h.debounce(w=>{if(w==null)return;const{limitTop:A}=ie(B,w,R,T);w=A;const V={unitId:c,subUnitId:u,drawingId:l,drawingType:g,transform:{top:w}};H(w),t.featurePluginUpdateNotification([V]),m.refreshControls().changeNotification()},pe),Et=w=>{if(w==null)return;const[A,V]=ut;w<A&&(w=A),w>V&&(w=V);const W={unitId:c,subUnitId:u,drawingId:l,drawingType:g,transform:{angle:w}};X(w),t.featurePluginUpdateNotification([W]),m.refreshControls().changeNotification()},Tt=w=>{ne(w),m.keepRatio=w};return f.jsxs("div",{className:U.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!a}),children:[f.jsx("header",{className:"univer-text-gray-600 dark:univer-text-gray-200",children:f.jsx("div",{children:r.t("image-panel.transform.title")})}),f.jsxs("div",{className:"univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",children:[f.jsxs("div",{children:[f.jsx("span",{children:r.t("image-panel.transform.width")}),f.jsx(U.InputNumber,{precision:1,value:R,onChange:w=>{q(w)}})]}),f.jsxs("div",{children:[f.jsx("span",{children:r.t("image-panel.transform.height")}),f.jsx(U.InputNumber,{precision:1,value:T,onChange:w=>{De(w)}})]}),f.jsxs("div",{children:[f.jsx("span",{children:r.t("image-panel.transform.lock")}),f.jsx("div",{className:"univer-text-center",children:f.jsx(U.Checkbox,{checked:oe,onChange:Tt})})]})]}),f.jsxs("div",{className:"univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",children:[f.jsxs("div",{children:[f.jsx("span",{children:r.t("image-panel.transform.x")}),f.jsx(U.InputNumber,{precision:1,value:B,onChange:w=>{Mt(w)}})]}),f.jsxs("div",{children:[f.jsx("span",{children:r.t("image-panel.transform.y")}),f.jsx(U.InputNumber,{precision:1,value:G,onChange:w=>{Ot(w)}})]}),f.jsxs("div",{children:[f.jsx("span",{children:r.t("image-panel.transform.rotate")}),f.jsx(U.InputNumber,{precision:1,value:$,onChange:Et})]})]})]})},me={id:"sheet.operation.open-image-crop",type:h.CommandType.OPERATION,handler:(i,r)=>!0},ee={id:"sheet.operation.close-image-crop",type:h.CommandType.OPERATION,handler:(i,r)=>!0};var L=(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))(L||{});const ue={id:"sheet.operation.Auto-image-crop",type:h.CommandType.OPERATION,handler:(i,r)=>!0},dt=i=>{const r=x.useDependency(h.ICommandService),t=x.useDependency(h.LocaleService),{drawings:e,cropperShow:n}=i;if(e[0]==null)return;const[s,o]=_.useState(L.FREE),c=_.useRef(!1),u=[{label:t.t("image-panel.crop.mode"),value:L.FREE},{label:"1:1",value:L.R1_1},{label:"16:9",value:L.R16_9},{label:"9:16",value:L.R9_16},{label:"5:4",value:L.R5_4},{label:"4:5",value:L.R4_5},{label:"4:3",value:L.R4_3},{label:"3:4",value:L.R3_4},{label:"3:2",value:L.R3_2},{label:"2:3",value:L.R2_3}];_.useEffect(()=>{const d=r.onCommandExecuted(p=>{if(p.id===ee.id){const S=p.params;S!=null&&S.isAuto||(c.current=!1)}});return()=>{d==null||d.dispose()}},[]);function l(d){o(d),c.current&&r.executeCommand(ue.id,{cropType:d})}const g=d=>{r.executeCommand(ue.id,{cropType:d}),c.current=!0};return f.jsxs("div",{className:U.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!n}),children:[f.jsx("header",{className:"univer-text-gray-600 dark:univer-text-gray-200",children:f.jsx("div",{children:t.t("image-panel.crop.title")})}),f.jsxs("div",{className:"univer-flex univer-items-center univer-justify-center univer-gap-2",children:[f.jsxs(U.Button,{onClick:()=>{g(s)},children:[f.jsx(Be,{}),t.t("image-panel.crop.start")]}),f.jsx(U.Select,{value:s,options:u,onChange:l})]})]})},ht=i=>{const r=x.useDependency(M.IDrawingManagerService),t=x.useDependency(I.IRenderManagerService),e=x.useDependency(h.LocaleService),{drawings:n,hasArrange:a=!0,hasTransform:s=!0,hasAlign:o=!0,hasCropper:c=!0,hasGroup:u=!0}=i,l=n[0];if(l==null)return;const{unitId:g}=l,d=t.getRenderById(g),p=d==null?void 0:d.scene;if(p==null)return;const S=p.getTransformerByCreate(),[m,v]=_.useState(!0),[C,y]=_.useState(!0),[O,N]=_.useState(!1),[R,b]=_.useState(!0),[T,E]=_.useState(!1);return _.useEffect(()=>{const B=S.clearControl$.subscribe(H=>{H===!0&&(v(!1),y(!1),N(!1),b(!1),E(!0))}),P=S.changeStart$.subscribe(H=>{const{objects:$}=H,X=le($,r);X.length===0?(v(!1),y(!1),N(!1),b(!1),E(!0)):X.length===1?(v(!0),y(!0),N(!1),b(!0),E(!1)):(v(!0),y(!1),N(!0),b(!1),E(!1))}),G=r.focus$.subscribe(H=>{H.length===0?(v(!1),y(!1),N(!1),b(!1),E(!0)):H.length===1?(v(!0),y(!0),N(!1),b(!0),E(!1)):(v(!0),y(!1),N(!0),b(!1),E(!1))});return()=>{P.unsubscribe(),B.unsubscribe(),G.unsubscribe()}},[]),f.jsxs(f.Fragment,{children:[f.jsx("div",{className:U.clsx("univer-h-full",{"univer-hidden":!T}),children:f.jsx("div",{className:"univer-flex univer-h-full univer-items-center univer-justify-center",children:f.jsx("span",{children:e.t("image-panel.null")})})}),f.jsx(ot,{arrangeShow:a===!0?m:!1,drawings:n}),f.jsx(gt,{transformShow:s===!0?C:!1,drawings:n}),f.jsx(Fe,{alignShow:o===!0?O:!1,drawings:n}),f.jsx(dt,{cropperShow:c===!0?R:!1,drawings:n}),f.jsx(ct,{hasGroup:u,drawings:n})]})},He=i=>{var m;const{popup:r}=i,t=(m=r==null?void 0:r.extraProps)==null?void 0:m.menuItems;if(!t)return null;const e=x.useDependency(h.ICommandService),n=x.useDependency(h.LocaleService),[a,s]=_.useState(!1),[o,c]=_.useState(!1),u=()=>{c(!0)},l=()=>{c(!1)},g=v=>{s(v)},d=v=>{e.executeCommand(v.commandId,v.commandParams),s(!1)},p=a||o,S=t.filter(v=>!v.disable);return f.jsx("div",{onMouseEnter:u,onMouseLeave:l,children:f.jsx(U.DropdownMenu,{align:"start",items:S.map(v=>({type:"item",children:n.t(v.label),onSelect:()=>d(v)})),open:a,onOpenChange:g,children:f.jsxs("div",{className:U.clsx("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 dark:hover:univer-bg-gray-800 hover:univer-bg-gray-100",U.borderClassName,{"univer-bg-gray-100 dark:univer-bg-gray-800":a,"univer-bg-white dark:univer-bg-gray-900":!a}),children:[f.jsx(Pe,{className:"univer-fill-primary-600 univer-text-gray-900 dark:univer-text-white"}),p&&f.jsx(je,{className:"dark:univer-text-white"})]})})})},ke="COMPONENT_IMAGE_POPUP_MENU",ft="drawing-ui.config",Ge={},Ie={id:"sheet.operation.image-reset-size",type:h.CommandType.OPERATION,handler:(i,r)=>!0};var pt=Object.getOwnPropertyDescriptor,mt=(i,r,t,e)=>{for(var n=e>1?void 0:e?pt(r,t):r,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},Ve=(i,r)=>(t,e)=>r(t,e,i);let ve=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(ke,He))}_initCommands(){[me,ee,Ie,fe,ue].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_init(){this._initCommands(),this._initCustomComponents()}};ve=mt([Ve(0,h.Inject(x.ComponentManager)),Ve(1,h.ICommandService)],ve);var vt=Object.getOwnPropertyDescriptor,wt=(i,r,t,e)=>{for(var n=e>1?void 0:e?vt(r,t):r,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},we=(i,r)=>(t,e)=>r(t,e,i);let Se=class extends h.Disposable{constructor(r,t,e,n){super();Q(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=Ee(this._currentUniverService);if(t==null)return;const{unitId:e,subUnitId:n}=t;Object.keys(r).forEach(a=>{Object.keys(r[a]).forEach(s=>{const o=r[a][s].data;o==null||a!==e||s!==n||Object.keys(o).forEach(c=>{o[c]&&this._insertDrawing([{unitId:a,subUnitId:s,drawingId:c}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===fe.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:a,drawingId:s}=t,o=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(o==null)return;const{scene:c,transformer:u}=o;this._commandService.syncExecuteCommand(ee.id);const l=[];if(e.forEach(p=>{const S=M.getDrawingShapeKeyByDrawingSearch(p),m=c.getObjectIncludeInGroup(S);if(m==null||l.includes(m))return;l.push(m);const{transform:v}=p;v!=null&&(m.classType===I.RENDER_CLASS_TYPE.GROUP?m.transformByState({left:v.left,top:v.top}):m.transformByState(v))}),l.length===0)return;const g=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:a,drawingId:s}),d=new I.Group(g);c.addObject(d,I.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(d),d.addObjects(...l),t.transform&&d.transformByState({left:t.transform.left,top:t.transform.top}),u.clearSelectedObjects(),u.setSelectedControl(d)}_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:a,transformer:s}=n;e.forEach(g=>{const d=M.getDrawingShapeKeyByDrawingSearch(g),p=a.getObjectIncludeInGroup(d);if(p==null)return!0;if(p==null)return;const{transform:S}=g;S!=null&&(p.classType===I.RENDER_CLASS_TYPE.GROUP?p.transformByState({left:S.left,top:S.top}):p.transformByState(S))});const o=M.getDrawingShapeKeyByDrawingSearch(t),c=a.getObject(o),{width:u,height:l}=c;c.getObjects().forEach(g=>{c.removeSelfObjectAndTransform(g.oKey,u,l)}),c.dispose(),s.clearSelectedObjects()}_drawingAlign(r){const{alignType:t}=r,e=this._drawingManagerService.getFocusDrawings();if(t===j.default)return;const n=[];let a=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY,u=0;e.forEach(l=>{const{unitId:g,subUnitId:d,drawingId:p,drawingType:S}=l,m=this._drawingManagerService.getDrawingByParam({unitId:g,subUnitId:d,drawingId:p});if(m==null||m.transform==null)return;n.push({unitId:g,subUnitId:d,drawingId:p,drawingType:S,transform:m.transform});const{left:v=0,top:C=0,width:y=0,height:O=0}=m.transform;a=Math.min(a,v),s=Math.min(s,C),o=Math.max(o,v+y),c=Math.max(c,C+O),u++}),u!==0&&(this._sortDrawingTransform(n,t),this._applyAlignType(n,t,a,s,o,c,u))}_applyAlignType(r,t,e,n,a,s,o){const c=Math.round((a-e)/o*10)/10,u=Math.round((s-n)/o*10)/10,l=[],g=this._getSceneAndTransformerByDrawingSearch(r[0].unitId);if(g==null)return;const{scene:d,transformer:p}=g;r.forEach((S,m)=>{const{unitId:v,subUnitId:C,drawingId:y,transform:O,drawingType:N}=S,{left:R=0,top:b=0,width:T=0,height:E=0}=O;let B=R,P=b;switch(t){case j.left:B=e;break;case j.center:B=e+(a-e)/2-T/2;break;case j.right:B=a-T;break;case j.top:P=n;break;case j.middle:P=n+(s-n)/2-E/2;break;case j.bottom:P=s-E;break;case j.horizon:B=e+c*m;break;case j.vertical:P=n+u*m;break}(B!==R||P!==b)&&l.push({unitId:v,subUnitId:C,drawingId:y,drawingType:N,transform:{left:B,top:P}})}),this._drawingManagerService.featurePluginUpdateNotification(l),p.refreshControls().changeNotification()}_sortDrawingTransform(r,t){r.sort((e,n)=>{const a=e.transform,s=n.transform,{left:o=0,top:c=0,width:u=0,height:l=0}=a,{left:g=0,top:d=0,width:p=0,height:S=0}=s;switch(t){case j.left:return o-g;case j.center:return o+u/2-(g+p/2);case j.right:return o+u-(g+p);case j.top:return c-d;case j.middle:return c+l/2-(d+S/2);case j.bottom:return c+l-(d+S);case j.horizon:return o+u/2-(g+p/2);case j.vertical:return c+l/2-(d+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,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;const{scene:s}=a;n.forEach(o=>{const c=M.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:o}),u=s.fuzzyMathObjects(c,!0);if(u==null||u.length===0)return;const l=this._drawingManagerService.getDrawingOrder(t,e).indexOf(o);for(const g of u)g.setProps({zIndex:l}),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 s=this._getSceneAndTransformerByDrawingSearch(n);if(s==null)return;const{scene:o}=s;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 l;const{unitId:e,subUnitId:n,drawingId:a}=t,s=this._getSceneAndTransformerByDrawingSearch(e);if(s==null)return;const{scene:o}=s,c=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),u=o.fuzzyMathObjects(c,!0);if(u.length>0){for(const g of u)g.dispose();(l=o.getTransformer())==null||l.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(r=>{r.forEach(t=>{var T;const{unitId:e,subUnitId:n,drawingId:a}=t,s=this._drawingManagerService.getDrawingByParam(t);if(s==null)return;const{transform:o,drawingType:c}=s,u=this._getSceneAndTransformerByDrawingSearch(e);if(u==null)return;const{scene:l,transformer:g}=u;if(o==null)return!0;const{left:d=0,top:p=0,width:S=0,height:m=0,angle:v=0,flipX:C=!1,flipY:y=!1,skewX:O=0,skewY:N=0}=o,R=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),b=l.getObject(R);if(b==null)return!0;b.transformByState({left:d,top:p,width:S,height:m,angle:v,flipX:C,flipY:y,skewX:O,skewY:N}),(T=l.getTransformer())==null||T.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(r=>{r.forEach(t=>{const{unitId:e,subUnitId:n,drawingId:a}=t,s=this._getSceneAndTransformerByDrawingSearch(e);if(s==null)return;const o=this._drawingManagerService.getDrawingByParam(t);if(o==null)return;const{transform:c}=o,{scene:u}=s,l=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),g=u.getObject(l);if(g==null||c==null)return!0;const{left:d=0,top:p=0,width:S=0,height:m=0,angle:v=0,flipX:C=!1,flipY:y=!1,skewX:O=0,skewY:N=0}=c;g.transformByState({left:d,top:p,width:S,height:m,angle:v,flipX:C,flipY:y,skewX:O,skewY:N})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(r=>{r.forEach(t=>{const{unitId:e,subUnitId:n,drawingId:a,visible:s}=t,o=this._getSceneAndTransformerByDrawingSearch(e);if(o==null)return;const{scene:c}=o,u=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),l=c.getObject(u);if(l==null)return!0;s?l.show():l.hide()})}))}_filterUpdateParams(r,t){return r.filter((e,n)=>{if(e==null)return!1;const{transform:a}=e;return h.checkIfMove(a,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:a}=n,s=Array.from(a.values()),o=[];e=s.map(c=>{const{left:u,top:l,height:g,width:d,angle:p,oKey:S,isInGroup:m}=c,v=this._drawingManagerService.getDrawingOKey(S);if(m||c instanceof I.Group){let C=c.ancestorGroup;if(C==null&&c instanceof I.Group&&(C=c),C==null)return null;const y=this._drawingManagerService.getDrawingOKey(C.oKey);if(y){const{unitId:O,subUnitId:N,drawingId:R}=y;o.push({unitId:O,subUnitId:N,drawingId:R});const{left:b,top:T,height:E,width:B,angle:P}=C;return{left:b,top:T,height:E,width:B,angle:P}}}else if(v!=null){const{unitId:C,subUnitId:y,drawingId:O}=v;return o.push({unitId:C,subUnitId:y,drawingId:O}),{left:u,top:l,height:g,width:d,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(t.changeEnd$.subscribe(n=>{const{objects:a}=n,s=this._filterUpdateParams(le(a,this._drawingManagerService),e);s.length>0&&this._drawingManagerService.featurePluginUpdateNotification(s)})))}};Se=wt([we(0,h.IUniverInstanceService),we(1,h.ICommandService),we(2,I.IRenderManagerService),we(3,M.IDrawingManagerService)],Se);class ge extends I.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);Q(this,"_srcRect");Q(this,"_prstGeom");Q(this,"_applyTransform");Q(this,"_dragPadding",8);Q(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 c,u;const n=this.getScene().getEngine(),{width:a,height:s}=n;this._initialCacheCanvas(),(c=this._cacheCanvas)==null||c.clear();const o=(u=this._cacheCanvas)==null?void 0:u.getContext();o!=null&&(o.save(),I.Rect.drawWith(o,{left:0,top:0,width:a,height:s,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,a=0;const{left:s=0,top:o=0,width:c=0,height:u=0,angle:l}=this._applyTransform;if(this._srcRect!=null){const{left:p=0,top:S=0,right:m=0,bottom:v=0}=this._srcRect;t=p,e=S,n=m,a=v}const g=s+t,d=o+e;this.transformByState({left:g,top:d,width:s+c-n-g,height:o+u-a-d,angle:l})}_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 I.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 St=Object.getOwnPropertyDescriptor,_t=(i,r,t,e)=>{for(var n=e>1?void 0:e?St(r,t):r,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},se=(i,r)=>(t,e)=>r(t,e,i);let _e=class extends h.Disposable{constructor(r,t,e,n,a,s){super();Q(this,"_sceneListenerOnImageMap",new WeakSet);this._commandService=r,this._drawingManagerService=t,this._renderManagerService=e,this._univerInstanceService=n,this._messageService=a,this._localeService=s,this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id!==ue.id)return;const t=r.params;if(t==null)return;const{cropType:e}=t,n=this._drawingManagerService.getFocusDrawings();if(n.length!==1)return;const a=n[0],{unitId:s,subUnitId:o,drawingId:c}=a,u=this._renderManagerService.getRenderById(s),l=u==null?void 0:u.scene;if(l==null)return!0;this._searchCropObject(l)!=null&&this._commandService.syncExecuteCommand(ee.id,{isAuto:!0});const d=M.getDrawingShapeKeyByDrawingSearch({unitId:s,subUnitId:o,drawingId:c}),p=l.getObject(d);if(!(p instanceof I.Image)){this._messageService.show({type:U.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}p!=null&&(this._updateCropperObject(e,p),this._commandService.executeCommand(me.id,{unitId:s,subUnitId:o,drawingId:c}))}))}_calculateSrcRectByRatio(r,t,e,n,a,s){const o=e/n,c=a/s;let u=e,l=n;o>c?u=n*c:l=e/c;const g=(e-u)/2,d=(n-l)/2;return{left:I.precisionTo(g,1),top:I.precisionTo(d,1),right:I.precisionTo(e-(g+u),1),bottom:I.precisionTo(n-(d+l),1)}}_updateCropperObject(r,t){const{left:e,top:n,width:a,height:s}=t.calculateTransformWithSrcRect();let o;switch(r){case L.R1_1:o=this._calculateSrcRectByRatio(e,n,a,s,1,1);break;case L.R16_9:o=this._calculateSrcRectByRatio(e,n,a,s,16,9);break;case L.R9_16:o=this._calculateSrcRectByRatio(e,n,a,s,9,16);break;case L.R5_4:o=this._calculateSrcRectByRatio(e,n,a,s,5,4);break;case L.R4_5:o=this._calculateSrcRectByRatio(e,n,a,s,4,5);break;case L.R4_3:o=this._calculateSrcRectByRatio(e,n,a,s,4,3);break;case L.R3_4:o=this._calculateSrcRectByRatio(e,n,a,s,3,4);break;case L.R3_2:o=this._calculateSrcRectByRatio(e,n,a,s,3,2);break;case L.R2_3:o=this._calculateSrcRectByRatio(e,n,a,s,2,3);break;case L.FREE:}if(o==null)return;t.setSrcRect(o);const{left:c=0,top:u=0,bottom:l=0,right:g=0}=o;t.transformByStateCloseCropper({left:e+c,top:n+u,width:a-g-c,height:s-l-u})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id!==me.id)return;const t=r.params;if(t==null)return;const{unitId:e,subUnitId:n,drawingId:a}=t,s=this._renderManagerService.getRenderById(e),o=s==null?void 0:s.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:a})==null)return;const u=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),l=o.getObject(u);if(l==null)return;if(!(l instanceof I.Image)){this._messageService.show({type:U.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}const g=o.getTransformer();g==null||g.clearControls();const d=new ge(`${u}-crop`,{srcRect:l.srcRect,prstGeom:l.prstGeom,applyTransform:l.calculateTransformWithSrcRect()});o.addObject(d,l.getLayerIndex()+1).attachTransformerTo(d),g==null||g.createControlForCopper(d),this._addHoverForImageCopper(d),l.openRenderByCropper(),g==null||g.refreshControls(),d.makeDirty(!0),this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:a}])}))}_searchCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof ge)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==ee.id)return;const e=this._univerInstanceService.getFocusedUnit();if(e==null)return;const n=e.getUnitId(),a=this._renderManagerService.getRenderById(n),s=a==null?void 0:a.scene;if(s==null)return!0;const o=this._searchCropObject(s);if(o==null)return;const c=this._getApplyObjectByCropObject(o);if(c==null)return;const u=s.getTransformerByCreate();u.detachFrom(o),u.clearCopperControl();const l=this._getSrcRectByTransformState(c,o),g=this._drawingManagerService.getDrawingOKey(c.oKey);if(g!=null){const{left:d,top:p,height:S,width:m}=o;this._drawingManagerService.featurePluginUpdateNotification([{...g,transform:{...g.transform,left:d,top:p,height:S,width:m},srcRect:l.srcRectAngle}])}c.setSrcRect({...l.srcRectAngle}),c.closeRenderByCropper(),c.makeDirty(!0),o==null||o.dispose()}));const r=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET).pipe(Me.switchMap(t=>t?t.activeSheet$:Me.of(null)));this.disposeWithMe(r.subscribe(()=>{this._commandService.syncExecuteCommand(ee.id)}))}_getApplyObjectByCropObject(r){const t=r.oKey,e=t.slice(0,t.length-5),n=r.getScene();if(!n)return null;const a=n.getObject(e);return a==null?null:a}_addListenerOnImage(r){const t=r.getTransformerByCreate();let e=null;this.disposeWithMe(t.changeStart$.subscribe(n=>{const{objects:a}=n,s=a.values().next().value;if(s==null||!(s instanceof ge))return;const{left:o,top:c,height:u,width:l,angle:g}=s;e={left:o,top:c,height:u,width:l,angle:g},t.clearCopperControl()})),this.disposeWithMe(t.changeEnd$.subscribe(n=>{const{objects:a}=n,s=a.values().next().value;if(s==null||!(s instanceof ge))return;const{left:o,top:c,height:u,width:l,angle:g}=s;if(!h.checkIfMove({left:o,top:c,height:u,width:l,angle:g},e))return;const d=this._getApplyObjectByCropObject(s);if(d==null)return;const p=this._getSrcRectByTransformState(d,s);s.refreshSrcRect(p.srcRect,d.getState()),t.createControlForCopper(s)})),this._endCropListener(r)}_addHoverForImageCopper(r){this.disposeWithMe(r.onPointerEnter$.subscribeEvent(()=>{r.cursor=I.CURSOR_TYPE.MOVE})),this.disposeWithMe(r.onPointerLeave$.subscribeEvent(()=>{r.cursor=I.CURSOR_TYPE.DEFAULT}))}_endCropListener(r){const t=r.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(ee.id)}))}_getSrcRectByTransformState(r,t){const{left:e,top:n,height:a,width:s,strokeWidth:o,angle:c}=t,{left:u,top:l,width:g,height:d,angle:p,strokeWidth:S}=r,m=e-u,v=n-l,C={left:m,top:v,right:g-m-s,bottom:d-v-a},y={...C};if(p!==0){const O=e+s/2,N=n+a/2,R=new I.Vector2(O,N),b=g/2+u,T=d/2+l,E=new I.Vector2(b,T),B=new I.Vector2(u,l);B.rotateByPoint(I.degToRad(p),E);const P=B.clone();P.rotateByPoint(I.degToRad(-p),R);const G=e-P.x,H=n-P.y;y.left=G,y.top=H,y.right=g-G-s,y.bottom=d-H-a}return{srcRect:C,srcRectAngle:y}}};_e=_t([se(0,h.ICommandService),se(1,M.IDrawingManagerService),se(2,I.IRenderManagerService),se(3,h.IUniverInstanceService),se(4,x.IMessageService),se(5,h.Inject(h.LocaleService))],_e);var Ct=Object.getOwnPropertyDescriptor,yt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ct(r,t):r,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},re=(i,r)=>(t,e)=>r(t,e,i);let Ce=class extends h.Disposable{constructor(i,r,t,e,n,a,s){super(),this._commandService=i,this._renderManagerService=r,this._drawingManagerService=t,this._dialogService=e,this._imageIoService=n,this._currentUniverService=a,this._drawingRenderService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===Ie.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:a,drawingId:s}=e,o=this._getSceneAndTransformerByDrawingSearch(n);if(o==null)return;const{scene:c}=o,u=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:a,drawingId:s}),l=c.getObject(u);if(l==null)return!0;const g=this._drawingManagerService.getDrawingByParam(e);if(g==null)return!0;if(g.drawingType!==h.DrawingTypeEnum.DRAWING_IMAGE)return;l.resetSize();const{width:d,height:p}=l.getNativeSize();t.includes(c)===!1&&t.push(c),r.push({...g,transform:{...g.transform,height:p,width:d,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(r),t.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,i)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(i=>{this._insertImages(i)}))}_insertImages(i){i.forEach(async r=>{var c;const{unitId:t,subUnitId:e}=r,n=this._getSceneAndTransformerByDrawingSearch(t),a=(c=Ee(this._currentUniverService,t))==null?void 0:c.subUnitId;if(n==null||a!==e)return;const s=this._drawingManagerService.getDrawingByParam(r);if(s==null)return;const o=await this._drawingRenderService.renderImages(s,n.scene);if(this._drawingManagerService.refreshTransform([s]),!(o==null||o.length===0))for(const u of o)this._addHoverForImage(u),this._addDialogForImage(u)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(i=>{i.forEach(r=>{const{unitId:t,subUnitId:e,drawingId:n}=r,a=this._drawingManagerService.getDrawingByParam(r);if(a==null)return;const{transform:s,drawingType:o,srcRect:c,prstGeom:u,source:l,imageSourceType:g}=a;if(o!==h.DrawingTypeEnum.DRAWING_IMAGE)return;const d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;const{scene:p,transformer:S}=d;if(s==null)return!0;const m=M.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),v=p.getObject(m);if(v==null)return!0;v.setSrcRect(c),v.setPrstGeom(u),l!=null&&l.length>0&&(g===h.ImageSourceType.BASE64||g===h.ImageSourceType.URL)&&v.changeSource(l)})}))}_addHoverForImage(i){this.disposeWithMe(h.toDisposable(i.onPointerEnter$.subscribeEvent(()=>{i.cursor=I.CURSOR_TYPE.GRAB}))),this.disposeWithMe(h.toDisposable(i.onPointerLeave$.subscribeEvent(()=>{i.cursor=I.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)})))}};Ce=yt([re(0,h.ICommandService),re(1,I.IRenderManagerService),re(2,M.IDrawingManagerService),re(3,x.IDialogService),re(4,M.IImageIoService),re(5,h.IUniverInstanceService),re(6,h.Inject(D.DrawingRenderService))],Ce);var It=Object.getOwnPropertyDescriptor,bt=(i,r,t,e)=>{for(var n=e>1?void 0:e?It(r,t):r,a=i.length-1,s;a>=0;a--)(s=i[a])&&(n=s(n)||n);return n},We=(i,r)=>(t,e)=>r(t,e,i);const Dt="UNIVER_DRAWING_UI_PLUGIN";D.UniverDrawingUIPlugin=(be=class extends h.Plugin{constructor(r=Ge,t,e){super(),this._config=r,this._injector=t,this._configService=e;const{menu:n,...a}=h.merge({},Ge,this._config);n&&this._configService.setConfig("menu",n,{merge:!0}),this._configService.setConfig(ft,a)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(Se),this._injector.get(ve),this._injector.get(_e),this._injector.get(Ce)}_initDependencies(){[[D.DrawingRenderService],[Se],[ve],[_e],[Ce]].forEach(t=>this._injector.add(t))}},Q(be,"pluginName",Dt),be),D.UniverDrawingUIPlugin=bt([We(1,h.Inject(h.Injector)),We(2,h.IConfigService)],D.UniverDrawingUIPlugin),D.AutoImageCropOperation=ue,D.COMPONENT_IMAGE_POPUP_MENU=ke,D.CloseImageCropOperation=ee,D.DrawingCommonPanel=ht,D.ImageCropperObject=ge,D.ImagePopupMenu=He,D.ImageResetSizeOperation=Ie,D.OpenImageCropOperation=me,D.SetDrawingAlignOperation=fe,D.getUpdateParams=le,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
7
7
 
8
8
 
9
9
  // @univerjs/sheets-drawing/index
@@ -11,8 +11,8 @@
11
11
 
12
12
 
13
13
  // @univerjs/sheets-drawing-ui/index
14
- (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,z,b,B,P,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(I=>{const{unitId:T}=I;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(P.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(P.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:z.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(b.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(P.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(b.HoverManagerService)),Le(2,c.Inject(C.SheetsSelectionsService)),Le(3,c.Inject(ge.DrawingRenderService)),Le(4,c.Inject(b.SheetSkeletonManagerService))],dt);function q(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=b.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.sheetTransform&&(n.transform=q(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(b.ISheetSelectionRenderService)),Fe(4,c.Inject(b.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(I=>I.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}},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(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(b.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:z.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:z.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:z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:z.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:q(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 I=R.message;I===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(j.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):I===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):I===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:z.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=b.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,...q(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};e.push(p)}),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(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(b.SheetSkeletonManagerService)),Q(2,c.ICommandService),Q(3,b.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(b.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(b.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},be=(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(b.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(b.SetCellEditVisibleOperation.id,{visible:!1})};((t=o.getBody())==null?void 0:t.dataStream)===`\r
15
- `?(this._commandService.syncExecuteCommand(b.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([be(0,c.ICommandService),be(1,c.IUniverInstanceService),be(2,B.IDialogService),be(3,W.IRenderManagerService),be(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=[b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,b.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===b.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=b.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},b.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.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(b.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:I,drawingStartY:T,drawingEndY:y}={drawingStartX:w,drawingEndX:w+_,drawingStartY:v,drawingEndY:v+D};s<=R&&I<=a&&l<=T&&y<=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(b.SheetSkeletonManagerService),u=l==null?void 0:l.with(b.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=d,h=b.discreteRangeToRange(a);return this._generateMutations(p,{unitId:o,subUnitId:s,isCut:t===b.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(b.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:b.discreteRangeToRange(s)},pasteType:o},l);const{ranges:[d,p],mapFunc:h}=b.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,I=D.startY-_.startY,T=w-f,y=v-S;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(E,N)=>{var k,A;return{transform:{...E,left:((k=E==null?void 0:E.left)!=null?k:0)+R,top:((A=E==null?void 0:E.top)!=null?A:0)+I},sheetTransform:{...N,to:{...N.to,row:N.to.row+T,column:N.to.column+y},from:{...N.from,row:N.from.row+T,column:N.from.column+y}}}},isCut:l===b.COPY_TYPE.CUT})}};Ve=sn([Ae(0,b.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=P.combineLatest([i,r]);this.disposeWithMe(t.pipe(P.switchMap(([e,n])=>e?e.activeSheet$.pipe(P.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),P.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=P.combineLatest([i,r]);this.disposeWithMe(t.pipe(P.switchMap(([e,n])=>e?e.activeSheet$.pipe(P.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),P.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(P.combineLatest([i,r]).pipe(P.switchMap(([t,e])=>t?t.activeSheet$.pipe(P.switchMap(n=>{if(!n)return P.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),l=a==null?void 0:a.scene;if(!l)return P.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookViewPermission(o).id,new C.WorksheetViewPermission(o,s).id]).pipe(P.map(d=>d.every(p=>p.value)),P.distinctUntilChanged()).pipe(P.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:s})))})):P.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(P.combineLatest([i,r]).pipe(P.switchMap(([t,e])=>t?t.activeSheet$.pipe(P.switchMap(n=>{if(!n)return P.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),l=a==null?void 0:a.scene;if(!l)return P.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookEditablePermission(o).id,new C.WorksheetEditPermission(o,s).id]).pipe(P.map(d=>d.every(p=>p.value)),P.distinctUntilChanged()).pipe(P.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:s})))})):P.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 Et(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:I,viewportScrollY:T}=l;const{boundsOfViewArea:y,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:E,columnHeaderHeight:N}=t,k={top:o?0:N,left:o?0:E};y&&(c.Tools.isDefine(k.top)&&(k.top=y.top),c.Tools.isDefine(k.left)&&(k.left=y.left)),U==="HORIZONTAL"&&(T=0),U==="VERTICAL"&&(I=0);let A=0,M=0;const Y=t.rowStartY(d-h)+N,$=t.colStartX(u-p)+E,J=t.rowStartY(d)+N,te=t.colStartX(u)+E;if(p===0)f.left=!1,A=(S-I)*s,M=(w-I)*s;else{const K=S-($-E),L=w-($-E);w<te?(A=K*s,M=L*s):S<=te&&w>=te?(A=K*s,M=Math.max(R,(w-I)*s)):S>te&&(f.left=!1,A=Math.max((S-I)*s,R),M=Math.max((w-I)*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-N),L=_-(Y-N);_<J?(X=K*a,x=L*a):v<=J&&_>=J?(X=K*a,x=Math.max(D,(_-T)*a)):v>J&&(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=Et(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 P.Subject);ie(this,"transformChange$",this._transformChange$.asObservable());ie(this,"_add$",new P.Subject);ie(this,"add$",this._add$.asObservable());ie(this,"_remove$",new P.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(P.filter(t=>t===c.LifecycleStages.Rendered),P.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(b.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:I,angle:T,flipX:y,flipY:U,skewX:E,skewY:N}=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:I,angle:T,flipX:y,flipY:U,skewX:E,skewY:N});return}const M={left:_,top:D,width:R,height:I,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 J=new c.DisposableCollection,te=ae($,S.renderUnit.scene,d.skeleton,a.worksheet),X=new P.BehaviorSubject(te),x={dispose:J,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)});J.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),ne&&J.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(b.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(P.switchMap(e=>e?e.activeSheet$:P.of(null)),P.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}),P.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(P.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):P.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===b.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(b.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 y,U,E;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=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(b.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(),I=Ke(w,n,R),T={unitId:a,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:f};{const{unitId:N,subUnitId:k,drawingId:A}=T,M=C.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:k}),Y=T,$=this._univerInstanceService.getUnit(N,c.UniverInstanceType.UNIVER_SHEET);if(!$)return;const J=$.getActiveSheet().getSheetId();if(!Y||!M)return;const te=(U=this._renderManagerService.getRenderById(N))==null?void 0:U.with(b.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(N);if(L==null)return;const{scene:Ie,canvas:ye}=L;if(x==null||J!==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:N,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(N,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:N,subUnitId:k},V=ae(de,L.renderUnit.scene,X.skeleton,M.worksheet,ue),Te=new P.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:N};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:N,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(N,k).length-1}),Xn=ae(Vn,L.renderUnit.scene,X.skeleton,M.worksheet,ue);Te.next(Xn)}));const We=(E=this._renderManagerService.getRenderById(N))==null?void 0:E.with(b.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 I,T,y;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=(I=this._renderManagerService.getRenderById(a))==null?void 0:I.with(b.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:E,drawingId:N}=R,k=C.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:E}),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(b.SheetSkeletonManagerService);if(!$)return;const J=$.getWorksheetSkeleton(E);if(!J)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!==E)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:E,drawingId:N}),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,E).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:E,boundsOfViewArea:de,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},it=ae(ce,x.renderUnit.scene,J.skeleton,k.worksheet,le),Me=new P.BehaviorSubject(it);le.position$=Me;let ke={position$:Me,id:N,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,J.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:E,drawingId:N}),We=new W.Rect(je,{left:Te.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,E).length-1}),st=ae(We,x.renderUnit.scene,J.skeleton,k.worksheet,le);Me.next(st)}));const ue=(y=this._renderManagerService.getRenderById(U))==null?void 0:y.with(b.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(V=>{V&&d.sheetId!==V.sheetId&&this._removeDom(S,!0)}),re.add(()=>{this._canvasFloatDomService.removeFloatDom(N)}),ot&&re.add(ot),this._domLayerInfoMap.set(N,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 P.BehaviorSubject(a),g=Pe(t.endRow,t.endColumn,n),u=new P.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===b.SetScrollOperation.id||v.id===b.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(P.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=Et({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 P.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(b.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 z.render(Z.jsx(l,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{z.unmount(r.root)}),t(i)}}}))}};ze=fn([fe(0,c.Inject(b.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 I=null,T=null;if(r===0&&h>=v&&S<=_)if(f>=D&&w<=R)n.push({unitId:l,subUnitId:g,drawingId:u});else{const y=this._shrinkCol(o,a,D,R,s);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}else if(r===1&&f>=D&&w<=R)if(h>=v&&S<=_)n.push({unitId:l,subUnitId:g,drawingId:u});else{const y=this._shrinkRow(o,a,v,_,s);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}else if(r===2){const y=this._expandRow(o,a,v,_,s);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}else if(r===3){const y=this._expandCol(o,a,D,R,s);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}if(I!=null&&T!=null){const y=q(I,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:I,transform:y})}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 I=0;I<t.length;I++){const T=t[I],{startRow:y,endRow:U,startColumn:E,endColumn:N}=T;if(R<E)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(_>=E&&_<=N){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:N,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(_>=E&&R<=N)continue;let k=null,A=null;if(_>=E&&_<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:_,endColumn:N,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>=E&&R<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,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:E,endColumn:N,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 I=0;I<t.length;I++){const T=t[I],{startRow:y,endRow:U,startColumn:E,endColumn:N}=T;if(D<y)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(v>=y&&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>=y&&D<=U)continue;let k=null,A=null;if(v>=y&&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>=y&&D<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:y,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:y,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:I,endColumn:T}=_;if(S<D||w<I)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=D&&S>=R||f<=I&&w>=T)){this._remainDrawingSize(g,o,a);continue}const y=q({...l},this._selectionRenderService,this._skeletonManagerService);if(y!=null){o.push({...a,transform:y});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(b.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=b.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(I=>{const T=p[I];if(T.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:y}=T;if(!y)return;const{left:U=0,top:E=0,width:N=0,height:k=0}=y,{drawingStartX:A,drawingEndX:M,drawingStartY:Y,drawingEndY:$}={drawingStartX:U,drawingEndX:U+N,drawingStartY:E,drawingEndY:E+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(I=>{const T=I.sheetTransform,y={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=q(y,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:I.drawingId,transform:U,sheetTransform:y}});if(_.length){const I=this._sheetDrawingService.getBatchUpdateOp(_),{undo:T,redo:y,objects:U}=I;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:y,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 I=this._expandRow(S,w,s,a,v);_=I==null?void 0:I.newSheetTransform,D=I==null?void 0:I.newTransform}else{const{from:I,to:T}=S,{row:y}=I,{row:U}=T;if(v===m.SheetDrawingAnchorType.Both&&y>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkRow(S,w,s,a,v);_=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.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 I=this._expandCol(S,w,s,a,v);_=I==null?void 0:I.newSheetTransform,D=I==null?void 0:I.newTransform}else{const{from:I,to:T}=S,{column:y}=I,{column:U}=T;if(v===m.SheetDrawingAnchorType.Both&&y>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkCol(S,w,s,a,v);_=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.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=q(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=q(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=q(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=q(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=q(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=q(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=q(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=q(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=q(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:I}=v;if(c.Rectangle.intersects({startRow:_,endRow:D,startColumn:R,endColumn:I},{startRow:p,endRow:f,startColumn:h,endColumn:S})||p>D||h>I){const T=g===m.SheetDrawingAnchorType.Position,y=q(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...y,width:T?l==null?void 0:l.width:y==null?void 0:y.width,height:T?l==null?void 0:l.height:y==null?void 0:y.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,b.ISheetSelectionRenderService),he(4,c.Inject(b.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},bt=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)}bt.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(bt,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(b.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(Ee.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$:b.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 En(i){return{id:mt.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}const bn=i=>{var _;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=(_=s.anchorType)!=null?_:m.SheetDrawingAnchorType.Position,[f,S]=oe.useState(h);function w(D,R){const I=[];return D.forEach(T=>{const{oKey:y}=T,U=R.getDrawingOKey(y);if(U==null)return I.push(null),!0;const{unitId:E,subUnitId:N,drawingId:k,drawingType:A,anchorType:M,sheetTransform:Y}=U;I.push({unitId:E,subUnitId:N,drawingId:k,anchorType:M,sheetTransform:Y,drawingType:A})}),I}oe.useEffect(()=>{const D=u.clearControl$.subscribe(I=>{I===!0&&p(!1)}),R=u.changeStart$.subscribe(I=>{var U;const{objects:T}=I,y=w(T,e);if(y.length===0)p(!1);else if(y.length>=1){p(!0);const E=((U=y[0])==null?void 0:U.anchorType)||m.SheetDrawingAnchorType.Position;S(E)}});return()=>{R.unsubscribe(),D.unsubscribe()}},[]);function v(D){S(D);const R=e.getFocusDrawings();if(R.length===0)return;const I=R.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:D}));r.executeCommand(Ee.id,{unitId:R[0].unitId,drawings:I})}return Z.jsxs("div",{className:z.clsx("univer-relative univer-mt-5 univer-w-full",z.borderTopClassName,{"univer-hidden":!d}),children:[Z.jsx("div",{className:"univer-relative univer-mt-2.5 univer-flex univer-h-full",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:"univer-relative univer-mt-2.5 univer-flex univer-h-full",children:Z.jsx("div",{className:"univer-flex univer-items-center univer-gap-1",children:Z.jsxs(z.RadioGroup,{value:f,onChange:v,direction:"vertical",children:[Z.jsx(z.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),Z.jsx(z.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),Z.jsx(z.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(bn,{drawings:t})]})},An={[B.RibbonStartGroup.FORMULAS_INSERT]:{[wt]:{order:3,menuItemFactory:Tn,[Oe.id]:{order:0,menuItemFactory:Rn},[mt.id]:{order:1,menuItemFactory:En}}}};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,Ee,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=Ee,O.SidebarSheetDrawingOperation=at,O.UngroupSheetDrawingCommand=ht,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
14
+ (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,Z,b,B,P,C,Be,J,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 v,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(I=>{const{unitId:T}=I;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([...(v=f.preRedos)!=null?v:[],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(P.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(P.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:Z.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(b.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(P.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(b.HoverManagerService)),Le(2,c.Inject(C.SheetsSelectionsService)),Le(3,c.Inject(ge.DrawingRenderService)),Le(4,c.Inject(b.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=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:S}=d;const w=t.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,v=w.columnHeaderHeight+w.rowTotalHeight;return p+f>_&&(p=_-f),h+S>v&&(h=v-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.sheetTransform&&(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(b.ISheetSelectionRenderService)),Fe(4,c.Inject(b.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 v,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(I=>I.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([...(v=f.preRedos)!=null?v:[],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}},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(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 v;const{rotatedHeight:o,rotatedWidth:s}=Zt(t,e,n),l=i.get(W.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(v=l.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:v.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,_=!w||Number.isNaN(w)?.001:w;return{width:t*_,height:e*_}}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:Z.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:Z.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:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.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 _=this._getImagePosition(d*w,p*w,f,S);if(_==null)return;const v={unitId:o,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:g,transform:z(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Re.id,{unitId:o,drawings:[v]})}async _insertCellImage(t,e){var v,D;let n;try{n=await this._imageIoService.saveImage(t)}catch(R){const I=R.message;I===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(j.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):I===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):I===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.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},_=c.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[w],selection:{collapsed:!0,startOffset:0,endOffset:0}});return _?(h.apply(_),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(v=e==null?void 0:e.row)!=null?v: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=b.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 _=this._selectionRenderService.getCellWithCoordByOffset(d,p);if(_==null)return;d=_.startX,p=_.startY,g=_.actualColumn,u=_.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(Ee.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(b.SheetSkeletonManagerService)),Q(2,c.ICommandService),Q(3,b.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(b.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(b.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},be=(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(b.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(b.SetCellEditVisibleOperation.id,{visible:!1})};((t=o.getBody())==null?void 0:t.dataStream)===`\r
15
+ `?(this._commandService.syncExecuteCommand(b.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([be(0,c.ICommandService),be(1,c.IUniverInstanceService),be(2,B.IDialogService),be(3,W.IRenderManagerService),be(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=[b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,b.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===b.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=b.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},b.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.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(b.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:_=0,width:v=0,height:D=0}=S,{drawingStartX:R,drawingEndX:I,drawingStartY:T,drawingEndY:y}={drawingStartX:w,drawingEndX:w+v,drawingStartY:_,drawingEndY:_+D};s<=R&&I<=a&&l<=T&&y<=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(b.SheetSkeletonManagerService),u=l==null?void 0:l.with(b.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=d,h=b.discreteRangeToRange(a);return this._generateMutations(p,{unitId:o,subUnitId:s,isCut:t===b.COPY_TYPE.CUT,getTransform:(f,S)=>{var v;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...f,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:_,sheetTransform:(v=H(_,u))!=null?v: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:_}=g.getBatchUpdateOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}}),l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:_}})}else{const{undo:S,redo:w,objects:_}=g.getBatchAddOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),l.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:_,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(b.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:b.discreteRangeToRange(s)},pasteType:o},l);const{ranges:[d,p],mapFunc:h}=b.virtualizeDiscreteRanges([a,s]),{row:f,col:S}=h(d.startRow,d.startColumn),{row:w,col:_}=h(p.startRow,p.startColumn),v=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),D=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:_,endColumn:_});if(!v||!D||!this._copyInfo)return{redos:[],undos:[]};const R=D.startX-v.startX,I=D.startY-v.startY,T=w-f,y=_-S;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(E,N)=>{var k,A;return{transform:{...E,left:((k=E==null?void 0:E.left)!=null?k:0)+R,top:((A=E==null?void 0:E.top)!=null?A:0)+I},sheetTransform:{...N,to:{...N.to,row:N.to.row+T,column:N.to.column+y},from:{...N.from,row:N.from.row+T,column:N.from.column+y}}}},isCut:l===b.COPY_TYPE.CUT})}};Ve=sn([Ae(0,b.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=P.combineLatest([i,r]);this.disposeWithMe(t.pipe(P.switchMap(([e,n])=>e?e.activeSheet$.pipe(P.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),P.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=P.combineLatest([i,r]);this.disposeWithMe(t.pipe(P.switchMap(([e,n])=>e?e.activeSheet$.pipe(P.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),P.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(P.combineLatest([i,r]).pipe(P.switchMap(([t,e])=>t?t.activeSheet$.pipe(P.switchMap(n=>{if(!n)return P.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),l=a==null?void 0:a.scene;if(!l)return P.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookViewPermission(o).id,new C.WorksheetViewPermission(o,s).id]).pipe(P.map(d=>d.every(p=>p.value)),P.distinctUntilChanged()).pipe(P.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:s})))})):P.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(P.combineLatest([i,r]).pipe(P.switchMap(([t,e])=>t?t.activeSheet$.pipe(P.switchMap(n=>{if(!n)return P.EMPTY;const o=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),l=a==null?void 0:a.scene;if(!l)return P.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new C.WorkbookEditablePermission(o).id,new C.WorksheetEditPermission(o,s).id]).pipe(P.map(d=>d.every(p=>p.value)),P.distinctUntilChanged()).pipe(P.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:s})))})):P.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 Et(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:_,bottom:v}=i;let{top:D,left:R,viewportScrollX:I,viewportScrollY:T}=l;const{boundsOfViewArea:y,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:E,columnHeaderHeight:N}=t,k={top:o?0:N,left:o?0:E};y&&(c.Tools.isDefine(k.top)&&(k.top=y.top),c.Tools.isDefine(k.left)&&(k.left=y.left)),U==="HORIZONTAL"&&(T=0),U==="VERTICAL"&&(I=0);let A=0,M=0;const Y=t.rowStartY(d-h)+N,$=t.colStartX(u-p)+E,q=t.rowStartY(d)+N,te=t.colStartX(u)+E;if(p===0)f.left=!1,A=(S-I)*s,M=(w-I)*s;else{const K=S-($-E),L=w-($-E);w<te?(A=K*s,M=L*s):S<=te&&w>=te?(A=K*s,M=Math.max(R,(w-I)*s)):S>te&&(f.left=!1,A=Math.max((S-I)*s,R),M=Math.max((w-I)*s,R))}let X=0,x=0;if(h===0)f.top=!1,X=(_-T)*a,x=(v-T)*a;else{const K=_-(Y-N),L=v-(Y-N);v<q?(X=K*a,x=L*a):_<=q&&v>=q?(X=K*a,x=Math.max(D,(v-T)*a)):_>q&&(f.top=!1,X=Math.max((_-T)*a,D),x=Math.max((v-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=Et(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 P.Subject);ie(this,"transformChange$",this._transformChange$.asObservable());ie(this,"_add$",new P.Subject);ie(this,"add$",this._add$.asObservable());ie(this,"_remove$",new P.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(P.filter(t=>t===c.LifecycleStages.Rendered),P.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(b.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:_}=S;if(p==null)return!0;if(u!==o)return;const{left:v,top:D,width:R,height:I,angle:T,flipX:y,flipY:U,skewX:E,skewY:N}=p,k=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),A=w.getObject(k);if(A!=null){A.transformByState({left:v,top:D,width:R,height:I,angle:T,flipX:y,flipY:U,skewX:E,skewY:N});return}const M={left:v,top:D,width:R,height:I,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 P.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=>{_.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{_.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{_.dispatchEvent(new PointerEvent(L.type,L))},onWheel:L=>{_.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(b.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(P.switchMap(e=>e?e.activeSheet$:P.of(null)),P.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}),P.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(W.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(P.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):P.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===b.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(b.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 y,U,E;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=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver(t,u,d.skeleton);if(this._getPosition(w,a)==null)return;const D=g.scene,{scaleX:R}=D.getAncestorScale(),I=Ke(w,n,R),T={unitId:a,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:f};{const{unitId:N,subUnitId:k,drawingId:A}=T,M=C.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:k}),Y=T,$=this._univerInstanceService.getUnit(N,c.UniverInstanceType.UNIVER_SHEET);if(!$)return;const q=$.getActiveSheet().getSheetId();if(!Y||!M)return;const te=(U=this._renderManagerService.getRenderById(N))==null?void 0:U.with(b.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(N);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:vt,flipX:It,flipY:tt,skewX:nt,skewY:Ce}=x,rt=j.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:k,drawingId:A}),ce=Ie.getObject(rt);if(ce!=null){ce.transformByState({left:qe,top:Je,width:Qe,height:et,angle:vt,flipX:It,flipY:tt,skewX:nt,skewY:Ce});return}const re={left:qe,top:Je,width:Qe,height:et,zIndex:this._drawingManagerService.getDrawingOrder(N,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:N,subUnitId:k},V=ae(de,L.renderUnit.scene,X.skeleton,M.worksheet,ue),Te=new P.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:N};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(_.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:N,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(N,k).length-1}),Xn=ae(Vn,L.renderUnit.scene,X.skeleton,M.worksheet,ue);Te.next(Xn)}));const We=(E=this._renderManagerService.getRenderById(N))==null?void 0:E.with(b.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 I,T,y;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=(I=this._renderManagerService.getRenderById(a))==null?void 0:I.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),v=w;if(v.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:v.startX,top:v.startY,width:v.width,height:v.height},data:h,allowTransform:f};{const{unitId:U,subUnitId:E,drawingId:N}=R,k=C.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:E}),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(b.SheetSkeletonManagerService);if(!$)return;const q=$.getWorksheetSkeleton(E);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!==E)return;const{left:L,top:Ie,width:ye,height:qe,angle:Je,flipX:Qe,flipY:et,skewX:vt,skewY:It}=te,tt=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:E,drawingId:N}),nt=ne.getObject(tt);if(nt!=null){nt.transformByState({left:L,top:Ie,width:ye,height:qe,angle:Je,flipX:Qe,flipY:et,skewX:vt,skewY:It});return}const Ce=Ke({startX:v.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,E).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:E,boundsOfViewArea:de,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},it=ae(ce,x.renderUnit.scene,q.skeleton,k.worksheet,le),Me=new P.BehaviorSubject(it);le.position$=Me;let ke={position$:Me,id:N,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(_.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:E,drawingId:N}),We=new W.Rect(je,{left:Te.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,E).length-1}),st=ae(We,x.renderUnit.scene,q.skeleton,k.worksheet,le);Me.next(st)}));const ue=(y=this._renderManagerService.getRenderById(U))==null?void 0:y.with(b.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(V=>{V&&d.sheetId!==V.sheetId&&this._removeDom(S,!0)}),re.add(()=>{this._canvasFloatDomService.removeFloatDom(N)}),ot&&re.add(ot),this._domLayerInfoMap.set(N,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 P.BehaviorSubject(a),g=Pe(t.endRow,t.endColumn,n),u=new P.BehaviorSubject(g),d=()=>{const _=Pe(o,s,n),v=Pe(t.endRow,t.endColumn,n);l.next(_),u.next(v)},p=new c.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>d())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===C.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(D=>D.row===o)>-1){d();return}(C.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===b.SetScrollOperation.id||_.id===b.SetZoomRatioOperation.id)&&d()}));const h=(_,v)=>{o=_,s=v,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(P.map(_=>{const v=Pe(t.endRow,t.endColumn,n);return{rotate:0,width:v.right-_.left,height:v.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:v.right,endY:v.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=Et({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 P.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 J.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([s,a])=>J.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(b.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 Z.render(J.jsx(l,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{Z.unmount(r.root)}),t(i)}}}))}};ze=fn([fe(0,c.Inject(b.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 _n=[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],vn=[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(!_n.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:_,endRow:v,startColumn:D,endColumn:R}=i;let I=null,T=null;if(r===0&&h>=_&&S<=v)if(f>=D&&w<=R)n.push({unitId:l,subUnitId:g,drawingId:u});else{const y=this._shrinkCol(o,a,D,R,s);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}else if(r===1&&f>=D&&w<=R)if(h>=_&&S<=v)n.push({unitId:l,subUnitId:g,drawingId:u});else{const y=this._shrinkRow(o,a,_,v,s);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}else if(r===2){const y=this._expandRow(o,a,_,v,s);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}else if(r===3){const y=this._expandCol(o,a,D,R,s);I=y==null?void 0:y.newSheetTransform,T=y==null?void 0:y.newTransform}if(I!=null&&T!=null){const y=z(I,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:I,transform:y})}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:_,column:v}=S,{row:D,column:R}=w;for(let I=0;I<t.length;I++){const T=t[I],{startRow:y,endRow:U,startColumn:E,endColumn:N}=T;if(R<E)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(v>=E&&v<=N){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:v,endColumn:N,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(v>=E&&R<=N)continue;let k=null,A=null;if(v>=E&&v<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:v,endColumn:N,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>=E&&R<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,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:E,endColumn:N,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:_,column:v}=S,{row:D,column:R}=w;for(let I=0;I<t.length;I++){const T=t[I],{startRow:y,endRow:U,startColumn:E,endColumn:N}=T;if(D<y)continue;if(f===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(_>=y&&_<=U){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,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(_>=y&&D<=U)continue;let k=null,A=null;if(_>=y&&_<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,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>=y&&D<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:y,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:y,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 _=0;_<t.length;_++){const v=t[_],{startRow:D,endRow:R,startColumn:I,endColumn:T}=v;if(S<D||w<I)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=D&&S>=R||f<=I&&w>=T)){this._remainDrawingSize(g,o,a);continue}const y=z({...l},this._selectionRenderService,this._skeletonManagerService);if(y!=null){o.push({...a,transform:y});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(b.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=b.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(I=>{const T=p[I];if(T.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:y}=T;if(!y)return;const{left:U=0,top:E=0,width:N=0,height:k=0}=y,{drawingStartX:A,drawingEndX:M,drawingStartY:Y,drawingEndY:$}={drawingStartX:U,drawingEndX:U+N,drawingStartY:E,drawingEndY:E+k};l<=A&&M<=g&&u<=Y&&$<=d&&h.push(T)});const f=[],S=[],w=r.startRow-t.startRow,_=r.startColumn-t.startColumn,v=h.map(I=>{const T=I.sheetTransform,y={to:{...T.to,row:T.to.row+w,column:T.to.column+_},from:{...T.from,row:T.from.row+w,column:T.from.column+_}},U=z(y,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:I.drawingId,transform:U,sheetTransform:y}});if(v.length){const I=this._sheetDrawingService.getBatchUpdateOp(v),{undo:T,redo:y,objects:U}=I;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:y,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:_=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let v,D;if(r==="insert"){const I=this._expandRow(S,w,s,a,_);v=I==null?void 0:I.newSheetTransform,D=I==null?void 0:I.newTransform}else{const{from:I,to:T}=S,{row:y}=I,{row:U}=T;if(_===m.SheetDrawingAnchorType.Both&&y>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkRow(S,w,s,a,_);v=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.newTransform}}if(!v||!D)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:v};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:_=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let v,D;if(r==="insert"){const I=this._expandCol(S,w,s,a,_);v=I==null?void 0:I.newSheetTransform,D=I==null?void 0:I.newTransform}else{const{from:I,to:T}=S,{column:y}=I,{column:U}=T;if(_===m.SheetDrawingAnchorType.Both&&y>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkCol(S,w,s,a,_);v=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.newTransform}}if(!v||!D)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:v};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=>{vn.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 _=t[w],{startRow:v,endRow:D,startColumn:R,endColumn:I}=_;if(c.Rectangle.intersects({startRow:v,endRow:D,startColumn:R,endColumn:I},{startRow:p,endRow:f,startColumn:h,endColumn:S})||p>D||h>I){const T=g===m.SheetDrawingAnchorType.Position,y=z(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...y,width:T?l==null?void 0:l.width:y==null?void 0:y.width,height:T?l==null?void 0:l.height:y==null?void 0:y.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,b.ISheetSelectionRenderService),he(4,c.Inject(b.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},bt=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)}bt.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(bt,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})}},_e={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(b.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(Ee.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$:b.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 En(i){return{id:mt.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}const bn=i=>{var v;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=(v=s.anchorType)!=null?v:m.SheetDrawingAnchorType.Position,[f,S]=oe.useState(h);function w(D,R){const I=[];return D.forEach(T=>{const{oKey:y}=T,U=R.getDrawingOKey(y);if(U==null)return I.push(null),!0;const{unitId:E,subUnitId:N,drawingId:k,drawingType:A,anchorType:M,sheetTransform:Y}=U;I.push({unitId:E,subUnitId:N,drawingId:k,anchorType:M,sheetTransform:Y,drawingType:A})}),I}oe.useEffect(()=>{const D=u.clearControl$.subscribe(I=>{I===!0&&p(!1)}),R=u.changeStart$.subscribe(I=>{var U;const{objects:T}=I,y=w(T,e);if(y.length===0)p(!1);else if(y.length>=1){p(!0);const E=((U=y[0])==null?void 0:U.anchorType)||m.SheetDrawingAnchorType.Position;S(E)}});return()=>{R.unsubscribe(),D.unsubscribe()}},[]);function _(D){S(D);const R=e.getFocusDrawings();if(R.length===0)return;const I=R.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:D}));r.executeCommand(Ee.id,{unitId:R[0].unitId,drawings:I})}return J.jsxs("div",{className:Z.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!d}),children:[J.jsx("header",{className:"univer-text-gray-600 dark:univer-text-gray-200",children:J.jsx("div",{children:t.t("drawing-anchor.title")})}),J.jsx("div",{children:J.jsxs(Z.RadioGroup,{value:f,onChange:_,direction:"vertical",children:[J.jsx(Z.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),J.jsx(Z.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),J.jsx(Z.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)&&J.jsxs("div",{className:"univer-text-sm",children:[J.jsx(ge.DrawingCommonPanel,{drawings:t}),J.jsx(bn,{drawings:t})]})},An={[B.RibbonStartGroup.FORMULAS_INSERT]:{[wt]:{order:3,menuItemFactory:Tn,[Oe.id]:{order:0,menuItemFactory:Rn},[mt.id]:{order:1,menuItemFactory:En}}}};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:_e.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:_e.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:_e.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:_e.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},ve=(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,Ee,at,G,ct,ut,ht,_e,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([ve(0,c.Inject(B.ComponentManager)),ve(1,B.IMenuManagerService),ve(2,c.ICommandService),ve(3,B.IShortcutService),ve(4,j.IDrawingManagerService),ve(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},_t=(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),_t(1,c.Inject(c.Injector)),_t(2,W.IRenderManagerService),_t(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=_e,O.RemoveSheetDrawingCommand=Se,O.SHEETS_IMAGE_MENU_ID=wt,O.SetDrawingArrangeCommand=gt,O.SetSheetDrawingCommand=Ee,O.SidebarSheetDrawingOperation=at,O.UngroupSheetDrawingCommand=ht,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
16
16
 
17
17
 
18
18
  // @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.7.0-nightly.202505121607",
3
+ "version": "0.7.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -57,19 +57,19 @@
57
57
  "rxjs": ">=7.0.0"
58
58
  },
59
59
  "dependencies": {
60
- "@univerjs/docs-drawing": "0.7.0-nightly.202505121607",
61
- "@univerjs/drawing": "0.7.0-nightly.202505121607",
62
- "@univerjs/drawing-ui": "0.7.0-nightly.202505121607",
63
- "@univerjs/sheets-drawing": "0.7.0-nightly.202505121607",
64
- "@univerjs/sheets-drawing-ui": "0.7.0-nightly.202505121607",
65
- "rxjs": ">=7.0.0"
60
+ "@univerjs/docs-drawing": "0.7.0",
61
+ "@univerjs/drawing": "0.7.0",
62
+ "@univerjs/drawing-ui": "0.7.0",
63
+ "@univerjs/sheets-drawing": "0.7.0",
64
+ "@univerjs/sheets-drawing-ui": "0.7.0"
66
65
  },
67
66
  "devDependencies": {
68
- "@univerjs/core": "0.7.0-nightly.202505121607",
67
+ "@univerjs/core": "0.7.0",
69
68
  "react": "18.3.1",
70
69
  "react-dom": "18.3.1",
70
+ "rxjs": "7.8.2",
71
71
  "typescript": "^5.8.3",
72
- "@univerjs-infra/shared": "0.7.0-beta.1"
72
+ "@univerjs-infra/shared": "0.7.0"
73
73
  },
74
74
  "scripts": {
75
75
  "prebuild:preset": "tsx prepare.ts",