chunk-QG2HZMYH.js 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141
  1. import {
  2. Ct,
  3. KC,
  4. Oa,
  5. Ot,
  6. Pt,
  7. Ra,
  8. SE,
  9. Subject,
  10. XC,
  11. ar,
  12. g0,
  13. kE,
  14. nu,
  15. ot,
  16. re,
  17. vl
  18. } from "./chunk-23V3HWTR.js";
  19. // 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
  20. var Nt = Object.defineProperty;
  21. var Rt = (a, e, n) => e in a ? Nt(a, e, { enumerable: true, configurable: true, writable: true, value: n }) : a[e] = n;
  22. var F = (a, e, n) => Rt(a, typeof e != "symbol" ? e + "" : e, n);
  23. var mn = 500;
  24. var On = 500;
  25. var wn = 10;
  26. var Yt = 5 * 1024 * 1024;
  27. var Zt = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/bmp"];
  28. var Ye = {};
  29. var et = {};
  30. var tt = {};
  31. var mt;
  32. function Qt() {
  33. if (mt)
  34. return tt;
  35. mt = 1, Object.defineProperty(tt, "__esModule", { value: true });
  36. function a(t, r) {
  37. if (Array.isArray(r))
  38. return false;
  39. for (let u in t)
  40. if (!n(t[u], r[u]))
  41. return false;
  42. for (let u in r)
  43. if (t[u] === void 0)
  44. return false;
  45. return true;
  46. }
  47. function e(t, r) {
  48. if (!Array.isArray(r) || t.length !== r.length)
  49. return false;
  50. for (let u = 0; u < t.length; u++)
  51. if (!n(t[u], r[u]))
  52. return false;
  53. return true;
  54. }
  55. function n(t, r) {
  56. return t === r ? true : t === null || r === null || typeof t != "object" || typeof r != "object" ? false : Array.isArray(t) ? e(t, r) : a(t, r);
  57. }
  58. return tt.default = n, tt;
  59. }
  60. var nt = {};
  61. var Ot2;
  62. function en() {
  63. if (Ot2)
  64. return nt;
  65. Ot2 = 1, Object.defineProperty(nt, "__esModule", { value: true });
  66. function a(e) {
  67. if (e === null)
  68. return null;
  69. if (Array.isArray(e))
  70. return e.map(a);
  71. if (typeof e == "object") {
  72. const n = {};
  73. for (let t in e)
  74. n[t] = a(e[t]);
  75. return n;
  76. } else
  77. return e;
  78. }
  79. return nt.default = a, nt;
  80. }
  81. var lt = {};
  82. var wt;
  83. function Mt() {
  84. return wt || (wt = 1, function(a) {
  85. Object.defineProperty(a, "__esModule", { value: true }), a.eachChildOf = a.advancer = a.readCursor = a.writeCursor = a.WriteCursor = a.ReadCursor = a.isValidPathItem = void 0;
  86. function e(_, s) {
  87. if (!_)
  88. throw new Error(s);
  89. }
  90. const n = (_) => _ != null && typeof _ == "object" && !Array.isArray(_), t = (_, s) => (
  91. // All the numbers, then all the letters. Just as the gods of ascii intended.
  92. typeof _ == typeof s ? _ > s : typeof _ == "string" && typeof s == "number"
  93. );
  94. function r(_, s) {
  95. for (let d in _) {
  96. const h = d;
  97. s.write(h, _[h]);
  98. }
  99. }
  100. a.isValidPathItem = (_) => typeof _ == "number" || typeof _ == "string" && _ !== "__proto__";
  101. class u {
  102. constructor(s = null) {
  103. this.parents = [], this.indexes = [], this.lcIdx = -1, this.idx = -1, this.container = s;
  104. }
  105. ascend() {
  106. 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--);
  107. }
  108. getPath() {
  109. const s = [];
  110. let d = this.container, h = this.parents.length - 1, k = this.idx;
  111. for (; k >= 0; )
  112. s.unshift(d[k]), k === 0 ? (k = this.indexes[h * 2], d = this.parents[h--]) : k -= n(d[k - 1]) ? 2 : 1;
  113. return s;
  114. }
  115. }
  116. class o extends u {
  117. get() {
  118. return this.container ? this.container.slice(this.idx + 1) : null;
  119. }
  120. // Its only valid to call this after descending into a child.
  121. getKey() {
  122. return e(this.container != null, "Invalid call to getKey before cursor descended"), this.container[this.idx];
  123. }
  124. getComponent() {
  125. let s;
  126. return this.container && this.container.length > this.idx + 1 && n(s = this.container[this.idx + 1]) ? s : null;
  127. }
  128. descendFirst() {
  129. let s = this.idx + 1;
  130. if (!this.container || s >= this.container.length || n(this.container[s]) && s + 1 >= this.container.length)
  131. return false;
  132. n(this.container[s]) && s++;
  133. const d = this.container[s];
  134. 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;
  135. }
  136. nextSibling() {
  137. if (e(this.parents.length === this.indexes.length / 2), this.idx > 0 || this.parents.length === 0)
  138. return false;
  139. const s = this.indexes[this.indexes.length - 1] + 1, d = this.parents[this.parents.length - 1];
  140. return s >= d.length ? false : (e(!isNaN(s)), this.indexes[this.indexes.length - 1] = s, this.container = d[s], true);
  141. }
  142. _init(s, d, h, k) {
  143. this.container = s, this.idx = d, this.parents = h.slice(), this.indexes = k.slice();
  144. }
  145. clone() {
  146. const s = new o();
  147. return s._init(this.container, this.idx, this.parents, this.indexes), s;
  148. }
  149. *[Symbol.iterator]() {
  150. if (this.descendFirst()) {
  151. do
  152. yield this.getKey();
  153. while (this.nextSibling());
  154. this.ascend();
  155. }
  156. }
  157. // TODO(cleanup): Consider moving these functions out of cursor, since
  158. // they're really just helper methods.
  159. // It'd be really nice to do this using generators.
  160. traverse(s, d) {
  161. const h = this.getComponent();
  162. h && d(h, s);
  163. for (const k of this)
  164. s && s.descend(k), this.traverse(s, d), s && s.ascend();
  165. }
  166. eachPick(s, d) {
  167. this.traverse(s, (h, k) => {
  168. h.p != null && d(h.p, k);
  169. });
  170. }
  171. eachDrop(s, d) {
  172. this.traverse(s, (h, k) => {
  173. h.d != null && d(h.d, k);
  174. });
  175. }
  176. }
  177. a.ReadCursor = o;
  178. class l extends u {
  179. constructor(s = null) {
  180. super(s), this.pendingDescent = [], this._op = s;
  181. }
  182. flushDescent() {
  183. e(this.parents.length === this.indexes.length / 2), this.container === null && (this._op = this.container = []);
  184. for (let s = 0; s < this.pendingDescent.length; s++) {
  185. const d = this.pendingDescent[s];
  186. let h = this.idx + 1;
  187. if (h < this.container.length && n(this.container[h]) && h++, e(h === this.container.length || !n(this.container[h])), h === this.container.length)
  188. this.container.push(d), this.idx = h;
  189. else if (this.container[h] === d)
  190. this.idx = h;
  191. else {
  192. if (!Array.isArray(this.container[h])) {
  193. const k = this.container.splice(h, this.container.length - h);
  194. this.container.push(k), this.lcIdx > -1 && (this.lcIdx = h);
  195. }
  196. 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]); )
  197. h++;
  198. if (this.indexes.push(h), this.idx = 0, h < this.container.length && this.container[h][0] === d)
  199. this.container = this.container[h];
  200. else {
  201. const k = [d];
  202. this.container.splice(h, 0, k), this.container = k;
  203. }
  204. }
  205. }
  206. this.pendingDescent.length = 0;
  207. }
  208. reset() {
  209. this.lcIdx = -1;
  210. }
  211. // Creates and returns a component, creating one if need be. You should
  212. // probably write to it immediately - ops are not valid with empty
  213. // components.
  214. getComponent() {
  215. this.flushDescent();
  216. const s = this.idx + 1;
  217. if (s < this.container.length && n(this.container[s]))
  218. return this.container[s];
  219. {
  220. const d = {};
  221. return this.container.splice(s, 0, d), d;
  222. }
  223. }
  224. write(s, d) {
  225. const h = this.getComponent();
  226. e(h[s] == null || h[s] === d, "Internal consistency error: Overwritten component. File a bug"), h[s] = d;
  227. }
  228. get() {
  229. return this._op;
  230. }
  231. descend(s) {
  232. if (!a.isValidPathItem(s))
  233. throw Error("Invalid JSON key");
  234. this.pendingDescent.push(s);
  235. }
  236. descendPath(s) {
  237. return this.pendingDescent.push(...s), this;
  238. }
  239. ascend() {
  240. this.pendingDescent.length ? this.pendingDescent.pop() : super.ascend();
  241. }
  242. mergeTree(s, d = r) {
  243. if (s === null)
  244. return;
  245. if (e(Array.isArray(s)), s === this._op)
  246. throw Error("Cannot merge into my own tree");
  247. const h = this.lcIdx, k = this.parents.length;
  248. let Y = 0;
  249. for (let pe = 0; pe < s.length; pe++) {
  250. const Z = s[pe];
  251. typeof Z == "string" || typeof Z == "number" ? (Y++, this.descend(Z)) : Array.isArray(Z) ? this.mergeTree(Z, d) : typeof Z == "object" && d(Z, this);
  252. }
  253. for (; Y--; )
  254. this.ascend();
  255. this.lcIdx = this.parents.length === k ? h : -1;
  256. }
  257. at(s, d) {
  258. this.descendPath(s), d(this);
  259. for (let h = 0; h < s.length; h++)
  260. this.ascend();
  261. return this;
  262. }
  263. // This is used by helpers, so the strict ordering guarantees are
  264. // relaxed.
  265. writeAtPath(s, d, h) {
  266. return this.at(s, () => this.write(d, h)), this.reset(), this;
  267. }
  268. writeMove(s, d, h = 0) {
  269. return this.writeAtPath(s, "p", h).writeAtPath(d, "d", h);
  270. }
  271. getPath() {
  272. const s = super.getPath();
  273. return s.push(...this.pendingDescent), s;
  274. }
  275. }
  276. a.WriteCursor = l, a.writeCursor = () => new l(), a.readCursor = (_) => new o(_);
  277. function E(_, s, d) {
  278. let h, k;
  279. k = h = _ ? _.descendFirst() : false;
  280. function Y(pe) {
  281. let Z;
  282. for (; k; ) {
  283. const Ce = Z = _.getKey();
  284. if (pe != null) {
  285. let Ge = false;
  286. if (s && typeof Ce == "number" && (Z = s(Ce, _.getComponent()), Z < 0 && (Z = ~Z, Ge = true)), t(Z, pe))
  287. return null;
  288. if (Z === pe && !Ge)
  289. return _;
  290. }
  291. d && typeof Z == "number" && d(Z, _.getComponent()), k = _.nextSibling();
  292. }
  293. return null;
  294. }
  295. return Y.end = () => {
  296. h && _.ascend();
  297. }, Y;
  298. }
  299. a.advancer = E;
  300. function x(_, s, d) {
  301. let h, k, Y, pe;
  302. for (h = k = _ && _.descendFirst(), Y = pe = s && s.descendFirst(); h || Y; ) {
  303. let Z = h ? _.getKey() : null, Ce = Y ? s.getKey() : null;
  304. 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());
  305. }
  306. k && _.ascend(), pe && s.ascend();
  307. }
  308. a.eachChildOf = x;
  309. }(lt)), lt;
  310. }
  311. var ut = {};
  312. var bt;
  313. function St() {
  314. return bt || (bt = 1, function(a) {
  315. Object.defineProperty(a, "__esModule", { value: true }), a.ConflictType = void 0, function(e) {
  316. e[e.RM_UNEXPECTED_CONTENT = 1] = "RM_UNEXPECTED_CONTENT", e[e.DROP_COLLISION = 2] = "DROP_COLLISION", e[e.BLACKHOLE = 3] = "BLACKHOLE";
  317. }(a.ConflictType || (a.ConflictType = {}));
  318. }(ut)), ut;
  319. }
  320. var Fe = {};
  321. var Ve = {};
  322. var vt;
  323. function pt() {
  324. return vt || (vt = 1, Object.defineProperty(Ve, "__esModule", { value: true }), Ve.uniToStrPos = Ve.strPosToUni = void 0, Ve.strPosToUni = (a, e = a.length) => {
  325. let n = 0, t = 0;
  326. for (; t < e; t++) {
  327. const r = a.charCodeAt(t);
  328. r >= 55296 && r <= 57343 && (n++, t++);
  329. }
  330. if (t !== e)
  331. throw Error("Invalid offset - splits unicode bytes");
  332. return t - n;
  333. }, Ve.uniToStrPos = (a, e) => {
  334. let n = 0;
  335. for (; e > 0; e--) {
  336. const t = a.charCodeAt(n);
  337. n += t >= 55296 && t <= 57343 ? 2 : 1;
  338. }
  339. return n;
  340. }), Ve;
  341. }
  342. var dt = {};
  343. var Ct2;
  344. function ht() {
  345. return Ct2 || (Ct2 = 1, function(a) {
  346. Object.defineProperty(a, "__esModule", { value: true }), a.uniSlice = a.dlen = a.eachOp = void 0;
  347. const e = pt(), n = (f) => {
  348. if (!Array.isArray(f))
  349. throw Error("Op must be an array of components");
  350. let y = null;
  351. for (let v = 0; v < f.length; v++) {
  352. const L = f[v];
  353. switch (typeof L) {
  354. case "object":
  355. if (typeof L.d != "number" && typeof L.d != "string")
  356. throw Error("Delete must be number or string");
  357. if (a.dlen(L.d) <= 0)
  358. throw Error("Deletes must not be empty");
  359. break;
  360. case "string":
  361. if (!(L.length > 0))
  362. throw Error("Inserts cannot be empty");
  363. break;
  364. case "number":
  365. if (!(L > 0))
  366. throw Error("Skip components must be >0");
  367. if (typeof y == "number")
  368. throw Error("Adjacent skip components should be combined");
  369. break;
  370. }
  371. y = L;
  372. }
  373. if (typeof y == "number")
  374. throw Error("Op has a trailing skip");
  375. };
  376. function t(f, y) {
  377. let v = 0, L = 0;
  378. for (let z = 0; z < f.length; z++) {
  379. const q = f[z];
  380. switch (y(q, v, L), typeof q) {
  381. case "object":
  382. v += a.dlen(q.d);
  383. break;
  384. case "string":
  385. L += e.strPosToUni(q);
  386. break;
  387. case "number":
  388. v += q, L += q;
  389. break;
  390. }
  391. }
  392. }
  393. a.eachOp = t;
  394. function r(f, y) {
  395. const v = [], L = l(v);
  396. return t(f, (z, q, Ee) => {
  397. L(y(z, q, Ee));
  398. }), s(v);
  399. }
  400. const u = (f) => f, o = (f) => r(f, u);
  401. a.dlen = (f) => typeof f == "number" ? f : e.strPosToUni(f);
  402. const l = (f) => (y) => {
  403. if (!(!y || y.d === 0 || y.d === ""))
  404. if (f.length === 0)
  405. f.push(y);
  406. else if (typeof y == typeof f[f.length - 1])
  407. if (typeof y == "object") {
  408. const v = f[f.length - 1];
  409. v.d = typeof v.d == "string" && typeof y.d == "string" ? v.d + y.d : a.dlen(v.d) + a.dlen(y.d);
  410. } else
  411. f[f.length - 1] += y;
  412. else
  413. f.push(y);
  414. }, E = (f) => typeof f == "number" ? f : typeof f == "string" ? e.strPosToUni(f) : typeof f.d == "number" ? f.d : e.strPosToUni(f.d);
  415. a.uniSlice = (f, y, v) => {
  416. const L = e.uniToStrPos(f, y), z = v == null ? 1 / 0 : e.uniToStrPos(f, v);
  417. return f.slice(L, z);
  418. };
  419. const x = (f, y, v) => typeof f == "number" ? v == null ? f - y : Math.min(f, v) - y : a.uniSlice(f, y, v), _ = (f) => {
  420. let y = 0, v = 0;
  421. return { take: (q, Ee) => {
  422. if (y === f.length)
  423. return q === -1 ? null : q;
  424. const de = f[y];
  425. let ne;
  426. if (typeof de == "number")
  427. return q === -1 || de - v <= q ? (ne = de - v, ++y, v = 0, ne) : (v += q, q);
  428. if (typeof de == "string") {
  429. if (q === -1 || Ee === "i" || e.strPosToUni(de.slice(v)) <= q)
  430. return ne = de.slice(v), ++y, v = 0, ne;
  431. {
  432. const le = v + e.uniToStrPos(de.slice(v), q);
  433. return ne = de.slice(v, le), v = le, ne;
  434. }
  435. } else {
  436. if (q === -1 || Ee === "d" || a.dlen(de.d) - v <= q)
  437. return ne = { d: x(de.d, v) }, ++y, v = 0, ne;
  438. {
  439. let le = x(de.d, v, v + q);
  440. return v += q, { d: le };
  441. }
  442. }
  443. }, peek: () => f[y] };
  444. }, s = (f) => (f.length > 0 && typeof f[f.length - 1] == "number" && f.pop(), f);
  445. function d(f, y, v) {
  446. if (v !== "left" && v !== "right")
  447. throw Error("side (" + v + ") must be 'left' or 'right'");
  448. n(f), n(y);
  449. const L = [], z = l(L), { take: q, peek: Ee } = _(f);
  450. for (let ne = 0; ne < y.length; ne++) {
  451. const le = y[ne];
  452. let ge, De;
  453. switch (typeof le) {
  454. case "number":
  455. for (ge = le; ge > 0; )
  456. De = q(ge, "i"), z(De), typeof De != "string" && (ge -= E(De));
  457. break;
  458. case "string":
  459. v === "left" && typeof Ee() == "string" && z(q(-1)), z(e.strPosToUni(le));
  460. break;
  461. case "object":
  462. for (ge = a.dlen(le.d); ge > 0; )
  463. switch (De = q(ge, "i"), typeof De) {
  464. case "number":
  465. ge -= De;
  466. break;
  467. case "string":
  468. z(De);
  469. break;
  470. case "object":
  471. ge -= a.dlen(De.d);
  472. }
  473. break;
  474. }
  475. }
  476. let de;
  477. for (; de = q(-1); )
  478. z(de);
  479. return s(L);
  480. }
  481. function h(f, y) {
  482. n(f), n(y);
  483. const v = [], L = l(v), { take: z } = _(f);
  484. for (let Ee = 0; Ee < y.length; Ee++) {
  485. const de = y[Ee];
  486. let ne, le;
  487. switch (typeof de) {
  488. case "number":
  489. for (ne = de; ne > 0; )
  490. le = z(ne, "d"), L(le), typeof le != "object" && (ne -= E(le));
  491. break;
  492. case "string":
  493. L(de);
  494. break;
  495. case "object":
  496. ne = a.dlen(de.d);
  497. let ge = 0;
  498. for (; ge < ne; )
  499. switch (le = z(ne - ge, "d"), typeof le) {
  500. case "number":
  501. L({ d: x(de.d, ge, ge + le) }), ge += le;
  502. break;
  503. case "string":
  504. ge += e.strPosToUni(le);
  505. break;
  506. case "object":
  507. L(le);
  508. }
  509. break;
  510. }
  511. }
  512. let q;
  513. for (; q = z(-1); )
  514. L(q);
  515. return s(v);
  516. }
  517. const k = (f, y) => {
  518. let v = 0;
  519. for (let L = 0; L < y.length && f > v; L++) {
  520. const z = y[L];
  521. switch (typeof z) {
  522. case "number": {
  523. v += z;
  524. break;
  525. }
  526. case "string":
  527. const q = e.strPosToUni(z);
  528. v += q, f += q;
  529. break;
  530. case "object":
  531. f -= Math.min(a.dlen(z.d), f - v);
  532. break;
  533. }
  534. }
  535. return f;
  536. }, Y = (f, y) => typeof f == "number" ? k(f, y) : f.map((v) => k(v, y));
  537. function pe(f, y, v) {
  538. return r(f, (L, z) => typeof L == "object" && typeof L.d == "number" ? { d: v.slice(y, z, z + L.d) } : L);
  539. }
  540. function Z(f) {
  541. return r(f, (y) => {
  542. switch (typeof y) {
  543. case "object":
  544. if (typeof y.d == "number")
  545. throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");
  546. return y.d;
  547. case "string":
  548. return { d: y };
  549. case "number":
  550. return y;
  551. }
  552. });
  553. }
  554. function Ce(f) {
  555. return r(f, (y) => typeof y == "object" && typeof y.d == "string" ? { d: e.strPosToUni(y.d) } : y);
  556. }
  557. function Ge(f) {
  558. let y = true;
  559. return t(f, (v) => {
  560. typeof v == "object" && typeof v.d == "number" && (y = false);
  561. }), y;
  562. }
  563. function me(f) {
  564. return {
  565. name: "text-unicode",
  566. uri: "http://sharejs.org/types/text-unicode",
  567. trim: s,
  568. normalize: o,
  569. checkOp: n,
  570. /** Create a new text snapshot.
  571. *
  572. * @param {string} initial - initial snapshot data. Optional. Defaults to ''.
  573. * @returns {Snap} Initial document snapshot object
  574. */
  575. create(y = "") {
  576. if (typeof y != "string")
  577. throw Error("Initial data must be a string");
  578. return f.create(y);
  579. },
  580. /** Apply an operation to a document snapshot
  581. */
  582. apply(y, v) {
  583. n(v);
  584. const L = f.builder(y);
  585. for (let z = 0; z < v.length; z++) {
  586. const q = v[z];
  587. switch (typeof q) {
  588. case "number":
  589. L.skip(q);
  590. break;
  591. case "string":
  592. L.append(q);
  593. break;
  594. case "object":
  595. L.del(a.dlen(q.d));
  596. break;
  597. }
  598. }
  599. return L.build();
  600. },
  601. transform: d,
  602. compose: h,
  603. transformPosition: k,
  604. transformSelection: Y,
  605. isInvertible: Ge,
  606. makeInvertible(y, v) {
  607. return pe(y, v, f);
  608. },
  609. stripInvertible: Ce,
  610. invert: Z,
  611. invertWithDoc(y, v) {
  612. return Z(pe(y, v, f));
  613. },
  614. isNoop: (y) => y.length === 0
  615. };
  616. }
  617. a.default = me;
  618. }(dt)), dt;
  619. }
  620. var rt = {};
  621. var It;
  622. function tn() {
  623. if (It)
  624. return rt;
  625. It = 1, Object.defineProperty(rt, "__esModule", { value: true });
  626. const a = ht(), e = pt();
  627. function n(t, r) {
  628. return {
  629. // Returns the text content of the document
  630. get: t,
  631. // Returns the number of characters in the string
  632. getLength() {
  633. return t().length;
  634. },
  635. // Insert the specified text at the given position in the document
  636. insert(u, o, l) {
  637. const E = e.strPosToUni(t(), u);
  638. return r([E, o], l);
  639. },
  640. remove(u, o, l) {
  641. const E = e.strPosToUni(t(), u);
  642. return r([E, { d: o }], l);
  643. },
  644. // When you use this API, you should implement these two methods
  645. // in your editing context.
  646. //onInsert: function(pos, text) {},
  647. //onRemove: function(pos, removedLength) {},
  648. _onOp(u) {
  649. a.eachOp(u, (o, l, E) => {
  650. switch (typeof o) {
  651. case "string":
  652. this.onInsert && this.onInsert(E, o);
  653. break;
  654. case "object":
  655. const x = a.dlen(o.d);
  656. this.onRemove && this.onRemove(E, x);
  657. }
  658. });
  659. },
  660. onInsert: null,
  661. onRemove: null
  662. };
  663. }
  664. return rt.default = n, n.provides = { text: true }, rt;
  665. }
  666. var Et;
  667. function nn() {
  668. return Et || (Et = 1, function(a) {
  669. var e = Fe.__createBinding || (Object.create ? function(d, h, k, Y) {
  670. Y === void 0 && (Y = k), Object.defineProperty(d, Y, { enumerable: true, get: function() {
  671. return h[k];
  672. } });
  673. } : function(d, h, k, Y) {
  674. Y === void 0 && (Y = k), d[Y] = h[k];
  675. }), n = Fe.__setModuleDefault || (Object.create ? function(d, h) {
  676. Object.defineProperty(d, "default", { enumerable: true, value: h });
  677. } : function(d, h) {
  678. d.default = h;
  679. }), t = Fe.__importStar || function(d) {
  680. if (d && d.__esModule)
  681. return d;
  682. var h = {};
  683. if (d != null)
  684. for (var k in d)
  685. Object.hasOwnProperty.call(d, k) && e(h, d, k);
  686. return n(h, d), h;
  687. }, r = Fe.__importDefault || function(d) {
  688. return d && d.__esModule ? d : { default: d };
  689. };
  690. Object.defineProperty(a, "__esModule", { value: true }), a.type = a.remove = a.insert = void 0;
  691. const u = pt(), o = t(ht()), l = r(tn()), E = {
  692. create(d) {
  693. return d;
  694. },
  695. toString(d) {
  696. return d;
  697. },
  698. builder(d) {
  699. if (typeof d != "string")
  700. throw Error("Invalid document snapshot: " + d);
  701. const h = [];
  702. return {
  703. skip(k) {
  704. let Y = u.uniToStrPos(d, k);
  705. if (Y > d.length)
  706. throw Error("The op is too long for this document");
  707. h.push(d.slice(0, Y)), d = d.slice(Y);
  708. },
  709. append(k) {
  710. h.push(k);
  711. },
  712. del(k) {
  713. d = d.slice(u.uniToStrPos(d, k));
  714. },
  715. build() {
  716. return h.join("") + d;
  717. }
  718. };
  719. },
  720. slice: o.uniSlice
  721. }, x = o.default(E), _ = Object.assign(Object.assign({}, x), { api: l.default });
  722. 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 }];
  723. var s = ht();
  724. Object.defineProperty(a, "makeType", { enumerable: true, get: function() {
  725. return s.default;
  726. } });
  727. }(Fe)), Fe;
  728. }
  729. var Dt;
  730. function rn() {
  731. return Dt || (Dt = 1, function(a) {
  732. var e = et.__importDefault || function(i) {
  733. return i && i.__esModule ? i : {
  734. default: i
  735. };
  736. };
  737. Object.defineProperty(a, "__esModule", {
  738. value: true
  739. }), a.editOp = a.replaceOp = a.insertOp = a.moveOp = a.removeOp = a.type = void 0;
  740. const n = e(Qt()), t = e(en()), r = Mt(), u = St();
  741. function o(i, c) {
  742. if (!i)
  743. throw new Error(c);
  744. }
  745. a.type = {
  746. name: "json1",
  747. uri: "http://sharejs.org/types/JSONv1",
  748. readCursor: r.readCursor,
  749. writeCursor: r.writeCursor,
  750. create: (i) => i,
  751. isNoop: (i) => i == null,
  752. setDebug(i) {
  753. },
  754. registerSubtype: Z,
  755. checkValidOp: z,
  756. normalize: q,
  757. apply: Ee,
  758. transformPosition: de,
  759. compose: ne,
  760. tryTransform: st,
  761. transform: jt,
  762. makeInvertible: De,
  763. invert: le,
  764. invertWithDoc: kt,
  765. RM_UNEXPECTED_CONTENT: u.ConflictType.RM_UNEXPECTED_CONTENT,
  766. DROP_COLLISION: u.ConflictType.DROP_COLLISION,
  767. BLACKHOLE: u.ConflictType.BLACKHOLE,
  768. transformNoConflict: (i, c, O) => yt(() => true, i, c, O),
  769. typeAllowingConflictsPred: (i) => Object.assign(Object.assign({}, a.type), {
  770. transform: (c, O, D) => yt(i, c, O, D)
  771. })
  772. };
  773. const l = (i) => i ? i.getComponent() : null;
  774. function E(i) {
  775. return i && typeof i == "object" && !Array.isArray(i);
  776. }
  777. 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);
  778. function d(i, c) {
  779. 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;
  780. }
  781. function h(i, c, O) {
  782. 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;
  783. }
  784. 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) => {
  785. D.write("r", c), D.write("i", O);
  786. }).get(), a.editOp = (i, c, O, D = false) => r.writeCursor().at(i, (w) => y(w, c, O, D)).get();
  787. 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 = {};
  788. function Z(i) {
  789. let c = i.type ? i.type : i;
  790. c.name && (pe[c.name] = c), c.uri && (pe[c.uri] = c);
  791. }
  792. const Ce = (i) => {
  793. const c = pe[i];
  794. if (c)
  795. return c;
  796. throw Error("Missing type: " + i);
  797. };
  798. Z(nn());
  799. const Ge = (i, c) => i + c;
  800. Z({
  801. name: "number",
  802. apply: Ge,
  803. compose: Ge,
  804. invert: (i) => -i,
  805. transform: (i) => i
  806. });
  807. 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) => {
  808. const [w, I] = typeof c == "string" ? [Ce(c), c] : [c, c.name];
  809. !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)));
  810. };
  811. function v(i) {
  812. o(typeof i == "number"), o(i >= 0), o(i === (0 | i));
  813. }
  814. function L(i) {
  815. typeof i == "number" ? v(i) : o(typeof i == "string");
  816. }
  817. function z(i) {
  818. if (i === null)
  819. return;
  820. const c = /* @__PURE__ */ new Set(), O = /* @__PURE__ */ new Set(), D = (I) => {
  821. let R = true, $ = false;
  822. for (let p in I) {
  823. const m = I[p];
  824. 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")
  825. v(m), o(!c.has(m)), c.add(m), o(I.r === void 0);
  826. else if (p === "d")
  827. v(m), o(!O.has(m)), O.add(m), o(I.i === void 0);
  828. else if (p === "e" || p === "es" || p === "ena") {
  829. o(!$), $ = true;
  830. const b = me(I);
  831. o(b, "Missing type in edit"), b.checkValidOp && b.checkValidOp(f(I));
  832. }
  833. }
  834. o(!R);
  835. }, w = (I, R, $) => {
  836. if (!Array.isArray(I))
  837. throw Error("Op must be null or a list");
  838. if (I.length === 0)
  839. throw Error("Empty descent");
  840. R || L(I[0]);
  841. let p = 1, m = 0, b = 0;
  842. for (let C = 0; C < I.length; C++) {
  843. const N = I[C];
  844. if (o(N != null), Array.isArray(N)) {
  845. const B = w(N, false);
  846. if (m) {
  847. const g = typeof b, S = typeof B;
  848. g === S ? o(b < B, "descent keys are not in order") : o(g === "number" && S === "string");
  849. }
  850. b = B, m++, p = 3;
  851. } else
  852. 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);
  853. }
  854. return o(m !== 1, "Operation makes multiple descents. Remove some []"), o(p === 2 || p === 3), I[0];
  855. };
  856. w(i, true), o(c.size === O.size, "Mismatched picks and drops in op");
  857. for (let I = 0; I < c.size; I++)
  858. o(c.has(I)), o(O.has(I));
  859. }
  860. function q(i) {
  861. let c = 0, O = [];
  862. const D = r.writeCursor();
  863. return D.mergeTree(i, (w, I) => {
  864. const R = me(w);
  865. if (R) {
  866. const p = f(w);
  867. y(I, R, R.normalize ? R.normalize(p) : p);
  868. }
  869. for (const p of ["r", "p", "i", "d"])
  870. if (w[p] !== void 0) {
  871. const m = p === "p" || p === "d" ? ($ = w[p], O[$] == null && (O[$] = c++), O[$]) : w[p];
  872. I.write(p, m);
  873. }
  874. var $;
  875. }), D.get();
  876. }
  877. function Ee(i, c) {
  878. if (z(c), c === null)
  879. return i;
  880. const O = [];
  881. return function D(w, I) {
  882. let R = w, $ = 0, p = {
  883. root: w
  884. }, m = 0, b = p, C = "root";
  885. function N() {
  886. for (; m < $; m++) {
  887. let B = I[m];
  888. typeof B != "object" && (o(k(b, C)), b = b[C] = x(b[C]), C = B);
  889. }
  890. }
  891. for (; $ < I.length; $++) {
  892. const B = I[$];
  893. if (Array.isArray(B)) {
  894. const g = D(R, B);
  895. g !== R && g !== void 0 && (N(), R = b[C] = g);
  896. } else if (typeof B == "object") {
  897. B.d != null ? (N(), R = h(b, C, O[B.d])) : B.i !== void 0 && (N(), R = h(b, C, B.i));
  898. const g = me(B);
  899. if (g)
  900. N(), R = b[C] = g.apply(R, f(B));
  901. else if (B.e !== void 0)
  902. throw Error("Subtype " + B.et + " undefined");
  903. } else
  904. R = Y(R, B);
  905. }
  906. return p.root;
  907. }(i = function D(w, I) {
  908. const R = [];
  909. let $ = 0;
  910. for (; $ < I.length; $++) {
  911. const C = I[$];
  912. if (Array.isArray(C))
  913. break;
  914. typeof C != "object" && (R.push(w), w = Y(w, C));
  915. }
  916. for (let C = I.length - 1; C >= $; C--)
  917. w = D(w, I[C]);
  918. for (--$; $ >= 0; $--) {
  919. const C = I[$];
  920. if (typeof C != "object") {
  921. const N = R.pop();
  922. w = w === Y(N, C) ? N : w === void 0 ? d(N, C) : (m = C, b = w, (p = x(p = N))[m] = b, p);
  923. } else
  924. _(C) && (o(w !== void 0, "Cannot pick up or remove undefined"), C.p != null && (O[C.p] = w), w = void 0);
  925. }
  926. var p, m, b;
  927. return w;
  928. }(i, c), c);
  929. }
  930. function de(i, c) {
  931. i = i.slice(), z(c);
  932. const O = r.readCursor(c);
  933. let D, w, I = false;
  934. const R = [];
  935. for (let p = 0; ; p++) {
  936. const m = i[p], b = O.getComponent();
  937. if (b && (b.r !== void 0 ? I = true : b.p != null && (I = false, D = b.p, w = p)), p >= i.length)
  938. break;
  939. let C = 0;
  940. const N = r.advancer(O, void 0, (g, S) => {
  941. _(S) && C++;
  942. });
  943. R.unshift(N);
  944. const B = N(m);
  945. if (typeof m == "number" && (i[p] -= C), !B)
  946. break;
  947. }
  948. if (R.forEach((p) => p.end()), I)
  949. return null;
  950. const $ = () => {
  951. let p = 0;
  952. if (D != null) {
  953. const m = O.getPath();
  954. p = m.length, i = m.concat(i.slice(w));
  955. }
  956. for (; p < i.length; p++) {
  957. const m = i[p], b = l(O), C = me(b);
  958. if (C) {
  959. const g = f(b);
  960. C.transformPosition && (i[p] = C.transformPosition(i[p], g));
  961. break;
  962. }
  963. let N = 0;
  964. const B = r.advancer(O, (g, S) => s(S) ? ~(g - N) : g - N, (g, S) => {
  965. s(S) && N++;
  966. })(m);
  967. if (typeof m == "number" && (i[p] += N), !B)
  968. break;
  969. }
  970. };
  971. return D != null ? O.eachDrop(null, (p) => {
  972. p === D && $();
  973. }) : $(), i;
  974. }
  975. function ne(i, c) {
  976. if (z(i), z(c), i == null)
  977. return c;
  978. if (c == null)
  979. return i;
  980. let O = 0;
  981. const D = r.readCursor(i), w = r.readCursor(c), I = r.writeCursor(), R = [], $ = [], p = [], m = [], b = [], C = [], N = /* @__PURE__ */ new Set();
  982. D.traverse(null, (g) => {
  983. g.p != null && (p[g.p] = D.clone());
  984. }), w.traverse(null, (g) => {
  985. g.d != null && (m[g.d] = w.clone());
  986. });
  987. const B = r.writeCursor();
  988. return function g(S, re2, te, K, se, $e, we, ye) {
  989. o(re2 || te);
  990. 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;
  991. if (Ie != null)
  992. K = m[Ie], we = $[Ie] = new r.WriteCursor();
  993. else if (Pe && Pe.r !== void 0)
  994. K = null;
  995. else {
  996. const T = l(K);
  997. T && T.d != null && (K = null);
  998. }
  999. const Q = l(K);
  1000. if (Te != null)
  1001. if (S = p[Te], ye = R[Te] = new r.WriteCursor(), Ne)
  1002. $e && !Ae && ye.write("r", true);
  1003. else {
  1004. const T = b[Te] = O++;
  1005. we.write("d", T);
  1006. }
  1007. else if (oe && oe.i !== void 0)
  1008. S = null;
  1009. else {
  1010. const T = l(S);
  1011. T && T.p != null && (S = null);
  1012. }
  1013. let A;
  1014. Le ? (o(se === void 0), A = oe.i) : A = se;
  1015. const W = (Ie == null ? !Le || $e || Ae : A === void 0) ? null : we.getComponent();
  1016. if (Ie != null) {
  1017. if (!(se !== void 0 || Le)) {
  1018. const T = Te != null ? b[Te] : O++;
  1019. C[Ie] = T, ye.write("p", T);
  1020. }
  1021. } else
  1022. Ae && (Le || se !== void 0 || (Pe.r, ye.write("r", Pe.r)));
  1023. const M = Ne ? null : me(oe), P = me(Q);
  1024. if ((M || P) && (M && M.name, P && P.name), M && P) {
  1025. o(M === P);
  1026. const T = f(oe), G = f(Q), he = M.compose(T, G);
  1027. y(we, M, he), N.add(Q);
  1028. } else
  1029. M ? y(we, M, f(oe)) : P && (y(we, P, f(Q)), N.add(Q));
  1030. const U = typeof A == "object" && A != null;
  1031. let J = false, X = 0, ee = 0, fe = 0, ce = 0, ae = 0;
  1032. const Oe = r.advancer(K, (T, G) => s(G) ? ce - T - 1 : T - ce, (T, G) => {
  1033. s(G) && ce++;
  1034. }), H = r.advancer(S, (T, G) => _(G) ? X - T - 1 : T - X, (T, G) => {
  1035. _(G) && X++;
  1036. });
  1037. if (r.eachChildOf(re2, te, (T, G, he) => {
  1038. let be, Re, qe = T, Me = T, Je = T;
  1039. if (typeof T == "number") {
  1040. let _e = T + fe;
  1041. Re = Oe(_e), Me = _e + ce;
  1042. let ue = T + ee;
  1043. 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");
  1044. const Se = s(l(G)), xe = _(l(he));
  1045. (Se || xe && !Ne) && ae--, Se && ee--, xe && fe--;
  1046. } else
  1047. be = H(T), Re = Oe(T);
  1048. ye.descend(qe), we.descend(Me);
  1049. const ze = U && !s(l(G)) ? A[Je] : void 0, ke = g(be, G, he, Re, ze, Ne, we, ye);
  1050. var je, j, ie;
  1051. 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();
  1052. }), H.end(), Oe.end(), W != null)
  1053. W.i = A;
  1054. else if (!$e && !Ae && Ie == null)
  1055. return A;
  1056. }(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) => {
  1057. const re2 = g.p;
  1058. if (re2 != null) {
  1059. const te = b[re2];
  1060. te != null && S.write("p", te);
  1061. const K = R[re2];
  1062. K && K.get(), K && S.mergeTree(K.get());
  1063. } else
  1064. g.r !== void 0 && S.write("r", g.r);
  1065. }), I.reset(), I.get(), w.traverse(I, (g, S) => {
  1066. const re2 = g.d;
  1067. if (re2 != null) {
  1068. const K = C[re2];
  1069. K != null && S.write("d", K);
  1070. const se = $[re2];
  1071. se && S.mergeTree(se.get());
  1072. } else
  1073. g.i !== void 0 && S.write("i", g.i);
  1074. const te = me(g);
  1075. te && !N.has(g) && y(S, te, f(g));
  1076. }), I.get();
  1077. }
  1078. function le(i) {
  1079. if (i == null)
  1080. return null;
  1081. const c = new r.ReadCursor(i), O = new r.WriteCursor();
  1082. let D;
  1083. const w = [], I = [];
  1084. return function R($, p, m) {
  1085. const b = $.getComponent();
  1086. let C, N = false;
  1087. if (b) {
  1088. 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);
  1089. const g = me(b);
  1090. g && (m === void 0 ? (D || (D = /* @__PURE__ */ new Set()), D.add(b)) : (f(b), m = g.apply(m, f(b)), N = true));
  1091. }
  1092. let B = 0;
  1093. for (const g of $) {
  1094. p.descend(g);
  1095. const S = typeof g == "number" ? g - B : g, re2 = Y(m, S);
  1096. s($.getComponent()) && B++;
  1097. const te = R($, p, re2);
  1098. if (m !== void 0 && te !== void 0) {
  1099. if (N || (N = true, m = x(m)), !k(m, S))
  1100. throw Error("Cannot modify child - invalid operation");
  1101. m[S] = te;
  1102. }
  1103. p.ascend();
  1104. }
  1105. if (C === void 0)
  1106. return N ? m : void 0;
  1107. p.write("r", m);
  1108. }(c, O, void 0), D && (O.reset(), function R($, p, m) {
  1109. const b = p.getComponent();
  1110. if (b) {
  1111. const g = b.d;
  1112. if (g != null && ($ = w[g], m = I[g] = r.writeCursor()), D.has(b)) {
  1113. const S = me(b);
  1114. if (!S.invert)
  1115. throw Error(`Cannot invert subtype ${S.name}`);
  1116. y(m, S, S.invert(f(b)));
  1117. }
  1118. }
  1119. let C = 0, N = 0;
  1120. const B = r.advancer($, (g, S) => _(S) ? C - g - 1 : g - C, (g, S) => {
  1121. _(S) && C++;
  1122. });
  1123. for (const g of p)
  1124. if (typeof g == "number") {
  1125. const S = g - N, re2 = B(S), te = S + C;
  1126. m.descend(te), R(re2, p, m), s(p.getComponent()) && N++, m.ascend();
  1127. } else
  1128. m.descend(g), R(B(g), p, m), m.ascend();
  1129. B.end();
  1130. }(c.clone(), c, O), I.length && (O.reset(), c.traverse(O, (R, $) => {
  1131. const p = R.p;
  1132. if (p != null) {
  1133. const m = I[p];
  1134. m && m.get(), m && $.mergeTree(m.get());
  1135. }
  1136. }))), O.get();
  1137. }
  1138. const ge = (i, c) => i.some((O) => typeof O == "object" && (Array.isArray(O) ? ge(O, c) : c(O)));
  1139. function De(i, c) {
  1140. if (i == null || !ge(i, (p) => {
  1141. var m;
  1142. return p.r !== void 0 || ((m = me(p)) === null || m === void 0 ? void 0 : m.makeInvertible) != null;
  1143. }))
  1144. return i;
  1145. const O = new r.ReadCursor(i), D = new r.WriteCursor();
  1146. let w = false;
  1147. const I = [], R = [], $ = (p, m, b) => {
  1148. const C = p.getComponent();
  1149. let N = false;
  1150. if (C) {
  1151. C.d != null && m.write("d", C.d), C.i !== void 0 && m.write("i", C.i);
  1152. const g = C.p;
  1153. 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)
  1154. throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");
  1155. const S = me(C);
  1156. S && (S.makeInvertible ? w = true : y(m, S, f(C), true));
  1157. }
  1158. let B = 0;
  1159. for (const g of p) {
  1160. m.descend(g);
  1161. const S = typeof g == "number" ? g - B : g, re2 = Y(b, S), te = $(p, m, re2);
  1162. re2 !== te && (N || (N = true, b = x(b)), te === void 0 ? (b = d(b, S), typeof g == "number" && B++) : b[S] = te), m.ascend();
  1163. }
  1164. return C && (C.r !== void 0 ? (m.write("r", t.default(b)), b = void 0) : C.p != null && (b = void 0)), b;
  1165. };
  1166. return $(O, D, c), D.get(), w && (D.reset(), function p(m, b, C, N, B) {
  1167. const g = b.getComponent();
  1168. if (g) {
  1169. g.i !== void 0 ? (N = g.i, B = true) : g.d != null && (N = R[g.d], m = I[g.d], B = false, g.d);
  1170. let K = me(g);
  1171. if (K && K.makeInvertible) {
  1172. const se = f(g);
  1173. y(C, K, K.makeInvertible(se, N), true);
  1174. }
  1175. }
  1176. let S = 0, re2 = 0;
  1177. const te = r.advancer(m, (K, se) => _(se) ? S - K - 1 : K - S, (K, se) => {
  1178. _(se) && S++;
  1179. });
  1180. for (const K of b)
  1181. if (typeof K == "number") {
  1182. const se = K - re2, $e = te(se), we = se + S, ye = Y(N, B ? se : we);
  1183. C.descend(K), p($e, b, C, ye, B), s(b.getComponent()) && re2++, C.ascend();
  1184. } else {
  1185. const se = Y(N, K);
  1186. C.descend(K), p(te(K), b, C, se, B), C.ascend();
  1187. }
  1188. te.end();
  1189. }(O.clone(), O, D, c, false)), D.get();
  1190. }
  1191. function kt(i, c) {
  1192. return le(De(i, c));
  1193. }
  1194. const it = (i) => {
  1195. if (i == null)
  1196. return null;
  1197. const c = i.slice();
  1198. for (let O = 0; O < i.length; O++) {
  1199. const D = c[O];
  1200. Array.isArray(D) && (c[O] = it(D));
  1201. }
  1202. return c;
  1203. };
  1204. function st(i, c, O) {
  1205. o(O === "left" || O === "right", "Direction must be left or right");
  1206. const D = O === "left" ? 0 : 1;
  1207. if (c == null)
  1208. return {
  1209. ok: true,
  1210. result: i
  1211. };
  1212. z(i), z(c);
  1213. let w = null;
  1214. const I = [], R = [], $ = [], p = [], m = [], b = [], C = [], N = [], B = [], g = [], S = [], re2 = [], te = [], K = [], se = [];
  1215. let $e = 0;
  1216. const we = r.readCursor(i), ye = r.readCursor(c), oe = r.writeCursor();
  1217. if (function Q(A, W = null, M) {
  1218. const P = l(W);
  1219. P && (P.r !== void 0 ? M = W.clone() : P.p != null && (M = null, b[P.p] = A.clone()));
  1220. const U = A.getComponent();
  1221. let J;
  1222. 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));
  1223. const X = r.advancer(W);
  1224. for (const ee of A)
  1225. Q(A, X(ee), M);
  1226. X.end();
  1227. }(ye, we, null), function Q(A, W, M, P, U) {
  1228. const J = M.getComponent();
  1229. let X, ee = false;
  1230. 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 = {
  1231. type: u.ConflictType.RM_UNEXPECTED_CONTENT,
  1232. op1: a.removeOp(U.getPath()),
  1233. op2: a.moveOp(W.getPath(), M.getPath())
  1234. }), ee = true) : J.i !== void 0 && (A = W = null, ee = true, U && w == null && (w = {
  1235. type: u.ConflictType.RM_UNEXPECTED_CONTENT,
  1236. op1: a.removeOp(U.getPath()),
  1237. op2: a.insertOp(M.getPath(), J.i)
  1238. })));
  1239. const fe = l(A);
  1240. fe && (fe.r !== void 0 ? U = A.clone() : fe.p != null && (fe.p, P = fe.p, U = null));
  1241. const ce = me(J);
  1242. ce && U && w == null && (w = {
  1243. type: u.ConflictType.RM_UNEXPECTED_CONTENT,
  1244. op1: a.removeOp(U.getPath()),
  1245. op2: a.editOp(M.getPath(), ce, f(J), true)
  1246. });
  1247. let ae = 0, Oe = 0;
  1248. const H = r.advancer(W, (G, he) => _(he) ? ae - G - 1 : G - ae, (G, he) => {
  1249. _(he) && ae++;
  1250. }), T = r.advancer(A);
  1251. for (const G of M)
  1252. if (typeof G == "number") {
  1253. const he = G - Oe, be = H(he);
  1254. Oe += +Q(T(he + ae), be, M, P, U);
  1255. } else {
  1256. const he = H(G);
  1257. Q(T(G), he, M, P, U);
  1258. }
  1259. return H.end(), T.end(), ee;
  1260. }(we, ye, ye.clone(), null, null), p.map((Q) => Q && Q.get()), w)
  1261. return {
  1262. ok: false,
  1263. conflict: w
  1264. };
  1265. S.map((Q) => !!Q);
  1266. const Pe = [];
  1267. let Ae = null;
  1268. (function Q(A, W, M, P, U) {
  1269. let J = false;
  1270. const X = l(W);
  1271. if (_(X)) {
  1272. const H = X.p;
  1273. H != null ? (M = p[H], P = re2[H] = r.writeCursor(), J = true, U = null) : (M = null, U = W.clone());
  1274. } else
  1275. s(l(M)) && (M = null);
  1276. const ee = A.getComponent();
  1277. if (ee) {
  1278. const H = ee.p;
  1279. 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)));
  1280. }
  1281. let fe = 0, ce = 0;
  1282. const ae = r.advancer(W, void 0, (H, T) => {
  1283. _(T) && fe++;
  1284. }), Oe = r.advancer(M, (H, T) => s(T) ? ~(H - ce) : H - ce, (H, T) => {
  1285. s(T) && ce++;
  1286. });
  1287. if (A)
  1288. for (const H of A)
  1289. if (typeof H == "string") {
  1290. const T = ae(H), G = Oe(H);
  1291. P.descend(H), Q(A, T, G, P, U), P.ascend();
  1292. } else {
  1293. const T = ae(H), G = H - fe, he = _(l(T)) ? null : Oe(G), be = G + ce;
  1294. o(be >= 0), P.descend(be), Q(A, T, he, P, U), P.ascend();
  1295. }
  1296. ae.end(), Oe.end();
  1297. })(we, ye, ye.clone(), oe, null), oe.reset();
  1298. let Le = [];
  1299. if (function Q(A, W, M, P, U, J) {
  1300. o(W);
  1301. const X = W.getComponent();
  1302. let ee = l(P), fe = false;
  1303. const ce = (j, ie, _e) => j ? a.moveOp(j.getPath(), ie.getPath()) : a.insertOp(ie.getPath(), _e.i);
  1304. if (s(X)) {
  1305. const j = X.d;
  1306. j != null && (R[j] = W.clone());
  1307. const ie = j != null ? Pe[j] : null;
  1308. let _e = false;
  1309. if (X.i !== void 0 || j != null && ie) {
  1310. let ue;
  1311. 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 = {
  1312. type: u.ConflictType.DROP_COLLISION,
  1313. op1: ce(j != null ? I[j] : null, W, X),
  1314. op2: ce(ue != null ? $[ue] : null, P, ee)
  1315. })), _e || (J ? w == null && (w = {
  1316. type: u.ConflictType.RM_UNEXPECTED_CONTENT,
  1317. op1: ce(j != null ? I[j] : null, W, X),
  1318. op2: a.removeOp(J.getPath())
  1319. }) : (j != null ? (Le[$e] = j, U.write("d", ie.p = $e++)) : U.write("i", t.default(X.i)), fe = true));
  1320. } else if (j != null && !ie) {
  1321. const ue = N[j];
  1322. ue && (J = ue.clone());
  1323. }
  1324. j != null ? (A = I[j], M = b[j], P = C[j]) : X.i !== void 0 && (A = M = null, _e || (P = null));
  1325. } else
  1326. _(l(A)) && (A = M = P = null);
  1327. const ae = l(A), Oe = l(M);
  1328. if (_(Oe)) {
  1329. const j = Oe.p;
  1330. 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));
  1331. } else
  1332. !s(X) && s(ee) && (P = null);
  1333. ee = P != null ? P.getComponent() : null;
  1334. const H = me(X);
  1335. if (H) {
  1336. const j = f(X);
  1337. if (J)
  1338. w == null && (w = {
  1339. type: u.ConflictType.RM_UNEXPECTED_CONTENT,
  1340. op1: a.editOp(W.getPath(), H, j, true),
  1341. op2: a.removeOp(J.getPath())
  1342. });
  1343. else {
  1344. const ie = me(ee);
  1345. let _e;
  1346. if (ie) {
  1347. if (H !== ie)
  1348. throw Error("Transforming incompatible types");
  1349. const ue = f(ee);
  1350. _e = H.transform(j, ue, O);
  1351. } else
  1352. _e = t.default(j);
  1353. y(U, H, _e);
  1354. }
  1355. }
  1356. let T = 0, G = 0, he = 0, be = 0, Re = 0, qe = 0, Me = A != null && A.descendFirst(), Je = Me;
  1357. const ze = r.advancer(M, void 0, (j, ie) => {
  1358. _(ie) && he++;
  1359. });
  1360. let ke = P != null && P.descendFirst(), je = ke;
  1361. for (const j of W)
  1362. if (typeof j == "number") {
  1363. let ie;
  1364. const _e = s(W.getComponent()), ue = j - G;
  1365. {
  1366. let Be;
  1367. for (; Me && typeof (Be = A.getKey()) == "number"; ) {
  1368. Be += T;
  1369. const Ue = A.getComponent(), Xe = _(Ue);
  1370. if (Be > ue || Be === ue && (!Xe || D === 0 && _e))
  1371. break;
  1372. if (Xe) {
  1373. T--;
  1374. const Ke = Ue.p;
  1375. 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--;
  1376. }
  1377. Me = A.nextSibling();
  1378. }
  1379. ie = Me && Be === ue ? A : null;
  1380. }
  1381. const Se = ue - T;
  1382. let xe = ze(Se);
  1383. const ot2 = Se - he;
  1384. let Ze = null;
  1385. {
  1386. let Be, Ue;
  1387. for (; ke && typeof (Be = P.getKey()) == "number"; ) {
  1388. Ue = Be - be;
  1389. const Xe = P.getComponent(), Ke = s(Xe);
  1390. if (Ue > ot2)
  1391. break;
  1392. if (Ue === ot2) {
  1393. if (!Ke) {
  1394. Ze = P;
  1395. break;
  1396. }
  1397. {
  1398. if (D === 0 && _e) {
  1399. Ze = P;
  1400. break;
  1401. }
  1402. const We = xe && _(xe.getComponent());
  1403. if (D === 0 && We)
  1404. break;
  1405. }
  1406. }
  1407. if (Ke) {
  1408. const We = Xe.d;
  1409. 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++;
  1410. }
  1411. ke = P.nextSibling();
  1412. }
  1413. }
  1414. const _t = ot2 + be + Re + qe;
  1415. 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();
  1416. } else {
  1417. let ie;
  1418. for (; Me && (ie = A.getKey(), typeof ie != "string" || !(ie > j || ie === j)); )
  1419. Me = A.nextSibling();
  1420. const _e = Me && ie === j ? A : null, ue = ze(j);
  1421. let Se;
  1422. for (; ke && (Se = P.getKey(), typeof Se != "string" || !(Se > j || Se === j)); )
  1423. ke = P.nextSibling();
  1424. const xe = ke && Se === j ? P : null;
  1425. U.descend(j), Q(_e, W, ue, xe, U, J), U.ascend();
  1426. }
  1427. return ze.end(), Je && A.ascend(), je && P.ascend(), fe;
  1428. }(we, we.clone(), ye, ye.clone(), oe, null), w)
  1429. return {
  1430. ok: false,
  1431. conflict: w
  1432. };
  1433. oe.reset();
  1434. const Te = (Q, A, W) => Q.traverse(A, (M, P) => {
  1435. M.d != null && W(M.d, Q, P);
  1436. });
  1437. (g.length || re2.length) && (Te(ye, oe, (Q, A, W) => {
  1438. g[Q] && !S[Q] && W.write("r", true), re2[Q] && W.mergeTree(re2[Q].get());
  1439. }), oe.reset());
  1440. const Ie = [], Ne = [];
  1441. if ((te.length || g.length) && !w) {
  1442. const Q = r.readCursor(it(oe.get()));
  1443. if (Te(Q, null, (A, W) => {
  1444. Ie[A] = W.clone();
  1445. }), te.forEach((A) => {
  1446. A && Te(r.readCursor(A.get()), null, (W, M) => {
  1447. Ie[W] = M.clone();
  1448. });
  1449. }), function A(W, M, P, U, J, X) {
  1450. const ee = l(M);
  1451. if (ee && _(ee))
  1452. if (ee.p != null) {
  1453. const T = ee.p;
  1454. Ie[T].getPath(), P = Ie[T], U = Ne[T] = r.writeCursor();
  1455. } else
  1456. ee.r !== void 0 && (P = null);
  1457. else
  1458. s(l(P)) && (P = null);
  1459. const fe = W.getComponent();
  1460. if (fe) {
  1461. let T;
  1462. if ((T = fe.d) != null) {
  1463. const G = te[T];
  1464. G && (G.get(), U.mergeTree(G.get()), P = r.readCursor(G.get()));
  1465. }
  1466. }
  1467. let ce = 0, ae = 0;
  1468. const Oe = r.advancer(M, void 0, (T, G) => {
  1469. _(G) && ce--;
  1470. }), H = r.advancer(P, (T, G) => s(G) ? -(T - ae) - 1 : T - ae, (T, G) => {
  1471. s(G) && ae++;
  1472. });
  1473. for (const T of W)
  1474. if (typeof T == "number") {
  1475. const G = Oe(T), he = T + ce, be = H(he), Re = he + ae;
  1476. U.descend(Re), A(W, G, be, U), U.ascend();
  1477. } else
  1478. U.descend(T), A(W, Oe(T), H(T), U), U.ascend();
  1479. Oe.end(), H.end();
  1480. }(ye, Q, Q.clone(), oe), oe.reset(), w)
  1481. return {
  1482. ok: false,
  1483. conflict: w
  1484. };
  1485. if (oe.get(), Ne.length) {
  1486. const A = Ne.map((M) => M ? M.get() : null), W = r.readCursor(it(oe.get()));
  1487. if (Te(W, oe, (M, P, U) => {
  1488. const J = A[M];
  1489. J && (U.mergeTree(J), A[M] = null);
  1490. }), A.find((M) => M)) {
  1491. const M = r.writeCursor(), P = r.writeCursor();
  1492. let U = 0, J = 0;
  1493. A.forEach((X) => {
  1494. X != null && Te(r.readCursor(X), null, (ee) => {
  1495. const fe = Le[ee];
  1496. M.writeMove(I[fe].getPath(), R[fe].getPath(), U++);
  1497. const ce = se[fe];
  1498. ce && ce.forEach((ae) => {
  1499. g[ae] || D !== 1 && K[ae] != null || P.writeMove($[ae].getPath(), p[ae].getPath(), J++);
  1500. });
  1501. });
  1502. }), w = {
  1503. type: u.ConflictType.BLACKHOLE,
  1504. op1: M.get(),
  1505. op2: P.get()
  1506. };
  1507. }
  1508. }
  1509. }
  1510. return w ? {
  1511. ok: false,
  1512. conflict: w
  1513. } : {
  1514. ok: true,
  1515. result: oe.get()
  1516. };
  1517. }
  1518. const gt = (i) => {
  1519. const c = new Error("Transform detected write conflict");
  1520. throw c.conflict = i, c.type = c.name = "writeConflict", c;
  1521. };
  1522. function jt(i, c, O) {
  1523. const D = st(i, c, O);
  1524. if (D.ok)
  1525. return D.result;
  1526. gt(D.conflict);
  1527. }
  1528. const He = (i) => {
  1529. const c = r.writeCursor();
  1530. return r.readCursor(i).traverse(c, (O, D) => {
  1531. (s(O) || me(O)) && D.write("r", true);
  1532. }), c.get();
  1533. }, $t = (i, c) => {
  1534. const { type: O, op1: D, op2: w } = i;
  1535. switch (O) {
  1536. case u.ConflictType.DROP_COLLISION:
  1537. return c === "left" ? [null, He(w)] : [He(D), null];
  1538. case u.ConflictType.RM_UNEXPECTED_CONTENT:
  1539. let I = false;
  1540. return r.readCursor(D).traverse(null, (R) => {
  1541. R.r !== void 0 && (I = true);
  1542. }), I ? [null, He(w)] : [He(D), null];
  1543. case u.ConflictType.BLACKHOLE:
  1544. return [He(D), He(w)];
  1545. default:
  1546. throw Error("Unrecognised conflict: " + O);
  1547. }
  1548. };
  1549. function yt(i, c, O, D) {
  1550. let w = null;
  1551. for (; ; ) {
  1552. const I = st(c, O, D);
  1553. if (I.ok)
  1554. return ne(w, I.result);
  1555. {
  1556. const { conflict: R } = I;
  1557. i(R) || gt(R);
  1558. const [$, p] = $t(R, D);
  1559. c = ne(q(c), $), O = ne(q(O), p), w = ne(w, p);
  1560. }
  1561. }
  1562. }
  1563. }(et)), et;
  1564. }
  1565. var Pt2;
  1566. function sn() {
  1567. return Pt2 || (Pt2 = 1, function(a) {
  1568. var e = Ye.__createBinding || (Object.create ? function(u, o, l, E) {
  1569. E === void 0 && (E = l), Object.defineProperty(u, E, { enumerable: true, get: function() {
  1570. return o[l];
  1571. } });
  1572. } : function(u, o, l, E) {
  1573. E === void 0 && (E = l), u[E] = o[l];
  1574. }), n = Ye.__exportStar || function(u, o) {
  1575. for (var l in u)
  1576. l !== "default" && !o.hasOwnProperty(l) && e(o, u, l);
  1577. };
  1578. Object.defineProperty(a, "__esModule", { value: true }), n(rn(), a);
  1579. var t = Mt();
  1580. Object.defineProperty(a, "ReadCursor", { enumerable: true, get: function() {
  1581. return t.ReadCursor;
  1582. } }), Object.defineProperty(a, "WriteCursor", { enumerable: true, get: function() {
  1583. return t.WriteCursor;
  1584. } });
  1585. var r = St();
  1586. Object.defineProperty(a, "ConflictType", { enumerable: true, get: function() {
  1587. return r.ConflictType;
  1588. } });
  1589. }(Ye)), Ye;
  1590. }
  1591. var V = sn();
  1592. var on = class {
  1593. constructor() {
  1594. F(this, "drawingManagerData", {});
  1595. F(this, "_oldDrawingManagerData", {});
  1596. F(this, "_focusDrawings", []);
  1597. F(this, "_remove$", new Subject());
  1598. F(this, "remove$", this._remove$.asObservable());
  1599. F(this, "_add$", new Subject());
  1600. F(this, "add$", this._add$.asObservable());
  1601. F(this, "_update$", new Subject());
  1602. F(this, "update$", this._update$.asObservable());
  1603. F(this, "_order$", new Subject());
  1604. F(this, "order$", this._order$.asObservable());
  1605. F(this, "_group$", new Subject());
  1606. F(this, "group$", this._group$.asObservable());
  1607. F(this, "_ungroup$", new Subject());
  1608. F(this, "ungroup$", this._ungroup$.asObservable());
  1609. F(this, "_refreshTransform$", new Subject());
  1610. F(this, "refreshTransform$", this._refreshTransform$.asObservable());
  1611. F(this, "_visible$", new Subject());
  1612. F(this, "visible$", this._visible$.asObservable());
  1613. F(this, "_focus$", new Subject());
  1614. F(this, "focus$", this._focus$.asObservable());
  1615. F(this, "_featurePluginUpdate$", new Subject());
  1616. F(this, "featurePluginUpdate$", this._featurePluginUpdate$.asObservable());
  1617. F(this, "_featurePluginAdd$", new Subject());
  1618. F(this, "featurePluginAdd$", this._featurePluginAdd$.asObservable());
  1619. F(this, "_featurePluginRemove$", new Subject());
  1620. F(this, "featurePluginRemove$", this._featurePluginRemove$.asObservable());
  1621. F(this, "_featurePluginOrderUpdate$", new Subject());
  1622. F(this, "featurePluginOrderUpdate$", this._featurePluginOrderUpdate$.asObservable());
  1623. F(this, "_featurePluginGroupUpdate$", new Subject());
  1624. F(this, "featurePluginGroupUpdate$", this._featurePluginGroupUpdate$.asObservable());
  1625. F(this, "_featurePluginUngroupUpdate$", new Subject());
  1626. F(this, "featurePluginUngroupUpdate$", this._featurePluginUngroupUpdate$.asObservable());
  1627. F(this, "_visible", true);
  1628. F(this, "_editable", true);
  1629. }
  1630. dispose() {
  1631. 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 = {};
  1632. }
  1633. visibleNotification(e) {
  1634. this._visible$.next(e);
  1635. }
  1636. refreshTransform(e) {
  1637. e.forEach((n) => {
  1638. const t = this._getCurrentBySearch(n);
  1639. t != null && (t.transform = n.transform, t.transforms = n.transforms, t.isMultiTransform = n.isMultiTransform);
  1640. }), this.refreshTransformNotification(e);
  1641. }
  1642. getDrawingDataForUnit(e) {
  1643. return this.drawingManagerData[e] || {};
  1644. }
  1645. removeDrawingDataForUnit(e) {
  1646. const n = this.drawingManagerData[e];
  1647. if (n == null)
  1648. return;
  1649. delete this.drawingManagerData[e];
  1650. const t = [];
  1651. Object.keys(n).forEach((r) => {
  1652. const u = n[r];
  1653. (u == null ? void 0 : u.data) != null && Object.keys(u.data).forEach((o) => {
  1654. t.push({ unitId: e, subUnitId: r, drawingId: o });
  1655. });
  1656. }), t.length > 0 && this.removeNotification(t);
  1657. }
  1658. registerDrawingData(e, n) {
  1659. this.drawingManagerData[e] = n;
  1660. }
  1661. initializeNotification(e) {
  1662. const n = [], t = this.drawingManagerData[e];
  1663. t != null && (Object.keys(t).forEach((r) => {
  1664. this._establishDrawingMap(e, r);
  1665. const u = t[r];
  1666. Object.keys(u.data).forEach((o) => {
  1667. const l = u.data[o];
  1668. l.unitId = e, l.subUnitId = r, n.push(l);
  1669. });
  1670. }), n.length > 0 && this.addNotification(n));
  1671. }
  1672. getDrawingData(e, n) {
  1673. return this._getDrawingData(e, n);
  1674. }
  1675. // Use in doc only.
  1676. setDrawingData(e, n, t) {
  1677. this.drawingManagerData[e][n].data = t;
  1678. }
  1679. getBatchAddOp(e) {
  1680. const n = [], t = [], r = [];
  1681. e.forEach((x) => {
  1682. const { op: _, invertOp: s } = this._addByParam(x);
  1683. n.push({ unitId: x.unitId, subUnitId: x.subUnitId, drawingId: x.drawingId }), t.push(_), r.push(s);
  1684. });
  1685. const u = t.reduce(V.type.compose, null), o = r.reduce(V.type.compose, null), { unitId: l, subUnitId: E } = e[0];
  1686. return { undo: o, redo: u, unitId: l, subUnitId: E, objects: n };
  1687. }
  1688. getBatchRemoveOp(e) {
  1689. const n = [], t = [];
  1690. e.forEach((E) => {
  1691. const { op: x, invertOp: _ } = this._removeByParam(E);
  1692. n.unshift(x), t.push(_);
  1693. });
  1694. const r = n.reduce(V.type.compose, null), u = t.reduce(V.type.compose, null), { unitId: o, subUnitId: l } = e[0];
  1695. return { undo: u, redo: r, unitId: o, subUnitId: l, objects: e };
  1696. }
  1697. getBatchUpdateOp(e) {
  1698. const n = [], t = [], r = [];
  1699. e.forEach((x) => {
  1700. const { op: _, invertOp: s } = this._updateByParam(x);
  1701. n.push({ unitId: x.unitId, subUnitId: x.subUnitId, drawingId: x.drawingId }), t.push(_), r.push(s);
  1702. });
  1703. const u = t.reduce(V.type.compose, null), o = r.reduce(V.type.compose, null), { unitId: l, subUnitId: E } = e[0];
  1704. return { undo: o, redo: u, unitId: l, subUnitId: E, objects: n };
  1705. }
  1706. removeNotification(e) {
  1707. this._remove$.next(e);
  1708. }
  1709. addNotification(e) {
  1710. this._add$.next(e);
  1711. }
  1712. updateNotification(e) {
  1713. this._update$.next(e);
  1714. }
  1715. orderNotification(e) {
  1716. this._order$.next(e);
  1717. }
  1718. groupUpdateNotification(e) {
  1719. this._group$.next(e);
  1720. }
  1721. ungroupUpdateNotification(e) {
  1722. this._ungroup$.next(e);
  1723. }
  1724. refreshTransformNotification(e) {
  1725. this._refreshTransform$.next(e);
  1726. }
  1727. getGroupDrawingOp(e) {
  1728. const n = [], { unitId: t, subUnitId: r } = e[0].parent;
  1729. e.forEach((l) => {
  1730. n.push(this._getGroupDrawingOp(l));
  1731. });
  1732. const u = n.reduce(V.type.compose, null);
  1733. return { undo: V.type.invertWithDoc(u, this.drawingManagerData), redo: u, unitId: t, subUnitId: r, objects: e };
  1734. }
  1735. getUngroupDrawingOp(e) {
  1736. const n = [], { unitId: t, subUnitId: r } = e[0].parent;
  1737. e.forEach((l) => {
  1738. n.push(this._getUngroupDrawingOp(l));
  1739. });
  1740. const u = n.reduce(V.type.compose, null);
  1741. return { undo: V.type.invertWithDoc(u, this.drawingManagerData), redo: u, unitId: t, subUnitId: r, objects: e };
  1742. }
  1743. getDrawingsByGroup(e) {
  1744. const { unitId: n, subUnitId: t, drawingId: r } = e;
  1745. if (this.getDrawingByParam({ unitId: n, subUnitId: t, drawingId: r }) == null)
  1746. return [];
  1747. const o = this._getDrawingData(n, t), l = [];
  1748. return Object.keys(o).forEach((E) => {
  1749. const x = o[E];
  1750. x.groupId === r && l.push(x);
  1751. }), l;
  1752. }
  1753. _getGroupDrawingOp(e) {
  1754. const { parent: n, children: t } = e, { unitId: r, subUnitId: u, drawingId: o } = n, l = [];
  1755. l.push(
  1756. V.insertOp([r, u, "data", o], n)
  1757. );
  1758. let E = Number.NEGATIVE_INFINITY;
  1759. return t.forEach((x) => {
  1760. const { unitId: _, subUnitId: s, drawingId: d } = x, h = this._hasDrawingOrder({ unitId: _, subUnitId: s, drawingId: d });
  1761. E = Math.max(E, h), l.push(
  1762. ...this._getUpdateParamCompareOp(x, this.getDrawingByParam({ unitId: _, subUnitId: s, drawingId: d }))
  1763. );
  1764. }), E === Number.NEGATIVE_INFINITY && (E = this._getDrawingOrder(r, u).length), l.push(
  1765. V.insertOp([r, u, "order", E], o)
  1766. ), l.reduce(V.type.compose, null);
  1767. }
  1768. _getUngroupDrawingOp(e) {
  1769. const { parent: n, children: t } = e, { unitId: r, subUnitId: u, drawingId: o } = n, l = [];
  1770. return t.forEach((E) => {
  1771. const { unitId: x, subUnitId: _, drawingId: s } = E;
  1772. l.push(
  1773. ...this._getUpdateParamCompareOp(E, this.getDrawingByParam({ unitId: x, subUnitId: _, drawingId: s }))
  1774. );
  1775. }), l.push(
  1776. V.removeOp([r, u, "data", o], true)
  1777. ), l.push(
  1778. V.removeOp([r, u, "order", this._getDrawingOrder(r, u).indexOf(o)], true)
  1779. ), l.reduce(V.type.compose, null);
  1780. }
  1781. applyJson1(e, n, t) {
  1782. this._establishDrawingMap(e, n), this._oldDrawingManagerData = { ...this.drawingManagerData }, this.drawingManagerData = V.type.apply(this.drawingManagerData, t);
  1783. }
  1784. // private _fillMissingFields(jsonOp: JSONOp) {
  1785. // if (jsonOp == null) {
  1786. // return;
  1787. // }
  1788. // let object: { [key: string]: {} } = this.drawingManagerData;
  1789. // for (let i = 0; i < jsonOp.length; i++) {
  1790. // const op = jsonOp[i];
  1791. // if (Array.isArray(op)) {
  1792. // const opKey = op[0] as string;
  1793. // if (!(opKey in object)) {
  1794. // object[opKey] = null as unknown as never;
  1795. // }
  1796. // } else if (typeof op === 'string') {
  1797. // object = object[op];
  1798. // if (object == null) {
  1799. // break;
  1800. // }
  1801. // }
  1802. // }
  1803. // }
  1804. featurePluginUpdateNotification(e) {
  1805. this._featurePluginUpdate$.next(e);
  1806. }
  1807. featurePluginOrderUpdateNotification(e) {
  1808. this._featurePluginOrderUpdate$.next(e);
  1809. }
  1810. featurePluginAddNotification(e) {
  1811. this._featurePluginAdd$.next(e);
  1812. }
  1813. featurePluginRemoveNotification(e) {
  1814. this._featurePluginRemove$.next(e);
  1815. }
  1816. featurePluginGroupUpdateNotification(e) {
  1817. this._featurePluginGroupUpdate$.next(e);
  1818. }
  1819. featurePluginUngroupUpdateNotification(e) {
  1820. this._featurePluginUngroupUpdate$.next(e);
  1821. }
  1822. getDrawingByParam(e) {
  1823. return this._getCurrentBySearch(e);
  1824. }
  1825. getOldDrawingByParam(e) {
  1826. return this._getOldBySearch(e);
  1827. }
  1828. getDrawingOKey(e) {
  1829. const [n, t, r] = e.split("#-#");
  1830. return this._getCurrentBySearch({ unitId: n, subUnitId: t, drawingId: r });
  1831. }
  1832. focusDrawing(e) {
  1833. if (e == null || e.length === 0) {
  1834. this._focusDrawings = [], this._focus$.next([]);
  1835. return;
  1836. }
  1837. const n = [];
  1838. e.forEach((t) => {
  1839. var E;
  1840. const { unitId: r, subUnitId: u, drawingId: o } = t, l = (E = this._getDrawingData(r, u)) == null ? void 0 : E[o];
  1841. l != null && n.push(l);
  1842. }), n.length > 0 && (this._focusDrawings = n, this._focus$.next(n));
  1843. }
  1844. getFocusDrawings() {
  1845. const e = [];
  1846. return this._focusDrawings.forEach((n) => {
  1847. var l;
  1848. const { unitId: t, subUnitId: r, drawingId: u } = n, o = (l = this._getDrawingData(t, r)) == null ? void 0 : l[u];
  1849. o != null && e.push(o);
  1850. }), e;
  1851. }
  1852. getDrawingOrder(e, n) {
  1853. return this._getDrawingOrder(e, n);
  1854. }
  1855. // Use in doc only.
  1856. setDrawingOrder(e, n, t) {
  1857. this.drawingManagerData[e][n].order = t;
  1858. }
  1859. orderUpdateNotification(e) {
  1860. this._order$.next(e);
  1861. }
  1862. getForwardDrawingsOp(e) {
  1863. const { unitId: n, subUnitId: t, drawingIds: r } = e, u = [], o = this.getDrawingOrder(n, t), l = [...r];
  1864. r.forEach((_) => {
  1865. const s = this._hasDrawingOrder({ unitId: n, subUnitId: t, drawingId: _ });
  1866. if (s === -1 || s === o.length - 1)
  1867. return;
  1868. const d = V.moveOp([n, t, "order", s], [n, t, "order", s + 1]);
  1869. u.push(d), l.includes(o[s + 1]) || l.push(o[s + 1]);
  1870. });
  1871. const E = u.reduce(V.type.compose, null);
  1872. return { undo: V.type.invertWithDoc(E, this.drawingManagerData), redo: E, unitId: n, subUnitId: t, objects: { ...e, drawingIds: l } };
  1873. }
  1874. getBackwardDrawingOp(e) {
  1875. const { unitId: n, subUnitId: t, drawingIds: r } = e, u = [], o = this.getDrawingOrder(n, t), l = [...r];
  1876. r.forEach((_) => {
  1877. const s = this._hasDrawingOrder({ unitId: n, subUnitId: t, drawingId: _ });
  1878. if (s === -1 || s === 0)
  1879. return;
  1880. const d = V.moveOp([n, t, "order", s], [n, t, "order", s - 1]);
  1881. u.push(d), l.includes(o[s - 1]) || l.push(o[s - 1]);
  1882. });
  1883. const E = u.reduce(V.type.compose, null);
  1884. return { undo: V.type.invertWithDoc(E, this.drawingManagerData), redo: E, unitId: n, subUnitId: t, objects: { ...e, drawingIds: l } };
  1885. }
  1886. getFrontDrawingsOp(e) {
  1887. const { unitId: n, subUnitId: t, drawingIds: r } = e, u = this._getOrderFromSearchParams(n, t, r), o = [...r], l = this.getDrawingOrder(n, t), E = [];
  1888. u.forEach((s) => {
  1889. 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]);
  1890. E.push(k), o.includes(l[h]) || o.push(l[h]);
  1891. });
  1892. const x = E.reduce(V.type.compose, null);
  1893. return { undo: V.type.invertWithDoc(x, this.drawingManagerData), redo: x, unitId: n, subUnitId: t, objects: { ...e, drawingIds: o } };
  1894. }
  1895. getBackDrawingsOp(e) {
  1896. const { unitId: n, subUnitId: t, drawingIds: r } = e, u = this._getOrderFromSearchParams(n, t, r, true), o = [...r], l = this.getDrawingOrder(n, t), E = [];
  1897. u.forEach((s) => {
  1898. const { drawingId: d } = s, h = V.moveOp([n, t, "order", this._getDrawingOrder(n, t).indexOf(d)], [n, t, "order", 0]);
  1899. E.push(h), o.includes(l[0]) || o.push(l[0]);
  1900. });
  1901. const x = E.reduce(V.type.compose, null);
  1902. return { undo: V.type.invertWithDoc(x, this.drawingManagerData), redo: x, unitId: n, subUnitId: t, objects: { ...e, drawingIds: o } };
  1903. }
  1904. _getDrawingCount(e, n) {
  1905. return this.getDrawingOrder(e, n).length || 0;
  1906. }
  1907. _getOrderFromSearchParams(e, n, t, r = false) {
  1908. return t.map((u) => {
  1909. const o = this._hasDrawingOrder({ unitId: e, subUnitId: n, drawingId: u });
  1910. return { drawingId: u, zIndex: o };
  1911. }).sort(r === false ? KC : XC);
  1912. }
  1913. _hasDrawingOrder(e) {
  1914. if (e == null)
  1915. return -1;
  1916. const { unitId: n, subUnitId: t, drawingId: r } = e;
  1917. return this._establishDrawingMap(n, t), this._getDrawingOrder(n, t).indexOf(r);
  1918. }
  1919. _getCurrentBySearch(e) {
  1920. var u, o, l;
  1921. if (e == null)
  1922. return;
  1923. const { unitId: n, subUnitId: t, drawingId: r } = e;
  1924. return (l = (o = (u = this.drawingManagerData[n]) == null ? void 0 : u[t]) == null ? void 0 : o.data) == null ? void 0 : l[r];
  1925. }
  1926. _getOldBySearch(e) {
  1927. var u, o, l;
  1928. if (e == null)
  1929. return;
  1930. const { unitId: n, subUnitId: t, drawingId: r } = e;
  1931. return (l = (o = (u = this._oldDrawingManagerData[n]) == null ? void 0 : u[t]) == null ? void 0 : o.data) == null ? void 0 : l[r];
  1932. }
  1933. _establishDrawingMap(e, n, t) {
  1934. var r;
  1935. return this.drawingManagerData[e] || (this.drawingManagerData[e] = {}), this.drawingManagerData[e][n] || (this.drawingManagerData[e][n] = {
  1936. data: {},
  1937. order: []
  1938. }), t == null ? null : (r = this.drawingManagerData[e][n].data) == null ? void 0 : r[t];
  1939. }
  1940. _addByParam(e) {
  1941. const { unitId: n, subUnitId: t, drawingId: r } = e;
  1942. this._establishDrawingMap(n, t, r);
  1943. 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);
  1944. return { op: l, invertOp: E };
  1945. }
  1946. _removeByParam(e) {
  1947. if (e == null)
  1948. return { op: [], invertOp: [] };
  1949. const { unitId: n, subUnitId: t, drawingId: r } = e;
  1950. if (this._establishDrawingMap(n, t, r) == null)
  1951. return { op: [], invertOp: [] };
  1952. 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);
  1953. return { op: E, invertOp: x };
  1954. }
  1955. _updateByParam(e) {
  1956. const { unitId: n, subUnitId: t, drawingId: r } = e, u = this._establishDrawingMap(n, t, r);
  1957. if (u == null)
  1958. return { op: [], invertOp: [] };
  1959. const l = this._getUpdateParamCompareOp(e, u).reduce(V.type.compose, null), E = V.type.invertWithDoc(l, this.drawingManagerData);
  1960. return { op: l, invertOp: E };
  1961. }
  1962. // private _initializeDrawingData(updateParam: T, oldParam: T) {
  1963. // Object.keys(updateParam).forEach((key) => {
  1964. // if (!(key in oldParam)) {
  1965. // oldParam[key as keyof IDrawingParam] = null as unknown as never;
  1966. // }
  1967. // });
  1968. // }
  1969. _getUpdateParamCompareOp(e, n) {
  1970. const { unitId: t, subUnitId: r, drawingId: u } = e, o = [];
  1971. return Object.keys(e).forEach((l) => {
  1972. const E = e[l], x = n[l];
  1973. x !== E && o.push(
  1974. V.replaceOp([t, r, "data", u, l], x, E)
  1975. );
  1976. }), o;
  1977. }
  1978. _getDrawingData(e, n) {
  1979. var t, r;
  1980. return ((r = (t = this.drawingManagerData[e]) == null ? void 0 : t[n]) == null ? void 0 : r.data) || {};
  1981. }
  1982. _getDrawingOrder(e, n) {
  1983. var t, r;
  1984. return ((r = (t = this.drawingManagerData[e]) == null ? void 0 : t[n]) == null ? void 0 : r.order) || [];
  1985. }
  1986. getDrawingVisible() {
  1987. return this._visible;
  1988. }
  1989. getDrawingEditable() {
  1990. return this._editable;
  1991. }
  1992. setDrawingVisible(e) {
  1993. this._visible = e;
  1994. }
  1995. setDrawingEditable(e) {
  1996. this._editable = e;
  1997. }
  1998. };
  1999. var an = class extends on {
  2000. };
  2001. function bn({ unitId: a, subUnitId: e, drawingId: n }, t) {
  2002. return typeof t == "number" ? `${a}#-#${e}#-#${n}#-#${t}` : `${a}#-#${e}#-#${n}`;
  2003. }
  2004. var vn = async (a) => new Promise((e, n) => {
  2005. const t = new Image();
  2006. t.src = a, t.onload = () => {
  2007. e({
  2008. width: t.width,
  2009. height: t.height,
  2010. image: t
  2011. });
  2012. }, t.onerror = (r) => {
  2013. n(r);
  2014. };
  2015. });
  2016. var Ut = Ct("univer.drawing-manager.service");
  2017. var ln = {
  2018. id: "drawing.operation.set-drawing-selected",
  2019. type: ar.OPERATION,
  2020. handler: (a, e) => {
  2021. const n = a.get(Ut);
  2022. return e == null ? false : (n.focusDrawing(e), true);
  2023. }
  2024. };
  2025. var un = "drawing.config";
  2026. var Tt = {};
  2027. var dn = class {
  2028. constructor() {
  2029. F(this, "_waitCount", 0);
  2030. F(this, "_change$", new Subject());
  2031. F(this, "change$", this._change$);
  2032. F(this, "_imageSourceCache", /* @__PURE__ */ new Map());
  2033. }
  2034. setWaitCount(e) {
  2035. this._waitCount = e, this._change$.next(e);
  2036. }
  2037. getImageSourceCache(e, n) {
  2038. if (n === vl.BASE64) {
  2039. const t = new Image();
  2040. return t.src = e, t;
  2041. }
  2042. return this._imageSourceCache.get(e);
  2043. }
  2044. addImageSourceCache(e, n, t) {
  2045. n === vl.BASE64 || t == null || this._imageSourceCache.set(e, t);
  2046. }
  2047. async getImage(e) {
  2048. return Promise.resolve(e);
  2049. }
  2050. async saveImage(e) {
  2051. return new Promise((n, t) => {
  2052. if (!Zt.includes(e.type)) {
  2053. t(new Error(g0.ERROR_IMAGE_TYPE)), this._decreaseWaiting();
  2054. return;
  2055. }
  2056. if (e.size > Yt) {
  2057. t(new Error(g0.ERROR_EXCEED_SIZE)), this._decreaseWaiting();
  2058. return;
  2059. }
  2060. const r = new FileReader();
  2061. r.readAsDataURL(e), r.onload = (u) => {
  2062. var E;
  2063. const o = (E = u.target) == null ? void 0 : E.result;
  2064. if (o == null) {
  2065. t(new Error(g0.ERROR_IMAGE)), this._decreaseWaiting();
  2066. return;
  2067. }
  2068. const l = re.generateRandomId(6);
  2069. n({
  2070. imageId: l,
  2071. imageSourceType: vl.BASE64,
  2072. source: o,
  2073. base64Cache: o,
  2074. status: g0.SUCCUSS
  2075. }), this._decreaseWaiting();
  2076. };
  2077. });
  2078. }
  2079. _decreaseWaiting() {
  2080. this._waitCount -= 1, this._change$.next(this._waitCount);
  2081. }
  2082. };
  2083. var cn = Object.defineProperty;
  2084. var fn = Object.getOwnPropertyDescriptor;
  2085. var hn = (a, e, n, t) => {
  2086. for (var r = t > 1 ? void 0 : t ? fn(e, n) : e, u = a.length - 1, o; u >= 0; u--)
  2087. (o = a[u]) && (r = (t ? o(e, n, r) : o(r)) || r);
  2088. return t && r && cn(e, n, r), r;
  2089. };
  2090. var ct = (a, e) => (n, t) => e(n, t, a);
  2091. var pn = "UNIVER_DRAWING_PLUGIN";
  2092. var ft;
  2093. var At = (ft = class extends Ra {
  2094. constructor(a = Tt, e, n, t) {
  2095. super(), this._config = a, this._injector = e, this._configService = n, this._commandService = t;
  2096. const { ...r } = nu(
  2097. {},
  2098. Tt,
  2099. this._config
  2100. );
  2101. this._configService.setConfig(un, r);
  2102. }
  2103. onStarting() {
  2104. this._initCommands(), this._initDependencies();
  2105. }
  2106. _initDependencies() {
  2107. var n;
  2108. kE([
  2109. [Oa, { useClass: dn }],
  2110. [Ut, { useClass: an }]
  2111. ], (n = this._config) == null ? void 0 : n.override).forEach((t) => this._injector.add(t));
  2112. }
  2113. _initCommands() {
  2114. [
  2115. ln
  2116. ].forEach((a) => this.disposeWithMe(this._commandService.registerCommand(a)));
  2117. }
  2118. }, F(ft, "pluginName", pn), ft);
  2119. At = hn([
  2120. ct(1, ot(Ot)),
  2121. ct(2, SE),
  2122. ct(3, Pt)
  2123. ], At);
  2124. export {
  2125. mn,
  2126. On,
  2127. wn,
  2128. Yt,
  2129. Zt,
  2130. on,
  2131. an,
  2132. bn,
  2133. vn,
  2134. Ut,
  2135. ln,
  2136. dn,
  2137. At
  2138. };
  2139. //# sourceMappingURL=chunk-QG2HZMYH.js.map