@silurus/ooxml 0.87.0 → 0.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +118 -23
  2. package/THIRD_PARTY_NOTICES.md +7 -6
  3. package/dist/abort-VrnK7mdP.js +10 -0
  4. package/dist/assets/render-worker-CUOU6mL2.js +16 -0
  5. package/dist/assets/render-worker-DOqrFhSU.js +15 -0
  6. package/dist/assets/render-worker-DvWUdZUN.js +35 -0
  7. package/dist/bounded-raw-part-cache-B7JoC1CD.js +64586 -0
  8. package/dist/bundled-asset-url-E2nXURF9.js +15 -0
  9. package/dist/canvas-viewer-mechanics-DfQqRKkD.js +675 -0
  10. package/dist/cfb-guard-9QTRTg7f.js +528 -0
  11. package/dist/chart-ex.mjs +708 -739
  12. package/dist/comment-overlay-controller-B5_zGgG5.js +994 -0
  13. package/dist/comment-ui-runtime-B7ZvovcS.js +2 -0
  14. package/dist/{comment-ui-runtime-DcJOYlw-.js → comment-ui-runtime-D_sb2K6s.js} +5 -5
  15. package/dist/{comment-ui-runtime-BfE7MJZn.js → comment-ui-runtime-Jy-3goA9.js} +5 -5
  16. package/dist/delimited-text-worker-host-CikWU6_m.js +27 -0
  17. package/dist/document-model-source-BKNrXjAL.js +249 -0
  18. package/dist/document-pull-client-CxONDGbk.js +37833 -0
  19. package/dist/document-pull-worker-AMyXYpPq.js +104 -0
  20. package/dist/docx-D91ER1_S.js +495 -0
  21. package/dist/docx-DhDnKEI6.js +3563 -0
  22. package/dist/docx-model-source-CdrSt3hF.js +98 -0
  23. package/dist/docx-source-worker.mjs +455 -0
  24. package/dist/docx.mjs +7 -7
  25. package/dist/docx_parser_bg.wasm +0 -0
  26. package/dist/drawingml-shape-ChcGZNd8.js +310 -0
  27. package/dist/duotone-ekYik4ix.js +126 -0
  28. package/dist/emf-UT6I8rVi.js +1790 -0
  29. package/dist/font-preload-demand-CdJZUMCT.js +2058 -0
  30. package/dist/grid-geometry-uQOgViJU.js +384 -0
  31. package/dist/host-layout-DVMw8hDY.js +56 -0
  32. package/dist/host-layout-measure-CCEgaC_v.js +7 -0
  33. package/dist/in-process-pull-transport-DuXcPZng.js +29 -0
  34. package/dist/index.mjs +4 -4
  35. package/dist/internal-companion.mjs +12 -0
  36. package/dist/line-distribute-CPOV6csk.js +2716 -0
  37. package/dist/math.mjs +2 -2
  38. package/dist/mathjax-stix2.js +10 -10
  39. package/dist/model-source-DJGzDtGb.js +61 -0
  40. package/dist/model-source-kz_NkZqT.js +179 -0
  41. package/dist/model-source-session-Bu9CHFHc.js +71 -0
  42. package/dist/model-source-session-CDuijwv1.js +85 -0
  43. package/dist/model-source-session-sKpNiIJI.js +58 -0
  44. package/dist/node.mjs +7 -1327
  45. package/dist/{pixel-budget-Dgjw269h.js → pixel-budget-BpTYrepD.js} +13 -10
  46. package/dist/plot-area-frame-CaJFvZ7p.js +8502 -0
  47. package/dist/pptx-CDP9dZHe.js +2936 -0
  48. package/dist/pptx-C_uxLVKB.js +183 -0
  49. package/dist/pptx-model-source-O7LhpOjz.js +37 -0
  50. package/dist/pptx-source-worker.mjs +446 -0
  51. package/dist/pptx.mjs +8 -7
  52. package/dist/pptx_parser_bg.wasm +0 -0
  53. package/dist/presentation-model-source-tmROzteR.js +77 -0
  54. package/dist/raster-target-YQ4G6rxo.js +42 -0
  55. package/dist/region-map.mjs +114 -150
  56. package/dist/{render-8Zo7dnds.js → render-CJVglUHl.js} +3 -3
  57. package/dist/{render-worker-host-BfbnEChF.js → render-worker-host-BseIaVvm.js} +1 -1
  58. package/dist/{render-worker-host-DNL9dWRh.js → render-worker-host-CyxPU4JU.js} +1 -1
  59. package/dist/{render-worker-host-IkHrYOci.js → render-worker-host-aF6aWkC0.js} +1 -1
  60. package/dist/renderer-CkGLj0CC.js +5170 -0
  61. package/dist/renderer-Czw1cCC7.js +5823 -0
  62. package/dist/resource-measurement-mXw-WjMF.js +771 -0
  63. package/dist/session-Csv9maad.js +656 -0
  64. package/dist/slide-pull-client-DRZYwBTu.js +6515 -0
  65. package/dist/three-d-BK5siJgJ.js +878 -0
  66. package/dist/three-d.mjs +871 -764
  67. package/dist/{raster-target-ojDdQizC.js → tiff-contract-C6M3QcPp.js} +1 -42
  68. package/dist/tiff.mjs +401 -248
  69. package/dist/types/chart-ex.d.ts +289 -4
  70. package/dist/types/docx.d.ts +473 -98
  71. package/dist/types/index.d.ts +674 -303
  72. package/dist/types/internal-companion.d.ts +11 -0
  73. package/dist/types/math.d.ts +1 -1
  74. package/dist/types/node.d.ts +530 -11
  75. package/dist/types/pptx.d.ts +410 -97
  76. package/dist/types/region-map.d.ts +289 -4
  77. package/dist/types/three-d.d.ts +289 -4
  78. package/dist/types/tiff.d.ts +1 -1
  79. package/dist/types/xlsx.d.ts +483 -134
  80. package/dist/wasm-loader-rlgHmcSv.js +35 -0
  81. package/dist/wasm-runtime-generation-DX4y0Ecl.js +97 -0
  82. package/dist/workbook-model-source-BTC4ISTS.js +94 -0
  83. package/dist/worker-source-I1cIYBel.js +22 -0
  84. package/dist/worker-source-SbudzjYL.js +22 -0
  85. package/dist/worker-source-UAi3GNcM.js +22 -0
  86. package/dist/worksheet-pull-client-CkHgbtyM.js +579 -0
  87. package/dist/xlsx-CpSDPAEU.js +5809 -0
  88. package/dist/xlsx-D5569TPf.js +534 -0
  89. package/dist/xlsx-model-source-DPSkjFic.js +309 -0
  90. package/dist/xlsx-source-worker.mjs +525 -0
  91. package/dist/xlsx.mjs +8 -7
  92. package/dist/xlsx_parser_bg.wasm +0 -0
  93. package/package.json +42 -16
  94. package/dist/assets/render-worker-CeK_iqK3.js +0 -10
  95. package/dist/assets/render-worker-DusrDhPk.js +0 -11
  96. package/dist/assets/render-worker-n2ZG0lrQ.js +0 -31
  97. package/dist/bounded-raw-part-cache-Cg1BsSZQ.js +0 -119
  98. package/dist/canvas-viewer-mechanics-Cpk0YFvM.js +0 -1384
  99. package/dist/cjk-fallback-bLI3z70h.js +0 -46
  100. package/dist/comment-occurrence-C8Y2uoVr.js +0 -6
  101. package/dist/comment-ui-runtime-BsK8pmUT.js +0 -2
  102. package/dist/comments-Diid5ujN.js +0 -246
  103. package/dist/delimited-text-worker-host-BVY-Ecni.js +0 -27
  104. package/dist/document-pull-client-yKxI8aDH.js +0 -27251
  105. package/dist/docx-BkSRiy07.js +0 -2995
  106. package/dist/dom-interaction-boundary-CBUQJsIM.js +0 -223
  107. package/dist/highlight-rect-C5hkRqUr.js +0 -13
  108. package/dist/hyperlink-ArrU3ArU.js +0 -36447
  109. package/dist/line-distribute-Dtudnqhs.js +0 -1023
  110. package/dist/line-metrics-B60C86uh.js +0 -60
  111. package/dist/plot-area-frame-D5hEOgkJ.js +0 -2903
  112. package/dist/pptx-62MmVbYB.js +0 -3063
  113. package/dist/renderer-XFSCOT6m.js +0 -5857
  114. package/dist/resource-measurement-CJsgolre.js +0 -150
  115. package/dist/session-CrU8f8DI.js +0 -743
  116. package/dist/slide-pull-client-B9KA8bU6.js +0 -6253
  117. package/dist/source-key-DIJG8BA0.js +0 -42
  118. package/dist/three-d-YYghQndN.js +0 -1346
  119. package/dist/transfer-p6iCC2R7.js +0 -6
  120. package/dist/units-EJdC96r6.js +0 -4
  121. package/dist/worksheet-pull-client-eIcQ-xlD.js +0 -458
  122. package/dist/xlsx-CRcSzZNq.js +0 -8482
  123. /package/dist/{chunk-DmhlhrBa.js → chunk-Dy4uBu1J.js} +0 -0
  124. /package/dist/{mathjax-DoyWZbSp.js → mathjax-BhwN6ilc.js} +0 -0
  125. /package/dist/{read-only-comment-decoration-Dz7eTQ4d.js → read-only-comment-decoration-PidH0wnP.js} +0 -0
  126. /package/dist/{read-only-comment-margin-DkgzASAl.js → read-only-comment-margin-B52rDVKo.js} +0 -0
  127. /package/dist/{renderer-module-contract-D91rkYHH.js → renderer-module-contract-CWM7jv6d.js} +0 -0
  128. /package/dist/{visible-index-BgiHEc1z.js → visible-index-FeVA0mGE.js} +0 -0
