goog.provide('replicant.string');

/**
 * @interface
 */
replicant.string.IStringifier = function(){};

var replicant$string$IStringifier$append$dyn_51623 = (function (this$,s){
var x__5373__auto__ = (((this$ == null))?null:this$);
var m__5374__auto__ = (replicant.string.append[goog.typeOf(x__5373__auto__)]);
if((!((m__5374__auto__ == null)))){
return (m__5374__auto__.cljs$core$IFn$_invoke$arity$2 ? m__5374__auto__.cljs$core$IFn$_invoke$arity$2(this$,s) : m__5374__auto__.call(null,this$,s));
} else {
var m__5372__auto__ = (replicant.string.append["_"]);
if((!((m__5372__auto__ == null)))){
return (m__5372__auto__.cljs$core$IFn$_invoke$arity$2 ? m__5372__auto__.cljs$core$IFn$_invoke$arity$2(this$,s) : m__5372__auto__.call(null,this$,s));
} else {
throw cljs.core.missing_protocol("IStringifier.append",this$);
}
}
});
replicant.string.append = (function replicant$string$append(this$,s){
if((((!((this$ == null)))) && ((!((this$.replicant$string$IStringifier$append$arity$2 == null)))))){
return this$.replicant$string$IStringifier$append$arity$2(this$,s);
} else {
return replicant$string$IStringifier$append$dyn_51623(this$,s);
}
});

var replicant$string$IStringifier$to_string$dyn_51628 = (function (this$){
var x__5373__auto__ = (((this$ == null))?null:this$);
var m__5374__auto__ = (replicant.string.to_string[goog.typeOf(x__5373__auto__)]);
if((!((m__5374__auto__ == null)))){
return (m__5374__auto__.cljs$core$IFn$_invoke$arity$1 ? m__5374__auto__.cljs$core$IFn$_invoke$arity$1(this$) : m__5374__auto__.call(null,this$));
} else {
var m__5372__auto__ = (replicant.string.to_string["_"]);
if((!((m__5372__auto__ == null)))){
return (m__5372__auto__.cljs$core$IFn$_invoke$arity$1 ? m__5372__auto__.cljs$core$IFn$_invoke$arity$1(this$) : m__5372__auto__.call(null,this$));
} else {
throw cljs.core.missing_protocol("IStringifier.to-string",this$);
}
}
});
replicant.string.to_string = (function replicant$string$to_string(this$){
if((((!((this$ == null)))) && ((!((this$.replicant$string$IStringifier$to_string$arity$1 == null)))))){
return this$.replicant$string$IStringifier$to_string$arity$1(this$);
} else {
return replicant$string$IStringifier$to_string$dyn_51628(this$);
}
});


/**
* @constructor
 * @implements {cljs.core.IMeta}
 * @implements {replicant.string.IStringifier}
 * @implements {cljs.core.IWithMeta}
*/
replicant.string.t_replicant$string51567 = (function (sb,meta51568){
this.sb = sb;
this.meta51568 = meta51568;
this.cljs$lang$protocol_mask$partition0$ = 393216;
this.cljs$lang$protocol_mask$partition1$ = 0;
});
(replicant.string.t_replicant$string51567.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_51569,meta51568__$1){
var self__ = this;
var _51569__$1 = this;
return (new replicant.string.t_replicant$string51567(self__.sb,meta51568__$1));
}));

(replicant.string.t_replicant$string51567.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_51569){
var self__ = this;
var _51569__$1 = this;
return self__.meta51568;
}));

(replicant.string.t_replicant$string51567.prototype.replicant$string$IStringifier$ = cljs.core.PROTOCOL_SENTINEL);

(replicant.string.t_replicant$string51567.prototype.replicant$string$IStringifier$append$arity$2 = (function (_,s){
var self__ = this;
var ___$1 = this;
return self__.sb.push(s);
}));

(replicant.string.t_replicant$string51567.prototype.replicant$string$IStringifier$to_string$arity$1 = (function (_){
var self__ = this;
var ___$1 = this;
return self__.sb.join("");
}));

(replicant.string.t_replicant$string51567.getBasis = (function (){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"sb","sb",-1249746442,null),new cljs.core.Symbol(null,"meta51568","meta51568",-1808895940,null)], null);
}));

(replicant.string.t_replicant$string51567.cljs$lang$type = true);

(replicant.string.t_replicant$string51567.cljs$lang$ctorStr = "replicant.string/t_replicant$string51567");

