vim-web 0.3.44-dev.61 → 0.3.44-dev.63

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,72 @@ 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);
55235
+ /**
55236
+ * If true, the selection manager is enabled and can modify the selection.
55237
+ */
55238
+ __publicField(this, "enabled", true);
55185
55239
  this._adapter = adapter;
55186
55240
  }
55241
+ /**
55242
+ * Checks whether a specific object is currently selected.
55243
+ * @param object - The object to check.
55244
+ * @returns `true` if the object is selected; otherwise, `false`.
55245
+ */
55187
55246
  has(object) {
55188
55247
  return this._selection.has(object);
55189
55248
  }
55249
+ /**
55250
+ * Returns the number of selected objects.
55251
+ * @returns The count of selected items.
55252
+ */
55190
55253
  count() {
55191
55254
  return this._selection.size;
55192
55255
  }
55256
+ /**
55257
+ * Checks if there is at least one selected object.
55258
+ * @returns `true` if the selection is not empty.
55259
+ */
55193
55260
  any() {
55194
55261
  return this._selection.size > 0;
55195
55262
  }
55263
+ /**
55264
+ * Signal that fires when the selection changes.
55265
+ */
55196
55266
  get onSelectionChanged() {
55197
- return this._onSelectionChanged.asEvent();
55267
+ return this._onSelectionChanged.signal;
55198
55268
  }
