@vuu-ui/vuu-utils 3.1.0-beta.2 → 3.1.0-beta.4

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.
Files changed (60) hide show
  1. package/package.json +10 -8
  2. package/src/index.js +4 -4
  3. package/src/vendor/@dnd-kit/abstract/index.d.ts +1279 -0
  4. package/src/vendor/@dnd-kit/abstract/index.js +1472 -0
  5. package/src/vendor/@dnd-kit/abstract/index.js.map +1 -0
  6. package/src/vendor/@dnd-kit/abstract/modifiers.d.ts +134 -0
  7. package/src/vendor/@dnd-kit/abstract/modifiers.js +100 -0
  8. package/src/vendor/@dnd-kit/abstract/modifiers.js.map +1 -0
  9. package/src/vendor/@dnd-kit/abstract/package.json +60 -0
  10. package/src/vendor/@dnd-kit/collision/dist/index.d.ts +46 -0
  11. package/src/vendor/@dnd-kit/collision/dist/index.js +175 -0
  12. package/src/vendor/@dnd-kit/collision/package.json +42 -0
  13. package/src/vendor/@dnd-kit/dom/index.d.ts +298 -0
  14. package/src/vendor/@dnd-kit/dom/index.js +1977 -0
  15. package/src/vendor/@dnd-kit/dom/index.js.map +1 -0
  16. package/src/vendor/@dnd-kit/dom/modifiers.d.ts +26 -0
  17. package/src/vendor/@dnd-kit/dom/modifiers.js +117 -0
  18. package/src/vendor/@dnd-kit/dom/modifiers.js.map +1 -0
  19. package/src/vendor/@dnd-kit/dom/package.json +92 -0
  20. package/src/vendor/@dnd-kit/dom/plugins/debug.d.ts +8 -0
  21. package/src/vendor/@dnd-kit/dom/plugins/debug.js +125 -0
  22. package/src/vendor/@dnd-kit/dom/plugins/debug.js.map +1 -0
  23. package/src/vendor/@dnd-kit/dom/sortable.d.ts +125 -0
  24. package/src/vendor/@dnd-kit/dom/sortable.js +822 -0
  25. package/src/vendor/@dnd-kit/dom/sortable.js.map +1 -0
  26. package/src/vendor/@dnd-kit/dom/utilities.d.ts +215 -0
  27. package/src/vendor/@dnd-kit/dom/utilities.js +1361 -0
  28. package/src/vendor/@dnd-kit/dom/utilities.js.map +1 -0
  29. package/src/vendor/@dnd-kit/geometry/dist/index.d.ts +178 -0
  30. package/src/vendor/@dnd-kit/geometry/dist/index.js +347 -0
  31. package/src/vendor/@dnd-kit/geometry/package.json +31 -0
  32. package/src/vendor/@dnd-kit/react/hooks.d.ts +30 -0
  33. package/src/vendor/@dnd-kit/react/hooks.js +133 -0
  34. package/src/vendor/@dnd-kit/react/index.d.ts +84 -0
  35. package/src/vendor/@dnd-kit/react/index.js +617 -0
  36. package/src/vendor/@dnd-kit/react/package.json +80 -0
  37. package/src/vendor/@dnd-kit/react/sortable.d.ts +26 -0
  38. package/src/vendor/@dnd-kit/react/sortable.js +175 -0
  39. package/src/vendor/@dnd-kit/react/utilities.d.ts +7 -0
  40. package/src/vendor/@dnd-kit/react/utilities.js +18 -0
  41. package/src/vendor/@dnd-kit/state/dist/index.d.ts +54 -0
  42. package/src/vendor/@dnd-kit/state/dist/index.js +328 -0
  43. package/src/vendor/@dnd-kit/state/package.json +33 -0
  44. package/src/vendor/@preact/signals-core/dist/signals-core.js +1 -0
  45. package/src/vendor/@preact/signals-core/dist/signals-core.js.map +1 -0
  46. package/src/vendor/@preact/signals-core/package.json +4 -0
  47. package/src/vendor/tslib/CopyrightNotice.txt +15 -0
  48. package/src/vendor/tslib/LICENSE.txt +12 -0
  49. package/src/vendor/tslib/README.md +164 -0
  50. package/src/vendor/tslib/SECURITY.md +41 -0
  51. package/src/vendor/tslib/modules/index.d.ts +38 -0
  52. package/src/vendor/tslib/modules/index.js +70 -0
  53. package/src/vendor/tslib/modules/package.json +3 -0
  54. package/src/vendor/tslib/package.json +47 -0
  55. package/src/vendor/tslib/tslib.d.ts +460 -0
  56. package/src/vendor/tslib/tslib.es6.html +1 -0
  57. package/src/vendor/tslib/tslib.es6.js +402 -0
  58. package/src/vendor/tslib/tslib.es6.mjs +401 -0
  59. package/src/vendor/tslib/tslib.html +1 -0
  60. package/src/vendor/tslib/tslib.js +484 -0
