// Compiled by ClojureScript 1.9.562 {}
goog.provide('garden.util');
goog.require('cljs.core');
goog.require('clojure.string');
goog.require('garden.types');
goog.require('goog.string');
goog.require('goog.string.format');
/**
 * Formats a string using goog.string.format.
 */
garden.util.format = (function garden$util$format(var_args){
var args__24376__auto__ = [];
var len__24369__auto___35448 = arguments.length;
var i__24370__auto___35449 = (0);
while(true){
if((i__24370__auto___35449 < len__24369__auto___35448)){
args__24376__auto__.push((arguments[i__24370__auto___35449]));

var G__35450 = (i__24370__auto___35449 + (1));
i__24370__auto___35449 = G__35450;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((1) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__auto__.slice((1)),(0),null)):null);
return garden.util.format.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__24377__auto__);
});

garden.util.format.cljs$core$IFn$_invoke$arity$variadic = (function (fmt,args){
return cljs.core.apply.call(null,goog.string.format,fmt,args);
});

garden.util.format.cljs$lang$maxFixedArity = (1);

garden.util.format.cljs$lang$applyTo = (function (seq35446){
var G__35447 = cljs.core.first.call(null,seq35446);
var seq35446__$1 = cljs.core.next.call(null,seq35446);
return garden.util.format.cljs$core$IFn$_invoke$arity$variadic(G__35447,seq35446__$1);
});


/**
 * @interface
 */
garden.util.ToString = function(){};

/**
 * Convert a value into a string.
 */
garden.util.to_str = (function garden$util$to_str(this$){
if((!((this$ == null))) && (!((this$.garden$util$ToString$to_str$arity$1 == null)))){
return this$.garden$util$ToString$to_str$arity$1(this$);
} else {
var x__23866__auto__ = (((this$ == null))?null:this$);
var m__23867__auto__ = (garden.util.to_str[goog.typeOf(x__23866__auto__)]);
if(!((m__23867__auto__ == null))){
return m__23867__auto__.call(null,this$);
} else {
var m__23867__auto____$1 = (garden.util.to_str["_"]);
if(!((m__23867__auto____$1 == null))){
return m__23867__auto____$1.call(null,this$);
} else {
throw cljs.core.missing_protocol.call(null,"ToString.to-str",this$);
}
}
}
});

cljs.core.Keyword.prototype.garden$util$ToString$ = cljs.core.PROTOCOL_SENTINEL;

cljs.core.Keyword.prototype.garden$util$ToString$to_str$arity$1 = (function (this$){
var this$__$1 = this;
return cljs.core.name.call(null,this$__$1);
});

(garden.util.ToString["_"] = true);

(garden.util.to_str["_"] = (function (this$){
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(this$)].join('');
}));

(garden.util.ToString["null"] = true);

(garden.util.to_str["null"] = (function (this$){
return "";
}));
/**
 * Convert a variable number of values into strings.
 */
garden.util.as_str = (function garden$util$as_str(var_args){
var args__24376__auto__ = [];
var len__24369__auto___35452 = arguments.length;
var i__24370__auto___35453 = (0);
while(true){
if((i__24370__auto___35453 < len__24369__auto___35452)){
args__24376__auto__.push((arguments[i__24370__auto___35453]));

var G__35454 = (i__24370__auto___35453 + (1));
i__24370__auto___35453 = G__35454;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((0) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__auto__.slice((0)),(0),null)):null);
return garden.util.as_str.cljs$core$IFn$_invoke$arity$variadic(argseq__24377__auto__);
});

garden.util.as_str.cljs$core$IFn$_invoke$arity$variadic = (function (args){
return cljs.core.apply.call(null,cljs.core.str,cljs.core.map.call(null,garden.util.to_str,args));
});

garden.util.as_str.cljs$lang$maxFixedArity = (0);

garden.util.as_str.cljs$lang$applyTo = (function (seq35451){
return garden.util.as_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq35451));
});

/**
 * Convert a string to an integer with optional base.
 */
garden.util.string__GT_int = (function garden$util$string__GT_int(var_args){
var args__24376__auto__ = [];
var len__24369__auto___35461 = arguments.length;
var i__24370__auto___35462 = (0);
while(true){
if((i__24370__auto___35462 < len__24369__auto___35461)){
args__24376__auto__.push((arguments[i__24370__auto___35462]));

var G__35463 = (i__24370__auto___35462 + (1));
i__24370__auto___35462 = G__35463;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((1) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__auto__.slice((1)),(0),null)):null);
return garden.util.string__GT_int.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__24377__auto__);
});

