@i.un/libs
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -52,43 +52,38 @@ /** | ||
export declare function createElement({ tag, children, props, attrs, styles, }?: DomOptionsType): Element; | ||
type SvgElement = { | ||
tag: string; | ||
attrs?: Record<string, string>; | ||
children?: SvgElement | SvgElement[] | string; | ||
}; | ||
type SvgOptions = { | ||
width?: number; | ||
height?: number; | ||
}; | ||
interface VNode { | ||
type: string; | ||
props: Record<string, string> | null; | ||
children: VNode[] | string | null; | ||
} | ||
/** | ||
* 创建一个 SVG 元素。 | ||
* 从 VNode 对象创建 SVG 元素。 | ||
* | ||
* @param {SvgElement[] | SvgElement | string} elements - 要创建的 SVG 元素,可以是对象数组、单个对象或 innerHTML 字符串。 | ||
* @param {SvgOptions} [options] - SVG 的配置选项,包括宽度和高度。 | ||
* @returns {SVGElement} - 创建的 SVG 元素。 | ||
* @param {VNode} vnode - 表示 SVG 结构的 VNode 对象。 | ||
* @returns {SVGElement} 创建的 SVG 元素。 | ||
*/ | ||
export declare function createSvgFromVNode(vnode: VNode): SVGElement; | ||
/** | ||
* 从 SVG 字符串创建 SVG 元素。 | ||
* | ||
* @example | ||
* // 使用嵌套对象 | ||
* const svg1 = createSvg( | ||
* { | ||
* tag: 'svg', | ||
* children: [ | ||
* { tag: 'circle', attrs: { cx: '16', cy: '16', r: '10', fill: 'red' } }, | ||
* { tag: 'g', children: | ||
* { tag: 'text', attrs: { x: '10', y: '20', fill: 'black' }, children: 'Hello' } | ||
* } | ||
* ] | ||
* }, | ||
* { width: 64, height: 64 } | ||
* ); | ||
* document.body.appendChild(svg1); | ||
* @param {string} svgString - 包含 SVG 内容的字符串。 | ||
* @returns {SVGElement} 创建的 SVG 元素。 | ||
* @throws {Error} 如果解析失败或结果不是 SVG 元素。 | ||
*/ | ||
export declare function createSvgFromString(svgString: string): SVGElement; | ||
/** | ||
* 创建 SVG 元素,根据输入参数的类型选择合适的创建方法。 | ||
* | ||
* @example | ||
* // 使用 innerHTML | ||
* const svg2 = createSvg( | ||
* `<circle cx="16" cy="16" r="10" fill="red"></circle> | ||
* <text x="10" y="20" fill="black">Hello</text>` | ||
* ); | ||
* document.body.appendChild(svg2); | ||
* @param {VNode | string} params - VNode 对象或 SVG 字符串。 | ||
* @returns {SVGElement} 创建的 SVG 元素。 | ||
* @throws {Error} 如果输入字符串无法解析为有效的 SVG 元素。 | ||
*/ | ||
export declare function createSvg(elements: SvgElement[] | SvgElement | string, options?: SvgOptions): SVGSVGElement; | ||
export declare function createSvg(params: VNode | string): SVGElement; | ||
/** | ||
* 从指定的 URL 加载 SVG 内容并创建 SVG 元素。 | ||
* | ||
* @param {string} url - 包含 SVG 内容的 URL。 | ||
* @returns {Promise<SVGElement>} Promise,解析为创建的 SVG 元素。 | ||
* @throws {Error} 如果无法获取或解析 SVG 内容。 | ||
*/ | ||
export declare function createSvgFromUrl(url: string): Promise<SVGElement>; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
function t(t){return"function"==typeof(null==t?void 0:t.clone)}function e(t){const e=typeof t;return null===t||"string"===e||"number"===e||"boolean"===e||"undefined"===e}function n(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this}function r(t){return e(t)?String(t):JSON.stringify(t,function(t,e){return"object"!=typeof e||null===e||Array.isArray(e)?e:Object.keys(e).sort().reduce((t,n)=>(t[n]=e[n],t),{})})}function i(e){if(null===e||"object"!=typeof e)return e;if(t(e))return e.clone();if(Array.isArray(e))return e.map(t=>i(t));const n={};for(const t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=i(e[t]));return n}function o(t,e){let n=null;return function(...r){const i=this;null!==n&&clearTimeout(n),n=setTimeout(()=>{t.apply(i,r),n=null},e)}}function s(t,e){let n=0;return function(...r){const i=Date.now();i-n>=e&&(t.apply(this,r),n=i)}}function c(t,e=0){return new Promise(n=>{0===e?n(t()):setTimeout(()=>{n(t())},e)})}const u={};function l(t){return u[t]}const f={timeout:6e4,timeoutResult:{code:408,msg:"请求超时"},identifier:""};function a(t,e=f){return function(...n){const o=r(n)+t.name+(e.identifier||"");if(u[o])return Promise.resolve(i(l(o)));const s=o+"_l_o_a_d_i_n_g_";if(u[s]){const t=Object.assign({},f,e);return new Promise(e=>{const n=Date.now(),r=setInterval(()=>{u[o]?(clearInterval(r),e(i(l(o)))):Date.now()-n>t.timeout&&(u[s]=!1,clearInterval(r),e(i(t.timeoutResult)))},100)})}return u[s]=!0,t(...n).then(t=>(u[o]=t,i(u[o]))).catch(t=>{throw t}).finally(()=>{u[s]=!1})}}function d(t){const e=function e(...n){if(e.isExecuting)return void console.log(`Function(${t.name}) is executing.`);let r;e.isExecuting=!0;try{r=t(...n),r instanceof Promise?r.finally(()=>{e.isExecuting=!1}):e.isExecuting=!1}catch(t){throw e.isExecuting=!1,t}return r};return e.isExecuting=!1,e}function g(t,e,n,r=!1){if(e in t.style)t.style[e]=n;else{const i=r?"important":"";t.style.setProperty(e,String(n),i)}}function p({tag:t="div",children:e=[],props:n={},attrs:r={},styles:i={}}={}){const o=document.createElement(t);Object.assign(o,n);for(const[t,e]of Object.entries(r))!1!==e&&o.setAttribute(t,e);for(const[t,e]of Object.entries(i))g(o,t,e);const s=Array.isArray(e)?e:[e];for(const t of s)t&&("object"==typeof t?t instanceof Element?o.appendChild(t):o.appendChild(p(t)):o.appendChild(document.createTextNode(t)));return o}function h(t,e){const{width:n=32,height:r=32}=e||{},i=document.createElementNS("http://www.w3.org/2000/svg","svg");if(i.setAttribute("width",n.toString()),i.setAttribute("height",r.toString()),i.setAttribute("viewBox",`0 0 ${n} ${r}`),"string"==typeof t){const e=(new DOMParser).parseFromString(`<svg xmlns="http://www.w3.org/2000/svg">${t}</svg>`,"image/svg+xml").documentElement;for(;e.firstChild;)i.appendChild(e.firstChild)}else(Array.isArray(t)?t:[t]).forEach(t=>{i.appendChild(y(t))});return i}function y(t){const{tag:e,attrs:n,children:r}=t,i=document.createElementNS("http://www.w3.org/2000/svg",e);if(n)for(const[t,e]of Object.entries(n))i.setAttribute(t,e);return"string"==typeof r?i.textContent=r:r&&(Array.isArray(r)?r:[r]).forEach(t=>{i.appendChild(y(t))}),i}function m(t){t&&setTimeout(()=>{t.scrollTop=t.scrollHeight},0)}function w(t){t&&("true"!==t.dataset.isListeningForUserScroll&&(function(t){t&&t.addEventListener("scroll",()=>{!function(t,e){t.dataset.userInteracted=e?"true":"false"}(t,t.scrollTop+t.clientHeight<t.scrollHeight-5)})}(t),t.dataset.isListeningForUserScroll="true"),"true"!==t.dataset.userInteracted&&m(t))}export{a as cacheWrapper,i as cloneDeep,p as createElement,h as createSvg,o as debounce,c as delayExecution,r as generateStableUniqueKey,n as getGlobal,t as isCloneable,e as isPrimitive,m as scrollToBottom,w as scrollToBottomIfNeeded,d as singleExecutionWrapper,s as throttle}; | ||
function t(t){return"function"==typeof(null==t?void 0:t.clone)}function e(t){const e=typeof t;return null===t||"string"===e||"number"===e||"boolean"===e||"undefined"===e}function n(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this}function r(t){return e(t)?String(t):JSON.stringify(t,function(t,e){return"object"!=typeof e||null===e||Array.isArray(e)?e:Object.keys(e).sort().reduce((t,n)=>(t[n]=e[n],t),{})})}function o(e){if(null===e||"object"!=typeof e)return e;if(t(e))return e.clone();if(Array.isArray(e))return e.map(t=>o(t));const n={};for(const t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=o(e[t]));return n}function i(t,e){let n=null;return function(...r){const o=this;null!==n&&clearTimeout(n),n=setTimeout(()=>{t.apply(o,r),n=null},e)}}function s(t,e){let n=0;return function(...r){const o=Date.now();o-n>=e&&(t.apply(this,r),n=o)}}function c(t,e=0){return new Promise(n=>{0===e?n(t()):setTimeout(()=>{n(t())},e)})}const u={};function l(t){return u[t]}const a={timeout:6e4,timeoutResult:{code:408,msg:"请求超时"},identifier:""};function f(t,e=a){return function(...n){const i=r(n)+t.name+(e.identifier||"");if(u[i])return Promise.resolve(o(l(i)));const s=i+"_l_o_a_d_i_n_g_";if(u[s]){const t=Object.assign({},a,e);return new Promise(e=>{const n=Date.now(),r=setInterval(()=>{u[i]?(clearInterval(r),e(o(l(i)))):Date.now()-n>t.timeout&&(u[s]=!1,clearInterval(r),e(o(t.timeoutResult)))},100)})}return u[s]=!0,t(...n).then(t=>(u[i]=t,o(u[i]))).catch(t=>{throw t}).finally(()=>{u[s]=!1})}}function d(t){const e=function e(...n){if(e.isExecuting)return void console.log(`Function(${t.name}) is executing.`);let r;e.isExecuting=!0;try{r=t(...n),r instanceof Promise?r.finally(()=>{e.isExecuting=!1}):e.isExecuting=!1}catch(t){throw e.isExecuting=!1,t}return r};return e.isExecuting=!1,e}function p(t,e,n,r=!1){if(e in t.style)t.style[e]=n;else{const o=r?"important":"";t.style.setProperty(e,String(n),o)}}function y({tag:t="div",children:e=[],props:n={},attrs:r={},styles:o={}}={}){const i=document.createElement(t);Object.assign(i,n);for(const[t,e]of Object.entries(r))!1!==e&&i.setAttribute(t,e);for(const[t,e]of Object.entries(o))p(i,t,e);const s=Array.isArray(e)?e:[e];for(const t of s)t&&("object"==typeof t?t instanceof Element?i.appendChild(t):i.appendChild(y(t)):i.appendChild(document.createTextNode(t)));return i}function g(t){const e=document.createElementNS("http://www.w3.org/2000/svg",t.type);if(t.props)for(const[n,r]of Object.entries(t.props))e.setAttribute(n,r);if("string"==typeof t.children){const n=document.createTextNode(t.children);e.appendChild(n)}else Array.isArray(t.children)&&t.children.forEach(t=>{const n=g(t);e.appendChild(n)});return e}function m(t){const e=(new DOMParser).parseFromString(t,"image/svg+xml").documentElement;if(!(e instanceof SVGElement))throw new Error("解析失败,结果不是有效的 SVG 元素");return e}function h(t){return"string"==typeof t?m(t):g(t)}async function w(t){try{const e=await fetch(t);if(!e.ok)throw new Error(`网络请求失败: ${e.status} ${e.statusText}`);return m(await e.text())}catch(t){const e=t instanceof Error?t.message:"未知错误";throw new Error(`无法创建 SVG 元素: ${e}`)}}function b(t){t&&setTimeout(()=>{t.scrollTop=t.scrollHeight},0)}function E(t){t&&("true"!==t.dataset.isListeningForUserScroll&&(function(t){t&&t.addEventListener("scroll",()=>{!function(t,e){t.dataset.userInteracted=e?"true":"false"}(t,t.scrollTop+t.clientHeight<t.scrollHeight-5)})}(t),t.dataset.isListeningForUserScroll="true"),"true"!==t.dataset.userInteracted&&b(t))}export{f as cacheWrapper,o as cloneDeep,y as createElement,h as createSvg,m as createSvgFromString,w as createSvgFromUrl,g as createSvgFromVNode,i as debounce,c as delayExecution,r as generateStableUniqueKey,n as getGlobal,t as isCloneable,e as isPrimitive,b as scrollToBottom,E as scrollToBottomIfNeeded,d as singleExecutionWrapper,s as throttle}; | ||
//# sourceMappingURL=index.modern.js.map |
@@ -1,2 +0,2 @@ | ||
function t(t){return"function"==typeof(null==t?void 0:t.clone)}function e(t){var e=typeof t;return null===t||"string"===e||"number"===e||"boolean"===e||"undefined"===e}function n(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this}function r(t){return e(t)?String(t):JSON.stringify(t,function(t,e){return"object"!=typeof e||null===e||Array.isArray(e)?e:Object.keys(e).sort().reduce(function(t,n){return t[n]=e[n],t},{})})}function i(e){if(null===e||"object"!=typeof e)return e;if(t(e))return e.clone();if(Array.isArray(e))return e.map(function(t){return i(t)});var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=i(e[r]));return n}function o(t,e){var n=null;return function(){var r=arguments,i=this;null!==n&&clearTimeout(n),n=setTimeout(function(){t.apply(i,[].slice.call(r)),n=null},e)}}function a(t,e){var n=0;return function(){var r=Date.now();r-n>=e&&(t.apply(this,[].slice.call(arguments)),n=r)}}function u(t,e){return void 0===e&&(e=0),new Promise(function(n){0===e?n(t()):setTimeout(function(){n(t())},e)})}var l={};function c(t){return l[t]}var s={timeout:6e4,timeoutResult:{code:408,msg:"请求超时"},identifier:""};function f(t,e){return void 0===e&&(e=s),function(){var n=[].slice.call(arguments),o=r(n)+t.name+(e.identifier||"");if(l[o])return Promise.resolve(i(c(o)));var a=o+"_l_o_a_d_i_n_g_";if(l[a]){var u=Object.assign({},s,e);return new Promise(function(t){var e=Date.now(),n=setInterval(function(){l[o]?(clearInterval(n),t(i(c(o)))):Date.now()-e>u.timeout&&(l[a]=!1,clearInterval(n),t(i(u.timeoutResult)))},100)})}return l[a]=!0,t.apply(void 0,n).then(function(t){return l[o]=t,i(l[o])}).catch(function(t){throw t}).finally(function(){l[a]=!1})}}function d(t){var e=function(){if(!e.isExecuting){var n;e.isExecuting=!0;try{(n=t.apply(void 0,[].slice.call(arguments)))instanceof Promise?n.finally(function(){e.isExecuting=!1}):e.isExecuting=!1}catch(t){throw e.isExecuting=!1,t}return n}console.log("Function("+t.name+") is executing.")};return e.isExecuting=!1,e}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function g(t,e,n,r){if(void 0===r&&(r=!1),e in t.style)t.style[e]=n;else{var i=r?"important":"";t.style.setProperty(e,String(n),i)}}function p(t){var e=void 0===t?{}:t,n=e.tag,r=e.children,i=void 0===r?[]:r,o=e.props,a=void 0===o?{}:o,u=e.attrs,l=void 0===u?{}:u,c=e.styles,s=void 0===c?{}:c,f=document.createElement(void 0===n?"div":n);Object.assign(f,a);for(var d=0,y=Object.entries(l);d<y.length;d++){var h=y[d],m=h[1];!1!==m&&f.setAttribute(h[0],m)}for(var b=0,w=Object.entries(s);b<w.length;b++){var A=w[b];g(f,A[0],A[1])}for(var E,S=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,e){if(t){if("string"==typeof t)return v(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?v(t,e):void 0}}(t))){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(Array.isArray(i)?i:[i]);!(E=S()).done;){var x=E.value;x&&("object"==typeof x?x instanceof Element?f.appendChild(x):f.appendChild(p(x)):f.appendChild(document.createTextNode(x)))}return f}function y(t,e){var n=e||{},r=n.width,i=void 0===r?32:r,o=n.height,a=void 0===o?32:o,u=document.createElementNS("http://www.w3.org/2000/svg","svg");if(u.setAttribute("width",i.toString()),u.setAttribute("height",a.toString()),u.setAttribute("viewBox","0 0 "+i+" "+a),"string"==typeof t)for(var l=(new DOMParser).parseFromString('<svg xmlns="http://www.w3.org/2000/svg">'+t+"</svg>","image/svg+xml").documentElement;l.firstChild;)u.appendChild(l.firstChild);else(Array.isArray(t)?t:[t]).forEach(function(t){u.appendChild(h(t))});return u}function h(t){var e=t.attrs,n=t.children,r=document.createElementNS("http://www.w3.org/2000/svg",t.tag);if(e)for(var i=0,o=Object.entries(e);i<o.length;i++){var a=o[i];r.setAttribute(a[0],a[1])}return"string"==typeof n?r.textContent=n:n&&(Array.isArray(n)?n:[n]).forEach(function(t){r.appendChild(h(t))}),r}function m(t){t&&setTimeout(function(){t.scrollTop=t.scrollHeight},0)}function b(t){t&&("true"!==t.dataset.isListeningForUserScroll&&(function(t){t&&t.addEventListener("scroll",function(){!function(t,e){t.dataset.userInteracted=e?"true":"false"}(t,t.scrollTop+t.clientHeight<t.scrollHeight-5)})}(t),t.dataset.isListeningForUserScroll="true"),"true"!==t.dataset.userInteracted&&m(t))}export{f as cacheWrapper,i as cloneDeep,p as createElement,y as createSvg,o as debounce,u as delayExecution,r as generateStableUniqueKey,n as getGlobal,t as isCloneable,e as isPrimitive,m as scrollToBottom,b as scrollToBottomIfNeeded,d as singleExecutionWrapper,a as throttle}; | ||
function t(t){return"function"==typeof(null==t?void 0:t.clone)}function e(t){var e=typeof t;return null===t||"string"===e||"number"===e||"boolean"===e||"undefined"===e}function n(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this}function r(t){return e(t)?String(t):JSON.stringify(t,function(t,e){return"object"!=typeof e||null===e||Array.isArray(e)?e:Object.keys(e).sort().reduce(function(t,n){return t[n]=e[n],t},{})})}function i(e){if(null===e||"object"!=typeof e)return e;if(t(e))return e.clone();if(Array.isArray(e))return e.map(function(t){return i(t)});var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=i(e[r]));return n}function o(t,e){var n=null;return function(){var r=arguments,i=this;null!==n&&clearTimeout(n),n=setTimeout(function(){t.apply(i,[].slice.call(r)),n=null},e)}}function a(t,e){var n=0;return function(){var r=Date.now();r-n>=e&&(t.apply(this,[].slice.call(arguments)),n=r)}}function u(t,e){return void 0===e&&(e=0),new Promise(function(n){0===e?n(t()):setTimeout(function(){n(t())},e)})}var c={};function l(t){return c[t]}var s={timeout:6e4,timeoutResult:{code:408,msg:"请求超时"},identifier:""};function f(t,e){return void 0===e&&(e=s),function(){var n=[].slice.call(arguments),o=r(n)+t.name+(e.identifier||"");if(c[o])return Promise.resolve(i(l(o)));var a=o+"_l_o_a_d_i_n_g_";if(c[a]){var u=Object.assign({},s,e);return new Promise(function(t){var e=Date.now(),n=setInterval(function(){c[o]?(clearInterval(n),t(i(l(o)))):Date.now()-e>u.timeout&&(c[a]=!1,clearInterval(n),t(i(u.timeoutResult)))},100)})}return c[a]=!0,t.apply(void 0,n).then(function(t){return c[o]=t,i(c[o])}).catch(function(t){throw t}).finally(function(){c[a]=!1})}}function d(t){var e=function(){if(!e.isExecuting){var n;e.isExecuting=!0;try{(n=t.apply(void 0,[].slice.call(arguments)))instanceof Promise?n.finally(function(){e.isExecuting=!1}):e.isExecuting=!1}catch(t){throw e.isExecuting=!1,t}return n}console.log("Function("+t.name+") is executing.")};return e.isExecuting=!1,e}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function p(t,e,n,r){if(void 0===r&&(r=!1),e in t.style)t.style[e]=n;else{var i=r?"important":"";t.style.setProperty(e,String(n),i)}}var y=function(t){try{return Promise.resolve(function(e,n){try{var r=Promise.resolve(fetch(t)).then(function(t){if(!t.ok)throw new Error("网络请求失败: "+t.status+" "+t.statusText);return Promise.resolve(t.text()).then(g)})}catch(t){return n(t)}return r&&r.then?r.then(void 0,n):r}(0,function(t){var e=t instanceof Error?t.message:"未知错误";throw new Error("无法创建 SVG 元素: "+e)}))}catch(t){return Promise.reject(t)}};function m(t){var e=void 0===t?{}:t,n=e.tag,r=e.children,i=void 0===r?[]:r,o=e.props,a=void 0===o?{}:o,u=e.attrs,c=void 0===u?{}:u,l=e.styles,s=void 0===l?{}:l,f=document.createElement(void 0===n?"div":n);Object.assign(f,a);for(var d=0,y=Object.entries(c);d<y.length;d++){var h=y[d],g=h[1];!1!==g&&f.setAttribute(h[0],g)}for(var b=0,w=Object.entries(s);b<w.length;b++){var E=w[b];p(f,E[0],E[1])}for(var A,S=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,e){if(t){if("string"==typeof t)return v(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?v(t,e):void 0}}(t))){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(Array.isArray(i)?i:[i]);!(A=S()).done;){var x=A.value;x&&("object"==typeof x?x instanceof Element?f.appendChild(x):f.appendChild(m(x)):f.appendChild(document.createTextNode(x)))}return f}function h(t){var e=document.createElementNS("http://www.w3.org/2000/svg",t.type);if(t.props)for(var n=0,r=Object.entries(t.props);n<r.length;n++){var i=r[n];e.setAttribute(i[0],i[1])}if("string"==typeof t.children){var o=document.createTextNode(t.children);e.appendChild(o)}else Array.isArray(t.children)&&t.children.forEach(function(t){var n=h(t);e.appendChild(n)});return e}function g(t){var e=(new DOMParser).parseFromString(t,"image/svg+xml").documentElement;if(!(e instanceof SVGElement))throw new Error("解析失败,结果不是有效的 SVG 元素");return e}function b(t){return"string"==typeof t?g(t):h(t)}function w(t){t&&setTimeout(function(){t.scrollTop=t.scrollHeight},0)}function E(t){t&&("true"!==t.dataset.isListeningForUserScroll&&(function(t){t&&t.addEventListener("scroll",function(){!function(t,e){t.dataset.userInteracted=e?"true":"false"}(t,t.scrollTop+t.clientHeight<t.scrollHeight-5)})}(t),t.dataset.isListeningForUserScroll="true"),"true"!==t.dataset.userInteracted&&w(t))}export{f as cacheWrapper,i as cloneDeep,m as createElement,b as createSvg,g as createSvgFromString,y as createSvgFromUrl,h as createSvgFromVNode,o as debounce,u as delayExecution,r as generateStableUniqueKey,n as getGlobal,t as isCloneable,e as isPrimitive,w as scrollToBottom,E as scrollToBottomIfNeeded,d as singleExecutionWrapper,a as throttle}; | ||
//# sourceMappingURL=index.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).iunLibs={})}(this,function(t){function e(t){return"function"==typeof(null==t?void 0:t.clone)}function n(t){var e=typeof t;return null===t||"string"===e||"number"===e||"boolean"===e||"undefined"===e}function r(t){return n(t)?String(t):JSON.stringify(t,function(t,e){return"object"!=typeof e||null===e||Array.isArray(e)?e:Object.keys(e).sort().reduce(function(t,n){return t[n]=e[n],t},{})})}function i(t){if(null===t||"object"!=typeof t)return t;if(e(t))return t.clone();if(Array.isArray(t))return t.map(function(t){return i(t)});var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=i(t[r]));return n}var o={};function a(t){return o[t]}var l={timeout:6e4,timeoutResult:{code:408,msg:"请求超时"},identifier:""};function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function c(t,e,n,r){if(void 0===r&&(r=!1),e in t.style)t.style[e]=n;else{var i=r?"important":"";t.style.setProperty(e,String(n),i)}}function s(t){var e=t.attrs,n=t.children,r=document.createElementNS("http://www.w3.org/2000/svg",t.tag);if(e)for(var i=0,o=Object.entries(e);i<o.length;i++){var a=o[i];r.setAttribute(a[0],a[1])}return"string"==typeof n?r.textContent=n:n&&(Array.isArray(n)?n:[n]).forEach(function(t){r.appendChild(s(t))}),r}function f(t){t&&setTimeout(function(){t.scrollTop=t.scrollHeight},0)}t.cacheWrapper=function(t,e){return void 0===e&&(e=l),function(){var n=[].slice.call(arguments),u=r(n)+t.name+(e.identifier||"");if(o[u])return Promise.resolve(i(a(u)));var c=u+"_l_o_a_d_i_n_g_";if(o[c]){var s=Object.assign({},l,e);return new Promise(function(t){var e=Date.now(),n=setInterval(function(){o[u]?(clearInterval(n),t(i(a(u)))):Date.now()-e>s.timeout&&(o[c]=!1,clearInterval(n),t(i(s.timeoutResult)))},100)})}return o[c]=!0,t.apply(void 0,n).then(function(t){return o[u]=t,i(o[u])}).catch(function(t){throw t}).finally(function(){o[c]=!1})}},t.cloneDeep=i,t.createElement=function t(e){var n=void 0===e?{}:e,r=n.tag,i=n.children,o=void 0===i?[]:i,a=n.props,l=void 0===a?{}:a,s=n.attrs,f=void 0===s?{}:s,d=n.styles,v=void 0===d?{}:d,p=document.createElement(void 0===r?"div":r);Object.assign(p,l);for(var g=0,y=Object.entries(f);g<y.length;g++){var h=y[g],m=h[1];!1!==m&&p.setAttribute(h[0],m)}for(var b=0,w=Object.entries(v);b<w.length;b++){var A=w[b];c(p,A[0],A[1])}for(var x,E=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,e){if(t){if("string"==typeof t)return u(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,e):void 0}}(t))){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(Array.isArray(o)?o:[o]);!(x=E()).done;){var S=x.value;S&&("object"==typeof S?S instanceof Element?p.appendChild(S):p.appendChild(t(S)):p.appendChild(document.createTextNode(S)))}return p},t.createSvg=function(t,e){var n=e||{},r=n.width,i=void 0===r?32:r,o=n.height,a=void 0===o?32:o,l=document.createElementNS("http://www.w3.org/2000/svg","svg");if(l.setAttribute("width",i.toString()),l.setAttribute("height",a.toString()),l.setAttribute("viewBox","0 0 "+i+" "+a),"string"==typeof t)for(var u=(new DOMParser).parseFromString('<svg xmlns="http://www.w3.org/2000/svg">'+t+"</svg>","image/svg+xml").documentElement;u.firstChild;)l.appendChild(u.firstChild);else(Array.isArray(t)?t:[t]).forEach(function(t){l.appendChild(s(t))});return l},t.debounce=function(t,e){var n=null;return function(){var r=arguments,i=this;null!==n&&clearTimeout(n),n=setTimeout(function(){t.apply(i,[].slice.call(r)),n=null},e)}},t.delayExecution=function(t,e){return void 0===e&&(e=0),new Promise(function(n){0===e?n(t()):setTimeout(function(){n(t())},e)})},t.generateStableUniqueKey=r,t.getGlobal=function(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this},t.isCloneable=e,t.isPrimitive=n,t.scrollToBottom=f,t.scrollToBottomIfNeeded=function(t){t&&("true"!==t.dataset.isListeningForUserScroll&&(function(t){t&&t.addEventListener("scroll",function(){!function(t,e){t.dataset.userInteracted=e?"true":"false"}(t,t.scrollTop+t.clientHeight<t.scrollHeight-5)})}(t),t.dataset.isListeningForUserScroll="true"),"true"!==t.dataset.userInteracted&&f(t))},t.singleExecutionWrapper=function(t){var e=function(){if(!e.isExecuting){var n;e.isExecuting=!0;try{(n=t.apply(void 0,[].slice.call(arguments)))instanceof Promise?n.finally(function(){e.isExecuting=!1}):e.isExecuting=!1}catch(t){throw e.isExecuting=!1,t}return n}console.log("Function("+t.name+") is executing.")};return e.isExecuting=!1,e},t.throttle=function(t,e){var n=0;return function(){var r=Date.now();r-n>=e&&(t.apply(this,[].slice.call(arguments)),n=r)}}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).iunLibs={})}(this,function(e){function t(e){return"function"==typeof(null==e?void 0:e.clone)}function n(e){var t=typeof e;return null===e||"string"===t||"number"===t||"boolean"===t||"undefined"===t}function r(e){return n(e)?String(e):JSON.stringify(e,function(e,t){return"object"!=typeof t||null===t||Array.isArray(t)?t:Object.keys(t).sort().reduce(function(e,n){return e[n]=t[n],e},{})})}function o(e){if(null===e||"object"!=typeof e)return e;if(t(e))return e.clone();if(Array.isArray(e))return e.map(function(e){return o(e)});var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=o(e[r]));return n}var i={};function a(e){return i[e]}var u={timeout:6e4,timeoutResult:{code:408,msg:"请求超时"},identifier:""};function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function l(e,t,n,r){if(void 0===r&&(r=!1),t in e.style)e.style[t]=n;else{var o=r?"important":"";e.style.setProperty(t,String(n),o)}}function s(e){var t=document.createElementNS("http://www.w3.org/2000/svg",e.type);if(e.props)for(var n=0,r=Object.entries(e.props);n<r.length;n++){var o=r[n];t.setAttribute(o[0],o[1])}if("string"==typeof e.children){var i=document.createTextNode(e.children);t.appendChild(i)}else Array.isArray(e.children)&&e.children.forEach(function(e){var n=s(e);t.appendChild(n)});return t}function f(e){var t=(new DOMParser).parseFromString(e,"image/svg+xml").documentElement;if(!(t instanceof SVGElement))throw new Error("解析失败,结果不是有效的 SVG 元素");return t}function d(e){e&&setTimeout(function(){e.scrollTop=e.scrollHeight},0)}e.cacheWrapper=function(e,t){return void 0===t&&(t=u),function(){var n=[].slice.call(arguments),c=r(n)+e.name+(t.identifier||"");if(i[c])return Promise.resolve(o(a(c)));var l=c+"_l_o_a_d_i_n_g_";if(i[l]){var s=Object.assign({},u,t);return new Promise(function(e){var t=Date.now(),n=setInterval(function(){i[c]?(clearInterval(n),e(o(a(c)))):Date.now()-t>s.timeout&&(i[l]=!1,clearInterval(n),e(o(s.timeoutResult)))},100)})}return i[l]=!0,e.apply(void 0,n).then(function(e){return i[c]=e,o(i[c])}).catch(function(e){throw e}).finally(function(){i[l]=!1})}},e.cloneDeep=o,e.createElement=function e(t){var n=void 0===t?{}:t,r=n.tag,o=n.children,i=void 0===o?[]:o,a=n.props,u=void 0===a?{}:a,s=n.attrs,f=void 0===s?{}:s,d=n.styles,v=void 0===d?{}:d,p=document.createElement(void 0===r?"div":r);Object.assign(p,u);for(var y=0,m=Object.entries(f);y<m.length;y++){var g=m[y],h=g[1];!1!==h&&p.setAttribute(g[0],h)}for(var b=0,w=Object.entries(v);b<w.length;b++){var E=w[b];l(p,E[0],E[1])}for(var S,x=function(e){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,t){if(e){if("string"==typeof e)return c(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,t):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(Array.isArray(i)?i:[i]);!(S=x()).done;){var A=S.value;A&&("object"==typeof A?A instanceof Element?p.appendChild(A):p.appendChild(e(A)):p.appendChild(document.createTextNode(A)))}return p},e.createSvg=function(e){return"string"==typeof e?f(e):s(e)},e.createSvgFromString=f,e.createSvgFromUrl=function(e){try{return Promise.resolve(function(t,n){try{var r=Promise.resolve(fetch(e)).then(function(e){if(!e.ok)throw new Error("网络请求失败: "+e.status+" "+e.statusText);return Promise.resolve(e.text()).then(f)})}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(0,function(e){var t=e instanceof Error?e.message:"未知错误";throw new Error("无法创建 SVG 元素: "+t)}))}catch(e){return Promise.reject(e)}},e.createSvgFromVNode=s,e.debounce=function(e,t){var n=null;return function(){var r=arguments,o=this;null!==n&&clearTimeout(n),n=setTimeout(function(){e.apply(o,[].slice.call(r)),n=null},t)}},e.delayExecution=function(e,t){return void 0===t&&(t=0),new Promise(function(n){0===t?n(e()):setTimeout(function(){n(e())},t)})},e.generateStableUniqueKey=r,e.getGlobal=function(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this},e.isCloneable=t,e.isPrimitive=n,e.scrollToBottom=d,e.scrollToBottomIfNeeded=function(e){e&&("true"!==e.dataset.isListeningForUserScroll&&(function(e){e&&e.addEventListener("scroll",function(){!function(e,t){e.dataset.userInteracted=t?"true":"false"}(e,e.scrollTop+e.clientHeight<e.scrollHeight-5)})}(e),e.dataset.isListeningForUserScroll="true"),"true"!==e.dataset.userInteracted&&d(e))},e.singleExecutionWrapper=function(e){var t=function(){if(!t.isExecuting){var n;t.isExecuting=!0;try{(n=e.apply(void 0,[].slice.call(arguments)))instanceof Promise?n.finally(function(){t.isExecuting=!1}):t.isExecuting=!1}catch(e){throw t.isExecuting=!1,e}return n}console.log("Function("+e.name+") is executing.")};return t.isExecuting=!1,t},e.throttle=function(e,t){var n=0;return function(){var r=Date.now();r-n>=t&&(e.apply(this,[].slice.call(arguments)),n=r)}}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@i.un/libs", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "一个实用的ts函数库", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
133015
330
4