@fluixi/utils 1.0.0-alpha.82 → 1.0.0-alpha.84

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.
Files changed (129) hide show
  1. package/dist/index.cjs +2858 -1
  2. package/dist/index.mjs +2838 -1
  3. package/dist/lib/array/advanced.cjs +2227 -1
  4. package/dist/lib/array/advanced.mjs +2204 -1
  5. package/dist/lib/array/array.cjs +57 -1
  6. package/dist/lib/array/array.mjs +36 -1
  7. package/dist/lib/array/index.cjs +2344 -1
  8. package/dist/lib/array/index.mjs +2322 -1
  9. package/dist/lib/array/utils.cjs +103 -1
  10. package/dist/lib/array/utils.mjs +82 -1
  11. package/dist/lib/color/color.cjs +2190 -1
  12. package/dist/lib/color/color.mjs +2167 -1
  13. package/dist/lib/color/constants.cjs +380 -1
  14. package/dist/lib/color/constants.mjs +359 -1
  15. package/dist/lib/color/conversions.cjs +629 -1
  16. package/dist/lib/color/conversions.mjs +608 -1
  17. package/dist/lib/color/helpers.cjs +2534 -1
  18. package/dist/lib/color/helpers.mjs +2511 -1
  19. package/dist/lib/color/index.cjs +2641 -1
  20. package/dist/lib/color/index.mjs +2619 -1
  21. package/dist/lib/color/types.cjs +18 -1
  22. package/dist/lib/color/utils.cjs +962 -1
  23. package/dist/lib/color/utils.mjs +939 -1
  24. package/dist/lib/compare/comparators.cjs +171 -1
  25. package/dist/lib/compare/comparators.mjs +150 -1
  26. package/dist/lib/compare/index.cjs +172 -1
  27. package/dist/lib/compare/index.mjs +152 -1
  28. package/dist/lib/crypto/hash.cjs +83 -1
  29. package/dist/lib/crypto/hash.mjs +62 -1
  30. package/dist/lib/crypto/index.cjs +85 -1
  31. package/dist/lib/crypto/index.mjs +62 -1
  32. package/dist/lib/dom/events.cjs +40 -1
  33. package/dist/lib/dom/events.mjs +19 -1
  34. package/dist/lib/dom/index.cjs +78 -1
  35. package/dist/lib/dom/index.mjs +56 -1
  36. package/dist/lib/dom/utils.cjs +57 -1
  37. package/dist/lib/dom/utils.mjs +36 -1
  38. package/dist/lib/functions/functions.cjs +366 -1
  39. package/dist/lib/functions/functions.mjs +345 -1
  40. package/dist/lib/functions/index.cjs +369 -1
  41. package/dist/lib/functions/index.mjs +347 -1
  42. package/dist/lib/functions/types.cjs +18 -1
  43. package/dist/lib/helpers.cjs +78 -1
  44. package/dist/lib/helpers.mjs +59 -1
  45. package/dist/lib/index.cjs +2857 -1
  46. package/dist/lib/index.mjs +2836 -1
  47. package/dist/lib/maths/constants.cjs +70 -1
  48. package/dist/lib/maths/constants.mjs +50 -1
  49. package/dist/lib/maths/fn/advanced.cjs +231 -1
  50. package/dist/lib/maths/fn/advanced.mjs +208 -1
  51. package/dist/lib/maths/fn/basic.cjs +212 -1
  52. package/dist/lib/maths/fn/basic.mjs +191 -1
  53. package/dist/lib/maths/fn/complex.cjs +268 -1
  54. package/dist/lib/maths/fn/complex.mjs +247 -1
  55. package/dist/lib/maths/fn/index.cjs +877 -1
  56. package/dist/lib/maths/fn/index.mjs +855 -1
  57. package/dist/lib/maths/fn/trigo.cjs +179 -1
  58. package/dist/lib/maths/fn/trigo.mjs +156 -1
  59. package/dist/lib/maths/fn/vector.cjs +728 -1
  60. package/dist/lib/maths/fn/vector.mjs +707 -1
  61. package/dist/lib/maths/formatter.cjs +61 -1
  62. package/dist/lib/maths/formatter.mjs +40 -1
  63. package/dist/lib/maths/guards.cjs +164 -1
  64. package/dist/lib/maths/guards.mjs +144 -1
  65. package/dist/lib/maths/index.cjs +1152 -1
  66. package/dist/lib/maths/index.mjs +1130 -1
  67. package/dist/lib/maths/parser.cjs +75 -1
  68. package/dist/lib/maths/parser.mjs +54 -1
  69. package/dist/lib/maths/random.cjs +49 -1
  70. package/dist/lib/maths/random.mjs +28 -1
  71. package/dist/lib/maths/types/advanced.cjs +18 -1
  72. package/dist/lib/maths/types/basic.cjs +18 -1
  73. package/dist/lib/maths/types/index.cjs +19 -1
  74. package/dist/lib/maths/types/index.mjs +1 -0
  75. package/dist/lib/maths/types/negative.cjs +18 -1
  76. package/dist/lib/maths/types/operations.cjs +18 -1
  77. package/dist/lib/object/clone.cjs +88 -1
  78. package/dist/lib/object/clone.mjs +65 -1
  79. package/dist/lib/object/diff.cjs +573 -1
  80. package/dist/lib/object/diff.mjs +550 -1
  81. package/dist/lib/object/getter-setter.cjs +2351 -1
  82. package/dist/lib/object/getter-setter.mjs +2330 -1
  83. package/dist/lib/object/index.cjs +3956 -6
  84. package/dist/lib/object/index.mjs +3936 -6
  85. package/dist/lib/object/merge.cjs +1029 -1
  86. package/dist/lib/object/merge.mjs +1006 -1
  87. package/dist/lib/object/object.cjs +280 -1
  88. package/dist/lib/object/object.mjs +257 -1
  89. package/dist/lib/object/omit.cjs +2022 -1
  90. package/dist/lib/object/omit.mjs +1999 -1
  91. package/dist/lib/object/reconcile.cjs +126 -1
  92. package/dist/lib/object/reconcile.mjs +105 -1
  93. package/dist/lib/object/selector.cjs +303 -1
  94. package/dist/lib/object/selector.mjs +282 -1
  95. package/dist/lib/object/sort.cjs +209 -1
  96. package/dist/lib/object/sort.mjs +186 -1
  97. package/dist/lib/object/transform.cjs +2211 -1
  98. package/dist/lib/object/transform.mjs +2190 -1
  99. package/dist/lib/object/types.cjs +18 -1
  100. package/dist/lib/object/utils.cjs +326 -6
  101. package/dist/lib/object/utils.mjs +305 -6
  102. package/dist/lib/primitive/boolean/boolean.cjs +407 -1
  103. package/dist/lib/primitive/boolean/boolean.mjs +386 -1
  104. package/dist/lib/primitive/boolean/index.cjs +382 -1
  105. package/dist/lib/primitive/boolean/index.mjs +359 -1
  106. package/dist/lib/primitive/boolean/types.cjs +18 -1
  107. package/dist/lib/primitive/date/date.cjs +1126 -1
  108. package/dist/lib/primitive/date/date.mjs +1105 -1
  109. package/dist/lib/primitive/date/index.cjs +1128 -1
  110. package/dist/lib/primitive/date/index.mjs +1105 -1
  111. package/dist/lib/primitive/date/types.cjs +18 -1
  112. package/dist/lib/primitive/index.cjs +2338 -5
  113. package/dist/lib/primitive/index.mjs +2316 -5
  114. package/dist/lib/primitive/string/index.cjs +875 -5
  115. package/dist/lib/primitive/string/index.mjs +852 -5
  116. package/dist/lib/primitive/string/parser-2.cjs +543 -8
  117. package/dist/lib/primitive/string/parser-2.mjs +522 -8
  118. package/dist/lib/primitive/string/parser.cjs +236 -3
  119. package/dist/lib/primitive/string/parser.mjs +215 -3
  120. package/dist/lib/primitive/string/string.cjs +926 -5
  121. package/dist/lib/primitive/string/string.mjs +903 -5
  122. package/dist/lib/primitive/string/types.cjs +18 -1
  123. package/dist/lib/primitive/types.cjs +18 -1
  124. package/dist/lib/url/index.cjs +327 -1
  125. package/dist/lib/url/index.mjs +304 -1
  126. package/dist/lib/url/parser.cjs +325 -1
  127. package/dist/lib/url/parser.mjs +304 -1
  128. package/dist/lib/url/types.cjs +18 -1
  129. package/package.json +5 -5
