var e,r;e=this,r=function(e){"use strict";function r(e,r,n,t,o,i){var a,f,u,c,p;n&&(Array.isArray(o)?function(e,r,n,t,o,i){for(var a=Math.min(o.length,i.length),f=0;f0||h.length>0)&&S(r),v(l,function(e,n){r.assigned[n]=!0}),v(h,function(e,n){r.assigned[n]=!1}),v(u,function(e,n){r.assigned[e]||N(n)})}}}}function D(e){var r=e.proxy;if(r.length!==e.base.length)return!0;var n=Object.getOwnPropertyDescriptor(r,r.length-1);return!(!n||n.get)}function M(e,r,n){if(s(e)){var t=r.call(e,e);return void 0===t?e:t}var o=k;k=[];var a=n&&[],c=n&&[];try{var p=C(void 0,e),d=r.call(p,p);v(k,function(e,r){r.finalizing=!0});var l=void 0;if(void 0!==d&&d!==p){if(p[f].modified)throw new Error(u);l=m(d),a&&(a.push({op:"replace",path:[],value:l}),c.push({op:"replace",path:[],value:e}))}else n&&N(p),function(){for(var e=k.length-1;e>=0;e--){var r=k[e];!1===r.modified&&(Array.isArray(r.base)?D(r)&&S(r):(n=r,t=Object.keys(n.base),o=Object.keys(n.proxy),function(e,r){if(b(e,r))return!0;if("object"!==(void 0===e?"undefined":i(e))||null===e||"object"!==(void 0===r?"undefined":i(r))||null===r)return!1;var n=Object.keys(e),t=Object.keys(r);if(n.length!==t.length)return!1;for(var o=0;o3)throw new Error("produce expects 1 to 3 arguments, got "+arguments.length);if("function"==typeof e){if("function"==typeof r)throw new Error("if first argument is a function (curried invocation), the second argument to produce cannot be a function");var t=r,o=e;return function(){var e=arguments;return R(void 0===e[0]&&void 0!==t?t:e[0],function(r){return e[0]=r,o.apply(r,e)})}}if("function"!=typeof r)throw new Error("if first argument is not a function, the second argument to produce should be a function");if(void 0!==n&&"function"!=typeof n)throw new Error("the third argument of a producer should not be set or a function");if("object"!==(void 0===e?"undefined":i(e))||null===e){var a=r(e);return void 0===a?e:F(a)}if(!d(e))throw new Error("the first argument to an immer producer should be a primitive, plain object or array, got "+(void 0===e?"undefined":i(e))+': "'+e+'"');return F(p?function(e,r,n){if(s(e)){var t=r.call(e,e);return void 0===t?e:t}var o=w;w=[];var i=n&&[],a=n&&[];try{var c=A(void 0,e),p=r.call(c,c),d=void 0;if(void 0!==p&&p!==c){if(c[f].modified)throw new Error(u);d=m(p),i&&(i.push({op:"replace",path:[],value:d}),a.push({op:"replace",path:[],value:e}))}else d=m(c,[],i,a);return v(w,function(e,r){return r.revoke()}),n&&n(i,a),d}finally{w=o}}(e,r,n):M(e,r,n))}function F(e){return e===a?void 0:e}var K=R(function(e,r){for(var n=function(n){var t=r[n];if(0===t.path.length&&"replace"===t.op)e=t.value;else{var o=t.path.slice(),i=o.pop(),a=o.reduce(function(e,r){if(!e)throw new Error("Cannot apply patch, path doesn't resolve: "+t.path.join("/"));return e[r]},e);if(!a)throw new Error("Cannot apply patch, path doesn't resolve: "+t.path.join("/"));switch(t.op){case"replace":case"add":a[i]=t.value;break;case"remove":if(Array.isArray(a)){if(i!==a.length-1)throw new Error("Remove can only remove the last key of an array, index: "+i+", length: "+a.length);a.length-=1}else delete a[i];break;default:throw new Error("Unsupported patch operation: "+t.op)}}},t=0;t