55199
- _dispatchIfChanged(prevSize, modified) {
55200
- if (modified || this._selection.size !== prevSize) {
55201
- this._onSelectionChanged.dispatch();
55202
- }
55269
+ /**
55270
+ * Normalizes a value to an array of objects.
55271
+ * @param oneOrMore - A single object or an array of objects.
55272
+ * @returns An array of objects.
55273
+ */
55274
+ toArray(oneOrMore) {
55275
+ return Array.isArray(oneOrMore) ? oneOrMore : [oneOrMore];
55203
55276
  }
55204
55277
  select(objectOrObjects) {
55278
+ if (!this.enabled) return;
55205
55279
  if (!objectOrObjects) {
55206
55280
  this.clear();
55207
55281
  return;
55208
55282
  }
55209
- const objects = Array.isArray(objectOrObjects) ? objectOrObjects : [objectOrObjects];
55210
- if (objects.length === 1 && this._selection.size === 1 && this._selection.has(objects[0])) {
55283
+ const objects = this.toArray(objectOrObjects);
55284
+ const isRepeatSingleSelection = objects.length === 1 && this._selection.size === 1 && this._selection.has(objects[0]);
55285
+ if (isRepeatSingleSelection) {
55286
+ if (this.toggleOnRepeatSelect) {
55287
+ this.toggle(objects);
55288
+ }
55211
55289
  return;
55212
55290
  }
55213
55291
  for (const obj of this._selection) {
@@ -55218,77 +55296,105 @@ class Selection {
55218
55296
  this._selection.add(obj);
55219
55297
  this._adapter.outline(obj, true);
55220
55298
  }
55221
- this._onSelectionChanged.dispatch();
55299
+ this._onSelectionChanged.requestDispatch();
55222
55300
  }
55223
55301
  toggle(objectOrObjects) {
55224
- const objects = Array.isArray(objectOrObjects) ? objectOrObjects : [objectOrObjects];
55225
- const prevSize = this._selection.size;
55226
- let modified = false;
55302
+ if (!this.enabled) return;
55303
+ const objects = this.toArray(objectOrObjects);
55304
+ let changed = false;
55227
55305
  for (const obj of objects) {
55228
55306
  if (this._selection.has(obj)) {
55229
55307
  this._selection.delete(obj);
55230
55308
  this._adapter.outline(obj, false);
55231
- modified = true;
55309
+ changed = true;
55232
55310
  } else {
55233
55311
  this._selection.add(obj);
55234
55312
  this._adapter.outline(obj, true);
55235
- modified = true;
55313
+ changed = true;
55236
55314
  }
55237
55315
  }
55238
- this._dispatchIfChanged(prevSize, modified);
55316
+ if (changed) {
55317
+ this._onSelectionChanged.requestDispatch();
55318
+ }
55239
55319
  }
55240
55320
  add(objectOrObjects) {
55241
- const objects = Array.isArray(objectOrObjects) ? objectOrObjects : [objectOrObjects];
55242
- const prevSize = this._selection.size;
55243
- let anyNew = false;
55321
+ if (!this.enabled) return;
55322
+ const objects = this.toArray(objectOrObjects);
55323
+ let changed = false;
55244
55324
  for (const obj of objects) {
55245
55325
  if (!this._selection.has(obj)) {
55246
55326
  this._selection.add(obj);
55247
55327
  this._adapter.outline(obj, true);
55248
- anyNew = true;
55328
+ changed = true;
55249
55329
  }
55250
55330
  }
55251
- this._dispatchIfChanged(prevSize, anyNew);
55331
+ if (changed) {
55332
+ this._onSelectionChanged.requestDispatch();
55333
+ }
55252
55334
  }
55253
55335
  remove(objectOrObjects) {
55254
- const objects = Array.isArray(objectOrObjects) ? objectOrObjects : [objectOrObjects];
55255
- const prevSize = this._selection.size;
55256
- let removedAny = false;
55336
+ if (!this.enabled) return;
55337
+ const objects = this.toArray(objectOrObjects);
55338
+ let changed = false;
55257
55339
  for (const obj of objects) {
55258
55340
  if (this._selection.delete(obj)) {
55259
55341
  this._adapter.outline(obj, false);
55260
- removedAny = true;
55342
+ changed = true;
55261
55343
  }
55262
55344
  }
55263
- this._dispatchIfChanged(prevSize, removedAny);
55345
+ if (changed) {
55346
+ this._onSelectionChanged.requestDispatch();
55347
+ }
55264
55348
  }
55349
+ /**
55350
+ * Clears the entire selection.
55351
+ */
55265
55352
  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();
55353
+ if (!this.enabled) return;
55354
+ if (this._selection.size === 0) return;
55355
+ for (const obj of this._selection) {
55356
+ this._adapter.outline(obj, false);
55272
55357
  }
55358
+ this._selection.clear();
55359
+ this._onSelectionChanged.requestDispatch();
55273
55360
  }
55361
+ /**
55362
+ * Returns an array of all currently selected objects.
55363
+ * @returns An array of selected objects.
55364
+ */
55274
55365
  getAll() {
55275
55366
  return [...this._selection];
55276
55367
  }
55277
- GetFromVim(vim) {
55368
+ /**
55369
+ * Returns all selected objects belonging to a specific VIM model.
55370
+ * @param vim - The VIM instance to filter by.
55371
+ * @returns An array of selected objects from the specified VIM.
55372
+ */
55373
+ getFromVim(vim) {
55278
55374
  return [...this._selection].filter((obj) => obj.vim === vim);
55279
55375
  }
55376
+ /**
55377
+ * Removes all selected objects that belong to a specific VIM model.
55378
+ * @param vim - The VIM instance to remove selections from.
55379
+ */
55280
55380
  removeFromVim(vim) {
55281
- const prevSize = this._selection.size;
55282
- let removed = false;
55381
+ let changed = false;
55283
55382
  for (const obj of [...this._selection]) {
55284
55383
  if (obj.vim === vim) {
55285
55384
  this._selection.delete(obj);
55286
55385
  this._adapter.outline(obj, false);
55287
- removed = true;
55386
+ changed = true;
55288
55387
  }
55289
55388
  }
55290
- this._dispatchIfChanged(prevSize, removed);
55389
+ if (changed) {
55390
+ this._onSelectionChanged.requestDispatch();
55391
+ }
55291
55392
  }
55393
+ /**
55394
+ * Computes the bounding box that contains all selected objects.
55395
+ * Skips objects that do not implement `getBoundingBox()`.
55396
+ * @returns A promise resolving to the combined bounding box.
55397
+ */
55292
55398
  async getBoundingBox() {
55293
55399
  var _a3;
55294
55400
  const box = new Box3();