@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.js CHANGED
@@ -41,7 +41,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
41
41
  // file that has been converted to a CommonJS file using a Babel-
42
42
  // compatible transform (i.e. "__esModule" has not been set), then set
43
43
  // "default" to the CommonJS "module.exports" for node compatibility.
44
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
44
+ !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
45
45
  mod
46
46
  ));
47
47
 
@@ -1027,9 +1027,9 @@ var require_lodash = __commonJS({
1027
1027
  return getMapData(this, key).has(key);
1028
1028
  }
1029
1029
  function mapCacheSet(key, value) {
1030
- var data = getMapData(this, key), size2 = data.size;
1030
+ var data = getMapData(this, key), size3 = data.size;
1031
1031
  data.set(key, value);
1032
- this.size += data.size == size2 ? 0 : 1;
1032
+ this.size += data.size == size3 ? 0 : 1;
1033
1033
  return this;
1034
1034
  }
1035
1035
  MapCache.prototype.clear = mapCacheClear;
@@ -2486,7 +2486,7 @@ var require_lodash = __commonJS({
2486
2486
  bitmask |= isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG;
2487
2487
  bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
2488
2488
  if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
2489
- bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
2489
+ bitmask &= -4;
2490
2490
  }
2491
2491
  var newData = [
2492
2492
  func,
@@ -2542,7 +2542,7 @@ var require_lodash = __commonJS({
2542
2542
  }
2543
2543
  var length = partials ? partials.length : 0;
2544
2544
  if (!length) {
2545
- bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
2545
+ bitmask &= -97;
2546
2546
  partials = holders = undefined2;
2547
2547
  }
2548
2548
  ary2 = ary2 === undefined2 ? ary2 : nativeMax(toInteger(ary2), 0);
@@ -2575,7 +2575,7 @@ var require_lodash = __commonJS({
2575
2575
  holders = newData[4];
2576
2576
  arity = newData[9] = newData[9] === undefined2 ? isBindKey ? 0 : func.length : nativeMax(newData[9] - length, 0);
2577
2577
  if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
2578
- bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
2578
+ bitmask &= -25;
2579
2579
  }
2580
2580
  if (!bitmask || bitmask == WRAP_BIND_FLAG) {
2581
2581
  var result2 = createBind(func, bitmask, thisArg);
@@ -2843,19 +2843,19 @@ var require_lodash = __commonJS({
2843
2843
  function getView(start, end, transforms) {
2844
2844
  var index = -1, length = transforms.length;
2845
2845
  while (++index < length) {
2846
- var data = transforms[index], size2 = data.size;
2846
+ var data = transforms[index], size3 = data.size;
2847
2847
  switch (data.type) {
2848
2848
  case "drop":
2849
- start += size2;
2849
+ start += size3;
2850
2850
  break;
2851
2851
  case "dropRight":
2852
- end -= size2;
2852
+ end -= size3;
2853
2853
  break;
2854
2854
  case "take":
2855
- end = nativeMin(end, start + size2);
2855
+ end = nativeMin(end, start + size3);
2856
2856
  break;
2857
2857
  case "takeRight":
2858
- start = nativeMax(start, end - size2);
2858
+ start = nativeMax(start, end - size3);
2859
2859
  break;
2860
2860
  }
2861
2861
  }
@@ -3115,15 +3115,15 @@ var require_lodash = __commonJS({
3115
3115
  return func.apply(undefined2, arguments);
3116
3116
  };
3117
3117
  }
3118
- function shuffleSelf(array, size2) {
3118
+ function shuffleSelf(array, size3) {
3119
3119
  var index = -1, length = array.length, lastIndex = length - 1;
3120
- size2 = size2 === undefined2 ? length : size2;
3121
- while (++index < size2) {
3120
+ size3 = size3 === undefined2 ? length : size3;
3121
+ while (++index < size3) {
3122
3122
  var rand = baseRandom(index, lastIndex), value = array[rand];
3123
3123
  array[rand] = array[index];
3124
3124
  array[index] = value;
3125
3125
  }
3126
- array.length = size2;
3126
+ array.length = size3;
3127
3127
  return array;
3128
3128
  }
3129
3129
  var stringToPath = memoizeCapped(function(string) {
@@ -3175,19 +3175,19 @@ var require_lodash = __commonJS({
3175
3175
  result2.__values__ = wrapper.__values__;
3176
3176
  return result2;
3177
3177
  }
3178
- function chunk(array, size2, guard) {
3179
- if (guard ? isIterateeCall(array, size2, guard) : size2 === undefined2) {
3180
- size2 = 1;
3178
+ function chunk(array, size3, guard) {
3179
+ if (guard ? isIterateeCall(array, size3, guard) : size3 === undefined2) {
3180
+ size3 = 1;
3181
3181
  } else {
3182
- size2 = nativeMax(toInteger(size2), 0);
3182
+ size3 = nativeMax(toInteger(size3), 0);
3183
3183
  }
3184
3184
  var length = array == null ? 0 : array.length;
3185
- if (!length || size2 < 1) {
3185
+ if (!length || size3 < 1) {
3186
3186
  return [];
3187
3187
  }
3188
- var index = 0, resIndex = 0, result2 = Array2(nativeCeil(length / size2));
3188
+ var index = 0, resIndex = 0, result2 = Array2(nativeCeil(length / size3));
3189
3189
  while (index < length) {
3190
- result2[resIndex++] = baseSlice(array, index, index += size2);
3190
+ result2[resIndex++] = baseSlice(array, index, index += size3);
3191
3191
  }
3192
3192
  return result2;
3193
3193
  }
@@ -3863,7 +3863,7 @@ var require_lodash = __commonJS({
3863
3863
  result2.placeholder = curryRight.placeholder;
3864
3864
  return result2;
3865
3865
  }
3866
- function debounce2(func, wait, options) {
3866
+ function debounce3(func, wait, options) {
3867
3867
  var lastArgs, lastThis, maxWait, result2, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
3868
3868
  if (typeof func != "function") {
3869
3869
  throw new TypeError2(FUNC_ERROR_TEXT);
@@ -4043,7 +4043,7 @@ var require_lodash = __commonJS({
4043
4043
  leading = "leading" in options ? !!options.leading : leading;
4044
4044
  trailing = "trailing" in options ? !!options.trailing : trailing;
4045
4045
  }
4046
- return debounce2(func, wait, {
4046
+ return debounce3(func, wait, {
4047
4047
  "leading": leading,
4048
4048
  "maxWait": wait,
4049
4049
  "trailing": trailing
@@ -4175,7 +4175,7 @@ var require_lodash = __commonJS({
4175
4175
  return baseIsMatch(object, source, getMatchData(source), customizer);
4176
4176
  }
4177
4177
  function isNaN(value) {
4178
- return isNumber(value) && value != +value;
4178
+ return isNumber2(value) && value != +value;
4179
4179
  }
4180
4180
  function isNative(value) {
4181
4181
  if (isMaskable(value)) {
@@ -4189,7 +4189,7 @@ var require_lodash = __commonJS({
4189
4189
  function isNil(value) {
4190
4190
  return value == null;
4191
4191
  }
4192
- function isNumber(value) {
4192
+ function isNumber2(value) {
4193
4193
  return typeof value == "number" || isObjectLike(value) && baseGetTag(value) == numberTag;
4194
4194
  }
4195
4195
  function isPlainObject(value) {
@@ -4995,7 +4995,7 @@ var require_lodash = __commonJS({
4995
4995
  var id = ++idCounter;
4996
4996
  return toString(prefix) + id;
4997
4997
  }
4998
- var add = createMathOperation(function(augend, addend) {
4998
+ var add2 = createMathOperation(function(augend, addend) {
4999
4999
  return augend + addend;
5000
5000
  }, 0);
5001
5001
  var ceil = createRound("ceil");
@@ -5057,7 +5057,7 @@ var require_lodash = __commonJS({
5057
5057
  lodash.create = create;
5058
5058
  lodash.curry = curry;
5059
5059
  lodash.curryRight = curryRight;
5060
- lodash.debounce = debounce2;
5060
+ lodash.debounce = debounce3;
5061
5061
  lodash.defaults = defaults;
5062
5062
  lodash.defaultsDeep = defaultsDeep;
5063
5063
  lodash.defer = defer;
@@ -5188,7 +5188,7 @@ var require_lodash = __commonJS({
5188
5188
  lodash.extend = assignIn;
5189
5189
  lodash.extendWith = assignInWith;
5190
5190
  mixin(lodash, lodash);
5191
- lodash.add = add;
5191
+ lodash.add = add2;
5192
5192
  lodash.attempt = attempt;
5193
5193
  lodash.camelCase = camelCase;
5194
5194
  lodash.capitalize = capitalize;
@@ -5255,7 +5255,7 @@ var require_lodash = __commonJS({
5255
5255
  lodash.isNative = isNative;
5256
5256
  lodash.isNil = isNil;
5257
5257
  lodash.isNull = isNull;
5258
- lodash.isNumber = isNumber;
5258
+ lodash.isNumber = isNumber2;
5259
5259
  lodash.isObject = isObject;
5260
5260
  lodash.isObjectLike = isObjectLike;
5261
5261
  lodash.isPlainObject = isPlainObject;
@@ -5525,72 +5525,81 @@ var require_lodash = __commonJS({
5525
5525
  }
5526
5526
  });
5527
5527
 
5528
- // node_modules/.pnpm/@wopjs+disposable@0.1.5/node_modules/@wopjs/disposable/dist/index.mjs
5529
- var isAbortable = (disposable) => disposable && disposable.abortable;
5530
- var dispose = (disposable) => {
5528
+ // node_modules/.pnpm/@wopjs+disposable@0.1.19/node_modules/@wopjs/disposable/dist/index.mjs
5529
+ var isFn = (value) => !!(value && value.constructor && value.call && value.apply);
5530
+ var isDisposable = (value) => isFn(value) || isFn(value == null ? void 0 : value.dispose);
5531
+ function dispose(disposable) {
5531
5532
  try {
5532
5533
  if (disposable) {
5533
- if (disposable.dispose) {
5534
+ if (isFn(disposable.dispose)) {
5534
5535
  disposable.dispose();
5535
- } else if (disposable.constructor && disposable.call && disposable.apply) {
5536
+ } else if (isFn(disposable)) {
5536
5537
  disposable();
5537
5538
  }
5538
5539
  }
5539
5540
  } catch (e) {
5540
5541
  console.error(e);
5541
5542
  }
5542
- };
5543
- var methods = {
5544
- size() {
5545
- return this._d.size;
5546
- },
5547
- has(disposable) {
5548
- return this._d.has(disposable);
5549
- },
5550
- add(disposable) {
5551
- const disposables = Array.isArray(disposable) ? disposable : [disposable];
5552
- for (const disposable2 of disposables) {
5553
- if (!this._d.has(disposable2)) {
5554
- this._d.add(disposable2);
5555
- if (isAbortable(disposable2)) {
5556
- disposable2.abortable(() => this.remove(disposable2));
5557
- }
5558
- }
5559
- }
5560
- return disposable;
5561
- },
5562
- make(executor) {
5563
- const disposable = executor();
5564
- if (disposable) {
5565
- return this.add(disposable);
5566
- }
5567
- },
5568
- remove(disposable) {
5569
- return this._d.delete(disposable);
5570
- },
5571
- flush(disposable) {
5572
- if (disposable) {
5573
- if (this.remove(disposable)) {
5574
- dispose(disposable);
5575
- }
5576
- } else {
5577
- this.dispose();
5578
- }
5543
+ }
5544
+ var isAbortable = (disposable) => isDisposable(disposable) && isFn(disposable.abortable);
5545
+ function disposableStore(disposables) {
5546
+ function disposableStore2() {
5547
+ var _a, _b;
5548
+ if (disposableStore2._i)
5549
+ return;
5550
+ disposableStore2._i = 1;
5551
+ (_a = disposableStore2._d) == null ? void 0 : _a.forEach(dispose);
5552
+ (_b = disposableStore2._d) == null ? void 0 : _b.clear();
5553
+ disposableStore2._i = 0;
5579
5554
  }
5580
- };
5581
- var disposableStore = (disposables) => {
5582
- const disposableStore2 = () => {
5583
- disposableStore2._d.forEach(dispose);
5584
- disposableStore2._d.clear();
5585
- };
5586
- disposableStore2._d = /* @__PURE__ */ new Set();
5555
+ disposableStore2._i = 0;
5587
5556
  disposableStore2.dispose = disposableStore2;
5588
- const store = Object.assign(disposableStore2, methods);
5589
- if (disposables) {
5590
- store.add(disposables);
5557
+ disposableStore2.size = size2;
5558
+ disposableStore2.has = has2;
5559
+ disposableStore2.add = add;
5560
+ disposableStore2.make = make3;
5561
+ disposableStore2.remove = remove3;
5562
+ disposableStore2.flush = flush2;
5563
+ return disposableStore2;
5564
+ }
5565
+ function _addOne(disposable) {
5566
+ var _a, _b;
5567
+ if (!((_a = this._d) == null ? void 0 : _a.has(disposable))) {
5568
+ ((_b = this._d) != null ? _b : this._d = /* @__PURE__ */ new Set()).add(disposable);
5569
+ if (isAbortable(disposable)) {
5570
+ disposable.abortable(() => this.remove(disposable));
5571
+ }
5591
5572
  }
5592
- return store;
5593
- };
5573
+ }
5574
+ function add(disposables) {
5575
+ Array.isArray(disposables) ? disposables.forEach(_addOne, this) : _addOne.call(this, disposables);
5576
+ return disposables;
5577
+ }
5578
+ function flush2(disposable) {
5579
+ if (disposable) {
5580
+ if (this.remove(disposable)) {
5581
+ dispose(disposable);
5582
+ }
5583
+ } else {
5584
+ this.dispose();
5585
+ }
5586
+ }
5587
+ function has2(disposable) {
5588
+ var _a;
5589
+ return ((_a = this._d) == null ? void 0 : _a.has(disposable)) || false;
5590
+ }
5591
+ function make3(executor) {
5592
+ const disposable = executor();
5593
+ return disposable && this.add(disposable);
5594
+ }
5595
+ function remove3(disposable) {
5596
+ var _a;
5597
+ return ((_a = this._d) == null ? void 0 : _a.delete(disposable)) || false;
5598
+ }
5599
+ function size2() {
5600
+ var _a;
5601
+ return ((_a = this._d) == null ? void 0 : _a.size) || 0;
5602
+ }
5594
5603
 
5595
5604
  // node_modules/.pnpm/@wopjs+dom@0.1.3/node_modules/@wopjs/dom/dist/index.js
5596
5605
  function addEventListener(target, type, listener, options) {
@@ -6457,9 +6466,6 @@ var Presentation = class {
6457
6466
  this.contentDOM.className = this.c("content");
6458
6467
  this.previewDOM = document.createElement("div");
6459
6468
  this.previewDOM.className = this.c("preview");
6460
- this.imageDOM = document.createElement("div");
6461
- this.imageDOM.className = this.c("image");
6462
- this.image = document.createElement("img");
6463
6469
  this.whiteboardDOM = document.createElement("div");
6464
6470
  this.whiteboardDOM.className = this.c("wb-view");
6465
6471
  this.footerDOM = document.createElement("div");
@@ -6529,8 +6535,6 @@ var Presentation = class {
6529
6535
  this.togglePreview(false);
6530
6536
  }
6531
6537
  }));
6532
- this.imageDOM.appendChild(this.image);
6533
- this.contentDOM.appendChild(this.imageDOM);
6534
6538
  this.updateImage();
6535
6539
  this.contentDOM.appendChild(this.whiteboardDOM);
6536
6540
  this.footerDOM.classList.toggle(this.c("readonly"), this.readonly);
@@ -6839,17 +6843,22 @@ var Scrollbar = class {
6839
6843
  return;
6840
6844
  const { scale, centerX, centerY } = this.view.camera;
6841
6845
  const originScale = this.option.getOriginScale();
6842
- const ratio = Math.round(originScale / scale * 1e3) / 1e3;
6843
- const scrollX = Math.round(centerX * originScale);
6844
- const scrollY = Math.round(centerY * originScale);
6846
+ const { width: pageWidth, height: pageHeight } = this.option.getPageSize();
6847
+ const { width: viewWidth, height: viewHeight } = this.view.size;
6848
+ const originScaleX = viewWidth / pageWidth;
6849
+ const originScaleY = viewHeight / pageHeight;
6850
+ const ratioX = Math.min(Math.round(originScaleX / scale * 100) / 100, 1);
6851
+ const ratioY = Math.min(Math.round(originScaleY / scale * 100) / 100, 1);
6852
+ const scrollX = Math.round(centerX * originScaleX);
6853
+ const scrollY = Math.round(centerY * originScaleY);
6845
6854
  if (this.scrollbarX) {
6846
- this.scrollbarX.style.width = `${ratio * 100}%`;
6847
- this.scrollbarX.style.display = ratio === 1 ? "none" : "block";
6855
+ this.scrollbarX.style.width = `${ratioX * 100}%`;
6856
+ this.scrollbarX.style.display = ratioX === 1 ? "none" : "block";
6848
6857
  this.scrollbarX.style.transform = `translateX(${scrollX}px)`;
6849
6858
  }
6850
6859
  if (this.scrollbarY) {
6851
- this.scrollbarY.style.height = `${ratio * 100}%`;
6852
- this.scrollbarY.style.display = ratio === 1 ? "none" : "block";
6860
+ this.scrollbarY.style.height = `${ratioY * 100}%`;
6861
+ this.scrollbarY.style.display = ratioY === 1 ? "none" : "block";
6853
6862
  this.scrollbarY.style.transform = `translateY(${scrollY}px)`;
6854
6863
  }
6855
6864
  (_b = (_a = this.option.scrollbarEventCallback) == null ? void 0 : _a.onScrollCameraUpdated) == null ? void 0 : _b.call(_a, this.appId, originScale, scale);
@@ -6868,9 +6877,11 @@ var Scrollbar = class {
6868
6877
  var _a, _b;
6869
6878
  if (this.cameraCache) {
6870
6879
  const { x } = transformedDrag;
6871
- const originScale = this.option.getOriginScale();
6880
+ const { width: pageWidth } = this.option.getPageSize();
6881
+ const { width: viewWidth } = this.view.size;
6882
+ const originScaleX = viewWidth / pageWidth;
6872
6883
  const { minX, maxX } = this.getScrollXRange(this.cameraCache);
6873
- const scrollX = Math.round(x / originScale);
6884
+ const scrollX = Math.round(x / originScaleX);
6874
6885
  let centerX = scrollX + this.cameraCache.centerX;
6875
6886
  if (centerX < minX) {
6876
6887
  centerX = minX;
@@ -6888,9 +6899,11 @@ var Scrollbar = class {
6888
6899
  var _a, _b;
6889
6900
  if (this.cameraCache) {
6890
6901
  const { y } = transformedDrag;
6891
- const originScale = this.option.getOriginScale();
6902
+ const { height: pageHeight } = this.option.getPageSize();
6903
+ const { height: viewHeight } = this.view.size;
6904
+ const originScaleY = viewHeight / pageHeight;
6892
6905
  const { minY, maxY } = this.getScrollYRange(this.cameraCache);
6893
- const scrollY = Math.round(y / originScale);
6906
+ const scrollY = Math.round(y / originScaleY);
6894
6907
  let centerY = scrollY + this.cameraCache.centerY;
6895
6908
  if (centerY < minY) {
6896
6909
  centerY = minY;
@@ -6910,6 +6923,35 @@ var Scrollbar = class {
6910
6923
  this.option.syncView();
6911
6924
  (_b = (_a = this.option.scrollbarEventCallback) == null ? void 0 : _a.onScrollbarDragEnd) == null ? void 0 : _b.call(_a);
6912
6925
  };
6926
+ this.moveCamera = (camera) => {
6927
+ const { centerX, centerY } = camera;
6928
+ const cacheCamera = this.view.camera;
6929
+ const _camera = {};
6930
+ if ((0, import_lodash.isNumber)(centerX)) {
6931
+ const { minX, maxX } = this.getScrollXRange(cacheCamera);
6932
+ let newCenterX = centerX;
6933
+ if (centerX < minX) {
6934
+ newCenterX = minX;
6935
+ } else if (centerX > maxX) {
6936
+ newCenterX = maxX;
6937
+ }
6938
+ _camera.centerX = newCenterX;
6939
+ }
6940
+ if ((0, import_lodash.isNumber)(centerY)) {
6941
+ const { minY, maxY } = this.getScrollYRange(cacheCamera);
6942
+ let newCenterY = centerY;
6943
+ if (centerY < minY) {
6944
+ newCenterY = minY;
6945
+ } else if (centerY > maxY) {
6946
+ newCenterY = maxY;
6947
+ }
6948
+ _camera.centerY = newCenterY;
6949
+ }
6950
+ this.view.moveCamera(__spreadProps(__spreadValues({}, _camera), {
6951
+ animationMode: "immediately"
6952
+ }));
6953
+ this.option.syncView();
6954
+ };
6913
6955
  this.scrollContainer.className = this.c("scrollbar-container");
6914
6956
  this.container = container;
6915
6957
  this.option = option;
@@ -6929,21 +6971,23 @@ var Scrollbar = class {
6929
6971
  }
6930
6972
  }
6931
6973
  getScrollXRange(camera) {
6932
- const { width } = this.option.getPageSize();
6933
- const originScale = this.option.getOriginScale();
6974
+ const { width: pageWidth } = this.option.getPageSize();
6975
+ const { width: viewWidth } = this.view.size;
6976
+ const originScaleX = viewWidth / pageWidth;
6934
6977
  const scale = camera.scale;
6935
- const ratio = Math.round(originScale / scale * 1e3) / 1e3;
6936
- const scrollWidth = width * (1 - ratio);
6978
+ const ratio = Math.min(Math.round(originScaleX / scale * 100) / 100, 1);
6979
+ const scrollWidth = pageWidth * (1 - ratio);
6937
6980
  const minX = -scrollWidth / 2;
6938
6981
  const maxX = scrollWidth / 2;
6939
6982
  return { minX, maxX };
6940
6983
  }
6941
6984
  getScrollYRange(camera) {
6942
- const { height } = this.option.getPageSize();
6943
- const originScale = this.option.getOriginScale();
6985
+ const { height: pageHeight } = this.option.getPageSize();
6986
+ const { height: viewHeight } = this.view.size;
6987
+ const originScaleY = viewHeight / pageHeight;
6944
6988
  const scale = camera.scale;
6945
- const ratio = Math.round(originScale / scale * 1e3) / 1e3;
6946
- const scrollHeight = height * (1 - ratio);
6989
+ const ratio = Math.min(Math.round(originScaleY / scale * 100) / 100, 1);
6990
+ const scrollHeight = pageHeight * (1 - ratio);
6947
6991
  const minY = -scrollHeight / 2;
6948
6992
  const maxY = scrollHeight / 2;
6949
6993
  return { minY, maxY };
@@ -7014,6 +7058,7 @@ var Scrollbar = class {
7014
7058
  };
7015
7059
 
7016
7060
  // src/app-presentation.ts
7061
+ var import_lodash2 = __toESM(require_lodash());
7017
7062
  var emptySceneName = "$$empty$$";
7018
7063
  var ppt2page = (ppt, name) => ppt ? { width: ppt.width, height: ppt.height, src: ppt.src, thumbnail: ppt.previewURL, name } : null;
7019
7064
  var createLogger = (room) => {
@@ -7095,9 +7140,9 @@ var NetlessAppPresentation = {
7095
7140
  if (pages.length > 100)
7096
7141
  console.warn(`[Presentation]: too many pages (${pages.length}), may cause performance issues`);
7097
7142
  let redirectResolve = void 0;
7098
- const room = context.getRoom();
7099
- if (room && room.isWritable) {
7100
- const scenes = room.entireScenes()[scenePath];
7143
+ const room2 = context.getRoom();
7144
+ if (room2 && room2.isWritable) {
7145
+ const scenes = room2.entireScenes()[scenePath];
7101
7146
  if (pageIndex$.value < 0 || pageIndex$.value >= pages.length) {
7102
7147
  throw new Error(`[Presentation] Invalid page index: ${pageIndex$.value}, scenes length: ${pages.length}`);
7103
7148
  }
@@ -7112,8 +7157,8 @@ var NetlessAppPresentation = {
7112
7157
  };
7113
7158
  });
7114
7159
  if (!scenesEqual(scenes, _scenes)) {
7115
- room.removeScenes(scenePath);
7116
- room.putScenes(scenePath, _scenes);
7160
+ room2.removeScenes(scenePath);
7161
+ room2.putScenes(scenePath, _scenes);
7117
7162
  }
7118
7163
  if (name === _scenes[pageIndex$.value].name && !ppt) {
7119
7164
  context.addPage({ scene: { name: emptySceneName } }).then(() => {
@@ -7126,10 +7171,10 @@ var NetlessAppPresentation = {
7126
7171
  redirectResolve && redirectResolve(false);
7127
7172
  }
7128
7173
  }).then(async (bol) => {
7129
- await syncPage(pageIndex$.value, room.logger);
7174
+ await syncPage(pageIndex$.value, room2.logger);
7130
7175
  if (bol) {
7131
7176
  log(`[Presentation] setup removeScenes ${scenePath}/${emptySceneName}`);
7132
- room.removeScenes(`${scenePath}/${emptySceneName}`);
7177
+ room2.removeScenes(`${scenePath}/${emptySceneName}`);
7133
7178
  }
7134
7179
  });
7135
7180
  }
@@ -7244,14 +7289,32 @@ var NetlessAppPresentation = {
7244
7289
  }
7245
7290
  };
7246
7291
  dispose2.add(view$$.addStateChangedListener(() => syncViewFromRemote(false, true)));
7292
+ const getPageSize = () => {
7293
+ const { width, height } = app.page() || {};
7294
+ return { width: width || 0, height: height || 0 };
7295
+ };
7247
7296
  const box = context.getBox();
7248
- const app = dispose2.add(createPresentation(box, pages, jumpPage, pageIndex$, options.thumbnail));
7249
- app.contentDOM.dataset.appPresentationVersion = "0.1.9-beta.5";
7297
+ const app = dispose2.add(createPresentation(box, pages, jumpPage, pageIndex$, view, options.thumbnail, options.useClipView));
7298
+ app.contentDOM.dataset.appPresentationVersion = "0.1.9-beta.7";
7250
7299
  app.scaleDocsToFit = scaleDocsToFit;
7251
7300
  app.log = log;
7252
7301
  if (options.justDocsViewReadonly) {
7253
7302
  app.setDocsViewReadonly(true);
7254
7303
  }
7304
+ const room = context.getRoom();
7305
+ const goToPageByClick = () => {
7306
+ var _a2, _b2, _c2, _d;
7307
+ 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 : "";
7308
+ if (!app.readonly && currentApplianceName === "clicker") {
7309
+ nextPage();
7310
+ }
7311
+ };
7312
+ if (room && options.goToPageByClick && app.whiteboardDOM) {
7313
+ dispose2.make(() => {
7314
+ app.whiteboardDOM.addEventListener("click", goToPageByClick);
7315
+ return () => app.whiteboardDOM.removeEventListener("click", goToPageByClick);
7316
+ });
7317
+ }
7255
7318
  context.mountView(app.whiteboardDOM);
7256
7319
  if (options.disableCameraTransform) {
7257
7320
  view.disableCameraTransform = true;
@@ -7281,10 +7344,6 @@ var NetlessAppPresentation = {
7281
7344
  dispose2.add(context.emitter.on("writableChange", (isWritable) => {
7282
7345
  app.setReadonly(!isWritable);
7283
7346
  }));
7284
- const getPageSize = () => {
7285
- const { width, height } = app.page() || {};
7286
- return { width: width || 0, height: height || 0 };
7287
- };
7288
7347
  const getOriginScale = () => {
7289
7348
  const { size } = view;
7290
7349
  const { width, height } = getPageSize();
@@ -7293,13 +7352,41 @@ var NetlessAppPresentation = {
7293
7352
  const getScale = () => {
7294
7353
  return view.camera.scale;
7295
7354
  };
7296
- const moveCamera = (camera) => {
7297
- if (context.getIsWritable()) {
7298
- view.moveCamera(__spreadProps(__spreadValues({}, camera), { animationMode: "immediately" }));
7299
- syncView();
7300
- return;
7355
+ const screenshotCurrentPageAsync = async (_context, _width, _height) => {
7356
+ var _a2, _b2;
7357
+ (_b2 = (_a2 = room == null ? void 0 : room.calibrationTimestamp) == null ? void 0 : _a2.toString()) != null ? _b2 : Date.now().toString();
7358
+ const currentPage = pages[pageIndex$.value];
7359
+ if (!currentPage) {
7360
+ throw new Error("[Presentation]: current page not found");
7361
+ }
7362
+ const { width, height, src } = currentPage;
7363
+ const img = document.createElement("img");
7364
+ img.width = width;
7365
+ img.height = height;
7366
+ img.crossOrigin = "Anonymous";
7367
+ await new Promise((resolve) => {
7368
+ img.onload = resolve;
7369
+ img.src = src;
7370
+ });
7371
+ _context.drawImage(img, 0, 0, width, height, 0, 0, _width || width, _height || height);
7372
+ const currentScenePath = view.focusScenePath;
7373
+ if (!currentScenePath) {
7374
+ throw new Error("[Presentation]: current scene path not found");
7375
+ }
7376
+ const windowManger = context.getWindowManager();
7377
+ if (windowManger._appliancePlugin) {
7378
+ await windowManger._appliancePlugin.screenshotToCanvasAsync(_context, currentScenePath, _width || width, _height || height, {
7379
+ centerX: 0,
7380
+ centerY: 0,
7381
+ scale: _width && _height ? Math.min(_width / width, _height / height) : 1
7382
+ });
7383
+ } else {
7384
+ await view.screenshotToCanvasAsync(_context, currentScenePath, _width || width, _height || height, {
7385
+ centerX: 0,
7386
+ centerY: 0,
7387
+ scale: _width && _height ? Math.min(_width / width, _height / height) : 1
7388
+ });
7301
7389
  }
7302
- throw new Error("[Presentation]: moveCamera must be called in writable room");
7303
7390
  };
7304
7391
  let scrollbar;
7305
7392
  if (options.useScrollbar) {
@@ -7315,6 +7402,16 @@ var NetlessAppPresentation = {
7315
7402
  return () => scrollbar == null ? void 0 : scrollbar.destroy();
7316
7403
  });
7317
7404
  }
7405
+ const moveCamera = (camera) => {
7406
+ if (context.getIsWritable() && scrollbar) {
7407
+ if (!scrollbar) {
7408
+ throw new Error("[Presentation]: moveCamera must be called when appOptions: useScrollbar is true");
7409
+ }
7410
+ scrollbar.moveCamera(camera);
7411
+ return;
7412
+ }
7413
+ throw new Error("[Presentation]: moveCamera must be called in writable room");
7414
+ };
7318
7415
  context.emitter.on("destroy", () => dispose2());
7319
7416
  const reportProgress = (progress, result) => {
7320
7417
  window.postMessage({ type: "@netless/_result_save_pdf_", appId: context.appId, progress, result }, "*");
@@ -7383,12 +7480,12 @@ var NetlessAppPresentation = {
7383
7480
  const name = (_a2 = p.name) != null ? _a2 : String(index + 1);
7384
7481
  if (scenes.some((scene) => scene.name == name)) {
7385
7482
  const camera = { centerX: 0, centerY: 0, scale: Math.min(wb_canvas.width / width2, wb_canvas.height / height2) };
7386
- const sPath = `${scenePath}/${index + 1}`;
7387
- const windowManger = context.manager.windowManger;
7483
+ const sPath = `${scenePath}/${name}`;
7484
+ const windowManger = context.getWindowManager();
7388
7485
  if (windowManger._appliancePlugin) {
7389
7486
  await windowManger._appliancePlugin.screenshotToCanvasAsync(wb, sPath, wb_canvas.width, wb_canvas.height, camera);
7390
7487
  } else {
7391
- view.screenshotToCanvas(
7488
+ await view.screenshotToCanvasAsync(
7392
7489
  wb,
7393
7490
  sPath,
7394
7491
  wb_canvas.width,
@@ -7434,11 +7531,12 @@ var NetlessAppPresentation = {
7434
7531
  };
7435
7532
  const setReadonly = (bol) => {
7436
7533
  app.setReadonly(bol);
7534
+ if (options.goToPageByClick) ;
7437
7535
  if (scrollbar) {
7438
7536
  scrollbar.setReadonly(bol);
7439
7537
  }
7440
7538
  };
7441
- const controller = { app, view, context, jumpPage, prevPage, nextPage, pageState, toPdf, log, setDocsViewReadonly, setReadonly, moveCamera, getOriginScale, getScale };
7539
+ const controller = { app, view, context, jumpPage, prevPage, nextPage, pageState, toPdf, log, setDocsViewReadonly, setReadonly, moveCamera, getOriginScale, getScale, getPageSize, screenshotCurrentPageAsync };
7442
7540
  dispose2.add(listen(window, "message", (ev) => {
7443
7541
  if (ev.data === "@netless/_presentation_") {
7444
7542
  if (typeof window !== "undefined")
@@ -7457,7 +7555,6 @@ var AppPresentation = class extends Presentation {
7457
7555
  constructor(config) {
7458
7556
  super(config);
7459
7557
  this.jumpPage = config.jumpPage;
7460
- this.image.style.display = "none";
7461
7558
  }
7462
7559
  updateImage() {
7463
7560
  super.updateImage();
@@ -7474,7 +7571,7 @@ var AppPresentation = class extends Presentation {
7474
7571
  }
7475
7572
  }
7476
7573
  };
7477
- function createPresentation(box, pages, jumpPage, pageIndex$, thumbnail) {
7574
+ function createPresentation(box, pages, jumpPage, pageIndex$, view, thumbnail, useClipView) {
7478
7575
  box.mountStyles(style_default);
7479
7576
  const app = new AppPresentation({ pages, readonly: box.readonly, jumpPage, thumbnail });
7480
7577
  app.box = box;
@@ -7483,6 +7580,29 @@ function createPresentation(box, pages, jumpPage, pageIndex$, thumbnail) {
7483
7580
  app.dispose.add(pageIndex$.subscribe((pageIndex) => {
7484
7581
  app.setPageIndex(pageIndex);
7485
7582
  }));
7583
+ if (useClipView && view) {
7584
+ const onCameraUpdatedEffectForMaskView = (0, import_lodash2.debounce)(() => {
7585
+ const { width: pageWidth, height: pageHeight } = app.page() || {};
7586
+ if (!pageWidth || !pageHeight) {
7587
+ return;
7588
+ }
7589
+ const { scale } = view.camera;
7590
+ const { width, height } = view.size;
7591
+ const pageRatioX = Math.round((1 - pageWidth * scale / width) / 2 * 100);
7592
+ const pageRatioY = Math.round((1 - pageHeight * scale / height) / 2 * 100);
7593
+ app.whiteboardDOM.style.clipPath = `inset(${pageRatioY}% ${pageRatioX}%)`;
7594
+ }, 50);
7595
+ onCameraUpdatedEffectForMaskView();
7596
+ const onCameraUpdatedEffect = () => {
7597
+ view.callbacks.on("onSizeUpdated", onCameraUpdatedEffectForMaskView);
7598
+ view.callbacks.on("onCameraUpdated", onCameraUpdatedEffectForMaskView);
7599
+ return () => {
7600
+ view.callbacks.off("onCameraUpdated", onCameraUpdatedEffectForMaskView);
7601
+ view.callbacks.off("onSizeUpdated", onCameraUpdatedEffectForMaskView);
7602
+ };
7603
+ };
7604
+ app.dispose.make(onCameraUpdatedEffect);
7605
+ }
7486
7606
  return app;
7487
7607
  }
7488
7608
  var install = (register, options = {}) => {
@@ -7494,7 +7614,7 @@ var install = (register, options = {}) => {
7494
7614
  };
7495
7615
 
7496
7616
  // src/index.ts
7497
- var version = "0.1.9-beta.5";
7617
+ var version = "0.1.9-beta.7";
7498
7618
  /*! Bundled license information:
7499
7619
 
7500
7620
  lodash/lodash.js:
@@ -7510,8 +7630,8 @@ lodash/lodash.js:
7510
7630
 
7511
7631
  exports.NetlessAppPresentation = NetlessAppPresentation;
7512
7632
  exports.Presentation = Presentation;
7633
+ exports.Scrollbar = Scrollbar;
7513
7634
  exports.default = NetlessAppPresentation;
7514
7635
  exports.install = install;
7515
- exports.styles = style_default;
7516
7636
  exports.version = version;
7517
7637
  //# sourceMappingURL=index.js.map