@minsize/utils 0.3.1 → 0.3.2

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/index.d.ts CHANGED
@@ -327,7 +327,7 @@ declare class DataKeeper<VALUE extends unknown> {
327
327
  }
328
328
 
329
329
  interface UrlRule {
330
- hosts: string[];
330
+ hosts: (string | RegExp)[];
331
331
  paths?: (string | RegExp)[];
332
332
  hash?: (string | RegExp)[];
333
333
  allowedParams?: string[];
@@ -392,6 +392,7 @@ declare class UrlSecurityManager {
392
392
  private ruleMatches;
393
393
  /**
394
394
  * Проверяет соответствие хоста URL правилу
395
+ * Поддерживает как строки, так и регулярные выражения
395
396
  *
396
397
  * @param rule - Правило для проверки
397
398
  * @param url - URL для проверки
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";const e=(e,t)=>t[e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2];function t(e,t,r){if(!r){const e=new Date;r=e.getDate()*e.getFullYear()*(e.getHours()??1)*e.getMilliseconds()}const n=function(e){const t=2**32;let r=e;return function(){var e;return r=(1664525*r+1013904223)%t,e=r,e^=e>>>21,r=(e^=e<<35)^e>>>4,(r>>>0)/t}}(r);return function(e,t,r){if(t>r)throw new Error("Минимальная граница не может быть больше максимальной.");return Math.floor(e()*(r-t+1))+t}(n,e,t)}function r(e,t){var r=Object.prototype.toString.call(e).replace("[object ","").replace("]","").toLowerCase();try{"number"===r?isNaN(e)&&(r="nan"):e instanceof Buffer&&(r="buffer")}catch{}return void 0!==t?r===t:r}const n=(e,t)=>{switch(r(e)){case"array":if(!function(e,t,r){if(!s(e,t,"array",r))return!1;if(e.length!==t.length)return!1;for(var o=0;o<e.length;o++)if(!n(e[o],t[o]))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"object":if(!function(e,t,r){if(!s(e,t,"object",r))return!1;const o=Object.keys(e),i=Object.keys(t);if(o.length!==i.length)return!1;for(var a of o){if(!t.hasOwnProperty(a))return!1;if(!n(e[a],t[a]))return!1}return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"function":if(!function(e,t,r){return!!s(e,t,"function",r)&&e===t}(e,t,{skipCheckPrev:!0}))return!1;break;case"date":if(!function(e,t,r){return!!s(e,t,"date",r)&&e.getTime()===t.getTime()}(e,t,{skipCheckPrev:!0}))return!1;break;case"map":if(!function(e,t,r){if(!s(e,t,"map",r))return!1;if(e.size!==t.size)return!1;for(const[r,s]of e)if(!n(s,t.get(r)))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"set":if(!function(e,t,r){if(!s(e,t,"set",r))return!1;if(e.size!==t.size)return!1;const o=Array.from(e.keys()),i=Array.from(t.keys());for(var a=0;a<o.length;a++)if(!n(o[a],i[a]))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;default:if(e!==t)return!1}return!0};function s(e,t,n,s){return!(!s?.skipCheckPrev&&!r(e,n)||!r(t,n))}const o=e=>{switch(r(e)){case"array":return i(e);case"object":return a(e);case"number":return Number(String(e));case"string":return String(e);case"bigint":return BigInt(String(e));case"map":return new Map(e);case"set":return new Set(e);default:return e}},i=e=>{const t=[];for(const r of e)t.push(o(r));return t},a=e=>{const t={};for(const r in e)t[r]=o(e[r]);return t},c=new RegExp(/(?:https?:\/\/)?(?:www\.)?([А-Яа-яa-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.(?:ru|com|org|net|me|su|рф|biz|info|co|uk|de|fr|jp|cn|es|it|ca|au|nl|se|no|dk|fi|pl|at|ch|be|cz|ie|pt|ro|hu|gr|sk|bg|hr|si|lt|lv|ee|is|mt|lu|li|mc|sm|va|ad|al|ba|mk|me|rs|tr|ua|by|kz|uz|am|ge|az|tm|kg|tj|md|kg|tj|af|dz|bh|eg|iq|ir|jo|kw|lb|ly|ma|om|ps|qa|sa|sd|sy|tn|ae|ye|ar|bo|br|cl|co|ec|gf|gy|pe|py|sr|uy|ve|ag|ai|aw|bb|bm|bs|bz|ca|cr|cu|dm|do|gd|gp|gt|hn|ht|jm|kn|ky|lc|ms|mx|ni|pa|pr|sv|tc|tt|vc|vg|vi|an|aq|as|fj|fm|gu|hm|id|ki|mh|mp|nc|nf|nr|nu|pf|pg|pw|sb|tk|to|tv|vu|wf|ws)(?:\/[a-zA-Z0-9._~:\/?#[\]@!$&'()*+,;=-]*)?)(?:\s)/),u=new RegExp(/(?:https?:\/\/)(?:www\.)?([А-Яа-яa-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.(?:ru|com|org|net|me|su|рф|biz|info|co|uk|de|fr|jp|cn|es|it|ca|au|nl|se|no|dk|fi|pl|at|ch|be|cz|ie|pt|ro|hu|gr|sk|bg|hr|si|lt|lv|ee|is|mt|lu|li|mc|sm|va|ad|al|ba|mk|me|rs|tr|ua|by|kz|uz|am|ge|az|tm|kg|tj|md|kg|tj|af|dz|bh|eg|iq|ir|jo|kw|lb|ly|ma|om|ps|qa|sa|sd|sy|tn|ae|ye|ar|bo|br|cl|co|ec|gf|gy|pe|py|sr|uy|ve|ag|ai|aw|bb|bm|bs|bz|ca|cr|cu|dm|do|gd|gp|gt|hn|ht|jm|kn|ky|lc|ms|mx|ni|pa|pr|sv|tc|tt|vc|vg|vi|an|aq|as|fj|fm|gu|hm|id|ki|mh|mp|nc|nf|nr|nu|pf|pg|pw|sb|tk|to|tv|vu|wf|ws)(?:\/[a-zA-Z0-9._~:\/?#[\]@!$&'()*+,;=-]*)?)(?:\s)/),h=e=>e;function l(e){return Array.from(new Set(e))}function f(e,t){switch(r(e)){case"object":return function(e,t){const r={},n=Object.keys(e),s=Object.keys(t),o=l([...n,...s]);for(const n of o)r[n]=f(e[n],t[n]);return r}(e,t);case"array":return function(e,t){const r=[];for(var n=0;n<e.length;n++)r.push(f(e?.[n],t?.[n]));for(n=e.length;n<t.length;n++)r.push(f(e?.[n],t?.[n]));return r}(e,t);default:return e??t}}function p(e,t){switch(r(e)){case"object":return function(e,t){const r={};var n=!1;for(const s in t)if(e.hasOwnProperty(s)){const o=p(e?.[s],t?.[s]);void 0!==o&&(r[s]=o,n=!0)}else r[s]=t[s],n=!0;for(const s in e)s in t||(r[s]=void 0,n=!0);return n?r:void 0}(e,t);case"array":return function(e,t){const r=[];for(var n=!1,s=0;s<e.length;s++){const o=p(e?.[s],t?.[s]);void 0===o&&void 0!==t?.[s]||(r[s]=o,n=!0)}for(s=0;s<t.length;s++){const o=p(e?.[s],t?.[s]);void 0!==o&&(r[s]=o,n=!0)}return n?r:void 0}(e,t);default:if(e!==t)return t}}function g(e,t){return t.split(".").reduce(((e,t)=>e?e[t]:void 0),e)}const d=e=>{const t=e.toString(16);return 1==t.length?"0"+t:t};var m=Object.defineProperty,b=(e,t,r)=>(((e,t,r)=>{t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);var y=Object.defineProperty,k=(e,t,r)=>(((e,t,r)=>{t in e?y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);var v=Object.defineProperty,w=(e,t,r)=>(((e,t,r)=>{t in e?v(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);var x=Object.defineProperty,j=(e,t,r)=>(((e,t,r)=>{t in e?x(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r),$=(e=>(e[e.ALLOW=1]="ALLOW",e[e.DENY=2]="DENY",e))($||{});exports.DataKeeper=class{constructor(e){w(this,"initValue"),w(this,"currentValue"),this.initValue=o(e),this.currentValue=e}setter(e){this.currentValue=e(this.currentValue)}reset(e){this.initValue=o(e),this.currentValue=e}isModified(){return!n(this.initValue,this.currentValue)}get updateValues(){return p(this.initValue,this.currentValue)}},exports.DebouncedFunction=class{constructor(e,t){k(this,"cb"),k(this,"o"),k(this,"tId",null),k(this,"s"),this.cb=e,this.o=t,this.s=[]}execute(...e){if(this.cancel(),"[object Function]"===Object.prototype.toString.call(e[0]))this.s=e[0](...this.s);else for(let t=0;t<this.cb.length;t++)this.s[t]=e[t];this.tId=setTimeout(this.executeImmediately.bind(this),this.o.delay)}executeImmediately(){this.cancel(),this.cb(...this.s),this.s=[]}cancel(){this.tId&&(clearTimeout(this.tId),this.tId=null)}},exports.EventEmitter=class{constructor(){b(this,"e",{})}on(e,t){return this.e[e]||(this.e[e]=[]),this.e[e].push(t),()=>this.off(e,t)}off(e,t){if(!this.e[e])return;const r=this.e[e].findIndex((e=>e===t));-1!==r&&(this.e[e].splice(r,1),0===this.e[e].length&&delete this.e[e])}emit(e,...t){if(!this.e[e])return;const r=this.e[e].slice();for(const n of r)try{n(...t)}catch(t){console.error(`Ошибка в обработчике события ${e}:`,t)}}once(e,t){const r=(...n)=>{this.off(e,r),t(...n)};return this.on(e,r)}clear(e){e?delete this.e[e]:this.e={}}},exports.HEXtoRGB=e=>{if(3===(e=e.replace("#","")).length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)return[0,0,0];const t=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),n=parseInt(e.substring(4,6),16);return isNaN(t)||isNaN(r)||isNaN(n)||t<0||t>255||r<0||r>255||n<0||n>255?[0,0,0]:[t,r,n]},exports.HSVtoRGB=(e,t,r)=>{var n,s,o,i,a,c,u,h;switch(c=r*(1-t),u=r*(1-(a=6*e-(i=Math.floor(6*e)))*t),h=r*(1-(1-a)*t),i%6){case 0:n=r,s=h,o=c;break;case 1:n=u,s=r,o=c;break;case 2:n=c,s=r,o=h;break;case 3:n=c,s=u,o=r;break;case 4:n=h,s=c,o=r;break;case 5:n=r,s=c,o=u}return[Math.round(255*n),Math.round(255*s),Math.round(255*o)]},exports.RGBtoHEX=(e,t,r)=>"#"+d(e)+d(t)+d(r),exports.RGBtoHSV=(e,t,r)=>{var n=Math.max(e,t,r),s=Math.min(e,t,r),o=n-s,i=0,a=0===n?0:o/n,c=n/255;switch(n){case s:i=0;break;case e:i=t-r+o*(t<r?6:0),i/=6*o;break;case t:i=r-e+2*o,i/=6*o;break;case r:i=e-t+4*o,i/=6*o}return[i,a,c]},exports.UrlAction=$,exports.UrlSecurityManager=class{constructor(e=[],t=!0){j(this,"rules"),j(this,"cache"),j(this,"cacheEnabled"),this.rules=[...e].sort(((e,t)=>(e.priority||50)-(t.priority||50))),this.cache=new Map,this.cacheEnabled=t,this.validateConfig()}isAllowed(e){try{const t="string"==typeof e?new URL(e):e;if(this.isObfuscatedUrl(t))return!1;const r=this.getCacheKey(t);if(this.cacheEnabled&&this.cache.has(r))return this.cache.get(r);const n=this.evaluateRules(t);return this.cacheEnabled&&this.cache.set(r,n),this.logAccess(t,n),n}catch(t){return console.error("Invalid URL:",e,t),!1}}evaluateRules(e){let t=null,r=null;for(const n of this.rules)this.ruleMatches(e,n)&&(null===t&&(t=1===n.action,r=n.id||null),console.debug(`Rule "${n.id}" matched for ${e.href}`));return null===t?(console.warn(`No rules matched for ${e.href}, defaulting to deny`),!1):(console.debug(`Final decision for ${e.href}: ${t} (rule: ${r})`),t)}ruleMatches(e,t){return this.checkHost(t,e)&&this.checkPaths(t,e)&&this.checkHash(t,e)&&this.checkParams(t,e)}checkHost(e,t){return!!e.hosts.includes("*")||e.hosts.some((e=>t.host===e||t.host.endsWith("."+e)))}checkPaths(e,t){return!e.paths||0===e.paths.length||e.paths.some((e=>"string"==typeof e?t.pathname===e||t.pathname.startsWith(e+"/"):e.test(t.pathname)))}checkHash(e,t){if(!e.hash||0===e.hash.length)return!0;const r=t.hash;return e.hash.some((e=>"string"==typeof e?r===e:e.test(r)))}checkParams(e,t){if(!e.allowedParams&&!e.ignoreParams)return!0;const r=new URL(t.toString());if(e.ignoreParams&&e.ignoreParams.forEach((e=>{r.searchParams.delete(e)})),e.allowedParams&&r.searchParams.size>0)for(const[t]of r.searchParams)if(!e.allowedParams.includes(t))return!1;return!0}isObfuscatedUrl(e){return[/@/,/\\/,/^\d+\.\d+\.\d+\.\d+$/,/\[.*\]/,/localhost/].some((t=>t.test(e.hostname)||t.test(e.href)))}getCacheKey(e){const t=new URL(e.toString());return t.searchParams.sort(),`${t.host}${t.pathname}${t.search}${t.hash}`}logAccess(e,t){console[t?"info":"warn"](`URL ${t?"allowed":"blocked"}: ${e.href}`)}validateConfig(){const e=[];this.rules.forEach(((t,r)=>{t.hosts&&Array.isArray(t.hosts)&&0!==t.hosts.length||e.push(`Rule ${r}: missing or invalid 'hosts' array`),void 0!==t.priority&&(t.priority<1||t.priority>100)&&e.push(`Rule ${r}: priority must be between 1 and 100`),t.action&&![1,2].includes(t.action)&&e.push(`Rule ${r}: action must be 'allow' or 'deny'`)})),e.length>0&&console.warn("URL security config validation errors:",e)}findMatchingRule(e){try{const t="string"==typeof e?new URL(e):e;for(const e of this.rules)if(this.ruleMatches(t,e))return e;return null}catch(e){return null}}clearCache(){this.cache.clear()}setCacheEnabled(e){this.cacheEnabled=e,e||this.clearCache()}getCacheSize(){return this.cache.size}},exports.alignTo=function(e,t){return e<=0?t:e+(t-e%t)%t},exports.chunks=(e,t)=>{const r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r},exports.clamp=(e,t,r)=>e>t?e<r?e:r:t,exports.comparison=n,exports.copyText=e=>{if(e){try{navigator.clipboard?.writeText(e)}catch{}try{var t=document.createElement("input");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}catch{}}},exports.createLinksFromText=(e,t)=>{const r=[],n=/{{([^}]+):([^}]+)}}/g;let s,o=0;for(;null!==(s=n.exec(e));)r.push(e.substring(o,s.index)),o=s.index+s[0].length,r.push({key:s[1],text:s[2]});return r.push(e.substring(o)),r.map((e=>"string"==typeof e?e:t(e.key,e.text)))},exports.decWord=e,exports.elasticClamp=(e,t,r,n={})=>{const{threshold:s=50,resistance:o=.2}=n;if(e<t){const r=t-e;return t-s*(1-Math.exp(-r*o/s))}if(e>r){const t=e-r;return r+s*(1-Math.exp(-t*o/s))}return e},exports.formatNumber=e=>(e||0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,"."),exports.generateUniqueKey=e=>{const t=e=>{if("string"==typeof e||"number"==typeof e||"boolean"==typeof e||null===e)return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(t).join(",")+"]";if("object"==typeof e){const r=Object.keys(e).sort();let n="{";for(let s=0;s<r.length;s++){const o=r[s];n+=JSON.stringify(o)+":"+t(e[o]),s<r.length-1&&(n+=",")}return n+="}",n}return String(e)},r=e=>{let t=0;if(0===e.length)return t;for(let r=0;r<e.length;r++){t=(t<<5)-t+e.charCodeAt(r),t|=0}return t};try{const n=t(e);return r(n).toString(16)}catch(t){return console.warn(`Object could not be fully stringified. Using a simple string conversion. Error: ${t}`),r(String(e)).toString(16)}},exports.getChangedData=p,exports.groupBy=function(e,t){return e.reduce(((e,r)=>{const n=t(r);return e[n]||(e[n]=[]),e[n].push(r),e}),{})},exports.isType=r,exports.memoize=function(e){const t=new Map;return function(...r){const n=JSON.stringify(r);if(t.has(n))return t.get(n);const s=e(...r);return t.set(n,s),s}},exports.omit=function(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)||(r[n]=e[n]),r)),{})},exports.orderBy=function(e,t){const r=Object.keys(t);return e.slice().sort(((e,n)=>{for(const s of r){const r="desc"===t[s]?-1:1,o=g(e,s),i=g(n,s);if(o<i)return-r;if(o>i)return r}return 0}))},exports.parseQueryString=function(e){const t={},r=(e.startsWith("?")?e.slice(1):e).split("&");for(const e of r){const[r,n]=e.split("=");if(r){const e=decodeURIComponent(r),s=n?decodeURIComponent(n):"";t[e]=s}}return t},exports.parseVersionString=function(e){const t=e.match(/^(\d+|\*)\.(\d+|\*)\.(\d+|\*)(?:-([a-zA-Z0-9-.]+))?$/);if(!t)throw new Error("Invalid version string");const[,r,n,s,o]=t,i=e=>"*"===e?"*":parseInt(e,10);return{major:i(r),minor:i(n),patch:i(s),prerelease:o||null}},exports.pick=function(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)&&(r[n]=e[n]),r)),{})},exports.random=t,exports.randomByWeight=function(e,r){let n=0;for(const t in e)n+=e[t];const s=t(0,n,r);let o=0;for(const t in e)if(o+=e[t],s<o)return t;const i=Object.keys(e);return i[t(0,i.length-1,r)]},exports.retry=function(e,t,r){return new Promise(((n,s)=>{const o=t=>{e().then(n).catch((e=>{0===t?s(e):(console.log(`Retrying... attempts left: ${t}`),setTimeout((()=>o(t-1)),r))}))};o(t)}))},exports.shuffle=(e,r)=>{for(let n=e.length-1;n>0;n--){const s=t(0,n,r);[e[n],e[s]]=[e[s],e[n]]}return e},exports.sleep=async e=>await new Promise((t=>setTimeout(t,e))),exports.textParserUrl=(e,t)=>{const r=t?.onToken??h,n=t?.requireProtocol??!1,s=t?.regex??n?u:c,o=[];let i=e+" ",a=s.exec(i);for(;a;){const e=a[0].trim(),t=a.index;t>0&&(o.push(r({type:"raw",value:i.substring(0,t)})),i=i.substring(t)),o.push(r({type:"url",value:e})),i=i.substring(e.length),a=s.exec(i)}return i.length>0&&o.push(r({type:"raw",value:i})),o},exports.timeAgo=t=>{if(!t)return"только что";const r=new Date(t),n=Math.floor((Date.now()-r.getTime())/1e3),s=()=>new Intl.DateTimeFormat("RU-ru",{day:"numeric",month:"short"}).format(r).replace(".",""),o=()=>r.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),i=(t,r,n)=>Array.isArray(t)?`${n} ${e(n,t)} ${r}`:`${t} ${r}`;switch(!0){case n<0:return"скоро";case n<60:return i(["секунду","секунды","секунд"],"назад",n);case n<3600:return i(["минуту","минуты","минут"],"назад",Math.floor(n/60));case n<7200:return i("час","назад",Math.floor(n/3600));case n<10800:return i("два часа","назад",Math.floor(n/3600));case n<14400:return i("три часа","назад",Math.floor(n/3600));case n<86400:return i(`сегодня в ${o()}`,"",Math.floor(n/3600));case n<172800:return i(`вчера в ${o()}`,"",Math.floor(n/86400));case n<259200:return i("два дня","назад",Math.floor(n/86400));case n<345600:return i("три дня","назад",Math.floor(n/86400));case n<31536e3:return i(`${s()} в ${o()}`,"",Math.floor(n/86400));case n>=31536e3:return i(`${s()} ${r.getFullYear()} г.`,"",Math.floor(n/31536e3))}return"только что"},exports.toShort=(e,t,r=1)=>{const n=t||["","k","M","G","T","P"],s=e<0,o=Math.abs(e),i=Math.log10(o)/3|0,a=o/10**(3*i);return parseFloat(`${s?"-":""}${a%1?(Math.floor(10*a)/10).toFixed(r):a}`)+n[i]},exports.unique=l,exports.unlink=o,exports.updateCurrent=f;
1
+ "use strict";const e=(e,t)=>t[e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2];function t(e,t,r){if(!r){const e=new Date;r=e.getDate()*e.getFullYear()*(e.getHours()??1)*e.getMilliseconds()}const n=function(e){const t=2**32;let r=e;return function(){var e;return r=(1664525*r+1013904223)%t,e=r,e^=e>>>21,r=(e^=e<<35)^e>>>4,(r>>>0)/t}}(r);return function(e,t,r){if(t>r)throw new Error("Минимальная граница не может быть больше максимальной.");return Math.floor(e()*(r-t+1))+t}(n,e,t)}function r(e,t){var r=Object.prototype.toString.call(e).replace("[object ","").replace("]","").toLowerCase();try{"number"===r?isNaN(e)&&(r="nan"):e instanceof Buffer&&(r="buffer")}catch{}return void 0!==t?r===t:r}const n=(e,t)=>{switch(r(e)){case"array":if(!function(e,t,r){if(!s(e,t,"array",r))return!1;if(e.length!==t.length)return!1;for(var o=0;o<e.length;o++)if(!n(e[o],t[o]))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"object":if(!function(e,t,r){if(!s(e,t,"object",r))return!1;const o=Object.keys(e),i=Object.keys(t);if(o.length!==i.length)return!1;for(var a of o){if(!t.hasOwnProperty(a))return!1;if(!n(e[a],t[a]))return!1}return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"function":if(!function(e,t,r){return!!s(e,t,"function",r)&&e===t}(e,t,{skipCheckPrev:!0}))return!1;break;case"date":if(!function(e,t,r){return!!s(e,t,"date",r)&&e.getTime()===t.getTime()}(e,t,{skipCheckPrev:!0}))return!1;break;case"map":if(!function(e,t,r){if(!s(e,t,"map",r))return!1;if(e.size!==t.size)return!1;for(const[r,s]of e)if(!n(s,t.get(r)))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"set":if(!function(e,t,r){if(!s(e,t,"set",r))return!1;if(e.size!==t.size)return!1;const o=Array.from(e.keys()),i=Array.from(t.keys());for(var a=0;a<o.length;a++)if(!n(o[a],i[a]))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;default:if(e!==t)return!1}return!0};function s(e,t,n,s){return!(!s?.skipCheckPrev&&!r(e,n)||!r(t,n))}const o=e=>{switch(r(e)){case"array":return i(e);case"object":return a(e);case"number":return Number(String(e));case"string":return String(e);case"bigint":return BigInt(String(e));case"map":return new Map(e);case"set":return new Set(e);default:return e}},i=e=>{const t=[];for(const r of e)t.push(o(r));return t},a=e=>{const t={};for(const r in e)t[r]=o(e[r]);return t},c=new RegExp(/(?:https?:\/\/)?(?:www\.)?([А-Яа-яa-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.(?:ru|com|org|net|me|su|рф|biz|info|co|uk|de|fr|jp|cn|es|it|ca|au|nl|se|no|dk|fi|pl|at|ch|be|cz|ie|pt|ro|hu|gr|sk|bg|hr|si|lt|lv|ee|is|mt|lu|li|mc|sm|va|ad|al|ba|mk|me|rs|tr|ua|by|kz|uz|am|ge|az|tm|kg|tj|md|kg|tj|af|dz|bh|eg|iq|ir|jo|kw|lb|ly|ma|om|ps|qa|sa|sd|sy|tn|ae|ye|ar|bo|br|cl|co|ec|gf|gy|pe|py|sr|uy|ve|ag|ai|aw|bb|bm|bs|bz|ca|cr|cu|dm|do|gd|gp|gt|hn|ht|jm|kn|ky|lc|ms|mx|ni|pa|pr|sv|tc|tt|vc|vg|vi|an|aq|as|fj|fm|gu|hm|id|ki|mh|mp|nc|nf|nr|nu|pf|pg|pw|sb|tk|to|tv|vu|wf|ws)(?:\/[a-zA-Z0-9._~:\/?#[\]@!$&'()*+,;=-]*)?)(?:\s)/),u=new RegExp(/(?:https?:\/\/)(?:www\.)?([А-Яа-яa-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.(?:ru|com|org|net|me|su|рф|biz|info|co|uk|de|fr|jp|cn|es|it|ca|au|nl|se|no|dk|fi|pl|at|ch|be|cz|ie|pt|ro|hu|gr|sk|bg|hr|si|lt|lv|ee|is|mt|lu|li|mc|sm|va|ad|al|ba|mk|me|rs|tr|ua|by|kz|uz|am|ge|az|tm|kg|tj|md|kg|tj|af|dz|bh|eg|iq|ir|jo|kw|lb|ly|ma|om|ps|qa|sa|sd|sy|tn|ae|ye|ar|bo|br|cl|co|ec|gf|gy|pe|py|sr|uy|ve|ag|ai|aw|bb|bm|bs|bz|ca|cr|cu|dm|do|gd|gp|gt|hn|ht|jm|kn|ky|lc|ms|mx|ni|pa|pr|sv|tc|tt|vc|vg|vi|an|aq|as|fj|fm|gu|hm|id|ki|mh|mp|nc|nf|nr|nu|pf|pg|pw|sb|tk|to|tv|vu|wf|ws)(?:\/[a-zA-Z0-9._~:\/?#[\]@!$&'()*+,;=-]*)?)(?:\s)/),h=e=>e;function l(e){return Array.from(new Set(e))}function f(e,t){switch(r(e)){case"object":return function(e,t){const r={},n=Object.keys(e),s=Object.keys(t),o=l([...n,...s]);for(const n of o)r[n]=f(e[n],t[n]);return r}(e,t);case"array":return function(e,t){const r=[];for(var n=0;n<e.length;n++)r.push(f(e?.[n],t?.[n]));for(n=e.length;n<t.length;n++)r.push(f(e?.[n],t?.[n]));return r}(e,t);default:return e??t}}function p(e,t){switch(r(e)){case"object":return function(e,t){const r={};var n=!1;for(const s in t)if(e.hasOwnProperty(s)){const o=p(e?.[s],t?.[s]);void 0!==o&&(r[s]=o,n=!0)}else r[s]=t[s],n=!0;for(const s in e)s in t||(r[s]=void 0,n=!0);return n?r:void 0}(e,t);case"array":return function(e,t){const r=[];for(var n=!1,s=0;s<e.length;s++){const o=p(e?.[s],t?.[s]);void 0===o&&void 0!==t?.[s]||(r[s]=o,n=!0)}for(s=0;s<t.length;s++){const o=p(e?.[s],t?.[s]);void 0!==o&&(r[s]=o,n=!0)}return n?r:void 0}(e,t);default:if(e!==t)return t}}function g(e,t){return t.split(".").reduce(((e,t)=>e?e[t]:void 0),e)}const d=e=>{const t=e.toString(16);return 1==t.length?"0"+t:t};var m=Object.defineProperty,b=(e,t,r)=>(((e,t,r)=>{t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);var y=Object.defineProperty,k=(e,t,r)=>(((e,t,r)=>{t in e?y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);var v=Object.defineProperty,w=(e,t,r)=>(((e,t,r)=>{t in e?v(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);var x=Object.defineProperty,j=(e,t,r)=>(((e,t,r)=>{t in e?x(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r),$=(e=>(e[e.ALLOW=1]="ALLOW",e[e.DENY=2]="DENY",e))($||{});exports.DataKeeper=class{constructor(e){w(this,"initValue"),w(this,"currentValue"),this.initValue=o(e),this.currentValue=e}setter(e){this.currentValue=e(this.currentValue)}reset(e){this.initValue=o(e),this.currentValue=e}isModified(){return!n(this.initValue,this.currentValue)}get updateValues(){return p(this.initValue,this.currentValue)}},exports.DebouncedFunction=class{constructor(e,t){k(this,"cb"),k(this,"o"),k(this,"tId",null),k(this,"s"),this.cb=e,this.o=t,this.s=[]}execute(...e){if(this.cancel(),"[object Function]"===Object.prototype.toString.call(e[0]))this.s=e[0](...this.s);else for(let t=0;t<this.cb.length;t++)this.s[t]=e[t];this.tId=setTimeout(this.executeImmediately.bind(this),this.o.delay)}executeImmediately(){this.cancel(),this.cb(...this.s),this.s=[]}cancel(){this.tId&&(clearTimeout(this.tId),this.tId=null)}},exports.EventEmitter=class{constructor(){b(this,"e",{})}on(e,t){return this.e[e]||(this.e[e]=[]),this.e[e].push(t),()=>this.off(e,t)}off(e,t){if(!this.e[e])return;const r=this.e[e].findIndex((e=>e===t));-1!==r&&(this.e[e].splice(r,1),0===this.e[e].length&&delete this.e[e])}emit(e,...t){if(!this.e[e])return;const r=this.e[e].slice();for(const n of r)try{n(...t)}catch(t){console.error(`Ошибка в обработчике события ${e}:`,t)}}once(e,t){const r=(...n)=>{this.off(e,r),t(...n)};return this.on(e,r)}clear(e){e?delete this.e[e]:this.e={}}},exports.HEXtoRGB=e=>{if(3===(e=e.replace("#","")).length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)return[0,0,0];const t=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),n=parseInt(e.substring(4,6),16);return isNaN(t)||isNaN(r)||isNaN(n)||t<0||t>255||r<0||r>255||n<0||n>255?[0,0,0]:[t,r,n]},exports.HSVtoRGB=(e,t,r)=>{var n,s,o,i,a,c,u,h;switch(c=r*(1-t),u=r*(1-(a=6*e-(i=Math.floor(6*e)))*t),h=r*(1-(1-a)*t),i%6){case 0:n=r,s=h,o=c;break;case 1:n=u,s=r,o=c;break;case 2:n=c,s=r,o=h;break;case 3:n=c,s=u,o=r;break;case 4:n=h,s=c,o=r;break;case 5:n=r,s=c,o=u}return[Math.round(255*n),Math.round(255*s),Math.round(255*o)]},exports.RGBtoHEX=(e,t,r)=>"#"+d(e)+d(t)+d(r),exports.RGBtoHSV=(e,t,r)=>{var n=Math.max(e,t,r),s=Math.min(e,t,r),o=n-s,i=0,a=0===n?0:o/n,c=n/255;switch(n){case s:i=0;break;case e:i=t-r+o*(t<r?6:0),i/=6*o;break;case t:i=r-e+2*o,i/=6*o;break;case r:i=e-t+4*o,i/=6*o}return[i,a,c]},exports.UrlAction=$,exports.UrlSecurityManager=class{constructor(e=[],t=!0){j(this,"rules"),j(this,"cache"),j(this,"cacheEnabled"),this.rules=[...e].sort(((e,t)=>(e.priority||50)-(t.priority||50))),this.cache=new Map,this.cacheEnabled=t,this.validateConfig()}isAllowed(e){try{const t="string"==typeof e?new URL(e):e;if(this.isObfuscatedUrl(t))return!1;const r=this.getCacheKey(t);if(this.cacheEnabled&&this.cache.has(r))return this.cache.get(r);const n=this.evaluateRules(t);return this.cacheEnabled&&this.cache.set(r,n),this.logAccess(t,n),n}catch(t){return console.error("Invalid URL:",e,t),!1}}evaluateRules(e){let t=null,r=null;for(const n of this.rules)this.ruleMatches(e,n)&&(null===t&&(t=1===n.action,r=n.id||null),console.debug(`Rule "${n.id}" matched for ${e.href}`));return null===t?(console.warn(`No rules matched for ${e.href}, defaulting to deny`),!1):(console.debug(`Final decision for ${e.href}: ${t} (rule: ${r})`),t)}ruleMatches(e,t){return this.checkHost(t,e)&&this.checkPaths(t,e)&&this.checkHash(t,e)&&this.checkParams(t,e)}checkHost(e,t){return e.hosts.some((e=>"string"==typeof e?"*"===e||t.host===e:e.test(t.host)))}checkPaths(e,t){return!e.paths||0===e.paths.length||e.paths.some((e=>"string"==typeof e?t.pathname===e||t.pathname.startsWith(e+"/"):e.test(t.pathname)))}checkHash(e,t){if(!e.hash||0===e.hash.length)return!0;const r=t.hash;return e.hash.some((e=>"string"==typeof e?r===e:e.test(r)))}checkParams(e,t){if(!e.allowedParams&&!e.ignoreParams)return!0;const r=new URL(t.toString());if(e.ignoreParams&&e.ignoreParams.forEach((e=>{r.searchParams.delete(e)})),e.allowedParams&&r.searchParams.size>0)for(const[t]of r.searchParams)if(!e.allowedParams.includes(t))return!1;return!0}isObfuscatedUrl(e){return[/@/,/\\/,/^\d+\.\d+\.\d+\.\d+$/,/\[.*\]/,/localhost/].some((t=>t.test(e.hostname)||t.test(e.href)))}getCacheKey(e){const t=new URL(e.toString());return t.searchParams.sort(),`${t.host}${t.pathname}${t.search}${t.hash}`}logAccess(e,t){console[t?"info":"warn"](`URL ${t?"allowed":"blocked"}: ${e.href}`)}validateConfig(){const e=[];this.rules.forEach(((t,r)=>{t.hosts&&Array.isArray(t.hosts)&&0!==t.hosts.length||e.push(`Rule ${r}: missing or invalid 'hosts' array`),void 0!==t.priority&&(t.priority<1||t.priority>100)&&e.push(`Rule ${r}: priority must be between 1 and 100`),t.action&&![1,2].includes(t.action)&&e.push(`Rule ${r}: action must be 'allow' or 'deny'`)})),e.length>0&&console.warn("URL security config validation errors:",e)}findMatchingRule(e){try{const t="string"==typeof e?new URL(e):e;for(const e of this.rules)if(this.ruleMatches(t,e))return e;return null}catch(e){return null}}clearCache(){this.cache.clear()}setCacheEnabled(e){this.cacheEnabled=e,e||this.clearCache()}getCacheSize(){return this.cache.size}},exports.alignTo=function(e,t){return e<=0?t:e+(t-e%t)%t},exports.chunks=(e,t)=>{const r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r},exports.clamp=(e,t,r)=>e>t?e<r?e:r:t,exports.comparison=n,exports.copyText=e=>{if(e){try{navigator.clipboard?.writeText(e)}catch{}try{var t=document.createElement("input");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}catch{}}},exports.createLinksFromText=(e,t)=>{const r=[],n=/{{([^}]+):([^}]+)}}/g;let s,o=0;for(;null!==(s=n.exec(e));)r.push(e.substring(o,s.index)),o=s.index+s[0].length,r.push({key:s[1],text:s[2]});return r.push(e.substring(o)),r.map((e=>"string"==typeof e?e:t(e.key,e.text)))},exports.decWord=e,exports.elasticClamp=(e,t,r,n={})=>{const{threshold:s=50,resistance:o=.2}=n;if(e<t){const r=t-e;return t-s*(1-Math.exp(-r*o/s))}if(e>r){const t=e-r;return r+s*(1-Math.exp(-t*o/s))}return e},exports.formatNumber=e=>(e||0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,"."),exports.generateUniqueKey=e=>{const t=e=>{if("string"==typeof e||"number"==typeof e||"boolean"==typeof e||null===e)return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(t).join(",")+"]";if("object"==typeof e){const r=Object.keys(e).sort();let n="{";for(let s=0;s<r.length;s++){const o=r[s];n+=JSON.stringify(o)+":"+t(e[o]),s<r.length-1&&(n+=",")}return n+="}",n}return String(e)},r=e=>{let t=0;if(0===e.length)return t;for(let r=0;r<e.length;r++){t=(t<<5)-t+e.charCodeAt(r),t|=0}return t};try{const n=t(e);return r(n).toString(16)}catch(t){return console.warn(`Object could not be fully stringified. Using a simple string conversion. Error: ${t}`),r(String(e)).toString(16)}},exports.getChangedData=p,exports.groupBy=function(e,t){return e.reduce(((e,r)=>{const n=t(r);return e[n]||(e[n]=[]),e[n].push(r),e}),{})},exports.isType=r,exports.memoize=function(e){const t=new Map;return function(...r){const n=JSON.stringify(r);if(t.has(n))return t.get(n);const s=e(...r);return t.set(n,s),s}},exports.omit=function(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)||(r[n]=e[n]),r)),{})},exports.orderBy=function(e,t){const r=Object.keys(t);return e.slice().sort(((e,n)=>{for(const s of r){const r="desc"===t[s]?-1:1,o=g(e,s),i=g(n,s);if(o<i)return-r;if(o>i)return r}return 0}))},exports.parseQueryString=function(e){const t={},r=(e.startsWith("?")?e.slice(1):e).split("&");for(const e of r){const[r,n]=e.split("=");if(r){const e=decodeURIComponent(r),s=n?decodeURIComponent(n):"";t[e]=s}}return t},exports.parseVersionString=function(e){const t=e.match(/^(\d+|\*)\.(\d+|\*)\.(\d+|\*)(?:-([a-zA-Z0-9-.]+))?$/);if(!t)throw new Error("Invalid version string");const[,r,n,s,o]=t,i=e=>"*"===e?"*":parseInt(e,10);return{major:i(r),minor:i(n),patch:i(s),prerelease:o||null}},exports.pick=function(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)&&(r[n]=e[n]),r)),{})},exports.random=t,exports.randomByWeight=function(e,r){let n=0;for(const t in e)n+=e[t];const s=t(0,n,r);let o=0;for(const t in e)if(o+=e[t],s<o)return t;const i=Object.keys(e);return i[t(0,i.length-1,r)]},exports.retry=function(e,t,r){return new Promise(((n,s)=>{const o=t=>{e().then(n).catch((e=>{0===t?s(e):(console.log(`Retrying... attempts left: ${t}`),setTimeout((()=>o(t-1)),r))}))};o(t)}))},exports.shuffle=(e,r)=>{for(let n=e.length-1;n>0;n--){const s=t(0,n,r);[e[n],e[s]]=[e[s],e[n]]}return e},exports.sleep=async e=>await new Promise((t=>setTimeout(t,e))),exports.textParserUrl=(e,t)=>{const r=t?.onToken??h,n=t?.requireProtocol??!1,s=t?.regex??n?u:c,o=[];let i=e+" ",a=s.exec(i);for(;a;){const e=a[0].trim(),t=a.index;t>0&&(o.push(r({type:"raw",value:i.substring(0,t)})),i=i.substring(t)),o.push(r({type:"url",value:e})),i=i.substring(e.length),a=s.exec(i)}return i.length>0&&o.push(r({type:"raw",value:i})),o},exports.timeAgo=t=>{if(!t)return"только что";const r=new Date(t),n=Math.floor((Date.now()-r.getTime())/1e3),s=()=>new Intl.DateTimeFormat("RU-ru",{day:"numeric",month:"short"}).format(r).replace(".",""),o=()=>r.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),i=(t,r,n)=>Array.isArray(t)?`${n} ${e(n,t)} ${r}`:`${t} ${r}`;switch(!0){case n<0:return"скоро";case n<60:return i(["секунду","секунды","секунд"],"назад",n);case n<3600:return i(["минуту","минуты","минут"],"назад",Math.floor(n/60));case n<7200:return i("час","назад",Math.floor(n/3600));case n<10800:return i("два часа","назад",Math.floor(n/3600));case n<14400:return i("три часа","назад",Math.floor(n/3600));case n<86400:return i(`сегодня в ${o()}`,"",Math.floor(n/3600));case n<172800:return i(`вчера в ${o()}`,"",Math.floor(n/86400));case n<259200:return i("два дня","назад",Math.floor(n/86400));case n<345600:return i("три дня","назад",Math.floor(n/86400));case n<31536e3:return i(`${s()} в ${o()}`,"",Math.floor(n/86400));case n>=31536e3:return i(`${s()} ${r.getFullYear()} г.`,"",Math.floor(n/31536e3))}return"только что"},exports.toShort=(e,t,r=1)=>{const n=t||["","k","M","G","T","P"],s=e<0,o=Math.abs(e),i=Math.log10(o)/3|0,a=o/10**(3*i);return parseFloat(`${s?"-":""}${a%1?(Math.floor(10*a)/10).toFixed(r):a}`)+n[i]},exports.unique=l,exports.unlink=o,exports.updateCurrent=f;
package/index.mjs CHANGED
@@ -1 +1 @@
1
- const e=(e,t,r)=>e>t?e<r?e:r:t,t=(e,t)=>t[e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2];function r(e,t){return e<=0?t:e+(t-e%t)%t}const n=(e,t,r=1)=>{const n=t||["","k","M","G","T","P"],s=e<0,o=Math.abs(e),i=Math.log10(o)/3|0,a=o/10**(3*i);return parseFloat(`${s?"-":""}${a%1?(Math.floor(10*a)/10).toFixed(r):a}`)+n[i]},s=e=>{if(!e)return"только что";const r=new Date(e),n=Math.floor((Date.now()-r.getTime())/1e3),s=()=>new Intl.DateTimeFormat("RU-ru",{day:"numeric",month:"short"}).format(r).replace(".",""),o=()=>r.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),i=(e,r,n)=>Array.isArray(e)?`${n} ${t(n,e)} ${r}`:`${e} ${r}`;switch(!0){case n<0:return"скоро";case n<60:return i(["секунду","секунды","секунд"],"назад",n);case n<3600:return i(["минуту","минуты","минут"],"назад",Math.floor(n/60));case n<7200:return i("час","назад",Math.floor(n/3600));case n<10800:return i("два часа","назад",Math.floor(n/3600));case n<14400:return i("три часа","назад",Math.floor(n/3600));case n<86400:return i(`сегодня в ${o()}`,"",Math.floor(n/3600));case n<172800:return i(`вчера в ${o()}`,"",Math.floor(n/86400));case n<259200:return i("два дня","назад",Math.floor(n/86400));case n<345600:return i("три дня","назад",Math.floor(n/86400));case n<31536e3:return i(`${s()} в ${o()}`,"",Math.floor(n/86400));case n>=31536e3:return i(`${s()} ${r.getFullYear()} г.`,"",Math.floor(n/31536e3))}return"только что"},o=e=>(e||0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,".");function i(e,t,r){if(!r){const e=new Date;r=e.getDate()*e.getFullYear()*(e.getHours()??1)*e.getMilliseconds()}const n=function(e){const t=2**32;let r=e;return function(){var e;return r=(1664525*r+1013904223)%t,e=r,e^=e>>>21,r=(e^=e<<35)^e>>>4,(r>>>0)/t}}(r);return function(e,t,r){if(t>r)throw new Error("Минимальная граница не может быть больше максимальной.");return Math.floor(e()*(r-t+1))+t}(n,e,t)}function a(e,t){let r=0;for(const t in e)r+=e[t];const n=i(0,r,t);let s=0;for(const t in e)if(s+=e[t],n<s)return t;const o=Object.keys(e);return o[i(0,o.length-1,t)]}function c(e,t){var r=Object.prototype.toString.call(e).replace("[object ","").replace("]","").toLowerCase();try{"number"===r?isNaN(e)&&(r="nan"):e instanceof Buffer&&(r="buffer")}catch{}return void 0!==t?r===t:r}function u(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)||(r[n]=e[n]),r)),{})}function h(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)&&(r[n]=e[n]),r)),{})}const l=async e=>await new Promise((t=>setTimeout(t,e))),f=e=>{if(e){try{navigator.clipboard?.writeText(e)}catch{}try{var t=document.createElement("input");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}catch{}}},g=(e,t)=>{const r=[],n=/{{([^}]+):([^}]+)}}/g;let s,o=0;for(;null!==(s=n.exec(e));)r.push(e.substring(o,s.index)),o=s.index+s[0].length,r.push({key:s[1],text:s[2]});return r.push(e.substring(o)),r.map((e=>"string"==typeof e?e:t(e.key,e.text)))},d=(e,t)=>{switch(c(e)){case"array":if(!function(e,t,r){if(!m(e,t,"array",r))return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(!d(e[n],t[n]))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"object":if(!function(e,t,r){if(!m(e,t,"object",r))return!1;const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(var o of n){if(!t.hasOwnProperty(o))return!1;if(!d(e[o],t[o]))return!1}return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"function":if(!function(e,t,r){return!!m(e,t,"function",r)&&e===t}(e,t,{skipCheckPrev:!0}))return!1;break;case"date":if(!function(e,t,r){return!!m(e,t,"date",r)&&e.getTime()===t.getTime()}(e,t,{skipCheckPrev:!0}))return!1;break;case"map":if(!function(e,t,r){if(!m(e,t,"map",r))return!1;if(e.size!==t.size)return!1;for(const[r,n]of e)if(!d(n,t.get(r)))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"set":if(!function(e,t,r){if(!m(e,t,"set",r))return!1;if(e.size!==t.size)return!1;const n=Array.from(e.keys()),s=Array.from(t.keys());for(var o=0;o<n.length;o++)if(!d(n[o],s[o]))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;default:if(e!==t)return!1}return!0};function m(e,t,r,n){return!(!n?.skipCheckPrev&&!c(e,r)||!c(t,r))}const p=e=>{const t=e=>{if("string"==typeof e||"number"==typeof e||"boolean"==typeof e||null===e)return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(t).join(",")+"]";if("object"==typeof e){const r=Object.keys(e).sort();let n="{";for(let s=0;s<r.length;s++){const o=r[s];n+=JSON.stringify(o)+":"+t(e[o]),s<r.length-1&&(n+=",")}return n+="}",n}return String(e)},r=e=>{let t=0;if(0===e.length)return t;for(let r=0;r<e.length;r++){t=(t<<5)-t+e.charCodeAt(r),t|=0}return t};try{const n=t(e);return r(n).toString(16)}catch(t){return console.warn(`Object could not be fully stringified. Using a simple string conversion. Error: ${t}`),r(String(e)).toString(16)}},b=e=>{switch(c(e)){case"array":return y(e);case"object":return k(e);case"number":return Number(String(e));case"string":return String(e);case"bigint":return BigInt(String(e));case"map":return new Map(e);case"set":return new Set(e);default:return e}},y=e=>{const t=[];for(const r of e)t.push(b(r));return t},k=e=>{const t={};for(const r in e)t[r]=b(e[r]);return t},v=new RegExp(/(?:https?:\/\/)?(?:www\.)?([А-Яа-яa-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.(?:ru|com|org|net|me|su|рф|biz|info|co|uk|de|fr|jp|cn|es|it|ca|au|nl|se|no|dk|fi|pl|at|ch|be|cz|ie|pt|ro|hu|gr|sk|bg|hr|si|lt|lv|ee|is|mt|lu|li|mc|sm|va|ad|al|ba|mk|me|rs|tr|ua|by|kz|uz|am|ge|az|tm|kg|tj|md|kg|tj|af|dz|bh|eg|iq|ir|jo|kw|lb|ly|ma|om|ps|qa|sa|sd|sy|tn|ae|ye|ar|bo|br|cl|co|ec|gf|gy|pe|py|sr|uy|ve|ag|ai|aw|bb|bm|bs|bz|ca|cr|cu|dm|do|gd|gp|gt|hn|ht|jm|kn|ky|lc|ms|mx|ni|pa|pr|sv|tc|tt|vc|vg|vi|an|aq|as|fj|fm|gu|hm|id|ki|mh|mp|nc|nf|nr|nu|pf|pg|pw|sb|tk|to|tv|vu|wf|ws)(?:\/[a-zA-Z0-9._~:\/?#[\]@!$&'()*+,;=-]*)?)(?:\s)/),w=new RegExp(/(?:https?:\/\/)(?:www\.)?([А-Яа-яa-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.(?:ru|com|org|net|me|su|рф|biz|info|co|uk|de|fr|jp|cn|es|it|ca|au|nl|se|no|dk|fi|pl|at|ch|be|cz|ie|pt|ro|hu|gr|sk|bg|hr|si|lt|lv|ee|is|mt|lu|li|mc|sm|va|ad|al|ba|mk|me|rs|tr|ua|by|kz|uz|am|ge|az|tm|kg|tj|md|kg|tj|af|dz|bh|eg|iq|ir|jo|kw|lb|ly|ma|om|ps|qa|sa|sd|sy|tn|ae|ye|ar|bo|br|cl|co|ec|gf|gy|pe|py|sr|uy|ve|ag|ai|aw|bb|bm|bs|bz|ca|cr|cu|dm|do|gd|gp|gt|hn|ht|jm|kn|ky|lc|ms|mx|ni|pa|pr|sv|tc|tt|vc|vg|vi|an|aq|as|fj|fm|gu|hm|id|ki|mh|mp|nc|nf|nr|nu|pf|pg|pw|sb|tk|to|tv|vu|wf|ws)(?:\/[a-zA-Z0-9._~:\/?#[\]@!$&'()*+,;=-]*)?)(?:\s)/),j=e=>e,$=(e,t)=>{const r=t?.onToken??j,n=t?.requireProtocol??!1,s=t?.regex??n?w:v,o=[];let i=e+" ",a=s.exec(i);for(;a;){const e=a[0].trim(),t=a.index;t>0&&(o.push(r({type:"raw",value:i.substring(0,t)})),i=i.substring(t)),o.push(r({type:"url",value:e})),i=i.substring(e.length),a=s.exec(i)}return i.length>0&&o.push(r({type:"raw",value:i})),o};function M(e){const t=new Map;return function(...r){const n=JSON.stringify(r);if(t.has(n))return t.get(n);const s=e(...r);return t.set(n,s),s}}function P(e,t,r){return new Promise(((n,s)=>{const o=t=>{e().then(n).catch((e=>{0===t?s(e):(console.log(`Retrying... attempts left: ${t}`),setTimeout((()=>o(t-1)),r))}))};o(t)}))}function z(e){const t={},r=(e.startsWith("?")?e.slice(1):e).split("&");for(const e of r){const[r,n]=e.split("=");if(r){const e=decodeURIComponent(r),s=n?decodeURIComponent(n):"";t[e]=s}}return t}function O(e){const t=e.match(/^(\d+|\*)\.(\d+|\*)\.(\d+|\*)(?:-([a-zA-Z0-9-.]+))?$/);if(!t)throw new Error("Invalid version string");const[,r,n,s,o]=t,i=e=>"*"===e?"*":parseInt(e,10);return{major:i(r),minor:i(n),patch:i(s),prerelease:o||null}}const x=(e,t,r,n={})=>{const{threshold:s=50,resistance:o=.2}=n;if(e<t){const r=t-e;return t-s*(1-Math.exp(-r*o/s))}if(e>r){const t=e-r;return r+s*(1-Math.exp(-t*o/s))}return e};function A(e){return Array.from(new Set(e))}function C(e,t){switch(c(e)){case"object":return function(e,t){const r={},n=Object.keys(e),s=Object.keys(t),o=A([...n,...s]);for(const n of o)r[n]=C(e[n],t[n]);return r}(e,t);case"array":return function(e,t){const r=[];for(var n=0;n<e.length;n++)r.push(C(e?.[n],t?.[n]));for(n=e.length;n<t.length;n++)r.push(C(e?.[n],t?.[n]));return r}(e,t);default:return e??t}}function R(e,t){switch(c(e)){case"object":return function(e,t){const r={};var n=!1;for(const s in t)if(e.hasOwnProperty(s)){const o=R(e?.[s],t?.[s]);void 0!==o&&(r[s]=o,n=!0)}else r[s]=t[s],n=!0;for(const s in e)s in t||(r[s]=void 0,n=!0);return n?r:void 0}(e,t);case"array":return function(e,t){const r=[];for(var n=!1,s=0;s<e.length;s++){const o=R(e?.[s],t?.[s]);void 0===o&&void 0!==t?.[s]||(r[s]=o,n=!0)}for(s=0;s<t.length;s++){const o=R(e?.[s],t?.[s]);void 0!==o&&(r[s]=o,n=!0)}return n?r:void 0}(e,t);default:if(e!==t)return t}}const S=(e,t)=>{const r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r},I=(e,t)=>{for(let r=e.length-1;r>0;r--){const n=i(0,r,t);[e[r],e[n]]=[e[n],e[r]]}return e};function E(e,t){return e.reduce(((e,r)=>{const n=t(r);return e[n]||(e[n]=[]),e[n].push(r),e}),{})}function N(e,t){return t.split(".").reduce(((e,t)=>e?e[t]:void 0),e)}function L(e,t){const r=Object.keys(t);return e.slice().sort(((e,n)=>{for(const s of r){const r="desc"===t[s]?-1:1,o=N(e,s),i=N(n,s);if(o<i)return-r;if(o>i)return r}return 0}))}const U=(e,t,r)=>{var n,s,o,i,a,c,u,h;switch(c=r*(1-t),u=r*(1-(a=6*e-(i=Math.floor(6*e)))*t),h=r*(1-(1-a)*t),i%6){case 0:n=r,s=h,o=c;break;case 1:n=u,s=r,o=c;break;case 2:n=c,s=r,o=h;break;case 3:n=c,s=u,o=r;break;case 4:n=h,s=c,o=r;break;case 5:n=r,s=c,o=u}return[Math.round(255*n),Math.round(255*s),Math.round(255*o)]},V=e=>{const t=e.toString(16);return 1==t.length?"0"+t:t},T=(e,t,r)=>"#"+V(e)+V(t)+V(r),q=(e,t,r)=>{var n=Math.max(e,t,r),s=Math.min(e,t,r),o=n-s,i=0,a=0===n?0:o/n,c=n/255;switch(n){case s:i=0;break;case e:i=t-r+o*(t<r?6:0),i/=6*o;break;case t:i=r-e+2*o,i/=6*o;break;case r:i=e-t+4*o,i/=6*o}return[i,a,c]},D=e=>{if(3===(e=e.replace("#","")).length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)return[0,0,0];const t=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),n=parseInt(e.substring(4,6),16);return isNaN(t)||isNaN(r)||isNaN(n)||t<0||t>255||r<0||r>255||n<0||n>255?[0,0,0]:[t,r,n]};var F=Object.defineProperty,Z=(e,t,r)=>(((e,t,r)=>{t in e?F(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class H{constructor(){Z(this,"e",{})}on(e,t){return this.e[e]||(this.e[e]=[]),this.e[e].push(t),()=>this.off(e,t)}off(e,t){if(!this.e[e])return;const r=this.e[e].findIndex((e=>e===t));-1!==r&&(this.e[e].splice(r,1),0===this.e[e].length&&delete this.e[e])}emit(e,...t){if(!this.e[e])return;const r=this.e[e].slice();for(const n of r)try{n(...t)}catch(t){console.error(`Ошибка в обработчике события ${e}:`,t)}}once(e,t){const r=(...n)=>{this.off(e,r),t(...n)};return this.on(e,r)}clear(e){e?delete this.e[e]:this.e={}}}var W=Object.defineProperty,Y=(e,t,r)=>(((e,t,r)=>{t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class B{constructor(e,t){Y(this,"cb"),Y(this,"o"),Y(this,"tId",null),Y(this,"s"),this.cb=e,this.o=t,this.s=[]}execute(...e){if(this.cancel(),"[object Function]"===Object.prototype.toString.call(e[0]))this.s=e[0](...this.s);else for(let t=0;t<this.cb.length;t++)this.s[t]=e[t];this.tId=setTimeout(this.executeImmediately.bind(this),this.o.delay)}executeImmediately(){this.cancel(),this.cb(...this.s),this.s=[]}cancel(){this.tId&&(clearTimeout(this.tId),this.tId=null)}}var J=Object.defineProperty,K=(e,t,r)=>(((e,t,r)=>{t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class _{constructor(e){K(this,"initValue"),K(this,"currentValue"),this.initValue=b(e),this.currentValue=e}setter(e){this.currentValue=e(this.currentValue)}reset(e){this.initValue=b(e),this.currentValue=e}isModified(){return!d(this.initValue,this.currentValue)}get updateValues(){return R(this.initValue,this.currentValue)}}var G=Object.defineProperty,Q=(e,t,r)=>(((e,t,r)=>{t in e?G(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r),X=(e=>(e[e.ALLOW=1]="ALLOW",e[e.DENY=2]="DENY",e))(X||{});class ee{constructor(e=[],t=!0){Q(this,"rules"),Q(this,"cache"),Q(this,"cacheEnabled"),this.rules=[...e].sort(((e,t)=>(e.priority||50)-(t.priority||50))),this.cache=new Map,this.cacheEnabled=t,this.validateConfig()}isAllowed(e){try{const t="string"==typeof e?new URL(e):e;if(this.isObfuscatedUrl(t))return!1;const r=this.getCacheKey(t);if(this.cacheEnabled&&this.cache.has(r))return this.cache.get(r);const n=this.evaluateRules(t);return this.cacheEnabled&&this.cache.set(r,n),this.logAccess(t,n),n}catch(t){return console.error("Invalid URL:",e,t),!1}}evaluateRules(e){let t=null,r=null;for(const n of this.rules)this.ruleMatches(e,n)&&(null===t&&(t=1===n.action,r=n.id||null),console.debug(`Rule "${n.id}" matched for ${e.href}`));return null===t?(console.warn(`No rules matched for ${e.href}, defaulting to deny`),!1):(console.debug(`Final decision for ${e.href}: ${t} (rule: ${r})`),t)}ruleMatches(e,t){return this.checkHost(t,e)&&this.checkPaths(t,e)&&this.checkHash(t,e)&&this.checkParams(t,e)}checkHost(e,t){return!!e.hosts.includes("*")||e.hosts.some((e=>t.host===e||t.host.endsWith("."+e)))}checkPaths(e,t){return!e.paths||0===e.paths.length||e.paths.some((e=>"string"==typeof e?t.pathname===e||t.pathname.startsWith(e+"/"):e.test(t.pathname)))}checkHash(e,t){if(!e.hash||0===e.hash.length)return!0;const r=t.hash;return e.hash.some((e=>"string"==typeof e?r===e:e.test(r)))}checkParams(e,t){if(!e.allowedParams&&!e.ignoreParams)return!0;const r=new URL(t.toString());if(e.ignoreParams&&e.ignoreParams.forEach((e=>{r.searchParams.delete(e)})),e.allowedParams&&r.searchParams.size>0)for(const[t]of r.searchParams)if(!e.allowedParams.includes(t))return!1;return!0}isObfuscatedUrl(e){return[/@/,/\\/,/^\d+\.\d+\.\d+\.\d+$/,/\[.*\]/,/localhost/].some((t=>t.test(e.hostname)||t.test(e.href)))}getCacheKey(e){const t=new URL(e.toString());return t.searchParams.sort(),`${t.host}${t.pathname}${t.search}${t.hash}`}logAccess(e,t){console[t?"info":"warn"](`URL ${t?"allowed":"blocked"}: ${e.href}`)}validateConfig(){const e=[];this.rules.forEach(((t,r)=>{t.hosts&&Array.isArray(t.hosts)&&0!==t.hosts.length||e.push(`Rule ${r}: missing or invalid 'hosts' array`),void 0!==t.priority&&(t.priority<1||t.priority>100)&&e.push(`Rule ${r}: priority must be between 1 and 100`),t.action&&![1,2].includes(t.action)&&e.push(`Rule ${r}: action must be 'allow' or 'deny'`)})),e.length>0&&console.warn("URL security config validation errors:",e)}findMatchingRule(e){try{const t="string"==typeof e?new URL(e):e;for(const e of this.rules)if(this.ruleMatches(t,e))return e;return null}catch(e){return null}}clearCache(){this.cache.clear()}setCacheEnabled(e){this.cacheEnabled=e,e||this.clearCache()}getCacheSize(){return this.cache.size}}export{_ as DataKeeper,B as DebouncedFunction,H as EventEmitter,D as HEXtoRGB,U as HSVtoRGB,T as RGBtoHEX,q as RGBtoHSV,X as UrlAction,ee as UrlSecurityManager,r as alignTo,S as chunks,e as clamp,d as comparison,f as copyText,g as createLinksFromText,t as decWord,x as elasticClamp,o as formatNumber,p as generateUniqueKey,R as getChangedData,E as groupBy,c as isType,M as memoize,u as omit,L as orderBy,z as parseQueryString,O as parseVersionString,h as pick,i as random,a as randomByWeight,P as retry,I as shuffle,l as sleep,$ as textParserUrl,s as timeAgo,n as toShort,A as unique,b as unlink,C as updateCurrent};
1
+ const e=(e,t,r)=>e>t?e<r?e:r:t,t=(e,t)=>t[e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2];function r(e,t){return e<=0?t:e+(t-e%t)%t}const n=(e,t,r=1)=>{const n=t||["","k","M","G","T","P"],s=e<0,o=Math.abs(e),i=Math.log10(o)/3|0,a=o/10**(3*i);return parseFloat(`${s?"-":""}${a%1?(Math.floor(10*a)/10).toFixed(r):a}`)+n[i]},s=e=>{if(!e)return"только что";const r=new Date(e),n=Math.floor((Date.now()-r.getTime())/1e3),s=()=>new Intl.DateTimeFormat("RU-ru",{day:"numeric",month:"short"}).format(r).replace(".",""),o=()=>r.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),i=(e,r,n)=>Array.isArray(e)?`${n} ${t(n,e)} ${r}`:`${e} ${r}`;switch(!0){case n<0:return"скоро";case n<60:return i(["секунду","секунды","секунд"],"назад",n);case n<3600:return i(["минуту","минуты","минут"],"назад",Math.floor(n/60));case n<7200:return i("час","назад",Math.floor(n/3600));case n<10800:return i("два часа","назад",Math.floor(n/3600));case n<14400:return i("три часа","назад",Math.floor(n/3600));case n<86400:return i(`сегодня в ${o()}`,"",Math.floor(n/3600));case n<172800:return i(`вчера в ${o()}`,"",Math.floor(n/86400));case n<259200:return i("два дня","назад",Math.floor(n/86400));case n<345600:return i("три дня","назад",Math.floor(n/86400));case n<31536e3:return i(`${s()} в ${o()}`,"",Math.floor(n/86400));case n>=31536e3:return i(`${s()} ${r.getFullYear()} г.`,"",Math.floor(n/31536e3))}return"только что"},o=e=>(e||0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,".");function i(e,t,r){if(!r){const e=new Date;r=e.getDate()*e.getFullYear()*(e.getHours()??1)*e.getMilliseconds()}const n=function(e){const t=2**32;let r=e;return function(){var e;return r=(1664525*r+1013904223)%t,e=r,e^=e>>>21,r=(e^=e<<35)^e>>>4,(r>>>0)/t}}(r);return function(e,t,r){if(t>r)throw new Error("Минимальная граница не может быть больше максимальной.");return Math.floor(e()*(r-t+1))+t}(n,e,t)}function a(e,t){let r=0;for(const t in e)r+=e[t];const n=i(0,r,t);let s=0;for(const t in e)if(s+=e[t],n<s)return t;const o=Object.keys(e);return o[i(0,o.length-1,t)]}function c(e,t){var r=Object.prototype.toString.call(e).replace("[object ","").replace("]","").toLowerCase();try{"number"===r?isNaN(e)&&(r="nan"):e instanceof Buffer&&(r="buffer")}catch{}return void 0!==t?r===t:r}function u(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)||(r[n]=e[n]),r)),{})}function h(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)&&(r[n]=e[n]),r)),{})}const l=async e=>await new Promise((t=>setTimeout(t,e))),f=e=>{if(e){try{navigator.clipboard?.writeText(e)}catch{}try{var t=document.createElement("input");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}catch{}}},g=(e,t)=>{const r=[],n=/{{([^}]+):([^}]+)}}/g;let s,o=0;for(;null!==(s=n.exec(e));)r.push(e.substring(o,s.index)),o=s.index+s[0].length,r.push({key:s[1],text:s[2]});return r.push(e.substring(o)),r.map((e=>"string"==typeof e?e:t(e.key,e.text)))},d=(e,t)=>{switch(c(e)){case"array":if(!function(e,t,r){if(!p(e,t,"array",r))return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(!d(e[n],t[n]))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"object":if(!function(e,t,r){if(!p(e,t,"object",r))return!1;const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(var o of n){if(!t.hasOwnProperty(o))return!1;if(!d(e[o],t[o]))return!1}return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"function":if(!function(e,t,r){return!!p(e,t,"function",r)&&e===t}(e,t,{skipCheckPrev:!0}))return!1;break;case"date":if(!function(e,t,r){return!!p(e,t,"date",r)&&e.getTime()===t.getTime()}(e,t,{skipCheckPrev:!0}))return!1;break;case"map":if(!function(e,t,r){if(!p(e,t,"map",r))return!1;if(e.size!==t.size)return!1;for(const[r,n]of e)if(!d(n,t.get(r)))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;case"set":if(!function(e,t,r){if(!p(e,t,"set",r))return!1;if(e.size!==t.size)return!1;const n=Array.from(e.keys()),s=Array.from(t.keys());for(var o=0;o<n.length;o++)if(!d(n[o],s[o]))return!1;return!0}(e,t,{skipCheckPrev:!0}))return!1;break;default:if(e!==t)return!1}return!0};function p(e,t,r,n){return!(!n?.skipCheckPrev&&!c(e,r)||!c(t,r))}const m=e=>{const t=e=>{if("string"==typeof e||"number"==typeof e||"boolean"==typeof e||null===e)return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(t).join(",")+"]";if("object"==typeof e){const r=Object.keys(e).sort();let n="{";for(let s=0;s<r.length;s++){const o=r[s];n+=JSON.stringify(o)+":"+t(e[o]),s<r.length-1&&(n+=",")}return n+="}",n}return String(e)},r=e=>{let t=0;if(0===e.length)return t;for(let r=0;r<e.length;r++){t=(t<<5)-t+e.charCodeAt(r),t|=0}return t};try{const n=t(e);return r(n).toString(16)}catch(t){return console.warn(`Object could not be fully stringified. Using a simple string conversion. Error: ${t}`),r(String(e)).toString(16)}},b=e=>{switch(c(e)){case"array":return y(e);case"object":return k(e);case"number":return Number(String(e));case"string":return String(e);case"bigint":return BigInt(String(e));case"map":return new Map(e);case"set":return new Set(e);default:return e}},y=e=>{const t=[];for(const r of e)t.push(b(r));return t},k=e=>{const t={};for(const r in e)t[r]=b(e[r]);return t},v=new RegExp(/(?:https?:\/\/)?(?:www\.)?([А-Яа-яa-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.(?:ru|com|org|net|me|su|рф|biz|info|co|uk|de|fr|jp|cn|es|it|ca|au|nl|se|no|dk|fi|pl|at|ch|be|cz|ie|pt|ro|hu|gr|sk|bg|hr|si|lt|lv|ee|is|mt|lu|li|mc|sm|va|ad|al|ba|mk|me|rs|tr|ua|by|kz|uz|am|ge|az|tm|kg|tj|md|kg|tj|af|dz|bh|eg|iq|ir|jo|kw|lb|ly|ma|om|ps|qa|sa|sd|sy|tn|ae|ye|ar|bo|br|cl|co|ec|gf|gy|pe|py|sr|uy|ve|ag|ai|aw|bb|bm|bs|bz|ca|cr|cu|dm|do|gd|gp|gt|hn|ht|jm|kn|ky|lc|ms|mx|ni|pa|pr|sv|tc|tt|vc|vg|vi|an|aq|as|fj|fm|gu|hm|id|ki|mh|mp|nc|nf|nr|nu|pf|pg|pw|sb|tk|to|tv|vu|wf|ws)(?:\/[a-zA-Z0-9._~:\/?#[\]@!$&'()*+,;=-]*)?)(?:\s)/),w=new RegExp(/(?:https?:\/\/)(?:www\.)?([А-Яа-яa-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.(?:ru|com|org|net|me|su|рф|biz|info|co|uk|de|fr|jp|cn|es|it|ca|au|nl|se|no|dk|fi|pl|at|ch|be|cz|ie|pt|ro|hu|gr|sk|bg|hr|si|lt|lv|ee|is|mt|lu|li|mc|sm|va|ad|al|ba|mk|me|rs|tr|ua|by|kz|uz|am|ge|az|tm|kg|tj|md|kg|tj|af|dz|bh|eg|iq|ir|jo|kw|lb|ly|ma|om|ps|qa|sa|sd|sy|tn|ae|ye|ar|bo|br|cl|co|ec|gf|gy|pe|py|sr|uy|ve|ag|ai|aw|bb|bm|bs|bz|ca|cr|cu|dm|do|gd|gp|gt|hn|ht|jm|kn|ky|lc|ms|mx|ni|pa|pr|sv|tc|tt|vc|vg|vi|an|aq|as|fj|fm|gu|hm|id|ki|mh|mp|nc|nf|nr|nu|pf|pg|pw|sb|tk|to|tv|vu|wf|ws)(?:\/[a-zA-Z0-9._~:\/?#[\]@!$&'()*+,;=-]*)?)(?:\s)/),j=e=>e,$=(e,t)=>{const r=t?.onToken??j,n=t?.requireProtocol??!1,s=t?.regex??n?w:v,o=[];let i=e+" ",a=s.exec(i);for(;a;){const e=a[0].trim(),t=a.index;t>0&&(o.push(r({type:"raw",value:i.substring(0,t)})),i=i.substring(t)),o.push(r({type:"url",value:e})),i=i.substring(e.length),a=s.exec(i)}return i.length>0&&o.push(r({type:"raw",value:i})),o};function M(e){const t=new Map;return function(...r){const n=JSON.stringify(r);if(t.has(n))return t.get(n);const s=e(...r);return t.set(n,s),s}}function P(e,t,r){return new Promise(((n,s)=>{const o=t=>{e().then(n).catch((e=>{0===t?s(e):(console.log(`Retrying... attempts left: ${t}`),setTimeout((()=>o(t-1)),r))}))};o(t)}))}function z(e){const t={},r=(e.startsWith("?")?e.slice(1):e).split("&");for(const e of r){const[r,n]=e.split("=");if(r){const e=decodeURIComponent(r),s=n?decodeURIComponent(n):"";t[e]=s}}return t}function O(e){const t=e.match(/^(\d+|\*)\.(\d+|\*)\.(\d+|\*)(?:-([a-zA-Z0-9-.]+))?$/);if(!t)throw new Error("Invalid version string");const[,r,n,s,o]=t,i=e=>"*"===e?"*":parseInt(e,10);return{major:i(r),minor:i(n),patch:i(s),prerelease:o||null}}const x=(e,t,r,n={})=>{const{threshold:s=50,resistance:o=.2}=n;if(e<t){const r=t-e;return t-s*(1-Math.exp(-r*o/s))}if(e>r){const t=e-r;return r+s*(1-Math.exp(-t*o/s))}return e};function A(e){return Array.from(new Set(e))}function C(e,t){switch(c(e)){case"object":return function(e,t){const r={},n=Object.keys(e),s=Object.keys(t),o=A([...n,...s]);for(const n of o)r[n]=C(e[n],t[n]);return r}(e,t);case"array":return function(e,t){const r=[];for(var n=0;n<e.length;n++)r.push(C(e?.[n],t?.[n]));for(n=e.length;n<t.length;n++)r.push(C(e?.[n],t?.[n]));return r}(e,t);default:return e??t}}function R(e,t){switch(c(e)){case"object":return function(e,t){const r={};var n=!1;for(const s in t)if(e.hasOwnProperty(s)){const o=R(e?.[s],t?.[s]);void 0!==o&&(r[s]=o,n=!0)}else r[s]=t[s],n=!0;for(const s in e)s in t||(r[s]=void 0,n=!0);return n?r:void 0}(e,t);case"array":return function(e,t){const r=[];for(var n=!1,s=0;s<e.length;s++){const o=R(e?.[s],t?.[s]);void 0===o&&void 0!==t?.[s]||(r[s]=o,n=!0)}for(s=0;s<t.length;s++){const o=R(e?.[s],t?.[s]);void 0!==o&&(r[s]=o,n=!0)}return n?r:void 0}(e,t);default:if(e!==t)return t}}const S=(e,t)=>{const r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r},I=(e,t)=>{for(let r=e.length-1;r>0;r--){const n=i(0,r,t);[e[r],e[n]]=[e[n],e[r]]}return e};function E(e,t){return e.reduce(((e,r)=>{const n=t(r);return e[n]||(e[n]=[]),e[n].push(r),e}),{})}function N(e,t){return t.split(".").reduce(((e,t)=>e?e[t]:void 0),e)}function L(e,t){const r=Object.keys(t);return e.slice().sort(((e,n)=>{for(const s of r){const r="desc"===t[s]?-1:1,o=N(e,s),i=N(n,s);if(o<i)return-r;if(o>i)return r}return 0}))}const U=(e,t,r)=>{var n,s,o,i,a,c,u,h;switch(c=r*(1-t),u=r*(1-(a=6*e-(i=Math.floor(6*e)))*t),h=r*(1-(1-a)*t),i%6){case 0:n=r,s=h,o=c;break;case 1:n=u,s=r,o=c;break;case 2:n=c,s=r,o=h;break;case 3:n=c,s=u,o=r;break;case 4:n=h,s=c,o=r;break;case 5:n=r,s=c,o=u}return[Math.round(255*n),Math.round(255*s),Math.round(255*o)]},V=e=>{const t=e.toString(16);return 1==t.length?"0"+t:t},T=(e,t,r)=>"#"+V(e)+V(t)+V(r),q=(e,t,r)=>{var n=Math.max(e,t,r),s=Math.min(e,t,r),o=n-s,i=0,a=0===n?0:o/n,c=n/255;switch(n){case s:i=0;break;case e:i=t-r+o*(t<r?6:0),i/=6*o;break;case t:i=r-e+2*o,i/=6*o;break;case r:i=e-t+4*o,i/=6*o}return[i,a,c]},D=e=>{if(3===(e=e.replace("#","")).length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)return[0,0,0];const t=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),n=parseInt(e.substring(4,6),16);return isNaN(t)||isNaN(r)||isNaN(n)||t<0||t>255||r<0||r>255||n<0||n>255?[0,0,0]:[t,r,n]};var F=Object.defineProperty,Z=(e,t,r)=>(((e,t,r)=>{t in e?F(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class H{constructor(){Z(this,"e",{})}on(e,t){return this.e[e]||(this.e[e]=[]),this.e[e].push(t),()=>this.off(e,t)}off(e,t){if(!this.e[e])return;const r=this.e[e].findIndex((e=>e===t));-1!==r&&(this.e[e].splice(r,1),0===this.e[e].length&&delete this.e[e])}emit(e,...t){if(!this.e[e])return;const r=this.e[e].slice();for(const n of r)try{n(...t)}catch(t){console.error(`Ошибка в обработчике события ${e}:`,t)}}once(e,t){const r=(...n)=>{this.off(e,r),t(...n)};return this.on(e,r)}clear(e){e?delete this.e[e]:this.e={}}}var W=Object.defineProperty,Y=(e,t,r)=>(((e,t,r)=>{t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class B{constructor(e,t){Y(this,"cb"),Y(this,"o"),Y(this,"tId",null),Y(this,"s"),this.cb=e,this.o=t,this.s=[]}execute(...e){if(this.cancel(),"[object Function]"===Object.prototype.toString.call(e[0]))this.s=e[0](...this.s);else for(let t=0;t<this.cb.length;t++)this.s[t]=e[t];this.tId=setTimeout(this.executeImmediately.bind(this),this.o.delay)}executeImmediately(){this.cancel(),this.cb(...this.s),this.s=[]}cancel(){this.tId&&(clearTimeout(this.tId),this.tId=null)}}var J=Object.defineProperty,K=(e,t,r)=>(((e,t,r)=>{t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r);class _{constructor(e){K(this,"initValue"),K(this,"currentValue"),this.initValue=b(e),this.currentValue=e}setter(e){this.currentValue=e(this.currentValue)}reset(e){this.initValue=b(e),this.currentValue=e}isModified(){return!d(this.initValue,this.currentValue)}get updateValues(){return R(this.initValue,this.currentValue)}}var G=Object.defineProperty,Q=(e,t,r)=>(((e,t,r)=>{t in e?G(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r),X=(e=>(e[e.ALLOW=1]="ALLOW",e[e.DENY=2]="DENY",e))(X||{});class ee{constructor(e=[],t=!0){Q(this,"rules"),Q(this,"cache"),Q(this,"cacheEnabled"),this.rules=[...e].sort(((e,t)=>(e.priority||50)-(t.priority||50))),this.cache=new Map,this.cacheEnabled=t,this.validateConfig()}isAllowed(e){try{const t="string"==typeof e?new URL(e):e;if(this.isObfuscatedUrl(t))return!1;const r=this.getCacheKey(t);if(this.cacheEnabled&&this.cache.has(r))return this.cache.get(r);const n=this.evaluateRules(t);return this.cacheEnabled&&this.cache.set(r,n),this.logAccess(t,n),n}catch(t){return console.error("Invalid URL:",e,t),!1}}evaluateRules(e){let t=null,r=null;for(const n of this.rules)this.ruleMatches(e,n)&&(null===t&&(t=1===n.action,r=n.id||null),console.debug(`Rule "${n.id}" matched for ${e.href}`));return null===t?(console.warn(`No rules matched for ${e.href}, defaulting to deny`),!1):(console.debug(`Final decision for ${e.href}: ${t} (rule: ${r})`),t)}ruleMatches(e,t){return this.checkHost(t,e)&&this.checkPaths(t,e)&&this.checkHash(t,e)&&this.checkParams(t,e)}checkHost(e,t){return e.hosts.some((e=>"string"==typeof e?"*"===e||t.host===e:e.test(t.host)))}checkPaths(e,t){return!e.paths||0===e.paths.length||e.paths.some((e=>"string"==typeof e?t.pathname===e||t.pathname.startsWith(e+"/"):e.test(t.pathname)))}checkHash(e,t){if(!e.hash||0===e.hash.length)return!0;const r=t.hash;return e.hash.some((e=>"string"==typeof e?r===e:e.test(r)))}checkParams(e,t){if(!e.allowedParams&&!e.ignoreParams)return!0;const r=new URL(t.toString());if(e.ignoreParams&&e.ignoreParams.forEach((e=>{r.searchParams.delete(e)})),e.allowedParams&&r.searchParams.size>0)for(const[t]of r.searchParams)if(!e.allowedParams.includes(t))return!1;return!0}isObfuscatedUrl(e){return[/@/,/\\/,/^\d+\.\d+\.\d+\.\d+$/,/\[.*\]/,/localhost/].some((t=>t.test(e.hostname)||t.test(e.href)))}getCacheKey(e){const t=new URL(e.toString());return t.searchParams.sort(),`${t.host}${t.pathname}${t.search}${t.hash}`}logAccess(e,t){console[t?"info":"warn"](`URL ${t?"allowed":"blocked"}: ${e.href}`)}validateConfig(){const e=[];this.rules.forEach(((t,r)=>{t.hosts&&Array.isArray(t.hosts)&&0!==t.hosts.length||e.push(`Rule ${r}: missing or invalid 'hosts' array`),void 0!==t.priority&&(t.priority<1||t.priority>100)&&e.push(`Rule ${r}: priority must be between 1 and 100`),t.action&&![1,2].includes(t.action)&&e.push(`Rule ${r}: action must be 'allow' or 'deny'`)})),e.length>0&&console.warn("URL security config validation errors:",e)}findMatchingRule(e){try{const t="string"==typeof e?new URL(e):e;for(const e of this.rules)if(this.ruleMatches(t,e))return e;return null}catch(e){return null}}clearCache(){this.cache.clear()}setCacheEnabled(e){this.cacheEnabled=e,e||this.clearCache()}getCacheSize(){return this.cache.size}}export{_ as DataKeeper,B as DebouncedFunction,H as EventEmitter,D as HEXtoRGB,U as HSVtoRGB,T as RGBtoHEX,q as RGBtoHSV,X as UrlAction,ee as UrlSecurityManager,r as alignTo,S as chunks,e as clamp,d as comparison,f as copyText,g as createLinksFromText,t as decWord,x as elasticClamp,o as formatNumber,m as generateUniqueKey,R as getChangedData,E as groupBy,c as isType,M as memoize,u as omit,L as orderBy,z as parseQueryString,O as parseVersionString,h as pick,i as random,a as randomByWeight,P as retry,I as shuffle,l as sleep,$ as textParserUrl,s as timeAgo,n as toShort,A as unique,b as unlink,C as updateCurrent};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minsize/utils",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Frequently used utilities",
5
5
  "license": "MIT",
6
6
  "types": "index.ts",