@sepveneto/free-dom 0.4.2 → 0.5.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.css +1 -1
- package/dist/index.js +37 -68
- package/dist/index.mjs +40 -73
- package/package.json +1 -1
package/dist/index.css
CHANGED
package/dist/index.js
CHANGED
|
@@ -202,7 +202,7 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
202
202
|
emits: ["update:x", "update:y", "update:width", "update:height", "select"],
|
|
203
203
|
setup(props, { emit }) {
|
|
204
204
|
const active = (0, import_vue_demi2.ref)(false);
|
|
205
|
-
const SceneContext = (0, import_vue_demi2.inject)(SceneToken);
|
|
205
|
+
const SceneContext = (0, import_vue_demi2.inject)(SceneToken, void 0);
|
|
206
206
|
const _preview = (0, import_vue_demi2.computed)(() => SceneContext?.preview || props.preview);
|
|
207
207
|
const canScale = (0, import_vue_demi2.computed)(() => !_preview.value && (SceneContext?.scale || props.scale));
|
|
208
208
|
const canMove = (0, import_vue_demi2.computed)(() => !_preview.value && (SceneContext?.move || props.move));
|
|
@@ -216,13 +216,7 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
216
216
|
const uuid = (0, import_uuid.v4)();
|
|
217
217
|
const isScale = (0, import_vue_demi2.ref)(false);
|
|
218
218
|
const isMove = (0, import_vue_demi2.ref)(false);
|
|
219
|
-
const _rect = (0, import_vue_demi2.reactive)({
|
|
220
|
-
x: 0,
|
|
221
|
-
y: 0,
|
|
222
|
-
width: 0,
|
|
223
|
-
height: 0
|
|
224
|
-
});
|
|
225
|
-
const triggerThrottle = (0, import_core.useThrottleFn)(trigger);
|
|
219
|
+
const _rect = (0, import_vue_demi2.reactive)({});
|
|
226
220
|
const context = {
|
|
227
221
|
_rect,
|
|
228
222
|
trigger
|
|
@@ -230,47 +224,45 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
230
224
|
(0, import_core.onClickOutside)(widgetRef, () => {
|
|
231
225
|
active.value = false;
|
|
232
226
|
});
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
props.width && (_rect.width = props.width);
|
|
239
|
-
props.height && (_rect.height = props.height);
|
|
240
|
-
props.x && (_rect.x = props.x);
|
|
241
|
-
props.y && (_rect.y = props.y);
|
|
242
|
-
init && triggerThrottle();
|
|
243
|
-
init = true;
|
|
244
|
-
});
|
|
245
|
-
const rectBound = (0, import_core.useElementBounding)(widgetRef);
|
|
246
|
-
const unwatchHeight = (0, import_vue_demi2.watch)(rectBound.height, (height) => {
|
|
247
|
-
if (height) {
|
|
248
|
-
_rect.height = height;
|
|
249
|
-
unwatchHeight();
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
const unwatchWidth = (0, import_vue_demi2.watch)(rectBound.width, (width) => {
|
|
253
|
-
if (width) {
|
|
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) {
|
|
254
232
|
_rect.width = width;
|
|
255
|
-
|
|
233
|
+
}
|
|
234
|
+
if (autoHeight && height) {
|
|
235
|
+
_rect.height = height;
|
|
256
236
|
}
|
|
257
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 && (_rect.x = x);
|
|
255
|
+
y && (_rect.y = y);
|
|
256
|
+
trigger();
|
|
257
|
+
},
|
|
258
|
+
{ immediate: true }
|
|
259
|
+
);
|
|
258
260
|
(0, import_vue_demi2.onMounted)(async () => {
|
|
259
261
|
SceneContext?.register(uuid, context);
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
_rect.
|
|
263
|
-
if (_rect.width) {
|
|
264
|
-
unwatchWidth();
|
|
265
|
-
}
|
|
266
|
-
_rect.height = _rect.height || rect.height;
|
|
267
|
-
if (_rect.height) {
|
|
268
|
-
unwatchHeight();
|
|
269
|
-
}
|
|
270
|
-
_rect.x = _rect.x || 0;
|
|
271
|
-
_rect.y = _rect.y || 0;
|
|
262
|
+
const { offsetTop, offsetLeft } = widgetRef.value;
|
|
263
|
+
_rect.x = _rect.x || offsetLeft;
|
|
264
|
+
_rect.y = _rect.y || offsetTop;
|
|
272
265
|
trigger();
|
|
273
|
-
emitPos();
|
|
274
266
|
});
|
|
275
267
|
function trigger() {
|
|
276
268
|
const { x, y, width, height } = _rect;
|
|
@@ -328,9 +320,7 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
328
320
|
emit("update:height", _rect.height);
|
|
329
321
|
}
|
|
330
322
|
function getDotPos(dot) {
|
|
331
|
-
|
|
332
|
-
return {};
|
|
333
|
-
const { width, height } = _style.value;
|
|
323
|
+
const { width, height } = _rect;
|
|
334
324
|
const isL = /l/.test(dot);
|
|
335
325
|
const isR = /r/.test(dot);
|
|
336
326
|
const isT = /t/.test(dot);
|
|
@@ -362,7 +352,7 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
362
352
|
const shouldUpdate = props.onDragStart?.();
|
|
363
353
|
if (shouldUpdate === false)
|
|
364
354
|
return;
|
|
365
|
-
const pos =
|
|
355
|
+
const pos = { ..._rect };
|
|
366
356
|
const move = (mouseEvt) => {
|
|
367
357
|
const { clientX, clientY } = mouseEvt;
|
|
368
358
|
const x = clientX - evt.clientX + pos.x;
|
|
@@ -398,27 +388,6 @@ var FreeDom = (0, import_vue_demi2.defineComponent)({
|
|
|
398
388
|
return true;
|
|
399
389
|
}
|
|
400
390
|
}
|
|
401
|
-
function getStyle(style) {
|
|
402
|
-
const { transform, width, height } = style;
|
|
403
|
-
const { x, y } = getPos(transform);
|
|
404
|
-
return {
|
|
405
|
-
x: x ? Number(x) : 0,
|
|
406
|
-
y: y ? Number(y) : 0,
|
|
407
|
-
width: parseFloat(width),
|
|
408
|
-
height: parseFloat(height)
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
function getPos(transform) {
|
|
412
|
-
if (!transform) {
|
|
413
|
-
return {
|
|
414
|
-
x: 0,
|
|
415
|
-
y: 0
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
const posRegexp = /translate\(([.0-9]+)px[, ]+([.0-9]+)px\)/;
|
|
419
|
-
const [, x, y] = posRegexp.exec(transform) ?? [];
|
|
420
|
-
return { x: parseNum(x), y: parseNum(y) };
|
|
421
|
-
}
|
|
422
391
|
return {
|
|
423
392
|
widgetRef,
|
|
424
393
|
canMove,
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,6 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
|
|
8
8
|
// src/components/freeDom.ts
|
|
9
9
|
import {
|
|
10
|
-
nextTick,
|
|
11
10
|
onMounted,
|
|
12
11
|
defineComponent,
|
|
13
12
|
h,
|
|
@@ -17,7 +16,6 @@ import {
|
|
|
17
16
|
reactive,
|
|
18
17
|
isVue2,
|
|
19
18
|
shallowRef,
|
|
20
|
-
watchEffect,
|
|
21
19
|
watch as watch2
|
|
22
20
|
} from "vue-demi";
|
|
23
21
|
|
|
@@ -126,7 +124,7 @@ function useResize(startX, startY, rect, dot, diagonal, snapGrid, callbacks) {
|
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
// src/components/freeDom.ts
|
|
129
|
-
import { onClickOutside,
|
|
127
|
+
import { onClickOutside, useElementSize } from "@vueuse/core";
|
|
130
128
|
import { v4 as uuidv4 } from "uuid";
|
|
131
129
|
var Dots = ["t", "r", "l", "b", "lt", "lb", "rt", "rb"];
|
|
132
130
|
var FreeDom = defineComponent({
|
|
@@ -190,7 +188,7 @@ var FreeDom = defineComponent({
|
|
|
190
188
|
emits: ["update:x", "update:y", "update:width", "update:height", "select"],
|
|
191
189
|
setup(props, { emit }) {
|
|
192
190
|
const active = ref2(false);
|
|
193
|
-
const SceneContext = inject(SceneToken);
|
|
191
|
+
const SceneContext = inject(SceneToken, void 0);
|
|
194
192
|
const _preview = computed(() => SceneContext?.preview || props.preview);
|
|
195
193
|
const canScale = computed(() => !_preview.value && (SceneContext?.scale || props.scale));
|
|
196
194
|
const canMove = computed(() => !_preview.value && (SceneContext?.move || props.move));
|
|
@@ -204,13 +202,7 @@ var FreeDom = defineComponent({
|
|
|
204
202
|
const uuid = uuidv4();
|
|
205
203
|
const isScale = ref2(false);
|
|
206
204
|
const isMove = ref2(false);
|
|
207
|
-
const _rect = reactive({
|
|
208
|
-
x: 0,
|
|
209
|
-
y: 0,
|
|
210
|
-
width: 0,
|
|
211
|
-
height: 0
|
|
212
|
-
});
|
|
213
|
-
const triggerThrottle = useThrottleFn(trigger);
|
|
205
|
+
const _rect = reactive({});
|
|
214
206
|
const context = {
|
|
215
207
|
_rect,
|
|
216
208
|
trigger
|
|
@@ -218,47 +210,45 @@ var FreeDom = defineComponent({
|
|
|
218
210
|
onClickOutside(widgetRef, () => {
|
|
219
211
|
active.value = false;
|
|
220
212
|
});
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
props.width && (_rect.width = props.width);
|
|
227
|
-
props.height && (_rect.height = props.height);
|
|
228
|
-
props.x && (_rect.x = props.x);
|
|
229
|
-
props.y && (_rect.y = props.y);
|
|
230
|
-
init && triggerThrottle();
|
|
231
|
-
init = true;
|
|
232
|
-
});
|
|
233
|
-
const rectBound = useElementBounding(widgetRef);
|
|
234
|
-
const unwatchHeight = watch2(rectBound.height, (height) => {
|
|
235
|
-
if (height) {
|
|
236
|
-
_rect.height = height;
|
|
237
|
-
unwatchHeight();
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
const unwatchWidth = watch2(rectBound.width, (width) => {
|
|
241
|
-
if (width) {
|
|
213
|
+
let rectSize = reactive(useElementSize(widgetRef));
|
|
214
|
+
let autoWidth = true;
|
|
215
|
+
let autoHeight = true;
|
|
216
|
+
const unwatch = watch2(rectSize, ({ width, height }) => {
|
|
217
|
+
if (autoWidth && width) {
|
|
242
218
|
_rect.width = width;
|
|
243
|
-
|
|
219
|
+
}
|
|
220
|
+
if (autoHeight && height) {
|
|
221
|
+
_rect.height = height;
|
|
244
222
|
}
|
|
245
223
|
});
|
|
224
|
+
watch2(
|
|
225
|
+
[
|
|
226
|
+
() => props.width,
|
|
227
|
+
() => props.height,
|
|
228
|
+
() => props.x,
|
|
229
|
+
() => props.y
|
|
230
|
+
],
|
|
231
|
+
([width, height, x, y]) => {
|
|
232
|
+
autoWidth = width === _rect.width;
|
|
233
|
+
autoHeight = height === _rect.height;
|
|
234
|
+
if (!autoHeight && !autoWidth) {
|
|
235
|
+
unwatch();
|
|
236
|
+
rectSize = null;
|
|
237
|
+
}
|
|
238
|
+
width && (_rect.width = width);
|
|
239
|
+
height && (_rect.height = height);
|
|
240
|
+
x && (_rect.x = x);
|
|
241
|
+
y && (_rect.y = y);
|
|
242
|
+
trigger();
|
|
243
|
+
},
|
|
244
|
+
{ immediate: true }
|
|
245
|
+
);
|
|
246
246
|
onMounted(async () => {
|
|
247
247
|
SceneContext?.register(uuid, context);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
_rect.
|
|
251
|
-
if (_rect.width) {
|
|
252
|
-
unwatchWidth();
|
|
253
|
-
}
|
|
254
|
-
_rect.height = _rect.height || rect.height;
|
|
255
|
-
if (_rect.height) {
|
|
256
|
-
unwatchHeight();
|
|
257
|
-
}
|
|
258
|
-
_rect.x = _rect.x || 0;
|
|
259
|
-
_rect.y = _rect.y || 0;
|
|
248
|
+
const { offsetTop, offsetLeft } = widgetRef.value;
|
|
249
|
+
_rect.x = _rect.x || offsetLeft;
|
|
250
|
+
_rect.y = _rect.y || offsetTop;
|
|
260
251
|
trigger();
|
|
261
|
-
emitPos();
|
|
262
252
|
});
|
|
263
253
|
function trigger() {
|
|
264
254
|
const { x, y, width, height } = _rect;
|
|
@@ -316,9 +306,7 @@ var FreeDom = defineComponent({
|
|
|
316
306
|
emit("update:height", _rect.height);
|
|
317
307
|
}
|
|
318
308
|
function getDotPos(dot) {
|
|
319
|
-
|
|
320
|
-
return {};
|
|
321
|
-
const { width, height } = _style.value;
|
|
309
|
+
const { width, height } = _rect;
|
|
322
310
|
const isL = /l/.test(dot);
|
|
323
311
|
const isR = /r/.test(dot);
|
|
324
312
|
const isT = /t/.test(dot);
|
|
@@ -350,7 +338,7 @@ var FreeDom = defineComponent({
|
|
|
350
338
|
const shouldUpdate = props.onDragStart?.();
|
|
351
339
|
if (shouldUpdate === false)
|
|
352
340
|
return;
|
|
353
|
-
const pos =
|
|
341
|
+
const pos = { ..._rect };
|
|
354
342
|
const move = (mouseEvt) => {
|
|
355
343
|
const { clientX, clientY } = mouseEvt;
|
|
356
344
|
const x = clientX - evt.clientX + pos.x;
|
|
@@ -386,27 +374,6 @@ var FreeDom = defineComponent({
|
|
|
386
374
|
return true;
|
|
387
375
|
}
|
|
388
376
|
}
|
|
389
|
-
function getStyle(style) {
|
|
390
|
-
const { transform, width, height } = style;
|
|
391
|
-
const { x, y } = getPos(transform);
|
|
392
|
-
return {
|
|
393
|
-
x: x ? Number(x) : 0,
|
|
394
|
-
y: y ? Number(y) : 0,
|
|
395
|
-
width: parseFloat(width),
|
|
396
|
-
height: parseFloat(height)
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
function getPos(transform) {
|
|
400
|
-
if (!transform) {
|
|
401
|
-
return {
|
|
402
|
-
x: 0,
|
|
403
|
-
y: 0
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
const posRegexp = /translate\(([.0-9]+)px[, ]+([.0-9]+)px\)/;
|
|
407
|
-
const [, x, y] = posRegexp.exec(transform) ?? [];
|
|
408
|
-
return { x: parseNum(x), y: parseNum(y) };
|
|
409
|
-
}
|
|
410
377
|
return {
|
|
411
378
|
widgetRef,
|
|
412
379
|
canMove,
|
|
@@ -481,7 +448,7 @@ var FreeDom = defineComponent({
|
|
|
481
448
|
|
|
482
449
|
// src/components/freeDomWrap.ts
|
|
483
450
|
import { defineComponent as defineComponent3, shallowRef as shallowRef3, h as h3, provide, reactive as reactive3, ref as ref4, toRefs } from "vue-demi";
|
|
484
|
-
import { useElementBounding
|
|
451
|
+
import { useElementBounding } from "@vueuse/core";
|
|
485
452
|
|
|
486
453
|
// src/components/markLine.ts
|
|
487
454
|
import { h as h2, defineComponent as defineComponent2, shallowRef as shallowRef2, ref as ref3, reactive as reactive2, inject as inject2, onBeforeUnmount } from "vue-demi";
|
|
@@ -675,7 +642,7 @@ var FreeDomWrap = defineComponent3({
|
|
|
675
642
|
props: freeDomWrapProps,
|
|
676
643
|
setup(props) {
|
|
677
644
|
const rectRef = shallowRef3(null);
|
|
678
|
-
const rect =
|
|
645
|
+
const rect = useElementBounding(rectRef);
|
|
679
646
|
const nodes = ref4([]);
|
|
680
647
|
function register(uuid, node) {
|
|
681
648
|
nodes.value.push({ uuid, node });
|