@ax-design/reveal-highlight 0.4.1 → 0.5.2

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.
@@ -1,89 +1,89 @@
1
- import { config } from './config.js';
2
-
3
- export interface ComputedStyleStorage {
4
- el: HTMLElement;
5
- size(): number;
6
- get(propertyName: string): string;
7
- getColor(propertyName: string): string;
8
- getNumber(propertyName: string): number;
9
- }
10
-
11
- class ComputedStyleCompat implements ComputedStyleStorage {
12
- protected static colorParser: HTMLDivElement;
13
- protected static colorParserStyle: CSSStyleDeclaration;
14
-
15
- el: HTMLElement;
16
- style: CSSStyleDeclaration;
17
-
18
- constructor(el: HTMLElement) {
19
- if (!ComputedStyleCompat.colorParser) {
20
- const el = document.createElement('div');
21
- el.style.display = 'none !important';
22
- document.body.appendChild(el);
23
-
24
- ComputedStyleCompat.colorParser = el;
25
- ComputedStyleCompat.colorParserStyle = window.getComputedStyle(el);
26
- }
27
-
28
- this.el = el;
29
- this.style = window.getComputedStyle(el);
30
- }
31
-
32
- size() {
33
- return this.style.length;
34
- }
35
-
36
- get(propertyName: string) {
37
- return this.style.getPropertyValue(propertyName).trim();
38
- }
39
-
40
- getColor(propertyName: string) {
41
- ComputedStyleCompat.colorParser.style.color = this.get(propertyName);
42
- return ComputedStyleCompat.colorParserStyle.color || 'rgb(0, 0, 0)';
43
- }
44
-
45
- getNumber(propertyName: string) {
46
- // Length values in computed style will always in the unit of px
47
- // Maybe NaN
48
- return parseFloat(this.get(propertyName));
49
- }
50
- }
51
-
52
- class ComputedStyleExperimental implements ComputedStyleStorage {
53
- el: HTMLElement;
54
- style: StylePropertyMap;
55
-
56
- constructor(el: HTMLElement) {
57
- this.el = el;
58
- this.style = el.computedStyleMap();
59
- }
60
-
61
- size() {
62
- return this.style.size;
63
- }
64
-
65
- get(propertyName: string) {
66
- return this.style.get(propertyName).toString();
67
- }
68
-
69
- getColor(propertyName: string) {
70
- return this.get(propertyName);
71
- }
72
-
73
- getNumber(propertyName: string) {
74
- const value = this.style.get(propertyName).value;
75
- if (typeof value === 'number') {
76
- // Length values in computed style will always in the unit of px
77
- return value;
78
- }
79
-
80
- // Maybe NaN
81
- return parseFloat(value as string);
82
- }
83
- }
84
-
85
- export function createStorage(el: HTMLElement): ComputedStyleStorage {
86
- return config.compat
87
- ? new ComputedStyleCompat(el)
88
- : new ComputedStyleExperimental(el);
89
- }
1
+ import { config } from './config.js';
2
+
3
+ export interface ComputedStyleStorage {
4
+ el: HTMLElement;
5
+ size(): number;
6
+ get(propertyName: string): string;
7
+ getColor(propertyName: string): string;
8
+ getNumber(propertyName: string): number;
9
+ }
10
+
11
+ class ComputedStyleCompat implements ComputedStyleStorage {
12
+ protected static colorParser: HTMLDivElement;
13
+ protected static colorParserStyle: CSSStyleDeclaration;
14
+
15
+ el: HTMLElement;
16
+ style: CSSStyleDeclaration;
17
+
18
+ constructor(el: HTMLElement) {
19
+ if (!ComputedStyleCompat.colorParser) {
20
+ const el = document.createElement('div');
21
+ el.style.display = 'none !important';
22
+ document.body.appendChild(el);
23
+
24
+ ComputedStyleCompat.colorParser = el;
25
+ ComputedStyleCompat.colorParserStyle = window.getComputedStyle(el);
26
+ }
27
+
28
+ this.el = el;
29
+ this.style = window.getComputedStyle(el);
30
+ }
31
+
32
+ size() {
33
+ return this.style.length;
34
+ }
35
+
36
+ get(propertyName: string) {
37
+ return this.style.getPropertyValue(propertyName).trim();
38
+ }
39
+
40
+ getColor(propertyName: string) {
41
+ ComputedStyleCompat.colorParser.style.color = this.get(propertyName);
42
+ return ComputedStyleCompat.colorParserStyle.color || 'rgb(0, 0, 0)';
43
+ }
44
+
45
+ getNumber(propertyName: string) {
46
+ // Length values in computed style will always in the unit of px
47
+ // Maybe NaN
48
+ return parseFloat(this.get(propertyName));
49
+ }
50
+ }
51
+
52
+ class ComputedStyleExperimental implements ComputedStyleStorage {
53
+ el: HTMLElement;
54
+ style: StylePropertyMap;
55
+
56
+ constructor(el: HTMLElement) {
57
+ this.el = el;
58
+ this.style = el.computedStyleMap();
59
+ }
60
+
61
+ size() {
62
+ return this.style.size;
63
+ }
64
+
65
+ get(propertyName: string) {
66
+ return this.style.get(propertyName).toString();
67
+ }
68
+
69
+ getColor(propertyName: string) {
70
+ return this.get(propertyName);
71
+ }
72
+
73
+ getNumber(propertyName: string) {
74
+ const value = this.style.get(propertyName).value;
75
+ if (typeof value === 'number') {
76
+ // Length values in computed style will always in the unit of px
77
+ return value;
78
+ }
79
+
80
+ // Maybe NaN
81
+ return parseFloat(value as string);
82
+ }
83
+ }
84
+
85
+ export function createStorage(el: HTMLElement): ComputedStyleStorage {
86
+ return config.compat
87
+ ? new ComputedStyleCompat(el)
88
+ : new ComputedStyleExperimental(el);
89
+ }