(replicant.string.t_replicant$string51567.cljs$lang$ctorPrWriter = (function (this__5310__auto__,writer__5311__auto__,opt__5312__auto__){
return cljs.core._write(writer__5311__auto__,"replicant.string/t_replicant$string51567");
}));

/**
 * Positional factory function for replicant.string/t_replicant$string51567.
 */
replicant.string.__GT_t_replicant$string51567 = (function replicant$string$__GT_t_replicant$string51567(sb,meta51568){
return (new replicant.string.t_replicant$string51567(sb,meta51568));
});


replicant.string.create_renderer = (function replicant$string$create_renderer(){
var sb = [];
return (new replicant.string.t_replicant$string51567(sb,cljs.core.PersistentArrayMap.EMPTY));
});
replicant.string.self_closing_QMARK_ = new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 15, ["track",null,"br",null,"img",null,"area",null,"base",null,"hr",null,"col",null,"param",null,"input",null,"link",null,"source",null,"audio",null,"meta",null,"wbr",null,"embed",null], null), null);
replicant.string.str_join = (function replicant$string$str_join(stringifier,sep,xs){
var G__51573_51629 = cljs.core.first(xs);
if((G__51573_51629 == null)){
} else {
replicant.string.append(stringifier,G__51573_51629);
}

var seq__51574_51630 = cljs.core.seq(cljs.core.rest(xs));
var chunk__51575_51631 = null;
var count__51576_51632 = (0);
var i__51577_51633 = (0);
while(true){
if((i__51577_51633 < count__51576_51632)){
var x_51634 = chunk__51575_51631.cljs$core$IIndexed$_nth$arity$2(null,i__51577_51633);
if(cljs.core.truth_(x_51634)){
replicant.string.append(stringifier,sep);

replicant.string.append(stringifier,x_51634);
} else {
}


var G__51635 = seq__51574_51630;
var G__51636 = chunk__51575_51631;
var G__51637 = count__51576_51632;
var G__51638 = (i__51577_51633 + (1));
seq__51574_51630 = G__51635;
chunk__51575_51631 = G__51636;
count__51576_51632 = G__51637;
i__51577_51633 = G__51638;
continue;
} else {
var temp__5804__auto___51639 = cljs.core.seq(seq__51574_51630);
if(temp__5804__auto___51639){
var seq__51574_51640__$1 = temp__5804__auto___51639;
if(cljs.core.chunked_seq_QMARK_(seq__51574_51640__$1)){
var c__5548__auto___51641 = cljs.core.chunk_first(seq__51574_51640__$1);
var G__51642 = cljs.core.chunk_rest(seq__51574_51640__$1);
var G__51643 = c__5548__auto___51641;
var G__51644 = cljs.core.count(c__5548__auto___51641);
var G__51645 = (0);
seq__51574_51630 = G__51642;
chunk__51575_51631 = G__51643;
count__51576_51632 = G__51644;
i__51577_51633 = G__51645;
continue;
} else {
var x_51646 = cljs.core.first(seq__51574_51640__$1);
if(cljs.core.truth_(x_51646)){
replicant.string.append(stringifier,sep);

replicant.string.append(stringifier,x_51646);
} else {
}


var G__51647 = cljs.core.next(seq__51574_51640__$1);
var G__51648 = null;
var G__51649 = (0);
var G__51650 = (0);
seq__51574_51630 = G__51647;
chunk__51575_51631 = G__51648;
count__51576_51632 = G__51649;
i__51577_51633 = G__51650;
continue;
}
} else {
}
}
break;
}

return stringifier;
});
replicant.string.render_attrs = (function replicant$string$render_attrs(stringifier,attrs){
return cljs.core.reduce_kv((function (_,k,v){
if(cljs.core.truth_((function (){var and__5023__auto__ = cljs.core.not((function (){var fexpr__51578 = new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"innerHTML","innerHTML",-1856751343),null,new cljs.core.Keyword(null,"on","on",173873944),null], null), null);
return (fexpr__51578.cljs$core$IFn$_invoke$arity$1 ? fexpr__51578.cljs$core$IFn$_invoke$arity$1(k) : fexpr__51578.call(null,k));
})());
if(and__5023__auto__){
var and__5023__auto____$1 = v;
if(cljs.core.truth_(and__5023__auto____$1)){
return (cljs.core.namespace(k) == null);
} else {
return and__5023__auto____$1;
}
} else {
return and__5023__auto__;
}
})())){
var v_51651__$1 = (function (){var G__51579 = v;
if((v instanceof cljs.core.Keyword)){
return cljs.core.name(G__51579);
} else {
return G__51579;
}
})();
replicant.string.append(stringifier," ");

var G__51580_51652 = k;
var G__51580_51653__$1 = (((G__51580_51652 instanceof cljs.core.Keyword))?G__51580_51652.fqn:null);
switch (G__51580_51653__$1) {
case "classes":
replicant.string.append(stringifier,"class=\"");

replicant.string.str_join(stringifier," ",v_51651__$1);

replicant.string.append(stringifier,"\"");

break;
case "style":
replicant.string.append(stringifier,"style=\"");

replicant.string.str_join(stringifier," ",cljs.core.keep.cljs$core$IFn$_invoke$arity$2((function (p__51581){
var vec__51582 = p__51581;
var prop = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__51582,(0),null);
var val = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__51582,(1),null);
var temp__5804__auto__ = replicant.core.get_style_val(prop,val);
if(cljs.core.truth_(temp__5804__auto__)){
var val__$1 = temp__5804__auto__;
return [cljs.core.name(prop),": ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(val__$1),";"].join('');
} else {
return null;
}
}),v_51651__$1));

replicant.string.append(stringifier,"\"");

break;
default:
if(((typeof v_51651__$1 === 'number') || (((typeof v_51651__$1 === 'string') && (((0) < cljs.core.count(v_51651__$1))))))){
var G__51585_51655 = stringifier;
replicant.string.append(G__51585_51655,cljs.core.name(k));

replicant.string.append(G__51585_51655,"=\"");

replicant.string.append(G__51585_51655,v_51651__$1);

replicant.string.append(G__51585_51655,"\"");

} else {
replicant.string.append(stringifier,cljs.core.name(k));
}

}
} else {
}

