@netless/app-presentation 0.1.11 → 0.1.13-beta.0
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.d.ts +4 -5
- package/dist/index.global.js +283 -106
- package/dist/index.js +283 -106
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +283 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app-presentation.ts +823 -516
package/dist/index.js
CHANGED
|
@@ -1951,7 +1951,6 @@ function cameraToSharedViewport(camera, viewSize, referenceSize) {
|
|
|
1951
1951
|
// src/app-presentation.ts
|
|
1952
1952
|
var import_debounce2 = __toESM(require_debounce());
|
|
1953
1953
|
var emptySceneName = "$$empty$$";
|
|
1954
|
-
var ORIGIN_SIZE_COORDINATE_VERSION = 2;
|
|
1955
1954
|
var ppt2page = (ppt, name, originSize) => {
|
|
1956
1955
|
if (!ppt)
|
|
1957
1956
|
return null;
|
|
@@ -1969,7 +1968,10 @@ var createDiagnosticLogger = (context) => {
|
|
|
1969
1968
|
var _a;
|
|
1970
1969
|
const createAppLogger = context.createLogger;
|
|
1971
1970
|
if (typeof createAppLogger === "function") {
|
|
1972
|
-
return createAppLogger.call(context, "camera", {
|
|
1971
|
+
return createAppLogger.call(context, "camera", {
|
|
1972
|
+
debounceTime: 300,
|
|
1973
|
+
maxWaitTime: 2e3
|
|
1974
|
+
});
|
|
1973
1975
|
}
|
|
1974
1976
|
const roomLogger = (_a = context.getRoom()) == null ? void 0 : _a.logger;
|
|
1975
1977
|
const prefix = `[Presentation][${context.appId}][camera]`;
|
|
@@ -2026,6 +2028,7 @@ var scenesEqual = (scenes1, scenes2) => {
|
|
|
2026
2028
|
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);
|
|
2027
2029
|
});
|
|
2028
2030
|
};
|
|
2031
|
+
var teardownByContext = /* @__PURE__ */ new WeakMap();
|
|
2029
2032
|
var NetlessAppPresentation = {
|
|
2030
2033
|
kind: "Presentation",
|
|
2031
2034
|
setup(context) {
|
|
@@ -2033,41 +2036,52 @@ var NetlessAppPresentation = {
|
|
|
2033
2036
|
const diagnosticLogger = createDiagnosticLogger(context);
|
|
2034
2037
|
const view = context.getView();
|
|
2035
2038
|
if (!view)
|
|
2036
|
-
throw new Error(
|
|
2039
|
+
throw new Error(
|
|
2040
|
+
"[Presentation]: no whiteboard view, make sure you have added options.scenePath in addApp()"
|
|
2041
|
+
);
|
|
2037
2042
|
const options = context.getAppOptions() || {};
|
|
2038
2043
|
const room = context.getRoom();
|
|
2039
2044
|
const log = options.log || createLogger(room);
|
|
2040
2045
|
const roomLogger = room == null ? void 0 : room.logger;
|
|
2041
2046
|
const warn = (...data) => (roomLogger == null ? void 0 : roomLogger.warn) ? roomLogger.warn(...data) : log(...data);
|
|
2042
2047
|
const configuredOriginSize = context.storage.state.originSize;
|
|
2043
|
-
const originSize = isValidSize(configuredOriginSize) ? {
|
|
2048
|
+
const originSize = isValidSize(configuredOriginSize) ? {
|
|
2049
|
+
width: configuredOriginSize.width,
|
|
2050
|
+
height: configuredOriginSize.height
|
|
2051
|
+
} : void 0;
|
|
2044
2052
|
if (configuredOriginSize != null && !originSize) {
|
|
2045
|
-
warn(
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
originSize && (context.isAddApp || context.storage.state._originSizeCoordinateVersion === ORIGIN_SIZE_COORDINATE_VERSION)
|
|
2049
|
-
);
|
|
2050
|
-
if (originSize && context.isAddApp && context.getIsWritable()) {
|
|
2051
|
-
context.storage.setState({
|
|
2052
|
-
_originSizeCoordinateVersion: ORIGIN_SIZE_COORDINATE_VERSION
|
|
2053
|
-
});
|
|
2053
|
+
warn(
|
|
2054
|
+
`[Presentation] originSize should contain finite positive width and height, got ${JSON.stringify(configuredOriginSize)}`
|
|
2055
|
+
);
|
|
2054
2056
|
}
|
|
2055
|
-
const pages = (_a = context.getScenes()) == null ? void 0 : _a.map(({ ppt, name }) => ppt2page(ppt, name,
|
|
2057
|
+
const pages = (_a = context.getScenes()) == null ? void 0 : _a.map(({ ppt, name }) => ppt2page(ppt, name, originSize)).filter(Boolean);
|
|
2056
2058
|
if (!pages || pages.length === 0)
|
|
2057
|
-
throw new Error(
|
|
2059
|
+
throw new Error(
|
|
2060
|
+
"[Presentation]: empty scenes, make sure you have added options.scenes in addApp()"
|
|
2061
|
+
);
|
|
2058
2062
|
if (pages[0].src.startsWith("ppt"))
|
|
2059
|
-
throw new Error(
|
|
2063
|
+
throw new Error(
|
|
2064
|
+
"[Presentation]: legacy dynamic PPT is unsupported, please use the projector converter and @netless/slide to render it"
|
|
2065
|
+
);
|
|
2060
2066
|
const scenePath = context.getInitScenePath();
|
|
2061
2067
|
let maxCameraScale = (_b = options.maxCameraScale) != null ? _b : 3;
|
|
2062
2068
|
if (!(Number.isFinite(maxCameraScale) && maxCameraScale > 0)) {
|
|
2063
|
-
warn(
|
|
2069
|
+
warn(
|
|
2070
|
+
`[Presentation] maxCameraScale should be a positive number, got ${options.maxCameraScale}`
|
|
2071
|
+
);
|
|
2064
2072
|
maxCameraScale = 3;
|
|
2065
2073
|
}
|
|
2066
2074
|
log(`[Presentation] new ${context.appId}`);
|
|
2067
2075
|
const dispose2 = disposableStore();
|
|
2068
2076
|
dispose2.add(() => log(`[Presentation] dispose ${context.appId}`));
|
|
2069
2077
|
dispose2.add(() => diagnosticLogger.flush());
|
|
2070
|
-
const view$$ = context.createStorage("view", {
|
|
2078
|
+
const view$$ = context.createStorage("view", {
|
|
2079
|
+
uid: "",
|
|
2080
|
+
originX: 0,
|
|
2081
|
+
originY: 0,
|
|
2082
|
+
width: 0,
|
|
2083
|
+
height: 0
|
|
2084
|
+
});
|
|
2071
2085
|
const _addScenePathListener = (name, listener) => {
|
|
2072
2086
|
const windowManger = context.manager.windowManger;
|
|
2073
2087
|
windowManger.emitter.on(name, listener);
|
|
@@ -2089,13 +2103,16 @@ var NetlessAppPresentation = {
|
|
|
2089
2103
|
let pageIndex = getPageIndex(view);
|
|
2090
2104
|
const pageIndex$ = readable(pageIndex, (set) => {
|
|
2091
2105
|
set(pageIndex);
|
|
2092
|
-
return _addScenePathListener(
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2106
|
+
return _addScenePathListener(
|
|
2107
|
+
"onAppScenePathChange",
|
|
2108
|
+
(payload) => {
|
|
2109
|
+
const { appId } = payload;
|
|
2110
|
+
if (appId === context.appId) {
|
|
2111
|
+
const _pageIndex = getPageIndex(payload.view);
|
|
2112
|
+
set(_pageIndex);
|
|
2113
|
+
}
|
|
2097
2114
|
}
|
|
2098
|
-
|
|
2115
|
+
);
|
|
2099
2116
|
});
|
|
2100
2117
|
dispose2.add(() => {
|
|
2101
2118
|
pageIndex$.dispose();
|
|
@@ -2112,7 +2129,12 @@ var NetlessAppPresentation = {
|
|
|
2112
2129
|
const p = pages[index];
|
|
2113
2130
|
const name = (_a2 = p.name) != null ? _a2 : String(index + 1);
|
|
2114
2131
|
if (!scenes.some((scene) => scene.name === name)) {
|
|
2115
|
-
await context.addPage({
|
|
2132
|
+
await context.addPage({
|
|
2133
|
+
scene: {
|
|
2134
|
+
name,
|
|
2135
|
+
ppt: { width: p.width, height: p.height, src: p.src }
|
|
2136
|
+
}
|
|
2137
|
+
});
|
|
2116
2138
|
}
|
|
2117
2139
|
if (logger) {
|
|
2118
2140
|
logger.info(`[Presentation] syncPage ${scenePath}/${name}`);
|
|
@@ -2124,15 +2146,21 @@ var NetlessAppPresentation = {
|
|
|
2124
2146
|
if (!context.isAddApp)
|
|
2125
2147
|
return;
|
|
2126
2148
|
if (pages.length > 100)
|
|
2127
|
-
warn(
|
|
2149
|
+
warn(
|
|
2150
|
+
`[Presentation]: too many pages (${pages.length}), may cause performance issues`
|
|
2151
|
+
);
|
|
2128
2152
|
if (!room || !room.isWritable)
|
|
2129
2153
|
return;
|
|
2130
2154
|
if (pageIndex$.value < 0 || pageIndex$.value >= pages.length) {
|
|
2131
|
-
throw new Error(
|
|
2155
|
+
throw new Error(
|
|
2156
|
+
`[Presentation] Invalid page index: ${pageIndex$.value}, scenes length: ${pages.length}`
|
|
2157
|
+
);
|
|
2132
2158
|
}
|
|
2133
2159
|
const scenes = room.entireScenes()[scenePath];
|
|
2134
2160
|
if (!scenes || !scenes[pageIndex$.value]) {
|
|
2135
|
-
throw new Error(
|
|
2161
|
+
throw new Error(
|
|
2162
|
+
`[Presentation]: no initial scene found at ${scenePath}, page index: ${pageIndex$.value}`
|
|
2163
|
+
);
|
|
2136
2164
|
}
|
|
2137
2165
|
const { name, ppt } = scenes[pageIndex$.value];
|
|
2138
2166
|
const nextScenes = pages.map((page, index) => {
|
|
@@ -2161,16 +2189,22 @@ var NetlessAppPresentation = {
|
|
|
2161
2189
|
const prepareScenesPromise = prepareScenes();
|
|
2162
2190
|
const canJumpPage = (index) => {
|
|
2163
2191
|
if (!context.getIsWritable()) {
|
|
2164
|
-
warn(
|
|
2192
|
+
warn(
|
|
2193
|
+
"[Presentation]: no permission, make sure you have test room.isWritable"
|
|
2194
|
+
);
|
|
2165
2195
|
return false;
|
|
2166
2196
|
}
|
|
2167
2197
|
if (!(0 <= index && index < pages.length)) {
|
|
2168
|
-
warn(
|
|
2198
|
+
warn(
|
|
2199
|
+
`[Presentation]: page ${index + 1} out of bounds [1, ${pages.length}]`
|
|
2200
|
+
);
|
|
2169
2201
|
return false;
|
|
2170
2202
|
}
|
|
2171
2203
|
const scenes = context.getDisplayer().entireScenes()[scenePath];
|
|
2172
2204
|
if (!scenes) {
|
|
2173
|
-
warn(
|
|
2205
|
+
warn(
|
|
2206
|
+
`[Presentation]: no scenes found at ${scenePath}, make sure you have added options.scenePath in addApp()`
|
|
2207
|
+
);
|
|
2174
2208
|
return false;
|
|
2175
2209
|
}
|
|
2176
2210
|
return true;
|
|
@@ -2276,13 +2310,20 @@ var NetlessAppPresentation = {
|
|
|
2276
2310
|
try {
|
|
2277
2311
|
const { camera, size } = view;
|
|
2278
2312
|
const referenceSize = getCameraReferenceSize(originSize, page);
|
|
2279
|
-
const viewport = cameraToSharedViewport(
|
|
2313
|
+
const viewport = cameraToSharedViewport(
|
|
2314
|
+
camera,
|
|
2315
|
+
size,
|
|
2316
|
+
referenceSize
|
|
2317
|
+
);
|
|
2280
2318
|
if (viewport)
|
|
2281
2319
|
view$$.setState(__spreadValues({ uid: me }, viewport));
|
|
2282
2320
|
if (pendingMoveCameraRequest) {
|
|
2283
2321
|
diagnosticLogger.debouncedInfo(
|
|
2284
2322
|
"moveCamera",
|
|
2285
|
-
getCameraDiagnosticState(
|
|
2323
|
+
getCameraDiagnosticState(
|
|
2324
|
+
"moveCamera",
|
|
2325
|
+
pendingMoveCameraRequest
|
|
2326
|
+
)
|
|
2286
2327
|
);
|
|
2287
2328
|
pendingMoveCameraRequest = void 0;
|
|
2288
2329
|
}
|
|
@@ -2290,7 +2331,10 @@ var NetlessAppPresentation = {
|
|
|
2290
2331
|
diagnosticLogger.error(
|
|
2291
2332
|
"syncView.failed",
|
|
2292
2333
|
error,
|
|
2293
|
-
getCameraDiagnosticState(
|
|
2334
|
+
getCameraDiagnosticState(
|
|
2335
|
+
"moveCamera",
|
|
2336
|
+
pendingMoveCameraRequest
|
|
2337
|
+
)
|
|
2294
2338
|
);
|
|
2295
2339
|
pendingMoveCameraRequest = void 0;
|
|
2296
2340
|
}
|
|
@@ -2315,14 +2359,26 @@ var NetlessAppPresentation = {
|
|
|
2315
2359
|
});
|
|
2316
2360
|
}
|
|
2317
2361
|
};
|
|
2318
|
-
dispose2.add(
|
|
2362
|
+
dispose2.add(
|
|
2363
|
+
view$$.addStateChangedListener(() => syncViewFromRemote(false, true))
|
|
2364
|
+
);
|
|
2319
2365
|
const getPageSize = () => {
|
|
2320
2366
|
const { width, height } = app.page() || {};
|
|
2321
2367
|
return { width: width || 0, height: height || 0 };
|
|
2322
2368
|
};
|
|
2323
2369
|
const box = context.getBox();
|
|
2324
|
-
const app = dispose2.add(
|
|
2325
|
-
|
|
2370
|
+
const app = dispose2.add(
|
|
2371
|
+
createPresentation(
|
|
2372
|
+
box,
|
|
2373
|
+
pages,
|
|
2374
|
+
jumpPage,
|
|
2375
|
+
pageIndex$,
|
|
2376
|
+
view,
|
|
2377
|
+
options.thumbnail,
|
|
2378
|
+
options.useClipView
|
|
2379
|
+
)
|
|
2380
|
+
);
|
|
2381
|
+
app.contentDOM.dataset.appPresentationVersion = "0.1.13-beta.0";
|
|
2326
2382
|
app.scaleDocsToFit = scaleDocsToFit;
|
|
2327
2383
|
app.log = log;
|
|
2328
2384
|
app.warn = warn;
|
|
@@ -2369,12 +2425,14 @@ var NetlessAppPresentation = {
|
|
|
2369
2425
|
};
|
|
2370
2426
|
if (originSize) {
|
|
2371
2427
|
let previousPageIndex = pageIndex$.value;
|
|
2372
|
-
dispose2.add(
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2428
|
+
dispose2.add(
|
|
2429
|
+
pageIndex$.subscribe((nextPageIndex) => {
|
|
2430
|
+
if (nextPageIndex === previousPageIndex)
|
|
2431
|
+
return;
|
|
2432
|
+
previousPageIndex = nextPageIndex;
|
|
2433
|
+
scaleDocsToFit();
|
|
2434
|
+
})
|
|
2435
|
+
);
|
|
2378
2436
|
}
|
|
2379
2437
|
if (options.justDocsViewReadonly) {
|
|
2380
2438
|
app.setDocsViewReadonly(true);
|
|
@@ -2423,9 +2481,11 @@ var NetlessAppPresentation = {
|
|
|
2423
2481
|
});
|
|
2424
2482
|
syncViewFromRemote(true);
|
|
2425
2483
|
reportInitializedCamera("setup");
|
|
2426
|
-
dispose2.add(
|
|
2427
|
-
|
|
2428
|
-
|
|
2484
|
+
dispose2.add(
|
|
2485
|
+
context.emitter.on("writableChange", (isWritable) => {
|
|
2486
|
+
app.setReadonly(!isWritable);
|
|
2487
|
+
})
|
|
2488
|
+
);
|
|
2429
2489
|
const getOriginScale = () => {
|
|
2430
2490
|
const page = app.page();
|
|
2431
2491
|
if (!page || !isValidSize(page))
|
|
@@ -2447,29 +2507,53 @@ var NetlessAppPresentation = {
|
|
|
2447
2507
|
img.crossOrigin = "Anonymous";
|
|
2448
2508
|
await new Promise((resolve, reject) => {
|
|
2449
2509
|
img.onload = () => resolve();
|
|
2450
|
-
img.onerror = () => reject(
|
|
2451
|
-
|
|
2452
|
-
|
|
2510
|
+
img.onerror = () => reject(
|
|
2511
|
+
new Error(
|
|
2512
|
+
`[Presentation]: failed to load screenshot page image: ${safeResourceLocation(src)}`
|
|
2513
|
+
)
|
|
2514
|
+
);
|
|
2453
2515
|
img.src = src;
|
|
2454
2516
|
});
|
|
2455
|
-
_context.drawImage(
|
|
2517
|
+
_context.drawImage(
|
|
2518
|
+
img,
|
|
2519
|
+
0,
|
|
2520
|
+
0,
|
|
2521
|
+
width,
|
|
2522
|
+
height,
|
|
2523
|
+
0,
|
|
2524
|
+
0,
|
|
2525
|
+
_width || width,
|
|
2526
|
+
_height || height
|
|
2527
|
+
);
|
|
2456
2528
|
const currentScenePath = view.focusScenePath;
|
|
2457
2529
|
if (!currentScenePath) {
|
|
2458
2530
|
throw new Error("[Presentation]: current scene path not found");
|
|
2459
2531
|
}
|
|
2460
2532
|
const windowManger = context.getWindowManager();
|
|
2461
2533
|
if (windowManger._appliancePlugin) {
|
|
2462
|
-
await windowManger._appliancePlugin.screenshotToCanvasAsync(
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2534
|
+
await windowManger._appliancePlugin.screenshotToCanvasAsync(
|
|
2535
|
+
_context,
|
|
2536
|
+
currentScenePath,
|
|
2537
|
+
_width || width,
|
|
2538
|
+
_height || height,
|
|
2539
|
+
{
|
|
2540
|
+
centerX: 0,
|
|
2541
|
+
centerY: 0,
|
|
2542
|
+
scale: _width && _height ? Math.min(_width / width, _height / height) : 1
|
|
2543
|
+
}
|
|
2544
|
+
);
|
|
2467
2545
|
} else {
|
|
2468
|
-
await view.screenshotToCanvasAsync(
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2546
|
+
await view.screenshotToCanvasAsync(
|
|
2547
|
+
_context,
|
|
2548
|
+
currentScenePath,
|
|
2549
|
+
_width || width,
|
|
2550
|
+
_height || height,
|
|
2551
|
+
{
|
|
2552
|
+
centerX: 0,
|
|
2553
|
+
centerY: 0,
|
|
2554
|
+
scale: _width && _height ? Math.min(_width / width, _height / height) : 1
|
|
2555
|
+
}
|
|
2556
|
+
);
|
|
2473
2557
|
}
|
|
2474
2558
|
};
|
|
2475
2559
|
const screenshotCurrentPageAsync = async (_context, _width, _height) => {
|
|
@@ -2487,21 +2571,27 @@ var NetlessAppPresentation = {
|
|
|
2487
2571
|
let scrollbar;
|
|
2488
2572
|
if (options.useScrollbar) {
|
|
2489
2573
|
dispose2.make(() => {
|
|
2490
|
-
scrollbar = new Scrollbar(
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2574
|
+
scrollbar = new Scrollbar(
|
|
2575
|
+
app.contentDOM,
|
|
2576
|
+
{
|
|
2577
|
+
appId: context.appId,
|
|
2578
|
+
getPageSize,
|
|
2579
|
+
getOriginScale,
|
|
2580
|
+
syncView,
|
|
2581
|
+
getWritable: () => context.getIsWritable(),
|
|
2582
|
+
scrollbarEventCallback: options.scrollbarEventCallback
|
|
2583
|
+
},
|
|
2584
|
+
view
|
|
2585
|
+
);
|
|
2498
2586
|
return () => scrollbar == null ? void 0 : scrollbar.destroy();
|
|
2499
2587
|
});
|
|
2500
2588
|
}
|
|
2501
2589
|
const moveCamera = (camera) => {
|
|
2502
2590
|
try {
|
|
2503
2591
|
if (!context.getIsWritable()) {
|
|
2504
|
-
throw new Error(
|
|
2592
|
+
throw new Error(
|
|
2593
|
+
"[Presentation]: moveCamera must be called in writable room"
|
|
2594
|
+
);
|
|
2505
2595
|
}
|
|
2506
2596
|
pendingMoveCameraRequest = __spreadValues({}, camera);
|
|
2507
2597
|
if (scrollbar) {
|
|
@@ -2522,9 +2612,29 @@ var NetlessAppPresentation = {
|
|
|
2522
2612
|
throw error;
|
|
2523
2613
|
}
|
|
2524
2614
|
};
|
|
2525
|
-
|
|
2615
|
+
let disposed = false;
|
|
2616
|
+
let offDestroy;
|
|
2617
|
+
const teardown = () => {
|
|
2618
|
+
if (disposed)
|
|
2619
|
+
return;
|
|
2620
|
+
disposed = true;
|
|
2621
|
+
const removeDestroy = offDestroy;
|
|
2622
|
+
offDestroy = void 0;
|
|
2623
|
+
removeDestroy == null ? void 0 : removeDestroy();
|
|
2624
|
+
dispose2();
|
|
2625
|
+
};
|
|
2626
|
+
offDestroy = context.emitter.on("destroy", teardown);
|
|
2627
|
+
teardownByContext.set(context, teardown);
|
|
2526
2628
|
const reportProgress = (progress, result) => {
|
|
2527
|
-
window.postMessage(
|
|
2629
|
+
window.postMessage(
|
|
2630
|
+
{
|
|
2631
|
+
type: "@netless/_result_save_pdf_",
|
|
2632
|
+
appId: context.appId,
|
|
2633
|
+
progress,
|
|
2634
|
+
result
|
|
2635
|
+
},
|
|
2636
|
+
"*"
|
|
2637
|
+
);
|
|
2528
2638
|
return result;
|
|
2529
2639
|
};
|
|
2530
2640
|
const base64url = async (url) => {
|
|
@@ -2564,7 +2674,9 @@ var NetlessAppPresentation = {
|
|
|
2564
2674
|
}
|
|
2565
2675
|
const scenes = context.getDisplayer().entireScenes()[scenePath];
|
|
2566
2676
|
if (!scenes) {
|
|
2567
|
-
throw new Error(
|
|
2677
|
+
throw new Error(
|
|
2678
|
+
`[Presentation]: no scenes found while exporting PDF: ${scenePath}`
|
|
2679
|
+
);
|
|
2568
2680
|
}
|
|
2569
2681
|
const stage_canvas = document.createElement("canvas");
|
|
2570
2682
|
stage_canvas.width = pdfWidth;
|
|
@@ -2589,20 +2701,32 @@ var NetlessAppPresentation = {
|
|
|
2589
2701
|
const img = document.createElement("img");
|
|
2590
2702
|
await new Promise((resolve, reject) => {
|
|
2591
2703
|
img.onload = () => resolve();
|
|
2592
|
-
img.onerror = () => reject(
|
|
2593
|
-
|
|
2594
|
-
|
|
2704
|
+
img.onerror = () => reject(
|
|
2705
|
+
new Error(
|
|
2706
|
+
`[Presentation]: failed to load PDF page image, page index: ${index}`
|
|
2707
|
+
)
|
|
2708
|
+
);
|
|
2595
2709
|
img.src = url;
|
|
2596
2710
|
});
|
|
2597
2711
|
stage.drawImage(img, 0, 0, width2, height2);
|
|
2598
2712
|
wb.clearRect(0, 0, pdfWidth, pdfHeight);
|
|
2599
2713
|
const name = (_a2 = p.name) != null ? _a2 : String(index + 1);
|
|
2600
2714
|
if (scenes.some((scene) => scene.name == name)) {
|
|
2601
|
-
const camera = {
|
|
2715
|
+
const camera = {
|
|
2716
|
+
centerX: 0,
|
|
2717
|
+
centerY: 0,
|
|
2718
|
+
scale: Math.min(wb_canvas.width / width2, wb_canvas.height / height2)
|
|
2719
|
+
};
|
|
2602
2720
|
const sPath = `${scenePath}/${name}`;
|
|
2603
2721
|
const windowManger = context.getWindowManager();
|
|
2604
2722
|
if (windowManger._appliancePlugin) {
|
|
2605
|
-
await windowManger._appliancePlugin.screenshotToCanvasAsync(
|
|
2723
|
+
await windowManger._appliancePlugin.screenshotToCanvasAsync(
|
|
2724
|
+
wb,
|
|
2725
|
+
sPath,
|
|
2726
|
+
wb_canvas.width,
|
|
2727
|
+
wb_canvas.height,
|
|
2728
|
+
camera
|
|
2729
|
+
);
|
|
2606
2730
|
} else {
|
|
2607
2731
|
await view.screenshotToCanvasAsync(
|
|
2608
2732
|
wb,
|
|
@@ -2649,14 +2773,20 @@ var NetlessAppPresentation = {
|
|
|
2649
2773
|
throw error;
|
|
2650
2774
|
}
|
|
2651
2775
|
};
|
|
2652
|
-
dispose2.add(
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2776
|
+
dispose2.add(
|
|
2777
|
+
listen(
|
|
2778
|
+
window,
|
|
2779
|
+
"message",
|
|
2780
|
+
(ev) => {
|
|
2781
|
+
if (ev.data && ev.data.type == "@netless/_request_save_pdf_" && ev.data.appId == context.appId) {
|
|
2782
|
+
toPdf().catch((err) => {
|
|
2783
|
+
warn(err);
|
|
2784
|
+
reportProgress(100, null);
|
|
2785
|
+
});
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
)
|
|
2789
|
+
);
|
|
2660
2790
|
const setDocsViewReadonly = (bol) => {
|
|
2661
2791
|
app.setDocsViewReadonly(bol);
|
|
2662
2792
|
};
|
|
@@ -2667,19 +2797,52 @@ var NetlessAppPresentation = {
|
|
|
2667
2797
|
scrollbar.setReadonly(bol);
|
|
2668
2798
|
}
|
|
2669
2799
|
};
|
|
2670
|
-
const controller = {
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2800
|
+
const controller = {
|
|
2801
|
+
app,
|
|
2802
|
+
view,
|
|
2803
|
+
context,
|
|
2804
|
+
jumpPage,
|
|
2805
|
+
prevPage,
|
|
2806
|
+
nextPage,
|
|
2807
|
+
jumpPageAsync,
|
|
2808
|
+
prevPageAsync,
|
|
2809
|
+
nextPageAsync,
|
|
2810
|
+
pageState,
|
|
2811
|
+
toPdf,
|
|
2812
|
+
log,
|
|
2813
|
+
setDocsViewReadonly,
|
|
2814
|
+
setReadonly,
|
|
2815
|
+
moveCamera,
|
|
2816
|
+
getOriginScale,
|
|
2817
|
+
getScale,
|
|
2818
|
+
getPageSize,
|
|
2819
|
+
screenshotCurrentPageAsync
|
|
2820
|
+
};
|
|
2821
|
+
dispose2.add(
|
|
2822
|
+
listen(
|
|
2823
|
+
window,
|
|
2824
|
+
"message",
|
|
2825
|
+
(ev) => {
|
|
2826
|
+
if (ev.data === "@netless/_presentation_") {
|
|
2827
|
+
if (typeof window !== "undefined")
|
|
2828
|
+
dispose2.make(() => {
|
|
2829
|
+
const debug = window._presentation_ || (window._presentation_ = /* @__PURE__ */ new Set());
|
|
2830
|
+
debug.add(controller);
|
|
2831
|
+
return () => debug.delete(controller);
|
|
2832
|
+
});
|
|
2833
|
+
console.log(controller);
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
)
|
|
2837
|
+
);
|
|
2838
|
+
return prepareScenesPromise.then(
|
|
2839
|
+
() => controller
|
|
2840
|
+
);
|
|
2841
|
+
},
|
|
2842
|
+
teardown(context) {
|
|
2843
|
+
var _a;
|
|
2844
|
+
(_a = teardownByContext.get(context)) == null ? void 0 : _a();
|
|
2845
|
+
teardownByContext.delete(context);
|
|
2683
2846
|
}
|
|
2684
2847
|
};
|
|
2685
2848
|
var AppPresentation = class extends Presentation {
|
|
@@ -2699,19 +2862,29 @@ var AppPresentation = class extends Presentation {
|
|
|
2699
2862
|
if (0 <= index && index < this.pages.length) {
|
|
2700
2863
|
this.jumpPage(index);
|
|
2701
2864
|
} else {
|
|
2702
|
-
(_a = this.warn) == null ? void 0 : _a.call(
|
|
2865
|
+
(_a = this.warn) == null ? void 0 : _a.call(
|
|
2866
|
+
this,
|
|
2867
|
+
`[Presentation]: page index ${index} out of bounds [0, ${this.pages.length - 1}]`
|
|
2868
|
+
);
|
|
2703
2869
|
}
|
|
2704
2870
|
}
|
|
2705
2871
|
};
|
|
2706
2872
|
function createPresentation(box, pages, jumpPage, pageIndex$, view, thumbnail, useClipView) {
|
|
2707
2873
|
box.mountStyles(style_default);
|
|
2708
|
-
const app = new AppPresentation({
|
|
2874
|
+
const app = new AppPresentation({
|
|
2875
|
+
pages,
|
|
2876
|
+
readonly: box.readonly,
|
|
2877
|
+
jumpPage,
|
|
2878
|
+
thumbnail
|
|
2879
|
+
});
|
|
2709
2880
|
app.box = box;
|
|
2710
2881
|
box.mountContent(app.contentDOM);
|
|
2711
2882
|
box.mountFooter(app.footerDOM);
|
|
2712
|
-
app.dispose.add(
|
|
2713
|
-
|
|
2714
|
-
|
|
2883
|
+
app.dispose.add(
|
|
2884
|
+
pageIndex$.subscribe((pageIndex) => {
|
|
2885
|
+
app.setPageIndex(pageIndex);
|
|
2886
|
+
})
|
|
2887
|
+
);
|
|
2715
2888
|
if (useClipView && view) {
|
|
2716
2889
|
const onCameraUpdatedEffectForMaskView = (0, import_debounce2.default)(() => {
|
|
2717
2890
|
const { width: pageWidth, height: pageHeight } = app.page() || {};
|
|
@@ -2720,8 +2893,12 @@ function createPresentation(box, pages, jumpPage, pageIndex$, view, thumbnail, u
|
|
|
2720
2893
|
}
|
|
2721
2894
|
const { scale } = view.camera;
|
|
2722
2895
|
const { width, height } = view.size;
|
|
2723
|
-
const pageRatioX = Math.round(
|
|
2724
|
-
|
|
2896
|
+
const pageRatioX = Math.round(
|
|
2897
|
+
(1 - pageWidth * scale / width) / 2 * 100
|
|
2898
|
+
);
|
|
2899
|
+
const pageRatioY = Math.round(
|
|
2900
|
+
(1 - pageHeight * scale / height) / 2 * 100
|
|
2901
|
+
);
|
|
2725
2902
|
app.whiteboardDOM.style.clipPath = `inset(${pageRatioY}% ${pageRatioX}%)`;
|
|
2726
2903
|
}, 50);
|
|
2727
2904
|
onCameraUpdatedEffectForMaskView();
|
|
@@ -2746,7 +2923,7 @@ var install = (register, options = {}) => {
|
|
|
2746
2923
|
};
|
|
2747
2924
|
|
|
2748
2925
|
// src/index.ts
|
|
2749
|
-
var version = "0.1.
|
|
2926
|
+
var version = "0.1.13-beta.0";
|
|
2750
2927
|
|
|
2751
2928
|
exports.NetlessAppPresentation = NetlessAppPresentation;
|
|
2752
2929
|
exports.Presentation = Presentation;
|