@react-fabric/utilities 1.0.0-beta.4 → 1.0.0-beta.41

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.
@@ -1,8 +1,31 @@
1
1
  'use strict';
2
2
 
3
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
3
  var _isType = require('./_isType.js');
5
4
 
5
+ /*
6
+ * React Fabric
7
+ * @version: 1.0.0
8
+ *
9
+ *
10
+ * The MIT License (MIT)
11
+ * Copyright (c) 2024 Adarsh Pastakia
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
14
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
15
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
16
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
17
+ * subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
20
+ * portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
23
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
6
29
  /** ***************** latin-ascii conversions *******************/
7
30
  var conversions = {
8
31
  AE: "Æ|Ǽ",
@@ -63,12 +86,9 @@ var conversions = {
63
86
  */
64
87
  var ascii = function ascii(str) {
65
88
  if (_isType.isEmpty(str)) return "";
66
- Object.entries(conversions).forEach(function (_ref) {
67
- var _ref2 = _slicedToArray(_ref, 2),
68
- a = _ref2[0],
69
- l = _ref2[1];
70
- var re = new RegExp(l, "g");
71
- str = "".concat(str).replace(re, a);
89
+ Object.entries(conversions).forEach(function (entry) {
90
+ var re = new RegExp(entry[1], "g");
91
+ str = "".concat(str).replace(re, entry[0]);
72
92
  });
73
93
  return str;
74
94
  };
@@ -33,8 +33,7 @@ var dedupe = function dedupe(list, key) {
33
33
  return Array.from(new Set(filtered).values());
34
34
  }
35
35
  return Array.from(new Map(filtered.map(function (obj) {
36
- var _obj$key;
37
- return [(_obj$key = obj[key]) !== null && _obj$key !== void 0 ? _obj$key : obj, obj];
36
+ return [obj[key], obj];
38
37
  })).values());
39
38
  };
40
39
  var flatten = function flatten(list) {
@@ -36,7 +36,7 @@ var _get = function _get(hit, field) {
36
36
  if (_isType.isNil(field)) {
37
37
  return hit;
38
38
  }
39
- if (_isType.isObject(hit)) {
39
+ if (_isType.isObject(hit) || _isType.isArray(hit)) {
40
40
  /** ***************** return value if object.property is not empty *******************/
41
41
  if (!_isType.isNil(hit[field])) {
42
42
  return hit[field];
package/dist/cjs/_hash.js CHANGED
@@ -49,7 +49,7 @@ var hash = function hash(str) {
49
49
  * @internal
50
50
  */
51
51
  var shortHash = function shortHash() {
52
- return (new Date().getTime() + Math.trunc(Math.random() * 1000)).toString(36);
52
+ return (new Date().getTime() * Math.random()).toString(36);
53
53
  };
54
54
 
55
55
  /**
@@ -45,8 +45,8 @@ var getImageColorset = function getImageColorset(el) {
45
45
  transparent = true;
46
46
  continue;
47
47
  }
48
- if (transparent && data[x - 1] === 1) {
49
- continue;
48
+ if (data[x + 3] < 1) {
49
+ transparent = true;
50
50
  }
51
51
  r = data[x];
52
52
  g = data[x + 1];
@@ -1,8 +1,31 @@
1
1
  'use client';
2
2
 
3
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
3
  import { isEmpty } from './_isType.js';
5
4
 
5
+ /*
6
+ * React Fabric
7
+ * @version: 1.0.0
8
+ *
9
+ *
10
+ * The MIT License (MIT)
11
+ * Copyright (c) 2024 Adarsh Pastakia
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
14
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
15
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
16
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
17
+ * subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
20
+ * portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
23
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+
6
29
  /** ***************** latin-ascii conversions *******************/
7
30
  var conversions = {
8
31
  AE: "Æ|Ǽ",
@@ -63,12 +86,9 @@ var conversions = {
63
86
  */
64
87
  var ascii = function ascii(str) {
65
88
  if (isEmpty(str)) return "";
66
- Object.entries(conversions).forEach(function (_ref) {
67
- var _ref2 = _slicedToArray(_ref, 2),
68
- a = _ref2[0],
69
- l = _ref2[1];
70
- var re = new RegExp(l, "g");
71
- str = "".concat(str).replace(re, a);
89
+ Object.entries(conversions).forEach(function (entry) {
90
+ var re = new RegExp(entry[1], "g");
91
+ str = "".concat(str).replace(re, entry[0]);
72
92
  });
73
93
  return str;
74
94
  };
@@ -33,8 +33,7 @@ var dedupe = function dedupe(list, key) {
33
33
  return Array.from(new Set(filtered).values());
34
34
  }
35
35
  return Array.from(new Map(filtered.map(function (obj) {
36
- var _obj$key;
37
- return [(_obj$key = obj[key]) !== null && _obj$key !== void 0 ? _obj$key : obj, obj];
36
+ return [obj[key], obj];
38
37
  })).values());
39
38
  };
40
39
  var flatten = function flatten(list) {
@@ -36,7 +36,7 @@ var _get = function _get(hit, field) {
36
36
  if (isNil(field)) {
37
37
  return hit;
38
38
  }
39
- if (isObject(hit)) {
39
+ if (isObject(hit) || isArray(hit)) {
40
40
  /** ***************** return value if object.property is not empty *******************/
41
41
  if (!isNil(hit[field])) {
42
42
  return hit[field];
package/dist/esm/_hash.js CHANGED
@@ -49,7 +49,7 @@ var hash = function hash(str) {
49
49
  * @internal
50
50
  */
51
51
  var shortHash = function shortHash() {
52
- return (new Date().getTime() + Math.trunc(Math.random() * 1000)).toString(36);
52
+ return (new Date().getTime() * Math.random()).toString(36);
53
53
  };
54
54
 
55
55
  /**
@@ -45,8 +45,8 @@ var getImageColorset = function getImageColorset(el) {
45
45
  transparent = true;
46
46
  continue;
47
47
  }
48
- if (transparent && data[x - 1] === 1) {
49
- continue;
48
+ if (data[x + 3] < 1) {
49
+ transparent = true;
50
50
  }
51
51
  r = data[x];
52
52
  g = data[x + 1];
@@ -1,6 +1,6 @@
1
1
  export declare const isUndefined: (value: AnyObject) => value is undefined;
2
2
  export declare const isNull: (value: AnyObject) => value is null;
3
- export declare const isNil: (val: AnyObject) => val is undefined;
3
+ export declare const isNil: (val: AnyObject) => val is null | undefined;
4
4
  export declare const isEmpty: (val: AnyObject) => val is undefined;
5
5
  export declare const isObject: (val: AnyObject) => val is KeyValue<any>;
6
6
  export declare const isArray: <T = any>(val: AnyObject) => val is T[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/utilities",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.41",
4
4
  "description": "RUF: Utility package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -44,5 +44,5 @@
44
44
  "node": ">=18.12.0",
45
45
  "npm": ">=8.19.0"
46
46
  },
47
- "gitHead": "47b0aede19252a3a3ef8df75c08a21caabde8100"
47
+ "gitHead": "bc737416d3c6a217a6b8c47291c3975a22722d80"
48
48
  }
package/src/_ascii.ts CHANGED
@@ -85,9 +85,9 @@ const conversions = {
85
85
  */
86
86
  export const ascii = (str: string) => {
87
87
  if (isEmpty(str)) return "";
88
- Object.entries(conversions).forEach(([a, l]) => {
89
- const re = new RegExp(l, "g");
90
- str = `${str}`.replace(re, a);
88
+ Object.entries(conversions).forEach((entry) => {
89
+ const re = new RegExp(entry[1], "g");
90
+ str = `${str}`.replace(re, entry[0]);
91
91
  });
92
92
  return str;
93
93
  };
package/src/_dedupe.ts CHANGED
@@ -29,9 +29,7 @@ export const dedupe = (list: any[], key?: string) => {
29
29
  return Array.from(new Set(filtered).values());
30
30
  }
31
31
 
32
- return Array.from(
33
- new Map(filtered.map((obj) => [obj[key] ?? obj, obj])).values(),
34
- );
32
+ return Array.from(new Map(filtered.map((obj) => [obj[key], obj])).values());
35
33
  };
36
34
 
37
35
  export const flatten = (list: any[]) => {
package/src/_getByPath.ts CHANGED
@@ -35,10 +35,10 @@ const _get = (hit: any, field: string): any => {
35
35
  return hit;
36
36
  }
37
37
 
38
- if (isObject(hit)) {
38
+ if (isObject(hit) || isArray(hit)) {
39
39
  /** ***************** return value if object.property is not empty *******************/
40
- if (!isNil(hit[field])) {
41
- return hit[field];
40
+ if (!isNil(hit[field as any])) {
41
+ return hit[field as any];
42
42
  }
43
43
 
44
44
  /** ***************** if property name contains `.` separator split to multiple property names *******************/
package/src/_hash.ts CHANGED
@@ -46,7 +46,7 @@ export const hash = (str: string) => {
46
46
  * @internal
47
47
  */
48
48
  export const shortHash = () => {
49
- return (new Date().getTime() + Math.trunc(Math.random() * 1000)).toString(36);
49
+ return (new Date().getTime() * Math.random()).toString(36);
50
50
  };
51
51
 
52
52
  /**
package/src/_isType.ts CHANGED
@@ -29,7 +29,7 @@ export const isNull = (value: AnyObject): value is null => {
29
29
  return value === null;
30
30
  };
31
31
 
32
- export const isNil = (val: AnyObject): val is undefined => {
32
+ export const isNil = (val: AnyObject): val is null | undefined => {
33
33
  return val === undefined || val === null;
34
34
  };
35
35
  export const isEmpty = (val: AnyObject): val is undefined => {
@@ -56,8 +56,8 @@ export const getImageColorset = (el: HTMLImageElement) => {
56
56
  transparent = true;
57
57
  continue;
58
58
  }
59
- if (transparent && data[x - 1] === 1) {
60
- continue;
59
+ if (data[x + 3] < 1) {
60
+ transparent = true;
61
61
  }
62
62
  r = data[x];
63
63
  g = data[x + 1];