@stemy/ngx-utils 19.7.23 → 19.7.24

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.
@@ -4,7 +4,7 @@ import { InjectionToken, PLATFORM_ID, Inject, Injectable, Optional, Injector, in
4
4
  import 'reflect-metadata';
5
5
  import * as i2 from '@angular/router';
6
6
  import { ActivatedRouteSnapshot, Scroll, NavigationEnd, Router, DefaultUrlSerializer, UrlTree, UrlSegmentGroup, UrlSegment, UrlSerializer, ROUTES } from '@angular/router';
7
- import { BehaviorSubject, Observable, firstValueFrom, Subject, Subscription, from, delay, timer, TimeoutError, combineLatest, isObservable, of, lastValueFrom } from 'rxjs';
7
+ import { BehaviorSubject, Observable, firstValueFrom, isObservable, Subject, Subscription, from, delay, timer, TimeoutError, combineLatest, of, lastValueFrom } from 'rxjs';
8
8
  import { skipWhile, debounceTime, distinctUntilChanged, map, filter, mergeMap, timeout } from 'rxjs/operators';
9
9
  import * as i1$3 from '@angular/common';
10
10
  import { isPlatformBrowser, isPlatformServer, DOCUMENT, AsyncPipe, APP_BASE_HREF, CommonModule } from '@angular/common';
@@ -332,19 +332,6 @@ class ObjectUtils {
332
332
  static assign(target, source, predicate) {
333
333
  return ObjectUtils.copyRecursive(target, source, predicate || defaultPredicate, new Map());
334
334
  }
335
- static hashCode(obj) {
336
- let hash = 0;
337
- ObjectUtils.copyRecursive(null, obj, value => {
338
- const str = JSON.stringify(value ?? "") || "";
339
- for (let i = 0, len = str.length; i < len; i++) {
340
- const chr = str.charCodeAt(i);
341
- hash = (hash << 5) - hash + chr;
342
- hash |= 0; // Convert to 32bit integer
343
- }
344
- return true;
345
- }, new Map());
346
- return hash;
347
- }
348
335
  static getType(obj) {
349
336
  const regex = new RegExp("\\s([a-zA-Z]+)");
350
337
  const target = !obj ? null : obj.constructor;
@@ -380,7 +367,7 @@ class ObjectUtils {
380
367
  return (hasBlob && value instanceof Blob) || (hasFile && value instanceof File);
381
368
  }
382
369
  static isBoolean(value) {
383
- return typeof (value) == typeof (true);
370
+ return value === true || value === false;
384
371
  }
385
372
  static isNumber(value) {
386
373
  if (typeof value !== "number")
@@ -1478,6 +1465,132 @@ class CanvasUtils {
1478
1465
  }
1479
1466
  }
1480
1467
 
1468
+ const iso8061 = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:.\d+)?(?:Z|[+-]\d\d:\d\d)$/;
1469
+ function serializer(replacer, cycleReplacer) {
1470
+ const stack = [], keys = [];
1471
+ if (cycleReplacer == null)
1472
+ cycleReplacer = function (key, value) {
1473
+ if (stack[0] === value)
1474
+ return "[Circular ~]";
1475
+ return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
1476
+ };
1477
+ return (key, value) => {
1478
+ if (isObservable(value))
1479
+ return "[Observable ~]";
1480
+ if (stack.length > 0) {
1481
+ const thisPos = stack.indexOf(this);
1482
+ ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
1483
+ ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
1484
+ if (~stack.indexOf(value))
1485
+ value = cycleReplacer.call(this, key, value);
1486
+ }
1487
+ else
1488
+ stack.push(value);
1489
+ if (typeof value === "string" && value.match(iso8061)) {
1490
+ value = new Date(value);
1491
+ }
1492
+ return replacer == null ? value : replacer.call(this, key, value);
1493
+ };
1494
+ }
1495
+ function stringify(value, replacer = null, spaces = 2, cycleReplacer = null) {
1496
+ return JSON.stringify(value, serializer(replacer, cycleReplacer), spaces);
1497
+ }
1498
+
1499
+ const S = [
1500
+ 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14,
1501
+ 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21,
1502
+ 6, 10, 15, 21,
1503
+ ];
1504
+ const K = [
1505
+ 3614090360, 3905402710, 606105819, 3250441966, 4118548399, 1200080426, 2821735955,
1506
+ 4249261313, 1770035416, 2336552879, 4294925233, 2304563134, 1804603682, 4254626195,
1507
+ 2792965006, 1236535329, 4129170786, 3225465664, 643717713, 3921069994, 3593408605,
1508
+ 38016083, 3634488961, 3889429448, 568446438, 3275163606, 4107603335, 1163531501,
1509
+ 2850285829, 4243563512, 1735328473, 2368359562, 4294588738, 2272392833, 1839030562,
1510
+ 4259657740, 2763975236, 1272893353, 4139469664, 3200236656, 681279174, 3936430074,
1511
+ 3572445317, 76029189, 3654602809, 3873151461, 530742520, 3299628645, 4096336452,
1512
+ 1126891415, 2878612391, 4237533241, 1700485571, 2399980690, 4293915773, 2240044497,
1513
+ 1873313359, 4264355552, 2734768916, 1309151649, 4149444226, 3174756917, 718787259,
1514
+ 3951481745,
1515
+ ];
1516
+ function leftRotate(x, c) {
1517
+ return (x << c) | (x >>> (32 - c));
1518
+ }
1519
+ function md5(input) {
1520
+ // UTF-8 encode the string
1521
+ const encoder = new TextEncoder();
1522
+ const data = encoder.encode(stringify(input ?? "") || "");
1523
+ const originalBitLength = data.length * 8;
1524
+ // --- Padding: append 0x80 then 0x00 until len ≡ 56 (mod 64)
1525
+ let msgLen = data.length + 1;
1526
+ while (msgLen % 64 !== 56)
1527
+ msgLen++;
1528
+ const buffer = new Uint8Array(msgLen + 8); // +8 bytes for length
1529
+ buffer.set(data);
1530
+ buffer[data.length] = 0x80;
1531
+ // Append original length in bits, little-endian 64-bit
1532
+ let bitLen = originalBitLength;
1533
+ for (let i = 0; i < 8; i++) {
1534
+ buffer[msgLen + i] = bitLen & 0xff;
1535
+ bitLen = Math.floor(bitLen / 256);
1536
+ }
1537
+ // Initial state
1538
+ let a0 = 0x67452301;
1539
+ let b0 = 0xefcdab89;
1540
+ let c0 = 0x98badcfe;
1541
+ let d0 = 0x10325476;
1542
+ const view = new DataView(buffer.buffer);
1543
+ // Process 512-bit chunks
1544
+ for (let offset = 0; offset < buffer.length; offset += 64) {
1545
+ const M = new Uint32Array(16);
1546
+ for (let i = 0; i < 16; i++) {
1547
+ M[i] = view.getUint32(offset + i * 4, true); // little-endian
1548
+ }
1549
+ let A = a0;
1550
+ let B = b0;
1551
+ let C = c0;
1552
+ let D = d0;
1553
+ for (let i = 0; i < 64; i++) {
1554
+ let F, g;
1555
+ if (i < 16) {
1556
+ F = (B & C) | (~B & D);
1557
+ g = i;
1558
+ }
1559
+ else if (i < 32) {
1560
+ F = (D & B) | (~D & C);
1561
+ g = (5 * i + 1) % 16;
1562
+ }
1563
+ else if (i < 48) {
1564
+ F = B ^ C ^ D;
1565
+ g = (3 * i + 5) % 16;
1566
+ }
1567
+ else {
1568
+ F = C ^ (B | ~D);
1569
+ g = (7 * i) % 16;
1570
+ }
1571
+ F = (F + A + K[i] + M[g]) >>> 0;
1572
+ A = D;
1573
+ D = C;
1574
+ C = B;
1575
+ B = (B + leftRotate(F, S[i])) >>> 0;
1576
+ }
1577
+ a0 = (a0 + A) >>> 0;
1578
+ b0 = (b0 + B) >>> 0;
1579
+ c0 = (c0 + C) >>> 0;
1580
+ d0 = (d0 + D) >>> 0;
1581
+ }
1582
+ // Output as hex (little-endian)
1583
+ const words = [a0, b0, c0, d0];
1584
+ let out = "";
1585
+ for (const w of words) {
1586
+ for (let i = 0; i < 4; i++) {
1587
+ const byte = (w >>> (8 * i)) & 0xff;
1588
+ out += byte.toString(16).padStart(2, "0");
1589
+ }
1590
+ }
1591
+ return out;
1592
+ }
1593
+
1481
1594
  class DateUtils {
1482
1595
  static isHoliday(date) {
1483
1596
  return DateTime.fromJSDate(date).isWeekend;
@@ -2313,51 +2426,6 @@ class Initializer {
2313
2426
  }
2314
2427
  }
2315
2428
 
2316
- class JSONfn {
2317
- static parse(text) {
2318
- return JSON.parse(text, JSONfn.reviver);
2319
- }
2320
- static stringify(obj) {
2321
- return JSON.stringify(obj, JSONfn.replacer);
2322
- }
2323
- static reviver(key, value) {
2324
- const iso8061 = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:.\d+)?(?:Z|[+-]\d\d:\d\d)$/;
2325
- if (typeof value !== "string")
2326
- return value;
2327
- if (value.length < 8) {
2328
- return value;
2329
- }
2330
- if (value.match(iso8061)) {
2331
- return new Date(value);
2332
- }
2333
- const prefix = value.substring(0, 8);
2334
- if (prefix === "function") {
2335
- return new Function(`return ${value}`)();
2336
- }
2337
- if (prefix === "_NuFrRa_") {
2338
- return new Function(`return ${value.slice(8)}`)();
2339
- }
2340
- if (prefix === "_PxEgEr_") {
2341
- return new Function(`return ${value.slice(8)}`)();
2342
- }
2343
- return value;
2344
- }
2345
- static replacer(key, value) {
2346
- if (value instanceof Function || typeof value === "function") {
2347
- const fnBody = value.toString();
2348
- if (fnBody.length < 8 || fnBody.substring(0, 8) !== "function") {
2349
- // this is ES6 Arrow Function
2350
- return "_NuFrRa_" + fnBody;
2351
- }
2352
- return fnBody;
2353
- }
2354
- if (value instanceof RegExp) {
2355
- return "_PxEgEr_" + value;
2356
- }
2357
- return value;
2358
- }
2359
- }
2360
-
2361
2429
  class LoaderUtils {
2362
2430
  static { this.promises = {}; }
2363
2431
  static loadScript(src, async = false, type = "text/javascript", parent) {
@@ -2437,21 +2505,6 @@ function getRoot(elem) {
2437
2505
  const root = elem?.getRootNode();
2438
2506
  return root || document;
2439
2507
  }
2440
- /**
2441
- * Returns a hash code from anything
2442
- * @param {string} obj The object to hash.
2443
- * @return {number} A 32bit integer
2444
- */
2445
- function hashCode(obj) {
2446
- const str = typeof obj === "string" ? obj : JSON.stringify(obj);
2447
- let hash = 0;
2448
- for (let i = 0, len = str.length; i < len; i++) {
2449
- const chr = str.charCodeAt(i);
2450
- hash = (hash << 5) - hash + chr;
2451
- hash |= 0; // Convert to 32bit integer
2452
- }
2453
- return hash;
2454
- }
2455
2508
  function switchClass(elem, className, status) {
2456
2509
  if (!elem?.classList)
2457
2510
  return;
@@ -3132,7 +3185,7 @@ class RequestBag {
3132
3185
  this.params = {};
3133
3186
  }
3134
3187
  makeHeaders(headersObj, withCredentials = true) {
3135
- const source = headersObj instanceof HttpHeaders ? this.convertHeaders(headersObj) : headersObj || {};
3188
+ const source = this.convertHeaders(headersObj);
3136
3189
  const headers = Object.assign({}, this.source?.headers || {}, this.headers, source);
3137
3190
  const authHeader = headers["Authorization"] || "";
3138
3191
  if (!withCredentials && !authHeader.startsWith("Bearer")) {
@@ -3141,7 +3194,8 @@ class RequestBag {
3141
3194
  return new HttpHeaders(headers);
3142
3195
  }
3143
3196
  makeParams(paramsObj) {
3144
- const params = Object.assign({}, this.source?.params || {}, this.params, paramsObj);
3197
+ const source = this.convertParams(paramsObj);
3198
+ const params = Object.assign({}, this.source?.params || {}, this.params, source);
3145
3199
  return new HttpParams({
3146
3200
  encoder: new HttpUrlEncodingCodec(),
3147
3201
  fromObject: Object.keys(params || {}).reduce((result, key) => {
@@ -3169,10 +3223,22 @@ class RequestBag {
3169
3223
  this.params[name] = value;
3170
3224
  }
3171
3225
  convertHeaders(headers) {
3172
- return headers.keys().reduce((res, key) => {
3173
- res[key] = headers.getAll(key);
3174
- return res;
3175
- }, {});
3226
+ if (headers instanceof HttpHeaders) {
3227
+ return headers.keys().reduce((res, key) => {
3228
+ res[key] = headers.getAll(key);
3229
+ return res;
3230
+ }, {});
3231
+ }
3232
+ return headers || {};
3233
+ }
3234
+ convertParams(params) {
3235
+ if (params instanceof HttpParams) {
3236
+ return params.keys().reduce((res, key) => {
3237
+ res[key] = params.getAll(key);
3238
+ return res;
3239
+ }, {});
3240
+ }
3241
+ return params || {};
3176
3242
  }
3177
3243
  }
3178
3244
 
@@ -3445,10 +3511,20 @@ class BaseHttpService {
3445
3511
  toastError(message, issueContext, reason, options) {
3446
3512
  this.toaster.warning(message, { issueContext, reason, options });
3447
3513
  }
3514
+ makeCacheKey(url, read, options) {
3515
+ const headers = this.bag.convertHeaders(options?.headers);
3516
+ const params = this.bag.convertParams(options?.params);
3517
+ const hash = md5({ url, read, options: {
3518
+ ...options,
3519
+ headers,
3520
+ params
3521
+ } });
3522
+ return `request-${hash}`;
3523
+ }
3448
3524
  toPromise(url, requestOptions, listener) {
3449
3525
  const { cache, read, ...options } = requestOptions;
3450
3526
  const absoluteUrl = this.absoluteUrl(url, options);
3451
- const cacheKey = `request-${ObjectUtils.hashCode(absoluteUrl)}-${ObjectUtils.hashCode(options)}`;
3527
+ const cacheKey = this.makeCacheKey(absoluteUrl, read, requestOptions);
3452
3528
  const issueContext = { url: absoluteUrl };
3453
3529
  return this.caches.use(`${cacheKey}-${read}`, async () => {
3454
3530
  const response = await this.caches.use(cacheKey, () => new HttpPromise(response => {
@@ -3887,7 +3963,7 @@ class ErrorHandlerService extends ErrorHandler {
3887
3963
  }
3888
3964
  if (!this.universal || this.universal.isServer)
3889
3965
  return;
3890
- const key = hashCode(`${error.message} ${error.stack}`);
3966
+ const key = md5(`${error.message} ${error.stack}`);
3891
3967
  if (this.errorMap[key] && this.errorMap[key].getTime() > date.getTime() - 5000)
3892
3968
  return;
3893
3969
  this.errorMap[key] = date;
@@ -9386,5 +9462,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
9386
9462
  * Generated bundle index. Do not edit.
9387
9463
  */
9388
9464
 
9389
- export { API_SERVICE, APP_BASE_URL, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AsyncMethodTargetDirective, AuthGuard, BASE_CONFIG, BUTTON_TYPE, BackgroundDirective, BaseDialogService, BaseHttpClient, BaseHttpService, BaseToasterService, BtnComponent, BtnDefaultComponent, CONFIG_SERVICE, CacheService, CanvasColor, CanvasUtils, ChipsComponent, ChunkPipe, Circle, CloseBtnComponent, ComponentLoaderDirective, ComponentLoaderService, ConfigService, DIALOG_SERVICE, DateUtils, DragDropEventPlugin, DropListComponent, DropdownBoxComponent, DropdownContentDirective, DropdownDirective, DropdownToggleDirective, DynamicTableComponent, DynamicTableTemplateDirective, EPSILON, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExclusionsRenderer, ExtraItemPropertiesPipe, FactoryDependencies, FakeModuleComponent, FileSystemEntry, FileUtils, FilterPipe, FindPipe, ForbiddenZone, FormatNumberPipe, FormatterService, GenericValue, GetOffsetPipe, GetTypePipe, GetValuePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, ICON_MAP, ICON_SERVICE, ICON_TYPE, IConfiguration, IconComponent, IconDefaultComponent, IconDirective, IconService, IncludesPipe, Initializer, InteractiveCanvasComponent, InteractiveCircleComponent, InteractiveItemComponent, InteractiveRectComponent, IsTypePipe, JSONfn, JoinPipe, KeysPipe, LANGUAGE_SERVICE, LanguageService, LoaderUtils, LocalHttpService, MapPipe, MathUtils, MaxPipe, MinPipe, NgxTemplateOutletDirective, NgxUtilsModule, OPTIONS_TOKEN, ObjectType, ObjectUtils, ObservableUtils, OpenApiService, Oval, PROMISE_SERVICE, PaginationDirective, PaginationItemContext, PaginationItemDirective, PaginationMenuComponent, Point, PopPipe, PromiseService, RESIZE_DELAY, RESIZE_STRATEGY, ROOT_ELEMENT, Rect, ReducePipe, ReflectUtils, RemapPipe, ReplacePipe, RequestBag, ResizeEventPlugin, ResourceIfContext, ResourceIfDirective, ReversePipe, RoundPipe, RulerCanvasRenderer, SCRIPT_PARAMS, STATIC_SCHEMAS, SafeHtmlPipe, ScrollEventPlugin, SetUtils, ShiftPipe, SocketClient, SocketService, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, SyncAsyncPipe, TOASTER_SERVICE, TabsComponent, TabsItemDirective, TabsTemplateDirective, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, UploadComponent, ValuedPromise, ValuesPipe, addPts, cachedFactory, cancelablePromise, checkTransitions, clamp, computedPrevious, createTypedProvider, cssStyles, cssVariables, distance, distanceSq, dividePts, dotProduct, ensurePoint, getComponentDef, getCssVariables, getRoot, gjkDistance, gjkIntersection, hashCode, impatientPromise, injectOptions, isBrowser, isPoint, lengthOfPt, lerpPts, multiplyPts, negatePt, normalizePt, normalizeRange, overflow, parseSelector, perpendicular, provideEntryComponents, provideOptions, provideWithOptions, rotateDeg, rotateRad, selectorMatchesList, subPts, svgToDataUri, switchClass, toDegrees, toRadians, tripleProduct };
9465
+ export { API_SERVICE, APP_BASE_URL, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AsyncMethodTargetDirective, AuthGuard, BASE_CONFIG, BUTTON_TYPE, BackgroundDirective, BaseDialogService, BaseHttpClient, BaseHttpService, BaseToasterService, BtnComponent, BtnDefaultComponent, CONFIG_SERVICE, CacheService, CanvasColor, CanvasUtils, ChipsComponent, ChunkPipe, Circle, CloseBtnComponent, ComponentLoaderDirective, ComponentLoaderService, ConfigService, DIALOG_SERVICE, DateUtils, DragDropEventPlugin, DropListComponent, DropdownBoxComponent, DropdownContentDirective, DropdownDirective, DropdownToggleDirective, DynamicTableComponent, DynamicTableTemplateDirective, EPSILON, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExclusionsRenderer, ExtraItemPropertiesPipe, FactoryDependencies, FakeModuleComponent, FileSystemEntry, FileUtils, FilterPipe, FindPipe, ForbiddenZone, FormatNumberPipe, FormatterService, GenericValue, GetOffsetPipe, GetTypePipe, GetValuePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, ICON_MAP, ICON_SERVICE, ICON_TYPE, IConfiguration, IconComponent, IconDefaultComponent, IconDirective, IconService, IncludesPipe, Initializer, InteractiveCanvasComponent, InteractiveCircleComponent, InteractiveItemComponent, InteractiveRectComponent, IsTypePipe, JoinPipe, KeysPipe, LANGUAGE_SERVICE, LanguageService, LoaderUtils, LocalHttpService, MapPipe, MathUtils, MaxPipe, MinPipe, NgxTemplateOutletDirective, NgxUtilsModule, OPTIONS_TOKEN, ObjectType, ObjectUtils, ObservableUtils, OpenApiService, Oval, PROMISE_SERVICE, PaginationDirective, PaginationItemContext, PaginationItemDirective, PaginationMenuComponent, Point, PopPipe, PromiseService, RESIZE_DELAY, RESIZE_STRATEGY, ROOT_ELEMENT, Rect, ReducePipe, ReflectUtils, RemapPipe, ReplacePipe, RequestBag, ResizeEventPlugin, ResourceIfContext, ResourceIfDirective, ReversePipe, RoundPipe, RulerCanvasRenderer, SCRIPT_PARAMS, STATIC_SCHEMAS, SafeHtmlPipe, ScrollEventPlugin, SetUtils, ShiftPipe, SocketClient, SocketService, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, SyncAsyncPipe, TOASTER_SERVICE, TabsComponent, TabsItemDirective, TabsTemplateDirective, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, UploadComponent, ValuedPromise, ValuesPipe, addPts, cachedFactory, cancelablePromise, checkTransitions, clamp, computedPrevious, createTypedProvider, cssStyles, cssVariables, distance, distanceSq, dividePts, dotProduct, ensurePoint, getComponentDef, getCssVariables, getRoot, gjkDistance, gjkIntersection, impatientPromise, injectOptions, isBrowser, isPoint, lengthOfPt, lerpPts, md5, multiplyPts, negatePt, normalizePt, normalizeRange, overflow, parseSelector, perpendicular, provideEntryComponents, provideOptions, provideWithOptions, rotateDeg, rotateRad, selectorMatchesList, stringify, subPts, svgToDataUri, switchClass, toDegrees, toRadians, tripleProduct };
9390
9466
  //# sourceMappingURL=stemy-ngx-utils.mjs.map