@univerjs/sheets-crosshair-highlight 0.10.12 → 0.10.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var W=Object.defineProperty;var F=(n,e,t)=>e in n?W(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var l=(n,e,t)=>F(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),u=require("rxjs"),w=require("@univerjs/engine-render"),_=require("@univerjs/ui"),P=require("react/jsx-runtime"),j=require("@univerjs/design"),v=require("react"),T=require("@univerjs/sheets"),M=require("@univerjs/sheets-ui"),x=["rgba(158, 109, 227, 0.3)","rgba(254, 75, 75, 0.3)","rgba(255, 140, 81, 0.3)","rgba(164, 220, 22, 0.3)","rgba(45, 174, 255, 0.3)","rgba(58, 96, 247, 0.3)","rgba(242, 72, 166, 0.3)","rgba(153, 153, 153, 0.3)","rgba(158, 109, 227, 0.15)","rgba(254, 75, 75, 0.15)","rgba(255, 140, 81, 0.15)","rgba(164, 220, 22, 0.15)","rgba(45, 174, 255, 0.15)","rgba(58, 96, 247, 0.15)","rgba(242, 72, 166, 0.15)","rgba(153, 153, 153, 0.15)"];class d extends a.Disposable{constructor(){super(...arguments);l(this,"_enabled$",new u.BehaviorSubject(!1));l(this,"enabled$",this._enabled$.asObservable());l(this,"_color$",new u.BehaviorSubject(x[0]));l(this,"color$",this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(t){this._enabled$.next(t)}setColor(t){this._color$.next(t)}}const I={id:"sheet.operation.toggle-crosshair-highlight",type:a.CommandType.OPERATION,handler(n){const e=n.get(d),t=e.enabled;return e.setEnabled(!t),!0}},$={id:"sheet.operation.set-crosshair-highlight-color",type:a.CommandType.OPERATION,handler(n,{value:e}){const t=n.get(d);return t.enabled||t.setEnabled(!0),t.setColor(e),!0}},L={id:"sheet.operation.enable-crosshair-highlight",type:a.CommandType.OPERATION,handler(n){const e=n.get(d);return e.enabled?!1:(e.setEnabled(!0),!0)}},G={id:"sheet.operation.disable-crosshair-highlight",type:a.CommandType.OPERATION,handler(n){const e=n.get(d);return e.enabled?(e.setEnabled(!1),!0):!1}},X="sheets-crosshair-highlight.config",A={};var h=function(){return h=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},h.apply(this,arguments)},z=function(n,e){var t={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(n);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(t[r[i]]=n[r[i]]);return t},V=v.forwardRef(function(n,e){var t=n.icon,r=n.id,i=n.className,s=n.extend,o=z(n,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),g=v.useRef("_".concat(Q()));return k(t,"".concat(r),{defIds:t.defIds,idSuffix:g.current},h({ref:e,className:c},o),s)});function k(n,e,t,r,i){return v.createElement(n.tag,h(h({key:e},K(n,t,i)),r),(J(n,t).children||[]).map(function(s,o){return k(s,"".concat(e,"-").concat(n.tag,"-").concat(o),t,void 0,i)}))}function K(n,e,t){var r=h({},n.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1),n.tag==="mask"&&r.id&&(r.id=r.id+e.idSuffix),Object.entries(r).forEach(function(s){var o=s[0],c=s[1];o==="mask"&&typeof c=="string"&&(r[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var i=e.defIds;return!i||i.length===0||(n.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+e.idSuffix),Object.entries(r).forEach(function(s){var o=s[0],c=s[1];typeof c=="string"&&(r[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function J(n,e){var t,r=e.defIds;return!r||r.length===0?n:n.tag==="defs"&&(!((t=n.children)===null||t===void 0)&&t.length)?h(h({},n),{children:n.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.includes(i.attrs.id)?h(h({},i),{attrs:h(h({},i.attrs),{id:i.attrs.id+e.idSuffix})}):i})}):n}function Q(){return Math.random().toString(36).substring(2,8)}V.displayName="UniverIcon";var ee={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:"M3.6498 1.05005C2.21386 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.3501V3.65005C14.9498 2.21411 13.7857 1.05005 12.3498 1.05005H3.6498ZM5.4002 2.25005H3.6498C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V5.40002H5.4002V2.25005ZM2.2498 10.6V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H5.4002V10.6H2.2498ZM6.60019 13.75H9.4002V9.40002H13.7498V6.60002H9.4002V2.25005H6.60019V6.60002H2.25029V9.40002H6.60019V13.75ZM10.6002 2.25005V5.40002H13.7498V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H10.6002ZM13.7498 10.6H10.6002V13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.6Z",fillRule:"evenodd",clipRule:"evenodd"}}]},U=v.forwardRef(function(n,e){return v.createElement(V,Object.assign({},n,{id:"cross-highlighting-icon",ref:e,icon:ee}))});U.displayName="CrossHighlightingIcon";function te(n){const{onChange:e}=n,t=_.useDependency(d),r=_.useObservable(t.color$),i=v.useCallback(s=>{e==null||e(s)},[e]);return P.jsx("div",{className:"univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3",children:x.map(s=>P.jsx("div",{className:j.clsx("hover:univer-ring-primary-600/40 hover:univer-ring-[1.5px] univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow",j.borderClassName,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":s===r}),style:{backgroundColor:s},onClick:()=>i(s)},s))})}const D="CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT";function re(n){const e=n.get(d);return{id:I.id,tooltip:"crosshair.button.tooltip",type:_.MenuItemType.BUTTON_SELECTOR,icon:"CrossHighlightingIcon",selections:[{label:{name:D,hoverable:!1,selectable:!1}}],selectionsCommandId:$.id,activated$:e.enabled$,hidden$:_.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const ne={[_.ContextMenuPosition.FOOTER_MENU]:{[_.ContextMenuGroup.OTHERS]:{[I.id]:{order:0,menuItemFactory:re}}}};var ie=Object.getOwnPropertyDescriptor,se=(n,e,t,r)=>{for(var i=r>1?void 0:r?ie(e,t):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=o(i)||i);return i},E=(n,e)=>(t,r)=>e(t,r,n);let H=class extends a.Disposable{constructor(n,e,t){super(),this._componentMgr=n,this._menuManagerService=e,this._cmdSrv=t,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[I,$,L,G].forEach(n=>this._cmdSrv.registerCommand(n))}_initMenus(){this._menuManagerService.mergeMenu(ne)}_initComponents(){this._componentMgr.register(D,te),this._componentMgr.register("CrossHighlightingIcon",U)}};H=se([E(0,a.Inject(_.ComponentManager)),E(1,_.IMenuManagerService),E(2,a.ICommandService)],H);const oe=1;class ae{constructor(){l(this,"_selectedRanges",[]);l(this,"_ranges",[])}addRange(e){if(e.rangeType===a.RANGE_TYPE.COLUMN||e.rangeType===a.RANGE_TYPE.ROW||e.rangeType===a.RANGE_TYPE.ALL)return;const t=this._getIntersects(e),r=this._getSplitRanges(e,t);r.length>0&&this._ranges.push(...r)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let r=[e];for(const i of t.concat(this._selectedRanges)){const s=[];for(const o of r){const c=a.Rectangle.subtract(o,i);c&&c.length>0&&s.push(...c)}r=s}return r.filter(i=>i.startRow<=i.endRow&&i.startColumn<=i.endColumn)}_getIntersects(e){const t=[];for(const r of this._ranges){const i=a.Rectangle.getIntersects(r,e);i&&t.push(i)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}}class ce extends w.Shape{constructor(t,r){super(t,r);l(this,"_color");r&&this.setShapeProps(r)}setShapeProps(t){typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){var i,s;const r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(s=(i=this._color)==null?void 0:i.a)!=null?s:.5})`;w.Rect.drawWith(t,{width:this.width,height:this.height,fill:r,stroke:void 0,strokeWidth:0,evented:!1})}}var le=Object.getOwnPropertyDescriptor,he=(n,e,t,r)=>{for(var i=r>1?void 0:r?le(e,t):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=o(i)||i);return i},p=(n,e)=>(t,r)=>e(t,r,n);let O=class extends a.Disposable{constructor(e,t,r,i,s,o){super();l(this,"_shapes",[]);l(this,"_rangeCollection",new ae);l(this,"_color","rgba(255,0,0,0.5)");this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=r,this._sheetsCrosshairHighlightService=i,this._contextService=s,this._refSelectionsService=o,this._initRenderListener()}_transformSelection(e,t){if(!e)return;const r=t.getRowCount(),i=t.getColumnCount(),s=[];for(const o of e){const{startRow:c,endRow:g,startColumn:S,endColumn:C}=o.range;g-c+1===r||C-S+1===i||s.push(o.range)}this._rangeCollection.setSelectedRanges(s);for(const o of s)this.addSelection(o,t)}_initRenderListener(){const e=this._context.unit;this.disposeWithMe(u.combineLatest([this._contextService.subscribeContextValue$(T.REF_SELECTIONS_ENABLED).pipe(u.startWith(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(u.tap(t=>this._color=t)),u.merge(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(u.map(()=>this._sheetsSelectionsService.getCurrentSelections()))),u.merge(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(u.map(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,r,i,s,o,c])=>{if(this._clear(),!i)return;const g=t?c:o;this._rangeCollection.reset(),this._transformSelection(g,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,t){if(e.rangeType===a.RANGE_TYPE.COLUMN||e.rangeType===a.RANGE_TYPE.ROW||e.rangeType===a.RANGE_TYPE.ALL)return;const r=t.getRowCount(),i=t.getColumnCount(),{startRow:s,endRow:o,startColumn:c,endColumn:g}=e,S={startRow:s,endRow:o,startColumn:0,endColumn:c-1},C={startRow:s,endRow:o,startColumn:g+1,endColumn:i},m={startRow:0,endRow:s-1,startColumn:c,endColumn:g},b={startRow:o+1,endRow:r,startColumn:c,endColumn:g};for(const f of[S,C,m,b])f.startRow<=f.endRow&&f.startColumn<=f.endColumn&&this._rangeCollection.addRange(f)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(e,t,r,i){const{startRow:s,endRow:o,startColumn:c,endColumn:g}=e,S=M.getCoordByCell(s,c,r,i),C=M.getCoordByCell(o,g,r,i),{startX:m,startY:b}=S,{endX:f,endY:Y}=C,q=f-m,B=Y-b,Z={left:m,top:b,color:new a.ColorKit(this._color).toRgb(),width:q,height:B,zIndex:oe,evented:!1},N=new ce(`crosshair-${t}`,Z);this._shapes.push(N),r.addObject(N)}render(e){const t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;const{scene:r}=this._context;this._clear();for(let i=0;i<e.length;i++){const s=e[i];this._addShapes(s,i,r,t)}r.makeDirty(!0)}async dispose(){super.dispose()}};O=he([p(1,a.Inject(M.SheetSkeletonManagerService)),p(2,a.Inject(T.SheetsSelectionsService)),p(3,a.Inject(d)),p(4,a.Inject(a.IContextService)),p(5,T.IRefSelectionsService)],O);var ge=Object.getOwnPropertyDescriptor,ue=(n,e,t,r)=>{for(var i=r>1?void 0:r?ge(e,t):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=o(i)||i);return i},y=(n,e)=>(t,r)=>e(t,r,n),R;exports.UniverSheetsCrosshairHighlightPlugin=(R=class extends a.Plugin{constructor(e=A,t,r,i){super(),this._config=e,this._injector=t,this._renderManagerService=r,this._configService=i;const{...s}=a.merge({},A,this._config);this._configService.setConfig(X,s)}onStarting(){[[d],[H]].forEach(e=>this._injector.add(e))}onReady(){[[O]].forEach(e=>this._injector.add(e)),this._injector.get(H),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[O])}},l(R,"pluginName","SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN"),l(R,"type",a.UniverInstanceType.UNIVER_SHEET),R);exports.UniverSheetsCrosshairHighlightPlugin=ue([y(1,a.Inject(a.Injector)),y(2,w.IRenderManagerService),y(3,a.IConfigService)],exports.UniverSheetsCrosshairHighlightPlugin);exports.CROSSHAIR_HIGHLIGHT_COLORS=x;exports.DisableCrosshairHighlightOperation=G;exports.EnableCrosshairHighlightOperation=L;exports.SetCrosshairHighlightColorOperation=$;exports.SheetsCrosshairHighlightService=d;exports.ToggleCrosshairHighlightOperation=I;
1
+ "use strict";var Z=Object.defineProperty;var W=(i,e,t)=>e in i?Z(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var l=(i,e,t)=>W(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),g=require("rxjs"),$=require("@univerjs/engine-render"),v=require("react"),d=require("@univerjs/ui"),N=require("react/jsx-runtime"),P=require("@univerjs/design"),T=require("@univerjs/sheets"),w=require("@univerjs/sheets-ui"),y=["rgba(158, 109, 227, 0.3)","rgba(254, 75, 75, 0.3)","rgba(255, 140, 81, 0.3)","rgba(164, 220, 22, 0.3)","rgba(45, 174, 255, 0.3)","rgba(58, 96, 247, 0.3)","rgba(242, 72, 166, 0.3)","rgba(153, 153, 153, 0.3)","rgba(158, 109, 227, 0.15)","rgba(254, 75, 75, 0.15)","rgba(255, 140, 81, 0.15)","rgba(164, 220, 22, 0.15)","rgba(45, 174, 255, 0.15)","rgba(58, 96, 247, 0.15)","rgba(242, 72, 166, 0.15)","rgba(153, 153, 153, 0.15)"];class u extends a.Disposable{constructor(){super(...arguments);l(this,"_enabled$",new g.BehaviorSubject(!1));l(this,"enabled$",this._enabled$.asObservable());l(this,"_color$",new g.BehaviorSubject(y[0]));l(this,"color$",this._color$.asObservable())}get enabled(){return this._enabled$.getValue()}get color(){return this._color$.getValue()}dispose(){this._enabled$.complete()}setEnabled(t){this._enabled$.next(t)}setColor(t){this._color$.next(t)}}const I={id:"sheet.operation.toggle-crosshair-highlight",type:a.CommandType.OPERATION,handler(i){const e=i.get(u),t=e.enabled;return e.setEnabled(!t),!0}},M={id:"sheet.operation.set-crosshair-highlight-color",type:a.CommandType.OPERATION,handler(i,{value:e}){const t=i.get(u);return t.enabled||t.setEnabled(!0),t.setColor(e),!0}},A={id:"sheet.operation.enable-crosshair-highlight",type:a.CommandType.OPERATION,handler(i){const e=i.get(u);return e.enabled?!1:(e.setEnabled(!0),!0)}},L={id:"sheet.operation.disable-crosshair-highlight",type:a.CommandType.OPERATION,handler(i){const e=i.get(u);return e.enabled?(e.setEnabled(!1),!0):!1}},F="sheets-crosshair-highlight.config",j={};function G({ref:i,...e}){const{icon:t,id:r,className:s,extend:n,...o}=e,c=`univerjs-icon univerjs-icon-${r} ${s||""}`.trim(),h=v.useRef(`_${K()}`);return V(t,`${r}`,{defIds:t.defIds,idSuffix:h.current},{ref:i,className:c,...o},n)}function V(i,e,t,r,s){return v.createElement(i.tag,{key:e,...X(i,t,s),...r},(z(i,t).children||[]).map((n,o)=>V(n,`${e}-${i.tag}-${o}`,t,void 0,s)))}function X(i,e,t){const r={...i.attrs};t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1),i.tag==="mask"&&r.id&&(r.id=r.id+e.idSuffix),Object.entries(r).forEach(([n,o])=>{n==="mask"&&typeof o=="string"&&(r[n]=o.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))});const{defIds:s}=e;return!s||s.length===0||(i.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+e.idSuffix),Object.entries(r).forEach(([n,o])=>{typeof o=="string"&&(r[n]=o.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))})),r}function z(i,e){var r;const{defIds:t}=e;return!t||t.length===0?i:i.tag==="defs"&&((r=i.children)!=null&&r.length)?{...i,children:i.children.map(s=>typeof s.attrs.id=="string"&&t&&t.includes(s.attrs.id)?{...s,attrs:{...s.attrs,id:s.attrs.id+e.idSuffix}}:s)}:i}function K(){return Math.random().toString(36).substring(2,8)}G.displayName="UniverIcon";const J={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:"M3.6498 1.05005C2.21386 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.3501V3.65005C14.9498 2.21411 13.7857 1.05005 12.3498 1.05005H3.6498ZM5.4002 2.25005H3.6498C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V5.40002H5.4002V2.25005ZM2.2498 10.6V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H5.4002V10.6H2.2498ZM6.60019 13.75H9.4002V9.40002H13.7498V6.60002H9.4002V2.25005H6.60019V6.60002H2.25029V9.40002H6.60019V13.75ZM10.6002 2.25005V5.40002H13.7498V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H10.6002ZM13.7498 10.6H10.6002V13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.6Z",fillRule:"evenodd",clipRule:"evenodd"}}]},U=v.forwardRef(function(e,t){return v.createElement(G,Object.assign({},e,{id:"cross-highlighting-icon",ref:t,icon:J}))});U.displayName="CrossHighlightingIcon";function Q(i){const{onChange:e}=i,t=d.useDependency(u),r=d.useObservable(t.color$),s=v.useCallback(n=>{e==null||e(n)},[e]);return N.jsx("div",{className:"univer-grid univer-grid-cols-8 univer-gap-x-2 univer-gap-y-3",children:y.map(n=>N.jsx("div",{className:P.clsx("hover:univer-ring-primary-600/40 hover:univer-ring-[1.5px] univer-box-border univer-size-5 univer-cursor-pointer univer-rounded univer-ring-offset-1 univer-transition-shadow",P.borderClassName,{"univer-ring-[1.5px] univer-ring-primary-600 hover:univer-ring-primary-600":n===r}),style:{backgroundColor:n},onClick:()=>s(n)},n))})}const k="CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT";function ee(i){const e=i.get(u);return{id:I.id,tooltip:"crosshair.button.tooltip",type:d.MenuItemType.BUTTON_SELECTOR,icon:"CrossHighlightingIcon",selections:[{label:{name:k,hoverable:!1,selectable:!1}}],selectionsCommandId:M.id,activated$:e.enabled$,hidden$:d.getMenuHiddenObservable(i,a.UniverInstanceType.UNIVER_SHEET)}}const te={[d.ContextMenuPosition.FOOTER_MENU]:{[d.ContextMenuGroup.OTHERS]:{[I.id]:{order:0,menuItemFactory:ee}}}};var re=Object.getOwnPropertyDescriptor,se=(i,e,t,r)=>{for(var s=r>1?void 0:r?re(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(s=o(s)||s);return s},E=(i,e)=>(t,r)=>e(t,r,i);let b=class extends a.Disposable{constructor(i,e,t){super(),this._componentMgr=i,this._menuManagerService=e,this._cmdSrv=t,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[I,M,A,L].forEach(i=>this._cmdSrv.registerCommand(i))}_initMenus(){this._menuManagerService.mergeMenu(te)}_initComponents(){this._componentMgr.register(k,Q),this._componentMgr.register("CrossHighlightingIcon",U)}};b=se([E(0,a.Inject(d.ComponentManager)),E(1,d.IMenuManagerService),E(2,a.ICommandService)],b);const ie=1;class ne{constructor(){l(this,"_selectedRanges",[]);l(this,"_ranges",[])}addRange(e){if(e.rangeType===a.RANGE_TYPE.COLUMN||e.rangeType===a.RANGE_TYPE.ROW||e.rangeType===a.RANGE_TYPE.ALL)return;const t=this._getIntersects(e),r=this._getSplitRanges(e,t);r.length>0&&this._ranges.push(...r)}setSelectedRanges(e){this._selectedRanges=e}_getSplitRanges(e,t){let r=[e];for(const s of t.concat(this._selectedRanges)){const n=[];for(const o of r){const c=a.Rectangle.subtract(o,s);c&&c.length>0&&n.push(...c)}r=n}return r.filter(s=>s.startRow<=s.endRow&&s.startColumn<=s.endColumn)}_getIntersects(e){const t=[];for(const r of this._ranges){const s=a.Rectangle.getIntersects(r,e);s&&t.push(s)}return t}getRanges(){return this._ranges}reset(){this._ranges=[],this._selectedRanges=[]}}class oe extends $.Shape{constructor(t,r){super(t,r);l(this,"_color");r&&this.setShapeProps(r)}setShapeProps(t){typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){var s,n;const r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, ${(n=(s=this._color)==null?void 0:s.a)!=null?n:.5})`;$.Rect.drawWith(t,{width:this.width,height:this.height,fill:r,stroke:void 0,strokeWidth:0,evented:!1})}}var ae=Object.getOwnPropertyDescriptor,ce=(i,e,t,r)=>{for(var s=r>1?void 0:r?ae(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(s=o(s)||s);return s},C=(i,e)=>(t,r)=>e(t,r,i);let H=class extends a.Disposable{constructor(e,t,r,s,n,o){super();l(this,"_shapes",[]);l(this,"_rangeCollection",new ne);l(this,"_color","rgba(255,0,0,0.5)");this._context=e,this._sheetSkeletonManagerService=t,this._sheetsSelectionsService=r,this._sheetsCrosshairHighlightService=s,this._contextService=n,this._refSelectionsService=o,this._initRenderListener()}_transformSelection(e,t){if(!e)return;const r=t.getRowCount(),s=t.getColumnCount(),n=[];for(const o of e){const{startRow:c,endRow:h,startColumn:S,endColumn:f}=o.range;h-c+1===r||f-S+1===s||n.push(o.range)}this._rangeCollection.setSelectedRanges(n);for(const o of n)this.addSelection(o,t)}_initRenderListener(){const e=this._context.unit;this.disposeWithMe(g.combineLatest([this._contextService.subscribeContextValue$(T.REF_SELECTIONS_ENABLED).pipe(g.startWith(!1)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsCrosshairHighlightService.enabled$,this._sheetsCrosshairHighlightService.color$.pipe(g.tap(t=>this._color=t)),g.merge(this._sheetsSelectionsService.selectionMoveStart$,this._sheetsSelectionsService.selectionMoving$,this._sheetsSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(g.map(()=>this._sheetsSelectionsService.getCurrentSelections()))),g.merge(this._refSelectionsService.selectionMoveStart$,this._refSelectionsService.selectionMoving$,this._refSelectionsService.selectionMoveEnd$,this._sheetsSelectionsService.selectionSet$,e.activeSheet$.pipe(g.map(()=>this._refSelectionsService.getCurrentSelections())))]).subscribe(([t,r,s,n,o,c])=>{if(this._clear(),!s)return;const h=t?c:o;this._rangeCollection.reset(),this._transformSelection(h,e.getActiveSheet()),this.render(this._rangeCollection.getRanges())}))}addSelection(e,t){if(e.rangeType===a.RANGE_TYPE.COLUMN||e.rangeType===a.RANGE_TYPE.ROW||e.rangeType===a.RANGE_TYPE.ALL)return;const r=t.getRowCount(),s=t.getColumnCount(),{startRow:n,endRow:o,startColumn:c,endColumn:h}=e,S={startRow:n,endRow:o,startColumn:0,endColumn:c-1},f={startRow:n,endRow:o,startColumn:h+1,endColumn:s},p={startRow:0,endRow:n-1,startColumn:c,endColumn:h},m={startRow:o+1,endRow:r,startColumn:c,endColumn:h};for(const _ of[S,f,p,m])_.startRow<=_.endRow&&_.startColumn<=_.endColumn&&this._rangeCollection.addRange(_)}_clear(){this._shapes.forEach(e=>{e.dispose()}),this._shapes=[]}_addShapes(e,t,r,s){const{startRow:n,endRow:o,startColumn:c,endColumn:h}=e,S=w.getCoordByCell(n,c,r,s),f=w.getCoordByCell(o,h,r,s),{startX:p,startY:m}=S,{endX:_,endY:D}=f,Y=_-p,q=D-m,B={left:p,top:m,color:new a.ColorKit(this._color).toRgb(),width:Y,height:q,zIndex:ie,evented:!1},x=new oe(`crosshair-${t}`,B);this._shapes.push(x),r.addObject(x)}render(e){const t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;const{scene:r}=this._context;this._clear();for(let s=0;s<e.length;s++){const n=e[s];this._addShapes(n,s,r,t)}r.makeDirty(!0)}async dispose(){super.dispose()}};H=ce([C(1,a.Inject(w.SheetSkeletonManagerService)),C(2,a.Inject(T.SheetsSelectionsService)),C(3,a.Inject(u)),C(4,a.Inject(a.IContextService)),C(5,T.IRefSelectionsService)],H);var le=Object.getOwnPropertyDescriptor,he=(i,e,t,r)=>{for(var s=r>1?void 0:r?le(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(s=o(s)||s);return s},O=(i,e)=>(t,r)=>e(t,r,i),R;exports.UniverSheetsCrosshairHighlightPlugin=(R=class extends a.Plugin{constructor(e=j,t,r,s){super(),this._config=e,this._injector=t,this._renderManagerService=r,this._configService=s;const{...n}=a.merge({},j,this._config);this._configService.setConfig(F,n)}onStarting(){[[u],[b]].forEach(e=>this._injector.add(e))}onReady(){[[H]].forEach(e=>this._injector.add(e)),this._injector.get(b),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[H])}},l(R,"pluginName","SHEET_CROSSHAIR_HIGHLIGHT_PLUGIN"),l(R,"type",a.UniverInstanceType.UNIVER_SHEET),R);exports.UniverSheetsCrosshairHighlightPlugin=he([O(1,a.Inject(a.Injector)),O(2,$.IRenderManagerService),O(3,a.IConfigService)],exports.UniverSheetsCrosshairHighlightPlugin);exports.CROSSHAIR_HIGHLIGHT_COLORS=y;exports.DisableCrosshairHighlightOperation=L;exports.EnableCrosshairHighlightOperation=A;exports.SetCrosshairHighlightColorOperation=M;exports.SheetsCrosshairHighlightService=u;exports.ToggleCrosshairHighlightOperation=I;