返回 oh-my-ppt
1 import type { EditableCapability, EditSelectionPayload } from '@arcsin1/presentation-editor-runtime'
2
3 export interface ElementEditDraft {
4 html: string
5 text: string
6 color: string
7 fontSize: string
8 fontWeight: string
9 textAlign: string
10 layoutX: string
11 layoutY: string
12 layoutWidth: string
13 layoutHeight: string
14 layoutZIndex: string
15 opacity: string
16 backgroundColor: string
17 objectFit: string
18 alt: string
19 poster: string
20 controls: boolean
21 muted: boolean
22 loop: boolean
23 autoplay: boolean
24 playsInline: boolean
25 preload: string
26 artTextTemplateId: string
27 formulaLatex: string
28 formulaHtml: string
29 formulaDisplayMode: boolean
30 chartType: string
31 chartTitle: string
32 chartLabels: string
33 chartValues: string
34 chartDataJson: string
35 chartPrimaryColor: string
36 chartAccentColor: string
37 chartTextColor: string
38 chartSmooth: boolean
39 chartHorizontal: boolean
40 chartStacked: boolean
41 chartAreaFill: boolean
42 chartShowPoints: boolean
43 chartShowLegend: boolean
44 chartDoughnutCutout: string
45 chartRadarFill: boolean
46 chartConfigJson: string
47 }
48
49 export interface ElementEditorProps {
50 selection: EditSelectionPayload
51 draft: ElementEditDraft
52 onDraftChange: (
53 draft: ElementEditDraft,
54 options?: { commit?: boolean; fields?: Array<keyof ElementEditDraft> }
55 ) => void
56 }
57
58 export function hasCapability(
59 selection: EditSelectionPayload | null,
60 capability: EditableCapability
61 ): boolean {
62 if (!selection) return false
63 if (selection.capabilities?.includes(capability)) return true
64
65 // Media semantics are intrinsic to the element tag. Keep the inspector
66 // usable for pages produced by older runtimes that omitted the derived
67 // capability list from the selection payload.
68 if (capability === 'media' || capability === 'appearance') {
69 const tag = String(selection.elementTag || selection.snapshot?.elementTag || '').toLowerCase()
70 return tag === 'img' || tag === 'video'
71 }
72
73 return false
74 }
75
76 export function isArtTextSelection(selection: EditSelectionPayload | null): boolean {
77 return Boolean(selection?.snapshot?.attrs.artTextTemplate)
78 }
79
80 export function getElementKindLabel(selection: EditSelectionPayload): string {
81 switch (selection.kind) {
82 case 'text':
83 return 'Text'
84 case 'media':
85 return 'Media'
86 case 'chart':
87 return 'Chart'
88 case 'table':
89 return 'Table'
90 case 'formula':
91 return 'Formula'
92 case 'shape':
93 return 'Shape'
94 case 'container':
95 return 'Group'
96 default:
97 return 'Element'
98 }
99 }
100
100 lines TYPESCRIPT