@univerjs/drawing 0.4.2-nightly.202411061606 → 0.4.2-nightly.202411081606
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 -0
- package/lib/es/index.js +1484 -1529
- package/package.json +9 -5
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var $t=Object.defineProperty;var Gt=(n,e,t)=>e in n?$t(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var F=(n,e,t)=>Gt(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ke=require("@univerjs/core"),we=require("rxjs"),Wt=500,Bt=500,xt=10,Ct=5*1024*1024,Et=["image/png","image/jpeg","image/jpg","image/gif","image/bmp"];var Ce=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},V={},Dt={},ut={};Object.defineProperty(ut,"__esModule",{value:!0});function Lt(n,e){if(Array.isArray(e))return!1;for(let t in n)if(!dt(n[t],e[t]))return!1;for(let t in e)if(n[t]===void 0)return!1;return!0}function Ht(n,e){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!dt(n[t],e[t]))return!1;return!0}function dt(n,e){return n===e?!0:n===null||e===null||typeof n!="object"||typeof e!="object"?!1:Array.isArray(n)?Ht(n,e):Lt(n,e)}ut.default=dt;var ft={};Object.defineProperty(ft,"__esModule",{value:!0});function lt(n){if(n===null)return null;if(Array.isArray(n))return n.map(lt);if(typeof n=="object"){const e={};for(let t in n)e[t]=lt(n[t]);return e}else return n}ft.default=lt;var ht={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.eachChildOf=n.advancer=n.readCursor=n.writeCursor=n.WriteCursor=n.ReadCursor=n.isValidPathItem=void 0;function e(v,o){if(!v)throw new Error(o)}const t=v=>v!=null&&typeof v=="object"&&!Array.isArray(v),r=(v,o)=>typeof v==typeof o?v>o:typeof v=="string"&&typeof o=="number";function s(v,o){for(let c in v){const h=c;o.write(h,v[h])}}n.isValidPathItem=v=>typeof v=="number"||typeof v=="string"&&v!=="__proto__";class d{constructor(o=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=o}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,t(this.container[this.idx])&&this.idx--)}getPath(){const o=[];let c=this.container,h=this.parents.length-1,j=this.idx;for(;j>=0;)o.unshift(c[j]),j===0?(j=this.indexes[h*2],c=this.parents[h--]):j-=t(c[j-1])?2:1;return o}}class a extends d{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let o;return this.container&&this.container.length>this.idx+1&&t(o=this.container[this.idx+1])?o:null}descendFirst(){let o=this.idx+1;if(!this.container||o>=this.container.length||t(this.container[o])&&o+1>=this.container.length)return!1;t(this.container[o])&&o++;const c=this.container[o];return Array.isArray(c)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(o),this.idx=0,this.container=c):this.idx=o,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const o=this.indexes[this.indexes.length-1]+1,c=this.parents[this.parents.length-1];return o>=c.length?!1:(e(!isNaN(o)),this.indexes[this.indexes.length-1]=o,this.container=c[o],!0)}_init(o,c,h,j){this.container=o,this.idx=c,this.parents=h.slice(),this.indexes=j.slice()}clone(){const o=new a;return o._init(this.container,this.idx,this.parents,this.indexes),o}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(o,c){const h=this.getComponent();h&&c(h,o);for(const j of this)o&&o.descend(j),this.traverse(o,c),o&&o.ascend()}eachPick(o,c){this.traverse(o,(h,j)=>{h.p!=null&&c(h.p,j)})}eachDrop(o,c){this.traverse(o,(h,j)=>{h.d!=null&&c(h.d,j)})}}n.ReadCursor=a;class l extends d{constructor(o=null){super(o),this.pendingDescent=[],this._op=o}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let o=0;o<this.pendingDescent.length;o++){const c=this.pendingDescent[o];let h=this.idx+1;if(h<this.container.length&&t(this.container[h])&&h++,e(h===this.container.length||!t(this.container[h])),h===this.container.length)this.container.push(c),this.idx=h;else if(this.container[h]===c)this.idx=h;else{if(!Array.isArray(this.container[h])){const j=this.container.splice(h,this.container.length-h);this.container.push(j),this.lcIdx>-1&&(this.lcIdx=h)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(r(c,this.container[this.lcIdx][0])),h=this.lcIdx+1,this.lcIdx=-1);h<this.container.length&&r(c,this.container[h][0]);)h++;if(this.indexes.push(h),this.idx=0,h<this.container.length&&this.container[h][0]===c)this.container=this.container[h];else{const j=[c];this.container.splice(h,0,j),this.container=j}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const o=this.idx+1;if(o<this.container.length&&t(this.container[o]))return this.container[o];{const c={};return this.container.splice(o,0,c),c}}write(o,c){const h=this.getComponent();e(h[o]==null||h[o]===c,"Internal consistency error: Overwritten component. File a bug"),h[o]=c}get(){return this._op}descend(o){if(!n.isValidPathItem(o))throw Error("Invalid JSON key");this.pendingDescent.push(o)}descendPath(o){return this.pendingDescent.push(...o),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(o,c=s){if(o===null)return;if(e(Array.isArray(o)),o===this._op)throw Error("Cannot merge into my own tree");const h=this.lcIdx,j=this.parents.length;let Z=0;for(let ge=0;ge<o.length;ge++){const J=o[ge];typeof J=="string"||typeof J=="number"?(Z++,this.descend(J)):Array.isArray(J)?this.mergeTree(J,c):typeof J=="object"&&c(J,this)}for(;Z--;)this.ascend();this.lcIdx=this.parents.length===j?h:-1}at(o,c){this.descendPath(o),c(this);for(let h=0;h<o.length;h++)this.ascend();return this}writeAtPath(o,c,h){return this.at(o,()=>this.write(c,h)),this.reset(),this}writeMove(o,c,h=0){return this.writeAtPath(o,"p",h).writeAtPath(c,"d",h)}getPath(){const o=super.getPath();return o.push(...this.pendingDescent),o}}n.WriteCursor=l,n.writeCursor=()=>new l,n.readCursor=v=>new a(v);function E(v,o,c){let h,j;j=h=v?v.descendFirst():!1;function Z(ge){let J;for(;j;){const Ie=J=v.getKey();if(ge!=null){let Le=!1;if(o&&typeof Ie=="number"&&(J=o(Ie,v.getComponent()),J<0&&(J=~J,Le=!0)),r(J,ge))return null;if(J===ge&&!Le)return v}c&&typeof J=="number"&&c(J,v.getComponent()),j=v.nextSibling()}return null}return Z.end=()=>{h&&v.ascend()},Z}n.advancer=E;function G(v,o,c){let h,j,Z,ge;for(h=j=v&&v.descendFirst(),Z=ge=o&&o.descendFirst();h||Z;){let J=h?v.getKey():null,Ie=Z?o.getKey():null;J!==null&&Ie!==null&&(r(Ie,J)?Ie=null:J!==Ie&&(J=null)),c(J==null?Ie:J,J!=null?v:null,Ie!=null?o:null),J!=null&&h&&(h=v.nextSibling()),Ie!=null&&Z&&(Z=o.nextSibling())}j&&v.ascend(),ge&&o.ascend()}n.eachChildOf=G})(ht);var gt={};(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.ConflictType=void 0,function(e){e[e.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",e[e.DROP_COLLISION=2]="DROP_COLLISION",e[e.BLACKHOLE=3]="BLACKHOLE"}(n.ConflictType||(n.ConflictType={}))})(gt);var st={},qe={},yt;function pt(){return yt||(yt=1,Object.defineProperty(qe,"__esModule",{value:!0}),qe.uniToStrPos=qe.strPosToUni=void 0,qe.strPosToUni=(n,e=n.length)=>{let t=0,r=0;for(;r<e;r++){const s=n.charCodeAt(r);s>=55296&&s<=57343&&(t++,r++)}if(r!==e)throw Error("Invalid offset - splits unicode bytes");return r-t},qe.uniToStrPos=(n,e)=>{let t=0;for(;e>0;e--){const r=n.charCodeAt(t);t+=r>=55296&&r<=57343?2:1}return t}),qe}var ot={},bt;function ct(){return bt||(bt=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.uniSlice=n.dlen=n.eachOp=void 0;const e=pt(),t=f=>{if(!Array.isArray(f))throw Error("Op must be an array of components");let _=null;for(let w=0;w<f.length;w++){const L=f[w];switch(typeof L){case"object":if(typeof L.d!="number"&&typeof L.d!="string")throw Error("Delete must be number or string");if(n.dlen(L.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(L.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(L>0))throw Error("Skip components must be >0");if(typeof _=="number")throw Error("Adjacent skip components should be combined");break}_=L}if(typeof _=="number")throw Error("Op has a trailing skip")};function r(f,_){let w=0,L=0;for(let z=0;z<f.length;z++){const H=f[z];switch(_(H,w,L),typeof H){case"object":w+=n.dlen(H.d);break;case"string":L+=e.strPosToUni(H);break;case"number":w+=H,L+=H;break}}}n.eachOp=r;function s(f,_){const w=[],L=l(w);return r(f,(z,H,De)=>{L(_(z,H,De))}),o(w)}const d=f=>f,a=f=>s(f,d);n.dlen=f=>typeof f=="number"?f:e.strPosToUni(f);const l=f=>_=>{if(!(!_||_.d===0||_.d===""))if(f.length===0)f.push(_);else if(typeof _==typeof f[f.length-1])if(typeof _=="object"){const w=f[f.length-1];w.d=typeof w.d=="string"&&typeof _.d=="string"?w.d+_.d:n.dlen(w.d)+n.dlen(_.d)}else f[f.length-1]+=_;else f.push(_)},E=f=>typeof f=="number"?f:typeof f=="string"?e.strPosToUni(f):typeof f.d=="number"?f.d:e.strPosToUni(f.d);n.uniSlice=(f,_,w)=>{const L=e.uniToStrPos(f,_),z=w==null?1/0:e.uniToStrPos(f,w);return f.slice(L,z)};const G=(f,_,w)=>typeof f=="number"?w==null?f-_:Math.min(f,w)-_:n.uniSlice(f,_,w),v=f=>{let _=0,w=0;return{take:(H,De)=>{if(_===f.length)return H===-1?null:H;const ue=f[_];let ne;if(typeof ue=="number")return H===-1||ue-w<=H?(ne=ue-w,++_,w=0,ne):(w+=H,H);if(typeof ue=="string"){if(H===-1||De==="i"||e.strPosToUni(ue.slice(w))<=H)return ne=ue.slice(w),++_,w=0,ne;{const le=w+e.uniToStrPos(ue.slice(w),H);return ne=ue.slice(w,le),w=le,ne}}else{if(H===-1||De==="d"||n.dlen(ue.d)-w<=H)return ne={d:G(ue.d,w)},++_,w=0,ne;{let le=G(ue.d,w,w+H);return w+=H,{d:le}}}},peek:()=>f[_]}},o=f=>(f.length>0&&typeof f[f.length-1]=="number"&&f.pop(),f);function c(f,_,w){if(w!=="left"&&w!=="right")throw Error("side ("+w+") must be 'left' or 'right'");t(f),t(_);const L=[],z=l(L),{take:H,peek:De}=v(f);for(let ne=0;ne<_.length;ne++){const le=_[ne];let pe,Ae;switch(typeof le){case"number":for(pe=le;pe>0;)Ae=H(pe,"i"),z(Ae),typeof Ae!="string"&&(pe-=E(Ae));break;case"string":w==="left"&&typeof De()=="string"&&z(H(-1)),z(e.strPosToUni(le));break;case"object":for(pe=n.dlen(le.d);pe>0;)switch(Ae=H(pe,"i"),typeof Ae){case"number":pe-=Ae;break;case"string":z(Ae);break;case"object":pe-=n.dlen(Ae.d)}break}}let ue;for(;ue=H(-1);)z(ue);return o(L)}function h(f,_){t(f),t(_);const w=[],L=l(w),{take:z}=v(f);for(let De=0;De<_.length;De++){const ue=_[De];let ne,le;switch(typeof ue){case"number":for(ne=ue;ne>0;)le=z(ne,"d"),L(le),typeof le!="object"&&(ne-=E(le));break;case"string":L(ue);break;case"object":ne=n.dlen(ue.d);let pe=0;for(;pe<ne;)switch(le=z(ne-pe,"d"),typeof le){case"number":L({d:G(ue.d,pe,pe+le)}),pe+=le;break;case"string":pe+=e.strPosToUni(le);break;case"object":L(le)}break}}let H;for(;H=z(-1);)L(H);return o(w)}const j=(f,_)=>{let w=0;for(let L=0;L<_.length&&f>w;L++){const z=_[L];switch(typeof z){case"number":{w+=z;break}case"string":const H=e.strPosToUni(z);w+=H,f+=H;break;case"object":f-=Math.min(n.dlen(z.d),f-w);break}}return f},Z=(f,_)=>typeof f=="number"?j(f,_):f.map(w=>j(w,_));function ge(f,_,w){return s(f,(L,z)=>typeof L=="object"&&typeof L.d=="number"?{d:w.slice(_,z,z+L.d)}:L)}function J(f){return s(f,_=>{switch(typeof _){case"object":if(typeof _.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return _.d;case"string":return{d:_};case"number":return _}})}function Ie(f){return s(f,_=>typeof _=="object"&&typeof _.d=="string"?{d:e.strPosToUni(_.d)}:_)}function Le(f){let _=!0;return r(f,w=>{typeof w=="object"&&typeof w.d=="number"&&(_=!1)}),_}function Oe(f){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:o,normalize:a,checkOp:t,create(_=""){if(typeof _!="string")throw Error("Initial data must be a string");return f.create(_)},apply(_,w){t(w);const L=f.builder(_);for(let z=0;z<w.length;z++){const H=w[z];switch(typeof H){case"number":L.skip(H);break;case"string":L.append(H);break;case"object":L.del(n.dlen(H.d));break}}return L.build()},transform:c,compose:h,transformPosition:j,transformSelection:Z,isInvertible:Le,makeInvertible(_,w){return ge(_,w,f)},stripInvertible:Ie,invert:J,invertWithDoc(_,w){return J(ge(_,w,f))},isNoop:_=>_.length===0}}n.default=Oe}(ot)),ot}var tt={},mt;function Kt(){if(mt)return tt;mt=1,Object.defineProperty(tt,"__esModule",{value:!0});const n=ct(),e=pt();function t(r,s){return{get:r,getLength(){return r().length},insert(d,a,l){const E=e.strPosToUni(r(),d);return s([E,a],l)},remove(d,a,l){const E=e.strPosToUni(r(),d);return s([E,{d:a}],l)},_onOp(d){n.eachOp(d,(a,l,E)=>{switch(typeof a){case"string":this.onInsert&&this.onInsert(E,a);break;case"object":const G=n.dlen(a.d);this.onRemove&&this.onRemove(E,G)}})},onInsert:null,onRemove:null}}return tt.default=t,t.provides={text:!0},tt}var wt;function Ft(){return wt||(wt=1,function(n){var e=Ce&&Ce.__createBinding||(Object.create?function(c,h,j,Z){Z===void 0&&(Z=j),Object.defineProperty(c,Z,{enumerable:!0,get:function(){return h[j]}})}:function(c,h,j,Z){Z===void 0&&(Z=j),c[Z]=h[j]}),t=Ce&&Ce.__setModuleDefault||(Object.create?function(c,h){Object.defineProperty(c,"default",{enumerable:!0,value:h})}:function(c,h){c.default=h}),r=Ce&&Ce.__importStar||function(c){if(c&&c.__esModule)return c;var h={};if(c!=null)for(var j in c)Object.hasOwnProperty.call(c,j)&&e(h,c,j);return t(h,c),h},s=Ce&&Ce.__importDefault||function(c){return c&&c.__esModule?c:{default:c}};Object.defineProperty(n,"__esModule",{value:!0}),n.type=n.remove=n.insert=void 0;const d=pt(),a=r(ct()),l=s(Kt()),E={create(c){return c},toString(c){return c},builder(c){if(typeof c!="string")throw Error("Invalid document snapshot: "+c);const h=[];return{skip(j){let Z=d.uniToStrPos(c,j);if(Z>c.length)throw Error("The op is too long for this document");h.push(c.slice(0,Z)),c=c.slice(Z)},append(j){h.push(j)},del(j){c=c.slice(d.uniToStrPos(c,j))},build(){return h.join("")+c}}},slice:a.uniSlice},G=a.default(E),v=Object.assign(Object.assign({},G),{api:l.default});n.type=v,n.insert=(c,h)=>h.length===0?[]:c===0?[h]:[c,h],n.remove=(c,h)=>a.dlen(h)===0?[]:c===0?[{d:h}]:[c,{d:h}];var o=ct();Object.defineProperty(n,"makeType",{enumerable:!0,get:function(){return o.default}})}(st)),st}(function(n){var e=Ce&&Ce.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(n,"__esModule",{value:!0}),n.editOp=n.replaceOp=n.insertOp=n.moveOp=n.removeOp=n.type=void 0;const t=e(ut),r=e(ft),s=ht,d=gt;function a(i,u){if(!i)throw new Error(u)}n.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:s.readCursor,writeCursor:s.writeCursor,create:i=>i,isNoop:i=>i==null,setDebug(i){},registerSubtype:J,checkValidOp:z,normalize:H,apply:De,transformPosition:ue,compose:ne,tryTransform:rt,transform:Tt,makeInvertible:Ae,invert:le,invertWithDoc:Rt,RM_UNEXPECTED_CONTENT:d.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:d.ConflictType.DROP_COLLISION,BLACKHOLE:d.ConflictType.BLACKHOLE,transformNoConflict:(i,u,y)=>vt(()=>!0,i,u,y),typeAllowingConflictsPred:i=>Object.assign(Object.assign({},n.type),{transform:(u,y,D)=>vt(i,u,y,D)})};const l=i=>i?i.getComponent():null;function E(i){return i&&typeof i=="object"&&!Array.isArray(i)}const G=i=>Array.isArray(i)?i.slice():i!==null&&typeof i=="object"?Object.assign({},i):i,v=i=>i&&(i.p!=null||i.r!==void 0),o=i=>i&&(i.d!=null||i.i!==void 0);function c(i,u){return a(i!=null),typeof u=="number"?(a(Array.isArray(i),"Invalid key - child is not an array"),(i=i.slice()).splice(u,1)):(a(E(i),"Invalid key - child is not an object"),delete(i=Object.assign({},i))[u]),i}function h(i,u,y){return typeof u=="number"?(a(i!=null,"Container is missing for key"),a(Array.isArray(i),"Cannot use numerical key for object container"),a(i.length>=u,"Cannot insert into out of bounds index"),i.splice(u,0,y)):(a(E(i),"Cannot insert into missing item"),a(i[u]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),i[u]=y),y}n.removeOp=(i,u=!0)=>s.writeCursor().writeAtPath(i,"r",u).get(),n.moveOp=(i,u)=>s.writeCursor().writeMove(i,u).get(),n.insertOp=(i,u)=>s.writeCursor().writeAtPath(i,"i",u).get(),n.replaceOp=(i,u,y)=>s.writeCursor().at(i,D=>{D.write("r",u),D.write("i",y)}).get(),n.editOp=(i,u,y,D=!1)=>s.writeCursor().at(i,b=>_(b,u,y,D)).get();const j=(i,u)=>i!=null&&(typeof u=="number"?Array.isArray(i):typeof i=="object"),Z=(i,u)=>j(i,u)?i[u]:void 0,ge={};function J(i){let u=i.type?i.type:i;u.name&&(ge[u.name]=u),u.uri&&(ge[u.uri]=u)}const Ie=i=>{const u=ge[i];if(u)return u;throw Error("Missing type: "+i)};J(Ft());const Le=(i,u)=>i+u;J({name:"number",apply:Le,compose:Le,invert:i=>-i,transform:i=>i});const Oe=i=>i==null?null:i.et?Ie(i.et):i.es?ge["text-unicode"]:i.ena!=null?ge.number:null,f=i=>i.es?i.es:i.ena!=null?i.ena:i.e,_=(i,u,y,D=!1)=>{const[b,C]=typeof u=="string"?[Ie(u),u]:[u,u.name];!D&&b.isNoop&&b.isNoop(y)||(C==="number"?i.write("ena",y):C==="text-unicode"?i.write("es",y):(i.write("et",C),i.write("e",y)))};function w(i){a(typeof i=="number"),a(i>=0),a(i===(0|i))}function L(i){typeof i=="number"?w(i):a(typeof i=="string")}function z(i){if(i===null)return;const u=new Set,y=new Set,D=C=>{let $=!0,T=!1;for(let g in C){const O=C[g];if($=!1,a(g==="p"||g==="r"||g==="d"||g==="i"||g==="e"||g==="es"||g==="ena"||g==="et","Invalid component item '"+g+"'"),g==="p")w(O),a(!u.has(O)),u.add(O),a(C.r===void 0);else if(g==="d")w(O),a(!y.has(O)),y.add(O),a(C.i===void 0);else if(g==="e"||g==="es"||g==="ena"){a(!T),T=!0;const m=Oe(C);a(m,"Missing type in edit"),m.checkValidOp&&m.checkValidOp(f(C))}}a(!$)},b=(C,$,T)=>{if(!Array.isArray(C))throw Error("Op must be null or a list");if(C.length===0)throw Error("Empty descent");$||L(C[0]);let g=1,O=0,m=0;for(let I=0;I<C.length;I++){const k=C[I];if(a(k!=null),Array.isArray(k)){const W=b(k,!1);if(O){const p=typeof m,U=typeof W;p===U?a(m<W,"descent keys are not in order"):a(p==="number"&&U==="string")}m=W,O++,g=3}else typeof k=="object"?(a(g===1,`Prev not scalar - instead ${g}`),D(k),g=2):(a(g!==3),L(k),a(s.isValidPathItem(k),"Invalid path key"),g=1)}return a(O!==1,"Operation makes multiple descents. Remove some []"),a(g===2||g===3),C[0]};b(i,!0),a(u.size===y.size,"Mismatched picks and drops in op");for(let C=0;C<u.size;C++)a(u.has(C)),a(y.has(C))}function H(i){let u=0,y=[];const D=s.writeCursor();return D.mergeTree(i,(b,C)=>{const $=Oe(b);if($){const g=f(b);_(C,$,$.normalize?$.normalize(g):g)}for(const g of["r","p","i","d"])if(b[g]!==void 0){const O=g==="p"||g==="d"?(T=b[g],y[T]==null&&(y[T]=u++),y[T]):b[g];C.write(g,O)}var T}),D.get()}function De(i,u){if(z(u),u===null)return i;const y=[];return function D(b,C){let $=b,T=0,g={root:b},O=0,m=g,I="root";function k(){for(;O<T;O++){let W=C[O];typeof W!="object"&&(a(j(m,I)),m=m[I]=G(m[I]),I=W)}}for(;T<C.length;T++){const W=C[T];if(Array.isArray(W)){const p=D($,W);p!==$&&p!==void 0&&(k(),$=m[I]=p)}else if(typeof W=="object"){W.d!=null?(k(),$=h(m,I,y[W.d])):W.i!==void 0&&(k(),$=h(m,I,W.i));const p=Oe(W);if(p)k(),$=m[I]=p.apply($,f(W));else if(W.e!==void 0)throw Error("Subtype "+W.et+" undefined")}else $=Z($,W)}return g.root}(i=function D(b,C){const $=[];let T=0;for(;T<C.length;T++){const I=C[T];if(Array.isArray(I))break;typeof I!="object"&&($.push(b),b=Z(b,I))}for(let I=C.length-1;I>=T;I--)b=D(b,C[I]);for(--T;T>=0;T--){const I=C[T];if(typeof I!="object"){const k=$.pop();b=b===Z(k,I)?k:b===void 0?c(k,I):(O=I,m=b,(g=G(g=k))[O]=m,g)}else v(I)&&(a(b!==void 0,"Cannot pick up or remove undefined"),I.p!=null&&(y[I.p]=b),b=void 0)}var g,O,m;return b}(i,u),u)}function ue(i,u){i=i.slice(),z(u);const y=s.readCursor(u);let D,b,C=!1;const $=[];for(let g=0;;g++){const O=i[g],m=y.getComponent();if(m&&(m.r!==void 0?C=!0:m.p!=null&&(C=!1,D=m.p,b=g)),g>=i.length)break;let I=0;const k=s.advancer(y,void 0,(p,U)=>{v(U)&&I++});$.unshift(k);const W=k(O);if(typeof O=="number"&&(i[g]-=I),!W)break}if($.forEach(g=>g.end()),C)return null;const T=()=>{let g=0;if(D!=null){const O=y.getPath();g=O.length,i=O.concat(i.slice(b))}for(;g<i.length;g++){const O=i[g],m=l(y),I=Oe(m);if(I){const p=f(m);I.transformPosition&&(i[g]=I.transformPosition(i[g],p));break}let k=0;const W=s.advancer(y,(p,U)=>o(U)?~(p-k):p-k,(p,U)=>{o(U)&&k++})(O);if(typeof O=="number"&&(i[g]+=k),!W)break}};return D!=null?y.eachDrop(null,g=>{g===D&&T()}):T(),i}function ne(i,u){if(z(i),z(u),i==null)return u;if(u==null)return i;let y=0;const D=s.readCursor(i),b=s.readCursor(u),C=s.writeCursor(),$=[],T=[],g=[],O=[],m=[],I=[],k=new Set;D.traverse(null,p=>{p.p!=null&&(g[p.p]=D.clone())}),b.traverse(null,p=>{p.d!=null&&(O[p.d]=b.clone())});const W=s.writeCursor();return function p(U,re,te,K,se,$e,be,_e){a(re||te);const oe=l(re),Pe=l(te),Me=!!Pe&&Pe.r!==void 0,He=!!oe&&oe.i!==void 0,Se=oe?oe.d:null,Ee=Pe?Pe.p:null,Ge=($e||Me)&&Ee==null;if(Ee!=null)K=O[Ee],be=T[Ee]=new s.WriteCursor;else if(Pe&&Pe.r!==void 0)K=null;else{const P=l(K);P&&P.d!=null&&(K=null)}const Q=l(K);if(Se!=null)if(U=g[Se],_e=$[Se]=new s.WriteCursor,Ge)$e&&!Me&&_e.write("r",!0);else{const P=m[Se]=y++;be.write("d",P)}else if(oe&&oe.i!==void 0)U=null;else{const P=l(U);P&&P.p!=null&&(U=null)}let S;He?(a(se===void 0),S=oe.i):S=se;const B=(Ee==null?!He||$e||Me:S===void 0)?null:be.getComponent();if(Ee!=null){if(!(se!==void 0||He)){const P=Se!=null?m[Se]:y++;I[Ee]=P,_e.write("p",P)}}else Me&&(He||se!==void 0||(Pe.r,_e.write("r",Pe.r)));const M=Ge?null:Oe(oe),A=Oe(Q);if((M||A)&&(M&&M.name,A&&A.name),M&&A){a(M===A);const P=f(oe),x=f(Q),he=M.compose(P,x);_(be,M,he),k.add(Q)}else M?_(be,M,f(oe)):A&&(_(be,A,f(Q)),k.add(Q));const N=typeof S=="object"&&S!=null;let X=!1,Y=0,ee=0,fe=0,de=0,ae=0;const ye=s.advancer(K,(P,x)=>o(x)?de-P-1:P-de,(P,x)=>{o(x)&&de++}),q=s.advancer(U,(P,x)=>v(x)?Y-P-1:P-Y,(P,x)=>{v(x)&&Y++});if(s.eachChildOf(re,te,(P,x,he)=>{let me,We,Ke=P,Ue=P,Je=P;if(typeof P=="number"){let ve=P+fe;We=ye(ve),Ue=ve+de;let ce=P+ee;me=q(ce),o(l(We))&&(me=null),Ke=ce+Y,Je=P+ae,a(Ke>=0,"p1PickKey is negative"),a(Ue>=0,"p2DropKey is negative");const Ne=o(l(x)),Be=v(l(he));(Ne||Be&&!Ge)&&ae--,Ne&&ee--,Be&&fe--}else me=q(P),We=ye(P);_e.descend(Ke),be.descend(Ue);const Xe=N&&!o(l(x))?S[Je]:void 0,Re=p(me,x,he,We,Xe,Ge,be,_e);var Te,R,ie;N&&!Ge?Xe!==Re&&(X||(S=Array.isArray(S)?S.slice():Object.assign({},S),X=!0),Te=S,ie=Re,typeof(R=Je)=="number"?(a(Array.isArray(Te)),a(R<Te.length)):(a(!Array.isArray(Te)),a(Te[R]!==void 0)),ie===void 0?typeof R=="number"?Te.splice(R,1):delete Te[R]:Te[R]=ie):a(Re===void 0),be.ascend(),_e.ascend()}),q.end(),ye.end(),B!=null)B.i=S;else if(!$e&&!Me&&Ee==null)return S}(D,D.clone(),b,b.clone(),void 0,!1,C,W),C.reset(),C.mergeTree(W.get()),C.reset(),C.get(),$.map(p=>p.get()),T.map(p=>p.get()),D.traverse(C,(p,U)=>{const re=p.p;if(re!=null){const te=m[re];te!=null&&U.write("p",te);const K=$[re];K&&K.get(),K&&U.mergeTree(K.get())}else p.r!==void 0&&U.write("r",p.r)}),C.reset(),C.get(),b.traverse(C,(p,U)=>{const re=p.d;if(re!=null){const K=I[re];K!=null&&U.write("d",K);const se=T[re];se&&U.mergeTree(se.get())}else p.i!==void 0&&U.write("i",p.i);const te=Oe(p);te&&!k.has(p)&&_(U,te,f(p))}),C.get()}function le(i){if(i==null)return null;const u=new s.ReadCursor(i),y=new s.WriteCursor;let D;const b=[],C=[];return function $(T,g,O){const m=T.getComponent();let I,k=!1;if(m){m.p!=null&&(g.write("d",m.p),b[m.p]=T.clone()),m.r!==void 0&&g.write("i",m.r),m.d!=null&&(g.write("p",m.d),O=void 0),m.i!==void 0&&(O=I=m.i);const p=Oe(m);p&&(O===void 0?(D||(D=new Set),D.add(m)):(f(m),O=p.apply(O,f(m)),k=!0))}let W=0;for(const p of T){g.descend(p);const U=typeof p=="number"?p-W:p,re=Z(O,U);o(T.getComponent())&&W++;const te=$(T,g,re);if(O!==void 0&&te!==void 0){if(k||(k=!0,O=G(O)),!j(O,U))throw Error("Cannot modify child - invalid operation");O[U]=te}g.ascend()}if(I===void 0)return k?O:void 0;g.write("r",O)}(u,y,void 0),D&&(y.reset(),function $(T,g,O){const m=g.getComponent();if(m){const p=m.d;if(p!=null&&(T=b[p],O=C[p]=s.writeCursor()),D.has(m)){const U=Oe(m);if(!U.invert)throw Error(`Cannot invert subtype ${U.name}`);_(O,U,U.invert(f(m)))}}let I=0,k=0;const W=s.advancer(T,(p,U)=>v(U)?I-p-1:p-I,(p,U)=>{v(U)&&I++});for(const p of g)if(typeof p=="number"){const U=p-k,re=W(U),te=U+I;O.descend(te),$(re,g,O),o(g.getComponent())&&k++,O.ascend()}else O.descend(p),$(W(p),g,O),O.ascend();W.end()}(u.clone(),u,y),C.length&&(y.reset(),u.traverse(y,($,T)=>{const g=$.p;if(g!=null){const O=C[g];O&&O.get(),O&&T.mergeTree(O.get())}}))),y.get()}const pe=(i,u)=>i.some(y=>typeof y=="object"&&(Array.isArray(y)?pe(y,u):u(y)));function Ae(i,u){if(i==null||!pe(i,g=>{var O;return g.r!==void 0||((O=Oe(g))===null||O===void 0?void 0:O.makeInvertible)!=null}))return i;const y=new s.ReadCursor(i),D=new s.WriteCursor;let b=!1;const C=[],$=[],T=(g,O,m)=>{const I=g.getComponent();let k=!1;if(I){I.d!=null&&O.write("d",I.d),I.i!==void 0&&O.write("i",I.i);const p=I.p;if(p!=null&&(C[p]=g.clone(),a(m!==void 0,"Operation picks up at an invalid key"),$[p]=m,O.write("p",I.p)),I.r!==void 0&&m===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const U=Oe(I);U&&(U.makeInvertible?b=!0:_(O,U,f(I),!0))}let W=0;for(const p of g){O.descend(p);const U=typeof p=="number"?p-W:p,re=Z(m,U),te=T(g,O,re);re!==te&&(k||(k=!0,m=G(m)),te===void 0?(m=c(m,U),typeof p=="number"&&W++):m[U]=te),O.ascend()}return I&&(I.r!==void 0?(O.write("r",r.default(m)),m=void 0):I.p!=null&&(m=void 0)),m};return T(y,D,u),D.get(),b&&(D.reset(),function g(O,m,I,k,W){const p=m.getComponent();if(p){p.i!==void 0?(k=p.i,W=!0):p.d!=null&&(k=$[p.d],O=C[p.d],W=!1,p.d);let K=Oe(p);if(K&&K.makeInvertible){const se=f(p);_(I,K,K.makeInvertible(se,k),!0)}}let U=0,re=0;const te=s.advancer(O,(K,se)=>v(se)?U-K-1:K-U,(K,se)=>{v(se)&&U++});for(const K of m)if(typeof K=="number"){const se=K-re,$e=te(se),be=se+U,_e=Z(k,W?se:be);I.descend(K),g($e,m,I,_e,W),o(m.getComponent())&&re++,I.ascend()}else{const se=Z(k,K);I.descend(K),g(te(K),m,I,se,W),I.ascend()}te.end()}(y.clone(),y,D,u,!1)),D.get()}function Rt(i,u){return le(Ae(i,u))}const nt=i=>{if(i==null)return null;const u=i.slice();for(let y=0;y<i.length;y++){const D=u[y];Array.isArray(D)&&(u[y]=nt(D))}return u};function rt(i,u,y){a(y==="left"||y==="right","Direction must be left or right");const D=y==="left"?0:1;if(u==null)return{ok:!0,result:i};z(i),z(u);let b=null;const C=[],$=[],T=[],g=[],O=[],m=[],I=[],k=[],W=[],p=[],U=[],re=[],te=[],K=[],se=[];let $e=0;const be=s.readCursor(i),_e=s.readCursor(u),oe=s.writeCursor();if(function Q(S,B=null,M){const A=l(B);A&&(A.r!==void 0?M=B.clone():A.p!=null&&(M=null,m[A.p]=S.clone()));const N=S.getComponent();let X;N&&(X=N.p)!=null&&(O[X]=B?B.clone():null,T[X]=S.clone(),M&&(p[X]=!0,W[X]=M),A&&A.p!=null&&(K[X]=A.p));const Y=s.advancer(B);for(const ee of S)Q(S,Y(ee),M);Y.end()}(_e,be,null),function Q(S,B,M,A,N){const X=M.getComponent();let Y,ee=!1;X&&((Y=X.d)!=null?(g[Y]=M.clone(),A!=null&&(se[A]==null&&(se[A]=[]),se[A].push(Y)),S=O[Y]||null,B=T[Y]||null,p[Y]?(N&&(U[Y]=!0),N=W[Y]||null):!N||D!==1&&K[Y]!=null||b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.moveOp(B.getPath(),M.getPath())}),ee=!0):X.i!==void 0&&(S=B=null,ee=!0,N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.insertOp(M.getPath(),X.i)})));const fe=l(S);fe&&(fe.r!==void 0?N=S.clone():fe.p!=null&&(fe.p,A=fe.p,N=null));const de=Oe(X);de&&N&&b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.removeOp(N.getPath()),op2:n.editOp(M.getPath(),de,f(X),!0)});let ae=0,ye=0;const q=s.advancer(B,(x,he)=>v(he)?ae-x-1:x-ae,(x,he)=>{v(he)&&ae++}),P=s.advancer(S);for(const x of M)if(typeof x=="number"){const he=x-ye,me=q(he);ye+=+Q(P(he+ae),me,M,A,N)}else{const he=q(x);Q(P(x),he,M,A,N)}return q.end(),P.end(),ee}(be,_e,_e.clone(),null,null),g.map(Q=>Q&&Q.get()),b)return{ok:!1,conflict:b};U.map(Q=>!!Q);const Pe=[];let Me=null;(function Q(S,B,M,A,N){let X=!1;const Y=l(B);if(v(Y)){const q=Y.p;q!=null?(M=g[q],A=re[q]=s.writeCursor(),X=!0,N=null):(M=null,N=B.clone())}else o(l(M))&&(M=null);const ee=S.getComponent();if(ee){const q=ee.p;q!=null?(N&&(k[q]=N),Pe[q]=N||D===1&&X?null:A.getComponent(),C[q]=S.clone(),M&&(I[q]=M.clone())):ee.r!==void 0&&(N||A.write("r",!0),(N||X)&&(Me==null&&(Me=new Set),Me.add(ee)))}let fe=0,de=0;const ae=s.advancer(B,void 0,(q,P)=>{v(P)&&fe++}),ye=s.advancer(M,(q,P)=>o(P)?~(q-de):q-de,(q,P)=>{o(P)&&de++});if(S)for(const q of S)if(typeof q=="string"){const P=ae(q),x=ye(q);A.descend(q),Q(S,P,x,A,N),A.ascend()}else{const P=ae(q),x=q-fe,he=v(l(P))?null:ye(x),me=x+de;a(me>=0),A.descend(me),Q(S,P,he,A,N),A.ascend()}ae.end(),ye.end()})(be,_e,_e.clone(),oe,null),oe.reset();let He=[];if(function Q(S,B,M,A,N,X){a(B);const Y=B.getComponent();let ee=l(A),fe=!1;const de=(R,ie,ve)=>R?n.moveOp(R.getPath(),ie.getPath()):n.insertOp(ie.getPath(),ve.i);if(o(Y)){const R=Y.d;R!=null&&($[R]=B.clone());const ie=R!=null?Pe[R]:null;let ve=!1;if(Y.i!==void 0||R!=null&&ie){let ce;ee&&(ee.i!==void 0||(ce=ee.d)!=null&&!p[ce])&&(ve=ce!=null?R!=null&&R===K[ce]:t.default(ee.i,Y.i),ve||ce!=null&&D!==1&&K[ce]!=null||b==null&&(b={type:d.ConflictType.DROP_COLLISION,op1:de(R!=null?C[R]:null,B,Y),op2:de(ce!=null?T[ce]:null,A,ee)})),ve||(X?b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:de(R!=null?C[R]:null,B,Y),op2:n.removeOp(X.getPath())}):(R!=null?(He[$e]=R,N.write("d",ie.p=$e++)):N.write("i",r.default(Y.i)),fe=!0))}else if(R!=null&&!ie){const ce=k[R];ce&&(X=ce.clone())}R!=null?(S=C[R],M=m[R],A=I[R]):Y.i!==void 0&&(S=M=null,ve||(A=null))}else v(l(S))&&(S=M=A=null);const ae=l(S),ye=l(M);if(v(ye)){const R=ye.p;ye.r!==void 0&&(!ae||ae.r===void 0)||p[R]?(A=null,X=M.clone()):R!=null&&(A=g[R],D!==1&&K[R]!=null||((N=te[R])||(N=te[R]=s.writeCursor()),N.reset(),X=null))}else!o(Y)&&o(ee)&&(A=null);ee=A!=null?A.getComponent():null;const q=Oe(Y);if(q){const R=f(Y);if(X)b==null&&(b={type:d.ConflictType.RM_UNEXPECTED_CONTENT,op1:n.editOp(B.getPath(),q,R,!0),op2:n.removeOp(X.getPath())});else{const ie=Oe(ee);let ve;if(ie){if(q!==ie)throw Error("Transforming incompatible types");const ce=f(ee);ve=q.transform(R,ce,y)}else ve=r.default(R);_(N,q,ve)}}let P=0,x=0,he=0,me=0,We=0,Ke=0,Ue=S!=null&&S.descendFirst(),Je=Ue;const Xe=s.advancer(M,void 0,(R,ie)=>{v(ie)&&he++});let Re=A!=null&&A.descendFirst(),Te=Re;for(const R of B)if(typeof R=="number"){let ie;const ve=o(B.getComponent()),ce=R-x;{let xe;for(;Ue&&typeof(xe=S.getKey())=="number";){xe+=P;const je=S.getComponent(),Ye=v(je);if(xe>ce||xe===ce&&(!Ye||D===0&&ve))break;if(Ye){P--;const Fe=je.p;K.includes(Fe),je.d,l(te[je.d]),v(l(te[je.d])),(je.r===void 0||Me&&Me.has(je))&&(Fe==null||!Pe[Fe]||D!==1&&K.includes(Fe))||We--}Ue=S.nextSibling()}ie=Ue&&xe===ce?S:null}const Ne=ce-P;let Be=Xe(Ne);const it=Ne-he;let et=null;{let xe,je;for(;Re&&typeof(xe=A.getKey())=="number";){je=xe-me;const Ye=A.getComponent(),Fe=o(Ye);if(je>it)break;if(je===it){if(!Fe){et=A;break}{if(D===0&&ve){et=A;break}const Ve=Be&&v(Be.getComponent());if(D===0&&Ve)break}}if(Fe){const Ve=Ye.d;K[Ve],Ye.i===void 0&&(p[Ve]||K[Ve]!=null&&D!==1)?(p[Ve]||K[Ve]!=null&&D===0)&&(me++,Ke--):me++}Re=A.nextSibling()}}const Ot=it+me+We+Ke;a(Ot>=0,"trying to descend to a negative index"),N.descend(Ot),ve&&(ie=Be=et=null,x++),Q(ie,B,Be,et,N,X)&&Ke++,N.ascend()}else{let ie;for(;Ue&&(ie=S.getKey(),typeof ie!="string"||!(ie>R||ie===R));)Ue=S.nextSibling();const ve=Ue&&ie===R?S:null,ce=Xe(R);let Ne;for(;Re&&(Ne=A.getKey(),typeof Ne!="string"||!(Ne>R||Ne===R));)Re=A.nextSibling();const Be=Re&&Ne===R?A:null;N.descend(R),Q(ve,B,ce,Be,N,X),N.ascend()}return Xe.end(),Je&&S.ascend(),Te&&A.ascend(),fe}(be,be.clone(),_e,_e.clone(),oe,null),b)return{ok:!1,conflict:b};oe.reset();const Se=(Q,S,B)=>Q.traverse(S,(M,A)=>{M.d!=null&&B(M.d,Q,A)});(p.length||re.length)&&(Se(_e,oe,(Q,S,B)=>{p[Q]&&!U[Q]&&B.write("r",!0),re[Q]&&B.mergeTree(re[Q].get())}),oe.reset());const Ee=[],Ge=[];if((te.length||p.length)&&!b){const Q=s.readCursor(nt(oe.get()));if(Se(Q,null,(S,B)=>{Ee[S]=B.clone()}),te.forEach(S=>{S&&Se(s.readCursor(S.get()),null,(B,M)=>{Ee[B]=M.clone()})}),function S(B,M,A,N,X,Y){const ee=l(M);if(ee&&v(ee))if(ee.p!=null){const P=ee.p;Ee[P].getPath(),A=Ee[P],N=Ge[P]=s.writeCursor()}else ee.r!==void 0&&(A=null);else o(l(A))&&(A=null);const fe=B.getComponent();if(fe){let P;if((P=fe.d)!=null){const x=te[P];x&&(x.get(),N.mergeTree(x.get()),A=s.readCursor(x.get()))}}let de=0,ae=0;const ye=s.advancer(M,void 0,(P,x)=>{v(x)&&de--}),q=s.advancer(A,(P,x)=>o(x)?-(P-ae)-1:P-ae,(P,x)=>{o(x)&&ae++});for(const P of B)if(typeof P=="number"){const x=ye(P),he=P+de,me=q(he),We=he+ae;N.descend(We),S(B,x,me,N),N.ascend()}else N.descend(P),S(B,ye(P),q(P),N),N.ascend();ye.end(),q.end()}(_e,Q,Q.clone(),oe),oe.reset(),b)return{ok:!1,conflict:b};if(oe.get(),Ge.length){const S=Ge.map(M=>M?M.get():null),B=s.readCursor(nt(oe.get()));if(Se(B,oe,(M,A,N)=>{const X=S[M];X&&(N.mergeTree(X),S[M]=null)}),S.find(M=>M)){const M=s.writeCursor(),A=s.writeCursor();let N=0,X=0;S.forEach(Y=>{Y!=null&&Se(s.readCursor(Y),null,ee=>{const fe=He[ee];M.writeMove(C[fe].getPath(),$[fe].getPath(),N++);const de=se[fe];de&&de.forEach(ae=>{p[ae]||D!==1&&K[ae]!=null||A.writeMove(T[ae].getPath(),g[ae].getPath(),X++)})})}),b={type:d.ConflictType.BLACKHOLE,op1:M.get(),op2:A.get()}}}}return b?{ok:!1,conflict:b}:{ok:!0,result:oe.get()}}const _t=i=>{const u=new Error("Transform detected write conflict");throw u.conflict=i,u.type=u.name="writeConflict",u};function Tt(i,u,y){const D=rt(i,u,y);if(D.ok)return D.result;_t(D.conflict)}const ze=i=>{const u=s.writeCursor();return s.readCursor(i).traverse(u,(y,D)=>{(o(y)||Oe(y))&&D.write("r",!0)}),u.get()},kt=(i,u)=>{const{type:y,op1:D,op2:b}=i;switch(y){case d.ConflictType.DROP_COLLISION:return u==="left"?[null,ze(b)]:[ze(D),null];case d.ConflictType.RM_UNEXPECTED_CONTENT:let C=!1;return s.readCursor(D).traverse(null,$=>{$.r!==void 0&&(C=!0)}),C?[null,ze(b)]:[ze(D),null];case d.ConflictType.BLACKHOLE:return[ze(D),ze(b)];default:throw Error("Unrecognised conflict: "+y)}};function vt(i,u,y,D){let b=null;for(;;){const C=rt(u,y,D);if(C.ok)return ne(b,C.result);{const{conflict:$}=C;i($)||_t($);const[T,g]=kt($,D);u=ne(H(u),T),y=ne(H(y),g),b=ne(b,g)}}}})(Dt);(function(n){var e=Ce&&Ce.__createBinding||(Object.create?function(d,a,l,E){E===void 0&&(E=l),Object.defineProperty(d,E,{enumerable:!0,get:function(){return a[l]}})}:function(d,a,l,E){E===void 0&&(E=l),d[E]=a[l]}),t=Ce&&Ce.__exportStar||function(d,a){for(var l in d)l!=="default"&&!a.hasOwnProperty(l)&&e(a,d,l)};Object.defineProperty(n,"__esModule",{value:!0}),t(Dt,n);var r=ht;Object.defineProperty(n,"ReadCursor",{enumerable:!0,get:function(){return r.ReadCursor}}),Object.defineProperty(n,"WriteCursor",{enumerable:!0,get:function(){return r.WriteCursor}});var s=gt;Object.defineProperty(n,"ConflictType",{enumerable:!0,get:function(){return s.ConflictType}})})(V);class At{constructor(){F(this,"drawingManagerData",{});F(this,"_oldDrawingManagerData",{});F(this,"_focusDrawings",[]);F(this,"_remove$",new we.Subject);F(this,"remove$",this._remove$.asObservable());F(this,"_add$",new we.Subject);F(this,"add$",this._add$.asObservable());F(this,"_update$",new we.Subject);F(this,"update$",this._update$.asObservable());F(this,"_order$",new we.Subject);F(this,"order$",this._order$.asObservable());F(this,"_group$",new we.Subject);F(this,"group$",this._group$.asObservable());F(this,"_ungroup$",new we.Subject);F(this,"ungroup$",this._ungroup$.asObservable());F(this,"_refreshTransform$",new we.Subject);F(this,"refreshTransform$",this._refreshTransform$.asObservable());F(this,"_visible$",new we.Subject);F(this,"visible$",this._visible$.asObservable());F(this,"_focus$",new we.Subject);F(this,"focus$",this._focus$.asObservable());F(this,"_featurePluginUpdate$",new we.Subject);F(this,"featurePluginUpdate$",this._featurePluginUpdate$.asObservable());F(this,"_featurePluginAdd$",new we.Subject);F(this,"featurePluginAdd$",this._featurePluginAdd$.asObservable());F(this,"_featurePluginRemove$",new we.Subject);F(this,"featurePluginRemove$",this._featurePluginRemove$.asObservable());F(this,"_featurePluginOrderUpdate$",new we.Subject);F(this,"featurePluginOrderUpdate$",this._featurePluginOrderUpdate$.asObservable());F(this,"_featurePluginGroupUpdate$",new we.Subject);F(this,"featurePluginGroupUpdate$",this._featurePluginGroupUpdate$.asObservable());F(this,"_featurePluginUngroupUpdate$",new we.Subject);F(this,"featurePluginUngroupUpdate$",this._featurePluginUngroupUpdate$.asObservable());F(this,"_visible",!0);F(this,"_editable",!0)}dispose(){this._remove$.complete(),this._add$.complete(),this._update$.complete(),this._order$.complete(),this._focus$.complete(),this._featurePluginUpdate$.complete(),this._featurePluginAdd$.complete(),this._featurePluginRemove$.complete(),this._featurePluginOrderUpdate$.complete(),this.drawingManagerData={},this._oldDrawingManagerData={}}visibleNotification(e){this._visible$.next(e)}refreshTransform(e){e.forEach(t=>{const r=this._getCurrentBySearch(t);r!=null&&(r.transform=t.transform,r.transforms=t.transforms,r.isMultiTransform=t.isMultiTransform)}),this.refreshTransformNotification(e)}getDrawingDataForUnit(e){return this.drawingManagerData[e]||{}}removeDrawingDataForUnit(e){const t=this.drawingManagerData[e];if(t==null)return;delete this.drawingManagerData[e];const r=[];Object.keys(t).forEach(s=>{const d=t[s];(d==null?void 0:d.data)!=null&&Object.keys(d.data).forEach(a=>{r.push({unitId:e,subUnitId:s,drawingId:a})})}),r.length>0&&this.removeNotification(r)}registerDrawingData(e,t){this.drawingManagerData[e]=t}initializeNotification(e){const t=[],r=this.drawingManagerData[e];r!=null&&(Object.keys(r).forEach(s=>{this._establishDrawingMap(e,s);const d=r[s];Object.keys(d.data).forEach(a=>{const l=d.data[a];l.unitId=e,l.subUnitId=s,t.push(l)})}),t.length>0&&this.addNotification(t))}getDrawingData(e,t){return this._getDrawingData(e,t)}setDrawingData(e,t,r){this.drawingManagerData[e][t].data=r}getBatchAddOp(e){const t=[],r=[],s=[];e.forEach(G=>{const{op:v,invertOp:o}=this._addByParam(G);t.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),r.push(v),s.push(o)});const d=r.reduce(V.type.compose,null),a=s.reduce(V.type.compose,null),{unitId:l,subUnitId:E}=e[0];return{undo:a,redo:d,unitId:l,subUnitId:E,objects:t}}getBatchRemoveOp(e){const t=[],r=[];e.forEach(E=>{const{op:G,invertOp:v}=this._removeByParam(E);t.unshift(G),r.push(v)});const s=t.reduce(V.type.compose,null),d=r.reduce(V.type.compose,null),{unitId:a,subUnitId:l}=e[0];return{undo:d,redo:s,unitId:a,subUnitId:l,objects:e}}getBatchUpdateOp(e){const t=[],r=[],s=[];e.forEach(G=>{const{op:v,invertOp:o}=this._updateByParam(G);t.push({unitId:G.unitId,subUnitId:G.subUnitId,drawingId:G.drawingId}),r.push(v),s.push(o)});const d=r.reduce(V.type.compose,null),a=s.reduce(V.type.compose,null),{unitId:l,subUnitId:E}=e[0];return{undo:a,redo:d,unitId:l,subUnitId:E,objects:t}}removeNotification(e){this._remove$.next(e)}addNotification(e){this._add$.next(e)}updateNotification(e){this._update$.next(e)}orderNotification(e){this._order$.next(e)}groupUpdateNotification(e){this._group$.next(e)}ungroupUpdateNotification(e){this._ungroup$.next(e)}refreshTransformNotification(e){this._refreshTransform$.next(e)}getGroupDrawingOp(e){const t=[],{unitId:r,subUnitId:s}=e[0].parent;e.forEach(l=>{t.push(this._getGroupDrawingOp(l))});const d=t.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:r,subUnitId:s,objects:e}}getUngroupDrawingOp(e){const t=[],{unitId:r,subUnitId:s}=e[0].parent;e.forEach(l=>{t.push(this._getUngroupDrawingOp(l))});const d=t.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(d,this.drawingManagerData),redo:d,unitId:r,subUnitId:s,objects:e}}getDrawingsByGroup(e){const{unitId:t,subUnitId:r,drawingId:s}=e;if(this.getDrawingByParam({unitId:t,subUnitId:r,drawingId:s})==null)return[];const a=this._getDrawingData(t,r),l=[];return Object.keys(a).forEach(E=>{const G=a[E];G.groupId===s&&l.push(G)}),l}_getGroupDrawingOp(e){const{parent:t,children:r}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];l.push(V.insertOp([s,d,"data",a],t));let E=Number.NEGATIVE_INFINITY;return r.forEach(G=>{const{unitId:v,subUnitId:o,drawingId:c}=G,h=this._hasDrawingOrder({unitId:v,subUnitId:o,drawingId:c});E=Math.max(E,h),l.push(...this._getUpdateParamCompareOp(G,this.getDrawingByParam({unitId:v,subUnitId:o,drawingId:c})))}),E===Number.NEGATIVE_INFINITY&&(E=this._getDrawingOrder(s,d).length),l.push(V.insertOp([s,d,"order",E],a)),l.reduce(V.type.compose,null)}_getUngroupDrawingOp(e){const{parent:t,children:r}=e,{unitId:s,subUnitId:d,drawingId:a}=t,l=[];return r.forEach(E=>{const{unitId:G,subUnitId:v,drawingId:o}=E;l.push(...this._getUpdateParamCompareOp(E,this.getDrawingByParam({unitId:G,subUnitId:v,drawingId:o})))}),l.push(V.removeOp([s,d,"data",a],!0)),l.push(V.removeOp([s,d,"order",this._getDrawingOrder(s,d).indexOf(a)],!0)),l.reduce(V.type.compose,null)}applyJson1(e,t,r){this._establishDrawingMap(e,t),this._oldDrawingManagerData={...this.drawingManagerData},this.drawingManagerData=V.type.apply(this.drawingManagerData,r)}featurePluginUpdateNotification(e){this._featurePluginUpdate$.next(e)}featurePluginOrderUpdateNotification(e){this._featurePluginOrderUpdate$.next(e)}featurePluginAddNotification(e){this._featurePluginAdd$.next(e)}featurePluginRemoveNotification(e){this._featurePluginRemove$.next(e)}featurePluginGroupUpdateNotification(e){this._featurePluginGroupUpdate$.next(e)}featurePluginUngroupUpdateNotification(e){this._featurePluginUngroupUpdate$.next(e)}getDrawingByParam(e){return this._getCurrentBySearch(e)}getOldDrawingByParam(e){return this._getOldBySearch(e)}getDrawingOKey(e){const[t,r,s]=e.split("#-#");return this._getCurrentBySearch({unitId:t,subUnitId:r,drawingId:s})}focusDrawing(e){if(e==null){this._focusDrawings=[],this._focus$.next([]);return}const t=[];e.forEach(r=>{var E;const{unitId:s,subUnitId:d,drawingId:a}=r,l=(E=this._getDrawingData(s,d))==null?void 0:E[a];l!=null&&t.push(l)}),t.length>0&&(this._focusDrawings=t,this._focus$.next(t))}getFocusDrawings(){const e=[];return this._focusDrawings.forEach(t=>{var l;const{unitId:r,subUnitId:s,drawingId:d}=t,a=(l=this._getDrawingData(r,s))==null?void 0:l[d];a!=null&&e.push(a)}),e}getDrawingOrder(e,t){return this._getDrawingOrder(e,t)}setDrawingOrder(e,t,r){this.drawingManagerData[e][t].order=r}orderUpdateNotification(e){this._order$.next(e)}getForwardDrawingsOp(e){const{unitId:t,subUnitId:r,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,r),l=[...s];s.forEach(v=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:r,drawingId:v});if(o===-1||o===a.length-1)return;const c=V.moveOp([t,r,"order",o],[t,r,"order",o+1]);d.push(c),l.includes(a[o+1])||l.push(a[o+1])});const E=d.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:r,objects:{...e,drawingIds:l}}}getBackwardDrawingOp(e){const{unitId:t,subUnitId:r,drawingIds:s}=e,d=[],a=this.getDrawingOrder(t,r),l=[...s];s.forEach(v=>{const o=this._hasDrawingOrder({unitId:t,subUnitId:r,drawingId:v});if(o===-1||o===0)return;const c=V.moveOp([t,r,"order",o],[t,r,"order",o-1]);d.push(c),l.includes(a[o-1])||l.push(a[o-1])});const E=d.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(E,this.drawingManagerData),redo:E,unitId:t,subUnitId:r,objects:{...e,drawingIds:l}}}getFrontDrawingsOp(e){const{unitId:t,subUnitId:r,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,r,s),a=[...s],l=this.getDrawingOrder(t,r),E=[];d.forEach(o=>{const{drawingId:c}=o,h=this._getDrawingCount(t,r)-1,j=V.moveOp([t,r,"order",this._getDrawingOrder(t,r).indexOf(c)],[t,r,"order",h]);E.push(j),a.includes(l[h])||a.push(l[h])});const G=E.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:t,subUnitId:r,objects:{...e,drawingIds:a}}}getBackDrawingsOp(e){const{unitId:t,subUnitId:r,drawingIds:s}=e,d=this._getOrderFromSearchParams(t,r,s,!0),a=[...s],l=this.getDrawingOrder(t,r),E=[];d.forEach(o=>{const{drawingId:c}=o,h=V.moveOp([t,r,"order",this._getDrawingOrder(t,r).indexOf(c)],[t,r,"order",0]);E.push(h),a.includes(l[0])||a.push(l[0])});const G=E.reduce(V.type.compose,null);return{undo:V.type.invertWithDoc(G,this.drawingManagerData),redo:G,unitId:t,subUnitId:r,objects:{...e,drawingIds:a}}}_getDrawingCount(e,t){return this.getDrawingOrder(e,t).length||0}_getOrderFromSearchParams(e,t,r,s=!1){return r.map(d=>{const a=this._hasDrawingOrder({unitId:e,subUnitId:t,drawingId:d});return{drawingId:d,zIndex:a}}).sort(s===!1?ke.sortRules:ke.sortRulesByDesc)}_hasDrawingOrder(e){if(e==null)return-1;const{unitId:t,subUnitId:r,drawingId:s}=e;return this._establishDrawingMap(t,r),this._getDrawingOrder(t,r).indexOf(s)}_getCurrentBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:r,drawingId:s}=e;return(l=(a=(d=this.drawingManagerData[t])==null?void 0:d[r])==null?void 0:a.data)==null?void 0:l[s]}_getOldBySearch(e){var d,a,l;if(e==null)return;const{unitId:t,subUnitId:r,drawingId:s}=e;return(l=(a=(d=this._oldDrawingManagerData[t])==null?void 0:d[r])==null?void 0:a.data)==null?void 0:l[s]}_establishDrawingMap(e,t,r){var s;return this.drawingManagerData[e]||(this.drawingManagerData[e]={}),this.drawingManagerData[e][t]||(this.drawingManagerData[e][t]={data:{},order:[]}),r==null?null:(s=this.drawingManagerData[e][t].data)==null?void 0:s[r]}_addByParam(e){const{unitId:t,subUnitId:r,drawingId:s}=e;this._establishDrawingMap(t,r,s);const d=V.insertOp([t,r,"data",s],e),a=V.insertOp([t,r,"order",this._getDrawingOrder(t,r).length],s),l=[d,a].reduce(V.type.compose,null),E=V.type.invertWithDoc(l,this.drawingManagerData);return{op:l,invertOp:E}}_removeByParam(e){if(e==null)return{op:[],invertOp:[]};const{unitId:t,subUnitId:r,drawingId:s}=e;if(this._establishDrawingMap(t,r,s)==null)return{op:[],invertOp:[]};const a=V.removeOp([t,r,"data",s],!0),l=V.removeOp([t,r,"order",this._getDrawingOrder(t,r).indexOf(s)],!0),E=[a,l].reduce(V.type.compose,null),G=V.type.invertWithDoc(E,this.drawingManagerData);return{op:E,invertOp:G}}_updateByParam(e){const{unitId:t,subUnitId:r,drawingId:s}=e,d=this._establishDrawingMap(t,r,s);if(d==null)return{op:[],invertOp:[]};const l=this._getUpdateParamCompareOp(e,d).reduce(V.type.compose,null),E=V.type.invertWithDoc(l,this.drawingManagerData);return{op:l,invertOp:E}}_getUpdateParamCompareOp(e,t){const{unitId:r,subUnitId:s,drawingId:d}=e,a=[];return Object.keys(e).forEach(l=>{const E=e[l],G=t[l];G!==E&&a.push(V.replaceOp([r,s,"data",d,l],G,E))}),a}_getDrawingData(e,t){var r,s;return((s=(r=this.drawingManagerData[e])==null?void 0:r[t])==null?void 0:s.data)||{}}_getDrawingOrder(e,t){var r,s;return((s=(r=this.drawingManagerData[e])==null?void 0:r[t])==null?void 0:s.order)||[]}getDrawingVisible(){return this._visible}getDrawingEditable(){return this._editable}setDrawingVisible(e){this._visible=e}setDrawingEditable(e){this._editable=e}}class Pt extends At{}function Vt({unitId:n,subUnitId:e,drawingId:t},r){return typeof r=="number"?`${n}#-#${e}#-#${t}#-#${r}`:`${n}#-#${e}#-#${t}`}const qt=async n=>new Promise((e,t)=>{const r=new Image;r.src=n,r.onload=()=>{e({width:r.width,height:r.height,image:r})},r.onerror=s=>{t(s)}});var Qe=(n=>(n.URL="URL",n.UUID="UUID",n.BASE64="BASE64",n))(Qe||{}),Ze=(n=>(n.SUCCUSS="0",n.ERROR_EXCEED_SIZE="1",n.ERROR_IMAGE_TYPE="2",n.ERROR_UPLOAD_COUNT_LIMIT="3",n.ERROR_IMAGE="4",n))(Ze||{});const St=ke.createIdentifier("core.image-io.service");class Mt{constructor(){F(this,"_waitCount",0);F(this,"_change$",new we.Subject);F(this,"change$",this._change$);F(this,"_imageSourceCache",new Map)}setWaitCount(e){this._waitCount=e,this._change$.next(e)}getImageSourceCache(e,t){if(t===Qe.BASE64){const r=new Image;return r.src=e,r}return this._imageSourceCache.get(e)}addImageSourceCache(e,t,r){t===Qe.BASE64||r==null||this._imageSourceCache.set(e,r)}async getImage(e){return Promise.resolve(e)}async saveImage(e){return new Promise((t,r)=>{if(!Et.includes(e.type)){r(new Error(Ze.ERROR_IMAGE_TYPE)),this._decreaseWaiting();return}if(e.size>Ct){r(new Error(Ze.ERROR_EXCEED_SIZE)),this._decreaseWaiting();return}const s=new FileReader;s.readAsDataURL(e),s.onload=d=>{var E;const a=(E=d.target)==null?void 0:E.result;if(a==null){r(new Error(Ze.ERROR_IMAGE)),this._decreaseWaiting();return}const l=ke.Tools.generateRandomId(6);t({imageId:l,imageSourceType:Qe.BASE64,source:a,base64Cache:a,status:Ze.SUCCUSS}),this._decreaseWaiting()}})}_decreaseWaiting(){this._waitCount-=1,this._change$.next(this._waitCount)}}const zt="__default_document_sub_component_id20231101__";var Ut=(n=>(n[n.forward=0]="forward",n[n.backward=1]="backward",n[n.front=2]="front",n[n.back=3]="back",n))(Ut||{}),Nt=(n=>(n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n[n.DRAWING_IMAGE=0]="DRAWING_IMAGE",n[n.DRAWING_SHAPE=1]="DRAWING_SHAPE",n[n.DRAWING_CHART=2]="DRAWING_CHART",n[n.DRAWING_TABLE=3]="DRAWING_TABLE",n[n.DRAWING_SMART_ART=4]="DRAWING_SMART_ART",n[n.DRAWING_VIDEO=5]="DRAWING_VIDEO",n[n.DRAWING_GROUP=6]="DRAWING_GROUP",n[n.DRAWING_UNIT=7]="DRAWING_UNIT",n[n.DRAWING_DOM=8]="DRAWING_DOM",n))(Nt||{});const jt=ke.createIdentifier("univer.drawing-manager.service"),Xt="drawing.config",Yt={};var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(n,e,t,r)=>{for(var s=r>1?void 0:r?Jt(e,t):e,d=n.length-1,a;d>=0;d--)(a=n[d])&&(s=(r?a(e,t,s):a(s))||s);return r&&s&&Zt(e,t,s),s},It=(n,e)=>(t,r)=>e(t,r,n);const en="UNIVER_DRAWING_PLUGIN";var at;exports.UniverDrawingPlugin=(at=class extends ke.Plugin{constructor(e=Yt,t,r){super(),this._config=e,this._injector=t,this._configService=r;const{...s}=this._config;this._configService.setConfig(Xt,s)}onStarting(){this._initDependencies()}_initDependencies(){var r;const e=[[St,{useClass:Mt}],[jt,{useClass:Pt}]];ke.mergeOverrideWithDependencies(e,(r=this._config)==null?void 0:r.override).forEach(s=>this._injector.add(s))}},F(at,"pluginName",en),at);exports.UniverDrawingPlugin=Qt([It(1,ke.Inject(ke.Injector)),It(2,ke.IConfigService)],exports.UniverDrawingPlugin);exports.ArrangeTypeEnum=Ut;exports.DEFAULT_DOCUMENT_SUB_COMPONENT_ID=zt;exports.DRAWING_IMAGE_ALLOW_IMAGE_LIST=Et;exports.DRAWING_IMAGE_ALLOW_SIZE=Ct;exports.DRAWING_IMAGE_COUNT_LIMIT=xt;exports.DRAWING_IMAGE_HEIGHT_LIMIT=Bt;exports.DRAWING_IMAGE_WIDTH_LIMIT=Wt;exports.DrawingManagerService=Pt;exports.DrawingTypeEnum=Nt;exports.IDrawingManagerService=jt;exports.IImageIoService=St;exports.ImageIoService=Mt;exports.ImageSourceType=Qe;exports.ImageUploadStatusType=Ze;exports.UnitDrawingService=At;exports.getDrawingShapeKeyByDrawingSearch=Vt;exports.getImageSize=qt;
|