@netless/app-presentation 0.1.7 → 0.1.8-beta.1

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
@@ -790,127 +790,98 @@ function arrowRightSVG(namespace) {
790
790
  var _Preload = class _Preload {
791
791
  constructor(pages) {
792
792
  this.pages = pages;
793
+ // 正在加载的链接
793
794
  this.loadingLinks = /* @__PURE__ */ new Map();
795
+ // 需要预加载的链接集合
794
796
  this.preloadMap = /* @__PURE__ */ new Map();
795
- this.waitingLoadSet = /* @__PURE__ */ new Set();
796
- this.waitinglinks = [];
797
+ // 当前触摸的索引
797
798
  this.touchIndex = 0;
798
799
  this.preloadSize = 0;
799
800
  this.preloadMap = new Map(pages.map((e, index) => [index, {
800
801
  src: e.src,
801
802
  state: 0 /* unloaded */
802
803
  }]));
803
- this.waitingLoadSet = new Set(pages.map((e, index) => index));
804
804
  this.preloadSize = this.preloadMap.size;
805
- this.touch(0);
805
+ this.touch(0, true);
806
806
  }
807
- async touch(index) {
808
- this.touchIndex = index;
809
- const value = this.preloadMap.get(index);
810
- let state = 0 /* unloaded */;
811
- if (value) {
812
- state = value.state;
813
- if (value.state === 0 /* unloaded */) {
814
- if (this.loadingLinks.size) {
815
- for (const [i, link] of this.loadingLinks) {
816
- this.destroyLink(i, link);
817
- this.waitingLoadSet.add(i);
818
- const v = this.preloadMap.get(i);
819
- if (v) {
820
- v.state = 0 /* unloaded */;
821
- this.preloadMap.set(i, v);
822
- }
823
- }
824
- for (const i of this.waitinglinks) {
825
- this.waitingLoadSet.add(i);
826
- }
827
- this.waitinglinks.length = 0;
828
- }
829
- if (this.waitinglinks.includes(index)) {
830
- this.waitinglinks.splice(this.waitinglinks.indexOf(index), 1);
831
- }
832
- state = await new Promise((resolve) => {
833
- this.waitingLoadSet.delete(index);
834
- this.createLink(index, resolve);
835
- });
836
- }
837
- }
838
- if (this.waitingLoadSet.size) {
839
- this.requestAsyncCallBack(() => {
840
- this.autoTouch();
841
- }, 1e3);
842
- }
843
- return state;
844
- }
845
- autoTouch() {
846
- this.handler();
847
- if (this.waitingLoadSet.size === 0) {
848
- return;
807
+ touch(index, force = false) {
808
+ if (index >= this.preloadSize) {
809
+ this.touchIndex = 0;
810
+ } else {
811
+ this.touchIndex = index;
849
812
  }
850
- let nextTouchDelay = 1e3;
851
- this.touchIndex = (this.touchIndex + 1) % this.preloadSize;
852
813
  const value = this.preloadMap.get(this.touchIndex);
853
- if (value) {
854
- switch (value.state) {
855
- case 0 /* unloaded */:
856
- case 3 /* error */:
857
- if (!this.waitinglinks.includes(this.touchIndex)) {
858
- this.waitinglinks.push(this.touchIndex);
859
- this.waitingLoadSet.delete(this.touchIndex);
860
- }
861
- nextTouchDelay = 0;
862
- break;
814
+ if (value && value.state === 0 /* unloaded */) {
815
+ this.createLink(this.touchIndex, force);
816
+ }
817
+ if (this.loadingLinks.size < _Preload.maxLinks) {
818
+ const willLoad = [...this.preloadMap.entries()].find(([i, e]) => i > this.touchIndex && e.state !== 1 /* loaded */);
819
+ if (willLoad) {
820
+ this.requestAsyncCallBack(() => {
821
+ this.touch(willLoad[0], false);
822
+ }, 100);
863
823
  }
864
824
  }
865
- this.requestAsyncCallBack(() => {
866
- this.autoTouch();
867
- }, nextTouchDelay);
868
825
  }
869
- createLink(index, resolve) {
826
+ createLink(index, force = false) {
870
827
  const value = this.preloadMap.get(index);
828
+ if (force) {
829
+ this.destroySomeLink(index);
830
+ }
871
831
  if (value) {
872
- const link = document.createElement("link");
873
- link.rel = "preload";
874
- link.as = "image";
875
- link.href = value.src;
876
- link.dataset.order = index + "";
877
- document.head.appendChild(link);
878
- link.onload = () => {
879
- value.state = 2 /* loaded */;
880
- this.preloadMap.set(index, value);
881
- document.head.contains(link) && document.head.removeChild(link);
882
- this.loadingLinks.delete(index);
883
- resolve && resolve(2 /* loaded */);
884
- this.autoTouch();
832
+ if (value.state === 1 /* loaded */) {
833
+ return 1 /* loaded */;
834
+ }
835
+ const curlink = this.loadingLinks.get(index);
836
+ if (curlink) {
837
+ if (curlink.isForce !== force) {
838
+ curlink.isForce = force;
839
+ this.loadingLinks.set(index, curlink);
840
+ }
841
+ return 0 /* unloaded */;
842
+ }
843
+ if (this.loadingLinks.size > _Preload.maxLinks) {
844
+ return 0 /* unloaded */;
845
+ }
846
+ const linkDom = document.createElement("link");
847
+ linkDom.rel = "preload";
848
+ linkDom.as = "image";
849
+ linkDom.href = value.src;
850
+ linkDom.dataset.order = index + "";
851
+ document.head.appendChild(linkDom);
852
+ linkDom.onload = () => {
853
+ const value2 = this.preloadMap.get(index);
854
+ if (value2) {
855
+ value2.state = 1 /* loaded */;
856
+ this.preloadMap.set(index, value2);
857
+ document.head.contains(linkDom) && document.head.removeChild(linkDom);
858
+ this.loadingLinks.delete(index);
859
+ this.touch(this.touchIndex + 1, false);
860
+ }
885
861
  };
886
- link.onerror = () => {
887
- value.state = 3 /* error */;
888
- this.preloadMap.set(index, value);
889
- if (!this.waitinglinks.includes(index)) {
890
- this.waitinglinks.push(index);
891
- this.waitingLoadSet.delete(this.touchIndex);
862
+ linkDom.onerror = () => {
863
+ const value2 = this.preloadMap.get(index);
864
+ if (value2 == null ? void 0 : value2.src) {
865
+ linkDom.href = value2.src;
892
866
  }
893
- document.head.contains(link) && document.head.removeChild(link);
894
- this.loadingLinks.delete(index);
895
- resolve && resolve(3 /* error */);
896
- this.autoTouch();
897
867
  };
898
- this.loadingLinks.set(index, link);
899
- value.state = 1 /* loading */;
868
+ this.loadingLinks.set(index, {
869
+ link: linkDom,
870
+ isForce: force
871
+ });
872
+ value.state = 0 /* unloaded */;
900
873
  this.preloadMap.set(index, value);
874
+ return 0 /* unloaded */;
901
875
  }
876
+ return 2 /* error */;
902
877
  }
903
- handler() {
904
- if (!this.waitinglinks.length) {
905
- return;
906
- }
907
- let i = this.loadingLinks.size;
908
- while (i < _Preload.maxLinks) {
909
- const index = this.waitinglinks.shift();
910
- if (index !== void 0) {
911
- this.createLink(index);
878
+ destroySomeLink(excludeIndex) {
879
+ for (const [index, { link }] of this.loadingLinks) {
880
+ if (excludeIndex !== void 0 && index === excludeIndex) {
881
+ continue;
912
882
  }
913
- i++;
883
+ document.head.contains(link) && document.head.removeChild(link);
884
+ this.loadingLinks.delete(index);
914
885
  }
915
886
  }
916
887
  async requestAsyncCallBack(callBack, timeout) {
@@ -927,17 +898,9 @@ var _Preload = class _Preload {
927
898
  });
928
899
  callBack();
929
900
  }
930
- destroyLink(index, link) {
931
- document.head.contains(link) && document.head.removeChild(link);
932
- this.loadingLinks.delete(index);
933
- }
934
901
  dispose() {
935
- for (const [index, link] of this.loadingLinks) {
936
- this.destroyLink(index, link);
937
- }
902
+ this.destroySomeLink();
938
903
  this.preloadMap.clear();
939
- this.waitingLoadSet.clear();
940
- this.waitinglinks.length = 0;
941
904
  }
942
905
  };
943
906
  _Preload.maxLinks = 5;
@@ -1164,16 +1127,7 @@ var Presentation = class {
1164
1127
  }
1165
1128
  this.timer = setTimeout(() => {
1166
1129
  this.timer = null;
1167
- this.preload.touch(this.pageIndex).then(() => {
1168
- const page = this.page();
1169
- if (!page) {
1170
- this.image.src = "";
1171
- return;
1172
- }
1173
- this.image.width = page.width;
1174
- this.image.height = page.height;
1175
- this.image.src = page.src;
1176
- });
1130
+ this.preload.touch(this.pageIndex, true);
1177
1131
  }, 200);
1178
1132
  }
1179
1133
  /** Returns a modified URL that points to the thumbnail image. */
@@ -1201,7 +1155,77 @@ var Presentation = class {
1201
1155
  // src/style.scss?inline
1202
1156
  var style_default = ".netless-app-presentation{height:100%;display:flex;flex-flow:column nowrap}.netless-app-presentation-content{position:relative;height:100%;overflow:hidden}.netless-app-presentation-preview-mask{display:none;position:absolute;z-index:200;top:0;left:0;width:100%;height:100%}.netless-app-presentation-preview{display:flex;flex-direction:column;align-items:center;position:absolute;z-index:300;top:0;left:0;width:33%;max-width:200px;height:100%;padding-top:10px;transform:translate(-100%);background:#ededf0e6;box-shadow:inset -1px 0 #0000001c;transition:transform .4s;overflow:auto;overflow-y:scroll}.netless-app-presentation-preview-active .netless-app-presentation-preview-mask{display:block}.netless-app-presentation-preview-active .netless-app-presentation-preview{transform:translate(0)}.netless-app-presentation-preview-page{position:relative;display:block;width:55%;margin-bottom:10px;font-size:0;color:#0000;outline:none;border:7px solid rgba(0,0,0,0);border-radius:4px;transition:border-color .3s;user-select:none}.netless-app-presentation-preview-page:hover,.netless-app-presentation-preview-page.netless-app-presentation-preview-page-active{border-color:#444e601a}.netless-app-presentation-preview-page>img{width:100%;height:auto;box-sizing:border-box;border:1px solid rgba(0,0,0,.5);border-radius:1px;background-color:#fff;box-shadow:0 2px 8px #0000004d}.netless-app-presentation-preview-page-name{position:absolute;top:1px;left:-10px;transform:translate(-100%);text-align:right;font-size:12px;color:#5f5f5f;user-select:none}.netless-app-presentation-footer{box-sizing:border-box;height:26px;display:flex;align-items:center;padding:0 16px;border-top:1px solid #eeeef7;color:#191919}.netless-app-presentation-float-footer{width:100%;min-height:26px;position:absolute;left:0;bottom:0;z-index:2000;background:#f9f9fce6;transition:opacity .4s}.netless-app-presentation-footer-btn{box-sizing:border-box;width:26px;height:26px;font-size:0;margin:0;padding:3px;border:none;border-radius:1px;outline:none;color:currentColor;background:#0000;transition:background .4s;cursor:pointer;user-select:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-presentation-footer-btn:hover{background:#ededf0e6}@media (hover: none){.netless-app-presentation-footer-btn:hover{background:#0000!important}}.netless-app-presentation-footer-btn>svg{width:100%;height:100%}.netless-app-presentation-footer-btn>svg:nth-of-type(2){display:none}.netless-app-presentation-footer-btn.netless-app-presentation-footer-btn-playing>svg:nth-of-type(1){display:none}.netless-app-presentation-footer-btn.netless-app-presentation-footer-btn-playing>svg:nth-of-type(2){display:initial}.netless-app-presentation-footer-btn~.netless-app-presentation-footer-btn{margin-left:15px}.netless-app-presentation-page-jumps{flex:1;display:flex;justify-content:center;align-items:center}.netless-app-presentation-page-number{margin-left:auto;font-size:13px;user-select:none;white-space:nowrap;word-break:keep-all}.netless-app-presentation-page-number-input{border:none;outline:none;width:3em;margin:0;padding:0 2px;text-align:right;font-size:13px;line-height:1;font-weight:400;font-family:inherit;border-radius:2px;color:currentColor;background:#0000;transition:background .4s;user-select:text;-webkit-tap-highlight-color:rgba(0,0,0,0)}.netless-app-presentation-page-number-input:hover,.netless-app-presentation-page-number-input:focus,.netless-app-presentation-page-number-input:active{background:#fff;box-shadow:#63636333 0 2px 8px}.netless-app-presentation-readonly.netless-app-presentation-footer{display:none}.netless-app-presentation-wb-view{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;overflow:hidden;transition:opacity .2s}.netless-app-presentation-image{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.netless-app-presentation-image>img{max-width:100%;max-height:100%;object-fit:contain}.telebox-color-scheme-dark .netless-app-presentation-page-number-input{color:#a6a6a8}.telebox-color-scheme-dark .netless-app-presentation-page-number-input:active,.telebox-color-scheme-dark .netless-app-presentation-page-number-input:focus,.telebox-color-scheme-dark .netless-app-presentation-page-number-input:hover{color:#222}.telebox-color-scheme-dark .netless-app-presentation-footer{color:#a6a6a8;background:#2d2d33;border-top:none}.telebox-color-scheme-dark .netless-app-presentation-footer-btn:hover{background:#212126}.telebox-color-scheme-dark .netless-app-presentation-preview{background:#323232e6}";
1203
1157
 
1158
+ // src/store.ts
1159
+ function noop() {
1160
+ }
1161
+ function safe_not_equal(a, b) {
1162
+ return a != a ? b == b : a !== b || a && typeof a === "object" || typeof a === "function";
1163
+ }
1164
+ function readable(value, start = noop) {
1165
+ let stop;
1166
+ const subscribers = /* @__PURE__ */ new Set();
1167
+ function set(new_value) {
1168
+ if (safe_not_equal(value, new_value)) {
1169
+ value = new_value;
1170
+ if (stop) {
1171
+ for (const run of subscribers) {
1172
+ run(value);
1173
+ }
1174
+ }
1175
+ }
1176
+ }
1177
+ function subscribe(run) {
1178
+ subscribers.add(run);
1179
+ if (subscribers.size === 1) {
1180
+ stop = start(set) || noop;
1181
+ }
1182
+ run(value);
1183
+ return () => {
1184
+ subscribers.delete(run);
1185
+ if (subscribers.size === 0) {
1186
+ stop && stop();
1187
+ stop = void 0;
1188
+ }
1189
+ };
1190
+ }
1191
+ function reaction(run) {
1192
+ subscribers.add(run);
1193
+ if (subscribers.size === 1) {
1194
+ stop = start(set) || noop;
1195
+ }
1196
+ return () => {
1197
+ subscribers.delete(run);
1198
+ if (subscribers.size === 0) {
1199
+ stop && stop();
1200
+ stop = void 0;
1201
+ }
1202
+ };
1203
+ }
1204
+ function dispose2(new_value) {
1205
+ if (new_value !== void 0) {
1206
+ set(new_value);
1207
+ }
1208
+ subscribers.clear();
1209
+ stop && stop();
1210
+ stop = void 0;
1211
+ }
1212
+ return {
1213
+ get value() {
1214
+ if (subscribers.size === 0) {
1215
+ stop = start(set) || noop;
1216
+ stop();
1217
+ stop = void 0;
1218
+ }
1219
+ return value;
1220
+ },
1221
+ subscribe,
1222
+ reaction,
1223
+ dispose: dispose2
1224
+ };
1225
+ }
1226
+
1204
1227
  // src/app-presentation.ts
1228
+ var emptySceneName = "$$empty$$";
1205
1229
  var ppt2page = (ppt, name) => ppt ? { width: ppt.width, height: ppt.height, src: ppt.src, thumbnail: ppt.previewURL, name } : null;
1206
1230
  var createLogger = (room) => {
1207
1231
  if (room && room.logger) {
@@ -1210,10 +1234,22 @@ var createLogger = (room) => {
1210
1234
  return (...args) => console.log(...args);
1211
1235
  }
1212
1236
  };
1237
+ var scenesEqual = (scenes1, scenes2) => {
1238
+ if (!scenes1 || !scenes2) {
1239
+ return false;
1240
+ }
1241
+ if (scenes1.length !== scenes2.length)
1242
+ return false;
1243
+ return scenes1.every((scene, index) => {
1244
+ var _a, _b, _c, _d, _e, _f;
1245
+ const scene2 = scenes2[index];
1246
+ return scene.name === scene2.name && ((_a = scene.ppt) == null ? void 0 : _a.width) === ((_b = scene2.ppt) == null ? void 0 : _b.width) && ((_c = scene.ppt) == null ? void 0 : _c.height) === ((_d = scene2.ppt) == null ? void 0 : _d.height) && ((_e = scene.ppt) == null ? void 0 : _e.src) === ((_f = scene2.ppt) == null ? void 0 : _f.src);
1247
+ });
1248
+ };
1213
1249
  var NetlessAppPresentation = {
1214
1250
  kind: "Presentation",
1215
1251
  setup(context) {
1216
- var _a, _b, _c, _d, _e;
1252
+ var _a, _b, _c;
1217
1253
  const view = context.getView();
1218
1254
  if (!view)
1219
1255
  throw new Error("[Presentation]: no whiteboard view, make sure you have added options.scenePath in addApp()");
@@ -1231,43 +1267,88 @@ var NetlessAppPresentation = {
1231
1267
  }
1232
1268
  const log = options.log || createLogger(context.getRoom());
1233
1269
  log(`[Presentation] new ${context.appId}`);
1270
+ const dispose2 = disposableStore();
1271
+ dispose2.add(() => log(`[Presentation] dispose ${context.appId}`));
1272
+ const view$$ = context.createStorage("view", { uid: "", originX: 0, originY: 0, width: 0, height: 0 });
1273
+ const _addScenePathListener = (name, listener) => {
1274
+ const windowManger = context.manager.windowManger;
1275
+ windowManger.emitter.on(name, listener);
1276
+ return () => windowManger == null ? void 0 : windowManger.emitter.off(name, listener);
1277
+ };
1278
+ const getPageIndex = (view2) => {
1279
+ const focusScenePath = view2.focusScenePath;
1280
+ const name = focusScenePath == null ? void 0 : focusScenePath.split("/").pop();
1281
+ let _pageIndex = pages.findIndex((page, index) => {
1282
+ var _a2;
1283
+ const n = (_a2 = page.name) != null ? _a2 : String(index + 1);
1284
+ return n === name;
1285
+ });
1286
+ if (_pageIndex === -1) {
1287
+ _pageIndex = 0;
1288
+ }
1289
+ return _pageIndex;
1290
+ };
1291
+ let pageIndex = getPageIndex(view);
1292
+ const pageIndex$ = readable(pageIndex, (set) => {
1293
+ set(pageIndex);
1294
+ return _addScenePathListener("onAppScenePathChange", (payload) => {
1295
+ const { appId } = payload;
1296
+ if (appId === context.appId) {
1297
+ const _pageIndex = getPageIndex(payload.view);
1298
+ set(_pageIndex);
1299
+ }
1300
+ });
1301
+ });
1302
+ dispose2.add(() => {
1303
+ pageIndex$.dispose();
1304
+ });
1234
1305
  if (context.isAddApp) {
1235
1306
  if (pages.length > 100)
1236
1307
  console.warn(`[Presentation]: too many pages (${pages.length}), may cause performance issues`);
1308
+ let redirectResolve = void 0;
1237
1309
  const room = context.getRoom();
1238
1310
  if (room && room.isWritable) {
1239
1311
  const scenes = room.entireScenes()[scenePath];
1240
- for (let i = 0; i < pages.length; i++) {
1241
- const p = pages[i];
1242
- const name = (_c = p.name) != null ? _c : String(i + 1);
1243
- const scene = scenes.find((scene2) => scene2.name == name && scene2.ppt);
1244
- if (scene) {
1245
- if (scene.ppt && ((_d = scene.ppt) == null ? void 0 : _d.src) === p.src) {
1246
- continue;
1247
- }
1248
- room.removeScenes(`${scenePath}/${name}`);
1249
- }
1250
- room.putScenes(scenePath, pages.map((p2, index) => {
1312
+ if (pageIndex$.value < 0 || pageIndex$.value >= pages.length) {
1313
+ throw new Error(`[Presentation] Invalid page index: ${pageIndex$.value}, scenes length: ${pages.length}`);
1314
+ }
1315
+ new Promise((resolve) => {
1316
+ const { name, ppt } = scenes[pageIndex$.value];
1317
+ redirectResolve = resolve;
1318
+ const _scenes = pages.map((p, index) => {
1251
1319
  var _a2;
1252
1320
  return {
1253
- name: (_a2 = p2.name) != null ? _a2 : String(index + 1),
1254
- ppt: { width: p2.width, height: p2.height, src: p2.src }
1321
+ name: (_a2 = p.name) != null ? _a2 : String(index + 1),
1322
+ ppt: { width: p.width, height: p.height, src: p.src }
1255
1323
  };
1256
- }));
1257
- }
1324
+ });
1325
+ if (!scenesEqual(scenes, _scenes)) {
1326
+ room.removeScenes(scenePath);
1327
+ room.putScenes(scenePath, _scenes);
1328
+ }
1329
+ if (name === _scenes[pageIndex$.value].name && !ppt) {
1330
+ context.addPage({ scene: { name: emptySceneName } }).then(() => {
1331
+ log(`[Presentation] setup setScenePath ${scenePath}/${emptySceneName}`);
1332
+ context.setScenePath(`${scenePath}/${emptySceneName}`).then(() => {
1333
+ redirectResolve && redirectResolve(true);
1334
+ });
1335
+ });
1336
+ } else {
1337
+ redirectResolve && redirectResolve(false);
1338
+ }
1339
+ }).then(async (bol) => {
1340
+ await syncPage(pageIndex$.value, room.logger);
1341
+ if (bol) {
1342
+ log(`[Presentation] setup removeScenes ${scenePath}/${emptySceneName}`);
1343
+ room.removeScenes(`${scenePath}/${emptySceneName}`);
1344
+ }
1345
+ });
1258
1346
  }
1259
1347
  }
1260
- const dispose2 = disposableStore();
1261
- dispose2.add(() => log(`[Presentation] dispose ${context.appId}`));
1262
- const page$$ = context.createStorage("page", { index: 0 });
1263
- const view$$ = context.createStorage("view", { uid: "", originX: 0, originY: 0, width: 0, height: 0 });
1264
- let lastIndex = -1;
1265
- const syncPage = async (index) => {
1348
+ const me = ((_c = context.getRoom()) == null ? void 0 : _c.uid) || context.getDisplayer().observerId + "";
1349
+ let throttleSyncView = 0;
1350
+ const syncPage = async (index, logger) => {
1266
1351
  var _a2;
1267
- if (lastIndex !== index) {
1268
- lastIndex = index;
1269
- context.dispatchAppEvent("pageStateChange", { index, length: pages.length });
1270
- }
1271
1352
  if (!context.getIsWritable())
1272
1353
  return;
1273
1354
  const scenes = context.getDisplayer().entireScenes()[scenePath];
@@ -1278,6 +1359,9 @@ var NetlessAppPresentation = {
1278
1359
  if (!scenes.some((scene) => scene.name === name)) {
1279
1360
  await context.addPage({ scene: { name, ppt: { width: p.width, height: p.height, src: p.src } } });
1280
1361
  }
1362
+ if (logger) {
1363
+ logger.info(`[Presentation] syncPage ${scenePath}/${name}`);
1364
+ }
1281
1365
  await context.setScenePath(`${scenePath}/${name}`);
1282
1366
  };
1283
1367
  const jumpPage = (index) => {
@@ -1298,14 +1382,14 @@ var NetlessAppPresentation = {
1298
1382
  const p = pages[index];
1299
1383
  const name = (_a2 = p.name) != null ? _a2 : String(index + 1);
1300
1384
  if (!scenes.some((scene) => scene.name === name)) {
1301
- context.addPage({ scene: { name } });
1385
+ context.addPage({ scene: { name, ppt: { width: p.width, height: p.height, src: p.src } } });
1302
1386
  }
1303
- page$$.setState({ index });
1387
+ syncPage(index);
1304
1388
  return true;
1305
1389
  };
1306
- const prevPage = () => jumpPage(page$$.state.index - 1);
1307
- const nextPage = () => jumpPage(page$$.state.index + 1);
1308
- const pageState = () => ({ index: page$$.state.index, length: pages.length });
1390
+ const prevPage = () => jumpPage(pageIndex$.value - 1);
1391
+ const nextPage = () => jumpPage(pageIndex$.value + 1);
1392
+ const pageState = () => ({ index: pageIndex$.value, length: pages.length });
1309
1393
  const scaleDocsToFit = () => {
1310
1394
  const { width, height } = app.page() || {};
1311
1395
  if (width && height) {
@@ -1330,8 +1414,6 @@ var NetlessAppPresentation = {
1330
1414
  syncViewFromRemote(true);
1331
1415
  }
1332
1416
  };
1333
- const me = ((_e = context.getRoom()) == null ? void 0 : _e.uid) || context.getDisplayer().observerId + "";
1334
- let throttleSyncView = 0;
1335
1417
  const syncView = () => {
1336
1418
  if (throttleSyncView > 0)
1337
1419
  return;
@@ -1366,12 +1448,10 @@ var NetlessAppPresentation = {
1366
1448
  });
1367
1449
  }
1368
1450
  };
1369
- syncPage(page$$.state.index);
1370
- dispose2.add(page$$.addStateChangedListener(() => syncPage(page$$.state.index)));
1371
1451
  dispose2.add(view$$.addStateChangedListener(() => syncViewFromRemote(false, true)));
1372
1452
  const box = context.getBox();
1373
- const app = dispose2.add(createPresentation(box, pages, jumpPage, page$$, options.thumbnail));
1374
- app.contentDOM.dataset.appPresentationVersion = "0.1.7";
1453
+ const app = dispose2.add(createPresentation(box, pages, jumpPage, pageIndex$, options.thumbnail));
1454
+ app.contentDOM.dataset.appPresentationVersion = "0.1.8-beta.1";
1375
1455
  app.scaleDocsToFit = scaleDocsToFit;
1376
1456
  app.log = log;
1377
1457
  if (options.justDocsViewReadonly) {
@@ -1545,6 +1625,7 @@ var AppPresentation = class extends Presentation {
1545
1625
  this.image.style.display = "none";
1546
1626
  }
1547
1627
  updateImage() {
1628
+ super.updateImage();
1548
1629
  }
1549
1630
  onNewPageIndex(index, origin) {
1550
1631
  if (origin === "keydown" && this.box && !this.box.focus)
@@ -1558,15 +1639,14 @@ var AppPresentation = class extends Presentation {
1558
1639
  }
1559
1640
  }
1560
1641
  };
1561
- function createPresentation(box, pages, jumpPage, page$$, thumbnail) {
1642
+ function createPresentation(box, pages, jumpPage, pageIndex$, thumbnail) {
1562
1643
  box.mountStyles(style_default);
1563
1644
  const app = new AppPresentation({ pages, readonly: box.readonly, jumpPage, thumbnail });
1564
1645
  app.box = box;
1565
1646
  box.mountContent(app.contentDOM);
1566
1647
  box.mountFooter(app.footerDOM);
1567
- app.setPageIndex(page$$.state.index);
1568
- app.dispose.add(page$$.addStateChangedListener(() => {
1569
- app.setPageIndex(page$$.state.index);
1648
+ app.dispose.add(pageIndex$.subscribe((pageIndex) => {
1649
+ app.setPageIndex(pageIndex);
1570
1650
  }));
1571
1651
  return app;
1572
1652
  }
@@ -1579,7 +1659,7 @@ var install = (register, options = {}) => {
1579
1659
  };
1580
1660
 
1581
1661
  // src/index.ts
1582
- var version = "0.1.7";
1662
+ var version = "0.1.8-beta.1";
1583
1663
 
1584
1664
  export { NetlessAppPresentation, Presentation, NetlessAppPresentation as default, install, style_default as styles, version };
1585
1665
  //# sourceMappingURL=index.mjs.map