@univerjs/drawing 0.20.1-insiders.20260418-3a69981 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1 -1
- package/lib/index.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +3 -3
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
package/lib/es/index.js
CHANGED
package/lib/index.js
CHANGED
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDrawing={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:r(s(e)),u(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e));let f=[`image/png`,`image/jpeg`,`image/jpg`,`image/gif`,`image/bmp`],p=(0,t.createIdentifier)(`univer.drawing-manager.service`),m={id:`drawing.operation.set-drawing-selected`,type:t.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(p);return t==null?!1:(n.focusDrawing(t),!0)}};var h=`@univerjs/drawing`,g=`0.20.1-insiders.20260418-3a69981`;let _=`drawing.config`;Symbol(_);let v={};var y=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0});function t(e,t){if(Array.isArray(t))return!1;for(let n in e)if(!r(e[n],t[n]))return!1;for(let n in t)if(e[n]===void 0)return!1;return!0}function n(e,t){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0}function r(e,r){return e===r?!0:e===null||r===null||typeof e!=`object`||typeof r!=`object`?!1:Array.isArray(e)?n(e,r):t(e,r)}e.default=r})),b=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0});function t(e){if(e===null)return null;if(Array.isArray(e))return e.map(t);if(typeof e==`object`){let n={};for(let r in e)n[r]=t(e[r]);return n}else return e}e.default=t})),x=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.eachChildOf=e.advancer=e.readCursor=e.writeCursor=e.WriteCursor=e.ReadCursor=e.isValidPathItem=void 0;function t(e,t){if(!e)throw Error(t)}let n=e=>typeof e==`object`&&!!e&&!Array.isArray(e),r=(e,t)=>typeof e==typeof t?e>t:typeof e==`string`&&typeof t==`number`;function i(e,t){for(let n in e){let r=n;t.write(r,e[r])}}e.isValidPathItem=e=>typeof e==`number`||typeof e==`string`&&e!==`__proto__`;var a=class{constructor(e=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=e}ascend(){t(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):(t(this.idx>0),this.idx--,n(this.container[this.idx])&&this.idx--)}getPath(){let e=[],t=this.container,r=this.parents.length-1,i=this.idx;for(;i>=0;)e.unshift(t[i]),i===0?(i=this.indexes[r*2],t=this.parents[r--]):i-=n(t[i-1])?2:1;return e}},o=class e extends a{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return t(this.container!=null,`Invalid call to getKey before cursor descended`),this.container[this.idx]}getComponent(){let e;return this.container&&this.container.length>this.idx+1&&n(e=this.container[this.idx+1])?e:null}descendFirst(){let e=this.idx+1;if(!this.container||e>=this.container.length||n(this.container[e])&&e+1>=this.container.length)return!1;n(this.container[e])&&e++;let t=this.container[e];return Array.isArray(t)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(e),this.idx=0,this.container=t):this.idx=e,!0}nextSibling(){if(t(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;let e=this.indexes[this.indexes.length-1]+1,n=this.parents[this.parents.length-1];return e>=n.length?!1:(t(!isNaN(e)),this.indexes[this.indexes.length-1]=e,this.container=n[e],!0)}_init(e,t,n,r){this.container=e,this.idx=t,this.parents=n.slice(),this.indexes=r.slice()}clone(){let t=new e;return t._init(this.container,this.idx,this.parents,this.indexes),t}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(e,t){let n=this.getComponent();n&&t(n,e);for(let n of this)e&&e.descend(n),this.traverse(e,t),e&&e.ascend()}eachPick(e,t){this.traverse(e,(e,n)=>{e.p!=null&&t(e.p,n)})}eachDrop(e,t){this.traverse(e,(e,n)=>{e.d!=null&&t(e.d,n)})}};e.ReadCursor=o;var s=class extends a{constructor(e=null){super(e),this.pendingDescent=[],this._op=e}flushDescent(){t(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let e=0;e<this.pendingDescent.length;e++){let i=this.pendingDescent[e],a=this.idx+1;if(a<this.container.length&&n(this.container[a])&&a++,t(a===this.container.length||!n(this.container[a])),a===this.container.length)this.container.push(i),this.idx=a;else if(this.container[a]===i)this.idx=a;else{if(!Array.isArray(this.container[a])){let e=this.container.splice(a,this.container.length-a);this.container.push(e),this.lcIdx>-1&&(this.lcIdx=a)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(t(r(i,this.container[this.lcIdx][0])),a=this.lcIdx+1,this.lcIdx=-1);a<this.container.length&&r(i,this.container[a][0]);)a++;if(this.indexes.push(a),this.idx=0,a<this.container.length&&this.container[a][0]===i)this.container=this.container[a];else{let e=[i];this.container.splice(a,0,e),this.container=e}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();let e=this.idx+1;if(e<this.container.length&&n(this.container[e]))return this.container[e];{let t={};return this.container.splice(e,0,t),t}}write(e,n){let r=this.getComponent();t(r[e]==null||r[e]===n,`Internal consistency error: Overwritten component. File a bug`),r[e]=n}get(){return this._op}descend(t){if(!e.isValidPathItem(t))throw Error(`Invalid JSON key`);this.pendingDescent.push(t)}descendPath(e){return this.pendingDescent.push(...e),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(e,n=i){if(e===null)return;if(t(Array.isArray(e)),e===this._op)throw Error(`Cannot merge into my own tree`);let r=this.lcIdx,a=this.parents.length,o=0;for(let t=0;t<e.length;t++){let r=e[t];typeof r==`string`||typeof r==`number`?(o++,this.descend(r)):Array.isArray(r)?this.mergeTree(r,n):typeof r==`object`&&n(r,this)}for(;o--;)this.ascend();this.lcIdx=this.parents.length===a?r:-1}at(e,t){this.descendPath(e),t(this);for(let t=0;t<e.length;t++)this.ascend();return this}writeAtPath(e,t,n){return this.at(e,()=>this.write(t,n)),this.reset(),this}writeMove(e,t,n=0){return this.writeAtPath(e,`p`,n).writeAtPath(t,`d`,n)}getPath(){let e=super.getPath();return e.push(...this.pendingDescent),e}};e.WriteCursor=s,e.writeCursor=()=>new s,e.readCursor=e=>new o(e);function c(e,t,n){let i,a;a=i=e?e.descendFirst():!1;function o(i){let o;for(;a;){let s=o=e.getKey();if(i!=null){let n=!1;if(t&&typeof s==`number`&&(o=t(s,e.getComponent()),o<0&&(o=~o,n=!0)),r(o,i))return null;if(o===i&&!n)return e}n&&typeof o==`number`&&n(o,e.getComponent()),a=e.nextSibling()}return null}return o.end=()=>{i&&e.ascend()},o}e.advancer=c;function l(e,t,n){let i,a,o,s;for(i=a=e&&e.descendFirst(),o=s=t&&t.descendFirst();i||o;){let a=i?e.getKey():null,s=o?t.getKey():null;a!==null&&s!==null&&(r(s,a)?s=null:a!==s&&(a=null)),n(a==null?s:a,a==null?null:e,s==null?null:t),a!=null&&i&&(i=e.nextSibling()),s!=null&&o&&(o=t.nextSibling())}a&&e.ascend(),s&&t.ascend()}e.eachChildOf=l})),S=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.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`})(e.ConflictType||(e.ConflictType={}))})),C=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.uniToStrPos=e.strPosToUni=void 0,e.strPosToUni=(e,t=e.length)=>{let n=0,r=0;for(;r<t;r++){let t=e.charCodeAt(r);t>=55296&&t<=57343&&(n++,r++)}if(r!==t)throw Error(`Invalid offset - splits unicode bytes`);return r-n},e.uniToStrPos=(e,t)=>{let n=0;for(;t>0;t--){let t=e.charCodeAt(n);n+=t>=55296&&t<=57343?2:1}return n}})),w=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.uniSlice=e.dlen=e.eachOp=void 0;let t=C(),n=t=>{if(!Array.isArray(t))throw Error(`Op must be an array of components`);let n=null;for(let r=0;r<t.length;r++){let i=t[r];switch(typeof i){case`object`:if(typeof i.d!=`number`&&typeof i.d!=`string`)throw Error(`Delete must be number or string`);if(e.dlen(i.d)<=0)throw Error(`Deletes must not be empty`);break;case`string`:if(!(i.length>0))throw Error(`Inserts cannot be empty`);break;case`number`:if(!(i>0))throw Error(`Skip components must be >0`);if(typeof n==`number`)throw Error(`Adjacent skip components should be combined`);break}n=i}if(typeof n==`number`)throw Error(`Op has a trailing skip`)};function r(n,r){let i=0,a=0;for(let o=0;o<n.length;o++){let s=n[o];switch(r(s,i,a),typeof s){case`object`:i+=e.dlen(s.d);break;case`string`:a+=t.strPosToUni(s);break;case`number`:i+=s,a+=s;break}}}e.eachOp=r;function i(e,t){let n=[],i=s(n);return r(e,(e,n,r)=>{i(t(e,n,r))}),d(n)}let a=e=>e,o=e=>i(e,a);e.dlen=e=>typeof e==`number`?e:t.strPosToUni(e);let s=t=>n=>{if(!(!n||n.d===0||n.d===``))if(t.length===0)t.push(n);else if(typeof n==typeof t[t.length-1])if(typeof n==`object`){let r=t[t.length-1];r.d=typeof r.d==`string`&&typeof n.d==`string`?r.d+n.d:e.dlen(r.d)+e.dlen(n.d)}else t[t.length-1]+=n;else t.push(n)},c=e=>typeof e==`number`?e:typeof e==`string`?t.strPosToUni(e):typeof e.d==`number`?e.d:t.strPosToUni(e.d);e.uniSlice=(e,n,r)=>{let i=t.uniToStrPos(e,n),a=r==null?1/0:t.uniToStrPos(e,r);return e.slice(i,a)};let l=(t,n,r)=>typeof t==`number`?r==null?t-n:Math.min(t,r)-n:e.uniSlice(t,n,r),u=n=>{let r=0,i=0;return{take:(a,o)=>{if(r===n.length)return a===-1?null:a;let s=n[r],c;if(typeof s==`number`)return a===-1||s-i<=a?(c=s-i,++r,i=0,c):(i+=a,a);if(typeof s==`string`){if(a===-1||o===`i`||t.strPosToUni(s.slice(i))<=a)return c=s.slice(i),++r,i=0,c;{let e=i+t.uniToStrPos(s.slice(i),a);return c=s.slice(i,e),i=e,c}}else if(a===-1||o===`d`||e.dlen(s.d)-i<=a)return c={d:l(s.d,i)},++r,i=0,c;else{let e=l(s.d,i,i+a);return i+=a,{d:e}}},peek:()=>n[r]}},d=e=>(e.length>0&&typeof e[e.length-1]==`number`&&e.pop(),e);function f(r,i,a){if(a!==`left`&&a!==`right`)throw Error(`side (`+a+`) must be 'left' or 'right'`);n(r),n(i);let o=[],l=s(o),{take:f,peek:p}=u(r);for(let n=0;n<i.length;n++){let r=i[n],o,s;switch(typeof r){case`number`:for(o=r;o>0;)s=f(o,`i`),l(s),typeof s!=`string`&&(o-=c(s));break;case`string`:a===`left`&&typeof p()==`string`&&l(f(-1)),l(t.strPosToUni(r));break;case`object`:for(o=e.dlen(r.d);o>0;)switch(s=f(o,`i`),typeof s){case`number`:o-=s;break;case`string`:l(s);break;case`object`:o-=e.dlen(s.d)}break}}let m;for(;m=f(-1);)l(m);return d(o)}function p(r,i){n(r),n(i);let a=[],o=s(a),{take:f}=u(r);for(let n=0;n<i.length;n++){let r=i[n],a,s;switch(typeof r){case`number`:for(a=r;a>0;)s=f(a,`d`),o(s),typeof s!=`object`&&(a-=c(s));break;case`string`:o(r);break;case`object`:a=e.dlen(r.d);let n=0;for(;n<a;)switch(s=f(a-n,`d`),typeof s){case`number`:o({d:l(r.d,n,n+s)}),n+=s;break;case`string`:n+=t.strPosToUni(s);break;case`object`:o(s)}break}}let p;for(;p=f(-1);)o(p);return d(a)}let m=(n,r)=>{let i=0;for(let a=0;a<r.length&&n>i;a++){let o=r[a];switch(typeof o){case`number`:i+=o;break;case`string`:let r=t.strPosToUni(o);i+=r,n+=r;break;case`object`:n-=Math.min(e.dlen(o.d),n-i);break}}return n},h=(e,t)=>typeof e==`number`?m(e,t):e.map(e=>m(e,t));function g(e,t,n){return i(e,(e,r)=>typeof e==`object`&&typeof e.d==`number`?{d:n.slice(t,r,r+e.d)}:e)}function _(e){return i(e,e=>{switch(typeof e){case`object`:if(typeof e.d==`number`)throw Error(`Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.`);return e.d;case`string`:return{d:e};case`number`:return e}})}function v(e){return i(e,e=>typeof e==`object`&&typeof e.d==`string`?{d:t.strPosToUni(e.d)}:e)}function y(e){let t=!0;return r(e,e=>{typeof e==`object`&&typeof e.d==`number`&&(t=!1)}),t}function b(t){return{name:`text-unicode`,uri:`http://sharejs.org/types/text-unicode`,trim:d,normalize:o,checkOp:n,create(e=``){if(typeof e!=`string`)throw Error(`Initial data must be a string`);return t.create(e)},apply(r,i){n(i);let a=t.builder(r);for(let t=0;t<i.length;t++){let n=i[t];switch(typeof n){case`number`:a.skip(n);break;case`string`:a.append(n);break;case`object`:a.del(e.dlen(n.d));break}}return a.build()},transform:f,compose:p,transformPosition:m,transformSelection:h,isInvertible:y,makeInvertible(e,n){return g(e,n,t)},stripInvertible:v,invert:_,invertWithDoc(e,n){return _(g(e,n,t))},isNoop:e=>e.length===0}}e.default=b})),T=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=w(),n=C();function r(e,r){return{get:e,getLength(){return e().length},insert(t,i,a){return r([n.strPosToUni(e(),t),i],a)},remove(t,i,a){return r([n.strPosToUni(e(),t),{d:i}],a)},_onOp(e){t.eachOp(e,(e,n,r)=>{switch(typeof e){case`string`:this.onInsert&&this.onInsert(r,e);break;case`object`:let n=t.dlen(e.d);this.onRemove&&this.onRemove(r,n)}})},onInsert:null,onRemove:null}}e.default=r,r.provides={text:!0}})),E=l((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}):function(e,t){e.default=t}),r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)Object.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r},i=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,`__esModule`,{value:!0}),e.type=e.remove=e.insert=void 0;let a=C(),o=r(w()),s=i(T()),c={create(e){return e},toString(e){return e},builder(e){if(typeof e!=`string`)throw Error(`Invalid document snapshot: `+e);let t=[];return{skip(n){let r=a.uniToStrPos(e,n);if(r>e.length)throw Error(`The op is too long for this document`);t.push(e.slice(0,r)),e=e.slice(r)},append(e){t.push(e)},del(t){e=e.slice(a.uniToStrPos(e,t))},build(){return t.join(``)+e}}},slice:o.uniSlice},l=o.default(c);e.type=Object.assign(Object.assign({},l),{api:s.default}),e.insert=(e,t)=>t.length===0?[]:e===0?[t]:[e,t],e.remove=(e,t)=>o.dlen(t)===0?[]:e===0?[{d:t}]:[e,{d:t}];var u=w();Object.defineProperty(e,`makeType`,{enumerable:!0,get:function(){return u.default}})})),D=l((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,`__esModule`,{value:!0}),e.editOp=e.replaceOp=e.insertOp=e.moveOp=e.removeOp=e.type=void 0;let n=t(y()),r=t(b()),i=x(),a=S(),o=()=>{};function s(e,t){if(!e)throw Error(t)}let c=!1;e.type={name:`json1`,uri:`http://sharejs.org/types/JSONv1`,readCursor:i.readCursor,writeCursor:i.writeCursor,create:e=>e,isNoop:e=>e==null,setDebug(e){c=e,o.quiet=!e},registerSubtype:C,checkValidOp:M,normalize:N,apply:P,transformPosition:F,compose:I,tryTransform:H,transform:W,makeInvertible:z,invert:L,invertWithDoc:B,RM_UNEXPECTED_CONTENT:a.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:a.ConflictType.DROP_COLLISION,BLACKHOLE:a.ConflictType.BLACKHOLE,transformNoConflict:(e,t,n)=>q(()=>!0,e,t,n),typeAllowingConflictsPred:t=>Object.assign(Object.assign({},e.type),{transform:(e,n,r)=>q(t,e,n,r)})};let l=e=>e?e.getComponent():null;function u(e){return e&&typeof e==`object`&&!Array.isArray(e)}let d=e=>Array.isArray(e)?e.slice():typeof e==`object`&&e?Object.assign({},e):e,f=e=>e&&(e.p!=null||e.r!==void 0),p=e=>e&&(e.d!=null||e.i!==void 0);function m(e,t){return s(e!=null),typeof t==`number`?(s(Array.isArray(e),`Invalid key - child is not an array`),(e=e.slice()).splice(t,1)):(s(u(e),`Invalid key - child is not an object`),delete(e=Object.assign({},e))[t]),e}function h(e,t,n){return typeof t==`number`?(s(e!=null,`Container is missing for key`),s(Array.isArray(e),`Cannot use numerical key for object container`),s(e.length>=t,`Cannot insert into out of bounds index`),e.splice(t,0,n)):(s(u(e),`Cannot insert into missing item`),s(e[t]===void 0,`Trying to overwrite value at key. Your op needs to remove it first`),e[t]=n),n}e.removeOp=(e,t=!0)=>i.writeCursor().writeAtPath(e,`r`,t).get(),e.moveOp=(e,t)=>i.writeCursor().writeMove(e,t).get(),e.insertOp=(e,t)=>i.writeCursor().writeAtPath(e,`i`,t).get(),e.replaceOp=(e,t,n)=>i.writeCursor().at(e,e=>{e.write(`r`,t),e.write(`i`,n)}).get(),e.editOp=(e,t,n,r=!1)=>i.writeCursor().at(e,e=>k(e,t,n,r)).get();let g=(e,t)=>e!=null&&(typeof t==`number`?Array.isArray(e):typeof e==`object`),_=(e,t)=>g(e,t)?e[t]:void 0,v={};function C(e){let t=e.type?e.type:e;t.name&&(v[t.name]=t),t.uri&&(v[t.uri]=t)}let w=e=>{let t=v[e];if(t)return t;throw Error(`Missing type: `+e)};C(E());let T=(e,t)=>e+t;C({name:`number`,apply:T,compose:T,invert:e=>-e,transform:e=>e});let D=e=>e==null?null:e.et?w(e.et):e.es?v[`text-unicode`]:e.ena==null?null:v.number,O=e=>e.es?e.es:e.ena==null?e.e:e.ena,k=(e,t,n,r=!1)=>{let[i,a]=typeof t==`string`?[w(t),t]:[t,t.name];!r&&i.isNoop&&i.isNoop(n)||(a===`number`?e.write(`ena`,n):a===`text-unicode`?e.write(`es`,n):(e.write(`et`,a),e.write(`e`,n)))};function A(e){s(typeof e==`number`),s(e>=0),s(e===(0|e))}function j(e){typeof e==`number`?A(e):s(typeof e==`string`)}function M(e){if(e===null)return;let t=new Set,n=new Set,r=e=>{let r=!0,i=!1;for(let a in e){let o=e[a];if(r=!1,s(a===`p`||a===`r`||a===`d`||a===`i`||a===`e`||a===`es`||a===`ena`||a===`et`,`Invalid component item '`+a+`'`),a===`p`)A(o),s(!t.has(o)),t.add(o),s(e.r===void 0);else if(a===`d`)A(o),s(!n.has(o)),n.add(o),s(e.i===void 0);else if(a===`e`||a===`es`||a===`ena`){s(!i),i=!0;let t=D(e);s(t,`Missing type in edit`),t.checkValidOp&&t.checkValidOp(O(e))}}s(!r)},a=(e,t,n)=>{if(!Array.isArray(e))throw Error(`Op must be null or a list`);if(e.length===0)throw Error(`Empty descent`);t||j(e[0]);let o=1,c=0,l=0;for(let t=0;t<e.length;t++){let u=e[t];if(s(u!=null),Array.isArray(u)){let e=a(u,!1,n);if(c){let t=typeof l,n=typeof e;t===n?s(l<e,`descent keys are not in order`):s(t===`number`&&n===`string`)}l=e,c++,o=3}else typeof u==`object`?(s(o===1,`Prev not scalar - instead ${o}`),r(u),o=2):(s(o!==3),j(u),s(i.isValidPathItem(u),`Invalid path key`),o=1)}return s(c!==1,`Operation makes multiple descents. Remove some []`),s(o===2||o===3),e[0]};a(e,!0,!1),s(t.size===n.size,`Mismatched picks and drops in op`);for(let e=0;e<t.size;e++)s(t.has(e)),s(n.has(e))}function N(e){let t=0,n=[],r=i.writeCursor();return r.mergeTree(e,(e,r)=>{let i=D(e);if(i){let t=O(e);k(r,i,i.normalize?i.normalize(t):t)}for(let i of[`r`,`p`,`i`,`d`])if(e[i]!==void 0){let o=i===`p`||i===`d`?(a=e[i],n[a]==null&&(n[a]=t++),n[a]):e[i];r.write(i,o)}var a}),r.get()}function P(e,t){if(o.quiet=!c,M(t),t===null)return e;let n=[];return function e(t,r){let i=t,a=0,o={root:t},c=0,l=o,u=`root`;function f(){for(;c<a;c++){let e=r[c];typeof e!=`object`&&(s(g(l,u)),l=l[u]=d(l[u]),u=e)}}for(;a<r.length;a++){let t=r[a];if(Array.isArray(t)){let n=e(i,t);n!==i&&n!==void 0&&(f(),i=l[u]=n)}else if(typeof t==`object`){t.d==null?t.i!==void 0&&(f(),i=h(l,u,t.i)):(f(),i=h(l,u,n[t.d]));let e=D(t);if(e)f(),i=l[u]=e.apply(i,O(t));else if(t.e!==void 0)throw Error(`Subtype `+t.et+` undefined`)}else i=_(i,t)}return o.root}(e=function e(t,r){let i=[],a=0;for(;a<r.length;a++){let e=r[a];if(Array.isArray(e))break;typeof e!=`object`&&(i.push(t),t=_(t,e))}for(let n=r.length-1;n>=a;n--)t=e(t,r[n]);for(--a;a>=0;a--){let e=r[a];if(typeof e!=`object`){let n=i.pop();t=t===_(n,e)?n:t===void 0?m(n,e):(c=e,l=t,(o=d(o=n))[c]=l,o)}else f(e)&&(s(t!==void 0,`Cannot pick up or remove undefined`),e.p!=null&&(n[e.p]=t),t=void 0)}var o,c,l;return t}(e,t),t)}function F(e,t){e=e.slice(),M(t);let n=i.readCursor(t),r,a,o=!1,s=[];for(let t=0;;t++){let c=e[t],l=n.getComponent();if(l&&(l.r===void 0?l.p!=null&&(o=!1,r=l.p,a=t):o=!0),t>=e.length)break;let u=0,d=i.advancer(n,void 0,(e,t)=>{f(t)&&u++});s.unshift(d);let p=d(c);if(typeof c==`number`&&(e[t]-=u),!p)break}if(s.forEach(e=>e.end()),o)return null;let c=()=>{let t=0;if(r!=null){let r=n.getPath();t=r.length,e=r.concat(e.slice(a))}for(;t<e.length;t++){let r=e[t],a=l(n),o=D(a);if(o){let n=O(a);o.transformPosition&&(e[t]=o.transformPosition(e[t],n));break}let s=0,c=i.advancer(n,(e,t)=>p(t)?~(e-s):e-s,(e,t)=>{p(t)&&s++})(r);if(typeof r==`number`&&(e[t]+=s),!c)break}};return r==null?c():n.eachDrop(null,e=>{e===r&&c()}),e}function I(e,t){if(M(e),M(t),e==null)return t;if(t==null)return e;let n=0,r=i.readCursor(e),a=i.readCursor(t),o=i.writeCursor(),c=[],u=[],d=[],m=[],h=[],g=[],_=new Set;r.traverse(null,e=>{e.p!=null&&(d[e.p]=r.clone())}),a.traverse(null,e=>{e.d!=null&&(m[e.d]=a.clone())});let v=i.writeCursor();return function e(t,r,a,o,v,y,b,x){s(r||a);let S=l(r),C=l(a),w=!!C&&C.r!==void 0,T=!!S&&S.i!==void 0,E=S?S.d:null,A=C?C.p:null,j=(y||w)&&A==null;if(A!=null)o=m[A],b=u[A]=new i.WriteCursor;else if(C&&C.r!==void 0)o=null;else{let e=l(o);e&&e.d!=null&&(o=null)}let M=l(o);if(E!=null)if(t=d[E],x=c[E]=new i.WriteCursor,j)y&&!w&&x.write(`r`,!0);else{let e=h[E]=n++;b.write(`d`,e)}else if(S&&S.i!==void 0)t=null;else{let e=l(t);e&&e.p!=null&&(t=null)}let N;T?(s(v===void 0),N=S.i):N=v;let P=(A==null?!T||y||w:N===void 0)?null:b.getComponent();if(A!=null){if(!(v!==void 0||T)){let e=E==null?n++:h[E];g[A]=e,x.write(`p`,e)}}else w&&(T||v!==void 0||(C.r,x.write(`r`,C.r)));let F=j?null:D(S),I=D(M);if((F||I)&&(F&&F.name,I&&I.name),F&&I){s(F===I);let e=O(S),t=O(M),n=F.compose(e,t);k(b,F,n),_.add(M)}else F?k(b,F,O(S)):I&&(k(b,I,O(M)),_.add(M));let L=typeof N==`object`&&!!N,R=!1,z=0,B=0,V=0,H=0,U=0,W=i.advancer(o,(e,t)=>p(t)?H-e-1:e-H,(e,t)=>{p(t)&&H++}),G=i.advancer(t,(e,t)=>f(t)?z-e-1:e-z,(e,t)=>{f(t)&&z++});if(i.eachChildOf(r,a,(t,n,r)=>{let i,a,o=t,c=t,u=t;if(typeof t==`number`){let e=t+V;a=W(e),c=e+H;let d=t+B;i=G(d),p(l(a))&&(i=null),o=d+z,u=t+U,s(o>=0,`p1PickKey is negative`),s(c>=0,`p2DropKey is negative`);let m=p(l(n)),h=f(l(r));(m||h&&!j)&&U--,m&&B--,h&&V--}else i=G(t),a=W(t);x.descend(o),b.descend(c);let d=L&&!p(l(n))?N[u]:void 0,m=e(i,n,r,a,d,j,b,x);var h,g,_;L&&!j?d!==m&&(R||(N=Array.isArray(N)?N.slice():Object.assign({},N),R=!0),h=N,_=m,typeof(g=u)==`number`?(s(Array.isArray(h)),s(g<h.length)):(s(!Array.isArray(h)),s(h[g]!==void 0)),_===void 0?typeof g==`number`?h.splice(g,1):delete h[g]:h[g]=_):s(m===void 0),b.ascend(),x.ascend()}),G.end(),W.end(),P!=null)P.i=N;else if(!y&&!w&&A==null)return N}(r,r.clone(),a,a.clone(),void 0,!1,o,v),o.reset(),o.mergeTree(v.get()),o.reset(),o.get(),c.map(e=>e.get()),u.map(e=>e.get()),r.traverse(o,(e,t)=>{let n=e.p;if(n!=null){let e=h[n];e!=null&&t.write(`p`,e);let r=c[n];r&&r.get(),r&&t.mergeTree(r.get())}else e.r!==void 0&&t.write(`r`,e.r)}),o.reset(),o.get(),a.traverse(o,(e,t)=>{let n=e.d;if(n!=null){let e=g[n];e!=null&&t.write(`d`,e);let r=u[n];r&&t.mergeTree(r.get())}else e.i!==void 0&&t.write(`i`,e.i);let r=D(e);r&&!_.has(e)&&k(t,r,O(e))}),o.get()}function L(e){if(e==null)return null;let t=new i.ReadCursor(e),n=new i.WriteCursor,r,a=[],o=[];return function e(t,n,i){let o=t.getComponent(),s,c=!1;if(o){o.p!=null&&(n.write(`d`,o.p),a[o.p]=t.clone()),o.r!==void 0&&n.write(`i`,o.r),o.d!=null&&(n.write(`p`,o.d),i=void 0),o.i!==void 0&&(i=s=o.i);let e=D(o);e&&(i===void 0?(r||(r=new Set),r.add(o)):(O(o),i=e.apply(i,O(o)),c=!0))}let l=0;for(let r of t){n.descend(r);let a=typeof r==`number`?r-l:r,o=_(i,a);p(t.getComponent())&&l++;let s=e(t,n,o);if(i!==void 0&&s!==void 0){if(c||(c=!0,i=d(i)),!g(i,a))throw Error(`Cannot modify child - invalid operation`);i[a]=s}n.ascend()}if(s===void 0)return c?i:void 0;n.write(`r`,i)}(t,n,void 0),r&&(n.reset(),function e(t,n,s){let c=n.getComponent();if(c){let e=c.d;if(e!=null&&(t=a[e],s=o[e]=i.writeCursor()),r.has(c)){let e=D(c);if(!e.invert)throw Error(`Cannot invert subtype ${e.name}`);k(s,e,e.invert(O(c)))}}let l=0,u=0,d=i.advancer(t,(e,t)=>f(t)?l-e-1:e-l,(e,t)=>{f(t)&&l++});for(let t of n)if(typeof t==`number`){let r=t-u,i=d(r),a=r+l;s.descend(a),e(i,n,s),p(n.getComponent())&&u++,s.ascend()}else s.descend(t),e(d(t),n,s),s.ascend();d.end()}(t.clone(),t,n),o.length&&(n.reset(),t.traverse(n,(e,t)=>{let n=e.p;if(n!=null){let e=o[n];e&&e.get(),e&&t.mergeTree(e.get())}}))),n.get()}let R=(e,t)=>e.some(e=>typeof e==`object`&&(Array.isArray(e)?R(e,t):t(e)));function z(e,t){if(e==null||!R(e,e=>{var t;return e.r!==void 0||((t=D(e))==null?void 0:t.makeInvertible)!=null}))return e;let n=new i.ReadCursor(e),a=new i.WriteCursor,o=!1,c=[],l=[],u=(e,t,n)=>{let i=e.getComponent(),a=!1;if(i){i.d!=null&&t.write(`d`,i.d),i.i!==void 0&&t.write(`i`,i.i);let r=i.p;if(r!=null&&(c[r]=e.clone(),s(n!==void 0,`Operation picks up at an invalid key`),l[r]=n,t.write(`p`,i.p)),i.r!==void 0&&n===void 0)throw Error(`Invalid doc / op in makeInvertible: removed item missing from doc`);let a=D(i);a&&(a.makeInvertible?o=!0:k(t,a,O(i),!0))}let f=0;for(let r of e){t.descend(r);let i=typeof r==`number`?r-f:r,o=_(n,i),s=u(e,t,o);o!==s&&(a||(a=!0,n=d(n)),s===void 0?(n=m(n,i),typeof r==`number`&&f++):n[i]=s),t.ascend()}return i&&(i.r===void 0?i.p!=null&&(n=void 0):(t.write(`r`,r.default(n)),n=void 0)),n};return u(n,a,t),a.get(),o&&(a.reset(),function e(t,n,r,a,o){let s=n.getComponent();if(s){s.i===void 0?s.d!=null&&(a=l[s.d],t=c[s.d],o=!1,s.d):(a=s.i,o=!0);let e=D(s);if(e&&e.makeInvertible){let t=O(s);k(r,e,e.makeInvertible(t,a),!0)}}let u=0,d=0,m=i.advancer(t,(e,t)=>f(t)?u-e-1:e-u,(e,t)=>{f(t)&&u++});for(let t of n)if(typeof t==`number`){let i=t-d,s=m(i),c=i+u,l=_(a,o?i:c);r.descend(t),e(s,n,r,l,o),p(n.getComponent())&&d++,r.ascend()}else{let i=_(a,t);r.descend(t),e(m(t),n,r,i,o),r.ascend()}m.end()}(n.clone(),n,a,t,!1)),a.get()}function B(e,t){return L(z(e,t))}let V=e=>{if(e==null)return null;let t=e.slice();for(let n=0;n<e.length;n++){let e=t[n];Array.isArray(e)&&(t[n]=V(e))}return t};function H(t,u,d){s(d===`left`||d===`right`,`Direction must be left or right`);let m=d===`left`?0:1;if(o.quiet=!c,o.prefix=0,u==null)return{ok:!0,result:t};M(t),M(u);let h=null,g=[],_=[],v=[],y=[],b=[],x=[],S=[],C=[],w=[],T=[],E=[],A=[],j=[],N=[],P=[],F=0,I=i.readCursor(t),L=i.readCursor(u),R=i.writeCursor();if(function e(t,n=null,r){let a=l(n);a&&(a.r===void 0?a.p!=null&&(r=null,x[a.p]=t.clone()):r=n.clone());let o=t.getComponent(),s;o&&(s=o.p)!=null&&(b[s]=n?n.clone():null,v[s]=t.clone(),r&&(T[s]=!0,w[s]=r),a&&a.p!=null&&(N[s]=a.p));let c=i.advancer(n);for(let n of t)e(t,c(n),r);c.end()}(L,I,null),function t(n,r,o,s,c){let u=o.getComponent(),d,p=!1;u&&((d=u.d)==null?u.i!==void 0&&(n=r=null,p=!0,c&&h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.insertOp(o.getPath(),u.i)})):(y[d]=o.clone(),s!=null&&(P[s]==null&&(P[s]=[]),P[s].push(d)),T[d],n=b[d]||null,r=v[d]||null,T[d]?(c&&(E[d]=!0),c=w[d]||null):!c||m!==1&&N[d]!=null||h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.moveOp(r.getPath(),o.getPath())}),p=!0));let g=l(n);g&&(g.r===void 0?g.p!=null&&(g.p,s=g.p,c=null):c=n.clone());let _=D(u);_&&c&&h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.editOp(o.getPath(),_,O(u),!0)});let x=0,S=0,C=i.advancer(r,(e,t)=>f(t)?x-e-1:e-x,(e,t)=>{f(t)&&x++}),k=i.advancer(n);for(let e of o)if(typeof e==`number`){let n=e-S,r=C(n);S+=+t(k(n+x),r,o,s,c)}else{let n=C(e);t(k(e),n,o,s,c)}return C.end(),k.end(),p}(I,L,L.clone(),null,null),y.map(e=>e&&e.get()),h)return{ok:!1,conflict:h};E.map(e=>!!e);let z=[],B=null;(function e(t,n,r,a,o){let c=!1,u=l(n);if(f(u)){let e=u.p;e==null?(r=null,o=n.clone()):(r=y[e],a=A[e]=i.writeCursor(),c=!0,o=null)}else p(l(r))&&(r=null);let d=t.getComponent();if(d){let e=d.p;e==null?d.r!==void 0&&(o||a.write(`r`,!0),(o||c)&&(B==null&&(B=new Set),B.add(d))):(o&&(C[e]=o),z[e]=o||m===1&&c?null:a.getComponent(),g[e]=t.clone(),r&&(S[e]=r.clone()))}let h=0,_=0,v=i.advancer(n,void 0,(e,t)=>{f(t)&&h++}),b=i.advancer(r,(e,t)=>p(t)?~(e-_):e-_,(e,t)=>{p(t)&&_++});if(t)for(let n of t)if(typeof n==`string`){let r=v(n),i=b(n);a.descend(n),e(t,r,i,a,o),a.ascend()}else{let r=v(n),i=n-h,c=f(l(r))?null:b(i),u=i+_;s(u>=0),a.descend(u),e(t,r,c,a,o),a.ascend()}v.end(),b.end()})(I,L,L.clone(),R,null),R.reset();let H=[];if(function t(o,c,u,b,w,E){s(c);let A=c.getComponent(),M=l(b),P=!1,I=(t,n,r)=>t?e.moveOp(t.getPath(),n.getPath()):e.insertOp(n.getPath(),r.i);if(p(A)){let t=A.d;t!=null&&(_[t]=c.clone());let i=t==null?null:z[t],s=!1;if(A.i!==void 0||t!=null&&i){let o;M&&(M.i!==void 0||(o=M.d)!=null&&!T[o])&&(s=o==null?n.default(M.i,A.i):t!=null&&t===N[o],s||o!=null&&m!==1&&N[o]!=null||h==null&&(h={type:a.ConflictType.DROP_COLLISION,op1:I(t==null?null:g[t],c,A),op2:I(o==null?null:v[o],b,M)})),s||(E?h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:I(t==null?null:g[t],c,A),op2:e.removeOp(E.getPath())}):(t==null?w.write(`i`,r.default(A.i)):(H[F]=t,w.write(`d`,i.p=F++)),P=!0))}else if(t!=null&&!i){let e=C[t];e&&(E=e.clone())}t==null?A.i!==void 0&&(o=u=null,s||(b=null)):(o=g[t],u=x[t],b=S[t])}else f(l(o))&&(o=u=b=null);let L=l(o),R=l(u);if(f(R)){let e=R.p;R.r!==void 0&&(!L||L.r===void 0)||T[e]?(b=null,E=u.clone()):e!=null&&(b=y[e],m!==1&&N[e]!=null||((w=j[e])||(w=j[e]=i.writeCursor()),w.reset(),E=null))}else !p(A)&&p(M)&&(b=null);M=b==null?null:b.getComponent();let V=D(A);if(V){let t=O(A);if(E)h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.editOp(c.getPath(),V,t,!0),op2:e.removeOp(E.getPath())});else{let e=D(M),n;if(e){if(V!==e)throw Error(`Transforming incompatible types`);let r=O(M);n=V.transform(t,r,d)}else n=r.default(t);k(w,V,n)}}let U=0,W=0,G=0,K=0,q=0,J=0,Y=o!=null&&o.descendFirst(),X=Y,Z=i.advancer(u,void 0,(e,t)=>{f(t)&&G++}),Q=b!=null&&b.descendFirst(),$=Q;for(let e of c)if(typeof e==`number`){let n,r=p(c.getComponent()),i=e-W;{let e;for(;Y&&typeof(e=o.getKey())==`number`;){e+=U;let t=o.getComponent(),n=f(t);if(e>i||e===i&&(!n||m===0&&r))break;if(n){U--;let e=t.p;z[e],N.includes(e),t.d,l(j[t.d]),f(l(j[t.d])),(t.r===void 0||B&&B.has(t))&&(e==null||!z[e]||m!==1&&N.includes(e))||q--}Y=o.nextSibling()}n=Y&&e===i?o:null}let a=i-U,u=Z(a),d=a-G,h=null;{let e,t;for(;Q&&typeof(e=b.getKey())==`number`;){t=e-K;let n=b.getComponent(),i=p(n);if(t>d)break;if(t===d){if(!i){h=b;break}{if(m===0&&r){h=b;break}let e=u&&f(u.getComponent());if(m===0&&e)break}}if(i){let e=n.d;T[e],N[e],n.i===void 0&&(T[e]||N[e]!=null&&m!==1)?(T[e]||N[e]!=null&&m===0)&&(K++,J--):K++}Q=b.nextSibling()}}let g=d+K+q+J;s(g>=0,`trying to descend to a negative index`),w.descend(g),r&&(n=u=h=null,W++),t(n,c,u,h,w,E)&&J++,w.ascend()}else{let n;for(;Y&&(n=o.getKey(),typeof n!=`string`||!(n>e||n===e));)Y=o.nextSibling();let r=Y&&n===e?o:null,i=Z(e),a;for(;Q&&(a=b.getKey(),typeof a!=`string`||!(a>e||a===e));)Q=b.nextSibling();let s=Q&&a===e?b:null;w.descend(e),t(r,c,i,s,w,E),w.ascend()}return Z.end(),X&&o.ascend(),$&&b.ascend(),P}(I,I.clone(),L,L.clone(),R,null),h)return{ok:!1,conflict:h};R.reset();let U=(e,t,n)=>e.traverse(t,(t,r)=>{t.d!=null&&n(t.d,e,r)});(T.length||A.length)&&(U(L,R,(e,t,n)=>{T[e]&&!E[e]&&n.write(`r`,!0),A[e]&&n.mergeTree(A[e].get())}),R.reset());let W=[],G=[];if((j.length||T.length)&&!h){let e=i.readCursor(V(R.get()));if(U(e,null,(e,t)=>{W[e]=t.clone()}),j.forEach(e=>{e&&U(i.readCursor(e.get()),null,(e,t)=>{W[e]=t.clone()})}),function e(t,n,r,a,s,c){o.prefix++;let u=l(n);if(u&&f(u))if(u.p!=null){s=u;let e=u.p;W[e].getPath(),r=W[e],a=G[e]=i.writeCursor()}else u.r!==void 0&&(r=null,c=!0);else p(l(r))&&(r=null);let d=t.getComponent();if(d){let e;if((e=d.d)!=null){let t=j[e];t&&(t.get(),a.mergeTree(t.get()),r=i.readCursor(t.get()))}}let m=0,h=0,g=i.advancer(n,void 0,(e,t)=>{f(t)&&m--}),_=i.advancer(r,(e,t)=>p(t)?-(e-h)-1:e-h,(e,t)=>{p(t)&&h++});for(let n of t)if(typeof n==`number`){let r=g(n),i=n+m,o=_(i),l=i+h;a.descend(l),e(t,r,o,a,s,c),a.ascend()}else a.descend(n),e(t,g(n),_(n),a,s,c),a.ascend();g.end(),_.end()}(L,e,e.clone(),R,null,!1),R.reset(),h)return{ok:!1,conflict:h};if(R.get(),G.length){let e=G.map(e=>e?e.get():null);if(U(i.readCursor(V(R.get())),R,(t,n,r)=>{let i=e[t];i&&(r.mergeTree(i),e[t]=null)}),e.find(e=>e)){let t=i.writeCursor(),n=i.writeCursor(),r=0,o=0;e.forEach(e=>{e!=null&&U(i.readCursor(e),null,e=>{let i=H[e];t.writeMove(g[i].getPath(),_[i].getPath(),r++);let a=P[i];a&&a.forEach(e=>{T[e]||m!==1&&N[e]!=null||n.writeMove(v[e].getPath(),y[e].getPath(),o++)})})}),h={type:a.ConflictType.BLACKHOLE,op1:t.get(),op2:n.get()}}}}return h?{ok:!1,conflict:h}:{ok:!0,result:R.get()}}let U=e=>{let t=Error(`Transform detected write conflict`);throw t.conflict=e,t.type=t.name=`writeConflict`,t};function W(e,t,n){let r=H(e,t,n);if(r.ok)return r.result;U(r.conflict)}let G=e=>{let t=i.writeCursor();return i.readCursor(e).traverse(t,(e,t)=>{(p(e)||D(e))&&t.write(`r`,!0)}),t.get()},K=(e,t)=>{let{type:n,op1:r,op2:o}=e;switch(n){case a.ConflictType.DROP_COLLISION:return t===`left`?[null,G(o)]:[G(r),null];case a.ConflictType.RM_UNEXPECTED_CONTENT:let e=!1;return i.readCursor(r).traverse(null,t=>{t.r!==void 0&&(e=!0)}),e?[null,G(o)]:[G(r),null];case a.ConflictType.BLACKHOLE:return[G(r),G(o)];default:throw Error(`Unrecognised conflict: `+n)}};function q(e,t,n,r){let i=null;for(;;){let a=H(t,n,r);if(a.ok)return I(i,a.result);{let{conflict:o}=a;e(o)||U(o);let[s,c]=K(o,r);t=I(N(t),s),n=I(N(n),c),i=I(i,c)}}}})),O=d(l((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__exportStar||function(e,n){for(var r in e)r!==`default`&&!n.hasOwnProperty(r)&&t(n,e,r)};Object.defineProperty(e,`__esModule`,{value:!0}),n(D(),e);var r=x();Object.defineProperty(e,`ReadCursor`,{enumerable:!0,get:function(){return r.ReadCursor}}),Object.defineProperty(e,`WriteCursor`,{enumerable:!0,get:function(){return r.WriteCursor}});var i=S();Object.defineProperty(e,`ConflictType`,{enumerable:!0,get:function(){return i.ConflictType}})}))());function k(e){"@babel/helpers - typeof";return k=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},k(e)}function A(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function j(e){var t=A(e,`string`);return k(t)==`symbol`?t:t+``}function M(e,t,n){return(t=j(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var N=function(e){return e.data=`data`,e.order=`order`,e}(N||{}),P=class{constructor(){M(this,`drawingManagerData`,{}),M(this,`_oldDrawingManagerData`,{}),M(this,`_focusDrawings`,[]),M(this,`_remove$`,new n.Subject),M(this,`remove$`,this._remove$.asObservable()),M(this,`_add$`,new n.Subject),M(this,`add$`,this._add$.asObservable()),M(this,`_update$`,new n.Subject),M(this,`update$`,this._update$.asObservable()),M(this,`_order$`,new n.Subject),M(this,`order$`,this._order$.asObservable()),M(this,`_group$`,new n.Subject),M(this,`group$`,this._group$.asObservable()),M(this,`_ungroup$`,new n.Subject),M(this,`ungroup$`,this._ungroup$.asObservable()),M(this,`_refreshTransform$`,new n.Subject),M(this,`refreshTransform$`,this._refreshTransform$.asObservable()),M(this,`_visible$`,new n.Subject),M(this,`visible$`,this._visible$.asObservable()),M(this,`_focus$`,new n.Subject),M(this,`focus$`,this._focus$.asObservable()),M(this,`_featurePluginUpdate$`,new n.Subject),M(this,`featurePluginUpdate$`,this._featurePluginUpdate$.asObservable()),M(this,`_featurePluginAdd$`,new n.Subject),M(this,`featurePluginAdd$`,this._featurePluginAdd$.asObservable()),M(this,`_featurePluginRemove$`,new n.Subject),M(this,`featurePluginRemove$`,this._featurePluginRemove$.asObservable()),M(this,`_featurePluginOrderUpdate$`,new n.Subject),M(this,`featurePluginOrderUpdate$`,this._featurePluginOrderUpdate$.asObservable()),M(this,`_featurePluginGroupUpdate$`,new n.Subject),M(this,`featurePluginGroupUpdate$`,this._featurePluginGroupUpdate$.asObservable()),M(this,`_featurePluginUngroupUpdate$`,new n.Subject),M(this,`featurePluginUngroupUpdate$`,this._featurePluginUngroupUpdate$.asObservable()),M(this,`_visible`,!0),M(this,`_editable`,!0)}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(e=>{let t=this._getCurrentBySearch(e);t!=null&&(t.transform=e.transform,t.transforms=e.transforms,t.isMultiTransform=e.isMultiTransform)}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return this.drawingManagerData[e]||{}}removeDrawingDataForUnit(e){let t=this.drawingManagerData[e];if(t==null)return;delete this.drawingManagerData[e];let n=[];Object.keys(t).forEach(r=>{let i=t[r];(i==null?void 0:i.data)!=null&&Object.keys(i.data).forEach(t=>{n.push({unitId:e,subUnitId:r,drawingId:t})})}),n.length>0&&this.removeNotification(n)}registerDrawingData(e,t){this.drawingManagerData[e]=t}initializeNotification(e){let t=[],n=this.drawingManagerData[e];n!=null&&(Object.keys(n).forEach(r=>{this._establishDrawingMap(e,r);let i=n[r];Object.keys(i.data).forEach(n=>{let a=i.data[n];a.unitId=e,a.subUnitId=r,t.push(a)})}),t.length>0&&this.addNotification(t))}getDrawingData(e,t){return this._getDrawingData(e,t)}setDrawingData(e,t,n){this.drawingManagerData[e][t].data=n}getBatchAddOp(e){let t=[],n=[],r=[];e.forEach(e=>{let{op:i,invertOp:a}=this._addByParam(e);t.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),n.push(i),r.push(a)});let i=n.reduce(O.type.compose,null),a=r.reduce(O.type.compose,null),{unitId:o,subUnitId:s}=e[0];return{undo:a,redo:i,unitId:o,subUnitId:s,objects:t}}getBatchRemoveOpInOder(e){if(e.length===0)return{undo:null,redo:null,unitId:``,subUnitId:``,objects:[]};let t=this.getDrawingOrder(e[0].unitId,e[0].subUnitId),n=new Map;return t.forEach((e,t)=>{n.set(e,t)}),e.sort((e,t)=>{var r,i;return((r=n.get(e.drawingId))==null?-1/0:r)-((i=n.get(t.drawingId))==null?-1/0:i)}),this.getBatchRemoveOp(e)}getBatchRemoveOp(e){var n;let r=new Set,i=[];e.forEach(e=>{let n=this.getDrawingByParam(e);if((n==null?void 0:n.drawingType)===t.DrawingTypeEnum.DRAWING_GROUP){let t=this.getDrawingsByGroupNested(e);if(t){let{flatChildren:e,groups:n}=t;[...e==null?[]:e,...n].forEach(e=>{r.has(e.drawingId)||(r.add(e.drawingId),i.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}))})}else r.has(e.drawingId)||(r.add(e.drawingId),i.push(e))}else r.has(e.drawingId)||(r.add(e.drawingId),i.push(e))});let{unitId:a,subUnitId:o}=(n=i[0])==null?e[0]:n,s=this._getDrawingOrder(a,o),c=new Map;s.forEach((e,t)=>c.set(e,t)),i.sort((e,t)=>{var n,r;return((n=c.get(e.drawingId))==null?-1/0:n)-((r=c.get(t.drawingId))==null?-1/0:r)});let l=[],u=[];i.forEach(e=>{let{op:t,invertOp:n}=this._removeByParam(e);l.unshift(t),u.push(n)});let d=l.reduce(O.type.compose,null);return{undo:u.reduce(O.type.compose,null),redo:d,unitId:a,subUnitId:o,objects:i}}getBatchUpdateOp(e){let t=[],n=[],r=[];e.forEach(e=>{let{op:i,invertOp:a}=this._updateByParam(e);t.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),n.push(i),r.push(a)});let i=n.reduce(O.type.compose,null),a=r.reduce(O.type.compose,null),{unitId:o,subUnitId:s}=e[0];return{undo:a,redo:i,unitId:o,subUnitId:s,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){let t=[],{unitId:n,subUnitId:r}=e[0].parent;e.forEach(e=>{t.push(this._getGroupDrawingOp(e))});let i=t.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(i,this.drawingManagerData),redo:i,unitId:n,subUnitId:r,objects:e}}getUngroupDrawingOp(e){let t=[],{unitId:n,subUnitId:r}=e[0].parent;e.forEach(e=>{t.push(this._getUngroupDrawingOp(e))});let i=t.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(i,this.drawingManagerData),redo:i,unitId:n,subUnitId:r,objects:e}}getDrawingsByGroup(e){let{unitId:t,subUnitId:n,drawingId:r}=e;if(this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})==null)return[];let i=this._getDrawingData(t,n),a=[];return Object.keys(i).forEach(e=>{let t=i[e];t.groupId===r&&a.push(t)}),a}getDrawingsByGroupNested(e){let{unitId:n,subUnitId:r}=e,i=this.getDrawingByParam(e);if(!i)return null;let a=this._getDrawingData(n,r),o=new Map;Object.values(a).forEach(e=>{e.groupId!=null&&(o.has(e.groupId)||o.set(e.groupId,[]),o.get(e.groupId).push(e.drawingId))});let s=[],c=[],l={},u=e=>{var n;let{drawingId:r}=e,i=(n=o.get(r))==null?[]:n;l[r]={drawingId:r,children:i},i.forEach(e=>{let n=a[e];n&&(n.drawingType===t.DrawingTypeEnum.DRAWING_GROUP?(u(n),c.push(n)):s.push(n))})};return u(i),c.push(i),{nestedIdRecord:l,flatChildren:s,groups:c}}_getGroupDrawingOp(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=[];o.push(O.insertOp([r,i,N.data,a],t));let s=-1/0;return n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:r});s=Math.max(s,i),o.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),s===-1/0&&(s=this._getDrawingOrder(r,i).length),o.push(O.insertOp([r,i,N.order,s],a)),o.reduce(O.type.compose,null)}_getUngroupDrawingOp(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=[];return n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e;o.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),o.push(O.removeOp([r,i,N.data,a],!0)),o.push(O.removeOp([r,i,N.order,this._getDrawingOrder(r,i).indexOf(a)],!0)),o.reduce(O.type.compose,null)}applyJson1(e,t,n){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=O.type.apply(this.drawingManagerData,n)}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){let[t,n,r]=e.split(`#-#`);return this._getCurrentBySearch({unitId:t,subUnitId:n,drawingId:r})}focusDrawing(e){if(e==null||e.length===0){this._focusDrawings=[],this._focus$.next([]);return}let t=[];e.forEach(e=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=e,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&t.push(o)}),t.length>0&&(this._focusDrawings=t,this._focus$.next(t))}getFocusDrawings(){let e=[];return this._focusDrawings.forEach(t=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=t,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&e.push(o)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,n){this.drawingManagerData[e][t].order=n}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=[],a=this.getDrawingOrder(t,n),o=[...r];r.forEach(e=>{let r=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:e});if(r===-1||r===a.length-1)return;let s=O.moveOp([t,n,N.order,r],[t,n,N.order,r+1]);i.push(s),o.includes(a[r+1])||o.push(a[r+1])});let s=i.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(s,this.drawingManagerData),redo:s,unitId:t,subUnitId:n,objects:{...e,drawingIds:o}}}getBackwardDrawingOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=[],a=this.getDrawingOrder(t,n),o=[...r];r.forEach(e=>{let r=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:e});if(r===-1||r===0)return;let s=O.moveOp([t,n,N.order,r],[t,n,N.order,r-1]);i.push(s),o.includes(a[r-1])||o.push(a[r-1])});let s=i.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(s,this.drawingManagerData),redo:s,unitId:t,subUnitId:n,objects:{...e,drawingIds:o}}}getFrontDrawingsOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getOrderFromSearchParams(t,n,r),a=[...r],o=this.getDrawingOrder(t,n),s=[];i.forEach(e=>{let{drawingId:r}=e,i=this._getDrawingCount(t,n)-1,c=O.moveOp([t,n,N.order,this._getDrawingOrder(t,n).indexOf(r)],[t,n,N.order,i]);s.push(c),a.includes(o[i])||a.push(o[i])});let c=s.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:t,subUnitId:n,objects:{...e,drawingIds:a}}}getBackDrawingsOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getOrderFromSearchParams(t,n,r,!0),a=[...r],o=this.getDrawingOrder(t,n),s=[];i.forEach(e=>{let{drawingId:r}=e,i=O.moveOp([t,n,N.order,this._getDrawingOrder(t,n).indexOf(r)],[t,n,N.order,0]);s.push(i),a.includes(o[0])||a.push(o[0])});let c=s.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:t,subUnitId:n,objects:{...e,drawingIds:a}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,n,r,i=!1){return r.map(t=>({drawingId:t,zIndex:this._hasDrawingOrder({unitId:e,subUnitId:n,drawingId:t})})).sort(i===!1?t.sortRules:t.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;let{unitId:t,subUnitId:n,drawingId:r}=e;return this._establishDrawingMap(t,n),this._getDrawingOrder(t,n).indexOf(r)}_getCurrentBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return(t=this.drawingManagerData[n])==null||(t=t[r])==null||(t=t.data)==null?void 0:t[i]}_getOldBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return(t=this._oldDrawingManagerData[n])==null||(t=t[r])==null||(t=t.data)==null?void 0:t[i]}_establishDrawingMap(e,t,n){var r;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),n==null?null:(r=this.drawingManagerData[e][t].data)==null?void 0:r[n]}_addByParam(e){let{unitId:t,subUnitId:n,drawingId:r}=e;this._establishDrawingMap(t,n,r);let i=[O.insertOp([t,n,N.data,r],e),O.insertOp([t,n,N.order,this._getDrawingOrder(t,n).length],r)].reduce(O.type.compose,null);return{op:i,invertOp:O.type.invertWithDoc(i,this.drawingManagerData)}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};let{unitId:t,subUnitId:n,drawingId:r}=e;if(this._establishDrawingMap(t,n,r)==null)return{op:[],invertOp:[]};let i=[O.removeOp([t,n,N.data,r],!0),O.removeOp([t,n,N.order,this._getDrawingOrder(t,n).indexOf(r)],!0)].reduce(O.type.compose,null);return{op:i,invertOp:O.type.invertWithDoc(i,this.drawingManagerData)}}_updateByParam(e){let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._establishDrawingMap(t,n,r);if(i==null)return{op:[],invertOp:[]};let a=this._getUpdateParamCompareOp(e,i).reduce(O.type.compose,null);return{op:a,invertOp:O.type.invertWithDoc(a,this.drawingManagerData)}}_getUpdateParamCompareOp(e,t){let{unitId:n,subUnitId:r,drawingId:i}=e,a=[];return Object.keys(e).forEach(o=>{let s=e[o],c=t[o];c!==s&&a.push(O.replaceOp([n,r,N.data,i,o],c,s))}),a}_getDrawingData(e,t){var n;return((n=this.drawingManagerData[e])==null||(n=n[t])==null?void 0:n.data)||{}}_getDrawingOrder(e,t){var n;return((n=this.drawingManagerData[e])==null||(n=n[t])==null?void 0:n.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(e){this._visible=e}setDrawingEditable(e){this._editable=e}},F=class extends P{},I=class{constructor(){M(this,`_waitCount`,0),M(this,`_change$`,new n.Subject),M(this,`change$`,this._change$),M(this,`_imageSourceCache`,new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,n){if(n===t.ImageSourceType.BASE64){let t=new Image;return t.src=e,t}return this._imageSourceCache.get(e)}addImageSourceCache(e,n,r){n===t.ImageSourceType.BASE64||r==null||this._imageSourceCache.set(e,r)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((n,r)=>{if(!f.includes(e.type)){r(Error(t.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>5242880){r(Error(t.ImageUploadStatusType.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}let i=new FileReader;i.readAsDataURL(e),i.onload=e=>{var i;let a=(i=e.target)==null?void 0:i.result;if(a==null){r(Error(t.ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting();return}n({imageId:(0,t.generateRandomId)(6),imageSourceType:t.ImageSourceType.BASE64,source:a,base64Cache:a,status:t.ImageUploadStatusType.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){--this._waitCount,this._change$.next(this._waitCount)}},L=class extends t.Disposable{constructor(...e){super(...e),M(this,`_urlImageDownloader`,null)}registerURLImageDownloader(e){return this._urlImageDownloader=e,(0,t.toDisposable)(()=>{this._urlImageDownloader=null})}async getImage(e){if(this._urlImageDownloader)try{return await this._urlImageDownloader(e)}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default behavior:`,t)}return e}async downloadImage(e){if(this._urlImageDownloader)try{let t=await this._urlImageDownloader(e);return await(await fetch(t)).blob()}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default fetch:`,t)}return await(await fetch(e)).blob()}};function R(e,t){return function(n,r){t(n,r,e)}}function z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let B=class extends t.Plugin{constructor(e=v,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},v,this._config);this._configService.setConfig(_,a)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var e;(0,t.mergeOverrideWithDependencies)([[t.IImageIoService,{useClass:I}],[t.IURLImageService,{useClass:L}],[p,{useClass:F}]],(e=this._config)==null?void 0:e.override).forEach(e=>this._injector.add(e))}_initCommands(){[m].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};M(B,`pluginName`,`UNIVER_DRAWING_PLUGIN`),M(B,`packageName`,h),M(B,`version`,g),B=z([R(1,(0,t.Inject)(t.Injector)),R(2,t.IConfigService),R(3,t.ICommandService)],B);function V({unitId:e,subUnitId:t,drawingId:n},r){return typeof r==`number`?`${e}#-#${t}#-#${n}#-#${r}`:`${e}#-#${t}#-#${n}`}e.DRAWING_IMAGE_ALLOW_IMAGE_LIST=f,e.DRAWING_IMAGE_ALLOW_SIZE=5242880,e.DRAWING_IMAGE_COUNT_LIMIT=10,e.DRAWING_IMAGE_HEIGHT_LIMIT=500,e.DRAWING_IMAGE_WIDTH_LIMIT=500,e.DrawingManagerService=F,e.IDrawingManagerService=p,Object.defineProperty(e,`IImageIoService`,{enumerable:!0,get:function(){return t.IImageIoService}}),e.ImageIoService=I,Object.defineProperty(e,`ImageSourceType`,{enumerable:!0,get:function(){return t.ImageSourceType}}),Object.defineProperty(e,`ImageUploadStatusType`,{enumerable:!0,get:function(){return t.ImageUploadStatusType}}),e.SetDrawingSelectedOperation=m,e.URLImageService=L,e.UnitDrawingService=P,Object.defineProperty(e,`UniverDrawingPlugin`,{enumerable:!0,get:function(){return B}}),e.getDrawingShapeKeyByDrawingSearch=V,e.getImageSize=async e=>new Promise((t,n)=>{let r=new Image;r.src=e,r.onload=()=>{t({width:r.width,height:r.height,image:r})},r.onerror=e=>{n(e)}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDrawing={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:r(s(e)),u(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e));let f=[`image/png`,`image/jpeg`,`image/jpg`,`image/gif`,`image/bmp`],p=(0,t.createIdentifier)(`univer.drawing-manager.service`),m={id:`drawing.operation.set-drawing-selected`,type:t.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(p);return t==null?!1:(n.focusDrawing(t),!0)}};var h=`@univerjs/drawing`,g=`0.21.0`;let _=`drawing.config`;Symbol(_);let v={};var y=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0});function t(e,t){if(Array.isArray(t))return!1;for(let n in e)if(!r(e[n],t[n]))return!1;for(let n in t)if(e[n]===void 0)return!1;return!0}function n(e,t){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0}function r(e,r){return e===r?!0:e===null||r===null||typeof e!=`object`||typeof r!=`object`?!1:Array.isArray(e)?n(e,r):t(e,r)}e.default=r})),b=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0});function t(e){if(e===null)return null;if(Array.isArray(e))return e.map(t);if(typeof e==`object`){let n={};for(let r in e)n[r]=t(e[r]);return n}else return e}e.default=t})),x=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.eachChildOf=e.advancer=e.readCursor=e.writeCursor=e.WriteCursor=e.ReadCursor=e.isValidPathItem=void 0;function t(e,t){if(!e)throw Error(t)}let n=e=>typeof e==`object`&&!!e&&!Array.isArray(e),r=(e,t)=>typeof e==typeof t?e>t:typeof e==`string`&&typeof t==`number`;function i(e,t){for(let n in e){let r=n;t.write(r,e[r])}}e.isValidPathItem=e=>typeof e==`number`||typeof e==`string`&&e!==`__proto__`;var a=class{constructor(e=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=e}ascend(){t(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):(t(this.idx>0),this.idx--,n(this.container[this.idx])&&this.idx--)}getPath(){let e=[],t=this.container,r=this.parents.length-1,i=this.idx;for(;i>=0;)e.unshift(t[i]),i===0?(i=this.indexes[r*2],t=this.parents[r--]):i-=n(t[i-1])?2:1;return e}},o=class e extends a{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return t(this.container!=null,`Invalid call to getKey before cursor descended`),this.container[this.idx]}getComponent(){let e;return this.container&&this.container.length>this.idx+1&&n(e=this.container[this.idx+1])?e:null}descendFirst(){let e=this.idx+1;if(!this.container||e>=this.container.length||n(this.container[e])&&e+1>=this.container.length)return!1;n(this.container[e])&&e++;let t=this.container[e];return Array.isArray(t)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(e),this.idx=0,this.container=t):this.idx=e,!0}nextSibling(){if(t(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;let e=this.indexes[this.indexes.length-1]+1,n=this.parents[this.parents.length-1];return e>=n.length?!1:(t(!isNaN(e)),this.indexes[this.indexes.length-1]=e,this.container=n[e],!0)}_init(e,t,n,r){this.container=e,this.idx=t,this.parents=n.slice(),this.indexes=r.slice()}clone(){let t=new e;return t._init(this.container,this.idx,this.parents,this.indexes),t}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(e,t){let n=this.getComponent();n&&t(n,e);for(let n of this)e&&e.descend(n),this.traverse(e,t),e&&e.ascend()}eachPick(e,t){this.traverse(e,(e,n)=>{e.p!=null&&t(e.p,n)})}eachDrop(e,t){this.traverse(e,(e,n)=>{e.d!=null&&t(e.d,n)})}};e.ReadCursor=o;var s=class extends a{constructor(e=null){super(e),this.pendingDescent=[],this._op=e}flushDescent(){t(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let e=0;e<this.pendingDescent.length;e++){let i=this.pendingDescent[e],a=this.idx+1;if(a<this.container.length&&n(this.container[a])&&a++,t(a===this.container.length||!n(this.container[a])),a===this.container.length)this.container.push(i),this.idx=a;else if(this.container[a]===i)this.idx=a;else{if(!Array.isArray(this.container[a])){let e=this.container.splice(a,this.container.length-a);this.container.push(e),this.lcIdx>-1&&(this.lcIdx=a)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(t(r(i,this.container[this.lcIdx][0])),a=this.lcIdx+1,this.lcIdx=-1);a<this.container.length&&r(i,this.container[a][0]);)a++;if(this.indexes.push(a),this.idx=0,a<this.container.length&&this.container[a][0]===i)this.container=this.container[a];else{let e=[i];this.container.splice(a,0,e),this.container=e}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();let e=this.idx+1;if(e<this.container.length&&n(this.container[e]))return this.container[e];{let t={};return this.container.splice(e,0,t),t}}write(e,n){let r=this.getComponent();t(r[e]==null||r[e]===n,`Internal consistency error: Overwritten component. File a bug`),r[e]=n}get(){return this._op}descend(t){if(!e.isValidPathItem(t))throw Error(`Invalid JSON key`);this.pendingDescent.push(t)}descendPath(e){return this.pendingDescent.push(...e),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(e,n=i){if(e===null)return;if(t(Array.isArray(e)),e===this._op)throw Error(`Cannot merge into my own tree`);let r=this.lcIdx,a=this.parents.length,o=0;for(let t=0;t<e.length;t++){let r=e[t];typeof r==`string`||typeof r==`number`?(o++,this.descend(r)):Array.isArray(r)?this.mergeTree(r,n):typeof r==`object`&&n(r,this)}for(;o--;)this.ascend();this.lcIdx=this.parents.length===a?r:-1}at(e,t){this.descendPath(e),t(this);for(let t=0;t<e.length;t++)this.ascend();return this}writeAtPath(e,t,n){return this.at(e,()=>this.write(t,n)),this.reset(),this}writeMove(e,t,n=0){return this.writeAtPath(e,`p`,n).writeAtPath(t,`d`,n)}getPath(){let e=super.getPath();return e.push(...this.pendingDescent),e}};e.WriteCursor=s,e.writeCursor=()=>new s,e.readCursor=e=>new o(e);function c(e,t,n){let i,a;a=i=e?e.descendFirst():!1;function o(i){let o;for(;a;){let s=o=e.getKey();if(i!=null){let n=!1;if(t&&typeof s==`number`&&(o=t(s,e.getComponent()),o<0&&(o=~o,n=!0)),r(o,i))return null;if(o===i&&!n)return e}n&&typeof o==`number`&&n(o,e.getComponent()),a=e.nextSibling()}return null}return o.end=()=>{i&&e.ascend()},o}e.advancer=c;function l(e,t,n){let i,a,o,s;for(i=a=e&&e.descendFirst(),o=s=t&&t.descendFirst();i||o;){let a=i?e.getKey():null,s=o?t.getKey():null;a!==null&&s!==null&&(r(s,a)?s=null:a!==s&&(a=null)),n(a==null?s:a,a==null?null:e,s==null?null:t),a!=null&&i&&(i=e.nextSibling()),s!=null&&o&&(o=t.nextSibling())}a&&e.ascend(),s&&t.ascend()}e.eachChildOf=l})),S=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.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`})(e.ConflictType||(e.ConflictType={}))})),C=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.uniToStrPos=e.strPosToUni=void 0,e.strPosToUni=(e,t=e.length)=>{let n=0,r=0;for(;r<t;r++){let t=e.charCodeAt(r);t>=55296&&t<=57343&&(n++,r++)}if(r!==t)throw Error(`Invalid offset - splits unicode bytes`);return r-n},e.uniToStrPos=(e,t)=>{let n=0;for(;t>0;t--){let t=e.charCodeAt(n);n+=t>=55296&&t<=57343?2:1}return n}})),w=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.uniSlice=e.dlen=e.eachOp=void 0;let t=C(),n=t=>{if(!Array.isArray(t))throw Error(`Op must be an array of components`);let n=null;for(let r=0;r<t.length;r++){let i=t[r];switch(typeof i){case`object`:if(typeof i.d!=`number`&&typeof i.d!=`string`)throw Error(`Delete must be number or string`);if(e.dlen(i.d)<=0)throw Error(`Deletes must not be empty`);break;case`string`:if(!(i.length>0))throw Error(`Inserts cannot be empty`);break;case`number`:if(!(i>0))throw Error(`Skip components must be >0`);if(typeof n==`number`)throw Error(`Adjacent skip components should be combined`);break}n=i}if(typeof n==`number`)throw Error(`Op has a trailing skip`)};function r(n,r){let i=0,a=0;for(let o=0;o<n.length;o++){let s=n[o];switch(r(s,i,a),typeof s){case`object`:i+=e.dlen(s.d);break;case`string`:a+=t.strPosToUni(s);break;case`number`:i+=s,a+=s;break}}}e.eachOp=r;function i(e,t){let n=[],i=s(n);return r(e,(e,n,r)=>{i(t(e,n,r))}),d(n)}let a=e=>e,o=e=>i(e,a);e.dlen=e=>typeof e==`number`?e:t.strPosToUni(e);let s=t=>n=>{if(!(!n||n.d===0||n.d===``))if(t.length===0)t.push(n);else if(typeof n==typeof t[t.length-1])if(typeof n==`object`){let r=t[t.length-1];r.d=typeof r.d==`string`&&typeof n.d==`string`?r.d+n.d:e.dlen(r.d)+e.dlen(n.d)}else t[t.length-1]+=n;else t.push(n)},c=e=>typeof e==`number`?e:typeof e==`string`?t.strPosToUni(e):typeof e.d==`number`?e.d:t.strPosToUni(e.d);e.uniSlice=(e,n,r)=>{let i=t.uniToStrPos(e,n),a=r==null?1/0:t.uniToStrPos(e,r);return e.slice(i,a)};let l=(t,n,r)=>typeof t==`number`?r==null?t-n:Math.min(t,r)-n:e.uniSlice(t,n,r),u=n=>{let r=0,i=0;return{take:(a,o)=>{if(r===n.length)return a===-1?null:a;let s=n[r],c;if(typeof s==`number`)return a===-1||s-i<=a?(c=s-i,++r,i=0,c):(i+=a,a);if(typeof s==`string`){if(a===-1||o===`i`||t.strPosToUni(s.slice(i))<=a)return c=s.slice(i),++r,i=0,c;{let e=i+t.uniToStrPos(s.slice(i),a);return c=s.slice(i,e),i=e,c}}else if(a===-1||o===`d`||e.dlen(s.d)-i<=a)return c={d:l(s.d,i)},++r,i=0,c;else{let e=l(s.d,i,i+a);return i+=a,{d:e}}},peek:()=>n[r]}},d=e=>(e.length>0&&typeof e[e.length-1]==`number`&&e.pop(),e);function f(r,i,a){if(a!==`left`&&a!==`right`)throw Error(`side (`+a+`) must be 'left' or 'right'`);n(r),n(i);let o=[],l=s(o),{take:f,peek:p}=u(r);for(let n=0;n<i.length;n++){let r=i[n],o,s;switch(typeof r){case`number`:for(o=r;o>0;)s=f(o,`i`),l(s),typeof s!=`string`&&(o-=c(s));break;case`string`:a===`left`&&typeof p()==`string`&&l(f(-1)),l(t.strPosToUni(r));break;case`object`:for(o=e.dlen(r.d);o>0;)switch(s=f(o,`i`),typeof s){case`number`:o-=s;break;case`string`:l(s);break;case`object`:o-=e.dlen(s.d)}break}}let m;for(;m=f(-1);)l(m);return d(o)}function p(r,i){n(r),n(i);let a=[],o=s(a),{take:f}=u(r);for(let n=0;n<i.length;n++){let r=i[n],a,s;switch(typeof r){case`number`:for(a=r;a>0;)s=f(a,`d`),o(s),typeof s!=`object`&&(a-=c(s));break;case`string`:o(r);break;case`object`:a=e.dlen(r.d);let n=0;for(;n<a;)switch(s=f(a-n,`d`),typeof s){case`number`:o({d:l(r.d,n,n+s)}),n+=s;break;case`string`:n+=t.strPosToUni(s);break;case`object`:o(s)}break}}let p;for(;p=f(-1);)o(p);return d(a)}let m=(n,r)=>{let i=0;for(let a=0;a<r.length&&n>i;a++){let o=r[a];switch(typeof o){case`number`:i+=o;break;case`string`:let r=t.strPosToUni(o);i+=r,n+=r;break;case`object`:n-=Math.min(e.dlen(o.d),n-i);break}}return n},h=(e,t)=>typeof e==`number`?m(e,t):e.map(e=>m(e,t));function g(e,t,n){return i(e,(e,r)=>typeof e==`object`&&typeof e.d==`number`?{d:n.slice(t,r,r+e.d)}:e)}function _(e){return i(e,e=>{switch(typeof e){case`object`:if(typeof e.d==`number`)throw Error(`Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.`);return e.d;case`string`:return{d:e};case`number`:return e}})}function v(e){return i(e,e=>typeof e==`object`&&typeof e.d==`string`?{d:t.strPosToUni(e.d)}:e)}function y(e){let t=!0;return r(e,e=>{typeof e==`object`&&typeof e.d==`number`&&(t=!1)}),t}function b(t){return{name:`text-unicode`,uri:`http://sharejs.org/types/text-unicode`,trim:d,normalize:o,checkOp:n,create(e=``){if(typeof e!=`string`)throw Error(`Initial data must be a string`);return t.create(e)},apply(r,i){n(i);let a=t.builder(r);for(let t=0;t<i.length;t++){let n=i[t];switch(typeof n){case`number`:a.skip(n);break;case`string`:a.append(n);break;case`object`:a.del(e.dlen(n.d));break}}return a.build()},transform:f,compose:p,transformPosition:m,transformSelection:h,isInvertible:y,makeInvertible(e,n){return g(e,n,t)},stripInvertible:v,invert:_,invertWithDoc(e,n){return _(g(e,n,t))},isNoop:e=>e.length===0}}e.default=b})),T=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=w(),n=C();function r(e,r){return{get:e,getLength(){return e().length},insert(t,i,a){return r([n.strPosToUni(e(),t),i],a)},remove(t,i,a){return r([n.strPosToUni(e(),t),{d:i}],a)},_onOp(e){t.eachOp(e,(e,n,r)=>{switch(typeof e){case`string`:this.onInsert&&this.onInsert(r,e);break;case`object`:let n=t.dlen(e.d);this.onRemove&&this.onRemove(r,n)}})},onInsert:null,onRemove:null}}e.default=r,r.provides={text:!0}})),E=l((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}):function(e,t){e.default=t}),r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)Object.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r},i=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,`__esModule`,{value:!0}),e.type=e.remove=e.insert=void 0;let a=C(),o=r(w()),s=i(T()),c={create(e){return e},toString(e){return e},builder(e){if(typeof e!=`string`)throw Error(`Invalid document snapshot: `+e);let t=[];return{skip(n){let r=a.uniToStrPos(e,n);if(r>e.length)throw Error(`The op is too long for this document`);t.push(e.slice(0,r)),e=e.slice(r)},append(e){t.push(e)},del(t){e=e.slice(a.uniToStrPos(e,t))},build(){return t.join(``)+e}}},slice:o.uniSlice},l=o.default(c);e.type=Object.assign(Object.assign({},l),{api:s.default}),e.insert=(e,t)=>t.length===0?[]:e===0?[t]:[e,t],e.remove=(e,t)=>o.dlen(t)===0?[]:e===0?[{d:t}]:[e,{d:t}];var u=w();Object.defineProperty(e,`makeType`,{enumerable:!0,get:function(){return u.default}})})),D=l((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,`__esModule`,{value:!0}),e.editOp=e.replaceOp=e.insertOp=e.moveOp=e.removeOp=e.type=void 0;let n=t(y()),r=t(b()),i=x(),a=S(),o=()=>{};function s(e,t){if(!e)throw Error(t)}let c=!1;e.type={name:`json1`,uri:`http://sharejs.org/types/JSONv1`,readCursor:i.readCursor,writeCursor:i.writeCursor,create:e=>e,isNoop:e=>e==null,setDebug(e){c=e,o.quiet=!e},registerSubtype:C,checkValidOp:M,normalize:N,apply:P,transformPosition:F,compose:I,tryTransform:H,transform:W,makeInvertible:z,invert:L,invertWithDoc:B,RM_UNEXPECTED_CONTENT:a.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:a.ConflictType.DROP_COLLISION,BLACKHOLE:a.ConflictType.BLACKHOLE,transformNoConflict:(e,t,n)=>q(()=>!0,e,t,n),typeAllowingConflictsPred:t=>Object.assign(Object.assign({},e.type),{transform:(e,n,r)=>q(t,e,n,r)})};let l=e=>e?e.getComponent():null;function u(e){return e&&typeof e==`object`&&!Array.isArray(e)}let d=e=>Array.isArray(e)?e.slice():typeof e==`object`&&e?Object.assign({},e):e,f=e=>e&&(e.p!=null||e.r!==void 0),p=e=>e&&(e.d!=null||e.i!==void 0);function m(e,t){return s(e!=null),typeof t==`number`?(s(Array.isArray(e),`Invalid key - child is not an array`),(e=e.slice()).splice(t,1)):(s(u(e),`Invalid key - child is not an object`),delete(e=Object.assign({},e))[t]),e}function h(e,t,n){return typeof t==`number`?(s(e!=null,`Container is missing for key`),s(Array.isArray(e),`Cannot use numerical key for object container`),s(e.length>=t,`Cannot insert into out of bounds index`),e.splice(t,0,n)):(s(u(e),`Cannot insert into missing item`),s(e[t]===void 0,`Trying to overwrite value at key. Your op needs to remove it first`),e[t]=n),n}e.removeOp=(e,t=!0)=>i.writeCursor().writeAtPath(e,`r`,t).get(),e.moveOp=(e,t)=>i.writeCursor().writeMove(e,t).get(),e.insertOp=(e,t)=>i.writeCursor().writeAtPath(e,`i`,t).get(),e.replaceOp=(e,t,n)=>i.writeCursor().at(e,e=>{e.write(`r`,t),e.write(`i`,n)}).get(),e.editOp=(e,t,n,r=!1)=>i.writeCursor().at(e,e=>k(e,t,n,r)).get();let g=(e,t)=>e!=null&&(typeof t==`number`?Array.isArray(e):typeof e==`object`),_=(e,t)=>g(e,t)?e[t]:void 0,v={};function C(e){let t=e.type?e.type:e;t.name&&(v[t.name]=t),t.uri&&(v[t.uri]=t)}let w=e=>{let t=v[e];if(t)return t;throw Error(`Missing type: `+e)};C(E());let T=(e,t)=>e+t;C({name:`number`,apply:T,compose:T,invert:e=>-e,transform:e=>e});let D=e=>e==null?null:e.et?w(e.et):e.es?v[`text-unicode`]:e.ena==null?null:v.number,O=e=>e.es?e.es:e.ena==null?e.e:e.ena,k=(e,t,n,r=!1)=>{let[i,a]=typeof t==`string`?[w(t),t]:[t,t.name];!r&&i.isNoop&&i.isNoop(n)||(a===`number`?e.write(`ena`,n):a===`text-unicode`?e.write(`es`,n):(e.write(`et`,a),e.write(`e`,n)))};function A(e){s(typeof e==`number`),s(e>=0),s(e===(0|e))}function j(e){typeof e==`number`?A(e):s(typeof e==`string`)}function M(e){if(e===null)return;let t=new Set,n=new Set,r=e=>{let r=!0,i=!1;for(let a in e){let o=e[a];if(r=!1,s(a===`p`||a===`r`||a===`d`||a===`i`||a===`e`||a===`es`||a===`ena`||a===`et`,`Invalid component item '`+a+`'`),a===`p`)A(o),s(!t.has(o)),t.add(o),s(e.r===void 0);else if(a===`d`)A(o),s(!n.has(o)),n.add(o),s(e.i===void 0);else if(a===`e`||a===`es`||a===`ena`){s(!i),i=!0;let t=D(e);s(t,`Missing type in edit`),t.checkValidOp&&t.checkValidOp(O(e))}}s(!r)},a=(e,t,n)=>{if(!Array.isArray(e))throw Error(`Op must be null or a list`);if(e.length===0)throw Error(`Empty descent`);t||j(e[0]);let o=1,c=0,l=0;for(let t=0;t<e.length;t++){let u=e[t];if(s(u!=null),Array.isArray(u)){let e=a(u,!1,n);if(c){let t=typeof l,n=typeof e;t===n?s(l<e,`descent keys are not in order`):s(t===`number`&&n===`string`)}l=e,c++,o=3}else typeof u==`object`?(s(o===1,`Prev not scalar - instead ${o}`),r(u),o=2):(s(o!==3),j(u),s(i.isValidPathItem(u),`Invalid path key`),o=1)}return s(c!==1,`Operation makes multiple descents. Remove some []`),s(o===2||o===3),e[0]};a(e,!0,!1),s(t.size===n.size,`Mismatched picks and drops in op`);for(let e=0;e<t.size;e++)s(t.has(e)),s(n.has(e))}function N(e){let t=0,n=[],r=i.writeCursor();return r.mergeTree(e,(e,r)=>{let i=D(e);if(i){let t=O(e);k(r,i,i.normalize?i.normalize(t):t)}for(let i of[`r`,`p`,`i`,`d`])if(e[i]!==void 0){let o=i===`p`||i===`d`?(a=e[i],n[a]==null&&(n[a]=t++),n[a]):e[i];r.write(i,o)}var a}),r.get()}function P(e,t){if(o.quiet=!c,M(t),t===null)return e;let n=[];return function e(t,r){let i=t,a=0,o={root:t},c=0,l=o,u=`root`;function f(){for(;c<a;c++){let e=r[c];typeof e!=`object`&&(s(g(l,u)),l=l[u]=d(l[u]),u=e)}}for(;a<r.length;a++){let t=r[a];if(Array.isArray(t)){let n=e(i,t);n!==i&&n!==void 0&&(f(),i=l[u]=n)}else if(typeof t==`object`){t.d==null?t.i!==void 0&&(f(),i=h(l,u,t.i)):(f(),i=h(l,u,n[t.d]));let e=D(t);if(e)f(),i=l[u]=e.apply(i,O(t));else if(t.e!==void 0)throw Error(`Subtype `+t.et+` undefined`)}else i=_(i,t)}return o.root}(e=function e(t,r){let i=[],a=0;for(;a<r.length;a++){let e=r[a];if(Array.isArray(e))break;typeof e!=`object`&&(i.push(t),t=_(t,e))}for(let n=r.length-1;n>=a;n--)t=e(t,r[n]);for(--a;a>=0;a--){let e=r[a];if(typeof e!=`object`){let n=i.pop();t=t===_(n,e)?n:t===void 0?m(n,e):(c=e,l=t,(o=d(o=n))[c]=l,o)}else f(e)&&(s(t!==void 0,`Cannot pick up or remove undefined`),e.p!=null&&(n[e.p]=t),t=void 0)}var o,c,l;return t}(e,t),t)}function F(e,t){e=e.slice(),M(t);let n=i.readCursor(t),r,a,o=!1,s=[];for(let t=0;;t++){let c=e[t],l=n.getComponent();if(l&&(l.r===void 0?l.p!=null&&(o=!1,r=l.p,a=t):o=!0),t>=e.length)break;let u=0,d=i.advancer(n,void 0,(e,t)=>{f(t)&&u++});s.unshift(d);let p=d(c);if(typeof c==`number`&&(e[t]-=u),!p)break}if(s.forEach(e=>e.end()),o)return null;let c=()=>{let t=0;if(r!=null){let r=n.getPath();t=r.length,e=r.concat(e.slice(a))}for(;t<e.length;t++){let r=e[t],a=l(n),o=D(a);if(o){let n=O(a);o.transformPosition&&(e[t]=o.transformPosition(e[t],n));break}let s=0,c=i.advancer(n,(e,t)=>p(t)?~(e-s):e-s,(e,t)=>{p(t)&&s++})(r);if(typeof r==`number`&&(e[t]+=s),!c)break}};return r==null?c():n.eachDrop(null,e=>{e===r&&c()}),e}function I(e,t){if(M(e),M(t),e==null)return t;if(t==null)return e;let n=0,r=i.readCursor(e),a=i.readCursor(t),o=i.writeCursor(),c=[],u=[],d=[],m=[],h=[],g=[],_=new Set;r.traverse(null,e=>{e.p!=null&&(d[e.p]=r.clone())}),a.traverse(null,e=>{e.d!=null&&(m[e.d]=a.clone())});let v=i.writeCursor();return function e(t,r,a,o,v,y,b,x){s(r||a);let S=l(r),C=l(a),w=!!C&&C.r!==void 0,T=!!S&&S.i!==void 0,E=S?S.d:null,A=C?C.p:null,j=(y||w)&&A==null;if(A!=null)o=m[A],b=u[A]=new i.WriteCursor;else if(C&&C.r!==void 0)o=null;else{let e=l(o);e&&e.d!=null&&(o=null)}let M=l(o);if(E!=null)if(t=d[E],x=c[E]=new i.WriteCursor,j)y&&!w&&x.write(`r`,!0);else{let e=h[E]=n++;b.write(`d`,e)}else if(S&&S.i!==void 0)t=null;else{let e=l(t);e&&e.p!=null&&(t=null)}let N;T?(s(v===void 0),N=S.i):N=v;let P=(A==null?!T||y||w:N===void 0)?null:b.getComponent();if(A!=null){if(!(v!==void 0||T)){let e=E==null?n++:h[E];g[A]=e,x.write(`p`,e)}}else w&&(T||v!==void 0||(C.r,x.write(`r`,C.r)));let F=j?null:D(S),I=D(M);if((F||I)&&(F&&F.name,I&&I.name),F&&I){s(F===I);let e=O(S),t=O(M),n=F.compose(e,t);k(b,F,n),_.add(M)}else F?k(b,F,O(S)):I&&(k(b,I,O(M)),_.add(M));let L=typeof N==`object`&&!!N,R=!1,z=0,B=0,V=0,H=0,U=0,W=i.advancer(o,(e,t)=>p(t)?H-e-1:e-H,(e,t)=>{p(t)&&H++}),G=i.advancer(t,(e,t)=>f(t)?z-e-1:e-z,(e,t)=>{f(t)&&z++});if(i.eachChildOf(r,a,(t,n,r)=>{let i,a,o=t,c=t,u=t;if(typeof t==`number`){let e=t+V;a=W(e),c=e+H;let d=t+B;i=G(d),p(l(a))&&(i=null),o=d+z,u=t+U,s(o>=0,`p1PickKey is negative`),s(c>=0,`p2DropKey is negative`);let m=p(l(n)),h=f(l(r));(m||h&&!j)&&U--,m&&B--,h&&V--}else i=G(t),a=W(t);x.descend(o),b.descend(c);let d=L&&!p(l(n))?N[u]:void 0,m=e(i,n,r,a,d,j,b,x);var h,g,_;L&&!j?d!==m&&(R||(N=Array.isArray(N)?N.slice():Object.assign({},N),R=!0),h=N,_=m,typeof(g=u)==`number`?(s(Array.isArray(h)),s(g<h.length)):(s(!Array.isArray(h)),s(h[g]!==void 0)),_===void 0?typeof g==`number`?h.splice(g,1):delete h[g]:h[g]=_):s(m===void 0),b.ascend(),x.ascend()}),G.end(),W.end(),P!=null)P.i=N;else if(!y&&!w&&A==null)return N}(r,r.clone(),a,a.clone(),void 0,!1,o,v),o.reset(),o.mergeTree(v.get()),o.reset(),o.get(),c.map(e=>e.get()),u.map(e=>e.get()),r.traverse(o,(e,t)=>{let n=e.p;if(n!=null){let e=h[n];e!=null&&t.write(`p`,e);let r=c[n];r&&r.get(),r&&t.mergeTree(r.get())}else e.r!==void 0&&t.write(`r`,e.r)}),o.reset(),o.get(),a.traverse(o,(e,t)=>{let n=e.d;if(n!=null){let e=g[n];e!=null&&t.write(`d`,e);let r=u[n];r&&t.mergeTree(r.get())}else e.i!==void 0&&t.write(`i`,e.i);let r=D(e);r&&!_.has(e)&&k(t,r,O(e))}),o.get()}function L(e){if(e==null)return null;let t=new i.ReadCursor(e),n=new i.WriteCursor,r,a=[],o=[];return function e(t,n,i){let o=t.getComponent(),s,c=!1;if(o){o.p!=null&&(n.write(`d`,o.p),a[o.p]=t.clone()),o.r!==void 0&&n.write(`i`,o.r),o.d!=null&&(n.write(`p`,o.d),i=void 0),o.i!==void 0&&(i=s=o.i);let e=D(o);e&&(i===void 0?(r||(r=new Set),r.add(o)):(O(o),i=e.apply(i,O(o)),c=!0))}let l=0;for(let r of t){n.descend(r);let a=typeof r==`number`?r-l:r,o=_(i,a);p(t.getComponent())&&l++;let s=e(t,n,o);if(i!==void 0&&s!==void 0){if(c||(c=!0,i=d(i)),!g(i,a))throw Error(`Cannot modify child - invalid operation`);i[a]=s}n.ascend()}if(s===void 0)return c?i:void 0;n.write(`r`,i)}(t,n,void 0),r&&(n.reset(),function e(t,n,s){let c=n.getComponent();if(c){let e=c.d;if(e!=null&&(t=a[e],s=o[e]=i.writeCursor()),r.has(c)){let e=D(c);if(!e.invert)throw Error(`Cannot invert subtype ${e.name}`);k(s,e,e.invert(O(c)))}}let l=0,u=0,d=i.advancer(t,(e,t)=>f(t)?l-e-1:e-l,(e,t)=>{f(t)&&l++});for(let t of n)if(typeof t==`number`){let r=t-u,i=d(r),a=r+l;s.descend(a),e(i,n,s),p(n.getComponent())&&u++,s.ascend()}else s.descend(t),e(d(t),n,s),s.ascend();d.end()}(t.clone(),t,n),o.length&&(n.reset(),t.traverse(n,(e,t)=>{let n=e.p;if(n!=null){let e=o[n];e&&e.get(),e&&t.mergeTree(e.get())}}))),n.get()}let R=(e,t)=>e.some(e=>typeof e==`object`&&(Array.isArray(e)?R(e,t):t(e)));function z(e,t){if(e==null||!R(e,e=>{var t;return e.r!==void 0||((t=D(e))==null?void 0:t.makeInvertible)!=null}))return e;let n=new i.ReadCursor(e),a=new i.WriteCursor,o=!1,c=[],l=[],u=(e,t,n)=>{let i=e.getComponent(),a=!1;if(i){i.d!=null&&t.write(`d`,i.d),i.i!==void 0&&t.write(`i`,i.i);let r=i.p;if(r!=null&&(c[r]=e.clone(),s(n!==void 0,`Operation picks up at an invalid key`),l[r]=n,t.write(`p`,i.p)),i.r!==void 0&&n===void 0)throw Error(`Invalid doc / op in makeInvertible: removed item missing from doc`);let a=D(i);a&&(a.makeInvertible?o=!0:k(t,a,O(i),!0))}let f=0;for(let r of e){t.descend(r);let i=typeof r==`number`?r-f:r,o=_(n,i),s=u(e,t,o);o!==s&&(a||(a=!0,n=d(n)),s===void 0?(n=m(n,i),typeof r==`number`&&f++):n[i]=s),t.ascend()}return i&&(i.r===void 0?i.p!=null&&(n=void 0):(t.write(`r`,r.default(n)),n=void 0)),n};return u(n,a,t),a.get(),o&&(a.reset(),function e(t,n,r,a,o){let s=n.getComponent();if(s){s.i===void 0?s.d!=null&&(a=l[s.d],t=c[s.d],o=!1,s.d):(a=s.i,o=!0);let e=D(s);if(e&&e.makeInvertible){let t=O(s);k(r,e,e.makeInvertible(t,a),!0)}}let u=0,d=0,m=i.advancer(t,(e,t)=>f(t)?u-e-1:e-u,(e,t)=>{f(t)&&u++});for(let t of n)if(typeof t==`number`){let i=t-d,s=m(i),c=i+u,l=_(a,o?i:c);r.descend(t),e(s,n,r,l,o),p(n.getComponent())&&d++,r.ascend()}else{let i=_(a,t);r.descend(t),e(m(t),n,r,i,o),r.ascend()}m.end()}(n.clone(),n,a,t,!1)),a.get()}function B(e,t){return L(z(e,t))}let V=e=>{if(e==null)return null;let t=e.slice();for(let n=0;n<e.length;n++){let e=t[n];Array.isArray(e)&&(t[n]=V(e))}return t};function H(t,u,d){s(d===`left`||d===`right`,`Direction must be left or right`);let m=d===`left`?0:1;if(o.quiet=!c,o.prefix=0,u==null)return{ok:!0,result:t};M(t),M(u);let h=null,g=[],_=[],v=[],y=[],b=[],x=[],S=[],C=[],w=[],T=[],E=[],A=[],j=[],N=[],P=[],F=0,I=i.readCursor(t),L=i.readCursor(u),R=i.writeCursor();if(function e(t,n=null,r){let a=l(n);a&&(a.r===void 0?a.p!=null&&(r=null,x[a.p]=t.clone()):r=n.clone());let o=t.getComponent(),s;o&&(s=o.p)!=null&&(b[s]=n?n.clone():null,v[s]=t.clone(),r&&(T[s]=!0,w[s]=r),a&&a.p!=null&&(N[s]=a.p));let c=i.advancer(n);for(let n of t)e(t,c(n),r);c.end()}(L,I,null),function t(n,r,o,s,c){let u=o.getComponent(),d,p=!1;u&&((d=u.d)==null?u.i!==void 0&&(n=r=null,p=!0,c&&h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.insertOp(o.getPath(),u.i)})):(y[d]=o.clone(),s!=null&&(P[s]==null&&(P[s]=[]),P[s].push(d)),T[d],n=b[d]||null,r=v[d]||null,T[d]?(c&&(E[d]=!0),c=w[d]||null):!c||m!==1&&N[d]!=null||h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.moveOp(r.getPath(),o.getPath())}),p=!0));let g=l(n);g&&(g.r===void 0?g.p!=null&&(g.p,s=g.p,c=null):c=n.clone());let _=D(u);_&&c&&h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.editOp(o.getPath(),_,O(u),!0)});let x=0,S=0,C=i.advancer(r,(e,t)=>f(t)?x-e-1:e-x,(e,t)=>{f(t)&&x++}),k=i.advancer(n);for(let e of o)if(typeof e==`number`){let n=e-S,r=C(n);S+=+t(k(n+x),r,o,s,c)}else{let n=C(e);t(k(e),n,o,s,c)}return C.end(),k.end(),p}(I,L,L.clone(),null,null),y.map(e=>e&&e.get()),h)return{ok:!1,conflict:h};E.map(e=>!!e);let z=[],B=null;(function e(t,n,r,a,o){let c=!1,u=l(n);if(f(u)){let e=u.p;e==null?(r=null,o=n.clone()):(r=y[e],a=A[e]=i.writeCursor(),c=!0,o=null)}else p(l(r))&&(r=null);let d=t.getComponent();if(d){let e=d.p;e==null?d.r!==void 0&&(o||a.write(`r`,!0),(o||c)&&(B==null&&(B=new Set),B.add(d))):(o&&(C[e]=o),z[e]=o||m===1&&c?null:a.getComponent(),g[e]=t.clone(),r&&(S[e]=r.clone()))}let h=0,_=0,v=i.advancer(n,void 0,(e,t)=>{f(t)&&h++}),b=i.advancer(r,(e,t)=>p(t)?~(e-_):e-_,(e,t)=>{p(t)&&_++});if(t)for(let n of t)if(typeof n==`string`){let r=v(n),i=b(n);a.descend(n),e(t,r,i,a,o),a.ascend()}else{let r=v(n),i=n-h,c=f(l(r))?null:b(i),u=i+_;s(u>=0),a.descend(u),e(t,r,c,a,o),a.ascend()}v.end(),b.end()})(I,L,L.clone(),R,null),R.reset();let H=[];if(function t(o,c,u,b,w,E){s(c);let A=c.getComponent(),M=l(b),P=!1,I=(t,n,r)=>t?e.moveOp(t.getPath(),n.getPath()):e.insertOp(n.getPath(),r.i);if(p(A)){let t=A.d;t!=null&&(_[t]=c.clone());let i=t==null?null:z[t],s=!1;if(A.i!==void 0||t!=null&&i){let o;M&&(M.i!==void 0||(o=M.d)!=null&&!T[o])&&(s=o==null?n.default(M.i,A.i):t!=null&&t===N[o],s||o!=null&&m!==1&&N[o]!=null||h==null&&(h={type:a.ConflictType.DROP_COLLISION,op1:I(t==null?null:g[t],c,A),op2:I(o==null?null:v[o],b,M)})),s||(E?h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:I(t==null?null:g[t],c,A),op2:e.removeOp(E.getPath())}):(t==null?w.write(`i`,r.default(A.i)):(H[F]=t,w.write(`d`,i.p=F++)),P=!0))}else if(t!=null&&!i){let e=C[t];e&&(E=e.clone())}t==null?A.i!==void 0&&(o=u=null,s||(b=null)):(o=g[t],u=x[t],b=S[t])}else f(l(o))&&(o=u=b=null);let L=l(o),R=l(u);if(f(R)){let e=R.p;R.r!==void 0&&(!L||L.r===void 0)||T[e]?(b=null,E=u.clone()):e!=null&&(b=y[e],m!==1&&N[e]!=null||((w=j[e])||(w=j[e]=i.writeCursor()),w.reset(),E=null))}else !p(A)&&p(M)&&(b=null);M=b==null?null:b.getComponent();let V=D(A);if(V){let t=O(A);if(E)h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.editOp(c.getPath(),V,t,!0),op2:e.removeOp(E.getPath())});else{let e=D(M),n;if(e){if(V!==e)throw Error(`Transforming incompatible types`);let r=O(M);n=V.transform(t,r,d)}else n=r.default(t);k(w,V,n)}}let U=0,W=0,G=0,K=0,q=0,J=0,Y=o!=null&&o.descendFirst(),X=Y,Z=i.advancer(u,void 0,(e,t)=>{f(t)&&G++}),Q=b!=null&&b.descendFirst(),$=Q;for(let e of c)if(typeof e==`number`){let n,r=p(c.getComponent()),i=e-W;{let e;for(;Y&&typeof(e=o.getKey())==`number`;){e+=U;let t=o.getComponent(),n=f(t);if(e>i||e===i&&(!n||m===0&&r))break;if(n){U--;let e=t.p;z[e],N.includes(e),t.d,l(j[t.d]),f(l(j[t.d])),(t.r===void 0||B&&B.has(t))&&(e==null||!z[e]||m!==1&&N.includes(e))||q--}Y=o.nextSibling()}n=Y&&e===i?o:null}let a=i-U,u=Z(a),d=a-G,h=null;{let e,t;for(;Q&&typeof(e=b.getKey())==`number`;){t=e-K;let n=b.getComponent(),i=p(n);if(t>d)break;if(t===d){if(!i){h=b;break}{if(m===0&&r){h=b;break}let e=u&&f(u.getComponent());if(m===0&&e)break}}if(i){let e=n.d;T[e],N[e],n.i===void 0&&(T[e]||N[e]!=null&&m!==1)?(T[e]||N[e]!=null&&m===0)&&(K++,J--):K++}Q=b.nextSibling()}}let g=d+K+q+J;s(g>=0,`trying to descend to a negative index`),w.descend(g),r&&(n=u=h=null,W++),t(n,c,u,h,w,E)&&J++,w.ascend()}else{let n;for(;Y&&(n=o.getKey(),typeof n!=`string`||!(n>e||n===e));)Y=o.nextSibling();let r=Y&&n===e?o:null,i=Z(e),a;for(;Q&&(a=b.getKey(),typeof a!=`string`||!(a>e||a===e));)Q=b.nextSibling();let s=Q&&a===e?b:null;w.descend(e),t(r,c,i,s,w,E),w.ascend()}return Z.end(),X&&o.ascend(),$&&b.ascend(),P}(I,I.clone(),L,L.clone(),R,null),h)return{ok:!1,conflict:h};R.reset();let U=(e,t,n)=>e.traverse(t,(t,r)=>{t.d!=null&&n(t.d,e,r)});(T.length||A.length)&&(U(L,R,(e,t,n)=>{T[e]&&!E[e]&&n.write(`r`,!0),A[e]&&n.mergeTree(A[e].get())}),R.reset());let W=[],G=[];if((j.length||T.length)&&!h){let e=i.readCursor(V(R.get()));if(U(e,null,(e,t)=>{W[e]=t.clone()}),j.forEach(e=>{e&&U(i.readCursor(e.get()),null,(e,t)=>{W[e]=t.clone()})}),function e(t,n,r,a,s,c){o.prefix++;let u=l(n);if(u&&f(u))if(u.p!=null){s=u;let e=u.p;W[e].getPath(),r=W[e],a=G[e]=i.writeCursor()}else u.r!==void 0&&(r=null,c=!0);else p(l(r))&&(r=null);let d=t.getComponent();if(d){let e;if((e=d.d)!=null){let t=j[e];t&&(t.get(),a.mergeTree(t.get()),r=i.readCursor(t.get()))}}let m=0,h=0,g=i.advancer(n,void 0,(e,t)=>{f(t)&&m--}),_=i.advancer(r,(e,t)=>p(t)?-(e-h)-1:e-h,(e,t)=>{p(t)&&h++});for(let n of t)if(typeof n==`number`){let r=g(n),i=n+m,o=_(i),l=i+h;a.descend(l),e(t,r,o,a,s,c),a.ascend()}else a.descend(n),e(t,g(n),_(n),a,s,c),a.ascend();g.end(),_.end()}(L,e,e.clone(),R,null,!1),R.reset(),h)return{ok:!1,conflict:h};if(R.get(),G.length){let e=G.map(e=>e?e.get():null);if(U(i.readCursor(V(R.get())),R,(t,n,r)=>{let i=e[t];i&&(r.mergeTree(i),e[t]=null)}),e.find(e=>e)){let t=i.writeCursor(),n=i.writeCursor(),r=0,o=0;e.forEach(e=>{e!=null&&U(i.readCursor(e),null,e=>{let i=H[e];t.writeMove(g[i].getPath(),_[i].getPath(),r++);let a=P[i];a&&a.forEach(e=>{T[e]||m!==1&&N[e]!=null||n.writeMove(v[e].getPath(),y[e].getPath(),o++)})})}),h={type:a.ConflictType.BLACKHOLE,op1:t.get(),op2:n.get()}}}}return h?{ok:!1,conflict:h}:{ok:!0,result:R.get()}}let U=e=>{let t=Error(`Transform detected write conflict`);throw t.conflict=e,t.type=t.name=`writeConflict`,t};function W(e,t,n){let r=H(e,t,n);if(r.ok)return r.result;U(r.conflict)}let G=e=>{let t=i.writeCursor();return i.readCursor(e).traverse(t,(e,t)=>{(p(e)||D(e))&&t.write(`r`,!0)}),t.get()},K=(e,t)=>{let{type:n,op1:r,op2:o}=e;switch(n){case a.ConflictType.DROP_COLLISION:return t===`left`?[null,G(o)]:[G(r),null];case a.ConflictType.RM_UNEXPECTED_CONTENT:let e=!1;return i.readCursor(r).traverse(null,t=>{t.r!==void 0&&(e=!0)}),e?[null,G(o)]:[G(r),null];case a.ConflictType.BLACKHOLE:return[G(r),G(o)];default:throw Error(`Unrecognised conflict: `+n)}};function q(e,t,n,r){let i=null;for(;;){let a=H(t,n,r);if(a.ok)return I(i,a.result);{let{conflict:o}=a;e(o)||U(o);let[s,c]=K(o,r);t=I(N(t),s),n=I(N(n),c),i=I(i,c)}}}})),O=d(l((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__exportStar||function(e,n){for(var r in e)r!==`default`&&!n.hasOwnProperty(r)&&t(n,e,r)};Object.defineProperty(e,`__esModule`,{value:!0}),n(D(),e);var r=x();Object.defineProperty(e,`ReadCursor`,{enumerable:!0,get:function(){return r.ReadCursor}}),Object.defineProperty(e,`WriteCursor`,{enumerable:!0,get:function(){return r.WriteCursor}});var i=S();Object.defineProperty(e,`ConflictType`,{enumerable:!0,get:function(){return i.ConflictType}})}))());function k(e){"@babel/helpers - typeof";return k=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},k(e)}function A(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function j(e){var t=A(e,`string`);return k(t)==`symbol`?t:t+``}function M(e,t,n){return(t=j(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var N=function(e){return e.data=`data`,e.order=`order`,e}(N||{}),P=class{constructor(){M(this,`drawingManagerData`,{}),M(this,`_oldDrawingManagerData`,{}),M(this,`_focusDrawings`,[]),M(this,`_remove$`,new n.Subject),M(this,`remove$`,this._remove$.asObservable()),M(this,`_add$`,new n.Subject),M(this,`add$`,this._add$.asObservable()),M(this,`_update$`,new n.Subject),M(this,`update$`,this._update$.asObservable()),M(this,`_order$`,new n.Subject),M(this,`order$`,this._order$.asObservable()),M(this,`_group$`,new n.Subject),M(this,`group$`,this._group$.asObservable()),M(this,`_ungroup$`,new n.Subject),M(this,`ungroup$`,this._ungroup$.asObservable()),M(this,`_refreshTransform$`,new n.Subject),M(this,`refreshTransform$`,this._refreshTransform$.asObservable()),M(this,`_visible$`,new n.Subject),M(this,`visible$`,this._visible$.asObservable()),M(this,`_focus$`,new n.Subject),M(this,`focus$`,this._focus$.asObservable()),M(this,`_featurePluginUpdate$`,new n.Subject),M(this,`featurePluginUpdate$`,this._featurePluginUpdate$.asObservable()),M(this,`_featurePluginAdd$`,new n.Subject),M(this,`featurePluginAdd$`,this._featurePluginAdd$.asObservable()),M(this,`_featurePluginRemove$`,new n.Subject),M(this,`featurePluginRemove$`,this._featurePluginRemove$.asObservable()),M(this,`_featurePluginOrderUpdate$`,new n.Subject),M(this,`featurePluginOrderUpdate$`,this._featurePluginOrderUpdate$.asObservable()),M(this,`_featurePluginGroupUpdate$`,new n.Subject),M(this,`featurePluginGroupUpdate$`,this._featurePluginGroupUpdate$.asObservable()),M(this,`_featurePluginUngroupUpdate$`,new n.Subject),M(this,`featurePluginUngroupUpdate$`,this._featurePluginUngroupUpdate$.asObservable()),M(this,`_visible`,!0),M(this,`_editable`,!0)}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(e=>{let t=this._getCurrentBySearch(e);t!=null&&(t.transform=e.transform,t.transforms=e.transforms,t.isMultiTransform=e.isMultiTransform)}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return this.drawingManagerData[e]||{}}removeDrawingDataForUnit(e){let t=this.drawingManagerData[e];if(t==null)return;delete this.drawingManagerData[e];let n=[];Object.keys(t).forEach(r=>{let i=t[r];(i==null?void 0:i.data)!=null&&Object.keys(i.data).forEach(t=>{n.push({unitId:e,subUnitId:r,drawingId:t})})}),n.length>0&&this.removeNotification(n)}registerDrawingData(e,t){this.drawingManagerData[e]=t}initializeNotification(e){let t=[],n=this.drawingManagerData[e];n!=null&&(Object.keys(n).forEach(r=>{this._establishDrawingMap(e,r);let i=n[r];Object.keys(i.data).forEach(n=>{let a=i.data[n];a.unitId=e,a.subUnitId=r,t.push(a)})}),t.length>0&&this.addNotification(t))}getDrawingData(e,t){return this._getDrawingData(e,t)}setDrawingData(e,t,n){this.drawingManagerData[e][t].data=n}getBatchAddOp(e){let t=[],n=[],r=[];e.forEach(e=>{let{op:i,invertOp:a}=this._addByParam(e);t.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),n.push(i),r.push(a)});let i=n.reduce(O.type.compose,null),a=r.reduce(O.type.compose,null),{unitId:o,subUnitId:s}=e[0];return{undo:a,redo:i,unitId:o,subUnitId:s,objects:t}}getBatchRemoveOpInOder(e){if(e.length===0)return{undo:null,redo:null,unitId:``,subUnitId:``,objects:[]};let t=this.getDrawingOrder(e[0].unitId,e[0].subUnitId),n=new Map;return t.forEach((e,t)=>{n.set(e,t)}),e.sort((e,t)=>{var r,i;return((r=n.get(e.drawingId))==null?-1/0:r)-((i=n.get(t.drawingId))==null?-1/0:i)}),this.getBatchRemoveOp(e)}getBatchRemoveOp(e){var n;let r=new Set,i=[];e.forEach(e=>{let n=this.getDrawingByParam(e);if((n==null?void 0:n.drawingType)===t.DrawingTypeEnum.DRAWING_GROUP){let t=this.getDrawingsByGroupNested(e);if(t){let{flatChildren:e,groups:n}=t;[...e==null?[]:e,...n].forEach(e=>{r.has(e.drawingId)||(r.add(e.drawingId),i.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}))})}else r.has(e.drawingId)||(r.add(e.drawingId),i.push(e))}else r.has(e.drawingId)||(r.add(e.drawingId),i.push(e))});let{unitId:a,subUnitId:o}=(n=i[0])==null?e[0]:n,s=this._getDrawingOrder(a,o),c=new Map;s.forEach((e,t)=>c.set(e,t)),i.sort((e,t)=>{var n,r;return((n=c.get(e.drawingId))==null?-1/0:n)-((r=c.get(t.drawingId))==null?-1/0:r)});let l=[],u=[];i.forEach(e=>{let{op:t,invertOp:n}=this._removeByParam(e);l.unshift(t),u.push(n)});let d=l.reduce(O.type.compose,null);return{undo:u.reduce(O.type.compose,null),redo:d,unitId:a,subUnitId:o,objects:i}}getBatchUpdateOp(e){let t=[],n=[],r=[];e.forEach(e=>{let{op:i,invertOp:a}=this._updateByParam(e);t.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),n.push(i),r.push(a)});let i=n.reduce(O.type.compose,null),a=r.reduce(O.type.compose,null),{unitId:o,subUnitId:s}=e[0];return{undo:a,redo:i,unitId:o,subUnitId:s,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){let t=[],{unitId:n,subUnitId:r}=e[0].parent;e.forEach(e=>{t.push(this._getGroupDrawingOp(e))});let i=t.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(i,this.drawingManagerData),redo:i,unitId:n,subUnitId:r,objects:e}}getUngroupDrawingOp(e){let t=[],{unitId:n,subUnitId:r}=e[0].parent;e.forEach(e=>{t.push(this._getUngroupDrawingOp(e))});let i=t.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(i,this.drawingManagerData),redo:i,unitId:n,subUnitId:r,objects:e}}getDrawingsByGroup(e){let{unitId:t,subUnitId:n,drawingId:r}=e;if(this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})==null)return[];let i=this._getDrawingData(t,n),a=[];return Object.keys(i).forEach(e=>{let t=i[e];t.groupId===r&&a.push(t)}),a}getDrawingsByGroupNested(e){let{unitId:n,subUnitId:r}=e,i=this.getDrawingByParam(e);if(!i)return null;let a=this._getDrawingData(n,r),o=new Map;Object.values(a).forEach(e=>{e.groupId!=null&&(o.has(e.groupId)||o.set(e.groupId,[]),o.get(e.groupId).push(e.drawingId))});let s=[],c=[],l={},u=e=>{var n;let{drawingId:r}=e,i=(n=o.get(r))==null?[]:n;l[r]={drawingId:r,children:i},i.forEach(e=>{let n=a[e];n&&(n.drawingType===t.DrawingTypeEnum.DRAWING_GROUP?(u(n),c.push(n)):s.push(n))})};return u(i),c.push(i),{nestedIdRecord:l,flatChildren:s,groups:c}}_getGroupDrawingOp(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=[];o.push(O.insertOp([r,i,N.data,a],t));let s=-1/0;return n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:r});s=Math.max(s,i),o.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),s===-1/0&&(s=this._getDrawingOrder(r,i).length),o.push(O.insertOp([r,i,N.order,s],a)),o.reduce(O.type.compose,null)}_getUngroupDrawingOp(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=[];return n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e;o.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),o.push(O.removeOp([r,i,N.data,a],!0)),o.push(O.removeOp([r,i,N.order,this._getDrawingOrder(r,i).indexOf(a)],!0)),o.reduce(O.type.compose,null)}applyJson1(e,t,n){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=O.type.apply(this.drawingManagerData,n)}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){let[t,n,r]=e.split(`#-#`);return this._getCurrentBySearch({unitId:t,subUnitId:n,drawingId:r})}focusDrawing(e){if(e==null||e.length===0){this._focusDrawings=[],this._focus$.next([]);return}let t=[];e.forEach(e=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=e,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&t.push(o)}),t.length>0&&(this._focusDrawings=t,this._focus$.next(t))}getFocusDrawings(){let e=[];return this._focusDrawings.forEach(t=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=t,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&e.push(o)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,n){this.drawingManagerData[e][t].order=n}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=[],a=this.getDrawingOrder(t,n),o=[...r];r.forEach(e=>{let r=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:e});if(r===-1||r===a.length-1)return;let s=O.moveOp([t,n,N.order,r],[t,n,N.order,r+1]);i.push(s),o.includes(a[r+1])||o.push(a[r+1])});let s=i.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(s,this.drawingManagerData),redo:s,unitId:t,subUnitId:n,objects:{...e,drawingIds:o}}}getBackwardDrawingOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=[],a=this.getDrawingOrder(t,n),o=[...r];r.forEach(e=>{let r=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:e});if(r===-1||r===0)return;let s=O.moveOp([t,n,N.order,r],[t,n,N.order,r-1]);i.push(s),o.includes(a[r-1])||o.push(a[r-1])});let s=i.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(s,this.drawingManagerData),redo:s,unitId:t,subUnitId:n,objects:{...e,drawingIds:o}}}getFrontDrawingsOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getOrderFromSearchParams(t,n,r),a=[...r],o=this.getDrawingOrder(t,n),s=[];i.forEach(e=>{let{drawingId:r}=e,i=this._getDrawingCount(t,n)-1,c=O.moveOp([t,n,N.order,this._getDrawingOrder(t,n).indexOf(r)],[t,n,N.order,i]);s.push(c),a.includes(o[i])||a.push(o[i])});let c=s.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:t,subUnitId:n,objects:{...e,drawingIds:a}}}getBackDrawingsOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getOrderFromSearchParams(t,n,r,!0),a=[...r],o=this.getDrawingOrder(t,n),s=[];i.forEach(e=>{let{drawingId:r}=e,i=O.moveOp([t,n,N.order,this._getDrawingOrder(t,n).indexOf(r)],[t,n,N.order,0]);s.push(i),a.includes(o[0])||a.push(o[0])});let c=s.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:t,subUnitId:n,objects:{...e,drawingIds:a}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,n,r,i=!1){return r.map(t=>({drawingId:t,zIndex:this._hasDrawingOrder({unitId:e,subUnitId:n,drawingId:t})})).sort(i===!1?t.sortRules:t.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;let{unitId:t,subUnitId:n,drawingId:r}=e;return this._establishDrawingMap(t,n),this._getDrawingOrder(t,n).indexOf(r)}_getCurrentBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return(t=this.drawingManagerData[n])==null||(t=t[r])==null||(t=t.data)==null?void 0:t[i]}_getOldBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return(t=this._oldDrawingManagerData[n])==null||(t=t[r])==null||(t=t.data)==null?void 0:t[i]}_establishDrawingMap(e,t,n){var r;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),n==null?null:(r=this.drawingManagerData[e][t].data)==null?void 0:r[n]}_addByParam(e){let{unitId:t,subUnitId:n,drawingId:r}=e;this._establishDrawingMap(t,n,r);let i=[O.insertOp([t,n,N.data,r],e),O.insertOp([t,n,N.order,this._getDrawingOrder(t,n).length],r)].reduce(O.type.compose,null);return{op:i,invertOp:O.type.invertWithDoc(i,this.drawingManagerData)}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};let{unitId:t,subUnitId:n,drawingId:r}=e;if(this._establishDrawingMap(t,n,r)==null)return{op:[],invertOp:[]};let i=[O.removeOp([t,n,N.data,r],!0),O.removeOp([t,n,N.order,this._getDrawingOrder(t,n).indexOf(r)],!0)].reduce(O.type.compose,null);return{op:i,invertOp:O.type.invertWithDoc(i,this.drawingManagerData)}}_updateByParam(e){let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._establishDrawingMap(t,n,r);if(i==null)return{op:[],invertOp:[]};let a=this._getUpdateParamCompareOp(e,i).reduce(O.type.compose,null);return{op:a,invertOp:O.type.invertWithDoc(a,this.drawingManagerData)}}_getUpdateParamCompareOp(e,t){let{unitId:n,subUnitId:r,drawingId:i}=e,a=[];return Object.keys(e).forEach(o=>{let s=e[o],c=t[o];c!==s&&a.push(O.replaceOp([n,r,N.data,i,o],c,s))}),a}_getDrawingData(e,t){var n;return((n=this.drawingManagerData[e])==null||(n=n[t])==null?void 0:n.data)||{}}_getDrawingOrder(e,t){var n;return((n=this.drawingManagerData[e])==null||(n=n[t])==null?void 0:n.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(e){this._visible=e}setDrawingEditable(e){this._editable=e}},F=class extends P{},I=class{constructor(){M(this,`_waitCount`,0),M(this,`_change$`,new n.Subject),M(this,`change$`,this._change$),M(this,`_imageSourceCache`,new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,n){if(n===t.ImageSourceType.BASE64){let t=new Image;return t.src=e,t}return this._imageSourceCache.get(e)}addImageSourceCache(e,n,r){n===t.ImageSourceType.BASE64||r==null||this._imageSourceCache.set(e,r)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((n,r)=>{if(!f.includes(e.type)){r(Error(t.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>5242880){r(Error(t.ImageUploadStatusType.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}let i=new FileReader;i.readAsDataURL(e),i.onload=e=>{var i;let a=(i=e.target)==null?void 0:i.result;if(a==null){r(Error(t.ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting();return}n({imageId:(0,t.generateRandomId)(6),imageSourceType:t.ImageSourceType.BASE64,source:a,base64Cache:a,status:t.ImageUploadStatusType.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){--this._waitCount,this._change$.next(this._waitCount)}},L=class extends t.Disposable{constructor(...e){super(...e),M(this,`_urlImageDownloader`,null)}registerURLImageDownloader(e){return this._urlImageDownloader=e,(0,t.toDisposable)(()=>{this._urlImageDownloader=null})}async getImage(e){if(this._urlImageDownloader)try{return await this._urlImageDownloader(e)}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default behavior:`,t)}return e}async downloadImage(e){if(this._urlImageDownloader)try{let t=await this._urlImageDownloader(e);return await(await fetch(t)).blob()}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default fetch:`,t)}return await(await fetch(e)).blob()}};function R(e,t){return function(n,r){t(n,r,e)}}function z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let B=class extends t.Plugin{constructor(e=v,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},v,this._config);this._configService.setConfig(_,a)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var e;(0,t.mergeOverrideWithDependencies)([[t.IImageIoService,{useClass:I}],[t.IURLImageService,{useClass:L}],[p,{useClass:F}]],(e=this._config)==null?void 0:e.override).forEach(e=>this._injector.add(e))}_initCommands(){[m].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};M(B,`pluginName`,`UNIVER_DRAWING_PLUGIN`),M(B,`packageName`,h),M(B,`version`,g),B=z([R(1,(0,t.Inject)(t.Injector)),R(2,t.IConfigService),R(3,t.ICommandService)],B);function V({unitId:e,subUnitId:t,drawingId:n},r){return typeof r==`number`?`${e}#-#${t}#-#${n}#-#${r}`:`${e}#-#${t}#-#${n}`}e.DRAWING_IMAGE_ALLOW_IMAGE_LIST=f,e.DRAWING_IMAGE_ALLOW_SIZE=5242880,e.DRAWING_IMAGE_COUNT_LIMIT=10,e.DRAWING_IMAGE_HEIGHT_LIMIT=500,e.DRAWING_IMAGE_WIDTH_LIMIT=500,e.DrawingManagerService=F,e.IDrawingManagerService=p,Object.defineProperty(e,`IImageIoService`,{enumerable:!0,get:function(){return t.IImageIoService}}),e.ImageIoService=I,Object.defineProperty(e,`ImageSourceType`,{enumerable:!0,get:function(){return t.ImageSourceType}}),Object.defineProperty(e,`ImageUploadStatusType`,{enumerable:!0,get:function(){return t.ImageUploadStatusType}}),e.SetDrawingSelectedOperation=m,e.URLImageService=L,e.UnitDrawingService=P,Object.defineProperty(e,`UniverDrawingPlugin`,{enumerable:!0,get:function(){return B}}),e.getDrawingShapeKeyByDrawingSearch=V,e.getImageSize=async e=>new Promise((t,n)=>{let r=new Image;r.src=e,r.onload=()=>{t({width:r.width,height:r.height,image:r})},r.onerror=e=>{n(e)}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/drawing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"ot-json1": "^1.0.2",
|
|
50
|
-
"@univerjs/core": "0.
|
|
50
|
+
"@univerjs/core": "0.21.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"rxjs": "^7.8.2",
|
|
54
54
|
"typescript": "^6.0.2",
|
|
55
55
|
"vitest": "^4.1.4",
|
|
56
|
-
"@univerjs-infra/shared": "0.
|
|
56
|
+
"@univerjs-infra/shared": "0.21.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"test": "vitest run",
|