!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 pt.objOf(pn.map(c,function(n){return n.fold(function(n,e,t,o){return vt.field(n,t,o)},function(n,e){return vt.state(n)})}))}}},Dt=function(r){return{extract:function(t,o,n){var e=pn.map(n,function(n,e){return r.extract(t.concat(["["+e+"]"]),o,n)});return tt(e)},toString:function(){return"array("+r.toString()+")"},toDsl:function(){return pt.arrOf(r)}}},Mt=function(u,a){return{extract:function(t,o,r){var n,e,i=M.keys(r);return(n=t,e=i,Dt(Ct(u)).extract(n,O.identity,e)).bind(function(n){var e=pn.map(n,function(n){return xt.field(n,n,Xe(),a)});return Et(e).extract(t,o,r)})},toString:function(){return"setOf("+a.toString()+")"},toDsl:function(){return pt.setOf(u,a)}}},At=O.constant(Ct($e.value)),Bt=(O.compose(Dt,Et),xt.state),Rt=xt.field,It=function(n){return Rt(n,n,Xe(),At())},Ft=function(n,e){return Rt(n,n,Xe(),e)},Nt=function(n){return Rt(n,n,Xe(),Ct(function(n){return E.isFunction(n)?$e.value(n):$e.error("Not a function")}))},Vt=function(n,e){return Rt(n,n,Xe(),Et(e))},Ht=function(n){return Rt(n,n,Ye(),At())},jt=function(n,e){return Rt(n,n,Ye(),Et(e))},zt=function(n,e){return Rt(n,n,Ye(),Ot(e))},Lt=function(n,e){return Rt(n,n,Ke(e),At())},Pt=function(n,e,t){return Rt(n,n,Ke(e),t)},Wt=function(n,e){return Bt(n,e)},Ut=function(t,e,o,r,i){return ft(r,i).fold(function(){return n=r,e=i,wt(t,function(){return'The chosen schema: "'+e+'" did not exist in branches: '+yt(n)});var n,e},function(n){return Et(n).extract(t.concat(["branch: "+i]),e,o)})},Gt=function(r,i){return{extract:function(e,t,o){return ft(o,r).fold(function(){return n=r,wt(e,function(){return'Choice schema did not contain choice key: "'+n+'"'});var n},function(n){return Ut(e,t,o,i,n)})},toString:function(){return"chooseOn("+r+"). Possible values: "+M.keys(i)},toDsl:function(){return pt.choiceOf(r,i)}}},$t=Ct($e.value),qt=function(n,e,t,o){return e.extract([n],t,o).fold(function(n){return $e.error({input:o,errors:n})},$e.value)},_t=function(n,e,t){return qt(n,e,O.constant,t)},Kt=function(n){return n.fold(function(n){throw new Error(Jt(n))},O.identity)},Xt=function(n,e,t){return Kt((o=t,qt(n,e,O.identity,o)));var o},Yt=function(n,e,t){return Kt(_t(n,e,t))},Jt=function(n){return"Errors: \n"+(e=n.errors,t=10 ")+")\n"+n.getErrorInfo()}))+"\n\nInput object: "+yt(n.input);var e,t},Qt=function(n,e){return Gt(n,e)},Zt=O.constant($t),no=function(n){if(!gt(n,"can")&&!gt(n,"abort")&&!gt(n,"run"))throw new Error("EventHandler defined by: "+bt(n,null,2)+" does not have can, abort, or run!");return Xt("Extracting event.handler",Ot([Lt("can",O.constant(!0)),Lt("abort",O.constant(!1)),Lt("run",O.noop)]),n)},eo=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 pn.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 pn.foldl(r,function(n,e){return n||i(e).apply(undefined,t)},!1)});return no({can:t,abort:u,run:function(){var e=Array.prototype.slice.call(arguments,0);pn.each(n,function(n){n.run.apply(undefined,e)})}})},to=dt,oo=function(n,e){return{key:n,value:no({abort:e})}},ro=function(n,e){return{key:n,value:no({run:e})}},io=function(n,e,t){return{key:n,value:no({run:function(n){e.apply(undefined,[n].concat(t))}})}},uo=function(n){return function(o){return{key:n,value:no({run:function(n,e){var t;t=e,Se(n.element(),t.event().target())&&o(n,e)}})}}},ao=function(n,e,t){var u,o,r=e.partUids()[t];return o=r,ro(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())})})},co=function(n){return ro(n,function(n,e){e.cut()})},so=uo(Ln()),fo=uo(Pn()),lo=uo(jn()),mo=(u=In(),function(n){return ro(u,n)}),go=function(n,e){return n},po=le.immutableBag(["tag"],["classes","attributes","styles","value","innerHtml","domChildren","defChildren"]),vo=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)})}},ho=le.immutableBag([],["classes","attributes","styles","value","innerHtml","defChildren","domChildren"]),bo=function(e,n,t){return n.fold(function(){return t.fold(function(){return{}},function(n){return lt(e,n)})},function(n){return t.fold(function(){return lt(e,n)},function(n){return lt(e,n)})})},yo=function(t,o,r){return lo(function(n,e){r(n,t,o)})},wo=function(n,e,t,o,r,i){var u,a,c=n,s=jt(e,[(u="config",a=n,Rt(u,u,Ye(),a))]);return So(c,s,e,t,o,r,i)},xo=function(n){return{key:n,value:undefined}},So=function(t,n,o,r,e,i,u){var a=function(n){return gt(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 go(n)}),f=D.deepMerge(s,c,{revoke:O.curry(xo,o),config:function(n){var e=Yt(o+"-config",t,n);return{key:o,value:{config:e,me:f,configAsRaw:L(function(){return Xt(o+"-config",t,n)}),initialConfig:n,state:u}}},schema:function(){return n},exhibit:function(n,t){return a(n).bind(function(e){return ft(r,"exhibit").map(function(n){return n(t,e.config,e.state)})}).getOr(ho({}))},name:function(){return o},handlers:function(n){return a(n).bind(function(e){return ft(r,"events").map(function(n){return n(e.config,e.state)})}).getOr({})}});return f},To=function(n,e){return ko(n,e,{validate:E.isFunction,label:"function"})},ko=function(o,r,i){if(0===r.length)throw new Error("You must specify at least one required field.");return fe.validateStrArr("required",r),fe.checkDupes(r),function(e){var t=M.keys(e);pn.forall(r,function(n){return pn.contains(t,n)})||fe.reqMessage(r,t),o(r,t);var n=pn.filter(r,function(n){return!i.validate(e[n],n)});return 0"}),Zt()),ec=Lt("defaults",O.constant({})),tc=Lt("overrides",O.constant({})),oc=Et([Ja,Qa,Za,nc,ec,tc]),rc=Et([Ja,Qa,Za,ec,tc]),ic=Et([Ja,Qa,Za,nc,ec,tc]),uc=Et([Ja,Qa,Za,It("unit"),nc,ec,tc]),ac=function(n){var e=function(n){return n.name()};return n.fold(e,e,e,e)},cc=function(t,o){return function(n){var e=Yt("Converting part type",o,n);return t(e)}},sc=cc(Ya.required,oc),fc=(cc(Ya.external,rc),cc(Ya.optional,ic)),lc=cc(Ya.group,uc),dc=O.constant("entirety"),mc=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":lt("part-"+e.name(),r)})},gc=function(r,n){var i={};return pn.each(n,function(n){var e;(e=n,e.fold(y.some,y.none,y.some,y.some)).each(function(t){var o=pc(r,t.pname());i[t.name()]=function(n){var e=Xt("Part: "+t.name()+" in "+r,Et(t.schema()),n);return D.deepMerge(o,{config:n,validated:e})}})}),i},pc=function(n,e){return{uiType:_a(),owner:n,name:e}},vc=function(n,e,t){return o=e,r=t,i={},u={},pn.each(r,function(n){n.fold(function(o){i[o.pname()]=$a(!0,function(n,e,t){return o.factory().sketch(mc(n,o,e,t))})},function(n){var e=o.parts()[n.name()]();u[n.name()]=O.constant(mc(o,n,e[dc()]()))},function(o){i[o.pname()]=$a(!1,function(n,e,t){return o.factory().sketch(mc(n,o,e,t))})},function(r){i[r.pname()]=qa(!0,function(e,n,t){var o=e[r.name()]();return pn.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},hc=function(n,e,t){return Ga(y.some(n),e,e.components(),t)},bc=function(n,e,t){var o=e.partUids()[t];return n.getSystem().getByUid(o).toOption()},yc=function(n,e,t){return bc(n,e,t).getOrDie("Could not find part: "+t)},wc=function(e,n){var t,o=(t=n,pn.map(t,ac));return dt(pn.map(o,function(n){return{key:n,value:e+"-"+n}}))},xc=function(e){return Rt("partUids","partUids",Qe(function(n){return wc(n.uid,e)}),Zt())},Sc=Xa("alloy-premade"),Tc=Xa("api"),kc=function(n){return lt(Sc,n)},Cc=function(o){return function(n){var e=Array.prototype.slice.call(arguments,0),t=n.config(Tc);return o.apply(undefined,[t].concat(e))}},Oc=O.constant(Tc),Ec=O.constant("alloy-id-"),Dc=O.constant("data-alloy-id"),Mc=Ec(),Ac=Dc(),Bc=function(n,e){var t=Xa(Mc+n);return Lo.set(e,Ac,t),t},Rc=function(n){var e=ie.isElement(n)?Lo.get(n,Ac):null;return y.from(e)},Ic=function(n){return Xa(n)},Fc=(O.constant(Ac),function(n,e,t,o,r){var i,u,a=(u=r,(0<(i=o).length?[Vt("parts",i)]:[]).concat([It("uid"),Lt("dom",{}),Lt("components",[]),Kr("originalSpec"),Lt("debug.sketcher",{})]).concat(u));return Yt(n+" [SpecSchema]",Ot(a.concat(e)),t)}),Nc=function(n,e,t,o,r){var i,u=Vc(r),a=(i=t,pn.bind(i,function(n){return n.fold(y.none,y.some,y.none,y.none).map(function(n){return Vt(n.name(),n.schema().concat([Kr(dc())]))}).toArray()})),c=xc(t),s=Fc(n,e,u,a,[c]),f=vc(0,s,t),l=hc(n,s,f.internals());return D.deepMerge(o(s,l,u,f.externals()),{"debug.sketcher":lt(n,r)})},Vc=function(n){return D.deepMerge({uid:Ic("uid")},n)},Hc=Ot([It("name"),It("factory"),It("configFields"),Lt("apis",{}),Lt("extraApis",{})]),jc=Ot([It("name"),It("factory"),It("configFields"),It("partFields"),Lt("apis",{}),Lt("extraApis",{})]),zc=function(n){var a=Xt("Sketcher for "+n.name,Hc,n),e=M.map(a.apis,Cc),t=M.map(a.extraApis,function(n,e){return go(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=Vc(r=n),u=Fc(e,t,i,[],[]),D.deepMerge(o(u,i),{"debug.sketcher":lt(e,r)});var e,t,o,r,i,u}},e,t)},Lc=function(n){var e=Xt("Sketcher for "+n.name,jc,n),t=gc(e.name,e.partFields),o=M.map(e.apis,Cc),r=M.map(e.extraApis,function(n,e){return go(n)});return D.deepMerge({name:O.constant(e.name),partFields:O.constant(e.partFields),configFields:O.constant(e.configFields),sketch:function(n){return Nc(e.name,e.configFields,e.partFields,e.factory,n)},parts:O.constant(t)},o,r)},Pc=zc({name:"Button",factory:function(n,e){var t,o,r,i=(t=n.action(),o=function(n,e){e.stop(),Gn(n)},r=Dn.detect().deviceType.isTouch()?[ro(Nn(),o)]:[ro(H(),o),ro(A(),function(n,e){e.cut()})],to(pn.flatten([t.map(function(t){return ro(In(),function(n,e){t(n),e.stop()})}).toArray(),r]))),u=ft(n.dom(),"attributes").bind(ct("type")),a=ft(n.dom(),"tag");return{uid:n.uid(),dom:n.dom(),components:n.components(),events:i,behaviours:D.deepMerge(Ao([bi.config({}),Ha.config({mode:"execution",useSpace:!0,useEnter:!0})]),za(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:[Lt("uid",undefined),It("dom"),Lt("components",[]),ja("buttonBehaviours",[bi,Ha]),Ht("action"),Ht("role"),Lt("eventOrder",{})]}),Wc=Object.freeze({events:function(n){return to([oo(z(),O.constant(!0))])},exhibit:function(n,e){return ho({styles:{"-webkit-user-select":"none","user-select":"none","-ms-user-select":"none","-moz-user-select":"-moz-none"},attributes:{unselectable:"on"}})}}),Uc=Ro({fields:[],name:"unselecting",active:Wc}),Gc=function(n){var e,t,o,r=Kn.fromHtml(n),i=Ae.children(r),u=(t=(e=r).dom().attributes!==undefined?e.dom().attributes:[],pn.foldl(t,function(n,e){return"class"===e.name?n:D.deepMerge(n,lt(e.name,e.value))},{})),a=(o=r,Array.prototype.slice.call(o.dom().classList,0)),c=0===i.length?{}:{innerHtml:kr(r)};return D.deepMerge({tag:ie.name(r),classes:a,attributes:u},c)},$c=function(n){var e=yn(n,{prefix:mi.prefix()});return Gc(e)},qc=function(n){return{dom:$c(n)}},_c=function(n){return Ao([ci.config({toggleClass:mi.resolve("toolbar-button-selected"),toggleOnExecute:!1,aria:{mode:"pressed"}}),si(n,function(n,e){(e?ci.on:ci.off)(n)})])},Kc=function(n,e,t){return Pc.sketch({dom:$c(''),action:e,buttonBehaviours:D.deepMerge(Ao([Uc.config({})]),t)})},Xc={forToolbar:Kc,forToolbarCommand:function(n,e){return Kc(e,function(){n.execCommand(e)},{})},forToolbarStateAction:function(n,e,t,o){var r=_c(t);return Kc(e,o,r)},forToolbarStateCommand:function(n,e){var t=_c(e);return Kc(e,function(){n.execCommand(e)},t)}},Yc=function(n,e,t){return Math.max(e,Math.min(t,n))},Jc=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=Yc(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 Yc(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},Qc="slider.change.value",Zc=Dn.detect().deviceType.isTouch(),ns=function(n){var e;return(e=n.event().raw(),Zc&&e.touches!==undefined&&1===e.touches.length?y.some(e.touches[0]):Zc&&e.touches!==undefined?y.none():Zc||e.clientX===undefined?y.none():y.some(e)).map(function(n){return n.clientX})},es=function(n,e){Un(n,Qc,{value:e})},ts=function(i,u,a,n){return ns(n).map(function(n){var e,t,o,r;return e=i,o=n,r=Jc(a,(t=u).min(),t.max(),o,t.stepSize(),t.snapToGrid(),t.snapStart()),es(e,r),n})},os=function(n,e){var t,o,r,i,u=(t=e.value().get(),o=e.min(),r=e.max(),i=e.stepSize(),to.max()?bc(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=Os(t.element())/2;Ci.set(t.element(),"left",e-o+"px")},o=function(n,e){var t=c.value().get(),o=r(n);return t!==e||Ci.getRaw(o.element(),"left").isNone()?(c.value().set(e),u(n),c.onChange()(n,o,e),y.some(!0)):y.none()},a=Es?[ro(T(),function(n,e){c.onDragStart()(n,r(n))}),ro(C(),function(n,e){c.onDragEnd()(n,r(n))})]:[ro(A(),function(n,e){e.stop(),c.onDragStart()(n,r(n)),c.mouseIsDown().set(!0)}),ro(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(Ao(pn.flatten([Es?[]:[Ha.config({mode:"special",focusIn:function(n){return bc(n,c,"spectrum").map(Ha.focusIn).map(O.constant(!0))}})],[xs.config({store:{mode:"manual",getValue:function(n){return c.value().get()}}})]])),za(c.sliderBehaviours())),events:to([ro(is(),function(n,e){o(n,e.event().value())}),so(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)}}}),Ms=function(e,t,o){return Xc.forToolbar(t,function(){var n=o();e.setContextToolbar([{label:t+" group",items:n}])},{})},As=function(n){return[(r=n,i=function(n){return n<0?"black":360'),components:[Ds.parts()["left-edge"](qc('
')),Ds.parts().spectrum({dom:$c('
'),components:[qc('
')],behaviours:Ao([ci.config({toggleClass:mi.resolve("thumb-active")})])}),Ds.parts()["right-edge"](qc('
')),Ds.parts().thumb({dom:$c('
'),behaviours:Ao([ci.config({toggleClass:mi.resolve("thumb-active")})])})],onChange:function(n,e,t){var o=i(t);Ci.set(e.element(),"background-color",o),r.onChange(n,e,o)},onDragStart:function(n,e){ci.on(e)},onDragEnd:function(n,e){ci.off(e)},onInit:function(n,e,t){var o=i(t);Ci.set(e.element(),"background-color",o)},stepSize:10,min:0,max:360,getInitialValue:r.getInitialValue,sliderBehaviours:Ao([fi(Ds.refresh)])}))];var r,i},Bs=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 Ms(n,"color",function(){return As(e)})},Rs=Ot([It("getInitialValue"),It("onChange"),It("category"),It("sizes")]),Is=function(n){var r=Xt("SizeSlider",Rs,n);return Ds.sketch({dom:{tag:"div",classes:[mi.resolve("slider-"+r.category+"-size-container"),mi.resolve("slider"),mi.resolve("slider-size-container")]},onChange:function(n,e,t){var o;0<=(o=t)&&o'),components:[qc('
')]}),Ds.parts().thumb({dom:$c('
'),behaviours:Ao([ci.config({toggleClass:mi.resolve("thumb-active")})])})]})},Fs=function(n,e,t){for(var o=n.dom(),r=E.isFunction(t)?t:O.constant(!1);o.parentNode;){o=o.parentNode;var i=Kn.fromDom(o),u=e(i);if(u.isSome())return u;if(r(i))break}return y.none()},Ns=function(n,e,t){return e(n).orThunk(function(){return t(n)?y.none():Fs(n,e,t)})},Vs=["9px","10px","11px","12px","14px","16px","18px","20px","24px","32px","36px"],Hs=function(n){var e,t,o=n.selection.getStart(),r=Kn.fromDom(o),i=Kn.fromDom(n.getBody()),u=(e=function(n){return Se(i,n)},t=r,(ie.isElement(t)?y.some(t):Ae.parent(t)).map(function(n){return Ns(n,function(n){return Ci.getRaw(n,"font-size")},e).getOrThunk(function(){return Ci.get(n,"font-size")})}).getOr(""));return pn.find(Vs,function(n){return u===n}).getOr("medium")},js={candidates:O.constant(Vs),get:function(n){var e,t=Hs(n);return(e=t,pn.findIndex(Vs,function(n){return n===e})).getOr(2)},apply:function(o,n){var e;(e=n,y.from(Vs[e])).each(function(n){var e,t;t=n,Hs(e=o)!==t&&e.execCommand("fontSize",!1,t)})}},zs=js.candidates(),Ls=function(n){return[qc(''),(e=n,Is({onChange:e.onChange,sizes:zs,category:"font",getInitialValue:e.getInitialValue})),qc('')];var e},Ps=function(n){var e=n.uid!==undefined&>(n,"uid")?n.uid:Ic("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 Ws(n,e){return Gs(document.createElement("canvas"),n,e)}function Us(n){return n.getContext("2d")}function Gs(n,e,t){return n.width=e,n.height=t,n}var $s={create:Ws,clone:function(n){var e;return Us(e=Ws(n.width,n.height)).drawImage(n,0,0),e},resize:Gs,get2dContext:Us,get3dContext:function(n){var e=null;try{e=n.getContext("webgl")||n.getContext("experimental-webgl")}catch(t){}return e||(e=null),e}},qs={getWidth:function(n){return n.naturalWidth||n.width},getHeight:function(n){return n.naturalHeight||n.height}},_s=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()}})},mf=function(n){return n.dom().textContent},gf=function(n,e){n.dom().textContent=e},pf=function(n){return 0'),action:function(n){var e=t.get(n);xs.setValue(e,"")}}));return{name:n,spec:Ef.sketch({dom:$c('
'),components:[t.asSpec(),o.asSpec()],containerBehaviours:Ao([ci.config({toggleClass:mi.resolve("input-container-empty")}),Of.config({find:function(n){return y.some(t.get(n))}}),Tf("input-clearing",[ro(N(),function(n){var e=t.get(n);(0"},Qf=function(r,n,e){return D.deepMerge({"debug.sketcher":{Form:e},uid:r.uid(),dom:r.dom(),components:n,behaviours:D.deepMerge(Ao([xs.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(Of.getCurrent).map(xs.getValue)})},setValue:function(t,n){M.each(n,function(e,n){bc(t,r,n).each(function(n){Of.getCurrent(n).each(function(n){xs.setValue(n,e)})})})}}})]),za(r.formBehaviours())),apis:{getField:function(n,e){return bc(n,r,e).bind(Of.getCurrent)}}})},Zf=(Cc(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=Jf(n),r=e,{uiType:_a(),owner:t,name:o,config:r,validated:{}};var t,o,r},record:function(){return i}}),t=n(e),o=e.record(),r=pn.map(o,function(n){return sc({name:n,pname:Jf(n)})});return Nc("form",Yf,r,Qf,t)}),nl=function(n){var e=ir(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))}}},el={destroyable:function(){return nl(function(n){n.destroy()})},unbindable:function(){return nl(function(n){n.unbind()})},api:function(){var e=ir(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=ir(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)}}}},tl=function(n){return{xValue:n,points:[]}},ol=function(n,e){if(e===n.xValue)return n;var t=0'),action:function(n){Un(n,o,{direction:e})},buttonBehaviours:Ao([Xf.config({disableClass:mi.resolve("toolbar-navigation-disabled"),disabled:!t})])})},i=function(n,r){var i=Vi(n.element(),"."+mi.resolve("serialised-dialog-screen"));Li(n.element(),"."+mi.resolve("serialised-dialog-chain")).each(function(o){0<=u.state.currentScreen.get()+r&&u.state.currentScreen.get()+r'),components:[Ef.sketch({dom:$c('
'),components:pn.map(u.fields,function(n,e){return e<=u.maxFieldIndex?Ef.sketch({dom:$c('
'),components:pn.flatten([[r(-1,"previous",0'),behaviours:Ao([fu.config({highlightClass:mi.resolve("dot-active"),itemClass:mi.resolve("dot-item")})]),components:pn.bind(u.fields,function(n,e){return e<=u.maxFieldIndex?[qc('
')]:[]})});return{dom:$c('
'),components:[c.asSpec(),s.asSpec()],behaviours:Ao([Ha.config({mode:"special",focusIn:function(n){var e=c.get(n);Ha.focusIn(e)}}),Tf("serializer-wrapper-events",[ro(T(),function(n,e){u.state.dialogSwipeState.set(tl(e.event().raw().touches[0].clientX))}),ro(k(),function(n,e){u.state.dialogSwipeState.on(function(n){e.event().prevent(),u.state.dialogSwipeState.set(ol(n,e.event().raw().touches[0].clientX))})}),ro(C(),function(o){u.state.dialogSwipeState.on(function(n){var e=c.get(o),t=-1*rl(n);i(e,t)})})])])}},ul=L(function(t,o){return[{label:"the link group",items:[il({fields:[Vf("url","Type or paste URL"),Vf("text","Link text"),Vf("title","Link title"),Vf("target","Link target"),(n="link",{name:n,spec:Df.sketch({dom:{tag:"span",styles:{display:"none"}},getInitialValue:function(){return y.none()}})})],maxFieldIndex:["url","text","title","target"].length-1,getInitialValue:function(){return y.some(yf.getInfo(o))},onExecute:function(n){var e=xs.getValue(n);yf.applyInfo(o,e),t.restoreToolbar(),o.focus()}})]}];var n}),al=[{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"}]}],cl={events:to([(ef=An(),tf=function(n,e){var t,o,r=e.event().originator(),i=e.event().target();return o=i,!(Se(t=r,n.element())&&!Se(t,o)&&(console.warn(An()+" did not get interpreted by the desired target. \nOriginator: "+Mr(r)+"\nTarget: "+Mr(i)+"\nCheck the "+An()+" event handlers"),1))},{key:ef,value:no({can:tf})})])},sl=O.identity,fl=Oo.exactly(["debugInfo","triggerFocus","triggerEvent","triggerEscape","addToWorld","removeFromWorld","addToGui","removeFromGui","build","getByUid","getByDom","broadcast","broadcastOn"]),ll=function(e){var n=function(n){return function(){throw new Error("The component must be in a context to send: "+n+"\n"+Mr(e().element())+" is not in context.")}};return fl({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")})},dl=function(e,n){var t=pn.map(n,function(n){return Rt(n.name(),n.name(),Ye(),Et([It("config"),Lt("state",Mo)]))}),o=_t("component.behaviours",Et(t),e.behaviours).fold(function(n){throw new Error(Jt(n)+"\nComplete spec:\n"+bt(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())}}))})}},ml=function(n){return n.list},gl=function(n){return n.data},pl=function(n,r){var i={};return M.each(n,function(n,o){M.each(n,function(n,e){var t=st(e,[])(i);i[e]=t.concat([r(o,n)])})}),i},vl=function(n,e){return{name:O.constant(n),modification:e}},hl=function(n,e,t){return 1 "):r[0].name();return lt(i,(e=o,{handler:t,purpose:O.constant(e)}))})});return mt(e,{})},Dl=function(n){return _t("custom.definition",Ot([Rt("dom","dom",Xe(),Ot([It("tag"),Lt("styles",{}),Lt("classes",[]),Lt("attributes",{}),Ht("value"),Ht("innerHtml")])),It("components"),It("uid"),Lt("events",{}),Lt("apis",O.constant({})),Rt("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"]},_e.mergeWithThunk(O.constant(e))),Zt()),Ht("domModification"),Kr("originalSpec"),Lt("debug.sketcher","unknown")]),n);var e},Ml=function(n){var e,t={tag:n.dom().tag(),classes:n.dom().classes(),attributes:D.deepMerge((e=n,lt(Dc(),e.uid())),n.dom().attributes()),styles:n.dom().styles(),domChildren:pn.map(n.components(),function(n){return n.element()})};return po(D.deepMerge(t,n.dom().innerHtml().map(function(n){return lt("innerHtml",n)}).getOr({}),n.dom().value().map(function(n){return lt("value",n)}).getOr({})))},Al={add:function(e,n){pn.each(n,function(n){nr.add(e,n)})},remove:function(e,n){pn.each(n,function(n){nr.remove(e,n)})},toggle:function(e,n){pn.each(n,function(n){nr.toggle(e,n)})},hasAll:function(e,n){return pn.forall(n,function(n){return nr.has(e,n)})},hasAny:function(e,n){return pn.exists(n,function(n){return nr.has(e,n)})},get:function(n){return Qo(n)?function(n){for(var e=n.dom().classList,t=new Array(e.length),o=0;o");o[t[0]]=lt(t[1],n),o[t[1]]=lt(t[0],n)}),o},createBistate:function(n,e,t){return dt([{key:n,value:lt(e,t)},{key:e,value:lt(n,t)}])},createTristate:function(n,e,t,o){return dt([{key:n,value:dt([{key:e,value:o},{key:t,value:o}])},{key:e,value:dt([{key:n,value:o},{key:t,value:o}])},{key:t,value:dt([{key:n,value:o},{key:e,value:o}])}])}}}),xd=mi.resolve("scrollable"),Sd={register:function(n){nr.add(n,xd)},deregister:function(n){nr.remove(n,xd)},scrollable:O.constant(xd)},Td=function(n){return ft(n,"format").getOr(n.title)},kd=function(n,e,t,o,r){return{data:{value:n,text:e},type:"item",dom:{tag:"div",classes:r?[mi.resolve("styles-item-is-menu")]:[]},toggling:{toggleOnExecute:!1,toggleClass:mi.resolve("format-matches"),selected:t},itemBehaviours:Ao(r?[]:[si(n,function(n,e){(e?ci.on:ci.off)(n)})]),components:[{dom:{tag:"div",attributes:{style:o},innerHtml:e}}]}},Cd=function(n,e,t,o){return{value:n,dom:{tag:"div"},components:[Pc.sketch({dom:{tag:"div",classes:[mi.resolve("styles-collapser")]},components:o?[{dom:{tag:"span",classes:[mi.resolve("styles-collapse-icon")]}},jl(n)]:[jl(n)],action:function(n){if(o){var e=t().get(n);ld.collapseMenu(e)}}}),{dom:{tag:"div",classes:[mi.resolve("styles-menu-items-container")]},components:[od.parts().items({})],behaviours:Ao([Tf("adhoc-scrollable-menu",[so(function(n,e){Ci.set(n.element(),"overflow-y","auto"),Ci.set(n.element(),"-webkit-overflow-scrolling","touch"),Sd.register(n.element())}),fo(function(n){Ci.remove(n.element(),"overflow-y"),Ci.remove(n.element(),"-webkit-overflow-scrolling"),Sd.deregister(n.element())})])])}],items:e,menuBehaviours:Ao([wd.config({initialState:"after",routes:wd.createTristate("before","current","after",{transition:{property:"transform",transitionClass:"transitioning"}})})])}},Od=function(o){var r,i,n,e,t,u=(r=o.formats,i=function(){return a},n=Cd("Styles",[].concat(pn.map(r.items,function(n){return kd(Td(n),n.title,n.isSelected(),n.getPreview(),gt(r.expansions,Td(n)))})),i,!1),e=M.map(r.menus,function(n,e){var t=pn.map(n,function(n){return kd(Td(n),n.title,n.isSelected!==undefined&&n.isSelected(),n.getPreview!==undefined?n.getPreview():"",gt(r.expansions,Td(n)))});return Cd(e,t,i,!0)}),t=D.deepMerge(e,lt("styles",n)),{tmenu:ld.tieredData("styles",t,r.expansions)}),a=Ps(ld.sketch({dom:{tag:"div",classes:[mi.resolve("styles-menu")]},components:[],fakeFocus:!0,stayInDom:!0,onExecute:function(n,e){var t=xs.getValue(e);o.handle(e,t.value)},onEscape:function(){},onOpenMenu:function(n,e){var t=Os(n.element());Cs(e.element(),t),wd.jumpTo(e,"current")},onOpenSubmenu:function(n,e,t){var o=Os(n.element()),r=zi(e.element(),'[role="menu"]').getOrDie("hacky"),i=n.getSystem().getByDom(r).getOrDie();Cs(t.element(),o),wd.progressTo(i,"before"),wd.jumpTo(t,"after"),wd.progressTo(t,"current")},onCollapseMenu:function(n,e,t){var o=zi(e.element(),'[role="menu"]').getOrDie("hacky"),r=n.getSystem().getByDom(o).getOrDie();wd.progressTo(r,"after"),wd.progressTo(t,"current")},navigateOnHover:!1,openImmediately:!0,data:u.tmenu,markers:{backgroundMenu:mi.resolve("styles-background-menu"),menu:mi.resolve("styles-menu"),selectedMenu:mi.resolve("styles-selected-menu"),item:mi.resolve("styles-item"),selectedItem:mi.resolve("styles-selected-item")}}));return a.asSpec()},Ed=function(n){return gt(n,"items")?(e=n,t=D.deepMerge(at(e,["items"]),{menu:!0}),o=Dd(e.items),{item:t,menus:D.deepMerge(o.menus,lt(e.title,o.items)),expansions:D.deepMerge(o.expansions,lt(e.title,e.title))}):{item:n,menus:{},expansions:{}};var e,t,o},Dd=function(n){return pn.foldr(n,function(n,e){var t=Ed(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:[]})},Md={expand:Dd},Ad=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=ft(n,"style_formats").getOr(al),f=function(n){return pn.map(n,function(n){if(gt(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 gt(n,"format")?(i=n,D.deepMerge(i,{isSelected:c(i.format),getPreview:s(i.format)})):(o=Xa((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)},Bd=function(t,n,o){var e,r,i,u=(e=t,i=(r=function(n){return pn.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===Qd?[]:[Gd.bind(Kn.fromDom(o.win()),"blur",function(){t.getByDom(e).each(ci.off)}),Gd.bind(i,"select",n),Gd.bind(o.doc(),"selectionchange",n)]);return{destroy:function(){pn.each(a,function(n){n.unbind()})}}},nm=function(n,e){var t=parseInt(Lo.get(n,e),10);return isNaN(t)?0:t},em=(of=ie.isText,rf="text",uf=function(n){return of(n)?y.from(n.dom().nodeValue):y.none()},af=Dn.detect().browser,{get:function(n){if(!of(n))throw new Error("Can only get "+rf+" value of a "+rf+" node");return cf(n).getOr("")},getOption:cf=af.isIE()&&10===af.version.major?function(n){try{return uf(n)}catch(e){return y.none()}}:uf,set:function(n,e){if(!of(n))throw new Error("Can only set raw "+rf+" value of a "+rf+" node");n.dom().nodeValue=e}}),tm=function(n){return em.getOption(n)},om=function(n){return"img"===ie.name(n)?1:tm(n).fold(function(){return Ae.children(n).length},function(n){return n.length})},rm=om,im=qe([{before:["element"]},{on:["element","offset"]},{after:["element"]}]),um={before:im.before,on:im.on,after:im.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)}},am=qe([{domRange:["rng"]},{relative:["startSitu","finishSitu"]},{exact:["start","soffset","finish","foffset"]}]),cm=le.immutable("start","soffset","finish","foffset"),sm={domRange:am.domRange,relative:am.relative,exact:am.exact,exactFromRange:function(n){return am.exact(n.start(),n.soffset(),n.finish(),n.foffset())},range:cm,getWin:function(n){var e=n.match({domRange:function(n){return Kn.fromDom(n.startContainer)},relative:function(n,e){return um.getStart(n)},exact:function(n,e,t,o){return n}});return Ae.defaultView(e)}},fm=function(n,e,t,o){var r=Ae.owner(n).dom().createRange();return r.setStart(n.dom(),e),r.setEnd(t.dom(),o),r},lm=function(n,e,t,o){var r=fm(n,e,t,o),i=Se(n,t)&&e===o;return r.collapsed&&!i},dm=function(n,e){n.selectNodeContents(e.dom())},mm=function(n){n.deleteContents()},gm=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)}},pm={create:function(n){return n.document.createRange()},replaceWith:function(n,e){mm(n),n.insertNode(e.dom())},selectNodeContents:function(n,e){var t=n.document.createRange();return dm(t,e),t},selectNodeContentsUsing:dm,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:mm,cloneFragment:function(n){var e=n.cloneContents();return Kn.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)})}),zm(e,n.innerHeight)});return zm(e,n.innerHeight),{toEditing:function(){Hm(u)},destroy:function(){t.unbind()}}},Um=function(n){return y.some(Kn.fromDom(n.dom().contentWindow.document.body))},Gm=function(n){return y.some(Kn.fromDom(n.dom().contentWindow.document))},$m=function(n){return y.from(n.dom().contentWindow)},qm=function(n){return $m(n).bind(Am)},_m=function(n){return n.getFrame()},Km=function(n,t){return function(e){return e[n].getOrThunk(function(){var n=_m(e);return function(){return t(n)}})()}},Xm=function(n,e,t,o){return n[t].getOrThunk(function(){return function(n){return Gd.bind(e,o,n)}})},Ym=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)}},Jm={getBody:Km("getBody",Um),getDoc:Km("getDoc",Gm),getWin:Km("getWin",$m),getSelection:Km("getSelection",qm),getFrame:_m,getActiveApi:function(a){var c=_m(a);return Um(c).bind(function(u){return Gm(c).bind(function(i){return $m(c).map(function(r){var n=Kn.fromDom(i.dom().documentElement),e=a.getCursorBox.getOrThunk(function(){return function(){return Bm(r).bind(function(n){return Im(r,n).orThunk(function(){return Am(r).filter(function(n){return Se(n.start(),n.finish())&&n.soffset()===n.foffset()}).bind(function(n){var e=n.start().dom().getBoundingClientRect();return 0