@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/window.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);
|
|
@@ -179,12 +182,42 @@ function toPoint(event) {
|
|
|
179
182
|
return { x: event.clientX, y: event.clientY };
|
|
180
183
|
}
|
|
181
184
|
var InteractionManager = class {
|
|
182
|
-
options;
|
|
183
|
-
activePointerId = null;
|
|
184
|
-
captureTarget = null;
|
|
185
|
-
_active = null;
|
|
186
|
-
destroyed = false;
|
|
187
185
|
constructor(options) {
|
|
186
|
+
this.activePointerId = null;
|
|
187
|
+
this.captureTarget = null;
|
|
188
|
+
this._active = null;
|
|
189
|
+
this.destroyed = false;
|
|
190
|
+
this.handlePointerDown = (event) => {
|
|
191
|
+
if (this.destroyed || this._active !== null) return;
|
|
192
|
+
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
193
|
+
const resizeHandle = this.options.resolveResizeHandle(event.target);
|
|
194
|
+
if (resizeHandle) {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
event.stopPropagation();
|
|
197
|
+
this.startResize(resizeHandle, event);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (this.options.isDragTarget(event.target)) {
|
|
201
|
+
this.startDrag(event);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
this.handlePointerMove = (event) => {
|
|
205
|
+
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
206
|
+
if (this._active === "drag") {
|
|
207
|
+
this.options.onDragMove(this.options.dragEngine.move(toPoint(event), event));
|
|
208
|
+
} else if (this._active === "resize") {
|
|
209
|
+
this.options.onResizeMove(this.options.resizeEngine.move(toPoint(event), event));
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
this.handlePointerUp = (event) => {
|
|
213
|
+
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
214
|
+
if (this._active === "drag") {
|
|
215
|
+
this.options.onDragEnd(this.options.dragEngine.end(toPoint(event), event));
|
|
216
|
+
} else if (this._active === "resize") {
|
|
217
|
+
this.options.onResizeEnd(this.options.resizeEngine.end(toPoint(event), event));
|
|
218
|
+
}
|
|
219
|
+
this.teardown();
|
|
220
|
+
};
|
|
188
221
|
this.options = options;
|
|
189
222
|
this.options.element.addEventListener("pointerdown", this.handlePointerDown);
|
|
190
223
|
}
|
|
@@ -215,10 +248,11 @@ var InteractionManager = class {
|
|
|
215
248
|
this.teardown();
|
|
216
249
|
}
|
|
217
250
|
captureGesture(event) {
|
|
251
|
+
var _a, _b;
|
|
218
252
|
this.activePointerId = event.pointerId;
|
|
219
253
|
this.captureTarget = event.target instanceof Element ? event.target : this.options.element;
|
|
220
254
|
try {
|
|
221
|
-
this.captureTarget.setPointerCapture
|
|
255
|
+
(_b = (_a = this.captureTarget).setPointerCapture) == null ? void 0 : _b.call(_a, event.pointerId);
|
|
222
256
|
} catch {
|
|
223
257
|
}
|
|
224
258
|
window.addEventListener("pointermove", this.handlePointerMove);
|
|
@@ -226,9 +260,10 @@ var InteractionManager = class {
|
|
|
226
260
|
window.addEventListener("pointercancel", this.handlePointerUp);
|
|
227
261
|
}
|
|
228
262
|
teardown() {
|
|
263
|
+
var _a, _b;
|
|
229
264
|
if (this.activePointerId !== null && this.captureTarget) {
|
|
230
265
|
try {
|
|
231
|
-
this.captureTarget.releasePointerCapture
|
|
266
|
+
(_b = (_a = this.captureTarget).releasePointerCapture) == null ? void 0 : _b.call(_a, this.activePointerId);
|
|
232
267
|
} catch {
|
|
233
268
|
}
|
|
234
269
|
}
|
|
@@ -239,37 +274,6 @@ var InteractionManager = class {
|
|
|
239
274
|
window.removeEventListener("pointerup", this.handlePointerUp);
|
|
240
275
|
window.removeEventListener("pointercancel", this.handlePointerUp);
|
|
241
276
|
}
|
|
242
|
-
handlePointerDown = (event) => {
|
|
243
|
-
if (this.destroyed || this._active !== null) return;
|
|
244
|
-
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
245
|
-
const resizeHandle = this.options.resolveResizeHandle(event.target);
|
|
246
|
-
if (resizeHandle) {
|
|
247
|
-
event.preventDefault();
|
|
248
|
-
event.stopPropagation();
|
|
249
|
-
this.startResize(resizeHandle, event);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
if (this.options.isDragTarget(event.target)) {
|
|
253
|
-
this.startDrag(event);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
handlePointerMove = (event) => {
|
|
257
|
-
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
258
|
-
if (this._active === "drag") {
|
|
259
|
-
this.options.onDragMove(this.options.dragEngine.move(toPoint(event), event));
|
|
260
|
-
} else if (this._active === "resize") {
|
|
261
|
-
this.options.onResizeMove(this.options.resizeEngine.move(toPoint(event), event));
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
handlePointerUp = (event) => {
|
|
265
|
-
if (this.destroyed || event.pointerId !== this.activePointerId) return;
|
|
266
|
-
if (this._active === "drag") {
|
|
267
|
-
this.options.onDragEnd(this.options.dragEngine.end(toPoint(event), event));
|
|
268
|
-
} else if (this._active === "resize") {
|
|
269
|
-
this.options.onResizeEnd(this.options.resizeEngine.end(toPoint(event), event));
|
|
270
|
-
}
|
|
271
|
-
this.teardown();
|
|
272
|
-
};
|
|
273
277
|
};
|
|
274
278
|
function createInteractionManager(options) {
|
|
275
279
|
return new InteractionManager(options);
|
|
@@ -277,8 +281,9 @@ function createInteractionManager(options) {
|
|
|
277
281
|
|
|
278
282
|
// src/dom/render.ts
|
|
279
283
|
function applyBaseStyles(element, options) {
|
|
284
|
+
var _a, _b;
|
|
280
285
|
const style = element.style;
|
|
281
|
-
const computedPosition = window.getComputedStyle
|
|
286
|
+
const computedPosition = (_b = (_a = window.getComputedStyle) == null ? void 0 : _a.call(window, element).position) != null ? _b : style.position;
|
|
282
287
|
if (options.forcePositioning || computedPosition === "static") {
|
|
283
288
|
style.position = options.positioning;
|
|
284
289
|
}
|
|
@@ -403,6 +408,7 @@ var ALL_HANDLES = ["n", "s", "e", "w", "nw", "ne", "sw", "se"];
|
|
|
403
408
|
var instances = /* @__PURE__ */ new WeakMap();
|
|
404
409
|
var autoId = 0;
|
|
405
410
|
function createWindow(element, options = {}) {
|
|
411
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
406
412
|
if (typeof document === "undefined" || typeof window === "undefined") {
|
|
407
413
|
throw new Error("freedom.window() requires a browser environment. Importing is SSR-safe, but creating a window must run in the browser.");
|
|
408
414
|
}
|
|
@@ -410,21 +416,21 @@ function createWindow(element, options = {}) {
|
|
|
410
416
|
if (instances.has(element)) {
|
|
411
417
|
throw new Error("freedom.window() was called more than once for the same element. Destroy the existing instance before creating a new one.");
|
|
412
418
|
}
|
|
413
|
-
const id = options.id
|
|
419
|
+
const id = (_a = options.id) != null ? _a : `freedom-window-${++autoId}`;
|
|
414
420
|
const emitter = new Emitter();
|
|
415
|
-
const plugins = options.plugins
|
|
421
|
+
const plugins = (_b = options.plugins) != null ? _b : [];
|
|
416
422
|
const limits = normalizeSizeLimits(options);
|
|
417
423
|
const positioning = resolvePositioning(element, options);
|
|
418
424
|
applyBaseStyles(element, {
|
|
419
425
|
positioning,
|
|
420
426
|
forcePositioning: shouldForcePositioning(element, options)
|
|
421
427
|
});
|
|
422
|
-
let size = clampSize(sanitizeSize(options.initialSize
|
|
428
|
+
let size = clampSize(sanitizeSize((_c = options.initialSize) != null ? _c : readInitialSize(element), "initialSize"), limits);
|
|
423
429
|
let position = resolveInitialPosition(options.initialPosition, element, size, options.bounds, positioning);
|
|
424
430
|
const renderer = createPositionRenderer(element, positioning, position);
|
|
425
|
-
let zIndex = normalizeZIndex(options.zIndex
|
|
431
|
+
let zIndex = normalizeZIndex((_d = options.zIndex) != null ? _d : 0);
|
|
426
432
|
let focused = false;
|
|
427
|
-
let isDraggable = options.draggable
|
|
433
|
+
let isDraggable = (_e = options.draggable) != null ? _e : true;
|
|
428
434
|
let isDestroyed = false;
|
|
429
435
|
writeSize(element, size);
|
|
430
436
|
writePosition(element, position, renderer);
|
|
@@ -544,7 +550,7 @@ function createWindow(element, options = {}) {
|
|
|
544
550
|
emitter.emit("resizeend", data);
|
|
545
551
|
}
|
|
546
552
|
});
|
|
547
|
-
const initialResizeHandles = resolveEnabledHandles(options.resizable
|
|
553
|
+
const initialResizeHandles = resolveEnabledHandles((_f = options.resizable) != null ? _f : true);
|
|
548
554
|
if (initialResizeHandles.length > 0) setupResizeHandles(initialResizeHandles);
|
|
549
555
|
const api = {
|
|
550
556
|
id,
|
|
@@ -568,20 +574,22 @@ function createWindow(element, options = {}) {
|
|
|
568
574
|
paint(void 0, size);
|
|
569
575
|
},
|
|
570
576
|
focus() {
|
|
577
|
+
var _a2;
|
|
571
578
|
assertAlive("focus");
|
|
572
579
|
if (focused) return;
|
|
573
580
|
focused = true;
|
|
574
581
|
element.classList.add("freedom-focused");
|
|
575
582
|
emitter.emit("focus", void 0);
|
|
576
|
-
options.onFocus
|
|
583
|
+
(_a2 = options.onFocus) == null ? void 0 : _a2.call(options);
|
|
577
584
|
},
|
|
578
585
|
blur() {
|
|
586
|
+
var _a2;
|
|
579
587
|
assertAlive("blur");
|
|
580
588
|
if (!focused) return;
|
|
581
589
|
focused = false;
|
|
582
590
|
element.classList.remove("freedom-focused");
|
|
583
591
|
emitter.emit("blur", void 0);
|
|
584
|
-
options.onBlur
|
|
592
|
+
(_a2 = options.onBlur) == null ? void 0 : _a2.call(options);
|
|
585
593
|
},
|
|
586
594
|
isFocused() {
|
|
587
595
|
assertAlive("isFocused");
|
|
@@ -621,13 +629,14 @@ function createWindow(element, options = {}) {
|
|
|
621
629
|
teardownResizeHandles();
|
|
622
630
|
},
|
|
623
631
|
destroy() {
|
|
632
|
+
var _a2;
|
|
624
633
|
if (isDestroyed) return;
|
|
625
634
|
isDestroyed = true;
|
|
626
635
|
interactionManager.destroy();
|
|
627
636
|
teardownResizeHandles();
|
|
628
637
|
scheduler.cancel();
|
|
629
638
|
element.classList.remove("freedom-dragging", "freedom-resizing", "freedom-focused");
|
|
630
|
-
for (const plugin of plugins) plugin.onDestroy
|
|
639
|
+
for (const plugin of plugins) (_a2 = plugin.onDestroy) == null ? void 0 : _a2.call(plugin, pluginContext);
|
|
631
640
|
emitter.emit("destroy", void 0);
|
|
632
641
|
emitter.clear();
|
|
633
642
|
instances.delete(element);
|
|
@@ -644,7 +653,7 @@ function createWindow(element, options = {}) {
|
|
|
644
653
|
if (options.onResizeStart) api.on("resizestart", options.onResizeStart);
|
|
645
654
|
if (options.onResize) api.on("resize", options.onResize);
|
|
646
655
|
if (options.onResizeEnd) api.on("resizeend", options.onResizeEnd);
|
|
647
|
-
for (const plugin of plugins) plugin.onInit
|
|
656
|
+
for (const plugin of plugins) (_g = plugin.onInit) == null ? void 0 : _g.call(plugin, pluginContext);
|
|
648
657
|
return api;
|
|
649
658
|
}
|
|
650
659
|
function assertHTMLElement(element) {
|
|
@@ -784,5 +793,3 @@ function normalizeResizeHandles(handles) {
|
|
|
784
793
|
|
|
785
794
|
exports.createWindow = createWindow;
|
|
786
795
|
exports.window = createWindow;
|
|
787
|
-
//# sourceMappingURL=window.cjs.map
|
|
788
|
-
//# sourceMappingURL=window.cjs.map
|
package/dist/window.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) {
|
|
@@ -781,5 +790,3 @@ function normalizeResizeHandles(handles) {
|
|
|
781
790
|
}
|
|
782
791
|
|
|
783
792
|
export { createWindow, createWindow as window };
|
|
784
|
-
//# sourceMappingURL=window.js.map
|
|
785
|
-
//# sourceMappingURL=window.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blcklab/freedom",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Framework agnostic draggable and resizable window engine for the DOM.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
38
|
"dist",
|
|
39
|
-
"README.md"
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE"
|
|
40
41
|
],
|
|
41
42
|
"sideEffects": false,
|
|
42
43
|
"scripts": {
|
|
@@ -44,7 +45,9 @@
|
|
|
44
45
|
"test": "vitest run",
|
|
45
46
|
"test:watch": "vitest",
|
|
46
47
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
47
|
-
"prepublishOnly": "npm run build"
|
|
48
|
+
"prepublishOnly": "npm run build",
|
|
49
|
+
"pack:check": "npm run typecheck && npm test && npm run build && npm pack --dry-run",
|
|
50
|
+
"size": "npm run build && npx size-limit"
|
|
48
51
|
},
|
|
49
52
|
"keywords": [
|
|
50
53
|
"draggable",
|
|
@@ -59,7 +62,10 @@
|
|
|
59
62
|
"devDependencies": {
|
|
60
63
|
"tsup": "^8.5.1",
|
|
61
64
|
"tsx": "^4.22.4",
|
|
62
|
-
"typescript": "^
|
|
65
|
+
"typescript": "^5.9.3",
|
|
63
66
|
"vitest": "^4.1.9"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=18"
|
|
64
70
|
}
|
|
65
71
|
}
|