@univerjs/drawing 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # @univerjs/drawing
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@univerjs/drawing)](https://npmjs.org/packages/@univerjs/drawing)
4
+ [![license](https://img.shields.io/npm/l/@univerjs/drawing)](https://img.shields.io/npm/l/@univerjs/drawing)
5
+
6
+ ## Introduction
7
+
8
+ > TODO: Introduction
9
+
10
+ ## Usage
11
+
12
+ ### Installation
13
+
14
+ ```shell
15
+ npm i @univerjs/drawing
16
+ ```
@@ -0,0 +1 @@
1
+ "use strict";var $t=Object.defineProperty;var Wt=(n,e,t)=>e in n?$t(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var q=(n,e,t)=>(Wt(n,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ie=require("rxjs"),Qe=require("@univerjs/core"),nt=require("@wendellhu/redi"),Gt=500,Bt=500,xt=10,Ct=5*1024*1024,Et=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"];var Ce=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},F={},At={},dt={};Object.defineProperty(dt,"__esModule",{value:!0});function Lt(n,e){if(Array.isArray(e))return!1;for(let t in n)if(!ft(n[t],e[t]))return!1;for(let t in e)if(n[t]===void 0)return!1;return!0}function Ht(n,e){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!ft(n[t],e[t]))return!1;return!0}function ft(n,e){return n===e?!0:n===null||e===null||typeof n!="object"||typeof e!="object"?!1:Array.isArray(n)?Ht(n,e):Lt(n,e)}dt.default=ft;var ht={};Object.defineProperty(ht,"__esModule",{value:!0});function ct(n){if(n===null)return null;if(Array.isArray(n))return n.map(ct);if(typeof n=="object"){const e={};for(let t in n)e[t]=ct(n[t]);return e}else return n}ht.default=ct;var pt={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.eachChildOf=n.advancer=n.readCursor=n.writeCursor=n.WriteCursor=n.ReadCursor=n.isValidPathItem=void 0;function e(O,o){if(!O)throw new Error(o)}const t=O=>O!=null&&typeof O=="object"&&!Array.isArray(O),s=(O,o)=>typeof O==typeof o?O>o:typeof O=="string"&&typeof o=="number";function i(O,o){for(let c in O){const h=c;o.write(h,O[h])}}n.isValidPathItem=O=>typeof O=="number"||typeof O=="string"&&O!=="__proto__";class d{constructor(o=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=o}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,t(this.container[this.idx])&&this.idx--)}getPath(){const o=[];let c=this.container,h=this.parents.length-1,j=this.idx;for(;j>=0;)o.unshift(c[j]),j===0?(j=this.indexes[h*2],c=this.parents[h--]):j-=t(c[j-1])?2:1;return o}}class l extends d{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let o;return this.container&&this.container.length>this.idx+1&&t(o=this.container[this.idx+1])?o:null}descendFirst(){let o=this.idx+1;if(!this.container||o>=this.container.length||t(this.container[o])&&o+1>=this.container.length)return!1;t(this.container[o])&&o++;const c=this.container[o];return Array.isArray(c)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(o),this.idx=0,this.container=c):this.idx=o,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const o=this.indexes[this.indexes.length-1]+1,c=this.parents[this.parents.length-1];return o>=c.length?!1:(e(!isNaN(o)),this.indexes[this.indexes.length-1]=o,this.container=c[o],!0)}_init(o,c,h,j){this.container=o,this.idx=c,this.parents=h.slice(),this.indexes=j.slice()}clone(){const o=new l;return o._init(this.container,this.idx,this.parents,this.indexes),o}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(o,c){const h=this.getComponent();h&&c(h,o);for(const j of this)o&&o.descend(j),this.traverse(o,c),o&&o.ascend()}eachPick(o,c){this.traverse(o,(h,j)=>{h.p!=null&&c(h.p,j)})}eachDrop(o,c){this.traverse(o,(h,j)=>{h.d!=null&&c(h.d,j)})}}n.ReadCursor=l;class a extends d{constructor(o=null){super(o),this.pendingDescent=[],this._op=o}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let o=0;o<this.pendingDescent.length;o++){const c=this.pendingDescent[o];let h=this.idx+1;if(h<this.container.length&&t(this.container[h])&&h++,e(h===this.container.length||!t(this.container[h])),h===this.container.length)this.container.push(c),this.idx=h;else if(this.container[h]===c)this.idx=h;else{if(!Array.isArray(this.container[h])){const j=this.container.splice(h,this.container.length-h);this.container.push(j),this.lcIdx>-1&&(this.lcIdx=h)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(s(c,this.container[this.lcIdx][0])),h=this.lcIdx+1,this.lcIdx=-1);h<this.container.length&&s(c,this.container[h][0]);)h++;if(this.indexes.push(h),this.idx=0,h<this.container.length&&this.container[h][0]===c)this.container=this.container[h];else{const j=[c];this.container.splice(h,0,j),this.container=j}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const o=this.idx+1;if(o<this.container.length&&t(this.container[o]))return this.container[o];{const c={};return this.container.splice(o,0,c),c}}write(o,c){const h=this.getComponent();e(h[o]==null||h[o]===c,"Internal consistency error: Overwritten component. File a bug"),h[o]=c}get(){return this._op}descend(o){if(!n.isValidPathItem(o))throw Error("Invalid JSON key");this.pendingDescent.push(o)}descendPath(o){return this.pendingDescent.push(...o),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(o,c=i){if(o===null)return;if(e(Array.isArray(o)),o===this._op)throw Error("Cannot merge into my own tree");const h=this.lcIdx,j=this.parents.length;let Y=0;for(let pe=0;pe<o.length;pe++){const J=o[pe];typeof J=="string"||typeof J=="number"?(Y++,this.descend(J)):Array.isArray(J)?this.mergeTree(J,c):typeof J=="object"&&c(J,this)}for(;Y--;)this.ascend();this.lcIdx=this.parents.length===j?h:-1}at(o,c){this.descendPath(o),c(this);for(let h=0;h<o.length;h++)this.ascend();return this}writeAtPath(o,c,h){return this.at(o,()=>this.write(c,h)),this.reset(),this}writeMove(o,c,h=0){return this.writeAtPath(o,"p",h).writeAtPath(c,"d",h)}getPath(){const o=super.getPath();return o.push(...this.pendingDescent),o}}n.WriteCursor=a,n.writeCursor=()=>new a,n.readCursor=O=>new l(O);function E(O,o,c){let h,j;j=h=O?O.descendFirst():!1;function Y(pe){let J;for(;j;){const we=J=O.getKey();if(pe!=null){let xe=!1;if(o&&typeof we=="number"&&(J=o(we,O.getComponent()),J<0&&(J=~J,xe=!0)),s(J,pe))return null;if(J===pe&&!xe)return O}c&&typeof J=="number"&&c(J,O.getComponent()),j=O.nextSibling()}return null}return Y.end=()=>{h&&O.ascend()},Y}n.advancer=E;function W(O,o,c){let h,j,Y,pe;for(h=j=O&&O.descendFirst(),Y=pe=o&&o.descendFirst();h||Y;){let J=h?O.getKey():null,we=Y?o.getKey():null;J!==null&&we!==null&&(s(we,J)?we=null:J!==we&&(J=null)),c(J==null?we:J,J!=null?O:null,we!=null?o:null),J!=null&&h&&(h=O.nextSibling()),we!=null&&Y&&(Y=o.nextSibling())}j&&O.ascend(),pe&&o.ascend()}n.eachChildOf=W})(pt);var gt={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.ConflictType=void 0,function(e){e[e.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",e[e.DROP_COLLISION=2]="DROP_COLLISION",e[e.BLACKHOLE=3]="BLACKHOLE"}(n.ConflictType||(n.ConflictType={}))})(gt);var ot={},Ve={},bt;function _t(){return bt||(bt=1,Object.defineProperty(Ve,"__esModule",{value:!0}),Ve.uniToStrPos=Ve.strPosToUni=void 0,Ve.strPosToUni=(n,e=n.length)=>{let t=0,s=0;for(;s<e;s++){const i=n.charCodeAt(s);i>=55296&&i<=57343&&(t++,s++)}if(s!==e)throw Error("Invalid offset - splits unicode bytes");return s-t},Ve.uniToStrPos=(n,e)=>{let t=0;for(;e>0;e--){const s=n.charCodeAt(t);t+=s>=55296&&s<=57343?2:1}return t}),Ve}var lt={},mt;function ut(){return mt||(mt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.uniSlice=n.dlen=n.eachOp=void 0;const e=_t(),t=f=>{if(!Array.isArray(f))throw Error("Op must be an array of components");let _=null;for(let I=0;I<f.length;I++){const L=f[I];switch(typeof L){case"object":if(typeof L.d!="number"&&typeof L.d!="string")throw Error("Delete must be number or string");if(n.dlen(L.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(L.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(L>0))throw Error("Skip components must be >0");if(typeof _=="number")throw Error("Adjacent skip components should be combined");break}_=L}if(typeof _=="number")throw Error("Op has a trailing skip")};function s(f,_){let I=0,L=0;for(let z=0;z<f.length;z++){const H=f[z];switch(_(H,I,L),typeof H){case"object":I+=n.dlen(H.d);break;case"string":L+=e.strPosToUni(H);break;case"number":I+=H,L+=H;break}}}n.eachOp=s;function i(f,_){const I=[],L=a(I);return s(f,(z,H,Ae)=>{L(_(z,H,Ae))}),o(I)}const d=f=>f,l=f=>i(f,d);n.dlen=f=>typeof f=="number"?f:e.strPosToUni(f);const a=f=>_=>{if(!(!_||_.d===0||_.d===""))if(f.length===0)f.push(_);else if(typeof _==typeof f[f.length-1])if(typeof _=="object"){const I=f[f.length-1];I.d=typeof I.d=="string"&&typeof _.d=="string"?I.d+_.d:n.dlen(I.d)+n.dlen(_.d)}else f[f.length-1]+=_;else f.push(_)},E=f=>typeof f=="number"?f:typeof f=="string"?e.strPosToUni(f):typeof f.d=="number"?f.d:e.strPosToUni(f.d);n.uniSlice=(f,_,I)=>{const L=e.uniToStrPos(f,_),z=I==null?1/0:e.uniToStrPos(f,I);return f.slice(L,z)};const W=(f,_,I)=>typeof f=="number"?I==null?f-_:Math.min(f,I)-_:n.uniSlice(f,_,I),O=f=>{let _=0,I=0;return{take:(H,Ae)=>{if(_===f.length)return H===-1?null:H;const ue=f[_];let ne;if(typeof ue=="number")return H===-1||ue-I<=H?(ne=ue-I,++_,I=0,ne):(I+=H,H);if(typeof ue=="string"){if(H===-1||Ae==="i"||e.strPosToUni(ue.slice(I))<=H)return ne=ue.slice(I),++_,I=0,ne;{const ae=I+e.uniToStrPos(ue.slice(I),H);return ne=ue.slice(I,ae),I=ae,ne}}else{if(H===-1||Ae==="d"||n.dlen(ue.d)-I<=H)return ne={d:W(ue.d,I)},++_,I=0,ne;{let ae=W(ue.d,I,I+H);return I+=H,{d:ae}}}},peek:()=>f[_]}},o=f=>(f.length>0&&typeof f[f.length-1]=="number"&&f.pop(),f);function c(f,_,I){if(I!=="left"&&I!=="right")throw Error("side ("+I+") must be 'left' or 'right'");t(f),t(_);const L=[],z=a(L),{take:H,peek:Ae}=O(f);for(let ne=0;ne<_.length;ne++){const ae=_[ne];let ge,De;switch(typeof ae){case"number":for(ge=ae;ge>0;)De=H(ge,"i"),z(De),typeof De!="string"&&(ge-=E(De));break;case"string":I==="left"&&typeof Ae()=="string"&&z(H(-1)),z(e.strPosToUni(ae));break;case"object":for(ge=n.dlen(ae.d);ge>0;)switch(De=H(ge,"i"),typeof De){case"number":ge-=De;break;case"string":z(De);break;case"object":ge-=n.dlen(De.d)}break}}let ue;for(;ue=H(-1);)z(ue);return o(L)}function h(f,_){t(f),t(_);const I=[],L=a(I),{take:z}=O(f);for(let Ae=0;Ae<_.length;Ae++){const ue=_[Ae];let ne,ae;switch(typeof ue){case"number":for(ne=ue;ne>0;)ae=z(ne,"d"),L(ae),typeof ae!="object"&&(ne-=E(ae));break;case"string":L(ue);break;case"object":ne=n.dlen(ue.d);let ge=0;for(;ge<ne;)switch(ae=z(ne-ge,"d"),typeof ae){case"number":L({d:W(ue.d,ge,ge+ae)}),ge+=ae;break;case"string":ge+=e.strPosToUni(ae);break;case"object":L(ae)}break}}let H;for(;H=z(-1);)L(H);return o(I)}const j=(f,_)=>{let I=0;for(let L=0;L<_.length&&f>I;L++){const z=_[L];switch(typeof z){case"number":{I+=z;break}case"string":const H=e.strPosToUni(z);I+=H,f+=H;break;case"object":f-=Math.min(n.dlen(z.d),f-I);break}}return f},Y=(f,_)=>typeof f=="number"?j(f,_):f.map(I=>j(I,_));function pe(f,_,I){return i(f,(L,z)=>typeof L=="object"&&typeof L.d=="number"?{d:I.slice(_,z,z+L.d)}:L)}function J(f){return i(f,_=>{switch(typeof _){case"object":if(typeof _.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return _.d;case"string":return{d:_};case"number":return _}})}function we(f){return i(f,_=>typeof _=="object"&&typeof _.d=="string"?{d:e.strPosToUni(_.d)}:_)}function xe(f){let _=!0;return s(f,I=>{typeof I=="object"&&typeof I.d=="number"&&(_=!1)}),_}function ve(f){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:o,normalize:l,checkOp:t,create(_=""){if(typeof _!="string")throw Error("Initial data must be a string");return f.create(_)},apply(_,I){t(I);const L=f.builder(_);for(let z=0;z<I.length;z++){const H=I[z];switch(typeof H){case"number":L.skip(H);break;case"string":L.append(H);break;case"object":L.del(n.dlen(H.d));break}}return L.build()},transform:c,compose:h,transformPosition:j,transformSelection:Y,isInvertible:xe,makeInvertible(_,I){return pe(_,I,f)},stripInvertible:we,invert:J,invertWithDoc(_,I){return J(pe(_,I,f))},isNoop:_=>_.length===0}}n.default=ve}(lt)),lt}var tt={},It;function Kt(){if(It)return tt;It=1,Object.defineProperty(tt,"__esModule",{value:!0});const n=ut(),e=_t();function t(s,i){return{get:s,getLength(){return s().length},insert(d,l,a){const E=e.strPosToUni(s(),d);return i([E,l],a)},remove(d,l,a){const E=e.strPosToUni(s(),d);return i([E,{d:l}],a)},_onOp(d){n.eachOp(d,(l,a,E)=>{switch(typeof l){case"string":this.onInsert&&this.onInsert(E,l);break;case"object":const W=n.dlen(l.d);this.onRemove&&this.onRemove(E,W)}})},onInsert:null,onRemove:null}}return tt.default=t,t.provides={text:!0},tt}var wt;function Ft(){return wt||(wt=1,function(n){var e=Ce&&Ce.__createBinding||(Object.create?function(c,h,j,Y){Y===void 0&&(Y=j),Object.defineProperty(c,Y,{enumerable:!0,get:function(){return h[j]}})}:function(c,h,j,Y){Y===void 0&&(Y=j),c[Y]=h[j]}),t=Ce&&Ce.__setModuleDefault||(Object.create?function(c,h){Object.defineProperty(c,"default",{enumerable:!0,value:h})}:function(c,h){c.default=h}),s=Ce&&Ce.__importStar||function(c){if(c&&c.__esModule)return c;var h={};if(c!=null)for(var j in c)Object.hasOwnProperty.call(c,j)&&e(h,c,j);return t(h,c),h},i=Ce&&Ce.__importDefault||function(c){return c&&c.__esModule?c:{default:c}};Object.defineProperty(n,"__esModule",{value:!0}),n.type=n.remove=n.insert=void 0;const d=_t(),l=s(ut()),a=i(Kt()),E={create(c){return c},toString(c){return c},builder(c){if(typeof c!="string")throw Error("Invalid document snapshot: "+c);const h=[];return{skip(j){let Y=d.uniToStrPos(c,j);if(Y>c.length)throw Error("The op is too long for this document");h.push(c.slice(0,Y)),c=c.slice(Y)},append(j){h.push(j)},del(j){c=c.slice(d.uniToStrPos(c,j))},build(){return h.join("")+c}}},slice:l.uniSlice},W=l.default(E),O=Object.assign(Object.assign({},W),{api:a.default});n.type=O,n.insert=(c,h)=>h.length===0?[]:c===0?[h]:[c,h],n.remove=(c,h)=>l.dlen(h)===0?[]:c===0?[{d:h}]:[c,{d:h}];var o=ut();Object.defineProperty(n,"makeType",{enumerable:!0,get:function(){return o.default}})}(ot)),ot}(function(n){var e=Ce&&Ce.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(n,"__esModule",{value:!0}),n.editOp=n.replaceOp=n.insertOp=n.moveOp=n.removeOp=n.type=void 0;const t=e(dt),s=e(ht),i=pt,d=gt;function l(r,u){if(!r)throw new Error(u)}n.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:i.readCursor,writeCursor:i.writeCursor,create:r=>r,isNoop:r=>r==null,setDebug(r){},registerSubtype:J,checkValidOp:z,normalize:H,apply:Ae,transformPosition:ue,compose:ne,tryTransform:it,transform:Tt,makeInvertible:De,invert:ae,invertWithDoc:Rt,RM_UNEXPECTED_CONTENT:d.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:d.ConflictType.DROP_COLLISION,BLACKHOLE:d.ConflictType.BLACKHOLE,transformNoConflict:(r,u,y)=>vt(()=>!0,r,u,y),typeAllowingConflictsPred:r=>Object.assign(Object.assign({},n.type),{transform:(u,y,A)=>vt(r,u,y,A)})};const a=r=>r?r.getComponent():null;function E(r){return r&&typeof r=="object"&&!Array.isArray(r)}const W=r=>Array.isArray(r)?r.slice():r!==null&&typeof r=="object"?Object.assign({},r):r,O=r=>r&&(r.p!=null||r.r!==void 0),o=r=>r&&(r.d!=null||r.i!==void 0);function c(r,u){return l(r!=null),typeof u=="number"?(l(Array.isArray(r),"Invalid key - child is not an array"),(r=r.slice()).splice(u,1)):(l(E(r),"Invalid key - child is not an object"),delete(r=Object.assign({},r))[u]),r}function h(r,u,y){return typeof u=="number"?(l(r!=null,"Container is missing for key"),l(Array.isArray(r),"Cannot use numerical key for object container"),l(r.length>=u,"Cannot insert into out of bounds index"),r.splice(u,0,y)):(l(E(r),"Cannot insert into missing item"),l(r[u]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),r[u]=y),y}n.removeOp=(r,u=!0)=>i.writeCursor().writeAtPath(r,"r",u).get(),n.moveOp=(r,u)=>i.writeCursor().writeMove(r,u).get(),n.insertOp=(r,u)=>i.writeCursor().writeAtPath(r,"i",u).get(),n.replaceOp=(r,u,y)=>i.writeCursor().at(r,A=>{A.write("r",u),A.write("i",y)}).get(),n.editOp=(r,u,y,A=!1)=>i.writeCursor().at(r,b=>_(b,u,y,A)).get();const j=(r,u)=>r!=null&&(typeof u=="number"?Array.isArray(r):typeof r=="object"),Y=(r,u)=>j(r,u)?r[u]:void 0,pe={};function J(r){let u=r.type?r.type:r;u.name&&(pe[u.name]=u),u.uri&&(pe[u.uri]=u)}const we=r=>{const u=pe[r];if(u)return u;throw Error("Missing type: "+r)};J(Ft());const xe=(r,u)=>r+u;J({name:"number",apply:xe,compose:xe,invert:r=>-r,transform:r=>r});const ve=r=>r==null?null:r.et?we(r.et):r.es?pe["text-unicode"]:r.ena!=null?pe.number:null,f=r=>r.es?r.es:r.ena!=null?r.ena:r.e,_=(r,u,y,A=!1)=>{const[b,C]=typeof u=="string"?[we(u),u]:[u,u.name];!A&&b.isNoop&&b.isNoop(y)||(C==="number"?r.write("ena",y):C==="text-unicode"?r.write("es",y):(r.write("et",C),r.write("e",y)))};function I(r){l(typeof r=="number"),l(r>=0),l(r===(0|r))}function L(r){typeof r=="number"?I(r):l(typeof r=="string")}function z(r){if(r===null)return;const u=new Set,y=new Set,A=C=>{let $=!0,T=!1;for(let p in C){const v=C[p];if($=!1,l(p==="p"||p==="r"||p==="d"||p==="i"||p==="e"||p==="es"||p==="ena"||p==="et","Invalid component item '"+p+"'"),p==="p")I(v),l(!u.has(v)),u.add(v),l(C.r===void 0);else if(p==="d")I(v),l(!y.has(v)),y.add(v),l(C.i===void 0);else if(p==="e"||p==="es"||p==="ena"){l(!T),T=!0;const m=ve(C);l(m,"Missing type in edit"),m.checkValidOp&&m.checkValidOp(f(C))}}l(!$)},b=(C,$,T)=>{if(!Array.isArray(C))throw Error("Op must be null or a list");if(C.length===0)throw Error("Empty descent");$||L(C[0]);let p=1,v=0,m=0;for(let w=0;w<C.length;w++){const k=C[w];if(l(k!=null),Array.isArray(k)){const G=b(k,!1);if(v){const g=typeof m,M=typeof G;g===M?l(m<G,"descent keys are not in order"):l(g==="number"&&M==="string")}m=G,v++,p=3}else typeof k=="object"?(l(p===1,`Prev not scalar - instead ${p}`),A(k),p=2):(l(p!==3),L(k),l(i.isValidPathItem(k),"Invalid path key"),p=1)}return l(v!==1,"Operation makes multiple descents. Remove some []"),l(p===2||p===3),C[0]};b(r,!0),l(u.size===y.size,"Mismatched picks and drops in op");for(let C=0;C<u.size;C++)l(u.has(C)),l(y.has(C))}function H(r){let u=0,y=[];const A=i.writeCursor();return A.mergeTree(r,(b,C)=>{const $=ve(b);if($){const p=f(b);_(C,$,$.normalize?$.normalize(p):p)}for(const p of["r","p","i","d"])if(b[p]!==void 0){const v=p==="p"||p==="d"?(T=b[p],y[T]==null&&(y[T]=u++),y[T]):b[p];C.write(p,v)}var T}),A.get()}function Ae(r,u){if(z(u),u===null)return r;const y=[];return function A(b,C){let $=b,T=0,p={root:b},v=0,m=p,w="root";function k(){for(;v<T;v++){let G=C[v];typeof G!="object"&&(l(j(m,w)),m=m[w]=W(m[w]),w=G)}}for(;T<C.length;T++){const G=C[T];if(Array.isArray(G)){const g=A($,G);g!==$&&g!==void 0&&(k(),$=m[w]=g)}else if(typeof G=="object"){G.d!=null?(k(),$=h(m,w,y[G.d])):G.i!==void 0&&(k(),$=h(m,w,G.i));const g=ve(G);if(g)k(),$=m[w]=g.apply($,f(G));else if(G.e!==void 0)throw Error("Subtype "+G.et+" undefined")}else $=Y($,G)}return p.root}(r=function A(b,C){const $=[];let T=0;for(;T<C.length;T++){const w=C[T];if(Array.isArray(w))break;typeof w!="object"&&($.push(b),b=Y(b,w))}for(let w=C.length-1;w>=T;w--)b=A(b,C[w]);for(--T;T>=0;T--){const w=C[T];if(typeof w!="object"){const k=$.pop();b=b===Y(k,w)?k:b===void 0?c(k,w):(v=w,m=b,(p=W(p=k))[v]=m,p)}else O(w)&&(l(b!==void 0,"Cannot pick up or remove undefined"),w.p!=null&&(y[w.p]=b),b=void 0)}var p,v,m;return b}(r,u),u)}function ue(r,u){r=r.slice(),z(u);const y=i.readCursor(u);let A,b,C=!1;const $=[];for(let p=0;;p++){const v=r[p],m=y.getComponent();if(m&&(m.r!==void 0?C=!0:m.p!=null&&(C=!1,A=m.p,b=p)),p>=r.length)break;let w=0;const k=i.advancer(y,void 0,(g,M)=>{O(M)&&w++});$.unshift(k);const G=k(v);if(typeof v=="number"&&(r[p]-=w),!G)break}if($.forEach(p=>p.end()),C)return null;const T=()=>{let p=0;if(A!=null){const v=y.getPath();p=v.length,r=v.concat(r.slice(b))}for(;p<r.length;p++){const v=r[p],m=a(y),w=ve(m);if(w){const g=f(m);w.transformPosition&&(r[p]=w.transformPosition(r[p],g));break}let k=0;const G=i.advancer(y,(g,M)=>o(M)?~(g-k):g-k,(g,M)=>{o(M)&&k++})(v);if(typeof v=="number"&&(r[p]+=k),!G)break}};return A!=null?y.eachDrop(null,p=>{p===A&&T()}):T(),r}function ne(r,u){if(z(r),z(u),r==null)return u;if(u==null)return r;let y=0;const A=i.readCursor(r),b=i.readCursor(u),C=i.writeCursor(),$=[],T=[],p=[],v=[],m=[],w=[],k=new Set;A.traverse(null,g=>{g.p!=null&&(p[g.p]=A.clone())}),b.traverse(null,g=>{g.d!=null&&(v[g.d]=b.clone())});const G=i.writeCursor();return function g(M,re,te,K,se,ke,be,_e){l(re||te);const oe=a(re),Pe=a(te),Ue=!!Pe&&Pe.r!==void 0,Le=!!oe&&oe.i!==void 0,Se=oe?oe.d:null,Ee=Pe?Pe.p:null,$e=(ke||Ue)&&Ee==null;if(Ee!=null)K=v[Ee],be=T[Ee]=new i.WriteCursor;else if(Pe&&Pe.r!==void 0)K=null;else{const P=a(K);P&&P.d!=null&&(K=null)}const Q=a(K);if(Se!=null)if(M=p[Se],_e=$[Se]=new i.WriteCursor,$e)ke&&!Ue&&_e.write("r",!0);else{const P=m[Se]=y++;be.write("d",P)}else if(oe&&oe.i!==void 0)M=null;else{const P=a(M);P&&P.p!=null&&(M=null)}let S;Le?(l(se===void 0),S=oe.i):S=se;const B=(Ee==null?!Le||ke||Ue:S===void 0)?null:be.getComponent();if(Ee!=null){if(!(se!==void 0||Le)){const P=Se!=null?m[Se]:y++;w[Ee]=P,_e.write("p",P)}}else Ue&&(Le||se!==void 0||(Pe.r,_e.write("r",Pe.r)));const U=$e?null:ve(oe),D=ve(Q);if((U||D)&&(U&&U.name,D&&D.name),U&&D){l(U===D);const P=f(oe),x=f(Q),he=U.compose(P,x);_(be,U,he),k.add(Q)}else U?_(be,U,f(oe)):D&&(_(be,D,f(Q)),k.add(Q));const N=typeof S=="object"&&S!=null;let X=!1,Z=0,ee=0,fe=0,de=0,le=0;const ye=i.advancer(K,(P,x)=>o(x)?de-P-1:P-de,(P,x)=>{o(x)&&de++}),V=i.advancer(M,(P,x)=>O(x)?Z-P-1:P-Z,(P,x)=>{O(x)&&Z++});if(i.eachChildOf(re,te,(P,x,he)=>{let me,We,He=P,Me=P,Ye=P;if(typeof P=="number"){let Oe=P+fe;We=ye(Oe),Me=Oe+de;let ce=P+ee;me=V(ce),o(a(We))&&(me=null),He=ce+Z,Ye=P+le,l(He>=0,"p1PickKey is negative"),l(Me>=0,"p2DropKey is negative");const Ne=o(a(x)),Ge=O(a(he));(Ne||Ge&&!$e)&&le--,Ne&&ee--,Ge&&fe--}else me=V(P),We=ye(P);_e.descend(He),be.descend(Me);const ze=N&&!o(a(x))?S[Ye]:void 0,Re=g(me,x,he,We,ze,$e,be,_e);var Te,R,ie;N&&!$e?ze!==Re&&(X||(S=Array.isArray(S)?S.slice():Object.assign({},S),X=!0),Te=S,ie=Re,typeof(R=Ye)=="number"?(l(Array.isArray(Te)),l(R<Te.length)):(l(!Array.isArray(Te)),l(Te[R]!==void 0)),ie===void 0?typeof R=="number"?Te.splice(R,1):delete Te[R]:Te[R]=ie):l(Re===void 0),be.ascend(),_e.ascend()}),V.end(),ye.end(),B!=null)B.i=S;else if(!ke&&!Ue&&Ee==null)return S}(A,A.clone(),b,b.clone(),void 0,!1,C,G),C.reset(),C.mergeTree(G.get()),C.reset(),C.get(),$.map(g=>g.get()),T.map(g=>g.get()),A.traverse(C,(g,M)=>{const re=g.p;if(re!=null){const te=m[re];te!=null&&M.write("p",te);const K=$[re];K&&K.get(),K&&M.mergeTree(K.get())}else g.r!==void 0&&M.write("r",g.r)}),C.reset(),C.get(),b.traverse(C,(g,M)=>{const re=g.d;if(re!=null){const K=w[re];K!=null&&M.write("d",K);const se=T[re];se&&M.mergeTree(se.get())}else g.i!==void 0&&M.write("i",g.i);const te=ve(g);te&&!k.has(g)&&_(M,te,f(g))}),C.get()}function ae(r){if(r==null)return null;const u=new i.ReadCursor(r),y=new i.WriteCursor;let A;const b=[],C=[];return function $(T,p,v){const m=T.getComponent();let w,k=!1;if(m){m.p!=null&&(p.write("d",m.p),b[m.p]=T.clone()),m.r!==void 0&&p.write("i",m.r),m.d!=null&&(p.write("p",m.d),v=void 0),m.i!==void 0&&(v=w=m.i);const g=ve(m);g&&(v===void 0?(A||(A=new Set),A.add(m)):(f(m),v=g.apply(v,f(m)),k=!0))}let G=0;for(const g of T){p.descend(g);const M=typeof g=="number"?g-G:g,re=Y(v,M);o(T.getComponent())&&G++;const te=$(T,p,re);if(v!==void 0&&te!==void 0){if(k||(k=!0,v=W(v)),!j(v,M))throw Error("Cannot modify child - invalid operation");v[M]=te}p.ascend()}if(w===void 0)return k?v:void 0;p.write("r",v)}(u,y,void 0),A&&(y.reset(),function $(T,p,v){const m=p.getComponent();if(m){const g=m.d;if(g!=null&&(T=b[g],v=C[g]=i.writeCursor()),A.has(m)){const M=ve(m);if(!M.invert)throw Error(`Cannot invert subtype ${M.name}`);_(v,M,M.invert(f(m)))}}let w=0,k=0;const G=i.advancer(T,(g,M)=>O(M)?w-g-1:g-w,(g,M)=>{O(M)&&w++});for(const g of p)if(typeof g=="number"){const M=g-k,re=G(M),te=M+w;v.descend(te),$(re,p,v),o(p.getComponent())&&k++,v.ascend()}else v.descend(g),$(G(g),p,v),v.ascend();G.end()}(u.clone(),u,y),C.length&&(y.reset(),u.traverse(y,($,T)=>{const p=$.p;if(p!=null){const v=C[p];v&&v.get(),v&&T.mergeTree(v.get())}}))),y.get()}const ge=(r,u)=>r.some(y=>typeof y=="object"&&(Array.isArray(y)?ge(y,u):u(y)));function De(r,u){if(r==null||!ge(r,p=>{var v;return p.r!==void 0||((v=ve(p))===null||v===void 0?void 0:v.makeInvertible)!=null}))return r;const y=new i.ReadCursor(r),A=new i.WriteCursor;let b=!1;const C=[],$=[],T=(p,v,m)=>{const w=p.getComponent();let k=!1;if(w){w.d!=null&&v.write("d",w.d),w.i!==void 0&&v.write("i",w.i);const g=w.p;if(g!=null&&(C[g]=p.clone(),l(m!==void 0,"Operation picks up at an invalid key"),$[g]=m,v.write("p",w.p)),w.r!==void 0&&m===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const M=ve(w);M&&(M.makeInvertible?b=!0:_(v,M,f(w),!0))}let G=0;for(const g of p){v.descend(g);const M=typeof g=="number"?g-G:g,re=Y(m,M),te=T(p,v,re);re!==te&&(k||(k=!0,m=W(m)),te===void 0?(m=c(m,M),typeof g=="number"&&G++):m[M]=te),v.ascend()}return w&&(w.r!==void 0?(v.write("r",s.default(m)),m=void 0):w.p!=null&&(m=void 0)),m};return T(y,A,u),A.get(),b&&(A.reset(),function p(v,m,w,k,G){const g=m.getComponent();if(g){g.i!==void 0?(k=g.i,G=!0):g.d!=null&&(k=$[g.d],v=C[g.d],G=!1,g.d);let K=ve(g);if(K&&K.makeInvertible){const se=f(g);_(w,K,K.makeInvertible(se,k),!0)}}let M=0,re=0;const te=i.advancer(v,(K,se)=>O(se)?M-K-1:K-M,(K,se)=>{O(se)&&M++});for(const K of m)if(typeof K=="number"){const se=K-re,ke=te(se),be=se+M,_e=Y(k,G?se:be);w.descend(K),p(ke,m,w,_e,G),o(m.getComponent())&&re++,w.ascend()}else{const se=Y(k,K);w.descend(K),p(te(K),m,w,se,G),w.ascend()}te.end()}(y.clone(),y,A,u,!1)),A.get()}function Rt(r,u){return ae(De(r,u))}const rt=r=>{if(r==null)return null;const u=r.slice();for(let y=0;y<r.length;y++){const A=u[y];Array.isArray(A)&&(u[y]=rt(A))}return u};function it(r,u,y){l(y==="left"||y==="right","Direction must be left or right");const A=y==="left"?0:1;if(u==null)return{ok:!0,result:r};z(r),z(u);let b=null;const C=[],$=[],T=[],p=[],v=[],m=[],w=[],k=[],G=[],g=[],M=[],re=[],te=[],K=[],se=[];let ke=0;const be=i.readCursor(r),_e=i.readCursor(u),oe=i.writeCursor();if(function Q(S,B=null,U){const D=a(B);D&&(D.r!==void 0?U=B.clone():D.p!=null&&(U=null,m[D.p]=S.clone()));const N=S.getComponent();let X;N&&(X=N.p)!=null&&(v[X]=B?B.clone():null,T[X]=S.clone(),U&&(g[X]=!0,G[X]=U),D&&D.p!=null&&(K[X]=D.p));const Z=i.advancer(B);for(const ee of S)Q(S,Z(ee),U);Z.end()}(_e,be,null),function Q(S,B,U,D,N){const X=U.getComponent();let Z,ee=!1;X&&((Z=X.d)!=null?(p[Z]=U.clone(),D!=null&&(se[D]==null&&(se[D]=[]),se[D].push(Z)),S=v[Z]||null,B=T[Z]||null,g[Z]?(N&&(M[Z]=!0),N=G[Z]||null):!N||A!==1&&K[Z]!=null||b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.moveOp(B.getPath(),U.getPath())}),ee=!0):X.i!==void 0&&(S=B=null,ee=!0,N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.insertOp(U.getPath(),X.i)})));const fe=a(S);fe&&(fe.r!==void 0?N=S.clone():fe.p!=null&&(fe.p,D=fe.p,N=null));const de=ve(X);de&&N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.editOp(U.getPath(),de,f(X),!0)});let le=0,ye=0;const V=i.advancer(B,(x,he)=>O(he)?le-x-1:x-le,(x,he)=>{O(he)&&le++}),P=i.advancer(S);for(const x of U)if(typeof x=="number"){const he=x-ye,me=V(he);ye+=+Q(P(he+le),me,U,D,N)}else{const he=V(x);Q(P(x),he,U,D,N)}return V.end(),P.end(),ee}(be,_e,_e.clone(),null,null),p.map(Q=>Q&&Q.get()),b)return{ok:!1,conflict:b};M.map(Q=>!!Q);const Pe=[];let Ue=null;(function Q(S,B,U,D,N){let X=!1;const Z=a(B);if(O(Z)){const V=Z.p;V!=null?(U=p[V],D=re[V]=i.writeCursor(),X=!0,N=null):(U=null,N=B.clone())}else o(a(U))&&(U=null);const ee=S.getComponent();if(ee){const V=ee.p;V!=null?(N&&(k[V]=N),Pe[V]=N||A===1&&X?null:D.getComponent(),C[V]=S.clone(),U&&(w[V]=U.clone())):ee.r!==void 0&&(N||D.write("r",!0),(N||X)&&(Ue==null&&(Ue=new Set),Ue.add(ee)))}let fe=0,de=0;const le=i.advancer(B,void 0,(V,P)=>{O(P)&&fe++}),ye=i.advancer(U,(V,P)=>o(P)?~(V-de):V-de,(V,P)=>{o(P)&&de++});if(S)for(const V of S)if(typeof V=="string"){const P=le(V),x=ye(V);D.descend(V),Q(S,P,x,D,N),D.ascend()}else{const P=le(V),x=V-fe,he=O(a(P))?null:ye(x),me=x+de;l(me>=0),D.descend(me),Q(S,P,he,D,N),D.ascend()}le.end(),ye.end()})(be,_e,_e.clone(),oe,null),oe.reset();let Le=[];if(function Q(S,B,U,D,N,X){l(B);const Z=B.getComponent();let ee=a(D),fe=!1;const de=(R,ie,Oe)=>R?n.moveOp(R.getPath(),ie.getPath()):n.insertOp(ie.getPath(),Oe.i);if(o(Z)){const R=Z.d;R!=null&&($[R]=B.clone());const ie=R!=null?Pe[R]:null;let Oe=!1;if(Z.i!==void 0||R!=null&&ie){let ce;ee&&(ee.i!==void 0||(ce=ee.d)!=null&&!g[ce])&&(Oe=ce!=null?R!=null&&R===K[ce]:t.default(ee.i,Z.i),Oe||ce!=null&&A!==1&&K[ce]!=null||b==null&&(b={type:d.ConflictType.DROP_COLLISION,op1:de(R!=null?C[R]:null,B,Z),op2:de(ce!=null?T[ce]:null,D,ee)})),Oe||(X?b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:de(R!=null?C[R]:null,B,Z),op2:n.removeOp(X.getPath())}):(R!=null?(Le[ke]=R,N.write("d",ie.p=ke++)):N.write("i",s.default(Z.i)),fe=!0))}else if(R!=null&&!ie){const ce=k[R];ce&&(X=ce.clone())}R!=null?(S=C[R],U=m[R],D=w[R]):Z.i!==void 0&&(S=U=null,Oe||(D=null))}else O(a(S))&&(S=U=D=null);const le=a(S),ye=a(U);if(O(ye)){const R=ye.p;ye.r!==void 0&&(!le||le.r===void 0)||g[R]?(D=null,X=U.clone()):R!=null&&(D=p[R],A!==1&&K[R]!=null||((N=te[R])||(N=te[R]=i.writeCursor()),N.reset(),X=null))}else!o(Z)&&o(ee)&&(D=null);ee=D!=null?D.getComponent():null;const V=ve(Z);if(V){const R=f(Z);if(X)b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.editOp(B.getPath(),V,R,!0),op2:n.removeOp(X.getPath())});else{const ie=ve(ee);let Oe;if(ie){if(V!==ie)throw Error("Transforming incompatible types");const ce=f(ee);Oe=V.transform(R,ce,y)}else Oe=s.default(R);_(N,V,Oe)}}let P=0,x=0,he=0,me=0,We=0,He=0,Me=S!=null&&S.descendFirst(),Ye=Me;const ze=i.advancer(U,void 0,(R,ie)=>{O(ie)&&he++});let Re=D!=null&&D.descendFirst(),Te=Re;for(const R of B)if(typeof R=="number"){let ie;const Oe=o(B.getComponent()),ce=R-x;{let Be;for(;Me&&typeof(Be=S.getKey())=="number";){Be+=P;const je=S.getComponent(),Xe=O(je);if(Be>ce||Be===ce&&(!Xe||A===0&&Oe))break;if(Xe){P--;const Ke=je.p;K.includes(Ke),je.d,a(te[je.d]),O(a(te[je.d])),(je.r===void 0||Ue&&Ue.has(je))&&(Ke==null||!Pe[Ke]||A!==1&&K.includes(Ke))||We--}Me=S.nextSibling()}ie=Me&&Be===ce?S:null}const Ne=ce-P;let Ge=ze(Ne);const st=Ne-he;let et=null;{let Be,je;for(;Re&&typeof(Be=D.getKey())=="number";){je=Be-me;const Xe=D.getComponent(),Ke=o(Xe);if(je>st)break;if(je===st){if(!Ke){et=D;break}{if(A===0&&Oe){et=D;break}const Fe=Ge&&O(Ge.getComponent());if(A===0&&Fe)break}}if(Ke){const Fe=Xe.d;K[Fe],Xe.i===void 0&&(g[Fe]||K[Fe]!=null&&A!==1)?(g[Fe]||K[Fe]!=null&&A===0)&&(me++,He--):me++}Re=D.nextSibling()}}const yt=st+me+We+He;l(yt>=0,"trying to descend to a negative index"),N.descend(yt),Oe&&(ie=Ge=et=null,x++),Q(ie,B,Ge,et,N,X)&&He++,N.ascend()}else{let ie;for(;Me&&(ie=S.getKey(),typeof ie!="string"||!(ie>R||ie===R));)Me=S.nextSibling();const Oe=Me&&ie===R?S:null,ce=ze(R);let Ne;for(;Re&&(Ne=D.getKey(),typeof Ne!="string"||!(Ne>R||Ne===R));)Re=D.nextSibling();const Ge=Re&&Ne===R?D:null;N.descend(R),Q(Oe,B,ce,Ge,N,X),N.ascend()}return ze.end(),Ye&&S.ascend(),Te&&D.ascend(),fe}(be,be.clone(),_e,_e.clone(),oe,null),b)return{ok:!1,conflict:b};oe.reset();const Se=(Q,S,B)=>Q.traverse(S,(U,D)=>{U.d!=null&&B(U.d,Q,D)});(g.length||re.length)&&(Se(_e,oe,(Q,S,B)=>{g[Q]&&!M[Q]&&B.write("r",!0),re[Q]&&B.mergeTree(re[Q].get())}),oe.reset());const Ee=[],$e=[];if((te.length||g.length)&&!b){const Q=i.readCursor(rt(oe.get()));if(Se(Q,null,(S,B)=>{Ee[S]=B.clone()}),te.forEach(S=>{S&&Se(i.readCursor(S.get()),null,(B,U)=>{Ee[B]=U.clone()})}),function S(B,U,D,N,X,Z){const ee=a(U);if(ee&&O(ee))if(ee.p!=null){const P=ee.p;Ee[P].getPath(),D=Ee[P],N=$e[P]=i.writeCursor()}else ee.r!==void 0&&(D=null);else o(a(D))&&(D=null);const fe=B.getComponent();if(fe){let P;if((P=fe.d)!=null){const x=te[P];x&&(x.get(),N.mergeTree(x.get()),D=i.readCursor(x.get()))}}let de=0,le=0;const ye=i.advancer(U,void 0,(P,x)=>{O(x)&&de--}),V=i.advancer(D,(P,x)=>o(x)?-(P-le)-1:P-le,(P,x)=>{o(x)&&le++});for(const P of B)if(typeof P=="number"){const x=ye(P),he=P+de,me=V(he),We=he+le;N.descend(We),S(B,x,me,N),N.ascend()}else N.descend(P),S(B,ye(P),V(P),N),N.ascend();ye.end(),V.end()}(_e,Q,Q.clone(),oe),oe.reset(),b)return{ok:!1,conflict:b};if(oe.get(),$e.length){const S=$e.map(U=>U?U.get():null),B=i.readCursor(rt(oe.get()));if(Se(B,oe,(U,D,N)=>{const X=S[U];X&&(N.mergeTree(X),S[U]=null)}),S.find(U=>U)){const U=i.writeCursor(),D=i.writeCursor();let N=0,X=0;S.forEach(Z=>{Z!=null&&Se(i.readCursor(Z),null,ee=>{const fe=Le[ee];U.writeMove(C[fe].getPath(),$[fe].getPath(),N++);const de=se[fe];de&&de.forEach(le=>{g[le]||A!==1&&K[le]!=null||D.writeMove(T[le].getPath(),p[le].getPath(),X++)})})}),b={type:d.ConflictType.BLACKHOLE,op1:U.get(),op2:D.get()}}}}return b?{ok:!1,conflict:b}:{ok:!0,result:oe.get()}}const Ot=r=>{const u=new Error("Transform detected write conflict");throw u.conflict=r,u.type=u.name="writeConflict",u};function Tt(r,u,y){const A=it(r,u,y);if(A.ok)return A.result;Ot(A.conflict)}const qe=r=>{const u=i.writeCursor();return i.readCursor(r).traverse(u,(y,A)=>{(o(y)||ve(y))&&A.write("r",!0)}),u.get()},kt=(r,u)=>{const{type:y,op1:A,op2:b}=r;switch(y){case d.ConflictType.DROP_COLLISION:return u==="left"?[null,qe(b)]:[qe(A),null];case d.ConflictType.RM_UNEXPECTED_CONTENT:let C=!1;return i.readCursor(A).traverse(null,$=>{$.r!==void 0&&(C=!0)}),C?[null,qe(b)]:[qe(A),null];case d.ConflictType.BLACKHOLE:return[qe(A),qe(b)];default:throw Error("Unrecognised conflict: "+y)}};function vt(r,u,y,A){let b=null;for(;;){const C=it(u,y,A);if(C.ok)return ne(b,C.result);{const{conflict:$}=C;r($)||Ot($);const[T,p]=kt($,A);u=ne(H(u),T),y=ne(H(y),p),b=ne(b,p)}}}})(At);(function(n){var e=Ce&&Ce.__createBinding||(Object.create?function(d,l,a,E){E===void 0&&(E=a),Object.defineProperty(d,E,{enumerable:!0,get:function(){return l[a]}})}:function(d,l,a,E){E===void 0&&(E=a),d[E]=l[a]}),t=Ce&&Ce.__exportStar||function(d,l){for(var a in d)a!=="default"&&!l.hasOwnProperty(a)&&e(l,d,a)};Object.defineProperty(n,"__esModule",{value:!0}),t(At,n);var s=pt;Object.defineProperty(n,"ReadCursor",{enumerable:!0,get:function(){return s.ReadCursor}}),Object.defineProperty(n,"WriteCursor",{enumerable:!0,get:function(){return s.WriteCursor}});var i=gt;Object.defineProperty(n,"ConflictType",{enumerable:!0,get:function(){return i.ConflictType}})})(F);class Dt{constructor(){q(this,"drawingManagerData",{});q(this,"_oldDrawingManagerData",{});q(this,"_focusDrawings",[]);q(this,"_remove$",new Ie.Subject);q(this,"remove$",this._remove$.asObservable());q(this,"_add$",new Ie.Subject);q(this,"add$",this._add$.asObservable());q(this,"_update$",new Ie.Subject);q(this,"update$",this._update$.asObservable());q(this,"_order$",new Ie.Subject);q(this,"order$",this._order$.asObservable());q(this,"_group$",new Ie.Subject);q(this,"group$",this._group$.asObservable());q(this,"_ungroup$",new Ie.Subject);q(this,"ungroup$",this._ungroup$.asObservable());q(this,"_refreshTransform$",new Ie.Subject);q(this,"refreshTransform$",this._refreshTransform$.asObservable());q(this,"_visible$",new Ie.Subject);q(this,"visible$",this._visible$.asObservable());q(this,"_focus$",new Ie.Subject);q(this,"focus$",this._focus$.asObservable());q(this,"_featurePluginUpdate$",new Ie.Subject);q(this,"featurePluginUpdate$",this._featurePluginUpdate$.asObservable());q(this,"_featurePluginAdd$",new Ie.Subject);q(this,"featurePluginAdd$",this._featurePluginAdd$.asObservable());q(this,"_featurePluginRemove$",new Ie.Subject);q(this,"featurePluginRemove$",this._featurePluginRemove$.asObservable());q(this,"_featurePluginOrderUpdate$",new Ie.Subject);q(this,"featurePluginOrderUpdate$",this._featurePluginOrderUpdate$.asObservable());q(this,"_featurePluginGroupUpdate$",new Ie.Subject);q(this,"featurePluginGroupUpdate$",this._featurePluginGroupUpdate$.asObservable());q(this,"_featurePluginUngroupUpdate$",new Ie.Subject);q(this,"featurePluginUngroupUpdate$",this._featurePluginUngroupUpdate$.asObservable())}dispose(){this._remove$.complete(),this._add$.complete(),this._update$.complete(),this._order$.complete(),this._focus$.complete(),this._featurePluginUpdate$.complete(),this._featurePluginAdd$.complete(),this._featurePluginRemove$.complete(),this._featurePluginOrderUpdate$.complete(),this.drawingManagerData={},this._oldDrawingManagerData={}}visibleNotification(e){this._visible$.next(e)}refreshTransform(e){e.forEach(t=>{if(this.getDrawingByParam(t)==null)return;const i=this._getCurrentBySearch(t);i!=null&&(i.transform=t.transform)}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return this.drawingManagerData[e]}removeDrawingDataForUnit(e){const t=this.drawingManagerData[e];if(t==null)return;delete this.drawingManagerData[e];const s=[];Object.keys(t).forEach(i=>{const d=t[i];(d==null?void 0:d.data)!=null&&Object.keys(d.data).forEach(l=>{s.push({unitId:e,subUnitId:i,drawingId:l})})}),s.length>0&&this.removeNotification(s)}registerDrawingData(e,t){this.drawingManagerData[e]=t;const s=[];Object.keys(t).forEach(i=>{this._establishDrawingMap(e,i);const d=t[i];Object.keys(d.data).forEach(l=>{const a=d.data[l];s.push(a)})}),s.length>0&&this.addNotification(s)}getDrawingData(e,t){return this._getDrawingData(e,t)}getBatchAddOp(e){const t=[],s=[],i=[];e.forEach(W=>{const{op:O,invertOp:o}=this._addByParam(W);t.push({unitId:W.unitId,subUnitId:W.subUnitId,drawingId:W.drawingId}),s.push(O),i.push(o)});const d=s.reduce(F.type.compose,null),l=i.reduce(F.type.compose,null),{unitId:a,subUnitId:E}=e[0];return{undo:l,redo:d,unitId:a,subUnitId:E,objects:t}}getBatchRemoveOp(e){const t=[],s=[];e.forEach(E=>{const{op:W,invertOp:O}=this._removeByParam(E);t.push(W),s.push(O)});const i=t.reduce(F.type.compose,null),d=s.reduce(F.type.compose,null),{unitId:l,subUnitId:a}=e[0];return{undo:d,redo:i,unitId:l,subUnitId:a,objects:e}}getBatchUpdateOp(e){const t=[],s=[],i=[];e.forEach(W=>{const{op:O,invertOp:o}=this._updateByParam(W);t.push({unitId:W.unitId,subUnitId:W.subUnitId,drawingId:W.drawingId}),s.push(O),i.push(o)});const d=s.reduce(F.type.compose,null),l=i.reduce(F.type.compose,null),{unitId:a,subUnitId:E}=e[0];return{undo:l,redo:d,unitId:a,subUnitId:E,objects:t}}removeNotification(e){this._remove$.next(e)}addNotification(e){this._add$.next(e)}updateNotification(e){this._update$.next(e)}orderNotification(e){this._order$.next(e)}groupUpdateNotification(e){this._group$.next(e)}ungroupUpdateNotification(e){this._ungroup$.next(e)}refreshTransformNotification(e){this._refreshTransform$.next(e)}getGroupDrawingOp(e){const t=[],{unitId:s,subUnitId:i}=e[0].parent;e.forEach(a=>{t.push(this._getGroupDrawingOp(a))});const d=t.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:s,subUnitId:i,objects:e}}getUngroupDrawingOp(e){const t=[],{unitId:s,subUnitId:i}=e[0].parent;e.forEach(a=>{t.push(this._getUngroupDrawingOp(a))});const d=t.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:s,subUnitId:i,objects:e}}getDrawingsByGroup(e){const{unitId:t,subUnitId:s,drawingId:i}=e;if(this.getDrawingByParam({unitId:t,subUnitId:s,drawingId:i})==null)return[];const l=this._getDrawingData(t,s),a=[];return Object.keys(l).forEach(E=>{const W=l[E];W.groupId===i&&a.push(W)}),a}_getGroupDrawingOp(e){const{parent:t,children:s}=e,{unitId:i,subUnitId:d,drawingId:l}=t,a=[];a.push(F.insertOp([i,d,"data",l],t));let E=Number.NEGATIVE_INFINITY;return s.forEach(W=>{const{unitId:O,subUnitId:o,drawingId:c}=W,h=this._hasDrawingOrder({unitId:O,subUnitId:o,drawingId:c});E=Math.max(E,h),a.push(...this._getUpdateParamCompareOp(W,this.getDrawingByParam({unitId:O,subUnitId:o,drawingId:c})))}),E===Number.NEGATIVE_INFINITY&&(E=this._getDrawingOrder(i,d).length),a.push(F.insertOp([i,d,"order",E],l)),a.reduce(F.type.compose,null)}_getUngroupDrawingOp(e){const{parent:t,children:s}=e,{unitId:i,subUnitId:d,drawingId:l}=t,a=[];return s.forEach(E=>{const{unitId:W,subUnitId:O,drawingId:o}=E;a.push(...this._getUpdateParamCompareOp(E,this.getDrawingByParam({unitId:W,subUnitId:O,drawingId:o})))}),a.push(F.removeOp([i,d,"data",l],!0)),a.push(F.removeOp([i,d,"order",this._getDrawingOrder(i,d).indexOf(l)],!0)),a.reduce(F.type.compose,null)}applyJson1(e,t,s){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=F.type.apply(this.drawingManagerData,s)}featurePluginUpdateNotification(e){this._featurePluginUpdate$.next(e)}featurePluginOrderUpdateNotification(e){this._featurePluginOrderUpdate$.next(e)}featurePluginAddNotification(e){this._featurePluginAdd$.next(e)}featurePluginRemoveNotification(e){this._featurePluginRemove$.next(e)}featurePluginGroupUpdateNotification(e){this._featurePluginGroupUpdate$.next(e)}featurePluginUngroupUpdateNotification(e){this._featurePluginUngroupUpdate$.next(e)}getDrawingByParam(e){return this._getCurrentBySearch(e)}getOldDrawingByParam(e){return this._getOldBySearch(e)}getDrawingOKey(e){const[t,s,i]=e.split("#-#");return this._getCurrentBySearch({unitId:t,subUnitId:s,drawingId:i})}focusDrawing(e){if(e==null){this._focusDrawings=[],this._focus$.next([]);return}const t=[];e.forEach(s=>{var E;const{unitId:i,subUnitId:d,drawingId:l}=s,a=(E=this._getDrawingData(i,d))==null?void 0:E[l];a!=null&&t.push(a)}),t.length>0&&(this._focusDrawings=t,this._focus$.next(t))}getFocusDrawings(){const e=[];return this._focusDrawings.forEach(t=>{var a;const{unitId:s,subUnitId:i,drawingId:d}=t,l=(a=this._getDrawingData(s,i))==null?void 0:a[d];l!=null&&e.push(l)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){const{unitId:t,subUnitId:s,drawingIds:i}=e,d=[],l=this.getDrawingOrder(t,s),a=[...i];i.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:s,drawingId:O});if(o===-1||o===l.length-1)return;const c=F.moveOp([t,s,"order",o],[t,s,"order",o+1]);d.push(c),a.includes(l[o+1])||a.push(l[o+1])});const E=d.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:s,objects:{...e,drawingIds:a}}}getBackwardDrawingOp(e){const{unitId:t,subUnitId:s,drawingIds:i}=e,d=[],l=this.getDrawingOrder(t,s),a=[...i];i.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:s,drawingId:O});if(o===-1||o===0)return;const c=F.moveOp([t,s,"order",o],[t,s,"order",o-1]);d.push(c),a.includes(l[o-1])||a.push(l[o-1])});const E=d.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:s,objects:{...e,drawingIds:a}}}getFrontDrawingsOp(e){const{unitId:t,subUnitId:s,drawingIds:i}=e,d=this._getOrderFromSearchParams(t,s,i),l=[...i],a=this.getDrawingOrder(t,s),E=[];d.forEach(o=>{const{drawingId:c}=o,h=this._getDrawingCount(t,s)-1,j=F.moveOp([t,s,"order",this._getDrawingOrder(t,s).indexOf(c)],[t,s,"order",h]);E.push(j),l.includes(a[h])||l.push(a[h])});const W=E.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(W,this.drawingManagerData),redo:W,unitId:t,subUnitId:s,objects:{...e,drawingIds:l}}}getBackDrawingsOp(e){const{unitId:t,subUnitId:s,drawingIds:i}=e,d=this._getOrderFromSearchParams(t,s,i,!0),l=[...i],a=this.getDrawingOrder(t,s),E=[];d.forEach(o=>{const{drawingId:c}=o,h=F.moveOp([t,s,"order",this._getDrawingOrder(t,s).indexOf(c)],[t,s,"order",0]);E.push(h),l.includes(a[0])||l.push(a[0])});const W=E.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(W,this.drawingManagerData),redo:W,unitId:t,subUnitId:s,objects:{...e,drawingIds:l}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,t,s,i=!1){return s.map(d=>{const l=this._hasDrawingOrder({unitId:e,subUnitId:t,drawingId:d});return{drawingId:d,zIndex:l}}).sort(i===!1?Qe.sortRules:Qe.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;const{unitId:t,subUnitId:s,drawingId:i}=e;return this._establishDrawingMap(t,s),this._getDrawingOrder(t,s).indexOf(i)}_getCurrentBySearch(e){var d,l,a;if(e==null)return;const{unitId:t,subUnitId:s,drawingId:i}=e;return(a=(l=(d=this.drawingManagerData[t])==null?void 0:d[s])==null?void 0:l.data)==null?void 0:a[i]}_getOldBySearch(e){var d,l,a;if(e==null)return;const{unitId:t,subUnitId:s,drawingId:i}=e;return(a=(l=(d=this._oldDrawingManagerData[t])==null?void 0:d[s])==null?void 0:l.data)==null?void 0:a[i]}_establishDrawingMap(e,t,s){var i;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),s==null?null:(i=this.drawingManagerData[e][t].data)==null?void 0:i[s]}_addByParam(e){const{unitId:t,subUnitId:s,drawingId:i}=e;this._establishDrawingMap(t,s,i);const d=F.insertOp([t,s,"data",i],e),l=F.insertOp([t,s,"order",this._getDrawingOrder(t,s).length],i),a=[d,l].reduce(F.type.compose,null),E=F.type.invertWithDoc(a,this.drawingManagerData);return{op:a,invertOp:E}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};const{unitId:t,subUnitId:s,drawingId:i}=e;if(this._establishDrawingMap(t,s,i)==null)return{op:[],invertOp:[]};const l=F.removeOp([t,s,"data",i],!0),a=F.removeOp([t,s,"order",this._getDrawingOrder(t,s).indexOf(i)],!0),E=[l,a].reduce(F.type.compose,null),W=F.type.invertWithDoc(E,this.drawingManagerData);return{op:E,invertOp:W}}_updateByParam(e){const{unitId:t,subUnitId:s,drawingId:i}=e,d=this._establishDrawingMap(t,s,i);if(d==null)return{op:[],invertOp:[]};const a=this._getUpdateParamCompareOp(e,d).reduce(F.type.compose,null),E=F.type.invertWithDoc(a,this.drawingManagerData);return{op:a,invertOp:E}}_getUpdateParamCompareOp(e,t){const{unitId:s,subUnitId:i,drawingId:d}=e,l=[];return Object.keys(e).forEach(a=>{const E=e[a],W=t[a];W!==E&&l.push(F.replaceOp([s,i,"data",d,a],W,E))}),l}_getDrawingData(e,t){var s,i;return((i=(s=this.drawingManagerData[e])==null?void 0:s[t])==null?void 0:i.data)||{}}_getDrawingOrder(e,t){var s,i;return((i=(s=this.drawingManagerData[e])==null?void 0:s[t])==null?void 0:i.order)||[]}}class Pt extends Dt{}function Vt(n){const{unitId:e,subUnitId:t,drawingId:s}=n;return`${e}#-#${t}#-#${s}`}const qt=async n=>new Promise((e,t)=>{const s=new Image;s.src=n,s.onload=()=>{e({width:s.width,height:s.height,image:s})},s.onerror=i=>{t(i)}});var Je=(n=>(n.URL="URL",n.UUID="UUID",n.BASE64="BASE64",n))(Je||{}),Ze=(n=>(n.SUCCUSS="0",n.ERROR_EXCEED_SIZE="1",n.ERROR_IMAGE_TYPE="2",n.ERROR_UPLOAD_COUNT_LIMIT="3",n.ERROR_IMAGE="4",n))(Ze||{});const St=nt.createIdentifier("core.image-io.service");class Ut{constructor(){q(this,"_waitCount",0);q(this,"_change$",new Ie.Subject);q(this,"change$",this._change$);q(this,"_imageSourceCache",new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,t){if(t===Je.BASE64){const s=new Image;return s.src=e,s}return this._imageSourceCache.get(e)}addImageSourceCache(e,t,s){t===Je.BASE64||s==null||this._imageSourceCache.set(e,s)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((t,s)=>{if(!Et.includes(e.type)){s(new Error(Ze.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>Ct){s(new Error(Ze.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}const i=new FileReader;i.readAsDataURL(e),i.onload=d=>{var E;const l=(E=d.target)==null?void 0:E.result;if(l==null){s(new Error(Ze.ERROR_IMAGE)),this._decreaseWaiting();return}const a=Qe.Tools.generateRandomId(6);t({imageId:a,imageSourceType:Je.BASE64,source:l,base64Cache:l,status:Ze.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}}const zt="__default_document_sub_component_id20231101__";var Mt=(n=>(n[n.forward=0]="forward",n[n.backward=1]="backward",n[n.front=2]="front",n[n.back=3]="back",n))(Mt||{}),Nt=(n=>(n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n[n.DRAWING_IMAGE=0]="DRAWING_IMAGE",n[n.DRAWING_SHAPE=1]="DRAWING_SHAPE",n[n.DRAWING_CHART=2]="DRAWING_CHART",n[n.DRAWING_TABLE=3]="DRAWING_TABLE",n[n.DRAWING_SMART_ART=4]="DRAWING_SMART_ART",n[n.DRAWING_VIDEO=5]="DRAWING_VIDEO",n[n.DRAWING_GROUP=6]="DRAWING_GROUP",n[n.DRAWING_UNIT=7]="DRAWING_UNIT",n[n.DRAWING_DOM=8]="DRAWING_DOM",n))(Nt||{});const jt=nt.createIdentifier("univer.drawing-manager.service");var Xt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Yt=(n,e,t,s)=>{for(var i=s>1?void 0:s?Zt(e,t):e,d=n.length-1,l;d>=0;d--)(l=n[d])&&(i=(s?l(e,t,i):l(i))||i);return s&&i&&Xt(e,t,i),i},Jt=(n,e)=>(t,s)=>e(t,s,n);const Qt="DRAWING_PLUGIN";var at;exports.UniverDrawingPlugin=(at=class extends Qe.Plugin{constructor(e,t){super(),this._config=e,this._injector=t}onStarting(e){this._initDependencies(e)}_initDependencies(e){var i;const t=[[St,{useClass:Ut}],[jt,{useClass:Pt}]];Qe.mergeOverrideWithDependencies(t,(i=this._config)==null?void 0:i.override).forEach(d=>e.add(d))}},q(at,"pluginName",Qt),at);exports.UniverDrawingPlugin=Yt([Jt(1,nt.Inject(nt.Injector))],exports.UniverDrawingPlugin);exports.ArrangeTypeEnum=Mt;exports.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=zt;exports.DRAWING_IMAGE_ALLOW_IMAGE_LIST=Et;exports.DRAWING_IMAGE_ALLOW_SIZE=Ct;exports.DRAWING_IMAGE_COUNT_LIMIT=xt;exports.DRAWING_IMAGE_HEIGHT_LIMIT=Bt;exports.DRAWING_IMAGE_WIDTH_LIMIT=Gt;exports.DrawingManagerService=Pt;exports.DrawingTypeEnum=Nt;exports.IDrawingManagerService=jt;exports.IImageIoService=St;exports.ImageIoService=Ut;exports.ImageSourceType=Je;exports.ImageUploadStatusType=Ze;exports.UnitDrawingService=Dt;exports.getDrawingShapeKeyByDrawingSearch=Vt;exports.getImageSize=qt;