@sepveneto/free-dom 0.6.0 → 0.7.0-alpha.2

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.js CHANGED
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
6
  var __export = (target, all) => {
8
7
  for (var name in all)
9
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,463 +16,46 @@ var __copyProps = (to, from, except, desc) => {
17
16
  return to;
18
17
  };
19
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => {
21
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
- return value;
23
- };
24
19
 
25
20
  // src/index.ts
26
21
  var src_exports = {};
27
22
  __export(src_exports, {
28
- freeDom: () => freeDom,
29
- freeScene: () => freeScene
23
+ FreeDom: () => FreeDom,
24
+ FreeScene: () => FreeScene,
25
+ GridLayout: () => GridLayout2
30
26
  });
31
27
  module.exports = __toCommonJS(src_exports);
32
28
 
33
- // src/components/freeDom.ts
34
- var import_vue_demi2 = require("vue-demi");
35
-
36
- // src/hooks/use-normalize-style.ts
37
- var import_vue_demi = require("vue-demi");
38
- function useNormalizeStyle(style) {
39
- const _style = (0, import_vue_demi.ref)({
40
- transition: "inherit"
41
- });
42
- (0, import_vue_demi.watch)(() => style, (data) => {
43
- const res = Object.entries((0, import_vue_demi.unref)(data)).reduce(
44
- (obj, _style2) => {
45
- const [key, value] = _style2;
46
- if (typeof value === "number") {
47
- obj[key] = `${value}px`;
48
- } else {
49
- obj[key] = value;
50
- }
51
- return obj;
52
- },
53
- {}
54
- );
55
- _style.value = {
56
- ..._style.value,
57
- ...res
58
- };
59
- }, { deep: true });
60
- return _style;
61
- }
62
-
63
- // src/util/EventBus.ts
64
- var _EventBus = class {
65
- static on(name, callback) {
66
- if (!Array.isArray(_EventBus._callbacks[name])) {
67
- _EventBus._callbacks[name] = [];
68
- }
69
- _EventBus._callbacks[name].push(callback);
70
- }
71
- static emit(name, ...args) {
72
- _EventBus._callbacks[name]?.forEach((item) => item.apply(this, args));
73
- }
74
- static off(name) {
75
- _EventBus._callbacks[name].length = 0;
76
- }
77
- };
78
- var EventBus = _EventBus;
79
- __publicField(EventBus, "_callbacks", {});
29
+ // src/components/freeDomWrap.ts
30
+ var import_vue_demi13 = require("vue-demi");
80
31
 
81
32
  // src/util/tokens.ts
82
33
  var SceneToken = Symbol("Scene");
83
34
 
84
35
  // src/util/index.ts
36
+ var isProduction = process.env.NODE_ENV === "production";
85
37
  function clamp(value, min, max = Infinity) {
86
38
  return Math.max(Math.min(value, max), min);
87
39
  }
88
- function snapToGrid(grid, pendingX, pendingY) {
89
- const x = Math.round(pendingX / grid[0]) * grid[0];
90
- const y = Math.round(pendingY / grid[1]) * grid[1];
91
- return [x, y];
92
- }
93
-
94
- // src/hooks/use-resize.ts
95
- var MIN_SIZE = 20;
96
- function useResize(startX, startY, rect, dot, diagonal, snapGrid, callbacks) {
97
- const isT = dot ? /t/.test(dot) : false;
98
- const isL = dot ? /l/.test(dot) : false;
99
- const isB = dot ? /b/.test(dot) : false;
100
- const isR = dot ? /r/.test(dot) : false;
101
- const isDiagonal = dot ? dot.length === 2 : false;
102
- const { width: cWidth, height: cHeight, x, y } = rect;
103
- const move = (mouseEvt) => {
104
- const { clientX, clientY } = mouseEvt;
105
- let deltaX = clientX - startX;
106
- let deltaY = clientY - startY;
107
- if (Array.isArray(snapGrid)) {
108
- [deltaX, deltaY] = snapToGrid(snapGrid, deltaX, deltaY);
109
- }
110
- const rate = cWidth / cHeight;
111
- const newWidth = cWidth + (isL ? -deltaX : isR ? deltaX : 0);
112
- const newHeight = cHeight + (isT ? -deltaY : isB ? deltaY : 0);
113
- if (isDiagonal && diagonal) {
114
- if (Math.abs(deltaX) >= Math.abs(deltaY)) {
115
- rect.x = x + (isL ? deltaX : 0);
116
- rect.width = clamp(newWidth, MIN_SIZE);
117
- rect.height = clamp(newWidth / rate, MIN_SIZE);
118
- } else {
119
- rect.y = y + (isT ? deltaY : 0);
120
- rect.height = clamp(newHeight, MIN_SIZE);
121
- rect.width = clamp(newHeight * rate, MIN_SIZE);
122
- }
123
- } else {
124
- rect.x = x + (isL ? deltaX : 0);
125
- rect.y = y + (isT ? deltaY : 0);
126
- rect.width = clamp(newWidth, MIN_SIZE);
127
- rect.height = clamp(newHeight, MIN_SIZE);
128
- }
129
- callbacks && callbacks.onMove && callbacks.onMove();
130
- };
131
- const up = () => {
132
- document.removeEventListener("mousemove", move);
133
- document.removeEventListener("mouseup", up);
134
- callbacks && callbacks.onMove && callbacks.onUp();
135
- };
136
- document.addEventListener("mousemove", move);
137
- document.addEventListener("mouseup", up);
40
+ function log(...args) {
41
+ if (isProduction)
42
+ return;
43
+ console.log("[grid-layout]", ...args);
138
44
  }
139
45
 
140
- // src/components/freeDom.ts
141
- var import_core = require("@vueuse/core");
142
- var import_uuid = require("uuid");
143
- var Dots = ["t", "r", "l", "b", "lt", "lb", "rt", "rb"];
144
- var FreeDom = (0, import_vue_demi2.defineComponent)({
145
- name: "FreeDom",
146
- props: {
147
- x: {
148
- type: Number,
149
- default: void 0
150
- },
151
- y: {
152
- type: Number,
153
- default: void 0
154
- },
155
- width: {
156
- type: Number,
157
- default: void 0
158
- },
159
- height: {
160
- type: Number,
161
- default: void 0
162
- },
163
- absolute: {
164
- type: Boolean,
165
- default: void 0
166
- },
167
- scale: {
168
- type: [Boolean, Array],
169
- default: void 0
170
- },
171
- move: Boolean,
172
- preview: Boolean,
173
- limitWidth: {
174
- type: Number,
175
- default: void 0
176
- },
177
- limitHeight: {
178
- type: Number,
179
- default: void 0
180
- },
181
- handler: {
182
- type: String,
183
- default: void 0
184
- },
185
- diagonal: {
186
- type: Boolean,
187
- default: void 0
188
- },
189
- grid: {
190
- type: Object,
191
- default: void 0
192
- },
193
- onDragStart: {
194
- type: Function,
195
- default: void 0
196
- },
197
- onDragEnd: {
198
- type: Function,
199
- default: void 0
200
- }
201
- },
202
- emits: ["update:x", "update:y", "update:width", "update:height", "select"],
203
- setup(props, { emit }) {
204
- const active = (0, import_vue_demi2.ref)(false);
205
- const SceneContext = (0, import_vue_demi2.inject)(SceneToken, void 0);
206
- const _preview = (0, import_vue_demi2.computed)(() => SceneContext?.preview || props.preview);
207
- const canScale = (0, import_vue_demi2.computed)(() => !_preview.value && (SceneContext?.scale || props.scale));
208
- const canMove = (0, import_vue_demi2.computed)(() => !_preview.value && (SceneContext?.move || props.move));
209
- const isAbsolute = (0, import_vue_demi2.computed)(() => props.absolute ?? SceneContext?.absolute ?? true);
210
- const handlerType = (0, import_vue_demi2.computed)(() => props.handler ?? SceneContext?.handler ?? "dot");
211
- const snapGrid = (0, import_vue_demi2.computed)(() => props.grid ?? SceneContext?.grid);
212
- const diagonal = (0, import_vue_demi2.computed)(() => props.diagonal ?? SceneContext?.diagonal ?? true);
213
- const widgetRef = (0, import_vue_demi2.shallowRef)();
214
- const _style = (0, import_vue_demi2.ref)({});
215
- const wrapStyle = useNormalizeStyle(_style);
216
- const uuid = (0, import_uuid.v4)();
217
- const isScale = (0, import_vue_demi2.ref)(false);
218
- const isMove = (0, import_vue_demi2.ref)(false);
219
- const _rect = (0, import_vue_demi2.reactive)({});
220
- const context = {
221
- _rect,
222
- trigger
223
- };
224
- (0, import_core.onClickOutside)(widgetRef, () => {
225
- active.value = false;
226
- });
227
- let rectSize = (0, import_vue_demi2.reactive)((0, import_core.useElementSize)(widgetRef));
228
- let autoWidth = true;
229
- let autoHeight = true;
230
- const unwatch = (0, import_vue_demi2.watch)(rectSize, ({ width, height }) => {
231
- if (autoWidth && width) {
232
- _rect.width = width;
233
- }
234
- if (autoHeight && height) {
235
- _rect.height = height;
236
- }
237
- });
238
- (0, import_vue_demi2.watch)(
239
- [
240
- () => props.width,
241
- () => props.height,
242
- () => props.x,
243
- () => props.y
244
- ],
245
- ([width, height, x, y]) => {
246
- autoWidth = width === _rect.width;
247
- autoHeight = height === _rect.height;
248
- if (!autoHeight && !autoWidth) {
249
- unwatch();
250
- rectSize = null;
251
- }
252
- width && (_rect.width = width);
253
- height && (_rect.height = height);
254
- x != null && (_rect.x = x);
255
- y != null && (_rect.y = y);
256
- trigger();
257
- },
258
- { immediate: true }
259
- );
260
- (0, import_vue_demi2.onMounted)(async () => {
261
- SceneContext?.register(uuid, context);
262
- const { offsetTop, offsetLeft } = widgetRef.value;
263
- _rect.x = _rect.x == null ? offsetLeft : _rect.x;
264
- _rect.y = _rect.y == null ? offsetTop : _rect.y;
265
- trigger();
266
- });
267
- function trigger() {
268
- const { x, y, width, height } = _rect;
269
- _style.value = {
270
- transform: `translate(${x}px, ${y}px)`,
271
- width,
272
- height
273
- };
274
- }
275
- const _dots = (0, import_vue_demi2.computed)(() => {
276
- return SceneContext && Array.isArray(SceneContext.scale) ? SceneContext.scale : props.scale;
277
- });
278
- const dots = (0, import_vue_demi2.computed)(() => {
279
- if (!isActive.value)
280
- return [];
281
- return Array.isArray(_dots.value) ? _dots.value : Dots;
282
- });
283
- const direct = {
284
- l: "w",
285
- r: "e",
286
- t: "n",
287
- b: "s"
288
- };
289
- const isActive = (0, import_vue_demi2.shallowRef)(true);
290
- function onMousedownDot(evt, dot) {
291
- evt.stopPropagation();
292
- evt.preventDefault();
293
- if (isMove.value)
294
- return;
295
- isScale.value = true;
296
- active.value = true;
297
- const shouldUpdate = props.onDragStart?.();
298
- if (shouldUpdate === false)
299
- return;
300
- const { clientX, clientY } = evt;
301
- useResize(clientX, clientY, _rect, dot, diagonal.value, snapGrid.value, {
302
- onMove() {
303
- if (!checkValid(_rect))
304
- return;
305
- EventBus.emit("move", uuid);
306
- trigger();
307
- },
308
- onUp() {
309
- props.onDragEnd?.();
310
- isScale.value = false;
311
- EventBus.emit("moveup", uuid);
312
- emitPos();
313
- }
314
- });
315
- }
316
- function emitPos() {
317
- emit("update:x", _rect.x);
318
- emit("update:y", _rect.y);
319
- emit("update:width", _rect.width);
320
- emit("update:height", _rect.height);
321
- }
322
- function getDotPos(dot) {
323
- const { width, height } = _rect;
324
- const isL = /l/.test(dot);
325
- const isR = /r/.test(dot);
326
- const isT = /t/.test(dot);
327
- let left, top;
328
- if (dot.length === 2) {
329
- left = isL ? 0 : width;
330
- top = isT ? 0 : height;
331
- } else {
332
- if (isL || isR) {
333
- left = isL ? 0 : width;
334
- top = Number(height) / 2;
335
- } else {
336
- left = Number(width) / 2;
337
- top = isT ? 0 : height;
338
- }
339
- }
340
- return {
341
- top: `${handlerType.value === "dot" ? top : top - 3}px`,
342
- left: `${handlerType.value === "dot" ? left : left - 3}px`,
343
- cursor: dot.split("").reverse().map((item) => direct[item]).join("") + "-resize"
344
- };
345
- }
346
- function onMousedown(evt) {
347
- evt.stopPropagation();
348
- if (isScale.value || !canMove.value)
349
- return;
350
- isMove.value = true;
351
- active.value = true;
352
- const shouldUpdate = props.onDragStart?.();
353
- if (shouldUpdate === false)
354
- return;
355
- const pos = { ..._rect };
356
- const move = (mouseEvt) => {
357
- const { clientX, clientY } = mouseEvt;
358
- const x = clientX - evt.clientX + pos.x;
359
- const y = clientY - evt.clientY + pos.y;
360
- _rect.x = x;
361
- _rect.y = y;
362
- _rect.width = pos.width;
363
- _rect.height = pos.height;
364
- if (!checkValid(_rect))
365
- return;
366
- EventBus.emit("move", uuid);
367
- trigger();
368
- };
369
- const up = () => {
370
- props.onDragEnd?.();
371
- isMove.value = false;
372
- EventBus.emit("moveup", uuid);
373
- document.removeEventListener("mousemove", move);
374
- document.removeEventListener("mouseup", up);
375
- emitPos();
376
- emit("select", _rect);
377
- };
378
- document.addEventListener("mousemove", move);
379
- document.addEventListener("mouseup", up);
380
- }
381
- function checkValid(rect) {
382
- if (SceneContext) {
383
- return SceneContext.checkValid(rect);
384
- } else if (props.limitWidth && props.limitHeight) {
385
- const { x, y, width, height } = rect;
386
- return x >= 0 && x + width <= props.limitWidth && y >= 0 && y + height <= props.limitHeight;
387
- } else {
388
- return true;
389
- }
390
- }
391
- return {
392
- widgetRef,
393
- canMove,
394
- wrapStyle,
395
- canScale,
396
- dots,
397
- active,
398
- isAbsolute,
399
- isScale,
400
- handlerType,
401
- getDotPos,
402
- onMousedown,
403
- onMousedownDot
404
- };
405
- },
406
- render() {
407
- const dots = this.canScale ? this.dots.map((dot) => {
408
- if (import_vue_demi2.isVue2) {
409
- return (0, import_vue_demi2.h)("div", {
410
- class: "free-dom__widget-dot",
411
- style: this.getDotPos(dot),
412
- on: {
413
- mousedown: (evt) => this.onMousedownDot(evt, dot)
414
- }
415
- });
416
- }
417
- return (0, import_vue_demi2.h)("div", {
418
- class: this.handlerType === "dot" ? "free-dom__widget-dot" : "free-dom__resizable-handler",
419
- style: this.getDotPos(dot),
420
- onMousedown: (evt) => this.onMousedownDot(evt, dot)
421
- });
422
- }) : null;
423
- const defaultSlot = typeof this.$slots.default === "function" ? this.$slots.default() : this.$slots.default;
424
- if (import_vue_demi2.isVue2) {
425
- return (0, import_vue_demi2.h)(
426
- "section",
427
- {
428
- class: [
429
- "free-dom__widget-wrapper",
430
- { "is-scale": this.isScale },
431
- { "is-absolute": this.isAbsolute },
432
- { "can-move": this.canMove },
433
- { "is-active": this.active }
434
- ],
435
- style: this.wrapStyle,
436
- ref: "widgetRef",
437
- on: {
438
- mousedown: this.onMousedown
439
- }
440
- },
441
- [dots, defaultSlot]
442
- );
443
- }
444
- return (0, import_vue_demi2.h)(
445
- "section",
446
- {
447
- ref: "widgetRef",
448
- class: [
449
- "free-dom__widget-wrapper",
450
- { "is-scale": this.isScale },
451
- { "is-absolute": this.isAbsolute },
452
- { "can-move": this.canMove },
453
- { "is-active": this.active }
454
- ],
455
- style: this.wrapStyle,
456
- onMousedown: this.onMousedown
457
- },
458
- [defaultSlot, dots]
459
- );
460
- }
461
- });
462
-
463
- // src/components/freeDomWrap.ts
464
- var import_vue_demi4 = require("vue-demi");
465
- var import_core2 = require("@vueuse/core");
466
-
467
46
  // src/components/markLine.ts
468
- var import_vue_demi3 = require("vue-demi");
47
+ var import_vue_demi = require("vue-demi");
469
48
  var lineType = ["xt", "xc", "xb", "yl", "yc", "yr"];
470
- var markLine_default = (0, import_vue_demi3.defineComponent)({
49
+ var markLine_default = (0, import_vue_demi.defineComponent)({
50
+ props: {
51
+ showLine: Boolean
52
+ },
471
53
  setup() {
472
- const SceneContext = (0, import_vue_demi3.inject)(SceneToken);
473
- const lines = (0, import_vue_demi3.shallowRef)(lineType);
474
- const diff = (0, import_vue_demi3.ref)(SceneContext.diff);
54
+ const SceneContext = (0, import_vue_demi.inject)(SceneToken);
55
+ const lines = (0, import_vue_demi.shallowRef)(lineType);
56
+ const diff = (0, import_vue_demi.ref)(SceneContext.diff);
475
57
  const nodes = SceneContext.nodes;
476
- const lineStatus = (0, import_vue_demi3.reactive)({
58
+ const lineStatus = (0, import_vue_demi.reactive)({
477
59
  xt: {
478
60
  show: false,
479
61
  pos: 0
@@ -499,7 +81,7 @@ var markLine_default = (0, import_vue_demi3.defineComponent)({
499
81
  pos: 0
500
82
  }
501
83
  });
502
- EventBus.on("move", async (uuid) => {
84
+ const runConstraints = (uuid) => {
503
85
  const current = nodes.find((node) => node.uuid === uuid)?.node ?? {};
504
86
  clearStatus();
505
87
  nodes.forEach((node) => {
@@ -578,11 +160,12 @@ var markLine_default = (0, import_vue_demi3.defineComponent)({
578
160
  current._rect.x = _target.right - _current.width;
579
161
  }
580
162
  });
581
- });
582
- EventBus.on("moveup", clearStatus);
583
- (0, import_vue_demi3.onBeforeUnmount)(() => {
584
- EventBus.off("move");
585
- EventBus.off("moveup");
163
+ };
164
+ SceneContext?.on("move", runConstraints);
165
+ SceneContext?.on("moveup", clearStatus);
166
+ (0, import_vue_demi.onBeforeUnmount)(() => {
167
+ SceneContext?.off("move");
168
+ SceneContext?.off("moveup");
586
169
  });
587
170
  function clearStatus() {
588
171
  lineStatus.xt.show = false;
@@ -594,6 +177,8 @@ var markLine_default = (0, import_vue_demi3.defineComponent)({
594
177
  }
595
178
  function normalize(rect) {
596
179
  return {
180
+ deltaX: rect.deltaX,
181
+ deltaY: rect.deltaY,
597
182
  top: rect.y,
598
183
  bottom: rect.y + rect.height,
599
184
  left: rect.x,
@@ -614,83 +199,1474 @@ var markLine_default = (0, import_vue_demi3.defineComponent)({
614
199
  };
615
200
  },
616
201
  render() {
617
- const _line = (line, info) => (0, import_vue_demi3.h)("div", {
202
+ const _line = (line, info) => (0, import_vue_demi.h)("div", {
618
203
  style: { [line.includes("x") ? "top" : "left"]: info.pos + "px" },
619
- class: [line.includes("x") ? "free-dom__xline" : "free-dom__yline", "free-dom__line"]
204
+ class: [line.includes("x") ? "vv-free-dom--xline" : "vv-free-dom--yline", "vv-free-dom--line"]
620
205
  });
621
- const _lines = this.lines.filter((line) => this.lineStatus[line].show).map((line) => _line(line, this.lineStatus[line]));
622
- return (0, import_vue_demi3.h)("div", {
623
- class: "free-dom__mark-line"
206
+ const _lines = this.showLine ? this.lines.filter((line) => this.lineStatus[line].show).map((line) => _line(line, this.lineStatus[line])) : [];
207
+ return (0, import_vue_demi.h)("div", {
208
+ class: "vv-free-dom--markline"
624
209
  }, _lines);
625
210
  }
626
211
  });
627
212
 
628
- // src/components/freeDomWrap.ts
629
- var freeDomWrapProps = {
630
- absolute: {
213
+ // src/hooks/use-normalize-style.ts
214
+ var import_vue_demi2 = require("vue-demi");
215
+
216
+ // src/hooks/use-default-slot.ts
217
+ var import_vue_demi3 = require("vue-demi");
218
+ function useDefaultSlot() {
219
+ const slots = (0, import_vue_demi3.useSlots)();
220
+ const slotList = (0, import_vue_demi3.computed)(() => {
221
+ return typeof slots.default === "function" ? slots.default() : slots.default;
222
+ });
223
+ const only = (0, import_vue_demi3.computed)(() => slotList.value?.filter((slot) => slot.type !== import_vue_demi3.Comment)[0] || null);
224
+ return {
225
+ slots: slotList,
226
+ only
227
+ };
228
+ }
229
+
230
+ // src/hooks/use-core-date.ts
231
+ var import_vue_demi4 = require("vue-demi");
232
+ function useCoreData(node) {
233
+ const lastX = (0, import_vue_demi4.ref)(NaN);
234
+ const lastY = (0, import_vue_demi4.ref)(NaN);
235
+ function create(x, y) {
236
+ const isStart = isNaN(lastX.value);
237
+ const _node = (0, import_vue_demi4.unref)(node);
238
+ if (!_node) {
239
+ throw new Error("drag node does not exist");
240
+ }
241
+ if (isStart) {
242
+ return {
243
+ node: _node,
244
+ deltaX: 0,
245
+ deltaY: 0,
246
+ lastX: x,
247
+ lastY: y,
248
+ x,
249
+ y
250
+ };
251
+ } else {
252
+ return {
253
+ node: _node,
254
+ deltaX: x - lastX.value,
255
+ deltaY: y - lastY.value,
256
+ lastX: lastX.value,
257
+ lastY: lastY.value,
258
+ x,
259
+ y
260
+ };
261
+ }
262
+ }
263
+ return {
264
+ lastX,
265
+ lastY,
266
+ create
267
+ };
268
+ }
269
+
270
+ // src/hooks/use-draggable-data.ts
271
+ var import_vue_demi5 = require("vue-demi");
272
+ function useDraggableData(props) {
273
+ const x = (0, import_vue_demi5.ref)(props.x || props.modelValue.x || 0);
274
+ const y = (0, import_vue_demi5.ref)(props.y || props.modelValue.y || 0);
275
+ const deltaX = (0, import_vue_demi5.ref)(0);
276
+ const deltaY = (0, import_vue_demi5.ref)(0);
277
+ const dragData = (0, import_vue_demi5.ref)();
278
+ (0, import_vue_demi5.watchEffect)(() => {
279
+ x.value = props.x || props.modelValue.x || 0;
280
+ });
281
+ (0, import_vue_demi5.watchEffect)(() => {
282
+ y.value = props.y || props.modelValue.y || 0;
283
+ });
284
+ const handleDrag = (evt, data) => {
285
+ x.value = data.x;
286
+ y.value = data.y;
287
+ deltaX.value = data.deltaX;
288
+ deltaY.value = data.deltaY;
289
+ props.dargFn(evt, data);
290
+ };
291
+ const handleDragStop = (evt, coreData) => {
292
+ const data = dragData.value = create(coreData);
293
+ props.dragStopFn(evt, data);
294
+ };
295
+ function create(coreData) {
296
+ return {
297
+ node: coreData.node,
298
+ x: x.value + coreData.deltaX,
299
+ y: y.value + coreData.deltaY,
300
+ deltaX: coreData.deltaX,
301
+ deltaY: coreData.deltaY,
302
+ lastX: x.value,
303
+ lastY: y.value
304
+ };
305
+ }
306
+ return {
307
+ x,
308
+ y,
309
+ deltaX,
310
+ deltaY,
311
+ create,
312
+ handleDrag,
313
+ handleDragStop
314
+ };
315
+ }
316
+
317
+ // src/hooks/use-scene-context.ts
318
+ var import_vue_demi6 = require("vue-demi");
319
+ var id = 0;
320
+ function useSceneContext(context, props) {
321
+ const SceneContext = (0, import_vue_demi6.inject)(SceneToken, void 0);
322
+ const uuid = id++;
323
+ const lockAspectRatio = (0, import_vue_demi6.computed)(() => SceneContext?.lockAspectRatio || props.lockAspectRatio);
324
+ const minWidth = (0, import_vue_demi6.computed)(() => SceneContext?.minWidth || props.minWidth);
325
+ const minHeight = (0, import_vue_demi6.computed)(() => SceneContext?.minHeight || props.minHeight);
326
+ const disabledDrag = (0, import_vue_demi6.computed)(() => SceneContext?.disabledDrag || props.disabledDrag);
327
+ const disabledResize = (0, import_vue_demi6.computed)(() => SceneContext?.disabledResize || props.disabledResize);
328
+ const scale = (0, import_vue_demi6.computed)(() => SceneContext?.scale || props.scale);
329
+ const fixNonMonospaced = (0, import_vue_demi6.computed)(() => {
330
+ return SceneContext?.fixNonMonospaced || props.fixNonMonospaced;
331
+ });
332
+ (0, import_vue_demi6.onMounted)(() => {
333
+ SceneContext?.register(uuid, context);
334
+ });
335
+ function check(pos) {
336
+ if (!SceneContext)
337
+ return true;
338
+ return SceneContext.checkValid(pos);
339
+ }
340
+ return {
341
+ emit: (name) => SceneContext?.emit(name, uuid),
342
+ check,
343
+ width: SceneContext?.width,
344
+ height: SceneContext?.height,
345
+ scale,
346
+ lockAspectRatio,
347
+ minWidth,
348
+ minHeight,
349
+ disabledDrag,
350
+ disabledResize,
351
+ fixNonMonospaced
352
+ };
353
+ }
354
+
355
+ // src/hooks/use-event-bus.ts
356
+ var import_vue_demi7 = require("vue-demi");
357
+ function useEventBus() {
358
+ const callbacks = (0, import_vue_demi7.ref)({});
359
+ const on = (name, cb) => {
360
+ if (!callbacks.value[name]) {
361
+ callbacks.value[name] = [cb];
362
+ } else {
363
+ callbacks.value[name].push(cb);
364
+ }
365
+ };
366
+ const off = (name) => {
367
+ callbacks.value[name].length = 0;
368
+ };
369
+ const emit = (name, args) => {
370
+ const fns = callbacks.value[name] || [];
371
+ fns.forEach((fn) => fn(args));
372
+ };
373
+ return {
374
+ on,
375
+ off,
376
+ emit
377
+ };
378
+ }
379
+
380
+ // src/hooks/use-resizable-data.ts
381
+ var import_vue_demi8 = require("vue-demi");
382
+ function useResizableData(props, domRef) {
383
+ const width = (0, import_vue_demi8.ref)(getWidth());
384
+ const height = (0, import_vue_demi8.ref)(getHeight());
385
+ (0, import_vue_demi8.watchEffect)(() => {
386
+ width.value = getWidth();
387
+ });
388
+ (0, import_vue_demi8.watchEffect)(() => {
389
+ height.value = getHeight();
390
+ });
391
+ function getWidth() {
392
+ return props.width || props.modelValue.w;
393
+ }
394
+ function getHeight() {
395
+ return props.height || props.modelValue.h;
396
+ }
397
+ async function syncSize(fixNonMonospaced, minWidth, minHeight) {
398
+ if (props.width && props.height || props.modelValue.w && props.modelValue.h)
399
+ return;
400
+ if (!domRef.value)
401
+ return [0, 0];
402
+ if (fixNonMonospaced) {
403
+ await document.fonts.ready;
404
+ }
405
+ const { width: w, height: h8 } = window.getComputedStyle(domRef.value.$el);
406
+ width.value = Math.max(Math.ceil(parseFloat(w)), minWidth);
407
+ height.value = Math.max(Math.ceil(parseFloat(h8)), minHeight);
408
+ }
409
+ return {
410
+ width,
411
+ height,
412
+ syncSize
413
+ };
414
+ }
415
+
416
+ // src/hooks/use-layout.ts
417
+ var import_vue_demi9 = require("vue-demi");
418
+ function useLayout(props) {
419
+ const layout = (0, import_vue_demi9.shallowRef)(props.modelValue);
420
+ (0, import_vue_demi9.watchEffect)(() => {
421
+ layout.value = props.modelValue;
422
+ });
423
+ const cellWidth = (0, import_vue_demi9.computed)(
424
+ () => (props.width - margin.value[0] * (cols.value - 1) - (containerPadding.value?.[0] || margin.value[0]) * 2) / props.cols
425
+ );
426
+ const cols = (0, import_vue_demi9.computed)(() => props.cols);
427
+ const rowHeight = (0, import_vue_demi9.computed)(() => props.rowHeight);
428
+ const margin = (0, import_vue_demi9.computed)(() => props.margin);
429
+ const maxRows = (0, import_vue_demi9.computed)(() => props.maxRows);
430
+ const containerPadding = (0, import_vue_demi9.computed)(() => props.containerPadding);
431
+ const minW = (0, import_vue_demi9.computed)(() => props.minW);
432
+ const minH = (0, import_vue_demi9.computed)(() => props.minH);
433
+ function getItem(key) {
434
+ return layout.value.find((item) => item.i === key);
435
+ }
436
+ function getFull() {
437
+ return layout.value;
438
+ }
439
+ function _moveElement(layout2, config, x, y, isUserAction, preventCollision) {
440
+ if (config.static)
441
+ return layout2;
442
+ if (config.y === y && config.x === x)
443
+ return layout2;
444
+ log(
445
+ `Moving element ${config.i} to [${String(x)},${String(y)}] from [${config.x},${config.y}]`
446
+ );
447
+ const oldX = config.x;
448
+ const oldY = config.y;
449
+ if (typeof x === "number")
450
+ config.x = x;
451
+ if (typeof y === "number")
452
+ config.y = y;
453
+ config.moved = true;
454
+ const sortable = _sortLayoutItems(layout2);
455
+ const collisions = sortable.filter((l) => _collides(l, config));
456
+ const hasCollsions = collisions.length > 0;
457
+ if (hasCollsions && preventCollision) {
458
+ config.x = oldX;
459
+ config.y = oldY;
460
+ config.moved = false;
461
+ return layout2;
462
+ }
463
+ collisions.forEach((collision) => {
464
+ log(
465
+ `Resolving collision between ${config.i} at [${config.x},${config.y}] and ${collision.i} at [${collision.x},${collision.y}]`,
466
+ collision.moved,
467
+ collision.i
468
+ );
469
+ if (collision.moved)
470
+ return;
471
+ if (collision.static) {
472
+ layout2 = _moveElementAwayFromCollision(
473
+ layout2,
474
+ collision,
475
+ config,
476
+ isUserAction
477
+ );
478
+ } else {
479
+ layout2 = _moveElementAwayFromCollision(
480
+ layout2,
481
+ config,
482
+ collision,
483
+ isUserAction
484
+ );
485
+ }
486
+ });
487
+ return layout2;
488
+ }
489
+ function _moveElementAwayFromCollision(layout2, collideWith, itemToMove, isUserAction) {
490
+ const preventCollision = collideWith.static;
491
+ if (isUserAction) {
492
+ isUserAction = false;
493
+ const fakeItem = {
494
+ x: itemToMove.x,
495
+ y: Math.max(collideWith.y - itemToMove.h, 0),
496
+ w: itemToMove.w,
497
+ h: itemToMove.h,
498
+ i: "-1"
499
+ };
500
+ if (!_getFirstCollision(layout2, fakeItem)) {
501
+ log(
502
+ `Doing reverse collision on ${itemToMove.i} up to [${fakeItem.x},${fakeItem.y}].`
503
+ );
504
+ return _moveElement(
505
+ layout2,
506
+ itemToMove,
507
+ void 0,
508
+ fakeItem.y,
509
+ isUserAction,
510
+ preventCollision
511
+ );
512
+ }
513
+ }
514
+ return _moveElement(
515
+ layout2,
516
+ itemToMove,
517
+ void 0,
518
+ itemToMove.y + 1,
519
+ isUserAction,
520
+ preventCollision
521
+ );
522
+ }
523
+ function moveTo(item, x, y) {
524
+ const isUserAction = true;
525
+ const _layout = _moveElement(layout.value, item, x, y, isUserAction, !props.collision);
526
+ layout.value = _normalize(_layout);
527
+ return layout.value;
528
+ }
529
+ function resizeTo(item, w, h8) {
530
+ let hasCollisions = false;
531
+ if (!props.collision) {
532
+ const collisions = layout.value.filter((l) => _collides(l, { ...item, w, h: h8 }));
533
+ hasCollisions = collisions.length > 0;
534
+ if (hasCollisions) {
535
+ let leastX = Infinity;
536
+ let leastY = Infinity;
537
+ collisions.forEach((collision) => {
538
+ if (collision.x > item.x)
539
+ leastX = Math.min(collision.x, leastX);
540
+ if (collision.y > item.y)
541
+ leastY = Math.min(collision.y, leastY);
542
+ });
543
+ if (Number.isFinite(leastX))
544
+ item.w = leastX - item.x;
545
+ if (Number.isFinite(leastY))
546
+ item.h = leastY - item.y;
547
+ }
548
+ }
549
+ if (!hasCollisions) {
550
+ item.w = w;
551
+ item.h = h8;
552
+ }
553
+ layout.value = _normalize([...layout.value]);
554
+ }
555
+ function _sortLayoutItems(layout2) {
556
+ return layout2.slice(0).sort((a, b) => {
557
+ if (a.y > b.y || a.y === b.y && a.x > b.x) {
558
+ return 1;
559
+ } else if (a.y === b.y && a.x === b.x) {
560
+ return 0;
561
+ } else {
562
+ return -1;
563
+ }
564
+ });
565
+ }
566
+ function _collides(l1, l2) {
567
+ if (l1.i === l2.i)
568
+ return false;
569
+ else if (l1.x + l1.w <= l2.x)
570
+ return false;
571
+ else if (l1.x >= l2.x + l2.w)
572
+ return false;
573
+ else if (l1.y + l1.h <= l2.y)
574
+ return false;
575
+ else if (l1.y >= l2.y + l2.h)
576
+ return false;
577
+ else
578
+ return true;
579
+ }
580
+ function _getFirstCollision(layout2, layoutItem) {
581
+ for (let i = 0; i < layout2.length; ++i) {
582
+ if (_collides(layout2[i], layoutItem))
583
+ return layout2[i];
584
+ }
585
+ }
586
+ function _normalize(layout2) {
587
+ const compareWith = layout2.filter((item) => item.static);
588
+ const sorted = _sortLayoutItems(layout2);
589
+ const _layout = new Array(layout2.length);
590
+ sorted.forEach((item, index) => {
591
+ let l = JSON.parse(JSON.stringify(item));
592
+ if (!l.static) {
593
+ l = _normalizeItem(compareWith, l, sorted);
594
+ compareWith.push(l);
595
+ }
596
+ _layout[layout2.indexOf(sorted[index])] = l;
597
+ l.moved = false;
598
+ });
599
+ return _layout;
600
+ }
601
+ function _normalizeItem(compareWith, l, layout2) {
602
+ if (props.collision) {
603
+ l.y = Math.min(_calBottom(compareWith), l.y);
604
+ while (l.y > 0 && !_getFirstCollision(compareWith, l)) {
605
+ --l.y;
606
+ }
607
+ }
608
+ let collides;
609
+ while ((collides = _getFirstCollision(compareWith, l)) && props.collision) {
610
+ resolveCompactionCollision(layout2, l, collides.y + collides.h, "y");
611
+ }
612
+ return l;
613
+ }
614
+ function _calBottom(layout2) {
615
+ let max = 0;
616
+ layout2.forEach((l) => {
617
+ const val = l.y + l.h;
618
+ if (val > max)
619
+ max = val;
620
+ });
621
+ return max;
622
+ }
623
+ function calContainerHeight() {
624
+ if (!props.autoHeight)
625
+ return;
626
+ const rows = _calBottom(layout.value);
627
+ return `${rows * props.rowHeight + margin.value[1] * (rows - 1) + (containerPadding.value?.[1] || margin.value[1]) * 2}px`;
628
+ }
629
+ const heightWidth = { x: "w", y: "h" };
630
+ function resolveCompactionCollision(layout2, item, position, axis) {
631
+ const sizeProp = heightWidth[axis];
632
+ item[axis] += 1;
633
+ const itemIndex = layout2.findIndex((each) => each === item);
634
+ for (let i = itemIndex + 1; i < layout2.length; ++i) {
635
+ const otherItem = layout2[i];
636
+ if (otherItem.y > item.y + item.h)
637
+ break;
638
+ if (_collides(item, otherItem)) {
639
+ resolveCompactionCollision(
640
+ layout2,
641
+ otherItem,
642
+ position + item[sizeProp],
643
+ axis
644
+ );
645
+ }
646
+ }
647
+ item[axis] = position;
648
+ }
649
+ return {
650
+ cellWidth,
651
+ cols,
652
+ rowHeight,
653
+ margin,
654
+ maxRows,
655
+ containerPadding,
656
+ minW,
657
+ minH,
658
+ calContainerHeight,
659
+ moveTo,
660
+ resizeTo,
661
+ getItem,
662
+ getFull
663
+ };
664
+ }
665
+ function useLayoutItem(props, layout) {
666
+ const { cellWidth, margin, rowHeight, cols, maxRows, containerPadding: cPadding } = layout;
667
+ const dragging = (0, import_vue_demi9.ref)();
668
+ const resizing = (0, import_vue_demi9.ref)();
669
+ const containerPadding = (0, import_vue_demi9.computed)(() => cPadding.value || margin.value);
670
+ const x = (0, import_vue_demi9.computed)(() => {
671
+ if (!dragging.value) {
672
+ return Math.round(props.x * (cellWidth.value + margin.value[0]) + containerPadding.value[0]);
673
+ } else {
674
+ return Math.round(dragging.value.x);
675
+ }
676
+ });
677
+ const y = (0, import_vue_demi9.computed)(() => {
678
+ if (!dragging.value) {
679
+ return Math.round(props.y * (rowHeight.value + margin.value[1]) + containerPadding.value[1]);
680
+ } else {
681
+ return Math.round(dragging.value.y);
682
+ }
683
+ });
684
+ const width = (0, import_vue_demi9.computed)(() => {
685
+ if (!resizing.value) {
686
+ return Math.round(cellWidth.value * props.width + Math.max(0, props.width - 1) * margin.value[0]);
687
+ } else {
688
+ return Math.round(resizing.value.width);
689
+ }
690
+ });
691
+ const height = (0, import_vue_demi9.computed)(() => {
692
+ if (!resizing.value) {
693
+ return Math.round(rowHeight.value * props.height + Math.max(0, props.height - 1) * margin.value[1]);
694
+ } else {
695
+ return Math.round(resizing.value.height);
696
+ }
697
+ });
698
+ const minWidth = (0, import_vue_demi9.computed)(() => {
699
+ const minW = layout.minW.value;
700
+ return Math.round(cellWidth.value * minW + Math.max(0, minW - 1) * margin.value[0]);
701
+ });
702
+ const minHeight = (0, import_vue_demi9.computed)(() => {
703
+ const minH = layout.minH.value;
704
+ return Math.round(rowHeight.value * minH + Math.max(0, minH - 1) * margin.value[1]);
705
+ });
706
+ const style = (0, import_vue_demi9.computed)(() => {
707
+ return {
708
+ position: "absolute",
709
+ width: `${width.value}px`,
710
+ height: `${height.value}px`,
711
+ transform: `translate(${x.value}px, ${y.value}px)`
712
+ };
713
+ });
714
+ const onDragStart = (evt, { node }) => {
715
+ const parentRect = node.offsetParent.getBoundingClientRect();
716
+ const clientRect = node.getBoundingClientRect();
717
+ dragging.value = {
718
+ x: clientRect.left - parentRect.left + node.offsetParent.scrollLeft,
719
+ y: clientRect.top - parentRect.top + node.offsetParent.scrollTop
720
+ };
721
+ };
722
+ const onDrag = (evt, coreData) => {
723
+ if (!dragging.value) {
724
+ throw new Error("onDrag called before onDragStart");
725
+ }
726
+ const { deltaX, deltaY } = coreData;
727
+ const dragX = dragging.value.x + deltaX;
728
+ const dragY = dragging.value.y + deltaY;
729
+ dragging.value = { x: dragX, y: dragY };
730
+ const { x: x2, y: y2 } = _calcXY(dragX, dragY);
731
+ props.dragFn(evt, { x: x2, y: y2 });
732
+ };
733
+ const onDragStop = (evt) => {
734
+ if (!dragging.value) {
735
+ throw new Error("onDragStop called before onDratStart");
736
+ }
737
+ const { x: _x, y: _y } = dragging.value;
738
+ const { x: x2, y: y2 } = _calcXY(_x, _y);
739
+ dragging.value = void 0;
740
+ props.dragEndFn(evt, { x: x2, y: y2 });
741
+ };
742
+ const onResizeStart = (evt, { width: width2, height: height2 }) => {
743
+ resizing.value = { width: width2, height: height2 };
744
+ };
745
+ const onResize = (evt, coreData) => {
746
+ const { width: width2, height: height2 } = coreData;
747
+ const { w, h: h8 } = _calcWH(width2, height2);
748
+ resizing.value = { width: width2, height: height2 };
749
+ props.resizeFn(evt, { w, h: h8 });
750
+ };
751
+ const onResizeStop = (evt, coreData) => {
752
+ resizing.value = void 0;
753
+ const { width: width2, height: height2 } = coreData;
754
+ const { w, h: h8 } = _calcWH(width2, height2);
755
+ props.resizeStopFn(evt, { w, h: h8 });
756
+ };
757
+ function _calcXY(left, top) {
758
+ let x2 = Math.round((left - margin.value[0]) / (cellWidth.value + margin.value[0]));
759
+ let y2 = Math.round((top - margin.value[1]) / (rowHeight.value + margin.value[1]));
760
+ x2 = clamp(x2, 0, cols.value - props.width);
761
+ y2 = clamp(y2, 0, maxRows.value - props.height);
762
+ return { x: x2, y: y2 };
763
+ }
764
+ function _calcWH(width2, height2) {
765
+ let w = Math.round((width2 + margin.value[0]) / (cellWidth.value + margin.value[0]));
766
+ let h8 = Math.round((height2 + margin.value[1]) / (rowHeight.value + margin.value[1]));
767
+ w = clamp(w, 0, cols.value - props.x);
768
+ h8 = clamp(h8, 0, maxRows.value - props.y);
769
+ return { w, h: h8 };
770
+ }
771
+ return {
772
+ x,
773
+ y,
774
+ width,
775
+ height,
776
+ dragging,
777
+ resizing,
778
+ style,
779
+ minWidth,
780
+ minHeight,
781
+ onDragStart,
782
+ onDrag,
783
+ onDragStop,
784
+ onResizeStart,
785
+ onResize,
786
+ onResizeStop
787
+ };
788
+ }
789
+
790
+ // src/components/freeDom.ts
791
+ var import_vue_demi12 = require("vue-demi");
792
+
793
+ // src/components/freeDomCore.ts
794
+ var import_vue_demi10 = require("vue-demi");
795
+ function noop() {
796
+ }
797
+ var freeDomCoreProps = {
798
+ userSelectHack: {
631
799
  type: Boolean,
800
+ default: true
801
+ },
802
+ startFn: {
803
+ type: Function,
804
+ default: noop
805
+ },
806
+ stopFn: {
807
+ type: Function,
808
+ default: noop
809
+ },
810
+ dragFn: {
811
+ type: Function,
812
+ default: noop
813
+ },
814
+ disabled: Boolean
815
+ };
816
+ var freeDomCore = (0, import_vue_demi10.defineComponent)({
817
+ name: "FreeDomCore",
818
+ props: freeDomCoreProps,
819
+ setup(props) {
820
+ const { only } = useDefaultSlot();
821
+ const dragging = (0, import_vue_demi10.ref)(false);
822
+ const domRef = (0, import_vue_demi10.ref)();
823
+ const node = (0, import_vue_demi10.computed)(() => domRef.value?.$el || domRef.value);
824
+ const ownerDoc = (0, import_vue_demi10.computed)(() => node.value?.ownerDocument);
825
+ const { lastX, lastY, create } = useCoreData(node);
826
+ let parentNode;
827
+ let parentRect;
828
+ (0, import_vue_demi10.onUnmounted)(() => {
829
+ if (!ownerDoc.value)
830
+ return;
831
+ if (props.userSelectHack)
832
+ _removeUserSelectStyle(ownerDoc.value);
833
+ ownerDoc.value.removeEventListener("mousemove", _handleDrag);
834
+ ownerDoc.value.removeEventListener("mouseup", _handleDragStop);
835
+ });
836
+ function mousedownFn(evt) {
837
+ return _handleDragstart(evt);
838
+ }
839
+ function mouseupFn(evt) {
840
+ _handleDragStop(evt);
841
+ }
842
+ function _addUserSelectStyle(doc) {
843
+ if (!doc)
844
+ return;
845
+ if (!doc.getElementById("free-dom-style-el")) {
846
+ const styleEl = doc.createElement("style");
847
+ styleEl.id = "free-dom-style-el";
848
+ styleEl.innerHTML = ".free-dom-transparent-selection *::selection {all: inherit;}";
849
+ doc.getElementsByTagName("head")[0].appendChild(styleEl);
850
+ }
851
+ if (doc.body)
852
+ doc.body.classList.add("free-dom-transparent-selection");
853
+ }
854
+ function _removeUserSelectStyle(doc) {
855
+ if (!doc)
856
+ return;
857
+ if (doc.body) {
858
+ doc.body.classList.remove("free-dom-transparent-selection");
859
+ }
860
+ const selection = doc.getSelection();
861
+ if (selection) {
862
+ selection.removeAllRanges();
863
+ }
864
+ }
865
+ function _handleDragstart(evt) {
866
+ if (props.disabled || !evt.target || !(evt.target instanceof node.value.ownerDocument.defaultView.Node))
867
+ return;
868
+ const { x, y } = _offsetFormat(evt);
869
+ const coreEvent = create(x, y);
870
+ props.startFn(evt, coreEvent);
871
+ lastX.value = x;
872
+ lastY.value = y;
873
+ dragging.value = true;
874
+ if (props.userSelectHack)
875
+ _addUserSelectStyle(ownerDoc.value);
876
+ ownerDoc.value?.addEventListener("mousemove", _handleDrag);
877
+ ownerDoc.value?.addEventListener("mouseup", _handleDragStop);
878
+ }
879
+ function _handleDragStop(evt) {
880
+ if (!dragging.value)
881
+ return;
882
+ const { x, y } = _offsetFormat(evt);
883
+ const coreEvent = create(x, y);
884
+ props.stopFn(evt, coreEvent);
885
+ if (props.userSelectHack)
886
+ _removeUserSelectStyle(ownerDoc.value);
887
+ dragging.value = false;
888
+ lastX.value = NaN;
889
+ lastY.value = NaN;
890
+ ownerDoc.value?.removeEventListener("mousemove", _handleDrag);
891
+ ownerDoc.value?.removeEventListener("mouseup", _handleDragStop);
892
+ }
893
+ function _handleDrag(evt) {
894
+ const { x, y } = _offsetFormat(evt);
895
+ const coreEvent = create(x, y);
896
+ props.dragFn(evt, coreEvent);
897
+ lastX.value = x;
898
+ lastY.value = y;
899
+ }
900
+ function _offsetFormat(evt) {
901
+ const parent = node.value?.offsetParent || ownerDoc.value.body;
902
+ const isBody = parent === parent.ownerDocument.body;
903
+ if (!parentNode || parentNode !== parent) {
904
+ parentNode = parent;
905
+ parentRect = isBody ? { left: 0, top: 0 } : parent.getBoundingClientRect();
906
+ }
907
+ const x = evt.clientX + parent.scrollLeft - parentRect.left;
908
+ const y = evt.clientY + parent.scrollTop - parentRect.top;
909
+ return { x, y };
910
+ }
911
+ return {
912
+ only,
913
+ domRef,
914
+ mousedownFn,
915
+ mouseupFn
916
+ };
917
+ },
918
+ render() {
919
+ return this.only ? (0, import_vue_demi10.h)(this.only, {
920
+ ref: "domRef",
921
+ onMousedown: (0, import_vue_demi10.withModifiers)(this.mousedownFn, ["stop"]),
922
+ onMouseup: this.mouseupFn
923
+ }) : null;
924
+ }
925
+ });
926
+ var freeDomCore_default = freeDomCore;
927
+
928
+ // src/components/resizeDomCore.ts
929
+ var import_vue_demi11 = require("vue-demi");
930
+ var Dots = ["t", "r", "l", "b", "lt", "lb", "rt", "rb"];
931
+ function noop2() {
932
+ }
933
+ var resizeDomCoreProps = {
934
+ dragOpts: {
935
+ type: Object,
936
+ default: () => ({})
937
+ },
938
+ width: {
939
+ type: Number,
940
+ default: 0
941
+ },
942
+ height: {
943
+ type: Number,
944
+ default: 0
945
+ },
946
+ scale: {
947
+ type: [Boolean, Array],
632
948
  default: void 0
633
949
  },
634
- preview: Boolean,
635
- move: Boolean,
636
- scale: [Boolean, Array],
637
- diff: {
950
+ startFn: {
951
+ type: Function,
952
+ default: noop2
953
+ },
954
+ stopFn: {
955
+ type: Function,
956
+ default: noop2
957
+ },
958
+ resizeFn: {
959
+ type: Function,
960
+ default: noop2
961
+ },
962
+ minWidth: {
638
963
  type: Number,
639
- default: 3
964
+ default: 50
640
965
  },
641
- handler: {
642
- type: String,
966
+ minHeight: {
967
+ type: Number,
968
+ default: 50
969
+ },
970
+ lockAspectRatio: Boolean
971
+ };
972
+ var resizeDomCore = (0, import_vue_demi11.defineComponent)({
973
+ name: "ResizeDomCore",
974
+ props: resizeDomCoreProps,
975
+ setup(props, { slots }) {
976
+ const { slots: _slots } = useDefaultSlot();
977
+ const dots = (0, import_vue_demi11.computed)(() => {
978
+ const _dots = props.scale;
979
+ return Array.isArray(_dots) ? _dots : Dots;
980
+ });
981
+ const lastRect = (0, import_vue_demi11.shallowRef)();
982
+ function runConstraints(width, height) {
983
+ const { lockAspectRatio } = props;
984
+ if (!props.minHeight && !props.minWidth && !lockAspectRatio)
985
+ return [width, height];
986
+ if (lockAspectRatio) {
987
+ const ratio = props.width / props.height;
988
+ const deltaW = width - props.width;
989
+ const deltaH = height - props.height;
990
+ if (Math.abs(deltaW) > Math.abs(deltaH * ratio)) {
991
+ height = width / ratio;
992
+ } else {
993
+ width = height * ratio;
994
+ }
995
+ }
996
+ width = Math.max(width, props.minWidth);
997
+ height = Math.max(height, props.minHeight);
998
+ return [width, height];
999
+ }
1000
+ function handleResize(handleName, axis) {
1001
+ return (evt, { node, deltaX, deltaY }) => {
1002
+ if (handleName === "start")
1003
+ lastRect.value = void 0;
1004
+ const canDragX = axis !== "t" && axis !== "b";
1005
+ const canDragY = axis !== "l" && axis !== "r";
1006
+ const axisH = axis[0];
1007
+ const axisV = axis[axis.length - 1];
1008
+ const handleRect = node.getBoundingClientRect();
1009
+ lastRect.value = handleRect;
1010
+ if (axisH === "l")
1011
+ deltaX = -deltaX;
1012
+ if (axisV === "t")
1013
+ deltaY = -deltaY;
1014
+ let width = props.width + (canDragX ? deltaX : 0);
1015
+ let height = props.height + (canDragY ? deltaY : 0);
1016
+ [width, height] = runConstraints(width, height);
1017
+ const sizeChanged = width !== props.width || height !== props.height;
1018
+ const fnName = `${handleName}Fn`;
1019
+ const cb = typeof props[fnName] === "function" ? props[fnName] : null;
1020
+ const shouldSkipCb = handleName === "resize" && !sizeChanged;
1021
+ if (cb && !shouldSkipCb) {
1022
+ cb(evt, { node, width, height, handle: axis });
1023
+ }
1024
+ if (handleName === "stop")
1025
+ lastRect.value = void 0;
1026
+ };
1027
+ }
1028
+ function renderResizehandler(axis) {
1029
+ if (!slots.handler) {
1030
+ return () => (0, import_vue_demi11.h)("i", {
1031
+ class: [
1032
+ "vv-resize-dom--handler",
1033
+ `vv-resize-dom--handler__${axis}`
1034
+ ]
1035
+ });
1036
+ }
1037
+ return () => slots.handler?.(axis);
1038
+ }
1039
+ return {
1040
+ dots,
1041
+ children: _slots,
1042
+ handleResize,
1043
+ renderResizehandler
1044
+ };
1045
+ },
1046
+ render() {
1047
+ return (0, import_vue_demi11.h)("div", {
1048
+ class: "vv-resize-dom--box"
1049
+ }, [
1050
+ this.children?.map((node) => (0, import_vue_demi11.h)(node)),
1051
+ this.dots.map((dot) => (0, import_vue_demi11.h)(freeDomCore_default, {
1052
+ class: [
1053
+ this.dragOpts.disabled && "vv-resize-dom--disabled"
1054
+ ],
1055
+ ...this.dragOpts,
1056
+ stopFn: this.handleResize("stop", dot),
1057
+ startFn: this.handleResize("start", dot),
1058
+ dragFn: this.handleResize("resize", dot)
1059
+ }, this.renderResizehandler(dot)))
1060
+ ]);
1061
+ }
1062
+ });
1063
+ var resizeDomCore_default = resizeDomCore;
1064
+
1065
+ // src/components/freeDom.ts
1066
+ function noop3() {
1067
+ }
1068
+ var freeDomProps = {
1069
+ modelValue: {
1070
+ type: Object,
1071
+ default: () => ({})
1072
+ },
1073
+ x: {
1074
+ type: Number,
1075
+ default: 0
1076
+ },
1077
+ y: {
1078
+ type: Number,
1079
+ default: 0
1080
+ },
1081
+ width: {
1082
+ type: Number,
1083
+ default: void 0
1084
+ },
1085
+ height: {
1086
+ type: Number,
643
1087
  default: void 0
644
1088
  },
645
- diagonal: {
1089
+ lockAspectRatio: Boolean,
1090
+ dragStartFn: {
1091
+ type: Function,
1092
+ default: noop3
1093
+ },
1094
+ dragStopFn: {
1095
+ type: Function,
1096
+ default: noop3
1097
+ },
1098
+ dargFn: {
1099
+ type: Function,
1100
+ default: noop3
1101
+ },
1102
+ resizeStartFn: {
1103
+ type: Function,
1104
+ default: noop3
1105
+ },
1106
+ resizeFn: {
1107
+ type: Function,
1108
+ default: noop3
1109
+ },
1110
+ resizeStopFn: {
1111
+ type: Function,
1112
+ default: noop3
1113
+ },
1114
+ autoSize: {
646
1115
  type: Boolean,
1116
+ default: true
1117
+ },
1118
+ minWidth: resizeDomCoreProps.minWidth,
1119
+ minHeight: resizeDomCoreProps.minHeight,
1120
+ disabledDrag: Boolean,
1121
+ disabledResize: Boolean,
1122
+ scale: resizeDomCoreProps.scale,
1123
+ fixNonMonospaced: Boolean
1124
+ };
1125
+ var freeDom = (0, import_vue_demi12.defineComponent)({
1126
+ name: "FreeDom",
1127
+ props: freeDomProps,
1128
+ emits: [
1129
+ "update:width",
1130
+ "update:height",
1131
+ "update:x",
1132
+ "update:y",
1133
+ "update:modelValue"
1134
+ ],
1135
+ setup(props, { emit, expose, slots }) {
1136
+ const domRef = (0, import_vue_demi12.ref)();
1137
+ const { slots: children } = useDefaultSlot();
1138
+ const {
1139
+ x,
1140
+ y,
1141
+ deltaX,
1142
+ deltaY,
1143
+ create,
1144
+ handleDrag,
1145
+ handleDragStop
1146
+ } = useDraggableData(props);
1147
+ const { width, height, syncSize: _syncSize } = useResizableData(props, domRef);
1148
+ const context = {
1149
+ _rect: (0, import_vue_demi12.reactive)({
1150
+ x,
1151
+ y,
1152
+ width,
1153
+ height,
1154
+ deltaX,
1155
+ deltaY
1156
+ }),
1157
+ trigger: () => {
1158
+ }
1159
+ };
1160
+ const sceneContext = useSceneContext(context, props);
1161
+ const syncSize = () => {
1162
+ _syncSize(
1163
+ sceneContext.fixNonMonospaced.value,
1164
+ sceneContext.minWidth.value,
1165
+ sceneContext.minHeight.value
1166
+ );
1167
+ };
1168
+ (0, import_vue_demi12.onMounted)(() => {
1169
+ props.autoSize && syncSize();
1170
+ });
1171
+ const style = (0, import_vue_demi12.computed)(() => ({
1172
+ position: "absolute",
1173
+ width: `${width.value}px`,
1174
+ height: `${height.value}px`,
1175
+ transform: `translate(${x.value}px, ${y.value}px)`
1176
+ }));
1177
+ const onDrag = (evt, coreData) => {
1178
+ const data = create(coreData);
1179
+ const newPos = {
1180
+ x: data.x,
1181
+ y: data.y,
1182
+ width: width.value,
1183
+ height: height.value
1184
+ };
1185
+ const isValid = sceneContext.check?.(newPos);
1186
+ if (!isValid)
1187
+ return;
1188
+ handleDrag(evt, data);
1189
+ sceneContext.emit("move");
1190
+ };
1191
+ const onDragStop = (evt, coreData) => {
1192
+ const newPos = {
1193
+ x: x.value,
1194
+ y: y.value,
1195
+ width: width.value,
1196
+ height: height.value
1197
+ };
1198
+ const isValid = sceneContext.check?.(newPos);
1199
+ if (!isValid) {
1200
+ x.value = clamp(x.value, 0, sceneContext.width);
1201
+ y.value = clamp(y.value, 0, sceneContext.height);
1202
+ }
1203
+ handleDragStop(evt, coreData);
1204
+ sceneContext.emit("moveup");
1205
+ emit("update:x", x.value);
1206
+ emit("update:y", y.value);
1207
+ emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
1208
+ };
1209
+ const onResize = (evt, { node, width: w, height: h8, handle: axis }) => {
1210
+ const offsetW = -(w - width.value);
1211
+ const offsetH = -(h8 - height.value);
1212
+ const axisH = axis[0];
1213
+ const axisV = axis[axis.length - 1];
1214
+ let _x = x.value;
1215
+ let _y = y.value;
1216
+ if (axisH === "l") {
1217
+ _x += offsetW;
1218
+ }
1219
+ if (axisV === "t") {
1220
+ _y += offsetH;
1221
+ }
1222
+ const isValid = sceneContext.check?.({ x: _x, y: _y, width: w, height: h8 });
1223
+ if (!isValid)
1224
+ return;
1225
+ width.value = w;
1226
+ height.value = h8;
1227
+ x.value = _x;
1228
+ y.value = _y;
1229
+ props.resizeFn(evt, { node, width: w, height: h8, handle: axis });
1230
+ sceneContext?.emit("move");
1231
+ };
1232
+ const onResizeStop = () => {
1233
+ const isValid = sceneContext.check?.({ x: x.value, y: y.value, width: width.value, height: height.value });
1234
+ if (!isValid) {
1235
+ x.value = clamp(x.value, 0, sceneContext.width);
1236
+ y.value = clamp(y.value, 0, sceneContext.height);
1237
+ }
1238
+ emit("update:width", width.value);
1239
+ emit("update:height", height.value);
1240
+ emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
1241
+ sceneContext.emit("moveup");
1242
+ };
1243
+ const resizeNode = () => (0, import_vue_demi12.h)(resizeDomCore_default, {
1244
+ width: width.value,
1245
+ height: height.value,
1246
+ lockAspectRatio: sceneContext.lockAspectRatio.value,
1247
+ dragOpts: { disabled: sceneContext.disabledResize.value },
1248
+ resizeFn: onResize,
1249
+ stopFn: onResizeStop,
1250
+ minHeight: sceneContext.minHeight.value,
1251
+ minWidth: sceneContext.minWidth.value,
1252
+ scale: sceneContext.scale.value
1253
+ }, {
1254
+ default: () => children.value,
1255
+ handler: slots.handler
1256
+ });
1257
+ expose({
1258
+ syncSize
1259
+ });
1260
+ return {
1261
+ domRef,
1262
+ style,
1263
+ onDragStop,
1264
+ onDrag,
1265
+ resizeNode,
1266
+ disabled: sceneContext.disabledDrag
1267
+ };
1268
+ },
1269
+ render() {
1270
+ return (0, import_vue_demi12.h)(freeDomCore_default, {
1271
+ ref: "domRef",
1272
+ class: "vv-free-dom--draggable",
1273
+ style: this.style,
1274
+ stopFn: this.onDragStop,
1275
+ dragFn: this.onDrag,
1276
+ disabled: this.disabled
1277
+ }, () => this.resizeNode());
1278
+ }
1279
+ });
1280
+ var freeDom_default = freeDom;
1281
+
1282
+ // src/components/freeDomWrap.ts
1283
+ var freeDomWrapProps = {
1284
+ width: {
1285
+ type: Number,
647
1286
  default: void 0
648
1287
  },
649
- grid: {
650
- type: Object,
1288
+ height: {
1289
+ type: Number,
651
1290
  default: void 0
652
- }
1291
+ },
1292
+ diff: {
1293
+ type: Number,
1294
+ default: 2
1295
+ },
1296
+ showLine: {
1297
+ type: Boolean,
1298
+ default: true
1299
+ },
1300
+ minWidth: freeDomProps.minWidth,
1301
+ minHeight: freeDomProps.minHeight,
1302
+ lockAspectRatio: freeDomProps.lockAspectRatio,
1303
+ disabledDrag: freeDomProps.disabledDrag,
1304
+ disabledResize: freeDomProps.disabledResize,
1305
+ scale: freeDomProps.scale,
1306
+ fixNonMonospaced: freeDomProps.fixNonMonospaced
653
1307
  };
654
- var FreeDomWrap = (0, import_vue_demi4.defineComponent)({
1308
+ var FreeDomWrap = (0, import_vue_demi13.defineComponent)({
655
1309
  name: "FreeDomWrap",
656
1310
  props: freeDomWrapProps,
657
1311
  setup(props) {
658
- const rectRef = (0, import_vue_demi4.shallowRef)(null);
659
- const rect = (0, import_core2.useElementBounding)(rectRef);
660
- const nodes = (0, import_vue_demi4.ref)([]);
1312
+ const eventBus = useEventBus();
1313
+ const rectRef = (0, import_vue_demi13.shallowRef)();
1314
+ const nodes = (0, import_vue_demi13.ref)([]);
1315
+ const width = (0, import_vue_demi13.ref)(props.width);
1316
+ const height = (0, import_vue_demi13.ref)(props.height);
1317
+ (0, import_vue_demi13.watchEffect)(() => {
1318
+ width.value = props.width;
1319
+ });
1320
+ (0, import_vue_demi13.watchEffect)(() => {
1321
+ height.value = props.height;
1322
+ });
1323
+ (0, import_vue_demi13.onMounted)(() => {
1324
+ if (!props.width || !props.height) {
1325
+ if (!rectRef.value)
1326
+ console.warn("[free-dom] cannot find element, width or height may be set to 0");
1327
+ const { width: w, height: h8 } = rectRef.value?.getBoundingClientRect() || {};
1328
+ if (!props.width)
1329
+ width.value = w || 0;
1330
+ if (!props.height)
1331
+ height.value = h8 || 0;
1332
+ }
1333
+ });
661
1334
  function register(uuid, node) {
662
1335
  nodes.value.push({ uuid, node });
663
1336
  }
664
1337
  function checkValid(pos) {
665
- const { x, y, width, height } = pos;
666
- return x >= 0 && x + width <= rect.width.value && y >= 0 && y + height <= rect.height.value;
1338
+ const { x, y, width: w, height: h8 } = pos;
1339
+ return x >= 0 && x + w <= width.value && y >= 0 && y + h8 <= height.value;
667
1340
  }
668
- (0, import_vue_demi4.provide)(
1341
+ (0, import_vue_demi13.provide)(
669
1342
  SceneToken,
670
- (0, import_vue_demi4.reactive)({
671
- ...(0, import_vue_demi4.toRefs)(props),
1343
+ (0, import_vue_demi13.reactive)({
1344
+ ...(0, import_vue_demi13.toRefs)(props),
672
1345
  nodes,
1346
+ width,
1347
+ height,
673
1348
  register,
674
- checkValid
1349
+ checkValid,
1350
+ on: eventBus.on,
1351
+ off: eventBus.off,
1352
+ emit: eventBus.emit
675
1353
  })
676
1354
  );
1355
+ const style = (0, import_vue_demi13.computed)(() => ({
1356
+ width: `${props.width}px`,
1357
+ height: `${props.height}px`
1358
+ }));
677
1359
  return {
678
- rectRef
1360
+ rectRef,
1361
+ style
679
1362
  };
680
1363
  },
681
1364
  render() {
682
1365
  const defaultSlot = typeof this.$slots.default === "function" ? this.$slots.default() : this.$slots.default;
683
- return (0, import_vue_demi4.h)("section", {
684
- ref: "rectRef"
685
- }, [defaultSlot, (0, import_vue_demi4.h)(markLine_default)]);
1366
+ return (0, import_vue_demi13.h)("section", {
1367
+ ref: "rectRef",
1368
+ class: "vv-free-dom--scene",
1369
+ style: this.style
1370
+ }, [defaultSlot, (0, import_vue_demi13.h)(markLine_default, { showLine: this.showLine })]);
1371
+ }
1372
+ });
1373
+
1374
+ // src/components/gridLayout.ts
1375
+ var import_vue_demi15 = require("vue-demi");
1376
+
1377
+ // src/components/gridItem.ts
1378
+ var import_vue_demi14 = require("vue-demi");
1379
+
1380
+ // src/components/tokens.ts
1381
+ var gridLayoutContextKey = Symbol("gridLayoutContext");
1382
+
1383
+ // src/components/gridItem.ts
1384
+ var noop4 = () => {
1385
+ };
1386
+ var gridItemProps = {
1387
+ x: {
1388
+ type: Number,
1389
+ required: true
1390
+ },
1391
+ y: {
1392
+ type: Number,
1393
+ required: true
1394
+ },
1395
+ width: {
1396
+ type: Number,
1397
+ required: true
1398
+ },
1399
+ height: {
1400
+ type: Number,
1401
+ required: true
1402
+ },
1403
+ dragStartFn: {
1404
+ type: Function,
1405
+ default: noop4
1406
+ },
1407
+ dragFn: {
1408
+ type: Function,
1409
+ default: noop4
1410
+ },
1411
+ dragEndFn: {
1412
+ type: Function,
1413
+ default: noop4
1414
+ },
1415
+ resizeStartFn: {
1416
+ type: Function,
1417
+ default: noop4
1418
+ },
1419
+ resizeFn: {
1420
+ type: Function,
1421
+ default: noop4
1422
+ },
1423
+ resizeStopFn: {
1424
+ type: Function,
1425
+ default: noop4
1426
+ },
1427
+ isDraggable: Boolean,
1428
+ isResizable: Boolean,
1429
+ scale: {
1430
+ type: resizeDomCoreProps.scale.type,
1431
+ default: () => ["rb"]
1432
+ }
1433
+ };
1434
+ var gridItemEmits = ["dragMove"];
1435
+ var GridItem = (0, import_vue_demi14.defineComponent)({
1436
+ name: "GridItem",
1437
+ props: gridItemProps,
1438
+ emits: gridItemEmits,
1439
+ setup(props) {
1440
+ const layout = (0, import_vue_demi14.inject)(gridLayoutContextKey);
1441
+ if (!layout) {
1442
+ throw new Error("TODO");
1443
+ }
1444
+ const {
1445
+ x,
1446
+ y,
1447
+ width,
1448
+ height,
1449
+ dragging,
1450
+ style,
1451
+ minWidth,
1452
+ minHeight,
1453
+ onDragStart,
1454
+ onDrag,
1455
+ onDragStop,
1456
+ onResizeStart,
1457
+ onResize,
1458
+ onResizeStop
1459
+ } = useLayoutItem(props, layout);
1460
+ const { only, slots } = useDefaultSlot();
1461
+ const resizeNode = (child) => {
1462
+ return (0, import_vue_demi14.h)(resizeDomCore_default, {
1463
+ width: width.value,
1464
+ height: height.value,
1465
+ scale: props.scale,
1466
+ dragOpts: {
1467
+ disabled: !props.isResizable
1468
+ },
1469
+ minWidth: minWidth.value,
1470
+ minHeight: minHeight.value,
1471
+ startFn: onResizeStart,
1472
+ resizeFn: onResize,
1473
+ stopFn: onResizeStop
1474
+ }, () => child);
1475
+ };
1476
+ const dragNode = (child) => (0, import_vue_demi14.h)(freeDomCore_default, {
1477
+ class: [
1478
+ dragging.value && "vv-grid-layout--item__draggable",
1479
+ "vv-grid-layout--item",
1480
+ !props.isDraggable && "vv-grid-layout--item__disabled"
1481
+ ],
1482
+ style: style.value,
1483
+ disabled: !props.isDraggable,
1484
+ startFn: onDragStart,
1485
+ stopFn: onDragStop,
1486
+ dragFn: onDrag
1487
+ }, () => resizeNode(child));
1488
+ return {
1489
+ x,
1490
+ y,
1491
+ width,
1492
+ height,
1493
+ child: only,
1494
+ slots,
1495
+ style,
1496
+ dragging,
1497
+ onDragStart,
1498
+ onDrag,
1499
+ onDragStop,
1500
+ onResizeStart,
1501
+ onResize,
1502
+ onResizeStop,
1503
+ dragNode
1504
+ };
1505
+ },
1506
+ render() {
1507
+ const node = this.slots;
1508
+ return this.dragNode(node);
1509
+ }
1510
+ });
1511
+
1512
+ // src/components/gridLayout.ts
1513
+ var gridLayoutProps = {
1514
+ style: {
1515
+ type: Object,
1516
+ default: () => ({})
1517
+ },
1518
+ modelValue: {
1519
+ type: Array,
1520
+ required: true,
1521
+ default: () => []
1522
+ },
1523
+ autoHeight: {
1524
+ type: Boolean,
1525
+ default: true
1526
+ },
1527
+ cols: {
1528
+ type: Number,
1529
+ default: 12
1530
+ },
1531
+ maxRows: {
1532
+ type: Number,
1533
+ default: Infinity
1534
+ },
1535
+ minW: {
1536
+ type: Number,
1537
+ default: 1
1538
+ },
1539
+ minH: {
1540
+ type: Number,
1541
+ default: 1
1542
+ },
1543
+ rowHeight: {
1544
+ type: Number,
1545
+ default: 150
1546
+ },
1547
+ width: {
1548
+ type: Number,
1549
+ default: 1200
1550
+ },
1551
+ margin: {
1552
+ type: Array,
1553
+ default: () => [10, 10]
1554
+ },
1555
+ containerPadding: {
1556
+ type: Array,
1557
+ default: void 0
1558
+ },
1559
+ disabledDrag: Boolean,
1560
+ disabledResize: Boolean,
1561
+ collision: Boolean
1562
+ };
1563
+ var GridLayout = (0, import_vue_demi15.defineComponent)({
1564
+ name: "GridLayout",
1565
+ props: gridLayoutProps,
1566
+ emits: ["update:modelValue"],
1567
+ setup(props, { emit }) {
1568
+ const layout = useLayout(props);
1569
+ (0, import_vue_demi15.provide)(gridLayoutContextKey, layout);
1570
+ const activeDrag = (0, import_vue_demi15.ref)(null);
1571
+ function processItem(node) {
1572
+ const key = node.key;
1573
+ if (!key)
1574
+ return;
1575
+ const config = layout.getItem(String(key));
1576
+ if (!config)
1577
+ return;
1578
+ const isDraggable = !config.static && !props.disabledDrag;
1579
+ const isResizable = !config.static && !props.disabledResize;
1580
+ return (0, import_vue_demi15.h)(GridItem, {
1581
+ x: config.x,
1582
+ y: config.y,
1583
+ width: config.w,
1584
+ height: config.h,
1585
+ isDraggable,
1586
+ isResizable,
1587
+ scale: config.scale,
1588
+ dragEndFn: (evt, rect) => {
1589
+ const { x, y } = rect;
1590
+ const _layout = layout.moveTo(config, x, y);
1591
+ emit("update:modelValue", _layout);
1592
+ activeDrag.value = null;
1593
+ },
1594
+ dragStartFn: () => {
1595
+ },
1596
+ dragFn: (evt, data) => {
1597
+ if (!config)
1598
+ return;
1599
+ const placeholder2 = {
1600
+ x: config.x,
1601
+ y: config.y,
1602
+ width: config.w,
1603
+ height: config.h
1604
+ };
1605
+ const { x, y } = data;
1606
+ layout.moveTo(config, x, y);
1607
+ activeDrag.value = placeholder2;
1608
+ },
1609
+ resizeFn: (evt, data) => {
1610
+ const placeholder2 = {
1611
+ x: config.x,
1612
+ y: config.y,
1613
+ width: config.w,
1614
+ height: config.h
1615
+ };
1616
+ activeDrag.value = placeholder2;
1617
+ const { w, h: h8 } = data;
1618
+ layout.resizeTo(config, w, h8);
1619
+ },
1620
+ resizeStopFn: (evt, data) => {
1621
+ const { w, h: h8 } = data;
1622
+ layout.resizeTo(config, w, h8);
1623
+ activeDrag.value = null;
1624
+ }
1625
+ }, () => node);
1626
+ }
1627
+ function placeholder() {
1628
+ if (!activeDrag.value)
1629
+ return null;
1630
+ const { x, y, width, height } = activeDrag.value;
1631
+ return (0, import_vue_demi15.h)(GridItem, {
1632
+ class: "vv-grid-layout--placeholder",
1633
+ x,
1634
+ y,
1635
+ width,
1636
+ height,
1637
+ move: false
1638
+ });
1639
+ }
1640
+ return {
1641
+ processItem,
1642
+ placeholder,
1643
+ layout
1644
+ };
1645
+ },
1646
+ render() {
1647
+ const mergedStyle = {
1648
+ ...this.style || {},
1649
+ height: this.layout.calContainerHeight()
1650
+ };
1651
+ const defaultSlot = typeof this.$slots.default === "function" ? this.$slots.default() : this.$slots.default || [];
1652
+ return (0, import_vue_demi15.h)("div", {
1653
+ class: "vv-grid-layout",
1654
+ style: mergedStyle
1655
+ }, [
1656
+ defaultSlot.map(this.processItem),
1657
+ this.placeholder()
1658
+ ]);
686
1659
  }
687
1660
  });
1661
+ var gridLayout_default = GridLayout;
688
1662
 
689
1663
  // src/index.ts
690
- var freeDom = FreeDom;
691
- var freeScene = FreeDomWrap;
1664
+ var FreeScene = FreeDomWrap;
1665
+ var GridLayout2 = gridLayout_default;
1666
+ var FreeDom = freeDom_default;
692
1667
  // Annotate the CommonJS export names for ESM import in node:
693
1668
  0 && (module.exports = {
694
- freeDom,
695
- freeScene
1669
+ FreeDom,
1670
+ FreeScene,
1671
+ GridLayout
696
1672
  });