@univerjs/drawing 0.17.0 → 0.18.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/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1 -2061
- package/lib/index.js +1 -2061
- package/lib/types/commands/operations/set-drawing-selected.operation.d.ts +16 -1
- package/lib/types/config/config.d.ts +16 -1
- package/lib/types/models/image-model-interface.d.ts +17 -2
- package/lib/types/plugin.d.ts +16 -1
- package/lib/types/services/drawing-manager-impl.service.d.ts +20 -4
- package/lib/types/services/drawing-manager.service.d.ts +19 -3
- package/lib/types/services/image-io-impl.service.d.ts +19 -3
- package/lib/types/services/url-image.service.d.ts +17 -1
- package/lib/types/utils/get-image-shape-key.d.ts +16 -1
- package/lib/types/utils/get-image-size.d.ts +16 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -6
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
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 { IDrawingSearch, IOperation } from '@univerjs/core';
|
|
2
17
|
export declare const SetDrawingSelectedOperation: IOperation<IDrawingSearch[]>;
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
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 { DependencyOverride } from '@univerjs/core';
|
|
2
17
|
export declare const DRAWING_PLUGIN_CONFIG_KEY = "drawing.config";
|
|
3
18
|
export declare const configSymbol: unique symbol;
|
|
4
19
|
export interface IUniverDrawingConfig {
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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, ISrcRect, Nullable, PresetGeometryType, Serializable } from '@univerjs/core';
|
|
17
|
+
import type { ImageSourceType } from '../services/image-io.service';
|
|
3
18
|
export interface IImageData extends IDrawingParam {
|
|
4
19
|
imageSourceType: ImageSourceType;
|
|
5
20
|
source: string;
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
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 { IUniverDrawingConfig } from './config/config';
|
|
2
17
|
import { ICommandService, IConfigService, Injector, Plugin } from '@univerjs/core';
|
|
3
18
|
export declare class UniverDrawingPlugin extends Plugin {
|
|
4
19
|
private readonly _config;
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 { IDrawingGroupNestedParam, IDrawingParam, IDrawingSearch, Nullable } from '@univerjs/core';
|
|
17
|
+
import type { JSONOp, JSONOpList } from 'ot-json1';
|
|
18
|
+
import type { Observable } from 'rxjs';
|
|
19
|
+
import type { IDrawingGroupUpdateParam, IDrawingMap, IDrawingMapItemData, IDrawingOrderMapParam, IDrawingOrderUpdateParam, IDrawingSubunitMap, IDrawingVisibleParam, IUnitDrawingService } from './drawing-manager.service';
|
|
5
20
|
export interface IDrawingJsonUndo1 {
|
|
6
21
|
undo: JSONOp;
|
|
7
22
|
redo: JSONOp;
|
|
@@ -76,6 +91,7 @@ export declare class UnitDrawingService<T extends IDrawingParam> implements IUni
|
|
|
76
91
|
getGroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): IDrawingJsonUndo1;
|
|
77
92
|
getUngroupDrawingOp(groupParams: IDrawingGroupUpdateParam[]): IDrawingJsonUndo1;
|
|
78
93
|
getDrawingsByGroup(groupParam: IDrawingSearch): IDrawingParam[];
|
|
94
|
+
getDrawingsByGroupNested(groupSearch: IDrawingSearch): IDrawingGroupNestedParam | null;
|
|
79
95
|
private _getGroupDrawingOp;
|
|
80
96
|
private _getUngroupDrawingOp;
|
|
81
97
|
applyJson1(unitId: string, subUnitId: string, jsonOp: JSONOp): void;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { ArrangeTypeEnum, IDisposable, IDrawingGroupNestedParam, IDrawingParam, IDrawingSearch, Nullable } from '@univerjs/core';
|
|
17
|
+
import type { Observable } from 'rxjs';
|
|
3
18
|
export interface IDrawingMap<T extends IDrawingParam> {
|
|
4
19
|
[unitId: string]: IDrawingSubunitMap<T>;
|
|
5
20
|
}
|
|
@@ -71,6 +86,7 @@ export interface IUnitGroupDrawingService {
|
|
|
71
86
|
groupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
|
|
72
87
|
ungroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
|
|
73
88
|
getDrawingsByGroup(groupParam: IDrawingSearch): IDrawingParam[];
|
|
89
|
+
getDrawingsByGroupNested(groupParam: IDrawingSearch): IDrawingGroupNestedParam | null;
|
|
74
90
|
featurePluginGroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
|
|
75
91
|
featurePluginUngroupUpdateNotification(groupParams: IDrawingGroupUpdateParam[]): void;
|
|
76
92
|
}
|
|
@@ -110,4 +126,4 @@ export interface IUnitDrawingService<T extends IDrawingParam> extends IUnitNorma
|
|
|
110
126
|
}
|
|
111
127
|
export interface IDrawingManagerService extends IUnitDrawingService<IDrawingParam> {
|
|
112
128
|
}
|
|
113
|
-
export declare const IDrawingManagerService: import(
|
|
129
|
+
export declare const IDrawingManagerService: import("@wendellhu/redi").IdentifierDecorator<IUnitDrawingService<IDrawingParam>>;
|
|
@@ -1,6 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 { Nullable } from '@univerjs/core';
|
|
17
|
+
import type { Observable } from 'rxjs';
|
|
18
|
+
import type { IImageIoService, IImageIoServiceParam } from './image-io.service';
|
|
19
|
+
import { ImageSourceType } from './image-io.service';
|
|
4
20
|
export declare class ImageIoService implements IImageIoService {
|
|
5
21
|
private _waitCount;
|
|
6
22
|
private _change$;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
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 { IDisposable, IURLImageService } from '@univerjs/core';
|
|
17
|
+
import { Disposable } from '@univerjs/core';
|
|
2
18
|
export declare class URLImageService extends Disposable implements IURLImageService {
|
|
3
19
|
private _urlImageDownloader;
|
|
4
20
|
registerURLImageDownloader(downloader: (url: string) => Promise<string>): IDisposable;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
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 { IDrawingSearch } from '@univerjs/core';
|
|
2
17
|
export declare function getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }: IDrawingSearch, index?: number): string;
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
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 { ISize } from '@univerjs/core';
|
|
2
17
|
interface IImageParam extends ISize {
|
|
3
18
|
image: HTMLImageElement;
|
|
4
19
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(te,z){typeof exports=="object"&&typeof module<"u"?z(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],z):(te=typeof globalThis<"u"?globalThis:te||self,z(te.UniverDrawing={},te.UniverCore,te.rxjs))})(this,(function(te,z,ge){"use strict";var Qt=Object.defineProperty;var en=(te,z,ge)=>z in te?Qt(te,z,{enumerable:!0,configurable:!0,writable:!0,value:ge}):te[z]=ge;var q=(te,z,ge)=>en(te,typeof z!="symbol"?z+"":z,ge);var et;const yt=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"],ot=z.createIdentifier("univer.drawing-manager.service"),_t={id:"drawing.operation.set-drawing-selected",type:z.CommandType.OPERATION,handler:(l,e)=>{const n=l.get(ot);return e==null?!1:(n.focusDrawing(e),!0)}},mt={name:"@univerjs/drawing",version:"0.17.0"},Lt="drawing.config",vt={};var Ke={},Qe={},nt={},Ot;function Bt(){if(Ot)return nt;Ot=1,Object.defineProperty(nt,"__esModule",{value:!0});function l(t,r){if(Array.isArray(r))return!1;for(let u in t)if(!n(t[u],r[u]))return!1;for(let u in r)if(t[u]===void 0)return!1;return!0}function e(t,r){if(!Array.isArray(r)||t.length!==r.length)return!1;for(let u=0;u<t.length;u++)if(!n(t[u],r[u]))return!1;return!0}function n(t,r){return t===r?!0:t===null||r===null||typeof t!="object"||typeof r!="object"?!1:Array.isArray(t)?e(t,r):l(t,r)}return nt.default=n,nt}var rt={},wt;function qt(){if(wt)return rt;wt=1,Object.defineProperty(rt,"__esModule",{value:!0});function l(e){if(e===null)return null;if(Array.isArray(e))return e.map(l);if(typeof e=="object"){const n={};for(let t in e)n[t]=l(e[t]);return n}else return e}return rt.default=l,rt}var at={},bt;function It(){return bt||(bt=1,(function(l){Object.defineProperty(l,"__esModule",{value:!0}),l.eachChildOf=l.advancer=l.readCursor=l.writeCursor=l.WriteCursor=l.ReadCursor=l.isValidPathItem=void 0;function e(_,s){if(!_)throw new Error(s)}const n=_=>_!=null&&typeof _=="object"&&!Array.isArray(_),t=(_,s)=>typeof _==typeof s?_>s:typeof _=="string"&&typeof s=="number";function r(_,s){for(let c in _){const h=c;s.write(h,_[h])}}l.isValidPathItem=_=>typeof _=="number"||typeof _=="string"&&_!=="__proto__";class u{constructor(s=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=s}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,n(this.container[this.idx])&&this.idx--)}getPath(){const s=[];let c=this.container,h=this.parents.length-1,k=this.idx;for(;k>=0;)s.unshift(c[k]),k===0?(k=this.indexes[h*2],c=this.parents[h--]):k-=n(c[k-1])?2:1;return s}}class o extends u{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let s;return this.container&&this.container.length>this.idx+1&&n(s=this.container[this.idx+1])?s:null}descendFirst(){let s=this.idx+1;if(!this.container||s>=this.container.length||n(this.container[s])&&s+1>=this.container.length)return!1;n(this.container[s])&&s++;const c=this.container[s];return Array.isArray(c)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(s),this.idx=0,this.container=c):this.idx=s,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const s=this.indexes[this.indexes.length-1]+1,c=this.parents[this.parents.length-1];return s>=c.length?!1:(e(!isNaN(s)),this.indexes[this.indexes.length-1]=s,this.container=c[s],!0)}_init(s,c,h,k){this.container=s,this.idx=c,this.parents=h.slice(),this.indexes=k.slice()}clone(){const s=new o;return s._init(this.container,this.idx,this.parents,this.indexes),s}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(s,c){const h=this.getComponent();h&&c(h,s);for(const k of this)s&&s.descend(k),this.traverse(s,c),s&&s.ascend()}eachPick(s,c){this.traverse(s,(h,k)=>{h.p!=null&&c(h.p,k)})}eachDrop(s,c){this.traverse(s,(h,k)=>{h.d!=null&&c(h.d,k)})}}l.ReadCursor=o;class a extends u{constructor(s=null){super(s),this.pendingDescent=[],this._op=s}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let s=0;s<this.pendingDescent.length;s++){const c=this.pendingDescent[s];let h=this.idx+1;if(h<this.container.length&&n(this.container[h])&&h++,e(h===this.container.length||!n(this.container[h])),h===this.container.length)this.container.push(c),this.idx=h;else if(this.container[h]===c)this.idx=h;else{if(!Array.isArray(this.container[h])){const k=this.container.splice(h,this.container.length-h);this.container.push(k),this.lcIdx>-1&&(this.lcIdx=h)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(t(c,this.container[this.lcIdx][0])),h=this.lcIdx+1,this.lcIdx=-1);h<this.container.length&&t(c,this.container[h][0]);)h++;if(this.indexes.push(h),this.idx=0,h<this.container.length&&this.container[h][0]===c)this.container=this.container[h];else{const k=[c];this.container.splice(h,0,k),this.container=k}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const s=this.idx+1;if(s<this.container.length&&n(this.container[s]))return this.container[s];{const c={};return this.container.splice(s,0,c),c}}write(s,c){const h=this.getComponent();e(h[s]==null||h[s]===c,"Internal consistency error: Overwritten component. File a bug"),h[s]=c}get(){return this._op}descend(s){if(!l.isValidPathItem(s))throw Error("Invalid JSON key");this.pendingDescent.push(s)}descendPath(s){return this.pendingDescent.push(...s),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(s,c=r){if(s===null)return;if(e(Array.isArray(s)),s===this._op)throw Error("Cannot merge into my own tree");const h=this.lcIdx,k=this.parents.length;let Z=0;for(let _e=0;_e<s.length;_e++){const Q=s[_e];typeof Q=="string"||typeof Q=="number"?(Z++,this.descend(Q)):Array.isArray(Q)?this.mergeTree(Q,c):typeof Q=="object"&&c(Q,this)}for(;Z--;)this.ascend();this.lcIdx=this.parents.length===k?h:-1}at(s,c){this.descendPath(s),c(this);for(let h=0;h<s.length;h++)this.ascend();return this}writeAtPath(s,c,h){return this.at(s,()=>this.write(c,h)),this.reset(),this}writeMove(s,c,h=0){return this.writeAtPath(s,"p",h).writeAtPath(c,"d",h)}getPath(){const s=super.getPath();return s.push(...this.pendingDescent),s}}l.WriteCursor=a,l.writeCursor=()=>new a,l.readCursor=_=>new o(_);function D(_,s,c){let h,k;k=h=_?_.descendFirst():!1;function Z(_e){let Q;for(;k;){const De=Q=_.getKey();if(_e!=null){let Fe=!1;if(s&&typeof De=="number"&&(Q=s(De,_.getComponent()),Q<0&&(Q=~Q,Fe=!0)),t(Q,_e))return null;if(Q===_e&&!Fe)return _}c&&typeof Q=="number"&&c(Q,_.getComponent()),k=_.nextSibling()}return null}return Z.end=()=>{h&&_.ascend()},Z}l.advancer=D;function G(_,s,c){let h,k,Z,_e;for(h=k=_&&_.descendFirst(),Z=_e=s&&s.descendFirst();h||Z;){let Q=h?_.getKey():null,De=Z?s.getKey():null;Q!==null&&De!==null&&(t(De,Q)?De=null:Q!==De&&(Q=null)),c(Q==null?De:Q,Q!=null?_:null,De!=null?s:null),Q!=null&&h&&(h=_.nextSibling()),De!=null&&Z&&(Z=s.nextSibling())}k&&_.ascend(),_e&&s.ascend()}l.eachChildOf=G})(at)),at}var lt={},Ct;function Dt(){return Ct||(Ct=1,(function(l){Object.defineProperty(l,"__esModule",{value:!0}),l.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"})(l.ConflictType||(l.ConflictType={}))})(lt)),lt}var Me={},$e={},Et;function ut(){return Et||(Et=1,Object.defineProperty($e,"__esModule",{value:!0}),$e.uniToStrPos=$e.strPosToUni=void 0,$e.strPosToUni=(l,e=l.length)=>{let n=0,t=0;for(;t<e;t++){const r=l.charCodeAt(t);r>=55296&&r<=57343&&(n++,t++)}if(t!==e)throw Error("Invalid offset - splits unicode bytes");return t-n},$e.uniToStrPos=(l,e)=>{let n=0;for(;e>0;e--){const t=l.charCodeAt(n);n+=t>=55296&&t<=57343?2:1}return n}),$e}var ct={},St;function dt(){return St||(St=1,(function(l){Object.defineProperty(l,"__esModule",{value:!0}),l.uniSlice=l.dlen=l.eachOp=void 0;const e=ut(),n=f=>{if(!Array.isArray(f))throw Error("Op must be an array of components");let y=null;for(let b=0;b<f.length;b++){const H=f[b];switch(typeof H){case"object":if(typeof H.d!="number"&&typeof H.d!="string")throw Error("Delete must be number or string");if(l.dlen(H.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(H.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(H>0))throw Error("Skip components must be >0");if(typeof y=="number")throw Error("Adjacent skip components should be combined");break}y=H}if(typeof y=="number")throw Error("Op has a trailing skip")};function t(f,y){let b=0,H=0;for(let X=0;X<f.length;X++){const K=f[X];switch(y(K,b,H),typeof K){case"object":b+=l.dlen(K.d);break;case"string":H+=e.strPosToUni(K);break;case"number":b+=K,H+=K;break}}}l.eachOp=t;function r(f,y){const b=[],H=a(b);return t(f,(X,K,Se)=>{H(y(X,K,Se))}),s(b)}const u=f=>f,o=f=>r(f,u);l.dlen=f=>typeof f=="number"?f:e.strPosToUni(f);const a=f=>y=>{if(!(!y||y.d===0||y.d===""))if(f.length===0)f.push(y);else if(typeof y==typeof f[f.length-1])if(typeof y=="object"){const b=f[f.length-1];b.d=typeof b.d=="string"&&typeof y.d=="string"?b.d+y.d:l.dlen(b.d)+l.dlen(y.d)}else f[f.length-1]+=y;else f.push(y)},D=f=>typeof f=="number"?f:typeof f=="string"?e.strPosToUni(f):typeof f.d=="number"?f.d:e.strPosToUni(f.d);l.uniSlice=(f,y,b)=>{const H=e.uniToStrPos(f,y),X=b==null?1/0:e.uniToStrPos(f,b);return f.slice(H,X)};const G=(f,y,b)=>typeof f=="number"?b==null?f-y:Math.min(f,b)-y:l.uniSlice(f,y,b),_=f=>{let y=0,b=0;return{take:(K,Se)=>{if(y===f.length)return K===-1?null:K;const fe=f[y];let ie;if(typeof fe=="number")return K===-1||fe-b<=K?(ie=fe-b,++y,b=0,ie):(b+=K,K);if(typeof fe=="string"){if(K===-1||Se==="i"||e.strPosToUni(fe.slice(b))<=K)return ie=fe.slice(b),++y,b=0,ie;{const ce=b+e.uniToStrPos(fe.slice(b),K);return ie=fe.slice(b,ce),b=ce,ie}}else{if(K===-1||Se==="d"||l.dlen(fe.d)-b<=K)return ie={d:G(fe.d,b)},++y,b=0,ie;{let ce=G(fe.d,b,b+K);return b+=K,{d:ce}}}},peek:()=>f[y]}},s=f=>(f.length>0&&typeof f[f.length-1]=="number"&&f.pop(),f);function c(f,y,b){if(b!=="left"&&b!=="right")throw Error("side ("+b+") must be 'left' or 'right'");n(f),n(y);const H=[],X=a(H),{take:K,peek:Se}=_(f);for(let ie=0;ie<y.length;ie++){const ce=y[ie];let me,Te;switch(typeof ce){case"number":for(me=ce;me>0;)Te=K(me,"i"),X(Te),typeof Te!="string"&&(me-=D(Te));break;case"string":b==="left"&&typeof Se()=="string"&&X(K(-1)),X(e.strPosToUni(ce));break;case"object":for(me=l.dlen(ce.d);me>0;)switch(Te=K(me,"i"),typeof Te){case"number":me-=Te;break;case"string":X(Te);break;case"object":me-=l.dlen(Te.d)}break}}let fe;for(;fe=K(-1);)X(fe);return s(H)}function h(f,y){n(f),n(y);const b=[],H=a(b),{take:X}=_(f);for(let Se=0;Se<y.length;Se++){const fe=y[Se];let ie,ce;switch(typeof fe){case"number":for(ie=fe;ie>0;)ce=X(ie,"d"),H(ce),typeof ce!="object"&&(ie-=D(ce));break;case"string":H(fe);break;case"object":ie=l.dlen(fe.d);let me=0;for(;me<ie;)switch(ce=X(ie-me,"d"),typeof ce){case"number":H({d:G(fe.d,me,me+ce)}),me+=ce;break;case"string":me+=e.strPosToUni(ce);break;case"object":H(ce)}break}}let K;for(;K=X(-1);)H(K);return s(b)}const k=(f,y)=>{let b=0;for(let H=0;H<y.length&&f>b;H++){const X=y[H];switch(typeof X){case"number":{b+=X;break}case"string":const K=e.strPosToUni(X);b+=K,f+=K;break;case"object":f-=Math.min(l.dlen(X.d),f-b);break}}return f},Z=(f,y)=>typeof f=="number"?k(f,y):f.map(b=>k(b,y));function _e(f,y,b){return r(f,(H,X)=>typeof H=="object"&&typeof H.d=="number"?{d:b.slice(y,X,X+H.d)}:H)}function Q(f){return r(f,y=>{switch(typeof y){case"object":if(typeof y.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return y.d;case"string":return{d:y};case"number":return y}})}function De(f){return r(f,y=>typeof y=="object"&&typeof y.d=="string"?{d:e.strPosToUni(y.d)}:y)}function Fe(f){let y=!0;return t(f,b=>{typeof b=="object"&&typeof b.d=="number"&&(y=!1)}),y}function we(f){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:s,normalize:o,checkOp:n,create(y=""){if(typeof y!="string")throw Error("Initial data must be a string");return f.create(y)},apply(y,b){n(b);const H=f.builder(y);for(let X=0;X<b.length;X++){const K=b[X];switch(typeof K){case"number":H.skip(K);break;case"string":H.append(K);break;case"object":H.del(l.dlen(K.d));break}}return H.build()},transform:c,compose:h,transformPosition:k,transformSelection:Z,isInvertible:Fe,makeInvertible(y,b){return _e(y,b,f)},stripInvertible:De,invert:Q,invertWithDoc(y,b){return Q(_e(y,b,f))},isNoop:y=>y.length===0}}l.default=we})(ct)),ct}var it={},Tt;function xt(){if(Tt)return it;Tt=1,Object.defineProperty(it,"__esModule",{value:!0});const l=dt(),e=ut();function n(t,r){return{get:t,getLength(){return t().length},insert(u,o,a){const D=e.strPosToUni(t(),u);return r([D,o],a)},remove(u,o,a){const D=e.strPosToUni(t(),u);return r([D,{d:o}],a)},_onOp(u){l.eachOp(u,(o,a,D)=>{switch(typeof o){case"string":this.onInsert&&this.onInsert(D,o);break;case"object":const G=l.dlen(o.d);this.onRemove&&this.onRemove(D,G)}})},onInsert:null,onRemove:null}}return it.default=n,n.provides={text:!0},it}var Pt;function Ht(){return Pt||(Pt=1,(function(l){var e=Me&&Me.__createBinding||(Object.create?(function(c,h,k,Z){Z===void 0&&(Z=k),Object.defineProperty(c,Z,{enumerable:!0,get:function(){return h[k]}})}):(function(c,h,k,Z){Z===void 0&&(Z=k),c[Z]=h[k]})),n=Me&&Me.__setModuleDefault||(Object.create?(function(c,h){Object.defineProperty(c,"default",{enumerable:!0,value:h})}):function(c,h){c.default=h}),t=Me&&Me.__importStar||function(c){if(c&&c.__esModule)return c;var h={};if(c!=null)for(var k in c)Object.hasOwnProperty.call(c,k)&&e(h,c,k);return n(h,c),h},r=Me&&Me.__importDefault||function(c){return c&&c.__esModule?c:{default:c}};Object.defineProperty(l,"__esModule",{value:!0}),l.type=l.remove=l.insert=void 0;const u=ut(),o=t(dt()),a=r(xt()),D={create(c){return c},toString(c){return c},builder(c){if(typeof c!="string")throw Error("Invalid document snapshot: "+c);const h=[];return{skip(k){let Z=u.uniToStrPos(c,k);if(Z>c.length)throw Error("The op is too long for this document");h.push(c.slice(0,Z)),c=c.slice(Z)},append(k){h.push(k)},del(k){c=c.slice(u.uniToStrPos(c,k))},build(){return h.join("")+c}}},slice:o.uniSlice},G=o.default(D),_=Object.assign(Object.assign({},G),{api:a.default});l.type=_,l.insert=(c,h)=>h.length===0?[]:c===0?[h]:[c,h],l.remove=(c,h)=>o.dlen(h)===0?[]:c===0?[{d:h}]:[c,{d:h}];var s=dt();Object.defineProperty(l,"makeType",{enumerable:!0,get:function(){return s.default}})})(Me)),Me}var At;function Kt(){return At||(At=1,(function(l){var e=Qe&&Qe.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(l,"__esModule",{value:!0}),l.editOp=l.replaceOp=l.insertOp=l.moveOp=l.removeOp=l.type=void 0;const n=e(Bt()),t=e(qt()),r=It(),u=Dt();function o(i,d){if(!i)throw new Error(d)}l.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:r.readCursor,writeCursor:r.writeCursor,create:i=>i,isNoop:i=>i==null,setDebug(i){},registerSubtype:Q,checkValidOp:X,normalize:K,apply:Se,transformPosition:fe,compose:ie,tryTransform:gt,transform:Yt,makeInvertible:Te,invert:ce,invertWithDoc:Jt,RM_UNEXPECTED_CONTENT:u.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:u.ConflictType.DROP_COLLISION,BLACKHOLE:u.ConflictType.BLACKHOLE,transformNoConflict:(i,d,v)=>Wt(()=>!0,i,d,v),typeAllowingConflictsPred:i=>Object.assign(Object.assign({},l.type),{transform:(d,v,E)=>Wt(i,d,v,E)})};const a=i=>i?i.getComponent():null;function D(i){return i&&typeof i=="object"&&!Array.isArray(i)}const G=i=>Array.isArray(i)?i.slice():i!==null&&typeof i=="object"?Object.assign({},i):i,_=i=>i&&(i.p!=null||i.r!==void 0),s=i=>i&&(i.d!=null||i.i!==void 0);function c(i,d){return o(i!=null),typeof d=="number"?(o(Array.isArray(i),"Invalid key - child is not an array"),(i=i.slice()).splice(d,1)):(o(D(i),"Invalid key - child is not an object"),delete(i=Object.assign({},i))[d]),i}function h(i,d,v){return typeof d=="number"?(o(i!=null,"Container is missing for key"),o(Array.isArray(i),"Cannot use numerical key for object container"),o(i.length>=d,"Cannot insert into out of bounds index"),i.splice(d,0,v)):(o(D(i),"Cannot insert into missing item"),o(i[d]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),i[d]=v),v}l.removeOp=(i,d=!0)=>r.writeCursor().writeAtPath(i,"r",d).get(),l.moveOp=(i,d)=>r.writeCursor().writeMove(i,d).get(),l.insertOp=(i,d)=>r.writeCursor().writeAtPath(i,"i",d).get(),l.replaceOp=(i,d,v)=>r.writeCursor().at(i,E=>{E.write("r",d),E.write("i",v)}).get(),l.editOp=(i,d,v,E=!1)=>r.writeCursor().at(i,O=>y(O,d,v,E)).get();const k=(i,d)=>i!=null&&(typeof d=="number"?Array.isArray(i):typeof i=="object"),Z=(i,d)=>k(i,d)?i[d]:void 0,_e={};function Q(i){let d=i.type?i.type:i;d.name&&(_e[d.name]=d),d.uri&&(_e[d.uri]=d)}const De=i=>{const d=_e[i];if(d)return d;throw Error("Missing type: "+i)};Q(Ht());const Fe=(i,d)=>i+d;Q({name:"number",apply:Fe,compose:Fe,invert:i=>-i,transform:i=>i});const we=i=>i==null?null:i.et?De(i.et):i.es?_e["text-unicode"]:i.ena!=null?_e.number:null,f=i=>i.es?i.es:i.ena!=null?i.ena:i.e,y=(i,d,v,E=!1)=>{const[O,C]=typeof d=="string"?[De(d),d]:[d,d.name];!E&&O.isNoop&&O.isNoop(v)||(C==="number"?i.write("ena",v):C==="text-unicode"?i.write("es",v):(i.write("et",C),i.write("e",v)))};function b(i){o(typeof i=="number"),o(i>=0),o(i===(0|i))}function H(i){typeof i=="number"?b(i):o(typeof i=="string")}function X(i){if(i===null)return;const d=new Set,v=new Set,E=C=>{let W=!0,N=!1;for(let g in C){const m=C[g];if(W=!1,o(g==="p"||g==="r"||g==="d"||g==="i"||g==="e"||g==="es"||g==="ena"||g==="et","Invalid component item '"+g+"'"),g==="p")b(m),o(!d.has(m)),d.add(m),o(C.r===void 0);else if(g==="d")b(m),o(!v.has(m)),v.add(m),o(C.i===void 0);else if(g==="e"||g==="es"||g==="ena"){o(!N),N=!0;const w=we(C);o(w,"Missing type in edit"),w.checkValidOp&&w.checkValidOp(f(C))}}o(!W)},O=(C,W,N)=>{if(!Array.isArray(C))throw Error("Op must be null or a list");if(C.length===0)throw Error("Empty descent");W||H(C[0]);let g=1,m=0,w=0;for(let I=0;I<C.length;I++){const R=C[I];if(o(R!=null),Array.isArray(R)){const L=O(R,!1);if(m){const p=typeof w,M=typeof L;p===M?o(w<L,"descent keys are not in order"):o(p==="number"&&M==="string")}w=L,m++,g=3}else typeof R=="object"?(o(g===1,`Prev not scalar - instead ${g}`),E(R),g=2):(o(g!==3),H(R),o(r.isValidPathItem(R),"Invalid path key"),g=1)}return o(m!==1,"Operation makes multiple descents. Remove some []"),o(g===2||g===3),C[0]};O(i,!0),o(d.size===v.size,"Mismatched picks and drops in op");for(let C=0;C<d.size;C++)o(d.has(C)),o(v.has(C))}function K(i){let d=0,v=[];const E=r.writeCursor();return E.mergeTree(i,(O,C)=>{const W=we(O);if(W){const g=f(O);y(C,W,W.normalize?W.normalize(g):g)}for(const g of["r","p","i","d"])if(O[g]!==void 0){const m=g==="p"||g==="d"?(N=O[g],v[N]==null&&(v[N]=d++),v[N]):O[g];C.write(g,m)}var N}),E.get()}function Se(i,d){if(X(d),d===null)return i;const v=[];return(function E(O,C){let W=O,N=0,g={root:O},m=0,w=g,I="root";function R(){for(;m<N;m++){let L=C[m];typeof L!="object"&&(o(k(w,I)),w=w[I]=G(w[I]),I=L)}}for(;N<C.length;N++){const L=C[N];if(Array.isArray(L)){const p=E(W,L);p!==W&&p!==void 0&&(R(),W=w[I]=p)}else if(typeof L=="object"){L.d!=null?(R(),W=h(w,I,v[L.d])):L.i!==void 0&&(R(),W=h(w,I,L.i));const p=we(L);if(p)R(),W=w[I]=p.apply(W,f(L));else if(L.e!==void 0)throw Error("Subtype "+L.et+" undefined")}else W=Z(W,L)}return g.root})(i=(function E(O,C){const W=[];let N=0;for(;N<C.length;N++){const I=C[N];if(Array.isArray(I))break;typeof I!="object"&&(W.push(O),O=Z(O,I))}for(let I=C.length-1;I>=N;I--)O=E(O,C[I]);for(--N;N>=0;N--){const I=C[N];if(typeof I!="object"){const R=W.pop();O=O===Z(R,I)?R:O===void 0?c(R,I):(m=I,w=O,(g=G(g=R))[m]=w,g)}else _(I)&&(o(O!==void 0,"Cannot pick up or remove undefined"),I.p!=null&&(v[I.p]=O),O=void 0)}var g,m,w;return O})(i,d),d)}function fe(i,d){i=i.slice(),X(d);const v=r.readCursor(d);let E,O,C=!1;const W=[];for(let g=0;;g++){const m=i[g],w=v.getComponent();if(w&&(w.r!==void 0?C=!0:w.p!=null&&(C=!1,E=w.p,O=g)),g>=i.length)break;let I=0;const R=r.advancer(v,void 0,(p,M)=>{_(M)&&I++});W.unshift(R);const L=R(m);if(typeof m=="number"&&(i[g]-=I),!L)break}if(W.forEach(g=>g.end()),C)return null;const N=()=>{let g=0;if(E!=null){const m=v.getPath();g=m.length,i=m.concat(i.slice(O))}for(;g<i.length;g++){const m=i[g],w=a(v),I=we(w);if(I){const p=f(w);I.transformPosition&&(i[g]=I.transformPosition(i[g],p));break}let R=0;const L=r.advancer(v,(p,M)=>s(M)?~(p-R):p-R,(p,M)=>{s(M)&&R++})(m);if(typeof m=="number"&&(i[g]+=R),!L)break}};return E!=null?v.eachDrop(null,g=>{g===E&&N()}):N(),i}function ie(i,d){if(X(i),X(d),i==null)return d;if(d==null)return i;let v=0;const E=r.readCursor(i),O=r.readCursor(d),C=r.writeCursor(),W=[],N=[],g=[],m=[],w=[],I=[],R=new Set;E.traverse(null,p=>{p.p!=null&&(g[p.p]=E.clone())}),O.traverse(null,p=>{p.d!=null&&(m[p.d]=O.clone())});const L=r.writeCursor();return(function p(M,se,re,$,ae,Ge,Ie,ve){o(se||re);const le=a(se),Pe=a(re),Ue=!!Pe&&Pe.r!==void 0,Ve=!!le&&le.i!==void 0,Ae=le?le.d:null,Ee=Pe?Pe.p:null,Le=(Ge||Ue)&&Ee==null;if(Ee!=null)$=m[Ee],Ie=N[Ee]=new r.WriteCursor;else if(Pe&&Pe.r!==void 0)$=null;else{const T=a($);T&&T.d!=null&&($=null)}const ee=a($);if(Ae!=null)if(M=g[Ae],ve=W[Ae]=new r.WriteCursor,Le)Ge&&!Ue&&ve.write("r",!0);else{const T=w[Ae]=v++;Ie.write("d",T)}else if(le&&le.i!==void 0)M=null;else{const T=a(M);T&&T.p!=null&&(M=null)}let P;Ve?(o(ae===void 0),P=le.i):P=ae;const B=(Ee==null?!Ve||Ge||Ue:P===void 0)?null:Ie.getComponent();if(Ee!=null){if(!(ae!==void 0||Ve)){const T=Ae!=null?w[Ae]:v++;I[Ee]=T,ve.write("p",T)}}else Ue&&(Ve||ae!==void 0||(Pe.r,ve.write("r",Pe.r)));const A=Le?null:we(le),S=we(ee);if((A||S)&&(A&&A.name,S&&S.name),A&&S){o(A===S);const T=f(le),x=f(ee),ye=A.compose(T,x);y(Ie,A,ye),R.add(ee)}else A?y(Ie,A,f(le)):S&&(y(Ie,S,f(ee)),R.add(ee));const U=typeof P=="object"&&P!=null;let Y=!1,J=0,ne=0,pe=0,he=0,ue=0;const be=r.advancer($,(T,x)=>s(x)?he-T-1:T-he,(T,x)=>{s(x)&&he++}),V=r.advancer(M,(T,x)=>_(x)?J-T-1:T-J,(T,x)=>{_(x)&&J++});if(r.eachChildOf(se,re,(T,x,ye)=>{let Ce,Be,ze=T,ke=T,tt=T;if(typeof T=="number"){let Oe=T+pe;Be=be(Oe),ke=Oe+he;let de=T+ne;Ce=V(de),s(a(Be))&&(Ce=null),ze=de+J,tt=T+ue,o(ze>=0,"p1PickKey is negative"),o(ke>=0,"p2DropKey is negative");const je=s(a(x)),qe=_(a(ye));(je||qe&&!Le)&&ue--,je&&ne--,qe&&pe--}else Ce=V(T),Be=be(T);ve.descend(ze),Ie.descend(ke);const Ye=U&&!s(a(x))?P[tt]:void 0,Re=p(Ce,x,ye,Be,Ye,Le,Ie,ve);var We,j,oe;U&&!Le?Ye!==Re&&(Y||(P=Array.isArray(P)?P.slice():Object.assign({},P),Y=!0),We=P,oe=Re,typeof(j=tt)=="number"?(o(Array.isArray(We)),o(j<We.length)):(o(!Array.isArray(We)),o(We[j]!==void 0)),oe===void 0?typeof j=="number"?We.splice(j,1):delete We[j]:We[j]=oe):o(Re===void 0),Ie.ascend(),ve.ascend()}),V.end(),be.end(),B!=null)B.i=P;else if(!Ge&&!Ue&&Ee==null)return P})(E,E.clone(),O,O.clone(),void 0,!1,C,L),C.reset(),C.mergeTree(L.get()),C.reset(),C.get(),W.map(p=>p.get()),N.map(p=>p.get()),E.traverse(C,(p,M)=>{const se=p.p;if(se!=null){const re=w[se];re!=null&&M.write("p",re);const $=W[se];$&&$.get(),$&&M.mergeTree($.get())}else p.r!==void 0&&M.write("r",p.r)}),C.reset(),C.get(),O.traverse(C,(p,M)=>{const se=p.d;if(se!=null){const $=I[se];$!=null&&M.write("d",$);const ae=N[se];ae&&M.mergeTree(ae.get())}else p.i!==void 0&&M.write("i",p.i);const re=we(p);re&&!R.has(p)&&y(M,re,f(p))}),C.get()}function ce(i){if(i==null)return null;const d=new r.ReadCursor(i),v=new r.WriteCursor;let E;const O=[],C=[];return(function W(N,g,m){const w=N.getComponent();let I,R=!1;if(w){w.p!=null&&(g.write("d",w.p),O[w.p]=N.clone()),w.r!==void 0&&g.write("i",w.r),w.d!=null&&(g.write("p",w.d),m=void 0),w.i!==void 0&&(m=I=w.i);const p=we(w);p&&(m===void 0?(E||(E=new Set),E.add(w)):(f(w),m=p.apply(m,f(w)),R=!0))}let L=0;for(const p of N){g.descend(p);const M=typeof p=="number"?p-L:p,se=Z(m,M);s(N.getComponent())&&L++;const re=W(N,g,se);if(m!==void 0&&re!==void 0){if(R||(R=!0,m=G(m)),!k(m,M))throw Error("Cannot modify child - invalid operation");m[M]=re}g.ascend()}if(I===void 0)return R?m:void 0;g.write("r",m)})(d,v,void 0),E&&(v.reset(),(function W(N,g,m){const w=g.getComponent();if(w){const p=w.d;if(p!=null&&(N=O[p],m=C[p]=r.writeCursor()),E.has(w)){const M=we(w);if(!M.invert)throw Error(`Cannot invert subtype ${M.name}`);y(m,M,M.invert(f(w)))}}let I=0,R=0;const L=r.advancer(N,(p,M)=>_(M)?I-p-1:p-I,(p,M)=>{_(M)&&I++});for(const p of g)if(typeof p=="number"){const M=p-R,se=L(M),re=M+I;m.descend(re),W(se,g,m),s(g.getComponent())&&R++,m.ascend()}else m.descend(p),W(L(p),g,m),m.ascend();L.end()})(d.clone(),d,v),C.length&&(v.reset(),d.traverse(v,(W,N)=>{const g=W.p;if(g!=null){const m=C[g];m&&m.get(),m&&N.mergeTree(m.get())}}))),v.get()}const me=(i,d)=>i.some(v=>typeof v=="object"&&(Array.isArray(v)?me(v,d):d(v)));function Te(i,d){if(i==null||!me(i,g=>{var m;return g.r!==void 0||((m=we(g))===null||m===void 0?void 0:m.makeInvertible)!=null}))return i;const v=new r.ReadCursor(i),E=new r.WriteCursor;let O=!1;const C=[],W=[],N=(g,m,w)=>{const I=g.getComponent();let R=!1;if(I){I.d!=null&&m.write("d",I.d),I.i!==void 0&&m.write("i",I.i);const p=I.p;if(p!=null&&(C[p]=g.clone(),o(w!==void 0,"Operation picks up at an invalid key"),W[p]=w,m.write("p",I.p)),I.r!==void 0&&w===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const M=we(I);M&&(M.makeInvertible?O=!0:y(m,M,f(I),!0))}let L=0;for(const p of g){m.descend(p);const M=typeof p=="number"?p-L:p,se=Z(w,M),re=N(g,m,se);se!==re&&(R||(R=!0,w=G(w)),re===void 0?(w=c(w,M),typeof p=="number"&&L++):w[M]=re),m.ascend()}return I&&(I.r!==void 0?(m.write("r",t.default(w)),w=void 0):I.p!=null&&(w=void 0)),w};return N(v,E,d),E.get(),O&&(E.reset(),(function g(m,w,I,R,L){const p=w.getComponent();if(p){p.i!==void 0?(R=p.i,L=!0):p.d!=null&&(R=W[p.d],m=C[p.d],L=!1,p.d);let $=we(p);if($&&$.makeInvertible){const ae=f(p);y(I,$,$.makeInvertible(ae,R),!0)}}let M=0,se=0;const re=r.advancer(m,($,ae)=>_(ae)?M-$-1:$-M,($,ae)=>{_(ae)&&M++});for(const $ of w)if(typeof $=="number"){const ae=$-se,Ge=re(ae),Ie=ae+M,ve=Z(R,L?ae:Ie);I.descend($),g(Ge,w,I,ve,L),s(w.getComponent())&&se++,I.ascend()}else{const ae=Z(R,$);I.descend($),g(re($),w,I,ae,L),I.ascend()}re.end()})(v.clone(),v,E,d,!1)),E.get()}function Jt(i,d){return ce(Te(i,d))}const ht=i=>{if(i==null)return null;const d=i.slice();for(let v=0;v<i.length;v++){const E=d[v];Array.isArray(E)&&(d[v]=ht(E))}return d};function gt(i,d,v){o(v==="left"||v==="right","Direction must be left or right");const E=v==="left"?0:1;if(d==null)return{ok:!0,result:i};X(i),X(d);let O=null;const C=[],W=[],N=[],g=[],m=[],w=[],I=[],R=[],L=[],p=[],M=[],se=[],re=[],$=[],ae=[];let Ge=0;const Ie=r.readCursor(i),ve=r.readCursor(d),le=r.writeCursor();if((function ee(P,B=null,A){const S=a(B);S&&(S.r!==void 0?A=B.clone():S.p!=null&&(A=null,w[S.p]=P.clone()));const U=P.getComponent();let Y;U&&(Y=U.p)!=null&&(m[Y]=B?B.clone():null,N[Y]=P.clone(),A&&(p[Y]=!0,L[Y]=A),S&&S.p!=null&&($[Y]=S.p));const J=r.advancer(B);for(const ne of P)ee(P,J(ne),A);J.end()})(ve,Ie,null),(function ee(P,B,A,S,U){const Y=A.getComponent();let J,ne=!1;Y&&((J=Y.d)!=null?(g[J]=A.clone(),S!=null&&(ae[S]==null&&(ae[S]=[]),ae[S].push(J)),p[J],P=m[J]||null,B=N[J]||null,p[J]?(U&&(M[J]=!0),U=L[J]||null):!U||E!==1&&$[J]!=null||O==null&&(O={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:l.removeOp(U.getPath()),op2:l.moveOp(B.getPath(),A.getPath())}),ne=!0):Y.i!==void 0&&(P=B=null,ne=!0,U&&O==null&&(O={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:l.removeOp(U.getPath()),op2:l.insertOp(A.getPath(),Y.i)})));const pe=a(P);pe&&(pe.r!==void 0?U=P.clone():pe.p!=null&&(pe.p,S=pe.p,U=null));const he=we(Y);he&&U&&O==null&&(O={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:l.removeOp(U.getPath()),op2:l.editOp(A.getPath(),he,f(Y),!0)});let ue=0,be=0;const V=r.advancer(B,(x,ye)=>_(ye)?ue-x-1:x-ue,(x,ye)=>{_(ye)&&ue++}),T=r.advancer(P);for(const x of A)if(typeof x=="number"){const ye=x-be,Ce=V(ye);be+=+ee(T(ye+ue),Ce,A,S,U)}else{const ye=V(x);ee(T(x),ye,A,S,U)}return V.end(),T.end(),ne})(Ie,ve,ve.clone(),null,null),g.map(ee=>ee&&ee.get()),O)return{ok:!1,conflict:O};M.map(ee=>!!ee);const Pe=[];let Ue=null;(function ee(P,B,A,S,U){let Y=!1;const J=a(B);if(_(J)){const V=J.p;V!=null?(A=g[V],S=se[V]=r.writeCursor(),Y=!0,U=null):(A=null,U=B.clone())}else s(a(A))&&(A=null);const ne=P.getComponent();if(ne){const V=ne.p;V!=null?(U&&(R[V]=U),Pe[V]=U||E===1&&Y?null:S.getComponent(),C[V]=P.clone(),A&&(I[V]=A.clone())):ne.r!==void 0&&(U||S.write("r",!0),(U||Y)&&(Ue==null&&(Ue=new Set),Ue.add(ne)))}let pe=0,he=0;const ue=r.advancer(B,void 0,(V,T)=>{_(T)&&pe++}),be=r.advancer(A,(V,T)=>s(T)?~(V-he):V-he,(V,T)=>{s(T)&&he++});if(P)for(const V of P)if(typeof V=="string"){const T=ue(V),x=be(V);S.descend(V),ee(P,T,x,S,U),S.ascend()}else{const T=ue(V),x=V-pe,ye=_(a(T))?null:be(x),Ce=x+he;o(Ce>=0),S.descend(Ce),ee(P,T,ye,S,U),S.ascend()}ue.end(),be.end()})(Ie,ve,ve.clone(),le,null),le.reset();let Ve=[];if((function ee(P,B,A,S,U,Y){o(B);const J=B.getComponent();let ne=a(S),pe=!1;const he=(j,oe,Oe)=>j?l.moveOp(j.getPath(),oe.getPath()):l.insertOp(oe.getPath(),Oe.i);if(s(J)){const j=J.d;j!=null&&(W[j]=B.clone());const oe=j!=null?Pe[j]:null;let Oe=!1;if(J.i!==void 0||j!=null&&oe){let de;ne&&(ne.i!==void 0||(de=ne.d)!=null&&!p[de])&&(Oe=de!=null?j!=null&&j===$[de]:n.default(ne.i,J.i),Oe||de!=null&&E!==1&&$[de]!=null||O==null&&(O={type:u.ConflictType.DROP_COLLISION,op1:he(j!=null?C[j]:null,B,J),op2:he(de!=null?N[de]:null,S,ne)})),Oe||(Y?O==null&&(O={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:he(j!=null?C[j]:null,B,J),op2:l.removeOp(Y.getPath())}):(j!=null?(Ve[Ge]=j,U.write("d",oe.p=Ge++)):U.write("i",t.default(J.i)),pe=!0))}else if(j!=null&&!oe){const de=R[j];de&&(Y=de.clone())}j!=null?(P=C[j],A=w[j],S=I[j]):J.i!==void 0&&(P=A=null,Oe||(S=null))}else _(a(P))&&(P=A=S=null);const ue=a(P),be=a(A);if(_(be)){const j=be.p;be.r!==void 0&&(!ue||ue.r===void 0)||p[j]?(S=null,Y=A.clone()):j!=null&&(S=g[j],E!==1&&$[j]!=null||((U=re[j])||(U=re[j]=r.writeCursor()),U.reset(),Y=null))}else!s(J)&&s(ne)&&(S=null);ne=S!=null?S.getComponent():null;const V=we(J);if(V){const j=f(J);if(Y)O==null&&(O={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:l.editOp(B.getPath(),V,j,!0),op2:l.removeOp(Y.getPath())});else{const oe=we(ne);let Oe;if(oe){if(V!==oe)throw Error("Transforming incompatible types");const de=f(ne);Oe=V.transform(j,de,v)}else Oe=t.default(j);y(U,V,Oe)}}let T=0,x=0,ye=0,Ce=0,Be=0,ze=0,ke=P!=null&&P.descendFirst(),tt=ke;const Ye=r.advancer(A,void 0,(j,oe)=>{_(oe)&&ye++});let Re=S!=null&&S.descendFirst(),We=Re;for(const j of B)if(typeof j=="number"){let oe;const Oe=s(B.getComponent()),de=j-x;{let xe;for(;ke&&typeof(xe=P.getKey())=="number";){xe+=T;const Ne=P.getComponent(),Ze=_(Ne);if(xe>de||xe===de&&(!Ze||E===0&&Oe))break;if(Ze){T--;const Xe=Ne.p;$.includes(Xe),Ne.d,a(re[Ne.d]),_(a(re[Ne.d])),(Ne.r===void 0||Ue&&Ue.has(Ne))&&(Xe==null||!Pe[Xe]||E!==1&&$.includes(Xe))||Be--}ke=P.nextSibling()}oe=ke&&xe===de?P:null}const je=de-T;let qe=Ye(je);const pt=je-ye;let st=null;{let xe,Ne;for(;Re&&typeof(xe=S.getKey())=="number";){Ne=xe-Ce;const Ze=S.getComponent(),Xe=s(Ze);if(Ne>pt)break;if(Ne===pt){if(!Xe){st=S;break}{if(E===0&&Oe){st=S;break}const He=qe&&_(qe.getComponent());if(E===0&&He)break}}if(Xe){const He=Ze.d;p[He],$[He],Ze.i===void 0&&(p[He]||$[He]!=null&&E!==1)?(p[He]||$[He]!=null&&E===0)&&(Ce++,ze--):Ce++}Re=S.nextSibling()}}const Gt=pt+Ce+Be+ze;o(Gt>=0,"trying to descend to a negative index"),U.descend(Gt),Oe&&(oe=qe=st=null,x++),ee(oe,B,qe,st,U,Y)&&ze++,U.ascend()}else{let oe;for(;ke&&(oe=P.getKey(),typeof oe!="string"||!(oe>j||oe===j));)ke=P.nextSibling();const Oe=ke&&oe===j?P:null,de=Ye(j);let je;for(;Re&&(je=S.getKey(),typeof je!="string"||!(je>j||je===j));)Re=S.nextSibling();const qe=Re&&je===j?S:null;U.descend(j),ee(Oe,B,de,qe,U,Y),U.ascend()}return Ye.end(),tt&&P.ascend(),We&&S.ascend(),pe})(Ie,Ie.clone(),ve,ve.clone(),le,null),O)return{ok:!1,conflict:O};le.reset();const Ae=(ee,P,B)=>ee.traverse(P,(A,S)=>{A.d!=null&&B(A.d,ee,S)});(p.length||se.length)&&(Ae(ve,le,(ee,P,B)=>{p[ee]&&!M[ee]&&B.write("r",!0),se[ee]&&B.mergeTree(se[ee].get())}),le.reset());const Ee=[],Le=[];if((re.length||p.length)&&!O){const ee=r.readCursor(ht(le.get()));if(Ae(ee,null,(P,B)=>{Ee[P]=B.clone()}),re.forEach(P=>{P&&Ae(r.readCursor(P.get()),null,(B,A)=>{Ee[B]=A.clone()})}),(function P(B,A,S,U,Y,J){const ne=a(A);if(ne&&_(ne))if(ne.p!=null){const T=ne.p;Ee[T].getPath(),S=Ee[T],U=Le[T]=r.writeCursor()}else ne.r!==void 0&&(S=null);else s(a(S))&&(S=null);const pe=B.getComponent();if(pe){let T;if((T=pe.d)!=null){const x=re[T];x&&(x.get(),U.mergeTree(x.get()),S=r.readCursor(x.get()))}}let he=0,ue=0;const be=r.advancer(A,void 0,(T,x)=>{_(x)&&he--}),V=r.advancer(S,(T,x)=>s(x)?-(T-ue)-1:T-ue,(T,x)=>{s(x)&&ue++});for(const T of B)if(typeof T=="number"){const x=be(T),ye=T+he,Ce=V(ye),Be=ye+ue;U.descend(Be),P(B,x,Ce,U),U.ascend()}else U.descend(T),P(B,be(T),V(T),U),U.ascend();be.end(),V.end()})(ve,ee,ee.clone(),le),le.reset(),O)return{ok:!1,conflict:O};if(le.get(),Le.length){const P=Le.map(A=>A?A.get():null),B=r.readCursor(ht(le.get()));if(Ae(B,le,(A,S,U)=>{const Y=P[A];Y&&(U.mergeTree(Y),P[A]=null)}),P.find(A=>A)){const A=r.writeCursor(),S=r.writeCursor();let U=0,Y=0;P.forEach(J=>{J!=null&&Ae(r.readCursor(J),null,ne=>{const pe=Ve[ne];A.writeMove(C[pe].getPath(),W[pe].getPath(),U++);const he=ae[pe];he&&he.forEach(ue=>{p[ue]||E!==1&&$[ue]!=null||S.writeMove(N[ue].getPath(),g[ue].getPath(),Y++)})})}),O={type:u.ConflictType.BLACKHOLE,op1:A.get(),op2:S.get()}}}}return O?{ok:!1,conflict:O}:{ok:!0,result:le.get()}}const Rt=i=>{const d=new Error("Transform detected write conflict");throw d.conflict=i,d.type=d.name="writeConflict",d};function Yt(i,d,v){const E=gt(i,d,v);if(E.ok)return E.result;Rt(E.conflict)}const Je=i=>{const d=r.writeCursor();return r.readCursor(i).traverse(d,(v,E)=>{(s(v)||we(v))&&E.write("r",!0)}),d.get()},Zt=(i,d)=>{const{type:v,op1:E,op2:O}=i;switch(v){case u.ConflictType.DROP_COLLISION:return d==="left"?[null,Je(O)]:[Je(E),null];case u.ConflictType.RM_UNEXPECTED_CONTENT:let C=!1;return r.readCursor(E).traverse(null,W=>{W.r!==void 0&&(C=!0)}),C?[null,Je(O)]:[Je(E),null];case u.ConflictType.BLACKHOLE:return[Je(E),Je(O)];default:throw Error("Unrecognised conflict: "+v)}};function Wt(i,d,v,E){let O=null;for(;;){const C=gt(d,v,E);if(C.ok)return ie(O,C.result);{const{conflict:W}=C;i(W)||Rt(W);const[N,g]=Zt(W,E);d=ie(K(d),N),v=ie(K(v),g),O=ie(O,g)}}}})(Qe)),Qe}var Mt;function $t(){return Mt||(Mt=1,(function(l){var e=Ke&&Ke.__createBinding||(Object.create?(function(u,o,a,D){D===void 0&&(D=a),Object.defineProperty(u,D,{enumerable:!0,get:function(){return o[a]}})}):(function(u,o,a,D){D===void 0&&(D=a),u[D]=o[a]})),n=Ke&&Ke.__exportStar||function(u,o){for(var a in u)a!=="default"&&!o.hasOwnProperty(a)&&e(o,u,a)};Object.defineProperty(l,"__esModule",{value:!0}),n(Kt(),l);var t=It();Object.defineProperty(l,"ReadCursor",{enumerable:!0,get:function(){return t.ReadCursor}}),Object.defineProperty(l,"WriteCursor",{enumerable:!0,get:function(){return t.WriteCursor}});var r=Dt();Object.defineProperty(l,"ConflictType",{enumerable:!0,get:function(){return r.ConflictType}})})(Ke)),Ke}var F=$t();class Ut{constructor(){q(this,"drawingManagerData",{});q(this,"_oldDrawingManagerData",{});q(this,"_focusDrawings",[]);q(this,"_remove$",new ge.Subject);q(this,"remove$",this._remove$.asObservable());q(this,"_add$",new ge.Subject);q(this,"add$",this._add$.asObservable());q(this,"_update$",new ge.Subject);q(this,"update$",this._update$.asObservable());q(this,"_order$",new ge.Subject);q(this,"order$",this._order$.asObservable());q(this,"_group$",new ge.Subject);q(this,"group$",this._group$.asObservable());q(this,"_ungroup$",new ge.Subject);q(this,"ungroup$",this._ungroup$.asObservable());q(this,"_refreshTransform$",new ge.Subject);q(this,"refreshTransform$",this._refreshTransform$.asObservable());q(this,"_visible$",new ge.Subject);q(this,"visible$",this._visible$.asObservable());q(this,"_focus$",new ge.Subject);q(this,"focus$",this._focus$.asObservable());q(this,"_featurePluginUpdate$",new ge.Subject);q(this,"featurePluginUpdate$",this._featurePluginUpdate$.asObservable());q(this,"_featurePluginAdd$",new ge.Subject);q(this,"featurePluginAdd$",this._featurePluginAdd$.asObservable());q(this,"_featurePluginRemove$",new ge.Subject);q(this,"featurePluginRemove$",this._featurePluginRemove$.asObservable());q(this,"_featurePluginOrderUpdate$",new ge.Subject);q(this,"featurePluginOrderUpdate$",this._featurePluginOrderUpdate$.asObservable());q(this,"_featurePluginGroupUpdate$",new ge.Subject);q(this,"featurePluginGroupUpdate$",this._featurePluginGroupUpdate$.asObservable());q(this,"_featurePluginUngroupUpdate$",new ge.Subject);q(this,"featurePluginUngroupUpdate$",this._featurePluginUngroupUpdate$.asObservable());q(this,"_visible",!0);q(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(n=>{const t=this._getCurrentBySearch(n);t!=null&&(t.transform=n.transform,t.transforms=n.transforms,t.isMultiTransform=n.isMultiTransform)}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return this.drawingManagerData[e]||{}}removeDrawingDataForUnit(e){const n=this.drawingManagerData[e];if(n==null)return;delete this.drawingManagerData[e];const t=[];Object.keys(n).forEach(r=>{const u=n[r];(u==null?void 0:u.data)!=null&&Object.keys(u.data).forEach(o=>{t.push({unitId:e,subUnitId:r,drawingId:o})})}),t.length>0&&this.removeNotification(t)}registerDrawingData(e,n){this.drawingManagerData[e]=n}initializeNotification(e){const n=[],t=this.drawingManagerData[e];t!=null&&(Object.keys(t).forEach(r=>{this._establishDrawingMap(e,r);const u=t[r];Object.keys(u.data).forEach(o=>{const a=u.data[o];a.unitId=e,a.subUnitId=r,n.push(a)})}),n.length>0&&this.addNotification(n))}getDrawingData(e,n){return this._getDrawingData(e,n)}setDrawingData(e,n,t){this.drawingManagerData[e][n].data=t}getBatchAddOp(e){const n=[],t=[],r=[];e.forEach(G=>{const{op:_,invertOp:s}=this._addByParam(G);n.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),t.push(_),r.push(s)});const u=t.reduce(F.type.compose,null),o=r.reduce(F.type.compose,null),{unitId:a,subUnitId:D}=e[0];return{undo:o,redo:u,unitId:a,subUnitId:D,objects:n}}getBatchRemoveOp(e){const n=[],t=[];e.forEach(D=>{const{op:G,invertOp:_}=this._removeByParam(D);n.unshift(G),t.push(_)});const r=n.reduce(F.type.compose,null),u=t.reduce(F.type.compose,null),{unitId:o,subUnitId:a}=e[0];return{undo:u,redo:r,unitId:o,subUnitId:a,objects:e}}getBatchUpdateOp(e){const n=[],t=[],r=[];e.forEach(G=>{const{op:_,invertOp:s}=this._updateByParam(G);n.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),t.push(_),r.push(s)});const u=t.reduce(F.type.compose,null),o=r.reduce(F.type.compose,null),{unitId:a,subUnitId:D}=e[0];return{undo:o,redo:u,unitId:a,subUnitId:D,objects:n}}removeNotification(e){this._remove$.next(e)}addNotification(e){this._add$.next(e)}updateNotification(e){this._update$.next(e)}orderNotification(e){this._order$.next(e)}groupUpdateNotification(e){this._group$.next(e)}ungroupUpdateNotification(e){this._ungroup$.next(e)}refreshTransformNotification(e){this._refreshTransform$.next(e)}getGroupDrawingOp(e){const n=[],{unitId:t,subUnitId:r}=e[0].parent;e.forEach(a=>{n.push(this._getGroupDrawingOp(a))});const u=n.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(u,this.drawingManagerData),redo:u,unitId:t,subUnitId:r,objects:e}}getUngroupDrawingOp(e){const n=[],{unitId:t,subUnitId:r}=e[0].parent;e.forEach(a=>{n.push(this._getUngroupDrawingOp(a))});const u=n.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(u,this.drawingManagerData),redo:u,unitId:t,subUnitId:r,objects:e}}getDrawingsByGroup(e){const{unitId:n,subUnitId:t,drawingId:r}=e;if(this.getDrawingByParam({unitId:n,subUnitId:t,drawingId:r})==null)return[];const o=this._getDrawingData(n,t),a=[];return Object.keys(o).forEach(D=>{const G=o[D];G.groupId===r&&a.push(G)}),a}_getGroupDrawingOp(e){const{parent:n,children:t}=e,{unitId:r,subUnitId:u,drawingId:o}=n,a=[];a.push(F.insertOp([r,u,"data",o],n));let D=Number.NEGATIVE_INFINITY;return t.forEach(G=>{const{unitId:_,subUnitId:s,drawingId:c}=G,h=this._hasDrawingOrder({unitId:_,subUnitId:s,drawingId:c});D=Math.max(D,h),a.push(...this._getUpdateParamCompareOp(G,this.getDrawingByParam({unitId:_,subUnitId:s,drawingId:c})))}),D===Number.NEGATIVE_INFINITY&&(D=this._getDrawingOrder(r,u).length),a.push(F.insertOp([r,u,"order",D],o)),a.reduce(F.type.compose,null)}_getUngroupDrawingOp(e){const{parent:n,children:t}=e,{unitId:r,subUnitId:u,drawingId:o}=n,a=[];return t.forEach(D=>{const{unitId:G,subUnitId:_,drawingId:s}=D;a.push(...this._getUpdateParamCompareOp(D,this.getDrawingByParam({unitId:G,subUnitId:_,drawingId:s})))}),a.push(F.removeOp([r,u,"data",o],!0)),a.push(F.removeOp([r,u,"order",this._getDrawingOrder(r,u).indexOf(o)],!0)),a.reduce(F.type.compose,null)}applyJson1(e,n,t){this._establishDrawingMap(e,n),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=F.type.apply(this.drawingManagerData,t)}featurePluginUpdateNotification(e){this._featurePluginUpdate$.next(e)}featurePluginOrderUpdateNotification(e){this._featurePluginOrderUpdate$.next(e)}featurePluginAddNotification(e){this._featurePluginAdd$.next(e)}featurePluginRemoveNotification(e){this._featurePluginRemove$.next(e)}featurePluginGroupUpdateNotification(e){this._featurePluginGroupUpdate$.next(e)}featurePluginUngroupUpdateNotification(e){this._featurePluginUngroupUpdate$.next(e)}getDrawingByParam(e){return this._getCurrentBySearch(e)}getOldDrawingByParam(e){return this._getOldBySearch(e)}getDrawingOKey(e){const[n,t,r]=e.split("#-#");return this._getCurrentBySearch({unitId:n,subUnitId:t,drawingId:r})}focusDrawing(e){if(e==null||e.length===0){this._focusDrawings=[],this._focus$.next([]);return}const n=[];e.forEach(t=>{var D;const{unitId:r,subUnitId:u,drawingId:o}=t,a=(D=this._getDrawingData(r,u))==null?void 0:D[o];a!=null&&n.push(a)}),n.length>0&&(this._focusDrawings=n,this._focus$.next(n))}getFocusDrawings(){const e=[];return this._focusDrawings.forEach(n=>{var a;const{unitId:t,subUnitId:r,drawingId:u}=n,o=(a=this._getDrawingData(t,r))==null?void 0:a[u];o!=null&&e.push(o)}),e}getDrawingOrder(e,n){return this._getDrawingOrder(e,n)}setDrawingOrder(e,n,t){this.drawingManagerData[e][n].order=t}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){const{unitId:n,subUnitId:t,drawingIds:r}=e,u=[],o=this.getDrawingOrder(n,t),a=[...r];r.forEach(_=>{const s=this._hasDrawingOrder({unitId:n,subUnitId:t,drawingId:_});if(s===-1||s===o.length-1)return;const c=F.moveOp([n,t,"order",s],[n,t,"order",s+1]);u.push(c),a.includes(o[s+1])||a.push(o[s+1])});const D=u.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(D,this.drawingManagerData),redo:D,unitId:n,subUnitId:t,objects:{...e,drawingIds:a}}}getBackwardDrawingOp(e){const{unitId:n,subUnitId:t,drawingIds:r}=e,u=[],o=this.getDrawingOrder(n,t),a=[...r];r.forEach(_=>{const s=this._hasDrawingOrder({unitId:n,subUnitId:t,drawingId:_});if(s===-1||s===0)return;const c=F.moveOp([n,t,"order",s],[n,t,"order",s-1]);u.push(c),a.includes(o[s-1])||a.push(o[s-1])});const D=u.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(D,this.drawingManagerData),redo:D,unitId:n,subUnitId:t,objects:{...e,drawingIds:a}}}getFrontDrawingsOp(e){const{unitId:n,subUnitId:t,drawingIds:r}=e,u=this._getOrderFromSearchParams(n,t,r),o=[...r],a=this.getDrawingOrder(n,t),D=[];u.forEach(s=>{const{drawingId:c}=s,h=this._getDrawingCount(n,t)-1,k=F.moveOp([n,t,"order",this._getDrawingOrder(n,t).indexOf(c)],[n,t,"order",h]);D.push(k),o.includes(a[h])||o.push(a[h])});const G=D.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:n,subUnitId:t,objects:{...e,drawingIds:o}}}getBackDrawingsOp(e){const{unitId:n,subUnitId:t,drawingIds:r}=e,u=this._getOrderFromSearchParams(n,t,r,!0),o=[...r],a=this.getDrawingOrder(n,t),D=[];u.forEach(s=>{const{drawingId:c}=s,h=F.moveOp([n,t,"order",this._getDrawingOrder(n,t).indexOf(c)],[n,t,"order",0]);D.push(h),o.includes(a[0])||o.push(a[0])});const G=D.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:n,subUnitId:t,objects:{...e,drawingIds:o}}}_getDrawingCount(e,n){return this.getDrawingOrder(e,n).length||0}_getOrderFromSearchParams(e,n,t,r=!1){return t.map(u=>{const o=this._hasDrawingOrder({unitId:e,subUnitId:n,drawingId:u});return{drawingId:u,zIndex:o}}).sort(r===!1?z.sortRules:z.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;const{unitId:n,subUnitId:t,drawingId:r}=e;return this._establishDrawingMap(n,t),this._getDrawingOrder(n,t).indexOf(r)}_getCurrentBySearch(e){var u,o,a;if(e==null)return;const{unitId:n,subUnitId:t,drawingId:r}=e;return(a=(o=(u=this.drawingManagerData[n])==null?void 0:u[t])==null?void 0:o.data)==null?void 0:a[r]}_getOldBySearch(e){var u,o,a;if(e==null)return;const{unitId:n,subUnitId:t,drawingId:r}=e;return(a=(o=(u=this._oldDrawingManagerData[n])==null?void 0:u[t])==null?void 0:o.data)==null?void 0:a[r]}_establishDrawingMap(e,n,t){var r;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][n]||(this.drawingManagerData[e][n]={data:{},order:[]}),t==null?null:(r=this.drawingManagerData[e][n].data)==null?void 0:r[t]}_addByParam(e){const{unitId:n,subUnitId:t,drawingId:r}=e;this._establishDrawingMap(n,t,r);const u=F.insertOp([n,t,"data",r],e),o=F.insertOp([n,t,"order",this._getDrawingOrder(n,t).length],r),a=[u,o].reduce(F.type.compose,null),D=F.type.invertWithDoc(a,this.drawingManagerData);return{op:a,invertOp:D}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};const{unitId:n,subUnitId:t,drawingId:r}=e;if(this._establishDrawingMap(n,t,r)==null)return{op:[],invertOp:[]};const o=F.removeOp([n,t,"data",r],!0),a=F.removeOp([n,t,"order",this._getDrawingOrder(n,t).indexOf(r)],!0),D=[o,a].reduce(F.type.compose,null),G=F.type.invertWithDoc(D,this.drawingManagerData);return{op:D,invertOp:G}}_updateByParam(e){const{unitId:n,subUnitId:t,drawingId:r}=e,u=this._establishDrawingMap(n,t,r);if(u==null)return{op:[],invertOp:[]};const a=this._getUpdateParamCompareOp(e,u).reduce(F.type.compose,null),D=F.type.invertWithDoc(a,this.drawingManagerData);return{op:a,invertOp:D}}_getUpdateParamCompareOp(e,n){const{unitId:t,subUnitId:r,drawingId:u}=e,o=[];return Object.keys(e).forEach(a=>{const D=e[a],G=n[a];G!==D&&o.push(F.replaceOp([t,r,"data",u,a],G,D))}),o}_getDrawingData(e,n){var t,r;return((r=(t=this.drawingManagerData[e])==null?void 0:t[n])==null?void 0:r.data)||{}}_getDrawingOrder(e,n){var t,r;return((r=(t=this.drawingManagerData[e])==null?void 0:t[n])==null?void 0:r.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(e){this._visible=e}setDrawingEditable(e){this._editable=e}}class kt extends Ut{}class jt{constructor(){q(this,"_waitCount",0);q(this,"_change$",new ge.Subject);q(this,"change$",this._change$);q(this,"_imageSourceCache",new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,n){if(n===z.ImageSourceType.BASE64){const t=new Image;return t.src=e,t}return this._imageSourceCache.get(e)}addImageSourceCache(e,n,t){n===z.ImageSourceType.BASE64||t==null||this._imageSourceCache.set(e,t)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((n,t)=>{if(!yt.includes(e.type)){t(new Error(z.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>5242880){t(new Error(z.ImageUploadStatusType.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}const r=new FileReader;r.readAsDataURL(e),r.onload=u=>{var D;const o=(D=u.target)==null?void 0:D.result;if(o==null){t(new Error(z.ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting();return}const a=z.generateRandomId(6);n({imageId:a,imageSourceType:z.ImageSourceType.BASE64,source:o,base64Cache:o,status:z.ImageUploadStatusType.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}}class Nt extends z.Disposable{constructor(){super(...arguments);q(this,"_urlImageDownloader",null)}registerURLImageDownloader(n){return this._urlImageDownloader=n,z.toDisposable(()=>{this._urlImageDownloader=null})}async getImage(n){if(this._urlImageDownloader)try{return await this._urlImageDownloader(n)}catch(t){console.error(`Custom downloader failed for ${n}, falling back to default behavior:`,t)}return n}async downloadImage(n){if(this._urlImageDownloader)try{const r=await this._urlImageDownloader(n);return await(await fetch(r)).blob()}catch(r){console.error(`Custom downloader failed for ${n}, falling back to default fetch:`,r)}return await(await fetch(n)).blob()}}var Ft=Object.getOwnPropertyDescriptor,Vt=(l,e,n,t)=>{for(var r=t>1?void 0:t?Ft(e,n):e,u=l.length-1,o;u>=0;u--)(o=l[u])&&(r=o(r)||r);return r},ft=(l,e)=>(n,t)=>e(n,t,l);te.UniverDrawingPlugin=(et=class extends z.Plugin{constructor(e=vt,n,t,r){super(),this._config=e,this._injector=n,this._configService=t,this._commandService=r;const{...u}=z.merge({},vt,this._config);this._configService.setConfig(Lt,u)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var t;const e=[[z.IImageIoService,{useClass:jt}],[z.IURLImageService,{useClass:Nt}],[ot,{useClass:kt}]];z.mergeOverrideWithDependencies(e,(t=this._config)==null?void 0:t.override).forEach(r=>this._injector.add(r))}_initCommands(){[_t].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}},q(et,"pluginName","UNIVER_DRAWING_PLUGIN"),q(et,"packageName",mt.name),q(et,"version",mt.version),et),te.UniverDrawingPlugin=Vt([ft(1,z.Inject(z.Injector)),ft(2,z.IConfigService),ft(3,z.ICommandService)],te.UniverDrawingPlugin);function zt({unitId:l,subUnitId:e,drawingId:n},t){return typeof t=="number"?`${l}#-#${e}#-#${n}#-#${t}`:`${l}#-#${e}#-#${n}`}const Xt=async l=>new Promise((e,n)=>{const t=new Image;t.src=l,t.onload=()=>{e({width:t.width,height:t.height,image:t})},t.onerror=r=>{n(r)}});Object.defineProperty(te,"IImageIoService",{enumerable:!0,get:()=>z.IImageIoService}),Object.defineProperty(te,"ImageSourceType",{enumerable:!0,get:()=>z.ImageSourceType}),Object.defineProperty(te,"ImageUploadStatusType",{enumerable:!0,get:()=>z.ImageUploadStatusType}),te.DRAWING_IMAGE_ALLOW_IMAGE_LIST=yt,te.DRAWING_IMAGE_ALLOW_SIZE=5242880,te.DRAWING_IMAGE_COUNT_LIMIT=10,te.DRAWING_IMAGE_HEIGHT_LIMIT=500,te.DRAWING_IMAGE_WIDTH_LIMIT=500,te.DrawingManagerService=kt,te.IDrawingManagerService=ot,te.ImageIoService=jt,te.SetDrawingSelectedOperation=_t,te.URLImageService=Nt,te.UnitDrawingService=Ut,te.getDrawingShapeKeyByDrawingSearch=zt,te.getImageSize=Xt,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDrawing={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:r(s(e)),u(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e));let f=[`image/png`,`image/jpeg`,`image/jpg`,`image/gif`,`image/bmp`],p=(0,t.createIdentifier)(`univer.drawing-manager.service`),m={id:`drawing.operation.set-drawing-selected`,type:t.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(p);return t==null?!1:(n.focusDrawing(t),!0)}};var h=`@univerjs/drawing`,g=`0.18.0`;let _=`drawing.config`;Symbol(_);let v={};var y=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0});function t(e,t){if(Array.isArray(t))return!1;for(let n in e)if(!r(e[n],t[n]))return!1;for(let n in t)if(e[n]===void 0)return!1;return!0}function n(e,t){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0}function r(e,r){return e===r?!0:e===null||r===null||typeof e!=`object`||typeof r!=`object`?!1:Array.isArray(e)?n(e,r):t(e,r)}e.default=r})),b=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0});function t(e){if(e===null)return null;if(Array.isArray(e))return e.map(t);if(typeof e==`object`){let n={};for(let r in e)n[r]=t(e[r]);return n}else return e}e.default=t})),x=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.eachChildOf=e.advancer=e.readCursor=e.writeCursor=e.WriteCursor=e.ReadCursor=e.isValidPathItem=void 0;function t(e,t){if(!e)throw Error(t)}let n=e=>typeof e==`object`&&!!e&&!Array.isArray(e),r=(e,t)=>typeof e==typeof t?e>t:typeof e==`string`&&typeof t==`number`;function i(e,t){for(let n in e){let r=n;t.write(r,e[r])}}e.isValidPathItem=e=>typeof e==`number`||typeof e==`string`&&e!==`__proto__`;var a=class{constructor(e=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=e}ascend(){t(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(t(this.idx>0),this.idx--,n(this.container[this.idx])&&this.idx--)}getPath(){let e=[],t=this.container,r=this.parents.length-1,i=this.idx;for(;i>=0;)e.unshift(t[i]),i===0?(i=this.indexes[r*2],t=this.parents[r--]):i-=n(t[i-1])?2:1;return e}},o=class e extends a{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return t(this.container!=null,`Invalid call to getKey before cursor descended`),this.container[this.idx]}getComponent(){let e;return this.container&&this.container.length>this.idx+1&&n(e=this.container[this.idx+1])?e:null}descendFirst(){let e=this.idx+1;if(!this.container||e>=this.container.length||n(this.container[e])&&e+1>=this.container.length)return!1;n(this.container[e])&&e++;let t=this.container[e];return Array.isArray(t)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(e),this.idx=0,this.container=t):this.idx=e,!0}nextSibling(){if(t(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;let e=this.indexes[this.indexes.length-1]+1,n=this.parents[this.parents.length-1];return e>=n.length?!1:(t(!isNaN(e)),this.indexes[this.indexes.length-1]=e,this.container=n[e],!0)}_init(e,t,n,r){this.container=e,this.idx=t,this.parents=n.slice(),this.indexes=r.slice()}clone(){let t=new e;return t._init(this.container,this.idx,this.parents,this.indexes),t}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(e,t){let n=this.getComponent();n&&t(n,e);for(let n of this)e&&e.descend(n),this.traverse(e,t),e&&e.ascend()}eachPick(e,t){this.traverse(e,(e,n)=>{e.p!=null&&t(e.p,n)})}eachDrop(e,t){this.traverse(e,(e,n)=>{e.d!=null&&t(e.d,n)})}};e.ReadCursor=o;var s=class extends a{constructor(e=null){super(e),this.pendingDescent=[],this._op=e}flushDescent(){t(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let e=0;e<this.pendingDescent.length;e++){let i=this.pendingDescent[e],a=this.idx+1;if(a<this.container.length&&n(this.container[a])&&a++,t(a===this.container.length||!n(this.container[a])),a===this.container.length)this.container.push(i),this.idx=a;else if(this.container[a]===i)this.idx=a;else{if(!Array.isArray(this.container[a])){let e=this.container.splice(a,this.container.length-a);this.container.push(e),this.lcIdx>-1&&(this.lcIdx=a)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(t(r(i,this.container[this.lcIdx][0])),a=this.lcIdx+1,this.lcIdx=-1);a<this.container.length&&r(i,this.container[a][0]);)a++;if(this.indexes.push(a),this.idx=0,a<this.container.length&&this.container[a][0]===i)this.container=this.container[a];else{let e=[i];this.container.splice(a,0,e),this.container=e}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();let e=this.idx+1;if(e<this.container.length&&n(this.container[e]))return this.container[e];{let t={};return this.container.splice(e,0,t),t}}write(e,n){let r=this.getComponent();t(r[e]==null||r[e]===n,`Internal consistency error: Overwritten component. File a bug`),r[e]=n}get(){return this._op}descend(t){if(!e.isValidPathItem(t))throw Error(`Invalid JSON key`);this.pendingDescent.push(t)}descendPath(e){return this.pendingDescent.push(...e),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(e,n=i){if(e===null)return;if(t(Array.isArray(e)),e===this._op)throw Error(`Cannot merge into my own tree`);let r=this.lcIdx,a=this.parents.length,o=0;for(let t=0;t<e.length;t++){let r=e[t];typeof r==`string`||typeof r==`number`?(o++,this.descend(r)):Array.isArray(r)?this.mergeTree(r,n):typeof r==`object`&&n(r,this)}for(;o--;)this.ascend();this.lcIdx=this.parents.length===a?r:-1}at(e,t){this.descendPath(e),t(this);for(let t=0;t<e.length;t++)this.ascend();return this}writeAtPath(e,t,n){return this.at(e,()=>this.write(t,n)),this.reset(),this}writeMove(e,t,n=0){return this.writeAtPath(e,`p`,n).writeAtPath(t,`d`,n)}getPath(){let e=super.getPath();return e.push(...this.pendingDescent),e}};e.WriteCursor=s,e.writeCursor=()=>new s,e.readCursor=e=>new o(e);function c(e,t,n){let i,a;a=i=e?e.descendFirst():!1;function o(i){let o;for(;a;){let s=o=e.getKey();if(i!=null){let n=!1;if(t&&typeof s==`number`&&(o=t(s,e.getComponent()),o<0&&(o=~o,n=!0)),r(o,i))return null;if(o===i&&!n)return e}n&&typeof o==`number`&&n(o,e.getComponent()),a=e.nextSibling()}return null}return o.end=()=>{i&&e.ascend()},o}e.advancer=c;function l(e,t,n){let i,a,o,s;for(i=a=e&&e.descendFirst(),o=s=t&&t.descendFirst();i||o;){let a=i?e.getKey():null,s=o?t.getKey():null;a!==null&&s!==null&&(r(s,a)?s=null:a!==s&&(a=null)),n(a==null?s:a,a==null?null:e,s==null?null:t),a!=null&&i&&(i=e.nextSibling()),s!=null&&o&&(o=t.nextSibling())}a&&e.ascend(),s&&t.ascend()}e.eachChildOf=l})),S=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.ConflictType=void 0,(function(e){e[e.RM_UNEXPECTED_CONTENT=1]=`RM_UNEXPECTED_CONTENT`,e[e.DROP_COLLISION=2]=`DROP_COLLISION`,e[e.BLACKHOLE=3]=`BLACKHOLE`})(e.ConflictType||(e.ConflictType={}))})),C=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.uniToStrPos=e.strPosToUni=void 0,e.strPosToUni=(e,t=e.length)=>{let n=0,r=0;for(;r<t;r++){let t=e.charCodeAt(r);t>=55296&&t<=57343&&(n++,r++)}if(r!==t)throw Error(`Invalid offset - splits unicode bytes`);return r-n},e.uniToStrPos=(e,t)=>{let n=0;for(;t>0;t--){let t=e.charCodeAt(n);n+=t>=55296&&t<=57343?2:1}return n}})),w=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.uniSlice=e.dlen=e.eachOp=void 0;let t=C(),n=t=>{if(!Array.isArray(t))throw Error(`Op must be an array of components`);let n=null;for(let r=0;r<t.length;r++){let i=t[r];switch(typeof i){case`object`:if(typeof i.d!=`number`&&typeof i.d!=`string`)throw Error(`Delete must be number or string`);if(e.dlen(i.d)<=0)throw Error(`Deletes must not be empty`);break;case`string`:if(!(i.length>0))throw Error(`Inserts cannot be empty`);break;case`number`:if(!(i>0))throw Error(`Skip components must be >0`);if(typeof n==`number`)throw Error(`Adjacent skip components should be combined`);break}n=i}if(typeof n==`number`)throw Error(`Op has a trailing skip`)};function r(n,r){let i=0,a=0;for(let o=0;o<n.length;o++){let s=n[o];switch(r(s,i,a),typeof s){case`object`:i+=e.dlen(s.d);break;case`string`:a+=t.strPosToUni(s);break;case`number`:i+=s,a+=s;break}}}e.eachOp=r;function i(e,t){let n=[],i=s(n);return r(e,(e,n,r)=>{i(t(e,n,r))}),d(n)}let a=e=>e,o=e=>i(e,a);e.dlen=e=>typeof e==`number`?e:t.strPosToUni(e);let s=t=>n=>{if(!(!n||n.d===0||n.d===``))if(t.length===0)t.push(n);else if(typeof n==typeof t[t.length-1])if(typeof n==`object`){let r=t[t.length-1];r.d=typeof r.d==`string`&&typeof n.d==`string`?r.d+n.d:e.dlen(r.d)+e.dlen(n.d)}else t[t.length-1]+=n;else t.push(n)},c=e=>typeof e==`number`?e:typeof e==`string`?t.strPosToUni(e):typeof e.d==`number`?e.d:t.strPosToUni(e.d);e.uniSlice=(e,n,r)=>{let i=t.uniToStrPos(e,n),a=r==null?1/0:t.uniToStrPos(e,r);return e.slice(i,a)};let l=(t,n,r)=>typeof t==`number`?r==null?t-n:Math.min(t,r)-n:e.uniSlice(t,n,r),u=n=>{let r=0,i=0;return{take:(a,o)=>{if(r===n.length)return a===-1?null:a;let s=n[r],c;if(typeof s==`number`)return a===-1||s-i<=a?(c=s-i,++r,i=0,c):(i+=a,a);if(typeof s==`string`){if(a===-1||o===`i`||t.strPosToUni(s.slice(i))<=a)return c=s.slice(i),++r,i=0,c;{let e=i+t.uniToStrPos(s.slice(i),a);return c=s.slice(i,e),i=e,c}}else if(a===-1||o===`d`||e.dlen(s.d)-i<=a)return c={d:l(s.d,i)},++r,i=0,c;else{let e=l(s.d,i,i+a);return i+=a,{d:e}}},peek:()=>n[r]}},d=e=>(e.length>0&&typeof e[e.length-1]==`number`&&e.pop(),e);function f(r,i,a){if(a!==`left`&&a!==`right`)throw Error(`side (`+a+`) must be 'left' or 'right'`);n(r),n(i);let o=[],l=s(o),{take:f,peek:p}=u(r);for(let n=0;n<i.length;n++){let r=i[n],o,s;switch(typeof r){case`number`:for(o=r;o>0;)s=f(o,`i`),l(s),typeof s!=`string`&&(o-=c(s));break;case`string`:a===`left`&&typeof p()==`string`&&l(f(-1)),l(t.strPosToUni(r));break;case`object`:for(o=e.dlen(r.d);o>0;)switch(s=f(o,`i`),typeof s){case`number`:o-=s;break;case`string`:l(s);break;case`object`:o-=e.dlen(s.d)}break}}let m;for(;m=f(-1);)l(m);return d(o)}function p(r,i){n(r),n(i);let a=[],o=s(a),{take:f}=u(r);for(let n=0;n<i.length;n++){let r=i[n],a,s;switch(typeof r){case`number`:for(a=r;a>0;)s=f(a,`d`),o(s),typeof s!=`object`&&(a-=c(s));break;case`string`:o(r);break;case`object`:a=e.dlen(r.d);let n=0;for(;n<a;)switch(s=f(a-n,`d`),typeof s){case`number`:o({d:l(r.d,n,n+s)}),n+=s;break;case`string`:n+=t.strPosToUni(s);break;case`object`:o(s)}break}}let p;for(;p=f(-1);)o(p);return d(a)}let m=(n,r)=>{let i=0;for(let a=0;a<r.length&&n>i;a++){let o=r[a];switch(typeof o){case`number`:i+=o;break;case`string`:let r=t.strPosToUni(o);i+=r,n+=r;break;case`object`:n-=Math.min(e.dlen(o.d),n-i);break}}return n},h=(e,t)=>typeof e==`number`?m(e,t):e.map(e=>m(e,t));function g(e,t,n){return i(e,(e,r)=>typeof e==`object`&&typeof e.d==`number`?{d:n.slice(t,r,r+e.d)}:e)}function _(e){return i(e,e=>{switch(typeof e){case`object`:if(typeof e.d==`number`)throw Error(`Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.`);return e.d;case`string`:return{d:e};case`number`:return e}})}function v(e){return i(e,e=>typeof e==`object`&&typeof e.d==`string`?{d:t.strPosToUni(e.d)}:e)}function y(e){let t=!0;return r(e,e=>{typeof e==`object`&&typeof e.d==`number`&&(t=!1)}),t}function b(t){return{name:`text-unicode`,uri:`http://sharejs.org/types/text-unicode`,trim:d,normalize:o,checkOp:n,create(e=``){if(typeof e!=`string`)throw Error(`Initial data must be a string`);return t.create(e)},apply(r,i){n(i);let a=t.builder(r);for(let t=0;t<i.length;t++){let n=i[t];switch(typeof n){case`number`:a.skip(n);break;case`string`:a.append(n);break;case`object`:a.del(e.dlen(n.d));break}}return a.build()},transform:f,compose:p,transformPosition:m,transformSelection:h,isInvertible:y,makeInvertible(e,n){return g(e,n,t)},stripInvertible:v,invert:_,invertWithDoc(e,n){return _(g(e,n,t))},isNoop:e=>e.length===0}}e.default=b})),T=l((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=w(),n=C();function r(e,r){return{get:e,getLength(){return e().length},insert(t,i,a){return r([n.strPosToUni(e(),t),i],a)},remove(t,i,a){return r([n.strPosToUni(e(),t),{d:i}],a)},_onOp(e){t.eachOp(e,(e,n,r)=>{switch(typeof e){case`string`:this.onInsert&&this.onInsert(r,e);break;case`object`:let n=t.dlen(e.d);this.onRemove&&this.onRemove(r,n)}})},onInsert:null,onRemove:null}}e.default=r,r.provides={text:!0}})),E=l((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}):function(e,t){e.default=t}),r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)Object.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r},i=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,`__esModule`,{value:!0}),e.type=e.remove=e.insert=void 0;let a=C(),o=r(w()),s=i(T()),c={create(e){return e},toString(e){return e},builder(e){if(typeof e!=`string`)throw Error(`Invalid document snapshot: `+e);let t=[];return{skip(n){let r=a.uniToStrPos(e,n);if(r>e.length)throw Error(`The op is too long for this document`);t.push(e.slice(0,r)),e=e.slice(r)},append(e){t.push(e)},del(t){e=e.slice(a.uniToStrPos(e,t))},build(){return t.join(``)+e}}},slice:o.uniSlice},l=o.default(c);e.type=Object.assign(Object.assign({},l),{api:s.default}),e.insert=(e,t)=>t.length===0?[]:e===0?[t]:[e,t],e.remove=(e,t)=>o.dlen(t)===0?[]:e===0?[{d:t}]:[e,{d:t}];var u=w();Object.defineProperty(e,`makeType`,{enumerable:!0,get:function(){return u.default}})})),D=l((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,`__esModule`,{value:!0}),e.editOp=e.replaceOp=e.insertOp=e.moveOp=e.removeOp=e.type=void 0;let n=t(y()),r=t(b()),i=x(),a=S(),o=()=>{};function s(e,t){if(!e)throw Error(t)}let c=!1;e.type={name:`json1`,uri:`http://sharejs.org/types/JSONv1`,readCursor:i.readCursor,writeCursor:i.writeCursor,create:e=>e,isNoop:e=>e==null,setDebug(e){c=e,o.quiet=!e},registerSubtype:C,checkValidOp:M,normalize:N,apply:P,transformPosition:F,compose:I,tryTransform:H,transform:W,makeInvertible:z,invert:L,invertWithDoc:B,RM_UNEXPECTED_CONTENT:a.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:a.ConflictType.DROP_COLLISION,BLACKHOLE:a.ConflictType.BLACKHOLE,transformNoConflict:(e,t,n)=>q(()=>!0,e,t,n),typeAllowingConflictsPred:t=>Object.assign(Object.assign({},e.type),{transform:(e,n,r)=>q(t,e,n,r)})};let l=e=>e?e.getComponent():null;function u(e){return e&&typeof e==`object`&&!Array.isArray(e)}let d=e=>Array.isArray(e)?e.slice():typeof e==`object`&&e?Object.assign({},e):e,f=e=>e&&(e.p!=null||e.r!==void 0),p=e=>e&&(e.d!=null||e.i!==void 0);function m(e,t){return s(e!=null),typeof t==`number`?(s(Array.isArray(e),`Invalid key - child is not an array`),(e=e.slice()).splice(t,1)):(s(u(e),`Invalid key - child is not an object`),delete(e=Object.assign({},e))[t]),e}function h(e,t,n){return typeof t==`number`?(s(e!=null,`Container is missing for key`),s(Array.isArray(e),`Cannot use numerical key for object container`),s(e.length>=t,`Cannot insert into out of bounds index`),e.splice(t,0,n)):(s(u(e),`Cannot insert into missing item`),s(e[t]===void 0,`Trying to overwrite value at key. Your op needs to remove it first`),e[t]=n),n}e.removeOp=(e,t=!0)=>i.writeCursor().writeAtPath(e,`r`,t).get(),e.moveOp=(e,t)=>i.writeCursor().writeMove(e,t).get(),e.insertOp=(e,t)=>i.writeCursor().writeAtPath(e,`i`,t).get(),e.replaceOp=(e,t,n)=>i.writeCursor().at(e,e=>{e.write(`r`,t),e.write(`i`,n)}).get(),e.editOp=(e,t,n,r=!1)=>i.writeCursor().at(e,e=>k(e,t,n,r)).get();let g=(e,t)=>e!=null&&(typeof t==`number`?Array.isArray(e):typeof e==`object`),_=(e,t)=>g(e,t)?e[t]:void 0,v={};function C(e){let t=e.type?e.type:e;t.name&&(v[t.name]=t),t.uri&&(v[t.uri]=t)}let w=e=>{let t=v[e];if(t)return t;throw Error(`Missing type: `+e)};C(E());let T=(e,t)=>e+t;C({name:`number`,apply:T,compose:T,invert:e=>-e,transform:e=>e});let D=e=>e==null?null:e.et?w(e.et):e.es?v[`text-unicode`]:e.ena==null?null:v.number,O=e=>e.es?e.es:e.ena==null?e.e:e.ena,k=(e,t,n,r=!1)=>{let[i,a]=typeof t==`string`?[w(t),t]:[t,t.name];!r&&i.isNoop&&i.isNoop(n)||(a===`number`?e.write(`ena`,n):a===`text-unicode`?e.write(`es`,n):(e.write(`et`,a),e.write(`e`,n)))};function A(e){s(typeof e==`number`),s(e>=0),s(e===(0|e))}function j(e){typeof e==`number`?A(e):s(typeof e==`string`)}function M(e){if(e===null)return;let t=new Set,n=new Set,r=e=>{let r=!0,i=!1;for(let a in e){let o=e[a];if(r=!1,s(a===`p`||a===`r`||a===`d`||a===`i`||a===`e`||a===`es`||a===`ena`||a===`et`,`Invalid component item '`+a+`'`),a===`p`)A(o),s(!t.has(o)),t.add(o),s(e.r===void 0);else if(a===`d`)A(o),s(!n.has(o)),n.add(o),s(e.i===void 0);else if(a===`e`||a===`es`||a===`ena`){s(!i),i=!0;let t=D(e);s(t,`Missing type in edit`),t.checkValidOp&&t.checkValidOp(O(e))}}s(!r)},a=(e,t,n)=>{if(!Array.isArray(e))throw Error(`Op must be null or a list`);if(e.length===0)throw Error(`Empty descent`);t||j(e[0]);let o=1,c=0,l=0;for(let t=0;t<e.length;t++){let u=e[t];if(s(u!=null),Array.isArray(u)){let e=a(u,!1,n);if(c){let t=typeof l,n=typeof e;t===n?s(l<e,`descent keys are not in order`):s(t===`number`&&n===`string`)}l=e,c++,o=3}else typeof u==`object`?(s(o===1,`Prev not scalar - instead ${o}`),r(u),o=2):(s(o!==3),j(u),s(i.isValidPathItem(u),`Invalid path key`),o=1)}return s(c!==1,`Operation makes multiple descents. Remove some []`),s(o===2||o===3),e[0]};a(e,!0,!1),s(t.size===n.size,`Mismatched picks and drops in op`);for(let e=0;e<t.size;e++)s(t.has(e)),s(n.has(e))}function N(e){let t=0,n=[],r=i.writeCursor();return r.mergeTree(e,(e,r)=>{let i=D(e);if(i){let t=O(e);k(r,i,i.normalize?i.normalize(t):t)}for(let i of[`r`,`p`,`i`,`d`])if(e[i]!==void 0){let o=i===`p`||i===`d`?(a=e[i],n[a]==null&&(n[a]=t++),n[a]):e[i];r.write(i,o)}var a}),r.get()}function P(e,t){if(o.quiet=!c,M(t),t===null)return e;let n=[];return function e(t,r){let i=t,a=0,o={root:t},c=0,l=o,u=`root`;function f(){for(;c<a;c++){let e=r[c];typeof e!=`object`&&(s(g(l,u)),l=l[u]=d(l[u]),u=e)}}for(;a<r.length;a++){let t=r[a];if(Array.isArray(t)){let n=e(i,t);n!==i&&n!==void 0&&(f(),i=l[u]=n)}else if(typeof t==`object`){t.d==null?t.i!==void 0&&(f(),i=h(l,u,t.i)):(f(),i=h(l,u,n[t.d]));let e=D(t);if(e)f(),i=l[u]=e.apply(i,O(t));else if(t.e!==void 0)throw Error(`Subtype `+t.et+` undefined`)}else i=_(i,t)}return o.root}(e=function e(t,r){let i=[],a=0;for(;a<r.length;a++){let e=r[a];if(Array.isArray(e))break;typeof e!=`object`&&(i.push(t),t=_(t,e))}for(let n=r.length-1;n>=a;n--)t=e(t,r[n]);for(--a;a>=0;a--){let e=r[a];if(typeof e!=`object`){let n=i.pop();t=t===_(n,e)?n:t===void 0?m(n,e):(c=e,l=t,(o=d(o=n))[c]=l,o)}else f(e)&&(s(t!==void 0,`Cannot pick up or remove undefined`),e.p!=null&&(n[e.p]=t),t=void 0)}var o,c,l;return t}(e,t),t)}function F(e,t){e=e.slice(),M(t);let n=i.readCursor(t),r,a,o=!1,s=[];for(let t=0;;t++){let c=e[t],l=n.getComponent();if(l&&(l.r===void 0?l.p!=null&&(o=!1,r=l.p,a=t):o=!0),t>=e.length)break;let u=0,d=i.advancer(n,void 0,(e,t)=>{f(t)&&u++});s.unshift(d);let p=d(c);if(typeof c==`number`&&(e[t]-=u),!p)break}if(s.forEach(e=>e.end()),o)return null;let c=()=>{let t=0;if(r!=null){let r=n.getPath();t=r.length,e=r.concat(e.slice(a))}for(;t<e.length;t++){let r=e[t],a=l(n),o=D(a);if(o){let n=O(a);o.transformPosition&&(e[t]=o.transformPosition(e[t],n));break}let s=0,c=i.advancer(n,(e,t)=>p(t)?~(e-s):e-s,(e,t)=>{p(t)&&s++})(r);if(typeof r==`number`&&(e[t]+=s),!c)break}};return r==null?c():n.eachDrop(null,e=>{e===r&&c()}),e}function I(e,t){if(M(e),M(t),e==null)return t;if(t==null)return e;let n=0,r=i.readCursor(e),a=i.readCursor(t),o=i.writeCursor(),c=[],u=[],d=[],m=[],h=[],g=[],_=new Set;r.traverse(null,e=>{e.p!=null&&(d[e.p]=r.clone())}),a.traverse(null,e=>{e.d!=null&&(m[e.d]=a.clone())});let v=i.writeCursor();return function e(t,r,a,o,v,y,b,x){s(r||a);let S=l(r),C=l(a),w=!!C&&C.r!==void 0,T=!!S&&S.i!==void 0,E=S?S.d:null,A=C?C.p:null,j=(y||w)&&A==null;if(A!=null)o=m[A],b=u[A]=new i.WriteCursor;else if(C&&C.r!==void 0)o=null;else{let e=l(o);e&&e.d!=null&&(o=null)}let M=l(o);if(E!=null)if(t=d[E],x=c[E]=new i.WriteCursor,j)y&&!w&&x.write(`r`,!0);else{let e=h[E]=n++;b.write(`d`,e)}else if(S&&S.i!==void 0)t=null;else{let e=l(t);e&&e.p!=null&&(t=null)}let N;T?(s(v===void 0),N=S.i):N=v;let P=(A==null?!T||y||w:N===void 0)?null:b.getComponent();if(A!=null){if(!(v!==void 0||T)){let e=E==null?n++:h[E];g[A]=e,x.write(`p`,e)}}else w&&(T||v!==void 0||(C.r,x.write(`r`,C.r)));let F=j?null:D(S),I=D(M);if((F||I)&&(F&&F.name,I&&I.name),F&&I){s(F===I);let e=O(S),t=O(M),n=F.compose(e,t);k(b,F,n),_.add(M)}else F?k(b,F,O(S)):I&&(k(b,I,O(M)),_.add(M));let L=typeof N==`object`&&!!N,R=!1,z=0,B=0,V=0,H=0,U=0,W=i.advancer(o,(e,t)=>p(t)?H-e-1:e-H,(e,t)=>{p(t)&&H++}),G=i.advancer(t,(e,t)=>f(t)?z-e-1:e-z,(e,t)=>{f(t)&&z++});if(i.eachChildOf(r,a,(t,n,r)=>{let i,a,o=t,c=t,u=t;if(typeof t==`number`){let e=t+V;a=W(e),c=e+H;let d=t+B;i=G(d),p(l(a))&&(i=null),o=d+z,u=t+U,s(o>=0,`p1PickKey is negative`),s(c>=0,`p2DropKey is negative`);let m=p(l(n)),h=f(l(r));(m||h&&!j)&&U--,m&&B--,h&&V--}else i=G(t),a=W(t);x.descend(o),b.descend(c);let d=L&&!p(l(n))?N[u]:void 0,m=e(i,n,r,a,d,j,b,x);var h,g,_;L&&!j?d!==m&&(R||(N=Array.isArray(N)?N.slice():Object.assign({},N),R=!0),h=N,_=m,typeof(g=u)==`number`?(s(Array.isArray(h)),s(g<h.length)):(s(!Array.isArray(h)),s(h[g]!==void 0)),_===void 0?typeof g==`number`?h.splice(g,1):delete h[g]:h[g]=_):s(m===void 0),b.ascend(),x.ascend()}),G.end(),W.end(),P!=null)P.i=N;else if(!y&&!w&&A==null)return N}(r,r.clone(),a,a.clone(),void 0,!1,o,v),o.reset(),o.mergeTree(v.get()),o.reset(),o.get(),c.map(e=>e.get()),u.map(e=>e.get()),r.traverse(o,(e,t)=>{let n=e.p;if(n!=null){let e=h[n];e!=null&&t.write(`p`,e);let r=c[n];r&&r.get(),r&&t.mergeTree(r.get())}else e.r!==void 0&&t.write(`r`,e.r)}),o.reset(),o.get(),a.traverse(o,(e,t)=>{let n=e.d;if(n!=null){let e=g[n];e!=null&&t.write(`d`,e);let r=u[n];r&&t.mergeTree(r.get())}else e.i!==void 0&&t.write(`i`,e.i);let r=D(e);r&&!_.has(e)&&k(t,r,O(e))}),o.get()}function L(e){if(e==null)return null;let t=new i.ReadCursor(e),n=new i.WriteCursor,r,a=[],o=[];return function e(t,n,i){let o=t.getComponent(),s,c=!1;if(o){o.p!=null&&(n.write(`d`,o.p),a[o.p]=t.clone()),o.r!==void 0&&n.write(`i`,o.r),o.d!=null&&(n.write(`p`,o.d),i=void 0),o.i!==void 0&&(i=s=o.i);let e=D(o);e&&(i===void 0?(r||(r=new Set),r.add(o)):(O(o),i=e.apply(i,O(o)),c=!0))}let l=0;for(let r of t){n.descend(r);let a=typeof r==`number`?r-l:r,o=_(i,a);p(t.getComponent())&&l++;let s=e(t,n,o);if(i!==void 0&&s!==void 0){if(c||(c=!0,i=d(i)),!g(i,a))throw Error(`Cannot modify child - invalid operation`);i[a]=s}n.ascend()}if(s===void 0)return c?i:void 0;n.write(`r`,i)}(t,n,void 0),r&&(n.reset(),function e(t,n,s){let c=n.getComponent();if(c){let e=c.d;if(e!=null&&(t=a[e],s=o[e]=i.writeCursor()),r.has(c)){let e=D(c);if(!e.invert)throw Error(`Cannot invert subtype ${e.name}`);k(s,e,e.invert(O(c)))}}let l=0,u=0,d=i.advancer(t,(e,t)=>f(t)?l-e-1:e-l,(e,t)=>{f(t)&&l++});for(let t of n)if(typeof t==`number`){let r=t-u,i=d(r),a=r+l;s.descend(a),e(i,n,s),p(n.getComponent())&&u++,s.ascend()}else s.descend(t),e(d(t),n,s),s.ascend();d.end()}(t.clone(),t,n),o.length&&(n.reset(),t.traverse(n,(e,t)=>{let n=e.p;if(n!=null){let e=o[n];e&&e.get(),e&&t.mergeTree(e.get())}}))),n.get()}let R=(e,t)=>e.some(e=>typeof e==`object`&&(Array.isArray(e)?R(e,t):t(e)));function z(e,t){if(e==null||!R(e,e=>{var t;return e.r!==void 0||((t=D(e))==null?void 0:t.makeInvertible)!=null}))return e;let n=new i.ReadCursor(e),a=new i.WriteCursor,o=!1,c=[],l=[],u=(e,t,n)=>{let i=e.getComponent(),a=!1;if(i){i.d!=null&&t.write(`d`,i.d),i.i!==void 0&&t.write(`i`,i.i);let r=i.p;if(r!=null&&(c[r]=e.clone(),s(n!==void 0,`Operation picks up at an invalid key`),l[r]=n,t.write(`p`,i.p)),i.r!==void 0&&n===void 0)throw Error(`Invalid doc / op in makeInvertible: removed item missing from doc`);let a=D(i);a&&(a.makeInvertible?o=!0:k(t,a,O(i),!0))}let f=0;for(let r of e){t.descend(r);let i=typeof r==`number`?r-f:r,o=_(n,i),s=u(e,t,o);o!==s&&(a||(a=!0,n=d(n)),s===void 0?(n=m(n,i),typeof r==`number`&&f++):n[i]=s),t.ascend()}return i&&(i.r===void 0?i.p!=null&&(n=void 0):(t.write(`r`,r.default(n)),n=void 0)),n};return u(n,a,t),a.get(),o&&(a.reset(),function e(t,n,r,a,o){let s=n.getComponent();if(s){s.i===void 0?s.d!=null&&(a=l[s.d],t=c[s.d],o=!1,s.d):(a=s.i,o=!0);let e=D(s);if(e&&e.makeInvertible){let t=O(s);k(r,e,e.makeInvertible(t,a),!0)}}let u=0,d=0,m=i.advancer(t,(e,t)=>f(t)?u-e-1:e-u,(e,t)=>{f(t)&&u++});for(let t of n)if(typeof t==`number`){let i=t-d,s=m(i),c=i+u,l=_(a,o?i:c);r.descend(t),e(s,n,r,l,o),p(n.getComponent())&&d++,r.ascend()}else{let i=_(a,t);r.descend(t),e(m(t),n,r,i,o),r.ascend()}m.end()}(n.clone(),n,a,t,!1)),a.get()}function B(e,t){return L(z(e,t))}let V=e=>{if(e==null)return null;let t=e.slice();for(let n=0;n<e.length;n++){let e=t[n];Array.isArray(e)&&(t[n]=V(e))}return t};function H(t,u,d){s(d===`left`||d===`right`,`Direction must be left or right`);let m=d===`left`?0:1;if(o.quiet=!c,o.prefix=0,u==null)return{ok:!0,result:t};M(t),M(u);let h=null,g=[],_=[],v=[],y=[],b=[],x=[],S=[],C=[],w=[],T=[],E=[],A=[],j=[],N=[],P=[],F=0,I=i.readCursor(t),L=i.readCursor(u),R=i.writeCursor();if(function e(t,n=null,r){let a=l(n);a&&(a.r===void 0?a.p!=null&&(r=null,x[a.p]=t.clone()):r=n.clone());let o=t.getComponent(),s;o&&(s=o.p)!=null&&(b[s]=n?n.clone():null,v[s]=t.clone(),r&&(T[s]=!0,w[s]=r),a&&a.p!=null&&(N[s]=a.p));let c=i.advancer(n);for(let n of t)e(t,c(n),r);c.end()}(L,I,null),function t(n,r,o,s,c){let u=o.getComponent(),d,p=!1;u&&((d=u.d)==null?u.i!==void 0&&(n=r=null,p=!0,c&&h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.insertOp(o.getPath(),u.i)})):(y[d]=o.clone(),s!=null&&(P[s]==null&&(P[s]=[]),P[s].push(d)),T[d],n=b[d]||null,r=v[d]||null,T[d]?(c&&(E[d]=!0),c=w[d]||null):!c||m!==1&&N[d]!=null||h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.moveOp(r.getPath(),o.getPath())}),p=!0));let g=l(n);g&&(g.r===void 0?g.p!=null&&(g.p,s=g.p,c=null):c=n.clone());let _=D(u);_&&c&&h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.removeOp(c.getPath()),op2:e.editOp(o.getPath(),_,O(u),!0)});let x=0,S=0,C=i.advancer(r,(e,t)=>f(t)?x-e-1:e-x,(e,t)=>{f(t)&&x++}),k=i.advancer(n);for(let e of o)if(typeof e==`number`){let n=e-S,r=C(n);S+=+t(k(n+x),r,o,s,c)}else{let n=C(e);t(k(e),n,o,s,c)}return C.end(),k.end(),p}(I,L,L.clone(),null,null),y.map(e=>e&&e.get()),h)return{ok:!1,conflict:h};E.map(e=>!!e);let z=[],B=null;(function e(t,n,r,a,o){let c=!1,u=l(n);if(f(u)){let e=u.p;e==null?(r=null,o=n.clone()):(r=y[e],a=A[e]=i.writeCursor(),c=!0,o=null)}else p(l(r))&&(r=null);let d=t.getComponent();if(d){let e=d.p;e==null?d.r!==void 0&&(o||a.write(`r`,!0),(o||c)&&(B==null&&(B=new Set),B.add(d))):(o&&(C[e]=o),z[e]=o||m===1&&c?null:a.getComponent(),g[e]=t.clone(),r&&(S[e]=r.clone()))}let h=0,_=0,v=i.advancer(n,void 0,(e,t)=>{f(t)&&h++}),b=i.advancer(r,(e,t)=>p(t)?~(e-_):e-_,(e,t)=>{p(t)&&_++});if(t)for(let n of t)if(typeof n==`string`){let r=v(n),i=b(n);a.descend(n),e(t,r,i,a,o),a.ascend()}else{let r=v(n),i=n-h,c=f(l(r))?null:b(i),u=i+_;s(u>=0),a.descend(u),e(t,r,c,a,o),a.ascend()}v.end(),b.end()})(I,L,L.clone(),R,null),R.reset();let H=[];if(function t(o,c,u,b,w,E){s(c);let A=c.getComponent(),M=l(b),P=!1,I=(t,n,r)=>t?e.moveOp(t.getPath(),n.getPath()):e.insertOp(n.getPath(),r.i);if(p(A)){let t=A.d;t!=null&&(_[t]=c.clone());let i=t==null?null:z[t],s=!1;if(A.i!==void 0||t!=null&&i){let o;M&&(M.i!==void 0||(o=M.d)!=null&&!T[o])&&(s=o==null?n.default(M.i,A.i):t!=null&&t===N[o],s||o!=null&&m!==1&&N[o]!=null||h==null&&(h={type:a.ConflictType.DROP_COLLISION,op1:I(t==null?null:g[t],c,A),op2:I(o==null?null:v[o],b,M)})),s||(E?h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:I(t==null?null:g[t],c,A),op2:e.removeOp(E.getPath())}):(t==null?w.write(`i`,r.default(A.i)):(H[F]=t,w.write(`d`,i.p=F++)),P=!0))}else if(t!=null&&!i){let e=C[t];e&&(E=e.clone())}t==null?A.i!==void 0&&(o=u=null,s||(b=null)):(o=g[t],u=x[t],b=S[t])}else f(l(o))&&(o=u=b=null);let L=l(o),R=l(u);if(f(R)){let e=R.p;R.r!==void 0&&(!L||L.r===void 0)||T[e]?(b=null,E=u.clone()):e!=null&&(b=y[e],m!==1&&N[e]!=null||((w=j[e])||(w=j[e]=i.writeCursor()),w.reset(),E=null))}else !p(A)&&p(M)&&(b=null);M=b==null?null:b.getComponent();let V=D(A);if(V){let t=O(A);if(E)h==null&&(h={type:a.ConflictType.RM_UNEXPECTED_CONTENT,op1:e.editOp(c.getPath(),V,t,!0),op2:e.removeOp(E.getPath())});else{let e=D(M),n;if(e){if(V!==e)throw Error(`Transforming incompatible types`);let r=O(M);n=V.transform(t,r,d)}else n=r.default(t);k(w,V,n)}}let U=0,W=0,G=0,K=0,q=0,J=0,Y=o!=null&&o.descendFirst(),X=Y,Z=i.advancer(u,void 0,(e,t)=>{f(t)&&G++}),Q=b!=null&&b.descendFirst(),$=Q;for(let e of c)if(typeof e==`number`){let n,r=p(c.getComponent()),i=e-W;{let e;for(;Y&&typeof(e=o.getKey())==`number`;){e+=U;let t=o.getComponent(),n=f(t);if(e>i||e===i&&(!n||m===0&&r))break;if(n){U--;let e=t.p;z[e],N.includes(e),t.d,l(j[t.d]),f(l(j[t.d])),(t.r===void 0||B&&B.has(t))&&(e==null||!z[e]||m!==1&&N.includes(e))||q--}Y=o.nextSibling()}n=Y&&e===i?o:null}let a=i-U,u=Z(a),d=a-G,h=null;{let e,t;for(;Q&&typeof(e=b.getKey())==`number`;){t=e-K;let n=b.getComponent(),i=p(n);if(t>d)break;if(t===d){if(!i){h=b;break}{if(m===0&&r){h=b;break}let e=u&&f(u.getComponent());if(m===0&&e)break}}if(i){let e=n.d;T[e],N[e],n.i===void 0&&(T[e]||N[e]!=null&&m!==1)?(T[e]||N[e]!=null&&m===0)&&(K++,J--):K++}Q=b.nextSibling()}}let g=d+K+q+J;s(g>=0,`trying to descend to a negative index`),w.descend(g),r&&(n=u=h=null,W++),t(n,c,u,h,w,E)&&J++,w.ascend()}else{let n;for(;Y&&(n=o.getKey(),typeof n!=`string`||!(n>e||n===e));)Y=o.nextSibling();let r=Y&&n===e?o:null,i=Z(e),a;for(;Q&&(a=b.getKey(),typeof a!=`string`||!(a>e||a===e));)Q=b.nextSibling();let s=Q&&a===e?b:null;w.descend(e),t(r,c,i,s,w,E),w.ascend()}return Z.end(),X&&o.ascend(),$&&b.ascend(),P}(I,I.clone(),L,L.clone(),R,null),h)return{ok:!1,conflict:h};R.reset();let U=(e,t,n)=>e.traverse(t,(t,r)=>{t.d!=null&&n(t.d,e,r)});(T.length||A.length)&&(U(L,R,(e,t,n)=>{T[e]&&!E[e]&&n.write(`r`,!0),A[e]&&n.mergeTree(A[e].get())}),R.reset());let W=[],G=[];if((j.length||T.length)&&!h){let e=i.readCursor(V(R.get()));if(U(e,null,(e,t)=>{W[e]=t.clone()}),j.forEach(e=>{e&&U(i.readCursor(e.get()),null,(e,t)=>{W[e]=t.clone()})}),function e(t,n,r,a,s,c){o.prefix++;let u=l(n);if(u&&f(u))if(u.p!=null){s=u;let e=u.p;W[e].getPath(),r=W[e],a=G[e]=i.writeCursor()}else u.r!==void 0&&(r=null,c=!0);else p(l(r))&&(r=null);let d=t.getComponent();if(d){let e;if((e=d.d)!=null){let t=j[e];t&&(t.get(),a.mergeTree(t.get()),r=i.readCursor(t.get()))}}let m=0,h=0,g=i.advancer(n,void 0,(e,t)=>{f(t)&&m--}),_=i.advancer(r,(e,t)=>p(t)?-(e-h)-1:e-h,(e,t)=>{p(t)&&h++});for(let n of t)if(typeof n==`number`){let r=g(n),i=n+m,o=_(i),l=i+h;a.descend(l),e(t,r,o,a,s,c),a.ascend()}else a.descend(n),e(t,g(n),_(n),a,s,c),a.ascend();g.end(),_.end()}(L,e,e.clone(),R,null,!1),R.reset(),h)return{ok:!1,conflict:h};if(R.get(),G.length){let e=G.map(e=>e?e.get():null);if(U(i.readCursor(V(R.get())),R,(t,n,r)=>{let i=e[t];i&&(r.mergeTree(i),e[t]=null)}),e.find(e=>e)){let t=i.writeCursor(),n=i.writeCursor(),r=0,o=0;e.forEach(e=>{e!=null&&U(i.readCursor(e),null,e=>{let i=H[e];t.writeMove(g[i].getPath(),_[i].getPath(),r++);let a=P[i];a&&a.forEach(e=>{T[e]||m!==1&&N[e]!=null||n.writeMove(v[e].getPath(),y[e].getPath(),o++)})})}),h={type:a.ConflictType.BLACKHOLE,op1:t.get(),op2:n.get()}}}}return h?{ok:!1,conflict:h}:{ok:!0,result:R.get()}}let U=e=>{let t=Error(`Transform detected write conflict`);throw t.conflict=e,t.type=t.name=`writeConflict`,t};function W(e,t,n){let r=H(e,t,n);if(r.ok)return r.result;U(r.conflict)}let G=e=>{let t=i.writeCursor();return i.readCursor(e).traverse(t,(e,t)=>{(p(e)||D(e))&&t.write(`r`,!0)}),t.get()},K=(e,t)=>{let{type:n,op1:r,op2:o}=e;switch(n){case a.ConflictType.DROP_COLLISION:return t===`left`?[null,G(o)]:[G(r),null];case a.ConflictType.RM_UNEXPECTED_CONTENT:let e=!1;return i.readCursor(r).traverse(null,t=>{t.r!==void 0&&(e=!0)}),e?[null,G(o)]:[G(r),null];case a.ConflictType.BLACKHOLE:return[G(r),G(o)];default:throw Error(`Unrecognised conflict: `+n)}};function q(e,t,n,r){let i=null;for(;;){let a=H(t,n,r);if(a.ok)return I(i,a.result);{let{conflict:o}=a;e(o)||U(o);let[s,c]=K(o,r);t=I(N(t),s),n=I(N(n),c),i=I(i,c)}}}})),O=d(l((e=>{var t=e&&e.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),n=e&&e.__exportStar||function(e,n){for(var r in e)r!==`default`&&!n.hasOwnProperty(r)&&t(n,e,r)};Object.defineProperty(e,`__esModule`,{value:!0}),n(D(),e);var r=x();Object.defineProperty(e,`ReadCursor`,{enumerable:!0,get:function(){return r.ReadCursor}}),Object.defineProperty(e,`WriteCursor`,{enumerable:!0,get:function(){return r.WriteCursor}});var i=S();Object.defineProperty(e,`ConflictType`,{enumerable:!0,get:function(){return i.ConflictType}})}))());function k(e){"@babel/helpers - typeof";return k=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},k(e)}function A(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function j(e){var t=A(e,`string`);return k(t)==`symbol`?t:t+``}function M(e,t,n){return(t=j(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var N=function(e){return e.data=`data`,e.order=`order`,e}(N||{}),P=class{constructor(){M(this,`drawingManagerData`,{}),M(this,`_oldDrawingManagerData`,{}),M(this,`_focusDrawings`,[]),M(this,`_remove$`,new n.Subject),M(this,`remove$`,this._remove$.asObservable()),M(this,`_add$`,new n.Subject),M(this,`add$`,this._add$.asObservable()),M(this,`_update$`,new n.Subject),M(this,`update$`,this._update$.asObservable()),M(this,`_order$`,new n.Subject),M(this,`order$`,this._order$.asObservable()),M(this,`_group$`,new n.Subject),M(this,`group$`,this._group$.asObservable()),M(this,`_ungroup$`,new n.Subject),M(this,`ungroup$`,this._ungroup$.asObservable()),M(this,`_refreshTransform$`,new n.Subject),M(this,`refreshTransform$`,this._refreshTransform$.asObservable()),M(this,`_visible$`,new n.Subject),M(this,`visible$`,this._visible$.asObservable()),M(this,`_focus$`,new n.Subject),M(this,`focus$`,this._focus$.asObservable()),M(this,`_featurePluginUpdate$`,new n.Subject),M(this,`featurePluginUpdate$`,this._featurePluginUpdate$.asObservable()),M(this,`_featurePluginAdd$`,new n.Subject),M(this,`featurePluginAdd$`,this._featurePluginAdd$.asObservable()),M(this,`_featurePluginRemove$`,new n.Subject),M(this,`featurePluginRemove$`,this._featurePluginRemove$.asObservable()),M(this,`_featurePluginOrderUpdate$`,new n.Subject),M(this,`featurePluginOrderUpdate$`,this._featurePluginOrderUpdate$.asObservable()),M(this,`_featurePluginGroupUpdate$`,new n.Subject),M(this,`featurePluginGroupUpdate$`,this._featurePluginGroupUpdate$.asObservable()),M(this,`_featurePluginUngroupUpdate$`,new n.Subject),M(this,`featurePluginUngroupUpdate$`,this._featurePluginUngroupUpdate$.asObservable()),M(this,`_visible`,!0),M(this,`_editable`,!0)}dispose(){this._remove$.complete(),this._add$.complete(),this._update$.complete(),this._order$.complete(),this._focus$.complete(),this._featurePluginUpdate$.complete(),this._featurePluginAdd$.complete(),this._featurePluginRemove$.complete(),this._featurePluginOrderUpdate$.complete(),this.drawingManagerData={},this._oldDrawingManagerData={}}visibleNotification(e){this._visible$.next(e)}refreshTransform(e){e.forEach(e=>{let t=this._getCurrentBySearch(e);t!=null&&(t.transform=e.transform,t.transforms=e.transforms,t.isMultiTransform=e.isMultiTransform)}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return this.drawingManagerData[e]||{}}removeDrawingDataForUnit(e){let t=this.drawingManagerData[e];if(t==null)return;delete this.drawingManagerData[e];let n=[];Object.keys(t).forEach(r=>{let i=t[r];(i==null?void 0:i.data)!=null&&Object.keys(i.data).forEach(t=>{n.push({unitId:e,subUnitId:r,drawingId:t})})}),n.length>0&&this.removeNotification(n)}registerDrawingData(e,t){this.drawingManagerData[e]=t}initializeNotification(e){let t=[],n=this.drawingManagerData[e];n!=null&&(Object.keys(n).forEach(r=>{this._establishDrawingMap(e,r);let i=n[r];Object.keys(i.data).forEach(n=>{let a=i.data[n];a.unitId=e,a.subUnitId=r,t.push(a)})}),t.length>0&&this.addNotification(t))}getDrawingData(e,t){return this._getDrawingData(e,t)}setDrawingData(e,t,n){this.drawingManagerData[e][t].data=n}getBatchAddOp(e){let t=[],n=[],r=[];e.forEach(e=>{let{op:i,invertOp:a}=this._addByParam(e);t.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),n.push(i),r.push(a)});let i=n.reduce(O.type.compose,null),a=r.reduce(O.type.compose,null),{unitId:o,subUnitId:s}=e[0];return{undo:a,redo:i,unitId:o,subUnitId:s,objects:t}}getBatchRemoveOp(e){let t=[],n=[];e.forEach(e=>{let{op:r,invertOp:i}=this._removeByParam(e);t.unshift(r),n.push(i)});let r=t.reduce(O.type.compose,null),i=n.reduce(O.type.compose,null),{unitId:a,subUnitId:o}=e[0];return{undo:i,redo:r,unitId:a,subUnitId:o,objects:e}}getBatchUpdateOp(e){let t=[],n=[],r=[];e.forEach(e=>{let{op:i,invertOp:a}=this._updateByParam(e);t.push({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.drawingId}),n.push(i),r.push(a)});let i=n.reduce(O.type.compose,null),a=r.reduce(O.type.compose,null),{unitId:o,subUnitId:s}=e[0];return{undo:a,redo:i,unitId:o,subUnitId:s,objects:t}}removeNotification(e){this._remove$.next(e)}addNotification(e){this._add$.next(e)}updateNotification(e){this._update$.next(e)}orderNotification(e){this._order$.next(e)}groupUpdateNotification(e){this._group$.next(e)}ungroupUpdateNotification(e){this._ungroup$.next(e)}refreshTransformNotification(e){this._refreshTransform$.next(e)}getGroupDrawingOp(e){let t=[],{unitId:n,subUnitId:r}=e[0].parent;e.forEach(e=>{t.push(this._getGroupDrawingOp(e))});let i=t.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(i,this.drawingManagerData),redo:i,unitId:n,subUnitId:r,objects:e}}getUngroupDrawingOp(e){let t=[],{unitId:n,subUnitId:r}=e[0].parent;e.forEach(e=>{t.push(this._getUngroupDrawingOp(e))});let i=t.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(i,this.drawingManagerData),redo:i,unitId:n,subUnitId:r,objects:e}}getDrawingsByGroup(e){let{unitId:t,subUnitId:n,drawingId:r}=e;if(this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})==null)return[];let i=this._getDrawingData(t,n),a=[];return Object.keys(i).forEach(e=>{let t=i[e];t.groupId===r&&a.push(t)}),a}getDrawingsByGroupNested(e){let{unitId:n,subUnitId:r}=e,i=this.getDrawingByParam(e);if(!i)return null;let a=this._getDrawingData(n,r),o=new Map;Object.values(a).forEach(e=>{e.groupId!=null&&(o.has(e.groupId)||o.set(e.groupId,[]),o.get(e.groupId).push(e.drawingId))});let s=[],c=[],l={},u=e=>{var n;let{drawingId:r}=e,i=(n=o.get(r))==null?[]:n;l[r]={drawingId:r,children:i},i.forEach(e=>{let n=a[e];n&&(n.drawingType===t.DrawingTypeEnum.DRAWING_GROUP?(u(n),c.push(n)):s.push(n))})};return u(i),c.push(i),{nestedIdRecord:l,flatChildren:s,groups:c}}_getGroupDrawingOp(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=[];o.push(O.insertOp([r,i,N.data,a],t));let s=-1/0;return n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:r});s=Math.max(s,i),o.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),s===-1/0&&(s=this._getDrawingOrder(r,i).length),o.push(O.insertOp([r,i,N.order,s],a)),o.reduce(O.type.compose,null)}_getUngroupDrawingOp(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=[];return n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e;o.push(...this._getUpdateParamCompareOp(e,this.getDrawingByParam({unitId:t,subUnitId:n,drawingId:r})))}),o.push(O.removeOp([r,i,N.data,a],!0)),o.push(O.removeOp([r,i,N.order,this._getDrawingOrder(r,i).indexOf(a)],!0)),o.reduce(O.type.compose,null)}applyJson1(e,t,n){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=O.type.apply(this.drawingManagerData,n)}featurePluginUpdateNotification(e){this._featurePluginUpdate$.next(e)}featurePluginOrderUpdateNotification(e){this._featurePluginOrderUpdate$.next(e)}featurePluginAddNotification(e){this._featurePluginAdd$.next(e)}featurePluginRemoveNotification(e){this._featurePluginRemove$.next(e)}featurePluginGroupUpdateNotification(e){this._featurePluginGroupUpdate$.next(e)}featurePluginUngroupUpdateNotification(e){this._featurePluginUngroupUpdate$.next(e)}getDrawingByParam(e){return this._getCurrentBySearch(e)}getOldDrawingByParam(e){return this._getOldBySearch(e)}getDrawingOKey(e){let[t,n,r]=e.split(`#-#`);return this._getCurrentBySearch({unitId:t,subUnitId:n,drawingId:r})}focusDrawing(e){if(e==null||e.length===0){this._focusDrawings=[],this._focus$.next([]);return}let t=[];e.forEach(e=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=e,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&t.push(o)}),t.length>0&&(this._focusDrawings=t,this._focus$.next(t))}getFocusDrawings(){let e=[];return this._focusDrawings.forEach(t=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=t,o=(n=this._getDrawingData(r,i))==null?void 0:n[a];o!=null&&e.push(o)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,n){this.drawingManagerData[e][t].order=n}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=[],a=this.getDrawingOrder(t,n),o=[...r];r.forEach(e=>{let r=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:e});if(r===-1||r===a.length-1)return;let s=O.moveOp([t,n,N.order,r],[t,n,N.order,r+1]);i.push(s),o.includes(a[r+1])||o.push(a[r+1])});let s=i.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(s,this.drawingManagerData),redo:s,unitId:t,subUnitId:n,objects:{...e,drawingIds:o}}}getBackwardDrawingOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=[],a=this.getDrawingOrder(t,n),o=[...r];r.forEach(e=>{let r=this._hasDrawingOrder({unitId:t,subUnitId:n,drawingId:e});if(r===-1||r===0)return;let s=O.moveOp([t,n,N.order,r],[t,n,N.order,r-1]);i.push(s),o.includes(a[r-1])||o.push(a[r-1])});let s=i.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(s,this.drawingManagerData),redo:s,unitId:t,subUnitId:n,objects:{...e,drawingIds:o}}}getFrontDrawingsOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getOrderFromSearchParams(t,n,r),a=[...r],o=this.getDrawingOrder(t,n),s=[];i.forEach(e=>{let{drawingId:r}=e,i=this._getDrawingCount(t,n)-1,c=O.moveOp([t,n,N.order,this._getDrawingOrder(t,n).indexOf(r)],[t,n,N.order,i]);s.push(c),a.includes(o[i])||a.push(o[i])});let c=s.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:t,subUnitId:n,objects:{...e,drawingIds:a}}}getBackDrawingsOp(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getOrderFromSearchParams(t,n,r,!0),a=[...r],o=this.getDrawingOrder(t,n),s=[];i.forEach(e=>{let{drawingId:r}=e,i=O.moveOp([t,n,N.order,this._getDrawingOrder(t,n).indexOf(r)],[t,n,N.order,0]);s.push(i),a.includes(o[0])||a.push(o[0])});let c=s.reduce(O.type.compose,null);return{undo:O.type.invertWithDoc(c,this.drawingManagerData),redo:c,unitId:t,subUnitId:n,objects:{...e,drawingIds:a}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,n,r,i=!1){return r.map(t=>({drawingId:t,zIndex:this._hasDrawingOrder({unitId:e,subUnitId:n,drawingId:t})})).sort(i===!1?t.sortRules:t.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;let{unitId:t,subUnitId:n,drawingId:r}=e;return this._establishDrawingMap(t,n),this._getDrawingOrder(t,n).indexOf(r)}_getCurrentBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return(t=this.drawingManagerData[n])==null||(t=t[r])==null||(t=t.data)==null?void 0:t[i]}_getOldBySearch(e){var t;if(e==null)return;let{unitId:n,subUnitId:r,drawingId:i}=e;return(t=this._oldDrawingManagerData[n])==null||(t=t[r])==null||(t=t.data)==null?void 0:t[i]}_establishDrawingMap(e,t,n){var r;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),n==null?null:(r=this.drawingManagerData[e][t].data)==null?void 0:r[n]}_addByParam(e){let{unitId:t,subUnitId:n,drawingId:r}=e;this._establishDrawingMap(t,n,r);let i=[O.insertOp([t,n,N.data,r],e),O.insertOp([t,n,N.order,this._getDrawingOrder(t,n).length],r)].reduce(O.type.compose,null);return{op:i,invertOp:O.type.invertWithDoc(i,this.drawingManagerData)}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};let{unitId:t,subUnitId:n,drawingId:r}=e;if(this._establishDrawingMap(t,n,r)==null)return{op:[],invertOp:[]};let i=[O.removeOp([t,n,N.data,r],!0),O.removeOp([t,n,N.order,this._getDrawingOrder(t,n).indexOf(r)],!0)].reduce(O.type.compose,null);return{op:i,invertOp:O.type.invertWithDoc(i,this.drawingManagerData)}}_updateByParam(e){let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._establishDrawingMap(t,n,r);if(i==null)return{op:[],invertOp:[]};let a=this._getUpdateParamCompareOp(e,i).reduce(O.type.compose,null);return{op:a,invertOp:O.type.invertWithDoc(a,this.drawingManagerData)}}_getUpdateParamCompareOp(e,t){let{unitId:n,subUnitId:r,drawingId:i}=e,a=[];return Object.keys(e).forEach(o=>{let s=e[o],c=t[o];c!==s&&a.push(O.replaceOp([n,r,N.data,i,o],c,s))}),a}_getDrawingData(e,t){var n;return((n=this.drawingManagerData[e])==null||(n=n[t])==null?void 0:n.data)||{}}_getDrawingOrder(e,t){var n;return((n=this.drawingManagerData[e])==null||(n=n[t])==null?void 0:n.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(e){this._visible=e}setDrawingEditable(e){this._editable=e}},F=class extends P{},I=class{constructor(){M(this,`_waitCount`,0),M(this,`_change$`,new n.Subject),M(this,`change$`,this._change$),M(this,`_imageSourceCache`,new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,n){if(n===t.ImageSourceType.BASE64){let t=new Image;return t.src=e,t}return this._imageSourceCache.get(e)}addImageSourceCache(e,n,r){n===t.ImageSourceType.BASE64||r==null||this._imageSourceCache.set(e,r)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((n,r)=>{if(!f.includes(e.type)){r(Error(t.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>5242880){r(Error(t.ImageUploadStatusType.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}let i=new FileReader;i.readAsDataURL(e),i.onload=e=>{var i;let a=(i=e.target)==null?void 0:i.result;if(a==null){r(Error(t.ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting();return}n({imageId:(0,t.generateRandomId)(6),imageSourceType:t.ImageSourceType.BASE64,source:a,base64Cache:a,status:t.ImageUploadStatusType.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){--this._waitCount,this._change$.next(this._waitCount)}},L=class extends t.Disposable{constructor(...e){super(...e),M(this,`_urlImageDownloader`,null)}registerURLImageDownloader(e){return this._urlImageDownloader=e,(0,t.toDisposable)(()=>{this._urlImageDownloader=null})}async getImage(e){if(this._urlImageDownloader)try{return await this._urlImageDownloader(e)}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default behavior:`,t)}return e}async downloadImage(e){if(this._urlImageDownloader)try{let t=await this._urlImageDownloader(e);return await(await fetch(t)).blob()}catch(t){console.error(`Custom downloader failed for ${e}, falling back to default fetch:`,t)}return await(await fetch(e)).blob()}};function R(e,t){return function(n,r){t(n,r,e)}}function z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let B=class extends t.Plugin{constructor(e=v,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},v,this._config);this._configService.setConfig(_,a)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var e;(0,t.mergeOverrideWithDependencies)([[t.IImageIoService,{useClass:I}],[t.IURLImageService,{useClass:L}],[p,{useClass:F}]],(e=this._config)==null?void 0:e.override).forEach(e=>this._injector.add(e))}_initCommands(){[m].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};M(B,`pluginName`,`UNIVER_DRAWING_PLUGIN`),M(B,`packageName`,h),M(B,`version`,g),B=z([R(1,(0,t.Inject)(t.Injector)),R(2,t.IConfigService),R(3,t.ICommandService)],B);function V({unitId:e,subUnitId:t,drawingId:n},r){return typeof r==`number`?`${e}#-#${t}#-#${n}#-#${r}`:`${e}#-#${t}#-#${n}`}e.DRAWING_IMAGE_ALLOW_IMAGE_LIST=f,e.DRAWING_IMAGE_ALLOW_SIZE=5242880,e.DRAWING_IMAGE_COUNT_LIMIT=10,e.DRAWING_IMAGE_HEIGHT_LIMIT=500,e.DRAWING_IMAGE_WIDTH_LIMIT=500,e.DrawingManagerService=F,e.IDrawingManagerService=p,Object.defineProperty(e,`IImageIoService`,{enumerable:!0,get:function(){return t.IImageIoService}}),e.ImageIoService=I,Object.defineProperty(e,`ImageSourceType`,{enumerable:!0,get:function(){return t.ImageSourceType}}),Object.defineProperty(e,`ImageUploadStatusType`,{enumerable:!0,get:function(){return t.ImageUploadStatusType}}),e.SetDrawingSelectedOperation=m,e.URLImageService=L,e.UnitDrawingService=P,Object.defineProperty(e,`UniverDrawingPlugin`,{enumerable:!0,get:function(){return B}}),e.getDrawingShapeKeyByDrawingSearch=V,e.getImageSize=async e=>new Promise((t,n)=>{let r=new Image;r.src=e,r.onload=()=>{t({width:r.width,height:r.height,image:r})},r.onerror=e=>{n(e)}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/drawing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -47,21 +47,22 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"ot-json1": "^1.0.2",
|
|
50
|
-
"@univerjs/core": "0.
|
|
50
|
+
"@univerjs/core": "0.18.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"rxjs": "^7.8.2",
|
|
54
54
|
"typescript": "^5.9.3",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"@univerjs-infra/shared": "0.17.0"
|
|
55
|
+
"vitest": "^4.1.0",
|
|
56
|
+
"@univerjs-infra/shared": "0.18.0"
|
|
58
57
|
},
|
|
59
58
|
"scripts": {
|
|
60
59
|
"test": "vitest run",
|
|
61
60
|
"test:watch": "vitest",
|
|
62
61
|
"coverage": "vitest run --coverage",
|
|
63
62
|
"typecheck": "tsc --noEmit",
|
|
64
|
-
"build": "univer-cli build"
|
|
63
|
+
"build:bundle": "univer-cli build",
|
|
64
|
+
"build:types": "tsc -p tsconfig.node.json",
|
|
65
|
+
"build": "pnpm run build:bundle && pnpm run build:types"
|
|
65
66
|
},
|
|
66
67
|
"module": "./lib/es/index.js"
|
|
67
68
|
}
|