return null;
}),null,attrs);
});
/**
 * Change special characters into HTML character entities.
 * 
 *   Taken from Hiccup:
 *   https://github.com/weavejester/hiccup/blob/5a6d45c17728dcbcb3aeb32ea890fd9dc1508547/src/hiccup/util.clj#L80-L88
 */
replicant.string.escape_html = (function replicant$string$escape_html(text){
return clojure.string.replace(clojure.string.replace(clojure.string.replace(clojure.string.replace(clojure.string.replace(text,"&","&amp;"),"<","&lt;"),">","&gt;"),"\"","&quot;"),"'","&apos;");
});
replicant.string.get_expanded_headers = (function replicant$string$get_expanded_headers(opt,headers){
if(((cljs.core.qualified_keyword_QMARK_((headers[(0)]))) && ((cljs.core.get.cljs$core$IFn$_invoke$arity$2(new cljs.core.Keyword(null,"aliases","aliases",1346874714).cljs$core$IFn$_invoke$arity$1(opt),(headers[(0)])) == null)))){
throw cljs.core.ex_info.cljs$core$IFn$_invoke$arity$2(["Tried to expand undefined alias ",cljs.core.str.cljs$core$IFn$_invoke$arity$1((headers[(0)]))].join(''),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"missing","missing",362507769),(headers[(0)]),new cljs.core.Keyword(null,"available","available",-1470697127),new cljs.core.Keyword(null,"aliases","aliases",1346874714).cljs$core$IFn$_invoke$arity$1(opt)], null));
} else {
}

