@netless/window-manager 0.4.60 → 0.4.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -20,7 +20,7 @@ var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
20
20
  import pRetry from "p-retry";
21
21
  import Emittery from "emittery";
22
22
  import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$2, pick, isEmpty, isInteger, orderBy, isFunction, isNumber, isNull } from "lodash";
23
- import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, autorun, toJS, listenDisposed, unlistenDisposed, ViewMode, AnimationMode, isPlayer, isRoom, WhiteVersion, ApplianceNames, RoomPhase, InvisiblePlugin } from "white-web-sdk";
23
+ import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, autorun, toJS, listenDisposed, unlistenDisposed, ViewMode, AnimationMode, isPlayer, isRoom, WhiteVersion, ApplianceNames, RoomPhase, PlayerPhase, InvisiblePlugin } from "white-web-sdk";
24
24
  import { v4 } from "uuid";
25
25
  import { genUID, SideEffectManager } from "side-effect-manager";
26
26
  import { ResizeObserver as ResizeObserver$3 } from "@juggle/resize-observer";
@@ -1117,6 +1117,7 @@ var Fields = /* @__PURE__ */ ((Fields2) => {
1117
1117
  Fields2["CursorState"] = "cursorState";
1118
1118
  Fields2["FullPath"] = "fullPath";
1119
1119
  Fields2["Registered"] = "registered";
1120
+ Fields2["IframeBridge"] = "iframeBridge";
1120
1121
  return Fields2;
1121
1122
  })(Fields || {});
1122
1123
  class AttributesDelegate {
@@ -1260,6 +1261,20 @@ class AttributesDelegate {
1260
1261
  setViewFocusScenePath(mainView, scenePath);
1261
1262
  }
1262
1263
  }
1264
+ getIframeBridge() {
1265
+ return get(this.attributes, ["iframeBridge"]);
1266
+ }
1267
+ setIframeBridge(data) {
1268
+ if (isObject(data)) {
1269
+ const oldState = this.getIframeBridge();
1270
+ for (const key in data) {
1271
+ const value = data[key];
1272
+ if (oldState[key] !== value) {
1273
+ this.context.safeUpdateAttributes(["iframeBridge", key], value);
1274
+ }
1275
+ }
1276
+ }
1277
+ }
1263
1278
  }
