!function(p){"use strict";var I=function(){},v=function(t,r){return function(){for(var n=[],e=0;e "+r.toString()},function(n,e){return"state("+n+")"})}).join("\n")+"}"},toDsl:function(){return Ct.objOf(wn(c,function(n){return n.fold(function(n,e,t,r){return Et.field(n,t,r)},function(n,e){return Et.state(n)})}))}}},Ht=function(t,i){var e=function(n,e){return(o=Nt(t),{extract:function(t,r,n){var e=wn(n,function(n,e){return o.extract(t.concat(["["+e+"]"]),r,n)});return mt(e)},toString:function(){return"array("+o.toString()+")"},toDsl:function(){return Ct.arrOf(o)}}).extract(n,h,e);var o};return{extract:function(t,r,o){var n=N(o);return e(t,n).bind(function(n){var e=wn(n,function(n){return Ft.field(n,n,ut(),i)});return jt(e).extract(t,r,o)})},toString:function(){return"setOf("+i.toString()+")"},toDsl:function(){return Ct.setOf(t,i)}}},zt=A(Nt(tt.value)),Lt=Ft.state,Pt=Ft.field,$t=function(t,e,r,o,i){return xt(o,i).fold(function(){return n=o,e=i,Mt(t,function(){return'The chosen schema: "'+e+'" did not exist in branches: '+At(n)});var n,e},function(n){return jt(n).extract(t.concat(["branch: "+i]),e,r)})},Wt=function(o,i){return{extract:function(e,t,r){return xt(r,o).fold(function(){return n=o,Mt(e,function(){return'Choice schema did not contain choice key: "'+n+'"'});var n},function(n){return $t(e,t,r,i,n)})},toString:function(){return"chooseOn("+o+"). Possible values: "+N(i)},toDsl:function(){return Ct.choiceOf(o,i)}}},Ut=Nt(tt.value),Gt=function(n,e,t,r){return e.extract([n],t,r).fold(function(n){return tt.error({input:r,errors:n})},tt.value)},qt=function(n,e,t){return Gt(n,e,A,t)},Yt=function(n){return n.fold(function(n){throw new Error(Jt(n))},h)},Kt=function(n,e,t){return Yt(Gt(n,e,h,t))},Xt=function(n,e,t){return Yt(qt(n,e,t))},Jt=function(n){return"Errors: \n"+(e=n.errors,t=10 ")+")\n"+n.getErrorInfo()}))+"\n\nInput object: "+At(n.input);var e,t},Qt=function(n,e){return Wt(n,e)},Zt=A(Ut),nr=(i=T,u="function",Nt(function(n){var e=typeof n;return i(n)?tt.value(n):tt.error("Expected type: "+u+" but got: "+e)})),er=function(n){return Pt(n,n,ut(),zt())},tr=function(n,e){return Pt(n,n,ut(),e)},rr=function(n){return tr(n,nr)},or=function(n,e){return Pt(n,n,ut(),jt(e))},ir=function(n){return Pt(n,n,ct(),zt())},ur=function(n,e){return Pt(n,n,ct(),jt(e))},cr=function(n,e){return Pt(n,n,ct(),_t(e))},ar=function(n,e){return Pt(n,n,it(e),zt())},fr=function(n,e,t){return Pt(n,n,it(e),t)},sr=function(n,e){return Lt(n,e)},lr=function(n){if(!kt(n,"can")&&!kt(n,"abort")&&!kt(n,"run"))throw new Error("EventHandler defined by: "+It(n,null,2)+" does not have can, abort, or run!");return Kt("Extracting event.handler",_t([ar("can",A(!0)),ar("abort",A(!1)),ar("run",I)]),n)},dr=function(t){var e,r,o,i,n=(e=t,r=function(n){return n.can},function(){for(var t=[],n=0;n"),innerHtml:n.innerHtml().getOr(""),defChildren:n.defChildren().fold(function(){return""},function(n){return It(n,null,2)}),domChildren:n.domChildren().fold(function(){return""},function(n){return 0===n.length?"0 children, but still specified":String(n.length)})}},Dr=Ae([],["classes","attributes","styles","value","innerHtml","defChildren","domChildren"]),Ir=function(e,n,t){return n.fold(function(){return t.fold(function(){return{}},function(n){return Tt(e,n)})},function(n){return t.fold(function(){return Tt(e,n)},function(n){return Tt(e,n)})})},Ar=function(t,r,o){return Tr(function(n,e){o(n,t,r)})},Mr=function(n,e,t,r,o,i){var u,c,a=n,f=ur(e,[(u="config",c=n,Pt(u,u,ct(),c))]);return Br(a,f,e,t,r,o,i)},Fr=function(o,i,u){var n,e,t,r,c,a;return n=function(t){for(var n=[],e=1;e"}),Zt()),ia=ar("defaults",A({})),ua=ar("overrides",A({})),ca=jt([ea,ta,ra,oa,ia,ua]),aa=jt([ea,ta,ra,oa,ia,ua]),fa=jt([ea,ta,ra,er("unit"),oa,ia,ua]),sa=function(n){var e=function(n){return n.name()};return n.fold(e,e,e,e)},la=function(t,r){return function(n){var e=Xt("Converting part type",r,n);return t(e)}},da=la(na.required,ca),ma=la(na.optional,aa),ga=la(na.group,fa),pa=A("entirety"),va=function(n,e,t,r){var o=t;return C(e.defaults()(n,t,r),t,{uid:n.partUids()[e.name()]},e.overrides()(n,t,r),{"debug.sketcher":Tt("part-"+e.name(),o)})},ha=function(o,n){var i={};return xn(n,function(n){var e;(e=n,e.fold(V.some,V.none,V.some,V.some)).each(function(t){var r=ya(o,t.pname());i[t.name()]=function(n){var e=Kt("Part: "+t.name()+" in "+o,jt(t.schema()),n);return C(r,{config:n,validated:e})}})}),i},ya=function(n,e){return{uiType:Jc(),owner:n,name:e}},ba=function(n,e,t){return r=e,i={},o={},xn(t,function(n){n.fold(function(r){i[r.pname()]=Kc(!0,function(n,e,t){return r.factory().sketch(va(n,r,e,t))})},function(n){var e=r.parts()[n.name()]();o[n.name()]=A(va(r,n,e[pa()]()))},function(r){i[r.pname()]=Kc(!1,function(n,e,t){return r.factory().sketch(va(n,r,e,t))})},function(o){i[o.pname()]=Xc(!0,function(e,n,t){var r=e[o.name()]();return wn(r,function(n){return o.factory().sketch(C(o.defaults()(e,n),n,o.overrides()(e,n)))})})})}),{internals:A(i),externals:A(o)};var r,i,o},wa=function(n,e,t){return Yc(V.some(n),e,e.components(),t)},xa=function(n,e,t){var r=e.partUids()[t];return n.getSystem().getByUid(r).toOption()},Ta=function(n,e,t){return xa(n,e,t).getOrDie("Could not find part: "+t)},Sa=function(e,n){var t=wn(n,sa);return St(wn(t,function(n){return{key:n,value:e+"-"+n}}))},Oa=function(e){return Pt("partUids","partUids",ft(function(n){return Sa(n.uid,e)}),Zt())},ka=Zc("alloy-premade"),Ca=Zc("api"),Ea=function(n){return Tt(ka,n)},Da=function(o){return n=function(n){for(var e=[],t=1;t'),action:e,buttonBehaviours:C(Pr([Wa.config({})]),t)})},Xa={forToolbar:Ka,forToolbarCommand:function(n,e){return Ka(e,function(){n.execCommand(e)},{})},forToolbarStateAction:function(n,e,t,r){var o=Ya(t);return Ka(e,r,o)},forToolbarStateCommand:function(n,e){var t=Ya(e);return Ka(e,function(){n.execCommand(e)},t)}},Ja=function(t,r){return{left:A(t),top:A(r),translate:function(n,e){return Ja(t+n,r+e)}}},Qa=Ja,Za=function(n,e,t){return Math.max(e,Math.min(t,n))},nf=function(n,e,t,r,o,i,u){var c=t-e;if(rn.right)return t+1;var a,f,s,l,d=Math.min(n.right,Math.max(r,n.left))-n.left,m=Za(d/n.width*c+e,e-1,t+1),g=Math.round(m);return i&&e<=m&&m<=t?(a=m,f=e,s=t,l=o,u.fold(function(){var n=a-f,e=Math.round(n/l)*l;return Za(f+e,f-1,s+1)},function(n){var e=(a-n)%l,t=Math.round(e/l),r=Math.floor((a-n)/l),o=Math.floor((s-n)/l),i=n+Math.min(o,r+t)*l;return Math.max(n,i)})):g},ef="slider.change.value",tf=Wn.detect().deviceType.isTouch(),rf=function(n){return function(n){var e=n.event().raw();if(tf){var t=e;return t.touches!==undefined&&1===t.touches.length?V.some(t.touches[0]).map(function(n){return Qa(n.clientX,n.clientY)}):V.none()}var r=e;return r.clientX!==undefined?V.some(r).map(function(n){return Qa(n.clientX,n.clientY)}):V.none()}(n).map(function(n){return n.left()})},of=function(n,e){ie(n,ef,{value:e})},uf=function(i,u,c,n){return rf(n).map(function(n){var e,t,r,o;return e=i,r=n,o=nf(c,(t=u).min(),t.max(),r,t.stepSize(),t.snapToGrid(),t.snapStart()),of(e,o),n})},cf=function(n,e){var t,r,o,i,u=(t=e.value().get(),r=e.min(),o=e.max(),i=e.stepSize(),tr.max()?xa(e,r,"right-edge").fold(function(){return t.width},function(n){return s(n)-t.left}):(r.value().get()-r.min())/f*t.width);return i.left-u.left+c},u=function(n){var e=i(n),t=o(n),r=If(t.element())/2;Si(t.element(),"left",e-r+"px")},r=function(n,e){var t=a.value().get(),r=o(n);return t!==e||Ei(r.element(),"left").isNone()?(a.value().set(e),u(n),a.onChange()(n,r,e),V.some(!0)):V.none()},c=Af?[pr(L(),function(n,e){a.onDragStart()(n,o(n))}),pr($(),function(n,e){a.onDragEnd()(n,o(n))})]:[pr(W(),function(n,e){e.stop(),a.onDragStart()(n,o(n)),a.mouseIsDown().set(!0)}),pr(G(),function(n,e){a.onDragEnd()(n,o(n)),a.mouseIsDown().set(!1)})];return{uid:a.uid(),dom:a.dom(),components:n,behaviours:C(Pr(In([Af?[]:[Lc.config({mode:"special",focusIn:function(n){return xa(n,a,"spectrum").map(Lc.focusIn).map(A(!0))}})],[Of.config({store:{mode:"manual",getValue:function(n){return a.value().get()}}})]])),$c(a.sliderBehaviours())),events:mr([pr(ef,function(n,e){r(n,e.event().value())}),wr(function(n,e){a.value().set(a.getInitialValue()());var t=o(n);u(n),a.onInit()(n,t,a.value().get())})].concat(c)),apis:{resetToMin:function(n){r(n,a.min())},resetToMax:function(n){r(n,a.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)}}}),Ff=function(e,t,r){return Xa.forToolbar(t,function(){var n=r();e.setContextToolbar([{label:t+" group",items:n}])},{})},Rf=function(n){return[(o=n,i=function(n){return n<0?"black":360'),components:[Mf.parts()["left-edge"](qa('
')),Mf.parts().spectrum({dom:Ga('
'),components:[qa('
')],behaviours:Pr([si.config({toggleClass:pi.resolve("thumb-active")})])}),Mf.parts()["right-edge"](qa('
')),Mf.parts().thumb({dom:Ga('
'),behaviours:Pr([si.config({toggleClass:pi.resolve("thumb-active")})])})],onChange:function(n,e,t){var r=i(t);Si(e.element(),"background-color",r),o.onChange(n,e,r)},onDragStart:function(n,e){si.on(e)},onDragEnd:function(n,e){si.off(e)},onInit:function(n,e,t){var r=i(t);Si(e.element(),"background-color",r)},stepSize:10,min:0,max:360,getInitialValue:o.getInitialValue,sliderBehaviours:Pr([di(Mf.refresh)])}))];var o,i},Bf=function(n,r){var e={onChange:function(n,e,t){r.undoManager.transact(function(){r.formatter.apply("forecolor",{value:t}),r.nodeChanged()})},getInitialValue:function(){return-1}};return Ff(n,"color",function(){return Rf(e)})},Vf=_t([er("getInitialValue"),er("onChange"),er("category"),er("sizes")]),Nf=function(n){var o=Kt("SizeSlider",Vf,n);return Mf.sketch({dom:{tag:"div",classes:[pi.resolve("slider-"+o.category+"-size-container"),pi.resolve("slider"),pi.resolve("slider-size-container")]},onChange:function(n,e,t){var r;0<=(r=t)&&r'),components:[qa('
')]}),Mf.parts().thumb({dom:Ga('
'),behaviours:Pr([si.config({toggleClass:pi.resolve("thumb-active")})])})]})},_f=["9px","10px","11px","12px","14px","16px","18px","20px","24px","32px","36px"],jf=function(n){var e,t,r=n.selection.getStart(),o=se.fromDom(r),i=se.fromDom(n.getBody()),u=(e=function(n){return _e(i,n)},(be(t=o)?V.some(t):ze(t).filter(be)).map(function(n){return vo(n,function(n){return Ei(n,"font-size").isSome()},e).bind(function(n){return Ei(n,"font-size")}).getOrThunk(function(){return ki(n,"font-size")})}).getOr(""));return kn(_f,function(n){return u===n}).getOr("medium")},Hf={candidates:A(_f),get:function(n){var e,t=jf(n);return(e=t,Cn(_f,function(n){return n===e})).getOr(2)},apply:function(r,n){var e;(e=n,V.from(_f[e])).each(function(n){var e,t;t=n,jf(e=r)!==t&&e.execCommand("fontSize",!1,t)})}},zf=Hf.candidates(),Lf=function(n){return[qa(''),(e=n,Nf({onChange:e.onChange,sizes:zf,category:"font",getInitialValue:e.getInitialValue})),qa('')];var e},Pf=function(n){var e=n.uid!==undefined&&kt(n,"uid")?n.uid:Va("memento");return{get:function(n){return n.getSystem().getByUid(e).getOrDie()},getOpt:function(n){return n.getSystem().getByUid(e).fold(V.none,V.some)},asSpec:function(){return C(n,{uid:e})}}},$f=window.Promise?window.Promise:function(){var i=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,r(o,this),r(c,this))},n=i.immediateFn||"function"==typeof window.setImmediate&&window.setImmediate||function(n){p.setTimeout(n,1)};function r(n,e){return function(){return n.apply(e,arguments)}}var t=Array.isArray||function(n){return"[object Array]"===Object.prototype.toString.call(n)};function u(r){var o=this;null!==this._state?n(function(){var n=o._state?r.onFulfilled:r.onRejected;if(null!==n){var e;try{e=n(o._value)}catch(t){return void r.reject(t)}r.resolve(e)}else(o._state?r.resolve:r.reject)(o._value)}):this._deferreds.push(r)}function o(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(r(e,n),r(o,this),r(c,this))}this._state=!0,this._value=n,a.call(this)}catch(t){c.call(this,t)}}function c(n){this._state=!1,this._value=n,a.call(this)}function a(){for(var n=0,e=this._deferreds;n'),components:[e.asSpec()],action:function(n){e.get(n).element().dom().click()}})},Zf=function(n){return n.dom().textContent},ns=function(n){return 0'),action:function(n){var e=t.get(n);Of.setValue(e,"")}}));return{name:n,spec:ds.sketch({dom:Ga('
'),components:[t.asSpec(),r.asSpec()],containerBehaviours:Pr([si.config({toggleClass:pi.resolve("input-container-empty")}),ls.config({find:function(n){return V.some(t.get(n))}}),as("input-clearing",[pr(K(),function(n){var e=t.get(n);(0"},js=function(o,n,e){return C({"debug.sketcher":{Form:e},uid:o.uid(),dom:o.dom(),components:n,behaviours:C(Pr([Of.config({store:{mode:"manual",getValue:function(n){var e,t,r=(e=o,t=n.getSystem(),j(e.partUids(),function(n,e){return A(t.getByUid(n))}));return j(r,function(n,e){return n().bind(ls.getCurrent).map(Of.getValue)})},setValue:function(t,n){_(n,function(e,n){xa(t,o,n).each(function(n){ls.getCurrent(n).each(function(n){Of.setValue(n,e)})})})}}})]),$c(o.formBehaviours())),apis:{getField:function(n,e){return xa(n,o,e).bind(ls.getCurrent)}}})},Hs=(Da(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",r=_s(n),o=e,{uiType:Jc(),owner:t,name:r,config:o,validated:{}};var t,r,o},record:function(){return i}}),t=n(e),r=e.record(),o=wn(r,function(n){return da({name:n,pname:_s(n)})});return _a("form",Ns,o,js,t)}),zs=function(){var e=mo(V.none()),t=function(){e.get().each(function(n){n.destroy()})};return{clear:function(){t(),e.set(V.none())},isSet:function(){return e.get().isSome()},set:function(n){t(),e.set(V.some(n))},run:function(n){e.get().each(n)}}},Ls=function(){var e=mo(V.none());return{clear:function(){e.set(V.none())},set:function(n){e.set(V.some(n))},isSet:function(){return e.get().isSome()},on:function(n){e.get().each(n)}}},Ps=function(n){return{xValue:n,points:[]}},$s=function(n,e){if(e===n.xValue)return n;var t=0'),action:function(n){ie(n,r,{direction:e})},buttonBehaviours:Pr([Vs.config({disableClass:pi.resolve("toolbar-navigation-disabled"),disabled:!t})])})},i=function(n,o){var i=_i(n.element(),"."+pi.resolve("serialised-dialog-screen"));zi(n.element(),"."+pi.resolve("serialised-dialog-chain")).each(function(r){0<=u.state.currentScreen.get()+o&&u.state.currentScreen.get()+o'),components:[ds.sketch({dom:Ga('
'),components:wn(u.fields,function(n,e){return e<=u.maxFieldIndex?ds.sketch({dom:Ga('
'),components:In([[o(-1,"previous",0'),behaviours:Pr([fu.config({highlightClass:pi.resolve("dot-active"),itemClass:pi.resolve("dot-item")})]),components:An(u.fields,function(n,e){return e<=u.maxFieldIndex?[qa('
')]:[]})});return{dom:Ga('
'),components:[a.asSpec(),f.asSpec()],behaviours:Pr([Lc.config({mode:"special",focusIn:function(n){var e=a.get(n);Lc.focusIn(e)}}),as("serializer-wrapper-events",[pr(L(),function(n,e){var t=e.event();u.state.dialogSwipeState.set(Ps(t.touches[0].clientX))}),pr(P(),function(n,e){var t=e.event();u.state.dialogSwipeState.on(function(n){e.event().prevent(),u.state.dialogSwipeState.set($s(n,t.raw().touches[0].clientX))})}),pr($(),function(r){u.state.dialogSwipeState.on(function(n){var e=a.get(r),t=-1*Ws(n);i(e,t)})})])])}},Gs=nn(function(t,r){return[{label:"the link group",items:[Us({fields:[Ts("url","Type or paste URL"),Ts("text","Link text"),Ts("title","Link title"),Ts("target","Link target"),(n="link",{name:n,spec:ms.sketch({dom:{tag:"span",styles:{display:"none"}},getInitialValue:function(){return V.none()}})})],maxFieldIndex:["url","text","title","target"].length-1,getInitialValue:function(){return V.some(os.getInfo(r))},onExecute:function(n){var e=Of.getValue(n);os.applyInfo(r,e),t.restoreToolbar(),r.focus()}})]}];var n}),qs=[{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"}]}],Ys=mr([(Uf=Gn(),Gf=function(n,e){var t,r,o=e.event().originator(),i=e.event().target();return r=i,!(_e(t=o,n.element())&&!_e(t,r)&&(p.console.warn(Gn()+" did not get interpreted by the desired target. \nOriginator: "+Ao(o)+"\nTarget: "+Ao(i)+"\nCheck the "+Gn()+" event handlers"),1))},{key:Uf,value:lr({can:Gf})})]),Ks=Object.freeze({events:Ys}),Xs=h,Js=Hr(["debugInfo","triggerFocus","triggerEvent","triggerEscape","addToWorld","removeFromWorld","addToGui","removeFromGui","build","getByUid","getByDom","broadcast","broadcastOn","isConnected"]),Qs=function(e){var n=function(n){return function(){throw new Error("The component must be in a context to send: "+n+"\n"+Ao(e().element())+" is not in context.")}};return Js({debugInfo:A("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"),isConnected:A(!1)})},Zs=function(n,o){var i={};return _(n,function(n,r){_(n,function(n,e){var t=wt(e,[])(i);i[e]=t.concat([o(r,n)])})}),i},nl=function(n,e){return 1 "):r[0].name();return Tt(o,{handler:e,purpose:A(t)})})});return Ot(e,{})},sl=function(n){return qt("custom.definition",_t([Pt("dom","dom",ut(),_t([er("tag"),ar("styles",{}),ar("classes",[]),ar("attributes",{}),ir("value"),ir("innerHtml")])),er("components"),er("uid"),ar("events",{}),ar("apis",A({})),Pt("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"]},ot.mergeWithThunk(A(e))),Zt()),ir("domModification"),Xo("originalSpec"),ar("debug.sketcher","unknown")]),n);var e},ll=function(n){var e,t={tag:n.dom().tag(),classes:n.dom().classes(),attributes:C((e=n,Tt(Ma(),e.uid())),n.dom().attributes()),styles:n.dom().styles(),domChildren:wn(n.components(),function(n){return n.element()})};return Cr(C(t,n.dom().innerHtml().map(function(n){return Tt("innerHtml",n)}).getOr({}),n.dom().value().map(function(n){return Tt("value",n)}).getOr({})))},dl=function(e,n){xn(n,function(n){oo(e,n)})},ml=function(e,n){xn(n,function(n){io(e,n)})},gl=function(e){if(e.domChildren().isSome()&&e.defChildren().isSome())throw new Error("Cannot specify children and child specs! Must be one or the other.\nDef: "+(n=Er(e),It(n,null,2)));return e.domChildren().fold(function(){var n=e.defChildren().getOr([]);return wn(n,vl)},function(n){return n});var n},pl=function(n){var e=se.fromTag(n.tag());Kr(e,n.attributes().getOr({})),dl(e,n.classes().getOr([])),Oi(e,n.styles().getOr({})),Eo(e,n.innerHtml().getOr(""));var t=gl(n);return Ue(e,t),n.value().each(function(n){ps(e,n)}),e},vl=function(n){var e=Cr(n);return pl(e)},hl=function(n,e){return t=n,o=wn(r=e,function(n){return ur(n.name(),[er("config"),ar("state",zr)])}),i=qt("component.behaviours",jt(o),t.behaviours).fold(function(n){throw new Error(Jt(n)+"\nComplete spec:\n"+It(t,null,2))},function(n){return n}),{list:r,data:j(i,function(n){var e=n().map(function(n){return{config:n.config(),state:n.state().init(n.config())}});return function(){return e}})};var t,r,o,i},yl=function(n){var e,t,r=(e=xt(n,"behaviours").getOr({}),t=Tn(N(e),function(n){return e[n]!==undefined}),wn(t,function(n){return e[n].me}));return hl(n,r)},bl=Hr(["getSystem","config","hasConfigured","spec","connect","disconnect","element","syncComponents","readState","components","events"]),wl=function(n,e,t){var r,o,i,u,c=ll(n),a=function(e,n,t,r){var o=C({},n);xn(t,function(n){o[n.name()]=n.exhibit(e,r)});var i=Zs(o,function(n,e){return{name:function(){return n},modification:e}}),u=j(i,function(n,e){return An(n,function(e){return e.modification().fold(function(){return[]},function(n){return[e]})})}),c=z(u,function(e,t){return xt(tl,t).fold(function(){return tt.error("Unknown field type: "+t)},function(n){return n(e,t)})});return Ot(c,{}).map(Dr)}(t,{"alloy.base.modification":(r=n,r.domModification().fold(function(){return Dr({})},Dr))},e,c).getOrDie();return i=a,u=C({tag:(o=c).tag(),classes:i.classes().getOr([]).concat(o.classes().getOr([])),attributes:E(o.attributes().getOr({}),i.attributes().getOr({})),styles:E(o.styles().getOr({}),i.styles().getOr({}))},i.innerHtml().or(o.innerHtml()).map(function(n){return Tt("innerHtml",n)}).getOr({}),Ir("domChildren",i.domChildren(),o.domChildren()),Ir("defChildren",i.defChildren(),o.defChildren()),i.value().or(o.value()).map(function(n){return Tt("value",n)}).getOr({})),Cr(u)},xl=function(n,e,t){var r,o,i,u,c,a,f={"alloy.base.behaviour":(r=n,r.events())};return(o=t,i=n.eventOrder(),u=e,c=f,a=ul(o,u,c),fl(a,i)).getOrDie()},Tl=function(n){var e,t,r,o,i,u,c,a,f,s,l,d,m,g,p=Xs(n),v=(e=p,t=wt("components",[])(e),wn(t,kl)),h=C(Ks,p,Tt("components",v));return tt.value((r=h,i=mo(Qs(o=function(){return g})),u=Yt(sl(C(r,{behaviours:undefined}))),c=yl(r),a=c.list,f=c.data,s=wl(u,a,f),l=pl(s),d=xl(u,a,f),m=mo(u.components()),g=bl({getSystem:i.get,config:function(n){if(n===Ia())return u.apis();if(y(n))throw new Error("Invalid input: only API constant is allowed");var e=f;return(T(e[n.name()])?e[n.name()]:function(){throw new Error("Could not find "+n.name()+" in "+It(r,null,2))})()},hasConfigured:function(n){return T(f[n.name()])},spec:A(r),readState:function(n){return f[n]().map(function(n){return n.state.readState()}).getOr("not enabled")},connect:function(n){i.set(n)},disconnect:function(){i.set(Qs(o))},element:A(l),syncComponents:function(){var n=Le(l),e=An(n,function(n){return i.get().getByDom(n).fold(function(){return[]},function(n){return[n]})});m.set(e)},components:m.get,events:A(d)})))},Sl=function(n){var e=se.fromText(n);return Ol({element:e})},Ol=function(n){var t=Xt("external.component",_t([er("element"),ir("uid")]),n),e=mo(Qs());t.uid().each(function(n){var e;e=t.element(),Yr(e,Ra,n)});var r=bl({getSystem:e.get,config:V.none,hasConfigured:A(!1),connect:function(n){e.set(n)},disconnect:function(){e.set(Qs(function(){return r}))},element:A(t.element()),spec:A(n),readState:A("No state"),syncComponents:I,components:A([]),events:A({})});return Ea(r)},kl=function(e){return(n=e,xt(n,ka)).fold(function(){var n=C({uid:Va("")},e);return Tl(n).getOrDie()},function(n){return n});var n},Cl=Ea,El="alloy.item-hover",Dl="alloy.item-focus",Il=function(n){(xo(n.element()).isNone()||wi.isFocused(n))&&(wi.isFocused(n)||wi.focus(n),ie(n,El,{item:n}))},Al=function(n){ie(n,Dl,{item:n})},Ml=A(El),Fl=A(Dl),Rl=[er("data"),er("components"),er("dom"),ir("toggling"),ar("itemBehaviours",{}),ar("ignoreFocus",!1),ar("domModification",{}),Ko("builder",function(n){return{dom:C(n.dom(),{attributes:{role:n.toggling().isSome()?"menuitemcheckbox":"menuitem"}}),behaviours:C(Pr([n.toggling().fold(si.revoke,function(n){return si.config(C({aria:{mode:"checked"}},n))}),wi.config({ignore:n.ignoreFocus(),onFocus:function(n){Al(n)}}),Lc.config({mode:"execution"}),Of.config({store:{mode:"memory",initialValue:n.data()}})]),n.itemBehaviours()),events:mr([(e=Qn(),r=ue,pr(e,function(e,t){var n=t.event();e.getSystem().getByDom(n.target()).each(function(n){r(e,n,t)})})),br(W()),pr(q(),Il),pr(Xn(),wi.focus)]),components:n.components(),domModification:n.domModification(),eventOrder:n.eventOrder()};var e,r}),ar("eventOrder",{})],Bl=[er("dom"),er("components"),Ko("builder",function(n){return{dom:n.dom(),components:n.components(),events:mr([(e=Xn(),pr(e,function(n,e){e.stop()}))])};var e})],Vl=A([da({name:"widget",overrides:function(e){return{behaviours:Pr([Of.config({store:{mode:"manual",getValue:function(n){return e.data()},setValue:function(){}}})])}}})]),Nl=[er("uid"),er("data"),er("components"),er("dom"),ar("autofocus",!1),ar("domModification",{}),Oa(Vl()),Ko("builder",function(t){var n=ba(0,t,Vl()),e=wa("item-widget",t,n.internals()),r=function(n){return xa(n,t,"widget").map(function(n){return Lc.focusIn(n),n})},o=function(n,e){return pu(e.event().target())||t.autofocus()&&e.setSource(n.element()),V.none()};return C({dom:t.dom(),components:e,domModification:t.domModification(),events:mr([Sr(function(n,e){r(n).each(function(n){e.stop()})}),pr(q(),Il),pr(Xn(),function(n,e){t.autofocus()?r(n):wi.focus(n)})]),behaviours:Pr([Of.config({store:{mode:"memory",initialValue:t.data()}}),wi.config({onFocus:function(n){Al(n)}}),Lc.config({mode:"special",focusIn:t.autofocus()?function(n){r(n)}:Gr(),onLeft:o,onRight:o,onEscape:function(n,e){return wi.isFocused(n)||t.autofocus()?(t.autofocus()&&e.setSource(n.element()),V.none()):(wi.focus(n),V.some(!0))}})])})})],_l=Qt("type",{widget:Nl,item:Rl,separator:Bl}),jl=A([ga({factory:{sketch:function(n){var e=Xt("menu.spec item",_l,n);return e.builder()(e)}},name:"items",unit:"item",defaults:function(n,e){var t=Va("");return C({uid:t},e)},overrides:function(n,e){return{type:e.type,ignoreFocus:n.fakeFocus(),domModification:{classes:[n.markers().item()]}}}})]),Hl=A([er("value"),er("items"),er("dom"),er("components"),ar("eventOrder",{}),Pc("menuBehaviours",[fu,Of,ls,Lc]),fr("movement",{mode:"menu",moveOnTab:!0},Qt("mode",{grid:[Jo(),Ko("config",function(n,e){return{mode:"flatgrid",selector:"."+n.markers().item(),initSize:{numColumns:e.initSize().numColumns(),numRows:e.initSize().numRows()},focusManager:n.focusManager()}})],menu:[ar("moveOnTab",!0),Ko("config",function(n,e){return{mode:"menu",selector:"."+n.markers().item(),moveOnTab:e.moveOnTab(),focusManager:n.focusManager()}})]})),tr("markers",Po()),ar("fakeFocus",!1),ar("focusManager",su()),Uo("onHighlight")]),zl=A("alloy.menu-focus"),Ll=Pa({name:"Menu",configFields:Hl(),partFields:jl(),factory:function(n,e,t,r){return C({dom:C(n.dom(),{attributes:{role:"menu"}}),uid:n.uid(),behaviours:C(Pr([fu.config({highlightClass:n.markers().selectedItem(),itemClass:n.markers().item(),onHighlight:n.onHighlight()}),Of.config({store:{mode:"memory",initialValue:n.value()}}),ls.config({find:V.some}),Lc.config(n.movement().config()(n,n.movement()))]),$c(n.menuBehaviours())),events:mr([pr(Fl(),function(e,t){var n=t.event();e.getSystem().getByDom(n.target()).each(function(n){fu.highlight(e,n),t.stop(),ie(e,zl(),{menu:e,item:n})})}),pr(Ml(),function(n,e){var t=e.event().item();fu.highlight(n,t)})]),components:e,eventOrder:n.eventOrder()})}}),Pl=function(n,e,t,r){var o=n.getSystem().build(r);Je(n,o,t)},$l=function(n,e){return n.components()},Wl=Wr({fields:[],name:"replacing",apis:Object.freeze({append:function(n,e,t,r){Pl(n,0,We,r)},prepend:function(n,e,t,r){Pl(n,0,$e,r)},remove:function(n,e,t,r){var o=$l(n);kn(o,function(n){return _e(r.element(),n.element())}).each(Ze)},set:function(e,n,t,r){var o,i,u,c,a,f;i=(o=e).components(),xn(i,Qe),Ge(o.element()),o.syncComponents(),u=function(){var n=wn(r,e.getSystem().build);xn(n,function(n){Xe(e,n)})},c=e.element(),a=je(c),f=wo(a).bind(function(e){var n=function(n){return _e(e,n)};return n(c)?V.some(c):ho(c,n)}),u(c),f.each(function(e){wo(a).filter(function(n){return _e(n,e)}).fold(function(){yo(e)},I)})},contents:$l})}),Ul=function(t,r,o,n){return xt(o,n).bind(function(n){return xt(t,n).bind(function(n){var e=Ul(t,r,o,n);return V.some([n].concat(e))})}).getOr([])},Gl=function(n,e){var t={};_(n,function(n,e){xn(n,function(n){t[n]=e})});var r=e,o=H(e,function(n,e){return{k:n,v:e}}),i=j(o,function(n,e){return[e].concat(Ul(t,r,o,e))});return j(t,function(n){return xt(i,n).getOr([n])})},ql=function(){var i=mo({}),u=mo({}),c=mo({}),a=mo(V.none()),f=mo({}),n=function(n){return xt(u.get(),n)};return{setContents:function(n,e,t,r){a.set(V.some(n)),i.set(t),u.set(e),f.set(r);var o=Gl(r,t);c.set(o)},expand:function(t){return xt(i.get(),t).map(function(n){var e=xt(c.get(),t).getOr([]);return[n].concat(e)})},refresh:function(n){return xt(c.get(),n)},collapse:function(n){return xt(c.get(),n).bind(function(n){return 1");r[t[0]]=Tt(t[1],n),r[t[1]]=Tt(t[0],n)}),r},createBistate:function(n,e,t){return St([{key:n,value:Tt(e,t)},{key:e,value:Tt(n,t)}])},createTristate:function(n,e,t,r){return St([{key:n,value:St([{key:e,value:r},{key:t,value:r}])},{key:e,value:St([{key:n,value:r},{key:t,value:r}])},{key:t,value:St([{key:n,value:r},{key:e,value:r}])}])}}}),id=pi.resolve("scrollable"),ud={register:function(n){oo(n,id)},deregister:function(n){io(n,id)},scrollable:A(id)},cd=function(n){return xt(n,"format").getOr(n.title)},ad=function(n,e,t,r,o){return{data:{value:n,text:e},type:"item",dom:{tag:"div",classes:o?[pi.resolve("styles-item-is-menu")]:[]},toggling:{toggleOnExecute:!1,toggleClass:pi.resolve("format-matches"),selected:t},itemBehaviours:Pr(o?[]:[li(n,function(n,e){(e?si.on:si.off)(n)})]),components:[{dom:{tag:"div",attributes:{style:r},innerHtml:e}}]}},fd=function(n,e,t,r){return{value:n,dom:{tag:"div"},components:[$a.sketch({dom:{tag:"div",classes:[pi.resolve("styles-collapser")]},components:r?[{dom:{tag:"span",classes:[pi.resolve("styles-collapse-icon")]}},Sl(n)]:[Sl(n)],action:function(n){if(r){var e=t().get(n);Kl.collapseMenu(e)}}}),{dom:{tag:"div",classes:[pi.resolve("styles-menu-items-container")]},components:[Ll.parts().items({})],behaviours:Pr([as("adhoc-scrollable-menu",[wr(function(n,e){Si(n.element(),"overflow-y","auto"),Si(n.element(),"-webkit-overflow-scrolling","touch"),ud.register(n.element())}),xr(function(n){Di(n.element(),"overflow-y"),Di(n.element(),"-webkit-overflow-scrolling"),ud.deregister(n.element())})])])}],items:e,menuBehaviours:Pr([od.config({initialState:"after",routes:od.createTristate("before","current","after",{transition:{property:"transform",transitionClass:"transitioning"}})})])}},sd=function(r){var o,i,n,e,t,u=(o=r.formats,i=function(){return c},n=fd("Styles",[].concat(wn(o.items,function(n){return ad(cd(n),n.title,n.isSelected(),n.getPreview(),kt(o.expansions,cd(n)))})),i,!1),e=j(o.menus,function(n,e){var t=wn(n,function(n){return ad(cd(n),n.title,n.isSelected!==undefined&&n.isSelected(),n.getPreview!==undefined?n.getPreview():"",kt(o.expansions,cd(n)))});return fd(e,t,i,!0)}),t=C(e,Tt("styles",n)),{tmenu:Kl.tieredData("styles",t,o.expansions)}),c=Pf(Kl.sketch({dom:{tag:"div",classes:[pi.resolve("styles-menu")]},components:[],fakeFocus:!0,stayInDom:!0,onExecute:function(n,e){var t=Of.getValue(e);return r.handle(e,t.value),V.none()},onEscape:function(){return V.none()},onOpenMenu:function(n,e){var t=If(n.element());Df(e.element(),t),od.jumpTo(e,"current")},onOpenSubmenu:function(n,e,t){var r=If(n.element()),o=Hi(e.element(),'[role="menu"]').getOrDie("hacky"),i=n.getSystem().getByDom(o).getOrDie();Df(t.element(),r),od.progressTo(i,"before"),od.jumpTo(t,"after"),od.progressTo(t,"current")},onCollapseMenu:function(n,e,t){var r=Hi(e.element(),'[role="menu"]').getOrDie("hacky"),o=n.getSystem().getByDom(r).getOrDie();od.progressTo(o,"after"),od.progressTo(t,"current")},navigateOnHover:!1,openImmediately:!0,data:u.tmenu,markers:{backgroundMenu:pi.resolve("styles-background-menu"),menu:pi.resolve("styles-menu"),selectedMenu:pi.resolve("styles-selected-menu"),item:pi.resolve("styles-item"),selectedItem:pi.resolve("styles-selected-item")}}));return c.asSpec()},ld=function(n){return kt(n,"items")?(t=C(yt(e=n,["items"]),{menu:!0}),r=dd(e.items),{item:t,menus:C(r.menus,Tt(e.title,r.items)),expansions:C(r.expansions,Tt(e.title,e.title))}):{item:n,menus:{},expansions:{}};var e,t,r},dd=function(n){return Sn(n,function(n,e){var t=ld(e);return{menus:C(n.menus,t.menus),items:[t.item].concat(n.items),expansions:C(n.expansions,t.expansions)}},{menus:{},expansions:{},items:[]})},md={expand:dd},gd=function(u,n){var c=function(n){return function(){return u.formatter.match(n)}},a=function(n){return function(){return u.formatter.getCssText(n)}},e=xt(n,"style_formats").getOr(qs),f=function(n){return wn(n,function(n){if(kt(n,"items")){var e=f(n.items);return C(C(n,{isSelected:A(!1),getPreview:A("")}),{items:e})}return kt(n,"format")?C(i=n,{isSelected:c(i.format),getPreview:a(i.format)}):(r=Zc((t=n).title),o=C(t,{format:r,isSelected:c(r),getPreview:a(r)}),u.formatter.register(r,o),o);var t,r,o,i})};return f(e)},pd=function(t,n,r){var e,o,i,u=(e=t,i=(o=function(n){return An(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===Vd?[]:[Cd(se.fromDom(r.win()),"blur",function(){t.getByDom(e).each(si.off)}),Cd(i,"select",n),Cd(r.doc(),"selectionchange",n)]);return{destroy:function(){xn(c,function(n){n.unbind()})}}},_d=function(n,e){var t=parseInt(Xr(n,e),10);return isNaN(t)?0:t},jd=(qf=we,Yf="text",{get:function(n){if(!qf(n))throw new Error("Can only get "+Yf+" value of a "+Yf+" node");return Kf(n).getOr("")},getOption:Kf=function(n){return qf(n)?V.from(n.dom().nodeValue):V.none()},set:function(n,e){if(!qf(n))throw new Error("Can only set raw "+Yf+" value of a "+Yf+" node");n.dom().nodeValue=e}}),Hd=function(n){return jd.getOption(n)},zd={create:Oe("start","soffset","finish","foffset")},Ld=rt([{before:["element"]},{on:["element","offset"]},{after:["element"]}]),Pd={before:Ld.before,on:Ld.on,after:Ld.after,cata:function(n,e,t,r){return n.fold(e,t,r)},getStart:function(n){return n.fold(h,h,h)}},$d=rt([{domRange:["rng"]},{relative:["startSitu","finishSitu"]},{exact:["start","soffset","finish","foffset"]}]),Wd={domRange:$d.domRange,relative:$d.relative,exact:$d.exact,exactFromRange:function(n){return $d.exact(n.start(),n.soffset(),n.finish(),n.foffset())},getWin:function(n){var e=n.match({domRange:function(n){return se.fromDom(n.startContainer)},relative:function(n,e){return Pd.getStart(n)},exact:function(n,e,t,r){return n}});return He(e)},range:zd.create},Ud=function(n,e,t){var r,o,i=n.document.createRange();return r=i,e.fold(function(n){r.setStartBefore(n.dom())},function(n,e){r.setStart(n.dom(),e)},function(n){r.setStartAfter(n.dom())}),o=i,t.fold(function(n){o.setEndBefore(n.dom())},function(n,e){o.setEnd(n.dom(),e)},function(n){o.setEndAfter(n.dom())}),i},Gd=function(n,e,t,r,o){var i=n.document.createRange();return i.setStart(e.dom(),t),i.setEnd(r.dom(),o),i},qd=function(n){return{left:A(n.left),top:A(n.top),right:A(n.right),bottom:A(n.bottom),width:A(n.width),height:A(n.height)}},Yd=rt([{ltr:["start","soffset","finish","foffset"]},{rtl:["start","soffset","finish","foffset"]}]),Kd=function(n,e,t){return e(se.fromDom(t.startContainer),t.startOffset,se.fromDom(t.endContainer),t.endOffset)},Xd=function(n,e){var o,t,r,i=(o=n,e.match({domRange:function(n){return{ltr:A(n),rtl:V.none}},relative:function(n,e){return{ltr:nn(function(){return Ud(o,n,e)}),rtl:nn(function(){return V.some(Ud(o,e,n))})}},exact:function(n,e,t,r){return{ltr:nn(function(){return Gd(o,n,e,t,r)}),rtl:nn(function(){return V.some(Gd(o,t,r,n,e))})}}}));return(r=(t=i).ltr()).collapsed?t.rtl().filter(function(n){return!1===n.collapsed}).map(function(n){return Yd.rtl(se.fromDom(n.endContainer),n.endOffset,se.fromDom(n.startContainer),n.startOffset)}).getOrThunk(function(){return Kd(0,Yd.ltr,r)}):Kd(0,Yd.ltr,r)},Jd=(document.caretPositionFromPoint||document.caretRangeFromPoint,function(n,e){var t=he(n);return"input"===t?Pd.after(n):bn(["br","img"],t)?0===e?Pd.before(n):Pd.after(n):Pd.on(n,e)}),Qd=function(n,e,t,r){var o,i,u,c,a,f=(i=e,u=t,c=r,(a=je(o=n).dom().createRange()).setStart(o.dom(),i),a.setEnd(u.dom(),c),a),s=_e(n,t)&&e===r;return f.collapsed&&!s},Zd=function(n,e,t,r,o){var i,u,c=Gd(n,e,t,r,o);i=n,u=c,V.from(i.getSelection()).each(function(n){n.removeAllRanges(),n.addRange(u)})},nm=function(n,e,t,r,o){var i,u,c,a,l,f=(i=r,u=o,c=Jd(e,t),a=Jd(i,u),Wd.relative(c,a));Xd(l=n,f).match({ltr:function(n,e,t,r){Zd(l,n,e,t,r)},rtl:function(n,e,t,r){var o,i,u,c,a,f=l.getSelection();if(f.setBaseAndExtent)f.setBaseAndExtent(n.dom(),e,t.dom(),r);else if(f.extend)try{i=n,u=e,c=t,a=r,(o=f).collapse(i.dom(),u),o.extend(c.dom(),a)}catch(s){Zd(l,t,r,n,e)}else Zd(l,t,r,n,e)}})},em=function(n){var e=se.fromDom(n.anchorNode),t=se.fromDom(n.focusNode);return Qd(e,n.anchorOffset,t,n.focusOffset)?V.some(zd.create(e,n.anchorOffset,t,n.focusOffset)):function(n){if(0e.innerHeight||t.bottom()>e.innerHeight?Math.min(r,t.bottom()-e.innerHeight+50):0);0!==o&&u.scrollTo(u.pageXOffset,u.pageYOffset+o)})}),sm(e,n.innerHeight)});return sm(e,n.innerHeight),{toEditing:function(){am(u)},destroy:function(){t.unbind()}}},gm=function(n){return V.some(se.fromDom(n.dom().contentWindow.document.body))},pm=function(n){return V.some(se.fromDom(n.dom().contentWindow.document))},vm=function(n){return V.from(n.dom().contentWindow)},hm=function(n){return vm(n).bind(tm)},ym=function(n){return n.getFrame()},bm=function(n,t){return function(e){return e[n].getOrThunk(function(){var n=ym(e);return function(){return t(n)}})()}},wm=function(n,e,t,r){return n[t].getOrThunk(function(){return function(n){return Cd(e,r,n)}})},xm=function(n){return{left:A(n.left),top:A(n.top),right:A(n.right),bottom:A(n.bottom),width:A(n.width),height:A(n.height)}},Tm={getBody:bm("getBody",gm),getDoc:bm("getDoc",pm),getWin:bm("getWin",vm),getSelection:bm("getSelection",hm),getFrame:ym,getActiveApi:function(c){var a=ym(c);return gm(a).bind(function(u){return pm(a).bind(function(i){return vm(a).map(function(o){var n=se.fromDom(i.dom().documentElement),e=c.getCursorBox.getOrThunk(function(){return function(){return(n=o,tm(n).map(function(n){return Wd.exact(n.start(),n.soffset(),n.finish(),n.foffset())})).bind(function(n){return rm(o,n).orThunk(function(){return tm(o).filter(function(n){return _e(n.start(),n.finish())&&n.soffset()===n.foffset()}).bind(function(n){var e=n.start().dom().getBoundingClientRect();return 0