// 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___30366 = arguments.length;
var i__24370__auto___30367 = (0);
while(true){
if((i__24370__auto___30367 < len__24369__auto___30366)){
args__24376__auto__.push((arguments[i__24370__auto___30367]));

var G__30368 = (i__24370__auto___30367 + (1));
i__24370__auto___30367 = G__30368;
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 (seq30364){
var G__30365 = cljs.core.first.call(null,seq30364);
var seq30364__$1 = cljs.core.next.call(null,seq30364);
return garden.util.format.cljs$core$IFn$_invoke$arity$variadic(G__30365,seq30364__$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___30370 = arguments.length;
var i__24370__auto___30371 = (0);
while(true){
if((i__24370__auto___30371 < len__24369__auto___30370)){
args__24376__auto__.push((arguments[i__24370__auto___30371]));

var G__30372 = (i__24370__auto___30371 + (1));
i__24370__auto___30371 = G__30372;
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 (seq30369){
return garden.util.as_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq30369));
});

/**
 * 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___30379 = arguments.length;
var i__24370__auto___30380 = (0);
while(true){
if((i__24370__auto___30380 < len__24369__auto___30379)){
args__24376__auto__.push((arguments[i__24370__auto___30380]));

var G__30381 = (i__24370__auto___30380 + (1));
i__24370__auto___30380 = G__30381;
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__30375){
var vec__30376 = p__30375;
var radix = cljs.core.nth.call(null,vec__30376,(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 (seq30373){
var G__30374 = cljs.core.first.call(null,seq30373);
var seq30373__$1 = cljs.core.next.call(null,seq30373);
return garden.util.string__GT_int.cljs$core$IFn$_invoke$arity$variadic(G__30374,seq30373__$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___30388 = arguments.length;
var i__24370__auto___30389 = (0);
while(true){
if((i__24370__auto___30389 < len__24369__auto___30388)){
args__24376__auto__.push((arguments[i__24370__auto___30389]));

var G__30390 = (i__24370__auto___30389 + (1));
i__24370__auto___30389 = G__30390;
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__30384){
var vec__30385 = p__30384;
var radix = cljs.core.nth.call(null,vec__30385,(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 (seq30382){
var G__30383 = cljs.core.first.call(null,seq30382);
var seq30382__$1 = cljs.core.next.call(null,seq30382);
return garden.util.int__GT_string.cljs$core$IFn$_invoke$arity$variadic(G__30383,seq30382__$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__30395(s__30396){
return (new cljs.core.LazySeq(null,(function (){
var s__30396__$1 = s__30396;
while(true){
var temp__5278__auto__ = cljs.core.seq.call(null,s__30396__$1);
if(temp__5278__auto__){
var s__30396__$2 = temp__5278__auto__;
if(cljs.core.chunked_seq_QMARK_.call(null,s__30396__$2)){
var c__24008__auto__ = cljs.core.chunk_first.call(null,s__30396__$2);
var size__24009__auto__ = cljs.core.count.call(null,c__24008__auto__);
var b__30398 = cljs.core.chunk_buffer.call(null,size__24009__auto__);
if((function (){var i__30397 = (0);
while(true){
if((i__30397 < size__24009__auto__)){
var x = cljs.core._nth.call(null,c__24008__auto__,i__30397);
cljs.core.chunk_append.call(null,b__30398,((cljs.core.sequential_QMARK_.call(null,x))?garden.util.space_join.call(null,x):garden.util.to_str.call(null,x)));

var G__30399 = (i__30397 + (1));
i__30397 = G__30399;
continue;
} else {
return true;
}
break;
}
})()){
return cljs.core.chunk_cons.call(null,cljs.core.chunk.call(null,b__30398),garden$util$comma_join_$_iter__30395.call(null,cljs.core.chunk_rest.call(null,s__30396__$2)));
} else {
return cljs.core.chunk_cons.call(null,cljs.core.chunk.call(null,b__30398),null);
}
} else {
var x = cljs.core.first.call(null,s__30396__$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__30395.call(null,cljs.core.rest.call(null,s__30396__$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__30403 = (((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__30403,(0),null);
var b__$1 = cljs.core.nth.call(null,vec__30403,(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___30409 = arguments.length;
var i__24370__auto___30410 = (0);
while(true){
if((i__24370__auto___30410 < len__24369__auto___30409)){
args__24376__auto__.push((arguments[i__24370__auto___30410]));

var G__30411 = (i__24370__auto___30410 + (1));
i__24370__auto___30410 = G__30411;
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 (seq30406){
var G__30407 = cljs.core.first.call(null,seq30406);
var seq30406__$1 = cljs.core.next.call(null,seq30406);
var G__30408 = cljs.core.first.call(null,seq30406__$1);
var seq30406__$2 = cljs.core.next.call(null,seq30406__$1);
return garden.util.average.cljs$core$IFn$_invoke$arity$variadic(G__30407,G__30408,seq30406__$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___30413 = arguments.length;
var i__24370__auto___30414 = (0);
while(true){
if((i__24370__auto___30414 < len__24369__auto___30413)){
args__24376__auto__.push((arguments[i__24370__auto___30414]));

var G__30415 = (i__24370__auto___30414 + (1));
i__24370__auto___30414 = G__30415;
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__30416 = (i - (1));
var G__30417 = cljs.core.assoc.call(null,v_seqs__$2,i,v_original_seqs.call(null,i));
i = G__30416;
v_seqs__$2 = G__30417;
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 (seq30412){
return garden.util.cartesian_product.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq30412));
});

