rumious 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,8 +12,33 @@ function _assertThisInitialized(e) {
12
12
  if (undefined === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
13
13
  return e;
14
14
  }
15
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
16
+ try {
17
+ var i = n[a](c),
18
+ u = i.value;
19
+ } catch (n) {
20
+ return void e(n);
21
+ }
22
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
23
+ }
24
+ function _asyncToGenerator(n) {
25
+ return function () {
26
+ var t = this,
27
+ e = arguments;
28
+ return new Promise(function (r, o) {
29
+ var a = n.apply(t, e);
30
+ function _next(n) {
31
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
32
+ }
33
+ function _throw(n) {
34
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
35
+ }
36
+ _next(undefined);
37
+ });
38
+ };
39
+ }
15
40
  function _callSuper(t, o, e) {
16
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
41
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
17
42
  }
18
43
  function _classCallCheck(a, n) {
19
44
  if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
@@ -36,6 +61,54 @@ function _createClass(e, r, t) {
36
61
  writable: false
37
62
  }), e;
38
63
  }
64
+ function _createForOfIteratorHelper(r, e) {
65
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
66
+ if (!t) {
67
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
68
+ t && (r = t);
69
+ var n = 0,
70
+ F = function () {};
71
+ return {
72
+ s: F,
73
+ n: function () {
74
+ return n >= r.length ? {
75
+ done: true
76
+ } : {
77
+ done: false,
78
+ value: r[n++]
79
+ };
80
+ },
81
+ e: function (r) {
82
+ throw r;
83
+ },
84
+ f: F
85
+ };
86
+ }
87
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
88
+ }
89
+ var o,
90
+ a = true,
91
+ u = false;
92
+ return {
93
+ s: function () {
94
+ t = t.call(r);
95
+ },
96
+ n: function () {
97
+ var r = t.next();
98
+ return a = r.done, r;
99
+ },
100
+ e: function (r) {
101
+ u = true, o = r;
102
+ },
103
+ f: function () {
104
+ try {
105
+ a || null == t.return || t.return();
106
+ } finally {
107
+ if (u) throw o;
108
+ }
109
+ }
110
+ };
111
+ }
39
112
  function _defineProperty(e, r, t) {
40
113
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
41
114
  value: t,
@@ -87,7 +160,10 @@ function _iterableToArrayLimit(r, l) {
87
160
  f = true,
88
161
  o = false;
89
162
  try {
90
- if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
163
+ if (i = (t = t.call(r)).next, 0 === l) {
164
+ if (Object(t) !== t) return;
165
+ f = !1;
166
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
91
167
  } catch (r) {
92
168
  o = true, n = r;
93
169
  } finally {
@@ -129,6 +205,307 @@ function _possibleConstructorReturn(t, e) {
129
205
  if (undefined !== e) throw new TypeError("Derived constructors may only return object or undefined");
130
206
  return _assertThisInitialized(t);
131
207
  }
208
+ function _regeneratorRuntime() {
209
+ _regeneratorRuntime = function () {
210
+ return e;
211
+ };
212
+ var t,
213
+ e = {},
214
+ r = Object.prototype,
215
+ n = r.hasOwnProperty,
216
+ o = Object.defineProperty || function (t, e, r) {
217
+ t[e] = r.value;
218
+ },
219
+ i = "function" == typeof Symbol ? Symbol : {},
220
+ a = i.iterator || "@@iterator",
221
+ c = i.asyncIterator || "@@asyncIterator",
222
+ u = i.toStringTag || "@@toStringTag";
223
+ function define(t, e, r) {
224
+ return Object.defineProperty(t, e, {
225
+ value: r,
226
+ enumerable: true,
227
+ configurable: true,
228
+ writable: true
229
+ }), t[e];
230
+ }
231
+ try {
232
+ define({}, "");
233
+ } catch (t) {
234
+ define = function (t, e, r) {
235
+ return t[e] = r;
236
+ };
237
+ }
238
+ function wrap(t, e, r, n) {
239
+ var i = e && e.prototype instanceof Generator ? e : Generator,
240
+ a = Object.create(i.prototype),
241
+ c = new Context(n || []);
242
+ return o(a, "_invoke", {
243
+ value: makeInvokeMethod(t, r, c)
244
+ }), a;
245
+ }
246
+ function tryCatch(t, e, r) {
247
+ try {
248
+ return {
249
+ type: "normal",
250
+ arg: t.call(e, r)
251
+ };
252
+ } catch (t) {
253
+ return {
254
+ type: "throw",
255
+ arg: t
256
+ };
257
+ }
258
+ }
259
+ e.wrap = wrap;
260
+ var h = "suspendedStart",
261
+ l = "suspendedYield",
262
+ f = "executing",
263
+ s = "completed",
264
+ y = {};
265
+ function Generator() {}
266
+ function GeneratorFunction() {}
267
+ function GeneratorFunctionPrototype() {}
268
+ var p = {};
269
+ define(p, a, function () {
270
+ return this;
271
+ });
272
+ var d = Object.getPrototypeOf,
273
+ v = d && d(d(values([])));
274
+ v && v !== r && n.call(v, a) && (p = v);
275
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
276
+ function defineIteratorMethods(t) {
277
+ ["next", "throw", "return"].forEach(function (e) {
278
+ define(t, e, function (t) {
279
+ return this._invoke(e, t);
280
+ });
281
+ });
282
+ }
283
+ function AsyncIterator(t, e) {
284
+ function invoke(r, o, i, a) {
285
+ var c = tryCatch(t[r], t, o);
286
+ if ("throw" !== c.type) {
287
+ var u = c.arg,
288
+ h = u.value;
289
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
290
+ invoke("next", t, i, a);
291
+ }, function (t) {
292
+ invoke("throw", t, i, a);
293
+ }) : e.resolve(h).then(function (t) {
294
+ u.value = t, i(u);
295
+ }, function (t) {
296
+ return invoke("throw", t, i, a);
297
+ });
298
+ }
299
+ a(c.arg);
300
+ }
301
+ var r;
302
+ o(this, "_invoke", {
303
+ value: function (t, n) {
304
+ function callInvokeWithMethodAndArg() {
305
+ return new e(function (e, r) {
306
+ invoke(t, n, e, r);
307
+ });
308
+ }
309
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
310
+ }
311
+ });
312
+ }
313
+ function makeInvokeMethod(e, r, n) {
314
+ var o = h;
315
+ return function (i, a) {
316
+ if (o === f) throw Error("Generator is already running");
317
+ if (o === s) {
318
+ if ("throw" === i) throw a;
319
+ return {
320
+ value: t,
321
+ done: true
322
+ };
323
+ }
324
+ for (n.method = i, n.arg = a;;) {
325
+ var c = n.delegate;
326
+ if (c) {
327
+ var u = maybeInvokeDelegate(c, n);
328
+ if (u) {
329
+ if (u === y) continue;
330
+ return u;
331
+ }
332
+ }
333
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
334
+ if (o === h) throw o = s, n.arg;
335
+ n.dispatchException(n.arg);
336
+ } else "return" === n.method && n.abrupt("return", n.arg);
337
+ o = f;
338
+ var p = tryCatch(e, r, n);
339
+ if ("normal" === p.type) {
340
+ if (o = n.done ? s : l, p.arg === y) continue;
341
+ return {
342
+ value: p.arg,
343
+ done: n.done
344
+ };
345
+ }
346
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
347
+ }
348
+ };
349
+ }
350
+ function maybeInvokeDelegate(e, r) {
351
+ var n = r.method,
352
+ o = e.iterator[n];
353
+ 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;
354
+ var i = tryCatch(o, e.iterator, r.arg);
355
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
356
+ var a = i.arg;
357
+ 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);
358
+ }
359
+ function pushTryEntry(t) {
360
+ var e = {
361
+ tryLoc: t[0]
362
+ };
363
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
364
+ }
365
+ function resetTryEntry(t) {
366
+ var e = t.completion || {};
367
+ e.type = "normal", delete e.arg, t.completion = e;
368
+ }
369
+ function Context(t) {
370
+ this.tryEntries = [{
371
+ tryLoc: "root"
372
+ }], t.forEach(pushTryEntry, this), this.reset(true);
373
+ }
374
+ function values(e) {
375
+ if (e || "" === e) {
376
+ var r = e[a];
377
+ if (r) return r.call(e);
378
+ if ("function" == typeof e.next) return e;
379
+ if (!isNaN(e.length)) {
380
+ var o = -1,
381
+ i = function next() {
382
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = false, next;
383
+ return next.value = t, next.done = true, next;
384
+ };
385
+ return i.next = i;
386
+ }
387
+ }
388
+ throw new TypeError(typeof e + " is not iterable");
389
+ }
390
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
391
+ value: GeneratorFunctionPrototype,
392
+ configurable: true
393
+ }), o(GeneratorFunctionPrototype, "constructor", {
394
+ value: GeneratorFunction,
395
+ configurable: true
396
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
397
+ var e = "function" == typeof t && t.constructor;
398
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
399
+ }, e.mark = function (t) {
400
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
401
+ }, e.awrap = function (t) {
402
+ return {
403
+ __await: t
404
+ };
405
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
406
+ return this;
407
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
408
+ undefined === i && (i = Promise);
409
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
410
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
411
+ return t.done ? t.value : a.next();
412
+ });
413
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
414
+ return this;
415
+ }), define(g, "toString", function () {
416
+ return "[object Generator]";
417
+ }), e.keys = function (t) {
418
+ var e = Object(t),
419
+ r = [];
420
+ for (var n in e) r.push(n);
421
+ return r.reverse(), function next() {
422
+ for (; r.length;) {
423
+ var t = r.pop();
424
+ if (t in e) return next.value = t, next.done = false, next;
425
+ }
426
+ return next.done = true, next;
427
+ };
428
+ }, e.values = values, Context.prototype = {
429
+ constructor: Context,
430
+ reset: function (e) {
431
+ 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);
432
+ },
433
+ stop: function () {
434
+ this.done = true;
435
+ var t = this.tryEntries[0].completion;
436
+ if ("throw" === t.type) throw t.arg;
437
+ return this.rval;
438
+ },
439
+ dispatchException: function (e) {
440
+ if (this.done) throw e;
441
+ var r = this;
442
+ function handle(n, o) {
443
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
444
+ }
445
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
446
+ var i = this.tryEntries[o],
447
+ a = i.completion;
448
+ if ("root" === i.tryLoc) return handle("end");
449
+ if (i.tryLoc <= this.prev) {
450
+ var c = n.call(i, "catchLoc"),
451
+ u = n.call(i, "finallyLoc");
452
+ if (c && u) {
453
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, true);
454
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
455
+ } else if (c) {
456
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, true);
457
+ } else {
458
+ if (!u) throw Error("try statement without catch or finally");
459
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
460
+ }
461
+ }
462
+ }
463
+ },
464
+ abrupt: function (t, e) {
465
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
466
+ var o = this.tryEntries[r];
467
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
468
+ var i = o;
469
+ break;
470
+ }
471
+ }
472
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
473
+ var a = i ? i.completion : {};
474
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
475
+ },
476
+ complete: function (t, e) {
477
+ if ("throw" === t.type) throw t.arg;
478
+ 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;
479
+ },
480
+ finish: function (t) {
481
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
482
+ var r = this.tryEntries[e];
483
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
484
+ }
485
+ },
486
+ catch: function (t) {
487
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
488
+ var r = this.tryEntries[e];
489
+ if (r.tryLoc === t) {
490
+ var n = r.completion;
491
+ if ("throw" === n.type) {
492
+ var o = n.arg;
493
+ resetTryEntry(r);
494
+ }
495
+ return o;
496
+ }
497
+ }
498
+ throw Error("illegal catch attempt");
499
+ },
500
+ delegateYield: function (e, r, n) {
501
+ return this.delegate = {
502
+ iterator: values(e),
503
+ resultName: r,
504
+ nextLoc: n
505
+ }, "next" === this.method && (this.arg = t), y;
506
+ }
507
+ }, e;
508
+ }
132
509
  function _setPrototypeOf(t, e) {
133
510
  return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
134
511
  return t.__proto__ = e, t;
@@ -190,27 +567,145 @@ function _wrapNativeSuper(t) {
190
567
  }, _wrapNativeSuper(t);
191
568
  }
