@univerjs/drawing 0.5.4 → 0.5.5-experimental.20250122-3362a4a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1530 -1481
- package/lib/umd/index.js +1 -1
- package/package.json +3 -3
- package/LICENSE +0 -176
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(te,Y){typeof exports=="object"&&typeof module<"u"?Y(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],Y):(te=typeof globalThis<"u"?globalThis:te||self,Y(te.UniverDrawing={},te.UniverCore,te.rxjs))})(this,function(te,Y,ge){"use strict";var Qt=Object.defineProperty;var en=(te,Y,ge)=>Y in te?Qt(te,Y,{enumerable:!0,configurable:!0,writable:!0,value:ge}):te[Y]=ge;var K=(te,Y,ge)=>en(te,typeof Y!="symbol"?Y+"":Y,ge);var ft;const yt=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"];var Ze={},et={},tt={},_t;function Rt(){if(_t)return tt;_t=1,Object.defineProperty(tt,"__esModule",{value:!0});function l(t,r){if(Array.isArray(r))return!1;for(let u in t)if(!n(t[u],r[u]))return!1;for(let u in r)if(t[u]===void 0)return!1;return!0}function e(t,r){if(!Array.isArray(r)||t.length!==r.length)return!1;for(let u=0;u<t.length;u++)if(!n(t[u],r[u]))return!1;return!0}function n(t,r){return t===r?!0:t===null||r===null||typeof t!="object"||typeof r!="object"?!1:Array.isArray(t)?e(t,r):l(t,r)}return tt.default=n,tt}var nt={},mt;function Wt(){if(mt)return nt;mt=1,Object.defineProperty(nt,"__esModule",{value:!0});function l(e){if(e===null)return null;if(Array.isArray(e))return e.map(l);if(typeof e=="object"){const n={};for(let t in e)n[t]=l(e[t]);return n}else return e}return nt.default=l,nt}var st={},Ot;function bt(){return Ot||(Ot=1,function(l){Object.defineProperty(l,"__esModule",{value:!0}),l.eachChildOf=l.advancer=l.readCursor=l.writeCursor=l.WriteCursor=l.ReadCursor=l.isValidPathItem=void 0;function e(_,s){if(!_)throw new Error(s)}const n=_=>_!=null&&typeof _=="object"&&!Array.isArray(_),t=(_,s)=>typeof _==typeof s?_>s:typeof _=="string"&&typeof s=="number";function r(_,s){for(let d in _){const h=d;s.write(h,_[h])}}l.isValidPathItem=_=>typeof _=="number"||typeof _=="string"&&_!=="__proto__";class u{constructor(s=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=s}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,n(this.container[this.idx])&&this.idx--)}getPath(){const s=[];let d=this.container,h=this.parents.length-1,j=this.idx;for(;j>=0;)s.unshift(d[j]),j===0?(j=this.indexes[h*2],d=this.parents[h--]):j-=n(d[j-1])?2:1;return s}}class o extends u{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let s;return this.container&&this.container.length>this.idx+1&&n(s=this.container[this.idx+1])?s:null}descendFirst(){let s=this.idx+1;if(!this.container||s>=this.container.length||n(this.container[s])&&s+1>=this.container.length)return!1;n(this.container[s])&&s++;const d=this.container[s];return Array.isArray(d)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(s),this.idx=0,this.container=d):this.idx=s,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const s=this.indexes[this.indexes.length-1]+1,d=this.parents[this.parents.length-1];return s>=d.length?!1:(e(!isNaN(s)),this.indexes[this.indexes.length-1]=s,this.container=d[s],!0)}_init(s,d,h,j){this.container=s,this.idx=d,this.parents=h.slice(),this.indexes=j.slice()}clone(){const s=new o;return s._init(this.container,this.idx,this.parents,this.indexes),s}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(s,d){const h=this.getComponent();h&&d(h,s);for(const j of this)s&&s.descend(j),this.traverse(s,d),s&&s.ascend()}eachPick(s,d){this.traverse(s,(h,j)=>{h.p!=null&&d(h.p,j)})}eachDrop(s,d){this.traverse(s,(h,j)=>{h.d!=null&&d(h.d,j)})}}l.ReadCursor=o;class a extends u{constructor(s=null){super(s),this.pendingDescent=[],this._op=s}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let s=0;s<this.pendingDescent.length;s++){const d=this.pendingDescent[s];let h=this.idx+1;if(h<this.container.length&&n(this.container[h])&&h++,e(h===this.container.length||!n(this.container[h])),h===this.container.length)this.container.push(d),this.idx=h;else if(this.container[h]===d)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(t(d,this.container[this.lcIdx][0])),h=this.lcIdx+1,this.lcIdx=-1);h<this.container.length&&t(d,this.container[h][0]);)h++;if(this.indexes.push(h),this.idx=0,h<this.container.length&&this.container[h][0]===d)this.container=this.container[h];else{const j=[d];this.container.splice(h,0,j),this.container=j}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const s=this.idx+1;if(s<this.container.length&&n(this.container[s]))return this.container[s];{const d={};return this.container.splice(s,0,d),d}}write(s,d){const h=this.getComponent();e(h[s]==null||h[s]===d,"Internal consistency error: Overwritten component. File a bug"),h[s]=d}get(){return this._op}descend(s){if(!l.isValidPathItem(s))throw Error("Invalid JSON key");this.pendingDescent.push(s)}descendPath(s){return this.pendingDescent.push(...s),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(s,d=r){if(s===null)return;if(e(Array.isArray(s)),s===this._op)throw Error("Cannot merge into my own tree");const h=this.lcIdx,j=this.parents.length;let Z=0;for(let _e=0;_e<s.length;_e++){const Q=s[_e];typeof Q=="string"||typeof Q=="number"?(Z++,this.descend(Q)):Array.isArray(Q)?this.mergeTree(Q,d):typeof Q=="object"&&d(Q,this)}for(;Z--;)this.ascend();this.lcIdx=this.parents.length===j?h:-1}at(s,d){this.descendPath(s),d(this);for(let h=0;h<s.length;h++)this.ascend();return this}writeAtPath(s,d,h){return this.at(s,()=>this.write(d,h)),this.reset(),this}writeMove(s,d,h=0){return this.writeAtPath(s,"p",h).writeAtPath(d,"d",h)}getPath(){const s=super.getPath();return s.push(...this.pendingDescent),s}}l.WriteCursor=a,l.writeCursor=()=>new a,l.readCursor=_=>new o(_);function E(_,s,d){let h,j;j=h=_?_.descendFirst():!1;function Z(_e){let Q;for(;j;){const Ee=Q=_.getKey();if(_e!=null){let Ke=!1;if(s&&typeof Ee=="number"&&(Q=s(Ee,_.getComponent()),Q<0&&(Q=~Q,Ke=!0)),t(Q,_e))return null;if(Q===_e&&!Ke)return _}d&&typeof Q=="number"&&d(Q,_.getComponent()),j=_.nextSibling()}return null}return Z.end=()=>{h&&_.ascend()},Z}l.advancer=E;function W(_,s,d){let h,j,Z,_e;for(h=j=_&&_.descendFirst(),Z=_e=s&&s.descendFirst();h||Z;){let Q=h?_.getKey():null,Ee=Z?s.getKey():null;Q!==null&&Ee!==null&&(t(Ee,Q)?Ee=null:Q!==Ee&&(Q=null)),d(Q==null?Ee:Q,Q!=null?_:null,Ee!=null?s:null),Q!=null&&h&&(h=_.nextSibling()),Ee!=null&&Z&&(Z=s.nextSibling())}j&&_.ascend(),_e&&s.ascend()}l.eachChildOf=W}(st)),st}var ot={},wt;function It(){return wt||(wt=1,function(l){Object.defineProperty(l,"__esModule",{value:!0}),l.ConflictType=void 0,function(e){e[e.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",e[e.DROP_COLLISION=2]="DROP_COLLISION",e[e.BLACKHOLE=3]="BLACKHOLE"}(l.ConflictType||(l.ConflictType={}))}(ot)),ot}var xe={},He={},vt;function at(){return vt||(vt=1,Object.defineProperty(He,"__esModule",{value:!0}),He.uniToStrPos=He.strPosToUni=void 0,He.strPosToUni=(l,e=l.length)=>{let n=0,t=0;for(;t<e;t++){const r=l.charCodeAt(t);r>=55296&&r<=57343&&(n++,t++)}if(t!==e)throw Error("Invalid offset - splits unicode bytes");return t-n},He.uniToStrPos=(l,e)=>{let n=0;for(;e>0;e--){const t=l.charCodeAt(n);n+=t>=55296&&t<=57343?2:1}return n}),He}var lt={},Ct;function ut(){return Ct||(Ct=1,function(l){Object.defineProperty(l,"__esModule",{value:!0}),l.uniSlice=l.dlen=l.eachOp=void 0;const e=at(),n=f=>{if(!Array.isArray(f))throw Error("Op must be an array of components");let y=null;for(let I=0;I<f.length;I++){const q=f[I];switch(typeof q){case"object":if(typeof q.d!="number"&&typeof q.d!="string")throw Error("Delete must be number or string");if(l.dlen(q.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(q.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(q>0))throw Error("Skip components must be >0");if(typeof y=="number")throw Error("Adjacent skip components should be combined");break}y=q}if(typeof y=="number")throw Error("Op has a trailing skip")};function t(f,y){let I=0,q=0;for(let z=0;z<f.length;z++){const x=f[z];switch(y(x,I,q),typeof x){case"object":I+=l.dlen(x.d);break;case"string":q+=e.strPosToUni(x);break;case"number":I+=x,q+=x;break}}}l.eachOp=t;function r(f,y){const I=[],q=a(I);return t(f,(z,x,Se)=>{q(y(z,x,Se))}),s(I)}const u=f=>f,o=f=>r(f,u);l.dlen=f=>typeof f=="number"?f:e.strPosToUni(f);const a=f=>y=>{if(!(!y||y.d===0||y.d===""))if(f.length===0)f.push(y);else if(typeof y==typeof f[f.length-1])if(typeof y=="object"){const I=f[f.length-1];I.d=typeof I.d=="string"&&typeof y.d=="string"?I.d+y.d:l.dlen(I.d)+l.dlen(y.d)}else f[f.length-1]+=y;else f.push(y)},E=f=>typeof f=="number"?f:typeof f=="string"?e.strPosToUni(f):typeof f.d=="number"?f.d:e.strPosToUni(f.d);l.uniSlice=(f,y,I)=>{const q=e.uniToStrPos(f,y),z=I==null?1/0:e.uniToStrPos(f,I);return f.slice(q,z)};const W=(f,y,I)=>typeof f=="number"?I==null?f-y:Math.min(f,I)-y:l.uniSlice(f,y,I),_=f=>{let y=0,I=0;return{take:(x,Se)=>{if(y===f.length)return x===-1?null:x;const fe=f[y];let ie;if(typeof fe=="number")return x===-1||fe-I<=x?(ie=fe-I,++y,I=0,ie):(I+=x,x);if(typeof fe=="string"){if(x===-1||Se==="i"||e.strPosToUni(fe.slice(I))<=x)return ie=fe.slice(I),++y,I=0,ie;{const de=I+e.uniToStrPos(fe.slice(I),x);return ie=fe.slice(I,de),I=de,ie}}else{if(x===-1||Se==="d"||l.dlen(fe.d)-I<=x)return ie={d:W(fe.d,I)},++y,I=0,ie;{let de=W(fe.d,I,I+x);return I+=x,{d:de}}}},peek:()=>f[y]}},s=f=>(f.length>0&&typeof f[f.length-1]=="number"&&f.pop(),f);function d(f,y,I){if(I!=="left"&&I!=="right")throw Error("side ("+I+") must be 'left' or 'right'");n(f),n(y);const q=[],z=a(q),{take:x,peek:Se}=_(f);for(let ie=0;ie<y.length;ie++){const de=y[ie];let me,Te;switch(typeof de){case"number":for(me=de;me>0;)Te=x(me,"i"),z(Te),typeof Te!="string"&&(me-=E(Te));break;case"string":I==="left"&&typeof Se()=="string"&&z(x(-1)),z(e.strPosToUni(de));break;case"object":for(me=l.dlen(de.d);me>0;)switch(Te=x(me,"i"),typeof Te){case"number":me-=Te;break;case"string":z(Te);break;case"object":me-=l.dlen(Te.d)}break}}let fe;for(;fe=x(-1);)z(fe);return s(q)}function h(f,y){n(f),n(y);const I=[],q=a(I),{take:z}=_(f);for(let Se=0;Se<y.length;Se++){const fe=y[Se];let ie,de;switch(typeof fe){case"number":for(ie=fe;ie>0;)de=z(ie,"d"),q(de),typeof de!="object"&&(ie-=E(de));break;case"string":q(fe);break;case"object":ie=l.dlen(fe.d);let me=0;for(;me<ie;)switch(de=z(ie-me,"d"),typeof de){case"number":q({d:W(fe.d,me,me+de)}),me+=de;break;case"string":me+=e.strPosToUni(de);break;case"object":q(de)}break}}let x;for(;x=z(-1);)q(x);return s(I)}const j=(f,y)=>{let I=0;for(let q=0;q<y.length&&f>I;q++){const z=y[q];switch(typeof z){case"number":{I+=z;break}case"string":const x=e.strPosToUni(z);I+=x,f+=x;break;case"object":f-=Math.min(l.dlen(z.d),f-I);break}}return f},Z=(f,y)=>typeof f=="number"?j(f,y):f.map(I=>j(I,y));function _e(f,y,I){return r(f,(q,z)=>typeof q=="object"&&typeof q.d=="number"?{d:I.slice(y,z,z+q.d)}:q)}function Q(f){return r(f,y=>{switch(typeof y){case"object":if(typeof y.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return y.d;case"string":return{d:y};case"number":return y}})}function Ee(f){return r(f,y=>typeof y=="object"&&typeof y.d=="string"?{d:e.strPosToUni(y.d)}:y)}function Ke(f){let y=!0;return t(f,I=>{typeof I=="object"&&typeof I.d=="number"&&(y=!1)}),y}function we(f){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:s,normalize:o,checkOp:n,create(y=""){if(typeof y!="string")throw Error("Initial data must be a string");return f.create(y)},apply(y,I){n(I);const q=f.builder(y);for(let z=0;z<I.length;z++){const x=I[z];switch(typeof x){case"number":q.skip(x);break;case"string":q.append(x);break;case"object":q.del(l.dlen(x.d));break}}return q.build()},transform:d,compose:h,transformPosition:j,transformSelection:Z,isInvertible:Ke,makeInvertible(y,I){return _e(y,I,f)},stripInvertible:Ee,invert:Q,invertWithDoc(y,I){return Q(_e(y,I,f))},isNoop:y=>y.length===0}}l.default=we}(lt)),lt}var rt={},Et;function Gt(){if(Et)return rt;Et=1,Object.defineProperty(rt,"__esModule",{value:!0});const l=ut(),e=at();function n(t,r){return{get:t,getLength(){return t().length},insert(u,o,a){const E=e.strPosToUni(t(),u);return r([E,o],a)},remove(u,o,a){const E=e.strPosToUni(t(),u);return r([E,{d:o}],a)},_onOp(u){l.eachOp(u,(o,a,E)=>{switch(typeof o){case"string":this.onInsert&&this.onInsert(E,o);break;case"object":const W=l.dlen(o.d);this.onRemove&&this.onRemove(E,W)}})},onInsert:null,onRemove:null}}return rt.default=n,n.provides={text:!0},rt}var Dt;function Lt(){return Dt||(Dt=1,function(l){var e=xe.__createBinding||(Object.create?function(d,h,j,Z){Z===void 0&&(Z=j),Object.defineProperty(d,Z,{enumerable:!0,get:function(){return h[j]}})}:function(d,h,j,Z){Z===void 0&&(Z=j),d[Z]=h[j]}),n=xe.__setModuleDefault||(Object.create?function(d,h){Object.defineProperty(d,"default",{enumerable:!0,value:h})}:function(d,h){d.default=h}),t=xe.__importStar||function(d){if(d&&d.__esModule)return d;var h={};if(d!=null)for(var j in d)Object.hasOwnProperty.call(d,j)&&e(h,d,j);return n(h,d),h},r=xe.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(l,"__esModule",{value:!0}),l.type=l.remove=l.insert=void 0;const u=at(),o=t(ut()),a=r(Gt()),E={create(d){return d},toString(d){return d},builder(d){if(typeof d!="string")throw Error("Invalid document snapshot: "+d);const h=[];return{skip(j){let Z=u.uniToStrPos(d,j);if(Z>d.length)throw Error("The op is too long for this document");h.push(d.slice(0,Z)),d=d.slice(Z)},append(j){h.push(j)},del(j){d=d.slice(u.uniToStrPos(d,j))},build(){return h.join("")+d}}},slice:o.uniSlice},W=o.default(E),_=Object.assign(Object.assign({},W),{api:a.default});l.type=_,l.insert=(d,h)=>h.length===0?[]:d===0?[h]:[d,h],l.remove=(d,h)=>o.dlen(h)===0?[]:d===0?[{d:h}]:[d,{d:h}];var s=ut();Object.defineProperty(l,"makeType",{enumerable:!0,get:function(){return s.default}})}(xe)),xe}var St;function Bt(){return St||(St=1,function(l){var e=et.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(l,"__esModule",{value:!0}),l.editOp=l.replaceOp=l.insertOp=l.moveOp=l.removeOp=l.type=void 0;const n=e(Rt()),t=e(Wt()),r=bt(),u=It();function o(i,c){if(!i)throw new Error(c)}l.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:r.readCursor,writeCursor:r.writeCursor,create:i=>i,isNoop:i=>i==null,setDebug(i){},registerSubtype:Q,checkValidOp:z,normalize:x,apply:Se,transformPosition:fe,compose:ie,tryTransform:gt,transform:Yt,makeInvertible:Te,invert:de,invertWithDoc:Jt,RM_UNEXPECTED_CONTENT:u.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:u.ConflictType.DROP_COLLISION,BLACKHOLE:u.ConflictType.BLACKHOLE,transformNoConflict:(i,c,O)=>Nt(()=>!0,i,c,O),typeAllowingConflictsPred:i=>Object.assign(Object.assign({},l.type),{transform:(c,O,D)=>Nt(i,c,O,D)})};const a=i=>i?i.getComponent():null;function E(i){return i&&typeof i=="object"&&!Array.isArray(i)}const W=i=>Array.isArray(i)?i.slice():i!==null&&typeof i=="object"?Object.assign({},i):i,_=i=>i&&(i.p!=null||i.r!==void 0),s=i=>i&&(i.d!=null||i.i!==void 0);function d(i,c){return o(i!=null),typeof c=="number"?(o(Array.isArray(i),"Invalid key - child is not an array"),(i=i.slice()).splice(c,1)):(o(E(i),"Invalid key - child is not an object"),delete(i=Object.assign({},i))[c]),i}function h(i,c,O){return typeof c=="number"?(o(i!=null,"Container is missing for key"),o(Array.isArray(i),"Cannot use numerical key for object container"),o(i.length>=c,"Cannot insert into out of bounds index"),i.splice(c,0,O)):(o(E(i),"Cannot insert into missing item"),o(i[c]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),i[c]=O),O}l.removeOp=(i,c=!0)=>r.writeCursor().writeAtPath(i,"r",c).get(),l.moveOp=(i,c)=>r.writeCursor().writeMove(i,c).get(),l.insertOp=(i,c)=>r.writeCursor().writeAtPath(i,"i",c).get(),l.replaceOp=(i,c,O)=>r.writeCursor().at(i,D=>{D.write("r",c),D.write("i",O)}).get(),l.editOp=(i,c,O,D=!1)=>r.writeCursor().at(i,b=>y(b,c,O,D)).get();const j=(i,c)=>i!=null&&(typeof c=="number"?Array.isArray(i):typeof i=="object"),Z=(i,c)=>j(i,c)?i[c]:void 0,_e={};function Q(i){let c=i.type?i.type:i;c.name&&(_e[c.name]=c),c.uri&&(_e[c.uri]=c)}const Ee=i=>{const c=_e[i];if(c)return c;throw Error("Missing type: "+i)};Q(Lt());const Ke=(i,c)=>i+c;Q({name:"number",apply:Ke,compose:Ke,invert:i=>-i,transform:i=>i});const we=i=>i==null?null:i.et?Ee(i.et):i.es?_e["text-unicode"]:i.ena!=null?_e.number:null,f=i=>i.es?i.es:i.ena!=null?i.ena:i.e,y=(i,c,O,D=!1)=>{const[b,C]=typeof c=="string"?[Ee(c),c]:[c,c.name];!D&&b.isNoop&&b.isNoop(O)||(C==="number"?i.write("ena",O):C==="text-unicode"?i.write("es",O):(i.write("et",C),i.write("e",O)))};function I(i){o(typeof i=="number"),o(i>=0),o(i===(0|i))}function q(i){typeof i=="number"?I(i):o(typeof i=="string")}function z(i){if(i===null)return;const c=new Set,O=new Set,D=C=>{let R=!0,N=!1;for(let g in C){const m=C[g];if(R=!1,o(g==="p"||g==="r"||g==="d"||g==="i"||g==="e"||g==="es"||g==="ena"||g==="et","Invalid component item '"+g+"'"),g==="p")I(m),o(!c.has(m)),c.add(m),o(C.r===void 0);else if(g==="d")I(m),o(!O.has(m)),O.add(m),o(C.i===void 0);else if(g==="e"||g==="es"||g==="ena"){o(!N),N=!0;const w=we(C);o(w,"Missing type in edit"),w.checkValidOp&&w.checkValidOp(f(C))}}o(!R)},b=(C,R,N)=>{if(!Array.isArray(C))throw Error("Op must be null or a list");if(C.length===0)throw Error("Empty descent");R||q(C[0]);let g=1,m=0,w=0;for(let v=0;v<C.length;v++){const $=C[v];if(o($!=null),Array.isArray($)){const G=b($,!1);if(m){const p=typeof w,M=typeof G;p===M?o(w<G,"descent keys are not in order"):o(p==="number"&&M==="string")}w=G,m++,g=3}else typeof $=="object"?(o(g===1,`Prev not scalar - instead ${g}`),D($),g=2):(o(g!==3),q($),o(r.isValidPathItem($),"Invalid path key"),g=1)}return o(m!==1,"Operation makes multiple descents. Remove some []"),o(g===2||g===3),C[0]};b(i,!0),o(c.size===O.size,"Mismatched picks and drops in op");for(let C=0;C<c.size;C++)o(c.has(C)),o(O.has(C))}function x(i){let c=0,O=[];const D=r.writeCursor();return D.mergeTree(i,(b,C)=>{const R=we(b);if(R){const g=f(b);y(C,R,R.normalize?R.normalize(g):g)}for(const g of["r","p","i","d"])if(b[g]!==void 0){const m=g==="p"||g==="d"?(N=b[g],O[N]==null&&(O[N]=c++),O[N]):b[g];C.write(g,m)}var N}),D.get()}function Se(i,c){if(z(c),c===null)return i;const O=[];return function D(b,C){let R=b,N=0,g={root:b},m=0,w=g,v="root";function $(){for(;m<N;m++){let G=C[m];typeof G!="object"&&(o(j(w,v)),w=w[v]=W(w[v]),v=G)}}for(;N<C.length;N++){const G=C[N];if(Array.isArray(G)){const p=D(R,G);p!==R&&p!==void 0&&($(),R=w[v]=p)}else if(typeof G=="object"){G.d!=null?($(),R=h(w,v,O[G.d])):G.i!==void 0&&($(),R=h(w,v,G.i));const p=we(G);if(p)$(),R=w[v]=p.apply(R,f(G));else if(G.e!==void 0)throw Error("Subtype "+G.et+" undefined")}else R=Z(R,G)}return g.root}(i=function D(b,C){const R=[];let N=0;for(;N<C.length;N++){const v=C[N];if(Array.isArray(v))break;typeof v!="object"&&(R.push(b),b=Z(b,v))}for(let v=C.length-1;v>=N;v--)b=D(b,C[v]);for(--N;N>=0;N--){const v=C[N];if(typeof v!="object"){const $=R.pop();b=b===Z($,v)?$:b===void 0?d($,v):(m=v,w=b,(g=W(g=$))[m]=w,g)}else _(v)&&(o(b!==void 0,"Cannot pick up or remove undefined"),v.p!=null&&(O[v.p]=b),b=void 0)}var g,m,w;return b}(i,c),c)}function fe(i,c){i=i.slice(),z(c);const O=r.readCursor(c);let D,b,C=!1;const R=[];for(let g=0;;g++){const m=i[g],w=O.getComponent();if(w&&(w.r!==void 0?C=!0:w.p!=null&&(C=!1,D=w.p,b=g)),g>=i.length)break;let v=0;const $=r.advancer(O,void 0,(p,M)=>{_(M)&&v++});R.unshift($);const G=$(m);if(typeof m=="number"&&(i[g]-=v),!G)break}if(R.forEach(g=>g.end()),C)return null;const N=()=>{let g=0;if(D!=null){const m=O.getPath();g=m.length,i=m.concat(i.slice(b))}for(;g<i.length;g++){const m=i[g],w=a(O),v=we(w);if(v){const p=f(w);v.transformPosition&&(i[g]=v.transformPosition(i[g],p));break}let $=0;const G=r.advancer(O,(p,M)=>s(M)?~(p-$):p-$,(p,M)=>{s(M)&&$++})(m);if(typeof m=="number"&&(i[g]+=$),!G)break}};return D!=null?O.eachDrop(null,g=>{g===D&&N()}):N(),i}function ie(i,c){if(z(i),z(c),i==null)return c;if(c==null)return i;let O=0;const D=r.readCursor(i),b=r.readCursor(c),C=r.writeCursor(),R=[],N=[],g=[],m=[],w=[],v=[],$=new Set;D.traverse(null,p=>{p.p!=null&&(g[p.p]=D.clone())}),b.traverse(null,p=>{p.d!=null&&(m[p.d]=b.clone())});const G=r.writeCursor();return function p(M,se,re,H,ae,Re,ve,Oe){o(se||re);const le=a(se),Pe=a(re),Me=!!Pe&&Pe.r!==void 0,Fe=!!le&&le.i!==void 0,Ae=le?le.d:null,De=Pe?Pe.p:null,We=(Re||Me)&&De==null;if(De!=null)H=m[De],ve=N[De]=new r.WriteCursor;else if(Pe&&Pe.r!==void 0)H=null;else{const T=a(H);T&&T.d!=null&&(H=null)}const ee=a(H);if(Ae!=null)if(M=g[Ae],Oe=R[Ae]=new r.WriteCursor,We)Re&&!Me&&Oe.write("r",!0);else{const T=w[Ae]=O++;ve.write("d",T)}else if(le&&le.i!==void 0)M=null;else{const T=a(M);T&&T.p!=null&&(M=null)}let P;Fe?(o(ae===void 0),P=le.i):P=ae;const L=(De==null?!Fe||Re||Me:P===void 0)?null:ve.getComponent();if(De!=null){if(!(ae!==void 0||Fe)){const T=Ae!=null?w[Ae]:O++;v[De]=T,Oe.write("p",T)}}else Me&&(Fe||ae!==void 0||(Pe.r,Oe.write("r",Pe.r)));const A=We?null:we(le),S=we(ee);if((A||S)&&(A&&A.name,S&&S.name),A&&S){o(A===S);const T=f(le),B=f(ee),ye=A.compose(T,B);y(ve,A,ye),$.add(ee)}else A?y(ve,A,f(le)):S&&(y(ve,S,f(ee)),$.add(ee));const U=typeof P=="object"&&P!=null;let J=!1,X=0,ne=0,pe=0,he=0,ue=0;const Ie=r.advancer(H,(T,B)=>s(B)?he-T-1:T-he,(T,B)=>{s(B)&&he++}),V=r.advancer(M,(T,B)=>_(B)?X-T-1:T-X,(T,B)=>{_(B)&&X++});if(r.eachChildOf(se,re,(T,B,ye)=>{let Ce,Ge,Ve=T,Ue=T,Qe=T;if(typeof T=="number"){let be=T+pe;Ge=Ie(be),Ue=be+he;let ce=T+ne;Ce=V(ce),s(a(Ge))&&(Ce=null),Ve=ce+X,Qe=T+ue,o(Ve>=0,"p1PickKey is negative"),o(Ue>=0,"p2DropKey is negative");const je=s(a(B)),Le=_(a(ye));(je||Le&&!We)&&ue--,je&&ne--,Le&&pe--}else Ce=V(T),Ge=Ie(T);Oe.descend(Ve),ve.descend(Ue);const Je=U&&!s(a(B))?P[Qe]:void 0,Ne=p(Ce,B,ye,Ge,Je,We,ve,Oe);var $e,k,oe;U&&!We?Je!==Ne&&(J||(P=Array.isArray(P)?P.slice():Object.assign({},P),J=!0),$e=P,oe=Ne,typeof(k=Qe)=="number"?(o(Array.isArray($e)),o(k<$e.length)):(o(!Array.isArray($e)),o($e[k]!==void 0)),oe===void 0?typeof k=="number"?$e.splice(k,1):delete $e[k]:$e[k]=oe):o(Ne===void 0),ve.ascend(),Oe.ascend()}),V.end(),Ie.end(),L!=null)L.i=P;else if(!Re&&!Me&&De==null)return P}(D,D.clone(),b,b.clone(),void 0,!1,C,G),C.reset(),C.mergeTree(G.get()),C.reset(),C.get(),R.map(p=>p.get()),N.map(p=>p.get()),D.traverse(C,(p,M)=>{const se=p.p;if(se!=null){const re=w[se];re!=null&&M.write("p",re);const H=R[se];H&&H.get(),H&&M.mergeTree(H.get())}else p.r!==void 0&&M.write("r",p.r)}),C.reset(),C.get(),b.traverse(C,(p,M)=>{const se=p.d;if(se!=null){const H=v[se];H!=null&&M.write("d",H);const ae=N[se];ae&&M.mergeTree(ae.get())}else p.i!==void 0&&M.write("i",p.i);const re=we(p);re&&!$.has(p)&&y(M,re,f(p))}),C.get()}function de(i){if(i==null)return null;const c=new r.ReadCursor(i),O=new r.WriteCursor;let D;const b=[],C=[];return function R(N,g,m){const w=N.getComponent();let v,$=!1;if(w){w.p!=null&&(g.write("d",w.p),b[w.p]=N.clone()),w.r!==void 0&&g.write("i",w.r),w.d!=null&&(g.write("p",w.d),m=void 0),w.i!==void 0&&(m=v=w.i);const p=we(w);p&&(m===void 0?(D||(D=new Set),D.add(w)):(f(w),m=p.apply(m,f(w)),$=!0))}let G=0;for(const p of N){g.descend(p);const M=typeof p=="number"?p-G:p,se=Z(m,M);s(N.getComponent())&&G++;const re=R(N,g,se);if(m!==void 0&&re!==void 0){if($||($=!0,m=W(m)),!j(m,M))throw Error("Cannot modify child - invalid operation");m[M]=re}g.ascend()}if(v===void 0)return $?m:void 0;g.write("r",m)}(c,O,void 0),D&&(O.reset(),function R(N,g,m){const w=g.getComponent();if(w){const p=w.d;if(p!=null&&(N=b[p],m=C[p]=r.writeCursor()),D.has(w)){const M=we(w);if(!M.invert)throw Error(`Cannot invert subtype ${M.name}`);y(m,M,M.invert(f(w)))}}let v=0,$=0;const G=r.advancer(N,(p,M)=>_(M)?v-p-1:p-v,(p,M)=>{_(M)&&v++});for(const p of g)if(typeof p=="number"){const M=p-$,se=G(M),re=M+v;m.descend(re),R(se,g,m),s(g.getComponent())&&$++,m.ascend()}else m.descend(p),R(G(p),g,m),m.ascend();G.end()}(c.clone(),c,O),C.length&&(O.reset(),c.traverse(O,(R,N)=>{const g=R.p;if(g!=null){const m=C[g];m&&m.get(),m&&N.mergeTree(m.get())}}))),O.get()}const me=(i,c)=>i.some(O=>typeof O=="object"&&(Array.isArray(O)?me(O,c):c(O)));function Te(i,c){if(i==null||!me(i,g=>{var m;return g.r!==void 0||((m=we(g))===null||m===void 0?void 0:m.makeInvertible)!=null}))return i;const O=new r.ReadCursor(i),D=new r.WriteCursor;let b=!1;const C=[],R=[],N=(g,m,w)=>{const v=g.getComponent();let $=!1;if(v){v.d!=null&&m.write("d",v.d),v.i!==void 0&&m.write("i",v.i);const p=v.p;if(p!=null&&(C[p]=g.clone(),o(w!==void 0,"Operation picks up at an invalid key"),R[p]=w,m.write("p",v.p)),v.r!==void 0&&w===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const M=we(v);M&&(M.makeInvertible?b=!0:y(m,M,f(v),!0))}let G=0;for(const p of g){m.descend(p);const M=typeof p=="number"?p-G:p,se=Z(w,M),re=N(g,m,se);se!==re&&($||($=!0,w=W(w)),re===void 0?(w=d(w,M),typeof p=="number"&&G++):w[M]=re),m.ascend()}return v&&(v.r!==void 0?(m.write("r",t.default(w)),w=void 0):v.p!=null&&(w=void 0)),w};return N(O,D,c),D.get(),b&&(D.reset(),function g(m,w,v,$,G){const p=w.getComponent();if(p){p.i!==void 0?($=p.i,G=!0):p.d!=null&&($=R[p.d],m=C[p.d],G=!1,p.d);let H=we(p);if(H&&H.makeInvertible){const ae=f(p);y(v,H,H.makeInvertible(ae,$),!0)}}let M=0,se=0;const re=r.advancer(m,(H,ae)=>_(ae)?M-H-1:H-M,(H,ae)=>{_(ae)&&M++});for(const H of w)if(typeof H=="number"){const ae=H-se,Re=re(ae),ve=ae+M,Oe=Z($,G?ae:ve);v.descend(H),g(Re,w,v,Oe,G),s(w.getComponent())&&se++,v.ascend()}else{const ae=Z($,H);v.descend(H),g(re(H),w,v,ae,G),v.ascend()}re.end()}(O.clone(),O,D,c,!1)),D.get()}function Jt(i,c){return de(Te(i,c))}const ht=i=>{if(i==null)return null;const c=i.slice();for(let O=0;O<i.length;O++){const D=c[O];Array.isArray(D)&&(c[O]=ht(D))}return c};function gt(i,c,O){o(O==="left"||O==="right","Direction must be left or right");const D=O==="left"?0:1;if(c==null)return{ok:!0,result:i};z(i),z(c);let b=null;const C=[],R=[],N=[],g=[],m=[],w=[],v=[],$=[],G=[],p=[],M=[],se=[],re=[],H=[],ae=[];let Re=0;const ve=r.readCursor(i),Oe=r.readCursor(c),le=r.writeCursor();if(function ee(P,L=null,A){const S=a(L);S&&(S.r!==void 0?A=L.clone():S.p!=null&&(A=null,w[S.p]=P.clone()));const U=P.getComponent();let J;U&&(J=U.p)!=null&&(m[J]=L?L.clone():null,N[J]=P.clone(),A&&(p[J]=!0,G[J]=A),S&&S.p!=null&&(H[J]=S.p));const X=r.advancer(L);for(const ne of P)ee(P,X(ne),A);X.end()}(Oe,ve,null),function ee(P,L,A,S,U){const J=A.getComponent();let X,ne=!1;J&&((X=J.d)!=null?(g[X]=A.clone(),S!=null&&(ae[S]==null&&(ae[S]=[]),ae[S].push(X)),p[X],P=m[X]||null,L=N[X]||null,p[X]?(U&&(M[X]=!0),U=G[X]||null):!U||D!==1&&H[X]!=null||b==null&&(b={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:l.removeOp(U.getPath()),op2:l.moveOp(L.getPath(),A.getPath())}),ne=!0):J.i!==void 0&&(P=L=null,ne=!0,U&&b==null&&(b={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:l.removeOp(U.getPath()),op2:l.insertOp(A.getPath(),J.i)})));const pe=a(P);pe&&(pe.r!==void 0?U=P.clone():pe.p!=null&&(pe.p,S=pe.p,U=null));const he=we(J);he&&U&&b==null&&(b={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:l.removeOp(U.getPath()),op2:l.editOp(A.getPath(),he,f(J),!0)});let ue=0,Ie=0;const V=r.advancer(L,(B,ye)=>_(ye)?ue-B-1:B-ue,(B,ye)=>{_(ye)&&ue++}),T=r.advancer(P);for(const B of A)if(typeof B=="number"){const ye=B-Ie,Ce=V(ye);Ie+=+ee(T(ye+ue),Ce,A,S,U)}else{const ye=V(B);ee(T(B),ye,A,S,U)}return V.end(),T.end(),ne}(ve,Oe,Oe.clone(),null,null),g.map(ee=>ee&&ee.get()),b)return{ok:!1,conflict:b};M.map(ee=>!!ee);const Pe=[];let Me=null;(function ee(P,L,A,S,U){let J=!1;const X=a(L);if(_(X)){const V=X.p;V!=null?(A=g[V],S=se[V]=r.writeCursor(),J=!0,U=null):(A=null,U=L.clone())}else s(a(A))&&(A=null);const ne=P.getComponent();if(ne){const V=ne.p;V!=null?(U&&($[V]=U),Pe[V]=U||D===1&&J?null:S.getComponent(),C[V]=P.clone(),A&&(v[V]=A.clone())):ne.r!==void 0&&(U||S.write("r",!0),(U||J)&&(Me==null&&(Me=new Set),Me.add(ne)))}let pe=0,he=0;const ue=r.advancer(L,void 0,(V,T)=>{_(T)&&pe++}),Ie=r.advancer(A,(V,T)=>s(T)?~(V-he):V-he,(V,T)=>{s(T)&&he++});if(P)for(const V of P)if(typeof V=="string"){const T=ue(V),B=Ie(V);S.descend(V),ee(P,T,B,S,U),S.ascend()}else{const T=ue(V),B=V-pe,ye=_(a(T))?null:Ie(B),Ce=B+he;o(Ce>=0),S.descend(Ce),ee(P,T,ye,S,U),S.ascend()}ue.end(),Ie.end()})(ve,Oe,Oe.clone(),le,null),le.reset();let Fe=[];if(function ee(P,L,A,S,U,J){o(L);const X=L.getComponent();let ne=a(S),pe=!1;const he=(k,oe,be)=>k?l.moveOp(k.getPath(),oe.getPath()):l.insertOp(oe.getPath(),be.i);if(s(X)){const k=X.d;k!=null&&(R[k]=L.clone());const oe=k!=null?Pe[k]:null;let be=!1;if(X.i!==void 0||k!=null&&oe){let ce;ne&&(ne.i!==void 0||(ce=ne.d)!=null&&!p[ce])&&(be=ce!=null?k!=null&&k===H[ce]:n.default(ne.i,X.i),be||ce!=null&&D!==1&&H[ce]!=null||b==null&&(b={type:u.ConflictType.DROP_COLLISION,op1:he(k!=null?C[k]:null,L,X),op2:he(ce!=null?N[ce]:null,S,ne)})),be||(J?b==null&&(b={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:he(k!=null?C[k]:null,L,X),op2:l.removeOp(J.getPath())}):(k!=null?(Fe[Re]=k,U.write("d",oe.p=Re++)):U.write("i",t.default(X.i)),pe=!0))}else if(k!=null&&!oe){const ce=$[k];ce&&(J=ce.clone())}k!=null?(P=C[k],A=w[k],S=v[k]):X.i!==void 0&&(P=A=null,be||(S=null))}else _(a(P))&&(P=A=S=null);const ue=a(P),Ie=a(A);if(_(Ie)){const k=Ie.p;Ie.r!==void 0&&(!ue||ue.r===void 0)||p[k]?(S=null,J=A.clone()):k!=null&&(S=g[k],D!==1&&H[k]!=null||((U=re[k])||(U=re[k]=r.writeCursor()),U.reset(),J=null))}else!s(X)&&s(ne)&&(S=null);ne=S!=null?S.getComponent():null;const V=we(X);if(V){const k=f(X);if(J)b==null&&(b={type:u.ConflictType.RM_UNEXPECTED_CONTENT,op1:l.editOp(L.getPath(),V,k,!0),op2:l.removeOp(J.getPath())});else{const oe=we(ne);let be;if(oe){if(V!==oe)throw Error("Transforming incompatible types");const ce=f(ne);be=V.transform(k,ce,O)}else be=t.default(k);y(U,V,be)}}let T=0,B=0,ye=0,Ce=0,Ge=0,Ve=0,Ue=P!=null&&P.descendFirst(),Qe=Ue;const Je=r.advancer(A,void 0,(k,oe)=>{_(oe)&&ye++});let Ne=S!=null&&S.descendFirst(),$e=Ne;for(const k of L)if(typeof k=="number"){let oe;const be=s(L.getComponent()),ce=k-B;{let Be;for(;Ue&&typeof(Be=P.getKey())=="number";){Be+=T;const ke=P.getComponent(),Ye=_(ke);if(Be>ce||Be===ce&&(!Ye||D===0&&be))break;if(Ye){T--;const ze=ke.p;H.includes(ze),ke.d,a(re[ke.d]),_(a(re[ke.d])),(ke.r===void 0||Me&&Me.has(ke))&&(ze==null||!Pe[ze]||D!==1&&H.includes(ze))||Ge--}Ue=P.nextSibling()}oe=Ue&&Be===ce?P:null}const je=ce-T;let Le=Je(je);const pt=je-ye;let it=null;{let Be,ke;for(;Ne&&typeof(Be=S.getKey())=="number";){ke=Be-Ce;const Ye=S.getComponent(),ze=s(Ye);if(ke>pt)break;if(ke===pt){if(!ze){it=S;break}{if(D===0&&be){it=S;break}const qe=Le&&_(Le.getComponent());if(D===0&&qe)break}}if(ze){const qe=Ye.d;p[qe],H[qe],Ye.i===void 0&&(p[qe]||H[qe]!=null&&D!==1)?(p[qe]||H[qe]!=null&&D===0)&&(Ce++,Ve--):Ce++}Ne=S.nextSibling()}}const $t=pt+Ce+Ge+Ve;o($t>=0,"trying to descend to a negative index"),U.descend($t),be&&(oe=Le=it=null,B++),ee(oe,L,Le,it,U,J)&&Ve++,U.ascend()}else{let oe;for(;Ue&&(oe=P.getKey(),typeof oe!="string"||!(oe>k||oe===k));)Ue=P.nextSibling();const be=Ue&&oe===k?P:null,ce=Je(k);let je;for(;Ne&&(je=S.getKey(),typeof je!="string"||!(je>k||je===k));)Ne=S.nextSibling();const Le=Ne&&je===k?S:null;U.descend(k),ee(be,L,ce,Le,U,J),U.ascend()}return Je.end(),Qe&&P.ascend(),$e&&S.ascend(),pe}(ve,ve.clone(),Oe,Oe.clone(),le,null),b)return{ok:!1,conflict:b};le.reset();const Ae=(ee,P,L)=>ee.traverse(P,(A,S)=>{A.d!=null&&L(A.d,ee,S)});(p.length||se.length)&&(Ae(Oe,le,(ee,P,L)=>{p[ee]&&!M[ee]&&L.write("r",!0),se[ee]&&L.mergeTree(se[ee].get())}),le.reset());const De=[],We=[];if((re.length||p.length)&&!b){const ee=r.readCursor(ht(le.get()));if(Ae(ee,null,(P,L)=>{De[P]=L.clone()}),re.forEach(P=>{P&&Ae(r.readCursor(P.get()),null,(L,A)=>{De[L]=A.clone()})}),function P(L,A,S,U,J,X){const ne=a(A);if(ne&&_(ne))if(ne.p!=null){const T=ne.p;De[T].getPath(),S=De[T],U=We[T]=r.writeCursor()}else ne.r!==void 0&&(S=null);else s(a(S))&&(S=null);const pe=L.getComponent();if(pe){let T;if((T=pe.d)!=null){const B=re[T];B&&(B.get(),U.mergeTree(B.get()),S=r.readCursor(B.get()))}}let he=0,ue=0;const Ie=r.advancer(A,void 0,(T,B)=>{_(B)&&he--}),V=r.advancer(S,(T,B)=>s(B)?-(T-ue)-1:T-ue,(T,B)=>{s(B)&&ue++});for(const T of L)if(typeof T=="number"){const B=Ie(T),ye=T+he,Ce=V(ye),Ge=ye+ue;U.descend(Ge),P(L,B,Ce,U),U.ascend()}else U.descend(T),P(L,Ie(T),V(T),U),U.ascend();Ie.end(),V.end()}(Oe,ee,ee.clone(),le),le.reset(),b)return{ok:!1,conflict:b};if(le.get(),We.length){const P=We.map(A=>A?A.get():null),L=r.readCursor(ht(le.get()));if(Ae(L,le,(A,S,U)=>{const J=P[A];J&&(U.mergeTree(J),P[A]=null)}),P.find(A=>A)){const A=r.writeCursor(),S=r.writeCursor();let U=0,J=0;P.forEach(X=>{X!=null&&Ae(r.readCursor(X),null,ne=>{const pe=Fe[ne];A.writeMove(C[pe].getPath(),R[pe].getPath(),U++);const he=ae[pe];he&&he.forEach(ue=>{p[ue]||D!==1&&H[ue]!=null||S.writeMove(N[ue].getPath(),g[ue].getPath(),J++)})})}),b={type:u.ConflictType.BLACKHOLE,op1:A.get(),op2:S.get()}}}}return b?{ok:!1,conflict:b}:{ok:!0,result:le.get()}}const kt=i=>{const c=new Error("Transform detected write conflict");throw c.conflict=i,c.type=c.name="writeConflict",c};function Yt(i,c,O){const D=gt(i,c,O);if(D.ok)return D.result;kt(D.conflict)}const Xe=i=>{const c=r.writeCursor();return r.readCursor(i).traverse(c,(O,D)=>{(s(O)||we(O))&&D.write("r",!0)}),c.get()},Zt=(i,c)=>{const{type:O,op1:D,op2:b}=i;switch(O){case u.ConflictType.DROP_COLLISION:return c==="left"?[null,Xe(b)]:[Xe(D),null];case u.ConflictType.RM_UNEXPECTED_CONTENT:let C=!1;return r.readCursor(D).traverse(null,R=>{R.r!==void 0&&(C=!0)}),C?[null,Xe(b)]:[Xe(D),null];case u.ConflictType.BLACKHOLE:return[Xe(D),Xe(b)];default:throw Error("Unrecognised conflict: "+O)}};function Nt(i,c,O,D){let b=null;for(;;){const C=gt(c,O,D);if(C.ok)return ie(b,C.result);{const{conflict:R}=C;i(R)||kt(R);const[N,g]=Zt(R,D);c=ie(x(c),N),O=ie(x(O),g),b=ie(b,g)}}}}(et)),et}var Tt;function qt(){return Tt||(Tt=1,function(l){var e=Ze.__createBinding||(Object.create?function(u,o,a,E){E===void 0&&(E=a),Object.defineProperty(u,E,{enumerable:!0,get:function(){return o[a]}})}:function(u,o,a,E){E===void 0&&(E=a),u[E]=o[a]}),n=Ze.__exportStar||function(u,o){for(var a in u)a!=="default"&&!o.hasOwnProperty(a)&&e(o,u,a)};Object.defineProperty(l,"__esModule",{value:!0}),n(Bt(),l);var t=bt();Object.defineProperty(l,"ReadCursor",{enumerable:!0,get:function(){return t.ReadCursor}}),Object.defineProperty(l,"WriteCursor",{enumerable:!0,get:function(){return t.WriteCursor}});var r=It();Object.defineProperty(l,"ConflictType",{enumerable:!0,get:function(){return r.ConflictType}})}(Ze)),Ze}var F=qt();class Pt{constructor(){K(this,"drawingManagerData",{});K(this,"_oldDrawingManagerData",{});K(this,"_focusDrawings",[]);K(this,"_remove$",new ge.Subject);K(this,"remove$",this._remove$.asObservable());K(this,"_add$",new ge.Subject);K(this,"add$",this._add$.asObservable());K(this,"_update$",new ge.Subject);K(this,"update$",this._update$.asObservable());K(this,"_order$",new ge.Subject);K(this,"order$",this._order$.asObservable());K(this,"_group$",new ge.Subject);K(this,"group$",this._group$.asObservable());K(this,"_ungroup$",new ge.Subject);K(this,"ungroup$",this._ungroup$.asObservable());K(this,"_refreshTransform$",new ge.Subject);K(this,"refreshTransform$",this._refreshTransform$.asObservable());K(this,"_visible$",new ge.Subject);K(this,"visible$",this._visible$.asObservable());K(this,"_focus$",new ge.Subject);K(this,"focus$",this._focus$.asObservable());K(this,"_featurePluginUpdate$",new ge.Subject);K(this,"featurePluginUpdate$",this._featurePluginUpdate$.asObservable());K(this,"_featurePluginAdd$",new ge.Subject);K(this,"featurePluginAdd$",this._featurePluginAdd$.asObservable());K(this,"_featurePluginRemove$",new ge.Subject);K(this,"featurePluginRemove$",this._featurePluginRemove$.asObservable());K(this,"_featurePluginOrderUpdate$",new ge.Subject);K(this,"featurePluginOrderUpdate$",this._featurePluginOrderUpdate$.asObservable());K(this,"_featurePluginGroupUpdate$",new ge.Subject);K(this,"featurePluginGroupUpdate$",this._featurePluginGroupUpdate$.asObservable());K(this,"_featurePluginUngroupUpdate$",new ge.Subject);K(this,"featurePluginUngroupUpdate$",this._featurePluginUngroupUpdate$.asObservable());K(this,"_visible",!0);K(this,"_editable",!0)}dispose(){this._remove$.complete(),this._add$.complete(),this._update$.complete(),this._order$.complete(),this._focus$.complete(),this._featurePluginUpdate$.complete(),this._featurePluginAdd$.complete(),this._featurePluginRemove$.complete(),this._featurePluginOrderUpdate$.complete(),this.drawingManagerData={},this._oldDrawingManagerData={}}visibleNotification(e){this._visible$.next(e)}refreshTransform(e){e.forEach(n=>{const t=this._getCurrentBySearch(n);t!=null&&(t.transform=n.transform,t.transforms=n.transforms,t.isMultiTransform=n.isMultiTransform)}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return this.drawingManagerData[e]||{}}removeDrawingDataForUnit(e){const n=this.drawingManagerData[e];if(n==null)return;delete this.drawingManagerData[e];const t=[];Object.keys(n).forEach(r=>{const u=n[r];(u==null?void 0:u.data)!=null&&Object.keys(u.data).forEach(o=>{t.push({unitId:e,subUnitId:r,drawingId:o})})}),t.length>0&&this.removeNotification(t)}registerDrawingData(e,n){this.drawingManagerData[e]=n}initializeNotification(e){const n=[],t=this.drawingManagerData[e];t!=null&&(Object.keys(t).forEach(r=>{this._establishDrawingMap(e,r);const u=t[r];Object.keys(u.data).forEach(o=>{const a=u.data[o];a.unitId=e,a.subUnitId=r,n.push(a)})}),n.length>0&&this.addNotification(n))}getDrawingData(e,n){return this._getDrawingData(e,n)}setDrawingData(e,n,t){this.drawingManagerData[e][n].data=t}getBatchAddOp(e){const n=[],t=[],r=[];e.forEach(W=>{const{op:_,invertOp:s}=this._addByParam(W);n.push({unitId:W.unitId,subUnitId:W.subUnitId,drawingId:W.drawingId}),t.push(_),r.push(s)});const u=t.reduce(F.type.compose,null),o=r.reduce(F.type.compose,null),{unitId:a,subUnitId:E}=e[0];return{undo:o,redo:u,unitId:a,subUnitId:E,objects:n}}getBatchRemoveOp(e){const n=[],t=[];e.forEach(E=>{const{op:W,invertOp:_}=this._removeByParam(E);n.unshift(W),t.push(_)});const r=n.reduce(F.type.compose,null),u=t.reduce(F.type.compose,null),{unitId:o,subUnitId:a}=e[0];return{undo:u,redo:r,unitId:o,subUnitId:a,objects:e}}getBatchUpdateOp(e){const n=[],t=[],r=[];e.forEach(W=>{const{op:_,invertOp:s}=this._updateByParam(W);n.push({unitId:W.unitId,subUnitId:W.subUnitId,drawingId:W.drawingId}),t.push(_),r.push(s)});const u=t.reduce(F.type.compose,null),o=r.reduce(F.type.compose,null),{unitId:a,subUnitId:E}=e[0];return{undo:o,redo:u,unitId:a,subUnitId:E,objects:n}}removeNotification(e){this._remove$.next(e)}addNotification(e){this._add$.next(e)}updateNotification(e){this._update$.next(e)}orderNotification(e){this._order$.next(e)}groupUpdateNotification(e){this._group$.next(e)}ungroupUpdateNotification(e){this._ungroup$.next(e)}refreshTransformNotification(e){this._refreshTransform$.next(e)}getGroupDrawingOp(e){const n=[],{unitId:t,subUnitId:r}=e[0].parent;e.forEach(a=>{n.push(this._getGroupDrawingOp(a))});const u=n.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(u,this.drawingManagerData),redo:u,unitId:t,subUnitId:r,objects:e}}getUngroupDrawingOp(e){const n=[],{unitId:t,subUnitId:r}=e[0].parent;e.forEach(a=>{n.push(this._getUngroupDrawingOp(a))});const u=n.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(u,this.drawingManagerData),redo:u,unitId:t,subUnitId:r,objects:e}}getDrawingsByGroup(e){const{unitId:n,subUnitId:t,drawingId:r}=e;if(this.getDrawingByParam({unitId:n,subUnitId:t,drawingId:r})==null)return[];const o=this._getDrawingData(n,t),a=[];return Object.keys(o).forEach(E=>{const W=o[E];W.groupId===r&&a.push(W)}),a}_getGroupDrawingOp(e){const{parent:n,children:t}=e,{unitId:r,subUnitId:u,drawingId:o}=n,a=[];a.push(F.insertOp([r,u,"data",o],n));let E=Number.NEGATIVE_INFINITY;return t.forEach(W=>{const{unitId:_,subUnitId:s,drawingId:d}=W,h=this._hasDrawingOrder({unitId:_,subUnitId:s,drawingId:d});E=Math.max(E,h),a.push(...this._getUpdateParamCompareOp(W,this.getDrawingByParam({unitId:_,subUnitId:s,drawingId:d})))}),E===Number.NEGATIVE_INFINITY&&(E=this._getDrawingOrder(r,u).length),a.push(F.insertOp([r,u,"order",E],o)),a.reduce(F.type.compose,null)}_getUngroupDrawingOp(e){const{parent:n,children:t}=e,{unitId:r,subUnitId:u,drawingId:o}=n,a=[];return t.forEach(E=>{const{unitId:W,subUnitId:_,drawingId:s}=E;a.push(...this._getUpdateParamCompareOp(E,this.getDrawingByParam({unitId:W,subUnitId:_,drawingId:s})))}),a.push(F.removeOp([r,u,"data",o],!0)),a.push(F.removeOp([r,u,"order",this._getDrawingOrder(r,u).indexOf(o)],!0)),a.reduce(F.type.compose,null)}applyJson1(e,n,t){this._establishDrawingMap(e,n),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=F.type.apply(this.drawingManagerData,t)}featurePluginUpdateNotification(e){this._featurePluginUpdate$.next(e)}featurePluginOrderUpdateNotification(e){this._featurePluginOrderUpdate$.next(e)}featurePluginAddNotification(e){this._featurePluginAdd$.next(e)}featurePluginRemoveNotification(e){this._featurePluginRemove$.next(e)}featurePluginGroupUpdateNotification(e){this._featurePluginGroupUpdate$.next(e)}featurePluginUngroupUpdateNotification(e){this._featurePluginUngroupUpdate$.next(e)}getDrawingByParam(e){return this._getCurrentBySearch(e)}getOldDrawingByParam(e){return this._getOldBySearch(e)}getDrawingOKey(e){const[n,t,r]=e.split("#-#");return this._getCurrentBySearch({unitId:n,subUnitId:t,drawingId:r})}focusDrawing(e){if(e==null||e.length===0){this._focusDrawings=[],this._focus$.next([]);return}const n=[];e.forEach(t=>{var E;const{unitId:r,subUnitId:u,drawingId:o}=t,a=(E=this._getDrawingData(r,u))==null?void 0:E[o];a!=null&&n.push(a)}),n.length>0&&(this._focusDrawings=n,this._focus$.next(n))}getFocusDrawings(){const e=[];return this._focusDrawings.forEach(n=>{var a;const{unitId:t,subUnitId:r,drawingId:u}=n,o=(a=this._getDrawingData(t,r))==null?void 0:a[u];o!=null&&e.push(o)}),e}getDrawingOrder(e,n){return this._getDrawingOrder(e,n)}setDrawingOrder(e,n,t){this.drawingManagerData[e][n].order=t}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){const{unitId:n,subUnitId:t,drawingIds:r}=e,u=[],o=this.getDrawingOrder(n,t),a=[...r];r.forEach(_=>{const s=this._hasDrawingOrder({unitId:n,subUnitId:t,drawingId:_});if(s===-1||s===o.length-1)return;const d=F.moveOp([n,t,"order",s],[n,t,"order",s+1]);u.push(d),a.includes(o[s+1])||a.push(o[s+1])});const E=u.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:n,subUnitId:t,objects:{...e,drawingIds:a}}}getBackwardDrawingOp(e){const{unitId:n,subUnitId:t,drawingIds:r}=e,u=[],o=this.getDrawingOrder(n,t),a=[...r];r.forEach(_=>{const s=this._hasDrawingOrder({unitId:n,subUnitId:t,drawingId:_});if(s===-1||s===0)return;const d=F.moveOp([n,t,"order",s],[n,t,"order",s-1]);u.push(d),a.includes(o[s-1])||a.push(o[s-1])});const E=u.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:n,subUnitId:t,objects:{...e,drawingIds:a}}}getFrontDrawingsOp(e){const{unitId:n,subUnitId:t,drawingIds:r}=e,u=this._getOrderFromSearchParams(n,t,r),o=[...r],a=this.getDrawingOrder(n,t),E=[];u.forEach(s=>{const{drawingId:d}=s,h=this._getDrawingCount(n,t)-1,j=F.moveOp([n,t,"order",this._getDrawingOrder(n,t).indexOf(d)],[n,t,"order",h]);E.push(j),o.includes(a[h])||o.push(a[h])});const W=E.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(W,this.drawingManagerData),redo:W,unitId:n,subUnitId:t,objects:{...e,drawingIds:o}}}getBackDrawingsOp(e){const{unitId:n,subUnitId:t,drawingIds:r}=e,u=this._getOrderFromSearchParams(n,t,r,!0),o=[...r],a=this.getDrawingOrder(n,t),E=[];u.forEach(s=>{const{drawingId:d}=s,h=F.moveOp([n,t,"order",this._getDrawingOrder(n,t).indexOf(d)],[n,t,"order",0]);E.push(h),o.includes(a[0])||o.push(a[0])});const W=E.reduce(F.type.compose,null);return{undo:F.type.invertWithDoc(W,this.drawingManagerData),redo:W,unitId:n,subUnitId:t,objects:{...e,drawingIds:o}}}_getDrawingCount(e,n){return this.getDrawingOrder(e,n).length||0}_getOrderFromSearchParams(e,n,t,r=!1){return t.map(u=>{const o=this._hasDrawingOrder({unitId:e,subUnitId:n,drawingId:u});return{drawingId:u,zIndex:o}}).sort(r===!1?Y.sortRules:Y.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;const{unitId:n,subUnitId:t,drawingId:r}=e;return this._establishDrawingMap(n,t),this._getDrawingOrder(n,t).indexOf(r)}_getCurrentBySearch(e){var u,o,a;if(e==null)return;const{unitId:n,subUnitId:t,drawingId:r}=e;return(a=(o=(u=this.drawingManagerData[n])==null?void 0:u[t])==null?void 0:o.data)==null?void 0:a[r]}_getOldBySearch(e){var u,o,a;if(e==null)return;const{unitId:n,subUnitId:t,drawingId:r}=e;return(a=(o=(u=this._oldDrawingManagerData[n])==null?void 0:u[t])==null?void 0:o.data)==null?void 0:a[r]}_establishDrawingMap(e,n,t){var r;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][n]||(this.drawingManagerData[e][n]={data:{},order:[]}),t==null?null:(r=this.drawingManagerData[e][n].data)==null?void 0:r[t]}_addByParam(e){const{unitId:n,subUnitId:t,drawingId:r}=e;this._establishDrawingMap(n,t,r);const u=F.insertOp([n,t,"data",r],e),o=F.insertOp([n,t,"order",this._getDrawingOrder(n,t).length],r),a=[u,o].reduce(F.type.compose,null),E=F.type.invertWithDoc(a,this.drawingManagerData);return{op:a,invertOp:E}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};const{unitId:n,subUnitId:t,drawingId:r}=e;if(this._establishDrawingMap(n,t,r)==null)return{op:[],invertOp:[]};const o=F.removeOp([n,t,"data",r],!0),a=F.removeOp([n,t,"order",this._getDrawingOrder(n,t).indexOf(r)],!0),E=[o,a].reduce(F.type.compose,null),W=F.type.invertWithDoc(E,this.drawingManagerData);return{op:E,invertOp:W}}_updateByParam(e){const{unitId:n,subUnitId:t,drawingId:r}=e,u=this._establishDrawingMap(n,t,r);if(u==null)return{op:[],invertOp:[]};const a=this._getUpdateParamCompareOp(e,u).reduce(F.type.compose,null),E=F.type.invertWithDoc(a,this.drawingManagerData);return{op:a,invertOp:E}}_getUpdateParamCompareOp(e,n){const{unitId:t,subUnitId:r,drawingId:u}=e,o=[];return Object.keys(e).forEach(a=>{const E=e[a],W=n[a];W!==E&&o.push(F.replaceOp([t,r,"data",u,a],W,E))}),o}_getDrawingData(e,n){var t,r;return((r=(t=this.drawingManagerData[e])==null?void 0:t[n])==null?void 0:r.data)||{}}_getDrawingOrder(e,n){var t,r;return((r=(t=this.drawingManagerData[e])==null?void 0:t[n])==null?void 0:r.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(e){this._visible=e}setDrawingEditable(e){this._editable=e}}class At extends Pt{}function xt({unitId:l,subUnitId:e,drawingId:n},t){return typeof t=="number"?`${l}#-#${e}#-#${n}#-#${t}`:`${l}#-#${e}#-#${n}`}const Ht=async l=>new Promise((e,n)=>{const t=new Image;t.src=l,t.onload=()=>{e({width:t.width,height:t.height,image:t})},t.onerror=r=>{n(r)}}),dt=Y.createIdentifier("univer.drawing-manager.service"),Mt={id:"drawing.operation.set-drawing-selected",type:Y.CommandType.OPERATION,handler:(l,e)=>{const n=l.get(dt);return e==null?!1:(n.focusDrawing(e),!0)}},Kt="drawing.config",Ut={};class jt{constructor(){K(this,"_waitCount",0);K(this,"_change$",new ge.Subject);K(this,"change$",this._change$);K(this,"_imageSourceCache",new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,n){if(n===Y.ImageSourceType.BASE64){const t=new Image;return t.src=e,t}return this._imageSourceCache.get(e)}addImageSourceCache(e,n,t){n===Y.ImageSourceType.BASE64||t==null||this._imageSourceCache.set(e,t)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((n,t)=>{if(!yt.includes(e.type)){t(new Error(Y.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>5242880){t(new Error(Y.ImageUploadStatusType.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}const r=new FileReader;r.readAsDataURL(e),r.onload=u=>{var E;const o=(E=u.target)==null?void 0:E.result;if(o==null){t(new Error(Y.ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting();return}const a=Y.Tools.generateRandomId(6);n({imageId:a,imageSourceType:Y.ImageSourceType.BASE64,source:o,base64Cache:o,status:Y.ImageUploadStatusType.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}}var Ft=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,zt=(l,e,n,t)=>{for(var r=t>1?void 0:t?Vt(e,n):e,u=l.length-1,o;u>=0;u--)(o=l[u])&&(r=(t?o(e,n,r):o(r))||r);return t&&r&&Ft(e,n,r),r},ct=(l,e)=>(n,t)=>e(n,t,l);const Xt="UNIVER_DRAWING_PLUGIN";te.UniverDrawingPlugin=(ft=class extends Y.Plugin{constructor(e=Ut,n,t,r){super(),this._config=e,this._injector=n,this._configService=t,this._commandService=r;const{...u}=Y.merge({},Ut,this._config);this._configService.setConfig(Kt,u)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var t;const e=[[Y.IImageIoService,{useClass:jt}],[dt,{useClass:At}]];Y.mergeOverrideWithDependencies(e,(t=this._config)==null?void 0:t.override).forEach(r=>this._injector.add(r))}_initCommands(){[Mt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}},K(ft,"pluginName",Xt),ft),te.UniverDrawingPlugin=zt([ct(1,Y.Inject(Y.Injector)),ct(2,Y.IConfigService),ct(3,Y.ICommandService)],te.UniverDrawingPlugin),Object.defineProperty(te,"IImageIoService",{enumerable:!0,get:()=>Y.IImageIoService}),Object.defineProperty(te,"ImageSourceType",{enumerable:!0,get:()=>Y.ImageSourceType}),Object.defineProperty(te,"ImageUploadStatusType",{enumerable:!0,get:()=>Y.ImageUploadStatusType}),te.DRAWING_IMAGE_ALLOW_IMAGE_LIST=yt,te.DRAWING_IMAGE_ALLOW_SIZE=5242880,te.DRAWING_IMAGE_COUNT_LIMIT=10,te.DRAWING_IMAGE_HEIGHT_LIMIT=500,te.DRAWING_IMAGE_WIDTH_LIMIT=500,te.DrawingManagerService=At,te.IDrawingManagerService=dt,te.ImageIoService=jt,te.SetDrawingSelectedOperation=Mt,te.UnitDrawingService=Pt,te.getDrawingShapeKeyByDrawingSearch=xt,te.getImageSize=Ht,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverDrawing={},global.UniverCore,global.rxjs))})(this,function(exports2,core,rxjs){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a;const DRAWING_IMAGE_ALLOW_IMAGE_LIST=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"];var dist$1={},json1_release={},deepEqual={},hasRequiredDeepEqual;function requireDeepEqual(){if(hasRequiredDeepEqual)return deepEqual;hasRequiredDeepEqual=1,Object.defineProperty(deepEqual,"__esModule",{value:!0});function eqObj(a,b){if(Array.isArray(b))return!1;for(let k in a)if(!deepEqual$1(a[k],b[k]))return!1;for(let k in b)if(a[k]===void 0)return!1;return!0}__name(eqObj,"eqObj");function eqArr(a,b){if(!Array.isArray(b)||a.length!==b.length)return!1;for(let i=0;i<a.length;i++)if(!deepEqual$1(a[i],b[i]))return!1;return!0}__name(eqArr,"eqArr");function deepEqual$1(a,b){return a===b?!0:a===null||b===null||typeof a!="object"||typeof b!="object"?!1:Array.isArray(a)?eqArr(a,b):eqObj(a,b)}return __name(deepEqual$1,"deepEqual$1"),deepEqual.default=deepEqual$1,deepEqual}__name(requireDeepEqual,"requireDeepEqual");var deepClone={},hasRequiredDeepClone;function requireDeepClone(){if(hasRequiredDeepClone)return deepClone;hasRequiredDeepClone=1,Object.defineProperty(deepClone,"__esModule",{value:!0});function deepClone$1(old){if(old===null)return null;if(Array.isArray(old))return old.map(deepClone$1);if(typeof old=="object"){const o={};for(let k in old)o[k]=deepClone$1(old[k]);return o}else return old}return __name(deepClone$1,"deepClone$1"),deepClone.default=deepClone$1,deepClone}__name(requireDeepClone,"requireDeepClone");var cursor={},hasRequiredCursor;function requireCursor(){return hasRequiredCursor||(hasRequiredCursor=1,function(exports3){Object.defineProperty(exports3,"__esModule",{value:!0}),exports3.eachChildOf=exports3.advancer=exports3.readCursor=exports3.writeCursor=exports3.WriteCursor=exports3.ReadCursor=exports3.isValidPathItem=void 0;function assert(pred,msg){if(!pred)throw new Error(msg)}__name(assert,"assert");const isObject=__name(o=>o!=null&&typeof o=="object"&&!Array.isArray(o),"isObject"),isGreaterKey=__name((a,b)=>typeof a==typeof b?a>b:typeof a=="string"&&typeof b=="number","isGreaterKey");function copyAll(c,w){for(let _k in c){const k=_k;w.write(k,c[k])}}__name(copyAll,"copyAll"),exports3.isValidPathItem=k=>typeof k=="number"||typeof k=="string"&&k!=="__proto__";const _Cursor=class _Cursor{constructor(op=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=op}ascend(){assert(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(assert(this.idx>0),this.idx--,isObject(this.container[this.idx])&&this.idx--)}getPath(){const path=[];let c=this.container,p=this.parents.length-1,i=this.idx;for(;i>=0;)path.unshift(c[i]),i===0?(i=this.indexes[p*2],c=this.parents[p--]):i-=isObject(c[i-1])?2:1;return path}};__name(_Cursor,"Cursor");let Cursor=_Cursor;const _ReadCursor=class _ReadCursor extends Cursor{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return assert(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let c;return this.container&&this.container.length>this.idx+1&&isObject(c=this.container[this.idx+1])?c:null}descendFirst(){let i=this.idx+1;if(!this.container||i>=this.container.length||isObject(this.container[i])&&i+1>=this.container.length)return!1;isObject(this.container[i])&&i++;const firstChild=this.container[i];return Array.isArray(firstChild)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(i),this.idx=0,this.container=firstChild):this.idx=i,!0}nextSibling(){if(assert(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const i=this.indexes[this.indexes.length-1]+1,c=this.parents[this.parents.length-1];return i>=c.length?!1:(assert(!isNaN(i)),this.indexes[this.indexes.length-1]=i,this.container=c[i],!0)}_init(_container,_idx,_parents,_indexes){this.container=_container,this.idx=_idx,this.parents=_parents.slice(),this.indexes=_indexes.slice()}clone(){const c=new _ReadCursor;return c._init(this.container,this.idx,this.parents,this.indexes),c}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(w,fn){const c=this.getComponent();c&&fn(c,w);for(const key of this)w&&w.descend(key),this.traverse(w,fn),w&&w.ascend()}eachPick(w,fn){this.traverse(w,(c,w2)=>{c.p!=null&&fn(c.p,w2)})}eachDrop(w,fn){this.traverse(w,(c,w2)=>{c.d!=null&&fn(c.d,w2)})}};__name(_ReadCursor,"ReadCursor");let ReadCursor=_ReadCursor;exports3.ReadCursor=ReadCursor;const _WriteCursor=class _WriteCursor extends Cursor{constructor(op=null){super(op),this.pendingDescent=[],this._op=op}flushDescent(){assert(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let j=0;j<this.pendingDescent.length;j++){const k=this.pendingDescent[j];let i=this.idx+1;if(i<this.container.length&&isObject(this.container[i])&&i++,assert(i===this.container.length||!isObject(this.container[i])),i===this.container.length)this.container.push(k),this.idx=i;else if(this.container[i]===k)this.idx=i;else{if(!Array.isArray(this.container[i])){const oldChild=this.container.splice(i,this.container.length-i);this.container.push(oldChild),this.lcIdx>-1&&(this.lcIdx=i)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(assert(isGreaterKey(k,this.container[this.lcIdx][0])),i=this.lcIdx+1,this.lcIdx=-1);i<this.container.length&&isGreaterKey(k,this.container[i][0]);)i++;if(this.indexes.push(i),this.idx=0,i<this.container.length&&this.container[i][0]===k)this.container=this.container[i];else{const child=[k];this.container.splice(i,0,child),this.container=child}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const i=this.idx+1;if(i<this.container.length&&isObject(this.container[i]))return this.container[i];{const component={};return this.container.splice(i,0,component),component}}write(key,value){const component=this.getComponent();assert(component[key]==null||component[key]===value,"Internal consistency error: Overwritten component. File a bug"),component[key]=value}get(){return this._op}descend(key){if(!exports3.isValidPathItem(key))throw Error("Invalid JSON key");this.pendingDescent.push(key)}descendPath(path){return this.pendingDescent.push(...path),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(data,mergeFn=copyAll){if(data===null)return;if(assert(Array.isArray(data)),data===this._op)throw Error("Cannot merge into my own tree");const _lcIdx=this.lcIdx,oldDepth=this.parents.length;let depth=0;for(let i=0;i<data.length;i++){const c=data[i];typeof c=="string"||typeof c=="number"?(depth++,this.descend(c)):Array.isArray(c)?this.mergeTree(c,mergeFn):typeof c=="object"&&mergeFn(c,this)}for(;depth--;)this.ascend();this.lcIdx=this.parents.length===oldDepth?_lcIdx:-1}at(path,fn){this.descendPath(path),fn(this);for(let i=0;i<path.length;i++)this.ascend();return this}writeAtPath(path,key,value){return this.at(path,()=>this.write(key,value)),this.reset(),this}writeMove(path1,path2,slot=0){return this.writeAtPath(path1,"p",slot).writeAtPath(path2,"d",slot)}getPath(){const path=super.getPath();return path.push(...this.pendingDescent),path}};__name(_WriteCursor,"WriteCursor");let WriteCursor=_WriteCursor;exports3.WriteCursor=WriteCursor,exports3.writeCursor=()=>new WriteCursor,exports3.readCursor=op=>new ReadCursor(op);function advancer(r,listMap,listAdv){let didDescend,valid;valid=didDescend=r?r.descendFirst():!1;function adv(ktarget){let k2_;for(;valid;){const k2=k2_=r.getKey();if(ktarget!=null){let skip=!1;if(listMap&&typeof k2=="number"&&(k2_=listMap(k2,r.getComponent()),k2_<0&&(k2_=~k2_,skip=!0)),isGreaterKey(k2_,ktarget))return null;if(k2_===ktarget&&!skip)return r}listAdv&&typeof k2_=="number"&&listAdv(k2_,r.getComponent()),valid=r.nextSibling()}return null}return __name(adv,"adv"),adv.end=()=>{didDescend&&r.ascend()},adv}__name(advancer,"advancer"),exports3.advancer=advancer;function eachChildOf(r1,r2,fn){let hasChild1,descended1,hasChild2,descended2;for(hasChild1=descended1=r1&&r1.descendFirst(),hasChild2=descended2=r2&&r2.descendFirst();hasChild1||hasChild2;){let k1=hasChild1?r1.getKey():null,k2=hasChild2?r2.getKey():null;k1!==null&&k2!==null&&(isGreaterKey(k2,k1)?k2=null:k1!==k2&&(k1=null)),fn(k1==null?k2:k1,k1!=null?r1:null,k2!=null?r2:null),k1!=null&&hasChild1&&(hasChild1=r1.nextSibling()),k2!=null&&hasChild2&&(hasChild2=r2.nextSibling())}descended1&&r1.ascend(),descended2&&r2.ascend()}__name(eachChildOf,"eachChildOf"),exports3.eachChildOf=eachChildOf}(cursor)),cursor}__name(requireCursor,"requireCursor");var types={},hasRequiredTypes;function requireTypes(){return hasRequiredTypes||(hasRequiredTypes=1,function(exports3){Object.defineProperty(exports3,"__esModule",{value:!0}),exports3.ConflictType=void 0,function(ConflictType){ConflictType[ConflictType.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",ConflictType[ConflictType.DROP_COLLISION=2]="DROP_COLLISION",ConflictType[ConflictType.BLACKHOLE=3]="BLACKHOLE"}(exports3.ConflictType||(exports3.ConflictType={}))}(types)),types}__name(requireTypes,"requireTypes");var dist={},unicount={},hasRequiredUnicount;function requireUnicount(){return hasRequiredUnicount||(hasRequiredUnicount=1,Object.defineProperty(unicount,"__esModule",{value:!0}),unicount.uniToStrPos=unicount.strPosToUni=void 0,unicount.strPosToUni=(s,strOffset=s.length)=>{let pairs=0,i=0;for(;i<strOffset;i++){const code=s.charCodeAt(i);code>=55296&&code<=57343&&(pairs++,i++)}if(i!==strOffset)throw Error("Invalid offset - splits unicode bytes");return i-pairs},unicount.uniToStrPos=(s,uniOffset)=>{let pos=0;for(;uniOffset>0;uniOffset--){const code=s.charCodeAt(pos);pos+=code>=55296&&code<=57343?2:1}return pos}),unicount}__name(requireUnicount,"requireUnicount");var type={},hasRequiredType;function requireType(){return hasRequiredType||(hasRequiredType=1,function(exports3){Object.defineProperty(exports3,"__esModule",{value:!0}),exports3.uniSlice=exports3.dlen=exports3.eachOp=void 0;const unicount_1=requireUnicount(),checkOp=__name(op=>{if(!Array.isArray(op))throw Error("Op must be an array of components");let last=null;for(let i=0;i<op.length;i++){const c=op[i];switch(typeof c){case"object":if(typeof c.d!="number"&&typeof c.d!="string")throw Error("Delete must be number or string");if(exports3.dlen(c.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(c.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(c>0))throw Error("Skip components must be >0");if(typeof last=="number")throw Error("Adjacent skip components should be combined");break}last=c}if(typeof last=="number")throw Error("Op has a trailing skip")},"checkOp");function eachOp(op,fn){let prePos=0,postPos=0;for(let i=0;i<op.length;i++){const c=op[i];switch(fn(c,prePos,postPos),typeof c){case"object":prePos+=exports3.dlen(c.d);break;case"string":postPos+=unicount_1.strPosToUni(c);break;case"number":prePos+=c,postPos+=c;break}}}__name(eachOp,"eachOp"),exports3.eachOp=eachOp;function mapOp(op,fn){const newOp=[],append=makeAppend(newOp);return eachOp(op,(c,prePos,postPos)=>{append(fn(c,prePos,postPos))}),trim(newOp)}__name(mapOp,"mapOp");const id=__name(x=>x,"id"),normalize=__name(op=>mapOp(op,id),"normalize");exports3.dlen=d=>typeof d=="number"?d:unicount_1.strPosToUni(d);const makeAppend=__name(op=>component=>{if(!(!component||component.d===0||component.d===""))if(op.length===0)op.push(component);else if(typeof component==typeof op[op.length-1])if(typeof component=="object"){const last=op[op.length-1];last.d=typeof last.d=="string"&&typeof component.d=="string"?last.d+component.d:exports3.dlen(last.d)+exports3.dlen(component.d)}else op[op.length-1]+=component;else op.push(component)},"makeAppend"),componentLength=__name(c=>typeof c=="number"?c:typeof c=="string"?unicount_1.strPosToUni(c):typeof c.d=="number"?c.d:unicount_1.strPosToUni(c.d),"componentLength");exports3.uniSlice=(s,startUni,endUni)=>{const start=unicount_1.uniToStrPos(s,startUni),end=endUni==null?1/0:unicount_1.uniToStrPos(s,endUni);return s.slice(start,end)};const dslice=__name((d,start,end)=>typeof d=="number"?end==null?d-start:Math.min(d,end)-start:exports3.uniSlice(d,start,end),"dslice"),makeTake=__name(op=>{let idx=0,offset=0;return{take:__name((n,indivisableField)=>{if(idx===op.length)return n===-1?null:n;const c=op[idx];let part;if(typeof c=="number")return n===-1||c-offset<=n?(part=c-offset,++idx,offset=0,part):(offset+=n,n);if(typeof c=="string"){if(n===-1||indivisableField==="i"||unicount_1.strPosToUni(c.slice(offset))<=n)return part=c.slice(offset),++idx,offset=0,part;{const offset2=offset+unicount_1.uniToStrPos(c.slice(offset),n);return part=c.slice(offset,offset2),offset=offset2,part}}else{if(n===-1||indivisableField==="d"||exports3.dlen(c.d)-offset<=n)return part={d:dslice(c.d,offset)},++idx,offset=0,part;{let result=dslice(c.d,offset,offset+n);return offset+=n,{d:result}}}},"take"),peek:__name(()=>op[idx],"peek")}},"makeTake"),trim=__name(op=>(op.length>0&&typeof op[op.length-1]=="number"&&op.pop(),op),"trim");function transform(op1,op2,side){if(side!=="left"&&side!=="right")throw Error("side ("+side+") must be 'left' or 'right'");checkOp(op1),checkOp(op2);const newOp=[],append=makeAppend(newOp),{take,peek}=makeTake(op1);for(let i=0;i<op2.length;i++){const c2=op2[i];let length,c1;switch(typeof c2){case"number":for(length=c2;length>0;)c1=take(length,"i"),append(c1),typeof c1!="string"&&(length-=componentLength(c1));break;case"string":side==="left"&&typeof peek()=="string"&&append(take(-1)),append(unicount_1.strPosToUni(c2));break;case"object":for(length=exports3.dlen(c2.d);length>0;)switch(c1=take(length,"i"),typeof c1){case"number":length-=c1;break;case"string":append(c1);break;case"object":length-=exports3.dlen(c1.d)}break}}let c;for(;c=take(-1);)append(c);return trim(newOp)}__name(transform,"transform");function compose(op1,op2){checkOp(op1),checkOp(op2);const result=[],append=makeAppend(result),{take}=makeTake(op1);for(let i=0;i<op2.length;i++){const component=op2[i];let length,chunk;switch(typeof component){case"number":for(length=component;length>0;)chunk=take(length,"d"),append(chunk),typeof chunk!="object"&&(length-=componentLength(chunk));break;case"string":append(component);break;case"object":length=exports3.dlen(component.d);let offset=0;for(;offset<length;)switch(chunk=take(length-offset,"d"),typeof chunk){case"number":append({d:dslice(component.d,offset,offset+chunk)}),offset+=chunk;break;case"string":offset+=unicount_1.strPosToUni(chunk);break;case"object":append(chunk)}break}}let c;for(;c=take(-1);)append(c);return trim(result)}__name(compose,"compose");const transformPosition=__name((cursor2,op)=>{let pos=0;for(let i=0;i<op.length&&cursor2>pos;i++){const c=op[i];switch(typeof c){case"number":{pos+=c;break}case"string":const offset=unicount_1.strPosToUni(c);pos+=offset,cursor2+=offset;break;case"object":cursor2-=Math.min(exports3.dlen(c.d),cursor2-pos);break}}return cursor2},"transformPosition"),transformSelection=__name((selection,op)=>typeof selection=="number"?transformPosition(selection,op):selection.map(s=>transformPosition(s,op)),"transformSelection");function makeInvertible(op,doc,ropeImpl){return mapOp(op,(c,prePos)=>typeof c=="object"&&typeof c.d=="number"?{d:ropeImpl.slice(doc,prePos,prePos+c.d)}:c)}__name(makeInvertible,"makeInvertible");function invert(op){return mapOp(op,c=>{switch(typeof c){case"object":if(typeof c.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return c.d;case"string":return{d:c};case"number":return c}})}__name(invert,"invert");function stripInvertible(op){return mapOp(op,c=>typeof c=="object"&&typeof c.d=="string"?{d:unicount_1.strPosToUni(c.d)}:c)}__name(stripInvertible,"stripInvertible");function isInvertible(op){let invertible=!0;return eachOp(op,c=>{typeof c=="object"&&typeof c.d=="number"&&(invertible=!1)}),invertible}__name(isInvertible,"isInvertible");function makeType(ropeImpl){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim,normalize,checkOp,create(initial=""){if(typeof initial!="string")throw Error("Initial data must be a string");return ropeImpl.create(initial)},apply(str,op){checkOp(op);const builder=ropeImpl.builder(str);for(let i=0;i<op.length;i++){const component=op[i];switch(typeof component){case"number":builder.skip(component);break;case"string":builder.append(component);break;case"object":builder.del(exports3.dlen(component.d));break}}return builder.build()},transform,compose,transformPosition,transformSelection,isInvertible,makeInvertible(op,doc){return makeInvertible(op,doc,ropeImpl)},stripInvertible,invert,invertWithDoc(op,doc){return invert(makeInvertible(op,doc,ropeImpl))},isNoop:__name(op=>op.length===0,"isNoop")}}__name(makeType,"makeType"),exports3.default=makeType}(type)),type}__name(requireType,"requireType");var api={},hasRequiredApi;function requireApi(){if(hasRequiredApi)return api;hasRequiredApi=1,Object.defineProperty(api,"__esModule",{value:!0});const type_1=requireType(),unicount_1=requireUnicount();function api$1(getSnapshot,submitOp){return{get:getSnapshot,getLength(){return getSnapshot().length},insert(pos,text,callback){const uniPos=unicount_1.strPosToUni(getSnapshot(),pos);return submitOp([uniPos,text],callback)},remove(pos,lengthOrContent,callback){const uniPos=unicount_1.strPosToUni(getSnapshot(),pos);return submitOp([uniPos,{d:lengthOrContent}],callback)},_onOp(op){type_1.eachOp(op,(component,prePos,postPos)=>{switch(typeof component){case"string":this.onInsert&&this.onInsert(postPos,component);break;case"object":const dl=type_1.dlen(component.d);this.onRemove&&this.onRemove(postPos,dl)}})},onInsert:null,onRemove:null}}return __name(api$1,"api$1"),api.default=api$1,api$1.provides={text:!0},api}__name(requireApi,"requireApi");var hasRequiredDist$1;function requireDist$1(){return hasRequiredDist$1||(hasRequiredDist$1=1,function(exports3){var __createBinding=dist.__createBinding||(Object.create?function(o,m,k,k2){k2===void 0&&(k2=k),Object.defineProperty(o,k2,{enumerable:!0,get:__name(function(){return m[k]},"get")})}:function(o,m,k,k2){k2===void 0&&(k2=k),o[k2]=m[k]}),__setModuleDefault=dist.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=dist.__importStar||function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null)for(var k in mod)Object.hasOwnProperty.call(mod,k)&&__createBinding(result,mod,k);return __setModuleDefault(result,mod),result},__importDefault=dist.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports3,"__esModule",{value:!0}),exports3.type=exports3.remove=exports3.insert=void 0;const unicount_1=requireUnicount(),type_1=__importStar(requireType()),api_1=__importDefault(requireApi()),ropeImplUnicodeString={create(s){return s},toString(s){return s},builder(oldDoc){if(typeof oldDoc!="string")throw Error("Invalid document snapshot: "+oldDoc);const newDoc=[];return{skip(n){let offset=unicount_1.uniToStrPos(oldDoc,n);if(offset>oldDoc.length)throw Error("The op is too long for this document");newDoc.push(oldDoc.slice(0,offset)),oldDoc=oldDoc.slice(offset)},append(s){newDoc.push(s)},del(n){oldDoc=oldDoc.slice(unicount_1.uniToStrPos(oldDoc,n))},build(){return newDoc.join("")+oldDoc}}},slice:type_1.uniSlice},textString=type_1.default(ropeImplUnicodeString),type2=Object.assign(Object.assign({},textString),{api:api_1.default});exports3.type=type2,exports3.insert=(pos,text)=>text.length===0?[]:pos===0?[text]:[pos,text],exports3.remove=(pos,textOrLen)=>type_1.dlen(textOrLen)===0?[]:pos===0?[{d:textOrLen}]:[pos,{d:textOrLen}];var type_2=requireType();Object.defineProperty(exports3,"makeType",{enumerable:!0,get:__name(function(){return type_2.default},"get")})}(dist)),dist}__name(requireDist$1,"requireDist$1");var hasRequiredJson1_release;function requireJson1_release(){return hasRequiredJson1_release||(hasRequiredJson1_release=1,function(exports3){var __importDefault=json1_release.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports3,"__esModule",{value:!0}),exports3.editOp=exports3.replaceOp=exports3.insertOp=exports3.moveOp=exports3.removeOp=exports3.type=void 0;const deepEqual_js_1=__importDefault(requireDeepEqual()),deepClone_js_1=__importDefault(requireDeepClone()),cursor_js_1=requireCursor(),types_js_1=requireTypes();function assert(pred,msg){if(!pred)throw new Error(msg)}__name(assert,"assert"),exports3.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:cursor_js_1.readCursor,writeCursor:cursor_js_1.writeCursor,create:__name(data=>data,"create"),isNoop:__name(op=>op==null,"isNoop"),setDebug(val){},registerSubtype,checkValidOp,normalize,apply,transformPosition,compose,tryTransform,transform,makeInvertible,invert,invertWithDoc,RM_UNEXPECTED_CONTENT:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:types_js_1.ConflictType.DROP_COLLISION,BLACKHOLE:types_js_1.ConflictType.BLACKHOLE,transformNoConflict:__name((op1,op2,side)=>transformWithConflictsPred(()=>!0,op1,op2,side),"transformNoConflict"),typeAllowingConflictsPred:__name(allowConflict=>Object.assign(Object.assign({},exports3.type),{transform:__name((op1,op2,side)=>transformWithConflictsPred(allowConflict,op1,op2,side),"transform")}),"typeAllowingConflictsPred")};const getComponent=__name(r=>r?r.getComponent():null,"getComponent");function isObject(o){return o&&typeof o=="object"&&!Array.isArray(o)}__name(isObject,"isObject");const shallowClone=__name(obj=>Array.isArray(obj)?obj.slice():obj!==null&&typeof obj=="object"?Object.assign({},obj):obj,"shallowClone"),hasPick=__name(c=>c&&(c.p!=null||c.r!==void 0),"hasPick"),hasDrop=__name(c=>c&&(c.d!=null||c.i!==void 0),"hasDrop");function removeChild(container,key){return assert(container!=null),typeof key=="number"?(assert(Array.isArray(container),"Invalid key - child is not an array"),(container=container.slice()).splice(key,1)):(assert(isObject(container),"Invalid key - child is not an object"),delete(container=Object.assign({},container))[key]),container}__name(removeChild,"removeChild");function insertChildMut(container,key,value){return typeof key=="number"?(assert(container!=null,"Container is missing for key"),assert(Array.isArray(container),"Cannot use numerical key for object container"),assert(container.length>=key,"Cannot insert into out of bounds index"),container.splice(key,0,value)):(assert(isObject(container),"Cannot insert into missing item"),assert(container[key]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),container[key]=value),value}__name(insertChildMut,"insertChildMut"),exports3.removeOp=(path,value=!0)=>cursor_js_1.writeCursor().writeAtPath(path,"r",value).get(),exports3.moveOp=(from,to)=>cursor_js_1.writeCursor().writeMove(from,to).get(),exports3.insertOp=(path,value)=>cursor_js_1.writeCursor().writeAtPath(path,"i",value).get(),exports3.replaceOp=(path,oldVal,newVal)=>cursor_js_1.writeCursor().at(path,w=>{w.write("r",oldVal),w.write("i",newVal)}).get(),exports3.editOp=(path,type2,subOp,preserveNoop=!1)=>cursor_js_1.writeCursor().at(path,w=>writeEdit(w,type2,subOp,preserveNoop)).get();const isValidKey=__name((container,key)=>container!=null&&(typeof key=="number"?Array.isArray(container):typeof container=="object"),"isValidKey"),maybeGetChild=__name((container,key)=>isValidKey(container,key)?container[key]:void 0,"maybeGetChild"),subtypes={};function registerSubtype(subtype){let _subtype=subtype.type?subtype.type:subtype;_subtype.name&&(subtypes[_subtype.name]=_subtype),_subtype.uri&&(subtypes[_subtype.uri]=_subtype)}__name(registerSubtype,"registerSubtype");const typeOrThrow=__name(name=>{const type2=subtypes[name];if(type2)return type2;throw Error("Missing type: "+name)},"typeOrThrow");registerSubtype(requireDist$1());const add=__name((a,b)=>a+b,"add");registerSubtype({name:"number",apply:add,compose:add,invert:__name(n=>-n,"invert"),transform:__name(a=>a,"transform")});const getEditType=__name(c=>c==null?null:c.et?typeOrThrow(c.et):c.es?subtypes["text-unicode"]:c.ena!=null?subtypes.number:null,"getEditType"),getEdit=__name(c=>c.es?c.es:c.ena!=null?c.ena:c.e,"getEdit"),writeEdit=__name((w,typeOrName,edit,preserveNoop=!1)=>{const[type2,name]=typeof typeOrName=="string"?[typeOrThrow(typeOrName),typeOrName]:[typeOrName,typeOrName.name];!preserveNoop&&type2.isNoop&&type2.isNoop(edit)||(name==="number"?w.write("ena",edit):name==="text-unicode"?w.write("es",edit):(w.write("et",name),w.write("e",edit)))},"writeEdit");function checkNonNegInteger(n){assert(typeof n=="number"),assert(n>=0),assert(n===(0|n))}__name(checkNonNegInteger,"checkNonNegInteger");function checkScalar(s){typeof s=="number"?checkNonNegInteger(s):assert(typeof s=="string")}__name(checkScalar,"checkScalar");function checkValidOp(op){if(op===null)return;const pickedSlots=new Set,droppedSlots=new Set,checkComponent=__name(e=>{let empty=!0,hasEdit=!1;for(let k in e){const v=e[k];if(empty=!1,assert(k==="p"||k==="r"||k==="d"||k==="i"||k==="e"||k==="es"||k==="ena"||k==="et","Invalid component item '"+k+"'"),k==="p")checkNonNegInteger(v),assert(!pickedSlots.has(v)),pickedSlots.add(v),assert(e.r===void 0);else if(k==="d")checkNonNegInteger(v),assert(!droppedSlots.has(v)),droppedSlots.add(v),assert(e.i===void 0);else if(k==="e"||k==="es"||k==="ena"){assert(!hasEdit),hasEdit=!0;const t=getEditType(e);assert(t,"Missing type in edit"),t.checkValidOp&&t.checkValidOp(getEdit(e))}}assert(!empty)},"checkComponent"),checkDescent=__name((descent,isRoot,removed)=>{if(!Array.isArray(descent))throw Error("Op must be null or a list");if(descent.length===0)throw Error("Empty descent");isRoot||checkScalar(descent[0]);let last=1,numDescents=0,lastKey=0;for(let i=0;i<descent.length;i++){const d=descent[i];if(assert(d!=null),Array.isArray(d)){const key=checkDescent(d,!1);if(numDescents){const t1=typeof lastKey,t2=typeof key;t1===t2?assert(lastKey<key,"descent keys are not in order"):assert(t1==="number"&&t2==="string")}lastKey=key,numDescents++,last=3}else typeof d=="object"?(assert(last===1,`Prev not scalar - instead ${last}`),checkComponent(d),last=2):(assert(last!==3),checkScalar(d),assert(cursor_js_1.isValidPathItem(d),"Invalid path key"),last=1)}return assert(numDescents!==1,"Operation makes multiple descents. Remove some []"),assert(last===2||last===3),descent[0]},"checkDescent");checkDescent(op,!0),assert(pickedSlots.size===droppedSlots.size,"Mismatched picks and drops in op");for(let i=0;i<pickedSlots.size;i++)assert(pickedSlots.has(i)),assert(droppedSlots.has(i))}__name(checkValidOp,"checkValidOp");function normalize(op){let nextSlot=0,slotMap=[];const w=cursor_js_1.writeCursor();return w.mergeTree(op,(c,w2)=>{const t=getEditType(c);if(t){const op2=getEdit(c);writeEdit(w2,t,t.normalize?t.normalize(op2):op2)}for(const k of["r","p","i","d"])if(c[k]!==void 0){const r=k==="p"||k==="d"?(inSlot=c[k],slotMap[inSlot]==null&&(slotMap[inSlot]=nextSlot++),slotMap[inSlot]):c[k];w2.write(k,r)}var inSlot}),w.get()}__name(normalize,"normalize");function apply(snapshot,op){if(checkValidOp(op),op===null)return snapshot;const held=[];return __name(function drop(root,descent){let subDoc=root,i=0,rootContainer={root},m=0,container=rootContainer,key="root";function mut(){for(;m<i;m++){let d=descent[m];typeof d!="object"&&(assert(isValidKey(container,key)),container=container[key]=shallowClone(container[key]),key=d)}}for(__name(mut,"mut");i<descent.length;i++){const d=descent[i];if(Array.isArray(d)){const child=drop(subDoc,d);child!==subDoc&&child!==void 0&&(mut(),subDoc=container[key]=child)}else if(typeof d=="object"){d.d!=null?(mut(),subDoc=insertChildMut(container,key,held[d.d])):d.i!==void 0&&(mut(),subDoc=insertChildMut(container,key,d.i));const t=getEditType(d);if(t)mut(),subDoc=container[key]=t.apply(subDoc,getEdit(d));else if(d.e!==void 0)throw Error("Subtype "+d.et+" undefined")}else subDoc=maybeGetChild(subDoc,d)}return rootContainer.root},"drop")(snapshot=__name(function pick(subDoc,descent){const stack=[];let i=0;for(;i<descent.length;i++){const d=descent[i];if(Array.isArray(d))break;typeof d!="object"&&(stack.push(subDoc),subDoc=maybeGetChild(subDoc,d))}for(let j=descent.length-1;j>=i;j--)subDoc=pick(subDoc,descent[j]);for(--i;i>=0;i--){const d=descent[i];if(typeof d!="object"){const container=stack.pop();subDoc=subDoc===maybeGetChild(container,d)?container:subDoc===void 0?removeChild(container,d):(k=d,v=subDoc,(obj=shallowClone(obj=container))[k]=v,obj)}else hasPick(d)&&(assert(subDoc!==void 0,"Cannot pick up or remove undefined"),d.p!=null&&(held[d.p]=subDoc),subDoc=void 0)}var obj,k,v;return subDoc},"pick")(snapshot,op),op)}__name(apply,"apply");function transformPosition(path,op){path=path.slice(),checkValidOp(op);const r=cursor_js_1.readCursor(op);let pickedAtSlot,pickIndex,removed=!1;const advStack=[];for(let i=0;;i++){const k=path[i],c=r.getComponent();if(c&&(c.r!==void 0?removed=!0:c.p!=null&&(removed=!1,pickedAtSlot=c.p,pickIndex=i)),i>=path.length)break;let pickOffset=0;const pickAdv=cursor_js_1.advancer(r,void 0,(k2,c2)=>{hasPick(c2)&&pickOffset++});advStack.unshift(pickAdv);const hasNext=pickAdv(k);if(typeof k=="number"&&(path[i]-=pickOffset),!hasNext)break}if(advStack.forEach(pickAdv=>pickAdv.end()),removed)return null;const handleDrop=__name(()=>{let i=0;if(pickedAtSlot!=null){const rPath=r.getPath();i=rPath.length,path=rPath.concat(path.slice(pickIndex))}for(;i<path.length;i++){const k=path[i],c=getComponent(r),et=getEditType(c);if(et){const e=getEdit(c);et.transformPosition&&(path[i]=et.transformPosition(path[i],e));break}let dropOffset=0;const hasNext=cursor_js_1.advancer(r,(k2,c2)=>hasDrop(c2)?~(k2-dropOffset):k2-dropOffset,(k2,c2)=>{hasDrop(c2)&&dropOffset++})(k);if(typeof k=="number"&&(path[i]+=dropOffset),!hasNext)break}},"handleDrop");return pickedAtSlot!=null?r.eachDrop(null,slot=>{slot===pickedAtSlot&&handleDrop()}):handleDrop(),path}__name(transformPosition,"transformPosition");function compose(op1,op2){if(checkValidOp(op1),checkValidOp(op2),op1==null)return op2;if(op2==null)return op1;let nextSlot=0;const r1=cursor_js_1.readCursor(op1),r2=cursor_js_1.readCursor(op2),w=cursor_js_1.writeCursor(),heldPickWrites=[],heldDropWrites=[],held1Pick=[],held2Drop=[],p1SlotMap=[],p2SlotMap=[],visitedOp2EditCs=new Set;r1.traverse(null,c=>{c.p!=null&&(held1Pick[c.p]=r1.clone())}),r2.traverse(null,c=>{c.d!=null&&(held2Drop[c.d]=r2.clone())});const w2=cursor_js_1.writeCursor();return __name(function xfBoundary(r1Pick,r1Drop,r2Pick,r2Drop,litIn,rmParent,wd,wp){assert(r1Drop||r2Pick);const c1d=getComponent(r1Drop),c2p=getComponent(r2Pick),rmHere=!!c2p&&c2p.r!==void 0,insHere=!!c1d&&c1d.i!==void 0,drop1Slot=c1d?c1d.d:null,pick2Slot=c2p?c2p.p:null,rmChildren=(rmParent||rmHere)&&pick2Slot==null;if(pick2Slot!=null)r2Drop=held2Drop[pick2Slot],wd=heldDropWrites[pick2Slot]=new cursor_js_1.WriteCursor;else if(c2p&&c2p.r!==void 0)r2Drop=null;else{const c2d2=getComponent(r2Drop);c2d2&&c2d2.d!=null&&(r2Drop=null)}const c2d=getComponent(r2Drop);if(drop1Slot!=null)if(r1Pick=held1Pick[drop1Slot],wp=heldPickWrites[drop1Slot]=new cursor_js_1.WriteCursor,rmChildren)rmParent&&!rmHere&&wp.write("r",!0);else{const slot=p1SlotMap[drop1Slot]=nextSlot++;wd.write("d",slot)}else if(c1d&&c1d.i!==void 0)r1Pick=null;else{const c1p=getComponent(r1Pick);c1p&&c1p.p!=null&&(r1Pick=null)}let litOut;insHere?(assert(litIn===void 0),litOut=c1d.i):litOut=litIn;const insComponent=(pick2Slot==null?!insHere||rmParent||rmHere:litOut===void 0)?null:wd.getComponent();if(pick2Slot!=null){if(!(litIn!==void 0||insHere)){const slot=drop1Slot!=null?p1SlotMap[drop1Slot]:nextSlot++;p2SlotMap[pick2Slot]=slot,wp.write("p",slot)}}else rmHere&&(insHere||litIn!==void 0||(c2p.r,wp.write("r",c2p.r)));const type1=rmChildren?null:getEditType(c1d),type2=getEditType(c2d);if((type1||type2)&&(type1&&type1.name,type2&&type2.name),type1&&type2){assert(type1===type2);const e1=getEdit(c1d),e2=getEdit(c2d),r=type1.compose(e1,e2);writeEdit(wd,type1,r),visitedOp2EditCs.add(c2d)}else type1?writeEdit(wd,type1,getEdit(c1d)):type2&&(writeEdit(wd,type2,getEdit(c2d)),visitedOp2EditCs.add(c2d));const hasContainerLiteral=typeof litOut=="object"&&litOut!=null;let isCloned=!1,p1PickOff=0,p1DropOff=0,p2PickOff=0,p2DropOff=0,litOff=0;const p2DropAdv=cursor_js_1.advancer(r2Drop,(k,c)=>hasDrop(c)?p2DropOff-k-1:k-p2DropOff,(k,c)=>{hasDrop(c)&&p2DropOff++}),p1PickAdv=cursor_js_1.advancer(r1Pick,(k,c)=>hasPick(c)?p1PickOff-k-1:k-p1PickOff,(k,c)=>{hasPick(c)&&p1PickOff++});if(cursor_js_1.eachChildOf(r1Drop,r2Pick,(inKey,_p1Drop,_p2Pick)=>{let _p1Pick,_p2Drop,p1PickKey=inKey,p2DropKey=inKey,litKey=inKey;if(typeof inKey=="number"){let p2Mid=inKey+p2PickOff;_p2Drop=p2DropAdv(p2Mid),p2DropKey=p2Mid+p2DropOff;let p1Mid=inKey+p1DropOff;_p1Pick=p1PickAdv(p1Mid),hasDrop(getComponent(_p2Drop))&&(_p1Pick=null),p1PickKey=p1Mid+p1PickOff,litKey=inKey+litOff,assert(p1PickKey>=0,"p1PickKey is negative"),assert(p2DropKey>=0,"p2DropKey is negative");const hd1=hasDrop(getComponent(_p1Drop)),hp2=hasPick(getComponent(_p2Pick));(hd1||hp2&&!rmChildren)&&litOff--,hd1&&p1DropOff--,hp2&&p2PickOff--}else _p1Pick=p1PickAdv(inKey),_p2Drop=p2DropAdv(inKey);wp.descend(p1PickKey),wd.descend(p2DropKey);const _lit=hasContainerLiteral&&!hasDrop(getComponent(_p1Drop))?litOut[litKey]:void 0,_litResult=xfBoundary(_p1Pick,_p1Drop,_p2Pick,_p2Drop,_lit,rmChildren,wd,wp);var container,key,child;hasContainerLiteral&&!rmChildren?_lit!==_litResult&&(isCloned||(litOut=Array.isArray(litOut)?litOut.slice():Object.assign({},litOut),isCloned=!0),container=litOut,child=_litResult,typeof(key=litKey)=="number"?(assert(Array.isArray(container)),assert(key<container.length)):(assert(!Array.isArray(container)),assert(container[key]!==void 0)),child===void 0?typeof key=="number"?container.splice(key,1):delete container[key]:container[key]=child):assert(_litResult===void 0),wd.ascend(),wp.ascend()}),p1PickAdv.end(),p2DropAdv.end(),insComponent!=null)insComponent.i=litOut;else if(!rmParent&&!rmHere&&pick2Slot==null)return litOut},"xfBoundary")(r1,r1.clone(),r2,r2.clone(),void 0,!1,w,w2),w.reset(),w.mergeTree(w2.get()),w.reset(),w.get(),heldPickWrites.map(w3=>w3.get()),heldDropWrites.map(w3=>w3.get()),r1.traverse(w,(c,w3)=>{const slot1=c.p;if(slot1!=null){const slot=p1SlotMap[slot1];slot!=null&&w3.write("p",slot);const _w=heldPickWrites[slot1];_w&&_w.get(),_w&&w3.mergeTree(_w.get())}else c.r!==void 0&&w3.write("r",c.r)}),w.reset(),w.get(),r2.traverse(w,(c,w3)=>{const slot2=c.d;if(slot2!=null){const slot=p2SlotMap[slot2];slot!=null&&w3.write("d",slot);const _w=heldDropWrites[slot2];_w&&w3.mergeTree(_w.get())}else c.i!==void 0&&w3.write("i",c.i);const t=getEditType(c);t&&!visitedOp2EditCs.has(c)&&writeEdit(w3,t,getEdit(c))}),w.get()}__name(compose,"compose");function invert(op){if(op==null)return null;const r=new cursor_js_1.ReadCursor(op),w=new cursor_js_1.WriteCursor;let editsToTransform;const heldPick=[],heldWrites=[];return __name(function invertSimple(r2,w2,subDoc){const c=r2.getComponent();let insertHere,subdocModified=!1;if(c){c.p!=null&&(w2.write("d",c.p),heldPick[c.p]=r2.clone()),c.r!==void 0&&w2.write("i",c.r),c.d!=null&&(w2.write("p",c.d),subDoc=void 0),c.i!==void 0&&(subDoc=insertHere=c.i);const t=getEditType(c);t&&(subDoc===void 0?(editsToTransform||(editsToTransform=new Set),editsToTransform.add(c)):(getEdit(c),subDoc=t.apply(subDoc,getEdit(c)),subdocModified=!0))}let dropOff=0;for(const key of r2){w2.descend(key);const raw=typeof key=="number"?key-dropOff:key,childIn=maybeGetChild(subDoc,raw);hasDrop(r2.getComponent())&&dropOff++;const childOut=invertSimple(r2,w2,childIn);if(subDoc!==void 0&&childOut!==void 0){if(subdocModified||(subdocModified=!0,subDoc=shallowClone(subDoc)),!isValidKey(subDoc,raw))throw Error("Cannot modify child - invalid operation");subDoc[raw]=childOut}w2.ascend()}if(insertHere===void 0)return subdocModified?subDoc:void 0;w2.write("r",subDoc)},"invertSimple")(r,w,void 0),editsToTransform&&(w.reset(),__name(function transformEdits(rPick,rDrop,w2){const cd=rDrop.getComponent();if(cd){const dropSlot=cd.d;if(dropSlot!=null&&(rPick=heldPick[dropSlot],w2=heldWrites[dropSlot]=cursor_js_1.writeCursor()),editsToTransform.has(cd)){const t=getEditType(cd);if(!t.invert)throw Error(`Cannot invert subtype ${t.name}`);writeEdit(w2,t,t.invert(getEdit(cd)))}}let pickOff=0,dropOff=0;const ap=cursor_js_1.advancer(rPick,(k,c)=>hasPick(c)?pickOff-k-1:k-pickOff,(k,c)=>{hasPick(c)&&pickOff++});for(const key of rDrop)if(typeof key=="number"){const mid=key-dropOff,_rPick=ap(mid),raw=mid+pickOff;w2.descend(raw),transformEdits(_rPick,rDrop,w2),hasDrop(rDrop.getComponent())&&dropOff++,w2.ascend()}else w2.descend(key),transformEdits(ap(key),rDrop,w2),w2.ascend();ap.end()},"transformEdits")(r.clone(),r,w),heldWrites.length&&(w.reset(),r.traverse(w,(c,w2)=>{const slot=c.p;if(slot!=null){const _w=heldWrites[slot];_w&&_w.get(),_w&&w2.mergeTree(_w.get())}}))),w.get()}__name(invert,"invert");const anyComponent=__name((op,fn)=>op.some(c=>typeof c=="object"&&(Array.isArray(c)?anyComponent(c,fn):fn(c))),"anyComponent");function makeInvertible(op,doc){if(op==null||!anyComponent(op,c=>{var _a2;return c.r!==void 0||((_a2=getEditType(c))===null||_a2===void 0?void 0:_a2.makeInvertible)!=null}))return op;const r=new cursor_js_1.ReadCursor(op),w=new cursor_js_1.WriteCursor;let hasEdits=!1;const heldPick=[],heldDoc=[],traversePick=__name((r2,w2,subDoc)=>{const c=r2.getComponent();let modified=!1;if(c){c.d!=null&&w2.write("d",c.d),c.i!==void 0&&w2.write("i",c.i);const pickSlot=c.p;if(pickSlot!=null&&(heldPick[pickSlot]=r2.clone(),assert(subDoc!==void 0,"Operation picks up at an invalid key"),heldDoc[pickSlot]=subDoc,w2.write("p",c.p)),c.r!==void 0&&subDoc===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const t=getEditType(c);t&&(t.makeInvertible?hasEdits=!0:writeEdit(w2,t,getEdit(c),!0))}let listOff=0;for(const key of r2){w2.descend(key);const keyRaw=typeof key=="number"?key-listOff:key,childIn=maybeGetChild(subDoc,keyRaw),childOut=traversePick(r2,w2,childIn);childIn!==childOut&&(modified||(modified=!0,subDoc=shallowClone(subDoc)),childOut===void 0?(subDoc=removeChild(subDoc,keyRaw),typeof key=="number"&&listOff++):subDoc[keyRaw]=childOut),w2.ascend()}return c&&(c.r!==void 0?(w2.write("r",deepClone_js_1.default(subDoc)),subDoc=void 0):c.p!=null&&(subDoc=void 0)),subDoc},"traversePick");return traversePick(r,w,doc),w.get(),hasEdits&&(w.reset(),__name(function traverseDrop(rPick,rDrop,w2,subDoc,isLiteral){const c=rDrop.getComponent();if(c){c.i!==void 0?(subDoc=c.i,isLiteral=!0):c.d!=null&&(subDoc=heldDoc[c.d],rPick=heldPick[c.d],isLiteral=!1,c.d);let t=getEditType(c);if(t&&t.makeInvertible){const edit=getEdit(c);writeEdit(w2,t,t.makeInvertible(edit,subDoc),!0)}}let pickOff=0,dropOff=0;const ap=cursor_js_1.advancer(rPick,(k,c2)=>hasPick(c2)?pickOff-k-1:k-pickOff,(k,c2)=>{hasPick(c2)&&pickOff++});for(const key of rDrop)if(typeof key=="number"){const mid=key-dropOff,_rPick=ap(mid),raw=mid+pickOff,child=maybeGetChild(subDoc,isLiteral?mid:raw);w2.descend(key),traverseDrop(_rPick,rDrop,w2,child,isLiteral),hasDrop(rDrop.getComponent())&&dropOff++,w2.ascend()}else{const child=maybeGetChild(subDoc,key);w2.descend(key),traverseDrop(ap(key),rDrop,w2,child,isLiteral),w2.ascend()}ap.end()},"traverseDrop")(r.clone(),r,w,doc,!1)),w.get()}__name(makeInvertible,"makeInvertible");function invertWithDoc(op,doc){return invert(makeInvertible(op,doc))}__name(invertWithDoc,"invertWithDoc");const shallowCloneOp=__name(op=>{if(op==null)return null;const result=op.slice();for(let i=0;i<op.length;i++){const c=result[i];Array.isArray(c)&&(result[i]=shallowCloneOp(c))}return result},"shallowCloneOp");function tryTransform(op1,op2,direction){assert(direction==="left"||direction==="right","Direction must be left or right");const side=direction==="left"?0:1;if(op2==null)return{ok:!0,result:op1};checkValidOp(op1),checkValidOp(op2);let conflict=null;const heldOp1PickByOp1=[],heldOp1DropByOp1=[],heldOp2PickByOp2=[],heldOp2DropByOp2=[],heldOp1PickByOp2=[],heldOp2PickByOp1=[],heldOp2DropByOp1=[],heldOp2RmForOp1=[],heldOp1RmForOp2=[],cancelledOp2=[],discardedOp2Drop=[],heldPickWrites=[],heldDropWrites=[],op1PickAtOp2Pick=[],op1PicksOp2DropSlots=[];let nextSlot=0;const r1=cursor_js_1.readCursor(op1),r2=cursor_js_1.readCursor(op2),w=cursor_js_1.writeCursor();if(__name(function scanOp2Pick(r2Pick,r1Pick=null,removed1){const c1=getComponent(r1Pick);c1&&(c1.r!==void 0?removed1=r1Pick.clone():c1.p!=null&&(removed1=null,heldOp2PickByOp1[c1.p]=r2Pick.clone()));const c2=r2Pick.getComponent();let slot2;c2&&(slot2=c2.p)!=null&&(heldOp1PickByOp2[slot2]=r1Pick?r1Pick.clone():null,heldOp2PickByOp2[slot2]=r2Pick.clone(),removed1&&(cancelledOp2[slot2]=!0,heldOp1RmForOp2[slot2]=removed1),c1&&c1.p!=null&&(op1PickAtOp2Pick[slot2]=c1.p));const ap1=cursor_js_1.advancer(r1Pick);for(const key of r2Pick)scanOp2Pick(r2Pick,ap1(key),removed1);ap1.end()},"scanOp2Pick")(r2,r1,null),__name(function scanOp2Drop(r1Pick,r2Pick,r2Drop,pickSlot1,removed1){const c2d=r2Drop.getComponent();let slot2,droppedHere=!1;c2d&&((slot2=c2d.d)!=null?(heldOp2DropByOp2[slot2]=r2Drop.clone(),pickSlot1!=null&&(op1PicksOp2DropSlots[pickSlot1]==null&&(op1PicksOp2DropSlots[pickSlot1]=[]),op1PicksOp2DropSlots[pickSlot1].push(slot2)),cancelledOp2[slot2],r1Pick=heldOp1PickByOp2[slot2]||null,r2Pick=heldOp2PickByOp2[slot2]||null,cancelledOp2[slot2]?(removed1&&(discardedOp2Drop[slot2]=!0),removed1=heldOp1RmForOp2[slot2]||null):!removed1||side!==1&&op1PickAtOp2Pick[slot2]!=null||conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:exports3.removeOp(removed1.getPath()),op2:exports3.moveOp(r2Pick.getPath(),r2Drop.getPath())}),droppedHere=!0):c2d.i!==void 0&&(r1Pick=r2Pick=null,droppedHere=!0,removed1&&conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:exports3.removeOp(removed1.getPath()),op2:exports3.insertOp(r2Drop.getPath(),c2d.i)})));const c1p=getComponent(r1Pick);c1p&&(c1p.r!==void 0?removed1=r1Pick.clone():c1p.p!=null&&(c1p.p,pickSlot1=c1p.p,removed1=null));const t2=getEditType(c2d);t2&&removed1&&conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:exports3.removeOp(removed1.getPath()),op2:exports3.editOp(r2Drop.getPath(),t2,getEdit(c2d),!0)});let p2PickOff=0,p2DropOff=0;const ap2=cursor_js_1.advancer(r2Pick,(k,c)=>hasPick(c)?p2PickOff-k-1:k-p2PickOff,(k,c)=>{hasPick(c)&&p2PickOff++}),ap1=cursor_js_1.advancer(r1Pick);for(const key of r2Drop)if(typeof key=="number"){const p2Mid=key-p2DropOff,_p2Pick=ap2(p2Mid);p2DropOff+=+scanOp2Drop(ap1(p2Mid+p2PickOff),_p2Pick,r2Drop,pickSlot1,removed1)}else{const _p2Pick=ap2(key);scanOp2Drop(ap1(key),_p2Pick,r2Drop,pickSlot1,removed1)}return ap2.end(),ap1.end(),droppedHere},"scanOp2Drop")(r1,r2,r2.clone(),null,null),heldOp2DropByOp2.map(x=>x&&x.get()),conflict)return{ok:!1,conflict};discardedOp2Drop.map(x=>!!x);const pickComponents=[];let cancelledRemoves=null;__name(function writeOp1Pick(r1Pick,r2Pick,r2Drop,w2,removed2){let iAmMoved=!1;const c2p=getComponent(r2Pick);if(hasPick(c2p)){const slot2=c2p.p;slot2!=null?(r2Drop=heldOp2DropByOp2[slot2],w2=heldPickWrites[slot2]=cursor_js_1.writeCursor(),iAmMoved=!0,removed2=null):(r2Drop=null,removed2=r2Pick.clone())}else hasDrop(getComponent(r2Drop))&&(r2Drop=null);const c1=r1Pick.getComponent();if(c1){const slot1=c1.p;slot1!=null?(removed2&&(heldOp2RmForOp1[slot1]=removed2),pickComponents[slot1]=removed2||side===1&&iAmMoved?null:w2.getComponent(),heldOp1PickByOp1[slot1]=r1Pick.clone(),r2Drop&&(heldOp2DropByOp1[slot1]=r2Drop.clone())):c1.r!==void 0&&(removed2||w2.write("r",!0),(removed2||iAmMoved)&&(cancelledRemoves==null&&(cancelledRemoves=new Set),cancelledRemoves.add(c1)))}let p2PickOff=0,p2DropOff=0;const ap2Pick=cursor_js_1.advancer(r2Pick,void 0,(k,c)=>{hasPick(c)&&p2PickOff++}),ap2Drop=cursor_js_1.advancer(r2Drop,(k,c)=>hasDrop(c)?~(k-p2DropOff):k-p2DropOff,(k,c)=>{hasDrop(c)&&p2DropOff++});if(r1Pick)for(const key of r1Pick)if(typeof key=="string"){const p2Pick_=ap2Pick(key),p2Drop_=ap2Drop(key);w2.descend(key),writeOp1Pick(r1Pick,p2Pick_,p2Drop_,w2,removed2),w2.ascend()}else{const p2Pick_=ap2Pick(key),p2Mid=key-p2PickOff,p2Drop_=hasPick(getComponent(p2Pick_))?null:ap2Drop(p2Mid),finalKey=p2Mid+p2DropOff;assert(finalKey>=0),w2.descend(finalKey),writeOp1Pick(r1Pick,p2Pick_,p2Drop_,w2,removed2),w2.ascend()}ap2Pick.end(),ap2Drop.end()},"writeOp1Pick")(r1,r2,r2.clone(),w,null),w.reset();let outputSlotMap=[];if(__name(function writeOp1Drop(p1Pick,p1Drop,p2Pick,p2Drop,w2,removed2){assert(p1Drop);const c1d=p1Drop.getComponent();let c2d=getComponent(p2Drop),droppedHere=!1;const insOrMv=__name((r12,r22,c)=>r12?exports3.moveOp(r12.getPath(),r22.getPath()):exports3.insertOp(r22.getPath(),c.i),"insOrMv");if(hasDrop(c1d)){const slot1=c1d.d;slot1!=null&&(heldOp1DropByOp1[slot1]=p1Drop.clone());const pc=slot1!=null?pickComponents[slot1]:null;let identical=!1;if(c1d.i!==void 0||slot1!=null&&pc){let slot2;c2d&&(c2d.i!==void 0||(slot2=c2d.d)!=null&&!cancelledOp2[slot2])&&(identical=slot2!=null?slot1!=null&&slot1===op1PickAtOp2Pick[slot2]:deepEqual_js_1.default(c2d.i,c1d.i),identical||slot2!=null&&side!==1&&op1PickAtOp2Pick[slot2]!=null||conflict==null&&(conflict={type:types_js_1.ConflictType.DROP_COLLISION,op1:insOrMv(slot1!=null?heldOp1PickByOp1[slot1]:null,p1Drop,c1d),op2:insOrMv(slot2!=null?heldOp2PickByOp2[slot2]:null,p2Drop,c2d)})),identical||(removed2?conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:insOrMv(slot1!=null?heldOp1PickByOp1[slot1]:null,p1Drop,c1d),op2:exports3.removeOp(removed2.getPath())}):(slot1!=null?(outputSlotMap[nextSlot]=slot1,w2.write("d",pc.p=nextSlot++)):w2.write("i",deepClone_js_1.default(c1d.i)),droppedHere=!0))}else if(slot1!=null&&!pc){const h=heldOp2RmForOp1[slot1];h&&(removed2=h.clone())}slot1!=null?(p1Pick=heldOp1PickByOp1[slot1],p2Pick=heldOp2PickByOp1[slot1],p2Drop=heldOp2DropByOp1[slot1]):c1d.i!==void 0&&(p1Pick=p2Pick=null,identical||(p2Drop=null))}else hasPick(getComponent(p1Pick))&&(p1Pick=p2Pick=p2Drop=null);const c1p=getComponent(p1Pick),c2p=getComponent(p2Pick);if(hasPick(c2p)){const slot2=c2p.p;c2p.r!==void 0&&(!c1p||c1p.r===void 0)||cancelledOp2[slot2]?(p2Drop=null,removed2=p2Pick.clone()):slot2!=null&&(p2Drop=heldOp2DropByOp2[slot2],side!==1&&op1PickAtOp2Pick[slot2]!=null||((w2=heldDropWrites[slot2])||(w2=heldDropWrites[slot2]=cursor_js_1.writeCursor()),w2.reset(),removed2=null))}else!hasDrop(c1d)&&hasDrop(c2d)&&(p2Drop=null);c2d=p2Drop!=null?p2Drop.getComponent():null;const t1=getEditType(c1d);if(t1){const e1=getEdit(c1d);if(removed2)conflict==null&&(conflict={type:types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,op1:exports3.editOp(p1Drop.getPath(),t1,e1,!0),op2:exports3.removeOp(removed2.getPath())});else{const t2=getEditType(c2d);let e;if(t2){if(t1!==t2)throw Error("Transforming incompatible types");const e2=getEdit(c2d);e=t1.transform(e1,e2,direction)}else e=deepClone_js_1.default(e1);writeEdit(w2,t1,e)}}let p1PickOff=0,p1DropOff=0,p2PickOff=0,p2DropOff=0,outPickOff=0,outDropOff=0,p1pValid=p1Pick!=null&&p1Pick.descendFirst(),p1pDidDescend=p1pValid;const ap2p=cursor_js_1.advancer(p2Pick,void 0,(k,c)=>{hasPick(c)&&p2PickOff++});let p2dValid=p2Drop!=null&&p2Drop.descendFirst(),p2dDidDescend=p2dValid;for(const key of p1Drop)if(typeof key=="number"){let _p1Pick;const hd1=hasDrop(p1Drop.getComponent()),k1Mid=key-p1DropOff;{let p1k;for(;p1pValid&&typeof(p1k=p1Pick.getKey())=="number";){p1k+=p1PickOff;const c=p1Pick.getComponent(),hp=hasPick(c);if(p1k>k1Mid||p1k===k1Mid&&(!hp||side===0&&hd1))break;if(hp){p1PickOff--;const slot1=c.p;op1PickAtOp2Pick.includes(slot1),c.d,getComponent(heldDropWrites[c.d]),hasPick(getComponent(heldDropWrites[c.d])),(c.r===void 0||cancelledRemoves&&cancelledRemoves.has(c))&&(slot1==null||!pickComponents[slot1]||side!==1&&op1PickAtOp2Pick.includes(slot1))||outPickOff--}p1pValid=p1Pick.nextSibling()}_p1Pick=p1pValid&&p1k===k1Mid?p1Pick:null}const raw=k1Mid-p1PickOff;let _p2Pick=ap2p(raw);const k2Mid=raw-p2PickOff;let _p2Drop=null;{let p2dk,op2Mid;for(;p2dValid&&typeof(p2dk=p2Drop.getKey())=="number";){op2Mid=p2dk-p2DropOff;const c=p2Drop.getComponent(),hd2=hasDrop(c);if(op2Mid>k2Mid)break;if(op2Mid===k2Mid){if(!hd2){_p2Drop=p2Drop;break}{if(side===0&&hd1){_p2Drop=p2Drop;break}const hp2=_p2Pick&&hasPick(_p2Pick.getComponent());if(side===0&&hp2)break}}if(hd2){const slot2=c.d;cancelledOp2[slot2],op1PickAtOp2Pick[slot2],c.i===void 0&&(cancelledOp2[slot2]||op1PickAtOp2Pick[slot2]!=null&&side!==1)?(cancelledOp2[slot2]||op1PickAtOp2Pick[slot2]!=null&&side===0)&&(p2DropOff++,outDropOff--):p2DropOff++}p2dValid=p2Drop.nextSibling()}}const descend=k2Mid+p2DropOff+outPickOff+outDropOff;assert(descend>=0,"trying to descend to a negative index"),w2.descend(descend),hd1&&(_p1Pick=_p2Pick=_p2Drop=null,p1DropOff++),writeOp1Drop(_p1Pick,p1Drop,_p2Pick,_p2Drop,w2,removed2)&&outDropOff++,w2.ascend()}else{let p1k;for(;p1pValid&&(p1k=p1Pick.getKey(),typeof p1k!="string"||!(p1k>key||p1k===key));)p1pValid=p1Pick.nextSibling();const _p1Pick=p1pValid&&p1k===key?p1Pick:null,_p2Pick=ap2p(key);let p2dk;for(;p2dValid&&(p2dk=p2Drop.getKey(),typeof p2dk!="string"||!(p2dk>key||p2dk===key));)p2dValid=p2Drop.nextSibling();const _p2Drop=p2dValid&&p2dk===key?p2Drop:null;w2.descend(key),writeOp1Drop(_p1Pick,p1Drop,_p2Pick,_p2Drop,w2,removed2),w2.ascend()}return ap2p.end(),p1pDidDescend&&p1Pick.ascend(),p2dDidDescend&&p2Drop.ascend(),droppedHere},"writeOp1Drop")(r1,r1.clone(),r2,r2.clone(),w,null),conflict)return{ok:!1,conflict};w.reset();const eachDrop=__name((r,w2,fn)=>r.traverse(w2,(c,w3)=>{c.d!=null&&fn(c.d,r,w3)}),"eachDrop");(cancelledOp2.length||heldPickWrites.length)&&(eachDrop(r2,w,(slot2,r,w2)=>{cancelledOp2[slot2]&&!discardedOp2Drop[slot2]&&w2.write("r",!0),heldPickWrites[slot2]&&w2.mergeTree(heldPickWrites[slot2].get())}),w.reset());const heldOutDropRead=[],heldOutDropWrites=[];if((heldDropWrites.length||cancelledOp2.length)&&!conflict){const rOut=cursor_js_1.readCursor(shallowCloneOp(w.get()));if(eachDrop(rOut,null,(slotOut,r)=>{heldOutDropRead[slotOut]=r.clone()}),heldDropWrites.forEach(hdw=>{hdw&&eachDrop(cursor_js_1.readCursor(hdw.get()),null,(slotOut,r)=>{heldOutDropRead[slotOut]=r.clone()})}),__name(function writeHeldOp2Drop(p2Drop,outPick,outDrop,w2,parentC,removedOut){const coutp=getComponent(outPick);if(coutp&&hasPick(coutp))if(coutp.p!=null){const slot=coutp.p;heldOutDropRead[slot].getPath(),outDrop=heldOutDropRead[slot],w2=heldOutDropWrites[slot]=cursor_js_1.writeCursor()}else coutp.r!==void 0&&(outDrop=null);else hasDrop(getComponent(outDrop))&&(outDrop=null);const c2=p2Drop.getComponent();if(c2){let slot2;if((slot2=c2.d)!=null){const _w=heldDropWrites[slot2];_w&&(_w.get(),w2.mergeTree(_w.get()),outDrop=cursor_js_1.readCursor(_w.get()))}}let outPickOff=0,outDropOff=0;const oPickAdv=cursor_js_1.advancer(outPick,void 0,(k,c)=>{hasPick(c)&&outPickOff--}),oDropAdv=cursor_js_1.advancer(outDrop,(k,c)=>hasDrop(c)?-(k-outDropOff)-1:k-outDropOff,(k,c)=>{hasDrop(c)&&outDropOff++});for(const o2dk of p2Drop)if(typeof o2dk=="number"){const _outPick=oPickAdv(o2dk),rmid=o2dk+outPickOff,_outDrop=oDropAdv(rmid),rfinal=rmid+outDropOff;w2.descend(rfinal),writeHeldOp2Drop(p2Drop,_outPick,_outDrop,w2),w2.ascend()}else w2.descend(o2dk),writeHeldOp2Drop(p2Drop,oPickAdv(o2dk),oDropAdv(o2dk),w2),w2.ascend();oPickAdv.end(),oDropAdv.end()},"writeHeldOp2Drop")(r2,rOut,rOut.clone(),w),w.reset(),conflict)return{ok:!1,conflict};if(w.get(),heldOutDropWrites.length){const heldOutDropContent=heldOutDropWrites.map(w2=>w2?w2.get():null),rOut2=cursor_js_1.readCursor(shallowCloneOp(w.get()));if(eachDrop(rOut2,w,(slotOut,r,w2)=>{const data=heldOutDropContent[slotOut];data&&(w2.mergeTree(data),heldOutDropContent[slotOut]=null)}),heldOutDropContent.find(x=>x)){const w1=cursor_js_1.writeCursor(),w2=cursor_js_1.writeCursor();let nextSlot1=0,nextSlot2=0;heldOutDropContent.forEach(data=>{data!=null&&eachDrop(cursor_js_1.readCursor(data),null,c=>{const slot1=outputSlotMap[c];w1.writeMove(heldOp1PickByOp1[slot1].getPath(),heldOp1DropByOp1[slot1].getPath(),nextSlot1++);const slot2s=op1PicksOp2DropSlots[slot1];slot2s&&slot2s.forEach(slot2=>{cancelledOp2[slot2]||side!==1&&op1PickAtOp2Pick[slot2]!=null||w2.writeMove(heldOp2PickByOp2[slot2].getPath(),heldOp2DropByOp2[slot2].getPath(),nextSlot2++)})})}),conflict={type:types_js_1.ConflictType.BLACKHOLE,op1:w1.get(),op2:w2.get()}}}}return conflict?{ok:!1,conflict}:{ok:!0,result:w.get()}}__name(tryTransform,"tryTransform");const throwConflictErr=__name(conflict=>{const err=new Error("Transform detected write conflict");throw err.conflict=conflict,err.type=err.name="writeConflict",err},"throwConflictErr");function transform(op1,op2,side){const res=tryTransform(op1,op2,side);if(res.ok)return res.result;throwConflictErr(res.conflict)}__name(transform,"transform");const opThatRemovesDE=__name(op=>{const w=cursor_js_1.writeCursor();return cursor_js_1.readCursor(op).traverse(w,(c,w2)=>{(hasDrop(c)||getEditType(c))&&w2.write("r",!0)}),w.get()},"opThatRemovesDE"),resolveConflict=__name((conflict,side)=>{const{type:type2,op1,op2}=conflict;switch(type2){case types_js_1.ConflictType.DROP_COLLISION:return side==="left"?[null,opThatRemovesDE(op2)]:[opThatRemovesDE(op1),null];case types_js_1.ConflictType.RM_UNEXPECTED_CONTENT:let op1HasRemove=!1;return cursor_js_1.readCursor(op1).traverse(null,c=>{c.r!==void 0&&(op1HasRemove=!0)}),op1HasRemove?[null,opThatRemovesDE(op2)]:[opThatRemovesDE(op1),null];case types_js_1.ConflictType.BLACKHOLE:return[opThatRemovesDE(op1),opThatRemovesDE(op2)];default:throw Error("Unrecognised conflict: "+type2)}},"resolveConflict");function transformWithConflictsPred(allowConflict,op1,op2,side){let r2Aggregate=null;for(;;){const res=tryTransform(op1,op2,side);if(res.ok)return compose(r2Aggregate,res.result);{const{conflict}=res;allowConflict(conflict)||throwConflictErr(conflict);const[r1,r2]=resolveConflict(conflict,side);op1=compose(normalize(op1),r1),op2=compose(normalize(op2),r2),r2Aggregate=compose(r2Aggregate,r2)}}}__name(transformWithConflictsPred,"transformWithConflictsPred")}(json1_release)),json1_release}__name(requireJson1_release,"requireJson1_release");var hasRequiredDist;function requireDist(){return hasRequiredDist||(hasRequiredDist=1,function(exports3){var __createBinding=dist$1.__createBinding||(Object.create?function(o,m,k,k2){k2===void 0&&(k2=k),Object.defineProperty(o,k2,{enumerable:!0,get:__name(function(){return m[k]},"get")})}:function(o,m,k,k2){k2===void 0&&(k2=k),o[k2]=m[k]}),__exportStar=dist$1.__exportStar||function(m,exports4){for(var p in m)p!=="default"&&!exports4.hasOwnProperty(p)&&__createBinding(exports4,m,p)};Object.defineProperty(exports3,"__esModule",{value:!0}),__exportStar(requireJson1_release(),exports3);var cursor_js_1=requireCursor();Object.defineProperty(exports3,"ReadCursor",{enumerable:!0,get:__name(function(){return cursor_js_1.ReadCursor},"get")}),Object.defineProperty(exports3,"WriteCursor",{enumerable:!0,get:__name(function(){return cursor_js_1.WriteCursor},"get")});var types_1=requireTypes();Object.defineProperty(exports3,"ConflictType",{enumerable:!0,get:__name(function(){return types_1.ConflictType},"get")})}(dist$1)),dist$1}__name(requireDist,"requireDist");var distExports=requireDist();const _UnitDrawingService=class _UnitDrawingService{constructor(){__publicField(this,"drawingManagerData",{});__publicField(this,"_oldDrawingManagerData",{});__publicField(this,"_focusDrawings",[]);__publicField(this,"_remove$",new rxjs.Subject);__publicField(this,"remove$",this._remove$.asObservable());__publicField(this,"_add$",new rxjs.Subject);__publicField(this,"add$",this._add$.asObservable());__publicField(this,"_update$",new rxjs.Subject);__publicField(this,"update$",this._update$.asObservable());__publicField(this,"_order$",new rxjs.Subject);__publicField(this,"order$",this._order$.asObservable());__publicField(this,"_group$",new rxjs.Subject);__publicField(this,"group$",this._group$.asObservable());__publicField(this,"_ungroup$",new rxjs.Subject);__publicField(this,"ungroup$",this._ungroup$.asObservable());__publicField(this,"_refreshTransform$",new rxjs.Subject);__publicField(this,"refreshTransform$",this._refreshTransform$.asObservable());__publicField(this,"_visible$",new rxjs.Subject);__publicField(this,"visible$",this._visible$.asObservable());__publicField(this,"_focus$",new rxjs.Subject);__publicField(this,"focus$",this._focus$.asObservable());__publicField(this,"_featurePluginUpdate$",new rxjs.Subject);__publicField(this,"featurePluginUpdate$",this._featurePluginUpdate$.asObservable());__publicField(this,"_featurePluginAdd$",new rxjs.Subject);__publicField(this,"featurePluginAdd$",this._featurePluginAdd$.asObservable());__publicField(this,"_featurePluginRemove$",new rxjs.Subject);__publicField(this,"featurePluginRemove$",this._featurePluginRemove$.asObservable());__publicField(this,"_featurePluginOrderUpdate$",new rxjs.Subject);__publicField(this,"featurePluginOrderUpdate$",this._featurePluginOrderUpdate$.asObservable());__publicField(this,"_featurePluginGroupUpdate$",new rxjs.Subject);__publicField(this,"featurePluginGroupUpdate$",this._featurePluginGroupUpdate$.asObservable());__publicField(this,"_featurePluginUngroupUpdate$",new rxjs.Subject);__publicField(this,"featurePluginUngroupUpdate$",this._featurePluginUngroupUpdate$.asObservable());__publicField(this,"_visible",!0);__publicField(this,"_editable",!0)}dispose(){this._remove$.complete(),this._add$.complete(),this._update$.complete(),this._order$.complete(),this._focus$.complete(),this._featurePluginUpdate$.complete(),this._featurePluginAdd$.complete(),this._featurePluginRemove$.complete(),this._featurePluginOrderUpdate$.complete(),this.drawingManagerData={},this._oldDrawingManagerData={}}visibleNotification(visibleParams){this._visible$.next(visibleParams)}refreshTransform(updateParams){updateParams.forEach(updateParam=>{const param=this._getCurrentBySearch(updateParam);param!=null&&(param.transform=updateParam.transform,param.transforms=updateParam.transforms,param.isMultiTransform=updateParam.isMultiTransform)}),this.refreshTransformNotification(updateParams)}getDrawingDataForUnit(unitId){return this.drawingManagerData[unitId]||{}}removeDrawingDataForUnit(unitId){const subUnits=this.drawingManagerData[unitId];if(subUnits==null)return;delete this.drawingManagerData[unitId];const drawings=[];Object.keys(subUnits).forEach(subUnitId=>{const subUnit=subUnits[subUnitId];(subUnit==null?void 0:subUnit.data)!=null&&Object.keys(subUnit.data).forEach(drawingId=>{drawings.push({unitId,subUnitId,drawingId})})}),drawings.length>0&&this.removeNotification(drawings)}registerDrawingData(unitId,data){this.drawingManagerData[unitId]=data}initializeNotification(unitId){const drawings=[],data=this.drawingManagerData[unitId];data!=null&&(Object.keys(data).forEach(subUnitId=>{this._establishDrawingMap(unitId,subUnitId);const subUnitData=data[subUnitId];Object.keys(subUnitData.data).forEach(drawingId=>{const drawing=subUnitData.data[drawingId];drawing.unitId=unitId,drawing.subUnitId=subUnitId,drawings.push(drawing)})}),drawings.length>0&&this.addNotification(drawings))}getDrawingData(unitId,subUnitId){return this._getDrawingData(unitId,subUnitId)}setDrawingData(unitId,subUnitId,data){this.drawingManagerData[unitId][subUnitId].data=data}getBatchAddOp(insertParams){const objects=[],ops=[],invertOps=[];insertParams.forEach(insertParam=>{const{op:op2,invertOp:invertOp2}=this._addByParam(insertParam);objects.push({unitId:insertParam.unitId,subUnitId:insertParam.subUnitId,drawingId:insertParam.drawingId}),ops.push(op2),invertOps.push(invertOp2)});const op=ops.reduce(distExports.type.compose,null),invertOp=invertOps.reduce(distExports.type.compose,null),{unitId,subUnitId}=insertParams[0];return{undo:invertOp,redo:op,unitId,subUnitId,objects}}getBatchRemoveOp(removeParams){const ops=[],invertOps=[];removeParams.forEach(removeParam=>{const{op:op2,invertOp:invertOp2}=this._removeByParam(removeParam);ops.unshift(op2),invertOps.push(invertOp2)});const op=ops.reduce(distExports.type.compose,null),invertOp=invertOps.reduce(distExports.type.compose,null),{unitId,subUnitId}=removeParams[0];return{undo:invertOp,redo:op,unitId,subUnitId,objects:removeParams}}getBatchUpdateOp(updateParams){const objects=[],ops=[],invertOps=[];updateParams.forEach(updateParam=>{const{op:op2,invertOp:invertOp2}=this._updateByParam(updateParam);objects.push({unitId:updateParam.unitId,subUnitId:updateParam.subUnitId,drawingId:updateParam.drawingId}),ops.push(op2),invertOps.push(invertOp2)});const op=ops.reduce(distExports.type.compose,null),invertOp=invertOps.reduce(distExports.type.compose,null),{unitId,subUnitId}=updateParams[0];return{undo:invertOp,redo:op,unitId,subUnitId,objects}}removeNotification(removeParams){this._remove$.next(removeParams)}addNotification(insertParams){this._add$.next(insertParams)}updateNotification(updateParams){this._update$.next(updateParams)}orderNotification(orderParams){this._order$.next(orderParams)}groupUpdateNotification(groupParams){this._group$.next(groupParams)}ungroupUpdateNotification(groupParams){this._ungroup$.next(groupParams)}refreshTransformNotification(refreshParams){this._refreshTransform$.next(refreshParams)}getGroupDrawingOp(groupParams){const ops=[],{unitId,subUnitId}=groupParams[0].parent;groupParams.forEach(groupParam=>{ops.push(this._getGroupDrawingOp(groupParam))});const op=ops.reduce(distExports.type.compose,null);return{undo:distExports.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:groupParams}}getUngroupDrawingOp(groupParams){const ops=[],{unitId,subUnitId}=groupParams[0].parent;groupParams.forEach(groupParam=>{ops.push(this._getUngroupDrawingOp(groupParam))});const op=ops.reduce(distExports.type.compose,null);return{undo:distExports.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:groupParams}}getDrawingsByGroup(groupParam){const{unitId,subUnitId,drawingId}=groupParam;if(this.getDrawingByParam({unitId,subUnitId,drawingId})==null)return[];const drawings=this._getDrawingData(unitId,subUnitId),children=[];return Object.keys(drawings).forEach(key=>{const drawing=drawings[key];drawing.groupId===drawingId&&children.push(drawing)}),children}_getGroupDrawingOp(groupParam){const{parent,children}=groupParam,{unitId:groupUnitId,subUnitId:groupSubUnitId,drawingId:groupDrawingId}=parent,ops=[];ops.push(distExports.insertOp([groupUnitId,groupSubUnitId,"data",groupDrawingId],parent));let maxChildIndex=Number.NEGATIVE_INFINITY;return children.forEach(child=>{const{unitId,subUnitId,drawingId}=child,index=this._hasDrawingOrder({unitId,subUnitId,drawingId});maxChildIndex=Math.max(maxChildIndex,index),ops.push(...this._getUpdateParamCompareOp(child,this.getDrawingByParam({unitId,subUnitId,drawingId})))}),maxChildIndex===Number.NEGATIVE_INFINITY&&(maxChildIndex=this._getDrawingOrder(groupUnitId,groupSubUnitId).length),ops.push(distExports.insertOp([groupUnitId,groupSubUnitId,"order",maxChildIndex],groupDrawingId)),ops.reduce(distExports.type.compose,null)}_getUngroupDrawingOp(groupParam){const{parent,children}=groupParam,{unitId:groupUnitId,subUnitId:groupSubUnitId,drawingId:groupDrawingId}=parent,ops=[];return children.forEach(child=>{const{unitId,subUnitId,drawingId}=child;ops.push(...this._getUpdateParamCompareOp(child,this.getDrawingByParam({unitId,subUnitId,drawingId})))}),ops.push(distExports.removeOp([groupUnitId,groupSubUnitId,"data",groupDrawingId],!0)),ops.push(distExports.removeOp([groupUnitId,groupSubUnitId,"order",this._getDrawingOrder(groupUnitId,groupSubUnitId).indexOf(groupDrawingId)],!0)),ops.reduce(distExports.type.compose,null)}applyJson1(unitId,subUnitId,jsonOp){this._establishDrawingMap(unitId,subUnitId),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=distExports.type.apply(this.drawingManagerData,jsonOp)}featurePluginUpdateNotification(updateParams){this._featurePluginUpdate$.next(updateParams)}featurePluginOrderUpdateNotification(drawingOrderUpdateParam){this._featurePluginOrderUpdate$.next(drawingOrderUpdateParam)}featurePluginAddNotification(insertParams){this._featurePluginAdd$.next(insertParams)}featurePluginRemoveNotification(removeParams){this._featurePluginRemove$.next(removeParams)}featurePluginGroupUpdateNotification(groupParams){this._featurePluginGroupUpdate$.next(groupParams)}featurePluginUngroupUpdateNotification(groupParams){this._featurePluginUngroupUpdate$.next(groupParams)}getDrawingByParam(param){return this._getCurrentBySearch(param)}getOldDrawingByParam(param){return this._getOldBySearch(param)}getDrawingOKey(oKey){const[unitId,subUnitId,drawingId]=oKey.split("#-#");return this._getCurrentBySearch({unitId,subUnitId,drawingId})}focusDrawing(params){if(params==null||params.length===0){this._focusDrawings=[],this._focus$.next([]);return}const drawingParams=[];params.forEach(param=>{var _a2;const{unitId,subUnitId,drawingId}=param,item=(_a2=this._getDrawingData(unitId,subUnitId))==null?void 0:_a2[drawingId];item!=null&&drawingParams.push(item)}),drawingParams.length>0&&(this._focusDrawings=drawingParams,this._focus$.next(drawingParams))}getFocusDrawings(){const drawingParams=[];return this._focusDrawings.forEach(param=>{var _a2;const{unitId,subUnitId,drawingId}=param,item=(_a2=this._getDrawingData(unitId,subUnitId))==null?void 0:_a2[drawingId];item!=null&&drawingParams.push(item)}),drawingParams}getDrawingOrder(unitId,subUnitId){return this._getDrawingOrder(unitId,subUnitId)}setDrawingOrder(unitId,subUnitId,order){this.drawingManagerData[unitId][subUnitId].order=order}orderUpdateNotification(orderParams){this._order$.next(orderParams)}getForwardDrawingsOp(orderParams){const{unitId,subUnitId,drawingIds}=orderParams,ops=[],orders=this.getDrawingOrder(unitId,subUnitId),newIds=[...drawingIds];drawingIds.forEach(drawingId=>{const index=this._hasDrawingOrder({unitId,subUnitId,drawingId});if(index===-1||index===orders.length-1)return;const op2=distExports.moveOp([unitId,subUnitId,"order",index],[unitId,subUnitId,"order",index+1]);ops.push(op2),newIds.includes(orders[index+1])||newIds.push(orders[index+1])});const op=ops.reduce(distExports.type.compose,null);return{undo:distExports.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:{...orderParams,drawingIds:newIds}}}getBackwardDrawingOp(orderParams){const{unitId,subUnitId,drawingIds}=orderParams,ops=[],orders=this.getDrawingOrder(unitId,subUnitId),newIds=[...drawingIds];drawingIds.forEach(drawingId=>{const index=this._hasDrawingOrder({unitId,subUnitId,drawingId});if(index===-1||index===0)return;const op2=distExports.moveOp([unitId,subUnitId,"order",index],[unitId,subUnitId,"order",index-1]);ops.push(op2),newIds.includes(orders[index-1])||newIds.push(orders[index-1])});const op=ops.reduce(distExports.type.compose,null);return{undo:distExports.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:{...orderParams,drawingIds:newIds}}}getFrontDrawingsOp(orderParams){const{unitId,subUnitId,drawingIds}=orderParams,orderDrawingIds=this._getOrderFromSearchParams(unitId,subUnitId,drawingIds),newIds=[...drawingIds],orders=this.getDrawingOrder(unitId,subUnitId),ops=[];orderDrawingIds.forEach(orderDrawingId=>{const{drawingId}=orderDrawingId,index=this._getDrawingCount(unitId,subUnitId)-1,op2=distExports.moveOp([unitId,subUnitId,"order",this._getDrawingOrder(unitId,subUnitId).indexOf(drawingId)],[unitId,subUnitId,"order",index]);ops.push(op2),newIds.includes(orders[index])||newIds.push(orders[index])});const op=ops.reduce(distExports.type.compose,null);return{undo:distExports.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:{...orderParams,drawingIds:newIds}}}getBackDrawingsOp(orderParams){const{unitId,subUnitId,drawingIds}=orderParams,orderSearchParams=this._getOrderFromSearchParams(unitId,subUnitId,drawingIds,!0),newIds=[...drawingIds],orders=this.getDrawingOrder(unitId,subUnitId),ops=[];orderSearchParams.forEach(orderSearchParam=>{const{drawingId}=orderSearchParam,op2=distExports.moveOp([unitId,subUnitId,"order",this._getDrawingOrder(unitId,subUnitId).indexOf(drawingId)],[unitId,subUnitId,"order",0]);ops.push(op2),newIds.includes(orders[0])||newIds.push(orders[0])});const op=ops.reduce(distExports.type.compose,null);return{undo:distExports.type.invertWithDoc(op,this.drawingManagerData),redo:op,unitId,subUnitId,objects:{...orderParams,drawingIds:newIds}}}_getDrawingCount(unitId,subUnitId){return this.getDrawingOrder(unitId,subUnitId).length||0}_getOrderFromSearchParams(unitId,subUnitId,drawingIds,isDesc=!1){return drawingIds.map(drawingId=>{const zIndex=this._hasDrawingOrder({unitId,subUnitId,drawingId});return{drawingId,zIndex}}).sort(isDesc===!1?core.sortRules:core.sortRulesByDesc)}_hasDrawingOrder(searchParam){if(searchParam==null)return-1;const{unitId,subUnitId,drawingId}=searchParam;return this._establishDrawingMap(unitId,subUnitId),this._getDrawingOrder(unitId,subUnitId).indexOf(drawingId)}_getCurrentBySearch(searchParam){var _a2,_b,_c;if(searchParam==null)return;const{unitId,subUnitId,drawingId}=searchParam;return(_c=(_b=(_a2=this.drawingManagerData[unitId])==null?void 0:_a2[subUnitId])==null?void 0:_b.data)==null?void 0:_c[drawingId]}_getOldBySearch(searchParam){var _a2,_b,_c;if(searchParam==null)return;const{unitId,subUnitId,drawingId}=searchParam;return(_c=(_b=(_a2=this._oldDrawingManagerData[unitId])==null?void 0:_a2[subUnitId])==null?void 0:_b.data)==null?void 0:_c[drawingId]}_establishDrawingMap(unitId,subUnitId,drawingId){var _a2;return this.drawingManagerData[unitId]||(this.drawingManagerData[unitId]={}),this.drawingManagerData[unitId][subUnitId]||(this.drawingManagerData[unitId][subUnitId]={data:{},order:[]}),drawingId==null?null:(_a2=this.drawingManagerData[unitId][subUnitId].data)==null?void 0:_a2[drawingId]}_addByParam(insertParam){const{unitId,subUnitId,drawingId}=insertParam;this._establishDrawingMap(unitId,subUnitId,drawingId);const op1=distExports.insertOp([unitId,subUnitId,"data",drawingId],insertParam),op2=distExports.insertOp([unitId,subUnitId,"order",this._getDrawingOrder(unitId,subUnitId).length],drawingId),op=[op1,op2].reduce(distExports.type.compose,null),invertOp=distExports.type.invertWithDoc(op,this.drawingManagerData);return{op,invertOp}}_removeByParam(searchParam){if(searchParam==null)return{op:[],invertOp:[]};const{unitId,subUnitId,drawingId}=searchParam;if(this._establishDrawingMap(unitId,subUnitId,drawingId)==null)return{op:[],invertOp:[]};const op1=distExports.removeOp([unitId,subUnitId,"data",drawingId],!0),op2=distExports.removeOp([unitId,subUnitId,"order",this._getDrawingOrder(unitId,subUnitId).indexOf(drawingId)],!0),op=[op1,op2].reduce(distExports.type.compose,null),invertOp=distExports.type.invertWithDoc(op,this.drawingManagerData);return{op,invertOp}}_updateByParam(updateParam){const{unitId,subUnitId,drawingId}=updateParam,object=this._establishDrawingMap(unitId,subUnitId,drawingId);if(object==null)return{op:[],invertOp:[]};const op=this._getUpdateParamCompareOp(updateParam,object).reduce(distExports.type.compose,null),invertOp=distExports.type.invertWithDoc(op,this.drawingManagerData);return{op,invertOp}}_getUpdateParamCompareOp(newParam,oldParam){const{unitId,subUnitId,drawingId}=newParam,ops=[];return Object.keys(newParam).forEach(key=>{const newVal=newParam[key],oldVal=oldParam[key];oldVal!==newVal&&ops.push(distExports.replaceOp([unitId,subUnitId,"data",drawingId,key],oldVal,newVal))}),ops}_getDrawingData(unitId,subUnitId){var _a2,_b;return((_b=(_a2=this.drawingManagerData[unitId])==null?void 0:_a2[subUnitId])==null?void 0:_b.data)||{}}_getDrawingOrder(unitId,subUnitId){var _a2,_b;return((_b=(_a2=this.drawingManagerData[unitId])==null?void 0:_a2[subUnitId])==null?void 0:_b.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(visible){this._visible=visible}setDrawingEditable(editable){this._editable=editable}};__name(_UnitDrawingService,"UnitDrawingService");let UnitDrawingService=_UnitDrawingService;const _DrawingManagerService=class _DrawingManagerService extends UnitDrawingService{};__name(_DrawingManagerService,"DrawingManagerService");let DrawingManagerService=_DrawingManagerService;function getDrawingShapeKeyByDrawingSearch({unitId,subUnitId,drawingId},index){return typeof index=="number"?`${unitId}#-#${subUnitId}#-#${drawingId}#-#${index}`:`${unitId}#-#${subUnitId}#-#${drawingId}`}__name(getDrawingShapeKeyByDrawingSearch,"getDrawingShapeKeyByDrawingSearch");const getImageSize=__name(async src=>new Promise((resolve,reject)=>{const image=new Image;image.src=src,image.onload=()=>{resolve({width:image.width,height:image.height,image})},image.onerror=error=>{reject(error)}}),"getImageSize"),IDrawingManagerService=core.createIdentifier("univer.drawing-manager.service"),SetDrawingSelectedOperation={id:"drawing.operation.set-drawing-selected",type:core.CommandType.OPERATION,handler:__name((accessor,params)=>{const drawingManagerService=accessor.get(IDrawingManagerService);return params==null?!1:(drawingManagerService.focusDrawing(params),!0)},"handler")},DRAWING_PLUGIN_CONFIG_KEY="drawing.config",defaultPluginConfig={},_ImageIoService=class _ImageIoService{constructor(){__publicField(this,"_waitCount",0);__publicField(this,"_change$",new rxjs.Subject);__publicField(this,"change$",this._change$);__publicField(this,"_imageSourceCache",new Map)}setWaitCount(count){this._waitCount=count,this._change$.next(count)}getImageSourceCache(source,imageSourceType){if(imageSourceType===core.ImageSourceType.BASE64){const image=new Image;return image.src=source,image}return this._imageSourceCache.get(source)}addImageSourceCache(source,imageSourceType,imageSource){imageSourceType===core.ImageSourceType.BASE64||imageSource==null||this._imageSourceCache.set(source,imageSource)}async getImage(imageId){return Promise.resolve(imageId)}async saveImage(imageFile){return new Promise((resolve,reject)=>{if(!DRAWING_IMAGE_ALLOW_IMAGE_LIST.includes(imageFile.type)){reject(new Error(core.ImageUploadStatusType.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(imageFile.size>5242880){reject(new Error(core.ImageUploadStatusType.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}const reader=new FileReader;reader.readAsDataURL(imageFile),reader.onload=evt=>{var _a2;const replaceSrc=(_a2=evt.target)==null?void 0:_a2.result;if(replaceSrc==null){reject(new Error(core.ImageUploadStatusType.ERROR_IMAGE)),this._decreaseWaiting();return}const imageId=core.Tools.generateRandomId(6);resolve({imageId,imageSourceType:core.ImageSourceType.BASE64,source:replaceSrc,base64Cache:replaceSrc,status:core.ImageUploadStatusType.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}};__name(_ImageIoService,"ImageIoService");let ImageIoService=_ImageIoService;var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");const PLUGIN_NAME="UNIVER_DRAWING_PLUGIN";exports2.UniverDrawingPlugin=(_a=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService,_commandService){super(),this._config=_config,this._injector=_injector,this._configService=_configService,this._commandService=_commandService;const{...rest}=core.merge({},defaultPluginConfig,this._config);this._configService.setConfig(DRAWING_PLUGIN_CONFIG_KEY,rest)}onStarting(){this._initCommands(),this._initDependencies()}_initDependencies(){var _a2;const dependencies=[[core.IImageIoService,{useClass:ImageIoService}],[IDrawingManagerService,{useClass:DrawingManagerService}]];core.mergeOverrideWithDependencies(dependencies,(_a2=this._config)==null?void 0:_a2.override).forEach(d=>this._injector.add(d))}_initCommands(){[SetDrawingSelectedOperation].forEach(command=>this.disposeWithMe(this._commandService.registerCommand(command)))}},__name(_a,"UniverDrawingPlugin"),__publicField(_a,"pluginName",PLUGIN_NAME),_a),exports2.UniverDrawingPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService),__decorateParam(3,core.ICommandService)],exports2.UniverDrawingPlugin),Object.defineProperty(exports2,"IImageIoService",{enumerable:!0,get:__name(()=>core.IImageIoService,"get")}),Object.defineProperty(exports2,"ImageSourceType",{enumerable:!0,get:__name(()=>core.ImageSourceType,"get")}),Object.defineProperty(exports2,"ImageUploadStatusType",{enumerable:!0,get:__name(()=>core.ImageUploadStatusType,"get")}),exports2.DRAWING_IMAGE_ALLOW_IMAGE_LIST=DRAWING_IMAGE_ALLOW_IMAGE_LIST,exports2.DRAWING_IMAGE_ALLOW_SIZE=5242880,exports2.DRAWING_IMAGE_COUNT_LIMIT=10,exports2.DRAWING_IMAGE_HEIGHT_LIMIT=500,exports2.DRAWING_IMAGE_WIDTH_LIMIT=500,exports2.DrawingManagerService=DrawingManagerService,exports2.IDrawingManagerService=IDrawingManagerService,exports2.ImageIoService=ImageIoService,exports2.SetDrawingSelectedOperation=SetDrawingSelectedOperation,exports2.UnitDrawingService=UnitDrawingService,exports2.getDrawingShapeKeyByDrawingSearch=getDrawingShapeKeyByDrawingSearch,exports2.getImageSize=getImageSize,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/drawing",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5-experimental.20250122-3362a4a",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"ot-json1": "^1.0.2",
|
|
50
|
-
"@univerjs/core": "0.5.
|
|
50
|
+
"@univerjs/core": "0.5.5-experimental.20250122-3362a4a"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"rxjs": "^7.8.1",
|
|
54
54
|
"typescript": "^5.7.2",
|
|
55
55
|
"vite": "^6.0.7",
|
|
56
56
|
"vitest": "^2.1.8",
|
|
57
|
-
"@univerjs-infra/shared": "0.5.
|
|
57
|
+
"@univerjs-infra/shared": "0.5.5"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|