garden.util.string__GT_int.cljs$core$IFn$_invoke$arity$variadic = (function (s,p__35457){
var vec__35458 = p__35457;
var radix = cljs.core.nth.call(null,vec__35458,(0),null);
var radix__$1 = (function (){var or__23148__auto__ = radix;
if(cljs.core.truth_(or__23148__auto__)){
return or__23148__auto__;
} else {
return (10);
}
})();
return parseInt(s,radix__$1);
});

garden.util.string__GT_int.cljs$lang$maxFixedArity = (1);

garden.util.string__GT_int.cljs$lang$applyTo = (function (seq35455){
var G__35456 = cljs.core.first.call(null,seq35455);
var seq35455__$1 = cljs.core.next.call(null,seq35455);
return garden.util.string__GT_int.cljs$core$IFn$_invoke$arity$variadic(G__35456,seq35455__$1);
});

/**
 * Convert an integer to a string with optional base.
 */
garden.util.int__GT_string = (function garden$util$int__GT_string(var_args){
var args__24376__auto__ = [];
var len__24369__auto___35470 = arguments.length;
var i__24370__auto___35471 = (0);
while(true){
if((i__24370__auto___35471 < len__24369__auto___35470)){
args__24376__auto__.push((arguments[i__24370__auto___35471]));

var G__35472 = (i__24370__auto___35471 + (1));
i__24370__auto___35471 = G__35472;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((1) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__auto__.slice((1)),(0),null)):null);
return garden.util.int__GT_string.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__24377__auto__);
});

garden.util.int__GT_string.cljs$core$IFn$_invoke$arity$variadic = (function (i,p__35466){
var vec__35467 = p__35466;
var radix = cljs.core.nth.call(null,vec__35467,(0),null);
var radix__$1 = (function (){var or__23148__auto__ = radix;
if(cljs.core.truth_(or__23148__auto__)){
return or__23148__auto__;
} else {
return (10);
}
})();
return i.toString(radix__$1);
});

garden.util.int__GT_string.cljs$lang$maxFixedArity = (1);

garden.util.int__GT_string.cljs$lang$applyTo = (function (seq35464){
var G__35465 = cljs.core.first.call(null,seq35464);
var seq35464__$1 = cljs.core.next.call(null,seq35464);
return garden.util.int__GT_string.cljs$core$IFn$_invoke$arity$variadic(G__35465,seq35464__$1);
});

/**
 * Return a space separated list of values.
 */
garden.util.space_join = (function garden$util$space_join(xs){
return clojure.string.join.call(null," ",cljs.core.map.call(null,garden.util.to_str,xs));
});
/**
 * Return a comma separated list of values. Subsequences are joined with
 * spaces.
 */
garden.util.comma_join = (function garden$util$comma_join(xs){
var ys = (function (){var iter__24010__auto__ = (function garden$util$comma_join_$_iter__35477(s__35478){
return (new cljs.core.LazySeq(null,(function (){
var s__35478__$1 = s__35478;
while(true){
var temp__5278__auto__ = cljs.core.seq.call(null,s__35478__$1);
if(temp__5278__auto__){
var s__35478__$2 = temp__5278__auto__;
if(cljs.core.chunked_seq_QMARK_.call(null,s__35478__$2)){
var c__24008__auto__ = cljs.core.chunk_first.call(null,s__35478__$2);
var size__24009__auto__ = cljs.core.count.call(null,c__24008__auto__);
var b__35480 = cljs.core.chunk_buffer.call(null,size__24009__auto__);
if((function (){var i__35479 = (0);
while(true){
if((i__35479 < size__24009__auto__)){
var x = cljs.core._nth.call(null,c__24008__auto__,i__35479);
cljs.core.chunk_append.call(null,b__35480,((cljs.core.sequential_QMARK_.call(null,x))?garden.util.space_join.call(null,x):garden.util.to_str.call(null,x)));

var G__35481 = (i__35479 + (1));
i__35479 = G__35481;
continue;
} else {
return true;
}
break;
}
})()){
return cljs.core.chunk_cons.call(null,cljs.core.chunk.call(null,b__35480),garden$util$comma_join_$_iter__35477.call(null,cljs.core.chunk_rest.call(null,s__35478__$2)));
} else {
return cljs.core.chunk_cons.call(null,cljs.core.chunk.call(null,b__35480),null);
}
} else {
var x = cljs.core.first.call(null,s__35478__$2);
return cljs.core.cons.call(null,((cljs.core.sequential_QMARK_.call(null,x))?garden.util.space_join.call(null,x):garden.util.to_str.call(null,x)),garden$util$comma_join_$_iter__35477.call(null,cljs.core.rest.call(null,s__35478__$2)));
}
} else {
return null;
}
break;
}
}),null,null));
});
return iter__24010__auto__.call(null,xs);
})();
return clojure.string.join.call(null,", ",ys);
});
/**
 * Wrap a string with double quotes.
 */
