@univerjs/docs-ui 0.9.3-nightly.202507250819 → 0.9.4
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/LICENSE +176 -0
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +2 -2
- package/lib/index.js +2 -2
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/lib/cjs/index.js
CHANGED
|
@@ -10,7 +10,7 @@ ${i.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
|
|
|
10
10
|
`," ");let s=this._umdToHtml.convert(t);if(t.length===1&&e){s=s.replace(/(<[a-z]+)/,(m,g)=>`${g} data-copy-id="${n}"`);const d=t[0],u={body:d.body};if((l=(c=d.body)==null?void 0:c.customBlocks)!=null&&l.length){u.drawings={};for(const m of d.body.customBlocks){const{blockId:g}=m,h=(A=d.drawings)==null?void 0:A[g];if(h){const p=i.generateRandomId(6);m.blockId=p,u.drawings[p]={...i.Tools.deepClone(h),drawingId:p}}}}Dn.set(n,u)}return this._clipboardInterfaceService.write(r,s)}addClipboardHook(t){return this._clipboardHooks.push(t),i.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t,e){var d;const n=this._univerInstanceService.getCurrentUniverDocInstance(),r=e!=null?e:this._docSelectionManagerService.getDocRanges(),s=[];let a=!0;if(n==null||r.length===0)return;const c=r[0].segmentId,l=(d=n==null?void 0:n.getSelfOrHeaderFooterModel(c))==null?void 0:d.getBody(),A=n.getSnapshot();if(l!=null){for(const u of r){const{startOffset:m,endOffset:g,collapsed:h,rangeType:p}=u;if(h||m==null||g==null)continue;if(p===i.DOC_RANGE_TYPE.RECT){a=!1;const{spanEntireRow:E}=u;let C;C=lr(l,m,g),s.push(C);continue}const f={startOffset:m,endOffset:g},S=n.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,t);S!=null&&s.push(S)}return{newSnapshotList:s.map(u=>({...A,body:u})),needCache:a,snapshot:A,ranges:r}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const r=[];for(const s of t)for(const a of s.types)switch(a){case I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await s.getType(a).then(c=>c&&c.text());break}case I.HTML_CLIPBOARD_MIME_TYPE:{e=await s.getType(a).then(c=>c&&c.text());break}case I.FILE__BMP_CLIPBOARD_MIME_TYPE:case I.FILE__JPEG_CLIPBOARD_MIME_TYPE:case I.FILE__WEBP_CLIPBOARD_MIME_TYPE:case I.FILE_PNG_CLIPBOARD_MIME_TYPE:{const c=await s.getType(a),l=new File([c],`pasted_image.${a.split("/")[1]}`,{type:a});r.push(l);break}}return!e&&!n&&r.length&&(e=await this._createImagePasteHtml(r)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:i.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const r=qs(t);if(r){const a=Dn.get(r);if(a)return a}if(!n){const a=this._univerInstanceService.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);n=(a==null?void 0:a.getUnitId())||""}const s=this._htmlToUDM.convert(t,{unitId:n});return r&&Dn.set(r,s),s}async _createImagePasteHtml(t){var c,l;const e={id:"",documentStyle:{},body:{dataStream:"",customBlocks:[]},drawings:{}},n=async A=>{const d=new FileReader;return new Promise(u=>{d.onloadend=function(){u({source:d.result,imageSourceType:co.ImageSourceType.BASE64})},d.readAsDataURL(A)})},r=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const g=Math.min(u,d.naturalWidth),h=d.naturalHeight/d.naturalWidth;m({width:g,height:g*h})}})},s=(l=(c=this._clipboardHooks.find(A=>A.onBeforePasteImage))==null?void 0:c.onBeforePasteImage)!=null?l:n;return await Promise.all(t.map(async(A,d)=>{var S;const u=await s(A);if(!u)return Promise.resolve();const{width:m=100,height:g=100}=await r(A),h=`paste_image_id_${d}`,p=e.body,f=e.drawings;p.dataStream+="\b",(S=p.customBlocks)==null||S.push({startIndex:d,blockId:h}),f[h]={drawingId:h,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:i.PositionedObjectLayoutType.INLINE,drawingType:i.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:g,angle:0},docTransform:{angle:0,size:{width:m,height:g},positionH:{relativeFrom:i.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:i.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};jn=oa([lt(0,i.IUniverInstanceService),lt(1,i.ILogService),lt(2,i.ICommandService),lt(3,I.IClipboardInterfaceService),lt(4,i.Inject(D.DocSelectionManagerService))],jn);function pn(o){return o.getContextValue(i.FOCUSING_DOC)||o.getContextValue(i.EDITOR_ACTIVATED)}const Eo=999,vt={id:I.CopyCommand.id,name:"doc.command.copy",type:i.CommandType.COMMAND,multi:!0,priority:Eo,preconditions:pn,handler:async o=>o.get(Be).copy()},Co={id:"doc.command.copy-current-paragraph",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(Be),e=bt(o);return e?t.copy(i.SliceBodyType.copy,[{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1}]):!1}},fn={id:I.CutCommand.id,name:"doc.command.cut",type:i.CommandType.COMMAND,multi:!0,priority:Eo,preconditions:pn,handler:async o=>o.get(Be).cut()},To={id:"doc.command.cut-current-paragraph",type:i.CommandType.COMMAND,handler:async o=>{const t=o.get(Be),e=bt(o);return e?t.cut([{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1,rangeType:i.DOC_RANGE_TYPE.TEXT}]):!1}},Sn={id:I.PasteCommand.id,name:"doc.command.paste",type:i.CommandType.COMMAND,multi:!0,priority:Eo,preconditions:pn,handler:async o=>{const t=o.get(Be),n=await o.get(I.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}},xt={id:"doc.command.horizontal-line",type:i.CommandType.COMMAND,handler:(o,t)=>o.get(i.ICommandService).syncExecuteCommand(cn.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:i.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},yo={id:"doc.command.insert-horizontal-line-bellow",type:i.CommandType.COMMAND,handler:o=>{const t=o.get(i.ICommandService),e=bt(o);return e?t.syncExecuteCommand(xt.id,{insertRange:{startOffset:e.startIndex+1,endOffset:e.startIndex+1}}):!1}},bo={id:"doc.command.select-all",type:i.CommandType.COMMAND,handler:async o=>{var g;const t=o.get(i.IUniverInstanceService),e=o.get(D.DocSelectionManagerService),n=t.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),r=e.getDocRanges(),s=(g=r.find(h=>h.isActive))!=null?g:r[0];if(n==null||s==null)return!1;const{segmentId:a}=s,c=n.getUnitId(),l=n.getSelfOrHeaderFooterModel(a).getSnapshot().body;if(l==null)return!1;const{tables:A=[],dataStream:d}=l;if(d===`\r
|
|
11
11
|
`)return!0;const u=[];let m=0;for(const h of A){const{startIndex:p,endIndex:f}=h;m!==p&&u.push({startOffset:m,endOffset:p-1,rangeType:i.DOC_RANGE_TYPE.TEXT}),u.push({startOffset:p+3,endOffset:f-5,rangeType:i.DOC_RANGE_TYPE.RECT}),m=f}return m!==l.dataStream.length-2&&u.push({startOffset:m,endOffset:l.dataStream.length-2,rangeType:i.DOC_RANGE_TYPE.TEXT}),e.replaceDocRanges(u,{unitId:c,subUnitId:c},!1),!0}};class Ot extends i.RxDisposable{constructor(e){super();M(this,"_previousActiveRange",null);M(this,"_undoMutationParamsCache",[]);M(this,"_redoMutationParamsCache",[]);this._context=e}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:e=[],redoCache:n=[]}){this._undoMutationParamsCache=e,this._redoMutationParamsCache=n}getActiveRange(){return this._previousActiveRange}setActiveRange(e){this._previousActiveRange=e}pushUndoRedoMutationParams(e,n){this._undoMutationParamsCache.push(e),this._redoMutationParamsCache.push(n)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:e}=this._undoMutationParamsCache[0],n={unitId:e,actions:this._undoMutationParamsCache.reverse().reduce((s,a)=>i.JSONX.compose(s,a.actions),null),textRanges:[]};return{redoMutationParams:{unitId:e,actions:this._redoMutationParamsCache.reduce((s,a)=>i.JSONX.compose(s,a.actions),null),textRanges:[]},undoMutationParams:n,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Ro={id:"doc.command.ime-input",type:i.CommandType.COMMAND,handler:async(o,t)=>{var L,G,W;const{unitId:e,newText:n,oldTextLen:r,isCompositionEnd:s,isCompositionStart:a}=t,c=o.get(i.ICommandService),l=o.get(B.IRenderManagerService),A=o.get(i.IUniverInstanceService),d=o.get(ve),u=(L=l.getRenderById(e))==null?void 0:L.with(Ot),m=A.getUnit(e,i.UniverInstanceType.UNIVER_DOC);if(m==null||u==null)return!1;const g=u.getActiveRange();if(g==null)return!1;const{style:h,segmentId:p}=g,f=m.getSelfOrHeaderFooterModel(p).getBody();if(f==null)return!1;Object.assign(g,g);const{startOffset:E,endOffset:C}=g,T=n.length,R=[{startOffset:E+T,endOffset:E+T,collapsed:!0,style:h}],v={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:R}},b=d.getDefaultStyle(),x=d.getStyleCache(),y=lo((G=f.customRanges)!=null?G:[],E+r,i.SHEET_EDITOR_UNITS.includes(e)),_=an(f,a?C:E+r,b,x,i.SHEET_EDITOR_UNITS.includes(e)),O=Ao((W=f.customDecorations)!=null?W:[],E+r),w=new i.TextX,Q=i.JSONX.getInstance();if(!g.collapsed&&a){const H=i.BuildTextUtils.selection.delete([g],f,0,null,!1);w.push(...H),v.params.textRanges=[{startOffset:E+T,endOffset:E+T,collapsed:!0}]}else w.push({t:i.TextXActionType.RETAIN,len:E});r>0&&w.push({t:i.TextXActionType.DELETE,len:r}),w.push({t:i.TextXActionType.INSERT,body:{dataStream:n,textRuns:_?[{..._,st:0,ed:n.length}]:[],customRanges:y?[{...y,startIndex:0,endIndex:n.length-1}]:[],customDecorations:O.map(H=>({...H,startIndex:0,endIndex:n.length-1}))},len:n.length});const k=J(m,p);v.params.actions=Q.editOp(w.serialize(),k),v.params.noHistory=!s,v.params.isCompositionEnd=s;const F=c.syncExecuteCommand(v.id,v.params);return u.pushUndoRedoMutationParams(F,v.params),!!F}};function ue(o,t,e){return e.executeCommand(be.id,{preCommandId:o,...t!=null?t:{}})}const dr="doc.command.set-inline-format-bold",_e={id:dr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(dr,t,e)}},Ar="doc.command.set-inline-format-italic",Ne={id:Ar,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Ar,t,e)}},ur="doc.command.set-inline-format-underline",Pe={id:ur,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(ur,t,e)}},gr="doc.command.set-inline-format-strikethrough",we={id:gr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(gr,t,e)}},hr="doc.command.set-inline-format-subscript",ye={id:hr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(hr,t,e)}},mr="doc.command.set-inline-format-superscript",Ue={id:mr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(mr,t,e)}},pr="doc.command.set-inline-format-fontsize",me={id:pr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(pr,t,e)}},fr="doc.command.set-inline-format-font-family",Xe={id:fr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(fr,t,e)}},Sr="doc.command.set-inline-format-text-color",Me={id:Sr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Sr,t,e)}},Ir="doc.command.set-inline-format-text-background-color",De={id:Ir,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(Ir,t,e)}},vr="doc.command.reset-inline-format-text-background-color",st={id:vr,type:i.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(i.ICommandService);return ue(vr,t,e)}},Wn={[_e.id]:"bl",[Ne.id]:"it",[Pe.id]:"ul",[we.id]:"st",[me.id]:"fs",[Xe.id]:"ff",[Me.id]:"cl",[De.id]:"bg",[st.id]:"bg",[ye.id]:"va",[Ue.id]:"va"},be={id:"doc.command.set-inline-format",type:i.CommandType.COMMAND,handler:async(o,t)=>{var R;const{value:e,preCommandId:n}=t,r=o.get(i.ICommandService),s=o.get(D.DocSelectionManagerService),a=o.get(i.IUniverInstanceService),c=o.get(ve),l=s.getDocRanges(),A=(R=l.find(v=>v.isActive))!=null?R:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=a.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const g=u.getUnitId();let h;switch(n){case _e.id:case Ne.id:case Pe.id:case we.id:case ye.id:case Ue.id:{const v=c.getDefaultStyle(),b=pi(m,A,v);h=ia(b,n);break}case me.id:case Xe.id:{h=e;break}case Me.id:case De.id:{h={rgb:e};break}case st.id:{h={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:l}},f=new i.TextX,S=i.JSONX.getInstance(),E=new i.MemoryCursor;E.reset();for(const v of l){let{startOffset:b,endOffset:x,rangeType:y}=v;if(b==null||x==null)continue;if(y===i.DOC_RANGE_TYPE.RECT&&(b=b-1),b===x){const w=c.getStyleCache(),Q=Wn[n];c.setStyleCache({[Q]:(w==null?void 0:w[Q])!==void 0?mi(w,Q,n):h});continue}const _={dataStream:"",textRuns:[{st:0,ed:x-b,ts:{[Wn[n]]:h}}]},O=b-E.cursor;O!==0&&f.push({t:i.TextXActionType.RETAIN,len:O}),f.push({t:i.TextXActionType.RETAIN,body:_,len:x-b}),E.reset(),E.moveCursor(x)}const C=J(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!r.syncExecuteCommand(p.id,p.params)}};function ra(o){return o!==null&&typeof o=="object"}function mi(o,t,e){if(/bl|it/.test(t))return(o==null?void 0:o[t])===i.BooleanNumber.TRUE?i.BooleanNumber.FALSE:i.BooleanNumber.TRUE;if(/ul|st/.test(t))return ra(o==null?void 0:o[t])&&(o==null?void 0:o[t]).s===i.BooleanNumber.TRUE?{s:i.BooleanNumber.FALSE}:{s:i.BooleanNumber.TRUE};if(/va/.test(t))return e===ye.id?(o==null?void 0:o[t])===i.BaselineOffset.SUBSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUBSCRIPT:(o==null?void 0:o[t])===i.BaselineOffset.SUPERSCRIPT?i.BaselineOffset.NORMAL:i.BaselineOffset.SUPERSCRIPT}function pi(o,t,e){var d,u,m,g,h,p,f,S,E,C,T,R,v,b;const{startOffset:n,endOffset:r,collapsed:s}=t;if(s){const x=(d=o.textRuns)!=null?d:[];let y=null;for(let _=x.length-1;_>=0;_--){const O=x[_];if(O.st<n&&n<=O.ed){y=O;break}}return y!=null&&y.ts?{...e,...y.ts}:e}const{textRuns:a=[]}=i.getBodySlice(o,n,r),c=i.Tools.deepClone(e),l=a.map(x=>{var y;return(y=x==null?void 0:x.ts)==null?void 0:y.fs}).filter(Boolean);c.fs=c.fs?Math.max(c.fs,...l):l.length?Math.max(...l):void 0,c.fs=!c.fs||Number.isNaN(c.fs)?void 0:c.fs,c.ff=(g=(m=(u=a.find(x=>{var y;return((y=x.ts)==null?void 0:y.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?g:c.ff,c.it=a.length&&a.every(x=>{var y;return((y=x.ts)==null?void 0:y.it)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.bl=a.length&&a.every(x=>{var y;return((y=x.ts)==null?void 0:y.bl)===i.BooleanNumber.TRUE})?i.BooleanNumber.TRUE:i.BooleanNumber.FALSE,c.ul=a.length&&a.every(x=>{var y,_;return((_=(y=x.ts)==null?void 0:y.ul)==null?void 0:_.s)===i.BooleanNumber.TRUE})?(h=a[0].ts)==null?void 0:h.ul:c.ul,c.st=a.length&&a.every(x=>{var y,_;return((_=(y=x.ts)==null?void 0:y.st)==null?void 0:_.s)===i.BooleanNumber.TRUE})?(p=a[0].ts)==null?void 0:p.st:c.st,c.bg=(E=(S=(f=a.find(x=>{var y;return((y=x.ts)==null?void 0:y.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(T=(C=a.find(x=>{var y;return((y=x.ts)==null?void 0:y.cl)!=null}))==null?void 0:C.ts)==null?void 0:T.cl)!=null?R:c.cl;const A=a.filter(x=>{var y;return((y=x==null?void 0:x.ts)==null?void 0:y.va)!=null});if(A.length>0&&A.length===a.length){const x=(v=A[0].ts)==null?void 0:v.va;let y=!0;for(let _=1;_<A.length;_++)if(((b=A[_].ts)==null?void 0:b.va)!==x){y=!1;break}y&&(c.va=x)}return c}function ia(o,t){const e=Wn[t];return mi(o,e,t)}const xo={id:"doc.command-replace-snapshot",type:i.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,snapshot:n,textRanges:r,segmentId:s="",options:a}=t,c=o.get(i.IUniverInstanceService),l=o.get(i.ICommandService),A=o.get(D.DocSelectionManagerService),d=c.getUnit(e,i.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot();if(d==null||u==null)return!1;const{body:m,tableSource:g,footers:h,headers:p,lists:f,drawings:S,drawingsOrder:E,documentStyle:C}=i.Tools.deepClone(n),{body:T,tableSource:R,footers:v,headers:b,lists:x,drawings:y,drawingsOrder:_,documentStyle:O}=u;if(m==null||T==null)return!1;if(i.Tools.diffValue(m,T)&&r)return A.replaceDocRanges(r,{unitId:e,subUnitId:e},!1),!0;const w={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:r}};a&&(w.params.options=a);const Q=[],k=i.JSONX.getInstance();if(!i.Tools.diffValue(O,C)){const L=k.replaceOp(["documentStyle"],O,C);L!=null&&Q.push(L)}if(!i.Tools.diffValue(m,T)){const L=k.replaceOp(["body"],T,m);L!=null&&Q.push(L)}if(!i.Tools.diffValue(g,R)){const L=k.replaceOp(["tableSource"],R,g);L!=null&&Q.push(L)}if(!i.Tools.diffValue(h,v)){const L=k.replaceOp(["footers"],v,h);L!=null&&Q.push(L)}if(!i.Tools.diffValue(p,b)){const L=k.replaceOp(["headers"],b,p);L!=null&&Q.push(L)}if(!i.Tools.diffValue(f,x)){const L=k.replaceOp(["lists"],x,f);L!=null&&Q.push(L)}if(!i.Tools.diffValue(S,y)){const L=k.replaceOp(["drawings"],y,S);L!=null&&Q.push(L)}if(!i.Tools.diffValue(E,_)){const L=k.replaceOp(["drawingsOrder"],_,E);L!=null&&Q.push(L)}return w.params.actions=Q.reduce((L,G)=>i.JSONX.compose(L,G),null),!!l.syncExecuteCommand(w.id,w.params)}},fi={id:"doc.command-replace-content",type:i.CommandType.COMMAND,handler:async(o,t)=>{const{unitId:e,body:n,textRanges:r,segmentId:s="",options:a}=t,c=o.get(i.IUniverInstanceService),l=o.get(i.ICommandService),A=o.get(D.DocSelectionManagerService),d=c.getUnit(e,i.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot().body;if(d==null||u==null)return!1;const m=Ii(e,s,d,u,n);return m.params.textRanges=r,a&&(m.params.options=a),m.params.actions==null&&r?(A.replaceDocRanges(r,{unitId:e,subUnitId:e},!1),!0):!!l.syncExecuteCommand(m.id,m.params)}},Si={id:"doc.command-cover-content",type:i.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,body:n,segmentId:r="",textRanges:s}=t,a=o.get(i.IUniverInstanceService),c=o.get(i.ICommandService),l=o.get(i.IUndoRedoService),A=a.getUniverDocInstance(e),d=A==null?void 0:A.getSnapshot().body;if(A==null||d==null)return!1;const u=Ii(e,r,A,d,n);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,u.params.textRanges=s,c.syncExecuteCommand(u.id,u.params),l.clearUndoRedo(e),!0}};function sa(o,t,e,n){const r=new i.TextX,s=i.JSONX.getInstance(),a=(e==null?void 0:e.dataStream.length)-2;a>0&&r.push({t:i.TextXActionType.DELETE,len:a}),n.dataStream.length>0&&r.push({t:i.TextXActionType.INSERT,body:n,len:n.dataStream.length});const c=J(t,o);return s.editOp(r.serialize(),c)}function Ii(o,t,e,n,r){const s={id:D.RichTextEditingMutation.id,params:{unitId:o,actions:[],textRanges:[]}},a=sa(t,e,n,r);return s.params.actions=a,s}const Oo={id:"doc.command.replace-selection",type:i.CommandType.COMMAND,handler(o,t){var h;if(!t)return!1;const e=o.get(i.ICommandService),{unitId:n,body:r,textRanges:s}=t,c=o.get(i.IUniverInstanceService).getUnit(n),l=o.get(D.DocSelectionManagerService);if(!c)return!1;const A=c.getBody(),d=(h=t.selection)!=null?h:l.getActiveTextRange();if(!d||!A)return!1;const u={id:D.RichTextEditingMutation.id,params:{unitId:n,actions:[],textRanges:s,debounce:!0}},m=new i.TextX,g=i.JSONX.getInstance();return m.push(...i.BuildTextUtils.selection.delete([d],A,0,r)),u.params.actions=g.editOp(m.serialize()),e.syncExecuteCommand(u.id,u.params)}},vi={id:"doc.command.replace-text-runs",type:i.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,body:n,textRanges:r,segmentId:s="",options:a}=t,c=o.get(i.IUniverInstanceService),l=o.get(i.ICommandService),A=o.get(i.ThemeService),d=c.getUnit(e,i.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot().body;if(d==null||u==null)return!1;const m=i.BuildTextUtils.selection.replaceTextRuns({doc:d,body:n,selection:{startOffset:0,endOffset:u.dataStream.length-2,collapsed:!1},themeService:A});if(!m)return!1;const g={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:r,noHistory:!0}},h=i.JSONX.getInstance(),p=J(d,s);return g.params.actions=h.editOp(m.serialize(),p),g.params.textRanges=r,a&&(g.params.options=a),!!l.syncExecuteCommand(g.id,g.params)}},Ei={id:"doc.command.insert-custom-range",type:i.CommandType.COMMAND,handler:(o,t)=>{if(!t)return!1;const e=o.get(i.ICommandService),{unitId:n,rangeId:r=i.generateRandomId(),textRanges:s,properties:a,text:c,wholeEntity:l}=t,A={unitId:n,textRanges:s,body:{dataStream:c,customRanges:[{startIndex:0,endIndex:c.length-1,rangeId:r,rangeType:i.CustomRangeType.CUSTOM,properties:a,wholeEntity:l}]}};return e.syncExecuteCommand(Oo.id,A)}},at={id:"doc.command.list-operation",type:i.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,b,x,y;const e=o.get(D.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=t.listType,a=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=(R=(T=t.docRange)!=null?T:e.getDocRanges())!=null?R:[];if(a==null||c.length===0)return!1;const l=c[0].segmentId,A=a.getSelfOrHeaderFooterModel(l),d=(b=(v=A.getBody())==null?void 0:v.paragraphs)!=null?b:[],u=(y=(x=A.getBody())==null?void 0:x.dataStream)!=null?y:"";if(!d.length)return!1;const m=i.BuildTextUtils.range.getParagraphsInRanges(c,d,u),g=a.getUnitId(),h={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:c,isEditing:!1}};new i.MemoryCursor().reset();const f=i.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:s,document:a,segmentId:l}),S=i.JSONX.getInstance(),E=J(a,l);return h.params.actions=S.editOp(f.serialize(),E),!!r.syncExecuteCommand(h.id,h.params)}},Mt={id:"doc.command.change-list-type",type:i.CommandType.COMMAND,handler:(o,t)=>{var C,T,R,v,b;const e=o.get(D.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),{listType:s}=t,a=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(a==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=a.getSelfOrHeaderFooterModel(l),d=(R=(T=A.getBody())==null?void 0:T.paragraphs)!=null?R:[],u=(b=(v=A.getBody())==null?void 0:v.dataStream)!=null?b:"";if(!d.length)return!1;const m=i.BuildTextUtils.range.getParagraphsInRanges(c,d,u),g=a.getUnitId(),h=i.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:s,segmentId:l,document:a});if(!h)return!1;const p=i.JSONX.getInstance(),f={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:c,isEditing:!1}},S=J(a,l);return f.params.actions=p.editOp(h.serialize(),S),!!r.syncExecuteCommand(f.id,f.params)}};var ft=(o=>(o[o.increase=1]="increase",o[o.decrease=-1]="decrease",o))(ft||{});const Kt={id:"doc.command.change-list-nesting-level",type:i.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,b,x;if(!t)return!1;const{type:e}=t,n=o.get(D.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(a==null||c==null)return!1;const{segmentId:l}=c,A=(T=n.getDocRanges())!=null?T:[],d=a.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(x=(b=d.getBody())==null?void 0:b.dataStream)!=null?x:"";if(!u.length)return!1;const g=i.BuildTextUtils.range.getParagraphsInRange(c,u,m),h=a.getUnitId(),p=i.JSONX.getInstance(),f=i.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:g,type:e,segmentId:l,document:a}),S={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:A,isEditing:!1}},E=J(a,l);return S.params.actions=p.editOp(f.serialize(),E),!!s.syncExecuteCommand(S.id,S.params)}},ot={id:"doc.command.bullet-list",type:i.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(i.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(Mt.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(at.id,{listType:i.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Et={id:"doc.command.check-list",type:i.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(i.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(Mt.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(at.id,{listType:i.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},Mo={id:"doc.command.toggle-check-list",type:i.CommandType.COMMAND,handler:(o,t)=>{var p;if(!t)return!1;const e=o.get(i.IUniverInstanceService),n=o.get(i.ICommandService),{index:r,segmentId:s,textRanges:a}=t,c=e.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC);if(c==null||((p=c.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:p.paragraphs)==null)return!1;const A=c.getUnitId(),d={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:a!=null?a:[],segmentId:s,isEditing:!1}},u=i.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:r,segmentId:s});if(!u)return!1;const m=i.JSONX.getInstance(),g=J(c,s);return d.params.actions=m.editOp(u.serialize(),g),!!n.syncExecuteCommand(d.id,d.params)}},rt={id:"doc.command.order-list",type:i.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(i.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(Mt.id,{listType:t.value}):e.syncExecuteCommand(at.id,{listType:i.PresetListType.ORDER_LIST})}},Do={id:"doc.command.quick-list",type:i.CommandType.COMMAND,handler(o,t){var O,w,Q;if(!t)return!1;const e=o.get(D.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),s=n.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),a=e.getActiveTextRange();if(s==null||a==null)return!1;const{segmentId:c,startOffset:l}=a,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,g=new i.TextX,h=i.JSONX.getInstance(),{paragraphStyle:p={}}=d,S=(i.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{}).textStyle;let C=i.generateRandomId(6);const T=(w=(O=s.getBody())==null?void 0:O.paragraphs)!=null?w:[],R=T.findIndex(k=>k.startIndex===d.startIndex),v=T[R-1],b=T[R+1];v&&v.bullet&&v.bullet.listType.indexOf(A)===0?C=v.bullet.listId:b&&b.bullet&&b.bullet.listType.indexOf(A)===0&&(C=b.bullet.listId);const x={id:D.RichTextEditingMutation.id,params:{unitId:s.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};g.push({t:i.TextXActionType.RETAIN,len:u}),g.push({t:i.TextXActionType.DELETE,len:l-u}),m>l&&g.push({t:i.TextXActionType.RETAIN,len:m-l}),g.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...p,textStyle:{...p.textStyle,...S},indentFirstLine:void 0},bullet:{...(Q=d.bullet)!=null?Q:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:C}}]}});const y=J(s,c);return x.params.actions=h.editOp(g.serialize(),y),!!r.syncExecuteCommand(x.id,x.params)}};function Bo(o,t){var d,u;const e=o.get(i.ICommandService),n=bt(o);if(!n)return!1;const r=o.get(i.IUniverInstanceService).getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC);if(!r)return!1;const s=i.BuildTextUtils.selection.replace({doc:r,selection:{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0},body:{dataStream:"\r",paragraphs:[{startIndex:0,paragraphStyle:{...n.paragraphStyle},bullet:{listType:t,listId:((d=n.bullet)==null?void 0:d.listType)===t?n.bullet.listId:i.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!s)return!1;const a={id:D.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=i.JSONX.getInstance(),l=J(r);return a.params.actions=c.editOp(s.serialize(),l),!!e.syncExecuteCommand(a.id,a.params)}const _o={id:"doc.command.insert-bullet-list-bellow",type:i.CommandType.COMMAND,handler:o=>Bo(o,i.PresetListType.BULLET_LIST)},No={id:"doc.command.insert-order-list-bellow",type:i.CommandType.COMMAND,handler:o=>Bo(o,i.PresetListType.ORDER_LIST)},Po={id:"doc.command.insert-check-list-bellow",type:i.CommandType.COMMAND,handler:o=>Bo(o,i.PresetListType.CHECK_LIST)},pe={id:"doc.command.align-action",type:i.CommandType.COMMAND,handler:(o,t)=>{var R,v,b,x;const e=o.get(D.DocSelectionManagerService),n=o.get(i.IUniverInstanceService),r=o.get(i.ICommandService),{alignType:s}=t,a=n.getCurrentUniverDocInstance();if(a==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=a.getSelfOrHeaderFooterModel(l),d=(v=(R=A.getBody())==null?void 0:R.paragraphs)!=null?v:[],u=(x=(b=A.getBody())==null?void 0:b.dataStream)!=null?x:"";if(d==null)return!1;const m=i.BuildTextUtils.range.getParagraphsInRanges(c,d,u),g=a.getUnitId(),h=m.every(y=>{var _;return((_=y.paragraphStyle)==null?void 0:_.horizontalAlign)===s}),p={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:c}},f=new i.MemoryCursor;f.reset();const S=new i.TextX,E=i.JSONX.getInstance();for(const y of m){const{startIndex:_}=y;S.push({t:i.TextXActionType.RETAIN,len:_-f.cursor});const O={...y.paragraphStyle,horizontalAlign:h?i.HorizontalAlign.UNSPECIFIED:s};S.push({t:i.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...y,paragraphStyle:O,startIndex:0}]},coverType:i.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(_+1)}const C=J(a,l);return p.params.actions=E.editOp(S.serialize(),C),!!r.syncExecuteCommand(p.id,p.params)}},Dt={id:"doc.command.align-left",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.LEFT})},Bt={id:"doc.command.align-center",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.CENTER})},_t={id:"doc.command.align-right",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.RIGHT})},Nt={id:"doc.command.align-justify",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(pe.id,{alignType:i.HorizontalAlign.JUSTIFIED})},aa=(o,t)=>{const n=o.get(i.IUniverInstanceService).getUnit(t.unitId,i.UniverInstanceType.UNIVER_DOC);return n==null||n.setZoomRatio(t.zoomRatio),{...t}},Ae={id:"doc.operation.set-zoom-ratio",type:i.CommandType.OPERATION,handler:(o,t)=>{const n=o.get(i.IUniverInstanceService).getUnit(t.unitId,i.UniverInstanceType.UNIVER_DOC);return n?(n.setZoomRatio(t.zoomRatio),!0):!1}},St={type:i.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,t)=>{var u,m,g;const e=o.get(i.ICommandService),n=o.get(i.IUndoRedoService),r=o.get(i.IUniverInstanceService);let s=(u=r.getCurrentUniverDocInstance())==null?void 0:u.getUnitId();if(!s)return!1;let a=1;if(t&&(s=(m=t.documentId)!=null?m:s,a=(g=t.zoomRatio)!=null?g:a),!r.getUniverDocInstance(s))return!1;const l={zoomRatio:a,unitId:s},A=aa(o,l);return e.syncExecuteCommand(Ae.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:Ae.id,params:A}],redoMutations:[{id:Ae.id,params:l}]}),!0):!1}},le={id:"doc.command.set-paragraph-named-style",type:i.CommandType.COMMAND,handler(o,t){var h;if(!t)return!1;const n=o.get(i.IUniverInstanceService).getCurrentUnitOfType(i.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const r=n.getUnitId(),s=o.get(D.DocSelectionManagerService),a=(h=t.textRanges)!=null?h:s.getTextRanges({unitId:r,subUnitId:r});if(!(a!=null&&a.length))return!1;const c=a[0].segmentId,l=i.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:a,style:{namedStyleType:t.value,headingId:!t.value||t.value===i.NamedStyleType.NORMAL_TEXT?void 0:i.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0,lineSpacing:void 0},paragraphTextRun:{}}),A={id:D.RichTextEditingMutation.id,params:{actions:[],textRanges:a,unitId:r,segmentId:c}},d=i.JSONX.getInstance(),u=J(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!o.get(i.ICommandService).syncExecuteCommand(A.id,A.params)}},Ci={id:"doc.command.quick-heading",type:i.CommandType.COMMAND,handler(o,t){var R,v,b,x;if(!t)return!1;const{value:e}=t,n=o.get(D.DocSelectionManagerService),r=o.get(i.IUniverInstanceService),s=o.get(i.ICommandService),a=r.getCurrentUnitForType(i.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(a==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=a.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(x=(b=d.getBody())==null?void 0:b.dataStream)!=null?x:"",g=i.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!g)return!1;const{paragraphStart:h}=g,p=new i.TextX,f=i.JSONX.getInstance(),{paragraphStyle:S={}}=g,E={id:D.RichTextEditingMutation.id,params:{unitId:a.getUnitId(),actions:[],textRanges:[{startOffset:h,endOffset:h,collapsed:!0}],isEditing:!1}};p.push({t:i.TextXActionType.RETAIN,len:h}),i.BuildTextUtils.paragraph.style.set({textRanges:[c],document:a,style:{...S,headingId:i.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-h,textX:p,paragraphTextRun:{}});const C=J(a,l);return E.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(E.id,E.params)}},_n={"#":i.NamedStyleType.HEADING_1,"##":i.NamedStyleType.HEADING_2,"###":i.NamedStyleType.HEADING_3,"####":i.NamedStyleType.HEADING_4,"#####":i.NamedStyleType.HEADING_5},wo={id:"doc.command.h1-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_1})},Uo={id:"doc.command.h2-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_2})},Lo={id:"doc.command.h3-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_3})},Qo={id:"doc.command.h4-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_4})},Fo={id:"doc.command.h5-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.HEADING_5})},zt={id:"doc.command.normal-text-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.NORMAL_TEXT})},Ti={id:"doc.command.title",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.TITLE})},yi={id:"doc.command.subtitle-heading",type:i.CommandType.COMMAND,handler:o=>o.get(i.ICommandService).syncExecuteCommand(le.id,{value:i.NamedStyleType.SUBTITLE})};var jt=(o=>(o[o.page=0]="page",o[o.section=1]="section",o[o.column=2]="column",o[o.line=3]="line",o[o.divide=4]="divide",o[o.glyph=5]="glyph",o))(jt||{});const $e={page:0,section:1,column:2,line:3,divide:4,glyph:5};function Ho(o,t){return o.page>t.page?!1:o.page<t.page?!0:o.section>t.section?!1:o.section<t.section?!0:o.column>t.column?!1:o.column<t.column?!0:o.line>t.line?!1:o.line<t.line?!0:o.divide>t.divide?!1:o.divide<t.divide?!0:o.glyph>t.glyph?!1:(o.glyph<t.glyph,!0)}function Gn(o,t){return Ho(o,t)?{start:o,end:t}:{start:t,end:o}}function Xn(o){const t=o.length;if(t===0)return;const e=o[0],n=o[t-1],r=o.length===1&&e.collapsed;return{startOffset:e.startOffset,endOffset:n.endOffset,collapsed:r}}function ca(o,t,e,n){let r=n,s=n;for(let a=0;a<o.length;a++){const l=o[a].count;a<t&&(r+=l),a<e&&(s+=l)}return{startOffset:r,endOffset:s}}function Kn(o){const{startX:t,startY:e,endX:n,endY:r}=o,s=[];return s.push({x:t,y:e}),s.push({x:n,y:e}),s.push({x:n,y:r}),s.push({x:t,y:r}),s.push({x:t,y:e}),s}class Ee{constructor(t,e){M(this,"_liquid",new B.Liquid);M(this,"_currentStartState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});M(this,"_currentEndState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],r=[],s=[];if(t==null||e==null)return{borderBoxPointGroup:n,contentBoxPointGroup:r,cursorList:s};if(!this._isValidPosition(t,e))throw new Error(`
|
|
12
12
|
Invalid positions in NodePositionConvertToCursor,
|
|
13
|
-
they are not in the same segment page when in header or footer.`);const{start:c,end:l}=Gn(t,e);return this._selectionIterator(c,l,(A,d,u,m,g,h)=>{const{lineHeight:p,asc:f,paddingTop:S,marginTop:E,marginBottom:C}=h,{glyphGroup:T,st:R}=g;if(T.length===0)return;const{x:v,y:b}=this._liquid;let x,y;const _=T[A],O=T[d],w=T[A-1],Q=(_==null?void 0:_.left)||0,k=(_==null?void 0:_.width)||0,F=(O==null?void 0:O.left)||0,L=(O==null?void 0:O.width)||0,G=(_==null?void 0:_.glyphType)===B.GlyphType.LIST,{startOffset:W,endOffset:H}=ca(T,A,d,R),V=c.glyph===A&&u?c.isBack:!0,j=l.glyph===d&&m?l.isBack:!1,X=c===l,z=V&&w!=null?w:_;if(A===0&&d===T.length-1)x={startX:v+Q+(G?k:0),startY:b,endX:v+F+(j?0:L),endY:b+p-E-C},y={startX:v+Q+(G?k:0),startY:b+S+f-z.bBox.ba,endX:v+F+(j?0:L),endY:b+S+f+z.bBox.bd};else{const Y=V&&!G;x={startX:v+Q+(Y?0:k),startY:b,endX:v+F+(j?0:L),endY:b+p-E-C},y={startX:v+Q+(Y?0:k),startY:b+S+f-z.bBox.ba,endX:v+F+(j?0:L),endY:b+S+f+z.bBox.bd}}n.push(Kn(x)),r.push(Kn(y)),s.push({startOffset:V?W:W+_.count,endOffset:j?H:H+O.count,collapsed:X})}),{borderBoxPointGroup:n,contentBoxPointGroup:r,cursorList:s}}_isValidPosition(t,e){const{segmentPage:n,pageType:r}=t,{segmentPage:s,pageType:a}=e;return r!==a?!1:r===B.DocumentSkeletonPageType.HEADER||r===B.DocumentSkeletonPageType.FOOTER?n===s:!0}_resetCurrentNodePositionState(){this._currentStartState={page:0,section:0,column:0,line:0,divide:0,glyph:0},this._currentEndState={page:0,section:0,column:0,line:0,divide:0,glyph:0}}_setNodePositionState(t=0,e,n,r){r===e?this._currentStartState[t]=1:this._currentStartState[t]=0,r===n?this._currentEndState[t]=2:this._currentEndState[t]=0}_checkPreviousNodePositionState(t,e=!0){let n=t,r;for(;n>=0;){const s=jt[n];let a;if(e?a=this._currentStartState[s]:a=this._currentEndState[s],a===void 0)return;if(r===void 0&&(r=a),a!==r)return 0;n--}return r}_getSelectionRuler(t,e,n,r,s){let a=0,c=r;const l=jt[t],A=jt[t+1];if(A===null||l===null)return{start_next:a,end_next:c};const d=e[l],u=n[l];this._setNodePositionState(l,d,u,s);const m=this._checkPreviousNodePositionState(t),g=this._checkPreviousNodePositionState(t,!1);return m===1&&(a=e[A]),g===2&&(c=n[A]),{start_next:a,end_next:c}}_selectionIterator(t,e,n){var T,R;const r=this._docSkeleton;if(!r)return[];const{pageType:s,path:a}=t;this._liquid.reset();const c=r.getSkeletonData();if(c==null)return[];const{pages:l,skeHeaders:A,skeFooters:d}=c,{page:u,segmentPage:m}=t,{page:g,segmentPage:h}=e;if(this._resetCurrentNodePositionState(),this._documentOffsetConfig==null)return[];const{pageLayoutType:p,pageMarginLeft:f,pageMarginTop:S}=this._documentOffsetConfig,E=s===B.DocumentSkeletonPageType.BODY||s===B.DocumentSkeletonPageType.CELL?u:m;for(let v=0;v<E;v++){const b=l[v];this._liquid.translatePage(b,p,f,S)}const C=s===B.DocumentSkeletonPageType.BODY||s===B.DocumentSkeletonPageType.CELL?g:h;for(let v=E;v<=C;v++){const b=l[v],{headerId:x,footerId:y,pageWidth:_}=b;let O=b;if(s===B.DocumentSkeletonPageType.HEADER?O=(T=A.get(x))==null?void 0:T.get(_):s===B.DocumentSkeletonPageType.FOOTER?O=(R=d.get(y))==null?void 0:R.get(_):s===B.DocumentSkeletonPageType.CELL&&(O=B.getPageFromPath(c,a)),O==null){this._liquid.translatePage(b,p,f,S);continue}const w=O.sections,{start_next:Q,end_next:k}=this._getSelectionRuler($e.page,t,e,w.length-1,s===B.DocumentSkeletonPageType.BODY||s===B.DocumentSkeletonPageType.CELL?v:0);switch(this._liquid.translateSave(),s){case B.DocumentSkeletonPageType.HEADER:this._liquid.translatePagePadding({...O,marginLeft:b.marginLeft});break;case B.DocumentSkeletonPageType.FOOTER:{const F=b.pageHeight-O.height-O.marginBottom;this._liquid.translate(b.marginLeft,F);break}case B.DocumentSkeletonPageType.CELL:{this._liquid.translatePagePadding(b);const F=O.parent,L=F.parent,{left:G}=O,{top:W,left:H}=L,{top:V}=F;this._liquid.translate(H+G,W+V),this._liquid.translatePagePadding(O);break}default:this._liquid.translatePagePadding(b);break}for(let F=Q;F<=k;F++){const L=w[F],G=L.columns,{start_next:W,end_next:H}=this._getSelectionRuler($e.section,t,e,G.length-1,F);this._liquid.translateSection(L);for(let V=W;V<=H;V++){const j=G[V],X=j.lines,{start_next:z,end_next:Y}=this._getSelectionRuler($e.column,t,e,X.length-1,V);this._liquid.translateColumn(j);for(let K=z;K<=Y;K++){const Z=X[K],{divides:ne}=Z,{start_next:ge,end_next:xe}=this._getSelectionRuler($e.line,t,e,ne.length-1,K);this._liquid.translateSave(),this._liquid.translateLine(Z,!0,!1);for(let he=ge;he<=xe;he++){const On=ne[he];this._liquid.translateSave(),this._liquid.translateDivide(On);const{glyphGroup:hs}=On,{start_next:ms,end_next:ps}=this._getSelectionRuler($e.divide,t,e,hs.length-1,he);let nr=!1,or=!1;v===E&&F===Q&&V===W&&K===z&&he===ge&&(nr=!0),v===C&&F===k&&V===H&&K===Y&&he===xe&&(or=!0),n&&n(ms,ps,nr,or,On,Z,j,L,O),this._liquid.translateRestore()}this._liquid.translateRestore()}}}this._liquid.translateRestore(),this._liquid.translatePage(b,p,f,S)}}}function bi(o,t){const{path:e}=o,{path:n}=t;if(e.length!==n.length||e.indexOf("cells")===-1)return!1;const r=e.indexOf("skeTables")+1,s=e.indexOf("rows")+1,a=e.indexOf("cells")+1,{tableId:c,sliceIndex:l}=B.getTableIdAndSliceIndex(e[r]),{tableId:A,sliceIndex:d}=B.getTableIdAndSliceIndex(n[r]);if(c!==A)return!1;const u=e[s],m=n[s],g=e[a],h=n[a];return!(u===m&&g===h&&l===d)}function ko(o,t){const{path:e}=o,{path:n}=t;return e.indexOf("cells")===-1||n.indexOf("cells")===-1||e.length!==n.length?!1:i.Tools.diffValue(e,n)}function Ri(o,t,e){var g,h,p,f,S,E,C,T;const{path:n}=t,{path:r}=e;if(n.indexOf("cells")===-1||r.indexOf("cells")===-1)return!1;const s=o.findGlyphByPosition(t),a=o.findGlyphByPosition(e),c=(f=(p=(h=(g=s==null?void 0:s.parent)==null?void 0:g.parent)==null?void 0:h.parent)==null?void 0:p.parent)==null?void 0:f.parent,l=(T=(C=(E=(S=a==null?void 0:a.parent)==null?void 0:S.parent)==null?void 0:E.parent)==null?void 0:C.parent)==null?void 0:T.parent;if(c==null||l==null)return!1;const A=c.parent,d=l.parent,u=A.cells.indexOf(c),m=d.cells.indexOf(l);return u===m&&A.index===d.index}function Nn(o,t){if(ko(o,t))return Ho(o,t);const{path:e}=o,{path:n}=t,r=e[e.length-5],s=n[n.length-5];if(r!==s&&typeof r=="string"&&typeof s=="string"){const d=r.split("#-#")[1],u=s.split("#-#")[1];return+d<+u}const a=e[e.length-3],c=n[n.length-3],l=e[e.length-1],A=n[n.length-1];return a<c?!0:a>c?!1:l<=A}function ze(o){return o.sections[0].columns[0].lines.length===0}function la(o,t,e){let n=t,r=e,s=o[n],a=o[r];for(;n<r&&(ze(s)||ze(a));)ze(s)?(n++,s=o[n]):ze(a)&&(r--,a=o[r]);if(!ze(s)&&!ze(a))return[s,a]}class Vo{constructor(t,e){M(this,"_liquid",new B.Liquid);this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],s=this._docSkeleton.getSkeletonData();if(s==null)return;const{pages:a}=s,{segmentPage:c,page:l,pageType:A}=t,d=this._getTableRectRangeInfo(t,e);if(d==null)return;const{tableId:u,startRowIndex:m,startColumnIndex:g,endRowIndex:h,endColumnIndex:p}=d;this._liquid.reset();const{pageLayoutType:f,pageMarginLeft:S,pageMarginTop:E}=this._documentOffsetConfig,C=A===B.DocumentSkeletonPageType.BODY||A===B.DocumentSkeletonPageType.CELL?l:c;for(let T=0;T<C;T++){const R=a[T];this._liquid.translatePage(R,f,S,E)}for(let T=C;T<a.length;T++){const R=a[T];this._liquid.translatePagePadding(R);const{skeTables:v}=R;let b=null;for(const[O,w]of v.entries())O.startsWith(u)&&(b=w);if(b==null){this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E);continue}this._liquid.translateSave(),this._liquid.translate(0,b.top);const{x,y}=this._liquid,{left:_}=b;for(const O of b.rows)if(O.index>=m&&O.index<=h){const w=la(O.cells,g,p);if(w==null)continue;const[Q,k]=w,F={startX:x+Q.left+_,startY:y+O.top,endX:x+k.left+k.pageWidth+_,endY:y+O.top+O.height};n.push(Kn(F))}this._liquid.translateRestore(),this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E)}return{pointGroup:n,startRow:m,startColumn:g,endRow:h,endColumn:p,tableId:u}}getNodePositionGroup(t,e){const n=[],r=this._docSkeleton.findCharIndexByPosition(t),s=this._docSkeleton.findCharIndexByPosition(e);if(r==null||s==null)return;const a=r<s,c=this._getTableRectRangeInfo(t,e);if(c==null)return;const{tableId:l,startRowIndex:A,startColumnIndex:d,endRowIndex:u,endColumnIndex:m}=c,g=this._docSkeleton.getViewModel().findTableNodeById(l);if(g==null)return;const h=g.children[0].children.length;if(d===0&&m===h-1){const f=g.children[A].children[d],S=this._docSkeleton.findNodePositionByCharIndex(f.startIndex+1),E=g.children[u].children[m],C=this._docSkeleton.findNodePositionByCharIndex(E.endIndex-2);if(S==null||C==null)return;n.push({anchor:a?S:C,focus:a?C:S})}else for(let f=A;f<=u;f++){const S=g.children[f],E=S.children[d],C=S.children[m],T=this._docSkeleton.findNodePositionByCharIndex(E.startIndex+1),R=this._docSkeleton.findNodePositionByCharIndex(C.endIndex-2);if(T==null||R==null)return;n.push({anchor:a?T:R,focus:a?R:T})}return n}_getTableRectRangeInfo(t,e){const r=this._docSkeleton.getSkeletonData();if(r==null)return;const{pages:s}=r,{path:a}=t,{path:c}=e,l=B.getPageFromPath(r,a),A=B.getPageFromPath(r,c);if(l==null||A==null)return;const d=l.segmentId,u=l.parent.index,m=l.parent.cells.indexOf(l),g=(A==null?void 0:A.parent).index,h=(A==null?void 0:A.parent).cells.indexOf(A),p=Math.min(u,g),f=Math.max(u,g),S=Math.min(m,h),E=Math.max(m,h);return{pages:s,tableId:d,startRowIndex:p,startColumnIndex:S,endRowIndex:f,endColumnIndex:E}}}const da="__TestSelectionRange__",Aa="__TestSelectionAnchor__",Er=6,Pn=500,ua=500,Yt=3;function It(o){const t=o[0],e=t[0],n=t[2],{x:r,y:s}=e,{x:a,y:c}=n;return{left:r,top:s,width:a-r,height:c-s}}function In(o){return o.map(t=>{let e=1/0,n=-1/0,r=1/0,s=-1/0;return t.forEach(a=>{e=Math.min(a.x,e),n=Math.max(a.x,n),s=Math.max(a.y,s),r=Math.min(a.y,r)}),{left:e,right:n,top:r,bottom:s}})}class je{constructor(t,e,n,r,s,a=B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){M(this,"rangeType",i.DOC_RANGE_TYPE.TEXT);M(this,"_current",!1);M(this,"_rangeShape");M(this,"_anchorShape");M(this,"_cursorList",[]);M(this,"_anchorBlinkTimer",null);this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=r,this.focusNodePosition=s,this.style=a,this._segmentId=c,this._segmentPage=l,this._anchorBlink(),this.refresh()}_anchorBlink(){setTimeout(()=>{this._anchorShape&&this._anchorShape.visible&&this.deactivateStatic()},Pn),this._anchorBlinkTimer=setInterval(()=>{this._anchorShape&&this._anchorShape.visible&&(this.activeStatic(),setTimeout(()=>{this.deactivateStatic()},Pn))},ua+Pn)}get startOffset(){var r;const{startOffset:t}=(r=Xn(this._cursorList))!=null?r:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(n,t)}get endOffset(){var r;const{endOffset:t}=(r=Xn(this._cursorList))!=null?r:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(t,n)}get collapsed(){const{startOffset:t,endOffset:e}=this;return t!=null&&t===e}get startNodePosition(){if(this.anchorNodePosition==null)return null;if(this.focusNodePosition==null)return this.anchorNodePosition;const{start:t}=Gn(this.anchorNodePosition,this.focusNodePosition);return t}get endNodePosition(){if(this.anchorNodePosition==null)return this.focusNodePosition;if(this.focusNodePosition==null)return null;const{end:t}=Gn(this.anchorNodePosition,this.focusNodePosition);return t}get direction(){const{collapsed:t,anchorNodePosition:e,focusNodePosition:n}=this;return t||e==null||n==null?i.RANGE_DIRECTION.NONE:Ho(e,n)?i.RANGE_DIRECTION.FORWARD:i.RANGE_DIRECTION.BACKWARD}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}getAbsolutePosition(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(this._isEmpty())return;const n=this._document.getOffsetConfig(),{docsLeft:r,docsTop:s}=n,a=new Ee(n,this._docSkeleton);if(this._isCollapsed()){const{contentBoxPointGroup:d,cursorList:u}=a.getRangePointData(t,t);if(this._setCursorList(u),d.length===0)return;const m=It(d);return{...m,left:m.left+r,top:m.top+s}}const{borderBoxPointGroup:c,cursorList:l}=a.getRangePointData(t,e);if(this._setCursorList(l),c.length===0)return;const A=It(c);return{...A,left:A.left+r,top:A.top+s}}getAnchor(){return this._anchorShape}activeStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.strokeActive)||B.getColor(i.COLORS.black,1)})}deactivateStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.stroke)||B.getColor(i.COLORS.black,0)})}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t,e;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null,(e=this._anchorShape)==null||e.dispose(),this._anchorShape=null,this._anchorBlinkTimer&&(clearInterval(this._anchorBlinkTimer),this._anchorBlinkTimer=null)}isIntersection(t){const{startOffset:e,endOffset:n}=this,{startOffset:r,endOffset:s}=t;return e==null||n==null||r==null||s==null?!1:e<=s&&n>=r}refresh(){var u,m;const{_document:t,_docSkeleton:e}=this,n=this.anchorNodePosition,r=this.focusNodePosition;if((u=this._anchorShape)==null||u.hide(),(m=this._rangeShape)==null||m.hide(),this._isEmpty())return;const s=t.getOffsetConfig(),{docsLeft:a,docsTop:c}=s,l=new Ee(s,e);if(this._isCollapsed()){const{contentBoxPointGroup:g,cursorList:h}=l.getRangePointData(n,n);if(this._setCursorList(h),g.length>0){const p=e.findGlyphByPosition(n);this._createOrUpdateAnchor(g,a,c,p)}return}const{borderBoxPointGroup:A,cursorList:d}=l.getRangePointData(n,r);this._setCursorList(d),A.length>0&&this._createOrUpdateRange(A,a,c)}_isEmpty(){return this.anchorNodePosition==null&&this.focusNodePosition==null}_isCollapsed(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(t!=null&&e==null)return!0;if(t==null||e==null)return!1;const n=Object.keys($e);for(const r of n){const s=t[r],a=e[r];if(s!==a)return!1}return t.isBack===e.isBack}_createOrUpdateRange(t,e,n){var a;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const r=.3,s=new B.RegularPolygon(da+i.generateRandomId(Er),{pointsGroup:t,fill:((a=this.style)==null?void 0:a.fill)||B.getColor(i.COLORS.black,r),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,Yt)}_createOrUpdateAnchor(t,e,n,r){var p,f,S;const s=It(t),{left:a}=s;let{top:c,height:l}=s;const A=14;l<A&&(c-=A-l,l=A);const d=12;let u=a+e;const m=c+n,g=((p=r==null?void 0:r.ts)==null?void 0:p.it)===i.BooleanNumber.TRUE;if(g&&(u+=l*Math.tan(d*Math.PI/180)/2),this._anchorShape){this._anchorShape.transformByState({left:u,top:m,height:l}),this._anchorShape.show(),g?this._anchorShape.skew(-12,0):this._anchorShape.skew(0,0);return}const h=new B.Rect(Aa+i.generateRandomId(Er),{left:u,top:m,height:l,strokeWidth:((f=this.style)==null?void 0:f.strokeWidth)||1,stroke:((S=this.style)==null?void 0:S.strokeActive)||B.getColor(i.COLORS.black,1),evented:!1});g&&h.skew(-12,0),this._anchorShape=h,this._scene.addObject(h,Yt),this.activeStatic()}_setCursorList(t){t.length!==0&&(this._cursorList=t)}}const ga="__DocTableRectRange__",ha=6;function Wt(o,t,e,n,r,s=B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,a="",c=-1){const l=t.getOffsetConfig(),d=new Vo(l,e).getNodePositionGroup(n,r);return(d!=null?d:[]).map(u=>new jo(o,t,e,u.anchor,u.focus,s,a,c))}class jo{constructor(t,e,n,r,s,a=B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){M(this,"rangeType",i.DOC_RANGE_TYPE.RECT);M(this,"_rangeShape");M(this,"_current",!1);M(this,"_startRow");M(this,"_startCol");M(this,"_endRow");M(this,"_endCol");M(this,"_tableId");this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=r,this.focusNodePosition=s,this.style=a,this._segmentId=c,this._segmentPage=l,this.refresh()}get startOffset(){const{startNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get endOffset(){const{endNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get collapsed(){return!1}get startRow(){return this._startRow}get startColumn(){return this._startCol}get endRow(){return this._endRow}get endColumn(){return this._endCol}get tableId(){return this._tableId}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}get spanEntireRow(){var a;const e=(a=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:a[this._tableId],{_startCol:n,_endCol:r}=this;if(e==null)throw new Error("Table is not found.");const{tableColumns:s}=e;return n===0&&r===s.length-1}get spanEntireColumn(){var a;const e=(a=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:a[this._tableId],{_startRow:n,_endRow:r}=this;if(e==null)throw new Error("Table is not found.");const{tableRows:s}=e;return n===0&&r===s.length-1}get spanEntireTable(){return this.spanEntireRow&&this.spanEntireColumn}get startNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Nn(t,e)?t:e}get endNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Nn(t,e)?e:t}get direction(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Nn(t,e)?i.RANGE_DIRECTION.FORWARD:i.RANGE_DIRECTION.BACKWARD}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null}isIntersection(t){const{startRow:e,startColumn:n,endRow:r,endColumn:s}=this,{startRow:a,startColumn:c,endRow:l,endColumn:A}=t,d={left:n,top:e,right:s,bottom:r},u={left:c,top:a,right:A,bottom:l};return i.Rectangle.hasIntersectionBetweenTwoRect(d,u)}refresh(){var f;(f=this._rangeShape)==null||f.hide();const{startNodePosition:t,endNodePosition:e,_document:n,_docSkeleton:r}=this,s=n.getOffsetConfig(),{docsLeft:a,docsTop:c}=s,A=new Vo(s,r).getRangePointData(t,e);if(A==null)return;const{pointGroup:d=[],startRow:u,endRow:m,startColumn:g,endColumn:h,tableId:p}=A;(d==null?void 0:d.length)>0&&this._createOrUpdateRange(d,a,c),this._updateTableInfo(u,m,g,h,p)}_updateTableInfo(t,e,n,r,s){this._startRow=t,this._endRow=e,this._startCol=n,this._endCol=r,this._tableId=s}_createOrUpdateRange(t,e,n){var a;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const r=.3,s=new B.RegularPolygon(ga+i.generateRandomId(ha),{pointsGroup:t,fill:((a=this.style)==null?void 0:a.fill)||B.getColor(i.COLORS.black,r),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,Yt)}}function Cr(o,t,e,n,r,s,a,c,l=!0,A=!0){const d=r.findNodePositionByCharIndex(o,l,a,c),u=r.findNodePositionByCharIndex(t,A,a,c);if(!(d==null||u==null))return new je(e,n,r,d,u,s,a,c)}function ma(o,t,e,n,r,s,a,c){const l=r.findNodePositionByCharIndex(o,!0,a,c),A=r.findNodePositionByCharIndex(t,!0,a,c);if(!(l==null||A==null))return new jo(e,n,r,l,A,s,a,c)}function pa(o,t,e,n,r,s,a,c){const l=r.findNodePositionByCharIndex(o,!0,a,c),A=r.findNodePositionByCharIndex(t,!0,a,c);if(!(l==null||A==null))return zn(l,A,e,n,r,s,a,c)}function zn(o,t,e,n,r,s,a,c){const l=[],A=[],d=[e,n,r,o,t,s,a,c];if(Ri(r,o,t)){if(ko(o,t))return l.push(new je(...d)),{textRanges:l,rectRanges:A};{const C=Wt(...d);return A.push(...C),{textRanges:l,rectRanges:A}}}if(bi(o,t)){const C=Wt(...d);return A.push(...C),{textRanges:l,rectRanges:A}}const u=r.getViewModel().getSelfOrHeaderFooterViewModel(a),m=r.findCharIndexByPosition(o),g=r.findCharIndexByPosition(t);if(m==null||g==null)return;const h=m<=g?i.RANGE_DIRECTION.FORWARD:i.RANGE_DIRECTION.BACKWARD,p=Math.min(m,g),f=Math.max(m,g);let S=p,E=f;for(const C of u.getChildren())for(const T of C.children){const{startIndex:R,endIndex:v,children:b}=T,x=C.children.indexOf(T),y=C.children[x+1],_=b[0];let O=!1;if(_){const{startIndex:w,endIndex:Q,children:k}=_;let F=null,L=null;const G=k.find(H=>H.startIndex<=p&&H.endIndex>=p),W=k.find(H=>H.startIndex<=f&&H.endIndex>=f);if(p>w&&p<Q)F=r.findNodePositionByCharIndex(G.startIndex+2,!0,a,c),L=r.findNodePositionByCharIndex(Q-4,!0,a,c),S=Q+1;else if(f>w&&f<Q)F=r.findNodePositionByCharIndex(w+3,!0,a,c),L=r.findNodePositionByCharIndex(W.endIndex-3,!0,a,c),E=w-1,O=!0;else if(w>p&&Q<f){if(F=r.findNodePositionByCharIndex(w+3,!0,a,c),L=r.findNodePositionByCharIndex(Q-4,!0,a,c),S<=w-1){const H=r.findNodePositionByCharIndex(S,!0,a,c),V=r.findNodePositionByCharIndex(w-1,!1,a,c),j=h===i.RANGE_DIRECTION.FORWARD?H:V,X=h===i.RANGE_DIRECTION.FORWARD?V:H;l.push(new je(e,n,r,j,X,s,a,c))}S=Q+1}if(F&&L){const H=h===i.RANGE_DIRECTION.FORWARD?F:L,V=h===i.RANGE_DIRECTION.FORWARD?L:F;A.push(...Wt(e,n,r,H,V,s,a,c))}}if(E===v+1&&!O&&y&&y.children.length&&(E=v,O=!0),E>=R&&E<=v||O){const w=r.findNodePositionByCharIndex(S,!0,a,c),Q=r.findNodePositionByCharIndex(E,!O,a,c),k=h===i.RANGE_DIRECTION.FORWARD?w:Q,F=h===i.RANGE_DIRECTION.FORWARD?Q:w;if(A.length&&i.Tools.diffValue(k,F))continue;l.push(new je(e,n,r,k,F,s,a,c))}}return{textRanges:l,rectRanges:A}}function xi(o){const t=o==null?void 0:o.getCanvasElement();if(!t)return{left:0,top:0};const{top:e,left:n}=B.getOffsetRectForDom(t);return{left:n,top:e}}function Tr(o){var l;const t=(l=o.parent)==null?void 0:l.parent,e=t==null?void 0:t.parent;if(t==null||e==null)return;const{paragraphIndex:n}=t,r=e.lines.filter(A=>A.paragraphIndex===n);let s=-1,a="",c=!1;for(const A of r)for(const d of A.divides)for(const u of d.glyphGroup)c||(s+=u.count),u===o&&(c=!0),a+=u.count>0?u.content:"";return{st:r[0].st,ed:n,content:a,nodeIndex:s}}function Yn(o){const{startOffset:t,endOffset:e,collapsed:n,rangeType:r,startNodePosition:s,endNodePosition:a,direction:c,segmentId:l,segmentPage:A}=o;return{startOffset:t,endOffset:e,collapsed:n,rangeType:r,startNodePosition:s,endNodePosition:a,direction:c,segmentId:l,segmentPage:A,isActive:o.isActive()}}function fa(o){const t=Yn(o),{startRow:e,startColumn:n,endRow:r,endColumn:s,tableId:a,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}=o;return{...t,startRow:e,startColumn:n,endRow:r,endColumn:s,tableId:a,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}}var Sa=Object.getOwnPropertyDescriptor,Ia=(o,t,e,n)=>{for(var r=n>1?void 0:n?Sa(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Ut=(o,t)=>(e,n)=>t(e,n,o);exports.DocSelectionRenderService=class extends i.RxDisposable{constructor(e,n,r,s,a){super();M(this,"_onInputBefore$",new U.Subject);M(this,"onInputBefore$",this._onInputBefore$.asObservable());M(this,"_onKeydown$",new U.Subject);M(this,"onKeydown$",this._onKeydown$.asObservable());M(this,"_onInput$",new U.Subject);M(this,"onInput$",this._onInput$.asObservable());M(this,"_onCompositionstart$",new U.BehaviorSubject(null));M(this,"onCompositionstart$",this._onCompositionstart$.asObservable());M(this,"_onCompositionupdate$",new U.BehaviorSubject(null));M(this,"onCompositionupdate$",this._onCompositionupdate$.asObservable());M(this,"_onCompositionend$",new U.BehaviorSubject(null));M(this,"onCompositionend$",this._onCompositionend$.asObservable());M(this,"_onSelectionStart$",new U.BehaviorSubject(null));M(this,"onSelectionStart$",this._onSelectionStart$.asObservable());M(this,"onChangeByEvent$",U.merge(this._onInput$,this._onKeydown$.pipe(U.filter(e=>e.event.keyCode===I.KeyCode.BACKSPACE)),this._onCompositionend$));M(this,"_onPaste$",new U.Subject);M(this,"onPaste$",this._onPaste$.asObservable());M(this,"_textSelectionInner$",new U.BehaviorSubject(null));M(this,"textSelectionInner$",this._textSelectionInner$.asObservable());M(this,"_onFocus$",new U.Subject);M(this,"onFocus$",this._onFocus$.asObservable());M(this,"_onBlur$",new U.Subject);M(this,"onBlur$",this._onBlur$.asObservable());M(this,"_onPointerDown$",new U.Subject);M(this,"onPointerDown$",this._onPointerDown$.asObservable());M(this,"_container");M(this,"_inputParent");M(this,"_input");M(this,"_scrollTimers",[]);M(this,"_rangeList",[]);M(this,"_rangeListCache",[]);M(this,"_rectRangeList",[]);M(this,"_rectRangeListCache",[]);M(this,"_anchorNodePosition",null);M(this,"_focusNodePosition",null);M(this,"_currentSegmentId","");M(this,"_currentSegmentPage",-1);M(this,"_selectionStyle",B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE);M(this,"_onPointerEvent",!1);M(this,"_viewPortObserverMap",new Map);M(this,"_isIMEInputApply",!1);M(this,"_scenePointerMoveSubs",[]);M(this,"_scenePointerUpSubs",[]);M(this,"_reserveRanges",!1);this._context=e,this._layoutService=n,this._logService=r,this._univerInstanceService=s,this._docSkeletonManagerService=a,this._initDOM(),this._registerContainer(),this._setSystemHighlightColorToStyle(),this._listenCurrentUnitChange()}get isOnPointerEvent(){return this._onPointerEvent}get isFocusing(){return this._input===document.activeElement}get canFocusing(){return this.isFocusing||document.activeElement===document.body||document.activeElement===null}_listenCurrentUnitChange(){this._univerInstanceService.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_DOC).pipe(U.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;e.getUnitId()!==this._context.unitId&&!this._reserveRanges&&this.removeAllRanges()})}get activeViewPort(){return this._context.scene.getViewports()[0]}setSegment(e){this._currentSegmentId=e}getSegment(){return this._currentSegmentId}setSegmentPage(e){this._currentSegmentPage=e}getSegmentPage(){return this._currentSegmentPage}setReserveRangesStatus(e){this._reserveRanges=e}_setRangeStyle(e=B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE){this._selectionStyle=e}addDocRanges(e,n=!0,r){const{_currentSegmentId:s,_currentSegmentPage:a,_selectionStyle:c}=this,{scene:l,mainComponent:A}=this._context,d=A,u=this._docSkeletonManagerService.getSkeleton(),m=(g,h)=>{const p=pa(g,h,l,d,u,c,s,a);if(p==null)return;const{textRanges:f,rectRanges:S}=p;for(const E of f)this._addTextRange(E);this._addRectRanges(S)};for(const g of e){const{startOffset:h,endOffset:p,rangeType:f,startNodePosition:S,endNodePosition:E}=g;if(f===i.DOC_RANGE_TYPE.RECT){const C=ma(h,p,l,d,u,c,s,a);C&&this._addRectRanges([C])}else if(f===i.DOC_RANGE_TYPE.TEXT)try{let C=null;S&&E?C=Cr(S.isBack?h:h-1,E.isBack?p:p-1,l,d,u,c,s,a,S.isBack,E.isBack):C=Cr(h,p,l,d,u,c,s,a),C&&this._addTextRange(C)}catch{m(h,p)}else m(h,p)}this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:s,segmentPage:a,style:c,isEditing:n,options:r}),!(!e.length||(r==null?void 0:r.shouldFocus)===!1)&&this._updateInputPosition(r==null?void 0:r.forceFocus)}setCursorManually(e,n){const r=this._findNodeByCoord(e,n,{strict:!0,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),s=this._getNodePosition(r);if(s==null){this._removeAllRanges();return}(r==null?void 0:r.node.streamType)===i.DataStreamTreeTokenType.PARAGRAPH&&(s.isBack=!0),this._createTextRangeByAnchorPosition(s),this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1})}sync(){this._updateInputPosition()}activate(e,n,r=!1){this._container.style.left=`${e}px`,this._container.style.top=`${n}px`,this._container.style.zIndex="1000",(this.canFocusing||r)&&this.focus()}hasFocus(){return document.activeElement===this._input}focus(){this._input.focus()}blur(){this._input.blur()}deactivate(){this._container.style.left="0px",this._container.style.top="0px"}__handleDblClick(e){const{offsetX:n,offsetY:r}=e,s=this._findNodeByCoord(n,r,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const a=Tr(s.node);if(a==null)return;const{content:c,st:l,nodeIndex:A}=a;if(A===-1||Intl.Segmenter==null)return;const u=new Intl.Segmenter(void 0,{granularity:"word"}).segment(c);let m=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;for(const{segment:h,index:p,isWordLike:f}of u)if(p<=A&&A<p+h.length&&f){m=p+l,g=p+l+h.length;break}if(Number.isFinite(m)&&Number.isFinite(g)){this.removeAllRanges();const h=[{startOffset:m,endOffset:g}];this.addDocRanges(h,!1,{forceFocus:!0})}}__handleTripleClick(e){const{offsetX:n,offsetY:r}=e,s=this._findNodeByCoord(n,r,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const a=Tr(s.node);if(a==null)return;this.removeAllRanges();const{st:c,ed:l}=a,A=[{startOffset:c,endOffset:l}];this.addDocRanges(A,!1,{forceFocus:!0})}__onPointDown(e){var f,S;const{scene:n,mainComponent:r}=this._context,s=this._docSkeletonManagerService.getSkeleton(),{offsetX:a,offsetY:c}=e,l=this._findNodeByCoord(a,c,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),A=this._getNodePosition(l);if(A==null||l==null){this._removeAllRanges();return}(l==null?void 0:l.node.streamType)===i.DataStreamTreeTokenType.PARAGRAPH&&(A.isBack=!0);const d=this._textSelectionInner$.value;if(l&&e.button===2&&d){const E=s.findCharIndexByPosition(A);if(typeof E=="number"&&d.textRanges.some(C=>C.startOffset<=E&&C.endOffset>E)||typeof E=="number"&&d.rectRanges.some(C=>C.startOffset<=E&&C.endOffset>=E))return}const{segmentId:u,segmentPage:m}=l;u&&this._currentSegmentId&&u!==this._currentSegmentId&&this.setSegment(u),u&&m!==this._currentSegmentPage&&this.setSegmentPage(m),this._anchorNodePosition=A,e.shiftKey&&this._getActiveRangeInstance()?this._updateActiveRangePosition(A):e.ctrlKey?this._removeAllCollapsedTextRanges():this._isEmpty()||this._removeAllRanges(),n.disableObjectsEvent();const g=B.ScrollTimer.create(n);this._scrollTimers.push(g),g.startScroll(a,c),this._onSelectionStart$.next((f=this._getActiveRangeInstance())==null?void 0:f.startNodePosition),(S=n.getTransformer())==null||S.clearSelectedObjects();let h=a,p=c;this._onPointerEvent=!0,this._scenePointerMoveSubs.push(n.onPointerMove$.subscribeEvent(E=>{const{offsetX:C,offsetY:T}=E;n.setCursor(B.CURSOR_TYPE.TEXT),!(Math.sqrt((C-h)**2+(T-p)**2)<3)&&(this._moving(C,T),g.scrolling(C,T,()=>{this._moving(C,T)}),h=C,p=T)})),this._scenePointerUpSubs.push(n.onPointerUp$.subscribeEvent(()=>{if([...this._scenePointerMoveSubs,...this._scenePointerUpSubs].forEach(C=>{C.unsubscribe()}),this._onPointerEvent=!1,n.enableObjectsEvent(),this._anchorNodePosition&&!this._focusNodePosition){if(e.ctrlKey){this._disposeScrollTimers();return}const C=new je(n,r,s,this._anchorNodePosition,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(C)}else if(this._anchorNodePosition&&this._focusNodePosition){for(const C of this._rangeListCache)e.ctrlKey?C.collapsed?C.dispose():this._addTextRange(C):this._addTextRange(C);this._addRectRanges(this._rectRangeListCache),this._rangeListCache=[],this._rectRangeListCache=[]}this._anchorNodePosition=null,this._focusNodePosition=null;const E={textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1};this._textSelectionInner$.next(E),this._disposeScrollTimers(),this._updateInputPosition(!0)}))}removeAllRanges(){this._removeAllRanges(),this.deactivate()}getActiveTextRange(){return this._getActiveRangeInstance()}_disposeScrollTimers(){this._scrollTimers.forEach(e=>{e==null||e.dispose()}),this._scrollTimers=[]}_setSystemHighlightColorToStyle(){const{r:e,g:n,b:r,a:s}=B.getSystemHighlightColor(),a={strokeWidth:1,stroke:"rgba(0, 0, 0, 0)",strokeActive:"rgba(0, 0, 0, 1)",fill:`rgba(${e}, ${n}, ${r}, ${s!=null?s:.3})`};this._setRangeStyle(a)}_getAllTextRanges(){return this._rangeList.map(Yn)}_getAllRectRanges(){return this._rectRangeList.map(fa)}getAllTextRanges(){return this._getAllTextRanges()}getAllRectRanges(){return this._getAllRectRanges()}_getActiveRange(){const e=this._rangeList.find(s=>s.isActive());if(e==null)return null;const{startOffset:n,endOffset:r}=e;return n==null||r==null?null:Yn(e)}_getActiveRangeInstance(){return this._rangeList.find(e=>e.isActive())}dispose(){super.dispose(),this._detachEvent(),this._removeAllRanges(),this._container.remove()}_initDOM(){const{unitId:e}=this._context,n=document.createElement("div");n.style.position="fixed",n.style.left="0px",n.style.top="0px",n.id=`univer-doc-selection-container-${e}`;const r=document.createElement("div"),s=document.createElement("div");r.appendChild(s),n.appendChild(r),this._container=n,this._inputParent=r,this._input=s,this._initInput(),this._initInputEvents(),document.body.appendChild(n)}_registerContainer(){this.disposeWithMe(this._layoutService.registerContainerElement(this._container))}_initInput(){this._inputParent.style.cssText=`
|
|
13
|
+
they are not in the same segment page when in header or footer.`);const{start:c,end:l}=Gn(t,e);return this._selectionIterator(c,l,(A,d,u,m,g,h)=>{const{lineHeight:p,asc:f,paddingTop:S,marginTop:E,marginBottom:C}=h,{glyphGroup:T,st:R}=g;if(T.length===0)return;const{x:v,y:b}=this._liquid;let x,y;const _=T[A],O=T[d],w=T[A-1],Q=(_==null?void 0:_.left)||0,k=(_==null?void 0:_.width)||0,F=(O==null?void 0:O.left)||0,L=(O==null?void 0:O.width)||0,G=(_==null?void 0:_.glyphType)===B.GlyphType.LIST,{startOffset:W,endOffset:H}=ca(T,A,d,R),V=c.glyph===A&&u?c.isBack:!0,j=l.glyph===d&&m?l.isBack:!1,X=c===l,z=V&&w!=null?w:_;if(A===0&&d===T.length-1)x={startX:v+Q+(G?k:0),startY:b,endX:v+F+(j?0:L),endY:b+p-E-C},y={startX:v+Q+(G?k:0),startY:b+S+f-z.bBox.ba,endX:v+F+(j?0:L),endY:b+S+f+z.bBox.bd};else{const Y=V&&!G;x={startX:v+Q+(Y?0:k),startY:b,endX:v+F+(j?0:L),endY:b+p-E-C},y={startX:v+Q+(Y?0:k),startY:b+S+f-z.bBox.ba,endX:v+F+(j?0:L),endY:b+S+f+z.bBox.bd}}n.push(Kn(x)),r.push(Kn(y)),s.push({startOffset:V?W:W+_.count,endOffset:j?H:H+O.count,collapsed:X})}),{borderBoxPointGroup:n,contentBoxPointGroup:r,cursorList:s}}_isValidPosition(t,e){const{segmentPage:n,pageType:r}=t,{segmentPage:s,pageType:a}=e;return r!==a?!1:r===B.DocumentSkeletonPageType.HEADER||r===B.DocumentSkeletonPageType.FOOTER?n===s:!0}_resetCurrentNodePositionState(){this._currentStartState={page:0,section:0,column:0,line:0,divide:0,glyph:0},this._currentEndState={page:0,section:0,column:0,line:0,divide:0,glyph:0}}_setNodePositionState(t=0,e,n,r){r===e?this._currentStartState[t]=1:this._currentStartState[t]=0,r===n?this._currentEndState[t]=2:this._currentEndState[t]=0}_checkPreviousNodePositionState(t,e=!0){let n=t,r;for(;n>=0;){const s=jt[n];let a;if(e?a=this._currentStartState[s]:a=this._currentEndState[s],a===void 0)return;if(r===void 0&&(r=a),a!==r)return 0;n--}return r}_getSelectionRuler(t,e,n,r,s){let a=0,c=r;const l=jt[t],A=jt[t+1];if(A===null||l===null)return{start_next:a,end_next:c};const d=e[l],u=n[l];this._setNodePositionState(l,d,u,s);const m=this._checkPreviousNodePositionState(t),g=this._checkPreviousNodePositionState(t,!1);return m===1&&(a=e[A]),g===2&&(c=n[A]),{start_next:a,end_next:c}}_selectionIterator(t,e,n){var T,R;const r=this._docSkeleton;if(!r)return[];const{pageType:s,path:a}=t;this._liquid.reset();const c=r.getSkeletonData();if(c==null)return[];const{pages:l,skeHeaders:A,skeFooters:d}=c,{page:u,segmentPage:m}=t,{page:g,segmentPage:h}=e;if(this._resetCurrentNodePositionState(),this._documentOffsetConfig==null)return[];const{pageLayoutType:p,pageMarginLeft:f,pageMarginTop:S}=this._documentOffsetConfig,E=s===B.DocumentSkeletonPageType.BODY||s===B.DocumentSkeletonPageType.CELL?u:m;for(let v=0;v<E;v++){const b=l[v];this._liquid.translatePage(b,p,f,S)}const C=s===B.DocumentSkeletonPageType.BODY||s===B.DocumentSkeletonPageType.CELL?g:h;for(let v=E;v<=C;v++){const b=l[v],{headerId:x,footerId:y,pageWidth:_}=b;let O=b;if(s===B.DocumentSkeletonPageType.HEADER?O=(T=A.get(x))==null?void 0:T.get(_):s===B.DocumentSkeletonPageType.FOOTER?O=(R=d.get(y))==null?void 0:R.get(_):s===B.DocumentSkeletonPageType.CELL&&(O=B.getPageFromPath(c,a)),O==null){this._liquid.translatePage(b,p,f,S);continue}const w=O.sections,{start_next:Q,end_next:k}=this._getSelectionRuler($e.page,t,e,w.length-1,s===B.DocumentSkeletonPageType.BODY||s===B.DocumentSkeletonPageType.CELL?v:0);switch(this._liquid.translateSave(),s){case B.DocumentSkeletonPageType.HEADER:this._liquid.translatePagePadding({...O,marginLeft:b.marginLeft});break;case B.DocumentSkeletonPageType.FOOTER:{const F=b.pageHeight-O.height-O.marginBottom;this._liquid.translate(b.marginLeft,F);break}case B.DocumentSkeletonPageType.CELL:{this._liquid.translatePagePadding(b);const F=O.parent,L=F.parent,{left:G}=O,{top:W,left:H}=L,{top:V}=F;this._liquid.translate(H+G,W+V),this._liquid.translatePagePadding(O);break}default:this._liquid.translatePagePadding(b);break}for(let F=Q;F<=k;F++){const L=w[F],G=L.columns,{start_next:W,end_next:H}=this._getSelectionRuler($e.section,t,e,G.length-1,F);this._liquid.translateSection(L);for(let V=W;V<=H;V++){const j=G[V],X=j.lines,{start_next:z,end_next:Y}=this._getSelectionRuler($e.column,t,e,X.length-1,V);this._liquid.translateColumn(j);for(let K=z;K<=Y;K++){const Z=X[K],{divides:ne}=Z,{start_next:ge,end_next:xe}=this._getSelectionRuler($e.line,t,e,ne.length-1,K);this._liquid.translateSave(),this._liquid.translateLine(Z,!0,!1);for(let he=ge;he<=xe;he++){const On=ne[he];this._liquid.translateSave(),this._liquid.translateDivide(On);const{glyphGroup:hs}=On,{start_next:ms,end_next:ps}=this._getSelectionRuler($e.divide,t,e,hs.length-1,he);let nr=!1,or=!1;v===E&&F===Q&&V===W&&K===z&&he===ge&&(nr=!0),v===C&&F===k&&V===H&&K===Y&&he===xe&&(or=!0),n&&n(ms,ps,nr,or,On,Z,j,L,O),this._liquid.translateRestore()}this._liquid.translateRestore()}}}this._liquid.translateRestore(),this._liquid.translatePage(b,p,f,S)}}}function bi(o,t){const{path:e}=o,{path:n}=t;if(e.length!==n.length||e.indexOf("cells")===-1)return!1;const r=e.indexOf("skeTables")+1,s=e.indexOf("rows")+1,a=e.indexOf("cells")+1,{tableId:c,sliceIndex:l}=B.getTableIdAndSliceIndex(e[r]),{tableId:A,sliceIndex:d}=B.getTableIdAndSliceIndex(n[r]);if(c!==A)return!1;const u=e[s],m=n[s],g=e[a],h=n[a];return!(u===m&&g===h&&l===d)}function ko(o,t){const{path:e}=o,{path:n}=t;return e.indexOf("cells")===-1||n.indexOf("cells")===-1||e.length!==n.length?!1:i.Tools.diffValue(e,n)}function Ri(o,t,e){var g,h,p,f,S,E,C,T;const{path:n}=t,{path:r}=e;if(n.indexOf("cells")===-1||r.indexOf("cells")===-1)return!1;const s=o.findGlyphByPosition(t),a=o.findGlyphByPosition(e),c=(f=(p=(h=(g=s==null?void 0:s.parent)==null?void 0:g.parent)==null?void 0:h.parent)==null?void 0:p.parent)==null?void 0:f.parent,l=(T=(C=(E=(S=a==null?void 0:a.parent)==null?void 0:S.parent)==null?void 0:E.parent)==null?void 0:C.parent)==null?void 0:T.parent;if(c==null||l==null)return!1;const A=c.parent,d=l.parent,u=A.cells.indexOf(c),m=d.cells.indexOf(l);return u===m&&A.index===d.index}function Nn(o,t){if(ko(o,t))return Ho(o,t);const{path:e}=o,{path:n}=t,r=e[e.length-5],s=n[n.length-5];if(r!==s&&typeof r=="string"&&typeof s=="string"){const d=r.split("#-#")[1],u=s.split("#-#")[1];return+d<+u}const a=e[e.length-3],c=n[n.length-3],l=e[e.length-1],A=n[n.length-1];return a<c?!0:a>c?!1:l<=A}function ze(o){return o.sections[0].columns[0].lines.length===0}function la(o,t,e){let n=t,r=e,s=o[n],a=o[r];for(;n<r&&(ze(s)||ze(a));)ze(s)?(n++,s=o[n]):ze(a)&&(r--,a=o[r]);if(!ze(s)&&!ze(a))return[s,a]}class Vo{constructor(t,e){M(this,"_liquid",new B.Liquid);this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],s=this._docSkeleton.getSkeletonData();if(s==null)return;const{pages:a}=s,{segmentPage:c,page:l,pageType:A}=t,d=this._getTableRectRangeInfo(t,e);if(d==null)return;const{tableId:u,startRowIndex:m,startColumnIndex:g,endRowIndex:h,endColumnIndex:p}=d;this._liquid.reset();const{pageLayoutType:f,pageMarginLeft:S,pageMarginTop:E}=this._documentOffsetConfig,C=A===B.DocumentSkeletonPageType.BODY||A===B.DocumentSkeletonPageType.CELL?l:c;for(let T=0;T<C;T++){const R=a[T];this._liquid.translatePage(R,f,S,E)}for(let T=C;T<a.length;T++){const R=a[T];this._liquid.translatePagePadding(R);const{skeTables:v}=R;let b=null;for(const[O,w]of v.entries())O.startsWith(u)&&(b=w);if(b==null){this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E);continue}this._liquid.translateSave(),this._liquid.translate(0,b.top);const{x,y}=this._liquid,{left:_}=b;for(const O of b.rows)if(O.index>=m&&O.index<=h){const w=la(O.cells,g,p);if(w==null)continue;const[Q,k]=w,F={startX:x+Q.left+_,startY:y+O.top,endX:x+k.left+k.pageWidth+_,endY:y+O.top+O.height};n.push(Kn(F))}this._liquid.translateRestore(),this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E)}return{pointGroup:n,startRow:m,startColumn:g,endRow:h,endColumn:p,tableId:u}}getNodePositionGroup(t,e){const n=[],r=this._docSkeleton.findCharIndexByPosition(t),s=this._docSkeleton.findCharIndexByPosition(e);if(r==null||s==null)return;const a=r<s,c=this._getTableRectRangeInfo(t,e);if(c==null)return;const{tableId:l,startRowIndex:A,startColumnIndex:d,endRowIndex:u,endColumnIndex:m}=c,g=this._docSkeleton.getViewModel().findTableNodeById(l);if(g==null)return;const h=g.children[0].children.length;if(d===0&&m===h-1){const f=g.children[A].children[d],S=this._docSkeleton.findNodePositionByCharIndex(f.startIndex+1),E=g.children[u].children[m],C=this._docSkeleton.findNodePositionByCharIndex(E.endIndex-2);if(S==null||C==null)return;n.push({anchor:a?S:C,focus:a?C:S})}else for(let f=A;f<=u;f++){const S=g.children[f],E=S.children[d],C=S.children[m],T=this._docSkeleton.findNodePositionByCharIndex(E.startIndex+1),R=this._docSkeleton.findNodePositionByCharIndex(C.endIndex-2);if(T==null||R==null)return;n.push({anchor:a?T:R,focus:a?R:T})}return n}_getTableRectRangeInfo(t,e){const r=this._docSkeleton.getSkeletonData();if(r==null)return;const{pages:s}=r,{path:a}=t,{path:c}=e,l=B.getPageFromPath(r,a),A=B.getPageFromPath(r,c);if(l==null||A==null)return;const d=l.segmentId,u=l.parent.index,m=l.parent.cells.indexOf(l),g=(A==null?void 0:A.parent).index,h=(A==null?void 0:A.parent).cells.indexOf(A),p=Math.min(u,g),f=Math.max(u,g),S=Math.min(m,h),E=Math.max(m,h);return{pages:s,tableId:d,startRowIndex:p,startColumnIndex:S,endRowIndex:f,endColumnIndex:E}}}const da="__TestSelectionRange__",Aa="__TestSelectionAnchor__",Er=6,Pn=500,ua=500,Yt=3;function It(o){const t=o[0],e=t[0],n=t[2],{x:r,y:s}=e,{x:a,y:c}=n;return{left:r,top:s,width:a-r,height:c-s}}function In(o){return o.map(t=>{let e=1/0,n=-1/0,r=1/0,s=-1/0;return t.forEach(a=>{e=Math.min(a.x,e),n=Math.max(a.x,n),s=Math.max(a.y,s),r=Math.min(a.y,r)}),{left:e,right:n,top:r,bottom:s}})}class je{constructor(t,e,n,r,s,a=B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){M(this,"rangeType",i.DOC_RANGE_TYPE.TEXT);M(this,"_current",!1);M(this,"_rangeShape");M(this,"_anchorShape");M(this,"_cursorList",[]);M(this,"_anchorBlinkTimer",null);this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=r,this.focusNodePosition=s,this.style=a,this._segmentId=c,this._segmentPage=l,this._anchorBlink(),this.refresh()}_anchorBlink(){setTimeout(()=>{this._anchorShape&&this._anchorShape.visible&&this.deactivateStatic()},Pn),this._anchorBlinkTimer=setInterval(()=>{this._anchorShape&&this._anchorShape.visible&&(this.activeStatic(),setTimeout(()=>{this.deactivateStatic()},Pn))},ua+Pn)}get startOffset(){var r;const{startOffset:t}=(r=Xn(this._cursorList))!=null?r:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(n,t)}get endOffset(){var r;const{endOffset:t}=(r=Xn(this._cursorList))!=null?r:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(t,n)}get collapsed(){const{startOffset:t,endOffset:e}=this;return t!=null&&t===e}get startNodePosition(){if(this.anchorNodePosition==null)return null;if(this.focusNodePosition==null)return this.anchorNodePosition;const{start:t}=Gn(this.anchorNodePosition,this.focusNodePosition);return t}get endNodePosition(){if(this.anchorNodePosition==null)return this.focusNodePosition;if(this.focusNodePosition==null)return null;const{end:t}=Gn(this.anchorNodePosition,this.focusNodePosition);return t}get direction(){const{collapsed:t,anchorNodePosition:e,focusNodePosition:n}=this;return t||e==null||n==null?i.RANGE_DIRECTION.NONE:Ho(e,n)?i.RANGE_DIRECTION.FORWARD:i.RANGE_DIRECTION.BACKWARD}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}getAbsolutePosition(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(this._isEmpty())return;const n=this._document.getOffsetConfig(),{docsLeft:r,docsTop:s}=n,a=new Ee(n,this._docSkeleton);if(this._isCollapsed()){const{contentBoxPointGroup:d,cursorList:u}=a.getRangePointData(t,t);if(this._setCursorList(u),d.length===0)return;const m=It(d);return{...m,left:m.left+r,top:m.top+s}}const{borderBoxPointGroup:c,cursorList:l}=a.getRangePointData(t,e);if(this._setCursorList(l),c.length===0)return;const A=It(c);return{...A,left:A.left+r,top:A.top+s}}getAnchor(){return this._anchorShape}activeStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.strokeActive)||B.getColor(i.COLORS.black,1)})}deactivateStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.stroke)||B.getColor(i.COLORS.black,0)})}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t,e;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null,(e=this._anchorShape)==null||e.dispose(),this._anchorShape=null,this._anchorBlinkTimer&&(clearInterval(this._anchorBlinkTimer),this._anchorBlinkTimer=null)}isIntersection(t){const{startOffset:e,endOffset:n}=this,{startOffset:r,endOffset:s}=t;return e==null||n==null||r==null||s==null?!1:e<=s&&n>=r}refresh(){var u,m;const{_document:t,_docSkeleton:e}=this,n=this.anchorNodePosition,r=this.focusNodePosition;if((u=this._anchorShape)==null||u.hide(),(m=this._rangeShape)==null||m.hide(),this._isEmpty())return;const s=t.getOffsetConfig(),{docsLeft:a,docsTop:c}=s,l=new Ee(s,e);if(this._isCollapsed()){const{contentBoxPointGroup:g,cursorList:h}=l.getRangePointData(n,n);if(this._setCursorList(h),g.length>0){const p=e.findGlyphByPosition(n);this._createOrUpdateAnchor(g,a,c,p)}return}const{borderBoxPointGroup:A,cursorList:d}=l.getRangePointData(n,r);this._setCursorList(d),A.length>0&&this._createOrUpdateRange(A,a,c)}_isEmpty(){return this.anchorNodePosition==null&&this.focusNodePosition==null}_isCollapsed(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(t!=null&&e==null)return!0;if(t==null||e==null)return!1;const n=Object.keys($e);for(const r of n){const s=t[r],a=e[r];if(s!==a)return!1}return t.isBack===e.isBack}_createOrUpdateRange(t,e,n){var a;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const r=.3,s=new B.RegularPolygon(da+i.generateRandomId(Er),{pointsGroup:t,fill:((a=this.style)==null?void 0:a.fill)||B.getColor(i.COLORS.black,r),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,Yt)}_createOrUpdateAnchor(t,e,n,r){var p,f,S;const s=It(t),{left:a}=s;let{top:c,height:l}=s;const A=14;l<A&&(c-=A-l,l=A);const d=12;let u=a+e;const m=c+n,g=((p=r==null?void 0:r.ts)==null?void 0:p.it)===i.BooleanNumber.TRUE;if(g&&(u+=l*Math.tan(d*Math.PI/180)/2),this._anchorShape){this._anchorShape.transformByState({left:u,top:m,height:l}),this._anchorShape.show(),g?this._anchorShape.skew(-d,0):this._anchorShape.skew(0,0);return}const h=new B.Rect(Aa+i.generateRandomId(Er),{left:u,top:m,height:l,strokeWidth:((f=this.style)==null?void 0:f.strokeWidth)||1,stroke:((S=this.style)==null?void 0:S.strokeActive)||B.getColor(i.COLORS.black,1),evented:!1});g&&h.skew(-d,0),this._anchorShape=h,this._scene.addObject(h,Yt),this.activeStatic()}_setCursorList(t){t.length!==0&&(this._cursorList=t)}}const ga="__DocTableRectRange__",ha=6;function Wt(o,t,e,n,r,s=B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,a="",c=-1){const l=t.getOffsetConfig(),d=new Vo(l,e).getNodePositionGroup(n,r);return(d!=null?d:[]).map(u=>new jo(o,t,e,u.anchor,u.focus,s,a,c))}class jo{constructor(t,e,n,r,s,a=B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){M(this,"rangeType",i.DOC_RANGE_TYPE.RECT);M(this,"_rangeShape");M(this,"_current",!1);M(this,"_startRow");M(this,"_startCol");M(this,"_endRow");M(this,"_endCol");M(this,"_tableId");this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=r,this.focusNodePosition=s,this.style=a,this._segmentId=c,this._segmentPage=l,this.refresh()}get startOffset(){const{startNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get endOffset(){const{endNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get collapsed(){return!1}get startRow(){return this._startRow}get startColumn(){return this._startCol}get endRow(){return this._endRow}get endColumn(){return this._endCol}get tableId(){return this._tableId}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}get spanEntireRow(){var a;const e=(a=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:a[this._tableId],{_startCol:n,_endCol:r}=this;if(e==null)throw new Error("Table is not found.");const{tableColumns:s}=e;return n===0&&r===s.length-1}get spanEntireColumn(){var a;const e=(a=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:a[this._tableId],{_startRow:n,_endRow:r}=this;if(e==null)throw new Error("Table is not found.");const{tableRows:s}=e;return n===0&&r===s.length-1}get spanEntireTable(){return this.spanEntireRow&&this.spanEntireColumn}get startNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Nn(t,e)?t:e}get endNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Nn(t,e)?e:t}get direction(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Nn(t,e)?i.RANGE_DIRECTION.FORWARD:i.RANGE_DIRECTION.BACKWARD}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null}isIntersection(t){const{startRow:e,startColumn:n,endRow:r,endColumn:s}=this,{startRow:a,startColumn:c,endRow:l,endColumn:A}=t,d={left:n,top:e,right:s,bottom:r},u={left:c,top:a,right:A,bottom:l};return i.Rectangle.hasIntersectionBetweenTwoRect(d,u)}refresh(){var f;(f=this._rangeShape)==null||f.hide();const{startNodePosition:t,endNodePosition:e,_document:n,_docSkeleton:r}=this,s=n.getOffsetConfig(),{docsLeft:a,docsTop:c}=s,A=new Vo(s,r).getRangePointData(t,e);if(A==null)return;const{pointGroup:d=[],startRow:u,endRow:m,startColumn:g,endColumn:h,tableId:p}=A;(d==null?void 0:d.length)>0&&this._createOrUpdateRange(d,a,c),this._updateTableInfo(u,m,g,h,p)}_updateTableInfo(t,e,n,r,s){this._startRow=t,this._endRow=e,this._startCol=n,this._endCol=r,this._tableId=s}_createOrUpdateRange(t,e,n){var a;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const r=.3,s=new B.RegularPolygon(ga+i.generateRandomId(ha),{pointsGroup:t,fill:((a=this.style)==null?void 0:a.fill)||B.getColor(i.COLORS.black,r),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,Yt)}}function Cr(o,t,e,n,r,s,a,c,l=!0,A=!0){const d=r.findNodePositionByCharIndex(o,l,a,c),u=r.findNodePositionByCharIndex(t,A,a,c);if(!(d==null||u==null))return new je(e,n,r,d,u,s,a,c)}function ma(o,t,e,n,r,s,a,c){const l=r.findNodePositionByCharIndex(o,!0,a,c),A=r.findNodePositionByCharIndex(t,!0,a,c);if(!(l==null||A==null))return new jo(e,n,r,l,A,s,a,c)}function pa(o,t,e,n,r,s,a,c){const l=r.findNodePositionByCharIndex(o,!0,a,c),A=r.findNodePositionByCharIndex(t,!0,a,c);if(!(l==null||A==null))return zn(l,A,e,n,r,s,a,c)}function zn(o,t,e,n,r,s,a,c){const l=[],A=[],d=[e,n,r,o,t,s,a,c];if(Ri(r,o,t)){if(ko(o,t))return l.push(new je(...d)),{textRanges:l,rectRanges:A};{const C=Wt(...d);return A.push(...C),{textRanges:l,rectRanges:A}}}if(bi(o,t)){const C=Wt(...d);return A.push(...C),{textRanges:l,rectRanges:A}}const u=r.getViewModel().getSelfOrHeaderFooterViewModel(a),m=r.findCharIndexByPosition(o),g=r.findCharIndexByPosition(t);if(m==null||g==null)return;const h=m<=g?i.RANGE_DIRECTION.FORWARD:i.RANGE_DIRECTION.BACKWARD,p=Math.min(m,g),f=Math.max(m,g);let S=p,E=f;for(const C of u.getChildren())for(const T of C.children){const{startIndex:R,endIndex:v,children:b}=T,x=C.children.indexOf(T),y=C.children[x+1],_=b[0];let O=!1;if(_){const{startIndex:w,endIndex:Q,children:k}=_;let F=null,L=null;const G=k.find(H=>H.startIndex<=p&&H.endIndex>=p),W=k.find(H=>H.startIndex<=f&&H.endIndex>=f);if(p>w&&p<Q)F=r.findNodePositionByCharIndex(G.startIndex+2,!0,a,c),L=r.findNodePositionByCharIndex(Q-4,!0,a,c),S=Q+1;else if(f>w&&f<Q)F=r.findNodePositionByCharIndex(w+3,!0,a,c),L=r.findNodePositionByCharIndex(W.endIndex-3,!0,a,c),E=w-1,O=!0;else if(w>p&&Q<f){if(F=r.findNodePositionByCharIndex(w+3,!0,a,c),L=r.findNodePositionByCharIndex(Q-4,!0,a,c),S<=w-1){const H=r.findNodePositionByCharIndex(S,!0,a,c),V=r.findNodePositionByCharIndex(w-1,!1,a,c),j=h===i.RANGE_DIRECTION.FORWARD?H:V,X=h===i.RANGE_DIRECTION.FORWARD?V:H;l.push(new je(e,n,r,j,X,s,a,c))}S=Q+1}if(F&&L){const H=h===i.RANGE_DIRECTION.FORWARD?F:L,V=h===i.RANGE_DIRECTION.FORWARD?L:F;A.push(...Wt(e,n,r,H,V,s,a,c))}}if(E===v+1&&!O&&y&&y.children.length&&(E=v,O=!0),E>=R&&E<=v||O){const w=r.findNodePositionByCharIndex(S,!0,a,c),Q=r.findNodePositionByCharIndex(E,!O,a,c),k=h===i.RANGE_DIRECTION.FORWARD?w:Q,F=h===i.RANGE_DIRECTION.FORWARD?Q:w;if(A.length&&i.Tools.diffValue(k,F))continue;l.push(new je(e,n,r,k,F,s,a,c))}}return{textRanges:l,rectRanges:A}}function xi(o){const t=o==null?void 0:o.getCanvasElement();if(!t)return{left:0,top:0};const{top:e,left:n}=B.getOffsetRectForDom(t);return{left:n,top:e}}function Tr(o){var l;const t=(l=o.parent)==null?void 0:l.parent,e=t==null?void 0:t.parent;if(t==null||e==null)return;const{paragraphIndex:n}=t,r=e.lines.filter(A=>A.paragraphIndex===n);let s=-1,a="",c=!1;for(const A of r)for(const d of A.divides)for(const u of d.glyphGroup)c||(s+=u.count),u===o&&(c=!0),a+=u.count>0?u.content:"";return{st:r[0].st,ed:n,content:a,nodeIndex:s}}function Yn(o){const{startOffset:t,endOffset:e,collapsed:n,rangeType:r,startNodePosition:s,endNodePosition:a,direction:c,segmentId:l,segmentPage:A}=o;return{startOffset:t,endOffset:e,collapsed:n,rangeType:r,startNodePosition:s,endNodePosition:a,direction:c,segmentId:l,segmentPage:A,isActive:o.isActive()}}function fa(o){const t=Yn(o),{startRow:e,startColumn:n,endRow:r,endColumn:s,tableId:a,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}=o;return{...t,startRow:e,startColumn:n,endRow:r,endColumn:s,tableId:a,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}}var Sa=Object.getOwnPropertyDescriptor,Ia=(o,t,e,n)=>{for(var r=n>1?void 0:n?Sa(t,e):t,s=o.length-1,a;s>=0;s--)(a=o[s])&&(r=a(r)||r);return r},Ut=(o,t)=>(e,n)=>t(e,n,o);exports.DocSelectionRenderService=class extends i.RxDisposable{constructor(e,n,r,s,a){super();M(this,"_onInputBefore$",new U.Subject);M(this,"onInputBefore$",this._onInputBefore$.asObservable());M(this,"_onKeydown$",new U.Subject);M(this,"onKeydown$",this._onKeydown$.asObservable());M(this,"_onInput$",new U.Subject);M(this,"onInput$",this._onInput$.asObservable());M(this,"_onCompositionstart$",new U.BehaviorSubject(null));M(this,"onCompositionstart$",this._onCompositionstart$.asObservable());M(this,"_onCompositionupdate$",new U.BehaviorSubject(null));M(this,"onCompositionupdate$",this._onCompositionupdate$.asObservable());M(this,"_onCompositionend$",new U.BehaviorSubject(null));M(this,"onCompositionend$",this._onCompositionend$.asObservable());M(this,"_onSelectionStart$",new U.BehaviorSubject(null));M(this,"onSelectionStart$",this._onSelectionStart$.asObservable());M(this,"onChangeByEvent$",U.merge(this._onInput$,this._onKeydown$.pipe(U.filter(e=>e.event.keyCode===I.KeyCode.BACKSPACE)),this._onCompositionend$));M(this,"_onPaste$",new U.Subject);M(this,"onPaste$",this._onPaste$.asObservable());M(this,"_textSelectionInner$",new U.BehaviorSubject(null));M(this,"textSelectionInner$",this._textSelectionInner$.asObservable());M(this,"_onFocus$",new U.Subject);M(this,"onFocus$",this._onFocus$.asObservable());M(this,"_onBlur$",new U.Subject);M(this,"onBlur$",this._onBlur$.asObservable());M(this,"_onPointerDown$",new U.Subject);M(this,"onPointerDown$",this._onPointerDown$.asObservable());M(this,"_container");M(this,"_inputParent");M(this,"_input");M(this,"_scrollTimers",[]);M(this,"_rangeList",[]);M(this,"_rangeListCache",[]);M(this,"_rectRangeList",[]);M(this,"_rectRangeListCache",[]);M(this,"_anchorNodePosition",null);M(this,"_focusNodePosition",null);M(this,"_currentSegmentId","");M(this,"_currentSegmentPage",-1);M(this,"_selectionStyle",B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE);M(this,"_onPointerEvent",!1);M(this,"_viewPortObserverMap",new Map);M(this,"_isIMEInputApply",!1);M(this,"_scenePointerMoveSubs",[]);M(this,"_scenePointerUpSubs",[]);M(this,"_reserveRanges",!1);this._context=e,this._layoutService=n,this._logService=r,this._univerInstanceService=s,this._docSkeletonManagerService=a,this._initDOM(),this._registerContainer(),this._setSystemHighlightColorToStyle(),this._listenCurrentUnitChange()}get isOnPointerEvent(){return this._onPointerEvent}get isFocusing(){return this._input===document.activeElement}get canFocusing(){return this.isFocusing||document.activeElement===document.body||document.activeElement===null}_listenCurrentUnitChange(){this._univerInstanceService.getCurrentTypeOfUnit$(i.UniverInstanceType.UNIVER_DOC).pipe(U.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;e.getUnitId()!==this._context.unitId&&!this._reserveRanges&&this.removeAllRanges()})}get activeViewPort(){return this._context.scene.getViewports()[0]}setSegment(e){this._currentSegmentId=e}getSegment(){return this._currentSegmentId}setSegmentPage(e){this._currentSegmentPage=e}getSegmentPage(){return this._currentSegmentPage}setReserveRangesStatus(e){this._reserveRanges=e}_setRangeStyle(e=B.NORMAL_TEXT_SELECTION_PLUGIN_STYLE){this._selectionStyle=e}addDocRanges(e,n=!0,r){const{_currentSegmentId:s,_currentSegmentPage:a,_selectionStyle:c}=this,{scene:l,mainComponent:A}=this._context,d=A,u=this._docSkeletonManagerService.getSkeleton(),m=(g,h)=>{const p=pa(g,h,l,d,u,c,s,a);if(p==null)return;const{textRanges:f,rectRanges:S}=p;for(const E of f)this._addTextRange(E);this._addRectRanges(S)};for(const g of e){const{startOffset:h,endOffset:p,rangeType:f,startNodePosition:S,endNodePosition:E}=g;if(f===i.DOC_RANGE_TYPE.RECT){const C=ma(h,p,l,d,u,c,s,a);C&&this._addRectRanges([C])}else if(f===i.DOC_RANGE_TYPE.TEXT)try{let C=null;S&&E?C=Cr(S.isBack?h:h-1,E.isBack?p:p-1,l,d,u,c,s,a,S.isBack,E.isBack):C=Cr(h,p,l,d,u,c,s,a),C&&this._addTextRange(C)}catch{m(h,p)}else m(h,p)}this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:s,segmentPage:a,style:c,isEditing:n,options:r}),!(!e.length||(r==null?void 0:r.shouldFocus)===!1)&&this._updateInputPosition(r==null?void 0:r.forceFocus)}setCursorManually(e,n){const r=this._findNodeByCoord(e,n,{strict:!0,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),s=this._getNodePosition(r);if(s==null){this._removeAllRanges();return}(r==null?void 0:r.node.streamType)===i.DataStreamTreeTokenType.PARAGRAPH&&(s.isBack=!0),this._createTextRangeByAnchorPosition(s),this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1})}sync(){this._updateInputPosition()}activate(e,n,r=!1){this._container.style.left=`${e}px`,this._container.style.top=`${n}px`,this._container.style.zIndex="1000",(this.canFocusing||r)&&this.focus()}hasFocus(){return document.activeElement===this._input}focus(){this._input.focus()}blur(){this._input.blur()}deactivate(){this._container.style.left="0px",this._container.style.top="0px"}__handleDblClick(e){const{offsetX:n,offsetY:r}=e,s=this._findNodeByCoord(n,r,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const a=Tr(s.node);if(a==null)return;const{content:c,st:l,nodeIndex:A}=a;if(A===-1||Intl.Segmenter==null)return;const u=new Intl.Segmenter(void 0,{granularity:"word"}).segment(c);let m=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;for(const{segment:h,index:p,isWordLike:f}of u)if(p<=A&&A<p+h.length&&f){m=p+l,g=p+l+h.length;break}if(Number.isFinite(m)&&Number.isFinite(g)){this.removeAllRanges();const h=[{startOffset:m,endOffset:g}];this.addDocRanges(h,!1,{forceFocus:!0})}}__handleTripleClick(e){const{offsetX:n,offsetY:r}=e,s=this._findNodeByCoord(n,r,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const a=Tr(s.node);if(a==null)return;this.removeAllRanges();const{st:c,ed:l}=a,A=[{startOffset:c,endOffset:l}];this.addDocRanges(A,!1,{forceFocus:!0})}__onPointDown(e){var f,S;const{scene:n,mainComponent:r}=this._context,s=this._docSkeletonManagerService.getSkeleton(),{offsetX:a,offsetY:c}=e,l=this._findNodeByCoord(a,c,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),A=this._getNodePosition(l);if(A==null||l==null){this._removeAllRanges();return}(l==null?void 0:l.node.streamType)===i.DataStreamTreeTokenType.PARAGRAPH&&(A.isBack=!0);const d=this._textSelectionInner$.value;if(l&&e.button===2&&d){const E=s.findCharIndexByPosition(A);if(typeof E=="number"&&d.textRanges.some(C=>C.startOffset<=E&&C.endOffset>E)||typeof E=="number"&&d.rectRanges.some(C=>C.startOffset<=E&&C.endOffset>=E))return}const{segmentId:u,segmentPage:m}=l;u&&this._currentSegmentId&&u!==this._currentSegmentId&&this.setSegment(u),u&&m!==this._currentSegmentPage&&this.setSegmentPage(m),this._anchorNodePosition=A,e.shiftKey&&this._getActiveRangeInstance()?this._updateActiveRangePosition(A):e.ctrlKey?this._removeAllCollapsedTextRanges():this._isEmpty()||this._removeAllRanges(),n.disableObjectsEvent();const g=B.ScrollTimer.create(n);this._scrollTimers.push(g),g.startScroll(a,c),this._onSelectionStart$.next((f=this._getActiveRangeInstance())==null?void 0:f.startNodePosition),(S=n.getTransformer())==null||S.clearSelectedObjects();let h=a,p=c;this._onPointerEvent=!0,this._scenePointerMoveSubs.push(n.onPointerMove$.subscribeEvent(E=>{const{offsetX:C,offsetY:T}=E;n.setCursor(B.CURSOR_TYPE.TEXT),!(Math.sqrt((C-h)**2+(T-p)**2)<3)&&(this._moving(C,T),g.scrolling(C,T,()=>{this._moving(C,T)}),h=C,p=T)})),this._scenePointerUpSubs.push(n.onPointerUp$.subscribeEvent(()=>{if([...this._scenePointerMoveSubs,...this._scenePointerUpSubs].forEach(C=>{C.unsubscribe()}),this._onPointerEvent=!1,n.enableObjectsEvent(),this._anchorNodePosition&&!this._focusNodePosition){if(e.ctrlKey){this._disposeScrollTimers();return}const C=new je(n,r,s,this._anchorNodePosition,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(C)}else if(this._anchorNodePosition&&this._focusNodePosition){for(const C of this._rangeListCache)e.ctrlKey?C.collapsed?C.dispose():this._addTextRange(C):this._addTextRange(C);this._addRectRanges(this._rectRangeListCache),this._rangeListCache=[],this._rectRangeListCache=[]}this._anchorNodePosition=null,this._focusNodePosition=null;const E={textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1};this._textSelectionInner$.next(E),this._disposeScrollTimers(),this._updateInputPosition(!0)}))}removeAllRanges(){this._removeAllRanges(),this.deactivate()}getActiveTextRange(){return this._getActiveRangeInstance()}_disposeScrollTimers(){this._scrollTimers.forEach(e=>{e==null||e.dispose()}),this._scrollTimers=[]}_setSystemHighlightColorToStyle(){const{r:e,g:n,b:r,a:s}=B.getSystemHighlightColor(),a={strokeWidth:1,stroke:"rgba(0, 0, 0, 0)",strokeActive:"rgba(0, 0, 0, 1)",fill:`rgba(${e}, ${n}, ${r}, ${s!=null?s:.3})`};this._setRangeStyle(a)}_getAllTextRanges(){return this._rangeList.map(Yn)}_getAllRectRanges(){return this._rectRangeList.map(fa)}getAllTextRanges(){return this._getAllTextRanges()}getAllRectRanges(){return this._getAllRectRanges()}_getActiveRange(){const e=this._rangeList.find(s=>s.isActive());if(e==null)return null;const{startOffset:n,endOffset:r}=e;return n==null||r==null?null:Yn(e)}_getActiveRangeInstance(){return this._rangeList.find(e=>e.isActive())}dispose(){super.dispose(),this._detachEvent(),this._removeAllRanges(),this._container.remove()}_initDOM(){const{unitId:e}=this._context,n=document.createElement("div");n.style.position="fixed",n.style.left="0px",n.style.top="0px",n.id=`univer-doc-selection-container-${e}`;const r=document.createElement("div"),s=document.createElement("div");r.appendChild(s),n.appendChild(r),this._container=n,this._inputParent=r,this._input=s,this._initInput(),this._initInputEvents(),document.body.appendChild(n)}_registerContainer(){this.disposeWithMe(this._layoutService.registerContainerElement(this._container))}_initInput(){this._inputParent.style.cssText=`
|
|
14
14
|
position:absolute;
|
|
15
15
|
height:1px;
|
|
16
16
|
width:1px;
|
package/lib/es/index.js
CHANGED
|
@@ -4588,7 +4588,7 @@ class Zt {
|
|
|
4588
4588
|
let A = i + t;
|
|
4589
4589
|
const h = a + o, u = ((f = r == null ? void 0 : r.ts) == null ? void 0 : f.it) === z.TRUE;
|
|
4590
4590
|
if (u && (A += c * Math.tan(l * Math.PI / 180) / 2), this._anchorShape) {
|
|
4591
|
-
this._anchorShape.transformByState({ left: A, top: h, height: c }), this._anchorShape.show(), u ? this._anchorShape.skew(-
|
|
4591
|
+
this._anchorShape.transformByState({ left: A, top: h, height: c }), this._anchorShape.show(), u ? this._anchorShape.skew(-l, 0) : this._anchorShape.skew(0, 0);
|
|
4592
4592
|
return;
|
|
4593
4593
|
}
|
|
4594
4594
|
const g = new qn(iA + ge(pi), {
|
|
@@ -4599,7 +4599,7 @@ class Zt {
|
|
|
4599
4599
|
stroke: ((m = this.style) == null ? void 0 : m.strokeActive) || pn(fn.black, 1),
|
|
4600
4600
|
evented: !1
|
|
4601
4601
|
});
|
|
4602
|
-
u && g.skew(-
|
|
4602
|
+
u && g.skew(-l, 0), this._anchorShape = g, this._scene.addObject(g, pr), this.activeStatic();
|
|
4603
4603
|
}
|
|
4604
4604
|
_setCursorList(e) {
|
|
4605
4605
|
e.length !== 0 && (this._cursorList = e);
|
package/lib/index.js
CHANGED
|
@@ -4588,7 +4588,7 @@ class Zt {
|
|
|
4588
4588
|
let A = i + t;
|
|
4589
4589
|
const h = a + o, u = ((f = r == null ? void 0 : r.ts) == null ? void 0 : f.it) === z.TRUE;
|
|
4590
4590
|
if (u && (A += c * Math.tan(l * Math.PI / 180) / 2), this._anchorShape) {
|
|
4591
|
-
this._anchorShape.transformByState({ left: A, top: h, height: c }), this._anchorShape.show(), u ? this._anchorShape.skew(-
|
|
4591
|
+
this._anchorShape.transformByState({ left: A, top: h, height: c }), this._anchorShape.show(), u ? this._anchorShape.skew(-l, 0) : this._anchorShape.skew(0, 0);
|
|
4592
4592
|
return;
|
|
4593
4593
|
}
|
|
4594
4594
|
const g = new qn(iA + ge(pi), {
|
|
@@ -4599,7 +4599,7 @@ class Zt {
|
|
|
4599
4599
|
stroke: ((m = this.style) == null ? void 0 : m.strokeActive) || pn(fn.black, 1),
|
|
4600
4600
|
evented: !1
|
|
4601
4601
|
});
|
|
4602
|
-
u && g.skew(-
|
|
4602
|
+
u && g.skew(-l, 0), this._anchorShape = g, this._scene.addObject(g, pr), this.activeStatic();
|
|
4603
4603
|
}
|
|
4604
4604
|
_setCursorList(e) {
|
|
4605
4605
|
e.length !== 0 && (this._cursorList = e);
|
package/lib/umd/index.js
CHANGED
|
@@ -10,7 +10,7 @@ ${a.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
|
|
|
10
10
|
`," ");let s=this._umdToHtml.convert(t);if(t.length===1&&e){s=s.replace(/(<[a-z]+)/,(m,h)=>`${h} data-copy-id="${n}"`);const d=t[0],u={body:d.body};if((l=(c=d.body)==null?void 0:c.customBlocks)!=null&&l.length){u.drawings={};for(const m of d.body.customBlocks){const{blockId:h}=m,g=(A=d.drawings)==null?void 0:A[h];if(g){const p=a.generateRandomId(6);m.blockId=p,u.drawings[p]={...a.Tools.deepClone(g),drawingId:p}}}}Wn.set(n,u)}return this._clipboardInterfaceService.write(i,s)}addClipboardHook(t){return this._clipboardHooks.push(t),a.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t,e){var d;const n=this._univerInstanceService.getCurrentUniverDocInstance(),i=e!=null?e:this._docSelectionManagerService.getDocRanges(),s=[];let r=!0;if(n==null||i.length===0)return;const c=i[0].segmentId,l=(d=n==null?void 0:n.getSelfOrHeaderFooterModel(c))==null?void 0:d.getBody(),A=n.getSnapshot();if(l!=null){for(const u of i){const{startOffset:m,endOffset:h,collapsed:g,rangeType:p}=u;if(g||m==null||h==null)continue;if(p===a.DOC_RANGE_TYPE.RECT){r=!1;const{spanEntireRow:E}=u;let C;C=Ri(l,m,h),s.push(C);continue}const f={startOffset:m,endOffset:h},S=n.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,t);S!=null&&s.push(S)}return{newSnapshotList:s.map(u=>({...A,body:u})),needCache:r,snapshot:A,ranges:i}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const i=[];for(const s of t)for(const r of s.types)switch(r){case I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await s.getType(r).then(c=>c&&c.text());break}case I.HTML_CLIPBOARD_MIME_TYPE:{e=await s.getType(r).then(c=>c&&c.text());break}case I.FILE__BMP_CLIPBOARD_MIME_TYPE:case I.FILE__JPEG_CLIPBOARD_MIME_TYPE:case I.FILE__WEBP_CLIPBOARD_MIME_TYPE:case I.FILE_PNG_CLIPBOARD_MIME_TYPE:{const c=await s.getType(r),l=new File([c],`pasted_image.${r.split("/")[1]}`,{type:r});i.push(l);break}}return!e&&!n&&i.length&&(e=await this._createImagePasteHtml(i)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:a.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const i=Gs(t);if(i){const r=Wn.get(i);if(r)return r}if(!n){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);n=(r==null?void 0:r.getUnitId())||""}const s=this._htmlToUDM.convert(t,{unitId:n});return i&&Wn.set(i,s),s}async _createImagePasteHtml(t){var c,l;const e={id:"",documentStyle:{},body:{dataStream:"",customBlocks:[]},drawings:{}},n=async A=>{const d=new FileReader;return new Promise(u=>{d.onloadend=function(){u({source:d.result,imageSourceType:xn.ImageSourceType.BASE64})},d.readAsDataURL(A)})},i=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const h=Math.min(u,d.naturalWidth),g=d.naturalHeight/d.naturalWidth;m({width:h,height:h*g})}})},s=(l=(c=this._clipboardHooks.find(A=>A.onBeforePasteImage))==null?void 0:c.onBeforePasteImage)!=null?l:n;return await Promise.all(t.map(async(A,d)=>{var S;const u=await s(A);if(!u)return Promise.resolve();const{width:m=100,height:h=100}=await i(A),g=`paste_image_id_${d}`,p=e.body,f=e.drawings;p.dataStream+="\b",(S=p.customBlocks)==null||S.push({startIndex:d,blockId:g}),f[g]={drawingId:g,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:a.PositionedObjectLayoutType.INLINE,drawingType:a.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:h,angle:0},docTransform:{angle:0,size:{width:m,height:h},positionH:{relativeFrom:a.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:a.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};Xn=Js([mt(0,a.IUniverInstanceService),mt(1,a.ILogService),mt(2,a.ICommandService),mt(3,I.IClipboardInterfaceService),mt(4,a.Inject(D.DocSelectionManagerService))],Xn);function Kt(o){return o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED)}const Kn=999,pt={id:I.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:Kn,preconditions:Kt,handler:async o=>o.get(Me).copy()},zn={id:"doc.command.copy-current-paragraph",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(Me),e=ht(o);return e?t.copy(a.SliceBodyType.copy,[{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1}]):!1}},zt={id:I.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:Kn,preconditions:Kt,handler:async o=>o.get(Me).cut()},Yn={id:"doc.command.cut-current-paragraph",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(Me),e=ht(o);return e?t.cut([{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1,rangeType:a.DOC_RANGE_TYPE.TEXT}]):!1}},Yt={id:I.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:Kn,preconditions:Kt,handler:async o=>{const t=o.get(Me),n=await o.get(I.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}},ft={id:"doc.command.horizontal-line",type:a.CommandType.COMMAND,handler:(o,t)=>o.get(a.ICommandService).syncExecuteCommand(Ft.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:a.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},qn={id:"doc.command.insert-horizontal-line-bellow",type:a.CommandType.COMMAND,handler:o=>{const t=o.get(a.ICommandService),e=ht(o);return e?t.syncExecuteCommand(ft.id,{insertRange:{startOffset:e.startIndex+1,endOffset:e.startIndex+1}}):!1}},Jn={id:"doc.command.select-all",type:a.CommandType.COMMAND,handler:async o=>{var h;const t=o.get(a.IUniverInstanceService),e=o.get(D.DocSelectionManagerService),n=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),i=e.getDocRanges(),s=(h=i.find(g=>g.isActive))!=null?h:i[0];if(n==null||s==null)return!1;const{segmentId:r}=s,c=n.getUnitId(),l=n.getSelfOrHeaderFooterModel(r).getSnapshot().body;if(l==null)return!1;const{tables:A=[],dataStream:d}=l;if(d===`\r
|
|
11
11
|
`)return!0;const u=[];let m=0;for(const g of A){const{startIndex:p,endIndex:f}=g;m!==p&&u.push({startOffset:m,endOffset:p-1,rangeType:a.DOC_RANGE_TYPE.TEXT}),u.push({startOffset:p+3,endOffset:f-5,rangeType:a.DOC_RANGE_TYPE.RECT}),m=f}return m!==l.dataStream.length-2&&u.push({startOffset:m,endOffset:l.dataStream.length-2,rangeType:a.DOC_RANGE_TYPE.TEXT}),e.replaceDocRanges(u,{unitId:c,subUnitId:c},!1),!0}};class St extends a.RxDisposable{constructor(e){super();B(this,"_previousActiveRange",null);B(this,"_undoMutationParamsCache",[]);B(this,"_redoMutationParamsCache",[]);this._context=e}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:e=[],redoCache:n=[]}){this._undoMutationParamsCache=e,this._redoMutationParamsCache=n}getActiveRange(){return this._previousActiveRange}setActiveRange(e){this._previousActiveRange=e}pushUndoRedoMutationParams(e,n){this._undoMutationParamsCache.push(e),this._redoMutationParamsCache.push(n)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:e}=this._undoMutationParamsCache[0],n={unitId:e,actions:this._undoMutationParamsCache.reverse().reduce((s,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]};return{redoMutationParams:{unitId:e,actions:this._redoMutationParamsCache.reduce((s,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]},undoMutationParams:n,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Zn={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(o,t)=>{var Q,X,j;const{unitId:e,newText:n,oldTextLen:i,isCompositionEnd:s,isCompositionStart:r}=t,c=o.get(a.ICommandService),l=o.get(_.IRenderManagerService),A=o.get(a.IUniverInstanceService),d=o.get(ve),u=(Q=l.getRenderById(e))==null?void 0:Q.with(St),m=A.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(m==null||u==null)return!1;const h=u.getActiveRange();if(h==null)return!1;const{style:g,segmentId:p}=h,f=m.getSelfOrHeaderFooterModel(p).getBody();if(f==null)return!1;Object.assign(h,h);const{startOffset:E,endOffset:C}=h,T=n.length,R=[{startOffset:E+T,endOffset:E+T,collapsed:!0,style:g}],v={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:R}},O=d.getDefaultStyle(),M=d.getStyleCache(),b=Bn((X=f.customRanges)!=null?X:[],E+i,a.SHEET_EDITOR_UNITS.includes(e)),N=Lt(f,r?C:E+i,O,M,a.SHEET_EDITOR_UNITS.includes(e)),x=_n((j=f.customDecorations)!=null?j:[],E+i),U=new a.TextX,F=a.JSONX.getInstance();if(!h.collapsed&&r){const k=a.BuildTextUtils.selection.delete([h],f,0,null,!1);U.push(...k),v.params.textRanges=[{startOffset:E+T,endOffset:E+T,collapsed:!0}]}else U.push({t:a.TextXActionType.RETAIN,len:E});i>0&&U.push({t:a.TextXActionType.DELETE,len:i}),U.push({t:a.TextXActionType.INSERT,body:{dataStream:n,textRuns:N?[{...N,st:0,ed:n.length}]:[],customRanges:b?[{...b,startIndex:0,endIndex:n.length-1}]:[],customDecorations:x.map(k=>({...k,startIndex:0,endIndex:n.length-1}))},len:n.length});const V=Z(m,p);v.params.actions=F.editOp(U.serialize(),V),v.params.noHistory=!s,v.params.isCompositionEnd=s;const H=c.syncExecuteCommand(v.id,v.params);return u.pushUndoRedoMutationParams(H,v.params),!!H}};function ue(o,t,e){return e.executeCommand(Ce.id,{preCommandId:o,...t!=null?t:{}})}const Mi="doc.command.set-inline-format-bold",xe={id:Mi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Mi,t,e)}},xi="doc.command.set-inline-format-italic",De={id:xi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(xi,t,e)}},Di="doc.command.set-inline-format-underline",Be={id:Di,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Di,t,e)}},Bi="doc.command.set-inline-format-strikethrough",_e={id:Bi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Bi,t,e)}},_i="doc.command.set-inline-format-subscript",Ee={id:_i,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(_i,t,e)}},Ni="doc.command.set-inline-format-superscript",Ne={id:Ni,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ni,t,e)}},Pi="doc.command.set-inline-format-fontsize",ge={id:Pi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Pi,t,e)}},wi="doc.command.set-inline-format-font-family",Ve={id:wi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(wi,t,e)}},Ui="doc.command.set-inline-format-text-color",Pe={id:Ui,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ui,t,e)}},Li="doc.command.set-inline-format-text-background-color",we={id:Li,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Li,t,e)}},Qi="doc.command.reset-inline-format-text-background-color",$e={id:Qi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Qi,t,e)}},$n={[xe.id]:"bl",[De.id]:"it",[Be.id]:"ul",[_e.id]:"st",[ge.id]:"fs",[Ve.id]:"ff",[Pe.id]:"cl",[we.id]:"bg",[$e.id]:"bg",[Ee.id]:"va",[Ne.id]:"va"},Ce={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(o,t)=>{var R;const{value:e,preCommandId:n}=t,i=o.get(a.ICommandService),s=o.get(D.DocSelectionManagerService),r=o.get(a.IUniverInstanceService),c=o.get(ve),l=s.getDocRanges(),A=(R=l.find(v=>v.isActive))!=null?R:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const h=u.getUnitId();let g;switch(n){case xe.id:case De.id:case Be.id:case _e.id:case Ee.id:case Ne.id:{const v=c.getDefaultStyle(),O=Hi(m,A,v);g=$s(O,n);break}case ge.id:case Ve.id:{g=e;break}case Pe.id:case we.id:{g={rgb:e};break}case $e.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:l}},f=new a.TextX,S=a.JSONX.getInstance(),E=new a.MemoryCursor;E.reset();for(const v of l){let{startOffset:O,endOffset:M,rangeType:b}=v;if(O==null||M==null)continue;if(b===a.DOC_RANGE_TYPE.RECT&&(O=O-1),O===M){const U=c.getStyleCache(),F=$n[n];c.setStyleCache({[F]:(U==null?void 0:U[F])!==void 0?Fi(U,F,n):g});continue}const N={dataStream:"",textRuns:[{st:0,ed:M-O,ts:{[$n[n]]:g}}]},x=O-E.cursor;x!==0&&f.push({t:a.TextXActionType.RETAIN,len:x}),f.push({t:a.TextXActionType.RETAIN,body:N,len:M-O}),E.reset(),E.moveCursor(M)}const C=Z(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}};function Zs(o){return o!==null&&typeof o=="object"}function Fi(o,t,e){if(/bl|it/.test(t))return(o==null?void 0:o[t])===a.BooleanNumber.TRUE?a.BooleanNumber.FALSE:a.BooleanNumber.TRUE;if(/ul|st/.test(t))return Zs(o==null?void 0:o[t])&&(o==null?void 0:o[t]).s===a.BooleanNumber.TRUE?{s:a.BooleanNumber.FALSE}:{s:a.BooleanNumber.TRUE};if(/va/.test(t))return e===Ee.id?(o==null?void 0:o[t])===a.BaselineOffset.SUBSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUBSCRIPT:(o==null?void 0:o[t])===a.BaselineOffset.SUPERSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUPERSCRIPT}function Hi(o,t,e){var d,u,m,h,g,p,f,S,E,C,T,R,v,O;const{startOffset:n,endOffset:i,collapsed:s}=t;if(s){const M=(d=o.textRuns)!=null?d:[];let b=null;for(let N=M.length-1;N>=0;N--){const x=M[N];if(x.st<n&&n<=x.ed){b=x;break}}return b!=null&&b.ts?{...e,...b.ts}:e}const{textRuns:r=[]}=a.getBodySlice(o,n,i),c=a.Tools.deepClone(e),l=r.map(M=>{var b;return(b=M==null?void 0:M.ts)==null?void 0:b.fs}).filter(Boolean);c.fs=c.fs?Math.max(c.fs,...l):l.length?Math.max(...l):void 0,c.fs=!c.fs||Number.isNaN(c.fs)?void 0:c.fs,c.ff=(h=(m=(u=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?h:c.ff,c.it=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.it)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.bl=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.bl)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.ul=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.ul)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(g=r[0].ts)==null?void 0:g.ul:c.ul,c.st=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.st)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(p=r[0].ts)==null?void 0:p.st:c.st,c.bg=(E=(S=(f=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(T=(C=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.cl)!=null}))==null?void 0:C.ts)==null?void 0:T.cl)!=null?R:c.cl;const A=r.filter(M=>{var b;return((b=M==null?void 0:M.ts)==null?void 0:b.va)!=null});if(A.length>0&&A.length===r.length){const M=(v=A[0].ts)==null?void 0:v.va;let b=!0;for(let N=1;N<A.length;N++)if(((O=A[N].ts)==null?void 0:O.va)!==M){b=!1;break}b&&(c.va=M)}return c}function $s(o,t){const e=$n[t];return Fi(o,e,t)}const eo={id:"doc.command-replace-snapshot",type:a.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,snapshot:n,textRanges:i,segmentId:s="",options:r}=t,c=o.get(a.IUniverInstanceService),l=o.get(a.ICommandService),A=o.get(D.DocSelectionManagerService),d=c.getUnit(e,a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot();if(d==null||u==null)return!1;const{body:m,tableSource:h,footers:g,headers:p,lists:f,drawings:S,drawingsOrder:E,documentStyle:C}=a.Tools.deepClone(n),{body:T,tableSource:R,footers:v,headers:O,lists:M,drawings:b,drawingsOrder:N,documentStyle:x}=u;if(m==null||T==null)return!1;if(a.Tools.diffValue(m,T)&&i)return A.replaceDocRanges(i,{unitId:e,subUnitId:e},!1),!0;const U={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:i}};r&&(U.params.options=r);const F=[],V=a.JSONX.getInstance();if(!a.Tools.diffValue(x,C)){const Q=V.replaceOp(["documentStyle"],x,C);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(m,T)){const Q=V.replaceOp(["body"],T,m);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(h,R)){const Q=V.replaceOp(["tableSource"],R,h);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(g,v)){const Q=V.replaceOp(["footers"],v,g);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(p,O)){const Q=V.replaceOp(["headers"],O,p);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(f,M)){const Q=V.replaceOp(["lists"],M,f);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(S,b)){const Q=V.replaceOp(["drawings"],b,S);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(E,N)){const Q=V.replaceOp(["drawingsOrder"],N,E);Q!=null&&F.push(Q)}return U.params.actions=F.reduce((Q,X)=>a.JSONX.compose(Q,X),null),!!l.syncExecuteCommand(U.id,U.params)}},ki={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(o,t)=>{const{unitId:e,body:n,textRanges:i,segmentId:s="",options:r}=t,c=o.get(a.IUniverInstanceService),l=o.get(a.ICommandService),A=o.get(D.DocSelectionManagerService),d=c.getUnit(e,a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot().body;if(d==null||u==null)return!1;const m=Wi(e,s,d,u,n);return m.params.textRanges=i,r&&(m.params.options=r),m.params.actions==null&&i?(A.replaceDocRanges(i,{unitId:e,subUnitId:e},!1),!0):!!l.syncExecuteCommand(m.id,m.params)}},Vi={id:"doc.command-cover-content",type:a.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,body:n,segmentId:i="",textRanges:s}=t,r=o.get(a.IUniverInstanceService),c=o.get(a.ICommandService),l=o.get(a.IUndoRedoService),A=r.getUniverDocInstance(e),d=A==null?void 0:A.getSnapshot().body;if(A==null||d==null)return!1;const u=Wi(e,i,A,d,n);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,u.params.textRanges=s,c.syncExecuteCommand(u.id,u.params),l.clearUndoRedo(e),!0}};function er(o,t,e,n){const i=new a.TextX,s=a.JSONX.getInstance(),r=(e==null?void 0:e.dataStream.length)-2;r>0&&i.push({t:a.TextXActionType.DELETE,len:r}),n.dataStream.length>0&&i.push({t:a.TextXActionType.INSERT,body:n,len:n.dataStream.length});const c=Z(t,o);return s.editOp(i.serialize(),c)}function Wi(o,t,e,n,i){const s={id:D.RichTextEditingMutation.id,params:{unitId:o,actions:[],textRanges:[]}},r=er(t,e,n,i);return s.params.actions=r,s}const to={id:"doc.command.replace-selection",type:a.CommandType.COMMAND,handler(o,t){var g;if(!t)return!1;const e=o.get(a.ICommandService),{unitId:n,body:i,textRanges:s}=t,c=o.get(a.IUniverInstanceService).getUnit(n),l=o.get(D.DocSelectionManagerService);if(!c)return!1;const A=c.getBody(),d=(g=t.selection)!=null?g:l.getActiveTextRange();if(!d||!A)return!1;const u={id:D.RichTextEditingMutation.id,params:{unitId:n,actions:[],textRanges:s,debounce:!0}},m=new a.TextX,h=a.JSONX.getInstance();return m.push(...a.BuildTextUtils.selection.delete([d],A,0,i)),u.params.actions=h.editOp(m.serialize()),e.syncExecuteCommand(u.id,u.params)}},Gi={id:"doc.command.replace-text-runs",type:a.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,body:n,textRanges:i,segmentId:s="",options:r}=t,c=o.get(a.IUniverInstanceService),l=o.get(a.ICommandService),A=o.get(a.ThemeService),d=c.getUnit(e,a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot().body;if(d==null||u==null)return!1;const m=a.BuildTextUtils.selection.replaceTextRuns({doc:d,body:n,selection:{startOffset:0,endOffset:u.dataStream.length-2,collapsed:!1},themeService:A});if(!m)return!1;const h={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:i,noHistory:!0}},g=a.JSONX.getInstance(),p=Z(d,s);return h.params.actions=g.editOp(m.serialize(),p),h.params.textRanges=i,r&&(h.params.options=r),!!l.syncExecuteCommand(h.id,h.params)}},ji={id:"doc.command.insert-custom-range",type:a.CommandType.COMMAND,handler:(o,t)=>{if(!t)return!1;const e=o.get(a.ICommandService),{unitId:n,rangeId:i=a.generateRandomId(),textRanges:s,properties:r,text:c,wholeEntity:l}=t,A={unitId:n,textRanges:s,body:{dataStream:c,customRanges:[{startIndex:0,endIndex:c.length-1,rangeId:i,rangeType:a.CustomRangeType.CUSTOM,properties:r,wholeEntity:l}]}};return e.syncExecuteCommand(to.id,A)}},et={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M,b;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=t.listType,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(R=(T=t.docRange)!=null?T:e.getDocRanges())!=null?R:[];if(r==null||c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(O=(v=A.getBody())==null?void 0:v.paragraphs)!=null?O:[],u=(b=(M=A.getBody())==null?void 0:M.dataStream)!=null?b:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}};new a.MemoryCursor().reset();const f=a.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:s,document:r,segmentId:l}),S=a.JSONX.getInstance(),E=Z(r,l);return g.params.actions=S.editOp(f.serialize(),E),!!i.syncExecuteCommand(g.id,g.params)}},It={id:"doc.command.change-list-type",type:a.CommandType.COMMAND,handler:(o,t)=>{var C,T,R,v,O;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{listType:s}=t,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(r==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=r.getSelfOrHeaderFooterModel(l),d=(R=(T=A.getBody())==null?void 0:T.paragraphs)!=null?R:[],u=(O=(v=A.getBody())==null?void 0:v.dataStream)!=null?O:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=a.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:s,segmentId:l,document:r});if(!g)return!1;const p=a.JSONX.getInstance(),f={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}},S=Z(r,l);return f.params.actions=p.editOp(g.serialize(),S),!!i.syncExecuteCommand(f.id,f.params)}};var vt=(o=>(o[o.increase=1]="increase",o[o.decrease=-1]="decrease",o))(vt||{});const qt={id:"doc.command.change-list-nesting-level",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M;if(!t)return!1;const{type:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null)return!1;const{segmentId:l}=c,A=(T=n.getDocRanges())!=null?T:[],d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"";if(!u.length)return!1;const h=a.BuildTextUtils.range.getParagraphsInRange(c,u,m),g=r.getUnitId(),p=a.JSONX.getInstance(),f=a.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:h,type:e,segmentId:l,document:r}),S={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:A,isEditing:!1}},E=Z(r,l);return S.params.actions=p.editOp(f.serialize(),E),!!s.syncExecuteCommand(S.id,S.params)}},tt={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(et.id,{listType:a.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Et={id:"doc.command.check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(et.id,{listType:a.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},no={id:"doc.command.toggle-check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{var p;if(!t)return!1;const e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),{index:i,segmentId:s,textRanges:r}=t,c=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(c==null||((p=c.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:p.paragraphs)==null)return!1;const A=c.getUnitId(),d={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:r!=null?r:[],segmentId:s,isEditing:!1}},u=a.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:i,segmentId:s});if(!u)return!1;const m=a.JSONX.getInstance(),h=Z(c,s);return d.params.actions=m.editOp(u.serialize(),h),!!n.syncExecuteCommand(d.id,d.params)}},nt={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value}):e.syncExecuteCommand(et.id,{listType:a.PresetListType.ORDER_LIST})}},oo={id:"doc.command.quick-list",type:a.CommandType.COMMAND,handler(o,t){var x,U,F;if(!t)return!1;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=e.getActiveTextRange();if(s==null||r==null)return!1;const{segmentId:c,startOffset:l}=r,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,h=new a.TextX,g=a.JSONX.getInstance(),{paragraphStyle:p={}}=d,S=(a.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{}).textStyle;let C=a.generateRandomId(6);const T=(U=(x=s.getBody())==null?void 0:x.paragraphs)!=null?U:[],R=T.findIndex(V=>V.startIndex===d.startIndex),v=T[R-1],O=T[R+1];v&&v.bullet&&v.bullet.listType.indexOf(A)===0?C=v.bullet.listId:O&&O.bullet&&O.bullet.listType.indexOf(A)===0&&(C=O.bullet.listId);const M={id:D.RichTextEditingMutation.id,params:{unitId:s.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};h.push({t:a.TextXActionType.RETAIN,len:u}),h.push({t:a.TextXActionType.DELETE,len:l-u}),m>l&&h.push({t:a.TextXActionType.RETAIN,len:m-l}),h.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...p,textStyle:{...p.textStyle,...S},indentFirstLine:void 0},bullet:{...(F=d.bullet)!=null?F:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:C}}]}});const b=Z(s,c);return M.params.actions=g.editOp(h.serialize(),b),!!i.syncExecuteCommand(M.id,M.params)}};function io(o,t){var d,u;const e=o.get(a.ICommandService),n=ht(o);if(!n)return!1;const i=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!i)return!1;const s=a.BuildTextUtils.selection.replace({doc:i,selection:{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0},body:{dataStream:"\r",paragraphs:[{startIndex:0,paragraphStyle:{...n.paragraphStyle},bullet:{listType:t,listId:((d=n.bullet)==null?void 0:d.listType)===t?n.bullet.listId:a.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!s)return!1;const r={id:D.RichTextEditingMutation.id,params:{unitId:i.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=a.JSONX.getInstance(),l=Z(i);return r.params.actions=c.editOp(s.serialize(),l),!!e.syncExecuteCommand(r.id,r.params)}const ao={id:"doc.command.insert-bullet-list-bellow",type:a.CommandType.COMMAND,handler:o=>io(o,a.PresetListType.BULLET_LIST)},so={id:"doc.command.insert-order-list-bellow",type:a.CommandType.COMMAND,handler:o=>io(o,a.PresetListType.ORDER_LIST)},ro={id:"doc.command.insert-check-list-bellow",type:a.CommandType.COMMAND,handler:o=>io(o,a.PresetListType.CHECK_LIST)},me={id:"doc.command.align-action",type:a.CommandType.COMMAND,handler:(o,t)=>{var R,v,O,M;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{alignType:s}=t,r=n.getCurrentUniverDocInstance();if(r==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(v=(R=A.getBody())==null?void 0:R.paragraphs)!=null?v:[],u=(M=(O=A.getBody())==null?void 0:O.dataStream)!=null?M:"";if(d==null)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=m.every(b=>{var N;return((N=b.paragraphStyle)==null?void 0:N.horizontalAlign)===s}),p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c}},f=new a.MemoryCursor;f.reset();const S=new a.TextX,E=a.JSONX.getInstance();for(const b of m){const{startIndex:N}=b;S.push({t:a.TextXActionType.RETAIN,len:N-f.cursor});const x={...b.paragraphStyle,horizontalAlign:g?a.HorizontalAlign.UNSPECIFIED:s};S.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...b,paragraphStyle:x,startIndex:0}]},coverType:a.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(N+1)}const C=Z(r,l);return p.params.actions=E.editOp(S.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}},Ct={id:"doc.command.align-left",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.LEFT})},Tt={id:"doc.command.align-center",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.CENTER})},yt={id:"doc.command.align-right",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.RIGHT})},bt={id:"doc.command.align-justify",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.JUSTIFIED})},tr=(o,t)=>{const n=o.get(a.IUniverInstanceService).getUnit(t.unitId,a.UniverInstanceType.UNIVER_DOC);return n==null||n.setZoomRatio(t.zoomRatio),{...t}},he={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(o,t)=>{const n=o.get(a.IUniverInstanceService).getUnit(t.unitId,a.UniverInstanceType.UNIVER_DOC);return n?(n.setZoomRatio(t.zoomRatio),!0):!1}},Ot={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,t)=>{var u,m,h;const e=o.get(a.ICommandService),n=o.get(a.IUndoRedoService),i=o.get(a.IUniverInstanceService);let s=(u=i.getCurrentUniverDocInstance())==null?void 0:u.getUnitId();if(!s)return!1;let r=1;if(t&&(s=(m=t.documentId)!=null?m:s,r=(h=t.zoomRatio)!=null?h:r),!i.getUniverDocInstance(s))return!1;const l={zoomRatio:r,unitId:s},A=tr(o,l);return e.syncExecuteCommand(he.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:he.id,params:A}],redoMutations:[{id:he.id,params:l}]}),!0):!1}},ce={id:"doc.command.set-paragraph-named-style",type:a.CommandType.COMMAND,handler(o,t){var g;if(!t)return!1;const n=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const i=n.getUnitId(),s=o.get(D.DocSelectionManagerService),r=(g=t.textRanges)!=null?g:s.getTextRanges({unitId:i,subUnitId:i});if(!(r!=null&&r.length))return!1;const c=r[0].segmentId,l=a.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:r,style:{namedStyleType:t.value,headingId:!t.value||t.value===a.NamedStyleType.NORMAL_TEXT?void 0:a.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0,lineSpacing:void 0},paragraphTextRun:{}}),A={id:D.RichTextEditingMutation.id,params:{actions:[],textRanges:r,unitId:i,segmentId:c}},d=a.JSONX.getInstance(),u=Z(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!o.get(a.ICommandService).syncExecuteCommand(A.id,A.params)}},Xi={id:"doc.command.quick-heading",type:a.CommandType.COMMAND,handler(o,t){var R,v,O,M;if(!t)return!1;const{value:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"",h=a.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!h)return!1;const{paragraphStart:g}=h,p=new a.TextX,f=a.JSONX.getInstance(),{paragraphStyle:S={}}=h,E={id:D.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:g,endOffset:g,collapsed:!0}],isEditing:!1}};p.push({t:a.TextXActionType.RETAIN,len:g}),a.BuildTextUtils.paragraph.style.set({textRanges:[c],document:r,style:{...S,headingId:a.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-g,textX:p,paragraphTextRun:{}});const C=Z(r,l);return E.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(E.id,E.params)}},co={"#":a.NamedStyleType.HEADING_1,"##":a.NamedStyleType.HEADING_2,"###":a.NamedStyleType.HEADING_3,"####":a.NamedStyleType.HEADING_4,"#####":a.NamedStyleType.HEADING_5},lo={id:"doc.command.h1-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_1})},Ao={id:"doc.command.h2-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_2})},uo={id:"doc.command.h3-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_3})},ho={id:"doc.command.h4-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_4})},go={id:"doc.command.h5-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_5})},Jt={id:"doc.command.normal-text-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.NORMAL_TEXT})},Ki={id:"doc.command.title",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.TITLE})},zi={id:"doc.command.subtitle-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.SUBTITLE})};var Zt=(o=>(o[o.page=0]="page",o[o.section=1]="section",o[o.column=2]="column",o[o.line=3]="line",o[o.divide=4]="divide",o[o.glyph=5]="glyph",o))(Zt||{});const ot={page:0,section:1,column:2,line:3,divide:4,glyph:5};function mo(o,t){return o.page>t.page?!1:o.page<t.page?!0:o.section>t.section?!1:o.section<t.section?!0:o.column>t.column?!1:o.column<t.column?!0:o.line>t.line?!1:o.line<t.line?!0:o.divide>t.divide?!1:o.divide<t.divide?!0:o.glyph>t.glyph?!1:(o.glyph<t.glyph,!0)}function po(o,t){return mo(o,t)?{start:o,end:t}:{start:t,end:o}}function fo(o){const t=o.length;if(t===0)return;const e=o[0],n=o[t-1],i=o.length===1&&e.collapsed;return{startOffset:e.startOffset,endOffset:n.endOffset,collapsed:i}}function nr(o,t,e,n){let i=n,s=n;for(let r=0;r<o.length;r++){const l=o[r].count;r<t&&(i+=l),r<e&&(s+=l)}return{startOffset:i,endOffset:s}}function So(o){const{startX:t,startY:e,endX:n,endY:i}=o,s=[];return s.push({x:t,y:e}),s.push({x:n,y:e}),s.push({x:n,y:i}),s.push({x:t,y:i}),s.push({x:t,y:e}),s}class Te{constructor(t,e){B(this,"_liquid",new _.Liquid);B(this,"_currentStartState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});B(this,"_currentEndState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],i=[],s=[];if(t==null||e==null)return{borderBoxPointGroup:n,contentBoxPointGroup:i,cursorList:s};if(!this._isValidPosition(t,e))throw new Error(`
|
|
12
12
|
Invalid positions in NodePositionConvertToCursor,
|
|
13
|
-
they are not in the same segment page when in header or footer.`);const{start:c,end:l}=po(t,e);return this._selectionIterator(c,l,(A,d,u,m,h,g)=>{const{lineHeight:p,asc:f,paddingTop:S,marginTop:E,marginBottom:C}=g,{glyphGroup:T,st:R}=h;if(T.length===0)return;const{x:v,y:O}=this._liquid;let M,b;const N=T[A],x=T[d],U=T[A-1],F=(N==null?void 0:N.left)||0,V=(N==null?void 0:N.width)||0,H=(x==null?void 0:x.left)||0,Q=(x==null?void 0:x.width)||0,X=(N==null?void 0:N.glyphType)===_.GlyphType.LIST,{startOffset:j,endOffset:k}=nr(T,A,d,R),W=c.glyph===A&&u?c.isBack:!0,G=l.glyph===d&&m?l.isBack:!1,K=c===l,Y=W&&U!=null?U:N;if(A===0&&d===T.length-1)M={startX:v+F+(X?V:0),startY:O,endX:v+H+(G?0:Q),endY:O+p-E-C},b={startX:v+F+(X?V:0),startY:O+S+f-Y.bBox.ba,endX:v+H+(G?0:Q),endY:O+S+f+Y.bBox.bd};else{const q=W&&!X;M={startX:v+F+(q?0:V),startY:O,endX:v+H+(G?0:Q),endY:O+p-E-C},b={startX:v+F+(q?0:V),startY:O+S+f-Y.bBox.ba,endX:v+H+(G?0:Q),endY:O+S+f+Y.bBox.bd}}n.push(So(M)),i.push(So(b)),s.push({startOffset:W?j:j+N.count,endOffset:G?k:k+x.count,collapsed:K})}),{borderBoxPointGroup:n,contentBoxPointGroup:i,cursorList:s}}_isValidPosition(t,e){const{segmentPage:n,pageType:i}=t,{segmentPage:s,pageType:r}=e;return i!==r?!1:i===_.DocumentSkeletonPageType.HEADER||i===_.DocumentSkeletonPageType.FOOTER?n===s:!0}_resetCurrentNodePositionState(){this._currentStartState={page:0,section:0,column:0,line:0,divide:0,glyph:0},this._currentEndState={page:0,section:0,column:0,line:0,divide:0,glyph:0}}_setNodePositionState(t=0,e,n,i){i===e?this._currentStartState[t]=1:this._currentStartState[t]=0,i===n?this._currentEndState[t]=2:this._currentEndState[t]=0}_checkPreviousNodePositionState(t,e=!0){let n=t,i;for(;n>=0;){const s=Zt[n];let r;if(e?r=this._currentStartState[s]:r=this._currentEndState[s],r===void 0)return;if(i===void 0&&(i=r),r!==i)return 0;n--}return i}_getSelectionRuler(t,e,n,i,s){let r=0,c=i;const l=Zt[t],A=Zt[t+1];if(A===null||l===null)return{start_next:r,end_next:c};const d=e[l],u=n[l];this._setNodePositionState(l,d,u,s);const m=this._checkPreviousNodePositionState(t),h=this._checkPreviousNodePositionState(t,!1);return m===1&&(r=e[A]),h===2&&(c=n[A]),{start_next:r,end_next:c}}_selectionIterator(t,e,n){var T,R;const i=this._docSkeleton;if(!i)return[];const{pageType:s,path:r}=t;this._liquid.reset();const c=i.getSkeletonData();if(c==null)return[];const{pages:l,skeHeaders:A,skeFooters:d}=c,{page:u,segmentPage:m}=t,{page:h,segmentPage:g}=e;if(this._resetCurrentNodePositionState(),this._documentOffsetConfig==null)return[];const{pageLayoutType:p,pageMarginLeft:f,pageMarginTop:S}=this._documentOffsetConfig,E=s===_.DocumentSkeletonPageType.BODY||s===_.DocumentSkeletonPageType.CELL?u:m;for(let v=0;v<E;v++){const O=l[v];this._liquid.translatePage(O,p,f,S)}const C=s===_.DocumentSkeletonPageType.BODY||s===_.DocumentSkeletonPageType.CELL?h:g;for(let v=E;v<=C;v++){const O=l[v],{headerId:M,footerId:b,pageWidth:N}=O;let x=O;if(s===_.DocumentSkeletonPageType.HEADER?x=(T=A.get(M))==null?void 0:T.get(N):s===_.DocumentSkeletonPageType.FOOTER?x=(R=d.get(b))==null?void 0:R.get(N):s===_.DocumentSkeletonPageType.CELL&&(x=_.getPageFromPath(c,r)),x==null){this._liquid.translatePage(O,p,f,S);continue}const U=x.sections,{start_next:F,end_next:V}=this._getSelectionRuler(ot.page,t,e,U.length-1,s===_.DocumentSkeletonPageType.BODY||s===_.DocumentSkeletonPageType.CELL?v:0);switch(this._liquid.translateSave(),s){case _.DocumentSkeletonPageType.HEADER:this._liquid.translatePagePadding({...x,marginLeft:O.marginLeft});break;case _.DocumentSkeletonPageType.FOOTER:{const H=O.pageHeight-x.height-x.marginBottom;this._liquid.translate(O.marginLeft,H);break}case _.DocumentSkeletonPageType.CELL:{this._liquid.translatePagePadding(O);const H=x.parent,Q=H.parent,{left:X}=x,{top:j,left:k}=Q,{top:W}=H;this._liquid.translate(k+X,j+W),this._liquid.translatePagePadding(x);break}default:this._liquid.translatePagePadding(O);break}for(let H=F;H<=V;H++){const Q=U[H],X=Q.columns,{start_next:j,end_next:k}=this._getSelectionRuler(ot.section,t,e,X.length-1,H);this._liquid.translateSection(Q);for(let W=j;W<=k;W++){const G=X[W],K=G.lines,{start_next:Y,end_next:q}=this._getSelectionRuler(ot.column,t,e,K.length-1,W);this._liquid.translateColumn(G);for(let z=Y;z<=q;z++){const $=K[z],{divides:ie}=$,{start_next:fe,end_next:Fe}=this._getSelectionRuler(ot.line,t,e,ie.length-1,z);this._liquid.translateSave(),this._liquid.translateLine($,!0,!1);for(let Se=fe;Se<=Fe;Se++){const ni=ie[Se];this._liquid.translateSave(),this._liquid.translateDivide(ni);const{glyphGroup:RA}=ni,{start_next:MA,end_next:xA}=this._getSelectionRuler(ot.divide,t,e,RA.length-1,Se);let hs=!1,gs=!1;v===E&&H===F&&W===j&&z===Y&&Se===fe&&(hs=!0),v===C&&H===V&&W===k&&z===q&&Se===Fe&&(gs=!0),n&&n(MA,xA,hs,gs,ni,$,G,Q,x),this._liquid.translateRestore()}this._liquid.translateRestore()}}}this._liquid.translateRestore(),this._liquid.translatePage(O,p,f,S)}}}function Yi(o,t){const{path:e}=o,{path:n}=t;if(e.length!==n.length||e.indexOf("cells")===-1)return!1;const i=e.indexOf("skeTables")+1,s=e.indexOf("rows")+1,r=e.indexOf("cells")+1,{tableId:c,sliceIndex:l}=_.getTableIdAndSliceIndex(e[i]),{tableId:A,sliceIndex:d}=_.getTableIdAndSliceIndex(n[i]);if(c!==A)return!1;const u=e[s],m=n[s],h=e[r],g=n[r];return!(u===m&&h===g&&l===d)}function Io(o,t){const{path:e}=o,{path:n}=t;return e.indexOf("cells")===-1||n.indexOf("cells")===-1||e.length!==n.length?!1:a.Tools.diffValue(e,n)}function qi(o,t,e){var h,g,p,f,S,E,C,T;const{path:n}=t,{path:i}=e;if(n.indexOf("cells")===-1||i.indexOf("cells")===-1)return!1;const s=o.findGlyphByPosition(t),r=o.findGlyphByPosition(e),c=(f=(p=(g=(h=s==null?void 0:s.parent)==null?void 0:h.parent)==null?void 0:g.parent)==null?void 0:p.parent)==null?void 0:f.parent,l=(T=(C=(E=(S=r==null?void 0:r.parent)==null?void 0:S.parent)==null?void 0:E.parent)==null?void 0:C.parent)==null?void 0:T.parent;if(c==null||l==null)return!1;const A=c.parent,d=l.parent,u=A.cells.indexOf(c),m=d.cells.indexOf(l);return u===m&&A.index===d.index}function vo(o,t){if(Io(o,t))return mo(o,t);const{path:e}=o,{path:n}=t,i=e[e.length-5],s=n[n.length-5];if(i!==s&&typeof i=="string"&&typeof s=="string"){const d=i.split("#-#")[1],u=s.split("#-#")[1];return+d<+u}const r=e[e.length-3],c=n[n.length-3],l=e[e.length-1],A=n[n.length-1];return r<c?!0:r>c?!1:l<=A}function it(o){return o.sections[0].columns[0].lines.length===0}function or(o,t,e){let n=t,i=e,s=o[n],r=o[i];for(;n<i&&(it(s)||it(r));)it(s)?(n++,s=o[n]):it(r)&&(i--,r=o[i]);if(!it(s)&&!it(r))return[s,r]}class Eo{constructor(t,e){B(this,"_liquid",new _.Liquid);this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],s=this._docSkeleton.getSkeletonData();if(s==null)return;const{pages:r}=s,{segmentPage:c,page:l,pageType:A}=t,d=this._getTableRectRangeInfo(t,e);if(d==null)return;const{tableId:u,startRowIndex:m,startColumnIndex:h,endRowIndex:g,endColumnIndex:p}=d;this._liquid.reset();const{pageLayoutType:f,pageMarginLeft:S,pageMarginTop:E}=this._documentOffsetConfig,C=A===_.DocumentSkeletonPageType.BODY||A===_.DocumentSkeletonPageType.CELL?l:c;for(let T=0;T<C;T++){const R=r[T];this._liquid.translatePage(R,f,S,E)}for(let T=C;T<r.length;T++){const R=r[T];this._liquid.translatePagePadding(R);const{skeTables:v}=R;let O=null;for(const[x,U]of v.entries())x.startsWith(u)&&(O=U);if(O==null){this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E);continue}this._liquid.translateSave(),this._liquid.translate(0,O.top);const{x:M,y:b}=this._liquid,{left:N}=O;for(const x of O.rows)if(x.index>=m&&x.index<=g){const U=or(x.cells,h,p);if(U==null)continue;const[F,V]=U,H={startX:M+F.left+N,startY:b+x.top,endX:M+V.left+V.pageWidth+N,endY:b+x.top+x.height};n.push(So(H))}this._liquid.translateRestore(),this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E)}return{pointGroup:n,startRow:m,startColumn:h,endRow:g,endColumn:p,tableId:u}}getNodePositionGroup(t,e){const n=[],i=this._docSkeleton.findCharIndexByPosition(t),s=this._docSkeleton.findCharIndexByPosition(e);if(i==null||s==null)return;const r=i<s,c=this._getTableRectRangeInfo(t,e);if(c==null)return;const{tableId:l,startRowIndex:A,startColumnIndex:d,endRowIndex:u,endColumnIndex:m}=c,h=this._docSkeleton.getViewModel().findTableNodeById(l);if(h==null)return;const g=h.children[0].children.length;if(d===0&&m===g-1){const f=h.children[A].children[d],S=this._docSkeleton.findNodePositionByCharIndex(f.startIndex+1),E=h.children[u].children[m],C=this._docSkeleton.findNodePositionByCharIndex(E.endIndex-2);if(S==null||C==null)return;n.push({anchor:r?S:C,focus:r?C:S})}else for(let f=A;f<=u;f++){const S=h.children[f],E=S.children[d],C=S.children[m],T=this._docSkeleton.findNodePositionByCharIndex(E.startIndex+1),R=this._docSkeleton.findNodePositionByCharIndex(C.endIndex-2);if(T==null||R==null)return;n.push({anchor:r?T:R,focus:r?R:T})}return n}_getTableRectRangeInfo(t,e){const i=this._docSkeleton.getSkeletonData();if(i==null)return;const{pages:s}=i,{path:r}=t,{path:c}=e,l=_.getPageFromPath(i,r),A=_.getPageFromPath(i,c);if(l==null||A==null)return;const d=l.segmentId,u=l.parent.index,m=l.parent.cells.indexOf(l),h=(A==null?void 0:A.parent).index,g=(A==null?void 0:A.parent).cells.indexOf(A),p=Math.min(u,h),f=Math.max(u,h),S=Math.min(m,g),E=Math.max(m,g);return{pages:s,tableId:d,startRowIndex:p,startColumnIndex:S,endRowIndex:f,endColumnIndex:E}}}const ir="__TestSelectionRange__",ar="__TestSelectionAnchor__",Ji=6,Co=500,sr=500,$t=3;function Rt(o){const t=o[0],e=t[0],n=t[2],{x:i,y:s}=e,{x:r,y:c}=n;return{left:i,top:s,width:r-i,height:c-s}}function en(o){return o.map(t=>{let e=1/0,n=-1/0,i=1/0,s=-1/0;return t.forEach(r=>{e=Math.min(r.x,e),n=Math.max(r.x,n),s=Math.max(r.y,s),i=Math.min(r.y,i)}),{left:e,right:n,top:i,bottom:s}})}class We{constructor(t,e,n,i,s,r=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){B(this,"rangeType",a.DOC_RANGE_TYPE.TEXT);B(this,"_current",!1);B(this,"_rangeShape");B(this,"_anchorShape");B(this,"_cursorList",[]);B(this,"_anchorBlinkTimer",null);this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=i,this.focusNodePosition=s,this.style=r,this._segmentId=c,this._segmentPage=l,this._anchorBlink(),this.refresh()}_anchorBlink(){setTimeout(()=>{this._anchorShape&&this._anchorShape.visible&&this.deactivateStatic()},Co),this._anchorBlinkTimer=setInterval(()=>{this._anchorShape&&this._anchorShape.visible&&(this.activeStatic(),setTimeout(()=>{this.deactivateStatic()},Co))},sr+Co)}get startOffset(){var i;const{startOffset:t}=(i=fo(this._cursorList))!=null?i:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(n,t)}get endOffset(){var i;const{endOffset:t}=(i=fo(this._cursorList))!=null?i:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(t,n)}get collapsed(){const{startOffset:t,endOffset:e}=this;return t!=null&&t===e}get startNodePosition(){if(this.anchorNodePosition==null)return null;if(this.focusNodePosition==null)return this.anchorNodePosition;const{start:t}=po(this.anchorNodePosition,this.focusNodePosition);return t}get endNodePosition(){if(this.anchorNodePosition==null)return this.focusNodePosition;if(this.focusNodePosition==null)return null;const{end:t}=po(this.anchorNodePosition,this.focusNodePosition);return t}get direction(){const{collapsed:t,anchorNodePosition:e,focusNodePosition:n}=this;return t||e==null||n==null?a.RANGE_DIRECTION.NONE:mo(e,n)?a.RANGE_DIRECTION.FORWARD:a.RANGE_DIRECTION.BACKWARD}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}getAbsolutePosition(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(this._isEmpty())return;const n=this._document.getOffsetConfig(),{docsLeft:i,docsTop:s}=n,r=new Te(n,this._docSkeleton);if(this._isCollapsed()){const{contentBoxPointGroup:d,cursorList:u}=r.getRangePointData(t,t);if(this._setCursorList(u),d.length===0)return;const m=Rt(d);return{...m,left:m.left+i,top:m.top+s}}const{borderBoxPointGroup:c,cursorList:l}=r.getRangePointData(t,e);if(this._setCursorList(l),c.length===0)return;const A=Rt(c);return{...A,left:A.left+i,top:A.top+s}}getAnchor(){return this._anchorShape}activeStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.strokeActive)||_.getColor(a.COLORS.black,1)})}deactivateStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.stroke)||_.getColor(a.COLORS.black,0)})}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t,e;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null,(e=this._anchorShape)==null||e.dispose(),this._anchorShape=null,this._anchorBlinkTimer&&(clearInterval(this._anchorBlinkTimer),this._anchorBlinkTimer=null)}isIntersection(t){const{startOffset:e,endOffset:n}=this,{startOffset:i,endOffset:s}=t;return e==null||n==null||i==null||s==null?!1:e<=s&&n>=i}refresh(){var u,m;const{_document:t,_docSkeleton:e}=this,n=this.anchorNodePosition,i=this.focusNodePosition;if((u=this._anchorShape)==null||u.hide(),(m=this._rangeShape)==null||m.hide(),this._isEmpty())return;const s=t.getOffsetConfig(),{docsLeft:r,docsTop:c}=s,l=new Te(s,e);if(this._isCollapsed()){const{contentBoxPointGroup:h,cursorList:g}=l.getRangePointData(n,n);if(this._setCursorList(g),h.length>0){const p=e.findGlyphByPosition(n);this._createOrUpdateAnchor(h,r,c,p)}return}const{borderBoxPointGroup:A,cursorList:d}=l.getRangePointData(n,i);this._setCursorList(d),A.length>0&&this._createOrUpdateRange(A,r,c)}_isEmpty(){return this.anchorNodePosition==null&&this.focusNodePosition==null}_isCollapsed(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(t!=null&&e==null)return!0;if(t==null||e==null)return!1;const n=Object.keys(ot);for(const i of n){const s=t[i],r=e[i];if(s!==r)return!1}return t.isBack===e.isBack}_createOrUpdateRange(t,e,n){var r;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const i=.3,s=new _.RegularPolygon(ir+a.generateRandomId(Ji),{pointsGroup:t,fill:((r=this.style)==null?void 0:r.fill)||_.getColor(a.COLORS.black,i),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,$t)}_createOrUpdateAnchor(t,e,n,i){var p,f,S;const s=Rt(t),{left:r}=s;let{top:c,height:l}=s;const A=14;l<A&&(c-=A-l,l=A);const d=12;let u=r+e;const m=c+n,h=((p=i==null?void 0:i.ts)==null?void 0:p.it)===a.BooleanNumber.TRUE;if(h&&(u+=l*Math.tan(d*Math.PI/180)/2),this._anchorShape){this._anchorShape.transformByState({left:u,top:m,height:l}),this._anchorShape.show(),h?this._anchorShape.skew(-12,0):this._anchorShape.skew(0,0);return}const g=new _.Rect(ar+a.generateRandomId(Ji),{left:u,top:m,height:l,strokeWidth:((f=this.style)==null?void 0:f.strokeWidth)||1,stroke:((S=this.style)==null?void 0:S.strokeActive)||_.getColor(a.COLORS.black,1),evented:!1});h&&g.skew(-12,0),this._anchorShape=g,this._scene.addObject(g,$t),this.activeStatic()}_setCursorList(t){t.length!==0&&(this._cursorList=t)}}const rr="__DocTableRectRange__",cr=6;function tn(o,t,e,n,i,s=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,r="",c=-1){const l=t.getOffsetConfig(),d=new Eo(l,e).getNodePositionGroup(n,i);return(d!=null?d:[]).map(u=>new To(o,t,e,u.anchor,u.focus,s,r,c))}class To{constructor(t,e,n,i,s,r=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){B(this,"rangeType",a.DOC_RANGE_TYPE.RECT);B(this,"_rangeShape");B(this,"_current",!1);B(this,"_startRow");B(this,"_startCol");B(this,"_endRow");B(this,"_endCol");B(this,"_tableId");this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=i,this.focusNodePosition=s,this.style=r,this._segmentId=c,this._segmentPage=l,this.refresh()}get startOffset(){const{startNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get endOffset(){const{endNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get collapsed(){return!1}get startRow(){return this._startRow}get startColumn(){return this._startCol}get endRow(){return this._endRow}get endColumn(){return this._endCol}get tableId(){return this._tableId}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}get spanEntireRow(){var r;const e=(r=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:r[this._tableId],{_startCol:n,_endCol:i}=this;if(e==null)throw new Error("Table is not found.");const{tableColumns:s}=e;return n===0&&i===s.length-1}get spanEntireColumn(){var r;const e=(r=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:r[this._tableId],{_startRow:n,_endRow:i}=this;if(e==null)throw new Error("Table is not found.");const{tableRows:s}=e;return n===0&&i===s.length-1}get spanEntireTable(){return this.spanEntireRow&&this.spanEntireColumn}get startNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return vo(t,e)?t:e}get endNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return vo(t,e)?e:t}get direction(){const{anchorNodePosition:t,focusNodePosition:e}=this;return vo(t,e)?a.RANGE_DIRECTION.FORWARD:a.RANGE_DIRECTION.BACKWARD}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null}isIntersection(t){const{startRow:e,startColumn:n,endRow:i,endColumn:s}=this,{startRow:r,startColumn:c,endRow:l,endColumn:A}=t,d={left:n,top:e,right:s,bottom:i},u={left:c,top:r,right:A,bottom:l};return a.Rectangle.hasIntersectionBetweenTwoRect(d,u)}refresh(){var f;(f=this._rangeShape)==null||f.hide();const{startNodePosition:t,endNodePosition:e,_document:n,_docSkeleton:i}=this,s=n.getOffsetConfig(),{docsLeft:r,docsTop:c}=s,A=new Eo(s,i).getRangePointData(t,e);if(A==null)return;const{pointGroup:d=[],startRow:u,endRow:m,startColumn:h,endColumn:g,tableId:p}=A;(d==null?void 0:d.length)>0&&this._createOrUpdateRange(d,r,c),this._updateTableInfo(u,m,h,g,p)}_updateTableInfo(t,e,n,i,s){this._startRow=t,this._endRow=e,this._startCol=n,this._endCol=i,this._tableId=s}_createOrUpdateRange(t,e,n){var r;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const i=.3,s=new _.RegularPolygon(rr+a.generateRandomId(cr),{pointsGroup:t,fill:((r=this.style)==null?void 0:r.fill)||_.getColor(a.COLORS.black,i),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,$t)}}function Zi(o,t,e,n,i,s,r,c,l=!0,A=!0){const d=i.findNodePositionByCharIndex(o,l,r,c),u=i.findNodePositionByCharIndex(t,A,r,c);if(!(d==null||u==null))return new We(e,n,i,d,u,s,r,c)}function lr(o,t,e,n,i,s,r,c){const l=i.findNodePositionByCharIndex(o,!0,r,c),A=i.findNodePositionByCharIndex(t,!0,r,c);if(!(l==null||A==null))return new To(e,n,i,l,A,s,r,c)}function dr(o,t,e,n,i,s,r,c){const l=i.findNodePositionByCharIndex(o,!0,r,c),A=i.findNodePositionByCharIndex(t,!0,r,c);if(!(l==null||A==null))return yo(l,A,e,n,i,s,r,c)}function yo(o,t,e,n,i,s,r,c){const l=[],A=[],d=[e,n,i,o,t,s,r,c];if(qi(i,o,t)){if(Io(o,t))return l.push(new We(...d)),{textRanges:l,rectRanges:A};{const C=tn(...d);return A.push(...C),{textRanges:l,rectRanges:A}}}if(Yi(o,t)){const C=tn(...d);return A.push(...C),{textRanges:l,rectRanges:A}}const u=i.getViewModel().getSelfOrHeaderFooterViewModel(r),m=i.findCharIndexByPosition(o),h=i.findCharIndexByPosition(t);if(m==null||h==null)return;const g=m<=h?a.RANGE_DIRECTION.FORWARD:a.RANGE_DIRECTION.BACKWARD,p=Math.min(m,h),f=Math.max(m,h);let S=p,E=f;for(const C of u.getChildren())for(const T of C.children){const{startIndex:R,endIndex:v,children:O}=T,M=C.children.indexOf(T),b=C.children[M+1],N=O[0];let x=!1;if(N){const{startIndex:U,endIndex:F,children:V}=N;let H=null,Q=null;const X=V.find(k=>k.startIndex<=p&&k.endIndex>=p),j=V.find(k=>k.startIndex<=f&&k.endIndex>=f);if(p>U&&p<F)H=i.findNodePositionByCharIndex(X.startIndex+2,!0,r,c),Q=i.findNodePositionByCharIndex(F-4,!0,r,c),S=F+1;else if(f>U&&f<F)H=i.findNodePositionByCharIndex(U+3,!0,r,c),Q=i.findNodePositionByCharIndex(j.endIndex-3,!0,r,c),E=U-1,x=!0;else if(U>p&&F<f){if(H=i.findNodePositionByCharIndex(U+3,!0,r,c),Q=i.findNodePositionByCharIndex(F-4,!0,r,c),S<=U-1){const k=i.findNodePositionByCharIndex(S,!0,r,c),W=i.findNodePositionByCharIndex(U-1,!1,r,c),G=g===a.RANGE_DIRECTION.FORWARD?k:W,K=g===a.RANGE_DIRECTION.FORWARD?W:k;l.push(new We(e,n,i,G,K,s,r,c))}S=F+1}if(H&&Q){const k=g===a.RANGE_DIRECTION.FORWARD?H:Q,W=g===a.RANGE_DIRECTION.FORWARD?Q:H;A.push(...tn(e,n,i,k,W,s,r,c))}}if(E===v+1&&!x&&b&&b.children.length&&(E=v,x=!0),E>=R&&E<=v||x){const U=i.findNodePositionByCharIndex(S,!0,r,c),F=i.findNodePositionByCharIndex(E,!x,r,c),V=g===a.RANGE_DIRECTION.FORWARD?U:F,H=g===a.RANGE_DIRECTION.FORWARD?F:U;if(A.length&&a.Tools.diffValue(V,H))continue;l.push(new We(e,n,i,V,H,s,r,c))}}return{textRanges:l,rectRanges:A}}function $i(o){const t=o==null?void 0:o.getCanvasElement();if(!t)return{left:0,top:0};const{top:e,left:n}=_.getOffsetRectForDom(t);return{left:n,top:e}}function ea(o){var l;const t=(l=o.parent)==null?void 0:l.parent,e=t==null?void 0:t.parent;if(t==null||e==null)return;const{paragraphIndex:n}=t,i=e.lines.filter(A=>A.paragraphIndex===n);let s=-1,r="",c=!1;for(const A of i)for(const d of A.divides)for(const u of d.glyphGroup)c||(s+=u.count),u===o&&(c=!0),r+=u.count>0?u.content:"";return{st:i[0].st,ed:n,content:r,nodeIndex:s}}function bo(o){const{startOffset:t,endOffset:e,collapsed:n,rangeType:i,startNodePosition:s,endNodePosition:r,direction:c,segmentId:l,segmentPage:A}=o;return{startOffset:t,endOffset:e,collapsed:n,rangeType:i,startNodePosition:s,endNodePosition:r,direction:c,segmentId:l,segmentPage:A,isActive:o.isActive()}}function Ar(o){const t=bo(o),{startRow:e,startColumn:n,endRow:i,endColumn:s,tableId:r,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}=o;return{...t,startRow:e,startColumn:n,endRow:i,endColumn:s,tableId:r,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}}var ur=Object.getOwnPropertyDescriptor,hr=(o,t,e,n)=>{for(var i=n>1?void 0:n?ur(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},nn=(o,t)=>(e,n)=>t(e,n,o);y.DocSelectionRenderService=class extends a.RxDisposable{constructor(e,n,i,s,r){super();B(this,"_onInputBefore$",new L.Subject);B(this,"onInputBefore$",this._onInputBefore$.asObservable());B(this,"_onKeydown$",new L.Subject);B(this,"onKeydown$",this._onKeydown$.asObservable());B(this,"_onInput$",new L.Subject);B(this,"onInput$",this._onInput$.asObservable());B(this,"_onCompositionstart$",new L.BehaviorSubject(null));B(this,"onCompositionstart$",this._onCompositionstart$.asObservable());B(this,"_onCompositionupdate$",new L.BehaviorSubject(null));B(this,"onCompositionupdate$",this._onCompositionupdate$.asObservable());B(this,"_onCompositionend$",new L.BehaviorSubject(null));B(this,"onCompositionend$",this._onCompositionend$.asObservable());B(this,"_onSelectionStart$",new L.BehaviorSubject(null));B(this,"onSelectionStart$",this._onSelectionStart$.asObservable());B(this,"onChangeByEvent$",L.merge(this._onInput$,this._onKeydown$.pipe(L.filter(e=>e.event.keyCode===I.KeyCode.BACKSPACE)),this._onCompositionend$));B(this,"_onPaste$",new L.Subject);B(this,"onPaste$",this._onPaste$.asObservable());B(this,"_textSelectionInner$",new L.BehaviorSubject(null));B(this,"textSelectionInner$",this._textSelectionInner$.asObservable());B(this,"_onFocus$",new L.Subject);B(this,"onFocus$",this._onFocus$.asObservable());B(this,"_onBlur$",new L.Subject);B(this,"onBlur$",this._onBlur$.asObservable());B(this,"_onPointerDown$",new L.Subject);B(this,"onPointerDown$",this._onPointerDown$.asObservable());B(this,"_container");B(this,"_inputParent");B(this,"_input");B(this,"_scrollTimers",[]);B(this,"_rangeList",[]);B(this,"_rangeListCache",[]);B(this,"_rectRangeList",[]);B(this,"_rectRangeListCache",[]);B(this,"_anchorNodePosition",null);B(this,"_focusNodePosition",null);B(this,"_currentSegmentId","");B(this,"_currentSegmentPage",-1);B(this,"_selectionStyle",_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE);B(this,"_onPointerEvent",!1);B(this,"_viewPortObserverMap",new Map);B(this,"_isIMEInputApply",!1);B(this,"_scenePointerMoveSubs",[]);B(this,"_scenePointerUpSubs",[]);B(this,"_reserveRanges",!1);this._context=e,this._layoutService=n,this._logService=i,this._univerInstanceService=s,this._docSkeletonManagerService=r,this._initDOM(),this._registerContainer(),this._setSystemHighlightColorToStyle(),this._listenCurrentUnitChange()}get isOnPointerEvent(){return this._onPointerEvent}get isFocusing(){return this._input===document.activeElement}get canFocusing(){return this.isFocusing||document.activeElement===document.body||document.activeElement===null}_listenCurrentUnitChange(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(L.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;e.getUnitId()!==this._context.unitId&&!this._reserveRanges&&this.removeAllRanges()})}get activeViewPort(){return this._context.scene.getViewports()[0]}setSegment(e){this._currentSegmentId=e}getSegment(){return this._currentSegmentId}setSegmentPage(e){this._currentSegmentPage=e}getSegmentPage(){return this._currentSegmentPage}setReserveRangesStatus(e){this._reserveRanges=e}_setRangeStyle(e=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE){this._selectionStyle=e}addDocRanges(e,n=!0,i){const{_currentSegmentId:s,_currentSegmentPage:r,_selectionStyle:c}=this,{scene:l,mainComponent:A}=this._context,d=A,u=this._docSkeletonManagerService.getSkeleton(),m=(h,g)=>{const p=dr(h,g,l,d,u,c,s,r);if(p==null)return;const{textRanges:f,rectRanges:S}=p;for(const E of f)this._addTextRange(E);this._addRectRanges(S)};for(const h of e){const{startOffset:g,endOffset:p,rangeType:f,startNodePosition:S,endNodePosition:E}=h;if(f===a.DOC_RANGE_TYPE.RECT){const C=lr(g,p,l,d,u,c,s,r);C&&this._addRectRanges([C])}else if(f===a.DOC_RANGE_TYPE.TEXT)try{let C=null;S&&E?C=Zi(S.isBack?g:g-1,E.isBack?p:p-1,l,d,u,c,s,r,S.isBack,E.isBack):C=Zi(g,p,l,d,u,c,s,r),C&&this._addTextRange(C)}catch{m(g,p)}else m(g,p)}this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:s,segmentPage:r,style:c,isEditing:n,options:i}),!(!e.length||(i==null?void 0:i.shouldFocus)===!1)&&this._updateInputPosition(i==null?void 0:i.forceFocus)}setCursorManually(e,n){const i=this._findNodeByCoord(e,n,{strict:!0,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),s=this._getNodePosition(i);if(s==null){this._removeAllRanges();return}(i==null?void 0:i.node.streamType)===a.DataStreamTreeTokenType.PARAGRAPH&&(s.isBack=!0),this._createTextRangeByAnchorPosition(s),this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1})}sync(){this._updateInputPosition()}activate(e,n,i=!1){this._container.style.left=`${e}px`,this._container.style.top=`${n}px`,this._container.style.zIndex="1000",(this.canFocusing||i)&&this.focus()}hasFocus(){return document.activeElement===this._input}focus(){this._input.focus()}blur(){this._input.blur()}deactivate(){this._container.style.left="0px",this._container.style.top="0px"}__handleDblClick(e){const{offsetX:n,offsetY:i}=e,s=this._findNodeByCoord(n,i,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const r=ea(s.node);if(r==null)return;const{content:c,st:l,nodeIndex:A}=r;if(A===-1||Intl.Segmenter==null)return;const u=new Intl.Segmenter(void 0,{granularity:"word"}).segment(c);let m=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY;for(const{segment:g,index:p,isWordLike:f}of u)if(p<=A&&A<p+g.length&&f){m=p+l,h=p+l+g.length;break}if(Number.isFinite(m)&&Number.isFinite(h)){this.removeAllRanges();const g=[{startOffset:m,endOffset:h}];this.addDocRanges(g,!1,{forceFocus:!0})}}__handleTripleClick(e){const{offsetX:n,offsetY:i}=e,s=this._findNodeByCoord(n,i,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const r=ea(s.node);if(r==null)return;this.removeAllRanges();const{st:c,ed:l}=r,A=[{startOffset:c,endOffset:l}];this.addDocRanges(A,!1,{forceFocus:!0})}__onPointDown(e){var f,S;const{scene:n,mainComponent:i}=this._context,s=this._docSkeletonManagerService.getSkeleton(),{offsetX:r,offsetY:c}=e,l=this._findNodeByCoord(r,c,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),A=this._getNodePosition(l);if(A==null||l==null){this._removeAllRanges();return}(l==null?void 0:l.node.streamType)===a.DataStreamTreeTokenType.PARAGRAPH&&(A.isBack=!0);const d=this._textSelectionInner$.value;if(l&&e.button===2&&d){const E=s.findCharIndexByPosition(A);if(typeof E=="number"&&d.textRanges.some(C=>C.startOffset<=E&&C.endOffset>E)||typeof E=="number"&&d.rectRanges.some(C=>C.startOffset<=E&&C.endOffset>=E))return}const{segmentId:u,segmentPage:m}=l;u&&this._currentSegmentId&&u!==this._currentSegmentId&&this.setSegment(u),u&&m!==this._currentSegmentPage&&this.setSegmentPage(m),this._anchorNodePosition=A,e.shiftKey&&this._getActiveRangeInstance()?this._updateActiveRangePosition(A):e.ctrlKey?this._removeAllCollapsedTextRanges():this._isEmpty()||this._removeAllRanges(),n.disableObjectsEvent();const h=_.ScrollTimer.create(n);this._scrollTimers.push(h),h.startScroll(r,c),this._onSelectionStart$.next((f=this._getActiveRangeInstance())==null?void 0:f.startNodePosition),(S=n.getTransformer())==null||S.clearSelectedObjects();let g=r,p=c;this._onPointerEvent=!0,this._scenePointerMoveSubs.push(n.onPointerMove$.subscribeEvent(E=>{const{offsetX:C,offsetY:T}=E;n.setCursor(_.CURSOR_TYPE.TEXT),!(Math.sqrt((C-g)**2+(T-p)**2)<3)&&(this._moving(C,T),h.scrolling(C,T,()=>{this._moving(C,T)}),g=C,p=T)})),this._scenePointerUpSubs.push(n.onPointerUp$.subscribeEvent(()=>{if([...this._scenePointerMoveSubs,...this._scenePointerUpSubs].forEach(C=>{C.unsubscribe()}),this._onPointerEvent=!1,n.enableObjectsEvent(),this._anchorNodePosition&&!this._focusNodePosition){if(e.ctrlKey){this._disposeScrollTimers();return}const C=new We(n,i,s,this._anchorNodePosition,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(C)}else if(this._anchorNodePosition&&this._focusNodePosition){for(const C of this._rangeListCache)e.ctrlKey?C.collapsed?C.dispose():this._addTextRange(C):this._addTextRange(C);this._addRectRanges(this._rectRangeListCache),this._rangeListCache=[],this._rectRangeListCache=[]}this._anchorNodePosition=null,this._focusNodePosition=null;const E={textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1};this._textSelectionInner$.next(E),this._disposeScrollTimers(),this._updateInputPosition(!0)}))}removeAllRanges(){this._removeAllRanges(),this.deactivate()}getActiveTextRange(){return this._getActiveRangeInstance()}_disposeScrollTimers(){this._scrollTimers.forEach(e=>{e==null||e.dispose()}),this._scrollTimers=[]}_setSystemHighlightColorToStyle(){const{r:e,g:n,b:i,a:s}=_.getSystemHighlightColor(),r={strokeWidth:1,stroke:"rgba(0, 0, 0, 0)",strokeActive:"rgba(0, 0, 0, 1)",fill:`rgba(${e}, ${n}, ${i}, ${s!=null?s:.3})`};this._setRangeStyle(r)}_getAllTextRanges(){return this._rangeList.map(bo)}_getAllRectRanges(){return this._rectRangeList.map(Ar)}getAllTextRanges(){return this._getAllTextRanges()}getAllRectRanges(){return this._getAllRectRanges()}_getActiveRange(){const e=this._rangeList.find(s=>s.isActive());if(e==null)return null;const{startOffset:n,endOffset:i}=e;return n==null||i==null?null:bo(e)}_getActiveRangeInstance(){return this._rangeList.find(e=>e.isActive())}dispose(){super.dispose(),this._detachEvent(),this._removeAllRanges(),this._container.remove()}_initDOM(){const{unitId:e}=this._context,n=document.createElement("div");n.style.position="fixed",n.style.left="0px",n.style.top="0px",n.id=`univer-doc-selection-container-${e}`;const i=document.createElement("div"),s=document.createElement("div");i.appendChild(s),n.appendChild(i),this._container=n,this._inputParent=i,this._input=s,this._initInput(),this._initInputEvents(),document.body.appendChild(n)}_registerContainer(){this.disposeWithMe(this._layoutService.registerContainerElement(this._container))}_initInput(){this._inputParent.style.cssText=`
|
|
13
|
+
they are not in the same segment page when in header or footer.`);const{start:c,end:l}=po(t,e);return this._selectionIterator(c,l,(A,d,u,m,h,g)=>{const{lineHeight:p,asc:f,paddingTop:S,marginTop:E,marginBottom:C}=g,{glyphGroup:T,st:R}=h;if(T.length===0)return;const{x:v,y:O}=this._liquid;let M,b;const N=T[A],x=T[d],U=T[A-1],F=(N==null?void 0:N.left)||0,V=(N==null?void 0:N.width)||0,H=(x==null?void 0:x.left)||0,Q=(x==null?void 0:x.width)||0,X=(N==null?void 0:N.glyphType)===_.GlyphType.LIST,{startOffset:j,endOffset:k}=nr(T,A,d,R),W=c.glyph===A&&u?c.isBack:!0,G=l.glyph===d&&m?l.isBack:!1,K=c===l,Y=W&&U!=null?U:N;if(A===0&&d===T.length-1)M={startX:v+F+(X?V:0),startY:O,endX:v+H+(G?0:Q),endY:O+p-E-C},b={startX:v+F+(X?V:0),startY:O+S+f-Y.bBox.ba,endX:v+H+(G?0:Q),endY:O+S+f+Y.bBox.bd};else{const q=W&&!X;M={startX:v+F+(q?0:V),startY:O,endX:v+H+(G?0:Q),endY:O+p-E-C},b={startX:v+F+(q?0:V),startY:O+S+f-Y.bBox.ba,endX:v+H+(G?0:Q),endY:O+S+f+Y.bBox.bd}}n.push(So(M)),i.push(So(b)),s.push({startOffset:W?j:j+N.count,endOffset:G?k:k+x.count,collapsed:K})}),{borderBoxPointGroup:n,contentBoxPointGroup:i,cursorList:s}}_isValidPosition(t,e){const{segmentPage:n,pageType:i}=t,{segmentPage:s,pageType:r}=e;return i!==r?!1:i===_.DocumentSkeletonPageType.HEADER||i===_.DocumentSkeletonPageType.FOOTER?n===s:!0}_resetCurrentNodePositionState(){this._currentStartState={page:0,section:0,column:0,line:0,divide:0,glyph:0},this._currentEndState={page:0,section:0,column:0,line:0,divide:0,glyph:0}}_setNodePositionState(t=0,e,n,i){i===e?this._currentStartState[t]=1:this._currentStartState[t]=0,i===n?this._currentEndState[t]=2:this._currentEndState[t]=0}_checkPreviousNodePositionState(t,e=!0){let n=t,i;for(;n>=0;){const s=Zt[n];let r;if(e?r=this._currentStartState[s]:r=this._currentEndState[s],r===void 0)return;if(i===void 0&&(i=r),r!==i)return 0;n--}return i}_getSelectionRuler(t,e,n,i,s){let r=0,c=i;const l=Zt[t],A=Zt[t+1];if(A===null||l===null)return{start_next:r,end_next:c};const d=e[l],u=n[l];this._setNodePositionState(l,d,u,s);const m=this._checkPreviousNodePositionState(t),h=this._checkPreviousNodePositionState(t,!1);return m===1&&(r=e[A]),h===2&&(c=n[A]),{start_next:r,end_next:c}}_selectionIterator(t,e,n){var T,R;const i=this._docSkeleton;if(!i)return[];const{pageType:s,path:r}=t;this._liquid.reset();const c=i.getSkeletonData();if(c==null)return[];const{pages:l,skeHeaders:A,skeFooters:d}=c,{page:u,segmentPage:m}=t,{page:h,segmentPage:g}=e;if(this._resetCurrentNodePositionState(),this._documentOffsetConfig==null)return[];const{pageLayoutType:p,pageMarginLeft:f,pageMarginTop:S}=this._documentOffsetConfig,E=s===_.DocumentSkeletonPageType.BODY||s===_.DocumentSkeletonPageType.CELL?u:m;for(let v=0;v<E;v++){const O=l[v];this._liquid.translatePage(O,p,f,S)}const C=s===_.DocumentSkeletonPageType.BODY||s===_.DocumentSkeletonPageType.CELL?h:g;for(let v=E;v<=C;v++){const O=l[v],{headerId:M,footerId:b,pageWidth:N}=O;let x=O;if(s===_.DocumentSkeletonPageType.HEADER?x=(T=A.get(M))==null?void 0:T.get(N):s===_.DocumentSkeletonPageType.FOOTER?x=(R=d.get(b))==null?void 0:R.get(N):s===_.DocumentSkeletonPageType.CELL&&(x=_.getPageFromPath(c,r)),x==null){this._liquid.translatePage(O,p,f,S);continue}const U=x.sections,{start_next:F,end_next:V}=this._getSelectionRuler(ot.page,t,e,U.length-1,s===_.DocumentSkeletonPageType.BODY||s===_.DocumentSkeletonPageType.CELL?v:0);switch(this._liquid.translateSave(),s){case _.DocumentSkeletonPageType.HEADER:this._liquid.translatePagePadding({...x,marginLeft:O.marginLeft});break;case _.DocumentSkeletonPageType.FOOTER:{const H=O.pageHeight-x.height-x.marginBottom;this._liquid.translate(O.marginLeft,H);break}case _.DocumentSkeletonPageType.CELL:{this._liquid.translatePagePadding(O);const H=x.parent,Q=H.parent,{left:X}=x,{top:j,left:k}=Q,{top:W}=H;this._liquid.translate(k+X,j+W),this._liquid.translatePagePadding(x);break}default:this._liquid.translatePagePadding(O);break}for(let H=F;H<=V;H++){const Q=U[H],X=Q.columns,{start_next:j,end_next:k}=this._getSelectionRuler(ot.section,t,e,X.length-1,H);this._liquid.translateSection(Q);for(let W=j;W<=k;W++){const G=X[W],K=G.lines,{start_next:Y,end_next:q}=this._getSelectionRuler(ot.column,t,e,K.length-1,W);this._liquid.translateColumn(G);for(let z=Y;z<=q;z++){const $=K[z],{divides:ie}=$,{start_next:fe,end_next:Fe}=this._getSelectionRuler(ot.line,t,e,ie.length-1,z);this._liquid.translateSave(),this._liquid.translateLine($,!0,!1);for(let Se=fe;Se<=Fe;Se++){const ni=ie[Se];this._liquid.translateSave(),this._liquid.translateDivide(ni);const{glyphGroup:RA}=ni,{start_next:MA,end_next:xA}=this._getSelectionRuler(ot.divide,t,e,RA.length-1,Se);let hs=!1,gs=!1;v===E&&H===F&&W===j&&z===Y&&Se===fe&&(hs=!0),v===C&&H===V&&W===k&&z===q&&Se===Fe&&(gs=!0),n&&n(MA,xA,hs,gs,ni,$,G,Q,x),this._liquid.translateRestore()}this._liquid.translateRestore()}}}this._liquid.translateRestore(),this._liquid.translatePage(O,p,f,S)}}}function Yi(o,t){const{path:e}=o,{path:n}=t;if(e.length!==n.length||e.indexOf("cells")===-1)return!1;const i=e.indexOf("skeTables")+1,s=e.indexOf("rows")+1,r=e.indexOf("cells")+1,{tableId:c,sliceIndex:l}=_.getTableIdAndSliceIndex(e[i]),{tableId:A,sliceIndex:d}=_.getTableIdAndSliceIndex(n[i]);if(c!==A)return!1;const u=e[s],m=n[s],h=e[r],g=n[r];return!(u===m&&h===g&&l===d)}function Io(o,t){const{path:e}=o,{path:n}=t;return e.indexOf("cells")===-1||n.indexOf("cells")===-1||e.length!==n.length?!1:a.Tools.diffValue(e,n)}function qi(o,t,e){var h,g,p,f,S,E,C,T;const{path:n}=t,{path:i}=e;if(n.indexOf("cells")===-1||i.indexOf("cells")===-1)return!1;const s=o.findGlyphByPosition(t),r=o.findGlyphByPosition(e),c=(f=(p=(g=(h=s==null?void 0:s.parent)==null?void 0:h.parent)==null?void 0:g.parent)==null?void 0:p.parent)==null?void 0:f.parent,l=(T=(C=(E=(S=r==null?void 0:r.parent)==null?void 0:S.parent)==null?void 0:E.parent)==null?void 0:C.parent)==null?void 0:T.parent;if(c==null||l==null)return!1;const A=c.parent,d=l.parent,u=A.cells.indexOf(c),m=d.cells.indexOf(l);return u===m&&A.index===d.index}function vo(o,t){if(Io(o,t))return mo(o,t);const{path:e}=o,{path:n}=t,i=e[e.length-5],s=n[n.length-5];if(i!==s&&typeof i=="string"&&typeof s=="string"){const d=i.split("#-#")[1],u=s.split("#-#")[1];return+d<+u}const r=e[e.length-3],c=n[n.length-3],l=e[e.length-1],A=n[n.length-1];return r<c?!0:r>c?!1:l<=A}function it(o){return o.sections[0].columns[0].lines.length===0}function or(o,t,e){let n=t,i=e,s=o[n],r=o[i];for(;n<i&&(it(s)||it(r));)it(s)?(n++,s=o[n]):it(r)&&(i--,r=o[i]);if(!it(s)&&!it(r))return[s,r]}class Eo{constructor(t,e){B(this,"_liquid",new _.Liquid);this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],s=this._docSkeleton.getSkeletonData();if(s==null)return;const{pages:r}=s,{segmentPage:c,page:l,pageType:A}=t,d=this._getTableRectRangeInfo(t,e);if(d==null)return;const{tableId:u,startRowIndex:m,startColumnIndex:h,endRowIndex:g,endColumnIndex:p}=d;this._liquid.reset();const{pageLayoutType:f,pageMarginLeft:S,pageMarginTop:E}=this._documentOffsetConfig,C=A===_.DocumentSkeletonPageType.BODY||A===_.DocumentSkeletonPageType.CELL?l:c;for(let T=0;T<C;T++){const R=r[T];this._liquid.translatePage(R,f,S,E)}for(let T=C;T<r.length;T++){const R=r[T];this._liquid.translatePagePadding(R);const{skeTables:v}=R;let O=null;for(const[x,U]of v.entries())x.startsWith(u)&&(O=U);if(O==null){this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E);continue}this._liquid.translateSave(),this._liquid.translate(0,O.top);const{x:M,y:b}=this._liquid,{left:N}=O;for(const x of O.rows)if(x.index>=m&&x.index<=g){const U=or(x.cells,h,p);if(U==null)continue;const[F,V]=U,H={startX:M+F.left+N,startY:b+x.top,endX:M+V.left+V.pageWidth+N,endY:b+x.top+x.height};n.push(So(H))}this._liquid.translateRestore(),this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E)}return{pointGroup:n,startRow:m,startColumn:h,endRow:g,endColumn:p,tableId:u}}getNodePositionGroup(t,e){const n=[],i=this._docSkeleton.findCharIndexByPosition(t),s=this._docSkeleton.findCharIndexByPosition(e);if(i==null||s==null)return;const r=i<s,c=this._getTableRectRangeInfo(t,e);if(c==null)return;const{tableId:l,startRowIndex:A,startColumnIndex:d,endRowIndex:u,endColumnIndex:m}=c,h=this._docSkeleton.getViewModel().findTableNodeById(l);if(h==null)return;const g=h.children[0].children.length;if(d===0&&m===g-1){const f=h.children[A].children[d],S=this._docSkeleton.findNodePositionByCharIndex(f.startIndex+1),E=h.children[u].children[m],C=this._docSkeleton.findNodePositionByCharIndex(E.endIndex-2);if(S==null||C==null)return;n.push({anchor:r?S:C,focus:r?C:S})}else for(let f=A;f<=u;f++){const S=h.children[f],E=S.children[d],C=S.children[m],T=this._docSkeleton.findNodePositionByCharIndex(E.startIndex+1),R=this._docSkeleton.findNodePositionByCharIndex(C.endIndex-2);if(T==null||R==null)return;n.push({anchor:r?T:R,focus:r?R:T})}return n}_getTableRectRangeInfo(t,e){const i=this._docSkeleton.getSkeletonData();if(i==null)return;const{pages:s}=i,{path:r}=t,{path:c}=e,l=_.getPageFromPath(i,r),A=_.getPageFromPath(i,c);if(l==null||A==null)return;const d=l.segmentId,u=l.parent.index,m=l.parent.cells.indexOf(l),h=(A==null?void 0:A.parent).index,g=(A==null?void 0:A.parent).cells.indexOf(A),p=Math.min(u,h),f=Math.max(u,h),S=Math.min(m,g),E=Math.max(m,g);return{pages:s,tableId:d,startRowIndex:p,startColumnIndex:S,endRowIndex:f,endColumnIndex:E}}}const ir="__TestSelectionRange__",ar="__TestSelectionAnchor__",Ji=6,Co=500,sr=500,$t=3;function Rt(o){const t=o[0],e=t[0],n=t[2],{x:i,y:s}=e,{x:r,y:c}=n;return{left:i,top:s,width:r-i,height:c-s}}function en(o){return o.map(t=>{let e=1/0,n=-1/0,i=1/0,s=-1/0;return t.forEach(r=>{e=Math.min(r.x,e),n=Math.max(r.x,n),s=Math.max(r.y,s),i=Math.min(r.y,i)}),{left:e,right:n,top:i,bottom:s}})}class We{constructor(t,e,n,i,s,r=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){B(this,"rangeType",a.DOC_RANGE_TYPE.TEXT);B(this,"_current",!1);B(this,"_rangeShape");B(this,"_anchorShape");B(this,"_cursorList",[]);B(this,"_anchorBlinkTimer",null);this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=i,this.focusNodePosition=s,this.style=r,this._segmentId=c,this._segmentPage=l,this._anchorBlink(),this.refresh()}_anchorBlink(){setTimeout(()=>{this._anchorShape&&this._anchorShape.visible&&this.deactivateStatic()},Co),this._anchorBlinkTimer=setInterval(()=>{this._anchorShape&&this._anchorShape.visible&&(this.activeStatic(),setTimeout(()=>{this.deactivateStatic()},Co))},sr+Co)}get startOffset(){var i;const{startOffset:t}=(i=fo(this._cursorList))!=null?i:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(n,t)}get endOffset(){var i;const{endOffset:t}=(i=fo(this._cursorList))!=null?i:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(t,n)}get collapsed(){const{startOffset:t,endOffset:e}=this;return t!=null&&t===e}get startNodePosition(){if(this.anchorNodePosition==null)return null;if(this.focusNodePosition==null)return this.anchorNodePosition;const{start:t}=po(this.anchorNodePosition,this.focusNodePosition);return t}get endNodePosition(){if(this.anchorNodePosition==null)return this.focusNodePosition;if(this.focusNodePosition==null)return null;const{end:t}=po(this.anchorNodePosition,this.focusNodePosition);return t}get direction(){const{collapsed:t,anchorNodePosition:e,focusNodePosition:n}=this;return t||e==null||n==null?a.RANGE_DIRECTION.NONE:mo(e,n)?a.RANGE_DIRECTION.FORWARD:a.RANGE_DIRECTION.BACKWARD}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}getAbsolutePosition(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(this._isEmpty())return;const n=this._document.getOffsetConfig(),{docsLeft:i,docsTop:s}=n,r=new Te(n,this._docSkeleton);if(this._isCollapsed()){const{contentBoxPointGroup:d,cursorList:u}=r.getRangePointData(t,t);if(this._setCursorList(u),d.length===0)return;const m=Rt(d);return{...m,left:m.left+i,top:m.top+s}}const{borderBoxPointGroup:c,cursorList:l}=r.getRangePointData(t,e);if(this._setCursorList(l),c.length===0)return;const A=Rt(c);return{...A,left:A.left+i,top:A.top+s}}getAnchor(){return this._anchorShape}activeStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.strokeActive)||_.getColor(a.COLORS.black,1)})}deactivateStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.stroke)||_.getColor(a.COLORS.black,0)})}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t,e;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null,(e=this._anchorShape)==null||e.dispose(),this._anchorShape=null,this._anchorBlinkTimer&&(clearInterval(this._anchorBlinkTimer),this._anchorBlinkTimer=null)}isIntersection(t){const{startOffset:e,endOffset:n}=this,{startOffset:i,endOffset:s}=t;return e==null||n==null||i==null||s==null?!1:e<=s&&n>=i}refresh(){var u,m;const{_document:t,_docSkeleton:e}=this,n=this.anchorNodePosition,i=this.focusNodePosition;if((u=this._anchorShape)==null||u.hide(),(m=this._rangeShape)==null||m.hide(),this._isEmpty())return;const s=t.getOffsetConfig(),{docsLeft:r,docsTop:c}=s,l=new Te(s,e);if(this._isCollapsed()){const{contentBoxPointGroup:h,cursorList:g}=l.getRangePointData(n,n);if(this._setCursorList(g),h.length>0){const p=e.findGlyphByPosition(n);this._createOrUpdateAnchor(h,r,c,p)}return}const{borderBoxPointGroup:A,cursorList:d}=l.getRangePointData(n,i);this._setCursorList(d),A.length>0&&this._createOrUpdateRange(A,r,c)}_isEmpty(){return this.anchorNodePosition==null&&this.focusNodePosition==null}_isCollapsed(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(t!=null&&e==null)return!0;if(t==null||e==null)return!1;const n=Object.keys(ot);for(const i of n){const s=t[i],r=e[i];if(s!==r)return!1}return t.isBack===e.isBack}_createOrUpdateRange(t,e,n){var r;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const i=.3,s=new _.RegularPolygon(ir+a.generateRandomId(Ji),{pointsGroup:t,fill:((r=this.style)==null?void 0:r.fill)||_.getColor(a.COLORS.black,i),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,$t)}_createOrUpdateAnchor(t,e,n,i){var p,f,S;const s=Rt(t),{left:r}=s;let{top:c,height:l}=s;const A=14;l<A&&(c-=A-l,l=A);const d=12;let u=r+e;const m=c+n,h=((p=i==null?void 0:i.ts)==null?void 0:p.it)===a.BooleanNumber.TRUE;if(h&&(u+=l*Math.tan(d*Math.PI/180)/2),this._anchorShape){this._anchorShape.transformByState({left:u,top:m,height:l}),this._anchorShape.show(),h?this._anchorShape.skew(-d,0):this._anchorShape.skew(0,0);return}const g=new _.Rect(ar+a.generateRandomId(Ji),{left:u,top:m,height:l,strokeWidth:((f=this.style)==null?void 0:f.strokeWidth)||1,stroke:((S=this.style)==null?void 0:S.strokeActive)||_.getColor(a.COLORS.black,1),evented:!1});h&&g.skew(-d,0),this._anchorShape=g,this._scene.addObject(g,$t),this.activeStatic()}_setCursorList(t){t.length!==0&&(this._cursorList=t)}}const rr="__DocTableRectRange__",cr=6;function tn(o,t,e,n,i,s=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,r="",c=-1){const l=t.getOffsetConfig(),d=new Eo(l,e).getNodePositionGroup(n,i);return(d!=null?d:[]).map(u=>new To(o,t,e,u.anchor,u.focus,s,r,c))}class To{constructor(t,e,n,i,s,r=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){B(this,"rangeType",a.DOC_RANGE_TYPE.RECT);B(this,"_rangeShape");B(this,"_current",!1);B(this,"_startRow");B(this,"_startCol");B(this,"_endRow");B(this,"_endCol");B(this,"_tableId");this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=i,this.focusNodePosition=s,this.style=r,this._segmentId=c,this._segmentPage=l,this.refresh()}get startOffset(){const{startNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get endOffset(){const{endNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get collapsed(){return!1}get startRow(){return this._startRow}get startColumn(){return this._startCol}get endRow(){return this._endRow}get endColumn(){return this._endCol}get tableId(){return this._tableId}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}get spanEntireRow(){var r;const e=(r=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:r[this._tableId],{_startCol:n,_endCol:i}=this;if(e==null)throw new Error("Table is not found.");const{tableColumns:s}=e;return n===0&&i===s.length-1}get spanEntireColumn(){var r;const e=(r=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:r[this._tableId],{_startRow:n,_endRow:i}=this;if(e==null)throw new Error("Table is not found.");const{tableRows:s}=e;return n===0&&i===s.length-1}get spanEntireTable(){return this.spanEntireRow&&this.spanEntireColumn}get startNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return vo(t,e)?t:e}get endNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return vo(t,e)?e:t}get direction(){const{anchorNodePosition:t,focusNodePosition:e}=this;return vo(t,e)?a.RANGE_DIRECTION.FORWARD:a.RANGE_DIRECTION.BACKWARD}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null}isIntersection(t){const{startRow:e,startColumn:n,endRow:i,endColumn:s}=this,{startRow:r,startColumn:c,endRow:l,endColumn:A}=t,d={left:n,top:e,right:s,bottom:i},u={left:c,top:r,right:A,bottom:l};return a.Rectangle.hasIntersectionBetweenTwoRect(d,u)}refresh(){var f;(f=this._rangeShape)==null||f.hide();const{startNodePosition:t,endNodePosition:e,_document:n,_docSkeleton:i}=this,s=n.getOffsetConfig(),{docsLeft:r,docsTop:c}=s,A=new Eo(s,i).getRangePointData(t,e);if(A==null)return;const{pointGroup:d=[],startRow:u,endRow:m,startColumn:h,endColumn:g,tableId:p}=A;(d==null?void 0:d.length)>0&&this._createOrUpdateRange(d,r,c),this._updateTableInfo(u,m,h,g,p)}_updateTableInfo(t,e,n,i,s){this._startRow=t,this._endRow=e,this._startCol=n,this._endCol=i,this._tableId=s}_createOrUpdateRange(t,e,n){var r;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const i=.3,s=new _.RegularPolygon(rr+a.generateRandomId(cr),{pointsGroup:t,fill:((r=this.style)==null?void 0:r.fill)||_.getColor(a.COLORS.black,i),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,$t)}}function Zi(o,t,e,n,i,s,r,c,l=!0,A=!0){const d=i.findNodePositionByCharIndex(o,l,r,c),u=i.findNodePositionByCharIndex(t,A,r,c);if(!(d==null||u==null))return new We(e,n,i,d,u,s,r,c)}function lr(o,t,e,n,i,s,r,c){const l=i.findNodePositionByCharIndex(o,!0,r,c),A=i.findNodePositionByCharIndex(t,!0,r,c);if(!(l==null||A==null))return new To(e,n,i,l,A,s,r,c)}function dr(o,t,e,n,i,s,r,c){const l=i.findNodePositionByCharIndex(o,!0,r,c),A=i.findNodePositionByCharIndex(t,!0,r,c);if(!(l==null||A==null))return yo(l,A,e,n,i,s,r,c)}function yo(o,t,e,n,i,s,r,c){const l=[],A=[],d=[e,n,i,o,t,s,r,c];if(qi(i,o,t)){if(Io(o,t))return l.push(new We(...d)),{textRanges:l,rectRanges:A};{const C=tn(...d);return A.push(...C),{textRanges:l,rectRanges:A}}}if(Yi(o,t)){const C=tn(...d);return A.push(...C),{textRanges:l,rectRanges:A}}const u=i.getViewModel().getSelfOrHeaderFooterViewModel(r),m=i.findCharIndexByPosition(o),h=i.findCharIndexByPosition(t);if(m==null||h==null)return;const g=m<=h?a.RANGE_DIRECTION.FORWARD:a.RANGE_DIRECTION.BACKWARD,p=Math.min(m,h),f=Math.max(m,h);let S=p,E=f;for(const C of u.getChildren())for(const T of C.children){const{startIndex:R,endIndex:v,children:O}=T,M=C.children.indexOf(T),b=C.children[M+1],N=O[0];let x=!1;if(N){const{startIndex:U,endIndex:F,children:V}=N;let H=null,Q=null;const X=V.find(k=>k.startIndex<=p&&k.endIndex>=p),j=V.find(k=>k.startIndex<=f&&k.endIndex>=f);if(p>U&&p<F)H=i.findNodePositionByCharIndex(X.startIndex+2,!0,r,c),Q=i.findNodePositionByCharIndex(F-4,!0,r,c),S=F+1;else if(f>U&&f<F)H=i.findNodePositionByCharIndex(U+3,!0,r,c),Q=i.findNodePositionByCharIndex(j.endIndex-3,!0,r,c),E=U-1,x=!0;else if(U>p&&F<f){if(H=i.findNodePositionByCharIndex(U+3,!0,r,c),Q=i.findNodePositionByCharIndex(F-4,!0,r,c),S<=U-1){const k=i.findNodePositionByCharIndex(S,!0,r,c),W=i.findNodePositionByCharIndex(U-1,!1,r,c),G=g===a.RANGE_DIRECTION.FORWARD?k:W,K=g===a.RANGE_DIRECTION.FORWARD?W:k;l.push(new We(e,n,i,G,K,s,r,c))}S=F+1}if(H&&Q){const k=g===a.RANGE_DIRECTION.FORWARD?H:Q,W=g===a.RANGE_DIRECTION.FORWARD?Q:H;A.push(...tn(e,n,i,k,W,s,r,c))}}if(E===v+1&&!x&&b&&b.children.length&&(E=v,x=!0),E>=R&&E<=v||x){const U=i.findNodePositionByCharIndex(S,!0,r,c),F=i.findNodePositionByCharIndex(E,!x,r,c),V=g===a.RANGE_DIRECTION.FORWARD?U:F,H=g===a.RANGE_DIRECTION.FORWARD?F:U;if(A.length&&a.Tools.diffValue(V,H))continue;l.push(new We(e,n,i,V,H,s,r,c))}}return{textRanges:l,rectRanges:A}}function $i(o){const t=o==null?void 0:o.getCanvasElement();if(!t)return{left:0,top:0};const{top:e,left:n}=_.getOffsetRectForDom(t);return{left:n,top:e}}function ea(o){var l;const t=(l=o.parent)==null?void 0:l.parent,e=t==null?void 0:t.parent;if(t==null||e==null)return;const{paragraphIndex:n}=t,i=e.lines.filter(A=>A.paragraphIndex===n);let s=-1,r="",c=!1;for(const A of i)for(const d of A.divides)for(const u of d.glyphGroup)c||(s+=u.count),u===o&&(c=!0),r+=u.count>0?u.content:"";return{st:i[0].st,ed:n,content:r,nodeIndex:s}}function bo(o){const{startOffset:t,endOffset:e,collapsed:n,rangeType:i,startNodePosition:s,endNodePosition:r,direction:c,segmentId:l,segmentPage:A}=o;return{startOffset:t,endOffset:e,collapsed:n,rangeType:i,startNodePosition:s,endNodePosition:r,direction:c,segmentId:l,segmentPage:A,isActive:o.isActive()}}function Ar(o){const t=bo(o),{startRow:e,startColumn:n,endRow:i,endColumn:s,tableId:r,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}=o;return{...t,startRow:e,startColumn:n,endRow:i,endColumn:s,tableId:r,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}}var ur=Object.getOwnPropertyDescriptor,hr=(o,t,e,n)=>{for(var i=n>1?void 0:n?ur(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},nn=(o,t)=>(e,n)=>t(e,n,o);y.DocSelectionRenderService=class extends a.RxDisposable{constructor(e,n,i,s,r){super();B(this,"_onInputBefore$",new L.Subject);B(this,"onInputBefore$",this._onInputBefore$.asObservable());B(this,"_onKeydown$",new L.Subject);B(this,"onKeydown$",this._onKeydown$.asObservable());B(this,"_onInput$",new L.Subject);B(this,"onInput$",this._onInput$.asObservable());B(this,"_onCompositionstart$",new L.BehaviorSubject(null));B(this,"onCompositionstart$",this._onCompositionstart$.asObservable());B(this,"_onCompositionupdate$",new L.BehaviorSubject(null));B(this,"onCompositionupdate$",this._onCompositionupdate$.asObservable());B(this,"_onCompositionend$",new L.BehaviorSubject(null));B(this,"onCompositionend$",this._onCompositionend$.asObservable());B(this,"_onSelectionStart$",new L.BehaviorSubject(null));B(this,"onSelectionStart$",this._onSelectionStart$.asObservable());B(this,"onChangeByEvent$",L.merge(this._onInput$,this._onKeydown$.pipe(L.filter(e=>e.event.keyCode===I.KeyCode.BACKSPACE)),this._onCompositionend$));B(this,"_onPaste$",new L.Subject);B(this,"onPaste$",this._onPaste$.asObservable());B(this,"_textSelectionInner$",new L.BehaviorSubject(null));B(this,"textSelectionInner$",this._textSelectionInner$.asObservable());B(this,"_onFocus$",new L.Subject);B(this,"onFocus$",this._onFocus$.asObservable());B(this,"_onBlur$",new L.Subject);B(this,"onBlur$",this._onBlur$.asObservable());B(this,"_onPointerDown$",new L.Subject);B(this,"onPointerDown$",this._onPointerDown$.asObservable());B(this,"_container");B(this,"_inputParent");B(this,"_input");B(this,"_scrollTimers",[]);B(this,"_rangeList",[]);B(this,"_rangeListCache",[]);B(this,"_rectRangeList",[]);B(this,"_rectRangeListCache",[]);B(this,"_anchorNodePosition",null);B(this,"_focusNodePosition",null);B(this,"_currentSegmentId","");B(this,"_currentSegmentPage",-1);B(this,"_selectionStyle",_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE);B(this,"_onPointerEvent",!1);B(this,"_viewPortObserverMap",new Map);B(this,"_isIMEInputApply",!1);B(this,"_scenePointerMoveSubs",[]);B(this,"_scenePointerUpSubs",[]);B(this,"_reserveRanges",!1);this._context=e,this._layoutService=n,this._logService=i,this._univerInstanceService=s,this._docSkeletonManagerService=r,this._initDOM(),this._registerContainer(),this._setSystemHighlightColorToStyle(),this._listenCurrentUnitChange()}get isOnPointerEvent(){return this._onPointerEvent}get isFocusing(){return this._input===document.activeElement}get canFocusing(){return this.isFocusing||document.activeElement===document.body||document.activeElement===null}_listenCurrentUnitChange(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(L.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;e.getUnitId()!==this._context.unitId&&!this._reserveRanges&&this.removeAllRanges()})}get activeViewPort(){return this._context.scene.getViewports()[0]}setSegment(e){this._currentSegmentId=e}getSegment(){return this._currentSegmentId}setSegmentPage(e){this._currentSegmentPage=e}getSegmentPage(){return this._currentSegmentPage}setReserveRangesStatus(e){this._reserveRanges=e}_setRangeStyle(e=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE){this._selectionStyle=e}addDocRanges(e,n=!0,i){const{_currentSegmentId:s,_currentSegmentPage:r,_selectionStyle:c}=this,{scene:l,mainComponent:A}=this._context,d=A,u=this._docSkeletonManagerService.getSkeleton(),m=(h,g)=>{const p=dr(h,g,l,d,u,c,s,r);if(p==null)return;const{textRanges:f,rectRanges:S}=p;for(const E of f)this._addTextRange(E);this._addRectRanges(S)};for(const h of e){const{startOffset:g,endOffset:p,rangeType:f,startNodePosition:S,endNodePosition:E}=h;if(f===a.DOC_RANGE_TYPE.RECT){const C=lr(g,p,l,d,u,c,s,r);C&&this._addRectRanges([C])}else if(f===a.DOC_RANGE_TYPE.TEXT)try{let C=null;S&&E?C=Zi(S.isBack?g:g-1,E.isBack?p:p-1,l,d,u,c,s,r,S.isBack,E.isBack):C=Zi(g,p,l,d,u,c,s,r),C&&this._addTextRange(C)}catch{m(g,p)}else m(g,p)}this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:s,segmentPage:r,style:c,isEditing:n,options:i}),!(!e.length||(i==null?void 0:i.shouldFocus)===!1)&&this._updateInputPosition(i==null?void 0:i.forceFocus)}setCursorManually(e,n){const i=this._findNodeByCoord(e,n,{strict:!0,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),s=this._getNodePosition(i);if(s==null){this._removeAllRanges();return}(i==null?void 0:i.node.streamType)===a.DataStreamTreeTokenType.PARAGRAPH&&(s.isBack=!0),this._createTextRangeByAnchorPosition(s),this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1})}sync(){this._updateInputPosition()}activate(e,n,i=!1){this._container.style.left=`${e}px`,this._container.style.top=`${n}px`,this._container.style.zIndex="1000",(this.canFocusing||i)&&this.focus()}hasFocus(){return document.activeElement===this._input}focus(){this._input.focus()}blur(){this._input.blur()}deactivate(){this._container.style.left="0px",this._container.style.top="0px"}__handleDblClick(e){const{offsetX:n,offsetY:i}=e,s=this._findNodeByCoord(n,i,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const r=ea(s.node);if(r==null)return;const{content:c,st:l,nodeIndex:A}=r;if(A===-1||Intl.Segmenter==null)return;const u=new Intl.Segmenter(void 0,{granularity:"word"}).segment(c);let m=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY;for(const{segment:g,index:p,isWordLike:f}of u)if(p<=A&&A<p+g.length&&f){m=p+l,h=p+l+g.length;break}if(Number.isFinite(m)&&Number.isFinite(h)){this.removeAllRanges();const g=[{startOffset:m,endOffset:h}];this.addDocRanges(g,!1,{forceFocus:!0})}}__handleTripleClick(e){const{offsetX:n,offsetY:i}=e,s=this._findNodeByCoord(n,i,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const r=ea(s.node);if(r==null)return;this.removeAllRanges();const{st:c,ed:l}=r,A=[{startOffset:c,endOffset:l}];this.addDocRanges(A,!1,{forceFocus:!0})}__onPointDown(e){var f,S;const{scene:n,mainComponent:i}=this._context,s=this._docSkeletonManagerService.getSkeleton(),{offsetX:r,offsetY:c}=e,l=this._findNodeByCoord(r,c,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),A=this._getNodePosition(l);if(A==null||l==null){this._removeAllRanges();return}(l==null?void 0:l.node.streamType)===a.DataStreamTreeTokenType.PARAGRAPH&&(A.isBack=!0);const d=this._textSelectionInner$.value;if(l&&e.button===2&&d){const E=s.findCharIndexByPosition(A);if(typeof E=="number"&&d.textRanges.some(C=>C.startOffset<=E&&C.endOffset>E)||typeof E=="number"&&d.rectRanges.some(C=>C.startOffset<=E&&C.endOffset>=E))return}const{segmentId:u,segmentPage:m}=l;u&&this._currentSegmentId&&u!==this._currentSegmentId&&this.setSegment(u),u&&m!==this._currentSegmentPage&&this.setSegmentPage(m),this._anchorNodePosition=A,e.shiftKey&&this._getActiveRangeInstance()?this._updateActiveRangePosition(A):e.ctrlKey?this._removeAllCollapsedTextRanges():this._isEmpty()||this._removeAllRanges(),n.disableObjectsEvent();const h=_.ScrollTimer.create(n);this._scrollTimers.push(h),h.startScroll(r,c),this._onSelectionStart$.next((f=this._getActiveRangeInstance())==null?void 0:f.startNodePosition),(S=n.getTransformer())==null||S.clearSelectedObjects();let g=r,p=c;this._onPointerEvent=!0,this._scenePointerMoveSubs.push(n.onPointerMove$.subscribeEvent(E=>{const{offsetX:C,offsetY:T}=E;n.setCursor(_.CURSOR_TYPE.TEXT),!(Math.sqrt((C-g)**2+(T-p)**2)<3)&&(this._moving(C,T),h.scrolling(C,T,()=>{this._moving(C,T)}),g=C,p=T)})),this._scenePointerUpSubs.push(n.onPointerUp$.subscribeEvent(()=>{if([...this._scenePointerMoveSubs,...this._scenePointerUpSubs].forEach(C=>{C.unsubscribe()}),this._onPointerEvent=!1,n.enableObjectsEvent(),this._anchorNodePosition&&!this._focusNodePosition){if(e.ctrlKey){this._disposeScrollTimers();return}const C=new We(n,i,s,this._anchorNodePosition,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(C)}else if(this._anchorNodePosition&&this._focusNodePosition){for(const C of this._rangeListCache)e.ctrlKey?C.collapsed?C.dispose():this._addTextRange(C):this._addTextRange(C);this._addRectRanges(this._rectRangeListCache),this._rangeListCache=[],this._rectRangeListCache=[]}this._anchorNodePosition=null,this._focusNodePosition=null;const E={textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1};this._textSelectionInner$.next(E),this._disposeScrollTimers(),this._updateInputPosition(!0)}))}removeAllRanges(){this._removeAllRanges(),this.deactivate()}getActiveTextRange(){return this._getActiveRangeInstance()}_disposeScrollTimers(){this._scrollTimers.forEach(e=>{e==null||e.dispose()}),this._scrollTimers=[]}_setSystemHighlightColorToStyle(){const{r:e,g:n,b:i,a:s}=_.getSystemHighlightColor(),r={strokeWidth:1,stroke:"rgba(0, 0, 0, 0)",strokeActive:"rgba(0, 0, 0, 1)",fill:`rgba(${e}, ${n}, ${i}, ${s!=null?s:.3})`};this._setRangeStyle(r)}_getAllTextRanges(){return this._rangeList.map(bo)}_getAllRectRanges(){return this._rectRangeList.map(Ar)}getAllTextRanges(){return this._getAllTextRanges()}getAllRectRanges(){return this._getAllRectRanges()}_getActiveRange(){const e=this._rangeList.find(s=>s.isActive());if(e==null)return null;const{startOffset:n,endOffset:i}=e;return n==null||i==null?null:bo(e)}_getActiveRangeInstance(){return this._rangeList.find(e=>e.isActive())}dispose(){super.dispose(),this._detachEvent(),this._removeAllRanges(),this._container.remove()}_initDOM(){const{unitId:e}=this._context,n=document.createElement("div");n.style.position="fixed",n.style.left="0px",n.style.top="0px",n.id=`univer-doc-selection-container-${e}`;const i=document.createElement("div"),s=document.createElement("div");i.appendChild(s),n.appendChild(i),this._container=n,this._inputParent=i,this._input=s,this._initInput(),this._initInputEvents(),document.body.appendChild(n)}_registerContainer(){this.disposeWithMe(this._layoutService.registerContainerElement(this._container))}_initInput(){this._inputParent.style.cssText=`
|
|
14
14
|
position:absolute;
|
|
15
15
|
height:1px;
|
|
16
16
|
width:1px;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-ui",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer normal ui-plugin-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@univerjs/icons": "^0.4.6",
|
|
68
|
-
"@univerjs/
|
|
69
|
-
"@univerjs/
|
|
70
|
-
"@univerjs/docs": "0.9.
|
|
71
|
-
"@univerjs/
|
|
72
|
-
"@univerjs/
|
|
73
|
-
"@univerjs/ui": "0.9.
|
|
68
|
+
"@univerjs/core": "0.9.4",
|
|
69
|
+
"@univerjs/design": "0.9.4",
|
|
70
|
+
"@univerjs/docs": "0.9.4",
|
|
71
|
+
"@univerjs/drawing": "0.9.4",
|
|
72
|
+
"@univerjs/engine-render": "0.9.4",
|
|
73
|
+
"@univerjs/ui": "0.9.4"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"jest-canvas-mock": "^2.5.2",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
"typescript": "^5.8.3",
|
|
83
83
|
"vite": "^7.0.5",
|
|
84
84
|
"vitest": "^3.2.4",
|
|
85
|
-
"@univerjs-
|
|
86
|
-
"@univerjs/
|
|
85
|
+
"@univerjs/docs-drawing": "0.9.4",
|
|
86
|
+
"@univerjs-infra/shared": "0.9.4"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
89
|
"test": "vitest run",
|