var or__5025__auto__ = (function (){var temp__5804__auto__ = replicant.core.get_alias_headers(opt,headers);
if(cljs.core.truth_(temp__5804__auto__)){
var aliased = temp__5804__auto__;
return (replicant.string.get_expanded_headers.cljs$core$IFn$_invoke$arity$2 ? replicant.string.get_expanded_headers.cljs$core$IFn$_invoke$arity$2(opt,aliased) : replicant.string.get_expanded_headers.call(null,opt,aliased));
} else {
return null;
}
})();
if(cljs.core.truth_(or__5025__auto__)){
return or__5025__auto__;
} else {
return headers;
}
});
replicant.string.render_node = (function replicant$string$render_node(stringifier,headers,p__51586){
var map__51587 = p__51586;
var map__51587__$1 = cljs.core.__destructure_map(map__51587);
var depth = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__51587__$1,new cljs.core.Keyword(null,"depth","depth",1768663640));
var indent = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__51587__$1,new cljs.core.Keyword(null,"indent","indent",-148200125));
var aliases = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__51587__$1,new cljs.core.Keyword(null,"aliases","aliases",1346874714));
var alias_data = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__51587__$1,new cljs.core.Keyword(null,"alias-data","alias-data",1743863930));
var indent_QMARK_ = (indent > (0));
var indent_s = ((indent_QMARK_)?clojure.string.join.cljs$core$IFn$_invoke$arity$1(cljs.core.repeat.cljs$core$IFn$_invoke$arity$2((depth * indent)," ")):"");
var newline = ((indent_QMARK_)?"\n":"");
var headers__$1 = replicant.string.get_expanded_headers(new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"aliases","aliases",1346874714),aliases,new cljs.core.Keyword(null,"alias-data","alias-data",1743863930),alias_data], null),headers);
var temp__5802__auto__ = (headers__$1[(8)]);
if(cljs.core.truth_(temp__5802__auto__)){
var text = temp__5802__auto__;
var G__51588 = stringifier;
replicant.string.append(G__51588,indent_s);

replicant.string.append(G__51588,replicant.string.escape_html(text));

replicant.string.append(G__51588,newline);

return G__51588;
} else {
var tag_name = (headers__$1[(0)]);
var attrs = replicant.core.get_attrs(headers__$1);
var ns_string = ((((cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2("svg",tag_name)) && (cljs.core.not(new cljs.core.Keyword(null,"xmlns","xmlns",-1862095571).cljs$core$IFn$_invoke$arity$1(attrs)))))?" xmlns=\"http://www.w3.org/2000/svg\"":"");
var G__51589_51660 = stringifier;
replicant.string.append(G__51589_51660,indent_s);

replicant.string.append(G__51589_51660,"<");

replicant.string.append(G__51589_51660,tag_name);

replicant.string.append(G__51589_51660,ns_string);


replicant.string.render_attrs(stringifier,attrs);

var G__51590_51661 = stringifier;
replicant.string.append(G__51590_51661,">");

replicant.string.append(G__51590_51661,newline);


if(cljs.core.truth_(new cljs.core.Keyword(null,"innerHTML","innerHTML",-1856751343).cljs$core$IFn$_invoke$arity$1(attrs))){
replicant.string.append(stringifier,new cljs.core.Keyword(null,"innerHTML","innerHTML",-1856751343).cljs$core$IFn$_invoke$arity$1(attrs));
} else {
cljs.core.run_BANG_((function (child){
if(cljs.core.truth_(child)){
var G__51591 = stringifier;
var G__51592 = child;
var G__51593 = new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"depth","depth",1768663640),(depth + (1)),new cljs.core.Keyword(null,"indent","indent",-148200125),indent,new cljs.core.Keyword(null,"aliases","aliases",1346874714),aliases,new cljs.core.Keyword(null,"alias-data","alias-data",1743863930),alias_data], null);
return (replicant.string.render_node.cljs$core$IFn$_invoke$arity$3 ? replicant.string.render_node.cljs$core$IFn$_invoke$arity$3(G__51591,G__51592,G__51593) : replicant.string.render_node.call(null,G__51591,G__51592,G__51593));
} else {
return null;
}
}),replicant.core.get_children(headers__$1,(headers__$1[(6)])));
}

if(cljs.core.truth_((replicant.string.self_closing_QMARK_.cljs$core$IFn$_invoke$arity$1 ? replicant.string.self_closing_QMARK_.cljs$core$IFn$_invoke$arity$1(tag_name) : replicant.string.self_closing_QMARK_.call(null,tag_name)))){
} else {
var G__51597_51662 = stringifier;
replicant.string.append(G__51597_51662,indent_s);

replicant.string.append(G__51597_51662,"</");

replicant.string.append(G__51597_51662,tag_name);

replicant.string.append(G__51597_51662,">");

replicant.string.append(G__51597_51662,newline);

}

return stringifier;
}
});
/**
 * Render `hiccup` to a string of HTML. `hiccup` can be either a single hiccup
 *   node or a list of multiple nodes.
 */
replicant.string.render = (function replicant$string$render(var_args){
var args__5755__auto__ = [];
var len__5749__auto___51664 = arguments.length;
var i__5750__auto___51665 = (0);
while(true){
if((i__5750__auto___51665 < len__5749__auto___51664)){
args__5755__auto__.push((arguments[i__5750__auto___51665]));

var G__51667 = (i__5750__auto___51665 + (1));
i__5750__auto___51665 = G__51667;
continue;
} else {
}
break;
}

var argseq__5756__auto__ = ((((1) < args__5755__auto__.length))?(new cljs.core.IndexedSeq(args__5755__auto__.slice((1)),(0),null)):null);
return replicant.string.render.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__5756__auto__);
});

