@univerjs/slides 0.1.5

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.
@@ -0,0 +1,940 @@
1
+ var De = Object.defineProperty;
2
+ var Ce = (a, e, r) => e in a ? De(a, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : a[e] = r;
3
+ var u = (a, e, r) => (Ce(a, typeof e != "symbol" ? e + "" : e, r), r);
4
+ import { Registry as Re, LocaleService as te, PageElementType as Y, DocumentDataModel as je, getColorStyle as Q, ShapeType as _e, SlideDataModel as Me, IContextService as Ee, ObjectMatrix as ze, Styles as Xe, Worksheet as Ae, sortRules as Le, OnLifecycle as Ue, LifecycleStages as Ne, RxDisposable as Ve, debounce as We, IUniverInstanceService as be, Plugin as $e, PluginType as He } from "@univerjs/core";
5
+ import { Liquid as Ye, DocumentViewModel as Fe, DocumentSkeleton as Be, Documents as Ke, SceneViewer as me, Scene as re, Viewport as L, EVENT_TYPE as ge, ScrollBar as ue, Rect as H, Picture as Ie, PageLayoutType as fe, RichText as ke, Slide as Te, SpreadsheetSkeleton as qe, Spreadsheet as Ge, SpreadsheetRowHeader as Ze, SpreadsheetColumnHeader as Je, getColor as ve, IRenderManagerService as Qe, IRenderingEngine as et } from "@univerjs/engine-render";
6
+ import { Inject as U, Injector as ne } from "@wendellhu/redi";
7
+ import { takeUntil as we } from "rxjs";
8
+ const Yt = {}, tt = {};
9
+ class F {
10
+ constructor() {
11
+ u(this, "zIndex", 0);
12
+ u(this, "viewKey", null);
13
+ }
14
+ check(e) {
15
+ if (e === this.viewKey)
16
+ return this;
17
+ }
18
+ convert(e, r) {
19
+ }
20
+ create(e) {
21
+ }
22
+ }
23
+ const W = Re.create();
24
+ var rt = Object.defineProperty, nt = Object.getOwnPropertyDescriptor, it = (a, e, r, n) => {
25
+ for (var t = n > 1 ? void 0 : n ? nt(e, r) : e, s = a.length - 1, i; s >= 0; s--)
26
+ (i = a[s]) && (t = (n ? i(e, r, t) : i(t)) || t);
27
+ return n && t && rt(e, r, t), t;
28
+ }, st = (a, e) => (r, n) => e(r, n, a);
29
+ let oe = class extends F {
30
+ constructor(e) {
31
+ super();
32
+ u(this, "zIndex", 5);
33
+ u(this, "viewKey", Y.DOCUMENT);
34
+ u(this, "_liquid", new Ye());
35
+ this._localeService = e;
36
+ }
37
+ check(e) {
38
+ if (e === this.viewKey)
39
+ return this;
40
+ }
41
+ convert(e, r) {
42
+ var K, pe;
43
+ const {
44
+ id: n,
45
+ zIndex: t,
46
+ left: s = 0,
47
+ top: i = 0,
48
+ width: c,
49
+ height: o,
50
+ angle: l,
51
+ scaleX: p,
52
+ scaleY: _,
53
+ skewX: d,
54
+ skewY: g,
55
+ flipX: h,
56
+ flipY: f,
57
+ title: y,
58
+ description: D,
59
+ document: T
60
+ } = e;
61
+ if (T == null)
62
+ return;
63
+ const m = new je(T), w = new Fe(m), P = Be.create(w, this._localeService), S = new Ke("__DocsRender__", P);
64
+ P.calculate();
65
+ const x = new me("__DocsViewer__" + n, {
66
+ top: i,
67
+ left: s,
68
+ width: c,
69
+ height: o,
70
+ zIndex: t,
71
+ angle: l,
72
+ scaleX: p,
73
+ scaleY: _,
74
+ skewX: d,
75
+ skewY: g,
76
+ flipX: h,
77
+ flipY: f,
78
+ isTransformer: !0
79
+ }), v = new re("__DocsScene__" + n, x), b = new L("__DocsViewPort_" + n, v, {
80
+ left: 0,
81
+ top: 0,
82
+ bottom: 0,
83
+ right: 0,
84
+ isWheelPreventDefaultX: !0
85
+ });
86
+ v.attachControl(), v.on(ge.wheel, (z, V) => {
87
+ const O = z;
88
+ if (O.ctrlKey) {
89
+ const X = Math.abs(O.deltaX);
90
+ let R = X < 40 ? 0.2 : X < 80 ? 0.4 : 0.2;
91
+ R *= O.deltaY > 0 ? -1 : 1, v.scaleX < 1 && (R /= 2), v.scaleX + R > 4 ? v.scale(4, 4) : v.scaleX + R < 0.1 ? v.scale(0.1, 0.1) : (O.deltaY > 0, O.preventDefault());
92
+ } else
93
+ b.onMouseWheel(O, V);
94
+ }), new ue(b, {
95
+ mainScene: r
96
+ }), v.addObject(S);
97
+ const I = P.getActualSize();
98
+ S.resize(I.actualWidth, I.actualHeight), v.resize(I.actualWidth, I.actualHeight + 200);
99
+ const C = (K = S.getSkeleton()) == null ? void 0 : K.getPageSize();
100
+ S.onPageRenderObservable.add((z) => {
101
+ const { page: V, pageLeft: O, pageTop: X, ctx: R } = z, { width: k, height: q, marginBottom: ie, marginLeft: M, marginRight: G, marginTop: Z } = V;
102
+ R.save(), R.translate(O - 0.5, X - 0.5), H.drawWith(R, {
103
+ width: (C == null ? void 0 : C.width) || k,
104
+ height: (C == null ? void 0 : C.height) || q,
105
+ strokeWidth: 1,
106
+ stroke: "rgba(198,198,198, 1)",
107
+ fill: "rgba(255,255,255, 1)",
108
+ zIndex: 3
109
+ }), R.restore();
110
+ });
111
+ const { left: $, top: N } = S, E = P.getSkeletonData();
112
+ if (E == null)
113
+ return;
114
+ const { pages: j } = E, A = [], B = /* @__PURE__ */ new Map();
115
+ this._recalculateSizeBySkeleton(S, v, P);
116
+ for (let z = 0, V = j.length; z < V; z++) {
117
+ const O = j[z], { skeDrawings: X, marginLeft: R, marginTop: k, pageWidth: q, pageHeight: ie } = O;
118
+ this._liquid.translatePagePadding(O), X.forEach((M) => {
119
+ const { aLeft: G, aTop: Z, height: Oe, width: xe, drawingOrigin: Ut } = M, ye = new Ie(M.objectId, {
120
+ // url: objectTransform.imageProperties?.contentUrl || '',
121
+ left: G + $ + this._liquid.x,
122
+ top: Z + N + this._liquid.y,
123
+ width: xe,
124
+ height: Oe,
125
+ zIndex: 11,
126
+ isTransformer: !0
127
+ });
128
+ B.set(M.objectId, {
129
+ marginLeft: this._liquid.x,
130
+ marginTop: this._liquid.y
131
+ }), A.push(ye);
132
+ }), this._liquid.translatePage(
133
+ O,
134
+ S.pageLayoutType,
135
+ S.pageMarginLeft,
136
+ S.pageMarginTop
137
+ );
138
+ }
139
+ return v.openTransformer(), v.addObjects(A), (pe = v.getTransformer()) == null || pe.onChangingObservable.add((z) => {
140
+ const { objects: V } = z;
141
+ V.forEach((O) => {
142
+ const { oKey: X, left: R, top: k, height: q, width: ie } = O, M = B.get(X), G = (M == null ? void 0 : M.marginLeft) || 0, Z = (M == null ? void 0 : M.marginTop) || 0;
143
+ P == null || P.getViewModel().getDataModel().updateDrawing(X, {
144
+ left: R - $ - G,
145
+ top: k - N - Z,
146
+ height: q,
147
+ width: ie
148
+ });
149
+ }), P == null || P.calculate();
150
+ }), v.closeTransformer(), this._calculatePagePosition(S, v, b), x;
151
+ }
152
+ _recalculateSizeBySkeleton(e, r, n) {
153
+ var c;
154
+ const t = (c = n.getSkeletonData()) == null ? void 0 : c.pages;
155
+ if (t == null)
156
+ return;
157
+ let s = 0, i = 0;
158
+ for (let o = 0, l = t.length; o < l; o++) {
159
+ const p = t[o], { pageWidth: _, pageHeight: d } = p;
160
+ e.pageLayoutType === fe.VERTICAL ? (i += d, i += e.pageMarginTop, o === l - 1 && (i += e.pageMarginTop), s = Math.max(s, _)) : e.pageLayoutType === fe.HORIZONTAL && (s += _, o !== l - 1 && (s += e.pageMarginLeft), i = Math.max(i, d));
161
+ }
162
+ e.resize(s, i), r.resize(s, i);
163
+ }
164
+ _calculatePagePosition(e, r, n, t = 1) {
165
+ const s = r == null ? void 0 : r.getParent(), { width: i, height: c, pageMarginLeft: o, pageMarginTop: l } = e;
166
+ if (s == null || i === Number.POSITIVE_INFINITY || c === Number.POSITIVE_INFINITY)
167
+ return;
168
+ const { width: p, height: _ } = s;
169
+ let d = 0, g = 0, h = 0, f = 0, y = Number.POSITIVE_INFINITY;
170
+ if (p > (i + o * 2) * t ? (d = p / 2 - i * t / 2, d /= t, h = (p - o * 2) / t, y = 0) : (d = o, h = i + o * 2, y = (h - p / t) / 2), _ > c ? (g = _ / 2 - c / 2, f = (_ - l * 2) / t) : (g = l, f = c + l * 2), r.resize(h, f + 200), e.translate(d, g), y !== Number.POSITIVE_INFINITY && n != null) {
171
+ const D = n.getBarScroll(y, 0).x;
172
+ n.scrollTo({
173
+ x: D
174
+ });
175
+ }
176
+ return this;
177
+ }
178
+ };
179
+ oe = it([
180
+ st(0, U(te))
181
+ ], oe);
182
+ class at {
183
+ constructor() {
184
+ u(this, "zIndex", 5);
185
+ }
186
+ create(e) {
187
+ return e.createInstance(oe);
188
+ }
189
+ }
190
+ W.add(new at());
191
+ class ct extends F {
192
+ constructor() {
193
+ super(...arguments);
194
+ u(this, "zIndex", 1);
195
+ u(this, "viewKey", Y.IMAGE);
196
+ }
197
+ check(r) {
198
+ if (r === this.viewKey)
199
+ return this;
200
+ }
201
+ convert(r) {
202
+ const {
203
+ id: n,
204
+ zIndex: t,
205
+ left: s = 0,
206
+ top: i = 0,
207
+ width: c,
208
+ height: o,
209
+ angle: l,
210
+ scaleX: p,
211
+ scaleY: _,
212
+ skewX: d,
213
+ skewY: g,
214
+ flipX: h,
215
+ flipY: f,
216
+ title: y,
217
+ description: D,
218
+ image: T = {}
219
+ } = r, { imageProperties: m, placeholder: w, link: P } = T, S = (m == null ? void 0 : m.contentUrl) || "";
220
+ return new Ie(n, {
221
+ url: S,
222
+ top: i,
223
+ left: s,
224
+ width: c,
225
+ height: o,
226
+ zIndex: t,
227
+ angle: l,
228
+ scaleX: p,
229
+ scaleY: _,
230
+ skewX: d,
231
+ skewY: g,
232
+ flipX: h,
233
+ flipY: f,
234
+ isTransformer: !0,
235
+ forceRender: !0
236
+ });
237
+ }
238
+ }
239
+ class ot {
240
+ constructor() {
241
+ u(this, "zIndex", 4);
242
+ }
243
+ create(e) {
244
+ return e.createInstance(ct);
245
+ }
246
+ }
247
+ W.add(new ot());
248
+ var lt = Object.defineProperty, dt = Object.getOwnPropertyDescriptor, ht = (a, e, r, n) => {
249
+ for (var t = n > 1 ? void 0 : n ? dt(e, r) : e, s = a.length - 1, i; s >= 0; s--)
250
+ (i = a[s]) && (t = (n ? i(e, r, t) : i(t)) || t);
251
+ return n && t && lt(e, r, t), t;
252
+ }, gt = (a, e) => (r, n) => e(r, n, a);
253
+ let le = class extends F {
254
+ constructor(e) {
255
+ super();
256
+ u(this, "zIndex", 2);
257
+ u(this, "viewKey", Y.TEXT);
258
+ this._localeService = e;
259
+ }
260
+ check(e) {
261
+ if (e === this.viewKey)
262
+ return this;
263
+ }
264
+ convert(e, r) {
265
+ const {
266
+ id: n,
267
+ zIndex: t,
268
+ left: s = 0,
269
+ top: i = 0,
270
+ width: c,
271
+ height: o,
272
+ angle: l,
273
+ scaleX: p,
274
+ scaleY: _,
275
+ skewX: d,
276
+ skewY: g,
277
+ flipX: h,
278
+ flipY: f,
279
+ title: y,
280
+ description: D,
281
+ richText: T = {}
282
+ } = e, { text: m, ff: w, fs: P, it: S, bl: x, ul: v, st: b, ol: I, bg: C, bd: $, cl: N, rich: E } = T;
283
+ let j = {
284
+ top: i,
285
+ left: s,
286
+ width: c,
287
+ height: o,
288
+ zIndex: t,
289
+ angle: l,
290
+ scaleX: p,
291
+ scaleY: _,
292
+ skewX: d,
293
+ skewY: g,
294
+ flipX: h,
295
+ flipY: f,
296
+ isTransformer: !0,
297
+ forceRender: !0
298
+ }, A = !1;
299
+ if (m != null ? (j = { ...j, text: m, ff: w, fs: P, it: S, bl: x, ul: v, st: b, ol: I, bg: C, bd: $, cl: N }, A = !0) : E != null && (j = { ...j, richText: E }, A = !0), A !== !1)
300
+ return new ke(this._localeService, n, j);
301
+ }
302
+ };
303
+ le = ht([
304
+ gt(0, U(te))
305
+ ], le);
306
+ class ut {
307
+ constructor() {
308
+ u(this, "zIndex", 0);
309
+ }
310
+ create(e) {
311
+ return e.createInstance(le);
312
+ }
313
+ }
314
+ W.add(new ut());
315
+ class pt extends F {
316
+ constructor() {
317
+ super(...arguments);
318
+ u(this, "zIndex", 2);
319
+ u(this, "viewKey", Y.SHAPE);
320
+ }
321
+ check(r) {
322
+ if (r === this.viewKey)
323
+ return this;
324
+ }
325
+ convert(r) {
326
+ const {
327
+ id: n,
328
+ zIndex: t,
329
+ left: s = 0,
330
+ top: i = 0,
331
+ width: c,
332
+ height: o,
333
+ angle: l,
334
+ scaleX: p,
335
+ scaleY: _,
336
+ skewX: d,
337
+ skewY: g,
338
+ flipX: h,
339
+ flipY: f,
340
+ title: y,
341
+ description: D
342
+ } = r, { shapeType: T, text: m, shapeProperties: w, placeholder: P, link: S } = r.shape || {}, x = w == null ? "" : Q(w.shapeBackgroundFill) || "rgba(255,255,255,1)", v = w == null ? void 0 : w.outline, b = {};
343
+ if (v) {
344
+ const { outlineFill: I, weight: C } = v;
345
+ b.strokeWidth = C, b.stroke = Q(I) || "rgba(0,0,0,1)";
346
+ }
347
+ if (T === _e.RECTANGLE)
348
+ return new H(n, {
349
+ fill: x,
350
+ top: i,
351
+ left: s,
352
+ width: c,
353
+ height: o,
354
+ zIndex: t,
355
+ angle: l,
356
+ scaleX: p,
357
+ scaleY: _,
358
+ skewX: d,
359
+ skewY: g,
360
+ flipX: h,
361
+ flipY: f,
362
+ isTransformer: !0,
363
+ forceRender: !0,
364
+ ...b
365
+ });
366
+ if (T === _e.ROUND_RECTANGLE) {
367
+ const I = (w == null ? void 0 : w.radius) || 0;
368
+ return new H(n, {
369
+ fill: x,
370
+ top: i,
371
+ left: s,
372
+ width: c,
373
+ height: o,
374
+ zIndex: t,
375
+ angle: l,
376
+ scaleX: p,
377
+ scaleY: _,
378
+ skewX: d,
379
+ skewY: g,
380
+ flipX: h,
381
+ flipY: f,
382
+ isTransformer: !0,
383
+ forceRender: !0,
384
+ radius: I,
385
+ ...b
386
+ });
387
+ }
388
+ }
389
+ }
390
+ class _t {
391
+ constructor() {
392
+ u(this, "zIndex", 2);
393
+ }
394
+ create(e) {
395
+ return e.createInstance(pt);
396
+ }
397
+ }
398
+ W.add(new _t());
399
+ var ft = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, wt = (a, e, r, n) => {
400
+ for (var t = n > 1 ? void 0 : n ? vt(e, r) : e, s = a.length - 1, i; s >= 0; s--)
401
+ (i = a[s]) && (t = (n ? i(e, r, t) : i(t)) || t);
402
+ return n && t && ft(e, r, t), t;
403
+ }, St = (a, e) => (r, n) => e(r, n, a);
404
+ let de = class extends F {
405
+ constructor(e) {
406
+ super();
407
+ u(this, "zIndex", 6);
408
+ u(this, "viewKey", Y.SLIDE);
409
+ u(this, "_ObjectProvider", null);
410
+ this._injector = e;
411
+ }
412
+ check(e) {
413
+ if (e === this.viewKey)
414
+ return this;
415
+ }
416
+ convert(e, r) {
417
+ const {
418
+ id: n,
419
+ zIndex: t,
420
+ left: s = 0,
421
+ top: i = 0,
422
+ width: c,
423
+ height: o,
424
+ angle: l,
425
+ scaleX: p,
426
+ scaleY: _,
427
+ skewX: d,
428
+ skewY: g,
429
+ flipX: h,
430
+ flipY: f,
431
+ title: y,
432
+ description: D,
433
+ slide: T
434
+ } = e;
435
+ if (T == null)
436
+ return;
437
+ const m = new Me(T), w = new Te("__SLIDERender__" + n, {
438
+ top: i,
439
+ left: s,
440
+ width: c,
441
+ height: o,
442
+ zIndex: t,
443
+ angle: l,
444
+ scaleX: p,
445
+ scaleY: _,
446
+ skewX: d,
447
+ skewY: g,
448
+ flipX: h,
449
+ flipY: f,
450
+ isTransformer: !1,
451
+ forceRender: !0
452
+ });
453
+ w.enableNav(), w.enableSelectedClipElement();
454
+ const P = m.getPageOrder(), S = m.getPages();
455
+ if (!P || !S)
456
+ return w;
457
+ this._ObjectProvider = new ee(this._injector);
458
+ for (let x = 0, v = P.length; x < v; x++) {
459
+ const b = S[P[x]], { id: I } = b;
460
+ w.addPage(this._createScene(I, w, b, r, m));
461
+ }
462
+ return w.activeFirstPage(), w;
463
+ }
464
+ _createScene(e, r, n, t, s) {
465
+ var g;
466
+ const { width: i, height: c } = r, o = new re(e, r, {
467
+ width: i,
468
+ height: c
469
+ });
470
+ new L(`PageViewer_${e}`, o, {
471
+ left: 0,
472
+ top: 0,
473
+ bottom: 0,
474
+ right: 0
475
+ }).closeClip();
476
+ const { pageElements: p, pageBackgroundFill: _ } = n, d = (g = this._ObjectProvider) == null ? void 0 : g.convertToRenderObjects(p, t);
477
+ return o.openTransformer(), this._addBackgroundRect(o, _, s), o.addObjects(d), o;
478
+ }
479
+ _addBackgroundRect(e, r, n) {
480
+ const t = n.getPageSize(), { width: s = 0, height: i = 0 } = t, c = new H("canvas", {
481
+ left: 0,
482
+ top: 0,
483
+ width: s,
484
+ height: i,
485
+ strokeWidth: 1,
486
+ stroke: "rgba(198,198,198, 1)",
487
+ fill: Q(r) || "rgba(255,255,255, 1)",
488
+ zIndex: 0,
489
+ evented: !1
490
+ });
491
+ e.addObject(c, 0);
492
+ }
493
+ };
494
+ de = wt([
495
+ St(0, U(ne))
496
+ ], de);
497
+ class Pt {
498
+ constructor() {
499
+ u(this, "zIndex", 6);
500
+ }
501
+ create(e) {
502
+ return e.createInstance(de);
503
+ }
504
+ }
505
+ W.add(new Pt());
506
+ var bt = Object.defineProperty, mt = Object.getOwnPropertyDescriptor, It = (a, e, r, n) => {
507
+ for (var t = n > 1 ? void 0 : n ? mt(e, r) : e, s = a.length - 1, i; s >= 0; s--)
508
+ (i = a[s]) && (t = (n ? i(e, r, t) : i(t)) || t);
509
+ return n && t && bt(e, r, t), t;
510
+ }, Se = (a, e) => (r, n) => e(r, n, a);
511
+ let he = class extends F {
512
+ constructor(e, r) {
513
+ super();
514
+ u(this, "zIndex", 4);
515
+ u(this, "viewKey", Y.SPREADSHEET);
516
+ this._localeService = e, this._contextService = r;
517
+ }
518
+ check(e) {
519
+ if (e === this.viewKey)
520
+ return this;
521
+ }
522
+ convert(e, r) {
523
+ const {
524
+ id: n,
525
+ zIndex: t,
526
+ left: s = 0,
527
+ top: i = 0,
528
+ width: c,
529
+ height: o,
530
+ angle: l,
531
+ scaleX: p,
532
+ scaleY: _,
533
+ skewX: d,
534
+ skewY: g,
535
+ flipX: h,
536
+ flipY: f,
537
+ spreadsheet: y
538
+ } = e;
539
+ if (y == null)
540
+ return;
541
+ const { worksheet: D, styles: T } = y, { cellData: m } = D, w = new ze(m), P = new Xe(T), S = new qe(
542
+ new Ae(D, P),
543
+ // FIXME: worksheet in slide doesn't has a Worksheet object
544
+ D,
545
+ w,
546
+ P,
547
+ this._localeService,
548
+ this._contextService
549
+ ), { rowTotalHeight: x, columnTotalWidth: v, rowHeaderWidth: b, columnHeaderHeight: I } = S, C = v + D.rowHeader.width || 0, $ = x + D.columnHeader.height || 0, N = new me("spreadInSlideSceneViewer" + n, {
550
+ top: i,
551
+ left: s,
552
+ width: c,
553
+ height: o,
554
+ zIndex: t,
555
+ angle: l,
556
+ scaleX: p,
557
+ scaleY: _,
558
+ skewX: d,
559
+ skewY: g,
560
+ flipX: h,
561
+ flipY: f,
562
+ isTransformer: !0,
563
+ forceRender: !0
564
+ }), E = new re("spreadInSlideScene" + n, N, {
565
+ width: C,
566
+ height: $
567
+ });
568
+ this._updateViewport(n, b, I, E, r);
569
+ const j = new Ge("testSheetViewer", S, !1), A = new Ze("spreadInSlideRow", S), B = new Je("spreadInSlideColumn", S), K = new H("spreadInSlideLeftTop", {
570
+ zIndex: 2,
571
+ left: -1,
572
+ top: -1,
573
+ width: b,
574
+ height: I,
575
+ fill: ve([248, 249, 250]),
576
+ stroke: ve([217, 217, 217]),
577
+ strokeWidth: 1
578
+ });
579
+ return j.zIndex = 10, E.addObjects([j], 1), E.addObjects([A, B, K], 2), N;
580
+ }
581
+ _updateViewport(e, r, n, t, s) {
582
+ if (s == null)
583
+ return;
584
+ const i = r * t.scaleX, c = n * t.scaleY, o = new L("spreadInSlideViewMain" + e, t, {
585
+ left: i,
586
+ top: c,
587
+ bottom: 0,
588
+ right: 0,
589
+ isWheelPreventDefaultX: !0
590
+ }), l = new L("spreadInSlideViewTop" + e, t, {
591
+ left: i,
592
+ height: c,
593
+ top: 0,
594
+ right: 0,
595
+ isWheelPreventDefaultX: !0
596
+ }), p = new L("spreadInSlideViewLeft" + e, t, {
597
+ left: 0,
598
+ bottom: 0,
599
+ top: c,
600
+ width: i,
601
+ isWheelPreventDefaultX: !0
602
+ });
603
+ new L("spreadInSlideViewLeftTop" + e, t, {
604
+ left: 0,
605
+ top: 0,
606
+ width: i,
607
+ height: c,
608
+ isWheelPreventDefaultX: !0
609
+ }), o.onScrollAfterObserver.add((_) => {
610
+ const { scrollX: d, scrollY: g, actualScrollX: h, actualScrollY: f } = _;
611
+ l.updateScroll({
612
+ scrollX: d,
613
+ actualScrollX: h
614
+ }), p.updateScroll({
615
+ scrollY: g,
616
+ actualScrollY: f
617
+ });
618
+ }), t.attachControl(), new ue(o, {
619
+ mainScene: s
620
+ }), t.on(ge.wheel, (_, d) => {
621
+ const g = _;
622
+ if (g.ctrlKey) {
623
+ const h = Math.abs(g.deltaX);
624
+ let f = h < 40 ? 0.05 : h < 80 ? 0.02 : 0.01;
625
+ f *= g.deltaY > 0 ? -1 : 1, t.scaleX < 1 && (f /= 2), t.scaleX + f > 4 ? t.scale(4, 4) : t.scaleX + f < 0.1 ? t.scale(0.1, 0.1) : (t.scaleBy(f, f), g.preventDefault());
626
+ } else
627
+ o.onMouseWheel(g, d);
628
+ });
629
+ }
630
+ };
631
+ he = It([
632
+ Se(0, U(te)),
633
+ Se(1, Ee)
634
+ ], he);
635
+ class Tt {
636
+ constructor() {
637
+ u(this, "zIndex", 4);
638
+ }
639
+ create(e) {
640
+ return e.createInstance(he);
641
+ }
642
+ }
643
+ W.add(new Tt());
644
+ var Ot = Object.defineProperty, xt = Object.getOwnPropertyDescriptor, yt = (a, e, r, n) => {
645
+ for (var t = n > 1 ? void 0 : n ? xt(e, r) : e, s = a.length - 1, i; s >= 0; s--)
646
+ (i = a[s]) && (t = (n ? i(e, r, t) : i(t)) || t);
647
+ return n && t && Ot(e, r, t), t;
648
+ }, Dt = (a, e) => (r, n) => e(r, n, a);
649
+ let ee = class {
650
+ constructor(a) {
651
+ u(this, "_adaptors", []);
652
+ this._injector = a, this._adaptorLoader();
653
+ }
654
+ convertToRenderObjects(a, e) {
655
+ const r = Object.keys(a), n = [];
656
+ return r.forEach((t) => {
657
+ const s = a[t], i = this._executor(s, e);
658
+ i != null && n.push(i);
659
+ }), n;
660
+ }
661
+ _executor(a, e) {
662
+ var t;
663
+ const { id: r, type: n } = a;
664
+ for (const s of this._adaptors) {
665
+ const i = (t = s.check(n)) == null ? void 0 : t.convert(a, e);
666
+ if (i != null)
667
+ return i;
668
+ }
669
+ }
670
+ _adaptorLoader() {
671
+ W.getData().sort(Le).forEach((a) => {
672
+ this._adaptors.push(a.create(this._injector));
673
+ });
674
+ }
675
+ };
676
+ ee = yt([
677
+ Dt(0, U(ne))
678
+ ], ee);
679
+ var Ct = Object.defineProperty, Rt = Object.getOwnPropertyDescriptor, jt = (a, e, r, n) => {
680
+ for (var t = n > 1 ? void 0 : n ? Rt(e, r) : e, s = a.length - 1, i; s >= 0; s--)
681
+ (i = a[s]) && (t = (n ? i(e, r, t) : i(t)) || t);
682
+ return n && t && Ct(e, r, t), t;
683
+ }, se = (a, e) => (r, n) => e(r, n, a), Mt = /* @__PURE__ */ ((a) => (a.COMPONENT = "__slideRender__", a.SCENE = "__mainScene__", a.VIEW = "__mainView__", a))(Mt || {});
684
+ let J = class extends Ve {
685
+ constructor(e, r, n) {
686
+ super();
687
+ u(this, "_objectProvider", null);
688
+ u(this, "_activePageId", "");
689
+ u(this, "_refreshThumb", We(() => {
690
+ this.createThumbs();
691
+ }, 300));
692
+ this._currentUniverService = e, this._injector = r, this._renderManagerService = n, this._initializeDependencies(this._injector), this._initialize();
693
+ }
694
+ _initialize() {
695
+ this._renderManagerService.createRender$.pipe(we(this.dispose$)).subscribe((e) => {
696
+ this._create(e);
697
+ }), this._currentUniverService.currentSlide$.pipe(we(this.dispose$)).subscribe((e) => {
698
+ this._create(e == null ? void 0 : e.getUnitId());
699
+ }), this._currentUniverService.getAllUniverSlidesInstance().forEach((e) => {
700
+ this._create(e.getUnitId());
701
+ });
702
+ }
703
+ activePage(e) {
704
+ const r = this._currentUniverService.getCurrentUniverSlideInstance();
705
+ let n;
706
+ if (e)
707
+ n = r.getPage(e);
708
+ else {
709
+ const c = r.getPages(), o = r.getPageOrder();
710
+ if (o == null || c == null)
711
+ return;
712
+ n = c[o[0]], e = n.id;
713
+ }
714
+ const t = this._currentRender();
715
+ if (n == null || t == null || t.mainComponent == null)
716
+ return;
717
+ const { id: s } = n, i = t.mainComponent;
718
+ if (this._activePageId = e, i != null && i.hasPage(s)) {
719
+ i.changePage(s);
720
+ return;
721
+ }
722
+ this._createScene(s, n);
723
+ }
724
+ _scrollToCenter() {
725
+ var o;
726
+ const e = (o = this._currentRender()) == null ? void 0 : o.scene, r = e == null ? void 0 : e.getViewport("__mainView__"), n = this._getCenterPositionViewPort(e);
727
+ if (!r || !n)
728
+ return;
729
+ const { left: t, top: s } = n, { x: i, y: c } = r.getBarScroll(t, s);
730
+ r.scrollTo({
731
+ x: i,
732
+ y: c
733
+ });
734
+ }
735
+ _create(e) {
736
+ e == null || this._currentUniverService.getUniverSlideInstance(e) == null || this._renderManagerService.has(e) || this._addNewRender(e);
737
+ }
738
+ _currentRender() {
739
+ const e = this._currentUniverService.getCurrentUniverSlideInstance();
740
+ return this._renderManagerService.getRenderById(e.getUnitId());
741
+ }
742
+ _addNewRender(e) {
743
+ const r = this._currentUniverService.getUniverSlideInstance(e);
744
+ if (r == null)
745
+ return;
746
+ const n = r.getContainer(), t = r.getParentRenderUnitId();
747
+ if (n != null && t != null)
748
+ throw new Error("container or parentRenderUnitId can only exist one");
749
+ n == null && t != null ? this._renderManagerService.createRenderWithParent(e, t) : this._renderManagerService.createRender(e);
750
+ const s = this._renderManagerService.getRenderById(e);
751
+ if (s == null)
752
+ return;
753
+ const { scene: i, engine: c } = s;
754
+ c.onTransformChangeObservable.addOnce(() => {
755
+ this._scrollToCenter();
756
+ }), c.onTransformChangeObservable.add(() => {
757
+ setTimeout(() => {
758
+ this.createThumbs();
759
+ }, 300);
760
+ }), i.resize(2400, 1800);
761
+ const o = new L("__mainView__", i, {
762
+ left: 0,
763
+ top: 0,
764
+ bottom: 0,
765
+ right: 0,
766
+ isWheelPreventDefaultX: !0
767
+ });
768
+ i.attachControl(), i.on(ge.wheel, (p, _) => {
769
+ const d = p;
770
+ if (d.ctrlKey) {
771
+ const g = Math.abs(d.deltaX);
772
+ let h = g < 40 ? 0.2 : g < 80 ? 0.4 : 0.2;
773
+ h *= d.deltaY > 0 ? -1 : 1, i.scaleX < 1 && (h /= 2), i.scaleX + h > 4 ? i.scale(4, 4) : i.scaleX + h < 0.1 ? i.scale(0.1, 0.1) : (d.deltaY > 0, d.preventDefault());
774
+ } else
775
+ o.onMouseWheel(d, _);
776
+ }), i.onFileLoadedObservable.add(() => {
777
+ this._refreshThumb();
778
+ }), ue.attachTo(o), this._renderManagerService.setCurrent(e);
779
+ const l = this._createSlide(i);
780
+ s.mainComponent = l, s.components.set("__slideRender__", l), this._createSlidePages(r, l), c.runRenderLoop(() => {
781
+ i.render();
782
+ const p = document.getElementById("app");
783
+ p && (p.innerText = `fps:${Math.round(c.getFps()).toString()}`);
784
+ });
785
+ }
786
+ _createSlide(e) {
787
+ const r = this._currentUniverService.getCurrentUniverSlideInstance(), { width: n, height: t } = e, s = r.getPageSize(), { width: i = 100, height: c = 100 } = s, o = new Te("__slideRender__", {
788
+ left: (n - i) / 2,
789
+ top: (t - c) / 2,
790
+ width: i,
791
+ height: c,
792
+ zIndex: 10
793
+ });
794
+ return o.enableNav(), o.enableSelectedClipElement(), e.addObject(o), o;
795
+ }
796
+ _addBackgroundRect(e, r) {
797
+ const t = this._currentUniverService.getCurrentUniverSlideInstance().getPageSize(), { width: s = 0, height: i = 0 } = t, c = new H("canvas", {
798
+ left: 0,
799
+ top: 0,
800
+ width: s,
801
+ height: i,
802
+ strokeWidth: 1,
803
+ stroke: "rgba(198,198,198, 1)",
804
+ fill: Q(r) || "rgba(255,255,255, 1)",
805
+ zIndex: 0,
806
+ evented: !1
807
+ });
808
+ e.addObject(c, 0);
809
+ }
810
+ _getCenterPositionViewPort(e) {
811
+ if (!e)
812
+ return { left: 0, top: 0 };
813
+ const { width: r, height: n } = e, t = e.getEngine(), s = (t == null ? void 0 : t.width) || 0, i = (t == null ? void 0 : t.height) || 0;
814
+ return {
815
+ left: (r - s) / 2,
816
+ top: (n - i) / 2
817
+ };
818
+ }
819
+ _thumbSceneRender(e, r) {
820
+ const n = this._renderManagerService.getRenderById(e);
821
+ if (n == null)
822
+ return;
823
+ const { engine: t } = n;
824
+ if (t == null)
825
+ return;
826
+ const { width: s, height: i } = r, { width: c = s, height: o = i } = t, l = t.getCanvas().getContext();
827
+ r.renderToThumb(l, e, c / s, o / i);
828
+ }
829
+ _createSlidePages(e, r) {
830
+ const n = e.getPages(), t = e.getPageOrder();
831
+ if (!(!n || !t) && t.length !== 0) {
832
+ for (let s = 0, i = t.length; s < i; s++) {
833
+ const c = t[s];
834
+ this._createScene(c, n[c]), this._createThumb(c);
835
+ }
836
+ this._activePageId = t[0], r.activeFirstPage();
837
+ }
838
+ }
839
+ createThumbs() {
840
+ const r = this._currentUniverService.getCurrentUniverSlideInstance().getPageOrder(), n = this._currentRender();
841
+ if (!(!r || !n) && r.length !== 0)
842
+ for (let t = 0, s = r.length; t < s; t++) {
843
+ const i = r[t];
844
+ this._thumbSceneRender(i, n.mainComponent);
845
+ }
846
+ }
847
+ _createThumb(e) {
848
+ this._renderManagerService.createRender(e);
849
+ }
850
+ _createScene(e, r) {
851
+ const n = this._currentRender();
852
+ if (!n || !this._objectProvider)
853
+ return;
854
+ const { scene: t, mainComponent: s } = n, i = s, { width: c, height: o } = i, l = new re(e, i, {
855
+ width: c,
856
+ height: o
857
+ });
858
+ new L(`PageViewer_${e}`, l, {
859
+ left: 0,
860
+ top: 0,
861
+ bottom: 0,
862
+ right: 0
863
+ }).closeClip();
864
+ const { pageElements: _, pageBackgroundFill: d } = r, g = this._objectProvider.convertToRenderObjects(_, t);
865
+ if (!g || !i)
866
+ return;
867
+ l.openTransformer(), this._addBackgroundRect(l, d), l.addObjects(g);
868
+ const h = l.getTransformer();
869
+ return h == null || h.onChangeEndObservable.add(() => {
870
+ this._thumbSceneRender(this._activePageId, i);
871
+ }), h == null || h.onClearControlObservable.add(() => {
872
+ this._thumbSceneRender(this._activePageId, i);
873
+ }), i.addPage(l), l;
874
+ }
875
+ _initializeDependencies(e) {
876
+ this._objectProvider = e.createInstance(ee);
877
+ }
878
+ };
879
+ J = jt([
880
+ Ue(Ne.Ready, J),
881
+ se(0, be),
882
+ se(1, U(ne)),
883
+ se(2, Qe)
884
+ ], J);
885
+ var Et = Object.defineProperty, zt = Object.getOwnPropertyDescriptor, Xt = (a, e, r, n) => {
886
+ for (var t = n > 1 ? void 0 : n ? zt(e, r) : e, s = a.length - 1, i; s >= 0; s--)
887
+ (i = a[s]) && (t = (n ? i(e, r, t) : i(t)) || t);
888
+ return n && t && Et(e, r, t), t;
889
+ }, ae = (a, e) => (r, n) => e(r, n, a);
890
+ const At = {}, Lt = "slides";
891
+ var ce;
892
+ let Pe = (ce = class extends $e {
893
+ constructor(e = {}, r, n, t) {
894
+ super(Lt);
895
+ u(this, "_config");
896
+ u(this, "_canvasEngine", null);
897
+ u(this, "_canvasView", null);
898
+ this._currentUniverService = r, this._localeService = n, this._injector = t, this._config = Object.assign(At, e), this._initializeDependencies(this._injector);
899
+ }
900
+ initialize() {
901
+ this._localeService.load({
902
+ zhCN: tt
903
+ }), this.initCanvasEngine();
904
+ }
905
+ getConfig() {
906
+ return this._config;
907
+ }
908
+ initCanvasEngine() {
909
+ this._canvasEngine = this._injector.get(et);
910
+ }
911
+ onRendered() {
912
+ this.initialize();
913
+ }
914
+ onDestroy() {
915
+ super.onDestroy();
916
+ }
917
+ getCanvasEngine() {
918
+ return this._canvasEngine;
919
+ }
920
+ getCanvasView() {
921
+ return this._canvasView;
922
+ }
923
+ _initializeDependencies(e) {
924
+ [[J]].forEach((n) => {
925
+ e.add(n);
926
+ });
927
+ }
928
+ }, u(ce, "type", He.Slide), ce);
929
+ Pe = Xt([
930
+ ae(1, be),
931
+ ae(2, U(te)),
932
+ ae(3, U(ne))
933
+ ], Pe);
934
+ export {
935
+ J as CanvasView,
936
+ Mt as SLIDE_KEY,
937
+ Pe as UniverSlidesPlugin,
938
+ Yt as enUS,
939
+ tt as zhCN
940
+ };