@@ -1 +1,126 @@
1
- "use strict";var g=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var j=(i,e)=>{for(var r in e)g(i,r,{get:e[r],enumerable:!0})},A=(i,e,r,f)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of w(e))!b.call(i,a)&&a!==r&&g(i,a,{get:()=>e[a],enumerable:!(f=O(e,a))||f.enumerable});return i};var h=i=>A(g({},"__esModule",{value:!0}),i);var v={};j(v,{reconcile:()=>q});module.exports=h(v);function p(i){if(i==null||typeof i!="object")return!1;let e=Object.getPrototypeOf(i);return e===Object.prototype||e===null}function k(i,e,r){return i===e?e:Array.isArray(i)?T(i,Array.isArray(e)?e:[],r):p(i)?m(i,p(e)?e:{},r):i}function T(i,e,r){let{key:f,keepRef:a}=r,u=e.length,o=i.length,s=new Array(u);for(let n=0;n<u;n++)s[n]=e[n];if(f===!1){if(a){for(let l=0;l<o;l++){let R=k(i[l],s[l],r);R!==s[l]&&(e[l]=R)}return u>o&&e.splice(o),e}let n=o!==u,t=new Array(o);for(let l=0;l<o;l++)t[l]=k(i[l],s[l],r),t[l]!==s[l]&&(n=!0);return n?t:e}let d=new Map;for(let n=0;n<u;n++){let t=s[n];t!=null&&typeof t=="object"&&f in t&&d.set(t[f],t)}let y=new Array(o);for(let n=0;n<o;n++){let t=i[n];t!=null&&typeof t=="object"&&f in t?y[n]=k(t,d.get(t[f]),r):y[n]=k(t,s[n],r)}if(a){for(let n=0;n<o;n++)y[n]!==s[n]&&(e[n]=y[n]);return u>o&&e.splice(o),e}let c=o!==u;for(let n=0;!c&&n<o;n++)y[n]!==s[n]&&(c=!0);return c?y:e}function m(i,e,r){let{merge:f,keepRef:a}=r,u=Object.keys(i),o=Object.keys(e),s=Object.create(null);for(let c=0;c<o.length;c++)s[o[c]]=e[o[c]];let d=null,y=()=>(d||(d=a?e:{...s}),d);if(!f)for(let c=0;c<o.length;c++){let n=o[c];n in i||delete y()[n]}for(let c=0;c<u.length;c++){let n=u[c],t=s[n],l=k(i[n],t,r);(l!==t||!(n in s))&&(y()[n]=l)}return d??e}function q(i,e){let r={key:e?.key!==void 0?e.key:"id",merge:e?.merge??!1,keepRef:e?.keepRef??!1};return f=>f==null?i:k(i,f,r)}
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/object/reconcile.ts
21
+ var reconcile_exports = {};
22
+ __export(reconcile_exports, {
23
+ reconcile: () => reconcile
24
+ });
25
+ module.exports = __toCommonJS(reconcile_exports);
26
+ function isPlain(v) {
27
+ if (v == null || typeof v !== "object") return false;
28
+ const p = Object.getPrototypeOf(v);
29
+ return p === Object.prototype || p === null;
30
+ }
31
+ function reconcileValue(next, current, opts) {
32
+ if (next === current) return current;
33
+ if (Array.isArray(next)) return reconcileArr(next, Array.isArray(current) ? current : [], opts);
34
+ if (isPlain(next)) return reconcileObj(next, isPlain(current) ? current : {}, opts);
35
+ return next;
36
+ }
37
+ function reconcileArr(next, current, opts) {
38
+ const { key, keepRef } = opts;
39
+ const curLen = current.length;
40
+ const nextLen = next.length;
41
+ const curItems = new Array(curLen);
42
+ for (let i = 0; i < curLen; i++) curItems[i] = current[i];
43
+ if (key === false) {
44
+ if (keepRef) {
45
+ for (let i = 0; i < nextLen; i++) {
46
+ const rv = reconcileValue(next[i], curItems[i], opts);
47
+ if (rv !== curItems[i]) current[i] = rv;
48
+ }
49
+ if (curLen > nextLen) current.splice(nextLen);
50
+ return current;
51
+ }
52
+ let changed2 = nextLen !== curLen;
53
+ const out = new Array(nextLen);
54
+ for (let i = 0; i < nextLen; i++) {
55
+ out[i] = reconcileValue(next[i], curItems[i], opts);
56
+ if (out[i] !== curItems[i]) changed2 = true;
57
+ }
58
+ return changed2 ? out : current;
59
+ }
60
+ const currentMap = /* @__PURE__ */ new Map();
61
+ for (let i = 0; i < curLen; i++) {
62
+ const item = curItems[i];
63
+ if (item != null && typeof item === "object" && key in item) {
64
+ currentMap.set(item[key], item);
65
+ }
66
+ }
67
+ const resolved = new Array(nextLen);
68
+ for (let i = 0; i < nextLen; i++) {
69
+ const n = next[i];
70
+ if (n != null && typeof n === "object" && key in n) {
71
+ resolved[i] = reconcileValue(n, currentMap.get(n[key]), opts);
72
+ } else {
73
+ resolved[i] = reconcileValue(n, curItems[i], opts);
74
+ }
75
+ }
76
+ if (keepRef) {
77
+ for (let i = 0; i < nextLen; i++) {
78
+ if (resolved[i] !== curItems[i]) current[i] = resolved[i];
79
+ }
80
+ if (curLen > nextLen) current.splice(nextLen);
81
+ return current;
82
+ }
83
+ let changed = nextLen !== curLen;
84
+ for (let i = 0; !changed && i < nextLen; i++) {
85
+ if (resolved[i] !== curItems[i]) changed = true;
86
+ }
87
+ return changed ? resolved : current;
88
+ }
89
+ function reconcileObj(next, current, opts) {
90
+ const { merge, keepRef } = opts;
91
+ const nextKeys = Object.keys(next);
92
+ const currentKeys = Object.keys(current);
93
+ const curValues = /* @__PURE__ */ Object.create(null);
94
+ for (let i = 0; i < currentKeys.length; i++) {
95
+ curValues[currentKeys[i]] = current[currentKeys[i]];
96
+ }
97
+ let out = null;
98
+ const getOut = () => {
99
+ if (!out) out = keepRef ? current : { ...curValues };
100
+ return out;
101
+ };
102
+ if (!merge) {
103
+ for (let i = 0; i < currentKeys.length; i++) {
104
+ const k = currentKeys[i];
105
+ if (!(k in next)) delete getOut()[k];
106
+ }
107
+ }
108
+ for (let i = 0; i < nextKeys.length; i++) {
109
+ const k = nextKeys[i];
110
+ const cv = curValues[k];
111
+ const rv = reconcileValue(next[k], cv, opts);
112
+ if (rv !== cv || !(k in curValues)) getOut()[k] = rv;
113
+ }
114
+ return out ?? current;
115
+ }
116
+ function reconcile(next, options) {
117
+ const opts = {
118
+ key: options?.key !== void 0 ? options.key : "id",
119
+ merge: options?.merge ?? false,
120
+ keepRef: options?.keepRef ?? false
121
+ };
122
+ return (current) => {
123
+ if (current === void 0 || current === null) return next;
124
+ return reconcileValue(next, current, opts);
125
+ };
126
+ }
@@ -1 +1,105 @@
1
- function R(i){if(i==null||typeof i!="object")return!1;let n=Object.getPrototypeOf(i);return n===Object.prototype||n===null}function d(i,n,f){return i===n?n:Array.isArray(i)?p(i,Array.isArray(n)?n:[],f):R(i)?O(i,R(n)?n:{},f):i}function p(i,n,f){let{key:s,keepRef:k}=f,a=n.length,o=i.length,c=new Array(a);for(let e=0;e<a;e++)c[e]=n[e];if(s===!1){if(k){for(let r=0;r<o;r++){let g=d(i[r],c[r],f);g!==c[r]&&(n[r]=g)}return a>o&&n.splice(o),n}let e=o!==a,t=new Array(o);for(let r=0;r<o;r++)t[r]=d(i[r],c[r],f),t[r]!==c[r]&&(e=!0);return e?t:n}let y=new Map;for(let e=0;e<a;e++){let t=c[e];t!=null&&typeof t=="object"&&s in t&&y.set(t[s],t)}let u=new Array(o);for(let e=0;e<o;e++){let t=i[e];t!=null&&typeof t=="object"&&s in t?u[e]=d(t,y.get(t[s]),f):u[e]=d(t,c[e],f)}if(k){for(let e=0;e<o;e++)u[e]!==c[e]&&(n[e]=u[e]);return a>o&&n.splice(o),n}let l=o!==a;for(let e=0;!l&&e<o;e++)u[e]!==c[e]&&(l=!0);return l?u:n}function O(i,n,f){let{merge:s,keepRef:k}=f,a=Object.keys(i),o=Object.keys(n),c=Object.create(null);for(let l=0;l<o.length;l++)c[o[l]]=n[o[l]];let y=null,u=()=>(y||(y=k?n:{...c}),y);if(!s)for(let l=0;l<o.length;l++){let e=o[l];e in i||delete u()[e]}for(let l=0;l<a.length;l++){let e=a[l],t=c[e],r=d(i[e],t,f);(r!==t||!(e in c))&&(u()[e]=r)}return y??n}function w(i,n){let f={key:n?.key!==void 0?n.key:"id",merge:n?.merge??!1,keepRef:n?.keepRef??!1};return s=>s==null?i:d(i,s,f)}export{w as reconcile};
1
+ // src/lib/object/reconcile.ts
2
+ function isPlain(v) {
3
+ if (v == null || typeof v !== "object") return false;
4
+ const p = Object.getPrototypeOf(v);
5
+ return p === Object.prototype || p === null;
6
+ }
7
+ function reconcileValue(next, current, opts) {
8
+ if (next === current) return current;
9
+ if (Array.isArray(next)) return reconcileArr(next, Array.isArray(current) ? current : [], opts);
10
+ if (isPlain(next)) return reconcileObj(next, isPlain(current) ? current : {}, opts);
11
+ return next;
12
+ }
13
+ function reconcileArr(next, current, opts) {
14
+ const { key, keepRef } = opts;
15
+ const curLen = current.length;
16
+ const nextLen = next.length;
17
+ const curItems = new Array(curLen);
18
+ for (let i = 0; i < curLen; i++) curItems[i] = current[i];
19
+ if (key === false) {
20
+ if (keepRef) {
21
+ for (let i = 0; i < nextLen; i++) {
22
+ const rv = reconcileValue(next[i], curItems[i], opts);
23
+ if (rv !== curItems[i]) current[i] = rv;
24
+ }
25
+ if (curLen > nextLen) current.splice(nextLen);
26
+ return current;
27
+ }
28
+ let changed2 = nextLen !== curLen;
29
+ const out = new Array(nextLen);
30
+ for (let i = 0; i < nextLen; i++) {
31
+ out[i] = reconcileValue(next[i], curItems[i], opts);
32
+ if (out[i] !== curItems[i]) changed2 = true;
33
+ }
34
+ return changed2 ? out : current;
35
+ }
36
+ const currentMap = /* @__PURE__ */ new Map();
37
+ for (let i = 0; i < curLen; i++) {
38
+ const item = curItems[i];
39
+ if (item != null && typeof item === "object" && key in item) {
40
+ currentMap.set(item[key], item);
41
+ }
42
+ }
43
+ const resolved = new Array(nextLen);
44
+ for (let i = 0; i < nextLen; i++) {
45
+ const n = next[i];
46
+ if (n != null && typeof n === "object" && key in n) {
47
+ resolved[i] = reconcileValue(n, currentMap.get(n[key]), opts);
48
+ } else {
49
+ resolved[i] = reconcileValue(n, curItems[i], opts);
50
+ }
51
+ }
52
+ if (keepRef) {
53
+ for (let i = 0; i < nextLen; i++) {
54
+ if (resolved[i] !== curItems[i]) current[i] = resolved[i];
55
+ }
56
+ if (curLen > nextLen) current.splice(nextLen);
57
+ return current;
58
+ }
59
+ let changed = nextLen !== curLen;
60
+ for (let i = 0; !changed && i < nextLen; i++) {
61
+ if (resolved[i] !== curItems[i]) changed = true;
62
+ }
63
+ return changed ? resolved : current;
64
+ }
65
+ function reconcileObj(next, current, opts) {
66
+ const { merge, keepRef } = opts;
67
+ const nextKeys = Object.keys(next);
68
+ const currentKeys = Object.keys(current);
69
+ const curValues = /* @__PURE__ */ Object.create(null);
70
+ for (let i = 0; i < currentKeys.length; i++) {
71
+ curValues[currentKeys[i]] = current[currentKeys[i]];
72
+ }
73
+ let out = null;
74
+ const getOut = () => {
75
+ if (!out) out = keepRef ? current : { ...curValues };
76
+ return out;
77
+ };
78
+ if (!merge) {
79
+ for (let i = 0; i < currentKeys.length; i++) {
80
+ const k = currentKeys[i];
81
+ if (!(k in next)) delete getOut()[k];
82
+ }
83
+ }
84
+ for (let i = 0; i < nextKeys.length; i++) {
85
+ const k = nextKeys[i];
86
+ const cv = curValues[k];
87
+ const rv = reconcileValue(next[k], cv, opts);
88
+ if (rv !== cv || !(k in curValues)) getOut()[k] = rv;
89
+ }
90
+ return out ?? current;
91
+ }
92
+ function reconcile(next, options) {
93
+ const opts = {
94
+ key: options?.key !== void 0 ? options.key : "id",
95
+ merge: options?.merge ?? false,
96
+ keepRef: options?.keepRef ?? false
97
+ };
98
+ return (current) => {
99
+ if (current === void 0 || current === null) return next;
100
+ return reconcileValue(next, current, opts);
101
+ };
102
+ }
103
+ export {
104
+ reconcile
105
+ };
@@ -1 +1,303 @@
1
- "use strict";var h=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var k=(e,n)=>{for(var a in n)h(e,a,{get:n[a],enumerable:!0})},I=(e,n,a,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let l of T(n))!x.call(e,l)&&l!==a&&h(e,l,{get:()=>n[l],enumerable:!(i=$(n,l))||i.enumerable});return e};var N=e=>I(h({},"__esModule",{value:!0}),e);var W={};k(W,{createFilterFunction:()=>g,createSelector:()=>E,detectSelectorType:()=>w,parseSelector:()=>v,stringifySelector:()=>A,validateSelector:()=>S});module.exports=N(W);var v=(e,n={})=>{let{type:a="auto",throwOnError:i=!1}=n;if(!e||typeof e!="string")return[];let l=[],s="",o=!1,d=!1,f="",y="",j=0,O=a==="auto"?(t=>t.includes("..")?"descendant":t.includes("[?(")?"filter":t.includes("[:")||t.includes("[0:")?"slice":t.includes("[,")||t.includes("[0,1]")?"union":t.includes("[*]")||t.includes(".*.")?"wildcard":t.includes("[]")?"array-wildcard":t.includes("[")&&t.includes("]")?"bracket":"dot")(e):a,m=t=>{let r=t.trim();if(r==="*"||r==="")return{type:"wildcard",value:r===""?"[]":"*",raw:r===""?"[]":t};if(r==="[]")return{type:"wildcard",value:"[]",raw:t};if(/^-?\d+$/.test(r))return{type:"index",value:parseInt(r,10),raw:t};if(r.includes(":")){let c=r.split(":").map(b=>b.trim()),u=c[0]===""?0:parseInt(c[0],10),p=c[1]===""?1/0:parseInt(c[1],10);if(isNaN(u)||isNaN(p)){if(i)throw new Error(`Invalid slice notation: ${t}`);return{type:"wildcard",value:"*",raw:t}}return{type:"slice",value:[u,p],raw:t}}if(r.includes(",")){let c=r.split(",").map(u=>{let p=parseInt(u.trim(),10);return isNaN(p)?-1:p}).filter(u=>u>=0);if(c.length===0){if(i)throw new Error(`Invalid union notation: ${t}`);return{type:"wildcard",value:"*",raw:t}}return{type:"union",value:c,raw:t}}if(r.startsWith("?(")&&r.endsWith(")")){let c=r.slice(2,-1);try{return{type:"filter",value:g(c),raw:t}}catch(u){if(i)throw u;return{type:"wildcard",value:"*",raw:t}}}return r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'")?{type:"property",value:r.slice(1,-1),raw:t}:{type:"property",value:r,raw:t}};for(let t=0;t<e.length;t++){let r=e[t],c=e[t+1];if((r==='"'||r==="'")&&!d){d=!0,f=r;continue}else if(r===f&&d){d=!1,f="",r==='"'||r==="'"||(o?y+=r:s+=r);continue}if(d){o?y+=r:s+=r;continue}if(r==="["&&!o){s&&(l.push({type:"property",value:s,raw:s}),s=""),o=!0,y="";continue}if(r==="]"&&o&&!d){o=!1;let p=m(y);l.push(p);continue}let u=l.length>0?l[l.length-1]:null;if(r==="."&&!o&&!d){if(c==="."){let p=e.split("..")[0];l.push({type:"property",value:p,raw:p}),l.push({type:"descendant",value:"..",raw:".."}),t++}else s&&(s==="*"?l.push({type:"wildcard",value:s,raw:s}):l.push({type:"property",value:s,raw:s}),s="");continue}if(o)y+=r;else if(u&&u.type!=="descendant")s+=r;else{let p=e.split(u?.raw)[1];p!==void 0?s=p:s+=r}}return s&&l.push({type:"property",value:s,raw:s}),l.map(t=>{if(t.type==="property"&&typeof t.value=="string"&&/^-?\d+$/.test(t.value)){let r=parseInt(t.value,10);if(!isNaN(r))return{...t,type:"index",value:r}}return t})},g=e=>{let n=e.replace(/@\.([a-zA-Z_$][\w$]*)/g,(a,i)=>`item.${i}`).replace(/@/g,"item");try{return new Function("item",`return ${n}`)}catch{throw new Error(`Invalid filter expression: ${e}`)}},A=e=>{let n=[];for(let a=0;a<e.length;a++){let i=e[a],l=a>0?e[a-1]:null;switch(i.type){case"property":/[\.\[\]\s]/.test(String(i.value))?n.push(`["${i.value}"]`):(l&&l.type!=="descendant"&&n.push("."),n.push(String(i.value)));break;case"index":n.push(`[${i.value}]`);break;case"wildcard":i.value==="[]"?n.push("[]"):n.push("[*]");break;case"slice":let[o,d]=i.value;n.push(`[${o}:${d===1/0?"":d}]`);break;case"union":let f=i.value;n.push(`[${f.join(",")}]`);break;case"filter":n.push(`[?(${i.raw?.slice(2,-1)||""})]`);break;case"descendant":n.push("..");break}}return n.join("").replace(/\.\[/g,"[")},S=(e,n={})=>{if(Array.isArray(e))return e.map(a=>S(a,n));if(!/^[a-zA-Z]/.test(e))return{valid:!1,error:"Selector starts with '.'",type:w(e)};if(!/[a-zA-Z]$/.test(e))return{valid:!1,error:"Selector end with '.'",type:w(e)};try{let a=v(e,{throwOnError:!0}),i=w(e);return n.allowedTypes&&!n.allowedTypes.includes(i)?{valid:!1,error:`Selector type ${i} not allowed. Allowed: ${n.allowedTypes.join(", ")}`,type:i}:{valid:!0,type:w(e)}}catch(a){return{valid:!1,error:a.message}}},w=e=>e.includes("..")?"descendant":e.includes("[?(")?"filter":e.includes("[:")||e.includes("[0:")?"slice":/\[[^\]]*,[^\]]*\]/.test(e)?"union":e.includes("[*]")||e.includes(".*.")?"wildcard":e.includes("[]")?"array-wildcard":e.includes("[")&&e.includes("]")?"bracket":"dot",E=(e,n)=>e.replace(/\{(\w+)\}/g,(a,i)=>i in n?String(n[i]):`{${i}}`);
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/object/selector.ts
21
+ var selector_exports = {};
22
+ __export(selector_exports, {
23
+ createFilterFunction: () => createFilterFunction,
24
+ createSelector: () => createSelector,
25
+ detectSelectorType: () => detectSelectorType,
26
+ parseSelector: () => parseSelector,
27
+ stringifySelector: () => stringifySelector,
28
+ validateSelector: () => validateSelector
29
+ });
30
+ module.exports = __toCommonJS(selector_exports);
31
+ var parseSelector = (selector, options = {}) => {
32
+ const { type = "auto", throwOnError = false } = options;
33
+ if (!selector || typeof selector !== "string") {
34
+ return [];
35
+ }
36
+ const segments = [];
37
+ let current = "";
38
+ let inBrackets = false;
39
+ let inQuotes = false;
40
+ let quoteChar = "";
41
+ let bracketContent = "";
42
+ let bracketDepth = 0;
43
+ const detectType = (str) => {
44
+ if (str.includes("..")) return "descendant";
45
+ if (str.includes("[?(")) return "filter";
46
+ if (str.includes("[:") || str.includes("[0:")) return "slice";
47
+ if (str.includes("[,") || str.includes("[0,1]")) return "union";
48
+ if (str.includes("[*]") || str.includes(".*.")) return "wildcard";
49
+ if (str.includes("[]")) return "array-wildcard";
50
+ if (str.includes("[") && str.includes("]")) return "bracket";
51
+ return "dot";
52
+ };
53
+ const actualType = type === "auto" ? detectType(selector) : type;
54
+ const parseBracketContent = (content) => {
55
+ const trimmed = content.trim();
56
+ if (trimmed === "*" || trimmed === "") {
57
+ return {
58
+ type: "wildcard",
59
+ value: trimmed === "" ? "[]" : "*",
60
+ raw: trimmed === "" ? "[]" : content
61
+ };
62
+ }
63
+ if (trimmed === "[]") {
64
+ return { type: "wildcard", value: "[]", raw: content };
65
+ }
66
+ if (/^-?\d+$/.test(trimmed)) {
67
+ return { type: "index", value: parseInt(trimmed, 10), raw: content };
68
+ }
69
+ if (trimmed.includes(":")) {
70
+ const parts = trimmed.split(":").map((p) => p.trim());
71
+ const start = parts[0] === "" ? 0 : parseInt(parts[0], 10);
72
+ const end = parts[1] === "" ? Infinity : parseInt(parts[1], 10);
73
+ if (isNaN(start) || isNaN(end)) {
74
+ if (throwOnError) throw new Error(`Invalid slice notation: ${content}`);
75
+ return { type: "wildcard", value: "*", raw: content };
76
+ }
77
+ return { type: "slice", value: [start, end], raw: content };
78
+ }
79
+ if (trimmed.includes(",")) {
80
+ const indices = trimmed.split(",").map((p) => {
81
+ const num = parseInt(p.trim(), 10);
82
+ return isNaN(num) ? -1 : num;
83
+ }).filter((n) => n >= 0);
84
+ if (indices.length === 0) {
85
+ if (throwOnError) throw new Error(`Invalid union notation: ${content}`);
86
+ return { type: "wildcard", value: "*", raw: content };
87
+ }
88
+ return { type: "union", value: indices, raw: content };
89
+ }
90
+ if (trimmed.startsWith("?(") && trimmed.endsWith(")")) {
91
+ const expr = trimmed.slice(2, -1);
92
+ try {
93
+ const filterFn = createFilterFunction(expr);
94
+ return { type: "filter", value: filterFn, raw: content };
95
+ } catch (error) {
96
+ if (throwOnError) throw error;
97
+ return { type: "wildcard", value: "*", raw: content };
98
+ }
99
+ }
100
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
101
+ return { type: "property", value: trimmed.slice(1, -1), raw: content };
102
+ }
103
+ return { type: "property", value: trimmed, raw: content };
104
+ };
105
+ for (let i = 0; i < selector.length; i++) {
106
+ const char = selector[i];
107
+ const nextChar = selector[i + 1];
108
+ if ((char === '"' || char === "'") && !inQuotes) {
109
+ inQuotes = true;
110
+ quoteChar = char;
111
+ continue;
112
+ } else if (char === quoteChar && inQuotes) {
113
+ inQuotes = false;
114
+ quoteChar = "";
115
+ if (!(char === '"' || char === "'")) {
116
+ if (inBrackets) {
117
+ bracketContent += char;
118
+ } else {
119
+ current += char;
120
+ }
121
+ }
122
+ continue;
123
+ }
124
+ if (inQuotes) {
125
+ if (inBrackets) {
126
+ bracketContent += char;
127
+ } else {
128
+ current += char;
129
+ }
130
+ continue;
131
+ }
132
+ if (char === "[" && !inBrackets) {
133
+ if (current) {
134
+ segments.push({ type: "property", value: current, raw: current });
135
+ current = "";
136
+ }
137
+ inBrackets = true;
138
+ bracketContent = "";
139
+ continue;
140
+ }
141
+ if (char === "]" && inBrackets && !inQuotes) {
142
+ inBrackets = false;
143
+ const segment = parseBracketContent(bracketContent);
144
+ segments.push(segment);
145
+ continue;
146
+ }
147
+ let lastDot = segments.length > 0 ? segments[segments.length - 1] : null;
148
+ if (char === "." && !inBrackets && !inQuotes) {
149
+ if (nextChar === ".") {
150
+ const l = selector.split("..")[0];
151
+ segments.push({ type: "property", value: l, raw: l });
152
+ segments.push({ type: "descendant", value: "..", raw: ".." });
153
+ i++;
154
+ } else if (current) {
155
+ if (current === "*") {
156
+ segments.push({ type: "wildcard", value: current, raw: current });
157
+ } else {
158
+ segments.push({ type: "property", value: current, raw: current });
159
+ }
160
+ current = "";
161
+ }
162
+ continue;
163
+ }
164
+ if (inBrackets) {
165
+ bracketContent += char;
166
+ } else {
167
+ if (lastDot && lastDot.type !== "descendant") {
168
+ current += char;
169
+ } else {
170
+ const l = selector.split(lastDot?.raw)[1];
171
+ if (l !== void 0) {
172
+ current = l;
173
+ } else {
174
+ current += char;
175
+ }
176
+ }
177
+ }
178
+ }
179
+ if (current) {
180
+ segments.push({ type: "property", value: current, raw: current });
181
+ }
182
+ return segments.map((segment) => {
183
+ if (segment.type === "property" && typeof segment.value === "string") {
184
+ if (/^-?\d+$/.test(segment.value)) {
185
+ const num = parseInt(segment.value, 10);
186
+ if (!isNaN(num)) {
187
+ return { ...segment, type: "index", value: num };
188
+ }
189
+ }
190
+ }
191
+ return segment;
192
+ });
193
+ };
194
+ var createFilterFunction = (expr) => {
195
+ const safeExpr = expr.replace(/@\.([a-zA-Z_$][\w$]*)/g, (_, prop) => `item.${prop}`).replace(/@/g, "item");
196
+ try {
197
+ return new Function("item", `return ${safeExpr}`);
198
+ } catch (error) {
199
+ throw new Error(`Invalid filter expression: ${expr}`);
200
+ }
201
+ };
202
+ var stringifySelector = (segments) => {
203
+ const parts = [];
204
+ for (let i = 0; i < segments.length; i++) {
205
+ const segment = segments[i];
206
+ const prevSegment = i > 0 ? segments[i - 1] : null;
207
+ switch (segment.type) {
208
+ case "property":
209
+ const needsQuotes = /[\.\[\]\s]/.test(String(segment.value));
210
+ if (needsQuotes) {
211
+ parts.push(`["${segment.value}"]`);
212
+ } else {
213
+ if (prevSegment && prevSegment.type !== "descendant") {
214
+ parts.push(".");
215
+ }
216
+ parts.push(String(segment.value));
217
+ }
218
+ break;
219
+ case "index":
220
+ parts.push(`[${segment.value}]`);
221
+ break;
222
+ case "wildcard":
223
+ if (segment.value === "[]") {
224
+ parts.push("[]");
225
+ } else {
226
+ parts.push("[*]");
227
+ }
228
+ break;
229
+ case "slice":
230
+ const [start, end] = segment.value;
231
+ parts.push(`[${start}:${end === Infinity ? "" : end}]`);
232
+ break;
233
+ case "union":
234
+ const indices = segment.value;
235
+ parts.push(`[${indices.join(",")}]`);
236
+ break;
237
+ case "filter":
238
+ parts.push(`[?(${segment.raw?.slice(2, -1) || ""})]`);
239
+ break;
240
+ case "descendant":
241
+ parts.push("..");
242
+ break;
243
+ }
244
+ }
245
+ return parts.join("").replace(/\.\[/g, "[");
246
+ };
247
+ var validateSelector = (selector, options = {}) => {
248
+ if (Array.isArray(selector)) {
249
+ return selector.map(
250
+ (sel) => validateSelector(sel, options)
251
+ );
252
+ }
253
+ if (!/^[a-zA-Z]/.test(selector)) {
254
+ return {
255
+ valid: false,
256
+ error: `Selector starts with '.'`,
257
+ type: detectSelectorType(selector)
258
+ };
259
+ }
260
+ if (!/[a-zA-Z]$/.test(selector)) {
261
+ return {
262
+ valid: false,
263
+ error: `Selector end with '.'`,
264
+ type: detectSelectorType(selector)
265
+ };
266
+ }
267
+ try {
268
+ const segments = parseSelector(selector, { throwOnError: true });
269
+ const type = detectSelectorType(selector);
270
+ if (options.allowedTypes) {
271
+ if (!options.allowedTypes.includes(type)) {
272
+ return {
273
+ valid: false,
274
+ error: `Selector type ${type} not allowed. Allowed: ${options.allowedTypes.join(
275
+ ", "
276
+ )}`,
277
+ type
278
+ };
279
+ }
280
+ }
281
+ return { valid: true, type: detectSelectorType(selector) };
282
+ } catch (error) {
283
+ return { valid: false, error: error.message };
284
+ }
285
+ };
286
+ var detectSelectorType = (selector) => {
287
+ if (selector.includes("..")) return "descendant";
288
+ if (selector.includes("[?(")) return "filter";
289
+ if (selector.includes("[:") || selector.includes("[0:")) return "slice";
290
+ if (/\[[^\]]*,[^\]]*\]/.test(selector)) return "union";
291
+ if (selector.includes("[*]") || selector.includes(".*.")) return "wildcard";
292
+ if (selector.includes("[]")) return "array-wildcard";
293
+ if (selector.includes("[") && selector.includes("]")) return "bracket";
294
+ return "dot";
295
+ };
296
+ var createSelector = (template, replacements) => {
297
+ return template.replace(/\{(\w+)\}/g, (_, key) => {
298
+ if (key in replacements) {
299
+ return String(replacements[key]);
300
+ }
301
+ return `{${key}}`;
302
+ });
303
+ };