LocalCDN-Firefox-Chrome-Brave/resources/knockout.mapping/2.4.1/knockout.mapping.min.jsm

1 line
10 KiB
JavaScript

(function(a){if(typeof require==="function"&&typeof exports==="object"&&typeof module==="object"){a(require("knockout"),exports)}else{if(typeof define==="function"&&define.amd){define(["knockout","exports"],a)}else{a(ko,ko.mapping={})}}}(function(b,B){var d=true;var n="__ko_mapping__";var i=b.dependentObservable;var q=0;var m;var v;var a=["create","update","key","arrayChanged"];var r={};var h={include:["_destroy"],ignore:[],copy:[],observe:[]};var w=h;function o(C,H){var G={};for(var F=C.length-1;F>=0;--F){G[C[F]]=C[F]}for(var F=H.length-1;F>=0;--F){G[H[F]]=H[F]}var E=[];for(var D in G){E.push(G[D])}return E}function p(C,F){var G;for(var D in F){if(F.hasOwnProperty(D)&&F[D]){G=B.getType(C[D]);if(D&&C[D]&&G!=="array"&&G!=="string"){p(C[D],F[D])}else{var E=B.getType(C[D])==="array"&&B.getType(F[D])==="array";if(E){C[D]=o(C[D],F[D])}else{C[D]=F[D]}}}}}function g(E,D){var C={};p(C,E);p(C,D);return C}B.isMapped=function(D){var C=b.utils.unwrapObservable(D);return C&&C[n]};B.fromJS=function(D){if(arguments.length==0){throw new Error("When calling ko.fromJS, pass the object you want to convert.")}try{if(!q++){m=[];v=new c()}var F;var H;if(arguments.length==2){if(arguments[1][n]){H=arguments[1]}else{F=arguments[1]}}if(arguments.length==3){F=arguments[1];H=arguments[2]}if(H){F=g(F,H[n])}F=s(F);var C=x(H,D,F);if(H){C=H}if(!--q){while(m.length){var E=m.pop();if(E){E();E.__DO.throttleEvaluation=E.throttleEvaluation}}}C[n]=g(C[n],F);return C}catch(G){q=0;throw G}};B.fromJSON=function(D){var C=b.utils.parseJson(D);arguments[0]=C;return B.fromJS.apply(this,arguments)};B.updateFromJS=function(C){throw new Error("ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!")};B.updateFromJSON=function(C){throw new Error("ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead. Please note that the order of parameters is different!")};B.toJS=function(D,C){if(!w){B.resetDefaultOptions()}if(arguments.length==0){throw new Error("When calling ko.mapping.toJS, pass the object you want to convert.")}if(B.getType(w.ignore)!=="array"){throw new Error("ko.mapping.defaultOptions().ignore should be an array.")}if(B.getType(w.include)!=="array"){throw new Error("ko.mapping.defaultOptions().include should be an array.")}if(B.getType(w.copy)!=="array"){throw new Error("ko.mapping.defaultOptions().copy should be an array.")}C=s(C,D[n]);return B.visitModel(D,function(E){return b.utils.unwrapObservable(E)},C)};B.toJSON=function(E,C){var D=B.toJS(E,C);return b.utils.stringifyJson(D)};B.defaultOptions=function(){if(arguments.length>0){w=arguments[0]}else{return w}};B.resetDefaultOptions=function(){w={include:h.include.slice(0),ignore:h.ignore.slice(0),copy:h.copy.slice(0)}};B.getType=function(C){if((C)&&(typeof(C)==="object")){if(C.constructor===Date){return"date"}if(C.constructor===Array){return"array"}}return typeof C};function s(F,C){var D=g({},F);for(var E=a.length-1;E>=0;E--){var G=a[E];if(!D[G]){continue}if(!(D[""] instanceof Object)){D[""]={}}D[""][G]=D[G];delete D[G]}if(C){D.ignore=k(C.ignore,D.ignore);D.include=k(C.include,D.include);D.copy=k(C.copy,D.copy);D.observe=k(C.observe,D.observe)}D.ignore=k(D.ignore,w.ignore);D.include=k(D.include,w.include);D.copy=k(D.copy,w.copy);D.observe=k(D.observe,w.observe);D.mappedProperties=D.mappedProperties||{};D.copiedProperties=D.copiedProperties||{};return D}function k(D,C){if(B.getType(D)!=="array"){if(B.getType(D)==="undefined"){D=[]}else{D=[D]}}if(B.getType(C)!=="array"){if(B.getType(C)==="undefined"){C=[]}else{C=[C]}}return b.utils.arrayGetDistinctValues(D.concat(C))}function f(D,F){var E=b.dependentObservable;b.dependentObservable=function(M,G,J){J=J||{};if(M&&typeof M=="object"){J=M}var I=J.deferEvaluation;var H=false;var L=function(N){var P=b.dependentObservable;b.dependentObservable=i;var Q=b.isWriteableObservable(N);b.dependentObservable=P;var O=i({read:function(){if(!H){b.utils.arrayRemoveItem(D,N);H=true}return N.apply(N,arguments)},write:Q&&function(R){return N(R)},deferEvaluation:true});if(d){O._wrapper=true}O.__DO=N;return O};J.deferEvaluation=true;var K=new i(M,G,J);if(!I){K=L(K);D.push(K)}return K};b.dependentObservable.fn=i.fn;b.computed=b.dependentObservable;var C=F();b.dependentObservable=E;b.computed=b.dependentObservable;return C}function x(ai,E,T,aj,H,C,al){var S=B.getType(b.utils.unwrapObservable(E))==="array";C=C||"";if(B.isMapped(ai)){var G=b.utils.unwrapObservable(ai)[n];T=g(G,T)}var ae={data:E,parent:al||H};var R=function(){return T[aj]&&T[aj].create instanceof Function};var J=function(an){return f(m,function(){if(b.utils.unwrapObservable(H) instanceof Array){return T[aj].create({data:an||ae.data,parent:ae.parent,skip:r})}else{return T[aj].create({data:an||ae.data,parent:ae.parent})}})};var aa=function(){return T[aj]&&T[aj].update instanceof Function};var P=function(ao,an){var ap={data:an||ae.data,parent:ae.parent,target:b.utils.unwrapObservable(ao)};if(b.isWriteableObservable(ao)){ap.observable=ao}return T[aj].update(ap)};var Y=v.get(E);if(Y){return Y}aj=aj||"";if(!S){if(!t(E)){switch(B.getType(E)){case"function":if(aa()){if(b.isWriteableObservable(E)){E(P(E));ai=E}else{ai=P(E)}}else{ai=E}break;default:if(b.isWriteableObservable(ai)){if(aa()){var V=P(ai);ai(V);return V}else{var V=b.utils.unwrapObservable(E);ai(V);return V}}else{var ab=R()||aa();if(R()){ai=J()}else{ai=b.observable(b.utils.unwrapObservable(E))}if(aa()){ai(P(ai))}if(ab){return ai}}}}else{ai=b.utils.unwrapObservable(ai);if(!ai){if(R()){var N=J();if(aa()){N=P(N)}return N}else{if(aa()){return P(N)}ai={}}}if(aa()){ai=P(ai)}v.save(E,ai);if(aa()){return ai}z(E,function(ao){var ar=C.length?C+"."+ao:ao;if(b.utils.arrayIndexOf(T.ignore,ar)!=-1){return}if(b.utils.arrayIndexOf(T.copy,ar)!=-1){ai[ao]=E[ao];return}if(typeof E[ao]!="object"&&typeof E[ao]!="array"&&T.observe.length>0&&b.utils.arrayIndexOf(T.observe,ar)==-1){ai[ao]=E[ao];T.copiedProperties[ar]=true;return}var aq=v.get(E[ao]);var an=x(ai[ao],E[ao],T,ao,ai,ar,ai);var ap=aq||an;if(T.observe.length>0&&b.utils.arrayIndexOf(T.observe,ar)==-1){ai[ao]=ap();T.copiedProperties[ar]=true;return}if(b.isWriteableObservable(ai[ao])){ap=b.utils.unwrapObservable(ap);if(ai[ao]()!==ap){ai[ao](ap)}}else{ap=ai[ao]===undefined?ap:b.utils.unwrapObservable(ap);ai[ao]=ap}T.mappedProperties[ar]=true})}}else{var O=[];var L=false;var U=function(an){return an};if(T[aj]&&T[aj].key){U=T[aj].key;L=true}if(!b.isObservable(ai)){ai=b.observableArray([]);ai.mappedRemove=function(ao){var an=typeof ao=="function"?ao:function(ap){return ap===U(ao)};return ai.remove(function(ap){return an(U(ap))})};ai.mappedRemoveAll=function(ao){var an=u(ao,U);return ai.remove(function(ap){return b.utils.arrayIndexOf(an,U(ap))!=-1})};ai.mappedDestroy=function(ao){var an=typeof ao=="function"?ao:function(ap){return ap===U(ao)};return ai.destroy(function(ap){return an(U(ap))})};ai.mappedDestroyAll=function(ao){var an=u(ao,U);return ai.destroy(function(ap){return b.utils.arrayIndexOf(an,U(ap))!=-1})};ai.mappedIndexOf=function(ap){var ao=u(ai(),U);var an=U(ap);return b.utils.arrayIndexOf(ao,an)};ai.mappedGet=function(an){return ai()[ai.mappedIndexOf(an)]};ai.mappedCreate=function(ao){if(ai.mappedIndexOf(ao)!==-1){throw new Error("There already is an object with the key that you specified.")}var an=R()?J(ao):ao;if(aa()){var ap=P(an,ao);if(b.isWriteableObservable(an)){an(ap)}else{an=ap}}ai.push(an);return an}}var W=u(b.utils.unwrapObservable(ai),U).sort();var K=u(E,U);if(L){K.sort()}var ac=b.utils.compareArrays(W,K);var am={};var ah,ag;var F=b.utils.unwrapObservable(E);var Q={};var ad=true;for(ah=0,ag=F.length;ah<ag;ah++){var M=U(F[ah]);if(M===undefined||M instanceof Object){ad=false;break}Q[M]=F[ah]}var ak=[];var I=0;for(ah=0,ag=ac.length;ah<ag;ah++){var M=ac[ah];var D;var af=C+"["+ah+"]";switch(M.status){case"added":var X=ad?Q[M.value]:l(b.utils.unwrapObservable(E),M.value,U);D=x(undefined,X,T,aj,ai,af,H);if(!R()){D=b.utils.unwrapObservable(D)}var Z=y(b.utils.unwrapObservable(E),X,am);if(D===r){I++}else{ak[Z-I]=D}am[Z]=true;break;case"retained":var X=ad?Q[M.value]:l(b.utils.unwrapObservable(E),M.value,U);D=l(ai,M.value,U);x(D,X,T,aj,ai,af,H);var Z=y(b.utils.unwrapObservable(E),X,am);ak[Z]=D;am[Z]=true;break;case"deleted":D=l(ai,M.value,U);break}O.push({event:M.status,item:D})}ai(ak);if(T[aj]&&T[aj].arrayChanged){b.utils.arrayForEach(O,function(an){T[aj].arrayChanged(an.event,an.item)})}}return ai}function y(G,F,E){for(var D=0,C=G.length;D<C;D++){if(E[D]===true){continue}if(G[D]===F){return D}}return null}function e(C,E){var D;if(E){D=E(C)}if(B.getType(D)==="undefined"){D=C}return b.utils.unwrapObservable(D)}function l(H,E,G){H=b.utils.unwrapObservable(H);for(var D=0,C=H.length;D<C;D++){var F=H[D];if(e(F,G)===E){return F}}throw new Error("When calling ko.update*, the key '"+E+"' was not found!")}function u(D,C){return b.utils.arrayMap(b.utils.unwrapObservable(D),function(E){if(C){return e(E,C)}else{return E}})}function z(E,F){if(B.getType(E)==="array"){for(var D=0;D<E.length;D++){F(D)}}else{for(var C in E){F(C)}}}function t(C){var D=B.getType(C);return((D==="object")||(D==="array"))&&(C!==null)}function j(F,E,D){var C=F||"";if(B.getType(E)==="array"){if(F){C+="["+D+"]"}}else{if(F){C+="."}C+=D}return C}B.visitModel=function(F,H,D){D=D||{};D.visitedObjects=D.visitedObjects||new c();var G;var C=b.utils.unwrapObservable(F);if(!t(C)){return H(F,D.parentName)}else{D=s(D,C[n]);H(F,D.parentName);G=B.getType(C)==="array"?[]:{}}D.visitedObjects.save(F,G);var E=D.parentName;z(C,function(K){if(D.ignore&&b.utils.arrayIndexOf(D.ignore,K)!=-1){return}var I=C[K];D.parentName=j(E,C,K);if(b.utils.arrayIndexOf(D.copy,K)===-1){if(b.utils.arrayIndexOf(D.include,K)===-1){if(C[n]&&C[n].mappedProperties&&!C[n].mappedProperties[K]&&C[n].copiedProperties&&!C[n].copiedProperties[K]&&!(B.getType(C)==="array")){return}}}var J;switch(B.getType(b.utils.unwrapObservable(I))){case"object":case"array":case"undefined":var L=D.visitedObjects.get(I);G[K]=(B.getType(L)!=="undefined")?L:B.visitModel(I,H,D);break;default:G[K]=H(I,D.parentName)}});return G};function A(){var D=[];var C=[];this.save=function(F,G){var E=b.utils.arrayIndexOf(D,F);if(E>=0){C[E]=G}else{D.push(F);C.push(G)}};this.get=function(F){var E=b.utils.arrayIndexOf(D,F);var G=(E>=0)?C[E]:undefined;return G}}function c(){var C={};var D=function(F){var E;try{E=F}catch(G){E="$$$"}var H=C[E];if(H===undefined){H=new A();C[E]=H}return H};this.save=function(E,F){D(E).save(E,F)};this.get=function(E){return D(E).get(E)}}}));