@sepveneto/free-dom 0.10.0 → 0.11.0

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.mjs CHANGED
@@ -1,5 +1,15 @@
1
1
  // src/components/freeDomWrap.ts
2
- import { computed as computed8, defineComponent as defineComponent5, onMounted as onMounted3, provide, reactive as reactive3, ref as ref9, shallowRef as shallowRef4, toRefs, watchEffect as watchEffect4 } from "vue-demi";
2
+ import {
3
+ computed as computed11,
4
+ defineComponent as defineComponent6,
5
+ onMounted as onMounted5,
6
+ provide as provide2,
7
+ reactive as reactive5,
8
+ ref as ref13,
9
+ shallowRef as shallowRef6,
10
+ toRefs as toRefs2,
11
+ watchEffect as watchEffect6
12
+ } from "vue-demi";
3
13
 
4
14
  // src/util/tokens.ts
5
15
  var SceneToken = Symbol("Scene");
@@ -45,6 +55,29 @@ function log(...args) {
45
55
  return;
46
56
  console.log("[grid-layout]", ...args);
47
57
  }
58
+ function addUserSelectStyle(doc) {
59
+ if (!doc)
60
+ return;
61
+ if (!doc.getElementById("free-dom-style-el")) {
62
+ const styleEl = doc.createElement("style");
63
+ styleEl.id = "free-dom-style-el";
64
+ styleEl.innerHTML = ".free-dom-transparent-selection *::selection {all: inherit;}";
65
+ doc.getElementsByTagName("head")[0].appendChild(styleEl);
66
+ }
67
+ if (doc.body)
68
+ doc.body.classList.add("free-dom-transparent-selection");
69
+ }
70
+ function removeUserSelectStyle(doc) {
71
+ if (!doc)
72
+ return;
73
+ if (doc.body) {
74
+ doc.body.classList.remove("free-dom-transparent-selection");
75
+ }
76
+ const selection = doc.getSelection();
77
+ if (selection) {
78
+ selection.removeAllRanges();
79
+ }
80
+ }
48
81
 
49
82
  // src/components/markLine.ts
50
83
  import { computed, defineComponent, h as h2, inject, onBeforeUnmount, reactive, shallowRef } from "vue-demi";
