@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.
Files changed (74) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +75 -75
  3. package/build/BaseConfig.d.ts +5 -1
  4. package/build/BaseConfig.d.ts.map +1 -1
  5. package/build/CanvasConfig.d.ts +7 -1
  6. package/build/CanvasConfig.d.ts.map +1 -1
  7. package/build/ComputedStyleStorage.d.ts.map +1 -1
  8. package/build/CustomElements.d.ts +20 -4
  9. package/build/CustomElements.d.ts.map +1 -1
  10. package/build/RevealBoundryStore.d.ts +4 -0
  11. package/build/RevealBoundryStore.d.ts.map +1 -1
  12. package/build/RevealStateManager.d.ts +5 -1
  13. package/build/RevealStateManager.d.ts.map +1 -1
  14. package/build/main.js +113 -82
  15. package/build/utils/types.d.ts +2 -10
  16. package/build/utils/types.d.ts.map +1 -1
  17. package/es/BaseConfig.d.ts +46 -42
  18. package/es/BaseConfig.d.ts.map +1 -1
  19. package/es/BaseConfig.js +241 -219
  20. package/es/BaseConfig.js.map +1 -1
  21. package/es/CanvasConfig.d.ts +21 -15
  22. package/es/CanvasConfig.d.ts.map +1 -1
  23. package/es/CanvasConfig.js +332 -320
  24. package/es/CanvasConfig.js.map +1 -1
  25. package/es/ComputedStyleStorage.d.ts +8 -8
  26. package/es/ComputedStyleStorage.d.ts.map +1 -1
  27. package/es/ComputedStyleStorage.js +68 -58
  28. package/es/ComputedStyleStorage.js.map +1 -1
  29. package/es/CustomElements.d.ts +75 -59
  30. package/es/CustomElements.d.ts.map +1 -1
  31. package/es/CustomElements.js +296 -233
  32. package/es/CustomElements.js.map +1 -1
  33. package/es/Profiler.d.ts +12 -12
  34. package/es/Profiler.js +31 -31
  35. package/es/RevealBoundryStore.d.ts +80 -76
  36. package/es/RevealBoundryStore.d.ts.map +1 -1
  37. package/es/RevealBoundryStore.js +269 -248
  38. package/es/RevealBoundryStore.js.map +1 -1
  39. package/es/RevealStateManager.d.ts +19 -15
  40. package/es/RevealStateManager.d.ts.map +1 -1
  41. package/es/RevealStateManager.js +99 -73
  42. package/es/RevealStateManager.js.map +1 -1
  43. package/es/SvgConfig.d.ts +16 -16
  44. package/es/SvgConfig.js +345 -345
  45. package/es/config.d.ts +4 -4
  46. package/es/config.js +21 -21
  47. package/es/index.d.ts +5 -5
  48. package/es/index.js +205 -205
  49. package/es/tsconfig.tsbuildinfo +1 -1
  50. package/es/utils/extractRGBValue.d.ts +1 -1
  51. package/es/utils/extractRGBValue.js +47 -47
  52. package/es/utils/isValidateBorderDecorationType.d.ts +2 -2
  53. package/es/utils/isValidateBorderDecorationType.js +9 -9
  54. package/es/utils/types.d.ts +94 -102
  55. package/es/utils/types.d.ts.map +1 -1
  56. package/es/utils/types.js +1 -1
  57. package/es/variables.d.ts +1 -1
  58. package/es/variables.js +1 -1
  59. package/package.json +35 -34
  60. package/src/BaseConfig.ts +332 -310
  61. package/src/CanvasConfig.ts +420 -415
  62. package/src/ComputedStyleStorage.ts +102 -89
  63. package/src/CustomElements.ts +344 -272
  64. package/src/Profiler.ts +44 -44
  65. package/src/RevealBoundryStore.ts +315 -291
  66. package/src/RevealStateManager.ts +109 -86
  67. package/src/SvgConfig.ts +422 -422
  68. package/src/config.ts +26 -26
  69. package/src/cssTypedOM.d.ts +52 -52
  70. package/src/index.ts +219 -219
  71. package/src/utils/extractRGBValue.ts +58 -58
  72. package/src/utils/isValidateBorderDecorationType.ts +8 -8
  73. package/src/utils/types.ts +97 -105
  74. 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
- 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
+ // 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
+ }