@ax-design/reveal-highlight 0.4.2 → 0.5.3
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.
- package/LICENSE +21 -21
- package/README.md +75 -75
- package/build/BaseConfig.d.ts +5 -1
- package/build/BaseConfig.d.ts.map +1 -1
- package/build/CanvasConfig.d.ts +7 -1
- package/build/CanvasConfig.d.ts.map +1 -1
- package/build/ComputedStyleStorage.d.ts.map +1 -1
- package/build/CustomElements.d.ts +20 -4
- package/build/CustomElements.d.ts.map +1 -1
- package/build/RevealBoundryStore.d.ts +4 -0
- package/build/RevealBoundryStore.d.ts.map +1 -1
- package/build/RevealStateManager.d.ts +5 -1
- package/build/RevealStateManager.d.ts.map +1 -1
- package/build/main.js +113 -82
- package/build/utils/types.d.ts +2 -10
- package/build/utils/types.d.ts.map +1 -1
- package/es/BaseConfig.d.ts +46 -42
- package/es/BaseConfig.d.ts.map +1 -1
- package/es/BaseConfig.js +241 -219
- package/es/BaseConfig.js.map +1 -1
- package/es/CanvasConfig.d.ts +21 -15
- package/es/CanvasConfig.d.ts.map +1 -1
- package/es/CanvasConfig.js +332 -320
- package/es/CanvasConfig.js.map +1 -1
- package/es/ComputedStyleStorage.d.ts +8 -8
- package/es/ComputedStyleStorage.d.ts.map +1 -1
- package/es/ComputedStyleStorage.js +68 -58
- package/es/ComputedStyleStorage.js.map +1 -1
- package/es/CustomElements.d.ts +75 -59
- package/es/CustomElements.d.ts.map +1 -1
- package/es/CustomElements.js +296 -233
- package/es/CustomElements.js.map +1 -1
- package/es/Profiler.d.ts +12 -12
- package/es/Profiler.js +31 -31
- package/es/RevealBoundryStore.d.ts +80 -76
- package/es/RevealBoundryStore.d.ts.map +1 -1
- package/es/RevealBoundryStore.js +269 -248
- package/es/RevealBoundryStore.js.map +1 -1
- package/es/RevealStateManager.d.ts +19 -15
- package/es/RevealStateManager.d.ts.map +1 -1
- package/es/RevealStateManager.js +99 -73
- package/es/RevealStateManager.js.map +1 -1
- package/es/SvgConfig.d.ts +16 -16
- package/es/SvgConfig.js +345 -345
- package/es/config.d.ts +4 -4
- package/es/config.js +21 -21
- package/es/index.d.ts +5 -5
- package/es/index.js +205 -205
- package/es/tsconfig.tsbuildinfo +1 -1
- package/es/utils/extractRGBValue.d.ts +1 -1
- package/es/utils/extractRGBValue.js +47 -47
- package/es/utils/isValidateBorderDecorationType.d.ts +2 -2
- package/es/utils/isValidateBorderDecorationType.js +9 -9
- package/es/utils/types.d.ts +94 -102
- package/es/utils/types.d.ts.map +1 -1
- package/es/utils/types.js +1 -1
- package/es/variables.d.ts +1 -1
- package/es/variables.js +1 -1
- package/package.json +35 -34
- package/src/BaseConfig.ts +332 -310
- package/src/CanvasConfig.ts +420 -415
- package/src/ComputedStyleStorage.ts +102 -89
- package/src/CustomElements.ts +344 -272
- package/src/Profiler.ts +44 -44
- package/src/RevealBoundryStore.ts +315 -291
- package/src/RevealStateManager.ts +109 -86
- package/src/SvgConfig.ts +422 -422
- package/src/config.ts +26 -26
- package/src/cssTypedOM.d.ts +52 -52
- package/src/index.ts +219 -219
- package/src/utils/extractRGBValue.ts +58 -58
- package/src/utils/isValidateBorderDecorationType.ts +8 -8
- package/src/utils/types.ts +97 -105
- package/src/variables.ts +1 -1
|
@@ -1,89 +1,102 @@
|
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
document.
|
|
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
|
-
this.
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
// Parsing a color forces a style recalc, so cache the result by the raw value
|
|
15
|
+
protected static colorCache = new Map<string, string>();
|
|
16
|
+
|
|
17
|
+
el: HTMLElement;
|
|
18
|
+
style: CSSStyleDeclaration;
|
|
19
|
+
|
|
20
|
+
constructor(el: HTMLElement) {
|
|
21
|
+
if (!ComputedStyleCompat.colorParser) {
|
|
22
|
+
const el = document.createElement('div');
|
|
23
|
+
el.style.setProperty('display', 'none', 'important');
|
|
24
|
+
document.body.appendChild(el);
|
|
25
|
+
|
|
26
|
+
ComputedStyleCompat.colorParser = el;
|
|
27
|
+
ComputedStyleCompat.colorParserStyle = window.getComputedStyle(el);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.el = el;
|
|
31
|
+
this.style = window.getComputedStyle(el);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
size() {
|
|
35
|
+
return this.style.length;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get(propertyName: string) {
|
|
39
|
+
return this.style.getPropertyValue(propertyName).trim();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getColor(propertyName: string) {
|
|
43
|
+
const value = this.get(propertyName);
|
|
44
|
+
let color = ComputedStyleCompat.colorCache.get(value);
|
|
45
|
+
|
|
46
|
+
if (color === undefined) {
|
|
47
|
+
ComputedStyleCompat.colorParser.style.color = value;
|
|
48
|
+
color = ComputedStyleCompat.colorParserStyle.color || 'rgb(0, 0, 0)';
|
|
49
|
+
ComputedStyleCompat.colorCache.set(value, color);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return color;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getNumber(propertyName: string) {
|
|
56
|
+
// Length values in computed style will always in the unit of px
|
|
57
|
+
// Maybe NaN
|
|
58
|
+
return parseFloat(this.get(propertyName));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
class ComputedStyleExperimental implements ComputedStyleStorage {
|
|
63
|
+
el: HTMLElement;
|
|
64
|
+
style: StylePropertyMap;
|
|
65
|
+
|
|
66
|
+
constructor(el: HTMLElement) {
|
|
67
|
+
this.el = el;
|
|
68
|
+
this.style = el.computedStyleMap();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
size() {
|
|
72
|
+
return this.style.size;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get(propertyName: string) {
|
|
76
|
+
return this.style.get(propertyName).toString();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getColor(propertyName: string) {
|
|
80
|
+
return this.get(propertyName);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getNumber(propertyName: string) {
|
|
84
|
+
const value = this.style.get(propertyName).value;
|
|
85
|
+
if (typeof value === 'number') {
|
|
86
|
+
// Length values in computed style will always in the unit of px
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Maybe NaN
|
|
91
|
+
return parseFloat(value as string);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Firefox supports `CSS.registerProperty` but not `computedStyleMap`
|
|
96
|
+
const supportsTypedOM = typeof Element !== 'undefined' && 'computedStyleMap' in Element.prototype;
|
|
97
|
+
|
|
98
|
+
export function createStorage(el: HTMLElement): ComputedStyleStorage {
|
|
99
|
+
return config.compat || !supportsTypedOM
|
|
100
|
+
? new ComputedStyleCompat(el)
|
|
101
|
+
: new ComputedStyleExperimental(el);
|
|
102
|
+
}
|