@netless/app-presentation 0.1.13-beta.1 → 0.1.13-beta.3
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/README-zh.md +18 -0
- package/README.md +22 -0
- package/dist/index.d.ts +73 -1
- package/dist/index.global.js +223 -82
- package/dist/index.js +223 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +223 -83
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/app-presentation.ts +146 -81
- package/src/preload.ts +23 -11
- package/src/presentation.ts +18 -1
- package/src/runtime-lifecycle.ts +31 -0
- package/src/setup-ready.ts +39 -0
- package/src/style.scss +7 -1
package/dist/index.mjs
CHANGED
|
@@ -1150,6 +1150,7 @@ var _Preload = class _Preload {
|
|
|
1150
1150
|
// 暂停后不再创建预加载链接(app 失焦降级时调用);已插入的 link 会被移除,
|
|
1151
1151
|
// 挂起的 idle 回调重新进入 touch() 时也会被跳过
|
|
1152
1152
|
this.paused = false;
|
|
1153
|
+
this.disposed = false;
|
|
1153
1154
|
this.preloadMap = new Map(pages.map((e, index) => [index, {
|
|
1154
1155
|
src: e.src,
|
|
1155
1156
|
state: 0 /* unloaded */
|
|
@@ -1164,13 +1165,13 @@ var _Preload = class _Preload {
|
|
|
1164
1165
|
this.destroySomeLink();
|
|
1165
1166
|
}
|
|
1166
1167
|
resume(index) {
|
|
1167
|
-
if (!this.paused)
|
|
1168
|
+
if (!this.paused || this.disposed)
|
|
1168
1169
|
return;
|
|
1169
1170
|
this.paused = false;
|
|
1170
1171
|
this.touch(index != null ? index : this.touchIndex, true);
|
|
1171
1172
|
}
|
|
1172
1173
|
touch(index, force = false) {
|
|
1173
|
-
if (this.paused)
|
|
1174
|
+
if (this.paused || this.disposed)
|
|
1174
1175
|
return;
|
|
1175
1176
|
if (index >= this.preloadSize) {
|
|
1176
1177
|
this.touchIndex = 0;
|
|
@@ -1178,11 +1179,11 @@ var _Preload = class _Preload {
|
|
|
1178
1179
|
this.touchIndex = index;
|
|
1179
1180
|
}
|
|
1180
1181
|
const value = this.preloadMap.get(this.touchIndex);
|
|
1181
|
-
if (value && value.state === 0 /* unloaded */) {
|
|
1182
|
+
if (value && (value.state === 0 /* unloaded */ || force && value.state === 2 /* error */)) {
|
|
1182
1183
|
this.createLink(this.touchIndex, force);
|
|
1183
1184
|
}
|
|
1184
1185
|
if (this.loadingLinks.size < _Preload.maxLinks) {
|
|
1185
|
-
const willLoad = [...this.preloadMap.entries()].find(([i, e]) => i > this.touchIndex && e.state
|
|
1186
|
+
const willLoad = [...this.preloadMap.entries()].find(([i, e]) => i > this.touchIndex && e.state === 0 /* unloaded */);
|
|
1186
1187
|
if (willLoad) {
|
|
1187
1188
|
this.requestAsyncCallBack(() => {
|
|
1188
1189
|
this.touch(willLoad[0], false);
|
|
@@ -1215,21 +1216,27 @@ var _Preload = class _Preload {
|
|
|
1215
1216
|
linkDom.as = "image";
|
|
1216
1217
|
linkDom.href = value.src;
|
|
1217
1218
|
linkDom.dataset.order = index + "";
|
|
1218
|
-
document.head.appendChild(linkDom);
|
|
1219
1219
|
linkDom.onload = () => {
|
|
1220
|
+
var _a;
|
|
1221
|
+
if (((_a = this.loadingLinks.get(index)) == null ? void 0 : _a.link) !== linkDom)
|
|
1222
|
+
return;
|
|
1220
1223
|
const value2 = this.preloadMap.get(index);
|
|
1221
1224
|
if (value2) {
|
|
1222
1225
|
value2.state = 1 /* loaded */;
|
|
1223
1226
|
this.preloadMap.set(index, value2);
|
|
1224
|
-
|
|
1225
|
-
this.loadingLinks.delete(index);
|
|
1227
|
+
this.removeLink(index, linkDom);
|
|
1226
1228
|
this.touch(this.touchIndex + 1, false);
|
|
1227
1229
|
}
|
|
1228
1230
|
};
|
|
1229
1231
|
linkDom.onerror = () => {
|
|
1232
|
+
var _a;
|
|
1233
|
+
if (((_a = this.loadingLinks.get(index)) == null ? void 0 : _a.link) !== linkDom)
|
|
1234
|
+
return;
|
|
1230
1235
|
const value2 = this.preloadMap.get(index);
|
|
1231
|
-
if (value2
|
|
1232
|
-
|
|
1236
|
+
if (value2) {
|
|
1237
|
+
value2.state = 2 /* error */;
|
|
1238
|
+
this.removeLink(index, linkDom);
|
|
1239
|
+
this.touch(this.touchIndex + 1, false);
|
|
1233
1240
|
}
|
|
1234
1241
|
};
|
|
1235
1242
|
this.loadingLinks.set(index, {
|
|
@@ -1238,17 +1245,23 @@ var _Preload = class _Preload {
|
|
|
1238
1245
|
});
|
|
1239
1246
|
value.state = 0 /* unloaded */;
|
|
1240
1247
|
this.preloadMap.set(index, value);
|
|
1248
|
+
document.head.appendChild(linkDom);
|
|
1241
1249
|
return 0 /* unloaded */;
|
|
1242
1250
|
}
|
|
1243
1251
|
return 2 /* error */;
|
|
1244
1252
|
}
|
|
1253
|
+
removeLink(index, link) {
|
|
1254
|
+
link.onload = null;
|
|
1255
|
+
link.onerror = null;
|
|
1256
|
+
document.head.contains(link) && document.head.removeChild(link);
|
|
1257
|
+
this.loadingLinks.delete(index);
|
|
1258
|
+
}
|
|
1245
1259
|
destroySomeLink(excludeIndex) {
|
|
1246
1260
|
for (const [index, { link }] of this.loadingLinks) {
|
|
1247
1261
|
if (excludeIndex !== void 0 && index === excludeIndex) {
|
|
1248
1262
|
continue;
|
|
1249
1263
|
}
|
|
1250
|
-
|
|
1251
|
-
this.loadingLinks.delete(index);
|
|
1264
|
+
this.removeLink(index, link);
|
|
1252
1265
|
}
|
|
1253
1266
|
}
|
|
1254
1267
|
async requestAsyncCallBack(callBack, timeout) {
|
|
@@ -1266,6 +1279,7 @@ var _Preload = class _Preload {
|
|
|
1266
1279
|
callBack();
|
|
1267
1280
|
}
|
|
1268
1281
|
dispose() {
|
|
1282
|
+
this.disposed = true;
|
|
1269
1283
|
this.destroySomeLink();
|
|
1270
1284
|
this.preloadMap.clear();
|
|
1271
1285
|
}
|
|
@@ -1313,10 +1327,7 @@ var Presentation = class {
|
|
|
1313
1327
|
if (this.initialized)
|
|
1314
1328
|
return;
|
|
1315
1329
|
this.initialized = true;
|
|
1316
|
-
this.dispose.add(() =>
|
|
1317
|
-
var _a2;
|
|
1318
|
-
return (_a2 = this.previewLazyload) == null ? void 0 : _a2.destroy();
|
|
1319
|
-
});
|
|
1330
|
+
this.dispose.add(() => this.destroyPreviewLazyload());
|
|
1320
1331
|
this.contentDOM.classList.toggle(this.c("readonly"), this.readonly);
|
|
1321
1332
|
this.dom.appendChild(this.contentDOM);
|
|
1322
1333
|
const previewMask = this.contentDOM.appendChild(document.createElement("div"));
|
|
@@ -1469,6 +1480,17 @@ var Presentation = class {
|
|
|
1469
1480
|
}
|
|
1470
1481
|
}
|
|
1471
1482
|
}
|
|
1483
|
+
/** Release preview images while this presentation stays in the runtime cache. */
|
|
1484
|
+
suspendPreviewResources() {
|
|
1485
|
+
this.togglePreview(false);
|
|
1486
|
+
this.destroyPreviewLazyload();
|
|
1487
|
+
this.previewDOM.querySelectorAll("img").forEach((img) => {
|
|
1488
|
+
img.removeAttribute("src");
|
|
1489
|
+
img.removeAttribute("srcset");
|
|
1490
|
+
img.removeAttribute("sizes");
|
|
1491
|
+
LazyLoad.resetStatus(img);
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1472
1494
|
// [origin] means the cause:
|
|
1473
1495
|
// - navigation: user clicked on the left / right button on footer
|
|
1474
1496
|
// - input: user filled the bottom-right page number input box
|
|
@@ -1503,6 +1525,11 @@ var Presentation = class {
|
|
|
1503
1525
|
return src;
|
|
1504
1526
|
}
|
|
1505
1527
|
}
|
|
1528
|
+
destroyPreviewLazyload() {
|
|
1529
|
+
var _a;
|
|
1530
|
+
(_a = this.previewLazyload) == null ? void 0 : _a.destroy();
|
|
1531
|
+
this.previewLazyload = null;
|
|
1532
|
+
}
|
|
1506
1533
|
c(className) {
|
|
1507
1534
|
return `${this.namespace}-${className}`;
|
|
1508
1535
|
}
|
|
@@ -1515,7 +1542,7 @@ var Presentation = class {
|
|
|
1515
1542
|
};
|
|
1516
1543
|
|
|
1517
1544
|
// src/style.scss?inline
|
|
1518
|
-
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}.netless-app-presentation-scrollbar-container{position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none;z-index:101}.netless-app-presentation-scrollbar-container-x,.netless-app-presentation-scrollbar-container-y{position:absolute;pointer-events:none;display:flex;justify-content:center;box-sizing:border-box;padding:0}.netless-app-presentation-scrollbar-container-x{bottom:0;left:0;height:6px;width:100%;padding-right:6px}.netless-app-presentation-scrollbar-container-y{top:0;right:0;width:6px;height:100%;flex-direction:column;padding-bottom:6px}.netless-app-presentation-scrollbar-x,.netless-app-presentation-scrollbar-y{border-radius:2px;background-color:#1b1f4d4d;pointer-events:auto;cursor:default}.netless-app-presentation-scrollbar-x{height:6px}.netless-app-presentation-scrollbar-y{width:6px}";
|
|
1545
|
+
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-background-suspended .background{display:none!important}.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}.netless-app-presentation-scrollbar-container{position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none;z-index:101}.netless-app-presentation-scrollbar-container-x,.netless-app-presentation-scrollbar-container-y{position:absolute;pointer-events:none;display:flex;justify-content:center;box-sizing:border-box;padding:0}.netless-app-presentation-scrollbar-container-x{bottom:0;left:0;height:6px;width:100%;padding-right:6px}.netless-app-presentation-scrollbar-container-y{top:0;right:0;width:6px;height:100%;flex-direction:column;padding-bottom:6px}.netless-app-presentation-scrollbar-x,.netless-app-presentation-scrollbar-y{border-radius:2px;background-color:#1b1f4d4d;pointer-events:auto;cursor:default}.netless-app-presentation-scrollbar-x{height:6px}.netless-app-presentation-scrollbar-y{width:6px}";
|
|
1519
1546
|
|
|
1520
1547
|
// src/store.ts
|
|
1521
1548
|
function noop() {
|
|
@@ -1961,6 +1988,66 @@ function cameraToSharedViewport(camera, viewSize, referenceSize) {
|
|
|
1961
1988
|
};
|
|
1962
1989
|
}
|
|
1963
1990
|
|
|
1991
|
+
// src/runtime-lifecycle.ts
|
|
1992
|
+
var createPresentationRuntimeTeardown = (box, dispose2) => {
|
|
1993
|
+
let tornDown = false;
|
|
1994
|
+
return () => {
|
|
1995
|
+
var _a, _b, _c;
|
|
1996
|
+
if (tornDown)
|
|
1997
|
+
return;
|
|
1998
|
+
tornDown = true;
|
|
1999
|
+
try {
|
|
2000
|
+
dispose2();
|
|
2001
|
+
} finally {
|
|
2002
|
+
try {
|
|
2003
|
+
(_a = box.unmountContent) == null ? void 0 : _a.call(box);
|
|
2004
|
+
} finally {
|
|
2005
|
+
try {
|
|
2006
|
+
(_b = box.unmountFooter) == null ? void 0 : _b.call(box);
|
|
2007
|
+
} finally {
|
|
2008
|
+
(_c = box.unmountStyles) == null ? void 0 : _c.call(box);
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
};
|
|
2013
|
+
};
|
|
2014
|
+
|
|
2015
|
+
// src/setup-ready.ts
|
|
2016
|
+
var waitForCurrentPageImage = (getImage, timeoutMs, isDisposed) => {
|
|
2017
|
+
return new Promise((resolve) => {
|
|
2018
|
+
let settled = false;
|
|
2019
|
+
let pollTimer;
|
|
2020
|
+
const settle = (result) => {
|
|
2021
|
+
if (settled)
|
|
2022
|
+
return;
|
|
2023
|
+
settled = true;
|
|
2024
|
+
window.clearTimeout(timeoutTimer);
|
|
2025
|
+
if (pollTimer !== void 0)
|
|
2026
|
+
window.clearInterval(pollTimer);
|
|
2027
|
+
resolve(result);
|
|
2028
|
+
};
|
|
2029
|
+
const timeoutTimer = window.setTimeout(() => settle("timeout"), timeoutMs);
|
|
2030
|
+
const check = () => {
|
|
2031
|
+
var _a, _b;
|
|
2032
|
+
if (isDisposed()) {
|
|
2033
|
+
settle("disposed");
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
const img = getImage();
|
|
2037
|
+
if (img == null ? void 0 : img.complete) {
|
|
2038
|
+
if (img.naturalWidth > 0) {
|
|
2039
|
+
settle("loaded");
|
|
2040
|
+
} else if (img.currentSrc || ((_a = img.getAttribute("src")) == null ? void 0 : _a.trim()) || ((_b = img.getAttribute("srcset")) == null ? void 0 : _b.trim())) {
|
|
2041
|
+
settle("error");
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
check();
|
|
2046
|
+
if (!settled)
|
|
2047
|
+
pollTimer = window.setInterval(check, 100);
|
|
2048
|
+
});
|
|
2049
|
+
};
|
|
2050
|
+
|
|
1964
2051
|
// src/app-presentation.ts
|
|
1965
2052
|
var import_debounce2 = __toESM(require_debounce());
|
|
1966
2053
|
var emptySceneName = "$$empty$$";
|
|
@@ -1977,6 +2064,10 @@ var findBackgroundImage = (view) => {
|
|
|
1977
2064
|
return container.querySelector('img[alt="background"]');
|
|
1978
2065
|
};
|
|
1979
2066
|
var isBlurDegradationAllowed = (context) => {
|
|
2067
|
+
var _a;
|
|
2068
|
+
if (((_a = context.getWindowManager()) == null ? void 0 : _a.lazySetupInMaximizedMode) !== true) {
|
|
2069
|
+
return false;
|
|
2070
|
+
}
|
|
1980
2071
|
const boxStatus = context.getBoxStatus();
|
|
1981
2072
|
if (boxStatus) {
|
|
1982
2073
|
return boxStatus !== "normal";
|
|
@@ -1985,36 +2076,6 @@ var isBlurDegradationAllowed = (context) => {
|
|
|
1985
2076
|
return boxState !== void 0 && boxState !== "normal";
|
|
1986
2077
|
};
|
|
1987
2078
|
var DEFAULT_SETUP_READY_TIMEOUT = 5e3;
|
|
1988
|
-
var waitForCurrentPageImage = (view, timeoutMs, isDisposed) => {
|
|
1989
|
-
return new Promise((resolve) => {
|
|
1990
|
-
let settled = false;
|
|
1991
|
-
let pollTimer;
|
|
1992
|
-
const settle = (loaded) => {
|
|
1993
|
-
if (settled)
|
|
1994
|
-
return;
|
|
1995
|
-
settled = true;
|
|
1996
|
-
window.clearTimeout(timeoutTimer);
|
|
1997
|
-
if (pollTimer !== void 0)
|
|
1998
|
-
window.clearInterval(pollTimer);
|
|
1999
|
-
resolve(loaded);
|
|
2000
|
-
};
|
|
2001
|
-
const timeoutTimer = window.setTimeout(() => settle(false), timeoutMs);
|
|
2002
|
-
const check = () => {
|
|
2003
|
-
if (isDisposed()) {
|
|
2004
|
-
settle(false);
|
|
2005
|
-
return;
|
|
2006
|
-
}
|
|
2007
|
-
const img = findBackgroundImage(view);
|
|
2008
|
-
if (img && img.complete && img.naturalWidth > 0) {
|
|
2009
|
-
settle(true);
|
|
2010
|
-
}
|
|
2011
|
-
};
|
|
2012
|
-
check();
|
|
2013
|
-
if (!settled) {
|
|
2014
|
-
pollTimer = window.setInterval(check, 100);
|
|
2015
|
-
}
|
|
2016
|
-
});
|
|
2017
|
-
};
|
|
2018
2079
|
var resolveImageUrl = (url) => {
|
|
2019
2080
|
try {
|
|
2020
2081
|
return new URL(url, window.location.href).href;
|
|
@@ -2022,17 +2083,55 @@ var resolveImageUrl = (url) => {
|
|
|
2022
2083
|
return url;
|
|
2023
2084
|
}
|
|
2024
2085
|
};
|
|
2086
|
+
var TRANSPARENT_BACKGROUND = "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";
|
|
2087
|
+
var BACKGROUND_SUSPENDED_CLASS = "netless-app-presentation-background-suspended";
|
|
2088
|
+
var hasUsableThumbnail = (page) => {
|
|
2089
|
+
const thumbnailURL = page.thumbnail;
|
|
2090
|
+
if (!thumbnailURL)
|
|
2091
|
+
return false;
|
|
2092
|
+
try {
|
|
2093
|
+
const source = new URL(page.src, window.location.href);
|
|
2094
|
+
const thumbnail = new URL(thumbnailURL, window.location.href);
|
|
2095
|
+
const sameResourcePath = source.origin === thumbnail.origin && source.pathname === thumbnail.pathname;
|
|
2096
|
+
if (/\.gif$/i.test(source.pathname) && sameResourcePath)
|
|
2097
|
+
return false;
|
|
2098
|
+
} catch (e) {
|
|
2099
|
+
if (/\.gif(?:$|[?#])/i.test(page.src))
|
|
2100
|
+
return false;
|
|
2101
|
+
}
|
|
2102
|
+
return resolveImageUrl(thumbnailURL) !== resolveImageUrl(page.src);
|
|
2103
|
+
};
|
|
2025
2104
|
var setupBlurThumbnailDegradation = (config) => {
|
|
2026
2105
|
const { context, view, pages, pageIndex$, app, dispose: dispose2 } = config;
|
|
2106
|
+
const box = context.getBox();
|
|
2107
|
+
const boxBlurClass = box.wrapClassName("blur");
|
|
2027
2108
|
let blurEpisode = false;
|
|
2028
2109
|
let reDegradeEnabled = false;
|
|
2110
|
+
let boxBlurred = box.$box.classList.contains(boxBlurClass);
|
|
2111
|
+
const setBackgroundSuspended = (suspended) => {
|
|
2112
|
+
app.whiteboardDOM.classList.toggle(
|
|
2113
|
+
BACKGROUND_SUSPENDED_CLASS,
|
|
2114
|
+
suspended
|
|
2115
|
+
);
|
|
2116
|
+
};
|
|
2029
2117
|
const degrade = () => {
|
|
2030
2118
|
const page = pages[pageIndex$.value];
|
|
2031
|
-
if (!
|
|
2119
|
+
if (!page)
|
|
2032
2120
|
return;
|
|
2121
|
+
const thumbnailURL = page.thumbnail;
|
|
2033
2122
|
const img = findBackgroundImage(view);
|
|
2034
|
-
if (
|
|
2035
|
-
|
|
2123
|
+
if (!thumbnailURL || !hasUsableThumbnail(page)) {
|
|
2124
|
+
if (boxBlurred) {
|
|
2125
|
+
setBackgroundSuspended(true);
|
|
2126
|
+
if (img && resolveImageUrl(img.src) !== resolveImageUrl(TRANSPARENT_BACKGROUND)) {
|
|
2127
|
+
img.src = TRANSPARENT_BACKGROUND;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
return;
|
|
2131
|
+
}
|
|
2132
|
+
setBackgroundSuspended(false);
|
|
2133
|
+
if (img && resolveImageUrl(img.src) !== resolveImageUrl(thumbnailURL)) {
|
|
2134
|
+
img.src = thumbnailURL;
|
|
2036
2135
|
}
|
|
2037
2136
|
};
|
|
2038
2137
|
const restore2 = () => {
|
|
@@ -2041,6 +2140,24 @@ var setupBlurThumbnailDegradation = (config) => {
|
|
|
2041
2140
|
if (page && img && resolveImageUrl(img.src) !== resolveImageUrl(page.src)) {
|
|
2042
2141
|
img.src = page.src;
|
|
2043
2142
|
}
|
|
2143
|
+
setBackgroundSuspended(false);
|
|
2144
|
+
};
|
|
2145
|
+
const suspendCachedResources = () => {
|
|
2146
|
+
if (!blurEpisode || !boxBlurred)
|
|
2147
|
+
return;
|
|
2148
|
+
app.suspendPreviewResources();
|
|
2149
|
+
const page = pages[pageIndex$.value];
|
|
2150
|
+
if (!page || !hasUsableThumbnail(page) || reDegradeEnabled) {
|
|
2151
|
+
degrade();
|
|
2152
|
+
}
|
|
2153
|
+
};
|
|
2154
|
+
const restoreFocusedResources = () => {
|
|
2155
|
+
if (!blurEpisode)
|
|
2156
|
+
return;
|
|
2157
|
+
blurEpisode = false;
|
|
2158
|
+
reDegradeEnabled = false;
|
|
2159
|
+
restore2();
|
|
2160
|
+
app.preload.resume(pageIndex$.value);
|
|
2044
2161
|
};
|
|
2045
2162
|
const isBackgroundImg = (target) => {
|
|
2046
2163
|
var _a;
|
|
@@ -2049,28 +2166,29 @@ var setupBlurThumbnailDegradation = (config) => {
|
|
|
2049
2166
|
el && el.tagName === "IMG" && ((_a = el.matches) == null ? void 0 : _a.call(el, 'img[alt="background"]'))
|
|
2050
2167
|
);
|
|
2051
2168
|
};
|
|
2169
|
+
const ownsTarget = (target) => {
|
|
2170
|
+
if (!isBackgroundImg(target))
|
|
2171
|
+
return false;
|
|
2172
|
+
const el = view.divElement;
|
|
2173
|
+
return !!(el && el.contains(target));
|
|
2174
|
+
};
|
|
2052
2175
|
const onImgLoad = (ev) => {
|
|
2053
2176
|
if (!blurEpisode || !reDegradeEnabled)
|
|
2054
2177
|
return;
|
|
2055
|
-
if (!
|
|
2178
|
+
if (!ownsTarget(ev.target))
|
|
2056
2179
|
return;
|
|
2057
2180
|
degrade();
|
|
2058
2181
|
};
|
|
2059
2182
|
const onImgError = (ev) => {
|
|
2060
2183
|
if (!blurEpisode || !reDegradeEnabled)
|
|
2061
2184
|
return;
|
|
2062
|
-
if (!
|
|
2185
|
+
if (!ownsTarget(ev.target))
|
|
2063
2186
|
return;
|
|
2064
2187
|
reDegradeEnabled = false;
|
|
2065
2188
|
};
|
|
2066
2189
|
const offFocus = context.emitter.on("focus", (isFocused) => {
|
|
2067
2190
|
if (isFocused) {
|
|
2068
|
-
|
|
2069
|
-
blurEpisode = false;
|
|
2070
|
-
reDegradeEnabled = false;
|
|
2071
|
-
restore2();
|
|
2072
|
-
app.preload.resume(pageIndex$.value);
|
|
2073
|
-
}
|
|
2191
|
+
restoreFocusedResources();
|
|
2074
2192
|
} else {
|
|
2075
2193
|
if (!isBlurDegradationAllowed(context))
|
|
2076
2194
|
return;
|
|
@@ -2078,29 +2196,41 @@ var setupBlurThumbnailDegradation = (config) => {
|
|
|
2078
2196
|
reDegradeEnabled = true;
|
|
2079
2197
|
degrade();
|
|
2080
2198
|
app.preload.pause();
|
|
2199
|
+
suspendCachedResources();
|
|
2081
2200
|
}
|
|
2082
2201
|
});
|
|
2083
2202
|
dispose2.add(offFocus);
|
|
2084
|
-
const
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
}
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
);
|
|
2203
|
+
const updateBoxBlurred = (blurred) => {
|
|
2204
|
+
if (boxBlurred === blurred)
|
|
2205
|
+
return;
|
|
2206
|
+
boxBlurred = blurred;
|
|
2207
|
+
if (blurred)
|
|
2208
|
+
suspendCachedResources();
|
|
2209
|
+
else
|
|
2210
|
+
restoreFocusedResources();
|
|
2211
|
+
};
|
|
2212
|
+
const onBoxBlur = () => updateBoxBlurred(true);
|
|
2213
|
+
const onBoxFocus = () => updateBoxBlurred(false);
|
|
2214
|
+
box.events.on("blur", onBoxBlur);
|
|
2215
|
+
box.events.on("focus", onBoxFocus);
|
|
2216
|
+
dispose2.add(() => {
|
|
2217
|
+
box.events.off("blur", onBoxBlur);
|
|
2218
|
+
box.events.off("focus", onBoxFocus);
|
|
2219
|
+
});
|
|
2220
|
+
const boxClassObserver = new MutationObserver(() => {
|
|
2221
|
+
updateBoxBlurred(box.$box.classList.contains(boxBlurClass));
|
|
2222
|
+
});
|
|
2223
|
+
boxClassObserver.observe(box.$box, {
|
|
2224
|
+
attributes: true,
|
|
2225
|
+
attributeFilter: ["class"]
|
|
2226
|
+
});
|
|
2227
|
+
dispose2.add(() => boxClassObserver.disconnect());
|
|
2228
|
+
document.addEventListener("load", onImgLoad, true);
|
|
2229
|
+
document.addEventListener("error", onImgError, true);
|
|
2230
|
+
dispose2.add(() => {
|
|
2231
|
+
document.removeEventListener("load", onImgLoad, true);
|
|
2232
|
+
document.removeEventListener("error", onImgError, true);
|
|
2233
|
+
});
|
|
2104
2234
|
};
|
|
2105
2235
|
var createLogger = (room) => {
|
|
2106
2236
|
if (room && room.logger) {
|
|
@@ -2523,7 +2653,7 @@ var NetlessAppPresentation = {
|
|
|
2523
2653
|
options.useClipView
|
|
2524
2654
|
)
|
|
2525
2655
|
);
|
|
2526
|
-
app.contentDOM.dataset.appPresentationVersion = "0.1.13-beta.
|
|
2656
|
+
app.contentDOM.dataset.appPresentationVersion = "0.1.13-beta.3";
|
|
2527
2657
|
app.scaleDocsToFit = scaleDocsToFit;
|
|
2528
2658
|
app.log = log;
|
|
2529
2659
|
app.warn = warn;
|
|
@@ -2765,6 +2895,10 @@ var NetlessAppPresentation = {
|
|
|
2765
2895
|
};
|
|
2766
2896
|
let disposed = false;
|
|
2767
2897
|
let offDestroy;
|
|
2898
|
+
const teardownRuntime = createPresentationRuntimeTeardown(
|
|
2899
|
+
box,
|
|
2900
|
+
dispose2
|
|
2901
|
+
);
|
|
2768
2902
|
const teardown = () => {
|
|
2769
2903
|
if (disposed)
|
|
2770
2904
|
return;
|
|
@@ -2772,7 +2906,7 @@ var NetlessAppPresentation = {
|
|
|
2772
2906
|
const removeDestroy = offDestroy;
|
|
2773
2907
|
offDestroy = void 0;
|
|
2774
2908
|
removeDestroy == null ? void 0 : removeDestroy();
|
|
2775
|
-
|
|
2909
|
+
teardownRuntime();
|
|
2776
2910
|
};
|
|
2777
2911
|
offDestroy = context.emitter.on("destroy", teardown);
|
|
2778
2912
|
teardownByContext.set(context, teardown);
|
|
@@ -2988,9 +3122,15 @@ var NetlessAppPresentation = {
|
|
|
2988
3122
|
);
|
|
2989
3123
|
const setupReadyTimeout = (_d = options.setupReadyTimeout) != null ? _d : DEFAULT_SETUP_READY_TIMEOUT;
|
|
2990
3124
|
return prepareScenesPromise.then(async () => {
|
|
2991
|
-
const
|
|
2992
|
-
|
|
3125
|
+
const result = await waitForCurrentPageImage(
|
|
3126
|
+
() => findBackgroundImage(view),
|
|
3127
|
+
setupReadyTimeout,
|
|
3128
|
+
() => disposed
|
|
3129
|
+
);
|
|
3130
|
+
if (result === "timeout" && !disposed) {
|
|
2993
3131
|
warn(`[Presentation] setup ready wait timed out after ${setupReadyTimeout}ms`);
|
|
3132
|
+
} else if (result === "error" && !disposed) {
|
|
3133
|
+
warn("[Presentation] setup page image failed to load; continuing setup");
|
|
2994
3134
|
}
|
|
2995
3135
|
return controller;
|
|
2996
3136
|
});
|
|
@@ -3079,7 +3219,7 @@ var install = (register, options = {}) => {
|
|
|
3079
3219
|
};
|
|
3080
3220
|
|
|
3081
3221
|
// src/index.ts
|
|
3082
|
-
var version = "0.1.13-beta.
|
|
3222
|
+
var version = "0.1.13-beta.3";
|
|
3083
3223
|
|
|
3084
|
-
export { NetlessAppPresentation, Presentation, Scrollbar, NetlessAppPresentation as default, install, version };
|
|
3224
|
+
export { NetlessAppPresentation, Presentation, Scrollbar, NetlessAppPresentation as default, install, setupBlurThumbnailDegradation, version };
|
|
3085
3225
|
//# sourceMappingURL=index.mjs.map
|