@univerjs/preset-sheets-drawing 0.8.0-beta.0 → 0.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/umd/index.js +3 -3
  2. package/package.json +8 -8
package/lib/umd/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
  // @univerjs/drawing-ui/index
6
- (function(D,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react/jsx-runtime"),require("@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"})});
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,L,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 Ke=Object.getOwnPropertyDescriptor,Ze=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ke(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:j,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:j,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:j,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:j,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=Ze([ye(0,M.IDrawingManagerService),ye(1,M.IImageIoService),ye(2,L.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 R=(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))(R||{});const fe={id:"sheet.operation.set-image-align",type:h.CommandType.OPERATION,handler:(i,r)=>!0},Fe=i=>{const r=L.useDependency(h.ICommandService),t=L.useDependency(h.LocaleService),{alignShow:e}=i,[n,a]=_.useState(R.default),s=[{label:t.t("image-panel.align.default"),value:R.default},{options:[{label:t.t("image-panel.align.left"),value:R.left},{label:t.t("image-panel.align.center"),value:R.center},{label:t.t("image-panel.align.right"),value:R.right}]},{options:[{label:t.t("image-panel.align.top"),value:R.top},{label:t.t("image-panel.align.middle"),value:R.middle},{label:t.t("image-panel.align.bottom"),value:R.bottom}]},{options:[{label:t.t("image-panel.align.horizon"),value:R.horizon},{label:t.t("image-panel.align.vertical"),value:R.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 K=function(){return K=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},K.apply(this,arguments)},ze=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},z=_.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,a=i.extend,s=ze(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},K({ref:r,className:o},s),a)});function Te(i,r,t,e,n){return _.createElement(i.tag,K(K({key:r},Ye(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 Ye(i,r,t){var e=K({},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)?K(K({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.includes(n.attrs.id)?K(K({},n),{attrs:K(K({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function qe(){return Math.random().toString(36).substring(2,8)}z.displayName="UniverIcon";var Je={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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.56377Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.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.83647Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M9.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(z,Object.assign({},i,{id:"autofill-double-icon",ref:r,icon:Je}))});Pe.displayName="AutofillDoubleIcon";var Qe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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.8334C15.6045 1.94974 14.8881 1.2334 14.0045 1.2334H3.70449C2.82084 1.2334 2.10449 1.94974 2.10449 2.8334C2.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.8334C3.30449 2.61248 3.48358 2.4334 3.70449 2.4334H14.0045C14.2254 2.4334 14.4045 2.61249 14.4045 2.8334Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 8.5999C15.038 8.5999 15.7544 7.88356 15.7544 6.9999C15.7544 6.11625 15.038 5.3999 14.1544 5.3999H3.85439C2.97074 5.3999 2.25439 6.11625 2.25439 6.9999C2.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.9999C3.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.7421C6.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.56641C9.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.7421C11.6631 11.9765 11.6631 12.3564 11.4288 12.5907L9.42923 14.5902"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.57975 14.5902C8.58121 14.5917 8.58268 14.5931 8.58416 14.5946C8.64077 14.6502 8.70566 14.6923 8.77482 14.7209C8.84557 14.7502 8.92314 14.7664 9.00449 14.7664C9.08585 14.7664 9.16342 14.7502 9.23416 14.7209C9.30332 14.6923 9.36821 14.6502 9.42482 14.5946"}}]},Ne=_.forwardRef(function(i,r){return _.createElement(z,Object.assign({},i,{id:"bottom-icon",ref:r,icon:Qe}))});Ne.displayName="BottomIcon";var et={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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.51296C9.08632 7.84433 8.81769 8.11296 8.48632 8.11296H6.57705C6.24568 8.11296 5.97705 7.84433 5.97705 7.51296Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.57705 9.41028C6.24568 9.41028 5.97705 9.67891 5.97705 10.0103C5.97705 10.3416 6.24568 10.6103 6.57705 10.6103H10.8199C11.1512 10.6103 11.4199 10.3416 11.4199 10.0103C11.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(z,Object.assign({},i,{id:"create-copy-icon",ref:r,icon:et}))});Be.displayName="CreateCopyIcon";var tt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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(z,Object.assign({},i,{id:"group-icon",ref:r,icon:tt}))});Ue.displayName="GroupIcon";var rt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Re=_.forwardRef(function(i,r){return _.createElement(z,Object.assign({},i,{id:"more-down-icon",ref:r,icon:rt}))});Re.displayName="MoreDownIcon";var nt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},je=_.forwardRef(function(i,r){return _.createElement(z,Object.assign({},i,{id:"move-down-icon",ref:r,icon:nt}))});je.displayName="MoveDownIcon";var it={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},xe=_.forwardRef(function(i,r){return _.createElement(z,Object.assign({},i,{id:"move-up-icon",ref:r,icon:it}))});xe.displayName="MoveUpIcon";var at={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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 9C15.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 9C2.70439 9.22091 2.88348 9.4 3.1044 9.4H13.4044C13.6253 9.4 13.8044 9.22091 13.8044 9C13.8044 8.77909 13.6253 8.6 13.4044 8.6H3.10439Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.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.1665C15.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.1665C2.8543 13.3874 3.03338 13.5665 3.2543 13.5665H13.5543C13.7752 13.5665 13.9543 13.3874 13.9543 13.1665C13.9543 12.9456 13.7752 12.7665 13.5543 12.7665H3.2543Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ae=_.forwardRef(function(i,r){return _.createElement(z,Object.assign({},i,{id:"topmost-icon",ref:r,icon:at}))});Ae.displayName="TopmostIcon";var st={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},Le=_.forwardRef(function(i,r){return _.createElement(z,Object.assign({},i,{id:"ungroup-icon",ref:r,icon:st}))});Le.displayName="UngroupIcon";const ot=i=>{const{arrangeShow:r,drawings:t}=i,e=L.useDependency(h.LocaleService),n=L.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(xe,{}),e.t("image-panel.arrange.forward")]}),f.jsxs(U.Button,{onClick:()=>{o(h.ArrangeTypeEnum.backward)},children:[f.jsx(je,{}),e.t("image-panel.arrange.backward")]}),f.jsxs(U.Button,{onClick:()=>{o(h.ArrangeTypeEnum.front)},children:[f.jsx(Ae,{}),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=L.useDependency(h.LocaleService),t=L.useDependency(I.IRenderManagerService),e=L.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},j=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:j}])},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 j=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:j}},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)}),j=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()=>{j.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(Le,{}),r.t("image-panel.group.unGroup")]})]})]})},te=20,lt=20,ut=[-3600,3600],pe=300,gt=i=>{var $e;const r=L.useDependency(h.LocaleService),t=L.useDependency(M.IDrawingManagerService),e=L.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,[j,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,x,V,W)=>{const{width:k,height:J}=S,{ancestorLeft:Z,ancestorTop:F}=p;let Y=w,ae=x,de=V,he=W;return w+Z<0&&(Y=-Z),x+F<0&&(ae=-F),de=k-Y-Z,de<te&&(de=te),he=J-ae-F,he<te&&(he=te),w+de+Z>k&&(Y=k-V-Z),x+he+F>J&&(ae=J-W-F),{limitLeft:Y,limitTop:ae,limitWidth:de,limitHeight:he}},ce=w=>{const{objects:x}=w,V=le(x,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:Z,left:F,top:Y,angle:ae}=k;J!=null&&b(J),Z!=null&&E(Z),F!=null&&P(F),Y!=null&&H(Y),ae!=null&&X(ae)};_.useEffect(()=>{const w=[m.changeStart$.subscribe(x=>{ce(x)}),m.changing$.subscribe(x=>{ce(x)}),m.changeEnd$.subscribe(x=>{ce(x)}),t.focus$.subscribe(x=>{if(x.length!==1)return;const V=t.getDrawingByParam(x[0]);if(V==null)return;const W=V.transform;if(W==null)return;const{width:k,height:J,left:Z,top:F,angle:Y}=W;k!=null&&b(k),J!=null&&E(J),Z!=null&&P(Z),F!=null&&H(F),Y!=null&&X(Y)})];return()=>{w.forEach(x=>x.unsubscribe())}},[]);const q=h.debounce(w=>{if(w==null)return;w=Math.max(w,te);const{limitWidth:x,limitHeight:V}=ie(B,G,w,T);w=Math.min(w,x);const W={unitId:c,subUnitId:u,drawingId:l,drawingType:g,transform:{width:w}};if(oe){let k=w/j*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:x,limitWidth:V}=ie(B,G,j,w);w=Math.min(w,x);const W={unitId:c,subUnitId:u,drawingId:l,drawingType:g,transform:{height:w}};if(oe){let k=w/T*j;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:x}=ie(w,G,j,T);w=x;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:x}=ie(B,w,j,T);w=x;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[x,V]=ut;w<x&&(w=x),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:j,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 A=(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))(A||{});const ue={id:"sheet.operation.Auto-image-crop",type:h.CommandType.OPERATION,handler:(i,r)=>!0},dt=i=>{const r=L.useDependency(h.ICommandService),t=L.useDependency(h.LocaleService),{drawings:e,cropperShow:n}=i;if(e[0]==null)return;const[s,o]=_.useState(A.FREE),c=_.useRef(!1),u=[{label:t.t("image-panel.crop.mode"),value:A.FREE},{label:"1:1",value:A.R1_1},{label:"16:9",value:A.R16_9},{label:"9:16",value:A.R9_16},{label:"5:4",value:A.R5_4},{label:"4:5",value:A.R4_5},{label:"4:3",value:A.R4_3},{label:"3:4",value:A.R3_4},{label:"3:2",value:A.R3_2},{label:"2:3",value:A.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=L.useDependency(M.IDrawingManagerService),t=L.useDependency(I.IRenderManagerService),e=L.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),[j,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?j:!1,drawings:n}),f.jsx(ct,{hasGroup:u,drawings:n})]})};function 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=L.useDependency(h.ICommandService),n=L.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(Re,{className:"dark:!univer-text-white"})]})})})}const 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(L.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===R.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:j=0,top:b=0,width:T=0,height:E=0}=O;let B=j,P=b;switch(t){case R.left:B=e;break;case R.center:B=e+(a-e)/2-T/2;break;case R.right:B=a-T;break;case R.top:P=n;break;case R.middle:P=n+(s-n)/2-E/2;break;case R.bottom:P=s-E;break;case R.horizon:B=e+c*m;break;case R.vertical:P=n+u*m;break}(B!==j||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 R.left:return o-g;case R.center:return o+u/2-(g+p/2);case R.right:return o+u-(g+p);case R.top:return c-d;case R.middle:return c+l/2-(d+S/2);case R.bottom:return c+l-(d+S);case R.horizon:return o+u/2-(g+p/2);case R.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,j=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:n,drawingId:a}),b=l.getObject(j);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:j}=y;o.push({unitId:O,subUnitId:N,drawingId:j});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 A.R1_1:o=this._calculateSrcRectByRatio(e,n,a,s,1,1);break;case A.R16_9:o=this._calculateSrcRectByRatio(e,n,a,s,16,9);break;case A.R9_16:o=this._calculateSrcRectByRatio(e,n,a,s,9,16);break;case A.R5_4:o=this._calculateSrcRectByRatio(e,n,a,s,5,4);break;case A.R4_5:o=this._calculateSrcRectByRatio(e,n,a,s,4,5);break;case A.R4_3:o=this._calculateSrcRectByRatio(e,n,a,s,4,3);break;case A.R3_4:o=this._calculateSrcRectByRatio(e,n,a,s,3,4);break;case A.R3_2:o=this._calculateSrcRectByRatio(e,n,a,s,3,2);break;case A.R2_3:o=this._calculateSrcRectByRatio(e,n,a,s,2,3);break;case A.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,j=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),j);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,L.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,L.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,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 I,D,R;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(C.SheetInterceptorService),o=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(y=>{const{unitId:T}=y;a.push(T)});const l=o.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,S=n.onCommandExecute({id:Se.id,params:r}),f={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([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(D=S.preUndos)!=null?D:[],w,...S.undos,{id:G.id,params:a}],redoMutations:[...(R=S.preRedos)!=null?R:[],f,...S.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,$t=(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,S=g.data;if(S&&S.disablePopup)return;n==null||n.dispose();const f=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:f||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=$t([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 Ft=Object.getOwnPropertyDescriptor,Gt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ft(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:S,height:f}=d;const w=t.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,I=w.columnHeaderHeight+w.rowTotalHeight;return p+S>_&&(p=_-S),h+f>I&&(h=I-f),{flipY:o,flipX:s,angle:a,skewX:l,skewY:g,left:p,top:h,width:S,height:f}}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 S={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:S}}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},$e=(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([$e(1,m.ISheetDrawingService),$e(2,j.IDrawingManagerService),$e(3,c.Inject(b.ISheetSelectionRenderService)),$e(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:S,drawingId:f}=d;return{unitId:h,subUnitId:S,drawingId:f,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:S,drawingId:f}=d,w=W.transformObjectOutOfGroup(p||{},l,l.width||0,l.height||0);return{unitId:h,subUnitId:S,drawingId:f,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:S})=>{o.push(h.unitId),S.forEach(f=>{o.push(f.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 I,D,R;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService),o=i.get(C.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(y=>y.unitId),l=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,S=o.onCommandExecute({id:Re.id,params:r}),f={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([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(D=S.preUndos)!=null?D:[],w,...S.undos,{id:G.id,params:a}],redoMutations:[...(R=S.preRedos)!=null?R:[],f,...S.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:S})=>{o.push(h.unitId),S.forEach(f=>{o.push(f.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 I;const{rotatedHeight:o,rotatedWidth:s}=Zt(t,e,n),l=i.get(W.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(I=l.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.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,S=s/o,w=Math.ceil(Math.min(p,h*S))/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,S){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=S,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:S,height:f}=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,S,f);if(_==null)return;const I={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:[I]})}async _insertCellImage(t,e){var R,y;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const v=T.message;v===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)))}):v===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===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;let h=p.primary.actualRow,S=p.primary.actualColumn;p.primary.isMerged&&(h=p.primary.startRow,S=p.primary.startColumn);const f=c.createDocumentModelWithStyle("",{}),w=pt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:S},g,u,0);if(!w)return!1;const _={size:{width:w.width,height:w.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},I={unitId:f.getUnitId(),subUnitId:f.getUnitId(),drawingId:o,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:Be.docDrawingPositionToTransform(_),docTransform:_,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},D=c.BuildTextUtils.drawing.add({documentDataModel:f,drawings:[I],selection:{collapsed:!0,startOffset:0,endOffset:0}});return D?(f.apply(D),this._commandService.syncExecuteCommand(C.SetRangeValuesCommand.id,{value:{[(R=e==null?void 0:e.row)!=null?R:h]:{[(y=e==null?void 0:e.col)!=null?y:S]:{p:f.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,S;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]:{[(S=e==null?void 0:e.col)!=null?S: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 S={column:g,columnOffset:0,row:u,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(d+t,p+e);if(f==null)return;const w={column:f.actualColumn,columnOffset:d+t-f.startX,row:f.actualRow,rowOffset:p+e-f.startY};return{from:S,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 Fe=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)}}))}};Fe=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))],Fe);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 S=u[h],{transform:f}=S;if(S.anchorType!==m.SheetDrawingAnchorType.Both||!f)return;const{left:w=0,top:_=0,width:I=0,height:D=0}=f,{drawingStartX:R,drawingEndX:y,drawingStartY:T,drawingEndY:v}={drawingStartX:w,drawingEndX:w+I,drawingStartY:_,drawingEndY:_+D};s<=R&&y<=a&&l<=T&&v<=g&&d.push(S)}),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:(S,f)=>{var I;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...S,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:_,sheetTransform:(I=H(_,u))!=null?I:f}}})}_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),S={...u,unitId:e,subUnitId:n,drawingId:s?u.drawingId:c.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:f,redo:w,objects:_}=g.getBatchUpdateOp([S]);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:f,objects:_}})}else{const{undo:f,redo:w,objects:_}=g.getBatchAddOp([S]);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:f,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:S,col:f}=h(d.startRow,d.startColumn),{row:w,col:_}=h(p.startRow,p.startColumn),I=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:f,endColumn:f}),D=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:_,endColumn:_});if(!I||!D||!this._copyInfo)return{redos:[],undos:[]};const R=D.startX-I.startX,y=D.startY-I.startY,T=w-S,v=_-f;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)+y},sheetTransform:{...N,to:{...N.to,row:N.to.row+T,column:N.to.column+v},from:{...N.from,row:N.from.row+T,column:N.from.column+v}}}},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,S={left:!0,top:!0};if(!l)return{...i,absolute:S};const{left:f,right:w,top:_,bottom:I}=i;let{top:D,left:R,viewportScrollX:y,viewportScrollY:T}=l;const{boundsOfViewArea:v,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:E,columnHeaderHeight:N}=t,k={top:o?0:N,left:o?0:E};v&&(c.Tools.isDefine(k.top)&&(k.top=v.top),c.Tools.isDefine(k.left)&&(k.left=v.left)),U==="HORIZONTAL"&&(T=0),U==="VERTICAL"&&(y=0);let A=0,M=0;const Y=t.rowStartY(d-h)+N,F=t.colStartX(u-p)+E,q=t.rowStartY(d)+N,te=t.colStartX(u)+E;if(p===0)S.left=!1,A=(f-y)*s,M=(w-y)*s;else{const K=f-(F-E),L=w-(F-E);w<te?(A=K*s,M=L*s):f<=te&&w>=te?(A=K*s,M=Math.max(R,(w-y)*s)):f>te&&(S.left=!1,A=Math.max((f-y)*s,R),M=Math.max((w-y)*s,R))}let X=0,x=0;if(h===0)S.top=!1,X=(_-T)*a,x=(I-T)*a;else{const K=_-(Y-N),L=I-(Y-N);I<q?(X=K*a,x=L*a):_<=q&&I>=q?(X=K*a,x=Math.max(D,(I-T)*a)):_>q&&(S.top=!1,X=Math.max((_-T)*a,D),x=Math.max((I-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:S}}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:S}=l;if(h!==c.DrawingTypeEnum.DRAWING_DOM&&h!==c.DrawingTypeEnum.DRAWING_CHART)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:w,canvas:_}=f;if(p==null)return!0;if(u!==o)return;const{left:I,top:D,width:R,height:y,angle:T,flipX:v,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:I,top:D,width:R,height:y,angle:T,flipX:v,flipY:U,skewX:E,skewY:N});return}const M={left:I,top:D,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},Y=h===c.DrawingTypeEnum.DRAWING_CHART;if(M.rotateEnabled=!1,Y){const L=S?S.backgroundColor:"white";M.fill=L,S&&S.border&&(M.stroke=S.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const F=new W.Rect(k,M);Y&&F.setObjectType(W.ObjectType.CHART),w.addObject(F,W.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&w.attachTransformerTo(F);const q=new c.DisposableCollection,te=ae(F,f.renderUnit.scene,d.skeleton,a.worksheet),X=new P.BehaviorSubject(te),x={dispose:q,rect:F,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:S,unitId:n});const ne=F.onTransformChange$.subscribeEvent(()=>{const L=ae(F,f.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 v,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=(v=this._renderManagerService.getRenderById(a))==null?void 0:v.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=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(),y=Ke(w,n,R),T={unitId:a,subUnitId:l,drawingId:f,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:S};{const{unitId:N,subUnitId:k,drawingId:A}=T,M=C.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:k}),Y=T,F=this._univerInstanceService.getUnit(N,c.UniverInstanceType.UNIVER_SHEET);if(!F)return;const q=F.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 $=K?K.backgroundColor:"white";re.fill=$,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:$=>{ye.dispatchEvent(new WheelEvent($.type,$))},data:K,unitId:N};e.eventPassThrough&&(je={...je,onPointerDown:$=>{ye.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{ye.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{ye.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(je),this.disposeWithMe(_.subscribe($=>{var kt,jt,Wt,Bt;const Nt=Ke({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(kt=n.width)!=null?kt:$.width,height:(jt=n.height)!=null?jt:$.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:$.width,height:(Bt=n.height)!=null?Bt:$.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($=>{$&&X.sheetId!==$.sheetId&&this._removeDom(f,!0)});const st=de.onTransformChange$.subscribeEvent(()=>{const $=ae(de,L.renderUnit.scene,X.skeleton,M.worksheet,ue);Te.next($)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(A)}),st&&le.add(st),this._domLayerInfoMap.set(A,ue)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var y,T,v;const s=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:l}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=o!=null?o:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),I=w;if(I.startY=0,this._getPosition(w,a)==null)return;const R={unitId:a,subUnitId:l,drawingId:f,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:S};{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 F=(T=this._renderManagerService.getRenderById(U))==null?void 0:T.with(b.SheetSkeletonManagerService);if(!F)return;const q=F.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:I.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=(v=this._renderManagerService.getRenderById(U))==null?void 0:v.with(b.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(V=>{V&&d.sheetId!==V.sheetId&&this._removeDom(f,!0)}),re.add(()=>{this._canvasFloatDomService.removeFloatDom(N)}),ot&&re.add(ot),this._domLayerInfoMap.set(N,le)}return{id:f,dispose:()=>{this._removeDom(f,!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),I=Pe(t.endRow,t.endColumn,n);l.next(_),u.next(I)},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=(_,I)=>{o=_,s=I,d()},S=()=>({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}),f=l.pipe(P.map(_=>{const I=Pe(t.endRow,t.endColumn,n);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),w=S();return{position$:f,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:S}=t.getAncestorScale(),f={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:l*S,absolute:p.absolute},w={position$:new P.BehaviorSubject(f),position:f,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 S=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),f=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});S.column<d.startColumn&&(d.startColumn=S.column),S.row<d.startRow&&(d.startRow=S.row),d.endRow<f.row&&(d.endRow=f.row),d.endColumn<f.column&&(d.endColumn=f.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:S}=d,{row:f,column:w}=p;if(o==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:I,startColumn:D,endColumn:R}=i;let y=null,T=null;if(r===0&&h>=_&&f<=I)if(S>=D&&w<=R)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(o,a,D,R,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===1&&S>=D&&w<=R)if(h>=_&&f<=I)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(o,a,_,I,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(o,a,_,I,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(o,a,D,R,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}if(y!=null&&T!=null){const v=z(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:v})}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:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:D,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:v,endRow:U,startColumn:E,endColumn:N}=T;if(R<E)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(I>=E&&I<=N){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:N,startRow:f.row,endRow:w.row});if(F==null)return;Y={...h,left:F.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(I>=E&&R<=N)continue;let k=null,A=null;if(I>=E&&I<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:N,startRow:f.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:f.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:f.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:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:D,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:v,endRow:U,startColumn:E,endColumn:N}=T;if(D<v)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(_>=v&&_<=U){const F=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:U});if(F==null)return;Y={...h,top:F.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&&D<=U)continue;let k=null,A=null;if(_>=v&&_<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.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>=v&&D<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,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:f.column,endColumn:w.column,startRow:v,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:S}=d,{row:f,column:w}=p;for(let _=0;_<t.length;_++){const I=t[_],{startRow:D,endRow:R,startColumn:y,endColumn:T}=I;if(f<D||w<y)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=D&&f>=R||S<=y&&w>=T)){this._remainDrawingSize(g,o,a);continue}const v=z({...l},this._selectionRenderService,this._skeletonManagerService);if(v!=null){o.push({...a,transform:v});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(y=>{const T=p[y];if(T.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=T;if(!v)return;const{left:U=0,top:E=0,width:N=0,height:k=0}=v,{drawingStartX:A,drawingEndX:M,drawingStartY:Y,drawingEndY:F}={drawingStartX:U,drawingEndX:U+N,drawingStartY:E,drawingEndY:E+k};l<=A&&M<=g&&u<=Y&&F<=d&&h.push(T)});const S=[],f=[],w=r.startRow-t.startRow,_=r.startColumn-t.startColumn,I=h.map(y=>{const T=y.sheetTransform,v={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(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:y.drawingId,transform:U,sheetTransform:v}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:v,objects:U}=y;S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:v,objects:U,type:m.DrawingApplyType.UPDATE}}),f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:T,objects:U,type:m.DrawingApplyType.UPDATE}})}return{redos:S,undos:f}}_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 S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,D;if(r==="insert"){const y=this._expandRow(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=f,{row:v}=y,{row:U}=T;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkRow(f,w,s,a,_);I=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.newTransform}}if(!I||!D)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:I};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,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 S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,D;if(r==="insert"){const y=this._expandCol(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=f,{column:v}=y,{column:U}=T;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkCol(f,w,s,a,_);I=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.newTransform}}if(!I||!D)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:D,sheetTransform:I};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,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:S,column:f}=d;for(let w=0;w<t.length;w++){const _=t[w],{startRow:I,endRow:D,startColumn:R,endColumn:y}=_;if(c.Rectangle.intersects({startRow:I,endRow:D,startColumn:R,endColumn:y},{startRow:p,endRow:S,startColumn:h,endColumn:f})||p>D||h>y){const T=g===m.SheetDrawingAnchorType.Position,v=z(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...v,width:T?l==null?void 0:l.width:v==null?void 0:v.width,height:T?l==null?void 0:l.height:v==null?void 0:v.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:S=0}=d;return o===c.Direction.UP?p.top=S-1:o===c.Direction.DOWN?p.top=S+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 I;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=(I=s.anchorType)!=null?I:m.SheetDrawingAnchorType.Position,[S,f]=oe.useState(h);function w(D,R){const y=[];return D.forEach(T=>{const{oKey:v}=T,U=R.getDrawingOKey(v);if(U==null)return y.push(null),!0;const{unitId:E,subUnitId:N,drawingId:k,drawingType:A,anchorType:M,sheetTransform:Y}=U;y.push({unitId:E,subUnitId:N,drawingId:k,anchorType:M,sheetTransform:Y,drawingType:A})}),y}oe.useEffect(()=>{const D=u.clearControl$.subscribe(y=>{y===!0&&p(!1)}),R=u.changeStart$.subscribe(y=>{var U;const{objects:T}=y,v=w(T,e);if(v.length===0)p(!1);else if(v.length>=1){p(!0);const E=((U=v[0])==null?void 0:U.anchorType)||m.SheetDrawingAnchorType.Position;f(E)}});return()=>{R.unsubscribe(),D.unsubscribe()}},[]);function _(D){f(D);const R=e.getFocusDrawings();if(R.length===0)return;const y=R.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:D}));r.executeCommand(Ee.id,{unitId:R[0].unitId,drawings:y})}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:S,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.RibbonInsertGroup.MEDIA]:{[wt]:{order:0,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,$n=(i,r,t)=>r in i?Yn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Fn=(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)=>$n(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],[Fe],[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],[Fe],[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=Fn([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"})});
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,ge,W,le,j,m,q,b,B,U,D,je,J,me){"use strict";var jn=Object.defineProperty;var Bn=(O,c,ge)=>c in O?jn(O,c,{enumerable:!0,configurable:!0,writable:!0,value:ge}):O[c]=ge;var re=(O,c,ge)=>Bn(O,typeof c!="symbol"?c+"":c,ge);const Nt="sheets-drawing-ui.config",It={},G={id:"sheet.operation.clear-drawing-transformer",type:c.CommandType.MUTATION,handler:(o,r)=>{const t=o.get(j.IRenderManagerService);return r.forEach(e=>{var n,i;(i=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||i.debounceRefreshControls()}),!0}},fe={id:"sheet.command.remove-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{var I,C,R;const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(D.SheetInterceptorService),i=o.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(y=>{const{unitId:T}=y;a.push(T)});const l=i.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,S=n.onCommandExecute({id:fe.id,params:r}),f={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([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=S.preUndos)!=null?C:[],w,...S.undos,{id:G.id,params:a}],redoMutations:[...(R=S.preRedos)!=null?R:[],f,...S.redos,{id:G.id,params:a}]}),!0):!1}},yt="COMPONENT_SHEET_DRAWING_PANEL",st={id:"sidebar.operation.sheet-image",type:c.CommandType.COMMAND,handler:async(o,r)=>{const t=o.get(B.ISidebarService),e=o.get(c.LocaleService),n=o.get(c.IUniverInstanceService),i=o.get(c.ICommandService);if(!D.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:yt},onClose:()=>{i.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},at={id:"sheet.operation.edit-sheet-image",type:c.CommandType.OPERATION,handler:(o,r)=>{const t=o.get(c.ICommandService);return r==null?!1:(t.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[r]),t.executeCommand(st.id,{value:"open"}),!0)}};var kt=Object.getOwnPropertyDescriptor,Wt=(o,r,t,e)=>{for(var n=e>1?void 0:e?kt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ie=(o,r)=>(t,e)=>r(t,e,o);let Be=class extends c.RxDisposable{constructor(r,t,e,n,i,s,a,l,g,u){super();re(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=i,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(U.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(U.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:q.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 le.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var i;const t=(i=this._renderManagerService.getRenderById(r))==null?void 0:i.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,S=g.data;if(S&&S.disablePopup)return;n==null||n.dispose();const f=this._canvasPopManagerService.getFeatureMenu(u,d,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:le.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:f||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(W.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:at.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:fe.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:le.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:le.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===c.DrawingTypeEnum.DRAWING_DOM}]}};Be=Wt([ie(0,c.Inject(c.Injector)),ie(1,c.Inject(c.LocaleService)),ie(2,W.IDrawingManagerService),ie(3,c.Inject(b.SheetCanvasPopManagerService)),ie(4,j.IRenderManagerService),ie(5,c.IUniverInstanceService),ie(6,B.IMessageService),ie(7,c.IContextService),ie(8,c.IImageIoService),ie(9,c.ICommandService)],Be);var jt=Object.getOwnPropertyDescriptor,Bt=(o,r,t,e)=>{for(var n=e>1?void 0:e?jt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ye=(o,r)=>(t,e)=>r(t,e,o);let ct=class extends c.Disposable{constructor(r,t,e,n,i){super();re(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=i,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(U.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(j.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}}))}};ct=Bt([Ye(1,c.Inject(b.HoverManagerService)),Ye(2,c.Inject(D.SheetsSelectionsService)),Ye(3,c.Inject(le.DrawingRenderService)),Ye(4,c.Inject(b.SheetSkeletonManagerService))],ct);function x(o,r,t){const{from:e,to:n,flipY:i=!1,flipX:s=!1,angle:a=0,skewX:l=0,skewY:g=0}=o,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:S,height:f}=d;const w=t.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,I=w.columnHeaderHeight+w.rowTotalHeight;return p+S>_&&(p=_-S),h+f>I&&(h=I-f),{flipY:i,flipX:s,angle:a,skewX:l,skewY:g,left:p,top:h,width:S,height:f}}function H(o,r){const{left:t=0,top:e=0,width:n=0,height:i=0,flipY:s=!1,flipX:a=!1,angle:l=0,skewX:g=0,skewY:u=0}=o,d=r.getCellWithCoordByOffset(t,e);if(d==null)return;const p={column:d.actualColumn,columnOffset:j.precisionTo(t-d.startX,1),row:d.actualRow,rowOffset:j.precisionTo(e-d.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+i);if(h==null)return;const S={column:h.actualColumn,columnOffset:j.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:j.precisionTo(e+i-h.startY,1)};return{flipY:s,flipX:a,angle:l,skewX:g,skewY:u,from:p,to:S}}var Yt=Object.getOwnPropertyDescriptor,Ft=(o,r,t,e)=>{for(var n=e>1?void 0:e?Yt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Fe=(o,r)=>(t,e)=>r(t,e,o);let dt=class extends c.Disposable{constructor(o,r,t,e,n){super(),this._context=o,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 o=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in o){const t=o[r];for(const e in t.data){const n=t.data[e];n.sheetTransform&&(n.transform=x(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};dt=Ft([Fe(1,m.ISheetDrawingService),Fe(2,W.IDrawingManagerService),Fe(3,c.Inject(b.ISheetSelectionRenderService)),Fe(4,c.Inject(b.SheetSkeletonManagerService))],dt);function $t(o){const r=[];return o.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,subUnitId:s,drawingId:a}=e,l=j.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const p=d.transform||{left:0,top:0},{unitId:h,subUnitId:S,drawingId:f}=d;return{unitId:h,subUnitId:S,drawingId:f,transform:{...p,left:p.left-l.left,top:p.top-l.top},groupId:a}}),u={unitId:i,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:g})}),r}function Lt(o){const r=[];return o.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,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:S,drawingId:f}=d,w=j.transformObjectOutOfGroup(p||{},l,l.width||0,l.height||0);return{unitId:h,subUnitId:S,drawingId:f,transform:w,groupId:void 0}}),u={unitId:i,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const lt={id:"sheet.command.group-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:S})=>{i.push(h.unitId),S.forEach(f=>{i.push(f.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:Lt(d),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP}},{id:G.id,params:i}]}),!0):!1}},Te={id:"sheet.command.insert-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{var I,C,R;const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService),i=o.get(D.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(y=>y.unitId),l=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,S=i.onCommandExecute({id:Te.id,params:r}),f={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([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=S.preUndos)!=null?C:[],w,...S.undos,{id:G.id,params:a}],redoMutations:[...(R=S.preRedos)!=null?R:[],f,...S.redos,{id:G.id,params:a}]}),!0):!1}},ut={id:"sheet.command.set-drawing-arrange",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService);if(!r)return!1;const n=o.get(m.ISheetDrawingService),{unitId:i,subUnitId:s,drawingIds:a,arrangeType:l}=r,g={unitId:i,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:i,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:i,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:i,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:i,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Re={id:"sheet.command.set-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:i}=r,s=n.getBatchUpdateOp(i),{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}},gt={id:"sheet.command.ungroup-sheet-image",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(c.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:S})=>{i.push(h.unitId),S.forEach(f=>{i.push(f.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:$t(d),type:m.DrawingApplyType.GROUP}},{id:G.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:i}]}),!0):!1}};var Gt=Object.getOwnPropertyDescriptor,Ht=(o,r,t,e)=>{for(var n=e>1?void 0:e?Gt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Q=(o,r)=>(t,e)=>r(t,e,o);function Xt(o,r,t){const e=t*Math.PI/180,n=Math.abs(o*Math.cos(e))+Math.abs(r*Math.sin(e)),i=Math.abs(o*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:i}}function ht(o,r,t,e,n){var I;const{rotatedHeight:i,rotatedWidth:s}=Xt(t,e,n),l=o.get(j.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(I=l.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.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,S=s/i,w=Math.ceil(Math.min(p,h*S))/s,_=!w||Number.isNaN(w)?.001:w;return{width:t*_,height:e*_}}O.SheetDrawingUpdateController=class extends c.Disposable{constructor(t,e,n,i,s,a,l,g,u,d,p,h,S){super();re(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=i,this._imageIoService=s,this._fileOpenerService=a,this._sheetDrawingService=l,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=p,this._injector=S,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:W.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>W.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(W.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:W.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(C){const R=C.message;R===W.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(W.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===W.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===W.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:i,subUnitId:s}=n,{imageId:a,imageSourceType:l,source:g,base64Cache:u}=e,{width:d,height:p,image:h}=await W.getImageSize(u||""),{width:S,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(g,l,h);let w=1;if(d>W.DRAWING_IMAGE_WIDTH_LIMIT||p>W.DRAWING_IMAGE_HEIGHT_LIMIT){const C=W.DRAWING_IMAGE_WIDTH_LIMIT/d,R=W.DRAWING_IMAGE_HEIGHT_LIMIT/p;w=Math.max(C,R)}const _=this._getImagePosition(d*w,p*w,S,f);if(_==null)return;const I={unitId:i,subUnitId:s,drawingId:a,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:g,transform:x(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Te.id,{unitId:i,drawings:[I]})}async _insertCellImage(t,e){var R,y;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const v=T.message;v===W.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(W.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===W.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===W.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:i,imageSourceType:s,source:a,base64Cache:l}=n,{width:g,height:u,image:d}=await W.getImageSize(l||"");this._imageIoService.addImageSourceCache(a,s,d);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;let h=p.primary.actualRow,S=p.primary.actualColumn;p.primary.isMerged&&(h=p.primary.startRow,S=p.primary.startColumn);const f=c.createDocumentModelWithStyle("",{}),w=ht(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:S},g,u,0);if(!w)return!1;const _={size:{width:w.width,height:w.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},I={unitId:f.getUnitId(),subUnitId:f.getUnitId(),drawingId:i,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:je.docDrawingPositionToTransform(_),docTransform:_,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},C=c.BuildTextUtils.drawing.add({documentDataModel:f,drawings:[I],selection:{collapsed:!0,startOffset:0,endOffset:0}});return C?(f.apply(C),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(R=e==null?void 0:e.row)!=null?R:h]:{[(y=e==null?void 0:e.col)!=null?y:S]:{p:f.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,S;const{width:n,height:i,image:s}=await W.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,c.ImageSourceType.URL,s);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const l=c.createDocumentModelWithStyle("",{}),g=ht(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,i,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:je.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(D.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:a.primary.actualRow]:{[(S=e==null?void 0:e.col)!=null?S: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(),i=e.getSheetId();return{unitId:n,subUnitId:i}}_getImagePosition(t,e,n,i){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>i&&(p=i-e,p<0&&(p=0,e=i),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(d,p);if(_==null)return;d=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const S={column:g,columnOffset:0,row:u,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(d+t,p+e);if(f==null)return;const w={column:f.actualColumn,columnOffset:d+t-f.startX,row:f.actualRow,rowOffset:p+e-f.startY};return{from:S,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:i,arrangeType:s}=t;this._commandService.executeCommand(ut.id,{unitId:e,subUnitId:n,drawingIds:i,arrangeType:s})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:i,subUnitId:s,drawingId:a,drawingType:l,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:i,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,...x(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Re.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(lt.id,t);const{unitId:e,subUnitId:n,drawingId:i}=t[0].parent;this._commandService.syncExecuteCommand(W.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:i}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(gt.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=Ht([Q(1,c.Inject(b.SheetSkeletonManagerService)),Q(2,c.ICommandService),Q(3,b.ISheetSelectionRenderService),Q(4,W.IImageIoService),Q(5,B.ILocalFileService),Q(6,m.ISheetDrawingService),Q(7,W.IDrawingManagerService),Q(8,c.IContextService),Q(9,B.IMessageService),Q(10,c.Inject(c.LocaleService)),Q(11,c.Inject(D.SheetsSelectionsService)),Q(12,c.Inject(c.Injector))],O.SheetDrawingUpdateController);var Vt=Object.getOwnPropertyDescriptor,Kt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Vt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Se=(o,r)=>(t,e)=>r(t,e,o);function Dt(o,r,t){var e,n,i,s;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((s=(i=t.p)==null?void 0:i.drawingsOrder)==null?void 0:s.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],l=ht(o,{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(o,r,t,e,n,i){super(),this._commandService=o,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(o=>{o.visible?o.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(o=>{o.id===je.ReplaceSnapshotCommand.id&&o.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(D.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:D.InterceptCellContentPriority.CELL_IMAGE,handler:(o,r,t)=>{var e;return o!=null&&o.p&&((e=o.p.drawingsOrder)!=null&&e.length)&&(o===r.rawData&&(o={...r.rawData}),o.interceptorStyle||(o.interceptorStyle={}),o.interceptorStyle.tr={a:0},Dt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},o)),t(o)}}))}};$e=Kt([Se(0,c.ICommandService),Se(1,c.Inject(D.SheetInterceptorService)),Se(2,c.Inject(c.Injector)),Se(3,W.IDrawingManagerService),Se(4,c.Inject(ge.DocDrawingController)),Se(5,c.Inject(b.IEditorBridgeService))],$e);var zt=Object.getOwnPropertyDescriptor,xt=(o,r,t,e)=>{for(var n=e>1?void 0:e?zt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ct=(o,r)=>(t,e)=>r(t,e,o);let Le=class extends c.Disposable{constructor(o,r){super(),this._autoFillService=o,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(o,r,t,e)=>{new c.ObjectMatrix(e).forValue((n,i,s)=>{Dt(this._injector,{unitId:o.unitId,subUnitId:o.subUnitId,row:n,col:i},s)})}}))}};Le=xt([Ct(0,c.Inject(b.IAutoFillService)),Ct(1,c.Inject(c.Injector))],Le);var qt=Object.getOwnPropertyDescriptor,Zt=(o,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ee=(o,r)=>(t,e)=>r(t,e,o);const Jt=[c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,c.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Ge=class extends c.Disposable{constructor(o,r,t,e,n){super(),this._commandService=o,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(o){var n;const r=c.createDocumentModelWithStyle("",{}),t=(n=j.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(b.EditingRenderController),e=c.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[o],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(o=>{var r,t;if(o.id===je.InnerPasteCommand.id){const e=o.params,{doc:n}=e,i=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_DOC);if(i==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const s=i.getUnitId();if(Jt.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=i.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")}}}))}};Ge=Zt([Ee(0,c.ICommandService),Ee(1,c.IUniverInstanceService),Ee(2,B.IDialogService),Ee(3,j.IRenderManagerService),Ee(4,c.Inject(c.LocaleService))],Ge);const be={id:"sheet.command.insert-float-image",type:c.CommandType.COMMAND,handler:async(o,r)=>{var s,a;const t=o.get(c.IUniverInstanceService),e=o.get(j.IRenderManagerService),n=(s=j.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:s.with(O.SheetDrawingUpdateController);if(!n)return!1;const i=r==null?void 0:r.files;if(i){const l=i.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(l)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},pt={id:"sheet.command.insert-cell-image",type:c.CommandType.COMMAND,handler:o=>{var e,n;const r=o.get(c.IUniverInstanceService),t=o.get(j.IRenderManagerService);return(n=(e=j.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(O.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var Qt=Object.getOwnPropertyDescriptor,en=(o,r,t,e)=>{for(var n=e>1?void 0:e?Qt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Oe=(o,r)=>(t,e)=>r(t,e,o);const Mt="image/png";function tn(o){const r=o.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let i=0;i<e;i++)n[i]=t.charCodeAt(i);return new Blob([n],{type:Mt})}function nn(o){const r=new ClipboardItem({[Mt]:tn(o)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function rn(){function o(){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=o();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Tt=[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 He=class extends c.Disposable{constructor(r,t,e,n,i){super();re(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=i,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const i=this._focusedDrawings;if(i.length>0){const[s]=i;if(n===b.COPY_TYPE.CUT){const l={unitId:r,drawings:[s]};this._commandService.executeCommand(fe.id,l)}setTimeout(()=>{const l=rn();s.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===W.ImageSourceType.BASE64?nn(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:i=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:i}):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:be.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 i=n.attachRangeWithCoord(e);if(!i)return;const{startX:s,endX:a,startY:l,endY:g}=i,u=this._drawingService.getDrawingData(r,t),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const S=u[h],{transform:f}=S;if(S.anchorType!==m.SheetDrawingAnchorType.Both||!f)return;const{left:w=0,top:_=0,width:I=0,height:C=0}=f,{drawingStartX:R,drawingEndX:y,drawingStartY:T,drawingEndY:v}={drawingStartX:w,drawingEndX:w+I,drawingStartY:_,drawingEndY:_+C};s<=R&&y<=a&&l<=T&&v<=g&&d.push(S)}),d.length)return{copyRange:e,drawings:d,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Tt.includes(e))return{redos:[],undos:[]};const{unitId:i,subUnitId:s,range:a}=n,l=this._renderManagerService.getRenderById(i),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:i,subUnitId:s,isCut:t===b.COPY_TYPE.CUT,getTransform:(S,f)=>{var I;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...S,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:_,sheetTransform:(I=H(_,u))!=null?I:f}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:i,isCut:s}=t,a=[],l=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:p}=u;if(!d)return;const h=i(d,p),S={...u,unitId:e,subUnitId:n,drawingId:s?u.drawingId:c.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:f,redo:w,objects:_}=g.getBatchUpdateOp([S]);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:f,objects:_}})}else{const{undo:f,redo:w,objects:_}=g.getBatchAddOp([S]);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:f,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:l}}_generateRangeDrawingsPasteMutations(r,t){var P;const{unitId:e,subUnitId:n,pasteType:i,pasteRange:s}=r,{copyRange:a,copyType:l}=t;if(Tt.includes(i))return{redos:[],undos:[]};const g=(P=this._renderManagerService.getRenderById(e))==null?void 0:P.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:i},l);const{ranges:[d,p],mapFunc:h}=b.virtualizeDiscreteRanges([a,s]),{row:S,col:f}=h(d.startRow,d.startColumn),{row:w,col:_}=h(p.startRow,p.startColumn),I=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:f,endColumn:f}),C=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:_,endColumn:_});if(!I||!C||!this._copyInfo)return{redos:[],undos:[]};const R=C.startX-I.startX,y=C.startY-I.startY,T=w-S,v=_-f;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)+y},sheetTransform:{...N,to:{...N.to,row:N.to.row+T,column:N.to.column+v},from:{...N.from,row:N.from.row+T,column:N.from.column+v}}}},isCut:l===b.COPY_TYPE.CUT})}};He=en([Oe(0,b.ISheetClipboardService),Oe(1,j.IRenderManagerService),Oe(2,W.IDrawingManagerService),Oe(3,B.IClipboardInterfaceService),Oe(4,c.ICommandService)],He);var on=Object.getOwnPropertyDescriptor,sn=(o,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ae=(o,r)=>(t,e)=>r(t,e,o);let Xe=class extends c.Disposable{constructor(o,r,t,e,n){super(),this._drawingManagerService=o,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=U.combineLatest([o,r]);this.disposeWithMe(t.pipe(U.switchMap(([e,n])=>e?e.activeSheet$.pipe(U.tap(i=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookViewPermission(s).id,new D.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,i)})):(this._drawingManagerService.setDrawingVisible(!1),U.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(o,r){this._drawingManagerService.setDrawingVisible(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=U.combineLatest([o,r]);this.disposeWithMe(t.pipe(U.switchMap(([e,n])=>e?e.activeSheet$.pipe(U.tap(i=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookEditablePermission(s).id,new D.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,i)})):(this._drawingManagerService.setDrawingEditable(!1),U.EMPTY))).subscribe())}_handleDrawingEditableFalse(o,r){this._drawingManagerService.setDrawingEditable(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(U.combineLatest([o,r]).pipe(U.switchMap(([t,e])=>t?t.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),l=a==null?void 0:a.scene;if(!l)return U.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookViewPermission(i).id,new D.WorksheetViewPermission(i,s).id]).pipe(U.map(d=>d.every(p=>p.value)),U.distinctUntilChanged()).pipe(U.map(d=>({permission:d,scene:l,transformer:g,unitId:i,subUnitId:s})))})):U.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(i,s),g=Object.values(l);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===j.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(),i=e==null?void 0:e.getSheetId();if(!n||!i)return;const s=this._drawingManagerService.getDrawingData(n,i),a=Object.values(s);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(U.combineLatest([o,r]).pipe(U.switchMap(([t,e])=>t?t.activeSheet$.pipe(U.switchMap(n=>{if(!n)return U.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),l=a==null?void 0:a.scene;if(!l)return U.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookEditablePermission(i).id,new D.WorksheetEditPermission(i,s).id]).pipe(U.map(d=>d.every(p=>p.value)),U.distinctUntilChanged()).pipe(U.map(d=>({permission:d,scene:l,transformer:g,unitId:i,subUnitId:s})))})):U.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(i,s),g=Object.values(l);t?(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===j.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 i=n.getSheetId(),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;const l=this._drawingManagerService.getDrawingData(e,i),g=Object.values(l);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(d=>{d.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>d.oKey.includes(p.drawingId))&&a.detachTransformerFrom(d)})}}))}};Xe=sn([Ae(0,W.IDrawingManagerService),Ae(1,j.IRenderManagerService),Ae(2,c.IPermissionService),Ae(3,c.IUniverInstanceService),Ae(4,c.Inject(c.UserManagerService))],Xe);var an=Object.getOwnPropertyDescriptor,cn=(o,r,t,e)=>{for(var n=e>1?void 0:e?an(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},he=(o,r)=>(t,e)=>r(t,e,o);function Rt(o,r,t,e,n,i=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),l=r.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:d,xSplit:p,ySplit:h}=g,S={left:!0,top:!0};if(!l)return{...o,absolute:S};const{left:f,right:w,top:_,bottom:I}=o;let{top:C,left:R,viewportScrollX:y,viewportScrollY:T}=l;const{boundsOfViewArea:v,scrollDirectionResponse:P}=n||{},{rowHeaderWidth:E,columnHeaderHeight:N}=t,k={top:i?0:N,left:i?0:E};v&&(c.Tools.isDefine(k.top)&&(k.top=v.top),c.Tools.isDefine(k.left)&&(k.left=v.left)),P==="HORIZONTAL"&&(T=0),P==="VERTICAL"&&(y=0);let A=0,M=0;const Y=t.rowStartY(d-h)+N,L=t.colStartX(u-p)+E,Z=t.rowStartY(d)+N,ee=t.colStartX(u)+E;if(p===0)S.left=!1,A=(f-y)*s,M=(w-y)*s;else{const K=f-(L-E),F=w-(L-E);w<ee?(A=K*s,M=F*s):f<=ee&&w>=ee?(A=K*s,M=Math.max(R,(w-y)*s)):f>ee&&(S.left=!1,A=Math.max((f-y)*s,R),M=Math.max((w-y)*s,R))}let V=0,z=0;if(h===0)S.top=!1,V=(_-T)*a,z=(I-T)*a;else{const K=_-(Y-N),F=I-(Y-N);I<Z?(V=K*a,z=F*a):_<=Z&&I>=Z?(V=K*a,z=Math.max(C,(I-T)*a)):_>Z&&(S.top=!1,V=Math.max((_-T)*a,C),z=Math.max((I-T)*a,C))}return A=Math.max(A,k.left),V=Math.max(V,k.top),M=Math.max(M,k.left),z=Math.max(z,k.top),{left:A,right:M,top:V,bottom:z,absolute:S}}const oe=(o,r,t,e,n)=>{const{left:i,top:s,width:a,height:l,angle:g}=o,u={left:i,right:i+a,top:s,bottom:s+l},d=Rt(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,i,s,a,l){super();re(this,"_domLayerInfoMap",new Map);re(this,"_transformChange$",new U.Subject);re(this,"transformChange$",this._transformChange$.asObservable());re(this,"_add$",new U.Subject);re(this,"add$",this._add$.asObservable());re(this,"_remove$",new U.Subject);re(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=i,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(U.filter(t=>t===c.LifecycleStages.Rendered),U.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 i=n.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:n,transformer:i,renderUnit:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var K;const{unitId:n,subUnitId:i,drawingId:s}=e,a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),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(i);if(!d)return;const{transform:p,drawingType:h,data:S}=l;if(h!==c.DrawingTypeEnum.DRAWING_DOM&&h!==c.DrawingTypeEnum.DRAWING_CHART)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:w,canvas:_}=f;if(p==null)return!0;if(u!==i)return;const{left:I,top:C,width:R,height:y,angle:T,flipX:v,flipY:P,skewX:E,skewY:N}=p,k=W.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:s}),A=w.getObject(k);if(A!=null){A.transformByState({left:I,top:C,width:R,height:y,angle:T,flipX:v,flipY:P,skewX:E,skewY:N});return}const M={left:I,top:C,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,i).length-1},Y=h===c.DrawingTypeEnum.DRAWING_CHART;if(M.rotateEnabled=!1,Y){const F=S?S.backgroundColor:"white";M.fill=F,S&&S.border&&(M.stroke=S.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const L=new j.Rect(k,M);Y&&L.setObjectType(j.ObjectType.CHART),w.addObject(L,j.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&w.attachTransformerTo(L);const Z=new c.DisposableCollection,ee=oe(L,f.renderUnit.scene,d.skeleton,a.worksheet),V=new U.BehaviorSubject(ee),z={dispose:Z,rect:L,position$:V,unitId:n,subUnitId:i,id:s};this._canvasFloatDomService.addFloatDom({position$:V,id:s,componentKey:l.componentKey,onPointerDown:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{_.dispatchEvent(new WheelEvent(F.type,F))},data:S,unitId:n});const te=L.onTransformChange$.subscribeEvent(()=>{const F=oe(L,f.renderUnit.scene,d.skeleton,a.worksheet);V.next(F)});Z.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),te&&Z.add(te),this._domLayerInfoMap.set(s,z)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:i,drawingId:s}=e,a=W.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,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 i=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=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),l=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(b.SheetSkeletonManagerService).getSkeletonParam(n);!i||!a||!l||s.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const p=oe(d.rect,i.renderUnit.scene,l.skeleton,a.worksheet,d);d.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(U.switchMap(e=>e?e.activeSheet$:U.of(null)),U.map(e=>{if(!e)return null;const n=e.getUnitId(),i=this._renderManagerService.getRenderById(n);return i?{render:i,unitId:n,subUnitId:e.getSheetId()}:null}),U.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(U.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):U.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:i}=e;t(n,i)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===b.SetZoomRatioOperation.id){const n=e.params,{unitId:i}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===i).map(a=>a.subUnitId).forEach(a=>{t(i,a)})}else if(e.id===D.SetFrozenMutation.id){const{unitId:n,subUnitId:i}=e.params;t(n,i)}}))}_getPosition(t,e){var h;const{startX:n,endX:i,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(i,a);if(d==null)return;const p={column:d.actualColumn,columnOffset:i-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 i={...n.transform};this._transformChange$.next({id:e.drawingId,value:i})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,i){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(s&&a){const{scene:l}=a,g=W.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=l.getObject(g);u&&u instanceof j.Rect&&u.setProps(i)}}addFloatDomToPosition(t,e){const n=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:i,subUnitId:s}=n,{initPosition:a,componentKey:l,data:g,allowTransform:u=!0}=t,d=e!=null?e:c.generateRandomId(),p=this._getPosition(a,i);if(p==null)return;const h={unitId:i,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(Te.id,{unitId:i,drawings:[h]}),this._add$.next({unitId:i,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:i,subUnitId:s}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(i);if(a&&a.scene.removeObject(n.rect),e){const l=this._drawingManagerService.getDrawingByParam({unitId:i,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:i,subUnitId:s,op:u,objects:d,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,i){var v,P,E;const s=D.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=(v=this._renderManagerService.getRenderById(a))==null?void 0:v.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver(t,u,d.skeleton);if(this._getPosition(w,a)==null)return;const C=g.scene,{scaleX:R}=C.getAncestorScale(),y=Ve(w,n,R),T={unitId:a,subUnitId:l,drawingId:f,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:S};{const{unitId:N,subUnitId:k,drawingId:A}=T,M=D.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:k}),Y=T,L=this._univerInstanceService.getUnit(N,c.UniverInstanceType.UNIVER_SHEET);if(!L)return;const Z=L.getActiveSheet().getSheetId();if(!Y||!M)return;const ee=(P=this._renderManagerService.getRenderById(N))==null?void 0:P.with(b.SheetSkeletonManagerService);if(!ee)return;const V=ee.getWorksheetSkeleton(k);if(!V)return;const{transform:z,drawingType:te,data:K}=Y;if(te!==c.DrawingTypeEnum.DRAWING_DOM&&te!==c.DrawingTypeEnum.DRAWING_CHART)return;const F=this._getSceneAndTransformerByDrawingSearch(N);if(F==null)return;const{scene:ve,canvas:Ie}=F;if(z==null||Z!==k)return;const{left:qe,top:Ze,width:Je,height:Qe,angle:_t,flipX:vt,flipY:et,skewX:tt,skewY:ye}=z,nt=W.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:k,drawingId:A}),se=ve.getObject(nt);if(se!=null){se.transformByState({left:qe,top:Ze,width:Je,height:Qe,angle:_t,flipX:vt,flipY:et,skewX:tt,skewY:ye});return}const ne={left:qe,top:Ze,width:Je,height:Qe,zIndex:this._drawingManagerService.getDrawingOrder(N,k).length-1},De=te===c.DrawingTypeEnum.DRAWING_CHART;if(De){const $=K?K.backgroundColor:"white";ne.fill=$,ne.rotateEnabled=!1,K&&K.border&&(ne.stroke=K.border),ne.paintFirst="stroke",ne.strokeWidth=1,ne.borderEnabled=!1,ne.radius=8}const ae=new j.Rect(nt,ne);De&&ae.setObjectType(j.ObjectType.CHART),ve.addObject(ae,j.DRAWING_OBJECT_LAYER_INDEX),Y.allowTransform!==!1&&ve.attachTransformerTo(ae);const ce=new c.DisposableCollection,rt=ve.getMainViewport(),{rowHeaderWidth:Ce,columnHeaderHeight:Ne}=V.skeleton,it={top:Ne,left:Ce,bottom:rt.bottom,right:rt.right},de={dispose:ce,rect:ae,boundsOfViewArea:it,domAnchor:n,unitId:N,subUnitId:k},X=oe(ae,F.renderUnit.scene,V.skeleton,M.worksheet,de),Me=new U.BehaviorSubject(X);de.position$=Me;let ke={position$:Me,id:A,componentKey:Y.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Ie.dispatchEvent(new WheelEvent($.type,$))},data:K,unitId:N};e.eventPassThrough&&(ke={...ke,onPointerDown:$=>{Ie.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Ie.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Ie.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(ke),this.disposeWithMe(_.subscribe($=>{var Ot,At,Pt,Ut;const bt=Ve({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Ot=n.width)!=null?Ot:$.width,height:(At=n.height)!=null?At:$.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Nn=W.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:k,drawingId:A}),kn=new j.Rect(Nn,{left:bt.startX,top:bt.startY,width:(Pt=n.width)!=null?Pt:$.width,height:(Ut=n.height)!=null?Ut:$.height,zIndex:this._drawingManagerService.getDrawingOrder(N,k).length-1}),Wn=oe(kn,F.renderUnit.scene,V.skeleton,M.worksheet,de);Me.next(Wn)}));const We=(E=this._renderManagerService.getRenderById(N))==null?void 0:E.with(b.SheetSkeletonManagerService);We==null||We.currentSkeleton$.subscribe($=>{$&&V.sheetId!==$.sheetId&&this._removeDom(f,!0)});const ot=ae.onTransformChange$.subscribeEvent(()=>{const $=oe(ae,F.renderUnit.scene,V.skeleton,M.worksheet,de);Me.next($)});ce.add(()=>{this._canvasFloatDomService.removeFloatDom(A)}),ot&&ce.add(ot),this._domLayerInfoMap.set(A,de)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}addFloatDomToColumnHeader(t,e,n,i){var y,T,v;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:l}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),I=w;if(I.startY=0,this._getPosition(w,a)==null)return;const R={unitId:a,subUnitId:l,drawingId:f,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:S};{const{unitId:P,subUnitId:E,drawingId:N}=R,k=D.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:E}),A=R,M=this._univerInstanceService.getUnit(P,c.UniverInstanceType.UNIVER_SHEET);if(!M)return;const Y=M.getActiveSheet().getSheetId();if(!A||!k)return;const L=(T=this._renderManagerService.getRenderById(P))==null?void 0:T.with(b.SheetSkeletonManagerService);if(!L)return;const Z=L.getWorksheetSkeleton(E);if(!Z)return;const{transform:ee,data:V}=A,z=this._getSceneAndTransformerByDrawingSearch(P);if(z==null)return;const{scene:te,canvas:K}=z;if(ee==null||Y!==E)return;const{left:F,top:ve,width:Ie,height:qe,angle:Ze,flipX:Je,flipY:Qe,skewX:_t,skewY:vt}=ee,et=W.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:E,drawingId:N}),tt=te.getObject(et);if(tt!=null){tt.transformByState({left:F,top:ve,width:Ie,height:qe,angle:Ze,flipX:Je,flipY:Qe,skewX:_t,skewY:vt});return}const ye=Ve({startX:I.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),nt={left:ye.startX,top:ye.startY,width:ye.width,height:ye.height,zIndex:this._drawingManagerService.getDrawingOrder(P,E).length-1},se=new j.Rect(et,nt);te.addObject(se,j.DRAWING_OBJECT_LAYER_INDEX),A.allowTransform!==!1&&te.attachTransformerTo(se);const ne=new c.DisposableCollection,De=te.getMainViewport(),ae={top:0,left:De.left,bottom:De.bottom,right:De.right},ce={dispose:ne,rect:se,unitId:P,subUnitId:E,boundsOfViewArea:ae,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},rt=oe(se,z.renderUnit.scene,Z.skeleton,k.worksheet,ce),Ce=new U.BehaviorSubject(rt);ce.position$=Ce;let Ne={position$:Ce,id:N,componentKey:A.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:X=>{K.dispatchEvent(new WheelEvent(X.type,X))},data:V,unitId:P};e.eventPassThrough&&(Ne={...Ne,onPointerDown:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{K.dispatchEvent(new PointerEvent(X.type,X))}}),this._canvasFloatDomService.addFloatDom(Ne);const it=se.onTransformChange$.subscribeEvent(()=>{const X=oe(se,z.renderUnit.scene,Z.skeleton,k.worksheet,ce);Ce.next(X)});this.disposeWithMe(_.subscribe(X=>{const Me=Ve({startX:X.startX,startY:0,endX:X.endX,endY:X.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),ke=W.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:E,drawingId:N}),We=new j.Rect(ke,{left:Me.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(P,E).length-1}),ot=oe(We,z.renderUnit.scene,Z.skeleton,k.worksheet,ce);Ce.next(ot)}));const de=(v=this._renderManagerService.getRenderById(P))==null?void 0:v.with(b.SheetSkeletonManagerService);de==null||de.currentSkeleton$.subscribe(X=>{X&&d.sheetId!==X.sheetId&&this._removeDom(f,!0)}),ne.add(()=>{this._canvasFloatDomService.removeFloatDom(N)}),it&&ne.add(it),this._domLayerInfoMap.set(N,ce)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:i,startColumn:s}=t;const a=Pe(i,s,n),l=new U.BehaviorSubject(a),g=Pe(t.endRow,t.endColumn,n),u=new U.BehaviorSubject(g),d=()=>{const _=Pe(i,s,n),I=Pe(t.endRow,t.endColumn,n);l.next(_),u.next(I)},p=new c.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>d())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===D.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===i)>-1){d();return}(D.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===b.SetScrollOperation.id||_.id===b.SetZoomRatioOperation.id)&&d()}));const h=(_,I)=>{i=_,s=I,d()},S=()=>({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}),f=l.pipe(U.map(_=>{const I=Pe(t.endRow,t.endColumn,n);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),w=S();return{position$:f,position:w,updateRowCol:h,topLeftPos$:l,rightBottomPos$:u,disposable:p}}},O.SheetCanvasFloatDomManagerService=cn([he(0,c.Inject(j.IRenderManagerService)),he(1,c.IUniverInstanceService),he(2,c.Inject(c.ICommandService)),he(3,W.IDrawingManagerService),he(4,c.Inject(B.CanvasFloatDomService)),he(5,m.ISheetDrawingService),he(6,c.Inject(c.LifecycleService))],O.SheetCanvasFloatDomManagerService);function Pe(o,r,t){const e=t.getCellWithCoordByIndex(o,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ve(o,r,t){var g,u;t=t!=null?t:1;const e=o.endX-o.startX,n=o.endY-o.startY,i=(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=Ke(r.marginX,e*t);a=o.endX-d-i}else a=o.startX+Ke(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const d=Ke(r.marginY,n*t);l=o.endY-d-s}else l=o.startY+Ke(r.marginY,n)}return{rotate:0,startX:a,startY:l,endX:o.endX,endY:o.endY,width:i,height:s,absolute:{left:o.absolute.left,top:o.absolute.top}}}function Ke(o,r){if(o===void 0)return 0;if(typeof o=="number")return o;const t=Number.parseFloat(o);return r*t/100}const dn=o=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=o,i=me.useMemo(()=>r.map(s=>{const{width:a,height:l,angle:g,left:u,top:d}=s.transform,p=Rt({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:S}=t.getAncestorScale(),f={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:l*S,absolute:p.absolute},w={position$:new U.BehaviorSubject(f),position:f,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:i.map(([s,a])=>J.jsx(B.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var ln=Object.getOwnPropertyDescriptor,un=(o,r,t,e)=>{for(var n=e>1?void 0:e?ln(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},pe=(o,r)=>(t,e)=>r(t,e,o);let ze=class extends c.Disposable{constructor(o,r,t,e,n,i,s){super(),this._sheetPrintInterceptorService=o,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=i,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(o,r,t)=>{const{unitId:e,scene:n,subUnitId:i}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[i];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:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._renderManagerService.getRenderById(e);if(!i)return t(o);const s=i.with(b.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)return t(o);const a=this._drawingManagerService.getDrawingDataForUnit(e),l=a==null?void 0:a[r.subUnitId];if(!l)return t(o);const{scaleX:g,scaleY:u}=i.scene,d=o?{...o}:{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 S=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),f=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});S.column<d.startColumn&&(d.startColumn=S.column),S.row<d.startRow&&(d.startRow=S.row),d.endRow<f.row&&(d.endRow=f.row),d.endColumn<f.column&&(d.endColumn=f.column)}}),t(d)):t(o)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._drawingManagerService.getDrawingDataForUnit(e),s=i==null?void 0:i[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(dn,this._injector);return q.render(J.jsx(l,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),o==null||o.add(()=>{q.unmount(r.root)}),t(o)}}}))}};ze=un([pe(0,c.Inject(b.SheetPrintInterceptorService)),pe(1,c.Inject(le.DrawingRenderService)),pe(2,W.IDrawingManagerService),pe(3,j.IRenderManagerService),pe(4,c.Inject(O.SheetCanvasFloatDomManagerService)),pe(5,c.Inject(B.ComponentManager)),pe(6,c.Inject(c.Injector))],ze);var gn=Object.getOwnPropertyDescriptor,hn=(o,r,t,e)=>{for(var n=e>1?void 0:e?gn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ue=(o,r)=>(t,e)=>r(t,e,o);const pn=[D.InsertRowCommand.id,D.InsertColCommand.id,D.RemoveRowCommand.id,D.RemoveColCommand.id,D.DeleteRangeMoveLeftCommand.id,D.DeleteRangeMoveUpCommand.id,D.InsertRangeMoveDownCommand.id,D.InsertRangeMoveRightCommand.id,D.DeltaRowHeightCommand.id,D.SetRowHeightCommand.id,D.DeltaColumnWidthCommand.id,D.SetColWidthCommand.id,D.SetRowHiddenCommand.id,D.SetSpecificRowsVisibleCommand.id,D.SetSpecificColsVisibleCommand.id,D.SetColHiddenCommand.id,D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id],mn=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetColWidthMutation.id];let mt=class extends c.Disposable{constructor(o,r,t,e,n,i,s,a,l){super(),this._context=o,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=i,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{if(!pn.includes(o.id))return{redos:[],undos:[]};if(o.params==null)return{redos:[],undos:[]};const r=o.id;if(r===D.InsertRowCommand.id)return this._moveRowInterceptor(o.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(o.params);if(r===D.InsertColCommand.id)return this._moveColInterceptor(o.params,"insert");if(r===D.RemoveRowCommand.id)return this._moveRowInterceptor(o.params,"remove");if(r===D.RemoveColCommand.id)return this._moveColInterceptor(o.params,"remove");if(r===D.DeleteRangeMoveLeftCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,0)}else if(r===D.DeleteRangeMoveUpCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,1)}else if(r===D.InsertRangeMoveDownCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,2)}else if(r===D.InsertRangeMoveRightCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,3)}else if(r===D.SetRowHiddenCommand.id||r===D.SetSpecificRowsVisibleCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForRowVisible(e,n,i)}else if(r===D.SetSpecificColsVisibleCommand.id||r===D.SetColHiddenCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForColVisible(e,n,i)}else if(r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id||r===D.DeltaColumnWidthCommand.id||r===D.SetColWidthCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t,s=r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,i,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(o,r){const t=D.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,i=[],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(o,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;i.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;i.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 i.push({id:G.id,params:[e]}),s.push({id:G.id,params:[e]}),{redos:i,undos:s}}_getUpdateOrDeleteDrawings(o,r,t){const e=[],n=[],{sheetTransform:i,anchorType:s=m.SheetDrawingAnchorType.Position,transform:a,unitId:l,subUnitId:g,drawingId:u}=t,{from:d,to:p}=i,{row:h,column:S}=d,{row:f,column:w}=p;if(i==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:I,startColumn:C,endColumn:R}=o;let y=null,T=null;if(r===0&&h>=_&&f<=I)if(S>=C&&w<=R)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(i,a,C,R,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===1&&S>=C&&w<=R)if(h>=_&&f<=I)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(i,a,C,R,s);y=v==null?void 0:v.newSheetTransform,T=v==null?void 0:v.newTransform}if(y!=null&&T!=null){const v=x(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:v})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(o,r,t){const e=H({...o},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:v,endRow:P,startColumn:E,endColumn:N}=T;if(R<E)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(I>=E&&I<=N){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:N,startRow:f.row,endRow:w.row});if(L==null)return;Y={...h,left:L.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(I>=E&&R<=N)continue;let k=null,A=null;if(I>=E&&I<=N){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:N,startRow:f.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:f.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:f.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){i.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&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),l=[],g=[];if(i.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(o,r,i);l.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:l,preUndos:g}}_createUndoAndRedoMutation(o,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:i,objects:s}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:i,objects:s,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[o]}],l=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:n,objects:s,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[o]}];return{redos:a,undos:l}}_getDrawingUndoForRowVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=d;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:R}=w;for(let y=0;y<t.length;y++){const T=t[y],{startRow:v,endRow:P,startColumn:E,endColumn:N}=T;if(C<v)continue;if(S===m.SheetDrawingAnchorType.Position){let M=null,Y=null;if(_>=v&&_<=P){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:P});if(L==null)return;Y={...h,top:L.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&&C<=P)continue;let k=null,A=null;if(_>=v&&_<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:P});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(C>=v&&C<=P){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:C});if(M==null)return;A={...h,top:M.startY-((h==null?void 0:h.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:P});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){i.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&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),l=[],g=[];if(i.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(o,r,i);l.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:l,preUndos:g}}_getDrawingUndoForRowAndColSize(o,r,t,e){const n=this._drawingManagerService.getDrawingData(o,r),i=[];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,i,a);else{const{from:d,to:p}=l,{row:h,column:S}=d,{row:f,column:w}=p;for(let _=0;_<t.length;_++){const I=t[_],{startRow:C,endRow:R,startColumn:y,endColumn:T}=I;if(f<C||w<y)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=C&&f>=R||S<=y&&w>=T)){this._remainDrawingSize(g,i,a);continue}const v=x({...l},this._selectionRenderService,this._skeletonManagerService);if(v!=null){i.push({...a,transform:v});break}}}}),i.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(o,r,i)}_getUnitIdAndSubUnitId(o,r){let t,e;if(r==="insert")t=o.unitId,e=o.subUnitId;else{const n=D.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(o){var C,R;const{toRange:r,fromRange:t}=o,e=D.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:i}=e,s=(R=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.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,i),h=[];Object.keys(p).forEach(y=>{const T=p[y];if(T.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=T;if(!v)return;const{left:P=0,top:E=0,width:N=0,height:k=0}=v,{drawingStartX:A,drawingEndX:M,drawingStartY:Y,drawingEndY:L}={drawingStartX:P,drawingEndX:P+N,drawingStartY:E,drawingEndY:E+k};l<=A&&M<=g&&u<=Y&&L<=d&&h.push(T)});const S=[],f=[],w=r.startRow-t.startRow,_=r.startColumn-t.startColumn,I=h.map(y=>{const T=y.sheetTransform,v={to:{...T.to,row:T.to.row+w,column:T.to.column+_},from:{...T.from,row:T.from.row+w,column:T.from.column+_}},P=x(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:i,drawingId:y.drawingId,transform:P,sheetTransform:v}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:v,objects:P}=y;S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:v,objects:P,type:m.DrawingApplyType.UPDATE}}),f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:T,objects:P,type:m.DrawingApplyType.UPDATE}})}return{redos:S,undos:f}}_moveRowInterceptor(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startRow,a=i.endRow,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandRow(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:T}=f,{row:v}=y,{row:P}=T;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&P<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkRow(f,w,s,a,_);I=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,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(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startColumn,a=i.endColumn,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandCol(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:T}=f,{column:v}=y,{column:P}=T;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&P<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkCol(f,w,s,a,_);I=E==null?void 0:E.newSheetTransform,C=E==null?void 0:E.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};d.push(R)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:S,redo:f,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,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(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{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+i}},d=x(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(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{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-i},to:{...a,column:g-i}},d=x(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-i}},d=x(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)-o.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-o.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=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{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+i}},d=x(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(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{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-i},to:{...a,row:g-i}},d=x(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-i}},d=x(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)-o.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-o.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=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===D.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=o.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(o=>{const{unit:r,unitId:t}=this._context;if(o){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(o){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(i=>{const s=n[i].data;s!=null&&Object.keys(s).forEach(a=>{e===o&&t.push(s[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(o,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(i=>{const s=t[i];s!=null&&Object.keys(s).forEach(a=>{const l=s[a].data;l!=null&&Object.keys(l).forEach(g=>{if(i===o&&a===r){const u=l[g];u.transform=x(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(o=>{mn.includes(o.id)&&requestIdleCallback(()=>{const r=o.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[];Object.keys(e).forEach(i=>{const s=e[i],{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:S,column:f}=d;for(let w=0;w<t.length;w++){const _=t[w],{startRow:I,endRow:C,startColumn:R,endColumn:y}=_;if(c.Rectangle.intersects({startRow:I,endRow:C,startColumn:R,endColumn:y},{startRow:p,endRow:S,startColumn:h,endColumn:f})||p>C||h>y){const T=g===m.SheetDrawingAnchorType.Position,v=x(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...v,width:T?l==null?void 0:l.width:v==null?void 0:v.width,height:T?l==null?void 0:l.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[o]))}};mt=hn([ue(1,j.IRenderManagerService),ue(2,c.ICommandService),ue(3,b.ISheetSelectionRenderService),ue(4,c.Inject(b.SheetSkeletonManagerService)),ue(5,c.Inject(D.SheetInterceptorService)),ue(6,m.ISheetDrawingService),ue(7,W.IDrawingManagerService),ue(8,c.IUniverInstanceService)],mt);const ft={id:"sheet.command.delete-drawing",type:c.CommandType.COMMAND,handler:o=>{const r=o.get(c.ICommandService),e=o.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,i=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(fe.id,{unitId:n,drawings:i})}},we={id:"sheet.command.move-drawing",type:c.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(c.ICommandService),e=o.get(m.ISheetDrawingService),n=o.get(b.ISheetSelectionRenderService),{direction:i}=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:S=0}=d;return i===c.Direction.UP?p.top=S-1:i===c.Direction.DOWN?p.top=S+1:i===c.Direction.LEFT?p.left=h-1:i===c.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:H(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Re.id,{unitId:a,drawings:l})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},fn=o=>{var I;const r=B.useDependency(c.ICommandService),t=B.useDependency(c.LocaleService),e=B.useDependency(W.IDrawingManagerService),n=B.useDependency(j.IRenderManagerService),{drawings:i}=o,s=i[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]=me.useState(!0),h=(I=s.anchorType)!=null?I:m.SheetDrawingAnchorType.Position,[S,f]=me.useState(h);function w(C,R){const y=[];return C.forEach(T=>{const{oKey:v}=T,P=R.getDrawingOKey(v);if(P==null)return y.push(null),!0;const{unitId:E,subUnitId:N,drawingId:k,drawingType:A,anchorType:M,sheetTransform:Y}=P;y.push({unitId:E,subUnitId:N,drawingId:k,anchorType:M,sheetTransform:Y,drawingType:A})}),y}me.useEffect(()=>{const C=u.clearControl$.subscribe(y=>{y===!0&&p(!1)}),R=u.changeStart$.subscribe(y=>{var P;const{objects:T}=y,v=w(T,e);if(v.length===0)p(!1);else if(v.length>=1){p(!0);const E=((P=v[0])==null?void 0:P.anchorType)||m.SheetDrawingAnchorType.Position;f(E)}});return()=>{R.unsubscribe(),C.unsubscribe()}},[]);function _(C){f(C);const R=e.getFocusDrawings();if(R.length===0)return;const y=R.map(T=>({unitId:T.unitId,subUnitId:T.subUnitId,drawingId:T.drawingId,anchorType:C}));r.executeCommand(Re.id,{unitId:R[0].unitId,drawings:y})}return J.jsxs("div",{className:q.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(q.RadioGroup,{value:S,onChange:_,direction:"vertical",children:[J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})]})},Sn=()=>{const o=B.useDependency(W.IDrawingManagerService),r=o.getFocusDrawings(),[t,e]=me.useState(r);return me.useEffect(()=>{const n=o.focus$.subscribe(i=>{e(i)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&J.jsxs("div",{className:"univer-text-sm",children:[J.jsx(le.DrawingCommonPanel,{drawings:t}),J.jsx(fn,{drawings:t})]})},St="sheet.menu.image";function wn(o){return{id:St,type:B.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(o,c.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(o,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function _n(o){return{id:be.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,c.UniverInstanceType.UNIVER_SHEET)}}function vn(o){return{id:pt.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,c.UniverInstanceType.UNIVER_SHEET)}}const In={[B.RibbonInsertGroup.MEDIA]:{[St]:{order:0,menuItemFactory:wn,[be.id]:{order:0,menuItemFactory:_n},[pt.id]:{order:1,menuItemFactory:vn}}}};function Ue(o){return!o.getContextValue(c.FOCUSING_FX_BAR_EDITOR)&&!o.getContextValue(c.EDITOR_ACTIVATED)&&!o.getContextValue(c.FOCUSING_PANEL_EDITOR)&&o.getContextValue(c.FOCUSING_COMMON_DRAWINGS)}const yn={id:we.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:Ue,staticParameters:{direction:c.Direction.DOWN}},Dn={id:we.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:Ue,staticParameters:{direction:c.Direction.UP}},Cn={id:we.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:Ue,staticParameters:{direction:c.Direction.LEFT}},Mn={id:we.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:Ue,staticParameters:{direction:c.Direction.RIGHT}},Tn={id:ft.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:Ue,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var Rn=Object.getOwnPropertyDescriptor,En=(o,r,t,e)=>{for(var n=e>1?void 0:e?Rn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},_e=(o,r)=>(t,e)=>r(t,e,o);let xe=class extends c.Disposable{constructor(o,r,t,e,n,i){super(),this._componentManager=o,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=i,this._init()}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(yt,Sn))}_initMenus(){this._menuManagerService.mergeMenu(In)}_initCommands(){[be,pt,Te,fe,Re,st,G,at,lt,gt,we,ft,ut].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initShortcuts(){[yn,Dn,Cn,Mn,Tn].forEach(o=>{this.disposeWithMe(this._shortcutService.registerShortcut(o))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};xe=En([_e(0,c.Inject(B.ComponentManager)),_e(1,B.IMenuManagerService),_e(2,c.ICommandService),_e(3,B.IShortcutService),_e(4,W.IDrawingManagerService),_e(5,c.Inject(D.SheetsSelectionsService))],xe);var bn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,An=(o,r,t)=>r in o?bn(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,Pn=(o,r,t,e)=>{for(var n=e>1?void 0:e?On(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},wt=(o,r)=>(t,e)=>r(t,e,o),Et=(o,r,t)=>An(o,typeof r!="symbol"?r+"":r,t);const Un="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends c.Plugin{constructor(r=It,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:i,...s}=c.merge({},It,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Nt,s)}onStarting(){c.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[xe],[Be],[ze],[Xe],[He],[$e],[Le],[Ge]]),c.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){c.touchDependencies(this._injector,[[He],[Ge]])}onRendered(){this._registerRenderModules(),c.touchDependencies(this._injector,[[Xe],[ze],[xe],[$e],[Le]])}onSteady(){this._injector.get(Be)}_registerRenderModules(){[[O.SheetDrawingUpdateController],[mt],[dt],[ct]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,r))})}},Et(O.UniverSheetsDrawingUIPlugin,"type",c.UniverInstanceType.UNIVER_SHEET),Et(O.UniverSheetsDrawingUIPlugin,"pluginName",Un),O.UniverSheetsDrawingUIPlugin=Pn([c.DependentOn(W.UniverDrawingPlugin,ge.UniverDocsDrawingPlugin,le.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),wt(1,c.Inject(c.Injector)),wt(2,j.IRenderManagerService),wt(3,c.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=G,O.DeleteDrawingsCommand=ft,O.EditSheetDrawingOperation=at,O.GroupSheetDrawingCommand=lt,O.InsertFloatImageCommand=be,O.InsertSheetDrawingCommand=Te,O.MoveDrawingsCommand=we,O.RemoveSheetDrawingCommand=fe,O.SHEETS_IMAGE_MENU_ID=St,O.SetDrawingArrangeCommand=ut,O.SetSheetDrawingCommand=Re,O.SidebarSheetDrawingOperation=st,O.UngroupSheetDrawingCommand=gt,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.8.0-beta.0",
3
+ "version": "0.8.0-beta.1",
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.8.0-beta.0",
61
- "@univerjs/drawing": "0.8.0-beta.0",
62
- "@univerjs/drawing-ui": "0.8.0-beta.0",
63
- "@univerjs/sheets-drawing": "0.8.0-beta.0",
64
- "@univerjs/sheets-drawing-ui": "0.8.0-beta.0"
60
+ "@univerjs/docs-drawing": "0.8.0-beta.1",
61
+ "@univerjs/drawing": "0.8.0-beta.1",
62
+ "@univerjs/drawing-ui": "0.8.0-beta.1",
63
+ "@univerjs/sheets-drawing": "0.8.0-beta.1",
64
+ "@univerjs/sheets-drawing-ui": "0.8.0-beta.1"
65
65
  },
66
66
  "devDependencies": {
67
- "@univerjs/core": "0.8.0-beta.0",
67
+ "@univerjs/core": "0.8.0-beta.1",
68
68
  "react": "18.3.1",
69
69
  "react-dom": "18.3.1",
70
70
  "rxjs": "7.8.2",
71
71
  "typescript": "^5.8.3",
72
- "@univerjs-infra/shared": "0.8.0-beta.0"
72
+ "@univerjs-infra/shared": "0.8.0-beta.1"
73
73
  },
74
74
  "scripts": {
75
75
  "prebuild:preset": "tsx prepare.ts",