rumious 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1,2653 +1 @@
1
- var Rumious = (function (exports) {
2
- 'use strict';
3
-
4
- function _arrayLikeToArray(r, a) {
5
- (null == a || a > r.length) && (a = r.length);
6
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
7
- return n;
8
- }
9
- function _arrayWithHoles(r) {
10
- if (Array.isArray(r)) return r;
11
- }
12
- function _assertThisInitialized(e) {
13
- if (undefined === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
14
- return e;
15
- }
16
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
17
- try {
18
- var i = n[a](c),
19
- u = i.value;
20
- } catch (n) {
21
- return void e(n);
22
- }
23
- i.done ? t(u) : Promise.resolve(u).then(r, o);
24
- }
25
- function _asyncToGenerator(n) {
26
- return function () {
27
- var t = this,
28
- e = arguments;
29
- return new Promise(function (r, o) {
30
- var a = n.apply(t, e);
31
- function _next(n) {
32
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
33
- }
34
- function _throw(n) {
35
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
36
- }
37
- _next(undefined);
38
- });
39
- };
40
- }
41
- function _callSuper(t, o, e) {
42
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
43
- }
44
- function _classCallCheck(a, n) {
45
- if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
46
- }
47
- function _construct(t, e, r) {
48
- if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
49
- var o = [null];
50
- o.push.apply(o, e);
51
- var p = new (t.bind.apply(t, o))();
52
- return r && _setPrototypeOf(p, r.prototype), p;
53
- }
54
- function _defineProperties(e, r) {
55
- for (var t = 0; t < r.length; t++) {
56
- var o = r[t];
57
- o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
58
- }
59
- }
60
- function _createClass(e, r, t) {
61
- return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
62
- writable: false
63
- }), e;
64
- }
65
- function _createForOfIteratorHelper(r, e) {
66
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
67
- if (!t) {
68
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
69
- t && (r = t);
70
- var n = 0,
71
- F = function () {};
72
- return {
73
- s: F,
74
- n: function () {
75
- return n >= r.length ? {
76
- done: true
77
- } : {
78
- done: false,
79
- value: r[n++]
80
- };
81
- },
82
- e: function (r) {
83
- throw r;
84
- },
85
- f: F
86
- };
87
- }
88
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
89
- }
90
- var o,
91
- a = true,
92
- u = false;
93
- return {
94
- s: function () {
95
- t = t.call(r);
96
- },
97
- n: function () {
98
- var r = t.next();
99
- return a = r.done, r;
100
- },
101
- e: function (r) {
102
- u = true, o = r;
103
- },
104
- f: function () {
105
- try {
106
- a || null == t.return || t.return();
107
- } finally {
108
- if (u) throw o;
109
- }
110
- }
111
- };
112
- }
113
- function _defineProperty(e, r, t) {
114
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
115
- value: t,
116
- enumerable: true,
117
- configurable: true,
118
- writable: true
119
- }) : e[r] = t, e;
120
- }
121
- function _getPrototypeOf(t) {
122
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
123
- return t.__proto__ || Object.getPrototypeOf(t);
124
- }, _getPrototypeOf(t);
125
- }
126
- function _inherits(t, e) {
127
- if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
128
- t.prototype = Object.create(e && e.prototype, {
129
- constructor: {
130
- value: t,
131
- writable: true,
132
- configurable: true
133
- }
134
- }), Object.defineProperty(t, "prototype", {
135
- writable: false
136
- }), e && _setPrototypeOf(t, e);
137
- }
138
- function _isNativeFunction(t) {
139
- try {
140
- return -1 !== Function.toString.call(t).indexOf("[native code]");
141
- } catch (n) {
142
- return "function" == typeof t;
143
- }
144
- }
145
- function _isNativeReflectConstruct() {
146
- try {
147
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
148
- } catch (t) {}
149
- return (_isNativeReflectConstruct = function () {
150
- return !!t;
151
- })();
152
- }
153
- function _iterableToArrayLimit(r, l) {
154
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
155
- if (null != t) {
156
- var e,
157
- n,
158
- i,
159
- u,
160
- a = [],
161
- f = true,
162
- o = false;
163
- try {
164
- if (i = (t = t.call(r)).next, 0 === l) {
165
- if (Object(t) !== t) return;
166
- f = !1;
167
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
168
- } catch (r) {
169
- o = true, n = r;
170
- } finally {
171
- try {
172
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
173
- } finally {
174
- if (o) throw n;
175
- }
176
- }
177
- return a;
178
- }
179
- }
180
- function _nonIterableRest() {
181
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
182
- }
183
- function ownKeys(e, r) {
184
- var t = Object.keys(e);
185
- if (Object.getOwnPropertySymbols) {
186
- var o = Object.getOwnPropertySymbols(e);
187
- r && (o = o.filter(function (r) {
188
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
189
- })), t.push.apply(t, o);
190
- }
191
- return t;
192
- }
193
- function _objectSpread2(e) {
194
- for (var r = 1; r < arguments.length; r++) {
195
- var t = null != arguments[r] ? arguments[r] : {};
196
- r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
197
- _defineProperty(e, r, t[r]);
198
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
199
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
200
- });
201
- }
202
- return e;
203
- }
204
- function _possibleConstructorReturn(t, e) {
205
- if (e && ("object" == typeof e || "function" == typeof e)) return e;
206
- if (undefined !== e) throw new TypeError("Derived constructors may only return object or undefined");
207
- return _assertThisInitialized(t);
208
- }
209
- function _regeneratorRuntime() {
210
- _regeneratorRuntime = function () {
211
- return e;
212
- };
213
- var t,
214
- e = {},
215
- r = Object.prototype,
216
- n = r.hasOwnProperty,
217
- o = Object.defineProperty || function (t, e, r) {
218
- t[e] = r.value;
219
- },
220
- i = "function" == typeof Symbol ? Symbol : {},
221
- a = i.iterator || "@@iterator",
222
- c = i.asyncIterator || "@@asyncIterator",
223
- u = i.toStringTag || "@@toStringTag";
224
- function define(t, e, r) {
225
- return Object.defineProperty(t, e, {
226
- value: r,
227
- enumerable: true,
228
- configurable: true,
229
- writable: true
230
- }), t[e];
231
- }
232
- try {
233
- define({}, "");
234
- } catch (t) {
235
- define = function (t, e, r) {
236
- return t[e] = r;
237
- };
238
- }
239
- function wrap(t, e, r, n) {
240
- var i = e && e.prototype instanceof Generator ? e : Generator,
241
- a = Object.create(i.prototype),
242
- c = new Context(n || []);
243
- return o(a, "_invoke", {
244
- value: makeInvokeMethod(t, r, c)
245
- }), a;
246
- }
247
- function tryCatch(t, e, r) {
248
- try {
249
- return {
250
- type: "normal",
251
- arg: t.call(e, r)
252
- };
253
- } catch (t) {
254
- return {
255
- type: "throw",
256
- arg: t
257
- };
258
- }
259
- }
260
- e.wrap = wrap;
261
- var h = "suspendedStart",
262
- l = "suspendedYield",
263
- f = "executing",
264
- s = "completed",
265
- y = {};
266
- function Generator() {}
267
- function GeneratorFunction() {}
268
- function GeneratorFunctionPrototype() {}
269
- var p = {};
270
- define(p, a, function () {
271
- return this;
272
- });
273
- var d = Object.getPrototypeOf,
274
- v = d && d(d(values([])));
275
- v && v !== r && n.call(v, a) && (p = v);
276
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
277
- function defineIteratorMethods(t) {
278
- ["next", "throw", "return"].forEach(function (e) {
279
- define(t, e, function (t) {
280
- return this._invoke(e, t);
281
- });
282
- });
283
- }
284
- function AsyncIterator(t, e) {
285
- function invoke(r, o, i, a) {
286
- var c = tryCatch(t[r], t, o);
287
- if ("throw" !== c.type) {
288
- var u = c.arg,
289
- h = u.value;
290
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
291
- invoke("next", t, i, a);
292
- }, function (t) {
293
- invoke("throw", t, i, a);
294
- }) : e.resolve(h).then(function (t) {
295
- u.value = t, i(u);
296
- }, function (t) {
297
- return invoke("throw", t, i, a);
298
- });
299
- }
300
- a(c.arg);
301
- }
302
- var r;
303
- o(this, "_invoke", {
304
- value: function (t, n) {
305
- function callInvokeWithMethodAndArg() {
306
- return new e(function (e, r) {
307
- invoke(t, n, e, r);
308
- });
309
- }
310
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
311
- }
312
- });
313
- }
314
- function makeInvokeMethod(e, r, n) {
315
- var o = h;
316
- return function (i, a) {
317
- if (o === f) throw Error("Generator is already running");
318
- if (o === s) {
319
- if ("throw" === i) throw a;
320
- return {
321
- value: t,
322
- done: true
323
- };
324
- }
325
- for (n.method = i, n.arg = a;;) {
326
- var c = n.delegate;
327
- if (c) {
328
- var u = maybeInvokeDelegate(c, n);
329
- if (u) {
330
- if (u === y) continue;
331
- return u;
332
- }
333
- }
334
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
335
- if (o === h) throw o = s, n.arg;
336
- n.dispatchException(n.arg);
337
- } else "return" === n.method && n.abrupt("return", n.arg);
338
- o = f;
339
- var p = tryCatch(e, r, n);
340
- if ("normal" === p.type) {
341
- if (o = n.done ? s : l, p.arg === y) continue;
342
- return {
343
- value: p.arg,
344
- done: n.done
345
- };
346
- }
347
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
348
- }
349
- };
350
- }
351
- function maybeInvokeDelegate(e, r) {
352
- var n = r.method,
353
- o = e.iterator[n];
354
- if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
355
- var i = tryCatch(o, e.iterator, r.arg);
356
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
357
- var a = i.arg;
358
- return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
359
- }
360
- function pushTryEntry(t) {
361
- var e = {
362
- tryLoc: t[0]
363
- };
364
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
365
- }
366
- function resetTryEntry(t) {
367
- var e = t.completion || {};
368
- e.type = "normal", delete e.arg, t.completion = e;
369
- }
370
- function Context(t) {
371
- this.tryEntries = [{
372
- tryLoc: "root"
373
- }], t.forEach(pushTryEntry, this), this.reset(true);
374
- }
375
- function values(e) {
376
- if (e || "" === e) {
377
- var r = e[a];
378
- if (r) return r.call(e);
379
- if ("function" == typeof e.next) return e;
380
- if (!isNaN(e.length)) {
381
- var o = -1,
382
- i = function next() {
383
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = false, next;
384
- return next.value = t, next.done = true, next;
385
- };
386
- return i.next = i;
387
- }
388
- }
389
- throw new TypeError(typeof e + " is not iterable");
390
- }
391
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
392
- value: GeneratorFunctionPrototype,
393
- configurable: true
394
- }), o(GeneratorFunctionPrototype, "constructor", {
395
- value: GeneratorFunction,
396
- configurable: true
397
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
398
- var e = "function" == typeof t && t.constructor;
399
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
400
- }, e.mark = function (t) {
401
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
402
- }, e.awrap = function (t) {
403
- return {
404
- __await: t
405
- };
406
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
407
- return this;
408
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
409
- undefined === i && (i = Promise);
410
- var a = new AsyncIterator(wrap(t, r, n, o), i);
411
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
412
- return t.done ? t.value : a.next();
413
- });
414
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
415
- return this;
416
- }), define(g, "toString", function () {
417
- return "[object Generator]";
418
- }), e.keys = function (t) {
419
- var e = Object(t),
420
- r = [];
421
- for (var n in e) r.push(n);
422
- return r.reverse(), function next() {
423
- for (; r.length;) {
424
- var t = r.pop();
425
- if (t in e) return next.value = t, next.done = false, next;
426
- }
427
- return next.done = true, next;
428
- };
429
- }, e.values = values, Context.prototype = {
430
- constructor: Context,
431
- reset: function (e) {
432
- if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = false, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
433
- },
434
- stop: function () {
435
- this.done = true;
436
- var t = this.tryEntries[0].completion;
437
- if ("throw" === t.type) throw t.arg;
438
- return this.rval;
439
- },
440
- dispatchException: function (e) {
441
- if (this.done) throw e;
442
- var r = this;
443
- function handle(n, o) {
444
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
445
- }
446
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
447
- var i = this.tryEntries[o],
448
- a = i.completion;
449
- if ("root" === i.tryLoc) return handle("end");
450
- if (i.tryLoc <= this.prev) {
451
- var c = n.call(i, "catchLoc"),
452
- u = n.call(i, "finallyLoc");
453
- if (c && u) {
454
- if (this.prev < i.catchLoc) return handle(i.catchLoc, true);
455
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
456
- } else if (c) {
457
- if (this.prev < i.catchLoc) return handle(i.catchLoc, true);
458
- } else {
459
- if (!u) throw Error("try statement without catch or finally");
460
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
461
- }
462
- }
463
- }
464
- },
465
- abrupt: function (t, e) {
466
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
467
- var o = this.tryEntries[r];
468
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
469
- var i = o;
470
- break;
471
- }
472
- }
473
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
474
- var a = i ? i.completion : {};
475
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
476
- },
477
- complete: function (t, e) {
478
- if ("throw" === t.type) throw t.arg;
479
- return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
480
- },
481
- finish: function (t) {
482
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
483
- var r = this.tryEntries[e];
484
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
485
- }
486
- },
487
- catch: function (t) {
488
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
489
- var r = this.tryEntries[e];
490
- if (r.tryLoc === t) {
491
- var n = r.completion;
492
- if ("throw" === n.type) {
493
- var o = n.arg;
494
- resetTryEntry(r);
495
- }
496
- return o;
497
- }
498
- }
499
- throw Error("illegal catch attempt");
500
- },
501
- delegateYield: function (e, r, n) {
502
- return this.delegate = {
503
- iterator: values(e),
504
- resultName: r,
505
- nextLoc: n
506
- }, "next" === this.method && (this.arg = t), y;
507
- }
508
- }, e;
509
- }
510
- function _setPrototypeOf(t, e) {
511
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
512
- return t.__proto__ = e, t;
513
- }, _setPrototypeOf(t, e);
514
- }
515
- function _slicedToArray(r, e) {
516
- return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
517
- }
518
- function _toPrimitive(t, r) {
519
- if ("object" != typeof t || !t) return t;
520
- var e = t[Symbol.toPrimitive];
521
- if (undefined !== e) {
522
- var i = e.call(t, r || "default");
523
- if ("object" != typeof i) return i;
524
- throw new TypeError("@@toPrimitive must return a primitive value.");
525
- }
526
- return ("string" === r ? String : Number)(t);
527
- }
528
- function _toPropertyKey(t) {
529
- var i = _toPrimitive(t, "string");
530
- return "symbol" == typeof i ? i : i + "";
531
- }
532
- function _typeof(o) {
533
- "@babel/helpers - typeof";
534
-
535
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
536
- return typeof o;
537
- } : function (o) {
538
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
539
- }, _typeof(o);
540
- }
541
- function _unsupportedIterableToArray(r, a) {
542
- if (r) {
543
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
544
- var t = {}.toString.call(r).slice(8, -1);
545
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : undefined;
546
- }
547
- }
548
- function _wrapNativeSuper(t) {
549
- var r = "function" == typeof Map ? new Map() : undefined;
550
- return _wrapNativeSuper = function (t) {
551
- if (null === t || !_isNativeFunction(t)) return t;
552
- if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
553
- if (undefined !== r) {
554
- if (r.has(t)) return r.get(t);
555
- r.set(t, Wrapper);
556
- }
557
- function Wrapper() {
558
- return _construct(t, arguments, _getPrototypeOf(this).constructor);
559
- }
560
- return Wrapper.prototype = Object.create(t.prototype, {
561
- constructor: {
562
- value: Wrapper,
563
- enumerable: false,
564
- writable: true,
565
- configurable: true
566
- }
567
- }), _setPrototypeOf(Wrapper, t);
568
- }, _wrapNativeSuper(t);
569
- }
570
-
571
- var RumiousRenderContext = /*#__PURE__*/function () {
572
- function RumiousRenderContext(target) {
573
- _classCallCheck(this, RumiousRenderContext);
574
- this.target = target;
575
- }
576
- return _createClass(RumiousRenderContext, [{
577
- key: "find",
578
- value: function find(name) {
579
- return this.target[name];
580
- }
581
- }, {
582
- key: "get",
583
- value: function get(name) {
584
- return this.target[name];
585
- }
586
- }]);
587
- }();
588
-
589
- var RumiousComponent = /*#__PURE__*/function () {
590
- function RumiousComponent() {
591
- _classCallCheck(this, RumiousComponent);
592
- this.element = null;
593
- this.props = {};
594
- this.renderContext = new RumiousRenderContext(this);
595
- this.renderer = null;
596
- this.wrapped = null;
597
- }
598
- return _createClass(RumiousComponent, [{
599
- key: "prepare",
600
- value: function prepare(element, props) {
601
- var wrapped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
602
- var renderer = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
603
- this.element = element;
604
- this.props = props;
605
- this.renderer = renderer;
606
- this.wrapped = wrapped;
607
- }
608
- }, {
609
- key: "template",
610
- value: function template() {
611
- return {};
612
- }
613
- }, {
614
- key: "requestRender",
615
- value: function requestRender() {
616
- var template = this.template();
617
- var fragment = this.renderer(template, document.createDocumentFragment(), this.renderContext);
618
- this.element.appendChild(fragment);
619
- this.onRender();
620
- }
621
- }, {
622
- key: "requestCleanUp",
623
- value: function () {
624
- var _requestCleanUp = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
625
- var cloned;
626
- return _regeneratorRuntime().wrap(function _callee$(_context) {
627
- while (1) switch (_context.prev = _context.next) {
628
- case 0:
629
- if (this.element) {
630
- cloned = this.element.cloneNode(true);
631
- this.element.replaceWith(cloned);
632
- this.element = cloned;
633
- while (this.element.firstChild) {
634
- this.element.removeChild(this.element.firstChild);
635
- }
636
- }
637
- case 1:
638
- case "end":
639
- return _context.stop();
640
- }
641
- }, _callee, this);
642
- }));
643
- function requestCleanUp() {
644
- return _requestCleanUp.apply(this, arguments);
645
- }
646
- return requestCleanUp;
647
- }()
648
- }, {
649
- key: "onInit",
650
- value: function onInit() {}
651
- }, {
652
- key: "onCreate",
653
- value: function onCreate() {}
654
- }, {
655
- key: "onRender",
656
- value: function onRender() {}
657
- }, {
658
- key: "onUpdate",
659
- value: function onUpdate() {}
660
- }, {
661
- key: "onDestroy",
662
- value: function onDestroy() {}
663
- }]);
664
- }();
665
- function isComponent(component) {
666
- return Object.getPrototypeOf(component) === RumiousComponent;
667
- }
668
-
669
- var RumiousElement = /*#__PURE__*/_createClass(function RumiousElement(type, props) {
670
- var children = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
671
- _classCallCheck(this, RumiousElement);
672
- this.type = type;
673
- this.props = props;
674
- this.children = children;
675
- });
676
- var RumiousElementList = /*#__PURE__*/function () {
677
- function RumiousElementList(list) {
678
- _classCallCheck(this, RumiousElementList);
679
- this.type = "ELEMENT_LIST";
680
- this.children = list;
681
- }
682
- return _createClass(RumiousElementList, [{
683
- key: "forEach",
684
- value: function forEach(callback) {
685
- this.children.forEach(callback);
686
- }
687
- }]);
688
- }();
689
-
690
- function isCamelCase(str) {
691
- var camelCaseRegex = /^[a-zA-Z]+([A-Z][a-z]*)*$/;
692
- return camelCaseRegex.test(str);
693
- }
694
- function isFunction(object) {
695
- return typeof object === 'function';
696
- }
697
-
698
- var RumiousDirective = /*#__PURE__*/function () {
699
- function RumiousDirective(type, name, value) {
700
- _classCallCheck(this, RumiousDirective);
701
- this.type = type;
702
- this.name = name;
703
- this.value = value;
704
- }
705
- return _createClass(RumiousDirective, [{
706
- key: "init",
707
- value: function init() {
708
- console.warn("Directive haven't handler !");
709
- }
710
- }]);
711
- }();
712
- var RumiousEventBindingDirective = /*#__PURE__*/function (_RumiousDirective) {
713
- function RumiousEventBindingDirective() {
714
- _classCallCheck(this, RumiousEventBindingDirective);
715
- return _callSuper(this, RumiousEventBindingDirective, arguments);
716
- }
717
- _inherits(RumiousEventBindingDirective, _RumiousDirective);
718
- return _createClass(RumiousEventBindingDirective, [{
719
- key: "init",
720
- value: function () {
721
- var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(dom, renderContext) {
722
- var _this = this;
723
- var fn, getHandler;
724
- return _regeneratorRuntime().wrap(function _callee$(_context) {
725
- while (1) switch (_context.prev = _context.next) {
726
- case 0:
727
- fn = null;
728
- getHandler = function getHandler(value) {
729
- if (!renderContext.find(value)) {
730
- console.warn("Missing event handler for event: ".concat(_this.name));
731
- return null;
732
- }
733
- var handler = renderContext.get(value);
734
- if (!isFunction(handler)) {
735
- throw "".concat(value, " is not a function!");
736
- }
737
- return handler.bind(renderContext.target);
738
- };
739
- if (!(this.value.type === "string")) {
740
- _context.next = 6;
741
- break;
742
- }
743
- fn = getHandler(this.value.value);
744
- _context.next = 13;
745
- break;
746
- case 6:
747
- if (!(this.value.type === "expression")) {
748
- _context.next = 12;
749
- break;
750
- }
751
- fn = this.value.value;
752
- if (isFunction(fn)) {
753
- _context.next = 10;
754
- break;
755
- }
756
- throw "Event handler requires a function!";
757
- case 10:
758
- _context.next = 13;
759
- break;
760
- case 12:
761
- if (this.value.type === "dynamic_value") {
762
- fn = getHandler(this.value.value.objectName);
763
- }
764
- case 13:
765
- if (fn) {
766
- dom.addEventListener(this.name, fn);
767
- }
768
- case 14:
769
- case "end":
770
- return _context.stop();
771
- }
772
- }, _callee, this);
773
- }));
774
- function init(_x, _x2) {
775
- return _init.apply(this, arguments);
776
- }
777
- return init;
778
- }()
779
- }]);
780
- }(RumiousDirective);
781
- var RumiousPropsBindingDirective = /*#__PURE__*/function (_RumiousDirective2) {
782
- function RumiousPropsBindingDirective() {
783
- _classCallCheck(this, RumiousPropsBindingDirective);
784
- return _callSuper(this, RumiousPropsBindingDirective, arguments);
785
- }
786
- _inherits(RumiousPropsBindingDirective, _RumiousDirective2);
787
- return _createClass(RumiousPropsBindingDirective, [{
788
- key: "init",
789
- value: function () {
790
- var _init2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(dom, renderContext) {
791
- var _this2 = this;
792
- var _this$value$evaluator, _this$value, currentStateValue, currentState;
793
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
794
- while (1) switch (_context2.prev = _context2.next) {
795
- case 0:
796
- if (!(this.value.type === "expression")) {
797
- _context2.next = 4;
798
- break;
799
- }
800
- _context2.next = 13;
801
- break;
802
- case 4:
803
- if (!(this.value.type === "dynamic_value")) {
804
- _context2.next = 13;
805
- break;
806
- }
807
- currentStateValue = (_this$value$evaluator = (_this$value = this.value).evaluator) === null || _this$value$evaluator === undefined ? undefined : _this$value$evaluator.call(_this$value, renderContext.target);
808
- currentState = renderContext.find(this.value.value.objectName);
809
- if (currentState) {
810
- _context2.next = 11;
811
- break;
812
- }
813
- throw "Invalid props value: Directive bind: require a RumiousState Object !";
814
- case 11:
815
- currentState.reactor.addBinding(function () {
816
- var _this2$value$evaluato, _this2$value;
817
- var currentStateValue = (_this2$value$evaluato = (_this2$value = _this2.value).evaluator) === null || _this2$value$evaluato === undefined ? undefined : _this2$value$evaluato.call(_this2$value, renderContext.target);
818
- _this2.bindAttr(dom, currentStateValue);
819
- });
820
- case 12:
821
- this.bindAttr(dom, currentStateValue);
822
- case 13:
823
- case "end":
824
- return _context2.stop();
825
- }
826
- }, _callee2, this);
827
- }));
828
- function init(_x3, _x4) {
829
- return _init2.apply(this, arguments);
830
- }
831
- return init;
832
- }()
833
- }, {
834
- key: "normalizeValue",
835
- value: function normalizeValue(value) {
836
- if (_typeof(value) === "object") {
837
- var _value$toString, _value$toString2;
838
- return (_value$toString = (_value$toString2 = value.toString) === null || _value$toString2 === undefined ? undefined : _value$toString2.call(value)) !== null && _value$toString !== undefined ? _value$toString : "";
839
- }
840
- return value;
841
- }
842
- }, {
843
- key: "bindAttr",
844
- value: function () {
845
- var _bindAttr = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(dom, value) {
846
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
847
- while (1) switch (_context3.prev = _context3.next) {
848
- case 0:
849
- _context3.t0 = this.name;
850
- _context3.next = _context3.t0 === "html" ? 3 : 5;
851
- break;
852
- case 3:
853
- dom.innerHTML = this.normalizeValue(value);
854
- return _context3.abrupt("break", 5);
855
- case 5:
856
- case "end":
857
- return _context3.stop();
858
- }
859
- }, _callee3, this);
860
- }));
861
- function bindAttr(_x5, _x6) {
862
- return _bindAttr.apply(this, arguments);
863
- }
864
- return bindAttr;
865
- }()
866
- }]);
867
- }(RumiousDirective);
868
- var directives = {
869
- on: function on(event, value) {
870
- return new RumiousEventBindingDirective("on", event, value);
871
- },
872
- bind: function bind(attr, value) {
873
- return new RumiousPropsBindingDirective("bind", attr, value);
874
- }
875
- };
876
- function registerDirective(type, name, value) {
877
- var _directives$type;
878
- return (_directives$type = directives[type]) === null || _directives$type === undefined ? undefined : _directives$type.call(directives, name, value);
879
- }
880
-
881
- function createDirective(type, name, value) {
882
- return registerDirective(type, name, value);
883
- }
884
- function createElement(type, props) {
885
- for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
886
- children[_key - 2] = arguments[_key];
887
- }
888
- if (isComponent(type)) {
889
- return createComponent(type, props, children);
890
- }
891
- if (type === createFragment) {
892
- return createFragment.apply(undefined, children);
893
- }
894
- return new RumiousElement(type, props || {}, normalizeChildren(children));
895
- }
896
- function createTextElement(text) {
897
- return new RumiousElement("TEXT_ELEMENT", {
898
- nodeValue: text
899
- }, []);
900
- }
901
- function createComponent(type, props, children) {
902
- return new RumiousElement("COMPONENT", _objectSpread2({
903
- component: type
904
- }, props), new RumiousElementList(normalizeChildren(children)));
905
- }
906
- function createFragment() {
907
- for (var _len2 = arguments.length, children = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
908
- children[_key2] = arguments[_key2];
909
- }
910
- return new RumiousElement("FRAGMENT", {}, normalizeChildren(children));
911
- }
912
- function normalizeChildren(children) {
913
- return children.map(function (child) {
914
- return _typeof(child) === "object" ? child : createTextElement(child);
915
- });
916
- }
917
- window.RUMIOUS_JSX_SUPPORT = {
918
- createElement: createElement,
919
- createFragment: createFragment,
920
- createDirective: createDirective
921
- };
922
-
923
- var RumiousComponentElement = /*#__PURE__*/function (_HTMLElement) {
924
- function RumiousComponentElement() {
925
- var _this;
926
- _classCallCheck(this, RumiousComponentElement);
927
- _this = _callSuper(this, RumiousComponentElement);
928
- _this.instance = null;
929
- return _this;
930
- }
931
- _inherits(RumiousComponentElement, _HTMLElement);
932
- return _createClass(RumiousComponentElement, [{
933
- key: "init",
934
- value: function init(componentConstructor, props) {
935
- var wrapped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
936
- var renderer = arguments.length > 3 ? arguments[3] : undefined;
937
- this.instance = new componentConstructor();
938
- this.instance.prepare(this, props, wrapped, renderer);
939
- this.instance.onInit();
940
- }
941
- }, {
942
- key: "connectedCallback",
943
- value: function connectedCallback() {
944
- this.instance.onCreate();
945
- this.instance.requestRender();
946
- }
947
- }, {
948
- key: "disconnectCallback",
949
- value: function disconnectCallback() {
950
- this.instance.onDestroy();
951
- this.instance.requestCleanUp();
952
- }
953
- }]);
954
- }(/*#__PURE__*/_wrapNativeSuper(HTMLElement));
955
- function createComponentElement() {
956
- return document.createElement("a-component");
957
- }
958
- window.customElements.define("a-component", RumiousComponentElement);
959
-
960
- function renderComponent(componentConstructor, props, wrapped, renderer) {
961
- var componentElement = createComponentElement();
962
- componentElement.init(componentConstructor, props, wrapped, renderer);
963
- return componentElement;
964
- }
965
-
966
- function handleComponentElement(element, container, render) {
967
- var dom = renderComponent(element.props.component, element.props, element.children, render);
968
- container.appendChild(dom);
969
- return container;
970
- }
971
- function handleFragmentOrElementList(element, container, renderContext) {
972
- element.children.forEach(function (child) {
973
- return render(child, container, renderContext);
974
- });
975
- return container;
976
- }
977
- function handleTextElement(element) {
978
- return document.createTextNode(element.props.nodeValue);
979
- }
980
- function handleRegularElement(element, renderContext) {
981
- var dom = document.createElement(element.type);
982
- Object.entries(element.props || {}).forEach(function (_ref) {
983
- var _ref2 = _slicedToArray(_ref, 2),
984
- name = _ref2[0],
985
- propValue = _ref2[1];
986
- if (name.startsWith("on") && isCamelCase(name)) {
987
- dom.addEventListener(name.substring(2).toLowerCase(), propValue);
988
- } else {
989
- setElementProps(dom, name, propValue, renderContext);
990
- }
991
- });
992
- return dom;
993
- }
994
- function handleDirective(dom, directive, renderContext) {
995
- directive.init(dom, renderContext);
996
- }
997
- function setElementProps(dom, name, propValue, renderContext) {
998
- if (dom.nodeType === Node.TEXT_NODE) {
999
- dom.nodeValue = propValue;
1000
- } else if (propValue instanceof RumiousDirective) {
1001
- handleDirective(dom, propValue, renderContext);
1002
- } else {
1003
- dom.setAttribute(name, propValue);
1004
- }
1005
- }
1006
- function render(element, container) {
1007
- var renderContext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1008
- if (!element) return container;
1009
- var dom;
1010
- if (element.type === "COMPONENT") {
1011
- return handleComponentElement(element, container, render);
1012
- }
1013
- if (element.type === "FRAGMENT" || element.type === "ELEMENT_LIST") {
1014
- return handleFragmentOrElementList(element, container, renderContext);
1015
- }
1016
- if (element.type === "TEXT_ELEMENT") {
1017
- dom = handleTextElement(element);
1018
- } else {
1019
- dom = handleRegularElement(element, renderContext);
1020
- }
1021
- element.children.forEach(function (child) {
1022
- return render(child, dom, renderContext);
1023
- });
1024
- container.appendChild(dom);
1025
- return container;
1026
- }
1027
-
1028
- var RumiousApp = /*#__PURE__*/function () {
1029
- function RumiousApp() {
1030
- var root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.createElement("span");
1031
- var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1032
- _classCallCheck(this, RumiousApp);
1033
- this.root = root;
1034
- this.configs = configs;
1035
- this.renderContext = new RumiousRenderContext(this);
1036
- }
1037
- return _createClass(RumiousApp, [{
1038
- key: "render",
1039
- value: function render$1(element) {
1040
- render(element, this.root, this.renderContext);
1041
- }
1042
- }]);
1043
- }();
1044
-
1045
- var RumiousReactor = /*#__PURE__*/function () {
1046
- function RumiousReactor() {
1047
- var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1048
- var bindings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1049
- _classCallCheck(this, RumiousReactor);
1050
- this.target = target;
1051
- this.bindings = bindings;
1052
- }
1053
- return _createClass(RumiousReactor, [{
1054
- key: "react",
1055
- value: function react() {
1056
- this.bindings.forEach(function (callback) {
1057
- return callback();
1058
- });
1059
- }
1060
- }, {
1061
- key: "addBinding",
1062
- value: function addBinding(fn) {
1063
- this.bindings.push(fn);
1064
- }
1065
- }]);
1066
- }();
1067
-
1068
- var RumiousReducer = /*#__PURE__*/function () {
1069
- function RumiousReducer(state) {
1070
- var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
1071
- var fn = arguments.length > 2 ? arguments[2] : undefined;
1072
- _classCallCheck(this, RumiousReducer);
1073
- this.state = state;
1074
- this.path = path;
1075
- this.fn = fn;
1076
- }
1077
- return _createClass(RumiousReducer, [{
1078
- key: "trigger",
1079
- value: function trigger() {
1080
- var value = this.fn.apply(this, arguments);
1081
- this.state.set(this.path, value);
1082
- }
1083
- }]);
1084
- }();
1085
-
1086
- var Operation = {
1087
- Remove: 'remove',
1088
- Replace: 'replace',
1089
- Add: 'add'
1090
- };
1091
-
1092
- // Don't use `Symbol()` just for 3rd party access the draft
1093
- var PROXY_DRAFT = Symbol["for"]('__MUTATIVE_PROXY_DRAFT__');
1094
- var RAW_RETURN_SYMBOL = Symbol('__MUTATIVE_RAW_RETURN_SYMBOL__');
1095
- var iteratorSymbol = Symbol.iterator;
1096
- var dataTypes = {
1097
- mutable: 'mutable',
1098
- immutable: 'immutable'
1099
- };
1100
- var internal = {};
1101
- function has(target, key) {
1102
- return target instanceof Map ? target.has(key) : Object.prototype.hasOwnProperty.call(target, key);
1103
- }
1104
- function getDescriptor(target, key) {
1105
- if (key in target) {
1106
- var prototype = Reflect.getPrototypeOf(target);
1107
- while (prototype) {
1108
- var descriptor = Reflect.getOwnPropertyDescriptor(prototype, key);
1109
- if (descriptor) return descriptor;
1110
- prototype = Reflect.getPrototypeOf(prototype);
1111
- }
1112
- }
1113
- return;
1114
- }
1115
- function isBaseSetInstance(obj) {
1116
- return Object.getPrototypeOf(obj) === Set.prototype;
1117
- }
1118
- function isBaseMapInstance(obj) {
1119
- return Object.getPrototypeOf(obj) === Map.prototype;
1120
- }
1121
- function latest(proxyDraft) {
1122
- var _a;
1123
- return (_a = proxyDraft.copy) !== null && _a !== undefined ? _a : proxyDraft.original;
1124
- }
1125
- /**
1126
- * Check if the value is a draft
1127
- */
1128
- function isDraft(target) {
1129
- return !!getProxyDraft(target);
1130
- }
1131
- function getProxyDraft(value) {
1132
- if (_typeof(value) !== 'object') return null;
1133
- return value === null || value === undefined ? undefined : value[PROXY_DRAFT];
1134
- }
1135
- function getValue(value) {
1136
- var _a;
1137
- var proxyDraft = getProxyDraft(value);
1138
- return proxyDraft ? (_a = proxyDraft.copy) !== null && _a !== undefined ? _a : proxyDraft.original : value;
1139
- }
1140
- /**
1141
- * Check if a value is draftable
1142
- */
1143
- function isDraftable(value, options) {
1144
- if (!value || _typeof(value) !== 'object') return false;
1145
- var markResult;
1146
- return Object.getPrototypeOf(value) === Object.prototype || Array.isArray(value) || value instanceof Map || value instanceof Set || !!(options === null || options === undefined ? undefined : options.mark) && ((markResult = options.mark(value, dataTypes)) === dataTypes.immutable || typeof markResult === 'function');
1147
- }
1148
- function getPath(target) {
1149
- var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1150
- if (Object.hasOwnProperty.call(target, 'key')) {
1151
- // check if the parent is a draft and the original value is not equal to the current value
1152
- var parentCopy = target.parent.copy;
1153
- var proxyDraft = getProxyDraft(get(parentCopy, target.key));
1154
- if (proxyDraft !== null && (proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.original) !== target.original) {
1155
- return null;
1156
- }
1157
- var isSet = target.parent.type === 3 /* DraftType.Set */;
1158
- var key = isSet ? Array.from(target.parent.setMap.keys()).indexOf(target.key) : target.key;
1159
- // check if the key is still in the next state parent
1160
- if (!(isSet && parentCopy.size > key || has(parentCopy, key))) return null;
1161
- path.push(key);
1162
- }
1163
- if (target.parent) {
1164
- return getPath(target.parent, path);
1165
- }
1166
- // `target` is root draft.
1167
- path.reverse();
1168
- try {
1169
- // check if the path is valid
1170
- resolvePath(target.copy, path);
1171
- } catch (e) {
1172
- return null;
1173
- }
1174
- return path;
1175
- }
1176
- function getType(target) {
1177
- if (Array.isArray(target)) return 1 /* DraftType.Array */;
1178
- if (target instanceof Map) return 2 /* DraftType.Map */;
1179
- if (target instanceof Set) return 3 /* DraftType.Set */;
1180
- return 0 /* DraftType.Object */;
1181
- }
1182
- function get(target, key) {
1183
- return getType(target) === 2 /* DraftType.Map */ ? target.get(key) : target[key];
1184
- }
1185
- function set(target, key, value) {
1186
- var type = getType(target);
1187
- if (type === 2 /* DraftType.Map */) {
1188
- target.set(key, value);
1189
- } else {
1190
- target[key] = value;
1191
- }
1192
- }
1193
- function peek(target, key) {
1194
- var state = getProxyDraft(target);
1195
- var source = state ? latest(state) : target;
1196
- return source[key];
1197
- }
1198
- function isEqual(x, y) {
1199
- if (x === y) {
1200
- return x !== 0 || 1 / x === 1 / y;
1201
- } else {
1202
- return x !== x && y !== y;
1203
- }
1204
- }
1205
- function revokeProxy(proxyDraft) {
1206
- if (!proxyDraft) return;
1207
- while (proxyDraft.finalities.revoke.length > 0) {
1208
- var revoke = proxyDraft.finalities.revoke.pop();
1209
- revoke();
1210
- }
1211
- }
1212
- // handle JSON Pointer path with spec https://www.rfc-editor.org/rfc/rfc6901
1213
- function escapePath(path, pathAsArray) {
1214
- return pathAsArray ? path : [''].concat(path).map(function (_item) {
1215
- var item = "".concat(_item);
1216
- if (item.indexOf('/') === -1 && item.indexOf('~') === -1) return item;
1217
- return item.replace(/~/g, '~0').replace(/\//g, '~1');
1218
- }).join('/');
1219
- }
1220
- function resolvePath(base, path) {
1221
- for (var index = 0; index < path.length - 1; index += 1) {
1222
- var key = path[index];
1223
- // use `index` in Set draft
1224
- base = get(getType(base) === 3 /* DraftType.Set */ ? Array.from(base) : base, key);
1225
- if (_typeof(base) !== 'object') {
1226
- throw new Error("Cannot resolve patch at '".concat(path.join('/'), "'."));
1227
- }
1228
- }
1229
- return base;
1230
- }
1231
- function strictCopy(target) {
1232
- var copy = Object.create(Object.getPrototypeOf(target));
1233
- Reflect.ownKeys(target).forEach(function (key) {
1234
- var desc = Reflect.getOwnPropertyDescriptor(target, key);
1235
- if (desc.enumerable && desc.configurable && desc.writable) {
1236
- copy[key] = target[key];
1237
- return;
1238
- }
1239
- // for freeze
1240
- if (!desc.writable) {
1241
- desc.writable = true;
1242
- desc.configurable = true;
1243
- }
1244
- if (desc.get || desc.set) desc = {
1245
- configurable: true,
1246
- writable: true,
1247
- enumerable: desc.enumerable,
1248
- value: target[key]
1249
- };
1250
- Reflect.defineProperty(copy, key, desc);
1251
- });
1252
- return copy;
1253
- }
1254
- var propIsEnum = Object.prototype.propertyIsEnumerable;
1255
- function shallowCopy(original, options) {
1256
- var markResult;
1257
- if (Array.isArray(original)) {
1258
- return Array.prototype.concat.call(original);
1259
- } else if (original instanceof Set) {
1260
- if (!isBaseSetInstance(original)) {
1261
- var SubClass = Object.getPrototypeOf(original).constructor;
1262
- return new SubClass(original.values());
1263
- }
1264
- return Set.prototype.difference ? Set.prototype.difference.call(original, new Set()) : new Set(original.values());
1265
- } else if (original instanceof Map) {
1266
- if (!isBaseMapInstance(original)) {
1267
- var _SubClass = Object.getPrototypeOf(original).constructor;
1268
- return new _SubClass(original);
1269
- }
1270
- return new Map(original);
1271
- } else if ((options === null || options === undefined ? undefined : options.mark) && (markResult = options.mark(original, dataTypes), markResult !== undefined) && markResult !== dataTypes.mutable) {
1272
- if (markResult === dataTypes.immutable) {
1273
- return strictCopy(original);
1274
- } else if (typeof markResult === 'function') {
1275
- if (options.enablePatches || options.enableAutoFreeze) {
1276
- throw new Error("You can't use mark and patches or auto freeze together.");
1277
- }
1278
- return markResult();
1279
- }
1280
- throw new Error("Unsupported mark result: ".concat(markResult));
1281
- } else if (_typeof(original) === 'object' && Object.getPrototypeOf(original) === Object.prototype) {
1282
- // For best performance with shallow copies,
1283
- // don't use `Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));` by default.
1284
- var copy = {};
1285
- Object.keys(original).forEach(function (key) {
1286
- copy[key] = original[key];
1287
- });
1288
- Object.getOwnPropertySymbols(original).forEach(function (key) {
1289
- if (propIsEnum.call(original, key)) {
1290
- copy[key] = original[key];
1291
- }
1292
- });
1293
- return copy;
1294
- } else {
1295
- throw new Error("Please check mark() to ensure that it is a stable marker draftable function.");
1296
- }
1297
- }
1298
- function ensureShallowCopy(target) {
1299
- if (target.copy) return;
1300
- target.copy = shallowCopy(target.original, target.options);
1301
- }
1302
- function deepClone(target) {
1303
- if (!isDraftable(target)) return getValue(target);
1304
- if (Array.isArray(target)) return target.map(deepClone);
1305
- if (target instanceof Map) {
1306
- var iterable = Array.from(target.entries()).map(function (_ref) {
1307
- var _ref2 = _slicedToArray(_ref, 2),
1308
- k = _ref2[0],
1309
- v = _ref2[1];
1310
- return [k, deepClone(v)];
1311
- });
1312
- if (!isBaseMapInstance(target)) {
1313
- var SubClass = Object.getPrototypeOf(target).constructor;
1314
- return new SubClass(iterable);
1315
- }
1316
- return new Map(iterable);
1317
- }
1318
- if (target instanceof Set) {
1319
- var _iterable = Array.from(target).map(deepClone);
1320
- if (!isBaseSetInstance(target)) {
1321
- var _SubClass2 = Object.getPrototypeOf(target).constructor;
1322
- return new _SubClass2(_iterable);
1323
- }
1324
- return new Set(_iterable);
1325
- }
1326
- var copy = Object.create(Object.getPrototypeOf(target));
1327
- for (var key in target) copy[key] = deepClone(target[key]);
1328
- return copy;
1329
- }
1330
- function cloneIfNeeded(target) {
1331
- return isDraft(target) ? deepClone(target) : target;
1332
- }
1333
- function markChanged(proxyDraft) {
1334
- var _a;
1335
- proxyDraft.assignedMap = (_a = proxyDraft.assignedMap) !== null && _a !== undefined ? _a : new Map();
1336
- if (!proxyDraft.operated) {
1337
- proxyDraft.operated = true;
1338
- if (proxyDraft.parent) {
1339
- markChanged(proxyDraft.parent);
1340
- }
1341
- }
1342
- }
1343
- function throwFrozenError() {
1344
- throw new Error('Cannot modify frozen object');
1345
- }
1346
- function deepFreeze(target, subKey, updatedValues, stack, keys) {
1347
- {
1348
- updatedValues = updatedValues !== null && updatedValues !== undefined ? updatedValues : new WeakMap();
1349
- stack = stack !== null && stack !== undefined ? stack : [];
1350
- keys = keys !== null && keys !== undefined ? keys : [];
1351
- var value = updatedValues.has(target) ? updatedValues.get(target) : target;
1352
- if (stack.length > 0) {
1353
- var index = stack.indexOf(value);
1354
- if (value && _typeof(value) === 'object' && index !== -1) {
1355
- if (stack[0] === value) {
1356
- throw new Error("Forbids circular reference");
1357
- }
1358
- throw new Error("Forbids circular reference: ~/".concat(keys.slice(0, index).map(function (key, index) {
1359
- if (_typeof(key) === 'symbol') return "[".concat(key.toString(), "]");
1360
- var parent = stack[index];
1361
- if (_typeof(key) === 'object' && (parent instanceof Map || parent instanceof Set)) return Array.from(parent.keys()).indexOf(key);
1362
- return key;
1363
- }).join('/')));
1364
- }
1365
- stack.push(value);
1366
- keys.push(subKey);
1367
- } else {
1368
- stack.push(value);
1369
- }
1370
- }
1371
- if (Object.isFrozen(target) || isDraft(target)) {
1372
- {
1373
- stack.pop();
1374
- keys.pop();
1375
- }
1376
- return;
1377
- }
1378
- var type = getType(target);
1379
- switch (type) {
1380
- case 2 /* DraftType.Map */:
1381
- var _iterator = _createForOfIteratorHelper(target),
1382
- _step;
1383
- try {
1384
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
1385
- var _step$value = _slicedToArray(_step.value, 2),
1386
- key = _step$value[0],
1387
- _value2 = _step$value[1];
1388
- deepFreeze(key, key, updatedValues, stack, keys);
1389
- deepFreeze(_value2, key, updatedValues, stack, keys);
1390
- }
1391
- } catch (err) {
1392
- _iterator.e(err);
1393
- } finally {
1394
- _iterator.f();
1395
- }
1396
- target.set = target.clear = target["delete"] = throwFrozenError;
1397
- break;
1398
- case 3 /* DraftType.Set */:
1399
- var _iterator2 = _createForOfIteratorHelper(target),
1400
- _step2;
1401
- try {
1402
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1403
- var _value3 = _step2.value;
1404
- deepFreeze(_value3, _value3, updatedValues, stack, keys);
1405
- }
1406
- } catch (err) {
1407
- _iterator2.e(err);
1408
- } finally {
1409
- _iterator2.f();
1410
- }
1411
- target.add = target.clear = target["delete"] = throwFrozenError;
1412
- break;
1413
- case 1 /* DraftType.Array */:
1414
- Object.freeze(target);
1415
- var _index = 0;
1416
- var _iterator3 = _createForOfIteratorHelper(target),
1417
- _step3;
1418
- try {
1419
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1420
- var _value4 = _step3.value;
1421
- deepFreeze(_value4, _index, updatedValues, stack, keys);
1422
- _index += 1;
1423
- }
1424
- } catch (err) {
1425
- _iterator3.e(err);
1426
- } finally {
1427
- _iterator3.f();
1428
- }
1429
- break;
1430
- default:
1431
- Object.freeze(target);
1432
- // ignore non-enumerable or symbol properties
1433
- Object.keys(target).forEach(function (name) {
1434
- var value = target[name];
1435
- deepFreeze(value, name, updatedValues, stack, keys);
1436
- });
1437
- }
1438
- {
1439
- stack.pop();
1440
- keys.pop();
1441
- }
1442
- }
1443
- function forEach(target, iter) {
1444
- var type = getType(target);
1445
- if (type === 0 /* DraftType.Object */) {
1446
- Reflect.ownKeys(target).forEach(function (key) {
1447
- iter(key, target[key], target);
1448
- });
1449
- } else if (type === 1 /* DraftType.Array */) {
1450
- var index = 0;
1451
- var _iterator4 = _createForOfIteratorHelper(target),
1452
- _step4;
1453
- try {
1454
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1455
- var entry = _step4.value;
1456
- iter(index, entry, target);
1457
- index += 1;
1458
- }
1459
- } catch (err) {
1460
- _iterator4.e(err);
1461
- } finally {
1462
- _iterator4.f();
1463
- }
1464
- } else {
1465
- target.forEach(function (entry, index) {
1466
- return iter(index, entry, target);
1467
- });
1468
- }
1469
- }
1470
- function handleValue(target, handledSet, options) {
1471
- if (isDraft(target) || !isDraftable(target, options) || handledSet.has(target) || Object.isFrozen(target)) return;
1472
- var isSet = target instanceof Set;
1473
- var setMap = isSet ? new Map() : undefined;
1474
- handledSet.add(target);
1475
- forEach(target, function (key, value) {
1476
- var _a;
1477
- if (isDraft(value)) {
1478
- var proxyDraft = getProxyDraft(value);
1479
- ensureShallowCopy(proxyDraft);
1480
- // A draft where a child node has been changed, or assigned a value
1481
- var updatedValue = ((_a = proxyDraft.assignedMap) === null || _a === void 0 ? void 0 : _a.size) || proxyDraft.operated ? proxyDraft.copy : proxyDraft.original;
1482
- // final update value
1483
- set(isSet ? setMap : target, key, updatedValue);
1484
- } else {
1485
- handleValue(value, handledSet, options);
1486
- }
1487
- });
1488
- if (setMap) {
1489
- var _set = target;
1490
- var values = Array.from(_set);
1491
- _set.clear();
1492
- values.forEach(function (value) {
1493
- _set.add(setMap.has(value) ? setMap.get(value) : value);
1494
- });
1495
- }
1496
- }
1497
- function finalizeAssigned(proxyDraft, key) {
1498
- // handle the draftable assigned values, and the value is not a draft
1499
- var copy = proxyDraft.type === 3 /* DraftType.Set */ ? proxyDraft.setMap : proxyDraft.copy;
1500
- if (proxyDraft.finalities.revoke.length > 1 && proxyDraft.assignedMap.get(key) && copy) {
1501
- handleValue(get(copy, key), proxyDraft.finalities.handledSet, proxyDraft.options);
1502
- }
1503
- }
1504
- function finalizeSetValue(target) {
1505
- if (target.type === 3 /* DraftType.Set */ && target.copy) {
1506
- target.copy.clear();
1507
- target.setMap.forEach(function (value) {
1508
- target.copy.add(getValue(value));
1509
- });
1510
- }
1511
- }
1512
- function finalizePatches(target, generatePatches, patches, inversePatches) {
1513
- var shouldFinalize = target.operated && target.assignedMap && target.assignedMap.size > 0 && !target.finalized;
1514
- if (shouldFinalize) {
1515
- if (patches && inversePatches) {
1516
- var basePath = getPath(target);
1517
- if (basePath) {
1518
- generatePatches(target, basePath, patches, inversePatches);
1519
- }
1520
- }
1521
- target.finalized = true;
1522
- }
1523
- }
1524
- function markFinalization(target, key, value, generatePatches) {
1525
- var proxyDraft = getProxyDraft(value);
1526
- if (proxyDraft) {
1527
- // !case: assign the draft value
1528
- if (!proxyDraft.callbacks) {
1529
- proxyDraft.callbacks = [];
1530
- }
1531
- proxyDraft.callbacks.push(function (patches, inversePatches) {
1532
- var _a;
1533
- var copy = target.type === 3 /* DraftType.Set */ ? target.setMap : target.copy;
1534
- if (isEqual(get(copy, key), value)) {
1535
- var updatedValue = proxyDraft.original;
1536
- if (proxyDraft.copy) {
1537
- updatedValue = proxyDraft.copy;
1538
- }
1539
- finalizeSetValue(target);
1540
- finalizePatches(target, generatePatches, patches, inversePatches);
1541
- if (target.options.enableAutoFreeze) {
1542
- target.options.updatedValues = (_a = target.options.updatedValues) !== null && _a !== undefined ? _a : new WeakMap();
1543
- target.options.updatedValues.set(updatedValue, proxyDraft.original);
1544
- }
1545
- // final update value
1546
- set(copy, key, updatedValue);
1547
- }
1548
- });
1549
- if (target.options.enableAutoFreeze) {
1550
- // !case: assign the draft value in cross draft tree
1551
- if (proxyDraft.finalities !== target.finalities) {
1552
- target.options.enableAutoFreeze = false;
1553
- }
1554
- }
1555
- }
1556
- if (isDraftable(value, target.options)) {
1557
- // !case: assign the non-draft value
1558
- target.finalities.draft.push(function () {
1559
- var copy = target.type === 3 /* DraftType.Set */ ? target.setMap : target.copy;
1560
- if (isEqual(get(copy, key), value)) {
1561
- finalizeAssigned(target, key);
1562
- }
1563
- });
1564
- }
1565
- }
1566
- function generateArrayPatches(proxyState, basePath, patches, inversePatches, pathAsArray) {
1567
- var original = proxyState.original,
1568
- assignedMap = proxyState.assignedMap,
1569
- options = proxyState.options;
1570
- var copy = proxyState.copy;
1571
- if (copy.length < original.length) {
1572
- var _ref3 = [copy, original];
1573
- original = _ref3[0];
1574
- copy = _ref3[1];
1575
- var _ref4 = [inversePatches, patches];
1576
- patches = _ref4[0];
1577
- inversePatches = _ref4[1];
1578
- }
1579
- for (var index = 0; index < original.length; index += 1) {
1580
- if (assignedMap.get(index.toString()) && copy[index] !== original[index]) {
1581
- var _path = basePath.concat([index]);
1582
- var path = escapePath(_path, pathAsArray);
1583
- patches.push({
1584
- op: Operation.Replace,
1585
- path: path,
1586
- // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
1587
- value: cloneIfNeeded(copy[index])
1588
- });
1589
- inversePatches.push({
1590
- op: Operation.Replace,
1591
- path: path,
1592
- // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
1593
- value: cloneIfNeeded(original[index])
1594
- });
1595
- }
1596
- }
1597
- for (var _index2 = original.length; _index2 < copy.length; _index2 += 1) {
1598
- var _path2 = basePath.concat([_index2]);
1599
- var _path3 = escapePath(_path2, pathAsArray);
1600
- patches.push({
1601
- op: Operation.Add,
1602
- path: _path3,
1603
- // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
1604
- value: cloneIfNeeded(copy[_index2])
1605
- });
1606
- }
1607
- if (original.length < copy.length) {
1608
- // https://www.rfc-editor.org/rfc/rfc6902#appendix-A.4
1609
- // For performance, here we only generate an operation that replaces the length of the array,
1610
- // which is inconsistent with JSON Patch specification
1611
- var _options$enablePatche = options.enablePatches.arrayLengthAssignment,
1612
- arrayLengthAssignment = _options$enablePatche === undefined ? true : _options$enablePatche;
1613
- if (arrayLengthAssignment) {
1614
- var _path4 = basePath.concat(['length']);
1615
- var _path5 = escapePath(_path4, pathAsArray);
1616
- inversePatches.push({
1617
- op: Operation.Replace,
1618
- path: _path5,
1619
- value: original.length
1620
- });
1621
- } else {
1622
- for (var _index3 = copy.length; original.length < _index3; _index3 -= 1) {
1623
- var _path6 = basePath.concat([_index3 - 1]);
1624
- var _path7 = escapePath(_path6, pathAsArray);
1625
- inversePatches.push({
1626
- op: Operation.Remove,
1627
- path: _path7
1628
- });
1629
- }
1630
- }
1631
- }
1632
- }
1633
- function generatePatchesFromAssigned(_ref5, basePath, patches, inversePatches, pathAsArray) {
1634
- var original = _ref5.original,
1635
- copy = _ref5.copy,
1636
- assignedMap = _ref5.assignedMap;
1637
- assignedMap.forEach(function (assignedValue, key) {
1638
- var originalValue = get(original, key);
1639
- var value = cloneIfNeeded(get(copy, key));
1640
- var op = !assignedValue ? Operation.Remove : has(original, key) ? Operation.Replace : Operation.Add;
1641
- if (isEqual(originalValue, value) && op === Operation.Replace) return;
1642
- var _path = basePath.concat(key);
1643
- var path = escapePath(_path, pathAsArray);
1644
- patches.push(op === Operation.Remove ? {
1645
- op: op,
1646
- path: path
1647
- } : {
1648
- op: op,
1649
- path: path,
1650
- value: value
1651
- });
1652
- inversePatches.push(op === Operation.Add ? {
1653
- op: Operation.Remove,
1654
- path: path
1655
- } : op === Operation.Remove ? {
1656
- op: Operation.Add,
1657
- path: path,
1658
- value: originalValue
1659
- } : {
1660
- op: Operation.Replace,
1661
- path: path,
1662
- value: originalValue
1663
- });
1664
- });
1665
- }
1666
- function generateSetPatches(_ref6, basePath, patches, inversePatches, pathAsArray) {
1667
- var original = _ref6.original,
1668
- copy = _ref6.copy;
1669
- var index = 0;
1670
- original.forEach(function (value) {
1671
- if (!copy.has(value)) {
1672
- var _path = basePath.concat([index]);
1673
- var path = escapePath(_path, pathAsArray);
1674
- patches.push({
1675
- op: Operation.Remove,
1676
- path: path,
1677
- value: value
1678
- });
1679
- inversePatches.unshift({
1680
- op: Operation.Add,
1681
- path: path,
1682
- value: value
1683
- });
1684
- }
1685
- index += 1;
1686
- });
1687
- index = 0;
1688
- copy.forEach(function (value) {
1689
- if (!original.has(value)) {
1690
- var _path = basePath.concat([index]);
1691
- var path = escapePath(_path, pathAsArray);
1692
- patches.push({
1693
- op: Operation.Add,
1694
- path: path,
1695
- value: value
1696
- });
1697
- inversePatches.unshift({
1698
- op: Operation.Remove,
1699
- path: path,
1700
- value: value
1701
- });
1702
- }
1703
- index += 1;
1704
- });
1705
- }
1706
- function generatePatches(proxyState, basePath, patches, inversePatches) {
1707
- var _proxyState$options$e = proxyState.options.enablePatches.pathAsArray,
1708
- pathAsArray = _proxyState$options$e === undefined ? true : _proxyState$options$e;
1709
- switch (proxyState.type) {
1710
- case 0 /* DraftType.Object */:
1711
- case 2 /* DraftType.Map */:
1712
- return generatePatchesFromAssigned(proxyState, basePath, patches, inversePatches, pathAsArray);
1713
- case 1 /* DraftType.Array */:
1714
- return generateArrayPatches(proxyState, basePath, patches, inversePatches, pathAsArray);
1715
- case 3 /* DraftType.Set */:
1716
- return generateSetPatches(proxyState, basePath, patches, inversePatches, pathAsArray);
1717
- }
1718
- }
1719
- var checkReadable = function checkReadable(value, options) {
1720
- var ignoreCheckDraftable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1721
- if (_typeof(value) === 'object' && value !== null && (!isDraftable(value, options) || ignoreCheckDraftable) && true) {
1722
- throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.");
1723
- }
1724
- };
1725
- var mapHandler = _defineProperty({
1726
- get size() {
1727
- var current = latest(getProxyDraft(this));
1728
- return current.size;
1729
- },
1730
- has: function has(key) {
1731
- return latest(getProxyDraft(this)).has(key);
1732
- },
1733
- set: function set(key, value) {
1734
- var target = getProxyDraft(this);
1735
- var source = latest(target);
1736
- if (!source.has(key) || !isEqual(source.get(key), value)) {
1737
- ensureShallowCopy(target);
1738
- markChanged(target);
1739
- target.assignedMap.set(key, true);
1740
- target.copy.set(key, value);
1741
- markFinalization(target, key, value, generatePatches);
1742
- }
1743
- return this;
1744
- },
1745
- "delete": function _delete(key) {
1746
- if (!this.has(key)) {
1747
- return false;
1748
- }
1749
- var target = getProxyDraft(this);
1750
- ensureShallowCopy(target);
1751
- markChanged(target);
1752
- if (target.original.has(key)) {
1753
- target.assignedMap.set(key, false);
1754
- } else {
1755
- target.assignedMap["delete"](key);
1756
- }
1757
- target.copy["delete"](key);
1758
- return true;
1759
- },
1760
- clear: function clear() {
1761
- var target = getProxyDraft(this);
1762
- if (!this.size) return;
1763
- ensureShallowCopy(target);
1764
- markChanged(target);
1765
- target.assignedMap = new Map();
1766
- var _iterator5 = _createForOfIteratorHelper(target.original),
1767
- _step5;
1768
- try {
1769
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1770
- var _step5$value = _slicedToArray(_step5.value, 1),
1771
- key = _step5$value[0];
1772
- target.assignedMap.set(key, false);
1773
- }
1774
- } catch (err) {
1775
- _iterator5.e(err);
1776
- } finally {
1777
- _iterator5.f();
1778
- }
1779
- target.copy.clear();
1780
- },
1781
- forEach: function forEach(callback, thisArg) {
1782
- var _this = this;
1783
- var target = getProxyDraft(this);
1784
- latest(target).forEach(function (_value, _key) {
1785
- callback.call(thisArg, _this.get(_key), _key, _this);
1786
- });
1787
- },
1788
- get: function get(key) {
1789
- var _a, _b;
1790
- var target = getProxyDraft(this);
1791
- var value = latest(target).get(key);
1792
- var mutable = ((_b = (_a = target.options).mark) === null || _b === undefined ? undefined : _b.call(_a, value, dataTypes)) === dataTypes.mutable;
1793
- if (target.options.strict) {
1794
- checkReadable(value, target.options, mutable);
1795
- }
1796
- if (mutable) {
1797
- return value;
1798
- }
1799
- if (target.finalized || !isDraftable(value, target.options)) {
1800
- return value;
1801
- }
1802
- // drafted or reassigned
1803
- if (value !== target.original.get(key)) {
1804
- return value;
1805
- }
1806
- var draft = internal.createDraft({
1807
- original: value,
1808
- parentDraft: target,
1809
- key: key,
1810
- finalities: target.finalities,
1811
- options: target.options
1812
- });
1813
- ensureShallowCopy(target);
1814
- target.copy.set(key, draft);
1815
- return draft;
1816
- },
1817
- keys: function keys() {
1818
- return latest(getProxyDraft(this)).keys();
1819
- },
1820
- values: function values() {
1821
- var _this2 = this;
1822
- var iterator = this.keys();
1823
- return _defineProperty(_defineProperty({}, iteratorSymbol, function () {
1824
- return _this2.values();
1825
- }), "next", function next() {
1826
- var result = iterator.next();
1827
- if (result.done) return result;
1828
- var value = _this2.get(result.value);
1829
- return {
1830
- done: false,
1831
- value: value
1832
- };
1833
- });
1834
- },
1835
- entries: function entries() {
1836
- var _this3 = this;
1837
- var iterator = this.keys();
1838
- return _defineProperty(_defineProperty({}, iteratorSymbol, function () {
1839
- return _this3.entries();
1840
- }), "next", function next() {
1841
- var result = iterator.next();
1842
- if (result.done) return result;
1843
- var value = _this3.get(result.value);
1844
- return {
1845
- done: false,
1846
- value: [result.value, value]
1847
- };
1848
- });
1849
- }
1850
- }, iteratorSymbol, function () {
1851
- return this.entries();
1852
- });
1853
- var mapHandlerKeys = Reflect.ownKeys(mapHandler);
1854
- var getNextIterator = function getNextIterator(target, iterator, _ref9) {
1855
- var isValuesIterator = _ref9.isValuesIterator;
1856
- return function () {
1857
- var _a, _b;
1858
- var result = iterator.next();
1859
- if (result.done) return result;
1860
- var key = result.value;
1861
- var value = target.setMap.get(key);
1862
- var currentDraft = getProxyDraft(value);
1863
- var mutable = ((_b = (_a = target.options).mark) === null || _b === undefined ? undefined : _b.call(_a, value, dataTypes)) === dataTypes.mutable;
1864
- if (target.options.strict) {
1865
- checkReadable(key, target.options, mutable);
1866
- }
1867
- if (!mutable && !currentDraft && isDraftable(key, target.options) && !target.finalized && target.original.has(key)) {
1868
- // draft a draftable original set item
1869
- var proxy = internal.createDraft({
1870
- original: key,
1871
- parentDraft: target,
1872
- key: key,
1873
- finalities: target.finalities,
1874
- options: target.options
1875
- });
1876
- target.setMap.set(key, proxy);
1877
- value = proxy;
1878
- } else if (currentDraft) {
1879
- // drafted
1880
- value = currentDraft.proxy;
1881
- }
1882
- return {
1883
- done: false,
1884
- value: isValuesIterator ? value : [value, value]
1885
- };
1886
- };
1887
- };
1888
- var setHandler = _defineProperty(_defineProperty({
1889
- get size() {
1890
- var target = getProxyDraft(this);
1891
- return target.setMap.size;
1892
- },
1893
- has: function has(value) {
1894
- var target = getProxyDraft(this);
1895
- // reassigned or non-draftable values
1896
- if (target.setMap.has(value)) return true;
1897
- ensureShallowCopy(target);
1898
- var valueProxyDraft = getProxyDraft(value);
1899
- // drafted
1900
- if (valueProxyDraft && target.setMap.has(valueProxyDraft.original)) return true;
1901
- return false;
1902
- },
1903
- add: function add(value) {
1904
- var target = getProxyDraft(this);
1905
- if (!this.has(value)) {
1906
- ensureShallowCopy(target);
1907
- markChanged(target);
1908
- target.assignedMap.set(value, true);
1909
- target.setMap.set(value, value);
1910
- markFinalization(target, value, value, generatePatches);
1911
- }
1912
- return this;
1913
- },
1914
- "delete": function _delete(value) {
1915
- if (!this.has(value)) {
1916
- return false;
1917
- }
1918
- var target = getProxyDraft(this);
1919
- ensureShallowCopy(target);
1920
- markChanged(target);
1921
- var valueProxyDraft = getProxyDraft(value);
1922
- if (valueProxyDraft && target.setMap.has(valueProxyDraft.original)) {
1923
- // delete drafted
1924
- target.assignedMap.set(valueProxyDraft.original, false);
1925
- return target.setMap["delete"](valueProxyDraft.original);
1926
- }
1927
- if (!valueProxyDraft && target.setMap.has(value)) {
1928
- // non-draftable values
1929
- target.assignedMap.set(value, false);
1930
- } else {
1931
- // reassigned
1932
- target.assignedMap["delete"](value);
1933
- }
1934
- // delete reassigned or non-draftable values
1935
- return target.setMap["delete"](value);
1936
- },
1937
- clear: function clear() {
1938
- if (!this.size) return;
1939
- var target = getProxyDraft(this);
1940
- ensureShallowCopy(target);
1941
- markChanged(target);
1942
- var _iterator6 = _createForOfIteratorHelper(target.original),
1943
- _step6;
1944
- try {
1945
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1946
- var value = _step6.value;
1947
- target.assignedMap.set(value, false);
1948
- }
1949
- } catch (err) {
1950
- _iterator6.e(err);
1951
- } finally {
1952
- _iterator6.f();
1953
- }
1954
- target.setMap.clear();
1955
- },
1956
- values: function values() {
1957
- var _this4 = this;
1958
- var target = getProxyDraft(this);
1959
- ensureShallowCopy(target);
1960
- var iterator = target.setMap.keys();
1961
- return _defineProperty(_defineProperty({}, Symbol.iterator, function () {
1962
- return _this4.values();
1963
- }), "next", getNextIterator(target, iterator, {
1964
- isValuesIterator: true
1965
- }));
1966
- },
1967
- entries: function entries() {
1968
- var _this5 = this;
1969
- var target = getProxyDraft(this);
1970
- ensureShallowCopy(target);
1971
- var iterator = target.setMap.keys();
1972
- return _defineProperty(_defineProperty({}, Symbol.iterator, function () {
1973
- return _this5.entries();
1974
- }), "next", getNextIterator(target, iterator, {
1975
- isValuesIterator: false
1976
- }));
1977
- },
1978
- keys: function keys() {
1979
- return this.values();
1980
- }
1981
- }, iteratorSymbol, function () {
1982
- return this.values();
1983
- }), "forEach", function forEach(callback, thisArg) {
1984
- var iterator = this.values();
1985
- var result = iterator.next();
1986
- while (!result.done) {
1987
- callback.call(thisArg, result.value, result.value, this);
1988
- result = iterator.next();
1989
- }
1990
- });
1991
- if (Set.prototype.difference) {
1992
- // for compatibility with new Set methods
1993
- // https://github.com/tc39/proposal-set-methods
1994
- // And `https://github.com/tc39/proposal-set-methods/blob/main/details.md#symbolspecies` has some details about the `@@species` symbol.
1995
- // So we can't use SubSet instance constructor to get the constructor of the SubSet instance.
1996
- Object.assign(setHandler, {
1997
- intersection: function intersection(other) {
1998
- return Set.prototype.intersection.call(new Set(this.values()), other);
1999
- },
2000
- union: function union(other) {
2001
- return Set.prototype.union.call(new Set(this.values()), other);
2002
- },
2003
- difference: function difference(other) {
2004
- return Set.prototype.difference.call(new Set(this.values()), other);
2005
- },
2006
- symmetricDifference: function symmetricDifference(other) {
2007
- return Set.prototype.symmetricDifference.call(new Set(this.values()), other);
2008
- },
2009
- isSubsetOf: function isSubsetOf(other) {
2010
- return Set.prototype.isSubsetOf.call(new Set(this.values()), other);
2011
- },
2012
- isSupersetOf: function isSupersetOf(other) {
2013
- return Set.prototype.isSupersetOf.call(new Set(this.values()), other);
2014
- },
2015
- isDisjointFrom: function isDisjointFrom(other) {
2016
- return Set.prototype.isDisjointFrom.call(new Set(this.values()), other);
2017
- }
2018
- });
2019
- }
2020
- var setHandlerKeys = Reflect.ownKeys(setHandler);
2021
- var draftsCache = new WeakSet();
2022
- var proxyHandler = {
2023
- get: function get(target, key, receiver) {
2024
- var _a, _b;
2025
- var copy = (_a = target.copy) === null || _a === undefined ? undefined : _a[key];
2026
- // Improve draft reading performance by caching the draft copy.
2027
- if (copy && draftsCache.has(copy)) {
2028
- return copy;
2029
- }
2030
- if (key === PROXY_DRAFT) return target;
2031
- var markResult;
2032
- if (target.options.mark) {
2033
- // handle `Uncaught TypeError: Method get Map.prototype.size called on incompatible receiver #<Map>`
2034
- // or `Uncaught TypeError: Method get Set.prototype.size called on incompatible receiver #<Set>`
2035
- var _value5 = key === 'size' && (target.original instanceof Map || target.original instanceof Set) ? Reflect.get(target.original, key) : Reflect.get(target.original, key, receiver);
2036
- markResult = target.options.mark(_value5, dataTypes);
2037
- if (markResult === dataTypes.mutable) {
2038
- if (target.options.strict) {
2039
- checkReadable(_value5, target.options, true);
2040
- }
2041
- return _value5;
2042
- }
2043
- }
2044
- var source = latest(target);
2045
- if (source instanceof Map && mapHandlerKeys.includes(key)) {
2046
- if (key === 'size') {
2047
- return Object.getOwnPropertyDescriptor(mapHandler, 'size').get.call(target.proxy);
2048
- }
2049
- var handle = mapHandler[key];
2050
- if (handle) {
2051
- return handle.bind(target.proxy);
2052
- }
2053
- }
2054
- if (source instanceof Set && setHandlerKeys.includes(key)) {
2055
- if (key === 'size') {
2056
- return Object.getOwnPropertyDescriptor(setHandler, 'size').get.call(target.proxy);
2057
- }
2058
- var _handle = setHandler[key];
2059
- if (_handle) {
2060
- return _handle.bind(target.proxy);
2061
- }
2062
- }
2063
- if (!has(source, key)) {
2064
- var desc = getDescriptor(source, key);
2065
- return desc ? "value" in desc ? desc.value :
2066
- // !case: support for getter
2067
- (_b = desc.get) === null || _b === undefined ? undefined : _b.call(target.proxy) : undefined;
2068
- }
2069
- var value = source[key];
2070
- if (target.options.strict) {
2071
- checkReadable(value, target.options);
2072
- }
2073
- if (target.finalized || !isDraftable(value, target.options)) {
2074
- return value;
2075
- }
2076
- // Ensure that the assigned values are not drafted
2077
- if (value === peek(target.original, key)) {
2078
- ensureShallowCopy(target);
2079
- target.copy[key] = createDraft({
2080
- original: target.original[key],
2081
- parentDraft: target,
2082
- key: target.type === 1 /* DraftType.Array */ ? Number(key) : key,
2083
- finalities: target.finalities,
2084
- options: target.options
2085
- });
2086
- // !case: support for custom shallow copy function
2087
- if (typeof markResult === 'function') {
2088
- var subProxyDraft = getProxyDraft(target.copy[key]);
2089
- ensureShallowCopy(subProxyDraft);
2090
- // Trigger a custom shallow copy to update to a new copy
2091
- markChanged(subProxyDraft);
2092
- return subProxyDraft.copy;
2093
- }
2094
- return target.copy[key];
2095
- }
2096
- return value;
2097
- },
2098
- set: function set(target, key, value) {
2099
- var _a;
2100
- if (target.type === 3 /* DraftType.Set */ || target.type === 2 /* DraftType.Map */) {
2101
- throw new Error("Map/Set draft does not support any property assignment.");
2102
- }
2103
- var _key;
2104
- if (target.type === 1 /* DraftType.Array */ && key !== 'length' && !(Number.isInteger(_key = Number(key)) && _key >= 0 && (key === 0 || _key === 0 || String(_key) === String(key)))) {
2105
- throw new Error("Only supports setting array indices and the 'length' property.");
2106
- }
2107
- var desc = getDescriptor(latest(target), key);
2108
- if (desc === null || desc === undefined ? undefined : desc.set) {
2109
- // !case: cover the case of setter
2110
- desc.set.call(target.proxy, value);
2111
- return true;
2112
- }
2113
- var current = peek(latest(target), key);
2114
- var currentProxyDraft = getProxyDraft(current);
2115
- if (currentProxyDraft && isEqual(currentProxyDraft.original, value)) {
2116
- // !case: ignore the case of assigning the original draftable value to a draft
2117
- target.copy[key] = value;
2118
- target.assignedMap = (_a = target.assignedMap) !== null && _a !== undefined ? _a : new Map();
2119
- target.assignedMap.set(key, false);
2120
- return true;
2121
- }
2122
- // !case: handle new props with value 'undefined'
2123
- if (isEqual(value, current) && (value !== undefined || has(target.original, key))) return true;
2124
- ensureShallowCopy(target);
2125
- markChanged(target);
2126
- if (has(target.original, key) && isEqual(value, target.original[key])) {
2127
- // !case: handle the case of assigning the original non-draftable value to a draft
2128
- target.assignedMap["delete"](key);
2129
- } else {
2130
- target.assignedMap.set(key, true);
2131
- }
2132
- target.copy[key] = value;
2133
- markFinalization(target, key, value, generatePatches);
2134
- return true;
2135
- },
2136
- has: function has(target, key) {
2137
- return key in latest(target);
2138
- },
2139
- ownKeys: function ownKeys(target) {
2140
- return Reflect.ownKeys(latest(target));
2141
- },
2142
- getOwnPropertyDescriptor: function getOwnPropertyDescriptor(target, key) {
2143
- var source = latest(target);
2144
- var descriptor = Reflect.getOwnPropertyDescriptor(source, key);
2145
- if (!descriptor) return descriptor;
2146
- return {
2147
- writable: true,
2148
- configurable: target.type !== 1 /* DraftType.Array */ || key !== 'length',
2149
- enumerable: descriptor.enumerable,
2150
- value: source[key]
2151
- };
2152
- },
2153
- getPrototypeOf: function getPrototypeOf(target) {
2154
- return Reflect.getPrototypeOf(target.original);
2155
- },
2156
- setPrototypeOf: function setPrototypeOf() {
2157
- throw new Error("Cannot call 'setPrototypeOf()' on drafts");
2158
- },
2159
- defineProperty: function defineProperty() {
2160
- throw new Error("Cannot call 'defineProperty()' on drafts");
2161
- },
2162
- deleteProperty: function deleteProperty(target, key) {
2163
- var _a;
2164
- if (target.type === 1 /* DraftType.Array */) {
2165
- return proxyHandler.set.call(this, target, key, undefined, target.proxy);
2166
- }
2167
- if (peek(target.original, key) !== undefined || key in target.original) {
2168
- // !case: delete an existing key
2169
- ensureShallowCopy(target);
2170
- markChanged(target);
2171
- target.assignedMap.set(key, false);
2172
- } else {
2173
- target.assignedMap = (_a = target.assignedMap) !== null && _a !== undefined ? _a : new Map();
2174
- // The original non-existent key has been deleted
2175
- target.assignedMap["delete"](key);
2176
- }
2177
- if (target.copy) delete target.copy[key];
2178
- return true;
2179
- }
2180
- };
2181
- function createDraft(createDraftOptions) {
2182
- var original = createDraftOptions.original,
2183
- parentDraft = createDraftOptions.parentDraft,
2184
- key = createDraftOptions.key,
2185
- finalities = createDraftOptions.finalities,
2186
- options = createDraftOptions.options;
2187
- var type = getType(original);
2188
- var proxyDraft = {
2189
- type: type,
2190
- finalized: false,
2191
- parent: parentDraft,
2192
- original: original,
2193
- copy: null,
2194
- proxy: null,
2195
- finalities: finalities,
2196
- options: options,
2197
- // Mapping of draft Set items to their corresponding draft values.
2198
- setMap: type === 3 /* DraftType.Set */ ? new Map(original.entries()) : undefined
2199
- };
2200
- // !case: undefined as a draft map key
2201
- if (key || 'key' in createDraftOptions) {
2202
- proxyDraft.key = key;
2203
- }
2204
- var _Proxy$revocable = Proxy.revocable(type === 1 /* DraftType.Array */ ? Object.assign([], proxyDraft) : proxyDraft, proxyHandler),
2205
- proxy = _Proxy$revocable.proxy,
2206
- revoke = _Proxy$revocable.revoke;
2207
- finalities.revoke.push(revoke);
2208
- draftsCache.add(proxy);
2209
- proxyDraft.proxy = proxy;
2210
- if (parentDraft) {
2211
- var target = parentDraft;
2212
- target.finalities.draft.push(function (patches, inversePatches) {
2213
- var _a, _b;
2214
- var oldProxyDraft = getProxyDraft(proxy);
2215
- // if target is a Set draft, `setMap` is the real Set copies proxy mapping.
2216
- var copy = target.type === 3 /* DraftType.Set */ ? target.setMap : target.copy;
2217
- var draft = get(copy, key);
2218
- var proxyDraft = getProxyDraft(draft);
2219
- if (proxyDraft) {
2220
- // assign the updated value to the copy object
2221
- var updatedValue = proxyDraft.original;
2222
- if (proxyDraft.operated) {
2223
- updatedValue = getValue(draft);
2224
- }
2225
- finalizeSetValue(proxyDraft);
2226
- finalizePatches(proxyDraft, generatePatches, patches, inversePatches);
2227
- if (target.options.enableAutoFreeze) {
2228
- target.options.updatedValues = (_a = target.options.updatedValues) !== null && _a !== undefined ? _a : new WeakMap();
2229
- target.options.updatedValues.set(updatedValue, proxyDraft.original);
2230
- }
2231
- // final update value
2232
- set(copy, key, updatedValue);
2233
- }
2234
- // !case: handle the deleted key
2235
- (_b = oldProxyDraft.callbacks) === null || _b === undefined ? undefined : _b.forEach(function (callback) {
2236
- callback(patches, inversePatches);
2237
- });
2238
- });
2239
- } else {
2240
- // !case: handle the root draft
2241
- var _target = getProxyDraft(proxy);
2242
- _target.finalities.draft.push(function (patches, inversePatches) {
2243
- finalizeSetValue(_target);
2244
- finalizePatches(_target, generatePatches, patches, inversePatches);
2245
- });
2246
- }
2247
- return proxy;
2248
- }
2249
- internal.createDraft = createDraft;
2250
- function finalizeDraft(result, returnedValue, patches, inversePatches, enableAutoFreeze) {
2251
- var _a;
2252
- var proxyDraft = getProxyDraft(result);
2253
- var original = (_a = proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.original) !== null && _a !== undefined ? _a : result;
2254
- var hasReturnedValue = !!returnedValue.length;
2255
- if (proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.operated) {
2256
- while (proxyDraft.finalities.draft.length > 0) {
2257
- var finalize = proxyDraft.finalities.draft.pop();
2258
- finalize(patches, inversePatches);
2259
- }
2260
- }
2261
- var state = hasReturnedValue ? returnedValue[0] : proxyDraft ? proxyDraft.operated ? proxyDraft.copy : proxyDraft.original : result;
2262
- if (proxyDraft) revokeProxy(proxyDraft);
2263
- if (enableAutoFreeze) {
2264
- deepFreeze(state, state, proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.options.updatedValues);
2265
- }
2266
- return [state, patches && hasReturnedValue ? [{
2267
- op: Operation.Replace,
2268
- path: [],
2269
- value: returnedValue[0]
2270
- }] : patches, inversePatches && hasReturnedValue ? [{
2271
- op: Operation.Replace,
2272
- path: [],
2273
- value: original
2274
- }] : inversePatches];
2275
- }
2276
- function draftify(baseState, options) {
2277
- var _a;
2278
- var finalities = {
2279
- draft: [],
2280
- revoke: [],
2281
- handledSet: new WeakSet()
2282
- };
2283
- var patches;
2284
- var inversePatches;
2285
- if (options.enablePatches) {
2286
- patches = [];
2287
- inversePatches = [];
2288
- }
2289
- var isMutable = ((_a = options.mark) === null || _a === undefined ? undefined : _a.call(options, baseState, dataTypes)) === dataTypes.mutable || !isDraftable(baseState, options);
2290
- var draft = isMutable ? baseState : createDraft({
2291
- original: baseState,
2292
- parentDraft: null,
2293
- finalities: finalities,
2294
- options: options
2295
- });
2296
- return [draft, function () {
2297
- var returnedValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2298
- var _finalizeDraft = finalizeDraft(draft, returnedValue, patches, inversePatches, options.enableAutoFreeze),
2299
- _finalizeDraft2 = _slicedToArray(_finalizeDraft, 3),
2300
- finalizedState = _finalizeDraft2[0],
2301
- finalizedPatches = _finalizeDraft2[1],
2302
- finalizedInversePatches = _finalizeDraft2[2];
2303
- return options.enablePatches ? [finalizedState, finalizedPatches, finalizedInversePatches] : finalizedState;
2304
- }];
2305
- }
2306
- function handleReturnValue(options) {
2307
- var rootDraft = options.rootDraft,
2308
- value = options.value,
2309
- _options$useRawReturn = options.useRawReturn,
2310
- useRawReturn = _options$useRawReturn === undefined ? false : _options$useRawReturn,
2311
- _options$isRoot = options.isRoot,
2312
- isRoot = _options$isRoot === undefined ? true : _options$isRoot;
2313
- forEach(value, function (key, item, source) {
2314
- var proxyDraft = getProxyDraft(item);
2315
- // just handle the draft which is created by the same rootDraft
2316
- if (proxyDraft && rootDraft && proxyDraft.finalities === rootDraft.finalities) {
2317
- options.isContainDraft = true;
2318
- var currentValue = proxyDraft.original;
2319
- // final update value, but just handle return value
2320
- if (source instanceof Set) {
2321
- var arr = Array.from(source);
2322
- source.clear();
2323
- arr.forEach(function (_item) {
2324
- return source.add(key === _item ? currentValue : _item);
2325
- });
2326
- } else {
2327
- set(source, key, currentValue);
2328
- }
2329
- } else if (_typeof(item) === 'object' && item !== null) {
2330
- options.value = item;
2331
- options.isRoot = false;
2332
- handleReturnValue(options);
2333
- }
2334
- });
2335
- if (isRoot) {
2336
- if (!options.isContainDraft) console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance.");
2337
- if (useRawReturn) {
2338
- console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value.");
2339
- }
2340
- }
2341
- }
2342
- function getCurrent(target) {
2343
- var _a;
2344
- var proxyDraft = getProxyDraft(target);
2345
- if (!isDraftable(target, proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.options)) return target;
2346
- var type = getType(target);
2347
- if (proxyDraft && !proxyDraft.operated) return proxyDraft.original;
2348
- var currentValue;
2349
- function ensureShallowCopy() {
2350
- currentValue = type === 2 /* DraftType.Map */ ? !isBaseMapInstance(target) ? new (Object.getPrototypeOf(target).constructor)(target) : new Map(target) : type === 3 /* DraftType.Set */ ? Array.from(proxyDraft.setMap.values()) : shallowCopy(target, proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.options);
2351
- }
2352
- if (proxyDraft) {
2353
- // It's a proxy draft, let's create a shallow copy eagerly
2354
- proxyDraft.finalized = true;
2355
- try {
2356
- ensureShallowCopy();
2357
- } finally {
2358
- proxyDraft.finalized = false;
2359
- }
2360
- } else {
2361
- // It's not a proxy draft, let's use the target directly and let's see
2362
- // lazily if we need to create a shallow copy
2363
- currentValue = target;
2364
- }
2365
- forEach(currentValue, function (key, value) {
2366
- if (proxyDraft && isEqual(get(proxyDraft.original, key), value)) return;
2367
- var newValue = getCurrent(value);
2368
- if (newValue !== value) {
2369
- if (currentValue === target) ensureShallowCopy();
2370
- set(currentValue, key, newValue);
2371
- }
2372
- });
2373
- if (type === 3 /* DraftType.Set */) {
2374
- var value = (_a = proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.original) !== null && _a !== undefined ? _a : currentValue;
2375
- return !isBaseSetInstance(value) ? new (Object.getPrototypeOf(value).constructor)(currentValue) : new Set(currentValue);
2376
- }
2377
- return currentValue;
2378
- }
2379
- function current(target) {
2380
- if (!isDraft(target)) {
2381
- throw new Error("current() is only used for Draft, parameter: ".concat(target));
2382
- }
2383
- return getCurrent(target);
2384
- }
2385
-
2386
- /**
2387
- * `makeCreator(options)` to make a creator function.
2388
- *
2389
- * ## Example
2390
- *
2391
- * ```ts
2392
- * import { makeCreator } from '../index';
2393
- *
2394
- * const baseState = { foo: { bar: 'str' }, arr: [] };
2395
- * const create = makeCreator({ enableAutoFreeze: true });
2396
- * const state = create(
2397
- * baseState,
2398
- * (draft) => {
2399
- * draft.foo.bar = 'str2';
2400
- * },
2401
- * );
2402
- *
2403
- * expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
2404
- * expect(state).not.toBe(baseState);
2405
- * expect(state.foo).not.toBe(baseState.foo);
2406
- * expect(state.arr).toBe(baseState.arr);
2407
- * expect(Object.isFrozen(state)).toBeTruthy();
2408
- * ```
2409
- */
2410
- var makeCreator = function makeCreator(arg) {
2411
- return function create(arg0, arg1, arg2) {
2412
- var _a, _b, _c;
2413
- if (typeof arg0 === 'function' && typeof arg1 !== 'function') {
2414
- return function (base) {
2415
- var _this6 = this;
2416
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key2 = 1; _key2 < _len; _key2++) {
2417
- args[_key2 - 1] = arguments[_key2];
2418
- }
2419
- return create(base, function (draft) {
2420
- return arg0.call.apply(arg0, [_this6, draft].concat(args));
2421
- }, arg1);
2422
- };
2423
- }
2424
- var base = arg0;
2425
- var mutate = arg1;
2426
- var options = arg2;
2427
- if (typeof arg1 !== 'function') {
2428
- options = arg1;
2429
- }
2430
- if (options !== undefined && Object.prototype.toString.call(options) !== '[object Object]') {
2431
- throw new Error("Invalid options: ".concat(options, ", 'options' should be an object."));
2432
- }
2433
- options = Object.assign(Object.assign({}, arg), options);
2434
- var state = isDraft(base) ? current(base) : base;
2435
- var mark = Array.isArray(options.mark) ? function (value, types) {
2436
- var _iterator7 = _createForOfIteratorHelper(options.mark),
2437
- _step7;
2438
- try {
2439
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
2440
- var _mark = _step7.value;
2441
- if (typeof _mark !== 'function') {
2442
- throw new Error("Invalid mark: ".concat(_mark, ", 'mark' should be a function."));
2443
- }
2444
- var _result = _mark(value, types);
2445
- if (_result) {
2446
- return _result;
2447
- }
2448
- }
2449
- } catch (err) {
2450
- _iterator7.e(err);
2451
- } finally {
2452
- _iterator7.f();
2453
- }
2454
- return;
2455
- } : options.mark;
2456
- var enablePatches = (_a = options.enablePatches) !== null && _a !== undefined ? _a : false;
2457
- var strict = (_b = options.strict) !== null && _b !== undefined ? _b : false;
2458
- var enableAutoFreeze = (_c = options.enableAutoFreeze) !== null && _c !== undefined ? _c : false;
2459
- var _options = {
2460
- enableAutoFreeze: enableAutoFreeze,
2461
- mark: mark,
2462
- strict: strict,
2463
- enablePatches: enablePatches
2464
- };
2465
- if (!isDraftable(state, _options) && _typeof(state) === 'object' && state !== null) {
2466
- throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
2467
- }
2468
- var _draftify = draftify(state, _options),
2469
- _draftify2 = _slicedToArray(_draftify, 2),
2470
- draft = _draftify2[0],
2471
- finalize = _draftify2[1];
2472
- if (typeof arg1 !== 'function') {
2473
- if (!isDraftable(state, _options)) {
2474
- throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
2475
- }
2476
- return [draft, finalize];
2477
- }
2478
- var result;
2479
- try {
2480
- result = mutate(draft);
2481
- } catch (error) {
2482
- revokeProxy(getProxyDraft(draft));
2483
- throw error;
2484
- }
2485
- var returnValue = function returnValue(value) {
2486
- var proxyDraft = getProxyDraft(draft);
2487
- if (!isDraft(value)) {
2488
- if (value !== undefined && !isEqual(value, draft) && (proxyDraft === null || proxyDraft === undefined ? undefined : proxyDraft.operated)) {
2489
- throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");
2490
- }
2491
- var rawReturnValue = value === null || value === undefined ? undefined : value[RAW_RETURN_SYMBOL];
2492
- if (rawReturnValue) {
2493
- var _value = rawReturnValue[0];
2494
- if (_options.strict && _typeof(value) === 'object' && value !== null) {
2495
- handleReturnValue({
2496
- rootDraft: proxyDraft,
2497
- value: value,
2498
- useRawReturn: true
2499
- });
2500
- }
2501
- return finalize([_value]);
2502
- }
2503
- if (value !== undefined) {
2504
- if (_typeof(value) === 'object' && value !== null) {
2505
- handleReturnValue({
2506
- rootDraft: proxyDraft,
2507
- value: value
2508
- });
2509
- }
2510
- return finalize([value]);
2511
- }
2512
- }
2513
- if (value === draft || value === undefined) {
2514
- return finalize([]);
2515
- }
2516
- var returnedProxyDraft = getProxyDraft(value);
2517
- if (_options === returnedProxyDraft.options) {
2518
- if (returnedProxyDraft.operated) {
2519
- throw new Error("Cannot return a modified child draft.");
2520
- }
2521
- return finalize([current(value)]);
2522
- }
2523
- return finalize([value]);
2524
- };
2525
- if (result instanceof Promise) {
2526
- return result.then(returnValue, function (error) {
2527
- revokeProxy(getProxyDraft(draft));
2528
- throw error;
2529
- });
2530
- }
2531
- return returnValue(result);
2532
- };
2533
- };
2534
-
2535
- /**
2536
- * `create(baseState, callback, options)` to create the next state
2537
- *
2538
- * ## Example
2539
- *
2540
- * ```ts
2541
- * import { create } from '../index';
2542
- *
2543
- * const baseState = { foo: { bar: 'str' }, arr: [] };
2544
- * const state = create(
2545
- * baseState,
2546
- * (draft) => {
2547
- * draft.foo.bar = 'str2';
2548
- * },
2549
- * );
2550
- *
2551
- * expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
2552
- * expect(state).not.toBe(baseState);
2553
- * expect(state.foo).not.toBe(baseState.foo);
2554
- * expect(state.arr).toBe(baseState.arr);
2555
- * ```
2556
- */
2557
- var create = makeCreator();
2558
- Object.prototype.constructor.toString();
2559
-
2560
- function produceState(state, fn) {
2561
- state.set(create(state.get(), fn));
2562
- }
2563
-
2564
- var RumiousState = /*#__PURE__*/function () {
2565
- function RumiousState(target) {
2566
- var reactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2567
- _classCallCheck(this, RumiousState);
2568
- this.value = target;
2569
- this.reactor = reactor !== null && reactor !== undefined ? reactor : new RumiousReactor(this, []);
2570
- }
2571
- return _createClass(RumiousState, [{
2572
- key: "produce",
2573
- value: function produce(recipe) {
2574
- return produceState(this, recipe);
2575
- }
2576
- }, {
2577
- key: "reducer",
2578
- value: function reducer() {
2579
- var computedObj;
2580
- if (arguments.length === 1) {
2581
- computedObj = new RumiousReducer(this, "", arguments.length <= 0 ? undefined : arguments[0]);
2582
- } else {
2583
- computedObj = new RumiousReducer(this, arguments.length <= 0 ? undefined : arguments[0], arguments.length <= 1 ? undefined : arguments[1]);
2584
- }
2585
- return computedObj.trigger.bind(computedObj);
2586
- }
2587
- }, {
2588
- key: "setObjectByPath",
2589
- value: function setObjectByPath() {
2590
- var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
2591
- var value = arguments.length > 1 ? arguments[1] : undefined;
2592
- if (path.length == 0) {
2593
- this.value = value;
2594
- return;
2595
- }
2596
- if (typeof path !== 'string' || !path) {
2597
- throw new Error('Invalid path');
2598
- }
2599
- var keys = path.split('.');
2600
- var obj = this.value;
2601
- for (var i = 0; i < keys.length - 1; i++) {
2602
- var key = keys[i];
2603
- if (!(key in obj)) {
2604
- obj[key] = {};
2605
- }
2606
- obj = obj[key];
2607
- }
2608
- obj[keys[keys.length - 1]] = value;
2609
- }
2610
- }, {
2611
- key: "set",
2612
- value: function set() {
2613
- if (arguments.length === 1) {
2614
- this.value = arguments.length <= 0 ? undefined : arguments[0];
2615
- } else {
2616
- var path = arguments.length <= 0 ? undefined : arguments[0];
2617
- var value = arguments.length <= 1 ? undefined : arguments[1];
2618
- this.setObjectByPath(path, value);
2619
- }
2620
- this.reactor.react();
2621
- }
2622
- }, {
2623
- key: "get",
2624
- value: function get() {
2625
- return this.value;
2626
- }
2627
- }]);
2628
- }();
2629
- function createState(value) {
2630
- return new RumiousState(value);
2631
- }
2632
- function isState(obj) {
2633
- return obj instanceof RumiousState;
2634
- }
2635
-
2636
- function watcher(state, callback) {
2637
- state.reactor.addBinding(callback);
2638
- }
2639
-
2640
- exports.RumiousApp = RumiousApp;
2641
- exports.RumiousComponent = RumiousComponent;
2642
- exports.RumiousComponentElement = RumiousComponentElement;
2643
- exports.RumiousState = RumiousState;
2644
- exports.createComponentElement = createComponentElement;
2645
- exports.createState = createState;
2646
- exports.isComponent = isComponent;
2647
- exports.isState = isState;
2648
- exports.watcher = watcher;
2649
-
2650
- return exports;
2651
-
2652
- })({});
2653
- //# sourceMappingURL=index.js.map
1
+ var Rumious=function(e){"use strict";class t{constructor(e){this.target=e}find(e){return this.target[e]}get(e){return this.target[e]}}class n{constructor(){this.element=null,this.props={},this.renderContext=new t(this),this.renderer=null,this.wrapped=null}prepare(e,t,n={},r=null){this.element=e,this.props=t,this.renderer=r,this.wrapped=n}template(){return{}}requestRender(){let e=this.template(),t=this.renderer(e,document.createDocumentFragment(),this.renderContext);this.element.appendChild(t),this.onRender()}async requestCleanUp(){if(this.element){let e=this.element.cloneNode(!0);for(this.element.replaceWith(e),this.element=e;this.element.firstChild;)this.element.removeChild(this.element.firstChild)}}onInit(){}onCreate(){}onRender(){}onUpdate(){}onDestroy(){}}function r(e){return Object.getPrototypeOf(e)===n}class o{constructor(e,t,n=[]){this.type=e,this.props=t,this.children=n}}class i{constructor(e){this.type="ELEMENT_LIST",this.children=e}forEach(e){this.children.forEach(e)}}function s(e){return"function"==typeof e}class a{constructor(e,t,n){this.type=e,this.name=t,this.value=n}init(){console.warn("Directive haven't handler !")}}class l extends a{async init(e,t){let n=null;const r=e=>{if(!t.find(e))return console.warn(`Missing event handler for event: ${this.name}`),null;const n=t.get(e);if(!s(n))throw`${e} is not a function!`;return n.bind(t.target)};if("string"===this.value.type)n=r(this.value.value);else if("expression"===this.value.type){if(n=this.value.value,!s(n))throw"Event handler requires a function!"}else"dynamic_value"===this.value.type&&(n=r(this.value.value.objectName));n&&e.addEventListener(this.name,n)}}class c extends a{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw"Invalid props value: Directive bind: require a RumiousState Object !";t.reactor.addBinding((()=>{let n=t.get();this.bindAttr(e,n)})),this.bindAttr(e,t.get())}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target),r=t.find(this.value.value.objectName);if(!r)throw"Invalid props value: Directive bind: require a RumiousState Object !";r.reactor.addBinding((()=>{let n=this.value.evaluator?.(t.target);this.bindAttr(e,n)})),this.bindAttr(e,n)}}normalizeValue(e){return"object"==typeof e?e.toString?.()??"":e}async bindAttr(e,t){if("html"===this.name)e.innerHTML=this.normalizeValue(t)}}class u extends a{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw"Invalid props value: Directive ref: require a RumiousRef Object !";t.set(e)}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target);if(!n)throw"Invalid props value: Directive ref: require a RumiousRef Object !";n.set(e)}}}class p extends a{async init(e,t){if("expression"===this.value.type){let t=this.value.value;if(!t)throw"Invalid props value: Directive childsRef: require a RumiousChildRef Object !";t.set(e)}else if("dynamic_value"===this.value.type){let n=this.value.evaluator?.(t.target);if(!n)throw"Invalid props value: Directive childsRef: require a RumiousChildRef Object !";n.set(e)}}}const f={on:(e,t)=>new l("on",e,t),bind:(e,t)=>new c("bind",e,t),ref:(e,t,n="element")=>new u("ref",e,t),childsRef:(e,t)=>new p("childsRef",e,t)};function h(...e){return new o("FRAGMENT",{},d(e))}function d(e){return e.map((e=>"object"==typeof e?e:new o("TEXT_ELEMENT",{nodeValue:e},[])))}window.RUMIOUS_JSX_SUPPORT={createElement:function(e,t,...n){return r(e)?function(e,t,n){return new o("COMPONENT",{component:e,...t},new i(d(n)))}(e,t,n):e===h?h(...n):new o(e,t||{},d(n))},createFragment:h,createDirective:function(e,t,n){return function(e,t,n){return f[e]?.(t,n)}(e,t,n)}};class y extends HTMLElement{constructor(){super(),this.instance=null,this.ref=null}setRef(e){this.ref=e}init(e,t,n={},r){this.instance=new e,this.instance.prepare(this,t,n,r),this.instance.onInit()}connectedCallback(){this.instance.onCreate(),this.instance.requestRender(),this.instance.forwardRef=this.ref??{}}disconnectCallback(){this.instance.onDestroy(),this.instance.requestCleanUp()}}function g(){return document.createElement("a-component")}function v(e,t,n,r){const o=function(e,t,n,r){const o=g();return o.init(e,t,n,r),o}(e.props.component,e.props,e.children,n);return Object.entries(e.props||{}).forEach((([e,t])=>{t instanceof a&&b(o,t,r)})),t.appendChild(o),t}function m(e,t){const n=document.createElement(e.type);return Object.entries(e.props||{}).forEach((([e,r])=>{e.startsWith("on")&&/^[a-zA-Z]+([A-Z][a-z]*)*$/.test(e)?n.addEventListener(e.substring(2).toLowerCase(),r):function(e,t,n,r){e.nodeType===Node.TEXT_NODE?e.nodeValue=n:n instanceof a?b(e,n,r):e.setAttribute(t,n)}(n,e,r,t)})),n}function b(e,t,n){t.init(e,n)}function w(e,t,n={}){if(!e)return t;let r;return"COMPONENT"===e.type?v(e,t,w,n):"FRAGMENT"===e.type||"ELEMENT_LIST"===e.type?function(e,t,n){return e.children.forEach((e=>w(e,t,n))),t}(e,t,n):(r="TEXT_ELEMENT"===e.type?function(e){return document.createTextNode(e.props.nodeValue)}(e):m(e,n),e.children.forEach((e=>w(e,r,n))),t.appendChild(r),t)}window.customElements.define("a-component",y);class O{constructor(e=null,t=[]){this.target=e,this.bindings=t}react(){this.bindings.forEach((e=>e()))}addBinding(e){this.bindings.push(e)}}class M{constructor(e,t="",n){this.state=e,this.path=t,this.fn=n}trigger(...e){let t=this.fn(...e);this.state.set(this.path,t)}}const E="remove",j="replace",S="add",k=Symbol.for("__MUTATIVE_PROXY_DRAFT__"),R=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"),A=Symbol.iterator,P={mutable:"mutable",immutable:"immutable"},x={};function C(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function z(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){const e=Reflect.getOwnPropertyDescriptor(n,t);if(e)return e;n=Reflect.getPrototypeOf(n)}}}function D(e){return Object.getPrototypeOf(e)===Set.prototype}function T(e){return Object.getPrototypeOf(e)===Map.prototype}function _(e){var t;return null!==(t=e.copy)&&void 0!==t?t:e.original}function I(e){return!!N(e)}function N(e){return"object"!=typeof e?null:null==e?void 0:e[k]}function F(e){var t;const n=N(e);return n?null!==(t=n.copy)&&void 0!==t?t:n.original:e}function V(e,t){if(!e||"object"!=typeof e)return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!(null==t?void 0:t.mark)&&((n=t.mark(e,P))===P.immutable||"function"==typeof n)}function L(e,t=[]){if(Object.hasOwnProperty.call(e,"key")){const n=e.parent.copy,r=N($(n,e.key));if(null!==r&&(null==r?void 0:r.original)!==e.original)return null;const o=3===e.parent.type,i=o?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(o&&n.size>i||C(n,i)))return null;t.push(i)}if(e.parent)return L(e.parent,t);t.reverse();try{!function(e,t){for(let n=0;n<t.length-1;n+=1){const r=t[n];if("object"!=typeof(e=$(3===q(e)?Array.from(e):e,r)))throw new Error(`Cannot resolve patch at '${t.join("/")}'.`)}}(e.copy,t)}catch(e){return null}return t}function q(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function $(e,t){return 2===q(e)?e.get(t):e[t]}function U(e,t,n){2===q(e)?e.set(t,n):e[t]=n}function W(e,t){const n=N(e);return(n?_(n):e)[t]}function B(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function K(e){if(e)for(;e.finalities.revoke.length>0;){e.finalities.revoke.pop()()}}function X(e,t){return t?e:[""].concat(e).map((e=>{const t=`${e}`;return-1===t.indexOf("/")&&-1===t.indexOf("~")?t:t.replace(/~/g,"~0").replace(/\//g,"~1")})).join("/")}const H=Object.prototype.propertyIsEnumerable;function Y(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set){if(!D(e)){return new(0,Object.getPrototypeOf(e).constructor)(e.values())}return Set.prototype.difference?Set.prototype.difference.call(e,new Set):new Set(e.values())}if(e instanceof Map){if(!T(e)){return new(0,Object.getPrototypeOf(e).constructor)(e)}return new Map(e)}if((null==t?void 0:t.mark)&&(n=t.mark(e,P),void 0!==n)&&n!==P.mutable){if(n===P.immutable)return function(e){const t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((n=>{let r=Reflect.getOwnPropertyDescriptor(e,n);r.enumerable&&r.configurable&&r.writable?t[n]=e[n]:(r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:e[n]}),Reflect.defineProperty(t,n,r))})),t}(e);if("function"==typeof n){if(t.enablePatches||t.enableAutoFreeze)throw new Error("You can't use mark and patches or auto freeze together.");return n()}throw new Error(`Unsupported mark result: ${n}`)}if("object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype){const t={};return Object.keys(e).forEach((n=>{t[n]=e[n]})),Object.getOwnPropertySymbols(e).forEach((n=>{H.call(e,n)&&(t[n]=e[n])})),t}throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}function G(e){e.copy||(e.copy=Y(e.original,e.options))}function Z(e){if(!V(e))return F(e);if(Array.isArray(e))return e.map(Z);if(e instanceof Map){const t=Array.from(e.entries()).map((([e,t])=>[e,Z(t)]));if(!T(e)){return new(0,Object.getPrototypeOf(e).constructor)(t)}return new Map(t)}if(e instanceof Set){const t=Array.from(e).map(Z);if(!D(e)){return new(0,Object.getPrototypeOf(e).constructor)(t)}return new Set(t)}const t=Object.create(Object.getPrototypeOf(e));for(const n in e)t[n]=Z(e[n]);return t}function J(e){return I(e)?Z(e):e}function Q(e){var t;e.assignedMap=null!==(t=e.assignedMap)&&void 0!==t?t:new Map,e.operated||(e.operated=!0,e.parent&&Q(e.parent))}function ee(){throw new Error("Cannot modify frozen object")}function te(e,t,n,r,o){{n=null!=n?n:new WeakMap,r=null!=r?r:[],o=null!=o?o:[];const i=n.has(e)?n.get(e):e;if(r.length>0){const e=r.indexOf(i);if(i&&"object"==typeof i&&-1!==e){if(r[0]===i)throw new Error("Forbids circular reference");throw new Error(`Forbids circular reference: ~/${o.slice(0,e).map(((e,t)=>{if("symbol"==typeof e)return`[${e.toString()}]`;const n=r[t];return"object"==typeof e&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(e):e})).join("/")}`)}r.push(i),o.push(t)}else r.push(i)}if(Object.isFrozen(e)||I(e))return r.pop(),void o.pop();switch(q(e)){case 2:for(const[t,i]of e)te(t,t,n,r,o),te(i,t,n,r,o);e.set=e.clear=e.delete=ee;break;case 3:for(const t of e)te(t,t,n,r,o);e.add=e.clear=e.delete=ee;break;case 1:Object.freeze(e);let t=0;for(const i of e)te(i,t,n,r,o),t+=1;break;default:Object.freeze(e),Object.keys(e).forEach((t=>{te(e[t],t,n,r,o)}))}r.pop(),o.pop()}function ne(e,t){const n=q(e);if(0===n)Reflect.ownKeys(e).forEach((n=>{t(n,e[n],e)}));else if(1===n){let n=0;for(const r of e)t(n,r,e),n+=1}else e.forEach(((n,r)=>t(r,n,e)))}function re(e,t,n){if(I(e)||!V(e,n)||t.has(e)||Object.isFrozen(e))return;const r=e instanceof Set,o=r?new Map:void 0;if(t.add(e),ne(e,((i,s)=>{var a;if(I(s)){const t=N(s);G(t);const n=(null===(a=t.assignedMap)||void 0===a?void 0:a.size)||t.operated?t.copy:t.original;U(r?o:e,i,n)}else re(s,t,n)})),o){const t=e,n=Array.from(t);t.clear(),n.forEach((e=>{t.add(o.has(e)?o.get(e):e)}))}}function oe(e,t){const n=3===e.type?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&re($(n,t),e.finalities.handledSet,e.options)}function ie(e){3===e.type&&e.copy&&(e.copy.clear(),e.setMap.forEach((t=>{e.copy.add(F(t))})))}function se(e,t,n,r){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&r){const o=L(e);o&&t(e,o,n,r)}e.finalized=!0}}function ae(e,t,n,r){const o=N(n);o&&(o.callbacks||(o.callbacks=[]),o.callbacks.push(((i,s)=>{var a;const l=3===e.type?e.setMap:e.copy;if(B($(l,t),n)){let n=o.original;o.copy&&(n=o.copy),ie(e),se(e,r,i,s),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(a=e.options.updatedValues)&&void 0!==a?a:new WeakMap,e.options.updatedValues.set(n,o.original)),U(l,t,n)}})),e.options.enableAutoFreeze&&o.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),V(n,e.options)&&e.finalities.draft.push((()=>{B($(3===e.type?e.setMap:e.copy,t),n)&&oe(e,t)}))}function le(e,t,n,r){const{pathAsArray:o=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return function({original:e,copy:t,assignedMap:n},r,o,i,s){n.forEach(((n,a)=>{const l=$(e,a),c=J($(t,a)),u=n?C(e,a)?j:S:E;if(B(l,c)&&u===j)return;const p=X(r.concat(a),s);o.push(u===E?{op:u,path:p}:{op:u,path:p,value:c}),i.push(u===S?{op:E,path:p}:u===E?{op:S,path:p,value:l}:{op:j,path:p,value:l})}))}(e,t,n,r,o);case 1:return function(e,t,n,r,o){let{original:i,assignedMap:s,options:a}=e,l=e.copy;l.length<i.length&&([i,l]=[l,i],[n,r]=[r,n]);for(let e=0;e<i.length;e+=1)if(s.get(e.toString())&&l[e]!==i[e]){const s=X(t.concat([e]),o);n.push({op:j,path:s,value:J(l[e])}),r.push({op:j,path:s,value:J(i[e])})}for(let e=i.length;e<l.length;e+=1){const r=X(t.concat([e]),o);n.push({op:S,path:r,value:J(l[e])})}if(i.length<l.length){const{arrayLengthAssignment:e=!0}=a.enablePatches;if(e){const e=X(t.concat(["length"]),o);r.push({op:j,path:e,value:i.length})}else for(let e=l.length;i.length<e;e-=1){const n=X(t.concat([e-1]),o);r.push({op:E,path:n})}}}(e,t,n,r,o);case 3:return function({original:e,copy:t},n,r,o,i){let s=0;e.forEach((e=>{if(!t.has(e)){const t=X(n.concat([s]),i);r.push({op:E,path:t,value:e}),o.unshift({op:S,path:t,value:e})}s+=1})),s=0,t.forEach((t=>{if(!e.has(t)){const e=X(n.concat([s]),i);r.push({op:S,path:e,value:t}),o.unshift({op:E,path:e,value:t})}s+=1}))}(e,t,n,r,o)}}const ce=(e,t,n=!1)=>{if("object"==typeof e&&null!==e&&(!V(e,t)||n))throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")},ue={get size(){return _(N(this)).size},has(e){return _(N(this)).has(e)},set(e,t){const n=N(this),r=_(n);return r.has(e)&&B(r.get(e),t)||(G(n),Q(n),n.assignedMap.set(e,!0),n.copy.set(e,t),ae(n,e,t,le)),this},delete(e){if(!this.has(e))return!1;const t=N(this);return G(t),Q(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){const e=N(this);if(this.size){G(e),Q(e),e.assignedMap=new Map;for(const[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){_(N(this)).forEach(((n,r)=>{e.call(t,this.get(r),r,this)}))},get(e){var t,n;const r=N(this),o=_(r).get(e),i=(null===(n=(t=r.options).mark)||void 0===n?void 0:n.call(t,o,P))===P.mutable;if(r.options.strict&&ce(o,r.options,i),i)return o;if(r.finalized||!V(o,r.options))return o;if(o!==r.original.get(e))return o;const s=x.createDraft({original:o,parentDraft:r,key:e,finalities:r.finalities,options:r.options});return G(r),r.copy.set(e,s),s},keys(){return _(N(this)).keys()},values(){const e=this.keys();return{[A]:()=>this.values(),next:()=>{const t=e.next();if(t.done)return t;return{done:!1,value:this.get(t.value)}}}},entries(){const e=this.keys();return{[A]:()=>this.entries(),next:()=>{const t=e.next();if(t.done)return t;const n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[A](){return this.entries()}},pe=Reflect.ownKeys(ue),fe=(e,t,{isValuesIterator:n})=>()=>{var r,o;const i=t.next();if(i.done)return i;const s=i.value;let a=e.setMap.get(s);const l=N(a),c=(null===(o=(r=e.options).mark)||void 0===o?void 0:o.call(r,a,P))===P.mutable;if(e.options.strict&&ce(s,e.options,c),c||l||!V(s,e.options)||e.finalized||!e.original.has(s))l&&(a=l.proxy);else{const t=x.createDraft({original:s,parentDraft:e,key:s,finalities:e.finalities,options:e.options});e.setMap.set(s,t),a=t}return{done:!1,value:n?a:[a,a]}},he={get size(){return N(this).setMap.size},has(e){const t=N(this);if(t.setMap.has(e))return!0;G(t);const n=N(e);return!(!n||!t.setMap.has(n.original))},add(e){const t=N(this);return this.has(e)||(G(t),Q(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),ae(t,e,e,le)),this},delete(e){if(!this.has(e))return!1;const t=N(this);G(t),Q(t);const n=N(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;const e=N(this);G(e),Q(e);for(const t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){const e=N(this);G(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:fe(e,t,{isValuesIterator:!0})}},entries(){const e=N(this);G(e);const t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:fe(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[A](){return this.values()},forEach(e,t){const n=this.values();let r=n.next();for(;!r.done;)e.call(t,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(he,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const de=Reflect.ownKeys(he),ye=new WeakSet,ge={get(e,t,n){var r,o;const i=null===(r=e.copy)||void 0===r?void 0:r[t];if(i&&ye.has(i))return i;if(t===k)return e;let s;if(e.options.mark){const r="size"===t&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(s=e.options.mark(r,P),s===P.mutable)return e.options.strict&&ce(r,e.options,!0),r}const a=_(e);if(a instanceof Map&&pe.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(ue,"size").get.call(e.proxy);const n=ue[t];if(n)return n.bind(e.proxy)}if(a instanceof Set&&de.includes(t)){if("size"===t)return Object.getOwnPropertyDescriptor(he,"size").get.call(e.proxy);const n=he[t];if(n)return n.bind(e.proxy)}if(!C(a,t)){const n=z(a,t);return n?"value"in n?n.value:null===(o=n.get)||void 0===o?void 0:o.call(e.proxy):void 0}const l=a[t];if(e.options.strict&&ce(l,e.options),e.finalized||!V(l,e.options))return l;if(l===W(e.original,t)){if(G(e),e.copy[t]=ve({original:e.original[t],parentDraft:e,key:1===e.type?Number(t):t,finalities:e.finalities,options:e.options}),"function"==typeof s){const n=N(e.copy[t]);return G(n),Q(n),n.copy}return e.copy[t]}return l},set(e,t,n){var r;if(3===e.type||2===e.type)throw new Error("Map/Set draft does not support any property assignment.");let o;if(1===e.type&&"length"!==t&&(!(Number.isInteger(o=Number(t))&&o>=0)||0!==t&&0!==o&&String(o)!==String(t)))throw new Error("Only supports setting array indices and the 'length' property.");const i=z(_(e),t);if(null==i?void 0:i.set)return i.set.call(e.proxy,n),!0;const s=W(_(e),t),a=N(s);return a&&B(a.original,n)?(e.copy[t]=n,e.assignedMap=null!==(r=e.assignedMap)&&void 0!==r?r:new Map,e.assignedMap.set(t,!1),!0):(B(n,s)&&(void 0!==n||C(e.original,t))||(G(e),Q(e),C(e.original,t)&&B(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,ae(e,t,n,le)),!0)},has:(e,t)=>t in _(e),ownKeys:e=>Reflect.ownKeys(_(e)),getOwnPropertyDescriptor(e,t){const n=_(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.type||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},getPrototypeOf:e=>Reflect.getPrototypeOf(e.original),setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty(e,t){var n;return 1===e.type?ge.set.call(this,e,t,void 0,e.proxy):(void 0!==W(e.original,t)||t in e.original?(G(e),Q(e),e.assignedMap.set(t,!1)):(e.assignedMap=null!==(n=e.assignedMap)&&void 0!==n?n:new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function ve(e){const{original:t,parentDraft:n,key:r,finalities:o,options:i}=e,s=q(t),a={type:s,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:o,options:i,setMap:3===s?new Map(t.entries()):void 0};(r||"key"in e)&&(a.key=r);const{proxy:l,revoke:c}=Proxy.revocable(1===s?Object.assign([],a):a,ge);if(o.revoke.push(c),ye.add(l),a.proxy=l,n){const e=n;e.finalities.draft.push(((t,n)=>{var o,i;const s=N(l);let a=3===e.type?e.setMap:e.copy;const c=$(a,r),u=N(c);if(u){let i=u.original;u.operated&&(i=F(c)),ie(u),se(u,le,t,n),e.options.enableAutoFreeze&&(e.options.updatedValues=null!==(o=e.options.updatedValues)&&void 0!==o?o:new WeakMap,e.options.updatedValues.set(i,u.original)),U(a,r,i)}null===(i=s.callbacks)||void 0===i||i.forEach((e=>{e(t,n)}))}))}else{const e=N(l);e.finalities.draft.push(((t,n)=>{ie(e),se(e,le,t,n)}))}return l}function me(e,t,n,r,o){var i;const s=N(e),a=null!==(i=null==s?void 0:s.original)&&void 0!==i?i:e,l=!!t.length;if(null==s?void 0:s.operated)for(;s.finalities.draft.length>0;){s.finalities.draft.pop()(n,r)}const c=l?t[0]:s?s.operated?s.copy:s.original:e;return s&&K(s),o&&te(c,c,null==s?void 0:s.options.updatedValues),[c,n&&l?[{op:j,path:[],value:t[0]}]:n,r&&l?[{op:j,path:[],value:a}]:r]}function be(e){const{rootDraft:t,value:n,useRawReturn:r=!1,isRoot:o=!0}=e;ne(n,((n,r,o)=>{const i=N(r);if(i&&t&&i.finalities===t.finalities){e.isContainDraft=!0;const t=i.original;if(o instanceof Set){const e=Array.from(o);o.clear(),e.forEach((e=>o.add(n===e?t:e)))}else U(o,n,t)}else"object"==typeof r&&null!==r&&(e.value=r,e.isRoot=!1,be(e))})),o&&(e.isContainDraft||console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance."),r&&console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value."))}function we(e){var t;const n=N(e);if(!V(e,null==n?void 0:n.options))return e;const r=q(e);if(n&&!n.operated)return n.original;let o;function i(){o=2===r?T(e)?new Map(e):new(Object.getPrototypeOf(e).constructor)(e):3===r?Array.from(n.setMap.values()):Y(e,null==n?void 0:n.options)}if(n){n.finalized=!0;try{i()}finally{n.finalized=!1}}else o=e;if(ne(o,((t,r)=>{if(n&&B($(n.original,t),r))return;const s=we(r);s!==r&&(o===e&&i(),U(o,t,s))})),3===r){const e=null!==(t=null==n?void 0:n.original)&&void 0!==t?t:o;return D(e)?new Set(o):new(Object.getPrototypeOf(e).constructor)(o)}return o}function Oe(e){if(!I(e))throw new Error(`current() is only used for Draft, parameter: ${e}`);return we(e)}x.createDraft=ve;const Me=function e(t,n,r){var o,i,s;if("function"==typeof t&&"function"!=typeof n)return function(r,...o){return e(r,(e=>t.call(this,e,...o)),n)};const a=t,l=n;let c=r;if("function"!=typeof n&&(c=n),void 0!==c&&"[object Object]"!==Object.prototype.toString.call(c))throw new Error(`Invalid options: ${c}, 'options' should be an object.`);c=Object.assign(Object.assign({},Ee),c);const u=I(a)?Oe(a):a,p=Array.isArray(c.mark)?(e,t)=>{for(const n of c.mark){if("function"!=typeof n)throw new Error(`Invalid mark: ${n}, 'mark' should be a function.`);const r=n(e,t);if(r)return r}}:c.mark,f=null!==(o=c.enablePatches)&&void 0!==o&&o,h=null!==(i=c.strict)&&void 0!==i&&i,d={enableAutoFreeze:null!==(s=c.enableAutoFreeze)&&void 0!==s&&s,mark:p,strict:h,enablePatches:f};if(!V(u,d)&&"object"==typeof u&&null!==u)throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");const[y,g]=function(e,t){var n;const r={draft:[],revoke:[],handledSet:new WeakSet};let o,i;t.enablePatches&&(o=[],i=[]);const s=(null===(n=t.mark)||void 0===n?void 0:n.call(t,e,P))!==P.mutable&&V(e,t)?ve({original:e,parentDraft:null,finalities:r,options:t}):e;return[s,(e=[])=>{const[n,r,a]=me(s,e,o,i,t.enableAutoFreeze);return t.enablePatches?[n,r,a]:n}]}(u,d);if("function"!=typeof n){if(!V(u,d))throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");return[y,g]}let v;try{v=l(y)}catch(e){throw K(N(y)),e}const m=e=>{const t=N(y);if(!I(e)){if(void 0!==e&&!B(e,y)&&(null==t?void 0:t.operated))throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");const n=null==e?void 0:e[R];if(n){const r=n[0];return d.strict&&"object"==typeof e&&null!==e&&be({rootDraft:t,value:e,useRawReturn:!0}),g([r])}if(void 0!==e)return"object"==typeof e&&null!==e&&be({rootDraft:t,value:e}),g([e])}if(e===y||void 0===e)return g([]);const n=N(e);if(d===n.options){if(n.operated)throw new Error("Cannot return a modified child draft.");return g([Oe(e)])}return g([e])};return v instanceof Promise?v.then(m,(e=>{throw K(N(y)),e})):m(v)};var Ee;Object.prototype.constructor.toString();class je{constructor(e,t=null){this.value=e,this.reactor=t??new O(this,[])}produce(e){return n=e,void(t=this).set(Me(t.get(),n));var t,n}reducer(...e){let t;return t=1===e.length?new M(this,"",e[0]):new M(this,e[0],e[1]),t.trigger.bind(t)}setObjectByPath(e="",t){if(0==e.length)return void(this.value=t);if("string"!=typeof e||!e)throw new Error("Invalid path");let n=e.split("."),r=this.value;for(let e=0;e<n.length-1;e++){let t=n[e];t in r||(r[t]={}),r=r[t]}r[n[n.length-1]]=t}set(...e){if(1===e.length)this.value=e[0];else{let t=e[0],n=e[1];this.setObjectByPath(t,n)}this.reactor.react()}get(){return this.value}}class Se{constructor(e){this.target=e}set html(e){this.target.innerHTML=e}query(e){return this.target.querySelectorAll(e)}set text(e){this.target.textContent=e}on(e,t){this.target.addEventListener(e,t)}off(e,t){this.target.removeEventListener(e,t)}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class ke{constructor(e){this.target=e}query(e){return this.target.querySelectorAll(e)}index(e){return Array.from(this.target.children)[e]}list(){return Array.from(this.target.children)}get parent(){return this.target}remove(){this.target.remove()}addChild(e){this.target.appendChild(e)}set(e){this.target=e}}class Re{constructor(e){this.target=e}set(e){this.target=e,e.setRef(this)}}return e.RumiousApp=class{constructor(e=document.createElement("span"),n={}){this.root=e,this.configs=n,this.renderContext=new t(this)}render(e){w(e,this.root,this.renderContext)}},e.RumiousChildrensRef=ke,e.RumiousComponent=n,e.RumiousComponentElement=y,e.RumiousComponentRef=Re,e.RumiousElementRef=Se,e.RumiousState=je,e.createChildrensRef=function(e){return new ke(e)},e.createComponentElement=g,e.createComponentRef=function(e){return new Re(e)},e.createElementRef=function(e){return new Se(e)},e.createState=function(e){return new je(e)},e.isComponent=r,e.isState=function(e){return e instanceof je},e.watcher=function(e,t){e.reactor.addBinding(t)},e}({});