@netless/app-presentation 0.1.9-beta.5 → 0.1.9-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -37,7 +37,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  // file that has been converted to a CommonJS file using a Babel-
38
38
  // compatible transform (i.e. "__esModule" has not been set), then set
39
39
  // "default" to the CommonJS "module.exports" for node compatibility.
40
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
+ !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
41
41
  mod
42
42
  ));
43
43
 
@@ -1023,9 +1023,9 @@ var require_lodash = __commonJS({
1023
1023
  return getMapData(this, key).has(key);
1024
1024
  }
1025
1025
  function mapCacheSet(key, value) {
1026
- var data = getMapData(this, key), size2 = data.size;
1026
+ var data = getMapData(this, key), size3 = data.size;
1027
1027
  data.set(key, value);
1028
- this.size += data.size == size2 ? 0 : 1;
1028
+ this.size += data.size == size3 ? 0 : 1;
1029
1029
  return this;
1030
1030
  }
1031
1031
  MapCache.prototype.clear = mapCacheClear;
@@ -2482,7 +2482,7 @@ var require_lodash = __commonJS({
2482
2482
  bitmask |= isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG;
2483
2483
  bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
2484
2484
  if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
2485
- bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
2485
+ bitmask &= -4;
2486
2486
  }
2487
2487
  var newData = [
2488
2488
  func,
@@ -2538,7 +2538,7 @@ var require_lodash = __commonJS({
2538
2538
  }
2539
2539
  var length = partials ? partials.length : 0;
2540
2540
  if (!length) {
2541
- bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
2541
+ bitmask &= -97;
2542
2542
  partials = holders = undefined2;
2543
2543
  }
2544
2544
  ary2 = ary2 === undefined2 ? ary2 : nativeMax(toInteger(ary2), 0);
@@ -2571,7 +2571,7 @@ var require_lodash = __commonJS({
2571
2571
  holders = newData[4];
2572
2572
  arity = newData[9] = newData[9] === undefined2 ? isBindKey ? 0 : func.length : nativeMax(newData[9] - length, 0);
2573
2573
  if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
2574
- bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
2574
+ bitmask &= -25;
2575
2575
  }
2576
2576
  if (!bitmask || bitmask == WRAP_BIND_FLAG) {
2577
2577
  var result2 = createBind(func, bitmask, thisArg);
@@ -2839,19 +2839,19 @@ var require_lodash = __commonJS({
2839
2839
  function getView(start, end, transforms) {
2840
2840
  var index = -1, length = transforms.length;
2841
2841
  while (++index < length) {
2842
- var data = transforms[index], size2 = data.size;
2842
+ var data = transforms[index], size3 = data.size;
2843
2843
  switch (data.type) {
2844
2844
  case "drop":
2845
- start += size2;
2845
+ start += size3;
2846
2846
  break;
2847
2847
  case "dropRight":
2848
- end -= size2;
2848
+ end -= size3;
2849
2849
  break;
2850
2850
  case "take":
2851
- end = nativeMin(end, start + size2);
2851
+ end = nativeMin(end, start + size3);
2852
2852
  break;
2853
2853
  case "takeRight":
2854
- start = nativeMax(start, end - size2);
2854
+ start = nativeMax(start, end - size3);
2855
2855
  break;
2856
2856
  }
2857
2857
  }
@@ -3111,15 +3111,15 @@ var require_lodash = __commonJS({
3111
3111
  return func.apply(undefined2, arguments);
3112
3112
  };
3113
3113
  }
3114
- function shuffleSelf(array, size2) {
3114
+ function shuffleSelf(array, size3) {
3115
3115
  var index = -1, length = array.length, lastIndex = length - 1;
3116
- size2 = size2 === undefined2 ? length : size2;
3117
- while (++index < size2) {
3116
+ size3 = size3 === undefined2 ? length : size3;
3117
+ while (++index < size3) {
3118
3118
  var rand = baseRandom(index, lastIndex), value = array[rand];
3119
3119
  array[rand] = array[index];
3120
3120
  array[index] = value;
3121
3121
  }
3122
- array.length = size2;
3122
+ array.length = size3;
3123
3123
  return array;
3124
3124
  }
3125
3125
  var stringToPath = memoizeCapped(function(string) {
@@ -3171,19 +3171,19 @@ var require_lodash = __commonJS({
3171
3171
  result2.__values__ = wrapper.__values__;
3172
3172
  return result2;
3173
3173
  }
3174
- function chunk(array, size2, guard) {
3175
- if (guard ? isIterateeCall(array, size2, guard) : size2 === undefined2) {
3176
- size2 = 1;
3174
+ function chunk(array, size3, guard) {
3175
+ if (guard ? isIterateeCall(array, size3, guard) : size3 === undefined2) {
3176
+ size3 = 1;
3177
3177
  } else {
3178
- size2 = nativeMax(toInteger(size2), 0);
3178
+ size3 = nativeMax(toInteger(size3), 0);
3179
3179
  }
3180
3180
  var length = array == null ? 0 : array.length;
3181
- if (!length || size2 < 1) {
3181
+ if (!length || size3 < 1) {
3182
3182
  return [];
3183
3183
  }
3184
- var index = 0, resIndex = 0, result2 = Array2(nativeCeil(length / size2));
3184
+ var index = 0, resIndex = 0, result2 = Array2(nativeCeil(length / size3));
3185
3185
  while (index < length) {
3186
- result2[resIndex++] = baseSlice(array, index, index += size2);
3186
+ result2[resIndex++] = baseSlice(array, index, index += size3);
3187
3187
  }
3188
3188
  return result2;
3189
3189
  }
@@ -3859,7 +3859,7 @@ var require_lodash = __commonJS({
3859
3859
  result2.placeholder = curryRight.placeholder;
3860
3860
  return result2;
3861
3861
  }
3862
- function debounce2(func, wait, options) {
3862
+ function debounce3(func, wait, options) {
3863
3863
  var lastArgs, lastThis, maxWait, result2, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
3864
3864
  if (typeof func != "function") {
3865
3865
  throw new TypeError2(FUNC_ERROR_TEXT);
@@ -4039,7 +4039,7 @@ var require_lodash = __commonJS({
4039
4039
  leading = "leading" in options ? !!options.leading : leading;
4040
4040
  trailing = "trailing" in options ? !!options.trailing : trailing;
4041
4041
  }
4042
- return debounce2(func, wait, {
4042
+ return debounce3(func, wait, {
4043
4043
  "leading": leading,
4044
4044
  "maxWait": wait,
4045
4045
  "trailing": trailing
@@ -4171,7 +4171,7 @@ var require_lodash = __commonJS({
4171
4171
  return baseIsMatch(object, source, getMatchData(source), customizer);
4172
4172
  }
4173
4173
  function isNaN(value) {
4174
- return isNumber(value) && value != +value;
4174
+ return isNumber2(value) && value != +value;
4175
4175
  }
4176
4176
  function isNative(value) {
4177
4177
  if (isMaskable(value)) {
@@ -4185,7 +4185,7 @@ var require_lodash = __commonJS({
4185
4185
  function isNil(value) {
4186
4186
  return value == null;
4187
4187
  }
4188
- function isNumber(value) {
4188
+ function isNumber2(value) {
4189
4189
  return typeof value == "number" || isObjectLike(value) && baseGetTag(value) == numberTag;
4190
4190
  }
4191
4191
  function isPlainObject(value) {
@@ -4991,7 +4991,7 @@ var require_lodash = __commonJS({
4991
4991
  var id = ++idCounter;
4992
4992
  return toString(prefix) + id;
4993
4993
  }
4994
- var add = createMathOperation(function(augend, addend) {
4994
+ var add2 = createMathOperation(function(augend, addend) {
4995
4995
  return augend + addend;
4996
4996
  }, 0);
4997
4997
  var ceil = createRound("ceil");
@@ -5053,7 +5053,7 @@ var require_lodash = __commonJS({
5053
5053
  lodash.create = create;
5054
5054
  lodash.curry = curry;
5055
5055
  lodash.curryRight = curryRight;
5056
- lodash.debounce = debounce2;
5056
+ lodash.debounce = debounce3;
5057
5057
  lodash.defaults = defaults;
5058
5058
  lodash.defaultsDeep = defaultsDeep;
5059
5059
  lodash.defer = defer;
@@ -5184,7 +5184,7 @@ var require_lodash = __commonJS({
5184
5184
  lodash.extend = assignIn;
5185
5185
  lodash.extendWith = assignInWith;
5186
5186
  mixin(lodash, lodash);
5187
- lodash.add = add;
5187
+ lodash.add = add2;
5188
5188
  lodash.attempt = attempt;
5189
5189
  lodash.camelCase = camelCase;
5190
5190
  lodash.capitalize = capitalize;
@@ -5251,7 +5251,7 @@ var require_lodash = __commonJS({
5251
5251
  lodash.isNative = isNative;
5252
5252
  lodash.isNil = isNil;
5253
5253
  lodash.isNull = isNull;
5254
- lodash.isNumber = isNumber;
5254
+ lodash.isNumber = isNumber2;
5255
5255
  lodash.isObject = isObject;
5256
5256
  lodash.isObjectLike = isObjectLike;
5257
5257
  lodash.isPlainObject = isPlainObject;
@@ -5521,72 +5521,81 @@ var require_lodash = __commonJS({
5521
5521
  }
5522
5522
  });
5523
5523
 
5524
- // node_modules/.pnpm/@wopjs+disposable@0.1.5/node_modules/@wopjs/disposable/dist/index.mjs
5525
- var isAbortable = (disposable) => disposable && disposable.abortable;
5526
- var dispose = (disposable) => {
5524
+ // node_modules/.pnpm/@wopjs+disposable@0.1.19/node_modules/@wopjs/disposable/dist/index.mjs
5525
+ var isFn = (value) => !!(value && value.constructor && value.call && value.apply);
5526
+ var isDisposable = (value) => isFn(value) || isFn(value == null ? void 0 : value.dispose);
5527
+ function dispose(disposable) {
5527
5528
  try {
5528
5529
  if (disposable) {
5529
- if (disposable.dispose) {
5530
+ if (isFn(disposable.dispose)) {
5530
5531
  disposable.dispose();
5531
- } else if (disposable.constructor && disposable.call && disposable.apply) {
5532
+ } else if (isFn(disposable)) {
5532
5533
  disposable();
5533
5534
  }
5534
5535
  }
5535
5536
  } catch (e) {
5536
5537
  console.error(e);
5537
5538
  }
5538
- };
5539
- var methods = {
5540
- size() {
5541
- return this._d.size;
5542
- },
5543
- has(disposable) {
5544
- return this._d.has(disposable);
5545
- },
5546
- add(disposable) {
5547
- const disposables = Array.isArray(disposable) ? disposable : [disposable];
5548
- for (const disposable2 of disposables) {
5549
- if (!this._d.has(disposable2)) {
5550
- this._d.add(disposable2);
5551
- if (isAbortable(disposable2)) {
5552
- disposable2.abortable(() => this.remove(disposable2));
5553
- }
5554
- }
5555
- }
5556
- return disposable;
5557
- },
5558
- make(executor) {
5559
- const disposable = executor();
5560
- if (disposable) {
5561
- return this.add(disposable);
5562
- }
5563
- },
5564
- remove(disposable) {
5565
- return this._d.delete(disposable);
5566
- },
5567
- flush(disposable) {
5568
- if (disposable) {
5569
- if (this.remove(disposable)) {
5570
- dispose(disposable);
5571
- }
5572
- } else {
5573
- this.dispose();
5574
- }
5539
+ }
5540
+ var isAbortable = (disposable) => isDisposable(disposable) && isFn(disposable.abortable);
5541
+ function disposableStore(disposables) {
5542
+ function disposableStore2() {
5543
+ var _a, _b;
5544
+ if (disposableStore2._i)
5545
+ return;
5546
+ disposableStore2._i = 1;
5547
+ (_a = disposableStore2._d) == null ? void 0 : _a.forEach(dispose);
5548
+ (_b = disposableStore2._d) == null ? void 0 : _b.clear();
5549
+ disposableStore2._i = 0;
5575
5550
  }
5576
- };
5577
- var disposableStore = (disposables) => {
5578
- const disposableStore2 = () => {
5579
- disposableStore2._d.forEach(dispose);
5580
- disposableStore2._d.clear();
5581
- };
5582
- disposableStore2._d = /* @__PURE__ */ new Set();
5551
+ disposableStore2._i = 0;
5583
5552
  disposableStore2.dispose = disposableStore2;
5584
- const store = Object.assign(disposableStore2, methods);
5585
- if (disposables) {
5586
- store.add(disposables);
5553
+ disposableStore2.size = size2;
5554
+ disposableStore2.has = has2;
5555
+ disposableStore2.add = add;
5556
+ disposableStore2.make = make3;
5557
+ disposableStore2.remove = remove3;
5558
+ disposableStore2.flush = flush2;
5559
+ return disposableStore2;
5560
+ }
5561
+ function _addOne(disposable) {
5562
+ var _a, _b;
5563
+ if (!((_a = this._d) == null ? void 0 : _a.has(disposable))) {
5564
+ ((_b = this._d) != null ? _b : this._d = /* @__PURE__ */ new Set()).add(disposable);
5565
+ if (isAbortable(disposable)) {
5566
+ disposable.abortable(() => this.remove(disposable));
5567
+ }
5587
5568
  }
5588
- return store;
5589
- };
5569
+ }
5570
+ function add(disposables) {
5571
+ Array.isArray(disposables) ? disposables.forEach(_addOne, this) : _addOne.call(this, disposables);
5572
+ return disposables;
5573
+ }
5574
+ function flush2(disposable) {
5575
+ if (disposable) {
5576
+ if (this.remove(disposable)) {
5577
+ dispose(disposable);
5578
+ }
5579
+ } else {
5580
+ this.dispose();
5581
+ }
5582
+ }
5583
+ function has2(disposable) {
5584
+ var _a;
5585
+ return ((_a = this._d) == null ? void 0 : _a.has(disposable)) || false;
5586
+ }
5587
+ function make3(executor) {
5588
+ const disposable = executor();
5589
+ return disposable && this.add(disposable);
5590
+ }
5591
+ function remove3(disposable) {
5592
+ var _a;
5593
+ return ((_a = this._d) == null ? void 0 : _a.delete(disposable)) || false;
5594
+ }
5595
+ function size2() {
5596
+ var _a;
5597
+ return ((_a = this._d) == null ? void 0 : _a.size) || 0;
5598
+ }
5590
5599
 
5591
5600
  // node_modules/.pnpm/@wopjs+dom@0.1.3/node_modules/@wopjs/dom/dist/index.js
5592
5601
  function addEventListener(target, type, listener, options) {
@@ -6453,9 +6462,6 @@ var Presentation = class {
6453
6462
  this.contentDOM.className = this.c("content");
6454
6463
  this.previewDOM = document.createElement("div");
6455
6464
  this.previewDOM.className = this.c("preview");
6456
- this.imageDOM = document.createElement("div");
6457
- this.imageDOM.className = this.c("image");
6458
- this.image = document.createElement("img");
6459
6465
  this.whiteboardDOM = document.createElement("div");
6460
6466
  this.whiteboardDOM.className = this.c("wb-view");
6461
6467
  this.footerDOM = document.createElement("div");
@@ -6525,8 +6531,6 @@ var Presentation = class {
6525
6531
  this.togglePreview(false);
6526
6532
  }
6527
6533
  }));
6528
- this.imageDOM.appendChild(this.image);
6529
- this.contentDOM.appendChild(this.imageDOM);
6530
6534
  this.updateImage();
6531
6535
  this.contentDOM.appendChild(this.whiteboardDOM);
6532
6536
  this.footerDOM.classList.toggle(this.c("readonly"), this.readonly);
@@ -6835,17 +6839,22 @@ var Scrollbar = class {
6835
6839
  return;
6836
6840
  const { scale, centerX, centerY } = this.view.camera;
6837
6841
  const originScale = this.option.getOriginScale();
6838
- const ratio = Math.round(originScale / scale * 1e3) / 1e3;
6839
- const scrollX = Math.round(centerX * originScale);
6840
- const scrollY = Math.round(centerY * originScale);
6842
+ const { width: pageWidth, height: pageHeight } = this.option.getPageSize();
6843
+ const { width: viewWidth, height: viewHeight } = this.view.size;
6844
+ const originScaleX = viewWidth / pageWidth;
6845
+ const originScaleY = viewHeight / pageHeight;
6846
+ const ratioX = Math.min(Math.round(originScaleX / scale * 100) / 100, 1);
6847
+ const ratioY = Math.min(Math.round(originScaleY / scale * 100) / 100, 1);
6848
+ const scrollX = Math.round(centerX * originScaleX);
6849
+ const scrollY = Math.round(centerY * originScaleY);
6841
6850
  if (this.scrollbarX) {
6842
- this.scrollbarX.style.width = `${ratio * 100}%`;
6843
- this.scrollbarX.style.display = ratio === 1 ? "none" : "block";
6851
+ this.scrollbarX.style.width = `${ratioX * 100}%`;
6852
+ this.scrollbarX.style.display = ratioX === 1 ? "none" : "block";
6844
6853
  this.scrollbarX.style.transform = `translateX(${scrollX}px)`;
6845
6854
  }
6846
6855
  if (this.scrollbarY) {
6847
- this.scrollbarY.style.height = `${ratio * 100}%`;
6848
- this.scrollbarY.style.display = ratio === 1 ? "none" : "block";
6856
+ this.scrollbarY.style.height = `${ratioY * 100}%`;
6857
+ this.scrollbarY.style.display = ratioY === 1 ? "none" : "block";
6849
6858
  this.scrollbarY.style.transform = `translateY(${scrollY}px)`;
6850
6859
  }
6851
6860
  (_b = (_a = this.option.scrollbarEventCallback) == null ? void 0 : _a.onScrollCameraUpdated) == null ? void 0 : _b.call(_a, this.appId, originScale, scale);
@@ -6864,9 +6873,11 @@ var Scrollbar = class {
6864
6873
  var _a, _b;
6865
6874
  if (this.cameraCache) {
6866
6875
  const { x } = transformedDrag;
6867
- const originScale = this.option.getOriginScale();
6876
+ const { width: pageWidth } = this.option.getPageSize();
6877
+ const { width: viewWidth } = this.view.size;
6878
+ const originScaleX = viewWidth / pageWidth;
6868
6879
  const { minX, maxX } = this.getScrollXRange(this.cameraCache);
6869
- const scrollX = Math.round(x / originScale);
6880
+ const scrollX = Math.round(x / originScaleX);
6870
6881
  let centerX = scrollX + this.cameraCache.centerX;
6871
6882
  if (centerX < minX) {
6872
6883
  centerX = minX;
@@ -6884,9 +6895,11 @@ var Scrollbar = class {
6884
6895
  var _a, _b;
6885
6896
  if (this.cameraCache) {
6886
6897
  const { y } = transformedDrag;
6887
- const originScale = this.option.getOriginScale();
6898
+ const { height: pageHeight } = this.option.getPageSize();
6899
+ const { height: viewHeight } = this.view.size;
6900
+ const originScaleY = viewHeight / pageHeight;
6888
6901
  const { minY, maxY } = this.getScrollYRange(this.cameraCache);
6889
- const scrollY = Math.round(y / originScale);
6902
+ const scrollY = Math.round(y / originScaleY);
6890
6903
  let centerY = scrollY + this.cameraCache.centerY;
6891
6904
  if (centerY < minY) {
6892
6905
  centerY = minY;
@@ -6906,6 +6919,35 @@ var Scrollbar = class {
6906
6919
  this.option.syncView();
6907
6920
  (_b = (_a = this.option.scrollbarEventCallback) == null ? void 0 : _a.onScrollbarDragEnd) == null ? void 0 : _b.call(_a);
6908
6921
  };
6922
+ this.moveCamera = (camera) => {
6923
+ const { centerX, centerY } = camera;
6924
+ const cacheCamera = this.view.camera;
6925
+ const _camera = {};
6926
+ if ((0, import_lodash.isNumber)(centerX)) {
6927
+ const { minX, maxX } = this.getScrollXRange(cacheCamera);
6928
+ let newCenterX = centerX;
6929
+ if (centerX < minX) {
6930
+ newCenterX = minX;
6931
+ } else if (centerX > maxX) {
6932
+ newCenterX = maxX;
6933
+ }
6934
+ _camera.centerX = newCenterX;
6935
+ }
6936
+ if ((0, import_lodash.isNumber)(centerY)) {
6937
+ const { minY, maxY } = this.getScrollYRange(cacheCamera);
6938
+ let newCenterY = centerY;
6939
+ if (centerY < minY) {
6940
+ newCenterY = minY;
6941
+ } else if (centerY > maxY) {
6942
+ newCenterY = maxY;
6943
+ }
6944
+ _camera.centerY = newCenterY;
6945
+ }
6946
+ this.view.moveCamera(__spreadProps(__spreadValues({}, _camera), {
6947
+ animationMode: "immediately"
6948
+ }));
6949
+ this.option.syncView();
6950
+ };
6909
6951
  this.scrollContainer.className = this.c("scrollbar-container");
6910
6952
  this.container = container;
6911
6953
  this.option = option;
@@ -6925,21 +6967,23 @@ var Scrollbar = class {
6925
6967
  }
6926
6968
  }
6927
6969
  getScrollXRange(camera) {
6928
- const { width } = this.option.getPageSize();
6929
- const originScale = this.option.getOriginScale();
6970
+ const { width: pageWidth } = this.option.getPageSize();
6971
+ const { width: viewWidth } = this.view.size;
6972
+ const originScaleX = viewWidth / pageWidth;
6930
6973
  const scale = camera.scale;
6931
- const ratio = Math.round(originScale / scale * 1e3) / 1e3;
6932
- const scrollWidth = width * (1 - ratio);
6974
+ const ratio = Math.min(Math.round(originScaleX / scale * 100) / 100, 1);
6975
+ const scrollWidth = pageWidth * (1 - ratio);
6933
6976
  const minX = -scrollWidth / 2;
6934
6977
  const maxX = scrollWidth / 2;
6935
6978
  return { minX, maxX };
6936
6979
  }
6937
6980
  getScrollYRange(camera) {
6938
- const { height } = this.option.getPageSize();
6939
- const originScale = this.option.getOriginScale();
6981
+ const { height: pageHeight } = this.option.getPageSize();
6982
+ const { height: viewHeight } = this.view.size;
6983
+ const originScaleY = viewHeight / pageHeight;
6940
6984
  const scale = camera.scale;
6941
- const ratio = Math.round(originScale / scale * 1e3) / 1e3;
6942
- const scrollHeight = height * (1 - ratio);
6985
+ const ratio = Math.min(Math.round(originScaleY / scale * 100) / 100, 1);
6986
+ const scrollHeight = pageHeight * (1 - ratio);
6943
6987
  const minY = -scrollHeight / 2;
6944
6988
  const maxY = scrollHeight / 2;
6945
6989
  return { minY, maxY };
@@ -7010,6 +7054,7 @@ var Scrollbar = class {
7010
7054
  };
7011
7055
 
7012
7056
  // src/app-presentation.ts
7057
+ var import_lodash2 = __toESM(require_lodash());
7013
7058
  var emptySceneName = "$$empty$$";
7014
7059
  var ppt2page = (ppt, name) => ppt ? { width: ppt.width, height: ppt.height, src: ppt.src, thumbnail: ppt.previewURL, name } : null;
7015
7060
  var createLogger = (room) => {
@@ -7091,9 +7136,9 @@ var NetlessAppPresentation = {
7091
7136
  if (pages.length > 100)
7092
7137
  console.warn(`[Presentation]: too many pages (${pages.length}), may cause performance issues`);
7093
7138
  let redirectResolve = void 0;
7094
- const room = context.getRoom();
7095
- if (room && room.isWritable) {
7096
- const scenes = room.entireScenes()[scenePath];
7139
+ const room2 = context.getRoom();
7140
+ if (room2 && room2.isWritable) {
7141
+ const scenes = room2.entireScenes()[scenePath];
7097
7142
  if (pageIndex$.value < 0 || pageIndex$.value >= pages.length) {
7098
7143
  throw new Error(`[Presentation] Invalid page index: ${pageIndex$.value}, scenes length: ${pages.length}`);
7099
7144
  }
@@ -7108,8 +7153,8 @@ var NetlessAppPresentation = {
7108
7153
  };
7109
7154
  });
7110
7155
  if (!scenesEqual(scenes, _scenes)) {
7111
- room.removeScenes(scenePath);
7112
- room.putScenes(scenePath, _scenes);
7156
+ room2.removeScenes(scenePath);
7157
+ room2.putScenes(scenePath, _scenes);
7113
7158
  }
7114
7159
  if (name === _scenes[pageIndex$.value].name && !ppt) {
7115
7160
  context.addPage({ scene: { name: emptySceneName } }).then(() => {
@@ -7122,10 +7167,10 @@ var NetlessAppPresentation = {
7122
7167
  redirectResolve && redirectResolve(false);
7123
7168
  }
7124
7169
  }).then(async (bol) => {
7125
- await syncPage(pageIndex$.value, room.logger);
7170
+ await syncPage(pageIndex$.value, room2.logger);
7126
7171
  if (bol) {
7127
7172
  log(`[Presentation] setup removeScenes ${scenePath}/${emptySceneName}`);
7128
- room.removeScenes(`${scenePath}/${emptySceneName}`);
7173
+ room2.removeScenes(`${scenePath}/${emptySceneName}`);
7129
7174
  }
7130
7175
  });
7131
7176
  }
@@ -7240,14 +7285,32 @@ var NetlessAppPresentation = {
7240
7285
  }
7241
7286
  };
7242
7287
  dispose2.add(view$$.addStateChangedListener(() => syncViewFromRemote(false, true)));
7288
+ const getPageSize = () => {
7289
+ const { width, height } = app.page() || {};
7290
+ return { width: width || 0, height: height || 0 };
7291
+ };
7243
7292
  const box = context.getBox();
7244
- const app = dispose2.add(createPresentation(box, pages, jumpPage, pageIndex$, options.thumbnail));
7245
- app.contentDOM.dataset.appPresentationVersion = "0.1.9-beta.5";
7293
+ const app = dispose2.add(createPresentation(box, pages, jumpPage, pageIndex$, view, options.thumbnail, options.useClipView));
7294
+ app.contentDOM.dataset.appPresentationVersion = "0.1.9-beta.7";
7246
7295
  app.scaleDocsToFit = scaleDocsToFit;
7247
7296
  app.log = log;
7248
7297
  if (options.justDocsViewReadonly) {
7249
7298
  app.setDocsViewReadonly(true);
7250
7299
  }
7300
+ const room = context.getRoom();
7301
+ const goToPageByClick = () => {
7302
+ var _a2, _b2, _c2, _d;
7303
+ const currentApplianceName = (_d = (_c2 = (_b2 = (_a2 = context.getRoom()) == null ? void 0 : _a2.state) == null ? void 0 : _b2.memberState) == null ? void 0 : _c2.currentApplianceName) != null ? _d : "";
7304
+ if (!app.readonly && currentApplianceName === "clicker") {
7305
+ nextPage();
7306
+ }
7307
+ };
7308
+ if (room && options.goToPageByClick && app.whiteboardDOM) {
7309
+ dispose2.make(() => {
7310
+ app.whiteboardDOM.addEventListener("click", goToPageByClick);
7311
+ return () => app.whiteboardDOM.removeEventListener("click", goToPageByClick);
7312
+ });
7313
+ }
7251
7314
  context.mountView(app.whiteboardDOM);
7252
7315
  if (options.disableCameraTransform) {
7253
7316
  view.disableCameraTransform = true;
@@ -7277,10 +7340,6 @@ var NetlessAppPresentation = {
7277
7340
  dispose2.add(context.emitter.on("writableChange", (isWritable) => {
7278
7341
  app.setReadonly(!isWritable);
7279
7342
  }));
7280
- const getPageSize = () => {
7281
- const { width, height } = app.page() || {};
7282
- return { width: width || 0, height: height || 0 };
7283
- };
7284
7343
  const getOriginScale = () => {
7285
7344
  const { size } = view;
7286
7345
  const { width, height } = getPageSize();
@@ -7289,13 +7348,41 @@ var NetlessAppPresentation = {
7289
7348
  const getScale = () => {
7290
7349
  return view.camera.scale;
7291
7350
  };
7292
- const moveCamera = (camera) => {
7293
- if (context.getIsWritable()) {
7294
- view.moveCamera(__spreadProps(__spreadValues({}, camera), { animationMode: "immediately" }));
7295
- syncView();
7296
- return;
7351
+ const screenshotCurrentPageAsync = async (_context, _width, _height) => {
7352
+ var _a2, _b2;
7353
+ (_b2 = (_a2 = room == null ? void 0 : room.calibrationTimestamp) == null ? void 0 : _a2.toString()) != null ? _b2 : Date.now().toString();
7354
+ const currentPage = pages[pageIndex$.value];
7355
+ if (!currentPage) {
7356
+ throw new Error("[Presentation]: current page not found");
7357
+ }
7358
+ const { width, height, src } = currentPage;
7359
+ const img = document.createElement("img");
7360
+ img.width = width;
7361
+ img.height = height;
7362
+ img.crossOrigin = "Anonymous";
7363
+ await new Promise((resolve) => {
7364
+ img.onload = resolve;
7365
+ img.src = src;
7366
+ });
7367
+ _context.drawImage(img, 0, 0, width, height, 0, 0, _width || width, _height || height);
7368
+ const currentScenePath = view.focusScenePath;
7369
+ if (!currentScenePath) {
7370
+ throw new Error("[Presentation]: current scene path not found");
7371
+ }
7372
+ const windowManger = context.getWindowManager();
7373
+ if (windowManger._appliancePlugin) {
7374
+ await windowManger._appliancePlugin.screenshotToCanvasAsync(_context, currentScenePath, _width || width, _height || height, {
7375
+ centerX: 0,
7376
+ centerY: 0,
7377
+ scale: _width && _height ? Math.min(_width / width, _height / height) : 1
7378
+ });
7379
+ } else {
7380
+ await view.screenshotToCanvasAsync(_context, currentScenePath, _width || width, _height || height, {
7381
+ centerX: 0,
7382
+ centerY: 0,
7383
+ scale: _width && _height ? Math.min(_width / width, _height / height) : 1
7384
+ });
7297
7385
  }
7298
- throw new Error("[Presentation]: moveCamera must be called in writable room");
7299
7386
  };
7300
7387
  let scrollbar;
7301
7388
  if (options.useScrollbar) {
@@ -7311,6 +7398,16 @@ var NetlessAppPresentation = {
7311
7398
  return () => scrollbar == null ? void 0 : scrollbar.destroy();
7312
7399
  });
7313
7400
  }
7401
+ const moveCamera = (camera) => {
7402
+ if (context.getIsWritable() && scrollbar) {
7403
+ if (!scrollbar) {
7404
+ throw new Error("[Presentation]: moveCamera must be called when appOptions: useScrollbar is true");
7405
+ }
7406
+ scrollbar.moveCamera(camera);
7407
+ return;
7408
+ }
7409
+ throw new Error("[Presentation]: moveCamera must be called in writable room");
7410
+ };
7314
7411
  context.emitter.on("destroy", () => dispose2());
7315
7412
  const reportProgress = (progress, result) => {
7316
7413
  window.postMessage({ type: "@netless/_result_save_pdf_", appId: context.appId, progress, result }, "*");
@@ -7379,12 +7476,12 @@ var NetlessAppPresentation = {
7379
7476
  const name = (_a2 = p.name) != null ? _a2 : String(index + 1);
7380
7477
  if (scenes.some((scene) => scene.name == name)) {
7381
7478
  const camera = { centerX: 0, centerY: 0, scale: Math.min(wb_canvas.width / width2, wb_canvas.height / height2) };
7382
- const sPath = `${scenePath}/${index + 1}`;
7383
- const windowManger = context.manager.windowManger;
7479
+ const sPath = `${scenePath}/${name}`;
7480
+ const windowManger = context.getWindowManager();
7384
7481
  if (windowManger._appliancePlugin) {
7385
7482
  await windowManger._appliancePlugin.screenshotToCanvasAsync(wb, sPath, wb_canvas.width, wb_canvas.height, camera);
7386
7483
  } else {
7387
- view.screenshotToCanvas(
7484
+ await view.screenshotToCanvasAsync(
7388
7485
  wb,
7389
7486
  sPath,
7390
7487
  wb_canvas.width,
@@ -7430,11 +7527,12 @@ var NetlessAppPresentation = {
7430
7527
  };
7431
7528
  const setReadonly = (bol) => {
7432
7529
  app.setReadonly(bol);
7530
+ if (options.goToPageByClick) ;
7433
7531
  if (scrollbar) {
7434
7532
  scrollbar.setReadonly(bol);
7435
7533
  }
7436
7534
  };
7437
- const controller = { app, view, context, jumpPage, prevPage, nextPage, pageState, toPdf, log, setDocsViewReadonly, setReadonly, moveCamera, getOriginScale, getScale };
7535
+ const controller = { app, view, context, jumpPage, prevPage, nextPage, pageState, toPdf, log, setDocsViewReadonly, setReadonly, moveCamera, getOriginScale, getScale, getPageSize, screenshotCurrentPageAsync };
7438
7536
  dispose2.add(listen(window, "message", (ev) => {
7439
7537
  if (ev.data === "@netless/_presentation_") {
7440
7538
  if (typeof window !== "undefined")
@@ -7453,7 +7551,6 @@ var AppPresentation = class extends Presentation {
7453
7551
  constructor(config) {
7454
7552
  super(config);
7455
7553
  this.jumpPage = config.jumpPage;
7456
- this.image.style.display = "none";
7457
7554
  }
7458
7555
  updateImage() {
7459
7556
  super.updateImage();
@@ -7470,7 +7567,7 @@ var AppPresentation = class extends Presentation {
7470
7567
  }
7471
7568
  }
7472
7569
  };
7473
- function createPresentation(box, pages, jumpPage, pageIndex$, thumbnail) {
7570
+ function createPresentation(box, pages, jumpPage, pageIndex$, view, thumbnail, useClipView) {
7474
7571
  box.mountStyles(style_default);
7475
7572
  const app = new AppPresentation({ pages, readonly: box.readonly, jumpPage, thumbnail });
7476
7573
  app.box = box;
@@ -7479,6 +7576,29 @@ function createPresentation(box, pages, jumpPage, pageIndex$, thumbnail) {
7479
7576
  app.dispose.add(pageIndex$.subscribe((pageIndex) => {
7480
7577
  app.setPageIndex(pageIndex);
7481
7578
  }));
7579
+ if (useClipView && view) {
7580
+ const onCameraUpdatedEffectForMaskView = (0, import_lodash2.debounce)(() => {
7581
+ const { width: pageWidth, height: pageHeight } = app.page() || {};
7582
+ if (!pageWidth || !pageHeight) {
7583
+ return;
7584
+ }
7585
+ const { scale } = view.camera;
7586
+ const { width, height } = view.size;
7587
+ const pageRatioX = Math.round((1 - pageWidth * scale / width) / 2 * 100);
7588
+ const pageRatioY = Math.round((1 - pageHeight * scale / height) / 2 * 100);
7589
+ app.whiteboardDOM.style.clipPath = `inset(${pageRatioY}% ${pageRatioX}%)`;
7590
+ }, 50);
7591
+ onCameraUpdatedEffectForMaskView();
7592
+ const onCameraUpdatedEffect = () => {
7593
+ view.callbacks.on("onSizeUpdated", onCameraUpdatedEffectForMaskView);
7594
+ view.callbacks.on("onCameraUpdated", onCameraUpdatedEffectForMaskView);
7595
+ return () => {
7596
+ view.callbacks.off("onCameraUpdated", onCameraUpdatedEffectForMaskView);
7597
+ view.callbacks.off("onSizeUpdated", onCameraUpdatedEffectForMaskView);
7598
+ };
7599
+ };
7600
+ app.dispose.make(onCameraUpdatedEffect);
7601
+ }
7482
7602
  return app;
7483
7603
  }
7484
7604
  var install = (register, options = {}) => {
@@ -7490,7 +7610,7 @@ var install = (register, options = {}) => {
7490
7610
  };
7491
7611
 
7492
7612
  // src/index.ts
7493
- var version = "0.1.9-beta.5";
7613
+ var version = "0.1.9-beta.7";
7494
7614
  /*! Bundled license information:
7495
7615
 
7496
7616
  lodash/lodash.js:
@@ -7504,5 +7624,5 @@ lodash/lodash.js:
7504
7624
  *)
7505
7625
  */
7506
7626
 
7507
- export { NetlessAppPresentation, Presentation, NetlessAppPresentation as default, install, style_default as styles, version };
7627
+ export { NetlessAppPresentation, Presentation, Scrollbar, NetlessAppPresentation as default, install, version };
7508
7628
  //# sourceMappingURL=index.mjs.map