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/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "5.3.0";
1
+ var VERSION = "5.3.1";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
@@ -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
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "5.3.0";
3
+ var VERSION = "5.3.1";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "5.3.0",
3
+ "version": "5.3.1",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -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;