vim-web 0.3.44-dev.60 → 0.3.44-dev.62

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
@@ -50671,6 +50671,48 @@ function debounce(func, delay) {
50671
50671
  }, delay);
50672
50672
  }, () => clearTimeout(timeoutId)];
50673
50673
  }
50674
+ class DebouncedSignal {
50675
+ constructor() {
50676
+ __publicField(this, "_dispatcher", new distExports$1.SignalDispatcher());
50677
+ __publicField(this, "_frameRequestId");
50678
+ }
50679
+ /**
50680
+ * Indicates whether a dispatch is currently scheduled.
50681
+ *
50682
+ * @returns `true` if a dispatch is scheduled; otherwise `false`.
50683
+ */
50684
+ get isScheduled() {
50685
+ return this._frameRequestId !== void 0;
50686
+ }
50687
+ /**
50688
+ * Returns the signal interface that subscribers can listen to.
50689
+ *
50690
+ * @returns An `ISignal` that is dispatched once per frame when requested.
50691
+ */
50692
+ get signal() {
50693
+ return this._dispatcher.asEvent();
50694
+ }
50695
+ /**
50696
+ * Schedules the signal to be dispatched on the next animation frame.
50697
+ * Has no effect if a dispatch is already scheduled.
50698
+ */
50699
+ requestDispatch() {
50700
+ if (this._frameRequestId !== void 0) return;
50701
+ this._frameRequestId = requestAnimationFrame(() => {
50702
+ this._dispatcher.dispatch();
50703
+ this._frameRequestId = void 0;
50704
+ });
50705
+ }
50706
+ /**
50707
+ * Cancels a scheduled signal dispatch if one exists.
50708
+ */
50709
+ cancel() {
50710
+ if (this._frameRequestId !== void 0) {
50711
+ cancelAnimationFrame(this._frameRequestId);
50712
+ this._frameRequestId = void 0;
50713
+ }
50714
+ }
50715
+ }
50674
50716
  function almostEqual(v1, v2, epsilon = 1e-6) {
50675
50717
  return Math.abs(v1.x - v2.x) < epsilon && Math.abs(v1.y - v2.y) < epsilon;
50676
50718
  }
@@ -55178,36 +55220,67 @@ class RenderScene {
55178
55220
  }
55179
55221
  }
