ph-utils 0.2.12 → 0.2.13

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/dom.d.ts CHANGED
@@ -80,3 +80,13 @@ export declare function attr(elem: HTMLElement, key: string, value?: string): st
80
80
  * @returns
81
81
  */
82
82
  export declare function parent(el: HTMLElement): HTMLElement;
83
+ /**
84
+ * 获取隐藏节点的尺寸
85
+ * @param {string | HTMLElement} hideNode - The node to hide.
86
+ * @param parent - 添加临时节点的父节点,默认为: body.
87
+ * @returns The DOMRect of the element.
88
+ */
89
+ export declare function queryHideNodeSize(hideNode: string | HTMLElement, parent?: HTMLElement): {
90
+ width: number;
91
+ height: number;
92
+ };
package/lib/dom.js CHANGED
@@ -164,3 +164,27 @@ export function attr(elem, key, value) {
164
164
  export function parent(el) {
165
165
  return el.parentNode;
166
166
  }
167
+ /**
168
+ * 获取隐藏节点的尺寸
169
+ * @param {string | HTMLElement} hideNode - The node to hide.
170
+ * @param parent - 添加临时节点的父节点,默认为: body.
171
+ * @returns The DOMRect of the element.
172
+ */
173
+ export function queryHideNodeSize(hideNode, parent = document.body) {
174
+ // 计算折叠菜单的高度
175
+ let $tmp = document.createElement('div');
176
+ $tmp.style.cssText = 'position:fixed;left:-1000px;top:-1000px;opacity:0;';
177
+ let $tmpInner = document.createElement('div');
178
+ $tmpInner.style.cssText = 'position:relative;';
179
+ if (typeof hideNode === 'string') {
180
+ $tmpInner.innerHTML = hideNode;
181
+ }
182
+ else {
183
+ $tmpInner.appendChild(hideNode.cloneNode(true));
184
+ }
185
+ $tmp.appendChild($tmpInner);
186
+ parent.appendChild($tmp);
187
+ let rect = $tmpInner.children[0].getBoundingClientRect();
188
+ parent.removeChild($tmp);
189
+ return { width: rect.width, height: rect.height };
190
+ }
package/lib/index.js CHANGED
@@ -86,9 +86,10 @@ exports.BaseError = BaseError;
86
86
  function throttle(func, wait = 300) {
87
87
  let t = -1;
88
88
  return function (...args) {
89
+ const self = this;
89
90
  clearTimeout(t);
90
91
  t = setTimeout(() => {
91
- func(...args);
92
+ func.apply(self, args);
92
93
  }, wait);
93
94
  };
94
95
  }
package/lib/index_m.js CHANGED
@@ -73,9 +73,10 @@ export class BaseError extends Error {
73
73
  export function throttle(func, wait = 300) {
74
74
  let t = -1;
75
75
  return function (...args) {
76
+ const self = this;
76
77
  clearTimeout(t);
77
78
  t = setTimeout(() => {
78
- func(...args);
79
+ func.apply(self, args);
79
80
  }, wait);
80
81
  };
81
82
  }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "module": "lib/index_m.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "browser": "lib/index_m.js",
8
- "version": "0.2.12",
8
+ "version": "0.2.13",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https//gitee.com/towardly/ph.git",