Blame view

美国版/Food Labeling Management App UniApp/src/utils/textElementLayout.ts 2.25 KB
20554770   杨鑫   更新bug
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  /** 文本控件在元素框内的垂直对齐(config.verticalAlign) */
  export type TextVerticalAlign = 'top' | 'center' | 'bottom'
  
  export function readVerticalAlign(
    config: Record<string, unknown> | undefined | null,
  ): TextVerticalAlign {
    const raw = config?.verticalAlign ?? config?.VerticalAlign
    const v = String(raw ?? 'top').trim().toLowerCase()
    if (v === 'center' || v === 'middle') return 'center'
    if (v === 'bottom') return 'bottom'
    return 'top'
  }
  
  export function computeVerticalTextBlockOffset(
    innerHeight: number,
    blockHeight: number,
    verticalAlign: TextVerticalAlign,
  ): number {
    const extra = Math.max(0, innerHeight - blockHeight)
    if (verticalAlign === 'center') return Math.floor(extra / 2)
    if (verticalAlign === 'bottom') return extra
    return 0
  }
  
  export function readFontWeight(
    config: Record<string, unknown> | undefined | null,
  ): 'normal' | 'bold' {
    const raw = config?.fontWeight ?? config?.FontWeight
    const v = String(raw ?? 'normal').trim().toLowerCase()
    return v === 'bold' || v === '700' || v === 'bolder' ? 'bold' : 'normal'
  }
  
  export function readFontStyle(
    config: Record<string, unknown> | undefined | null,
  ): 'normal' | 'italic' {
    const raw = config?.fontStyle ?? config?.FontStyle
    const v = String(raw ?? 'normal').trim().toLowerCase()
    return v === 'italic' || v === 'oblique' ? 'italic' : 'normal'
  }
  
  export function readTextDecoration(
    config: Record<string, unknown> | undefined | null,
  ): 'none' | 'underline' {
    const raw = config?.textDecoration ?? config?.TextDecoration
    const v = String(raw ?? 'none').trim().toLowerCase()
    return v.includes('underline') ? 'underline' : 'none'
  }
  
  export function readElementBorder(
    el: {
      border?: string | null
      Border?: string | null
      BorderType?: string | null
      borderType?: string | null
    },
  ): string {
    const raw = el.border ?? el.Border ?? el.BorderType ?? el.borderType ?? 'none'
    return String(raw).trim().toLowerCase() || 'none'
  }
  
  /** 元素 rotation(兼容大小写) */
  export function readElementRotation(
    el: { rotation?: string | null; Rotation?: string | null },
  ): 'horizontal' | 'vertical' {
    const v = String(el.rotation ?? el.Rotation ?? 'horizontal').trim().toLowerCase()
    return v === 'vertical' ? 'vertical' : 'horizontal'
  }