jvs-ppt-ui 0.0.37 → 0.0.38

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.
@@ -1,4 +1,4 @@
1
- import { type Ref } from 'vue'
1
+ import { ref, type Ref } from 'vue'
2
2
 
3
3
  export interface CropOptions {
4
4
  zoomRatio: Ref<number>
@@ -6,6 +6,7 @@ export interface CropOptions {
6
6
  getElementPixels: (el: any) => { left: number; top: number; width: number; height: number; rotate: number }
7
7
  findParentGroup: (id: any) => any
8
8
  addHistorySnapshot: () => void
9
+ onCropStop?: () => void
9
10
  }
10
11
 
11
12
  export function useCanvasCrop(options: CropOptions) {
@@ -14,9 +15,11 @@ export function useCanvasCrop(options: CropOptions) {
14
15
  pauseHistory,
15
16
  getElementPixels,
16
17
  findParentGroup,
17
- addHistorySnapshot
18
+ addHistorySnapshot,
19
+ onCropStop
18
20
  } = options
19
21
 
22
+ const isCropping = ref(false)
20
23
  let isCroppingDrag = false
21
24
  let cropHandle = ''
22
25
  let cropStartX = 0
@@ -121,11 +124,29 @@ export function useCanvasCrop(options: CropOptions) {
121
124
  cancelAnimationFrame(cropAnimationFrameId)
122
125
  cropAnimationFrameId = null
123
126
  }
127
+ if (lastCropEvent && isCroppingDrag && cropCurrentEl) {
128
+ updateCropDimensions(lastCropEvent)
129
+ lastCropEvent = null
130
+ }
124
131
  window.removeEventListener('mousemove', handleCropDrag)
125
132
  window.removeEventListener('mouseup', stopCropDrag)
126
133
  isCroppingDrag = false
134
+ isCropping.value = false
127
135
  cropCurrentEl = null
128
136
  pauseHistory.value = false
137
+ if (onCropStop) onCropStop()
138
+
139
+ // 拦截因拖拽手柄移出图片范围后 mouseup 与 mousedown 节点不一致而由浏览器合成在父容器上的 click 事件,防止误触发 handleDeselect 退出裁剪模式
140
+ const suppressSyntheticClick = (ev: MouseEvent) => {
141
+ ev.stopPropagation()
142
+ ev.preventDefault()
143
+ window.removeEventListener('click', suppressSyntheticClick, true)
144
+ }
145
+ window.addEventListener('click', suppressSyntheticClick, true)
146
+ setTimeout(() => {
147
+ window.removeEventListener('click', suppressSyntheticClick, true)
148
+ }, 50)
149
+
129
150
  addHistorySnapshot()
130
151
  }
131
152
 
@@ -136,6 +157,7 @@ export function useCanvasCrop(options: CropOptions) {
136
157
 
137
158
  pauseHistory.value = true
138
159
  isCroppingDrag = true
160
+ isCropping.value = true
139
161
  cropHandle = handle
140
162
  cropCurrentEl = el
141
163
 
@@ -165,6 +187,7 @@ export function useCanvasCrop(options: CropOptions) {
165
187
  }
166
188
 
167
189
  return {
190
+ isCropping,
168
191
  startInteractiveCrop,
169
192
  handleCropDrag,
170
193
  stopCropDrag,
@@ -132,7 +132,7 @@ export function useSidebarElementTransform(
132
132
  return { width: logicalWidth.value, height: logicalHeight.value }
133
133
  }
134
134
 
135
- const { isCanvasDragging, activeSlideVersion } = useSlides()
135
+ const { isCanvasDragging, activeSlideVersion, selectedElementWidth, selectedElementHeight } = useSlides()
136
136
  let cachedX = 0
137
137
  let cachedY = 0
138
138
 
@@ -272,8 +272,9 @@ export function useSidebarElementTransform(
272
272
  }
273
273
  return parseFloat(parseFloat(wStr).toFixed(1)) || (selectedElement.value.width || 0)
274
274
  },
275
- set(val: number) {
275
+ set(rawVal: number) {
276
276
  if (!selectedElement.value) return
277
+ const val = Math.max(10, Number(rawVal) || 10)
277
278
  if (selectedElementIds.value.length > 1 && activeSlide.value) {
278
279
  activeSlide.value.elements.forEach((el: any) => {
279
280
  if (selectedElementIds.value.includes(el.id)) {
@@ -302,7 +303,7 @@ export function useSidebarElementTransform(
302
303
  elOldH = parseFloat(hStr) || 0
303
304
  }
304
305
  const ratio = elOldH / elOldW
305
- const newH = parseFloat((val * ratio).toFixed(1))
306
+ const newH = Math.max(10, parseFloat((val * ratio).toFixed(1)))
306
307
  if (hStr.endsWith('%')) {
307
308
  el.style.height = `${((newH / refDims.height) * 100).toFixed(4)}%`
308
309
  } else {
@@ -337,10 +338,11 @@ export function useSidebarElementTransform(
337
338
  el.style.width = `${val}px`
338
339
  }
339
340
  el.width = val
341
+ if (selectedElementWidth) selectedElementWidth.value = `${val}px`
340
342
  let newH = elementH.value
341
343
  if ((el as any).fixedRatio && oldW > 0) {
342
344
  const ratio = elementH.value / oldW
343
- newH = parseFloat((val * ratio).toFixed(1))
345
+ newH = Math.max(10, parseFloat((val * ratio).toFixed(1)))
344
346
  const hStr = el.style?.height || '100px'
345
347
  if (hStr.endsWith('%')) {
346
348
  el.style.height = `${((newH / refDims.height) * 100).toFixed(4)}%`
@@ -348,6 +350,7 @@ export function useSidebarElementTransform(
348
350
  el.style.height = `${newH}px`
349
351
  }
350
352
  el.height = newH
353
+ if (selectedElementHeight) selectedElementHeight.value = `${newH}px`
351
354
  }
352
355
  if (el.type === 'group' && Array.isArray(el.elements) && oldW > 0) {
353
356
  const scaleX = val / oldW
@@ -413,8 +416,9 @@ export function useSidebarElementTransform(
413
416
  }
414
417
  return parseFloat(parseFloat(hStr).toFixed(1)) || (el.height || 0)
415
418
  },
416
- set(val: number) {
419
+ set(rawVal: number) {
417
420
  if (!selectedElement.value) return
421
+ const val = Math.max(10, Number(rawVal) || 10)
418
422
  if (selectedElementIds.value.length > 1 && activeSlide.value) {
419
423
  activeSlide.value.elements.forEach((el: any) => {
420
424
  if (selectedElementIds.value.includes(el.id)) {
@@ -443,7 +447,7 @@ export function useSidebarElementTransform(
443
447
  elOldW = parseFloat(wStr) || 0
444
448
  }
445
449
  const ratio = elOldW / elOldH
446
- const newW = parseFloat((val * ratio).toFixed(1))
450
+ const newW = Math.max(10, parseFloat((val * ratio).toFixed(1)))
447
451
  if (wStr.endsWith('%')) {
448
452
  el.style.width = `${((newW / refDims.width) * 100).toFixed(4)}%`
449
453
  } else {
@@ -478,10 +482,11 @@ export function useSidebarElementTransform(
478
482
  el.style.height = `${val}px`
479
483
  }
480
484
  el.height = val
485
+ if (selectedElementHeight) selectedElementHeight.value = `${val}px`
481
486
  let newW = elementW.value
482
487
  if ((el as any).fixedRatio && oldH > 0) {
483
488
  const ratio = elementW.value / oldH
484
- newW = parseFloat((val * ratio).toFixed(1))
489
+ newW = Math.max(10, parseFloat((val * ratio).toFixed(1)))
485
490
  const wStr = el.style?.width || '100px'
486
491
  if (wStr.endsWith('%')) {
487
492
  el.style.width = `${((newW / refDims.width) * 100).toFixed(4)}%`
@@ -489,6 +494,7 @@ export function useSidebarElementTransform(
489
494
  el.style.width = `${newW}px`
490
495
  }
491
496
  el.width = newW
497
+ if (selectedElementWidth) selectedElementWidth.value = `${newW}px`
492
498
  }
493
499
  if (el.type === 'group' && Array.isArray(el.elements) && oldH > 0) {
494
500
  const scaleY = val / oldH