55180
55222
  class Selection {
55223
+ /**
55224
+ * Creates a new Selection manager.
55225
+ * @param adapter - Adapter responsible for visual selection feedback.
55226
+ */
55181
55227
  constructor(adapter) {
55182
- __publicField(this, "_onSelectionChanged", new distExports$1.SignalDispatcher());
55228
+ __publicField(this, "_onSelectionChanged", new DebouncedSignal());
55183
55229
  __publicField(this, "_selection", /* @__PURE__ */ new Set());
55184
55230
  __publicField(this, "_adapter");
55231
+ /**
55232
+ * If true, reselecting the currently selected single object will toggle it instead of doing nothing.
55233
+ */
55234
+ __publicField(this, "toggleOnRepeatSelect", false);
55185
55235
  this._adapter = adapter;
55186
55236
  }
55237
+ /**
55238
+ * Checks whether a specific object is currently selected.
55239
+ * @param object - The object to check.
55240
+ * @returns `true` if the object is selected; otherwise, `false`.
55241
+ */
55187
55242
  has(object) {
55188
55243
  return this._selection.has(object);
55189
55244
  }
55245
+ /**
55246
+ * Returns the number of selected objects.
55247
+ * @returns The count of selected items.
55248
+ */
55190
55249
  count() {
55191
55250
  return this._selection.size;
55192
55251
  }
55252
+ /**
55253
+ * Checks if there is at least one selected object.
55254
+ * @returns `true` if the selection is not empty.
55255
+ */
55193
55256
  any() {
55194
55257
  return this._selection.size > 0;
55195
55258
  }
55259
+ /**
55260
+ * Signal that fires when the selection changes.
55261
+ */
55196
55262
  get onSelectionChanged() {
55197
- return this._onSelectionChanged.asEvent();
55263
+ return this._onSelectionChanged.signal;
55198
55264
  }
55199
- _dispatchIfChanged(prevSize, modified) {
55200
- if (modified || this._selection.size !== prevSize) {
55201
- this._onSelectionChanged.dispatch();
55202
- }
55265
+ /**
55266
+ * Normalizes a value to an array of objects.
55267
+ * @param oneOrMore - A single object or an array of objects.
55268
+ * @returns An array of objects.
55269
+ */
55270
+ toArray(oneOrMore) {
55271
+ return Array.isArray(oneOrMore) ? oneOrMore : [oneOrMore];
55203
55272
  }
55204
55273
  select(objectOrObjects) {
55205
55274
  if (!objectOrObjects) {
55206
55275
  this.clear();
55207
55276
  return;
55208
55277
  }
55209
- const objects = Array.isArray(objectOrObjects) ? objectOrObjects : [objectOrObjects];
55210
- if (objects.length === 1 && this._selection.size === 1 && this._selection.has(objects[0])) {
55278
+ const objects = this.toArray(objectOrObjects);
55279
+ const isRepeatSingleSelection = objects.length === 1 && this._selection.size === 1 && this._selection.has(objects[0]);
55280
+ if (isRepeatSingleSelection) {
55281
+ if (this.toggleOnRepeatSelect) {
55282
+ this.toggle(objects);
55283
+ }
55211
55284
  return;
55212
55285
  }
55213
55286
  for (const obj of this._selection) {
@@ -55218,77 +55291,101 @@ class Selection {
55218
55291
  this._selection.add(obj);
55219
55292
  this._adapter.outline(obj, true);
55220
55293
  }
55221
- this._onSelectionChanged.dispatch();
55294
+ this._onSelectionChanged.requestDispatch();
55222
55295
  }
55223
55296
  toggle(objectOrObjects) {
55224
- const objects = Array.isArray(objectOrObjects) ? objectOrObjects : [objectOrObjects];
55225
- const prevSize = this._selection.size;
55226
- let modified = false;
55297
+ const objects = this.toArray(objectOrObjects);
55298
+ let changed = false;
55227
55299
  for (const obj of objects) {
55228
55300
  if (this._selection.has(obj)) {
55229
55301
  this._selection.delete(obj);
55230
55302
  this._adapter.outline(obj, false);
55231
- modified = true;
55303
+ changed = true;
55232
55304
  } else {
55233
55305
  this._selection.add(obj);
55234
55306
  this._adapter.outline(obj, true);
55235
- modified = true;
55307
+ changed = true;
55236
55308
  }
55237
55309
  }
55238
- this._dispatchIfChanged(prevSize, modified);
55310
+ if (changed) {
55311
+ this._onSelectionChanged.requestDispatch();
55312
+ }
55239
55313
  }
55240
55314
  add(objectOrObjects) {
55241
- const objects = Array.isArray(objectOrObjects) ? objectOrObjects : [objectOrObjects];
55242
- const prevSize = this._selection.size;
55243
- let anyNew = false;
55315
+ const objects = this.toArray(objectOrObjects);
55316
+ let changed = false;
55244
55317
  for (const obj of objects) {
55245
55318
  if (!this._selection.has(obj)) {
55246
55319
  this._selection.add(obj);
55247
55320
  this._adapter.outline(obj, true);
55248
- anyNew = true;
55321
+ changed = true;
55249
55322
  }
55250
55323
  }
55251
- this._dispatchIfChanged(prevSize, anyNew);
55324
+ if (changed) {
55325
+ this._onSelectionChanged.requestDispatch();
55326
+ }
55252
55327
  }
55253
55328
  remove(objectOrObjects) {
55254
- const objects = Array.isArray(objectOrObjects) ? objectOrObjects : [objectOrObjects];
55255
- const prevSize = this._selection.size;
55256
- let removedAny = false;
55329
+ const objects = this.toArray(objectOrObjects);
55330
+ let changed = false;
55257
55331
  for (const obj of objects) {
55258
55332
  if (this._selection.delete(obj)) {
55259
55333
  this._adapter.outline(obj, false);
55260
- removedAny = true;
55334
+ changed = true;
55261
55335
  }
55262
55336
  }
55263
- this._dispatchIfChanged(prevSize, removedAny);
55337
+ if (changed) {
55338
+ this._onSelectionChanged.requestDispatch();
55339
+ }
55264
55340
  }
55341
+ /**
55342
+ * Clears the entire selection.
55343
+ */
55265
55344
  clear() {
55266
- if (this._selection.size > 0) {
55267
- for (const obj of this._selection) {
55268
- this._adapter.outline(obj, false);
55269
- }
55270
- this._selection.clear();
55271
- this._onSelectionChanged.dispatch();
55345
+ if (this._selection.size === 0) return;
55346
+ for (const obj of this._selection) {
55347
+ this._adapter.outline(obj, false);
55272
55348
  }
55349
+ this._selection.clear();
55350
+ this._onSelectionChanged.requestDispatch();
55273
55351
  }
55352
+ /**
55353
+ * Returns an array of all currently selected objects.
55354
+ * @returns An array of selected objects.
55355
+ */
55274
55356
  getAll() {
55275
55357
  return [...this._selection];
55276
55358
  }
55277
- GetFromVim(vim) {
55359
+ /**
55360
+ * Returns all selected objects belonging to a specific VIM model.
55361
+ * @param vim - The VIM instance to filter by.
55362
+ * @returns An array of selected objects from the specified VIM.
55363
+ */
55364
+ getFromVim(vim) {
55278
55365
  return [...this._selection].filter((obj) => obj.vim === vim);
55279
55366
  }
55367
+ /**
55368
+ * Removes all selected objects that belong to a specific VIM model.
55369
+ * @param vim - The VIM instance to remove selections from.
55370
+ */
55280
55371
  removeFromVim(vim) {
55281
- const prevSize = this._selection.size;
55282
- let removed = false;
55372
+ let changed = false;
55283
55373
  for (const obj of [...this._selection]) {
55284
55374
  if (obj.vim === vim) {
55285
55375
  this._selection.delete(obj);
55286
55376
  this._adapter.outline(obj, false);
55287
- removed = true;
55377
+ changed = true;
55288
55378
  }
55289
55379
  }
55290
- this._dispatchIfChanged(prevSize, removed);
55380
+ if (changed) {
55381
+ this._onSelectionChanged.requestDispatch();
55382
+ }
55291
55383
  }
55384
+ /**
55385
+ * Computes the bounding box that contains all selected objects.
55386
+ * Skips objects that do not implement `getBoundingBox()`.
55387
+ * @returns A promise resolving to the combined bounding box.
55388
+ */
55292
55389
  async getBoundingBox() {
55293
55390
  var _a3;
55294
55391
  const box = new Box3();
@@ -75362,6 +75459,7 @@ const Modal = forwardRef((props, ref) => {
75362
75459
  const getActiveState = () => {
75363
75460
  return (state == null ? void 0 : state[0]) ?? (state == null ? void 0 : state[1]) ?? (state == null ? void 0 : state[2]);
75364
75461
  };
75462
+ console.log("REnder Modal and setup Imperative handle");
75365
75463
  useImperativeHandle(ref, () => ({
75366
75464
  getActiveState,
75367
75465
  loading(content2) {
@@ -75740,18 +75838,28 @@ function useSharedIsolation(adapter) {
75740
75838
  const showRooms = useStateRef(false);
75741
75839
  const showGhost = useStateRef(false);
75742
75840
  const ghostOpacity = useStateRef(() => adapter.getGhostOpacity().toFixed(4));
75841
+ const onAutoIsolate = useFuncRef(() => {
75842
+ if (adapter.hasSelection()) {
75843
+ adapter.isolateSelection();
75844
+ } else {
75845
+ adapter.showAll();
75846
+ }
75847
+ });
75848
+ const onVisibilityChange = useFuncRef(() => {
75849
+ visibility.set(adapter.computeVisibility());
75850
+ });
75743
75851
  useEffect(() => {
75744
75852
  adapter.showGhost(showGhost.get());
75745
75853
  adapter.onVisibilityChange.sub(() => {
75746
- visibility.set(adapter.computeVisibility());
75854
+ onVisibilityChange.call();
75747
75855
  });
75748
75856
  adapter.onSelectionChanged.sub(() => {
75749
- if (autoIsolate2.get()) onAutoIsolate(adapter);
75857
+ if (autoIsolate2.get()) onAutoIsolate.call();
75750
75858
  });
75751
75859
  }, []);
75752
75860
  ghostOpacity.useConfirm((v) => sanitize(v, true, 0.04));
75753
75861
  autoIsolate2.useOnChange((v) => {
75754
- if (v) onAutoIsolate(adapter);
75862
+ if (v) onAutoIsolate.call();
75755
75863
  });
75756
75864
  showGhost.useOnChange((v) => adapter.showGhost(v));
75757
75865
  showRooms.useOnChange((v) => adapter.setShowRooms(v));
@@ -75763,16 +75871,11 @@ function useSharedIsolation(adapter) {
75763
75871
  showPanel,
75764
75872
  showGhost,
75765
75873
  showRooms,
75766
- ghostOpacity
75874
+ ghostOpacity,
75875
+ onAutoIsolate,
75876
+ onVisibilityChange
75767
75877
  };
75768
75878
  }
75769
- function onAutoIsolate(adapter) {
75770
- if (adapter.hasSelection()) {
75771
- adapter.isolateSelection();
75772
- } else {
75773
- adapter.showAll();
75774
- }
75775
- }
75776
75879
  function useWebglIsolation(viewer) {
75777
75880
  const adapter = createWebglIsolationAdapter(viewer);
75778
75881
  return useSharedIsolation(adapter);
@@ -75922,6 +76025,7 @@ function Viewer$1(props) {
75922
76025
  props.viewer.viewport.canvas.tabIndex = 0;
75923
76026
  applyWebglBindings(props.viewer, camera2, isolationRef, side);
75924
76027
  const subContext = props.viewer.inputs.onContextMenu.subscribe(showContextMenu);
76028
+ console.log("ON MOUNT");
75925
76029
  props.onMount({
75926
76030
  container: props.container,
75927
76031
  core: props.viewer,