zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export function isFunction (func) {
  return (typeof func === 'function' || Object.prototype.toString.call(func) === '[object Function]')
}
 
// 生成随机字符串, e表示长度
export function randomString(e) {  
  e = e || 32;
  var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
  a = t.length,
  n = "";
  for (let i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
  return n
}
 
export function snapToGrid (grid, pendingX, pendingY, scale = 1) {
  const x = Math.round((pendingX / scale) / grid[0]) * grid[0]
  const y = Math.round((pendingY / scale) / grid[1]) * grid[1]
 
  return [x, y]
}
 
export function getSize (el) {
  const rect = el.getBoundingClientRect()
 
  return [
    parseInt(rect.width),
    parseInt(rect.height)
  ]
}
 
export function restrictToBounds (value, min, max) {
  if (min !== null && value < min) {
    return min
  }
 
  if (max !== null && max < value) {
    return max
  }
 
  return value
}