@netless/window-manager 1.0.0-canary.24 → 1.0.0-canary.27
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/App/AppContext.d.ts +1 -1
- package/dist/App/WhiteboardView.d.ts +6 -4
- package/dist/AppListener.d.ts +0 -2
- package/dist/BoxManager.d.ts +2 -1
- package/dist/BuiltinApps.d.ts +3 -0
- package/dist/Cursor/index.d.ts +3 -2
- package/dist/Helper.d.ts +3 -1
- package/dist/callback.d.ts +5 -0
- package/dist/constants.d.ts +0 -2
- package/dist/index.cjs.js +82 -12
- package/dist/index.d.ts +16 -9
- package/dist/index.es.js +1620 -704
- package/dist/index.umd.js +82 -12
- package/dist/src/App/AppContext.d.ts +78 -0
- package/dist/src/App/AppPageStateImpl.d.ts +21 -0
- package/dist/src/App/AppProxy.d.ts +98 -0
- package/dist/src/App/MagixEvent/index.d.ts +29 -0
- package/dist/src/App/Storage/StorageEvent.d.ts +8 -0
- package/dist/src/App/Storage/index.d.ts +39 -0
- package/dist/src/App/Storage/typings.d.ts +22 -0
- package/dist/src/App/Storage/utils.d.ts +5 -0
- package/dist/src/App/WhiteboardView.d.ts +27 -0
- package/dist/src/App/index.d.ts +4 -0
- package/dist/src/App/type.d.ts +21 -0
- package/dist/src/AppListener.d.ts +19 -0
- package/dist/src/AppManager.d.ts +107 -0
- package/dist/src/AttributesDelegate.d.ts +83 -0
- package/dist/src/BoxEmitter.d.ts +34 -0
- package/dist/src/BoxManager.d.ts +102 -0
- package/dist/src/BuiltinApps.d.ts +8 -0
- package/dist/src/Cursor/Cursor.d.ts +39 -0
- package/dist/src/Cursor/icons.d.ts +3 -0
- package/dist/src/Cursor/index.d.ts +46 -0
- package/dist/src/Helper.d.ts +19 -0
- package/dist/src/InternalEmitter.d.ts +38 -0
- package/dist/src/Page/PageController.d.ts +21 -0
- package/dist/src/Page/index.d.ts +3 -0
- package/dist/src/PageState.d.ts +9 -0
- package/dist/src/ReconnectRefresher.d.ts +24 -0
- package/dist/src/RedoUndo.d.ts +18 -0
- package/dist/src/Register/index.d.ts +28 -0
- package/dist/src/Register/loader.d.ts +4 -0
- package/dist/src/Register/storage.d.ts +8 -0
- package/dist/src/Utils/AppCreateQueue.d.ts +15 -0
- package/dist/src/Utils/Common.d.ts +23 -0
- package/dist/src/Utils/Reactive.d.ts +6 -0
- package/dist/src/Utils/RoomHacker.d.ts +3 -0
- package/dist/src/Utils/error.d.ts +27 -0
- package/dist/src/Utils/log.d.ts +1 -0
- package/dist/src/View/CameraSynchronizer.d.ts +17 -0
- package/dist/src/View/MainView.d.ts +59 -0
- package/dist/src/View/ViewManager.d.ts +13 -0
- package/dist/src/View/ViewSync.d.ts +24 -0
- package/dist/src/callback.d.ts +29 -0
- package/dist/src/constants.d.ts +51 -0
- package/dist/src/image.d.ts +19 -0
- package/dist/src/index.d.ts +267 -0
- package/dist/src/shim.d.ts +11 -0
- package/dist/src/typings.d.ts +88 -0
- package/dist/style.css +1 -1
- package/dist/typings.d.ts +6 -0
- package/docs/app-context.md +68 -26
- package/package.json +10 -5
- package/playwright.config.ts +28 -0
- package/pnpm-lock.yaml +516 -30
- package/src/App/AppContext.ts +14 -6
- package/src/App/AppProxy.ts +17 -7
- package/src/App/WhiteboardView.ts +23 -18
- package/src/AppListener.ts +1 -21
- package/src/AppManager.ts +2 -1
- package/src/BoxManager.ts +32 -24
- package/src/BuiltinApps.ts +5 -0
- package/src/Cursor/Cursor.ts +6 -2
- package/src/Cursor/index.ts +5 -5
- package/src/Helper.ts +23 -5
- package/src/View/CameraSynchronizer.ts +5 -9
- package/src/View/MainView.ts +3 -1
- package/src/callback.ts +1 -0
- package/src/constants.ts +0 -2
- package/src/index.ts +69 -45
- package/src/style.css +2 -45
- package/src/typings.ts +6 -0
- package/vite.config.js +5 -3
package/dist/index.es.js
CHANGED
@@ -19,12 +19,12 @@ var __spreadValues = (a2, b2) => {
|
|
19
19
|
var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
|
20
20
|
import pRetry from "p-retry";
|
21
21
|
import Emittery from "emittery";
|
22
|
-
import { debounce,
|
22
|
+
import { debounce, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isBoolean, isNumber, throttle, isEqual, omitBy, isUndefined, isInteger, orderBy, isEmpty, omit, isFunction, isNull } from "lodash";
|
23
23
|
import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, WhiteVersion, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, ViewMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin } from "white-web-sdk";
|
24
24
|
import { v4 } from "uuid";
|
25
25
|
import { genUID, SideEffectManager } from "side-effect-manager";
|
26
26
|
import { Val, combine, ValManager, withReadonlyValueEnhancer, withValueEnhancer, derive } from "value-enhancer";
|
27
|
-
import { ResizeObserver as ResizeObserver$
|
27
|
+
import { ResizeObserver as ResizeObserver$3 } from "@juggle/resize-observer";
|
28
28
|
import p$1 from "video.js";
|
29
29
|
var Events = /* @__PURE__ */ ((Events2) => {
|
30
30
|
Events2["AppMove"] = "AppMove";
|
@@ -38,8 +38,6 @@ var Events = /* @__PURE__ */ ((Events2) => {
|
|
38
38
|
Events2["SetMainViewSceneIndex"] = "SetMainViewSceneIndex";
|
39
39
|
Events2["SetAppFocusIndex"] = "SetAppFocusIndex";
|
40
40
|
Events2["SwitchViewsToFreedom"] = "SwitchViewsToFreedom";
|
41
|
-
Events2["MoveCamera"] = "MoveCamera";
|
42
|
-
Events2["MoveCameraToContain"] = "MoveCameraToContain";
|
43
41
|
Events2["CursorMove"] = "CursorMove";
|
44
42
|
Events2["RootDirRemoved"] = "RootDirRemoved";
|
45
43
|
Events2["Refresh"] = "Refresh";
|
@@ -473,14 +471,6 @@ class AppListeners {
|
|
473
471
|
this.setMainViewScenePathHandler(data.payload);
|
474
472
|
break;
|
475
473
|
}
|
476
|
-
case Events.MoveCamera: {
|
477
|
-
this.moveCameraHandler(data.payload);
|
478
|
-
break;
|
479
|
-
}
|
480
|
-
case Events.MoveCameraToContain: {
|
481
|
-
this.moveCameraToContainHandler(data.payload);
|
482
|
-
break;
|
483
|
-
}
|
484
474
|
case Events.CursorMove: {
|
485
475
|
this.cursorMoveHandler(data.payload);
|
486
476
|
break;
|
@@ -520,14 +510,6 @@ class AppListeners {
|
|
520
510
|
setViewFocusScenePath(this.manager.mainView, nextScenePath);
|
521
511
|
callbacks$1.emit("mainViewScenePathChange", nextScenePath);
|
522
512
|
};
|
523
|
-
this.moveCameraHandler = (payload) => {
|
524
|
-
if (isEqual(omit(payload, ["animationMode"]), __spreadValues({}, this.manager.mainView.camera)))
|
525
|
-
return;
|
526
|
-
this.manager.mainView.moveCamera(payload);
|
527
|
-
};
|
528
|
-
this.moveCameraToContainHandler = (payload) => {
|
529
|
-
this.manager.mainView.moveCameraToContain(payload);
|
530
|
-
};
|
531
513
|
this.cursorMoveHandler = (payload) => {
|
532
514
|
emitter.emit("cursorMove", payload);
|
533
515
|
};
|
@@ -949,17 +931,25 @@ class WhiteBoardView {
|
|
949
931
|
return this.appProxy.removeSceneByIndex(needRemoveIndex);
|
950
932
|
};
|
951
933
|
const pageState$ = new Val(appProxy.pageState);
|
934
|
+
const baseRect$ = new Val(appProxy.size$.value);
|
935
|
+
const pickCamera = (camera) => pick(camera, ["centerX", "centerY", "scale"]);
|
936
|
+
const camera$ = new Val(pickCamera(this.view.camera));
|
937
|
+
this.baseRect$ = baseRect$;
|
952
938
|
this.pageState$ = pageState$;
|
953
|
-
this.
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
939
|
+
this.baseCamera$ = camera$;
|
940
|
+
this.appProxy.sideEffectManager.add(() => [
|
941
|
+
appProxy.appEmitter.on("pageStateChange", (pageState) => pageState$.setValue(pageState)),
|
942
|
+
appProxy.camera$.subscribe((camera) => {
|
943
|
+
if (camera) {
|
944
|
+
camera$.setValue(pickCamera(camera));
|
945
|
+
}
|
946
|
+
}),
|
947
|
+
appProxy.size$.subscribe((size2) => {
|
948
|
+
if (size2) {
|
949
|
+
baseRect$.setValue(pick(size2, ["width", "height"]));
|
950
|
+
}
|
951
|
+
})
|
952
|
+
]);
|
963
953
|
view.disableCameraTransform = true;
|
964
954
|
}
|
965
955
|
get pageState() {
|
@@ -968,16 +958,21 @@ class WhiteBoardView {
|
|
968
958
|
moveCamera(camera) {
|
969
959
|
this.appProxy.moveCamera(camera);
|
970
960
|
}
|
971
|
-
|
961
|
+
setBaseRect(rect) {
|
972
962
|
this.appProxy.updateSize(rect.width, rect.height);
|
973
963
|
}
|
974
964
|
}
|
975
|
-
const
|
965
|
+
const log = (...args) => {
|
966
|
+
if (WindowManager.debug) {
|
967
|
+
console.log(`[WindowManager]:`, ...args);
|
968
|
+
}
|
969
|
+
};
|
970
|
+
const setupWrapper = (root, target) => {
|
976
971
|
const playground = document.createElement("div");
|
977
972
|
playground.className = "netless-window-manager-playground";
|
978
973
|
const mainViewElement = document.createElement("div");
|
979
974
|
mainViewElement.className = "netless-window-manager-main-view";
|
980
|
-
|
975
|
+
target.appendChild(mainViewElement);
|
981
976
|
root.appendChild(playground);
|
982
977
|
return { playground, mainViewElement };
|
983
978
|
};
|
@@ -1002,6 +997,19 @@ const serializeRoomMembers = (members) => {
|
|
1002
997
|
}, member);
|
1003
998
|
});
|
1004
999
|
};
|
1000
|
+
const createInvisiblePlugin = async (room) => {
|
1001
|
+
try {
|
1002
|
+
const manager = await room.createInvisiblePlugin(WindowManager, {});
|
1003
|
+
return manager;
|
1004
|
+
} catch (error) {
|
1005
|
+
if (error.message === `invisible plugin "WindowManager" exits`) {
|
1006
|
+
await wait(200);
|
1007
|
+
return room.getInvisiblePlugin(WindowManager.kind);
|
1008
|
+
} else {
|
1009
|
+
log("createInvisiblePlugin failed", error);
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
};
|
1005
1013
|
class AppContext {
|
1006
1014
|
constructor(manager, appId, appProxy, appOptions) {
|
1007
1015
|
this.manager = manager;
|
@@ -1033,7 +1041,6 @@ class AppContext {
|
|
1033
1041
|
}
|
1034
1042
|
};
|
1035
1043
|
this.createWhiteBoardView = (params) => {
|
1036
|
-
var _a;
|
1037
1044
|
if (this.whiteBoardView) {
|
1038
1045
|
return this.whiteBoardView;
|
1039
1046
|
}
|
@@ -1049,18 +1056,26 @@ class AppContext {
|
|
1049
1056
|
const viewWrapper = document.createElement("div");
|
1050
1057
|
this._viewWrapper = viewWrapper;
|
1051
1058
|
viewWrapper.className = "window-manager-view-wrapper";
|
1052
|
-
|
1059
|
+
this.box.$main.appendChild(viewWrapper);
|
1053
1060
|
view.divElement = viewWrapper;
|
1054
1061
|
this.appProxy.fireMemberStateChange();
|
1055
1062
|
if (this.isAddApp) {
|
1056
1063
|
this.ensurePageSize(params == null ? void 0 : params.size);
|
1057
1064
|
}
|
1058
1065
|
this.whiteBoardView = new WhiteBoardView(view, this, this.appProxy, this.ensurePageSize);
|
1059
|
-
this.appProxy.sideEffectManager.add(() =>
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1066
|
+
this.appProxy.sideEffectManager.add(() => [
|
1067
|
+
this.box._stageRect$.subscribe((rect) => {
|
1068
|
+
viewWrapper.style.left = `${rect.x}px`;
|
1069
|
+
viewWrapper.style.top = `${rect.y}px`;
|
1070
|
+
viewWrapper.style.width = `${rect.width}px`;
|
1071
|
+
viewWrapper.style.height = `${rect.height}px`;
|
1072
|
+
}),
|
1073
|
+
() => {
|
1074
|
+
return () => {
|
1075
|
+
this.whiteBoardView = void 0;
|
1076
|
+
};
|
1077
|
+
}
|
1078
|
+
]);
|
1064
1079
|
this.appProxy.whiteBoardViewCreated$.setValue(true);
|
1065
1080
|
return this.whiteBoardView;
|
1066
1081
|
};
|
@@ -1147,7 +1162,7 @@ class AppContext {
|
|
1147
1162
|
get members() {
|
1148
1163
|
return this.manager.members;
|
1149
1164
|
}
|
1150
|
-
get
|
1165
|
+
get currentMember() {
|
1151
1166
|
const self2 = findMemberByUid(this.room, this.manager.uid);
|
1152
1167
|
if (!self2) {
|
1153
1168
|
throw new Error(`Member ${this.manager.uid} not found.`);
|
@@ -1230,16 +1245,12 @@ class CameraSynchronizer {
|
|
1230
1245
|
this.remoteCamera = camera;
|
1231
1246
|
this.remoteSize = size2;
|
1232
1247
|
if (this.remoteSize && this.rect) {
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
} else {
|
1237
|
-
scale2 = this.rect.height / size2.height;
|
1238
|
-
}
|
1239
|
-
const nextScale = camera.scale * scale2;
|
1248
|
+
const wScale = this.rect.width / size2.width;
|
1249
|
+
const hScale = this.rect.height / size2.height;
|
1250
|
+
const nextScale = camera.scale * Math.min(wScale, hScale);
|
1240
1251
|
const config = {
|
1241
1252
|
scale: nextScale,
|
1242
|
-
animationMode: AnimationMode.
|
1253
|
+
animationMode: AnimationMode.Continuous
|
1243
1254
|
};
|
1244
1255
|
if (camera.centerX !== null) {
|
1245
1256
|
config.centerX = camera.centerX;
|
@@ -1263,7 +1274,7 @@ class CameraSynchronizer {
|
|
1263
1274
|
const nextScale = this.remoteCamera.scale * scale2;
|
1264
1275
|
(_a = this.view) == null ? void 0 : _a.moveCamera({
|
1265
1276
|
scale: nextScale,
|
1266
|
-
animationMode: AnimationMode.
|
1277
|
+
animationMode: AnimationMode.Continuous
|
1267
1278
|
});
|
1268
1279
|
}
|
1269
1280
|
}
|
@@ -1537,11 +1548,6 @@ const store = new AttributesDelegate({
|
|
1537
1548
|
throw new Error("safeUpdateAttributes not implemented");
|
1538
1549
|
}
|
1539
1550
|
});
|
1540
|
-
const log = (...args) => {
|
1541
|
-
if (WindowManager.debug) {
|
1542
|
-
console.log(`[WindowManager]:`, ...args);
|
1543
|
-
}
|
1544
|
-
};
|
1545
1551
|
class AppProxy {
|
1546
1552
|
constructor(params, manager, appId, isAddApp) {
|
1547
1553
|
var _a;
|
@@ -1765,10 +1771,10 @@ class AppProxy {
|
|
1765
1771
|
});
|
1766
1772
|
this.camera$.setValue(toJS(this.appAttributes.camera));
|
1767
1773
|
}
|
1768
|
-
if (!this.size$.value && box.
|
1769
|
-
const initialRect = this.computedInitialRect(box.
|
1770
|
-
const width = (initialRect == null ? void 0 : initialRect.width) || box.
|
1771
|
-
const height = (initialRect == null ? void 0 : initialRect.height) || box.
|
1774
|
+
if (!this.size$.value && box.stageRect) {
|
1775
|
+
const initialRect = this.computedInitialRect(box.stageRect);
|
1776
|
+
const width = (initialRect == null ? void 0 : initialRect.width) || box.stageRect.width;
|
1777
|
+
const height = (initialRect == null ? void 0 : initialRect.height) || box.stageRect.height;
|
1772
1778
|
this.storeSize({
|
1773
1779
|
id: this.uid,
|
1774
1780
|
width,
|
@@ -1781,7 +1787,7 @@ class AppProxy {
|
|
1781
1787
|
view$: this.view$,
|
1782
1788
|
camera$: this.camera$,
|
1783
1789
|
size$: this.size$,
|
1784
|
-
stageRect$: box.
|
1790
|
+
stageRect$: box._stageRect$,
|
1785
1791
|
storeCamera: this.storeCamera,
|
1786
1792
|
storeSize: this.storeSize
|
1787
1793
|
});
|
@@ -1909,9 +1915,17 @@ class AppProxy {
|
|
1909
1915
|
canOperate: this.manager.canOperate,
|
1910
1916
|
smartPosition: this.isAddApp
|
1911
1917
|
});
|
1918
|
+
const registerParams = appRegister.registered.get(this.kind);
|
1919
|
+
if (registerParams == null ? void 0 : registerParams.contentStyles) {
|
1920
|
+
box == null ? void 0 : box.mountUserStyles(registerParams.contentStyles);
|
1921
|
+
}
|
1912
1922
|
this.box$.setValue(box);
|
1913
1923
|
if (this.isAddApp && this.box) {
|
1914
1924
|
this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
|
1925
|
+
this.store.updateAppState(appId, AppAttributes.Size, {
|
1926
|
+
width: this.box.intrinsicWidth,
|
1927
|
+
height: this.box.intrinsicHeight
|
1928
|
+
});
|
1915
1929
|
this.boxManager.focusBox({ appId }, false);
|
1916
1930
|
}
|
1917
1931
|
} catch (error) {
|
@@ -2087,6 +2101,7 @@ class AppProxy {
|
|
2087
2101
|
this.status = "destroyed";
|
2088
2102
|
try {
|
2089
2103
|
await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
|
2104
|
+
callbacks$1.emit("appClose", { appId: this.id, kind: this.kind, error });
|
2090
2105
|
await this.appEmitter.emit("destroy", { error });
|
2091
2106
|
} catch (error2) {
|
2092
2107
|
console.error("[WindowManager]: notifyApp error", error2.message, error2.stack);
|
@@ -2336,12 +2351,14 @@ class MainViewProxy {
|
|
2336
2351
|
rebind() {
|
2337
2352
|
const divElement = this.mainView.divElement;
|
2338
2353
|
const disableCameraTransform = this.mainView.disableCameraTransform;
|
2354
|
+
const camera = __spreadValues({}, this.mainView.camera);
|
2339
2355
|
this.stop();
|
2340
2356
|
releaseView(this.mainView);
|
2341
2357
|
this.removeMainViewListener();
|
2342
2358
|
this.mainView = this.createMainView();
|
2343
2359
|
this.mainView.disableCameraTransform = disableCameraTransform;
|
2344
2360
|
this.mainView.divElement = divElement;
|
2361
|
+
this.mainView.moveCamera(__spreadProps(__spreadValues({}, camera), { animationMode: AnimationMode.Immediately }));
|
2345
2362
|
this.addMainViewListener();
|
2346
2363
|
this.start();
|
2347
2364
|
}
|
@@ -2613,8 +2630,7 @@ class AppManager {
|
|
2613
2630
|
this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
|
2614
2631
|
};
|
2615
2632
|
this.addAppsChangeListener = () => {
|
2616
|
-
|
2617
|
-
(_a = this.refresher) == null ? void 0 : _a.add("apps", () => {
|
2633
|
+
this.refresher.add("apps", () => {
|
2618
2634
|
return safeListenPropsUpdated(() => this.attributes.apps, () => {
|
2619
2635
|
this.attributesUpdateCallback(this.attributes.apps);
|
2620
2636
|
});
|
@@ -2691,7 +2707,7 @@ class AppManager {
|
|
2691
2707
|
}
|
2692
2708
|
};
|
2693
2709
|
this.closeAll = async () => {
|
2694
|
-
for (const [
|
2710
|
+
for (const [_, appProxy] of this.appProxies.entries()) {
|
2695
2711
|
await appProxy.destroy(true, false, true);
|
2696
2712
|
}
|
2697
2713
|
};
|
@@ -3107,6 +3123,7 @@ class AppManager {
|
|
3107
3123
|
}
|
3108
3124
|
}
|
3109
3125
|
async onReconnected() {
|
3126
|
+
this.attributesUpdateCallback(this.attributes.apps);
|
3110
3127
|
const appProxies = Array.from(this.appProxies.values());
|
3111
3128
|
const reconnected = appProxies.map((appProxy) => {
|
3112
3129
|
return appProxy.onReconnected();
|
@@ -3303,7 +3320,7 @@ var startLoop = function() {
|
|
3303
3320
|
if (!isProcessing)
|
3304
3321
|
onNextFrame(processFrame);
|
3305
3322
|
};
|
3306
|
-
var clamp$
|
3323
|
+
var clamp$2 = function(min, max) {
|
3307
3324
|
return function(v2) {
|
3308
3325
|
return Math.max(Math.min(v2, max), min);
|
3309
3326
|
};
|
@@ -3321,7 +3338,7 @@ var number = {
|
|
3321
3338
|
return v2;
|
3322
3339
|
}
|
3323
3340
|
};
|
3324
|
-
var alpha = __assign(__assign({}, number), { transform: clamp$
|
3341
|
+
var alpha = __assign(__assign({}, number), { transform: clamp$2(0, 1) });
|
3325
3342
|
var scale = __assign(__assign({}, number), { default: 1 });
|
3326
3343
|
var createUnitType = function(unit) {
|
3327
3344
|
return {
|
@@ -3345,7 +3362,7 @@ var progressPercentage = __assign(__assign({}, percent), { parse: function(v2) {
|
|
3345
3362
|
var getValueFromFunctionString = function(value) {
|
3346
3363
|
return value.substring(value.indexOf("(") + 1, value.lastIndexOf(")"));
|
3347
3364
|
};
|
3348
|
-
var clampRgbUnit = clamp$
|
3365
|
+
var clampRgbUnit = clamp$2(0, 255);
|
3349
3366
|
var isRgba = function(v2) {
|
3350
3367
|
return v2.red !== void 0;
|
3351
3368
|
};
|
@@ -3984,190 +4001,422 @@ var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
|
|
3984
4001
|
}
|
3985
4002
|
return true;
|
3986
4003
|
};
|
3987
|
-
var
|
3988
|
-
|
3989
|
-
|
3990
|
-
|
3991
|
-
|
3992
|
-
|
3993
|
-
|
3994
|
-
|
3995
|
-
|
3996
|
-
|
3997
|
-
|
3998
|
-
return
|
3999
|
-
}
|
4000
|
-
|
4001
|
-
|
4002
|
-
|
4003
|
-
|
4004
|
-
|
4005
|
-
|
4006
|
-
|
4007
|
-
|
4008
|
-
|
4004
|
+
var shadowStyles = /* @__PURE__ */ (() => '.telebox-quarantine {\n all: initial;\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n}\n\n.telebox-body-wrap {\n color: #191919;\n color: var(--tele-box-color, #191919);\n flex: 1;\n width: 100%;\n overflow: hidden;\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n}\n\n.telebox-content {\n width: 100%;\n height: 100%;\n position: relative;\n background-color: #f9f9f9;\n background-color: var(--tele-manager-container-background, #f9f9f9);\n}\n\n.telebox-box-stage {\n position: absolute;\n z-index: 1;\n overflow: hidden;\n background-color: #fff;\n background-color: var(--tele-manager-stage-background, #fff);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);\n box-shadow: var(--tele-manager-stage-shadow, 0px 0px 16px rgba(0, 0, 0, 0.08));\n}\n\n.telebox-footer-wrap {\n flex-shrink: 0;\n display: flex;\n flex-direction: column;\n}\n\n.telebox-footer-wrap::before {\n content: "";\n display: block;\n flex: 1;\n}\n\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n\n.telebox-color-scheme-dark .telebox-body-wrap {\n color: #e9e9e9;\n color: var(--tele-box-color-dark, #e9e9e9);\n}\n\n.telebox-color-scheme-dark .telebox-content {\n background-color: #25282e;\n background-color: var(--tele-manager-container-background-dark, #25282e);\n}\n\n.telebox-color-scheme-dark .telebox-box-stage {\n background-color: #272a30;\n background-color: var(--tele-manager-stage-background-dark, #272a30);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.24);\n box-shadow: var(--tele-manager-stage-shadow-dark, 0px 0px 16px rgba(0, 0, 0, 0.24));\n}')();
|
4005
|
+
var TELE_BOX_COLOR_SCHEME = /* @__PURE__ */ ((TELE_BOX_COLOR_SCHEME2) => {
|
4006
|
+
TELE_BOX_COLOR_SCHEME2["Light"] = "light";
|
4007
|
+
TELE_BOX_COLOR_SCHEME2["Dark"] = "dark";
|
4008
|
+
TELE_BOX_COLOR_SCHEME2["Auto"] = "auto";
|
4009
|
+
return TELE_BOX_COLOR_SCHEME2;
|
4010
|
+
})(TELE_BOX_COLOR_SCHEME || {});
|
4011
|
+
var TELE_BOX_STATE = /* @__PURE__ */ ((TELE_BOX_STATE2) => {
|
4012
|
+
TELE_BOX_STATE2["Normal"] = "normal";
|
4013
|
+
TELE_BOX_STATE2["Minimized"] = "minimized";
|
4014
|
+
TELE_BOX_STATE2["Maximized"] = "maximized";
|
4015
|
+
return TELE_BOX_STATE2;
|
4016
|
+
})(TELE_BOX_STATE || {});
|
4017
|
+
var TELE_BOX_EVENT = /* @__PURE__ */ ((TELE_BOX_EVENT2) => {
|
4018
|
+
TELE_BOX_EVENT2["DarkMode"] = "dark_mode";
|
4019
|
+
TELE_BOX_EVENT2["PrefersColorScheme"] = "prefers_color_scheme";
|
4020
|
+
TELE_BOX_EVENT2["Close"] = "close";
|
4021
|
+
TELE_BOX_EVENT2["Focus"] = "focus";
|
4022
|
+
TELE_BOX_EVENT2["Blur"] = "blur";
|
4023
|
+
TELE_BOX_EVENT2["IntrinsicMove"] = "intrinsic_move";
|
4024
|
+
TELE_BOX_EVENT2["IntrinsicResize"] = "intrinsic_resize";
|
4025
|
+
TELE_BOX_EVENT2["ZIndex"] = "z_index";
|
4026
|
+
TELE_BOX_EVENT2["State"] = "state";
|
4027
|
+
TELE_BOX_EVENT2["Minimized"] = "minimized";
|
4028
|
+
TELE_BOX_EVENT2["Maximized"] = "maximized";
|
4029
|
+
TELE_BOX_EVENT2["Readonly"] = "readonly";
|
4030
|
+
TELE_BOX_EVENT2["Destroyed"] = "destroyed";
|
4031
|
+
return TELE_BOX_EVENT2;
|
4032
|
+
})(TELE_BOX_EVENT || {});
|
4033
|
+
var TELE_BOX_DELEGATE_EVENT = /* @__PURE__ */ ((TELE_BOX_DELEGATE_EVENT2) => {
|
4034
|
+
TELE_BOX_DELEGATE_EVENT2["Close"] = "close";
|
4035
|
+
TELE_BOX_DELEGATE_EVENT2["Maximize"] = "maximize";
|
4036
|
+
TELE_BOX_DELEGATE_EVENT2["Minimize"] = "minimize";
|
4037
|
+
return TELE_BOX_DELEGATE_EVENT2;
|
4038
|
+
})(TELE_BOX_DELEGATE_EVENT || {});
|
4039
|
+
var TELE_BOX_RESIZE_HANDLE = /* @__PURE__ */ ((TELE_BOX_RESIZE_HANDLE2) => {
|
4040
|
+
TELE_BOX_RESIZE_HANDLE2["North"] = "n";
|
4041
|
+
TELE_BOX_RESIZE_HANDLE2["South"] = "s";
|
4042
|
+
TELE_BOX_RESIZE_HANDLE2["West"] = "w";
|
4043
|
+
TELE_BOX_RESIZE_HANDLE2["East"] = "e";
|
4044
|
+
TELE_BOX_RESIZE_HANDLE2["NorthWest"] = "nw";
|
4045
|
+
TELE_BOX_RESIZE_HANDLE2["NorthEast"] = "ne";
|
4046
|
+
TELE_BOX_RESIZE_HANDLE2["SouthEast"] = "se";
|
4047
|
+
TELE_BOX_RESIZE_HANDLE2["SouthWest"] = "sw";
|
4048
|
+
return TELE_BOX_RESIZE_HANDLE2;
|
4049
|
+
})(TELE_BOX_RESIZE_HANDLE || {});
|
4050
|
+
const TeleBoxDragHandleType = "dh";
|
4051
|
+
function clamp$1(value, min, max) {
|
4052
|
+
return Math.min(Math.max(value, min), max);
|
4009
4053
|
}
|
4010
|
-
function
|
4011
|
-
|
4054
|
+
function preventEvent$1(ev) {
|
4055
|
+
ev.stopPropagation();
|
4056
|
+
if (ev.cancelable) {
|
4057
|
+
ev.preventDefault();
|
4058
|
+
}
|
4012
4059
|
}
|
4013
|
-
|
4014
|
-
|
4060
|
+
let defaultBoxCount = 1;
|
4061
|
+
function getBoxDefaultName() {
|
4062
|
+
return `New Box ${defaultBoxCount++}`;
|
4015
4063
|
}
|
4016
|
-
class
|
4017
|
-
constructor({
|
4018
|
-
|
4019
|
-
|
4020
|
-
|
4021
|
-
|
4022
|
-
|
4023
|
-
|
4024
|
-
|
4064
|
+
class DefaultTitleBar {
|
4065
|
+
constructor({
|
4066
|
+
readonly$,
|
4067
|
+
state$,
|
4068
|
+
title$,
|
4069
|
+
buttons,
|
4070
|
+
onEvent,
|
4071
|
+
onDragStart,
|
4072
|
+
namespace = "telebox"
|
4073
|
+
}) {
|
4074
|
+
this.sideEffect = new SideEffectManager();
|
4075
|
+
this.lastTitleBarClick = {
|
4076
|
+
timestamp: 0,
|
4077
|
+
clientX: -100,
|
4078
|
+
clientY: -100
|
4079
|
+
};
|
4080
|
+
this.handleTitleBarClick = (ev) => {
|
4081
|
+
var _a;
|
4082
|
+
if (!ev.isPrimary || this.readonly$.value) {
|
4025
4083
|
return;
|
4026
|
-
|
4027
|
-
|
4028
|
-
i3 - this.lastTitleBarClick.timestamp <= 500 ? Math.abs(e3.clientX - this.lastTitleBarClick.clientX) <= 5 && Math.abs(e3.clientY - this.lastTitleBarClick.clientY) <= 5 && this.onEvent && this.onEvent({ type: _.Maximize }) : this.onDragStart && this.onDragStart(e3), this.lastTitleBarClick.timestamp = i3, this.lastTitleBarClick.clientX = e3.clientX, this.lastTitleBarClick.clientY = e3.clientY;
|
4029
|
-
}, this.lastTitleBarTouch = { timestamp: 0, clientX: -100, clientY: -100 }, this.handleTitleBarTouch = (e3) => {
|
4030
|
-
var t3;
|
4031
|
-
if (this.readonly$.value)
|
4084
|
+
}
|
4085
|
+
if (ev.button !== 0) {
|
4032
4086
|
return;
|
4033
|
-
|
4087
|
+
}
|
4088
|
+
if ((_a = ev.target.dataset) == null ? void 0 : _a.teleTitleBarNoDblClick) {
|
4034
4089
|
return;
|
4035
|
-
|
4036
|
-
|
4037
|
-
|
4038
|
-
|
4090
|
+
}
|
4091
|
+
preventEvent$1(ev);
|
4092
|
+
const now = Date.now();
|
4093
|
+
if (now - this.lastTitleBarClick.timestamp <= 500) {
|
4094
|
+
if (Math.abs(ev.clientX - this.lastTitleBarClick.clientX) <= 5 && Math.abs(ev.clientY - this.lastTitleBarClick.clientY) <= 5) {
|
4095
|
+
if (this.onEvent) {
|
4096
|
+
this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
|
4097
|
+
}
|
4098
|
+
}
|
4099
|
+
} else if (this.onDragStart) {
|
4100
|
+
this.onDragStart(ev);
|
4101
|
+
}
|
4102
|
+
this.lastTitleBarClick.timestamp = now;
|
4103
|
+
this.lastTitleBarClick.clientX = ev.clientX;
|
4104
|
+
this.lastTitleBarClick.clientY = ev.clientY;
|
4105
|
+
};
|
4106
|
+
this.readonly$ = readonly$;
|
4107
|
+
this.state$ = state$;
|
4108
|
+
this.title$ = title$;
|
4109
|
+
this.onEvent = onEvent;
|
4110
|
+
this.onDragStart = onDragStart;
|
4111
|
+
this.namespace = namespace;
|
4112
|
+
this.buttons = buttons || [
|
4113
|
+
{
|
4114
|
+
type: TELE_BOX_DELEGATE_EVENT.Minimize,
|
4115
|
+
iconClassName: this.wrapClassName("titlebar-icon-minimize")
|
4116
|
+
},
|
4117
|
+
{
|
4118
|
+
type: TELE_BOX_DELEGATE_EVENT.Maximize,
|
4119
|
+
iconClassName: this.wrapClassName("titlebar-icon-maximize"),
|
4120
|
+
isActive: (state) => state === TELE_BOX_STATE.Maximized
|
4121
|
+
},
|
4122
|
+
{
|
4123
|
+
type: TELE_BOX_DELEGATE_EVENT.Close,
|
4124
|
+
iconClassName: this.wrapClassName("titlebar-icon-close")
|
4125
|
+
}
|
4126
|
+
];
|
4127
|
+
this.$dragArea = this.renderDragArea();
|
4039
4128
|
}
|
4040
4129
|
render() {
|
4041
4130
|
if (!this.$titleBar) {
|
4042
|
-
this.$titleBar = document.createElement("div")
|
4043
|
-
|
4044
|
-
|
4045
|
-
|
4046
|
-
|
4047
|
-
const
|
4048
|
-
|
4049
|
-
|
4050
|
-
|
4051
|
-
|
4052
|
-
|
4053
|
-
|
4054
|
-
|
4055
|
-
|
4056
|
-
|
4131
|
+
this.$titleBar = document.createElement("div");
|
4132
|
+
this.$titleBar.className = this.wrapClassName("titlebar");
|
4133
|
+
const $titleArea = document.createElement("div");
|
4134
|
+
$titleArea.className = this.wrapClassName("title-area");
|
4135
|
+
$titleArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
|
4136
|
+
const $title = document.createElement("h1");
|
4137
|
+
$title.className = this.wrapClassName("title");
|
4138
|
+
$title.dataset.teleBoxHandle = TeleBoxDragHandleType;
|
4139
|
+
$titleArea.appendChild($title);
|
4140
|
+
$titleArea.appendChild(this.$dragArea);
|
4141
|
+
const $buttonsContainer = document.createElement("div");
|
4142
|
+
$buttonsContainer.className = this.wrapClassName("titlebar-btns");
|
4143
|
+
this.buttons.forEach(({ iconClassName }, i2) => {
|
4144
|
+
const teleTitleBarBtnIndex = String(i2);
|
4145
|
+
const $btn = document.createElement("button");
|
4146
|
+
$btn.className = `${this.wrapClassName("titlebar-btn")} ${iconClassName}`;
|
4147
|
+
$btn.dataset.teleTitleBarBtnIndex = teleTitleBarBtnIndex;
|
4148
|
+
$btn.dataset.teleTitleBarNoDblClick = "true";
|
4149
|
+
$buttonsContainer.appendChild($btn);
|
4150
|
+
});
|
4151
|
+
this.sideEffect.addDisposer(this.title$.subscribe((title) => {
|
4152
|
+
$title.textContent = title;
|
4153
|
+
$title.title = title;
|
4154
|
+
}), "render-title");
|
4155
|
+
this.sideEffect.addDisposer(this.state$.subscribe((state) => {
|
4156
|
+
this.buttons.forEach((btn, i2) => {
|
4157
|
+
var _a;
|
4158
|
+
if (btn.isActive) {
|
4159
|
+
(_a = $buttonsContainer.children[i2]) == null ? void 0 : _a.classList.toggle("is-active", btn.isActive(state));
|
4160
|
+
}
|
4057
4161
|
});
|
4058
|
-
}), "render-state-btns")
|
4059
|
-
|
4060
|
-
|
4162
|
+
}), "render-state-btns");
|
4163
|
+
this.sideEffect.addEventListener($buttonsContainer, "pointerup", (ev) => {
|
4164
|
+
var _a;
|
4165
|
+
if (!ev.isPrimary || this.readonly$.value) {
|
4061
4166
|
return;
|
4062
|
-
const i3 = e3.target, s2 = Number((t3 = i3.dataset) == null ? void 0 : t3.teleTitleBarBtnIndex);
|
4063
|
-
if (!Number.isNaN(s2) && s2 < this.buttons.length) {
|
4064
|
-
k$1(e3);
|
4065
|
-
const t4 = this.buttons[s2];
|
4066
|
-
this.onEvent && this.onEvent({ type: t4.type, value: t4.value });
|
4067
4167
|
}
|
4068
|
-
|
4168
|
+
const target = ev.target;
|
4169
|
+
const teleTitleBarBtnIndex = Number((_a = target.dataset) == null ? void 0 : _a.teleTitleBarBtnIndex);
|
4170
|
+
if (!Number.isNaN(teleTitleBarBtnIndex) && teleTitleBarBtnIndex < this.buttons.length) {
|
4171
|
+
preventEvent$1(ev);
|
4172
|
+
const btn = this.buttons[teleTitleBarBtnIndex];
|
4173
|
+
if (this.onEvent) {
|
4174
|
+
this.onEvent({
|
4175
|
+
type: btn.type,
|
4176
|
+
value: btn.value
|
4177
|
+
});
|
4178
|
+
}
|
4179
|
+
}
|
4180
|
+
}, {}, "render-btns-container-click");
|
4181
|
+
this.$titleBar.appendChild($titleArea);
|
4182
|
+
this.$titleBar.appendChild($buttonsContainer);
|
4069
4183
|
}
|
4070
4184
|
return this.$titleBar;
|
4071
4185
|
}
|
4072
4186
|
renderDragArea() {
|
4073
|
-
const
|
4074
|
-
|
4187
|
+
const $dragArea = document.createElement("div");
|
4188
|
+
$dragArea.className = this.wrapClassName("drag-area");
|
4189
|
+
$dragArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
|
4190
|
+
this.sideEffect.addEventListener($dragArea, "pointerdown", this.handleTitleBarClick);
|
4191
|
+
return $dragArea;
|
4075
4192
|
}
|
4076
4193
|
dragHandle() {
|
4077
4194
|
return this.$titleBar;
|
4078
4195
|
}
|
4079
|
-
wrapClassName(
|
4080
|
-
return `${this.namespace}-${
|
4196
|
+
wrapClassName(className) {
|
4197
|
+
return `${this.namespace}-${className}`;
|
4081
4198
|
}
|
4082
4199
|
destroy() {
|
4083
|
-
this.sideEffect.flushAll()
|
4084
|
-
|
4085
|
-
|
4086
|
-
|
4087
|
-
|
4088
|
-
|
4089
|
-
if (t3 <= 0 || e3.width <= 0 || e3.height <= 0)
|
4090
|
-
return e3;
|
4091
|
-
const i3 = e3.width * t3;
|
4092
|
-
if (i3 === e3.height)
|
4093
|
-
return e3;
|
4094
|
-
if (i3 < e3.height)
|
4095
|
-
return { x: 0, y: (e3.height - i3) / 2, width: e3.width, height: i3 };
|
4096
|
-
const s3 = e3.height / t3;
|
4097
|
-
return { x: (e3.width - s3) / 2, y: 0, width: s3, height: e3.height };
|
4098
|
-
}, { compare: shallowequal }), this._sideEffect.addDisposer(combine([a2, s2]).subscribe(([e3, t3]) => {
|
4099
|
-
var i3;
|
4100
|
-
e3 && t3 ? e3.appendChild(this.render()) : ((i3 = this.$boxStage) == null ? void 0 : i3.parentNode) && this.$boxStage.remove();
|
4101
|
-
}));
|
4200
|
+
this.sideEffect.flushAll();
|
4201
|
+
if (this.$titleBar) {
|
4202
|
+
this.$titleBar = void 0;
|
4203
|
+
this.onDragStart = void 0;
|
4204
|
+
this.onEvent = void 0;
|
4205
|
+
}
|
4102
4206
|
}
|
4103
|
-
|
4104
|
-
|
4105
|
-
|
4106
|
-
|
4107
|
-
e2.className = this.wrapClassName("box-stage-container");
|
4108
|
-
const t2 = document.createElement("div");
|
4109
|
-
t2.className = this.wrapClassName("box-stage-mask");
|
4110
|
-
const i2 = document.createElement("div");
|
4111
|
-
i2.className = this.wrapClassName("box-stage-mask");
|
4112
|
-
const s2 = document.createElement("div");
|
4113
|
-
s2.className = this.wrapClassName("box-stage-frame");
|
4114
|
-
const [a2, n2, o2, r2] = ["M0 8V0h8v2H2v6H0Z", "M8 8V0H0v2h6v6h2Z", "M0 0v8h8V6H2V0H0Z", "M8 0v8H0V6h6V0h2Z"].map((e3, t3) => {
|
4115
|
-
const i3 = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
4116
|
-
i3.setAttribute("viewBox", "0 0 8 8"), i3.setAttribute("class", `${this.wrapClassName("box-stage-frame-corner")} is-${t3}`);
|
4117
|
-
const s3 = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
4118
|
-
return s3.setAttribute("d", e3), s3.setAttribute("fill", "#3381FF"), i3.appendChild(s3), i3;
|
4119
|
-
});
|
4120
|
-
return s2.appendChild(a2), s2.appendChild(o2), s2.appendChild(n2), s2.appendChild(r2), e2.appendChild(t2), e2.appendChild(s2), e2.appendChild(i2), this._sideEffect.addDisposer(this.highlightStage$.subscribe((t3) => {
|
4121
|
-
e2.classList.toggle("is-active", t3);
|
4122
|
-
})), this._sideEffect.addDisposer(combine([this.highlightStage$, this.stageRect$]).subscribe(([s3, a3]) => {
|
4123
|
-
s3 && (a3.x > 0 ? (e2.style.flexDirection = "row", t2.style.width = `${a3.x}px`, t2.style.height = "", i2.style.width = `${a3.x}px`, i2.style.height = "") : a3.y > 0 && (e2.style.flexDirection = "column", t2.style.width = "", t2.style.height = `${a3.y}px`, i2.style.width = "", i2.style.height = `${a3.y}px`));
|
4124
|
-
})), this.$boxStage = e2, e2;
|
4207
|
+
}
|
4208
|
+
function calcStageRect([rootRect, ratio]) {
|
4209
|
+
if (ratio <= 0 || rootRect.width <= 0 || rootRect.height <= 0) {
|
4210
|
+
return rootRect;
|
4125
4211
|
}
|
4126
|
-
|
4127
|
-
|
4212
|
+
const preferredHeight = rootRect.width * ratio;
|
4213
|
+
if (preferredHeight === rootRect.height) {
|
4214
|
+
return rootRect;
|
4128
4215
|
}
|
4129
|
-
|
4130
|
-
return
|
4131
|
-
|
4132
|
-
|
4133
|
-
|
4134
|
-
|
4135
|
-
|
4136
|
-
|
4137
|
-
|
4138
|
-
|
4139
|
-
|
4140
|
-
|
4141
|
-
|
4142
|
-
|
4143
|
-
|
4144
|
-
|
4216
|
+
if (preferredHeight < rootRect.height) {
|
4217
|
+
return {
|
4218
|
+
x: 0,
|
4219
|
+
y: (rootRect.height - preferredHeight) / 2,
|
4220
|
+
width: rootRect.width,
|
4221
|
+
height: preferredHeight
|
4222
|
+
};
|
4223
|
+
}
|
4224
|
+
const preferredWidth = rootRect.height / ratio;
|
4225
|
+
return {
|
4226
|
+
x: (rootRect.width - preferredWidth) / 2,
|
4227
|
+
y: 0,
|
4228
|
+
width: preferredWidth,
|
4229
|
+
height: rootRect.height
|
4230
|
+
};
|
4231
|
+
}
|
4232
|
+
const ResizeObserver$1$1 = window.ResizeObserver || ResizeObserver$3;
|
4233
|
+
class TeleBox {
|
4234
|
+
constructor({
|
4235
|
+
id: id2 = genUID(),
|
4236
|
+
title = getBoxDefaultName(),
|
4237
|
+
namespace = "telebox",
|
4238
|
+
visible = true,
|
4239
|
+
width = 0.5,
|
4240
|
+
height = 0.5,
|
4241
|
+
minWidth = 0,
|
4242
|
+
minHeight = 0,
|
4243
|
+
x: x2 = 0.1,
|
4244
|
+
y: y2 = 0.1,
|
4245
|
+
resizable = true,
|
4246
|
+
draggable = true,
|
4247
|
+
boxRatio = -1,
|
4248
|
+
focus = false,
|
4249
|
+
zIndex = 100,
|
4250
|
+
stageRatio = null,
|
4251
|
+
enableShadowDOM = true,
|
4252
|
+
titleBar,
|
4253
|
+
content,
|
4254
|
+
stage,
|
4255
|
+
footer,
|
4256
|
+
styles: styles2,
|
4257
|
+
userStyles,
|
4258
|
+
bodyStyle = null,
|
4259
|
+
stageStyle = null,
|
4260
|
+
darkMode$,
|
4261
|
+
fence$,
|
4262
|
+
minimized$,
|
4263
|
+
maximized$,
|
4264
|
+
readonly$,
|
4265
|
+
root,
|
4266
|
+
rootRect$,
|
4267
|
+
managerStageRect$,
|
4268
|
+
managerStageRatio$,
|
4269
|
+
defaultBoxBodyStyle$,
|
4270
|
+
defaultBoxStageStyle$,
|
4271
|
+
collectorRect$
|
4272
|
+
}) {
|
4273
|
+
this.events = new Emittery();
|
4274
|
+
this._delegateEvents = new Emittery();
|
4275
|
+
this.handleTrackStart = (ev) => {
|
4276
|
+
var _a;
|
4277
|
+
return (_a = this._handleTrackStart) == null ? void 0 : _a.call(this, ev);
|
4278
|
+
};
|
4279
|
+
this._sideEffect = new SideEffectManager();
|
4280
|
+
this.id = id2;
|
4281
|
+
this.namespace = namespace;
|
4282
|
+
this.enableShadowDOM = enableShadowDOM;
|
4283
|
+
const valManager = new ValManager();
|
4284
|
+
this._sideEffect.addDisposer(() => valManager.destroy());
|
4285
|
+
const title$ = new Val(title);
|
4286
|
+
const visible$ = new Val(visible);
|
4287
|
+
const resizable$ = new Val(resizable);
|
4288
|
+
const draggable$ = new Val(draggable);
|
4289
|
+
const boxRatio$ = new Val(boxRatio);
|
4290
|
+
const zIndex$ = new Val(zIndex);
|
4291
|
+
const focus$ = new Val(focus);
|
4292
|
+
const state$ = combine([minimized$, maximized$], ([minimized, maximized]) => minimized ? TELE_BOX_STATE.Minimized : maximized ? TELE_BOX_STATE.Maximized : TELE_BOX_STATE.Normal);
|
4293
|
+
const minSize$ = new Val({
|
4294
|
+
width: clamp$1(minWidth, 0, 1),
|
4295
|
+
height: clamp$1(minHeight, 0, 1)
|
4296
|
+
}, { compare: shallowequal });
|
4297
|
+
const pxMinSize$ = combine([minSize$, managerStageRect$], ([minSize, managerStageRect]) => ({
|
4298
|
+
width: minSize.width * managerStageRect.width,
|
4299
|
+
height: minSize.height * managerStageRect.height
|
4300
|
+
}), { compare: shallowequal });
|
4301
|
+
const intrinsicSize$ = new Val({ width, height }, { compare: shallowequal });
|
4302
|
+
this._sideEffect.addDisposer(minSize$.reaction((minSize, skipUpdate) => {
|
4303
|
+
intrinsicSize$.setValue({
|
4304
|
+
width: Math.max(width, minSize.width),
|
4305
|
+
height: Math.max(height, minSize.height)
|
4306
|
+
}, skipUpdate);
|
4145
4307
|
}));
|
4146
|
-
const
|
4147
|
-
|
4148
|
-
|
4149
|
-
|
4150
|
-
|
4151
|
-
|
4152
|
-
|
4153
|
-
|
4154
|
-
},
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
|
4308
|
+
const intrinsicCoord$ = new Val({ x: x2, y: y2 }, { compare: shallowequal });
|
4309
|
+
const pxIntrinsicSize$ = combine([intrinsicSize$, managerStageRect$], ([size2, managerStageRect]) => ({
|
4310
|
+
width: managerStageRect.width * size2.width,
|
4311
|
+
height: managerStageRect.height * size2.height
|
4312
|
+
}), { compare: shallowequal });
|
4313
|
+
const pxIntrinsicCoord$ = combine([intrinsicCoord$, managerStageRect$], ([intrinsicCoord, managerStageRect]) => ({
|
4314
|
+
x: intrinsicCoord.x * managerStageRect.width,
|
4315
|
+
y: intrinsicCoord.y * managerStageRect.height
|
4316
|
+
}), { compare: shallowequal });
|
4317
|
+
const bodyStyle$ = new Val(bodyStyle);
|
4318
|
+
const stageStyle$ = new Val(stageStyle);
|
4319
|
+
const contentRoot$ = new Val(null);
|
4320
|
+
const bodyRect$ = new Val(managerStageRect$.value, {
|
4321
|
+
compare: shallowequal
|
4322
|
+
});
|
4323
|
+
const stageRatio$ = new Val(stageRatio);
|
4324
|
+
const finalStageRatio$ = combine([stageRatio$, managerStageRatio$], ([stageRatio2, managerStageRatio]) => stageRatio2 != null ? stageRatio2 : managerStageRatio);
|
4325
|
+
const stageRect$ = combine([bodyRect$, finalStageRatio$], calcStageRect, { compare: shallowequal });
|
4326
|
+
const propsValConfig = {
|
4327
|
+
darkMode: darkMode$,
|
4328
|
+
fence: fence$,
|
4329
|
+
minimized: minimized$,
|
4330
|
+
maximized: maximized$,
|
4331
|
+
readonly: readonly$,
|
4332
|
+
rootRect: rootRect$,
|
4333
|
+
managerStageRect: managerStageRect$,
|
4334
|
+
defaultBoxBodyStyle: defaultBoxBodyStyle$,
|
4335
|
+
defaultBoxStageStyle: defaultBoxStageStyle$,
|
4336
|
+
collectorRect: collectorRect$
|
4337
|
+
};
|
4338
|
+
withReadonlyValueEnhancer(this, propsValConfig);
|
4339
|
+
const myReadonlyValConfig = {
|
4340
|
+
zIndex: zIndex$,
|
4341
|
+
focus: focus$,
|
4342
|
+
state: state$,
|
4343
|
+
minSize: minSize$,
|
4344
|
+
pxMinSize: pxMinSize$,
|
4345
|
+
intrinsicSize: intrinsicSize$,
|
4346
|
+
intrinsicCoord: intrinsicCoord$,
|
4347
|
+
pxIntrinsicSize: pxIntrinsicSize$,
|
4348
|
+
pxIntrinsicCoord: pxIntrinsicCoord$,
|
4349
|
+
bodyRect: bodyRect$,
|
4350
|
+
stageRect: stageRect$
|
4351
|
+
};
|
4352
|
+
withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
|
4353
|
+
const valConfig = {
|
4354
|
+
title: title$,
|
4355
|
+
visible: visible$,
|
4356
|
+
resizable: resizable$,
|
4357
|
+
draggable: draggable$,
|
4358
|
+
boxRatio: boxRatio$,
|
4359
|
+
stageRatio: stageRatio$,
|
4360
|
+
bodyStyle: bodyStyle$,
|
4361
|
+
stageStyle: stageStyle$
|
4362
|
+
};
|
4363
|
+
withValueEnhancer(this, valConfig, valManager);
|
4364
|
+
this.titleBar = titleBar || new DefaultTitleBar({
|
4365
|
+
readonly$,
|
4366
|
+
state$,
|
4367
|
+
title$,
|
4368
|
+
namespace: this.namespace,
|
4369
|
+
onDragStart: (event) => {
|
4370
|
+
var _a;
|
4371
|
+
return (_a = this._handleTrackStart) == null ? void 0 : _a.call(this, event);
|
4372
|
+
},
|
4373
|
+
onEvent: (event) => this._delegateEvents.emit(event.type)
|
4374
|
+
});
|
4375
|
+
this._sideEffect.addDisposer(boxRatio$.subscribe((boxRatio2) => {
|
4376
|
+
if (boxRatio2 > 0) {
|
4377
|
+
this.transform(pxIntrinsicCoord$.value.x, pxIntrinsicCoord$.value.y, pxIntrinsicSize$.value.width, pxIntrinsicSize$.value.height);
|
4378
|
+
}
|
4379
|
+
}));
|
4380
|
+
this._sideEffect.addDisposer(fence$.subscribe((fence) => {
|
4381
|
+
if (fence) {
|
4382
|
+
this.move(pxIntrinsicCoord$.value.x, pxIntrinsicCoord$.value.y);
|
4383
|
+
}
|
4384
|
+
}));
|
4385
|
+
this.$box = this._render();
|
4386
|
+
contentRoot$.setValue(this.$content.parentElement);
|
4387
|
+
content && this.mountContent(content);
|
4388
|
+
stage && this.mountStage(stage);
|
4389
|
+
footer && this.mountFooter(footer);
|
4390
|
+
styles2 && this.mountStyles(styles2);
|
4391
|
+
userStyles && this.mountUserStyles(userStyles);
|
4392
|
+
root.appendChild(this.$box);
|
4393
|
+
const watchValEvent = (val, event) => {
|
4394
|
+
this._sideEffect.addDisposer(val.reaction((v2, skipUpdate) => {
|
4395
|
+
if (!skipUpdate) {
|
4396
|
+
this.events.emit(event, v2);
|
4397
|
+
}
|
4162
4398
|
}));
|
4163
4399
|
};
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
|
4169
|
-
|
4170
|
-
|
4400
|
+
watchValEvent(darkMode$, TELE_BOX_EVENT.DarkMode);
|
4401
|
+
watchValEvent(readonly$, TELE_BOX_EVENT.Readonly);
|
4402
|
+
watchValEvent(zIndex$, TELE_BOX_EVENT.ZIndex);
|
4403
|
+
watchValEvent(minimized$, TELE_BOX_EVENT.Minimized);
|
4404
|
+
watchValEvent(maximized$, TELE_BOX_EVENT.Maximized);
|
4405
|
+
watchValEvent(state$, TELE_BOX_EVENT.State);
|
4406
|
+
watchValEvent(intrinsicSize$, TELE_BOX_EVENT.IntrinsicResize);
|
4407
|
+
watchValEvent(intrinsicCoord$, TELE_BOX_EVENT.IntrinsicMove);
|
4408
|
+
this._sideEffect.addDisposer([
|
4409
|
+
visible$.reaction((visible2, skipUpdate) => {
|
4410
|
+
if (!skipUpdate && !visible2) {
|
4411
|
+
this.events.emit(TELE_BOX_EVENT.Close);
|
4412
|
+
}
|
4413
|
+
}),
|
4414
|
+
focus$.reaction((focus2, skipUpdate) => {
|
4415
|
+
if (!skipUpdate) {
|
4416
|
+
this.events.emit(focus2 ? TELE_BOX_EVENT.Focus : TELE_BOX_EVENT.Blur);
|
4417
|
+
}
|
4418
|
+
})
|
4419
|
+
]);
|
4171
4420
|
}
|
4172
4421
|
get minWidth() {
|
4173
4422
|
return this._minSize$.value.width;
|
@@ -4175,14 +4424,17 @@ class Y$3 {
|
|
4175
4424
|
get minHeight() {
|
4176
4425
|
return this._minSize$.value.height;
|
4177
4426
|
}
|
4178
|
-
setMinWidth(
|
4179
|
-
this._minSize$.setValue({ width:
|
4427
|
+
setMinWidth(minWidth, skipUpdate = false) {
|
4428
|
+
this._minSize$.setValue({ width: minWidth, height: this.minHeight }, skipUpdate);
|
4180
4429
|
}
|
4181
|
-
setMinHeight(
|
4182
|
-
this._minSize$.setValue({ width: this.minWidth, height:
|
4430
|
+
setMinHeight(minHeight, skipUpdate = false) {
|
4431
|
+
this._minSize$.setValue({ width: this.minWidth, height: minHeight }, skipUpdate);
|
4183
4432
|
}
|
4184
|
-
resize(
|
4185
|
-
this._intrinsicSize$.setValue({
|
4433
|
+
resize(width, height, skipUpdate = false) {
|
4434
|
+
this._intrinsicSize$.setValue({
|
4435
|
+
width: Math.max(width, this.minWidth),
|
4436
|
+
height: Math.max(height, this.minHeight)
|
4437
|
+
}, skipUpdate);
|
4186
4438
|
}
|
4187
4439
|
get intrinsicX() {
|
4188
4440
|
return this._intrinsicCoord$.value.x;
|
@@ -4196,388 +4448,853 @@ class Y$3 {
|
|
4196
4448
|
get intrinsicHeight() {
|
4197
4449
|
return this._intrinsicSize$.value.height;
|
4198
4450
|
}
|
4199
|
-
move(
|
4200
|
-
let
|
4201
|
-
|
4202
|
-
|
4203
|
-
|
4204
|
-
|
4205
|
-
|
4206
|
-
|
4207
|
-
}
|
4208
|
-
|
4209
|
-
|
4210
|
-
|
4211
|
-
|
4212
|
-
|
4213
|
-
|
4214
|
-
|
4215
|
-
|
4216
|
-
|
4217
|
-
|
4218
|
-
|
4219
|
-
this.
|
4451
|
+
move(x2, y2, skipUpdate = false) {
|
4452
|
+
let safeX;
|
4453
|
+
let safeY;
|
4454
|
+
const managerStageRect = this.managerStageRect;
|
4455
|
+
const pxIntrinsicSize = this.pxIntrinsicSize;
|
4456
|
+
if (this.fence) {
|
4457
|
+
safeX = clamp$1(x2, 0, managerStageRect.width - pxIntrinsicSize.width);
|
4458
|
+
safeY = clamp$1(y2, 0, managerStageRect.height - pxIntrinsicSize.height);
|
4459
|
+
} else {
|
4460
|
+
safeX = clamp$1(x2, -(pxIntrinsicSize.width - 120), 0 + managerStageRect.width - 20);
|
4461
|
+
safeY = clamp$1(y2, 0, 0 + managerStageRect.height - 20);
|
4462
|
+
}
|
4463
|
+
this._intrinsicCoord$.setValue({
|
4464
|
+
x: safeX / managerStageRect.width,
|
4465
|
+
y: safeY / managerStageRect.height
|
4466
|
+
}, skipUpdate);
|
4467
|
+
}
|
4468
|
+
transform(x2, y2, width, height, skipUpdate = false) {
|
4469
|
+
const managerStageRect = this.managerStageRect;
|
4470
|
+
width = Math.max(width, this.pxMinSize.width);
|
4471
|
+
height = Math.max(height, this.pxMinSize.height);
|
4472
|
+
if (this.boxRatio > 0) {
|
4473
|
+
const newHeight = this.boxRatio * width;
|
4474
|
+
if (y2 !== this.pxIntrinsicCoord.y) {
|
4475
|
+
y2 -= newHeight - height;
|
4476
|
+
}
|
4477
|
+
height = newHeight;
|
4478
|
+
}
|
4479
|
+
if (y2 < 0) {
|
4480
|
+
y2 = 0;
|
4481
|
+
height = this.pxIntrinsicSize.height;
|
4482
|
+
}
|
4483
|
+
this.move(x2, y2, skipUpdate);
|
4484
|
+
this._intrinsicSize$.setValue({
|
4485
|
+
width: width / managerStageRect.width,
|
4486
|
+
height: height / managerStageRect.height
|
4487
|
+
}, skipUpdate);
|
4488
|
+
}
|
4489
|
+
mountContent(content) {
|
4490
|
+
var _a;
|
4491
|
+
(_a = this.$authorContent) == null ? void 0 : _a.remove();
|
4492
|
+
this.$authorContent = content;
|
4493
|
+
this.$content.appendChild(content);
|
4220
4494
|
}
|
4221
4495
|
unmountContent() {
|
4222
|
-
this
|
4496
|
+
if (this.$authorContent) {
|
4497
|
+
this.$authorContent.remove();
|
4498
|
+
this.$authorContent = void 0;
|
4499
|
+
}
|
4223
4500
|
}
|
4224
|
-
mountStage(
|
4225
|
-
|
4501
|
+
mountStage(stage) {
|
4502
|
+
var _a;
|
4503
|
+
(_a = this.$authorStage) == null ? void 0 : _a.remove();
|
4504
|
+
this.$authorStage = stage;
|
4505
|
+
if (!this.$stage) {
|
4506
|
+
this.$stage = this._renderStage();
|
4507
|
+
}
|
4508
|
+
this.$stage.appendChild(stage);
|
4509
|
+
if (!this.$stage.parentElement) {
|
4510
|
+
this.$body.appendChild(this.$stage);
|
4511
|
+
}
|
4226
4512
|
}
|
4227
4513
|
unmountStage() {
|
4228
|
-
|
4514
|
+
var _a;
|
4515
|
+
if (this.$authorStage) {
|
4516
|
+
this.$authorStage.remove();
|
4517
|
+
this.$authorStage = void 0;
|
4518
|
+
}
|
4519
|
+
(_a = this.$stage) == null ? void 0 : _a.remove();
|
4229
4520
|
}
|
4230
|
-
mountFooter(
|
4231
|
-
|
4521
|
+
mountFooter(footer) {
|
4522
|
+
var _a;
|
4523
|
+
(_a = this.$authorFooter) == null ? void 0 : _a.remove();
|
4524
|
+
this.$authorFooter = footer;
|
4525
|
+
this.$footer.appendChild(footer);
|
4232
4526
|
}
|
4233
4527
|
unmountFooter() {
|
4234
|
-
this
|
4235
|
-
|
4236
|
-
|
4237
|
-
|
4528
|
+
if (this.$authorFooter) {
|
4529
|
+
this.$authorFooter.remove();
|
4530
|
+
this.$authorFooter = void 0;
|
4531
|
+
}
|
4238
4532
|
}
|
4239
|
-
mountStyles(
|
4240
|
-
|
4241
|
-
typeof e2 == "string" ? (t2 = document.createElement("style"), t2.textContent = e2) : t2 = e2, this._$userStyles$.setValue(t2);
|
4533
|
+
mountStyles(styles2) {
|
4534
|
+
this.$styles.textContent = styles2;
|
4242
4535
|
}
|
4243
4536
|
unmountStyles() {
|
4244
|
-
this.
|
4537
|
+
this.$styles.textContent = "";
|
4245
4538
|
}
|
4246
|
-
|
4247
|
-
this.
|
4539
|
+
mountUserStyles(styles2) {
|
4540
|
+
this.$userStyles.textContent = styles2;
|
4248
4541
|
}
|
4249
|
-
|
4250
|
-
|
4542
|
+
unmountUserStyles() {
|
4543
|
+
this.$userStyles.textContent = "";
|
4544
|
+
}
|
4545
|
+
_render() {
|
4546
|
+
if (this.$box) {
|
4251
4547
|
return this.$box;
|
4252
|
-
|
4253
|
-
const
|
4254
|
-
|
4255
|
-
|
4256
|
-
|
4548
|
+
}
|
4549
|
+
const bindBoxStates = (el, disposerID) => {
|
4550
|
+
return this._sideEffect.addDisposer([
|
4551
|
+
this._readonly$.subscribe((readonly) => el.classList.toggle(this.wrapClassName("readonly"), readonly)),
|
4552
|
+
this._draggable$.subscribe((draggable) => el.classList.toggle(this.wrapClassName("no-drag"), !draggable)),
|
4553
|
+
this._resizable$.subscribe((resizable) => el.classList.toggle(this.wrapClassName("no-resize"), !resizable)),
|
4554
|
+
this._focus$.subscribe((focus) => el.classList.toggle(this.wrapClassName("blur"), !focus)),
|
4555
|
+
this._darkMode$.subscribe((darkMode) => {
|
4556
|
+
el.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
|
4557
|
+
el.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
|
4558
|
+
})
|
4559
|
+
], disposerID);
|
4560
|
+
};
|
4561
|
+
this.$box = document.createElement("div");
|
4562
|
+
this.$box.classList.add(this.wrapClassName("box"));
|
4563
|
+
bindBoxStates(this.$box, "bind-box-state");
|
4564
|
+
this._sideEffect.add(() => {
|
4565
|
+
const minimizedClassName = this.wrapClassName("minimized");
|
4566
|
+
const maximizedClassName = this.wrapClassName("maximized");
|
4567
|
+
const MAXIMIZED_TIMER_ID = "box-maximized-timer";
|
4568
|
+
return this._state$.subscribe((state) => {
|
4569
|
+
this.$box.classList.toggle(minimizedClassName, state === TELE_BOX_STATE.Minimized);
|
4570
|
+
if (state === TELE_BOX_STATE.Maximized) {
|
4571
|
+
this._sideEffect.flush(MAXIMIZED_TIMER_ID);
|
4572
|
+
this.$box.classList.toggle(maximizedClassName, true);
|
4573
|
+
} else {
|
4574
|
+
this._sideEffect.setTimeout(() => {
|
4575
|
+
this.$box.classList.toggle(maximizedClassName, false);
|
4576
|
+
}, 0, MAXIMIZED_TIMER_ID);
|
4577
|
+
}
|
4257
4578
|
});
|
4258
4579
|
});
|
4259
|
-
|
4260
|
-
|
4261
|
-
|
4262
|
-
|
4263
|
-
|
4264
|
-
}, 0, i3);
|
4265
|
-
});
|
4266
|
-
}), this._sideEffect.addDisposer(this._visible$.subscribe((e3) => {
|
4267
|
-
this.$box.style.display = e3 ? "block" : "none";
|
4268
|
-
})), this._sideEffect.addDisposer(this._zIndex$.subscribe((e3) => {
|
4269
|
-
this.$box.style.zIndex = String(e3);
|
4270
|
-
})), this.$box.dataset.teleBoxID = this.id;
|
4271
|
-
const t2 = index(this.$box), i2 = combine([this._maximized$, this._minimized$, this._pxIntrinsicSize$, this._pxIntrinsicCoord$, this._collectorRect$], ([e3, t3, i3, s3, a3]) => {
|
4272
|
-
const n3 = e3 ? { x: 0, y: 0, width: "100%", height: "100%", scaleX: 1, scaleY: 1 } : { x: s3.x, y: s3.y, width: i3.width + "px", height: i3.height + "px", scaleX: 1, scaleY: 1 };
|
4273
|
-
if (t3 && a3) {
|
4274
|
-
const { width: t4, height: s4 } = e3 ? this.rootRect : i3;
|
4275
|
-
n3.x = a3.x - t4 / 2 + a3.width / 2, n3.y = a3.y - s4 / 2 + a3.height / 2, n3.scaleX = a3.width / t4, n3.scaleY = a3.height / s4;
|
4276
|
-
}
|
4277
|
-
return n3;
|
4278
|
-
}, { compare: shallowequal }), s2 = i2.value;
|
4279
|
-
this.$box.style.width = s2.width, this.$box.style.height = s2.height, this.$box.style.transform = `translate(${s2.x - 10}px,${s2.y - 10}px)`, this._sideEffect.addDisposer(i2.subscribe((e3) => {
|
4280
|
-
t2.set(e3);
|
4580
|
+
this._sideEffect.addDisposer(this._visible$.subscribe((visible) => {
|
4581
|
+
this.$box.style.display = visible ? "block" : "none";
|
4582
|
+
}));
|
4583
|
+
this._sideEffect.addDisposer(this._zIndex$.subscribe((zIndex) => {
|
4584
|
+
this.$box.style.zIndex = String(zIndex);
|
4281
4585
|
}));
|
4282
|
-
|
4283
|
-
|
4284
|
-
const
|
4285
|
-
|
4286
|
-
|
4287
|
-
|
4288
|
-
|
4289
|
-
|
4290
|
-
|
4291
|
-
|
4292
|
-
|
4586
|
+
this.$box.dataset.teleBoxID = this.id;
|
4587
|
+
const boxStyler = index(this.$box);
|
4588
|
+
const boxStyles$ = combine([
|
4589
|
+
this._maximized$,
|
4590
|
+
this._minimized$,
|
4591
|
+
this._pxIntrinsicSize$,
|
4592
|
+
this._pxIntrinsicCoord$,
|
4593
|
+
this._collectorRect$,
|
4594
|
+
this._rootRect$,
|
4595
|
+
this._managerStageRect$
|
4596
|
+
], ([
|
4597
|
+
maximized,
|
4598
|
+
minimized,
|
4599
|
+
pxIntrinsicSize,
|
4600
|
+
pxIntrinsicCoord,
|
4601
|
+
collectorRect,
|
4602
|
+
rootRect,
|
4603
|
+
managerStageRect
|
4604
|
+
]) => {
|
4605
|
+
const styles2 = maximized ? {
|
4606
|
+
x: -managerStageRect.x,
|
4607
|
+
y: -managerStageRect.y,
|
4608
|
+
width: rootRect.width,
|
4609
|
+
height: rootRect.height,
|
4610
|
+
scaleX: 1,
|
4611
|
+
scaleY: 1
|
4612
|
+
} : {
|
4613
|
+
x: pxIntrinsicCoord.x,
|
4614
|
+
y: pxIntrinsicCoord.y,
|
4615
|
+
width: pxIntrinsicSize.width,
|
4616
|
+
height: pxIntrinsicSize.height,
|
4617
|
+
scaleX: 1,
|
4618
|
+
scaleY: 1
|
4619
|
+
};
|
4620
|
+
if (minimized && collectorRect) {
|
4621
|
+
const { width: boxWidth, height: boxHeight } = maximized ? this.rootRect : pxIntrinsicSize;
|
4622
|
+
styles2.x = collectorRect.x - boxWidth / 2 + collectorRect.width / 2 - managerStageRect.x;
|
4623
|
+
styles2.y = collectorRect.y - boxHeight / 2 + collectorRect.height / 2 - managerStageRect.y;
|
4624
|
+
styles2.scaleX = collectorRect.width / boxWidth;
|
4625
|
+
styles2.scaleY = collectorRect.height / boxHeight;
|
4626
|
+
}
|
4627
|
+
return styles2;
|
4628
|
+
}, { compare: shallowequal });
|
4629
|
+
const boxStyles = boxStyles$.value;
|
4630
|
+
this.$box.style.width = boxStyles.width + "px";
|
4631
|
+
this.$box.style.height = boxStyles.height + "px";
|
4632
|
+
this.$box.style.transform = `translate(${boxStyles.x - 10}px,${boxStyles.y - 10}px)`;
|
4633
|
+
this._sideEffect.addDisposer(boxStyles$.subscribe((styles2) => {
|
4634
|
+
boxStyler.set(styles2);
|
4635
|
+
}));
|
4636
|
+
const $boxMain = document.createElement("div");
|
4637
|
+
$boxMain.className = this.wrapClassName("box-main");
|
4638
|
+
this.$box.appendChild($boxMain);
|
4639
|
+
const $titleBar = document.createElement("div");
|
4640
|
+
$titleBar.className = this.wrapClassName("titlebar-wrap");
|
4641
|
+
$titleBar.appendChild(this.titleBar.render());
|
4642
|
+
this.$titleBar = $titleBar;
|
4643
|
+
const $body = document.createElement("div");
|
4644
|
+
$body.className = this.wrapClassName("body-wrap");
|
4645
|
+
this.$body = $body;
|
4646
|
+
const $styles = document.createElement("style");
|
4647
|
+
this.$styles = $styles;
|
4648
|
+
$body.appendChild($styles);
|
4649
|
+
const $userStyles = document.createElement("style");
|
4650
|
+
this.$userStyles = $userStyles;
|
4651
|
+
$body.appendChild($userStyles);
|
4652
|
+
const $content = document.createElement("div");
|
4653
|
+
$content.className = this.wrapClassName("content") + " tele-fancy-scrollbar";
|
4654
|
+
this.$content = $content;
|
4655
|
+
this._sideEffect.addDisposer(combine([this._bodyStyle$, this._defaultBoxBodyStyle$], ([bodyStyle, defaultBoxBodyStyle]) => bodyStyle != null ? bodyStyle : defaultBoxBodyStyle).subscribe((style2) => $content.style.cssText = style2 || ""));
|
4656
|
+
$body.appendChild($content);
|
4657
|
+
const $footer = document.createElement("div");
|
4658
|
+
$footer.className = this.wrapClassName("footer-wrap");
|
4659
|
+
this.$footer = $footer;
|
4660
|
+
$boxMain.appendChild($titleBar);
|
4661
|
+
const $main = document.createElement("div");
|
4662
|
+
$main.className = this.wrapClassName("main");
|
4663
|
+
this.$main = $main;
|
4664
|
+
$boxMain.appendChild($main);
|
4665
|
+
const $quarantineOuter = document.createElement("div");
|
4666
|
+
$quarantineOuter.className = this.wrapClassName("quarantine-outer");
|
4667
|
+
$main.appendChild($quarantineOuter);
|
4668
|
+
const $quarantine = document.createElement("div");
|
4669
|
+
$quarantine.className = this.wrapClassName("quarantine");
|
4670
|
+
$quarantine.appendChild($body);
|
4671
|
+
$quarantine.appendChild($footer);
|
4672
|
+
if (this.enableShadowDOM) {
|
4673
|
+
bindBoxStates($quarantine, "bind-quarantine-state");
|
4674
|
+
const $shadowStyle = document.createElement("style");
|
4675
|
+
$shadowStyle.textContent = shadowStyles;
|
4676
|
+
$quarantine.insertBefore($shadowStyle, $quarantine.firstChild);
|
4677
|
+
const shadow = $quarantineOuter.attachShadow({ mode: "open" });
|
4678
|
+
shadow.appendChild($quarantine);
|
4679
|
+
} else {
|
4680
|
+
$quarantineOuter.appendChild($quarantine);
|
4681
|
+
}
|
4682
|
+
this._renderResizeHandlers();
|
4683
|
+
const updateBodyRect = () => {
|
4684
|
+
const rect = $body.getBoundingClientRect();
|
4685
|
+
this._bodyRect$.setValue({
|
4686
|
+
x: 0,
|
4687
|
+
y: 0,
|
4688
|
+
width: rect.width,
|
4689
|
+
height: rect.height
|
4690
|
+
});
|
4293
4691
|
};
|
4294
4692
|
this._sideEffect.add(() => {
|
4295
|
-
const
|
4296
|
-
this.minimized
|
4297
|
-
|
4298
|
-
|
4299
|
-
}), this._sideEffect.addDisposer(this._minimized$.reaction((e3) => {
|
4300
|
-
e3 || this._sideEffect.setTimeout(h, 400, "minimized-content-rect-fix");
|
4301
|
-
})), this._sideEffect.add(() => {
|
4302
|
-
let e3;
|
4303
|
-
return this._$userStyles$.subscribe((t3) => {
|
4304
|
-
e3 && e3.remove(), e3 = t3, t3 && o2.appendChild(t3);
|
4305
|
-
});
|
4306
|
-
}), this._sideEffect.add(() => {
|
4307
|
-
let e3;
|
4308
|
-
return this._$userContent$.subscribe((t3) => {
|
4309
|
-
e3 && e3.remove(), e3 = t3, t3 && r2.appendChild(t3);
|
4310
|
-
});
|
4311
|
-
}), this._sideEffect.add(() => {
|
4312
|
-
let e3;
|
4313
|
-
return this._$userStage$.subscribe((t3) => {
|
4314
|
-
var i3;
|
4315
|
-
if (e3 && e3.remove(), e3 = t3, t3) {
|
4316
|
-
if (!this.$stage) {
|
4317
|
-
const e4 = document.createElement("div");
|
4318
|
-
this.$stage = e4, e4.className = this.wrapClassName("content-stage"), this._sideEffect.addDisposer(this._contentStageRect$.subscribe((t4) => {
|
4319
|
-
e4.style.top = t4.y + "px", e4.style.left = t4.x + "px", e4.style.width = t4.width + "px", e4.style.height = t4.height + "px";
|
4320
|
-
}), "content-stage-rect"), r2.appendChild(e4);
|
4321
|
-
}
|
4322
|
-
this.$stage.parentElement || r2.appendChild(this.$stage), this.$stage.appendChild(t3);
|
4323
|
-
} else
|
4324
|
-
((i3 = this.$stage) == null ? void 0 : i3.parentElement) && this.$stage.remove();
|
4325
|
-
});
|
4326
|
-
}), o2.appendChild(r2);
|
4327
|
-
const c = document.createElement("div");
|
4328
|
-
return c.className = this.wrapClassName("footer-wrap"), this.$footer = c, this._sideEffect.add(() => {
|
4329
|
-
let e3;
|
4330
|
-
return this._$userFooter$.subscribe((t3) => {
|
4331
|
-
e3 && e3.remove(), e3 = t3, t3 && c.appendChild(t3);
|
4693
|
+
const observer = new ResizeObserver$1$1(() => {
|
4694
|
+
if (!this.minimized) {
|
4695
|
+
updateBodyRect();
|
4696
|
+
}
|
4332
4697
|
});
|
4333
|
-
|
4698
|
+
observer.observe($body);
|
4699
|
+
return () => observer.disconnect();
|
4700
|
+
});
|
4701
|
+
this._sideEffect.addDisposer(this._minimized$.reaction((minimized) => {
|
4702
|
+
if (!minimized) {
|
4703
|
+
this._sideEffect.setTimeout(updateBodyRect, 400, "minimized-content-rect-fix");
|
4704
|
+
}
|
4705
|
+
}));
|
4706
|
+
return this.$box;
|
4707
|
+
}
|
4708
|
+
_renderStage() {
|
4709
|
+
const $stage = document.createElement("div");
|
4710
|
+
$stage.className = this.wrapClassName("box-stage");
|
4711
|
+
const updateStageRect = (stageRect) => {
|
4712
|
+
$stage.style.top = stageRect.y + "px";
|
4713
|
+
$stage.style.left = stageRect.x + "px";
|
4714
|
+
$stage.style.width = stageRect.width + "px";
|
4715
|
+
$stage.style.height = stageRect.height + "px";
|
4716
|
+
};
|
4717
|
+
this._sideEffect.addDisposer([
|
4718
|
+
combine([this._stageStyle$, this._defaultBoxStageStyle$], ([stageStyle, defaultBoxStageStyle]) => stageStyle != null ? stageStyle : defaultBoxStageStyle).subscribe((styles2) => {
|
4719
|
+
$stage.style.cssText = styles2 || "";
|
4720
|
+
updateStageRect(this._stageRect$.value);
|
4721
|
+
}),
|
4722
|
+
this._stageRect$.subscribe(updateStageRect)
|
4723
|
+
], "box-stage-styles");
|
4724
|
+
return $stage;
|
4334
4725
|
}
|
4335
4726
|
_renderResizeHandlers() {
|
4336
|
-
const
|
4337
|
-
|
4338
|
-
|
4339
|
-
|
4340
|
-
|
4341
|
-
|
4342
|
-
|
4343
|
-
|
4344
|
-
|
4727
|
+
const $resizeHandles = document.createElement("div");
|
4728
|
+
$resizeHandles.className = this.wrapClassName("resize-handles");
|
4729
|
+
Object.values(TELE_BOX_RESIZE_HANDLE).forEach((handleType) => {
|
4730
|
+
const $handle = document.createElement("div");
|
4731
|
+
$handle.className = this.wrapClassName(handleType) + " " + this.wrapClassName("resize-handle");
|
4732
|
+
$handle.dataset.teleBoxHandle = handleType;
|
4733
|
+
$resizeHandles.appendChild($handle);
|
4734
|
+
});
|
4735
|
+
this.$box.appendChild($resizeHandles);
|
4736
|
+
const TRACKING_DISPOSER_ID = "handle-tracking-listener";
|
4737
|
+
const transformingClassName = this.wrapClassName("transforming");
|
4738
|
+
let $trackMask;
|
4739
|
+
let trackStartX = 0;
|
4740
|
+
let trackStartY = 0;
|
4741
|
+
let trackStartWidth = 0;
|
4742
|
+
let trackStartHeight = 0;
|
4743
|
+
let trackStartPageX = 0;
|
4744
|
+
let trackStartPageY = 0;
|
4745
|
+
let trackingHandle;
|
4746
|
+
const handleTracking = (ev) => {
|
4747
|
+
if (!ev.isPrimary || this.state !== TELE_BOX_STATE.Normal) {
|
4345
4748
|
return;
|
4346
|
-
|
4347
|
-
|
4348
|
-
|
4349
|
-
|
4350
|
-
|
4351
|
-
|
4352
|
-
|
4353
|
-
|
4749
|
+
}
|
4750
|
+
preventEvent$1(ev);
|
4751
|
+
let { pageX, pageY } = ev;
|
4752
|
+
if (pageY < 0) {
|
4753
|
+
pageY = 0;
|
4754
|
+
}
|
4755
|
+
const offsetX = pageX - trackStartPageX;
|
4756
|
+
const offsetY = pageY - trackStartPageY;
|
4757
|
+
let { x: newX, y: newY } = this.pxIntrinsicCoord;
|
4758
|
+
let { width: newWidth, height: newHeight } = this.pxIntrinsicSize;
|
4759
|
+
switch (trackingHandle) {
|
4760
|
+
case TELE_BOX_RESIZE_HANDLE.North: {
|
4761
|
+
newY = trackStartY + offsetY;
|
4762
|
+
newHeight = trackStartHeight - offsetY;
|
4354
4763
|
break;
|
4355
|
-
|
4356
|
-
|
4764
|
+
}
|
4765
|
+
case TELE_BOX_RESIZE_HANDLE.South: {
|
4766
|
+
newHeight = trackStartHeight + offsetY;
|
4357
4767
|
break;
|
4358
|
-
|
4359
|
-
|
4768
|
+
}
|
4769
|
+
case TELE_BOX_RESIZE_HANDLE.West: {
|
4770
|
+
newX = trackStartX + offsetX;
|
4771
|
+
newWidth = trackStartWidth - offsetX;
|
4360
4772
|
break;
|
4361
|
-
|
4362
|
-
|
4773
|
+
}
|
4774
|
+
case TELE_BOX_RESIZE_HANDLE.East: {
|
4775
|
+
newWidth = trackStartWidth + offsetX;
|
4363
4776
|
break;
|
4364
|
-
|
4365
|
-
|
4777
|
+
}
|
4778
|
+
case TELE_BOX_RESIZE_HANDLE.NorthWest: {
|
4779
|
+
newX = trackStartX + offsetX;
|
4780
|
+
newY = trackStartY + offsetY;
|
4781
|
+
newWidth = trackStartWidth - offsetX;
|
4782
|
+
newHeight = trackStartHeight - offsetY;
|
4366
4783
|
break;
|
4367
|
-
|
4368
|
-
|
4784
|
+
}
|
4785
|
+
case TELE_BOX_RESIZE_HANDLE.NorthEast: {
|
4786
|
+
newY = trackStartY + offsetY;
|
4787
|
+
newWidth = trackStartWidth + offsetX;
|
4788
|
+
newHeight = trackStartHeight - offsetY;
|
4369
4789
|
break;
|
4370
|
-
|
4371
|
-
|
4790
|
+
}
|
4791
|
+
case TELE_BOX_RESIZE_HANDLE.SouthEast: {
|
4792
|
+
newWidth = trackStartWidth + offsetX;
|
4793
|
+
newHeight = trackStartHeight + offsetY;
|
4372
4794
|
break;
|
4373
|
-
|
4374
|
-
|
4795
|
+
}
|
4796
|
+
case TELE_BOX_RESIZE_HANDLE.SouthWest: {
|
4797
|
+
newX = trackStartX + offsetX;
|
4798
|
+
newWidth = trackStartWidth - offsetX;
|
4799
|
+
newHeight = trackStartHeight + offsetY;
|
4375
4800
|
break;
|
4376
|
-
|
4377
|
-
|
4378
|
-
|
4379
|
-
|
4380
|
-
|
4381
|
-
|
4382
|
-
|
4383
|
-
|
4384
|
-
|
4801
|
+
}
|
4802
|
+
default: {
|
4803
|
+
this.move(trackStartX + offsetX, trackStartY + offsetY);
|
4804
|
+
return;
|
4805
|
+
}
|
4806
|
+
}
|
4807
|
+
this.transform(newX, newY, newWidth, newHeight);
|
4808
|
+
};
|
4809
|
+
const handleTrackEnd = (ev) => {
|
4810
|
+
if (!ev.isPrimary) {
|
4385
4811
|
return;
|
4386
|
-
|
4812
|
+
}
|
4813
|
+
trackingHandle = void 0;
|
4814
|
+
if (!$trackMask) {
|
4387
4815
|
return;
|
4388
|
-
|
4816
|
+
}
|
4817
|
+
preventEvent$1(ev);
|
4818
|
+
this.$box.classList.toggle(transformingClassName, false);
|
4819
|
+
this._sideEffect.flush(TRACKING_DISPOSER_ID);
|
4820
|
+
$trackMask.remove();
|
4821
|
+
};
|
4822
|
+
const handleTrackStart = (ev) => {
|
4823
|
+
var _a;
|
4824
|
+
if (!ev.isPrimary || this.readonly) {
|
4389
4825
|
return;
|
4390
|
-
|
4391
|
-
if (
|
4392
|
-
|
4393
|
-
|
4394
|
-
|
4395
|
-
|
4396
|
-
|
4826
|
+
}
|
4827
|
+
if (ev.button != null && ev.button !== 0) {
|
4828
|
+
return;
|
4829
|
+
}
|
4830
|
+
if (!this.draggable || trackingHandle || this.state !== TELE_BOX_STATE.Normal) {
|
4831
|
+
return;
|
4832
|
+
}
|
4833
|
+
const target = ev.target;
|
4834
|
+
if ((_a = target.dataset) == null ? void 0 : _a.teleBoxHandle) {
|
4835
|
+
preventEvent$1(ev);
|
4836
|
+
({ x: trackStartX, y: trackStartY } = this.pxIntrinsicCoord);
|
4837
|
+
({ width: trackStartWidth, height: trackStartHeight } = this.pxIntrinsicSize);
|
4838
|
+
({ pageX: trackStartPageX, pageY: trackStartPageY } = ev);
|
4839
|
+
trackingHandle = target.dataset.teleBoxHandle;
|
4840
|
+
if (!$trackMask) {
|
4841
|
+
$trackMask = document.createElement("div");
|
4842
|
+
}
|
4843
|
+
const cursor = trackingHandle ? this.wrapClassName(`cursor-${trackingHandle}`) : "";
|
4844
|
+
$trackMask.className = this.wrapClassName(`track-mask${cursor ? ` ${cursor}` : ""}`);
|
4845
|
+
this.$box.appendChild($trackMask);
|
4846
|
+
this.$box.classList.add(transformingClassName);
|
4847
|
+
this._sideEffect.add(() => {
|
4848
|
+
window.addEventListener("pointermove", handleTracking, {
|
4849
|
+
passive: false
|
4850
|
+
});
|
4851
|
+
window.addEventListener("pointerup", handleTrackEnd, {
|
4852
|
+
passive: false
|
4853
|
+
});
|
4854
|
+
window.addEventListener("pointercancel", handleTrackEnd, {
|
4855
|
+
passive: false
|
4856
|
+
});
|
4857
|
+
return () => {
|
4858
|
+
window.removeEventListener("pointermove", handleTracking);
|
4859
|
+
window.removeEventListener("pointerup", handleTrackEnd);
|
4860
|
+
window.removeEventListener("pointercancel", handleTrackEnd);
|
4861
|
+
};
|
4862
|
+
}, TRACKING_DISPOSER_ID);
|
4397
4863
|
}
|
4398
4864
|
};
|
4399
|
-
this._handleTrackStart =
|
4865
|
+
this._handleTrackStart = handleTrackStart;
|
4866
|
+
this._sideEffect.addEventListener($resizeHandles, "pointerdown", handleTrackStart, {}, "box-resizeHandles-pointerdown");
|
4400
4867
|
}
|
4401
4868
|
async destroy() {
|
4402
|
-
this.$box.remove()
|
4403
|
-
|
4404
|
-
|
4405
|
-
|
4406
|
-
|
4407
|
-
|
4408
|
-
|
4409
|
-
|
4410
|
-
|
4411
|
-
|
4412
|
-
|
4413
|
-
|
4414
|
-
|
4415
|
-
|
4416
|
-
|
4417
|
-
|
4418
|
-
|
4419
|
-
|
4420
|
-
|
4421
|
-
|
4422
|
-
|
4423
|
-
|
4424
|
-
|
4425
|
-
|
4426
|
-
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
|
4431
|
-
|
4432
|
-
|
4433
|
-
|
4434
|
-
|
4435
|
-
|
4436
|
-
|
4437
|
-
|
4438
|
-
|
4869
|
+
this.$box.remove();
|
4870
|
+
this._sideEffect.flushAll();
|
4871
|
+
this._sideEffect.flushAll();
|
4872
|
+
await this.events.emit(TELE_BOX_EVENT.Destroyed);
|
4873
|
+
this.events.clearListeners();
|
4874
|
+
this._delegateEvents.clearListeners();
|
4875
|
+
}
|
4876
|
+
wrapClassName(className) {
|
4877
|
+
return `${this.namespace}-${className}`;
|
4878
|
+
}
|
4879
|
+
}
|
4880
|
+
var collectorSVG = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxOCAxNiI+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxwYXRoIHN0cm9rZT0iIzdCODhBMCIgc3Ryb2tlLXdpZHRoPSIxLjQiIGQ9Ik0uNyAxLjJoMTYuNnYxMy42SC43eiIgLz4KICAgICAgICA8cGF0aCBmaWxsPSIjN0I4OEEwIiBkPSJNNCA1LjVoNnYxLjRINHpNNCA5LjVoMTB2MS40SDR6IiAvPgogICAgPC9nPgo8L3N2Zz4K";
|
4881
|
+
class TeleBoxCollector {
|
4882
|
+
constructor({
|
4883
|
+
minimized$,
|
4884
|
+
readonly$,
|
4885
|
+
darkMode$,
|
4886
|
+
namespace = "telebox",
|
4887
|
+
styles: styles2 = {},
|
4888
|
+
root$
|
4889
|
+
}) {
|
4890
|
+
this._sideEffect = new SideEffectManager();
|
4891
|
+
this.namespace = namespace;
|
4892
|
+
const valManager = new ValManager();
|
4893
|
+
this._sideEffect.addDisposer(() => valManager.destroy());
|
4894
|
+
const rect$ = new Val(void 0);
|
4895
|
+
const visible$ = derive(minimized$);
|
4896
|
+
const styles$ = new Val(styles2);
|
4897
|
+
const el$ = new Val(document.createElement("button"));
|
4898
|
+
const valConfig = {
|
4899
|
+
styles: styles$,
|
4900
|
+
$collector: el$
|
4901
|
+
};
|
4902
|
+
withValueEnhancer(this, valConfig, valManager);
|
4903
|
+
const propsValConfig = {
|
4904
|
+
root: root$
|
4905
|
+
};
|
4906
|
+
withReadonlyValueEnhancer(this, propsValConfig);
|
4907
|
+
const myReadonlyValConfig = {
|
4908
|
+
rect: rect$,
|
4909
|
+
visible: visible$
|
4910
|
+
};
|
4911
|
+
withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
|
4912
|
+
el$.value.className = this.wrapClassName("collector");
|
4913
|
+
el$.value.style.backgroundImage = `url('${collectorSVG}')`;
|
4914
|
+
this._sideEffect.addDisposer(el$.subscribe(($collector) => {
|
4915
|
+
this._sideEffect.addEventListener($collector, "pointerup", (ev) => {
|
4916
|
+
if (ev.isPrimary && !readonly$.value) {
|
4917
|
+
minimized$.setValue(false);
|
4918
|
+
}
|
4919
|
+
}, {}, "telebox-collector-click");
|
4920
|
+
this._sideEffect.addDisposer([
|
4921
|
+
visible$.subscribe((visible) => {
|
4922
|
+
$collector.classList.toggle(this.wrapClassName("collector-visible"), visible);
|
4923
|
+
}),
|
4924
|
+
readonly$.subscribe((readonly) => {
|
4925
|
+
$collector.classList.toggle(this.wrapClassName("collector-readonly"), readonly);
|
4926
|
+
}),
|
4927
|
+
darkMode$.subscribe((darkMode) => {
|
4928
|
+
$collector.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
|
4929
|
+
$collector.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
|
4930
|
+
}),
|
4931
|
+
styles$.subscribe((styles22) => {
|
4932
|
+
Object.keys(styles22).forEach((key) => {
|
4933
|
+
const value = styles22[key];
|
4934
|
+
if (value != null) {
|
4935
|
+
$collector.style[key] = value;
|
4936
|
+
}
|
4937
|
+
});
|
4938
|
+
}),
|
4939
|
+
root$.subscribe((root) => {
|
4940
|
+
if (root) {
|
4941
|
+
root.appendChild($collector);
|
4942
|
+
}
|
4943
|
+
}),
|
4944
|
+
combine([minimized$, root$]).subscribe(([minimized, root]) => {
|
4945
|
+
if (minimized && root) {
|
4946
|
+
const { x: x2, y: y2, width, height } = $collector.getBoundingClientRect();
|
4947
|
+
const rootRect = root.getBoundingClientRect();
|
4948
|
+
rect$.setValue({
|
4949
|
+
x: x2 - rootRect.x,
|
4950
|
+
y: y2 - rootRect.y,
|
4951
|
+
width,
|
4952
|
+
height
|
4953
|
+
});
|
4954
|
+
}
|
4955
|
+
})
|
4956
|
+
], "telebox-collector-el");
|
4439
4957
|
}));
|
4440
4958
|
}
|
4441
4959
|
destroy() {
|
4442
4960
|
this._sideEffect.flushAll();
|
4443
4961
|
}
|
4444
|
-
wrapClassName(
|
4445
|
-
return `${this.namespace}-${
|
4962
|
+
wrapClassName(className) {
|
4963
|
+
return `${this.namespace}-${className}`;
|
4446
4964
|
}
|
4447
4965
|
}
|
4448
|
-
|
4449
|
-
|
4450
|
-
|
4451
|
-
|
4452
|
-
|
4453
|
-
|
4454
|
-
|
4966
|
+
var TELE_BOX_MANAGER_EVENT = /* @__PURE__ */ ((TELE_BOX_MANAGER_EVENT2) => {
|
4967
|
+
TELE_BOX_MANAGER_EVENT2["Focused"] = "focused";
|
4968
|
+
TELE_BOX_MANAGER_EVENT2["Blurred"] = "blurred";
|
4969
|
+
TELE_BOX_MANAGER_EVENT2["Created"] = "created";
|
4970
|
+
TELE_BOX_MANAGER_EVENT2["Removed"] = "removed";
|
4971
|
+
TELE_BOX_MANAGER_EVENT2["State"] = "state";
|
4972
|
+
TELE_BOX_MANAGER_EVENT2["Maximized"] = "maximized";
|
4973
|
+
TELE_BOX_MANAGER_EVENT2["Minimized"] = "minimized";
|
4974
|
+
TELE_BOX_MANAGER_EVENT2["IntrinsicMove"] = "intrinsic_move";
|
4975
|
+
TELE_BOX_MANAGER_EVENT2["IntrinsicResize"] = "intrinsic_resize";
|
4976
|
+
TELE_BOX_MANAGER_EVENT2["ZIndex"] = "z_index";
|
4977
|
+
TELE_BOX_MANAGER_EVENT2["PrefersColorScheme"] = "prefers_color_scheme";
|
4978
|
+
TELE_BOX_MANAGER_EVENT2["DarkMode"] = "dark_mode";
|
4979
|
+
return TELE_BOX_MANAGER_EVENT2;
|
4980
|
+
})(TELE_BOX_MANAGER_EVENT || {});
|
4981
|
+
class MaxTitleBar extends DefaultTitleBar {
|
4982
|
+
constructor(config) {
|
4983
|
+
super(config);
|
4984
|
+
this.boxes$ = config.boxes$;
|
4985
|
+
this.rootRect$ = config.rootRect$;
|
4986
|
+
this.darkMode$ = config.darkMode$;
|
4987
|
+
config.root.appendChild(this.render());
|
4455
4988
|
}
|
4456
|
-
focusBox(
|
4457
|
-
var
|
4458
|
-
if (
|
4459
|
-
|
4460
|
-
|
4461
|
-
|
4462
|
-
|
4463
|
-
|
4989
|
+
focusBox(box) {
|
4990
|
+
var _a;
|
4991
|
+
if (this.focusedBox && this.focusedBox === box) {
|
4992
|
+
return;
|
4993
|
+
}
|
4994
|
+
if (this.$titles && this.state$.value === TELE_BOX_STATE.Maximized) {
|
4995
|
+
const { children: children2 } = this.$titles.firstElementChild;
|
4996
|
+
for (let i2 = children2.length - 1; i2 >= 0; i2 -= 1) {
|
4997
|
+
const $tab = children2[i2];
|
4998
|
+
const id2 = (_a = $tab.dataset) == null ? void 0 : _a.teleBoxID;
|
4999
|
+
if (id2) {
|
5000
|
+
if (box && id2 === box.id) {
|
5001
|
+
$tab.classList.toggle(this.wrapClassName("titles-tab-focus"), true);
|
5002
|
+
} else if (this.focusedBox && id2 === this.focusedBox.id) {
|
5003
|
+
$tab.classList.toggle(this.wrapClassName("titles-tab-focus"), false);
|
5004
|
+
}
|
4464
5005
|
}
|
4465
5006
|
}
|
4466
|
-
this.focusedBox = e2;
|
4467
5007
|
}
|
5008
|
+
this.focusedBox = box;
|
4468
5009
|
}
|
4469
5010
|
render() {
|
4470
|
-
if (this.$titleBar)
|
5011
|
+
if (this.$titleBar) {
|
4471
5012
|
return this.$titleBar;
|
4472
|
-
|
4473
|
-
|
4474
|
-
|
4475
|
-
|
4476
|
-
|
4477
|
-
|
4478
|
-
|
4479
|
-
|
4480
|
-
|
4481
|
-
|
4482
|
-
|
4483
|
-
|
5013
|
+
}
|
5014
|
+
const $titleBar = super.render();
|
5015
|
+
$titleBar.classList.add(this.wrapClassName("max-titlebar"));
|
5016
|
+
this.sideEffect.addDisposer([
|
5017
|
+
this.state$.subscribe((state) => {
|
5018
|
+
$titleBar.classList.toggle(this.wrapClassName("max-titlebar-maximized"), state === TELE_BOX_STATE.Maximized);
|
5019
|
+
}),
|
5020
|
+
this.readonly$.subscribe((readonly) => {
|
5021
|
+
$titleBar.classList.toggle(this.wrapClassName("readonly"), readonly);
|
5022
|
+
}),
|
5023
|
+
combine([this.state$, this.boxes$]).subscribe(([state, titles]) => {
|
5024
|
+
if (state === TELE_BOX_STATE.Maximized) {
|
5025
|
+
$titleBar.classList.toggle(this.wrapClassName("max-titlebar-single-title"), titles.length === 1);
|
5026
|
+
if (titles.length !== 1) {
|
5027
|
+
$titleBar.replaceChild(this.renderTitles(), $titleBar.firstElementChild);
|
5028
|
+
}
|
5029
|
+
}
|
5030
|
+
})
|
5031
|
+
], "max-render");
|
5032
|
+
const $titlesArea = document.createElement("div");
|
5033
|
+
$titlesArea.classList.add(this.wrapClassName("titles-area"));
|
5034
|
+
$titleBar.insertBefore($titlesArea, $titleBar.firstElementChild);
|
5035
|
+
return $titleBar;
|
4484
5036
|
}
|
4485
5037
|
destroy() {
|
4486
|
-
super.destroy()
|
5038
|
+
super.destroy();
|
5039
|
+
this.$titles = void 0;
|
5040
|
+
this.focusedBox = void 0;
|
4487
5041
|
}
|
4488
5042
|
renderTitles() {
|
4489
|
-
this.$titles = document.createElement("div")
|
4490
|
-
|
5043
|
+
this.$titles = document.createElement("div");
|
5044
|
+
this.$titles.className = this.wrapClassName("titles");
|
5045
|
+
this.sideEffect.addEventListener(this.$titles, "wheel", (ev) => {
|
5046
|
+
ev.currentTarget.scrollBy({
|
5047
|
+
left: ev.deltaY > 0 ? 250 : -250,
|
5048
|
+
behavior: "smooth"
|
5049
|
+
});
|
4491
5050
|
}, { passive: false }, "max-render-wheel-titles");
|
4492
|
-
const
|
4493
|
-
|
4494
|
-
|
4495
|
-
|
4496
|
-
|
5051
|
+
const $content = document.createElement("div");
|
5052
|
+
$content.className = this.wrapClassName("titles-content");
|
5053
|
+
this.$titles.appendChild($content);
|
5054
|
+
const disposers = this.boxes$.value.map((box) => {
|
5055
|
+
const $tab = document.createElement("button");
|
5056
|
+
$tab.className = this.wrapClassName("titles-tab");
|
5057
|
+
$tab.textContent = box.title;
|
5058
|
+
$tab.dataset.teleBoxID = box.id;
|
5059
|
+
$tab.dataset.teleTitleBarNoDblClick = "true";
|
5060
|
+
if (this.focusedBox && box.id === this.focusedBox.id) {
|
5061
|
+
$tab.classList.add(this.wrapClassName("titles-tab-focus"));
|
5062
|
+
}
|
5063
|
+
$content.appendChild($tab);
|
5064
|
+
return box._title$.reaction((title) => $tab.textContent = title);
|
4497
5065
|
});
|
4498
|
-
|
5066
|
+
this.sideEffect.addDisposer(() => disposers.forEach((disposer) => disposer()), "max-render-tab-titles");
|
5067
|
+
return this.$titles;
|
4499
5068
|
}
|
4500
5069
|
}
|
4501
|
-
const
|
4502
|
-
class
|
4503
|
-
constructor({
|
4504
|
-
|
4505
|
-
|
4506
|
-
|
4507
|
-
|
4508
|
-
|
5070
|
+
const ResizeObserver$2 = window.ResizeObserver || ResizeObserver$3;
|
5071
|
+
class TeleBoxManager {
|
5072
|
+
constructor({
|
5073
|
+
root = null,
|
5074
|
+
prefersColorScheme = TELE_BOX_COLOR_SCHEME.Light,
|
5075
|
+
minimized = false,
|
5076
|
+
maximized = false,
|
5077
|
+
fence = true,
|
5078
|
+
collector,
|
5079
|
+
namespace = "telebox",
|
5080
|
+
readonly = false,
|
5081
|
+
stageRatio = -1,
|
5082
|
+
containerStyle = "",
|
5083
|
+
stageStyle = "",
|
5084
|
+
defaultBoxBodyStyle = null,
|
5085
|
+
defaultBoxStageStyle = null
|
5086
|
+
} = {}) {
|
5087
|
+
this.events = new Emittery();
|
5088
|
+
this._sideEffect = new SideEffectManager();
|
5089
|
+
this.namespace = namespace;
|
5090
|
+
const valManager = new ValManager();
|
5091
|
+
this._sideEffect.addDisposer(() => valManager.destroy());
|
5092
|
+
const root$ = new Val(root);
|
5093
|
+
const readonly$ = new Val(readonly);
|
5094
|
+
const minimized$ = new Val(minimized);
|
5095
|
+
const maximized$ = new Val(maximized);
|
5096
|
+
const fence$ = new Val(fence);
|
5097
|
+
const containerStyle$ = new Val(containerStyle);
|
5098
|
+
const stageStyle$ = new Val(stageStyle);
|
5099
|
+
const stageRatio$ = new Val(stageRatio);
|
5100
|
+
const defaultBoxBodyStyle$ = new Val(defaultBoxBodyStyle);
|
5101
|
+
const defaultBoxStageStyle$ = new Val(defaultBoxStageStyle);
|
5102
|
+
const rootRect$ = new Val({
|
5103
|
+
x: 0,
|
5104
|
+
y: 0,
|
5105
|
+
width: window.innerWidth,
|
5106
|
+
height: window.innerHeight
|
5107
|
+
}, { compare: shallowequal });
|
5108
|
+
this._sideEffect.addDisposer(root$.subscribe((root2) => {
|
4509
5109
|
this._sideEffect.add(() => {
|
4510
|
-
if (!
|
4511
|
-
return () =>
|
4512
|
-
|
4513
|
-
const
|
4514
|
-
const
|
4515
|
-
|
5110
|
+
if (!root2) {
|
5111
|
+
return () => void 0;
|
5112
|
+
}
|
5113
|
+
const observer = new ResizeObserver$2(() => {
|
5114
|
+
const rect = root2.getBoundingClientRect();
|
5115
|
+
rootRect$.setValue({
|
5116
|
+
x: 0,
|
5117
|
+
y: 0,
|
5118
|
+
width: rect.width,
|
5119
|
+
height: rect.height
|
5120
|
+
});
|
4516
5121
|
});
|
4517
|
-
|
5122
|
+
observer.observe(root2);
|
5123
|
+
return () => observer.disconnect();
|
4518
5124
|
}, "calc-root-rect");
|
4519
|
-
})), this.boxes$ = new Val([]), this.topBox$ = new Val(void 0), this._sideEffect.addDisposer(this.boxes$.subscribe((e3) => {
|
4520
|
-
if (e3.length > 0) {
|
4521
|
-
const t3 = e3.reduce((e4, t4) => e4.zIndex > t4.zIndex ? e4 : t4);
|
4522
|
-
this.topBox$.setValue(t3);
|
4523
|
-
} else
|
4524
|
-
this.topBox$.setValue(void 0);
|
4525
5125
|
}));
|
4526
|
-
const
|
4527
|
-
|
4528
|
-
|
4529
|
-
|
4530
|
-
|
4531
|
-
|
5126
|
+
const stageRect$ = combine([rootRect$, stageRatio$], calcStageRect, {
|
5127
|
+
compare: shallowequal
|
5128
|
+
});
|
5129
|
+
this.boxes$ = new Val([]);
|
5130
|
+
this.topBox$ = new Val(void 0);
|
5131
|
+
this._sideEffect.addDisposer(this.boxes$.subscribe((boxes) => {
|
5132
|
+
if (boxes.length > 0) {
|
5133
|
+
const topBox = boxes.reduce((topBox2, box) => topBox2.zIndex > box.zIndex ? topBox2 : box);
|
5134
|
+
this.topBox$.setValue(topBox);
|
5135
|
+
} else {
|
5136
|
+
this.topBox$.setValue(void 0);
|
5137
|
+
}
|
4532
5138
|
}));
|
4533
|
-
const
|
4534
|
-
|
4535
|
-
|
5139
|
+
const prefersDarkMatch = window.matchMedia("(prefers-color-scheme: dark)");
|
5140
|
+
const prefersDark$ = new Val(false);
|
5141
|
+
if (prefersDarkMatch) {
|
5142
|
+
prefersDark$.setValue(prefersDarkMatch.matches);
|
5143
|
+
this._sideEffect.add(() => {
|
5144
|
+
const handler = (evt) => {
|
5145
|
+
prefersDark$.setValue(evt.matches);
|
5146
|
+
};
|
5147
|
+
prefersDarkMatch.addEventListener("change", handler);
|
5148
|
+
return () => prefersDarkMatch.removeEventListener("change", handler);
|
5149
|
+
});
|
5150
|
+
}
|
5151
|
+
const prefersColorScheme$ = new Val(prefersColorScheme);
|
5152
|
+
this._sideEffect.addDisposer(prefersColorScheme$.reaction((prefersColorScheme2, skipUpdate) => {
|
5153
|
+
if (!skipUpdate) {
|
5154
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.PrefersColorScheme, prefersColorScheme2);
|
5155
|
+
}
|
4536
5156
|
}));
|
4537
|
-
const
|
4538
|
-
|
4539
|
-
|
4540
|
-
|
4541
|
-
|
4542
|
-
|
4543
|
-
|
4544
|
-
|
4545
|
-
|
4546
|
-
|
5157
|
+
const darkMode$ = combine([prefersDark$, prefersColorScheme$], ([prefersDark, prefersColorScheme2]) => prefersColorScheme2 === "auto" ? prefersDark : prefersColorScheme2 === "dark");
|
5158
|
+
const state$ = combine([minimized$, maximized$], ([minimized2, maximized2]) => minimized2 ? TELE_BOX_STATE.Minimized : maximized2 ? TELE_BOX_STATE.Maximized : TELE_BOX_STATE.Normal);
|
5159
|
+
this.collector = collector != null ? collector : new TeleBoxCollector({
|
5160
|
+
minimized$,
|
5161
|
+
readonly$,
|
5162
|
+
darkMode$,
|
5163
|
+
namespace,
|
5164
|
+
root$
|
5165
|
+
});
|
5166
|
+
const readonlyValConfig = {
|
5167
|
+
darkMode: darkMode$,
|
5168
|
+
state: state$,
|
5169
|
+
root: root$,
|
5170
|
+
rootRect: rootRect$,
|
5171
|
+
stageRect: stageRect$
|
5172
|
+
};
|
5173
|
+
withReadonlyValueEnhancer(this, readonlyValConfig, valManager);
|
5174
|
+
const valConfig = {
|
5175
|
+
prefersColorScheme: prefersColorScheme$,
|
5176
|
+
readonly: readonly$,
|
5177
|
+
fence: fence$,
|
5178
|
+
minimized: minimized$,
|
5179
|
+
maximized: maximized$,
|
5180
|
+
stageRatio: stageRatio$,
|
5181
|
+
containerStyle: containerStyle$,
|
5182
|
+
stageStyle: stageStyle$,
|
5183
|
+
defaultBoxBodyStyle: defaultBoxBodyStyle$,
|
5184
|
+
defaultBoxStageStyle: defaultBoxStageStyle$
|
5185
|
+
};
|
5186
|
+
withValueEnhancer(this, valConfig, valManager);
|
5187
|
+
const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
|
5188
|
+
const checkFocusBox = (ev) => {
|
5189
|
+
var _a;
|
5190
|
+
if (!ev.isPrimary || readonly$.value) {
|
4547
5191
|
return;
|
4548
|
-
|
4549
|
-
|
4550
|
-
|
4551
|
-
|
5192
|
+
}
|
5193
|
+
const target = ev.target;
|
5194
|
+
if (!target.tagName) {
|
5195
|
+
return;
|
5196
|
+
}
|
5197
|
+
for (let el = target; el; el = el.parentElement) {
|
5198
|
+
if (el.classList && el.classList.contains(closeBtnClassName)) {
|
5199
|
+
return;
|
5200
|
+
}
|
5201
|
+
const id2 = (_a = el.dataset) == null ? void 0 : _a.teleBoxID;
|
5202
|
+
if (id2) {
|
5203
|
+
const box = this.getBox(id2);
|
5204
|
+
if (box) {
|
5205
|
+
this.focusBox(box);
|
5206
|
+
this.makeBoxTop(box);
|
4552
5207
|
return;
|
4553
|
-
const e4 = (t3 = s3.dataset) == null ? void 0 : t3.teleBoxID;
|
4554
|
-
if (e4) {
|
4555
|
-
const t4 = this.getBox(e4);
|
4556
|
-
if (t4)
|
4557
|
-
return this.focusBox(t4), void this.makeBoxTop(t4);
|
4558
5208
|
}
|
4559
5209
|
}
|
5210
|
+
}
|
4560
5211
|
};
|
4561
|
-
this._sideEffect.addEventListener(window, "
|
4562
|
-
|
4563
|
-
|
4564
|
-
|
4565
|
-
|
4566
|
-
|
4567
|
-
|
4568
|
-
|
4569
|
-
|
4570
|
-
|
4571
|
-
}
|
4572
|
-
|
4573
|
-
|
4574
|
-
|
4575
|
-
|
4576
|
-
|
4577
|
-
|
4578
|
-
|
4579
|
-
|
4580
|
-
|
5212
|
+
this._sideEffect.addEventListener(window, "pointerdown", checkFocusBox, true);
|
5213
|
+
this.$container = document.createElement("div");
|
5214
|
+
this.$container.className = this.wrapClassName("manager-container");
|
5215
|
+
this.$stage = document.createElement("div");
|
5216
|
+
this.$stage.className = this.wrapClassName("manager-stage");
|
5217
|
+
this.$container.appendChild(this.$stage);
|
5218
|
+
this._sideEffect.addDisposer([
|
5219
|
+
darkMode$.subscribe((darkMode) => {
|
5220
|
+
this.$container.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
|
5221
|
+
this.$container.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
|
5222
|
+
}),
|
5223
|
+
maximized$.subscribe((maximized2) => {
|
5224
|
+
this.$container.classList.toggle("is-maximized", maximized2);
|
5225
|
+
}),
|
5226
|
+
minimized$.subscribe((minimized2) => {
|
5227
|
+
this.$container.classList.toggle("is-minimized", minimized2);
|
5228
|
+
}),
|
5229
|
+
containerStyle$.subscribe((containerStyle2) => {
|
5230
|
+
this.$container.style.cssText = containerStyle2;
|
5231
|
+
}),
|
5232
|
+
stageStyle$.subscribe((stageStyle2) => {
|
5233
|
+
this.$stage.style.cssText = stageStyle2;
|
5234
|
+
this.$stage.style.width = stageRect$.value.width + "px";
|
5235
|
+
this.$stage.style.height = stageRect$.value.height + "px";
|
5236
|
+
}),
|
5237
|
+
stageRect$.subscribe((stageRect) => {
|
5238
|
+
this.$stage.style.width = stageRect.width + "px";
|
5239
|
+
this.$stage.style.height = stageRect.height + "px";
|
5240
|
+
}),
|
5241
|
+
root$.subscribe((root2) => {
|
5242
|
+
if (root2) {
|
5243
|
+
root2.appendChild(this.$container);
|
5244
|
+
} else if (this.$container.parentElement) {
|
5245
|
+
this.$container.remove();
|
5246
|
+
}
|
5247
|
+
})
|
5248
|
+
]);
|
5249
|
+
this.titleBar = new MaxTitleBar({
|
5250
|
+
namespace: this.namespace,
|
5251
|
+
title$: derive(this.topBox$, (topBox) => (topBox == null ? void 0 : topBox.title) || ""),
|
5252
|
+
boxes$: this.boxes$,
|
5253
|
+
darkMode$,
|
5254
|
+
readonly$,
|
5255
|
+
state$,
|
5256
|
+
rootRect$,
|
5257
|
+
root: this.$container,
|
5258
|
+
onEvent: (event) => {
|
5259
|
+
switch (event.type) {
|
5260
|
+
case TELE_BOX_DELEGATE_EVENT.Maximize: {
|
5261
|
+
maximized$.setValue(!maximized$.value);
|
5262
|
+
break;
|
5263
|
+
}
|
5264
|
+
case TELE_BOX_DELEGATE_EVENT.Minimize: {
|
5265
|
+
minimized$.setValue(true);
|
5266
|
+
break;
|
5267
|
+
}
|
5268
|
+
case TELE_BOX_EVENT.Close: {
|
5269
|
+
this.removeTopBox();
|
5270
|
+
this.focusTopBox();
|
5271
|
+
break;
|
5272
|
+
}
|
5273
|
+
}
|
5274
|
+
}
|
5275
|
+
});
|
5276
|
+
this._sideEffect.addDisposer([
|
5277
|
+
state$.reaction((state, skipUpdate) => {
|
5278
|
+
if (!skipUpdate) {
|
5279
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.State, state);
|
5280
|
+
}
|
5281
|
+
}),
|
5282
|
+
maximized$.reaction((maximized2, skipUpdate) => {
|
5283
|
+
if (!skipUpdate) {
|
5284
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Maximized, maximized2);
|
5285
|
+
}
|
5286
|
+
}),
|
5287
|
+
minimized$.reaction((minimized2, skipUpdate) => {
|
5288
|
+
if (!skipUpdate) {
|
5289
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Minimized, minimized2);
|
5290
|
+
}
|
5291
|
+
}),
|
5292
|
+
darkMode$.reaction((darkMode, skipUpdate) => {
|
5293
|
+
if (!skipUpdate) {
|
5294
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.DarkMode, darkMode);
|
5295
|
+
}
|
5296
|
+
})
|
5297
|
+
]);
|
4581
5298
|
}
|
4582
5299
|
get boxes() {
|
4583
5300
|
return this.boxes$.value;
|
@@ -4585,143 +5302,300 @@ class F$3 {
|
|
4585
5302
|
get topBox() {
|
4586
5303
|
return this.topBox$.value;
|
4587
5304
|
}
|
4588
|
-
setState(
|
4589
|
-
switch (
|
4590
|
-
case
|
4591
|
-
this.setMinimized(false,
|
5305
|
+
setState(state, skipUpdate = false) {
|
5306
|
+
switch (state) {
|
5307
|
+
case TELE_BOX_STATE.Maximized: {
|
5308
|
+
this.setMinimized(false, skipUpdate);
|
5309
|
+
this.setMaximized(true, skipUpdate);
|
5310
|
+
break;
|
5311
|
+
}
|
5312
|
+
case TELE_BOX_STATE.Minimized: {
|
5313
|
+
this.setMinimized(true, skipUpdate);
|
5314
|
+
this.setMaximized(false, skipUpdate);
|
4592
5315
|
break;
|
4593
|
-
|
4594
|
-
|
5316
|
+
}
|
5317
|
+
default: {
|
5318
|
+
this.setMinimized(false, skipUpdate);
|
5319
|
+
this.setMaximized(false, skipUpdate);
|
4595
5320
|
break;
|
4596
|
-
|
4597
|
-
this.setMinimized(false, t2), this.setMaximized(false, t2);
|
5321
|
+
}
|
4598
5322
|
}
|
4599
5323
|
return this;
|
4600
5324
|
}
|
4601
|
-
create(
|
4602
|
-
const
|
4603
|
-
|
4604
|
-
|
4605
|
-
this.
|
4606
|
-
|
4607
|
-
this.
|
4608
|
-
|
4609
|
-
|
4610
|
-
|
4611
|
-
|
4612
|
-
|
4613
|
-
|
4614
|
-
|
4615
|
-
|
4616
|
-
|
4617
|
-
|
4618
|
-
|
4619
|
-
|
4620
|
-
|
4621
|
-
|
4622
|
-
|
4623
|
-
|
4624
|
-
|
4625
|
-
|
4626
|
-
|
4627
|
-
|
4628
|
-
|
4629
|
-
|
4630
|
-
|
4631
|
-
|
5325
|
+
create(config = {}, smartPosition = true) {
|
5326
|
+
const box = new TeleBox(__spreadProps(__spreadValues(__spreadValues({
|
5327
|
+
zIndex: this.topBox ? this.topBox.zIndex + 1 : 100
|
5328
|
+
}, config), smartPosition ? this.smartPosition(config) : {}), {
|
5329
|
+
namespace: this.namespace,
|
5330
|
+
root: this.$stage,
|
5331
|
+
darkMode$: this._darkMode$,
|
5332
|
+
maximized$: this._maximized$,
|
5333
|
+
minimized$: this._minimized$,
|
5334
|
+
fence$: this._fence$,
|
5335
|
+
rootRect$: this._rootRect$,
|
5336
|
+
managerStageRect$: this._stageRect$,
|
5337
|
+
managerStageRatio$: this._stageRatio$,
|
5338
|
+
readonly$: this._readonly$,
|
5339
|
+
collectorRect$: this.collector._rect$,
|
5340
|
+
defaultBoxBodyStyle$: this._defaultBoxBodyStyle$,
|
5341
|
+
defaultBoxStageStyle$: this._defaultBoxStageStyle$
|
5342
|
+
}));
|
5343
|
+
if (box.focus) {
|
5344
|
+
this.focusBox(box);
|
5345
|
+
if (smartPosition) {
|
5346
|
+
this.makeBoxTop(box);
|
5347
|
+
}
|
5348
|
+
}
|
5349
|
+
this.boxes$.setValue([...this.boxes, box]);
|
5350
|
+
this._sideEffect.addDisposer([
|
5351
|
+
box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
|
5352
|
+
this.setMaximized(!this.maximized);
|
5353
|
+
}),
|
5354
|
+
box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Minimize, () => {
|
5355
|
+
this.setMinimized(true);
|
5356
|
+
}),
|
5357
|
+
box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
|
5358
|
+
this.remove(box);
|
5359
|
+
this.focusTopBox();
|
5360
|
+
}),
|
5361
|
+
box._intrinsicCoord$.reaction((_, skipUpdate) => {
|
5362
|
+
if (!skipUpdate) {
|
5363
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicMove, box);
|
5364
|
+
}
|
5365
|
+
}),
|
5366
|
+
box._intrinsicSize$.reaction((_, skipUpdate) => {
|
5367
|
+
if (!skipUpdate) {
|
5368
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicResize, box);
|
5369
|
+
}
|
5370
|
+
}),
|
5371
|
+
box._zIndex$.reaction((_, skipUpdate) => {
|
5372
|
+
if (this.boxes.length > 0) {
|
5373
|
+
const topBox = this.boxes.reduce((topBox2, box2) => topBox2.zIndex > box2.zIndex ? topBox2 : box2);
|
5374
|
+
this.topBox$.setValue(topBox);
|
5375
|
+
}
|
5376
|
+
if (!skipUpdate) {
|
5377
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.ZIndex, box);
|
5378
|
+
}
|
5379
|
+
})
|
5380
|
+
]);
|
5381
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Created, box);
|
5382
|
+
return box;
|
5383
|
+
}
|
5384
|
+
query(config) {
|
5385
|
+
return config ? this.boxes.filter(this.teleBoxMatcher(config)) : [...this.boxes];
|
5386
|
+
}
|
5387
|
+
queryOne(config) {
|
5388
|
+
return config ? this.boxes.find(this.teleBoxMatcher(config)) : this.boxes[0];
|
5389
|
+
}
|
5390
|
+
update(boxID, config, skipUpdate = false) {
|
5391
|
+
const box = this.boxes.find((box2) => box2.id === boxID);
|
5392
|
+
if (box) {
|
5393
|
+
return this.updateBox(box, config, skipUpdate);
|
5394
|
+
}
|
4632
5395
|
}
|
4633
|
-
updateAll(
|
4634
|
-
this.boxes.forEach((
|
4635
|
-
this.updateBox(
|
5396
|
+
updateAll(config, skipUpdate = false) {
|
5397
|
+
this.boxes.forEach((box) => {
|
5398
|
+
this.updateBox(box, config, skipUpdate);
|
4636
5399
|
});
|
4637
5400
|
}
|
4638
|
-
remove(
|
4639
|
-
const
|
4640
|
-
if (
|
4641
|
-
const
|
4642
|
-
|
5401
|
+
remove(boxOrID, skipUpdate = false) {
|
5402
|
+
const index2 = this.getBoxIndex(boxOrID);
|
5403
|
+
if (index2 >= 0) {
|
5404
|
+
const boxes = this.boxes.slice();
|
5405
|
+
const deletedBoxes = boxes.splice(index2, 1);
|
5406
|
+
this.boxes$.setValue(boxes);
|
5407
|
+
deletedBoxes.forEach((box) => box.destroy());
|
5408
|
+
if (!skipUpdate) {
|
5409
|
+
if (this.boxes.length <= 0) {
|
5410
|
+
this.setMaximized(false);
|
5411
|
+
this.setMinimized(false);
|
5412
|
+
}
|
5413
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
|
5414
|
+
}
|
5415
|
+
return deletedBoxes[0];
|
4643
5416
|
}
|
5417
|
+
return;
|
4644
5418
|
}
|
4645
5419
|
removeTopBox() {
|
4646
|
-
if (this.topBox)
|
5420
|
+
if (this.topBox) {
|
4647
5421
|
return this.remove(this.topBox);
|
5422
|
+
}
|
5423
|
+
return;
|
4648
5424
|
}
|
4649
|
-
removeAll(
|
4650
|
-
const
|
4651
|
-
|
5425
|
+
removeAll(skipUpdate = false) {
|
5426
|
+
const deletedBoxes = this.boxes$.value;
|
5427
|
+
this.boxes$.setValue([]);
|
5428
|
+
deletedBoxes.forEach((box) => box.destroy());
|
5429
|
+
if (!skipUpdate) {
|
5430
|
+
if (this.boxes.length <= 0) {
|
5431
|
+
this.setMaximized(false);
|
5432
|
+
this.setMinimized(false);
|
5433
|
+
}
|
5434
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
|
5435
|
+
}
|
5436
|
+
return deletedBoxes;
|
4652
5437
|
}
|
4653
|
-
mount(
|
4654
|
-
this._root$.setValue(
|
5438
|
+
mount(root) {
|
5439
|
+
this._root$.setValue(root);
|
4655
5440
|
}
|
4656
5441
|
unmount() {
|
4657
5442
|
this._root$.setValue(null);
|
4658
5443
|
}
|
4659
|
-
destroy(
|
4660
|
-
this.events.clearListeners()
|
5444
|
+
destroy(skipUpdate = false) {
|
5445
|
+
this.events.clearListeners();
|
5446
|
+
this._sideEffect.flushAll();
|
5447
|
+
this.removeAll(skipUpdate);
|
5448
|
+
this.collector.destroy();
|
5449
|
+
this.titleBar.destroy();
|
4661
5450
|
}
|
4662
|
-
wrapClassName(
|
4663
|
-
return `${this.namespace}-${
|
5451
|
+
wrapClassName(className) {
|
5452
|
+
return `${this.namespace}-${className}`;
|
4664
5453
|
}
|
4665
|
-
focusBox(
|
4666
|
-
const
|
4667
|
-
|
4668
|
-
|
4669
|
-
|
4670
|
-
|
4671
|
-
|
4672
|
-
|
4673
|
-
|
5454
|
+
focusBox(boxOrID, skipUpdate = false) {
|
5455
|
+
const targetBox = this.getBox(boxOrID);
|
5456
|
+
if (targetBox) {
|
5457
|
+
this.boxes.forEach((box) => {
|
5458
|
+
if (targetBox === box) {
|
5459
|
+
let focusChanged = false;
|
5460
|
+
if (!targetBox.focus) {
|
5461
|
+
focusChanged = true;
|
5462
|
+
targetBox._focus$.setValue(true, skipUpdate);
|
5463
|
+
}
|
5464
|
+
if (focusChanged && !skipUpdate) {
|
5465
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Focused, targetBox);
|
5466
|
+
}
|
5467
|
+
} else if (box.focus) {
|
5468
|
+
this.blurBox(box, skipUpdate);
|
5469
|
+
}
|
5470
|
+
});
|
5471
|
+
this.titleBar.focusBox(targetBox);
|
5472
|
+
}
|
4674
5473
|
}
|
4675
5474
|
focusTopBox() {
|
4676
|
-
if (this.topBox && !this.topBox.focus)
|
5475
|
+
if (this.topBox && !this.topBox.focus) {
|
4677
5476
|
return this.focusBox(this.topBox);
|
5477
|
+
}
|
4678
5478
|
}
|
4679
|
-
blurBox(
|
4680
|
-
const
|
4681
|
-
|
4682
|
-
|
4683
|
-
|
4684
|
-
|
4685
|
-
|
4686
|
-
|
4687
|
-
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
updateBox(e2, t2, i2 = false) {
|
4693
|
-
var s2, a2, n2, o2, r2, h;
|
4694
|
-
t2.x == null && t2.y == null || e2._intrinsicCoord$.setValue({ x: (s2 = t2.x) != null ? s2 : e2.intrinsicX, y: (a2 = t2.y) != null ? a2 : e2.intrinsicY }, i2), t2.width == null && t2.height == null || e2._intrinsicSize$.setValue({ width: (n2 = t2.width) != null ? n2 : e2.intrinsicWidth, height: (o2 = t2.height) != null ? o2 : e2.intrinsicHeight }, i2), t2.title != null && e2._title$.setValue(t2.title), t2.visible != null && e2._visible$.setValue(t2.visible, i2), t2.resizable != null && e2._resizable$.setValue(t2.resizable, i2), t2.draggable != null && e2._draggable$.setValue(t2.draggable, i2), t2.ratio != null && e2._ratio$.setValue(t2.ratio, i2), t2.zIndex != null && e2._zIndex$.setValue(t2.zIndex, i2), t2.stageRatio !== void 0 && e2.setStageRatio(t2.stageRatio, i2), t2.content != null && e2.mountContent(t2.content), t2.footer != null && e2.mountFooter(t2.footer), t2.minHeight == null && t2.minWidth == null || e2._minSize$.setValue({ width: (r2 = t2.minWidth) != null ? r2 : e2.minWidth, height: (h = t2.minHeight) != null ? h : e2.minHeight }, i2);
|
5479
|
+
blurBox(boxOrID, skipUpdate = false) {
|
5480
|
+
const targetBox = this.getBox(boxOrID);
|
5481
|
+
if (targetBox) {
|
5482
|
+
if (targetBox.focus) {
|
5483
|
+
targetBox._focus$.setValue(false, skipUpdate);
|
5484
|
+
if (!skipUpdate) {
|
5485
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, targetBox);
|
5486
|
+
}
|
5487
|
+
}
|
5488
|
+
if (this.titleBar.focusedBox === targetBox) {
|
5489
|
+
this.titleBar.focusBox();
|
5490
|
+
}
|
5491
|
+
}
|
4695
5492
|
}
|
4696
|
-
|
4697
|
-
|
4698
|
-
|
4699
|
-
|
4700
|
-
|
4701
|
-
|
4702
|
-
|
4703
|
-
|
5493
|
+
blurAll(skipUpdate = false) {
|
5494
|
+
this.boxes.forEach((box) => {
|
5495
|
+
if (box.focus) {
|
5496
|
+
box._focus$.setValue(false, skipUpdate);
|
5497
|
+
if (!skipUpdate) {
|
5498
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, box);
|
5499
|
+
}
|
5500
|
+
}
|
5501
|
+
});
|
5502
|
+
if (this.titleBar.focusedBox) {
|
5503
|
+
this.titleBar.focusBox();
|
5504
|
+
}
|
5505
|
+
}
|
5506
|
+
teleBoxMatcher(config) {
|
5507
|
+
const keys = Object.keys(config);
|
5508
|
+
return (box) => keys.every((key) => config[key] === box[key]);
|
5509
|
+
}
|
5510
|
+
updateBox(box, config, skipUpdate = false) {
|
5511
|
+
var _a, _b, _c, _d, _e, _f;
|
5512
|
+
if (config.x != null || config.y != null) {
|
5513
|
+
box._intrinsicCoord$.setValue({
|
5514
|
+
x: (_a = config.x) != null ? _a : box.intrinsicX,
|
5515
|
+
y: (_b = config.y) != null ? _b : box.intrinsicY
|
5516
|
+
}, skipUpdate);
|
5517
|
+
}
|
5518
|
+
if (config.width != null || config.height != null) {
|
5519
|
+
box._intrinsicSize$.setValue({
|
5520
|
+
width: (_c = config.width) != null ? _c : box.intrinsicWidth,
|
5521
|
+
height: (_d = config.height) != null ? _d : box.intrinsicHeight
|
5522
|
+
}, skipUpdate);
|
5523
|
+
}
|
5524
|
+
if (config.title != null) {
|
5525
|
+
box._title$.setValue(config.title);
|
5526
|
+
}
|
5527
|
+
if (config.visible != null) {
|
5528
|
+
box._visible$.setValue(config.visible, skipUpdate);
|
5529
|
+
}
|
5530
|
+
if (config.resizable != null) {
|
5531
|
+
box._resizable$.setValue(config.resizable, skipUpdate);
|
5532
|
+
}
|
5533
|
+
if (config.draggable != null) {
|
5534
|
+
box._draggable$.setValue(config.draggable, skipUpdate);
|
5535
|
+
}
|
5536
|
+
if (config.boxRatio != null) {
|
5537
|
+
box._boxRatio$.setValue(config.boxRatio, skipUpdate);
|
5538
|
+
}
|
5539
|
+
if (config.zIndex != null) {
|
5540
|
+
box._zIndex$.setValue(config.zIndex, skipUpdate);
|
5541
|
+
}
|
5542
|
+
if (config.stageRatio !== void 0) {
|
5543
|
+
box.setStageRatio(config.stageRatio, skipUpdate);
|
5544
|
+
}
|
5545
|
+
if (config.content != null) {
|
5546
|
+
box.mountContent(config.content);
|
5547
|
+
}
|
5548
|
+
if (config.footer != null) {
|
5549
|
+
box.mountFooter(config.footer);
|
5550
|
+
}
|
5551
|
+
if (config.minHeight != null || config.minWidth != null) {
|
5552
|
+
box._minSize$.setValue({
|
5553
|
+
width: (_e = config.minWidth) != null ? _e : box.minWidth,
|
5554
|
+
height: (_f = config.minHeight) != null ? _f : box.minHeight
|
5555
|
+
}, skipUpdate);
|
5556
|
+
}
|
5557
|
+
}
|
5558
|
+
smartPosition(rect) {
|
5559
|
+
let { x: x2, y: y2 } = rect;
|
5560
|
+
const { width = 0.5, height = 0.5 } = rect;
|
5561
|
+
const stageRect = this.stageRect;
|
5562
|
+
const topBox = this.topBox;
|
5563
|
+
if (x2 == null) {
|
5564
|
+
let pxX = 20;
|
5565
|
+
if (topBox) {
|
5566
|
+
const pxPreferredX = topBox.pxIntrinsicCoord.x + 20;
|
5567
|
+
const pxIntrinsicWidth = width * stageRect.width;
|
5568
|
+
if (pxPreferredX + pxIntrinsicWidth <= stageRect.width) {
|
5569
|
+
pxX = pxPreferredX;
|
5570
|
+
}
|
4704
5571
|
}
|
4705
|
-
|
5572
|
+
x2 = pxX / stageRect.width;
|
4706
5573
|
}
|
4707
|
-
if (
|
4708
|
-
let
|
4709
|
-
if (
|
4710
|
-
const
|
4711
|
-
|
5574
|
+
if (y2 == null) {
|
5575
|
+
let pxY = 20;
|
5576
|
+
if (topBox) {
|
5577
|
+
const pxPreferredY = topBox.pxIntrinsicCoord.y + 20;
|
5578
|
+
const pxIntrinsicHeight = height * stageRect.height;
|
5579
|
+
if (pxPreferredY + pxIntrinsicHeight <= stageRect.height) {
|
5580
|
+
pxY = pxPreferredY;
|
5581
|
+
}
|
4712
5582
|
}
|
4713
|
-
|
5583
|
+
y2 = pxY / stageRect.height;
|
4714
5584
|
}
|
4715
|
-
return { x:
|
5585
|
+
return { x: x2, y: y2, width, height };
|
4716
5586
|
}
|
4717
|
-
makeBoxTop(
|
4718
|
-
|
5587
|
+
makeBoxTop(box, skipUpdate = false) {
|
5588
|
+
if (this.topBox) {
|
5589
|
+
if (box !== this.topBox) {
|
5590
|
+
box._zIndex$.setValue(this.topBox.zIndex + 1, skipUpdate);
|
5591
|
+
}
|
5592
|
+
}
|
4719
5593
|
}
|
4720
|
-
getBoxIndex(
|
4721
|
-
return typeof
|
5594
|
+
getBoxIndex(boxOrID) {
|
5595
|
+
return typeof boxOrID === "string" ? this.boxes.findIndex((box) => box.id === boxOrID) : this.boxes.findIndex((box) => box === boxOrID);
|
4722
5596
|
}
|
4723
|
-
getBox(
|
4724
|
-
return typeof
|
5597
|
+
getBox(boxOrID) {
|
5598
|
+
return typeof boxOrID === "string" ? this.boxes.find((box) => box.id === boxOrID) : boxOrID;
|
4725
5599
|
}
|
4726
5600
|
}
|
4727
5601
|
const createBoxManager = (manager, callbacks2, emitter2, boxEmitter2, options) => {
|
@@ -4819,13 +5693,6 @@ class BoxManager {
|
|
4819
5693
|
this.teleBoxManager.events.on("z_index", (box) => {
|
4820
5694
|
this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
|
4821
5695
|
}),
|
4822
|
-
this.teleBoxManager._stageRect$.subscribe((stage) => {
|
4823
|
-
emitter2.emit("playgroundSizeChange", stage);
|
4824
|
-
this.context.notifyContainerRectUpdate(stage);
|
4825
|
-
}),
|
4826
|
-
emitter2.on("writableChange", (isWritable) => {
|
4827
|
-
this.teleBoxManager.setHighlightStage(isWritable);
|
4828
|
-
}),
|
4829
5696
|
emitter2.on("containerSizeRatioUpdate", (ratio) => {
|
4830
5697
|
this.teleBoxManager._stageRatio$.setValue(ratio);
|
4831
5698
|
})
|
@@ -4862,7 +5729,7 @@ class BoxManager {
|
|
4862
5729
|
var _a, _b, _c;
|
4863
5730
|
if (!this.teleBoxManager)
|
4864
5731
|
return;
|
4865
|
-
let { minwidth = MIN_WIDTH, minheight = MIN_HEIGHT } = (_a = params.app.config) != null ? _a : {};
|
5732
|
+
let { minwidth = MIN_WIDTH, minheight = MIN_HEIGHT, enableShadowDOM = true } = (_a = params.app.config) != null ? _a : {};
|
4866
5733
|
const { width, height } = (_b = params.app.config) != null ? _b : {};
|
4867
5734
|
const title = ((_c = params.options) == null ? void 0 : _c.title) || params.appId;
|
4868
5735
|
const rect = this.teleBoxManager.rootRect;
|
@@ -4878,7 +5745,8 @@ class BoxManager {
|
|
4878
5745
|
minHeight: minheight,
|
4879
5746
|
width,
|
4880
5747
|
height,
|
4881
|
-
id: params.appId
|
5748
|
+
id: params.appId,
|
5749
|
+
enableShadowDOM
|
4882
5750
|
};
|
4883
5751
|
const box = this.teleBoxManager.create(createBoxConfig, params.smartPosition);
|
4884
5752
|
this.context.emitter.emit(`${params.appId}${Events.WindowCreated}`);
|
@@ -4890,10 +5758,15 @@ class BoxManager {
|
|
4890
5758
|
stageRatio: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.stageRatio,
|
4891
5759
|
root,
|
4892
5760
|
fence: false,
|
4893
|
-
prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme
|
4894
|
-
highlightStage: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.highlightStage
|
5761
|
+
prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme
|
4895
5762
|
};
|
4896
|
-
|
5763
|
+
if (createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.containerStyle) {
|
5764
|
+
initManagerState.containerStyle = createTeleBoxManagerConfig.containerStyle;
|
5765
|
+
}
|
5766
|
+
if (createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.stageStyle) {
|
5767
|
+
initManagerState.stageStyle = createTeleBoxManagerConfig.stageStyle;
|
5768
|
+
}
|
5769
|
+
const manager = new TeleBoxManager(initManagerState);
|
4897
5770
|
if (this.teleBoxManager) {
|
4898
5771
|
this.teleBoxManager.destroy();
|
4899
5772
|
}
|
@@ -4925,18 +5798,19 @@ class BoxManager {
|
|
4925
5798
|
return this.teleBoxManager.topBox;
|
4926
5799
|
}
|
4927
5800
|
updateBoxState(state) {
|
4928
|
-
var _a, _b, _c, _d;
|
4929
5801
|
if (!state)
|
4930
5802
|
return;
|
4931
5803
|
const box = this.getBox(state.id);
|
4932
5804
|
if (box) {
|
4933
|
-
|
4934
|
-
|
4935
|
-
|
4936
|
-
|
4937
|
-
|
4938
|
-
|
4939
|
-
|
5805
|
+
if (state.size) {
|
5806
|
+
box._intrinsicSize$.setValue(state.size, true);
|
5807
|
+
}
|
5808
|
+
if (state.position) {
|
5809
|
+
box._intrinsicCoord$.setValue(state.position, true);
|
5810
|
+
}
|
5811
|
+
if (state.zIndex) {
|
5812
|
+
box._zIndex$.setValue(state.zIndex, true);
|
5813
|
+
}
|
4940
5814
|
setTimeout(() => {
|
4941
5815
|
if (state.focus) {
|
4942
5816
|
this.teleBoxManager.focusBox(box.id, true);
|
@@ -4952,13 +5826,19 @@ class BoxManager {
|
|
4952
5826
|
}
|
4953
5827
|
}
|
4954
5828
|
moveBox({ appId, x: x2, y: y2 }) {
|
4955
|
-
this.
|
5829
|
+
const box = this.getBox(appId);
|
5830
|
+
if (box) {
|
5831
|
+
box._intrinsicCoord$.setValue({ x: x2, y: y2 }, true);
|
5832
|
+
}
|
4956
5833
|
}
|
4957
5834
|
focusBox({ appId }, skipUpdate = true) {
|
4958
5835
|
this.teleBoxManager.focusBox(appId, skipUpdate);
|
4959
5836
|
}
|
4960
5837
|
resizeBox({ appId, width, height, skipUpdate }) {
|
4961
|
-
this.
|
5838
|
+
const box = this.getBox(appId);
|
5839
|
+
if (box) {
|
5840
|
+
box._intrinsicSize$.setValue({ width, height }, skipUpdate);
|
5841
|
+
}
|
4962
5842
|
}
|
4963
5843
|
setBoxMinSize(params) {
|
4964
5844
|
this.teleBoxManager.update(params.appId, {
|
@@ -5628,11 +6508,14 @@ class Cursor {
|
|
5628
6508
|
let translateX = point.x - 2;
|
5629
6509
|
let translateY = point.y - 18;
|
5630
6510
|
if (type === "app") {
|
5631
|
-
const wrapperRect = this.cursorManager.
|
6511
|
+
const wrapperRect = this.cursorManager.playgroundRect;
|
5632
6512
|
if (wrapperRect) {
|
5633
6513
|
translateX = translateX + rect.x - wrapperRect.x;
|
5634
6514
|
translateY = translateY + rect.y - wrapperRect.y;
|
5635
6515
|
}
|
6516
|
+
} else {
|
6517
|
+
translateX = translateX + rect.x;
|
6518
|
+
translateY = translateY + rect.y;
|
5636
6519
|
}
|
5637
6520
|
if (point.x < 0 || point.x > rect.width || point.y < 0 || point.y > rect.height) {
|
5638
6521
|
(_a = this.component) == null ? void 0 : _a.$set({ visible: false, x: translateX, y: translateY });
|
@@ -5863,7 +6746,6 @@ class CursorManager {
|
|
5863
6746
|
wrapper.removeEventListener("pointerleave", this.mouseLeaveListener);
|
5864
6747
|
};
|
5865
6748
|
});
|
5866
|
-
this.wrapperRect = wrapper.getBoundingClientRect();
|
5867
6749
|
}
|
5868
6750
|
setMainViewDivElement(div) {
|
5869
6751
|
this.mainViewElement = div;
|
@@ -5892,8 +6774,9 @@ class CursorManager {
|
|
5892
6774
|
}
|
5893
6775
|
}
|
5894
6776
|
updateContainerRect() {
|
5895
|
-
var _a;
|
5896
|
-
this.wrapperRect = (_a =
|
6777
|
+
var _a, _b;
|
6778
|
+
this.wrapperRect = (_a = this.manager.boxManager) == null ? void 0 : _a.teleBoxManager.stageRect;
|
6779
|
+
this.playgroundRect = (_b = WindowManager.playground) == null ? void 0 : _b.getBoundingClientRect();
|
5897
6780
|
}
|
5898
6781
|
deleteCursor(uid) {
|
5899
6782
|
this.store.cleanCursor(uid);
|
@@ -15632,6 +16515,10 @@ const BuiltinApps = {
|
|
15632
16515
|
DocsViewer: NetlessAppDocsViewer.kind,
|
15633
16516
|
MediaPlayer: K.kind
|
15634
16517
|
};
|
16518
|
+
const BuiltinAppsMap = {
|
16519
|
+
[BuiltinApps.DocsViewer]: NetlessAppDocsViewer,
|
16520
|
+
[BuiltinApps.MediaPlayer]: K
|
16521
|
+
};
|
15635
16522
|
var videoJs = "";
|
15636
16523
|
var style$1 = "";
|
15637
16524
|
var style = "";
|
@@ -15639,15 +16526,15 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
|
|
15639
16526
|
const _WindowManager = class extends InvisiblePlugin {
|
15640
16527
|
constructor(context) {
|
15641
16528
|
super(context);
|
15642
|
-
this.version = "1.0.0-canary.
|
15643
|
-
this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.
|
16529
|
+
this.version = "1.0.0-canary.27";
|
16530
|
+
this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.25", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@playwright/test": "^1.23.0", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/node": "^18.0.0", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vite-plugin-dts": "^1.2.0", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
|
15644
16531
|
this.emitter = callbacks$1;
|
15645
16532
|
this.viewMode = ViewMode.Broadcaster;
|
15646
16533
|
this.viewMode$ = new Val(ViewMode.Broadcaster);
|
15647
16534
|
this.isReplay = isPlayer(this.displayer);
|
15648
16535
|
this.containerSizeRatio = _WindowManager.containerSizeRatio;
|
15649
16536
|
_WindowManager.displayer = context.displayer;
|
15650
|
-
window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.
|
16537
|
+
window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.25", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@playwright/test": "^1.23.0", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/node": "^18.0.0", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vite-plugin-dts": "^1.2.0", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
|
15651
16538
|
}
|
15652
16539
|
static async mount(params) {
|
15653
16540
|
var _a;
|
@@ -15702,7 +16589,8 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
15702
16589
|
collectorStyles: params.collectorStyles,
|
15703
16590
|
prefersColorScheme: params.prefersColorScheme,
|
15704
16591
|
stageRatio: _WindowManager.containerSizeRatio,
|
15705
|
-
|
16592
|
+
containerStyle: params.containerStyle,
|
16593
|
+
stageStyle: params.stageStyle
|
15706
16594
|
});
|
15707
16595
|
(_a = manager.appManager) == null ? void 0 : _a.setBoxManager(manager.boxManager);
|
15708
16596
|
if (params.container) {
|
@@ -15729,22 +16617,22 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
15729
16617
|
} catch (error) {
|
15730
16618
|
throw new Error("[WindowManger]: room must be switched to be writable");
|
15731
16619
|
}
|
15732
|
-
manager = await
|
15733
|
-
manager.ensureAttributes();
|
16620
|
+
manager = await createInvisiblePlugin(room);
|
16621
|
+
manager == null ? void 0 : manager.ensureAttributes();
|
15734
16622
|
await wait(500);
|
15735
16623
|
await room.setWritable(false);
|
15736
16624
|
} else {
|
15737
|
-
manager = await
|
16625
|
+
manager = await createInvisiblePlugin(room);
|
15738
16626
|
}
|
15739
16627
|
}
|
15740
16628
|
}
|
15741
16629
|
return manager;
|
15742
16630
|
}
|
15743
|
-
static initContainer(container, overwriteStyles) {
|
16631
|
+
static initContainer(container, target, overwriteStyles) {
|
15744
16632
|
if (!_WindowManager.container) {
|
15745
16633
|
_WindowManager.container = container;
|
15746
16634
|
}
|
15747
|
-
const { playground, mainViewElement } = setupWrapper(container);
|
16635
|
+
const { playground, mainViewElement } = setupWrapper(container, target);
|
15748
16636
|
_WindowManager.playground = playground;
|
15749
16637
|
if (overwriteStyles) {
|
15750
16638
|
const style2 = document.createElement("style");
|
@@ -15757,7 +16645,7 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
15757
16645
|
return appRegister.registered;
|
15758
16646
|
}
|
15759
16647
|
bindContainer(container) {
|
15760
|
-
var _a, _b, _c, _d, _e;
|
16648
|
+
var _a, _b, _c, _d, _e, _f;
|
15761
16649
|
if (isRoom(this.displayer) && this.room.phase !== RoomPhase.Connected) {
|
15762
16650
|
throw new BindContainerRoomPhaseInvalidError();
|
15763
16651
|
}
|
@@ -15766,23 +16654,24 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
15766
16654
|
container.appendChild(_WindowManager.container.firstChild);
|
15767
16655
|
}
|
15768
16656
|
} else {
|
15769
|
-
|
16657
|
+
const teleboxContainer = (_a = this.boxManager) == null ? void 0 : _a.teleBoxManager.$stage;
|
16658
|
+
if (_WindowManager.params && teleboxContainer) {
|
15770
16659
|
const params = _WindowManager.params;
|
15771
|
-
const mainViewElement = _WindowManager.initContainer(container, params.overwriteStyles);
|
16660
|
+
const mainViewElement = _WindowManager.initContainer(container, teleboxContainer, params.overwriteStyles);
|
15772
16661
|
if (this.boxManager && _WindowManager.playground) {
|
15773
16662
|
this.boxManager.setRoot(_WindowManager.playground);
|
15774
16663
|
}
|
15775
16664
|
this.bindMainView(mainViewElement, params.disableCameraTransform);
|
15776
16665
|
if (_WindowManager.playground) {
|
15777
|
-
(
|
16666
|
+
(_b = this.cursorManager) == null ? void 0 : _b.setupWrapper(_WindowManager.playground);
|
15778
16667
|
}
|
15779
16668
|
}
|
15780
16669
|
}
|
15781
16670
|
emitter.emit("updateManagerRect");
|
15782
|
-
(
|
15783
|
-
(
|
15784
|
-
(
|
15785
|
-
(
|
16671
|
+
(_c = this.appManager) == null ? void 0 : _c.refresh();
|
16672
|
+
(_d = this.appManager) == null ? void 0 : _d.resetMaximized();
|
16673
|
+
(_e = this.appManager) == null ? void 0 : _e.resetMinimized();
|
16674
|
+
(_f = this.appManager) == null ? void 0 : _f.displayerWritableListener(!this.room.isWritable);
|
15786
16675
|
_WindowManager.container = container;
|
15787
16676
|
}
|
15788
16677
|
bindCollectorContainer(container) {
|
@@ -16041,6 +16930,20 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
16041
16930
|
throw new AppManagerNotInitError();
|
16042
16931
|
}
|
16043
16932
|
}
|
16933
|
+
get baseCamera$() {
|
16934
|
+
if (this.appManager) {
|
16935
|
+
return this.appManager.mainViewProxy.camera$;
|
16936
|
+
} else {
|
16937
|
+
throw new AppManagerNotInitError();
|
16938
|
+
}
|
16939
|
+
}
|
16940
|
+
get baseSize$() {
|
16941
|
+
if (this.appManager) {
|
16942
|
+
return this.appManager.mainViewProxy.size$;
|
16943
|
+
} else {
|
16944
|
+
throw new AppManagerNotInitError();
|
16945
|
+
}
|
16946
|
+
}
|
16044
16947
|
get cameraState() {
|
16045
16948
|
if (this.appManager) {
|
16046
16949
|
return this.appManager.mainViewProxy.cameraState;
|
@@ -16134,26 +17037,31 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
16134
17037
|
return (_a = this.appManager) == null ? void 0 : _a.closeApp(appId);
|
16135
17038
|
}
|
16136
17039
|
moveCamera(camera) {
|
16137
|
-
var _a;
|
16138
|
-
const pureCamera = omit(camera, ["animationMode"]);
|
16139
17040
|
const mainViewCamera = __spreadValues({}, this.mainView.camera);
|
16140
|
-
|
17041
|
+
const nextCamera = __spreadValues(__spreadValues({}, mainViewCamera), camera);
|
17042
|
+
if (isEqual(nextCamera, mainViewCamera))
|
16141
17043
|
return;
|
16142
|
-
this.
|
16143
|
-
|
16144
|
-
|
16145
|
-
|
16146
|
-
|
16147
|
-
}, 500);
|
17044
|
+
if (!this.appManager)
|
17045
|
+
return;
|
17046
|
+
this.appManager.mainViewProxy.storeCamera(__spreadValues({
|
17047
|
+
id: this.appManager.uid
|
17048
|
+
}, nextCamera));
|
16148
17049
|
}
|
16149
17050
|
moveCameraToContain(rectangle) {
|
16150
|
-
|
16151
|
-
|
16152
|
-
|
16153
|
-
|
16154
|
-
|
16155
|
-
|
16156
|
-
|
17051
|
+
if (!this.appManager)
|
17052
|
+
return;
|
17053
|
+
const mainViewSize = this.appManager.mainViewProxy.size$.value;
|
17054
|
+
if (mainViewSize) {
|
17055
|
+
const wScale = mainViewSize.width / rectangle.width;
|
17056
|
+
const hScale = mainViewSize.height / rectangle.height;
|
17057
|
+
const nextScale = Math.min(wScale, hScale);
|
17058
|
+
this.appManager.mainViewProxy.storeCamera({
|
17059
|
+
id: this.appManager.uid,
|
17060
|
+
scale: nextScale,
|
17061
|
+
centerX: rectangle.originX,
|
17062
|
+
centerY: rectangle.originY
|
17063
|
+
});
|
17064
|
+
}
|
16157
17065
|
}
|
16158
17066
|
convertToPointInWorld(point) {
|
16159
17067
|
return this.mainView.convertToPointInWorld(point);
|
@@ -16279,6 +17187,14 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
16279
17187
|
this.containerSizeRatio = ratio;
|
16280
17188
|
emitter.emit("containerSizeRatioUpdate", ratio);
|
16281
17189
|
}
|
17190
|
+
setContainerStyle(style2) {
|
17191
|
+
var _a;
|
17192
|
+
(_a = this.boxManager) == null ? void 0 : _a.teleBoxManager.setContainerStyle(style2);
|
17193
|
+
}
|
17194
|
+
setStageStyle(style2) {
|
17195
|
+
var _a;
|
17196
|
+
(_a = this.boxManager) == null ? void 0 : _a.teleBoxManager.setStageStyle(style2);
|
17197
|
+
}
|
16282
17198
|
createPPTHandler() {
|
16283
17199
|
return {
|
16284
17200
|
onPageJumpTo: (_pptUUID, index2) => {
|
@@ -16333,4 +17249,4 @@ WindowManager.debug = false;
|
|
16333
17249
|
WindowManager.containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
16334
17250
|
WindowManager.isCreated = false;
|
16335
17251
|
setupBuiltin();
|
16336
|
-
export { AppCreateError, AppManagerNotInitError, AppNotRegisterError, BindContainerRoomPhaseInvalidError, BoxManagerNotFoundError, BoxNotCreatedError, BuiltinApps, InvalidScenePath, ParamsInvalidError, WhiteWebSDKInvalidError, WindowManager, calculateNextIndex, reconnectRefresher };
|
17252
|
+
export { AppCreateError, AppManagerNotInitError, AppNotRegisterError, BindContainerRoomPhaseInvalidError, BoxManagerNotFoundError, BoxNotCreatedError, BuiltinApps, BuiltinAppsMap, InvalidScenePath, ParamsInvalidError, WhiteWebSDKInvalidError, WindowManager, calculateNextIndex, reconnectRefresher };
|