@blcklab/freedom 0.1.1 → 0.1.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.
- package/dist/index.cjs +60 -53
- package/dist/index.js +60 -53
- package/dist/manager.cjs +11 -7
- package/dist/manager.js +11 -7
- package/dist/snap.cjs +3 -4
- package/dist/snap.js +3 -4
- package/dist/window.cjs +60 -53
- package/dist/window.js +60 -53
- package/package.json +11 -5
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/manager.cjs.map +0 -1
- package/dist/manager.js.map +0 -1
- package/dist/snap.cjs.map +0 -1
- package/dist/snap.js.map +0 -1
- package/dist/window.cjs.map +0 -1
- package/dist/window.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
// src/core/events.ts
|
|
6
6
|
var Emitter = class {
|
|
7
|
-
|
|
7
|
+
constructor() {
|
|
8
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
9
|
+
}
|
|
8
10
|
on(event, handler) {
|
|
9
11
|
let set = this.listeners.get(event);
|
|
10
12
|
if (!set) {
|
|
@@ -15,7 +17,8 @@ var Emitter = class {
|
|
|
15
17
|
return () => this.off(event, handler);
|
|
16
18
|
}
|
|
17
19
|
off(event, handler) {
|
|
18
|
-
|
|
20
|
+
var _a;
|
|
21
|
+
(_a = this.listeners.get(event)) == null ? void 0 : _a.delete(handler);
|
|
19
22
|
}
|
|
20
23
|
emit(event, data) {
|
|
21
24
|
const set = this.listeners.get(event);
|
|
@@ -181,12 +184,42 @@ function toPoint(event) {
|
|
|
181
184
|
return { x: event.clientX, y: event.clientY };
|
|
182
185
|
}
|
|
183
186
|
var InteractionManager = class {
|
|
184
|
-
options;
|
|
185
|
-
activePointerId = null;
|
|
186
|
-
captureTarget = null;
|
|
187
|
-
_active = null;
|
|
188
|
-
destroyed = false;
|
|
189
187
|
constructor(options) {
|
|
188
|
+
this.activePointerId = null;
|
|
189
|
+
this.captureTarget = null;
|
|
190
|
+
this._active = null;
|
|
191
|
+
this.destroyed = false;
|
|
192
|
+
this.handlePointerDown = (event) => {
|
|
193
|
+
if (this.destroyed || this._active !== null) return;
|
|
194
|
+
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
195
|
+
const resizeHandle = this.options.resolveResizeHandle(event.target);
|
|
196
|
+
if (resizeHandle) {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
event.stopPropagation();
|
|
199
|
+
this.startResize(resizeHandle, event);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.options.isDragTarget(event.target)) {
|
|
203
|
+
this.startDrag(event);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
this.handlePointerMove = (event) => {
|
|
207
|
+
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
208
|
+
if (this._active === "drag") {
|
|
209
|
+
this.options.onDragMove(this.options.dragEngine.move(toPoint(event), event));
|
|
210
|
+
} else if (this._active === "resize") {
|
|
211
|
+
this.options.onResizeMove(this.options.resizeEngine.move(toPoint(event), event));
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
this.handlePointerUp = (event) => {
|
|
215
|
+
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
216
|
+
if (this._active === "drag") {
|
|
217
|
+
this.options.onDragEnd(this.options.dragEngine.end(toPoint(event), event));
|
|
218
|
+
} else if (this._active === "resize") {
|
|
219
|
+
this.options.onResizeEnd(this.options.resizeEngine.end(toPoint(event), event));
|
|
220
|
+
}
|
|
221
|
+
this.teardown();
|
|
222
|
+
};
|
|
190
223
|
this.options = options;
|
|
191
224
|
this.options.element.addEventListener("pointerdown", this.handlePointerDown);
|
|
192
225
|
}
|
|
@@ -217,10 +250,11 @@ var InteractionManager = class {
|
|
|
217
250
|
this.teardown();
|
|
218
251
|
}
|
|
219
252
|
captureGesture(event) {
|
|
253
|
+
var _a, _b;
|
|
220
254
|
this.activePointerId = event.pointerId;
|
|
221
255
|
this.captureTarget = event.target instanceof Element ? event.target : this.options.element;
|
|
222
256
|
try {
|
|
223
|
-
this.captureTarget.setPointerCapture
|
|
257
|
+
(_b = (_a = this.captureTarget).setPointerCapture) == null ? void 0 : _b.call(_a, event.pointerId);
|
|
224
258
|
} catch {
|
|
225
259
|
}
|
|
226
260
|
window.addEventListener("pointermove", this.handlePointerMove);
|
|
@@ -228,9 +262,10 @@ var InteractionManager = class {
|
|
|
228
262
|
window.addEventListener("pointercancel", this.handlePointerUp);
|
|
229
263
|
}
|
|
230
264
|
teardown() {
|
|
265
|
+
var _a, _b;
|
|
231
266
|
if (this.activePointerId !== null && this.captureTarget) {
|
|
232
267
|
try {
|
|
233
|
-
this.captureTarget.releasePointerCapture
|
|
268
|
+
(_b = (_a = this.captureTarget).releasePointerCapture) == null ? void 0 : _b.call(_a, this.activePointerId);
|
|
234
269
|
} catch {
|
|
235
270
|
}
|
|
236
271
|
}
|
|
@@ -241,37 +276,6 @@ var InteractionManager = class {
|
|
|
241
276
|
window.removeEventListener("pointerup", this.handlePointerUp);
|
|
242
277
|
window.removeEventListener("pointercancel", this.handlePointerUp);
|
|
243
278
|
}
|
|
244
|
-
handlePointerDown = (event) => {
|
|
245
|
-
if (this.destroyed || this._active !== null) return;
|
|
246
|
-
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
247
|
-
const resizeHandle = this.options.resolveResizeHandle(event.target);
|
|
248
|
-
if (resizeHandle) {
|
|
249
|
-
event.preventDefault();
|
|
250
|
-
event.stopPropagation();
|
|
251
|
-
this.startResize(resizeHandle, event);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
if (this.options.isDragTarget(event.target)) {
|
|
255
|
-
this.startDrag(event);
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
handlePointerMove = (event) => {
|
|
259
|
-
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
260
|
-
if (this._active === "drag") {
|
|
261
|
-
this.options.onDragMove(this.options.dragEngine.move(toPoint(event), event));
|
|
262
|
-
} else if (this._active === "resize") {
|
|
263
|
-
this.options.onResizeMove(this.options.resizeEngine.move(toPoint(event), event));
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
handlePointerUp = (event) => {
|
|
267
|
-
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
268
|
-
if (this._active === "drag") {
|
|
269
|
-
this.options.onDragEnd(this.options.dragEngine.end(toPoint(event), event));
|
|
270
|
-
} else if (this._active === "resize") {
|
|
271
|
-
this.options.onResizeEnd(this.options.resizeEngine.end(toPoint(event), event));
|
|
272
|
-
}
|
|
273
|
-
this.teardown();
|
|
274
|
-
};
|
|
275
279
|
};
|
|
276
280
|
function createInteractionManager(options) {
|
|
277
281
|
return new InteractionManager(options);
|
|
@@ -279,8 +283,9 @@ function createInteractionManager(options) {
|
|
|
279
283
|
|
|
280
284
|
// src/dom/render.ts
|
|
281
285
|
function applyBaseStyles(element, options) {
|
|
286
|
+
var _a, _b;
|
|
282
287
|
const style = element.style;
|
|
283
|
-
const computedPosition = window.getComputedStyle
|
|
288
|
+
const computedPosition = (_b = (_a = window.getComputedStyle) == null ? void 0 : _a.call(window, element).position) != null ? _b : style.position;
|
|
284
289
|
if (options.forcePositioning || computedPosition === "static") {
|
|
285
290
|
style.position = options.positioning;
|
|
286
291
|
}
|
|
@@ -405,6 +410,7 @@ var ALL_HANDLES = ["n", "s", "e", "w", "nw", "ne", "sw", "se"];
|
|
|
405
410
|
var instances = /* @__PURE__ */ new WeakMap();
|
|
406
411
|
var autoId = 0;
|
|
407
412
|
function createWindow(element, options = {}) {
|
|
413
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
408
414
|
if (typeof document === "undefined" || typeof window === "undefined") {
|
|
409
415
|
throw new Error("freedom.window() requires a browser environment. Importing is SSR-safe, but creating a window must run in the browser.");
|
|
410
416
|
}
|
|
@@ -412,21 +418,21 @@ function createWindow(element, options = {}) {
|
|
|
412
418
|
if (instances.has(element)) {
|
|
413
419
|
throw new Error("freedom.window() was called more than once for the same element. Destroy the existing instance before creating a new one.");
|
|
414
420
|
}
|
|
415
|
-
const id = options.id
|
|
421
|
+
const id = (_a = options.id) != null ? _a : `freedom-window-${++autoId}`;
|
|
416
422
|
const emitter = new Emitter();
|
|
417
|
-
const plugins = options.plugins
|
|
423
|
+
const plugins = (_b = options.plugins) != null ? _b : [];
|
|
418
424
|
const limits = normalizeSizeLimits(options);
|
|
419
425
|
const positioning = resolvePositioning(element, options);
|
|
420
426
|
applyBaseStyles(element, {
|
|
421
427
|
positioning,
|
|
422
428
|
forcePositioning: shouldForcePositioning(element, options)
|
|
423
429
|
});
|
|
424
|
-
let size = clampSize(sanitizeSize(options.initialSize
|
|
430
|
+
let size = clampSize(sanitizeSize((_c = options.initialSize) != null ? _c : readInitialSize(element), "initialSize"), limits);
|
|
425
431
|
let position = resolveInitialPosition(options.initialPosition, element, size, options.bounds, positioning);
|
|
426
432
|
const renderer = createPositionRenderer(element, positioning, position);
|
|
427
|
-
let zIndex = normalizeZIndex(options.zIndex
|
|
433
|
+
let zIndex = normalizeZIndex((_d = options.zIndex) != null ? _d : 0);
|
|
428
434
|
let focused = false;
|
|
429
|
-
let isDraggable = options.draggable
|
|
435
|
+
let isDraggable = (_e = options.draggable) != null ? _e : true;
|
|
430
436
|
let isDestroyed = false;
|
|
431
437
|
writeSize(element, size);
|
|
432
438
|
writePosition(element, position, renderer);
|
|
@@ -546,7 +552,7 @@ function createWindow(element, options = {}) {
|
|
|
546
552
|
emitter.emit("resizeend", data);
|
|
547
553
|
}
|
|
548
554
|
});
|
|
549
|
-
const initialResizeHandles = resolveEnabledHandles(options.resizable
|
|
555
|
+
const initialResizeHandles = resolveEnabledHandles((_f = options.resizable) != null ? _f : true);
|
|
550
556
|
if (initialResizeHandles.length > 0) setupResizeHandles(initialResizeHandles);
|
|
551
557
|
const api = {
|
|
552
558
|
id,
|
|
@@ -570,20 +576,22 @@ function createWindow(element, options = {}) {
|
|
|
570
576
|
paint(void 0, size);
|
|
571
577
|
},
|
|
572
578
|
focus() {
|
|
579
|
+
var _a2;
|
|
573
580
|
assertAlive("focus");
|
|
574
581
|
if (focused) return;
|
|
575
582
|
focused = true;
|
|
576
583
|
element.classList.add("freedom-focused");
|
|
577
584
|
emitter.emit("focus", void 0);
|
|
578
|
-
options.onFocus
|
|
585
|
+
(_a2 = options.onFocus) == null ? void 0 : _a2.call(options);
|
|
579
586
|
},
|
|
580
587
|
blur() {
|
|
588
|
+
var _a2;
|
|
581
589
|
assertAlive("blur");
|
|
582
590
|
if (!focused) return;
|
|
583
591
|
focused = false;
|
|
584
592
|
element.classList.remove("freedom-focused");
|
|
585
593
|
emitter.emit("blur", void 0);
|
|
586
|
-
options.onBlur
|
|
594
|
+
(_a2 = options.onBlur) == null ? void 0 : _a2.call(options);
|
|
587
595
|
},
|
|
588
596
|
isFocused() {
|
|
589
597
|
assertAlive("isFocused");
|
|
@@ -623,13 +631,14 @@ function createWindow(element, options = {}) {
|
|
|
623
631
|
teardownResizeHandles();
|
|
624
632
|
},
|
|
625
633
|
destroy() {
|
|
634
|
+
var _a2;
|
|
626
635
|
if (isDestroyed) return;
|
|
627
636
|
isDestroyed = true;
|
|
628
637
|
interactionManager.destroy();
|
|
629
638
|
teardownResizeHandles();
|
|
630
639
|
scheduler.cancel();
|
|
631
640
|
element.classList.remove("freedom-dragging", "freedom-resizing", "freedom-focused");
|
|
632
|
-
for (const plugin of plugins) plugin.onDestroy
|
|
641
|
+
for (const plugin of plugins) (_a2 = plugin.onDestroy) == null ? void 0 : _a2.call(plugin, pluginContext);
|
|
633
642
|
emitter.emit("destroy", void 0);
|
|
634
643
|
emitter.clear();
|
|
635
644
|
instances.delete(element);
|
|
@@ -646,7 +655,7 @@ function createWindow(element, options = {}) {
|
|
|
646
655
|
if (options.onResizeStart) api.on("resizestart", options.onResizeStart);
|
|
647
656
|
if (options.onResize) api.on("resize", options.onResize);
|
|
648
657
|
if (options.onResizeEnd) api.on("resizeend", options.onResizeEnd);
|
|
649
|
-
for (const plugin of plugins) plugin.onInit
|
|
658
|
+
for (const plugin of plugins) (_g = plugin.onInit) == null ? void 0 : _g.call(plugin, pluginContext);
|
|
650
659
|
return api;
|
|
651
660
|
}
|
|
652
661
|
function assertHTMLElement(element) {
|
|
@@ -794,5 +803,3 @@ exports.createWindow = createWindow;
|
|
|
794
803
|
exports.default = src_default;
|
|
795
804
|
exports.freedom = freedom;
|
|
796
805
|
exports.window = createWindow;
|
|
797
|
-
//# sourceMappingURL=index.cjs.map
|
|
798
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/core/events.ts
|
|
2
2
|
var Emitter = class {
|
|
3
|
-
|
|
3
|
+
constructor() {
|
|
4
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
5
|
+
}
|
|
4
6
|
on(event, handler) {
|
|
5
7
|
let set = this.listeners.get(event);
|
|
6
8
|
if (!set) {
|
|
@@ -11,7 +13,8 @@ var Emitter = class {
|
|
|
11
13
|
return () => this.off(event, handler);
|
|
12
14
|
}
|
|
13
15
|
off(event, handler) {
|
|
14
|
-
|
|
16
|
+
var _a;
|
|
17
|
+
(_a = this.listeners.get(event)) == null ? void 0 : _a.delete(handler);
|
|
15
18
|
}
|
|
16
19
|
emit(event, data) {
|
|
17
20
|
const set = this.listeners.get(event);
|
|
@@ -177,12 +180,42 @@ function toPoint(event) {
|
|
|
177
180
|
return { x: event.clientX, y: event.clientY };
|
|
178
181
|
}
|
|
179
182
|
var InteractionManager = class {
|
|
180
|
-
options;
|
|
181
|
-
activePointerId = null;
|
|
182
|
-
captureTarget = null;
|
|
183
|
-
_active = null;
|
|
184
|
-
destroyed = false;
|
|
185
183
|
constructor(options) {
|
|
184
|
+
this.activePointerId = null;
|
|
185
|
+
this.captureTarget = null;
|
|
186
|
+
this._active = null;
|
|
187
|
+
this.destroyed = false;
|
|
188
|
+
this.handlePointerDown = (event) => {
|
|
189
|
+
if (this.destroyed || this._active !== null) return;
|
|
190
|
+
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
191
|
+
const resizeHandle = this.options.resolveResizeHandle(event.target);
|
|
192
|
+
if (resizeHandle) {
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
event.stopPropagation();
|
|
195
|
+
this.startResize(resizeHandle, event);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (this.options.isDragTarget(event.target)) {
|
|
199
|
+
this.startDrag(event);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
this.handlePointerMove = (event) => {
|
|
203
|
+
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
204
|
+
if (this._active === "drag") {
|
|
205
|
+
this.options.onDragMove(this.options.dragEngine.move(toPoint(event), event));
|
|
206
|
+
} else if (this._active === "resize") {
|
|
207
|
+
this.options.onResizeMove(this.options.resizeEngine.move(toPoint(event), event));
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
this.handlePointerUp = (event) => {
|
|
211
|
+
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
212
|
+
if (this._active === "drag") {
|
|
213
|
+
this.options.onDragEnd(this.options.dragEngine.end(toPoint(event), event));
|
|
214
|
+
} else if (this._active === "resize") {
|
|
215
|
+
this.options.onResizeEnd(this.options.resizeEngine.end(toPoint(event), event));
|
|
216
|
+
}
|
|
217
|
+
this.teardown();
|
|
218
|
+
};
|
|
186
219
|
this.options = options;
|
|
187
220
|
this.options.element.addEventListener("pointerdown", this.handlePointerDown);
|
|
188
221
|
}
|
|
@@ -213,10 +246,11 @@ var InteractionManager = class {
|
|
|
213
246
|
this.teardown();
|
|
214
247
|
}
|
|
215
248
|
captureGesture(event) {
|
|
249
|
+
var _a, _b;
|
|
216
250
|
this.activePointerId = event.pointerId;
|
|
217
251
|
this.captureTarget = event.target instanceof Element ? event.target : this.options.element;
|
|
218
252
|
try {
|
|
219
|
-
this.captureTarget.setPointerCapture
|
|
253
|
+
(_b = (_a = this.captureTarget).setPointerCapture) == null ? void 0 : _b.call(_a, event.pointerId);
|
|
220
254
|
} catch {
|
|
221
255
|
}
|
|
222
256
|
window.addEventListener("pointermove", this.handlePointerMove);
|
|
@@ -224,9 +258,10 @@ var InteractionManager = class {
|
|
|
224
258
|
window.addEventListener("pointercancel", this.handlePointerUp);
|
|
225
259
|
}
|
|
226
260
|
teardown() {
|
|
261
|
+
var _a, _b;
|
|
227
262
|
if (this.activePointerId !== null && this.captureTarget) {
|
|
228
263
|
try {
|
|
229
|
-
this.captureTarget.releasePointerCapture
|
|
264
|
+
(_b = (_a = this.captureTarget).releasePointerCapture) == null ? void 0 : _b.call(_a, this.activePointerId);
|
|
230
265
|
} catch {
|
|
231
266
|
}
|
|
232
267
|
}
|
|
@@ -237,37 +272,6 @@ var InteractionManager = class {
|
|
|
237
272
|
window.removeEventListener("pointerup", this.handlePointerUp);
|
|
238
273
|
window.removeEventListener("pointercancel", this.handlePointerUp);
|
|
239
274
|
}
|
|
240
|
-
handlePointerDown = (event) => {
|
|
241
|
-
if (this.destroyed || this._active !== null) return;
|
|
242
|
-
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
243
|
-
const resizeHandle = this.options.resolveResizeHandle(event.target);
|
|
244
|
-
if (resizeHandle) {
|
|
245
|
-
event.preventDefault();
|
|
246
|
-
event.stopPropagation();
|
|
247
|
-
this.startResize(resizeHandle, event);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
if (this.options.isDragTarget(event.target)) {
|
|
251
|
-
this.startDrag(event);
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
handlePointerMove = (event) => {
|
|
255
|
-
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
256
|
-
if (this._active === "drag") {
|
|
257
|
-
this.options.onDragMove(this.options.dragEngine.move(toPoint(event), event));
|
|
258
|
-
} else if (this._active === "resize") {
|
|
259
|
-
this.options.onResizeMove(this.options.resizeEngine.move(toPoint(event), event));
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
handlePointerUp = (event) => {
|
|
263
|
-
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
264
|
-
if (this._active === "drag") {
|
|
265
|
-
this.options.onDragEnd(this.options.dragEngine.end(toPoint(event), event));
|
|
266
|
-
} else if (this._active === "resize") {
|
|
267
|
-
this.options.onResizeEnd(this.options.resizeEngine.end(toPoint(event), event));
|
|
268
|
-
}
|
|
269
|
-
this.teardown();
|
|
270
|
-
};
|
|
271
275
|
};
|
|
272
276
|
function createInteractionManager(options) {
|
|
273
277
|
return new InteractionManager(options);
|
|
@@ -275,8 +279,9 @@ function createInteractionManager(options) {
|
|
|
275
279
|
|
|
276
280
|
// src/dom/render.ts
|
|
277
281
|
function applyBaseStyles(element, options) {
|
|
282
|
+
var _a, _b;
|
|
278
283
|
const style = element.style;
|
|
279
|
-
const computedPosition = window.getComputedStyle
|
|
284
|
+
const computedPosition = (_b = (_a = window.getComputedStyle) == null ? void 0 : _a.call(window, element).position) != null ? _b : style.position;
|
|
280
285
|
if (options.forcePositioning || computedPosition === "static") {
|
|
281
286
|
style.position = options.positioning;
|
|
282
287
|
}
|
|
@@ -401,6 +406,7 @@ var ALL_HANDLES = ["n", "s", "e", "w", "nw", "ne", "sw", "se"];
|
|
|
401
406
|
var instances = /* @__PURE__ */ new WeakMap();
|
|
402
407
|
var autoId = 0;
|
|
403
408
|
function createWindow(element, options = {}) {
|
|
409
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
404
410
|
if (typeof document === "undefined" || typeof window === "undefined") {
|
|
405
411
|
throw new Error("freedom.window() requires a browser environment. Importing is SSR-safe, but creating a window must run in the browser.");
|
|
406
412
|
}
|
|
@@ -408,21 +414,21 @@ function createWindow(element, options = {}) {
|
|
|
408
414
|
if (instances.has(element)) {
|
|
409
415
|
throw new Error("freedom.window() was called more than once for the same element. Destroy the existing instance before creating a new one.");
|
|
410
416
|
}
|
|
411
|
-
const id = options.id
|
|
417
|
+
const id = (_a = options.id) != null ? _a : `freedom-window-${++autoId}`;
|
|
412
418
|
const emitter = new Emitter();
|
|
413
|
-
const plugins = options.plugins
|
|
419
|
+
const plugins = (_b = options.plugins) != null ? _b : [];
|
|
414
420
|
const limits = normalizeSizeLimits(options);
|
|
415
421
|
const positioning = resolvePositioning(element, options);
|
|
416
422
|
applyBaseStyles(element, {
|
|
417
423
|
positioning,
|
|
418
424
|
forcePositioning: shouldForcePositioning(element, options)
|
|
419
425
|
});
|
|
420
|
-
let size = clampSize(sanitizeSize(options.initialSize
|
|
426
|
+
let size = clampSize(sanitizeSize((_c = options.initialSize) != null ? _c : readInitialSize(element), "initialSize"), limits);
|
|
421
427
|
let position = resolveInitialPosition(options.initialPosition, element, size, options.bounds, positioning);
|
|
422
428
|
const renderer = createPositionRenderer(element, positioning, position);
|
|
423
|
-
let zIndex = normalizeZIndex(options.zIndex
|
|
429
|
+
let zIndex = normalizeZIndex((_d = options.zIndex) != null ? _d : 0);
|
|
424
430
|
let focused = false;
|
|
425
|
-
let isDraggable = options.draggable
|
|
431
|
+
let isDraggable = (_e = options.draggable) != null ? _e : true;
|
|
426
432
|
let isDestroyed = false;
|
|
427
433
|
writeSize(element, size);
|
|
428
434
|
writePosition(element, position, renderer);
|
|
@@ -542,7 +548,7 @@ function createWindow(element, options = {}) {
|
|
|
542
548
|
emitter.emit("resizeend", data);
|
|
543
549
|
}
|
|
544
550
|
});
|
|
545
|
-
const initialResizeHandles = resolveEnabledHandles(options.resizable
|
|
551
|
+
const initialResizeHandles = resolveEnabledHandles((_f = options.resizable) != null ? _f : true);
|
|
546
552
|
if (initialResizeHandles.length > 0) setupResizeHandles(initialResizeHandles);
|
|
547
553
|
const api = {
|
|
548
554
|
id,
|
|
@@ -566,20 +572,22 @@ function createWindow(element, options = {}) {
|
|
|
566
572
|
paint(void 0, size);
|
|
567
573
|
},
|
|
568
574
|
focus() {
|
|
575
|
+
var _a2;
|
|
569
576
|
assertAlive("focus");
|
|
570
577
|
if (focused) return;
|
|
571
578
|
focused = true;
|
|
572
579
|
element.classList.add("freedom-focused");
|
|
573
580
|
emitter.emit("focus", void 0);
|
|
574
|
-
options.onFocus
|
|
581
|
+
(_a2 = options.onFocus) == null ? void 0 : _a2.call(options);
|
|
575
582
|
},
|
|
576
583
|
blur() {
|
|
584
|
+
var _a2;
|
|
577
585
|
assertAlive("blur");
|
|
578
586
|
if (!focused) return;
|
|
579
587
|
focused = false;
|
|
580
588
|
element.classList.remove("freedom-focused");
|
|
581
589
|
emitter.emit("blur", void 0);
|
|
582
|
-
options.onBlur
|
|
590
|
+
(_a2 = options.onBlur) == null ? void 0 : _a2.call(options);
|
|
583
591
|
},
|
|
584
592
|
isFocused() {
|
|
585
593
|
assertAlive("isFocused");
|
|
@@ -619,13 +627,14 @@ function createWindow(element, options = {}) {
|
|
|
619
627
|
teardownResizeHandles();
|
|
620
628
|
},
|
|
621
629
|
destroy() {
|
|
630
|
+
var _a2;
|
|
622
631
|
if (isDestroyed) return;
|
|
623
632
|
isDestroyed = true;
|
|
624
633
|
interactionManager.destroy();
|
|
625
634
|
teardownResizeHandles();
|
|
626
635
|
scheduler.cancel();
|
|
627
636
|
element.classList.remove("freedom-dragging", "freedom-resizing", "freedom-focused");
|
|
628
|
-
for (const plugin of plugins) plugin.onDestroy
|
|
637
|
+
for (const plugin of plugins) (_a2 = plugin.onDestroy) == null ? void 0 : _a2.call(plugin, pluginContext);
|
|
629
638
|
emitter.emit("destroy", void 0);
|
|
630
639
|
emitter.clear();
|
|
631
640
|
instances.delete(element);
|
|
@@ -642,7 +651,7 @@ function createWindow(element, options = {}) {
|
|
|
642
651
|
if (options.onResizeStart) api.on("resizestart", options.onResizeStart);
|
|
643
652
|
if (options.onResize) api.on("resize", options.onResize);
|
|
644
653
|
if (options.onResizeEnd) api.on("resizeend", options.onResizeEnd);
|
|
645
|
-
for (const plugin of plugins) plugin.onInit
|
|
654
|
+
for (const plugin of plugins) (_g = plugin.onInit) == null ? void 0 : _g.call(plugin, pluginContext);
|
|
646
655
|
return api;
|
|
647
656
|
}
|
|
648
657
|
function assertHTMLElement(element) {
|
|
@@ -787,5 +796,3 @@ var freedom = {
|
|
|
787
796
|
var src_default = freedom;
|
|
788
797
|
|
|
789
798
|
export { createWindow, src_default as default, freedom, createWindow as window };
|
|
790
|
-
//# sourceMappingURL=index.js.map
|
|
791
|
-
//# sourceMappingURL=index.js.map
|
package/dist/manager.cjs
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
// src/core/events.ts
|
|
4
4
|
var Emitter = class {
|
|
5
|
-
|
|
5
|
+
constructor() {
|
|
6
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
7
|
+
}
|
|
6
8
|
on(event, handler) {
|
|
7
9
|
let set = this.listeners.get(event);
|
|
8
10
|
if (!set) {
|
|
@@ -13,7 +15,8 @@ var Emitter = class {
|
|
|
13
15
|
return () => this.off(event, handler);
|
|
14
16
|
}
|
|
15
17
|
off(event, handler) {
|
|
16
|
-
|
|
18
|
+
var _a;
|
|
19
|
+
(_a = this.listeners.get(event)) == null ? void 0 : _a.delete(handler);
|
|
17
20
|
}
|
|
18
21
|
emit(event, data) {
|
|
19
22
|
const set = this.listeners.get(event);
|
|
@@ -29,7 +32,8 @@ var Emitter = class {
|
|
|
29
32
|
|
|
30
33
|
// src/manager/manager.ts
|
|
31
34
|
function createManager(options = {}) {
|
|
32
|
-
|
|
35
|
+
var _a;
|
|
36
|
+
const baseZIndex = (_a = options.baseZIndex) != null ? _a : 1;
|
|
33
37
|
const windows = [];
|
|
34
38
|
const unsubscribeDestroy = /* @__PURE__ */ new Map();
|
|
35
39
|
const emitter = new Emitter();
|
|
@@ -45,10 +49,11 @@ function createManager(options = {}) {
|
|
|
45
49
|
emitter.emit("register", win);
|
|
46
50
|
}
|
|
47
51
|
function unregister(win) {
|
|
52
|
+
var _a2;
|
|
48
53
|
const index = windows.indexOf(win);
|
|
49
54
|
if (index === -1) return;
|
|
50
55
|
windows.splice(index, 1);
|
|
51
|
-
unsubscribeDestroy.get(win)
|
|
56
|
+
(_a2 = unsubscribeDestroy.get(win)) == null ? void 0 : _a2();
|
|
52
57
|
unsubscribeDestroy.delete(win);
|
|
53
58
|
if (focused === win) {
|
|
54
59
|
focused = null;
|
|
@@ -70,7 +75,8 @@ function createManager(options = {}) {
|
|
|
70
75
|
emitter.emit("focus", win);
|
|
71
76
|
}
|
|
72
77
|
function destroy() {
|
|
73
|
-
|
|
78
|
+
var _a2;
|
|
79
|
+
for (const win of windows) (_a2 = unsubscribeDestroy.get(win)) == null ? void 0 : _a2();
|
|
74
80
|
windows.length = 0;
|
|
75
81
|
unsubscribeDestroy.clear();
|
|
76
82
|
focused = null;
|
|
@@ -90,5 +96,3 @@ function createManager(options = {}) {
|
|
|
90
96
|
|
|
91
97
|
exports.createManager = createManager;
|
|
92
98
|
exports.manager = createManager;
|
|
93
|
-
//# sourceMappingURL=manager.cjs.map
|
|
94
|
-
//# sourceMappingURL=manager.cjs.map
|
package/dist/manager.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/core/events.ts
|
|
2
2
|
var Emitter = class {
|
|
3
|
-
|
|
3
|
+
constructor() {
|
|
4
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
5
|
+
}
|
|
4
6
|
on(event, handler) {
|
|
5
7
|
let set = this.listeners.get(event);
|
|
6
8
|
if (!set) {
|
|
@@ -11,7 +13,8 @@ var Emitter = class {
|
|
|
11
13
|
return () => this.off(event, handler);
|
|
12
14
|
}
|
|
13
15
|
off(event, handler) {
|
|
14
|
-
|
|
16
|
+
var _a;
|
|
17
|
+
(_a = this.listeners.get(event)) == null ? void 0 : _a.delete(handler);
|
|
15
18
|
}
|
|
16
19
|
emit(event, data) {
|
|
17
20
|
const set = this.listeners.get(event);
|
|
@@ -27,7 +30,8 @@ var Emitter = class {
|
|
|
27
30
|
|
|
28
31
|
// src/manager/manager.ts
|
|
29
32
|
function createManager(options = {}) {
|
|
30
|
-
|
|
33
|
+
var _a;
|
|
34
|
+
const baseZIndex = (_a = options.baseZIndex) != null ? _a : 1;
|
|
31
35
|
const windows = [];
|
|
32
36
|
const unsubscribeDestroy = /* @__PURE__ */ new Map();
|
|
33
37
|
const emitter = new Emitter();
|
|
@@ -43,10 +47,11 @@ function createManager(options = {}) {
|
|
|
43
47
|
emitter.emit("register", win);
|
|
44
48
|
}
|
|
45
49
|
function unregister(win) {
|
|
50
|
+
var _a2;
|
|
46
51
|
const index = windows.indexOf(win);
|
|
47
52
|
if (index === -1) return;
|
|
48
53
|
windows.splice(index, 1);
|
|
49
|
-
unsubscribeDestroy.get(win)
|
|
54
|
+
(_a2 = unsubscribeDestroy.get(win)) == null ? void 0 : _a2();
|
|
50
55
|
unsubscribeDestroy.delete(win);
|
|
51
56
|
if (focused === win) {
|
|
52
57
|
focused = null;
|
|
@@ -68,7 +73,8 @@ function createManager(options = {}) {
|
|
|
68
73
|
emitter.emit("focus", win);
|
|
69
74
|
}
|
|
70
75
|
function destroy() {
|
|
71
|
-
|
|
76
|
+
var _a2;
|
|
77
|
+
for (const win of windows) (_a2 = unsubscribeDestroy.get(win)) == null ? void 0 : _a2();
|
|
72
78
|
windows.length = 0;
|
|
73
79
|
unsubscribeDestroy.clear();
|
|
74
80
|
focused = null;
|
|
@@ -87,5 +93,3 @@ function createManager(options = {}) {
|
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
export { createManager, createManager as manager };
|
|
90
|
-
//# sourceMappingURL=manager.js.map
|
|
91
|
-
//# sourceMappingURL=manager.js.map
|
package/dist/snap.cjs
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
// src/plugins/snap.ts
|
|
4
4
|
function snapPlugin(options = {}) {
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
var _a, _b;
|
|
6
|
+
const threshold = (_a = options.threshold) != null ? _a : 8;
|
|
7
|
+
const snapToViewport = (_b = options.snapToViewport) != null ? _b : true;
|
|
7
8
|
return {
|
|
8
9
|
name: "freedom-snap",
|
|
9
10
|
onDrag(data, ctx) {
|
|
@@ -30,5 +31,3 @@ function snapPlugin(options = {}) {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
exports.snapPlugin = snapPlugin;
|
|
33
|
-
//# sourceMappingURL=snap.cjs.map
|
|
34
|
-
//# sourceMappingURL=snap.cjs.map
|
package/dist/snap.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/plugins/snap.ts
|
|
2
2
|
function snapPlugin(options = {}) {
|
|
3
|
-
|
|
4
|
-
const
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const threshold = (_a = options.threshold) != null ? _a : 8;
|
|
5
|
+
const snapToViewport = (_b = options.snapToViewport) != null ? _b : true;
|
|
5
6
|
return {
|
|
6
7
|
name: "freedom-snap",
|
|
7
8
|
onDrag(data, ctx) {
|
|
@@ -28,5 +29,3 @@ function snapPlugin(options = {}) {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export { snapPlugin };
|
|
31
|
-
//# sourceMappingURL=snap.js.map
|
|
32
|
-
//# sourceMappingURL=snap.js.map
|