@contrail/document-util 1.0.5 → 1.0.7
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.
|
@@ -12,6 +12,9 @@ export declare class DocumentStyleUtil {
|
|
|
12
12
|
static getFirstFontSize(text: string, toPt?: boolean): string;
|
|
13
13
|
static getFirstFontFamily(text: string): string;
|
|
14
14
|
static getFirstFontColor(text: string): string;
|
|
15
|
+
static getFirstFontWeight(text: string): string;
|
|
16
|
+
static isBold(text: string, fontFamily?: string): boolean;
|
|
17
|
+
static isItalic(text: string): boolean;
|
|
15
18
|
static isPx(str: any): boolean;
|
|
16
19
|
static toPt(px: any, precision?: number): number;
|
|
17
20
|
static toPx(pt: any, precision?: number): number;
|
|
@@ -23,9 +23,7 @@ class DocumentStyleUtil {
|
|
|
23
23
|
if (!toPt || !fontSize) {
|
|
24
24
|
return fontSize;
|
|
25
25
|
}
|
|
26
|
-
return this.convertToPt(fontSize)
|
|
27
|
-
.replace('pt', '')
|
|
28
|
-
.replace('px', '');
|
|
26
|
+
return this.convertToPt(fontSize).replace('pt', '').replace('px', '');
|
|
29
27
|
}
|
|
30
28
|
static getFirstFontFamily(text) {
|
|
31
29
|
return this.getFirstInlineStyleValue(text, 'font-family');
|
|
@@ -33,6 +31,33 @@ class DocumentStyleUtil {
|
|
|
33
31
|
static getFirstFontColor(text) {
|
|
34
32
|
return this.getFirstInlineStyleValue(text, 'color');
|
|
35
33
|
}
|
|
34
|
+
static getFirstFontWeight(text) {
|
|
35
|
+
return this.getFirstInlineStyleValue(text, 'font-weight');
|
|
36
|
+
}
|
|
37
|
+
static isBold(text, fontFamily) {
|
|
38
|
+
if (text.indexOf('<strong>') !== -1)
|
|
39
|
+
return true;
|
|
40
|
+
const fontWeight = this.getFirstFontWeight(text);
|
|
41
|
+
if (Number(fontWeight) > 400 || fontWeight === 'bold' || fontWeight === 'bolder') {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (fontFamily) {
|
|
45
|
+
const fontFamilyLowerCase = fontFamily.toLowerCase();
|
|
46
|
+
if (fontFamilyLowerCase.indexOf('bold') !== -1 || fontFamilyLowerCase.indexOf('black') !== -1) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
static isItalic(text) {
|
|
53
|
+
if (text.indexOf('<em>') !== -1)
|
|
54
|
+
return true;
|
|
55
|
+
const fontStyle = this.getFirstInlineStyleValue(text, 'font-style');
|
|
56
|
+
if (fontStyle === 'italic') {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
36
61
|
static isPx(str) {
|
|
37
62
|
return /[0-9.]+px$/.test(str);
|
|
38
63
|
}
|