garden.util.wrap_quotes = (function garden$util$wrap_quotes(s){
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1("\""),cljs.core.str.cljs$core$IFn$_invoke$arity$1(s),cljs.core.str.cljs$core$IFn$_invoke$arity$1("\"")].join('');
});
/**
 * True if `(map? x)` and `x` does not satisfy `clojure.lang.IRecord`.
 */
garden.util.hash_map_QMARK_ = (function garden$util$hash_map_QMARK_(x){
return (cljs.core.map_QMARK_.call(null,x)) && (!(cljs.core.record_QMARK_.call(null,x)));
});
/**
 * Alias to `vector?`.
 */
garden.util.rule_QMARK_ = cljs.core.vector_QMARK_;
/**
 * Alias to `hash-map?`.
 */
garden.util.declaration_QMARK_ = garden.util.hash_map_QMARK_;
garden.util.at_rule_QMARK_ = (function garden$util$at_rule_QMARK_(x){
return (x instanceof garden.types.CSSAtRule);
});
/**
 * True if `x` is a CSS `@media` rule.
 */
garden.util.at_media_QMARK_ = (function garden$util$at_media_QMARK_(x){
var and__23136__auto__ = garden.util.at_rule_QMARK_.call(null,x);
if(cljs.core.truth_(and__23136__auto__)){
return cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"identifier","identifier",-805503498).cljs$core$IFn$_invoke$arity$1(x),new cljs.core.Keyword(null,"media","media",-1066138403));
} else {
return and__23136__auto__;
}
});
/**
 * True if `x` is a CSS `@keyframes` rule.
 */
garden.util.at_keyframes_QMARK_ = (function garden$util$at_keyframes_QMARK_(x){
var and__23136__auto__ = garden.util.at_rule_QMARK_.call(null,x);
if(cljs.core.truth_(and__23136__auto__)){
return cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"identifier","identifier",-805503498).cljs$core$IFn$_invoke$arity$1(x),new cljs.core.Keyword(null,"keyframes","keyframes",-1437976012));
} else {
return and__23136__auto__;
}
});
/**
 * True if `x` is a CSS `@import` rule.
 */
garden.util.at_import_QMARK_ = (function garden$util$at_import_QMARK_(x){
var and__23136__auto__ = garden.util.at_rule_QMARK_.call(null,x);
if(cljs.core.truth_(and__23136__auto__)){
return cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"identifier","identifier",-805503498).cljs$core$IFn$_invoke$arity$1(x),new cljs.core.Keyword(null,"import","import",-1399500709));
} else {
return and__23136__auto__;
}
});
/**
 * Attach a CSS style prefix to s.
 */
garden.util.prefix = (function garden$util$prefix(p,s){
var p__$1 = garden.util.to_str.call(null,p);
if(cljs.core._EQ_.call(null,"-",cljs.core.last.call(null,p__$1))){
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(p__$1),cljs.core.str.cljs$core$IFn$_invoke$arity$1(s)].join('');
} else {
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(p__$1),cljs.core.str.cljs$core$IFn$_invoke$arity$1("-"),cljs.core.str.cljs$core$IFn$_invoke$arity$1(s)].join('');
}
});
/**
 * Attach a CSS vendor prefix to s.
 */
garden.util.vendor_prefix = (function garden$util$vendor_prefix(p,s){
var p__$1 = garden.util.to_str.call(null,p);
if(cljs.core._EQ_.call(null,"-",cljs.core.first.call(null,p__$1))){
return garden.util.prefix.call(null,p__$1,s);
} else {
return garden.util.prefix.call(null,[cljs.core.str.cljs$core$IFn$_invoke$arity$1("-"),cljs.core.str.cljs$core$IFn$_invoke$arity$1(p__$1)].join(''),s);
}
});
/**
 * True if n is a natural number.
 */
garden.util.natural_QMARK_ = (function garden$util$natural_QMARK_(n){
return (cljs.core.integer_QMARK_.call(null,n)) && ((n > (0)));
});
/**
 * True if n is a number between a and b.
 */
garden.util.between_QMARK_ = (function garden$util$between_QMARK_(n,a,b){
var bottom = (function (){var x__23493__auto__ = a;
var y__23494__auto__ = b;
return ((x__23493__auto__ < y__23494__auto__) ? x__23493__auto__ : y__23494__auto__);
})();
var top = (function (){var x__23486__auto__ = a;
var y__23487__auto__ = b;
return ((x__23486__auto__ > y__23487__auto__) ? x__23486__auto__ : y__23487__auto__);
})();
return ((n >= bottom)) && ((n <= top));
});
/**
 * Return a number such that n is no less than a and no more than b.
 */