@@ -0,0 +1,1472 @@
1
+ import { untracked, effect, effects, reactive, derived, ValueHistory, snapshot, batch, signal } from '../state/dist/index.js';
2
+ import { Position } from '../geometry/dist/index.js';
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __defProps = Object.defineProperties;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
9
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
13
+ var __typeError = (msg) => {
14
+ throw TypeError(msg);
15
+ };
16
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __spreadValues = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ if (__getOwnPropSymbols)
22
+ for (var prop of __getOwnPropSymbols(b)) {
23
+ if (__propIsEnum.call(b, prop))
24
+ __defNormalProp(a, prop, b[prop]);
25
+ }
26
+ return a;
27
+ };
28
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
29
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
30
+ var __objRest = (source, exclude) => {
31
+ var target = {};
32
+ for (var prop in source)
33
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
34
+ target[prop] = source[prop];
35
+ if (source != null && __getOwnPropSymbols)
36
+ for (var prop of __getOwnPropSymbols(source)) {
37
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
38
+ target[prop] = source[prop];
39
+ }
40
+ return target;
41
+ };
42
+ var __decoratorStart = (base) => {
43
+ var _a;
44
+ return [, , , __create((_a = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a : null)];
45
+ };
46
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
47
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
48
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
49
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
50
+ var __runInitializers = (array, flags, self, value) => {
51
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
52
+ return value;
53
+ };
54
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
55
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
56
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
57
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
58
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
59
+ return __privateGet(this, extra);
60
+ }, set [name](x) {
61
+ return __privateSet(this, extra, x);
62
+ } }, name));
63
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
64
+ for (var i = decorators.length - 1; i >= 0; i--) {
65
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
66
+ if (k) {
67
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
68
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
69
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
70
+ }
71
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
72
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
73
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
74
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
75
+ }
76
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
77
+ };
78
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
79
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
80
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
81
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
82
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
83
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
84
+
85
+ // src/core/plugins/utilities.ts
86
+ function configure(plugin, options) {
87
+ return {
88
+ plugin,
89
+ options
90
+ };
91
+ }
92
+ function configurator(plugin) {
93
+ return (options) => {
94
+ return configure(plugin, options);
95
+ };
96
+ }
97
+ function descriptor(plugin) {
98
+ if (typeof plugin === "function") {
99
+ return {
100
+ plugin,
101
+ options: void 0
102
+ };
103
+ }
104
+ return plugin;
105
+ }
106
+
107
+ // src/core/plugins/plugin.ts
108
+ var _disabled_dec, _init, _disabled, _cleanupFunctions;
109
+ _disabled_dec = [reactive];
110
+ var Plugin = class {
111
+ /**
112
+ * Creates a new plugin instance.
113
+ *
114
+ * @param manager - The drag and drop manager that owns this plugin
115
+ * @param options - Optional configuration for the plugin
116
+ */
117
+ constructor(manager, options) {
118
+ this.manager = manager;
119
+ this.options = options;
120
+ __privateAdd(this, _disabled, __runInitializers(_init, 8, this, false)), __runInitializers(_init, 11, this);
121
+ __privateAdd(this, _cleanupFunctions, /* @__PURE__ */ new Set());
122
+ }
123
+ /**
124
+ * Enables a disabled plugin instance.
125
+ *
126
+ * @remarks
127
+ * This method triggers effects when called.
128
+ */
129
+ enable() {
130
+ this.disabled = false;
131
+ }
132
+ /**
133
+ * Disables an enabled plugin instance.
134
+ *
135
+ * @remarks
136
+ * This method triggers effects when called.
137
+ */
138
+ disable() {
139
+ this.disabled = true;
140
+ }
141
+ /**
142
+ * Checks if the plugin instance is disabled.
143
+ *
144
+ * @returns true if the plugin is disabled
145
+ * @remarks
146
+ * This method does not trigger effects when accessed.
147
+ */
148
+ isDisabled() {
149
+ return untracked(() => {
150
+ return this.disabled;
151
+ });
152
+ }
153
+ /**
154
+ * Configures a plugin instance with new options.
155
+ *
156
+ * @param options - The new options to apply
157
+ */
158
+ configure(options) {
159
+ this.options = options;
160
+ }
161
+ /**
162
+ * Registers an effect that will be cleaned up when the plugin is destroyed.
163
+ *
164
+ * @param callback - The effect callback to register
165
+ * @returns A function to dispose of the effect
166
+ */
167
+ registerEffect(callback) {
168
+ const dispose = effect(callback.bind(this));
169
+ __privateGet(this, _cleanupFunctions).add(dispose);
170
+ return dispose;
171
+ }
172
+ /**
173
+ * Destroys a plugin instance and cleans up its resources.
174
+ *
175
+ * @remarks
176
+ * This method:
177
+ * - Calls all registered cleanup functions
178
+ * - Should be overridden by subclasses to clean up additional resources
179
+ */
180
+ destroy() {
181
+ __privateGet(this, _cleanupFunctions).forEach((cleanup) => cleanup());
182
+ }
183
+ /**
184
+ * Configures a plugin constructor with options.
185
+ *
186
+ * @param options - The options to configure the constructor with
187
+ * @returns The configured plugin constructor
188
+ *
189
+ * @remarks
190
+ * This method is used to configure the options that the
191
+ * plugin constructor will use to create plugin instances.
192
+ */
193
+ static configure(options) {
194
+ return configure(this, options);
195
+ }
196
+ };
197
+ _init = __decoratorStart(null);
198
+ _disabled = new WeakMap();
199
+ _cleanupFunctions = new WeakMap();
200
+ __decorateElement(_init, 4, "disabled", _disabled_dec, Plugin, _disabled);
201
+ __decoratorMetadata(_init, Plugin);
202
+ var CorePlugin = class extends Plugin {
203
+ };
204
+
205
+ // src/core/plugins/registry.ts
206
+ var _previousValues;
207
+ var PluginRegistry = class {
208
+ /**
209
+ * Creates a new plugin registry.
210
+ *
211
+ * @param manager - The drag and drop manager that owns this registry
212
+ */
213
+ constructor(manager) {
214
+ this.manager = manager;
215
+ this.instances = /* @__PURE__ */ new Map();
216
+ __privateAdd(this, _previousValues, []);
217
+ }
218
+ /**
219
+ * Gets all registered plugin instances.
220
+ *
221
+ * @returns An array of all active plugin instances
222
+ */
223
+ get values() {
224
+ return Array.from(this.instances.values());
225
+ }
226
+ /**
227
+ * Sets the list of plugins to be used by the registry.
228
+ *
229
+ * @param entries - Array of plugin constructors or descriptors
230
+ * @remarks
231
+ * This method:
232
+ * - Filters out duplicate plugins
233
+ * - Unregisters plugins that are no longer in use
234
+ * - Registers new plugins with their options
235
+ */
236
+ set values(entries) {
237
+ const descriptors = entries.map(descriptor).reduceRight((acc, descriptor2) => {
238
+ if (acc.some(({ plugin }) => plugin === descriptor2.plugin)) {
239
+ return acc;
240
+ }
241
+ return [descriptor2, ...acc];
242
+ }, []);
243
+ const constructors = descriptors.map(({ plugin }) => plugin);
244
+ for (const plugin of __privateGet(this, _previousValues)) {
245
+ if (!constructors.includes(plugin)) {
246
+ if (plugin.prototype instanceof CorePlugin) {
247
+ continue;
248
+ }
249
+ this.unregister(plugin);
250
+ }
251
+ }
252
+ for (const { plugin, options } of descriptors) {
253
+ this.register(plugin, options);
254
+ }
255
+ __privateSet(this, _previousValues, constructors);
256
+ }
257
+ /**
258
+ * Gets a plugin instance by its constructor.
259
+ *
260
+ * @param plugin - The plugin constructor to look up
261
+ * @returns The plugin instance or undefined if not found
262
+ */
263
+ get(plugin) {
264
+ const instance = this.instances.get(plugin);
265
+ return instance;
266
+ }
267
+ /**
268
+ * Registers a new plugin instance.
269
+ *
270
+ * @param plugin - The plugin constructor to register
271
+ * @param options - Optional configuration for the plugin
272
+ * @returns The registered plugin instance
273
+ * @remarks
274
+ * If the plugin is already registered, its options will be updated
275
+ * and the existing instance will be returned.
276
+ */
277
+ register(plugin, options) {
278
+ const existingInstance = this.instances.get(plugin);
279
+ if (existingInstance) {
280
+ if (existingInstance.options !== options) {
281
+ existingInstance.options = options;
282
+ }
283
+ return existingInstance;
284
+ }
285
+ const instance = new plugin(this.manager, options);
286
+ this.instances.set(plugin, instance);
287
+ return instance;
288
+ }
289
+ /**
290
+ * Unregisters a plugin instance.
291
+ *
292
+ * @param plugin - The plugin constructor to unregister
293
+ * @remarks
294
+ * This method:
295
+ * - Destroys the plugin instance
296
+ * - Removes it from the registry
297
+ */
298
+ unregister(plugin) {
299
+ const instance = this.instances.get(plugin);
300
+ if (instance) {
301
+ instance.destroy();
302
+ this.instances.delete(plugin);
303
+ }
304
+ }
305
+ /**
306
+ * Destroys all registered plugin instances.
307
+ *
308
+ * @remarks
309
+ * This method:
310
+ * - Calls destroy() on all plugin instances
311
+ * - Clears the registry
312
+ */
313
+ destroy() {
314
+ for (const plugin of this.instances.values()) {
315
+ plugin.destroy();
316
+ }
317
+ this.instances.clear();
318
+ }
319
+ };
320
+ _previousValues = new WeakMap();
321
+
322
+ // src/core/collision/utilities.ts
323
+ function sortCollisions(a, b) {
324
+ if (a.priority === b.priority) {
325
+ if (a.type === b.type) {
326
+ return b.value - a.value;
327
+ }
328
+ return b.type - a.type;
329
+ }
330
+ return b.priority - a.priority;
331
+ }
332
+
333
+ // src/core/collision/observer.ts
334
+ var DEFAULT_VALUE = [];
335
+ var _previousCoordinates, _collisions;
336
+ var CollisionObserver = class extends Plugin {
337
+ /**
338
+ * Creates a new CollisionObserver instance.
339
+ *
340
+ * @param manager - The drag drop manager instance
341
+ */
342
+ constructor(manager) {
343
+ super(manager);
344
+ __privateAdd(this, _previousCoordinates);
345
+ __privateAdd(this, _collisions);
346
+ this.computeCollisions = this.computeCollisions.bind(this);
347
+ __privateSet(this, _collisions, signal(DEFAULT_VALUE));
348
+ this.destroy = effects(
349
+ () => {
350
+ const collisions = this.computeCollisions();
351
+ const coordinates = untracked(
352
+ () => this.manager.dragOperation.position.current
353
+ );
354
+ if (collisions !== DEFAULT_VALUE) {
355
+ const previousCoordinates = __privateGet(this, _previousCoordinates);
356
+ __privateSet(this, _previousCoordinates, coordinates);
357
+ if (previousCoordinates && coordinates.x == previousCoordinates.x && coordinates.y == previousCoordinates.y) {
358
+ return;
359
+ }
360
+ } else {
361
+ __privateSet(this, _previousCoordinates, void 0);
362
+ }
363
+ __privateGet(this, _collisions).value = collisions;
364
+ },
365
+ () => {
366
+ const { dragOperation } = this.manager;
367
+ if (dragOperation.status.initialized) {
368
+ this.forceUpdate();
369
+ }
370
+ }
371
+ );
372
+ }
373
+ /**
374
+ * Forces an immediate update of collision detection.
375
+ *
376
+ * @param immediate - If true, updates collisions immediately. If false, resets previous coordinates.
377
+ */
378
+ forceUpdate(immediate = true) {
379
+ untracked(() => {
380
+ if (immediate) {
381
+ __privateGet(this, _collisions).value = this.computeCollisions();
382
+ } else {
383
+ __privateSet(this, _previousCoordinates, void 0);
384
+ }
385
+ });
386
+ }
387
+ /**
388
+ * Computes collisions between draggable and droppable elements.
389
+ *
390
+ * @param entries - Optional array of droppable elements to check. If not provided, uses all registered droppables.
391
+ * @param collisionDetector - Optional custom collision detector function
392
+ * @returns Array of detected collisions, sorted by priority
393
+ */
394
+ computeCollisions(entries, collisionDetector) {
395
+ const { registry, dragOperation } = this.manager;
396
+ const { source, shape, status } = dragOperation;
397
+ if (!status.initialized || !shape) {
398
+ return DEFAULT_VALUE;
399
+ }
400
+ const collisions = [];
401
+ const potentialTargets = [];
402
+ for (const entry of entries != null ? entries : registry.droppables) {
403
+ if (entry.disabled) {
404
+ continue;
405
+ }
406
+ if (source && !entry.accepts(source)) {
407
+ continue;
408
+ }
409
+ const detectCollision = collisionDetector != null ? collisionDetector : entry.collisionDetector;
410
+ if (!detectCollision) {
411
+ continue;
412
+ }
413
+ potentialTargets.push(entry);
414
+ void entry.shape;
415
+ const collision = untracked(
416
+ () => detectCollision({
417
+ droppable: entry,
418
+ dragOperation
419
+ })
420
+ );
421
+ if (collision) {
422
+ if (entry.collisionPriority != null) {
423
+ collision.priority = entry.collisionPriority;
424
+ }
425
+ collisions.push(collision);
426
+ }
427
+ }
428
+ if (potentialTargets.length === 0) {
429
+ return DEFAULT_VALUE;
430
+ }
431
+ collisions.sort(sortCollisions);
432
+ return collisions;
433
+ }
434
+ /**
435
+ * Gets the current collisions signal value.
436
+ */
437
+ get collisions() {
438
+ return __privateGet(this, _collisions).value;
439
+ }
440
+ };
441
+ _previousCoordinates = new WeakMap();
442
+ _collisions = new WeakMap();
443
+
444
+ // src/core/manager/events.ts
445
+ var Monitor = class {
446
+ constructor() {
447
+ this.registry = /* @__PURE__ */ new Map();
448
+ }
449
+ /**
450
+ * Adds an event listener for the specified event type.
451
+ *
452
+ * @param name - The name of the event to listen for
453
+ * @param handler - The function to call when the event occurs
454
+ * @returns A function to remove the event listener
455
+ */
456
+ addEventListener(name, handler) {
457
+ const { registry } = this;
458
+ const listeners = new Set(registry.get(name));
459
+ listeners.add(handler);
460
+ registry.set(name, listeners);
461
+ return () => this.removeEventListener(name, handler);
462
+ }
463
+ /**
464
+ * Removes an event listener for the specified event type.
465
+ *
466
+ * @param name - The name of the event
467
+ * @param handler - The function to remove
468
+ */
469
+ removeEventListener(name, handler) {
470
+ const { registry } = this;
471
+ const listeners = new Set(registry.get(name));
472
+ listeners.delete(handler);
473
+ registry.set(name, listeners);
474
+ }
475
+ /**
476
+ * Dispatches an event to all registered listeners.
477
+ *
478
+ * @param name - The name of the event to dispatch
479
+ * @param args - Arguments to pass to the event handlers
480
+ */
481
+ dispatch(name, ...args) {
482
+ const { registry } = this;
483
+ const listeners = registry.get(name);
484
+ if (!listeners) {
485
+ return;
486
+ }
487
+ for (const listener of listeners) {
488
+ listener(...args);
489
+ }
490
+ }
491
+ };
492
+ var DragDropMonitor = class extends Monitor {
493
+ /**
494
+ * Creates a new drag and drop monitor.
495
+ *
496
+ * @param manager - The drag and drop manager to monitor
497
+ */
498
+ constructor(manager) {
499
+ super();
500
+ this.manager = manager;
501
+ }
502
+ /**
503
+ * Dispatches a drag and drop event.
504
+ *
505
+ * @param type - The type of event to dispatch
506
+ * @param event - The event data to dispatch
507
+ */
508
+ dispatch(type, event) {
509
+ const args = [event, this.manager];
510
+ super.dispatch(type, ...args);
511
+ }
512
+ };
513
+ function defaultPreventable(event, cancelable = true) {
514
+ let defaultPrevented = false;
515
+ return __spreadProps(__spreadValues({}, event), {
516
+ cancelable,
517
+ get defaultPrevented() {
518
+ return defaultPrevented;
519
+ },
520
+ preventDefault() {
521
+ if (!cancelable) {
522
+ return;
523
+ }
524
+ defaultPrevented = true;
525
+ }
526
+ });
527
+ }
528
+
529
+ // src/core/collision/notifier.ts
530
+ var CollisionNotifier = class extends CorePlugin {
531
+ constructor(manager) {
532
+ super(manager);
533
+ const isEqual = (a, b) => a.map(({ id }) => id).join("") === b.map(({ id }) => id).join("");
534
+ let previousCollisions = [];
535
+ this.destroy = effects(
536
+ () => {
537
+ const { dragOperation, collisionObserver } = manager;
538
+ if (dragOperation.status.initializing) {
539
+ previousCollisions = [];
540
+ collisionObserver.enable();
541
+ }
542
+ },
543
+ () => {
544
+ const { collisionObserver, monitor } = manager;
545
+ const { collisions } = collisionObserver;
546
+ if (collisionObserver.isDisabled()) {
547
+ return;
548
+ }
549
+ const event = defaultPreventable({
550
+ collisions
551
+ });
552
+ monitor.dispatch("collision", event);
553
+ if (event.defaultPrevented) {
554
+ return;
555
+ }
556
+ if (isEqual(collisions, previousCollisions)) {
557
+ return;
558
+ } else {
559
+ previousCollisions = collisions;
560
+ }
561
+ const [firstCollision] = collisions;
562
+ untracked(() => {
563
+ var _a;
564
+ if ((firstCollision == null ? void 0 : firstCollision.id) !== ((_a = manager.dragOperation.target) == null ? void 0 : _a.id)) {
565
+ collisionObserver.disable();
566
+ manager.actions.setDropTarget(firstCollision == null ? void 0 : firstCollision.id).then(() => {
567
+ collisionObserver.enable();
568
+ });
569
+ }
570
+ });
571
+ }
572
+ );
573
+ }
574
+ };
575
+
576
+ // src/core/collision/types.ts
577
+ var CollisionPriority = /* @__PURE__ */ ((CollisionPriority2) => {
578
+ CollisionPriority2[CollisionPriority2["Lowest"] = 0] = "Lowest";
579
+ CollisionPriority2[CollisionPriority2["Low"] = 1] = "Low";
580
+ CollisionPriority2[CollisionPriority2["Normal"] = 2] = "Normal";
581
+ CollisionPriority2[CollisionPriority2["High"] = 3] = "High";
582
+ CollisionPriority2[CollisionPriority2["Highest"] = 4] = "Highest";
583
+ return CollisionPriority2;
584
+ })(CollisionPriority || {});
585
+ var CollisionType = /* @__PURE__ */ ((CollisionType2) => {
586
+ CollisionType2[CollisionType2["Collision"] = 0] = "Collision";
587
+ CollisionType2[CollisionType2["ShapeIntersection"] = 1] = "ShapeIntersection";
588
+ CollisionType2[CollisionType2["PointerIntersection"] = 2] = "PointerIntersection";
589
+ return CollisionType2;
590
+ })(CollisionType || {});
591
+ var _dropped_dec, _dragging_dec, _initialized_dec, _initializing_dec, _idle_dec, _current_dec, _value_dec, _init2, _value;
592
+ _value_dec = [reactive], _current_dec = [derived], _idle_dec = [derived], _initializing_dec = [derived], _initialized_dec = [derived], _dragging_dec = [derived], _dropped_dec = [derived];
593
+ var Status = class {
594
+ constructor() {
595
+ __runInitializers(_init2, 5, this);
596
+ __privateAdd(this, _value, __runInitializers(_init2, 8, this, "idle" /* Idle */)), __runInitializers(_init2, 11, this);
597
+ }
598
+ get current() {
599
+ return this.value;
600
+ }
601
+ get idle() {
602
+ return this.value === "idle" /* Idle */;
603
+ }
604
+ get initializing() {
605
+ return this.value === "initializing" /* Initializing */;
606
+ }
607
+ get initialized() {
608
+ const { value } = this;
609
+ return value !== "idle" /* Idle */ && value !== "initialization-pending" /* InitializationPending */;
610
+ }
611
+ get dragging() {
612
+ return this.value === "dragging" /* Dragging */;
613
+ }
614
+ get dropped() {
615
+ return this.value === "dropped" /* Dropped */;
616
+ }
617
+ /**
618
+ * Sets the current status value.
619
+ *
620
+ * @param value - The new status value
621
+ */
622
+ set(value) {
623
+ this.value = value;
624
+ }
625
+ };
626
+ _init2 = __decoratorStart(null);
627
+ _value = new WeakMap();
628
+ __decorateElement(_init2, 4, "value", _value_dec, Status, _value);
629
+ __decorateElement(_init2, 2, "current", _current_dec, Status);
630
+ __decorateElement(_init2, 2, "idle", _idle_dec, Status);
631
+ __decorateElement(_init2, 2, "initializing", _initializing_dec, Status);
632
+ __decorateElement(_init2, 2, "initialized", _initialized_dec, Status);
633
+ __decorateElement(_init2, 2, "dragging", _dragging_dec, Status);
634
+ __decorateElement(_init2, 2, "dropped", _dropped_dec, Status);
635
+ __decoratorMetadata(_init2, Status);
636
+
637
+ // src/core/manager/actions.ts
638
+ var DragActions = class {
639
+ /**
640
+ * Creates a new instance of drag actions.
641
+ *
642
+ * @param manager - The drag and drop manager instance
643
+ */
644
+ constructor(manager) {
645
+ this.manager = manager;
646
+ }
647
+ /**
648
+ * Sets the source of the drag operation.
649
+ *
650
+ * @param source - The draggable entity or its unique identifier
651
+ */
652
+ setDragSource(source) {
653
+ const { dragOperation } = this.manager;
654
+ dragOperation.sourceIdentifier = typeof source === "string" || typeof source === "number" ? source : source.id;
655
+ }
656
+ /**
657
+ * Sets the target of the drop operation.
658
+ *
659
+ * @param identifier - The unique identifier of the droppable entity or null/undefined
660
+ * @returns A promise that resolves to true if the drop was prevented
661
+ */
662
+ setDropTarget(identifier) {
663
+ return untracked(() => {
664
+ const { dragOperation } = this.manager;
665
+ const id = identifier != null ? identifier : null;
666
+ if (dragOperation.targetIdentifier === id) {
667
+ return Promise.resolve(false);
668
+ }
669
+ dragOperation.targetIdentifier = id;
670
+ const event = defaultPreventable({
671
+ operation: dragOperation.snapshot()
672
+ });
673
+ if (dragOperation.status.dragging) {
674
+ this.manager.monitor.dispatch("dragover", event);
675
+ }
676
+ return this.manager.renderer.rendering.then(() => event.defaultPrevented);
677
+ });
678
+ }
679
+ /**
680
+ * Starts a new drag operation.
681
+ *
682
+ * @param args - Configuration for the drag operation
683
+ * @param args.event - The event that initiated the drag
684
+ * @param args.source - The source draggable entity or its identifier
685
+ * @param args.coordinates - The initial coordinates of the drag
686
+ * @returns true if the drag operation started successfully
687
+ * @throws {Error} If there is no drag source or another operation is active
688
+ */
689
+ start(args) {
690
+ return untracked(() => {
691
+ const { dragOperation } = this.manager;
692
+ if (args.source != null) {
693
+ this.setDragSource(args.source);
694
+ }
695
+ const sourceInstance = dragOperation.source;
696
+ if (!sourceInstance) {
697
+ throw new Error("Cannot start a drag operation without a drag source");
698
+ }
699
+ if (!dragOperation.status.idle) {
700
+ throw new Error(
701
+ "Cannot start a drag operation while another is active"
702
+ );
703
+ }
704
+ const controller = new AbortController();
705
+ const { event: nativeEvent, coordinates } = args;
706
+ batch(() => {
707
+ dragOperation.status.set("initialization-pending" /* InitializationPending */);
708
+ dragOperation.shape = null;
709
+ dragOperation.canceled = false;
710
+ dragOperation.activatorEvent = nativeEvent != null ? nativeEvent : null;
711
+ dragOperation.position.reset(coordinates);
712
+ });
713
+ const beforeStartEvent = defaultPreventable({
714
+ operation: dragOperation.snapshot()
715
+ });
716
+ this.manager.monitor.dispatch("beforedragstart", beforeStartEvent);
717
+ if (beforeStartEvent.defaultPrevented) {
718
+ dragOperation.reset();
719
+ controller.abort();
720
+ return controller;
721
+ }
722
+ dragOperation.status.set("initializing" /* Initializing */);
723
+ dragOperation.controller = controller;
724
+ this.manager.renderer.rendering.then(() => {
725
+ if (controller.signal.aborted) return;
726
+ const { status } = dragOperation;
727
+ if (status.current !== "initializing" /* Initializing */) return;
728
+ dragOperation.status.set("dragging" /* Dragging */);
729
+ this.manager.monitor.dispatch("dragstart", {
730
+ nativeEvent,
731
+ operation: dragOperation.snapshot(),
732
+ cancelable: false
733
+ });
734
+ });
735
+ return controller;
736
+ });
737
+ }
738
+ /**
739
+ * Moves the dragged entity to a new position.
740
+ *
741
+ * @param args - Configuration for the move operation
742
+ * @param args.by - Relative coordinates to move by
743
+ * @param args.to - Absolute coordinates to move to
744
+ * @param args.event - The event that triggered the move
745
+ * @param args.cancelable - Whether the move can be canceled
746
+ * @param args.propagate - Whether to dispatch dragmove events
747
+ */
748
+ move(args) {
749
+ return untracked(() => {
750
+ var _a, _b;
751
+ const { dragOperation } = this.manager;
752
+ const { status, controller } = dragOperation;
753
+ if (!status.dragging || !controller || controller.signal.aborted) {
754
+ return;
755
+ }
756
+ const event = defaultPreventable(
757
+ {
758
+ nativeEvent: args.event,
759
+ operation: dragOperation.snapshot(),
760
+ by: args.by,
761
+ to: args.to
762
+ },
763
+ (_a = args.cancelable) != null ? _a : true
764
+ );
765
+ if ((_b = args.propagate) != null ? _b : true) {
766
+ this.manager.monitor.dispatch("dragmove", event);
767
+ }
768
+ queueMicrotask(() => {
769
+ var _a2, _b2, _c3, _d, _e;
770
+ if (event.defaultPrevented) {
771
+ return;
772
+ }
773
+ const coordinates = (_e = args.to) != null ? _e : {
774
+ x: dragOperation.position.current.x + ((_b2 = (_a2 = args.by) == null ? void 0 : _a2.x) != null ? _b2 : 0),
775
+ y: dragOperation.position.current.y + ((_d = (_c3 = args.by) == null ? void 0 : _c3.y) != null ? _d : 0)
776
+ };
777
+ dragOperation.position.current = coordinates;
778
+ });
779
+ });
780
+ }
781
+ /**
782
+ * Stops the current drag operation.
783
+ *
784
+ * @param args - Configuration for stopping the operation
785
+ * @param args.event - The event that triggered the stop
786
+ * @param args.canceled - Whether the operation was canceled
787
+ * @remarks
788
+ * This method:
789
+ * - Dispatches a dragend event
790
+ * - Allows suspension of the operation
791
+ * - Handles cleanup of the operation state
792
+ */
793
+ stop(args = {}) {
794
+ return untracked(() => {
795
+ var _a, _b;
796
+ const { dragOperation } = this.manager;
797
+ const { controller } = dragOperation;
798
+ if (!controller || controller.signal.aborted) return;
799
+ let promise;
800
+ const suspend = () => {
801
+ const output = {
802
+ resume: () => {
803
+ },
804
+ abort: () => {
805
+ }
806
+ };
807
+ promise = new Promise((resolve, reject) => {
808
+ output.resume = resolve;
809
+ output.abort = reject;
810
+ });
811
+ return output;
812
+ };
813
+ controller.abort();
814
+ const end = () => {
815
+ this.manager.renderer.rendering.then(() => {
816
+ dragOperation.status.set("dropped" /* Dropped */);
817
+ const dropping = untracked(
818
+ () => {
819
+ var _a2;
820
+ return ((_a2 = dragOperation.source) == null ? void 0 : _a2.status) === "dropping";
821
+ }
822
+ );
823
+ const cleanup = () => {
824
+ if (dragOperation.controller === controller) {
825
+ dragOperation.controller = void 0;
826
+ }
827
+ dragOperation.reset();
828
+ };
829
+ if (dropping) {
830
+ const { source } = dragOperation;
831
+ const dispose = effect(() => {
832
+ if ((source == null ? void 0 : source.status) === "idle") {
833
+ dispose();
834
+ cleanup();
835
+ }
836
+ });
837
+ } else {
838
+ this.manager.renderer.rendering.then(cleanup);
839
+ }
840
+ });
841
+ };
842
+ dragOperation.canceled = (_a = args.canceled) != null ? _a : false;
843
+ this.manager.monitor.dispatch("dragend", {
844
+ nativeEvent: args.event,
845
+ operation: dragOperation.snapshot(),
846
+ canceled: (_b = args.canceled) != null ? _b : false,
847
+ suspend
848
+ });
849
+ if (promise) {
850
+ promise.then(end).catch(() => dragOperation.reset());
851
+ } else {
852
+ end();
853
+ }
854
+ });
855
+ }
856
+ };
857
+ var _disabled_dec2, _data_dec, _id_dec, _manager_dec, _init3, _manager, _id, _data, _disabled2;
858
+ _manager_dec = [reactive], _id_dec = [reactive], _data_dec = [reactive], _disabled_dec2 = [reactive];
859
+ var Entity = class {
860
+ /**
861
+ * Creates a new instance of the `Entity` class.
862
+ *
863
+ * @param input - An object containing the initial properties of the entity.
864
+ * @param manager - The manager that controls the drag and drop operations.
865
+ */
866
+ constructor(input, manager) {
867
+ __privateAdd(this, _manager, __runInitializers(_init3, 8, this)), __runInitializers(_init3, 11, this);
868
+ __privateAdd(this, _id, __runInitializers(_init3, 12, this)), __runInitializers(_init3, 15, this);
869
+ __privateAdd(this, _data, __runInitializers(_init3, 16, this)), __runInitializers(_init3, 19, this);
870
+ __privateAdd(this, _disabled2, __runInitializers(_init3, 20, this)), __runInitializers(_init3, 23, this);
871
+ const { effects: effects6, id, data = {}, disabled = false, register = true } = input;
872
+ let previousId = id;
873
+ this.manager = manager;
874
+ this.id = id;
875
+ this.data = data;
876
+ this.disabled = disabled;
877
+ this.effects = () => {
878
+ var _a;
879
+ return [
880
+ () => {
881
+ const { id: id2, manager: manager2 } = this;
882
+ if (id2 === previousId) {
883
+ return;
884
+ }
885
+ manager2 == null ? void 0 : manager2.registry.register(this);
886
+ return () => manager2 == null ? void 0 : manager2.registry.unregister(this);
887
+ },
888
+ ...(_a = effects6 == null ? void 0 : effects6()) != null ? _a : []
889
+ ];
890
+ };
891
+ this.register = this.register.bind(this);
892
+ this.unregister = this.unregister.bind(this);
893
+ this.destroy = this.destroy.bind(this);
894
+ if (manager && register) {
895
+ queueMicrotask(this.register);
896
+ }
897
+ }
898
+ /**
899
+ * A method that registers the entity with the manager.
900
+ * @returns CleanupFunction | void
901
+ */
902
+ register() {
903
+ var _a;
904
+ return (_a = this.manager) == null ? void 0 : _a.registry.register(this);
905
+ }
906
+ /**
907
+ * A method that unregisters the entity from the manager.
908
+ * @returns void
909
+ */
910
+ unregister() {
911
+ var _a;
912
+ (_a = this.manager) == null ? void 0 : _a.registry.unregister(this);
913
+ }
914
+ /**
915
+ * A method that cleans up the entity when it is no longer needed.
916
+ * @returns void
917
+ */
918
+ destroy() {
919
+ var _a;
920
+ (_a = this.manager) == null ? void 0 : _a.registry.unregister(this);
921
+ }
922
+ };
923
+ _init3 = __decoratorStart(null);
924
+ _manager = new WeakMap();
925
+ _id = new WeakMap();
926
+ _data = new WeakMap();
927
+ _disabled2 = new WeakMap();
928
+ __decorateElement(_init3, 4, "manager", _manager_dec, Entity, _manager);
929
+ __decorateElement(_init3, 4, "id", _id_dec, Entity, _id);
930
+ __decorateElement(_init3, 4, "data", _data_dec, Entity, _data);
931
+ __decorateElement(_init3, 4, "disabled", _disabled_dec2, Entity, _disabled2);
932
+ __decoratorMetadata(_init3, Entity);
933
+ var EntityRegistry = class {
934
+ constructor() {
935
+ this.map = signal(/* @__PURE__ */ new Map());
936
+ this.cleanupFunctions = /* @__PURE__ */ new WeakMap();
937
+ /**
938
+ * Registers a entity in the registry.
939
+ * @param key - The unique identifier of the entity.
940
+ * @param value - The entity to register.
941
+ * @returns A function that unregisters the entity.
942
+ */
943
+ this.register = (key, value) => {
944
+ const current = this.map.peek();
945
+ const currentValue = current.get(key);
946
+ const unregister = () => this.unregister(key, value);
947
+ if (currentValue === value) return unregister;
948
+ if (currentValue) {
949
+ const cleanup2 = this.cleanupFunctions.get(currentValue);
950
+ cleanup2 == null ? void 0 : cleanup2();
951
+ this.cleanupFunctions.delete(currentValue);
952
+ }
953
+ const updatedMap = new Map(current);
954
+ updatedMap.set(key, value);
955
+ this.map.value = updatedMap;
956
+ const cleanup = effects(...value.effects());
957
+ this.cleanupFunctions.set(value, cleanup);
958
+ return unregister;
959
+ };
960
+ /**
961
+ * Unregisters an entity from the registry.
962
+ * @param key - The unique identifier of the entity.
963
+ * @param value - The entity instance to unregister.
964
+ */
965
+ this.unregister = (key, value) => {
966
+ const current = this.map.peek();
967
+ if (current.get(key) !== value) {
968
+ return;
969
+ }
970
+ const cleanup = this.cleanupFunctions.get(value);
971
+ cleanup == null ? void 0 : cleanup();
972
+ this.cleanupFunctions.delete(value);
973
+ const updatedMap = new Map(current);
974
+ updatedMap.delete(key);
975
+ this.map.value = updatedMap;
976
+ };
977
+ }
978
+ /**
979
+ * Iterator for the EntityRegistry class.
980
+ * @returns An iterator for the values in the map.
981
+ */
982
+ [Symbol.iterator]() {
983
+ return this.map.peek().values();
984
+ }
985
+ get value() {
986
+ return this.map.value.values();
987
+ }
988
+ /**
989
+ * Checks if a entity with the given identifier exists in the registry.
990
+ * @param identifier - The unique identifier of the entity.
991
+ * @returns True if the entity exists, false otherwise.
992
+ */
993
+ has(identifier) {
994
+ return this.map.value.has(identifier);
995
+ }
996
+ /**
997
+ * Retrieves a entity from the registry using its identifier.
998
+ * @param identifier - The unique identifier of the entity.
999
+ * @returns The entity if it exists, undefined otherwise.
1000
+ */
1001
+ get(identifier) {
1002
+ return this.map.value.get(identifier);
1003
+ }
1004
+ /**
1005
+ * Destroys all entries in the registry and clears the registry.
1006
+ */
1007
+ destroy() {
1008
+ for (const entry of this) {
1009
+ const cleanup = this.cleanupFunctions.get(entry);
1010
+ cleanup == null ? void 0 : cleanup();
1011
+ entry.destroy();
1012
+ }
1013
+ this.map.value = /* @__PURE__ */ new Map();
1014
+ }
1015
+ };
1016
+ var _isDragSource_dec, _isDragging_dec, _isDropping_dec, _status_dec, _modifiers_dec, _type_dec, _c, _init4, _type, _modifiers, _status;
1017
+ var Draggable = class extends (_c = Entity, _type_dec = [reactive], _modifiers_dec = [reactive], _status_dec = [reactive], _isDropping_dec = [derived], _isDragging_dec = [derived], _isDragSource_dec = [derived], _c) {
1018
+ constructor(_a, manager) {
1019
+ var _b = _a, { modifiers, type, sensors } = _b, input = __objRest(_b, ["modifiers", "type", "sensors"]);
1020
+ super(input, manager);
1021
+ __runInitializers(_init4, 5, this);
1022
+ __privateAdd(this, _type, __runInitializers(_init4, 8, this)), __runInitializers(_init4, 11, this);
1023
+ __privateAdd(this, _modifiers, __runInitializers(_init4, 12, this)), __runInitializers(_init4, 15, this);
1024
+ __privateAdd(this, _status, __runInitializers(_init4, 16, this, this.isDragSource ? "dragging" : "idle")), __runInitializers(_init4, 19, this);
1025
+ this.type = type;
1026
+ this.sensors = sensors;
1027
+ this.modifiers = modifiers;
1028
+ this.alignment = input.alignment;
1029
+ }
1030
+ get isDropping() {
1031
+ return this.status === "dropping" && this.isDragSource;
1032
+ }
1033
+ get isDragging() {
1034
+ return this.status === "dragging" && this.isDragSource;
1035
+ }
1036
+ get isDragSource() {
1037
+ var _a, _b;
1038
+ return ((_b = (_a = this.manager) == null ? void 0 : _a.dragOperation.source) == null ? void 0 : _b.id) === this.id;
1039
+ }
1040
+ };
1041
+ _init4 = __decoratorStart(_c);
1042
+ _type = new WeakMap();
1043
+ _modifiers = new WeakMap();
1044
+ _status = new WeakMap();
1045
+ __decorateElement(_init4, 4, "type", _type_dec, Draggable, _type);
1046
+ __decorateElement(_init4, 4, "modifiers", _modifiers_dec, Draggable, _modifiers);
1047
+ __decorateElement(_init4, 4, "status", _status_dec, Draggable, _status);
1048
+ __decorateElement(_init4, 2, "isDropping", _isDropping_dec, Draggable);
1049
+ __decorateElement(_init4, 2, "isDragging", _isDragging_dec, Draggable);
1050
+ __decorateElement(_init4, 2, "isDragSource", _isDragSource_dec, Draggable);
1051
+ __decoratorMetadata(_init4, Draggable);
1052
+ var _isDropTarget_dec, _shape_dec, _collisionPriority_dec, _collisionDetector_dec, _type_dec2, _accept_dec, _c2, _init5, _accept, _type2, _collisionDetector, _collisionPriority, _shape;
1053
+ var Droppable = class extends (_c2 = Entity, _accept_dec = [reactive], _type_dec2 = [reactive], _collisionDetector_dec = [reactive], _collisionPriority_dec = [reactive], _shape_dec = [reactive], _isDropTarget_dec = [derived], _c2) {
1054
+ constructor(_a, manager) {
1055
+ var _b = _a, { accept, collisionDetector, collisionPriority, type } = _b, input = __objRest(_b, ["accept", "collisionDetector", "collisionPriority", "type"]);
1056
+ super(input, manager);
1057
+ __runInitializers(_init5, 5, this);
1058
+ __privateAdd(this, _accept, __runInitializers(_init5, 8, this)), __runInitializers(_init5, 11, this);
1059
+ __privateAdd(this, _type2, __runInitializers(_init5, 12, this)), __runInitializers(_init5, 15, this);
1060
+ __privateAdd(this, _collisionDetector, __runInitializers(_init5, 16, this)), __runInitializers(_init5, 19, this);
1061
+ __privateAdd(this, _collisionPriority, __runInitializers(_init5, 20, this)), __runInitializers(_init5, 23, this);
1062
+ __privateAdd(this, _shape, __runInitializers(_init5, 24, this)), __runInitializers(_init5, 27, this);
1063
+ this.accept = accept;
1064
+ this.collisionDetector = collisionDetector;
1065
+ this.collisionPriority = collisionPriority;
1066
+ this.type = type;
1067
+ }
1068
+ /**
1069
+ * Checks whether or not the droppable accepts a given draggable.
1070
+ *
1071
+ * @param draggable - The draggable to check
1072
+ * @returns true if the draggable can be dropped here
1073
+ */
1074
+ accepts(draggable) {
1075
+ const { accept } = this;
1076
+ if (!accept) {
1077
+ return true;
1078
+ }
1079
+ if (typeof accept === "function") {
1080
+ return accept(draggable);
1081
+ }
1082
+ if (!draggable.type) {
1083
+ return false;
1084
+ }
1085
+ if (Array.isArray(accept)) {
1086
+ return accept.includes(draggable.type);
1087
+ }
1088
+ return draggable.type === accept;
1089
+ }
1090
+ get isDropTarget() {
1091
+ var _a, _b;
1092
+ return ((_b = (_a = this.manager) == null ? void 0 : _a.dragOperation.target) == null ? void 0 : _b.id) === this.id;
1093
+ }
1094
+ };
1095
+ _init5 = __decoratorStart(_c2);
1096
+ _accept = new WeakMap();
1097
+ _type2 = new WeakMap();
1098
+ _collisionDetector = new WeakMap();
1099
+ _collisionPriority = new WeakMap();
1100
+ _shape = new WeakMap();
1101
+ __decorateElement(_init5, 4, "accept", _accept_dec, Droppable, _accept);
1102
+ __decorateElement(_init5, 4, "type", _type_dec2, Droppable, _type2);
1103
+ __decorateElement(_init5, 4, "collisionDetector", _collisionDetector_dec, Droppable, _collisionDetector);
1104
+ __decorateElement(_init5, 4, "collisionPriority", _collisionPriority_dec, Droppable, _collisionPriority);
1105
+ __decorateElement(_init5, 4, "shape", _shape_dec, Droppable, _shape);
1106
+ __decorateElement(_init5, 2, "isDropTarget", _isDropTarget_dec, Droppable);
1107
+ __decoratorMetadata(_init5, Droppable);
1108
+
1109
+ // src/core/sensors/sensor.ts
1110
+ var Sensor = class extends Plugin {
1111
+ /**
1112
+ * Creates a new sensor instance.
1113
+ *
1114
+ * @param manager - The drag drop manager instance
1115
+ * @param options - Optional sensor configuration
1116
+ */
1117
+ constructor(manager, options) {
1118
+ super(manager, options);
1119
+ this.manager = manager;
1120
+ this.options = options;
1121
+ }
1122
+ };
1123
+
1124
+ // src/core/modifiers/modifier.ts
1125
+ var Modifier = class extends Plugin {
1126
+ /**
1127
+ * Creates a new modifier instance.
1128
+ *
1129
+ * @param manager - The drag and drop manager that owns this modifier
1130
+ * @param options - Optional configuration for the modifier
1131
+ */
1132
+ constructor(manager, options) {
1133
+ super(manager, options);
1134
+ this.manager = manager;
1135
+ this.options = options;
1136
+ }
1137
+ /**
1138
+ * Applies the modifier to the current drag operation.
1139
+ *
1140
+ * @param operation - The current state of the drag operation
1141
+ * @returns The transformed coordinates
1142
+ *
1143
+ * @remarks
1144
+ * Override this method to implement custom transformation logic.
1145
+ * The default implementation returns the original transform unchanged.
1146
+ */
1147
+ apply(operation) {
1148
+ return operation.transform;
1149
+ }
1150
+ };
1151
+
1152
+ // src/core/manager/registry.ts
1153
+ var DragDropRegistry = class {
1154
+ /**
1155
+ * Creates a new registry instance.
1156
+ *
1157
+ * @param manager - The drag and drop manager that owns this registry
1158
+ */
1159
+ constructor(manager) {
1160
+ /** Registry for draggable entities */
1161
+ this.draggables = new EntityRegistry();
1162
+ /** Registry for droppable entities */
1163
+ this.droppables = new EntityRegistry();
1164
+ this.plugins = new PluginRegistry(manager);
1165
+ this.sensors = new PluginRegistry(manager);
1166
+ this.modifiers = new PluginRegistry(manager);
1167
+ }
1168
+ register(input, options) {
1169
+ if (input instanceof Draggable) {
1170
+ return this.draggables.register(input.id, input);
1171
+ }
1172
+ if (input instanceof Droppable) {
1173
+ return this.droppables.register(input.id, input);
1174
+ }
1175
+ if (input.prototype instanceof Modifier) {
1176
+ return this.modifiers.register(input, options);
1177
+ }
1178
+ if (input.prototype instanceof Sensor) {
1179
+ return this.sensors.register(input, options);
1180
+ }
1181
+ if (input.prototype instanceof Plugin) {
1182
+ return this.plugins.register(input, options);
1183
+ }
1184
+ throw new Error("Invalid instance type");
1185
+ }
1186
+ unregister(input) {
1187
+ if (input instanceof Entity) {
1188
+ if (input instanceof Draggable) {
1189
+ return this.draggables.unregister(input.id, input);
1190
+ }
1191
+ if (input instanceof Droppable) {
1192
+ return this.droppables.unregister(input.id, input);
1193
+ }
1194
+ return () => {
1195
+ };
1196
+ }
1197
+ if (input.prototype instanceof Modifier) {
1198
+ return this.modifiers.unregister(input);
1199
+ }
1200
+ if (input.prototype instanceof Sensor) {
1201
+ return this.sensors.unregister(input);
1202
+ }
1203
+ if (input.prototype instanceof Plugin) {
1204
+ return this.plugins.unregister(input);
1205
+ }
1206
+ throw new Error("Invalid instance type");
1207
+ }
1208
+ /**
1209
+ * Destroys all registered entities and cleans up resources.
1210
+ *
1211
+ * @remarks
1212
+ * This method:
1213
+ * - Destroys all draggable and droppable entities
1214
+ * - Destroys all plugins, sensors, and modifiers
1215
+ * - Cleans up any associated resources
1216
+ */
1217
+ destroy() {
1218
+ this.draggables.destroy();
1219
+ this.droppables.destroy();
1220
+ this.plugins.destroy();
1221
+ this.sensors.destroy();
1222
+ this.modifiers.destroy();
1223
+ }
1224
+ };
1225
+ var _transform_dec, _target_dec, _source_dec, _modifiers_dec2, _targetIdentifier_dec, _sourceIdentifier_dec, _activatorEvent_dec, _canceled_dec, _shape_dec2, _manager2, _previousSource, _shape2, _init6, _canceled, _activatorEvent, _sourceIdentifier, _targetIdentifier, _modifiers2, _transform;
1226
+ _shape_dec2 = [derived], _canceled_dec = [reactive], _activatorEvent_dec = [reactive], _sourceIdentifier_dec = [reactive], _targetIdentifier_dec = [reactive], _modifiers_dec2 = [reactive], _source_dec = [derived], _target_dec = [derived], _transform_dec = [derived];
1227
+ var DragOperation = class {
1228
+ /**
1229
+ * Creates a new drag operation instance.
1230
+ *
1231
+ * @param manager - The drag and drop manager that owns this operation
1232
+ */
1233
+ constructor(manager) {
1234
+ __runInitializers(_init6, 5, this);
1235
+ __privateAdd(this, _manager2);
1236
+ __privateAdd(this, _previousSource);
1237
+ __privateAdd(this, _shape2, new ValueHistory(
1238
+ void 0,
1239
+ (a, b) => a && b ? a.equals(b) : a === b
1240
+ ));
1241
+ /** Current status of the drag operation */
1242
+ this.status = new Status();
1243
+ __privateAdd(this, _canceled, __runInitializers(_init6, 8, this, false)), __runInitializers(_init6, 11, this);
1244
+ __privateAdd(this, _activatorEvent, __runInitializers(_init6, 12, this, null)), __runInitializers(_init6, 15, this);
1245
+ __privateAdd(this, _sourceIdentifier, __runInitializers(_init6, 16, this, null)), __runInitializers(_init6, 19, this);
1246
+ __privateAdd(this, _targetIdentifier, __runInitializers(_init6, 20, this, null)), __runInitializers(_init6, 23, this);
1247
+ __privateAdd(this, _modifiers2, __runInitializers(_init6, 24, this, [])), __runInitializers(_init6, 27, this);
1248
+ /** Current position of the dragged entity */
1249
+ this.position = new Position({ x: 0, y: 0 });
1250
+ __privateAdd(this, _transform, { x: 0, y: 0 });
1251
+ __privateSet(this, _manager2, manager);
1252
+ }
1253
+ get shape() {
1254
+ const { current, initial, previous } = __privateGet(this, _shape2);
1255
+ if (!current || !initial) {
1256
+ return null;
1257
+ }
1258
+ return { current, initial, previous };
1259
+ }
1260
+ /**
1261
+ * Sets the shape of the dragged entity.
1262
+ *
1263
+ * @param value - The new shape or null to reset
1264
+ */
1265
+ set shape(value) {
1266
+ if (!value) {
1267
+ __privateGet(this, _shape2).reset();
1268
+ } else {
1269
+ __privateGet(this, _shape2).current = value;
1270
+ }
1271
+ }
1272
+ get source() {
1273
+ var _a;
1274
+ const identifier = this.sourceIdentifier;
1275
+ if (identifier == null) return null;
1276
+ const value = __privateGet(this, _manager2).registry.draggables.get(identifier);
1277
+ if (value) {
1278
+ __privateSet(this, _previousSource, value);
1279
+ }
1280
+ return (_a = value != null ? value : __privateGet(this, _previousSource)) != null ? _a : null;
1281
+ }
1282
+ get target() {
1283
+ var _a;
1284
+ const identifier = this.targetIdentifier;
1285
+ return identifier != null ? (_a = __privateGet(this, _manager2).registry.droppables.get(identifier)) != null ? _a : null : null;
1286
+ }
1287
+ get transform() {
1288
+ const { x, y } = this.position.delta;
1289
+ let transform = { x, y };
1290
+ for (const modifier of this.modifiers) {
1291
+ transform = modifier.apply(__spreadProps(__spreadValues({}, this.snapshot()), {
1292
+ transform
1293
+ }));
1294
+ }
1295
+ __privateSet(this, _transform, transform);
1296
+ return transform;
1297
+ }
1298
+ /**
1299
+ * Creates a snapshot of the current drag operation state.
1300
+ *
1301
+ * @returns An immutable snapshot of the current operation state
1302
+ */
1303
+ snapshot() {
1304
+ return untracked(() => ({
1305
+ source: this.source,
1306
+ target: this.target,
1307
+ activatorEvent: this.activatorEvent,
1308
+ transform: __privateGet(this, _transform),
1309
+ shape: this.shape ? snapshot(this.shape) : null,
1310
+ position: snapshot(this.position),
1311
+ status: snapshot(this.status),
1312
+ canceled: this.canceled
1313
+ }));
1314
+ }
1315
+ /**
1316
+ * Resets the drag operation to its initial state.
1317
+ *
1318
+ * @remarks
1319
+ * This method:
1320
+ * - Sets status to idle
1321
+ * - Clears source and target identifiers
1322
+ * - Resets shape history
1323
+ * - Resets position and transform
1324
+ * - Clears modifiers
1325
+ */
1326
+ reset() {
1327
+ batch(() => {
1328
+ this.status.set("idle" /* Idle */);
1329
+ this.sourceIdentifier = null;
1330
+ this.targetIdentifier = null;
1331
+ __privateGet(this, _shape2).reset();
1332
+ this.position.reset({ x: 0, y: 0 });
1333
+ __privateSet(this, _transform, { x: 0, y: 0 });
1334
+ this.modifiers = [];
1335
+ });
1336
+ }
1337
+ };
1338
+ _init6 = __decoratorStart(null);
1339
+ _manager2 = new WeakMap();
1340
+ _previousSource = new WeakMap();
1341
+ _shape2 = new WeakMap();
1342
+ _canceled = new WeakMap();
1343
+ _activatorEvent = new WeakMap();
1344
+ _sourceIdentifier = new WeakMap();
1345
+ _targetIdentifier = new WeakMap();
1346
+ _modifiers2 = new WeakMap();
1347
+ _transform = new WeakMap();
1348
+ __decorateElement(_init6, 2, "shape", _shape_dec2, DragOperation);
1349
+ __decorateElement(_init6, 4, "canceled", _canceled_dec, DragOperation, _canceled);
1350
+ __decorateElement(_init6, 4, "activatorEvent", _activatorEvent_dec, DragOperation, _activatorEvent);
1351
+ __decorateElement(_init6, 4, "sourceIdentifier", _sourceIdentifier_dec, DragOperation, _sourceIdentifier);
1352
+ __decorateElement(_init6, 4, "targetIdentifier", _targetIdentifier_dec, DragOperation, _targetIdentifier);
1353
+ __decorateElement(_init6, 4, "modifiers", _modifiers_dec2, DragOperation, _modifiers2);
1354
+ __decorateElement(_init6, 2, "source", _source_dec, DragOperation);
1355
+ __decorateElement(_init6, 2, "target", _target_dec, DragOperation);
1356
+ __decorateElement(_init6, 2, "transform", _transform_dec, DragOperation);
1357
+ __decoratorMetadata(_init6, DragOperation);
1358
+
1359
+ // src/core/manager/renderer.ts
1360
+ var defaultRenderer = {
1361
+ get rendering() {
1362
+ return Promise.resolve();
1363
+ }
1364
+ };
1365
+
1366
+ // src/core/manager/manager.ts
1367
+ var DragDropManager = class {
1368
+ /**
1369
+ * Creates a new drag and drop manager instance.
1370
+ *
1371
+ * @param config - Optional configuration for plugins, sensors, modifiers, and renderer
1372
+ */
1373
+ constructor(config) {
1374
+ /**
1375
+ * Cleans up resources and stops any active drag operations.
1376
+ */
1377
+ this.destroy = () => {
1378
+ if (!this.dragOperation.status.idle) {
1379
+ this.actions.stop({ canceled: true });
1380
+ }
1381
+ this.dragOperation.modifiers.forEach((modifier) => modifier.destroy());
1382
+ this.registry.destroy();
1383
+ this.collisionObserver.destroy();
1384
+ };
1385
+ const {
1386
+ plugins = [],
1387
+ sensors = [],
1388
+ modifiers = [],
1389
+ renderer = defaultRenderer
1390
+ } = config != null ? config : {};
1391
+ const monitor = new DragDropMonitor(this);
1392
+ const registry = new DragDropRegistry(this);
1393
+ this.registry = registry;
1394
+ this.monitor = monitor;
1395
+ this.renderer = renderer;
1396
+ this.actions = new DragActions(this);
1397
+ this.dragOperation = new DragOperation(this);
1398
+ this.collisionObserver = new CollisionObserver(this);
1399
+ this.plugins = [CollisionNotifier, ...plugins];
1400
+ this.modifiers = modifiers;
1401
+ this.sensors = sensors;
1402
+ const { destroy } = this;
1403
+ const cleanup = effects(() => {
1404
+ var _a, _b, _c3;
1405
+ const currentModifiers = untracked(() => this.dragOperation.modifiers);
1406
+ const managerModifiers = this.modifiers;
1407
+ if (currentModifiers !== managerModifiers) {
1408
+ currentModifiers.forEach((modifier) => modifier.destroy());
1409
+ }
1410
+ this.dragOperation.modifiers = (_c3 = (_b = (_a = this.dragOperation.source) == null ? void 0 : _a.modifiers) == null ? void 0 : _b.map((modifier) => {
1411
+ const { plugin, options } = descriptor(modifier);
1412
+ return new plugin(this, options);
1413
+ })) != null ? _c3 : managerModifiers;
1414
+ });
1415
+ this.destroy = () => {
1416
+ cleanup();
1417
+ destroy();
1418
+ };
1419
+ }
1420
+ /**
1421
+ * Gets the list of active plugins.
1422
+ *
1423
+ * @returns Array of active plugin instances
1424
+ */
1425
+ get plugins() {
1426
+ return this.registry.plugins.values;
1427
+ }
1428
+ /**
1429
+ * Sets the list of plugins to be used by the manager.
1430
+ *
1431
+ * @param plugins - Array of plugin constructors or instances
1432
+ */
1433
+ set plugins(plugins) {
1434
+ this.registry.plugins.values = plugins;
1435
+ }
1436
+ /**
1437
+ * Gets the list of active modifiers.
1438
+ *
1439
+ * @returns Array of active modifier instances
1440
+ */
1441
+ get modifiers() {
1442
+ return this.registry.modifiers.values;
1443
+ }
1444
+ /**
1445
+ * Sets the list of modifiers to be used by the manager.
1446
+ *
1447
+ * @param modifiers - Array of modifier constructors or instances
1448
+ */
1449
+ set modifiers(modifiers) {
1450
+ this.registry.modifiers.values = modifiers;
1451
+ }
1452
+ /**
1453
+ * Gets the list of active sensors.
1454
+ *
1455
+ * @returns Array of active sensor instances
1456
+ */
1457
+ get sensors() {
1458
+ return this.registry.sensors.values;
1459
+ }
1460
+ /**
1461
+ * Sets the list of sensors to be used by the manager.
1462
+ *
1463
+ * @param sensors - Array of sensor constructors or instances
1464
+ */
1465
+ set sensors(sensors) {
1466
+ this.registry.sensors.values = sensors;
1467
+ }
1468
+ };
1469
+
1470
+ export { CollisionPriority, CollisionType, CorePlugin, DragDropManager, Status as DragOperationStatus, Draggable, Droppable, Modifier, Plugin, PluginRegistry, Sensor, configurator, configure, descriptor, sortCollisions };
1471
+ //# sourceMappingURL=index.js.map
1472
+ //# sourceMappingURL=index.js.map