@univerjs/drawing 0.2.4 → 0.2.5
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var $t=Object.defineProperty;var Wt=(n,e,t)=>e in n?$t(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var F=(n,e,t)=>Wt(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const we=require("rxjs"),Qe=require("@univerjs/core"),nt=require("@wendellhu/redi"),Gt=500,Bt=500,xt=10,Ct=5*1024*1024,Et=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"];var Ce=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},V={},Dt={},dt={};Object.defineProperty(dt,"__esModule",{value:!0});function Lt(n,e){if(Array.isArray(e))return!1;for(let t in n)if(!ft(n[t],e[t]))return!1;for(let t in e)if(n[t]===void 0)return!1;return!0}function Ht(n,e){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!ft(n[t],e[t]))return!1;return!0}function ft(n,e){return n===e?!0:n===null||e===null||typeof n!="object"||typeof e!="object"?!1:Array.isArray(n)?Ht(n,e):Lt(n,e)}dt.default=ft;var ht={};Object.defineProperty(ht,"__esModule",{value:!0});function ct(n){if(n===null)return null;if(Array.isArray(n))return n.map(ct);if(typeof n=="object"){const e={};for(let t in n)e[t]=ct(n[t]);return e}else return n}ht.default=ct;var pt={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.eachChildOf=n.advancer=n.readCursor=n.writeCursor=n.WriteCursor=n.ReadCursor=n.isValidPathItem=void 0;function e(O,o){if(!O)throw new Error(o)}const t=O=>O!=null&&typeof O=="object"&&!Array.isArray(O),i=(O,o)=>typeof O==typeof o?O>o:typeof O=="string"&&typeof o=="number";function s(O,o){for(let c in O){const h=c;o.write(h,O[h])}}n.isValidPathItem=O=>typeof O=="number"||typeof O=="string"&&O!=="__proto__";class d{constructor(o=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=o}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,t(this.container[this.idx])&&this.idx--)}getPath(){const o=[];let c=this.container,h=this.parents.length-1,j=this.idx;for(;j>=0;)o.unshift(c[j]),j===0?(j=this.indexes[h*2],c=this.parents[h--]):j-=t(c[j-1])?2:1;return o}}class 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(i(c,this.container[this.lcIdx][0])),h=this.lcIdx+1,this.lcIdx=-1);h<this.container.length&&i(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 Y=0;for(let pe=0;pe<o.length;pe++){const J=o[pe];typeof J=="string"||typeof J=="number"?(Y++,this.descend(J)):Array.isArray(J)?this.mergeTree(J,c):typeof J=="object"&&c(J,this)}for(;Y--;)this.ascend();this.lcIdx=this.parents.length===j?h:-1}at(o,c){this.descendPath(o),c(this);for(let h=0;h<o.length;h++)this.ascend();return this}writeAtPath(o,c,h){return this.at(o,()=>this.write(c,h)),this.reset(),this}writeMove(o,c,h=0){return this.writeAtPath(o,"p",h).writeAtPath(c,"d",h)}getPath(){const o=super.getPath();return o.push(...this.pendingDescent),o}}n.WriteCursor=l,n.writeCursor=()=>new l,n.readCursor=O=>new a(O);function E(O,o,c){let h,j;j=h=O?O.descendFirst():!1;function Y(pe){let J;for(;j;){const Ie=J=O.getKey();if(pe!=null){let xe=!1;if(o&&typeof Ie=="number"&&(J=o(Ie,O.getComponent()),J<0&&(J=~J,xe=!0)),i(J,pe))return null;if(J===pe&&!xe)return O}c&&typeof J=="number"&&c(J,O.getComponent()),j=O.nextSibling()}return null}return Y.end=()=>{h&&O.ascend()},Y}n.advancer=E;function W(O,o,c){let h,j,Y,pe;for(h=j=O&&O.descendFirst(),Y=pe=o&&o.descendFirst();h||Y;){let J=h?O.getKey():null,Ie=Y?o.getKey():null;J!==null&&Ie!==null&&(i(Ie,J)?Ie=null:J!==Ie&&(J=null)),c(J==null?Ie:J,J!=null?O:null,Ie!=null?o:null),J!=null&&h&&(h=O.nextSibling()),Ie!=null&&Y&&(Y=o.nextSibling())}j&&O.ascend(),pe&&o.ascend()}n.eachChildOf=W})(pt);var gt={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.ConflictType=void 0,function(e){e[e.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",e[e.DROP_COLLISION=2]="DROP_COLLISION",e[e.BLACKHOLE=3]="BLACKHOLE"}(n.ConflictType||(n.ConflictType={}))})(gt);var ot={},Ve={},bt;function _t(){return bt||(bt=1,Object.defineProperty(Ve,"__esModule",{value:!0}),Ve.uniToStrPos=Ve.strPosToUni=void 0,Ve.strPosToUni=(n,e=n.length)=>{let t=0,i=0;for(;i<e;i++){const s=n.charCodeAt(i);s>=55296&&s<=57343&&(t++,i++)}if(i!==e)throw Error("Invalid offset - splits unicode bytes");return i-t},Ve.uniToStrPos=(n,e)=>{let t=0;for(;e>0;e--){const i=n.charCodeAt(t);t+=i>=55296&&i<=57343?2:1}return t}),Ve}var at={},mt;function ut(){return mt||(mt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.uniSlice=n.dlen=n.eachOp=void 0;const e=_t(),t=f=>{if(!Array.isArray(f))throw Error("Op must be an array of components");let _=null;for(let 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 i(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=i;function s(f,_){const w=[],L=l(w);return i(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 W=(f,_,w)=>typeof f=="number"?w==null?f-_:Math.min(f,w)-_:n.uniSlice(f,_,w),O=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:W(ue.d,w)},++_,w=0,ne;{let le=W(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}=O(f);for(let ne=0;ne<_.length;ne++){const le=_[ne];let ge,Ae;switch(typeof le){case"number":for(ge=le;ge>0;)Ae=H(ge,"i"),z(Ae),typeof Ae!="string"&&(ge-=E(Ae));break;case"string":w==="left"&&typeof De()=="string"&&z(H(-1)),z(e.strPosToUni(le));break;case"object":for(ge=n.dlen(le.d);ge>0;)switch(Ae=H(ge,"i"),typeof Ae){case"number":ge-=Ae;break;case"string":z(Ae);break;case"object":ge-=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}=O(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 ge=0;for(;ge<ne;)switch(le=z(ne-ge,"d"),typeof le){case"number":L({d:W(ue.d,ge,ge+le)}),ge+=le;break;case"string":ge+=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},Y=(f,_)=>typeof f=="number"?j(f,_):f.map(w=>j(w,_));function pe(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 xe(f){let _=!0;return i(f,w=>{typeof w=="object"&&typeof w.d=="number"&&(_=!1)}),_}function ve(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:Y,isInvertible:xe,makeInvertible(_,w){return pe(_,w,f)},stripInvertible:Ie,invert:J,invertWithDoc(_,w){return J(pe(_,w,f))},isNoop:_=>_.length===0}}n.default=ve}(at)),at}var tt={},wt;function Kt(){if(wt)return tt;wt=1,Object.defineProperty(tt,"__esModule",{value:!0});const n=ut(),e=_t();function t(i,s){return{get:i,getLength(){return i().length},insert(d,a,l){const E=e.strPosToUni(i(),d);return s([E,a],l)},remove(d,a,l){const E=e.strPosToUni(i(),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 W=n.dlen(a.d);this.onRemove&&this.onRemove(E,W)}})},onInsert:null,onRemove:null}}return tt.default=t,t.provides={text:!0},tt}var It;function Ft(){return It||(It=1,function(n){var e=Ce&&Ce.__createBinding||(Object.create?function(c,h,j,Y){Y===void 0&&(Y=j),Object.defineProperty(c,Y,{enumerable:!0,get:function(){return h[j]}})}:function(c,h,j,Y){Y===void 0&&(Y=j),c[Y]=h[j]}),t=Ce&&Ce.__setModuleDefault||(Object.create?function(c,h){Object.defineProperty(c,"default",{enumerable:!0,value:h})}:function(c,h){c.default=h}),i=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=_t(),a=i(ut()),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 Y=d.uniToStrPos(c,j);if(Y>c.length)throw Error("The op is too long for this document");h.push(c.slice(0,Y)),c=c.slice(Y)},append(j){h.push(j)},del(j){c=c.slice(d.uniToStrPos(c,j))},build(){return h.join("")+c}}},slice:a.uniSlice},W=a.default(E),O=Object.assign(Object.assign({},W),{api:l.default});n.type=O,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=ut();Object.defineProperty(n,"makeType",{enumerable:!0,get:function(){return o.default}})}(ot)),ot}(function(n){var e=Ce&&Ce.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(n,"__esModule",{value:!0}),n.editOp=n.replaceOp=n.insertOp=n.moveOp=n.removeOp=n.type=void 0;const t=e(dt),i=e(ht),s=pt,d=gt;function a(r,u){if(!r)throw new Error(u)}n.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:s.readCursor,writeCursor:s.writeCursor,create:r=>r,isNoop:r=>r==null,setDebug(r){},registerSubtype:J,checkValidOp:z,normalize:H,apply:De,transformPosition:ue,compose:ne,tryTransform:it,transform:Rt,makeInvertible:Ae,invert:le,invertWithDoc:Tt,RM_UNEXPECTED_CONTENT:d.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:d.ConflictType.DROP_COLLISION,BLACKHOLE:d.ConflictType.BLACKHOLE,transformNoConflict:(r,u,y)=>vt(()=>!0,r,u,y),typeAllowingConflictsPred:r=>Object.assign(Object.assign({},n.type),{transform:(u,y,D)=>vt(r,u,y,D)})};const l=r=>r?r.getComponent():null;function E(r){return r&&typeof r=="object"&&!Array.isArray(r)}const W=r=>Array.isArray(r)?r.slice():r!==null&&typeof r=="object"?Object.assign({},r):r,O=r=>r&&(r.p!=null||r.r!==void 0),o=r=>r&&(r.d!=null||r.i!==void 0);function c(r,u){return a(r!=null),typeof u=="number"?(a(Array.isArray(r),"Invalid key - child is not an array"),(r=r.slice()).splice(u,1)):(a(E(r),"Invalid key - child is not an object"),delete(r=Object.assign({},r))[u]),r}function h(r,u,y){return typeof u=="number"?(a(r!=null,"Container is missing for key"),a(Array.isArray(r),"Cannot use numerical key for object container"),a(r.length>=u,"Cannot insert into out of bounds index"),r.splice(u,0,y)):(a(E(r),"Cannot insert into missing item"),a(r[u]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),r[u]=y),y}n.removeOp=(r,u=!0)=>s.writeCursor().writeAtPath(r,"r",u).get(),n.moveOp=(r,u)=>s.writeCursor().writeMove(r,u).get(),n.insertOp=(r,u)=>s.writeCursor().writeAtPath(r,"i",u).get(),n.replaceOp=(r,u,y)=>s.writeCursor().at(r,D=>{D.write("r",u),D.write("i",y)}).get(),n.editOp=(r,u,y,D=!1)=>s.writeCursor().at(r,b=>_(b,u,y,D)).get();const j=(r,u)=>r!=null&&(typeof u=="number"?Array.isArray(r):typeof r=="object"),Y=(r,u)=>j(r,u)?r[u]:void 0,pe={};function J(r){let u=r.type?r.type:r;u.name&&(pe[u.name]=u),u.uri&&(pe[u.uri]=u)}const Ie=r=>{const u=pe[r];if(u)return u;throw Error("Missing type: "+r)};J(Ft());const xe=(r,u)=>r+u;J({name:"number",apply:xe,compose:xe,invert:r=>-r,transform:r=>r});const ve=r=>r==null?null:r.et?Ie(r.et):r.es?pe["text-unicode"]:r.ena!=null?pe.number:null,f=r=>r.es?r.es:r.ena!=null?r.ena:r.e,_=(r,u,y,D=!1)=>{const[b,C]=typeof u=="string"?[Ie(u),u]:[u,u.name];!D&&b.isNoop&&b.isNoop(y)||(C==="number"?r.write("ena",y):C==="text-unicode"?r.write("es",y):(r.write("et",C),r.write("e",y)))};function w(r){a(typeof r=="number"),a(r>=0),a(r===(0|r))}function L(r){typeof r=="number"?w(r):a(typeof r=="string")}function z(r){if(r===null)return;const u=new Set,y=new Set,D=C=>{let $=!0,R=!1;for(let p in C){const v=C[p];if($=!1,a(p==="p"||p==="r"||p==="d"||p==="i"||p==="e"||p==="es"||p==="ena"||p==="et","Invalid component item '"+p+"'"),p==="p")w(v),a(!u.has(v)),u.add(v),a(C.r===void 0);else if(p==="d")w(v),a(!y.has(v)),y.add(v),a(C.i===void 0);else if(p==="e"||p==="es"||p==="ena"){a(!R),R=!0;const m=ve(C);a(m,"Missing type in edit"),m.checkValidOp&&m.checkValidOp(f(C))}}a(!$)},b=(C,$,R)=>{if(!Array.isArray(C))throw Error("Op must be null or a list");if(C.length===0)throw Error("Empty descent");$||L(C[0]);let p=1,v=0,m=0;for(let I=0;I<C.length;I++){const k=C[I];if(a(k!=null),Array.isArray(k)){const G=b(k,!1);if(v){const g=typeof m,U=typeof G;g===U?a(m<G,"descent keys are not in order"):a(g==="number"&&U==="string")}m=G,v++,p=3}else typeof k=="object"?(a(p===1,`Prev not scalar - instead ${p}`),D(k),p=2):(a(p!==3),L(k),a(s.isValidPathItem(k),"Invalid path key"),p=1)}return a(v!==1,"Operation makes multiple descents. Remove some []"),a(p===2||p===3),C[0]};b(r,!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(r){let u=0,y=[];const D=s.writeCursor();return D.mergeTree(r,(b,C)=>{const $=ve(b);if($){const p=f(b);_(C,$,$.normalize?$.normalize(p):p)}for(const p of["r","p","i","d"])if(b[p]!==void 0){const v=p==="p"||p==="d"?(R=b[p],y[R]==null&&(y[R]=u++),y[R]):b[p];C.write(p,v)}var R}),D.get()}function De(r,u){if(z(u),u===null)return r;const y=[];return function D(b,C){let $=b,R=0,p={root:b},v=0,m=p,I="root";function k(){for(;v<R;v++){let G=C[v];typeof G!="object"&&(a(j(m,I)),m=m[I]=W(m[I]),I=G)}}for(;R<C.length;R++){const G=C[R];if(Array.isArray(G)){const g=D($,G);g!==$&&g!==void 0&&(k(),$=m[I]=g)}else if(typeof G=="object"){G.d!=null?(k(),$=h(m,I,y[G.d])):G.i!==void 0&&(k(),$=h(m,I,G.i));const g=ve(G);if(g)k(),$=m[I]=g.apply($,f(G));else if(G.e!==void 0)throw Error("Subtype "+G.et+" undefined")}else $=Y($,G)}return p.root}(r=function D(b,C){const $=[];let R=0;for(;R<C.length;R++){const I=C[R];if(Array.isArray(I))break;typeof I!="object"&&($.push(b),b=Y(b,I))}for(let I=C.length-1;I>=R;I--)b=D(b,C[I]);for(--R;R>=0;R--){const I=C[R];if(typeof I!="object"){const k=$.pop();b=b===Y(k,I)?k:b===void 0?c(k,I):(v=I,m=b,(p=W(p=k))[v]=m,p)}else O(I)&&(a(b!==void 0,"Cannot pick up or remove undefined"),I.p!=null&&(y[I.p]=b),b=void 0)}var p,v,m;return b}(r,u),u)}function ue(r,u){r=r.slice(),z(u);const y=s.readCursor(u);let D,b,C=!1;const $=[];for(let p=0;;p++){const v=r[p],m=y.getComponent();if(m&&(m.r!==void 0?C=!0:m.p!=null&&(C=!1,D=m.p,b=p)),p>=r.length)break;let I=0;const k=s.advancer(y,void 0,(g,U)=>{O(U)&&I++});$.unshift(k);const G=k(v);if(typeof v=="number"&&(r[p]-=I),!G)break}if($.forEach(p=>p.end()),C)return null;const R=()=>{let p=0;if(D!=null){const v=y.getPath();p=v.length,r=v.concat(r.slice(b))}for(;p<r.length;p++){const v=r[p],m=l(y),I=ve(m);if(I){const g=f(m);I.transformPosition&&(r[p]=I.transformPosition(r[p],g));break}let k=0;const G=s.advancer(y,(g,U)=>o(U)?~(g-k):g-k,(g,U)=>{o(U)&&k++})(v);if(typeof v=="number"&&(r[p]+=k),!G)break}};return D!=null?y.eachDrop(null,p=>{p===D&&R()}):R(),r}function ne(r,u){if(z(r),z(u),r==null)return u;if(u==null)return r;let y=0;const D=s.readCursor(r),b=s.readCursor(u),C=s.writeCursor(),$=[],R=[],p=[],v=[],m=[],I=[],k=new Set;D.traverse(null,g=>{g.p!=null&&(p[g.p]=D.clone())}),b.traverse(null,g=>{g.d!=null&&(v[g.d]=b.clone())});const G=s.writeCursor();return function g(U,re,te,K,se,ke,be,_e){a(re||te);const oe=l(re),Pe=l(te),Se=!!Pe&&Pe.r!==void 0,Le=!!oe&&oe.i!==void 0,Me=oe?oe.d:null,Ee=Pe?Pe.p:null,$e=(ke||Se)&&Ee==null;if(Ee!=null)K=v[Ee],be=R[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(Me!=null)if(U=p[Me],_e=$[Me]=new s.WriteCursor,$e)ke&&!Se&&_e.write("r",!0);else{const P=m[Me]=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 M;Le?(a(se===void 0),M=oe.i):M=se;const B=(Ee==null?!Le||ke||Se:M===void 0)?null:be.getComponent();if(Ee!=null){if(!(se!==void 0||Le)){const P=Me!=null?m[Me]:y++;I[Ee]=P,_e.write("p",P)}}else Se&&(Le||se!==void 0||(Pe.r,_e.write("r",Pe.r)));const S=$e?null:ve(oe),A=ve(Q);if((S||A)&&(S&&S.name,A&&A.name),S&&A){a(S===A);const P=f(oe),x=f(Q),he=S.compose(P,x);_(be,S,he),k.add(Q)}else S?_(be,S,f(oe)):A&&(_(be,A,f(Q)),k.add(Q));const N=typeof M=="object"&&M!=null;let X=!1,Z=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)=>O(x)?Z-P-1:P-Z,(P,x)=>{O(x)&&Z++});if(s.eachChildOf(re,te,(P,x,he)=>{let me,We,He=P,Ue=P,Ye=P;if(typeof P=="number"){let Oe=P+fe;We=ye(Oe),Ue=Oe+de;let ce=P+ee;me=q(ce),o(l(We))&&(me=null),He=ce+Z,Ye=P+ae,a(He>=0,"p1PickKey is negative"),a(Ue>=0,"p2DropKey is negative");const Ne=o(l(x)),Ge=O(l(he));(Ne||Ge&&!$e)&&ae--,Ne&&ee--,Ge&&fe--}else me=q(P),We=ye(P);_e.descend(He),be.descend(Ue);const ze=N&&!o(l(x))?M[Ye]:void 0,Te=g(me,x,he,We,ze,$e,be,_e);var Re,T,ie;N&&!$e?ze!==Te&&(X||(M=Array.isArray(M)?M.slice():Object.assign({},M),X=!0),Re=M,ie=Te,typeof(T=Ye)=="number"?(a(Array.isArray(Re)),a(T<Re.length)):(a(!Array.isArray(Re)),a(Re[T]!==void 0)),ie===void 0?typeof T=="number"?Re.splice(T,1):delete Re[T]:Re[T]=ie):a(Te===void 0),be.ascend(),_e.ascend()}),q.end(),ye.end(),B!=null)B.i=M;else if(!ke&&!Se&&Ee==null)return M}(D,D.clone(),b,b.clone(),void 0,!1,C,G),C.reset(),C.mergeTree(G.get()),C.reset(),C.get(),$.map(g=>g.get()),R.map(g=>g.get()),D.traverse(C,(g,U)=>{const re=g.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 g.r!==void 0&&U.write("r",g.r)}),C.reset(),C.get(),b.traverse(C,(g,U)=>{const re=g.d;if(re!=null){const K=I[re];K!=null&&U.write("d",K);const se=R[re];se&&U.mergeTree(se.get())}else g.i!==void 0&&U.write("i",g.i);const te=ve(g);te&&!k.has(g)&&_(U,te,f(g))}),C.get()}function le(r){if(r==null)return null;const u=new s.ReadCursor(r),y=new s.WriteCursor;let D;const b=[],C=[];return function $(R,p,v){const m=R.getComponent();let I,k=!1;if(m){m.p!=null&&(p.write("d",m.p),b[m.p]=R.clone()),m.r!==void 0&&p.write("i",m.r),m.d!=null&&(p.write("p",m.d),v=void 0),m.i!==void 0&&(v=I=m.i);const g=ve(m);g&&(v===void 0?(D||(D=new Set),D.add(m)):(f(m),v=g.apply(v,f(m)),k=!0))}let G=0;for(const g of R){p.descend(g);const U=typeof g=="number"?g-G:g,re=Y(v,U);o(R.getComponent())&&G++;const te=$(R,p,re);if(v!==void 0&&te!==void 0){if(k||(k=!0,v=W(v)),!j(v,U))throw Error("Cannot modify child - invalid operation");v[U]=te}p.ascend()}if(I===void 0)return k?v:void 0;p.write("r",v)}(u,y,void 0),D&&(y.reset(),function $(R,p,v){const m=p.getComponent();if(m){const g=m.d;if(g!=null&&(R=b[g],v=C[g]=s.writeCursor()),D.has(m)){const U=ve(m);if(!U.invert)throw Error(`Cannot invert subtype ${U.name}`);_(v,U,U.invert(f(m)))}}let I=0,k=0;const G=s.advancer(R,(g,U)=>O(U)?I-g-1:g-I,(g,U)=>{O(U)&&I++});for(const g of p)if(typeof g=="number"){const U=g-k,re=G(U),te=U+I;v.descend(te),$(re,p,v),o(p.getComponent())&&k++,v.ascend()}else v.descend(g),$(G(g),p,v),v.ascend();G.end()}(u.clone(),u,y),C.length&&(y.reset(),u.traverse(y,($,R)=>{const p=$.p;if(p!=null){const v=C[p];v&&v.get(),v&&R.mergeTree(v.get())}}))),y.get()}const ge=(r,u)=>r.some(y=>typeof y=="object"&&(Array.isArray(y)?ge(y,u):u(y)));function Ae(r,u){if(r==null||!ge(r,p=>{var v;return p.r!==void 0||((v=ve(p))===null||v===void 0?void 0:v.makeInvertible)!=null}))return r;const y=new s.ReadCursor(r),D=new s.WriteCursor;let b=!1;const C=[],$=[],R=(p,v,m)=>{const I=p.getComponent();let k=!1;if(I){I.d!=null&&v.write("d",I.d),I.i!==void 0&&v.write("i",I.i);const g=I.p;if(g!=null&&(C[g]=p.clone(),a(m!==void 0,"Operation picks up at an invalid key"),$[g]=m,v.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=ve(I);U&&(U.makeInvertible?b=!0:_(v,U,f(I),!0))}let G=0;for(const g of p){v.descend(g);const U=typeof g=="number"?g-G:g,re=Y(m,U),te=R(p,v,re);re!==te&&(k||(k=!0,m=W(m)),te===void 0?(m=c(m,U),typeof g=="number"&&G++):m[U]=te),v.ascend()}return I&&(I.r!==void 0?(v.write("r",i.default(m)),m=void 0):I.p!=null&&(m=void 0)),m};return R(y,D,u),D.get(),b&&(D.reset(),function p(v,m,I,k,G){const g=m.getComponent();if(g){g.i!==void 0?(k=g.i,G=!0):g.d!=null&&(k=$[g.d],v=C[g.d],G=!1,g.d);let K=ve(g);if(K&&K.makeInvertible){const se=f(g);_(I,K,K.makeInvertible(se,k),!0)}}let U=0,re=0;const te=s.advancer(v,(K,se)=>O(se)?U-K-1:K-U,(K,se)=>{O(se)&&U++});for(const K of m)if(typeof K=="number"){const se=K-re,ke=te(se),be=se+U,_e=Y(k,G?se:be);I.descend(K),p(ke,m,I,_e,G),o(m.getComponent())&&re++,I.ascend()}else{const se=Y(k,K);I.descend(K),p(te(K),m,I,se,G),I.ascend()}te.end()}(y.clone(),y,D,u,!1)),D.get()}function Tt(r,u){return le(Ae(r,u))}const rt=r=>{if(r==null)return null;const u=r.slice();for(let y=0;y<r.length;y++){const D=u[y];Array.isArray(D)&&(u[y]=rt(D))}return u};function it(r,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:r};z(r),z(u);let b=null;const C=[],$=[],R=[],p=[],v=[],m=[],I=[],k=[],G=[],g=[],U=[],re=[],te=[],K=[],se=[];let ke=0;const be=s.readCursor(r),_e=s.readCursor(u),oe=s.writeCursor();if(function Q(M,B=null,S){const A=l(B);A&&(A.r!==void 0?S=B.clone():A.p!=null&&(S=null,m[A.p]=M.clone()));const N=M.getComponent();let X;N&&(X=N.p)!=null&&(v[X]=B?B.clone():null,R[X]=M.clone(),S&&(g[X]=!0,G[X]=S),A&&A.p!=null&&(K[X]=A.p));const Z=s.advancer(B);for(const ee of M)Q(M,Z(ee),S);Z.end()}(_e,be,null),function Q(M,B,S,A,N){const X=S.getComponent();let Z,ee=!1;X&&((Z=X.d)!=null?(p[Z]=S.clone(),A!=null&&(se[A]==null&&(se[A]=[]),se[A].push(Z)),M=v[Z]||null,B=R[Z]||null,g[Z]?(N&&(U[Z]=!0),N=G[Z]||null):!N||D!==1&&K[Z]!=null||b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.moveOp(B.getPath(),S.getPath())}),ee=!0):X.i!==void 0&&(M=B=null,ee=!0,N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.insertOp(S.getPath(),X.i)})));const fe=l(M);fe&&(fe.r!==void 0?N=M.clone():fe.p!=null&&(fe.p,A=fe.p,N=null));const de=ve(X);de&&N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.editOp(S.getPath(),de,f(X),!0)});let ae=0,ye=0;const q=s.advancer(B,(x,he)=>O(he)?ae-x-1:x-ae,(x,he)=>{O(he)&&ae++}),P=s.advancer(M);for(const x of S)if(typeof x=="number"){const he=x-ye,me=q(he);ye+=+Q(P(he+ae),me,S,A,N)}else{const he=q(x);Q(P(x),he,S,A,N)}return q.end(),P.end(),ee}(be,_e,_e.clone(),null,null),p.map(Q=>Q&&Q.get()),b)return{ok:!1,conflict:b};U.map(Q=>!!Q);const Pe=[];let Se=null;(function Q(M,B,S,A,N){let X=!1;const Z=l(B);if(O(Z)){const q=Z.p;q!=null?(S=p[q],A=re[q]=s.writeCursor(),X=!0,N=null):(S=null,N=B.clone())}else o(l(S))&&(S=null);const ee=M.getComponent();if(ee){const q=ee.p;q!=null?(N&&(k[q]=N),Pe[q]=N||D===1&&X?null:A.getComponent(),C[q]=M.clone(),S&&(I[q]=S.clone())):ee.r!==void 0&&(N||A.write("r",!0),(N||X)&&(Se==null&&(Se=new Set),Se.add(ee)))}let fe=0,de=0;const ae=s.advancer(B,void 0,(q,P)=>{O(P)&&fe++}),ye=s.advancer(S,(q,P)=>o(P)?~(q-de):q-de,(q,P)=>{o(P)&&de++});if(M)for(const q of M)if(typeof q=="string"){const P=ae(q),x=ye(q);A.descend(q),Q(M,P,x,A,N),A.ascend()}else{const P=ae(q),x=q-fe,he=O(l(P))?null:ye(x),me=x+de;a(me>=0),A.descend(me),Q(M,P,he,A,N),A.ascend()}ae.end(),ye.end()})(be,_e,_e.clone(),oe,null),oe.reset();let Le=[];if(function Q(M,B,S,A,N,X){a(B);const Z=B.getComponent();let ee=l(A),fe=!1;const de=(T,ie,Oe)=>T?n.moveOp(T.getPath(),ie.getPath()):n.insertOp(ie.getPath(),Oe.i);if(o(Z)){const T=Z.d;T!=null&&($[T]=B.clone());const ie=T!=null?Pe[T]:null;let Oe=!1;if(Z.i!==void 0||T!=null&&ie){let ce;ee&&(ee.i!==void 0||(ce=ee.d)!=null&&!g[ce])&&(Oe=ce!=null?T!=null&&T===K[ce]:t.default(ee.i,Z.i),Oe||ce!=null&&D!==1&&K[ce]!=null||b==null&&(b={type:d.ConflictType.DROP_COLLISION,op1:de(T!=null?C[T]:null,B,Z),op2:de(ce!=null?R[ce]:null,A,ee)})),Oe||(X?b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:de(T!=null?C[T]:null,B,Z),op2:n.removeOp(X.getPath())}):(T!=null?(Le[ke]=T,N.write("d",ie.p=ke++)):N.write("i",i.default(Z.i)),fe=!0))}else if(T!=null&&!ie){const ce=k[T];ce&&(X=ce.clone())}T!=null?(M=C[T],S=m[T],A=I[T]):Z.i!==void 0&&(M=S=null,Oe||(A=null))}else O(l(M))&&(M=S=A=null);const ae=l(M),ye=l(S);if(O(ye)){const T=ye.p;ye.r!==void 0&&(!ae||ae.r===void 0)||g[T]?(A=null,X=S.clone()):T!=null&&(A=p[T],D!==1&&K[T]!=null||((N=te[T])||(N=te[T]=s.writeCursor()),N.reset(),X=null))}else!o(Z)&&o(ee)&&(A=null);ee=A!=null?A.getComponent():null;const q=ve(Z);if(q){const T=f(Z);if(X)b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.editOp(B.getPath(),q,T,!0),op2:n.removeOp(X.getPath())});else{const ie=ve(ee);let Oe;if(ie){if(q!==ie)throw Error("Transforming incompatible types");const ce=f(ee);Oe=q.transform(T,ce,y)}else Oe=i.default(T);_(N,q,Oe)}}let P=0,x=0,he=0,me=0,We=0,He=0,Ue=M!=null&&M.descendFirst(),Ye=Ue;const ze=s.advancer(S,void 0,(T,ie)=>{O(ie)&&he++});let Te=A!=null&&A.descendFirst(),Re=Te;for(const T of B)if(typeof T=="number"){let ie;const Oe=o(B.getComponent()),ce=T-x;{let Be;for(;Ue&&typeof(Be=M.getKey())=="number";){Be+=P;const je=M.getComponent(),Xe=O(je);if(Be>ce||Be===ce&&(!Xe||D===0&&Oe))break;if(Xe){P--;const Ke=je.p;K.includes(Ke),je.d,l(te[je.d]),O(l(te[je.d])),(je.r===void 0||Se&&Se.has(je))&&(Ke==null||!Pe[Ke]||D!==1&&K.includes(Ke))||We--}Ue=M.nextSibling()}ie=Ue&&Be===ce?M:null}const Ne=ce-P;let Ge=ze(Ne);const st=Ne-he;let et=null;{let Be,je;for(;Te&&typeof(Be=A.getKey())=="number";){je=Be-me;const Xe=A.getComponent(),Ke=o(Xe);if(je>st)break;if(je===st){if(!Ke){et=A;break}{if(D===0&&Oe){et=A;break}const Fe=Ge&&O(Ge.getComponent());if(D===0&&Fe)break}}if(Ke){const Fe=Xe.d;K[Fe],Xe.i===void 0&&(g[Fe]||K[Fe]!=null&&D!==1)?(g[Fe]||K[Fe]!=null&&D===0)&&(me++,He--):me++}Te=A.nextSibling()}}const yt=st+me+We+He;a(yt>=0,"trying to descend to a negative index"),N.descend(yt),Oe&&(ie=Ge=et=null,x++),Q(ie,B,Ge,et,N,X)&&He++,N.ascend()}else{let ie;for(;Ue&&(ie=M.getKey(),typeof ie!="string"||!(ie>T||ie===T));)Ue=M.nextSibling();const Oe=Ue&&ie===T?M:null,ce=ze(T);let Ne;for(;Te&&(Ne=A.getKey(),typeof Ne!="string"||!(Ne>T||Ne===T));)Te=A.nextSibling();const Ge=Te&&Ne===T?A:null;N.descend(T),Q(Oe,B,ce,Ge,N,X),N.ascend()}return ze.end(),Ye&&M.ascend(),Re&&A.ascend(),fe}(be,be.clone(),_e,_e.clone(),oe,null),b)return{ok:!1,conflict:b};oe.reset();const Me=(Q,M,B)=>Q.traverse(M,(S,A)=>{S.d!=null&&B(S.d,Q,A)});(g.length||re.length)&&(Me(_e,oe,(Q,M,B)=>{g[Q]&&!U[Q]&&B.write("r",!0),re[Q]&&B.mergeTree(re[Q].get())}),oe.reset());const Ee=[],$e=[];if((te.length||g.length)&&!b){const Q=s.readCursor(rt(oe.get()));if(Me(Q,null,(M,B)=>{Ee[M]=B.clone()}),te.forEach(M=>{M&&Me(s.readCursor(M.get()),null,(B,S)=>{Ee[B]=S.clone()})}),function M(B,S,A,N,X,Z){const ee=l(S);if(ee&&O(ee))if(ee.p!=null){const P=ee.p;Ee[P].getPath(),A=Ee[P],N=$e[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(S,void 0,(P,x)=>{O(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),M(B,x,me,N),N.ascend()}else N.descend(P),M(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(),$e.length){const M=$e.map(S=>S?S.get():null),B=s.readCursor(rt(oe.get()));if(Me(B,oe,(S,A,N)=>{const X=M[S];X&&(N.mergeTree(X),M[S]=null)}),M.find(S=>S)){const S=s.writeCursor(),A=s.writeCursor();let N=0,X=0;M.forEach(Z=>{Z!=null&&Me(s.readCursor(Z),null,ee=>{const fe=Le[ee];S.writeMove(C[fe].getPath(),$[fe].getPath(),N++);const de=se[fe];de&&de.forEach(ae=>{g[ae]||D!==1&&K[ae]!=null||A.writeMove(R[ae].getPath(),p[ae].getPath(),X++)})})}),b={type:d.ConflictType.BLACKHOLE,op1:S.get(),op2:A.get()}}}}return b?{ok:!1,conflict:b}:{ok:!0,result:oe.get()}}const Ot=r=>{const u=new Error("Transform detected write conflict");throw u.conflict=r,u.type=u.name="writeConflict",u};function Rt(r,u,y){const D=it(r,u,y);if(D.ok)return D.result;Ot(D.conflict)}const qe=r=>{const u=s.writeCursor();return s.readCursor(r).traverse(u,(y,D)=>{(o(y)||ve(y))&&D.write("r",!0)}),u.get()},kt=(r,u)=>{const{type:y,op1:D,op2:b}=r;switch(y){case d.ConflictType.DROP_COLLISION:return u==="left"?[null,qe(b)]:[qe(D),null];case d.ConflictType.RM_UNEXPECTED_CONTENT:let C=!1;return s.readCursor(D).traverse(null,$=>{$.r!==void 0&&(C=!0)}),C?[null,qe(b)]:[qe(D),null];case d.ConflictType.BLACKHOLE:return[qe(D),qe(b)];default:throw Error("Unrecognised conflict: "+y)}};function vt(r,u,y,D){let b=null;for(;;){const C=it(u,y,D);if(C.ok)return ne(b,C.result);{const{conflict:$}=C;r($)||Ot($);const[R,p]=kt($,D);u=ne(H(u),R),y=ne(H(y),p),b=ne(b,p)}}}})(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 i=pt;Object.defineProperty(n,"ReadCursor",{enumerable:!0,get:function(){return i.ReadCursor}}),Object.defineProperty(n,"WriteCursor",{enumerable:!0,get:function(){return i.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 i=this._getCurrentBySearch(t);i!=null&&(i.transform=t.transform,i.transforms=t.transforms,i.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 i=[];Object.keys(t).forEach(s=>{const d=t[s];(d==null?void 0:d.data)!=null&&Object.keys(d.data).forEach(a=>{i.push({unitId:e,subUnitId:s,drawingId:a})})}),i.length>0&&this.removeNotification(i)}registerDrawingData(e,t){this.drawingManagerData[e]=t}initializeNotification(e){const t=[],i=this.drawingManagerData[e];i!=null&&(Object.keys(i).forEach(s=>{this._establishDrawingMap(e,s);const d=i[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,i){this.drawingManagerData[e][t].data=i}getBatchAddOp(e){const t=[],i=[],s=[];e.forEach(W=>{const{op:O,invertOp:o}=this._addByParam(W);t.push({unitId:W.unitId,subUnitId:W.subUnitId,drawingId:W.drawingId}),i.push(O),s.push(o)});const d=i.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=[],i=[];e.forEach(E=>{const{op:W,invertOp:O}=this._removeByParam(E);t.push(W),i.push(O)});const s=t.reduce(V.type.compose,null),d=i.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=[],i=[],s=[];e.forEach(W=>{const{op:O,invertOp:o}=this._updateByParam(W);t.push({unitId:W.unitId,subUnitId:W.subUnitId,drawingId:W.drawingId}),i.push(O),s.push(o)});const d=i.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:i,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:i,subUnitId:s,objects:e}}getUngroupDrawingOp(e){const t=[],{unitId:i,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:i,subUnitId:s,objects:e}}getDrawingsByGroup(e){const{unitId:t,subUnitId:i,drawingId:s}=e;if(this.getDrawingByParam({unitId:t,subUnitId:i,drawingId:s})==null)return[];const a=this._getDrawingData(t,i),l=[];return Object.keys(a).forEach(E=>{const W=a[E];W.groupId===s&&l.push(W)}),l}_getGroupDrawingOp(e){const{parent:t,children:i}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];l.push(V.insertOp([s,d,"data",a],t));let E=Number.NEGATIVE_INFINITY;return i.forEach(W=>{const{unitId:O,subUnitId:o,drawingId:c}=W,h=this._hasDrawingOrder({unitId:O,subUnitId:o,drawingId:c});E=Math.max(E,h),l.push(...this._getUpdateParamCompareOp(W,this.getDrawingByParam({unitId:O,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:i}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];return i.forEach(E=>{const{unitId:W,subUnitId:O,drawingId:o}=E;l.push(...this._getUpdateParamCompareOp(E,this.getDrawingByParam({unitId:W,subUnitId:O,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,i){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=V.type.apply(this.drawingManagerData,i)}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,i,s]=e.split("#-#");return this._getCurrentBySearch({unitId:t,subUnitId:i,drawingId:s})}focusDrawing(e){if(e==null){this._focusDrawings=[],this._focus$.next([]);return}const t=[];e.forEach(i=>{var E;const{unitId:s,subUnitId:d,drawingId:a}=i,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:i,subUnitId:s,drawingId:d}=t,a=(l=this._getDrawingData(i,s))==null?void 0:l[d];a!=null&&e.push(a)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,i){this.drawingManagerData[e][t].order=i}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,i),l=[...s];s.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:i,drawingId:O});if(o===-1||o===a.length-1)return;const c=V.moveOp([t,i,"order",o],[t,i,"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:i,objects:{...e,drawingIds:l}}}getBackwardDrawingOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,i),l=[...s];s.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:i,drawingId:O});if(o===-1||o===0)return;const c=V.moveOp([t,i,"order",o],[t,i,"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:i,objects:{...e,drawingIds:l}}}getFrontDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,i,s),a=[...s],l=this.getDrawingOrder(t,i),E=[];d.forEach(o=>{const{drawingId:c}=o,h=this._getDrawingCount(t,i)-1,j=V.moveOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(c)],[t,i,"order",h]);E.push(j),a.includes(l[h])||a.push(l[h])});const W=E.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(W,this.drawingManagerData),redo:W,unitId:t,subUnitId:i,objects:{...e,drawingIds:a}}}getBackDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,i,s,!0),a=[...s],l=this.getDrawingOrder(t,i),E=[];d.forEach(o=>{const{drawingId:c}=o,h=V.moveOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(c)],[t,i,"order",0]);E.push(h),a.includes(l[0])||a.push(l[0])});const W=E.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(W,this.drawingManagerData),redo:W,unitId:t,subUnitId:i,objects:{...e,drawingIds:a}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,t,i,s=!1){return i.map(d=>{const a=this._hasDrawingOrder({unitId:e,subUnitId:t,drawingId:d});return{drawingId:d,zIndex:a}}).sort(s===!1?Qe.sortRules:Qe.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;const{unitId:t,subUnitId:i,drawingId:s}=e;return this._establishDrawingMap(t,i),this._getDrawingOrder(t,i).indexOf(s)}_getCurrentBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:i,drawingId:s}=e;return(l=(a=(d=this.drawingManagerData[t])==null?void 0:d[i])==null?void 0:a.data)==null?void 0:l[s]}_getOldBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:i,drawingId:s}=e;return(l=(a=(d=this._oldDrawingManagerData[t])==null?void 0:d[i])==null?void 0:a.data)==null?void 0:l[s]}_establishDrawingMap(e,t,i){var s;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),i==null?null:(s=this.drawingManagerData[e][t].data)==null?void 0:s[i]}_addByParam(e){const{unitId:t,subUnitId:i,drawingId:s}=e;this._establishDrawingMap(t,i,s);const d=V.insertOp([t,i,"data",s],e),a=V.insertOp([t,i,"order",this._getDrawingOrder(t,i).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:i,drawingId:s}=e;if(this._establishDrawingMap(t,i,s)==null)return{op:[],invertOp:[]};const a=V.removeOp([t,i,"data",s],!0),l=V.removeOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(s)],!0),E=[a,l].reduce(V.type.compose,null),W=V.type.invertWithDoc(E,this.drawingManagerData);return{op:E,invertOp:W}}_updateByParam(e){const{unitId:t,subUnitId:i,drawingId:s}=e,d=this._establishDrawingMap(t,i,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:i,subUnitId:s,drawingId:d}=e,a=[];return Object.keys(e).forEach(l=>{const E=e[l],W=t[l];W!==E&&a.push(V.replaceOp([i,s,"data",d,l],W,E))}),a}_getDrawingData(e,t){var i,s;return((s=(i=this.drawingManagerData[e])==null?void 0:i[t])==null?void 0:s.data)||{}}_getDrawingOrder(e,t){var i,s;return((s=(i=this.drawingManagerData[e])==null?void 0:i[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},i){return typeof i=="number"?`${n}#-#${e}#-#${t}#-#${i}`:`${n}#-#${e}#-#${t}`}const qt=async n=>new Promise((e,t)=>{const i=new Image;i.src=n,i.onload=()=>{e({width:i.width,height:i.height,image:i})},i.onerror=s=>{t(s)}});var Je=(n=>(n.URL="URL",n.UUID="UUID",n.BASE64="BASE64",n))(Je||{}),Ze=(n=>(n.SUCCUSS="0",n.ERROR_EXCEED_SIZE="1",n.ERROR_IMAGE_TYPE="2",n.ERROR_UPLOAD_COUNT_LIMIT="3",n.ERROR_IMAGE="4",n))(Ze||{});const Mt=nt.createIdentifier("core.image-io.service");class St{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===Je.BASE64){const i=new Image;return i.src=e,i}return this._imageSourceCache.get(e)}addImageSourceCache(e,t,i){t===Je.BASE64||i==null||this._imageSourceCache.set(e,i)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((t,i)=>{if(!Et.includes(e.type)){i(new Error(Ze.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>Ct){i(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){i(new Error(Ze.ERROR_IMAGE)),this._decreaseWaiting();return}const l=Qe.Tools.generateRandomId(6);t({imageId:l,imageSourceType:Je.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=nt.createIdentifier("univer.drawing-manager.service");var Xt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Yt=(n,e,t,i)=>{for(var s=i>1?void 0:i?Zt(e,t):e,d=n.length-1,a;d>=0;d--)(a=n[d])&&(s=(i?a(e,t,s):a(s))||s);return i&&s&&Xt(e,t,s),s},Jt=(n,e)=>(t,i)=>e(t,i,n);const Qt="DRAWING_PLUGIN";var lt;exports.UniverDrawingPlugin=(lt=class extends Qe.Plugin{constructor(e,t){super(),this._config=e,this._injector=t}onStarting(e){this._initDependencies(e)}_initDependencies(e){var s;const t=[[Mt,{useClass:St}],[jt,{useClass:Pt}]];Qe.mergeOverrideWithDependencies(t,(s=this._config)==null?void 0:s.override).forEach(d=>e.add(d))}},F(lt,"pluginName",Qt),lt);exports.UniverDrawingPlugin=Yt([Jt(1,nt.Inject(nt.Injector))],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=Gt;exports.DrawingManagerService=Pt;exports.DrawingTypeEnum=Nt;exports.IDrawingManagerService=jt;exports.IImageIoService=Mt;exports.ImageIoService=St;exports.ImageSourceType=Je;exports.ImageUploadStatusType=Ze;exports.UnitDrawingService=At;exports.getDrawingShapeKeyByDrawingSearch=Vt;exports.getImageSize=qt;
|
|
1
|
+
"use strict";var kt=Object.defineProperty;var $t=(n,e,t)=>e in n?kt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var F=(n,e,t)=>$t(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const we=require("rxjs"),Be=require("@univerjs/core"),Wt=500,Gt=500,Bt=10,It=5*1024*1024,Ct=["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={},Et={},ut={};Object.defineProperty(ut,"__esModule",{value:!0});function xt(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 Lt(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)?Lt(n,e):xt(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(O,o){if(!O)throw new Error(o)}const t=O=>O!=null&&typeof O=="object"&&!Array.isArray(O),i=(O,o)=>typeof O==typeof o?O>o:typeof O=="string"&&typeof o=="number";function s(O,o){for(let c in O){const h=c;o.write(h,O[h])}}n.isValidPathItem=O=>typeof O=="number"||typeof O=="string"&&O!=="__proto__";class d{constructor(o=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=o}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,t(this.container[this.idx])&&this.idx--)}getPath(){const o=[];let c=this.container,h=this.parents.length-1,j=this.idx;for(;j>=0;)o.unshift(c[j]),j===0?(j=this.indexes[h*2],c=this.parents[h--]):j-=t(c[j-1])?2:1;return o}}class 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(i(c,this.container[this.lcIdx][0])),h=this.lcIdx+1,this.lcIdx=-1);h<this.container.length&&i(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 Y=0;for(let pe=0;pe<o.length;pe++){const J=o[pe];typeof J=="string"||typeof J=="number"?(Y++,this.descend(J)):Array.isArray(J)?this.mergeTree(J,c):typeof J=="object"&&c(J,this)}for(;Y--;)this.ascend();this.lcIdx=this.parents.length===j?h:-1}at(o,c){this.descendPath(o),c(this);for(let h=0;h<o.length;h++)this.ascend();return this}writeAtPath(o,c,h){return this.at(o,()=>this.write(c,h)),this.reset(),this}writeMove(o,c,h=0){return this.writeAtPath(o,"p",h).writeAtPath(c,"d",h)}getPath(){const o=super.getPath();return o.push(...this.pendingDescent),o}}n.WriteCursor=l,n.writeCursor=()=>new l,n.readCursor=O=>new a(O);function E(O,o,c){let h,j;j=h=O?O.descendFirst():!1;function Y(pe){let J;for(;j;){const Ie=J=O.getKey();if(pe!=null){let Le=!1;if(o&&typeof Ie=="number"&&(J=o(Ie,O.getComponent()),J<0&&(J=~J,Le=!0)),i(J,pe))return null;if(J===pe&&!Le)return O}c&&typeof J=="number"&&c(J,O.getComponent()),j=O.nextSibling()}return null}return Y.end=()=>{h&&O.ascend()},Y}n.advancer=E;function W(O,o,c){let h,j,Y,pe;for(h=j=O&&O.descendFirst(),Y=pe=o&&o.descendFirst();h||Y;){let J=h?O.getKey():null,Ie=Y?o.getKey():null;J!==null&&Ie!==null&&(i(Ie,J)?Ie=null:J!==Ie&&(J=null)),c(J==null?Ie:J,J!=null?O:null,Ie!=null?o:null),J!=null&&h&&(h=O.nextSibling()),Ie!=null&&Y&&(Y=o.nextSibling())}j&&O.ascend(),pe&&o.ascend()}n.eachChildOf=W})(ht);var pt={};(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={}))})(pt);var st={},qe={},yt;function gt(){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,i=0;for(;i<e;i++){const s=n.charCodeAt(i);s>=55296&&s<=57343&&(t++,i++)}if(i!==e)throw Error("Invalid offset - splits unicode bytes");return i-t},qe.uniToStrPos=(n,e)=>{let t=0;for(;e>0;e--){const i=n.charCodeAt(t);t+=i>=55296&&i<=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=gt(),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 i(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=i;function s(f,_){const w=[],L=l(w);return i(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 W=(f,_,w)=>typeof f=="number"?w==null?f-_:Math.min(f,w)-_:n.uniSlice(f,_,w),O=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:W(ue.d,w)},++_,w=0,ne;{let le=W(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}=O(f);for(let ne=0;ne<_.length;ne++){const le=_[ne];let ge,Ae;switch(typeof le){case"number":for(ge=le;ge>0;)Ae=H(ge,"i"),z(Ae),typeof Ae!="string"&&(ge-=E(Ae));break;case"string":w==="left"&&typeof De()=="string"&&z(H(-1)),z(e.strPosToUni(le));break;case"object":for(ge=n.dlen(le.d);ge>0;)switch(Ae=H(ge,"i"),typeof Ae){case"number":ge-=Ae;break;case"string":z(Ae);break;case"object":ge-=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}=O(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 ge=0;for(;ge<ne;)switch(le=z(ne-ge,"d"),typeof le){case"number":L({d:W(ue.d,ge,ge+le)}),ge+=le;break;case"string":ge+=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},Y=(f,_)=>typeof f=="number"?j(f,_):f.map(w=>j(w,_));function pe(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 i(f,w=>{typeof w=="object"&&typeof w.d=="number"&&(_=!1)}),_}function ve(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:Y,isInvertible:Le,makeInvertible(_,w){return pe(_,w,f)},stripInvertible:Ie,invert:J,invertWithDoc(_,w){return J(pe(_,w,f))},isNoop:_=>_.length===0}}n.default=ve}(ot)),ot}var tt={},mt;function Ht(){if(mt)return tt;mt=1,Object.defineProperty(tt,"__esModule",{value:!0});const n=ct(),e=gt();function t(i,s){return{get:i,getLength(){return i().length},insert(d,a,l){const E=e.strPosToUni(i(),d);return s([E,a],l)},remove(d,a,l){const E=e.strPosToUni(i(),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 W=n.dlen(a.d);this.onRemove&&this.onRemove(E,W)}})},onInsert:null,onRemove:null}}return tt.default=t,t.provides={text:!0},tt}var wt;function Kt(){return wt||(wt=1,function(n){var e=Ce&&Ce.__createBinding||(Object.create?function(c,h,j,Y){Y===void 0&&(Y=j),Object.defineProperty(c,Y,{enumerable:!0,get:function(){return h[j]}})}:function(c,h,j,Y){Y===void 0&&(Y=j),c[Y]=h[j]}),t=Ce&&Ce.__setModuleDefault||(Object.create?function(c,h){Object.defineProperty(c,"default",{enumerable:!0,value:h})}:function(c,h){c.default=h}),i=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=gt(),a=i(ct()),l=s(Ht()),E={create(c){return c},toString(c){return c},builder(c){if(typeof c!="string")throw Error("Invalid document snapshot: "+c);const h=[];return{skip(j){let Y=d.uniToStrPos(c,j);if(Y>c.length)throw Error("The op is too long for this document");h.push(c.slice(0,Y)),c=c.slice(Y)},append(j){h.push(j)},del(j){c=c.slice(d.uniToStrPos(c,j))},build(){return h.join("")+c}}},slice:a.uniSlice},W=a.default(E),O=Object.assign(Object.assign({},W),{api:l.default});n.type=O,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(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(n,"__esModule",{value:!0}),n.editOp=n.replaceOp=n.insertOp=n.moveOp=n.removeOp=n.type=void 0;const t=e(ut),i=e(ft),s=ht,d=pt;function a(r,u){if(!r)throw new Error(u)}n.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:s.readCursor,writeCursor:s.writeCursor,create:r=>r,isNoop:r=>r==null,setDebug(r){},registerSubtype:J,checkValidOp:z,normalize:H,apply:De,transformPosition:ue,compose:ne,tryTransform:rt,transform:Tt,makeInvertible:Ae,invert:le,invertWithDoc:jt,RM_UNEXPECTED_CONTENT:d.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:d.ConflictType.DROP_COLLISION,BLACKHOLE:d.ConflictType.BLACKHOLE,transformNoConflict:(r,u,y)=>Ot(()=>!0,r,u,y),typeAllowingConflictsPred:r=>Object.assign(Object.assign({},n.type),{transform:(u,y,D)=>Ot(r,u,y,D)})};const l=r=>r?r.getComponent():null;function E(r){return r&&typeof r=="object"&&!Array.isArray(r)}const W=r=>Array.isArray(r)?r.slice():r!==null&&typeof r=="object"?Object.assign({},r):r,O=r=>r&&(r.p!=null||r.r!==void 0),o=r=>r&&(r.d!=null||r.i!==void 0);function c(r,u){return a(r!=null),typeof u=="number"?(a(Array.isArray(r),"Invalid key - child is not an array"),(r=r.slice()).splice(u,1)):(a(E(r),"Invalid key - child is not an object"),delete(r=Object.assign({},r))[u]),r}function h(r,u,y){return typeof u=="number"?(a(r!=null,"Container is missing for key"),a(Array.isArray(r),"Cannot use numerical key for object container"),a(r.length>=u,"Cannot insert into out of bounds index"),r.splice(u,0,y)):(a(E(r),"Cannot insert into missing item"),a(r[u]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),r[u]=y),y}n.removeOp=(r,u=!0)=>s.writeCursor().writeAtPath(r,"r",u).get(),n.moveOp=(r,u)=>s.writeCursor().writeMove(r,u).get(),n.insertOp=(r,u)=>s.writeCursor().writeAtPath(r,"i",u).get(),n.replaceOp=(r,u,y)=>s.writeCursor().at(r,D=>{D.write("r",u),D.write("i",y)}).get(),n.editOp=(r,u,y,D=!1)=>s.writeCursor().at(r,b=>_(b,u,y,D)).get();const j=(r,u)=>r!=null&&(typeof u=="number"?Array.isArray(r):typeof r=="object"),Y=(r,u)=>j(r,u)?r[u]:void 0,pe={};function J(r){let u=r.type?r.type:r;u.name&&(pe[u.name]=u),u.uri&&(pe[u.uri]=u)}const Ie=r=>{const u=pe[r];if(u)return u;throw Error("Missing type: "+r)};J(Kt());const Le=(r,u)=>r+u;J({name:"number",apply:Le,compose:Le,invert:r=>-r,transform:r=>r});const ve=r=>r==null?null:r.et?Ie(r.et):r.es?pe["text-unicode"]:r.ena!=null?pe.number:null,f=r=>r.es?r.es:r.ena!=null?r.ena:r.e,_=(r,u,y,D=!1)=>{const[b,C]=typeof u=="string"?[Ie(u),u]:[u,u.name];!D&&b.isNoop&&b.isNoop(y)||(C==="number"?r.write("ena",y):C==="text-unicode"?r.write("es",y):(r.write("et",C),r.write("e",y)))};function w(r){a(typeof r=="number"),a(r>=0),a(r===(0|r))}function L(r){typeof r=="number"?w(r):a(typeof r=="string")}function z(r){if(r===null)return;const u=new Set,y=new Set,D=C=>{let $=!0,R=!1;for(let p in C){const v=C[p];if($=!1,a(p==="p"||p==="r"||p==="d"||p==="i"||p==="e"||p==="es"||p==="ena"||p==="et","Invalid component item '"+p+"'"),p==="p")w(v),a(!u.has(v)),u.add(v),a(C.r===void 0);else if(p==="d")w(v),a(!y.has(v)),y.add(v),a(C.i===void 0);else if(p==="e"||p==="es"||p==="ena"){a(!R),R=!0;const m=ve(C);a(m,"Missing type in edit"),m.checkValidOp&&m.checkValidOp(f(C))}}a(!$)},b=(C,$,R)=>{if(!Array.isArray(C))throw Error("Op must be null or a list");if(C.length===0)throw Error("Empty descent");$||L(C[0]);let p=1,v=0,m=0;for(let I=0;I<C.length;I++){const k=C[I];if(a(k!=null),Array.isArray(k)){const G=b(k,!1);if(v){const g=typeof m,U=typeof G;g===U?a(m<G,"descent keys are not in order"):a(g==="number"&&U==="string")}m=G,v++,p=3}else typeof k=="object"?(a(p===1,`Prev not scalar - instead ${p}`),D(k),p=2):(a(p!==3),L(k),a(s.isValidPathItem(k),"Invalid path key"),p=1)}return a(v!==1,"Operation makes multiple descents. Remove some []"),a(p===2||p===3),C[0]};b(r,!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(r){let u=0,y=[];const D=s.writeCursor();return D.mergeTree(r,(b,C)=>{const $=ve(b);if($){const p=f(b);_(C,$,$.normalize?$.normalize(p):p)}for(const p of["r","p","i","d"])if(b[p]!==void 0){const v=p==="p"||p==="d"?(R=b[p],y[R]==null&&(y[R]=u++),y[R]):b[p];C.write(p,v)}var R}),D.get()}function De(r,u){if(z(u),u===null)return r;const y=[];return function D(b,C){let $=b,R=0,p={root:b},v=0,m=p,I="root";function k(){for(;v<R;v++){let G=C[v];typeof G!="object"&&(a(j(m,I)),m=m[I]=W(m[I]),I=G)}}for(;R<C.length;R++){const G=C[R];if(Array.isArray(G)){const g=D($,G);g!==$&&g!==void 0&&(k(),$=m[I]=g)}else if(typeof G=="object"){G.d!=null?(k(),$=h(m,I,y[G.d])):G.i!==void 0&&(k(),$=h(m,I,G.i));const g=ve(G);if(g)k(),$=m[I]=g.apply($,f(G));else if(G.e!==void 0)throw Error("Subtype "+G.et+" undefined")}else $=Y($,G)}return p.root}(r=function D(b,C){const $=[];let R=0;for(;R<C.length;R++){const I=C[R];if(Array.isArray(I))break;typeof I!="object"&&($.push(b),b=Y(b,I))}for(let I=C.length-1;I>=R;I--)b=D(b,C[I]);for(--R;R>=0;R--){const I=C[R];if(typeof I!="object"){const k=$.pop();b=b===Y(k,I)?k:b===void 0?c(k,I):(v=I,m=b,(p=W(p=k))[v]=m,p)}else O(I)&&(a(b!==void 0,"Cannot pick up or remove undefined"),I.p!=null&&(y[I.p]=b),b=void 0)}var p,v,m;return b}(r,u),u)}function ue(r,u){r=r.slice(),z(u);const y=s.readCursor(u);let D,b,C=!1;const $=[];for(let p=0;;p++){const v=r[p],m=y.getComponent();if(m&&(m.r!==void 0?C=!0:m.p!=null&&(C=!1,D=m.p,b=p)),p>=r.length)break;let I=0;const k=s.advancer(y,void 0,(g,U)=>{O(U)&&I++});$.unshift(k);const G=k(v);if(typeof v=="number"&&(r[p]-=I),!G)break}if($.forEach(p=>p.end()),C)return null;const R=()=>{let p=0;if(D!=null){const v=y.getPath();p=v.length,r=v.concat(r.slice(b))}for(;p<r.length;p++){const v=r[p],m=l(y),I=ve(m);if(I){const g=f(m);I.transformPosition&&(r[p]=I.transformPosition(r[p],g));break}let k=0;const G=s.advancer(y,(g,U)=>o(U)?~(g-k):g-k,(g,U)=>{o(U)&&k++})(v);if(typeof v=="number"&&(r[p]+=k),!G)break}};return D!=null?y.eachDrop(null,p=>{p===D&&R()}):R(),r}function ne(r,u){if(z(r),z(u),r==null)return u;if(u==null)return r;let y=0;const D=s.readCursor(r),b=s.readCursor(u),C=s.writeCursor(),$=[],R=[],p=[],v=[],m=[],I=[],k=new Set;D.traverse(null,g=>{g.p!=null&&(p[g.p]=D.clone())}),b.traverse(null,g=>{g.d!=null&&(v[g.d]=b.clone())});const G=s.writeCursor();return function g(U,re,te,K,se,ke,be,_e){a(re||te);const oe=l(re),Pe=l(te),Se=!!Pe&&Pe.r!==void 0,He=!!oe&&oe.i!==void 0,Me=oe?oe.d:null,Ee=Pe?Pe.p:null,$e=(ke||Se)&&Ee==null;if(Ee!=null)K=v[Ee],be=R[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(Me!=null)if(U=p[Me],_e=$[Me]=new s.WriteCursor,$e)ke&&!Se&&_e.write("r",!0);else{const P=m[Me]=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 M;He?(a(se===void 0),M=oe.i):M=se;const B=(Ee==null?!He||ke||Se:M===void 0)?null:be.getComponent();if(Ee!=null){if(!(se!==void 0||He)){const P=Me!=null?m[Me]:y++;I[Ee]=P,_e.write("p",P)}}else Se&&(He||se!==void 0||(Pe.r,_e.write("r",Pe.r)));const S=$e?null:ve(oe),A=ve(Q);if((S||A)&&(S&&S.name,A&&A.name),S&&A){a(S===A);const P=f(oe),x=f(Q),he=S.compose(P,x);_(be,S,he),k.add(Q)}else S?_(be,S,f(oe)):A&&(_(be,A,f(Q)),k.add(Q));const N=typeof M=="object"&&M!=null;let X=!1,Z=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)=>O(x)?Z-P-1:P-Z,(P,x)=>{O(x)&&Z++});if(s.eachChildOf(re,te,(P,x,he)=>{let me,We,Ke=P,Ue=P,Je=P;if(typeof P=="number"){let Oe=P+fe;We=ye(Oe),Ue=Oe+de;let ce=P+ee;me=q(ce),o(l(We))&&(me=null),Ke=ce+Z,Je=P+ae,a(Ke>=0,"p1PickKey is negative"),a(Ue>=0,"p2DropKey is negative");const Ne=o(l(x)),Ge=O(l(he));(Ne||Ge&&!$e)&&ae--,Ne&&ee--,Ge&&fe--}else me=q(P),We=ye(P);_e.descend(Ke),be.descend(Ue);const Xe=N&&!o(l(x))?M[Je]:void 0,Te=g(me,x,he,We,Xe,$e,be,_e);var Re,T,ie;N&&!$e?Xe!==Te&&(X||(M=Array.isArray(M)?M.slice():Object.assign({},M),X=!0),Re=M,ie=Te,typeof(T=Je)=="number"?(a(Array.isArray(Re)),a(T<Re.length)):(a(!Array.isArray(Re)),a(Re[T]!==void 0)),ie===void 0?typeof T=="number"?Re.splice(T,1):delete Re[T]:Re[T]=ie):a(Te===void 0),be.ascend(),_e.ascend()}),q.end(),ye.end(),B!=null)B.i=M;else if(!ke&&!Se&&Ee==null)return M}(D,D.clone(),b,b.clone(),void 0,!1,C,G),C.reset(),C.mergeTree(G.get()),C.reset(),C.get(),$.map(g=>g.get()),R.map(g=>g.get()),D.traverse(C,(g,U)=>{const re=g.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 g.r!==void 0&&U.write("r",g.r)}),C.reset(),C.get(),b.traverse(C,(g,U)=>{const re=g.d;if(re!=null){const K=I[re];K!=null&&U.write("d",K);const se=R[re];se&&U.mergeTree(se.get())}else g.i!==void 0&&U.write("i",g.i);const te=ve(g);te&&!k.has(g)&&_(U,te,f(g))}),C.get()}function le(r){if(r==null)return null;const u=new s.ReadCursor(r),y=new s.WriteCursor;let D;const b=[],C=[];return function $(R,p,v){const m=R.getComponent();let I,k=!1;if(m){m.p!=null&&(p.write("d",m.p),b[m.p]=R.clone()),m.r!==void 0&&p.write("i",m.r),m.d!=null&&(p.write("p",m.d),v=void 0),m.i!==void 0&&(v=I=m.i);const g=ve(m);g&&(v===void 0?(D||(D=new Set),D.add(m)):(f(m),v=g.apply(v,f(m)),k=!0))}let G=0;for(const g of R){p.descend(g);const U=typeof g=="number"?g-G:g,re=Y(v,U);o(R.getComponent())&&G++;const te=$(R,p,re);if(v!==void 0&&te!==void 0){if(k||(k=!0,v=W(v)),!j(v,U))throw Error("Cannot modify child - invalid operation");v[U]=te}p.ascend()}if(I===void 0)return k?v:void 0;p.write("r",v)}(u,y,void 0),D&&(y.reset(),function $(R,p,v){const m=p.getComponent();if(m){const g=m.d;if(g!=null&&(R=b[g],v=C[g]=s.writeCursor()),D.has(m)){const U=ve(m);if(!U.invert)throw Error(`Cannot invert subtype ${U.name}`);_(v,U,U.invert(f(m)))}}let I=0,k=0;const G=s.advancer(R,(g,U)=>O(U)?I-g-1:g-I,(g,U)=>{O(U)&&I++});for(const g of p)if(typeof g=="number"){const U=g-k,re=G(U),te=U+I;v.descend(te),$(re,p,v),o(p.getComponent())&&k++,v.ascend()}else v.descend(g),$(G(g),p,v),v.ascend();G.end()}(u.clone(),u,y),C.length&&(y.reset(),u.traverse(y,($,R)=>{const p=$.p;if(p!=null){const v=C[p];v&&v.get(),v&&R.mergeTree(v.get())}}))),y.get()}const ge=(r,u)=>r.some(y=>typeof y=="object"&&(Array.isArray(y)?ge(y,u):u(y)));function Ae(r,u){if(r==null||!ge(r,p=>{var v;return p.r!==void 0||((v=ve(p))===null||v===void 0?void 0:v.makeInvertible)!=null}))return r;const y=new s.ReadCursor(r),D=new s.WriteCursor;let b=!1;const C=[],$=[],R=(p,v,m)=>{const I=p.getComponent();let k=!1;if(I){I.d!=null&&v.write("d",I.d),I.i!==void 0&&v.write("i",I.i);const g=I.p;if(g!=null&&(C[g]=p.clone(),a(m!==void 0,"Operation picks up at an invalid key"),$[g]=m,v.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=ve(I);U&&(U.makeInvertible?b=!0:_(v,U,f(I),!0))}let G=0;for(const g of p){v.descend(g);const U=typeof g=="number"?g-G:g,re=Y(m,U),te=R(p,v,re);re!==te&&(k||(k=!0,m=W(m)),te===void 0?(m=c(m,U),typeof g=="number"&&G++):m[U]=te),v.ascend()}return I&&(I.r!==void 0?(v.write("r",i.default(m)),m=void 0):I.p!=null&&(m=void 0)),m};return R(y,D,u),D.get(),b&&(D.reset(),function p(v,m,I,k,G){const g=m.getComponent();if(g){g.i!==void 0?(k=g.i,G=!0):g.d!=null&&(k=$[g.d],v=C[g.d],G=!1,g.d);let K=ve(g);if(K&&K.makeInvertible){const se=f(g);_(I,K,K.makeInvertible(se,k),!0)}}let U=0,re=0;const te=s.advancer(v,(K,se)=>O(se)?U-K-1:K-U,(K,se)=>{O(se)&&U++});for(const K of m)if(typeof K=="number"){const se=K-re,ke=te(se),be=se+U,_e=Y(k,G?se:be);I.descend(K),p(ke,m,I,_e,G),o(m.getComponent())&&re++,I.ascend()}else{const se=Y(k,K);I.descend(K),p(te(K),m,I,se,G),I.ascend()}te.end()}(y.clone(),y,D,u,!1)),D.get()}function jt(r,u){return le(Ae(r,u))}const nt=r=>{if(r==null)return null;const u=r.slice();for(let y=0;y<r.length;y++){const D=u[y];Array.isArray(D)&&(u[y]=nt(D))}return u};function rt(r,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:r};z(r),z(u);let b=null;const C=[],$=[],R=[],p=[],v=[],m=[],I=[],k=[],G=[],g=[],U=[],re=[],te=[],K=[],se=[];let ke=0;const be=s.readCursor(r),_e=s.readCursor(u),oe=s.writeCursor();if(function Q(M,B=null,S){const A=l(B);A&&(A.r!==void 0?S=B.clone():A.p!=null&&(S=null,m[A.p]=M.clone()));const N=M.getComponent();let X;N&&(X=N.p)!=null&&(v[X]=B?B.clone():null,R[X]=M.clone(),S&&(g[X]=!0,G[X]=S),A&&A.p!=null&&(K[X]=A.p));const Z=s.advancer(B);for(const ee of M)Q(M,Z(ee),S);Z.end()}(_e,be,null),function Q(M,B,S,A,N){const X=S.getComponent();let Z,ee=!1;X&&((Z=X.d)!=null?(p[Z]=S.clone(),A!=null&&(se[A]==null&&(se[A]=[]),se[A].push(Z)),M=v[Z]||null,B=R[Z]||null,g[Z]?(N&&(U[Z]=!0),N=G[Z]||null):!N||D!==1&&K[Z]!=null||b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.moveOp(B.getPath(),S.getPath())}),ee=!0):X.i!==void 0&&(M=B=null,ee=!0,N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.insertOp(S.getPath(),X.i)})));const fe=l(M);fe&&(fe.r!==void 0?N=M.clone():fe.p!=null&&(fe.p,A=fe.p,N=null));const de=ve(X);de&&N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.editOp(S.getPath(),de,f(X),!0)});let ae=0,ye=0;const q=s.advancer(B,(x,he)=>O(he)?ae-x-1:x-ae,(x,he)=>{O(he)&&ae++}),P=s.advancer(M);for(const x of S)if(typeof x=="number"){const he=x-ye,me=q(he);ye+=+Q(P(he+ae),me,S,A,N)}else{const he=q(x);Q(P(x),he,S,A,N)}return q.end(),P.end(),ee}(be,_e,_e.clone(),null,null),p.map(Q=>Q&&Q.get()),b)return{ok:!1,conflict:b};U.map(Q=>!!Q);const Pe=[];let Se=null;(function Q(M,B,S,A,N){let X=!1;const Z=l(B);if(O(Z)){const q=Z.p;q!=null?(S=p[q],A=re[q]=s.writeCursor(),X=!0,N=null):(S=null,N=B.clone())}else o(l(S))&&(S=null);const ee=M.getComponent();if(ee){const q=ee.p;q!=null?(N&&(k[q]=N),Pe[q]=N||D===1&&X?null:A.getComponent(),C[q]=M.clone(),S&&(I[q]=S.clone())):ee.r!==void 0&&(N||A.write("r",!0),(N||X)&&(Se==null&&(Se=new Set),Se.add(ee)))}let fe=0,de=0;const ae=s.advancer(B,void 0,(q,P)=>{O(P)&&fe++}),ye=s.advancer(S,(q,P)=>o(P)?~(q-de):q-de,(q,P)=>{o(P)&&de++});if(M)for(const q of M)if(typeof q=="string"){const P=ae(q),x=ye(q);A.descend(q),Q(M,P,x,A,N),A.ascend()}else{const P=ae(q),x=q-fe,he=O(l(P))?null:ye(x),me=x+de;a(me>=0),A.descend(me),Q(M,P,he,A,N),A.ascend()}ae.end(),ye.end()})(be,_e,_e.clone(),oe,null),oe.reset();let He=[];if(function Q(M,B,S,A,N,X){a(B);const Z=B.getComponent();let ee=l(A),fe=!1;const de=(T,ie,Oe)=>T?n.moveOp(T.getPath(),ie.getPath()):n.insertOp(ie.getPath(),Oe.i);if(o(Z)){const T=Z.d;T!=null&&($[T]=B.clone());const ie=T!=null?Pe[T]:null;let Oe=!1;if(Z.i!==void 0||T!=null&&ie){let ce;ee&&(ee.i!==void 0||(ce=ee.d)!=null&&!g[ce])&&(Oe=ce!=null?T!=null&&T===K[ce]:t.default(ee.i,Z.i),Oe||ce!=null&&D!==1&&K[ce]!=null||b==null&&(b={type:d.ConflictType.DROP_COLLISION,op1:de(T!=null?C[T]:null,B,Z),op2:de(ce!=null?R[ce]:null,A,ee)})),Oe||(X?b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:de(T!=null?C[T]:null,B,Z),op2:n.removeOp(X.getPath())}):(T!=null?(He[ke]=T,N.write("d",ie.p=ke++)):N.write("i",i.default(Z.i)),fe=!0))}else if(T!=null&&!ie){const ce=k[T];ce&&(X=ce.clone())}T!=null?(M=C[T],S=m[T],A=I[T]):Z.i!==void 0&&(M=S=null,Oe||(A=null))}else O(l(M))&&(M=S=A=null);const ae=l(M),ye=l(S);if(O(ye)){const T=ye.p;ye.r!==void 0&&(!ae||ae.r===void 0)||g[T]?(A=null,X=S.clone()):T!=null&&(A=p[T],D!==1&&K[T]!=null||((N=te[T])||(N=te[T]=s.writeCursor()),N.reset(),X=null))}else!o(Z)&&o(ee)&&(A=null);ee=A!=null?A.getComponent():null;const q=ve(Z);if(q){const T=f(Z);if(X)b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.editOp(B.getPath(),q,T,!0),op2:n.removeOp(X.getPath())});else{const ie=ve(ee);let Oe;if(ie){if(q!==ie)throw Error("Transforming incompatible types");const ce=f(ee);Oe=q.transform(T,ce,y)}else Oe=i.default(T);_(N,q,Oe)}}let P=0,x=0,he=0,me=0,We=0,Ke=0,Ue=M!=null&&M.descendFirst(),Je=Ue;const Xe=s.advancer(S,void 0,(T,ie)=>{O(ie)&&he++});let Te=A!=null&&A.descendFirst(),Re=Te;for(const T of B)if(typeof T=="number"){let ie;const Oe=o(B.getComponent()),ce=T-x;{let xe;for(;Ue&&typeof(xe=M.getKey())=="number";){xe+=P;const je=M.getComponent(),Ze=O(je);if(xe>ce||xe===ce&&(!Ze||D===0&&Oe))break;if(Ze){P--;const Fe=je.p;K.includes(Fe),je.d,l(te[je.d]),O(l(te[je.d])),(je.r===void 0||Se&&Se.has(je))&&(Fe==null||!Pe[Fe]||D!==1&&K.includes(Fe))||We--}Ue=M.nextSibling()}ie=Ue&&xe===ce?M:null}const Ne=ce-P;let Ge=Xe(Ne);const it=Ne-he;let et=null;{let xe,je;for(;Te&&typeof(xe=A.getKey())=="number";){je=xe-me;const Ze=A.getComponent(),Fe=o(Ze);if(je>it)break;if(je===it){if(!Fe){et=A;break}{if(D===0&&Oe){et=A;break}const Ve=Ge&&O(Ge.getComponent());if(D===0&&Ve)break}}if(Fe){const Ve=Ze.d;K[Ve],Ze.i===void 0&&(g[Ve]||K[Ve]!=null&&D!==1)?(g[Ve]||K[Ve]!=null&&D===0)&&(me++,Ke--):me++}Te=A.nextSibling()}}const vt=it+me+We+Ke;a(vt>=0,"trying to descend to a negative index"),N.descend(vt),Oe&&(ie=Ge=et=null,x++),Q(ie,B,Ge,et,N,X)&&Ke++,N.ascend()}else{let ie;for(;Ue&&(ie=M.getKey(),typeof ie!="string"||!(ie>T||ie===T));)Ue=M.nextSibling();const Oe=Ue&&ie===T?M:null,ce=Xe(T);let Ne;for(;Te&&(Ne=A.getKey(),typeof Ne!="string"||!(Ne>T||Ne===T));)Te=A.nextSibling();const Ge=Te&&Ne===T?A:null;N.descend(T),Q(Oe,B,ce,Ge,N,X),N.ascend()}return Xe.end(),Je&&M.ascend(),Re&&A.ascend(),fe}(be,be.clone(),_e,_e.clone(),oe,null),b)return{ok:!1,conflict:b};oe.reset();const Me=(Q,M,B)=>Q.traverse(M,(S,A)=>{S.d!=null&&B(S.d,Q,A)});(g.length||re.length)&&(Me(_e,oe,(Q,M,B)=>{g[Q]&&!U[Q]&&B.write("r",!0),re[Q]&&B.mergeTree(re[Q].get())}),oe.reset());const Ee=[],$e=[];if((te.length||g.length)&&!b){const Q=s.readCursor(nt(oe.get()));if(Me(Q,null,(M,B)=>{Ee[M]=B.clone()}),te.forEach(M=>{M&&Me(s.readCursor(M.get()),null,(B,S)=>{Ee[B]=S.clone()})}),function M(B,S,A,N,X,Z){const ee=l(S);if(ee&&O(ee))if(ee.p!=null){const P=ee.p;Ee[P].getPath(),A=Ee[P],N=$e[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(S,void 0,(P,x)=>{O(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),M(B,x,me,N),N.ascend()}else N.descend(P),M(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(),$e.length){const M=$e.map(S=>S?S.get():null),B=s.readCursor(nt(oe.get()));if(Me(B,oe,(S,A,N)=>{const X=M[S];X&&(N.mergeTree(X),M[S]=null)}),M.find(S=>S)){const S=s.writeCursor(),A=s.writeCursor();let N=0,X=0;M.forEach(Z=>{Z!=null&&Me(s.readCursor(Z),null,ee=>{const fe=He[ee];S.writeMove(C[fe].getPath(),$[fe].getPath(),N++);const de=se[fe];de&&de.forEach(ae=>{g[ae]||D!==1&&K[ae]!=null||A.writeMove(R[ae].getPath(),p[ae].getPath(),X++)})})}),b={type:d.ConflictType.BLACKHOLE,op1:S.get(),op2:A.get()}}}}return b?{ok:!1,conflict:b}:{ok:!0,result:oe.get()}}const _t=r=>{const u=new Error("Transform detected write conflict");throw u.conflict=r,u.type=u.name="writeConflict",u};function Tt(r,u,y){const D=rt(r,u,y);if(D.ok)return D.result;_t(D.conflict)}const ze=r=>{const u=s.writeCursor();return s.readCursor(r).traverse(u,(y,D)=>{(o(y)||ve(y))&&D.write("r",!0)}),u.get()},Rt=(r,u)=>{const{type:y,op1:D,op2:b}=r;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 Ot(r,u,y,D){let b=null;for(;;){const C=rt(u,y,D);if(C.ok)return ne(b,C.result);{const{conflict:$}=C;r($)||_t($);const[R,p]=Rt($,D);u=ne(H(u),R),y=ne(H(y),p),b=ne(b,p)}}}})(Et);(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(Et,n);var i=ht;Object.defineProperty(n,"ReadCursor",{enumerable:!0,get:function(){return i.ReadCursor}}),Object.defineProperty(n,"WriteCursor",{enumerable:!0,get:function(){return i.WriteCursor}});var s=pt;Object.defineProperty(n,"ConflictType",{enumerable:!0,get:function(){return s.ConflictType}})})(V);class Dt{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 i=this._getCurrentBySearch(t);i!=null&&(i.transform=t.transform,i.transforms=t.transforms,i.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 i=[];Object.keys(t).forEach(s=>{const d=t[s];(d==null?void 0:d.data)!=null&&Object.keys(d.data).forEach(a=>{i.push({unitId:e,subUnitId:s,drawingId:a})})}),i.length>0&&this.removeNotification(i)}registerDrawingData(e,t){this.drawingManagerData[e]=t}initializeNotification(e){const t=[],i=this.drawingManagerData[e];i!=null&&(Object.keys(i).forEach(s=>{this._establishDrawingMap(e,s);const d=i[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,i){this.drawingManagerData[e][t].data=i}getBatchAddOp(e){const t=[],i=[],s=[];e.forEach(W=>{const{op:O,invertOp:o}=this._addByParam(W);t.push({unitId:W.unitId,subUnitId:W.subUnitId,drawingId:W.drawingId}),i.push(O),s.push(o)});const d=i.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=[],i=[];e.forEach(E=>{const{op:W,invertOp:O}=this._removeByParam(E);t.push(W),i.push(O)});const s=t.reduce(V.type.compose,null),d=i.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=[],i=[],s=[];e.forEach(W=>{const{op:O,invertOp:o}=this._updateByParam(W);t.push({unitId:W.unitId,subUnitId:W.subUnitId,drawingId:W.drawingId}),i.push(O),s.push(o)});const d=i.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:i,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:i,subUnitId:s,objects:e}}getUngroupDrawingOp(e){const t=[],{unitId:i,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:i,subUnitId:s,objects:e}}getDrawingsByGroup(e){const{unitId:t,subUnitId:i,drawingId:s}=e;if(this.getDrawingByParam({unitId:t,subUnitId:i,drawingId:s})==null)return[];const a=this._getDrawingData(t,i),l=[];return Object.keys(a).forEach(E=>{const W=a[E];W.groupId===s&&l.push(W)}),l}_getGroupDrawingOp(e){const{parent:t,children:i}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];l.push(V.insertOp([s,d,"data",a],t));let E=Number.NEGATIVE_INFINITY;return i.forEach(W=>{const{unitId:O,subUnitId:o,drawingId:c}=W,h=this._hasDrawingOrder({unitId:O,subUnitId:o,drawingId:c});E=Math.max(E,h),l.push(...this._getUpdateParamCompareOp(W,this.getDrawingByParam({unitId:O,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:i}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];return i.forEach(E=>{const{unitId:W,subUnitId:O,drawingId:o}=E;l.push(...this._getUpdateParamCompareOp(E,this.getDrawingByParam({unitId:W,subUnitId:O,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,i){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=V.type.apply(this.drawingManagerData,i)}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,i,s]=e.split("#-#");return this._getCurrentBySearch({unitId:t,subUnitId:i,drawingId:s})}focusDrawing(e){if(e==null){this._focusDrawings=[],this._focus$.next([]);return}const t=[];e.forEach(i=>{var E;const{unitId:s,subUnitId:d,drawingId:a}=i,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:i,subUnitId:s,drawingId:d}=t,a=(l=this._getDrawingData(i,s))==null?void 0:l[d];a!=null&&e.push(a)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,i){this.drawingManagerData[e][t].order=i}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,i),l=[...s];s.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:i,drawingId:O});if(o===-1||o===a.length-1)return;const c=V.moveOp([t,i,"order",o],[t,i,"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:i,objects:{...e,drawingIds:l}}}getBackwardDrawingOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,i),l=[...s];s.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:i,drawingId:O});if(o===-1||o===0)return;const c=V.moveOp([t,i,"order",o],[t,i,"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:i,objects:{...e,drawingIds:l}}}getFrontDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,i,s),a=[...s],l=this.getDrawingOrder(t,i),E=[];d.forEach(o=>{const{drawingId:c}=o,h=this._getDrawingCount(t,i)-1,j=V.moveOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(c)],[t,i,"order",h]);E.push(j),a.includes(l[h])||a.push(l[h])});const W=E.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(W,this.drawingManagerData),redo:W,unitId:t,subUnitId:i,objects:{...e,drawingIds:a}}}getBackDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,i,s,!0),a=[...s],l=this.getDrawingOrder(t,i),E=[];d.forEach(o=>{const{drawingId:c}=o,h=V.moveOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(c)],[t,i,"order",0]);E.push(h),a.includes(l[0])||a.push(l[0])});const W=E.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(W,this.drawingManagerData),redo:W,unitId:t,subUnitId:i,objects:{...e,drawingIds:a}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,t,i,s=!1){return i.map(d=>{const a=this._hasDrawingOrder({unitId:e,subUnitId:t,drawingId:d});return{drawingId:d,zIndex:a}}).sort(s===!1?Be.sortRules:Be.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;const{unitId:t,subUnitId:i,drawingId:s}=e;return this._establishDrawingMap(t,i),this._getDrawingOrder(t,i).indexOf(s)}_getCurrentBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:i,drawingId:s}=e;return(l=(a=(d=this.drawingManagerData[t])==null?void 0:d[i])==null?void 0:a.data)==null?void 0:l[s]}_getOldBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:i,drawingId:s}=e;return(l=(a=(d=this._oldDrawingManagerData[t])==null?void 0:d[i])==null?void 0:a.data)==null?void 0:l[s]}_establishDrawingMap(e,t,i){var s;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),i==null?null:(s=this.drawingManagerData[e][t].data)==null?void 0:s[i]}_addByParam(e){const{unitId:t,subUnitId:i,drawingId:s}=e;this._establishDrawingMap(t,i,s);const d=V.insertOp([t,i,"data",s],e),a=V.insertOp([t,i,"order",this._getDrawingOrder(t,i).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:i,drawingId:s}=e;if(this._establishDrawingMap(t,i,s)==null)return{op:[],invertOp:[]};const a=V.removeOp([t,i,"data",s],!0),l=V.removeOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(s)],!0),E=[a,l].reduce(V.type.compose,null),W=V.type.invertWithDoc(E,this.drawingManagerData);return{op:E,invertOp:W}}_updateByParam(e){const{unitId:t,subUnitId:i,drawingId:s}=e,d=this._establishDrawingMap(t,i,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:i,subUnitId:s,drawingId:d}=e,a=[];return Object.keys(e).forEach(l=>{const E=e[l],W=t[l];W!==E&&a.push(V.replaceOp([i,s,"data",d,l],W,E))}),a}_getDrawingData(e,t){var i,s;return((s=(i=this.drawingManagerData[e])==null?void 0:i[t])==null?void 0:s.data)||{}}_getDrawingOrder(e,t){var i,s;return((s=(i=this.drawingManagerData[e])==null?void 0:i[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 At extends Dt{}function Ft({unitId:n,subUnitId:e,drawingId:t},i){return typeof i=="number"?`${n}#-#${e}#-#${t}#-#${i}`:`${n}#-#${e}#-#${t}`}const Vt=async n=>new Promise((e,t)=>{const i=new Image;i.src=n,i.onload=()=>{e({width:i.width,height:i.height,image:i})},i.onerror=s=>{t(s)}});var Qe=(n=>(n.URL="URL",n.UUID="UUID",n.BASE64="BASE64",n))(Qe||{}),Ye=(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))(Ye||{});const Pt=Be.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 i=new Image;return i.src=e,i}return this._imageSourceCache.get(e)}addImageSourceCache(e,t,i){t===Qe.BASE64||i==null||this._imageSourceCache.set(e,i)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((t,i)=>{if(!Ct.includes(e.type)){i(new Error(Ye.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>It){i(new Error(Ye.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){i(new Error(Ye.ERROR_IMAGE)),this._decreaseWaiting();return}const l=Be.Tools.generateRandomId(6);t({imageId:l,imageSourceType:Qe.BASE64,source:a,base64Cache:a,status:Ye.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}}const qt="__default_document_sub_component_id20231101__";var St=(n=>(n[n.forward=0]="forward",n[n.backward=1]="backward",n[n.front=2]="front",n[n.back=3]="back",n))(St||{}),Ut=(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))(Ut||{});const Nt=Be.createIdentifier("univer.drawing-manager.service");var zt=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,Zt=(n,e,t,i)=>{for(var s=i>1?void 0:i?Xt(e,t):e,d=n.length-1,a;d>=0;d--)(a=n[d])&&(s=(i?a(e,t,s):a(s))||s);return i&&s&&zt(e,t,s),s},Yt=(n,e)=>(t,i)=>e(t,i,n);const Jt="DRAWING_PLUGIN";var at;exports.UniverDrawingPlugin=(at=class extends Be.Plugin{constructor(e,t){super(),this._config=e,this._injector=t}onStarting(e){this._initDependencies(e)}_initDependencies(e){var s;const t=[[Pt,{useClass:Mt}],[Nt,{useClass:At}]];Be.mergeOverrideWithDependencies(t,(s=this._config)==null?void 0:s.override).forEach(d=>e.add(d))}},F(at,"pluginName",Jt),at);exports.UniverDrawingPlugin=Zt([Yt(1,Be.Inject(Be.Injector))],exports.UniverDrawingPlugin);exports.ArrangeTypeEnum=St;exports.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=qt;exports.DRAWING_IMAGE_ALLOW_IMAGE_LIST=Ct;exports.DRAWING_IMAGE_ALLOW_SIZE=It;exports.DRAWING_IMAGE_COUNT_LIMIT=Bt;exports.DRAWING_IMAGE_HEIGHT_LIMIT=Gt;exports.DRAWING_IMAGE_WIDTH_LIMIT=Wt;exports.DrawingManagerService=At;exports.DrawingTypeEnum=Ut;exports.IDrawingManagerService=Nt;exports.IImageIoService=Pt;exports.ImageIoService=Mt;exports.ImageSourceType=Qe;exports.ImageUploadStatusType=Ye;exports.UnitDrawingService=Dt;exports.getDrawingShapeKeyByDrawingSearch=Ft;exports.getImageSize=Vt;
|
package/lib/es/index.js
CHANGED
|
@@ -2,9 +2,8 @@ var Pt = Object.defineProperty;
|
|
|
2
2
|
var Mt = (n, e, t) => e in n ? Pt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
3
|
var V = (n, e, t) => Mt(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { Subject as we } from "rxjs";
|
|
5
|
-
import { sortRules as Ut, sortRulesByDesc as Nt, Tools as kt,
|
|
6
|
-
|
|
7
|
-
const on = 500, ln = 500, an = 10, $t = 5 * 1024 * 1024, Wt = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/bmp"];
|
|
5
|
+
import { sortRules as Ut, sortRulesByDesc as Nt, createIdentifier as It, Tools as kt, Inject as Rt, Injector as St, Plugin as Tt, mergeOverrideWithDependencies as jt } from "@univerjs/core";
|
|
6
|
+
const sn = 500, on = 500, ln = 10, $t = 5 * 1024 * 1024, Wt = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/bmp"];
|
|
8
7
|
var Ce = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, F = {}, Ct = {}, ct = {};
|
|
9
8
|
Object.defineProperty(ct, "__esModule", { value: !0 });
|
|
10
9
|
function Gt(n, e) {
|
|
@@ -1873,10 +1872,10 @@ class Ht {
|
|
|
1873
1872
|
}
|
|
1874
1873
|
class Kt extends Ht {
|
|
1875
1874
|
}
|
|
1876
|
-
function
|
|
1875
|
+
function an({ unitId: n, subUnitId: e, drawingId: t }, i) {
|
|
1877
1876
|
return typeof i == "number" ? `${n}#-#${e}#-#${t}#-#${i}` : `${n}#-#${e}#-#${t}`;
|
|
1878
1877
|
}
|
|
1879
|
-
const
|
|
1878
|
+
const cn = async (n) => new Promise((e, t) => {
|
|
1880
1879
|
const i = new Image();
|
|
1881
1880
|
i.src = n, i.onload = () => {
|
|
1882
1881
|
e({
|
|
@@ -1946,7 +1945,7 @@ class Ft {
|
|
|
1946
1945
|
this._waitCount -= 1, this._change$.next(this._waitCount);
|
|
1947
1946
|
}
|
|
1948
1947
|
}
|
|
1949
|
-
const
|
|
1948
|
+
const un = "__default_document_sub_component_id20231101__";
|
|
1950
1949
|
var qt = /* @__PURE__ */ ((n) => (n[n.forward = 0] = "forward", n[n.backward = 1] = "backward", n[n.front = 2] = "front", n[n.back = 3] = "back", n))(qt || {}), zt = /* @__PURE__ */ ((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))(zt || {});
|
|
1951
1950
|
const Xt = It("univer.drawing-manager.service");
|
|
1952
1951
|
var Yt = Object.defineProperty, Zt = Object.getOwnPropertyDescriptor, Jt = (n, e, t, i) => {
|
|
@@ -1956,7 +1955,7 @@ var Yt = Object.defineProperty, Zt = Object.getOwnPropertyDescriptor, Jt = (n, e
|
|
|
1956
1955
|
}, Qt = (n, e) => (t, i) => e(t, i, n);
|
|
1957
1956
|
const en = "DRAWING_PLUGIN";
|
|
1958
1957
|
var ot;
|
|
1959
|
-
let wt = (ot = class extends
|
|
1958
|
+
let wt = (ot = class extends Tt {
|
|
1960
1959
|
constructor(n, e) {
|
|
1961
1960
|
super(), this._config = n, this._injector = e;
|
|
1962
1961
|
}
|
|
@@ -1965,23 +1964,23 @@ let wt = (ot = class extends Rt {
|
|
|
1965
1964
|
}
|
|
1966
1965
|
_initDependencies(n) {
|
|
1967
1966
|
var i;
|
|
1968
|
-
|
|
1967
|
+
jt([
|
|
1969
1968
|
[Vt, { useClass: Ft }],
|
|
1970
1969
|
[Xt, { useClass: Kt }]
|
|
1971
1970
|
], (i = this._config) == null ? void 0 : i.override).forEach((s) => n.add(s));
|
|
1972
1971
|
}
|
|
1973
1972
|
}, V(ot, "pluginName", en), ot);
|
|
1974
1973
|
wt = Jt([
|
|
1975
|
-
Qt(1,
|
|
1974
|
+
Qt(1, Rt(St))
|
|
1976
1975
|
], wt);
|
|
1977
1976
|
export {
|
|
1978
1977
|
qt as ArrangeTypeEnum,
|
|
1979
|
-
|
|
1978
|
+
un as DEFAULT_DOCUMENT_SUB_COMPONENT_ID,
|
|
1980
1979
|
Wt as DRAWING_IMAGE_ALLOW_IMAGE_LIST,
|
|
1981
1980
|
$t as DRAWING_IMAGE_ALLOW_SIZE,
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1981
|
+
ln as DRAWING_IMAGE_COUNT_LIMIT,
|
|
1982
|
+
on as DRAWING_IMAGE_HEIGHT_LIMIT,
|
|
1983
|
+
sn as DRAWING_IMAGE_WIDTH_LIMIT,
|
|
1985
1984
|
Kt as DrawingManagerService,
|
|
1986
1985
|
zt as DrawingTypeEnum,
|
|
1987
1986
|
Xt as IDrawingManagerService,
|
|
@@ -1991,6 +1990,6 @@ export {
|
|
|
1991
1990
|
Ze as ImageUploadStatusType,
|
|
1992
1991
|
Ht as UnitDrawingService,
|
|
1993
1992
|
wt as UniverDrawingPlugin,
|
|
1994
|
-
|
|
1995
|
-
|
|
1993
|
+
an as getDrawingShapeKeyByDrawingSearch,
|
|
1994
|
+
cn as getImageSize
|
|
1996
1995
|
};
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { IDisposable } from '@
|
|
1
|
+
import { BooleanNumber, IDisposable, Nullable } from '@univerjs/core';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { BooleanNumber, Nullable } from '@univerjs/core';
|
|
4
3
|
import { ITransformState } from './interface';
|
|
5
4
|
|
|
6
5
|
export declare const DEFAULT_DOCUMENT_SUB_COMPONENT_ID = "__default_document_sub_component_id20231101__";
|
|
@@ -147,4 +146,4 @@ export interface IUnitDrawingService<T extends IDrawingParam> extends IUnitNorma
|
|
|
147
146
|
}
|
|
148
147
|
export interface IDrawingManagerService extends IUnitDrawingService<IDrawingParam> {
|
|
149
148
|
}
|
|
150
|
-
export declare const IDrawingManagerService: import('@
|
|
149
|
+
export declare const IDrawingManagerService: import('@univerjs/core').IdentifierDecorator<IUnitDrawingService<IDrawingParam>>;
|
|
@@ -28,4 +28,4 @@ export interface IImageIoService {
|
|
|
28
28
|
getImageSourceCache(source: string, imageSourceType: ImageSourceType): Nullable<HTMLImageElement>;
|
|
29
29
|
addImageSourceCache(source: string, imageSourceType: ImageSourceType, imageSource: Nullable<HTMLImageElement>): void;
|
|
30
30
|
}
|
|
31
|
-
export declare const IImageIoService: import('@
|
|
31
|
+
export declare const IImageIoService: import('@univerjs/core').IdentifierDecorator<IImageIoService>;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(Y,re){typeof exports=="object"&&typeof module<"u"?re(exports,require("rxjs"),require("@univerjs/core"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core","@wendellhu/redi"],re):(Y=typeof globalThis<"u"?globalThis:Y||self,re(Y.UniverDrawing={},Y.rxjs,Y.UniverCore,Y["@wendellhu/redi"]))})(this,function(Y,re,ke,tt){"use strict";var Xt=Object.defineProperty;var Zt=(Y,re,ke)=>re in Y?Xt(Y,re,{enumerable:!0,configurable:!0,writable:!0,value:ke}):Y[re]=ke;var V=(Y,re,ke)=>Zt(Y,typeof re!="symbol"?re+"":re,ke);var gt;const vt=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"];var Ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},F={},yt={},it={};Object.defineProperty(it,"__esModule",{value:!0});function Rt(n,e){if(Array.isArray(e))return!1;for(let t in n)if(!st(n[t],e[t]))return!1;for(let t in e)if(n[t]===void 0)return!1;return!0}function kt(n,e){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!st(n[t],e[t]))return!1;return!0}function st(n,e){return n===e?!0:n===null||e===null||typeof n!="object"||typeof e!="object"?!1:Array.isArray(n)?kt(n,e):Rt(n,e)}it.default=st;var ot={};Object.defineProperty(ot,"__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}ot.default=lt;var at={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.eachChildOf=n.advancer=n.readCursor=n.writeCursor=n.WriteCursor=n.ReadCursor=n.isValidPathItem=void 0;function e(O,o){if(!O)throw new Error(o)}const t=O=>O!=null&&typeof O=="object"&&!Array.isArray(O),i=(O,o)=>typeof O==typeof o?O>o:typeof O=="string"&&typeof o=="number";function s(O,o){for(let c in O){const h=c;o.write(h,O[h])}}n.isValidPathItem=O=>typeof O=="number"||typeof O=="string"&&O!=="__proto__";class d{constructor(o=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=o}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,t(this.container[this.idx])&&this.idx--)}getPath(){const o=[];let c=this.container,h=this.parents.length-1,T=this.idx;for(;T>=0;)o.unshift(c[T]),T===0?(T=this.indexes[h*2],c=this.parents[h--]):T-=t(c[T-1])?2:1;return o}}class l extends d{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let o;return this.container&&this.container.length>this.idx+1&&t(o=this.container[this.idx+1])?o:null}descendFirst(){let o=this.idx+1;if(!this.container||o>=this.container.length||t(this.container[o])&&o+1>=this.container.length)return!1;t(this.container[o])&&o++;const c=this.container[o];return Array.isArray(c)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(o),this.idx=0,this.container=c):this.idx=o,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const o=this.indexes[this.indexes.length-1]+1,c=this.parents[this.parents.length-1];return o>=c.length?!1:(e(!isNaN(o)),this.indexes[this.indexes.length-1]=o,this.container=c[o],!0)}_init(o,c,h,T){this.container=o,this.idx=c,this.parents=h.slice(),this.indexes=T.slice()}clone(){const o=new l;return o._init(this.container,this.idx,this.parents,this.indexes),o}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(o,c){const h=this.getComponent();h&&c(h,o);for(const T of this)o&&o.descend(T),this.traverse(o,c),o&&o.ascend()}eachPick(o,c){this.traverse(o,(h,T)=>{h.p!=null&&c(h.p,T)})}eachDrop(o,c){this.traverse(o,(h,T)=>{h.d!=null&&c(h.d,T)})}}n.ReadCursor=l;class a extends d{constructor(o=null){super(o),this.pendingDescent=[],this._op=o}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let o=0;o<this.pendingDescent.length;o++){const c=this.pendingDescent[o];let h=this.idx+1;if(h<this.container.length&&t(this.container[h])&&h++,e(h===this.container.length||!t(this.container[h])),h===this.container.length)this.container.push(c),this.idx=h;else if(this.container[h]===c)this.idx=h;else{if(!Array.isArray(this.container[h])){const T=this.container.splice(h,this.container.length-h);this.container.push(T),this.lcIdx>-1&&(this.lcIdx=h)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(i(c,this.container[this.lcIdx][0])),h=this.lcIdx+1,this.lcIdx=-1);h<this.container.length&&i(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 T=[c];this.container.splice(h,0,T),this.container=T}}}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,T=this.parents.length;let J=0;for(let _e=0;_e<o.length;_e++){const Q=o[_e];typeof Q=="string"||typeof Q=="number"?(J++,this.descend(Q)):Array.isArray(Q)?this.mergeTree(Q,c):typeof Q=="object"&&c(Q,this)}for(;J--;)this.ascend();this.lcIdx=this.parents.length===T?h:-1}at(o,c){this.descendPath(o),c(this);for(let h=0;h<o.length;h++)this.ascend();return this}writeAtPath(o,c,h){return this.at(o,()=>this.write(c,h)),this.reset(),this}writeMove(o,c,h=0){return this.writeAtPath(o,"p",h).writeAtPath(c,"d",h)}getPath(){const o=super.getPath();return o.push(...this.pendingDescent),o}}n.WriteCursor=a,n.writeCursor=()=>new a,n.readCursor=O=>new l(O);function E(O,o,c){let h,T;T=h=O?O.descendFirst():!1;function J(_e){let Q;for(;T;){const Ce=Q=O.getKey();if(_e!=null){let xe=!1;if(o&&typeof Ce=="number"&&(Q=o(Ce,O.getComponent()),Q<0&&(Q=~Q,xe=!0)),i(Q,_e))return null;if(Q===_e&&!xe)return O}c&&typeof Q=="number"&&c(Q,O.getComponent()),T=O.nextSibling()}return null}return J.end=()=>{h&&O.ascend()},J}n.advancer=E;function G(O,o,c){let h,T,J,_e;for(h=T=O&&O.descendFirst(),J=_e=o&&o.descendFirst();h||J;){let Q=h?O.getKey():null,Ce=J?o.getKey():null;Q!==null&&Ce!==null&&(i(Ce,Q)?Ce=null:Q!==Ce&&(Q=null)),c(Q==null?Ce:Q,Q!=null?O:null,Ce!=null?o:null),Q!=null&&h&&(h=O.nextSibling()),Ce!=null&&J&&(J=o.nextSibling())}T&&O.ascend(),_e&&o.ascend()}n.eachChildOf=G})(at);var ct={};(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={}))})(ct);var ut={},Ke={},bt;function dt(){return bt||(bt=1,Object.defineProperty(Ke,"__esModule",{value:!0}),Ke.uniToStrPos=Ke.strPosToUni=void 0,Ke.strPosToUni=(n,e=n.length)=>{let t=0,i=0;for(;i<e;i++){const s=n.charCodeAt(i);s>=55296&&s<=57343&&(t++,i++)}if(i!==e)throw Error("Invalid offset - splits unicode bytes");return i-t},Ke.uniToStrPos=(n,e)=>{let t=0;for(;e>0;e--){const i=n.charCodeAt(t);t+=i>=55296&&i<=57343?2:1}return t}),Ke}var ft={},mt;function ht(){return mt||(mt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.uniSlice=n.dlen=n.eachOp=void 0;const e=dt(),t=f=>{if(!Array.isArray(f))throw Error("Op must be an array of components");let _=null;for(let I=0;I<f.length;I++){const H=f[I];switch(typeof H){case"object":if(typeof H.d!="number"&&typeof H.d!="string")throw Error("Delete must be number or string");if(n.dlen(H.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(H.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(H>0))throw Error("Skip components must be >0");if(typeof _=="number")throw Error("Adjacent skip components should be combined");break}_=H}if(typeof _=="number")throw Error("Op has a trailing skip")};function i(f,_){let I=0,H=0;for(let z=0;z<f.length;z++){const K=f[z];switch(_(K,I,H),typeof K){case"object":I+=n.dlen(K.d);break;case"string":H+=e.strPosToUni(K);break;case"number":I+=K,H+=K;break}}}n.eachOp=i;function s(f,_){const I=[],H=a(I);return i(f,(z,K,De)=>{H(_(z,K,De))}),o(I)}const d=f=>f,l=f=>s(f,d);n.dlen=f=>typeof f=="number"?f:e.strPosToUni(f);const a=f=>_=>{if(!(!_||_.d===0||_.d===""))if(f.length===0)f.push(_);else if(typeof _==typeof f[f.length-1])if(typeof _=="object"){const I=f[f.length-1];I.d=typeof I.d=="string"&&typeof _.d=="string"?I.d+_.d:n.dlen(I.d)+n.dlen(_.d)}else f[f.length-1]+=_;else f.push(_)},E=f=>typeof f=="number"?f:typeof f=="string"?e.strPosToUni(f):typeof f.d=="number"?f.d:e.strPosToUni(f.d);n.uniSlice=(f,_,I)=>{const H=e.uniToStrPos(f,_),z=I==null?1/0:e.uniToStrPos(f,I);return f.slice(H,z)};const G=(f,_,I)=>typeof f=="number"?I==null?f-_:Math.min(f,I)-_:n.uniSlice(f,_,I),O=f=>{let _=0,I=0;return{take:(K,De)=>{if(_===f.length)return K===-1?null:K;const fe=f[_];let ie;if(typeof fe=="number")return K===-1||fe-I<=K?(ie=fe-I,++_,I=0,ie):(I+=K,K);if(typeof fe=="string"){if(K===-1||De==="i"||e.strPosToUni(fe.slice(I))<=K)return ie=fe.slice(I),++_,I=0,ie;{const ue=I+e.uniToStrPos(fe.slice(I),K);return ie=fe.slice(I,ue),I=ue,ie}}else{if(K===-1||De==="d"||n.dlen(fe.d)-I<=K)return ie={d:G(fe.d,I)},++_,I=0,ie;{let ue=G(fe.d,I,I+K);return I+=K,{d:ue}}}},peek:()=>f[_]}},o=f=>(f.length>0&&typeof f[f.length-1]=="number"&&f.pop(),f);function c(f,_,I){if(I!=="left"&&I!=="right")throw Error("side ("+I+") must be 'left' or 'right'");t(f),t(_);const H=[],z=a(H),{take:K,peek:De}=O(f);for(let ie=0;ie<_.length;ie++){const ue=_[ie];let Oe,Me;switch(typeof ue){case"number":for(Oe=ue;Oe>0;)Me=K(Oe,"i"),z(Me),typeof Me!="string"&&(Oe-=E(Me));break;case"string":I==="left"&&typeof De()=="string"&&z(K(-1)),z(e.strPosToUni(ue));break;case"object":for(Oe=n.dlen(ue.d);Oe>0;)switch(Me=K(Oe,"i"),typeof Me){case"number":Oe-=Me;break;case"string":z(Me);break;case"object":Oe-=n.dlen(Me.d)}break}}let fe;for(;fe=K(-1);)z(fe);return o(H)}function h(f,_){t(f),t(_);const I=[],H=a(I),{take:z}=O(f);for(let De=0;De<_.length;De++){const fe=_[De];let ie,ue;switch(typeof fe){case"number":for(ie=fe;ie>0;)ue=z(ie,"d"),H(ue),typeof ue!="object"&&(ie-=E(ue));break;case"string":H(fe);break;case"object":ie=n.dlen(fe.d);let Oe=0;for(;Oe<ie;)switch(ue=z(ie-Oe,"d"),typeof ue){case"number":H({d:G(fe.d,Oe,Oe+ue)}),Oe+=ue;break;case"string":Oe+=e.strPosToUni(ue);break;case"object":H(ue)}break}}let K;for(;K=z(-1);)H(K);return o(I)}const T=(f,_)=>{let I=0;for(let H=0;H<_.length&&f>I;H++){const z=_[H];switch(typeof z){case"number":{I+=z;break}case"string":const K=e.strPosToUni(z);I+=K,f+=K;break;case"object":f-=Math.min(n.dlen(z.d),f-I);break}}return f},J=(f,_)=>typeof f=="number"?T(f,_):f.map(I=>T(I,_));function _e(f,_,I){return s(f,(H,z)=>typeof H=="object"&&typeof H.d=="number"?{d:I.slice(_,z,z+H.d)}:H)}function Q(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 Ce(f){return s(f,_=>typeof _=="object"&&typeof _.d=="string"?{d:e.strPosToUni(_.d)}:_)}function xe(f){let _=!0;return i(f,I=>{typeof I=="object"&&typeof I.d=="number"&&(_=!1)}),_}function be(f){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:o,normalize:l,checkOp:t,create(_=""){if(typeof _!="string")throw Error("Initial data must be a string");return f.create(_)},apply(_,I){t(I);const H=f.builder(_);for(let z=0;z<I.length;z++){const K=I[z];switch(typeof K){case"number":H.skip(K);break;case"string":H.append(K);break;case"object":H.del(n.dlen(K.d));break}}return H.build()},transform:c,compose:h,transformPosition:T,transformSelection:J,isInvertible:xe,makeInvertible(_,I){return _e(_,I,f)},stripInvertible:Ce,invert:Q,invertWithDoc(_,I){return Q(_e(_,I,f))},isNoop:_=>_.length===0}}n.default=be}(ft)),ft}var nt={},It;function jt(){if(It)return nt;It=1,Object.defineProperty(nt,"__esModule",{value:!0});const n=ht(),e=dt();function t(i,s){return{get:i,getLength(){return i().length},insert(d,l,a){const E=e.strPosToUni(i(),d);return s([E,l],a)},remove(d,l,a){const E=e.strPosToUni(i(),d);return s([E,{d:l}],a)},_onOp(d){n.eachOp(d,(l,a,E)=>{switch(typeof l){case"string":this.onInsert&&this.onInsert(E,l);break;case"object":const G=n.dlen(l.d);this.onRemove&&this.onRemove(E,G)}})},onInsert:null,onRemove:null}}return nt.default=t,t.provides={text:!0},nt}var wt;function $t(){return wt||(wt=1,function(n){var e=Ee&&Ee.__createBinding||(Object.create?function(c,h,T,J){J===void 0&&(J=T),Object.defineProperty(c,J,{enumerable:!0,get:function(){return h[T]}})}:function(c,h,T,J){J===void 0&&(J=T),c[J]=h[T]}),t=Ee&&Ee.__setModuleDefault||(Object.create?function(c,h){Object.defineProperty(c,"default",{enumerable:!0,value:h})}:function(c,h){c.default=h}),i=Ee&&Ee.__importStar||function(c){if(c&&c.__esModule)return c;var h={};if(c!=null)for(var T in c)Object.hasOwnProperty.call(c,T)&&e(h,c,T);return t(h,c),h},s=Ee&&Ee.__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=dt(),l=i(ht()),a=s(jt()),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(T){let J=d.uniToStrPos(c,T);if(J>c.length)throw Error("The op is too long for this document");h.push(c.slice(0,J)),c=c.slice(J)},append(T){h.push(T)},del(T){c=c.slice(d.uniToStrPos(c,T))},build(){return h.join("")+c}}},slice:l.uniSlice},G=l.default(E),O=Object.assign(Object.assign({},G),{api:a.default});n.type=O,n.insert=(c,h)=>h.length===0?[]:c===0?[h]:[c,h],n.remove=(c,h)=>l.dlen(h)===0?[]:c===0?[{d:h}]:[c,{d:h}];var o=ht();Object.defineProperty(n,"makeType",{enumerable:!0,get:function(){return o.default}})}(ut)),ut}(function(n){var e=Ee&&Ee.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(n,"__esModule",{value:!0}),n.editOp=n.replaceOp=n.insertOp=n.moveOp=n.removeOp=n.type=void 0;const t=e(it),i=e(ot),s=at,d=ct;function l(r,u){if(!r)throw new Error(u)}n.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:s.readCursor,writeCursor:s.writeCursor,create:r=>r,isNoop:r=>r==null,setDebug(r){},registerSubtype:Q,checkValidOp:z,normalize:K,apply:De,transformPosition:fe,compose:ie,tryTransform:_t,transform:qt,makeInvertible:Me,invert:ue,invertWithDoc:Vt,RM_UNEXPECTED_CONTENT:d.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:d.ConflictType.DROP_COLLISION,BLACKHOLE:d.ConflictType.BLACKHOLE,transformNoConflict:(r,u,y)=>Nt(()=>!0,r,u,y),typeAllowingConflictsPred:r=>Object.assign(Object.assign({},n.type),{transform:(u,y,A)=>Nt(r,u,y,A)})};const a=r=>r?r.getComponent():null;function E(r){return r&&typeof r=="object"&&!Array.isArray(r)}const G=r=>Array.isArray(r)?r.slice():r!==null&&typeof r=="object"?Object.assign({},r):r,O=r=>r&&(r.p!=null||r.r!==void 0),o=r=>r&&(r.d!=null||r.i!==void 0);function c(r,u){return l(r!=null),typeof u=="number"?(l(Array.isArray(r),"Invalid key - child is not an array"),(r=r.slice()).splice(u,1)):(l(E(r),"Invalid key - child is not an object"),delete(r=Object.assign({},r))[u]),r}function h(r,u,y){return typeof u=="number"?(l(r!=null,"Container is missing for key"),l(Array.isArray(r),"Cannot use numerical key for object container"),l(r.length>=u,"Cannot insert into out of bounds index"),r.splice(u,0,y)):(l(E(r),"Cannot insert into missing item"),l(r[u]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),r[u]=y),y}n.removeOp=(r,u=!0)=>s.writeCursor().writeAtPath(r,"r",u).get(),n.moveOp=(r,u)=>s.writeCursor().writeMove(r,u).get(),n.insertOp=(r,u)=>s.writeCursor().writeAtPath(r,"i",u).get(),n.replaceOp=(r,u,y)=>s.writeCursor().at(r,A=>{A.write("r",u),A.write("i",y)}).get(),n.editOp=(r,u,y,A=!1)=>s.writeCursor().at(r,b=>_(b,u,y,A)).get();const T=(r,u)=>r!=null&&(typeof u=="number"?Array.isArray(r):typeof r=="object"),J=(r,u)=>T(r,u)?r[u]:void 0,_e={};function Q(r){let u=r.type?r.type:r;u.name&&(_e[u.name]=u),u.uri&&(_e[u.uri]=u)}const Ce=r=>{const u=_e[r];if(u)return u;throw Error("Missing type: "+r)};Q($t());const xe=(r,u)=>r+u;Q({name:"number",apply:xe,compose:xe,invert:r=>-r,transform:r=>r});const be=r=>r==null?null:r.et?Ce(r.et):r.es?_e["text-unicode"]:r.ena!=null?_e.number:null,f=r=>r.es?r.es:r.ena!=null?r.ena:r.e,_=(r,u,y,A=!1)=>{const[b,C]=typeof u=="string"?[Ce(u),u]:[u,u.name];!A&&b.isNoop&&b.isNoop(y)||(C==="number"?r.write("ena",y):C==="text-unicode"?r.write("es",y):(r.write("et",C),r.write("e",y)))};function I(r){l(typeof r=="number"),l(r>=0),l(r===(0|r))}function H(r){typeof r=="number"?I(r):l(typeof r=="string")}function z(r){if(r===null)return;const u=new Set,y=new Set,A=C=>{let $=!0,k=!1;for(let g in C){const v=C[g];if($=!1,l(g==="p"||g==="r"||g==="d"||g==="i"||g==="e"||g==="es"||g==="ena"||g==="et","Invalid component item '"+g+"'"),g==="p")I(v),l(!u.has(v)),u.add(v),l(C.r===void 0);else if(g==="d")I(v),l(!y.has(v)),y.add(v),l(C.i===void 0);else if(g==="e"||g==="es"||g==="ena"){l(!k),k=!0;const m=be(C);l(m,"Missing type in edit"),m.checkValidOp&&m.checkValidOp(f(C))}}l(!$)},b=(C,$,k)=>{if(!Array.isArray(C))throw Error("Op must be null or a list");if(C.length===0)throw Error("Empty descent");$||H(C[0]);let g=1,v=0,m=0;for(let w=0;w<C.length;w++){const j=C[w];if(l(j!=null),Array.isArray(j)){const W=b(j,!1);if(v){const p=typeof m,U=typeof W;p===U?l(m<W,"descent keys are not in order"):l(p==="number"&&U==="string")}m=W,v++,g=3}else typeof j=="object"?(l(g===1,`Prev not scalar - instead ${g}`),A(j),g=2):(l(g!==3),H(j),l(s.isValidPathItem(j),"Invalid path key"),g=1)}return l(v!==1,"Operation makes multiple descents. Remove some []"),l(g===2||g===3),C[0]};b(r,!0),l(u.size===y.size,"Mismatched picks and drops in op");for(let C=0;C<u.size;C++)l(u.has(C)),l(y.has(C))}function K(r){let u=0,y=[];const A=s.writeCursor();return A.mergeTree(r,(b,C)=>{const $=be(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 v=g==="p"||g==="d"?(k=b[g],y[k]==null&&(y[k]=u++),y[k]):b[g];C.write(g,v)}var k}),A.get()}function De(r,u){if(z(u),u===null)return r;const y=[];return function A(b,C){let $=b,k=0,g={root:b},v=0,m=g,w="root";function j(){for(;v<k;v++){let W=C[v];typeof W!="object"&&(l(T(m,w)),m=m[w]=G(m[w]),w=W)}}for(;k<C.length;k++){const W=C[k];if(Array.isArray(W)){const p=A($,W);p!==$&&p!==void 0&&(j(),$=m[w]=p)}else if(typeof W=="object"){W.d!=null?(j(),$=h(m,w,y[W.d])):W.i!==void 0&&(j(),$=h(m,w,W.i));const p=be(W);if(p)j(),$=m[w]=p.apply($,f(W));else if(W.e!==void 0)throw Error("Subtype "+W.et+" undefined")}else $=J($,W)}return g.root}(r=function A(b,C){const $=[];let k=0;for(;k<C.length;k++){const w=C[k];if(Array.isArray(w))break;typeof w!="object"&&($.push(b),b=J(b,w))}for(let w=C.length-1;w>=k;w--)b=A(b,C[w]);for(--k;k>=0;k--){const w=C[k];if(typeof w!="object"){const j=$.pop();b=b===J(j,w)?j:b===void 0?c(j,w):(v=w,m=b,(g=G(g=j))[v]=m,g)}else O(w)&&(l(b!==void 0,"Cannot pick up or remove undefined"),w.p!=null&&(y[w.p]=b),b=void 0)}var g,v,m;return b}(r,u),u)}function fe(r,u){r=r.slice(),z(u);const y=s.readCursor(u);let A,b,C=!1;const $=[];for(let g=0;;g++){const v=r[g],m=y.getComponent();if(m&&(m.r!==void 0?C=!0:m.p!=null&&(C=!1,A=m.p,b=g)),g>=r.length)break;let w=0;const j=s.advancer(y,void 0,(p,U)=>{O(U)&&w++});$.unshift(j);const W=j(v);if(typeof v=="number"&&(r[g]-=w),!W)break}if($.forEach(g=>g.end()),C)return null;const k=()=>{let g=0;if(A!=null){const v=y.getPath();g=v.length,r=v.concat(r.slice(b))}for(;g<r.length;g++){const v=r[g],m=a(y),w=be(m);if(w){const p=f(m);w.transformPosition&&(r[g]=w.transformPosition(r[g],p));break}let j=0;const W=s.advancer(y,(p,U)=>o(U)?~(p-j):p-j,(p,U)=>{o(U)&&j++})(v);if(typeof v=="number"&&(r[g]+=j),!W)break}};return A!=null?y.eachDrop(null,g=>{g===A&&k()}):k(),r}function ie(r,u){if(z(r),z(u),r==null)return u;if(u==null)return r;let y=0;const A=s.readCursor(r),b=s.readCursor(u),C=s.writeCursor(),$=[],k=[],g=[],v=[],m=[],w=[],j=new Set;A.traverse(null,p=>{p.p!=null&&(g[p.p]=A.clone())}),b.traverse(null,p=>{p.d!=null&&(v[p.d]=b.clone())});const W=s.writeCursor();return function p(U,se,ne,x,le,Ge,Ie,ve){l(se||ne);const ae=a(se),Pe=a(ne),Ue=!!Pe&&Pe.r!==void 0,Fe=!!ae&&ae.i!==void 0,Se=ae?ae.d:null,Ae=Pe?Pe.p:null,We=(Ge||Ue)&&Ae==null;if(Ae!=null)x=v[Ae],Ie=k[Ae]=new s.WriteCursor;else if(Pe&&Pe.r!==void 0)x=null;else{const M=a(x);M&&M.d!=null&&(x=null)}const ee=a(x);if(Se!=null)if(U=g[Se],ve=$[Se]=new s.WriteCursor,We)Ge&&!Ue&&ve.write("r",!0);else{const M=m[Se]=y++;Ie.write("d",M)}else if(ae&&ae.i!==void 0)U=null;else{const M=a(U);M&&M.p!=null&&(U=null)}let P;Fe?(l(le===void 0),P=ae.i):P=le;const L=(Ae==null?!Fe||Ge||Ue:P===void 0)?null:Ie.getComponent();if(Ae!=null){if(!(le!==void 0||Fe)){const M=Se!=null?m[Se]:y++;w[Ae]=M,ve.write("p",M)}}else Ue&&(Fe||le!==void 0||(Pe.r,ve.write("r",Pe.r)));const S=We?null:be(ae),D=be(ee);if((S||D)&&(S&&S.name,D&&D.name),S&&D){l(S===D);const M=f(ae),B=f(ee),pe=S.compose(M,B);_(Ie,S,pe),j.add(ee)}else S?_(Ie,S,f(ae)):D&&(_(Ie,D,f(ee)),j.add(ee));const N=typeof P=="object"&&P!=null;let X=!1,Z=0,te=0,ge=0,he=0,ce=0;const me=s.advancer(x,(M,B)=>o(B)?he-M-1:M-he,(M,B)=>{o(B)&&he++}),q=s.advancer(U,(M,B)=>O(B)?Z-M-1:M-Z,(M,B)=>{O(B)&&Z++});if(s.eachChildOf(se,ne,(M,B,pe)=>{let we,Le,Ve=M,Ne=M,et=M;if(typeof M=="number"){let ye=M+ge;Le=me(ye),Ne=ye+he;let de=M+te;we=q(de),o(a(Le))&&(we=null),Ve=de+Z,et=M+ce,l(Ve>=0,"p1PickKey is negative"),l(Ne>=0,"p2DropKey is negative");const Te=o(a(B)),Be=O(a(pe));(Te||Be&&!We)&&ce--,Te&&te--,Be&&ge--}else we=q(M),Le=me(M);ve.descend(Ve),Ie.descend(Ne);const Ye=N&&!o(a(B))?P[et]:void 0,je=p(we,B,pe,Le,Ye,We,Ie,ve);var $e,R,oe;N&&!We?Ye!==je&&(X||(P=Array.isArray(P)?P.slice():Object.assign({},P),X=!0),$e=P,oe=je,typeof(R=et)=="number"?(l(Array.isArray($e)),l(R<$e.length)):(l(!Array.isArray($e)),l($e[R]!==void 0)),oe===void 0?typeof R=="number"?$e.splice(R,1):delete $e[R]:$e[R]=oe):l(je===void 0),Ie.ascend(),ve.ascend()}),q.end(),me.end(),L!=null)L.i=P;else if(!Ge&&!Ue&&Ae==null)return P}(A,A.clone(),b,b.clone(),void 0,!1,C,W),C.reset(),C.mergeTree(W.get()),C.reset(),C.get(),$.map(p=>p.get()),k.map(p=>p.get()),A.traverse(C,(p,U)=>{const se=p.p;if(se!=null){const ne=m[se];ne!=null&&U.write("p",ne);const x=$[se];x&&x.get(),x&&U.mergeTree(x.get())}else p.r!==void 0&&U.write("r",p.r)}),C.reset(),C.get(),b.traverse(C,(p,U)=>{const se=p.d;if(se!=null){const x=w[se];x!=null&&U.write("d",x);const le=k[se];le&&U.mergeTree(le.get())}else p.i!==void 0&&U.write("i",p.i);const ne=be(p);ne&&!j.has(p)&&_(U,ne,f(p))}),C.get()}function ue(r){if(r==null)return null;const u=new s.ReadCursor(r),y=new s.WriteCursor;let A;const b=[],C=[];return function $(k,g,v){const m=k.getComponent();let w,j=!1;if(m){m.p!=null&&(g.write("d",m.p),b[m.p]=k.clone()),m.r!==void 0&&g.write("i",m.r),m.d!=null&&(g.write("p",m.d),v=void 0),m.i!==void 0&&(v=w=m.i);const p=be(m);p&&(v===void 0?(A||(A=new Set),A.add(m)):(f(m),v=p.apply(v,f(m)),j=!0))}let W=0;for(const p of k){g.descend(p);const U=typeof p=="number"?p-W:p,se=J(v,U);o(k.getComponent())&&W++;const ne=$(k,g,se);if(v!==void 0&&ne!==void 0){if(j||(j=!0,v=G(v)),!T(v,U))throw Error("Cannot modify child - invalid operation");v[U]=ne}g.ascend()}if(w===void 0)return j?v:void 0;g.write("r",v)}(u,y,void 0),A&&(y.reset(),function $(k,g,v){const m=g.getComponent();if(m){const p=m.d;if(p!=null&&(k=b[p],v=C[p]=s.writeCursor()),A.has(m)){const U=be(m);if(!U.invert)throw Error(`Cannot invert subtype ${U.name}`);_(v,U,U.invert(f(m)))}}let w=0,j=0;const W=s.advancer(k,(p,U)=>O(U)?w-p-1:p-w,(p,U)=>{O(U)&&w++});for(const p of g)if(typeof p=="number"){const U=p-j,se=W(U),ne=U+w;v.descend(ne),$(se,g,v),o(g.getComponent())&&j++,v.ascend()}else v.descend(p),$(W(p),g,v),v.ascend();W.end()}(u.clone(),u,y),C.length&&(y.reset(),u.traverse(y,($,k)=>{const g=$.p;if(g!=null){const v=C[g];v&&v.get(),v&&k.mergeTree(v.get())}}))),y.get()}const Oe=(r,u)=>r.some(y=>typeof y=="object"&&(Array.isArray(y)?Oe(y,u):u(y)));function Me(r,u){if(r==null||!Oe(r,g=>{var v;return g.r!==void 0||((v=be(g))===null||v===void 0?void 0:v.makeInvertible)!=null}))return r;const y=new s.ReadCursor(r),A=new s.WriteCursor;let b=!1;const C=[],$=[],k=(g,v,m)=>{const w=g.getComponent();let j=!1;if(w){w.d!=null&&v.write("d",w.d),w.i!==void 0&&v.write("i",w.i);const p=w.p;if(p!=null&&(C[p]=g.clone(),l(m!==void 0,"Operation picks up at an invalid key"),$[p]=m,v.write("p",w.p)),w.r!==void 0&&m===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const U=be(w);U&&(U.makeInvertible?b=!0:_(v,U,f(w),!0))}let W=0;for(const p of g){v.descend(p);const U=typeof p=="number"?p-W:p,se=J(m,U),ne=k(g,v,se);se!==ne&&(j||(j=!0,m=G(m)),ne===void 0?(m=c(m,U),typeof p=="number"&&W++):m[U]=ne),v.ascend()}return w&&(w.r!==void 0?(v.write("r",i.default(m)),m=void 0):w.p!=null&&(m=void 0)),m};return k(y,A,u),A.get(),b&&(A.reset(),function g(v,m,w,j,W){const p=m.getComponent();if(p){p.i!==void 0?(j=p.i,W=!0):p.d!=null&&(j=$[p.d],v=C[p.d],W=!1,p.d);let x=be(p);if(x&&x.makeInvertible){const le=f(p);_(w,x,x.makeInvertible(le,j),!0)}}let U=0,se=0;const ne=s.advancer(v,(x,le)=>O(le)?U-x-1:x-U,(x,le)=>{O(le)&&U++});for(const x of m)if(typeof x=="number"){const le=x-se,Ge=ne(le),Ie=le+U,ve=J(j,W?le:Ie);w.descend(x),g(Ge,m,w,ve,W),o(m.getComponent())&&se++,w.ascend()}else{const le=J(j,x);w.descend(x),g(ne(x),m,w,le,W),w.ascend()}ne.end()}(y.clone(),y,A,u,!1)),A.get()}function Vt(r,u){return ue(Me(r,u))}const pt=r=>{if(r==null)return null;const u=r.slice();for(let y=0;y<r.length;y++){const A=u[y];Array.isArray(A)&&(u[y]=pt(A))}return u};function _t(r,u,y){l(y==="left"||y==="right","Direction must be left or right");const A=y==="left"?0:1;if(u==null)return{ok:!0,result:r};z(r),z(u);let b=null;const C=[],$=[],k=[],g=[],v=[],m=[],w=[],j=[],W=[],p=[],U=[],se=[],ne=[],x=[],le=[];let Ge=0;const Ie=s.readCursor(r),ve=s.readCursor(u),ae=s.writeCursor();if(function ee(P,L=null,S){const D=a(L);D&&(D.r!==void 0?S=L.clone():D.p!=null&&(S=null,m[D.p]=P.clone()));const N=P.getComponent();let X;N&&(X=N.p)!=null&&(v[X]=L?L.clone():null,k[X]=P.clone(),S&&(p[X]=!0,W[X]=S),D&&D.p!=null&&(x[X]=D.p));const Z=s.advancer(L);for(const te of P)ee(P,Z(te),S);Z.end()}(ve,Ie,null),function ee(P,L,S,D,N){const X=S.getComponent();let Z,te=!1;X&&((Z=X.d)!=null?(g[Z]=S.clone(),D!=null&&(le[D]==null&&(le[D]=[]),le[D].push(Z)),P=v[Z]||null,L=k[Z]||null,p[Z]?(N&&(U[Z]=!0),N=W[Z]||null):!N||A!==1&&x[Z]!=null||b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.moveOp(L.getPath(),S.getPath())}),te=!0):X.i!==void 0&&(P=L=null,te=!0,N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.insertOp(S.getPath(),X.i)})));const ge=a(P);ge&&(ge.r!==void 0?N=P.clone():ge.p!=null&&(ge.p,D=ge.p,N=null));const he=be(X);he&&N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.editOp(S.getPath(),he,f(X),!0)});let ce=0,me=0;const q=s.advancer(L,(B,pe)=>O(pe)?ce-B-1:B-ce,(B,pe)=>{O(pe)&&ce++}),M=s.advancer(P);for(const B of S)if(typeof B=="number"){const pe=B-me,we=q(pe);me+=+ee(M(pe+ce),we,S,D,N)}else{const pe=q(B);ee(M(B),pe,S,D,N)}return q.end(),M.end(),te}(Ie,ve,ve.clone(),null,null),g.map(ee=>ee&&ee.get()),b)return{ok:!1,conflict:b};U.map(ee=>!!ee);const Pe=[];let Ue=null;(function ee(P,L,S,D,N){let X=!1;const Z=a(L);if(O(Z)){const q=Z.p;q!=null?(S=g[q],D=se[q]=s.writeCursor(),X=!0,N=null):(S=null,N=L.clone())}else o(a(S))&&(S=null);const te=P.getComponent();if(te){const q=te.p;q!=null?(N&&(j[q]=N),Pe[q]=N||A===1&&X?null:D.getComponent(),C[q]=P.clone(),S&&(w[q]=S.clone())):te.r!==void 0&&(N||D.write("r",!0),(N||X)&&(Ue==null&&(Ue=new Set),Ue.add(te)))}let ge=0,he=0;const ce=s.advancer(L,void 0,(q,M)=>{O(M)&&ge++}),me=s.advancer(S,(q,M)=>o(M)?~(q-he):q-he,(q,M)=>{o(M)&&he++});if(P)for(const q of P)if(typeof q=="string"){const M=ce(q),B=me(q);D.descend(q),ee(P,M,B,D,N),D.ascend()}else{const M=ce(q),B=q-ge,pe=O(a(M))?null:me(B),we=B+he;l(we>=0),D.descend(we),ee(P,M,pe,D,N),D.ascend()}ce.end(),me.end()})(Ie,ve,ve.clone(),ae,null),ae.reset();let Fe=[];if(function ee(P,L,S,D,N,X){l(L);const Z=L.getComponent();let te=a(D),ge=!1;const he=(R,oe,ye)=>R?n.moveOp(R.getPath(),oe.getPath()):n.insertOp(oe.getPath(),ye.i);if(o(Z)){const R=Z.d;R!=null&&($[R]=L.clone());const oe=R!=null?Pe[R]:null;let ye=!1;if(Z.i!==void 0||R!=null&&oe){let de;te&&(te.i!==void 0||(de=te.d)!=null&&!p[de])&&(ye=de!=null?R!=null&&R===x[de]:t.default(te.i,Z.i),ye||de!=null&&A!==1&&x[de]!=null||b==null&&(b={type:d.ConflictType.DROP_COLLISION,op1:he(R!=null?C[R]:null,L,Z),op2:he(de!=null?k[de]:null,D,te)})),ye||(X?b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:he(R!=null?C[R]:null,L,Z),op2:n.removeOp(X.getPath())}):(R!=null?(Fe[Ge]=R,N.write("d",oe.p=Ge++)):N.write("i",i.default(Z.i)),ge=!0))}else if(R!=null&&!oe){const de=j[R];de&&(X=de.clone())}R!=null?(P=C[R],S=m[R],D=w[R]):Z.i!==void 0&&(P=S=null,ye||(D=null))}else O(a(P))&&(P=S=D=null);const ce=a(P),me=a(S);if(O(me)){const R=me.p;me.r!==void 0&&(!ce||ce.r===void 0)||p[R]?(D=null,X=S.clone()):R!=null&&(D=g[R],A!==1&&x[R]!=null||((N=ne[R])||(N=ne[R]=s.writeCursor()),N.reset(),X=null))}else!o(Z)&&o(te)&&(D=null);te=D!=null?D.getComponent():null;const q=be(Z);if(q){const R=f(Z);if(X)b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.editOp(L.getPath(),q,R,!0),op2:n.removeOp(X.getPath())});else{const oe=be(te);let ye;if(oe){if(q!==oe)throw Error("Transforming incompatible types");const de=f(te);ye=q.transform(R,de,y)}else ye=i.default(R);_(N,q,ye)}}let M=0,B=0,pe=0,we=0,Le=0,Ve=0,Ne=P!=null&&P.descendFirst(),et=Ne;const Ye=s.advancer(S,void 0,(R,oe)=>{O(oe)&&pe++});let je=D!=null&&D.descendFirst(),$e=je;for(const R of L)if(typeof R=="number"){let oe;const ye=o(L.getComponent()),de=R-B;{let He;for(;Ne&&typeof(He=P.getKey())=="number";){He+=M;const Re=P.getComponent(),Je=O(Re);if(He>de||He===de&&(!Je||A===0&&ye))break;if(Je){M--;const qe=Re.p;x.includes(qe),Re.d,a(ne[Re.d]),O(a(ne[Re.d])),(Re.r===void 0||Ue&&Ue.has(Re))&&(qe==null||!Pe[qe]||A!==1&&x.includes(qe))||Le--}Ne=P.nextSibling()}oe=Ne&&He===de?P:null}const Te=de-M;let Be=Ye(Te);const Ot=Te-pe;let rt=null;{let He,Re;for(;je&&typeof(He=D.getKey())=="number";){Re=He-we;const Je=D.getComponent(),qe=o(Je);if(Re>Ot)break;if(Re===Ot){if(!qe){rt=D;break}{if(A===0&&ye){rt=D;break}const ze=Be&&O(Be.getComponent());if(A===0&&ze)break}}if(qe){const ze=Je.d;x[ze],Je.i===void 0&&(p[ze]||x[ze]!=null&&A!==1)?(p[ze]||x[ze]!=null&&A===0)&&(we++,Ve--):we++}je=D.nextSibling()}}const Tt=Ot+we+Le+Ve;l(Tt>=0,"trying to descend to a negative index"),N.descend(Tt),ye&&(oe=Be=rt=null,B++),ee(oe,L,Be,rt,N,X)&&Ve++,N.ascend()}else{let oe;for(;Ne&&(oe=P.getKey(),typeof oe!="string"||!(oe>R||oe===R));)Ne=P.nextSibling();const ye=Ne&&oe===R?P:null,de=Ye(R);let Te;for(;je&&(Te=D.getKey(),typeof Te!="string"||!(Te>R||Te===R));)je=D.nextSibling();const Be=je&&Te===R?D:null;N.descend(R),ee(ye,L,de,Be,N,X),N.ascend()}return Ye.end(),et&&P.ascend(),$e&&D.ascend(),ge}(Ie,Ie.clone(),ve,ve.clone(),ae,null),b)return{ok:!1,conflict:b};ae.reset();const Se=(ee,P,L)=>ee.traverse(P,(S,D)=>{S.d!=null&&L(S.d,ee,D)});(p.length||se.length)&&(Se(ve,ae,(ee,P,L)=>{p[ee]&&!U[ee]&&L.write("r",!0),se[ee]&&L.mergeTree(se[ee].get())}),ae.reset());const Ae=[],We=[];if((ne.length||p.length)&&!b){const ee=s.readCursor(pt(ae.get()));if(Se(ee,null,(P,L)=>{Ae[P]=L.clone()}),ne.forEach(P=>{P&&Se(s.readCursor(P.get()),null,(L,S)=>{Ae[L]=S.clone()})}),function P(L,S,D,N,X,Z){const te=a(S);if(te&&O(te))if(te.p!=null){const M=te.p;Ae[M].getPath(),D=Ae[M],N=We[M]=s.writeCursor()}else te.r!==void 0&&(D=null);else o(a(D))&&(D=null);const ge=L.getComponent();if(ge){let M;if((M=ge.d)!=null){const B=ne[M];B&&(B.get(),N.mergeTree(B.get()),D=s.readCursor(B.get()))}}let he=0,ce=0;const me=s.advancer(S,void 0,(M,B)=>{O(B)&&he--}),q=s.advancer(D,(M,B)=>o(B)?-(M-ce)-1:M-ce,(M,B)=>{o(B)&&ce++});for(const M of L)if(typeof M=="number"){const B=me(M),pe=M+he,we=q(pe),Le=pe+ce;N.descend(Le),P(L,B,we,N),N.ascend()}else N.descend(M),P(L,me(M),q(M),N),N.ascend();me.end(),q.end()}(ve,ee,ee.clone(),ae),ae.reset(),b)return{ok:!1,conflict:b};if(ae.get(),We.length){const P=We.map(S=>S?S.get():null),L=s.readCursor(pt(ae.get()));if(Se(L,ae,(S,D,N)=>{const X=P[S];X&&(N.mergeTree(X),P[S]=null)}),P.find(S=>S)){const S=s.writeCursor(),D=s.writeCursor();let N=0,X=0;P.forEach(Z=>{Z!=null&&Se(s.readCursor(Z),null,te=>{const ge=Fe[te];S.writeMove(C[ge].getPath(),$[ge].getPath(),N++);const he=le[ge];he&&he.forEach(ce=>{p[ce]||A!==1&&x[ce]!=null||D.writeMove(k[ce].getPath(),g[ce].getPath(),X++)})})}),b={type:d.ConflictType.BLACKHOLE,op1:S.get(),op2:D.get()}}}}return b?{ok:!1,conflict:b}:{ok:!0,result:ae.get()}}const Ut=r=>{const u=new Error("Transform detected write conflict");throw u.conflict=r,u.type=u.name="writeConflict",u};function qt(r,u,y){const A=_t(r,u,y);if(A.ok)return A.result;Ut(A.conflict)}const Ze=r=>{const u=s.writeCursor();return s.readCursor(r).traverse(u,(y,A)=>{(o(y)||be(y))&&A.write("r",!0)}),u.get()},zt=(r,u)=>{const{type:y,op1:A,op2:b}=r;switch(y){case d.ConflictType.DROP_COLLISION:return u==="left"?[null,Ze(b)]:[Ze(A),null];case d.ConflictType.RM_UNEXPECTED_CONTENT:let C=!1;return s.readCursor(A).traverse(null,$=>{$.r!==void 0&&(C=!0)}),C?[null,Ze(b)]:[Ze(A),null];case d.ConflictType.BLACKHOLE:return[Ze(A),Ze(b)];default:throw Error("Unrecognised conflict: "+y)}};function Nt(r,u,y,A){let b=null;for(;;){const C=_t(u,y,A);if(C.ok)return ie(b,C.result);{const{conflict:$}=C;r($)||Ut($);const[k,g]=zt($,A);u=ie(K(u),k),y=ie(K(y),g),b=ie(b,g)}}}})(yt),function(n){var e=Ee&&Ee.__createBinding||(Object.create?function(d,l,a,E){E===void 0&&(E=a),Object.defineProperty(d,E,{enumerable:!0,get:function(){return l[a]}})}:function(d,l,a,E){E===void 0&&(E=a),d[E]=l[a]}),t=Ee&&Ee.__exportStar||function(d,l){for(var a in d)a!=="default"&&!l.hasOwnProperty(a)&&e(l,d,a)};Object.defineProperty(n,"__esModule",{value:!0}),t(yt,n);var i=at;Object.defineProperty(n,"ReadCursor",{enumerable:!0,get:function(){return i.ReadCursor}}),Object.defineProperty(n,"WriteCursor",{enumerable:!0,get:function(){return i.WriteCursor}});var s=ct;Object.defineProperty(n,"ConflictType",{enumerable:!0,get:function(){return s.ConflictType}})}(F);class Ct{constructor(){V(this,"drawingManagerData",{});V(this,"_oldDrawingManagerData",{});V(this,"_focusDrawings",[]);V(this,"_remove$",new re.Subject);V(this,"remove$",this._remove$.asObservable());V(this,"_add$",new re.Subject);V(this,"add$",this._add$.asObservable());V(this,"_update$",new re.Subject);V(this,"update$",this._update$.asObservable());V(this,"_order$",new re.Subject);V(this,"order$",this._order$.asObservable());V(this,"_group$",new re.Subject);V(this,"group$",this._group$.asObservable());V(this,"_ungroup$",new re.Subject);V(this,"ungroup$",this._ungroup$.asObservable());V(this,"_refreshTransform$",new re.Subject);V(this,"refreshTransform$",this._refreshTransform$.asObservable());V(this,"_visible$",new re.Subject);V(this,"visible$",this._visible$.asObservable());V(this,"_focus$",new re.Subject);V(this,"focus$",this._focus$.asObservable());V(this,"_featurePluginUpdate$",new re.Subject);V(this,"featurePluginUpdate$",this._featurePluginUpdate$.asObservable());V(this,"_featurePluginAdd$",new re.Subject);V(this,"featurePluginAdd$",this._featurePluginAdd$.asObservable());V(this,"_featurePluginRemove$",new re.Subject);V(this,"featurePluginRemove$",this._featurePluginRemove$.asObservable());V(this,"_featurePluginOrderUpdate$",new re.Subject);V(this,"featurePluginOrderUpdate$",this._featurePluginOrderUpdate$.asObservable());V(this,"_featurePluginGroupUpdate$",new re.Subject);V(this,"featurePluginGroupUpdate$",this._featurePluginGroupUpdate$.asObservable());V(this,"_featurePluginUngroupUpdate$",new re.Subject);V(this,"featurePluginUngroupUpdate$",this._featurePluginUngroupUpdate$.asObservable());V(this,"_visible",!0);V(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 i=this._getCurrentBySearch(t);i!=null&&(i.transform=t.transform,i.transforms=t.transforms,i.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 i=[];Object.keys(t).forEach(s=>{const d=t[s];(d==null?void 0:d.data)!=null&&Object.keys(d.data).forEach(l=>{i.push({unitId:e,subUnitId:s,drawingId:l})})}),i.length>0&&this.removeNotification(i)}registerDrawingData(e,t){this.drawingManagerData[e]=t}initializeNotification(e){const t=[],i=this.drawingManagerData[e];i!=null&&(Object.keys(i).forEach(s=>{this._establishDrawingMap(e,s);const d=i[s];Object.keys(d.data).forEach(l=>{const a=d.data[l];a.unitId=e,a.subUnitId=s,t.push(a)})}),t.length>0&&this.addNotification(t))}getDrawingData(e,t){return this._getDrawingData(e,t)}setDrawingData(e,t,i){this.drawingManagerData[e][t].data=i}getBatchAddOp(e){const t=[],i=[],s=[];e.forEach(G=>{const{op:O,invertOp:o}=this._addByParam(G);t.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),i.push(O),s.push(o)});const d=i.reduce(F.type.compose,null),l=s.reduce(F.type.compose,null),{unitId:a,subUnitId:E}=e[0];return{undo:l,redo:d,unitId:a,subUnitId:E,objects:t}}getBatchRemoveOp(e){const t=[],i=[];e.forEach(E=>{const{op:G,invertOp:O}=this._removeByParam(E);t.push(G),i.push(O)});const s=t.reduce(F.type.compose,null),d=i.reduce(F.type.compose,null),{unitId:l,subUnitId:a}=e[0];return{undo:d,redo:s,unitId:l,subUnitId:a,objects:e}}getBatchUpdateOp(e){const t=[],i=[],s=[];e.forEach(G=>{const{op:O,invertOp:o}=this._updateByParam(G);t.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),i.push(O),s.push(o)});const d=i.reduce(F.type.compose,null),l=s.reduce(F.type.compose,null),{unitId:a,subUnitId:E}=e[0];return{undo:l,redo:d,unitId:a,subUnitId:E,objects:t}}removeNotification(e){this._remove$.next(e)}addNotification(e){this._add$.next(e)}updateNotification(e){this._update$.next(e)}orderNotification(e){this._order$.next(e)}groupUpdateNotification(e){this._group$.next(e)}ungroupUpdateNotification(e){this._ungroup$.next(e)}refreshTransformNotification(e){this._refreshTransform$.next(e)}getGroupDrawingOp(e){const t=[],{unitId:i,subUnitId:s}=e[0].parent;e.forEach(a=>{t.push(this._getGroupDrawingOp(a))});const d=t.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:i,subUnitId:s,objects:e}}getUngroupDrawingOp(e){const t=[],{unitId:i,subUnitId:s}=e[0].parent;e.forEach(a=>{t.push(this._getUngroupDrawingOp(a))});const d=t.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:i,subUnitId:s,objects:e}}getDrawingsByGroup(e){const{unitId:t,subUnitId:i,drawingId:s}=e;if(this.getDrawingByParam({unitId:t,subUnitId:i,drawingId:s})==null)return[];const l=this._getDrawingData(t,i),a=[];return Object.keys(l).forEach(E=>{const G=l[E];G.groupId===s&&a.push(G)}),a}_getGroupDrawingOp(e){const{parent:t,children:i}=e,{unitId:s,subUnitId:d,drawingId:l}=t,a=[];a.push(F.insertOp([s,d,"data",l],t));let E=Number.NEGATIVE_INFINITY;return i.forEach(G=>{const{unitId:O,subUnitId:o,drawingId:c}=G,h=this._hasDrawingOrder({unitId:O,subUnitId:o,drawingId:c});E=Math.max(E,h),a.push(...this._getUpdateParamCompareOp(G,this.getDrawingByParam({unitId:O,subUnitId:o,drawingId:c})))}),E===Number.NEGATIVE_INFINITY&&(E=this._getDrawingOrder(s,d).length),a.push(F.insertOp([s,d,"order",E],l)),a.reduce(F.type.compose,null)}_getUngroupDrawingOp(e){const{parent:t,children:i}=e,{unitId:s,subUnitId:d,drawingId:l}=t,a=[];return i.forEach(E=>{const{unitId:G,subUnitId:O,drawingId:o}=E;a.push(...this._getUpdateParamCompareOp(E,this.getDrawingByParam({unitId:G,subUnitId:O,drawingId:o})))}),a.push(F.removeOp([s,d,"data",l],!0)),a.push(F.removeOp([s,d,"order",this._getDrawingOrder(s,d).indexOf(l)],!0)),a.reduce(F.type.compose,null)}applyJson1(e,t,i){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=F.type.apply(this.drawingManagerData,i)}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,i,s]=e.split("#-#");return this._getCurrentBySearch({unitId:t,subUnitId:i,drawingId:s})}focusDrawing(e){if(e==null){this._focusDrawings=[],this._focus$.next([]);return}const t=[];e.forEach(i=>{var E;const{unitId:s,subUnitId:d,drawingId:l}=i,a=(E=this._getDrawingData(s,d))==null?void 0:E[l];a!=null&&t.push(a)}),t.length>0&&(this._focusDrawings=t,this._focus$.next(t))}getFocusDrawings(){const e=[];return this._focusDrawings.forEach(t=>{var a;const{unitId:i,subUnitId:s,drawingId:d}=t,l=(a=this._getDrawingData(i,s))==null?void 0:a[d];l!=null&&e.push(l)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,i){this.drawingManagerData[e][t].order=i}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=[],l=this.getDrawingOrder(t,i),a=[...s];s.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:i,drawingId:O});if(o===-1||o===l.length-1)return;const c=F.moveOp([t,i,"order",o],[t,i,"order",o+1]);d.push(c),a.includes(l[o+1])||a.push(l[o+1])});const E=d.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:i,objects:{...e,drawingIds:a}}}getBackwardDrawingOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=[],l=this.getDrawingOrder(t,i),a=[...s];s.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:i,drawingId:O});if(o===-1||o===0)return;const c=F.moveOp([t,i,"order",o],[t,i,"order",o-1]);d.push(c),a.includes(l[o-1])||a.push(l[o-1])});const E=d.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:i,objects:{...e,drawingIds:a}}}getFrontDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,i,s),l=[...s],a=this.getDrawingOrder(t,i),E=[];d.forEach(o=>{const{drawingId:c}=o,h=this._getDrawingCount(t,i)-1,T=F.moveOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(c)],[t,i,"order",h]);E.push(T),l.includes(a[h])||l.push(a[h])});const G=E.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:t,subUnitId:i,objects:{...e,drawingIds:l}}}getBackDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,i,s,!0),l=[...s],a=this.getDrawingOrder(t,i),E=[];d.forEach(o=>{const{drawingId:c}=o,h=F.moveOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(c)],[t,i,"order",0]);E.push(h),l.includes(a[0])||l.push(a[0])});const G=E.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:t,subUnitId:i,objects:{...e,drawingIds:l}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,t,i,s=!1){return i.map(d=>{const l=this._hasDrawingOrder({unitId:e,subUnitId:t,drawingId:d});return{drawingId:d,zIndex:l}}).sort(s===!1?ke.sortRules:ke.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;const{unitId:t,subUnitId:i,drawingId:s}=e;return this._establishDrawingMap(t,i),this._getDrawingOrder(t,i).indexOf(s)}_getCurrentBySearch(e){var d,l,a;if(e==null)return;const{unitId:t,subUnitId:i,drawingId:s}=e;return(a=(l=(d=this.drawingManagerData[t])==null?void 0:d[i])==null?void 0:l.data)==null?void 0:a[s]}_getOldBySearch(e){var d,l,a;if(e==null)return;const{unitId:t,subUnitId:i,drawingId:s}=e;return(a=(l=(d=this._oldDrawingManagerData[t])==null?void 0:d[i])==null?void 0:l.data)==null?void 0:a[s]}_establishDrawingMap(e,t,i){var s;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),i==null?null:(s=this.drawingManagerData[e][t].data)==null?void 0:s[i]}_addByParam(e){const{unitId:t,subUnitId:i,drawingId:s}=e;this._establishDrawingMap(t,i,s);const d=F.insertOp([t,i,"data",s],e),l=F.insertOp([t,i,"order",this._getDrawingOrder(t,i).length],s),a=[d,l].reduce(F.type.compose,null),E=F.type.invertWithDoc(a,this.drawingManagerData);return{op:a,invertOp:E}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};const{unitId:t,subUnitId:i,drawingId:s}=e;if(this._establishDrawingMap(t,i,s)==null)return{op:[],invertOp:[]};const l=F.removeOp([t,i,"data",s],!0),a=F.removeOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(s)],!0),E=[l,a].reduce(F.type.compose,null),G=F.type.invertWithDoc(E,this.drawingManagerData);return{op:E,invertOp:G}}_updateByParam(e){const{unitId:t,subUnitId:i,drawingId:s}=e,d=this._establishDrawingMap(t,i,s);if(d==null)return{op:[],invertOp:[]};const a=this._getUpdateParamCompareOp(e,d).reduce(F.type.compose,null),E=F.type.invertWithDoc(a,this.drawingManagerData);return{op:a,invertOp:E}}_getUpdateParamCompareOp(e,t){const{unitId:i,subUnitId:s,drawingId:d}=e,l=[];return Object.keys(e).forEach(a=>{const E=e[a],G=t[a];G!==E&&l.push(F.replaceOp([i,s,"data",d,a],G,E))}),l}_getDrawingData(e,t){var i,s;return((s=(i=this.drawingManagerData[e])==null?void 0:i[t])==null?void 0:s.data)||{}}_getDrawingOrder(e,t){var i,s;return((s=(i=this.drawingManagerData[e])==null?void 0:i[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 Et extends Ct{}function Gt({unitId:n,subUnitId:e,drawingId:t},i){return typeof i=="number"?`${n}#-#${e}#-#${t}#-#${i}`:`${n}#-#${e}#-#${t}`}const Wt=async n=>new Promise((e,t)=>{const i=new Image;i.src=n,i.onload=()=>{e({width:i.width,height:i.height,image:i})},i.onerror=s=>{t(s)}});var Qe=(n=>(n.URL="URL",n.UUID="UUID",n.BASE64="BASE64",n))(Qe||{}),Xe=(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))(Xe||{});const At=tt.createIdentifier("core.image-io.service");class Dt{constructor(){V(this,"_waitCount",0);V(this,"_change$",new re.Subject);V(this,"change$",this._change$);V(this,"_imageSourceCache",new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,t){if(t===Qe.BASE64){const i=new Image;return i.src=e,i}return this._imageSourceCache.get(e)}addImageSourceCache(e,t,i){t===Qe.BASE64||i==null||this._imageSourceCache.set(e,i)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((t,i)=>{if(!vt.includes(e.type)){i(new Error(Xe.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>5242880){i(new Error(Xe.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}const s=new FileReader;s.readAsDataURL(e),s.onload=d=>{var E;const l=(E=d.target)==null?void 0:E.result;if(l==null){i(new Error(Xe.ERROR_IMAGE)),this._decreaseWaiting();return}const a=ke.Tools.generateRandomId(6);t({imageId:a,imageSourceType:Qe.BASE64,source:l,base64Cache:l,status:Xe.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}}const Lt="__default_document_sub_component_id20231101__";var Mt=(n=>(n[n.forward=0]="forward",n[n.backward=1]="backward",n[n.front=2]="front",n[n.back=3]="back",n))(Mt||{}),Pt=(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))(Pt||{});const St=tt.createIdentifier("univer.drawing-manager.service");var Bt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,Kt=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ht(e,t):e,d=n.length-1,l;d>=0;d--)(l=n[d])&&(s=(i?l(e,t,s):l(s))||s);return i&&s&&Bt(e,t,s),s},xt=(n,e)=>(t,i)=>e(t,i,n);const Ft="DRAWING_PLUGIN";Y.UniverDrawingPlugin=(gt=class extends ke.Plugin{constructor(e,t){super(),this._config=e,this._injector=t}onStarting(e){this._initDependencies(e)}_initDependencies(e){var s;const t=[[At,{useClass:Dt}],[St,{useClass:Et}]];ke.mergeOverrideWithDependencies(t,(s=this._config)==null?void 0:s.override).forEach(d=>e.add(d))}},V(gt,"pluginName",Ft),gt),Y.UniverDrawingPlugin=Kt([xt(1,tt.Inject(tt.Injector))],Y.UniverDrawingPlugin),Y.ArrangeTypeEnum=Mt,Y.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=Lt,Y.DRAWING_IMAGE_ALLOW_IMAGE_LIST=vt,Y.DRAWING_IMAGE_ALLOW_SIZE=5242880,Y.DRAWING_IMAGE_COUNT_LIMIT=10,Y.DRAWING_IMAGE_HEIGHT_LIMIT=500,Y.DRAWING_IMAGE_WIDTH_LIMIT=500,Y.DrawingManagerService=Et,Y.DrawingTypeEnum=Pt,Y.IDrawingManagerService=St,Y.IImageIoService=At,Y.ImageIoService=Dt,Y.ImageSourceType=Qe,Y.ImageUploadStatusType=Xe,Y.UnitDrawingService=Ct,Y.getDrawingShapeKeyByDrawingSearch=Gt,Y.getImageSize=Wt,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(Y,re){typeof exports=="object"&&typeof module<"u"?re(exports,require("rxjs"),require("@univerjs/core")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core"],re):(Y=typeof globalThis<"u"?globalThis:Y||self,re(Y.UniverDrawing={},Y.rxjs,Y.UniverCore))})(this,function(Y,re,Ee){"use strict";var zt=Object.defineProperty;var Xt=(Y,re,Ee)=>re in Y?zt(Y,re,{enumerable:!0,configurable:!0,writable:!0,value:Ee}):Y[re]=Ee;var V=(Y,re,Ee)=>Xt(Y,typeof re!="symbol"?re+"":re,Ee);var ht;const Ot=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"];var Ae=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},F={},vt={},rt={};Object.defineProperty(rt,"__esModule",{value:!0});function Tt(n,e){if(Array.isArray(e))return!1;for(let t in n)if(!it(n[t],e[t]))return!1;for(let t in e)if(n[t]===void 0)return!1;return!0}function Rt(n,e){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!it(n[t],e[t]))return!1;return!0}function it(n,e){return n===e?!0:n===null||e===null||typeof n!="object"||typeof e!="object"?!1:Array.isArray(n)?Rt(n,e):Tt(n,e)}rt.default=it;var st={};Object.defineProperty(st,"__esModule",{value:!0});function ot(n){if(n===null)return null;if(Array.isArray(n))return n.map(ot);if(typeof n=="object"){const e={};for(let t in n)e[t]=ot(n[t]);return e}else return n}st.default=ot;var at={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.eachChildOf=n.advancer=n.readCursor=n.writeCursor=n.WriteCursor=n.ReadCursor=n.isValidPathItem=void 0;function e(O,o){if(!O)throw new Error(o)}const t=O=>O!=null&&typeof O=="object"&&!Array.isArray(O),i=(O,o)=>typeof O==typeof o?O>o:typeof O=="string"&&typeof o=="number";function s(O,o){for(let c in O){const h=c;o.write(h,O[h])}}n.isValidPathItem=O=>typeof O=="number"||typeof O=="string"&&O!=="__proto__";class d{constructor(o=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=o}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,t(this.container[this.idx])&&this.idx--)}getPath(){const o=[];let c=this.container,h=this.parents.length-1,T=this.idx;for(;T>=0;)o.unshift(c[T]),T===0?(T=this.indexes[h*2],c=this.parents[h--]):T-=t(c[T-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,T){this.container=o,this.idx=c,this.parents=h.slice(),this.indexes=T.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 T of this)o&&o.descend(T),this.traverse(o,c),o&&o.ascend()}eachPick(o,c){this.traverse(o,(h,T)=>{h.p!=null&&c(h.p,T)})}eachDrop(o,c){this.traverse(o,(h,T)=>{h.d!=null&&c(h.d,T)})}}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 T=this.container.splice(h,this.container.length-h);this.container.push(T),this.lcIdx>-1&&(this.lcIdx=h)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(i(c,this.container[this.lcIdx][0])),h=this.lcIdx+1,this.lcIdx=-1);h<this.container.length&&i(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 T=[c];this.container.splice(h,0,T),this.container=T}}}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,T=this.parents.length;let J=0;for(let _e=0;_e<o.length;_e++){const Q=o[_e];typeof Q=="string"||typeof Q=="number"?(J++,this.descend(Q)):Array.isArray(Q)?this.mergeTree(Q,c):typeof Q=="object"&&c(Q,this)}for(;J--;)this.ascend();this.lcIdx=this.parents.length===T?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=O=>new a(O);function E(O,o,c){let h,T;T=h=O?O.descendFirst():!1;function J(_e){let Q;for(;T;){const Ce=Q=O.getKey();if(_e!=null){let xe=!1;if(o&&typeof Ce=="number"&&(Q=o(Ce,O.getComponent()),Q<0&&(Q=~Q,xe=!0)),i(Q,_e))return null;if(Q===_e&&!xe)return O}c&&typeof Q=="number"&&c(Q,O.getComponent()),T=O.nextSibling()}return null}return J.end=()=>{h&&O.ascend()},J}n.advancer=E;function G(O,o,c){let h,T,J,_e;for(h=T=O&&O.descendFirst(),J=_e=o&&o.descendFirst();h||J;){let Q=h?O.getKey():null,Ce=J?o.getKey():null;Q!==null&&Ce!==null&&(i(Ce,Q)?Ce=null:Q!==Ce&&(Q=null)),c(Q==null?Ce:Q,Q!=null?O:null,Ce!=null?o:null),Q!=null&&h&&(h=O.nextSibling()),Ce!=null&&J&&(J=o.nextSibling())}T&&O.ascend(),_e&&o.ascend()}n.eachChildOf=G})(at);var lt={};(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={}))})(lt);var ct={},Ke={},yt;function ut(){return yt||(yt=1,Object.defineProperty(Ke,"__esModule",{value:!0}),Ke.uniToStrPos=Ke.strPosToUni=void 0,Ke.strPosToUni=(n,e=n.length)=>{let t=0,i=0;for(;i<e;i++){const s=n.charCodeAt(i);s>=55296&&s<=57343&&(t++,i++)}if(i!==e)throw Error("Invalid offset - splits unicode bytes");return i-t},Ke.uniToStrPos=(n,e)=>{let t=0;for(;e>0;e--){const i=n.charCodeAt(t);t+=i>=55296&&i<=57343?2:1}return t}),Ke}var dt={},bt;function ft(){return bt||(bt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.uniSlice=n.dlen=n.eachOp=void 0;const e=ut(),t=f=>{if(!Array.isArray(f))throw Error("Op must be an array of components");let _=null;for(let I=0;I<f.length;I++){const H=f[I];switch(typeof H){case"object":if(typeof H.d!="number"&&typeof H.d!="string")throw Error("Delete must be number or string");if(n.dlen(H.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(H.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(H>0))throw Error("Skip components must be >0");if(typeof _=="number")throw Error("Adjacent skip components should be combined");break}_=H}if(typeof _=="number")throw Error("Op has a trailing skip")};function i(f,_){let I=0,H=0;for(let z=0;z<f.length;z++){const K=f[z];switch(_(K,I,H),typeof K){case"object":I+=n.dlen(K.d);break;case"string":H+=e.strPosToUni(K);break;case"number":I+=K,H+=K;break}}}n.eachOp=i;function s(f,_){const I=[],H=l(I);return i(f,(z,K,Me)=>{H(_(z,K,Me))}),o(I)}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 I=f[f.length-1];I.d=typeof I.d=="string"&&typeof _.d=="string"?I.d+_.d:n.dlen(I.d)+n.dlen(_.d)}else f[f.length-1]+=_;else f.push(_)},E=f=>typeof f=="number"?f:typeof f=="string"?e.strPosToUni(f):typeof f.d=="number"?f.d:e.strPosToUni(f.d);n.uniSlice=(f,_,I)=>{const H=e.uniToStrPos(f,_),z=I==null?1/0:e.uniToStrPos(f,I);return f.slice(H,z)};const G=(f,_,I)=>typeof f=="number"?I==null?f-_:Math.min(f,I)-_:n.uniSlice(f,_,I),O=f=>{let _=0,I=0;return{take:(K,Me)=>{if(_===f.length)return K===-1?null:K;const fe=f[_];let ie;if(typeof fe=="number")return K===-1||fe-I<=K?(ie=fe-I,++_,I=0,ie):(I+=K,K);if(typeof fe=="string"){if(K===-1||Me==="i"||e.strPosToUni(fe.slice(I))<=K)return ie=fe.slice(I),++_,I=0,ie;{const ue=I+e.uniToStrPos(fe.slice(I),K);return ie=fe.slice(I,ue),I=ue,ie}}else{if(K===-1||Me==="d"||n.dlen(fe.d)-I<=K)return ie={d:G(fe.d,I)},++_,I=0,ie;{let ue=G(fe.d,I,I+K);return I+=K,{d:ue}}}},peek:()=>f[_]}},o=f=>(f.length>0&&typeof f[f.length-1]=="number"&&f.pop(),f);function c(f,_,I){if(I!=="left"&&I!=="right")throw Error("side ("+I+") must be 'left' or 'right'");t(f),t(_);const H=[],z=l(H),{take:K,peek:Me}=O(f);for(let ie=0;ie<_.length;ie++){const ue=_[ie];let Oe,Pe;switch(typeof ue){case"number":for(Oe=ue;Oe>0;)Pe=K(Oe,"i"),z(Pe),typeof Pe!="string"&&(Oe-=E(Pe));break;case"string":I==="left"&&typeof Me()=="string"&&z(K(-1)),z(e.strPosToUni(ue));break;case"object":for(Oe=n.dlen(ue.d);Oe>0;)switch(Pe=K(Oe,"i"),typeof Pe){case"number":Oe-=Pe;break;case"string":z(Pe);break;case"object":Oe-=n.dlen(Pe.d)}break}}let fe;for(;fe=K(-1);)z(fe);return o(H)}function h(f,_){t(f),t(_);const I=[],H=l(I),{take:z}=O(f);for(let Me=0;Me<_.length;Me++){const fe=_[Me];let ie,ue;switch(typeof fe){case"number":for(ie=fe;ie>0;)ue=z(ie,"d"),H(ue),typeof ue!="object"&&(ie-=E(ue));break;case"string":H(fe);break;case"object":ie=n.dlen(fe.d);let Oe=0;for(;Oe<ie;)switch(ue=z(ie-Oe,"d"),typeof ue){case"number":H({d:G(fe.d,Oe,Oe+ue)}),Oe+=ue;break;case"string":Oe+=e.strPosToUni(ue);break;case"object":H(ue)}break}}let K;for(;K=z(-1);)H(K);return o(I)}const T=(f,_)=>{let I=0;for(let H=0;H<_.length&&f>I;H++){const z=_[H];switch(typeof z){case"number":{I+=z;break}case"string":const K=e.strPosToUni(z);I+=K,f+=K;break;case"object":f-=Math.min(n.dlen(z.d),f-I);break}}return f},J=(f,_)=>typeof f=="number"?T(f,_):f.map(I=>T(I,_));function _e(f,_,I){return s(f,(H,z)=>typeof H=="object"&&typeof H.d=="number"?{d:I.slice(_,z,z+H.d)}:H)}function Q(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 Ce(f){return s(f,_=>typeof _=="object"&&typeof _.d=="string"?{d:e.strPosToUni(_.d)}:_)}function xe(f){let _=!0;return i(f,I=>{typeof I=="object"&&typeof I.d=="number"&&(_=!1)}),_}function be(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(_,I){t(I);const H=f.builder(_);for(let z=0;z<I.length;z++){const K=I[z];switch(typeof K){case"number":H.skip(K);break;case"string":H.append(K);break;case"object":H.del(n.dlen(K.d));break}}return H.build()},transform:c,compose:h,transformPosition:T,transformSelection:J,isInvertible:xe,makeInvertible(_,I){return _e(_,I,f)},stripInvertible:Ce,invert:Q,invertWithDoc(_,I){return Q(_e(_,I,f))},isNoop:_=>_.length===0}}n.default=be}(dt)),dt}var tt={},mt;function kt(){if(mt)return tt;mt=1,Object.defineProperty(tt,"__esModule",{value:!0});const n=ft(),e=ut();function t(i,s){return{get:i,getLength(){return i().length},insert(d,a,l){const E=e.strPosToUni(i(),d);return s([E,a],l)},remove(d,a,l){const E=e.strPosToUni(i(),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 It;function jt(){return It||(It=1,function(n){var e=Ae&&Ae.__createBinding||(Object.create?function(c,h,T,J){J===void 0&&(J=T),Object.defineProperty(c,J,{enumerable:!0,get:function(){return h[T]}})}:function(c,h,T,J){J===void 0&&(J=T),c[J]=h[T]}),t=Ae&&Ae.__setModuleDefault||(Object.create?function(c,h){Object.defineProperty(c,"default",{enumerable:!0,value:h})}:function(c,h){c.default=h}),i=Ae&&Ae.__importStar||function(c){if(c&&c.__esModule)return c;var h={};if(c!=null)for(var T in c)Object.hasOwnProperty.call(c,T)&&e(h,c,T);return t(h,c),h},s=Ae&&Ae.__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=ut(),a=i(ft()),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(T){let J=d.uniToStrPos(c,T);if(J>c.length)throw Error("The op is too long for this document");h.push(c.slice(0,J)),c=c.slice(J)},append(T){h.push(T)},del(T){c=c.slice(d.uniToStrPos(c,T))},build(){return h.join("")+c}}},slice:a.uniSlice},G=a.default(E),O=Object.assign(Object.assign({},G),{api:l.default});n.type=O,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=ft();Object.defineProperty(n,"makeType",{enumerable:!0,get:function(){return o.default}})}(ct)),ct}(function(n){var e=Ae&&Ae.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(n,"__esModule",{value:!0}),n.editOp=n.replaceOp=n.insertOp=n.moveOp=n.removeOp=n.type=void 0;const t=e(rt),i=e(st),s=at,d=lt;function a(r,u){if(!r)throw new Error(u)}n.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:s.readCursor,writeCursor:s.writeCursor,create:r=>r,isNoop:r=>r==null,setDebug(r){},registerSubtype:Q,checkValidOp:z,normalize:K,apply:Me,transformPosition:fe,compose:ie,tryTransform:pt,transform:Vt,makeInvertible:Pe,invert:ue,invertWithDoc:Ft,RM_UNEXPECTED_CONTENT:d.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:d.ConflictType.DROP_COLLISION,BLACKHOLE:d.ConflictType.BLACKHOLE,transformNoConflict:(r,u,y)=>Ut(()=>!0,r,u,y),typeAllowingConflictsPred:r=>Object.assign(Object.assign({},n.type),{transform:(u,y,A)=>Ut(r,u,y,A)})};const l=r=>r?r.getComponent():null;function E(r){return r&&typeof r=="object"&&!Array.isArray(r)}const G=r=>Array.isArray(r)?r.slice():r!==null&&typeof r=="object"?Object.assign({},r):r,O=r=>r&&(r.p!=null||r.r!==void 0),o=r=>r&&(r.d!=null||r.i!==void 0);function c(r,u){return a(r!=null),typeof u=="number"?(a(Array.isArray(r),"Invalid key - child is not an array"),(r=r.slice()).splice(u,1)):(a(E(r),"Invalid key - child is not an object"),delete(r=Object.assign({},r))[u]),r}function h(r,u,y){return typeof u=="number"?(a(r!=null,"Container is missing for key"),a(Array.isArray(r),"Cannot use numerical key for object container"),a(r.length>=u,"Cannot insert into out of bounds index"),r.splice(u,0,y)):(a(E(r),"Cannot insert into missing item"),a(r[u]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),r[u]=y),y}n.removeOp=(r,u=!0)=>s.writeCursor().writeAtPath(r,"r",u).get(),n.moveOp=(r,u)=>s.writeCursor().writeMove(r,u).get(),n.insertOp=(r,u)=>s.writeCursor().writeAtPath(r,"i",u).get(),n.replaceOp=(r,u,y)=>s.writeCursor().at(r,A=>{A.write("r",u),A.write("i",y)}).get(),n.editOp=(r,u,y,A=!1)=>s.writeCursor().at(r,b=>_(b,u,y,A)).get();const T=(r,u)=>r!=null&&(typeof u=="number"?Array.isArray(r):typeof r=="object"),J=(r,u)=>T(r,u)?r[u]:void 0,_e={};function Q(r){let u=r.type?r.type:r;u.name&&(_e[u.name]=u),u.uri&&(_e[u.uri]=u)}const Ce=r=>{const u=_e[r];if(u)return u;throw Error("Missing type: "+r)};Q(jt());const xe=(r,u)=>r+u;Q({name:"number",apply:xe,compose:xe,invert:r=>-r,transform:r=>r});const be=r=>r==null?null:r.et?Ce(r.et):r.es?_e["text-unicode"]:r.ena!=null?_e.number:null,f=r=>r.es?r.es:r.ena!=null?r.ena:r.e,_=(r,u,y,A=!1)=>{const[b,C]=typeof u=="string"?[Ce(u),u]:[u,u.name];!A&&b.isNoop&&b.isNoop(y)||(C==="number"?r.write("ena",y):C==="text-unicode"?r.write("es",y):(r.write("et",C),r.write("e",y)))};function I(r){a(typeof r=="number"),a(r>=0),a(r===(0|r))}function H(r){typeof r=="number"?I(r):a(typeof r=="string")}function z(r){if(r===null)return;const u=new Set,y=new Set,A=C=>{let $=!0,k=!1;for(let g in C){const v=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")I(v),a(!u.has(v)),u.add(v),a(C.r===void 0);else if(g==="d")I(v),a(!y.has(v)),y.add(v),a(C.i===void 0);else if(g==="e"||g==="es"||g==="ena"){a(!k),k=!0;const m=be(C);a(m,"Missing type in edit"),m.checkValidOp&&m.checkValidOp(f(C))}}a(!$)},b=(C,$,k)=>{if(!Array.isArray(C))throw Error("Op must be null or a list");if(C.length===0)throw Error("Empty descent");$||H(C[0]);let g=1,v=0,m=0;for(let w=0;w<C.length;w++){const j=C[w];if(a(j!=null),Array.isArray(j)){const W=b(j,!1);if(v){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,v++,g=3}else typeof j=="object"?(a(g===1,`Prev not scalar - instead ${g}`),A(j),g=2):(a(g!==3),H(j),a(s.isValidPathItem(j),"Invalid path key"),g=1)}return a(v!==1,"Operation makes multiple descents. Remove some []"),a(g===2||g===3),C[0]};b(r,!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 K(r){let u=0,y=[];const A=s.writeCursor();return A.mergeTree(r,(b,C)=>{const $=be(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 v=g==="p"||g==="d"?(k=b[g],y[k]==null&&(y[k]=u++),y[k]):b[g];C.write(g,v)}var k}),A.get()}function Me(r,u){if(z(u),u===null)return r;const y=[];return function A(b,C){let $=b,k=0,g={root:b},v=0,m=g,w="root";function j(){for(;v<k;v++){let W=C[v];typeof W!="object"&&(a(T(m,w)),m=m[w]=G(m[w]),w=W)}}for(;k<C.length;k++){const W=C[k];if(Array.isArray(W)){const p=A($,W);p!==$&&p!==void 0&&(j(),$=m[w]=p)}else if(typeof W=="object"){W.d!=null?(j(),$=h(m,w,y[W.d])):W.i!==void 0&&(j(),$=h(m,w,W.i));const p=be(W);if(p)j(),$=m[w]=p.apply($,f(W));else if(W.e!==void 0)throw Error("Subtype "+W.et+" undefined")}else $=J($,W)}return g.root}(r=function A(b,C){const $=[];let k=0;for(;k<C.length;k++){const w=C[k];if(Array.isArray(w))break;typeof w!="object"&&($.push(b),b=J(b,w))}for(let w=C.length-1;w>=k;w--)b=A(b,C[w]);for(--k;k>=0;k--){const w=C[k];if(typeof w!="object"){const j=$.pop();b=b===J(j,w)?j:b===void 0?c(j,w):(v=w,m=b,(g=G(g=j))[v]=m,g)}else O(w)&&(a(b!==void 0,"Cannot pick up or remove undefined"),w.p!=null&&(y[w.p]=b),b=void 0)}var g,v,m;return b}(r,u),u)}function fe(r,u){r=r.slice(),z(u);const y=s.readCursor(u);let A,b,C=!1;const $=[];for(let g=0;;g++){const v=r[g],m=y.getComponent();if(m&&(m.r!==void 0?C=!0:m.p!=null&&(C=!1,A=m.p,b=g)),g>=r.length)break;let w=0;const j=s.advancer(y,void 0,(p,U)=>{O(U)&&w++});$.unshift(j);const W=j(v);if(typeof v=="number"&&(r[g]-=w),!W)break}if($.forEach(g=>g.end()),C)return null;const k=()=>{let g=0;if(A!=null){const v=y.getPath();g=v.length,r=v.concat(r.slice(b))}for(;g<r.length;g++){const v=r[g],m=l(y),w=be(m);if(w){const p=f(m);w.transformPosition&&(r[g]=w.transformPosition(r[g],p));break}let j=0;const W=s.advancer(y,(p,U)=>o(U)?~(p-j):p-j,(p,U)=>{o(U)&&j++})(v);if(typeof v=="number"&&(r[g]+=j),!W)break}};return A!=null?y.eachDrop(null,g=>{g===A&&k()}):k(),r}function ie(r,u){if(z(r),z(u),r==null)return u;if(u==null)return r;let y=0;const A=s.readCursor(r),b=s.readCursor(u),C=s.writeCursor(),$=[],k=[],g=[],v=[],m=[],w=[],j=new Set;A.traverse(null,p=>{p.p!=null&&(g[p.p]=A.clone())}),b.traverse(null,p=>{p.d!=null&&(v[p.d]=b.clone())});const W=s.writeCursor();return function p(U,se,ne,x,ae,Ge,Ie,ve){a(se||ne);const le=l(se),Se=l(ne),Ne=!!Se&&Se.r!==void 0,Fe=!!le&&le.i!==void 0,Ue=le?le.d:null,De=Se?Se.p:null,We=(Ge||Ne)&&De==null;if(De!=null)x=v[De],Ie=k[De]=new s.WriteCursor;else if(Se&&Se.r!==void 0)x=null;else{const M=l(x);M&&M.d!=null&&(x=null)}const ee=l(x);if(Ue!=null)if(U=g[Ue],ve=$[Ue]=new s.WriteCursor,We)Ge&&!Ne&&ve.write("r",!0);else{const M=m[Ue]=y++;Ie.write("d",M)}else if(le&&le.i!==void 0)U=null;else{const M=l(U);M&&M.p!=null&&(U=null)}let P;Fe?(a(ae===void 0),P=le.i):P=ae;const L=(De==null?!Fe||Ge||Ne:P===void 0)?null:Ie.getComponent();if(De!=null){if(!(ae!==void 0||Fe)){const M=Ue!=null?m[Ue]:y++;w[De]=M,ve.write("p",M)}}else Ne&&(Fe||ae!==void 0||(Se.r,ve.write("r",Se.r)));const S=We?null:be(le),D=be(ee);if((S||D)&&(S&&S.name,D&&D.name),S&&D){a(S===D);const M=f(le),B=f(ee),pe=S.compose(M,B);_(Ie,S,pe),j.add(ee)}else S?_(Ie,S,f(le)):D&&(_(Ie,D,f(ee)),j.add(ee));const N=typeof P=="object"&&P!=null;let X=!1,Z=0,te=0,ge=0,he=0,ce=0;const me=s.advancer(x,(M,B)=>o(B)?he-M-1:M-he,(M,B)=>{o(B)&&he++}),q=s.advancer(U,(M,B)=>O(B)?Z-M-1:M-Z,(M,B)=>{O(B)&&Z++});if(s.eachChildOf(se,ne,(M,B,pe)=>{let we,Le,Ve=M,Te=M,et=M;if(typeof M=="number"){let ye=M+ge;Le=me(ye),Te=ye+he;let de=M+te;we=q(de),o(l(Le))&&(we=null),Ve=de+Z,et=M+ce,a(Ve>=0,"p1PickKey is negative"),a(Te>=0,"p2DropKey is negative");const Re=o(l(B)),Be=O(l(pe));(Re||Be&&!We)&&ce--,Re&&te--,Be&&ge--}else we=q(M),Le=me(M);ve.descend(Ve),Ie.descend(Te);const Ye=N&&!o(l(B))?P[et]:void 0,je=p(we,B,pe,Le,Ye,We,Ie,ve);var $e,R,oe;N&&!We?Ye!==je&&(X||(P=Array.isArray(P)?P.slice():Object.assign({},P),X=!0),$e=P,oe=je,typeof(R=et)=="number"?(a(Array.isArray($e)),a(R<$e.length)):(a(!Array.isArray($e)),a($e[R]!==void 0)),oe===void 0?typeof R=="number"?$e.splice(R,1):delete $e[R]:$e[R]=oe):a(je===void 0),Ie.ascend(),ve.ascend()}),q.end(),me.end(),L!=null)L.i=P;else if(!Ge&&!Ne&&De==null)return P}(A,A.clone(),b,b.clone(),void 0,!1,C,W),C.reset(),C.mergeTree(W.get()),C.reset(),C.get(),$.map(p=>p.get()),k.map(p=>p.get()),A.traverse(C,(p,U)=>{const se=p.p;if(se!=null){const ne=m[se];ne!=null&&U.write("p",ne);const x=$[se];x&&x.get(),x&&U.mergeTree(x.get())}else p.r!==void 0&&U.write("r",p.r)}),C.reset(),C.get(),b.traverse(C,(p,U)=>{const se=p.d;if(se!=null){const x=w[se];x!=null&&U.write("d",x);const ae=k[se];ae&&U.mergeTree(ae.get())}else p.i!==void 0&&U.write("i",p.i);const ne=be(p);ne&&!j.has(p)&&_(U,ne,f(p))}),C.get()}function ue(r){if(r==null)return null;const u=new s.ReadCursor(r),y=new s.WriteCursor;let A;const b=[],C=[];return function $(k,g,v){const m=k.getComponent();let w,j=!1;if(m){m.p!=null&&(g.write("d",m.p),b[m.p]=k.clone()),m.r!==void 0&&g.write("i",m.r),m.d!=null&&(g.write("p",m.d),v=void 0),m.i!==void 0&&(v=w=m.i);const p=be(m);p&&(v===void 0?(A||(A=new Set),A.add(m)):(f(m),v=p.apply(v,f(m)),j=!0))}let W=0;for(const p of k){g.descend(p);const U=typeof p=="number"?p-W:p,se=J(v,U);o(k.getComponent())&&W++;const ne=$(k,g,se);if(v!==void 0&&ne!==void 0){if(j||(j=!0,v=G(v)),!T(v,U))throw Error("Cannot modify child - invalid operation");v[U]=ne}g.ascend()}if(w===void 0)return j?v:void 0;g.write("r",v)}(u,y,void 0),A&&(y.reset(),function $(k,g,v){const m=g.getComponent();if(m){const p=m.d;if(p!=null&&(k=b[p],v=C[p]=s.writeCursor()),A.has(m)){const U=be(m);if(!U.invert)throw Error(`Cannot invert subtype ${U.name}`);_(v,U,U.invert(f(m)))}}let w=0,j=0;const W=s.advancer(k,(p,U)=>O(U)?w-p-1:p-w,(p,U)=>{O(U)&&w++});for(const p of g)if(typeof p=="number"){const U=p-j,se=W(U),ne=U+w;v.descend(ne),$(se,g,v),o(g.getComponent())&&j++,v.ascend()}else v.descend(p),$(W(p),g,v),v.ascend();W.end()}(u.clone(),u,y),C.length&&(y.reset(),u.traverse(y,($,k)=>{const g=$.p;if(g!=null){const v=C[g];v&&v.get(),v&&k.mergeTree(v.get())}}))),y.get()}const Oe=(r,u)=>r.some(y=>typeof y=="object"&&(Array.isArray(y)?Oe(y,u):u(y)));function Pe(r,u){if(r==null||!Oe(r,g=>{var v;return g.r!==void 0||((v=be(g))===null||v===void 0?void 0:v.makeInvertible)!=null}))return r;const y=new s.ReadCursor(r),A=new s.WriteCursor;let b=!1;const C=[],$=[],k=(g,v,m)=>{const w=g.getComponent();let j=!1;if(w){w.d!=null&&v.write("d",w.d),w.i!==void 0&&v.write("i",w.i);const p=w.p;if(p!=null&&(C[p]=g.clone(),a(m!==void 0,"Operation picks up at an invalid key"),$[p]=m,v.write("p",w.p)),w.r!==void 0&&m===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const U=be(w);U&&(U.makeInvertible?b=!0:_(v,U,f(w),!0))}let W=0;for(const p of g){v.descend(p);const U=typeof p=="number"?p-W:p,se=J(m,U),ne=k(g,v,se);se!==ne&&(j||(j=!0,m=G(m)),ne===void 0?(m=c(m,U),typeof p=="number"&&W++):m[U]=ne),v.ascend()}return w&&(w.r!==void 0?(v.write("r",i.default(m)),m=void 0):w.p!=null&&(m=void 0)),m};return k(y,A,u),A.get(),b&&(A.reset(),function g(v,m,w,j,W){const p=m.getComponent();if(p){p.i!==void 0?(j=p.i,W=!0):p.d!=null&&(j=$[p.d],v=C[p.d],W=!1,p.d);let x=be(p);if(x&&x.makeInvertible){const ae=f(p);_(w,x,x.makeInvertible(ae,j),!0)}}let U=0,se=0;const ne=s.advancer(v,(x,ae)=>O(ae)?U-x-1:x-U,(x,ae)=>{O(ae)&&U++});for(const x of m)if(typeof x=="number"){const ae=x-se,Ge=ne(ae),Ie=ae+U,ve=J(j,W?ae:Ie);w.descend(x),g(Ge,m,w,ve,W),o(m.getComponent())&&se++,w.ascend()}else{const ae=J(j,x);w.descend(x),g(ne(x),m,w,ae,W),w.ascend()}ne.end()}(y.clone(),y,A,u,!1)),A.get()}function Ft(r,u){return ue(Pe(r,u))}const gt=r=>{if(r==null)return null;const u=r.slice();for(let y=0;y<r.length;y++){const A=u[y];Array.isArray(A)&&(u[y]=gt(A))}return u};function pt(r,u,y){a(y==="left"||y==="right","Direction must be left or right");const A=y==="left"?0:1;if(u==null)return{ok:!0,result:r};z(r),z(u);let b=null;const C=[],$=[],k=[],g=[],v=[],m=[],w=[],j=[],W=[],p=[],U=[],se=[],ne=[],x=[],ae=[];let Ge=0;const Ie=s.readCursor(r),ve=s.readCursor(u),le=s.writeCursor();if(function ee(P,L=null,S){const D=l(L);D&&(D.r!==void 0?S=L.clone():D.p!=null&&(S=null,m[D.p]=P.clone()));const N=P.getComponent();let X;N&&(X=N.p)!=null&&(v[X]=L?L.clone():null,k[X]=P.clone(),S&&(p[X]=!0,W[X]=S),D&&D.p!=null&&(x[X]=D.p));const Z=s.advancer(L);for(const te of P)ee(P,Z(te),S);Z.end()}(ve,Ie,null),function ee(P,L,S,D,N){const X=S.getComponent();let Z,te=!1;X&&((Z=X.d)!=null?(g[Z]=S.clone(),D!=null&&(ae[D]==null&&(ae[D]=[]),ae[D].push(Z)),P=v[Z]||null,L=k[Z]||null,p[Z]?(N&&(U[Z]=!0),N=W[Z]||null):!N||A!==1&&x[Z]!=null||b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.moveOp(L.getPath(),S.getPath())}),te=!0):X.i!==void 0&&(P=L=null,te=!0,N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.insertOp(S.getPath(),X.i)})));const ge=l(P);ge&&(ge.r!==void 0?N=P.clone():ge.p!=null&&(ge.p,D=ge.p,N=null));const he=be(X);he&&N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.editOp(S.getPath(),he,f(X),!0)});let ce=0,me=0;const q=s.advancer(L,(B,pe)=>O(pe)?ce-B-1:B-ce,(B,pe)=>{O(pe)&&ce++}),M=s.advancer(P);for(const B of S)if(typeof B=="number"){const pe=B-me,we=q(pe);me+=+ee(M(pe+ce),we,S,D,N)}else{const pe=q(B);ee(M(B),pe,S,D,N)}return q.end(),M.end(),te}(Ie,ve,ve.clone(),null,null),g.map(ee=>ee&&ee.get()),b)return{ok:!1,conflict:b};U.map(ee=>!!ee);const Se=[];let Ne=null;(function ee(P,L,S,D,N){let X=!1;const Z=l(L);if(O(Z)){const q=Z.p;q!=null?(S=g[q],D=se[q]=s.writeCursor(),X=!0,N=null):(S=null,N=L.clone())}else o(l(S))&&(S=null);const te=P.getComponent();if(te){const q=te.p;q!=null?(N&&(j[q]=N),Se[q]=N||A===1&&X?null:D.getComponent(),C[q]=P.clone(),S&&(w[q]=S.clone())):te.r!==void 0&&(N||D.write("r",!0),(N||X)&&(Ne==null&&(Ne=new Set),Ne.add(te)))}let ge=0,he=0;const ce=s.advancer(L,void 0,(q,M)=>{O(M)&&ge++}),me=s.advancer(S,(q,M)=>o(M)?~(q-he):q-he,(q,M)=>{o(M)&&he++});if(P)for(const q of P)if(typeof q=="string"){const M=ce(q),B=me(q);D.descend(q),ee(P,M,B,D,N),D.ascend()}else{const M=ce(q),B=q-ge,pe=O(l(M))?null:me(B),we=B+he;a(we>=0),D.descend(we),ee(P,M,pe,D,N),D.ascend()}ce.end(),me.end()})(Ie,ve,ve.clone(),le,null),le.reset();let Fe=[];if(function ee(P,L,S,D,N,X){a(L);const Z=L.getComponent();let te=l(D),ge=!1;const he=(R,oe,ye)=>R?n.moveOp(R.getPath(),oe.getPath()):n.insertOp(oe.getPath(),ye.i);if(o(Z)){const R=Z.d;R!=null&&($[R]=L.clone());const oe=R!=null?Se[R]:null;let ye=!1;if(Z.i!==void 0||R!=null&&oe){let de;te&&(te.i!==void 0||(de=te.d)!=null&&!p[de])&&(ye=de!=null?R!=null&&R===x[de]:t.default(te.i,Z.i),ye||de!=null&&A!==1&&x[de]!=null||b==null&&(b={type:d.ConflictType.DROP_COLLISION,op1:he(R!=null?C[R]:null,L,Z),op2:he(de!=null?k[de]:null,D,te)})),ye||(X?b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:he(R!=null?C[R]:null,L,Z),op2:n.removeOp(X.getPath())}):(R!=null?(Fe[Ge]=R,N.write("d",oe.p=Ge++)):N.write("i",i.default(Z.i)),ge=!0))}else if(R!=null&&!oe){const de=j[R];de&&(X=de.clone())}R!=null?(P=C[R],S=m[R],D=w[R]):Z.i!==void 0&&(P=S=null,ye||(D=null))}else O(l(P))&&(P=S=D=null);const ce=l(P),me=l(S);if(O(me)){const R=me.p;me.r!==void 0&&(!ce||ce.r===void 0)||p[R]?(D=null,X=S.clone()):R!=null&&(D=g[R],A!==1&&x[R]!=null||((N=ne[R])||(N=ne[R]=s.writeCursor()),N.reset(),X=null))}else!o(Z)&&o(te)&&(D=null);te=D!=null?D.getComponent():null;const q=be(Z);if(q){const R=f(Z);if(X)b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.editOp(L.getPath(),q,R,!0),op2:n.removeOp(X.getPath())});else{const oe=be(te);let ye;if(oe){if(q!==oe)throw Error("Transforming incompatible types");const de=f(te);ye=q.transform(R,de,y)}else ye=i.default(R);_(N,q,ye)}}let M=0,B=0,pe=0,we=0,Le=0,Ve=0,Te=P!=null&&P.descendFirst(),et=Te;const Ye=s.advancer(S,void 0,(R,oe)=>{O(oe)&&pe++});let je=D!=null&&D.descendFirst(),$e=je;for(const R of L)if(typeof R=="number"){let oe;const ye=o(L.getComponent()),de=R-B;{let He;for(;Te&&typeof(He=P.getKey())=="number";){He+=M;const ke=P.getComponent(),Je=O(ke);if(He>de||He===de&&(!Je||A===0&&ye))break;if(Je){M--;const qe=ke.p;x.includes(qe),ke.d,l(ne[ke.d]),O(l(ne[ke.d])),(ke.r===void 0||Ne&&Ne.has(ke))&&(qe==null||!Se[qe]||A!==1&&x.includes(qe))||Le--}Te=P.nextSibling()}oe=Te&&He===de?P:null}const Re=de-M;let Be=Ye(Re);const _t=Re-pe;let nt=null;{let He,ke;for(;je&&typeof(He=D.getKey())=="number";){ke=He-we;const Je=D.getComponent(),qe=o(Je);if(ke>_t)break;if(ke===_t){if(!qe){nt=D;break}{if(A===0&&ye){nt=D;break}const ze=Be&&O(Be.getComponent());if(A===0&&ze)break}}if(qe){const ze=Je.d;x[ze],Je.i===void 0&&(p[ze]||x[ze]!=null&&A!==1)?(p[ze]||x[ze]!=null&&A===0)&&(we++,Ve--):we++}je=D.nextSibling()}}const Nt=_t+we+Le+Ve;a(Nt>=0,"trying to descend to a negative index"),N.descend(Nt),ye&&(oe=Be=nt=null,B++),ee(oe,L,Be,nt,N,X)&&Ve++,N.ascend()}else{let oe;for(;Te&&(oe=P.getKey(),typeof oe!="string"||!(oe>R||oe===R));)Te=P.nextSibling();const ye=Te&&oe===R?P:null,de=Ye(R);let Re;for(;je&&(Re=D.getKey(),typeof Re!="string"||!(Re>R||Re===R));)je=D.nextSibling();const Be=je&&Re===R?D:null;N.descend(R),ee(ye,L,de,Be,N,X),N.ascend()}return Ye.end(),et&&P.ascend(),$e&&D.ascend(),ge}(Ie,Ie.clone(),ve,ve.clone(),le,null),b)return{ok:!1,conflict:b};le.reset();const Ue=(ee,P,L)=>ee.traverse(P,(S,D)=>{S.d!=null&&L(S.d,ee,D)});(p.length||se.length)&&(Ue(ve,le,(ee,P,L)=>{p[ee]&&!U[ee]&&L.write("r",!0),se[ee]&&L.mergeTree(se[ee].get())}),le.reset());const De=[],We=[];if((ne.length||p.length)&&!b){const ee=s.readCursor(gt(le.get()));if(Ue(ee,null,(P,L)=>{De[P]=L.clone()}),ne.forEach(P=>{P&&Ue(s.readCursor(P.get()),null,(L,S)=>{De[L]=S.clone()})}),function P(L,S,D,N,X,Z){const te=l(S);if(te&&O(te))if(te.p!=null){const M=te.p;De[M].getPath(),D=De[M],N=We[M]=s.writeCursor()}else te.r!==void 0&&(D=null);else o(l(D))&&(D=null);const ge=L.getComponent();if(ge){let M;if((M=ge.d)!=null){const B=ne[M];B&&(B.get(),N.mergeTree(B.get()),D=s.readCursor(B.get()))}}let he=0,ce=0;const me=s.advancer(S,void 0,(M,B)=>{O(B)&&he--}),q=s.advancer(D,(M,B)=>o(B)?-(M-ce)-1:M-ce,(M,B)=>{o(B)&&ce++});for(const M of L)if(typeof M=="number"){const B=me(M),pe=M+he,we=q(pe),Le=pe+ce;N.descend(Le),P(L,B,we,N),N.ascend()}else N.descend(M),P(L,me(M),q(M),N),N.ascend();me.end(),q.end()}(ve,ee,ee.clone(),le),le.reset(),b)return{ok:!1,conflict:b};if(le.get(),We.length){const P=We.map(S=>S?S.get():null),L=s.readCursor(gt(le.get()));if(Ue(L,le,(S,D,N)=>{const X=P[S];X&&(N.mergeTree(X),P[S]=null)}),P.find(S=>S)){const S=s.writeCursor(),D=s.writeCursor();let N=0,X=0;P.forEach(Z=>{Z!=null&&Ue(s.readCursor(Z),null,te=>{const ge=Fe[te];S.writeMove(C[ge].getPath(),$[ge].getPath(),N++);const he=ae[ge];he&&he.forEach(ce=>{p[ce]||A!==1&&x[ce]!=null||D.writeMove(k[ce].getPath(),g[ce].getPath(),X++)})})}),b={type:d.ConflictType.BLACKHOLE,op1:S.get(),op2:D.get()}}}}return b?{ok:!1,conflict:b}:{ok:!0,result:le.get()}}const St=r=>{const u=new Error("Transform detected write conflict");throw u.conflict=r,u.type=u.name="writeConflict",u};function Vt(r,u,y){const A=pt(r,u,y);if(A.ok)return A.result;St(A.conflict)}const Ze=r=>{const u=s.writeCursor();return s.readCursor(r).traverse(u,(y,A)=>{(o(y)||be(y))&&A.write("r",!0)}),u.get()},qt=(r,u)=>{const{type:y,op1:A,op2:b}=r;switch(y){case d.ConflictType.DROP_COLLISION:return u==="left"?[null,Ze(b)]:[Ze(A),null];case d.ConflictType.RM_UNEXPECTED_CONTENT:let C=!1;return s.readCursor(A).traverse(null,$=>{$.r!==void 0&&(C=!0)}),C?[null,Ze(b)]:[Ze(A),null];case d.ConflictType.BLACKHOLE:return[Ze(A),Ze(b)];default:throw Error("Unrecognised conflict: "+y)}};function Ut(r,u,y,A){let b=null;for(;;){const C=pt(u,y,A);if(C.ok)return ie(b,C.result);{const{conflict:$}=C;r($)||St($);const[k,g]=qt($,A);u=ie(K(u),k),y=ie(K(y),g),b=ie(b,g)}}}})(vt),function(n){var e=Ae&&Ae.__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=Ae&&Ae.__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(vt,n);var i=at;Object.defineProperty(n,"ReadCursor",{enumerable:!0,get:function(){return i.ReadCursor}}),Object.defineProperty(n,"WriteCursor",{enumerable:!0,get:function(){return i.WriteCursor}});var s=lt;Object.defineProperty(n,"ConflictType",{enumerable:!0,get:function(){return s.ConflictType}})}(F);class wt{constructor(){V(this,"drawingManagerData",{});V(this,"_oldDrawingManagerData",{});V(this,"_focusDrawings",[]);V(this,"_remove$",new re.Subject);V(this,"remove$",this._remove$.asObservable());V(this,"_add$",new re.Subject);V(this,"add$",this._add$.asObservable());V(this,"_update$",new re.Subject);V(this,"update$",this._update$.asObservable());V(this,"_order$",new re.Subject);V(this,"order$",this._order$.asObservable());V(this,"_group$",new re.Subject);V(this,"group$",this._group$.asObservable());V(this,"_ungroup$",new re.Subject);V(this,"ungroup$",this._ungroup$.asObservable());V(this,"_refreshTransform$",new re.Subject);V(this,"refreshTransform$",this._refreshTransform$.asObservable());V(this,"_visible$",new re.Subject);V(this,"visible$",this._visible$.asObservable());V(this,"_focus$",new re.Subject);V(this,"focus$",this._focus$.asObservable());V(this,"_featurePluginUpdate$",new re.Subject);V(this,"featurePluginUpdate$",this._featurePluginUpdate$.asObservable());V(this,"_featurePluginAdd$",new re.Subject);V(this,"featurePluginAdd$",this._featurePluginAdd$.asObservable());V(this,"_featurePluginRemove$",new re.Subject);V(this,"featurePluginRemove$",this._featurePluginRemove$.asObservable());V(this,"_featurePluginOrderUpdate$",new re.Subject);V(this,"featurePluginOrderUpdate$",this._featurePluginOrderUpdate$.asObservable());V(this,"_featurePluginGroupUpdate$",new re.Subject);V(this,"featurePluginGroupUpdate$",this._featurePluginGroupUpdate$.asObservable());V(this,"_featurePluginUngroupUpdate$",new re.Subject);V(this,"featurePluginUngroupUpdate$",this._featurePluginUngroupUpdate$.asObservable());V(this,"_visible",!0);V(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 i=this._getCurrentBySearch(t);i!=null&&(i.transform=t.transform,i.transforms=t.transforms,i.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 i=[];Object.keys(t).forEach(s=>{const d=t[s];(d==null?void 0:d.data)!=null&&Object.keys(d.data).forEach(a=>{i.push({unitId:e,subUnitId:s,drawingId:a})})}),i.length>0&&this.removeNotification(i)}registerDrawingData(e,t){this.drawingManagerData[e]=t}initializeNotification(e){const t=[],i=this.drawingManagerData[e];i!=null&&(Object.keys(i).forEach(s=>{this._establishDrawingMap(e,s);const d=i[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,i){this.drawingManagerData[e][t].data=i}getBatchAddOp(e){const t=[],i=[],s=[];e.forEach(G=>{const{op:O,invertOp:o}=this._addByParam(G);t.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),i.push(O),s.push(o)});const d=i.reduce(F.type.compose,null),a=s.reduce(F.type.compose,null),{unitId:l,subUnitId:E}=e[0];return{undo:a,redo:d,unitId:l,subUnitId:E,objects:t}}getBatchRemoveOp(e){const t=[],i=[];e.forEach(E=>{const{op:G,invertOp:O}=this._removeByParam(E);t.push(G),i.push(O)});const s=t.reduce(F.type.compose,null),d=i.reduce(F.type.compose,null),{unitId:a,subUnitId:l}=e[0];return{undo:d,redo:s,unitId:a,subUnitId:l,objects:e}}getBatchUpdateOp(e){const t=[],i=[],s=[];e.forEach(G=>{const{op:O,invertOp:o}=this._updateByParam(G);t.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),i.push(O),s.push(o)});const d=i.reduce(F.type.compose,null),a=s.reduce(F.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:i,subUnitId:s}=e[0].parent;e.forEach(l=>{t.push(this._getGroupDrawingOp(l))});const d=t.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:i,subUnitId:s,objects:e}}getUngroupDrawingOp(e){const t=[],{unitId:i,subUnitId:s}=e[0].parent;e.forEach(l=>{t.push(this._getUngroupDrawingOp(l))});const d=t.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:i,subUnitId:s,objects:e}}getDrawingsByGroup(e){const{unitId:t,subUnitId:i,drawingId:s}=e;if(this.getDrawingByParam({unitId:t,subUnitId:i,drawingId:s})==null)return[];const a=this._getDrawingData(t,i),l=[];return Object.keys(a).forEach(E=>{const G=a[E];G.groupId===s&&l.push(G)}),l}_getGroupDrawingOp(e){const{parent:t,children:i}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];l.push(F.insertOp([s,d,"data",a],t));let E=Number.NEGATIVE_INFINITY;return i.forEach(G=>{const{unitId:O,subUnitId:o,drawingId:c}=G,h=this._hasDrawingOrder({unitId:O,subUnitId:o,drawingId:c});E=Math.max(E,h),l.push(...this._getUpdateParamCompareOp(G,this.getDrawingByParam({unitId:O,subUnitId:o,drawingId:c})))}),E===Number.NEGATIVE_INFINITY&&(E=this._getDrawingOrder(s,d).length),l.push(F.insertOp([s,d,"order",E],a)),l.reduce(F.type.compose,null)}_getUngroupDrawingOp(e){const{parent:t,children:i}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];return i.forEach(E=>{const{unitId:G,subUnitId:O,drawingId:o}=E;l.push(...this._getUpdateParamCompareOp(E,this.getDrawingByParam({unitId:G,subUnitId:O,drawingId:o})))}),l.push(F.removeOp([s,d,"data",a],!0)),l.push(F.removeOp([s,d,"order",this._getDrawingOrder(s,d).indexOf(a)],!0)),l.reduce(F.type.compose,null)}applyJson1(e,t,i){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=F.type.apply(this.drawingManagerData,i)}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,i,s]=e.split("#-#");return this._getCurrentBySearch({unitId:t,subUnitId:i,drawingId:s})}focusDrawing(e){if(e==null){this._focusDrawings=[],this._focus$.next([]);return}const t=[];e.forEach(i=>{var E;const{unitId:s,subUnitId:d,drawingId:a}=i,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:i,subUnitId:s,drawingId:d}=t,a=(l=this._getDrawingData(i,s))==null?void 0:l[d];a!=null&&e.push(a)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,i){this.drawingManagerData[e][t].order=i}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,i),l=[...s];s.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:i,drawingId:O});if(o===-1||o===a.length-1)return;const c=F.moveOp([t,i,"order",o],[t,i,"order",o+1]);d.push(c),l.includes(a[o+1])||l.push(a[o+1])});const E=d.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:i,objects:{...e,drawingIds:l}}}getBackwardDrawingOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,i),l=[...s];s.forEach(O=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:i,drawingId:O});if(o===-1||o===0)return;const c=F.moveOp([t,i,"order",o],[t,i,"order",o-1]);d.push(c),l.includes(a[o-1])||l.push(a[o-1])});const E=d.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:i,objects:{...e,drawingIds:l}}}getFrontDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,i,s),a=[...s],l=this.getDrawingOrder(t,i),E=[];d.forEach(o=>{const{drawingId:c}=o,h=this._getDrawingCount(t,i)-1,T=F.moveOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(c)],[t,i,"order",h]);E.push(T),a.includes(l[h])||a.push(l[h])});const G=E.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:t,subUnitId:i,objects:{...e,drawingIds:a}}}getBackDrawingsOp(e){const{unitId:t,subUnitId:i,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,i,s,!0),a=[...s],l=this.getDrawingOrder(t,i),E=[];d.forEach(o=>{const{drawingId:c}=o,h=F.moveOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(c)],[t,i,"order",0]);E.push(h),a.includes(l[0])||a.push(l[0])});const G=E.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:t,subUnitId:i,objects:{...e,drawingIds:a}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,t,i,s=!1){return i.map(d=>{const a=this._hasDrawingOrder({unitId:e,subUnitId:t,drawingId:d});return{drawingId:d,zIndex:a}}).sort(s===!1?Ee.sortRules:Ee.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;const{unitId:t,subUnitId:i,drawingId:s}=e;return this._establishDrawingMap(t,i),this._getDrawingOrder(t,i).indexOf(s)}_getCurrentBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:i,drawingId:s}=e;return(l=(a=(d=this.drawingManagerData[t])==null?void 0:d[i])==null?void 0:a.data)==null?void 0:l[s]}_getOldBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:i,drawingId:s}=e;return(l=(a=(d=this._oldDrawingManagerData[t])==null?void 0:d[i])==null?void 0:a.data)==null?void 0:l[s]}_establishDrawingMap(e,t,i){var s;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),i==null?null:(s=this.drawingManagerData[e][t].data)==null?void 0:s[i]}_addByParam(e){const{unitId:t,subUnitId:i,drawingId:s}=e;this._establishDrawingMap(t,i,s);const d=F.insertOp([t,i,"data",s],e),a=F.insertOp([t,i,"order",this._getDrawingOrder(t,i).length],s),l=[d,a].reduce(F.type.compose,null),E=F.type.invertWithDoc(l,this.drawingManagerData);return{op:l,invertOp:E}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};const{unitId:t,subUnitId:i,drawingId:s}=e;if(this._establishDrawingMap(t,i,s)==null)return{op:[],invertOp:[]};const a=F.removeOp([t,i,"data",s],!0),l=F.removeOp([t,i,"order",this._getDrawingOrder(t,i).indexOf(s)],!0),E=[a,l].reduce(F.type.compose,null),G=F.type.invertWithDoc(E,this.drawingManagerData);return{op:E,invertOp:G}}_updateByParam(e){const{unitId:t,subUnitId:i,drawingId:s}=e,d=this._establishDrawingMap(t,i,s);if(d==null)return{op:[],invertOp:[]};const l=this._getUpdateParamCompareOp(e,d).reduce(F.type.compose,null),E=F.type.invertWithDoc(l,this.drawingManagerData);return{op:l,invertOp:E}}_getUpdateParamCompareOp(e,t){const{unitId:i,subUnitId:s,drawingId:d}=e,a=[];return Object.keys(e).forEach(l=>{const E=e[l],G=t[l];G!==E&&a.push(F.replaceOp([i,s,"data",d,l],G,E))}),a}_getDrawingData(e,t){var i,s;return((s=(i=this.drawingManagerData[e])==null?void 0:i[t])==null?void 0:s.data)||{}}_getDrawingOrder(e,t){var i,s;return((s=(i=this.drawingManagerData[e])==null?void 0:i[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 Ct extends wt{}function $t({unitId:n,subUnitId:e,drawingId:t},i){return typeof i=="number"?`${n}#-#${e}#-#${t}#-#${i}`:`${n}#-#${e}#-#${t}`}const Gt=async n=>new Promise((e,t)=>{const i=new Image;i.src=n,i.onload=()=>{e({width:i.width,height:i.height,image:i})},i.onerror=s=>{t(s)}});var Qe=(n=>(n.URL="URL",n.UUID="UUID",n.BASE64="BASE64",n))(Qe||{}),Xe=(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))(Xe||{});const Et=Ee.createIdentifier("core.image-io.service");class At{constructor(){V(this,"_waitCount",0);V(this,"_change$",new re.Subject);V(this,"change$",this._change$);V(this,"_imageSourceCache",new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,t){if(t===Qe.BASE64){const i=new Image;return i.src=e,i}return this._imageSourceCache.get(e)}addImageSourceCache(e,t,i){t===Qe.BASE64||i==null||this._imageSourceCache.set(e,i)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((t,i)=>{if(!Ot.includes(e.type)){i(new Error(Xe.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>5242880){i(new Error(Xe.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){i(new Error(Xe.ERROR_IMAGE)),this._decreaseWaiting();return}const l=Ee.Tools.generateRandomId(6);t({imageId:l,imageSourceType:Qe.BASE64,source:a,base64Cache:a,status:Xe.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}}const Wt="__default_document_sub_component_id20231101__";var Dt=(n=>(n[n.forward=0]="forward",n[n.backward=1]="backward",n[n.front=2]="front",n[n.back=3]="back",n))(Dt||{}),Mt=(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))(Mt||{});const Pt=Ee.createIdentifier("univer.drawing-manager.service");var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Ht=(n,e,t,i)=>{for(var s=i>1?void 0:i?Bt(e,t):e,d=n.length-1,a;d>=0;d--)(a=n[d])&&(s=(i?a(e,t,s):a(s))||s);return i&&s&&Lt(e,t,s),s},Kt=(n,e)=>(t,i)=>e(t,i,n);const xt="DRAWING_PLUGIN";Y.UniverDrawingPlugin=(ht=class extends Ee.Plugin{constructor(e,t){super(),this._config=e,this._injector=t}onStarting(e){this._initDependencies(e)}_initDependencies(e){var s;const t=[[Et,{useClass:At}],[Pt,{useClass:Ct}]];Ee.mergeOverrideWithDependencies(t,(s=this._config)==null?void 0:s.override).forEach(d=>e.add(d))}},V(ht,"pluginName",xt),ht),Y.UniverDrawingPlugin=Ht([Kt(1,Ee.Inject(Ee.Injector))],Y.UniverDrawingPlugin),Y.ArrangeTypeEnum=Dt,Y.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=Wt,Y.DRAWING_IMAGE_ALLOW_IMAGE_LIST=Ot,Y.DRAWING_IMAGE_ALLOW_SIZE=5242880,Y.DRAWING_IMAGE_COUNT_LIMIT=10,Y.DRAWING_IMAGE_HEIGHT_LIMIT=500,Y.DRAWING_IMAGE_WIDTH_LIMIT=500,Y.DrawingManagerService=Ct,Y.DrawingTypeEnum=Mt,Y.IDrawingManagerService=Pt,Y.IImageIoService=Et,Y.ImageIoService=At,Y.ImageSourceType=Qe,Y.ImageUploadStatusType=Xe,Y.UnitDrawingService=wt,Y.getDrawingShapeKeyByDrawingSearch=$t,Y.getImageSize=Gt,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/drawing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -44,23 +44,21 @@
|
|
|
44
44
|
"lib"
|
|
45
45
|
],
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@wendellhu/redi": "0.16.0",
|
|
48
47
|
"rxjs": ">=7.0.0",
|
|
49
|
-
"@univerjs/core": "0.2.
|
|
48
|
+
"@univerjs/core": "0.2.5"
|
|
50
49
|
},
|
|
51
50
|
"dependencies": {
|
|
52
51
|
"@univerjs/icons": "^0.1.65",
|
|
53
52
|
"ot-json1": "^1.0.2"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
|
-
"@wendellhu/redi": "0.16.0",
|
|
57
55
|
"less": "^4.2.0",
|
|
58
56
|
"rxjs": "^7.8.1",
|
|
59
57
|
"typescript": "^5.5.3",
|
|
60
58
|
"vite": "^5.3.4",
|
|
61
59
|
"vitest": "^2.0.3",
|
|
62
|
-
"@univerjs/core": "0.2.
|
|
63
|
-
"@univerjs/shared": "0.2.
|
|
60
|
+
"@univerjs/core": "0.2.5",
|
|
61
|
+
"@univerjs/shared": "0.2.5"
|
|
64
62
|
},
|
|
65
63
|
"univerSpace": {
|
|
66
64
|
".": {
|