Skip to content

Commit 021f212

Browse files
committed
feat(shared): add detail level enums and optional text/css fields to
TargetedElement
1 parent 3f2f66f commit 021f212

File tree

2 files changed

+97
-9
lines changed

2 files changed

+97
-9
lines changed

packages/shared/src/detail.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { CSSDetailLevel, TextDetailLevel } from './types';
2+
3+
export const TEXT_DETAIL_OPTIONS: readonly TextDetailLevel[] = ['full', 'visible', 'none'];
4+
5+
export const CSS_DETAIL_OPTIONS: readonly CSSDetailLevel[] = [0, 1, 2, 3];
6+
7+
export const CSS_LEVEL_1_FIELDS: readonly string[] = [
8+
'display',
9+
'position',
10+
'fontSize',
11+
'color',
12+
'backgroundColor',
13+
];
14+
15+
const CSS_LEVEL_2_EXTRA_FIELDS = [
16+
'margin',
17+
'marginTop',
18+
'marginRight',
19+
'marginBottom',
20+
'marginLeft',
21+
'padding',
22+
'paddingTop',
23+
'paddingRight',
24+
'paddingBottom',
25+
'paddingLeft',
26+
'lineHeight',
27+
'textAlign',
28+
'fontWeight',
29+
'fontFamily',
30+
'width',
31+
'height',
32+
'minWidth',
33+
'maxWidth',
34+
'minHeight',
35+
'maxHeight',
36+
'border',
37+
'borderTop',
38+
'borderRight',
39+
'borderBottom',
40+
'borderLeft',
41+
'borderRadius',
42+
'borderTopLeftRadius',
43+
'borderTopRightRadius',
44+
'borderBottomRightRadius',
45+
'borderBottomLeftRadius',
46+
'boxSizing',
47+
'flexDirection',
48+
'justifyContent',
49+
'alignItems',
50+
'gap',
51+
'overflow',
52+
'overflowX',
53+
'overflowY',
54+
] as const;
55+
56+
export const CSS_LEVEL_2_FIELDS: readonly string[] = Object.freeze([
57+
...CSS_LEVEL_1_FIELDS,
58+
...CSS_LEVEL_2_EXTRA_FIELDS,
59+
]);
60+
61+
export const CSS_LEVEL_FIELD_MAP: Record<
62+
Exclude<CSSDetailLevel, 0>,
63+
readonly string[]
64+
> = Object.freeze({
65+
1: CSS_LEVEL_1_FIELDS,
66+
2: CSS_LEVEL_2_FIELDS,
67+
3: [],
68+
});
69+
70+
export function isValidTextDetail(detail: unknown): detail is TextDetailLevel {
71+
return typeof detail === 'string' && (TEXT_DETAIL_OPTIONS as readonly string[]).includes(detail);
72+
}
73+
74+
export function isValidCSSLevel(level: unknown): level is CSSDetailLevel {
75+
return typeof level === 'number' && (CSS_DETAIL_OPTIONS as readonly number[]).includes(level);
76+
}

packages/shared/src/types.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1+
export type TextDetailLevel = 'full' | 'visible' | 'none';
2+
3+
export type CSSDetailLevel = 0 | 1 | 2 | 3;
4+
5+
export const DEFAULT_TEXT_DETAIL: TextDetailLevel = 'full';
6+
7+
export const DEFAULT_CSS_LEVEL: CSSDetailLevel = 1;
8+
9+
export interface TextSnapshots {
10+
visible: string;
11+
full: string;
12+
}
13+
114
export interface ElementPosition {
215
x: number;
316
y: number;
417
width: number;
518
height: number;
619
}
720

8-
export interface CSSProperties {
9-
display: string;
10-
position: string;
11-
fontSize: string;
12-
color: string;
13-
backgroundColor: string;
14-
}
21+
export type CSSProperties = Record<string, string>;
1522

1623
export interface ComponentInfo {
1724
name?: string;
@@ -24,10 +31,15 @@ export interface TargetedElement {
2431
tagName: string;
2532
id?: string;
2633
classes: string[];
27-
innerText: string;
34+
innerText?: string;
35+
textContent?: string;
36+
textDetail?: TextDetailLevel;
37+
textVariants?: TextSnapshots;
2838
attributes: Record<string, string>;
2939
position: ElementPosition;
30-
cssProperties: CSSProperties;
40+
cssLevel?: CSSDetailLevel;
41+
cssProperties?: CSSProperties;
42+
cssComputed?: Record<string, string>;
3143
componentInfo?: ComponentInfo;
3244
timestamp: number;
3345
url: string;

0 commit comments

Comments
 (0)