ivue 1.5.8 → 1.6.1

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.
package/README.md CHANGED
@@ -42,7 +42,6 @@
42
42
 
43
43
  `ivue` also offers a set of functions and utility types to make extensible & exportable props defaults, extensible emits and extensible slots possible.
44
44
 
45
+ ## Full Documentation
45
46
 
46
- ## Examples
47
-
48
- ## Documentation
47
+ See: https://infinite-system.github.io/ivue/
package/dist/env.d.ts ADDED
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/dist/index.es.js CHANGED
@@ -1,88 +1,215 @@
1
- import { reactive as v, computed as b, ref as A, shallowRef as D, toRef as m } from "vue";
2
- const d = /* @__PURE__ */ new Map();
3
- function E(e) {
4
- if (d.has(e))
5
- return d.get(e);
6
- const o = /* @__PURE__ */ new Map();
7
- let t = e.prototype;
8
- for (; t.constructor !== Object; )
9
- Object.entries(Object.getOwnPropertyDescriptors(t)).forEach(([f, r]) => {
10
- const i = o.get(f);
11
- i !== r && (r != null && r.get || r != null && r.set) && (i != null && i.get && (r.get = i == null ? void 0 : i.get), i != null && i.set && (r.set = i == null ? void 0 : i.set), o.set(f, r));
12
- }), t = Object.getPrototypeOf(t);
13
- return d.set(e, o), o;
14
- }
15
- function M(e, ...o) {
16
- var i, O;
17
- const t = E(e), f = t != null && t.size ? {} : null, r = v(new e(...o));
18
- for (const [n, l] of t)
19
- ((i = e == null ? void 0 : e.ivue) == null ? void 0 : i[n]) !== !1 && Object.defineProperty(r, n, { get: l.get ? () => {
20
- var a, g;
21
- return n in f ? f[n] : f[n] = b({ get: (a = l.get) == null ? void 0 : a.bind(r), set: (g = l.set) == null ? void 0 : g.bind(r) });
22
- } : void 0, set: (O = l.set) == null ? void 0 : O.bind(r), enumerable: !1 });
23
- return Object.defineProperty(r, "toRefs", { get: () => function(n, l, a) {
24
- return function(g, S) {
25
- var w, h;
26
- const p = {};
27
- if (Array.isArray(g))
28
- for (let u = 0; u < g.length; u++) {
29
- const s = g[u];
30
- if (l.has(s))
31
- if (s in a)
32
- p[s] = a[s];
33
- else {
34
- const c = l.get(s);
35
- p[s] = a[s] = b({ get: (w = c == null ? void 0 : c.get) == null ? void 0 : w.bind(n), set: (h = c == null ? void 0 : c.set) == null ? void 0 : h.bind(n) });
36
- }
37
- else
38
- typeof n[s] == "function" ? p[s] = n[s].bind(n) : p[s] = m(n, s);
39
- }
40
- else {
41
- let u = new Set(C(n));
42
- l.forEach((s, c) => {
43
- var j, P;
44
- p[c] = c in a ? a[c] : a[c] = b({ get: (j = s.get) == null ? void 0 : j.bind(n), set: (P = s.set) == null ? void 0 : P.bind(n) }), u == null || u.delete(c);
45
- }), u.forEach((s) => {
46
- typeof n[s] == "function" ? p[s] = n[s].bind(n) : p[s] = m(n, s);
47
- }), u = null;
1
+ import { reactive as _, computed as j, markRaw as x, ref as B, shallowRef as T, toRef as z } from "vue";
2
+ const I = Array.isArray, M = Object.create, p = Object.defineProperty, D = Object.getPrototypeOf, L = Object.getOwnPropertyNames, U = Object.getOwnPropertyDescriptor, q = Object.getOwnPropertyDescriptors, R = Symbol("IVUE_INSTANCE");
3
+ let h = /* @__PURE__ */ new WeakMap();
4
+ const A = (e) => {
5
+ if (h.has(e))
6
+ return h.get(e);
7
+ const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set();
8
+ let n = e.prototype;
9
+ for (; n && n !== Object.prototype; ) {
10
+ const t = q(n);
11
+ for (const a in t) {
12
+ if (a === "constructor")
13
+ continue;
14
+ const r = t[a];
15
+ r.get || r.set ? s.has(a) || s.set(a, r) : typeof r.value == "function" && o.add(a);
16
+ }
17
+ n = D(n);
18
+ }
19
+ const c = { accessors: s, methods: o };
20
+ return h.set(e, c), c;
21
+ };
22
+ let v = /* @__PURE__ */ new WeakMap();
23
+ const G = /* @__PURE__ */ new Set(["caller", "callee", "arguments", "constructor"]), k = (e) => {
24
+ const s = e.constructor;
25
+ if (v.has(s))
26
+ return v.get(s);
27
+ const { accessors: o, methods: n } = h.get(s) ?? A(s), c = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Map();
28
+ do {
29
+ const r = L(e);
30
+ for (let f = 0, g = r.length; f < g; f++) {
31
+ const b = r[f];
32
+ G.has(b) || t.has(b) || (o.has(b) ? t.set(b, 2) : n.has(b) || (c.add(b), t.set(b, 0)));
33
+ }
34
+ e = D(e);
35
+ } while (e && e.constructor !== Object);
36
+ const a = { allProps: t, onlyProps: c };
37
+ return v.set(s, a), a;
38
+ }, F = (e, ...s) => {
39
+ var f, g, b;
40
+ const { accessors: o, methods: n } = A(e), c = o != null && o.size ? M(null) : null, t = _(new e(...s));
41
+ for (const [i, u] of o)
42
+ p(t, i, { get: () => {
43
+ var y, m;
44
+ return c[i] ?? (c[i] = j({ get: (y = u.get) == null ? void 0 : y.bind(t), set: (m = u.set) == null ? void 0 : m.bind(t) }));
45
+ }, enumerable: u.enumerable, configurable: u.configurable });
46
+ const a = e == null ? void 0 : e.ivueDisableReactivity;
47
+ if (a)
48
+ for (const i of a) {
49
+ const u = o.get(i);
50
+ u ? p(t, i, { get: (f = u.get) == null ? void 0 : f.bind(t), set: (g = u.set) == null ? void 0 : g.bind(t), enumerable: u.enumerable, configurable: u.configurable }) : (console.log("des criptor", i, u), t[i] = x(t[i]));
51
+ }
52
+ const r = { writable: !0, configurable: !0, enumerable: !1 };
53
+ for (const i of n)
54
+ r.value = t[i].bind(t), p(t, i, r);
55
+ return p(t, "toRefs", { get: (() => {
56
+ let i = null;
57
+ return () => i ?? (i = N(t, o, c));
58
+ })(), enumerable: !1 }), p(t, "clone", { value: (...i) => V(e, s, t, o, n, i), enumerable: !1 }), p(t, R, { value: !0, enumerable: !1, configurable: !1, writable: !1 }), (b = t == null ? void 0 : t.init) == null || b.call(t, !1), t;
59
+ }, V = (e, s, o, n, c, t = []) => {
60
+ var y, m, S;
61
+ const a = n != null && n.size ? M(null) : null, r = _(new e(...s)), { onlyProps: f } = k(r), g = e.ivueCloneByReference, b = P.get(e);
62
+ if (g)
63
+ for (const l of f)
64
+ r[l] = g.has(l) ? o[l] : d(o[l], b);
65
+ else
66
+ for (const l of f)
67
+ r[l] = d(o[l], b);
68
+ for (const [l, w] of n)
69
+ p(r, l, { get: () => {
70
+ var W, C;
71
+ return a[l] ?? (a[l] = j({ get: (W = w.get) == null ? void 0 : W.bind(r), set: (C = w.set) == null ? void 0 : C.bind(r) }));
72
+ }, enumerable: w.enumerable, configurable: w.configurable });
73
+ const i = e == null ? void 0 : e.ivueDisableReactivity;
74
+ if (i)
75
+ for (const l of i) {
76
+ const w = n.get(l);
77
+ w ? p(r, l, { get: (y = w.get) == null ? void 0 : y.bind(r), set: (m = w.set) == null ? void 0 : m.bind(r), enumerable: w.enumerable, configurable: w.configurable }) : r[l] = x(r[l]);
78
+ }
79
+ const u = { writable: !0, configurable: !0, enumerable: !1 };
80
+ for (const l of c)
81
+ u.value = r[l].bind(r), p(r, l, u);
82
+ return p(r, "toRefs", { get: (() => {
83
+ let l = null;
84
+ return () => l ?? (l = N(r, n, a));
85
+ })(), enumerable: !1 }), p(r, "clone", { value: (...l) => V(e, s, r, n, c, l), enumerable: !1 }), p(r, R, { value: !0, enumerable: !1, configurable: !1, writable: !1 }), (S = r == null ? void 0 : r.init) == null || S.call(r, !0, ...t), r;
86
+ }, H = B, J = T, Q = (e) => e, N = (e, s, o) => {
87
+ const n = s.get.bind(s), { allProps: c } = k(e);
88
+ return function(t = !1, a) {
89
+ const r = {};
90
+ if (I(t))
91
+ for (const f of t) {
92
+ const g = c.get(f);
93
+ E(r, f, g, e, n, o);
94
+ }
95
+ else
96
+ for (const [f, g] of c.entries())
97
+ E(r, f, g, e, n, o);
98
+ return r;
99
+ };
100
+ }, E = (e, s, o, n, c, t) => {
101
+ var a, r;
102
+ if (o === 2) {
103
+ const f = c(s);
104
+ e[s] = t[s] ?? (t[s] = j({ get: (a = f.get) == null ? void 0 : a.bind(n), set: (r = f.set) == null ? void 0 : r.bind(n) }));
105
+ } else
106
+ o === 0 && (e[s] = z(n, s));
107
+ }, K = (e) => {
108
+ var s;
109
+ return typeof e == "function" && !!e.prototype && !((s = U(e, "prototype")) != null && s.writable);
110
+ }, X = (e, s, o = void 0) => {
111
+ for (const n in s) {
112
+ const c = e == null ? void 0 : e[n];
113
+ s[n].required || c !== void 0 && (typeof c == "object" && c !== null ? s[n].default = () => d(c, o) : K(c) ? s[n].default = () => c : s[n].default = c);
114
+ }
115
+ return s;
116
+ }, O = (e, s, o, n) => {
117
+ const c = Object.getOwnPropertyDescriptors(e);
118
+ for (const t of Reflect.ownKeys(c)) {
119
+ const a = c[t];
120
+ "value" in a && (a.value = d(a.value, o, n)), Object.defineProperty(s, t, a);
121
+ }
122
+ };
123
+ let P = /* @__PURE__ */ new WeakMap();
124
+ const d = (e, s, o = /* @__PURE__ */ new WeakMap()) => {
125
+ if (e == null || typeof e != "object")
126
+ return e;
127
+ if (o.has(e))
128
+ return o.get(e);
129
+ if (I(e)) {
130
+ const t = e.length, a = new Array(t);
131
+ o.set(e, a);
132
+ for (let r = 0; r < t; r++)
133
+ a[r] = d(e[r], s, o);
134
+ return a;
135
+ }
136
+ const n = D(e);
137
+ if (n === Object.prototype || n === null) {
138
+ const t = M(n);
139
+ return o.set(e, t), O(e, t, s, o), t;
140
+ }
141
+ if (e[R]) {
142
+ const t = e.constructor;
143
+ if (t.ivueGlobalStore)
144
+ return o.set(e, e), e;
145
+ let a;
146
+ if (s != null && s.has(t)) {
147
+ P.set(t, s);
148
+ try {
149
+ a = e.clone(...s.get(t) ?? []);
150
+ } finally {
151
+ P.delete(t);
48
152
  }
49
- return p;
50
- };
51
- }(r, t, f), enumerable: !1 }), "init" in r && r.init(), r;
52
- }
53
- const y = /* @__PURE__ */ new Map();
54
- function C(e) {
55
- if (y.has(e.constructor))
56
- return y.get(e.constructor);
57
- const o = e.constructor, t = /* @__PURE__ */ new Set();
58
- do
59
- Object.getOwnPropertyNames(e).forEach((f) => {
60
- ["caller", "callee", "arguments", "constructor"].includes(f) || t.add(f);
61
- }), e = Object.getPrototypeOf(e);
62
- while (e.constructor !== Object);
63
- return y.set(o, t), t;
64
- }
65
- const z = A, N = D;
66
- function W(e, ...o) {
67
- return typeof e == "function" ? R(e) ? M(e, ...o).toRefs(!0) : e(...o) : e;
68
- }
69
- function R(e) {
70
- var o;
71
- return typeof e == "function" && !!e.prototype && !((o = Object.getOwnPropertyDescriptor(e, "prototype")) != null && o.writable);
72
- }
73
- function k(e, o) {
74
- for (const t in o)
75
- typeof (e == null ? void 0 : e[t]) == "object" && (e == null ? void 0 : e[t]) !== null || R(e == null ? void 0 : e[t]) ? o[t].default = () => e == null ? void 0 : e[t] : o[t].default = e == null ? void 0 : e[t];
76
- return o;
77
- }
153
+ } else
154
+ a = e.clone();
155
+ return o.set(e, a), a;
156
+ }
157
+ if (e instanceof Date)
158
+ return new Date(e.getTime());
159
+ if (e instanceof Map) {
160
+ const t = new e.constructor();
161
+ o.set(e, t);
162
+ for (const [a, r] of e)
163
+ t.set(d(a, s, o), d(r, s, o));
164
+ return t;
165
+ }
166
+ if (e instanceof Set) {
167
+ const t = new e.constructor();
168
+ o.set(e, t);
169
+ for (const a of e)
170
+ t.add(d(a, s, o));
171
+ return t;
172
+ }
173
+ if (e instanceof RegExp) {
174
+ const t = new RegExp(e.source, e.flags);
175
+ return t.lastIndex = e.lastIndex, t;
176
+ }
177
+ if (e instanceof Error) {
178
+ const t = new e.constructor(e.message);
179
+ return o.set(e, t), O(e, t, s, o), t;
180
+ }
181
+ if (e instanceof Promise || e instanceof WeakMap || e instanceof WeakSet)
182
+ return o.set(e, e), e;
183
+ if (e instanceof DataView) {
184
+ const t = new DataView(e.buffer.slice(0), e.byteOffset, e.byteLength);
185
+ return o.set(e, t), t;
186
+ }
187
+ if (ArrayBuffer.isView(e) && !(e instanceof DataView)) {
188
+ const t = new e.constructor(e);
189
+ return o.set(e, t), t;
190
+ }
191
+ if (e instanceof ArrayBuffer) {
192
+ const t = e.slice(0);
193
+ return o.set(e, t), t;
194
+ }
195
+ const c = M(n);
196
+ return o.set(e, c), O(e, c, s, o), c;
197
+ }, Z = () => {
198
+ h = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap();
199
+ }, $ = { copyOwnProps: O, getClassAccessorsMethodsMap: A, getClassPropertiesAccessorsMap: k };
78
200
  export {
79
- d as descriptorsMap,
80
- E as getAllClassDescriptors,
81
- C as getAllClassProperties,
82
- z as iref,
83
- R as isClass,
84
- N as ishallowRef,
85
- W as iuse,
86
- M as ivue,
87
- k as propsWithDefaults
201
+ R as IVUE_INSTANCE_SYMBOL,
202
+ $ as __test__,
203
+ h as accessorsMethodsMaps,
204
+ P as activeDeepCloneArgsMap,
205
+ Z as clearCache,
206
+ O as copyOwnProps,
207
+ d as deepClone,
208
+ H as iref,
209
+ K as isClass,
210
+ J as ishallowRef,
211
+ Q as iuse,
212
+ F as ivue,
213
+ v as propertiesAccessorsMaps,
214
+ X as propsWithDefaults
88
215
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(c,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):f((c=typeof globalThis<"u"?globalThis:c||self).ivue={},c.Vue)})(this,function(c,f){"use strict";const y=new Map;function j(t){if(y.has(t))return y.get(t);const r=new Map;let e=t.prototype;for(;e.constructor!==Object;)Object.entries(Object.getOwnPropertyDescriptors(e)).forEach(([l,n])=>{const i=r.get(l);i!==n&&(n!=null&&n.get||n!=null&&n.set)&&(i!=null&&i.get&&(n.get=i==null?void 0:i.get),i!=null&&i.set&&(n.set=i==null?void 0:i.set),r.set(l,n))}),e=Object.getPrototypeOf(e);return y.set(t,r),r}function w(t,...r){var i,P;const e=j(t),l=e!=null&&e.size?{}:null,n=f.reactive(new t(...r));for(const[s,d]of e)((i=t==null?void 0:t.ivue)==null?void 0:i[s])!==!1&&Object.defineProperty(n,s,{get:d.get?()=>{var p,b;return s in l?l[s]:l[s]=f.computed({get:(p=d.get)==null?void 0:p.bind(n),set:(b=d.set)==null?void 0:b.bind(n)})}:void 0,set:(P=d.set)==null?void 0:P.bind(n),enumerable:!1});return Object.defineProperty(n,"toRefs",{get:()=>function(s,d,p){return function(b,S){var v,R;const g={};if(Array.isArray(b))for(let a=0;a<b.length;a++){const o=b[a];if(d.has(o))if(o in p)g[o]=p[o];else{const u=d.get(o);g[o]=p[o]=f.computed({get:(v=u==null?void 0:u.get)==null?void 0:v.bind(s),set:(R=u==null?void 0:u.set)==null?void 0:R.bind(s)})}else typeof s[o]=="function"?g[o]=s[o].bind(s):g[o]=f.toRef(s,o)}else{let a=new Set(m(s));d.forEach((o,u)=>{var M,A;g[u]=u in p?p[u]:p[u]=f.computed({get:(M=o.get)==null?void 0:M.bind(s),set:(A=o.set)==null?void 0:A.bind(s)}),a==null||a.delete(u)}),a.forEach(o=>{typeof s[o]=="function"?g[o]=s[o].bind(s):g[o]=f.toRef(s,o)}),a=null}return g}}(n,e,l),enumerable:!1}),"init"in n&&n.init(),n}const O=new Map;function m(t){if(O.has(t.constructor))return O.get(t.constructor);const r=t.constructor,e=new Set;do Object.getOwnPropertyNames(t).forEach(l=>{["caller","callee","arguments","constructor"].includes(l)||e.add(l)}),t=Object.getPrototypeOf(t);while(t.constructor!==Object);return O.set(r,e),e}const D=f.ref,E=f.shallowRef;function h(t){var r;return typeof t=="function"&&!!t.prototype&&!((r=Object.getOwnPropertyDescriptor(t,"prototype"))!=null&&r.writable)}c.descriptorsMap=y,c.getAllClassDescriptors=j,c.getAllClassProperties=m,c.iref=D,c.isClass=h,c.ishallowRef=E,c.iuse=function(t,...r){return typeof t=="function"?h(t)?w(t,...r).toRefs(!0):t(...r):t},c.ivue=w,c.propsWithDefaults=function(t,r){for(const e in r)typeof(t==null?void 0:t[e])=="object"&&(t==null?void 0:t[e])!==null||h(t==null?void 0:t[e])?r[e].default=()=>t==null?void 0:t[e]:r[e].default=t==null?void 0:t[e];return r},Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],p):p((c=typeof globalThis<"u"?globalThis:c||self).ivue={},c.Vue)})(this,function(c,p){"use strict";const C=Array.isArray,O=Object.create,d=Object.defineProperty,D=Object.getPrototypeOf,_=Object.getOwnPropertyNames,I=Object.getOwnPropertyDescriptor,T=Object.getOwnPropertyDescriptors,A=Symbol("IVUE_INSTANCE");c.accessorsMethodsMaps=new WeakMap;const P=e=>{if(c.accessorsMethodsMaps.has(e))return c.accessorsMethodsMaps.get(e);const s=new Map,r=new Set;let t=e.prototype;for(;t&&t!==Object.prototype;){const o=T(t);for(const a in o){if(a==="constructor")continue;const n=o[a];n.get||n.set?s.has(a)||s.set(a,n):typeof n.value=="function"&&r.add(a)}t=D(t)}const i={accessors:s,methods:r};return c.accessorsMethodsMaps.set(e,i),i};c.propertiesAccessorsMaps=new WeakMap;const N=new Set(["caller","callee","arguments","constructor"]),j=e=>{const s=e.constructor;if(c.propertiesAccessorsMaps.has(s))return c.propertiesAccessorsMaps.get(s);const{accessors:r,methods:t}=c.accessorsMethodsMaps.get(s)??P(s),i=new Set,o=new Map;do{const n=_(e);for(let u=0,w=n.length;u<w;u++){const g=n[u];N.has(g)||o.has(g)||(r.has(g)?o.set(g,2):t.has(g)||(i.add(g),o.set(g,0)))}e=D(e)}while(e&&e.constructor!==Object);const a={allProps:o,onlyProps:i};return c.propertiesAccessorsMaps.set(s,a),a},R=(e,s,r,t,i,o=[])=>{var h,v,x;const a=t!=null&&t.size?O(null):null,n=p.reactive(new e(...s)),{onlyProps:u}=j(n),w=e.ivueCloneByReference,g=c.activeDeepCloneArgsMap.get(e);if(w)for(const l of u)n[l]=w.has(l)?r[l]:M(r[l],g);else for(const l of u)n[l]=M(r[l],g);for(const[l,y]of t)d(n,l,{get:()=>{var E,V;return a[l]??(a[l]=p.computed({get:(E=y.get)==null?void 0:E.bind(n),set:(V=y.set)==null?void 0:V.bind(n)}))},enumerable:y.enumerable,configurable:y.configurable});const f=e==null?void 0:e.ivueDisableReactivity;if(f)for(const l of f){const y=t.get(l);y?d(n,l,{get:(h=y.get)==null?void 0:h.bind(n),set:(v=y.set)==null?void 0:v.bind(n),enumerable:y.enumerable,configurable:y.configurable}):n[l]=p.markRaw(n[l])}const b={writable:!0,configurable:!0,enumerable:!1};for(const l of i)b.value=n[l].bind(n),d(n,l,b);return d(n,"toRefs",{get:(()=>{let l=null;return()=>l??(l=S(n,t,a))})(),enumerable:!1}),d(n,"clone",{value:(...l)=>R(e,s,n,t,i,l),enumerable:!1}),d(n,A,{value:!0,enumerable:!1,configurable:!1,writable:!1}),(x=n==null?void 0:n.init)==null||x.call(n,!0,...o),n},B=p.ref,q=p.shallowRef,S=(e,s,r)=>{const t=s.get.bind(s),{allProps:i}=j(e);return function(o=!1,a){const n={};if(C(o))for(const u of o){const w=i.get(u);k(n,u,w,e,t,r)}else for(const[u,w]of i.entries())k(n,u,w,e,t,r);return n}},k=(e,s,r,t,i,o)=>{var a,n;if(r===2){const u=i(s);e[s]=o[s]??(o[s]=p.computed({get:(a=u.get)==null?void 0:a.bind(t),set:(n=u.set)==null?void 0:n.bind(t)}))}else r===0&&(e[s]=p.toRef(t,s))},W=e=>{var s;return typeof e=="function"&&!!e.prototype&&!((s=I(e,"prototype"))!=null&&s.writable)},m=(e,s,r,t)=>{const i=Object.getOwnPropertyDescriptors(e);for(const o of Reflect.ownKeys(i)){const a=i[o];"value"in a&&(a.value=M(a.value,r,t)),Object.defineProperty(s,o,a)}};c.activeDeepCloneArgsMap=new WeakMap;const M=(e,s,r=new WeakMap)=>{if(e==null||typeof e!="object")return e;if(r.has(e))return r.get(e);if(C(e)){const o=e.length,a=new Array(o);r.set(e,a);for(let n=0;n<o;n++)a[n]=M(e[n],s,r);return a}const t=D(e);if(t===Object.prototype||t===null){const o=O(t);return r.set(e,o),m(e,o,s,r),o}if(e[A]){const o=e.constructor;if(o.ivueGlobalStore)return r.set(e,e),e;let a;if(s!=null&&s.has(o)){c.activeDeepCloneArgsMap.set(o,s);try{a=e.clone(...s.get(o)??[])}finally{c.activeDeepCloneArgsMap.delete(o)}}else a=e.clone();return r.set(e,a),a}if(e instanceof Date)return new Date(e.getTime());if(e instanceof Map){const o=new e.constructor;r.set(e,o);for(const[a,n]of e)o.set(M(a,s,r),M(n,s,r));return o}if(e instanceof Set){const o=new e.constructor;r.set(e,o);for(const a of e)o.add(M(a,s,r));return o}if(e instanceof RegExp){const o=new RegExp(e.source,e.flags);return o.lastIndex=e.lastIndex,o}if(e instanceof Error){const o=new e.constructor(e.message);return r.set(e,o),m(e,o,s,r),o}if(e instanceof Promise||e instanceof WeakMap||e instanceof WeakSet)return r.set(e,e),e;if(e instanceof DataView){const o=new DataView(e.buffer.slice(0),e.byteOffset,e.byteLength);return r.set(e,o),o}if(ArrayBuffer.isView(e)&&!(e instanceof DataView)){const o=new e.constructor(e);return r.set(e,o),o}if(e instanceof ArrayBuffer){const o=e.slice(0);return r.set(e,o),o}const i=O(t);return r.set(e,i),m(e,i,s,r),i},z={copyOwnProps:m,getClassAccessorsMethodsMap:P,getClassPropertiesAccessorsMap:j};c.IVUE_INSTANCE_SYMBOL=A,c.__test__=z,c.clearCache=()=>{c.accessorsMethodsMaps=new WeakMap,c.propertiesAccessorsMaps=new WeakMap,c.activeDeepCloneArgsMap=new WeakMap},c.copyOwnProps=m,c.deepClone=M,c.iref=B,c.isClass=W,c.ishallowRef=q,c.iuse=e=>e,c.ivue=(e,...s)=>{var u,w,g;const{accessors:r,methods:t}=P(e),i=r!=null&&r.size?O(null):null,o=p.reactive(new e(...s));for(const[f,b]of r)d(o,f,{get:()=>{var h,v;return i[f]??(i[f]=p.computed({get:(h=b.get)==null?void 0:h.bind(o),set:(v=b.set)==null?void 0:v.bind(o)}))},enumerable:b.enumerable,configurable:b.configurable});const a=e==null?void 0:e.ivueDisableReactivity;if(a)for(const f of a){const b=r.get(f);b?d(o,f,{get:(u=b.get)==null?void 0:u.bind(o),set:(w=b.set)==null?void 0:w.bind(o),enumerable:b.enumerable,configurable:b.configurable}):(console.log("des criptor",f,b),o[f]=p.markRaw(o[f]))}const n={writable:!0,configurable:!0,enumerable:!1};for(const f of t)n.value=o[f].bind(o),d(o,f,n);return d(o,"toRefs",{get:(()=>{let f=null;return()=>f??(f=S(o,r,i))})(),enumerable:!1}),d(o,"clone",{value:(...f)=>R(e,s,o,r,t,f),enumerable:!1}),d(o,A,{value:!0,enumerable:!1,configurable:!1,writable:!1}),(g=o==null?void 0:o.init)==null||g.call(o,!1),o},c.propsWithDefaults=(e,s,r=void 0)=>{for(const t in s){const i=e==null?void 0:e[t];s[t].required||i!==void 0&&(typeof i=="object"&&i!==null?s[t].default=()=>M(i,r):W(i)?s[t].default=()=>i:s[t].default=i)}return s},Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/dist/ivue.d.ts CHANGED
@@ -6,16 +6,30 @@ import type { Ref as DemiRef } from 'vue-demi';
6
6
  */
7
7
  export declare type IVue<T extends AnyClass> = InstanceType<T> & {
8
8
  toRefs: IVueToRefsFn<T>;
9
+ clone: IVueClone<T>;
9
10
  };
11
+ /**
12
+ * Type definition for `.clone()` method creates a deep clone of the ivue instance.
13
+ */
14
+ export declare type IVueClone<T extends AnyClass> = (...cloneArgs: CloneArgsFor<InstanceType<T>>) => IVue<T>;
10
15
  /**
11
16
  * Type definition for `.toRefs()` method converts reactive class properties to composable .value properties.
12
17
  * But if props = true OR unwrap = true is specified, the refs will be unwrapped refs to be able to be merged with the the root class properties without losing reactivity.
13
18
  */
19
+ /** Extract only non-method keys from a type */
20
+ declare type NonMethodKeys<T> = {
21
+ [K in keyof T]: T[K] extends AnyFn ? never : K;
22
+ }[keyof T];
23
+ /** Create a type with only data properties and accessors */
24
+ declare type DataProperties<T> = Pick<T, NonMethodKeys<T>>;
25
+ /**
26
+ * Simplified IVueToRefsFn that only works with data properties
27
+ */
14
28
  interface IVueToRefsFn<T extends AnyClass> {
15
- <P extends keyof InstanceType<T>>(props: P[]): Pick<IVueRefs<InstanceType<T>>, P>;
16
- <P extends keyof InstanceType<T>>(props: P[], unwrap: false): Pick<IVueRefs<InstanceType<T>>, P>;
17
- <P extends keyof InstanceType<T>>(props: P[], unwrap: true): Pick<InstanceType<T>, P>;
18
- (props: true): InstanceType<T>;
29
+ <P extends keyof IVueRefs<InstanceType<T>>>(props: P[]): Pick<IVueRefs<InstanceType<T>>, P>;
30
+ <P extends keyof IVueRefs<InstanceType<T>>>(props: P[], unwrap: false): Pick<IVueRefs<InstanceType<T>>, P>;
31
+ <P extends keyof DataProperties<InstanceType<T>>>(props: P[], unwrap: true): Pick<DataProperties<InstanceType<T>>, P>;
32
+ (props: true): DataProperties<InstanceType<T>>;
19
33
  (props: false): IVueRefs<InstanceType<T>>;
20
34
  (): IVueRefs<InstanceType<T>>;
21
35
  }
@@ -24,7 +38,7 @@ interface IVueToRefsFn<T extends AnyClass> {
24
38
  * also knows NOT to convert functions to .value Refs but to leave them as is.
25
39
  */
26
40
  export declare type IVueRefs<T> = {
27
- [K in keyof T]: T[K] extends Function ? T[K] : ToRef<T[K]>;
41
+ [K in keyof T as T[K] extends AnyFn ? never : K]: ToRef<T[K]>;
28
42
  };
29
43
  /**
30
44
  * Unwraps Ref Recursively, helps resolve fully the bare value types of any type T
@@ -45,7 +59,7 @@ declare type UnwrapComposableRefs<T> = T extends Ref | DemiRef ? UnwrapRefRecurs
45
59
  */
46
60
  export declare type Use<T = any> = T extends Ref | DemiRef ? UnwrapRefRecursively<T> : UnwrapComposableRefs<T extends AnyFn ? ReturnType<T> : T>;
47
61
  /**
48
- * Extracts object defined emit types by converting them to a plain interface
62
+ * Extracts object defined emit types by converting them to a plain interface.
49
63
  */
50
64
  export declare type ExtractEmitTypes<T extends Record<string, any>> = UnionToIntersection<RecordToUnion<{
51
65
  [K in keyof T]: (evt: K, ...args: Parameters<T[K]>) => void;
@@ -68,11 +82,11 @@ export declare type AnyFn = (...args: any[]) => any;
68
82
  /**
69
83
  * Any JavaScript class of any type.
70
84
  */
71
- export declare type AnyClass = abstract new (...args: any[]) => any;
85
+ export declare type AnyClass = new (...args: any[]) => any;
72
86
  /**
73
- * Descriptors map type.
87
+ * Accessors map type.
74
88
  */
75
- declare type Descriptors = Map<string, PropertyDescriptor>;
89
+ declare type Accessors = Map<string, PropertyDescriptor>;
76
90
  /**
77
91
  * Infer paramaters of a constructor function of a Class.
78
92
  */
@@ -85,14 +99,6 @@ export declare type InferredArgs<T> = T extends {
85
99
  export declare type PrefixKeys<T, P extends string | undefined = undefined> = {
86
100
  [K in Extract<keyof T, string> as P extends string ? `${P}${K}` : K]: T[K];
87
101
  };
88
- /**
89
- * Get Interface's property's function arguments Parmeters<F>
90
- */
91
- export declare type IFnParameters<T extends Record<any, any>, K extends string> = Parameters<Required<Pick<T, K>>[K]>;
92
- /**
93
- * Get Interface's [T] property's [P] function arguments Parmeters<F> parameter by key [K]
94
- */
95
- export declare type IFnParameter<T extends Record<any, any>, P extends keyof T, K extends number> = FnParameter<ValueOf<T, P>, K>;
96
102
  /**
97
103
  * Get function arguments Parmeters<F> parameter by key K
98
104
  */
@@ -100,34 +106,96 @@ export declare type FnParameter<F extends AnyFn, K extends number> = Parameters<
100
106
  /**
101
107
  * Convert Union Type to Intersection Type.
102
108
  */
103
- export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
109
+ declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
104
110
  /**
105
111
  * Convert Record to Union Type.
106
112
  */
107
- export declare type RecordToUnion<T extends Record<string, any>> = T[keyof T];
113
+ declare type RecordToUnion<T extends Record<string, any>> = T[keyof T];
108
114
  /**
109
115
  * Gets object T property by key [K].
110
116
  */
111
- export declare type ValueOf<T extends Record<any, any>, K> = T[K];
117
+ declare type ValueOf<T extends Record<any, any>, K> = T[K];
118
+ /**
119
+ * Props Map Value type.
120
+ */
121
+ declare type PropsMapValue = {
122
+ allProps: Map<string, PropKind>;
123
+ onlyProps: Set<string>;
124
+ };
125
+ /**
126
+ * Accessors and Methods map type.
127
+ */
128
+ declare type AccessorsMethodsMap = {
129
+ accessors: Accessors;
130
+ methods: Set<string>;
131
+ };
132
+ export declare type IVueInstanceBase = {
133
+ init?: (...args: any[]) => void;
134
+ };
135
+ /**
136
+ * IVue static configuration interface.
137
+ */
138
+ export interface IVueStaticConfig<T> {
139
+ ivueGlobalStore?: boolean;
140
+ ivueCloneByReference?: Set<keyof T>;
141
+ ivueDisableReactivity?: Set<keyof T>;
142
+ }
143
+ /**
144
+ * IVue constructor type.
145
+ */
146
+ export declare type IVueConstructor<T> = new (...args: any[]) => T;
147
+ /**
148
+ * IVue class type with static configuration.
149
+ */
150
+ export declare type IVueClass<T> = IVueConstructor<T> & IVueStaticConfig<T>;
151
+ /**
152
+ * Get IVue init() method arguments IVueInitArgs<T>
153
+ */
154
+ export declare type IVueInitArgs<T extends IVueInstanceBase> = T['init'] extends (...args: any[]) => any ? Parameters<T['init']> : never;
155
+ /**
156
+ * Get Interface's method keys MethodKeys<T>
157
+ */
158
+ declare type MethodKeys<T> = {
159
+ [P in keyof T]: T[P] extends (...args: any[]) => any ? P : never;
160
+ }[keyof T];
161
+ /**
162
+ * Get Interface's property's function arguments Parameters<F>
163
+ */
164
+ export declare type IFnParameters<T extends Record<any, any> | InstanceType<AnyClass>, K extends MethodKeys<T>> = Parameters<Extract<Required<Pick<T, K>>[K], AnyFn>>;
165
+ /**
166
+ * Get Interface's [T] property's [P] function arguments Parmeters<F> parameter by key [K]
167
+ */
168
+ export declare type IFnParameter<T extends Record<any, any>, P extends keyof T, K extends number> = FnParameter<ValueOf<T, P>, K>;
169
+ export declare type IVueDeepCloneArgsMap = Map<AnyClass, any[]>;
170
+ declare type CloneArgsFor<T> = T extends {
171
+ init: (isClone: boolean, ...rest: infer A) => any;
172
+ } ? A : [];
112
173
  /** Types End. */
174
+ export declare const IVUE_INSTANCE_SYMBOL: unique symbol;
113
175
  /**
114
- * Store all descriptors for each class prototype processed by
115
- * @see {getAllClassDescriptors}
176
+ * Stores accessors for each class prototype processed by
177
+ * @see {getClassAccessorsMethodsMap}. Uses WeakMap to allow garbage collection
178
+ * of unused class accessors, ensuring memory efficiency in long-running applications.
116
179
  */
117
- export declare const descriptorsMap: Map<any, any>;
180
+ export declare let accessorsMethodsMaps: WeakMap<object, AccessorsMethodsMap>;
118
181
  /**
119
- * Get descriptors of an entire class prototype ancestors chain as a Map.
120
- * Completely emulates JavaScript class inheritance chain for getters and setters.
121
- *
122
- * @param className
123
- * @return {Descriptors}
182
+ * Property kind enum for distinguishing between data properties and accessors.
183
+ */
184
+ declare const enum PropKind {
185
+ Data = 0,
186
+ Accessor = 2
187
+ }
188
+ /**
189
+ * Stores properties for each class prototype processed by
190
+ * @see {getClassPropertiesAccessorsMap}. Uses WeakMap to allow garbage collection
191
+ * of unused class properties, ensuring memory efficiency in long-running applications.
124
192
  */
125
- export declare function getAllClassDescriptors(className: AnyClass): Descriptors;
193
+ export declare let propertiesAccessorsMaps: WeakMap<object, PropsMapValue>;
126
194
  /**
127
195
  * Infinite Vue (ivue) class reactive initializer.
128
196
  *
129
197
  * Converts class instance to a reactive object,
130
- * where descriptors are converted to computeds.
198
+ * where accessors are converted to computeds.
131
199
  *
132
200
  * You can turn off computed behaviour by adding static
133
201
  * ivue object and setting the getter props to false.
@@ -143,41 +211,30 @@ export declare function getAllClassDescriptors(className: AnyClass): Descriptors
143
211
  * @param args Class constructor arguments that you would pass to a `new AnyClass(args...)`
144
212
  * @returns {IVue<T>}
145
213
  */
146
- export declare function ivue<T extends AnyClass>(className: T, ...args: InferredArgs<T>): IVue<T>;
147
- /**
148
- * Get properties of an entire class prototype ancestors chain as a Map.
149
- */
150
- export declare function getAllClassProperties(obj: object): Set<string>;
214
+ export declare const ivue: <T extends AnyClass>(className: T, ...args: InferredArgs<T>) => IVue<T>;
151
215
  /**
152
216
  * `iref()` is an alias for Vue ref() function but returns an unwrapped type without the .value
153
217
  * `iref()` does not alter the behavior of ref(), but simply transforms the type to an unwrapped raw value.
154
218
  * @param val T
155
- * @returns {T}
219
+ * @returns {T} Ref but with type unwrapped
156
220
  */
157
221
  export declare const iref: <T = any>(value?: T | undefined) => T;
158
222
  /**
159
223
  * `ishallowRef()` is an alias for Vue shallowRef() function but returns an unwrapped type without the .value
160
224
  * `ishallowRef()` does not alter the behavior of shallowRef(), but simply transforms the type to an unwrapped raw value.
161
225
  * @param val T
162
- * @returns {T}
226
+ * @returns {T} ShallowRef but with type unwrapped
163
227
  */
164
228
  export declare const ishallowRef: <T = any>(value?: T | undefined) => T;
165
229
  /**
166
- * Three modes of operation:
167
- * 1. `iuse(useComposable(arg, arg2, arg3, ...))` converts the return types of a Composable / Ref to pure raw unwrapped type definition.
168
- * Returns for all properties of an object an unwrapped raw type definition,
169
- * unwraps direct Refs & ComputedRefs as well down to their raw types.
230
+ * `iuse()` is a helper function that unwraps any Vue 3 composable return type down to its bare types.
170
231
  *
171
- * 2. `iuse(useComposable, arg, arg2, arg3, ...)` for cleaner syntax for #1, it does exactly the same thing but
172
- * here the TypeScript inference works for composable function arguments to assist you with intellisence,
173
- * like they work for constructor arguments in the cause of `ivue()` core function,
174
- * making the API cleaner to look at and make it compatible with how this function operates with classes, see #3.
232
+ * It does not alter the behavior of the composable, but simply transforms the type to an unwrapped raw value.
175
233
  *
176
- * 3. `iuse(AnyClass, ...args)` If AnyClass is supplied and that class's arguments into `iuse(AnyClass, ...args)`,
177
- * it returns an 'ivue(AnyClass, ...args).toRefs()` object for all properties but casts
178
- * their types as raw (no-Ref) types to fit with reactive() structure of the ivue class context.
234
+ * @param obj Any Vue 3 composable return type or any object or any type
235
+ * @returns {Use<T>} Composable with types unwrapped
179
236
  */
180
- export declare function iuse<T extends AnyClass | AnyFn | Object | any>(classFunctionObject?: T, ...args: T extends AnyClass ? InferredArgs<T> : T extends AnyFn ? Parameters<T extends (...args: any[]) => any ? T : any> : any): T extends AnyClass ? InstanceType<T> : Use<T>;
237
+ export declare const iuse: <T extends object>(obj: T) => Use<T>; /** Unwrap any other Object or any type down to its bare types. */
181
238
  /**
182
239
  * Vue props interface in defineComponent() style.
183
240
  */
@@ -203,7 +260,7 @@ export declare type VuePropsWithDefaults<T extends VuePropsObject> = {
203
260
  * @param val Any value
204
261
  * @returns boolean If it's a JavaScript Class returns true
205
262
  */
206
- export declare function isClass(val: any): boolean;
263
+ export declare const isClass: (val: any) => boolean;
207
264
  /**
208
265
  * Creates props with defaults in defineComponent() style.
209
266
  *
@@ -229,6 +286,25 @@ export declare function isClass(val: any): boolean;
229
286
  * @param typedProps Props declared in defineComponent() style with type and possibly required declared, but without default
230
287
  * @returns Props declared in defineComponent() style with all properties having default property declared.
231
288
  */
232
- export declare function propsWithDefaults<T extends VuePropsObject>(defaults: Record<string, any>, typedProps: T): VuePropsWithDefaults<T>;
289
+ export declare const propsWithDefaults: <T extends VuePropsObject>(defaults: Record<string, any>, typedProps: T, deepCloneArgs?: IVueDeepCloneArgsMap | undefined) => VuePropsWithDefaults<T>;
290
+ /**
291
+ * Copies own properties (including symbols and non-enumerable) from source to target.
292
+ * Recursively deep clones values, but preserves getters/setters as-is.
293
+ */
294
+ export declare const copyOwnProps: (source: any, target: any, deepCloneArgs: IVueDeepCloneArgsMap | undefined, seen: WeakMap<object, any>) => void;
295
+ export declare let activeDeepCloneArgsMap: WeakMap<AnyClass, IVueDeepCloneArgsMap>;
296
+ export declare const deepClone: (source: any, deepCloneArgs?: IVueDeepCloneArgsMap, seen?: WeakMap<object, any>) => any;
297
+ /**
298
+ * Clears the accessorsMethodsMaps, and propertiesAccessorsMaps WeakMaps.
299
+ * Useful for SSR scenarios where you want to reset the cache between requests.
300
+ * Also useful for testing purposes to ensure a clean state.
301
+ */
302
+ export declare const clearCache: () => void;
303
+ /** Exported for testing purposes. */
304
+ export declare const __test__: {
305
+ copyOwnProps: (source: any, target: any, deepCloneArgs: IVueDeepCloneArgsMap | undefined, seen: WeakMap<object, any>) => void;
306
+ getClassAccessorsMethodsMap: (className: AnyClass) => AccessorsMethodsMap;
307
+ getClassPropertiesAccessorsMap: (obj: object) => PropsMapValue;
308
+ };
233
309
  /** Necessary ivue.ts to be treated as a module. */
234
310
  export {};