1264
1279
  const store = new AttributesDelegate({
1265
1280
  getAttributes: () => {
@@ -1806,8 +1821,18 @@ class MainViewProxy {
1806
1821
  this.setMainViewSize = debounce((size2) => {
1807
1822
  this.store.setMainViewSize(__spreadProps(__spreadValues({}, size2), { id: this.manager.uid }));
1808
1823
  }, 50);
1824
+ this._syncMainViewTimer = 0;
1809
1825
  this.onCameraOrSizeUpdated = () => {
1810
1826
  callbacks$1.emit("cameraStateChange", this.cameraState);
1827
+ if (this.manager.room && this.manager.room.syncMainView) {
1828
+ clearTimeout(this._syncMainViewTimer);
1829
+ this._syncMainViewTimer = setTimeout(this.syncMainView, 100, this.manager.room);
1830
+ }
1831
+ };
1832
+ this.syncMainView = (room) => {
1833
+ if (room.isWritable) {
1834
+ room.syncMainView(this.mainView);
1835
+ }
1811
1836
  };
1812
1837
  this.setViewMode = (mode) => {
1813
1838
  this.viewMode = mode;
@@ -16905,18 +16930,527 @@ const BuiltinApps = {
16905
16930
  var videoJs = "";
16906
16931
  var style$1 = "";
16907
16932
  var style = "";
16933
+ var IframeEvents = /* @__PURE__ */ ((IframeEvents2) => {
16934
+ IframeEvents2["Init"] = "Init";
16935
+ IframeEvents2["AttributesUpdate"] = "AttributesUpdate";
16936
+ IframeEvents2["SetAttributes"] = "SetAttributes";
16937
+ IframeEvents2["RegisterMagixEvent"] = "RegisterMagixEvent";
16938
+ IframeEvents2["RemoveMagixEvent"] = "RemoveMagixEvent";
16939
+ IframeEvents2["RemoveAllMagixEvent"] = "RemoveAllMagixEvent";
16940
+ IframeEvents2["RoomStateChanged"] = "RoomStateChanged";
16941
+ IframeEvents2["DispatchMagixEvent"] = "DispatchMagixEvent";
16942
+ IframeEvents2["ReciveMagixEvent"] = "ReciveMagixEvent";
16943
+ IframeEvents2["NextPage"] = "NextPage";
16944
+ IframeEvents2["PrevPage"] = "PrevPage";
16945
+ IframeEvents2["SDKCreate"] = "SDKCreate";
16946
+ IframeEvents2["OnCreate"] = "OnCreate";
16947
+ IframeEvents2["SetPage"] = "SetPage";
16948
+ IframeEvents2["GetAttributes"] = "GetAttributes";
16949
+ IframeEvents2["Ready"] = "Ready";
16950
+ IframeEvents2["Destory"] = "Destory";
16951
+ IframeEvents2["StartCreate"] = "StartCreate";
16952
+ IframeEvents2["WrapperDidUpdate"] = "WrapperDidUpdate";
16953
+ IframeEvents2["DispayIframe"] = "DispayIframe";
16954
+ IframeEvents2["HideIframe"] = "HideIframe";
16955
+ IframeEvents2["GetRootRect"] = "GetRootRect";
16956
+ IframeEvents2["ReplayRootRect"] = "ReplayRootRect";
16957
+ IframeEvents2["PageTo"] = "PageTo";
16958
+ return IframeEvents2;
16959
+ })(IframeEvents || {});
16960
+ var DomEvents = /* @__PURE__ */ ((DomEvents2) => {
16961
+ DomEvents2["WrapperDidMount"] = "WrapperDidMount";
16962
+ DomEvents2["IframeLoad"] = "IframeLoad";
16963
+ return DomEvents2;
16964
+ })(DomEvents || {});
16965
+ const RefreshIDs = {
16966
+ Ready: "Ready",
16967
+ RootRect: "ReplayRootRect",
16968
+ Message: "message",
16969
+ ComputeStyle: "computeStyle",
16970
+ Load: "load",
16971
+ DisplayerState: "displayerState",
16972
+ Show: "show",
16973
+ Hide: "hide"
16974
+ };
16975
+ const times = (number2, iteratee) => {
16976
+ return new Array(number2).fill(0).map((_, index2) => iteratee(index2));
16977
+ };
16978
+ const _IframeBridge = class {
16979
+ constructor(manager, appManager) {
16980
+ this.manager = manager;
16981
+ this.appManager = appManager;
16982
+ this.magixEventMap = /* @__PURE__ */ new Map();
16983
+ this.cssList = [];
16984
+ this.allowAppliances = ["clicker"];
16985
+ this.bridgeDisposer = noop$2;
16986
+ this.rootRect = null;
16987
+ this.sideEffectManager = new SideEffectManager();
16988
+ this.execListenIframe = debounce((options) => {
16989
+ this.listenIframe(options);
16990
+ }, 50);
16991
+ this.onPhaseChangedListener = (phase) => {
16992
+ if (phase === PlayerPhase.Playing) {
16993
+ this.computedStyleAndIframeDisplay();
16994
+ }
16995
+ };
16996
+ this.stateChangeListener = (state) => {
16997
+ state = __spreadValues({}, state);
16998
+ state.cameraState = this.manager.cameraState;
16999
+ this.postMessage({ kind: "RoomStateChanged", payload: state });
17000
+ if (state.cameraState) {
17001
+ _IframeBridge.emitter.emit("GetRootRect");
17002
+ this.computedStyle(state);
17003
+ }
17004
+ if (state.memberState) {
17005
+ this.computedZindex();
17006
+ this.updateStyle();
17007
+ }
17008
+ if (state.sceneState) {
17009
+ this.computedIframeDisplay(state, this.attributes);
17010
+ }
17011
+ };
17012
+ this.displayer = _IframeBridge.displayer = appManager.displayer;
17013
+ this.iframe = this._createIframe();
17014
+ this.sideEffectManager.addDisposer(_IframeBridge.emitter.on("ReplayRootRect", (rect) => {
17015
+ this.rootRect = rect;
17016
+ }), RefreshIDs.RootRect);
17017
+ this.sideEffectManager.addDisposer(_IframeBridge.emitter.on("HideIframe", () => {
17018
+ this.iframe.className = _IframeBridge.hiddenClass;
17019
+ }), RefreshIDs.Hide);
17020
+ this.sideEffectManager.addDisposer(_IframeBridge.emitter.on("DispayIframe", () => {
17021
+ this.iframe.className = "";
17022
+ }), RefreshIDs.Show);
17023
+ this.sideEffectManager.addDisposer(_IframeBridge.emitter.on("created", () => {
17024
+ this.bridgeDisposer();
17025
+ this.bridgeDisposer = autorun(() => {
17026
+ var _a;
17027
+ const attributes = this.attributes;
17028
+ if (attributes.url) {
17029
+ const iframeSrc = (_a = this.iframe) == null ? void 0 : _a.src;
17030
+ if (iframeSrc && iframeSrc !== attributes.url) {
17031
+ this.execListenIframe(attributes);
17032
+ }
17033
+ }
17034
+ if (attributes.displaySceneDir) {
17035
+ this.computedIframeDisplay(this.displayer.state, attributes);
17036
+ }
17037
+ if ((attributes.width || attributes.height) && this.iframe) {
17038
+ this.iframe.width = `${attributes.width}px`;
17039
+ this.iframe.height = `${attributes.height}px`;
17040
+ }
17041
+ this.postMessage({ kind: "AttributesUpdate", payload: attributes });
17042
+ });
17043
+ }));
17044
+ this.sideEffectManager.addDisposer(manager.emitter.on("cameraStateChange", () => {
17045
+ this.computedStyle(this.displayer.state);
17046
+ }));
17047
+ _IframeBridge.onCreate(this);
17048
+ }
17049
+ static onCreate(plugin) {
17050
+ _IframeBridge.emitter.emit("StartCreate");
17051
+ _IframeBridge.emitter.emit("OnCreate", plugin);
17052
+ _IframeBridge.emitter.emit("created");
17053
+ }
17054
+ insert(options) {
17055
+ const initAttributes = {
17056
+ url: options.url,
17057
+ width: options.width,
17058
+ height: options.height,
17059
+ displaySceneDir: options.displaySceneDir,
17060
+ useClicker: options.useClicker || false,
17061
+ useSelector: options.useSelector
17062
+ };
17063
+ this.setAttributes(initAttributes);
17064
+ const wrapperDidMountListener = () => {
17065
+ this.getIframe();
17066
+ this.listenIframe(this.attributes);
17067
+ this.listenDisplayerState();
17068
+ _IframeBridge.emitter.emit("GetRootRect");
17069
+ };
17070
+ if (this.getIframe()) {
17071
+ wrapperDidMountListener();
17072
+ } else {
17073
+ const didMount = this.sideEffectManager.addDisposer(_IframeBridge.emitter.on("WrapperDidMount", () => {
17074
+ wrapperDidMountListener();
17075
+ this.sideEffectManager.flush(didMount);
17076
+ }));
17077
+ const didUpdate = this.sideEffectManager.addDisposer(_IframeBridge.emitter.on("WrapperDidUpdate", () => {
17078
+ wrapperDidMountListener();
17079
+ this.sideEffectManager.flush(didUpdate);
17080
+ }));
17081
+ }
17082
+ if (this.attributes.useSelector) {
17083
+ this.allowAppliances.push("selector");
17084
+ }
17085
+ this.computedStyle(this.displayer.state);
17086
+ this.listenDisplayerCallbacks();
17087
+ this.getComputedIframeStyle();
17088
+ this.sideEffectManager.addEventListener(window, "message", this.messageListener.bind(this), void 0, RefreshIDs.Message);
17089
+ _IframeBridge.alreadyCreate = true;
17090
+ return this;
17091
+ }
17092
+ getComputedIframeStyle() {
17093
+ this.sideEffectManager.setTimeout(() => {
17094
+ if (this.iframe) {
17095
+ getComputedStyle(this.iframe);
17096
+ }
17097
+ }, 200, RefreshIDs.ComputeStyle);
17098
+ }
17099
+ destroy() {
17100
+ this.sideEffectManager.flushAll();
17101
+ _IframeBridge.emitter.emit("Destory");
17102
+ _IframeBridge.alreadyCreate = false;
17103
+ _IframeBridge.emitter.clearListeners();
17104
+ }
17105
+ getIframe() {
17106
+ this.iframe || (this.iframe = this._createIframe());
17107
+ return this.iframe;
17108
+ }
17109
+ setIframeSize(params) {
17110
+ if (this.iframe) {
17111
+ this.iframe.width = `${params.width}px`;
17112
+ this.iframe.height = `${params.height}px`;
17113
+ this.setAttributes({ width: params.width, height: params.height });
17114
+ }
17115
+ }
17116
+ get attributes() {
17117
+ return this.appManager.store.getIframeBridge();
17118
+ }
17119
+ setAttributes(data) {
17120
+ this.appManager.store.setIframeBridge(data);
17121
+ }
17122
+ _createIframe() {
17123
+ const iframe = document.createElement("iframe");
17124
+ iframe.id = "IframeBridge";
17125
+ iframe.className = _IframeBridge.hiddenClass;
17126
+ if (this.appManager.mainView.divElement) {
17127
+ this.appManager.mainView.divElement.appendChild(iframe);
17128
+ }
17129
+ return iframe;
17130
+ }
17131
+ scaleIframeToFit(animationMode = AnimationMode.Immediately) {
17132
+ if (!this.inDisplaySceneDir) {
17133
+ return;
17134
+ }
17135
+ const { width = 1280, height = 720 } = this.attributes;
17136
+ const x2 = width ? -width / 2 : 0;
17137
+ const y2 = height ? -height / 2 : 0;
17138
+ this.manager.moveCameraToContain({
17139
+ originX: x2,
17140
+ originY: y2,
17141
+ width,
17142
+ height,
17143
+ animationMode
17144
+ });
17145
+ }
17146
+ get isReplay() {
17147
+ return this.manager.isReplay;
17148
+ }
17149
+ handleSetPage(data) {
17150
+ if (this.isReplay || !this.attributes.displaySceneDir) {
17151
+ return;
17152
+ }
17153
+ const page = data.payload;
17154
+ const room = this.displayer;
17155
+ const scenes = room.entireScenes()[this.attributes.displaySceneDir];
17156
+ if (!scenes || scenes.length !== page) {
17157
+ const genScenes = times(page, (index2) => ({ name: String(index2 + 1) }));
17158
+ room.putScenes(this.attributes.displaySceneDir, genScenes);
17159
+ this.manager.setMainViewScenePath(this.attributes.displaySceneDir);
17160
+ }
17161
+ }
17162
+ listenIframe(options) {
17163
+ const loadListener = (ev) => {
17164
+ var _a;
17165
+ this.postMessage({
17166
+ kind: "Init",
17167
+ payload: {
17168
+ attributes: this.attributes,
17169
+ roomState: (_a = _IframeBridge.displayer) == null ? void 0 : _a.state,
17170
+ currentPage: this.currentPage,
17171
+ observerId: this.displayer.observerId
17172
+ }
17173
+ });
17174
+ _IframeBridge.emitter.emit("IframeLoad", ev);
17175
+ this.sideEffectManager.addDisposer(_IframeBridge.emitter.on("Ready", () => {
17176
+ var _a2;
17177
+ this.postMessage((_a2 = this.attributes.lastEvent) == null ? void 0 : _a2.payload);
17178
+ }), RefreshIDs.Ready);
17179
+ this.computedStyleAndIframeDisplay();
17180
+ };
17181
+ if (options.url && this.iframe.src !== options.url) {
17182
+ if (!this.src_url_equal_anchor)
17183
+ this.src_url_equal_anchor = document.createElement("a");
17184
+ this.src_url_equal_anchor.href = options.url;
17185
+ if (this.src_url_equal_anchor.href !== this.iframe.src) {
17186
+ this.iframe.src = options.url;
17187
+ }
17188
+ }
17189
+ this.iframe.width = `${options.width}px`;
17190
+ this.iframe.height = `${options.height}px`;
17191
+ this.sideEffectManager.addEventListener(this.iframe, "load", loadListener, void 0, RefreshIDs.Load);
17192
+ }
17193
+ listenDisplayerState() {
17194
+ if (this.isReplay) {
17195
+ if (this.displayer._phase === PlayerPhase.Playing) {
17196
+ this.computedStyleAndIframeDisplay();
17197
+ }
17198
+ this.sideEffectManager.add(() => {
17199
+ this.displayer.callbacks.on("onPhaseChanged", this.onPhaseChangedListener);
17200
+ return () => this.displayer.callbacks.off("onPhaseChanged", this.onPhaseChangedListener);
17201
+ }, RefreshIDs.DisplayerState);
17202
+ }
17203
+ this.computedStyleAndIframeDisplay();
17204
+ }
17205
+ computedStyleAndIframeDisplay() {
17206
+ this.computedStyle(this.displayer.state);
17207
+ this.computedIframeDisplay(this.displayer.state, this.attributes);
17208
+ }
17209
+ listenDisplayerCallbacks() {
17210
+ this.displayer.callbacks.on(this.callbackName, this.stateChangeListener);
17211
+ }
17212
+ get callbackName() {
17213
+ return this.isReplay ? "onPlayerStateChanged" : "onRoomStateChanged";
17214
+ }
17215
+ computedStyle(_state) {
17216
+ const cameraState = this.manager.cameraState;
17217
+ const setWidth = this.attributes.width || 1280;
17218
+ const setHeight = this.attributes.height || 720;
17219
+ if (this.iframe) {
17220
+ const { width, height, scale: scale2, centerX, centerY } = cameraState;
17221
+ const rootRect = this.rootRect || { x: 0, y: 0 };
17222
+ const transformOriginX = `${width / 2 + rootRect.x}px`;
17223
+ const transformOriginY = `${height / 2 + rootRect.y}px`;
17224
+ const transformOrigin = `transform-origin: ${transformOriginX} ${transformOriginY};`;
17225
+ const iframeXDiff = (width - setWidth) / 2 * scale2;
17226
+ const iframeYDiff = (height - setHeight) / 2 * scale2;
17227
+ const x2 = -(centerX * scale2) + iframeXDiff;
17228
+ const y2 = -(centerY * scale2) + iframeYDiff;
17229
+ const transform = `transform: translate(${x2}px,${y2}px) scale(${scale2}, ${scale2});`;
17230
+ const position = "position: absolute;";
17231
+ const borderWidth = "border: 0.1px solid rgba(0,0,0,0);";
17232
+ const left = `left: 0px;`;
17233
+ const top = `top: 0px;`;
17234
+ const cssList = [position, borderWidth, top, left, transformOrigin, transform];
17235
+ this.cssList = cssList;
17236
+ this.computedZindex();
17237
+ this.updateStyle();
17238
+ }
17239
+ }
17240
+ computedIframeDisplay(_state, _attributes) {
17241
+ if (this.inDisplaySceneDir) {
17242
+ _IframeBridge.emitter.emit("DispayIframe");
17243
+ } else {
17244
+ _IframeBridge.emitter.emit("HideIframe");
17245
+ }
17246
+ }
17247
+ computedZindex() {
17248
+ const zIndexString = "z-index: -1;";
17249
+ const index2 = this.cssList.findIndex((css) => css === zIndexString);
17250
+ if (index2 !== -1) {
17251
+ this.cssList.splice(index2, 1);
17252
+ }
17253
+ if (!this.isClicker() || this.isDisableInput) {
17254
+ this.cssList.push(zIndexString);
17255
+ }
17256
+ }
17257
+ updateStyle() {
17258
+ this.iframe.style.cssText = this.cssList.join(" ");
17259
+ }
17260
+ get iframeOrigin() {
17261
+ if (this.iframe) {
17262
+ try {
17263
+ return new URL(this.iframe.src).origin;
17264
+ } catch (err) {
17265
+ console.warn(err);
17266
+ }
17267
+ }
17268
+ }
17269
+ messageListener(event) {
17270
+ log("<<<", JSON.stringify(event.data));
17271
+ if (event.origin !== this.iframeOrigin) {
17272
+ return;
17273
+ }
17274
+ const data = event.data;
17275
+ switch (data.kind) {
17276
+ case "SetAttributes": {
17277
+ this.handleSetAttributes(data);
17278
+ break;
17279
+ }
17280
+ case "RegisterMagixEvent": {
17281
+ this.handleRegisterMagixEvent(data);
17282
+ break;
17283
+ }
17284
+ case "RemoveMagixEvent": {
17285
+ this.handleRemoveMagixEvent(data);
17286
+ break;
17287
+ }
17288
+ case "DispatchMagixEvent": {
17289
+ this.handleDispatchMagixEvent(data);
17290
+ break;
17291
+ }
17292
+ case "RemoveAllMagixEvent": {
17293
+ this.handleRemoveAllMagixEvent();
17294
+ break;
17295
+ }
17296
+ case "NextPage": {
17297
+ this.handleNextPage();
17298
+ break;
17299
+ }
17300
+ case "PrevPage": {
17301
+ this.handlePrevPage();
17302
+ break;
17303
+ }
17304
+ case "SDKCreate": {
17305
+ this.handleSDKCreate();
17306
+ break;
17307
+ }
17308
+ case "SetPage": {
17309
+ this.handleSetPage(data);
17310
+ break;
17311
+ }
17312
+ case "GetAttributes": {
17313
+ this.handleGetAttributes();
17314
+ break;
17315
+ }
17316
+ case "PageTo": {
17317
+ this.handlePageTo(data);
17318
+ break;
17319
+ }
17320
+ default: {
17321
+ log(`${data.kind} not allow event.`);
17322
+ break;
17323
+ }
17324
+ }
17325
+ }
17326
+ handleSDKCreate() {
17327
+ this.postMessage({
17328
+ kind: "Init",
17329
+ payload: {
17330
+ attributes: this.attributes,
17331
+ roomState: this.displayer.state,
17332
+ currentPage: this.currentPage,
17333
+ observerId: this.displayer.observerId
17334
+ }
17335
+ });
17336
+ }
17337
+ handleDispatchMagixEvent(data) {
17338
+ const eventPayload = data.payload;
17339
+ this.appManager.safeDispatchMagixEvent(eventPayload.event, eventPayload.payload);
17340
+ }
17341
+ handleSetAttributes(data) {
17342
+ this.setAttributes(data.payload);
17343
+ }
17344
+ handleRegisterMagixEvent(data) {
17345
+ const eventName = data.payload;
17346
+ const listener = (event) => {
17347
+ if (event.authorId === this.displayer.observerId) {
17348
+ return;
17349
+ }
17350
+ this.postMessage({ kind: "ReciveMagixEvent", payload: event });
17351
+ };
17352
+ this.magixEventMap.set(eventName, listener);
17353
+ this.displayer.addMagixEventListener(eventName, listener);
17354
+ }
17355
+ handleRemoveMagixEvent(data) {
17356
+ const eventName = data.payload;
17357
+ const listener = this.magixEventMap.get(eventName);
17358
+ this.displayer.removeMagixEventListener(eventName, listener);
17359
+ }
17360
+ handleNextPage() {
17361
+ if (this.manager.canOperate) {
17362
+ this.manager.nextPage();
17363
+ this.dispatchMagixEvent("NextPage", {});
17364
+ }
17365
+ }
17366
+ handlePrevPage() {
17367
+ if (this.manager.canOperate) {
17368
+ this.manager.prevPage();
17369
+ this.dispatchMagixEvent("PrevPage", {});
17370
+ }
17371
+ }
17372
+ handlePageTo(data) {
17373
+ if (this.manager.canOperate) {
17374
+ const page = data.payload;
17375
+ if (!Number.isSafeInteger(page) || page <= 0) {
17376
+ return;
17377
+ }
17378
+ this.manager.setMainViewSceneIndex(page - 1);
17379
+ this.dispatchMagixEvent("PageTo", page - 1);
17380
+ }
17381
+ }
17382
+ handleRemoveAllMagixEvent() {
17383
+ this.magixEventMap.forEach((listener, event) => {
17384
+ this.displayer.removeMagixEventListener(event, listener);
17385
+ });
17386
+ this.magixEventMap.clear();
17387
+ }
17388
+ handleGetAttributes() {
17389
+ this.postMessage({
17390
+ kind: "GetAttributes",
17391
+ payload: this.attributes
17392
+ });
17393
+ }
17394
+ postMessage(message) {
17395
+ var _a;
17396
+ if (this.iframe) {
17397
+ (_a = this.iframe.contentWindow) == null ? void 0 : _a.postMessage(JSON.parse(JSON.stringify(message)), "*");
17398
+ }
17399
+ }
17400
+ dispatchMagixEvent(event, payload) {
17401
+ if (this.manager.canOperate) {
17402
+ this.setAttributes({ lastEvent: { name: event, payload } });
17403
+ this.displayer.dispatchMagixEvent(event, payload);
17404
+ }
17405
+ }
17406
+ get currentIndex() {
17407
+ return this.manager.mainViewSceneIndex;
17408
+ }
17409
+ get currentPage() {
17410
+ return this.currentIndex + 1;
17411
+ }
17412
+ get totalPage() {
17413
+ return this.manager.mainViewScenesLength;
17414
+ }
17415
+ get readonly() {
17416
+ return !this.displayer.isWritable;
17417
+ }
17418
+ get inDisplaySceneDir() {
17419
+ return this.manager.mainViewSceneDir === this.attributes.displaySceneDir;
17420
+ }
17421
+ isClicker() {
17422
+ if (this.readonly) {
17423
+ return false;
17424
+ }
17425
+ const currentApplianceName = this.displayer.state.memberState.currentApplianceName;
17426
+ return this.allowAppliances.includes(currentApplianceName);
17427
+ }
17428
+ get isDisableInput() {
17429
+ if ("disableDeviceInputs" in this.displayer) {
17430
+ return this.displayer.disableDeviceInputs;
17431
+ } else {
17432
+ return true;
17433
+ }
17434
+ }
17435
+ };
17436
+ let IframeBridge = _IframeBridge;
17437
+ IframeBridge.kind = "IframeBridge";
17438
+ IframeBridge.hiddenClass = "netless-iframe-brdige-hidden";
17439
+ IframeBridge.emitter = new Emittery();
17440
+ IframeBridge.displayer = null;
17441
+ IframeBridge.alreadyCreate = false;
16908
17442
  const reconnectRefresher = new ReconnectRefresher({ emitter });
16909
17443
  const _WindowManager = class extends InvisiblePlugin {
16910
17444
  constructor(context) {
16911
17445
  super(context);
16912
- this.version = "0.4.60";
16913
- this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.2.27", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^0.1.5", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.15", "@netless/app-media-player": "0.1.0-beta.5", "@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/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", "jspdf": "^2.5.1", "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", "vitest": "^0.14.1", "white-web-sdk": "2.16.42" } };
17446
+ this.version = "0.4.61";
17447
+ this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.2.27", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^0.1.5", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.15", "@netless/app-media-player": "0.1.0-beta.5", "@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/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", "jspdf": "^2.5.1", "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", "vitest": "^0.14.1", "white-web-sdk": "2.16.43" } };
16914
17448
  this.emitter = callbacks$1;
16915
17449
  this.viewMode = ViewMode.Broadcaster;
16916
17450
  this.isReplay = isPlayer(this.displayer);
16917
17451
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
16918
17452
  _WindowManager.displayer = context.displayer;
16919
- window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.2.27", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^0.1.5", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.15", "@netless/app-media-player": "0.1.0-beta.5", "@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/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", "jspdf": "^2.5.1", "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", "vitest": "^0.14.1", "white-web-sdk": "2.16.42" } };
17453
+ window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.2.27", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^0.1.5", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.15", "@netless/app-media-player": "0.1.0-beta.5", "@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/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", "jspdf": "^2.5.1", "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", "vitest": "^0.14.1", "white-web-sdk": "2.16.43" } };
16920
17454
  }
16921
17455
  static async mount(params) {
16922
17456
  const room = params.room;
@@ -17438,7 +17972,7 @@ const _WindowManager = class extends InvisiblePlugin {
17438
17972
  this._destroy();
17439
17973
  }
17440
17974
  _destroy() {
17441
- var _a, _b, _c, _d;
17975
+ var _a, _b, _c, _d, _e;
17442
17976
  (_a = this.containerResizeObserver) == null ? void 0 : _a.disconnect();
17443
17977
  (_b = this.appManager) == null ? void 0 : _b.destroy();
17444
17978
  (_c = this.cursorManager) == null ? void 0 : _c.destroy();
@@ -17449,6 +17983,8 @@ const _WindowManager = class extends InvisiblePlugin {
17449
17983
  (_d = _WindowManager.playground.parentNode) == null ? void 0 : _d.removeChild(_WindowManager.playground);
17450
17984
  }
17451
17985
  _WindowManager.params = void 0;
17986
+ (_e = this._iframeBridge) == null ? void 0 : _e.destroy();
17987
+ this._iframeBridge = void 0;
17452
17988
  log("Destroyed");
17453
17989
  }
17454
17990
  bindMainView(divElement, disableCameraTransform) {
@@ -17545,8 +18081,8 @@ const _WindowManager = class extends InvisiblePlugin {
17545
18081
  (_c = (_b = this.appManager) == null ? void 0 : _b.refresher) == null ? void 0 : _c.refresh();
17546
18082
  }
17547
18083
  setContainerSizeRatio(ratio) {
17548
- if (!isNumber(ratio)) {
17549
- throw new Error(`[WindowManager]: updateContainerSizeRatio error, ratio must be a number. but got ${ratio}`);
18084
+ if (!isNumber(ratio) || !(ratio > 0)) {
18085
+ throw new Error(`[WindowManager]: updateContainerSizeRatio error, ratio must be a positive number. but got ${ratio}`);
17550
18086
  }
17551
18087
  _WindowManager.containerSizeRatio = ratio;
17552
18088
  this.containerSizeRatio = ratio;
@@ -17577,7 +18113,17 @@ const _WindowManager = class extends InvisiblePlugin {
17577
18113
  if (!this.attributes[Fields.Registered]) {
17578
18114
  this.safeSetAttributes({ [Fields.Registered]: {} });
17579
18115
  }
18116
+ if (!this.attributes[Fields.IframeBridge]) {
18117
+ this.safeSetAttributes({ [Fields.IframeBridge]: {} });
18118
+ }
18119
+ }
18120
+ }
18121
+ getIframeBridge() {
18122
+ if (!this.appManager) {
18123
+ throw new Error("[WindowManager]: should call getIframeBridge() after await mount()");
17580
18124
  }
18125
+ this._iframeBridge || (this._iframeBridge = new IframeBridge(this, this.appManager));
18126
+ return this._iframeBridge;
17581
18127
  }
17582
18128
  };
17583
18129
  let WindowManager = _WindowManager;
@@ -17586,5 +18132,5 @@ WindowManager.debug = false;
17586
18132
  WindowManager.containerSizeRatio = DEFAULT_CONTAINER_RATIO;
17587
18133
  WindowManager.isCreated = false;
17588
18134
  setupBuiltin();
17589
- export { AppCreateError, AppManagerNotInitError, AppNotRegisterError, BindContainerRoomPhaseInvalidError, BoxManagerNotFoundError, BoxNotCreatedError, BuiltinApps, InvalidScenePath, ParamsInvalidError, WhiteWebSDKInvalidError, WindowManager, calculateNextIndex, reconnectRefresher };
18135
+ export { AppCreateError, AppManagerNotInitError, AppNotRegisterError, BindContainerRoomPhaseInvalidError, BoxManagerNotFoundError, BoxNotCreatedError, BuiltinApps, DomEvents, IframeBridge, IframeEvents, InvalidScenePath, ParamsInvalidError, WhiteWebSDKInvalidError, WindowManager, calculateNextIndex, reconnectRefresher };
17590
18136
  //# sourceMappingURL=index.mjs.map