@univerjs/drawing 1.0.0-insiders.20260809-70eefdd → 1.0.0-rc.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/README.md +0 -1
- package/lib/cjs/index.js +90 -34
- package/lib/es/index.js +91 -35
- package/lib/index.js +91 -35
- package/lib/types/index.d.ts +3 -2
- package/lib/types/services/drawing-manager-impl.service.d.ts +8 -4
- package/lib/types/services/drawing-manager.service.d.ts +1 -0
- package/lib/types/utils/drawing-copy-plan.d.ts +33 -0
- package/lib/types/utils/drawing-group.d.ts +1 -14
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -85,7 +85,7 @@ const SetDrawingSelectedOperation = {
|
|
|
85
85
|
//#endregion
|
|
86
86
|
//#region package.json
|
|
87
87
|
var name = "@univerjs/drawing";
|
|
88
|
-
var version = "1.0.0-
|
|
88
|
+
var version = "1.0.0-rc.0";
|
|
89
89
|
|
|
90
90
|
//#endregion
|
|
91
91
|
//#region src/config/config.ts
|
|
@@ -142,17 +142,48 @@ function isNonEmptyOp(op) {
|
|
|
142
142
|
}
|
|
143
143
|
function isJsonValueEqual(left, right) {
|
|
144
144
|
if (left === right) return true;
|
|
145
|
-
if (left == null || right == null || typeof left !== "object" || typeof right !== "object") return false;
|
|
146
145
|
if (Array.isArray(left) || Array.isArray(right)) {
|
|
147
146
|
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
148
147
|
return left.every((item, index) => isJsonValueEqual(item, right[index]));
|
|
149
148
|
}
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
const rightKeys = Object.keys(rightRecord);
|
|
149
|
+
if (!isPlainObject(left) || !isPlainObject(right)) return false;
|
|
150
|
+
const leftKeys = Object.keys(left);
|
|
151
|
+
const rightKeys = Object.keys(right);
|
|
154
152
|
if (leftKeys.length !== rightKeys.length) return false;
|
|
155
|
-
return leftKeys.every((key) => Object.prototype.hasOwnProperty.call(
|
|
153
|
+
return leftKeys.every((key) => Object.prototype.hasOwnProperty.call(right, key) && isJsonValueEqual(left[key], right[key]));
|
|
154
|
+
}
|
|
155
|
+
function isPlainObject(value) {
|
|
156
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
157
|
+
}
|
|
158
|
+
function hasOnlyEnumerableOwnProperties(value) {
|
|
159
|
+
return Object.getOwnPropertyNames(value).every((key) => Object.prototype.propertyIsEnumerable.call(value, key));
|
|
160
|
+
}
|
|
161
|
+
function createJsonRemoveOp(path, value) {
|
|
162
|
+
return ot_json1.type.writeCursor().writeAtPath(path, "r", value).get();
|
|
163
|
+
}
|
|
164
|
+
function normalizeJsonDocument(value) {
|
|
165
|
+
if (value === void 0) return;
|
|
166
|
+
if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") return value;
|
|
167
|
+
if (Array.isArray(value)) return value.map((item) => normalizeJsonDocument(item) ?? null);
|
|
168
|
+
if (!isPlainObject(value)) return;
|
|
169
|
+
const normalizedValue = {};
|
|
170
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
171
|
+
const normalizedItem = normalizeJsonDocument(item);
|
|
172
|
+
if (normalizedItem !== void 0) normalizedValue[key] = normalizedItem;
|
|
173
|
+
});
|
|
174
|
+
return normalizedValue;
|
|
175
|
+
}
|
|
176
|
+
function appendJsonUpdateOps(ops, path, newValue, oldValue, hasOldValue) {
|
|
177
|
+
const normalizedOldValue = normalizeJsonDocument(oldValue);
|
|
178
|
+
const normalizedNewValue = normalizeJsonDocument(newValue);
|
|
179
|
+
const hasNormalizedOldValue = hasOldValue && normalizedOldValue !== void 0;
|
|
180
|
+
if (hasNormalizedOldValue && isJsonValueEqual(normalizedOldValue, normalizedNewValue)) return;
|
|
181
|
+
if (hasNormalizedOldValue && isPlainObject(oldValue) && isPlainObject(newValue) && hasOnlyEnumerableOwnProperties(oldValue) && hasOnlyEnumerableOwnProperties(newValue)) {
|
|
182
|
+
(/* @__PURE__ */ new Set([...Object.keys(oldValue), ...Object.keys(newValue)])).forEach((key) => appendJsonUpdateOps(ops, [...path, key], newValue[key], oldValue[key], Object.prototype.hasOwnProperty.call(oldValue, key) && oldValue[key] !== void 0));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const op = !hasNormalizedOldValue ? normalizedNewValue === void 0 ? null : ot_json1.insertOp(path, normalizedNewValue) : normalizedNewValue === void 0 ? createJsonRemoveOp(path, normalizedOldValue) : ot_json1.replaceOp(path, normalizedOldValue, normalizedNewValue);
|
|
186
|
+
if (op && isNonEmptyOp(op)) ops.push(op);
|
|
156
187
|
}
|
|
157
188
|
/**
|
|
158
189
|
* unitId -> subUnitId -> drawingId -> drawingParam
|
|
@@ -818,6 +849,38 @@ var UnitDrawingService = class {
|
|
|
818
849
|
}
|
|
819
850
|
};
|
|
820
851
|
}
|
|
852
|
+
getDrawingOrderOp(orderParams, zOrder) {
|
|
853
|
+
const { unitId, subUnitId, drawingIds } = orderParams;
|
|
854
|
+
if (drawingIds.length !== 1) return null;
|
|
855
|
+
const orders = this.getDrawingOrder(unitId, subUnitId);
|
|
856
|
+
const drawingId = drawingIds[0];
|
|
857
|
+
const currentIndex = orders.indexOf(drawingId);
|
|
858
|
+
const targetIndex = (0, _univerjs_core.normalizeDrawingOrderIndex)(zOrder, orders.length);
|
|
859
|
+
if (currentIndex < 0 || currentIndex === targetIndex) return null;
|
|
860
|
+
const op = ot_json1.moveOp([
|
|
861
|
+
unitId,
|
|
862
|
+
subUnitId,
|
|
863
|
+
"order",
|
|
864
|
+
currentIndex
|
|
865
|
+
], [
|
|
866
|
+
unitId,
|
|
867
|
+
subUnitId,
|
|
868
|
+
"order",
|
|
869
|
+
targetIndex
|
|
870
|
+
]);
|
|
871
|
+
const invertOp = ot_json1.type.invertWithDoc(op, this.drawingManagerData);
|
|
872
|
+
const affectedDrawingIds = orders.slice(Math.min(currentIndex, targetIndex), Math.max(currentIndex, targetIndex) + 1);
|
|
873
|
+
return {
|
|
874
|
+
undo: invertOp,
|
|
875
|
+
redo: op,
|
|
876
|
+
unitId,
|
|
877
|
+
subUnitId,
|
|
878
|
+
objects: {
|
|
879
|
+
...orderParams,
|
|
880
|
+
drawingIds: affectedDrawingIds
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
}
|
|
821
884
|
_getDrawingCount(unitId, subUnitId) {
|
|
822
885
|
return this.getDrawingOrder(unitId, subUnitId).length || 0;
|
|
823
886
|
}
|
|
@@ -921,7 +984,7 @@ var UnitDrawingService = class {
|
|
|
921
984
|
const op = ops.reduce(ot_json1.type.compose, null);
|
|
922
985
|
return {
|
|
923
986
|
op,
|
|
924
|
-
invertOp: ot_json1.type.
|
|
987
|
+
invertOp: ot_json1.type.invert(op)
|
|
925
988
|
};
|
|
926
989
|
}
|
|
927
990
|
_getUpdateParamCompareOp(newParam, oldParam) {
|
|
@@ -931,27 +994,13 @@ var UnitDrawingService = class {
|
|
|
931
994
|
const newVal = newParam[key];
|
|
932
995
|
const hasOldKey = Object.prototype.hasOwnProperty.call(oldParam, key);
|
|
933
996
|
const oldVal = oldParam[key];
|
|
934
|
-
|
|
935
|
-
const path = [
|
|
997
|
+
appendJsonUpdateOps(ops, [
|
|
936
998
|
unitId,
|
|
937
999
|
subUnitId,
|
|
938
1000
|
"data",
|
|
939
1001
|
drawingId,
|
|
940
1002
|
key
|
|
941
|
-
];
|
|
942
|
-
if (!hasOldKey) {
|
|
943
|
-
if (newVal === void 0) return;
|
|
944
|
-
const op = ot_json1.insertOp(path, newVal);
|
|
945
|
-
if (isNonEmptyOp(op)) ops.push(op);
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
if (newVal === void 0) {
|
|
949
|
-
const op = ot_json1.removeOp(path, true);
|
|
950
|
-
if (isNonEmptyOp(op)) ops.push(op);
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
953
|
-
const op = ot_json1.replaceOp(path, oldVal, newVal);
|
|
954
|
-
if (isNonEmptyOp(op)) ops.push(op);
|
|
1003
|
+
], newVal, oldVal, hasOldKey);
|
|
955
1004
|
});
|
|
956
1005
|
return ops;
|
|
957
1006
|
}
|
|
@@ -1137,16 +1186,11 @@ UniverDrawingPlugin = __decorate([
|
|
|
1137
1186
|
], UniverDrawingPlugin);
|
|
1138
1187
|
|
|
1139
1188
|
//#endregion
|
|
1140
|
-
//#region src/utils/drawing-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
_univerjs_core.DrawingTypeEnum.DRAWING_GROUP
|
|
1146
|
-
];
|
|
1147
|
-
function isGroupableDrawingType(type) {
|
|
1148
|
-
return DRAWING_GROUPABLE_TYPES.includes(type);
|
|
1149
|
-
}
|
|
1189
|
+
//#region src/utils/drawing-copy-plan.ts
|
|
1190
|
+
/**
|
|
1191
|
+
* A command-scoped cache key shared by sheet-copy interceptors so every drawing model
|
|
1192
|
+
* resolves against the same copied drawing IDs.
|
|
1193
|
+
*/
|
|
1150
1194
|
const DRAWING_COPY_CONTEXT_KEY = "univer.drawing.copy-plan";
|
|
1151
1195
|
function cloneDrawing(drawing) {
|
|
1152
1196
|
return JSON.parse(JSON.stringify(drawing));
|
|
@@ -1199,6 +1243,18 @@ function getOrCreateDrawingCopyPlan(copyContext, drawings, options) {
|
|
|
1199
1243
|
return plan;
|
|
1200
1244
|
}
|
|
1201
1245
|
|
|
1246
|
+
//#endregion
|
|
1247
|
+
//#region src/utils/drawing-group.ts
|
|
1248
|
+
const DRAWING_GROUPABLE_TYPES = [
|
|
1249
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_IMAGE,
|
|
1250
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_SHAPE,
|
|
1251
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_CHART,
|
|
1252
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_GROUP
|
|
1253
|
+
];
|
|
1254
|
+
function isGroupableDrawingType(type) {
|
|
1255
|
+
return DRAWING_GROUPABLE_TYPES.includes(type);
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1202
1258
|
//#endregion
|
|
1203
1259
|
//#region src/utils/get-image-shape-key.ts
|
|
1204
1260
|
function getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }, index) {
|
package/lib/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IURLImageService, ImageSourceType, ImageUploadStatusType, Inject, Injector, Plugin, createIdentifier, generateRandomId, merge, mergeOverrideWithDependencies, sortRules, sortRulesByDesc, toDisposable } from "@univerjs/core";
|
|
1
|
+
import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IURLImageService, ImageSourceType, ImageUploadStatusType, Inject, Injector, Plugin, createIdentifier, generateRandomId, merge, mergeOverrideWithDependencies, normalizeDrawingOrderIndex, sortRules, sortRulesByDesc, toDisposable } from "@univerjs/core";
|
|
2
2
|
import * as json1 from "ot-json1";
|
|
3
3
|
import { Subject } from "rxjs";
|
|
4
4
|
|
|
@@ -56,7 +56,7 @@ const SetDrawingSelectedOperation = {
|
|
|
56
56
|
//#endregion
|
|
57
57
|
//#region package.json
|
|
58
58
|
var name = "@univerjs/drawing";
|
|
59
|
-
var version = "1.0.0-
|
|
59
|
+
var version = "1.0.0-rc.0";
|
|
60
60
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/config/config.ts
|
|
@@ -113,17 +113,48 @@ function isNonEmptyOp(op) {
|
|
|
113
113
|
}
|
|
114
114
|
function isJsonValueEqual(left, right) {
|
|
115
115
|
if (left === right) return true;
|
|
116
|
-
if (left == null || right == null || typeof left !== "object" || typeof right !== "object") return false;
|
|
117
116
|
if (Array.isArray(left) || Array.isArray(right)) {
|
|
118
117
|
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
119
118
|
return left.every((item, index) => isJsonValueEqual(item, right[index]));
|
|
120
119
|
}
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const rightKeys = Object.keys(rightRecord);
|
|
120
|
+
if (!isPlainObject(left) || !isPlainObject(right)) return false;
|
|
121
|
+
const leftKeys = Object.keys(left);
|
|
122
|
+
const rightKeys = Object.keys(right);
|
|
125
123
|
if (leftKeys.length !== rightKeys.length) return false;
|
|
126
|
-
return leftKeys.every((key) => Object.prototype.hasOwnProperty.call(
|
|
124
|
+
return leftKeys.every((key) => Object.prototype.hasOwnProperty.call(right, key) && isJsonValueEqual(left[key], right[key]));
|
|
125
|
+
}
|
|
126
|
+
function isPlainObject(value) {
|
|
127
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
128
|
+
}
|
|
129
|
+
function hasOnlyEnumerableOwnProperties(value) {
|
|
130
|
+
return Object.getOwnPropertyNames(value).every((key) => Object.prototype.propertyIsEnumerable.call(value, key));
|
|
131
|
+
}
|
|
132
|
+
function createJsonRemoveOp(path, value) {
|
|
133
|
+
return json1.type.writeCursor().writeAtPath(path, "r", value).get();
|
|
134
|
+
}
|
|
135
|
+
function normalizeJsonDocument(value) {
|
|
136
|
+
if (value === void 0) return;
|
|
137
|
+
if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") return value;
|
|
138
|
+
if (Array.isArray(value)) return value.map((item) => normalizeJsonDocument(item) ?? null);
|
|
139
|
+
if (!isPlainObject(value)) return;
|
|
140
|
+
const normalizedValue = {};
|
|
141
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
142
|
+
const normalizedItem = normalizeJsonDocument(item);
|
|
143
|
+
if (normalizedItem !== void 0) normalizedValue[key] = normalizedItem;
|
|
144
|
+
});
|
|
145
|
+
return normalizedValue;
|
|
146
|
+
}
|
|
147
|
+
function appendJsonUpdateOps(ops, path, newValue, oldValue, hasOldValue) {
|
|
148
|
+
const normalizedOldValue = normalizeJsonDocument(oldValue);
|
|
149
|
+
const normalizedNewValue = normalizeJsonDocument(newValue);
|
|
150
|
+
const hasNormalizedOldValue = hasOldValue && normalizedOldValue !== void 0;
|
|
151
|
+
if (hasNormalizedOldValue && isJsonValueEqual(normalizedOldValue, normalizedNewValue)) return;
|
|
152
|
+
if (hasNormalizedOldValue && isPlainObject(oldValue) && isPlainObject(newValue) && hasOnlyEnumerableOwnProperties(oldValue) && hasOnlyEnumerableOwnProperties(newValue)) {
|
|
153
|
+
(/* @__PURE__ */ new Set([...Object.keys(oldValue), ...Object.keys(newValue)])).forEach((key) => appendJsonUpdateOps(ops, [...path, key], newValue[key], oldValue[key], Object.prototype.hasOwnProperty.call(oldValue, key) && oldValue[key] !== void 0));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const op = !hasNormalizedOldValue ? normalizedNewValue === void 0 ? null : json1.insertOp(path, normalizedNewValue) : normalizedNewValue === void 0 ? createJsonRemoveOp(path, normalizedOldValue) : json1.replaceOp(path, normalizedOldValue, normalizedNewValue);
|
|
157
|
+
if (op && isNonEmptyOp(op)) ops.push(op);
|
|
127
158
|
}
|
|
128
159
|
/**
|
|
129
160
|
* unitId -> subUnitId -> drawingId -> drawingParam
|
|
@@ -789,6 +820,38 @@ var UnitDrawingService = class {
|
|
|
789
820
|
}
|
|
790
821
|
};
|
|
791
822
|
}
|
|
823
|
+
getDrawingOrderOp(orderParams, zOrder) {
|
|
824
|
+
const { unitId, subUnitId, drawingIds } = orderParams;
|
|
825
|
+
if (drawingIds.length !== 1) return null;
|
|
826
|
+
const orders = this.getDrawingOrder(unitId, subUnitId);
|
|
827
|
+
const drawingId = drawingIds[0];
|
|
828
|
+
const currentIndex = orders.indexOf(drawingId);
|
|
829
|
+
const targetIndex = normalizeDrawingOrderIndex(zOrder, orders.length);
|
|
830
|
+
if (currentIndex < 0 || currentIndex === targetIndex) return null;
|
|
831
|
+
const op = json1.moveOp([
|
|
832
|
+
unitId,
|
|
833
|
+
subUnitId,
|
|
834
|
+
"order",
|
|
835
|
+
currentIndex
|
|
836
|
+
], [
|
|
837
|
+
unitId,
|
|
838
|
+
subUnitId,
|
|
839
|
+
"order",
|
|
840
|
+
targetIndex
|
|
841
|
+
]);
|
|
842
|
+
const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData);
|
|
843
|
+
const affectedDrawingIds = orders.slice(Math.min(currentIndex, targetIndex), Math.max(currentIndex, targetIndex) + 1);
|
|
844
|
+
return {
|
|
845
|
+
undo: invertOp,
|
|
846
|
+
redo: op,
|
|
847
|
+
unitId,
|
|
848
|
+
subUnitId,
|
|
849
|
+
objects: {
|
|
850
|
+
...orderParams,
|
|
851
|
+
drawingIds: affectedDrawingIds
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
}
|
|
792
855
|
_getDrawingCount(unitId, subUnitId) {
|
|
793
856
|
return this.getDrawingOrder(unitId, subUnitId).length || 0;
|
|
794
857
|
}
|
|
@@ -892,7 +955,7 @@ var UnitDrawingService = class {
|
|
|
892
955
|
const op = ops.reduce(json1.type.compose, null);
|
|
893
956
|
return {
|
|
894
957
|
op,
|
|
895
|
-
invertOp: json1.type.
|
|
958
|
+
invertOp: json1.type.invert(op)
|
|
896
959
|
};
|
|
897
960
|
}
|
|
898
961
|
_getUpdateParamCompareOp(newParam, oldParam) {
|
|
@@ -902,27 +965,13 @@ var UnitDrawingService = class {
|
|
|
902
965
|
const newVal = newParam[key];
|
|
903
966
|
const hasOldKey = Object.prototype.hasOwnProperty.call(oldParam, key);
|
|
904
967
|
const oldVal = oldParam[key];
|
|
905
|
-
|
|
906
|
-
const path = [
|
|
968
|
+
appendJsonUpdateOps(ops, [
|
|
907
969
|
unitId,
|
|
908
970
|
subUnitId,
|
|
909
971
|
"data",
|
|
910
972
|
drawingId,
|
|
911
973
|
key
|
|
912
|
-
];
|
|
913
|
-
if (!hasOldKey) {
|
|
914
|
-
if (newVal === void 0) return;
|
|
915
|
-
const op = json1.insertOp(path, newVal);
|
|
916
|
-
if (isNonEmptyOp(op)) ops.push(op);
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
if (newVal === void 0) {
|
|
920
|
-
const op = json1.removeOp(path, true);
|
|
921
|
-
if (isNonEmptyOp(op)) ops.push(op);
|
|
922
|
-
return;
|
|
923
|
-
}
|
|
924
|
-
const op = json1.replaceOp(path, oldVal, newVal);
|
|
925
|
-
if (isNonEmptyOp(op)) ops.push(op);
|
|
974
|
+
], newVal, oldVal, hasOldKey);
|
|
926
975
|
});
|
|
927
976
|
return ops;
|
|
928
977
|
}
|
|
@@ -1108,16 +1157,11 @@ UniverDrawingPlugin = __decorate([
|
|
|
1108
1157
|
], UniverDrawingPlugin);
|
|
1109
1158
|
|
|
1110
1159
|
//#endregion
|
|
1111
|
-
//#region src/utils/drawing-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
DrawingTypeEnum.DRAWING_GROUP
|
|
1117
|
-
];
|
|
1118
|
-
function isGroupableDrawingType(type) {
|
|
1119
|
-
return DRAWING_GROUPABLE_TYPES.includes(type);
|
|
1120
|
-
}
|
|
1160
|
+
//#region src/utils/drawing-copy-plan.ts
|
|
1161
|
+
/**
|
|
1162
|
+
* A command-scoped cache key shared by sheet-copy interceptors so every drawing model
|
|
1163
|
+
* resolves against the same copied drawing IDs.
|
|
1164
|
+
*/
|
|
1121
1165
|
const DRAWING_COPY_CONTEXT_KEY = "univer.drawing.copy-plan";
|
|
1122
1166
|
function cloneDrawing(drawing) {
|
|
1123
1167
|
return JSON.parse(JSON.stringify(drawing));
|
|
@@ -1170,6 +1214,18 @@ function getOrCreateDrawingCopyPlan(copyContext, drawings, options) {
|
|
|
1170
1214
|
return plan;
|
|
1171
1215
|
}
|
|
1172
1216
|
|
|
1217
|
+
//#endregion
|
|
1218
|
+
//#region src/utils/drawing-group.ts
|
|
1219
|
+
const DRAWING_GROUPABLE_TYPES = [
|
|
1220
|
+
DrawingTypeEnum.DRAWING_IMAGE,
|
|
1221
|
+
DrawingTypeEnum.DRAWING_SHAPE,
|
|
1222
|
+
DrawingTypeEnum.DRAWING_CHART,
|
|
1223
|
+
DrawingTypeEnum.DRAWING_GROUP
|
|
1224
|
+
];
|
|
1225
|
+
function isGroupableDrawingType(type) {
|
|
1226
|
+
return DRAWING_GROUPABLE_TYPES.includes(type);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1173
1229
|
//#endregion
|
|
1174
1230
|
//#region src/utils/get-image-shape-key.ts
|
|
1175
1231
|
function getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }, index) {
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IURLImageService, ImageSourceType, ImageUploadStatusType, Inject, Injector, Plugin, createIdentifier, generateRandomId, merge, mergeOverrideWithDependencies, sortRules, sortRulesByDesc, toDisposable } from "@univerjs/core";
|
|
1
|
+
import { CommandType, Disposable, DrawingTypeEnum, ICommandService, IConfigService, IImageIoService, IURLImageService, ImageSourceType, ImageUploadStatusType, Inject, Injector, Plugin, createIdentifier, generateRandomId, merge, mergeOverrideWithDependencies, normalizeDrawingOrderIndex, sortRules, sortRulesByDesc, toDisposable } from "@univerjs/core";
|
|
2
2
|
import * as json1 from "ot-json1";
|
|
3
3
|
import { Subject } from "rxjs";
|
|
4
4
|
|
|
@@ -56,7 +56,7 @@ const SetDrawingSelectedOperation = {
|
|
|
56
56
|
//#endregion
|
|
57
57
|
//#region package.json
|
|
58
58
|
var name = "@univerjs/drawing";
|
|
59
|
-
var version = "1.0.0-
|
|
59
|
+
var version = "1.0.0-rc.0";
|
|
60
60
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/config/config.ts
|
|
@@ -113,17 +113,48 @@ function isNonEmptyOp(op) {
|
|
|
113
113
|
}
|
|
114
114
|
function isJsonValueEqual(left, right) {
|
|
115
115
|
if (left === right) return true;
|
|
116
|
-
if (left == null || right == null || typeof left !== "object" || typeof right !== "object") return false;
|
|
117
116
|
if (Array.isArray(left) || Array.isArray(right)) {
|
|
118
117
|
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
119
118
|
return left.every((item, index) => isJsonValueEqual(item, right[index]));
|
|
120
119
|
}
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const rightKeys = Object.keys(rightRecord);
|
|
120
|
+
if (!isPlainObject(left) || !isPlainObject(right)) return false;
|
|
121
|
+
const leftKeys = Object.keys(left);
|
|
122
|
+
const rightKeys = Object.keys(right);
|
|
125
123
|
if (leftKeys.length !== rightKeys.length) return false;
|
|
126
|
-
return leftKeys.every((key) => Object.prototype.hasOwnProperty.call(
|
|
124
|
+
return leftKeys.every((key) => Object.prototype.hasOwnProperty.call(right, key) && isJsonValueEqual(left[key], right[key]));
|
|
125
|
+
}
|
|
126
|
+
function isPlainObject(value) {
|
|
127
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
128
|
+
}
|
|
129
|
+
function hasOnlyEnumerableOwnProperties(value) {
|
|
130
|
+
return Object.getOwnPropertyNames(value).every((key) => Object.prototype.propertyIsEnumerable.call(value, key));
|
|
131
|
+
}
|
|
132
|
+
function createJsonRemoveOp(path, value) {
|
|
133
|
+
return json1.type.writeCursor().writeAtPath(path, "r", value).get();
|
|
134
|
+
}
|
|
135
|
+
function normalizeJsonDocument(value) {
|
|
136
|
+
if (value === void 0) return;
|
|
137
|
+
if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") return value;
|
|
138
|
+
if (Array.isArray(value)) return value.map((item) => normalizeJsonDocument(item) ?? null);
|
|
139
|
+
if (!isPlainObject(value)) return;
|
|
140
|
+
const normalizedValue = {};
|
|
141
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
142
|
+
const normalizedItem = normalizeJsonDocument(item);
|
|
143
|
+
if (normalizedItem !== void 0) normalizedValue[key] = normalizedItem;
|
|
144
|
+
});
|
|
145
|
+
return normalizedValue;
|
|
146
|
+
}
|
|
147
|
+
function appendJsonUpdateOps(ops, path, newValue, oldValue, hasOldValue) {
|
|
148
|
+
const normalizedOldValue = normalizeJsonDocument(oldValue);
|
|
149
|
+
const normalizedNewValue = normalizeJsonDocument(newValue);
|
|
150
|
+
const hasNormalizedOldValue = hasOldValue && normalizedOldValue !== void 0;
|
|
151
|
+
if (hasNormalizedOldValue && isJsonValueEqual(normalizedOldValue, normalizedNewValue)) return;
|
|
152
|
+
if (hasNormalizedOldValue && isPlainObject(oldValue) && isPlainObject(newValue) && hasOnlyEnumerableOwnProperties(oldValue) && hasOnlyEnumerableOwnProperties(newValue)) {
|
|
153
|
+
(/* @__PURE__ */ new Set([...Object.keys(oldValue), ...Object.keys(newValue)])).forEach((key) => appendJsonUpdateOps(ops, [...path, key], newValue[key], oldValue[key], Object.prototype.hasOwnProperty.call(oldValue, key) && oldValue[key] !== void 0));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const op = !hasNormalizedOldValue ? normalizedNewValue === void 0 ? null : json1.insertOp(path, normalizedNewValue) : normalizedNewValue === void 0 ? createJsonRemoveOp(path, normalizedOldValue) : json1.replaceOp(path, normalizedOldValue, normalizedNewValue);
|
|
157
|
+
if (op && isNonEmptyOp(op)) ops.push(op);
|
|
127
158
|
}
|
|
128
159
|
/**
|
|
129
160
|
* unitId -> subUnitId -> drawingId -> drawingParam
|
|
@@ -789,6 +820,38 @@ var UnitDrawingService = class {
|
|
|
789
820
|
}
|
|
790
821
|
};
|
|
791
822
|
}
|
|
823
|
+
getDrawingOrderOp(orderParams, zOrder) {
|
|
824
|
+
const { unitId, subUnitId, drawingIds } = orderParams;
|
|
825
|
+
if (drawingIds.length !== 1) return null;
|
|
826
|
+
const orders = this.getDrawingOrder(unitId, subUnitId);
|
|
827
|
+
const drawingId = drawingIds[0];
|
|
828
|
+
const currentIndex = orders.indexOf(drawingId);
|
|
829
|
+
const targetIndex = normalizeDrawingOrderIndex(zOrder, orders.length);
|
|
830
|
+
if (currentIndex < 0 || currentIndex === targetIndex) return null;
|
|
831
|
+
const op = json1.moveOp([
|
|
832
|
+
unitId,
|
|
833
|
+
subUnitId,
|
|
834
|
+
"order",
|
|
835
|
+
currentIndex
|
|
836
|
+
], [
|
|
837
|
+
unitId,
|
|
838
|
+
subUnitId,
|
|
839
|
+
"order",
|
|
840
|
+
targetIndex
|
|
841
|
+
]);
|
|
842
|
+
const invertOp = json1.type.invertWithDoc(op, this.drawingManagerData);
|
|
843
|
+
const affectedDrawingIds = orders.slice(Math.min(currentIndex, targetIndex), Math.max(currentIndex, targetIndex) + 1);
|
|
844
|
+
return {
|
|
845
|
+
undo: invertOp,
|
|
846
|
+
redo: op,
|
|
847
|
+
unitId,
|
|
848
|
+
subUnitId,
|
|
849
|
+
objects: {
|
|
850
|
+
...orderParams,
|
|
851
|
+
drawingIds: affectedDrawingIds
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
}
|
|
792
855
|
_getDrawingCount(unitId, subUnitId) {
|
|
793
856
|
return this.getDrawingOrder(unitId, subUnitId).length || 0;
|
|
794
857
|
}
|
|
@@ -892,7 +955,7 @@ var UnitDrawingService = class {
|
|
|
892
955
|
const op = ops.reduce(json1.type.compose, null);
|
|
893
956
|
return {
|
|
894
957
|
op,
|
|
895
|
-
invertOp: json1.type.
|
|
958
|
+
invertOp: json1.type.invert(op)
|
|
896
959
|
};
|
|
897
960
|
}
|
|
898
961
|
_getUpdateParamCompareOp(newParam, oldParam) {
|
|
@@ -902,27 +965,13 @@ var UnitDrawingService = class {
|
|
|
902
965
|
const newVal = newParam[key];
|
|
903
966
|
const hasOldKey = Object.prototype.hasOwnProperty.call(oldParam, key);
|
|
904
967
|
const oldVal = oldParam[key];
|
|
905
|
-
|
|
906
|
-
const path = [
|
|
968
|
+
appendJsonUpdateOps(ops, [
|
|
907
969
|
unitId,
|
|
908
970
|
subUnitId,
|
|
909
971
|
"data",
|
|
910
972
|
drawingId,
|
|
911
973
|
key
|
|
912
|
-
];
|
|
913
|
-
if (!hasOldKey) {
|
|
914
|
-
if (newVal === void 0) return;
|
|
915
|
-
const op = json1.insertOp(path, newVal);
|
|
916
|
-
if (isNonEmptyOp(op)) ops.push(op);
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
if (newVal === void 0) {
|
|
920
|
-
const op = json1.removeOp(path, true);
|
|
921
|
-
if (isNonEmptyOp(op)) ops.push(op);
|
|
922
|
-
return;
|
|
923
|
-
}
|
|
924
|
-
const op = json1.replaceOp(path, oldVal, newVal);
|
|
925
|
-
if (isNonEmptyOp(op)) ops.push(op);
|
|
974
|
+
], newVal, oldVal, hasOldKey);
|
|
926
975
|
});
|
|
927
976
|
return ops;
|
|
928
977
|
}
|
|
@@ -1108,16 +1157,11 @@ UniverDrawingPlugin = __decorate([
|
|
|
1108
1157
|
], UniverDrawingPlugin);
|
|
1109
1158
|
|
|
1110
1159
|
//#endregion
|
|
1111
|
-
//#region src/utils/drawing-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
DrawingTypeEnum.DRAWING_GROUP
|
|
1117
|
-
];
|
|
1118
|
-
function isGroupableDrawingType(type) {
|
|
1119
|
-
return DRAWING_GROUPABLE_TYPES.includes(type);
|
|
1120
|
-
}
|
|
1160
|
+
//#region src/utils/drawing-copy-plan.ts
|
|
1161
|
+
/**
|
|
1162
|
+
* A command-scoped cache key shared by sheet-copy interceptors so every drawing model
|
|
1163
|
+
* resolves against the same copied drawing IDs.
|
|
1164
|
+
*/
|
|
1121
1165
|
const DRAWING_COPY_CONTEXT_KEY = "univer.drawing.copy-plan";
|
|
1122
1166
|
function cloneDrawing(drawing) {
|
|
1123
1167
|
return JSON.parse(JSON.stringify(drawing));
|
|
@@ -1170,6 +1214,18 @@ function getOrCreateDrawingCopyPlan(copyContext, drawings, options) {
|
|
|
1170
1214
|
return plan;
|
|
1171
1215
|
}
|
|
1172
1216
|
|
|
1217
|
+
//#endregion
|
|
1218
|
+
//#region src/utils/drawing-group.ts
|
|
1219
|
+
const DRAWING_GROUPABLE_TYPES = [
|
|
1220
|
+
DrawingTypeEnum.DRAWING_IMAGE,
|
|
1221
|
+
DrawingTypeEnum.DRAWING_SHAPE,
|
|
1222
|
+
DrawingTypeEnum.DRAWING_CHART,
|
|
1223
|
+
DrawingTypeEnum.DRAWING_GROUP
|
|
1224
|
+
];
|
|
1225
|
+
function isGroupableDrawingType(type) {
|
|
1226
|
+
return DRAWING_GROUPABLE_TYPES.includes(type);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1173
1229
|
//#endregion
|
|
1174
1230
|
//#region src/utils/get-image-shape-key.ts
|
|
1175
1231
|
function getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }, index) {
|
package/lib/types/index.d.ts
CHANGED
|
@@ -24,8 +24,9 @@ export type { IDrawingGroupUpdateParam, IDrawingMap, IDrawingMapItem, IDrawingMa
|
|
|
24
24
|
export { IDrawingManagerService } from './services/drawing-manager.service';
|
|
25
25
|
export { ImageIoService } from './services/image-io-impl.service';
|
|
26
26
|
export { URLImageService } from './services/url-image.service';
|
|
27
|
-
export { createDrawingCopyPlan, DRAWING_COPY_CONTEXT_KEY,
|
|
28
|
-
export type { ICreateDrawingCopyPlanOptions, IDrawingCopyPlan } from './utils/drawing-
|
|
27
|
+
export { createDrawingCopyPlan, DRAWING_COPY_CONTEXT_KEY, getOrCreateDrawingCopyPlan } from './utils/drawing-copy-plan';
|
|
28
|
+
export type { ICreateDrawingCopyPlanOptions, IDrawingCopyPlan } from './utils/drawing-copy-plan';
|
|
29
|
+
export { DRAWING_GROUPABLE_TYPES, isGroupableDrawingType } from './utils/drawing-group';
|
|
29
30
|
export { getDrawingShapeKeyByDrawingSearch } from './utils/get-image-shape-key';
|
|
30
31
|
export { getImageSize } from './utils/get-image-size';
|
|
31
32
|
export { resolveDrawingRotateEnabled } from './utils/rotate-enabled';
|
|
@@ -14,15 +14,17 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { IDrawingGroupNestedParam, IDrawingParam, IDrawingSearch, Nullable } from '@univerjs/core';
|
|
17
|
-
import type { JSONOp, JSONOpList } from 'ot-json1';
|
|
18
17
|
import type { Observable } from 'rxjs';
|
|
19
18
|
import type { IDrawingGroupUpdateParam, IDrawingMap, IDrawingMapItemData, IDrawingOrderMapParam, IDrawingOrderUpdateParam, IDrawingSubunitMap, IDrawingVisibleParam, IUnitDrawingService } from './drawing-manager.service';
|
|
20
|
-
|
|
19
|
+
import * as json1 from 'ot-json1';
|
|
20
|
+
type JSONOp = json1.JSONOp;
|
|
21
|
+
type JSONOpList = json1.JSONOpList;
|
|
22
|
+
export interface IDrawingJsonUndo1<TObjects = IDrawingSearch[] | IDrawingOrderMapParam | IDrawingGroupUpdateParam | IDrawingGroupUpdateParam[]> {
|
|
21
23
|
undo: JSONOp;
|
|
22
24
|
redo: JSONOp;
|
|
23
25
|
unitId: string;
|
|
24
26
|
subUnitId: string;
|
|
25
|
-
objects:
|
|
27
|
+
objects: TObjects;
|
|
26
28
|
}
|
|
27
29
|
export interface IDrawingJson1Type {
|
|
28
30
|
op: JSONOp | JSONOpList;
|
|
@@ -82,7 +84,7 @@ export declare class UnitDrawingService<T extends IDrawingParam> implements IUni
|
|
|
82
84
|
getBatchRemoveOpInOder(removeParams: IDrawingSearch[]): IDrawingJsonUndo1;
|
|
83
85
|
private _getExpandedBatchRemoveParams;
|
|
84
86
|
getBatchRemoveOp(removeParams: IDrawingSearch[]): IDrawingJsonUndo1;
|
|
85
|
-
getBatchUpdateOp(updateParams: T[]): IDrawingJsonUndo1
|
|
87
|
+
getBatchUpdateOp(updateParams: T[]): IDrawingJsonUndo1<IDrawingSearch[]>;
|
|
86
88
|
removeNotification(removeParams: IDrawingSearch[]): void;
|
|
87
89
|
addNotification(insertParams: IDrawingSearch[]): void;
|
|
88
90
|
updateNotification(updateParams: IDrawingSearch[]): void;
|
|
@@ -115,6 +117,7 @@ export declare class UnitDrawingService<T extends IDrawingParam> implements IUni
|
|
|
115
117
|
getBackwardDrawingOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1;
|
|
116
118
|
getFrontDrawingsOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1;
|
|
117
119
|
getBackDrawingsOp(orderParams: IDrawingOrderMapParam): IDrawingJsonUndo1;
|
|
120
|
+
getDrawingOrderOp(orderParams: IDrawingOrderMapParam, zOrder: number): Nullable<IDrawingJsonUndo1>;
|
|
118
121
|
private _getDrawingCount;
|
|
119
122
|
private _getOrderFromSearchParams;
|
|
120
123
|
private _hasDrawingOrder;
|
|
@@ -134,3 +137,4 @@ export declare class UnitDrawingService<T extends IDrawingParam> implements IUni
|
|
|
134
137
|
}
|
|
135
138
|
export declare class DrawingManagerService extends UnitDrawingService<IDrawingParam> {
|
|
136
139
|
}
|
|
140
|
+
export {};
|
|
@@ -101,6 +101,7 @@ export interface IUnitOrderDrawingService {
|
|
|
101
101
|
getBackwardDrawingOp(orderParams: IDrawingOrderMapParam): unknown;
|
|
102
102
|
getFrontDrawingsOp(orderParams: IDrawingOrderMapParam): unknown;
|
|
103
103
|
getBackDrawingsOp(orderParams: IDrawingOrderMapParam): unknown;
|
|
104
|
+
getDrawingOrderOp(orderParams: IDrawingOrderMapParam, zOrder: number): unknown;
|
|
104
105
|
getDrawingOrder(unitId: string, subUnitId: string): string[];
|
|
105
106
|
setDrawingOrder(unitId: string, subUnitId: string, order: string[]): void;
|
|
106
107
|
orderUpdateNotification(orderParams: IDrawingOrderMapParam): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IDrawingParam } from '@univerjs/core';
|
|
17
|
+
/**
|
|
18
|
+
* A command-scoped cache key shared by sheet-copy interceptors so every drawing model
|
|
19
|
+
* resolves against the same copied drawing IDs.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DRAWING_COPY_CONTEXT_KEY = "univer.drawing.copy-plan";
|
|
22
|
+
export interface ICreateDrawingCopyPlanOptions {
|
|
23
|
+
unitId: string;
|
|
24
|
+
sourceSubUnitId: string;
|
|
25
|
+
targetSubUnitId: string;
|
|
26
|
+
generateId?: () => string;
|
|
27
|
+
}
|
|
28
|
+
export interface IDrawingCopyPlan<T extends IDrawingParam = IDrawingParam> {
|
|
29
|
+
idMap: Map<string, string>;
|
|
30
|
+
drawings: T[];
|
|
31
|
+
}
|
|
32
|
+
export declare function createDrawingCopyPlan<T extends IDrawingParam>(drawings: readonly T[], options: ICreateDrawingCopyPlanOptions): IDrawingCopyPlan<T>;
|
|
33
|
+
export declare function getOrCreateDrawingCopyPlan<T extends IDrawingParam>(copyContext: Map<string, unknown> | undefined, drawings: readonly T[], options: ICreateDrawingCopyPlanOptions): IDrawingCopyPlan<T>;
|
|
@@ -13,20 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { DrawingType
|
|
16
|
+
import type { DrawingType } from '@univerjs/core';
|
|
17
17
|
import { DrawingTypeEnum } from '@univerjs/core';
|
|
18
18
|
export declare const DRAWING_GROUPABLE_TYPES: readonly [DrawingTypeEnum.DRAWING_IMAGE, DrawingTypeEnum.DRAWING_SHAPE, DrawingTypeEnum.DRAWING_CHART, DrawingTypeEnum.DRAWING_GROUP];
|
|
19
19
|
export declare function isGroupableDrawingType(type: DrawingType): boolean;
|
|
20
|
-
export declare const DRAWING_COPY_CONTEXT_KEY = "univer.drawing.copy-plan";
|
|
21
|
-
export interface ICreateDrawingCopyPlanOptions {
|
|
22
|
-
unitId: string;
|
|
23
|
-
sourceSubUnitId: string;
|
|
24
|
-
targetSubUnitId: string;
|
|
25
|
-
generateId?: () => string;
|
|
26
|
-
}
|
|
27
|
-
export interface IDrawingCopyPlan<T extends IDrawingParam = IDrawingParam> {
|
|
28
|
-
idMap: Map<string, string>;
|
|
29
|
-
drawings: T[];
|
|
30
|
-
}
|
|
31
|
-
export declare function createDrawingCopyPlan<T extends IDrawingParam>(drawings: readonly T[], options: ICreateDrawingCopyPlanOptions): IDrawingCopyPlan<T>;
|
|
32
|
-
export declare function getOrCreateDrawingCopyPlan<T extends IDrawingParam>(copyContext: Map<string, unknown> | undefined, drawings: readonly T[], options: ICreateDrawingCopyPlanOptions): IDrawingCopyPlan<T>;
|
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),e=null),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=5*1024*1024;function p(e){f=e}function m(){return f}let h=[`image/png`,`image/jpeg`,`image/jpg`,`image/gif`,`image/bmp`],g=(0,t.createIdentifier)(`univer.drawing-manager.service`),_={id:`drawing.operation.set-drawing-selected`,type:t.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(g);return t==null?!1:(n.focusDrawing(t),!0)}};var v=`@univerjs/drawing`,y=`1.0.0-insiders.20260809-70eefdd`;let b={};var x=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})),S=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})),C=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??s,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})),w=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||={})})),T=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}})),E=l((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.uniSlice=e.dlen=e.eachOp=void 0;let t=T(),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})),D=l((e=>{Object.defineProperty(e,"__esModule",{value:!0});let t=E(),n=T();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}})),O=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=T(),o=r(E()),s=i(D()),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=E();Object.defineProperty(e,"makeType",{enumerable:!0,get:function(){return u.default}})})),k=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(x()),r=t(S()),i=C(),a=w(),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:y,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 y(e){let t=e.type?e.type:e;t.name&&(v[t.name]=t),t.uri&&(v[t.uri]=t)}let b=e=>{let t=v[e];if(t)return t;throw Error(`Missing type: `+e)};y(O());let T=(e,t)=>e+t;y({name:`number`,apply:T,compose:T,invert:e=>-e,transform:e=>e});let E=e=>e==null?null:e.et?b(e.et):e.es?v[`text-unicode`]:e.ena==null?null:v.number,D=e=>e.es?e.es:e.ena==null?e.e:e.ena,k=(e,t,n,r=!1)=>{let[i,a]=typeof t==`string`?[b(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=E(e);s(t,`Missing type in edit`),t.checkValidOp&&t.checkValidOp(D(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=E(e);if(i){let t=D(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]??(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=E(t);if(e)f(),i=l[u]=e.apply(i,D(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=E(a);if(o){let n=D(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,O=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(O!=null)if(t=d[O],x=c[O]=new i.WriteCursor,j)y&&!w&&x.write(`r`,!0);else{let e=h[O]=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=O==null?n++:h[O];g[A]=e,x.write(`p`,e)}}else w&&(T||v!==void 0||(C.r,x.write(`r`,C.r)));let F=j?null:E(S),I=E(M);if((F||I)&&(F&&F.name,I&&I.name),F&&I){s(F===I);let e=D(S),t=D(M),n=F.compose(e,t);k(b,F,n),_.add(M)}else F?k(b,F,D(S)):I&&(k(b,I,D(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),!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=E(e);r&&!_.has(e)&&k(t,r,D(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=E(o);e&&(i===void 0?(r||=new Set,r.add(o)):(D(o),i=e.apply(i,D(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=E(c);if(!e.invert)throw Error(`Cannot invert subtype ${e.name}`);k(s,e,e.invert(D(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=E(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=E(i);a&&(a.makeInvertible?o=!0:k(t,a,D(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=E(s);if(e&&e.makeInvertible){let t=D(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=[],O=[],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]??(P[s]=[]),P[s].push(d)),T[d],n=b[d]||null,r=v[d]||null,T[d]?(c&&(O[d]=!0),c=w[d]||null):!c||m!==1&&N[d]!=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 _=E(u);_&&c&&h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.editOp(o.getPath(),_,D(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};O.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??=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,O){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??={type:a.ConflictType.DROP_COLLISION,op1:I(t==null?null:g[t],c,A),op2:I(o==null?null:v[o],b,M)})),s||(O?h??={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:I(t==null?null:g[t],c,A),op2:e.removeOp(O.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&&(O=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,O=u.clone()):e!=null&&(b=y[e],m!==1&&N[e]!=null||((w=j[e])||(w=j[e]=i.writeCursor()),w.reset(),O=null))}else!p(A)&&p(M)&&(b=null);M=b==null?null:b.getComponent();let V=E(A);if(V){let t=D(A);if(O)h??={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.editOp(c.getPath(),V,t,!0),op2:e.removeOp(O.getPath())};else{let e=E(M),n;if(e){if(V!==e)throw Error(`Transforming incompatible types`);let r=D(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,O)&&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,O),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]&&!O[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)||E(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)}}}})),A=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(k(),e);var r=C();Object.defineProperty(e,"ReadCursor",{enumerable:!0,get:function(){return r.ReadCursor}}),Object.defineProperty(e,"WriteCursor",{enumerable:!0,get:function(){return r.WriteCursor}});var i=w();Object.defineProperty(e,"ConflictType",{enumerable:!0,get:function(){return i.ConflictType}})}))());function j(e){"@babel/helpers - typeof";return j=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},j(e)}function M(e,t){if(j(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(j(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function N(e){var t=M(e,`string`);return j(t)==`symbol`?t:t+``}function P(e,t,n){return(t=N(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function F(e){return Array.isArray(e)&&e.length>0}function I(e,t){if(e===t)return!0;if(e==null||t==null||typeof e!=`object`||typeof t!=`object`)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length?!1:e.every((e,n)=>I(e,t[n]));let n=e,r=t,i=Object.keys(n),a=Object.keys(r);return i.length===a.length&&i.every(e=>Object.prototype.hasOwnProperty.call(r,e)&&I(n[e],r[e]))}var L=class{constructor(){P(this,`drawingManagerData`,{}),P(this,`_oldDrawingManagerData`,{}),P(this,`_focusDrawings`,[]),P(this,`_remove$`,new n.Subject),P(this,`remove$`,this._remove$.asObservable()),P(this,`_add$`,new n.Subject),P(this,`add$`,this._add$.asObservable()),P(this,`_update$`,new n.Subject),P(this,`update$`,this._update$.asObservable()),P(this,`_order$`,new n.Subject),P(this,`order$`,this._order$.asObservable()),P(this,`_group$`,new n.Subject),P(this,`group$`,this._group$.asObservable()),P(this,`_ungroup$`,new n.Subject),P(this,`ungroup$`,this._ungroup$.asObservable()),P(this,`_refreshTransform$`,new n.Subject),P(this,`refreshTransform$`,this._refreshTransform$.asObservable()),P(this,`_visible$`,new n.Subject),P(this,`visible$`,this._visible$.asObservable()),P(this,`_focus$`,new n.Subject),P(this,`focus$`,this._focus$.asObservable()),P(this,`_featurePluginUpdate$`,new n.Subject),P(this,`featurePluginUpdate$`,this._featurePluginUpdate$.asObservable()),P(this,`_featurePluginAdd$`,new n.Subject),P(this,`featurePluginAdd$`,this._featurePluginAdd$.asObservable()),P(this,`_featurePluginRemove$`,new n.Subject),P(this,`featurePluginRemove$`,this._featurePluginRemove$.asObservable()),P(this,`_featurePluginOrderUpdate$`,new n.Subject),P(this,`featurePluginOrderUpdate$`,this._featurePluginOrderUpdate$.asObservable()),P(this,`_featurePluginGroupUpdate$`,new n.Subject),P(this,`featurePluginGroupUpdate$`,this._featurePluginGroupUpdate$.asObservable()),P(this,`_featurePluginUngroupUpdate$`,new n.Subject),P(this,`featurePluginUngroupUpdate$`,this._featurePluginUngroupUpdate$.asObservable()),P(this,`_visible`,!0),P(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,Object.prototype.hasOwnProperty.call(e,`transforms`)&&(t.transforms=e.transforms),Object.prototype.hasOwnProperty.call(e,`isMultiTransform`)&&(t.isMultiTransform=e.isMultiTransform),`behindText`in e&&(t.behindText=e.behindText),`hidden`in e&&(t.hidden=e.hidden))}),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];(i==null?void 0:i.data)!=null&&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){let r=this.drawingManagerData[e],i=r[t];this._oldDrawingManagerData={...this.drawingManagerData,[e]:{...r,[t]:{...i}}},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(A.type.compose,null),a=r.reduce(A.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)=>(n.get(e.drawingId)??-1/0)-(n.get(t.drawingId)??-1/0)),this.getBatchRemoveOp(e)}_getExpandedBatchRemoveParams(e){let n=new Set,r=[],i=e=>{n.has(e.drawingId)||(n.add(e.drawingId),r.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}))},a=e=>{n.has(e.drawingId)||(n.add(e.drawingId),r.push(e))};return 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??[],...n].forEach(e=>{i(e)})}else i(n)}else n?i(n):a(e)}),r}getBatchRemoveOp(e){let t=this._getExpandedBatchRemoveParams(e),{unitId:n,subUnitId:r}=t[0]??e[0]??{unitId:``,subUnitId:``};if(t.length===0)return{undo:null,redo:null,unitId:n,subUnitId:r,objects:[]};let i=this._getDrawingOrder(n,r),a=new Map;i.forEach((e,t)=>a.set(e,t)),t.sort((e,t)=>(a.get(e.drawingId)??-1/0)-(a.get(t.drawingId)??-1/0));let o=[],s=[];t.forEach(e=>{let{op:t,invertOp:n}=this._removeByParam(e);o.unshift(t),s.push(n)});let c=o.reduce(A.type.compose,null);return{undo:s.reduce(A.type.compose,null),redo:c,unitId:n,subUnitId:r,objects:t}}getBatchUpdateOp(e){let t=[],n=[],r=[];if(e.forEach(e=>{let{op:i,invertOp:a}=this._updateByParam(e);F(i)&&(t.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),n.push(i),r.push(a))}),n.length===0){let{unitId:n,subUnitId:r}=e[0];return{undo:null,redo:null,unitId:n,subUnitId:r,objects:t}}let i=n.reduce(A.type.compose,null),a=r.reduce(A.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(A.type.compose,null);return{undo:A.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(A.type.compose,null);return{undo:A.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=>{let{drawingId:n}=e,r=o.get(n)??[];l[n]={drawingId:n,children:r},r.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(A.insertOp([r,i,`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(A.insertOp([r,i,`order`,s],a)),o.reduce(A.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(A.removeOp([r,i,`data`,a],!0)),o.push(A.removeOp([r,i,`order`,this._getDrawingOrder(r,i).indexOf(a)],!0)),o.reduce(A.type.compose,null)}applyJson1(e,t,n){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=A.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=A.moveOp([t,n,`order`,r],[t,n,`order`,r+1]);i.push(s),o.includes(a[r+1])||o.push(a[r+1])});let s=i.reduce(A.type.compose,null);return{undo:A.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=A.moveOp([t,n,`order`,r],[t,n,`order`,r-1]);i.push(s),o.includes(a[r-1])||o.push(a[r-1])});let s=i.reduce(A.type.compose,null);return{undo:A.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=A.moveOp([t,n,`order`,this._getDrawingOrder(t,n).indexOf(r)],[t,n,`order`,i]);s.push(c),a.includes(o[i])||a.push(o[i])});let c=s.reduce(A.type.compose,null);return{undo:A.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=A.moveOp([t,n,`order`,this._getDrawingOrder(t,n).indexOf(r)],[t,n,`order`,0]);s.push(i),a.includes(o[0])||a.push(o[0])});let c=s.reduce(A.type.compose,null);return{undo:A.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=[A.insertOp([t,n,`data`,r],e),A.insertOp([t,n,`order`,this._getDrawingOrder(t,n).length],r)].reduce(A.type.compose,null);return{op:i,invertOp:A.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=[A.removeOp([t,n,`data`,r],!0),A.removeOp([t,n,`order`,this._getDrawingOrder(t,n).indexOf(r)],!0)].reduce(A.type.compose,null);return{op:i,invertOp:A.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);if(a.length===0)return{op:[],invertOp:[]};let o=a.reduce(A.type.compose,null);return{op:o,invertOp:A.type.invertWithDoc(o,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=Object.prototype.hasOwnProperty.call(t,o),l=t[o];if(c&&I(l,s))return;let u=[n,r,`data`,i,o];if(!c){if(s===void 0)return;let e=A.insertOp(u,s);F(e)&&a.push(e);return}if(s===void 0){let e=A.removeOp(u,!0);F(e)&&a.push(e);return}let d=A.replaceOp(u,l,s);F(d)&&a.push(d)}),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}},R=class extends L{},z=class{constructor(){P(this,`_waitCount`,0),P(this,`_change$`,new n.Subject),P(this,`change$`,this._change$),P(this,`_imageSourceCache`,new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,n){let r=this._imageSourceCache.get(e);if(r!=null)return r;if(n===t.ImageSourceType.BASE64){let t=new Image;return t.onload=()=>this._change$.next(this._waitCount),t.onerror=()=>this._change$.next(this._waitCount),t.src=e,this._imageSourceCache.set(e,t),t}}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(!h.includes(e.type)){r(Error(t.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>m()){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)}},B=class extends t.Disposable{constructor(...e){super(...e),P(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 V(e,t){return function(n,r){t(n,r,e)}}function H(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 U=class extends t.Plugin{constructor(e=b,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},b,this._config);this._configService.setConfig(`drawing.config`,a),a.allowImageSize!==void 0&&p(a.allowImageSize)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var e;(0,t.mergeOverrideWithDependencies)([[t.IImageIoService,{useClass:z}],[t.IURLImageService,{useClass:B}],[g,{useClass:R}]],(e=this._config)==null?void 0:e.override).forEach(e=>this._injector.add(e))}_initCommands(){[_].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};P(U,`pluginName`,`UNIVER_DRAWING_PLUGIN`),P(U,`packageName`,v),P(U,`version`,y),U=H([V(1,(0,t.Inject)(t.Injector)),V(2,t.IConfigService),V(3,t.ICommandService)],U);let W=[t.DrawingTypeEnum.DRAWING_IMAGE,t.DrawingTypeEnum.DRAWING_SHAPE,t.DrawingTypeEnum.DRAWING_CHART,t.DrawingTypeEnum.DRAWING_GROUP];function G(e){return W.includes(e)}let K=`univer.drawing.copy-plan`;function q(e){return JSON.parse(JSON.stringify(e))}function J(e,t,n){let r=q(e),i=t.get(e.drawingId);if(i==null)return r;if(r.unitId=n.unitId,r.subUnitId=n.targetSubUnitId,r.drawingId=i,r.groupId){let e=t.get(r.groupId);e?r.groupId=e:delete r.groupId}return r}function Y(e,n){let{generateId:r=()=>(0,t.generateRandomId)(10)}=n,i=new Map;return e.forEach(e=>{i.has(e.drawingId)||i.set(e.drawingId,r())}),{idMap:i,drawings:e.map(e=>J(e,i,n))}}function X(e,n,r){if(e==null)return Y(n,r);let i=e.get(K);if(i){let{generateId:e=()=>(0,t.generateRandomId)(10)}=r;if(!n.some(e=>!i.idMap.has(e.drawingId)))return i;n.forEach(t=>{i.idMap.has(t.drawingId)||i.idMap.set(t.drawingId,e())});let a=new Set(n.map(e=>e.drawingId)),o=new Map(Array.from(i.idMap.entries()).map(([e,t])=>[t,e])),s=i.drawings.filter(e=>{let t=o.get(e.drawingId);return t==null||!a.has(t)});return i.drawings=[...n.map(e=>J(e,i.idMap,r)),...s],i}let a=Y(n,r);return e.set(K,a),a}function Z({unitId:e,subUnitId:t,drawingId:n},r){return typeof r==`number`?`${e}#-#${t}#-#${n}#-#${r}`:`${e}#-#${t}#-#${n}`}let Q=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)}});function $(e){return`${e.unitId}\u0000${e.subUnitId}\u0000${e.drawingId}`}function ee(e,n={},r=new Set){var i,a,o;let s=$(e);if(r.has(s))return!0;if(e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP){var c;r.add(s);let t=(c=n.getChildren)==null?void 0:c.call(n,e);if(t!=null){let e=t.every(e=>ee(e,n,r));return r.delete(s),e}r.delete(s)}return!(((i=e.transform)==null?void 0:i.rotateEnabled)===!1||((a=n.getRenderObject)==null||(a=a.call(n,e))==null||(a=a.transformerConfig)==null?void 0:a.rotateEnabled)===!1||(o=n.isKnownNonRotatableType)!=null&&o.call(n,e.drawingType))}e.DRAWING_COPY_CONTEXT_KEY=K,e.DRAWING_GROUPABLE_TYPES=W,e.DRAWING_IMAGE_ALLOW_IMAGE_LIST=h,e.DRAWING_IMAGE_COUNT_LIMIT=10,e.DRAWING_IMAGE_HEIGHT_LIMIT=500,e.DRAWING_IMAGE_WIDTH_LIMIT=500,e.DrawingManagerService=R,e.IDrawingManagerService=g,e.ImageIoService=z,e.SetDrawingSelectedOperation=_,e.URLImageService=B,e.UnitDrawingService=L,Object.defineProperty(e,"UniverDrawingPlugin",{enumerable:!0,get:function(){return U}}),e.createDrawingCopyPlan=Y,e.getDrawingImageAllowSize=m,e.getDrawingShapeKeyByDrawingSearch=Z,e.getImageSize=Q,e.getOrCreateDrawingCopyPlan=X,e.isGroupableDrawingType=G,e.resolveDrawingRotateEnabled=ee});
|
|
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),e=null),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=5*1024*1024;function p(e){f=e}function m(){return f}let h=[`image/png`,`image/jpeg`,`image/jpg`,`image/gif`,`image/bmp`],g=(0,t.createIdentifier)(`univer.drawing-manager.service`),_={id:`drawing.operation.set-drawing-selected`,type:t.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(g);return t==null?!1:(n.focusDrawing(t),!0)}};var v=`@univerjs/drawing`,y=`1.0.0-rc.0`;let b={};var x=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})),S=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})),C=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??s,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})),w=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||={})})),T=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}})),E=l((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.uniSlice=e.dlen=e.eachOp=void 0;let t=T(),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})),D=l((e=>{Object.defineProperty(e,"__esModule",{value:!0});let t=E(),n=T();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}})),O=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=T(),o=r(E()),s=i(D()),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=E();Object.defineProperty(e,"makeType",{enumerable:!0,get:function(){return u.default}})})),k=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(x()),r=t(S()),i=C(),a=w(),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:y,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 y(e){let t=e.type?e.type:e;t.name&&(v[t.name]=t),t.uri&&(v[t.uri]=t)}let b=e=>{let t=v[e];if(t)return t;throw Error(`Missing type: `+e)};y(O());let T=(e,t)=>e+t;y({name:`number`,apply:T,compose:T,invert:e=>-e,transform:e=>e});let E=e=>e==null?null:e.et?b(e.et):e.es?v[`text-unicode`]:e.ena==null?null:v.number,D=e=>e.es?e.es:e.ena==null?e.e:e.ena,k=(e,t,n,r=!1)=>{let[i,a]=typeof t==`string`?[b(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=E(e);s(t,`Missing type in edit`),t.checkValidOp&&t.checkValidOp(D(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=E(e);if(i){let t=D(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]??(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=E(t);if(e)f(),i=l[u]=e.apply(i,D(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=E(a);if(o){let n=D(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,O=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(O!=null)if(t=d[O],x=c[O]=new i.WriteCursor,j)y&&!w&&x.write(`r`,!0);else{let e=h[O]=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=O==null?n++:h[O];g[A]=e,x.write(`p`,e)}}else w&&(T||v!==void 0||(C.r,x.write(`r`,C.r)));let F=j?null:E(S),I=E(M);if((F||I)&&(F&&F.name,I&&I.name),F&&I){s(F===I);let e=D(S),t=D(M),n=F.compose(e,t);k(b,F,n),_.add(M)}else F?k(b,F,D(S)):I&&(k(b,I,D(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),!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=E(e);r&&!_.has(e)&&k(t,r,D(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=E(o);e&&(i===void 0?(r||=new Set,r.add(o)):(D(o),i=e.apply(i,D(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=E(c);if(!e.invert)throw Error(`Cannot invert subtype ${e.name}`);k(s,e,e.invert(D(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=E(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=E(i);a&&(a.makeInvertible?o=!0:k(t,a,D(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=E(s);if(e&&e.makeInvertible){let t=D(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=[],O=[],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]??(P[s]=[]),P[s].push(d)),T[d],n=b[d]||null,r=v[d]||null,T[d]?(c&&(O[d]=!0),c=w[d]||null):!c||m!==1&&N[d]!=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 _=E(u);_&&c&&h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.editOp(o.getPath(),_,D(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};O.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??=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,O){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??={type:a.ConflictType.DROP_COLLISION,op1:I(t==null?null:g[t],c,A),op2:I(o==null?null:v[o],b,M)})),s||(O?h??={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:I(t==null?null:g[t],c,A),op2:e.removeOp(O.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&&(O=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,O=u.clone()):e!=null&&(b=y[e],m!==1&&N[e]!=null||((w=j[e])||(w=j[e]=i.writeCursor()),w.reset(),O=null))}else!p(A)&&p(M)&&(b=null);M=b==null?null:b.getComponent();let V=E(A);if(V){let t=D(A);if(O)h??={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.editOp(c.getPath(),V,t,!0),op2:e.removeOp(O.getPath())};else{let e=E(M),n;if(e){if(V!==e)throw Error(`Transforming incompatible types`);let r=D(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,O)&&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,O),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]&&!O[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)||E(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)}}}})),A=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(k(),e);var r=C();Object.defineProperty(e,"ReadCursor",{enumerable:!0,get:function(){return r.ReadCursor}}),Object.defineProperty(e,"WriteCursor",{enumerable:!0,get:function(){return r.WriteCursor}});var i=w();Object.defineProperty(e,"ConflictType",{enumerable:!0,get:function(){return i.ConflictType}})}))());function j(e){"@babel/helpers - typeof";return j=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},j(e)}function M(e,t){if(j(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(j(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function N(e){var t=M(e,`string`);return j(t)==`symbol`?t:t+``}function P(e,t,n){return(t=N(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function F(e){return Array.isArray(e)&&e.length>0}function I(e,t){if(e===t)return!0;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length?!1:e.every((e,n)=>I(e,t[n]));if(!L(e)||!L(t))return!1;let n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every(n=>Object.prototype.hasOwnProperty.call(t,n)&&I(e[n],t[n]))}function L(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function R(e){return Object.getOwnPropertyNames(e).every(t=>Object.prototype.propertyIsEnumerable.call(e,t))}function z(e,t){return A.type.writeCursor().writeAtPath(e,`r`,t).get()}function B(e){if(e===void 0)return;if(e===null||typeof e==`boolean`||typeof e==`number`||typeof e==`string`)return e;if(Array.isArray(e))return e.map(e=>B(e)??null);if(!L(e))return;let t={};return Object.entries(e).forEach(([e,n])=>{let r=B(n);r!==void 0&&(t[e]=r)}),t}function V(e,t,n,r,i){let a=B(r),o=B(n),s=i&&a!==void 0;if(s&&I(a,o))return;if(s&&L(r)&&L(n)&&R(r)&&R(n)){new Set([...Object.keys(r),...Object.keys(n)]).forEach(i=>V(e,[...t,i],n[i],r[i],Object.prototype.hasOwnProperty.call(r,i)&&r[i]!==void 0));return}let c=s?o===void 0?z(t,a):A.replaceOp(t,a,o):o===void 0?null:A.insertOp(t,o);c&&F(c)&&e.push(c)}var H=class{constructor(){P(this,`drawingManagerData`,{}),P(this,`_oldDrawingManagerData`,{}),P(this,`_focusDrawings`,[]),P(this,`_remove$`,new n.Subject),P(this,`remove$`,this._remove$.asObservable()),P(this,`_add$`,new n.Subject),P(this,`add$`,this._add$.asObservable()),P(this,`_update$`,new n.Subject),P(this,`update$`,this._update$.asObservable()),P(this,`_order$`,new n.Subject),P(this,`order$`,this._order$.asObservable()),P(this,`_group$`,new n.Subject),P(this,`group$`,this._group$.asObservable()),P(this,`_ungroup$`,new n.Subject),P(this,`ungroup$`,this._ungroup$.asObservable()),P(this,`_refreshTransform$`,new n.Subject),P(this,`refreshTransform$`,this._refreshTransform$.asObservable()),P(this,`_visible$`,new n.Subject),P(this,`visible$`,this._visible$.asObservable()),P(this,`_focus$`,new n.Subject),P(this,`focus$`,this._focus$.asObservable()),P(this,`_featurePluginUpdate$`,new n.Subject),P(this,`featurePluginUpdate$`,this._featurePluginUpdate$.asObservable()),P(this,`_featurePluginAdd$`,new n.Subject),P(this,`featurePluginAdd$`,this._featurePluginAdd$.asObservable()),P(this,`_featurePluginRemove$`,new n.Subject),P(this,`featurePluginRemove$`,this._featurePluginRemove$.asObservable()),P(this,`_featurePluginOrderUpdate$`,new n.Subject),P(this,`featurePluginOrderUpdate$`,this._featurePluginOrderUpdate$.asObservable()),P(this,`_featurePluginGroupUpdate$`,new n.Subject),P(this,`featurePluginGroupUpdate$`,this._featurePluginGroupUpdate$.asObservable()),P(this,`_featurePluginUngroupUpdate$`,new n.Subject),P(this,`featurePluginUngroupUpdate$`,this._featurePluginUngroupUpdate$.asObservable()),P(this,`_visible`,!0),P(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,Object.prototype.hasOwnProperty.call(e,`transforms`)&&(t.transforms=e.transforms),Object.prototype.hasOwnProperty.call(e,`isMultiTransform`)&&(t.isMultiTransform=e.isMultiTransform),`behindText`in e&&(t.behindText=e.behindText),`hidden`in e&&(t.hidden=e.hidden))}),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];(i==null?void 0:i.data)!=null&&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){let r=this.drawingManagerData[e],i=r[t];this._oldDrawingManagerData={...this.drawingManagerData,[e]:{...r,[t]:{...i}}},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(A.type.compose,null),a=r.reduce(A.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)=>(n.get(e.drawingId)??-1/0)-(n.get(t.drawingId)??-1/0)),this.getBatchRemoveOp(e)}_getExpandedBatchRemoveParams(e){let n=new Set,r=[],i=e=>{n.has(e.drawingId)||(n.add(e.drawingId),r.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}))},a=e=>{n.has(e.drawingId)||(n.add(e.drawingId),r.push(e))};return 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??[],...n].forEach(e=>{i(e)})}else i(n)}else n?i(n):a(e)}),r}getBatchRemoveOp(e){let t=this._getExpandedBatchRemoveParams(e),{unitId:n,subUnitId:r}=t[0]??e[0]??{unitId:``,subUnitId:``};if(t.length===0)return{undo:null,redo:null,unitId:n,subUnitId:r,objects:[]};let i=this._getDrawingOrder(n,r),a=new Map;i.forEach((e,t)=>a.set(e,t)),t.sort((e,t)=>(a.get(e.drawingId)??-1/0)-(a.get(t.drawingId)??-1/0));let o=[],s=[];t.forEach(e=>{let{op:t,invertOp:n}=this._removeByParam(e);o.unshift(t),s.push(n)});let c=o.reduce(A.type.compose,null);return{undo:s.reduce(A.type.compose,null),redo:c,unitId:n,subUnitId:r,objects:t}}getBatchUpdateOp(e){let t=[],n=[],r=[];if(e.forEach(e=>{let{op:i,invertOp:a}=this._updateByParam(e);F(i)&&(t.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),n.push(i),r.push(a))}),n.length===0){let{unitId:n,subUnitId:r}=e[0];return{undo:null,redo:null,unitId:n,subUnitId:r,objects:t}}let i=n.reduce(A.type.compose,null),a=r.reduce(A.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(A.type.compose,null);return{undo:A.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(A.type.compose,null);return{undo:A.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=>{let{drawingId:n}=e,r=o.get(n)??[];l[n]={drawingId:n,children:r},r.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(A.insertOp([r,i,`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(A.insertOp([r,i,`order`,s],a)),o.reduce(A.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(A.removeOp([r,i,`data`,a],!0)),o.push(A.removeOp([r,i,`order`,this._getDrawingOrder(r,i).indexOf(a)],!0)),o.reduce(A.type.compose,null)}applyJson1(e,t,n){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=A.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=A.moveOp([t,n,`order`,r],[t,n,`order`,r+1]);i.push(s),o.includes(a[r+1])||o.push(a[r+1])});let s=i.reduce(A.type.compose,null);return{undo:A.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=A.moveOp([t,n,`order`,r],[t,n,`order`,r-1]);i.push(s),o.includes(a[r-1])||o.push(a[r-1])});let s=i.reduce(A.type.compose,null);return{undo:A.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=A.moveOp([t,n,`order`,this._getDrawingOrder(t,n).indexOf(r)],[t,n,`order`,i]);s.push(c),a.includes(o[i])||a.push(o[i])});let c=s.reduce(A.type.compose,null);return{undo:A.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=A.moveOp([t,n,`order`,this._getDrawingOrder(t,n).indexOf(r)],[t,n,`order`,0]);s.push(i),a.includes(o[0])||a.push(o[0])});let c=s.reduce(A.type.compose,null);return{undo:A.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:t,subUnitId:n,objects:{...e,drawingIds:a}}}getDrawingOrderOp(e,n){let{unitId:r,subUnitId:i,drawingIds:a}=e;if(a.length!==1)return null;let o=this.getDrawingOrder(r,i),s=a[0],c=o.indexOf(s),l=(0,t.normalizeDrawingOrderIndex)(n,o.length);if(c<0||c===l)return null;let u=A.moveOp([r,i,`order`,c],[r,i,`order`,l]),d=A.type.invertWithDoc(u,this.drawingManagerData),f=o.slice(Math.min(c,l),Math.max(c,l)+1);return{undo:d,redo:u,unitId:r,subUnitId:i,objects:{...e,drawingIds:f}}}_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=[A.insertOp([t,n,`data`,r],e),A.insertOp([t,n,`order`,this._getDrawingOrder(t,n).length],r)].reduce(A.type.compose,null);return{op:i,invertOp:A.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=[A.removeOp([t,n,`data`,r],!0),A.removeOp([t,n,`order`,this._getDrawingOrder(t,n).indexOf(r)],!0)].reduce(A.type.compose,null);return{op:i,invertOp:A.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);if(a.length===0)return{op:[],invertOp:[]};let o=a.reduce(A.type.compose,null);return{op:o,invertOp:A.type.invert(o)}}_getUpdateParamCompareOp(e,t){let{unitId:n,subUnitId:r,drawingId:i}=e,a=[];return Object.keys(e).forEach(o=>{let s=e[o],c=Object.prototype.hasOwnProperty.call(t,o),l=t[o];V(a,[n,r,`data`,i,o],s,l,c)}),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}},U=class extends H{},W=class{constructor(){P(this,`_waitCount`,0),P(this,`_change$`,new n.Subject),P(this,`change$`,this._change$),P(this,`_imageSourceCache`,new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,n){let r=this._imageSourceCache.get(e);if(r!=null)return r;if(n===t.ImageSourceType.BASE64){let t=new Image;return t.onload=()=>this._change$.next(this._waitCount),t.onerror=()=>this._change$.next(this._waitCount),t.src=e,this._imageSourceCache.set(e,t),t}}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(!h.includes(e.type)){r(Error(t.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>m()){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)}},G=class extends t.Disposable{constructor(...e){super(...e),P(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 K(e,t){return function(n,r){t(n,r,e)}}function q(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 J=class extends t.Plugin{constructor(e=b,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},b,this._config);this._configService.setConfig(`drawing.config`,a),a.allowImageSize!==void 0&&p(a.allowImageSize)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var e;(0,t.mergeOverrideWithDependencies)([[t.IImageIoService,{useClass:W}],[t.IURLImageService,{useClass:G}],[g,{useClass:U}]],(e=this._config)==null?void 0:e.override).forEach(e=>this._injector.add(e))}_initCommands(){[_].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};P(J,`pluginName`,`UNIVER_DRAWING_PLUGIN`),P(J,`packageName`,v),P(J,`version`,y),J=q([K(1,(0,t.Inject)(t.Injector)),K(2,t.IConfigService),K(3,t.ICommandService)],J);let Y=`univer.drawing.copy-plan`;function X(e){return JSON.parse(JSON.stringify(e))}function Z(e,t,n){let r=X(e),i=t.get(e.drawingId);if(i==null)return r;if(r.unitId=n.unitId,r.subUnitId=n.targetSubUnitId,r.drawingId=i,r.groupId){let e=t.get(r.groupId);e?r.groupId=e:delete r.groupId}return r}function Q(e,n){let{generateId:r=()=>(0,t.generateRandomId)(10)}=n,i=new Map;return e.forEach(e=>{i.has(e.drawingId)||i.set(e.drawingId,r())}),{idMap:i,drawings:e.map(e=>Z(e,i,n))}}function $(e,n,r){if(e==null)return Q(n,r);let i=e.get(Y);if(i){let{generateId:e=()=>(0,t.generateRandomId)(10)}=r;if(!n.some(e=>!i.idMap.has(e.drawingId)))return i;n.forEach(t=>{i.idMap.has(t.drawingId)||i.idMap.set(t.drawingId,e())});let a=new Set(n.map(e=>e.drawingId)),o=new Map(Array.from(i.idMap.entries()).map(([e,t])=>[t,e])),s=i.drawings.filter(e=>{let t=o.get(e.drawingId);return t==null||!a.has(t)});return i.drawings=[...n.map(e=>Z(e,i.idMap,r)),...s],i}let a=Q(n,r);return e.set(Y,a),a}let ee=[t.DrawingTypeEnum.DRAWING_IMAGE,t.DrawingTypeEnum.DRAWING_SHAPE,t.DrawingTypeEnum.DRAWING_CHART,t.DrawingTypeEnum.DRAWING_GROUP];function te(e){return ee.includes(e)}function ne({unitId:e,subUnitId:t,drawingId:n},r){return typeof r==`number`?`${e}#-#${t}#-#${n}#-#${r}`:`${e}#-#${t}#-#${n}`}let re=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)}});function ie(e){return`${e.unitId}\u0000${e.subUnitId}\u0000${e.drawingId}`}function ae(e,n={},r=new Set){var i,a,o;let s=ie(e);if(r.has(s))return!0;if(e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP){var c;r.add(s);let t=(c=n.getChildren)==null?void 0:c.call(n,e);if(t!=null){let e=t.every(e=>ae(e,n,r));return r.delete(s),e}r.delete(s)}return!(((i=e.transform)==null?void 0:i.rotateEnabled)===!1||((a=n.getRenderObject)==null||(a=a.call(n,e))==null||(a=a.transformerConfig)==null?void 0:a.rotateEnabled)===!1||(o=n.isKnownNonRotatableType)!=null&&o.call(n,e.drawingType))}e.DRAWING_COPY_CONTEXT_KEY=Y,e.DRAWING_GROUPABLE_TYPES=ee,e.DRAWING_IMAGE_ALLOW_IMAGE_LIST=h,e.DRAWING_IMAGE_COUNT_LIMIT=10,e.DRAWING_IMAGE_HEIGHT_LIMIT=500,e.DRAWING_IMAGE_WIDTH_LIMIT=500,e.DrawingManagerService=U,e.IDrawingManagerService=g,e.ImageIoService=W,e.SetDrawingSelectedOperation=_,e.URLImageService=G,e.UnitDrawingService=H,Object.defineProperty(e,"UniverDrawingPlugin",{enumerable:!0,get:function(){return J}}),e.createDrawingCopyPlan=Q,e.getDrawingImageAllowSize=m,e.getDrawingShapeKeyByDrawingSearch=ne,e.getImageSize=re,e.getOrCreateDrawingCopyPlan=$,e.isGroupableDrawingType=te,e.resolveDrawingRotateEnabled=ae});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/drawing",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared drawing models, commands, and services for Univer.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"ot-json1": "^1.0.2",
|
|
56
|
-
"@univerjs/core": "1.0.0-
|
|
56
|
+
"@univerjs/core": "1.0.0-rc.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"rxjs": "^7.8.2",
|
|
60
60
|
"typescript": "^6.0.3",
|
|
61
|
-
"vitest": "^
|
|
62
|
-
"@univerjs-infra/shared": "1.0.0-
|
|
61
|
+
"vitest": "^5.0.0",
|
|
62
|
+
"@univerjs-infra/shared": "1.0.0-rc.0"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"test": "vitest run",
|