(replicant.string.render.cljs$core$IFn$_invoke$arity$variadic = (function (hiccup,p__51610){
var vec__51611 = p__51610;
var map__51614 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__51611,(0),null);
var map__51614__$1 = cljs.core.__destructure_map(map__51614);
var aliases = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__51614__$1,new cljs.core.Keyword(null,"aliases","aliases",1346874714));
var alias_data = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__51614__$1,new cljs.core.Keyword(null,"alias-data","alias-data",1743863930));
var indent = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__51614__$1,new cljs.core.Keyword(null,"indent","indent",-148200125));
var opt = new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"indent","indent",-148200125),(function (){var or__5025__auto__ = indent;
if(cljs.core.truth_(or__5025__auto__)){
return or__5025__auto__;
} else {
return (0);
}
})(),new cljs.core.Keyword(null,"depth","depth",1768663640),(0),new cljs.core.Keyword(null,"aliases","aliases",1346874714),(function (){var or__5025__auto__ = aliases;
if(cljs.core.truth_(or__5025__auto__)){
return or__5025__auto__;
} else {
return replicant.alias.get_registered_aliases();
}
})(),new cljs.core.Keyword(null,"alias-data","alias-data",1743863930),alias_data], null);
if(replicant.hiccup.hiccup_QMARK_(hiccup)){
var stringifier = replicant.string.create_renderer();
replicant.string.render_node(stringifier,replicant.core.get_hiccup_headers(null,hiccup),opt);

return stringifier.replicant$string$IStringifier$to_string$arity$1(null);
} else {
if(cljs.core.list_QMARK_(hiccup)){
var stringifier = replicant.string.create_renderer();
var seq__51616_51669 = cljs.core.seq(hiccup);
var chunk__51617_51670 = null;
var count__51618_51671 = (0);
var i__51619_51672 = (0);
while(true){
if((i__51619_51672 < count__51618_51671)){
var hiccup_node_51674 = chunk__51617_51670.cljs$core$IIndexed$_nth$arity$2(null,i__51619_51672);
replicant.string.render_node(stringifier,replicant.core.get_hiccup_headers(null,hiccup_node_51674),opt);


var G__51675 = seq__51616_51669;
var G__51676 = chunk__51617_51670;
var G__51677 = count__51618_51671;
var G__51678 = (i__51619_51672 + (1));
seq__51616_51669 = G__51675;
chunk__51617_51670 = G__51676;
count__51618_51671 = G__51677;
i__51619_51672 = G__51678;
continue;
} else {
var temp__5804__auto___51679 = cljs.core.seq(seq__51616_51669);
if(temp__5804__auto___51679){
var seq__51616_51680__$1 = temp__5804__auto___51679;
if(cljs.core.chunked_seq_QMARK_(seq__51616_51680__$1)){
var c__5548__auto___51681 = cljs.core.chunk_first(seq__51616_51680__$1);
var G__51683 = cljs.core.chunk_rest(seq__51616_51680__$1);
var G__51684 = c__5548__auto___51681;
var G__51685 = cljs.core.count(c__5548__auto___51681);
var G__51686 = (0);
seq__51616_51669 = G__51683;
chunk__51617_51670 = G__51684;
count__51618_51671 = G__51685;
i__51619_51672 = G__51686;
continue;
} else {
var hiccup_node_51687 = cljs.core.first(seq__51616_51680__$1);
replicant.string.render_node(stringifier,replicant.core.get_hiccup_headers(null,hiccup_node_51687),opt);


var G__51688 = cljs.core.next(seq__51616_51680__$1);
var G__51689 = null;
var G__51690 = (0);
var G__51691 = (0);
seq__51616_51669 = G__51688;
chunk__51617_51670 = G__51689;
count__51618_51671 = G__51690;
i__51619_51672 = G__51691;
continue;
}
} else {
}
}
break;
}

return stringifier.replicant$string$IStringifier$to_string$arity$1(null);
} else {
return cljs.core.str.cljs$core$IFn$_invoke$arity$1(hiccup);

}
}
}));

(replicant.string.render.cljs$lang$maxFixedArity = (1));

/** @this {Function} */
(replicant.string.render.cljs$lang$applyTo = (function (seq51603){
var G__51604 = cljs.core.first(seq51603);
var seq51603__$1 = cljs.core.next(seq51603);
var self__5734__auto__ = this;
return self__5734__auto__.cljs$core$IFn$_invoke$arity$variadic(G__51604,seq51603__$1);
}));


//# sourceMappingURL=replicant.string.js.map