192
569
 
193
- var RumiousRenderContext=/*#__PURE__*/_createClass(function RumiousRenderContext(target){_classCallCheck(this,RumiousRenderContext);this.target=target;});
570
+ var RumiousRenderContext=/*#__PURE__*/function(){function RumiousRenderContext(target){_classCallCheck(this,RumiousRenderContext);this.target=target;}return _createClass(RumiousRenderContext,[{key:"find",value:function find(name){return this.target[name]}},{key:"get",value:function get(name){return this.target[name]}}])}();
194
571
 
195
- var RumiousComponent=/*#__PURE__*/function(){function RumiousComponent(){_classCallCheck(this,RumiousComponent);this.element=null;this.props={};this.renderContext=new RumiousRenderContext(this);this.renderer=null;this.wrapped=null;}return _createClass(RumiousComponent,[{key:"prepare",value:function prepare(element,props){var wrapped=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var renderer=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;this.element=element;this.props=props;this.renderer=renderer;this.wrapped=wrapped;}},{key:"template",value:function template(){return {}}},{key:"requestRender",value:function requestRender(){var template=this.template();var fragment=this.renderer(template,document.createDocumentFragment(),this.renderContext);this.element.appendChild(fragment);this.onRender();}},{key:"onCreate",value:function onCreate(){}},{key:"onRender",value:function onRender(){}},{key:"onUpdate",value:function onUpdate(){}},{key:"onDestroy",value:function onDestroy(){}}])}();function isComponent(constructor){return Object.getPrototypeOf(constructor)===RumiousComponent}
572
+ var RumiousComponent=/*#__PURE__*/function(){function RumiousComponent(){_classCallCheck(this,RumiousComponent);this.element=null;this.props={};this.renderContext=new RumiousRenderContext(this);this.renderer=null;this.wrapped=null;}return _createClass(RumiousComponent,[{key:"prepare",value:function prepare(element,props){var wrapped=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var renderer=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;this.element=element;this.props=props;this.renderer=renderer;this.wrapped=wrapped;}},{key:"template",value:function template(){return {}}},{key:"requestRender",value:function requestRender(){var template=this.template();var fragment=this.renderer(template,document.createDocumentFragment(),this.renderContext);this.element.appendChild(fragment);this.onRender();}},{key:"requestCleanUp",value:function(){var _requestCleanUp=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(){var cloned;return _regeneratorRuntime().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(this.element){cloned=this.element.cloneNode(true);this.element.replaceWith(cloned);this.element=cloned;while(this.element.firstChild){this.element.removeChild(this.element.firstChild);}}case 1:case "end":return _context.stop()}},_callee,this)}));function requestCleanUp(){return _requestCleanUp.apply(this,arguments)}return requestCleanUp}()},{key:"onInit",value:function onInit(){}},{key:"onCreate",value:function onCreate(){}},{key:"onRender",value:function onRender(){}},{key:"onUpdate",value:function onUpdate(){}},{key:"onDestroy",value:function onDestroy(){}}])}();function isComponent(component){return Object.getPrototypeOf(component)===RumiousComponent}
196
573
 
197
574
  var RumiousElement=/*#__PURE__*/_createClass(function RumiousElement(type,props){var children=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];_classCallCheck(this,RumiousElement);this.type=type;this.props=props;this.children=children;});var RumiousElementList=/*#__PURE__*/function(){function RumiousElementList(list){_classCallCheck(this,RumiousElementList);this.type="ELEMENT_LIST";this.children=list;}return _createClass(RumiousElementList,[{key:"forEach",value:function forEach(callback){this.children.forEach(callback);}}])}();
198
575
 
199
- function createElement(type,props){for(var _len=arguments.length,children=new Array(_len>2?_len-2:0),_key=2;_key<_len;_key++){children[_key-2]=arguments[_key];}if(isComponent(type)){return createComponent(type,props,children)}if(type===createFragment){return createFragment.apply(undefined,children)}return new RumiousElement(type,props||{},normalizeChildren(children))}function createTextElement(text){return new RumiousElement("TEXT_ELEMENT",{nodeValue:text},[])}function createComponent(type,props,children){return new RumiousElement("COMPONENT",_objectSpread2({component:type},props),new RumiousElementList(normalizeChildren(children)))}function createFragment(){for(var _len2=arguments.length,children=new Array(_len2),_key2=0;_key2<_len2;_key2++){children[_key2]=arguments[_key2];}return new RumiousElement("FRAGMENT",{},normalizeChildren(children))}function normalizeChildren(children){return children.map(function(child){return _typeof(child)==="object"?child:createTextElement(child)})}window.RUMIOUS_JSX_SUPPORT={createElement:createElement,createFragment:createFragment};
576
+ function isCamelCase(str){var camelCaseRegex=/^[a-zA-Z]+([A-Z][a-z]*)*$/;return camelCaseRegex.test(str)}function isFunction(object){return typeof object==="function"}
577
+
578
+ var RumiousDirective=/*#__PURE__*/function(){function RumiousDirective(type,name,value){_classCallCheck(this,RumiousDirective);this.type=type;this.name=name;this.value=value;}return _createClass(RumiousDirective,[{key:"init",value:function init(){console.warn("Directive haven't handler !");}}])}();var RumiousEventBindingDirective=/*#__PURE__*/function(_RumiousDirective){function RumiousEventBindingDirective(){_classCallCheck(this,RumiousEventBindingDirective);return _callSuper(this,RumiousEventBindingDirective,arguments)}_inherits(RumiousEventBindingDirective,_RumiousDirective);return _createClass(RumiousEventBindingDirective,[{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(dom,renderContext){var _this=this;var fn,getHandler;return _regeneratorRuntime().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:fn=null;getHandler=function getHandler(value){if(!renderContext.find(value)){console.warn("Missing event handler for event: ".concat(_this.name));return null}var handler=renderContext.get(value);if(!isFunction(handler)){throw "".concat(value," is not a function!")}return handler.bind(renderContext.target)};if(!(this.value.type==="string")){_context.next=6;break}fn=getHandler(this.value.value);_context.next=13;break;case 6:if(!(this.value.type==="expression")){_context.next=12;break}fn=this.value.value;if(isFunction(fn)){_context.next=10;break}throw "Event handler requires a function!";case 10:_context.next=13;break;case 12:if(this.value.type==="dynamic_value"){fn=getHandler(this.value.value.objectName);}case 13:if(fn){dom.addEventListener(this.name,fn);}case 14:case "end":return _context.stop()}},_callee,this)}));function init(_x,_x2){return _init.apply(this,arguments)}return init}()}])}(RumiousDirective);var RumiousPropsBindingDirective=/*#__PURE__*/function(_RumiousDirective2){function RumiousPropsBindingDirective(){_classCallCheck(this,RumiousPropsBindingDirective);return _callSuper(this,RumiousPropsBindingDirective,arguments)}_inherits(RumiousPropsBindingDirective,_RumiousDirective2);return _createClass(RumiousPropsBindingDirective,[{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(dom,renderContext){var _this2=this;var _this$value$evaluator,_this$value,currentStateValue,currentState;return _regeneratorRuntime().wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:if(!(this.value.type==="expression")){_context2.next=4;break}_context2.next=13;break;case 4:if(!(this.value.type==="dynamic_value")){_context2.next=13;break}currentStateValue=(_this$value$evaluator=(_this$value=this.value).evaluator)===null||_this$value$evaluator===undefined?undefined:_this$value$evaluator.call(_this$value,renderContext.target);currentState=renderContext.find(this.value.value.objectName);if(currentState){_context2.next=11;break}throw "Invalid props value: Directive bind: require a RumiousState Object !";case 11:currentState.reactor.addBinding(function(){var _this2$value$evaluato,_this2$value;var currentStateValue=(_this2$value$evaluato=(_this2$value=_this2.value).evaluator)===null||_this2$value$evaluato===undefined?undefined:_this2$value$evaluato.call(_this2$value,renderContext.target);_this2.bindAttr(dom,currentStateValue);});case 12:this.bindAttr(dom,currentStateValue);case 13:case "end":return _context2.stop()}},_callee2,this)}));function init(_x3,_x4){return _init2.apply(this,arguments)}return init}()},{key:"normalizeValue",value:function normalizeValue(value){if(_typeof(value)==="object"){var _value$toString,_value$toString2;return (_value$toString=(_value$toString2=value.toString)===null||_value$toString2===undefined?undefined:_value$toString2.call(value))!==null&&_value$toString!==undefined?_value$toString:""}return value}},{key:"bindAttr",value:function(){var _bindAttr=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(dom,value){return _regeneratorRuntime().wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:_context3.t0=this.name;_context3.next=_context3.t0==="html"?3:5;break;case 3:dom.innerHTML=this.normalizeValue(value);return _context3.abrupt("break",5);case 5:case "end":return _context3.stop()}},_callee3,this)}));function bindAttr(_x5,_x6){return _bindAttr.apply(this,arguments)}return bindAttr}()}])}(RumiousDirective);var directives={on:function on(event,value){return new RumiousEventBindingDirective("on",event,value)},bind:function bind(attr,value){return new RumiousPropsBindingDirective("bind",attr,value)}};function registerDirective(type,name,value){var _directives$type;return (_directives$type=directives[type])===null||_directives$type===undefined?undefined:_directives$type.call(directives,name,value)}
200
579
 
