@ka-libs/utils 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kuzuki Azusa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,229 @@
1
+ # KAUtil
2
+
3
+ A lightweight TypeScript utility library for frontend development, providing keyboard shortcuts, event management, DOM utilities, color conversion, and general\-purpose helpers\.
4
+
5
+ ---
6
+
7
+ ## โœจ Features
8
+
9
+ - โŒจ๏ธ Keyboard shortcut manager \(`BindKey`\)
10
+
11
+ - โšก Throttle \& debounce event system
12
+
13
+ - ๐ŸŒ DOM \& HTML utilities
14
+
15
+ - ๐ŸŽจ RGB / HSL / HEX color conversion
16
+
17
+ - ๐Ÿง  Deep clone, deep merge, object utilities
18
+
19
+ - ๐Ÿ“ Unit conversion \(px / pt / mm\)
20
+
21
+ - ๐Ÿงฉ Class \& DOM manipulation helpers
22
+
23
+ - ๐Ÿงต String utilities
24
+
25
+ - ๐Ÿ–ฅ Canvas \& rendering helpers
26
+
27
+ - ๐Ÿ“ฆ Fully TypeScript supported
28
+
29
+ ---
30
+
31
+ ## ๐Ÿ“ฆ Installation
32
+
33
+ ```bash
34
+ npm install ka-util
35
+
36
+ # or
37
+ yarn add ka-util
38
+ ```
39
+
40
+ ---
41
+
42
+ ## ๐Ÿš€ Usage
43
+
44
+ ```typescript
45
+ import KAUtil from "ka-util";
46
+
47
+ const { BindKey, EventManager, Helper, RenderHTMLHelper } = KAUtil;
48
+ ```
49
+
50
+ ### โŒจ๏ธ BindKey
51
+
52
+ Keyboard shortcut manager\.
53
+
54
+ #### Example
55
+
56
+ ```typescript
57
+ const keyboard = new BindKey();
58
+
59
+ keyboard.register("save", {
60
+ shortcut: "ctrl+s",
61
+ callback: () => {
62
+ console.log("save triggered");
63
+ }
64
+ });
65
+ ```
66
+
67
+ #### API
68
+
69
+ ```typescript
70
+ register(name: string, opt: BindKeyOpt): void;
71
+ register(name: string, callback: Function): void;
72
+ remove(name: string): void;
73
+ on(name: string): void;
74
+ has(name: string): boolean;
75
+ ```
76
+
77
+ ### โšก FrequencyEvent
78
+
79
+ Throttle \& debounce utility\.
80
+
81
+ #### Example
82
+
83
+ ```typescript
84
+ const handler = new FrequencyEvent(() => {
85
+ console.log("resize");
86
+ }).throttle(200);
87
+
88
+ const inputHandler = new FrequencyEvent(() => {
89
+ console.log("input");
90
+ }).debounce(300);
91
+ ```
92
+
93
+ ### ๐ŸŒ EventManager
94
+
95
+ Unified DOM event system with throttle/debounce support\.
96
+
97
+ #### Example
98
+
99
+ ```typescript
100
+ EventManager.addEvent(window, "resize", () => {
101
+ console.log("resize");
102
+ }, {
103
+ debounce: 200
104
+ });
105
+ ```
106
+
107
+ #### API
108
+
109
+ ```typescript
110
+ addEvent(element, type, listener, config?)
111
+ delEvent(element, type, listener?)
112
+ ```
113
+
114
+ ### ๐Ÿงฐ Helper Utilities
115
+
116
+ #### Object
117
+
118
+ ```typescript
119
+ deepClone(obj);
120
+ deepMerge(target, source);
121
+ cleanObject(obj);
122
+ ```
123
+
124
+ #### String
125
+
126
+ ```typescript
127
+ toCamelCase(str);
128
+ toKebabCase(str);
129
+ numToString(num);
130
+ formatNumber(num);
131
+ ```
132
+
133
+ #### Array
134
+
135
+ ```typescript
136
+ arrayCounter(arr, start?, end?);
137
+ isMatched(item, arr);
138
+ ```
139
+
140
+ #### Math / Number
141
+
142
+ ```typescript
143
+ NumberToUpperCase(num);
144
+ NumberToLowerCase(str);
145
+ segmentIntersection(seg1, seg2);
146
+ ```
147
+
148
+ ### ๐ŸŽจ Color Utilities
149
+
150
+ ```typescript
151
+ rgbToNum("rgb(255,255,255)");
152
+ rgbToHex([255, 255, 255]);
153
+ rgbToHsl([255, 255, 255]);
154
+ hslToRgb([0, 0, 100]);
155
+ rgbFadeOut([255, 0, 0], 5);
156
+ toHex(255);
157
+ ```
158
+
159
+ ### ๐Ÿ“ Unit Conversion
160
+
161
+ ```typescript
162
+ pt2px(12);
163
+ px2pt(16);
164
+ px2mm(10);
165
+ mm2px(10);
166
+ getDPI();
167
+ ```
168
+
169
+ ### ๐Ÿงฉ DOM Utilities
170
+
171
+ ```typescript
172
+ addClass(el, "active");
173
+ delClass(el, "hidden");
174
+ hasClass(el, "box");
175
+ removeNode(el);
176
+ posInRect(x, y, rect);
177
+ ```
178
+
179
+ ### ๐ŸŒ HTML / Render Helper
180
+
181
+ ```typescript
182
+ initCanvas();
183
+
184
+ getCss(el, "width");
185
+ getCssText(style);
186
+ getStyleFromCssText(cssText);
187
+
188
+ measureText("hello", "16px", "Arial");
189
+ moveCursorToEnd(input);
190
+ ```
191
+
192
+ ### ๐Ÿง  Global Helper Namespace
193
+
194
+ ```typescript
195
+ KAUtil.Helper.deepClone({});
196
+ KAUtil.Helper.deepMerge({}, {});
197
+ KAUtil.RenderHTMLHelper.getCss(el, "width");
198
+ KAUtil.EventManager.addEvent(window, "click", () => {});
199
+ ```
200
+
201
+ ## ๐Ÿ“ฆ Export
202
+
203
+ ```typescript
204
+ export {
205
+ BindKey,
206
+ EventManager,
207
+ helper,
208
+ htmlHelper,
209
+ KAUtil as default
210
+ };
211
+ ```
212
+
213
+ ## ๐Ÿงช TypeScript Support
214
+
215
+ Fully typed with:
216
+
217
+ - Strong DOM typings
218
+
219
+ - Overloaded APIs
220
+
221
+ - Event config support \(throttle / debounce\)
222
+
223
+ - Namespace exports
224
+
225
+ ## ๐Ÿ“„ License
226
+
227
+ MIT
228
+
229
+ > ๏ผˆๆณจ๏ผš้ƒจๅˆ†ๅ†…ๅฎนๅฏ่ƒฝ็”ฑ AI ็”Ÿๆˆ๏ผ‰
@@ -0,0 +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;
@@ -0,0 +1 @@
1
+ const e={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};export{e as KeyMap};
@@ -0,0 +1 @@
1
+ const o=window||{},e=document||{},n="CirnoHelper";export{e as DocumentIntance,n as EventManagerName,o as GlobalIntance};
@@ -0,0 +1 @@
1
+ import*as e from"./lib/core/helper.js";export{e as Helper};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";
@@ -0,0 +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};
@@ -0,0 +1 @@
1
+ import{KeyMap as t}from"../config/KeyMap.js";class e{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(e){let s=e.toLowerCase();const i=s.split("+").pop();let o,a;return i&&(s=i),a=/^[a-z]$/.test(s)?`key${s}`:/^\d$/.test(s)?`digit${s}`:/^(left|right|up|down)$/.test(s)?`arrow${s}`:s,o=t[a]||+s,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 s="function"==typeof e?e:function(){},i={shortcut:"default",repeat:!1,callback:s};"object"==typeof e&&(i.shortcut=e.shortcut||"default",i.repeat=e.repeat||!1,i.callback=e.callback||s);const o="function"==typeof e?"default":this.getCode(i.shortcut);!this.watch.has(o)&&this.watch.set(o,[]),this.watch.get(o).push(t),this.remove(t),this.event.set(t,{name:t,disabled:!1,...i})}remove(t){if(!this.has(t))return;const e=this.getCode(this.event.get(t).shortcut),s=this.watch.get(e);for(let e=0,i=s.length;e<i;e++)if(s[e]===t){s.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:s,altKey:i,metaKey:o,code:a,repeat:n}=t,r=this.getCode(a),c=(t,a)=>{const c=t.toLowerCase().split("+"),h=c.pop()||"",l=c.includes("ctrl")?e:!e,u=c.includes("shift")?s:!s,d=c.includes("alt")?i:!i,p=c.includes("meta")?o:!o;let f=+h;return Number.isNaN(f)&&(f=this.getCode(h)),r===f&&(!(n&&!a)&&(!!l&&(!!u&&(!!d&&!!p))))},h=(t,e)=>!!this.active||(this.active=!0,setTimeout(()=>{this.active=!1},60),!!t.callback(e,t)),l=[...this.watch.get(r)||[]];for(;l.length>0;){const e=l.pop(),s=this.event.get(e);if(s&&(("function"!=typeof s.before||!s.before())&&c(s.shortcut,s.repeat))){if(!1===h(s,t)||!s.disabled)return t.preventDefault(),!1;s.disabled=!1}}}}export{e as BindKey};
@@ -0,0 +1 @@
1
+ import{toKebabCase as e,toCamelCase as t}from"./helper.js";export{NumberToLowerCase,NumberToUpperCase,addClass,arrayCounter,cleanObject,deepClone,deepMerge,delClass,formatDateString,formatDecimal,formatNumber,getDPI,getGlobalLocation,hasClass,hslDeS,hslToRgb,isMatched,isSameDomain,isSameDomainBlob,mm2px,numToString,posInRect,pt2px,px2mm,px2pt,removeAllRanges,removeNode,rgbFadeOut,rgbToHex,rgbToHsl,rgbToNum,segmentIntersection,throttle,toHex}from"./helper.js";let o,n;const r=["top","right","bottom","left"];function a(){return o&&n||(o=document.createElement("canvas"),n=o.getContext("2d")),{canvas:o,ctx:n}}function c(t,o){return t?Array.from(t.querySelectorAll("."+e(o))):[]}function s(e,t){return c(e,t)[0]}function l(e,t){return window.getComputedStyle(e,null).getPropertyValue(t)}function m(t){return Object.entries(t).map(([t,o])=>`${e(t)}: ${o}`).join(";")}function u(e){const o={};return e.split(";").forEach(e=>{const[n,r]=e.split(":").map(e=>e.trim());r&&(o[t(n)]=r)}),o}function i(e,t){const o=[0,0,0,0];return o.forEach((n,a)=>{const c=+l(e,`${t}-${r[a]}`).replace(/([0-9-.]+)/g,"$1"),s=Number.isNaN(c)?0:c;o[a]=s}),o}function p(e,t,o){const{ctx:n}=a();return n.font=`${t} ${o}`,Math.round(n.measureText(e).width)}function g(e){const t=document.createRange();t.selectNodeContents(e),t.collapse(!1);const o=window.getSelection();o&&(o.removeAllRanges(),o.addRange(t))}export{l as getCss,m as getCssText,s as getElementByClassName,c as getElementsByClassName,i as getGap,u as getStyleFromCssText,a as initCanvas,p as measureText,g as moveCursorToEnd,t as toCamelCase,e as toKebabCase};
@@ -0,0 +1 @@
1
+ function t(t){return t.split(",").map(t=>+t.replace(/\D/g,""))}function n(t){return t<0&&(t=4294967295+t+1),t.toString(16).toUpperCase()}function e(n,e){const r="string"==typeof n?t(n):n;if(e<=0||!Number.isInteger(e))throw new Error("Invalid number of steps");const o=1/e;let i=[...r];for(let t=0;t<e;t++)i=[Math.max(0,i[0]*(1-o)),Math.max(0,i[1]*(1-o)),Math.max(0,i[2]*(1-o))];return"string"==typeof n?`rgb(${i.join(", ")})`:i}function r(n,e){const r="string"==typeof n?t(n):n,[o,i,s]=r;return"string"==typeof n?`hsl(${o}, ${i*e}%, ${s}%)`:[o,i*e/100,s/100]}function o(n){const e="string"==typeof n?t(n):n,[r,o,i]=e,s=(t=0,n=3)=>Math.floor(t*10**n)/10**n,[c,u,a]=[r/255,o/255,i/255],[f,l]=[Math.max(c,u,a),Math.min(c,u,a)],h=f-l;let p=0;0===h?p=0:f===c?p=(u-a)/h%6*60:f===u?p=60*((a-c)/h+2):f===a&&(p=60*((c-u)/h+4)),p=Math.floor(((t,n)=>{let e=t%n;return e<0&&(e+=n),e})(p,360));const g=s((f+l)/2),d=0===h?0:s(h/(1-Math.abs(2*g-1))),m=Math.round(p),y=Math.round(100*d)/100,M=Math.round(100*g)/100;return"string"==typeof n?`hsl(${m}, ${100*y}%, ${100*M}%)`:[m,y,M]}function i(n){const e="string"==typeof n?t(n):n;let[r,o,i]=e;o>1&&(o/=100),i>1&&(i/=100);const s=(1-Math.abs(2*i-1))*o,c=s*(1-Math.abs(r/60%2-1)),u=i-s/2,a=[];r>=360&&(r=0),r>=0&&r<60?a.push(s,c,0):r>=60&&r<120?a.push(c,s,0):r>=120&&r<180?a.push(0,s,c):r>=180&&r<240?a.push(0,c,s):r>=240&&r<300?a.push(c,0,s):r>=300&&r<360&&a.push(s,0,c);const[f,l,h]=a,p=Math.round(Math.abs(255*(f+u)))||0,g=Math.round(Math.abs(255*(l+u)))||0,d=Math.round(Math.abs(255*(h+u)))||0;return"string"==typeof n?`rgb(${p}, ${g}, ${d})`:[p,g,d]}function s(e){const r="string"==typeof e?t(e):e,[o,i,s]=r;return`#${n(o)}${n(i)}${n(s)}`}function c(t,n){if(!t)return!1;const e=f(n),r=t.className||"";return new Set(r.split(" ").filter(t=>!!t)).has(e)}function u(t,n){if(!t)return;const e=f(n),r=t.className||"",o=new Set(r.split(" ").filter(t=>!!t));o.add(e),t.className=Array.from(o).join(" ")}function a(t,n){if(!t)return;const e=f(n),r=t.className||"",o=new Set(r.split(" ").filter(t=>!!t));o.delete(e),t.className=Array.from(o).join(" ")}function f(t){return t.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`).replace(/^-/,"").replace(/[-]{1,}/,"-").toLowerCase()}function l(t){return t.replace(/-([a-z])/g,t=>t.slice(1,2).toUpperCase())}function h(t,n){let e=!0;for(const[r,o]of n){if(r in t){e=t[r]===o}else e=!1;if(!e)break}return e}function p(t,n){const e=Array.isArray(t)?[...t]:{...t};for(const t in n)Object.prototype.hasOwnProperty.call(n,t)&&("object"==typeof n[t]&&null!==n[t]?Array.isArray(n[t])?e[t]=p(e[t]||[],n[t]):e[t]=p(e[t]||{},n[t]):e[t]=n[t]);return e}function g(t){return Array.isArray(t)?p([],t):p({},t)}function d(t){const n={};for(const[e,r]of Object.entries(t))"string"!=typeof r&&"number"!=typeof r||"string"==typeof r&&""===r.trim()||(n[e]=r);return n}function m(t,n,e){let r=0;return function(...o){r||(r=setTimeout(()=>{n.apply(t,o),r=0},e))}}function y(t,n,e){return t>=e.left&&t<=e.right&&n>=e.top&&n<=e.bottom}function M(t){t.parentNode?.removeChild(t)}function b(t){const n="A".charCodeAt(0),e="Z".charCodeAt(0)-n+1;let r="";for(;t>=0;)r=String.fromCharCode(t%e+n)+r,t=Math.floor(t/e)-1;return r}function w(t){if(0===t)return"้›ถ";const n=["","ไธ‡","ไบฟ","ไธ‡ไบฟ"],e=["้›ถ","ไธ€","ไบŒ","ไธ‰","ๅ››","ไบ”","ๅ…ญ","ไธƒ","ๅ…ซ","ไน"],r=["ๅƒ","็™พ","ๅ",""],o=t.toString(),i=[];for(let t=o.length;t>0;t-=4)i.push(o.substring(Math.max(0,t-4),t));if(i.reverse(),i.length>n.length)throw new Error("ๆ•ฐๅญ—ๅคชๅคง๏ผŒ่ถ…่ฟ‡ไธ‡ไบฟ็บงๅˆซ");let s="",c=!1;for(let t=0;t<i.length;t++){const o=i[t].padStart(4,"0");let u="",a=!1,f=!1;for(let t=0;t<4;t++){const n=parseInt(o[t],10);0!==n?(a&&f&&(u+="้›ถ",f=!1),u+=e[n]+r[t],a=!0):a&&(f=!0)}u&&(c&&(s+="้›ถ"),s+=u+n[i.length-1-t],c=!0)}return s.startsWith("ไธ€ๅ")&&(s="ๅ"+s.substring(2)),s}function $(t){const n={"้›ถ":0,"ไธ€":1,"ไบŒ":2,"ไธ‰":3,"ๅ››":4,"ไบ”":5,"ๅ…ญ":6,"ไธƒ":7,"ๅ…ซ":8,"ไน":9},e={"ๅ":10,"็™พ":100,"ๅƒ":1e3,"ไธ‡":1e4,"ไบฟ":1e8};let r=0,o=0,i=0,s=0;for(let c=0;c<t.length;c++){const u=t[c];if(u in n)i=n[u],c===t.length-1&&(o+=i);else if(u in e){const t=e[u];if(t>=1e4){o+=i,i=0;s>t?r+=o*t:r=(r+o)*t,o=0,s=t}else 0===i&&(i=1),o+=i*t,i=0}}return r+o}function A(){window.getSelection()?.removeAllRanges()}function S(){return window.location}const x=[];function v(){if(x.length>0)return x;if("deviceXDPI"in window.screen&&"deviceYDPI"in window.screen)x.push(window.screen.deviceXDPI),x.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),x.push(t.offsetWidth),x.push(t.offsetHeight),t.parentNode?.removeChild(t)}return x}function C(t,n=0){if("number"!=typeof t){t=+`${t}`.replace("pt","")}return Math.floor(t*(v()[0]/72)*10**n)/10**n}function I(t,n=2){return t=t/v()[0]*25.4,t/=.367,Math.round(t*10**n)/10**n}function N(t,n=2){return t=t/v()[0]*25.4,Math.round(t*10**n)/10**n}function j(t,n=!1){const e=t/25.4*v()[0];return n?e:Math.floor(e)}function D(t,n){if(!t)return"";let e=!1,r=0,o="";for(const i of t)"."!==i?(e?r+=1:o+=i,e&&r<=n&&(o+=i)):(e=!0,n>0&&(o+=i));!e&&n>0&&(o+=".");for(let t=r;t<n;t+=1)o+="0";return o}function P(t,n=3){const e=Math.floor(t).toString(),r=Math.max(n,e.length);return Array.from({length:r-e.length}).map(()=>"0").join("")+e}function L(t,n){const[e,r]=t[0]<=t[1]?t:[t[1],t[0]],[o,i]=n[0]<=n[1]?n:[n[1],n[0]],s=Math.max(e,o),c=Math.min(r,i);return s>c?null:[s,c]}function U(t,n=0,e){return 0===t.length?0:(void 0===e&&(e=t.length),n===e?0:1===t.length?t[0]:t.slice(n,e).reduce((t,n)=>t+n))}function E(t){console.log({url:t});try{const n=new URL(t),e=S();return"data:"===n.protocol||("blob:"===n.protocol||n.protocol===e.protocol&&n.hostname===e.hostname)}catch(t){return console.error(t),!1}}function O(t){const n=new URL(t);if("blob:"!==n.protocol)return!1;const e=S();return n.origin===e.origin}function R(t,n){const e=t.getFullYear(),r=t.getMonth()+1,o=t.getDate();return n.replace("yyyy",e.toString()).replace("mm",r.toString().padStart(2,"0")).replace("dd",o.toString().padStart(2,"0"))}export{$ as NumberToLowerCase,w as NumberToUpperCase,u as addClass,U as arrayCounter,d as cleanObject,g as deepClone,p as deepMerge,a as delClass,R as formatDateString,D as formatDecimal,P as formatNumber,v as getDPI,S as getGlobalLocation,c as hasClass,r as hslDeS,i as hslToRgb,h as isMatched,E as isSameDomain,O as isSameDomainBlob,j as mm2px,b as numToString,y as posInRect,C as pt2px,N as px2mm,I as px2pt,A as removeAllRanges,M as removeNode,e as rgbFadeOut,s as rgbToHex,o as rgbToHsl,t as rgbToNum,L as segmentIntersection,m as throttle,l as toCamelCase,n as toHex,f as toKebabCase};
@@ -0,0 +1 @@
1
+ import{EventManagerName as e,GlobalIntance as t,DocumentIntance as n}from"../config/constants.js";import{FrequencyEvent as o}from"./frequencyEvent.js";const i=!import.meta?.env?.PROD;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 a{static name=e+"EventManager";static eventMap=new WeakMap;static globalEventMap={};static Global=t;static Document=n;static{i&&(window.__CirnoGlobalEventMap__||(window.__CirnoGlobalEventMap__={}),this.globalEventMap=window.__CirnoGlobalEventMap__)}static addEvent(e,t,n,a){const s=e,l={throttle:0,debounce:0,...a||{}};i&&s.nodeType===Node.DOCUMENT_NODE&&(t in this.globalEventMap||(this.globalEventMap[t]=[]),this.globalEventMap[t].push(n)),this.eventMap.has(s)||this.eventMap.set(s,{});const c=this.eventMap.get(s);if(t in c||(c[t]=[]),l.throttle||l.debounce){for(const e of c[t])if(e instanceof o&&e.callback===n)return;const e=new o(n,l.throttle,l.debounce);return c[t].push(e),void s.addEventListener(t,e.listener)}c[t].includes(n)||(c[t].push(n),s.addEventListener(t,n))}static delEvent(e,t,n){const i=e;if(!this.eventMap.has(i))return;const a=this.eventMap.get(i);if(!(t in a))return;const s=a[t];for(const e of s)if(e instanceof o){if("function"==typeof n&&e.callback!==n)continue;i.removeEventListener(t,e.listener)}else{if("function"==typeof n&&e!==n)continue;i.removeEventListener(t,e)}delete a[t],0===Object.keys(a).length&&this.eventMap.delete(i)}}export{a as EventManager};
@@ -0,0 +1 @@
1
+ class t{callback;listener;limit=0;delay=0;constructor(t,i,e){this.callback=t,this.limit=i||0,this.delay=e||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:i,callback:e}=this;if(!t&&!i)return void(this.listener=(...t)=>e(...t));let s=0,l=0;this.listener=function(...n){const a=Date.now();a-l>=t&&(e(...n),l=a),i&&(clearTimeout(s),s=setTimeout(()=>{e(...n),l=Date.now()},i))}}}export{t as FrequencyEvent};
@@ -0,0 +1,376 @@
1
+ interface BindKeyCallBack {
2
+ (...args: any[]): any;
3
+ }
4
+ interface BindKeyOpt {
5
+ shortcut: string;
6
+ repeat?: boolean;
7
+ callback: BindKeyCallBack;
8
+ }
9
+ interface BindKeyEvent extends BindKeyOpt {
10
+ name: string;
11
+ disabled: boolean;
12
+ repeat: boolean;
13
+ before?: () => boolean;
14
+ }
15
+ declare class BindKey {
16
+ event: Map<string, BindKeyEvent>;
17
+ watch: Map<any, any>;
18
+ stop: boolean;
19
+ active: boolean;
20
+ keyEvent: BindKeyEvent;
21
+ constructor(ManualBind?: boolean);
22
+ init(): void;
23
+ getCode(_key: string): number;
24
+ has(_name: string): boolean;
25
+ /**
26
+ * ๆณจๅ†Œไบ‹ไปถ
27
+ * @param {string} name ไบ‹ไปถๅ๏ผŒๅฟ…้กป๏ผŒ็”จไบŽๆ˜ ๅฐ„ไบ‹ไปถ็š„ๅ›ž่ฐƒๅ‡ฝๆ•ฐใ€‚
28
+ * @param {callback} opt ไบ‹ไปถๅฏน่ฑกๆˆ–ๅ›ž่ฐƒๅ‡ฝๆ•ฐ๏ผŒไธบๅฏน่ฑกๆ—ถๅบ”ๅŒ…ๅซๅ‚ๆ•ฐ shortcut ๅ’Œ callbackใ€‚
29
+ */
30
+ register(name: string, opt: BindKeyOpt): void;
31
+ register(name: string, callback: BindKeyCallBack): void;
32
+ /**
33
+ * ๅˆ ้™คไบ‹ไปถ
34
+ * @param {string} name ไบ‹ไปถๅใ€‚
35
+ */
36
+ remove(name: string): void;
37
+ /**
38
+ * ๆ‰ง่กŒไบ‹ไปถ
39
+ * @param {string} name ไบ‹ไปถๅใ€‚
40
+ */
41
+ on(name: string): void;
42
+ dispatcher(event: KeyboardEvent): boolean;
43
+ }
44
+
45
+ /**
46
+ * FrequencyEvent ็ฑป - ็”จไบŽๅฎž็Žฐ่Š‚ๆตๅ’Œ้˜ฒๆŠ–ๅŠŸ่ƒฝ็š„ๅทฅๅ…ท็ฑป
47
+ * ๅฏไปฅๅฏนๅ‡ฝๆ•ฐๆ‰ง่กŒ้ข‘็އ่ฟ›่กŒๆŽงๅˆถ๏ผŒๆ”ฏๆŒ่Š‚ๆต(throttle)ๅ’Œ้˜ฒๆŠ–(debounce)ไธค็งๆจกๅผ
48
+ */
49
+ declare class FrequencyEvent {
50
+ /**
51
+ * ๅŽŸๅง‹ๅ›ž่ฐƒๅ‡ฝๆ•ฐ
52
+ */
53
+ callback: Function;
54
+ /**
55
+ * ๅŒ…่ฃ…ๅŽ็š„็›‘ๅฌๅ™จๅ‡ฝๆ•ฐ๏ผŒๅฐ†ๆ นๆฎ่Š‚ๆตๆˆ–้˜ฒๆŠ–้…็ฝฎๆ‰ง่กŒๅŽŸๅง‹ๅ›ž่ฐƒ
56
+ */
57
+ listener: (...args: any[]) => void;
58
+ /**
59
+ * ่Š‚ๆตๆ—ถ้—ด้™ๅˆถ๏ผŒๅ•ไฝไธบๆฏซ็ง’
60
+ * 0่กจ็คบไธ่ฟ›่กŒ่Š‚ๆต้™ๅˆถ
61
+ */
62
+ private limit;
63
+ /**
64
+ * ้˜ฒๆŠ–ๅปถ่ฟŸๆ—ถ้—ด๏ผŒๅ•ไฝไธบๆฏซ็ง’
65
+ * 0่กจ็คบไธ่ฟ›่กŒ้˜ฒๆŠ–ๅค„็†
66
+ */
67
+ private delay;
68
+ /**
69
+ * ๆž„้€ ๅ‡ฝๆ•ฐ - ๅˆ›ๅปบ FrequencyEvent ๅฎžไพ‹
70
+ * @param callback - ้œ€่ฆๆ‰ง่กŒ้ข‘็އๆŽงๅˆถ็š„ๅŽŸๅง‹ๅ›ž่ฐƒๅ‡ฝๆ•ฐ
71
+ */
72
+ constructor(callback: Function);
73
+ /**
74
+ * ๆž„้€ ๅ‡ฝๆ•ฐ - ๅˆ›ๅปบ FrequencyEvent ๅฎžไพ‹ๅนถ่ฎพ็ฝฎ่Š‚ๆต
75
+ * @param callback - ้œ€่ฆๆ‰ง่กŒ้ข‘็އๆŽงๅˆถ็š„ๅŽŸๅง‹ๅ›ž่ฐƒๅ‡ฝๆ•ฐ
76
+ * @param throttleLimit - ่Š‚ๆตๆ—ถ้—ด้™ๅˆถ๏ผŒๅ•ไฝไธบๆฏซ็ง’
77
+ */
78
+ constructor(callback: Function, throttleLimit: number);
79
+ constructor(callback: Function, throttleLimit: number, debounceDelay: number);
80
+ throttle(limit: number): this;
81
+ /**
82
+ * ้˜ฒๆŠ–ๅ‡ฝๆ•ฐ่ฎพ็ฝฎๆ–นๆณ•
83
+ * @param delay - ้˜ฒๆŠ–ๅปถ่ฟŸๆ—ถ้—ด๏ผŒๅ•ไฝไธบๆฏซ็ง’
84
+ * ่ฎพ็ฝฎ้˜ฒๆŠ–็š„ๅปถ่ฟŸๆ—ถ้—ดๅนถ้‡ๆ–ฐๅˆๅง‹ๅŒ–๏ผŒๆ”ฏๆŒ้“พๅผ่ฐƒ็”จ
85
+ */
86
+ debounce(delay: number): this;
87
+ /**
88
+ * ๅˆๅง‹ๅŒ–ๅ‡ฝๆ•ฐ๏ผŒ็”จไบŽ่ฎพ็ฝฎไบ‹ไปถ็›‘ๅฌๅ™จ
89
+ * ๆ นๆฎlimitๅ’Œdelay็š„ๅ€ผๅ†ณๅฎšๅฆ‚ไฝ•ๅค„็†ๅ›ž่ฐƒๅ‡ฝๆ•ฐ็š„ๆ‰ง่กŒ
90
+ */
91
+ private init;
92
+ }
93
+
94
+ type EventElement = HTMLElement | Document;
95
+ declare global {
96
+ interface Window {
97
+ __CirnoGlobalEventMap__?: {
98
+ [key: string]: Function[];
99
+ };
100
+ }
101
+ }
102
+ interface EventConfig {
103
+ throttle?: number;
104
+ debounce?: number;
105
+ }
106
+ declare class EventManager {
107
+ static name: string;
108
+ static eventMap: WeakMap<EventElement, {
109
+ [key: string]: Array<FrequencyEvent | Function>;
110
+ }>;
111
+ static globalEventMap: {
112
+ [key: string]: Array<FrequencyEvent | Function>;
113
+ };
114
+ static Global: {};
115
+ static Document: {};
116
+ static addEvent(_elem: EventElement, type: keyof HTMLElementEventMap, listener: Function, _config?: EventConfig): void;
117
+ static delEvent(_elem: EventElement, type: keyof HTMLElementEventMap, eventListener?: Function): void;
118
+ }
119
+
120
+ declare function rgbToNum(rgbStr: string): number[];
121
+ declare function toHex(num: number): string;
122
+ declare function rgbFadeOut(rgbStr: string, steps: number): string;
123
+ declare function rgbFadeOut(rgbArray: number[], steps: number): number[];
124
+ declare function hslDeS(hslStr: string, rate: number): string;
125
+ declare function hslDeS(hslArray: number[], rate: number): number[];
126
+ declare function rgbToHsl(rgbStr: string): string;
127
+ declare function rgbToHsl(rgbArray: number[]): number[];
128
+ declare function hslToRgb(hslStr: string): string;
129
+ declare function hslToRgb(hslArray: number[]): number[];
130
+ declare function rgbToHex(rgbStr: string): string;
131
+ declare function rgbToHex(rgbArray: number[]): string;
132
+ declare function hasClass(el: any, name: string): boolean;
133
+ declare function addClass(el: any, name: string): void;
134
+ declare function delClass(el: any, name: string): void;
135
+ declare function toKebabCase(name: string): string;
136
+ declare function toCamelCase(name: string): string;
137
+ declare function isMatched(item: any, optArr: any[]): boolean;
138
+ /** Object ๅค„็† */
139
+ declare function deepMerge(target: any, source: any): any;
140
+ declare function deepClone(source: any): any;
141
+ declare function cleanObject(source: any): any;
142
+ /** ไบ‹ไปถๅค„็† */
143
+ declare function throttle(_this: any, func: any, wait: number): (...args: any) => void;
144
+ declare function posInRect(x: number, y: number, rect: {
145
+ left: number;
146
+ right: number;
147
+ top: number;
148
+ bottom: number;
149
+ }): boolean;
150
+ declare function removeNode(elem: Element): void;
151
+ declare function numToString(num: number): string;
152
+ declare function NumberToUpperCase(num: number): string;
153
+ declare function NumberToLowerCase(chnStr: string): number;
154
+ declare function removeAllRanges(): void;
155
+ declare function getGlobalLocation(): Location;
156
+ declare function getDPI(): number[];
157
+ declare function pt2px(value: number, demi?: number): number;
158
+ declare function px2pt(value: number, decimalSize?: number): number;
159
+ declare function px2mm(value: number, decimalSize?: number): number;
160
+ declare function mm2px(value: number, origin?: boolean): number;
161
+ declare function formatDecimal(decimalText: string, decimalSize: number): string;
162
+ declare function formatNumber(number: number, _size?: number): string;
163
+ /**
164
+ * ่ฎก็ฎ—ไธคๆก็บฟๆฎต็š„ไบค้›†
165
+ * @param {Array} seg1 - ็ฌฌไธ€ๆก็บฟๆฎต [startX, endX]
166
+ * @param {Array} seg2 - ็ฌฌไบŒๆก็บฟๆฎต [startX, endX]
167
+ * @returns {[number, number] | null} ไบค้›†็š„็บฟๆฎต [startX, endX]๏ผŒๅฆ‚ๆžœๆฒกๆœ‰ไบค้›†ๅˆ™่ฟ”ๅ›žnull
168
+ */
169
+ declare function segmentIntersection(seg1: [number, number], seg2: [number, number]): [number, number] | null;
170
+ declare function arrayCounter(arr: number[], start?: number, end?: number): number;
171
+ declare function isSameDomain(url: string): boolean;
172
+ declare function isSameDomainBlob(url: string): boolean;
173
+ declare function formatDateString(date: Date, format: string): string;
174
+
175
+ declare const helper_NumberToLowerCase: typeof NumberToLowerCase;
176
+ declare const helper_NumberToUpperCase: typeof NumberToUpperCase;
177
+ declare const helper_addClass: typeof addClass;
178
+ declare const helper_arrayCounter: typeof arrayCounter;
179
+ declare const helper_cleanObject: typeof cleanObject;
180
+ declare const helper_deepClone: typeof deepClone;
181
+ declare const helper_deepMerge: typeof deepMerge;
182
+ declare const helper_delClass: typeof delClass;
183
+ declare const helper_formatDateString: typeof formatDateString;
184
+ declare const helper_formatDecimal: typeof formatDecimal;
185
+ declare const helper_formatNumber: typeof formatNumber;
186
+ declare const helper_getDPI: typeof getDPI;
187
+ declare const helper_getGlobalLocation: typeof getGlobalLocation;
188
+ declare const helper_hasClass: typeof hasClass;
189
+ declare const helper_hslDeS: typeof hslDeS;
190
+ declare const helper_hslToRgb: typeof hslToRgb;
191
+ declare const helper_isMatched: typeof isMatched;
192
+ declare const helper_isSameDomain: typeof isSameDomain;
193
+ declare const helper_isSameDomainBlob: typeof isSameDomainBlob;
194
+ declare const helper_mm2px: typeof mm2px;
195
+ declare const helper_numToString: typeof numToString;
196
+ declare const helper_posInRect: typeof posInRect;
197
+ declare const helper_pt2px: typeof pt2px;
198
+ declare const helper_px2mm: typeof px2mm;
199
+ declare const helper_px2pt: typeof px2pt;
200
+ declare const helper_removeAllRanges: typeof removeAllRanges;
201
+ declare const helper_removeNode: typeof removeNode;
202
+ declare const helper_rgbFadeOut: typeof rgbFadeOut;
203
+ declare const helper_rgbToHex: typeof rgbToHex;
204
+ declare const helper_rgbToHsl: typeof rgbToHsl;
205
+ declare const helper_rgbToNum: typeof rgbToNum;
206
+ declare const helper_segmentIntersection: typeof segmentIntersection;
207
+ declare const helper_throttle: typeof throttle;
208
+ declare const helper_toCamelCase: typeof toCamelCase;
209
+ declare const helper_toHex: typeof toHex;
210
+ declare const helper_toKebabCase: typeof toKebabCase;
211
+ declare namespace helper {
212
+ export {
213
+ helper_NumberToLowerCase as NumberToLowerCase,
214
+ helper_NumberToUpperCase as NumberToUpperCase,
215
+ helper_addClass as addClass,
216
+ helper_arrayCounter as arrayCounter,
217
+ helper_cleanObject as cleanObject,
218
+ helper_deepClone as deepClone,
219
+ helper_deepMerge as deepMerge,
220
+ helper_delClass as delClass,
221
+ helper_formatDateString as formatDateString,
222
+ helper_formatDecimal as formatDecimal,
223
+ helper_formatNumber as formatNumber,
224
+ helper_getDPI as getDPI,
225
+ helper_getGlobalLocation as getGlobalLocation,
226
+ helper_hasClass as hasClass,
227
+ helper_hslDeS as hslDeS,
228
+ helper_hslToRgb as hslToRgb,
229
+ helper_isMatched as isMatched,
230
+ helper_isSameDomain as isSameDomain,
231
+ helper_isSameDomainBlob as isSameDomainBlob,
232
+ helper_mm2px as mm2px,
233
+ helper_numToString as numToString,
234
+ helper_posInRect as posInRect,
235
+ helper_pt2px as pt2px,
236
+ helper_px2mm as px2mm,
237
+ helper_px2pt as px2pt,
238
+ helper_removeAllRanges as removeAllRanges,
239
+ helper_removeNode as removeNode,
240
+ helper_rgbFadeOut as rgbFadeOut,
241
+ helper_rgbToHex as rgbToHex,
242
+ helper_rgbToHsl as rgbToHsl,
243
+ helper_rgbToNum as rgbToNum,
244
+ helper_segmentIntersection as segmentIntersection,
245
+ helper_throttle as throttle,
246
+ helper_toCamelCase as toCamelCase,
247
+ helper_toHex as toHex,
248
+ helper_toKebabCase as toKebabCase,
249
+ };
250
+ }
251
+
252
+ declare function initCanvas(): {
253
+ canvas: HTMLCanvasElement;
254
+ ctx: CanvasRenderingContext2D;
255
+ };
256
+ declare function getElementsByClassName(el: HTMLElement | null, className: string): HTMLElement[];
257
+ declare function getElementByClassName(el: HTMLElement | null, className: string): HTMLElement;
258
+ declare function getCss(dom: Element, attr: string): string;
259
+ declare function getCssText(style: {
260
+ [key: string]: string;
261
+ }): string;
262
+ declare function getStyleFromCssText(cssText: string): {
263
+ [key: string]: string;
264
+ };
265
+ declare function getGap(elem: Element, attr: string): number[];
266
+ declare function measureText(str: string, fontSize: string, fontFamily: string): number;
267
+ declare function moveCursorToEnd(elem: HTMLElement | HTMLInputElement | HTMLTextAreaElement): void;
268
+
269
+ declare const domHelper_NumberToLowerCase: typeof NumberToLowerCase;
270
+ declare const domHelper_NumberToUpperCase: typeof NumberToUpperCase;
271
+ declare const domHelper_addClass: typeof addClass;
272
+ declare const domHelper_arrayCounter: typeof arrayCounter;
273
+ declare const domHelper_cleanObject: typeof cleanObject;
274
+ declare const domHelper_deepClone: typeof deepClone;
275
+ declare const domHelper_deepMerge: typeof deepMerge;
276
+ declare const domHelper_delClass: typeof delClass;
277
+ declare const domHelper_formatDateString: typeof formatDateString;
278
+ declare const domHelper_formatDecimal: typeof formatDecimal;
279
+ declare const domHelper_formatNumber: typeof formatNumber;
280
+ declare const domHelper_getCss: typeof getCss;
281
+ declare const domHelper_getCssText: typeof getCssText;
282
+ declare const domHelper_getDPI: typeof getDPI;
283
+ declare const domHelper_getElementByClassName: typeof getElementByClassName;
284
+ declare const domHelper_getElementsByClassName: typeof getElementsByClassName;
285
+ declare const domHelper_getGap: typeof getGap;
286
+ declare const domHelper_getGlobalLocation: typeof getGlobalLocation;
287
+ declare const domHelper_getStyleFromCssText: typeof getStyleFromCssText;
288
+ declare const domHelper_hasClass: typeof hasClass;
289
+ declare const domHelper_hslDeS: typeof hslDeS;
290
+ declare const domHelper_hslToRgb: typeof hslToRgb;
291
+ declare const domHelper_initCanvas: typeof initCanvas;
292
+ declare const domHelper_isMatched: typeof isMatched;
293
+ declare const domHelper_isSameDomain: typeof isSameDomain;
294
+ declare const domHelper_isSameDomainBlob: typeof isSameDomainBlob;
295
+ declare const domHelper_measureText: typeof measureText;
296
+ declare const domHelper_mm2px: typeof mm2px;
297
+ declare const domHelper_moveCursorToEnd: typeof moveCursorToEnd;
298
+ declare const domHelper_numToString: typeof numToString;
299
+ declare const domHelper_posInRect: typeof posInRect;
300
+ declare const domHelper_pt2px: typeof pt2px;
301
+ declare const domHelper_px2mm: typeof px2mm;
302
+ declare const domHelper_px2pt: typeof px2pt;
303
+ declare const domHelper_removeAllRanges: typeof removeAllRanges;
304
+ declare const domHelper_removeNode: typeof removeNode;
305
+ declare const domHelper_rgbFadeOut: typeof rgbFadeOut;
306
+ declare const domHelper_rgbToHex: typeof rgbToHex;
307
+ declare const domHelper_rgbToHsl: typeof rgbToHsl;
308
+ declare const domHelper_rgbToNum: typeof rgbToNum;
309
+ declare const domHelper_segmentIntersection: typeof segmentIntersection;
310
+ declare const domHelper_throttle: typeof throttle;
311
+ declare const domHelper_toCamelCase: typeof toCamelCase;
312
+ declare const domHelper_toHex: typeof toHex;
313
+ declare const domHelper_toKebabCase: typeof toKebabCase;
314
+ declare namespace domHelper {
315
+ export {
316
+ domHelper_NumberToLowerCase as NumberToLowerCase,
317
+ domHelper_NumberToUpperCase as NumberToUpperCase,
318
+ domHelper_addClass as addClass,
319
+ domHelper_arrayCounter as arrayCounter,
320
+ domHelper_cleanObject as cleanObject,
321
+ domHelper_deepClone as deepClone,
322
+ domHelper_deepMerge as deepMerge,
323
+ domHelper_delClass as delClass,
324
+ domHelper_formatDateString as formatDateString,
325
+ domHelper_formatDecimal as formatDecimal,
326
+ domHelper_formatNumber as formatNumber,
327
+ domHelper_getCss as getCss,
328
+ domHelper_getCssText as getCssText,
329
+ domHelper_getDPI as getDPI,
330
+ domHelper_getElementByClassName as getElementByClassName,
331
+ domHelper_getElementsByClassName as getElementsByClassName,
332
+ domHelper_getGap as getGap,
333
+ domHelper_getGlobalLocation as getGlobalLocation,
334
+ domHelper_getStyleFromCssText as getStyleFromCssText,
335
+ domHelper_hasClass as hasClass,
336
+ domHelper_hslDeS as hslDeS,
337
+ domHelper_hslToRgb as hslToRgb,
338
+ domHelper_initCanvas as initCanvas,
339
+ domHelper_isMatched as isMatched,
340
+ domHelper_isSameDomain as isSameDomain,
341
+ domHelper_isSameDomainBlob as isSameDomainBlob,
342
+ domHelper_measureText as measureText,
343
+ domHelper_mm2px as mm2px,
344
+ domHelper_moveCursorToEnd as moveCursorToEnd,
345
+ domHelper_numToString as numToString,
346
+ domHelper_posInRect as posInRect,
347
+ domHelper_pt2px as pt2px,
348
+ domHelper_px2mm as px2mm,
349
+ domHelper_px2pt as px2pt,
350
+ domHelper_removeAllRanges as removeAllRanges,
351
+ domHelper_removeNode as removeNode,
352
+ domHelper_rgbFadeOut as rgbFadeOut,
353
+ domHelper_rgbToHex as rgbToHex,
354
+ domHelper_rgbToHsl as rgbToHsl,
355
+ domHelper_rgbToNum as rgbToNum,
356
+ domHelper_segmentIntersection as segmentIntersection,
357
+ domHelper_throttle as throttle,
358
+ domHelper_toCamelCase as toCamelCase,
359
+ domHelper_toHex as toHex,
360
+ domHelper_toKebabCase as toKebabCase,
361
+ };
362
+ }
363
+
364
+ type KAUtil_BindKey = BindKey;
365
+ declare const KAUtil_BindKey: typeof BindKey;
366
+ type KAUtil_BindKeyEvent = BindKeyEvent;
367
+ type KAUtil_EventConfig = EventConfig;
368
+ type KAUtil_EventManager = EventManager;
369
+ declare const KAUtil_EventManager: typeof EventManager;
370
+ declare namespace KAUtil {
371
+ export { KAUtil_BindKey as BindKey, domHelper as DomHelper, KAUtil_EventManager as EventManager, helper as Helper };
372
+ export type { KAUtil_BindKeyEvent as BindKeyEvent, KAUtil_EventConfig as EventConfig };
373
+ }
374
+
375
+ export { BindKey, domHelper as DomHelper, EventManager, helper as Helper, KAUtil as default };
376
+ export type { BindKeyEvent, EventConfig };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@ka-libs/utils",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "import": "./dist/esm/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "sideEffects": false,
22
+ "directories": {
23
+ "lib": "lib"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "test": "echo \"Error: no test specified\" && exit 1"
30
+ },
31
+ "author": "Kuzuki Azusa",
32
+ "license": "MIT"
33
+ }