util-helpers 5.3.0 → 5.3.1
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/dist/util-helpers.js +5 -2
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/VERSION.js +1 -1
- package/esm/injectStyle.js +4 -1
- package/lib/VERSION.js +1 -1
- package/lib/injectStyle.js +4 -1
- package/package.json +1 -1
- package/types/injectStyle.d.ts +2 -0
package/esm/VERSION.js
CHANGED
package/esm/injectStyle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function injectStyle(css, options) {
|
|
2
|
-
var _a = options || {}, _b = _a.container, container = _b === void 0 ? document.head || document.getElementsByTagName('head')[0] || document.body : _b, _c = _a.insertAt, insertAt = _c === void 0 ? 'top' : _c;
|
|
2
|
+
var _a = options || {}, _b = _a.container, container = _b === void 0 ? document.head || document.getElementsByTagName('head')[0] || document.body : _b, _c = _a.insertAt, insertAt = _c === void 0 ? 'top' : _c, onBefore = _a.onBefore;
|
|
3
3
|
var style = document.createElement('style');
|
|
4
4
|
if (style.styleSheet) {
|
|
5
5
|
style.styleSheet.cssText = css;
|
|
@@ -7,6 +7,9 @@ function injectStyle(css, options) {
|
|
|
7
7
|
else {
|
|
8
8
|
style.appendChild(document.createTextNode(css));
|
|
9
9
|
}
|
|
10
|
+
if (typeof onBefore === 'function') {
|
|
11
|
+
onBefore(style);
|
|
12
|
+
}
|
|
10
13
|
var atTop = insertAt === 'top';
|
|
11
14
|
if (atTop && container.prepend) {
|
|
12
15
|
container.prepend(style);
|
package/lib/VERSION.js
CHANGED
package/lib/injectStyle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
function injectStyle(css, options) {
|
|
4
|
-
var _a = options || {}, _b = _a.container, container = _b === void 0 ? document.head || document.getElementsByTagName('head')[0] || document.body : _b, _c = _a.insertAt, insertAt = _c === void 0 ? 'top' : _c;
|
|
4
|
+
var _a = options || {}, _b = _a.container, container = _b === void 0 ? document.head || document.getElementsByTagName('head')[0] || document.body : _b, _c = _a.insertAt, insertAt = _c === void 0 ? 'top' : _c, onBefore = _a.onBefore;
|
|
5
5
|
var style = document.createElement('style');
|
|
6
6
|
if (style.styleSheet) {
|
|
7
7
|
style.styleSheet.cssText = css;
|
|
@@ -9,6 +9,9 @@ function injectStyle(css, options) {
|
|
|
9
9
|
else {
|
|
10
10
|
style.appendChild(document.createTextNode(css));
|
|
11
11
|
}
|
|
12
|
+
if (typeof onBefore === 'function') {
|
|
13
|
+
onBefore(style);
|
|
14
|
+
}
|
|
12
15
|
var atTop = insertAt === 'top';
|
|
13
16
|
if (atTop && container.prepend) {
|
|
14
17
|
container.prepend(style);
|
package/package.json
CHANGED
package/types/injectStyle.d.ts
CHANGED
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
* @param {Object} [options] 配置项。
|
|
8
8
|
* @param {HTMLElement} [options.container=document.head] 要注入样式的容器。默认 `document.head`。如果 `document.head` 不存在,默认 `document.body`。
|
|
9
9
|
* @param {'top' | 'bottom'} [options.insertAt='top'] 注入容器内容前面还是后面。默认 `top`。
|
|
10
|
+
* @param {Function} [options.onBefore] 注入样式前的回调方法。
|
|
10
11
|
* @returns {HTMLStyleElement} `style` 元素。
|
|
11
12
|
*/
|
|
12
13
|
declare function injectStyle(css: string, options?: {
|
|
13
14
|
container?: HTMLElement;
|
|
14
15
|
insertAt?: 'top' | 'bottom';
|
|
16
|
+
onBefore?: (style: HTMLStyleElement) => void;
|
|
15
17
|
}): HTMLStyleElement;
|
|
16
18
|
export default injectStyle;
|