12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141 |
- import {
- Ct,
- KC,
- Oa,
- Ot,
- Pt,
- Ra,
- SE,
- Subject,
- XC,
- ar,
- g0,
- kE,
- nu,
- ot,
- re,
- vl
- } from "./chunk-23V3HWTR.js";
- // node_modules/.pnpm/@univerjs+drawing@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/drawing/lib/es/index.js
- var Nt = Object.defineProperty;
- var Rt = (a, e, n) => e in a ? Nt(a, e, { enumerable: true, configurable: true, writable: true, value: n }) : a[e] = n;
- var F = (a, e, n) => Rt(a, typeof e != "symbol" ? e + "" : e, n);
- var mn = 500;
- var On = 500;
- var wn = 10;
- var Yt = 5 * 1024 * 1024;
- var Zt = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/bmp"];
- var Ye = {};
- var et = {};
- var tt = {};
- var mt;
- function Qt() {
- if (mt)
- return tt;
- mt = 1, Object.defineProperty(tt, "__esModule", { value: true });
- function a(t, r) {
- if (Array.isArray(r))
- return false;
- for (let u in t)
- if (!n(t[u], r[u]))
- return false;
- for (let u in r)
- if (t[u] === void 0)
- return false;
- return true;
- }
- function e(t, r) {
- if (!Array.isArray(r) || t.length !== r.length)
- return false;
- for (let u = 0; u < t.length; u++)
- if (!n(t[u], r[u]))
- return false;
- return true;
- }
- function n(t, r) {
- return t === r ? true : t === null || r === null || typeof t != "object" || typeof r != "object" ? false : Array.isArray(t) ? e(t, r) : a(t, r);
- }
- return tt.default = n, tt;
- }
- var nt = {};
- var Ot2;
- function en() {
- if (Ot2)
- return nt;
- Ot2 = 1, Object.defineProperty(nt, "__esModule", { value: true });
- function a(e) {
- if (e === null)
- return null;
- if (Array.isArray(e))
- return e.map(a);
- if (typeof e == "object") {
- const n = {};
- for (let t in e)
- n[t] = a(e[t]);
- return n;
- } else
- return e;
- }
- return nt.default = a, nt;
- }
- var lt = {};
- var wt;
- function Mt() {
- return wt || (wt = 1, function(a) {
- Object.defineProperty(a, "__esModule", { value: true }), a.eachChildOf = a.advancer = a.readCursor = a.writeCursor = a.WriteCursor = a.ReadCursor = a.isValidPathItem = void 0;
- function e(_, s) {
- if (!_)
- throw new Error(s);
- }
- const n = (_) => _ != null && typeof _ == "object" && !Array.isArray(_), t = (_, s) => (
- // All the numbers, then all the letters. Just as the gods of ascii intended.
- typeof _ == typeof s ? _ > s : typeof _ == "string" && typeof s == "number"
- );
- function r(_, s) {
- for (let d in _) {
- const h = d;
- s.write(h, _[h]);
- }
- }
- a.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, k = this.idx;
- for (; k >= 0; )
- s.unshift(d[k]), k === 0 ? (k = this.indexes[h * 2], d = this.parents[h--]) : k -= n(d[k - 1]) ? 2 : 1;
- return s;
- }
- }
- class o extends u {
- get() {
- return this.container ? this.container.slice(this.idx + 1) : null;
- }
- // Its only valid to call this after descending into a child.
- 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 false;
- 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, true;
- }
- nextSibling() {
- if (e(this.parents.length === this.indexes.length / 2), this.idx > 0 || this.parents.length === 0)
- return false;
- const s = this.indexes[this.indexes.length - 1] + 1, d = this.parents[this.parents.length - 1];
- return s >= d.length ? false : (e(!isNaN(s)), this.indexes[this.indexes.length - 1] = s, this.container = d[s], true);
- }
- _init(s, d, h, k) {
- this.container = s, this.idx = d, this.parents = h.slice(), this.indexes = k.slice();
- }
- clone() {
- const s = new o();
- return s._init(this.container, this.idx, this.parents, this.indexes), s;
- }
- *[Symbol.iterator]() {
- if (this.descendFirst()) {
- do
- yield this.getKey();
- while (this.nextSibling());
- this.ascend();
- }
- }
- // TODO(cleanup): Consider moving these functions out of cursor, since
- // they're really just helper methods.
- // It'd be really nice to do this using generators.
- traverse(s, d) {
- const h = this.getComponent();
- h && d(h, s);
- for (const k of this)
- s && s.descend(k), this.traverse(s, d), s && s.ascend();
- }
- eachPick(s, d) {
- this.traverse(s, (h, k) => {
- h.p != null && d(h.p, k);
- });
- }
- eachDrop(s, d) {
- this.traverse(s, (h, k) => {
- h.d != null && d(h.d, k);
- });
- }
- }
- a.ReadCursor = o;
- class l 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 k = this.container.splice(h, this.container.length - h);
- this.container.push(k), this.lcIdx > -1 && (this.lcIdx = h);
- }
- for (this.indexes.push(this.idx), this.parents.push(this.container), this.lcIdx !== -1 && (e(t(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 k = [d];
- this.container.splice(h, 0, k), this.container = k;
- }
- }
- }
- this.pendingDescent.length = 0;
- }
- reset() {
- this.lcIdx = -1;
- }
- // Creates and returns a component, creating one if need be. You should
- // probably write to it immediately - ops are not valid with empty
- // components.
- 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 (!a.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, k = this.parents.length;
- let Y = 0;
- for (let pe = 0; pe < s.length; pe++) {
- const Z = s[pe];
- typeof Z == "string" || typeof Z == "number" ? (Y++, this.descend(Z)) : Array.isArray(Z) ? this.mergeTree(Z, d) : typeof Z == "object" && d(Z, this);
- }
- for (; Y--; )
- this.ascend();
- this.lcIdx = this.parents.length === k ? h : -1;
- }
- at(s, d) {
- this.descendPath(s), d(this);
- for (let h = 0; h < s.length; h++)
- this.ascend();
- return this;
- }
- // This is used by helpers, so the strict ordering guarantees are
- // relaxed.
- 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;
- }
- }
- a.WriteCursor = l, a.writeCursor = () => new l(), a.readCursor = (_) => new o(_);
- function E(_, s, d) {
- let h, k;
- k = h = _ ? _.descendFirst() : false;
- function Y(pe) {
- let Z;
- for (; k; ) {
- const Ce = Z = _.getKey();
- if (pe != null) {
- let Ge = false;
- if (s && typeof Ce == "number" && (Z = s(Ce, _.getComponent()), Z < 0 && (Z = ~Z, Ge = true)), t(Z, pe))
- return null;
- if (Z === pe && !Ge)
- return _;
- }
- d && typeof Z == "number" && d(Z, _.getComponent()), k = _.nextSibling();
- }
- return null;
- }
- return Y.end = () => {
- h && _.ascend();
- }, Y;
- }
- a.advancer = E;
- function x(_, s, d) {
- let h, k, Y, pe;
- for (h = k = _ && _.descendFirst(), Y = pe = s && s.descendFirst(); h || Y; ) {
- let Z = h ? _.getKey() : null, Ce = Y ? s.getKey() : null;
- Z !== null && Ce !== null && (t(Ce, Z) ? Ce = null : Z !== Ce && (Z = null)), d(Z == null ? Ce : Z, Z != null ? _ : null, Ce != null ? s : null), Z != null && h && (h = _.nextSibling()), Ce != null && Y && (Y = s.nextSibling());
- }
- k && _.ascend(), pe && s.ascend();
- }
- a.eachChildOf = x;
- }(lt)), lt;
- }
- var ut = {};
- var bt;
- function St() {
- return bt || (bt = 1, function(a) {
- Object.defineProperty(a, "__esModule", { value: true }), a.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";
- }(a.ConflictType || (a.ConflictType = {}));
- }(ut)), ut;
- }
- var Fe = {};
- var Ve = {};
- var vt;
- function pt() {
- return vt || (vt = 1, Object.defineProperty(Ve, "__esModule", { value: true }), Ve.uniToStrPos = Ve.strPosToUni = void 0, Ve.strPosToUni = (a, e = a.length) => {
- let n = 0, t = 0;
- for (; t < e; t++) {
- const r = a.charCodeAt(t);
- r >= 55296 && r <= 57343 && (n++, t++);
- }
- if (t !== e)
- throw Error("Invalid offset - splits unicode bytes");
- return t - n;
- }, Ve.uniToStrPos = (a, e) => {
- let n = 0;
- for (; e > 0; e--) {
- const t = a.charCodeAt(n);
- n += t >= 55296 && t <= 57343 ? 2 : 1;
- }
- return n;
- }), Ve;
- }
- var dt = {};
- var Ct2;
- function ht() {
- return Ct2 || (Ct2 = 1, function(a) {
- Object.defineProperty(a, "__esModule", { value: true }), a.uniSlice = a.dlen = a.eachOp = void 0;
- const e = pt(), n = (f) => {
- if (!Array.isArray(f))
- throw Error("Op must be an array of components");
- let y = null;
- for (let v = 0; v < f.length; v++) {
- const L = f[v];
- switch (typeof L) {
- case "object":
- if (typeof L.d != "number" && typeof L.d != "string")
- throw Error("Delete must be number or string");
- if (a.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 y == "number")
- throw Error("Adjacent skip components should be combined");
- break;
- }
- y = L;
- }
- if (typeof y == "number")
- throw Error("Op has a trailing skip");
- };
- function t(f, y) {
- let v = 0, L = 0;
- for (let z = 0; z < f.length; z++) {
- const q = f[z];
- switch (y(q, v, L), typeof q) {
- case "object":
- v += a.dlen(q.d);
- break;
- case "string":
- L += e.strPosToUni(q);
- break;
- case "number":
- v += q, L += q;
- break;
- }
- }
- }
- a.eachOp = t;
- function r(f, y) {
- const v = [], L = l(v);
- return t(f, (z, q, Ee) => {
- L(y(z, q, Ee));
- }), s(v);
- }
- const u = (f) => f, o = (f) => r(f, u);
- a.dlen = (f) => typeof f == "number" ? f : e.strPosToUni(f);
- const l = (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 v = f[f.length - 1];
- v.d = typeof v.d == "string" && typeof y.d == "string" ? v.d + y.d : a.dlen(v.d) + a.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);
- a.uniSlice = (f, y, v) => {
- const L = e.uniToStrPos(f, y), z = v == null ? 1 / 0 : e.uniToStrPos(f, v);
- return f.slice(L, z);
- };
- const x = (f, y, v) => typeof f == "number" ? v == null ? f - y : Math.min(f, v) - y : a.uniSlice(f, y, v), _ = (f) => {
- let y = 0, v = 0;
- return { take: (q, Ee) => {
- if (y === f.length)
- return q === -1 ? null : q;
- const de = f[y];
- let ne;
- if (typeof de == "number")
- return q === -1 || de - v <= q ? (ne = de - v, ++y, v = 0, ne) : (v += q, q);
- if (typeof de == "string") {
- if (q === -1 || Ee === "i" || e.strPosToUni(de.slice(v)) <= q)
- return ne = de.slice(v), ++y, v = 0, ne;
- {
- const le = v + e.uniToStrPos(de.slice(v), q);
- return ne = de.slice(v, le), v = le, ne;
- }
- } else {
- if (q === -1 || Ee === "d" || a.dlen(de.d) - v <= q)
- return ne = { d: x(de.d, v) }, ++y, v = 0, ne;
- {
- let le = x(de.d, v, v + q);
- return v += q, { d: le };
- }
- }
- }, peek: () => f[y] };
- }, s = (f) => (f.length > 0 && typeof f[f.length - 1] == "number" && f.pop(), f);
- function d(f, y, v) {
- if (v !== "left" && v !== "right")
- throw Error("side (" + v + ") must be 'left' or 'right'");
- n(f), n(y);
- const L = [], z = l(L), { take: q, peek: Ee } = _(f);
- for (let ne = 0; ne < y.length; ne++) {
- const le = y[ne];
- let ge, De;
- switch (typeof le) {
- case "number":
- for (ge = le; ge > 0; )
- De = q(ge, "i"), z(De), typeof De != "string" && (ge -= E(De));
- break;
- case "string":
- v === "left" && typeof Ee() == "string" && z(q(-1)), z(e.strPosToUni(le));
- break;
- case "object":
- for (ge = a.dlen(le.d); ge > 0; )
- switch (De = q(ge, "i"), typeof De) {
- case "number":
- ge -= De;
- break;
- case "string":
- z(De);
- break;
- case "object":
- ge -= a.dlen(De.d);
- }
- break;
- }
- }
- let de;
- for (; de = q(-1); )
- z(de);
- return s(L);
- }
- function h(f, y) {
- n(f), n(y);
- const v = [], L = l(v), { take: z } = _(f);
- for (let Ee = 0; Ee < y.length; Ee++) {
- const de = y[Ee];
- let ne, le;
- switch (typeof de) {
- case "number":
- for (ne = de; ne > 0; )
- le = z(ne, "d"), L(le), typeof le != "object" && (ne -= E(le));
- break;
- case "string":
- L(de);
- break;
- case "object":
- ne = a.dlen(de.d);
- let ge = 0;
- for (; ge < ne; )
- switch (le = z(ne - ge, "d"), typeof le) {
- case "number":
- L({ d: x(de.d, ge, ge + le) }), ge += le;
- break;
- case "string":
- ge += e.strPosToUni(le);
- break;
- case "object":
- L(le);
- }
- break;
- }
- }
- let q;
- for (; q = z(-1); )
- L(q);
- return s(v);
- }
- const k = (f, y) => {
- let v = 0;
- for (let L = 0; L < y.length && f > v; L++) {
- const z = y[L];
- switch (typeof z) {
- case "number": {
- v += z;
- break;
- }
- case "string":
- const q = e.strPosToUni(z);
- v += q, f += q;
- break;
- case "object":
- f -= Math.min(a.dlen(z.d), f - v);
- break;
- }
- }
- return f;
- }, Y = (f, y) => typeof f == "number" ? k(f, y) : f.map((v) => k(v, y));
- function pe(f, y, v) {
- return r(f, (L, z) => typeof L == "object" && typeof L.d == "number" ? { d: v.slice(y, z, z + L.d) } : L);
- }
- function Z(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 Ce(f) {
- return r(f, (y) => typeof y == "object" && typeof y.d == "string" ? { d: e.strPosToUni(y.d) } : y);
- }
- function Ge(f) {
- let y = true;
- return t(f, (v) => {
- typeof v == "object" && typeof v.d == "number" && (y = false);
- }), y;
- }
- function me(f) {
- return {
- name: "text-unicode",
- uri: "http://sharejs.org/types/text-unicode",
- trim: s,
- normalize: o,
- checkOp: n,
- /** Create a new text snapshot.
- *
- * @param {string} initial - initial snapshot data. Optional. Defaults to ''.
- * @returns {Snap} Initial document snapshot object
- */
- create(y = "") {
- if (typeof y != "string")
- throw Error("Initial data must be a string");
- return f.create(y);
- },
- /** Apply an operation to a document snapshot
- */
- apply(y, v) {
- n(v);
- const L = f.builder(y);
- for (let z = 0; z < v.length; z++) {
- const q = v[z];
- switch (typeof q) {
- case "number":
- L.skip(q);
- break;
- case "string":
- L.append(q);
- break;
- case "object":
- L.del(a.dlen(q.d));
- break;
- }
- }
- return L.build();
- },
- transform: d,
- compose: h,
- transformPosition: k,
- transformSelection: Y,
- isInvertible: Ge,
- makeInvertible(y, v) {
- return pe(y, v, f);
- },
- stripInvertible: Ce,
- invert: Z,
- invertWithDoc(y, v) {
- return Z(pe(y, v, f));
- },
- isNoop: (y) => y.length === 0
- };
- }
- a.default = me;
- }(dt)), dt;
- }
- var rt = {};
- var It;
- function tn() {
- if (It)
- return rt;
- It = 1, Object.defineProperty(rt, "__esModule", { value: true });
- const a = ht(), e = pt();
- function n(t, r) {
- return {
- // Returns the text content of the document
- get: t,
- // Returns the number of characters in the string
- getLength() {
- return t().length;
- },
- // Insert the specified text at the given position in the document
- insert(u, o, l) {
- const E = e.strPosToUni(t(), u);
- return r([E, o], l);
- },
- remove(u, o, l) {
- const E = e.strPosToUni(t(), u);
- return r([E, { d: o }], l);
- },
- // When you use this API, you should implement these two methods
- // in your editing context.
- //onInsert: function(pos, text) {},
- //onRemove: function(pos, removedLength) {},
- _onOp(u) {
- a.eachOp(u, (o, l, E) => {
- switch (typeof o) {
- case "string":
- this.onInsert && this.onInsert(E, o);
- break;
- case "object":
- const x = a.dlen(o.d);
- this.onRemove && this.onRemove(E, x);
- }
- });
- },
- onInsert: null,
- onRemove: null
- };
- }
- return rt.default = n, n.provides = { text: true }, rt;
- }
- var Et;
- function nn() {
- return Et || (Et = 1, function(a) {
- var e = Fe.__createBinding || (Object.create ? function(d, h, k, Y) {
- Y === void 0 && (Y = k), Object.defineProperty(d, Y, { enumerable: true, get: function() {
- return h[k];
- } });
- } : function(d, h, k, Y) {
- Y === void 0 && (Y = k), d[Y] = h[k];
- }), n = Fe.__setModuleDefault || (Object.create ? function(d, h) {
- Object.defineProperty(d, "default", { enumerable: true, value: h });
- } : function(d, h) {
- d.default = h;
- }), t = Fe.__importStar || function(d) {
- if (d && d.__esModule)
- return d;
- var h = {};
- if (d != null)
- for (var k in d)
- Object.hasOwnProperty.call(d, k) && e(h, d, k);
- return n(h, d), h;
- }, r = Fe.__importDefault || function(d) {
- return d && d.__esModule ? d : { default: d };
- };
- Object.defineProperty(a, "__esModule", { value: true }), a.type = a.remove = a.insert = void 0;
- const u = pt(), o = t(ht()), l = r(tn()), 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(k) {
- let Y = u.uniToStrPos(d, k);
- if (Y > d.length)
- throw Error("The op is too long for this document");
- h.push(d.slice(0, Y)), d = d.slice(Y);
- },
- append(k) {
- h.push(k);
- },
- del(k) {
- d = d.slice(u.uniToStrPos(d, k));
- },
- build() {
- return h.join("") + d;
- }
- };
- },
- slice: o.uniSlice
- }, x = o.default(E), _ = Object.assign(Object.assign({}, x), { api: l.default });
- a.type = _, a.insert = (d, h) => h.length === 0 ? [] : d === 0 ? [h] : [d, h], a.remove = (d, h) => o.dlen(h) === 0 ? [] : d === 0 ? [{ d: h }] : [d, { d: h }];
- var s = ht();
- Object.defineProperty(a, "makeType", { enumerable: true, get: function() {
- return s.default;
- } });
- }(Fe)), Fe;
- }
- var Dt;
- function rn() {
- return Dt || (Dt = 1, function(a) {
- var e = et.__importDefault || function(i) {
- return i && i.__esModule ? i : {
- default: i
- };
- };
- Object.defineProperty(a, "__esModule", {
- value: true
- }), a.editOp = a.replaceOp = a.insertOp = a.moveOp = a.removeOp = a.type = void 0;
- const n = e(Qt()), t = e(en()), r = Mt(), u = St();
- function o(i, c) {
- if (!i)
- throw new Error(c);
- }
- a.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: Z,
- checkValidOp: z,
- normalize: q,
- apply: Ee,
- transformPosition: de,
- compose: ne,
- tryTransform: st,
- transform: jt,
- makeInvertible: De,
- invert: le,
- invertWithDoc: kt,
- RM_UNEXPECTED_CONTENT: u.ConflictType.RM_UNEXPECTED_CONTENT,
- DROP_COLLISION: u.ConflictType.DROP_COLLISION,
- BLACKHOLE: u.ConflictType.BLACKHOLE,
- transformNoConflict: (i, c, O) => yt(() => true, i, c, O),
- typeAllowingConflictsPred: (i) => Object.assign(Object.assign({}, a.type), {
- transform: (c, O, D) => yt(i, c, O, D)
- })
- };
- const l = (i) => i ? i.getComponent() : null;
- function E(i) {
- return i && typeof i == "object" && !Array.isArray(i);
- }
- const x = (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;
- }
- a.removeOp = (i, c = true) => r.writeCursor().writeAtPath(i, "r", c).get(), a.moveOp = (i, c) => r.writeCursor().writeMove(i, c).get(), a.insertOp = (i, c) => r.writeCursor().writeAtPath(i, "i", c).get(), a.replaceOp = (i, c, O) => r.writeCursor().at(i, (D) => {
- D.write("r", c), D.write("i", O);
- }).get(), a.editOp = (i, c, O, D = false) => r.writeCursor().at(i, (w) => y(w, c, O, D)).get();
- const k = (i, c) => i != null && (typeof c == "number" ? Array.isArray(i) : typeof i == "object"), Y = (i, c) => k(i, c) ? i[c] : void 0, pe = {};
- function Z(i) {
- let c = i.type ? i.type : i;
- c.name && (pe[c.name] = c), c.uri && (pe[c.uri] = c);
- }
- const Ce = (i) => {
- const c = pe[i];
- if (c)
- return c;
- throw Error("Missing type: " + i);
- };
- Z(nn());
- const Ge = (i, c) => i + c;
- Z({
- name: "number",
- apply: Ge,
- compose: Ge,
- invert: (i) => -i,
- transform: (i) => i
- });
- const me = (i) => i == null ? null : i.et ? Ce(i.et) : i.es ? pe["text-unicode"] : i.ena != null ? pe.number : null, f = (i) => i.es ? i.es : i.ena != null ? i.ena : i.e, y = (i, c, O, D = false) => {
- const [w, I] = typeof c == "string" ? [Ce(c), c] : [c, c.name];
- !D && w.isNoop && w.isNoop(O) || (I === "number" ? i.write("ena", O) : I === "text-unicode" ? i.write("es", O) : (i.write("et", I), i.write("e", O)));
- };
- function v(i) {
- o(typeof i == "number"), o(i >= 0), o(i === (0 | i));
- }
- function L(i) {
- typeof i == "number" ? v(i) : o(typeof i == "string");
- }
- function z(i) {
- if (i === null)
- return;
- const c = /* @__PURE__ */ new Set(), O = /* @__PURE__ */ new Set(), D = (I) => {
- let R = true, $ = false;
- for (let p in I) {
- const m = I[p];
- if (R = false, o(p === "p" || p === "r" || p === "d" || p === "i" || p === "e" || p === "es" || p === "ena" || p === "et", "Invalid component item '" + p + "'"), p === "p")
- v(m), o(!c.has(m)), c.add(m), o(I.r === void 0);
- else if (p === "d")
- v(m), o(!O.has(m)), O.add(m), o(I.i === void 0);
- else if (p === "e" || p === "es" || p === "ena") {
- o(!$), $ = true;
- const b = me(I);
- o(b, "Missing type in edit"), b.checkValidOp && b.checkValidOp(f(I));
- }
- }
- o(!R);
- }, w = (I, R, $) => {
- if (!Array.isArray(I))
- throw Error("Op must be null or a list");
- if (I.length === 0)
- throw Error("Empty descent");
- R || L(I[0]);
- let p = 1, m = 0, b = 0;
- for (let C = 0; C < I.length; C++) {
- const N = I[C];
- if (o(N != null), Array.isArray(N)) {
- const B = w(N, false);
- if (m) {
- const g = typeof b, S = typeof B;
- g === S ? o(b < B, "descent keys are not in order") : o(g === "number" && S === "string");
- }
- b = B, m++, p = 3;
- } else
- typeof N == "object" ? (o(p === 1, `Prev not scalar - instead ${p}`), D(N), p = 2) : (o(p !== 3), L(N), o(r.isValidPathItem(N), "Invalid path key"), p = 1);
- }
- return o(m !== 1, "Operation makes multiple descents. Remove some []"), o(p === 2 || p === 3), I[0];
- };
- w(i, true), o(c.size === O.size, "Mismatched picks and drops in op");
- for (let I = 0; I < c.size; I++)
- o(c.has(I)), o(O.has(I));
- }
- function q(i) {
- let c = 0, O = [];
- const D = r.writeCursor();
- return D.mergeTree(i, (w, I) => {
- const R = me(w);
- if (R) {
- const p = f(w);
- y(I, R, R.normalize ? R.normalize(p) : p);
- }
- for (const p of ["r", "p", "i", "d"])
- if (w[p] !== void 0) {
- const m = p === "p" || p === "d" ? ($ = w[p], O[$] == null && (O[$] = c++), O[$]) : w[p];
- I.write(p, m);
- }
- var $;
- }), D.get();
- }
- function Ee(i, c) {
- if (z(c), c === null)
- return i;
- const O = [];
- return function D(w, I) {
- let R = w, $ = 0, p = {
- root: w
- }, m = 0, b = p, C = "root";
- function N() {
- for (; m < $; m++) {
- let B = I[m];
- typeof B != "object" && (o(k(b, C)), b = b[C] = x(b[C]), C = B);
- }
- }
- for (; $ < I.length; $++) {
- const B = I[$];
- if (Array.isArray(B)) {
- const g = D(R, B);
- g !== R && g !== void 0 && (N(), R = b[C] = g);
- } else if (typeof B == "object") {
- B.d != null ? (N(), R = h(b, C, O[B.d])) : B.i !== void 0 && (N(), R = h(b, C, B.i));
- const g = me(B);
- if (g)
- N(), R = b[C] = g.apply(R, f(B));
- else if (B.e !== void 0)
- throw Error("Subtype " + B.et + " undefined");
- } else
- R = Y(R, B);
- }
- return p.root;
- }(i = function D(w, I) {
- const R = [];
- let $ = 0;
- for (; $ < I.length; $++) {
- const C = I[$];
- if (Array.isArray(C))
- break;
- typeof C != "object" && (R.push(w), w = Y(w, C));
- }
- for (let C = I.length - 1; C >= $; C--)
- w = D(w, I[C]);
- for (--$; $ >= 0; $--) {
- const C = I[$];
- if (typeof C != "object") {
- const N = R.pop();
- w = w === Y(N, C) ? N : w === void 0 ? d(N, C) : (m = C, b = w, (p = x(p = N))[m] = b, p);
- } else
- _(C) && (o(w !== void 0, "Cannot pick up or remove undefined"), C.p != null && (O[C.p] = w), w = void 0);
- }
- var p, m, b;
- return w;
- }(i, c), c);
- }
- function de(i, c) {
- i = i.slice(), z(c);
- const O = r.readCursor(c);
- let D, w, I = false;
- const R = [];
- for (let p = 0; ; p++) {
- const m = i[p], b = O.getComponent();
- if (b && (b.r !== void 0 ? I = true : b.p != null && (I = false, D = b.p, w = p)), p >= i.length)
- break;
- let C = 0;
- const N = r.advancer(O, void 0, (g, S) => {
- _(S) && C++;
- });
- R.unshift(N);
- const B = N(m);
- if (typeof m == "number" && (i[p] -= C), !B)
- break;
- }
- if (R.forEach((p) => p.end()), I)
- return null;
- const $ = () => {
- let p = 0;
- if (D != null) {
- const m = O.getPath();
- p = m.length, i = m.concat(i.slice(w));
- }
- for (; p < i.length; p++) {
- const m = i[p], b = l(O), C = me(b);
- if (C) {
- const g = f(b);
- C.transformPosition && (i[p] = C.transformPosition(i[p], g));
- break;
- }
- let N = 0;
- const B = r.advancer(O, (g, S) => s(S) ? ~(g - N) : g - N, (g, S) => {
- s(S) && N++;
- })(m);
- if (typeof m == "number" && (i[p] += N), !B)
- break;
- }
- };
- return D != null ? O.eachDrop(null, (p) => {
- p === D && $();
- }) : $(), i;
- }
- function ne(i, c) {
- if (z(i), z(c), i == null)
- return c;
- if (c == null)
- return i;
- let O = 0;
- const D = r.readCursor(i), w = r.readCursor(c), I = r.writeCursor(), R = [], $ = [], p = [], m = [], b = [], C = [], N = /* @__PURE__ */ new Set();
- D.traverse(null, (g) => {
- g.p != null && (p[g.p] = D.clone());
- }), w.traverse(null, (g) => {
- g.d != null && (m[g.d] = w.clone());
- });
- const B = r.writeCursor();
- return function g(S, re2, te, K, se, $e, we, ye) {
- o(re2 || te);
- const oe = l(re2), Pe = l(te), Ae = !!Pe && Pe.r !== void 0, Le = !!oe && oe.i !== void 0, Te = oe ? oe.d : null, Ie = Pe ? Pe.p : null, Ne = ($e || Ae) && Ie == null;
- if (Ie != null)
- K = m[Ie], we = $[Ie] = new r.WriteCursor();
- else if (Pe && Pe.r !== void 0)
- K = null;
- else {
- const T = l(K);
- T && T.d != null && (K = null);
- }
- const Q = l(K);
- if (Te != null)
- if (S = p[Te], ye = R[Te] = new r.WriteCursor(), Ne)
- $e && !Ae && ye.write("r", true);
- else {
- const T = b[Te] = O++;
- we.write("d", T);
- }
- else if (oe && oe.i !== void 0)
- S = null;
- else {
- const T = l(S);
- T && T.p != null && (S = null);
- }
- let A;
- Le ? (o(se === void 0), A = oe.i) : A = se;
- const W = (Ie == null ? !Le || $e || Ae : A === void 0) ? null : we.getComponent();
- if (Ie != null) {
- if (!(se !== void 0 || Le)) {
- const T = Te != null ? b[Te] : O++;
- C[Ie] = T, ye.write("p", T);
- }
- } else
- Ae && (Le || se !== void 0 || (Pe.r, ye.write("r", Pe.r)));
- const M = Ne ? null : me(oe), P = me(Q);
- if ((M || P) && (M && M.name, P && P.name), M && P) {
- o(M === P);
- const T = f(oe), G = f(Q), he = M.compose(T, G);
- y(we, M, he), N.add(Q);
- } else
- M ? y(we, M, f(oe)) : P && (y(we, P, f(Q)), N.add(Q));
- const U = typeof A == "object" && A != null;
- let J = false, X = 0, ee = 0, fe = 0, ce = 0, ae = 0;
- const Oe = r.advancer(K, (T, G) => s(G) ? ce - T - 1 : T - ce, (T, G) => {
- s(G) && ce++;
- }), H = r.advancer(S, (T, G) => _(G) ? X - T - 1 : T - X, (T, G) => {
- _(G) && X++;
- });
- if (r.eachChildOf(re2, te, (T, G, he) => {
- let be, Re, qe = T, Me = T, Je = T;
- if (typeof T == "number") {
- let _e = T + fe;
- Re = Oe(_e), Me = _e + ce;
- let ue = T + ee;
- be = H(ue), s(l(Re)) && (be = null), qe = ue + X, Je = T + ae, o(qe >= 0, "p1PickKey is negative"), o(Me >= 0, "p2DropKey is negative");
- const Se = s(l(G)), xe = _(l(he));
- (Se || xe && !Ne) && ae--, Se && ee--, xe && fe--;
- } else
- be = H(T), Re = Oe(T);
- ye.descend(qe), we.descend(Me);
- const ze = U && !s(l(G)) ? A[Je] : void 0, ke = g(be, G, he, Re, ze, Ne, we, ye);
- var je, j, ie;
- U && !Ne ? ze !== ke && (J || (A = Array.isArray(A) ? A.slice() : Object.assign({}, A), J = true), je = A, ie = ke, typeof (j = Je) == "number" ? (o(Array.isArray(je)), o(j < je.length)) : (o(!Array.isArray(je)), o(je[j] !== void 0)), ie === void 0 ? typeof j == "number" ? je.splice(j, 1) : delete je[j] : je[j] = ie) : o(ke === void 0), we.ascend(), ye.ascend();
- }), H.end(), Oe.end(), W != null)
- W.i = A;
- else if (!$e && !Ae && Ie == null)
- return A;
- }(D, D.clone(), w, w.clone(), void 0, false, I, B), I.reset(), I.mergeTree(B.get()), I.reset(), I.get(), R.map((g) => g.get()), $.map((g) => g.get()), D.traverse(I, (g, S) => {
- const re2 = g.p;
- if (re2 != null) {
- const te = b[re2];
- te != null && S.write("p", te);
- const K = R[re2];
- K && K.get(), K && S.mergeTree(K.get());
- } else
- g.r !== void 0 && S.write("r", g.r);
- }), I.reset(), I.get(), w.traverse(I, (g, S) => {
- const re2 = g.d;
- if (re2 != null) {
- const K = C[re2];
- K != null && S.write("d", K);
- const se = $[re2];
- se && S.mergeTree(se.get());
- } else
- g.i !== void 0 && S.write("i", g.i);
- const te = me(g);
- te && !N.has(g) && y(S, te, f(g));
- }), I.get();
- }
- function le(i) {
- if (i == null)
- return null;
- const c = new r.ReadCursor(i), O = new r.WriteCursor();
- let D;
- const w = [], I = [];
- return function R($, p, m) {
- const b = $.getComponent();
- let C, N = false;
- if (b) {
- b.p != null && (p.write("d", b.p), w[b.p] = $.clone()), b.r !== void 0 && p.write("i", b.r), b.d != null && (p.write("p", b.d), m = void 0), b.i !== void 0 && (m = C = b.i);
- const g = me(b);
- g && (m === void 0 ? (D || (D = /* @__PURE__ */ new Set()), D.add(b)) : (f(b), m = g.apply(m, f(b)), N = true));
- }
- let B = 0;
- for (const g of $) {
- p.descend(g);
- const S = typeof g == "number" ? g - B : g, re2 = Y(m, S);
- s($.getComponent()) && B++;
- const te = R($, p, re2);
- if (m !== void 0 && te !== void 0) {
- if (N || (N = true, m = x(m)), !k(m, S))
- throw Error("Cannot modify child - invalid operation");
- m[S] = te;
- }
- p.ascend();
- }
- if (C === void 0)
- return N ? m : void 0;
- p.write("r", m);
- }(c, O, void 0), D && (O.reset(), function R($, p, m) {
- const b = p.getComponent();
- if (b) {
- const g = b.d;
- if (g != null && ($ = w[g], m = I[g] = r.writeCursor()), D.has(b)) {
- const S = me(b);
- if (!S.invert)
- throw Error(`Cannot invert subtype ${S.name}`);
- y(m, S, S.invert(f(b)));
- }
- }
- let C = 0, N = 0;
- const B = r.advancer($, (g, S) => _(S) ? C - g - 1 : g - C, (g, S) => {
- _(S) && C++;
- });
- for (const g of p)
- if (typeof g == "number") {
- const S = g - N, re2 = B(S), te = S + C;
- m.descend(te), R(re2, p, m), s(p.getComponent()) && N++, m.ascend();
- } else
- m.descend(g), R(B(g), p, m), m.ascend();
- B.end();
- }(c.clone(), c, O), I.length && (O.reset(), c.traverse(O, (R, $) => {
- const p = R.p;
- if (p != null) {
- const m = I[p];
- m && m.get(), m && $.mergeTree(m.get());
- }
- }))), O.get();
- }
- const ge = (i, c) => i.some((O) => typeof O == "object" && (Array.isArray(O) ? ge(O, c) : c(O)));
- function De(i, c) {
- if (i == null || !ge(i, (p) => {
- var m;
- return p.r !== void 0 || ((m = me(p)) === null || m === void 0 ? void 0 : m.makeInvertible) != null;
- }))
- return i;
- const O = new r.ReadCursor(i), D = new r.WriteCursor();
- let w = false;
- const I = [], R = [], $ = (p, m, b) => {
- const C = p.getComponent();
- let N = false;
- if (C) {
- C.d != null && m.write("d", C.d), C.i !== void 0 && m.write("i", C.i);
- const g = C.p;
- if (g != null && (I[g] = p.clone(), o(b !== void 0, "Operation picks up at an invalid key"), R[g] = b, m.write("p", C.p)), C.r !== void 0 && b === void 0)
- throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");
- const S = me(C);
- S && (S.makeInvertible ? w = true : y(m, S, f(C), true));
- }
- let B = 0;
- for (const g of p) {
- m.descend(g);
- const S = typeof g == "number" ? g - B : g, re2 = Y(b, S), te = $(p, m, re2);
- re2 !== te && (N || (N = true, b = x(b)), te === void 0 ? (b = d(b, S), typeof g == "number" && B++) : b[S] = te), m.ascend();
- }
- return C && (C.r !== void 0 ? (m.write("r", t.default(b)), b = void 0) : C.p != null && (b = void 0)), b;
- };
- return $(O, D, c), D.get(), w && (D.reset(), function p(m, b, C, N, B) {
- const g = b.getComponent();
- if (g) {
- g.i !== void 0 ? (N = g.i, B = true) : g.d != null && (N = R[g.d], m = I[g.d], B = false, g.d);
- let K = me(g);
- if (K && K.makeInvertible) {
- const se = f(g);
- y(C, K, K.makeInvertible(se, N), true);
- }
- }
- let S = 0, re2 = 0;
- const te = r.advancer(m, (K, se) => _(se) ? S - K - 1 : K - S, (K, se) => {
- _(se) && S++;
- });
- for (const K of b)
- if (typeof K == "number") {
- const se = K - re2, $e = te(se), we = se + S, ye = Y(N, B ? se : we);
- C.descend(K), p($e, b, C, ye, B), s(b.getComponent()) && re2++, C.ascend();
- } else {
- const se = Y(N, K);
- C.descend(K), p(te(K), b, C, se, B), C.ascend();
- }
- te.end();
- }(O.clone(), O, D, c, false)), D.get();
- }
- function kt(i, c) {
- return le(De(i, c));
- }
- const it = (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] = it(D));
- }
- return c;
- };
- function st(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: true,
- result: i
- };
- z(i), z(c);
- let w = null;
- const I = [], R = [], $ = [], p = [], m = [], b = [], C = [], N = [], B = [], g = [], S = [], re2 = [], te = [], K = [], se = [];
- let $e = 0;
- const we = r.readCursor(i), ye = r.readCursor(c), oe = r.writeCursor();
- if (function Q(A, W = null, M) {
- const P = l(W);
- P && (P.r !== void 0 ? M = W.clone() : P.p != null && (M = null, b[P.p] = A.clone()));
- const U = A.getComponent();
- let J;
- U && (J = U.p) != null && (m[J] = W ? W.clone() : null, $[J] = A.clone(), M && (g[J] = true, B[J] = M), P && P.p != null && (K[J] = P.p));
- const X = r.advancer(W);
- for (const ee of A)
- Q(A, X(ee), M);
- X.end();
- }(ye, we, null), function Q(A, W, M, P, U) {
- const J = M.getComponent();
- let X, ee = false;
- J && ((X = J.d) != null ? (p[X] = M.clone(), P != null && (se[P] == null && (se[P] = []), se[P].push(X)), g[X], A = m[X] || null, W = $[X] || null, g[X] ? (U && (S[X] = true), U = B[X] || null) : !U || D !== 1 && K[X] != null || w == null && (w = {
- type: u.ConflictType.RM_UNEXPECTED_CONTENT,
- op1: a.removeOp(U.getPath()),
- op2: a.moveOp(W.getPath(), M.getPath())
- }), ee = true) : J.i !== void 0 && (A = W = null, ee = true, U && w == null && (w = {
- type: u.ConflictType.RM_UNEXPECTED_CONTENT,
- op1: a.removeOp(U.getPath()),
- op2: a.insertOp(M.getPath(), J.i)
- })));
- const fe = l(A);
- fe && (fe.r !== void 0 ? U = A.clone() : fe.p != null && (fe.p, P = fe.p, U = null));
- const ce = me(J);
- ce && U && w == null && (w = {
- type: u.ConflictType.RM_UNEXPECTED_CONTENT,
- op1: a.removeOp(U.getPath()),
- op2: a.editOp(M.getPath(), ce, f(J), true)
- });
- let ae = 0, Oe = 0;
- const H = r.advancer(W, (G, he) => _(he) ? ae - G - 1 : G - ae, (G, he) => {
- _(he) && ae++;
- }), T = r.advancer(A);
- for (const G of M)
- if (typeof G == "number") {
- const he = G - Oe, be = H(he);
- Oe += +Q(T(he + ae), be, M, P, U);
- } else {
- const he = H(G);
- Q(T(G), he, M, P, U);
- }
- return H.end(), T.end(), ee;
- }(we, ye, ye.clone(), null, null), p.map((Q) => Q && Q.get()), w)
- return {
- ok: false,
- conflict: w
- };
- S.map((Q) => !!Q);
- const Pe = [];
- let Ae = null;
- (function Q(A, W, M, P, U) {
- let J = false;
- const X = l(W);
- if (_(X)) {
- const H = X.p;
- H != null ? (M = p[H], P = re2[H] = r.writeCursor(), J = true, U = null) : (M = null, U = W.clone());
- } else
- s(l(M)) && (M = null);
- const ee = A.getComponent();
- if (ee) {
- const H = ee.p;
- H != null ? (U && (N[H] = U), Pe[H] = U || D === 1 && J ? null : P.getComponent(), I[H] = A.clone(), M && (C[H] = M.clone())) : ee.r !== void 0 && (U || P.write("r", true), (U || J) && (Ae == null && (Ae = /* @__PURE__ */ new Set()), Ae.add(ee)));
- }
- let fe = 0, ce = 0;
- const ae = r.advancer(W, void 0, (H, T) => {
- _(T) && fe++;
- }), Oe = r.advancer(M, (H, T) => s(T) ? ~(H - ce) : H - ce, (H, T) => {
- s(T) && ce++;
- });
- if (A)
- for (const H of A)
- if (typeof H == "string") {
- const T = ae(H), G = Oe(H);
- P.descend(H), Q(A, T, G, P, U), P.ascend();
- } else {
- const T = ae(H), G = H - fe, he = _(l(T)) ? null : Oe(G), be = G + ce;
- o(be >= 0), P.descend(be), Q(A, T, he, P, U), P.ascend();
- }
- ae.end(), Oe.end();
- })(we, ye, ye.clone(), oe, null), oe.reset();
- let Le = [];
- if (function Q(A, W, M, P, U, J) {
- o(W);
- const X = W.getComponent();
- let ee = l(P), fe = false;
- const ce = (j, ie, _e) => j ? a.moveOp(j.getPath(), ie.getPath()) : a.insertOp(ie.getPath(), _e.i);
- if (s(X)) {
- const j = X.d;
- j != null && (R[j] = W.clone());
- const ie = j != null ? Pe[j] : null;
- let _e = false;
- if (X.i !== void 0 || j != null && ie) {
- let ue;
- ee && (ee.i !== void 0 || (ue = ee.d) != null && !g[ue]) && (_e = ue != null ? j != null && j === K[ue] : n.default(ee.i, X.i), _e || ue != null && D !== 1 && K[ue] != null || w == null && (w = {
- type: u.ConflictType.DROP_COLLISION,
- op1: ce(j != null ? I[j] : null, W, X),
- op2: ce(ue != null ? $[ue] : null, P, ee)
- })), _e || (J ? w == null && (w = {
- type: u.ConflictType.RM_UNEXPECTED_CONTENT,
- op1: ce(j != null ? I[j] : null, W, X),
- op2: a.removeOp(J.getPath())
- }) : (j != null ? (Le[$e] = j, U.write("d", ie.p = $e++)) : U.write("i", t.default(X.i)), fe = true));
- } else if (j != null && !ie) {
- const ue = N[j];
- ue && (J = ue.clone());
- }
- j != null ? (A = I[j], M = b[j], P = C[j]) : X.i !== void 0 && (A = M = null, _e || (P = null));
- } else
- _(l(A)) && (A = M = P = null);
- const ae = l(A), Oe = l(M);
- if (_(Oe)) {
- const j = Oe.p;
- Oe.r !== void 0 && (!ae || ae.r === void 0) || g[j] ? (P = null, J = M.clone()) : j != null && (P = p[j], D !== 1 && K[j] != null || ((U = te[j]) || (U = te[j] = r.writeCursor()), U.reset(), J = null));
- } else
- !s(X) && s(ee) && (P = null);
- ee = P != null ? P.getComponent() : null;
- const H = me(X);
- if (H) {
- const j = f(X);
- if (J)
- w == null && (w = {
- type: u.ConflictType.RM_UNEXPECTED_CONTENT,
- op1: a.editOp(W.getPath(), H, j, true),
- op2: a.removeOp(J.getPath())
- });
- else {
- const ie = me(ee);
- let _e;
- if (ie) {
- if (H !== ie)
- throw Error("Transforming incompatible types");
- const ue = f(ee);
- _e = H.transform(j, ue, O);
- } else
- _e = t.default(j);
- y(U, H, _e);
- }
- }
- let T = 0, G = 0, he = 0, be = 0, Re = 0, qe = 0, Me = A != null && A.descendFirst(), Je = Me;
- const ze = r.advancer(M, void 0, (j, ie) => {
- _(ie) && he++;
- });
- let ke = P != null && P.descendFirst(), je = ke;
- for (const j of W)
- if (typeof j == "number") {
- let ie;
- const _e = s(W.getComponent()), ue = j - G;
- {
- let Be;
- for (; Me && typeof (Be = A.getKey()) == "number"; ) {
- Be += T;
- const Ue = A.getComponent(), Xe = _(Ue);
- if (Be > ue || Be === ue && (!Xe || D === 0 && _e))
- break;
- if (Xe) {
- T--;
- const Ke = Ue.p;
- K.includes(Ke), Ue.d, l(te[Ue.d]), _(l(te[Ue.d])), (Ue.r === void 0 || Ae && Ae.has(Ue)) && (Ke == null || !Pe[Ke] || D !== 1 && K.includes(Ke)) || Re--;
- }
- Me = A.nextSibling();
- }
- ie = Me && Be === ue ? A : null;
- }
- const Se = ue - T;
- let xe = ze(Se);
- const ot2 = Se - he;
- let Ze = null;
- {
- let Be, Ue;
- for (; ke && typeof (Be = P.getKey()) == "number"; ) {
- Ue = Be - be;
- const Xe = P.getComponent(), Ke = s(Xe);
- if (Ue > ot2)
- break;
- if (Ue === ot2) {
- if (!Ke) {
- Ze = P;
- break;
- }
- {
- if (D === 0 && _e) {
- Ze = P;
- break;
- }
- const We = xe && _(xe.getComponent());
- if (D === 0 && We)
- break;
- }
- }
- if (Ke) {
- const We = Xe.d;
- g[We], K[We], Xe.i === void 0 && (g[We] || K[We] != null && D !== 1) ? (g[We] || K[We] != null && D === 0) && (be++, qe--) : be++;
- }
- ke = P.nextSibling();
- }
- }
- const _t = ot2 + be + Re + qe;
- o(_t >= 0, "trying to descend to a negative index"), U.descend(_t), _e && (ie = xe = Ze = null, G++), Q(ie, W, xe, Ze, U, J) && qe++, U.ascend();
- } else {
- let ie;
- for (; Me && (ie = A.getKey(), typeof ie != "string" || !(ie > j || ie === j)); )
- Me = A.nextSibling();
- const _e = Me && ie === j ? A : null, ue = ze(j);
- let Se;
- for (; ke && (Se = P.getKey(), typeof Se != "string" || !(Se > j || Se === j)); )
- ke = P.nextSibling();
- const xe = ke && Se === j ? P : null;
- U.descend(j), Q(_e, W, ue, xe, U, J), U.ascend();
- }
- return ze.end(), Je && A.ascend(), je && P.ascend(), fe;
- }(we, we.clone(), ye, ye.clone(), oe, null), w)
- return {
- ok: false,
- conflict: w
- };
- oe.reset();
- const Te = (Q, A, W) => Q.traverse(A, (M, P) => {
- M.d != null && W(M.d, Q, P);
- });
- (g.length || re2.length) && (Te(ye, oe, (Q, A, W) => {
- g[Q] && !S[Q] && W.write("r", true), re2[Q] && W.mergeTree(re2[Q].get());
- }), oe.reset());
- const Ie = [], Ne = [];
- if ((te.length || g.length) && !w) {
- const Q = r.readCursor(it(oe.get()));
- if (Te(Q, null, (A, W) => {
- Ie[A] = W.clone();
- }), te.forEach((A) => {
- A && Te(r.readCursor(A.get()), null, (W, M) => {
- Ie[W] = M.clone();
- });
- }), function A(W, M, P, U, J, X) {
- const ee = l(M);
- if (ee && _(ee))
- if (ee.p != null) {
- const T = ee.p;
- Ie[T].getPath(), P = Ie[T], U = Ne[T] = r.writeCursor();
- } else
- ee.r !== void 0 && (P = null);
- else
- s(l(P)) && (P = null);
- const fe = W.getComponent();
- if (fe) {
- let T;
- if ((T = fe.d) != null) {
- const G = te[T];
- G && (G.get(), U.mergeTree(G.get()), P = r.readCursor(G.get()));
- }
- }
- let ce = 0, ae = 0;
- const Oe = r.advancer(M, void 0, (T, G) => {
- _(G) && ce--;
- }), H = r.advancer(P, (T, G) => s(G) ? -(T - ae) - 1 : T - ae, (T, G) => {
- s(G) && ae++;
- });
- for (const T of W)
- if (typeof T == "number") {
- const G = Oe(T), he = T + ce, be = H(he), Re = he + ae;
- U.descend(Re), A(W, G, be, U), U.ascend();
- } else
- U.descend(T), A(W, Oe(T), H(T), U), U.ascend();
- Oe.end(), H.end();
- }(ye, Q, Q.clone(), oe), oe.reset(), w)
- return {
- ok: false,
- conflict: w
- };
- if (oe.get(), Ne.length) {
- const A = Ne.map((M) => M ? M.get() : null), W = r.readCursor(it(oe.get()));
- if (Te(W, oe, (M, P, U) => {
- const J = A[M];
- J && (U.mergeTree(J), A[M] = null);
- }), A.find((M) => M)) {
- const M = r.writeCursor(), P = r.writeCursor();
- let U = 0, J = 0;
- A.forEach((X) => {
- X != null && Te(r.readCursor(X), null, (ee) => {
- const fe = Le[ee];
- M.writeMove(I[fe].getPath(), R[fe].getPath(), U++);
- const ce = se[fe];
- ce && ce.forEach((ae) => {
- g[ae] || D !== 1 && K[ae] != null || P.writeMove($[ae].getPath(), p[ae].getPath(), J++);
- });
- });
- }), w = {
- type: u.ConflictType.BLACKHOLE,
- op1: M.get(),
- op2: P.get()
- };
- }
- }
- }
- return w ? {
- ok: false,
- conflict: w
- } : {
- ok: true,
- result: oe.get()
- };
- }
- const gt = (i) => {
- const c = new Error("Transform detected write conflict");
- throw c.conflict = i, c.type = c.name = "writeConflict", c;
- };
- function jt(i, c, O) {
- const D = st(i, c, O);
- if (D.ok)
- return D.result;
- gt(D.conflict);
- }
- const He = (i) => {
- const c = r.writeCursor();
- return r.readCursor(i).traverse(c, (O, D) => {
- (s(O) || me(O)) && D.write("r", true);
- }), c.get();
- }, $t = (i, c) => {
- const { type: O, op1: D, op2: w } = i;
- switch (O) {
- case u.ConflictType.DROP_COLLISION:
- return c === "left" ? [null, He(w)] : [He(D), null];
- case u.ConflictType.RM_UNEXPECTED_CONTENT:
- let I = false;
- return r.readCursor(D).traverse(null, (R) => {
- R.r !== void 0 && (I = true);
- }), I ? [null, He(w)] : [He(D), null];
- case u.ConflictType.BLACKHOLE:
- return [He(D), He(w)];
- default:
- throw Error("Unrecognised conflict: " + O);
- }
- };
- function yt(i, c, O, D) {
- let w = null;
- for (; ; ) {
- const I = st(c, O, D);
- if (I.ok)
- return ne(w, I.result);
- {
- const { conflict: R } = I;
- i(R) || gt(R);
- const [$, p] = $t(R, D);
- c = ne(q(c), $), O = ne(q(O), p), w = ne(w, p);
- }
- }
- }
- }(et)), et;
- }
- var Pt2;
- function sn() {
- return Pt2 || (Pt2 = 1, function(a) {
- var e = Ye.__createBinding || (Object.create ? function(u, o, l, E) {
- E === void 0 && (E = l), Object.defineProperty(u, E, { enumerable: true, get: function() {
- return o[l];
- } });
- } : function(u, o, l, E) {
- E === void 0 && (E = l), u[E] = o[l];
- }), n = Ye.__exportStar || function(u, o) {
- for (var l in u)
- l !== "default" && !o.hasOwnProperty(l) && e(o, u, l);
- };
- Object.defineProperty(a, "__esModule", { value: true }), n(rn(), a);
- var t = Mt();
- Object.defineProperty(a, "ReadCursor", { enumerable: true, get: function() {
- return t.ReadCursor;
- } }), Object.defineProperty(a, "WriteCursor", { enumerable: true, get: function() {
- return t.WriteCursor;
- } });
- var r = St();
- Object.defineProperty(a, "ConflictType", { enumerable: true, get: function() {
- return r.ConflictType;
- } });
- }(Ye)), Ye;
- }
- var V = sn();
- var on = class {
- constructor() {
- F(this, "drawingManagerData", {});
- F(this, "_oldDrawingManagerData", {});
- F(this, "_focusDrawings", []);
- F(this, "_remove$", new Subject());
- F(this, "remove$", this._remove$.asObservable());
- F(this, "_add$", new Subject());
- F(this, "add$", this._add$.asObservable());
- F(this, "_update$", new Subject());
- F(this, "update$", this._update$.asObservable());
- F(this, "_order$", new Subject());
- F(this, "order$", this._order$.asObservable());
- F(this, "_group$", new Subject());
- F(this, "group$", this._group$.asObservable());
- F(this, "_ungroup$", new Subject());
- F(this, "ungroup$", this._ungroup$.asObservable());
- F(this, "_refreshTransform$", new Subject());
- F(this, "refreshTransform$", this._refreshTransform$.asObservable());
- F(this, "_visible$", new Subject());
- F(this, "visible$", this._visible$.asObservable());
- F(this, "_focus$", new Subject());
- F(this, "focus$", this._focus$.asObservable());
- F(this, "_featurePluginUpdate$", new Subject());
- F(this, "featurePluginUpdate$", this._featurePluginUpdate$.asObservable());
- F(this, "_featurePluginAdd$", new Subject());
- F(this, "featurePluginAdd$", this._featurePluginAdd$.asObservable());
- F(this, "_featurePluginRemove$", new Subject());
- F(this, "featurePluginRemove$", this._featurePluginRemove$.asObservable());
- F(this, "_featurePluginOrderUpdate$", new Subject());
- F(this, "featurePluginOrderUpdate$", this._featurePluginOrderUpdate$.asObservable());
- F(this, "_featurePluginGroupUpdate$", new Subject());
- F(this, "featurePluginGroupUpdate$", this._featurePluginGroupUpdate$.asObservable());
- F(this, "_featurePluginUngroupUpdate$", new Subject());
- F(this, "featurePluginUngroupUpdate$", this._featurePluginUngroupUpdate$.asObservable());
- F(this, "_visible", true);
- F(this, "_editable", true);
- }
- 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 l = u.data[o];
- l.unitId = e, l.subUnitId = r, n.push(l);
- });
- }), n.length > 0 && this.addNotification(n));
- }
- getDrawingData(e, n) {
- return this._getDrawingData(e, n);
- }
- // Use in doc only.
- setDrawingData(e, n, t) {
- this.drawingManagerData[e][n].data = t;
- }
- getBatchAddOp(e) {
- const n = [], t = [], r = [];
- e.forEach((x) => {
- const { op: _, invertOp: s } = this._addByParam(x);
- n.push({ unitId: x.unitId, subUnitId: x.subUnitId, drawingId: x.drawingId }), t.push(_), r.push(s);
- });
- const u = t.reduce(V.type.compose, null), o = r.reduce(V.type.compose, null), { unitId: l, subUnitId: E } = e[0];
- return { undo: o, redo: u, unitId: l, subUnitId: E, objects: n };
- }
- getBatchRemoveOp(e) {
- const n = [], t = [];
- e.forEach((E) => {
- const { op: x, invertOp: _ } = this._removeByParam(E);
- n.unshift(x), t.push(_);
- });
- const r = n.reduce(V.type.compose, null), u = t.reduce(V.type.compose, null), { unitId: o, subUnitId: l } = e[0];
- return { undo: u, redo: r, unitId: o, subUnitId: l, objects: e };
- }
- getBatchUpdateOp(e) {
- const n = [], t = [], r = [];
- e.forEach((x) => {
- const { op: _, invertOp: s } = this._updateByParam(x);
- n.push({ unitId: x.unitId, subUnitId: x.subUnitId, drawingId: x.drawingId }), t.push(_), r.push(s);
- });
- const u = t.reduce(V.type.compose, null), o = r.reduce(V.type.compose, null), { unitId: l, subUnitId: E } = e[0];
- return { undo: o, redo: u, unitId: l, 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((l) => {
- n.push(this._getGroupDrawingOp(l));
- });
- const u = n.reduce(V.type.compose, null);
- return { undo: V.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((l) => {
- n.push(this._getUngroupDrawingOp(l));
- });
- const u = n.reduce(V.type.compose, null);
- return { undo: V.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), l = [];
- return Object.keys(o).forEach((E) => {
- const x = o[E];
- x.groupId === r && l.push(x);
- }), l;
- }
- _getGroupDrawingOp(e) {
- const { parent: n, children: t } = e, { unitId: r, subUnitId: u, drawingId: o } = n, l = [];
- l.push(
- V.insertOp([r, u, "data", o], n)
- );
- let E = Number.NEGATIVE_INFINITY;
- return t.forEach((x) => {
- const { unitId: _, subUnitId: s, drawingId: d } = x, h = this._hasDrawingOrder({ unitId: _, subUnitId: s, drawingId: d });
- E = Math.max(E, h), l.push(
- ...this._getUpdateParamCompareOp(x, this.getDrawingByParam({ unitId: _, subUnitId: s, drawingId: d }))
- );
- }), E === Number.NEGATIVE_INFINITY && (E = this._getDrawingOrder(r, u).length), l.push(
- V.insertOp([r, u, "order", E], o)
- ), l.reduce(V.type.compose, null);
- }
- _getUngroupDrawingOp(e) {
- const { parent: n, children: t } = e, { unitId: r, subUnitId: u, drawingId: o } = n, l = [];
- return t.forEach((E) => {
- const { unitId: x, subUnitId: _, drawingId: s } = E;
- l.push(
- ...this._getUpdateParamCompareOp(E, this.getDrawingByParam({ unitId: x, subUnitId: _, drawingId: s }))
- );
- }), l.push(
- V.removeOp([r, u, "data", o], true)
- ), l.push(
- V.removeOp([r, u, "order", this._getDrawingOrder(r, u).indexOf(o)], true)
- ), l.reduce(V.type.compose, null);
- }
- applyJson1(e, n, t) {
- this._establishDrawingMap(e, n), this._oldDrawingManagerData = { ...this.drawingManagerData }, this.drawingManagerData = V.type.apply(this.drawingManagerData, t);
- }
- // private _fillMissingFields(jsonOp: JSONOp) {
- // if (jsonOp == null) {
- // return;
- // }
- // let object: { [key: string]: {} } = this.drawingManagerData;
- // for (let i = 0; i < jsonOp.length; i++) {
- // const op = jsonOp[i];
- // if (Array.isArray(op)) {
- // const opKey = op[0] as string;
- // if (!(opKey in object)) {
- // object[opKey] = null as unknown as never;
- // }
- // } else if (typeof op === 'string') {
- // object = object[op];
- // if (object == null) {
- // break;
- // }
- // }
- // }
- // }
- 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, l = (E = this._getDrawingData(r, u)) == null ? void 0 : E[o];
- l != null && n.push(l);
- }), n.length > 0 && (this._focusDrawings = n, this._focus$.next(n));
- }
- getFocusDrawings() {
- const e = [];
- return this._focusDrawings.forEach((n) => {
- var l;
- const { unitId: t, subUnitId: r, drawingId: u } = n, o = (l = this._getDrawingData(t, r)) == null ? void 0 : l[u];
- o != null && e.push(o);
- }), e;
- }
- getDrawingOrder(e, n) {
- return this._getDrawingOrder(e, n);
- }
- // Use in doc only.
- 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), l = [...r];
- r.forEach((_) => {
- const s = this._hasDrawingOrder({ unitId: n, subUnitId: t, drawingId: _ });
- if (s === -1 || s === o.length - 1)
- return;
- const d = V.moveOp([n, t, "order", s], [n, t, "order", s + 1]);
- u.push(d), l.includes(o[s + 1]) || l.push(o[s + 1]);
- });
- const E = u.reduce(V.type.compose, null);
- return { undo: V.type.invertWithDoc(E, this.drawingManagerData), redo: E, unitId: n, subUnitId: t, objects: { ...e, drawingIds: l } };
- }
- getBackwardDrawingOp(e) {
- const { unitId: n, subUnitId: t, drawingIds: r } = e, u = [], o = this.getDrawingOrder(n, t), l = [...r];
- r.forEach((_) => {
- const s = this._hasDrawingOrder({ unitId: n, subUnitId: t, drawingId: _ });
- if (s === -1 || s === 0)
- return;
- const d = V.moveOp([n, t, "order", s], [n, t, "order", s - 1]);
- u.push(d), l.includes(o[s - 1]) || l.push(o[s - 1]);
- });
- const E = u.reduce(V.type.compose, null);
- return { undo: V.type.invertWithDoc(E, this.drawingManagerData), redo: E, unitId: n, subUnitId: t, objects: { ...e, drawingIds: l } };
- }
- getFrontDrawingsOp(e) {
- const { unitId: n, subUnitId: t, drawingIds: r } = e, u = this._getOrderFromSearchParams(n, t, r), o = [...r], l = this.getDrawingOrder(n, t), E = [];
- u.forEach((s) => {
- const { drawingId: d } = s, h = this._getDrawingCount(n, t) - 1, k = V.moveOp([n, t, "order", this._getDrawingOrder(n, t).indexOf(d)], [n, t, "order", h]);
- E.push(k), o.includes(l[h]) || o.push(l[h]);
- });
- const x = E.reduce(V.type.compose, null);
- return { undo: V.type.invertWithDoc(x, this.drawingManagerData), redo: x, unitId: n, subUnitId: t, objects: { ...e, drawingIds: o } };
- }
- getBackDrawingsOp(e) {
- const { unitId: n, subUnitId: t, drawingIds: r } = e, u = this._getOrderFromSearchParams(n, t, r, true), o = [...r], l = this.getDrawingOrder(n, t), E = [];
- u.forEach((s) => {
- const { drawingId: d } = s, h = V.moveOp([n, t, "order", this._getDrawingOrder(n, t).indexOf(d)], [n, t, "order", 0]);
- E.push(h), o.includes(l[0]) || o.push(l[0]);
- });
- const x = E.reduce(V.type.compose, null);
- return { undo: V.type.invertWithDoc(x, this.drawingManagerData), redo: x, unitId: n, subUnitId: t, objects: { ...e, drawingIds: o } };
- }
- _getDrawingCount(e, n) {
- return this.getDrawingOrder(e, n).length || 0;
- }
- _getOrderFromSearchParams(e, n, t, r = false) {
- return t.map((u) => {
- const o = this._hasDrawingOrder({ unitId: e, subUnitId: n, drawingId: u });
- return { drawingId: u, zIndex: o };
- }).sort(r === false ? KC : XC);
- }
- _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, l;
- if (e == null)
- return;
- const { unitId: n, subUnitId: t, drawingId: r } = e;
- return (l = (o = (u = this.drawingManagerData[n]) == null ? void 0 : u[t]) == null ? void 0 : o.data) == null ? void 0 : l[r];
- }
- _getOldBySearch(e) {
- var u, o, l;
- if (e == null)
- return;
- const { unitId: n, subUnitId: t, drawingId: r } = e;
- return (l = (o = (u = this._oldDrawingManagerData[n]) == null ? void 0 : u[t]) == null ? void 0 : o.data) == null ? void 0 : l[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 = V.insertOp([n, t, "data", r], e), o = V.insertOp([n, t, "order", this._getDrawingOrder(n, t).length], r), l = [u, o].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: n, subUnitId: t, drawingId: r } = e;
- if (this._establishDrawingMap(n, t, r) == null)
- return { op: [], invertOp: [] };
- const o = V.removeOp([n, t, "data", r], true), l = V.removeOp([n, t, "order", this._getDrawingOrder(n, t).indexOf(r)], true), E = [o, l].reduce(V.type.compose, null), x = V.type.invertWithDoc(E, this.drawingManagerData);
- return { op: E, invertOp: x };
- }
- _updateByParam(e) {
- const { unitId: n, subUnitId: t, drawingId: r } = e, u = this._establishDrawingMap(n, t, r);
- if (u == null)
- return { op: [], invertOp: [] };
- const l = this._getUpdateParamCompareOp(e, u).reduce(V.type.compose, null), E = V.type.invertWithDoc(l, this.drawingManagerData);
- return { op: l, invertOp: E };
- }
- // private _initializeDrawingData(updateParam: T, oldParam: T) {
- // Object.keys(updateParam).forEach((key) => {
- // if (!(key in oldParam)) {
- // oldParam[key as keyof IDrawingParam] = null as unknown as never;
- // }
- // });
- // }
- _getUpdateParamCompareOp(e, n) {
- const { unitId: t, subUnitId: r, drawingId: u } = e, o = [];
- return Object.keys(e).forEach((l) => {
- const E = e[l], x = n[l];
- x !== E && o.push(
- V.replaceOp([t, r, "data", u, l], x, 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;
- }
- };
- var an = class extends on {
- };
- function bn({ unitId: a, subUnitId: e, drawingId: n }, t) {
- return typeof t == "number" ? `${a}#-#${e}#-#${n}#-#${t}` : `${a}#-#${e}#-#${n}`;
- }
- var vn = async (a) => new Promise((e, n) => {
- const t = new Image();
- t.src = a, t.onload = () => {
- e({
- width: t.width,
- height: t.height,
- image: t
- });
- }, t.onerror = (r) => {
- n(r);
- };
- });
- var Ut = Ct("univer.drawing-manager.service");
- var ln = {
- id: "drawing.operation.set-drawing-selected",
- type: ar.OPERATION,
- handler: (a, e) => {
- const n = a.get(Ut);
- return e == null ? false : (n.focusDrawing(e), true);
- }
- };
- var un = "drawing.config";
- var Tt = {};
- var dn = class {
- constructor() {
- F(this, "_waitCount", 0);
- F(this, "_change$", new Subject());
- F(this, "change$", this._change$);
- F(this, "_imageSourceCache", /* @__PURE__ */ new Map());
- }
- setWaitCount(e) {
- this._waitCount = e, this._change$.next(e);
- }
- getImageSourceCache(e, n) {
- if (n === vl.BASE64) {
- const t = new Image();
- return t.src = e, t;
- }
- return this._imageSourceCache.get(e);
- }
- addImageSourceCache(e, n, t) {
- n === vl.BASE64 || t == null || this._imageSourceCache.set(e, t);
- }
- async getImage(e) {
- return Promise.resolve(e);
- }
- async saveImage(e) {
- return new Promise((n, t) => {
- if (!Zt.includes(e.type)) {
- t(new Error(g0.ERROR_IMAGE_TYPE)), this._decreaseWaiting();
- return;
- }
- if (e.size > Yt) {
- t(new Error(g0.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(g0.ERROR_IMAGE)), this._decreaseWaiting();
- return;
- }
- const l = re.generateRandomId(6);
- n({
- imageId: l,
- imageSourceType: vl.BASE64,
- source: o,
- base64Cache: o,
- status: g0.SUCCUSS
- }), this._decreaseWaiting();
- };
- });
- }
- _decreaseWaiting() {
- this._waitCount -= 1, this._change$.next(this._waitCount);
- }
- };
- var cn = Object.defineProperty;
- var fn = Object.getOwnPropertyDescriptor;
- var hn = (a, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? fn(e, n) : e, u = a.length - 1, o; u >= 0; u--)
- (o = a[u]) && (r = (t ? o(e, n, r) : o(r)) || r);
- return t && r && cn(e, n, r), r;
- };
- var ct = (a, e) => (n, t) => e(n, t, a);
- var pn = "UNIVER_DRAWING_PLUGIN";
- var ft;
- var At = (ft = class extends Ra {
- constructor(a = Tt, e, n, t) {
- super(), this._config = a, this._injector = e, this._configService = n, this._commandService = t;
- const { ...r } = nu(
- {},
- Tt,
- this._config
- );
- this._configService.setConfig(un, r);
- }
- onStarting() {
- this._initCommands(), this._initDependencies();
- }
- _initDependencies() {
- var n;
- kE([
- [Oa, { useClass: dn }],
- [Ut, { useClass: an }]
- ], (n = this._config) == null ? void 0 : n.override).forEach((t) => this._injector.add(t));
- }
- _initCommands() {
- [
- ln
- ].forEach((a) => this.disposeWithMe(this._commandService.registerCommand(a)));
- }
- }, F(ft, "pluginName", pn), ft);
- At = hn([
- ct(1, ot(Ot)),
- ct(2, SE),
- ct(3, Pt)
- ], At);
- export {
- mn,
- On,
- wn,
- Yt,
- Zt,
- on,
- an,
- bn,
- vn,
- Ut,
- ln,
- dn,
- At
- };
- //# sourceMappingURL=chunk-QG2HZMYH.js.map
|