201
- function isCamelCase(str){var camelCaseRegex=/^[a-z]+([A-Z][a-z]*)*$/;return camelCaseRegex.test(str)}
580
+ function createDirective(type,name,value){return registerDirective(type,name,value)}function createElement(type,props){for(var _len=arguments.length,children=new Array(_len>2?_len-2:0),_key=2;_key<_len;_key++){children[_key-2]=arguments[_key];}if(isComponent(type)){return createComponent(type,props,children)}if(type===createFragment){return createFragment.apply(undefined,children)}return new RumiousElement(type,props||{},normalizeChildren(children))}function createTextElement(text){return new RumiousElement("TEXT_ELEMENT",{nodeValue:text},[])}function createComponent(type,props,children){return new RumiousElement("COMPONENT",_objectSpread2({component:type},props),new RumiousElementList(normalizeChildren(children)))}function createFragment(){for(var _len2=arguments.length,children=new Array(_len2),_key2=0;_key2<_len2;_key2++){children[_key2]=arguments[_key2];}return new RumiousElement("FRAGMENT",{},normalizeChildren(children))}function normalizeChildren(children){return children.map(function(child){return _typeof(child)==="object"?child:createTextElement(child)})}window.RUMIOUS_JSX_SUPPORT={createElement:createElement,createFragment:createFragment,createDirective:createDirective};
202
581
 
203
- var RumiousComponentElement=/*#__PURE__*/function(_HTMLElement){function RumiousComponentElement(){var _this;_classCallCheck(this,RumiousComponentElement);_this=_callSuper(this,RumiousComponentElement);_this.instance=null;return _this}_inherits(RumiousComponentElement,_HTMLElement);return _createClass(RumiousComponentElement,[{key:"init",value:function init(componentConstructor,props){var wrapped=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var renderer=arguments.length>3?arguments[3]:undefined;this.instance=new componentConstructor;this.instance.prepare(this,props,wrapped,renderer);}},{key:"connectedCallback",value:function connectedCallback(){this.instance.onCreate();this.instance.requestRender();}}])}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));function createComponentElement(){return document.createElement("a-component")}window.customElements.define("a-component",RumiousComponentElement);
582
+ var RumiousComponentElement=/*#__PURE__*/function(_HTMLElement){function RumiousComponentElement(){var _this;_classCallCheck(this,RumiousComponentElement);_this=_callSuper(this,RumiousComponentElement);_this.instance=null;return _this}_inherits(RumiousComponentElement,_HTMLElement);return _createClass(RumiousComponentElement,[{key:"init",value:function init(componentConstructor,props){var wrapped=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var renderer=arguments.length>3?arguments[3]:undefined;this.instance=new componentConstructor;this.instance.prepare(this,props,wrapped,renderer);this.instance.onInit();}},{key:"connectedCallback",value:function connectedCallback(){this.instance.onCreate();this.instance.requestRender();}},{key:"disconnectCallback",value:function disconnectCallback(){this.instance.onDestroy();this.instance.requestCleanUp();}}])}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));function createComponentElement(){return document.createElement("a-component")}window.customElements.define("a-component",RumiousComponentElement);
204
583
 
205
584
  function renderComponent(componentConstructor,props,wrapped,renderer){var componentElement=createComponentElement();componentElement.init(componentConstructor,props,wrapped,renderer);return componentElement}
206
585
 
207
- function render(element,container){var renderContext=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};if(!element)return container;var dom;if(element.type==="COMPONENT"){dom=renderComponent(element.props.component,element.props,element.children,render);container.appendChild(dom);return container}if(element.type==="FRAGMENT"||element.type==="ELEMENT_LIST"){element.children.forEach(function(child){return render(child,container,renderContext)});return container}if(element.type==="TEXT_ELEMENT"){dom=document.createTextNode(element.props.nodeValue);}else {dom=document.createElement(element.type);}Object.entries(element.props||{}).forEach(function(_ref){var _ref2=_slicedToArray(_ref,2),name=_ref2[0],value=_ref2[1];if(name==="ref"){var _renderContext$addRef;(_renderContext$addRef=renderContext.addRef)===null||_renderContext$addRef===undefined||_renderContext$addRef.call(renderContext,value);}else if(name.startsWith("on")&&isCamelCase(name)){dom.addEventListener(name.substring(2).toLowerCase(),value);}else if(dom.nodeType===Node.TEXT_NODE){dom.nodeValue=value;}else {dom.setAttribute(name,value);}});element.children.forEach(function(child){return render(child,dom,renderContext)});container.appendChild(dom);return container}
586
+ function handleComponentElement(element,container,render){var dom=renderComponent(element.props.component,element.props,element.children,render);container.appendChild(dom);return container}function handleFragmentOrElementList(element,container,renderContext){element.children.forEach(function(child){return render(child,container,renderContext)});return container}function handleTextElement(element){return document.createTextNode(element.props.nodeValue)}function handleRegularElement(element,renderContext){var dom=document.createElement(element.type);Object.entries(element.props||{}).forEach(function(_ref){var _ref2=_slicedToArray(_ref,2),name=_ref2[0],propValue=_ref2[1];if(name.startsWith("on")&&isCamelCase(name)){dom.addEventListener(name.substring(2).toLowerCase(),propValue);}else {setElementProps(dom,name,propValue,renderContext);}});return dom}function handleDirective(dom,directive,renderContext){directive.init(dom,renderContext);}function setElementProps(dom,name,propValue,renderContext){if(dom.nodeType===Node.TEXT_NODE){dom.nodeValue=propValue;}else if(propValue instanceof RumiousDirective){handleDirective(dom,propValue,renderContext);}else {dom.setAttribute(name,propValue);}}function render(element,container){var renderContext=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};if(!element)return container;var dom;if(element.type==="COMPONENT"){return handleComponentElement(element,container,render)}if(element.type==="FRAGMENT"||element.type==="ELEMENT_LIST"){return handleFragmentOrElementList(element,container,renderContext)}if(element.type==="TEXT_ELEMENT"){dom=handleTextElement(element);}else {dom=handleRegularElement(element,renderContext);}element.children.forEach(function(child){return render(child,dom,renderContext)});container.appendChild(dom);return container}
208
587
 
209
588
  var RumiousApp=/*#__PURE__*/function(){function RumiousApp(){var root=arguments.length>0&&arguments[0]!==undefined?arguments[0]:document.createElement("span");var configs=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,RumiousApp);this.root=root;this.configs=configs;this.renderContext=new RumiousRenderContext(this);}return _createClass(RumiousApp,[{key:"render",value:function render$1(element){render(element,this.root,this.renderContext);}}])}();
210
589
 