@@ -0,0 +1,994 @@
1
+ import { Dn as e, Gn as t, Hn as n, Kn as r, Q as i, qn as a } from "./bounded-raw-part-cache-B7JoC1CD.js";
2
+ import { C as o, S as s, _ as c, a as l, b as u, g as d, h as f, l as p, m, p as h, r as g, x as _, y as v } from "./canvas-viewer-mechanics-DfQqRKkD.js";
3
+ //#region packages/core/src/fonts/embedded.ts
4
+ function y(t, n = e) {
5
+ return t.byteLength > 0 && t.byteLength <= n;
6
+ }
7
+ function b(e, t) {
8
+ let n = x(t), r = e.slice(), i = Math.min(32, r.length);
9
+ for (let e = 0; e < i; e++) r[e] ^= n[e % 16];
10
+ return r;
11
+ }
12
+ function x(e) {
13
+ let t = e.replace(/[{}\-\s]/g, "");
14
+ if (t.length !== 32 || /[^0-9a-fA-F]/.test(t)) throw Error(`invalid fontKey GUID: ${e}`);
15
+ let n = new Uint8Array(16);
16
+ for (let e = 0; e < 16; e++) n[e] = parseInt(t.slice(e * 2, e * 2 + 2), 16);
17
+ return n.reverse();
18
+ }
19
+ function ee(e, t, n, r) {
20
+ let i = 2166136261;
21
+ for (let e = 0; e < r.length; e++) i ^= r[e], i = Math.imul(i, 16777619);
22
+ return `${e}|${t}|${n}|${r.length}|${(i >>> 0).toString(16)}`;
23
+ }
24
+ async function S(i, o = e) {
25
+ let s = n();
26
+ if (!s || typeof FontFace > "u") return [];
27
+ let c = [], l = /* @__PURE__ */ new Set(), u = [];
28
+ for (let e of i) try {
29
+ if (!y(e.bytes, o)) {
30
+ u.push(e.family);
31
+ continue;
32
+ }
33
+ let t = e.odttf ? b(e.bytes, e.fontKey ?? "") : e.bytes, n = `embedded:${ee(e.family, e.weight, e.style, t)}`;
34
+ if (l.has(n)) continue;
35
+ l.add(n);
36
+ let { face: r } = a(n, s, () => {
37
+ let n = t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength), r = new FontFace(e.family, n, {
38
+ weight: e.weight,
39
+ style: e.style
40
+ });
41
+ return s.add(r), r;
42
+ });
43
+ c.push(r);
44
+ } catch {
45
+ u.push(e.family);
46
+ }
47
+ let d = c;
48
+ if (c.length > 0) {
49
+ let e = await t(Promise.allSettled(c.map((e) => Promise.resolve().then(() => e.load()))));
50
+ Array.isArray(e) ? (d = [], e.forEach((e, t) => {
51
+ let n = c[t];
52
+ e.status === "fulfilled" ? d.push(n) : (u.push(n.family), r([n]));
53
+ })) : (u.push(...c.map((e) => e.family)), r(c), d = []);
54
+ }
55
+ return u.length > 0 && console.warn(`[ooxml] failed to register embedded font(s): ${[...new Set(u)].join(", ")}; falling back to substitute fonts (text may shift or differ).`), d;
56
+ }
57
+ function C(e) {
58
+ r(e);
59
+ }
60
+ //#endregion
61
+ //#region packages/core/src/layout/virtual-scroll.ts
62
+ function w(e, t, n) {
63
+ return e < t ? t : e > n ? n : e;
64
+ }
65
+ function T(e, t) {
66
+ return Math.min(Math.max(0, t), Math.ceil(Math.max(0, e)));
67
+ }
68
+ function E(e, t, n) {
69
+ let r = e.length;
70
+ if (r === 0) return {
71
+ offsets: [],
72
+ totalHeight: 0
73
+ };
74
+ let i = n?.leading ?? 0, a = n?.trailing ?? 0, o = Array(r), s = 0;
75
+ for (let n = 0; n < r; n++) o[n] = i + s + n * t, s += e[n];
76
+ return {
77
+ offsets: o,
78
+ totalHeight: i + s + (r - 1) * t + a
79
+ };
80
+ }
81
+ function D(e, t, n, r) {
82
+ let i = e.offsets, a = i.length;
83
+ if (a === 0) return {
84
+ start: 0,
85
+ end: -1,
86
+ topIndex: 0,
87
+ offsets: i,
88
+ totalHeight: 0
89
+ };
90
+ let o = 0, s = a;
91
+ for (; o < s;) {
92
+ let e = o + s >>> 1;
93
+ i[e] <= t ? o = e + 1 : s = e;
94
+ }
95
+ let c = w(o - 1, 0, a - 1), l = t + n;
96
+ for (o = 0, s = a; o < s;) {
97
+ let e = o + s >>> 1;
98
+ i[e] < l ? o = e + 1 : s = e;
99
+ }
100
+ let u = w(o - 1, 0, a - 1);
101
+ return {
102
+ start: w(c - r, 0, a - 1),
103
+ end: w(u + r, 0, a - 1),
104
+ topIndex: c,
105
+ offsets: i,
106
+ totalHeight: e.totalHeight
107
+ };
108
+ }
109
+ function O(e, t, n, r, i, a, o) {
110
+ if (e === 0) return {
111
+ start: 0,
112
+ end: -1,
113
+ topIndex: 0,
114
+ totalHeight: 0
115
+ };
116
+ let s = o?.leading ?? 0, c = o?.trailing ?? 0, l = t + n, u = w(r < s ? 0 : l > 0 ? Math.floor((r - s) / l) : e - 1, 0, e - 1), d = r + i, f = w(d <= s ? 0 : l > 0 ? Math.ceil((d - s) / l) - 1 : e - 1, 0, e - 1);
117
+ return {
118
+ start: w(u - a, 0, e - 1),
119
+ end: w(f + a, 0, e - 1),
120
+ topIndex: u,
121
+ totalHeight: s + e * t + (e - 1) * n + c
122
+ };
123
+ }
124
+ //#endregion
125
+ //#region packages/core/src/search/highlight-rect.ts
126
+ function k(e, t, n, r) {
127
+ let i = t <= 0 ? 0 : r(e.slice(0, t)), a = n >= e.length ? r(e) : r(e.slice(0, n));
128
+ return {
129
+ x: i,
130
+ width: Math.max(0, a - i)
131
+ };
132
+ }
133
+ function A(e, t) {
134
+ return t > 0 ? `${e / t * 100}%` : "0%";
135
+ }
136
+ //#endregion
137
+ //#region packages/core/src/internal/selection-data.ts
138
+ function j(e, t, n) {
139
+ e.dataset ? n === void 0 ? delete e.dataset[t] : e.dataset[t] = n : n !== void 0 && e.setAttribute?.(`data-${t.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`)}`, n);
140
+ }
141
+ function M(e) {
142
+ if (e === void 0 || !/^\d+$/.test(e)) return null;
143
+ let t = Number(e);
144
+ return Number.isSafeInteger(t) ? t : null;
145
+ }
146
+ //#endregion
147
+ //#region packages/core/src/viewer/find-controller.ts
148
+ var N = class {
149
+ _count;
150
+ _collectRuns;
151
+ _location;
152
+ _acceptMatch;
153
+ _runs = /* @__PURE__ */ new Map();
154
+ _matches = [];
155
+ _active = -1;
156
+ _generation = 0;
157
+ _runsRevision = 0;
158
+ constructor(e, t, n, r = () => !0) {
159
+ this._count = e, this._collectRuns = t, this._location = n, this._acceptMatch = r;
160
+ }
161
+ invalidate() {
162
+ this._generation++, this._runsRevision++, this._runs.clear(), this._matches = [], this._active = -1;
163
+ }
164
+ unitRuns(e) {
165
+ return this._runs.get(e);
166
+ }
167
+ setUnitRuns(e, t) {
168
+ this._runsRevision++, this._runs.set(e, t);
169
+ }
170
+ unitHighlights(e) {
171
+ let t = [];
172
+ for (let n = 0; n < this._matches.length; n++) {
173
+ let r = this._matches[n];
174
+ r.unit === e && t.push({
175
+ slices: r.slices,
176
+ active: n === this._active
177
+ });
178
+ }
179
+ return t;
180
+ }
181
+ activeUnit() {
182
+ return this._matches[this._active]?.unit ?? null;
183
+ }
184
+ matches() {
185
+ return this._matches.map((e, t) => ({
186
+ matchIndex: t,
187
+ text: e.text,
188
+ location: this._location(e.unit)
189
+ }));
190
+ }
191
+ async find(e, t = {}) {
192
+ let n = ++this._generation;
193
+ if (e.length === 0) return this._runsRevision++, this._runs.clear(), this._matches = [], this._active = -1, [];
194
+ let r = this._runsRevision, i = new Map(this._runs), a = this._count();
195
+ for (let e = 0; e < a; e++) {
196
+ let t = i.get(e);
197
+ if (!t) {
198
+ try {
199
+ t = await this._collectRuns(e);
200
+ } catch (e) {
201
+ if (n !== this._generation) return [];
202
+ throw e;
203
+ }
204
+ if (n !== this._generation) return [];
205
+ i.set(e, t);
206
+ }
207
+ }
208
+ if (n !== this._generation) return [];
209
+ let o = r === this._runsRevision ? i : new Map([...i, ...this._runs]), s = [];
210
+ for (let n = 0; n < a; n++) {
211
+ let r = o.get(n) ?? [];
212
+ for (let i of c(d(r), e, t)) {
213
+ if (!this._acceptMatch(r, i.slices)) continue;
214
+ let e = i.slices.map((e) => r[e.runIndex].text.slice(e.start, e.end)).join("");
215
+ s.push({
216
+ unit: n,
217
+ text: e,
218
+ slices: i.slices
219
+ });
220
+ }
221
+ }
222
+ return this._runsRevision++, this._runs = o, this._matches = s, this._active = -1, this.matches();
223
+ }
224
+ next() {
225
+ return this._active = m(this._active, this._matches.length), this._activePublic();
226
+ }
227
+ prev() {
228
+ return this._active = f(this._active, this._matches.length), this._activePublic();
229
+ }
230
+ _activePublic() {
231
+ let e = this._matches[this._active];
232
+ return e ? {
233
+ matchIndex: this._active,
234
+ text: e.text,
235
+ location: this._location(e.unit)
236
+ } : null;
237
+ }
238
+ }, P = class {
239
+ state = Object.freeze({ status: "complete" });
240
+ get complete() {
241
+ return this.state.status === "complete";
242
+ }
243
+ get settled() {
244
+ return this.state.status !== "pending";
245
+ }
246
+ begin() {
247
+ this.state = Object.freeze({ status: "pending" });
248
+ }
249
+ succeed() {
250
+ this.state = Object.freeze({ status: "complete" });
251
+ }
252
+ fail(e) {
253
+ let t = e instanceof Error ? e : Error(String(e));
254
+ return this.state = Object.freeze({
255
+ status: "failed",
256
+ error: t
257
+ }), t;
258
+ }
259
+ throwIfFailed() {
260
+ if (this.state.status === "failed") throw this.state.error;
261
+ }
262
+ }, F = class {
263
+ failed = /* @__PURE__ */ new WeakMap();
264
+ notify(e, t, ...n) {
265
+ if (!(!t || this.failed.get(t)?.has(e))) try {
266
+ let r = t(...n);
267
+ r && typeof r.then == "function" && Promise.resolve(r).catch((n) => this.reportOnce(e, t, n));
268
+ } catch (n) {
269
+ this.reportOnce(e, t, n);
270
+ }
271
+ }
272
+ reportOnce(e, t, n) {
273
+ let r = this.failed.get(t) ?? /* @__PURE__ */ new Set();
274
+ if (r.has(e)) return;
275
+ r.add(e), this.failed.has(t) || this.failed.set(t, r);
276
+ let i = n instanceof Error ? n : Error(String(n));
277
+ console.error(`[ooxml] ${e} callback failed and was disabled:`, i);
278
+ }
279
+ };
280
+ //#endregion
281
+ //#region packages/core/src/internal/deferred.ts
282
+ function I() {
283
+ let e, t;
284
+ return {
285
+ promise: new Promise((n, r) => {
286
+ e = n, t = r;
287
+ }),
288
+ resolve: e,
289
+ reject: t
290
+ };
291
+ }
292
+ //#endregion
293
+ //#region packages/core/src/internal/comment-context.ts
294
+ var L = 65536;
295
+ function R(e) {
296
+ if (e !== void 0 && (!Number.isFinite(e) || e < 0)) throw RangeError("maxTextCharacters must be a finite non-negative number.");
297
+ return Math.min(L, Math.floor(e ?? 65536));
298
+ }
299
+ function z(e, t, n) {
300
+ let r = R(n), i = 0, a = !1, o = (e) => {
301
+ let t = h(e.text, Math.max(0, r - i));
302
+ return i += t.length, t.length < e.text.length && (a = !0), {
303
+ ...e,
304
+ text: t
305
+ };
306
+ }, s = Object.freeze({
307
+ root: Object.freeze(o(e)),
308
+ replies: Object.freeze(t.map((e) => Object.freeze(o(e))))
309
+ });
310
+ return Object.freeze({
311
+ thread: s,
312
+ truncated: a,
313
+ textCharacters: i,
314
+ maxTextCharacters: r
315
+ });
316
+ }
317
+ //#endregion
318
+ //#region packages/core/src/internal/dom-interaction-boundary.ts
319
+ function B(e, t) {
320
+ return e.dataset?.[t] !== void 0;
321
+ }
322
+ function V(e, t, n) {
323
+ let r = typeof e.composedPath == "function" ? e.composedPath() : [];
324
+ if (r.length > 0) {
325
+ let e = !1;
326
+ for (let i of r) {
327
+ if (i === t) return e;
328
+ B(i, n) && (e = !0);
329
+ }
330
+ }
331
+ let i = e.target;
332
+ if (!i || !t.contains(i)) return !1;
333
+ let a = i;
334
+ for (; a;) {
335
+ if (B(a, n)) return !0;
336
+ if (a === t) break;
337
+ a = a.parentElement;
338
+ }
339
+ return !1;
340
+ }
341
+ //#endregion
342
+ //#region packages/core/src/viewer/scroll-viewer-shell.ts
343
+ var H = class {
344
+ wrapper;
345
+ scrollHost;
346
+ spacer;
347
+ onScroll;
348
+ onPointerDown;
349
+ constructor(e, t) {
350
+ let n = e.ownerDocument ?? document;
351
+ this.wrapper = n.createElement("div"), this.wrapper.style.cssText = "position:relative;width:100%;height:100%;overflow:hidden;", this.scrollHost = n.createElement("div"), this.scrollHost.style.cssText = "position:absolute;inset:0;overflow:auto;", this.scrollHost.style.scrollbarGutter = "stable", t.background && (this.scrollHost.style.background = t.background), this.spacer = n.createElement("div"), this.spacer.style.cssText = "position:absolute;top:0;left:0;width:1px;height:0;pointer-events:none;", this.scrollHost.appendChild(this.spacer), this.wrapper.appendChild(this.scrollHost), e.appendChild(this.wrapper), this.onScroll = t.onScroll, this.scrollHost.addEventListener("scroll", this.onScroll), this.onPointerDown = t.comments ? (e) => {
352
+ V(e, this.wrapper, "ooxmlCommentId") || t.onOutsideComment();
353
+ } : null, this.onPointerDown && n.addEventListener("pointerdown", this.onPointerDown);
354
+ }
355
+ destroy() {
356
+ this.scrollHost.removeEventListener("scroll", this.onScroll), this.onPointerDown && this.wrapper.ownerDocument.removeEventListener("pointerdown", this.onPointerDown), this.wrapper.remove();
357
+ }
358
+ }, U = class {
359
+ hooks;
360
+ measureContext;
361
+ constructor(e) {
362
+ this.hooks = e;
363
+ }
364
+ redrawAll() {
365
+ for (let [e, t] of this.hooks.slots()) this.redrawSlot(e, t);
366
+ }
367
+ redrawSlot(e, t) {
368
+ let n = this.hooks.active() ? this.hooks.runs(e) : void 0;
369
+ if (!n) {
370
+ t.highlightLayer.innerHTML = "";
371
+ return;
372
+ }
373
+ this.hooks.paint(e, t, n, (e) => this.measure(e));
374
+ }
375
+ refreshRuns(e, t) {
376
+ this.hooks.active() && this.hooks.setRuns(e, t);
377
+ }
378
+ async activate(e) {
379
+ return e && this.hooks.reveal(this.hooks.unitOf(e.location)), this.redrawAll(), e;
380
+ }
381
+ measure(e) {
382
+ if (this.measureContext === void 0) {
383
+ let e = document.createElement("canvas");
384
+ this.measureContext = e.getContext("2d");
385
+ }
386
+ let t = this.measureContext;
387
+ return !t || typeof t.measureText != "function" ? (e) => e.length : (t.font = e, (e) => t.measureText(e).width);
388
+ }
389
+ destroy() {
390
+ this.measureContext = void 0;
391
+ }
392
+ }, W = class {
393
+ hooks;
394
+ constructor(e) {
395
+ this.hooks = e;
396
+ }
397
+ async render(e, t, n, r, i, a = this.hooks.nextToken(t), o = t.dispatcher, s = o.begin(), c = !0) {
398
+ let l = this.hooks.inFlight();
399
+ if (l.has(e) || this.hooks.slots().get(e) !== t) return;
400
+ let u = this.hooks.epoch(), d = t.canvas;
401
+ l.add(e);
402
+ let f = !1, p = [], m = this.hooks.wantRuns(t);
403
+ try {
404
+ let c = await this.hooks.render(e, d, n, r, m ? (e) => p.push(e) : void 0);
405
+ if (!this.isCurrent(e, t, a, o, s, d, u)) {
406
+ c.close();
407
+ return;
408
+ }
409
+ if (!this.hooks.commitBitmap(e, t, o, s, c, n)) return;
410
+ t.renderedScale = i, this.hooks.commitRuns(e, t, p, n, m), f = !0;
411
+ } catch (n) {
412
+ if (this.isCurrent(e, t, a, o, s, d, u)) if (c) this.hooks.reportError(n);
413
+ else throw n;
414
+ } finally {
415
+ l.delete(e);
416
+ let n = this.hooks.slots().get(e);
417
+ if (!f && n && this.hooks.canRetry(n) && (n !== t || u !== this.hooks.epoch() || a !== this.hooks.token(n) || !o.isCurrent(s)) && !l.has(e) && !this.hooks.destroyed()) {
418
+ let t = n.dispatcher;
419
+ await this.render(e, n, this.hooks.width(e), this.hooks.dpr(), this.hooks.scale(), this.hooks.nextToken(n), t, t.begin(), c);
420
+ }
421
+ }
422
+ }
423
+ isCurrent(e, t, n, r, i, a, o) {
424
+ return n === this.hooks.token(t) && r.isCurrent(i) && a === t.canvas && o === this.hooks.epoch() && this.hooks.slots().get(e) === t && this.hooks.slotIndex(t) === e;
425
+ }
426
+ }, G = class {
427
+ hooks;
428
+ constructor(e) {
429
+ this.hooks = e;
430
+ }
431
+ render(e, t, n, r, i, a, o, s) {
432
+ let c = this.hooks.epoch(), l = this.hooks.scale(), u = t.canvas, d = [], f = this.hooks.wantRuns(t), p;
433
+ try {
434
+ p = this.hooks.render(e, u, n, r, f ? (e) => d.push(e) : void 0, !1);
435
+ } catch (e) {
436
+ return s ? (this.hooks.reportError(e), Promise.resolve()) : Promise.reject(e);
437
+ }
438
+ return p.then(() => {
439
+ this.isCurrent(e, t, i, a, o, u, c) && (t.renderedScale = l, this.hooks.commitRuns(e, t, d, u, n, f, !1));
440
+ }).catch((n) => {
441
+ if (this.isCurrent(e, t, i, a, o, u, c)) if (s) this.hooks.reportError(n);
442
+ else throw n;
443
+ });
444
+ }
445
+ settle(e, t, n, r) {
446
+ let i = this.hooks.scale(), a = this.hooks.epoch(), o = document.createElement("canvas");
447
+ o.style.cssText = "display:block;background:#fff;";
448
+ let s = this.hooks.shadow();
449
+ s !== !1 && (o.style.boxShadow = s);
450
+ let c = this.hooks.nextToken(t), u = new l(o, !1), d = u.begin(), f = [], p = this.hooks.wantRuns(t), m;
451
+ try {
452
+ m = this.hooks.render(e, o, n, r, p ? (e) => f.push(e) : void 0, !0);
453
+ } catch (n) {
454
+ this.isCurrent(e, t, c, u, d, o, a, !0) && this.hooks.reportError(n), u.destroy();
455
+ return;
456
+ }
457
+ m.then(() => {
458
+ if (!this.isCurrent(e, t, c, u, d, o, a, !0)) {
459
+ u.destroy();
460
+ return;
461
+ }
462
+ let r = t.canvas;
463
+ t.dispatcher.destroy(), t.wrapper.insertBefore(o, r), r.remove(), t.canvas = o, t.dispatcher = u, t.renderedScale = i, this.hooks.commitRuns(e, t, f, o, n, p, !0);
464
+ }).catch((n) => {
465
+ this.isCurrent(e, t, c, u, d, o, a, !0) && this.hooks.reportError(n), u.destroy();
466
+ });
467
+ }
468
+ isCurrent(e, t, n, r, i, a, o, s = !1) {
469
+ return n === this.hooks.token(t) && r.isCurrent(i) && (s || a === t.canvas) && o === this.hooks.epoch() && this.hooks.slots().get(e) === t && this.hooks.slotIndex(t) === e;
470
+ }
471
+ }, K = class {
472
+ hooks;
473
+ slots = /* @__PURE__ */ new Map();
474
+ free = [];
475
+ inFlight = /* @__PURE__ */ new Set();
476
+ lastRange = null;
477
+ renderEpoch = 0;
478
+ _settleTimer = null;
479
+ _destroyed = !1;
480
+ constructor(e) {
481
+ this.hooks = e;
482
+ }
483
+ syncSpacer() {
484
+ let e = this.hooks.range();
485
+ this.lastRange = e, this.hooks.spacer().style.height = `${e.totalHeight}px`, this.hooks.syncSpacerWidth();
486
+ }
487
+ acquireSlot() {
488
+ let e = this.free.pop();
489
+ return e ? (this.hooks.attachSlot(e), e) : this.hooks.createSlot();
490
+ }
491
+ recycleSlot(e, t) {
492
+ this.slots.delete(e), this.hooks.resetSlot(e, t), this.free.push(t);
493
+ }
494
+ mount(e, t = !0) {
495
+ if (this._destroyed || this.hooks.count() === 0) return;
496
+ let n = this.hooks.range();
497
+ this.lastRange = n;
498
+ for (let [e, t] of [...this.slots]) (e < n.start || e > n.end) && this.recycleSlot(e, t);
499
+ for (let r = n.start; r <= n.end; r++) {
500
+ let i = this.slots.get(r);
501
+ if (i) {
502
+ if (!t) continue;
503
+ this.hooks.positionSlot(r, i, n);
504
+ let a = this.hooks.onExistingSlot?.(r, i, e === void 0);
505
+ e && a && e.push(a);
506
+ continue;
507
+ }
508
+ let a = this.acquireSlot();
509
+ this.hooks.positionSlot(r, a, n), this.slots.set(r, a), this.hooks.onNewSlot?.(r, a);
510
+ let o = this.hooks.renderSlot(r, a, e === void 0);
511
+ e && o && (this.hooks.awaitInitialRender?.(r) ?? !0) && e.push(o);
512
+ }
513
+ this.hooks.afterMount?.(n), this.hooks.onRange(n);
514
+ }
515
+ preview() {
516
+ if (this._destroyed || this.hooks.count() === 0) return;
517
+ let e = this.hooks.range();
518
+ this.lastRange = e;
519
+ for (let [t, n] of [...this.slots]) (t < e.start || t > e.end) && this.recycleSlot(t, n);
520
+ for (let t = e.start; t <= e.end; t++) {
521
+ let n = this.slots.get(t);
522
+ if (n) {
523
+ this.hooks.previewSlot(t, n, e);
524
+ continue;
525
+ }
526
+ let r = this.acquireSlot();
527
+ this.hooks.positionSlot(t, r, e), this.slots.set(t, r), this.hooks.onNewSlot?.(t, r), this.hooks.renderSlot(t, r, !0);
528
+ }
529
+ this.hooks.afterMount?.(e), this.hooks.onRange(e);
530
+ }
531
+ scheduleSettle(e) {
532
+ this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = setTimeout(() => {
533
+ this._settleTimer = null, this.settle();
534
+ }, e);
535
+ }
536
+ settle() {
537
+ if (!(this._destroyed || this.hooks.count() === 0)) for (let [e, t] of [...this.slots]) this.hooks.renderedScale(t) !== this.hooks.scale() && (this.hooks.shouldSettle && !this.hooks.shouldSettle(e, t) || this.hooks.settleSlot(e, t));
538
+ }
539
+ destroy() {
540
+ if (!this._destroyed) {
541
+ this._destroyed = !0, this._settleTimer !== null && clearTimeout(this._settleTimer), this._settleTimer = null;
542
+ for (let [e, t] of [...this.slots]) this.recycleSlot(e, t);
543
+ this.inFlight.clear(), this.free.length = 0;
544
+ }
545
+ }
546
+ };
547
+ function q(e) {
548
+ e.style.transform = "", e.style.transformOrigin = "", e.style.width = "100%", e.style.height = "100%";
549
+ }
550
+ function J(e, t, n) {
551
+ let r = e.ownerDocument, i = r.createElement("div");
552
+ i.style.cssText = "position:absolute;";
553
+ let a = r.createElement("canvas");
554
+ a.style.cssText = "display:block;background:#fff;", n !== !1 && (a.style.boxShadow = n), i.appendChild(a);
555
+ let { textLayer: o, highlightLayer: s } = new g(i, t);
556
+ return {
557
+ wrapper: i,
558
+ canvas: a,
559
+ textLayer: o,
560
+ highlightLayer: s
561
+ };
562
+ }
563
+ function Y(e, t, n, r) {
564
+ if (e.canvas.style.width = `${t}px`, e.canvas.style.height = `${n}px`, e.renderedScale <= 0) return null;
565
+ let i = r / e.renderedScale;
566
+ return e.textLayer && (e.textLayer.style.transformOrigin = "0 0", e.textLayer.style.width = `${t / i}px`, e.textLayer.style.height = `${n / i}px`, e.textLayer.style.transform = `scale(${i})`), i;
567
+ }
568
+ function X(e) {
569
+ e.textLayer && (e.textLayer.innerHTML = "", q(e.textLayer)), e.highlightLayer.innerHTML = "", e.highlightLayer.style.transform = "", e.highlightLayer.style.transformOrigin = "";
570
+ }
571
+ function Z(e, t, n, r, i) {
572
+ if (!t) return {
573
+ markerLayer: null,
574
+ margin: null,
575
+ decorationLayer: null
576
+ };
577
+ let a = e.ownerDocument, o = a.createElement("div");
578
+ if (o.setAttribute("data-overlay", "comment-marker"), o.style.cssText = "position:absolute;inset:0;overflow:hidden;pointer-events:none;", e.appendChild(o), !n) return {
579
+ markerLayer: o,
580
+ margin: null,
581
+ decorationLayer: null
582
+ };
583
+ let s = a.createElement("div");
584
+ s.style.cssText = "position:absolute;top:0;height:100%;box-sizing:border-box;overflow-x:hidden;overflow-y:auto;pointer-events:auto;", i(s);
585
+ let c = null;
586
+ return r && (c = a.createElement("div"), c.style.cssText = "position:absolute;top:0;left:0;overflow:visible;pointer-events:none;", e.appendChild(c)), e.appendChild(s), {
587
+ markerLayer: o,
588
+ margin: s,
589
+ decorationLayer: c
590
+ };
591
+ }
592
+ //#endregion
593
+ //#region packages/core/src/viewer/slot-layer-controller.ts
594
+ var Q = class {
595
+ hooks;
596
+ constructor(e) {
597
+ this.hooks = e;
598
+ }
599
+ position(e, t, n, r, i, a, o) {
600
+ if (t.wrapper.style.top = `${n}px`, t.wrapper.style.width = `${r}px`, t.wrapper.style.height = `${i}px`, this.hooks.syncMargin(t.commentMargin), t.commentDecorationLayer) {
601
+ let e = this.hooks.marginExtent();
602
+ t.commentDecorationLayer.style.left = this.hooks.marginSide() === "left" ? `${-e}px` : "0px", t.commentDecorationLayer.style.width = `${r + e}px`, t.commentDecorationLayer.style.height = `${i}px`;
603
+ }
604
+ this.hooks.redrawOutline(e, t);
605
+ let s = Math.max(o, (a - r) / 2);
606
+ t.wrapper.style.left = this.hooks.marginSide() === "left" && this.hooks.commentsEnabled() ? `calc(${s}px + var(--ooxml-review-origin-x, 0px))` : `${s}px`;
607
+ }
608
+ preview(e, t, n, r) {
609
+ let i = Y(e, t, n, r), a = this.hooks.markerLayer(e);
610
+ if (i !== null) {
611
+ e.commentMargin && this.hooks.previewMargin(e.commentMargin, i);
612
+ for (let e of a?.children ?? []) e.dataset.ooxmlCommentMarker !== void 0 && (e.style.transform = `translate(-50%,-50%) scale(${this.hooks.markerRatio(i)})`);
613
+ }
614
+ let o = i === null ? "hidden" : "";
615
+ a && (a.style.visibility = o), e.commentMargin && (e.commentMargin.style.visibility = o), e.commentDecorationLayer && (e.commentDecorationLayer.style.visibility = o);
616
+ }
617
+ reset(e) {
618
+ X(e);
619
+ let t = this.hooks.markerLayer(e);
620
+ t && (t.replaceChildren(), this.hooks.resetMarkerTransform() && (t.style.transform = "", t.style.transformOrigin = ""), t.style.visibility = ""), e.commentMargin && (this.hooks.disposeMargin(e.commentMargin), e.commentMargin.style.visibility = ""), e.commentDecorationLayer && (this.hooks.disposeDecoration(e.commentDecorationLayer), this.hooks.resetDecorationVisibility() && (e.commentDecorationLayer.style.visibility = "")), p(e.elementLayer, null);
621
+ }
622
+ }, $ = class {
623
+ hooks;
624
+ constructor(e) {
625
+ this.hooks = e;
626
+ }
627
+ scrollToUnit(e, t) {
628
+ if (this.hooks.count() === 0 || !this.hooks.established()) return;
629
+ let n = Math.max(0, Math.min(e, this.hooks.count() - 1)), r = this.hooks.host(), i = Math.max(0, this.hooks.totalHeight() - r.clientHeight), a = T(this.hooks.offset(n), i);
630
+ typeof r.scrollTo == "function" ? r.scrollTo({
631
+ top: a,
632
+ behavior: t?.behavior ?? "auto"
633
+ }) : r.scrollTop = a, this.hooks.mount();
634
+ }
635
+ scrollToPoint(e, t, n, r) {
636
+ let i = this.hooks.host(), a = Math.max(this.hooks.padLeft(), (i.clientWidth - this.hooks.width(e)) / 2) + this.hooks.marginOrigin(), o = Math.max(0, this.hooks.totalHeight() - i.clientHeight), s = this.hooks.spacer(), c = s.offsetWidth || Number.parseFloat(s.style.width) || 0, l = Math.max(0, c - i.clientWidth), u = Math.min(o, Math.max(0, this.hooks.offset(e) + n - i.clientHeight / 2)), d = Math.min(l, Math.max(0, a + t - i.clientWidth / 2));
637
+ typeof i.scrollTo == "function" ? i.scrollTo({
638
+ top: u,
639
+ left: d,
640
+ behavior: r?.behavior ?? "auto"
641
+ }) : (i.scrollTop = u, i.scrollLeft = d), this.hooks.mount();
642
+ }
643
+ contentAtViewportY(e) {
644
+ let t = this.hooks.host().scrollTop + e, n = this.hooks.indexAt(t), r = this.hooks.height(n);
645
+ return {
646
+ unit: n,
647
+ frac: r > 0 ? Math.min(1, Math.max(0, (t - this.hooks.offset(n)) / r)) : 0
648
+ };
649
+ }
650
+ viewportYOf(e, t) {
651
+ return this.hooks.offset(e) + t * this.hooks.height(e) - this.hooks.host().scrollTop;
652
+ }
653
+ }, te = "0 1px 3px rgba(0,0,0,0.2)", ne = class {
654
+ hooks;
655
+ constructor(e) {
656
+ this.hooks = e;
657
+ }
658
+ gap() {
659
+ return this.hooks.options().gap ?? 16;
660
+ }
661
+ overscan() {
662
+ return this.hooks.options().overscan ?? 1;
663
+ }
664
+ verticalPadding() {
665
+ let e = this.hooks.options(), t = this.gap();
666
+ return {
667
+ leading: e.paddingTop ?? t,
668
+ trailing: e.paddingBottom ?? t
669
+ };
670
+ }
671
+ horizontalPadding() {
672
+ let e = this.hooks.options(), t = this.gap();
673
+ return {
674
+ left: e.paddingLeft ?? t,
675
+ right: e.paddingRight ?? t
676
+ };
677
+ }
678
+ fitWidth() {
679
+ let e = this.hooks.options().width;
680
+ if (e && e > 0) return e;
681
+ let t = this.hooks.scrollHost().clientWidth || this.hooks.container().clientWidth;
682
+ if (t <= 0) return 0;
683
+ let { left: n, right: r } = this.horizontalPadding();
684
+ return Math.max(0, t - n - r);
685
+ }
686
+ dpr() {
687
+ return this.hooks.options().dpr ?? i();
688
+ }
689
+ }, re = class {
690
+ notify;
691
+ lastIndex = -1;
692
+ lastTotal = -1;
693
+ lastComplete = null;
694
+ constructor(e) {
695
+ this.notify = e;
696
+ }
697
+ publish(e, t, n) {
698
+ e.topIndex === this.lastIndex && t === this.lastTotal && n === this.lastComplete || (this.lastIndex = e.topIndex, this.lastTotal = t, this.lastComplete = n, this.notify(e.topIndex, t, n));
699
+ }
700
+ reset() {
701
+ this.lastIndex = -1, this.lastTotal = -1, this.lastComplete = null;
702
+ }
703
+ resetIndex() {
704
+ this.lastIndex = -1;
705
+ }
706
+ }, ie = class {
707
+ hooks;
708
+ constructor(e) {
709
+ this.hooks = e;
710
+ }
711
+ async load(e) {
712
+ let t = this.hooks.name();
713
+ if (this.hooks.destroyed()) throw Error(`${t} is destroyed`);
714
+ if (this.hooks.borrowed()) throw Error(this.hooks.borrowedMessage());
715
+ let n = this.hooks.beginLoad?.(), r = !1;
716
+ try {
717
+ let i = await this.hooks.owner().replace(() => this.hooks.acquire(e, n), (e) => {
718
+ this.hooks.beforeReplace(e), r = !0;
719
+ });
720
+ if (!i) return;
721
+ if (this.hooks.destroyed()) throw Error(`${t} is destroyed`);
722
+ if (this.hooks.isCurrentLoad && !this.hooks.isCurrentLoad(n) || (this.hooks.afterReplace(i, n), await this.hooks.mountOpeningWindow(), this.hooks.isCurrentLoad && !this.hooks.isCurrentLoad(n))) return;
723
+ } catch (e) {
724
+ if (this.hooks.destroyed()) throw Error(`${t} is destroyed`);
725
+ if (this.hooks.isCurrentLoad && !this.hooks.isCurrentLoad(n)) return;
726
+ throw e instanceof Error ? e : Error(String(e));
727
+ } finally {
728
+ this.hooks.finishLoad?.(n);
729
+ }
730
+ r && !this.hooks.destroyed() && this.hooks.selectionChanged();
731
+ }
732
+ }, ae = class {
733
+ hooks;
734
+ _originPx = 0;
735
+ constructor(e) {
736
+ this.hooks = e;
737
+ }
738
+ enabled() {
739
+ return this.hooks.enabled();
740
+ }
741
+ zoom() {
742
+ return this.hooks.zoom();
743
+ }
744
+ get originPx() {
745
+ return this._originPx;
746
+ }
747
+ hasMargin() {
748
+ return this.hooks.enabled() && this.hooks.cards() && this.hooks.hasDisplayableComments();
749
+ }
750
+ side() {
751
+ let e = this.hooks.requestedSide();
752
+ if (e === "left" || e === "right") return e;
753
+ let t = this.hooks.container();
754
+ return (t.ownerDocument.defaultView?.getComputedStyle?.(t).direction || t.dir || t.style.direction) === "rtl" ? "left" : "right";
755
+ }
756
+ extent() {
757
+ return this.hasMargin() ? (this.hooks.gapPx + this.hooks.widthPx) * this.hooks.zoom() : 0;
758
+ }
759
+ syncMargin(e) {
760
+ if (!e) return;
761
+ e.style.display = this.hasMargin() ? "" : "none";
762
+ let t = this.hooks.zoom(), n = `calc(100% + ${this.hooks.gapPx * t}px)`;
763
+ e.style.left = this.side() === "right" ? n : "", e.style.right = this.side() === "left" ? n : "", e.style.width = `${this.hooks.widthPx * t}px`, e.style.fontSize = `${this.hooks.fontSizePx}px`, e.dataset.ooxmlCommentZoom = String(t);
764
+ }
765
+ syncSpacerWidth(e, t, n) {
766
+ let r = this.extent(), i = this.side() === "left" ? r : 0, a = i - this._originPx, o = this.hooks.scrollHost(), s = Math.max(0, o.scrollLeft + a);
767
+ this.hooks.spacer().style.width = `${e + r + t + n}px`, a !== 0 && (this._originPx = i, o.style["--ooxml-review-origin-x"] = `${i}px`, o.scrollLeft = s);
768
+ }
769
+ destroy() {
770
+ this._originPx = 0;
771
+ }
772
+ }, oe = class {
773
+ hooks;
774
+ scale = 1;
775
+ established = !1;
776
+ pendingScale = null;
777
+ pendingAnchor = null;
778
+ prevBase = 0;
779
+ lastFitWidth = 0;
780
+ _wheelListener = null;
781
+ _resizeObserver = null;
782
+ constructor(e) {
783
+ this.hooks = e;
784
+ }
785
+ bind(e, t, n) {
786
+ n && (this._wheelListener = (e) => {
787
+ if (!(e.ctrlKey || e.metaKey) || (e.preventDefault(), e.deltaY === 0)) return;
788
+ let n = t.getBoundingClientRect(), r = e.clientX - n.left, i = e.clientY - n.top;
789
+ this.pendingAnchor = Number.isFinite(r) && Number.isFinite(i) ? {
790
+ x: r,
791
+ y: i
792
+ } : null, this.setScale(o(this.scale, e.deltaY, e.deltaMode));
793
+ }, t.addEventListener("wheel", this._wheelListener, { passive: !1 })), typeof ResizeObserver < "u" && (this._resizeObserver = new ResizeObserver(() => this.onResize()), this._resizeObserver.observe(e));
794
+ }
795
+ establishBase() {
796
+ let e = this.hooks.baseScale();
797
+ if (e <= 0) return !1;
798
+ if (this.scale = e, this.prevBase = e, this.lastFitWidth = this.hooks.fitWidthPx(), this.established = !0, this.pendingScale !== null) {
799
+ let e = this.pendingScale;
800
+ this.pendingScale = null, e !== this.scale && (this.scale = e, this.hooks.onScaleChange(e));
801
+ }
802
+ return !0;
803
+ }
804
+ setScale(e) {
805
+ let t = Math.min(this.hooks.zoomMax(), Math.max(this.effectiveMin(), e)), n = this.pendingAnchor;
806
+ if (this.pendingAnchor = null, this.hooks.count() === 0 || !this.established) {
807
+ this.pendingScale = t;
808
+ return;
809
+ }
810
+ if (t === this.scale) return;
811
+ let r = this.scale, i = n?.y ?? 0, a = this.hooks.scrollHost(), o = a.scrollTop, c = o + i, l = this.hooks.indexAt(c), u = this.hooks.height(l), d = this.hooks.offset(l), f = Math.min(1, Math.max(0, u > 0 ? (c - d) / u : 0)), p = this.hooks.padLeft(), m = a.scrollLeft || 0;
812
+ this.hooks.invalidateRender(), this.scale = t, this.hooks.recomputeHeights();
813
+ let h = this.hooks.totalHeight();
814
+ this.hooks.spacer().style.height = `${h}px`, this.hooks.syncSpacerWidth();
815
+ let g = Math.max(0, h - a.clientHeight), _ = this.hooks.offset(l) + f * this.hooks.height(l), v = c < d && l === 0 ? o : _ - i;
816
+ if (a.scrollTop = Math.min(g, Math.max(0, v)), n) {
817
+ let e = Math.max(0, (this.hooks.spacer().offsetWidth || 0) - a.clientWidth);
818
+ a.scrollLeft = s(m, n.x - p, r, t, { maxScroll: e });
819
+ }
820
+ this.hooks.preview(), this.hooks.scheduleSettle(), this.hooks.onScaleChange(t);
821
+ }
822
+ getScale() {
823
+ return this.established ? this.scale : this.pendingScale ?? 1;
824
+ }
825
+ zoomIn() {
826
+ this.setScale(u(this.getScale()));
827
+ }
828
+ zoomOut() {
829
+ this.setScale(_(this.getScale(), this.effectiveMin()));
830
+ }
831
+ effectiveMin() {
832
+ let e = this.hooks.zoomMin();
833
+ return this.established && this.prevBase > 0 ? Math.min(e, this.prevBase) : e;
834
+ }
835
+ fit(e) {
836
+ if (this.hooks.count() === 0) return;
837
+ let t = this.hooks.fitContentSize(e);
838
+ if (!t) return;
839
+ let n = v({
840
+ contentWidth: t.width,
841
+ contentHeight: t.height,
842
+ containerWidth: this.hooks.fitWidthPx(),
843
+ containerHeight: this.hooks.scrollHost().clientHeight
844
+ }, e);
845
+ n > 0 && this.setScale(n);
846
+ }
847
+ onResize() {
848
+ if (this.hooks.count() === 0) return;
849
+ if (!this.established) {
850
+ this.hooks.relayout();
851
+ return;
852
+ }
853
+ if (!this.hooks.refitOnResize()) {
854
+ this.lastFitWidth = this.hooks.fitWidthPx(), this.hooks.mountVisible();
855
+ return;
856
+ }
857
+ let e = this.hooks.baseScale();
858
+ if (e <= 0) return;
859
+ let t = this.hooks.fitWidthPx();
860
+ if (t === this.lastFitWidth) {
861
+ this.hooks.mountVisible();
862
+ return;
863
+ }
864
+ this.lastFitWidth = t;
865
+ let n = this.prevBase > 0 ? this.scale / this.prevBase : 1;
866
+ this.prevBase = e, this.setScale(e * n), this.hooks.mountVisible();
867
+ }
868
+ destroy() {
869
+ this.pendingAnchor = null, this._wheelListener &&= (this.hooks.scrollHost().removeEventListener("wheel", this._wheelListener), null), this._resizeObserver?.disconnect(), this._resizeObserver = null;
870
+ }
871
+ }, se = class {
872
+ hooks;
873
+ elementContext = null;
874
+ _generation = 0;
875
+ _contextKey = "null";
876
+ _selectionChangeListener = null;
877
+ _elementClickListener = null;
878
+ _contextMenuListener = null;
879
+ constructor(e) {
880
+ this.hooks = e;
881
+ }
882
+ bind(e, t) {
883
+ let n = this.hooks.wrapper(), r = this.hooks.scrollHost();
884
+ this.hooks.textSelectionEnabled() && (e || this.hooks.elementSelectionEnabled()) && (this._selectionChangeListener = () => this.emitChange(), n.ownerDocument.addEventListener("selectionchange", this._selectionChangeListener)), this.hooks.elementSelectionEnabled() && (this._elementClickListener = (e) => {
885
+ this.onElementClick(e).catch((e) => this.hooks.reportError(e));
886
+ }, r.addEventListener("click", this._elementClickListener)), t && this.hooks.onContextMenu && (this._contextMenuListener = (e) => {
887
+ let t;
888
+ this.hooks.onContextMenu?.(e, () => t ??= this.resolveContextAt(e));
889
+ }, r.addEventListener("contextmenu", this._contextMenuListener));
890
+ }
891
+ emitChange() {
892
+ let e = this.hooks.getContext();
893
+ e?.kind === "text" && (this._generation++, this.elementContext = null, this.redrawOutlines());
894
+ let t = JSON.stringify(e);
895
+ t !== this._contextKey && (this._contextKey = t, this.hooks.onChange(e ? structuredClone(e) : null));
896
+ }
897
+ setElementContext(e) {
898
+ this.elementContext = e ? structuredClone(e) : null, this.redrawOutlines(), this.emitChange();
899
+ }
900
+ invalidateElementContext(e = !0) {
901
+ this._generation++, this.elementContext = null, this.redrawOutlines(), e && this.emitChange();
902
+ }
903
+ clearElementContext() {
904
+ this.elementContext = null;
905
+ }
906
+ redrawOutlines() {
907
+ for (let [e, t] of this.hooks.slots()) this.redrawOutlineForSlot(e, t);
908
+ }
909
+ redrawOutlineForSlot(e, t) {
910
+ let n = this.elementContext, r = this.hooks.resource();
911
+ p(t.elementLayer, n && r ? this.hooks.outline(r, e, n) : null);
912
+ }
913
+ async onElementClick(e) {
914
+ this.hooks.destroyed() || e.defaultPrevented || e.button !== 0 || await this.resolveContextAt(e);
915
+ }
916
+ async resolveContextAt(e) {
917
+ let t = this.hooks.resource();
918
+ if (this.hooks.destroyed() || !t) return null;
919
+ if (this.hooks.textSelectionEnabled() && this.hooks.textSelected()) return this.emitChange(), this.hooks.destroyed() ? null : this.hooks.getContext();
920
+ if (!this.hooks.elementSelectionEnabled()) return this.hooks.getContext();
921
+ let n = e.target, r = [...this.hooks.slots()].find(([, e]) => n !== null && e.wrapper.contains(n));
922
+ if (!r) return this.invalidateElementContext(), null;
923
+ let [i, a] = r, o = a.canvas.getBoundingClientRect();
924
+ if (o.width <= 0 || o.height <= 0) return this.invalidateElementContext(), null;
925
+ let s = e.clientX - o.left, c = e.clientY - o.top;
926
+ if (s < 0 || c < 0 || s > o.width || c > o.height) return this.invalidateElementContext(), null;
927
+ let l = ++this._generation, u;
928
+ try {
929
+ u = await this.hooks.hitTest(t, i, s / o.width, c / o.height, o.width);
930
+ } catch (e) {
931
+ if (this.hooks.destroyed() || l !== this._generation || t !== this.hooks.resource()) return null;
932
+ throw e;
933
+ }
934
+ return this.hooks.destroyed() || l !== this._generation || t !== this.hooks.resource() ? null : (this.setElementContext(u), this.hooks.destroyed() ? null : this.hooks.getContext());
935
+ }
936
+ destroy() {
937
+ this._generation++;
938
+ let e = this.hooks.wrapper(), t = this.hooks.scrollHost();
939
+ this._selectionChangeListener &&= (e.ownerDocument.removeEventListener("selectionchange", this._selectionChangeListener), null), this._elementClickListener &&= (t.removeEventListener("click", this._elementClickListener), null), this._contextMenuListener &&= (t.removeEventListener("contextmenu", this._contextMenuListener), null), this.elementContext = null;
940
+ }
941
+ }, ce = class {
942
+ hooks;
943
+ _scheduled = !1;
944
+ _frame = null;
945
+ _pending = /* @__PURE__ */ new Map();
946
+ constructor(e) {
947
+ this.hooks = e;
948
+ }
949
+ drawConnectors(e, t) {
950
+ let n = t.commentDecorationLayer, r = t.commentMargin, i = t.commentGeometry, a = this.hooks.connectorOptions(), o = this.hooks.runtime();
951
+ if (!n || !r || !i || !a || !o) return;
952
+ let s = this.hooks.width(e), c = this.hooks.height(e), l = this.hooks.side(), u = this.hooks.marginExtent();
953
+ o.buildReadOnlyCommentDecoration(n, Object.freeze({
954
+ surfaceBounds: Object.freeze({
955
+ x: l === "left" ? -u : 0,
956
+ y: 0,
957
+ width: s + u,
958
+ height: c
959
+ }),
960
+ contentBounds: Object.freeze({
961
+ x: 0,
962
+ y: 0,
963
+ width: s,
964
+ height: c
965
+ }),
966
+ side: l,
967
+ threads: o.projectReadOnlyCommentMarginScroll(i, r.scrollTop)
968
+ }), {
969
+ route: a.route ?? "bezier",
970
+ stroke: a.stroke ?? "solid",
971
+ color: a.color,
972
+ activeColor: a.activeColor
973
+ });
974
+ }
975
+ schedule(e, t, n = !1) {
976
+ let r = this._pending.get(e);
977
+ if (this._pending.set(e, {
978
+ slot: t,
979
+ connectorsOnly: r?.slot === t ? r.connectorsOnly && n : n
980
+ }), this._scheduled) return;
981
+ this._scheduled = !0;
982
+ let i = () => {
983
+ this._scheduled = !1, this._frame = null;
984
+ let e = [...this._pending];
985
+ if (this._pending.clear(), !this.hooks.destroyed()) for (let [t, n] of e) this.hooks.slots().get(t) !== n.slot || n.slot.renderedScale !== this.hooks.scale() || (n.connectorsOnly ? this.drawConnectors(t, n.slot) : this.hooks.redrawComments(t, n.slot));
986
+ }, a = this.hooks.ownerWindow();
987
+ a?.requestAnimationFrame ? this._frame = a.requestAnimationFrame(i) : queueMicrotask(i);
988
+ }
989
+ destroy() {
990
+ this._frame !== null && this.hooks.ownerWindow()?.cancelAnimationFrame?.(this._frame), this._frame = null, this._scheduled = !1, this._pending.clear();
991
+ }
992
+ };
993
+ //#endregion
994
+ export { E as A, N as C, k as D, A as E, y as M, S as N, O, C as P, P as S, j as T, U as _, ie as a, I as b, ne as c, K as d, q as f, W as g, G as h, ae as i, b as j, D as k, $ as l, J as m, se as n, re as o, Z as p, oe as r, te as s, ce as t, Q as u, H as v, M as w, F as x, z as y };