browser-extension-utils 0.0.4 → 0.0.6
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/lib/index.d.ts +6 -2
- package/lib/index.js +14 -4
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -36,9 +36,13 @@ export function setAttribute(
|
|
|
36
36
|
value: string
|
|
37
37
|
): void
|
|
38
38
|
|
|
39
|
-
export function setStyle(
|
|
39
|
+
export function setStyle(
|
|
40
|
+
element: HTMLElement,
|
|
41
|
+
style: string | Record<string, unknown>,
|
|
42
|
+
overwrite?: boolean
|
|
43
|
+
): void
|
|
40
44
|
|
|
41
|
-
export function toStyleMap(styleText: string): Record<string,
|
|
45
|
+
export function toStyleMap(styleText: string): Record<string, string>
|
|
42
46
|
|
|
43
47
|
export function noStyleSpace(text: string): string
|
|
44
48
|
|
package/lib/index.js
CHANGED
|
@@ -38,9 +38,19 @@ export const addEventListener = (element, type, listener) => {
|
|
|
38
38
|
export const setAttribute = (element, name, value) =>
|
|
39
39
|
element.setAttribute(name, value)
|
|
40
40
|
|
|
41
|
-
export const setStyle = (element, values) => {
|
|
42
|
-
// setAttribute(element, "style", value)
|
|
41
|
+
export const setStyle = (element, values, overwrite) => {
|
|
42
|
+
// setAttribute(element, "style", value) -> Fail when violates CSP
|
|
43
43
|
const style = element.style
|
|
44
|
+
|
|
45
|
+
if (overwrite) {
|
|
46
|
+
if (typeof values === "string") {
|
|
47
|
+
style.cssText = values
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
style.cssText = ""
|
|
52
|
+
}
|
|
53
|
+
|
|
44
54
|
if (typeof values === "string") {
|
|
45
55
|
values = toStyleKeyValues(values)
|
|
46
56
|
}
|
|
@@ -74,14 +84,14 @@ export const toStyleMap = (styleText) => {
|
|
|
74
84
|
for (const keyValue of keyValues) {
|
|
75
85
|
const kv = keyValue.split("{")
|
|
76
86
|
if (kv[0] && kv[1]) {
|
|
77
|
-
map[kv[0]] =
|
|
87
|
+
map[kv[0]] = kv[1]
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
return map
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
export const noStyleSpace = (text) => text.replace(/\s*([^\w
|
|
94
|
+
export const noStyleSpace = (text) => text.replace(/\s*([^\w-!])\s*/gm, "$1")
|
|
85
95
|
|
|
86
96
|
export const createSetStyle = (styleText) => {
|
|
87
97
|
const styleMap = toStyleMap(styleText)
|