vim-web 0.3.40 → 0.3.42

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/vim-web.js CHANGED
@@ -50152,10 +50152,10 @@ const defaultViewerSettings = {
50152
50152
  background: { color: new Color(12698310) },
50153
50153
  skybox: {
50154
50154
  enable: true,
50155
- skyColor: new Color(15135994),
50156
- // Light sky blue pastel
50157
- groundColor: new Color(14671841),
50158
- // Light earthy brown pastel
50155
+ skyColor: new Color(16777215),
50156
+ // white
50157
+ groundColor: new Color(16185078),
50158
+ // less white
50159
50159
  sharpness: 2
50160
50160
  },
50161
50161
  groundPlane: {
@@ -55220,6 +55220,15 @@ class BoxInputs {
55220
55220
  this.reg(canvas, "pointerdown", this.onMouseDown.bind(this));
55221
55221
  this.reg(canvas, "pointermove", this.onMouseMove.bind(this));
55222
55222
  this.reg(canvas, "pointerup", this.onMouseUp.bind(this));
55223
+ this.reg(canvas, "pointerleave", this.onPointerLeave.bind(this));
55224
+ }
55225
+ onPointerLeave(event) {
55226
+ var _a2;
55227
+ if (this.capturedId !== void 0) {
55228
+ return;
55229
+ }
55230
+ this.faceNormal.set(0, 0, 0);
55231
+ (_a2 = this.onFaceEnter) == null ? void 0 : _a2.call(this, this.faceNormal);
55223
55232
  }
55224
55233
  capturePointer(pointerId) {
55225
55234
  this.releasePointer();
@@ -58111,6 +58120,9 @@ class RpcClient {
58111
58120
  get url() {
58112
58121
  return this._messenger.url;
58113
58122
  }
58123
+ get connected() {
58124
+ return this._messenger.state.status === "connected";
58125
+ }
58114
58126
  RPCAddNodeFlags(componentHandle, nodes, flags) {
58115
58127
  const marshal = new Marshal();
58116
58128
  marshal.writeString("RPCAddNodeFlags");
@@ -58807,6 +58819,9 @@ class RpcSafeClient {
58807
58819
  get url() {
58808
58820
  return this.rpc.url;
58809
58821
  }
58822
+ get connected() {
58823
+ return this.rpc.connected;
58824
+ }
58810
58825
  /*******************************************************************************
58811
58826
  * SCENE MANAGEMENT METHODS
58812
58827
  * Methods for managing the overall scene, including initialization, lighting,
@@ -59143,15 +59158,15 @@ class RpcSafeClient {
59143
59158
  ******************************************************************************/
59144
59159
  /**
59145
59160
  * Loads a VIM file from the local filesystem.
59146
- * @param fileName - The path to the VIM file (supports file:// protocol)
59161
+ * @param source - The path to the VIM file (supports file:// protocol)
59147
59162
  * @returns Promise resolving to the handle of the loaded VIM component
59148
59163
  * @throws {Error} If the filename is invalid or empty
59149
59164
  */
59150
- async RPCLoadVim(fileName) {
59151
- if (!Validation.isNonEmptyString(fileName)) return INVALID_HANDLE;
59152
- fileName = fileName.replace("file:///", "file://");
59165
+ async RPCLoadVim(source) {
59166
+ if (!Validation.isNonEmptyString(source.url)) return INVALID_HANDLE;
59167
+ const url = source.url.replace("file:///", "file://");
59153
59168
  return await this.safeCall(
59154
- () => this.rpc.RPCLoadVim(fileName),
59169
+ () => this.rpc.RPCLoadVim(url),
59155
59170
  INVALID_HANDLE
59156
59171
  );
59157
59172
  }
@@ -59161,10 +59176,10 @@ class RpcSafeClient {
59161
59176
  * @returns Promise resolving to the handle of the loaded VIM component
59162
59177
  * @throws {Error} If the URL is invalid
59163
59178
  */
59164
- async RPCLoadVimURL(url) {
59165
- if (!Validation.isURL(url)) return INVALID_HANDLE;
59179
+ async RPCLoadVimURL(source) {
59180
+ if (!Validation.isURL(source.url)) return INVALID_HANDLE;
59166
59181
  return await this.safeCall(
59167
- () => this.rpc.RPCLoadVimURL(url, ""),
59182
+ () => this.rpc.RPCLoadVimURL(source.url, source.authToken ?? ""),
59168
59183
  INVALID_HANDLE
59169
59184
  );
59170
59185
  }
@@ -59548,9 +59563,9 @@ class Inputs extends InputHandler2 {
59548
59563
  this._inputsMouse = new InputMouse(this._canvas, this._rpc, selection, camera2);
59549
59564
  this._inputsTouch = new InputTouch(this._canvas, this._rpc);
59550
59565
  this._keyboard = new InputKeyboard(this._rpc, selection, camera2, this);
59551
- this.register();
59552
59566
  }
59553
59567
  onConnect() {
59568
+ this.register();
59554
59569
  this._rpc.RPCSetMoveSpeed(this._moveSpeed);
59555
59570
  }
59556
59571
  register() {
@@ -59796,7 +59811,7 @@ class SocketClient {
59796
59811
  * Disconnects from the current WebSocket server.
59797
59812
  */
59798
59813
  disconnect(error) {
59799
- this._logger.log("Disconnecting from " + this._connectingUrl);
59814
+ this._logger.log("Disconnecting from: ", this._connectingUrl);
59800
59815
  this._connectingUrl = void 0;
59801
59816
  this._disconnect(error);
59802
59817
  }
@@ -59882,7 +59897,7 @@ class SocketClient {
59882
59897
  this._disconnect(issues);
59883
59898
  return;
59884
59899
  }
59885
- this._logger.log("Connected to " + ((_a2 = this._socket) == null ? void 0 : _a2.url));
59900
+ this._logger.log("Connected to: ", (_a2 = this._socket) == null ? void 0 : _a2.url);
59886
59901
  this.updateState({ status: "connected" });
59887
59902
  this._streamLogger.startLoggging();
59888
59903
  this._connectPromise.resolve();
@@ -60195,7 +60210,10 @@ class Decoder {
60195
60210
  this._logger.error("Error decoding video chunk: ", e);
60196
60211
  }
60197
60212
  }
60198
- this._firstDecoded = true;
60213
+ if (!this._firstDecoded) {
60214
+ this._firstDecoded = true;
60215
+ this._logger.log("First frame decoded");
60216
+ }
60199
60217
  }
60200
60218
  /**
60201
60219
  * Clears the decoder state and renderer buffer.
@@ -60405,16 +60423,16 @@ class Vim2 {
60405
60423
  if (this._request) {
60406
60424
  return this._request;
60407
60425
  }
60408
- this._logger.log("Loading " + this.source);
60426
+ this._logger.log("Loading: ", this.source);
60409
60427
  this._request = new LoadRequest$1();
60410
60428
  this._load(this.source, this._request).then(async (request2) => {
60411
60429
  const result = await request2.getResult();
60412
60430
  if (result.isSuccess) {
60413
- this._logger.log(`Successfully loaded vim: ${this.source}`);
60431
+ this._logger.log("Successfully loaded vim: ", this.source);
60414
60432
  this.reapplyNodes();
60415
60433
  this.reapplyColors();
60416
60434
  } else {
60417
- this._logger.log(`Failed to load vim: ${this.source}`);
60435
+ this._logger.log("Failed to load vim: ", this.source);
60418
60436
  }
60419
60437
  });
60420
60438
  return this._request;
@@ -60447,18 +60465,19 @@ class Vim2 {
60447
60465
  }
60448
60466
  /**
60449
60467
  * Requests for the server to load the given URL or file path.
60450
- * @param url - The URL or file path to load.
60468
+ * @param source - The URL or file path to load.
60451
60469
  * @param result - The load request object to update.
60452
60470
  * @returns The updated load request.
60453
60471
  */
60454
- async _load(url, result) {
60455
- const handle = await this._getHandle(url, result);
60472
+ async _load(source, result) {
60473
+ const handle = await this._getHandle(source, result);
60456
60474
  if (result.isCompleted || handle === INVALID_HANDLE) {
60457
60475
  return result;
60458
60476
  }
60459
60477
  while (true) {
60460
60478
  try {
60461
60479
  const state = await this._rpc.RPCGetVimLoadingState(handle);
60480
+ this._logger.log("state :", state);
60462
60481
  result.onProgress(state.progress);
60463
60482
  switch (state.status) {
60464
60483
  // Keep waiting for the loading to complete
@@ -60495,16 +60514,16 @@ class Vim2 {
60495
60514
  return "unknown";
60496
60515
  }
60497
60516
  }
60498
- async _getHandle(url, result) {
60517
+ async _getHandle(source, result) {
60499
60518
  let handle = void 0;
60500
60519
  try {
60501
- if (isURL(url)) {
60502
- handle = await this._rpc.RPCLoadVimURL(url);
60503
- } else if (isFileURI(url)) {
60504
- handle = await this._rpc.RPCLoadVim(url);
60520
+ if (isURL(source.url)) {
60521
+ handle = await this._rpc.RPCLoadVimURL(source);
60522
+ } else if (isFileURI(source.url)) {
60523
+ handle = await this._rpc.RPCLoadVim(source);
60505
60524
  } else {
60506
60525
  console.log("Defaulting to file path");
60507
- handle = await this._rpc.RPCLoadVim(url);
60526
+ handle = await this._rpc.RPCLoadVim(source);
60508
60527
  }
60509
60528
  } catch (e) {
60510
60529
  result.error("downloadingError", e.message);
@@ -60514,6 +60533,7 @@ class Vim2 {
60514
60533
  result.error("downloadingError");
60515
60534
  return INVALID_HANDLE;
60516
60535
  }
60536
+ console.log("handle :", handle);
60517
60537
  return handle;
60518
60538
  }
60519
60539
  /**
@@ -60719,13 +60739,27 @@ function wait(ms) {
60719
60739
  return new Promise((resolve) => setTimeout(resolve, ms));
60720
60740
  }
60721
60741
  const defaultLogger = {
60722
- log: (message) => {
60723
- console.log("VIM Ultra: " + message);
60742
+ log: (message, obj) => {
60743
+ const caller = getCaller();
60744
+ const msg = `VIM Ultra : ${message}`;
60745
+ if (obj) {
60746
+ console.log(msg, obj, { caller });
60747
+ } else {
60748
+ console.log(msg, { caller });
60749
+ }
60724
60750
  },
60725
60751
  error: (message, e) => {
60726
- console.error("VIM Ultra: " + message, e);
60752
+ console.error("VIM Ultra " + message, e);
60727
60753
  }
60728
60754
  };
60755
+ function getCaller() {
60756
+ const stack = new Error().stack;
60757
+ if (!stack) return "";
60758
+ const files = stack.split("/");
60759
+ const file = files[files.length - 1];
60760
+ const clean = file.replace(/\?[^:]+/, "");
60761
+ return clean;
60762
+ }
60729
60763
  function debounce(func, delay) {
60730
60764
  let timeoutId;
60731
60765
  return [function(...args) {
@@ -60743,14 +60777,16 @@ class Viewport2 {
60743
60777
  * @param canvas - The HTML canvas element to observe and manage
60744
60778
  * @param rpc - RPC client for viewport communication
60745
60779
  */
60746
- constructor(canvas, rpc) {
60780
+ constructor(canvas, rpc, logger) {
60747
60781
  /** The HTML canvas element used for rendering */
60748
60782
  __publicField(this, "canvas");
60749
60783
  __publicField(this, "_rpc");
60784
+ __publicField(this, "_logger");
60750
60785
  __publicField(this, "_observer");
60751
60786
  __publicField(this, "_clearTimeout");
60752
60787
  this.canvas = canvas;
60753
60788
  this._rpc = rpc;
60789
+ this._logger = logger;
60754
60790
  const [debounced, clear] = debounce(() => this.onResize(), 250);
60755
60791
  this._observer = new ResizeObserver(debounced);
60756
60792
  this._observer.observe(canvas);
@@ -60761,14 +60797,16 @@ class Viewport2 {
60761
60797
  * @private
60762
60798
  */
60763
60799
  onResize() {
60764
- console.log("Canvas resized to", this.canvas.offsetWidth, "x", this.canvas.offsetHeight);
60800
+ this._logger.log("Canvas resized to :", { x: this.canvas.offsetWidth, y: this.canvas.offsetHeight });
60765
60801
  this.update();
60766
60802
  }
60767
60803
  /**
60768
60804
  * Updates the aspect ratio of the viewport on the server
60769
60805
  */
60770
60806
  update() {
60771
- this._rpc.RPCSetAspectRatio(this.canvas.offsetWidth, this.canvas.offsetHeight);
60807
+ if (this._rpc.connected) {
60808
+ this._rpc.RPCSetAspectRatio(this.canvas.offsetWidth, this.canvas.offsetHeight);
60809
+ }
60772
60810
  }
60773
60811
  /**
60774
60812
  * Cleans up resources by removing resize observer and clearing timeouts
@@ -61314,14 +61352,16 @@ class Renderer2 {
61314
61352
  * @param rpc - RPC client for communication with the rendering backend
61315
61353
  * @param settings - Optional partial render settings to override defaults
61316
61354
  */
61317
- constructor(rpc, settings2 = {}) {
61355
+ constructor(rpc, logger, settings2 = {}) {
61318
61356
  __publicField(this, "_rpc");
61357
+ __publicField(this, "_logger");
61319
61358
  __publicField(this, "_settings");
61320
61359
  __publicField(this, "_animationFrame");
61321
61360
  __publicField(this, "_updateLighting", false);
61322
61361
  __publicField(this, "_updateGhostColor", false);
61323
61362
  __publicField(this, "_updateIblRotation", false);
61324
61363
  this._rpc = rpc;
61364
+ this._logger = logger;
61325
61365
  this._settings = { ...defaultRenderSettings, ...settings2 };
61326
61366
  }
61327
61367
  /**
@@ -61330,8 +61370,12 @@ class Renderer2 {
61330
61370
  */
61331
61371
  async validateConnection() {
61332
61372
  const success = await this._rpc.RPCStartScene(this._settings);
61333
- if (success) return void 0;
61373
+ if (success) {
61374
+ this._logger.log("Scene stream started successfully");
61375
+ return void 0;
61376
+ }
61334
61377
  const error = await this._rpc.RPCGetLastError();
61378
+ this._logger.error("Failed to start scene stream", error);
61335
61379
  return {
61336
61380
  status: "error",
61337
61381
  error: "stream",
@@ -61556,10 +61600,10 @@ class Viewer2 {
61556
61600
  this.rpc = new RpcSafeClient(new RpcClient(this._socketClient));
61557
61601
  this._canvas = canvas;
61558
61602
  this._vims = new VimCollection();
61559
- this._viewport = new Viewport2(canvas, this.rpc);
61603
+ this._viewport = new Viewport2(canvas, this.rpc, this._logger);
61560
61604
  this._decoder = new Decoder(canvas, this._logger);
61561
61605
  this._selection = new ViewerSelection(this.rpc, this._vims);
61562
- this._renderer = new Renderer2(this.rpc);
61606
+ this._renderer = new Renderer2(this.rpc, this._logger);
61563
61607
  this.colors = new ColorManager(this.rpc);
61564
61608
  this._camera = new Camera3(this.rpc);
61565
61609
  this._input = new Inputs(canvas, this.rpc, this._selection, this._camera, this._renderer);
@@ -61668,6 +61712,7 @@ class Viewer2 {
61668
61712
  const remoteVersion = parseVersion(version2);
61669
61713
  const localParsedVersion = parseVersion(localVersion);
61670
61714
  if (localParsedVersion.major !== remoteVersion.major) {
61715
+ this._logger.error("Major version mismatch", { local: localParsedVersion, remote: remoteVersion });
61671
61716
  return {
61672
61717
  status: "error",
61673
61718
  error: "compatibility",
@@ -61676,6 +61721,7 @@ class Viewer2 {
61676
61721
  serverVersion: version2
61677
61722
  };
61678
61723
  }
61724
+ this._logger.log("API version check passed", { local: localParsedVersion, remote: remoteVersion });
61679
61725
  return void 0;
61680
61726
  }
61681
61727
  /**
@@ -61705,16 +61751,16 @@ class Viewer2 {
61705
61751
  }
61706
61752
  /**
61707
61753
  * Requests the server to load the given URL or file path.
61708
- * @param path - The path or URL to the VIM file.
61754
+ * @param source - The path or URL to the VIM file.
61709
61755
  * @returns A load request object that can be used to wait for the load to complete.
61710
61756
  */
61711
- loadVim(path) {
61712
- if (typeof path !== "string" || path.trim() === "") {
61757
+ loadVim(source) {
61758
+ if (typeof source.url !== "string" || source.url.trim() === "") {
61713
61759
  const request22 = new LoadRequest$1();
61714
61760
  request22.error("loadingError", "Invalid path");
61715
61761
  return request22;
61716
61762
  }
61717
- const vim = new Vim2(this.rpc, this.colors, path, this._logger);
61763
+ const vim = new Vim2(this.rpc, this.colors, source, this._logger);
61718
61764
  this._vims.add(vim);
61719
61765
  const request2 = vim.connect();
61720
61766
  request2.getResult().then((result) => {
@@ -74199,6 +74245,8 @@ function Overlay(props) {
74199
74245
  relay("pointerdown", (s, e) => new PointerEvent(s, e), false);
74200
74246
  relay("pointermove", (s, e) => new PointerEvent(s, e), false);
74201
74247
  relay("pointerup", (s, e) => new PointerEvent(s, e), false);
74248
+ relay("pointerenter", (s, e) => new PointerEvent(s, e));
74249
+ relay("pointerleave", (s, e) => new PointerEvent(s, e));
74202
74250
  relay("touchstart", (s, e) => new TouchEvent(s, e), false);
74203
74251
  relay("touchend", (s, e) => new TouchEvent(s, e), false);
74204
74252
  relay("touchmove", (s, e) => new TouchEvent(s, e), false);
@@ -75642,18 +75690,18 @@ function isFilePathOrUri(input) {
75642
75690
  }
75643
75691
  return true;
75644
75692
  }
75645
- function serverFileDownloadingError(url, server) {
75693
+ function serverFileDownloadingError(url, authToken, server) {
75646
75694
  if (isFilePathOrUri(url)) {
75647
75695
  return fileOpeningError(url);
75648
75696
  }
75649
75697
  return {
75650
75698
  title: "File Downloading Error",
75651
- body: body$4(server, url),
75699
+ body: body$4(server, authToken, server),
75652
75700
  footer: footer(support),
75653
75701
  canClose: false
75654
75702
  };
75655
75703
  }
75656
- function body$4(server, url) {
75704
+ function body$4(url, server, authToken) {
75657
75705
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: vcRoboto, children: [
75658
75706
  mainText(/* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
75659
75707
  "Oops, it appears that there’s an ",
@@ -75663,7 +75711,8 @@ function body$4(server, url) {
75663
75711
  subTitle("Error details:"),
75664
75712
  dotList([
75665
75713
  server ? bullet("VIM ULTRA Server:", server) : null,
75666
- bullet("File URL:", url)
75714
+ bullet("File URL:", url),
75715
+ authToken ? bullet("Auth Token:", authToken) : null
75667
75716
  ]),
75668
75717
  subTitle("Troubleshooting tips:"),
75669
75718
  numList([
@@ -75799,17 +75848,17 @@ function getErrorMessage(state) {
75799
75848
  return serverStreamError(state.serverUrl);
75800
75849
  }
75801
75850
  }
75802
- function getRequestErrorMessage(url, error) {
75851
+ function getRequestErrorMessage(source, error) {
75803
75852
  console.log(error);
75804
75853
  switch (error) {
75805
75854
  case "loadingError":
75806
- return serverFileLoadingError(url);
75855
+ return serverFileLoadingError(source.url);
75807
75856
  case "downloadingError":
75808
75857
  case "unknown":
75809
75858
  case "cancelled":
75810
- return serverFileDownloadingError(url);
75859
+ return serverFileDownloadingError(source.url);
75811
75860
  case "serverDisconnected":
75812
- return serverConnectionError(url);
75861
+ return serverConnectionError(source.url);
75813
75862
  }
75814
75863
  }
75815
75864
  function createUltraComponent(container) {
@@ -75864,13 +75913,13 @@ function updateModal(modal, state) {
75864
75913
  }
75865
75914
  }
75866
75915
  function ToRef(viewer, modal) {
75867
- function load(url) {
75868
- const request2 = viewer.loadVim(url);
75916
+ function load(source) {
75917
+ const request2 = viewer.loadVim(source);
75869
75918
  void updateProgress(request2, modal);
75870
75919
  void request2.getResult().then(
75871
75920
  (result) => {
75872
75921
  if (result.isError) {
75873
- modal.message(getRequestErrorMessage(url, result.error));
75922
+ modal.message(getRequestErrorMessage(source, result.error));
75874
75923
  return;
75875
75924
  }
75876
75925
  if (result.isSuccess) {