211
590
  var RumiousReactor=/*#__PURE__*/function(){function RumiousReactor(){var target=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var bindings=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[];_classCallCheck(this,RumiousReactor);this.target=target;this.bindings=bindings;}return _createClass(RumiousReactor,[{key:"react",value:function react(){this.bindings.forEach(function(callback){return callback()});}},{key:"addBinding",value:function addBinding(fn){this.bindings.push(fn);}}])}();
212
591
 
213
- var RumiousState=/*#__PURE__*/function(){function RumiousState(target){var reactor=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;_classCallCheck(this,RumiousState);this.target=target;this.reactor=reactor!==null&&reactor!==undefined?reactor:new RumiousReactor(this,[]);if(target&&_typeof(target)==="object"){this.wrapProxy(target);}else {this._value=target;}}return _createClass(RumiousState,[{key:"wrapProxy",value:function wrapProxy(target){var _this=this;this._value=new Proxy(target,{get:function get(target,prop){var value=target[prop];return value&&_typeof(value)==="object"?new RumiousState(value,_this.reactor).value:value},set:function set(target,prop,value){if(value&&_typeof(value)==="object"){value=new RumiousState(value,_this.reactor).proxy;}_this.reactor.react();target[prop]=value;return true}});}},{key:"value",get:function get(){return this._value},set:function set(val){if(val&&_typeof(val)==="object"){this.wrapProxy(val);}else {this._value=val;}this.reactor.react();}}])}();function createState(value){return new RumiousState(value)}
592
+ var RumiousReducer=/*#__PURE__*/function(){function RumiousReducer(state){var path=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"";var fn=arguments.length>2?arguments[2]:undefined;_classCallCheck(this,RumiousReducer);this.state=state;this.path=path;this.fn=fn;}return _createClass(RumiousReducer,[{key:"trigger",value:function trigger(){var value=this.fn.apply(this,arguments);this.state.set(this.path,value);}}])}();
593
+
594
+ var Operation={Remove:"remove",Replace:"replace",Add:"add"};// Don't use `Symbol()` just for 3rd party access the draft
595
+ var PROXY_DRAFT=Symbol["for"]("__MUTATIVE_PROXY_DRAFT__");var RAW_RETURN_SYMBOL=Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__");var iteratorSymbol=Symbol.iterator;var dataTypes={mutable:"mutable",immutable:"immutable"};var internal={};function has(target,key){return target instanceof Map?target.has(key):Object.prototype.hasOwnProperty.call(target,key)}function getDescriptor(target,key){if(key in target){var prototype=Reflect.getPrototypeOf(target);while(prototype){var descriptor=Reflect.getOwnPropertyDescriptor(prototype,key);if(descriptor)return descriptor;prototype=Reflect.getPrototypeOf(prototype);}}return}function isBaseSetInstance(obj){return Object.getPrototypeOf(obj)===Set.prototype}function isBaseMapInstance(obj){return Object.getPrototypeOf(obj)===Map.prototype}function latest(proxyDraft){var _a;return (_a=proxyDraft.copy)!==null&&_a!==undefined?_a:proxyDraft.original}/**
596
+ * Check if the value is a draft
597
+ */function isDraft(target){return !!getProxyDraft(target)}function getProxyDraft(value){if(_typeof(value)!=="object")return null;return value===null||value===undefined?undefined:value[PROXY_DRAFT]}function getValue(value){var _a;var proxyDraft=getProxyDraft(value);return proxyDraft?(_a=proxyDraft.copy)!==null&&_a!==undefined?_a:proxyDraft.original:value}/**
598
+ * Check if a value is draftable
599
+ */function isDraftable(value,options){if(!value||_typeof(value)!=="object")return false;var markResult;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")}function getPath(target){var path=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[];if(Object.hasOwnProperty.call(target,"key")){// check if the parent is a draft and the original value is not equal to the current value
600
+ var parentCopy=target.parent.copy;var proxyDraft=getProxyDraft(get(parentCopy,target.key));if(proxyDraft!==null&&(proxyDraft===null||proxyDraft===undefined?undefined:proxyDraft.original)!==target.original){return null}var isSet=target.parent.type===3/* DraftType.Set */;var key=isSet?Array.from(target.parent.setMap.keys()).indexOf(target.key):target.key;// check if the key is still in the next state parent
601
+ if(!(isSet&&parentCopy.size>key||has(parentCopy,key)))return null;path.push(key);}if(target.parent){return getPath(target.parent,path)}// `target` is root draft.
602
+ path.reverse();try{// check if the path is valid
603
+ resolvePath(target.copy,path);}catch(e){return null}return path}function getType(target){if(Array.isArray(target))return 1/* DraftType.Array */;if(target instanceof Map)return 2/* DraftType.Map */;if(target instanceof Set)return 3/* DraftType.Set */;return 0/* DraftType.Object */}function get(target,key){return getType(target)===2/* DraftType.Map */?target.get(key):target[key]}function set(target,key,value){var type=getType(target);if(type===2/* DraftType.Map */){target.set(key,value);}else {target[key]=value;}}function peek(target,key){var state=getProxyDraft(target);var source=state?latest(state):target;return source[key]}function isEqual(x,y){if(x===y){return x!==0||1/x===1/y}else {return x!==x&&y!==y}}function revokeProxy(proxyDraft){if(!proxyDraft)return;while(proxyDraft.finalities.revoke.length>0){var revoke=proxyDraft.finalities.revoke.pop();revoke();}}// handle JSON Pointer path with spec https://www.rfc-editor.org/rfc/rfc6901
604
+ function escapePath(path,pathAsArray){return pathAsArray?path:[""].concat(path).map(function(_item){var item="".concat(_item);if(item.indexOf("/")===-1&&item.indexOf("~")===-1)return item;return item.replace(/~/g,"~0").replace(/\//g,"~1")}).join("/")}function resolvePath(base,path){for(var index=0;index<path.length-1;index+=1){var key=path[index];// use `index` in Set draft
605
+ base=get(getType(base)===3/* DraftType.Set */?Array.from(base):base,key);if(_typeof(base)!=="object"){throw new Error("Cannot resolve patch at '".concat(path.join("/"),"'."))}}return base}function strictCopy(target){var copy=Object.create(Object.getPrototypeOf(target));Reflect.ownKeys(target).forEach(function(key){var desc=Reflect.getOwnPropertyDescriptor(target,key);if(desc.enumerable&&desc.configurable&&desc.writable){copy[key]=target[key];return}// for freeze
606
+ if(!desc.writable){desc.writable=true;desc.configurable=true;}if(desc.get||desc.set)desc={configurable:true,writable:true,enumerable:desc.enumerable,value:target[key]};Reflect.defineProperty(copy,key,desc);});return copy}var propIsEnum=Object.prototype.propertyIsEnumerable;function shallowCopy(original,options){var markResult;if(Array.isArray(original)){return Array.prototype.concat.call(original)}else if(original instanceof Set){if(!isBaseSetInstance(original)){var SubClass=Object.getPrototypeOf(original).constructor;return new SubClass(original.values())}return Set.prototype.difference?Set.prototype.difference.call(original,new Set):new Set(original.values())}else if(original instanceof Map){if(!isBaseMapInstance(original)){var _SubClass=Object.getPrototypeOf(original).constructor;return new _SubClass(original)}return new Map(original)}else if((options===null||options===undefined?undefined:options.mark)&&(markResult=options.mark(original,dataTypes),markResult!==undefined)&&markResult!==dataTypes.mutable){if(markResult===dataTypes.immutable){return strictCopy(original)}else if(typeof markResult==="function"){if(options.enablePatches||options.enableAutoFreeze){throw new Error("You can't use mark and patches or auto freeze together.")}return markResult()}throw new Error("Unsupported mark result: ".concat(markResult))}else if(_typeof(original)==="object"&&Object.getPrototypeOf(original)===Object.prototype){// For best performance with shallow copies,
607
+ // don't use `Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));` by default.
608
+ var copy={};Object.keys(original).forEach(function(key){copy[key]=original[key];});Object.getOwnPropertySymbols(original).forEach(function(key){if(propIsEnum.call(original,key)){copy[key]=original[key];}});return copy}else {throw new Error("Please check mark() to ensure that it is a stable marker draftable function.")}}function ensureShallowCopy(target){if(target.copy)return;target.copy=shallowCopy(target.original,target.options);}function deepClone(target){if(!isDraftable(target))return getValue(target);if(Array.isArray(target))return target.map(deepClone);if(target instanceof Map){var iterable=Array.from(target.entries()).map(function(_ref){var _ref2=_slicedToArray(_ref,2),k=_ref2[0],v=_ref2[1];return [k,deepClone(v)]});if(!isBaseMapInstance(target)){var SubClass=Object.getPrototypeOf(target).constructor;return new SubClass(iterable)}return new Map(iterable)}if(target instanceof Set){var _iterable=Array.from(target).map(deepClone);if(!isBaseSetInstance(target)){var _SubClass2=Object.getPrototypeOf(target).constructor;return new _SubClass2(_iterable)}return new Set(_iterable)}var copy=Object.create(Object.getPrototypeOf(target));for(var key in target)copy[key]=deepClone(target[key]);return copy}function cloneIfNeeded(target){return isDraft(target)?deepClone(target):target}function markChanged(proxyDraft){var _a;proxyDraft.assignedMap=(_a=proxyDraft.assignedMap)!==null&&_a!==undefined?_a:new Map;if(!proxyDraft.operated){proxyDraft.operated=true;if(proxyDraft.parent){markChanged(proxyDraft.parent);}}}function throwFrozenError(){throw new Error("Cannot modify frozen object")}function deepFreeze(target,subKey,updatedValues,stack,keys){{updatedValues=updatedValues!==null&&updatedValues!==undefined?updatedValues:new WeakMap;stack=stack!==null&&stack!==undefined?stack:[];keys=keys!==null&&keys!==undefined?keys:[];var value=updatedValues.has(target)?updatedValues.get(target):target;if(stack.length>0){var index=stack.indexOf(value);if(value&&_typeof(value)==="object"&&index!==-1){if(stack[0]===value){throw new Error("Forbids circular reference")}throw new Error("Forbids circular reference: ~/".concat(keys.slice(0,index).map(function(key,index){if(_typeof(key)==="symbol")return "[".concat(key.toString(),"]");var parent=stack[index];if(_typeof(key)==="object"&&(parent instanceof Map||parent instanceof Set))return Array.from(parent.keys()).indexOf(key);return key}).join("/")))}stack.push(value);keys.push(subKey);}else {stack.push(value);}}if(Object.isFrozen(target)||isDraft(target)){{stack.pop();keys.pop();}return}var type=getType(target);switch(type){case 2/* DraftType.Map */:var _iterator=_createForOfIteratorHelper(target),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var _step$value=_slicedToArray(_step.value,2),key=_step$value[0],_value2=_step$value[1];deepFreeze(key,key,updatedValues,stack,keys);deepFreeze(_value2,key,updatedValues,stack,keys);}}catch(err){_iterator.e(err);}finally{_iterator.f();}target.set=target.clear=target["delete"]=throwFrozenError;break;case 3/* DraftType.Set */:var _iterator2=_createForOfIteratorHelper(target),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _value3=_step2.value;deepFreeze(_value3,_value3,updatedValues,stack,keys);}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}target.add=target.clear=target["delete"]=throwFrozenError;break;case 1/* DraftType.Array */:Object.freeze(target);var _index=0;var _iterator3=_createForOfIteratorHelper(target),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var _value4=_step3.value;deepFreeze(_value4,_index,updatedValues,stack,keys);_index+=1;}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}break;default:Object.freeze(target);// ignore non-enumerable or symbol properties
609
+ Object.keys(target).forEach(function(name){var value=target[name];deepFreeze(value,name,updatedValues,stack,keys);});}{stack.pop();keys.pop();}}function forEach(target,iter){var type=getType(target);if(type===0/* DraftType.Object */){Reflect.ownKeys(target).forEach(function(key){iter(key,target[key],target);});}else if(type===1/* DraftType.Array */){var index=0;var _iterator4=_createForOfIteratorHelper(target),_step4;try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){var entry=_step4.value;iter(index,entry,target);index+=1;}}catch(err){_iterator4.e(err);}finally{_iterator4.f();}}else {target.forEach(function(entry,index){return iter(index,entry,target)});}}function handleValue(target,handledSet,options){if(isDraft(target)||!isDraftable(target,options)||handledSet.has(target)||Object.isFrozen(target))return;var isSet=target instanceof Set;var setMap=isSet?new Map:undefined;handledSet.add(target);forEach(target,function(key,value){var _a;if(isDraft(value)){var proxyDraft=getProxyDraft(value);ensureShallowCopy(proxyDraft);// A draft where a child node has been changed, or assigned a value
610
+ var updatedValue=((_a=proxyDraft.assignedMap)===null||_a===void 0?void 0:_a.size)||proxyDraft.operated?proxyDraft.copy:proxyDraft.original;// final update value
611
+ set(isSet?setMap:target,key,updatedValue);}else {handleValue(value,handledSet,options);}});if(setMap){var _set=target;var values=Array.from(_set);_set.clear();values.forEach(function(value){_set.add(setMap.has(value)?setMap.get(value):value);});}}function finalizeAssigned(proxyDraft,key){// handle the draftable assigned values, and the value is not a draft
612
+ var copy=proxyDraft.type===3/* DraftType.Set */?proxyDraft.setMap:proxyDraft.copy;if(proxyDraft.finalities.revoke.length>1&&proxyDraft.assignedMap.get(key)&&copy){handleValue(get(copy,key),proxyDraft.finalities.handledSet,proxyDraft.options);}}function finalizeSetValue(target){if(target.type===3/* DraftType.Set */&&target.copy){target.copy.clear();target.setMap.forEach(function(value){target.copy.add(getValue(value));});}}function finalizePatches(target,generatePatches,patches,inversePatches){var shouldFinalize=target.operated&&target.assignedMap&&target.assignedMap.size>0&&!target.finalized;if(shouldFinalize){if(patches&&inversePatches){var basePath=getPath(target);if(basePath){generatePatches(target,basePath,patches,inversePatches);}}target.finalized=true;}}function markFinalization(target,key,value,generatePatches){var proxyDraft=getProxyDraft(value);if(proxyDraft){// !case: assign the draft value
613
+ if(!proxyDraft.callbacks){proxyDraft.callbacks=[];}proxyDraft.callbacks.push(function(patches,inversePatches){var _a;var copy=target.type===3/* DraftType.Set */?target.setMap:target.copy;if(isEqual(get(copy,key),value)){var updatedValue=proxyDraft.original;if(proxyDraft.copy){updatedValue=proxyDraft.copy;}finalizeSetValue(target);finalizePatches(target,generatePatches,patches,inversePatches);if(target.options.enableAutoFreeze){target.options.updatedValues=(_a=target.options.updatedValues)!==null&&_a!==undefined?_a:new WeakMap;target.options.updatedValues.set(updatedValue,proxyDraft.original);}// final update value
614
+ set(copy,key,updatedValue);}});if(target.options.enableAutoFreeze){// !case: assign the draft value in cross draft tree
615
+ if(proxyDraft.finalities!==target.finalities){target.options.enableAutoFreeze=false;}}}if(isDraftable(value,target.options)){// !case: assign the non-draft value
616
+ target.finalities.draft.push(function(){var copy=target.type===3/* DraftType.Set */?target.setMap:target.copy;if(isEqual(get(copy,key),value)){finalizeAssigned(target,key);}});}}function generateArrayPatches(proxyState,basePath,patches,inversePatches,pathAsArray){var original=proxyState.original,assignedMap=proxyState.assignedMap,options=proxyState.options;var copy=proxyState.copy;if(copy.length<original.length){var _ref3=[copy,original];original=_ref3[0];copy=_ref3[1];var _ref4=[inversePatches,patches];patches=_ref4[0];inversePatches=_ref4[1];}for(var index=0;index<original.length;index+=1){if(assignedMap.get(index.toString())&&copy[index]!==original[index]){var _path=basePath.concat([index]);var path=escapePath(_path,pathAsArray);patches.push({op:Operation.Replace,path:path,// If it is a draft, it needs to be deep cloned, and it may also be non-draft.
617
+ value:cloneIfNeeded(copy[index])});inversePatches.push({op:Operation.Replace,path:path,// If it is a draft, it needs to be deep cloned, and it may also be non-draft.
618
+ value:cloneIfNeeded(original[index])});}}for(var _index2=original.length;_index2<copy.length;_index2+=1){var _path2=basePath.concat([_index2]);var _path3=escapePath(_path2,pathAsArray);patches.push({op:Operation.Add,path:_path3,// If it is a draft, it needs to be deep cloned, and it may also be non-draft.
619
+ value:cloneIfNeeded(copy[_index2])});}if(original.length<copy.length){// https://www.rfc-editor.org/rfc/rfc6902#appendix-A.4
620
+ // For performance, here we only generate an operation that replaces the length of the array,
621
+ // which is inconsistent with JSON Patch specification
622
+ var _options$enablePatche=options.enablePatches.arrayLengthAssignment,arrayLengthAssignment=_options$enablePatche===undefined?true:_options$enablePatche;if(arrayLengthAssignment){var _path4=basePath.concat(["length"]);var _path5=escapePath(_path4,pathAsArray);inversePatches.push({op:Operation.Replace,path:_path5,value:original.length});}else {for(var _index3=copy.length;original.length<_index3;_index3-=1){var _path6=basePath.concat([_index3-1]);var _path7=escapePath(_path6,pathAsArray);inversePatches.push({op:Operation.Remove,path:_path7});}}}}function generatePatchesFromAssigned(_ref5,basePath,patches,inversePatches,pathAsArray){var original=_ref5.original,copy=_ref5.copy,assignedMap=_ref5.assignedMap;assignedMap.forEach(function(assignedValue,key){var originalValue=get(original,key);var value=cloneIfNeeded(get(copy,key));var op=!assignedValue?Operation.Remove:has(original,key)?Operation.Replace:Operation.Add;if(isEqual(originalValue,value)&&op===Operation.Replace)return;var _path=basePath.concat(key);var path=escapePath(_path,pathAsArray);patches.push(op===Operation.Remove?{op:op,path:path}:{op:op,path:path,value:value});inversePatches.push(op===Operation.Add?{op:Operation.Remove,path:path}:op===Operation.Remove?{op:Operation.Add,path:path,value:originalValue}:{op:Operation.Replace,path:path,value:originalValue});});}function generateSetPatches(_ref6,basePath,patches,inversePatches,pathAsArray){var original=_ref6.original,copy=_ref6.copy;var index=0;original.forEach(function(value){if(!copy.has(value)){var _path=basePath.concat([index]);var path=escapePath(_path,pathAsArray);patches.push({op:Operation.Remove,path:path,value:value});inversePatches.unshift({op:Operation.Add,path:path,value:value});}index+=1;});index=0;copy.forEach(function(value){if(!original.has(value)){var _path=basePath.concat([index]);var path=escapePath(_path,pathAsArray);patches.push({op:Operation.Add,path:path,value:value});inversePatches.unshift({op:Operation.Remove,path:path,value:value});}index+=1;});}function generatePatches(proxyState,basePath,patches,inversePatches){var _proxyState$options$e=proxyState.options.enablePatches.pathAsArray,pathAsArray=_proxyState$options$e===undefined?true:_proxyState$options$e;switch(proxyState.type){case 0/* DraftType.Object */:case 2/* DraftType.Map */:return generatePatchesFromAssigned(proxyState,basePath,patches,inversePatches,pathAsArray);case 1/* DraftType.Array */:return generateArrayPatches(proxyState,basePath,patches,inversePatches,pathAsArray);case 3/* DraftType.Set */:return generateSetPatches(proxyState,basePath,patches,inversePatches,pathAsArray)}}var checkReadable=function checkReadable(value,options){var ignoreCheckDraftable=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(_typeof(value)==="object"&&value!==null&&(!isDraftable(value,options)||ignoreCheckDraftable)&&true){throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.")}};var mapHandler=_defineProperty({get size(){var current=latest(getProxyDraft(this));return current.size},has:function has(key){return latest(getProxyDraft(this)).has(key)},set:function set(key,value){var target=getProxyDraft(this);var source=latest(target);if(!source.has(key)||!isEqual(source.get(key),value)){ensureShallowCopy(target);markChanged(target);target.assignedMap.set(key,true);target.copy.set(key,value);markFinalization(target,key,value,generatePatches);}return this},"delete":function _delete(key){if(!this.has(key)){return false}var target=getProxyDraft(this);ensureShallowCopy(target);markChanged(target);if(target.original.has(key)){target.assignedMap.set(key,false);}else {target.assignedMap["delete"](key);}target.copy["delete"](key);return true},clear:function clear(){var target=getProxyDraft(this);if(!this.size)return;ensureShallowCopy(target);markChanged(target);target.assignedMap=new Map;var _iterator5=_createForOfIteratorHelper(target.original),_step5;try{for(_iterator5.s();!(_step5=_iterator5.n()).done;){var _step5$value=_slicedToArray(_step5.value,1),key=_step5$value[0];target.assignedMap.set(key,false);}}catch(err){_iterator5.e(err);}finally{_iterator5.f();}target.copy.clear();},forEach:function forEach(callback,thisArg){var _this=this;var target=getProxyDraft(this);latest(target).forEach(function(_value,_key){callback.call(thisArg,_this.get(_key),_key,_this);});},get:function get(key){var _a,_b;var target=getProxyDraft(this);var value=latest(target).get(key);var mutable=((_b=(_a=target.options).mark)===null||_b===undefined?undefined:_b.call(_a,value,dataTypes))===dataTypes.mutable;if(target.options.strict){checkReadable(value,target.options,mutable);}if(mutable){return value}if(target.finalized||!isDraftable(value,target.options)){return value}// drafted or reassigned
623
+ if(value!==target.original.get(key)){return value}var draft=internal.createDraft({original:value,parentDraft:target,key:key,finalities:target.finalities,options:target.options});ensureShallowCopy(target);target.copy.set(key,draft);return draft},keys:function keys(){return latest(getProxyDraft(this)).keys()},values:function values(){var _this2=this;var iterator=this.keys();return _defineProperty(_defineProperty({},iteratorSymbol,function(){return _this2.values()}),"next",function next(){var result=iterator.next();if(result.done)return result;var value=_this2.get(result.value);return {done:false,value:value}})},entries:function entries(){var _this3=this;var iterator=this.keys();return _defineProperty(_defineProperty({},iteratorSymbol,function(){return _this3.entries()}),"next",function next(){var result=iterator.next();if(result.done)return result;var value=_this3.get(result.value);return {done:false,value:[result.value,value]}})}},iteratorSymbol,function(){return this.entries()});var mapHandlerKeys=Reflect.ownKeys(mapHandler);var getNextIterator=function getNextIterator(target,iterator,_ref9){var isValuesIterator=_ref9.isValuesIterator;return function(){var _a,_b;var result=iterator.next();if(result.done)return result;var key=result.value;var value=target.setMap.get(key);var currentDraft=getProxyDraft(value);var mutable=((_b=(_a=target.options).mark)===null||_b===undefined?undefined:_b.call(_a,value,dataTypes))===dataTypes.mutable;if(target.options.strict){checkReadable(key,target.options,mutable);}if(!mutable&&!currentDraft&&isDraftable(key,target.options)&&!target.finalized&&target.original.has(key)){// draft a draftable original set item
624
+ var proxy=internal.createDraft({original:key,parentDraft:target,key:key,finalities:target.finalities,options:target.options});target.setMap.set(key,proxy);value=proxy;}else if(currentDraft){// drafted
625
+ value=currentDraft.proxy;}return {done:false,value:isValuesIterator?value:[value,value]}}};var setHandler=_defineProperty(_defineProperty({get size(){var target=getProxyDraft(this);return target.setMap.size},has:function has(value){var target=getProxyDraft(this);// reassigned or non-draftable values
626
+ if(target.setMap.has(value))return true;ensureShallowCopy(target);var valueProxyDraft=getProxyDraft(value);// drafted
627
+ if(valueProxyDraft&&target.setMap.has(valueProxyDraft.original))return true;return false},add:function add(value){var target=getProxyDraft(this);if(!this.has(value)){ensureShallowCopy(target);markChanged(target);target.assignedMap.set(value,true);target.setMap.set(value,value);markFinalization(target,value,value,generatePatches);}return this},"delete":function _delete(value){if(!this.has(value)){return false}var target=getProxyDraft(this);ensureShallowCopy(target);markChanged(target);var valueProxyDraft=getProxyDraft(value);if(valueProxyDraft&&target.setMap.has(valueProxyDraft.original)){// delete drafted
628
+ target.assignedMap.set(valueProxyDraft.original,false);return target.setMap["delete"](valueProxyDraft.original)}if(!valueProxyDraft&&target.setMap.has(value)){// non-draftable values
629
+ target.assignedMap.set(value,false);}else {// reassigned
630
+ target.assignedMap["delete"](value);}// delete reassigned or non-draftable values
631
+ return target.setMap["delete"](value)},clear:function clear(){if(!this.size)return;var target=getProxyDraft(this);ensureShallowCopy(target);markChanged(target);var _iterator6=_createForOfIteratorHelper(target.original),_step6;try{for(_iterator6.s();!(_step6=_iterator6.n()).done;){var value=_step6.value;target.assignedMap.set(value,false);}}catch(err){_iterator6.e(err);}finally{_iterator6.f();}target.setMap.clear();},values:function values(){var _this4=this;var target=getProxyDraft(this);ensureShallowCopy(target);var iterator=target.setMap.keys();return _defineProperty(_defineProperty({},Symbol.iterator,function(){return _this4.values()}),"next",getNextIterator(target,iterator,{isValuesIterator:true}))},entries:function entries(){var _this5=this;var target=getProxyDraft(this);ensureShallowCopy(target);var iterator=target.setMap.keys();return _defineProperty(_defineProperty({},Symbol.iterator,function(){return _this5.entries()}),"next",getNextIterator(target,iterator,{isValuesIterator:false}))},keys:function keys(){return this.values()}},iteratorSymbol,function(){return this.values()}),"forEach",function forEach(callback,thisArg){var iterator=this.values();var result=iterator.next();while(!result.done){callback.call(thisArg,result.value,result.value,this);result=iterator.next();}});if(Set.prototype.difference){// for compatibility with new Set methods
632
+ // https://github.com/tc39/proposal-set-methods
633
+ // And `https://github.com/tc39/proposal-set-methods/blob/main/details.md#symbolspecies` has some details about the `@@species` symbol.
634
+ // So we can't use SubSet instance constructor to get the constructor of the SubSet instance.
635
+ Object.assign(setHandler,{intersection:function intersection(other){return Set.prototype.intersection.call(new Set(this.values()),other)},union:function union(other){return Set.prototype.union.call(new Set(this.values()),other)},difference:function difference(other){return Set.prototype.difference.call(new Set(this.values()),other)},symmetricDifference:function symmetricDifference(other){return Set.prototype.symmetricDifference.call(new Set(this.values()),other)},isSubsetOf:function isSubsetOf(other){return Set.prototype.isSubsetOf.call(new Set(this.values()),other)},isSupersetOf:function isSupersetOf(other){return Set.prototype.isSupersetOf.call(new Set(this.values()),other)},isDisjointFrom:function isDisjointFrom(other){return Set.prototype.isDisjointFrom.call(new Set(this.values()),other)}});}var setHandlerKeys=Reflect.ownKeys(setHandler);var draftsCache=new WeakSet;var proxyHandler={get:function get(target,key,receiver){var _a,_b;var copy=(_a=target.copy)===null||_a===undefined?undefined:_a[key];// Improve draft reading performance by caching the draft copy.
636
+ if(copy&&draftsCache.has(copy)){return copy}if(key===PROXY_DRAFT)return target;var markResult;if(target.options.mark){// handle `Uncaught TypeError: Method get Map.prototype.size called on incompatible receiver #<Map>`
637
+ // or `Uncaught TypeError: Method get Set.prototype.size called on incompatible receiver #<Set>`
638
+ var _value5=key==="size"&&(target.original instanceof Map||target.original instanceof Set)?Reflect.get(target.original,key):Reflect.get(target.original,key,receiver);markResult=target.options.mark(_value5,dataTypes);if(markResult===dataTypes.mutable){if(target.options.strict){checkReadable(_value5,target.options,true);}return _value5}}var source=latest(target);if(source instanceof Map&&mapHandlerKeys.includes(key)){if(key==="size"){return Object.getOwnPropertyDescriptor(mapHandler,"size").get.call(target.proxy)}var handle=mapHandler[key];if(handle){return handle.bind(target.proxy)}}if(source instanceof Set&&setHandlerKeys.includes(key)){if(key==="size"){return Object.getOwnPropertyDescriptor(setHandler,"size").get.call(target.proxy)}var _handle=setHandler[key];if(_handle){return _handle.bind(target.proxy)}}if(!has(source,key)){var desc=getDescriptor(source,key);return desc?"value"in desc?desc.value:// !case: support for getter
639
+ (_b=desc.get)===null||_b===undefined?undefined:_b.call(target.proxy):undefined}var value=source[key];if(target.options.strict){checkReadable(value,target.options);}if(target.finalized||!isDraftable(value,target.options)){return value}// Ensure that the assigned values are not drafted
640
+ if(value===peek(target.original,key)){ensureShallowCopy(target);target.copy[key]=createDraft({original:target.original[key],parentDraft:target,key:target.type===1/* DraftType.Array */?Number(key):key,finalities:target.finalities,options:target.options});// !case: support for custom shallow copy function
641
+ if(typeof markResult==="function"){var subProxyDraft=getProxyDraft(target.copy[key]);ensureShallowCopy(subProxyDraft);// Trigger a custom shallow copy to update to a new copy
642
+ markChanged(subProxyDraft);return subProxyDraft.copy}return target.copy[key]}return value},set:function set(target,key,value){var _a;if(target.type===3/* DraftType.Set */||target.type===2/* DraftType.Map */){throw new Error("Map/Set draft does not support any property assignment.")}var _key;if(target.type===1/* DraftType.Array */&&key!=="length"&&!(Number.isInteger(_key=Number(key))&&_key>=0&&(key===0||_key===0||String(_key)===String(key)))){throw new Error("Only supports setting array indices and the 'length' property.")}var desc=getDescriptor(latest(target),key);if(desc===null||desc===undefined?undefined:desc.set){// !case: cover the case of setter
643
+ desc.set.call(target.proxy,value);return true}var current=peek(latest(target),key);var currentProxyDraft=getProxyDraft(current);if(currentProxyDraft&&isEqual(currentProxyDraft.original,value)){// !case: ignore the case of assigning the original draftable value to a draft
644
+ target.copy[key]=value;target.assignedMap=(_a=target.assignedMap)!==null&&_a!==undefined?_a:new Map;target.assignedMap.set(key,false);return true}// !case: handle new props with value 'undefined'
645
+ if(isEqual(value,current)&&(value!==undefined||has(target.original,key)))return true;ensureShallowCopy(target);markChanged(target);if(has(target.original,key)&&isEqual(value,target.original[key])){// !case: handle the case of assigning the original non-draftable value to a draft
646
+ target.assignedMap["delete"](key);}else {target.assignedMap.set(key,true);}target.copy[key]=value;markFinalization(target,key,value,generatePatches);return true},has:function has(target,key){return key in latest(target)},ownKeys:function ownKeys(target){return Reflect.ownKeys(latest(target))},getOwnPropertyDescriptor:function getOwnPropertyDescriptor(target,key){var source=latest(target);var descriptor=Reflect.getOwnPropertyDescriptor(source,key);if(!descriptor)return descriptor;return {writable:true,configurable:target.type!==1/* DraftType.Array */||key!=="length",enumerable:descriptor.enumerable,value:source[key]}},getPrototypeOf:function getPrototypeOf(target){return Reflect.getPrototypeOf(target.original)},setPrototypeOf:function setPrototypeOf(){throw new Error("Cannot call 'setPrototypeOf()' on drafts")},defineProperty:function defineProperty(){throw new Error("Cannot call 'defineProperty()' on drafts")},deleteProperty:function deleteProperty(target,key){var _a;if(target.type===1/* DraftType.Array */){return proxyHandler.set.call(this,target,key,undefined,target.proxy)}if(peek(target.original,key)!==undefined||key in target.original){// !case: delete an existing key
647
+ ensureShallowCopy(target);markChanged(target);target.assignedMap.set(key,false);}else {target.assignedMap=(_a=target.assignedMap)!==null&&_a!==undefined?_a:new Map;// The original non-existent key has been deleted
648
+ target.assignedMap["delete"](key);}if(target.copy)delete target.copy[key];return true}};function createDraft(createDraftOptions){var original=createDraftOptions.original,parentDraft=createDraftOptions.parentDraft,key=createDraftOptions.key,finalities=createDraftOptions.finalities,options=createDraftOptions.options;var type=getType(original);var proxyDraft={type:type,finalized:false,parent:parentDraft,original:original,copy:null,proxy:null,finalities:finalities,options:options,// Mapping of draft Set items to their corresponding draft values.
649
+ setMap:type===3/* DraftType.Set */?new Map(original.entries()):undefined};// !case: undefined as a draft map key
650
+ if(key||"key"in createDraftOptions){proxyDraft.key=key;}var _Proxy$revocable=Proxy.revocable(type===1/* DraftType.Array */?Object.assign([],proxyDraft):proxyDraft,proxyHandler),proxy=_Proxy$revocable.proxy,revoke=_Proxy$revocable.revoke;finalities.revoke.push(revoke);draftsCache.add(proxy);proxyDraft.proxy=proxy;if(parentDraft){var target=parentDraft;target.finalities.draft.push(function(patches,inversePatches){var _a,_b;var oldProxyDraft=getProxyDraft(proxy);// if target is a Set draft, `setMap` is the real Set copies proxy mapping.
651
+ var copy=target.type===3/* DraftType.Set */?target.setMap:target.copy;var draft=get(copy,key);var proxyDraft=getProxyDraft(draft);if(proxyDraft){// assign the updated value to the copy object
652
+ var updatedValue=proxyDraft.original;if(proxyDraft.operated){updatedValue=getValue(draft);}finalizeSetValue(proxyDraft);finalizePatches(proxyDraft,generatePatches,patches,inversePatches);if(target.options.enableAutoFreeze){target.options.updatedValues=(_a=target.options.updatedValues)!==null&&_a!==undefined?_a:new WeakMap;target.options.updatedValues.set(updatedValue,proxyDraft.original);}// final update value
653
+ set(copy,key,updatedValue);}// !case: handle the deleted key
654
+ (_b=oldProxyDraft.callbacks)===null||_b===undefined?undefined:_b.forEach(function(callback){callback(patches,inversePatches);});});}else {// !case: handle the root draft
655
+ var _target=getProxyDraft(proxy);_target.finalities.draft.push(function(patches,inversePatches){finalizeSetValue(_target);finalizePatches(_target,generatePatches,patches,inversePatches);});}return proxy}internal.createDraft=createDraft;function finalizeDraft(result,returnedValue,patches,inversePatches,enableAutoFreeze){var _a;var proxyDraft=getProxyDraft(result);var original=(_a=proxyDraft===null||proxyDraft===undefined?undefined:proxyDraft.original)!==null&&_a!==undefined?_a:result;var hasReturnedValue=!!returnedValue.length;if(proxyDraft===null||proxyDraft===undefined?undefined:proxyDraft.operated){while(proxyDraft.finalities.draft.length>0){var finalize=proxyDraft.finalities.draft.pop();finalize(patches,inversePatches);}}var state=hasReturnedValue?returnedValue[0]:proxyDraft?proxyDraft.operated?proxyDraft.copy:proxyDraft.original:result;if(proxyDraft)revokeProxy(proxyDraft);if(enableAutoFreeze){deepFreeze(state,state,proxyDraft===null||proxyDraft===undefined?undefined:proxyDraft.options.updatedValues);}return [state,patches&&hasReturnedValue?[{op:Operation.Replace,path:[],value:returnedValue[0]}]:patches,inversePatches&&hasReturnedValue?[{op:Operation.Replace,path:[],value:original}]:inversePatches]}function draftify(baseState,options){var _a;var finalities={draft:[],revoke:[],handledSet:new WeakSet};var patches;var inversePatches;if(options.enablePatches){patches=[];inversePatches=[];}var isMutable=((_a=options.mark)===null||_a===undefined?undefined:_a.call(options,baseState,dataTypes))===dataTypes.mutable||!isDraftable(baseState,options);var draft=isMutable?baseState:createDraft({original:baseState,parentDraft:null,finalities:finalities,options:options});return [draft,function(){var returnedValue=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var _finalizeDraft=finalizeDraft(draft,returnedValue,patches,inversePatches,options.enableAutoFreeze),_finalizeDraft2=_slicedToArray(_finalizeDraft,3),finalizedState=_finalizeDraft2[0],finalizedPatches=_finalizeDraft2[1],finalizedInversePatches=_finalizeDraft2[2];return options.enablePatches?[finalizedState,finalizedPatches,finalizedInversePatches]:finalizedState}]}function handleReturnValue(options){var rootDraft=options.rootDraft,value=options.value,_options$useRawReturn=options.useRawReturn,useRawReturn=_options$useRawReturn===undefined?false:_options$useRawReturn,_options$isRoot=options.isRoot,isRoot=_options$isRoot===undefined?true:_options$isRoot;forEach(value,function(key,item,source){var proxyDraft=getProxyDraft(item);// just handle the draft which is created by the same rootDraft
656
+ if(proxyDraft&&rootDraft&&proxyDraft.finalities===rootDraft.finalities){options.isContainDraft=true;var currentValue=proxyDraft.original;// final update value, but just handle return value
657
+ if(source instanceof Set){var arr=Array.from(source);source.clear();arr.forEach(function(_item){return source.add(key===_item?currentValue:_item)});}else {set(source,key,currentValue);}}else if(_typeof(item)==="object"&&item!==null){options.value=item;options.isRoot=false;handleReturnValue(options);}});if(isRoot){if(!options.isContainDraft)console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance.");if(useRawReturn){console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value.");}}}function getCurrent(target){var _a;var proxyDraft=getProxyDraft(target);if(!isDraftable(target,proxyDraft===null||proxyDraft===undefined?undefined:proxyDraft.options))return target;var type=getType(target);if(proxyDraft&&!proxyDraft.operated)return proxyDraft.original;var currentValue;function ensureShallowCopy(){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);}if(proxyDraft){// It's a proxy draft, let's create a shallow copy eagerly
658
+ proxyDraft.finalized=true;try{ensureShallowCopy();}finally{proxyDraft.finalized=false;}}else {// It's not a proxy draft, let's use the target directly and let's see
659
+ // lazily if we need to create a shallow copy
660
+ currentValue=target;}forEach(currentValue,function(key,value){if(proxyDraft&&isEqual(get(proxyDraft.original,key),value))return;var newValue=getCurrent(value);if(newValue!==value){if(currentValue===target)ensureShallowCopy();set(currentValue,key,newValue);}});if(type===3/* DraftType.Set */){var value=(_a=proxyDraft===null||proxyDraft===undefined?undefined:proxyDraft.original)!==null&&_a!==undefined?_a:currentValue;return !isBaseSetInstance(value)?new(Object.getPrototypeOf(value).constructor)(currentValue):new Set(currentValue)}return currentValue}function current(target){if(!isDraft(target)){throw new Error("current() is only used for Draft, parameter: ".concat(target))}return getCurrent(target)}/**
661
+ * `makeCreator(options)` to make a creator function.
662
+ *
663
+ * ## Example
664
+ *
665
+ * ```ts
666
+ * import { makeCreator } from '../index';
667
+ *
668
+ * const baseState = { foo: { bar: 'str' }, arr: [] };
669
+ * const create = makeCreator({ enableAutoFreeze: true });
670
+ * const state = create(
671
+ * baseState,
672
+ * (draft) => {
673
+ * draft.foo.bar = 'str2';
674
+ * },
675
+ * );
676
+ *
677
+ * expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
678
+ * expect(state).not.toBe(baseState);
679
+ * expect(state.foo).not.toBe(baseState.foo);
680
+ * expect(state.arr).toBe(baseState.arr);
681
+ * expect(Object.isFrozen(state)).toBeTruthy();
682
+ * ```
683
+ */var makeCreator=function makeCreator(arg){return function create(arg0,arg1,arg2){var _a,_b,_c;if(typeof arg0==="function"&&typeof arg1!=="function"){return function(base){var _this6=this;for(var _len=arguments.length,args=new Array(_len>1?_len-1:0),_key2=1;_key2<_len;_key2++){args[_key2-1]=arguments[_key2];}return create(base,function(draft){return arg0.call.apply(arg0,[_this6,draft].concat(args))},arg1)}}var base=arg0;var mutate=arg1;var options=arg2;if(typeof arg1!=="function"){options=arg1;}if(options!==undefined&&Object.prototype.toString.call(options)!=="[object Object]"){throw new Error("Invalid options: ".concat(options,", 'options' should be an object."))}options=Object.assign(Object.assign({},arg),options);var state=isDraft(base)?current(base):base;var mark=Array.isArray(options.mark)?function(value,types){var _iterator7=_createForOfIteratorHelper(options.mark),_step7;try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){var _mark=_step7.value;if(typeof _mark!=="function"){throw new Error("Invalid mark: ".concat(_mark,", 'mark' should be a function."))}var _result=_mark(value,types);if(_result){return _result}}}catch(err){_iterator7.e(err);}finally{_iterator7.f();}return}:options.mark;var enablePatches=(_a=options.enablePatches)!==null&&_a!==undefined?_a:false;var strict=(_b=options.strict)!==null&&_b!==undefined?_b:false;var enableAutoFreeze=(_c=options.enableAutoFreeze)!==null&&_c!==undefined?_c:false;var _options={enableAutoFreeze:enableAutoFreeze,mark:mark,strict:strict,enablePatches:enablePatches};if(!isDraftable(state,_options)&&_typeof(state)==="object"&&state!==null){throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.")}var _draftify=draftify(state,_options),_draftify2=_slicedToArray(_draftify,2),draft=_draftify2[0],finalize=_draftify2[1];if(typeof arg1!=="function"){if(!isDraftable(state,_options)){throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.")}return [draft,finalize]}var result;try{result=mutate(draft);}catch(error){revokeProxy(getProxyDraft(draft));throw error}var returnValue=function returnValue(value){var proxyDraft=getProxyDraft(draft);if(!isDraft(value)){if(value!==undefined&&!isEqual(value,draft)&&(proxyDraft===null||proxyDraft===undefined?undefined:proxyDraft.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.")}var rawReturnValue=value===null||value===undefined?undefined:value[RAW_RETURN_SYMBOL];if(rawReturnValue){var _value=rawReturnValue[0];if(_options.strict&&_typeof(value)==="object"&&value!==null){handleReturnValue({rootDraft:proxyDraft,value:value,useRawReturn:true});}return finalize([_value])}if(value!==undefined){if(_typeof(value)==="object"&&value!==null){handleReturnValue({rootDraft:proxyDraft,value:value});}return finalize([value])}}if(value===draft||value===undefined){return finalize([])}var returnedProxyDraft=getProxyDraft(value);if(_options===returnedProxyDraft.options){if(returnedProxyDraft.operated){throw new Error("Cannot return a modified child draft.")}return finalize([current(value)])}return finalize([value])};if(result instanceof Promise){return result.then(returnValue,function(error){revokeProxy(getProxyDraft(draft));throw error})}return returnValue(result)}};/**
684
+ * `create(baseState, callback, options)` to create the next state
685
+ *
686
+ * ## Example
687
+ *
688
+ * ```ts
689
+ * import { create } from '../index';
690
+ *
691
+ * const baseState = { foo: { bar: 'str' }, arr: [] };
692
+ * const state = create(
693
+ * baseState,
694
+ * (draft) => {
695
+ * draft.foo.bar = 'str2';
696
+ * },
697
+ * );
698
+ *
699
+ * expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
700
+ * expect(state).not.toBe(baseState);
701
+ * expect(state.foo).not.toBe(baseState.foo);
702
+ * expect(state.arr).toBe(baseState.arr);
703
+ * ```
704
+ */var create=makeCreator();Object.prototype.constructor.toString();
705
+
706
+ function produceState(state,fn){state.set(create(state.get(),fn));}
707
+
708
+ var RumiousState=/*#__PURE__*/function(){function RumiousState(target){var reactor=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;_classCallCheck(this,RumiousState);this.value=target;this.reactor=reactor!==null&&reactor!==undefined?reactor:new RumiousReactor(this,[]);}return _createClass(RumiousState,[{key:"produce",value:function produce(recipe){return produceState(this,recipe)}},{key:"reducer",value:function reducer(){var computedObj;if(arguments.length===1){computedObj=new RumiousReducer(this,"",arguments.length<=0?undefined:arguments[0]);}else {computedObj=new RumiousReducer(this,arguments.length<=0?undefined:arguments[0],arguments.length<=1?undefined:arguments[1]);}return computedObj.trigger.bind(computedObj)}},{key:"setObjectByPath",value:function setObjectByPath(){var path=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";var value=arguments.length>1?arguments[1]:undefined;if(path.length==0){this.value=value;return}if(typeof path!=="string"||!path){throw new Error("Invalid path")}var keys=path.split(".");var obj=this.value;for(var i=0;i<keys.length-1;i++){var key=keys[i];if(!(key in obj)){obj[key]={};}obj=obj[key];}obj[keys[keys.length-1]]=value;}},{key:"set",value:function set(){if(arguments.length===1){this.value=arguments.length<=0?undefined:arguments[0];}else {var path=arguments.length<=0?undefined:arguments[0];var value=arguments.length<=1?undefined:arguments[1];this.setObjectByPath(path,value);}this.reactor.react();}},{key:"get",value:function get(){return this.value}}])}();function createState(value){return new RumiousState(value)}function isState(obj){return obj instanceof RumiousState}
214
709
 
215
710
  function watcher(state,callback){state.reactor.addBinding(callback);}
216
711
 
@@ -221,4 +716,5 @@ exports.RumiousState = RumiousState;
221
716
  exports.createComponentElement = createComponentElement;
222
717
  exports.createState = createState;
223
718
  exports.isComponent = isComponent;
719
+ exports.isState = isState;
224
720
  exports.watcher = watcher;