@@ -58,6 +91,7 @@ var markLine_default = defineComponent({
58
91
  const lines = shallowRef(lineType);
59
92
  const diff = computed(() => SceneContext.diff / SceneContext.transformScale);
60
93
  const nodes = SceneContext.nodes;
94
+ const staticNodes = computed(() => nodes.filter((node) => !node.node.selected));
61
95
  const lineStatus = reactive({
62
96
  xt: {
63
97
  show: false,
@@ -84,78 +118,80 @@ var markLine_default = defineComponent({
84
118
  pos: 0
85
119
  }
86
120
  });
87
- const runConstraints = (uuid) => {
88
- const current = nodes.find((node) => node.uuid === uuid)?.node ?? {};
121
+ const runConstraints = (uuid, withoutConstraint) => {
122
+ const current = nodes.find((node) => node.uuid === uuid)?.node;
123
+ if (!current)
124
+ return;
89
125
  clearStatus();
90
- nodes.forEach((node) => {
126
+ staticNodes.value.forEach((node) => {
91
127
  if (node.uuid === uuid)
92
128
  return;
93
129
  const _current = normalize(current._rect);
94
130
  const _target = normalize(node.node._rect);
95
- if (isNearly(_current.top, _target.top)) {
131
+ if (isNearly(_current.top, _target.top, withoutConstraint)) {
96
132
  lineStatus.xt = {
97
133
  show: true,
98
134
  pos: _target.top
99
135
  };
100
136
  current._rect.y = _target.top;
101
137
  }
102
- if (isNearly(_current.bottom, _target.top)) {
138
+ if (isNearly(_current.bottom, _target.top, withoutConstraint)) {
103
139
  lineStatus.xt = {
104
140
  show: true,
105
141
  pos: _target.top
106
142
  };
107
143
  current._rect.y = _target.top - _current.height;
108
144
  }
109
- if (isNearly(_current.centerY, _target.centerY)) {
145
+ if (isNearly(_current.centerY, _target.centerY, withoutConstraint)) {
110
146
  lineStatus.xc = {
111
147
  show: true,
112
148
  pos: _target.centerY
113
149
  };
114
150
  current._rect.y = _target.centerY - _current.height / 2;
115
151
  }
116
- if (isNearly(_current.top, _target.bottom)) {
152
+ if (isNearly(_current.top, _target.bottom, withoutConstraint)) {
117
153
  lineStatus.xb = {
118
154
  show: true,
119
155
  pos: _target.bottom
120
156
  };
121
157
  current._rect.y = _target.bottom;
122
158
  }
123
- if (isNearly(_current.bottom, _target.bottom)) {
159
+ if (isNearly(_current.bottom, _target.bottom, withoutConstraint)) {
124
160
  lineStatus.xb = {
125
161
  show: true,
126
162
  pos: _target.bottom
127
163
  };
128
164
  current._rect.y = _target.bottom - _current.height;
129
165
  }
130
- if (isNearly(_current.left, _target.left)) {
166
+ if (isNearly(_current.left, _target.left, withoutConstraint)) {
131
167
  lineStatus.yl = {
132
168
  show: true,
133
169
  pos: _target.left
134
170
  };
135
171
  current._rect.x = _target.left;
136
172
  }
137
- if (isNearly(_current.right, _target.left)) {
173
+ if (isNearly(_current.right, _target.left, withoutConstraint)) {
138
174
  lineStatus.yl = {
139
175
  show: true,
140
176
  pos: _target.left
141
177
  };
142
178
  current._rect.x = _target.left - _current.width;
143
179
  }
144
- if (isNearly(_current.centerX, _target.centerX)) {
180
+ if (isNearly(_current.centerX, _target.centerX, withoutConstraint)) {
145
181
  lineStatus.yc = {
146
182
  show: true,
147
183
  pos: _target.centerX
148
184
  };
149
185
  current._rect.x = _target.centerX - _current.width / 2;
150
186
  }
151
- if (isNearly(_current.left, _target.right)) {
187
+ if (isNearly(_current.left, _target.right, withoutConstraint)) {
152
188
  lineStatus.yr = {
153
189
  show: true,
154
190
  pos: _target.right
155
191
  };
156
192
  current._rect.x = _target.right;
157
193
  }
158
- if (isNearly(_current.right, _target.right)) {
194
+ if (isNearly(_current.right, _target.right, withoutConstraint)) {
159
195
  lineStatus.yr = {
160
196
  show: true,
161
197
  pos: _target.right
@@ -192,8 +228,9 @@ var markLine_default = defineComponent({
192
228
  centerY: rect.y + rect.height / 2
193
229
  };
194
230
  }
195
- function isNearly(curr, target) {
196
- return Math.abs(curr - target) <= diff.value;
231
+ function isNearly(curr, target, withoutConstraint) {
232
+ const _diff = withoutConstraint ? 0 : diff.value;
233
+ return Math.abs(curr - target) <= _diff;
197
234
  }
198
235
  return {
199
236
  lines,
@@ -217,13 +254,11 @@ var markLine_default = defineComponent({
217
254
  import { ref, unref, watch } from "vue-demi";
218
255
 
219
256
  // src/hooks/use-default-slot.ts
220
- import { computed as computed2, useSlots } from "vue-demi";
257
+ import { useSlots } from "vue-demi";
221
258
  function useDefaultSlot() {
222
259
  const slots = useSlots();
223
- const slotList = computed2(() => {
224
- return typeof slots.default === "function" ? slots.default() : slots.default;
225
- });
226
- const only = computed2(() => slotList.value?.[0]);
260
+ const slotList = typeof slots.default === "function" ? slots.default() : slots.default;
261
+ const only = slotList?.[0];
227
262
  return {
228
263
  slots: slotList,
229
264
  only
@@ -322,22 +357,23 @@ function useDraggableData(props) {
322
357
  }
323
358
 
324
359
  // src/hooks/use-scene-context.ts
325
- import { computed as computed3, inject as inject2, onMounted, onUnmounted } from "vue-demi";
360
+ import { computed as computed2, inject as inject2, onMounted, onUnmounted } from "vue-demi";
326
361
  var id = 0;
327
362
  function useSceneContext(context, props) {
328
363
  const SceneContext = inject2(SceneToken, void 0);
329
364
  const uuid = id++;
330
- const handle = computed3(() => SceneContext?.handle || props.handle);
331
- const lockAspectRatio = computed3(() => SceneContext?.lockAspectRatio || props.lockAspectRatio);
332
- const minWidth = computed3(() => SceneContext?.minWidth || props.minWidth);
333
- const minHeight = computed3(() => SceneContext?.minHeight || props.minHeight);
334
- const disabledDrag = computed3(() => SceneContext?.disabledDrag || props.disabledDrag);
335
- const disabledResize = computed3(() => SceneContext?.disabledResize || props.disabledResize);
336
- const scale = computed3(() => SceneContext?.scale || props.scale);
337
- const transformScale = computed3(() => SceneContext?.transformScale || props.transformScale);
338
- const fixNonMonospaced = computed3(() => {
365
+ const handle = computed2(() => SceneContext?.handle || props.handle);
366
+ const lockAspectRatio = computed2(() => SceneContext?.lockAspectRatio || props.lockAspectRatio);
367
+ const minWidth = computed2(() => SceneContext?.minWidth || props.minWidth);
368
+ const minHeight = computed2(() => SceneContext?.minHeight || props.minHeight);
369
+ const disabledDrag = computed2(() => SceneContext?.disabledDrag || props.disabledDrag);
370
+ const disabledResize = computed2(() => SceneContext?.disabledResize || props.disabledResize);
371
+ const scale = computed2(() => SceneContext?.scale || props.scale);
372
+ const transformScale = computed2(() => SceneContext?.transformScale || props.transformScale);
373
+ const fixNonMonospaced = computed2(() => {
339
374
  return SceneContext?.fixNonMonospaced || props.fixNonMonospaced;
340
375
  });
376
+ const keyboard = computed2(() => SceneContext?.keyboard || props.keyboard);
341
377
  onMounted(() => {
342
378
  SceneContext?.register(uuid, context);
343
379
  });
@@ -355,11 +391,15 @@ function useSceneContext(context, props) {
355
391
  return SceneContext.correct(pos);
356
392
  }
357
393
  return {
358
- emit: (name) => SceneContext?.emit(name, uuid),
394
+ emit: (name, withoutConstraint) => {
395
+ SceneContext?.emit(name, uuid, withoutConstraint);
396
+ },
359
397
  check,
360
398
  correct,
399
+ clearSelectState: SceneContext?.clearSelectState,
361
400
  width: SceneContext?.width,
362
401
  height: SceneContext?.height,
402
+ history: SceneContext?.history,
363
403
  scale,
364
404
  handle,
365
405
  lockAspectRatio,
@@ -368,14 +408,15 @@ function useSceneContext(context, props) {
368
408
  disabledDrag,
369
409
  disabledResize,
370
410
  fixNonMonospaced,
371
- transformScale
411
+ transformScale,
412
+ keyboard
372
413
  };
373
414
  }
374
415
 
375
416
  // src/hooks/use-event-bus.ts
376
417
  import { ref as ref4 } from "vue-demi";
418
+ var callbacks = ref4({});
377
419
  function useEventBus() {
378
- const callbacks = ref4({});
379
420
  const on = (name, cb) => {
380
421
  if (!callbacks.value[name]) {
381
422
  callbacks.value[name] = [cb];
@@ -386,9 +427,9 @@ function useEventBus() {
386
427
  const off = (name) => {
387
428
  callbacks.value[name].length = 0;
388
429
  };
389
- const emit = (name, args) => {
430
+ const emit = (name, ...args) => {
390
431
  const fns = callbacks.value[name] || [];
391
- fns.forEach((fn) => fn(args));
432
+ fns.forEach((fn) => fn(...args));
392
433
  };
393
434
  return {
394
435
  on,
@@ -422,9 +463,9 @@ function useResizableData(props, domRef) {
422
463
  if (fixNonMonospaced) {
423
464
  await document.fonts.ready;
424
465
  }
425
- const { width: w, height: h5 } = window.getComputedStyle(domRef.value.$el);
466
+ const { width: w, height: h7 } = window.getComputedStyle(domRef.value.$el);
426
467
  width.value = Math.max(Math.ceil(parseFloat(w)), minWidth);
427
- height.value = Math.max(Math.ceil(parseFloat(h5)), minHeight);
468
+ height.value = Math.max(Math.ceil(parseFloat(h7)), minHeight);
428
469
  }
429
470
  return {
430
471
  width,
@@ -434,22 +475,22 @@ function useResizableData(props, domRef) {
434
475
  }
435
476
 
436
477
  // src/hooks/use-layout.ts
437
- import { computed as computed4, ref as ref6, shallowRef as shallowRef2, watchEffect as watchEffect3 } from "vue-demi";
478
+ import { computed as computed3, ref as ref6, shallowRef as shallowRef2, watchEffect as watchEffect3 } from "vue-demi";
438
479
  function useLayout(props) {
439
480
  const layout = shallowRef2(props.modelValue);
440
481
  watchEffect3(() => {
441
482
  layout.value = props.modelValue;
442
483
  });
443
- const cellWidth = computed4(
484
+ const cellWidth = computed3(
444
485
  () => (props.width - margin.value[0] * (cols.value - 1) - (containerPadding.value?.[0] || margin.value[0]) * 2) / props.cols
445
486
  );
446
- const cols = computed4(() => props.cols);
447
- const rowHeight = computed4(() => props.rowHeight);
448
- const margin = computed4(() => props.margin);
449
- const maxRows = computed4(() => props.maxRows);
450
- const containerPadding = computed4(() => props.containerPadding);
451
- const minW = computed4(() => props.minW);
452
- const minH = computed4(() => props.minH);
487
+ const cols = computed3(() => props.cols);
488
+ const rowHeight = computed3(() => props.rowHeight);
489
+ const margin = computed3(() => props.margin);
490
+ const maxRows = computed3(() => props.maxRows);
491
+ const containerPadding = computed3(() => props.containerPadding);
492
+ const minW = computed3(() => props.minW);
493
+ const minH = computed3(() => props.minH);
453
494
  function getItem(key) {
454
495
  return layout.value.find((item) => item.i === key);
455
496
  }
@@ -546,10 +587,10 @@ function useLayout(props) {
546
587
  layout.value = _normalize(_layout);
547
588
  return layout.value;
548
589
  }
549
- function resizeTo(item, w, h5) {
590
+ function resizeTo(item, w, h7) {
550
591
  let hasCollisions = false;
551
592
  if (!props.collision) {
552
- const collisions = layout.value.filter((l) => _collides(l, { ...item, w, h: h5 }));
593
+ const collisions = layout.value.filter((l) => _collides(l, { ...item, w, h: h7 }));
553
594
  hasCollisions = collisions.length > 0;
554
595
  if (hasCollisions) {
555
596
  let leastX = Infinity;
@@ -568,7 +609,7 @@ function useLayout(props) {
568
609
  }
569
610
  if (!hasCollisions) {
570
611
  item.w = w;
571
- item.h = h5;
612
+ item.h = h7;
572
613
  }
573
614
  layout.value = _normalize([...layout.value]);
574
615
  }
@@ -686,44 +727,44 @@ function useLayoutItem(props, layout) {
686
727
  const { cellWidth, margin, rowHeight, cols, maxRows, containerPadding: cPadding } = layout;
687
728
  const dragging = ref6();
688
729
  const resizing = ref6();
689
- const containerPadding = computed4(() => cPadding.value || margin.value);
690
- const x = computed4(() => {
730
+ const containerPadding = computed3(() => cPadding.value || margin.value);
731
+ const x = computed3(() => {
691
732
  if (!dragging.value) {
692
733
  return Math.round(props.x * (cellWidth.value + margin.value[0]) + containerPadding.value[0]);
693
734
  } else {
694
735
  return Math.round(dragging.value.x);
695
736
  }
696
737
  });
697
- const y = computed4(() => {
738
+ const y = computed3(() => {
698
739
  if (!dragging.value) {
699
740
  return Math.round(props.y * (rowHeight.value + margin.value[1]) + containerPadding.value[1]);
700
741
  } else {
701
742
  return Math.round(dragging.value.y);
702
743
  }
703
744
  });
704
- const width = computed4(() => {
745
+ const width = computed3(() => {
705
746
  if (!resizing.value) {
706
747
  return Math.round(cellWidth.value * props.width + Math.max(0, props.width - 1) * margin.value[0]);
707
748
  } else {
708
749
  return Math.round(resizing.value.width);
709
750
  }
710
751
  });
711
- const height = computed4(() => {
752
+ const height = computed3(() => {
712
753
  if (!resizing.value) {
713
754
  return Math.round(rowHeight.value * props.height + Math.max(0, props.height - 1) * margin.value[1]);
714
755
  } else {
715
756
  return Math.round(resizing.value.height);
716
757
  }
717
758
  });
718
- const minWidth = computed4(() => {
759
+ const minWidth = computed3(() => {
719
760
  const minW = layout.minW.value;
720
761
  return Math.round(cellWidth.value * minW + Math.max(0, minW - 1) * margin.value[0]);
721
762
  });
722
- const minHeight = computed4(() => {
763
+ const minHeight = computed3(() => {
723
764
  const minH = layout.minH.value;
724
765
  return Math.round(rowHeight.value * minH + Math.max(0, minH - 1) * margin.value[1]);
725
766
  });
726
- const style = computed4(() => {
767
+ const style = computed3(() => {
727
768
  return {
728
769
  position: "absolute",
729
770
  width: `${width.value}px`,
@@ -764,15 +805,15 @@ function useLayoutItem(props, layout) {
764
805
  };
765
806
  const onResize = (evt, coreData) => {
766
807
  const { width: width2, height: height2 } = coreData;
767
- const { w, h: h5 } = _calcWH(width2, height2);
808
+ const { w, h: h7 } = _calcWH(width2, height2);
768
809
  resizing.value = { width: width2, height: height2 };
769
- props.resizeFn(evt, { w, h: h5 });
810
+ props.resizeFn(evt, { w, h: h7 });
770
811
  };
771
812
  const onResizeStop = (evt, coreData) => {
772
813
  resizing.value = void 0;
773
814
  const { width: width2, height: height2 } = coreData;
774
- const { w, h: h5 } = _calcWH(width2, height2);
775
- props.resizeStopFn(evt, { w, h: h5 });
815
+ const { w, h: h7 } = _calcWH(width2, height2);
816
+ props.resizeStopFn(evt, { w, h: h7 });
776
817
  };
777
818
  function _calcXY(left, top) {
778
819
  let x2 = Math.round((left - margin.value[0]) / (cellWidth.value + margin.value[0]));
@@ -783,10 +824,10 @@ function useLayoutItem(props, layout) {
783
824
  }
784
825
  function _calcWH(width2, height2) {
785
826
  let w = Math.round((width2 + margin.value[0]) / (cellWidth.value + margin.value[0]));
786
- let h5 = Math.round((height2 + margin.value[1]) / (rowHeight.value + margin.value[1]));
827
+ let h7 = Math.round((height2 + margin.value[1]) / (rowHeight.value + margin.value[1]));
787
828
  w = clamp(w, 0, cols.value - props.x);
788
- h5 = clamp(h5, 0, maxRows.value - props.y);
789
- return { w, h: h5 };
829
+ h7 = clamp(h7, 0, maxRows.value - props.y);
830
+ return { w, h: h7 };
790
831
  }
791
832
  return {
792
833
  x,
@@ -807,12 +848,474 @@ function useLayoutItem(props, layout) {
807
848
  };
808
849
  }
809
850
 
851
+ // src/hooks/use-mask.ts
852
+ import { computed as computed6, h as h4, ref as ref9 } from "vue-demi";
853
+
854
+ // ../../node_modules/.pnpm/@vueuse+shared@10.7.1_vue@3.4.6/node_modules/@vueuse/shared/index.mjs
855
+ import { shallowRef as shallowRef3, watchEffect as watchEffect4, readonly, ref as ref7, watch as watch2, customRef, getCurrentScope, onScopeDispose, effectScope, getCurrentInstance, provide, inject as inject3, isVue3, version, isRef, unref as unref3, computed as computed4, reactive as reactive2, toRefs as toRefs$1, toRef as toRef$1, isVue2 as isVue22, set as set$1, onBeforeMount, nextTick, onBeforeUnmount as onBeforeUnmount2, onMounted as onMounted2, onUnmounted as onUnmounted2, isReactive } from "vue-demi";
856
+ function tryOnScopeDispose(fn) {
857
+ if (getCurrentScope()) {
858
+ onScopeDispose(fn);
859
+ return true;
860
+ }
861
+ return false;
862
+ }
863
+ function toValue(r) {
864
+ return typeof r === "function" ? r() : unref3(r);
865
+ }
866
+ var isClient = typeof window !== "undefined" && typeof document !== "undefined";
867
+ var isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
868
+ var toString = Object.prototype.toString;
869
+ var isObject = (val) => toString.call(val) === "[object Object]";
870
+ var noop = () => {
871
+ };
872
+ var isIOS = /* @__PURE__ */ getIsIOS();
873
+ function getIsIOS() {
874
+ var _a, _b;
875
+ return isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && (/iP(ad|hone|od)/.test(window.navigator.userAgent) || ((_b = window == null ? void 0 : window.navigator) == null ? void 0 : _b.maxTouchPoints) > 2 && /iPad|Macintosh/.test(window == null ? void 0 : window.navigator.userAgent));
876
+ }
877
+ function cacheStringFunction(fn) {
878
+ const cache = /* @__PURE__ */ Object.create(null);
879
+ return (str) => {
880
+ const hit = cache[str];
881
+ return hit || (cache[str] = fn(str));
882
+ };
883
+ }
884
+ var hyphenateRE = /\B([A-Z])/g;
885
+ var hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
886
+ var camelizeRE = /-(\w)/g;
887
+ var camelize = cacheStringFunction((str) => {
888
+ return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
889
+ });
890
+ function getLifeCycleTarget(target) {
891
+ return target || getCurrentInstance();
892
+ }
893
+ function tryOnMounted(fn, sync = true, target) {
894
+ const instance = getLifeCycleTarget();
895
+ if (instance)
896
+ onMounted2(fn, target);
897
+ else if (sync)
898
+ fn();
899
+ else
900
+ nextTick(fn);
901
+ }
902
+
903
+ // ../../node_modules/.pnpm/@vueuse+core@10.7.1_vue@3.4.6/node_modules/@vueuse/core/index.mjs
904
+ import { isRef as isRef2, ref as ref8, shallowRef as shallowRef4, watchEffect as watchEffect5, computed as computed5, inject as inject4, isVue3 as isVue32, version as version2, defineComponent as defineComponent2, h as h3, TransitionGroup, shallowReactive, Fragment, watch as watch3, getCurrentInstance as getCurrentInstance2, customRef as customRef2, onUpdated, onMounted as onMounted3, readonly as readonly2, nextTick as nextTick2, reactive as reactive3, markRaw, unref as unref4, getCurrentScope as getCurrentScope2, isVue2 as isVue23, set, del, isReadonly, onBeforeUpdate } from "vue-demi";
905
+ function unrefElement(elRef) {
906
+ var _a;
907
+ const plain = toValue(elRef);
908
+ return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
909
+ }
910
+ var defaultWindow = isClient ? window : void 0;
911
+ var defaultDocument = isClient ? window.document : void 0;
912
+ var defaultNavigator = isClient ? window.navigator : void 0;
913
+ var defaultLocation = isClient ? window.location : void 0;
914
+ function useEventListener(...args) {
915
+ let target;
916
+ let events;
917
+ let listeners;
918
+ let options;
919
+ if (typeof args[0] === "string" || Array.isArray(args[0])) {
920
+ [events, listeners, options] = args;
921
+ target = defaultWindow;
922
+ } else {
923
+ [target, events, listeners, options] = args;
924
+ }
925
+ if (!target)
926
+ return noop;
927
+ if (!Array.isArray(events))
928
+ events = [events];
929
+ if (!Array.isArray(listeners))
930
+ listeners = [listeners];
931
+ const cleanups = [];
932
+ const cleanup = () => {
933
+ cleanups.forEach((fn) => fn());
934
+ cleanups.length = 0;
935
+ };
936
+ const register = (el, event, listener, options2) => {
937
+ el.addEventListener(event, listener, options2);
938
+ return () => el.removeEventListener(event, listener, options2);
939
+ };
940
+ const stopWatch = watch3(
941
+ () => [unrefElement(target), toValue(options)],
942
+ ([el, options2]) => {
943
+ cleanup();
944
+ if (!el)
945
+ return;
946
+ const optionsClone = isObject(options2) ? { ...options2 } : options2;
947
+ cleanups.push(
948
+ ...events.flatMap((event) => {
949
+ return listeners.map((listener) => register(el, event, listener, optionsClone));
950
+ })
951
+ );
952
+ },
953
+ { immediate: true, flush: "post" }
954
+ );
955
+ const stop = () => {
956
+ stopWatch();
957
+ cleanup();
958
+ };
959
+ tryOnScopeDispose(stop);
960
+ return stop;
961
+ }
962
+ var _iOSWorkaround = false;
963
+ function onClickOutside(target, handler, options = {}) {
964
+ const { window: window2 = defaultWindow, ignore = [], capture = true, detectIframe = false } = options;
965
+ if (!window2)
966
+ return noop;
967
+ if (isIOS && !_iOSWorkaround) {
968
+ _iOSWorkaround = true;
969
+ Array.from(window2.document.body.children).forEach((el) => el.addEventListener("click", noop));
970
+ window2.document.documentElement.addEventListener("click", noop);
971
+ }
972
+ let shouldListen = true;
973
+ const shouldIgnore = (event) => {
974
+ return ignore.some((target2) => {
975
+ if (typeof target2 === "string") {
976
+ return Array.from(window2.document.querySelectorAll(target2)).some((el) => el === event.target || event.composedPath().includes(el));
977
+ } else {
978
+ const el = unrefElement(target2);
979
+ return el && (event.target === el || event.composedPath().includes(el));
980
+ }
981
+ });
982
+ };
983
+ const listener = (event) => {
984
+ const el = unrefElement(target);
985
+ if (!el || el === event.target || event.composedPath().includes(el))
986
+ return;
987
+ if (event.detail === 0)
988
+ shouldListen = !shouldIgnore(event);
989
+ if (!shouldListen) {
990
+ shouldListen = true;
991
+ return;
992
+ }
993
+ handler(event);
994
+ };
995
+ const cleanup = [
996
+ useEventListener(window2, "click", listener, { passive: true, capture }),
997
+ useEventListener(window2, "pointerdown", (e) => {
998
+ const el = unrefElement(target);
999
+ shouldListen = !shouldIgnore(e) && !!(el && !e.composedPath().includes(el));
1000
+ }, { passive: true }),
1001
+ detectIframe && useEventListener(window2, "blur", (event) => {
1002
+ setTimeout(() => {
1003
+ var _a;
1004
+ const el = unrefElement(target);
1005
+ if (((_a = window2.document.activeElement) == null ? void 0 : _a.tagName) === "IFRAME" && !(el == null ? void 0 : el.contains(window2.document.activeElement)))
1006
+ handler(event);
1007
+ }, 0);
1008
+ })
1009
+ ].filter(Boolean);
1010
+ const stop = () => cleanup.forEach((fn) => fn());
1011
+ return stop;
1012
+ }
1013
+ function useMounted() {
1014
+ const isMounted = ref8(false);
1015
+ if (getCurrentInstance2()) {
1016
+ onMounted3(() => {
1017
+ isMounted.value = true;
1018
+ });
1019
+ }
1020
+ return isMounted;
1021
+ }
1022
+ function useSupported(callback) {
1023
+ const isMounted = useMounted();
1024
+ return computed5(() => {
1025
+ isMounted.value;
1026
+ return Boolean(callback());
1027
+ });
1028
+ }
1029
+ function useMutationObserver(target, callback, options = {}) {
1030
+ const { window: window2 = defaultWindow, ...mutationOptions } = options;
1031
+ let observer;
1032
+ const isSupported = useSupported(() => window2 && "MutationObserver" in window2);
1033
+ const cleanup = () => {
1034
+ if (observer) {
1035
+ observer.disconnect();
1036
+ observer = void 0;
1037
+ }
1038
+ };
1039
+ const stopWatch = watch3(
1040
+ () => unrefElement(target),
1041
+ (el) => {
1042
+ cleanup();
1043
+ if (isSupported.value && window2 && el) {
1044
+ observer = new MutationObserver(callback);
1045
+ observer.observe(el, mutationOptions);
1046
+ }
1047
+ },
1048
+ { immediate: true }
1049
+ );
1050
+ const takeRecords = () => {
1051
+ return observer == null ? void 0 : observer.takeRecords();
1052
+ };
1053
+ const stop = () => {
1054
+ cleanup();
1055
+ stopWatch();
1056
+ };
1057
+ tryOnScopeDispose(stop);
1058
+ return {
1059
+ isSupported,
1060
+ stop,
1061
+ takeRecords
1062
+ };
1063
+ }
1064
+ function useResizeObserver(target, callback, options = {}) {
1065
+ const { window: window2 = defaultWindow, ...observerOptions } = options;
1066
+ let observer;
1067
+ const isSupported = useSupported(() => window2 && "ResizeObserver" in window2);
1068
+ const cleanup = () => {
1069
+ if (observer) {
1070
+ observer.disconnect();
1071
+ observer = void 0;
1072
+ }
1073
+ };
1074
+ const targets = computed5(() => Array.isArray(target) ? target.map((el) => unrefElement(el)) : [unrefElement(target)]);
1075
+ const stopWatch = watch3(
1076
+ targets,
1077
+ (els) => {
1078
+ cleanup();
1079
+ if (isSupported.value && window2) {
1080
+ observer = new ResizeObserver(callback);
1081
+ for (const _el of els)
1082
+ _el && observer.observe(_el, observerOptions);
1083
+ }
1084
+ },
1085
+ { immediate: true, flush: "post", deep: true }
1086
+ );
1087
+ const stop = () => {
1088
+ cleanup();
1089
+ stopWatch();
1090
+ };
1091
+ tryOnScopeDispose(stop);
1092
+ return {
1093
+ isSupported,
1094
+ stop
1095
+ };
1096
+ }
1097
+ function useElementBounding(target, options = {}) {
1098
+ const {
1099
+ reset = true,
1100
+ windowResize = true,
1101
+ windowScroll = true,
1102
+ immediate = true
1103
+ } = options;
1104
+ const height = ref8(0);
1105
+ const bottom = ref8(0);
1106
+ const left = ref8(0);
1107
+ const right = ref8(0);
1108
+ const top = ref8(0);
1109
+ const width = ref8(0);
1110
+ const x = ref8(0);
1111
+ const y = ref8(0);
1112
+ function update() {
1113
+ const el = unrefElement(target);
1114
+ if (!el) {
1115
+ if (reset) {
1116
+ height.value = 0;
1117
+ bottom.value = 0;
1118
+ left.value = 0;
1119
+ right.value = 0;
1120
+ top.value = 0;
1121
+ width.value = 0;
1122
+ x.value = 0;
1123
+ y.value = 0;
1124
+ }
1125
+ return;
1126
+ }
1127
+ const rect = el.getBoundingClientRect();
1128
+ height.value = rect.height;
1129
+ bottom.value = rect.bottom;
1130
+ left.value = rect.left;
1131
+ right.value = rect.right;
1132
+ top.value = rect.top;
1133
+ width.value = rect.width;
1134
+ x.value = rect.x;
1135
+ y.value = rect.y;
1136
+ }
1137
+ useResizeObserver(target, update);
1138
+ watch3(() => unrefElement(target), (ele) => !ele && update());
1139
+ useMutationObserver(target, update, {
1140
+ attributeFilter: ["style", "class"]
1141
+ });
1142
+ if (windowScroll)
1143
+ useEventListener("scroll", update, { capture: true, passive: true });
1144
+ if (windowResize)
1145
+ useEventListener("resize", update, { passive: true });
1146
+ tryOnMounted(() => {
1147
+ if (immediate)
1148
+ update();
1149
+ });
1150
+ return {
1151
+ height,
1152
+ bottom,
1153
+ left,
1154
+ right,
1155
+ top,
1156
+ width,
1157
+ x,
1158
+ y,
1159
+ update
1160
+ };
1161
+ }
1162
+ var DEFAULT_UNITS = [
1163
+ { max: 6e4, value: 1e3, name: "second" },
1164
+ { max: 276e4, value: 6e4, name: "minute" },
1165
+ { max: 72e6, value: 36e5, name: "hour" },
1166
+ { max: 5184e5, value: 864e5, name: "day" },
1167
+ { max: 24192e5, value: 6048e5, name: "week" },
1168
+ { max: 28512e6, value: 2592e6, name: "month" },
1169
+ { max: Number.POSITIVE_INFINITY, value: 31536e6, name: "year" }
1170
+ ];
1171
+
1172
+ // src/hooks/use-mask.ts
1173
+ function useMask(target, nodes) {
1174
+ const eventBus = useEventBus();
1175
+ const startX = ref9(0);
1176
+ const startY = ref9(0);
1177
+ const lastX = ref9(0);
1178
+ const lastY = ref9(0);
1179
+ const history = useOperateHistory(nodes);
1180
+ const hasEmit = ref9(false);
1181
+ const style = computed6(() => {
1182
+ const width = lastX.value - startX.value;
1183
+ const height = lastY.value - startY.value;
1184
+ return {
1185
+ visibility: selecting.value ? "visible" : "hidden",
1186
+ border: "2px solid rgb(0,120,215)",
1187
+ background: "rgb(0,120,215,0.3)",
1188
+ position: "absolute",
1189
+ top: startY.value + (height < 0 ? height : 0) + "px",
1190
+ left: startX.value + (width < 0 ? width : 0) + "px",
1191
+ width: Math.abs(width) + "px",
1192
+ height: Math.abs(height) + "px"
1193
+ };
1194
+ });
1195
+ const selecting = ref9(false);
1196
+ const rect = useElementBounding(target);
1197
+ const ownerDoc = computed6(() => unrefElement(target)?.ownerDocument);
1198
+ function checkNode() {
1199
+ nodes.value.forEach((node) => {
1200
+ const rect2 = node.node._rect;
1201
+ if (rect2.x == void 0 || // eslint-disable-next-line eqeqeq
1202
+ rect2.y == void 0 || // eslint-disable-next-line eqeqeq
1203
+ rect2.width == void 0 || // eslint-disable-next-line eqeqeq
1204
+ rect2.height == void 0)
1205
+ return false;
1206
+ const x1 = rect2.x;
1207
+ const y1 = rect2.y;
1208
+ const x2 = x1 + rect2.width;
1209
+ const y2 = y1 + rect2.height;
1210
+ node.node.selected = inArea(x1, y1, x2, y2);
1211
+ });
1212
+ }
1213
+ function inArea(x1, y1, x2, y2) {
1214
+ const areaStartX = Math.min(startX.value, lastX.value);
1215
+ const areaStartY = Math.min(startY.value, lastY.value);
1216
+ const areaEndX = Math.max(startX.value, lastX.value);
1217
+ const areaEndY = Math.max(startY.value, lastY.value);
1218
+ const crossX = isCrossing(areaStartX, areaEndX, x1, x2, Math.abs(x1 - x2) / 5);
1219
+ const crossY = isCrossing(areaStartY, areaEndY, y1, y2, Math.abs(y1 - y2) / 5);
1220
+ return crossX && crossY;
1221
+ }
1222
+ function isCrossing(a, b, c, d, standard) {
1223
+ return Math.max(a, c) - Math.min(b, d) <= -standard;
1224
+ }
1225
+ function offsetFormat(evt) {
1226
+ const offsetX = evt.clientX - rect.x.value;
1227
+ const offsetY = evt.clientY - rect.y.value;
1228
+ return {
1229
+ x: offsetX,
1230
+ y: offsetY
1231
+ };
1232
+ }
1233
+ function handleMousedown(evt) {
1234
+ addUserSelectStyle(ownerDoc.value);
1235
+ const { x: offsetX, y: offsetY } = offsetFormat(evt);
1236
+ selecting.value = true;
1237
+ startX.value = offsetX;
1238
+ startY.value = offsetY;
1239
+ lastX.value = offsetX;
1240
+ lastY.value = offsetY;
1241
+ document.addEventListener("mouseup", handleMouseup);
1242
+ }
1243
+ function handleMousemove(evt) {
1244
+ if (!selecting.value)
1245
+ return;
1246
+ if (!hasEmit.value) {
1247
+ eventBus.emit("batch-select", "start");
1248
+ hasEmit.value = true;
1249
+ }
1250
+ const { x: offsetX, y: offsetY } = offsetFormat(evt);
1251
+ if (lastX.value === offsetX && lastY.value === offsetY)
1252
+ return;
1253
+ lastX.value = offsetX;
1254
+ lastY.value = offsetY;
1255
+ handleBatchSelect();
1256
+ }
1257
+ function handleMouseup() {
1258
+ removeUserSelectStyle(ownerDoc.value);
1259
+ selecting.value = false;
1260
+ hasEmit.value = false;
1261
+ if (lastX.value === startX.value && lastY.value === startY.value) {
1262
+ } else {
1263
+ history.push({ type: "batch-select" });
1264
+ document.removeEventListener("mouseup", handleMouseup);
1265
+ }
1266
+ lastX.value = 0;
1267
+ lastY.value = 0;
1268
+ startX.value = 0;
1269
+ startY.value = 0;
1270
+ setTimeout(() => {
1271
+ eventBus.emit("batch-select", "end");
1272
+ });
1273
+ }
1274
+ function renderMask() {
1275
+ return h4("div", {
1276
+ id: "mask",
1277
+ style: style.value
1278
+ });
1279
+ }
1280
+ async function handleBatchSelect() {
1281
+ checkNode();
1282
+ }
1283
+ return {
1284
+ selecting,
1285
+ renderMask,
1286
+ handleMousedown,
1287
+ handleMousemove
1288
+ };
1289
+ }
1290
+
1291
+ // src/hooks/use-operate-history.ts
1292
+ import { computed as computed7, ref as ref10 } from "vue-demi";
1293
+ var records = ref10([]);
1294
+ var state = ref10({
1295
+ canClear: false
1296
+ });
1297
+ function useOperateHistory(nodes) {
1298
+ const lastOperate = computed7(() => records.value.slice(-1)[0]?.type);
1299
+ function push(operate) {
1300
+ records.value.push({
1301
+ ...operate,
1302
+ data: nodes
1303
+ });
1304
+ }
1305
+ return {
1306
+ state,
1307
+ records,
1308
+ lastOperate,
1309
+ push
1310
+ };
1311
+ }
1312
+
810
1313
  // src/components/freeDom.ts
811
- import { computed as computed7, defineComponent as defineComponent4, onMounted as onMounted2, reactive as reactive2, ref as ref8 } from "vue-demi";
1314
+ import { computed as computed10, defineComponent as defineComponent5, isVue2 as isVue25, onMounted as onMounted4, reactive as reactive4, ref as ref12 } from "vue-demi";
812
1315
 
813
1316
  // src/components/freeDomCore.ts
814
- import { computed as computed5, defineComponent as defineComponent2, isVue2 as isVue22, onUnmounted as onUnmounted2, ref as ref7 } from "vue-demi";
815
- function noop() {
1317
+ import { computed as computed8, defineComponent as defineComponent3, isVue2 as isVue24, onUnmounted as onUnmounted3, ref as ref11 } from "vue-demi";
1318
+ function noop2() {
816
1319
  }
817
1320
  var freeDomCoreProps = {
818
1321
  userSelectHack: {
@@ -821,15 +1324,15 @@ var freeDomCoreProps = {
821
1324
  },
822
1325
  startFn: {
823
1326
  type: Function,
824
- default: noop
1327
+ default: noop2
825
1328
  },
826
1329
  stopFn: {
827
1330
  type: Function,
828
- default: noop
1331
+ default: noop2
829
1332
  },
830
1333
  dragFn: {
831
1334
  type: Function,
832
- default: noop
1335
+ default: noop2
833
1336
  },
834
1337
  disabled: Boolean,
835
1338
  scale: {
@@ -837,23 +1340,24 @@ var freeDomCoreProps = {
837
1340
  default: 1
838
1341
  }
839
1342
  };
840
- var freeDomCore = defineComponent2({
1343
+ var freeDomCore = defineComponent3({
841
1344
  name: "FreeDomCore",
842
1345
  props: freeDomCoreProps,
843
1346
  setup(props) {
844
- const { only } = useDefaultSlot();
845
- const dragging = ref7(false);
846
- const coreRef = ref7();
847
- const node = computed5(() => coreRef.value?.$el || coreRef.value);
848
- const ownerDoc = computed5(() => node.value?.ownerDocument);
1347
+ const dragging = ref11(false);
1348
+ const coreRef = ref11();
1349
+ const node = computed8(() => coreRef.value?.$el || coreRef.value);
1350
+ const ownerDoc = computed8(() => node.value?.ownerDocument);
849
1351
  const { lastX, lastY, create } = useCoreData(node);
1352
+ const startX = ref11(NaN);
1353
+ const startY = ref11(NaN);
850
1354
  let parentNode;
851
1355
  let parentRect;
852
- onUnmounted2(() => {
1356
+ onUnmounted3(() => {
853
1357
  if (!ownerDoc.value)
854
1358
  return;
855
1359
  if (props.userSelectHack)
856
- _removeUserSelectStyle(ownerDoc.value);
1360
+ removeUserSelectStyle(ownerDoc.value);
857
1361
  ownerDoc.value.removeEventListener("mousemove", _handleDrag);
858
1362
  ownerDoc.value.removeEventListener("mouseup", _handleDragStop);
859
1363
  });
@@ -863,51 +1367,33 @@ var freeDomCore = defineComponent2({
863
1367
  function mouseupFn(evt) {
864
1368
  _handleDragStop(evt);
865
1369
  }
866
- function _addUserSelectStyle(doc) {
867
- if (!doc)
868
- return;
869
- if (!doc.getElementById("free-dom-style-el")) {
870
- const styleEl = doc.createElement("style");
871
- styleEl.id = "free-dom-style-el";
872
- styleEl.innerHTML = ".free-dom-transparent-selection *::selection {all: inherit;}";
873
- doc.getElementsByTagName("head")[0].appendChild(styleEl);
874
- }
875
- if (doc.body)
876
- doc.body.classList.add("free-dom-transparent-selection");
877
- }
878
- function _removeUserSelectStyle(doc) {
879
- if (!doc)
880
- return;
881
- if (doc.body) {
882
- doc.body.classList.remove("free-dom-transparent-selection");
883
- }
884
- const selection = doc.getSelection();
885
- if (selection) {
886
- selection.removeAllRanges();
887
- }
888
- }
889
1370
  function _handleDragstart(evt) {
890
1371
  if (props.disabled || !evt.target || !(evt.target instanceof node.value.ownerDocument.defaultView.Node))
891
1372
  return;
892
1373
  const { x, y } = _offsetFormat(evt);
893
1374
  const coreEvent = create(x, y);
894
1375
  props.startFn(evt, coreEvent);
1376
+ startX.value = x;
1377
+ startY.value = y;
895
1378
  lastX.value = x;
896
1379
  lastY.value = y;
897
1380
  dragging.value = true;
898
1381
  if (props.userSelectHack)
899
- _addUserSelectStyle(ownerDoc.value);
1382
+ addUserSelectStyle(ownerDoc.value);
900
1383
  ownerDoc.value?.addEventListener("mousemove", _handleDrag);
901
1384
  ownerDoc.value?.addEventListener("mouseup", _handleDragStop);
902
1385
  }
903
1386
  function _handleDragStop(evt) {
904
1387
  if (!dragging.value)
905
1388
  return;
906
- const { x, y } = _offsetFormat(evt);
907
- const coreEvent = create(x, y);
908
- props.stopFn(evt, coreEvent);
1389
+ if (startX.value === lastX.value && startY.value === lastY.value) {
1390
+ } else {
1391
+ const { x, y } = _offsetFormat(evt);
1392
+ const coreEvent = create(x, y);
1393
+ props.stopFn(evt, coreEvent);
1394
+ }
909
1395
  if (props.userSelectHack)
910
- _removeUserSelectStyle(ownerDoc.value);
1396
+ removeUserSelectStyle(ownerDoc.value);
911
1397
  dragging.value = false;
912
1398
  lastX.value = NaN;
913
1399
  lastY.value = NaN;
@@ -933,13 +1419,13 @@ var freeDomCore = defineComponent2({
933
1419
  return { x, y };
934
1420
  }
935
1421
  return {
936
- only,
937
1422
  coreRef,
938
1423
  mousedownFn,
939
1424
  mouseupFn
940
1425
  };
941
1426
  },
942
1427
  render() {
1428
+ const { only } = useDefaultSlot();
943
1429
  const vue2Props = {
944
1430
  on: {
945
1431
  mousedown: (evt) => {
@@ -958,12 +1444,12 @@ var freeDomCore = defineComponent2({
958
1444
  };
959
1445
  const res = createRender(
960
1446
  // @ts-expect-error: maybe vue2
961
- this.only,
1447
+ only,
962
1448
  { ref: (el) => {
963
1449
  this.coreRef = el;
964
1450
  } },
965
- isVue22 ? {} : vue3Props,
966
- isVue22 ? vue2Props.on : {}
1451
+ isVue24 ? {} : vue3Props,
1452
+ isVue24 ? vue2Props.on : {}
967
1453
  );
968
1454
  if (typeof res === "function") {
969
1455
  return res();
@@ -975,9 +1461,9 @@ var freeDomCore = defineComponent2({
975
1461
  var freeDomCore_default = freeDomCore;
976
1462
 
977
1463
  // src/components/resizeDomCore.ts
978
- import { computed as computed6, defineComponent as defineComponent3, h as h3, shallowRef as shallowRef3 } from "vue-demi";
1464
+ import { computed as computed9, defineComponent as defineComponent4, h as h5, shallowRef as shallowRef5 } from "vue-demi";
979
1465
  var Dots = ["t", "r", "l", "b", "lt", "lb", "rt", "rb"];
980
- function noop2() {
1466
+ function noop3() {
981
1467
  }
982
1468
  var resizeDomCoreProps = {
983
1469
  dragOpts: {
@@ -998,15 +1484,15 @@ var resizeDomCoreProps = {
998
1484
  },
999
1485
  startFn: {
1000
1486
  type: Function,
1001
- default: noop2
1487
+ default: noop3
1002
1488
  },
1003
1489
  stopFn: {
1004
1490
  type: Function,
1005
- default: noop2
1491
+ default: noop3
1006
1492
  },
1007
1493
  resizeFn: {
1008
1494
  type: Function,
1009
- default: noop2
1495
+ default: noop3
1010
1496
  },
1011
1497
  minWidth: {
1012
1498
  type: Number,
@@ -1018,16 +1504,15 @@ var resizeDomCoreProps = {
1018
1504
  },
1019
1505
  lockAspectRatio: Boolean
1020
1506
  };
1021
- var resizeDomCore = defineComponent3({
1507
+ var resizeDomCore = defineComponent4({
1022
1508
  name: "ResizeDomCore",
1023
1509
  props: resizeDomCoreProps,
1024
1510
  setup(props, { slots }) {
1025
- const { slots: _slots } = useDefaultSlot();
1026
- const dots = computed6(() => {
1511
+ const dots = computed9(() => {
1027
1512
  const _dots = props.scale;
1028
1513
  return Array.isArray(_dots) ? _dots : Dots;
1029
1514
  });
1030
- const lastRect = shallowRef3();
1515
+ const lastRect = shallowRef5();
1031
1516
  function runConstraints(width, height) {
1032
1517
  const { lockAspectRatio } = props;
1033
1518
  if (!props.minHeight && !props.minWidth && !lockAspectRatio)
@@ -1076,7 +1561,8 @@ var resizeDomCore = defineComponent3({
1076
1561
  }
1077
1562
  function renderResizehandler(axis) {
1078
1563
  if (!slots.handler) {
1079
- return () => h3("i", {
1564
+ return () => h5("i", {
1565
+ dataType: "handler",
1080
1566
  class: [
1081
1567
  "vv-resize-dom--handler",
1082
1568
  `vv-resize-dom--handler__${axis}`
@@ -1087,14 +1573,14 @@ var resizeDomCore = defineComponent3({
1087
1573
  }
1088
1574
  return {
1089
1575
  dots,
1090
- children: _slots,
1091
1576
  handleResize,
1092
1577
  renderResizehandler
1093
1578
  };
1094
1579
  },
1095
1580
  render() {
1581
+ const { slots: children } = useDefaultSlot();
1096
1582
  const slots = [
1097
- ...this.children || [],
1583
+ ...children || [],
1098
1584
  this.dots.map((dot) => {
1099
1585
  return createRender(
1100
1586
  freeDomCore_default,
@@ -1117,13 +1603,14 @@ var resizeDomCore = defineComponent3({
1117
1603
  var resizeDomCore_default = resizeDomCore;
1118
1604
 
1119
1605
  // src/components/freeDom.ts
1120
- function noop3() {
1606
+ function noop4() {
1121
1607
  }
1122
1608
  var freeDomProps = {
1123
1609
  modelValue: {
1124
1610
  type: Object,
1125
1611
  default: () => ({})
1126
1612
  },
1613
+ keyboard: Boolean,
1127
1614
  x: {
1128
1615
  type: Number,
1129
1616
  default: 0
@@ -1147,27 +1634,27 @@ var freeDomProps = {
1147
1634
  lockAspectRatio: Boolean,
1148
1635
  dragStartFn: {
1149
1636
  type: Function,
1150
- default: noop3
1637
+ default: noop4
1151
1638
  },
1152
1639
  dragStopFn: {
1153
1640
  type: Function,
1154
- default: noop3
1641
+ default: noop4
1155
1642
  },
1156
1643
  dragFn: {
1157
1644
  type: Function,
1158
- default: noop3
1645
+ default: noop4
1159
1646
  },
1160
1647
  resizeStartFn: {
1161
1648
  type: Function,
1162
- default: noop3
1649
+ default: noop4
1163
1650
  },
1164
1651
  resizeFn: {
1165
1652
  type: Function,
1166
- default: noop3
1653
+ default: noop4
1167
1654
  },
1168
1655
  resizeStopFn: {
1169
1656
  type: Function,
1170
- default: noop3
1657
+ default: noop4
1171
1658
  },
1172
1659
  autoSize: {
1173
1660
  type: Boolean,
@@ -1184,7 +1671,7 @@ var freeDomProps = {
1184
1671
  },
1185
1672
  fixNonMonospaced: Boolean
1186
1673
  };
1187
- var freeDom = defineComponent4({
1674
+ var freeDom = defineComponent5({
1188
1675
  name: "FreeDom",
1189
1676
  props: freeDomProps,
1190
1677
  emits: [
@@ -1195,7 +1682,12 @@ var freeDom = defineComponent4({
1195
1682
  "update:modelValue"
1196
1683
  ],
1197
1684
  setup(props, { emit, expose, slots }) {
1198
- const domRef = ref8();
1685
+ const domRef = ref12();
1686
+ const isBatchSelecting = ref12(false);
1687
+ const eventBus = useEventBus();
1688
+ eventBus.on("batch-select", (state2) => {
1689
+ isBatchSelecting.value = state2 === "start";
1690
+ });
1199
1691
  const {
1200
1692
  x,
1201
1693
  y,
@@ -1207,8 +1699,10 @@ var freeDom = defineComponent4({
1207
1699
  handleDragStop
1208
1700
  } = useDraggableData(props);
1209
1701
  const { width, height, syncSize: _syncSize } = useResizableData(props, domRef);
1702
+ const selected = ref12(false);
1210
1703
  const context = {
1211
- _rect: reactive2({
1704
+ selected,
1705
+ _rect: reactive4({
1212
1706
  x,
1213
1707
  y,
1214
1708
  width,
@@ -1220,7 +1714,12 @@ var freeDom = defineComponent4({
1220
1714
  emit("update:modelValue", pos);
1221
1715
  }
1222
1716
  };
1223
- const sceneContext = useSceneContext(context, props);
1717
+ const sceneContext = useSceneContext(context, reactive4(props));
1718
+ onClickOutside(domRef, () => {
1719
+ if (!selected.value || isBatchSelecting.value)
1720
+ return;
1721
+ selected.value = false;
1722
+ }, { ignore: [sceneContext.clearSelectState && ".vv-free-dom--draggable"] });
1224
1723
  const syncSize = () => {
1225
1724
  _syncSize(
1226
1725
  sceneContext.fixNonMonospaced.value,
@@ -1228,13 +1727,13 @@ var freeDom = defineComponent4({
1228
1727
  sceneContext.minHeight.value
1229
1728
  );
1230
1729
  };
1231
- const canDrag = ref8(false);
1232
- onMounted2(() => {
1730
+ const canDrag = ref12(false);
1731
+ onMounted4(() => {
1233
1732
  props.autoSize && syncSize();
1234
1733
  const pos = sceneContext.correct(context._rect);
1235
1734
  context.trigger({ x: pos.x, y: pos.y, w: pos.width, h: pos.height });
1236
1735
  });
1237
- const style = computed7(() => ({
1736
+ const style = computed10(() => ({
1238
1737
  width: `${width.value}px`,
1239
1738
  height: `${height.value}px`,
1240
1739
  transform: `translate(${x.value}px, ${y.value}px)`
@@ -1253,7 +1752,7 @@ var freeDom = defineComponent4({
1253
1752
  if (!isValid)
1254
1753
  return;
1255
1754
  handleDrag(evt, data);
1256
- sceneContext.emit("move");
1755
+ sceneContext.emit("move", evt.shiftKey);
1257
1756
  };
1258
1757
  const onDragStop = (evt, coreData) => {
1259
1758
  if (!canDrag.value)
@@ -1274,6 +1773,7 @@ var freeDom = defineComponent4({
1274
1773
  emit("update:x", x.value);
1275
1774
  emit("update:y", y.value);
1276
1775
  emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
1776
+ sceneContext.history?.push({ type: "move-end" });
1277
1777
  };
1278
1778
  const onDragStart = (evt, coreData) => {
1279
1779
  const handle = sceneContext.handle.value;
@@ -1291,9 +1791,9 @@ var freeDom = defineComponent4({
1291
1791
  }
1292
1792
  canDrag.value && handleDragStart(evt, coreData);
1293
1793
  };
1294
- const onResize = (evt, { node, width: w, height: h5, handle: axis }) => {
1794
+ const onResize = (evt, { node, width: w, height: h7, handle: axis }) => {
1295
1795
  const offsetW = -(w - width.value);
1296
- const offsetH = -(h5 - height.value);
1796
+ const offsetH = -(h7 - height.value);
1297
1797
  const axisH = axis[0];
1298
1798
  const axisV = axis[axis.length - 1];
1299
1799
  let _x = x.value;
@@ -1304,14 +1804,14 @@ var freeDom = defineComponent4({
1304
1804
  if (axisV === "t") {
1305
1805
  _y += offsetH;
1306
1806
  }
1307
- const isValid = sceneContext.check?.({ x: _x, y: _y, width: w, height: h5 });
1807
+ const isValid = sceneContext.check?.({ x: _x, y: _y, width: w, height: h7 });
1308
1808
  if (!isValid)
1309
1809
  return;
1310
1810
  width.value = w;
1311
- height.value = h5;
1811
+ height.value = h7;
1312
1812
  x.value = _x;
1313
1813
  y.value = _y;
1314
- props.resizeFn(evt, { node, width: w, height: h5, handle: axis });
1814
+ props.resizeFn(evt, { node, width: w, height: h7, handle: axis });
1315
1815
  sceneContext?.emit("move");
1316
1816
  };
1317
1817
  const onResizeStop = (evt, data) => {
@@ -1325,6 +1825,7 @@ var freeDom = defineComponent4({
1325
1825
  emit("update:height", height.value);
1326
1826
  emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
1327
1827
  sceneContext.emit("moveup");
1828
+ sceneContext.history?.push({ type: "resize-end" });
1328
1829
  };
1329
1830
  const onResizeStart = (evt, data) => {
1330
1831
  props.resizeStartFn(evt, data);
@@ -1347,17 +1848,65 @@ var freeDom = defineComponent4({
1347
1848
  };
1348
1849
  return createRender(resizeDomCore_default, {}, props2)(slots);
1349
1850
  };
1851
+ function handleSelect(evt) {
1852
+ if (evt.ctrlKey) {
1853
+ selected.value = !selected.value;
1854
+ sceneContext.history?.push({ type: "select" });
1855
+ } else if (!selected.value) {
1856
+ sceneContext.clearSelectState?.();
1857
+ selected.value = true;
1858
+ sceneContext.history?.push({ type: "select" });
1859
+ }
1860
+ }
1861
+ function handleKeyboard(evt) {
1862
+ if (!canDrag.value || !sceneContext.keyboard.value)
1863
+ return;
1864
+ evt.preventDefault();
1865
+ switch (evt.key) {
1866
+ case "ArrowUp":
1867
+ y.value -= 1;
1868
+ break;
1869
+ case "ArrowDown":
1870
+ y.value += 1;
1871
+ break;
1872
+ case "ArrowLeft":
1873
+ x.value -= 1;
1874
+ break;
1875
+ case "ArrowRight":
1876
+ x.value += 1;
1877
+ break;
1878
+ }
1879
+ const newPos = {
1880
+ x: x.value,
1881
+ y: y.value,
1882
+ width: width.value,
1883
+ height: height.value
1884
+ };
1885
+ const isValid = sceneContext.check?.(newPos);
1886
+ if (!isValid) {
1887
+ x.value = clamp(x.value, 0, sceneContext.width);
1888
+ y.value = clamp(y.value, 0, sceneContext.height);
1889
+ }
1890
+ emit("update:x", x.value);
1891
+ emit("update:y", y.value);
1892
+ emit("update:modelValue", { x: x.value, y: y.value, w: width.value, h: height.value });
1893
+ sceneContext.emit("move", true);
1894
+ }
1350
1895
  expose?.({
1351
1896
  syncSize
1352
1897
  });
1353
1898
  return {
1899
+ selected,
1354
1900
  domRef,
1355
1901
  style,
1356
1902
  onDragStop,
1357
1903
  onDrag,
1358
1904
  onDragStart,
1359
1905
  resizeNode,
1360
- disabled: sceneContext.disabledDrag
1906
+ handleKeyboard,
1907
+ handleSelect,
1908
+ disabled: sceneContext.disabledDrag,
1909
+ scale: sceneContext.transformScale
1361
1910
  };
1362
1911
  },
1363
1912
  render() {
@@ -1365,17 +1914,36 @@ var freeDom = defineComponent4({
1365
1914
  startFn: this.onDragStart,
1366
1915
  stopFn: this.onDragStop,
1367
1916
  dragFn: this.onDrag,
1368
- disabled: this.disabled
1917
+ disabled: this.disabled,
1918
+ scale: this.scale,
1919
+ keyboard: this.keyboard
1920
+ };
1921
+ const vue2Listener = {
1922
+ on: {
1923
+ click: this.handleSelect,
1924
+ keydown: this.handleKeyboard
1925
+ }
1926
+ };
1927
+ const vue3Props = {
1928
+ ...props,
1929
+ onClick: this.handleSelect,
1930
+ onKeydown: this.handleKeyboard
1369
1931
  };
1370
1932
  const slots = () => this.resizeNode();
1371
1933
  return createRender(
1372
1934
  freeDomCore_default,
1373
1935
  {
1374
1936
  ref: "domRef",
1375
- class: ["vv-free-dom--draggable", this.disabled && "vv-free-dom--draggable__disabled"],
1937
+ tabindex: -1,
1938
+ class: [
1939
+ "vv-free-dom--draggable",
1940
+ this.disabled && "vv-free-dom--draggable__disabled",
1941
+ this.selected && "vv-free-dom--draggable__selected"
1942
+ ],
1376
1943
  style: this.style
1377
1944
  },
1378
- props
1945
+ isVue25 ? props : vue3Props,
1946
+ isVue25 ? vue2Listener.on : {}
1379
1947
  )?.(slots);
1380
1948
  }
1381
1949
  });
@@ -1403,6 +1971,7 @@ var freeDomWrapProps = {
1403
1971
  type: Number,
1404
1972
  default: 1
1405
1973
  },
1974
+ keyboard: Boolean,
1406
1975
  handle: freeDomProps.handle,
1407
1976
  minWidth: freeDomProps.minWidth,
1408
1977
  minHeight: freeDomProps.minHeight,
@@ -1412,32 +1981,47 @@ var freeDomWrapProps = {
1412
1981
  scale: freeDomProps.scale,
1413
1982
  fixNonMonospaced: freeDomProps.fixNonMonospaced
1414
1983
  };
1415
- var FreeDomWrap = defineComponent5({
1984
+ var FreeDomWrap = defineComponent6({
1416
1985
  name: "FreeDomWrap",
1417
1986
  props: freeDomWrapProps,
1418
1987
  setup(props) {
1419
- const { slots } = useDefaultSlot();
1420
1988
  const eventBus = useEventBus();
1421
- const rectRef = shallowRef4();
1422
- const nodes = ref9([]);
1423
- const width = ref9(props.width);
1424
- const height = ref9(props.height);
1425
- watchEffect4(() => {
1989
+ const rectRef = shallowRef6();
1990
+ const nodes = ref13([]);
1991
+ const history = useOperateHistory(nodes);
1992
+ const width = ref13(props.width);
1993
+ const height = ref13(props.height);
1994
+ const selectedNodes = computed11(() => nodes.value.filter((node) => node.node.selected));
1995
+ eventBus.on("move", (nodeId) => {
1996
+ const mainNode = selectedNodes.value.find((node) => node.uuid === nodeId);
1997
+ if (!mainNode)
1998
+ return;
1999
+ const { deltaX, deltaY } = mainNode.node._rect;
2000
+ selectedNodes.value.forEach((node) => {
2001
+ if (node.uuid === nodeId)
2002
+ return;
2003
+ node.node._rect.x += deltaX || 0;
2004
+ node.node._rect.y += deltaY || 0;
2005
+ });
2006
+ });
2007
+ const selecting = ref13(false);
2008
+ const mask = useMask(rectRef, nodes);
2009
+ watchEffect6(() => {
1426
2010
  width.value = props.width;
1427
2011
  });
1428
- watchEffect4(() => {
2012
+ watchEffect6(() => {
1429
2013
  height.value = props.height;
1430
2014
  });
1431
- onMounted3(() => {
2015
+ onMounted5(() => {
1432
2016
  if (!props.width || !props.height) {
1433
2017
  if (!rectRef.value)
1434
2018
  console.warn("[free-dom] cannot find element, width or height may be set to 0");
1435
- const h5 = rectRef.value?.clientHeight;
2019
+ const h7 = rectRef.value?.clientHeight;
1436
2020
  const w = rectRef.value?.clientWidth;
1437
2021
  if (!props.width)
1438
2022
  width.value = w || 0;
1439
2023
  if (!props.height)
1440
- height.value = h5 || 0;
2024
+ height.value = h7 || 0;
1441
2025
  }
1442
2026
  nodes.value.forEach((pos) => {
1443
2027
  const { x, y, width: width2, height: height2 } = correct(pos.node._rect);
@@ -1449,23 +2033,26 @@ var FreeDomWrap = defineComponent5({
1449
2033
  });
1450
2034
  });
1451
2035
  function register(uuid, node) {
1452
- nodes.value.push({ uuid, node });
2036
+ nodes.value.push({
2037
+ uuid,
2038
+ node
2039
+ });
1453
2040
  }
1454
2041
  function remove(uuid) {
1455
2042
  const index = nodes.value.findIndex((item) => item.uuid === uuid);
1456
2043
  nodes.value.splice(index, 1);
1457
2044
  }
1458
2045
  function checkValid(pos) {
1459
- const { x, y, width: w, height: h5 } = pos;
2046
+ const { x, y, width: w, height: h7 } = pos;
1460
2047
  return x >= 0 && // @ts-expect-error: trigger after mounted
1461
2048
  x + w <= width.value && y >= 0 && // @ts-expect-error: trigger after mounted
1462
- y + h5 <= height.value;
2049
+ y + h7 <= height.value;
1463
2050
  }
1464
2051
  function correct(pos) {
1465
2052
  let x = Math.max(pos.x, 0);
1466
2053
  let y = Math.max(pos.y, 0);
1467
2054
  let w = pos.width;
1468
- let h5 = pos.height;
2055
+ let h7 = pos.height;
1469
2056
  if (pos.x + pos.width > width.value) {
1470
2057
  x = width.value - pos.width;
1471
2058
  if (x < 0) {
@@ -1476,7 +2063,7 @@ var FreeDomWrap = defineComponent5({
1476
2063
  if (pos.y + pos.height > height.value) {
1477
2064
  y = height.value - pos.height;
1478
2065
  if (y < 0) {
1479
- h5 = height.value;
2066
+ h7 = height.value;
1480
2067
  y = 0;
1481
2068
  }
1482
2069
  }
@@ -1484,16 +2071,23 @@ var FreeDomWrap = defineComponent5({
1484
2071
  x,
1485
2072
  y,
1486
2073
  width: w,
1487
- height: h5
2074
+ height: h7
1488
2075
  };
1489
2076
  }
1490
- provide(
2077
+ function clearSelectState() {
2078
+ selectedNodes.value.forEach((node) => {
2079
+ node.node.selected = false;
2080
+ });
2081
+ }
2082
+ provide2(
1491
2083
  SceneToken,
1492
- reactive3({
1493
- ...toRefs(props),
2084
+ reactive5({
2085
+ ...toRefs2(props),
1494
2086
  nodes,
1495
2087
  width,
1496
2088
  height,
2089
+ history,
2090
+ clearSelectState,
1497
2091
  register,
1498
2092
  remove,
1499
2093
  checkValid,
@@ -1503,41 +2097,52 @@ var FreeDomWrap = defineComponent5({
1503
2097
  emit: eventBus.emit
1504
2098
  })
1505
2099
  );
1506
- const style = computed8(() => ({
2100
+ const style = computed11(() => ({
1507
2101
  width: `${props.width}px`,
1508
2102
  height: `${props.height}px`
1509
2103
  }));
1510
2104
  return {
1511
2105
  rectRef,
1512
2106
  style,
1513
- slots
2107
+ selecting,
2108
+ mask,
2109
+ history
1514
2110
  };
1515
2111
  },
1516
2112
  render() {
2113
+ const { slots } = useDefaultSlot();
1517
2114
  const marklineComp = createRender(markLine_default, {}, { showLine: this.showLine })();
1518
- const slots = [this.slots, marklineComp];
2115
+ const slotList = [
2116
+ this.mask.selecting && this.mask.renderMask(),
2117
+ slots,
2118
+ marklineComp
2119
+ ];
1519
2120
  return createRender(
1520
2121
  "section",
1521
2122
  {
1522
2123
  ref: "rectRef",
1523
2124
  class: "vv-free-dom--scene",
1524
2125
  style: this.style
2126
+ },
2127
+ {
2128
+ onMousedown: this.mask.handleMousedown,
2129
+ onMousemove: this.mask.handleMousemove
1525
2130
  }
1526
- )(slots);
2131
+ )(slotList);
1527
2132
  }
1528
2133
  });
1529
2134
 
1530
2135
  // src/components/gridLayout.ts
1531
- import { defineComponent as defineComponent7, h as h4, provide as provide2, ref as ref10 } from "vue-demi";
2136
+ import { defineComponent as defineComponent8, h as h6, provide as provide3, ref as ref14 } from "vue-demi";
1532
2137
 
1533
2138
  // src/components/gridItem.ts
1534
- import { defineComponent as defineComponent6, inject as inject3 } from "vue-demi";
2139
+ import { defineComponent as defineComponent7, inject as inject5 } from "vue-demi";
1535
2140
 
1536
2141
  // src/components/tokens.ts
1537
2142
  var gridLayoutContextKey = Symbol("gridLayoutContext");
1538
2143
 
1539
2144
  // src/components/gridItem.ts
1540
- var noop4 = () => {
2145
+ var noop5 = () => {
1541
2146
  };
1542
2147
  var gridItemProps = {
1543
2148
  x: {
@@ -1558,27 +2163,27 @@ var gridItemProps = {
1558
2163
  },
1559
2164
  dragStartFn: {
1560
2165
  type: Function,
1561
- default: noop4
2166
+ default: noop5
1562
2167
  },
1563
2168
  dragFn: {
1564
2169
  type: Function,
1565
- default: noop4
2170
+ default: noop5
1566
2171
  },
1567
2172
  dragEndFn: {
1568
2173
  type: Function,
1569
- default: noop4
2174
+ default: noop5
1570
2175
  },
1571
2176
  resizeStartFn: {
1572
2177
  type: Function,
1573
- default: noop4
2178
+ default: noop5
1574
2179
  },
1575
2180
  resizeFn: {
1576
2181
  type: Function,
1577
- default: noop4
2182
+ default: noop5
1578
2183
  },
1579
2184
  resizeStopFn: {
1580
2185
  type: Function,
1581
- default: noop4
2186
+ default: noop5
1582
2187
  },
1583
2188
  isDraggable: Boolean,
1584
2189
  isResizable: Boolean,
@@ -1588,12 +2193,12 @@ var gridItemProps = {
1588
2193
  }
1589
2194
  };
1590
2195
  var gridItemEmits = ["dragMove"];
1591
- var GridItem = defineComponent6({
2196
+ var GridItem = defineComponent7({
1592
2197
  name: "GridItem",
1593
2198
  props: gridItemProps,
1594
2199
  emits: gridItemEmits,
1595
2200
  setup(props) {
1596
- const layout = inject3(gridLayoutContextKey);
2201
+ const layout = inject5(gridLayoutContextKey);
1597
2202
  if (!layout) {
1598
2203
  throw new Error("TODO");
1599
2204
  }
@@ -1613,7 +2218,6 @@ var GridItem = defineComponent6({
1613
2218
  onResize,
1614
2219
  onResizeStop
1615
2220
  } = useLayoutItem(props, layout);
1616
- const { only, slots } = useDefaultSlot();
1617
2221
  const resizeNode = (child) => {
1618
2222
  const _props = {
1619
2223
  width: width.value,
@@ -1652,8 +2256,6 @@ var GridItem = defineComponent6({
1652
2256
  y,
1653
2257
  width,
1654
2258
  height,
1655
- child: only,
1656
- slots,
1657
2259
  style,
1658
2260
  dragging,
1659
2261
  onDragStart,
@@ -1666,7 +2268,8 @@ var GridItem = defineComponent6({
1666
2268
  };
1667
2269
  },
1668
2270
  render() {
1669
- const node = this.slots;
2271
+ const { slots } = useDefaultSlot();
2272
+ const node = slots;
1670
2273
  return this.dragNode(node);
1671
2274
  }
1672
2275
  });
@@ -1718,15 +2321,15 @@ var gridLayoutProps = {
1718
2321
  disabledResize: Boolean,
1719
2322
  collision: Boolean
1720
2323
  };
1721
- var GridLayout = defineComponent7({
2324
+ var GridLayout = defineComponent8({
1722
2325
  name: "GridLayout",
1723
2326
  inheritAttrs: false,
1724
2327
  props: gridLayoutProps,
1725
2328
  emits: ["update:modelValue"],
1726
2329
  setup(props, { emit }) {
1727
2330
  const layout = useLayout(props);
1728
- provide2(gridLayoutContextKey, layout);
1729
- const activeDrag = ref10(null);
2331
+ provide3(gridLayoutContextKey, layout);
2332
+ const activeDrag = ref14(null);
1730
2333
  function processItem(node) {
1731
2334
  const key = node.key;
1732
2335
  if (!key)
@@ -1773,12 +2376,12 @@ var GridLayout = defineComponent7({
1773
2376
  height: config.h
1774
2377
  };
1775
2378
  activeDrag.value = placeholder2;
1776
- const { w, h: h5 } = data;
1777
- layout.resizeTo(config, w, h5);
2379
+ const { w, h: h7 } = data;
2380
+ layout.resizeTo(config, w, h7);
1778
2381
  },
1779
2382
  resizeStopFn: (evt, data) => {
1780
- const { w, h: h5 } = data;
1781
- layout.resizeTo(config, w, h5);
2383
+ const { w, h: h7 } = data;
2384
+ layout.resizeTo(config, w, h7);
1782
2385
  activeDrag.value = null;
1783
2386
  }
1784
2387
  };
@@ -1811,7 +2414,7 @@ var GridLayout = defineComponent7({
1811
2414
  height: this.layout.calContainerHeight()
1812
2415
  };
1813
2416
  const defaultSlot = typeof this.$slots.default === "function" ? this.$slots.default() : this.$slots.default || [];
1814
- return h4("div", {
2417
+ return h6("div", {
1815
2418
  class: "vv-grid-layout",
1816
2419
  style: mergedStyle
1817
2420
  }, [