@univerjs/drawing 0.4.2 → 0.5.0-alpha.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 +1484 -1529
- package/lib/umd/index.js +1 -1
- package/package.json +11 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),rxjs=require("rxjs"),DRAWING_IMAGE_WIDTH_LIMIT=500,DRAWING_IMAGE_HEIGHT_LIMIT=500,DRAWING_IMAGE_COUNT_LIMIT=10,DRAWING_IMAGE_ALLOW_SIZE=5*1024*1024,DRAWING_IMAGE_ALLOW_IMAGE_LIST=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"];var commonjsGlobal=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},dist$1={},json1_release={},deepEqual$1={};Object.defineProperty(deepEqual$1,"__esModule",{value:!0});function eqObj(a,b){if(Array.isArray(b))return!1;for(let k in a)if(!deepEqual(a[k],b[k]))return!1;for(let k in b)if(a[k]===void 0)return!1;return!0}__name(eqObj,"eqObj");function eqArr(a,b){if(!Array.isArray(b)||a.length!==b.length)return!1;for(let i=0;i<a.length;i++)if(!deepEqual(a[i],b[i]))return!1;return!0}__name(eqArr,"eqArr");function deepEqual(a,b){return a===b?!0:a===null||b===null||typeof a!="object"||typeof b!="object"?!1:Array.isArray(a)?eqArr(a,b):eqObj(a,b)}__name(deepEqual,"deepEqual");deepEqual$1.default=deepEqual;var deepClone$1={};Object.defineProperty(deepClone$1,"__esModule",{value:!0});function deepClone(old){if(old===null)return null;if(Array.isArray(old))return old.map(deepClone);if(typeof old=="object"){const o={};for(let k in old)o[k]=deepClone(old[k]);return o}else return old}__name(deepClone,"deepClone");deepClone$1.default=deepClone;var cursor={};(function(exports2){Object.defineProperty(exports2,"__esModule",{value:!0}),exports2.eachChildOf=exports2.advancer=exports2.readCursor=exports2.writeCursor=exports2.WriteCursor=exports2.ReadCursor=exports2.isValidPathItem=void 0;function assert(pred,msg){if(!pred)throw new Error(msg)}__name(assert,"assert");const isObject=__name(o=>o!=null&&typeof o=="object"&&!Array.isArray(o),"isObject"),isGreaterKey=__name((a,b)=>typeof a==typeof b?a>b:typeof a=="string"&&typeof b=="number","isGreaterKey");function copyAll(c,w){for(let _k in c){const k=_k;w.write(k,c[k])}}__name(copyAll,"copyAll"),exports2.isValidPathItem=k=>typeof k=="number"||typeof k=="string"&&k!=="__proto__";const _Cursor=class _Cursor{constructor(op=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=op}ascend(){assert(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):(assert(this.idx>0),this.idx--,isObject(this.container[this.idx])&&this.idx--)}getPath(){const path=[];let c=this.container,p=this.parents.length-1,i=this.idx;for(;i>=0;)path.unshift(c[i]),i===0?(i=this.indexes[p*2],c=this.parents[p--]):i-=isObject(c[i-1])?2:1;return path}};__name(_Cursor,"Cursor");let Cursor=_Cursor;const _ReadCursor=class _ReadCursor extends Cursor{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return assert(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let c;return this.container&&this.container.length>this.idx+1&&isObject(c=this.container[this.idx+1])?c:null}descendFirst(){let i=this.idx+1;if(!this.container||i>=this.container.length||isObject(this.container[i])&&i+1>=this.container.length)return!1;isObject(this.container[i])&&i++;const firstChild=this.container[i];return Array.isArray(firstChild)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(i),this.idx=0,this.container=firstChild):this.idx=i,!0}nextSibling(){if(assert(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const i=this.indexes[this.indexes.length-1]+1,c=this.parents[this.parents.length-1];return i>=c.length?!1:(assert(!isNaN(i)),this.indexes[this.indexes.length-1]=i,this.container=c[i],!0)}_init(_container,_idx,_parents,_indexes){this.container=_container,this.idx=_idx,this.parents=_parents.slice(),this.indexes=_indexes.slice()}clone(){const c=new _ReadCursor;return c._init(this.container,this.idx,this.parents,this.indexes),c}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(w,fn){const c=this.getComponent();c&&fn(c,w);for(const key of this)w&&w.descend(key),this.traverse(w,fn),w&&w.ascend()}eachPick(w,fn){this.traverse(w,(c,w2)=>{c.p!=null&&fn(c.p,w2)})}eachDrop(w,fn){this.traverse(w,(c,w2)=>{c.d!=null&&fn(c.d,w2)})}};__name(_ReadCursor,"ReadCursor");let ReadCursor=_ReadCursor;exports2.ReadCursor=ReadCursor;const _WriteCursor=class _WriteCursor extends Cursor{constructor(op=null){super(op),this.pendingDescent=[],this._op=op}flushDescent(){assert(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let j=0;j<this.pendingDescent.length;j++){const k=this.pendingDescent[j];let i=this.idx+1;if(i<this.container.length&&isObject(this.container[i])&&i++,assert(i===this.container.length||!isObject(this.container[i])),i===this.container.length)this.container.push(k),this.idx=i;else if(this.container[i]===k)this.idx=i;else{if(!Array.isArray(this.container[i])){const oldChild=this.container.splice(i,this.container.length-i);this.container.push(oldChild),this.lcIdx>-1&&(this.lcIdx=i)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(assert(isGreaterKey(k,this.container[this.lcIdx][0])),i=this.lcIdx+1,this.lcIdx=-1);i<this.container.length&&isGreaterKey(k,this.container[i][0]);)i++;if(this.indexes.push(i),this.idx=0,i<this.container.length&&this.container[i][0]===k)this.container=this.container[i];else{const child=[k];this.container.splice(i,0,child),this.container=child}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const i=this.idx+1;if(i<this.container.length&&isObject(this.container[i]))return this.container[i];{const component={};return this.container.splice(i,0,component),component}}write(key,value){const component=this.getComponent();assert(component[key]==null||component[key]===value,"Internal consistency error: Overwritten component. File a bug"),component[key]=value}get(){return this._op}descend(key){if(!exports2.isValidPathItem(key))throw Error("Invalid JSON key");this.pendingDescent.push(key)}descendPath(path){return this.pendingDescent.push(...path),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(data,mergeFn=copyAll){if(data===null)return;if(assert(Array.isArray(data)),data===this._op)throw Error("Cannot merge into my own tree");const _lcIdx=this.lcIdx,oldDepth=this.parents.length;let depth=0;for(let i=0;i<data.length;i++){const c=data[i];typeof c=="string"||typeof c=="number"?(depth++,this.descend(c)):Array.isArray(c)?this.mergeTree(c,mergeFn):typeof c=="object"&&mergeFn(c,this)}for(;depth--;)this.ascend();this.lcIdx=this.parents.length===oldDepth?_lcIdx:-1}at(path,fn){this.descendPath(path),fn(this);for(let i=0;i<path.length;i++)this.ascend();return this}writeAtPath(path,key,value){return this.at(path,()=>this.write(key,value)),this.reset(),this}writeMove(path1,path2,slot=0){return this.writeAtPath(path1,"p",slot).writeAtPath(path2,"d",slot)}getPath(){const path=super.getPath();return path.push(...this.pendingDescent),path}};__name(_WriteCursor,"WriteCursor");let WriteCursor=_WriteCursor;exports2.WriteCursor=WriteCursor,exports2.writeCursor=()=>new WriteCursor,exports2.readCursor=op=>new ReadCursor(op);function advancer(r,listMap,listAdv){let didDescend,valid;valid=didDescend=r?r.descendFirst():!1;function adv(ktarget){let k2_;for(;valid;){const k2=k2_=r.getKey();if(ktarget!=null){let skip=!1;if(listMap&&typeof k2=="number"&&(k2_=listMap(k2,r.getComponent()),k2_<0&&(k2_=~k2_,skip=!0)),isGreaterKey(k2_,ktarget))return null;if(k2_===ktarget&&!skip)return r}listAdv&&typeof k2_=="number"&&listAdv(k2_,r.getComponent()),valid=r.nextSibling()}return null}return __name(adv,"adv"),adv.end=()=>{didDescend&&r.ascend()},adv}__name(advancer,"advancer"),exports2.advancer=advancer;function eachChildOf(r1,r2,fn){let hasChild1,descended1,hasChild2,descended2;for(hasChild1=descended1=r1&&r1.descendFirst(),hasChild2=descended2=r2&&r2.descendFirst();hasChild1||hasChild2;){let k1=hasChild1?r1.getKey():null,k2=hasChild2?r2.getKey():null;k1!==null&&k2!==null&&(isGreaterKey(k2,k1)?k2=null:k1!==k2&&(k1=null)),fn(k1==null?k2:k1,k1!=null?r1:null,k2!=null?r2:null),k1!=null&&hasChild1&&(hasChild1=r1.nextSibling()),k2!=null&&hasChild2&&(hasChild2=r2.nextSibling())}descended1&&r1.ascend(),descended2&&r2.ascend()}__name(eachChildOf,"eachChildOf"),exports2.eachChildOf=eachChildOf})(cursor);var types={};(function(exports2){Object.defineProperty(exports2,"__esModule",{value:!0}),exports2.ConflictType=void 0,function(ConflictType){ConflictType[ConflictType.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",ConflictType[ConflictType.DROP_COLLISION=2]="DROP_COLLISION",ConflictType[ConflictType.BLACKHOLE=3]="BLACKHOLE"}(exports2.ConflictType||(exports2.ConflictType={}))})(types);var dist={},unicount={},hasRequiredUnicount;function requireUnicount(){return hasRequiredUnicount||(hasRequiredUnicount=1,Object.defineProperty(unicount,"__esModule",{value:!0}),unicount.uniToStrPos=unicount.strPosToUni=void 0,unicount.strPosToUni=(s,strOffset=s.length)=>{let pairs=0,i=0;for(;i<strOffset;i++){const code=s.charCodeAt(i);code>=55296&&code<=57343&&(pairs++,i++)}if(i!==strOffset)throw Error("Invalid offset - splits unicode bytes");return i-pairs},unicount.uniToStrPos=(s,uniOffset)=>{let pos=0;for(;uniOffset>0;uniOffset--){const code=s.charCodeAt(pos);pos+=code>=55296&&code<=57343?2:1}return pos}),unicount}__name(requireUnicount,"requireUnicount");var type={},hasRequiredType;function requireType(){return hasRequiredType||(hasRequiredType=1,function(exports2){Object.defineProperty(exports2,"__esModule",{value:!0}),exports2.uniSlice=exports2.dlen=exports2.eachOp=void 0;const unicount_1=requireUnicount(),checkOp=__name(op=>{if(!Array.isArray(op))throw Error("Op must be an array of components");let last=null;for(let i=0;i<op.length;i++){const c=op[i];switch(typeof c){case"object":if(typeof c.d!="number"&&typeof c.d!="string")throw Error("Delete must be number or string");if(exports2.dlen(c.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(c.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(c>0))throw Error("Skip components must be >0");if(typeof last=="number")throw Error("Adjacent skip components should be combined");break}last=c}if(typeof last=="number")throw Error("Op has a trailing skip")},"checkOp");function eachOp(op,fn){let prePos=0,postPos=0;for(let i=0;i<op.length;i++){const c=op[i];switch(fn(c,prePos,postPos),typeof c){case"object":prePos+=exports2.dlen(c.d);break;case"string":postPos+=unicount_1.strPosToUni(c);break;case"number":prePos+=c,postPos+=c;break}}}__name(eachOp,"eachOp"),exports2.eachOp=eachOp;function mapOp(op,fn){const newOp=[],append=makeAppend(newOp);return eachOp(op,(c,prePos,postPos)=>{append(fn(c,prePos,postPos))}),trim(newOp)}__name(mapOp,"mapOp");const id=__name(x=>x,"id"),normalize=__name(op=>mapOp(op,id),"normalize");exports2.dlen=d=>typeof d=="number"?d:unicount_1.strPosToUni(d);const makeAppend=__name(op=>component=>{if(!(!component||component.d===0||component.d===""))if(op.length===0)op.push(component);else if(typeof component==typeof op[op.length-1])if(typeof component=="object"){const last=op[op.length-1];last.d=typeof last.d=="string"&&typeof component.d=="string"?last.d+component.d:exports2.dlen(last.d)+exports2.dlen(component.d)}else op[op.length-1]+=component;else op.push(component)},"makeAppend"),componentLength=__name(c=>typeof c=="number"?c:typeof c=="string"?unicount_1.strPosToUni(c):typeof c.d=="number"?c.d:unicount_1.strPosToUni(c.d),"componentLength");exports2.uniSlice=(s,startUni,endUni)=>{const start=unicount_1.uniToStrPos(s,startUni),end=endUni==null?1/0:unicount_1.uniToStrPos(s,endUni);return s.slice(start,end)};const dslice=__name((d,start,end)=>typeof d=="number"?end==null?d-start:Math.min(d,end)-start:exports2.uniSlice(d,start,end),"dslice"),makeTake=__name(op=>{let idx=0,offset=0;return{take:__name((n,indivisableField)=>{if(idx===op.length)return n===-1?null:n;const c=op[idx];let part;if(typeof c=="number")return n===-1||c-offset<=n?(part=c-offset,++idx,offset=0,part):(offset+=n,n);if(typeof c=="string"){if(n===-1||indivisableField==="i"||unicount_1.strPosToUni(c.slice(offset))<=n)return part=c.slice(offset),++idx,offset=0,part;{const offset2=offset+unicount_1.uniToStrPos(c.slice(offset),n);return part=c.slice(offset,offset2),offset=offset2,part}}else{if(n===-1||indivisableField==="d"||exports2.dlen(c.d)-offset<=n)return part={d:dslice(c.d,offset)},++idx,offset=0,part;{let result=dslice(c.d,offset,offset+n);return offset+=n,{d:result}}}},"take"),peek:__name(()=>op[idx],"peek")}},"makeTake"),trim=__name(op=>(op.length>0&&typeof op[op.length-1]=="number"&&op.pop(),op),"trim");function transform(op1,op2,side){if(side!=="left"&&side!=="right")throw Error("side ("+side+") must be 'left' or 'right'");checkOp(op1),checkOp(op2);const newOp=[],append=makeAppend(newOp),{take,peek}=makeTake(op1);for(let i=0;i<op2.length;i++){const c2=op2[i];let length,c1;switch(typeof c2){case"number":for(length=c2;length>0;)c1=take(length,"i"),append(c1),typeof c1!="string"&&(length-=componentLength(c1));break;case"string":side==="left"&&typeof peek()=="string"&&append(take(-1)),append(unicount_1.strPosToUni(c2));break;case"object":for(length=exports2.dlen(c2.d);length>0;)switch(c1=take(length,"i"),typeof c1){case"number":length-=c1;break;case"string":append(c1);break;case"object":length-=exports2.dlen(c1.d)}break}}let c;for(;c=take(-1);)append(c);return trim(newOp)}__name(transform,"transform");function compose(op1,op2){checkOp(op1),checkOp(op2);const result=[],append=makeAppend(result),{take}=makeTake(op1);for(let i=0;i<op2.length;i++){const component=op2[i];let length,chunk;switch(typeof component){case"number":for(length=component;length>0;)chunk=take(length,"d"),append(chunk),typeof chunk!="object"&&(length-=componentLength(chunk));break;case"string":append(component);break;case"object":length=exports2.dlen(component.d);let offset=0;for(;offset<length;)switch(chunk=take(length-offset,"d"),typeof chunk){case"number":append({d:dslice(component.d,offset,offset+chunk)}),offset+=chunk;break;case"string":offset+=unicount_1.strPosToUni(chunk);break;case"object":append(chunk)}break}}let c;for(;c=take(-1);)append(c);return trim(result)}__name(compose,"compose");const transformPosition=__name((cursor2,op)=>{let pos=0;for(let i=0;i<op.length&&cursor2>pos;i++){const c=op[i];switch(typeof c){case"number":{pos+=c;break}case"string":const offset=unicount_1.strPosToUni(c);pos+=offset,cursor2+=offset;break;case"object":cursor2-=Math.min(exports2.dlen(c.d),cursor2-pos);break}}return cursor2},"transformPosition"),transformSelection=__name((selection,op)=>typeof selection=="number"?transformPosition(selection,op):selection.map(s=>transformPosition(s,op)),"transformSelection");function makeInvertible(op,doc,ropeImpl){return mapOp(op,(c,prePos)=>typeof c=="object"&&typeof c.d=="number"?{d:ropeImpl.slice(doc,prePos,prePos+c.d)}:c)}__name(makeInvertible,"makeInvertible");function invert(op){return mapOp(op,c=>{switch(typeof c){case"object":if(typeof c.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return c.d;case"string":return{d:c};case"number":return c}})}__name(invert,"invert");function stripInvertible(op){return mapOp(op,c=>typeof c=="object"&&typeof c.d=="string"?{d:unicount_1.strPosToUni(c.d)}:c)}__name(stripInvertible,"stripInvertible");function isInvertible(op){let invertible=!0;return eachOp(op,c=>{typeof c=="object"&&typeof c.d=="number"&&(invertible=!1)}),invertible}__name(isInvertible,"isInvertible");function makeType(ropeImpl){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim,normalize,checkOp,create(initial=""){if(typeof initial!="string")throw Error("Initial data must be a string");return ropeImpl.create(initial)},apply(str,op){checkOp(op);const builder=ropeImpl.builder(str);for(let i=0;i<op.length;i++){const component=op[i];switch(typeof component){case"number":builder.skip(component);break;case"string":builder.append(component);break;case"object":builder.del(exports2.dlen(component.d));break}}return builder.build()},transform,compose,transformPosition,transformSelection,isInvertible,makeInvertible(op,doc){return makeInvertible(op,doc,ropeImpl)},stripInvertible,invert,invertWithDoc(op,doc){return invert(makeInvertible(op,doc,ropeImpl))},isNoop:__name(op=>op.length===0,"isNoop")}}__name(makeType,"makeType"),exports2.default=makeType}(type)),type}__name(requireType,"requireType");var api={},hasRequiredApi;function requireApi(){if(hasRequiredApi)return api;hasRequiredApi=1,Object.defineProperty(api,"__esModule",{value:!0});const type_1=requireType(),unicount_1=requireUnicount();function api$1(getSnapshot,submitOp){return{get:getSnapshot,getLength(){return getSnapshot().length},insert(pos,text,callback){const uniPos=unicount_1.strPosToUni(getSnapshot(),pos);return submitOp([uniPos,text],callback)},remove(pos,lengthOrContent,callback){const uniPos=unicount_1.strPosToUni(getSnapshot(),pos);return submitOp([uniPos,{d:lengthOrContent}],callback)},_onOp(op){type_1.eachOp(op,(component,prePos,postPos)=>{switch(typeof component){case"string":this.onInsert&&this.onInsert(postPos,component);break;case"object":const dl=type_1.dlen(component.d);this.onRemove&&this.onRemove(postPos,dl)}})},onInsert:null,onRemove:null}}return __name(api$1,"api$1"),api.default=api$1,api$1.provides={text:!0},api}__name(requireApi,"requireApi");var hasRequiredDist;function requireDist(){return hasRequiredDist||(hasRequiredDist=1,function(exports2){var __createBinding=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(o,m,k,k2){k2===void 0&&(k2=k),Object.defineProperty(o,k2,{enumerable:!0,get:__name(function(){return m[k]},"get")})}:function(o,m,k,k2){k2===void 0&&(k2=k),o[k2]=m[k]}),__setModuleDefault=commonjsGlobal&&commonjsGlobal.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=commonjsGlobal&&commonjsGlobal.__importStar||function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null)for(var k in mod)Object.hasOwnProperty.call(mod,k)&&__createBinding(result,mod,k);return __setModuleDefault(result,mod),result},__importDefault=commonjsGlobal&&commonjsGlobal.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports2,"__esModule",{value:!0}),exports2.type=exports2.remove=exports2.insert=void 0;const unicount_1=requireUnicount(),type_1=__importStar(requireType()),api_1=__importDefault(requireApi()),ropeImplUnicodeString={create(s){return s},toString(s){return s},builder(oldDoc){if(typeof oldDoc!="string")throw Error("Invalid document snapshot: "+oldDoc);const newDoc=[];return{skip(n){let offset=unicount_1.uniToStrPos(oldDoc,n);if(offset>oldDoc.length)throw Error("The op is too long for this document");newDoc.push(oldDoc.slice(0,offset)),oldDoc=oldDoc.slice(offset)},append(s){newDoc.push(s)},del(n){oldDoc=oldDoc.slice(unicount_1.uniToStrPos(oldDoc,n))},build(){return newDoc.join("")+oldDoc}}},slice:type_1.uniSlice},textString=type_1.default(ropeImplUnicodeString),type2=Object.assign(Object.assign({},textString),{api:api_1.default});exports2.type=type2,exports2.insert=(pos,text)=>text.length===0?[]:pos===0?[text]:[pos,text],exports2.remove=(pos,textOrLen)=>type_1.dlen(textOrLen)===0?[]:pos===0?[{d:textOrLen}]:[pos,{d:textOrLen}];var type_2=requireType();Object.defineProperty(exports2,"makeType",{enumerable:!0,get:__name(function(){return type_2.default},"get")})}(dist)),dist}__name(requireDist,"requireDist");(function(exports2){var __importDefault=commonjsGlobal&&commonjsGlobal.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports2,"__esModule",{value:!0}),exports2.editOp=exports2.replaceOp=exports2.insertOp=exports2.moveOp=exports2.removeOp=exports2.type=void 0;const deepEqual_js_1=__importDefault(deepEqual$1),deepClone_js_1=__importDefault(deepClone$1),cursor_js_1=cursor,types_js_1=types;function assert(pred,msg){if(!pred)throw new Error(msg)}__name(assert,"assert"),exports2.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:cursor_js_1.readCursor,writeCursor:cursor_js_1.writeCursor,create:__name(data=>data,"create"),isNoop:__name(op=>op==null,"isNoop"),setDebug(val){},registerSubtype,checkValidOp,normalize,apply,transformPosition,compose,tryTransform,transform,makeInvertible,invert,invertWithDoc,RM_UNEXPECTED_CONTENT:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:types_js_1.ConflictType.DROP_COLLISION,BLACKHOLE:types_js_1.ConflictType.BLACKHOLE,transformNoConflict:__name((op1,op2,side)=>transformWithConflictsPred(()=>!0,op1,op2,side),"transformNoConflict"),typeAllowingConflictsPred:__name(allowConflict=>Object.assign(Object.assign({},exports2.type),{transform:__name((op1,op2,side)=>transformWithConflictsPred(allowConflict,op1,op2,side),"transform")}),"typeAllowingConflictsPred")};const getComponent=__name(r=>r?r.getComponent():null,"getComponent");function isObject(o){return o&&typeof o=="object"&&!Array.isArray(o)}__name(isObject,"isObject");const shallowClone=__name(obj=>Array.isArray(obj)?obj.slice():obj!==null&&typeof obj=="object"?Object.assign({},obj):obj,"shallowClone"),hasPick=__name(c=>c&&(c.p!=null||c.r!==void 0),"hasPick"),hasDrop=__name(c=>c&&(c.d!=null||c.i!==void 0),"hasDrop");function removeChild(container,key){return assert(container!=null),typeof key=="number"?(assert(Array.isArray(container),"Invalid key - child is not an array"),(container=container.slice()).splice(key,1)):(assert(isObject(container),"Invalid key - child is not an object"),delete(container=Object.assign({},container))[key]),container}__name(removeChild,"removeChild");function insertChildMut(container,key,value){return typeof key=="number"?(assert(container!=null,"Container is missing for key"),assert(Array.isArray(container),"Cannot use numerical key for object container"),assert(container.length>=key,"Cannot insert into out of bounds index"),container.splice(key,0,value)):(assert(isObject(container),"Cannot insert into missing item"),assert(container[key]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),container[key]=value),value}__name(insertChildMut,"insertChildMut"),exports2.removeOp=(path,value=!0)=>cursor_js_1.writeCursor().writeAtPath(path,"r",value).get(),exports2.moveOp=(from,to)=>cursor_js_1.writeCursor().writeMove(from,to).get(),exports2.insertOp=(path,value)=>cursor_js_1.writeCursor().writeAtPath(path,"i",value).get(),exports2.replaceOp=(path,oldVal,newVal)=>cursor_js_1.writeCursor().at(path,w=>{w.write("r",oldVal),w.write("i",newVal)}).get(),exports2.editOp=(path,type2,subOp,preserveNoop=!1)=>cursor_js_1.writeCursor().at(path,w=>writeEdit(w,type2,subOp,preserveNoop)).get();const isValidKey=__name((container,key)=>container!=null&&(typeof key=="number"?Array.isArray(container):typeof container=="object"),"isValidKey"),maybeGetChild=__name((container,key)=>isValidKey(container,key)?container[key]:void 0,"maybeGetChild"),subtypes={};function registerSubtype(subtype){let _subtype=subtype.type?subtype.type:subtype;_subtype.name&&(subtypes[_subtype.name]=_subtype),_subtype.uri&&(subtypes[_subtype.uri]=_subtype)}__name(registerSubtype,"registerSubtype");const typeOrThrow=__name(name=>{const type2=subtypes[name];if(type2)return type2;throw Error("Missing type: "+name)},"typeOrThrow");registerSubtype(requireDist());const add=__name((a,b)=>a+b,"add");registerSubtype({name:"number",apply:add,compose:add,invert:__name(n=>-n,"invert"),transform:__name(a=>a,"transform")});const getEditType=__name(c=>c==null?null:c.et?typeOrThrow(c.et):c.es?subtypes["text-unicode"]:c.ena!=null?subtypes.number:null,"getEditType"),getEdit=__name(c=>c.es?c.es:c.ena!=null?c.ena:c.e,"getEdit"),writeEdit=__name((w,typeOrName,edit,preserveNoop=!1)=>{const[type2,name]=typeof typeOrName=="string"?[typeOrThrow(typeOrName),typeOrName]:[typeOrName,typeOrName.name];!preserveNoop&&type2.isNoop&&type2.isNoop(edit)||(name==="number"?w.write("ena",edit):name==="text-unicode"?w.write("es",edit):(w.write("et",name),w.write("e",edit)))},"writeEdit");function checkNonNegInteger(n){assert(typeof n=="number"),assert(n>=0),assert(n===(0|n))}__name(checkNonNegInteger,"checkNonNegInteger");function checkScalar(s){typeof s=="number"?checkNonNegInteger(s):assert(typeof s=="string")}__name(checkScalar,"checkScalar");function checkValidOp(op){if(op===null)return;const pickedSlots=new Set,droppedSlots=new Set,checkComponent=__name(e=>{let empty=!0,hasEdit=!1;for(let k in e){const v=e[k];if(empty=!1,assert(k==="p"||k==="r"||k==="d"||k==="i"||k==="e"||k==="es"||k==="ena"||k==="et","Invalid component item '"+k+"'"),k==="p")checkNonNegInteger(v),assert(!pickedSlots.has(v)),pickedSlots.add(v),assert(e.r===void 0);else if(k==="d")checkNonNegInteger(v),assert(!droppedSlots.has(v)),droppedSlots.add(v),assert(e.i===void 0);else if(k==="e"||k==="es"||k==="ena"){assert(!hasEdit),hasEdit=!0;const t=getEditType(e);assert(t,"Missing type in edit"),t.checkValidOp&&t.checkValidOp(getEdit(e))}}assert(!empty)},"checkComponent"),checkDescent=__name((descent,isRoot,removed)=>{if(!Array.isArray(descent))throw Error("Op must be null or a list");if(descent.length===0)throw Error("Empty descent");isRoot||checkScalar(descent[0]);let last=1,numDescents=0,lastKey=0;for(let i=0;i<descent.length;i++){const d=descent[i];if(assert(d!=null),Array.isArray(d)){const key=checkDescent(d,!1);if(numDescents){const t1=typeof lastKey,t2=typeof key;t1===t2?assert(lastKey<key,"descent keys are not in order"):assert(t1==="number"&&t2==="string")}lastKey=key,numDescents++,last=3}else typeof d=="object"?(assert(last===1,`Prev not scalar - instead ${last}`),checkComponent(d),last=2):(assert(last!==3),checkScalar(d),assert(cursor_js_1.isValidPathItem(d),"Invalid path key"),last=1)}return assert(numDescents!==1,"Operation makes multiple descents. Remove some []"),assert(last===2||last===3),descent[0]},"checkDescent");checkDescent(op,!0),assert(pickedSlots.size===droppedSlots.size,"Mismatched picks and drops in op");for(let i=0;i<pickedSlots.size;i++)assert(pickedSlots.has(i)),assert(droppedSlots.has(i))}__name(checkValidOp,"checkValidOp");function normalize(op){let nextSlot=0,slotMap=[];const w=cursor_js_1.writeCursor();return w.mergeTree(op,(c,w2)=>{const t=getEditType(c);if(t){const op2=getEdit(c);writeEdit(w2,t,t.normalize?t.normalize(op2):op2)}for(const k of["r","p","i","d"])if(c[k]!==void 0){const r=k==="p"||k==="d"?(inSlot=c[k],slotMap[inSlot]==null&&(slotMap[inSlot]=nextSlot++),slotMap[inSlot]):c[k];w2.write(k,r)}var inSlot}),w.get()}__name(normalize,"normalize");function apply(snapshot,op){if(checkValidOp(op),op===null)return snapshot;const held=[];return __name(function drop(root,descent){let subDoc=root,i=0,rootContainer={root},m=0,container=rootContainer,key="root";function mut(){for(;m<i;m++){let d=descent[m];typeof d!="object"&&(assert(isValidKey(container,key)),container=container[key]=shallowClone(container[key]),key=d)}}for(__name(mut,"mut");i<descent.length;i++){const d=descent[i];if(Array.isArray(d)){const child=drop(subDoc,d);child!==subDoc&&child!==void 0&&(mut(),subDoc=container[key]=child)}else if(typeof d=="object"){d.d!=null?(mut(),subDoc=insertChildMut(container,key,held[d.d])):d.i!==void 0&&(mut(),subDoc=insertChildMut(container,key,d.i));const t=getEditType(d);if(t)mut(),subDoc=container[key]=t.apply(subDoc,getEdit(d));else if(d.e!==void 0)throw Error("Subtype "+d.et+" undefined")}else subDoc=maybeGetChild(subDoc,d)}return rootContainer.root},"drop")(snapshot=__name(function pick(subDoc,descent){const stack=[];let i=0;for(;i<descent.length;i++){const d=descent[i];if(Array.isArray(d))break;typeof d!="object"&&(stack.push(subDoc),subDoc=maybeGetChild(subDoc,d))}for(let j=descent.length-1;j>=i;j--)subDoc=pick(subDoc,descent[j]);for(--i;i>=0;i--){const d=descent[i];if(typeof d!="object"){const container=stack.pop();subDoc=subDoc===maybeGetChild(container,d)?container:subDoc===void 0?removeChild(container,d):(k=d,v=subDoc,(obj=shallowClone(obj=container))[k]=v,obj)}else hasPick(d)&&(assert(subDoc!==void 0,"Cannot pick up or remove undefined"),d.p!=null&&(held[d.p]=subDoc),subDoc=void 0)}var obj,k,v;return subDoc},"pick")(snapshot,op),op)}__name(apply,"apply");function transformPosition(path,op){path=path.slice(),checkValidOp(op);const r=cursor_js_1.readCursor(op);let pickedAtSlot,pickIndex,removed=!1;const advStack=[];for(let i=0;;i++){const k=path[i],c=r.getComponent();if(c&&(c.r!==void 0?removed=!0:c.p!=null&&(removed=!1,pickedAtSlot=c.p,pickIndex=i)),i>=path.length)break;let pickOffset=0;const pickAdv=cursor_js_1.advancer(r,void 0,(k2,c2)=>{hasPick(c2)&&pickOffset++});advStack.unshift(pickAdv);const hasNext=pickAdv(k);if(typeof k=="number"&&(path[i]-=pickOffset),!hasNext)break}if(advStack.forEach(pickAdv=>pickAdv.end()),removed)return null;const handleDrop=__name(()=>{let i=0;if(pickedAtSlot!=null){const rPath=r.getPath();i=rPath.length,path=rPath.concat(path.slice(pickIndex))}for(;i<path.length;i++){const k=path[i],c=getComponent(r),et=getEditType(c);if(et){const e=getEdit(c);et.transformPosition&&(path[i]=et.transformPosition(path[i],e));break}let dropOffset=0;const hasNext=cursor_js_1.advancer(r,(k2,c2)=>hasDrop(c2)?~(k2-dropOffset):k2-dropOffset,(k2,c2)=>{hasDrop(c2)&&dropOffset++})(k);if(typeof k=="number"&&(path[i]+=dropOffset),!hasNext)break}},"handleDrop");return pickedAtSlot!=null?r.eachDrop(null,slot=>{slot===pickedAtSlot&&handleDrop()}):handleDrop(),path}__name(transformPosition,"transformPosition");function compose(op1,op2){if(checkValidOp(op1),checkValidOp(op2),op1==null)return op2;if(op2==null)return op1;let nextSlot=0;const r1=cursor_js_1.readCursor(op1),r2=cursor_js_1.readCursor(op2),w=cursor_js_1.writeCursor(),heldPickWrites=[],heldDropWrites=[],held1Pick=[],held2Drop=[],p1SlotMap=[],p2SlotMap=[],visitedOp2EditCs=new Set;r1.traverse(null,c=>{c.p!=null&&(held1Pick[c.p]=r1.clone())}),r2.traverse(null,c=>{c.d!=null&&(held2Drop[c.d]=r2.clone())});const w2=cursor_js_1.writeCursor();return __name(function xfBoundary(r1Pick,r1Drop,r2Pick,r2Drop,litIn,rmParent,wd,wp){assert(r1Drop||r2Pick);const c1d=getComponent(r1Drop),c2p=getComponent(r2Pick),rmHere=!!c2p&&c2p.r!==void 0,insHere=!!c1d&&c1d.i!==void 0,drop1Slot=c1d?c1d.d:null,pick2Slot=c2p?c2p.p:null,rmChildren=(rmParent||rmHere)&&pick2Slot==null;if(pick2Slot!=null)r2Drop=held2Drop[pick2Slot],wd=heldDropWrites[pick2Slot]=new cursor_js_1.WriteCursor;else if(c2p&&c2p.r!==void 0)r2Drop=null;else{const c2d2=getComponent(r2Drop);c2d2&&c2d2.d!=null&&(r2Drop=null)}const c2d=getComponent(r2Drop);if(drop1Slot!=null)if(r1Pick=held1Pick[drop1Slot],wp=heldPickWrites[drop1Slot]=new cursor_js_1.WriteCursor,rmChildren)rmParent&&!rmHere&&wp.write("r",!0);else{const slot=p1SlotMap[drop1Slot]=nextSlot++;wd.write("d",slot)}else if(c1d&&c1d.i!==void 0)r1Pick=null;else{const c1p=getComponent(r1Pick);c1p&&c1p.p!=null&&(r1Pick=null)}let litOut;insHere?(assert(litIn===void 0),litOut=c1d.i):litOut=litIn;const insComponent=(pick2Slot==null?!insHere||rmParent||rmHere:litOut===void 0)?null:wd.getComponent();if(pick2Slot!=null){if(!(litIn!==void 0||insHere)){const slot=drop1Slot!=null?p1SlotMap[drop1Slot]:nextSlot++;p2SlotMap[pick2Slot]=slot,wp.write("p",slot)}}else rmHere&&(insHere||litIn!==void 0||(c2p.r,wp.write("r",c2p.r)));const type1=rmChildren?null:getEditType(c1d),type2=getEditType(c2d);if((type1||type2)&&(type1&&type1.name,type2&&type2.name),type1&&type2){assert(type1===type2);const e1=getEdit(c1d),e2=getEdit(c2d),r=type1.compose(e1,e2);writeEdit(wd,type1,r),visitedOp2EditCs.add(c2d)}else type1?writeEdit(wd,type1,getEdit(c1d)):type2&&(writeEdit(wd,type2,getEdit(c2d)),visitedOp2EditCs.add(c2d));const hasContainerLiteral=typeof litOut=="object"&&litOut!=null;let isCloned=!1,p1PickOff=0,p1DropOff=0,p2PickOff=0,p2DropOff=0,litOff=0;const p2DropAdv=cursor_js_1.advancer(r2Drop,(k,c)=>hasDrop(c)?p2DropOff-k-1:k-p2DropOff,(k,c)=>{hasDrop(c)&&p2DropOff++}),p1PickAdv=cursor_js_1.advancer(r1Pick,(k,c)=>hasPick(c)?p1PickOff-k-1:k-p1PickOff,(k,c)=>{hasPick(c)&&p1PickOff++});if(cursor_js_1.eachChildOf(r1Drop,r2Pick,(inKey,_p1Drop,_p2Pick)=>{let _p1Pick,_p2Drop,p1PickKey=inKey,p2DropKey=inKey,litKey=inKey;if(typeof inKey=="number"){let p2Mid=inKey+p2PickOff;_p2Drop=p2DropAdv(p2Mid),p2DropKey=p2Mid+p2DropOff;let p1Mid=inKey+p1DropOff;_p1Pick=p1PickAdv(p1Mid),hasDrop(getComponent(_p2Drop))&&(_p1Pick=null),p1PickKey=p1Mid+p1PickOff,litKey=inKey+litOff,assert(p1PickKey>=0,"p1PickKey is negative"),assert(p2DropKey>=0,"p2DropKey is negative");const hd1=hasDrop(getComponent(_p1Drop)),hp2=hasPick(getComponent(_p2Pick));(hd1||hp2&&!rmChildren)&&litOff--,hd1&&p1DropOff--,hp2&&p2PickOff--}else _p1Pick=p1PickAdv(inKey),_p2Drop=p2DropAdv(inKey);wp.descend(p1PickKey),wd.descend(p2DropKey);const _lit=hasContainerLiteral&&!hasDrop(getComponent(_p1Drop))?litOut[litKey]:void 0,_litResult=xfBoundary(_p1Pick,_p1Drop,_p2Pick,_p2Drop,_lit,rmChildren,wd,wp);var container,key,child;hasContainerLiteral&&!rmChildren?_lit!==_litResult&&(isCloned||(litOut=Array.isArray(litOut)?litOut.slice():Object.assign({},litOut),isCloned=!0),container=litOut,child=_litResult,typeof(key=litKey)=="number"?(assert(Array.isArray(container)),assert(key<container.length)):(assert(!Array.isArray(container)),assert(container[key]!==void 0)),child===void 0?typeof key=="number"?container.splice(key,1):delete container[key]:container[key]=child):assert(_litResult===void 0),wd.ascend(),wp.ascend()}),p1PickAdv.end(),p2DropAdv.end(),insComponent!=null)insComponent.i=litOut;else if(!rmParent&&!rmHere&&pick2Slot==null)return litOut},"xfBoundary")(r1,r1.clone(),r2,r2.clone(),void 0,!1,w,w2),w.reset(),w.mergeTree(w2.get()),w.reset(),w.get(),heldPickWrites.map(w3=>w3.get()),heldDropWrites.map(w3=>w3.get()),r1.traverse(w,(c,w3)=>{const slot1=c.p;if(slot1!=null){const slot=p1SlotMap[slot1];slot!=null&&w3.write("p",slot);const _w=heldPickWrites[slot1];_w&&_w.get(),_w&&w3.mergeTree(_w.get())}else c.r!==void 0&&w3.write("r",c.r)}),w.reset(),w.get(),r2.traverse(w,(c,w3)=>{const slot2=c.d;if(slot2!=null){const slot=p2SlotMap[slot2];slot!=null&&w3.write("d",slot);const _w=heldDropWrites[slot2];_w&&w3.mergeTree(_w.get())}else c.i!==void 0&&w3.write("i",c.i);const t=getEditType(c);t&&!visitedOp2EditCs.has(c)&&writeEdit(w3,t,getEdit(c))}),w.get()}__name(compose,"compose");function invert(op){if(op==null)return null;const r=new cursor_js_1.ReadCursor(op),w=new cursor_js_1.WriteCursor;let editsToTransform;const heldPick=[],heldWrites=[];return __name(function invertSimple(r2,w2,subDoc){const c=r2.getComponent();let insertHere,subdocModified=!1;if(c){c.p!=null&&(w2.write("d",c.p),heldPick[c.p]=r2.clone()),c.r!==void 0&&w2.write("i",c.r),c.d!=null&&(w2.write("p",c.d),subDoc=void 0),c.i!==void 0&&(subDoc=insertHere=c.i);const t=getEditType(c);t&&(subDoc===void 0?(editsToTransform||(editsToTransform=new Set),editsToTransform.add(c)):(getEdit(c),subDoc=t.apply(subDoc,getEdit(c)),subdocModified=!0))}let dropOff=0;for(const key of r2){w2.descend(key);const raw=typeof key=="number"?key-dropOff:key,childIn=maybeGetChild(subDoc,raw);hasDrop(r2.getComponent())&&dropOff++;const childOut=invertSimple(r2,w2,childIn);if(subDoc!==void 0&&childOut!==void 0){if(subdocModified||(subdocModified=!0,subDoc=shallowClone(subDoc)),!isValidKey(subDoc,raw))throw Error("Cannot modify child - invalid operation");subDoc[raw]=childOut}w2.ascend()}if(insertHere===void 0)return subdocModified?subDoc:void 0;w2.write("r",subDoc)},"invertSimple")(r,w,void 0),editsToTransform&&(w.reset(),__name(function transformEdits(rPick,rDrop,w2){const cd=rDrop.getComponent();if(cd){const dropSlot=cd.d;if(dropSlot!=null&&(rPick=heldPick[dropSlot],w2=heldWrites[dropSlot]=cursor_js_1.writeCursor()),editsToTransform.has(cd)){const t=getEditType(cd);if(!t.invert)throw Error(`Cannot invert subtype ${t.name}`);writeEdit(w2,t,t.invert(getEdit(cd)))}}let pickOff=0,dropOff=0;const ap=cursor_js_1.advancer(rPick,(k,c)=>hasPick(c)?pickOff-k-1:k-pickOff,(k,c)=>{hasPick(c)&&pickOff++});for(const key of rDrop)if(typeof key=="number"){const mid=key-dropOff,_rPick=ap(mid),raw=mid+pickOff;w2.descend(raw),transformEdits(_rPick,rDrop,w2),hasDrop(rDrop.getComponent())&&dropOff++,w2.ascend()}else w2.descend(key),transformEdits(ap(key),rDrop,w2),w2.ascend();ap.end()},"transformEdits")(r.clone(),r,w),heldWrites.length&&(w.reset(),r.traverse(w,(c,w2)=>{const slot=c.p;if(slot!=null){const _w=heldWrites[slot];_w&&_w.get(),_w&&w2.mergeTree(_w.get())}}))),w.get()}__name(invert,"invert");const anyComponent=__name((op,fn)=>op.some(c=>typeof c=="object"&&(Array.isArray(c)?anyComponent(c,fn):fn(c))),"anyComponent");function makeInvertible(op,doc){if(op==null||!anyComponent(op,c=>{var _a2;return c.r!==void 0||((_a2=getEditType(c))===null||_a2===void 0?void 0:_a2.makeInvertible)!=null}))return op;const r=new cursor_js_1.ReadCursor(op),w=new cursor_js_1.WriteCursor;let hasEdits=!1;const heldPick=[],heldDoc=[],traversePick=__name((r2,w2,subDoc)=>{const c=r2.getComponent();let modified=!1;if(c){c.d!=null&&w2.write("d",c.d),c.i!==void 0&&w2.write("i",c.i);const pickSlot=c.p;if(pickSlot!=null&&(heldPick[pickSlot]=r2.clone(),assert(subDoc!==void 0,"Operation picks up at an invalid key"),heldDoc[pickSlot]=subDoc,w2.write("p",c.p)),c.r!==void 0&&subDoc===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const t=getEditType(c);t&&(t.makeInvertible?hasEdits=!0:writeEdit(w2,t,getEdit(c),!0))}let listOff=0;for(const key of r2){w2.descend(key);const keyRaw=typeof key=="number"?key-listOff:key,childIn=maybeGetChild(subDoc,keyRaw),childOut=traversePick(r2,w2,childIn);childIn!==childOut&&(modified||(modified=!0,subDoc=shallowClone(subDoc)),childOut===void 0?(subDoc=removeChild(subDoc,keyRaw),typeof key=="number"&&listOff++):subDoc[keyRaw]=childOut),w2.ascend()}return c&&(c.r!==void 0?(w2.write("r",deepClone_js_1.default(subDoc)),subDoc=void 0):c.p!=null&&(subDoc=void 0)),subDoc},"traversePick");return traversePick(r,w,doc),w.get(),hasEdits&&(w.reset(),__name(function traverseDrop(rPick,rDrop,w2,subDoc,isLiteral){const c=rDrop.getComponent();if(c){c.i!==void 0?(subDoc=c.i,isLiteral=!0):c.d!=null&&(subDoc=heldDoc[c.d],rPick=heldPick[c.d],isLiteral=!1,c.d);let t=getEditType(c);if(t&&t.makeInvertible){const edit=getEdit(c);writeEdit(w2,t,t.makeInvertible(edit,subDoc),!0)}}let pickOff=0,dropOff=0;const ap=cursor_js_1.advancer(rPick,(k,c2)=>hasPick(c2)?pickOff-k-1:k-pickOff,(k,c2)=>{hasPick(c2)&&pickOff++});for(const key of rDrop)if(typeof key=="number"){const mid=key-dropOff,_rPick=ap(mid),raw=mid+pickOff,child=maybeGetChild(subDoc,isLiteral?mid:raw);w2.descend(key),traverseDrop(_rPick,rDrop,w2,child,isLiteral),hasDrop(rDrop.getComponent())&&dropOff++,w2.ascend()}else{const child=maybeGetChild(subDoc,key);w2.descend(key),traverseDrop(ap(key),rDrop,w2,child,isLiteral),w2.ascend()}ap.end()},"traverseDrop")(r.clone(),r,w,doc,!1)),w.get()}__name(makeInvertible,"makeInvertible");function invertWithDoc(op,doc){return invert(makeInvertible(op,doc))}__name(invertWithDoc,"invertWithDoc");const shallowCloneOp=__name(op=>{if(op==null)return null;const result=op.slice();for(let i=0;i<op.length;i++){const c=result[i];Array.isArray(c)&&(result[i]=shallowCloneOp(c))}return result},"shallowCloneOp");function tryTransform(op1,op2,direction){assert(direction==="left"||direction==="right","Direction must be left or right");const side=direction==="left"?0:1;if(op2==null)return{ok:!0,result:op1};checkValidOp(op1),checkValidOp(op2);let conflict=null;const heldOp1PickByOp1=[],heldOp1DropByOp1=[],heldOp2PickByOp2=[],heldOp2DropByOp2=[],heldOp1PickByOp2=[],heldOp2PickByOp1=[],heldOp2DropByOp1=[],heldOp2RmForOp1=[],heldOp1RmForOp2=[],cancelledOp2=[],discardedOp2Drop=[],heldPickWrites=[],heldDropWrites=[],op1PickAtOp2Pick=[],op1PicksOp2DropSlots=[];let nextSlot=0;const r1=cursor_js_1.readCursor(op1),r2=cursor_js_1.readCursor(op2),w=cursor_js_1.writeCursor();if(__name(function scanOp2Pick(r2Pick,r1Pick=null,removed1){const c1=getComponent(r1Pick);c1&&(c1.r!==void 0?removed1=r1Pick.clone():c1.p!=null&&(removed1=null,heldOp2PickByOp1[c1.p]=r2Pick.clone()));const c2=r2Pick.getComponent();let slot2;c2&&(slot2=c2.p)!=null&&(heldOp1PickByOp2[slot2]=r1Pick?r1Pick.clone():null,heldOp2PickByOp2[slot2]=r2Pick.clone(),removed1&&(cancelledOp2[slot2]=!0,heldOp1RmForOp2[slot2]=removed1),c1&&c1.p!=null&&(op1PickAtOp2Pick[slot2]=c1.p));const ap1=cursor_js_1.advancer(r1Pick);for(const key of r2Pick)scanOp2Pick(r2Pick,ap1(key),removed1);ap1.end()},"scanOp2Pick")(r2,r1,null),__name(function scanOp2Drop(r1Pick,r2Pick,r2Drop,pickSlot1,removed1){const c2d=r2Drop.getComponent();let slot2,droppedHere=!1;c2d&&((slot2=c2d.d)!=null?(heldOp2DropByOp2[slot2]=r2Drop.clone(),pickSlot1!=null&&(op1PicksOp2DropSlots[pickSlot1]==null&&(op1PicksOp2DropSlots[pickSlot1]=[]),op1PicksOp2DropSlots[pickSlot1].push(slot2)),r1Pick=heldOp1PickByOp2[slot2]||null,r2Pick=heldOp2PickByOp2[slot2]||null,cancelledOp2[slot2]?(removed1&&(discardedOp2Drop[slot2]=!0),removed1=heldOp1RmForOp2[slot2]||null):!removed1||side!==1&&op1PickAtOp2Pick[slot2]!=null||conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:exports2.removeOp(removed1.getPath()),op2:exports2.moveOp(r2Pick.getPath(),r2Drop.getPath())}),droppedHere=!0):c2d.i!==void 0&&(r1Pick=r2Pick=null,droppedHere=!0,removed1&&conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:exports2.removeOp(removed1.getPath()),op2:exports2.insertOp(r2Drop.getPath(),c2d.i)})));const c1p=getComponent(r1Pick);c1p&&(c1p.r!==void 0?removed1=r1Pick.clone():c1p.p!=null&&(c1p.p,pickSlot1=c1p.p,removed1=null));const t2=getEditType(c2d);t2&&removed1&&conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:exports2.removeOp(removed1.getPath()),op2:exports2.editOp(r2Drop.getPath(),t2,getEdit(c2d),!0)});let p2PickOff=0,p2DropOff=0;const ap2=cursor_js_1.advancer(r2Pick,(k,c)=>hasPick(c)?p2PickOff-k-1:k-p2PickOff,(k,c)=>{hasPick(c)&&p2PickOff++}),ap1=cursor_js_1.advancer(r1Pick);for(const key of r2Drop)if(typeof key=="number"){const p2Mid=key-p2DropOff,_p2Pick=ap2(p2Mid);p2DropOff+=+scanOp2Drop(ap1(p2Mid+p2PickOff),_p2Pick,r2Drop,pickSlot1,removed1)}else{const _p2Pick=ap2(key);scanOp2Drop(ap1(key),_p2Pick,r2Drop,pickSlot1,removed1)}return ap2.end(),ap1.end(),droppedHere},"scanOp2Drop")(r1,r2,r2.clone(),null,null),heldOp2DropByOp2.map(x=>x&&x.get()),conflict)return{ok:!1,conflict};discardedOp2Drop.map(x=>!!x);const pickComponents=[];let cancelledRemoves=null;__name(function writeOp1Pick(r1Pick,r2Pick,r2Drop,w2,removed2){let iAmMoved=!1;const c2p=getComponent(r2Pick);if(hasPick(c2p)){const slot2=c2p.p;slot2!=null?(r2Drop=heldOp2DropByOp2[slot2],w2=heldPickWrites[slot2]=cursor_js_1.writeCursor(),iAmMoved=!0,removed2=null):(r2Drop=null,removed2=r2Pick.clone())}else hasDrop(getComponent(r2Drop))&&(r2Drop=null);const c1=r1Pick.getComponent();if(c1){const slot1=c1.p;slot1!=null?(removed2&&(heldOp2RmForOp1[slot1]=removed2),pickComponents[slot1]=removed2||side===1&&iAmMoved?null:w2.getComponent(),heldOp1PickByOp1[slot1]=r1Pick.clone(),r2Drop&&(heldOp2DropByOp1[slot1]=r2Drop.clone())):c1.r!==void 0&&(removed2||w2.write("r",!0),(removed2||iAmMoved)&&(cancelledRemoves==null&&(cancelledRemoves=new Set),cancelledRemoves.add(c1)))}let p2PickOff=0,p2DropOff=0;const ap2Pick=cursor_js_1.advancer(r2Pick,void 0,(k,c)=>{hasPick(c)&&p2PickOff++}),ap2Drop=cursor_js_1.advancer(r2Drop,(k,c)=>hasDrop(c)?~(k-p2DropOff):k-p2DropOff,(k,c)=>{hasDrop(c)&&p2DropOff++});if(r1Pick)for(const key of r1Pick)if(typeof key=="string"){const p2Pick_=ap2Pick(key),p2Drop_=ap2Drop(key);w2.descend(key),writeOp1Pick(r1Pick,p2Pick_,p2Drop_,w2,removed2),w2.ascend()}else{const p2Pick_=ap2Pick(key),p2Mid=key-p2PickOff,p2Drop_=hasPick(getComponent(p2Pick_))?null:ap2Drop(p2Mid),finalKey=p2Mid+p2DropOff;assert(finalKey>=0),w2.descend(finalKey),writeOp1Pick(r1Pick,p2Pick_,p2Drop_,w2,removed2),w2.ascend()}ap2Pick.end(),ap2Drop.end()},"writeOp1Pick")(r1,r2,r2.clone(),w,null),w.reset();let outputSlotMap=[];if(__name(function writeOp1Drop(p1Pick,p1Drop,p2Pick,p2Drop,w2,removed2){assert(p1Drop);const c1d=p1Drop.getComponent();let c2d=getComponent(p2Drop),droppedHere=!1;const insOrMv=__name((r12,r22,c)=>r12?exports2.moveOp(r12.getPath(),r22.getPath()):exports2.insertOp(r22.getPath(),c.i),"insOrMv");if(hasDrop(c1d)){const slot1=c1d.d;slot1!=null&&(heldOp1DropByOp1[slot1]=p1Drop.clone());const pc=slot1!=null?pickComponents[slot1]:null;let identical=!1;if(c1d.i!==void 0||slot1!=null&&pc){let slot2;c2d&&(c2d.i!==void 0||(slot2=c2d.d)!=null&&!cancelledOp2[slot2])&&(identical=slot2!=null?slot1!=null&&slot1===op1PickAtOp2Pick[slot2]:deepEqual_js_1.default(c2d.i,c1d.i),identical||slot2!=null&&side!==1&&op1PickAtOp2Pick[slot2]!=null||conflict==null&&(conflict={type:types_js_1.ConflictType.DROP_COLLISION,op1:insOrMv(slot1!=null?heldOp1PickByOp1[slot1]:null,p1Drop,c1d),op2:insOrMv(slot2!=null?heldOp2PickByOp2[slot2]:null,p2Drop,c2d)})),identical||(removed2?conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:insOrMv(slot1!=null?heldOp1PickByOp1[slot1]:null,p1Drop,c1d),op2:exports2.removeOp(removed2.getPath())}):(slot1!=null?(outputSlotMap[nextSlot]=slot1,w2.write("d",pc.p=nextSlot++)):w2.write("i",deepClone_js_1.default(c1d.i)),droppedHere=!0))}else if(slot1!=null&&!pc){const h=heldOp2RmForOp1[slot1];h&&(removed2=h.clone())}slot1!=null?(p1Pick=heldOp1PickByOp1[slot1],p2Pick=heldOp2PickByOp1[slot1],p2Drop=heldOp2DropByOp1[slot1]):c1d.i!==void 0&&(p1Pick=p2Pick=null,identical||(p2Drop=null))}else hasPick(getComponent(p1Pick))&&(p1Pick=p2Pick=p2Drop=null);const c1p=getComponent(p1Pick),c2p=getComponent(p2Pick);if(hasPick(c2p)){const slot2=c2p.p;c2p.r!==void 0&&(!c1p||c1p.r===void 0)||cancelledOp2[slot2]?(p2Drop=null,removed2=p2Pick.clone()):slot2!=null&&(p2Drop=heldOp2DropByOp2[slot2],side!==1&&op1PickAtOp2Pick[slot2]!=null||((w2=heldDropWrites[slot2])||(w2=heldDropWrites[slot2]=cursor_js_1.writeCursor()),w2.reset(),removed2=null))}else!hasDrop(c1d)&&hasDrop(c2d)&&(p2Drop=null);c2d=p2Drop!=null?p2Drop.getComponent():null;const t1=getEditType(c1d);if(t1){const e1=getEdit(c1d);if(removed2)conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:exports2.editOp(p1Drop.getPath(),t1,e1,!0),op2:exports2.removeOp(removed2.getPath())});else{const t2=getEditType(c2d);let e;if(t2){if(t1!==t2)throw Error("Transforming incompatible types");const e2=getEdit(c2d);e=t1.transform(e1,e2,direction)}else e=deepClone_js_1.default(e1);writeEdit(w2,t1,e)}}let p1PickOff=0,p1DropOff=0,p2PickOff=0,p2DropOff=0,outPickOff=0,outDropOff=0,p1pValid=p1Pick!=null&&p1Pick.descendFirst(),p1pDidDescend=p1pValid;const ap2p=cursor_js_1.advancer(p2Pick,void 0,(k,c)=>{hasPick(c)&&p2PickOff++});let p2dValid=p2Drop!=null&&p2Drop.descendFirst(),p2dDidDescend=p2dValid;for(const key of p1Drop)if(typeof key=="number"){let _p1Pick;const hd1=hasDrop(p1Drop.getComponent()),k1Mid=key-p1DropOff;{let p1k;for(;p1pValid&&typeof(p1k=p1Pick.getKey())=="number";){p1k+=p1PickOff;const c=p1Pick.getComponent(),hp=hasPick(c);if(p1k>k1Mid||p1k===k1Mid&&(!hp||side===0&&hd1))break;if(hp){p1PickOff--;const slot1=c.p;op1PickAtOp2Pick.includes(slot1),c.d,getComponent(heldDropWrites[c.d]),hasPick(getComponent(heldDropWrites[c.d])),(c.r===void 0||cancelledRemoves&&cancelledRemoves.has(c))&&(slot1==null||!pickComponents[slot1]||side!==1&&op1PickAtOp2Pick.includes(slot1))||outPickOff--}p1pValid=p1Pick.nextSibling()}_p1Pick=p1pValid&&p1k===k1Mid?p1Pick:null}const raw=k1Mid-p1PickOff;let _p2Pick=ap2p(raw);const k2Mid=raw-p2PickOff;let _p2Drop=null;{let p2dk,op2Mid;for(;p2dValid&&typeof(p2dk=p2Drop.getKey())=="number";){op2Mid=p2dk-p2DropOff;const c=p2Drop.getComponent(),hd2=hasDrop(c);if(op2Mid>k2Mid)break;if(op2Mid===k2Mid){if(!hd2){_p2Drop=p2Drop;break}{if(side===0&&hd1){_p2Drop=p2Drop;break}const hp2=_p2Pick&&hasPick(_p2Pick.getComponent());if(side===0&&hp2)break}}if(hd2){const slot2=c.d;op1PickAtOp2Pick[slot2],c.i===void 0&&(cancelledOp2[slot2]||op1PickAtOp2Pick[slot2]!=null&&side!==1)?(cancelledOp2[slot2]||op1PickAtOp2Pick[slot2]!=null&&side===0)&&(p2DropOff++,outDropOff--):p2DropOff++}p2dValid=p2Drop.nextSibling()}}const descend=k2Mid+p2DropOff+outPickOff+outDropOff;assert(descend>=0,"trying to descend to a negative index"),w2.descend(descend),hd1&&(_p1Pick=_p2Pick=_p2Drop=null,p1DropOff++),writeOp1Drop(_p1Pick,p1Drop,_p2Pick,_p2Drop,w2,removed2)&&outDropOff++,w2.ascend()}else{let p1k;for(;p1pValid&&(p1k=p1Pick.getKey(),typeof p1k!="string"||!(p1k>key||p1k===key));)p1pValid=p1Pick.nextSibling();const _p1Pick=p1pValid&&p1k===key?p1Pick:null,_p2Pick=ap2p(key);let p2dk;for(;p2dValid&&(p2dk=p2Drop.getKey(),typeof p2dk!="string"||!(p2dk>key||p2dk===key));)p2dValid=p2Drop.nextSibling();const _p2Drop=p2dValid&&p2dk===key?p2Drop:null;w2.descend(key),writeOp1Drop(_p1Pick,p1Drop,_p2Pick,_p2Drop,w2,removed2),w2.ascend()}return ap2p.end(),p1pDidDescend&&p1Pick.ascend(),p2dDidDescend&&p2Drop.ascend(),droppedHere},"writeOp1Drop")(r1,r1.clone(),r2,r2.clone(),w,null),conflict)return{ok:!1,conflict};w.reset();const eachDrop=__name((r,w2,fn)=>r.traverse(w2,(c,w3)=>{c.d!=null&&fn(c.d,r,w3)}),"eachDrop");(cancelledOp2.length||heldPickWrites.length)&&(eachDrop(r2,w,(slot2,r,w2)=>{cancelledOp2[slot2]&&!discardedOp2Drop[slot2]&&w2.write("r",!0),heldPickWrites[slot2]&&w2.mergeTree(heldPickWrites[slot2].get())}),w.reset());const heldOutDropRead=[],heldOutDropWrites=[];if((heldDropWrites.length||cancelledOp2.length)&&!conflict){const rOut=cursor_js_1.readCursor(shallowCloneOp(w.get()));if(eachDrop(rOut,null,(slotOut,r)=>{heldOutDropRead[slotOut]=r.clone()}),heldDropWrites.forEach(hdw=>{hdw&&eachDrop(cursor_js_1.readCursor(hdw.get()),null,(slotOut,r)=>{heldOutDropRead[slotOut]=r.clone()})}),__name(function writeHeldOp2Drop(p2Drop,outPick,outDrop,w2,parentC,removedOut){const coutp=getComponent(outPick);if(coutp&&hasPick(coutp))if(coutp.p!=null){const slot=coutp.p;heldOutDropRead[slot].getPath(),outDrop=heldOutDropRead[slot],w2=heldOutDropWrites[slot]=cursor_js_1.writeCursor()}else coutp.r!==void 0&&(outDrop=null);else hasDrop(getComponent(outDrop))&&(outDrop=null);const c2=p2Drop.getComponent();if(c2){let slot2;if((slot2=c2.d)!=null){const _w=heldDropWrites[slot2];_w&&(_w.get(),w2.mergeTree(_w.get()),outDrop=cursor_js_1.readCursor(_w.get()))}}let outPickOff=0,outDropOff=0;const oPickAdv=cursor_js_1.advancer(outPick,void 0,(k,c)=>{hasPick(c)&&outPickOff--}),oDropAdv=cursor_js_1.advancer(outDrop,(k,c)=>hasDrop(c)?-(k-outDropOff)-1:k-outDropOff,(k,c)=>{hasDrop(c)&&outDropOff++});for(const o2dk of p2Drop)if(typeof o2dk=="number"){const _outPick=oPickAdv(o2dk),rmid=o2dk+outPickOff,_outDrop=oDropAdv(rmid),rfinal=rmid+outDropOff;w2.descend(rfinal),writeHeldOp2Drop(p2Drop,_outPick,_outDrop,w2),w2.ascend()}else w2.descend(o2dk),writeHeldOp2Drop(p2Drop,oPickAdv(o2dk),oDropAdv(o2dk),w2),w2.ascend();oPickAdv.end(),oDropAdv.end()},"writeHeldOp2Drop")(r2,rOut,rOut.clone(),w),w.reset(),conflict)return{ok:!1,conflict};if(w.get(),heldOutDropWrites.length){const heldOutDropContent=heldOutDropWrites.map(w2=>w2?w2.get():null),rOut2=cursor_js_1.readCursor(shallowCloneOp(w.get()));if(eachDrop(rOut2,w,(slotOut,r,w2)=>{const data=heldOutDropContent[slotOut];data&&(w2.mergeTree(data),heldOutDropContent[slotOut]=null)}),heldOutDropContent.find(x=>x)){const w1=cursor_js_1.writeCursor(),w2=cursor_js_1.writeCursor();let nextSlot1=0,nextSlot2=0;heldOutDropContent.forEach(data=>{data!=null&&eachDrop(cursor_js_1.readCursor(data),null,c=>{const slot1=outputSlotMap[c];w1.writeMove(heldOp1PickByOp1[slot1].getPath(),heldOp1DropByOp1[slot1].getPath(),nextSlot1++);const slot2s=op1PicksOp2DropSlots[slot1];slot2s&&slot2s.forEach(slot2=>{cancelledOp2[slot2]||side!==1&&op1PickAtOp2Pick[slot2]!=null||w2.writeMove(heldOp2PickByOp2[slot2].getPath(),heldOp2DropByOp2[slot2].getPath(),nextSlot2++)})})}),conflict={type:types_js_1.ConflictType.BLACKHOLE,op1:w1.get(),op2:w2.get()}}}}return conflict?{ok:!1,conflict}:{ok:!0,result:w.get()}}__name(tryTransform,"tryTransform");const throwConflictErr=__name(conflict=>{const err=new Error("Transform detected write conflict");throw err.conflict=conflict,err.type=err.name="writeConflict",err},"throwConflictErr");function transform(op1,op2,side){const res=tryTransform(op1,op2,side);if(res.ok)return res.result;throwConflictErr(res.conflict)}__name(transform,"transform");const opThatRemovesDE=__name(op=>{const w=cursor_js_1.writeCursor();return cursor_js_1.readCursor(op).traverse(w,(c,w2)=>{(hasDrop(c)||getEditType(c))&&w2.write("r",!0)}),w.get()},"opThatRemovesDE"),resolveConflict=__name((conflict,side)=>{const{type:type2,op1,op2}=conflict;switch(type2){case types_js_1.ConflictType.DROP_COLLISION:return side==="left"?[null,opThatRemovesDE(op2)]:[opThatRemovesDE(op1),null];case types_js_1.ConflictType.RM_UNEXPECTED_CONTENT:let op1HasRemove=!1;return cursor_js_1.readCursor(op1).traverse(null,c=>{c.r!==void 0&&(op1HasRemove=!0)}),op1HasRemove?[null,opThatRemovesDE(op2)]:[opThatRemovesDE(op1),null];case types_js_1.ConflictType.BLACKHOLE:return[opThatRemovesDE(op1),opThatRemovesDE(op2)];default:throw Error("Unrecognised conflict: "+type2)}},"resolveConflict");function transformWithConflictsPred(allowConflict,op1,op2,side){let r2Aggregate=null;for(;;){const res=tryTransform(op1,op2,side);if(res.ok)return compose(r2Aggregate,res.result);{const{conflict}=res;allowConflict(conflict)||throwConflictErr(conflict);const[r1,r2]=resolveConflict(conflict,side);op1=compose(normalize(op1),r1),op2=compose(normalize(op2),r2),r2Aggregate=compose(r2Aggregate,r2)}}}__name(transformWithConflictsPred,"transformWithConflictsPred")})(json1_release);(function(exports2){var __createBinding=commonjsGlobal&&commonjsGlobal.__createBinding||(Object.create?function(o,m,k,k2){k2===void 0&&(k2=k),Object.defineProperty(o,k2,{enumerable:!0,get:__name(function(){return m[k]},"get")})}:function(o,m,k,k2){k2===void 0&&(k2=k),o[k2]=m[k]}),__exportStar=commonjsGlobal&&commonjsGlobal.__exportStar||function(m,exports3){for(var p in m)p!=="default"&&!exports3.hasOwnProperty(p)&&__createBinding(exports3,m,p)};Object.defineProperty(exports2,"__esModule",{value:!0}),__exportStar(json1_release,exports2);var cursor_js_1=cursor;Object.defineProperty(exports2,"ReadCursor",{enumerable:!0,get:__name(function(){return cursor_js_1.ReadCursor},"get")}),Object.defineProperty(exports2,"WriteCursor",{enumerable:!0,get:__name(function(){return cursor_js_1.WriteCursor},"get")});var types_1=types;Object.defineProperty(exports2,"ConflictType",{enumerable:!0,get:__name(function(){return types_1.ConflictType},"get")})})(dist$1);const _UnitDrawingService=class _UnitDrawingService{constructor(){__publicField(this,"drawingManagerData",{});__publicField(this,"_oldDrawingManagerData",{});__publicField(this,"_focusDrawings",[]);__publicField(this,"_remove$",new rxjs.Subject);__publicField(this,"remove$",this._remove$.asObservable());__publicField(this,"_add$",new rxjs.Subject);__publicField(this,"add$",this._add$.asObservable());__publicField(this,"_update$",new rxjs.Subject);__publicField(this,"update$",this._update$.asObservable());__publicField(this,"_order$",new rxjs.Subject);__publicField(this,"order$",this._order$.asObservable());__publicField(this,"_group$",new rxjs.Subject);__publicField(this,"group$",this._group$.asObservable());__publicField(this,"_ungroup$",new rxjs.Subject);__publicField(this,"ungroup$",this._ungroup$.asObservable());__publicField(this,"_refreshTransform$",new rxjs.Subject);__publicField(this,"refreshTransform$",this._refreshTransform$.asObservable());__publicField(this,"_visible$",new rxjs.Subject);__publicField(this,"visible$",this._visible$.asObservable());__publicField(this,"_focus$",new rxjs.Subject);__publicField(this,"focus$",this._focus$.asObservable());__publicField(this,"_featurePluginUpdate$",new rxjs.Subject);__publicField(this,"featurePluginUpdate$",this._featurePluginUpdate$.asObservable());__publicField(this,"_featurePluginAdd$",new rxjs.Subject);__publicField(this,"featurePluginAdd$",this._featurePluginAdd$.asObservable());__publicField(this,"_featurePluginRemove$",new rxjs.Subject);__publicField(this,"featurePluginRemove$",this._featurePluginRemove$.asObservable());__publicField(this,"_featurePluginOrderUpdate$",new rxjs.Subject);__publicField(this,"featurePluginOrderUpdate$",this._featurePluginOrderUpdate$.asObservable());__publicField(this,"_featurePluginGroupUpdate$",new rxjs.Subject);__publicField(this,"featurePluginGroupUpdate$",this._featurePluginGroupUpdate$.asObservable());__publicField(this,"_featurePluginUngroupUpdate$",new rxjs.Subject);__publicField(this,"featurePluginUngroupUpdate$",this._featurePluginUngroupUpdate$.asObservable());__publicField(this,"_visible",!0);__publicField(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(visibleParams){this._visible$.next(visibleParams)}refreshTransform(updateParams){updateParams.forEach(updateParam=>{const param=this._getCurrentBySearch(updateParam);param!=null&&(param.transform=updateParam.transform,param.transforms=updateParam.transforms,param.isMultiTransform=updateParam.isMultiTransform)}),this.refreshTransformNotification(updateParams)}getDrawingDataForUnit(unitId){return this.drawingManagerData[unitId]||{}}removeDrawingDataForUnit(unitId){const subUnits=this.drawingManagerData[unitId];if(subUnits==null)return;delete this.drawingManagerData[unitId];const drawings=[];Object.keys(subUnits).forEach(subUnitId=>{const subUnit=subUnits[subUnitId];(subUnit==null?void 0:subUnit.data)!=null&&Object.keys(subUnit.data).forEach(drawingId=>{drawings.push({unitId,subUnitId,drawingId})})}),drawings.length>0&&this.removeNotification(drawings)}registerDrawingData(unitId,data){this.drawingManagerData[unitId]=data}initializeNotification(unitId){const drawings=[],data=this.drawingManagerData[unitId];data!=null&&(Object.keys(data).forEach(subUnitId=>{this._establishDrawingMap(unitId,subUnitId);const subUnitData=data[subUnitId];Object.keys(subUnitData.data).forEach(drawingId=>{const drawing=subUnitData.data[drawingId];drawing.unitId=unitId,drawing.subUnitId=subUnitId,drawings.push(drawing)})}),drawings.length>0&&this.addNotification(drawings))}getDrawingData(unitId,subUnitId){return this._getDrawingData(unitId,subUnitId)}setDrawingData(unitId,subUnitId,data){this.drawingManagerData[unitId][subUnitId].data=data}getBatchAddOp(insertParams){const objects=[],ops=[],invertOps=[];insertParams.forEach(insertParam=>{const{op:op2,invertOp:invertOp2}=this._addByParam(insertParam);objects.push({unitId:insertParam.unitId,subUnitId:insertParam.subUnitId,drawingId:insertParam.drawingId}),ops.push(op2),invertOps.push(invertOp2)});const op=ops.reduce(dist$1.type.compose,null),invertOp=invertOps.reduce(dist$1.type.compose,null),{unitId,subUnitId}=insertParams[0];return{undo:invertOp,redo:op,unitId,subUnitId,objects}}getBatchRemoveOp(removeParams){const ops=[],invertOps=[];removeParams.forEach(removeParam=>{const{op:op2,invertOp:invertOp2}=this._removeByParam(removeParam);ops.unshift(op2),invertOps.push(invertOp2)});const op=ops.reduce(dist$1.type.compose,null),invertOp=invertOps.reduce(dist$1.type.compose,null),{unitId,subUnitId}=removeParams[0];return{undo:invertOp,redo:op,unitId,subUnitId,objects:removeParams}}getBatchUpdateOp(updateParams){const objects=[],ops=[],invertOps=[];updateParams.forEach(updateParam=>{const{op:op2,invertOp:invertOp2}=this._updateByParam(updateParam);objects.push({unitId:updateParam.unitId,subUnitId:updateParam.subUnitId,drawingId:updateParam.drawingId}),ops.push(op2),invertOps.push(invertOp2)});const op=ops.reduce(dist$1.type.compose,null),invertOp=invertOps.reduce(dist$1.type.compose,null),{unitId,subUnitId}=updateParams[0];return{undo:invertOp,redo:op,unitId,subUnitId,objects}}removeNotification(removeParams){this._remove$.next(removeParams)}addNotification(insertParams){this._add$.next(insertParams)}updateNotification(updateParams){this._update$.next(updateParams)}orderNotification(orderParams){this._order$.next(orderParams)}groupUpdateNotification(groupParams){this._group$.next(groupParams)}ungroupUpdateNotification(groupParams){this._ungroup$.next(groupParams)}refreshTransformNotification(refreshParams){this._refreshTransform$.next(refreshParams)}getGroupDrawingOp(groupParams){const ops=[],{unitId,subUnitId}=groupParams[0].parent;groupParams.forEach(groupParam=>{ops.push(this._getGroupDrawingOp(groupParam))});const op=ops.reduce(dist$1.type.compose,null);return{undo:dist$1.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:groupParams}}getUngroupDrawingOp(groupParams){const ops=[],{unitId,subUnitId}=groupParams[0].parent;groupParams.forEach(groupParam=>{ops.push(this._getUngroupDrawingOp(groupParam))});const op=ops.reduce(dist$1.type.compose,null);return{undo:dist$1.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:groupParams}}getDrawingsByGroup(groupParam){const{unitId,subUnitId,drawingId}=groupParam;if(this.getDrawingByParam({unitId,subUnitId,drawingId})==null)return[];const drawings=this._getDrawingData(unitId,subUnitId),children=[];return Object.keys(drawings).forEach(key=>{const drawing=drawings[key];drawing.groupId===drawingId&&children.push(drawing)}),children}_getGroupDrawingOp(groupParam){const{parent,children}=groupParam,{unitId:groupUnitId,subUnitId:groupSubUnitId,drawingId:groupDrawingId}=parent,ops=[];ops.push(dist$1.insertOp([groupUnitId,groupSubUnitId,"data",groupDrawingId],parent));let maxChildIndex=Number.NEGATIVE_INFINITY;return children.forEach(child=>{const{unitId,subUnitId,drawingId}=child,index=this._hasDrawingOrder({unitId,subUnitId,drawingId});maxChildIndex=Math.max(maxChildIndex,index),ops.push(...this._getUpdateParamCompareOp(child,this.getDrawingByParam({unitId,subUnitId,drawingId})))}),maxChildIndex===Number.NEGATIVE_INFINITY&&(maxChildIndex=this._getDrawingOrder(groupUnitId,groupSubUnitId).length),ops.push(dist$1.insertOp([groupUnitId,groupSubUnitId,"order",maxChildIndex],groupDrawingId)),ops.reduce(dist$1.type.compose,null)}_getUngroupDrawingOp(groupParam){const{parent,children}=groupParam,{unitId:groupUnitId,subUnitId:groupSubUnitId,drawingId:groupDrawingId}=parent,ops=[];return children.forEach(child=>{const{unitId,subUnitId,drawingId}=child;ops.push(...this._getUpdateParamCompareOp(child,this.getDrawingByParam({unitId,subUnitId,drawingId})))}),ops.push(dist$1.removeOp([groupUnitId,groupSubUnitId,"data",groupDrawingId],!0)),ops.push(dist$1.removeOp([groupUnitId,groupSubUnitId,"order",this._getDrawingOrder(groupUnitId,groupSubUnitId).indexOf(groupDrawingId)],!0)),ops.reduce(dist$1.type.compose,null)}applyJson1(unitId,subUnitId,jsonOp){this._establishDrawingMap(unitId,subUnitId),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=dist$1.type.apply(this.drawingManagerData,jsonOp)}featurePluginUpdateNotification(updateParams){this._featurePluginUpdate$.next(updateParams)}featurePluginOrderUpdateNotification(drawingOrderUpdateParam){this._featurePluginOrderUpdate$.next(drawingOrderUpdateParam)}featurePluginAddNotification(insertParams){this._featurePluginAdd$.next(insertParams)}featurePluginRemoveNotification(removeParams){this._featurePluginRemove$.next(removeParams)}featurePluginGroupUpdateNotification(groupParams){this._featurePluginGroupUpdate$.next(groupParams)}featurePluginUngroupUpdateNotification(groupParams){this._featurePluginUngroupUpdate$.next(groupParams)}getDrawingByParam(param){return this._getCurrentBySearch(param)}getOldDrawingByParam(param){return this._getOldBySearch(param)}getDrawingOKey(oKey){const[unitId,subUnitId,drawingId]=oKey.split("#-#");return this._getCurrentBySearch({unitId,subUnitId,drawingId})}focusDrawing(params){if(params==null){this._focusDrawings=[],this._focus$.next([]);return}const drawingParams=[];params.forEach(param=>{var _a2;const{unitId,subUnitId,drawingId}=param,item=(_a2=this._getDrawingData(unitId,subUnitId))==null?void 0:_a2[drawingId];item!=null&&drawingParams.push(item)}),drawingParams.length>0&&(this._focusDrawings=drawingParams,this._focus$.next(drawingParams))}getFocusDrawings(){const drawingParams=[];return this._focusDrawings.forEach(param=>{var _a2;const{unitId,subUnitId,drawingId}=param,item=(_a2=this._getDrawingData(unitId,subUnitId))==null?void 0:_a2[drawingId];item!=null&&drawingParams.push(item)}),drawingParams}getDrawingOrder(unitId,subUnitId){return this._getDrawingOrder(unitId,subUnitId)}setDrawingOrder(unitId,subUnitId,order){this.drawingManagerData[unitId][subUnitId].order=order}orderUpdateNotification(orderParams){this._order$.next(orderParams)}getForwardDrawingsOp(orderParams){const{unitId,subUnitId,drawingIds}=orderParams,ops=[],orders=this.getDrawingOrder(unitId,subUnitId),newIds=[...drawingIds];drawingIds.forEach(drawingId=>{const index=this._hasDrawingOrder({unitId,subUnitId,drawingId});if(index===-1||index===orders.length-1)return;const op2=dist$1.moveOp([unitId,subUnitId,"order",index],[unitId,subUnitId,"order",index+1]);ops.push(op2),newIds.includes(orders[index+1])||newIds.push(orders[index+1])});const op=ops.reduce(dist$1.type.compose,null);return{undo:dist$1.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:{...orderParams,drawingIds:newIds}}}getBackwardDrawingOp(orderParams){const{unitId,subUnitId,drawingIds}=orderParams,ops=[],orders=this.getDrawingOrder(unitId,subUnitId),newIds=[...drawingIds];drawingIds.forEach(drawingId=>{const index=this._hasDrawingOrder({unitId,subUnitId,drawingId});if(index===-1||index===0)return;const op2=dist$1.moveOp([unitId,subUnitId,"order",index],[unitId,subUnitId,"order",index-1]);ops.push(op2),newIds.includes(orders[index-1])||newIds.push(orders[index-1])});const op=ops.reduce(dist$1.type.compose,null);return{undo:dist$1.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:{...orderParams,drawingIds:newIds}}}getFrontDrawingsOp(orderParams){const{unitId,subUnitId,drawingIds}=orderParams,orderDrawingIds=this._getOrderFromSearchParams(unitId,subUnitId,drawingIds),newIds=[...drawingIds],orders=this.getDrawingOrder(unitId,subUnitId),ops=[];orderDrawingIds.forEach(orderDrawingId=>{const{drawingId}=orderDrawingId,index=this._getDrawingCount(unitId,subUnitId)-1,op2=dist$1.moveOp([unitId,subUnitId,"order",this._getDrawingOrder(unitId,subUnitId).indexOf(drawingId)],[unitId,subUnitId,"order",index]);ops.push(op2),newIds.includes(orders[index])||newIds.push(orders[index])});const op=ops.reduce(dist$1.type.compose,null);return{undo:dist$1.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:{...orderParams,drawingIds:newIds}}}getBackDrawingsOp(orderParams){const{unitId,subUnitId,drawingIds}=orderParams,orderSearchParams=this._getOrderFromSearchParams(unitId,subUnitId,drawingIds,!0),newIds=[...drawingIds],orders=this.getDrawingOrder(unitId,subUnitId),ops=[];orderSearchParams.forEach(orderSearchParam=>{const{drawingId}=orderSearchParam,op2=dist$1.moveOp([unitId,subUnitId,"order",this._getDrawingOrder(unitId,subUnitId).indexOf(drawingId)],[unitId,subUnitId,"order",0]);ops.push(op2),newIds.includes(orders[0])||newIds.push(orders[0])});const op=ops.reduce(dist$1.type.compose,null);return{undo:dist$1.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:{...orderParams,drawingIds:newIds}}}_getDrawingCount(unitId,subUnitId){return this.getDrawingOrder(unitId,subUnitId).length||0}_getOrderFromSearchParams(unitId,subUnitId,drawingIds,isDesc=!1){return drawingIds.map(drawingId=>{const zIndex=this._hasDrawingOrder({unitId,subUnitId,drawingId});return{drawingId,zIndex}}).sort(isDesc===!1?core.sortRules:core.sortRulesByDesc)}_hasDrawingOrder(searchParam){if(searchParam==null)return-1;const{unitId,subUnitId,drawingId}=searchParam;return this._establishDrawingMap(unitId,subUnitId),this._getDrawingOrder(unitId,subUnitId).indexOf(drawingId)}_getCurrentBySearch(searchParam){var _a2,_b,_c;if(searchParam==null)return;const{unitId,subUnitId,drawingId}=searchParam;return(_c=(_b=(_a2=this.drawingManagerData[unitId])==null?void 0:_a2[subUnitId])==null?void 0:_b.data)==null?void 0:_c[drawingId]}_getOldBySearch(searchParam){var _a2,_b,_c;if(searchParam==null)return;const{unitId,subUnitId,drawingId}=searchParam;return(_c=(_b=(_a2=this._oldDrawingManagerData[unitId])==null?void 0:_a2[subUnitId])==null?void 0:_b.data)==null?void 0:_c[drawingId]}_establishDrawingMap(unitId,subUnitId,drawingId){var _a2;return this.drawingManagerData[unitId]||(this.drawingManagerData[unitId]={}),this.drawingManagerData[unitId][subUnitId]||(this.drawingManagerData[unitId][subUnitId]={data:{},order:[]}),drawingId==null?null:(_a2=this.drawingManagerData[unitId][subUnitId].data)==null?void 0:_a2[drawingId]}_addByParam(insertParam){const{unitId,subUnitId,drawingId}=insertParam;this._establishDrawingMap(unitId,subUnitId,drawingId);const op1=dist$1.insertOp([unitId,subUnitId,"data",drawingId],insertParam),op2=dist$1.insertOp([unitId,subUnitId,"order",this._getDrawingOrder(unitId,subUnitId).length],drawingId),op=[op1,op2].reduce(dist$1.type.compose,null),invertOp=dist$1.type.invertWithDoc(op,this.drawingManagerData);return{op,invertOp}}_removeByParam(searchParam){if(searchParam==null)return{op:[],invertOp:[]};const{unitId,subUnitId,drawingId}=searchParam;if(this._establishDrawingMap(unitId,subUnitId,drawingId)==null)return{op:[],invertOp:[]};const op1=dist$1.removeOp([unitId,subUnitId,"data",drawingId],!0),op2=dist$1.removeOp([unitId,subUnitId,"order",this._getDrawingOrder(unitId,subUnitId).indexOf(drawingId)],!0),op=[op1,op2].reduce(dist$1.type.compose,null),invertOp=dist$1.type.invertWithDoc(op,this.drawingManagerData);return{op,invertOp}}_updateByParam(updateParam){const{unitId,subUnitId,drawingId}=updateParam,object=this._establishDrawingMap(unitId,subUnitId,drawingId);if(object==null)return{op:[],invertOp:[]};const op=this._getUpdateParamCompareOp(updateParam,object).reduce(dist$1.type.compose,null),invertOp=dist$1.type.invertWithDoc(op,this.drawingManagerData);return{op,invertOp}}_getUpdateParamCompareOp(newParam,oldParam){const{unitId,subUnitId,drawingId}=newParam,ops=[];return Object.keys(newParam).forEach(key=>{const newVal=newParam[key],oldVal=oldParam[key];oldVal!==newVal&&ops.push(dist$1.replaceOp([unitId,subUnitId,"data",drawingId,key],oldVal,newVal))}),ops}_getDrawingData(unitId,subUnitId){var _a2,_b;return((_b=(_a2=this.drawingManagerData[unitId])==null?void 0:_a2[subUnitId])==null?void 0:_b.data)||{}}_getDrawingOrder(unitId,subUnitId){var _a2,_b;return((_b=(_a2=this.drawingManagerData[unitId])==null?void 0:_a2[subUnitId])==null?void 0:_b.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(visible){this._visible=visible}setDrawingEditable(editable){this._editable=editable}};__name(_UnitDrawingService,"UnitDrawingService");let UnitDrawingService=_UnitDrawingService;const _DrawingManagerService=class _DrawingManagerService extends UnitDrawingService{};__name(_DrawingManagerService,"DrawingManagerService");let DrawingManagerService=_DrawingManagerService;function getDrawingShapeKeyByDrawingSearch({unitId,subUnitId,drawingId},index){return typeof index=="number"?`${unitId}#-#${subUnitId}#-#${drawingId}#-#${index}`:`${unitId}#-#${subUnitId}#-#${drawingId}`}__name(getDrawingShapeKeyByDrawingSearch,"getDrawingShapeKeyByDrawingSearch");const getImageSize=__name(async src=>new Promise((resolve,reject)=>{const image=new Image;image.src=src,image.onload=()=>{resolve({width:image.width,height:image.height,image})},image.onerror=error=>{reject(error)}}),"getImageSize");var ImageSourceType=(ImageSourceType2=>(ImageSourceType2.URL="URL",ImageSourceType2.UUID="UUID",ImageSourceType2.BASE64="BASE64",ImageSourceType2))(ImageSourceType||{}),ImageUploadStatusType=(ImageUploadStatusType2=>(ImageUploadStatusType2.SUCCUSS="0",ImageUploadStatusType2.ERROR_EXCEED_SIZE="1",ImageUploadStatusType2.ERROR_IMAGE_TYPE="2",ImageUploadStatusType2.ERROR_UPLOAD_COUNT_LIMIT="3",ImageUploadStatusType2.ERROR_IMAGE="4",ImageUploadStatusType2))(ImageUploadStatusType||{});const IImageIoService=core.createIdentifier("core.image-io.service"),_ImageIoService=class _ImageIoService{constructor(){__publicField(this,"_waitCount",0);__publicField(this,"_change$",new rxjs.Subject);__publicField(this,"change$",this._change$);__publicField(this,"_imageSourceCache",new Map)}setWaitCount(count){this._waitCount=count,this._change$.next(count)}getImageSourceCache(source,imageSourceType){if(imageSourceType===ImageSourceType.BASE64){const image=new Image;return image.src=source,image}return this._imageSourceCache.get(source)}addImageSourceCache(source,imageSourceType,imageSource){imageSourceType===ImageSourceType.BASE64||imageSource==null||this._imageSourceCache.set(source,imageSource)}async getImage(imageId){return Promise.resolve(imageId)}async saveImage(imageFile){return new Promise((resolve,reject)=>{if(!DRAWING_IMAGE_ALLOW_IMAGE_LIST.includes(imageFile.type)){reject(new Error(ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(imageFile.size>DRAWING_IMAGE_ALLOW_SIZE){reject(new Error(ImageUploadStatusType.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}const reader=new FileReader;reader.readAsDataURL(imageFile),reader.onload=evt=>{var _a2;const replaceSrc=(_a2=evt.target)==null?void 0:_a2.result;if(replaceSrc==null){reject(new Error(ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting();return}const imageId=core.Tools.generateRandomId(6);resolve({imageId,imageSourceType:ImageSourceType.BASE64,source:replaceSrc,base64Cache:replaceSrc,status:ImageUploadStatusType.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}};__name(_ImageIoService,"ImageIoService");let ImageIoService=_ImageIoService;const DEFAULT_DOCUMENT_SUB_COMPONENT_ID="__default_document_sub_component_id20231101__";var ArrangeTypeEnum=(ArrangeTypeEnum2=>(ArrangeTypeEnum2[ArrangeTypeEnum2.forward=0]="forward",ArrangeTypeEnum2[ArrangeTypeEnum2.backward=1]="backward",ArrangeTypeEnum2[ArrangeTypeEnum2.front=2]="front",ArrangeTypeEnum2[ArrangeTypeEnum2.back=3]="back",ArrangeTypeEnum2))(ArrangeTypeEnum||{}),DrawingTypeEnum=(DrawingTypeEnum2=>(DrawingTypeEnum2[DrawingTypeEnum2.UNRECOGNIZED=-1]="UNRECOGNIZED",DrawingTypeEnum2[DrawingTypeEnum2.DRAWING_IMAGE=0]="DRAWING_IMAGE",DrawingTypeEnum2[DrawingTypeEnum2.DRAWING_SHAPE=1]="DRAWING_SHAPE",DrawingTypeEnum2[DrawingTypeEnum2.DRAWING_CHART=2]="DRAWING_CHART",DrawingTypeEnum2[DrawingTypeEnum2.DRAWING_TABLE=3]="DRAWING_TABLE",DrawingTypeEnum2[DrawingTypeEnum2.DRAWING_SMART_ART=4]="DRAWING_SMART_ART",DrawingTypeEnum2[DrawingTypeEnum2.DRAWING_VIDEO=5]="DRAWING_VIDEO",DrawingTypeEnum2[DrawingTypeEnum2.DRAWING_GROUP=6]="DRAWING_GROUP",DrawingTypeEnum2[DrawingTypeEnum2.DRAWING_UNIT=7]="DRAWING_UNIT",DrawingTypeEnum2[DrawingTypeEnum2.DRAWING_DOM=8]="DRAWING_DOM",DrawingTypeEnum2))(DrawingTypeEnum||{});const IDrawingManagerService=core.createIdentifier("univer.drawing-manager.service"),PLUGIN_CONFIG_KEY="drawing.config",defaultPluginConfig={};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");const PLUGIN_NAME="UNIVER_DRAWING_PLUGIN";var _a;exports.UniverDrawingPlugin=(_a=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){this._initDependencies()}_initDependencies(){var _a2;const dependencies=[[IImageIoService,{useClass:ImageIoService}],[IDrawingManagerService,{useClass:DrawingManagerService}]];core.mergeOverrideWithDependencies(dependencies,(_a2=this._config)==null?void 0:_a2.override).forEach(d=>this._injector.add(d))}},__name(_a,"UniverDrawingPlugin"),__publicField(_a,"pluginName",PLUGIN_NAME),_a);exports.UniverDrawingPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverDrawingPlugin);exports.ArrangeTypeEnum=ArrangeTypeEnum;exports.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=DEFAULT_DOCUMENT_SUB_COMPONENT_ID;exports.DRAWING_IMAGE_ALLOW_IMAGE_LIST=DRAWING_IMAGE_ALLOW_IMAGE_LIST;exports.DRAWING_IMAGE_ALLOW_SIZE=DRAWING_IMAGE_ALLOW_SIZE;exports.DRAWING_IMAGE_COUNT_LIMIT=DRAWING_IMAGE_COUNT_LIMIT;exports.DRAWING_IMAGE_HEIGHT_LIMIT=DRAWING_IMAGE_HEIGHT_LIMIT;exports.DRAWING_IMAGE_WIDTH_LIMIT=DRAWING_IMAGE_WIDTH_LIMIT;exports.DrawingManagerService=DrawingManagerService;exports.DrawingTypeEnum=DrawingTypeEnum;exports.IDrawingManagerService=IDrawingManagerService;exports.IImageIoService=IImageIoService;exports.ImageIoService=ImageIoService;exports.ImageSourceType=ImageSourceType;exports.ImageUploadStatusType=ImageUploadStatusType;exports.UnitDrawingService=UnitDrawingService;exports.getDrawingShapeKeyByDrawingSearch=getDrawingShapeKeyByDrawingSearch;exports.getImageSize=getImageSize;
|
|
1
|
+
"use strict";var $t=Object.defineProperty;var Gt=(n,e,t)=>e in n?$t(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var F=(n,e,t)=>Gt(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ke=require("@univerjs/core"),we=require("rxjs"),Wt=500,Bt=500,xt=10,Ct=5*1024*1024,Et=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"];var Ce=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},V={},Dt={},ut={};Object.defineProperty(ut,"__esModule",{value:!0});function Lt(n,e){if(Array.isArray(e))return!1;for(let t in n)if(!dt(n[t],e[t]))return!1;for(let t in e)if(n[t]===void 0)return!1;return!0}function Ht(n,e){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!dt(n[t],e[t]))return!1;return!0}function dt(n,e){return n===e?!0:n===null||e===null||typeof n!="object"||typeof e!="object"?!1:Array.isArray(n)?Ht(n,e):Lt(n,e)}ut.default=dt;var ft={};Object.defineProperty(ft,"__esModule",{value:!0});function lt(n){if(n===null)return null;if(Array.isArray(n))return n.map(lt);if(typeof n=="object"){const e={};for(let t in n)e[t]=lt(n[t]);return e}else return n}ft.default=lt;var ht={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.eachChildOf=n.advancer=n.readCursor=n.writeCursor=n.WriteCursor=n.ReadCursor=n.isValidPathItem=void 0;function e(v,o){if(!v)throw new Error(o)}const t=v=>v!=null&&typeof v=="object"&&!Array.isArray(v),r=(v,o)=>typeof v==typeof o?v>o:typeof v=="string"&&typeof o=="number";function s(v,o){for(let c in v){const h=c;o.write(h,v[h])}}n.isValidPathItem=v=>typeof v=="number"||typeof v=="string"&&v!=="__proto__";class d{constructor(o=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=o}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,t(this.container[this.idx])&&this.idx--)}getPath(){const o=[];let c=this.container,h=this.parents.length-1,j=this.idx;for(;j>=0;)o.unshift(c[j]),j===0?(j=this.indexes[h*2],c=this.parents[h--]):j-=t(c[j-1])?2:1;return o}}class a extends d{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let o;return this.container&&this.container.length>this.idx+1&&t(o=this.container[this.idx+1])?o:null}descendFirst(){let o=this.idx+1;if(!this.container||o>=this.container.length||t(this.container[o])&&o+1>=this.container.length)return!1;t(this.container[o])&&o++;const c=this.container[o];return Array.isArray(c)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(o),this.idx=0,this.container=c):this.idx=o,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const o=this.indexes[this.indexes.length-1]+1,c=this.parents[this.parents.length-1];return o>=c.length?!1:(e(!isNaN(o)),this.indexes[this.indexes.length-1]=o,this.container=c[o],!0)}_init(o,c,h,j){this.container=o,this.idx=c,this.parents=h.slice(),this.indexes=j.slice()}clone(){const o=new a;return o._init(this.container,this.idx,this.parents,this.indexes),o}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(o,c){const h=this.getComponent();h&&c(h,o);for(const j of this)o&&o.descend(j),this.traverse(o,c),o&&o.ascend()}eachPick(o,c){this.traverse(o,(h,j)=>{h.p!=null&&c(h.p,j)})}eachDrop(o,c){this.traverse(o,(h,j)=>{h.d!=null&&c(h.d,j)})}}n.ReadCursor=a;class l extends d{constructor(o=null){super(o),this.pendingDescent=[],this._op=o}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let o=0;o<this.pendingDescent.length;o++){const c=this.pendingDescent[o];let h=this.idx+1;if(h<this.container.length&&t(this.container[h])&&h++,e(h===this.container.length||!t(this.container[h])),h===this.container.length)this.container.push(c),this.idx=h;else if(this.container[h]===c)this.idx=h;else{if(!Array.isArray(this.container[h])){const j=this.container.splice(h,this.container.length-h);this.container.push(j),this.lcIdx>-1&&(this.lcIdx=h)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(r(c,this.container[this.lcIdx][0])),h=this.lcIdx+1,this.lcIdx=-1);h<this.container.length&&r(c,this.container[h][0]);)h++;if(this.indexes.push(h),this.idx=0,h<this.container.length&&this.container[h][0]===c)this.container=this.container[h];else{const j=[c];this.container.splice(h,0,j),this.container=j}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const o=this.idx+1;if(o<this.container.length&&t(this.container[o]))return this.container[o];{const c={};return this.container.splice(o,0,c),c}}write(o,c){const h=this.getComponent();e(h[o]==null||h[o]===c,"Internal consistency error: Overwritten component. File a bug"),h[o]=c}get(){return this._op}descend(o){if(!n.isValidPathItem(o))throw Error("Invalid JSON key");this.pendingDescent.push(o)}descendPath(o){return this.pendingDescent.push(...o),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(o,c=s){if(o===null)return;if(e(Array.isArray(o)),o===this._op)throw Error("Cannot merge into my own tree");const h=this.lcIdx,j=this.parents.length;let Z=0;for(let ge=0;ge<o.length;ge++){const J=o[ge];typeof J=="string"||typeof J=="number"?(Z++,this.descend(J)):Array.isArray(J)?this.mergeTree(J,c):typeof J=="object"&&c(J,this)}for(;Z--;)this.ascend();this.lcIdx=this.parents.length===j?h:-1}at(o,c){this.descendPath(o),c(this);for(let h=0;h<o.length;h++)this.ascend();return this}writeAtPath(o,c,h){return this.at(o,()=>this.write(c,h)),this.reset(),this}writeMove(o,c,h=0){return this.writeAtPath(o,"p",h).writeAtPath(c,"d",h)}getPath(){const o=super.getPath();return o.push(...this.pendingDescent),o}}n.WriteCursor=l,n.writeCursor=()=>new l,n.readCursor=v=>new a(v);function E(v,o,c){let h,j;j=h=v?v.descendFirst():!1;function Z(ge){let J;for(;j;){const Ie=J=v.getKey();if(ge!=null){let Le=!1;if(o&&typeof Ie=="number"&&(J=o(Ie,v.getComponent()),J<0&&(J=~J,Le=!0)),r(J,ge))return null;if(J===ge&&!Le)return v}c&&typeof J=="number"&&c(J,v.getComponent()),j=v.nextSibling()}return null}return Z.end=()=>{h&&v.ascend()},Z}n.advancer=E;function G(v,o,c){let h,j,Z,ge;for(h=j=v&&v.descendFirst(),Z=ge=o&&o.descendFirst();h||Z;){let J=h?v.getKey():null,Ie=Z?o.getKey():null;J!==null&&Ie!==null&&(r(Ie,J)?Ie=null:J!==Ie&&(J=null)),c(J==null?Ie:J,J!=null?v:null,Ie!=null?o:null),J!=null&&h&&(h=v.nextSibling()),Ie!=null&&Z&&(Z=o.nextSibling())}j&&v.ascend(),ge&&o.ascend()}n.eachChildOf=G})(ht);var gt={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.ConflictType=void 0,function(e){e[e.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",e[e.DROP_COLLISION=2]="DROP_COLLISION",e[e.BLACKHOLE=3]="BLACKHOLE"}(n.ConflictType||(n.ConflictType={}))})(gt);var st={},qe={},yt;function pt(){return yt||(yt=1,Object.defineProperty(qe,"__esModule",{value:!0}),qe.uniToStrPos=qe.strPosToUni=void 0,qe.strPosToUni=(n,e=n.length)=>{let t=0,r=0;for(;r<e;r++){const s=n.charCodeAt(r);s>=55296&&s<=57343&&(t++,r++)}if(r!==e)throw Error("Invalid offset - splits unicode bytes");return r-t},qe.uniToStrPos=(n,e)=>{let t=0;for(;e>0;e--){const r=n.charCodeAt(t);t+=r>=55296&&r<=57343?2:1}return t}),qe}var ot={},bt;function ct(){return bt||(bt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.uniSlice=n.dlen=n.eachOp=void 0;const e=pt(),t=f=>{if(!Array.isArray(f))throw Error("Op must be an array of components");let _=null;for(let w=0;w<f.length;w++){const L=f[w];switch(typeof L){case"object":if(typeof L.d!="number"&&typeof L.d!="string")throw Error("Delete must be number or string");if(n.dlen(L.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(L.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(L>0))throw Error("Skip components must be >0");if(typeof _=="number")throw Error("Adjacent skip components should be combined");break}_=L}if(typeof _=="number")throw Error("Op has a trailing skip")};function r(f,_){let w=0,L=0;for(let z=0;z<f.length;z++){const H=f[z];switch(_(H,w,L),typeof H){case"object":w+=n.dlen(H.d);break;case"string":L+=e.strPosToUni(H);break;case"number":w+=H,L+=H;break}}}n.eachOp=r;function s(f,_){const w=[],L=l(w);return r(f,(z,H,De)=>{L(_(z,H,De))}),o(w)}const d=f=>f,a=f=>s(f,d);n.dlen=f=>typeof f=="number"?f:e.strPosToUni(f);const l=f=>_=>{if(!(!_||_.d===0||_.d===""))if(f.length===0)f.push(_);else if(typeof _==typeof f[f.length-1])if(typeof _=="object"){const w=f[f.length-1];w.d=typeof w.d=="string"&&typeof _.d=="string"?w.d+_.d:n.dlen(w.d)+n.dlen(_.d)}else f[f.length-1]+=_;else f.push(_)},E=f=>typeof f=="number"?f:typeof f=="string"?e.strPosToUni(f):typeof f.d=="number"?f.d:e.strPosToUni(f.d);n.uniSlice=(f,_,w)=>{const L=e.uniToStrPos(f,_),z=w==null?1/0:e.uniToStrPos(f,w);return f.slice(L,z)};const G=(f,_,w)=>typeof f=="number"?w==null?f-_:Math.min(f,w)-_:n.uniSlice(f,_,w),v=f=>{let _=0,w=0;return{take:(H,De)=>{if(_===f.length)return H===-1?null:H;const ue=f[_];let ne;if(typeof ue=="number")return H===-1||ue-w<=H?(ne=ue-w,++_,w=0,ne):(w+=H,H);if(typeof ue=="string"){if(H===-1||De==="i"||e.strPosToUni(ue.slice(w))<=H)return ne=ue.slice(w),++_,w=0,ne;{const le=w+e.uniToStrPos(ue.slice(w),H);return ne=ue.slice(w,le),w=le,ne}}else{if(H===-1||De==="d"||n.dlen(ue.d)-w<=H)return ne={d:G(ue.d,w)},++_,w=0,ne;{let le=G(ue.d,w,w+H);return w+=H,{d:le}}}},peek:()=>f[_]}},o=f=>(f.length>0&&typeof f[f.length-1]=="number"&&f.pop(),f);function c(f,_,w){if(w!=="left"&&w!=="right")throw Error("side ("+w+") must be 'left' or 'right'");t(f),t(_);const L=[],z=l(L),{take:H,peek:De}=v(f);for(let ne=0;ne<_.length;ne++){const le=_[ne];let pe,Ae;switch(typeof le){case"number":for(pe=le;pe>0;)Ae=H(pe,"i"),z(Ae),typeof Ae!="string"&&(pe-=E(Ae));break;case"string":w==="left"&&typeof De()=="string"&&z(H(-1)),z(e.strPosToUni(le));break;case"object":for(pe=n.dlen(le.d);pe>0;)switch(Ae=H(pe,"i"),typeof Ae){case"number":pe-=Ae;break;case"string":z(Ae);break;case"object":pe-=n.dlen(Ae.d)}break}}let ue;for(;ue=H(-1);)z(ue);return o(L)}function h(f,_){t(f),t(_);const w=[],L=l(w),{take:z}=v(f);for(let De=0;De<_.length;De++){const ue=_[De];let ne,le;switch(typeof ue){case"number":for(ne=ue;ne>0;)le=z(ne,"d"),L(le),typeof le!="object"&&(ne-=E(le));break;case"string":L(ue);break;case"object":ne=n.dlen(ue.d);let pe=0;for(;pe<ne;)switch(le=z(ne-pe,"d"),typeof le){case"number":L({d:G(ue.d,pe,pe+le)}),pe+=le;break;case"string":pe+=e.strPosToUni(le);break;case"object":L(le)}break}}let H;for(;H=z(-1);)L(H);return o(w)}const j=(f,_)=>{let w=0;for(let L=0;L<_.length&&f>w;L++){const z=_[L];switch(typeof z){case"number":{w+=z;break}case"string":const H=e.strPosToUni(z);w+=H,f+=H;break;case"object":f-=Math.min(n.dlen(z.d),f-w);break}}return f},Z=(f,_)=>typeof f=="number"?j(f,_):f.map(w=>j(w,_));function ge(f,_,w){return s(f,(L,z)=>typeof L=="object"&&typeof L.d=="number"?{d:w.slice(_,z,z+L.d)}:L)}function J(f){return s(f,_=>{switch(typeof _){case"object":if(typeof _.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return _.d;case"string":return{d:_};case"number":return _}})}function Ie(f){return s(f,_=>typeof _=="object"&&typeof _.d=="string"?{d:e.strPosToUni(_.d)}:_)}function Le(f){let _=!0;return r(f,w=>{typeof w=="object"&&typeof w.d=="number"&&(_=!1)}),_}function Oe(f){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:o,normalize:a,checkOp:t,create(_=""){if(typeof _!="string")throw Error("Initial data must be a string");return f.create(_)},apply(_,w){t(w);const L=f.builder(_);for(let z=0;z<w.length;z++){const H=w[z];switch(typeof H){case"number":L.skip(H);break;case"string":L.append(H);break;case"object":L.del(n.dlen(H.d));break}}return L.build()},transform:c,compose:h,transformPosition:j,transformSelection:Z,isInvertible:Le,makeInvertible(_,w){return ge(_,w,f)},stripInvertible:Ie,invert:J,invertWithDoc(_,w){return J(ge(_,w,f))},isNoop:_=>_.length===0}}n.default=Oe}(ot)),ot}var tt={},mt;function Kt(){if(mt)return tt;mt=1,Object.defineProperty(tt,"__esModule",{value:!0});const n=ct(),e=pt();function t(r,s){return{get:r,getLength(){return r().length},insert(d,a,l){const E=e.strPosToUni(r(),d);return s([E,a],l)},remove(d,a,l){const E=e.strPosToUni(r(),d);return s([E,{d:a}],l)},_onOp(d){n.eachOp(d,(a,l,E)=>{switch(typeof a){case"string":this.onInsert&&this.onInsert(E,a);break;case"object":const G=n.dlen(a.d);this.onRemove&&this.onRemove(E,G)}})},onInsert:null,onRemove:null}}return tt.default=t,t.provides={text:!0},tt}var wt;function Ft(){return wt||(wt=1,function(n){var e=Ce&&Ce.__createBinding||(Object.create?function(c,h,j,Z){Z===void 0&&(Z=j),Object.defineProperty(c,Z,{enumerable:!0,get:function(){return h[j]}})}:function(c,h,j,Z){Z===void 0&&(Z=j),c[Z]=h[j]}),t=Ce&&Ce.__setModuleDefault||(Object.create?function(c,h){Object.defineProperty(c,"default",{enumerable:!0,value:h})}:function(c,h){c.default=h}),r=Ce&&Ce.__importStar||function(c){if(c&&c.__esModule)return c;var h={};if(c!=null)for(var j in c)Object.hasOwnProperty.call(c,j)&&e(h,c,j);return t(h,c),h},s=Ce&&Ce.__importDefault||function(c){return c&&c.__esModule?c:{default:c}};Object.defineProperty(n,"__esModule",{value:!0}),n.type=n.remove=n.insert=void 0;const d=pt(),a=r(ct()),l=s(Kt()),E={create(c){return c},toString(c){return c},builder(c){if(typeof c!="string")throw Error("Invalid document snapshot: "+c);const h=[];return{skip(j){let Z=d.uniToStrPos(c,j);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(j){h.push(j)},del(j){c=c.slice(d.uniToStrPos(c,j))},build(){return h.join("")+c}}},slice:a.uniSlice},G=a.default(E),v=Object.assign(Object.assign({},G),{api:l.default});n.type=v,n.insert=(c,h)=>h.length===0?[]:c===0?[h]:[c,h],n.remove=(c,h)=>a.dlen(h)===0?[]:c===0?[{d:h}]:[c,{d:h}];var o=ct();Object.defineProperty(n,"makeType",{enumerable:!0,get:function(){return o.default}})}(st)),st}(function(n){var e=Ce&&Ce.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(n,"__esModule",{value:!0}),n.editOp=n.replaceOp=n.insertOp=n.moveOp=n.removeOp=n.type=void 0;const t=e(ut),r=e(ft),s=ht,d=gt;function a(i,u){if(!i)throw new Error(u)}n.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:s.readCursor,writeCursor:s.writeCursor,create:i=>i,isNoop:i=>i==null,setDebug(i){},registerSubtype:J,checkValidOp:z,normalize:H,apply:De,transformPosition:ue,compose:ne,tryTransform:rt,transform:Tt,makeInvertible:Ae,invert:le,invertWithDoc:Rt,RM_UNEXPECTED_CONTENT:d.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:d.ConflictType.DROP_COLLISION,BLACKHOLE:d.ConflictType.BLACKHOLE,transformNoConflict:(i,u,y)=>vt(()=>!0,i,u,y),typeAllowingConflictsPred:i=>Object.assign(Object.assign({},n.type),{transform:(u,y,D)=>vt(i,u,y,D)})};const l=i=>i?i.getComponent():null;function E(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,v=i=>i&&(i.p!=null||i.r!==void 0),o=i=>i&&(i.d!=null||i.i!==void 0);function c(i,u){return a(i!=null),typeof u=="number"?(a(Array.isArray(i),"Invalid key - child is not an array"),(i=i.slice()).splice(u,1)):(a(E(i),"Invalid key - child is not an object"),delete(i=Object.assign({},i))[u]),i}function h(i,u,y){return typeof u=="number"?(a(i!=null,"Container is missing for key"),a(Array.isArray(i),"Cannot use numerical key for object container"),a(i.length>=u,"Cannot insert into out of bounds index"),i.splice(u,0,y)):(a(E(i),"Cannot insert into missing item"),a(i[u]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),i[u]=y),y}n.removeOp=(i,u=!0)=>s.writeCursor().writeAtPath(i,"r",u).get(),n.moveOp=(i,u)=>s.writeCursor().writeMove(i,u).get(),n.insertOp=(i,u)=>s.writeCursor().writeAtPath(i,"i",u).get(),n.replaceOp=(i,u,y)=>s.writeCursor().at(i,D=>{D.write("r",u),D.write("i",y)}).get(),n.editOp=(i,u,y,D=!1)=>s.writeCursor().at(i,b=>_(b,u,y,D)).get();const j=(i,u)=>i!=null&&(typeof u=="number"?Array.isArray(i):typeof i=="object"),Z=(i,u)=>j(i,u)?i[u]:void 0,ge={};function J(i){let u=i.type?i.type:i;u.name&&(ge[u.name]=u),u.uri&&(ge[u.uri]=u)}const Ie=i=>{const u=ge[i];if(u)return u;throw Error("Missing type: "+i)};J(Ft());const Le=(i,u)=>i+u;J({name:"number",apply:Le,compose:Le,invert:i=>-i,transform:i=>i});const Oe=i=>i==null?null:i.et?Ie(i.et):i.es?ge["text-unicode"]:i.ena!=null?ge.number:null,f=i=>i.es?i.es:i.ena!=null?i.ena:i.e,_=(i,u,y,D=!1)=>{const[b,C]=typeof u=="string"?[Ie(u),u]:[u,u.name];!D&&b.isNoop&&b.isNoop(y)||(C==="number"?i.write("ena",y):C==="text-unicode"?i.write("es",y):(i.write("et",C),i.write("e",y)))};function w(i){a(typeof i=="number"),a(i>=0),a(i===(0|i))}function L(i){typeof i=="number"?w(i):a(typeof i=="string")}function z(i){if(i===null)return;const u=new Set,y=new Set,D=C=>{let $=!0,T=!1;for(let g in C){const O=C[g];if($=!1,a(g==="p"||g==="r"||g==="d"||g==="i"||g==="e"||g==="es"||g==="ena"||g==="et","Invalid component item '"+g+"'"),g==="p")w(O),a(!u.has(O)),u.add(O),a(C.r===void 0);else if(g==="d")w(O),a(!y.has(O)),y.add(O),a(C.i===void 0);else if(g==="e"||g==="es"||g==="ena"){a(!T),T=!0;const m=Oe(C);a(m,"Missing type in edit"),m.checkValidOp&&m.checkValidOp(f(C))}}a(!$)},b=(C,$,T)=>{if(!Array.isArray(C))throw Error("Op must be null or a list");if(C.length===0)throw Error("Empty descent");$||L(C[0]);let g=1,O=0,m=0;for(let I=0;I<C.length;I++){const k=C[I];if(a(k!=null),Array.isArray(k)){const W=b(k,!1);if(O){const p=typeof m,U=typeof W;p===U?a(m<W,"descent keys are not in order"):a(p==="number"&&U==="string")}m=W,O++,g=3}else typeof k=="object"?(a(g===1,`Prev not scalar - instead ${g}`),D(k),g=2):(a(g!==3),L(k),a(s.isValidPathItem(k),"Invalid path key"),g=1)}return a(O!==1,"Operation makes multiple descents. Remove some []"),a(g===2||g===3),C[0]};b(i,!0),a(u.size===y.size,"Mismatched picks and drops in op");for(let C=0;C<u.size;C++)a(u.has(C)),a(y.has(C))}function H(i){let u=0,y=[];const D=s.writeCursor();return D.mergeTree(i,(b,C)=>{const $=Oe(b);if($){const g=f(b);_(C,$,$.normalize?$.normalize(g):g)}for(const g of["r","p","i","d"])if(b[g]!==void 0){const O=g==="p"||g==="d"?(T=b[g],y[T]==null&&(y[T]=u++),y[T]):b[g];C.write(g,O)}var T}),D.get()}function De(i,u){if(z(u),u===null)return i;const y=[];return function D(b,C){let $=b,T=0,g={root:b},O=0,m=g,I="root";function k(){for(;O<T;O++){let W=C[O];typeof W!="object"&&(a(j(m,I)),m=m[I]=G(m[I]),I=W)}}for(;T<C.length;T++){const W=C[T];if(Array.isArray(W)){const p=D($,W);p!==$&&p!==void 0&&(k(),$=m[I]=p)}else if(typeof W=="object"){W.d!=null?(k(),$=h(m,I,y[W.d])):W.i!==void 0&&(k(),$=h(m,I,W.i));const p=Oe(W);if(p)k(),$=m[I]=p.apply($,f(W));else if(W.e!==void 0)throw Error("Subtype "+W.et+" undefined")}else $=Z($,W)}return g.root}(i=function D(b,C){const $=[];let T=0;for(;T<C.length;T++){const I=C[T];if(Array.isArray(I))break;typeof I!="object"&&($.push(b),b=Z(b,I))}for(let I=C.length-1;I>=T;I--)b=D(b,C[I]);for(--T;T>=0;T--){const I=C[T];if(typeof I!="object"){const k=$.pop();b=b===Z(k,I)?k:b===void 0?c(k,I):(O=I,m=b,(g=G(g=k))[O]=m,g)}else v(I)&&(a(b!==void 0,"Cannot pick up or remove undefined"),I.p!=null&&(y[I.p]=b),b=void 0)}var g,O,m;return b}(i,u),u)}function ue(i,u){i=i.slice(),z(u);const y=s.readCursor(u);let D,b,C=!1;const $=[];for(let g=0;;g++){const O=i[g],m=y.getComponent();if(m&&(m.r!==void 0?C=!0:m.p!=null&&(C=!1,D=m.p,b=g)),g>=i.length)break;let I=0;const k=s.advancer(y,void 0,(p,U)=>{v(U)&&I++});$.unshift(k);const W=k(O);if(typeof O=="number"&&(i[g]-=I),!W)break}if($.forEach(g=>g.end()),C)return null;const T=()=>{let g=0;if(D!=null){const O=y.getPath();g=O.length,i=O.concat(i.slice(b))}for(;g<i.length;g++){const O=i[g],m=l(y),I=Oe(m);if(I){const p=f(m);I.transformPosition&&(i[g]=I.transformPosition(i[g],p));break}let k=0;const W=s.advancer(y,(p,U)=>o(U)?~(p-k):p-k,(p,U)=>{o(U)&&k++})(O);if(typeof O=="number"&&(i[g]+=k),!W)break}};return D!=null?y.eachDrop(null,g=>{g===D&&T()}):T(),i}function ne(i,u){if(z(i),z(u),i==null)return u;if(u==null)return i;let y=0;const D=s.readCursor(i),b=s.readCursor(u),C=s.writeCursor(),$=[],T=[],g=[],O=[],m=[],I=[],k=new Set;D.traverse(null,p=>{p.p!=null&&(g[p.p]=D.clone())}),b.traverse(null,p=>{p.d!=null&&(O[p.d]=b.clone())});const W=s.writeCursor();return function p(U,re,te,K,se,$e,be,_e){a(re||te);const oe=l(re),Pe=l(te),Me=!!Pe&&Pe.r!==void 0,He=!!oe&&oe.i!==void 0,Se=oe?oe.d:null,Ee=Pe?Pe.p:null,Ge=($e||Me)&&Ee==null;if(Ee!=null)K=O[Ee],be=T[Ee]=new s.WriteCursor;else if(Pe&&Pe.r!==void 0)K=null;else{const P=l(K);P&&P.d!=null&&(K=null)}const Q=l(K);if(Se!=null)if(U=g[Se],_e=$[Se]=new s.WriteCursor,Ge)$e&&!Me&&_e.write("r",!0);else{const P=m[Se]=y++;be.write("d",P)}else if(oe&&oe.i!==void 0)U=null;else{const P=l(U);P&&P.p!=null&&(U=null)}let S;He?(a(se===void 0),S=oe.i):S=se;const B=(Ee==null?!He||$e||Me:S===void 0)?null:be.getComponent();if(Ee!=null){if(!(se!==void 0||He)){const P=Se!=null?m[Se]:y++;I[Ee]=P,_e.write("p",P)}}else Me&&(He||se!==void 0||(Pe.r,_e.write("r",Pe.r)));const M=Ge?null:Oe(oe),A=Oe(Q);if((M||A)&&(M&&M.name,A&&A.name),M&&A){a(M===A);const P=f(oe),x=f(Q),he=M.compose(P,x);_(be,M,he),k.add(Q)}else M?_(be,M,f(oe)):A&&(_(be,A,f(Q)),k.add(Q));const N=typeof S=="object"&&S!=null;let X=!1,Y=0,ee=0,fe=0,de=0,ae=0;const ye=s.advancer(K,(P,x)=>o(x)?de-P-1:P-de,(P,x)=>{o(x)&&de++}),q=s.advancer(U,(P,x)=>v(x)?Y-P-1:P-Y,(P,x)=>{v(x)&&Y++});if(s.eachChildOf(re,te,(P,x,he)=>{let me,We,Ke=P,Ue=P,Je=P;if(typeof P=="number"){let ve=P+fe;We=ye(ve),Ue=ve+de;let ce=P+ee;me=q(ce),o(l(We))&&(me=null),Ke=ce+Y,Je=P+ae,a(Ke>=0,"p1PickKey is negative"),a(Ue>=0,"p2DropKey is negative");const Ne=o(l(x)),Be=v(l(he));(Ne||Be&&!Ge)&&ae--,Ne&&ee--,Be&&fe--}else me=q(P),We=ye(P);_e.descend(Ke),be.descend(Ue);const Xe=N&&!o(l(x))?S[Je]:void 0,Re=p(me,x,he,We,Xe,Ge,be,_e);var Te,R,ie;N&&!Ge?Xe!==Re&&(X||(S=Array.isArray(S)?S.slice():Object.assign({},S),X=!0),Te=S,ie=Re,typeof(R=Je)=="number"?(a(Array.isArray(Te)),a(R<Te.length)):(a(!Array.isArray(Te)),a(Te[R]!==void 0)),ie===void 0?typeof R=="number"?Te.splice(R,1):delete Te[R]:Te[R]=ie):a(Re===void 0),be.ascend(),_e.ascend()}),q.end(),ye.end(),B!=null)B.i=S;else if(!$e&&!Me&&Ee==null)return S}(D,D.clone(),b,b.clone(),void 0,!1,C,W),C.reset(),C.mergeTree(W.get()),C.reset(),C.get(),$.map(p=>p.get()),T.map(p=>p.get()),D.traverse(C,(p,U)=>{const re=p.p;if(re!=null){const te=m[re];te!=null&&U.write("p",te);const K=$[re];K&&K.get(),K&&U.mergeTree(K.get())}else p.r!==void 0&&U.write("r",p.r)}),C.reset(),C.get(),b.traverse(C,(p,U)=>{const re=p.d;if(re!=null){const K=I[re];K!=null&&U.write("d",K);const se=T[re];se&&U.mergeTree(se.get())}else p.i!==void 0&&U.write("i",p.i);const te=Oe(p);te&&!k.has(p)&&_(U,te,f(p))}),C.get()}function le(i){if(i==null)return null;const u=new s.ReadCursor(i),y=new s.WriteCursor;let D;const b=[],C=[];return function $(T,g,O){const m=T.getComponent();let I,k=!1;if(m){m.p!=null&&(g.write("d",m.p),b[m.p]=T.clone()),m.r!==void 0&&g.write("i",m.r),m.d!=null&&(g.write("p",m.d),O=void 0),m.i!==void 0&&(O=I=m.i);const p=Oe(m);p&&(O===void 0?(D||(D=new Set),D.add(m)):(f(m),O=p.apply(O,f(m)),k=!0))}let W=0;for(const p of T){g.descend(p);const U=typeof p=="number"?p-W:p,re=Z(O,U);o(T.getComponent())&&W++;const te=$(T,g,re);if(O!==void 0&&te!==void 0){if(k||(k=!0,O=G(O)),!j(O,U))throw Error("Cannot modify child - invalid operation");O[U]=te}g.ascend()}if(I===void 0)return k?O:void 0;g.write("r",O)}(u,y,void 0),D&&(y.reset(),function $(T,g,O){const m=g.getComponent();if(m){const p=m.d;if(p!=null&&(T=b[p],O=C[p]=s.writeCursor()),D.has(m)){const U=Oe(m);if(!U.invert)throw Error(`Cannot invert subtype ${U.name}`);_(O,U,U.invert(f(m)))}}let I=0,k=0;const W=s.advancer(T,(p,U)=>v(U)?I-p-1:p-I,(p,U)=>{v(U)&&I++});for(const p of g)if(typeof p=="number"){const U=p-k,re=W(U),te=U+I;O.descend(te),$(re,g,O),o(g.getComponent())&&k++,O.ascend()}else O.descend(p),$(W(p),g,O),O.ascend();W.end()}(u.clone(),u,y),C.length&&(y.reset(),u.traverse(y,($,T)=>{const g=$.p;if(g!=null){const O=C[g];O&&O.get(),O&&T.mergeTree(O.get())}}))),y.get()}const pe=(i,u)=>i.some(y=>typeof y=="object"&&(Array.isArray(y)?pe(y,u):u(y)));function Ae(i,u){if(i==null||!pe(i,g=>{var O;return g.r!==void 0||((O=Oe(g))===null||O===void 0?void 0:O.makeInvertible)!=null}))return i;const y=new s.ReadCursor(i),D=new s.WriteCursor;let b=!1;const C=[],$=[],T=(g,O,m)=>{const I=g.getComponent();let k=!1;if(I){I.d!=null&&O.write("d",I.d),I.i!==void 0&&O.write("i",I.i);const p=I.p;if(p!=null&&(C[p]=g.clone(),a(m!==void 0,"Operation picks up at an invalid key"),$[p]=m,O.write("p",I.p)),I.r!==void 0&&m===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const U=Oe(I);U&&(U.makeInvertible?b=!0:_(O,U,f(I),!0))}let W=0;for(const p of g){O.descend(p);const U=typeof p=="number"?p-W:p,re=Z(m,U),te=T(g,O,re);re!==te&&(k||(k=!0,m=G(m)),te===void 0?(m=c(m,U),typeof p=="number"&&W++):m[U]=te),O.ascend()}return I&&(I.r!==void 0?(O.write("r",r.default(m)),m=void 0):I.p!=null&&(m=void 0)),m};return T(y,D,u),D.get(),b&&(D.reset(),function g(O,m,I,k,W){const p=m.getComponent();if(p){p.i!==void 0?(k=p.i,W=!0):p.d!=null&&(k=$[p.d],O=C[p.d],W=!1,p.d);let K=Oe(p);if(K&&K.makeInvertible){const se=f(p);_(I,K,K.makeInvertible(se,k),!0)}}let U=0,re=0;const te=s.advancer(O,(K,se)=>v(se)?U-K-1:K-U,(K,se)=>{v(se)&&U++});for(const K of m)if(typeof K=="number"){const se=K-re,$e=te(se),be=se+U,_e=Z(k,W?se:be);I.descend(K),g($e,m,I,_e,W),o(m.getComponent())&&re++,I.ascend()}else{const se=Z(k,K);I.descend(K),g(te(K),m,I,se,W),I.ascend()}te.end()}(y.clone(),y,D,u,!1)),D.get()}function Rt(i,u){return le(Ae(i,u))}const nt=i=>{if(i==null)return null;const u=i.slice();for(let y=0;y<i.length;y++){const D=u[y];Array.isArray(D)&&(u[y]=nt(D))}return u};function rt(i,u,y){a(y==="left"||y==="right","Direction must be left or right");const D=y==="left"?0:1;if(u==null)return{ok:!0,result:i};z(i),z(u);let b=null;const C=[],$=[],T=[],g=[],O=[],m=[],I=[],k=[],W=[],p=[],U=[],re=[],te=[],K=[],se=[];let $e=0;const be=s.readCursor(i),_e=s.readCursor(u),oe=s.writeCursor();if(function Q(S,B=null,M){const A=l(B);A&&(A.r!==void 0?M=B.clone():A.p!=null&&(M=null,m[A.p]=S.clone()));const N=S.getComponent();let X;N&&(X=N.p)!=null&&(O[X]=B?B.clone():null,T[X]=S.clone(),M&&(p[X]=!0,W[X]=M),A&&A.p!=null&&(K[X]=A.p));const Y=s.advancer(B);for(const ee of S)Q(S,Y(ee),M);Y.end()}(_e,be,null),function Q(S,B,M,A,N){const X=M.getComponent();let Y,ee=!1;X&&((Y=X.d)!=null?(g[Y]=M.clone(),A!=null&&(se[A]==null&&(se[A]=[]),se[A].push(Y)),S=O[Y]||null,B=T[Y]||null,p[Y]?(N&&(U[Y]=!0),N=W[Y]||null):!N||D!==1&&K[Y]!=null||b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.moveOp(B.getPath(),M.getPath())}),ee=!0):X.i!==void 0&&(S=B=null,ee=!0,N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.insertOp(M.getPath(),X.i)})));const fe=l(S);fe&&(fe.r!==void 0?N=S.clone():fe.p!=null&&(fe.p,A=fe.p,N=null));const de=Oe(X);de&&N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.editOp(M.getPath(),de,f(X),!0)});let ae=0,ye=0;const q=s.advancer(B,(x,he)=>v(he)?ae-x-1:x-ae,(x,he)=>{v(he)&&ae++}),P=s.advancer(S);for(const x of M)if(typeof x=="number"){const he=x-ye,me=q(he);ye+=+Q(P(he+ae),me,M,A,N)}else{const he=q(x);Q(P(x),he,M,A,N)}return q.end(),P.end(),ee}(be,_e,_e.clone(),null,null),g.map(Q=>Q&&Q.get()),b)return{ok:!1,conflict:b};U.map(Q=>!!Q);const Pe=[];let Me=null;(function Q(S,B,M,A,N){let X=!1;const Y=l(B);if(v(Y)){const q=Y.p;q!=null?(M=g[q],A=re[q]=s.writeCursor(),X=!0,N=null):(M=null,N=B.clone())}else o(l(M))&&(M=null);const ee=S.getComponent();if(ee){const q=ee.p;q!=null?(N&&(k[q]=N),Pe[q]=N||D===1&&X?null:A.getComponent(),C[q]=S.clone(),M&&(I[q]=M.clone())):ee.r!==void 0&&(N||A.write("r",!0),(N||X)&&(Me==null&&(Me=new Set),Me.add(ee)))}let fe=0,de=0;const ae=s.advancer(B,void 0,(q,P)=>{v(P)&&fe++}),ye=s.advancer(M,(q,P)=>o(P)?~(q-de):q-de,(q,P)=>{o(P)&&de++});if(S)for(const q of S)if(typeof q=="string"){const P=ae(q),x=ye(q);A.descend(q),Q(S,P,x,A,N),A.ascend()}else{const P=ae(q),x=q-fe,he=v(l(P))?null:ye(x),me=x+de;a(me>=0),A.descend(me),Q(S,P,he,A,N),A.ascend()}ae.end(),ye.end()})(be,_e,_e.clone(),oe,null),oe.reset();let He=[];if(function Q(S,B,M,A,N,X){a(B);const Y=B.getComponent();let ee=l(A),fe=!1;const de=(R,ie,ve)=>R?n.moveOp(R.getPath(),ie.getPath()):n.insertOp(ie.getPath(),ve.i);if(o(Y)){const R=Y.d;R!=null&&($[R]=B.clone());const ie=R!=null?Pe[R]:null;let ve=!1;if(Y.i!==void 0||R!=null&&ie){let ce;ee&&(ee.i!==void 0||(ce=ee.d)!=null&&!p[ce])&&(ve=ce!=null?R!=null&&R===K[ce]:t.default(ee.i,Y.i),ve||ce!=null&&D!==1&&K[ce]!=null||b==null&&(b={type:d.ConflictType.DROP_COLLISION,op1:de(R!=null?C[R]:null,B,Y),op2:de(ce!=null?T[ce]:null,A,ee)})),ve||(X?b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:de(R!=null?C[R]:null,B,Y),op2:n.removeOp(X.getPath())}):(R!=null?(He[$e]=R,N.write("d",ie.p=$e++)):N.write("i",r.default(Y.i)),fe=!0))}else if(R!=null&&!ie){const ce=k[R];ce&&(X=ce.clone())}R!=null?(S=C[R],M=m[R],A=I[R]):Y.i!==void 0&&(S=M=null,ve||(A=null))}else v(l(S))&&(S=M=A=null);const ae=l(S),ye=l(M);if(v(ye)){const R=ye.p;ye.r!==void 0&&(!ae||ae.r===void 0)||p[R]?(A=null,X=M.clone()):R!=null&&(A=g[R],D!==1&&K[R]!=null||((N=te[R])||(N=te[R]=s.writeCursor()),N.reset(),X=null))}else!o(Y)&&o(ee)&&(A=null);ee=A!=null?A.getComponent():null;const q=Oe(Y);if(q){const R=f(Y);if(X)b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.editOp(B.getPath(),q,R,!0),op2:n.removeOp(X.getPath())});else{const ie=Oe(ee);let ve;if(ie){if(q!==ie)throw Error("Transforming incompatible types");const ce=f(ee);ve=q.transform(R,ce,y)}else ve=r.default(R);_(N,q,ve)}}let P=0,x=0,he=0,me=0,We=0,Ke=0,Ue=S!=null&&S.descendFirst(),Je=Ue;const Xe=s.advancer(M,void 0,(R,ie)=>{v(ie)&&he++});let Re=A!=null&&A.descendFirst(),Te=Re;for(const R of B)if(typeof R=="number"){let ie;const ve=o(B.getComponent()),ce=R-x;{let xe;for(;Ue&&typeof(xe=S.getKey())=="number";){xe+=P;const je=S.getComponent(),Ye=v(je);if(xe>ce||xe===ce&&(!Ye||D===0&&ve))break;if(Ye){P--;const Fe=je.p;K.includes(Fe),je.d,l(te[je.d]),v(l(te[je.d])),(je.r===void 0||Me&&Me.has(je))&&(Fe==null||!Pe[Fe]||D!==1&&K.includes(Fe))||We--}Ue=S.nextSibling()}ie=Ue&&xe===ce?S:null}const Ne=ce-P;let Be=Xe(Ne);const it=Ne-he;let et=null;{let xe,je;for(;Re&&typeof(xe=A.getKey())=="number";){je=xe-me;const Ye=A.getComponent(),Fe=o(Ye);if(je>it)break;if(je===it){if(!Fe){et=A;break}{if(D===0&&ve){et=A;break}const Ve=Be&&v(Be.getComponent());if(D===0&&Ve)break}}if(Fe){const Ve=Ye.d;K[Ve],Ye.i===void 0&&(p[Ve]||K[Ve]!=null&&D!==1)?(p[Ve]||K[Ve]!=null&&D===0)&&(me++,Ke--):me++}Re=A.nextSibling()}}const Ot=it+me+We+Ke;a(Ot>=0,"trying to descend to a negative index"),N.descend(Ot),ve&&(ie=Be=et=null,x++),Q(ie,B,Be,et,N,X)&&Ke++,N.ascend()}else{let ie;for(;Ue&&(ie=S.getKey(),typeof ie!="string"||!(ie>R||ie===R));)Ue=S.nextSibling();const ve=Ue&&ie===R?S:null,ce=Xe(R);let Ne;for(;Re&&(Ne=A.getKey(),typeof Ne!="string"||!(Ne>R||Ne===R));)Re=A.nextSibling();const Be=Re&&Ne===R?A:null;N.descend(R),Q(ve,B,ce,Be,N,X),N.ascend()}return Xe.end(),Je&&S.ascend(),Te&&A.ascend(),fe}(be,be.clone(),_e,_e.clone(),oe,null),b)return{ok:!1,conflict:b};oe.reset();const Se=(Q,S,B)=>Q.traverse(S,(M,A)=>{M.d!=null&&B(M.d,Q,A)});(p.length||re.length)&&(Se(_e,oe,(Q,S,B)=>{p[Q]&&!U[Q]&&B.write("r",!0),re[Q]&&B.mergeTree(re[Q].get())}),oe.reset());const Ee=[],Ge=[];if((te.length||p.length)&&!b){const Q=s.readCursor(nt(oe.get()));if(Se(Q,null,(S,B)=>{Ee[S]=B.clone()}),te.forEach(S=>{S&&Se(s.readCursor(S.get()),null,(B,M)=>{Ee[B]=M.clone()})}),function S(B,M,A,N,X,Y){const ee=l(M);if(ee&&v(ee))if(ee.p!=null){const P=ee.p;Ee[P].getPath(),A=Ee[P],N=Ge[P]=s.writeCursor()}else ee.r!==void 0&&(A=null);else o(l(A))&&(A=null);const fe=B.getComponent();if(fe){let P;if((P=fe.d)!=null){const x=te[P];x&&(x.get(),N.mergeTree(x.get()),A=s.readCursor(x.get()))}}let de=0,ae=0;const ye=s.advancer(M,void 0,(P,x)=>{v(x)&&de--}),q=s.advancer(A,(P,x)=>o(x)?-(P-ae)-1:P-ae,(P,x)=>{o(x)&&ae++});for(const P of B)if(typeof P=="number"){const x=ye(P),he=P+de,me=q(he),We=he+ae;N.descend(We),S(B,x,me,N),N.ascend()}else N.descend(P),S(B,ye(P),q(P),N),N.ascend();ye.end(),q.end()}(_e,Q,Q.clone(),oe),oe.reset(),b)return{ok:!1,conflict:b};if(oe.get(),Ge.length){const S=Ge.map(M=>M?M.get():null),B=s.readCursor(nt(oe.get()));if(Se(B,oe,(M,A,N)=>{const X=S[M];X&&(N.mergeTree(X),S[M]=null)}),S.find(M=>M)){const M=s.writeCursor(),A=s.writeCursor();let N=0,X=0;S.forEach(Y=>{Y!=null&&Se(s.readCursor(Y),null,ee=>{const fe=He[ee];M.writeMove(C[fe].getPath(),$[fe].getPath(),N++);const de=se[fe];de&&de.forEach(ae=>{p[ae]||D!==1&&K[ae]!=null||A.writeMove(T[ae].getPath(),g[ae].getPath(),X++)})})}),b={type:d.ConflictType.BLACKHOLE,op1:M.get(),op2:A.get()}}}}return b?{ok:!1,conflict:b}:{ok:!0,result:oe.get()}}const _t=i=>{const u=new Error("Transform detected write conflict");throw u.conflict=i,u.type=u.name="writeConflict",u};function Tt(i,u,y){const D=rt(i,u,y);if(D.ok)return D.result;_t(D.conflict)}const ze=i=>{const u=s.writeCursor();return s.readCursor(i).traverse(u,(y,D)=>{(o(y)||Oe(y))&&D.write("r",!0)}),u.get()},kt=(i,u)=>{const{type:y,op1:D,op2:b}=i;switch(y){case d.ConflictType.DROP_COLLISION:return u==="left"?[null,ze(b)]:[ze(D),null];case d.ConflictType.RM_UNEXPECTED_CONTENT:let C=!1;return s.readCursor(D).traverse(null,$=>{$.r!==void 0&&(C=!0)}),C?[null,ze(b)]:[ze(D),null];case d.ConflictType.BLACKHOLE:return[ze(D),ze(b)];default:throw Error("Unrecognised conflict: "+y)}};function vt(i,u,y,D){let b=null;for(;;){const C=rt(u,y,D);if(C.ok)return ne(b,C.result);{const{conflict:$}=C;i($)||_t($);const[T,g]=kt($,D);u=ne(H(u),T),y=ne(H(y),g),b=ne(b,g)}}}})(Dt);(function(n){var e=Ce&&Ce.__createBinding||(Object.create?function(d,a,l,E){E===void 0&&(E=l),Object.defineProperty(d,E,{enumerable:!0,get:function(){return a[l]}})}:function(d,a,l,E){E===void 0&&(E=l),d[E]=a[l]}),t=Ce&&Ce.__exportStar||function(d,a){for(var l in d)l!=="default"&&!a.hasOwnProperty(l)&&e(a,d,l)};Object.defineProperty(n,"__esModule",{value:!0}),t(Dt,n);var r=ht;Object.defineProperty(n,"ReadCursor",{enumerable:!0,get:function(){return r.ReadCursor}}),Object.defineProperty(n,"WriteCursor",{enumerable:!0,get:function(){return r.WriteCursor}});var s=gt;Object.defineProperty(n,"ConflictType",{enumerable:!0,get:function(){return s.ConflictType}})})(V);class At{constructor(){F(this,"drawingManagerData",{});F(this,"_oldDrawingManagerData",{});F(this,"_focusDrawings",[]);F(this,"_remove$",new we.Subject);F(this,"remove$",this._remove$.asObservable());F(this,"_add$",new we.Subject);F(this,"add$",this._add$.asObservable());F(this,"_update$",new we.Subject);F(this,"update$",this._update$.asObservable());F(this,"_order$",new we.Subject);F(this,"order$",this._order$.asObservable());F(this,"_group$",new we.Subject);F(this,"group$",this._group$.asObservable());F(this,"_ungroup$",new we.Subject);F(this,"ungroup$",this._ungroup$.asObservable());F(this,"_refreshTransform$",new we.Subject);F(this,"refreshTransform$",this._refreshTransform$.asObservable());F(this,"_visible$",new we.Subject);F(this,"visible$",this._visible$.asObservable());F(this,"_focus$",new we.Subject);F(this,"focus$",this._focus$.asObservable());F(this,"_featurePluginUpdate$",new we.Subject);F(this,"featurePluginUpdate$",this._featurePluginUpdate$.asObservable());F(this,"_featurePluginAdd$",new we.Subject);F(this,"featurePluginAdd$",this._featurePluginAdd$.asObservable());F(this,"_featurePluginRemove$",new we.Subject);F(this,"featurePluginRemove$",this._featurePluginRemove$.asObservable());F(this,"_featurePluginOrderUpdate$",new we.Subject);F(this,"featurePluginOrderUpdate$",this._featurePluginOrderUpdate$.asObservable());F(this,"_featurePluginGroupUpdate$",new we.Subject);F(this,"featurePluginGroupUpdate$",this._featurePluginGroupUpdate$.asObservable());F(this,"_featurePluginUngroupUpdate$",new we.Subject);F(this,"featurePluginUngroupUpdate$",this._featurePluginUngroupUpdate$.asObservable());F(this,"_visible",!0);F(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(t=>{const r=this._getCurrentBySearch(t);r!=null&&(r.transform=t.transform,r.transforms=t.transforms,r.isMultiTransform=t.isMultiTransform)}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return this.drawingManagerData[e]||{}}removeDrawingDataForUnit(e){const t=this.drawingManagerData[e];if(t==null)return;delete this.drawingManagerData[e];const r=[];Object.keys(t).forEach(s=>{const d=t[s];(d==null?void 0:d.data)!=null&&Object.keys(d.data).forEach(a=>{r.push({unitId:e,subUnitId:s,drawingId:a})})}),r.length>0&&this.removeNotification(r)}registerDrawingData(e,t){this.drawingManagerData[e]=t}initializeNotification(e){const t=[],r=this.drawingManagerData[e];r!=null&&(Object.keys(r).forEach(s=>{this._establishDrawingMap(e,s);const d=r[s];Object.keys(d.data).forEach(a=>{const l=d.data[a];l.unitId=e,l.subUnitId=s,t.push(l)})}),t.length>0&&this.addNotification(t))}getDrawingData(e,t){return this._getDrawingData(e,t)}setDrawingData(e,t,r){this.drawingManagerData[e][t].data=r}getBatchAddOp(e){const t=[],r=[],s=[];e.forEach(G=>{const{op:v,invertOp:o}=this._addByParam(G);t.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),r.push(v),s.push(o)});const d=r.reduce(V.type.compose,null),a=s.reduce(V.type.compose,null),{unitId:l,subUnitId:E}=e[0];return{undo:a,redo:d,unitId:l,subUnitId:E,objects:t}}getBatchRemoveOp(e){const t=[],r=[];e.forEach(E=>{const{op:G,invertOp:v}=this._removeByParam(E);t.unshift(G),r.push(v)});const s=t.reduce(V.type.compose,null),d=r.reduce(V.type.compose,null),{unitId:a,subUnitId:l}=e[0];return{undo:d,redo:s,unitId:a,subUnitId:l,objects:e}}getBatchUpdateOp(e){const t=[],r=[],s=[];e.forEach(G=>{const{op:v,invertOp:o}=this._updateByParam(G);t.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),r.push(v),s.push(o)});const d=r.reduce(V.type.compose,null),a=s.reduce(V.type.compose,null),{unitId:l,subUnitId:E}=e[0];return{undo:a,redo:d,unitId:l,subUnitId:E,objects:t}}removeNotification(e){this._remove$.next(e)}addNotification(e){this._add$.next(e)}updateNotification(e){this._update$.next(e)}orderNotification(e){this._order$.next(e)}groupUpdateNotification(e){this._group$.next(e)}ungroupUpdateNotification(e){this._ungroup$.next(e)}refreshTransformNotification(e){this._refreshTransform$.next(e)}getGroupDrawingOp(e){const t=[],{unitId:r,subUnitId:s}=e[0].parent;e.forEach(l=>{t.push(this._getGroupDrawingOp(l))});const d=t.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:r,subUnitId:s,objects:e}}getUngroupDrawingOp(e){const t=[],{unitId:r,subUnitId:s}=e[0].parent;e.forEach(l=>{t.push(this._getUngroupDrawingOp(l))});const d=t.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:r,subUnitId:s,objects:e}}getDrawingsByGroup(e){const{unitId:t,subUnitId:r,drawingId:s}=e;if(this.getDrawingByParam({unitId:t,subUnitId:r,drawingId:s})==null)return[];const a=this._getDrawingData(t,r),l=[];return Object.keys(a).forEach(E=>{const G=a[E];G.groupId===s&&l.push(G)}),l}_getGroupDrawingOp(e){const{parent:t,children:r}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];l.push(V.insertOp([s,d,"data",a],t));let E=Number.NEGATIVE_INFINITY;return r.forEach(G=>{const{unitId:v,subUnitId:o,drawingId:c}=G,h=this._hasDrawingOrder({unitId:v,subUnitId:o,drawingId:c});E=Math.max(E,h),l.push(...this._getUpdateParamCompareOp(G,this.getDrawingByParam({unitId:v,subUnitId:o,drawingId:c})))}),E===Number.NEGATIVE_INFINITY&&(E=this._getDrawingOrder(s,d).length),l.push(V.insertOp([s,d,"order",E],a)),l.reduce(V.type.compose,null)}_getUngroupDrawingOp(e){const{parent:t,children:r}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];return r.forEach(E=>{const{unitId:G,subUnitId:v,drawingId:o}=E;l.push(...this._getUpdateParamCompareOp(E,this.getDrawingByParam({unitId:G,subUnitId:v,drawingId:o})))}),l.push(V.removeOp([s,d,"data",a],!0)),l.push(V.removeOp([s,d,"order",this._getDrawingOrder(s,d).indexOf(a)],!0)),l.reduce(V.type.compose,null)}applyJson1(e,t,r){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=V.type.apply(this.drawingManagerData,r)}featurePluginUpdateNotification(e){this._featurePluginUpdate$.next(e)}featurePluginOrderUpdateNotification(e){this._featurePluginOrderUpdate$.next(e)}featurePluginAddNotification(e){this._featurePluginAdd$.next(e)}featurePluginRemoveNotification(e){this._featurePluginRemove$.next(e)}featurePluginGroupUpdateNotification(e){this._featurePluginGroupUpdate$.next(e)}featurePluginUngroupUpdateNotification(e){this._featurePluginUngroupUpdate$.next(e)}getDrawingByParam(e){return this._getCurrentBySearch(e)}getOldDrawingByParam(e){return this._getOldBySearch(e)}getDrawingOKey(e){const[t,r,s]=e.split("#-#");return this._getCurrentBySearch({unitId:t,subUnitId:r,drawingId:s})}focusDrawing(e){if(e==null){this._focusDrawings=[],this._focus$.next([]);return}const t=[];e.forEach(r=>{var E;const{unitId:s,subUnitId:d,drawingId:a}=r,l=(E=this._getDrawingData(s,d))==null?void 0:E[a];l!=null&&t.push(l)}),t.length>0&&(this._focusDrawings=t,this._focus$.next(t))}getFocusDrawings(){const e=[];return this._focusDrawings.forEach(t=>{var l;const{unitId:r,subUnitId:s,drawingId:d}=t,a=(l=this._getDrawingData(r,s))==null?void 0:l[d];a!=null&&e.push(a)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,r){this.drawingManagerData[e][t].order=r}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){const{unitId:t,subUnitId:r,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,r),l=[...s];s.forEach(v=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:r,drawingId:v});if(o===-1||o===a.length-1)return;const c=V.moveOp([t,r,"order",o],[t,r,"order",o+1]);d.push(c),l.includes(a[o+1])||l.push(a[o+1])});const E=d.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:r,objects:{...e,drawingIds:l}}}getBackwardDrawingOp(e){const{unitId:t,subUnitId:r,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,r),l=[...s];s.forEach(v=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:r,drawingId:v});if(o===-1||o===0)return;const c=V.moveOp([t,r,"order",o],[t,r,"order",o-1]);d.push(c),l.includes(a[o-1])||l.push(a[o-1])});const E=d.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:r,objects:{...e,drawingIds:l}}}getFrontDrawingsOp(e){const{unitId:t,subUnitId:r,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,r,s),a=[...s],l=this.getDrawingOrder(t,r),E=[];d.forEach(o=>{const{drawingId:c}=o,h=this._getDrawingCount(t,r)-1,j=V.moveOp([t,r,"order",this._getDrawingOrder(t,r).indexOf(c)],[t,r,"order",h]);E.push(j),a.includes(l[h])||a.push(l[h])});const G=E.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:t,subUnitId:r,objects:{...e,drawingIds:a}}}getBackDrawingsOp(e){const{unitId:t,subUnitId:r,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,r,s,!0),a=[...s],l=this.getDrawingOrder(t,r),E=[];d.forEach(o=>{const{drawingId:c}=o,h=V.moveOp([t,r,"order",this._getDrawingOrder(t,r).indexOf(c)],[t,r,"order",0]);E.push(h),a.includes(l[0])||a.push(l[0])});const G=E.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:t,subUnitId:r,objects:{...e,drawingIds:a}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,t,r,s=!1){return r.map(d=>{const a=this._hasDrawingOrder({unitId:e,subUnitId:t,drawingId:d});return{drawingId:d,zIndex:a}}).sort(s===!1?ke.sortRules:ke.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;const{unitId:t,subUnitId:r,drawingId:s}=e;return this._establishDrawingMap(t,r),this._getDrawingOrder(t,r).indexOf(s)}_getCurrentBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:r,drawingId:s}=e;return(l=(a=(d=this.drawingManagerData[t])==null?void 0:d[r])==null?void 0:a.data)==null?void 0:l[s]}_getOldBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:r,drawingId:s}=e;return(l=(a=(d=this._oldDrawingManagerData[t])==null?void 0:d[r])==null?void 0:a.data)==null?void 0:l[s]}_establishDrawingMap(e,t,r){var s;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),r==null?null:(s=this.drawingManagerData[e][t].data)==null?void 0:s[r]}_addByParam(e){const{unitId:t,subUnitId:r,drawingId:s}=e;this._establishDrawingMap(t,r,s);const d=V.insertOp([t,r,"data",s],e),a=V.insertOp([t,r,"order",this._getDrawingOrder(t,r).length],s),l=[d,a].reduce(V.type.compose,null),E=V.type.invertWithDoc(l,this.drawingManagerData);return{op:l,invertOp:E}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};const{unitId:t,subUnitId:r,drawingId:s}=e;if(this._establishDrawingMap(t,r,s)==null)return{op:[],invertOp:[]};const a=V.removeOp([t,r,"data",s],!0),l=V.removeOp([t,r,"order",this._getDrawingOrder(t,r).indexOf(s)],!0),E=[a,l].reduce(V.type.compose,null),G=V.type.invertWithDoc(E,this.drawingManagerData);return{op:E,invertOp:G}}_updateByParam(e){const{unitId:t,subUnitId:r,drawingId:s}=e,d=this._establishDrawingMap(t,r,s);if(d==null)return{op:[],invertOp:[]};const l=this._getUpdateParamCompareOp(e,d).reduce(V.type.compose,null),E=V.type.invertWithDoc(l,this.drawingManagerData);return{op:l,invertOp:E}}_getUpdateParamCompareOp(e,t){const{unitId:r,subUnitId:s,drawingId:d}=e,a=[];return Object.keys(e).forEach(l=>{const E=e[l],G=t[l];G!==E&&a.push(V.replaceOp([r,s,"data",d,l],G,E))}),a}_getDrawingData(e,t){var r,s;return((s=(r=this.drawingManagerData[e])==null?void 0:r[t])==null?void 0:s.data)||{}}_getDrawingOrder(e,t){var r,s;return((s=(r=this.drawingManagerData[e])==null?void 0:r[t])==null?void 0:s.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(e){this._visible=e}setDrawingEditable(e){this._editable=e}}class Pt extends At{}function Vt({unitId:n,subUnitId:e,drawingId:t},r){return typeof r=="number"?`${n}#-#${e}#-#${t}#-#${r}`:`${n}#-#${e}#-#${t}`}const qt=async n=>new Promise((e,t)=>{const r=new Image;r.src=n,r.onload=()=>{e({width:r.width,height:r.height,image:r})},r.onerror=s=>{t(s)}});var Qe=(n=>(n.URL="URL",n.UUID="UUID",n.BASE64="BASE64",n))(Qe||{}),Ze=(n=>(n.SUCCUSS="0",n.ERROR_EXCEED_SIZE="1",n.ERROR_IMAGE_TYPE="2",n.ERROR_UPLOAD_COUNT_LIMIT="3",n.ERROR_IMAGE="4",n))(Ze||{});const St=ke.createIdentifier("core.image-io.service");class Mt{constructor(){F(this,"_waitCount",0);F(this,"_change$",new we.Subject);F(this,"change$",this._change$);F(this,"_imageSourceCache",new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,t){if(t===Qe.BASE64){const r=new Image;return r.src=e,r}return this._imageSourceCache.get(e)}addImageSourceCache(e,t,r){t===Qe.BASE64||r==null||this._imageSourceCache.set(e,r)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((t,r)=>{if(!Et.includes(e.type)){r(new Error(Ze.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>Ct){r(new Error(Ze.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}const s=new FileReader;s.readAsDataURL(e),s.onload=d=>{var E;const a=(E=d.target)==null?void 0:E.result;if(a==null){r(new Error(Ze.ERROR_IMAGE)),this._decreaseWaiting();return}const l=ke.Tools.generateRandomId(6);t({imageId:l,imageSourceType:Qe.BASE64,source:a,base64Cache:a,status:Ze.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}}const zt="__default_document_sub_component_id20231101__";var Ut=(n=>(n[n.forward=0]="forward",n[n.backward=1]="backward",n[n.front=2]="front",n[n.back=3]="back",n))(Ut||{}),Nt=(n=>(n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n[n.DRAWING_IMAGE=0]="DRAWING_IMAGE",n[n.DRAWING_SHAPE=1]="DRAWING_SHAPE",n[n.DRAWING_CHART=2]="DRAWING_CHART",n[n.DRAWING_TABLE=3]="DRAWING_TABLE",n[n.DRAWING_SMART_ART=4]="DRAWING_SMART_ART",n[n.DRAWING_VIDEO=5]="DRAWING_VIDEO",n[n.DRAWING_GROUP=6]="DRAWING_GROUP",n[n.DRAWING_UNIT=7]="DRAWING_UNIT",n[n.DRAWING_DOM=8]="DRAWING_DOM",n))(Nt||{});const jt=ke.createIdentifier("univer.drawing-manager.service"),Xt="drawing.config",Yt={};var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(n,e,t,r)=>{for(var s=r>1?void 0:r?Jt(e,t):e,d=n.length-1,a;d>=0;d--)(a=n[d])&&(s=(r?a(e,t,s):a(s))||s);return r&&s&&Zt(e,t,s),s},It=(n,e)=>(t,r)=>e(t,r,n);const en="UNIVER_DRAWING_PLUGIN";var at;exports.UniverDrawingPlugin=(at=class extends ke.Plugin{constructor(e=Yt,t,r){super(),this._config=e,this._injector=t,this._configService=r;const{...s}=this._config;this._configService.setConfig(Xt,s)}onStarting(){this._initDependencies()}_initDependencies(){var r;const e=[[St,{useClass:Mt}],[jt,{useClass:Pt}]];ke.mergeOverrideWithDependencies(e,(r=this._config)==null?void 0:r.override).forEach(s=>this._injector.add(s))}},F(at,"pluginName",en),at);exports.UniverDrawingPlugin=Qt([It(1,ke.Inject(ke.Injector)),It(2,ke.IConfigService)],exports.UniverDrawingPlugin);exports.ArrangeTypeEnum=Ut;exports.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=zt;exports.DRAWING_IMAGE_ALLOW_IMAGE_LIST=Et;exports.DRAWING_IMAGE_ALLOW_SIZE=Ct;exports.DRAWING_IMAGE_COUNT_LIMIT=xt;exports.DRAWING_IMAGE_HEIGHT_LIMIT=Bt;exports.DRAWING_IMAGE_WIDTH_LIMIT=Wt;exports.DrawingManagerService=Pt;exports.DrawingTypeEnum=Nt;exports.IDrawingManagerService=jt;exports.IImageIoService=St;exports.ImageIoService=Mt;exports.ImageSourceType=Qe;exports.ImageUploadStatusType=Ze;exports.UnitDrawingService=At;exports.getDrawingShapeKeyByDrawingSearch=Vt;exports.getImageSize=qt;
|