@stemy/ngx-utils 19.7.22 → 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';
@@ -367,7 +367,7 @@ class ObjectUtils {
367
367
  return (hasBlob && value instanceof Blob) || (hasFile && value instanceof File);
368
368
  }
369
369
  static isBoolean(value) {
370
- return typeof (value) == typeof (true);
370
+ return value === true || value === false;
371
371
  }
372
372
  static isNumber(value) {
373
373
  if (typeof value !== "number")
@@ -1465,6 +1465,132 @@ class CanvasUtils {
1465
1465
  }
1466
1466
  }
1467
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
+
1468
1594
  class DateUtils {
1469
1595
  static isHoliday(date) {
1470
1596
  return DateTime.fromJSDate(date).isWeekend;
@@ -2300,51 +2426,6 @@ class Initializer {
2300
2426
  }
2301
2427
  }
2302
2428
 
2303
- class JSONfn {
2304
- static parse(text) {
2305
- return JSON.parse(text, JSONfn.reviver);
2306
- }
2307
- static stringify(obj) {
2308
- return JSON.stringify(obj, JSONfn.replacer);
2309
- }
2310
- static reviver(key, value) {
2311
- const iso8061 = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:.\d+)?(?:Z|[+-]\d\d:\d\d)$/;
2312
- if (typeof value !== "string")
2313
- return value;
2314
- if (value.length < 8) {
2315
- return value;
2316
- }
2317
- if (value.match(iso8061)) {
2318
- return new Date(value);
2319
- }
2320
- const prefix = value.substring(0, 8);
2321
- if (prefix === "function") {
2322
- return new Function(`return ${value}`)();
2323
- }
2324
- if (prefix === "_NuFrRa_") {
2325
- return new Function(`return ${value.slice(8)}`)();
2326
- }
2327
- if (prefix === "_PxEgEr_") {
2328
- return new Function(`return ${value.slice(8)}`)();
2329
- }
2330
- return value;
2331
- }
2332
- static replacer(key, value) {
2333
- if (value instanceof Function || typeof value === "function") {
2334
- const fnBody = value.toString();
2335
- if (fnBody.length < 8 || fnBody.substring(0, 8) !== "function") {
2336
- // this is ES6 Arrow Function
2337
- return "_NuFrRa_" + fnBody;
2338
- }
2339
- return fnBody;
2340
- }
2341
- if (value instanceof RegExp) {
2342
- return "_PxEgEr_" + value;
2343
- }
2344
- return value;
2345
- }
2346
- }
2347
-
2348
2429
  class LoaderUtils {
2349
2430
  static { this.promises = {}; }
2350
2431
  static loadScript(src, async = false, type = "text/javascript", parent) {
@@ -2424,21 +2505,6 @@ function getRoot(elem) {
2424
2505
  const root = elem?.getRootNode();
2425
2506
  return root || document;
2426
2507
  }
2427
- /**
2428
- * Returns a hash code from anything
2429
- * @param {string} obj The object to hash.
2430
- * @return {number} A 32bit integer
2431
- */
2432
- function hashCode(obj) {
2433
- const str = typeof obj === "string" ? obj : JSON.stringify(obj);
2434
- let hash = 0;
2435
- for (let i = 0, len = str.length; i < len; i++) {
2436
- const chr = str.charCodeAt(i);
2437
- hash = (hash << 5) - hash + chr;
2438
- hash |= 0; // Convert to 32bit integer
2439
- }
2440
- return hash;
2441
- }
2442
2508
  function switchClass(elem, className, status) {
2443
2509
  if (!elem?.classList)
2444
2510
  return;
@@ -3119,7 +3185,7 @@ class RequestBag {
3119
3185
  this.params = {};
3120
3186
  }
3121
3187
  makeHeaders(headersObj, withCredentials = true) {
3122
- const source = headersObj instanceof HttpHeaders ? this.convertHeaders(headersObj) : headersObj || {};
3188
+ const source = this.convertHeaders(headersObj);
3123
3189
  const headers = Object.assign({}, this.source?.headers || {}, this.headers, source);
3124
3190
  const authHeader = headers["Authorization"] || "";
3125
3191
  if (!withCredentials && !authHeader.startsWith("Bearer")) {
@@ -3128,7 +3194,8 @@ class RequestBag {
3128
3194
  return new HttpHeaders(headers);
3129
3195
  }
3130
3196
  makeParams(paramsObj) {
3131
- const params = Object.assign({}, this.params?.headers || {}, this.params, paramsObj);
3197
+ const source = this.convertParams(paramsObj);
3198
+ const params = Object.assign({}, this.source?.params || {}, this.params, source);
3132
3199
  return new HttpParams({
3133
3200
  encoder: new HttpUrlEncodingCodec(),
3134
3201
  fromObject: Object.keys(params || {}).reduce((result, key) => {
@@ -3156,10 +3223,22 @@ class RequestBag {
3156
3223
  this.params[name] = value;
3157
3224
  }
3158
3225
  convertHeaders(headers) {
3159
- return headers.keys().reduce((res, key) => {
3160
- res[key] = headers.getAll(key);
3161
- return res;
3162
- }, {});
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 || {};
3163
3242
  }
3164
3243
  }
3165
3244
 
@@ -3183,6 +3262,9 @@ class BaseHttpClient extends HttpClient {
3183
3262
  setParam(name, value) {
3184
3263
  this.bag.setParam(name, value);
3185
3264
  }
3265
+ setExtraRequestParam(name, value) {
3266
+ this.bag.setParam(name, value);
3267
+ }
3186
3268
  makeHeaders() {
3187
3269
  return this.bag.makeHeaders();
3188
3270
  }
@@ -3429,10 +3511,20 @@ class BaseHttpService {
3429
3511
  toastError(message, issueContext, reason, options) {
3430
3512
  this.toaster.warning(message, { issueContext, reason, options });
3431
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
+ }
3432
3524
  toPromise(url, requestOptions, listener) {
3433
3525
  const { cache, read, ...options } = requestOptions;
3434
3526
  const absoluteUrl = this.absoluteUrl(url, options);
3435
- const cacheKey = `request-${hashCode(absoluteUrl)}-${hashCode(options)}`;
3527
+ const cacheKey = this.makeCacheKey(absoluteUrl, read, requestOptions);
3436
3528
  const issueContext = { url: absoluteUrl };
3437
3529
  return this.caches.use(`${cacheKey}-${read}`, async () => {
3438
3530
  const response = await this.caches.use(cacheKey, () => new HttpPromise(response => {
@@ -3871,7 +3963,7 @@ class ErrorHandlerService extends ErrorHandler {
3871
3963
  }
3872
3964
  if (!this.universal || this.universal.isServer)
3873
3965
  return;
3874
- const key = hashCode(`${error.message} ${error.stack}`);
3966
+ const key = md5(`${error.message} ${error.stack}`);
3875
3967
  if (this.errorMap[key] && this.errorMap[key].getTime() > date.getTime() - 5000)
3876
3968
  return;
3877
3969
  this.errorMap[key] = date;
@@ -9370,5 +9462,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
9370
9462
  * Generated bundle index. Do not edit.
9371
9463
  */
9372
9464
 
9373
- 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 };
9374
9466
  //# sourceMappingURL=stemy-ngx-utils.mjs.map