@ka-libs/utils 1.0.0 → 1.0.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/cjs/index.cjs +1 -1
- package/dist/esm/config/constants.js +1 -1
- package/dist/esm/exports.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +86 -75
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(t){return t.split(",").map(t=>+t.replace(/\D/g,""))}function e(t){return t<0&&(t=4294967295+t+1),t.toString(16).toUpperCase()}function n(e,n){const o="string"==typeof e?t(e):e;if(n<=0||!Number.isInteger(n))throw new Error("Invalid number of steps");const r=1/n;let i=[...o];for(let t=0;t<n;t++)i=[Math.max(0,i[0]*(1-r)),Math.max(0,i[1]*(1-r)),Math.max(0,i[2]*(1-r))];return"string"==typeof e?`rgb(${i.join(", ")})`:i}function o(e,n){const o="string"==typeof e?t(e):e,[r,i,s]=o;return"string"==typeof e?`hsl(${r}, ${i*n}%, ${s}%)`:[r,i*n/100,s/100]}function r(e){const n="string"==typeof e?t(e):e,[o,r,i]=n,s=(t=0,e=3)=>Math.floor(t*10**e)/10**e,[a,c,l]=[o/255,r/255,i/255],[u,p]=[Math.max(a,c,l),Math.min(a,c,l)],f=u-p;let h=0;0===f?h=0:u===a?h=(c-l)/f%6*60:u===c?h=60*((l-a)/f+2):u===l&&(h=60*((a-c)/f+4)),h=Math.floor(((t,e)=>{let n=t%e;return n<0&&(n+=e),n})(h,360));const d=s((u+p)/2),m=0===f?0:s(f/(1-Math.abs(2*d-1))),g=Math.round(h),b=Math.round(100*m)/100,y=Math.round(100*d)/100;return"string"==typeof e?`hsl(${g}, ${100*b}%, ${100*y}%)`:[g,b,y]}function i(e){const n="string"==typeof e?t(e):e;let[o,r,i]=n;r>1&&(r/=100),i>1&&(i/=100);const s=(1-Math.abs(2*i-1))*r,a=s*(1-Math.abs(o/60%2-1)),c=i-s/2,l=[];o>=360&&(o=0),o>=0&&o<60?l.push(s,a,0):o>=60&&o<120?l.push(a,s,0):o>=120&&o<180?l.push(0,s,a):o>=180&&o<240?l.push(0,a,s):o>=240&&o<300?l.push(a,0,s):o>=300&&o<360&&l.push(s,0,a);const[u,p,f]=l,h=Math.round(Math.abs(255*(u+c)))||0,d=Math.round(Math.abs(255*(p+c)))||0,m=Math.round(Math.abs(255*(f+c)))||0;return"string"==typeof e?`rgb(${h}, ${d}, ${m})`:[h,d,m]}function s(n){const o="string"==typeof n?t(n):n,[r,i,s]=o;return`#${e(r)}${e(i)}${e(s)}`}function a(t,e){if(!t)return!1;const n=u(e),o=t.className||"";return new Set(o.split(" ").filter(t=>!!t)).has(n)}function c(t,e){if(!t)return;const n=u(e),o=t.className||"",r=new Set(o.split(" ").filter(t=>!!t));r.add(n),t.className=Array.from(r).join(" ")}function l(t,e){if(!t)return;const n=u(e),o=t.className||"",r=new Set(o.split(" ").filter(t=>!!t));r.delete(n),t.className=Array.from(r).join(" ")}function u(t){return t.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`).replace(/^-/,"").replace(/[-]{1,}/,"-").toLowerCase()}function p(t){return t.replace(/-([a-z])/g,t=>t.slice(1,2).toUpperCase())}function f(t,e){let n=!0;for(const[o,r]of e){if(o in t){n=t[o]===r}else n=!1;if(!n)break}return n}function h(t,e){const n=Array.isArray(t)?[...t]:{...t};for(const t in e)Object.prototype.hasOwnProperty.call(e,t)&&("object"==typeof e[t]&&null!==e[t]?Array.isArray(e[t])?n[t]=h(n[t]||[],e[t]):n[t]=h(n[t]||{},e[t]):n[t]=e[t]);return n}function d(t){return Array.isArray(t)?h([],t):h({},t)}function m(t){const e={};for(const[n,o]of Object.entries(t))"string"!=typeof o&&"number"!=typeof o||"string"==typeof o&&""===o.trim()||(e[n]=o);return e}function g(t,e,n){let o=0;return function(...r){o||(o=setTimeout(()=>{e.apply(t,r),o=0},n))}}function b(t,e,n){return t>=n.left&&t<=n.right&&e>=n.top&&e<=n.bottom}function y(t){t.parentNode?.removeChild(t)}function v(t){const e="A".charCodeAt(0),n="Z".charCodeAt(0)-e+1;let o="";for(;t>=0;)o=String.fromCharCode(t%n+e)+o,t=Math.floor(t/n)-1;return o}function w(t){if(0===t)return"零";const e=["","万","亿","万亿"],n=["零","一","二","三","四","五","六","七","八","九"],o=["千","百","十",""],r=t.toString(),i=[];for(let t=r.length;t>0;t-=4)i.push(r.substring(Math.max(0,t-4),t));if(i.reverse(),i.length>e.length)throw new Error("数字太大,超过万亿级别");let s="",a=!1;for(let t=0;t<i.length;t++){const r=i[t].padStart(4,"0");let c="",l=!1,u=!1;for(let t=0;t<4;t++){const e=parseInt(r[t],10);0!==e?(l&&u&&(c+="零",u=!1),c+=n[e]+o[t],l=!0):l&&(u=!0)}c&&(a&&(s+="零"),s+=c+e[i.length-1-t],a=!0)}return s.startsWith("一十")&&(s="十"+s.substring(2)),s}function M(t){const e={"零":0,"一":1,"二":2,"三":3,"四":4,"五":5,"六":6,"七":7,"八":8,"九":9},n={"十":10,"百":100,"千":1e3,"万":1e4,"亿":1e8};let o=0,r=0,i=0,s=0;for(let a=0;a<t.length;a++){const c=t[a];if(c in e)i=e[c],a===t.length-1&&(r+=i);else if(c in n){const t=n[c];if(t>=1e4){r+=i,i=0;s>t?o+=r*t:o=(o+r)*t,r=0,s=t}else 0===i&&(i=1),r+=i*t,i=0}}return o+r}function C(){window.getSelection()?.removeAllRanges()}function k(){return window.location}Object.defineProperty(exports,"__esModule",{value:!0});const _=[];function x(){if(_.length>0)return _;if("deviceXDPI"in window.screen&&"deviceYDPI"in window.screen)_.push(window.screen.deviceXDPI),_.push(window.screen.deviceYDPI);else{const t=document.createElement("DIV");t.style.cssText="width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden",document.body.appendChild(t),_.push(t.offsetWidth),_.push(t.offsetHeight),t.parentNode?.removeChild(t)}return _}function E(t,e=0){if("number"!=typeof t){t=+`${t}`.replace("pt","")}return Math.floor(t*(x()[0]/72)*10**e)/10**e}function N(t,e=2){return t=t/x()[0]*25.4,t/=.367,Math.round(t*10**e)/10**e}function $(t,e=2){return t=t/x()[0]*25.4,Math.round(t*10**e)/10**e}function S(t,e=!1){const n=t/25.4*x()[0];return e?n:Math.floor(n)}function D(t,e){if(!t)return"";let n=!1,o=0,r="";for(const i of t)"."!==i?(n?o+=1:r+=i,n&&o<=e&&(r+=i)):(n=!0,e>0&&(r+=i));!n&&e>0&&(r+=".");for(let t=o;t<e;t+=1)r+="0";return r}function T(t,e=3){const n=Math.floor(t).toString(),o=Math.max(e,n.length);return Array.from({length:o-n.length}).map(()=>"0").join("")+n}function j(t,e){const[n,o]=t[0]<=t[1]?t:[t[1],t[0]],[r,i]=e[0]<=e[1]?e:[e[1],e[0]],s=Math.max(n,r),a=Math.min(o,i);return s>a?null:[s,a]}function A(t,e=0,n){return 0===t.length?0:(void 0===n&&(n=t.length),e===n?0:1===t.length?t[0]:t.slice(e,n).reduce((t,e)=>t+e))}function L(t){console.log({url:t});try{const e=new URL(t),n=k();return"data:"===e.protocol||("blob:"===e.protocol||e.protocol===n.protocol&&e.hostname===n.hostname)}catch(t){return console.error(t),!1}}function O(t){const e=new URL(t);if("blob:"!==e.protocol)return!1;const n=k();return e.origin===n.origin}function I(t,e){const n=t.getFullYear(),o=t.getMonth()+1,r=t.getDate();return e.replace("yyyy",n.toString()).replace("mm",o.toString().padStart(2,"0")).replace("dd",r.toString().padStart(2,"0"))}var H=Object.freeze({__proto__:null,NumberToLowerCase:M,NumberToUpperCase:w,addClass:c,arrayCounter:A,cleanObject:m,deepClone:d,deepMerge:h,delClass:l,formatDateString:I,formatDecimal:D,formatNumber:T,getDPI:x,getGlobalLocation:k,hasClass:a,hslDeS:o,hslToRgb:i,isMatched:f,isSameDomain:L,isSameDomainBlob:O,mm2px:S,numToString:v,posInRect:b,pt2px:E,px2mm:$,px2pt:N,removeAllRanges:C,removeNode:y,rgbFadeOut:n,rgbToHex:s,rgbToHsl:r,rgbToNum:t,segmentIntersection:j,throttle:g,toCamelCase:p,toHex:e,toKebabCase:u});let R,G;const K=["top","right","bottom","left"];function P(){return R&&G||(R=document.createElement("canvas"),G=R.getContext("2d")),{canvas:R,ctx:G}}function z(t,e){return t?Array.from(t.querySelectorAll("."+u(e))):[]}function B(t,e){return window.getComputedStyle(t,null).getPropertyValue(e)}var U=Object.freeze({__proto__:null,NumberToLowerCase:M,NumberToUpperCase:w,addClass:c,arrayCounter:A,cleanObject:m,deepClone:d,deepMerge:h,delClass:l,formatDateString:I,formatDecimal:D,formatNumber:T,getCss:B,getCssText:function(t){return Object.entries(t).map(([t,e])=>`${u(t)}: ${e}`).join(";")},getDPI:x,getElementByClassName:function(t,e){return z(t,e)[0]},getElementsByClassName:z,getGap:function(t,e){const n=[0,0,0,0];return n.forEach((o,r)=>{const i=+B(t,`${e}-${K[r]}`).replace(/([0-9-.]+)/g,"$1"),s=Number.isNaN(i)?0:i;n[r]=s}),n},getGlobalLocation:k,getStyleFromCssText:function(t){const e={};return t.split(";").forEach(t=>{const[n,o]=t.split(":").map(t=>t.trim());o&&(e[p(n)]=o)}),e},hasClass:a,hslDeS:o,hslToRgb:i,initCanvas:P,isMatched:f,isSameDomain:L,isSameDomainBlob:O,measureText:function(t,e,n){const{ctx:o}=P();return o.font=`${e} ${n}`,Math.round(o.measureText(t).width)},mm2px:S,moveCursorToEnd:function(t){const e=document.createRange();e.selectNodeContents(t),e.collapse(!1);const n=window.getSelection();n&&(n.removeAllRanges(),n.addRange(e))},numToString:v,posInRect:b,pt2px:E,px2mm:$,px2pt:N,removeAllRanges:C,removeNode:y,rgbFadeOut:n,rgbToHex:s,rgbToHsl:r,rgbToNum:t,segmentIntersection:j,throttle:g,toCamelCase:p,toHex:e,toKebabCase:u});const q={backspace:8,tab:9,enter:13,numpadenter:13,capslock:20,escape:27,esc:27,space:32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,digit0:48,digit1:49,digit2:50,digit3:51,digit4:52,digit5:53,digit6:54,digit7:55,digit8:56,digit9:57,keya:65,keyb:66,keyc:67,keyd:68,keye:69,keyf:70,keyg:71,keyh:72,keyi:73,keyj:74,keyk:75,keyl:76,keym:77,keyn:78,keyo:79,keyp:80,keyq:81,keyr:82,keys:83,keyt:84,keyu:85,keyv:86,keyw:87,keyx:88,keyy:89,keyz:90,metaleft:91,metaright:92,contextmenu:93,numpad0:96,numpad1:97,numpad2:98,numpad3:99,numpad4:100,numpad5:101,numpad6:102,numpad7:103,numpad8:104,numpad9:105,numpadmultiply:106,numpadadd:107,numpadsubtract:109,numpaddecimal:110,numpaddivide:111,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,numlock:144,semicolon:186,equal:187,comma:188,minus:189,period:190,slash:191,backquote:192,bracketleft:219,backslash:220,bracketright:221,quote:222};class F{event;watch;stop;active;keyEvent={name:"event name",shortcut:"event shortcut",repeat:!1,disabled:!1,before:()=>!0,callback:()=>{}};constructor(t=!1){this.event=new Map,this.watch=new Map,this.stop=!1,this.active=!1,t||this.init()}init(){window.addEventListener("keydown",t=>this.dispatcher(t))}getCode(t){let e=t.toLowerCase();const n=e.split("+").pop();let o,r;return n&&(e=n),r=/^[a-z]$/.test(e)?`key${e}`:/^\d$/.test(e)?`digit${e}`:/^(left|right|up|down)$/.test(e)?`arrow${e}`:e,o=q[r]||+e,o}has(t){const e=`${t}`;return!!this.event.has(e)||(console.warn(`Name Error: no such name of "${e}" in BindKey Events, need of registry before using.`),!1)}register(t,e){const n="function"==typeof e?e:function(){},o={shortcut:"default",repeat:!1,callback:n};"object"==typeof e&&(o.shortcut=e.shortcut||"default",o.repeat=e.repeat||!1,o.callback=e.callback||n);const r="function"==typeof e?"default":this.getCode(o.shortcut);!this.watch.has(r)&&this.watch.set(r,[]),this.watch.get(r).push(t),this.remove(t),this.event.set(t,{name:t,disabled:!1,...o})}remove(t){if(!this.has(t))return;const e=this.getCode(this.event.get(t).shortcut),n=this.watch.get(e);for(let e=0,o=n.length;e<o;e++)if(n[e]===t){n.splice(e,1);break}this.event.delete(t)}on(t){this.has(t)&&this.event.get(t).callback()}dispatcher(t){if(this.stop)return!1;if(!t.isTrusted)return!1;const{ctrlKey:e,shiftKey:n,altKey:o,metaKey:r,code:i,repeat:s}=t,a=this.getCode(i),c=(t,i)=>{const c=t.toLowerCase().split("+"),l=c.pop()||"",u=c.includes("ctrl")?e:!e,p=c.includes("shift")?n:!n,f=c.includes("alt")?o:!o,h=c.includes("meta")?r:!r;let d=+l;return Number.isNaN(d)&&(d=this.getCode(l)),a===d&&(!(s&&!i)&&(!!u&&(!!p&&(!!f&&!!h))))},l=(t,e)=>!!this.active||(this.active=!0,setTimeout(()=>{this.active=!1},60),!!t.callback(e,t)),u=[...this.watch.get(a)||[]];for(;u.length>0;){const e=u.pop(),n=this.event.get(e);if(n&&(("function"!=typeof n.before||!n.before())&&c(n.shortcut,n.repeat))){if(!1===l(n,t)||!n.disabled)return t.preventDefault(),!1;n.disabled=!1}}}}const W=window||{},Y=document||{};class V{callback;listener;limit=0;delay=0;constructor(t,e,n){this.callback=t,this.limit=e||0,this.delay=n||0,this.init()}throttle(t){return this.limit=t,this.init(),this}debounce(t){return this.delay=t,this.init(),this}init(){const{limit:t,delay:e,callback:n}=this;if(!t&&!e)return void(this.listener=(...t)=>n(...t));let o=0,r=0;this.listener=function(...i){const s=Date.now();s-r>=t&&(n(...i),r=s),e&&(clearTimeout(o),o=setTimeout(()=>{n(...i),r=Date.now()},e))}}}if("undefined"!=typeof window&&"object"==typeof window.__CirnoGlobalEventMap__){for(const[t,e]of Object.entries(window.__CirnoGlobalEventMap__)){for(const n of e)document.removeEventListener(t,n);delete window.__CirnoGlobalEventMap__[t]}delete window.__CirnoGlobalEventMap__}class X{static name="CirnoHelperEventManager";static eventMap=new WeakMap;static globalEventMap={};static Global=W;static Document=Y;static{window.__CirnoGlobalEventMap__||(window.__CirnoGlobalEventMap__={}),this.globalEventMap=window.__CirnoGlobalEventMap__}static addEvent(t,e,n,o){const r=t,i={throttle:0,debounce:0,...o||{}};r.nodeType===Node.DOCUMENT_NODE&&(e in this.globalEventMap||(this.globalEventMap[e]=[]),this.globalEventMap[e].push(n)),this.eventMap.has(r)||this.eventMap.set(r,{});const s=this.eventMap.get(r);if(e in s||(s[e]=[]),i.throttle||i.debounce){for(const t of s[e])if(t instanceof V&&t.callback===n)return;const t=new V(n,i.throttle,i.debounce);return s[e].push(t),void r.addEventListener(e,t.listener)}s[e].includes(n)||(s[e].push(n),r.addEventListener(e,n))}static delEvent(t,e,n){const o=t;if(!this.eventMap.has(o))return;const r=this.eventMap.get(o);if(!(e in r))return;const i=r[e];for(const t of i)if(t instanceof V){if("function"==typeof n&&t.callback!==n)continue;o.removeEventListener(e,t.listener)}else{if("function"==typeof n&&t!==n)continue;o.removeEventListener(e,t)}delete r[e],0===Object.keys(r).length&&this.eventMap.delete(o)}}var Z=Object.freeze({__proto__:null,BindKey:F,DomHelper:U,EventManager:X,Helper:H});exports.BindKey=F,exports.DomHelper=U,exports.EventManager=X,exports.Helper=H,exports.default=Z;
|
|
1
|
+
"use strict";function e(e){return e.split(",").map(e=>+e.replace(/\D/g,""))}function t(e){return e<0&&(e=4294967295+e+1),e.toString(16).toUpperCase()}function n(t,n){const o="string"==typeof t?e(t):t;if(n<=0||!Number.isInteger(n))throw new Error("Invalid number of steps");const r=1/n;let i=[...o];for(let e=0;e<n;e++)i=[Math.max(0,i[0]*(1-r)),Math.max(0,i[1]*(1-r)),Math.max(0,i[2]*(1-r))];return"string"==typeof t?`rgb(${i.join(", ")})`:i}function o(t,n){const o="string"==typeof t?e(t):t,[r,i,s]=o;return"string"==typeof t?`hsl(${r}, ${i*n}%, ${s}%)`:[r,i*n/100,s/100]}function r(t){const n="string"==typeof t?e(t):t,[o,r,i]=n,s=(e=0,t=3)=>Math.floor(e*10**t)/10**t,[a,c,l]=[o/255,r/255,i/255],[u,f]=[Math.max(a,c,l),Math.min(a,c,l)],p=u-f;let d=0;0===p?d=0:u===a?d=(c-l)/p%6*60:u===c?d=60*((l-a)/p+2):u===l&&(d=60*((a-c)/p+4)),d=Math.floor(((e,t)=>{let n=e%t;return n<0&&(n+=t),n})(d,360));const h=s((u+f)/2),m=0===p?0:s(p/(1-Math.abs(2*h-1))),g=Math.round(d),b=Math.round(100*m)/100,y=Math.round(100*h)/100;return"string"==typeof t?`hsl(${g}, ${100*b}%, ${100*y}%)`:[g,b,y]}function i(t){const n="string"==typeof t?e(t):t;let[o,r,i]=n;r>1&&(r/=100),i>1&&(i/=100);const s=(1-Math.abs(2*i-1))*r,a=s*(1-Math.abs(o/60%2-1)),c=i-s/2,l=[];o>=360&&(o=0),o>=0&&o<60?l.push(s,a,0):o>=60&&o<120?l.push(a,s,0):o>=120&&o<180?l.push(0,s,a):o>=180&&o<240?l.push(0,a,s):o>=240&&o<300?l.push(a,0,s):o>=300&&o<360&&l.push(s,0,a);const[u,f,p]=l,d=Math.round(Math.abs(255*(u+c)))||0,h=Math.round(Math.abs(255*(f+c)))||0,m=Math.round(Math.abs(255*(p+c)))||0;return"string"==typeof t?`rgb(${d}, ${h}, ${m})`:[d,h,m]}function s(n){const o="string"==typeof n?e(n):n,[r,i,s]=o;return`#${t(r)}${t(i)}${t(s)}`}function a(e,t){if(!e)return!1;const n=u(t),o=e.className||"";return new Set(o.split(" ").filter(e=>!!e)).has(n)}function c(e,t){if(!e)return;const n=u(t),o=e.className||"",r=new Set(o.split(" ").filter(e=>!!e));r.add(n),e.className=Array.from(r).join(" ")}function l(e,t){if(!e)return;const n=u(t),o=e.className||"",r=new Set(o.split(" ").filter(e=>!!e));r.delete(n),e.className=Array.from(r).join(" ")}function u(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`).replace(/^-/,"").replace(/[-]{1,}/,"-").toLowerCase()}function f(e){return e.replace(/-([a-z])/g,e=>e.slice(1,2).toUpperCase())}function p(e,t){let n=!0;for(const[o,r]of t){if(o in e){n=e[o]===r}else n=!1;if(!n)break}return n}function d(e,t){const n=Array.isArray(e)?[...e]:{...e};for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&("object"==typeof t[e]&&null!==t[e]?Array.isArray(t[e])?n[e]=d(n[e]||[],t[e]):n[e]=d(n[e]||{},t[e]):n[e]=t[e]);return n}function h(e){return Array.isArray(e)?d([],e):d({},e)}function m(e){const t={};for(const[n,o]of Object.entries(e))"string"!=typeof o&&"number"!=typeof o||"string"==typeof o&&""===o.trim()||(t[n]=o);return t}function g(e,t,n){let o=0;return function(...r){o||(o=setTimeout(()=>{t.apply(e,r),o=0},n))}}function b(e,t,n){return e>=n.left&&e<=n.right&&t>=n.top&&t<=n.bottom}function y(e){e.parentNode?.removeChild(e)}function v(e){const t="A".charCodeAt(0),n="Z".charCodeAt(0)-t+1;let o="";for(;e>=0;)o=String.fromCharCode(e%n+t)+o,e=Math.floor(e/n)-1;return o}function w(e){if(0===e)return"零";const t=["","万","亿","万亿"],n=["零","一","二","三","四","五","六","七","八","九"],o=["千","百","十",""],r=e.toString(),i=[];for(let e=r.length;e>0;e-=4)i.push(r.substring(Math.max(0,e-4),e));if(i.reverse(),i.length>t.length)throw new Error("数字太大,超过万亿级别");let s="",a=!1;for(let e=0;e<i.length;e++){const r=i[e].padStart(4,"0");let c="",l=!1,u=!1;for(let e=0;e<4;e++){const t=parseInt(r[e],10);0!==t?(l&&u&&(c+="零",u=!1),c+=n[t]+o[e],l=!0):l&&(u=!0)}c&&(a&&(s+="零"),s+=c+t[i.length-1-e],a=!0)}return s.startsWith("一十")&&(s="十"+s.substring(2)),s}function M(e){const t={"零":0,"一":1,"二":2,"三":3,"四":4,"五":5,"六":6,"七":7,"八":8,"九":9},n={"十":10,"百":100,"千":1e3,"万":1e4,"亿":1e8};let o=0,r=0,i=0,s=0;for(let a=0;a<e.length;a++){const c=e[a];if(c in t)i=t[c],a===e.length-1&&(r+=i);else if(c in n){const e=n[c];if(e>=1e4){r+=i,i=0;s>e?o+=r*e:o=(o+r)*e,r=0,s=e}else 0===i&&(i=1),r+=i*e,i=0}}return o+r}function C(){window.getSelection()?.removeAllRanges()}function k(){return window.location}Object.defineProperty(exports,"__esModule",{value:!0});const _=[];function x(){if(_.length>0)return _;if("deviceXDPI"in window.screen&&"deviceYDPI"in window.screen)_.push(window.screen.deviceXDPI),_.push(window.screen.deviceYDPI);else{const e=document.createElement("DIV");e.style.cssText="width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden",document.body.appendChild(e),_.push(e.offsetWidth),_.push(e.offsetHeight),e.parentNode?.removeChild(e)}return _}function E(e,t=0){if("number"!=typeof e){e=+`${e}`.replace("pt","")}return Math.floor(e*(x()[0]/72)*10**t)/10**t}function N(e,t=2){return e=e/x()[0]*25.4,e/=.367,Math.round(e*10**t)/10**t}function $(e,t=2){return e=e/x()[0]*25.4,Math.round(e*10**t)/10**t}function T(e,t=!1){const n=e/25.4*x()[0];return t?n:Math.floor(n)}function S(e,t){if(!e)return"";let n=!1,o=0,r="";for(const i of e)"."!==i?(n?o+=1:r+=i,n&&o<=t&&(r+=i)):(n=!0,t>0&&(r+=i));!n&&t>0&&(r+=".");for(let e=o;e<t;e+=1)r+="0";return r}function D(e,t=3){const n=Math.floor(e).toString(),o=Math.max(t,n.length);return Array.from({length:o-n.length}).map(()=>"0").join("")+n}function j(e,t){const[n,o]=e[0]<=e[1]?e:[e[1],e[0]],[r,i]=t[0]<=t[1]?t:[t[1],t[0]],s=Math.max(n,r),a=Math.min(o,i);return s>a?null:[s,a]}function A(e,t=0,n){return 0===e.length?0:(void 0===n&&(n=e.length),t===n?0:1===e.length?e[0]:e.slice(t,n).reduce((e,t)=>e+t))}function L(e){console.log({url:e});try{const t=new URL(e),n=k();return"data:"===t.protocol||("blob:"===t.protocol||t.protocol===n.protocol&&t.hostname===n.hostname)}catch(e){return console.error(e),!1}}function O(e){const t=new URL(e);if("blob:"!==t.protocol)return!1;const n=k();return t.origin===n.origin}function H(e,t){const n=e.getFullYear(),o=e.getMonth()+1,r=e.getDate();return t.replace("yyyy",n.toString()).replace("mm",o.toString().padStart(2,"0")).replace("dd",r.toString().padStart(2,"0"))}var I=Object.freeze({__proto__:null,NumberToLowerCase:M,NumberToUpperCase:w,addClass:c,arrayCounter:A,cleanObject:m,deepClone:h,deepMerge:d,delClass:l,formatDateString:H,formatDecimal:S,formatNumber:D,getDPI:x,getGlobalLocation:k,hasClass:a,hslDeS:o,hslToRgb:i,isMatched:p,isSameDomain:L,isSameDomainBlob:O,mm2px:T,numToString:v,posInRect:b,pt2px:E,px2mm:$,px2pt:N,removeAllRanges:C,removeNode:y,rgbFadeOut:n,rgbToHex:s,rgbToHsl:r,rgbToNum:e,segmentIntersection:j,throttle:g,toCamelCase:f,toHex:t,toKebabCase:u});let R,G;const K=["top","right","bottom","left"];function P(){return R&&G||(R=document.createElement("canvas"),G=R.getContext("2d")),{canvas:R,ctx:G}}function z(e,t){return e?Array.from(e.querySelectorAll("."+u(t))):[]}function B(e,t){return window.getComputedStyle(e,null).getPropertyValue(t)}var U=Object.freeze({__proto__:null,NumberToLowerCase:M,NumberToUpperCase:w,addClass:c,arrayCounter:A,cleanObject:m,deepClone:h,deepMerge:d,delClass:l,formatDateString:H,formatDecimal:S,formatNumber:D,getCss:B,getCssText:function(e){return Object.entries(e).map(([e,t])=>`${u(e)}: ${t}`).join(";")},getDPI:x,getElementByClassName:function(e,t){return z(e,t)[0]},getElementsByClassName:z,getGap:function(e,t){const n=[0,0,0,0];return n.forEach((o,r)=>{const i=+B(e,`${t}-${K[r]}`).replace(/([0-9-.]+)/g,"$1"),s=Number.isNaN(i)?0:i;n[r]=s}),n},getGlobalLocation:k,getStyleFromCssText:function(e){const t={};return e.split(";").forEach(e=>{const[n,o]=e.split(":").map(e=>e.trim());o&&(t[f(n)]=o)}),t},hasClass:a,hslDeS:o,hslToRgb:i,initCanvas:P,isMatched:p,isSameDomain:L,isSameDomainBlob:O,measureText:function(e,t,n){const{ctx:o}=P();return o.font=`${t} ${n}`,Math.round(o.measureText(e).width)},mm2px:T,moveCursorToEnd:function(e){const t=document.createRange();t.selectNodeContents(e),t.collapse(!1);const n=window.getSelection();n&&(n.removeAllRanges(),n.addRange(t))},numToString:v,posInRect:b,pt2px:E,px2mm:$,px2pt:N,removeAllRanges:C,removeNode:y,rgbFadeOut:n,rgbToHex:s,rgbToHsl:r,rgbToNum:e,segmentIntersection:j,throttle:g,toCamelCase:f,toHex:t,toKebabCase:u});const q={backspace:8,tab:9,enter:13,numpadenter:13,capslock:20,escape:27,esc:27,space:32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,digit0:48,digit1:49,digit2:50,digit3:51,digit4:52,digit5:53,digit6:54,digit7:55,digit8:56,digit9:57,keya:65,keyb:66,keyc:67,keyd:68,keye:69,keyf:70,keyg:71,keyh:72,keyi:73,keyj:74,keyk:75,keyl:76,keym:77,keyn:78,keyo:79,keyp:80,keyq:81,keyr:82,keys:83,keyt:84,keyu:85,keyv:86,keyw:87,keyx:88,keyy:89,keyz:90,metaleft:91,metaright:92,contextmenu:93,numpad0:96,numpad1:97,numpad2:98,numpad3:99,numpad4:100,numpad5:101,numpad6:102,numpad7:103,numpad8:104,numpad9:105,numpadmultiply:106,numpadadd:107,numpadsubtract:109,numpaddecimal:110,numpaddivide:111,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,numlock:144,semicolon:186,equal:187,comma:188,minus:189,period:190,slash:191,backquote:192,bracketleft:219,backslash:220,bracketright:221,quote:222};class F{event;watch;stop;active;keyEvent={name:"event name",shortcut:"event shortcut",repeat:!1,disabled:!1,before:()=>!0,callback:()=>{}};constructor(e=!1){this.event=new Map,this.watch=new Map,this.stop=!1,this.active=!1,e||this.init()}init(){window.addEventListener("keydown",e=>this.dispatcher(e))}getCode(e){let t=e.toLowerCase();const n=t.split("+").pop();let o,r;return n&&(t=n),r=/^[a-z]$/.test(t)?`key${t}`:/^\d$/.test(t)?`digit${t}`:/^(left|right|up|down)$/.test(t)?`arrow${t}`:t,o=q[r]||+t,o}has(e){const t=`${e}`;return!!this.event.has(t)||(console.warn(`Name Error: no such name of "${t}" in BindKey Events, need of registry before using.`),!1)}register(e,t){const n="function"==typeof t?t:function(){},o={shortcut:"default",repeat:!1,callback:n};"object"==typeof t&&(o.shortcut=t.shortcut||"default",o.repeat=t.repeat||!1,o.callback=t.callback||n);const r="function"==typeof t?"default":this.getCode(o.shortcut);!this.watch.has(r)&&this.watch.set(r,[]),this.watch.get(r).push(e),this.remove(e),this.event.set(e,{name:e,disabled:!1,...o})}remove(e){if(!this.has(e))return;const t=this.getCode(this.event.get(e).shortcut),n=this.watch.get(t);for(let t=0,o=n.length;t<o;t++)if(n[t]===e){n.splice(t,1);break}this.event.delete(e)}on(e){this.has(e)&&this.event.get(e).callback()}dispatcher(e){if(this.stop)return!1;if(!e.isTrusted)return!1;const{ctrlKey:t,shiftKey:n,altKey:o,metaKey:r,code:i,repeat:s}=e,a=this.getCode(i),c=(e,i)=>{const c=e.toLowerCase().split("+"),l=c.pop()||"",u=c.includes("ctrl")?t:!t,f=c.includes("shift")?n:!n,p=c.includes("alt")?o:!o,d=c.includes("meta")?r:!r;let h=+l;return Number.isNaN(h)&&(h=this.getCode(l)),a===h&&(!(s&&!i)&&(!!u&&(!!f&&(!!p&&!!d))))},l=(e,t)=>!!this.active||(this.active=!0,setTimeout(()=>{this.active=!1},60),!!e.callback(t,e)),u=[...this.watch.get(a)||[]];for(;u.length>0;){const t=u.pop(),n=this.event.get(t);if(n&&(("function"!=typeof n.before||!n.before())&&c(n.shortcut,n.repeat))){if(!1===l(n,e)||!n.disabled)return e.preventDefault(),!1;n.disabled=!1}}}}const W="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof globalThis?globalThis:{},Y="undefined"!=typeof document?document:{};class V{callback;listener;limit=0;delay=0;constructor(e,t,n){this.callback=e,this.limit=t||0,this.delay=n||0,this.init()}throttle(e){return this.limit=e,this.init(),this}debounce(e){return this.delay=e,this.init(),this}init(){const{limit:e,delay:t,callback:n}=this;if(!e&&!t)return void(this.listener=(...e)=>n(...e));let o=0,r=0;this.listener=function(...i){const s=Date.now();s-r>=e&&(n(...i),r=s),t&&(clearTimeout(o),o=setTimeout(()=>{n(...i),r=Date.now()},t))}}}if("undefined"!=typeof window&&"object"==typeof window.__CirnoGlobalEventMap__){for(const[e,t]of Object.entries(window.__CirnoGlobalEventMap__)){for(const n of t)document.removeEventListener(e,n);delete window.__CirnoGlobalEventMap__[e]}delete window.__CirnoGlobalEventMap__}class X{static name="CirnoHelperEventManager";static eventMap=new WeakMap;static globalEventMap={};static Global=W;static Document=Y;static{window.__CirnoGlobalEventMap__||(window.__CirnoGlobalEventMap__={}),this.globalEventMap=window.__CirnoGlobalEventMap__}static addEvent(e,t,n,o){const r=e,i={throttle:0,debounce:0,...o||{}};r.nodeType===Node.DOCUMENT_NODE&&(t in this.globalEventMap||(this.globalEventMap[t]=[]),this.globalEventMap[t].push(n)),this.eventMap.has(r)||this.eventMap.set(r,{});const s=this.eventMap.get(r);if(t in s||(s[t]=[]),i.throttle||i.debounce){for(const e of s[t])if(e instanceof V&&e.callback===n)return;const e=new V(n,i.throttle,i.debounce);return s[t].push(e),void r.addEventListener(t,e.listener)}s[t].includes(n)||(s[t].push(n),r.addEventListener(t,n))}static delEvent(e,t,n){const o=e;if(!this.eventMap.has(o))return;const r=this.eventMap.get(o);if(!(t in r))return;const i=r[t];for(const e of i)if(e instanceof V){if("function"==typeof n&&e.callback!==n)continue;o.removeEventListener(t,e.listener)}else{if("function"==typeof n&&e!==n)continue;o.removeEventListener(t,e)}delete r[t],0===Object.keys(r).length&&this.eventMap.delete(o)}}function Z(){}var J={Helper2:I,asd:123},Q=Object.freeze({__proto__:null,BindKey:F,DomHelper:U,EventManager:X,Helper:I,Helper2:I,aaa:"",asd:Z,asdf:I,default:J});exports.BindKey=F,exports.DomHelper=U,exports.EventManager=X,exports.Helper=I,exports.Helper2=I,exports.aaa="",exports.asd=Z,exports.asdf=I,exports.default=Q;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const e="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof globalThis?globalThis:{},n="undefined"!=typeof document?document:{},o="CirnoHelper";export{n as DocumentIntance,o as EventManagerName,e as GlobalIntance};
|
package/dist/esm/exports.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"./lib/core/helper.js";
|
|
1
|
+
import*as e from"./lib/core/helper.js";import*as r from"./lib/core/dom-helper.js";export{r as DomHelper};export{BindKey}from"./lib/bindkey.js";export{EventManager}from"./lib/eventManager.js";function o(){}const a="";var s={Helper2:e,asd:123};export{e as Helper,e as Helper2,a as aaa,o as asd,e as asdf,s as default};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"./exports.js";export{BindKey}from"./lib/bindkey.js";import*as r from"./lib/core/dom-helper.js";export{r as DomHelper};export{EventManager}from"./lib/eventManager.js";import*as o from"./lib/core/helper.js";export{o as Helper};export{e as default};
|
|
1
|
+
import*as e from"./exports.js";export{aaa,asd}from"./exports.js";export{BindKey}from"./lib/bindkey.js";import*as r from"./lib/core/dom-helper.js";export{r as DomHelper};export{EventManager}from"./lib/eventManager.js";import*as o from"./lib/core/helper.js";export{o as Helper};export{o as Helper2};export{o as asdf};export{e as default};
|
package/dist/index.d.ts
CHANGED
|
@@ -172,80 +172,80 @@ declare function isSameDomain(url: string): boolean;
|
|
|
172
172
|
declare function isSameDomainBlob(url: string): boolean;
|
|
173
173
|
declare function formatDateString(date: Date, format: string): string;
|
|
174
174
|
|
|
175
|
-
declare const
|
|
176
|
-
declare const
|
|
177
|
-
declare const
|
|
178
|
-
declare const
|
|
179
|
-
declare const
|
|
180
|
-
declare const
|
|
181
|
-
declare const
|
|
182
|
-
declare const
|
|
183
|
-
declare const
|
|
184
|
-
declare const
|
|
185
|
-
declare const
|
|
186
|
-
declare const
|
|
187
|
-
declare const
|
|
188
|
-
declare const
|
|
189
|
-
declare const
|
|
190
|
-
declare const
|
|
191
|
-
declare const
|
|
192
|
-
declare const
|
|
193
|
-
declare const
|
|
194
|
-
declare const
|
|
195
|
-
declare const
|
|
196
|
-
declare const
|
|
197
|
-
declare const
|
|
198
|
-
declare const
|
|
199
|
-
declare const
|
|
200
|
-
declare const
|
|
201
|
-
declare const
|
|
202
|
-
declare const
|
|
203
|
-
declare const
|
|
204
|
-
declare const
|
|
205
|
-
declare const
|
|
206
|
-
declare const
|
|
207
|
-
declare const
|
|
208
|
-
declare const
|
|
209
|
-
declare const
|
|
210
|
-
declare const
|
|
211
|
-
declare namespace
|
|
175
|
+
declare const Helper2_NumberToLowerCase: typeof NumberToLowerCase;
|
|
176
|
+
declare const Helper2_NumberToUpperCase: typeof NumberToUpperCase;
|
|
177
|
+
declare const Helper2_addClass: typeof addClass;
|
|
178
|
+
declare const Helper2_arrayCounter: typeof arrayCounter;
|
|
179
|
+
declare const Helper2_cleanObject: typeof cleanObject;
|
|
180
|
+
declare const Helper2_deepClone: typeof deepClone;
|
|
181
|
+
declare const Helper2_deepMerge: typeof deepMerge;
|
|
182
|
+
declare const Helper2_delClass: typeof delClass;
|
|
183
|
+
declare const Helper2_formatDateString: typeof formatDateString;
|
|
184
|
+
declare const Helper2_formatDecimal: typeof formatDecimal;
|
|
185
|
+
declare const Helper2_formatNumber: typeof formatNumber;
|
|
186
|
+
declare const Helper2_getDPI: typeof getDPI;
|
|
187
|
+
declare const Helper2_getGlobalLocation: typeof getGlobalLocation;
|
|
188
|
+
declare const Helper2_hasClass: typeof hasClass;
|
|
189
|
+
declare const Helper2_hslDeS: typeof hslDeS;
|
|
190
|
+
declare const Helper2_hslToRgb: typeof hslToRgb;
|
|
191
|
+
declare const Helper2_isMatched: typeof isMatched;
|
|
192
|
+
declare const Helper2_isSameDomain: typeof isSameDomain;
|
|
193
|
+
declare const Helper2_isSameDomainBlob: typeof isSameDomainBlob;
|
|
194
|
+
declare const Helper2_mm2px: typeof mm2px;
|
|
195
|
+
declare const Helper2_numToString: typeof numToString;
|
|
196
|
+
declare const Helper2_posInRect: typeof posInRect;
|
|
197
|
+
declare const Helper2_pt2px: typeof pt2px;
|
|
198
|
+
declare const Helper2_px2mm: typeof px2mm;
|
|
199
|
+
declare const Helper2_px2pt: typeof px2pt;
|
|
200
|
+
declare const Helper2_removeAllRanges: typeof removeAllRanges;
|
|
201
|
+
declare const Helper2_removeNode: typeof removeNode;
|
|
202
|
+
declare const Helper2_rgbFadeOut: typeof rgbFadeOut;
|
|
203
|
+
declare const Helper2_rgbToHex: typeof rgbToHex;
|
|
204
|
+
declare const Helper2_rgbToHsl: typeof rgbToHsl;
|
|
205
|
+
declare const Helper2_rgbToNum: typeof rgbToNum;
|
|
206
|
+
declare const Helper2_segmentIntersection: typeof segmentIntersection;
|
|
207
|
+
declare const Helper2_throttle: typeof throttle;
|
|
208
|
+
declare const Helper2_toCamelCase: typeof toCamelCase;
|
|
209
|
+
declare const Helper2_toHex: typeof toHex;
|
|
210
|
+
declare const Helper2_toKebabCase: typeof toKebabCase;
|
|
211
|
+
declare namespace Helper2 {
|
|
212
212
|
export {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
213
|
+
Helper2_NumberToLowerCase as NumberToLowerCase,
|
|
214
|
+
Helper2_NumberToUpperCase as NumberToUpperCase,
|
|
215
|
+
Helper2_addClass as addClass,
|
|
216
|
+
Helper2_arrayCounter as arrayCounter,
|
|
217
|
+
Helper2_cleanObject as cleanObject,
|
|
218
|
+
Helper2_deepClone as deepClone,
|
|
219
|
+
Helper2_deepMerge as deepMerge,
|
|
220
|
+
Helper2_delClass as delClass,
|
|
221
|
+
Helper2_formatDateString as formatDateString,
|
|
222
|
+
Helper2_formatDecimal as formatDecimal,
|
|
223
|
+
Helper2_formatNumber as formatNumber,
|
|
224
|
+
Helper2_getDPI as getDPI,
|
|
225
|
+
Helper2_getGlobalLocation as getGlobalLocation,
|
|
226
|
+
Helper2_hasClass as hasClass,
|
|
227
|
+
Helper2_hslDeS as hslDeS,
|
|
228
|
+
Helper2_hslToRgb as hslToRgb,
|
|
229
|
+
Helper2_isMatched as isMatched,
|
|
230
|
+
Helper2_isSameDomain as isSameDomain,
|
|
231
|
+
Helper2_isSameDomainBlob as isSameDomainBlob,
|
|
232
|
+
Helper2_mm2px as mm2px,
|
|
233
|
+
Helper2_numToString as numToString,
|
|
234
|
+
Helper2_posInRect as posInRect,
|
|
235
|
+
Helper2_pt2px as pt2px,
|
|
236
|
+
Helper2_px2mm as px2mm,
|
|
237
|
+
Helper2_px2pt as px2pt,
|
|
238
|
+
Helper2_removeAllRanges as removeAllRanges,
|
|
239
|
+
Helper2_removeNode as removeNode,
|
|
240
|
+
Helper2_rgbFadeOut as rgbFadeOut,
|
|
241
|
+
Helper2_rgbToHex as rgbToHex,
|
|
242
|
+
Helper2_rgbToHsl as rgbToHsl,
|
|
243
|
+
Helper2_rgbToNum as rgbToNum,
|
|
244
|
+
Helper2_segmentIntersection as segmentIntersection,
|
|
245
|
+
Helper2_throttle as throttle,
|
|
246
|
+
Helper2_toCamelCase as toCamelCase,
|
|
247
|
+
Helper2_toHex as toHex,
|
|
248
|
+
Helper2_toKebabCase as toKebabCase,
|
|
249
249
|
};
|
|
250
250
|
}
|
|
251
251
|
|
|
@@ -361,16 +361,27 @@ declare namespace domHelper {
|
|
|
361
361
|
};
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
declare function asd(): void;
|
|
365
|
+
declare const aaa = "";
|
|
366
|
+
|
|
367
|
+
declare const _default: {
|
|
368
|
+
Helper2: typeof Helper2;
|
|
369
|
+
asd: number;
|
|
370
|
+
};
|
|
371
|
+
|
|
364
372
|
type KAUtil_BindKey = BindKey;
|
|
365
373
|
declare const KAUtil_BindKey: typeof BindKey;
|
|
366
374
|
type KAUtil_BindKeyEvent = BindKeyEvent;
|
|
367
375
|
type KAUtil_EventConfig = EventConfig;
|
|
368
376
|
type KAUtil_EventManager = EventManager;
|
|
369
377
|
declare const KAUtil_EventManager: typeof EventManager;
|
|
378
|
+
declare const KAUtil_Helper2: typeof Helper2;
|
|
379
|
+
declare const KAUtil_aaa: typeof aaa;
|
|
380
|
+
declare const KAUtil_asd: typeof asd;
|
|
370
381
|
declare namespace KAUtil {
|
|
371
|
-
export { KAUtil_BindKey as BindKey, domHelper as DomHelper, KAUtil_EventManager as EventManager,
|
|
382
|
+
export { KAUtil_BindKey as BindKey, domHelper as DomHelper, KAUtil_EventManager as EventManager, Helper2 as Helper, KAUtil_Helper2 as Helper2, KAUtil_aaa as aaa, KAUtil_asd as asd, Helper2 as asdf, _default as default };
|
|
372
383
|
export type { KAUtil_BindKeyEvent as BindKeyEvent, KAUtil_EventConfig as EventConfig };
|
|
373
384
|
}
|
|
374
385
|
|
|
375
|
-
export { BindKey, domHelper as DomHelper, EventManager,
|
|
386
|
+
export { BindKey, domHelper as DomHelper, EventManager, Helper2 as Helper, Helper2, aaa, asd, Helper2 as asdf, KAUtil as default };
|
|
376
387
|
export type { BindKeyEvent, EventConfig };
|