!function(){"use strict";var n,e,t,o,r,i,u,a=function(n){return function(){return n}},O={noop:function(){for(var n=[],e=0;e "+o.toString()},function(n,e){return"state("+n+")"})}).join("\n")+"}"},toDsl:function(){return vt.objOf(vn.map(c,function(n){return n.fold(function(n,e,t,o){return ht.field(n,t,o)},function(n,e){return ht.state(n)})}))}}},Mt=function(r){return{extract:function(t,o,n){var e=vn.map(n,function(n,e){return r.extract(t.concat(["["+e+"]"]),o,n)});return ot(e)},toString:function(){return"array("+r.toString()+")"},toDsl:function(){return vt.arrOf(r)}}},At=function(u,a){return{extract:function(t,o,r){var n,e,i=M.keys(r);return(n=t,e=i,Mt(Ot(u)).extract(n,O.identity,e)).bind(function(n){var e=vn.map(n,function(n){return St.field(n,n,Ye(),a)});return Dt(e).extract(t,o,r)})},toString:function(){return"setOf("+a.toString()+")"},toDsl:function(){return vt.setOf(u,a)}}},Bt=O.constant(Ot(qe.value)),Rt=(O.compose(Mt,Dt),St.state),It=St.field,Ft=function(n){return It(n,n,Ye(),Bt())},Nt=function(n,e){return It(n,n,Ye(),e)},Vt=function(n){return It(n,n,Ye(),Ot(function(n){return E.isFunction(n)?qe.value(n):qe.error("Not a function")}))},Ht=function(n,e){return It(n,n,Ye(),Dt(e))},jt=function(n){return It(n,n,Je(),Bt())},zt=function(n,e){return It(n,n,Je(),Dt(e))},Lt=function(n,e){return It(n,n,Je(),Et(e))},Pt=function(n,e){return It(n,n,Xe(e),Bt())},Wt=function(n,e,t){return It(n,n,Xe(e),t)},Ut=function(n,e){return Rt(n,e)},Gt=function(t,e,o,r,i){return lt(r,i).fold(function(){return n=r,e=i,xt(t,function(){return'The chosen schema: "'+e+'" did not exist in branches: '+wt(n)});var n,e},function(n){return Dt(n).extract(t.concat(["branch: "+i]),e,o)})},$t=function(r,i){return{extract:function(e,t,o){return lt(o,r).fold(function(){return n=r,xt(e,function(){return'Choice schema did not contain choice key: "'+n+'"'});var n},function(n){return Gt(e,t,o,i,n)})},toString:function(){return"chooseOn("+r+"). Possible values: "+M.keys(i)},toDsl:function(){return vt.choiceOf(r,i)}}},qt=Ot(qe.value),_t=function(n,e,t,o){return e.extract([n],t,o).fold(function(n){return qe.error({input:o,errors:n})},qe.value)},Kt=function(n,e,t){return _t(n,e,O.constant,t)},Xt=function(n){return n.fold(function(n){throw new Error(Qt(n))},O.identity)},Yt=function(n,e,t){return Xt((o=t,_t(n,e,O.identity,o)));var o},Jt=function(n,e,t){return Xt(Kt(n,e,t))},Qt=function(n){return"Errors: \n"+(e=n.errors,t=10 ")+")\n"+n.getErrorInfo()}))+"\n\nInput object: "+wt(n.input);var e,t},Zt=function(n,e){return $t(n,e)},no=O.constant(qt),eo=function(n){if(!pt(n,"can")&&!pt(n,"abort")&&!pt(n,"run"))throw new Error("EventHandler defined by: "+yt(n,null,2)+" does not have can, abort, or run!");return Yt("Extracting event.handler",Et([Pt("can",O.constant(!0)),Pt("abort",O.constant(!1)),Pt("run",O.noop)]),n)},to=function(n){var e,o,r,i,t=(e=n,o=function(n){return n.can},function(){var t=Array.prototype.slice.call(arguments,0);return vn.foldl(e,function(n,e){return n&&o(e).apply(undefined,t)},!0)}),u=(r=n,i=function(n){return n.abort},function(){var t=Array.prototype.slice.call(arguments,0);return vn.foldl(r,function(n,e){return n||i(e).apply(undefined,t)},!1)});return eo({can:t,abort:u,run:function(){var e=Array.prototype.slice.call(arguments,0);vn.each(n,function(n){n.run.apply(undefined,e)})}})},oo=mt,ro=function(n,e){return{key:n,value:eo({abort:e})}},io=function(n,e){return{key:n,value:eo({run:e})}},uo=function(n,e,t){return{key:n,value:eo({run:function(n){e.apply(undefined,[n].concat(t))}})}},ao=function(n){return function(o){return{key:n,value:eo({run:function(n,e){var t;t=e,Te(n.element(),t.event().target())&&o(n,e)}})}}},co=function(n,e,t){var u,o,r=e.partUids()[t];return o=r,io(u=n,function(n,i){n.getSystem().getByUid(o).each(function(n){var e,t,o,r;t=(e=n).element(),o=u,r=i,e.getSystem().triggerEvent(o,t,r.event())})})},so=function(n){return io(n,function(n,e){e.cut()})},fo=ao(Pn()),lo=ao(Wn()),mo=ao(zn()),go=(u=Fn(),function(n){return io(u,n)}),po=function(n,e){return n},vo=de.immutableBag(["tag"],["classes","attributes","styles","value","innerHtml","domChildren","defChildren"]),ho=function(n){return{tag:n.tag(),classes:n.classes().getOr([]),attributes:n.attributes().getOr({}),styles:n.styles().getOr({}),value:n.value().getOr(""),innerHtml:n.innerHtml().getOr(""),defChildren:n.defChildren().getOr(""),domChildren:n.domChildren().fold(function(){return""},function(n){return 0===n.length?"0 children, but still specified":String(n.length)})}},bo=de.immutableBag([],["classes","attributes","styles","value","innerHtml","defChildren","domChildren"]),yo=function(e,n,t){return n.fold(function(){return t.fold(function(){return{}},function(n){return dt(e,n)})},function(n){return t.fold(function(){return dt(e,n)},function(n){return dt(e,n)})})},wo=function(t,o,r){return mo(function(n,e){r(n,t,o)})},xo=function(n,e,t,o,r,i){var u,a,c=n,s=zt(e,[(u="config",a=n,It(u,u,Je(),a))]);return To(c,s,e,t,o,r,i)},So=function(n){return{key:n,value:undefined}},To=function(t,n,o,r,e,i,u){var a=function(n){return pt(n,o)?n[o]():y.none()},c=M.map(e,function(n,e){return r=o,i=n,u=e,function(t){var o=arguments;return t.config({name:O.constant(r)}).fold(function(){throw new Error("We could not find any behaviour configuration for: "+r+". Using API: "+u)},function(n){var e=Array.prototype.slice.call(o,1);return i.apply(undefined,[t,n.config,n.state].concat(e))})};var r,i,u}),s=M.map(i,function(n,e){return po(n)}),f=D.deepMerge(s,c,{revoke:O.curry(So,o),config:function(n){var e=Jt(o+"-config",t,n);return{key:o,value:{config:e,me:f,configAsRaw:L(function(){return Yt(o+"-config",t,n)}),initialConfig:n,state:u}}},schema:function(){return n},exhibit:function(n,t){return a(n).bind(function(e){return lt(r,"exhibit").map(function(n){return n(t,e.config,e.state)})}).getOr(bo({}))},name:function(){return o},handlers:function(n){return a(n).bind(function(e){return lt(r,"events").map(function(n){return n(e.config,e.state)})}).getOr({})}});return f},ko=function(n,e){return Co(n,e,{validate:E.isFunction,label:"function"})},Co=function(o,r,i){if(0===r.length)throw new Error("You must specify at least one required field.");return le.validateStrArr("required",r),le.checkDupes(r),function(e){var t=M.keys(e);vn.forall(r,function(n){return vn.contains(t,n)})||le.reqMessage(r,t),o(r,t);var n=vn.filter(r,function(n){return!i.validate(e[n],n)});return 0"}),no()),tc=Pt("defaults",O.constant({})),oc=Pt("overrides",O.constant({})),rc=Dt([Qa,Za,nc,ec,tc,oc]),ic=Dt([Qa,Za,nc,tc,oc]),uc=Dt([Qa,Za,nc,ec,tc,oc]),ac=Dt([Qa,Za,nc,Ft("unit"),ec,tc,oc]),cc=function(n){var e=function(n){return n.name()};return n.fold(e,e,e,e)},sc=function(t,o){return function(n){var e=Jt("Converting part type",o,n);return t(e)}},fc=sc(Ja.required,rc),lc=(sc(Ja.external,ic),sc(Ja.optional,uc)),dc=sc(Ja.group,ac),mc=O.constant("entirety"),gc=function(n,e,t,o){var r=t;return D.deepMerge(e.defaults()(n,t,o),t,{uid:n.partUids()[e.name()]},e.overrides()(n,t,o),{"debug.sketcher":dt("part-"+e.name(),r)})},pc=function(r,n){var i={};return vn.each(n,function(n){var e;(e=n,e.fold(y.some,y.none,y.some,y.some)).each(function(t){var o=vc(r,t.pname());i[t.name()]=function(n){var e=Yt("Part: "+t.name()+" in "+r,Dt(t.schema()),n);return D.deepMerge(o,{config:n,validated:e})}})}),i},vc=function(n,e){return{uiType:Ka(),owner:n,name:e}},hc=function(n,e,t){return o=e,r=t,i={},u={},vn.each(r,function(n){n.fold(function(o){i[o.pname()]=qa(!0,function(n,e,t){return o.factory().sketch(gc(n,o,e,t))})},function(n){var e=o.parts()[n.name()]();u[n.name()]=O.constant(gc(o,n,e[mc()]()))},function(o){i[o.pname()]=qa(!1,function(n,e,t){return o.factory().sketch(gc(n,o,e,t))})},function(r){i[r.pname()]=_a(!0,function(e,n,t){var o=e[r.name()]();return vn.map(o,function(n){return r.factory().sketch(D.deepMerge(r.defaults()(e,n),n,r.overrides()(e,n)))})})})}),{internals:O.constant(i),externals:O.constant(u)};var o,r,i,u},bc=function(n,e,t){return $a(y.some(n),e,e.components(),t)},yc=function(n,e,t){var o=e.partUids()[t];return n.getSystem().getByUid(o).toOption()},wc=function(n,e,t){return yc(n,e,t).getOrDie("Could not find part: "+t)},xc=function(e,n){var t,o=(t=n,vn.map(t,cc));return mt(vn.map(o,function(n){return{key:n,value:e+"-"+n}}))},Sc=function(e){return It("partUids","partUids",Ze(function(n){return xc(n.uid,e)}),no())},Tc=Ya("alloy-premade"),kc=Ya("api"),Cc=function(n){return dt(Tc,n)},Oc=function(o){return function(n){var e=Array.prototype.slice.call(arguments,0),t=n.config(kc);return o.apply(undefined,[t].concat(e))}},Ec=O.constant(kc),Dc=O.constant("alloy-id-"),Mc=O.constant("data-alloy-id"),Ac=Dc(),Bc=Mc(),Rc=function(n,e){var t=Ya(Ac+n);return Po.set(e,Bc,t),t},Ic=function(n){var e=ue.isElement(n)?Po.get(n,Bc):null;return y.from(e)},Fc=function(n){return Ya(n)},Nc=(O.constant(Bc),function(n,e,t,o,r){var i,u,a=(u=r,(0<(i=o).length?[Ht("parts",i)]:[]).concat([Ft("uid"),Pt("dom",{}),Pt("components",[]),Xr("originalSpec"),Pt("debug.sketcher",{})]).concat(u));return Jt(n+" [SpecSchema]",Et(a.concat(e)),t)}),Vc=function(n,e,t,o,r){var i,u=Hc(r),a=(i=t,vn.bind(i,function(n){return n.fold(y.none,y.some,y.none,y.none).map(function(n){return Ht(n.name(),n.schema().concat([Xr(mc())]))}).toArray()})),c=Sc(t),s=Nc(n,e,u,a,[c]),f=hc(0,s,t),l=bc(n,s,f.internals());return D.deepMerge(o(s,l,u,f.externals()),{"debug.sketcher":dt(n,r)})},Hc=function(n){return D.deepMerge({uid:Fc("uid")},n)},jc=Et([Ft("name"),Ft("factory"),Ft("configFields"),Pt("apis",{}),Pt("extraApis",{})]),zc=Et([Ft("name"),Ft("factory"),Ft("configFields"),Ft("partFields"),Pt("apis",{}),Pt("extraApis",{})]),Lc=function(n){var a=Yt("Sketcher for "+n.name,jc,n),e=M.map(a.apis,Oc),t=M.map(a.extraApis,function(n,e){return po(n)});return D.deepMerge({name:O.constant(a.name),partFields:O.constant([]),configFields:O.constant(a.configFields),sketch:function(n){return e=a.name,t=a.configFields,o=a.factory,i=Hc(r=n),u=Nc(e,t,i,[],[]),D.deepMerge(o(u,i),{"debug.sketcher":dt(e,r)});var e,t,o,r,i,u}},e,t)},Pc=function(n){var e=Yt("Sketcher for "+n.name,zc,n),t=pc(e.name,e.partFields),o=M.map(e.apis,Oc),r=M.map(e.extraApis,function(n,e){return po(n)});return D.deepMerge({name:O.constant(e.name),partFields:O.constant(e.partFields),configFields:O.constant(e.configFields),sketch:function(n){return Vc(e.name,e.configFields,e.partFields,e.factory,n)},parts:O.constant(t)},o,r)},Wc=Lc({name:"Button",factory:function(n,e){var t,o,r,i=(t=n.action(),o=function(n,e){e.stop(),$n(n)},r=Mn.detect().deviceType.isTouch()?[io(Vn(),o)]:[io(H(),o),io(A(),function(n,e){e.cut()})],oo(vn.flatten([t.map(function(t){return io(Fn(),function(n,e){t(n),e.stop()})}).toArray(),r]))),u=lt(n.dom(),"attributes").bind(st("type")),a=lt(n.dom(),"tag");return{uid:n.uid(),dom:n.dom(),components:n.components(),events:i,behaviours:D.deepMerge(Bo([yi.config({}),ja.config({mode:"execution",useSpace:!0,useEnter:!0})]),La(n.buttonBehaviours())),domModification:{attributes:D.deepMerge(u.fold(function(){return a.is("button")?{type:"button"}:{}},function(n){return{}}),{role:n.role().getOr("button")})},eventOrder:n.eventOrder()}},configFields:[Pt("uid",undefined),Ft("dom"),Pt("components",[]),za("buttonBehaviours",[yi,ja]),jt("action"),jt("role"),Pt("eventOrder",{})]}),Uc=Object.freeze({events:function(n){return oo([ro(z(),O.constant(!0))])},exhibit:function(n,e){return bo({styles:{"-webkit-user-select":"none","user-select":"none","-ms-user-select":"none","-moz-user-select":"-moz-none"},attributes:{unselectable:"on"}})}}),Gc=Io({fields:[],name:"unselecting",active:Uc}),$c=function(n){var e,t,o,r=Xn.fromHtml(n),i=Be.children(r),u=(t=(e=r).dom().attributes!==undefined?e.dom().attributes:[],vn.foldl(t,function(n,e){return"class"===e.name?n:D.deepMerge(n,dt(e.name,e.value))},{})),a=(o=r,Array.prototype.slice.call(o.dom().classList,0)),c=0===i.length?{}:{innerHtml:Cr(r)};return D.deepMerge({tag:ue.name(r),classes:a,attributes:u},c)},qc=function(n){var e=wn(n,{prefix:gi.prefix()});return $c(e)},_c=function(n){return{dom:qc(n)}},Kc=function(n){return Bo([si.config({toggleClass:gi.resolve("toolbar-button-selected"),toggleOnExecute:!1,aria:{mode:"pressed"}}),fi(n,function(n,e){(e?si.on:si.off)(n)})])},Xc=function(n,e,t){return Wc.sketch({dom:qc(''),action:e,buttonBehaviours:D.deepMerge(Bo([Gc.config({})]),t)})},Yc={forToolbar:Xc,forToolbarCommand:function(n,e){return Xc(e,function(){n.execCommand(e)},{})},forToolbarStateAction:function(n,e,t,o){var r=Kc(t);return Xc(e,o,r)},forToolbarStateCommand:function(n,e){var t=Kc(e);return Xc(e,function(){n.execCommand(e)},t)}},Jc=function(n,e,t){return Math.max(e,Math.min(t,n))},Qc=function(n,e,t,o,r,i,u){var a=t-e;if(on.right)return t+1;var c,s,f,l,d=Math.min(n.right,Math.max(o,n.left))-n.left,m=Jc(d/n.width*a+e,e-1,t+1),g=Math.round(m);return i&&e<=m&&m<=t?(c=m,s=e,f=t,l=r,u.fold(function(){var n=c-s,e=Math.round(n/l)*l;return Jc(s+e,s-1,f+1)},function(n){var e=(c-n)%l,t=Math.round(e/l),o=Math.floor((c-n)/l),r=Math.floor((f-n)/l),i=n+Math.min(r,o+t)*l;return Math.max(n,i)})):g},Zc="slider.change.value",ns=Mn.detect().deviceType.isTouch(),es=function(n){var e;return(e=n.event().raw(),ns&&e.touches!==undefined&&1===e.touches.length?y.some(e.touches[0]):ns&&e.touches!==undefined?y.none():ns||e.clientX===undefined?y.none():y.some(e)).map(function(n){return n.clientX})},ts=function(n,e){Gn(n,Zc,{value:e})},os=function(i,u,a,n){return es(n).map(function(n){var e,t,o,r;return e=i,o=n,r=Qc(a,(t=u).min(),t.max(),o,t.stepSize(),t.snapToGrid(),t.snapStart()),ts(e,r),n})},rs=function(n,e){var t,o,r,i,u=(t=e.value().get(),o=e.min(),r=e.max(),i=e.stepSize(),to.max()?yc(e,o,"right-edge").fold(function(){return t.width},function(n){return f(n)-t.left}):(o.value().get()-o.min())/s*t.width);return i.left-u.left+a},u=function(n){var e=i(n),t=r(n),o=Es(t.element())/2;Oi.set(t.element(),"left",e-o+"px")},o=function(n,e){var t=c.value().get(),o=r(n);return t!==e||Oi.getRaw(o.element(),"left").isNone()?(c.value().set(e),u(n),c.onChange()(n,o,e),y.some(!0)):y.none()},a=Ds?[io(T(),function(n,e){c.onDragStart()(n,r(n))}),io(C(),function(n,e){c.onDragEnd()(n,r(n))})]:[io(A(),function(n,e){e.stop(),c.onDragStart()(n,r(n)),c.mouseIsDown().set(!0)}),io(R(),function(n,e){c.onDragEnd()(n,r(n)),c.mouseIsDown().set(!1)})];return{uid:c.uid(),dom:c.dom(),components:n,behaviours:D.deepMerge(Bo(vn.flatten([Ds?[]:[ja.config({mode:"special",focusIn:function(n){return yc(n,c,"spectrum").map(ja.focusIn).map(O.constant(!0))}})],[Ss.config({store:{mode:"manual",getValue:function(n){return c.value().get()}}})]])),La(c.sliderBehaviours())),events:oo([io(us(),function(n,e){o(n,e.event().value())}),fo(function(n,e){c.value().set(c.getInitialValue()());var t=r(n);u(n),c.onInit()(n,t,c.value().get())})].concat(a)),apis:{resetToMin:function(n){o(n,c.min())},resetToMax:function(n){o(n,c.max())},refresh:u},domModification:{styles:{position:"relative"}}}},apis:{resetToMin:function(n,e){n.resetToMin(e)},resetToMax:function(n,e){n.resetToMax(e)},refresh:function(n,e){n.refresh(e)}}}),As=function(e,t,o){return Yc.forToolbar(t,function(){var n=o();e.setContextToolbar([{label:t+" group",items:n}])},{})},Bs=function(n){return[(r=n,i=function(n){return n<0?"black":360'),components:[Ms.parts()["left-edge"](_c('
')),Ms.parts().spectrum({dom:qc('
'),components:[_c('
')],behaviours:Bo([si.config({toggleClass:gi.resolve("thumb-active")})])}),Ms.parts()["right-edge"](_c('
')),Ms.parts().thumb({dom:qc('
'),behaviours:Bo([si.config({toggleClass:gi.resolve("thumb-active")})])})],onChange:function(n,e,t){var o=i(t);Oi.set(e.element(),"background-color",o),r.onChange(n,e,o)},onDragStart:function(n,e){si.on(e)},onDragEnd:function(n,e){si.off(e)},onInit:function(n,e,t){var o=i(t);Oi.set(e.element(),"background-color",o)},stepSize:10,min:0,max:360,getInitialValue:r.getInitialValue,sliderBehaviours:Bo([li(Ms.refresh)])}))];var r,i},Rs=function(n,o){var e={onChange:function(n,e,t){o.undoManager.transact(function(){o.formatter.apply("forecolor",{value:t}),o.nodeChanged()})},getInitialValue:function(){return-1}};return As(n,"color",function(){return Bs(e)})},Is=Et([Ft("getInitialValue"),Ft("onChange"),Ft("category"),Ft("sizes")]),Fs=function(n){var r=Yt("SizeSlider",Is,n);return Ms.sketch({dom:{tag:"div",classes:[gi.resolve("slider-"+r.category+"-size-container"),gi.resolve("slider"),gi.resolve("slider-size-container")]},onChange:function(n,e,t){var o;0<=(o=t)&&o'),components:[_c('
')]}),Ms.parts().thumb({dom:qc('
'),behaviours:Bo([si.config({toggleClass:gi.resolve("thumb-active")})])})]})},Ns=function(n,e,t){for(var o=n.dom(),r=E.isFunction(t)?t:O.constant(!1);o.parentNode;){o=o.parentNode;var i=Xn.fromDom(o),u=e(i);if(u.isSome())return u;if(r(i))break}return y.none()},Vs=function(n,e,t){return e(n).orThunk(function(){return t(n)?y.none():Ns(n,e,t)})},Hs=["9px","10px","11px","12px","14px","16px","18px","20px","24px","32px","36px"],js=function(n){var e,t,o=n.selection.getStart(),r=Xn.fromDom(o),i=Xn.fromDom(n.getBody()),u=(e=function(n){return Te(i,n)},t=r,(ue.isElement(t)?y.some(t):Be.parent(t)).map(function(n){return Vs(n,function(n){return Oi.getRaw(n,"font-size")},e).getOrThunk(function(){return Oi.get(n,"font-size")})}).getOr(""));return vn.find(Hs,function(n){return u===n}).getOr("medium")},zs={candidates:O.constant(Hs),get:function(n){var e,t=js(n);return(e=t,vn.findIndex(Hs,function(n){return n===e})).getOr(2)},apply:function(o,n){var e;(e=n,y.from(Hs[e])).each(function(n){var e,t;t=n,js(e=o)!==t&&e.execCommand("fontSize",!1,t)})}},Ls=zs.candidates(),Ps=function(n){return[_c(''),(e=n,Fs({onChange:e.onChange,sizes:Ls,category:"font",getInitialValue:e.getInitialValue})),_c('')];var e},Ws=function(n){var e=n.uid!==undefined&&pt(n,"uid")?n.uid:Fc("memento");return{get:function(n){return n.getSystem().getByUid(e).getOrDie()},getOpt:function(n){return n.getSystem().getByUid(e).fold(y.none,y.some)},asSpec:function(){return D.deepMerge(n,{uid:e})}}};function Us(n,e){return $s(document.createElement("canvas"),n,e)}function Gs(n){return n.getContext("2d")}function $s(n,e,t){return n.width=e,n.height=t,n}var qs={create:Us,clone:function(n){var e;return Gs(e=Us(n.width,n.height)).drawImage(n,0,0),e},resize:$s,get2dContext:Gs,get3dContext:function(n){var e=null;try{e=n.getContext("webgl")||n.getContext("experimental-webgl")}catch(t){}return e||(e=null),e}},_s={getWidth:function(n){return n.naturalWidth||n.width},getHeight:function(n){return n.naturalHeight||n.height}},Ks=window.Promise?window.Promise:function(){var n=function(n){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof n)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],s(n,o(r,this),o(u,this))},e=n.immediateFn||"function"==typeof setImmediate&&setImmediate||function(n){setTimeout(n,1)};function o(n,e){return function(){n.apply(e,arguments)}}var t=Array.isArray||function(n){return"[object Array]"===Object.prototype.toString.call(n)};function i(o){var r=this;null!==this._state?e(function(){var n=r._state?o.onFulfilled:o.onRejected;if(null!==n){var e;try{e=n(r._value)}catch(t){return void o.reject(t)}o.resolve(e)}else(r._state?o.resolve:o.reject)(r._value)}):this._deferreds.push(o)}function r(n){try{if(n===this)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var e=n.then;if("function"==typeof e)return void s(o(e,n),o(r,this),o(u,this))}this._state=!0,this._value=n,a.call(this)}catch(t){u.call(this,t)}}function u(n){this._state=!1,this._value=n,a.call(this)}function a(){for(var n=0,e=this._deferreds.length;n'),components:[e.asSpec()],action:function(n){e.get(n).element().dom().click()}})},gf=function(n){return n.dom().textContent},pf=function(n,e){n.dom().textContent=e},vf=function(n){return 0'),action:function(n){var e=t.get(n);Ss.setValue(e,"")}}));return{name:n,spec:Df.sketch({dom:qc('
'),components:[t.asSpec(),o.asSpec()],containerBehaviours:Bo([si.config({toggleClass:gi.resolve("input-container-empty")}),Ef.config({find:function(n){return y.some(t.get(n))}}),kf("input-clearing",[io(N(),function(n){var e=t.get(n);(0"},Zf=function(r,n,e){return D.deepMerge({"debug.sketcher":{Form:e},uid:r.uid(),dom:r.dom(),components:n,behaviours:D.deepMerge(Bo([Ss.config({store:{mode:"manual",getValue:function(n){var e,t,o=(e=r,t=n.getSystem(),M.map(e.partUids(),function(n,e){return O.constant(t.getByUid(n))}));return M.map(o,function(n,e){return n().bind(Ef.getCurrent).map(Ss.getValue)})},setValue:function(t,n){M.each(n,function(e,n){yc(t,r,n).each(function(n){Ef.getCurrent(n).each(function(n){Ss.setValue(n,e)})})})}}})]),La(r.formBehaviours())),apis:{getField:function(n,e){return yc(n,r,e).bind(Ef.getCurrent)}}})},nl=(Oc(function(n,e,t){return n.getField(e,t)}),function(n){var i,e=(i=[],{field:function(n,e){return i.push(n),t="form",o=Qf(n),r=e,{uiType:Ka(),owner:t,name:o,config:r,validated:{}};var t,o,r},record:function(){return i}}),t=n(e),o=e.record(),r=vn.map(o,function(n){return fc({name:n,pname:Qf(n)})});return Vc("form",Jf,r,Zf,t)}),el=function(n){var e=ur(y.none()),t=function(){e.get().each(n)};return{clear:function(){t(),e.set(y.none())},isSet:function(){return e.get().isSome()},set:function(n){t(),e.set(y.some(n))}}},tl={destroyable:function(){return el(function(n){n.destroy()})},unbindable:function(){return el(function(n){n.unbind()})},api:function(){var e=ur(y.none()),t=function(){e.get().each(function(n){n.destroy()})};return{clear:function(){t(),e.set(y.none())},isSet:function(){return e.get().isSome()},set:function(n){t(),e.set(y.some(n))},run:function(n){e.get().each(n)}}},value:function(){var e=ur(y.none());return{clear:function(){e.set(y.none())},set:function(n){e.set(y.some(n))},isSet:function(){return e.get().isSome()},on:function(n){e.get().each(n)}}}},ol=function(n){return{xValue:n,points:[]}},rl=function(n,e){if(e===n.xValue)return n;var t=0'),action:function(n){Gn(n,o,{direction:e})},buttonBehaviours:Bo([Yf.config({disableClass:gi.resolve("toolbar-navigation-disabled"),disabled:!t})])})},i=function(n,r){var i=Hi(n.element(),"."+gi.resolve("serialised-dialog-screen"));Pi(n.element(),"."+gi.resolve("serialised-dialog-chain")).each(function(o){0<=u.state.currentScreen.get()+r&&u.state.currentScreen.get()+r'),components:[Df.sketch({dom:qc('
'),components:vn.map(u.fields,function(n,e){return e<=u.maxFieldIndex?Df.sketch({dom:qc('
'),components:vn.flatten([[r(-1,"previous",0'),behaviours:Bo([lu.config({highlightClass:gi.resolve("dot-active"),itemClass:gi.resolve("dot-item")})]),components:vn.bind(u.fields,function(n,e){return e<=u.maxFieldIndex?[_c('
')]:[]})});return{dom:qc('
'),components:[c.asSpec(),s.asSpec()],behaviours:Bo([ja.config({mode:"special",focusIn:function(n){var e=c.get(n);ja.focusIn(e)}}),kf("serializer-wrapper-events",[io(T(),function(n,e){u.state.dialogSwipeState.set(ol(e.event().raw().touches[0].clientX))}),io(k(),function(n,e){u.state.dialogSwipeState.on(function(n){e.event().prevent(),u.state.dialogSwipeState.set(rl(n,e.event().raw().touches[0].clientX))})}),io(C(),function(o){u.state.dialogSwipeState.on(function(n){var e=c.get(o),t=-1*il(n);i(e,t)})})])])}},al=L(function(t,o){return[{label:"the link group",items:[ul({fields:[Hf("url","Type or paste URL"),Hf("text","Link text"),Hf("title","Link title"),Hf("target","Link target"),(n="link",{name:n,spec:Mf.sketch({dom:{tag:"span",styles:{display:"none"}},getInitialValue:function(){return y.none()}})})],maxFieldIndex:["url","text","title","target"].length-1,getInitialValue:function(){return y.some(wf.getInfo(o))},onExecute:function(n){var e=Ss.getValue(n);wf.applyInfo(o,e),t.restoreToolbar(),o.focus()}})]}];var n}),cl=[{title:"Headings",items:[{title:"Heading 1",format:"h1"},{title:"Heading 2",format:"h2"},{title:"Heading 3",format:"h3"},{title:"Heading 4",format:"h4"},{title:"Heading 5",format:"h5"},{title:"Heading 6",format:"h6"}]},{title:"Inline",items:[{title:"Bold",icon:"bold",format:"bold"},{title:"Italic",icon:"italic",format:"italic"},{title:"Underline",icon:"underline",format:"underline"},{title:"Strikethrough",icon:"strikethrough",format:"strikethrough"},{title:"Superscript",icon:"superscript",format:"superscript"},{title:"Subscript",icon:"subscript",format:"subscript"},{title:"Code",icon:"code",format:"code"}]},{title:"Blocks",items:[{title:"Paragraph",format:"p"},{title:"Blockquote",format:"blockquote"},{title:"Div",format:"div"},{title:"Pre",format:"pre"}]},{title:"Alignment",items:[{title:"Left",icon:"alignleft",format:"alignleft"},{title:"Center",icon:"aligncenter",format:"aligncenter"},{title:"Right",icon:"alignright",format:"alignright"},{title:"Justify",icon:"alignjustify",format:"alignjustify"}]}],sl={events:oo([(tf=Bn(),of=function(n,e){var t,o,r=e.event().originator(),i=e.event().target();return o=i,!(Te(t=r,n.element())&&!Te(t,o)&&(console.warn(Bn()+" did not get interpreted by the desired target. \nOriginator: "+Ar(r)+"\nTarget: "+Ar(i)+"\nCheck the "+Bn()+" event handlers"),1))},{key:tf,value:eo({can:of})})])},fl=O.identity,ll=Eo.exactly(["debugInfo","triggerFocus","triggerEvent","triggerEscape","addToWorld","removeFromWorld","addToGui","removeFromGui","build","getByUid","getByDom","broadcast","broadcastOn"]),dl=function(e){var n=function(n){return function(){throw new Error("The component must be in a context to send: "+n+"\n"+Ar(e().element())+" is not in context.")}};return ll({debugInfo:O.constant("fake"),triggerEvent:n("triggerEvent"),triggerFocus:n("triggerFocus"),triggerEscape:n("triggerEscape"),build:n("build"),addToWorld:n("addToWorld"),removeFromWorld:n("removeFromWorld"),addToGui:n("addToGui"),removeFromGui:n("removeFromGui"),getByUid:n("getByUid"),getByDom:n("getByDom"),broadcast:n("broadcast"),broadcastOn:n("broadcastOn")})},ml=function(e,n){var t=vn.map(n,function(n){return It(n.name(),n.name(),Je(),Dt([Ft("config"),Pt("state",Ao)]))}),o=Kt("component.behaviours",Dt(t),e.behaviours).fold(function(n){throw new Error(Qt(n)+"\nComplete spec:\n"+yt(e,null,2))},O.identity);return{list:n,data:M.map(o,function(n){var e=n();return O.constant(e.map(function(n){return{config:n.config(),state:n.state().init(n.config())}}))})}},gl=function(n){return n.list},pl=function(n){return n.data},vl=function(n,r){var i={};return M.each(n,function(n,o){M.each(n,function(n,e){var t=ft(e,[])(i);i[e]=t.concat([r(o,n)])})}),i},hl=function(n,e){return{name:O.constant(n),modification:e}},bl=function(n,e,t){return 1 "):r[0].name();return dt(i,(e=o,{handler:t,purpose:O.constant(e)}))})});return gt(e,{})},Ml=function(n){return Kt("custom.definition",Et([It("dom","dom",Ye(),Et([Ft("tag"),Pt("styles",{}),Pt("classes",[]),Pt("attributes",{}),jt("value"),jt("innerHtml")])),Ft("components"),Ft("uid"),Pt("events",{}),Pt("apis",O.constant({})),It("eventOrder","eventOrder",(e={"alloy.execute":["disabling","alloy.base.behaviour","toggling"],"alloy.focus":["alloy.base.behaviour","focusing","keying"],"alloy.system.init":["alloy.base.behaviour","disabling","toggling","representing"],input:["alloy.base.behaviour","representing","streaming","invalidating"],"alloy.system.detached":["alloy.base.behaviour","representing"]},Ke.mergeWithThunk(O.constant(e))),no()),jt("domModification"),Xr("originalSpec"),Pt("debug.sketcher","unknown")]),n);var e},Al=function(n){var e,t={tag:n.dom().tag(),classes:n.dom().classes(),attributes:D.deepMerge((e=n,dt(Mc(),e.uid())),n.dom().attributes()),styles:n.dom().styles(),domChildren:vn.map(n.components(),function(n){return n.element()})};return vo(D.deepMerge(t,n.dom().innerHtml().map(function(n){return dt("innerHtml",n)}).getOr({}),n.dom().value().map(function(n){return dt("value",n)}).getOr({})))},Bl={add:function(e,n){vn.each(n,function(n){er.add(e,n)})},remove:function(e,n){vn.each(n,function(n){er.remove(e,n)})},toggle:function(e,n){vn.each(n,function(n){er.toggle(e,n)})},hasAll:function(e,n){return vn.forall(n,function(n){return er.has(e,n)})},hasAny:function(e,n){return vn.exists(n,function(n){return er.has(e,n)})},get:function(n){return Zo(n)?function(n){for(var e=n.dom().classList,t=new Array(e.length),o=0;o");o[t[0]]=dt(t[1],n),o[t[1]]=dt(t[0],n)}),o},createBistate:function(n,e,t){return mt([{key:n,value:dt(e,t)},{key:e,value:dt(n,t)}])},createTristate:function(n,e,t,o){return mt([{key:n,value:mt([{key:e,value:o},{key:t,value:o}])},{key:e,value:mt([{key:n,value:o},{key:t,value:o}])},{key:t,value:mt([{key:n,value:o},{key:e,value:o}])}])}}}),Sd=gi.resolve("scrollable"),Td={register:function(n){er.add(n,Sd)},deregister:function(n){er.remove(n,Sd)},scrollable:O.constant(Sd)},kd=function(n){return lt(n,"format").getOr(n.title)},Cd=function(n,e,t,o,r){return{data:{value:n,text:e},type:"item",dom:{tag:"div",classes:r?[gi.resolve("styles-item-is-menu")]:[]},toggling:{toggleOnExecute:!1,toggleClass:gi.resolve("format-matches"),selected:t},itemBehaviours:Bo(r?[]:[fi(n,function(n,e){(e?si.on:si.off)(n)})]),components:[{dom:{tag:"div",attributes:{style:o},innerHtml:e}}]}},Od=function(n,e,t,o){return{value:n,dom:{tag:"div"},components:[Wc.sketch({dom:{tag:"div",classes:[gi.resolve("styles-collapser")]},components:o?[{dom:{tag:"span",classes:[gi.resolve("styles-collapse-icon")]}},zl(n)]:[zl(n)],action:function(n){if(o){var e=t().get(n);dd.collapseMenu(e)}}}),{dom:{tag:"div",classes:[gi.resolve("styles-menu-items-container")]},components:[rd.parts().items({})],behaviours:Bo([kf("adhoc-scrollable-menu",[fo(function(n,e){Oi.set(n.element(),"overflow-y","auto"),Oi.set(n.element(),"-webkit-overflow-scrolling","touch"),Td.register(n.element())}),lo(function(n){Oi.remove(n.element(),"overflow-y"),Oi.remove(n.element(),"-webkit-overflow-scrolling"),Td.deregister(n.element())})])])}],items:e,menuBehaviours:Bo([xd.config({initialState:"after",routes:xd.createTristate("before","current","after",{transition:{property:"transform",transitionClass:"transitioning"}})})])}},Ed=function(o){var r,i,n,e,t,u=(r=o.formats,i=function(){return a},n=Od("Styles",[].concat(vn.map(r.items,function(n){return Cd(kd(n),n.title,n.isSelected(),n.getPreview(),pt(r.expansions,kd(n)))})),i,!1),e=M.map(r.menus,function(n,e){var t=vn.map(n,function(n){return Cd(kd(n),n.title,n.isSelected!==undefined&&n.isSelected(),n.getPreview!==undefined?n.getPreview():"",pt(r.expansions,kd(n)))});return Od(e,t,i,!0)}),t=D.deepMerge(e,dt("styles",n)),{tmenu:dd.tieredData("styles",t,r.expansions)}),a=Ws(dd.sketch({dom:{tag:"div",classes:[gi.resolve("styles-menu")]},components:[],fakeFocus:!0,stayInDom:!0,onExecute:function(n,e){var t=Ss.getValue(e);o.handle(e,t.value)},onEscape:function(){},onOpenMenu:function(n,e){var t=Es(n.element());Os(e.element(),t),xd.jumpTo(e,"current")},onOpenSubmenu:function(n,e,t){var o=Es(n.element()),r=Li(e.element(),'[role="menu"]').getOrDie("hacky"),i=n.getSystem().getByDom(r).getOrDie();Os(t.element(),o),xd.progressTo(i,"before"),xd.jumpTo(t,"after"),xd.progressTo(t,"current")},onCollapseMenu:function(n,e,t){var o=Li(e.element(),'[role="menu"]').getOrDie("hacky"),r=n.getSystem().getByDom(o).getOrDie();xd.progressTo(r,"after"),xd.progressTo(t,"current")},navigateOnHover:!1,openImmediately:!0,data:u.tmenu,markers:{backgroundMenu:gi.resolve("styles-background-menu"),menu:gi.resolve("styles-menu"),selectedMenu:gi.resolve("styles-selected-menu"),item:gi.resolve("styles-item"),selectedItem:gi.resolve("styles-selected-item")}}));return a.asSpec()},Dd=function(n){return pt(n,"items")?(e=n,t=D.deepMerge(ct(e,["items"]),{menu:!0}),o=Md(e.items),{item:t,menus:D.deepMerge(o.menus,dt(e.title,o.items)),expansions:D.deepMerge(o.expansions,dt(e.title,e.title))}):{item:n,menus:{},expansions:{}};var e,t,o},Md=function(n){return vn.foldr(n,function(n,e){var t=Dd(e);return{menus:D.deepMerge(n.menus,t.menus),items:[t.item].concat(n.items),expansions:D.deepMerge(n.expansions,t.expansions)}},{menus:{},expansions:{},items:[]})},Ad={expand:Md},Bd=function(a,n){var c=function(n){return function(){return a.formatter.match(n)}},s=function(n){return function(){return a.formatter.getCssText(n)}},e=lt(n,"style_formats").getOr(cl),f=function(n){return vn.map(n,function(n){if(pt(n,"items")){var e=f(n.items);return D.deepMerge((u=n,D.deepMerge(u,{isSelected:O.constant(!1),getPreview:O.constant("")})),{items:e})}return pt(n,"format")?(i=n,D.deepMerge(i,{isSelected:c(i.format),getPreview:s(i.format)})):(o=Ya((t=n).title),r=D.deepMerge(t,{format:o,isSelected:c(o),getPreview:s(o)}),a.formatter.register(o,r),r);var t,o,r,i,u})};return f(e)},Rd=function(t,n,o){var e,r,i,u=(e=t,i=(r=function(n){return vn.bind(n,function(n){return n.items!==undefined?0e.innerHeight||n.bottom()>e.innerHeight?n.bottom()-e.innerHeight+50:0;0!==t&&e.scrollTo(e.pageXOffset,e.pageYOffset+t)})})].concat(!0===Zd?[]:[$d.bind(Xn.fromDom(o.win()),"blur",function(){t.getByDom(e).each(si.off)}),$d.bind(i,"select",n),$d.bind(o.doc(),"selectionchange",n)]);return{destroy:function(){vn.each(a,function(n){n.unbind()})}}},em=function(n,e){var t=parseInt(Po.get(n,e),10);return isNaN(t)?0:t},tm=(rf=ue.isText,uf="text",af=function(n){return rf(n)?y.from(n.dom().nodeValue):y.none()},cf=Mn.detect().browser,{get:function(n){if(!rf(n))throw new Error("Can only get "+uf+" value of a "+uf+" node");return sf(n).getOr("")},getOption:sf=cf.isIE()&&10===cf.version.major?function(n){try{return af(n)}catch(e){return y.none()}}:af,set:function(n,e){if(!rf(n))throw new Error("Can only set raw "+uf+" value of a "+uf+" node");n.dom().nodeValue=e}}),om=function(n){return tm.getOption(n)},rm=function(n){return"img"===ue.name(n)?1:om(n).fold(function(){return Be.children(n).length},function(n){return n.length})},im=rm,um=_e([{before:["element"]},{on:["element","offset"]},{after:["element"]}]),am={before:um.before,on:um.on,after:um.after,cata:function(n,e,t,o){return n.fold(e,t,o)},getStart:function(n){return n.fold(O.identity,O.identity,O.identity)}},cm=_e([{domRange:["rng"]},{relative:["startSitu","finishSitu"]},{exact:["start","soffset","finish","foffset"]}]),sm=de.immutable("start","soffset","finish","foffset"),fm={domRange:cm.domRange,relative:cm.relative,exact:cm.exact,exactFromRange:function(n){return cm.exact(n.start(),n.soffset(),n.finish(),n.foffset())},range:sm,getWin:function(n){var e=n.match({domRange:function(n){return Xn.fromDom(n.startContainer)},relative:function(n,e){return am.getStart(n)},exact:function(n,e,t,o){return n}});return Be.defaultView(e)}},lm=function(n,e,t,o){var r=Be.owner(n).dom().createRange();return r.setStart(n.dom(),e),r.setEnd(t.dom(),o),r},dm=function(n,e,t,o){var r=lm(n,e,t,o),i=Te(n,t)&&e===o;return r.collapsed&&!i},mm=function(n,e){n.selectNodeContents(e.dom())},gm=function(n){n.deleteContents()},pm=function(n){return{left:O.constant(n.left),top:O.constant(n.top),right:O.constant(n.right),bottom:O.constant(n.bottom),width:O.constant(n.width),height:O.constant(n.height)}},vm={create:function(n){return n.document.createRange()},replaceWith:function(n,e){gm(n),n.insertNode(e.dom())},selectNodeContents:function(n,e){var t=n.document.createRange();return mm(t,e),t},selectNodeContentsUsing:mm,relativeToNative:function(n,e,t){var o,r,i=n.document.createRange();return o=i,e.fold(function(n){o.setStartBefore(n.dom())},function(n,e){o.setStart(n.dom(),e)},function(n){o.setStartAfter(n.dom())}),r=i,t.fold(function(n){r.setEndBefore(n.dom())},function(n,e){r.setEnd(n.dom(),e)},function(n){r.setEndAfter(n.dom())}),i},exactToNative:function(n,e,t,o,r){var i=n.document.createRange();return i.setStart(e.dom(),t),i.setEnd(o.dom(),r),i},deleteContents:gm,cloneFragment:function(n){var e=n.cloneContents();return Xn.fromDom(e)},getFirstRect:function(n){var e=n.getClientRects(),t=0e.innerHeight||t.bottom()>e.innerHeight?Math.min(o,t.bottom()-e.innerHeight+50):0);0!==r&&u.scrollTo(u.pageXOffset,u.pageYOffset+r)})}),Lm(e,n.innerHeight)});return Lm(e,n.innerHeight),{toEditing:function(){jm(u)},destroy:function(){t.unbind()}}},Gm=function(n){return y.some(Xn.fromDom(n.dom().contentWindow.document.body))},$m=function(n){return y.some(Xn.fromDom(n.dom().contentWindow.document))},qm=function(n){return y.from(n.dom().contentWindow)},_m=function(n){return qm(n).bind(Bm)},Km=function(n){return n.getFrame()},Xm=function(n,t){return function(e){return e[n].getOrThunk(function(){var n=Km(e);return function(){return t(n)}})()}},Ym=function(n,e,t,o){return n[t].getOrThunk(function(){return function(n){return $d.bind(e,o,n)}})},Jm=function(n){return{left:O.constant(n.left),top:O.constant(n.top),right:O.constant(n.right),bottom:O.constant(n.bottom),width:O.constant(n.width),height:O.constant(n.height)}},Qm={getBody:Xm("getBody",Gm),getDoc:Xm("getDoc",$m),getWin:Xm("getWin",qm),getSelection:Xm("getSelection",_m),getFrame:Km,getActiveApi:function(a){var c=Km(a);return Gm(c).bind(function(u){return $m(c).bind(function(i){return qm(c).map(function(r){var n=Xn.fromDom(i.dom().documentElement),e=a.getCursorBox.getOrThunk(function(){return function(){return Rm(r).bind(function(n){return Fm(r,n).orThunk(function(){return Bm(r).filter(function(n){return Te(n.start(),n.finish())&&n.soffset()===n.foffset()}).bind(function(n){var e=n.start().dom().getBoundingClientRect();return 0