garden.util.clip = (function garden$util$clip(a,b,n){
var vec__35485 = (((a <= b))?new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [a,b], null):new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [b,a], null));
var a__$1 = cljs.core.nth.call(null,vec__35485,(0),null);
var b__$1 = cljs.core.nth.call(null,vec__35485,(1),null);
var x__23486__auto__ = a__$1;
var y__23487__auto__ = (function (){var x__23493__auto__ = b__$1;
var y__23494__auto__ = n;
return ((x__23493__auto__ < y__23494__auto__) ? x__23493__auto__ : y__23494__auto__);
})();
return ((x__23486__auto__ > y__23487__auto__) ? x__23486__auto__ : y__23487__auto__);
});
/**
 * Return the average of two or more numbers.
 */
garden.util.average = (function garden$util$average(var_args){
var args__24376__auto__ = [];
var len__24369__auto___35491 = arguments.length;
var i__24370__auto___35492 = (0);
while(true){
if((i__24370__auto___35492 < len__24369__auto___35491)){
args__24376__auto__.push((arguments[i__24370__auto___35492]));

var G__35493 = (i__24370__auto___35492 + (1));
i__24370__auto___35492 = G__35493;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((2) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__auto__.slice((2)),(0),null)):null);
return garden.util.average.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__24377__auto__);
});

garden.util.average.cljs$core$IFn$_invoke$arity$variadic = (function (n,m,more){
return (cljs.core.apply.call(null,cljs.core._PLUS_,n,m,more) / (2.0 + cljs.core.count.call(null,more)));
});

garden.util.average.cljs$lang$maxFixedArity = (2);

garden.util.average.cljs$lang$applyTo = (function (seq35488){
var G__35489 = cljs.core.first.call(null,seq35488);
var seq35488__$1 = cljs.core.next.call(null,seq35488);
var G__35490 = cljs.core.first.call(null,seq35488__$1);
var seq35488__$2 = cljs.core.next.call(null,seq35488__$1);
return garden.util.average.cljs$core$IFn$_invoke$arity$variadic(G__35489,G__35490,seq35488__$2);
});

/**
 * All the ways to take one item from each sequence.
 */
garden.util.cartesian_product = (function garden$util$cartesian_product(var_args){
var args__24376__auto__ = [];
var len__24369__auto___35495 = arguments.length;
var i__24370__auto___35496 = (0);
while(true){
if((i__24370__auto___35496 < len__24369__auto___35495)){
args__24376__auto__.push((arguments[i__24370__auto___35496]));

var G__35497 = (i__24370__auto___35496 + (1));
i__24370__auto___35496 = G__35497;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((0) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__auto__.slice((0)),(0),null)):null);
return garden.util.cartesian_product.cljs$core$IFn$_invoke$arity$variadic(argseq__24377__auto__);
});

garden.util.cartesian_product.cljs$core$IFn$_invoke$arity$variadic = (function (seqs){
var v_original_seqs = cljs.core.vec.call(null,seqs);
var step = ((function (v_original_seqs){
return (function garden$util$step(v_seqs){
var increment = ((function (v_original_seqs){
return (function (v_seqs__$1){
var i = (cljs.core.count.call(null,v_seqs__$1) - (1));
var v_seqs__$2 = v_seqs__$1;
while(true){
if(cljs.core._EQ_.call(null,i,(-1))){
return null;
} else {
var temp__5276__auto__ = cljs.core.next.call(null,v_seqs__$2.call(null,i));
if(temp__5276__auto__){
var rst = temp__5276__auto__;
return cljs.core.assoc.call(null,v_seqs__$2,i,rst);
} else {
var G__35498 = (i - (1));
var G__35499 = cljs.core.assoc.call(null,v_seqs__$2,i,v_original_seqs.call(null,i));
i = G__35498;
v_seqs__$2 = G__35499;
continue;
}
}
break;
}
});})(v_original_seqs))
;
if(cljs.core.truth_(v_seqs)){
return cljs.core.cons.call(null,cljs.core.map.call(null,cljs.core.first,v_seqs),(new cljs.core.LazySeq(null,((function (increment,v_original_seqs){
return (function (){
return garden$util$step.call(null,increment.call(null,v_seqs));
});})(increment,v_original_seqs))
,null,null)));
} else {
return null;
}
});})(v_original_seqs))
;
if(cljs.core.every_QMARK_.call(null,cljs.core.seq,seqs)){
return (new cljs.core.LazySeq(null,((function (v_original_seqs,step){
return (function (){
return step.call(null,v_original_seqs);
});})(v_original_seqs,step))
,null,null));
} else {
return null;
}
});

garden.util.cartesian_product.cljs$lang$maxFixedArity = (0);

garden.util.cartesian_product.cljs$lang$applyTo = (function (seq35494){
return garden.util.cartesian_product.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq35494));
});

