@fluixi/utils 1.0.0-alpha.83 → 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,2330 @@
1
- import{isDate as X}from"@fluixi/utils/primitive";import{isClass as xe,isObject as he}from"@fluixi/utils/object";import{isArray as Se}from"@fluixi/utils/array";import{isFunction as be}from"@fluixi/utils/functions";function _(e){let r=typeof e;return e===null||r==="string"||r==="number"||r==="boolean"||r==="symbol"||r==="bigint"||r==="undefined"||X(e)}var m=e=>e==null||Array.isArray(e)||typeof e=="function"||e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Error?!1:typeof e=="object";var w=(e,r,t,i)=>{if(t>i)return;if(r.length===0)return e;let s=r[0],l=r.slice(1);if(s.type==="descendant"){let a=w(e,l,t+1,i);if(a!==void 0)return a;if(e&&typeof e=="object")if(Array.isArray(e)){let n=[];for(let f=0;f<e.length;f++){let o=w(e[f],r,t+1,i);o!==void 0&&(n[f]=o)}return n.length>0?n:void 0}else{let n={};for(let f in e)if(e.hasOwnProperty(f)){let o=w(e[f],r,t+1,i);o!==void 0&&(n[f]=o)}return Object.keys(n).length>0?n:void 0}return}switch(s.type){case"property":if(m(e)&&s.value&&String(s.value)in e){let a=e[String(s.value)],n=w(a,l,t+1,i);if(n!==void 0)return{[String(s.value)]:n}}break;case"index":if(Array.isArray(e)){let a=s.value;if(a>=0&&a<e.length){let n=w(e[a],l,t+1,i);if(n!==void 0){let f=new Array(e.length).filter(o=>o!==void 0);return f[a]=n,f}}}else if(e&&typeof e=="object"){let a=String(s.value);if(a in e){let n=w(e[a],l,t+1,i);if(n!==void 0)return{[a]:n}}}break;case"wildcard":if(e&&typeof e=="object")if(Array.isArray(e)){let a=[],n=!1;for(let f=0;f<e.length;f++){let o=w(e[f],l,t+1,i);o!==void 0&&(a[f]=o,n=!0)}return n?a:void 0}else{let a={},n=!1;for(let f in e)if(e.hasOwnProperty(f)){let o=w(e[f],l,t+1,i);o!==void 0&&(a[f]=o,n=!0)}return n?a:void 0}break;case"slice":if(Array.isArray(e)){let[a,n]=s.value,f=Math.max(0,a),o=Math.min(e.length,n===1/0?e.length:n),u=[],g=!1;for(let p=f;p<o;p++){let A=w(e[p],l,t+1,i);A!==void 0&&(u[p]=A,g=!0)}return g?u:void 0}break;case"union":if(Array.isArray(e)){let a=s.value,n=[],f=!1;for(let o of a)if(o>=0&&o<e.length){let u=w(e[o],l,t+1,i);u!==void 0&&(n[o]=u,f=!0)}return f?n:void 0}break;case"filter":if(Array.isArray(e)){let a=s.value,n=[],f=!1;for(let o=0;o<e.length;o++)if(a(e[o])){let u=w(e[o],l,t+1,i);u!==void 0&&(n[o]=u,f=!0)}return f?n:void 0}break}};var V=(e,r)=>{if(e==null||typeof e!="object")return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){let t=new Map;return e.forEach((i,s)=>{(!r||!r.some(l=>l.toString()===s.toString()))&&t.set(s,V(i))}),t}if(e instanceof Set){let t=new Set;return e.forEach(i=>{t.add(V(i))}),t}if(Array.isArray(e))return Array.from(e).map(t=>V(t));if(m(e)){let t={};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&(!r||!r.some(l=>l.toString()===s.toString()))&&(t[s]=V(e[s]));let i=Object.getOwnPropertySymbols(e);for(let s of i)(!r||!r.some(l=>l.toString()===s.toString()))&&(t[s]=V(e[s]));return t}return e};var B=(e,r)=>e===r,j=(e,r)=>{if(e.length!==r.length)return!1;for(let t=0;t<e.length;t++)if(Array.isArray(e[t])&&Array.isArray(r[t])){if(!j(e[t],r[t]))return!1}else if(m(e[t])&&m(r[t])){if(!q(e[t],r[t]))return!1}else if(e[t]!==r[t])return!1;return!0},q=(e,r)=>{let t=Object.keys(e),i=Object.keys(r);if(t.length!==i.length)return!1;for(let s of t){if(!(s in r))return!1;let l=e[s],a=r[s];if(Array.isArray(l)&&Array.isArray(a)){if(!j(l,a))return!1}else if(m(l)&&m(a)){if(!q(l,a))return!1}else if(l!==a)return!1}return!0},L=(e,r,t={})=>{let{includeDeleted:i=!1,includeAdded:s=!0,deepArrayComparison:l=!0,equalityFn:a=B,preserveStructure:n=!1}=t;if(e==null&&r==null)return{};if(e==null)return s?{...r}:{};if(r==null){if(i){let u={};for(let g in e)u[g]=void 0;return u}return{}}if(!m(e)||!m(r))return a(e,r)?{}:r;let f={},o=new Set;for(let u in r){o.add(u);let g=e[u],p=r[u];if(!(u in e)){s&&(f[u]=p);continue}if(Array.isArray(g)&&Array.isArray(p)){l?j(g,p)?n&&(f[u]=void 0):f[u]=p:g!==p?f[u]=p:n&&(f[u]=void 0);continue}if(m(g)&&m(p)){let A=L(g,p,t);Object.keys(A).length>0?f[u]=A:n&&(f[u]=void 0);continue}a(g,p)?n&&(f[u]=void 0):f[u]=p}if(i)for(let u in e)o.has(u)||(f[u]=void 0);return f},U=(e,r,t={})=>{let i=[],s=[],l=[],a={},{includeDeleted:n=!1,includeAdded:f=!0,deepArrayComparison:o=!0,equalityFn:u=B}=t;if(Array.isArray(e)&&Array.isArray(r)){let A=Math.max(e.length,r.length),d=[],c=!1;for(let y=0;y<A;y++){let T=`[${y}]`;if(y>=e.length)i.push(T),d[y]=r[y],c=!0;else if(y>=r.length)s.push(T),c=!0;else{let x=e[y],h=r[y];m(x)&&m(h)||Array.isArray(x)&&Array.isArray(h)?U(x,h,t).hasChanges?(l.push(T),d[y]=h,c=!0):d[y]=x:u(x,h)?d[y]=x:(l.push(T),d[y]=h,c=!0)}}return{changes:c?d:{},added:i,deleted:s,modified:l,hasChanges:c||s.length>0}}let g=(A,d,c="")=>{let y={added:[],deleted:[],modified:[]};if(Array.isArray(A)&&Array.isArray(d)){let T=Math.max(A.length,d.length);for(let x=0;x<T;x++){let h=c?`${c}[${x}]`:`[${x}]`;if(x>=A.length)y.added.push(h);else if(x>=d.length)y.deleted.push(h);else{let S=A[x],K=d[x];if(m(S)&&m(K)){let v=g(S,K,h);y.added.push(...v.added),y.deleted.push(...v.deleted),y.modified.push(...v.modified)}else if(Array.isArray(S)&&Array.isArray(K)){let v=g(S,K,h);y.added.push(...v.added),y.deleted.push(...v.deleted),y.modified.push(...v.modified)}else S!==K&&y.modified.push(h)}}return y}if(m(A)&&m(d)){let T=new Set([...Object.keys(A||{}),...Object.keys(d||{})]);for(let x of T){let h=A?.[x],S=d?.[x],K=c?`${c}.${x}`:x;if(!(x in(A||{})))y.added.push(K);else if(!(x in(d||{})))y.deleted.push(K);else if(Array.isArray(h)&&Array.isArray(S)){if(!j(h,S)){let v=g(h,S,K);y.added.push(...v.added),y.deleted.push(...v.deleted),y.modified.push(...v.modified)}}else if(m(h)&&m(S)){let v=g(h,S,K);y.added.push(...v.added),y.deleted.push(...v.deleted),y.modified.push(...v.modified)}else h!==S&&y.modified.push(K)}}return y};if(e==null&&r==null)return{changes:{},added:i,deleted:s,modified:l,hasChanges:!1};if(e==null){if(f&&r)for(let A in r)i.push(A),a[A]=r[A];return{changes:a,added:i,deleted:s,modified:l,hasChanges:i.length>0}}if(r==null){if(n)for(let A in e)s.push(A),a[A]=void 0;return{changes:a,added:i,deleted:s,modified:l,hasChanges:s.length>0}}let p=new Set;for(let A in r){p.add(A);let d=e[A],c=r[A];if(!(A in e)){f&&(i.push(A),a[A]=c);continue}let y=!1;if(Array.isArray(d)&&Array.isArray(c)){if(y=o?!j(d,c):d!==c,y){let T=g(d,c,A);i.push(...T.added),s.push(...T.deleted),l.push(...T.modified),a[A]=c}}else if(m(d)&&m(c)){let T=L(d,c,t);if(y=Object.keys(T).length>0,y){let x=g(d,c,A);i.push(...x.added),s.push(...x.deleted),l.push(...x.modified),a[A]=T}}else y=!u(d,c),y&&(l.push(A),a[A]=c)}for(let A in e)p.has(A)||(s.push(A),a[A]=void 0);return{changes:a,added:i,deleted:s,modified:l,hasChanges:i.length>0||s.length>0||l.length>0}};function Y(e){return!!(e&&(e.diff||e.changes)&&(e.modified||e.deleted||e.hasChanges))}var b=(e,r,t)=>{if(!Y(r)){let y=r,T=t||!1;if(Array.isArray(e)&&Array.isArray(y)){let h=T?e:[...e];y.length<h.length&&(h.length=y.length);for(let S=0;S<y.length;S++){let K=y[S];K!==void 0&&(m(h[S])&&m(K)||Array.isArray(h[S])&&Array.isArray(K)?h[S]=b(h[S],K,T):h[S]=K)}return h}if(!m(e))return y;if(!m(y))return e;let x=T?e:{...e};for(let h in y){let S=y[h];S===void 0?delete x[h]:Array.isArray(x[h])&&Array.isArray(S)||m(x[h])&&m(S)?x[h]=b(x[h],S,T):x[h]=S}return x}let{diff:i,added:s=[],deleted:l=[],modified:a=[],changes:n,keepRef:f}=r,o=t!==void 0?t:f,u=n||i;if(!u)return e;let g=new Set(s),p=new Set(l),A=new Set(a),d=y=>{if(s.length===0&&l.length===0&&a.length===0)return!0;let T=y.split(/[.\[\]]+/).filter(Boolean);for(let x=0;x<=T.length;x++){let h=T.slice(0,x).join("."),S=T.slice(0,x).map((K,v)=>/^\d+$/.test(K)?`[${K}]`:v>0?`.${K}`:K).join("");if(g.has(h)||g.has(S)||p.has(h)||p.has(S)||A.has(h)||A.has(S))return!0}return!1};if(Array.isArray(e)&&Array.isArray(u)){let y=o?e:[...e];y.length=u.length;for(let T=0;T<u.length;T++){let x=`[${T}]`,h=u[T];h!==void 0&&d(x)&&(m(y[T])&&m(h)||Array.isArray(y[T])&&Array.isArray(h)?y[T]=b(y[T],h,o):y[T]=h)}return y}if(!m(e))return u;if(!m(u))return e;let c=o?e:{...e};for(let y of l)y.includes(".")||y.includes("[")||d(y)&&delete c[y];for(let y in u){let T=u[y];d(y)&&(T===void 0?delete c[y]:Array.isArray(c[y])&&Array.isArray(T)||m(c[y])&&m(T)?c[y]=b(c[y],T,o):c[y]=T)}return c};var O=(e,r={})=>{let{type:t="auto",throwOnError:i=!1}=r;if(!e||typeof e!="string")return[];let s=[],l="",a=!1,n=!1,f="",o="",u=0,p=t==="auto"?(d=>d.includes("..")?"descendant":d.includes("[?(")?"filter":d.includes("[:")||d.includes("[0:")?"slice":d.includes("[,")||d.includes("[0,1]")?"union":d.includes("[*]")||d.includes(".*.")?"wildcard":d.includes("[]")?"array-wildcard":d.includes("[")&&d.includes("]")?"bracket":"dot")(e):t,A=d=>{let c=d.trim();if(c==="*"||c==="")return{type:"wildcard",value:c===""?"[]":"*",raw:c===""?"[]":d};if(c==="[]")return{type:"wildcard",value:"[]",raw:d};if(/^-?\d+$/.test(c))return{type:"index",value:parseInt(c,10),raw:d};if(c.includes(":")){let y=c.split(":").map(h=>h.trim()),T=y[0]===""?0:parseInt(y[0],10),x=y[1]===""?1/0:parseInt(y[1],10);if(isNaN(T)||isNaN(x)){if(i)throw new Error(`Invalid slice notation: ${d}`);return{type:"wildcard",value:"*",raw:d}}return{type:"slice",value:[T,x],raw:d}}if(c.includes(",")){let y=c.split(",").map(T=>{let x=parseInt(T.trim(),10);return isNaN(x)?-1:x}).filter(T=>T>=0);if(y.length===0){if(i)throw new Error(`Invalid union notation: ${d}`);return{type:"wildcard",value:"*",raw:d}}return{type:"union",value:y,raw:d}}if(c.startsWith("?(")&&c.endsWith(")")){let y=c.slice(2,-1);try{return{type:"filter",value:ee(y),raw:d}}catch(T){if(i)throw T;return{type:"wildcard",value:"*",raw:d}}}return c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'")?{type:"property",value:c.slice(1,-1),raw:d}:{type:"property",value:c,raw:d}};for(let d=0;d<e.length;d++){let c=e[d],y=e[d+1];if((c==='"'||c==="'")&&!n){n=!0,f=c;continue}else if(c===f&&n){n=!1,f="",c==='"'||c==="'"||(a?o+=c:l+=c);continue}if(n){a?o+=c:l+=c;continue}if(c==="["&&!a){l&&(s.push({type:"property",value:l,raw:l}),l=""),a=!0,o="";continue}if(c==="]"&&a&&!n){a=!1;let x=A(o);s.push(x);continue}let T=s.length>0?s[s.length-1]:null;if(c==="."&&!a&&!n){if(y==="."){let x=e.split("..")[0];s.push({type:"property",value:x,raw:x}),s.push({type:"descendant",value:"..",raw:".."}),d++}else l&&(l==="*"?s.push({type:"wildcard",value:l,raw:l}):s.push({type:"property",value:l,raw:l}),l="");continue}if(a)o+=c;else if(T&&T.type!=="descendant")l+=c;else{let x=e.split(T?.raw)[1];x!==void 0?l=x:l+=c}}return l&&s.push({type:"property",value:l,raw:l}),s.map(d=>{if(d.type==="property"&&typeof d.value=="string"&&/^-?\d+$/.test(d.value)){let c=parseInt(d.value,10);if(!isNaN(c))return{...d,type:"index",value:c}}return d})},ee=e=>{let r=e.replace(/@\.([a-zA-Z_$][\w$]*)/g,(t,i)=>`item.${i}`).replace(/@/g,"item");try{return new Function("item",`return ${r}`)}catch{throw new Error(`Invalid filter expression: ${e}`)}},C=e=>{let r=[];for(let t=0;t<e.length;t++){let i=e[t],s=t>0?e[t-1]:null;switch(i.type){case"property":/[\.\[\]\s]/.test(String(i.value))?r.push(`["${i.value}"]`):(s&&s.type!=="descendant"&&r.push("."),r.push(String(i.value)));break;case"index":r.push(`[${i.value}]`);break;case"wildcard":i.value==="[]"?r.push("[]"):r.push("[*]");break;case"slice":let[a,n]=i.value;r.push(`[${a}:${n===1/0?"":n}]`);break;case"union":let f=i.value;r.push(`[${f.join(",")}]`);break;case"filter":r.push(`[?(${i.raw?.slice(2,-1)||""})]`);break;case"descendant":r.push("..");break}}return r.join("").replace(/\.\[/g,"[")};var J=(e,r,t)=>{let i=O(r),s=e;for(let l=0;l<i.length;l++){let a=i[l],n=l===i.length-1;switch(a.type){case"property":if(n)s[String(a.value)]=t;else{if(!s[String(a.value)]){let o=i[l+1];s[String(a.value)]=o.type==="index"||o.type==="slice"||o.type==="union"||o.type==="wildcard"?[]:{}}s=s[String(a.value)]}break;case"index":Array.isArray(s)||(s=[]);let f=a.value;if(n){if(f>=s.length)for(let o=s.length;o<=f;o++)s.push(void 0);s[f]=t}else{if(!s[f]){let o=i[l+1];s[f]=o.type==="index"||o.type==="slice"||o.type==="union"||o.type==="wildcard"?[]:{}}s=s[f]}break;case"wildcard":if(Array.isArray(s))if(n)for(let o=0;o<s.length;o++)s[o]=t;else{let o=i[l+1];for(let u=0;u<s.length;u++)s[u]||(s[u]=o.type==="index"||o.type==="slice"||o.type==="union"||o.type==="wildcard"?[]:{});s.length>0&&(s=s[0])}break}}};function $(e,r,t={}){let{preserveStructure:i,multiple:s,throwOnError:l=!1,defaultValue:a,maxDepth:n=20}=t;if(!e||typeof e!="object")return a;if(!r)return e;if(Array.isArray(r))if(i){let u={};for(let g of r){let p=$(e,g,{...t,preserveStructure:!1});p!==void 0&&J(u,g,p)}return u}else return r.map(u=>$(e,u,{...t,preserveStructure:!1}));let f=O(r,{...t,throwOnError:l});if(f.length===0)return e;if(typeof i>"u"||i===!1){let u=P(e,r);return s===!1&&Array.isArray(u)?u[0]:u===void 0&&a!==void 0?a:u}let o=w(e,f,0,n);return o===void 0&&a!==void 0?a:o}function H(e,r,t,i,s){let l=V(e),a=[];if(typeof r<"u"&&a.push(r),typeof t<"u"&&a.push(t),typeof i<"u"&&a.push(i),typeof s<"u"&&a.push(s),_(l))return typeof r=="function"?r(l):r;if(a.length===1){if(typeof a[0]=="function")return ce(l,a[0]);if(Array.isArray(a[0])){if(Array.isArray(l))if(r.length===0)for(let n=0;n<l.length;n++)l.pop();else return U([...l],[...a[0]]).hasChanges&&b(l,[...a[0]],!0),l}else typeof a[0]=="object"&&!Array.isArray(a[0])?typeof l=="object"&&!Array.isArray(l)&&b(l,a[0],!0):l=a[0];return l}if(Array.isArray(l)){if(typeof r=="string"&&(te(t)||typeof t=="string")&&a.length===3){if(Array.isArray(t)){for(let n=0;n<t.length;n++)k(l,r,i,t[n]);return l}return k(l,r,i,t)}if(typeof r=="string"&&typeof t=="function"&&a.length===2)return k(l,r,t)}if((typeof r=="string"||typeof r=="number")&&(a.length===2||a.length===3))return ne(t)?M(l,r,t,i):typeof r=="number"?typeof i<"u"?k(l,`[${r}].${t}`,i):k(l,`[${r}]`,t,i):typeof t=="number"&&typeof i<"u"?E(l,r,t,i):Array.isArray(t)&&t.length>0&&t.every(n=>typeof n=="number")?R(l,r,t,i):typeof i<"u"&&typeof t=="function"?D(l,r,t,i):k(l,r,t,i);if(typeof r=="string"&&typeof t=="number"){if(a.length===3)return E(l,r,t,i);if(a.length===4)return re(l,r,t,i,s)}if(typeof r=="string"&&Array.isArray(t)){if(a.length===3)return R(l,r,t,i);if(a.length===4)return se(l,r,t,i,s)}if(typeof r=="string"&&typeof t=="object"&&!Array.isArray(t)&&t!==null){let n=t;if("from"in n||"to"in n){if(a.length===3)return M(l,r,n,i);if(a.length===4)return ie(l,r,n,i,s)}}if(typeof r=="object"&&!Array.isArray(r)&&a.length===1)return b(l,r,!0);if(typeof r=="string"&&typeof t=="object"&&!Array.isArray(t)&&a.length===2)return oe(l,r,t);if(typeof r=="string"&&typeof t=="function"){if(a.length===3)return D(l,r,t,i);if(a.length===4)return z(l,r,t,i,s)}if(typeof r=="function"&&typeof t=="string"){if(a.length===3)return ae(l,r,t,i);if(a.length===4)return z(l,t,r,i,s)}if(Array.isArray(r)){if(a.length===2&&typeof t=="object"&&!Array.isArray(t))return Q(l,r,t);if(a.length===2)return Q(l,r,t)}throw new Error(`Invalid set parameters: ${JSON.stringify(a)}`)}function W(e,r,t,i=!1){let s=O(e);if(s.length===0)return t;let l=s[s.length-1].type==="wildcard",a=s.some(f=>f.type==="wildcard")&&Array.isArray(r),n;if((l||a&&i||a&&s.length===2)&&Array.isArray(r))for(let f=0;f<r.length;f++){let o=typeof t=="function"?t(r[f]):typeof r[f]=="object"?b(r[f],t,!0):t;n||(n=[]),n.push(o)}return!l&&!n&&(n=typeof t=="function"?t(r):t),n}function ne(e){return typeof e=="object"&&e!==null&&"from"in e&&"to"in e&&typeof e.from=="number"&&typeof e.to=="number"&&e.from<e.to&&e.from>=0&&e.to>0}function te(e){return Array.isArray(e)&&e.every(r=>typeof r=="string")}function k(e,r,t,i){let s=O(r),l=P(e,r,{paths:s,createMissing:!0}),a;i&&typeof t=="function"&&(a=$(l,i));let f=W(r,i?a:l,t,Array.isArray(e));return i?I(e,`${r}.${i}`,f,{createMissing:!0}):I(e,r,f,{createMissing:!0})}function E(e,r,t,i){let s=P(e,r,{createMissing:!0});if(!Array.isArray(s))throw new Error(`Target at ${r} is not an array ${t}`);let l=structuredClone(s),a=W(r,l[t],i);if(t<0){let n=s.length+t;if(n<0)throw new Error(`Index ${t} is out of bounds`);return I(e,`${r}[${n}]`,a,{createMissing:!0})}return I(e,`${r}[${t}]`,a,{createMissing:!0})}var re=(e,r,t,i,s)=>typeof i=="function"?k(e,`${r}[${t}]`,i):typeof i=="string"?k(e,`${r}[${t}]`,s,i):null,R=(e,r,t,i)=>{let s=P(e,r);if(!Array.isArray(s))throw new Error(`Target at ${r} is not an array`);for(let l of t)typeof l=="number"?E(e,r,l,i):typeof l=="string"&&k(e,r,i,l);return e},se=(e,r,t,i,s)=>R(e,r,t,a=>{let n=typeof s=="function"?s(a?P(a,i):void 0):s,f=a?{...a}:{};return I(f,i,n),f});function M(e,r,t,i){let s=P(e,r);if(!Array.isArray(s))throw new Error(`Target at ${r} is not an array`);let l=t.from??0,a=t.to??s.length-1,n=t.by??1,f=[];for(let o=l;o<=a;o+=n)o>=0&&o<s.length&&f.push(o);return R(e,r,f,i)}var ie=(e,r,t,i,s)=>M(e,r,t,a=>{let n=typeof s=="function"?s(a?P(a,i):void 0):s,f=a?{...a}:{};return I(f,i,n),f});function We(e,r){return Object.assign(e,r)}function D(e,r,t,i){let s=P(e,r);if(!Array.isArray(s))throw new Error(`Target at ${r} is not an array`);let l=[],a=[...s];return s.forEach((n,f)=>{t(n,f)&&l.push(f)}),R(e,r,l,i)}function ae(e,r,t,i){let s=e;if(!Array.isArray(s))throw new Error(`Target at ${t} is not an array`);let l=[],a=[...s];return s.forEach((n,f)=>{n=I(n,t,i,{createMissing:!0})}),s}function z(e,r,t,i,s){return D(e,r,t,a=>{let n=typeof s=="function"?s(a?P(a,i):void 0):s,f=a?{...a}:{};return I(f,i,n),f})}function oe(e,r,t){let i=P(e,r,{createMissing:!0}),s=b(i||{},t,!0);return I(e,r,s,{createMissing:!0})}function Q(e,r,t){if(typeof t=="object"&&!Array.isArray(t)&&t!==null)for(let[i,s]of Object.entries(t))r.includes(i)&&I(e,i,s,{createMissing:!0});else for(let i of r){let s=W(i,P(e,i),t);I(e,i,s,{createMissing:!0})}return e}function P(e,r,t={}){let{createMissing:i=!1,add:s=!1,debug:l=!1}=t,a=O(r),n=e,f=!1,o="",u=r;if(typeof n=="object"&&!Array.isArray(n)&&u.length>0&&n[u])return n=n[u],n;for(let g=0;g<a.length;g++){let p=a[g],A=a.length>1?g===a.length-1:!1;if(n===null&&!i)return;let d=a[g+1];switch(p.type){case"property":if(n&&typeof n=="object")if(Array.isArray(n)){if(typeof p.value=="number"){let c=p.value;if(i&&c>=n.length)for(let y=n.length;y<=c;y++)n.push(void 0);if(i&&(n[c]===null||n[c]===void 0)&&(!A||f)&&(d?n[c]=d.type==="index"||d.type==="slice"||d.type==="union"||d.type==="wildcard"?[]:{}:n[c]=null,f=!1),n=n[c],d){f=!0;continue}}else s?n.push({[String(p.value)]:null}):n=n.map(c=>c[String(p.value)]);if(d)continue;return Z(n)}else{if(n[o]&&o.split(".").length>=2){n=n[o];continue}if(i&&(n[String(p.value)]===null||n[String(p.value)]===void 0)&&(!A||f)&&(d?n[String(p.value)]=d.type==="index"||d.type==="slice"||d.type==="union"||d.type==="wildcard"?[]:{}:n[String(p.value)]=null,f=!1,n=n[String(p.value)],d)){f=!0;continue}if(n?(!n[String(p.value)]&&i&&(n[String(p.value)]=null),n=n[String(p.value)]):n={[String(p.value)]:null},d)continue}else if(i)n={},n[String(p.value)]=d.type==="index"||d.type==="slice"||d.type==="union"||d.type==="wildcard"||t.type==="array"?[]:{},n=n[String(p.value)];else return;break;case"index":case"wildcard":if(Array.isArray(n)){if(p.type==="index"){let c=p.value;if(c<0){n=n[n.length-Math.abs(c)];continue}if(i&&(c>=n.length||n[c]==null||n[c]==null)&&!A){for(let y=n.length;y<=c;y++)n.push(void 0);d&&(n[c]=d.type==="index"||d.type==="slice"||d.type==="union"||d.type==="wildcard"?[]:{})}n=n[c]}else if(!A)continue}else if(i){let c=a[g+1];n=[];let y=p.value;for(let T=0;T<=y;T++)n.push(void 0);n[y]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"||t.type==="array"?[]:{},n=n[y]}else{if(p.type==="index"&&typeof n=="object"&&n&&n[String(p.value)]!==void 0){n=n[String(p.value)];continue}if(typeof n=="object"){n=Object.values(n);continue}return}break;default:return}}return Z(n)}function Z(e){return Array.isArray(e)?e.filter(r=>typeof r<"u"):e}var I=(e,r,t,i={})=>{if(r==="[*]")return b(e,t,!0);let{createMissing:s=!0}=i,l=O(r);if(l.length===0)return e;let a=l[l.length-1],n=e;for(let f=0;f<l.length-1;f++){let o=l[f];if(n==null){if(!s)return e;throw new Error(`Cannot navigate through null/undefined at segment ${f}`)}let u=l[f+1],g=u.type==="index"||u.type==="slice"||u.type==="union"||u.type==="wildcard";if(o.type==="property"){if(Array.isArray(n)&&typeof typeof o.value=="number"){let p=o.value;if(p<0)throw new Error(`Negative index ${p} not allowed`);if(p>=n.length&&s)for(let A=n.length;A<=p;A++)n.push(void 0);(n[p]===null||n[p]===void 0)&&s&&(n[p]=g?[]:{}),n=n[p]}else(n[String(o.value)]===null||n[String(o.value)]===void 0)&&s&&(n[String(o.value)]=g?[]:{}),typeof n=="object"&&!Array.isArray(n)&&(n=n[String(o.value)]);if(u)continue;break}else if(o.type==="index"||o.type==="wildcard"){if(!Array.isArray(n)){if(!s)return e;n=[]}if(o.type==="index"){let p=o.value;if(p<0)throw new Error(`Negative index ${p} not allowed`);if(p>=n.length&&s)for(let A=n.length;A<=p;A++)n.push(void 0);(n[p]===null||n[p]===void 0)&&s&&(n[p]=g?[]:void 0),n=n[p]}if(u)continue;break}else throw new Error(`Invalid segment type for set: ${o.type}`)}switch(a.type){case"property":if(Array.isArray(n)&&typeof a.value=="number"){let o=a.value;if(o<0)throw new Error(`Negative index ${o} not allowed`);if(o>=n.length)for(let u=n.length;u<=o;u++)n.push(void 0);Array.isArray(t)?n[o]=b(structuredClone(n[o]),t[o],!0):n[o]=t}else if(n||(n={}),Array.isArray(n)){let o=r.split("."),u;if(o.length>=2){o.shift();for(let g=0;g<n.length;g++)Array.isArray(t)?(u=G(o.join("."),t[g]),n[g]=typeof n[g]=="object"?b(n[g],u,!0):u):(u=G(o.join("."),t),n[g]=typeof n[g]=="object"?b(n[g],u,!0):u)}else u={[String(a.value)]:t}}else Array.isArray(t)&&t.length===0?typeof n[String(a.value)]>"u"?n[String(a.value)]=[]:n[String(a.value)]=[]:n[String(a.value)]=t;break;case"index":case"wildcard":if(!Array.isArray(n))throw new Error("Cannot use index on non-array for final segment");let f=a.value;if(a.type==="index"){if(f<0)throw new Error(`Negative index ${f} not allowed`);if(f>=n.length)for(let o=n.length;o<=f;o++)n.push(void 0);if(Array.isArray(t))if(typeof n[f]==typeof t[f])try{n[f]=b(V(n[f]),t[f],!0)}catch{throw Error("expected on array")}else n[f]=t;else n[f]=t}else if(a.type==="wildcard")if(Array.isArray(t))for(let o=0;o<n.length;o++)typeof n[o]=="object"?n[o]=b(n[o],t[o],!0):n[o]=t[o];else for(let o=0;o<n.length;o++)typeof n[o]=="object"?n[o]=b(n[o],t,!0):n[o]=t;break;default:throw new Error(`Invalid final segment type for set: ${a.type}`)}return e};var G=(e,r)=>{let t=O(e);if(t.length===0)return r;let i=r;for(let s=t.length-1;s>=0;s--){let l=t[s];if(l.type==="property")i={[String(l.value)]:i};else if(l.type==="index"){let a=parseInt(String(l.value)),n=[];n[a]=i,i=n}else l.type==="wildcard"?Array.isArray(i)?i=i:i=[i]:l.type==="slice"?Array.isArray(i)||(i=[i]):l.type==="union"?Array.isArray(i)||(i=[i]):l.type==="filter"?Array.isArray(i)||(i=[i]):l.type==="descendant"&&(i=i)}return i},Ne=(e,r,t={})=>$(e,r,{...t,preserveStructure:!1}),le=(e,r,t={})=>{if(Array.isArray(r))return r.map(s=>le(e,s,t));let i=$(e,r,{...t,preserveStructure:!1});return Array.isArray(i)?i.length>0?i.every(s=>s!==void 0):!1:i!==void 0},fe=(e,r,t={})=>{let{throwOnError:i=!1}=t;if(Array.isArray(r))return r.map(n=>fe(e,n,t));let s=O(r,{throwOnError:i});if(s.length===0)return!1;let l=s[s.length-1];if(s.some(n=>n.type==="wildcard"||n.type==="slice"||n.type==="union")){let n=N(e,r,t),f=!1;for(let o of n)ye(e,o)&&(f=!0);return f}let a=e;for(let n=0;n<s.length-1;n++){let f=s[n];if(a==null)return!1;switch(f.type){case"property":a=a[String(f.value)];break;case"index":if(!Array.isArray(a))return!1;let o=f.value;if(o<0||o>=a.length)return!1;a=a[o];break;default:return!1}}if(a==null)return!1;switch(l.type){case"property":if(String(l.value)in a)return delete a[String(l.value)],!0;break;case"index":if(!Array.isArray(a))return!1;let n=l.value;if(n>=0&&n<a.length)return a.splice(n,1),!0;break}return!1},ye=(e,r)=>{let t=O(r);if(t.length===0)return!1;let i=t[t.length-1],s=e;for(let l=0;l<t.length-1;l++){let a=t[l];if(s==null)return!1;switch(a.type){case"property":s=s[String(a.value)];break;case"index":if(!Array.isArray(s))return!1;let n=a.value;if(n<0||n>=s.length)return!1;s=s[n];break;default:return!1}}if(s==null)return!1;switch(i.type){case"property":if(String(i.value)in s)return delete s[String(i.value)],!0;break;case"index":if(!Array.isArray(s))return!1;let l=i.value;if(l>=0&&l<s.length)return s.splice(l,1),!0;break}return!1},N=(e,r,t={})=>{let{format:i="selector",maxDepth:s=20}=t;if(r&&Array.isArray(r)){let n=[];for(let f of r){let o=N(e,f,t);n.push(...o)}return n}if(r){let n=O(r,t);return F(e,n,0,s).map(o=>i==="selector"?o.path:o.stringPath)}let l=[],a=(n,f=[],o=[],u=0)=>{if(!(u>s)){if(f.length>0){let g=C(f);l.push({path:g,stringPath:o.join(".")})}if(n&&typeof n=="object")if(Array.isArray(n))for(let g=0;g<n.length;g++)a(n[g],[...f,{type:"index",value:g,raw:`[${g}]`}],[...o,`[${g}]`],u+1);else for(let g in n)n.hasOwnProperty(g)&&a(n[g],[...f,{type:"property",value:g,raw:g}],[...o,g],u+1)}};return a(e),l.map(n=>i==="selector"?n.path:n.stringPath)},_e=(e,r)=>N(e).filter(i=>{let s=$(e,i);return r(i,s)}),ue=(e,r=".")=>{let t={},i=(s,l=[])=>{if(s==null)return;let a=w(s,l,0,20);if(a!==void 0){t[C(l)]=a;return}if(Array.isArray(s))for(let n=0;n<s.length;n++){let f=[...l,{type:"index",value:n,raw:`[${n}]`}];i(s[n],f)}else if(m(s)){for(let f in s)if(s.hasOwnProperty(f)){let o=[...l,{type:"property",value:f,raw:f}];i(s[f],o)}let n=Object.getOwnPropertySymbols(s);for(let f of n){let o=[...l,{type:"property",value:f.toString(),raw:f.toString()}];i(s[f],o)}}else{let n=C(l);t[n]=s}};return i(e),t},Be=e=>{let r={};for(let t in e)H(r,t,e[t]);return r},qe=(...e)=>{let r={};for(let t of e){if(!m(t))continue;let i=ue(t);for(let s in i)H(r,s,i[s])}return r};function F(e,r,t,i,s=[],l=[]){if(t>i)return[];if(r.length===0)return[{value:e,path:C(s),stringPath:l.join(".")}];let a=r[0],n=r.slice(1),f=[];if(a.type==="descendant"){if(f.push(...F(e,n,t+1,i,s,l)),e&&typeof e=="object")if(Array.isArray(e))for(let o=0;o<e.length;o++)f.push(...F(e[o],r,t+1,i,[...s,{type:"index",value:o,raw:`[${o}]`}],[...l,`[${o}]`]));else for(let o in e)e.hasOwnProperty(o)&&f.push(...F(e[o],r,t+1,i,[...s,{type:"property",value:o,raw:o}],[...l,o]));return f}switch(a.type){case"property":if(e&&typeof e=="object"&&String(a.value)in e){let o=e[String(a.value)];f.push(...F(o,n,t+1,i,[...s,a],[...l,String(a.value)]))}break;case"index":if(Array.isArray(e)){let o=a.value;o>=0&&o<e.length&&f.push(...F(e[o],n,t+1,i,[...s,a],[...l,`[${o}]`]))}else if(e&&typeof e=="object"){let o=String(a.value);o in e&&f.push(...F(e[o],n,t+1,i,[...s,{...a,type:"property"}],[...l,o]))}break;case"wildcard":if(e&&typeof e=="object")if(Array.isArray(e))for(let o=0;o<e.length;o++)f.push(...F(e[o],n,t+1,i,[...s,{type:"index",value:o,raw:`[${o}]`}],[...l,`[${o}]`]));else for(let o in e)e.hasOwnProperty(o)&&f.push(...F(e[o],n,t+1,i,[...s,{type:"property",value:o,raw:o}],[...l,o]));break;case"slice":if(Array.isArray(e)){let[o,u]=a.value,g=Math.max(0,o),p=Math.min(e.length,u===1/0?e.length:u);for(let A=g;A<p;A++)f.push(...F(e[A],n,t+1,i,[...s,{type:"index",value:A,raw:`[${A}]`}],[...l,`[${A}]`]))}break;case"union":if(Array.isArray(e)){let o=a.value;for(let u of o)u>=0&&u<e.length&&f.push(...F(e[u],n,t+1,i,[...s,{type:"index",value:u,raw:`[${u}]`}],[...l,`[${u}]`]))}break;case"filter":if(Array.isArray(e)){let o=a.value;for(let u=0;u<e.length;u++)o(e[u])&&f.push(...F(e[u],n,t+1,i,[...s,{type:"index",value:u,raw:`[${u}]`}],[...l,`[${u}]`]))}break}return f}var Le=(e,r,t)=>{let i=$(e,r),s=t(i);return k(e,r,s)},ce=(e,r)=>{let t=r(e);return b(e,t,!0)},Je=(e,r)=>{let t=$(e,r);if(t!==void 0)return t===null?"null":Array.isArray(t)?"array":typeof t};export{P as ValueOfKey,We as castProps,qe as deepMergeWithArrays,fe as deletePath,_e as findPaths,ue as flattenWithArrays,G as fromPath,$ as get,N as getPaths,Je as getTypeAtPath,le as has,ne as isRangeObject,oe as mergeUpdateAtPath,Ne as select,H as set,ae as setArrayValueWithFilter,I as setAtPath,E as setValueAtIndex,k as setValueAtPath,M as setValueBetweenRange,ie as setValueBetweenRangeWithSubPath,Q as setValueWithArraySelectors,D as setValueWithFilter,z as setValueWithFilterWithSubPath,F as traverseWithPaths,Be as unflattenWithArrays,Le as update,ce as updateWithCallBack};
1
+ // src/lib/helpers.ts
2
+ import {
3
+ isDate
4
+ } from "@fluixi/utils/primitive";
5
+ import { isClass, isObject } from "@fluixi/utils/object";
6
+ import { isArray } from "@fluixi/utils/array";
7
+ import { isFunction } from "@fluixi/utils/functions";
8
+ function isPrimitive(v) {
9
+ const type = typeof v;
10
+ return v === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "bigint" || type === "undefined" || isDate(v);
11
+ }
12
+
13
+ // src/lib/object/utils.ts
14
+ var isObject2 = (value) => {
15
+ if (value == null) return false;
16
+ if (Array.isArray(value)) return false;
17
+ if (typeof value === "function") return false;
18
+ if (value instanceof Date) return false;
19
+ if (value instanceof RegExp) return false;
20
+ if (value instanceof Map) return false;
21
+ if (value instanceof Set) return false;
22
+ if (value instanceof Error) return false;
23
+ return typeof value === "object";
24
+ };
25
+ var traverseStructure = (current, segments, depth, maxDepth) => {
26
+ if (depth > maxDepth) return void 0;
27
+ if (segments.length === 0) return current;
28
+ const segment = segments[0];
29
+ const remaining = segments.slice(1);
30
+ if (segment.type === "descendant") {
31
+ const result = traverseStructure(current, remaining, depth + 1, maxDepth);
32
+ if (result !== void 0) {
33
+ return result;
34
+ }
35
+ if (current && typeof current === "object") {
36
+ if (Array.isArray(current)) {
37
+ const arrResult = [];
38
+ for (let i = 0; i < current.length; i++) {
39
+ const itemResult = traverseStructure(
40
+ current[i],
41
+ segments,
42
+ depth + 1,
43
+ maxDepth
44
+ );
45
+ if (itemResult !== void 0) {
46
+ arrResult[i] = itemResult;
47
+ }
48
+ }
49
+ return arrResult.length > 0 ? arrResult : void 0;
50
+ } else {
51
+ const objResult = {};
52
+ for (const key in current) {
53
+ if (current.hasOwnProperty(key)) {
54
+ const itemResult = traverseStructure(
55
+ current[key],
56
+ segments,
57
+ depth + 1,
58
+ maxDepth
59
+ );
60
+ if (itemResult !== void 0) {
61
+ objResult[key] = itemResult;
62
+ }
63
+ }
64
+ }
65
+ return Object.keys(objResult).length > 0 ? objResult : void 0;
66
+ }
67
+ }
68
+ return void 0;
69
+ }
70
+ switch (segment.type) {
71
+ case "property":
72
+ if (isObject2(current) && segment.value && String(segment.value) in current) {
73
+ const next = current[String(segment.value)];
74
+ const result = traverseStructure(next, remaining, depth + 1, maxDepth);
75
+ if (result !== void 0) {
76
+ return { [String(segment.value)]: result };
77
+ }
78
+ }
79
+ break;
80
+ case "index":
81
+ if (Array.isArray(current)) {
82
+ const index = segment.value;
83
+ if (index >= 0 && index < current.length) {
84
+ const result = traverseStructure(
85
+ current[index],
86
+ remaining,
87
+ depth + 1,
88
+ maxDepth
89
+ );
90
+ if (result !== void 0) {
91
+ const arr = new Array(current.length).filter(
92
+ (a) => a !== void 0
93
+ );
94
+ arr[index] = result;
95
+ return arr;
96
+ }
97
+ }
98
+ } else if (current && typeof current === "object") {
99
+ const key = String(segment.value);
100
+ if (key in current) {
101
+ const result = traverseStructure(
102
+ current[key],
103
+ remaining,
104
+ depth + 1,
105
+ maxDepth
106
+ );
107
+ if (result !== void 0) {
108
+ return { [key]: result };
109
+ }
110
+ }
111
+ }
112
+ break;
113
+ case "wildcard":
114
+ if (current && typeof current === "object") {
115
+ if (Array.isArray(current)) {
116
+ const arrResult = [];
117
+ let hasResults = false;
118
+ for (let i = 0; i < current.length; i++) {
119
+ const result = traverseStructure(
120
+ current[i],
121
+ remaining,
122
+ depth + 1,
123
+ maxDepth
124
+ );
125
+ if (result !== void 0) {
126
+ arrResult[i] = result;
127
+ hasResults = true;
128
+ }
129
+ }
130
+ return hasResults ? arrResult : void 0;
131
+ } else {
132
+ const objResult = {};
133
+ let hasResults = false;
134
+ for (const key in current) {
135
+ if (current.hasOwnProperty(key)) {
136
+ const result = traverseStructure(
137
+ current[key],
138
+ remaining,
139
+ depth + 1,
140
+ maxDepth
141
+ );
142
+ if (result !== void 0) {
143
+ objResult[key] = result;
144
+ hasResults = true;
145
+ }
146
+ }
147
+ }
148
+ return hasResults ? objResult : void 0;
149
+ }
150
+ }
151
+ break;
152
+ case "slice":
153
+ if (Array.isArray(current)) {
154
+ const [start, end] = segment.value;
155
+ const actualStart = Math.max(0, start);
156
+ const actualEnd = Math.min(
157
+ current.length,
158
+ end === Infinity ? current.length : end
159
+ );
160
+ const arrResult = [];
161
+ let hasResults = false;
162
+ for (let i = actualStart; i < actualEnd; i++) {
163
+ const result = traverseStructure(
164
+ current[i],
165
+ remaining,
166
+ depth + 1,
167
+ maxDepth
168
+ );
169
+ if (result !== void 0) {
170
+ arrResult[i] = result;
171
+ hasResults = true;
172
+ }
173
+ }
174
+ return hasResults ? arrResult : void 0;
175
+ }
176
+ break;
177
+ case "union":
178
+ if (Array.isArray(current)) {
179
+ const indices = segment.value;
180
+ const arrResult = [];
181
+ let hasResults = false;
182
+ for (const index of indices) {
183
+ if (index >= 0 && index < current.length) {
184
+ const result = traverseStructure(
185
+ current[index],
186
+ remaining,
187
+ depth + 1,
188
+ maxDepth
189
+ );
190
+ if (result !== void 0) {
191
+ arrResult[index] = result;
192
+ hasResults = true;
193
+ }
194
+ }
195
+ }
196
+ return hasResults ? arrResult : void 0;
197
+ }
198
+ break;
199
+ case "filter":
200
+ if (Array.isArray(current)) {
201
+ const filterFn = segment.value;
202
+ const arrResult = [];
203
+ let hasResults = false;
204
+ for (let i = 0; i < current.length; i++) {
205
+ if (filterFn(current[i])) {
206
+ const result = traverseStructure(
207
+ current[i],
208
+ remaining,
209
+ depth + 1,
210
+ maxDepth
211
+ );
212
+ if (result !== void 0) {
213
+ arrResult[i] = result;
214
+ hasResults = true;
215
+ }
216
+ }
217
+ }
218
+ return hasResults ? arrResult : void 0;
219
+ }
220
+ break;
221
+ }
222
+ return void 0;
223
+ };
224
+
225
+ // src/lib/object/clone.ts
226
+ var deepClone = (obj, skipKeys) => {
227
+ if (obj == null || typeof obj !== "object") {
228
+ return obj;
229
+ }
230
+ if (obj instanceof Date) {
231
+ return new Date(obj.getTime());
232
+ }
233
+ if (obj instanceof RegExp) {
234
+ return new RegExp(obj.source, obj.flags);
235
+ }
236
+ if (obj instanceof Map) {
237
+ const clone = /* @__PURE__ */ new Map();
238
+ obj.forEach((value, key) => {
239
+ if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
240
+ clone.set(key, deepClone(value));
241
+ }
242
+ });
243
+ return clone;
244
+ }
245
+ if (obj instanceof Set) {
246
+ const clone = /* @__PURE__ */ new Set();
247
+ obj.forEach((value) => {
248
+ clone.add(deepClone(value));
249
+ });
250
+ return clone;
251
+ }
252
+ if (Array.isArray(obj)) {
253
+ return Array.from(obj).map((item) => deepClone(item));
254
+ }
255
+ if (isObject2(obj)) {
256
+ const clone = {};
257
+ for (const key in obj) {
258
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
259
+ if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
260
+ clone[key] = deepClone(obj[key]);
261
+ }
262
+ }
263
+ }
264
+ const symbols = Object.getOwnPropertySymbols(obj);
265
+ for (const symbol of symbols) {
266
+ if (!skipKeys || !skipKeys.some((s) => s.toString() === symbol.toString())) {
267
+ clone[symbol] = deepClone(obj[symbol]);
268
+ }
269
+ }
270
+ return clone;
271
+ }
272
+ return obj;
273
+ };
274
+
275
+ // src/lib/object/diff.ts
276
+ var defaultEqualityFn = (a, b) => a === b;
277
+ var deepArrayEqual = (arr1, arr2) => {
278
+ if (arr1.length !== arr2.length) return false;
279
+ for (let i = 0; i < arr1.length; i++) {
280
+ if (Array.isArray(arr1[i]) && Array.isArray(arr2[i])) {
281
+ if (!deepArrayEqual(arr1[i], arr2[i])) return false;
282
+ } else if (isObject2(arr1[i]) && isObject2(arr2[i])) {
283
+ if (!deepObjectEqual(arr1[i], arr2[i])) return false;
284
+ } else if (arr1[i] !== arr2[i]) {
285
+ return false;
286
+ }
287
+ }
288
+ return true;
289
+ };
290
+ var deepObjectEqual = (obj1, obj2) => {
291
+ const keys1 = Object.keys(obj1);
292
+ const keys2 = Object.keys(obj2);
293
+ if (keys1.length !== keys2.length) return false;
294
+ for (const key of keys1) {
295
+ if (!(key in obj2)) return false;
296
+ const val1 = obj1[key];
297
+ const val2 = obj2[key];
298
+ if (Array.isArray(val1) && Array.isArray(val2)) {
299
+ if (!deepArrayEqual(val1, val2)) return false;
300
+ } else if (isObject2(val1) && isObject2(val2)) {
301
+ if (!deepObjectEqual(val1, val2)) return false;
302
+ } else if (val1 !== val2) {
303
+ return false;
304
+ }
305
+ }
306
+ return true;
307
+ };
308
+ var diffObject = (oldObj, newObj, options = {}) => {
309
+ const {
310
+ includeDeleted = false,
311
+ includeAdded = true,
312
+ deepArrayComparison = true,
313
+ equalityFn = defaultEqualityFn,
314
+ preserveStructure = false
315
+ } = options;
316
+ if (oldObj == null && newObj == null) {
317
+ return {};
318
+ }
319
+ if (oldObj == null) {
320
+ return includeAdded ? { ...newObj } : {};
321
+ }
322
+ if (newObj == null) {
323
+ if (includeDeleted) {
324
+ const result2 = {};
325
+ for (const key in oldObj) {
326
+ result2[key] = void 0;
327
+ }
328
+ return result2;
329
+ }
330
+ return {};
331
+ }
332
+ if (!isObject2(oldObj) || !isObject2(newObj)) {
333
+ return equalityFn(oldObj, newObj) ? {} : newObj;
334
+ }
335
+ const result = {};
336
+ const processedKeys = /* @__PURE__ */ new Set();
337
+ for (const key in newObj) {
338
+ processedKeys.add(key);
339
+ const oldValue = oldObj[key];
340
+ const newValue = newObj[key];
341
+ if (!(key in oldObj)) {
342
+ if (includeAdded) {
343
+ result[key] = newValue;
344
+ }
345
+ continue;
346
+ }
347
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
348
+ if (deepArrayComparison) {
349
+ if (!deepArrayEqual(oldValue, newValue)) {
350
+ result[key] = newValue;
351
+ } else if (preserveStructure) {
352
+ result[key] = void 0;
353
+ }
354
+ } else {
355
+ if (oldValue !== newValue) {
356
+ result[key] = newValue;
357
+ } else if (preserveStructure) {
358
+ result[key] = void 0;
359
+ }
360
+ }
361
+ continue;
362
+ }
363
+ if (isObject2(oldValue) && isObject2(newValue)) {
364
+ const nestedDiff = diffObject(oldValue, newValue, options);
365
+ if (Object.keys(nestedDiff).length > 0) {
366
+ result[key] = nestedDiff;
367
+ } else if (preserveStructure) {
368
+ result[key] = void 0;
369
+ }
370
+ continue;
371
+ }
372
+ if (!equalityFn(oldValue, newValue)) {
373
+ result[key] = newValue;
374
+ } else if (preserveStructure) {
375
+ result[key] = void 0;
376
+ }
377
+ }
378
+ if (includeDeleted) {
379
+ for (const key in oldObj) {
380
+ if (!processedKeys.has(key)) {
381
+ result[key] = void 0;
382
+ }
383
+ }
384
+ }
385
+ return result;
386
+ };
387
+ var diffObjectDetailed = (oldObj, newObj, options = {}) => {
388
+ const added = [];
389
+ const deleted = [];
390
+ const modified = [];
391
+ const changes = {};
392
+ const {
393
+ includeDeleted = false,
394
+ includeAdded = true,
395
+ deepArrayComparison = true,
396
+ equalityFn = defaultEqualityFn
397
+ } = options;
398
+ if (Array.isArray(oldObj) && Array.isArray(newObj)) {
399
+ const maxLength = Math.max(oldObj.length, newObj.length);
400
+ const arrayChanges = [];
401
+ let hasArrayChanges = false;
402
+ for (let i = 0; i < maxLength; i++) {
403
+ const indexPath = `[${i}]`;
404
+ if (i >= oldObj.length) {
405
+ added.push(indexPath);
406
+ arrayChanges[i] = newObj[i];
407
+ hasArrayChanges = true;
408
+ } else if (i >= newObj.length) {
409
+ deleted.push(indexPath);
410
+ hasArrayChanges = true;
411
+ } else {
412
+ const oldElement = oldObj[i];
413
+ const newElement = newObj[i];
414
+ if (isObject2(oldElement) && isObject2(newElement)) {
415
+ const nestedDiff = diffObjectDetailed(
416
+ oldElement,
417
+ newElement,
418
+ options
419
+ );
420
+ if (nestedDiff.hasChanges) {
421
+ modified.push(indexPath);
422
+ arrayChanges[i] = newElement;
423
+ hasArrayChanges = true;
424
+ } else {
425
+ arrayChanges[i] = oldElement;
426
+ }
427
+ } else if (Array.isArray(oldElement) && Array.isArray(newElement)) {
428
+ const nestedDiff = diffObjectDetailed(
429
+ oldElement,
430
+ newElement,
431
+ options
432
+ );
433
+ if (nestedDiff.hasChanges) {
434
+ modified.push(indexPath);
435
+ arrayChanges[i] = newElement;
436
+ hasArrayChanges = true;
437
+ } else {
438
+ arrayChanges[i] = oldElement;
439
+ }
440
+ } else if (!equalityFn(oldElement, newElement)) {
441
+ modified.push(indexPath);
442
+ arrayChanges[i] = newElement;
443
+ hasArrayChanges = true;
444
+ } else {
445
+ arrayChanges[i] = oldElement;
446
+ }
447
+ }
448
+ }
449
+ return {
450
+ changes: hasArrayChanges ? arrayChanges : {},
451
+ added,
452
+ deleted,
453
+ modified,
454
+ hasChanges: hasArrayChanges || deleted.length > 0
455
+ };
456
+ }
457
+ const collectDetailedPaths = (old, newVal, currentPath = "") => {
458
+ const result = {
459
+ added: [],
460
+ deleted: [],
461
+ modified: []
462
+ };
463
+ if (Array.isArray(old) && Array.isArray(newVal)) {
464
+ const maxLength = Math.max(old.length, newVal.length);
465
+ for (let i = 0; i < maxLength; i++) {
466
+ const indexPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;
467
+ if (i >= old.length) {
468
+ result.added.push(indexPath);
469
+ } else if (i >= newVal.length) {
470
+ result.deleted.push(indexPath);
471
+ } else {
472
+ const oldElement = old[i];
473
+ const newElement = newVal[i];
474
+ if (isObject2(oldElement) && isObject2(newElement)) {
475
+ const nested = collectDetailedPaths(
476
+ oldElement,
477
+ newElement,
478
+ indexPath
479
+ );
480
+ result.added.push(...nested.added);
481
+ result.deleted.push(...nested.deleted);
482
+ result.modified.push(...nested.modified);
483
+ } else if (Array.isArray(oldElement) && Array.isArray(newElement)) {
484
+ const nested = collectDetailedPaths(
485
+ oldElement,
486
+ newElement,
487
+ indexPath
488
+ );
489
+ result.added.push(...nested.added);
490
+ result.deleted.push(...nested.deleted);
491
+ result.modified.push(...nested.modified);
492
+ } else if (oldElement !== newElement) {
493
+ result.modified.push(indexPath);
494
+ }
495
+ }
496
+ }
497
+ return result;
498
+ }
499
+ if (isObject2(old) && isObject2(newVal)) {
500
+ const allKeys = /* @__PURE__ */ new Set([
501
+ ...Object.keys(old || {}),
502
+ ...Object.keys(newVal || {})
503
+ ]);
504
+ for (const key of allKeys) {
505
+ const oldValue = old?.[key];
506
+ const newValue = newVal?.[key];
507
+ const path = currentPath ? `${currentPath}.${key}` : key;
508
+ if (!(key in (old || {}))) {
509
+ result.added.push(path);
510
+ } else if (!(key in (newVal || {}))) {
511
+ result.deleted.push(path);
512
+ } else if (Array.isArray(oldValue) && Array.isArray(newValue)) {
513
+ if (!deepArrayEqual(oldValue, newValue)) {
514
+ const nested = collectDetailedPaths(oldValue, newValue, path);
515
+ result.added.push(...nested.added);
516
+ result.deleted.push(...nested.deleted);
517
+ result.modified.push(...nested.modified);
518
+ }
519
+ } else if (isObject2(oldValue) && isObject2(newValue)) {
520
+ const nested = collectDetailedPaths(oldValue, newValue, path);
521
+ result.added.push(...nested.added);
522
+ result.deleted.push(...nested.deleted);
523
+ result.modified.push(...nested.modified);
524
+ } else if (oldValue !== newValue) {
525
+ result.modified.push(path);
526
+ }
527
+ }
528
+ }
529
+ return result;
530
+ };
531
+ if (oldObj == null && newObj == null) {
532
+ return { changes: {}, added, deleted, modified, hasChanges: false };
533
+ }
534
+ if (oldObj == null) {
535
+ if (includeAdded && newObj) {
536
+ for (const key in newObj) {
537
+ added.push(key);
538
+ changes[key] = newObj[key];
539
+ }
540
+ }
541
+ return {
542
+ changes,
543
+ added,
544
+ deleted,
545
+ modified,
546
+ hasChanges: added.length > 0
547
+ };
548
+ }
549
+ if (newObj == null) {
550
+ if (includeDeleted) {
551
+ for (const key in oldObj) {
552
+ deleted.push(key);
553
+ changes[key] = void 0;
554
+ }
555
+ }
556
+ return {
557
+ changes,
558
+ added,
559
+ deleted,
560
+ modified,
561
+ hasChanges: deleted.length > 0
562
+ };
563
+ }
564
+ const processedKeys = /* @__PURE__ */ new Set();
565
+ for (const key in newObj) {
566
+ processedKeys.add(key);
567
+ const oldValue = oldObj[key];
568
+ const newValue = newObj[key];
569
+ if (!(key in oldObj)) {
570
+ if (includeAdded) {
571
+ added.push(key);
572
+ changes[key] = newValue;
573
+ }
574
+ continue;
575
+ }
576
+ let isDifferent = false;
577
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
578
+ isDifferent = deepArrayComparison ? !deepArrayEqual(oldValue, newValue) : oldValue !== newValue;
579
+ if (isDifferent) {
580
+ const paths = collectDetailedPaths(oldValue, newValue, key);
581
+ added.push(...paths.added);
582
+ deleted.push(...paths.deleted);
583
+ modified.push(...paths.modified);
584
+ changes[key] = newValue;
585
+ }
586
+ } else if (isObject2(oldValue) && isObject2(newValue)) {
587
+ const nestedDiff = diffObject(oldValue, newValue, options);
588
+ isDifferent = Object.keys(nestedDiff).length > 0;
589
+ if (isDifferent) {
590
+ const paths = collectDetailedPaths(oldValue, newValue, key);
591
+ added.push(...paths.added);
592
+ deleted.push(...paths.deleted);
593
+ modified.push(...paths.modified);
594
+ changes[key] = nestedDiff;
595
+ }
596
+ } else {
597
+ isDifferent = !equalityFn(oldValue, newValue);
598
+ if (isDifferent) {
599
+ modified.push(key);
600
+ changes[key] = newValue;
601
+ }
602
+ }
603
+ }
604
+ for (const key in oldObj) {
605
+ if (!processedKeys.has(key)) {
606
+ deleted.push(key);
607
+ changes[key] = void 0;
608
+ }
609
+ }
610
+ return {
611
+ changes,
612
+ added,
613
+ deleted,
614
+ modified,
615
+ hasChanges: added.length > 0 || deleted.length > 0 || modified.length > 0
616
+ };
617
+ };
618
+ function isApplyDiff(value) {
619
+ if (value && (value.diff || value.changes) && (value.modified || value.deleted || value.hasChanges)) {
620
+ return true;
621
+ }
622
+ return false;
623
+ }
624
+ var applyDiff = (baseObj, option, keepRefParam) => {
625
+ if (!isApplyDiff(option)) {
626
+ const diff2 = option;
627
+ const shouldKeepRef2 = keepRefParam || false;
628
+ if (Array.isArray(baseObj) && Array.isArray(diff2)) {
629
+ const result3 = shouldKeepRef2 ? baseObj : [...baseObj];
630
+ if (diff2.length < result3.length) {
631
+ result3.length = diff2.length;
632
+ }
633
+ for (let i = 0; i < diff2.length; i++) {
634
+ const diffValue = diff2[i];
635
+ if (diffValue === void 0) {
636
+ continue;
637
+ }
638
+ if (isObject2(result3[i]) && isObject2(diffValue)) {
639
+ result3[i] = applyDiff(result3[i], diffValue, shouldKeepRef2);
640
+ } else if (Array.isArray(result3[i]) && Array.isArray(diffValue)) {
641
+ result3[i] = applyDiff(
642
+ result3[i],
643
+ diffValue,
644
+ shouldKeepRef2
645
+ );
646
+ } else {
647
+ result3[i] = diffValue;
648
+ }
649
+ }
650
+ return result3;
651
+ }
652
+ if (!isObject2(baseObj)) return diff2;
653
+ if (!isObject2(diff2)) return baseObj;
654
+ const result2 = shouldKeepRef2 ? baseObj : { ...baseObj };
655
+ for (const key in diff2) {
656
+ const diffValue = diff2[key];
657
+ if (diffValue === void 0) {
658
+ delete result2[key];
659
+ } else if (Array.isArray(result2[key]) && Array.isArray(diffValue)) {
660
+ result2[key] = applyDiff(result2[key], diffValue, shouldKeepRef2);
661
+ } else if (isObject2(result2[key]) && isObject2(diffValue)) {
662
+ result2[key] = applyDiff(result2[key], diffValue, shouldKeepRef2);
663
+ } else {
664
+ result2[key] = diffValue;
665
+ }
666
+ }
667
+ return result2;
668
+ }
669
+ const {
670
+ diff,
671
+ added = [],
672
+ deleted = [],
673
+ modified = [],
674
+ changes,
675
+ keepRef: keepRefOption
676
+ } = option;
677
+ const shouldKeepRef = keepRefParam !== void 0 ? keepRefParam : keepRefOption;
678
+ const diffToApply = changes || diff;
679
+ if (!diffToApply) return baseObj;
680
+ const addedSet = new Set(added);
681
+ const deletedSet = new Set(deleted);
682
+ const modifiedSet = new Set(modified);
683
+ const shouldApplyPath = (path) => {
684
+ if (added.length === 0 && deleted.length === 0 && modified.length === 0) {
685
+ return true;
686
+ }
687
+ const pathParts = path.split(/[.\[\]]+/).filter(Boolean);
688
+ for (let i = 0; i <= pathParts.length; i++) {
689
+ const partialPath = pathParts.slice(0, i).join(".");
690
+ const bracketPath = pathParts.slice(0, i).map((p, idx) => /^\d+$/.test(p) ? `[${p}]` : idx > 0 ? `.${p}` : p).join("");
691
+ if (addedSet.has(partialPath) || addedSet.has(bracketPath) || deletedSet.has(partialPath) || deletedSet.has(bracketPath) || modifiedSet.has(partialPath) || modifiedSet.has(bracketPath)) {
692
+ return true;
693
+ }
694
+ }
695
+ return false;
696
+ };
697
+ if (Array.isArray(baseObj) && Array.isArray(diffToApply)) {
698
+ const result2 = shouldKeepRef ? baseObj : [...baseObj];
699
+ result2.length = diffToApply.length;
700
+ for (let i = 0; i < diffToApply.length; i++) {
701
+ const indexPath = `[${i}]`;
702
+ const diffValue = diffToApply[i];
703
+ if (diffValue === void 0) {
704
+ continue;
705
+ }
706
+ if (!shouldApplyPath(indexPath)) {
707
+ continue;
708
+ }
709
+ if (isObject2(result2[i]) && isObject2(diffValue)) {
710
+ result2[i] = applyDiff(result2[i], diffValue, shouldKeepRef);
711
+ } else if (Array.isArray(result2[i]) && Array.isArray(diffValue)) {
712
+ result2[i] = applyDiff(
713
+ result2[i],
714
+ diffValue,
715
+ shouldKeepRef
716
+ );
717
+ } else {
718
+ result2[i] = diffValue;
719
+ }
720
+ }
721
+ return result2;
722
+ }
723
+ if (!isObject2(baseObj)) return diffToApply;
724
+ if (!isObject2(diffToApply)) return baseObj;
725
+ const result = shouldKeepRef ? baseObj : { ...baseObj };
726
+ for (const path of deleted) {
727
+ if (path.includes(".") || path.includes("[")) continue;
728
+ if (shouldApplyPath(path)) {
729
+ delete result[path];
730
+ }
731
+ }
732
+ for (const key in diffToApply) {
733
+ const diffValue = diffToApply[key];
734
+ if (!shouldApplyPath(key)) {
735
+ continue;
736
+ }
737
+ if (diffValue === void 0) {
738
+ delete result[key];
739
+ } else if (Array.isArray(result[key]) && Array.isArray(diffValue)) {
740
+ result[key] = applyDiff(result[key], diffValue, shouldKeepRef);
741
+ } else if (isObject2(result[key]) && isObject2(diffValue)) {
742
+ result[key] = applyDiff(result[key], diffValue, shouldKeepRef);
743
+ } else {
744
+ result[key] = diffValue;
745
+ }
746
+ }
747
+ return result;
748
+ };
749
+
750
+ // src/lib/object/selector.ts
751
+ var parseSelector = (selector, options = {}) => {
752
+ const { type = "auto", throwOnError = false } = options;
753
+ if (!selector || typeof selector !== "string") {
754
+ return [];
755
+ }
756
+ const segments = [];
757
+ let current = "";
758
+ let inBrackets = false;
759
+ let inQuotes = false;
760
+ let quoteChar = "";
761
+ let bracketContent = "";
762
+ let bracketDepth = 0;
763
+ const detectType = (str) => {
764
+ if (str.includes("..")) return "descendant";
765
+ if (str.includes("[?(")) return "filter";
766
+ if (str.includes("[:") || str.includes("[0:")) return "slice";
767
+ if (str.includes("[,") || str.includes("[0,1]")) return "union";
768
+ if (str.includes("[*]") || str.includes(".*.")) return "wildcard";
769
+ if (str.includes("[]")) return "array-wildcard";
770
+ if (str.includes("[") && str.includes("]")) return "bracket";
771
+ return "dot";
772
+ };
773
+ const actualType = type === "auto" ? detectType(selector) : type;
774
+ const parseBracketContent = (content) => {
775
+ const trimmed = content.trim();
776
+ if (trimmed === "*" || trimmed === "") {
777
+ return {
778
+ type: "wildcard",
779
+ value: trimmed === "" ? "[]" : "*",
780
+ raw: trimmed === "" ? "[]" : content
781
+ };
782
+ }
783
+ if (trimmed === "[]") {
784
+ return { type: "wildcard", value: "[]", raw: content };
785
+ }
786
+ if (/^-?\d+$/.test(trimmed)) {
787
+ return { type: "index", value: parseInt(trimmed, 10), raw: content };
788
+ }
789
+ if (trimmed.includes(":")) {
790
+ const parts = trimmed.split(":").map((p) => p.trim());
791
+ const start = parts[0] === "" ? 0 : parseInt(parts[0], 10);
792
+ const end = parts[1] === "" ? Infinity : parseInt(parts[1], 10);
793
+ if (isNaN(start) || isNaN(end)) {
794
+ if (throwOnError) throw new Error(`Invalid slice notation: ${content}`);
795
+ return { type: "wildcard", value: "*", raw: content };
796
+ }
797
+ return { type: "slice", value: [start, end], raw: content };
798
+ }
799
+ if (trimmed.includes(",")) {
800
+ const indices = trimmed.split(",").map((p) => {
801
+ const num = parseInt(p.trim(), 10);
802
+ return isNaN(num) ? -1 : num;
803
+ }).filter((n) => n >= 0);
804
+ if (indices.length === 0) {
805
+ if (throwOnError) throw new Error(`Invalid union notation: ${content}`);
806
+ return { type: "wildcard", value: "*", raw: content };
807
+ }
808
+ return { type: "union", value: indices, raw: content };
809
+ }
810
+ if (trimmed.startsWith("?(") && trimmed.endsWith(")")) {
811
+ const expr = trimmed.slice(2, -1);
812
+ try {
813
+ const filterFn = createFilterFunction(expr);
814
+ return { type: "filter", value: filterFn, raw: content };
815
+ } catch (error) {
816
+ if (throwOnError) throw error;
817
+ return { type: "wildcard", value: "*", raw: content };
818
+ }
819
+ }
820
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
821
+ return { type: "property", value: trimmed.slice(1, -1), raw: content };
822
+ }
823
+ return { type: "property", value: trimmed, raw: content };
824
+ };
825
+ for (let i = 0; i < selector.length; i++) {
826
+ const char = selector[i];
827
+ const nextChar = selector[i + 1];
828
+ if ((char === '"' || char === "'") && !inQuotes) {
829
+ inQuotes = true;
830
+ quoteChar = char;
831
+ continue;
832
+ } else if (char === quoteChar && inQuotes) {
833
+ inQuotes = false;
834
+ quoteChar = "";
835
+ if (!(char === '"' || char === "'")) {
836
+ if (inBrackets) {
837
+ bracketContent += char;
838
+ } else {
839
+ current += char;
840
+ }
841
+ }
842
+ continue;
843
+ }
844
+ if (inQuotes) {
845
+ if (inBrackets) {
846
+ bracketContent += char;
847
+ } else {
848
+ current += char;
849
+ }
850
+ continue;
851
+ }
852
+ if (char === "[" && !inBrackets) {
853
+ if (current) {
854
+ segments.push({ type: "property", value: current, raw: current });
855
+ current = "";
856
+ }
857
+ inBrackets = true;
858
+ bracketContent = "";
859
+ continue;
860
+ }
861
+ if (char === "]" && inBrackets && !inQuotes) {
862
+ inBrackets = false;
863
+ const segment = parseBracketContent(bracketContent);
864
+ segments.push(segment);
865
+ continue;
866
+ }
867
+ let lastDot = segments.length > 0 ? segments[segments.length - 1] : null;
868
+ if (char === "." && !inBrackets && !inQuotes) {
869
+ if (nextChar === ".") {
870
+ const l = selector.split("..")[0];
871
+ segments.push({ type: "property", value: l, raw: l });
872
+ segments.push({ type: "descendant", value: "..", raw: ".." });
873
+ i++;
874
+ } else if (current) {
875
+ if (current === "*") {
876
+ segments.push({ type: "wildcard", value: current, raw: current });
877
+ } else {
878
+ segments.push({ type: "property", value: current, raw: current });
879
+ }
880
+ current = "";
881
+ }
882
+ continue;
883
+ }
884
+ if (inBrackets) {
885
+ bracketContent += char;
886
+ } else {
887
+ if (lastDot && lastDot.type !== "descendant") {
888
+ current += char;
889
+ } else {
890
+ const l = selector.split(lastDot?.raw)[1];
891
+ if (l !== void 0) {
892
+ current = l;
893
+ } else {
894
+ current += char;
895
+ }
896
+ }
897
+ }
898
+ }
899
+ if (current) {
900
+ segments.push({ type: "property", value: current, raw: current });
901
+ }
902
+ return segments.map((segment) => {
903
+ if (segment.type === "property" && typeof segment.value === "string") {
904
+ if (/^-?\d+$/.test(segment.value)) {
905
+ const num = parseInt(segment.value, 10);
906
+ if (!isNaN(num)) {
907
+ return { ...segment, type: "index", value: num };
908
+ }
909
+ }
910
+ }
911
+ return segment;
912
+ });
913
+ };
914
+ var createFilterFunction = (expr) => {
915
+ const safeExpr = expr.replace(/@\.([a-zA-Z_$][\w$]*)/g, (_, prop) => `item.${prop}`).replace(/@/g, "item");
916
+ try {
917
+ return new Function("item", `return ${safeExpr}`);
918
+ } catch (error) {
919
+ throw new Error(`Invalid filter expression: ${expr}`);
920
+ }
921
+ };
922
+ var stringifySelector = (segments) => {
923
+ const parts = [];
924
+ for (let i = 0; i < segments.length; i++) {
925
+ const segment = segments[i];
926
+ const prevSegment = i > 0 ? segments[i - 1] : null;
927
+ switch (segment.type) {
928
+ case "property":
929
+ const needsQuotes = /[\.\[\]\s]/.test(String(segment.value));
930
+ if (needsQuotes) {
931
+ parts.push(`["${segment.value}"]`);
932
+ } else {
933
+ if (prevSegment && prevSegment.type !== "descendant") {
934
+ parts.push(".");
935
+ }
936
+ parts.push(String(segment.value));
937
+ }
938
+ break;
939
+ case "index":
940
+ parts.push(`[${segment.value}]`);
941
+ break;
942
+ case "wildcard":
943
+ if (segment.value === "[]") {
944
+ parts.push("[]");
945
+ } else {
946
+ parts.push("[*]");
947
+ }
948
+ break;
949
+ case "slice":
950
+ const [start, end] = segment.value;
951
+ parts.push(`[${start}:${end === Infinity ? "" : end}]`);
952
+ break;
953
+ case "union":
954
+ const indices = segment.value;
955
+ parts.push(`[${indices.join(",")}]`);
956
+ break;
957
+ case "filter":
958
+ parts.push(`[?(${segment.raw?.slice(2, -1) || ""})]`);
959
+ break;
960
+ case "descendant":
961
+ parts.push("..");
962
+ break;
963
+ }
964
+ }
965
+ return parts.join("").replace(/\.\[/g, "[");
966
+ };
967
+
968
+ // src/lib/object/merge.ts
969
+ var mergeIntoStructure = (target, selector, value) => {
970
+ const segments = parseSelector(selector);
971
+ let current = target;
972
+ for (let i = 0; i < segments.length; i++) {
973
+ const segment = segments[i];
974
+ const isLast = i === segments.length - 1;
975
+ switch (segment.type) {
976
+ case "property":
977
+ if (isLast) {
978
+ current[String(segment.value)] = value;
979
+ } else {
980
+ if (!current[String(segment.value)]) {
981
+ const nextSegment = segments[i + 1];
982
+ current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
983
+ }
984
+ current = current[String(segment.value)];
985
+ }
986
+ break;
987
+ case "index":
988
+ if (!Array.isArray(current)) {
989
+ current = [];
990
+ }
991
+ const index = segment.value;
992
+ if (isLast) {
993
+ if (index >= current.length) {
994
+ for (let j = current.length; j <= index; j++) {
995
+ current.push(void 0);
996
+ }
997
+ }
998
+ current[index] = value;
999
+ } else {
1000
+ if (!current[index]) {
1001
+ const nextSegment = segments[i + 1];
1002
+ current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
1003
+ }
1004
+ current = current[index];
1005
+ }
1006
+ break;
1007
+ case "wildcard":
1008
+ if (Array.isArray(current)) {
1009
+ if (isLast) {
1010
+ for (let j = 0; j < current.length; j++) {
1011
+ current[j] = value;
1012
+ }
1013
+ } else {
1014
+ const nextSegment = segments[i + 1];
1015
+ for (let j = 0; j < current.length; j++) {
1016
+ if (!current[j]) {
1017
+ current[j] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
1018
+ }
1019
+ }
1020
+ if (current.length > 0) {
1021
+ current = current[0];
1022
+ }
1023
+ }
1024
+ }
1025
+ break;
1026
+ }
1027
+ }
1028
+ };
1029
+
1030
+ // src/lib/object/getter-setter.ts
1031
+ function get(obj, selector, options = {}) {
1032
+ const {
1033
+ preserveStructure,
1034
+ multiple,
1035
+ throwOnError = false,
1036
+ defaultValue,
1037
+ maxDepth = 20
1038
+ } = options;
1039
+ if (!obj || typeof obj !== "object") {
1040
+ return defaultValue;
1041
+ }
1042
+ if (!selector) {
1043
+ return obj;
1044
+ }
1045
+ if (Array.isArray(selector)) {
1046
+ if (preserveStructure) {
1047
+ const result2 = {};
1048
+ for (const sel of selector) {
1049
+ const value = get(obj, sel, { ...options, preserveStructure: false });
1050
+ if (value !== void 0) {
1051
+ mergeIntoStructure(result2, sel, value);
1052
+ }
1053
+ }
1054
+ return result2;
1055
+ } else {
1056
+ return selector.map(
1057
+ (sel) => get(obj, sel, { ...options, preserveStructure: false })
1058
+ );
1059
+ }
1060
+ }
1061
+ const segments = parseSelector(selector, { ...options, throwOnError });
1062
+ if (segments.length === 0) {
1063
+ return obj;
1064
+ }
1065
+ if (typeof preserveStructure === "undefined" || preserveStructure === false) {
1066
+ const v = ValueOfKey(obj, selector);
1067
+ if (multiple === false && Array.isArray(v)) {
1068
+ return v[0];
1069
+ }
1070
+ if (v === void 0 && defaultValue !== void 0) {
1071
+ return defaultValue;
1072
+ }
1073
+ return v;
1074
+ }
1075
+ const result = traverseStructure(obj, segments, 0, maxDepth);
1076
+ if (result === void 0 && defaultValue !== void 0) {
1077
+ return defaultValue;
1078
+ }
1079
+ return result;
1080
+ }
1081
+ function set(_obj, first, second, third, fourth) {
1082
+ let obj = deepClone(_obj);
1083
+ const params = [];
1084
+ if (typeof first !== "undefined") params.push(first);
1085
+ if (typeof second !== "undefined") params.push(second);
1086
+ if (typeof third !== "undefined") params.push(third);
1087
+ if (typeof fourth !== "undefined") params.push(fourth);
1088
+ if (isPrimitive(obj)) {
1089
+ if (typeof first === "function") {
1090
+ return first(obj);
1091
+ }
1092
+ return first;
1093
+ }
1094
+ if (params.length === 1) {
1095
+ if (typeof params[0] === "function") {
1096
+ return updateWithCallBack(obj, params[0]);
1097
+ }
1098
+ if (Array.isArray(params[0])) {
1099
+ if (Array.isArray(obj)) {
1100
+ if (first.length === 0) {
1101
+ for (let i = 0; i < obj.length; i++) {
1102
+ obj.pop();
1103
+ }
1104
+ } else {
1105
+ const diff = diffObjectDetailed([...obj], [...params[0]]);
1106
+ if (diff.hasChanges) {
1107
+ applyDiff(obj, [...params[0]], true);
1108
+ }
1109
+ return obj;
1110
+ }
1111
+ }
1112
+ } else if (typeof params[0] === "object" && !Array.isArray(params[0])) {
1113
+ if (typeof obj === "object" && !Array.isArray(obj)) {
1114
+ applyDiff(obj, params[0], true);
1115
+ }
1116
+ } else {
1117
+ obj = params[0];
1118
+ }
1119
+ return obj;
1120
+ }
1121
+ if (Array.isArray(obj)) {
1122
+ if (typeof first === "string" && (isArrayOfString(second) || typeof second === "string") && params.length === 3) {
1123
+ if (Array.isArray(second)) {
1124
+ for (let i = 0; i < second.length; i++) {
1125
+ setValueAtPath(obj, first, third, second[i]);
1126
+ }
1127
+ return obj;
1128
+ }
1129
+ return setValueAtPath(obj, first, third, second);
1130
+ }
1131
+ if (typeof first === "string" && typeof second === "function" && params.length === 2) {
1132
+ return setValueAtPath(obj, first, second);
1133
+ }
1134
+ }
1135
+ if ((typeof first === "string" || typeof first === "number") && (params.length === 2 || params.length === 3)) {
1136
+ if (isRangeObject(second)) {
1137
+ return setValueBetweenRange(
1138
+ obj,
1139
+ first,
1140
+ second,
1141
+ third
1142
+ );
1143
+ }
1144
+ if (typeof first === "number") {
1145
+ if (typeof third !== "undefined") {
1146
+ return setValueAtPath(obj, `[${first}].${second}`, third);
1147
+ } else {
1148
+ return setValueAtPath(obj, `[${first}]`, second, third);
1149
+ }
1150
+ }
1151
+ if (typeof second === "number" && typeof third !== "undefined") {
1152
+ return setValueAtIndex(obj, first, second, third);
1153
+ }
1154
+ if (Array.isArray(second) && second.length > 0 && second.every((s) => typeof s === "number")) {
1155
+ return setValueWithIndices(obj, first, second, third);
1156
+ }
1157
+ if (typeof third !== "undefined" && typeof second === "function") {
1158
+ return setValueWithFilter(obj, first, second, third);
1159
+ }
1160
+ return setValueAtPath(obj, first, second, third);
1161
+ }
1162
+ if (typeof first === "string" && typeof second === "number") {
1163
+ if (params.length === 3) {
1164
+ return setValueAtIndex(obj, first, second, third);
1165
+ } else if (params.length === 4) {
1166
+ return setIndexWithSubPath(
1167
+ obj,
1168
+ first,
1169
+ second,
1170
+ third,
1171
+ fourth
1172
+ );
1173
+ }
1174
+ }
1175
+ if (typeof first === "string" && Array.isArray(second)) {
1176
+ if (params.length === 3) {
1177
+ return setValueWithIndices(obj, first, second, third);
1178
+ } else if (params.length === 4) {
1179
+ return setValueWithIndicesWithSubPath(
1180
+ obj,
1181
+ first,
1182
+ second,
1183
+ third,
1184
+ fourth
1185
+ );
1186
+ }
1187
+ }
1188
+ if (typeof first === "string" && typeof second === "object" && !Array.isArray(second) && second !== null) {
1189
+ const range = second;
1190
+ if ("from" in range || "to" in range) {
1191
+ if (params.length === 3) {
1192
+ return setValueBetweenRange(obj, first, range, third);
1193
+ } else if (params.length === 4) {
1194
+ return setValueBetweenRangeWithSubPath(
1195
+ obj,
1196
+ first,
1197
+ range,
1198
+ third,
1199
+ fourth
1200
+ );
1201
+ }
1202
+ }
1203
+ }
1204
+ if (typeof first === "object" && !Array.isArray(first) && params.length === 1) {
1205
+ return applyDiff(obj, first, true);
1206
+ }
1207
+ if (typeof first === "string" && typeof second === "object" && !Array.isArray(second) && params.length === 2) {
1208
+ return mergeUpdateAtPath(obj, first, second);
1209
+ }
1210
+ if (typeof first === "string" && typeof second === "function") {
1211
+ if (params.length === 3) {
1212
+ return setValueWithFilter(
1213
+ obj,
1214
+ first,
1215
+ second,
1216
+ third
1217
+ );
1218
+ } else if (params.length === 4) {
1219
+ return setValueWithFilterWithSubPath(
1220
+ obj,
1221
+ first,
1222
+ second,
1223
+ third,
1224
+ fourth
1225
+ );
1226
+ }
1227
+ }
1228
+ if (typeof first === "function" && typeof second === "string") {
1229
+ if (params.length === 3) {
1230
+ return setArrayValueWithFilter(
1231
+ obj,
1232
+ first,
1233
+ second,
1234
+ third
1235
+ );
1236
+ } else if (params.length === 4) {
1237
+ return setValueWithFilterWithSubPath(
1238
+ obj,
1239
+ second,
1240
+ first,
1241
+ third,
1242
+ fourth
1243
+ );
1244
+ }
1245
+ }
1246
+ if (Array.isArray(first)) {
1247
+ if (params.length === 2 && typeof second === "object" && !Array.isArray(second)) {
1248
+ return setValueWithArraySelectors(obj, first, second);
1249
+ } else if (params.length === 2) {
1250
+ return setValueWithArraySelectors(obj, first, second);
1251
+ }
1252
+ }
1253
+ throw new Error(`Invalid set parameters: ${JSON.stringify(params)}`);
1254
+ }
1255
+ function handleFunctionParams(selector, data, value, isArray2 = false) {
1256
+ const paths = parseSelector(selector);
1257
+ if (paths.length === 0) return value;
1258
+ const isWildcard = paths[paths.length - 1].type === "wildcard";
1259
+ const containWildcard = paths.some((path) => path.type === "wildcard") && Array.isArray(data);
1260
+ let finalValue;
1261
+ if (isWildcard || containWildcard && isArray2 || containWildcard && paths.length === 2) {
1262
+ if (Array.isArray(data)) {
1263
+ for (let i = 0; i < data.length; i++) {
1264
+ const v = typeof value === "function" ? value(data[i]) : typeof data[i] === "object" ? applyDiff(data[i], value, true) : value;
1265
+ if (!finalValue) finalValue = [];
1266
+ finalValue.push(v);
1267
+ }
1268
+ }
1269
+ }
1270
+ if (!isWildcard && !finalValue) {
1271
+ finalValue = typeof value === "function" ? value(data) : value;
1272
+ }
1273
+ return finalValue;
1274
+ }
1275
+ function isRangeObject(obj) {
1276
+ return typeof obj === "object" && obj !== null && "from" in obj && "to" in obj && typeof obj.from === "number" && typeof obj.to === "number" && obj.from < obj.to && obj.from >= 0 && obj.to > 0;
1277
+ }
1278
+ function isArrayOfString(value) {
1279
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
1280
+ }
1281
+ function setValueAtPath(obj, selector, value, subPath) {
1282
+ const paths = parseSelector(selector);
1283
+ let target = ValueOfKey(obj, selector, {
1284
+ paths,
1285
+ createMissing: true
1286
+ });
1287
+ let get_value;
1288
+ if (subPath) {
1289
+ if (typeof value === "function") {
1290
+ get_value = get(target, subPath);
1291
+ }
1292
+ }
1293
+ const data = subPath ? get_value : target;
1294
+ const finalValue = handleFunctionParams(
1295
+ selector,
1296
+ data,
1297
+ value,
1298
+ Array.isArray(obj)
1299
+ );
1300
+ if (subPath) {
1301
+ const result = setAtPath(obj, `${selector}.${subPath}`, finalValue, {
1302
+ createMissing: true
1303
+ });
1304
+ return result;
1305
+ } else {
1306
+ const r = setAtPath(obj, selector, finalValue, { createMissing: true });
1307
+ return r;
1308
+ }
1309
+ }
1310
+ function setValueAtIndex(obj, selector, index, value) {
1311
+ const target = ValueOfKey(obj, selector, { createMissing: true });
1312
+ if (!Array.isArray(target)) {
1313
+ throw new Error(`Target at ${selector} is not an array ${index}`);
1314
+ }
1315
+ const target_copy = structuredClone(target);
1316
+ const finalValue = handleFunctionParams(selector, target_copy[index], value);
1317
+ if (index < 0) {
1318
+ const actualIndex = target.length + index;
1319
+ if (actualIndex < 0) {
1320
+ throw new Error(`Index ${index} is out of bounds`);
1321
+ }
1322
+ return setAtPath(obj, `${selector}[${actualIndex}]`, finalValue, {
1323
+ createMissing: true
1324
+ });
1325
+ }
1326
+ return setAtPath(obj, `${selector}[${index}]`, finalValue, {
1327
+ createMissing: true
1328
+ });
1329
+ }
1330
+ var setIndexWithSubPath = (obj, selector, index, subPath, value) => {
1331
+ if (typeof subPath === "function") {
1332
+ return setValueAtPath(obj, `${selector}[${index}]`, subPath);
1333
+ }
1334
+ if (typeof subPath === "string") {
1335
+ return setValueAtPath(obj, `${selector}[${index}]`, value, subPath);
1336
+ }
1337
+ return null;
1338
+ };
1339
+ var setValueWithIndices = (obj, selector, indices, value) => {
1340
+ const target = ValueOfKey(obj, selector);
1341
+ if (!Array.isArray(target)) {
1342
+ throw new Error(`Target at ${selector} is not an array`);
1343
+ }
1344
+ for (const index of indices) {
1345
+ if (typeof index === "number") {
1346
+ setValueAtIndex(obj, selector, index, value);
1347
+ } else if (typeof index === "string") {
1348
+ setValueAtPath(obj, selector, value, index);
1349
+ }
1350
+ }
1351
+ return obj;
1352
+ };
1353
+ var setValueWithIndicesWithSubPath = (obj, selector, indices, subPath, value) => {
1354
+ const updater = (prev) => {
1355
+ const newValue = typeof value === "function" ? value(prev ? ValueOfKey(prev, subPath) : void 0) : value;
1356
+ const result = prev ? { ...prev } : {};
1357
+ setAtPath(result, subPath, newValue);
1358
+ return result;
1359
+ };
1360
+ return setValueWithIndices(obj, selector, indices, updater);
1361
+ };
1362
+ function setValueBetweenRange(obj, selector, range, value) {
1363
+ const target = ValueOfKey(obj, selector);
1364
+ if (!Array.isArray(target)) {
1365
+ throw new Error(`Target at ${selector} is not an array`);
1366
+ }
1367
+ const from = range.from ?? 0;
1368
+ const to = range.to ?? target.length - 1;
1369
+ const by = range.by ?? 1;
1370
+ const indices = [];
1371
+ for (let i = from; i <= to; i += by) {
1372
+ if (i >= 0 && i < target.length) {
1373
+ indices.push(i);
1374
+ }
1375
+ }
1376
+ return setValueWithIndices(obj, selector, indices, value);
1377
+ }
1378
+ var setValueBetweenRangeWithSubPath = (obj, selector, range, subPath, value) => {
1379
+ const updater = (prev) => {
1380
+ const newValue = typeof value === "function" ? value(prev ? ValueOfKey(prev, subPath) : void 0) : value;
1381
+ const result = prev ? { ...prev } : {};
1382
+ setAtPath(result, subPath, newValue);
1383
+ return result;
1384
+ };
1385
+ return setValueBetweenRange(obj, selector, range, updater);
1386
+ };
1387
+ function castProps(arr, props) {
1388
+ return Object.assign(arr, props);
1389
+ }
1390
+ function setValueWithFilter(obj, selector, filterFn, value) {
1391
+ const target = ValueOfKey(obj, selector);
1392
+ if (!Array.isArray(target)) {
1393
+ throw new Error(`Target at ${selector} is not an array`);
1394
+ }
1395
+ const indices = [];
1396
+ const target_copy = [...target];
1397
+ target.forEach((item, index) => {
1398
+ if (filterFn(item, index)) {
1399
+ indices.push(index);
1400
+ }
1401
+ });
1402
+ return setValueWithIndices(obj, selector, indices, value);
1403
+ }
1404
+ function setArrayValueWithFilter(obj, filterFn, selector, value) {
1405
+ let target = obj;
1406
+ if (!Array.isArray(target)) {
1407
+ throw new Error(`Target at ${selector} is not an array`);
1408
+ }
1409
+ const indices = [];
1410
+ const target_copy = [...target];
1411
+ target.forEach((item, index) => {
1412
+ const n = setAtPath(item, selector, value, { createMissing: true });
1413
+ item = n;
1414
+ });
1415
+ return target;
1416
+ }
1417
+ function setValueWithFilterWithSubPath(obj, selector, filterFn, subPath, value) {
1418
+ const updater = (prev) => {
1419
+ const newValue = typeof value === "function" ? value(prev ? ValueOfKey(prev, subPath) : void 0) : value;
1420
+ const result = prev ? { ...prev } : {};
1421
+ setAtPath(result, subPath, newValue);
1422
+ return result;
1423
+ };
1424
+ return setValueWithFilter(obj, selector, filterFn, updater);
1425
+ }
1426
+ function mergeUpdateAtPath(obj, selector, updates) {
1427
+ const current = ValueOfKey(obj, selector, { createMissing: true });
1428
+ const merged = applyDiff(current || {}, updates, true);
1429
+ return setAtPath(obj, selector, merged, { createMissing: true });
1430
+ }
1431
+ function setValueWithArraySelectors(obj, selectors, value) {
1432
+ if (typeof value === "object" && !Array.isArray(value) && value !== null) {
1433
+ for (const [path, val] of Object.entries(value)) {
1434
+ if (selectors.includes(path)) {
1435
+ setAtPath(obj, path, val, { createMissing: true });
1436
+ }
1437
+ }
1438
+ } else {
1439
+ for (const selector of selectors) {
1440
+ const finalValue = handleFunctionParams(
1441
+ selector,
1442
+ ValueOfKey(obj, selector),
1443
+ value
1444
+ );
1445
+ setAtPath(obj, selector, finalValue, { createMissing: true });
1446
+ }
1447
+ }
1448
+ return obj;
1449
+ }
1450
+ function ValueOfKey(obj, selector, options = {}) {
1451
+ const { createMissing = false, add = false, debug = false } = options;
1452
+ const segments = parseSelector(selector);
1453
+ let current = obj;
1454
+ let updateEvenIfNotlast = false;
1455
+ let chained_property = "";
1456
+ const stringify = selector;
1457
+ if (typeof current === "object" && !Array.isArray(current) && stringify.length > 0) {
1458
+ if (current[stringify]) {
1459
+ current = current[stringify];
1460
+ return current;
1461
+ }
1462
+ }
1463
+ for (let i = 0; i < segments.length; i++) {
1464
+ const segment = segments[i];
1465
+ const isLast = segments.length > 1 ? i === segments.length - 1 : false;
1466
+ if (current === null && !createMissing) {
1467
+ return void 0;
1468
+ }
1469
+ const nextSegment = segments[i + 1];
1470
+ switch (segment.type) {
1471
+ case "property":
1472
+ if (current && typeof current === "object") {
1473
+ if (Array.isArray(current)) {
1474
+ if (typeof segment.value === "number") {
1475
+ const index = segment.value;
1476
+ if (createMissing && index >= current.length) {
1477
+ for (let j = current.length; j <= index; j++) {
1478
+ current.push(void 0);
1479
+ }
1480
+ }
1481
+ if (createMissing && (current[index] === null || current[index] === void 0) && (!isLast || updateEvenIfNotlast)) {
1482
+ if (nextSegment) {
1483
+ current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
1484
+ } else {
1485
+ current[index] = null;
1486
+ }
1487
+ updateEvenIfNotlast = false;
1488
+ }
1489
+ current = current[index];
1490
+ if (nextSegment) {
1491
+ updateEvenIfNotlast = true;
1492
+ continue;
1493
+ }
1494
+ } else if (add) {
1495
+ current.push({
1496
+ [String(segment.value)]: null
1497
+ });
1498
+ } else {
1499
+ current = current.map((item) => item[String(segment.value)]);
1500
+ }
1501
+ if (nextSegment) {
1502
+ continue;
1503
+ }
1504
+ return filterDefined(current);
1505
+ } else {
1506
+ if (current[chained_property] && chained_property.split(".").length >= 2) {
1507
+ current = current[chained_property];
1508
+ continue;
1509
+ }
1510
+ if (createMissing && (current[String(segment.value)] === null || current[String(segment.value)] === void 0) && (!isLast || updateEvenIfNotlast)) {
1511
+ if (nextSegment) {
1512
+ current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
1513
+ } else {
1514
+ current[String(segment.value)] = null;
1515
+ }
1516
+ updateEvenIfNotlast = false;
1517
+ current = current[String(segment.value)];
1518
+ if (nextSegment) {
1519
+ updateEvenIfNotlast = true;
1520
+ continue;
1521
+ }
1522
+ }
1523
+ if (!current) {
1524
+ current = { [String(segment.value)]: null };
1525
+ } else {
1526
+ if (!current[String(segment.value)] && createMissing) {
1527
+ current[String(segment.value)] = null;
1528
+ }
1529
+ current = current[String(segment.value)];
1530
+ }
1531
+ if (nextSegment) {
1532
+ continue;
1533
+ }
1534
+ }
1535
+ } else if (createMissing) {
1536
+ current = {};
1537
+ current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" || options.type === "array" ? [] : {};
1538
+ current = current[String(segment.value)];
1539
+ } else {
1540
+ return void 0;
1541
+ }
1542
+ break;
1543
+ case "index":
1544
+ case "wildcard":
1545
+ if (Array.isArray(current)) {
1546
+ if (segment.type === "index") {
1547
+ const index = segment.value;
1548
+ if (index < 0) {
1549
+ current = current[current.length - Math.abs(index)];
1550
+ continue;
1551
+ }
1552
+ if (createMissing && (index >= current.length || current[index] == null || current[index] == void 0) && !isLast) {
1553
+ for (let j = current.length; j <= index; j++) {
1554
+ current.push(void 0);
1555
+ }
1556
+ if (nextSegment) {
1557
+ current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
1558
+ }
1559
+ }
1560
+ current = current[index];
1561
+ } else {
1562
+ if (!isLast) {
1563
+ continue;
1564
+ }
1565
+ }
1566
+ } else if (createMissing) {
1567
+ const nextSegment2 = segments[i + 1];
1568
+ current = [];
1569
+ const index = segment.value;
1570
+ for (let j = 0; j <= index; j++) {
1571
+ current.push(void 0);
1572
+ }
1573
+ current[index] = nextSegment2.type === "index" || nextSegment2.type === "slice" || nextSegment2.type === "union" || nextSegment2.type === "wildcard" || options.type === "array" ? [] : {};
1574
+ current = current[index];
1575
+ } else {
1576
+ if (segment.type === "index" && typeof current === "object") {
1577
+ if (current && current[String(segment.value)] !== void 0) {
1578
+ current = current[String(segment.value)];
1579
+ continue;
1580
+ }
1581
+ }
1582
+ if (typeof current === "object") {
1583
+ const values = Object.values(current);
1584
+ current = values;
1585
+ continue;
1586
+ }
1587
+ return void 0;
1588
+ }
1589
+ break;
1590
+ default:
1591
+ return void 0;
1592
+ }
1593
+ }
1594
+ return filterDefined(current);
1595
+ }
1596
+ function filterDefined(obj) {
1597
+ if (Array.isArray(obj)) {
1598
+ return obj.filter((item) => typeof item !== "undefined");
1599
+ }
1600
+ return obj;
1601
+ }
1602
+ var setAtPath = (obj, selector, value, options = {}) => {
1603
+ if (selector === "[*]") {
1604
+ return applyDiff(obj, value, true);
1605
+ }
1606
+ const { createMissing = true } = options;
1607
+ const segments = parseSelector(selector);
1608
+ if (segments.length === 0) {
1609
+ return obj;
1610
+ }
1611
+ const lastSegment = segments[segments.length - 1];
1612
+ let current = obj;
1613
+ for (let i = 0; i < segments.length - 1; i++) {
1614
+ const segment = segments[i];
1615
+ if (current == null) {
1616
+ if (!createMissing) return obj;
1617
+ throw new Error(`Cannot navigate through null/undefined at segment ${i}`);
1618
+ }
1619
+ const nextSegment = segments[i + 1];
1620
+ const shouldBeArray = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard";
1621
+ if (segment.type === "property") {
1622
+ if (Array.isArray(current) && typeof typeof segment.value === "number") {
1623
+ const index = segment.value;
1624
+ if (index < 0) {
1625
+ throw new Error(`Negative index ${index} not allowed`);
1626
+ }
1627
+ if (index >= current.length && createMissing) {
1628
+ for (let j = current.length; j <= index; j++) {
1629
+ current.push(void 0);
1630
+ }
1631
+ }
1632
+ if ((current[index] === null || current[index] === void 0) && createMissing) {
1633
+ current[index] = shouldBeArray ? [] : {};
1634
+ }
1635
+ current = current[index];
1636
+ } else {
1637
+ if ((current[String(segment.value)] === null || current[String(segment.value)] === void 0) && createMissing) {
1638
+ current[String(segment.value)] = shouldBeArray ? [] : {};
1639
+ }
1640
+ if (typeof current === "object" && !Array.isArray(current)) {
1641
+ current = current[String(segment.value)];
1642
+ }
1643
+ }
1644
+ if (nextSegment) {
1645
+ continue;
1646
+ }
1647
+ break;
1648
+ } else if (segment.type === "index" || segment.type === "wildcard") {
1649
+ if (!Array.isArray(current)) {
1650
+ if (!createMissing) return obj;
1651
+ current = [];
1652
+ }
1653
+ if (segment.type === "index") {
1654
+ const index = segment.value;
1655
+ if (index < 0) {
1656
+ throw new Error(`Negative index ${index} not allowed`);
1657
+ }
1658
+ if (index >= current.length && createMissing) {
1659
+ for (let j = current.length; j <= index; j++) {
1660
+ current.push(void 0);
1661
+ }
1662
+ }
1663
+ if ((current[index] === null || current[index] === void 0) && createMissing) {
1664
+ current[index] = shouldBeArray ? [] : void 0;
1665
+ }
1666
+ current = current[index];
1667
+ }
1668
+ if (nextSegment) {
1669
+ continue;
1670
+ }
1671
+ break;
1672
+ } else {
1673
+ throw new Error(`Invalid segment type for set: ${segment.type}`);
1674
+ }
1675
+ }
1676
+ switch (lastSegment.type) {
1677
+ case "property":
1678
+ if (Array.isArray(current) && typeof lastSegment.value === "number") {
1679
+ const index2 = lastSegment.value;
1680
+ if (index2 < 0) {
1681
+ throw new Error(`Negative index ${index2} not allowed`);
1682
+ }
1683
+ if (index2 >= current.length) {
1684
+ for (let j = current.length; j <= index2; j++) {
1685
+ current.push(void 0);
1686
+ }
1687
+ }
1688
+ if (Array.isArray(value)) {
1689
+ current[index2] = applyDiff(
1690
+ structuredClone(current[index2]),
1691
+ value[index2],
1692
+ true
1693
+ );
1694
+ } else {
1695
+ current[index2] = value;
1696
+ }
1697
+ } else {
1698
+ if (!current) current = {};
1699
+ if (Array.isArray(current)) {
1700
+ const paths = selector.split(".");
1701
+ let ob;
1702
+ if (paths.length >= 2) {
1703
+ paths.shift();
1704
+ for (let i = 0; i < current.length; i++) {
1705
+ if (Array.isArray(value)) {
1706
+ ob = fromPath(paths.join("."), value[i]);
1707
+ current[i] = typeof current[i] === "object" ? applyDiff(current[i], ob, true) : ob;
1708
+ } else {
1709
+ ob = fromPath(paths.join("."), value);
1710
+ current[i] = typeof current[i] === "object" ? applyDiff(current[i], ob, true) : ob;
1711
+ }
1712
+ }
1713
+ } else {
1714
+ ob = {
1715
+ [String(lastSegment.value)]: value
1716
+ };
1717
+ }
1718
+ } else {
1719
+ if (Array.isArray(value) && value.length === 0) {
1720
+ if (typeof current[String(lastSegment.value)] === "undefined") {
1721
+ current[String(lastSegment.value)] = [];
1722
+ } else {
1723
+ current[String(lastSegment.value)] = [];
1724
+ }
1725
+ } else {
1726
+ current[String(lastSegment.value)] = value;
1727
+ }
1728
+ }
1729
+ }
1730
+ break;
1731
+ case "index":
1732
+ case "wildcard":
1733
+ if (!Array.isArray(current)) {
1734
+ throw new Error(`Cannot use index on non-array for final segment`);
1735
+ }
1736
+ const index = lastSegment.value;
1737
+ if (lastSegment.type === "index") {
1738
+ if (index < 0) {
1739
+ throw new Error(`Negative index ${index} not allowed`);
1740
+ }
1741
+ if (index >= current.length) {
1742
+ for (let j = current.length; j <= index; j++) {
1743
+ current.push(void 0);
1744
+ }
1745
+ }
1746
+ if (Array.isArray(value)) {
1747
+ if (typeof current[index] === typeof value[index]) {
1748
+ try {
1749
+ current[index] = applyDiff(
1750
+ deepClone(current[index]),
1751
+ value[index],
1752
+ true
1753
+ );
1754
+ } catch (e) {
1755
+ throw Error("expected on array");
1756
+ }
1757
+ } else {
1758
+ current[index] = value;
1759
+ }
1760
+ } else {
1761
+ current[index] = value;
1762
+ }
1763
+ } else if (lastSegment.type === "wildcard") {
1764
+ if (Array.isArray(value)) {
1765
+ for (let i = 0; i < current.length; i++) {
1766
+ if (typeof current[i] === "object") {
1767
+ current[i] = applyDiff(current[i], value[i], true);
1768
+ } else {
1769
+ current[i] = value[i];
1770
+ }
1771
+ }
1772
+ } else {
1773
+ for (let i = 0; i < current.length; i++) {
1774
+ if (typeof current[i] === "object") {
1775
+ current[i] = applyDiff(current[i], value, true);
1776
+ } else {
1777
+ current[i] = value;
1778
+ }
1779
+ }
1780
+ }
1781
+ }
1782
+ break;
1783
+ default:
1784
+ throw new Error(
1785
+ `Invalid final segment type for set: ${lastSegment.type}`
1786
+ );
1787
+ }
1788
+ return obj;
1789
+ };
1790
+ var fromPath = (path, value) => {
1791
+ const segments = parseSelector(path);
1792
+ if (segments.length === 0) {
1793
+ return value;
1794
+ }
1795
+ let result = value;
1796
+ for (let i = segments.length - 1; i >= 0; i--) {
1797
+ const segment = segments[i];
1798
+ if (segment.type === "property") {
1799
+ result = { [String(segment.value)]: result };
1800
+ } else if (segment.type === "index") {
1801
+ const index = parseInt(String(segment.value));
1802
+ const arr = [];
1803
+ arr[index] = result;
1804
+ result = arr;
1805
+ } else if (segment.type === "wildcard") {
1806
+ if (Array.isArray(result)) {
1807
+ result = result;
1808
+ } else {
1809
+ result = [result];
1810
+ }
1811
+ } else if (segment.type === "slice") {
1812
+ if (!Array.isArray(result)) {
1813
+ result = [result];
1814
+ }
1815
+ } else if (segment.type === "union") {
1816
+ if (!Array.isArray(result)) {
1817
+ result = [result];
1818
+ }
1819
+ } else if (segment.type === "filter") {
1820
+ if (!Array.isArray(result)) {
1821
+ result = [result];
1822
+ }
1823
+ } else if (segment.type === "descendant") {
1824
+ result = result;
1825
+ }
1826
+ }
1827
+ return result;
1828
+ };
1829
+ var select = (obj, selector, options = {}) => {
1830
+ return get(obj, selector, { ...options, preserveStructure: false });
1831
+ };
1832
+ var has = (obj, selector, options = {}) => {
1833
+ if (Array.isArray(selector)) {
1834
+ return selector.map((sel) => has(obj, sel, options));
1835
+ }
1836
+ const result = get(obj, selector, { ...options, preserveStructure: false });
1837
+ if (Array.isArray(result)) {
1838
+ if (result.length > 0) {
1839
+ return result.every((r) => r !== void 0);
1840
+ }
1841
+ return false;
1842
+ }
1843
+ return result !== void 0;
1844
+ };
1845
+ var deletePath = (obj, selector, options = {}) => {
1846
+ const { throwOnError = false } = options;
1847
+ if (Array.isArray(selector)) {
1848
+ return selector.map((sel) => deletePath(obj, sel, options));
1849
+ }
1850
+ const segments = parseSelector(selector, { throwOnError });
1851
+ if (segments.length === 0) {
1852
+ return false;
1853
+ }
1854
+ const lastSegment = segments[segments.length - 1];
1855
+ if (segments.some(
1856
+ (s) => s.type === "wildcard" || s.type === "slice" || s.type === "union"
1857
+ )) {
1858
+ const paths = getPaths(obj, selector, options);
1859
+ let deleted = false;
1860
+ for (const path of paths) {
1861
+ if (deleteSinglePath(obj, path)) {
1862
+ deleted = true;
1863
+ }
1864
+ }
1865
+ return deleted;
1866
+ }
1867
+ let current = obj;
1868
+ for (let i = 0; i < segments.length - 1; i++) {
1869
+ const segment = segments[i];
1870
+ if (current == null) {
1871
+ return false;
1872
+ }
1873
+ switch (segment.type) {
1874
+ case "property":
1875
+ current = current[String(segment.value)];
1876
+ break;
1877
+ case "index":
1878
+ if (!Array.isArray(current)) return false;
1879
+ const index = segment.value;
1880
+ if (index < 0 || index >= current.length) return false;
1881
+ current = current[index];
1882
+ break;
1883
+ default:
1884
+ return false;
1885
+ }
1886
+ }
1887
+ if (current == null) {
1888
+ return false;
1889
+ }
1890
+ switch (lastSegment.type) {
1891
+ case "property":
1892
+ if (String(lastSegment.value) in current) {
1893
+ delete current[String(lastSegment.value)];
1894
+ return true;
1895
+ }
1896
+ break;
1897
+ case "index":
1898
+ if (!Array.isArray(current)) return false;
1899
+ const index = lastSegment.value;
1900
+ if (index >= 0 && index < current.length) {
1901
+ current.splice(index, 1);
1902
+ return true;
1903
+ }
1904
+ break;
1905
+ }
1906
+ return false;
1907
+ };
1908
+ var deleteSinglePath = (obj, selector) => {
1909
+ const segments = parseSelector(selector);
1910
+ if (segments.length === 0) {
1911
+ return false;
1912
+ }
1913
+ const lastSegment = segments[segments.length - 1];
1914
+ let current = obj;
1915
+ for (let i = 0; i < segments.length - 1; i++) {
1916
+ const segment = segments[i];
1917
+ if (current == null) {
1918
+ return false;
1919
+ }
1920
+ switch (segment.type) {
1921
+ case "property":
1922
+ current = current[String(segment.value)];
1923
+ break;
1924
+ case "index":
1925
+ if (!Array.isArray(current)) return false;
1926
+ const index = segment.value;
1927
+ if (index < 0 || index >= current.length) return false;
1928
+ current = current[index];
1929
+ break;
1930
+ default:
1931
+ return false;
1932
+ }
1933
+ }
1934
+ if (current == null) {
1935
+ return false;
1936
+ }
1937
+ switch (lastSegment.type) {
1938
+ case "property":
1939
+ if (String(lastSegment.value) in current) {
1940
+ delete current[String(lastSegment.value)];
1941
+ return true;
1942
+ }
1943
+ break;
1944
+ case "index":
1945
+ if (!Array.isArray(current)) return false;
1946
+ const index = lastSegment.value;
1947
+ if (index >= 0 && index < current.length) {
1948
+ current.splice(index, 1);
1949
+ return true;
1950
+ }
1951
+ break;
1952
+ }
1953
+ return false;
1954
+ };
1955
+ var getPaths = (obj, selector, options = {}) => {
1956
+ const { format = "selector", maxDepth = 20 } = options;
1957
+ if (selector && Array.isArray(selector)) {
1958
+ const allPaths2 = [];
1959
+ for (const sel of selector) {
1960
+ const paths = getPaths(obj, sel, options);
1961
+ allPaths2.push(...paths);
1962
+ }
1963
+ return allPaths2;
1964
+ }
1965
+ if (selector) {
1966
+ const segments = parseSelector(selector, options);
1967
+ const results = traverseWithPaths(obj, segments, 0, maxDepth);
1968
+ return results.map(
1969
+ (r) => format === "selector" ? r.path : r.stringPath
1970
+ );
1971
+ }
1972
+ const allPaths = [];
1973
+ const traverseAll = (current, path = [], stringPath = [], depth = 0) => {
1974
+ if (depth > maxDepth) return;
1975
+ if (path.length > 0) {
1976
+ const pathStr = stringifySelector(path);
1977
+ allPaths.push({ path: pathStr, stringPath: stringPath.join(".") });
1978
+ }
1979
+ if (current && typeof current === "object") {
1980
+ if (Array.isArray(current)) {
1981
+ for (let i = 0; i < current.length; i++) {
1982
+ traverseAll(
1983
+ current[i],
1984
+ [...path, { type: "index", value: i, raw: `[${i}]` }],
1985
+ [...stringPath, `[${i}]`],
1986
+ depth + 1
1987
+ );
1988
+ }
1989
+ } else {
1990
+ for (const key in current) {
1991
+ if (current.hasOwnProperty(key)) {
1992
+ traverseAll(
1993
+ current[key],
1994
+ [...path, { type: "property", value: key, raw: key }],
1995
+ [...stringPath, key],
1996
+ depth + 1
1997
+ );
1998
+ }
1999
+ }
2000
+ }
2001
+ }
2002
+ };
2003
+ traverseAll(obj);
2004
+ return allPaths.map(
2005
+ (p) => format === "selector" ? p.path : p.stringPath
2006
+ );
2007
+ };
2008
+ var findPaths = (obj, predicate) => {
2009
+ const paths = getPaths(obj);
2010
+ return paths.filter((path) => {
2011
+ const value = get(obj, path);
2012
+ return predicate(path, value);
2013
+ });
2014
+ };
2015
+ var flattenWithArrays = (obj, separator = ".") => {
2016
+ const result = {};
2017
+ const traverse = (current, path = []) => {
2018
+ if (current == null) return;
2019
+ const trav = traverseStructure(current, path, 0, 20);
2020
+ if (trav !== void 0) {
2021
+ result[stringifySelector(path)] = trav;
2022
+ return;
2023
+ }
2024
+ if (Array.isArray(current)) {
2025
+ for (let i = 0; i < current.length; i++) {
2026
+ const newPath = [
2027
+ ...path,
2028
+ { type: "index", value: i, raw: `[${i}]` }
2029
+ ];
2030
+ traverse(current[i], newPath);
2031
+ }
2032
+ } else if (isObject2(current)) {
2033
+ for (const key in current) {
2034
+ if (current.hasOwnProperty(key)) {
2035
+ const newPath = [
2036
+ ...path,
2037
+ { type: "property", value: key, raw: key }
2038
+ ];
2039
+ traverse(current[key], newPath);
2040
+ }
2041
+ }
2042
+ const symbols = Object.getOwnPropertySymbols(current);
2043
+ for (const symbol of symbols) {
2044
+ const newPath = [
2045
+ ...path,
2046
+ {
2047
+ type: "property",
2048
+ value: symbol.toString(),
2049
+ raw: symbol.toString()
2050
+ }
2051
+ ];
2052
+ traverse(current[symbol], newPath);
2053
+ }
2054
+ } else {
2055
+ const pathStr = stringifySelector(path);
2056
+ result[pathStr] = current;
2057
+ }
2058
+ };
2059
+ traverse(obj);
2060
+ return result;
2061
+ };
2062
+ var unflattenWithArrays = (obj) => {
2063
+ const result = {};
2064
+ for (const key in obj) {
2065
+ set(result, key, obj[key]);
2066
+ }
2067
+ return result;
2068
+ };
2069
+ var deepMergeWithArrays = (...objects) => {
2070
+ const result = {};
2071
+ for (const obj of objects) {
2072
+ if (!isObject2(obj)) continue;
2073
+ const flat = flattenWithArrays(obj);
2074
+ for (const path in flat) {
2075
+ set(result, path, flat[path]);
2076
+ }
2077
+ }
2078
+ return result;
2079
+ };
2080
+ function traverseWithPaths(current, segments, depth, maxDepth, currentPath = [], currentStringPath = []) {
2081
+ if (depth > maxDepth) return [];
2082
+ if (segments.length === 0)
2083
+ return [
2084
+ {
2085
+ value: current,
2086
+ path: stringifySelector(currentPath),
2087
+ stringPath: currentStringPath.join(".")
2088
+ }
2089
+ ];
2090
+ const segment = segments[0];
2091
+ const remaining = segments.slice(1);
2092
+ const results = [];
2093
+ if (segment.type === "descendant") {
2094
+ results.push(
2095
+ ...traverseWithPaths(
2096
+ current,
2097
+ remaining,
2098
+ depth + 1,
2099
+ maxDepth,
2100
+ currentPath,
2101
+ currentStringPath
2102
+ )
2103
+ );
2104
+ if (current && typeof current === "object") {
2105
+ if (Array.isArray(current)) {
2106
+ for (let i = 0; i < current.length; i++) {
2107
+ results.push(
2108
+ ...traverseWithPaths(
2109
+ current[i],
2110
+ segments,
2111
+ // Use same segments for recursion
2112
+ depth + 1,
2113
+ maxDepth,
2114
+ [...currentPath, { type: "index", value: i, raw: `[${i}]` }],
2115
+ [...currentStringPath, `[${i}]`]
2116
+ )
2117
+ );
2118
+ }
2119
+ } else {
2120
+ for (const key in current) {
2121
+ if (current.hasOwnProperty(key)) {
2122
+ results.push(
2123
+ ...traverseWithPaths(
2124
+ current[key],
2125
+ segments,
2126
+ depth + 1,
2127
+ maxDepth,
2128
+ [...currentPath, { type: "property", value: key, raw: key }],
2129
+ [...currentStringPath, key]
2130
+ )
2131
+ );
2132
+ }
2133
+ }
2134
+ }
2135
+ }
2136
+ return results;
2137
+ }
2138
+ switch (segment.type) {
2139
+ case "property":
2140
+ if (current && typeof current === "object" && String(segment.value) in current) {
2141
+ const next = current[String(segment.value)];
2142
+ results.push(
2143
+ ...traverseWithPaths(
2144
+ next,
2145
+ remaining,
2146
+ depth + 1,
2147
+ maxDepth,
2148
+ [...currentPath, segment],
2149
+ [...currentStringPath, String(segment.value)]
2150
+ )
2151
+ );
2152
+ }
2153
+ break;
2154
+ case "index":
2155
+ if (Array.isArray(current)) {
2156
+ const index = segment.value;
2157
+ if (index >= 0 && index < current.length) {
2158
+ results.push(
2159
+ ...traverseWithPaths(
2160
+ current[index],
2161
+ remaining,
2162
+ depth + 1,
2163
+ maxDepth,
2164
+ [...currentPath, segment],
2165
+ [...currentStringPath, `[${index}]`]
2166
+ )
2167
+ );
2168
+ }
2169
+ } else if (current && typeof current === "object") {
2170
+ const key = String(segment.value);
2171
+ if (key in current) {
2172
+ results.push(
2173
+ ...traverseWithPaths(
2174
+ current[key],
2175
+ remaining,
2176
+ depth + 1,
2177
+ maxDepth,
2178
+ [...currentPath, { ...segment, type: "property" }],
2179
+ [...currentStringPath, key]
2180
+ )
2181
+ );
2182
+ }
2183
+ }
2184
+ break;
2185
+ case "wildcard":
2186
+ if (current && typeof current === "object") {
2187
+ if (Array.isArray(current)) {
2188
+ for (let i = 0; i < current.length; i++) {
2189
+ results.push(
2190
+ ...traverseWithPaths(
2191
+ current[i],
2192
+ remaining,
2193
+ depth + 1,
2194
+ maxDepth,
2195
+ [...currentPath, { type: "index", value: i, raw: `[${i}]` }],
2196
+ [...currentStringPath, `[${i}]`]
2197
+ )
2198
+ );
2199
+ }
2200
+ } else {
2201
+ for (const key in current) {
2202
+ if (current.hasOwnProperty(key)) {
2203
+ results.push(
2204
+ ...traverseWithPaths(
2205
+ current[key],
2206
+ remaining,
2207
+ depth + 1,
2208
+ maxDepth,
2209
+ [...currentPath, { type: "property", value: key, raw: key }],
2210
+ [...currentStringPath, key]
2211
+ )
2212
+ );
2213
+ }
2214
+ }
2215
+ }
2216
+ }
2217
+ break;
2218
+ case "slice":
2219
+ if (Array.isArray(current)) {
2220
+ const [start, end] = segment.value;
2221
+ const actualStart = Math.max(0, start);
2222
+ const actualEnd = Math.min(
2223
+ current.length,
2224
+ end === Infinity ? current.length : end
2225
+ );
2226
+ for (let i = actualStart; i < actualEnd; i++) {
2227
+ results.push(
2228
+ ...traverseWithPaths(
2229
+ current[i],
2230
+ remaining,
2231
+ depth + 1,
2232
+ maxDepth,
2233
+ [...currentPath, { type: "index", value: i, raw: `[${i}]` }],
2234
+ [...currentStringPath, `[${i}]`]
2235
+ )
2236
+ );
2237
+ }
2238
+ }
2239
+ break;
2240
+ case "union":
2241
+ if (Array.isArray(current)) {
2242
+ const indices = segment.value;
2243
+ for (const index of indices) {
2244
+ if (index >= 0 && index < current.length) {
2245
+ results.push(
2246
+ ...traverseWithPaths(
2247
+ current[index],
2248
+ remaining,
2249
+ depth + 1,
2250
+ maxDepth,
2251
+ [
2252
+ ...currentPath,
2253
+ { type: "index", value: index, raw: `[${index}]` }
2254
+ ],
2255
+ [...currentStringPath, `[${index}]`]
2256
+ )
2257
+ );
2258
+ }
2259
+ }
2260
+ }
2261
+ break;
2262
+ case "filter":
2263
+ if (Array.isArray(current)) {
2264
+ const filterFn = segment.value;
2265
+ for (let i = 0; i < current.length; i++) {
2266
+ if (filterFn(current[i])) {
2267
+ results.push(
2268
+ ...traverseWithPaths(
2269
+ current[i],
2270
+ remaining,
2271
+ depth + 1,
2272
+ maxDepth,
2273
+ [...currentPath, { type: "index", value: i, raw: `[${i}]` }],
2274
+ [...currentStringPath, `[${i}]`]
2275
+ )
2276
+ );
2277
+ }
2278
+ }
2279
+ }
2280
+ break;
2281
+ }
2282
+ return results;
2283
+ }
2284
+ var update = (obj, path, updater) => {
2285
+ const currentValue = get(obj, path);
2286
+ const newValue = updater(currentValue);
2287
+ return setValueAtPath(obj, path, newValue);
2288
+ };
2289
+ var updateWithCallBack = (obj, updater) => {
2290
+ const newValue = updater(obj);
2291
+ const result = applyDiff(obj, newValue, true);
2292
+ return result;
2293
+ };
2294
+ var getTypeAtPath = (obj, path) => {
2295
+ const value = get(obj, path);
2296
+ if (value === void 0) return void 0;
2297
+ if (value === null) return "null";
2298
+ if (Array.isArray(value)) return "array";
2299
+ return typeof value;
2300
+ };
2301
+ export {
2302
+ ValueOfKey,
2303
+ castProps,
2304
+ deepMergeWithArrays,
2305
+ deletePath,
2306
+ findPaths,
2307
+ flattenWithArrays,
2308
+ fromPath,
2309
+ get,
2310
+ getPaths,
2311
+ getTypeAtPath,
2312
+ has,
2313
+ isRangeObject,
2314
+ mergeUpdateAtPath,
2315
+ select,
2316
+ set,
2317
+ setArrayValueWithFilter,
2318
+ setAtPath,
2319
+ setValueAtIndex,
2320
+ setValueAtPath,
2321
+ setValueBetweenRange,
2322
+ setValueBetweenRangeWithSubPath,
2323
+ setValueWithArraySelectors,
2324
+ setValueWithFilter,
2325
+ setValueWithFilterWithSubPath,
2326
+ traverseWithPaths,
2327
+ unflattenWithArrays,
2328
+ update,
2329
+ updateWithCallBack
2330
+ };