@madronejs/core 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,557 +0,0 @@
1
- const A = /* @__PURE__ */ new Set();
2
- let B;
3
- function re() {
4
- return [...A];
5
- }
6
- function ce() {
7
- return re().at(-1);
8
- }
9
- function x() {
10
- B = ce();
11
- }
12
- function Pe(e) {
13
- e && (A.add(e), x());
14
- }
15
- function _e(e) {
16
- A.delete(e), x();
17
- }
18
- function se() {
19
- return B;
20
- }
21
- const W = /* @__PURE__ */ new WeakMap();
22
- function U(e) {
23
- return (se()?.toRaw ?? ((t) => t))(e);
24
- }
25
- function I(e) {
26
- W.set(U(e), Date.now());
27
- }
28
- function Ae(e) {
29
- return W.get(U(e));
30
- }
31
- const f = Symbol("keys"), L = Symbol("computed"), H = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap();
32
- let y = [], T = null;
33
- const ae = (e) => H.has(e), Y = (e) => D.has(e), M = (e) => H.get(e), ue = (e) => D.get(e), ie = (e) => Y(e) ? ue(e) : e, oe = (e, n) => {
34
- H.set(e, n), D.set(n, e);
35
- }, fe = () => {
36
- T === null && (T = Symbol("scheduler"), queueMicrotask(() => {
37
- try {
38
- for (; y.length > 0; ) {
39
- const e = y;
40
- y = [];
41
- for (const n of e)
42
- try {
43
- n();
44
- } catch (t) {
45
- console.error("Unhandled error in scheduled task:", t);
46
- }
47
- }
48
- } finally {
49
- T = null;
50
- }
51
- }));
52
- }, le = (e) => {
53
- y.push(e), fe();
54
- }, de = (e, n) => {
55
- const t = w.get(e), c = t?.get(n);
56
- if (c) {
57
- for (const r of c)
58
- R.get(r)?.get(n)?.delete(e);
59
- c.clear(), t.delete(n), t.size === 0 && w.delete(e);
60
- }
61
- }, N = (e) => {
62
- const n = w.get(e);
63
- if (n) {
64
- for (const [t, c] of n)
65
- for (const r of c)
66
- R.get(r)?.get(t)?.delete(e);
67
- w.delete(e);
68
- }
69
- }, $ = (e, n) => {
70
- const t = he();
71
- if (!t) return;
72
- w.has(t) || w.set(t, /* @__PURE__ */ new Map()), R.has(e) || R.set(e, /* @__PURE__ */ new Map());
73
- const c = R.get(e), r = w.get(t);
74
- c.has(n) || c.set(n, /* @__PURE__ */ new Set()), r.has(n) || r.set(n, /* @__PURE__ */ new Set());
75
- const s = c.get(n), a = r.get(n);
76
- s.add(t), a.add(e);
77
- }, d = (e, n) => {
78
- const t = M(e);
79
- t && $(t, n);
80
- }, X = (e, n) => {
81
- const t = R.get(e);
82
- if (t?.get(n))
83
- for (const c of t.get(n))
84
- c.setDirty(), de(c, n);
85
- }, h = (e, n) => {
86
- X(M(e), n);
87
- }, P = [];
88
- function he() {
89
- return P.at(-1);
90
- }
91
- class V {
92
- /**
93
- * Factory method to create a new ObservableItem.
94
- * @internal
95
- */
96
- static create(...n) {
97
- return new V(...n);
98
- }
99
- /**
100
- * Creates a new ObservableItem.
101
- * @param options - Configuration options
102
- */
103
- constructor(n) {
104
- this.name = n.name, this.get = n.get, this.set = n.set, this.cache = !!(n.cache ?? !0), this.alive = !0, this.dirty = !0, this.cachedVal = void 0, this.hooks = {
105
- onGet: n.onGet,
106
- onSet: n.onSet,
107
- onChange: n.onChange,
108
- onImmediateChange: n.onImmediateChange
109
- };
110
- }
111
- callHook(n) {
112
- typeof this.hooks[n] == "function" && this.hooks[n](this);
113
- }
114
- /**
115
- * Stop observing and dispose of the observer
116
- * @returns {void}
117
- */
118
- dispose() {
119
- N(this), this.alive = !1, this.dirty = !1, this.cachedVal = void 0, this.prev = void 0;
120
- }
121
- wrap(n) {
122
- P.push(this);
123
- try {
124
- return n();
125
- } finally {
126
- P.pop();
127
- }
128
- }
129
- setDirty() {
130
- this.alive && !this.dirty && (this.dirty = !0, X(this, L), this.prev = this.cachedVal, this.cachedVal = void 0, this.callHook(
131
- "onImmediateChange"
132
- /* onImmediateChange */
133
- ), le(() => this.notifyChange()));
134
- }
135
- notifyChange() {
136
- this.callHook(
137
- "onChange"
138
- /* onChange */
139
- ), this.prev = void 0;
140
- }
141
- run() {
142
- if (!this.alive) return;
143
- const n = this.wrap(() => {
144
- if (this.cache && this.dirty || !this.cache) {
145
- N(this);
146
- try {
147
- this.cachedVal = this.get();
148
- } finally {
149
- this.dirty = !1;
150
- }
151
- }
152
- return this.cachedVal;
153
- });
154
- return $(this, L), this.callHook(
155
- "onGet"
156
- /* onGet */
157
- ), n;
158
- }
159
- /** The value of the observer */
160
- get value() {
161
- return this.run();
162
- }
163
- set value(n) {
164
- if (typeof this.set == "function")
165
- this.set(n), this.callHook(
166
- "onSet"
167
- /* onSet */
168
- );
169
- else
170
- throw new TypeError(`No setter defined for "${this.name}"`);
171
- }
172
- }
173
- function q(...e) {
174
- return V.create(...e);
175
- }
176
- function me(e) {
177
- return q(e);
178
- }
179
- const o = (e) => {
180
- const {
181
- name: n,
182
- target: t,
183
- key: c,
184
- receiver: r,
185
- value: s,
186
- keysChanged: a = !1,
187
- valueChanged: l = !1
188
- } = e;
189
- return {
190
- name: n,
191
- target: t,
192
- key: c,
193
- receiver: r,
194
- value: s,
195
- keysChanged: a,
196
- valueChanged: l
197
- };
198
- }, ve = (e, n, t, c) => {
199
- d(n, t), e?.onGet && e.onGet(o({
200
- name: e.name,
201
- target: n,
202
- key: t,
203
- receiver: c
204
- }));
205
- }, Se = (e, n, t, c) => {
206
- const r = n[t], s = Array.isArray(n);
207
- let a = !1, l = !1;
208
- t in n || (h(n, f), l = !0, s && h(n, "length")), (r !== c || s) && (h(n, t), a = !0), (l || a) && e?.onSet && e.onSet(o({
209
- name: e.name,
210
- target: n,
211
- key: t,
212
- value: c,
213
- keysChanged: l,
214
- valueChanged: a
215
- }));
216
- }, Ce = (e, n, t) => {
217
- h(n, t), h(n, f), e?.onDelete && e.onDelete(o({
218
- name: e.name,
219
- target: n,
220
- key: t,
221
- keysChanged: !0
222
- }));
223
- }, z = (e, n, t) => {
224
- d(n, f), e?.onHas && e.onHas(o({ name: e.name, target: n, key: t }));
225
- };
226
- function F(e) {
227
- const n = e.needsProxy || (() => !0);
228
- return {
229
- get: (t, c, r) => {
230
- ve(e, t, c, r);
231
- const s = Reflect.get(t, c, r);
232
- return e?.deep && s && typeof s == "object" && n({ target: t, key: c, value: s }) && Object.getOwnPropertyDescriptor(t, c)?.configurable ? S(s, e) : s;
233
- },
234
- set: (t, c, r) => (Se(e, t, c, r), Reflect.set(t, c, r)),
235
- deleteProperty: (...t) => (Ce(e, ...t), Reflect.deleteProperty(...t)),
236
- has: (t, c) => (z(e, t), Reflect.has(t, c)),
237
- ownKeys: (t) => (z(e, t), Reflect.ownKeys(t)),
238
- getPrototypeOf: (t) => Object.getPrototypeOf(t)
239
- };
240
- }
241
- const we = (e) => ({
242
- ...F(e)
243
- }), Re = (e) => ({
244
- ...F(e)
245
- }), v = (e, n) => n?.deep && e && typeof e == "object" ? S(e, n) : e;
246
- function* b(e, n, t) {
247
- for (const c of e)
248
- yield t(c);
249
- }
250
- const be = (e) => ({
251
- get: (n, t, c) => t === "size" ? (d(n, f), e?.onGet?.(o({
252
- name: e.name,
253
- target: n,
254
- key: t
255
- })), n.size) : t === "has" ? (r) => (d(n, f), e?.onGet?.(o({
256
- name: e.name,
257
- target: n,
258
- key: t,
259
- value: r
260
- })), n.has(r)) : t === "add" ? (r) => {
261
- const s = n.has(r);
262
- return n.add(r), s || (h(n, f), e?.onSet?.(o({
263
- name: e.name,
264
- target: n,
265
- key: t,
266
- value: r,
267
- keysChanged: !0
268
- }))), c;
269
- } : t === "delete" ? (r) => {
270
- const s = n.has(r), a = n.delete(r);
271
- return s && (h(n, f), e?.onDelete?.(o({
272
- name: e.name,
273
- target: n,
274
- key: t,
275
- value: r,
276
- keysChanged: !0
277
- }))), a;
278
- } : t === "clear" ? () => {
279
- const r = n.size > 0;
280
- n.clear(), r && (h(n, f), e?.onDelete?.(o({
281
- name: e.name,
282
- target: n,
283
- key: t,
284
- keysChanged: !0
285
- })));
286
- } : t === "forEach" ? (r, s) => {
287
- d(n, f), e?.onGet?.(o({
288
- name: e.name,
289
- target: n,
290
- key: t
291
- }));
292
- for (const [a, l] of n.entries())
293
- r.call(s, v(a, e), v(l, e), c);
294
- } : t === "values" || t === "keys" ? () => (d(n, f), e?.onGet?.(o({
295
- name: e.name,
296
- target: n,
297
- key: t
298
- })), b(n.values(), e, (r) => v(r, e))) : t === "entries" ? () => (d(n, f), e?.onGet?.(o({
299
- name: e.name,
300
- target: n,
301
- key: t
302
- })), b(
303
- n.entries(),
304
- e,
305
- ([r, s]) => [v(r, e), v(s, e)]
306
- )) : t === Symbol.iterator ? () => (d(n, f), e?.onGet?.(o({
307
- name: e.name,
308
- target: n,
309
- key: t
310
- })), b(n[Symbol.iterator](), e, (r) => v(r, e))) : t === Symbol.toStringTag ? "Set" : Reflect.get(n, t, c)
311
- }), Oe = (e) => ({
312
- get: (n, t, c) => t === "size" ? (d(n, f), e?.onGet?.(o({
313
- name: e.name,
314
- target: n,
315
- key: t
316
- })), n.size) : t === "has" ? (r) => (d(n, r), e?.onGet?.(o({
317
- name: e.name,
318
- target: n,
319
- key: r
320
- })), n.has(r)) : t === "get" ? (r) => (d(n, r), e?.onGet?.(o({
321
- name: e.name,
322
- target: n,
323
- key: r
324
- })), v(n.get(r), e)) : t === "set" ? (r, s) => {
325
- const a = n.has(r), l = n.get(r);
326
- return n.set(r, s), a || h(n, f), (!a || l !== s) && (h(n, r), e?.onSet?.(o({
327
- name: e.name,
328
- target: n,
329
- key: r,
330
- value: s,
331
- keysChanged: !a,
332
- valueChanged: l !== s
333
- }))), c;
334
- } : t === "delete" ? (r) => {
335
- const s = n.has(r), a = n.delete(r);
336
- return s && (h(n, f), h(n, r), e?.onDelete?.(o({
337
- name: e.name,
338
- target: n,
339
- key: r,
340
- keysChanged: !0
341
- }))), a;
342
- } : t === "clear" ? () => {
343
- const r = [...n.keys()], s = n.size > 0;
344
- if (n.clear(), s) {
345
- h(n, f);
346
- for (const a of r)
347
- h(n, a);
348
- e?.onDelete?.(o({
349
- name: e.name,
350
- target: n,
351
- key: t,
352
- keysChanged: !0
353
- }));
354
- }
355
- } : t === "forEach" ? (r, s) => {
356
- d(n, f), e?.onGet?.(o({
357
- name: e.name,
358
- target: n,
359
- key: t
360
- }));
361
- for (const [a, l] of n.entries())
362
- r.call(s, v(l, e), a, c);
363
- } : t === "keys" ? () => (d(n, f), e?.onGet?.(o({
364
- name: e.name,
365
- target: n,
366
- key: t
367
- })), n.keys()) : t === "values" ? () => (d(n, f), e?.onGet?.(o({
368
- name: e.name,
369
- target: n,
370
- key: t
371
- })), b(n.values(), e, (r) => v(r, e))) : t === "entries" ? () => (d(n, f), e?.onGet?.(o({
372
- name: e.name,
373
- target: n,
374
- key: t
375
- })), b(
376
- n.entries(),
377
- e,
378
- ([r, s]) => [r, v(s, e)]
379
- )) : t === Symbol.iterator ? () => (d(n, f), e?.onGet?.(o({
380
- name: e.name,
381
- target: n,
382
- key: t
383
- })), b(
384
- n[Symbol.iterator](),
385
- e,
386
- ([r, s]) => [r, v(s, e)]
387
- )) : t === Symbol.toStringTag ? "Map" : Reflect.get(n, t, c)
388
- }), Q = Object.freeze({
389
- object: we,
390
- array: Re,
391
- set: be,
392
- map: Oe
393
- });
394
- function S(e, n) {
395
- if (ae(e)) return M(e);
396
- if (Y(e)) return e;
397
- const t = n || {}, c = { ...t, deep: t?.deep ?? !0 }, r = S.getStringType(e);
398
- if (!S.hasHandler(r)) return e;
399
- const s = new Proxy(e, S.typeHandler(r, c));
400
- return oe(e, s), s;
401
- }
402
- const Ge = (e) => {
403
- const n = Object.getPrototypeOf(e);
404
- return n === null ? !0 : n === Object.prototype;
405
- };
406
- S.getStringType = (e) => e === null ? "null" : typeof e != "object" ? typeof e : Array.isArray(e) ? "array" : e instanceof Map ? "map" : e instanceof Set ? "set" : Ge(e) ? "object" : "native";
407
- S.hasHandler = (e) => !!Q[e];
408
- S.typeHandler = (e, n) => Q[e]?.(n);
409
- function J(e, n, t) {
410
- const c = q({
411
- get: e,
412
- onChange: ({ value: s, prev: a }) => n(s, a)
413
- }), r = c.run();
414
- return t?.immediate && n(r), () => c.dispose();
415
- }
416
- function g(e, n, t) {
417
- let c, r;
418
- if (n.cache) {
419
- const s = me({
420
- ...n,
421
- get: n.get,
422
- name: e,
423
- onImmediateChange: t?.computed?.onImmediateChange,
424
- onChange: t?.computed?.onChange,
425
- onGet: t?.computed?.onGet,
426
- onSet: t?.computed?.onSet
427
- });
428
- c = function() {
429
- return I(this), s.value;
430
- }, r = function(l) {
431
- s.value = l;
432
- };
433
- } else
434
- c = function() {
435
- return I(this), n.get.call(this);
436
- }, r = function(...a) {
437
- n.set.call(this, ...a);
438
- };
439
- return {
440
- enumerable: n.enumerable,
441
- configurable: n.configurable,
442
- get: c,
443
- set: r
444
- };
445
- }
446
- function j(e, n, t) {
447
- const c = { value: n.value }, r = S(c, {
448
- name: e,
449
- onGet: t?.reactive?.onGet,
450
- onHas: t?.reactive?.onHas,
451
- onSet: t?.reactive?.onSet,
452
- onDelete: t?.reactive?.onDelete,
453
- needsProxy: t?.reactive?.needsProxy,
454
- deep: n.deep ?? t?.reactive?.deep
455
- });
456
- return {
457
- configurable: n.configurable,
458
- enumerable: n.enumerable,
459
- get: function() {
460
- I(this);
461
- const { value: a } = r;
462
- return Array.isArray(a) && Reflect.get(a, "length"), a;
463
- },
464
- set: function(a) {
465
- r.value = a;
466
- }
467
- };
468
- }
469
- function Z(e, n, t, c) {
470
- Object.defineProperty(e, n, g(n, t, c));
471
- }
472
- function p(e, n, t, c) {
473
- Object.defineProperty(e, n, j(n, t, c));
474
- }
475
- const ye = {
476
- toRaw: ie,
477
- watch: J,
478
- describeProperty: j,
479
- defineProperty: p,
480
- describeComputed: g,
481
- defineComputed: Z
482
- }, E = /* @__PURE__ */ new Set(["__proto__", "__ob__"]), _ = "value", Ie = (e) => {
483
- e[_] += 1;
484
- };
485
- function He(e) {
486
- if (!e?.reactive || typeof e.reactive != "function")
487
- throw new Error(
488
- `MadroneVue3 requires Vue's reactive function. Either use "madrone/integrations/vue" for automatic setup, or pass { reactive, toRaw } from "vue".`
489
- );
490
- const { reactive: n, toRaw: t } = e, c = t ?? ((u) => u), r = /* @__PURE__ */ new WeakMap(), s = (u, i) => {
491
- const m = c(u);
492
- let C = r.get(m);
493
- C || (C = /* @__PURE__ */ new Map(), r.set(m, C));
494
- let G = C.get(i);
495
- return G || (G = n({ [_]: 0 }), C.set(i, G)), G;
496
- }, a = (u, i) => {
497
- E.has(i) || Reflect.get(s(u, i), _);
498
- }, l = (u, i) => {
499
- E.has(i) || Ie(s(u, i));
500
- }, K = (u, i) => {
501
- const m = c(u), C = r.get(m);
502
- C && l(C, i), r.delete(m);
503
- }, O = {
504
- computed: {
505
- onGet: (u) => {
506
- a(u, u.name);
507
- },
508
- onImmediateChange: (u) => {
509
- l(u, u.name);
510
- }
511
- },
512
- reactive: {
513
- onGet: ({ target: u, key: i }) => {
514
- I(u), a(u, i);
515
- },
516
- onHas: ({ target: u, key: i }) => {
517
- a(u, i);
518
- },
519
- onDelete: ({ target: u, key: i }) => {
520
- K(u, i);
521
- },
522
- onSet: ({ target: u, key: i, keysChanged: m }) => {
523
- l(u, i), m && l(u);
524
- },
525
- needsProxy: ({ key: u }) => !E.has(u)
526
- }
527
- };
528
- function k(u, i) {
529
- return g(u, i, O);
530
- }
531
- function ee(u, i) {
532
- return j(u, i, O);
533
- }
534
- function ne(u, i, m) {
535
- return Z(u, i, m, O);
536
- }
537
- function te(u, i, m) {
538
- return p(u, i, m, O);
539
- }
540
- return {
541
- toRaw: ye.toRaw,
542
- watch: J,
543
- describeProperty: ee,
544
- defineProperty: te,
545
- describeComputed: k,
546
- defineComputed: ne
547
- };
548
- }
549
- export {
550
- ye as M,
551
- Pe as a,
552
- He as b,
553
- se as g,
554
- Ae as l,
555
- _e as r,
556
- U as t
557
- };