agenda-libre-ruby/public/assets/tinymce/themes/mobile/theme-d8ea7128fdf215593ad6e1fd511fc1ac196324084fb31c74eb4d0078b9935514.js
2018-02-19 14:21:53 +01:00

2 lines
181 KiB
JavaScript

!function(){"use strict";var n,e,t,r,o,i,u,a=function(n){return function(){return n}},c={noop:function(){},noarg:function(n){return function(){return n()}},compose:function(n,e){return function(){return n(e.apply(null,arguments))}},constant:a,identity:function(n){return n},tripleEquals:function(n,e){return n===e},curry:function(n){for(var e=new Array(arguments.length-1),t=1;t<arguments.length;t++)e[t-1]=arguments[t];return function(){for(var t=new Array(arguments.length),r=0;r<t.length;r++)t[r]=arguments[r];var o=e.concat(t);return n.apply(null,o)}},not:function(n){return function(){return!n.apply(null,arguments)}},die:function(n){return function(){throw new Error(n)}},apply:function(n){return n()},call:function(n){n()},never:a(!1),always:a(!0)},s=c.never,f=c.always,l=function(){return d},d=(r={fold:function(n,e){return n()},is:s,isSome:s,isNone:f,getOr:t=function(n){return n},getOrThunk:e=function(n){return n()},getOrDie:function(n){throw new Error(n||"error: getOrDie called on none.")},or:t,orThunk:e,map:l,ap:l,each:function(){},bind:l,flatten:l,exists:s,forall:f,filter:l,equals:n=function(n){return n.isNone()},equals_:n,toArray:function(){return[]},toString:c.constant("none()")},Object.freeze&&Object.freeze(r),r),m=function(n){var e=function(){return n},t=function(){return o},r=function(e){return e(n)},o={fold:function(e,t){return t(n)},is:function(e){return n===e},isSome:f,isNone:s,getOr:e,getOrThunk:e,getOrDie:e,or:t,orThunk:t,map:function(e){return m(e(n))},ap:function(e){return e.fold(l,function(e){return m(e(n))})},each:function(e){e(n)},bind:r,flatten:e,exists:r,forall:r,filter:function(e){return e(n)?o:d},equals:function(e){return e.is(n)},equals_:function(e,t){return e.fold(s,function(e){return t(n,e)})},toArray:function(){return[n]},toString:function(){return"some("+n+")"}};return o},p={some:m,none:l,from:function(n){return null===n||n===undefined?d:m(n)}},g=(o=Array.prototype.indexOf)===undefined?function(n,e){return x(n,e)}:function(n,e){return o.call(n,e)},h=function(n,e){return g(n,e)>-1},v=function(n,e){for(var t=n.length,r=new Array(t),o=0;o<t;o++){var i=n[o];r[o]=e(i,o,n)}return r},y=function(n,e){for(var t=0,r=n.length;t<r;t++)e(n[t],t,n)},b=function(n,e){for(var t=n.length-1;t>=0;t--)e(n[t],t,n)},w=function(n,e){for(var t=[],r=0,o=n.length;r<o;r++){var i=n[r];e(i,r,n)&&t.push(i)}return t},S=function(n,e){for(var t=0,r=n.length;t<r;t++)if(e(n[t],t,n))return p.some(t);return p.none()},x=function(n,e){for(var t=0,r=n.length;t<r;++t)if(n[t]===e)return t;return-1},O=Array.prototype.push,T=function(n){for(var e=[],t=0,r=n.length;t<r;++t){if(!Array.prototype.isPrototypeOf(n[t]))throw new Error("Arr.flatten item "+t+" was not an array, input: "+n);O.apply(e,n[t])}return e},k=function(n,e){for(var t=0,r=n.length;t<r;++t)if(!0!==e(n[t],t,n))return!1;return!0},C=Array.prototype.slice,E={map:v,each:y,eachr:b,partition:function(n,e){for(var t=[],r=[],o=0,i=n.length;o<i;o++){var u=n[o];(e(u,o,n)?t:r).push(u)}return{pass:t,fail:r}},filter:w,groupBy:function(n,e){if(0===n.length)return[];for(var t=e(n[0]),r=[],o=[],i=0,u=n.length;i<u;i++){var a=n[i],c=e(a);c!==t&&(r.push(o),o=[]),t=c,o.push(a)}return 0!==o.length&&r.push(o),r},indexOf:function(n,e){var t=g(n,e);return-1===t?p.none():p.some(t)},foldr:function(n,e,t){return b(n,function(n){t=e(t,n)}),t},foldl:function(n,e,t){return y(n,function(n){t=e(t,n)}),t},find:function(n,e){for(var t=0,r=n.length;t<r;t++){var o=n[t];if(e(o,t,n))return p.some(o)}return p.none()},findIndex:S,flatten:T,bind:function(n,e){var t=v(n,e);return T(t)},forall:k,exists:function(n,e){return S(n,e).isSome()},contains:h,equal:function(n,e){return n.length===e.length&&k(n,function(n,t){return n===e[t]})},reverse:function(n){var e=C.call(n,0);return e.reverse(),e},chunk:function(n,e){for(var t=[],r=0;r<n.length;r+=e){var o=n.slice(r,r+e);t.push(o)}return t},difference:function(n,e){return w(n,function(n){return!h(e,n)})},mapToObject:function(n,e){for(var t={},r=0,o=n.length;r<o;r++){var i=n[r];t[String(i)]=e(i,r)}return t},pure:function(n){return[n]},sort:function(n,e){var t=C.call(n,0);return t.sort(e),t},range:function(n,e){for(var t=[],r=0;r<n;r++)t.push(e(r));return t},head:function(n){return 0===n.length?p.none():p.some(n[0])},last:function(n){return 0===n.length?p.none():p.some(n[n.length-1])}},D="undefined"!=typeof window?window:Function("return this;")(),A=function(n,e){for(var t=e!==undefined&&null!==e?e:D,r=0;r<n.length&&t!==undefined&&null!==t;++r)t=t[n[r]];return t},M=function(n,e){var t=n.split(".");return A(t,e)},R={getOrDie:function(n,e){var t=M(n,e);if(t===undefined||null===t)throw n+" not available on this browser";return t}},F=function(n){var e,t=!1;return function(){return t||(t=!0,e=n.apply(null,arguments)),e}},B=function(n,e){var t=function(n,e){for(var t=0;t<n.length;t++){var r=n[t];if(r.test(e))return r}return undefined}(n,e);if(!t)return{major:0,minor:0};var r=function(n){return Number(e.replace(t,"$"+n))};return H(r(1),r(2))},I=function(){return H(0,0)},H=function(n,e){return{major:n,minor:e}},N={nu:H,detect:function(n,e){var t=String(e).toLowerCase();return 0===n.length?I():B(n,t)},unknown:I},V="Firefox",j=function(n,e){return function(){return e===n}},P=function(n){var e=n.current;return{current:e,version:n.version,isEdge:j("Edge",e),isChrome:j("Chrome",e),isIE:j("IE",e),isOpera:j("Opera",e),isFirefox:j(V,e),isSafari:j("Safari",e)}},L={unknown:function(){return P({current:undefined,version:N.unknown()})},nu:P,edge:c.constant("Edge"),chrome:c.constant("Chrome"),ie:c.constant("IE"),opera:c.constant("Opera"),firefox:c.constant(V),safari:c.constant("Safari")},W="Windows",U="Android",z="Solaris",K="FreeBSD",G=function(n,e){return function(){return e===n}},$=function(n){var e=n.current;return{current:e,version:n.version,isWindows:G(W,e),isiOS:G("iOS",e),isAndroid:G(U,e),isOSX:G("OSX",e),isLinux:G("Linux",e),isSolaris:G(z,e),isFreeBSD:G(K,e)}},q={unknown:function(){return $({current:undefined,version:N.unknown()})},nu:$,windows:c.constant(W),ios:c.constant("iOS"),android:c.constant(U),linux:c.constant("Linux"),osx:c.constant("OSX"),solaris:c.constant(z),freebsd:c.constant(K)},_=function(n,e){var t=String(e).toLowerCase();return E.find(n,function(n){return n.search(t)})},X=function(n,e){return _(n,e).map(function(n){var t=N.detect(n.versionRegexes,e);return{current:n.name,version:t}})},Y=function(n,e){return _(n,e).map(function(n){var t=N.detect(n.versionRegexes,e);return{current:n.name,version:t}})},J=function(n,e){return n.replace(/\${([^{}]*)}/g,function(n,t){var r,o=e[t];return"string"==(r=typeof o)||"number"===r?o:n})},Q=function(n,e){return-1!==n.indexOf(e)},Z=function(n){return n.replace(/^\s+|\s+$/g,"")},nn=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,en=function(n){return function(e){return Q(e,n)}},tn=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:function(n){return Q(n,"edge/")&&Q(n,"chrome")&&Q(n,"safari")&&Q(n,"applewebkit")}},{name:"Chrome",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,nn],search:function(n){return Q(n,"chrome")&&!Q(n,"chromeframe")}},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:function(n){return Q(n,"msie")||Q(n,"trident")}},{name:"Opera",versionRegexes:[nn,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:en("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:en("firefox")},{name:"Safari",versionRegexes:[nn,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:function(n){return(Q(n,"safari")||Q(n,"mobile/"))&&Q(n,"applewebkit")}}],rn=[{name:"Windows",search:en("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:function(n){return Q(n,"iphone")||Q(n,"ipad")},versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:en("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"OSX",search:en("os x"),versionRegexes:[/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:en("linux"),versionRegexes:[]},{name:"Solaris",search:en("sunos"),versionRegexes:[]},{name:"FreeBSD",search:en("freebsd"),versionRegexes:[]}],on={browsers:c.constant(tn),oses:c.constant(rn)},un=function(n){var e,t,r,o,i,u,a,s,f,l,d,m=on.browsers(),p=on.oses(),g=X(m,n).fold(L.unknown,L.nu),h=Y(p,n).fold(q.unknown,q.nu);return{browser:g,os:h,deviceType:(t=g,r=n,o=(e=h).isiOS()&&!0===/ipad/i.test(r),i=e.isiOS()&&!o,u=e.isAndroid()&&3===e.version.major,a=e.isAndroid()&&4===e.version.major,s=o||u||a&&!0===/mobile/i.test(r),f=e.isiOS()||e.isAndroid(),l=f&&!s,d=t.isSafari()&&e.isiOS()&&!1===/safari/i.test(r),{isiPad:c.constant(o),isiPhone:c.constant(i),isTablet:c.constant(s),isPhone:c.constant(l),isTouch:c.constant(f),isAndroid:e.isAndroid,isiOS:e.isiOS,isWebView:c.constant(d)})}},an={detect:F(function(){var n=navigator.userAgent;return un(n)})},cn=function(n){if(null===n||n===undefined)throw new Error("Node cannot be null or undefined");return{dom:c.constant(n)}},sn={fromHtml:function(n,e){var t=(e||document).createElement("div");if(t.innerHTML=n,!t.hasChildNodes()||t.childNodes.length>1)throw console.error("HTML does not have a single root node",n),"HTML must have a single root node";return cn(t.childNodes[0])},fromTag:function(n,e){var t=(e||document).createElement(n);return cn(t)},fromText:function(n,e){var t=(e||document).createTextNode(n);return cn(t)},fromDom:cn,fromPoint:function(n,e,t){return p.from(n.dom().elementFromPoint(e,t)).map(cn)}},fn=8,ln=9,dn=1,mn=3,pn=dn,gn=ln,hn=function(n){return n.nodeType!==pn&&n.nodeType!==gn||0===n.childElementCount},vn={all:function(n,e){var t=e===undefined?document:e.dom();return hn(t)?[]:E.map(t.querySelectorAll(n),sn.fromDom)},is:function(n,e){var t=n.dom();if(t.nodeType!==pn)return!1;if(t.matches!==undefined)return t.matches(e);if(t.msMatchesSelector!==undefined)return t.msMatchesSelector(e);if(t.webkitMatchesSelector!==undefined)return t.webkitMatchesSelector(e);if(t.mozMatchesSelector!==undefined)return t.mozMatchesSelector(e);throw new Error("Browser lacks native selectors")},one:function(n,e){var t=e===undefined?document:e.dom();return hn(t)?p.none():p.from(t.querySelector(n)).map(sn.fromDom)}},yn=function(n,e){return n.dom()===e.dom()},bn=(an.detect().browser.isIE(),yn),wn=function(n,e){return bn(n.element(),e.event().target())},Sn={contextmenu:c.constant("contextmenu"),touchstart:c.constant("touchstart"),touchmove:c.constant("touchmove"),touchend:c.constant("touchend"),gesturestart:c.constant("gesturestart"),mousedown:c.constant("mousedown"),mousemove:c.constant("mousemove"),mouseout:c.constant("mouseout"),mouseup:c.constant("mouseup"),mouseover:c.constant("mouseover"),focusin:c.constant("focusin"),keydown:c.constant("keydown"),input:c.constant("input"),change:c.constant("change"),focus:c.constant("focus"),click:c.constant("click"),transitionend:c.constant("transitionend"),selectstart:c.constant("selectstart")},xn={tap:c.constant("alloy.tap")},On={focus:c.constant("alloy.focus"),postBlur:c.constant("alloy.blur.post"),receive:c.constant("alloy.receive"),execute:c.constant("alloy.execute"),focusItem:c.constant("alloy.focus.item"),tap:xn.tap,tapOrClick:an.detect().deviceType.isTouch()?xn.tap:Sn.click,longpress:c.constant("alloy.longpress"),sandboxClose:c.constant("alloy.sandbox.close"),systemInit:c.constant("alloy.system.init"),windowScroll:c.constant("alloy.system.scroll"),attachedToDom:c.constant("alloy.system.attached"),detachedFromDom:c.constant("alloy.system.detached"),changeTab:c.constant("alloy.change.tab"),dismissTab:c.constant("alloy.dismiss.tab")},Tn=function(n){return function(e){return function(n){if(null===n)return"null";var e=typeof n;return"object"===e&&Array.prototype.isPrototypeOf(n)?"array":"object"===e&&String.prototype.isPrototypeOf(n)?"string":e}(e)===n}},kn={isString:Tn("string"),isObject:Tn("object"),isArray:Tn("array"),isNull:Tn("null"),isBoolean:Tn("boolean"),isUndefined:Tn("undefined"),isFunction:Tn("function"),isNumber:Tn("number")},Cn=function(n){return function(){for(var e=new Array(arguments.length),t=0;t<e.length;t++)e[t]=arguments[t];if(0===e.length)throw new Error("Can't merge zero objects");for(var r={},o=0;o<e.length;o++){var i=e[o];for(var u in i)i.hasOwnProperty(u)&&(r[u]=n(r[u],i[u]))}return r}},En=Cn(function(n,e){return kn.isObject(n)&&kn.isObject(e)?En(n,e):e}),Dn=Cn(function(n,e){return e}),An={deepMerge:En,merge:Dn},Mn=(i=Object.keys)===undefined?function(n){var e=[];for(var t in n)n.hasOwnProperty(t)&&e.push(t);return e}:i,Rn=function(n,e){for(var t=Mn(n),r=0,o=t.length;r<o;r++){var i=t[r];e(n[i],i,n)}},Fn=function(n,e){var t={};return Rn(n,function(r,o){var i=e(r,o,n);t[i.k]=i.v}),t},Bn=function(n,e){var t=[];return Rn(n,function(n,r){t.push(e(n,r))}),t},In=function(n){return Bn(n,function(n){return n})},Hn={bifilter:function(n,e){var t={},r={};return Rn(n,function(n,o){(e(n,o)?t:r)[o]=n}),{t:t,f:r}},each:Rn,map:function(n,e){return Fn(n,function(n,t,r){return{k:t,v:e(n,t,r)}})},mapToArray:Bn,tupleMap:Fn,find:function(n,e){for(var t=Mn(n),r=0,o=t.length;r<o;r++){var i=t[r],u=n[i];if(e(u,i,n))return p.some(u)}return p.none()},keys:Mn,values:In,size:function(n){return In(n).length}},Nn=function(n,e){Vn(n,n.element(),e,{})},Vn=function(n,e,t,r){var o=An.deepMerge({target:e},r);n.getSystem().triggerEvent(t,e,Hn.map(o,c.constant))},jn=Nn,Pn=function(n,e,t){Vn(n,n.element(),e,t)},Ln=function(n){Nn(n,On.execute())},Wn=function(n,e,t){Vn(n,e,t,{})},Un=function(n,e,t,r){n.getSystem().triggerEvent(t,e,r.event())},zn=function(n,e){n.getSystem().triggerFocus(e,n.element())},Kn=function(n){if(!kn.isArray(n))throw new Error("cases must be an array");if(0===n.length)throw new Error("there must be at least one case");var e=[],t={};return E.each(n,function(r,o){var i=Hn.keys(r);if(1!==i.length)throw new Error("one and only one name per case");var u=i[0],a=r[u];if(t[u]!==undefined)throw new Error("duplicate key detected:"+u);if("cata"===u)throw new Error("cannot have a case named cata (sorry)");if(!kn.isArray(a))throw new Error("case arguments must be an array");e.push(u),t[u]=function(){var t=arguments.length;if(t!==a.length)throw new Error("Wrong number of arguments to case "+u+". Expected "+a.length+" ("+a+"), got "+t);for(var r=new Array(t),i=0;i<r.length;i++)r[i]=arguments[i];return{fold:function(){if(arguments.length!==n.length)throw new Error("Wrong number of arguments to fold. Expected "+n.length+", got "+arguments.length);return arguments[o].apply(null,r)},match:function(n){var t=Hn.keys(n);if(e.length!==t.length)throw new Error("Wrong number of arguments to match. Expected: "+e.join(",")+"\nActual: "+t.join(","));if(!E.forall(e,function(n){return E.contains(t,n)}))throw new Error("Not all branches were specified when using match. Specified: "+t.join(", ")+"\nRequired: "+e.join(", "));return n[u].apply(null,r)},log:function(n){console.log(n,{constructors:e,constructor:u,params:r})}}}}),t},Gn=Kn([{strict:[]},{defaultedThunk:["fallbackThunk"]},{asOption:[]},{asDefaultedOptionThunk:["fallbackThunk"]},{mergeWithThunk:["baseThunk"]}]),$n={strict:Gn.strict,asOption:Gn.asOption,defaulted:function(n){return Gn.defaultedThunk(c.constant(n))},defaultedThunk:Gn.defaultedThunk,asDefaultedOption:function(n){return Gn.asDefaultedOptionThunk(c.constant(n))},asDefaultedOptionThunk:Gn.asDefaultedOptionThunk,mergeWith:function(n){return Gn.mergeWithThunk(c.constant(n))},mergeWithThunk:Gn.mergeWithThunk},qn=function(n){return{is:function(e){return n===e},isValue:c.constant(!0),isError:c.constant(!1),getOr:c.constant(n),getOrThunk:c.constant(n),getOrDie:c.constant(n),or:function(e){return qn(n)},orThunk:function(e){return qn(n)},fold:function(e,t){return t(n)},map:function(e){return qn(e(n))},each:function(e){e(n)},bind:function(e){return e(n)},exists:function(e){return e(n)},forall:function(e){return e(n)},toOption:function(){return p.some(n)}}},_n=function(n){return{is:c.constant(!1),isValue:c.constant(!1),isError:c.constant(!0),getOr:c.identity,getOrThunk:function(n){return n()},getOrDie:function(){return c.die(n)()},or:function(n){return n},orThunk:function(n){return n()},fold:function(e,t){return e(n)},map:function(e){return _n(n)},each:c.noop,bind:function(e){return _n(n)},exists:c.constant(!1),forall:c.constant(!0),toOption:p.none}},Xn={value:qn,error:_n},Yn=(Kn([{bothErrors:["error1","error2"]},{firstError:["error1","value2"]},{secondError:["value1","error2"]},{bothValues:["value1","value2"]}]),function(n){var e=[],t=[];return E.each(n,function(n){n.fold(function(n){e.push(n)},function(n){t.push(n)})}),{errors:e,values:t}}),Jn=function(n){return c.compose(Xn.error,E.flatten)(n)},Qn=function(n,e){var t,r,o=Yn(n);return o.errors.length>0?Jn(o.errors):(t=o.values,r=e,Xn.value(An.deepMerge.apply(undefined,[r].concat(t))))},Zn=function(n){var e=Yn(n);return e.errors.length>0?Jn(e.errors):Xn.value(e.values)},ne=function(n,e){var t={};return E.each(e,function(e){n[e]!==undefined&&n.hasOwnProperty(e)&&(t[e]=n[e])}),t},ee=function(n,e){var t={};return Hn.each(n,function(n,r){E.contains(e,r)||(t[r]=n)}),t},te=function(n,e){var t={};return E.each(n,function(n){var r=n[e];t[r]=n}),t},re=function(n){return function(e){return e.hasOwnProperty(n)?p.from(e[n]):p.none()}},oe=re,ie=function(n,e){return function(t){return re(n)(t).getOr(e)}},ue=function(n,e){return re(e)(n)},ae=function(n,e){return n.hasOwnProperty(e)&&n[e]!==undefined&&null!==n[e]},ce=function(n,e){var t={};return t[n]=e,t},se=function(n){var e={};return E.each(n,function(n){e[n.key]=n.value}),e},fe={narrow:function(n,e){return ne(n,e)},exclude:function(n,e){return ee(n,e)},readOpt:function(n){return oe(n)},readOr:function(n,e){return ie(n,e)},readOptFrom:function(n,e){return ue(n,e)},wrap:function(n,e){return ce(n,e)},wrapAll:function(n){return se(n)},indexOnKey:function(n,e){return te(n,e)},hasKey:function(n,e){return ae(n,e)},consolidate:function(n,e){return Qn(n,e)}},le=function(){return R.getOrDie("JSON")},de=function(n,e,t){return le().stringify(n,e,t)},me=function(n){return kn.isObject(n)&&Hn.keys(n).length>100?" removed due to size":de(n,null,2)},pe=function(n){var e=n.length>10?n.slice(0,10).concat([{path:[],getErrorInfo:function(){return"... (only showing first ten failures)"}}]):n;return E.map(e,function(n){return"Failed path: ("+n.path.join(" > ")+")\n"+n.getErrorInfo()})},ge=function(n,e){return Xn.error([{path:n,getErrorInfo:e}])},he=function(n,e,t){return ge(n,function(){return'Could not find valid *strict* value for "'+e+'" in '+me(t)})},ve=function(n,e){return ge(n,function(){return'Choice schema did not contain choice key: "'+e+'"'})},ye=function(n,e,t){return ge(n,function(){return'The chosen schema: "'+t+'" did not exist in branches: '+me(e)})},be=function(n,e){return ge(n,function(){return"There are unsupported fields: ["+e.join(", ")+"] specified"})},we=function(n,e){return ge(n,function(){return e})},Se={typeAdt:Kn([{setOf:["validator","valueType"]},{arrOf:["valueType"]},{objOf:["fields"]},{itemOf:["validator"]},{choiceOf:["key","branches"]}]),fieldAdt:Kn([{field:["name","presence","type"]},{state:["name"]}])},xe=Kn([{field:["key","okey","presence","prop"]},{state:["okey","instantiator"]}]),Oe=function(n,e,t){var r=ue(n,e).fold(function(){return t(n)},c.identity);return Xn.value(r)},Te=function(n,e,t,r){return t.fold(function(t,o,i,u){var a=function(e){return u.extract(n.concat([t]),r,e).map(function(n){return ce(o,r(n))})},s=function(e){return e.fold(function(){var n=ce(o,r(p.none()));return Xn.value(n)},function(e){return u.extract(n.concat([t]),r,e).map(function(n){return ce(o,r(p.some(n)))})})};return i.fold(function(){return(r=n,o=e,i=t,ue(o,i).fold(function(){return he(r,i,o)},Xn.value)).bind(a);var r,o,i},function(n){return Oe(e,t,n).bind(a)},function(){return(n=e,r=t,Xn.value(ue(n,r))).bind(s);var n,r},function(n){return(r=e,o=t,i=n,u=ue(r,o).map(function(n){return!0===n?i(r):n}),Xn.value(u)).bind(s);var r,o,i,u},function(n){var r=n(e);return Oe(e,t,c.constant({})).map(function(n){return An.deepMerge(r,n)}).bind(a)})},function(n,t){var o=t(e);return Xn.value(ce(n,r(o)))})},ke=function(n){return{extract:function(e,t,r){return n(r).fold(function(n){return we(e,n)},Xn.value)},toString:function(){return"val"},toDsl:function(){return Se.typeAdt.itemOf(n)}}},Ce=function(n){return{extract:function(e,t,r){return o=e,i=r,u=n,a=t,c=E.map(u,function(n){return Te(o,i,n,a)}),Qn(c,{});var o,i,u,a,c},toString:function(){return"obj{\n"+E.map(n,function(n){return n.fold(function(n,e,t,r){return n+" -> "+r.toString()},function(n,e){return"state("+n+")"})}).join("\n")+"}"},toDsl:function(){return Se.typeAdt.objOf(E.map(n,function(n){return n.fold(function(n,e,t,r){return Se.fieldAdt.field(n,t,r)},function(n,e){return Se.fieldAdt.state(n)})}))}}},Ee=function(n){return{extract:function(e,t,r){var o=E.map(r,function(r,o){return n.extract(e.concat(["["+o+"]"]),t,r)});return Zn(o)},toString:function(){return"array("+n.toString()+")"},toDsl:function(){return Se.typeAdt.arrOf(n)}}},De=ke(Xn.value),Ae=c.compose(Ee,Ce),Me={anyValue:c.constant(De),value:ke,obj:Ce,objOnly:function(n){var e=Ce(n),t=E.foldr(n,function(n,e){return e.fold(function(e){return An.deepMerge(n,fe.wrap(e,!0))},c.constant(n))},{});return{extract:function(n,r,o){var i,u,a=kn.isBoolean(o)?[]:(i=o,u=Hn.keys(i),E.filter(u,function(n){return fe.hasKey(i,n)})),c=E.filter(a,function(n){return!fe.hasKey(t,n)});return 0===c.length?e.extract(n,r,o):be(n,c)},toString:e.toString,toDsl:e.toDsl}},arr:Ee,setOf:function(n,e){return{extract:function(t,r,o){var i,u,a=Hn.keys(o);return(i=t,u=a,Ee(ke(n)).extract(i,c.identity,u)).bind(function(n){var i=E.map(n,function(n){return xe.field(n,n,$n.strict(),e)});return Ce(i).extract(t,r,o)})},toString:function(){return"setOf("+e.toString()+")"},toDsl:function(){return Se.typeAdt.setOf(n,e)}}},arrOfObj:Ae,state:xe.state,field:xe.field,output:function(n,e){return xe.state(n,c.constant(e))},snapshot:function(n){return xe.state(n,c.identity)}},Re=function(n,e){return Me.field(n,n,$n.strict(),e)},Fe=function(n){return Me.field(n,n,$n.strict(),Me.anyValue())},Be=Re,Ie=function(n,e){return Me.field(n,n,$n.strict(),Me.obj(e))},He=function(n){return Me.field(n,n,$n.strict(),Me.value(function(n){return kn.isFunction(n)?Xn.value(n):Xn.error("Not a function")}))},Ne=function(n,e){return Me.field(n,n,$n.asOption(),Me.value(function(t){return Xn.error("The field: "+n+" is forbidden. "+e)}))},Ve=function(n){return Me.field(n,n,$n.asOption(),Me.anyValue())},je=function(n,e){return Me.field(n,n,$n.asOption(),e)},Pe=function(n,e){return Me.field(n,n,$n.asOption(),Me.obj(e))},Le=function(n,e){return Me.field(n,n,$n.asOption(),Me.objOnly(e))},We=function(n,e){return Me.field(n,n,$n.defaulted(e),Me.anyValue())},Ue=function(n,e,t){return Me.field(n,n,$n.defaulted(e),t)},ze=function(n,e,t){return Me.field(n,n,$n.defaulted(e),Me.obj(t))},Ke=function(n,e,t,r){return Me.field(n,e,t,r)},Ge=function(n,e){return Me.state(n,e)},$e=function(n,e){return{extract:function(t,r,o){return fe.readOptFrom(o,n).fold(function(){return ve(t,n)},function(n){return i=t,u=r,a=o,c=e,s=n,fe.readOptFrom(c,s).fold(function(){return ye(i,c,s)},function(n){return Me.obj(n).extract(i.concat(["branch: "+s]),u,a)});var i,u,a,c,s})},toString:function(){return"chooseOn("+n+"). Possible values: "+Hn.keys(e)},toDsl:function(){return Se.typeAdt.choiceOf(n,e)}}},qe=Me.value(Xn.value),_e=Me.arr,Xe=Me.obj,Ye=Me.objOnly,Je=Me.setOf,Qe=function(n,e,t,r){return e.extract([n],t,r).fold(function(n){return Xn.error({input:r,errors:n})},Xn.value)},Ze=function(n,e,t){return Qe(n,e,c.constant,t)},nt=function(n,e,t){return Qe(n,e,c.identity,t)},et=function(n){return n.fold(function(n){throw new Error(tt(n))},c.identity)},tt=function(n){return"Errors: \n"+pe(n.errors)+"\n\nInput object: "+me(n.input)},rt={anyValue:c.constant(qe),arrOfObj:function(n){return Me.arrOfObj(n)},arrOf:_e,arrOfVal:function(){return Me.arr(qe)},valueOf:function(n){return Me.value(n)},setOf:Je,objOf:Xe,objOfOnly:Ye,asStruct:Ze,asRaw:nt,asStructOrDie:function(n,e,t){return et(Ze(n,e,t))},asRawOrDie:function(n,e,t){return et(nt(n,e,t))},getOrDie:et,formatError:tt,choose:function(n,e){return $e(n,e)}},ot=function(n){if(!fe.hasKey(n,"can")&&!fe.hasKey(n,"abort")&&!fe.hasKey(n,"run"))throw new Error("EventHandler defined by: "+de(n,null,2)+" does not have can, abort, or run!");return rt.asRawOrDie("Extracting event.handler",rt.objOfOnly([We("can",c.constant(!0)),We("abort",c.constant(!1)),We("run",c.noop)]),n)},it=function(n){return kn.isFunction(n)?{can:c.constant(!0),abort:c.constant(!1),run:n}:n},ut=function(n){var e,t,r,o,i=(e=n,t=function(n){return n.can},function(){var n=Array.prototype.slice.call(arguments,0);return E.foldl(e,function(e,r){return e&&t(r).apply(undefined,n)},!0)}),u=(r=n,o=function(n){return n.abort},function(){var n=Array.prototype.slice.call(arguments,0);return E.foldl(r,function(e,t){return e||o(t).apply(undefined,n)},!1)});return ot({can:i,abort:u,run:function(){var e=Array.prototype.slice.call(arguments,0);E.each(n,function(n){n.run.apply(undefined,e)})}})},at=ot,ct=function(n,e){return{key:n,value:at({run:e})}},st=function(n){return function(e){return{key:n,value:at({run:function(n,t){wn(n,t)&&e(n,t)}})}}},ft=function(n,e){return ct(n,function(t,r){t.getSystem().getByUid(e).each(function(e){Un(e,e.element(),n,r)})})},lt={derive:fe.wrapAll,run:ct,preventDefault:function(n){return{key:n,value:at({run:function(n,e){e.event().prevent()}})}},runActionExtra:function(n,e,t){return{key:n,value:at({run:function(n){e.apply(undefined,[n].concat(t))}})}},runOnAttached:st(On.attachedToDom()),runOnDetached:st(On.detachedFromDom()),runOnInit:st(On.systemInit()),runOnExecute:(u=On.execute(),function(n){return ct(u,n)}),redirectToUid:ft,redirectToPart:function(n,e,t){var r=e.partUids()[t];return ft(n,r)},runWithTarget:function(n,e){return ct(n,function(n,t){n.getSystem().getByDom(t.event().target()).each(function(r){e(n,r,t)})})},abort:function(n,e){return{key:n,value:at({abort:e})}},can:function(n,e){return{key:n,value:at({can:e})}},cutter:function(n){return ct(n,function(n,e){e.cut()})},stopper:function(n){return ct(n,function(n,e){e.stop()})}},dt=function(n,e,t){return n},mt=function(n,e){return n},pt=function(n,e){return n};p.none;var gt=function(n){return n.slice(0).sort()},ht={sort:gt,reqMessage:function(n,e){throw new Error("All required keys ("+gt(n).join(", ")+") were not specified. Specified keys were: "+gt(e).join(", ")+".")},unsuppMessage:function(n){throw new Error("Unsupported keys for object: "+gt(n).join(", "))},validateStrArr:function(n,e){if(!kn.isArray(e))throw new Error("The "+n+" fields must be an array. Was: "+e+".");E.each(e,function(e){if(!kn.isString(e))throw new Error("The value "+e+" in the "+n+" fields was not a string.")})},invalidTypeMessage:function(n,e){throw new Error("All values need to be of type: "+e+". Keys ("+gt(n).join(", ")+") were not.")},checkDupes:function(n){var e=gt(n);E.find(e,function(n,t){return t<e.length-1&&n===e[t+1]}).each(function(n){throw new Error("The field: "+n+" occurs more than once in the combined fields: ["+e.join(", ")+"].")})}},vt={immutable:function(){var n=arguments;return function(){for(var e=new Array(arguments.length),t=0;t<e.length;t++)e[t]=arguments[t];if(n.length!==e.length)throw new Error('Wrong number of arguments to struct. Expected "['+n.length+']", got '+e.length+" arguments");var r={};return E.each(n,function(n,t){r[n]=c.constant(e[t])}),r}},immutableBag:function(n,e){var t=n.concat(e);if(0===t.length)throw new Error("You must specify at least one required or optional field.");return ht.validateStrArr("required",n),ht.validateStrArr("optional",e),ht.checkDupes(t),function(r){var o=Hn.keys(r);E.forall(n,function(n){return E.contains(o,n)})||ht.reqMessage(n,o);var i=E.filter(o,function(n){return!E.contains(t,n)});i.length>0&&ht.unsuppMessage(i);var u={};return E.each(n,function(n){u[n]=c.constant(r[n])}),E.each(e,function(n){u[n]=c.constant(Object.prototype.hasOwnProperty.call(r,n)?p.some(r[n]):p.none())}),u}}},yt=function(n){return{tag:n.tag(),classes:n.classes().getOr([]),attributes:n.attributes().getOr({}),styles:n.styles().getOr({}),value:n.value().getOr("<none>"),innerHtml:n.innerHtml().getOr("<none>"),defChildren:n.defChildren().getOr("<none>"),domChildren:n.domChildren().fold(function(){return"<none>"},function(n){return 0===n.length?"0 children, but still specified":String(n.length)})}},bt={nu:vt.immutableBag(["tag"],["classes","attributes","styles","value","innerHtml","domChildren","defChildren"]),defToStr:function(n){var e=yt(n);return de(e,null,2)},defToRaw:yt},wt=vt.immutableBag([],["classes","attributes","styles","value","innerHtml","defChildren","domChildren"]),St=function(n){return{classes:n.classes().getOr("<none>"),attributes:n.attributes().getOr("<none>"),styles:n.styles().getOr("<none>"),value:n.value().getOr("<none>"),innerHtml:n.innerHtml().getOr("<none>"),defChildren:n.defChildren().getOr("<none>"),domChildren:n.domChildren().fold(function(){return"<none>"},function(n){return 0===n.length?"0 children, but still specified":String(n.length)})}},xt=function(n,e,t){return e.fold(function(){return t.fold(function(){return{}},function(e){return fe.wrap(n,e)})},function(e){return t.fold(function(){return fe.wrap(n,e)},function(e){return fe.wrap(n,e)})})},Ot={nu:wt,derive:function(n){var e={},t=Hn.keys(n);return E.each(t,function(t){n[t].each(function(n){e[t]=n})}),wt(e)},merge:function(n,e){var t=An.deepMerge({tag:n.tag(),classes:e.classes().getOr([]).concat(n.classes().getOr([])),attributes:An.merge(n.attributes().getOr({}),e.attributes().getOr({})),styles:An.merge(n.styles().getOr({}),e.styles().getOr({}))},e.innerHtml().or(n.innerHtml()).map(function(n){return fe.wrap("innerHtml",n)}).getOr({}),xt("domChildren",e.domChildren(),n.domChildren()),xt("defChildren",e.defChildren(),n.defChildren()),e.value().or(n.value()).map(function(n){return fe.wrap("value",n)}).getOr({}));return bt.nu(t)},modToStr:function(n){var e=St(n);return de(e,null,2)},modToRaw:St},Tt=function(n){return{key:n,value:undefined}},kt=function(n,e,t,r,o,i,u){var a=function(n){return fe.hasKey(n,t)?n[t]():p.none()},s=Hn.map(o,function(n,e){return r=t,dt(function(n){var e=arguments;return n.config({name:c.constant(r)}).fold(function(){throw new Error("We could not find any behaviour configuration for: "+r+". Using API: "+i)},function(t){var r=Array.prototype.slice.call(e,1);return o.apply(undefined,[n,t.config,t.state].concat(r))})},i=e,o=n);var r,o,i}),f=Hn.map(i,function(n,e){return mt(n,e)}),l=An.deepMerge(f,s,{revoke:c.curry(Tt,t),config:function(e){var r=rt.asStructOrDie(t+"-config",n,e);return{key:t,value:{config:r,me:l,configAsRaw:F(function(){return rt.asRawOrDie(t+"-config",n,e)}),initialConfig:e,state:u}}},schema:function(){return e},exhibit:function(n,e){return a(n).bind(function(n){return fe.readOptFrom(r,"exhibit").map(function(t){return t(e,n.config,n.state)})}).getOr(Ot.nu({}))},name:function(){return t},handlers:function(n){return a(n).bind(function(n){return fe.readOptFrom(r,"events").map(function(e){return e(n.config,n.state)})}).getOr({})}});return l},Ct=function(n,e,t){return lt.runOnExecute(function(r){t(r,n,e)})},Et=function(n,e,t){return lt.runOnInit(function(r,o){t(r,n,e)})},Dt=function(n,e,t,r,o,i){var u=rt.objOfOnly(n),a=Pe(e,[Le("config",n)]);return kt(u,a,e,t,r,o,i)},At=function(n,e,t,r,o,i){var u=n,a=Pe(e,[je("config",n)]);return kt(u,a,e,t,r,o,i)},Mt=function(n,e){return Rt(n,e,{validate:kn.isFunction,label:"function"})},Rt=function(n,e,t){if(0===e.length)throw new Error("You must specify at least one required field.");return ht.validateStrArr("required",e),ht.checkDupes(e),function(r){var o=Hn.keys(r);E.forall(e,function(n){return E.contains(o,n)})||ht.reqMessage(e,o),n(e,o);var i=E.filter(e,function(n){return!t.validate(r[n],n)});return i.length>0&&ht.invalidTypeMessage(i,t.label),r}},Ft=c.noop,Bt={exactly:c.curry(Mt,function(n,e){var t=E.filter(e,function(e){return!E.contains(n,e)});t.length>0&&ht.unsuppMessage(t)}),ensure:c.curry(Mt,Ft),ensureWith:c.curry(Rt,Ft)},It=Bt.ensure(["readState"]),Ht={init:function(){return It({readState:function(){return"No State required"}})}},Nt=rt.objOfOnly([Fe("fields"),Fe("name"),We("active",{}),We("apis",{}),We("extra",{}),We("state",Ht)]),Vt=rt.objOfOnly([Fe("branchKey"),Fe("branches"),Fe("name"),We("active",{}),We("apis",{}),We("extra",{}),We("state",Ht)]),jt={derive:function(n){return fe.wrapAll(n)},revoke:c.constant(undefined),noActive:c.constant({}),noApis:c.constant({}),noExtra:c.constant({}),noState:c.constant(Ht),create:function(n){var e=rt.asRawOrDie("Creating behaviour: "+n.name,Nt,n);return Dt(e.fields,e.name,e.active,e.apis,e.extra,e.state)},createModes:function(n){var e=rt.asRawOrDie("Creating behaviour: "+n.name,Vt,n);return At(rt.choose(e.branchKey,e.branches),e.name,e.active,e.apis,e.extra,e.state)}};function Pt(n,e,t){var r=t||!1,o=function(){e(),r=!0},i=function(){n(),r=!1};return{on:o,off:i,toggle:function(){(r?i:o)()},isOn:function(){return r}}}var Lt=function(n){return n.dom().nodeName.toLowerCase()},Wt=function(n){return n.dom().nodeType},Ut=function(n){return function(e){return Wt(e)===n}},zt=Ut(dn),Kt=Ut(mn),Gt=Ut(ln),$t={name:Lt,type:Wt,value:function(n){return n.dom().nodeValue},isElement:zt,isText:Kt,isDocument:Gt,isComment:function(n){return Wt(n)===fn||"#comment"===Lt(n)}},qt=function(n,e,t){if(!(kn.isString(t)||kn.isBoolean(t)||kn.isNumber(t)))throw console.error("Invalid call to Attr.set. Key ",e,":: Value ",t,":: Element ",n),new Error("Attribute value was not simple");n.setAttribute(e,t+"")},_t=function(n,e,t){qt(n.dom(),e,t)},Xt=function(n,e){var t=n.dom().getAttribute(e);return null===t?undefined:t},Yt=function(n,e){var t=n.dom();return!(!t||!t.hasAttribute)&&t.hasAttribute(e)},Jt={clone:function(n){return E.foldl(n.dom().attributes,function(n,e){return n[e.name]=e.value,n},{})},set:_t,setAll:function(n,e){var t=n.dom();Hn.each(e,function(n,e){qt(t,e,n)})},get:Xt,has:Yt,remove:function(n,e){n.dom().removeAttribute(e)},hasNone:function(n){var e=n.dom().attributes;return e===undefined||null===e||0===e.length},transfer:function(n,e,t){$t.isElement(n)&&$t.isElement(e)&&E.each(t,function(t){var r,o,i;o=e,Yt(r=n,i=t)&&!Yt(o,i)&&_t(o,i,Xt(r,i))})}},Qt=function(n,e){var t=Jt.get(n,e);return t===undefined||""===t?[]:t.split(" ")},Zt=Qt,nr=function(n,e,t){var r=Qt(n,e).concat([t]);Jt.set(n,e,r.join(" "))},er=function(n,e,t){var r=E.filter(Qt(n,e),function(n){return n!==t});r.length>0?Jt.set(n,e,r.join(" ")):Jt.remove(n,e)},tr=function(n){return Zt(n,"class")},rr=function(n,e){return nr(n,"class",e)},or=function(n,e){return er(n,"class",e)},ir=tr,ur=rr,ar=or,cr=function(n,e){E.contains(tr(n),e)?or(n,e):rr(n,e)},sr=function(n){return n.dom().classList!==undefined},fr=function(n,e){return sr(n)&&n.dom().classList.contains(e)},lr={add:function(n,e){sr(n)?n.dom().classList.add(e):ur(n,e)},remove:function(n,e){var t;sr(n)?n.dom().classList.remove(e):ar(n,e),0===(sr(t=n)?t.dom().classList:ir(t)).length&&Jt.remove(t,"class")},toggle:function(n,e){return sr(n)?n.dom().classList.toggle(e):cr(n,e)},toggler:function(n,e){var t=sr(n),r=n.dom().classList;return Pt(function(){t?r.remove(e):ar(n,e)},function(){t?r.add(e):ur(n,e)},fr(n,e))},has:fr},dr=function(n,e,t){lr.remove(n,t),lr.add(n,e)},mr={toAlpha:function(n,e,t){dr(n.element(),e.alpha(),e.omega())},toOmega:function(n,e,t){dr(n.element(),e.omega(),e.alpha())},isAlpha:function(n,e,t){return lr.has(n.element(),e.alpha())},isOmega:function(n,e,t){return lr.has(n.element(),e.omega())},clear:function(n,e,t){lr.remove(n.element(),e.alpha()),lr.remove(n.element(),e.omega())}},pr=[Fe("alpha"),Fe("omega")],gr=jt.create({fields:pr,name:"swapping",apis:mr}),hr=function(n,e){var t=[],r=function(n){return t.push(n),e(n)},o=e(n);do{o=o.bind(r)}while(o.isSome());return t},vr=function(n){return sn.fromDom(n.dom().ownerDocument)},yr=function(n){var e=n.dom();return p.from(e.parentNode).map(sn.fromDom)},br=function(n){var e=n.dom();return p.from(e.previousSibling).map(sn.fromDom)},wr=function(n){var e=n.dom();return p.from(e.nextSibling).map(sn.fromDom)},Sr=function(n){var e=n.dom();return E.map(e.childNodes,sn.fromDom)},xr=function(n,e){var t=n.dom().childNodes;return p.from(t[e]).map(sn.fromDom)},Or=vt.immutable("element","offset"),Tr={owner:vr,defaultView:function(n){var e=n.dom().ownerDocument.defaultView;return sn.fromDom(e)},documentElement:function(n){var e=vr(n);return sn.fromDom(e.dom().documentElement)},parent:yr,findIndex:function(n){return yr(n).bind(function(e){var t=Sr(e);return E.findIndex(t,function(e){return bn(n,e)})})},parents:function(n,e){for(var t=kn.isFunction(e)?e:c.constant(!1),r=n.dom(),o=[];null!==r.parentNode&&r.parentNode!==undefined;){var i=r.parentNode,u=sn.fromDom(i);if(o.push(u),!0===t(u))break;r=i}return o},siblings:function(n){return yr(n).map(Sr).map(function(e){return E.filter(e,function(e){return!bn(n,e)})}).getOr([])},prevSibling:br,offsetParent:function(n){var e=n.dom();return p.from(e.offsetParent).map(sn.fromDom)},prevSiblings:function(n){return E.reverse(hr(n,br))},nextSibling:wr,nextSiblings:function(n){return hr(n,wr)},children:Sr,child:xr,firstChild:function(n){return xr(n,0)},lastChild:function(n){return xr(n,n.dom().childNodes.length-1)},childNodesCount:function(n){return n.dom().childNodes.length},hasChildNodes:function(n){return n.dom().hasChildNodes()},leaf:function(n,e){var t=Sr(n);return t.length>0&&e<t.length?Or(t[e],0):Or(n,e)}},kr=function(n,e){Tr.parent(n).each(function(t){t.dom().insertBefore(e.dom(),n.dom())})},Cr=function(n,e){n.dom().appendChild(e.dom())},Er={before:kr,after:function(n,e){Tr.nextSibling(n).fold(function(){Tr.parent(n).each(function(n){Cr(n,e)})},function(n){kr(n,e)})},prepend:function(n,e){Tr.firstChild(n).fold(function(){Cr(n,e)},function(t){n.dom().insertBefore(e.dom(),t.dom())})},append:Cr,appendAt:function(n,e,t){Tr.child(n,t).fold(function(){Cr(n,e)},function(n){kr(n,e)})},wrap:function(n,e){kr(n,e),Cr(e,n)}},Dr={before:function(n,e){E.each(e,function(e){Er.before(n,e)})},after:function(n,e){E.each(e,function(t,r){var o=0===r?n:e[r-1];Er.after(o,t)})},prepend:function(n,e){E.each(e.slice().reverse(),function(e){Er.prepend(n,e)})},append:function(n,e){E.each(e,function(e){Er.append(n,e)})}},Ar=function(n){var e=n.dom();null!==e.parentNode&&e.parentNode.removeChild(e)},Mr={empty:function(n){n.dom().textContent="",E.each(Tr.children(n),function(n){Ar(n)})},remove:Ar,unwrap:function(n){var e=Tr.children(n);e.length>0&&Dr.before(n,e),Ar(n)}},Rr=F(function(){return Fr(sn.fromDom(document))}),Fr=function(n){var e=n.dom().body;if(null===e||e===undefined)throw"Body is not available yet";return sn.fromDom(e)},Br={body:Rr,getBody:Fr,inBody:function(n){var e=$t.isText(n)?n.dom().parentNode:n.dom();return e!==undefined&&null!==e&&e.ownerDocument.body.contains(e)}},Ir=function(n){jn(n,On.detachedFromDom());var e=n.components();E.each(e,Ir)},Hr=function(n){var e=n.components();E.each(e,Hr),jn(n,On.attachedToDom())},Nr=function(n,e,t){n.getSystem().addToWorld(e),t(n.element(),e.element()),Br.inBody(n.element())&&Hr(e),n.syncComponents()},Vr=function(n){Ir(n),Mr.remove(n.element()),n.getSystem().removeFromWorld(n)},jr={attach:function(n,e){Nr(n,e,Er.append)},attachWith:Nr,detach:function(n){var e=Tr.parent(n.element()).bind(function(e){return n.getSystem().getByDom(e).fold(p.none,p.some)});Vr(n),e.each(function(n){n.syncComponents()})},detachChildren:function(n){var e=n.components();E.each(e,Vr),Mr.empty(n.element()),n.syncComponents()},attachSystem:function(n,e){Er.append(n,e.element());var t=Tr.children(e.element());E.each(t,function(n){e.getByDom(n).each(Hr)})},detachSystem:function(n){var e=Tr.children(n.element());E.each(e,function(e){n.getByDom(e).each(Ir)}),Mr.remove(n.element())}},Pr=function(n,e){var t=(e||document).createElement("div");return t.innerHTML=n,Tr.children(sn.fromDom(t))},Lr=function(n){return n.dom().innerHTML},Wr=Lr,Ur=function(n,e){var t=Tr.owner(n).dom(),r=sn.fromDom(t.createDocumentFragment()),o=Pr(e,t);Dr.append(r,o),Mr.empty(n),Er.append(n,r)},zr=function(n){var e=sn.fromTag("div"),t=sn.fromDom(n.dom().cloneNode(!0));return Er.append(e,t),Lr(e)},Kr=function(n,e){return sn.fromDom(n.dom().cloneNode(e))},Gr=function(n){return Kr(n,!1)},$r=function(n){var e=Gr(n);return zr(e)},qr={element:function(n){return $r(n)}},_r=function(n){for(var e=[],t=function(n){e.push(n)},r=0;r<n.length;r++)n[r].each(t);return e},Xr=function(n,e){for(var t=0;t<n.length;t++){var r=e(n[t],t);if(r.isSome())return r}return p.none()},Yr="unknown",Jr="__CHROME_INSPECTOR_CONNECTION_TO_ALLOY__",Qr=[],Zr=["alloy/data/Fields","alloy/debugging/Debugging"],no={logEventCut:c.noop,logEventStopped:c.noop,logNoParent:c.noop,logEventNoHandlers:c.noop,logEventResponse:c.noop,write:c.noop},eo=function(){return window[Jr]!==undefined?window[Jr]:(window[Jr]={systems:{},lookup:function(n){var e=window[Jr].systems,t=Hn.keys(e);return Xr(t,function(t){return e[t].getByUid(n).toOption().map(function(n){return fe.wrap(qr.element(n.element()),(e=function(n){var t=n.spec();return{"(original.spec)":t,"(dom.ref)":n.element().dom(),"(element)":qr.element(n.element()),"(initComponents)":E.map(t.components!==undefined?t.components:[],e),"(components)":E.map(n.components(),e),"(bound.events)":Hn.mapToArray(n.events(),function(n,e){return[e]}).join(", "),"(behaviours)":t.behaviours!==undefined?Hn.map(t.behaviours,function(e,t){return e===undefined?"--revoked--":{config:e.configAsRaw(),"original-config":e.initialConfig,state:n.readState(t)}}):"none"}})(n));var e})})}},window[Jr])},to=function(n,e,t){},ro=(c.constant(no),function(){var n=new Error;if(n.stack!==undefined){var e=n.stack.split("\n");return E.find(e,function(n){return n.indexOf("alloy")>0&&!E.exists(Zr,function(e){return n.indexOf(e)>-1})}).getOr(Yr)}return Yr}),oo=function(n,e,t){var r,o="*"===Qr||E.contains(Qr,n)?(r=[],{logEventCut:function(n,e,t){r.push({outcome:"cut",target:e,purpose:t})},logEventStopped:function(n,e,t){r.push({outcome:"stopped",target:e,purpose:t})},logNoParent:function(n,e,t){r.push({outcome:"no-parent",target:e,purpose:t})},logEventNoHandlers:function(n,e){r.push({outcome:"no-handlers-left",target:e})},logEventResponse:function(n,e,t){r.push({outcome:"response",purpose:t,target:e})},write:function(){E.contains(["mousemove","mouseover","mouseout",On.systemInit()],n)||console.log(n,{event:n,target:e.dom(),sequence:E.map(r,function(n){return E.contains(["cut","stopped","response"],n.outcome)?"{"+n.purpose+"} "+n.outcome+" at ("+qr.element(n.target)+")":n.outcome})})}}):no,i=t(o);return o.write(),i},io=(c.constant(!0),function(n,e){eo().systems[n]=e}),uo=function(n){var e=n,t=function(){return e};return{get:t,set:function(n){e=n},clone:function(){return uo(t())}}};function ao(n,e,t,r,o){return n(t,r)?p.some(t):kn.isFunction(o)&&o(t)?p.none():e(t,r,o)}var co=function(n,e,t){for(var r=n.dom(),o=kn.isFunction(t)?t:c.constant(!1);r.parentNode;){r=r.parentNode;var i=sn.fromDom(r);if(e(i))return p.some(i);if(o(i))break}return p.none()},so=function(n,e){return E.find(n.dom().childNodes,c.compose(e,sn.fromDom)).map(sn.fromDom)},fo=function(n,e){var t=function(n){for(var r=0;r<n.childNodes.length;r++){if(e(sn.fromDom(n.childNodes[r])))return p.some(sn.fromDom(n.childNodes[r]));var o=t(n.childNodes[r]);if(o.isSome())return o}return p.none()};return t(n.dom())},lo={first:function(n){return fo(Br.body(),n)},ancestor:co,closest:function(n,e,t){return ao(function(n){return e(n)},co,n,e,t)},sibling:function(n,e){var t=n.dom();return t.parentNode?so(sn.fromDom(t.parentNode),function(t){return!bn(n,t)&&e(t)}):p.none()},child:so,descendant:fo},mo=function(n){n.dom().focus()},po=function(n){var e=n!==undefined?n.dom():document;return p.from(e.activeElement).map(sn.fromDom)},go=function(n){var e=Tr.owner(n).dom();return n.dom()===e.activeElement},ho=mo,vo=function(n){n.dom().blur()},yo=po,bo=function(n){return po(Tr.owner(n)).filter(function(e){return n.dom().contains(e.dom())})},wo=tinymce.util.Tools.resolve("tinymce.ThemeManager"),So=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),xo=function(n){var e=document.createElement("a");e.target="_blank",e.href=n.href,e.rel="noreferrer noopener";var t=document.createEvent("MouseEvents");t.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),document.body.appendChild(e),e.dispatchEvent(t),document.body.removeChild(e)},Oo=function(n){return!1===n.settings.skin},To={formatChanged:c.constant("formatChanged"),orientationChanged:c.constant("orientationChanged"),dropupDismissed:c.constant("dropupDismissed")},ko={events:function(n){return lt.derive([lt.run(On.receive(),function(e,t){var r,o,i=n.channels(),u=Hn.keys(i),a=(r=u,(o=t).universal()?r:E.filter(r,function(n){return E.contains(o.channels(),n)}));E.each(a,function(n){var r=i[n](),o=r.schema(),u=rt.asStructOrDie("channel["+n+"] data\nReceiver: "+qr.element(e.element()),o,t.data());r.onReceive()(e,u)})})])}},Co=[Fe("menu"),Fe("selectedMenu")],Eo=[Fe("item"),Fe("selectedItem")],Do=rt.objOfOnly(Eo.concat(Co)),Ao=rt.objOfOnly(Eo),Mo={menuFields:c.constant(Co),itemFields:c.constant(Eo),schema:c.constant(Do),itemSchema:c.constant(Ao)},Ro=Ie("initSize",[Fe("numColumns"),Fe("numRows")]),Fo=function(n,e,t){var r=ro();return Ke(e,e,t,rt.valueOf(function(t){return Xn.value(function(){return to(n,e,r),t.apply(undefined,arguments)})}))},Bo={initSize:c.constant(Ro),itemMarkers:function(){return Be("markers",Mo.itemSchema())},menuMarkers:function(){return Be("markers",Mo.schema())},tieredMenuMarkers:function(){return Ie("markers",[Fe("backgroundMenu")].concat(Mo.menuFields()).concat(Mo.itemFields()))},markers:function(n){return Ie("markers",E.map(n,Fe))},onHandler:function(n){return Fo("onHandler",n,$n.defaulted(c.noop))},onKeyboardHandler:function(n){return Fo("onKeyboardHandler",n,$n.defaulted(p.none))},onStrictHandler:function(n){return Fo("onHandler",n,$n.strict())},onStrictKeyboardHandler:function(n){return Fo("onKeyboardHandler",n,$n.strict())},output:function(n,e){return Ge(n,c.constant(e))},snapshot:function(n){return Ge(n,c.identity)}},Io=[Be("channels",rt.setOf(Xn.value,rt.objOfOnly([Bo.onStrictHandler("onReceive"),We("schema",rt.anyValue())])))],Ho=jt.create({fields:Io,name:"receiving",active:ko}),No=function(n,e){var t=Po(n,e),r=e.aria();r.update()(n,r,t)},Vo=function(n,e,t){lr.add(n.element(),e.toggleClass()),No(n,e)},jo=function(n,e,t){lr.remove(n.element(),e.toggleClass()),No(n,e)},Po=function(n,e){return lr.has(n.element(),e.toggleClass())},Lo={onLoad:function(n,e,t){(e.selected()?Vo:jo)(n,e,t)},toggle:function(n,e,t){lr.toggle(n.element(),e.toggleClass()),No(n,e)},isOn:Po,on:Vo,off:jo},Wo={exhibit:function(n,e,t){return Ot.nu({})},events:function(n,e){var t=Ct(n,e,Lo.toggle),r=Et(n,e,Lo.onLoad);return lt.derive(E.flatten([n.toggleOnExecute()?[t]:[],[r]]))}},Uo=function(n,e,t){Jt.set(n.element(),"aria-expanded",t)},zo={button:["aria-pressed"],"input:checkbox":["aria-checked"]},Ko={button:["aria-pressed"],listbox:["aria-pressed","aria-expanded"],menuitemcheckbox:["aria-checked"]},Go={updatePressed:function(n,e,t){Jt.set(n.element(),"aria-pressed",t),e.syncWithExpanded()&&Uo(n,e,t)},updateSelected:function(n,e,t){Jt.set(n.element(),"aria-selected",t)},updateChecked:function(n,e,t){Jt.set(n.element(),"aria-checked",t)},updateExpanded:Uo,updateAuto:function(n,e,t){var r=function(n){var e=n.element();if(Jt.has(e,"role")){var t=Jt.get(e,"role");return fe.readOptFrom(Ko,t)}return p.none()}(n).orThunk(function(){return e=n.element(),t=$t.name(e),r="input"===t&&Jt.has(e,"type")?":"+Jt.get(e,"type"):"",fe.readOptFrom(zo,t+r);var e,t,r}).getOr([]);E.each(r,function(e){Jt.set(n.element(),e,t)})}},$o=[We("selected",!1),Fe("toggleClass"),We("toggleOnExecute",!0),Ue("aria",{mode:"none"},rt.choose("mode",{pressed:[We("syncWithExpanded",!1),Bo.output("update",Go.updatePressed)],checked:[Bo.output("update",Go.updateChecked)],expanded:[Bo.output("update",Go.updateExpanded)],selected:[Bo.output("update",Go.updateSelected)],none:[Bo.output("update",c.noop)]}))],qo=jt.create({fields:$o,name:"toggling",active:Wo,apis:Lo}),_o=function(n,e){return Ho.config({channels:fe.wrap(To.formatChanged(),{onReceive:function(t,r){r.command===n&&e(t,r.state)}})})},Xo=function(n){return Ho.config({channels:fe.wrap(To.orientationChanged(),{onReceive:n})})},Yo=function(n,e){return{key:n,value:{onReceive:e}}},Jo="tinymce-mobile",Qo={resolve:function(n){return Jo+"-"+n},prefix:c.constant(Jo)},Zo={events:function(n){return lt.derive([lt.abort(Sn.selectstart(),c.constant(!0))])},exhibit:function(n,e){return Ot.nu({styles:{"-webkit-user-select":"none","user-select":"none","-ms-user-select":"none","-moz-user-select":"-moz-none"},attributes:{unselectable:"on"}})}},ni=jt.create({fields:[],name:"unselecting",active:Zo}),ei={focus:function(n,e){e.ignore()||(ho(n.element()),e.onFocus()(n))},blur:function(n,e){e.ignore()||vo(n.element())},isFocused:function(n){return go(n.element())}},ti={exhibit:function(n,e){return e.ignore()?Ot.nu({}):Ot.nu({attributes:{tabindex:"-1"}})},events:function(n){return lt.derive([lt.run(On.focus(),function(e,t){ei.focus(e,n),t.stop()})])}},ri=[Bo.onHandler("onFocus"),We("ignore",!1)],oi=jt.create({fields:ri,name:"focusing",active:ti,apis:ei}),ii={BACKSPACE:c.constant([8]),TAB:c.constant([9]),ENTER:c.constant([13]),SHIFT:c.constant([16]),CTRL:c.constant([17]),ALT:c.constant([18]),CAPSLOCK:c.constant([20]),ESCAPE:c.constant([27]),SPACE:c.constant([32]),PAGEUP:c.constant([33]),PAGEDOWN:c.constant([34]),END:c.constant([35]),HOME:c.constant([36]),LEFT:c.constant([37]),UP:c.constant([38]),RIGHT:c.constant([39]),DOWN:c.constant([40]),INSERT:c.constant([45]),DEL:c.constant([46]),META:c.constant([91,93,224]),F10:c.constant([121])},ui=function(n,e,t,r){var o=n+e;return o>r?t:o<t?r:o},ai=function(n,e,t){return n<=e?e:n>=t?t:n},ci=function(n,e,t){return E.filter(Tr.parents(n,t),e)},si=function(n,e){return E.filter(Tr.siblings(n),e)},fi=function(n){return vn.all(n)},li=function(n,e,t){return ci(n,function(n){return vn.is(n,e)},t)},di=function(n,e){return si(n,function(n){return vn.is(n,e)})},mi=function(n,e){return vn.all(e,n)},pi=function(n,e,t){return lo.ancestor(n,function(n){return vn.is(n,e)},t)},gi=function(n){return vn.one(n)},hi=pi,vi=function(n,e){return vn.one(e,n)},yi=function(n,e,t){return ao(vn.is,pi,n,e,t)},bi=function(n,e,t){var r=mi(n.element(),"."+e.highlightClass());E.each(r,function(t){lr.remove(t,e.highlightClass()),n.getSystem().getByDom(t).each(function(t){e.onDehighlight()(n,t)})})},wi=function(n,e,t,r){var o=Si(n,e,t,r);bi(n,e),lr.add(r.element(),e.highlightClass()),o||e.onHighlight()(n,r)},Si=function(n,e,t,r){return lr.has(r.element(),e.highlightClass())},xi=function(n,e,t,r){var o=mi(n.element(),"."+e.itemClass());return p.from(o[r]).fold(function(){return Xn.error("No element found with index "+r)},n.getSystem().getByDom)},Oi=function(n,e,t){return vi(n.element(),"."+e.itemClass()).bind(n.getSystem().getByDom)},Ti=function(n,e,t){var r=mi(n.element(),"."+e.itemClass());return(r.length>0?p.some(r[r.length-1]):p.none()).bind(n.getSystem().getByDom)},ki=function(n,e,t,r){var o=mi(n.element(),"."+e.itemClass());return E.findIndex(o,function(n){return lr.has(n,e.highlightClass())}).bind(function(e){var t=ui(e,r,0,o.length-1);return n.getSystem().getByDom(o[t])})},Ci={dehighlightAll:bi,dehighlight:function(n,e,t,r){var o=Si(n,e,t,r);lr.remove(r.element(),e.highlightClass()),o&&e.onDehighlight()(n,r)},highlight:wi,highlightFirst:function(n,e,t){Oi(n,e,t).each(function(r){wi(n,e,t,r)})},highlightLast:function(n,e,t){Ti(n,e,t).each(function(r){wi(n,e,t,r)})},highlightAt:function(n,e,t,r){xi(n,e,t,r).fold(function(n){throw new Error(n)},function(r){wi(n,e,t,r)})},highlightBy:function(n,e,t,r){var o=mi(n.element(),"."+e.itemClass()),i=_r(E.map(o,function(e){return n.getSystem().getByDom(e).toOption()}));E.find(i,r).each(function(r){wi(n,e,t,r)})},isHighlighted:Si,getHighlighted:function(n,e,t){return vi(n.element(),"."+e.highlightClass()).bind(n.getSystem().getByDom)},getFirst:Oi,getLast:Ti,getPrevious:function(n,e,t){return ki(n,e,0,-1)},getNext:function(n,e,t){return ki(n,e,0,1)}},Ei=[Fe("highlightClass"),Fe("itemClass"),Bo.onHandler("onHighlight"),Bo.onHandler("onDehighlight")],Di=jt.create({fields:Ei,name:"highlighting",apis:Ci}),Ai=function(){return{get:function(n){return bo(n.element())},set:function(n,e){n.getSystem().triggerFocus(e,n.element())}}},Mi=function(){return{get:function(n){return Di.getHighlighted(n).map(function(n){return n.element()})},set:function(n,e){n.getSystem().getByDom(e).fold(c.noop,function(e){Di.highlight(n,e)})}}},Ri=function(n){return!0===n.raw().shiftKey},Fi=function(n){return!0===n.raw().ctrlKey},Bi={inSet:function(n){return function(e){return E.contains(n,e.raw().which)}},and:function(n){return function(e){return E.forall(n,function(n){return n(e)})}},is:function(n){return function(e){return e.raw().which===n}},isShift:Ri,isNotShift:c.not(Ri),isControl:Fi,isNotControl:c.not(Fi)},Ii=function(n,e){return{matches:n,classification:e}},Hi=function(n,e){return E.find(n,function(n){return n.matches(e)}).map(function(n){return n.classification})},Ni=function(n,e,t,r,o,i){var u=function(n,e,r,o){var i=t(n,e,r,o);return Hi(i,e.event()).bind(function(t){return t(n,e,r,o)})},a={schema:function(){return n.concat([We("focusManager",Ai()),Bo.output("handler",a),Bo.output("state",e)])},processKey:u,toEvents:function(n,e){var t=r(n,e),o=lt.derive(i.map(function(t){return lt.run(On.focus(),function(r,o){t(r,n,e,o),o.stop()})}).toArray().concat([lt.run(Sn.keydown(),function(t,r){u(t,r,n,e).each(function(n){r.stop()})})]));return An.deepMerge(t,o)},toApis:o};return a},Vi={cyclePrev:function(n,e,t){var r=E.reverse(n.slice(0,e)),o=E.reverse(n.slice(e+1));return E.find(r.concat(o),t)},cycleNext:function(n,e,t){var r=n.slice(0,e),o=n.slice(e+1);return E.find(o.concat(r),t)},tryPrev:function(n,e,t){var r=E.reverse(n.slice(0,e));return E.find(r,t)},tryNext:function(n,e,t){var r=n.slice(e+1);return E.find(r,t)}},ji={isSupported:function(n){return n.style!==undefined}},Pi=function(n,e,t){if(!kn.isString(t))throw console.error("Invalid call to CSS.set. Property ",e,":: Value ",t,":: Element ",n),new Error("CSS value must be a string: "+t);ji.isSupported(n)&&n.style.setProperty(e,t)},Li=function(n,e){ji.isSupported(n)&&n.style.removeProperty(e)},Wi=function(n,e,t){var r=n.dom();Pi(r,e,t)},Ui=function(n,e){return ji.isSupported(n)?n.style.getPropertyValue(e):""},zi=function(n,e){var t=n.dom(),r=Ui(t,e);return p.from(r).filter(function(n){return n.length>0})},Ki={copy:function(n,e){var t=n.dom(),r=e.dom();ji.isSupported(t)&&ji.isSupported(r)&&(r.style.cssText=t.style.cssText)},set:Wi,preserve:function(n,e){var t=Jt.get(n,"style"),r=e(n);return(t===undefined?Jt.remove:Jt.set)(n,"style",t),r},setAll:function(n,e){var t=n.dom();Hn.each(e,function(n,e){Pi(t,e,n)})},setOptions:function(n,e){var t=n.dom();Hn.each(e,function(n,e){n.fold(function(){Li(t,e)},function(n){Pi(t,e,n)})})},remove:function(n,e){var t=n.dom();Li(t,e),Jt.has(n,"style")&&""===Z(Jt.get(n,"style"))&&Jt.remove(n,"style")},get:function(n,e){var t=n.dom(),r=window.getComputedStyle(t).getPropertyValue(e),o=""!==r||Br.inBody(n)?r:Ui(t,e);return null===o?undefined:o},getRaw:zi,getAllRaw:function(n){var e={},t=n.dom();if(ji.isSupported(t))for(var r=0;r<t.style.length;r++){var o=t.style.item(r);e[o]=t.style[o]}return e},isValidValue:function(n,e,t){var r=sn.fromTag(n);return Wi(r,e,t),zi(r,e).isSome()},reflow:function(n){return n.dom().offsetWidth},transfer:function(n,e,t){$t.isElement(n)&&$t.isElement(e)&&E.each(t,function(t){var r,o;r=e,zi(n,o=t).each(function(n){zi(r,o).isNone()&&Wi(r,o,n)})})}};function Gi(n,e){var t=function(t){var r=e(t);if(r<=0||null===r){var o=Ki.get(t,n);return parseFloat(o)||0}return r},r=function(n,e){return E.foldl(e,function(e,t){var r=Ki.get(n,t),o=r===undefined?0:parseInt(r,10);return isNaN(o)?e:e+o},0)};return{set:function(e,t){if(!kn.isNumber(t)&&!t.match(/^[0-9]+$/))throw n+".set accepts only positive integer values. Value was "+t;var r=e.dom();ji.isSupported(r)&&(r.style[n]=t+"px")},get:t,getOuter:t,aggregate:r,max:function(n,e,t){var o=r(n,t);return e>o?e-o:0}}}var $i=Gi("height",function(n){return Br.inBody(n)?n.dom().getBoundingClientRect().height:n.dom().offsetHeight}),qi=function(n){return $i.get(n)},_i=function(n){var e=[Ve("onEscape"),Ve("onEnter"),We("selector",'[data-alloy-tabstop="true"]'),We("firstTabstop",0),We("useTabstopAt",c.constant(!0)),Ve("visibilitySelector")].concat([n]),t=function(n,e){var t=n.visibilitySelector().bind(function(n){return yi(e,n)}).getOr(e);return qi(t)>0},r=function(n,e,r,o,i){return i(e,r,function(n){return t(e=o,r=n)&&e.useTabstopAt()(r);var e,r}).fold(function(){return o.cyclic()?p.some(!0):p.none()},function(e){return o.focusManager().set(n,e),p.some(!0)})},o=function(n,e,t,o){var i,u,a=mi(n.element(),t.selector());return(i=n,u=t,u.focusManager().get(i).bind(function(n){return yi(n,u.selector())})).bind(function(e){return E.findIndex(a,c.curry(bn,e)).bind(function(e){return r(n,a,e,t,o)})})},i=c.constant([Ii(Bi.and([Bi.isShift,Bi.inSet(ii.TAB())]),function(n,e,t,r){var i=t.cyclic()?Vi.cyclePrev:Vi.tryPrev;return o(n,0,t,i)}),Ii(Bi.inSet(ii.TAB()),function(n,e,t,r){var i=t.cyclic()?Vi.cycleNext:Vi.tryNext;return o(n,0,t,i)}),Ii(Bi.inSet(ii.ESCAPE()),function(n,e,t,r){return t.onEscape().bind(function(t){return t(n,e)})}),Ii(Bi.and([Bi.isNotShift,Bi.inSet(ii.ENTER())]),function(n,e,t,r){return t.onEnter().bind(function(t){return t(n,e)})})]),u=c.constant({}),a=c.constant({});return Ni(e,Ht.init,i,u,a,p.some(function(n,e,r){var o,i,u,a;(o=n,i=e,u=mi(o.element(),i.selector()),a=E.filter(u,function(n){return t(i,n)}),p.from(a[i.firstTabstop()])).each(function(t){e.focusManager().set(n,t)})}))},Xi=_i(Ge("cyclic",c.constant(!1))),Yi=_i(Ge("cyclic",c.constant(!0))),Ji=function(n){return"input"===$t.name(n)&&"radio"!==Jt.get(n,"type")||"textarea"===$t.name(n)},Qi=function(n,e,t){return Ji(t)&&Bi.inSet(ii.SPACE())(e.event())?p.none():(Wn(n,t,On.execute()),p.some(!0))},Zi=[We("execute",Qi),We("useSpace",!1),We("useEnter",!0),We("useControlEnter",!1),We("useDown",!1)],nu=function(n,e,t,r){return t.execute()(n,e,n.element())},eu=c.constant({}),tu=c.constant({}),ru=Ni(Zi,Ht.init,function(n,e,t,r){var o=t.useSpace()&&!Ji(n.element())?ii.SPACE():[],i=t.useEnter()?ii.ENTER():[],u=t.useDown()?ii.DOWN():[],a=o.concat(i).concat(u);return[Ii(Bi.inSet(a),nu)].concat(t.useControlEnter()?[Ii(Bi.and([Bi.isControl,Bi.inSet(ii.ENTER())]),nu)]:[])},eu,tu,p.none()),ou={flatgrid:function(n){var e=uo(p.none());return It({readState:c.constant({}),setGridSize:function(n,t){e.set(p.some({numRows:c.constant(n),numColumns:c.constant(t)}))},getNumRows:function(){return e.get().map(function(n){return n.numRows()})},getNumColumns:function(){return e.get().map(function(n){return n.numColumns()})}})},init:function(n){return n.state()(n)}},iu=function(n){return"rtl"===Ki.get(n,"direction")?"rtl":"ltr"},uu=function(n,e){return function(t){return"rtl"===iu(t)?e:n}},au=function(n){return function(e,t,r,o){var i=n(e.element());return su(i,e,t,r,o)}},cu=function(n){return function(e,t,r,o){return su(n,e,t,r,o)}},su=function(n,e,t,r,o){return r.focusManager().get(e).bind(function(t){return n(e.element(),t,r,o)}).map(function(n){return r.focusManager().set(e,n),!0})},fu=function(n,e){var t=uu(e,n);return au(t)},lu=function(n,e){var t=uu(n,e);return au(t)},du=cu,mu=cu,pu=cu,gu=vt.immutableBag(["index","candidates"],[]),hu=function(n,e){return E.findIndex(n,e).map(function(e){return gu({index:e,candidates:n})})},vu=function(n){var e,t=n.dom();return!((e=t).offsetWidth<=0&&e.offsetHeight<=0)},yu=function(n,e,t,r){var o=c.curry(bn,e),i=mi(n,t),u=E.filter(i,vu);return hu(u,o)},bu=function(n,e,t){return yu(n,e,t,vu)},wu=function(n,e){return E.findIndex(n,function(n){return bn(e,n)})},Su=function(n,e,t,r){return r(Math.floor(e/t),e%t).bind(function(e){var r=e.row()*t+e.column();return r>=0&&r<n.length?p.some(n[r]):p.none()})},xu=function(n,e,t,r,o){return Su(n,e,r,function(e,i){var u=e===t-1?n.length-e*r:r,a=ui(i,o,0,u-1);return p.some({row:c.constant(e),column:c.constant(a)})})},Ou=function(n,e,t,r,o){return Su(n,e,r,function(e,i){var u=ui(e,o,0,t-1),a=u===t-1?n.length-u*r:r,s=ai(i,0,a-1);return p.some({row:c.constant(u),column:c.constant(s)})})},Tu=function(n,e,t,r){return Ou(n,e,t,r,1)},ku=function(n,e,t,r){return Ou(n,e,t,r,-1)},Cu=function(n,e,t,r){return xu(n,e,t,r,-1)},Eu=function(n,e,t,r){return xu(n,e,t,r,1)},Du=[Fe("selector"),We("execute",Qi),Bo.onKeyboardHandler("onEscape"),We("captureTab",!1),Bo.initSize()],Au=function(n){return function(e,t,r,o){return bu(e,t,r.selector()).bind(function(e){return n(e.candidates(),e.index(),o.getNumRows().getOr(r.initSize().numRows()),o.getNumColumns().getOr(r.initSize().numColumns()))})}},Mu=function(n,e,t,r){return t.captureTab()?p.some(!0):p.none()},Ru=Au(Cu),Fu=Au(Eu),Bu=Au(ku),Iu=Au(Tu),Hu=c.constant([Ii(Bi.inSet(ii.LEFT()),lu(Ru,Fu)),Ii(Bi.inSet(ii.RIGHT()),fu(Ru,Fu)),Ii(Bi.inSet(ii.UP()),du(Bu)),Ii(Bi.inSet(ii.DOWN()),mu(Iu)),Ii(Bi.and([Bi.isShift,Bi.inSet(ii.TAB())]),Mu),Ii(Bi.and([Bi.isNotShift,Bi.inSet(ii.TAB())]),Mu),Ii(Bi.inSet(ii.ESCAPE()),function(n,e,t,r){return t.onEscape()(n,e)}),Ii(Bi.inSet(ii.SPACE().concat(ii.ENTER())),function(n,e,t,r){return(o=n,i=t,i.focusManager().get(o).bind(function(n){return yi(n,i.selector())})).bind(function(r){return t.execute()(n,e,r)});var o,i})]),Nu=c.constant({}),Vu=Ni(Du,ou.flatgrid,Hu,Nu,{},p.some(function(n,e,t){vi(n.element(),e.selector()).each(function(t){e.focusManager().set(n,t)})})),ju=function(n,e,t,r){return bu(n,t,e,c.constant(!0)).bind(function(n){var e=n.index(),t=n.candidates(),o=ui(e,r,0,t.length-1);return p.from(t[o])})},Pu=[Fe("selector"),We("getInitial",p.none),We("execute",Qi),We("executeOnMove",!1)],Lu=function(n,e,t){return(r=n,o=t,o.focusManager().get(r).bind(function(n){return yi(n,o.selector())})).bind(function(r){return t.execute()(n,e,r)});var r,o},Wu=function(n,e,t){return ju(n,t.selector(),e,-1)},Uu=function(n,e,t){return ju(n,t.selector(),e,1)},zu=function(n){return function(e,t,r){return n(e,t,r).bind(function(){return r.executeOnMove()?Lu(e,t,r):p.some(!0)})}},Ku=c.constant({}),Gu=c.constant({}),$u=Ni(Pu,Ht.init,function(n){return[Ii(Bi.inSet(ii.LEFT().concat(ii.UP())),zu(lu(Wu,Uu))),Ii(Bi.inSet(ii.RIGHT().concat(ii.DOWN())),zu(fu(Wu,Uu))),Ii(Bi.inSet(ii.ENTER()),Lu),Ii(Bi.inSet(ii.SPACE()),Lu)]},Ku,Gu,p.some(function(n,e){e.getInitial()(n).or(vi(n.element(),e.selector())).each(function(t){e.focusManager().set(n,t)})})),qu=vt.immutableBag(["rowIndex","columnIndex","cell"],[]),_u=function(n,e,t){return p.from(n[e]).bind(function(n){return p.from(n[t]).map(function(n){return qu({rowIndex:e,columnIndex:t,cell:n})})})},Xu=function(n,e,t,r){var o=n[e].length,i=ui(t,r,0,o-1);return _u(n,e,i)},Yu=function(n,e,t,r){var o=ui(t,r,0,n.length-1),i=n[o].length,u=ai(e,0,i-1);return _u(n,o,u)},Ju=function(n,e,t,r){var o=n[e].length,i=ai(t+r,0,o-1);return _u(n,e,i)},Qu=function(n,e,t,r){var o=ai(t+r,0,n.length-1),i=n[o].length,u=ai(e,0,i-1);return _u(n,o,u)},Zu=function(n,e,t){return Xu(n,e,t,1)},na=function(n,e,t){return Xu(n,e,t,-1)},ea=function(n,e,t){return Yu(n,t,e,-1)},ta=function(n,e,t){return Yu(n,t,e,1)},ra=function(n,e,t){return Ju(n,e,t,-1)},oa=function(n,e,t){return Ju(n,e,t,1)},ia=function(n,e,t){return Qu(n,t,e,-1)},ua=function(n,e,t){return Qu(n,t,e,1)},aa=[Ie("selectors",[Fe("row"),Fe("cell")]),We("cycles",!0),We("previousSelector",p.none),We("execute",Qi)],ca=function(n,e){return function(t,r,o){var i=o.cycles()?n:e;return yi(r,o.selectors().row()).bind(function(n){var e=mi(n,o.selectors().cell());return wu(e,r).bind(function(e){var r=mi(t,o.selectors().row());return wu(r,n).bind(function(n){var t,u,a=(t=r,u=o,E.map(t,function(n){return mi(n,u.selectors().cell())}));return i(a,n,e).map(function(n){return n.cell()})})})})}},sa=ca(na,ra),fa=ca(Zu,oa),la=ca(ea,ia),da=ca(ta,ua),ma=c.constant([Ii(Bi.inSet(ii.LEFT()),lu(sa,fa)),Ii(Bi.inSet(ii.RIGHT()),fu(sa,fa)),Ii(Bi.inSet(ii.UP()),du(la)),Ii(Bi.inSet(ii.DOWN()),mu(da)),Ii(Bi.inSet(ii.SPACE().concat(ii.ENTER())),function(n,e,t){return bo(n.element()).bind(function(r){return t.execute()(n,e,r)})})]),pa=c.constant({}),ga=c.constant({}),ha=Ni(aa,Ht.init,ma,pa,ga,p.some(function(n,e){e.previousSelector()(n).orThunk(function(){var t=e.selectors();return vi(n.element(),t.cell())}).each(function(t){e.focusManager().set(n,t)})})),va=[Fe("selector"),We("execute",Qi),We("moveOnTab",!1)],ya=function(n,e,t){return t.focusManager().get(n).bind(function(r){return t.execute()(n,e,r)})},ba=function(n,e,t){return ju(n,t.selector(),e,-1)},wa=function(n,e,t){return ju(n,t.selector(),e,1)},Sa=c.constant([Ii(Bi.inSet(ii.UP()),pu(ba)),Ii(Bi.inSet(ii.DOWN()),pu(wa)),Ii(Bi.and([Bi.isShift,Bi.inSet(ii.TAB())]),function(n,e,t){return t.moveOnTab()?pu(ba)(n,e,t):p.none()}),Ii(Bi.and([Bi.isNotShift,Bi.inSet(ii.TAB())]),function(n,e,t){return t.moveOnTab()?pu(wa)(n,e,t):p.none()}),Ii(Bi.inSet(ii.ENTER()),ya),Ii(Bi.inSet(ii.SPACE()),ya)]),xa=c.constant({}),Oa=c.constant({}),Ta=Ni(va,Ht.init,Sa,xa,Oa,p.some(function(n,e,t){vi(n.element(),e.selector()).each(function(t){e.focusManager().set(n,t)})})),ka=[Bo.onKeyboardHandler("onSpace"),Bo.onKeyboardHandler("onEnter"),Bo.onKeyboardHandler("onShiftEnter"),Bo.onKeyboardHandler("onLeft"),Bo.onKeyboardHandler("onRight"),Bo.onKeyboardHandler("onTab"),Bo.onKeyboardHandler("onShiftTab"),Bo.onKeyboardHandler("onUp"),Bo.onKeyboardHandler("onDown"),Bo.onKeyboardHandler("onEscape"),Ve("focusIn")],Ca=c.constant({}),Ea=c.constant({}),Da=Ni(ka,Ht.init,function(n,e,t){return[Ii(Bi.inSet(ii.SPACE()),t.onSpace()),Ii(Bi.and([Bi.isNotShift,Bi.inSet(ii.ENTER())]),t.onEnter()),Ii(Bi.and([Bi.isShift,Bi.inSet(ii.ENTER())]),t.onShiftEnter()),Ii(Bi.and([Bi.isShift,Bi.inSet(ii.TAB())]),t.onShiftTab()),Ii(Bi.and([Bi.isNotShift,Bi.inSet(ii.TAB())]),t.onTab()),Ii(Bi.inSet(ii.UP()),t.onUp()),Ii(Bi.inSet(ii.DOWN()),t.onDown()),Ii(Bi.inSet(ii.LEFT()),t.onLeft()),Ii(Bi.inSet(ii.RIGHT()),t.onRight()),Ii(Bi.inSet(ii.SPACE()),t.onSpace()),Ii(Bi.inSet(ii.ESCAPE()),t.onEscape())]},Ca,Ea,p.some(function(n,e){return e.focusIn().bind(function(t){return t(n,e)})})),Aa={acyclic:Xi.schema(),cyclic:Yi.schema(),flow:$u.schema(),flatgrid:Vu.schema(),matrix:ha.schema(),execution:ru.schema(),menu:Ta.schema(),special:Da.schema()},Ma=jt.createModes({branchKey:"mode",branches:Aa,name:"keying",active:{events:function(n,e){return n.handler().toEvents(n,e)}},apis:{focusIn:function(n){n.getSystem().triggerFocus(n.element(),n.element())},setGridSize:function(n,e,t,r,o){fe.hasKey(t,"setGridSize")?t.setGridSize(r,o):console.error("Layout does not support setGridSize")}},state:ou}),Ra=function(n,e){return ze(n,{},E.map(e,function(e){return Ne(e.name(),"Cannot configure "+e.name()+" for "+n)}).concat([Ge("dump",c.identity)]))},Fa=function(n){return n.dump()},Ba=0,Ia=function(n){var e=(new Date).getTime();return n+"_"+Math.floor(1e9*Math.random())+ ++Ba+String(e)},Ha=Ia("alloy-premade"),Na=Ia("api"),Va={apiConfig:c.constant(Na),makeApi:function(n){return pt(function(e){var t=Array.prototype.slice.call(arguments,0),r=e.config(Na);return n.apply(undefined,[r].concat(t))},n)},premade:function(n){return fe.wrap(Ha,n)},getPremade:function(n){return fe.readOptFrom(n,Ha)}},ja=Kn([{required:["data"]},{external:["data"]},{optional:["data"]},{group:["data"]}]),Pa=We("factory",{sketch:c.identity}),La=We("schema",[]),Wa=Fe("name"),Ua=Ke("pname","pname",$n.defaultedThunk(function(n){return"<alloy."+Ia(n.name)+">"}),rt.anyValue()),za=We("defaults",c.constant({})),Ka=We("overrides",c.constant({})),Ga=rt.objOf([Pa,La,Wa,Ua,za,Ka]),$a=rt.objOf([Pa,La,Wa,za,Ka]),qa=rt.objOf([Pa,La,Wa,Ua,za,Ka]),_a=rt.objOf([Pa,La,Wa,Fe("unit"),Ua,za,Ka]),Xa=function(n,e){return function(t){var r=rt.asStructOrDie("Converting part type",e,t);return n(r)}},Ya={required:Xa(ja.required,Ga),external:Xa(ja.external,$a),optional:Xa(ja.optional,qa),group:Xa(ja.group,_a),asNamedPart:function(n){return n.fold(p.some,p.none,p.some,p.some)},name:function(n){var e=function(n){return n.name()};return n.fold(e,e,e,e)},asCommon:function(n){return n.fold(c.identity,c.identity,c.identity,c.identity)},original:c.constant("entirety")},Ja="placeholder",Qa=Kn([{single:["required","valueThunk"]},{multiple:["required","valueThunks"]}]),Za=function(n,e,t,r){return t.uiType===Ja?(i=t,u=r,(o=n).exists(function(n){return n!==i.owner})?Qa.single(!0,c.constant(i)):fe.readOptFrom(u,i.name).fold(function(){throw new Error("Unknown placeholder component: "+i.name+"\nKnown: ["+Hn.keys(u)+"]\nNamespace: "+o.getOr("none")+"\nSpec: "+de(i,null,2))},function(n){return n.replace()})):Qa.single(!1,c.constant(t));var o,i,u},nc=function(n,e,t,r){return Za(n,0,t,r).fold(function(o,i){var u=i(e,t.config,t.validated),a=fe.readOptFrom(u,"components").getOr([]),c=E.bind(a,function(t){return nc(n,e,t,r)});return[An.deepMerge(u,{components:c})]},function(n,r){return r(e,t.config,t.validated)})},ec=function(n,e,t,r){return E.bind(t,function(t){return nc(n,e,t,r)})},tc={single:Qa.single,multiple:Qa.multiple,isSubstitute:function(n){return E.contains([Ja],n)},placeholder:c.constant(Ja),substituteAll:ec,substitutePlaces:function(n,e,t,r){var o=Hn.map(r,function(n,e){return t=e,r=n,o=!1,{name:c.constant(t),required:function(){return r.fold(function(n,e){return n},function(n,e){return n})},used:function(){return o},replace:function(){if(!0===o)throw new Error("Trying to use the same placeholder more than once: "+t);return o=!0,r}};var t,r,o}),i=ec(n,e,t,o);return Hn.each(o,function(t){if(!1===t.used()&&t.required())throw new Error("Placeholder: "+t.name()+" was not found in components list\nNamespace: "+n.getOr("none")+"\nComponents: "+de(e.components(),null,2))}),i},singleReplace:function(n,e){return e.fold(function(e,t){return[t(n)]},function(e,t){return t(n)})}},rc=function(n,e,t,r){var o=t;return An.deepMerge(e.defaults()(n,t,r),t,{uid:n.partUids()[e.name()]},e.overrides()(n,t,r),{"debug.sketcher":fe.wrap("part-"+e.name(),o)})},oc=function(n,e,t){var r={},o={};return E.each(t,function(n){n.fold(function(n){r[n.pname()]=tc.single(!0,function(e,t,r){return n.factory().sketch(rc(e,n,t,r))})},function(n){var t=e.parts()[n.name()]();o[n.name()]=c.constant(rc(e,n,t[Ya.original()]()))},function(n){r[n.pname()]=tc.single(!1,function(e,t,r){return n.factory().sketch(rc(e,n,t,r))})},function(n){r[n.pname()]=tc.multiple(!0,function(e,t,r){var o=e[n.name()]();return E.map(o,function(t){return n.factory().sketch(An.deepMerge(n.defaults()(e,t),t,n.overrides()(e,t)))})})})}),{internals:c.constant(r),externals:c.constant(o)}},ic=function(n,e){return{uiType:tc.placeholder(),owner:n,name:e}},uc=function(n){return E.map(n,Ya.name)},ac=function(n,e,t){var r=e.partUids()[t];return n.getSystem().getByUid(r).toOption()},cc=function(n,e){var t=uc(e);return fe.wrapAll(E.map(t,function(e){return{key:e,value:n+"-"+e}}))},sc=function(n,e){var t={};return E.each(e,function(e){Ya.asNamedPart(e).each(function(e){var r=ic(n,e.pname());t[e.name()]=function(t){var o=rt.asRawOrDie("Part: "+e.name()+" in "+n,rt.objOf(e.schema()),t);return An.deepMerge(r,{config:t,validated:o})}})}),t},fc=function(n,e,t){return{uiType:tc.placeholder(),owner:n,name:e,config:t,validated:{}}},lc=function(n){return E.bind(n,function(n){return n.fold(p.none,p.some,p.none,p.none).map(function(n){return Ie(n.name(),n.schema().concat([Bo.snapshot(Ya.original())]))}).toArray()})},dc=function(n,e,t){return oc(n,e,t)},mc=function(n,e,t){return tc.substitutePlaces(p.some(n),e,e.components(),t)},pc=function(n){return Ke("partUids","partUids",$n.mergeWithThunk(function(e){return cc(e.uid,n)}),rt.anyValue())},gc=function(n,e){var t=n.getSystem();return Hn.map(e.partUids(),function(n,e){return c.constant(t.getByUid(n))})},hc=ac,vc=function(n,e,t){return ac(n,e,t).getOrDie("Could not find part: "+t)},yc={prefix:c.constant("alloy-id-"),idAttr:c.constant("data-alloy-id")},bc=yc.prefix(),wc=yc.idAttr(),Sc={revoke:function(n){Jt.remove(n,wc)},write:function(n,e){var t=Ia(bc+n);return Jt.set(e,wc,t),t},writeOnly:function(n,e){Jt.set(n,wc,e)},read:function(n){var e=$t.isElement(n)?Jt.get(n,wc):null;return p.from(e)},find:function(n,e){return vi(n,e)},generate:function(n){return Ia(n)},attribute:c.constant(wc)},xc=function(n,e,t,r){return(e.length>0?[Ie("parts",e)]:[]).concat([Fe("uid"),We("dom",{}),We("components",[]),Bo.snapshot("originalSpec"),We("debug.sketcher",{})]).concat(t)},Oc=function(n,e,t,r,o){var i=xc(0,r,o);return rt.asStructOrDie(n+" [SpecSchema]",rt.objOfOnly(i.concat(e)),t)},Tc=function(n){return An.deepMerge({uid:Sc.generate("uid")},n)},kc=function(n,e,t,r){var o=Tc(r),i=Oc(n,e,o,[],[]);return An.deepMerge(t(i,o),{"debug.sketcher":fe.wrap(n,r)})},Cc=function(n,e,t,r,o){var i=Tc(o),u=lc(t),a=pc(t),c=Oc(n,e,i,u,[a]),s=dc(n,c,t),f=mc(n,c,s.internals());return An.deepMerge(r(c,f,i,s.externals()),{"debug.sketcher":fe.wrap(n,o)})},Ec=rt.objOfOnly([Fe("name"),Fe("factory"),Fe("configFields"),We("apis",{}),We("extraApis",{})]),Dc=rt.objOfOnly([Fe("name"),Fe("factory"),Fe("configFields"),Fe("partFields"),We("apis",{}),We("extraApis",{})]),Ac=function(n){var e=rt.asRawOrDie("Sketcher for "+n.name,Ec,n),t=Hn.map(e.apis,Va.makeApi),r=Hn.map(e.extraApis,function(n,e){return mt(n,e)});return An.deepMerge({name:c.constant(e.name),partFields:c.constant([]),configFields:c.constant(e.configFields),sketch:function(n){return kc(e.name,e.configFields,e.factory,n)}},t,r)},Mc=function(n){var e=rt.asRawOrDie("Sketcher for "+n.name,Dc,n),t=sc(e.name,e.partFields),r=Hn.map(e.apis,Va.makeApi),o=Hn.map(e.extraApis,function(n,e){return mt(n,e)});return An.deepMerge({name:c.constant(e.name),partFields:c.constant(e.partFields),configFields:c.constant(e.configFields),sketch:function(n){return Cc(e.name,e.configFields,e.partFields,e.factory,n)},parts:c.constant(t)},r,o)},Rc=function(n){var e=function(n,e){e.stop(),Ln(n)},t=an.detect().deviceType.isTouch()?[lt.run(On.tap(),e)]:[lt.run(Sn.click(),e),lt.run(Sn.mousedown(),function(n,e){e.cut()})];return lt.derive(E.flatten([n.map(function(n){return lt.run(On.execute(),function(e,t){n(e),t.stop()})}).toArray(),t]))},Fc=Ac({name:"Button",factory:function(n,e){var t=Rc(n.action()),r=fe.readOptFrom(n.dom(),"attributes").bind(fe.readOpt("type")),o=fe.readOptFrom(n.dom(),"tag");return{uid:n.uid(),dom:n.dom(),components:n.components(),events:t,behaviours:An.deepMerge(jt.derive([oi.config({}),Ma.config({mode:"execution",useSpace:!0,useEnter:!0})]),Fa(n.buttonBehaviours())),domModification:{attributes:An.deepMerge(r.fold(function(){return o.is("button")?{type:"button"}:{}},function(n){return{}}),{role:n.role().getOr("button")})},eventOrder:n.eventOrder()}},configFields:[We("uid",undefined),Fe("dom"),We("components",[]),Ra("buttonBehaviours",[oi,Ma]),Ve("action"),Ve("role"),We("eventOrder",{})]}),Bc=function(n){var e,t,r,o=sn.fromHtml(n),i=Tr.children(o),u=(t=(e=o).dom().attributes!==undefined?e.dom().attributes:[],E.foldl(t,function(n,e){return"class"===e.name?n:An.deepMerge(n,fe.wrap(e.name,e.value))},{})),a=(r=o,Array.prototype.slice.call(r.dom().classList,0)),c=0===i.length?{}:{innerHtml:Wr(o)};return An.deepMerge({tag:$t.name(o),classes:a,attributes:u},c)},Ic=Bc,Hc=function(n){var e=J(n,{prefix:Qo.prefix()});return Ic(e)},Nc={dom:Hc,spec:function(n){return{dom:Hc(n)}}},Vc=function(n){return jt.derive([qo.config({toggleClass:Qo.resolve("toolbar-button-selected"),toggleOnExecute:!1,aria:{mode:"pressed"}}),_o(n,function(n,e){(e?qo.on:qo.off)(n)})])},jc=function(n,e,t){return Fc.sketch({dom:Nc.dom('<span class="${prefix}-toolbar-button ${prefix}-icon-'+n+' ${prefix}-icon"></span>'),action:e,buttonBehaviours:An.deepMerge(jt.derive([ni.config({})]),t)})},Pc={forToolbar:jc,forToolbarCommand:function(n,e){return jc(e,function(){n.execCommand(e)},{})},forToolbarStateAction:function(n,e,t,r){var o=Vc(t);return jc(e,r,o)},forToolbarStateCommand:function(n,e){var t=Vc(e);return jc(e,function(){n.execCommand(e)},t)}},Lc=function(n,e,t){return Math.max(e,Math.min(t,n))},Wc=function(n,e,t,r){return n<e?n:n>t?t:n===e?e-1:Math.max(e,n-r)},Uc=function(n,e,t,r){return n>t?n:n<e?e:n===t?t+1:Math.min(t,n+r)},zc=function(n,e,t,r,o,i,u){var a=t-e;if(r<n.left)return e-1;if(r>n.right)return t+1;var c,s,f,l,d=Math.min(n.right,Math.max(r,n.left))-n.left,m=Lc(d/n.width*a+e,e-1,t+1),p=Math.round(m);return i&&m>=e&&m<=t?(c=m,s=e,f=t,l=o,u.fold(function(){var n=c-s,e=Math.round(n/l)*l;return Lc(s+e,s-1,f+1)},function(n){var e=(c-n)%l,t=Math.round(e/l),r=Math.floor((c-n)/l),o=Math.floor((f-n)/l),i=n+Math.min(o,r+t)*l;return Math.max(n,i)})):p},Kc="slider.change.value",Gc=an.detect().deviceType.isTouch(),$c=function(n){var e;return(e=n.event().raw(),Gc&&e.touches!==undefined&&1===e.touches.length?p.some(e.touches[0]):Gc&&e.touches!==undefined?p.none():Gc||e.clientX===undefined?p.none():p.some(e)).map(function(n){return n.clientX})},qc=function(n,e){Pn(n,Kc,{value:e})},_c={setXFromEvent:function(n,e,t,r){return $c(r).map(function(r){var o,i,u,a;return o=n,u=r,a=zc(t,(i=e).min(),i.max(),u,i.stepSize(),i.snapToGrid(),i.snapStart()),qc(o,a),r})},setToLedge:function(n,e){qc(n,e.min()-1)},setToRedge:function(n,e){qc(n,e.max()+1)},moveLeftFromRedge:function(n,e){qc(n,e.max())},moveRightFromLedge:function(n,e){qc(n,e.min())},moveLeft:function(n,e){var t=Wc(e.value().get(),e.min(),e.max(),e.stepSize());qc(n,t)},moveRight:function(n,e){var t=Uc(e.value().get(),e.min(),e.max(),e.stepSize());qc(n,t)},changeEvent:c.constant(Kc)},Xc=an.detect().deviceType.isTouch(),Yc=function(n,e){return Ya.optional({name:n+"-edge",overrides:function(n){var t=lt.derive([lt.runActionExtra(Sn.touchstart(),e,[n])]),r=lt.derive([lt.runActionExtra(Sn.mousedown(),e,[n]),lt.runActionExtra(Sn.mousemove(),function(n,t){t.mouseIsDown().get()&&e(n,t)},[n])]);return{events:Xc?t:r}}})},Jc=[Yc("left",_c.setToLedge),Yc("right",_c.setToRedge),Ya.required({name:"thumb",defaults:c.constant({dom:{styles:{position:"absolute"}}}),overrides:function(n){return{events:lt.derive([lt.redirectToPart(Sn.touchstart(),n,"spectrum"),lt.redirectToPart(Sn.touchmove(),n,"spectrum"),lt.redirectToPart(Sn.touchend(),n,"spectrum")])}}}),Ya.required({schema:[Ge("mouseIsDown",function(){return uo(!1)})],name:"spectrum",overrides:function(n){var e=function(e,t){var r=e.element().dom().getBoundingClientRect();_c.setXFromEvent(e,n,r,t)},t=lt.derive([lt.run(Sn.touchstart(),e),lt.run(Sn.touchmove(),e)]),r=lt.derive([lt.run(Sn.mousedown(),e),lt.run(Sn.mousemove(),function(t,r){n.mouseIsDown().get()&&e(t,r)})]);return{behaviours:jt.derive(Xc?[]:[Ma.config({mode:"special",onLeft:function(e){return _c.moveLeft(e,n),p.some(!0)},onRight:function(e){return _c.moveRight(e,n),p.some(!0)}}),oi.config({})]),events:Xc?t:r}}})],Qc={onLoad:function(n,e,t){e.store().manager().onLoad(n,e,t)},onUnload:function(n,e,t){e.store().manager().onUnload(n,e,t)},setValue:function(n,e,t,r){e.store().manager().setValue(n,e,t,r)},getValue:function(n,e,t){return e.store().manager().getValue(n,e,t)}},Zc={events:function(n,e){var t=n.resetOnDom()?[lt.runOnAttached(function(t,r){Qc.onLoad(t,n,e)}),lt.runOnDetached(function(t,r){Qc.onUnload(t,n,e)})]:[Et(n,e,Qc.onLoad)];return lt.derive(t)}},ns={memory:function(){var n=uo(null);return It({set:n.set,get:n.get,isNotSet:function(){return null===n.get()},clear:function(){n.set(null)},readState:function(){return{mode:"memory",value:n.get()}}})},dataset:function(){var n=uo({});return It({readState:function(){return{mode:"dataset",dataset:n.get()}},set:n.set,get:n.get})},manual:function(){return It({readState:function(){}})},init:function(n){return n.store().manager().state(n)}},es=function(n,e,t,r){e.store().getDataKey(),t.set({}),e.store().setData()(n,r),e.onSetValue()(n,r)},ts=[Ve("initialValue"),Fe("getFallbackEntry"),Fe("getDataKey"),Fe("setData"),Bo.output("manager",{setValue:es,getValue:function(n,e,t){var r=e.store().getDataKey()(n),o=t.get();return fe.readOptFrom(o,r).fold(function(){return e.store().getFallbackEntry()(r)},function(n){return n})},onLoad:function(n,e,t){e.store().initialValue().each(function(r){es(n,e,t,r)})},onUnload:function(n,e,t){t.set({})},state:ns.dataset})],rs=[Fe("getValue"),We("setValue",c.noop),Ve("initialValue"),Bo.output("manager",{setValue:function(n,e,t,r){e.store().setValue()(n,r),e.onSetValue()(n,r)},getValue:function(n,e,t){return e.store().getValue()(n)},onLoad:function(n,e,t){e.store().initialValue().each(function(t){e.store().setValue()(n,t)})},onUnload:c.noop,state:Ht.init})],os=[Ve("initialValue"),Bo.output("manager",{setValue:function(n,e,t,r){t.set(r),e.onSetValue()(n,r)},getValue:function(n,e,t){return t.get()},onLoad:function(n,e,t){e.store().initialValue().each(function(n){t.isNotSet()&&t.set(n)})},onUnload:function(n,e,t){t.clear()},state:ns.memory})],is=[Ue("store",{mode:"memory"},rt.choose("mode",{memory:os,manual:rs,dataset:ts})),Bo.onHandler("onSetValue"),We("resetOnDom",!1)],us=jt.create({fields:is,name:"representing",active:Zc,apis:Qc,extra:{setValueFrom:function(n,e){var t=us.getValue(e);us.setValue(n,t)}},state:ns}),as=an.detect().deviceType.isTouch(),cs=[Fe("min"),Fe("max"),We("stepSize",1),We("onChange",c.noop),We("onInit",c.noop),We("onDragStart",c.noop),We("onDragEnd",c.noop),We("snapToGrid",!1),Ve("snapStart"),Fe("getInitialValue"),Ra("sliderBehaviours",[Ma,us]),Ge("value",function(n){return uo(n.min)})].concat(as?[]:[Ge("mouseIsDown",function(){return uo(!1)})]),ss=Gi("width",function(n){return n.dom().offsetWidth}),fs=function(n,e){ss.set(n,e)},ls=function(n){return ss.get(n)},ds=an.detect().deviceType.isTouch(),ms=Mc({name:"Slider",configFields:cs,partFields:Jc,factory:function(n,e,t,r){var o=n.max()-n.min(),i=function(n){var e=n.element().dom().getBoundingClientRect();return(e.left+e.right)/2},u=function(e){return vc(e,n,"thumb")},a=function(e){var t,r,u,a,c=vc(e,n,"spectrum").element().dom().getBoundingClientRect(),s=e.element().dom().getBoundingClientRect(),f=(t=e,r=c,(a=(u=n).value().get())<u.min()?hc(t,u,"left-edge").fold(function(){return 0},function(n){return i(n)-r.left}):a>u.max()?hc(t,u,"right-edge").fold(function(){return r.width},function(n){return i(n)-r.left}):(u.value().get()-u.min())/o*r.width);return c.left-s.left+f},s=function(n){var e=a(n),t=u(n),r=ls(t.element())/2;Ki.set(t.element(),"left",e-r+"px")},f=function(e,t){var r=n.value().get(),o=u(e);return r!==t||Ki.getRaw(o.element(),"left").isNone()?(n.value().set(t),s(e),n.onChange()(e,o,t),p.some(!0)):p.none()},l=ds?[lt.run(Sn.touchstart(),function(e,t){n.onDragStart()(e,u(e))}),lt.run(Sn.touchend(),function(e,t){n.onDragEnd()(e,u(e))})]:[lt.run(Sn.mousedown(),function(e,t){t.stop(),n.onDragStart()(e,u(e)),n.mouseIsDown().set(!0)}),lt.run(Sn.mouseup(),function(e,t){n.onDragEnd()(e,u(e)),n.mouseIsDown().set(!1)})];return{uid:n.uid(),dom:n.dom(),components:e,behaviours:An.deepMerge(jt.derive(E.flatten([ds?[]:[Ma.config({mode:"special",focusIn:function(e){return hc(e,n,"spectrum").map(Ma.focusIn).map(c.constant(!0))}})],[us.config({store:{mode:"manual",getValue:function(e){return n.value().get()}}})]])),Fa(n.sliderBehaviours())),events:lt.derive([lt.run(_c.changeEvent(),function(n,e){f(n,e.event().value())}),lt.runOnAttached(function(e,t){n.value().set(n.getInitialValue()());var r=u(e);s(e),n.onInit()(e,r,n.value().get())})].concat(l)),apis:{resetToMin:function(e){f(e,n.min())},resetToMax:function(e){f(e,n.max())},refresh:s},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)}}}),ps=function(n,e,t){return Pc.forToolbar(e,function(){var r=t();n.setContextToolbar([{label:e+" group",items:r}])},{})},gs=function(n){return[(e=n,t=function(n){return n<0?"black":n>360?"white":"hsl("+n+", 100%, 50%)"},ms.sketch({dom:Nc.dom('<div class="${prefix}-slider ${prefix}-hue-slider-container"></div>'),components:[ms.parts()["left-edge"](Nc.spec('<div class="${prefix}-hue-slider-black"></div>')),ms.parts().spectrum({dom:Nc.dom('<div class="${prefix}-slider-gradient-container"></div>'),components:[Nc.spec('<div class="${prefix}-slider-gradient"></div>')],behaviours:jt.derive([qo.config({toggleClass:Qo.resolve("thumb-active")})])}),ms.parts()["right-edge"](Nc.spec('<div class="${prefix}-hue-slider-white"></div>')),ms.parts().thumb({dom:Nc.dom('<div class="${prefix}-slider-thumb"></div>'),behaviours:jt.derive([qo.config({toggleClass:Qo.resolve("thumb-active")})])})],onChange:function(n,r,o){var i=t(o);Ki.set(r.element(),"background-color",i),e.onChange(n,r,i)},onDragStart:function(n,e){qo.on(e)},onDragEnd:function(n,e){qo.off(e)},onInit:function(n,e,r){var o=t(r);Ki.set(e.element(),"background-color",o)},stepSize:10,min:0,max:360,getInitialValue:e.getInitialValue,sliderBehaviours:jt.derive([Xo(ms.refresh)])}))];var e,t},hs=function(n,e){var t={onChange:function(n,t,r){e.undoManager.transact(function(){e.formatter.apply("forecolor",{value:r}),e.nodeChanged()})},getInitialValue:function(){return-1}};return ps(n,"color",function(){return gs(t)})},vs=rt.objOfOnly([Fe("getInitialValue"),Fe("onChange"),Fe("category"),Fe("sizes")]),ys=function(n){var e=rt.asRawOrDie("SizeSlider",vs,n);return ms.sketch({dom:{tag:"div",classes:[Qo.resolve("slider-"+e.category+"-size-container"),Qo.resolve("slider"),Qo.resolve("slider-size-container")]},onChange:function(n,t,r){var o;(o=r)>=0&&o<e.sizes.length&&e.onChange(r)},onDragStart:function(n,e){qo.on(e)},onDragEnd:function(n,e){qo.off(e)},min:0,max:e.sizes.length-1,stepSize:1,getInitialValue:e.getInitialValue,snapToGrid:!0,sliderBehaviours:jt.derive([Xo(ms.refresh)]),components:[ms.parts().spectrum({dom:Nc.dom('<div class="${prefix}-slider-size-container"></div>'),components:[Nc.spec('<div class="${prefix}-slider-size-line"></div>')]}),ms.parts().thumb({dom:Nc.dom('<div class="${prefix}-slider-thumb"></div>'),behaviours:jt.derive([qo.config({toggleClass:Qo.resolve("thumb-active")})])})]})},bs=function(n,e,t){for(var r=n.dom(),o=kn.isFunction(t)?t:c.constant(!1);r.parentNode;){r=r.parentNode;var i=sn.fromDom(r),u=e(i);if(u.isSome())return u;if(o(i))break}return p.none()},ws=function(n,e,t){return e(n).orThunk(function(){return t(n)?p.none():bs(n,e,t)})},Ss=["9px","10px","11px","12px","14px","16px","18px","20px","24px","32px","36px"],xs=function(n){var e,t,r=n.selection.getStart(),o=sn.fromDom(r),i=sn.fromDom(n.getBody()),u=(e=function(n){return bn(i,n)},t=o,($t.isElement(t)?p.some(t):Tr.parent(t)).map(function(n){return ws(n,function(n){return Ki.getRaw(n,"font-size")},e).getOrThunk(function(){return Ki.get(n,"font-size")})}).getOr(""));return E.find(Ss,function(n){return u===n}).getOr("medium")},Os={candidates:c.constant(Ss),get:function(n){var e,t=xs(n);return(e=t,E.findIndex(Ss,function(n){return n===e})).getOr(2)},apply:function(n,e){var t;(t=e,p.from(Ss[t])).each(function(e){var t,r;r=e,xs(t=n)!==r&&t.execCommand("fontSize",!1,r)})}},Ts=Os.candidates(),ks=function(n){return[Nc.spec('<span class="${prefix}-toolbar-button ${prefix}-icon-small-font ${prefix}-icon"></span>'),(e=n,ys({onChange:e.onChange,sizes:Ts,category:"font",getInitialValue:e.getInitialValue})),Nc.spec('<span class="${prefix}-toolbar-button ${prefix}-icon-large-font ${prefix}-icon"></span>')];var e},Cs=function(n,e){var t={onChange:function(n){Os.apply(e,n)},getInitialValue:function(){return Os.get(e)}};return ps(n,"font-size",function(){return ks(t)})},Es=function(n){var e=fe.hasKey(n,"uid")?n.uid:Sc.generate("memento");return{get:function(n){return n.getSystem().getByUid(e).getOrDie()},getOpt:function(n){return n.getSystem().getByUid(e).fold(p.none,p.some)},asSpec:function(){return An.deepMerge(n,{uid:e})}}};function Ds(n,e){return Ms(document.createElement("canvas"),n,e)}function As(n){return n.getContext("2d")}function Ms(n,e,t){return n.width=e,n.height=t,n}var Rs={create:Ds,clone:function(n){var e;return As(e=Ds(n.width,n.height)).drawImage(n,0,0),e},resize:Ms,get2dContext:As,get3dContext:function(n){var e=null;try{e=n.getContext("webgl")||n.getContext("experimental-webgl")}catch(t){}return e||(e=null),e}},Fs={getWidth:function(n){return n.naturalWidth||n.width},getHeight:function(n){return n.naturalHeight||n.height}},Bs=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=[],c(n,t(i,this),t(u,this))},e=n.immediateFn||"function"==typeof setImmediate&&setImmediate||function(n){setTimeout(n,1)};function t(n,e){return function(){n.apply(e,arguments)}}var r=Array.isArray||function(n){return"[object Array]"===Object.prototype.toString.call(n)};function o(n){var t=this;null!==this._state?e(function(){var e=t._state?n.onFulfilled:n.onRejected;if(null!==e){var r;try{r=e(t._value)}catch(o){return void n.reject(o)}n.resolve(r)}else(t._state?n.resolve:n.reject)(t._value)}):this._deferreds.push(n)}function i(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 c(t(e,n),t(i,this),t(u,this))}this._state=!0,this._value=n,a.call(this)}catch(r){u.call(this,r)}}function u(n){this._state=!1,this._value=n,a.call(this)}function a(){for(var n=0,e=this._deferreds.length;n<e;n++)o.call(this,this._deferreds[n]);this._deferreds=null}function c(n,e,t){var r=!1;try{n(function(n){r||(r=!0,e(n))},function(n){r||(r=!0,t(n))})}catch(o){if(r)return;r=!0,t(o)}}return n.prototype["catch"]=function(n){return this.then(null,n)},n.prototype.then=function(e,t){var r=this;return new n(function(n,i){o.call(r,new function(n,e,t,r){this.onFulfilled="function"==typeof n?n:null,this.onRejected="function"==typeof e?e:null,this.resolve=t,this.reject=r}(e,t,n,i))})},n.all=function(){var e=Array.prototype.slice.call(1===arguments.length&&r(arguments[0])?arguments[0]:arguments);return new n(function(n,t){if(0===e.length)return n([]);var r=e.length;function o(i,u){try{if(u&&("object"==typeof u||"function"==typeof u)){var a=u.then;if("function"==typeof a)return void a.call(u,function(n){o(i,n)},t)}e[i]=u,0==--r&&n(e)}catch(c){t(c)}}for(var i=0;i<e.length;i++)o(i,e[i])})},n.resolve=function(e){return e&&"object"==typeof e&&e.constructor===n?e:new n(function(n){n(e)})},n.reject=function(e){return new n(function(n,t){t(e)})},n.race=function(e){return new n(function(n,t){for(var r=0,o=e.length;r<o;r++)e[r].then(n,t)})},n}(),Is={atob:function(n){return R.getOrDie("atob")(n)},requestAnimationFrame:function(n){R.getOrDie("requestAnimationFrame")(n)}};function Hs(n){return new Bs(function(e,t){var r=URL.createObjectURL(n),o=new Image,i=function(){o.removeEventListener("load",u),o.removeEventListener("error",a)};function u(){i(),e(o)}function a(){i(),t("Unable to load data of type "+n.type+": "+r)}o.addEventListener("load",u),o.addEventListener("error",a),o.src=r,o.complete&&u()})}function Ns(n){return new Bs(function(e,t){var r=new XMLHttpRequest;r.open("GET",n,!0),r.responseType="blob",r.onload=function(){200==this.status&&e(this.response)},r.onerror=function(){var n,e=this;t(0===this.status?((n=new Error("No access to download image")).code=18,n.name="SecurityError",n):new Error("Error "+e.status+" downloading image"))},r.send()})}function Vs(n){var e=n.split(","),t=/data:([^;]+)/.exec(e[0]);if(!t)return p.none();for(var r,o,i,u=t[1],a=e[1],c=Is.atob(a),s=c.length,f=Math.ceil(s/1024),l=new Array(f),d=0;d<f;++d){for(var m=1024*d,g=Math.min(m+1024,s),h=new Array(g-m),v=m,y=0;v<g;++y,++v)h[y]=c[v].charCodeAt(0);l[d]=(r=h,new(R.getOrDie("Uint8Array"))(r))}return p.some((o=l,i={type:u},new(R.getOrDie("Blob"))(o,i)))}function js(n){return new Bs(function(e,t){Vs(n).fold(function(){t("uri is not base64: "+n)},e)})}function Ps(n){return new Bs(function(e){var t=new function(){return new(R.getOrDie("FileReader"))};t.onloadend=function(){e(t.result)},t.readAsDataURL(n)})}var Ls={blobToImage:Hs,imageToBlob:function(n){return(e=n,new Bs(function(n){e.complete?n(e):e.addEventListener("load",function t(){e.removeEventListener("load",t),n(e)})})).then(function(n){var e=n.src;return 0===e.indexOf("blob:")?Ns(e):0===e.indexOf("data:")?js(e):Ns(e)});var e},blobToDataUri:Ps,blobToBase64:function(n){return Ps(n).then(function(n){return n.split(",")[1]})},dataUriToBlobSync:Vs,canvasToBlob:function(n,e,t){return e=e||"image/png",HTMLCanvasElement.prototype.toBlob?new Bs(function(r){n.toBlob(function(n){r(n)},e,t)}):js(n.toDataURL(e,t))},canvasToDataURL:function(n,e,t){return e=e||"image/png",n.then(function(n){return n.toDataURL(e,t)})},blobToCanvas:function(n){return Hs(n).then(function(n){var e,t;return e=n,URL.revokeObjectURL(e.src),t=Rs.create(Fs.getWidth(n),Fs.getHeight(n)),Rs.get2dContext(t).drawImage(n,0,0),t})},uriToBlob:function(n){return 0===n.indexOf("blob:")?Ns(n):0===n.indexOf("data:")?js(n):null}},Ws=function(n){return Ls.blobToBase64(n)},Us=function(n){var e=Es({dom:{tag:"input",attributes:{accept:"image/*",type:"file",title:""},styles:{visibility:"hidden",position:"absolute"}},events:lt.derive([lt.cutter(Sn.click()),lt.run(Sn.change(),function(e,t){var r,o,i;(r=t,o=r.event(),i=o.raw().target.files||o.raw().dataTransfer.files,p.from(i[0])).each(function(e){var t,r;t=n,Ws(r=e).then(function(n){t.undoManager.transact(function(){var e=t.editorUpload.blobCache,o=e.create(Ia("mceu"),r,n);e.add(o);var i=t.dom.createHTML("img",{src:o.blobUri()});t.insertContent(i)})})})})])});return Fc.sketch({dom:Nc.dom('<span class="${prefix}-toolbar-button ${prefix}-icon-image ${prefix}-icon"></span>'),components:[e.asSpec()],action:function(n){e.get(n).element().dom().click()}})},zs=function(n){return n.dom().textContent},Ks=function(n,e){n.dom().textContent=e},Gs=function(n){return n.length>0},$s=function(n){return n===undefined||null===n?"":n},qs=function(n,e,t){return t.text.filter(Gs).fold(function(){return Jt.get(t=n,"href")===zs(t)?p.some(e):p.none();var t},p.some)},_s=function(n){var e=sn.fromDom(n.selection.getStart());return yi(e,"a")},Xs={getInfo:function(n){return _s(n).fold(function(){return{url:"",text:n.selection.getContent({format:"text"}),title:"",target:"",link:p.none()}},function(n){return t=zs(e=n),r=Jt.get(e,"href"),o=Jt.get(e,"title"),i=Jt.get(e,"target"),{url:$s(r),text:t!==r?$s(t):"",title:$s(o),target:$s(i),link:p.some(e)};var e,t,r,o,i})},applyInfo:function(n,e){e.url.filter(Gs).fold(function(){var t;t=n,e.link.bind(c.identity).each(function(n){t.execCommand("unlink")})},function(t){var r,o,i=(r=e,(o={}).href=t,r.title.filter(Gs).each(function(n){o.title=n}),r.target.filter(Gs).each(function(n){o.target=n}),o);e.link.bind(c.identity).fold(function(){var r=e.text.filter(Gs).getOr(t);n.insertContent(n.dom.createHTML("a",i,n.dom.encode(r)))},function(n){var r=qs(n,t,e);Jt.setAll(n,i),r.each(function(e){Ks(n,e)})})})},query:_s},Ys=function(n,e){var t=lt.derive(e);return jt.create({fields:[Fe("enabled")],name:n,active:{events:c.constant(t)}})},Js={events:Ys,config:function(n,e){return{key:n,value:{config:{},me:Ys(n,e),configAsRaw:c.constant({}),initialConfig:{},state:jt.noState()}}}},Qs={getCurrent:function(n,e,t){return e.find()(n)}},Zs=[Fe("find")],nf=jt.create({fields:Zs,name:"composing",apis:Qs}),ef=Ac({name:"Container",factory:function(n,e){return{uid:n.uid(),dom:An.deepMerge({tag:"div",attributes:{role:"presentation"}},n.dom()),components:n.components(),behaviours:Fa(n.containerBehaviours()),events:n.events(),domModification:n.domModification(),eventOrder:n.eventOrder()}},configFields:[We("components",[]),Ra("containerBehaviours",[]),We("events",{}),We("domModification",{}),We("eventOrder",{})]}),tf=Ac({name:"DataField",factory:function(n,e){return{uid:n.uid(),dom:n.dom(),behaviours:An.deepMerge(jt.derive([us.config({store:{mode:"memory",initialValue:n.getInitialValue()()}}),nf.config({find:p.some})]),Fa(n.dataBehaviours())),events:lt.derive([lt.runOnAttached(function(e,t){us.setValue(e,n.getInitialValue()())})])}},configFields:[Fe("uid"),Fe("dom"),Fe("getInitialValue"),Ra("dataBehaviours",[us,nf])]}),rf=function(n,e){if(e===undefined)throw new Error("Value.set was undefined");n.dom().value=e},of=function(n){return n.dom().value},uf=[Ve("data"),We("inputAttributes",{}),We("inputStyles",{}),We("type","input"),We("tag","input"),We("inputClasses",[]),Bo.onHandler("onSetValue"),We("styles",{}),Ve("placeholder"),We("eventOrder",{}),Ra("inputBehaviours",[us,oi]),We("selectOnFocus",!0)],af={schema:c.constant(uf),behaviours:function(n){return An.deepMerge(jt.derive([us.config({store:{mode:"manual",initialValue:n.data().getOr(undefined),getValue:function(n){return of(n.element())},setValue:function(n,e){of(n.element())!==e&&rf(n.element(),e)}},onSetValue:n.onSetValue()}),oi.config({onFocus:!1===n.selectOnFocus()?c.noop:function(n){var e=n.element(),t=of(e);e.dom().setSelectionRange(0,t.length)}})]),Fa(n.inputBehaviours()))},dom:function(n){return{tag:n.tag(),attributes:An.deepMerge(fe.wrapAll([{key:"type",value:n.type()}].concat(n.placeholder().map(function(n){return{key:"placeholder",value:n}}).toArray())),n.inputAttributes()),styles:n.inputStyles(),classes:n.inputClasses()}}},cf=Ac({name:"Input",configFields:af.schema(),factory:function(n,e){return{uid:n.uid(),dom:af.dom(n),components:[],behaviours:af.behaviours(n),eventOrder:n.eventOrder()}}}),sf={exhibit:function(n,e){return Ot.nu({attributes:fe.wrapAll([{key:e.tabAttr(),value:"true"}])})}},ff=[We("tabAttr","data-alloy-tabstop")],lf=jt.create({fields:ff,name:"tabstopping",active:sf}),df=function(n,e){var t=Es(cf.sketch({placeholder:e,onSetValue:function(n,e){jn(n,Sn.input())},inputBehaviours:jt.derive([nf.config({find:p.some}),lf.config({}),Ma.config({mode:"execution"})]),selectOnFocus:!1})),r=Es(Fc.sketch({dom:Nc.dom('<button class="${prefix}-input-container-x ${prefix}-icon-cancel-circle ${prefix}-icon"></button>'),action:function(n){var e=t.get(n);us.setValue(e,"")}}));return{name:n,spec:ef.sketch({dom:Nc.dom('<div class="${prefix}-input-container"></div>'),components:[t.asSpec(),r.asSpec()],containerBehaviours:jt.derive([qo.config({toggleClass:Qo.resolve("input-container-empty")}),nf.config({find:function(n){return p.some(t.get(n))}}),Js.config("input-clearing",[lt.run(Sn.input(),function(n){var e=t.get(n);(us.getValue(e).length>0?qo.off:qo.on)(n)})])])})}},mf=function(n){return{name:n,spec:tf.sketch({dom:{tag:"span",styles:{display:"none"}},getInitialValue:function(){return p.none()}})}},pf=["input","button","textarea"],gf=function(n){return E.contains(pf,$t.name(n.element()))},hf=function(n){Jt.set(n.element(),"disabled","disabled")},vf=function(n){Jt.remove(n.element(),"disabled")},yf=function(n){Jt.set(n.element(),"aria-disabled","true")},bf=function(n){Jt.set(n.element(),"aria-disabled","false")},wf=function(n,e,t){e.disableClass().each(function(e){lr.add(n.element(),e)}),(gf(n)?hf:yf)(n)},Sf={enable:function(n,e,t){e.disableClass().each(function(e){lr.remove(n.element(),e)}),(gf(n)?vf:bf)(n)},disable:wf,isDisabled:function(n){return gf(n)?Jt.has(n.element(),"disabled"):"true"===Jt.get(n.element(),"aria-disabled")},onLoad:function(n,e,t){e.disabled()&&wf(n,e,t)}},xf={exhibit:function(n,e,t){return Ot.nu({classes:e.disabled()?e.disableClass().map(E.pure).getOr([]):[]})},events:function(n,e){return lt.derive([lt.abort(On.execute(),function(t,r){return Sf.isDisabled(t,n,e)}),Et(n,e,Sf.onLoad)])}},Of=[We("disabled",!1),Ve("disableClass")],Tf=jt.create({fields:Of,name:"disabling",active:xf,apis:Sf}),kf=[Ra("formBehaviours",[us])],Cf=function(n){return"<alloy.field."+n+">"},Ef=function(n,e,t){return An.deepMerge({"debug.sketcher":{Form:t},uid:n.uid(),dom:n.dom(),components:e,behaviours:An.deepMerge(jt.derive([us.config({store:{mode:"manual",getValue:function(e){var t=gc(e,n);return Hn.map(t,function(n,e){return n().bind(nf.getCurrent).map(us.getValue)})},setValue:function(e,t){Hn.each(t,function(t,r){hc(e,n,r).each(function(n){nf.getCurrent(n).each(function(n){us.setValue(n,t)})})})}}})]),Fa(n.formBehaviours())),apis:{getField:function(e,t){return hc(e,n,t).bind(nf.getCurrent)}}})},Df=(Va.makeApi(function(n,e,t){return n.getField(e,t)}),function(n){var e,t=(e=[],{field:function(n,t){return e.push(n),fc("form",Cf(n),t)},record:function(){return e}}),r=n(t),o=t.record(),i=E.map(o,function(n){return Ya.required({name:n,pname:Cf(n)})});return Cc("form",kf,i,Ef,r)}),Af=function(n){var e=uo(p.none()),t=function(){e.get().each(n)};return{clear:function(){t(),e.set(p.none())},isSet:function(){return e.get().isSome()},set:function(n){t(),e.set(p.some(n))}}},Mf={destroyable:function(){return Af(function(n){n.destroy()})},unbindable:function(){return Af(function(n){n.unbind()})},api:function(){var n=uo(p.none()),e=function(){n.get().each(function(n){n.destroy()})};return{clear:function(){e(),n.set(p.none())},isSet:function(){return n.get().isSome()},set:function(t){e(),n.set(p.some(t))},run:function(e){n.get().each(e)}}},value:function(){var n=uo(p.none());return{clear:function(){n.set(p.none())},set:function(e){n.set(p.some(e))},isSet:function(){return n.get().isSome()},on:function(e){n.get().each(e)}}}},Rf=function(n){return{xValue:n,points:[]}},Ff=function(n,e){if(e===n.xValue)return n;var t=e-n.xValue>0?1:-1,r={direction:t,xValue:e};return{xValue:e,points:(0===n.points.length?[]:n.points[n.points.length-1].direction===t?n.points.slice(0,n.points.length-1):n.points).concat([r])}},Bf=function(n){if(0===n.points.length)return 0;var e=n.points[0].direction,t=n.points[n.points.length-1].direction;return-1===e&&-1===t?-1:1===e&&1===t?1:0},If=function(n){var e="navigateEvent",t=rt.objOf([Fe("fields"),We("maxFieldIndex",n.fields.length-1),Fe("onExecute"),Fe("getInitialValue"),Ge("state",function(){return{dialogSwipeState:Mf.value(),currentScreen:uo(0)}})]),r=rt.asRawOrDie("SerialisedDialog",t,n),o=function(n,t,r){return Fc.sketch({dom:Nc.dom('<span class="${prefix}-icon-'+t+' ${prefix}-icon"></span>'),action:function(t){Pn(t,e,{direction:n})},buttonBehaviours:jt.derive([Tf.config({disableClass:Qo.resolve("toolbar-navigation-disabled"),disabled:!r})])})},i=function(n,e){var t=mi(n.element(),"."+Qo.resolve("serialised-dialog-screen"));vi(n.element(),"."+Qo.resolve("serialised-dialog-chain")).each(function(n){r.state.currentScreen.get()+e>=0&&r.state.currentScreen.get()+e<t.length&&(Ki.getRaw(n,"left").each(function(r){var o=parseInt(r,10),i=ls(t[0]);Ki.set(n,"left",o-e*i+"px")}),r.state.currentScreen.set(r.state.currentScreen.get()+e))})},u=function(n){var e=mi(n.element(),"input");p.from(e[r.state.currentScreen.get()]).each(function(e){n.getSystem().getByDom(e).each(function(e){zn(n,e.element())})});var t=c.get(n);Di.highlightAt(t,r.state.currentScreen.get())},a=Es(Df(function(n){return{dom:Nc.dom('<div class="${prefix}-serialised-dialog"></div>'),components:[ef.sketch({dom:Nc.dom('<div class="${prefix}-serialised-dialog-chain" style="left: 0px; position: absolute;"></div>'),components:E.map(r.fields,function(e,t){return t<=r.maxFieldIndex?ef.sketch({dom:Nc.dom('<div class="${prefix}-serialised-dialog-screen"></div>'),components:E.flatten([[o(-1,"previous",t>0)],[n.field(e.name,e.spec)],[o(1,"next",t<r.maxFieldIndex)]])}):n.field(e.name,e.spec)})})],formBehaviours:jt.derive([Xo(function(n,e){var t;t=e,vi(n.element(),"."+Qo.resolve("serialised-dialog-chain")).each(function(n){Ki.set(n,"left",-r.state.currentScreen.get()*t.width+"px")})}),Ma.config({mode:"special",focusIn:function(n){u(n)},onTab:function(n){return i(n,1),p.some(!0)},onShiftTab:function(n){return i(n,-1),p.some(!0)}}),Js.config("form-events",[lt.runOnAttached(function(n,e){r.state.currentScreen.set(0),r.state.dialogSwipeState.clear();var t=c.get(n);Di.highlightFirst(t),r.getInitialValue(n).each(function(e){us.setValue(n,e)})}),lt.runOnExecute(r.onExecute),lt.run(Sn.transitionend(),function(n,e){"left"===e.event().raw().propertyName&&u(n)}),lt.run(e,function(n,e){var t=e.event().direction();i(n,t)})])])}})),c=Es({dom:Nc.dom('<div class="${prefix}-dot-container"></div>'),behaviours:jt.derive([Di.config({highlightClass:Qo.resolve("dot-active"),itemClass:Qo.resolve("dot-item")})]),components:E.bind(r.fields,function(n,e){return e<=r.maxFieldIndex?[Nc.spec('<div class="${prefix}-dot-item ${prefix}-icon-full-dot ${prefix}-icon"></div>')]:[]})});return{dom:Nc.dom('<div class="${prefix}-serializer-wrapper"></div>'),components:[a.asSpec(),c.asSpec()],behaviours:jt.derive([Ma.config({mode:"special",focusIn:function(n){var e=a.get(n);Ma.focusIn(e)}}),Js.config("serializer-wrapper-events",[lt.run(Sn.touchstart(),function(n,e){r.state.dialogSwipeState.set(Rf(e.event().raw().touches[0].clientX))}),lt.run(Sn.touchmove(),function(n,e){r.state.dialogSwipeState.on(function(n){e.event().prevent(),r.state.dialogSwipeState.set(Ff(n,e.event().raw().touches[0].clientX))})}),lt.run(Sn.touchend(),function(n){r.state.dialogSwipeState.on(function(e){var t=a.get(n),r=-1*Bf(e);i(t,r)})})])])}},Hf=an.detect(),Nf=function(n,e){var t=e.selection.getRng();n(),e.selection.setRng(t)},Vf=function(n,e){(Hf.os.isAndroid()?Nf:c.apply)(e,n)},jf=F(function(n,e){return[{label:"the link group",items:[If({fields:[df("url","Type or paste URL"),df("text","Link text"),df("title","Link title"),df("target","Link target"),mf("link")],maxFieldIndex:["url","text","title","target"].length-1,getInitialValue:function(){return p.some(Xs.getInfo(e))},onExecute:function(t){var r=us.getValue(t);Xs.applyInfo(e,r),n.restoreToolbar(),e.focus()}})]}]}),Pf=function(n,e){return Pc.forToolbarStateAction(e,"link","link",function(){var t=jf(n,e);n.setContextToolbar(t),Vf(e,function(){n.focusToolbar()}),Xs.query(e).each(function(n){e.selection.select(n.dom())})})},Lf=[{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"}]}],Wf=function(n,e,t,r){return fe.readOptFrom(e.routes(),r.start()).map(c.apply).bind(function(n){return fe.readOptFrom(n,r.destination()).map(c.apply)})},Uf=function(n,e,t,r){return Wf(0,e,0,r).bind(function(n){return n.transition().map(function(e){return{transition:c.constant(e),route:c.constant(n)}})})},zf=function(n,e,t){var r,o,i;(r=n,o=e,i=t,Kf(r,o,i).bind(function(n){return Uf(r,o,i,n)})).each(function(t){var r=t.transition();lr.remove(n.element(),r.transitionClass()),Jt.remove(n.element(),e.destinationAttr())})},Kf=function(n,e,t){var r=n.element();return Jt.has(r,e.destinationAttr())?p.some({start:c.constant(Jt.get(n.element(),e.stateAttr())),destination:c.constant(Jt.get(n.element(),e.destinationAttr()))}):p.none()},Gf=function(n,e,t,r){zf(n,e,t),Jt.has(n.element(),e.stateAttr())&&Jt.get(n.element(),e.stateAttr())!==r&&e.onFinish()(n,r),Jt.set(n.element(),e.stateAttr(),r)},$f={findRoute:Wf,disableTransition:zf,getCurrentRoute:Kf,jumpTo:Gf,progressTo:function(n,e,t,r){var o,i;i=e,Jt.has((o=n).element(),i.destinationAttr())&&(Jt.set(o.element(),i.stateAttr(),Jt.get(o.element(),i.destinationAttr())),Jt.remove(o.element(),i.destinationAttr()));var u,a,s,f=(u=n,a=e,s=r,{start:c.constant(Jt.get(u.element(),a.stateAttr())),destination:c.constant(s)});Uf(n,e,t,f).fold(function(){Gf(n,e,t,r)},function(o){zf(n,e,t);var i=o.transition();lr.add(n.element(),i.transitionClass()),Jt.set(n.element(),e.destinationAttr(),r)})},getState:function(n,e,t){var r=n.element();return Jt.has(r,e.stateAttr())?p.some(Jt.get(r,e.stateAttr())):p.none()}},qf={events:function(n,e){return lt.derive([lt.run(Sn.transitionend(),function(t,r){var o=r.event().raw();$f.getCurrentRoute(t,n,e).each(function(r){$f.findRoute(t,n,e,r).each(function(i){i.transition().each(function(i){o.propertyName===i.property()&&($f.jumpTo(t,n,e,r.destination()),n.onTransition()(t,r))})})})}),lt.runOnAttached(function(t,r){$f.jumpTo(t,n,e,n.initialState())})])}},_f=[We("destinationAttr","data-transitioning-destination"),We("stateAttr","data-transitioning-state"),Fe("initialState"),Bo.onHandler("onTransition"),Bo.onHandler("onFinish"),Be("routes",rt.setOf(Xn.value,rt.setOf(Xn.value,rt.objOfOnly([Le("transition",[Fe("property"),Fe("transitionClass")])]))))],Xf=jt.create({fields:_f,name:"transitioning",active:qf,apis:$f,extra:{createRoutes:function(n){var e={};return Hn.each(n,function(n,t){var r=t.split("<->");e[r[0]]=fe.wrap(r[1],n),e[r[1]]=fe.wrap(r[0],n)}),e},createBistate:function(n,e,t){return fe.wrapAll([{key:n,value:fe.wrap(e,t)},{key:e,value:fe.wrap(n,t)}])},createTristate:function(n,e,t,r){return fe.wrapAll([{key:n,value:fe.wrapAll([{key:e,value:r},{key:t,value:r}])},{key:e,value:fe.wrapAll([{key:n,value:r},{key:t,value:r}])},{key:t,value:fe.wrapAll([{key:n,value:r},{key:e,value:r}])}])}}}),Yf=function(n,e){var t=E.map(e,function(n){return Ke(n.name(),n.name(),$n.asOption(),rt.objOf([Fe("config"),We("state",Ht)]))}),r=rt.asStruct("component.behaviours",rt.objOf(t),n.behaviours).fold(function(e){throw new Error(rt.formatError(e)+"\nComplete spec:\n"+de(n,null,2))},c.identity);return{list:e,data:Hn.map(r,function(n){var e=n();return c.constant(e.map(function(n){return{config:n.config(),state:n.state().init(n.config())}}))})}},Jf=function(n){return n.list},Qf=function(n){return n.data},Zf=function(n,e){return Yf(n,e)},nl=function(n){var e,t,r,o=(e=n,t=fe.readOptFrom(e,"behaviours").getOr({}),r=E.filter(Hn.keys(t),function(n){return t[n]!==undefined}),E.map(r,function(n){return e.behaviours[n].me}));return Zf(n,o)},el=Bt.exactly(["getSystem","config","hasConfigured","spec","connect","disconnect","element","syncComponents","readState","components","events"]),tl=Bt.exactly(["debugInfo","triggerFocus","triggerEvent","triggerEscape","addToWorld","removeFromWorld","addToGui","removeFromGui","build","getByUid","getByDom","broadcast","broadcastOn"]);function rl(n){var e=function(e){return function(){throw new Error("The component must be in a context to send: "+e+"\n"+qr.element(n().element())+" is not in context.")}};return tl({debugInfo:c.constant("fake"),triggerEvent:e("triggerEvent"),triggerFocus:e("triggerFocus"),triggerEscape:e("triggerEscape"),build:e("build"),addToWorld:e("addToWorld"),removeFromWorld:e("removeFromWorld"),addToGui:e("addToGui"),removeFromGui:e("removeFromGui"),getByUid:e("getByUid"),getByDom:e("getByDom"),broadcast:e("broadcast"),broadcastOn:e("broadcastOn")})}var ol,il,ul,al,cl,sl=function(n,e){var t={};return Hn.each(n,function(n,r){Hn.each(n,function(n,o){var i=fe.readOr(o,[])(t);t[o]=i.concat([e(r,n)])})}),t},fl=function(n,e){return{name:c.constant(n),modification:e}},ll=function(n,e,t){return n.length>1?Xn.error('Multiple behaviours have tried to change DOM "'+e+'". The guilty behaviours are: '+de(E.map(n,function(n){return n.name()}))+". At this stage, this is not supported. Future releases might provide strategies for resolving this."):0===n.length?Xn.value({}):Xn.value(n[0].modification().fold(function(){return{}},function(n){return fe.wrap(e,n)}))},dl=function(n,e){return E.foldl(n,function(t,r){var o=r.modification().getOr({});return t.bind(function(t){var r=Hn.mapToArray(o,function(r,o){return t[o]!==undefined?(i=e,u=o,a=n,Xn.error("Mulitple behaviours have tried to change the _"+u+'_ "'+i+'". The guilty behaviours are: '+de(E.bind(a,function(n){return n.modification().getOr({})[u]!==undefined?[n.name()]:[]}),null,2)+". This is not currently supported.")):Xn.value(fe.wrap(o,r));var i,u,a});return fe.consolidate(r,t)})},Xn.value({})).map(function(n){return fe.wrap(e,n)})},ml={classes:function(n,e){var t=E.bind(n,function(n){return n.modification().getOr([])});return Xn.value(fe.wrap(e,t))},attributes:dl,styles:dl,domChildren:ll,defChildren:ll,innerHtml:ll,value:ll},pl=function(n,e,t,r){var o=An.deepMerge({},e);E.each(t,function(e){o[e.name()]=e.exhibit(n,r)});var i=sl(o,fl),u=Hn.map(i,function(n,e){return E.bind(n,function(n){return n.modification().fold(function(){return[]},function(e){return[n]})})}),a=Hn.mapToArray(u,function(n,e){return fe.readOptFrom(ml,e).fold(function(){return Xn.error("Unknown field type: "+e)},function(t){return t(n,e)})});return fe.consolidate(a,{}).map(Ot.nu)},gl=function(n,e,t,r){var o=t.slice(0);try{var i=o.sort(function(t,o){var i=t[e](),u=o[e](),a=r.indexOf(i),c=r.indexOf(u);if(-1===a)throw new Error("The ordering for "+n+" does not have an entry for "+i+".\nOrder specified: "+de(r,null,2));if(-1===c)throw new Error("The ordering for "+n+" does not have an entry for "+u+".\nOrder specified: "+de(r,null,2));return a<c?-1:c<a?1:0});return Xn.value(i)}catch(u){return Xn.error([u])}},hl={nu:function(n,e){return{handler:n,purpose:c.constant(e)}},curryArgs:function(n,e){return{handler:c.curry.apply(undefined,[n.handler].concat(e)),purpose:n.purpose}},getHandler:function(n){return n.handler}},vl=function(n,e){return{name:c.constant(n),handler:c.constant(e)}},yl=function(n,e,t){var r,o,i,u=An.deepMerge(t,(r=e,o=n,i={},E.each(r,function(n){i[n.name()]=n.handlers(o)}),i));return sl(u,vl)},bl=function(n,e,t){var r,o,i=e[t];return i?gl("Event: "+t,"name",n,i).map(function(n){var e=E.map(n,function(n){return n.handler()});return ut(e)}):(r=t,o=n,new Xn.error(["The event ("+r+') has more than one behaviour that listens to it.\nWhen this occurs, you must specify an event ordering for the behaviours in your spec (e.g. [ "listing", "toggling" ]).\nThe behaviours that can trigger it are: '+de(E.map(o,function(n){return n.name()}),null,2)]))},wl=function(n,e){var t=Hn.mapToArray(n,function(n,t){return(1===n.length?Xn.value(n[0].handler()):bl(n,e,t)).map(function(r){var o,i=(o=it(r),function(n,e){var t=Array.prototype.slice.call(arguments,0);o.abort.apply(undefined,t)?e.stop():o.can.apply(undefined,t)&&o.run.apply(undefined,t)}),u=n.length>1?E.filter(e,function(e){return E.contains(n,function(n){return n.name()===e})}).join(" > "):n[0].name();return fe.wrap(t,hl.nu(i,u))})});return fe.consolidate(t,{})},Sl=function(n,e,t,r){var o=yl(n,t,r);return wl(o,e)},xl=function(n){return rt.asStruct("custom.definition",rt.objOfOnly([Ke("dom","dom",$n.strict(),rt.objOfOnly([Fe("tag"),We("styles",{}),We("classes",[]),We("attributes",{}),Ve("value"),Ve("innerHtml")])),Fe("components"),Fe("uid"),We("events",{}),We("apis",c.constant({})),Ke("eventOrder","eventOrder",$n.mergeWith({"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"]}),rt.anyValue()),Ve("domModification"),Bo.snapshot("originalSpec"),We("debug.sketcher","unknown")]),n)},Ol=function(n){var e,t={tag:n.dom().tag(),classes:n.dom().classes(),attributes:An.deepMerge((e=n,fe.wrap(yc.idAttr(),e.uid())),n.dom().attributes()),styles:n.dom().styles(),domChildren:E.map(n.components(),function(n){return n.element()})};return bt.nu(An.deepMerge(t,n.dom().innerHtml().map(function(n){return fe.wrap("innerHtml",n)}).getOr({}),n.dom().value().map(function(n){return fe.wrap("value",n)}).getOr({})))},Tl=function(n){return n.domModification().fold(function(){return Ot.nu({})},Ot.nu)},kl=function(n){return n.events()},Cl={add:function(n,e){E.each(e,function(e){lr.add(n,e)})},remove:function(n,e){E.each(e,function(e){lr.remove(n,e)})},toggle:function(n,e){E.each(e,function(e){lr.toggle(n,e)})},hasAll:function(n,e){return E.forall(e,function(e){return lr.has(n,e)})},hasAny:function(n,e){return E.exists(e,function(e){return lr.has(n,e)})},get:function(n){return sr(n)?function(n){for(var e=n.dom().classList,t=new Array(e.length),r=0;r<e.length;r++)t[r]=e.item(r);return t}(n):ir(n)}},El=function(n){var e=sn.fromTag(n.tag());Jt.setAll(e,n.attributes().getOr({})),Cl.add(e,n.classes().getOr([])),Ki.setAll(e,n.styles().getOr({})),Ur(e,n.innerHtml().getOr(""));var t=function(n){if(n.domChildren().isSome()&&n.defChildren().isSome())throw new Error("Cannot specify children and child specs! Must be one or the other.\nDef: "+bt.defToStr(n));return n.domChildren().fold(function(){var e=n.defChildren().getOr([]);return E.map(e,Dl)},function(n){return n})}(n);return Dr.append(e,t),n.value().each(function(n){rf(e,n)}),e},Dl=function(n){var e=bt.nu(n);return El(e)},Al=El,Ml=function(n){var e=function(){return h},t=uo(rl(e)),r=rt.getOrDie(xl(An.deepMerge(n,{behaviours:undefined}))),o=nl(n),i=Jf(o),u=Qf(o),a=Ol(r),s={"alloy.base.modification":Tl(r)},f=pl(u,s,i,a).getOrDie(),l=Ot.merge(a,f),d=Al(l),m={"alloy.base.behaviour":kl(r)},p=Sl(u,r.eventOrder(),i,m).getOrDie(),g=uo(r.components()),h=el({getSystem:t.get,config:function(e){if(e===Va.apiConfig())return r.apis();var t=u;return(kn.isFunction(t[e.name()])?t[e.name()]:function(){throw new Error("Could not find "+e.name()+" in "+de(n,null,2))})()},hasConfigured:function(n){return kn.isFunction(u[n.name()])},spec:c.constant(n),readState:function(n){return u[n]().map(function(n){return n.state.readState()}).getOr("not enabled")},connect:function(n){t.set(n)},disconnect:function(){t.set(rl(e))},element:c.constant(d),syncComponents:function(){var n=Tr.children(d),e=E.bind(n,function(n){return t.get().getByDom(n).fold(function(){return[]},function(n){return[n]})});g.set(e)},components:g.get,events:c.constant(p)});return h},Rl={events:lt.derive([lt.can(On.focus(),function(n,e){var t,r,o=e.event().originator(),i=e.event().target();return r=i,!(bn(t=o,n.element())&&!bn(t,r)&&(console.warn(On.focus()+" did not get interpreted by the desired target. \nOriginator: "+qr.element(o)+"\nTarget: "+qr.element(i)+"\nCheck the "+On.focus()+" event handlers"),1))})])},Fl=function(n){return n},Bl=function(n){var e,t,r=Fl(n),o=(e=r,t=fe.readOr("components",[])(e),E.map(t,Hl)),i=An.deepMerge(Rl,r,fe.wrap("components",o));return Xn.value(Ml(i))},Il=function(n){var e=rt.asStructOrDie("external.component",rt.objOfOnly([Fe("element"),Ve("uid")]),n),t=uo(rl());e.uid().each(function(n){Sc.writeOnly(e.element(),n)});var r=el({getSystem:t.get,config:p.none,hasConfigured:c.constant(!1),connect:function(n){t.set(n)},disconnect:function(){t.set(rl(function(){return r}))},element:c.constant(e.element()),spec:c.constant(n),readState:c.constant("No state"),syncComponents:c.noop,components:c.constant([]),events:c.constant({})});return Va.premade(r)},Hl=function(n){return Va.getPremade(n).fold(function(){var e=An.deepMerge({uid:Sc.generate("")},n);return Bl(e).getOrDie()},function(n){return n})},Nl={build:Hl,premade:Va.premade,external:Il,text:function(n){var e=sn.fromText(n);return Il({element:e})}},Vl="alloy.item-hover",jl="alloy.item-focus",Pl={hover:c.constant(Vl),focus:c.constant(jl),onHover:function(n){(bo(n.element()).isNone()||oi.isFocused(n))&&(oi.isFocused(n)||oi.focus(n),Pn(n,Vl,{item:n}))},onFocus:function(n){Pn(n,jl,{item:n})}},Ll=[Fe("data"),Fe("components"),Fe("dom"),Ve("toggling"),We("itemBehaviours",{}),We("ignoreFocus",!1),We("domModification",{}),Bo.output("builder",function(n){return{dom:An.deepMerge(n.dom(),{attributes:{role:n.toggling().isSome()?"menuitemcheckbox":"menuitem"}}),behaviours:An.deepMerge(jt.derive([n.toggling().fold(qo.revoke,function(n){return qo.config(An.deepMerge({aria:{mode:"checked"}},n))}),oi.config({ignore:n.ignoreFocus(),onFocus:function(n){Pl.onFocus(n)}}),Ma.config({mode:"execution"}),us.config({store:{mode:"memory",initialValue:n.data()}})]),n.itemBehaviours()),events:lt.derive([lt.runWithTarget(On.tapOrClick(),Ln),lt.cutter(Sn.mousedown()),lt.run(Sn.mouseover(),Pl.onHover),lt.run(On.focusItem(),oi.focus)]),components:n.components(),domModification:n.domModification()}})],Wl=[Fe("dom"),Fe("components"),Bo.output("builder",function(n){return{dom:n.dom(),components:n.components(),events:lt.derive([lt.stopper(On.focusItem())])}})],Ul=[Ya.required({name:"widget",overrides:function(n){return{behaviours:jt.derive([us.config({store:{mode:"manual",getValue:function(e){return n.data()},setValue:function(){}}})])}}})],zl={owner:c.constant("item-widget"),parts:c.constant(Ul)},Kl=[Fe("uid"),Fe("data"),Fe("components"),Fe("dom"),We("autofocus",!1),We("domModification",{}),pc(zl.parts()),Bo.output("builder",function(n){var e=dc(zl.owner(),n,zl.parts()),t=mc(zl.owner(),n,e.internals()),r=function(e){return hc(e,n,"widget").map(function(n){return Ma.focusIn(n),n})},o=function(e,t){return Ji(t.event().target())?p.none():n.autofocus()?(t.setSource(e.element()),p.none()):p.none()};return An.deepMerge({dom:n.dom(),components:t,domModification:n.domModification(),events:lt.derive([lt.runOnExecute(function(n,e){r(n).each(function(n){e.stop()})}),lt.run(Sn.mouseover(),Pl.onHover),lt.run(On.focusItem(),function(e,t){n.autofocus()?r(e):oi.focus(e)})]),behaviours:jt.derive([us.config({store:{mode:"memory",initialValue:n.data()}}),oi.config({onFocus:function(n){Pl.onFocus(n)}}),Ma.config({mode:"special",onLeft:o,onRight:o,onEscape:function(e,t){return oi.isFocused(e)||n.autofocus()?n.autofocus()?(t.setSource(e.element()),p.none()):p.none():(oi.focus(e),p.some(!0))}})])})})],Gl=rt.choose("type",{widget:Kl,item:Ll,separator:Wl}),$l=[Ya.group({factory:{sketch:function(n){var e=rt.asStructOrDie("menu.spec item",Gl,n);return e.builder()(e)}},name:"items",unit:"item",defaults:function(n,e){var t=Sc.generate("");return An.deepMerge({uid:t},e)},overrides:function(n,e){return{type:e.type,ignoreFocus:n.fakeFocus(),domModification:{classes:[n.markers().item()]}}}})],ql=[Fe("value"),Fe("items"),Fe("dom"),Fe("components"),We("eventOrder",{}),Ra("menuBehaviours",[Di,us,nf,Ma]),Ue("movement",{mode:"menu",moveOnTab:!0},rt.choose("mode",{grid:[Bo.initSize(),Bo.output("config",function(n,e){return{mode:"flatgrid",selector:"."+n.markers().item(),initSize:{numColumns:e.initSize().numColumns(),numRows:e.initSize().numRows()},focusManager:n.focusManager()}})],menu:[We("moveOnTab",!0),Bo.output("config",function(n,e){return{mode:"menu",selector:"."+n.markers().item(),moveOnTab:e.moveOnTab(),focusManager:n.focusManager()}})]})),Bo.itemMarkers(),We("fakeFocus",!1),We("focusManager",Ai()),Bo.onHandler("onHighlight")],_l={name:c.constant("Menu"),schema:c.constant(ql),parts:c.constant($l)},Xl={focus:c.constant("alloy.menu-focus")},Yl={make:function(n,e,t,r){return An.deepMerge({dom:An.deepMerge(n.dom(),{attributes:{role:"menu"}}),uid:n.uid(),behaviours:An.deepMerge(jt.derive([Di.config({highlightClass:n.markers().selectedItem(),itemClass:n.markers().item(),onHighlight:n.onHighlight()}),us.config({store:{mode:"memory",initialValue:n.value()}}),nf.config({find:c.identity}),Ma.config(n.movement().config()(n,n.movement()))]),Fa(n.menuBehaviours())),events:lt.derive([lt.run(Pl.focus(),function(n,e){var t=e.event();n.getSystem().getByDom(t.target()).each(function(t){Di.highlight(n,t),e.stop(),Pn(n,Xl.focus(),{menu:n,item:t})})}),lt.run(Pl.hover(),function(n,e){var t=e.event().item();Di.highlight(n,t)})]),components:e,eventOrder:n.eventOrder()})}},Jl=Mc({name:"Menu",configFields:_l.schema(),partFields:_l.parts(),factory:Yl.make}),Ql=function(n,e){var t=Tr.owner(e),r=yo(t).bind(function(n){var t=function(e){return bn(n,e)};return t(e)?p.some(e):lo.descendant(e,t)}),o=n(e);return r.each(function(n){yo(t).filter(function(e){return bn(e,n)}).orThunk(function(){ho(n)})}),o},Zl=function(n,e,t,r){var o=n.getSystem().build(r);jr.attachWith(n,o,t)},nd=function(n,e){return n.components()},ed={append:function(n,e,t,r){Zl(n,0,Er.append,r)},prepend:function(n,e,t,r){Zl(n,0,Er.prepend,r)},remove:function(n,e,t,r){var o=nd(n,e);E.find(o,function(n){return bn(r.element(),n.element())}).each(jr.detach)},set:function(n,e,t,r){jr.detachChildren(n),Ql(function(){var e=E.map(r,n.getSystem().build);E.each(e,function(e){jr.attach(n,e)})},n.element())},contents:nd},td=jt.create({fields:[],name:"replacing",apis:ed}),rd=function(n,e,t,r){return fe.readOptFrom(t,r).bind(function(r){return fe.readOptFrom(n,r).bind(function(r){var o=rd(n,e,t,r);return p.some([r].concat(o))})}).getOr([])},od={generate:function(n,e){var t={};Hn.each(n,function(n,e){E.each(n,function(n){t[n]=e})});var r,o=e,i=(r=e,Hn.tupleMap(r,function(n,e){return{k:n,v:e}})),u=Hn.map(i,function(n,e){return[e].concat(rd(t,o,i,e))});return Hn.map(t,function(n){return fe.readOptFrom(u,n).getOr([n])})}},id={make:function(n,e){var t,r,o,i,u,a,s=(t=uo({}),r=uo({}),o=uo({}),i=uo(p.none()),u=uo(c.constant([])),{setContents:function(n,e,a,c){i.set(p.some(n)),t.set(a),r.set(e),u.set(c);var s=c(e),f=od.generate(s,a);o.set(f)},expand:function(n){return fe.readOptFrom(t.get(),n).map(function(e){var t=fe.readOptFrom(o.get(),n).getOr([]);return[e].concat(t)})},refresh:function(n){return fe.readOptFrom(o.get(),n)},collapse:function(n){return fe.readOptFrom(o.get(),n).bind(function(n){return n.length>1?p.some(n.slice(1)):p.none()})},lookupMenu:a=function(n){return fe.readOptFrom(r.get(),n)},otherMenus:function(n){var e=u.get()(r.get());return E.difference(Hn.keys(e),n)},getPrimary:function(){return i.get().bind(a)},getMenus:function(){return r.get()},clear:function(){t.set({}),r.set({}),o.set({}),i.set(p.none())},isClear:function(){return i.get().isNone()}}),f=function(t){var r,o,i=(r=t,o=n.data().menus(),Hn.map(o,function(t,o){var i=Jl.sketch(An.deepMerge(t,{value:o,items:t.items,markers:fe.narrow(e.markers,["item","selectedItem"]),fakeFocus:n.fakeFocus(),onHighlight:n.onHighlight(),focusManager:n.fakeFocus()?Mi():Ai()}));return r.getSystem().build(i)}));return s.setContents(n.data().primary(),i,n.data().expansions(),function(n){return d(t,n)}),s.getPrimary()},l=function(n){return us.getValue(n).value},d=function(e,t){return Hn.map(n.data().menus(),function(n,e){return E.bind(n.items,function(n){return"separator"===n.type?[]:[n.data.value]})})},m=function(n,e){Di.highlight(n,e),Di.getHighlighted(e).orThunk(function(){return Di.getFirst(e)}).each(function(e){Wn(n,e.element(),On.focusItem())})},g=function(n,e){return _r(E.map(e,n.lookupMenu))},h=function(e,t,r){return p.from(r[0]).bind(t.lookupMenu).map(function(o){var i=g(t,r.slice(1));E.each(i,function(e){lr.add(e.element(),n.markers().backgroundMenu())}),Br.inBody(o.element())||td.append(e,Nl.premade(o)),Cl.remove(o.element(),[n.markers().backgroundMenu()]),m(e,o);var u=g(t,t.otherMenus(r));return E.each(u,function(t){Cl.remove(t.element(),[n.markers().backgroundMenu()]),n.stayInDom()||td.remove(e,t)}),o})},v=function(e,t){var r=l(t);return s.expand(r).bind(function(r){return p.from(r[0]).bind(s.lookupMenu).each(function(r){Br.inBody(r.element())||td.append(e,Nl.premade(r)),n.onOpenSubmenu()(e,t,r),Di.highlightFirst(r)}),h(e,s,r)})},y=function(e,t){var r=l(t);return s.collapse(r).bind(function(r){return h(e,s,r).map(function(r){return n.onCollapseMenu()(e,t,r),r})})},b=function(e){return function(t,r){return yi(r.getSource(),"."+n.markers().item()).bind(function(n){return t.getSystem().getByDom(n).bind(function(n){return e(t,n)})})}},w=lt.derive([lt.run(Xl.focus(),function(n,e){var t=e.event().menu();Di.highlight(n,t)}),lt.runOnExecute(function(e,t){var r=t.event().target();return e.getSystem().getByDom(r).bind(function(t){return 0===l(t).indexOf("collapse-item")?y(e,t):v(e,t).orThunk(function(){return n.onExecute()(e,t)})})}),lt.runOnAttached(function(e,t){f(e).each(function(t){td.append(e,Nl.premade(t)),n.openImmediately()&&(m(e,t),n.onOpenMenu()(e,t))})})].concat(n.navigateOnHover()?[lt.run(Pl.hover(),function(e,t){var r,o,i=t.event().item();r=e,o=l(i),s.refresh(o).bind(function(n){return h(r,s,n)}),v(e,i),n.onHover()(e,i)})]:[]));return{uid:n.uid(),dom:n.dom(),behaviours:An.deepMerge(jt.derive([Ma.config({mode:"special",onRight:b(function(n,e){return Ji(e.element())?p.none():v(n,e)}),onLeft:b(function(n,e){return Ji(e.element())?p.none():y(n,e)}),onEscape:b(function(e,t){return y(e,t).orThunk(function(){return n.onEscape()(e,t)})}),focusIn:function(n,e){s.getPrimary().each(function(e){Wn(n,e.element(),On.focusItem())})}}),Di.config({highlightClass:n.markers().selectedMenu(),itemClass:n.markers().menu()}),nf.config({find:function(n){return Di.getHighlighted(n)}}),td.config({})]),Fa(n.tmenuBehaviours())),eventOrder:n.eventOrder(),apis:{collapseMenu:function(n){Di.getHighlighted(n).each(function(e){Di.getHighlighted(e).each(function(e){y(n,e)})})}},events:w}},collapseItem:c.constant("collapse-item")},ud=Ac({name:"TieredMenu",configFields:[Bo.onStrictKeyboardHandler("onExecute"),Bo.onStrictKeyboardHandler("onEscape"),Bo.onStrictHandler("onOpenMenu"),Bo.onStrictHandler("onOpenSubmenu"),Bo.onHandler("onCollapseMenu"),We("openImmediately",!0),Ie("data",[Fe("primary"),Fe("menus"),Fe("expansions")]),We("fakeFocus",!1),Bo.onHandler("onHighlight"),Bo.onHandler("onHover"),Bo.tieredMenuMarkers(),Fe("dom"),We("navigateOnHover",!0),We("stayInDom",!1),Ra("tmenuBehaviours",[Ma,Di,nf,td]),We("eventOrder",{})],apis:{collapseMenu:function(n,e){n.collapseMenu(e)}},factory:id.make,extraApis:{tieredData:function(n,e,t){return{primary:n,menus:e,expansions:t}},singleData:function(n,e){return{primary:n,menus:fe.wrap(n,e),expansions:{}}},collapseItem:function(n){return{value:Ia(id.collapseItem()),text:n}}}}),ad=Qo.resolve("scrollable"),cd={register:function(n){lr.add(n,ad)},deregister:function(n){lr.remove(n,ad)},scrollable:c.constant(ad)},sd=function(n){return fe.readOptFrom(n,"format").getOr(n.title)},fd=function(n,e,t,r,o){return{data:{value:n,text:e},type:"item",dom:{tag:"div",classes:o?[Qo.resolve("styles-item-is-menu")]:[]},toggling:{toggleOnExecute:!1,toggleClass:Qo.resolve("format-matches"),selected:t},itemBehaviours:jt.derive(o?[]:[_o(n,function(n,e){(e?qo.on:qo.off)(n)})]),components:[{dom:{tag:"div",attributes:{style:r},innerHtml:e}}]}},ld=function(n,e,t,r){return{value:n,dom:{tag:"div"},components:[Fc.sketch({dom:{tag:"div",classes:[Qo.resolve("styles-collapser")]},components:r?[{dom:{tag:"span",classes:[Qo.resolve("styles-collapse-icon")]}},Nl.text(n)]:[Nl.text(n)],action:function(n){if(r){var e=t().get(n);ud.collapseMenu(e)}}}),{dom:{tag:"div",classes:[Qo.resolve("styles-menu-items-container")]},components:[Jl.parts().items({})],behaviours:jt.derive([Js.config("adhoc-scrollable-menu",[lt.runOnAttached(function(n,e){Ki.set(n.element(),"overflow-y","auto"),Ki.set(n.element(),"-webkit-overflow-scrolling","touch"),cd.register(n.element())}),lt.runOnDetached(function(n){Ki.remove(n.element(),"overflow-y"),Ki.remove(n.element(),"-webkit-overflow-scrolling"),cd.deregister(n.element())})])])}],items:e,menuBehaviours:jt.derive([Xf.config({initialState:"after",routes:Xf.createTristate("before","current","after",{transition:{property:"transform",transitionClass:"transitioning"}})})])}},dd=function(n){var e,t,r,o,i,u=(e=n.formats,t=function(){return a},r=ld("Styles",[].concat(E.map(e.items,function(n){return fd(sd(n),n.title,n.isSelected(),n.getPreview(),fe.hasKey(e.expansions,sd(n)))})),t,!1),o=Hn.map(e.menus,function(n,r){var o=E.map(n,function(n){return fd(sd(n),n.title,n.isSelected!==undefined&&n.isSelected(),n.getPreview!==undefined?n.getPreview():"",fe.hasKey(e.expansions,sd(n)))});return ld(r,o,t,!0)}),i=An.deepMerge(o,fe.wrap("styles",r)),{tmenu:ud.tieredData("styles",i,e.expansions)}),a=Es(ud.sketch({dom:{tag:"div",classes:[Qo.resolve("styles-menu")]},components:[],fakeFocus:!0,stayInDom:!0,onExecute:function(e,t){var r=us.getValue(t);n.handle(t,r.value)},onEscape:function(){},onOpenMenu:function(n,e){var t=ls(n.element());fs(e.element(),t),Xf.jumpTo(e,"current")},onOpenSubmenu:function(n,e,t){var r=ls(n.element()),o=hi(e.element(),'[role="menu"]').getOrDie("hacky"),i=n.getSystem().getByDom(o).getOrDie();fs(t.element(),r),Xf.progressTo(i,"before"),Xf.jumpTo(t,"after"),Xf.progressTo(t,"current")},onCollapseMenu:function(n,e,t){var r=hi(e.element(),'[role="menu"]').getOrDie("hacky"),o=n.getSystem().getByDom(r).getOrDie();Xf.progressTo(o,"after"),Xf.progressTo(t,"current")},navigateOnHover:!1,openImmediately:!0,data:u.tmenu,markers:{backgroundMenu:Qo.resolve("styles-background-menu"),menu:Qo.resolve("styles-menu"),selectedMenu:Qo.resolve("styles-selected-menu"),item:Qo.resolve("styles-item"),selectedItem:Qo.resolve("styles-selected-item")}}));return a.asSpec()},md=function(n){return fe.hasKey(n,"items")?(e=n,t=An.deepMerge(fe.exclude(e,["items"]),{menu:!0}),r=pd(e.items),{item:t,menus:An.deepMerge(r.menus,fe.wrap(e.title,r.items)),expansions:An.deepMerge(r.expansions,fe.wrap(e.title,e.title))}):{item:n,menus:{},expansions:{}};var e,t,r},pd=function(n){return E.foldr(n,function(n,e){var t=md(e);return{menus:An.deepMerge(n.menus,t.menus),items:[t.item].concat(n.items),expansions:An.deepMerge(n.expansions,t.expansions)}},{menus:{},expansions:{},items:[]})},gd={expand:pd},hd=function(n,e){var t=function(e){return function(){return n.formatter.match(e)}},r=function(e){return function(){return n.formatter.getCssText(e)}},o=fe.readOptFrom(e,"style_formats").getOr(Lf),i=function(e){return E.map(e,function(e){if(fe.hasKey(e,"items")){var o=i(e.items);return An.deepMerge((l=e,An.deepMerge(l,{isSelected:c.constant(!1),getPreview:c.constant("")})),{items:o})}return fe.hasKey(e,"format")?(f=e,An.deepMerge(f,{isSelected:t(f.format),getPreview:r(f.format)})):(a=Ia((u=e).title),s=An.deepMerge(u,{format:a,isSelected:t(a),getPreview:r(a)}),n.formatter.register(a,s),s);var u,a,s,f,l})};return i(o)},vd=function(n,e,t){var r,o,i,u=(r=n,i=(o=function(n){return E.bind(n,function(n){return n.items!==undefined?o(n.items).length>0?[n]:[]:!fe.hasKey(n,"format")||r.formatter.canApply(n.format)?[n]:[]})})(e),gd.expand(i));return dd({formats:u,handle:function(e,r){n.undoManager.transact(function(){qo.isOn(e)?n.formatter.remove(r):n.formatter.apply(r)}),t()}})},yd=["undo","bold","italic","link","image","bullist","styleselect"],bd=function(n){var e=n.replace(/\|/g," ").trim();return e.length>0?e.split(/\s+/):[]},wd=function(n){return E.bind(n,function(n){return kn.isArray(n)?wd(n):bd(n)})},Sd=function(n){var e=n.toolbar!==undefined?n.toolbar:yd;return kn.isArray(e)?wd(e):bd(e)},xd=function(n,e){var t=function(n){return function(){return Pc.forToolbarCommand(e,n)}},r=function(n){return function(){return Pc.forToolbarStateCommand(e,n)}},o=function(n,t,r){return function(){return Pc.forToolbarStateAction(e,n,t,r)}},i=t("undo"),u=t("redo"),a=r("bold"),c=r("italic"),s=r("underline"),f=t("removeformat"),l=o("unlink","link",function(){e.execCommand("unlink",null,!1)}),d=o("unordered-list","ul",function(){e.execCommand("InsertUnorderedList",null,!1)}),m=o("ordered-list","ol",function(){e.execCommand("InsertOrderedList",null,!1)}),g=hd(e,e.settings),h=function(){return vd(e,g,function(){e.fire("scrollIntoView")})},v=function(n,t){return{isSupported:function(){return n.forall(function(n){return fe.hasKey(e.buttons,n)})},sketch:t}};return{undo:v(p.none(),i),redo:v(p.none(),u),bold:v(p.none(),a),italic:v(p.none(),c),underline:v(p.none(),s),removeformat:v(p.none(),f),link:v(p.none(),function(){return Pf(n,e)}),unlink:v(p.none(),l),image:v(p.none(),function(){return Us(e)}),bullist:v(p.some("bullist"),d),numlist:v(p.some("numlist"),m),fontsizeselect:v(p.none(),function(){return Cs(n,e)}),forecolor:v(p.none(),function(){return hs(n,e)}),styleselect:v(p.none(),function(){return Pc.forToolbar("style-formats",function(t){e.fire("toReading"),n.dropup().appear(h,qo.on,t)},jt.derive([qo.config({toggleClass:Qo.resolve("toolbar-button-selected"),toggleOnExecute:!1,aria:{mode:"pressed"}}),Ho.config({channels:fe.wrapAll([Yo(To.orientationChanged(),qo.off),Yo(To.dropupDismissed(),qo.off)])})]))})}},Od=function(n,e){var t=Sd(n),r={};return E.bind(t,function(n){var t=!fe.hasKey(r,n)&&fe.hasKey(e,n)&&e[n].isSupported()?[e[n].sketch()]:[];return r[n]=!0,t})},Td=function(n,e){return function(t){if(n(t)){var r,o,i,u,a,s,f,l=sn.fromDom(t.target),d=function(){t.stopPropagation()},m=function(){t.preventDefault()},p=c.compose(m,d),g=(r=l,o=t.clientX,i=t.clientY,u=d,a=m,s=p,f=t,{target:c.constant(r),x:c.constant(o),y:c.constant(i),stop:u,prevent:a,kill:s,raw:c.constant(f)});e(g)}}},kd=function(n,e,t,r,o){var i=Td(t,r);return n.dom().addEventListener(e,i,o),{unbind:c.curry(Cd,n,e,i,o)}},Cd=function(n,e,t,r){n.dom().removeEventListener(e,t,r)},Ed=function(n,e,t,r){return kd(n,e,t,r,!1)},Dd=function(n,e,t,r){return kd(n,e,t,r,!0)},Ad=c.constant(!0),Md={bind:function(n,e,t){return Ed(n,e,Ad,t)},capture:function(n,e,t){return Dd(n,e,Ad,t)}},Rd=function(n){var e=n.matchMedia("(orientation: portrait)").matches;return{isPortrait:c.constant(e)}},Fd=Rd,Bd=function(n,e){var t=sn.fromDom(n),r=null,o=Md.bind(t,"orientationchange",function(){clearInterval(r);var t=Rd(n);e.onChange(t),i(function(){e.onReady(t)})}),i=function(e){clearInterval(r);var t=n.innerHeight,o=0;r=setInterval(function(){t!==n.innerHeight?(clearInterval(r),e(p.some(n.innerHeight))):o>20&&(clearInterval(r),e(p.none())),o++},50)};return{onAdjustment:i,destroy:function(){o.unbind()}}},Id=function(n){var e=an.detect().os.isiOS(),t=Rd(n).isPortrait();return e&&!t?n.screen.height:n.screen.width},Hd=function(n){return n.raw().touches===undefined||1!==n.raw().touches.length?p.none():p.some(n.raw().touches[0])},Nd=function(n){var e,t,r,o=uo(p.none()),i=(e=function(e){o.set(p.none()),n.triggerEvent(On.longpress(),e)},t=400,r=null,{cancel:function(){null!==r&&(clearTimeout(r),r=null)},schedule:function(){var n=arguments;r=setTimeout(function(){e.apply(null,n),r=null},t)}}),u=fe.wrapAll([{key:Sn.touchstart(),value:function(n){return Hd(n).each(function(e){i.cancel();var t={x:c.constant(e.clientX),y:c.constant(e.clientY),target:n.target};i.schedule(t),o.set(p.some(t))}),p.none()}},{key:Sn.touchmove(),value:function(n){return i.cancel(),Hd(n).each(function(n){o.get().each(function(e){var t,r,i,u;t=n,r=e,i=Math.abs(t.clientX-r.x()),u=Math.abs(t.clientY-r.y()),(i>5||u>5)&&o.set(p.none())})}),p.none()}},{key:Sn.touchend(),value:function(e){return i.cancel(),o.get().filter(function(n){return bn(n.target(),e.target())}).map(function(t){return n.triggerEvent(On.tap(),e)})}}]);return{fireIfReady:function(n,e){return fe.readOptFrom(u,e).bind(function(e){return e(n)})}}},Vd=function(n){var e=Nd({triggerEvent:function(e,t){n.onTapContent(t)}});return{fireTouchstart:function(n){e.fireIfReady(n,"touchstart")},onTouchend:function(){return Md.bind(n.body(),"touchend",function(n){e.fireIfReady(n,"touchend")})},onTouchmove:function(){return Md.bind(n.body(),"touchmove",function(n){e.fireIfReady(n,"touchmove")})}}},jd=an.detect().os.version.major>=6,Pd=function(n,e,t){var r=Vd(n),o=Tr.owner(e),i=function(n){return!bn(n.start(),n.finish())||n.soffset()!==n.foffset()},u=function(){var r=n.doc().dom().hasFocus()&&n.getSelection().exists(i);t.getByDom(e).each(!0===(r||yo(o).filter(function(n){return"input"===$t.name(n)}).exists(function(n){return n.dom().selectionStart!==n.dom().selectionEnd}))?qo.on:qo.off)},a=[Md.bind(n.body(),"touchstart",function(e){n.onTouchContent(),r.fireTouchstart(e)}),r.onTouchmove(),r.onTouchend(),Md.bind(e,"touchstart",function(e){n.onTouchToolstrip()}),n.onToReading(function(){vo(n.body())}),n.onToEditing(c.noop),n.onScrollToCursor(function(e){e.preventDefault(),n.getCursorBox().each(function(e){var t=n.win(),r=e.top()>t.innerHeight||e.bottom()>t.innerHeight?e.bottom()-t.innerHeight+50:0;0!==r&&t.scrollTo(t.pageXOffset,t.pageYOffset+r)})})].concat(!0===jd?[]:[Md.bind(sn.fromDom(n.win()),"blur",function(){t.getByDom(e).each(qo.off)}),Md.bind(o,"select",u),Md.bind(n.doc(),"selectionchange",u)]);return{destroy:function(){E.each(a,function(n){n.unbind()})}}},Ld=function(n){n.focus();var e=sn.fromDom(n.document.body);(yo().exists(function(n){return E.contains(["input","textarea"],$t.name(n))})?function(n){setTimeout(function(){n()},0)}:c.apply)(function(){yo().each(vo),ho(e)})},Wd=function(n,e){var t=parseInt(Jt.get(n,e),10);return isNaN(t)?0:t},Ud=(ol=$t.isText,il="text",ul=function(n){return ol(n)?p.from(n.dom().nodeValue):p.none()},al=an.detect().browser,{get:function(n){if(!ol(n))throw new Error("Can only get "+il+" value of a "+il+" node");return cl(n).getOr("")},getOption:cl=al.isIE()&&10===al.version.major?function(n){try{return ul(n)}catch(e){return p.none()}}:ul,set:function(n,e){if(!ol(n))throw new Error("Can only set raw "+il+" value of a "+il+" node");n.dom().nodeValue=e}}),zd=function(n){return Ud.getOption(n)},Kd=function(n){return"img"===$t.name(n)?1:zd(n).fold(function(){return Tr.children(n).length},function(n){return n.length})},Gd=Kd,$d=Kn([{before:["element"]},{on:["element","offset"]},{after:["element"]}]),qd={before:$d.before,on:$d.on,after:$d.after,cata:function(n,e,t,r){return n.fold(e,t,r)},getStart:function(n){return n.fold(c.identity,c.identity,c.identity)}},_d=Kn([{domRange:["rng"]},{relative:["startSitu","finishSitu"]},{exact:["start","soffset","finish","foffset"]}]),Xd=vt.immutable("start","soffset","finish","foffset"),Yd={domRange:_d.domRange,relative:_d.relative,exact:_d.exact,exactFromRange:function(n){return _d.exact(n.start(),n.soffset(),n.finish(),n.foffset())},range:Xd,getWin:function(n){var e=n.match({domRange:function(n){return sn.fromDom(n.startContainer)},relative:function(n,e){return qd.getStart(n)},exact:function(n,e,t,r){return n}});return Tr.defaultView(e)}},Jd=function(n,e,t,r){var o=Tr.owner(n).dom().createRange();return o.setStart(n.dom(),e),o.setEnd(t.dom(),r),o},Qd=function(n,e,t,r){var o=Jd(n,e,t,r),i=bn(n,t)&&e===r;return o.collapsed&&!i},Zd=function(n,e){n.selectNodeContents(e.dom())},nm=function(n){n.deleteContents()},em=function(n){return{left:c.constant(n.left),top:c.constant(n.top),right:c.constant(n.right),bottom:c.constant(n.bottom),width:c.constant(n.width),height:c.constant(n.height)}},tm={create:function(n){return n.document.createRange()},replaceWith:function(n,e){nm(n),n.insertNode(e.dom())},selectNodeContents:function(n,e){var t=n.document.createRange();return Zd(t,e),t},selectNodeContentsUsing:Zd,relativeToNative: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},exactToNative:function(n,e,t,r,o){var i=n.document.createRange();return i.setStart(e.dom(),t),i.setEnd(r.dom(),o),i},deleteContents:nm,cloneFragment:function(n){var e=n.cloneContents();return sn.fromDom(e)},getFirstRect:function(n){var e=n.getClientRects(),t=e.length>0?e[0]:n.getBoundingClientRect();return t.width>0||t.height>0?p.some(t).map(em):p.none()},getBounds:function(n){var e=n.getBoundingClientRect();return e.width>0||e.height>0?p.some(e).map(em):p.none()},isWithin:function(n,e){return e.compareBoundaryPoints(n.END_TO_START,n)<1&&e.compareBoundaryPoints(n.START_TO_END,n)>-1},toString:function(n){return n.toString()}},rm=Kn([{ltr:["start","soffset","finish","foffset"]},{rtl:["start","soffset","finish","foffset"]}]),om=function(n,e,t){return e(sn.fromDom(t.startContainer),t.startOffset,sn.fromDom(t.endContainer),t.endOffset)},im=function(n,e){var t,r,o,i=(t=n,e.match({domRange:function(n){return{ltr:c.constant(n),rtl:p.none}},relative:function(n,e){return{ltr:F(function(){return tm.relativeToNative(t,n,e)}),rtl:F(function(){return p.some(tm.relativeToNative(t,e,n))})}},exact:function(n,e,r,o){return{ltr:F(function(){return tm.exactToNative(t,n,e,r,o)}),rtl:F(function(){return p.some(tm.exactToNative(t,r,o,n,e))})}}}));return(o=(r=i).ltr()).collapsed?r.rtl().filter(function(n){return!1===n.collapsed}).map(function(n){return rm.rtl(sn.fromDom(n.endContainer),n.endOffset,sn.fromDom(n.startContainer),n.startOffset)}).getOrThunk(function(){return om(0,rm.ltr,o)}):om(0,rm.ltr,o)},um=(rm.ltr,rm.rtl,im),am=function(n,e){return im(n,e).match({ltr:function(e,t,r,o){var i=n.document.createRange();return i.setStart(e.dom(),t),i.setEnd(r.dom(),o),i},rtl:function(e,t,r,o){var i=n.document.createRange();return i.setStart(r.dom(),o),i.setEnd(e.dom(),t),i}})},cm=(document.caretPositionFromPoint||document.caretRangeFromPoint,function(n,e){var t=$t.name(n);return"input"===t?qd.after(n):E.contains(["br","img"],t)?0===e?qd.before(n):qd.after(n):qd.on(n,e)}),sm=function(n,e,t,r){var o=cm(n,e),i=cm(t,r);return Yd.relative(o,i)},fm=sm,lm=function(n,e){p.from(n.getSelection()).each(function(n){n.removeAllRanges(),n.addRange(e)})},dm=function(n,e,t,r,o){var i=tm.exactToNative(n,e,t,r,o);lm(n,i)},mm=function(n,e){return um(n,e).match({ltr:function(e,t,r,o){dm(n,e,t,r,o)},rtl:function(e,t,r,o){var i=n.getSelection();i.extend?(i.collapse(e.dom(),t),i.extend(r.dom(),o)):dm(n,r,o,e,t)}})},pm=function(n){var e=sn.fromDom(n.anchorNode),t=sn.fromDom(n.focusNode);return Qd(e,n.anchorOffset,t,n.focusOffset)?p.some(Yd.range(sn.fromDom(n.anchorNode),n.anchorOffset,sn.fromDom(n.focusNode),n.focusOffset)):function(n){if(n.rangeCount>0){var e=n.getRangeAt(0),t=n.getRangeAt(n.rangeCount-1);return p.some(Yd.range(sn.fromDom(e.startContainer),e.startOffset,sn.fromDom(t.endContainer),t.endOffset))}return p.none()}(n)},gm=function(n){var e=n.getSelection();return e.rangeCount>0?pm(e):p.none()},hm=function(n,e,t,r,o){var i=fm(e,t,r,o);mm(n,i)},vm=gm,ym=function(n){return gm(n).map(function(n){return Yd.exact(n.start(),n.soffset(),n.finish(),n.foffset())})},bm=function(n){n.getSelection().removeAllRanges()},wm=function(n,e){var t=am(n,e);return tm.getFirstRect(t)},Sm=function(n){return{left:n.left,top:n.top,right:n.right,bottom:n.bottom,width:c.constant(2),height:n.height}},xm=function(n){return{left:c.constant(n.left),top:c.constant(n.top),right:c.constant(n.right),bottom:c.constant(n.bottom),width:c.constant(n.width),height:c.constant(n.height)}},Om={getRectangles:function(n){var e=n.getSelection();return e!==undefined&&e.rangeCount>0?function(n){if(n.collapsed){var e=sn.fromDom(n.startContainer);return Tr.parent(e).bind(function(t){var r=Yd.exact(e,n.startOffset,t,Gd(t));return wm(n.startContainer.ownerDocument.defaultView,r).map(Sm).map(E.pure)}).getOr([])}return E.map(n.getClientRects(),xm)}(e.getRangeAt(0)):[]}},Tm="data-"+Qo.resolve("last-outer-height"),km=function(n,e){Jt.set(n,Tm,e)},Cm=function(n){return{top:c.constant(n.top()),bottom:c.constant(n.top()+n.height())}},Em=function(n,e){var t=Wd(e,Tm),r=n.innerHeight;return t>r?p.some(t-r):p.none()},Dm=function(n,e){var t=sn.fromDom(e.document.body),r=Md.bind(sn.fromDom(n),"resize",function(){Em(n,t).each(function(n){var t,r;(t=e,r=Om.getRectangles(t),r.length>0?p.some(r[0]).map(Cm):p.none()).each(function(t){var r,o,i,u=(r=e,i=n,(o=t).top()>r.innerHeight||o.bottom()>r.innerHeight?Math.min(i,o.bottom()-r.innerHeight+50):0);0!==u&&e.scrollTo(e.pageXOffset,e.pageYOffset+u)})}),km(t,n.innerHeight)});return km(t,n.innerHeight),{toEditing:function(){Ld(e)},destroy:function(){r.unbind()}}},Am=function(n){return p.some(sn.fromDom(n.dom().contentWindow.document.body))},Mm=function(n){return p.some(sn.fromDom(n.dom().contentWindow.document))},Rm=function(n){return p.from(n.dom().contentWindow)},Fm=function(n){return Rm(n).bind(vm)},Bm=function(n){return n.getFrame()},Im=function(n,e){return function(t){return t[n].getOrThunk(function(){var n=Bm(t);return function(){return e(n)}})()}},Hm=function(n,e,t,r){return n[t].getOrThunk(function(){return function(n){return Md.bind(e,r,n)}})},Nm=function(n){return{left:c.constant(n.left),top:c.constant(n.top),right:c.constant(n.right),bottom:c.constant(n.bottom),width:c.constant(n.width),height:c.constant(n.height)}},Vm={getBody:Im("getBody",Am),getDoc:Im("getDoc",Mm),getWin:Im("getWin",Rm),getSelection:Im("getSelection",Fm),getFrame:Bm,getActiveApi:function(n){var e=Bm(n);return Am(e).bind(function(t){return Mm(e).bind(function(r){return Rm(e).map(function(o){var i=sn.fromDom(r.dom().documentElement),u=n.getCursorBox.getOrThunk(function(){return function(){return ym(o).bind(function(n){return wm(o,n).orThunk(function(){return vm(o).filter(function(n){return bn(n.start(),n.finish())&&n.soffset()===n.foffset()}).bind(function(n){var e=n.start().dom().getBoundingClientRect();return e.width>0||e.height>0?p.some(e).map(Nm):p.none()})})})}}),a=n.setSelection.getOrThunk(function(){return function(n,e,t,r){hm(o,n,e,t,r)}}),s=n.clearSelection.getOrThunk(function(){return function(){bm(o)}});return{body:c.constant(t),doc:c.constant(r),win:c.constant(o),html:c.constant(i),getSelection:c.curry(Fm,e),setSelection:a,clearSelection:s,frame:c.constant(e),onKeyup:Hm(n,r,"onKeyup","keyup"),onNodeChanged:Hm(n,r,"onNodeChanged","selectionchange"),onDomChanged:n.onDomChanged,onScrollToCursor:n.onScrollToCursor,onScrollToElement:n.onScrollToElement,onToReading:n.onToReading,onToEditing:n.onToEditing,onToolbarScrollStart:n.onToolbarScrollStart,onTouchContent:n.onTouchContent,onTapContent:n.onTapContent,onTouchToolstrip:n.onTouchToolstrip,getCursorBox:u}})})})}},jm="data-ephox-mobile-fullscreen-style",Pm="position:absolute!important;",Lm="top:0!important;left:0!important;margin:0!important;padding:0!important;width:100%!important;",Wm=an.detect().os.isAndroid(),Um=function(n,e){var t,r,o=function(n){return function(e){var t=Jt.get(e,"style"),r=t===undefined?"no-styles":t.trim();r!==n&&(Jt.set(e,jm,r),Jt.set(e,"style",n))}},i=li(n,"*"),u=E.bind(i,function(n){return di(n,"*")}),a=(t=e,(r=Ki.get(t,"background-color"))!==undefined&&""!==r?"background-color:"+r+"!important":"background-color:rgb(255,255,255)!important;");E.each(u,o("display:none!important;")),E.each(i,o(Pm+Lm+a)),o((!0===Wm?"":Pm)+Lm+a)(n)},zm=function(){var n=fi("["+jm+"]");E.each(n,function(n){var e=Jt.get(n,jm);"no-styles"!==e?Jt.set(n,"style",e):Jt.remove(n,"style"),Jt.remove(n,jm)})},Km=function(){var n=gi("head").getOrDie(),e=gi('meta[name="viewport"]').getOrThunk(function(){var e=sn.fromTag("meta");return Jt.set(e,"name","viewport"),Er.append(n,e),e}),t=Jt.get(e,"content");return{maximize:function(){Jt.set(e,"content","width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0")},restore:function(){t!==undefined&&null!==t&&t.length>0?Jt.set(e,"content",t):Jt.set(e,"content","user-scalable=yes")}}},Gm=function(n,e){var t=Km(),r=Mf.api(),o=Mf.api();return{enter:function(){e.hide(),lr.add(n.container,Qo.resolve("fullscreen-maximized")),lr.add(n.container,Qo.resolve("android-maximized")),t.maximize(),lr.add(n.body,Qo.resolve("android-scroll-reload")),r.set(Dm(n.win,Vm.getWin(n.editor).getOrDie("no"))),Vm.getActiveApi(n.editor).each(function(e){Um(n.container,e.body()),o.set(Pd(e,n.toolstrip,n.alloy))})},exit:function(){t.restore(),e.show(),lr.remove(n.container,Qo.resolve("fullscreen-maximized")),lr.remove(n.container,Qo.resolve("android-maximized")),zm(),lr.remove(n.body,Qo.resolve("android-scroll-reload")),o.clear(),r.clear()}}},$m=rt.objOf([Ie("editor",[Fe("getFrame"),Ve("getBody"),Ve("getDoc"),Ve("getWin"),Ve("getSelection"),Ve("setSelection"),Ve("clearSelection"),Ve("cursorSaver"),Ve("onKeyup"),Ve("onNodeChanged"),Ve("getCursorBox"),Fe("onDomChanged"),We("onTouchContent",c.noop),We("onTapContent",c.noop),We("onTouchToolstrip",c.noop),We("onScrollToCursor",c.constant({unbind:c.noop})),We("onScrollToElement",c.constant({unbind:c.noop})),We("onToEditing",c.constant({unbind:c.noop})),We("onToReading",c.constant({unbind:c.noop})),We("onToolbarScrollStart",c.identity)]),Fe("socket"),Fe("toolstrip"),Fe("dropup"),Fe("toolbar"),Fe("container"),Fe("alloy"),Ge("win",function(n){return Tr.owner(n.socket).dom().defaultView}),Ge("body",function(n){return sn.fromDom(n.socket.dom().ownerDocument.body)}),We("translate",c.identity),We("setReadOnly",c.noop)]),qm=function(n,e){var t=null;return{cancel:function(){null!==t&&(clearTimeout(t),t=null)},throttle:function(){var r=arguments;null===t&&(t=setTimeout(function(){n.apply(null,r),t=null,r=null},e))}}},_m=function(n,e){var t=null;return{cancel:function(){null!==t&&(clearTimeout(t),t=null)},throttle:function(){var r=arguments;null!==t&&clearTimeout(t),t=setTimeout(function(){n.apply(null,r),t=null,r=null},e)}}},Xm=function(n,e){var t=Es(ef.sketch({dom:Nc.dom('<div aria-hidden="true" class="${prefix}-mask-tap-icon"></div>'),containerBehaviours:jt.derive([qo.config({toggleClass:Qo.resolve("mask-tap-icon-selected"),toggleOnExecute:!1})])})),r=qm(n,200);return ef.sketch({dom:Nc.dom('<div class="${prefix}-disabled-mask"></div>'),components:[ef.sketch({dom:Nc.dom('<div class="${prefix}-content-container"></div>'),components:[Fc.sketch({dom:Nc.dom('<div class="${prefix}-content-tap-section"></div>'),components:[t.asSpec()],action:function(n){r.throttle()},buttonBehaviours:jt.derive([qo.config({toggleClass:Qo.resolve("mask-tap-icon-selected")})])})]})]})},Ym={produce:function(n){var e=rt.asRawOrDie("Getting AndroidWebapp schema",$m,n);Ki.set(e.toolstrip,"width","100%");var t=Nl.build(Xm(function(){e.setReadOnly(!0),o.enter()},e.translate));e.alloy.add(t);var r={show:function(){e.alloy.add(t)},hide:function(){e.alloy.remove(t)}};Er.append(e.container,t.element());var o=Gm(e,r);return{setReadOnly:e.setReadOnly,refreshStructure:c.noop,enter:o.enter,exit:o.exit,destroy:c.noop}}},Jm=[We("shell",!0),Ra("toolbarBehaviours",[td])],Qm=[Ya.optional({name:"groups",overrides:function(n){return{behaviours:jt.derive([td.config({})])}}})],Zm={name:c.constant("Toolbar"),schema:c.constant(Jm),parts:c.constant(Qm)},np=Mc({name:"Toolbar",configFields:Zm.schema(),partFields:Zm.parts(),factory:function(n,e,t,r){var o=function(e){return n.shell()?p.some(e):hc(e,n,"groups")},i=n.shell()?{behaviours:[td.config({})],components:[]}:{behaviours:[],components:e};return{uid:n.uid(),dom:n.dom(),components:i.components,behaviours:An.deepMerge(jt.derive(i.behaviours),Fa(n.toolbarBehaviours())),apis:{setGroups:function(n,e){o(n).fold(function(){throw console.error("Toolbar was defined to not be a shell, but no groups container was specified in components"),new Error("Toolbar was defined to not be a shell, but no groups container was specified in components")},function(n){td.set(n,e)})}},domModification:{attributes:{role:"group"}}}},apis:{setGroups:function(n,e,t){n.setGroups(e,t)}}}),ep=[Fe("items"),Bo.markers(["itemClass"]),Ra("tgroupBehaviours",[Ma])],tp=[Ya.group({name:"items",unit:"item",overrides:function(n){return{domModification:{classes:[n.markers().itemClass()]}}}})],rp={name:c.constant("ToolbarGroup"),schema:c.constant(ep),parts:c.constant(tp)},op=Mc({name:"ToolbarGroup",configFields:rp.schema(),partFields:rp.parts(),factory:function(n,e,t,r){return An.deepMerge({dom:{attributes:{role:"toolbar"}}},{uid:n.uid(),dom:n.dom(),components:e,behaviours:An.deepMerge(jt.derive([Ma.config({mode:"flow",selector:"."+n.markers().itemClass()})]),Fa(n.tgroupBehaviours())),"debug.sketcher":t["debug.sketcher"]})}}),ip="data-"+Qo.resolve("horizontal-scroll"),up=function(n){return n.dom().scrollTop>0||function(n){n.dom().scrollTop=1;var e=0!==n.dom().scrollTop;return n.dom().scrollTop=0,e}(n)},ap=function(n){return n.dom().scrollLeft>0||function(n){n.dom().scrollLeft=1;var e=0!==n.dom().scrollLeft;return n.dom().scrollLeft=0,e}(n)},cp=function(n){return"true"===Jt.get(n,ip)?ap:up},sp={exclusive:function(n,e){return Md.bind(n,"touchmove",function(n){yi(n.target(),e).filter(cp).fold(function(){n.raw().preventDefault()},c.noop)})},markAsHorizontal:function(n){Jt.set(n,ip,"true")}};function fp(){var n=function(n){var e=!0===n.scrollable?"${prefix}-toolbar-scrollable-group":"";return{dom:Nc.dom('<div aria-label="'+n.label+'" class="${prefix}-toolbar-group '+e+'"></div>'),tgroupBehaviours:jt.derive([Js.config("adhoc-scrollable-toolbar",!0===n.scrollable?[lt.runOnInit(function(n,e){Ki.set(n.element(),"overflow-x","auto"),sp.markAsHorizontal(n.element()),cd.register(n.element())})]:[])]),components:[ef.sketch({components:[op.parts().items({})]})],markers:{itemClass:Qo.resolve("toolbar-group-item")},items:n.items}},e=Nl.build(np.sketch({dom:Nc.dom('<div class="${prefix}-toolbar"></div>'),components:[np.parts().groups({})],toolbarBehaviours:jt.derive([qo.config({toggleClass:Qo.resolve("context-toolbar"),toggleOnExecute:!1,aria:{mode:"none"}}),Ma.config({mode:"cyclic"})]),shell:!0})),t=Nl.build(ef.sketch({dom:{classes:[Qo.resolve("toolstrip")]},components:[Nl.premade(e)],containerBehaviours:jt.derive([qo.config({toggleClass:Qo.resolve("android-selection-context-toolbar"),toggleOnExecute:!1})])})),r=function(){np.setGroups(e,o.get()),qo.off(e)},o=uo([]);return{wrapper:c.constant(t),toolbar:c.constant(e),createGroups:function(e){return E.map(e,c.compose(op.sketch,n))},setGroups:function(n){o.set(n),r()},setContextToolbar:function(n){qo.on(e),np.setGroups(e,n)},restoreToolbar:function(){qo.isOn(e)&&r()},refresh:function(){np.refresh(e)},focus:function(){Ma.focusIn(e)}}}var lp=function(n,e){td.append(n,Nl.premade(e))},dp=function(n,e){td.remove(n,e)},mp={makeEditSwitch:function(n){return Nl.build(Fc.sketch({dom:Nc.dom('<div class="${prefix}-mask-edit-icon ${prefix}-icon"></div>'),action:function(){n.run(function(n){n.setReadOnly(!1)})}}))},makeSocket:function(){return Nl.build(ef.sketch({dom:Nc.dom('<div class="${prefix}-editor-socket"></div>'),components:[],containerBehaviours:jt.derive([td.config({})])}))},updateMode:function(n,e,t,r){(!0===t?gr.toAlpha:gr.toOmega)(r),(t?lp:dp)(n,e)}},pp=function(n,e){return e.getAnimationRoot().fold(function(){return n.element()},function(e){return e(n)})},gp=function(n){return n.dimension().property()},hp=function(n,e){return n.dimension().getDimension()(e)},vp=function(n,e){var t=pp(n,e);Cl.remove(t,[e.shrinkingClass(),e.growingClass()])},yp=function(n,e){lr.remove(n.element(),e.openClass()),lr.add(n.element(),e.closedClass()),Ki.set(n.element(),gp(e),"0px"),Ki.reflow(n.element())},bp=function(n,e){lr.remove(n.element(),e.closedClass()),lr.add(n.element(),e.openClass()),Ki.remove(n.element(),gp(e))},wp=function(n,e,t){t.setCollapsed(),Ki.set(n.element(),gp(e),hp(e,n.element())),Ki.reflow(n.element());var r=pp(n,e);lr.add(r,e.shrinkingClass()),yp(n,e),e.onStartShrink()(n)},Sp=function(n,e,t){var r=function(n,e){bp(n,e);var t=hp(e,n.element());return yp(n,e),t}(n,e),o=pp(n,e);lr.add(o,e.growingClass()),bp(n,e),Ki.set(n.element(),gp(e),r),t.setExpanded(),e.onStartGrow()(n)},xp=function(n,e,t){var r=pp(n,e);return!0===lr.has(r,e.growingClass())},Op=function(n,e,t){var r=pp(n,e);return!0===lr.has(r,e.shrinkingClass())},Tp={grow:function(n,e,t){t.isExpanded()||Sp(n,e,t)},shrink:function(n,e,t){t.isExpanded()&&wp(n,e,t)},immediateShrink:function(n,e,t){var r,o;t.isExpanded()&&(r=n,o=e,t.setCollapsed(),Ki.set(r.element(),gp(o),hp(o,r.element())),Ki.reflow(r.element()),vp(r,o),yp(r,o),o.onStartShrink()(r),o.onShrunk()(r))},hasGrown:function(n,e,t){return t.isExpanded()},hasShrunk:function(n,e,t){return t.isCollapsed()},isGrowing:xp,isShrinking:Op,isTransitioning:function(n,e,t){return!0===xp(n,e)||!0===Op(n,e)},toggleGrow:function(n,e,t){(t.isExpanded()?wp:Sp)(n,e,t)},disableTransitions:vp},kp={exhibit:function(n,e){return e.expanded()?Ot.nu({classes:[e.openClass()],styles:{}}):Ot.nu({classes:[e.closedClass()],styles:fe.wrap(e.dimension().property(),"0px")})},events:function(n,e){return lt.derive([lt.run(Sn.transitionend(),function(t,r){r.event().raw().propertyName===n.dimension().property()&&(Tp.disableTransitions(t,n,e),e.isExpanded()&&Ki.remove(t.element(),n.dimension().property()),(e.isExpanded()?n.onGrown():n.onShrunk())(t,r))})])}},Cp=[Fe("closedClass"),Fe("openClass"),Fe("shrinkingClass"),Fe("growingClass"),Ve("getAnimationRoot"),Bo.onHandler("onShrunk"),Bo.onHandler("onStartShrink"),Bo.onHandler("onGrown"),Bo.onHandler("onStartGrow"),We("expanded",!1),Be("dimension",rt.choose("property",{width:[Bo.output("property","width"),Bo.output("getDimension",function(n){return ls(n)+"px"})],height:[Bo.output("property","height"),Bo.output("getDimension",function(n){return qi(n)+"px"})]}))],Ep={init:function(n){var e=uo(n.expanded());return It({isExpanded:function(){return!0===e.get()},isCollapsed:function(){return!1===e.get()},setCollapsed:c.curry(e.set,!1),setExpanded:c.curry(e.set,!0),readState:function(){return"expanded: "+e.get()}})}},Dp=jt.create({fields:Cp,name:"sliding",active:kp,apis:Tp,state:Ep}),Ap={build:function(n,e){var t=Nl.build(ef.sketch({dom:{tag:"div",classes:Qo.resolve("dropup")},components:[],containerBehaviours:jt.derive([td.config({}),Dp.config({closedClass:Qo.resolve("dropup-closed"),openClass:Qo.resolve("dropup-open"),shrinkingClass:Qo.resolve("dropup-shrinking"),growingClass:Qo.resolve("dropup-growing"),dimension:{property:"height"},onShrunk:function(t){n(),e(),td.set(t,[])},onGrown:function(t){n(),e()}}),Xo(function(n,e){r(c.noop)})])})),r=function(n){window.requestAnimationFrame(function(){n(),Dp.shrink(t)})};return{appear:function(n,e,r){!0===Dp.hasShrunk(t)&&!1===Dp.isTransitioning(t)&&window.requestAnimationFrame(function(){e(r),td.set(t,[n()]),Dp.grow(t)})},disappear:r,component:c.constant(t),element:t.element}}},Mp=an.detect().browser.isFirefox(),Rp=rt.objOfOnly([He("triggerEvent"),He("broadcastEvent"),We("stopBackspace",!0)]),Fp=function(n,e){var t,r,o,i,u=rt.asRawOrDie("Getting GUI events settings",Rp,e),a=an.detect().deviceType.isTouch()?["touchstart","touchmove","touchend","gesturestart"]:["mousedown","mouseup","mouseover","mousemove","mouseout","click"],c=Nd(u),s=E.map(a.concat(["selectstart","input","contextmenu","change","transitionend","dragstart","dragover","drop"]),function(e){return Md.bind(n,e,function(n){c.fireIfReady(n,e).each(function(e){e&&n.kill()}),u.triggerEvent(e,n)&&n.kill()})}),f=Md.bind(n,"keydown",function(n){var e;u.triggerEvent("keydown",n)?n.kill():!0!==u.stopBackspace||(e=n).raw().which!==ii.BACKSPACE()[0]||E.contains(["input","textarea"],$t.name(e.target()))||n.prevent()}),l=(t=n,r=function(n){u.triggerEvent("focusin",n)&&n.kill()},Mp?Md.capture(t,"focus",r):Md.bind(t,"focusin",r)),d=(o=n,i=function(n){u.triggerEvent("focusout",n)&&n.kill(),setTimeout(function(){u.triggerEvent(On.postBlur(),n)},0)},Mp?Md.capture(o,"blur",i):Md.bind(o,"focusout",i)),m=Tr.defaultView(n),p=Md.bind(m,"scroll",function(n){u.broadcastEvent(On.windowScroll(),n)&&n.kill()});return{unbind:function(){E.each(s,function(n){n.unbind()}),f.unbind(),l.unbind(),d.unbind(),p.unbind()}}},Bp=function(n,e){var t=fe.readOptFrom(n,"target").map(function(n){return n()}).getOr(e);return uo(t)},Ip=function(n,e){var t=uo(!1),r=uo(!1);return{stop:function(){t.set(!0)},cut:function(){r.set(!0)},isStopped:t.get,isCut:r.get,event:c.constant(n),setSource:e.set,getSource:e.get}},Hp=Ip,Np=function(n){var e=uo(!1);return{stop:function(){e.set(!0)},cut:c.noop,isStopped:e.get,isCut:c.constant(!1),event:c.constant(n),setTarget:c.die(new Error("Cannot set target of a broadcasted event")),getTarget:c.die(new Error("Cannot get target of a broadcasted event"))}},Vp=Kn([{stopped:[]},{resume:["element"]},{complete:[]}]),jp=function(n,e,t,r,o,i){var u=n(e,r),a=Hp(t,o);return u.fold(function(){return i.logEventNoHandlers(e,r),Vp.complete()},function(n){var t=n.descHandler();return hl.getHandler(t)(a),a.isStopped()?(i.logEventStopped(e,n.element(),t.purpose()),Vp.stopped()):a.isCut()?(i.logEventCut(e,n.element(),t.purpose()),Vp.complete()):Tr.parent(n.element()).fold(function(){return i.logNoParent(e,n.element(),t.purpose()),Vp.complete()},function(r){return i.logEventResponse(e,n.element(),t.purpose()),Vp.resume(r)})})},Pp=function(n,e,t,r,o,i){return jp(n,e,t,r,o,i).fold(function(){return!0},function(r){return Pp(n,e,t,r,o,i)},function(){return!1})},Lp=function(n,e,t,r,o){var i=Bp(t,r);return Pp(n,e,t,r,i,o)},Wp={triggerHandler:function(n,e,t,r,o){var i=Bp(t,r);return jp(n,e,t,r,i,o)},triggerUntilStopped:function(n,e,t,r){var o=t.target();return Lp(n,e,t,o,r)},triggerOnUntilStopped:Lp,broadcast:function(n,e,t){var r=Np(e);return E.each(n,function(n){var e=n.descHandler();hl.getHandler(e)(r)}),r.isStopped()}},Up={closest:function(n,e,t){return lo.closest(n,function(n){return e(n).isSome()},t).bind(e)}},zp=vt.immutable("element","descHandler"),Kp=function(n,e){return{id:c.constant(n),descHandler:c.constant(e)}};function Gp(){var n={};return{registerId:function(e,t,r){Hn.each(r,function(r,o){var i=n[o]!==undefined?n[o]:{};i[t]=hl.curryArgs(r,e),n[o]=i})},unregisterId:function(e){Hn.each(n,function(n,t){n.hasOwnProperty(e)&&delete n[e]})},filterByType:function(e){return fe.readOptFrom(n,e).map(function(n){return Hn.mapToArray(n,function(n,e){return Kp(e,n)})}).getOr([])},find:function(e,t,r){var o=fe.readOpt(t)(n);return Up.closest(r,function(n){return e=o,t=n,Sc.read(t).fold(function(n){return p.none()},function(n){var r=fe.readOpt(n);return e.bind(r).map(function(n){return zp(t,n)})});var e,t},e)}}}function $p(){var n=Gp(),e={},t=function(t){Sc.read(t.element()).each(function(t){e[t]=undefined,n.unregisterId(t)})};return{find:function(e,t,r){return n.find(e,t,r)},filter:function(e){return n.filterByType(e)},register:function(r){var o,i,u=(i=(o=r).element(),Sc.read(i).fold(function(){return Sc.write("uid-",o.element())},function(n){return n}));fe.hasKey(e,u)&&function(n,r){var o=e[r];if(o!==n)throw new Error('The tagId "'+r+'" is already used by: '+qr.element(o.element())+"\nCannot use it for: "+qr.element(n.element())+"\nThe conflicting element is"+(Br.inBody(o.element())?" ":" not ")+"already in the DOM");t(n)}(r,u);var a=[r];n.registerId(a,u,r.events()),e[u]=r},unregister:t,getById:function(n){return fe.readOpt(n)(e)}}}var qp=function(n){var e=function(e){return Tr.parent(n.element()).fold(function(){return!0},function(n){return bn(e,n)})},t=$p(),r=function(n,r){return t.find(e,n,r)},o=Fp(n.element(),{triggerEvent:function(n,e){return oo(n,e.target(),function(t){return Wp.triggerUntilStopped(r,n,e,t)})},broadcastEvent:function(n,e){var r=t.filter(n);return Wp.broadcast(r,e)}}),i=tl({debugInfo:c.constant("real"),triggerEvent:function(n,e,t){oo(n,e,function(o){Wp.triggerOnUntilStopped(r,n,t,e,o)})},triggerFocus:function(n,e){Sc.read(n).fold(function(){ho(n)},function(t){oo(On.focus(),n,function(t){Wp.triggerHandler(r,On.focus(),{originator:c.constant(e),target:c.constant(n)},n,t)})})},triggerEscape:function(n,e){i.triggerEvent("keydown",n.element(),e.event())},getByUid:function(n){return p(n)},getByDom:function(n){return g(n)},build:Nl.build,addToGui:function(n){s(n)},removeFromGui:function(n){f(n)},addToWorld:function(n){u(n)},removeFromWorld:function(n){a(n)},broadcast:function(n){d(n)},broadcastOn:function(n,e){m(n,e)}}),u=function(n){n.connect(i),$t.isText(n.element())||(t.register(n),E.each(n.components(),u),i.triggerEvent(On.systemInit(),n.element(),{target:c.constant(n.element())}))},a=function(n){$t.isText(n.element())||(E.each(n.components(),a),t.unregister(n)),n.disconnect()},s=function(e){jr.attach(n,e)},f=function(n){jr.detach(n)},l=function(n){var e=t.filter(On.receive());E.each(e,function(e){var t=e.descHandler();hl.getHandler(t)(n)})},d=function(n){l({universal:c.constant(!0),data:c.constant(n)})},m=function(n,e){l({universal:c.constant(!1),channels:c.constant(n),data:c.constant(e)})},p=function(n){return t.getById(n).fold(function(){return Xn.error(new Error('Could not find component with uid: "'+n+'" in system.'))},Xn.value)},g=function(n){return Sc.read(n).bind(p)};return u(n),{root:c.constant(n),element:n.element,destroy:function(){o.unbind(),Mr.remove(n.element())},add:s,remove:f,getByUid:p,getByDom:g,addToWorld:u,removeFromWorld:a,broadcast:d,broadcastOn:m}},_p={create:function(){var n=Nl.build(ef.sketch({dom:{tag:"div"}}));return qp(n)},takeover:qp},Xp=c.constant(Qo.resolve("readonly-mode")),Yp=c.constant(Qo.resolve("edit-mode"));function Jp(n){var e=Nl.build(ef.sketch({dom:{classes:[Qo.resolve("outer-container")].concat(n.classes)},containerBehaviours:jt.derive([gr.config({alpha:Xp(),omega:Yp()})])}));return _p.takeover(e)}var Qp=function(n,e,t,r,o){var i=function(){e.run(function(n){n.refreshSelection()})},u=function(n,t){var o=n-r.dom().scrollTop;e.run(function(n){n.scrollIntoView(o,o+t)})},a=function(){e.run(function(n){n.clearSelection()})},c=function(){n.getCursorBox().each(function(n){u(n.top(),n.height())}),e.run(function(n){n.syncHeight()})},s=Vd(n),f=_m(c,300),l=[n.onKeyup(function(){a(),f.throttle()}),n.onNodeChanged(i),n.onDomChanged(f.throttle),n.onDomChanged(i),n.onScrollToCursor(function(n){n.preventDefault(),f.throttle()}),n.onScrollToElement(function(n){n.element(),u(e,r)}),n.onToEditing(function(){e.run(function(n){n.toEditing()})}),n.onToReading(function(){e.run(function(n){n.toReading()})}),Md.bind(n.doc(),"touchend",function(e){bn(n.html(),e.target())||bn(n.body(),e.target())}),Md.bind(t,"transitionend",function(n){var r;"height"===n.raw().propertyName&&(r=qi(t),e.run(function(n){n.setViewportOffset(r)}),i(),c())}),Md.capture(t,"touchstart",function(t){var r;e.run(function(n){n.highlightSelection()}),r=t,e.run(function(n){n.onToolbarTouch(r)}),n.onTouchToolstrip()}),Md.bind(n.body(),"touchstart",function(e){a(),n.onTouchContent(),s.fireTouchstart(e)}),s.onTouchmove(),s.onTouchend(),Md.bind(n.body(),"click",function(n){n.kill()}),Md.bind(t,"touchmove",function(){n.onToolbarScrollStart()})];return{destroy:function(){E.each(l,function(n){n.unbind()})}}},Zp=function(n){var e=n.getSelection();if(e.rangeCount>0){var t=e.getRangeAt(0),r=n.document.createRange();r.setStart(t.startContainer,t.startOffset),r.setEnd(t.endContainer,t.endOffset),e.removeAllRanges(),e.addRange(r)}},ng={resume:function(n,e){yo().each(function(n){bn(n,e)||vo(n)}),n.focus(),ho(sn.fromDom(n.document.body)),Zp(n)}},eg=function(n){var e=p.none(),t=[],r=function(n){o()?u(n):t.push(n)},o=function(){return e.isSome()},i=function(n){E.each(n,u)},u=function(n){e.each(function(e){setTimeout(function(){n(e)},0)})};return n(function(n){e=p.some(n),i(t),t=[]}),{get:r,map:function(n){return eg(function(e){r(function(t){e(n(t))})})},isReady:o}},tg={nu:eg,pure:function(n){return eg(function(e){e(n)})}},rg=function(n){return function(){var e=Array.prototype.slice.call(arguments),t=this;setTimeout(function(){n.apply(t,e)},0)}},og=function(n){var e=function(e){n(rg(e))};return{map:function(n){return og(function(t){e(function(e){var r=n(e);t(r)})})},bind:function(n){return og(function(t){e(function(e){n(e).get(t)})})},anonBind:function(n){return og(function(t){e(function(e){n.get(t)})})},toLazy:function(){return tg.nu(e)},get:e}},ig={nu:og,pure:function(n){return og(function(e){e(n)})}},ug=function(n,e,t){return Math.abs(n-e)<=t?p.none():n<e?p.some(n+t):p.some(n-t)},ag=function(){var n=null;return{animate:function(e,t,r,o,i,u){var a=!1,c=function(n){a=!0,i(n)};clearInterval(n);var s=function(e){clearInterval(n),c(e)};n=setInterval(function(){var i=e();ug(i,t,r).fold(function(){clearInterval(n),c(t)},function(r){if(o(r,s),!a){var u=e();(u!==r||Math.abs(u-t)>Math.abs(i-t))&&(clearInterval(n),c(t))}})},u)}}},cg=function(n,e){return Xr([{width:320,height:480,keyboard:{portrait:300,landscape:240}},{width:320,height:568,keyboard:{portrait:300,landscape:240}},{width:375,height:667,keyboard:{portrait:305,landscape:240}},{width:414,height:736,keyboard:{portrait:320,landscape:240}},{width:768,height:1024,keyboard:{portrait:320,landscape:400}},{width:1024,height:1366,keyboard:{portrait:380,landscape:460}}],function(t){return n<=t.width&&e<=t.height?p.some(t.keyboard):p.none()}).getOr({portrait:e/5,landscape:n/4})},sg=function(n){var e,t=Fd(n).isPortrait(),r=cg((e=n).screen.width,e.screen.height),o=t?r.portrait:r.landscape;return(t?n.screen.height:n.screen.width)-n.innerHeight>o?0:o},fg=function(n,e){var t=Tr.owner(n).dom().defaultView;return qi(n)+qi(e)-sg(t)},lg=fg,dg=function(n,e,t){var r=fg(e,t),o=qi(e)+qi(t)-r;Ki.set(n,"padding-bottom",o+"px")},mg=Kn([{fixed:["element","property","offsetY"]},{scroller:["element","offsetY"]}]),pg="data-"+Qo.resolve("position-y-fixed"),gg="data-"+Qo.resolve("y-property"),hg="data-"+Qo.resolve("scrolling"),vg="data-"+Qo.resolve("last-window-height"),yg=function(n){return Wd(n,pg)},bg=function(n,e){var t=Jt.get(n,gg);return mg.fixed(n,t,e)},wg=function(n,e){return mg.scroller(n,e)},Sg=function(n){var e=yg(n);return("true"===Jt.get(n,hg)?wg:bg)(n,e)},xg=function(n,e,t){var r=Tr.owner(n).dom().defaultView.innerHeight;return Jt.set(n,vg,r+"px"),r-e-t},Og=function(n){var e=mi(n,"["+pg+"]");return E.map(e,Sg)},Tg=function(n,e,t,r){var o,i,u,a,s,f,l,d,m=Tr.owner(n).dom().defaultView,p=(d=Jt.get(l=t,"style"),Ki.setAll(l,{position:"absolute",top:"0px"}),Jt.set(l,pg,"0px"),Jt.set(l,gg,"top"),{restore:function(){Jt.set(l,"style",d||""),Jt.remove(l,pg),Jt.remove(l,gg)}}),g=qi(t),h=qi(r),v=xg(n,g,h),y=(u=g,a=v,f=Jt.get(s=n,"style"),cd.register(s),Ki.setAll(s,{position:"absolute",height:a+"px",width:"100%",top:u+"px"}),Jt.set(s,pg,u+"px"),Jt.set(s,hg,"true"),Jt.set(s,gg,"top"),{restore:function(){cd.deregister(s),Jt.set(s,"style",f||""),Jt.remove(s,pg),Jt.remove(s,hg),Jt.remove(s,gg)}}),b=(i=Jt.get(o=r,"style"),Ki.setAll(o,{position:"absolute",bottom:"0px"}),Jt.set(o,pg,"0px"),Jt.set(o,gg,"bottom"),{restore:function(){Jt.set(o,"style",i||""),Jt.remove(o,pg),Jt.remove(o,gg)}}),w=!0,S=function(){return m.innerHeight>Wd(n,vg)},x=function(){if(w){var o=qi(t),i=qi(r),u=xg(n,o,i);Jt.set(n,pg,o+"px"),Ki.set(n,"height",u+"px"),Ki.set(r,"bottom",-(o+u+i)+"px"),dg(e,n,r)}};return dg(e,n,r),{setViewportOffset:function(e){Jt.set(n,pg,e+"px"),x()},isExpanding:S,isShrinking:c.not(S),refresh:x,restore:function(){w=!1,p.restore(),y.restore(),b.restore()}}},kg=yg,Cg=ag(),Eg="data-"+Qo.resolve("last-scroll-top"),Dg=function(n){var e=Ki.getRaw(n,"top").getOr(0);return parseInt(e,10)},Ag=function(n){return parseInt(n.dom().scrollTop,10)},Mg=function(n,e){var t=e+kg(n)+"px";Ki.set(n,"top",t)},Rg=function(n,e,t){return ig.nu(function(r){var o=c.curry(Ag,n);Cg.animate(o,e,15,function(e){n.dom().scrollTop=e,Ki.set(n,"top",Dg(n)+15+"px")},function(){n.dom().scrollTop=e,Ki.set(n,"top",t+"px"),r(e)},10)})},Fg=function(n,e){return ig.nu(function(t){var r=c.curry(Ag,n);Jt.set(n,Eg,r());var o=Math.abs(e-r()),i=Math.ceil(o/10);Cg.animate(r,e,i,function(e,t){Wd(n,Eg)!==n.dom().scrollTop?t(n.dom().scrollTop):(n.dom().scrollTop=e,Jt.set(n,Eg,e))},function(){n.dom().scrollTop=e,Jt.set(n,Eg,e),t(e)},10)})},Bg=function(n,e){return ig.nu(function(t){var r=c.curry(Dg,n),o=function(e){Ki.set(n,"top",e+"px")},i=Math.abs(e-r()),u=Math.ceil(i/10);Cg.animate(r,e,u,o,function(){o(e),t(e)},10)})},Ig=function(n,e,t){var r=Tr.owner(n).dom().defaultView;return ig.nu(function(o){Mg(n,t),Mg(e,t),r.scrollTo(0,t),o(t)})},Hg=function(n,e,t,r,o){var i=lg(e,t),u=c.curry(Zp,n);r>i||o>i?Fg(e,e.dom().scrollTop-i+o).get(u):r<0&&Fg(e,e.dom().scrollTop+r).get(u)},Ng=function(n,e){return e(function(e){var t=[],r=0;0===n.length?e([]):E.each(n,function(o,i){var u;o.get((u=i,function(o){t[u]=o,++r>=n.length&&e(t)}))})})},Vg=function(n){return Ng(n,ig.nu)},jg=Vg,Pg=function(n,e){return n.fold(function(n,t,r){return o=n,i=t,a=e+(u=r),Ki.set(o,i,a+"px"),ig.pure(u);var o,i,u,a},function(n,t){return r=n,i=e+(o=t),u=Ki.getRaw(r,"top").getOr(o),a=i-parseInt(u,10),c=r.dom().scrollTop+a,Rg(r,c,i);var r,o,i,u,a,c})},Lg=function(n,e){var t=Og(n),r=E.map(t,function(n){return Pg(n,e)});return jg(r)},Wg=function(n,e){var t=sn.fromTag("input");Ki.setAll(t,{opacity:"0",position:"absolute",top:"-1000px",left:"-1000px"}),Er.append(n,t),ho(t),e(t),Mr.remove(t)},Ug=function(n,e,t,r,o,i){var u,a,s=(u=function(t){return Ig(n,e,t)},a=uo(tg.pure({})),{start:function(n){var e=tg.nu(function(e){return u(n).get(e)});a.set(e)},idle:function(n){a.get().get(function(){n()})}}),f=_m(function(){s.idle(function(){Lg(t,r.pageYOffset).get(function(){var n;(n=Om.getRectangles(i),p.from(n[0]).bind(function(n){var t=n.top()-e.dom().scrollTop;return t>r.innerHeight+5||t<-5?p.some({top:c.constant(t),bottom:c.constant(t+n.height())}):p.none()})).each(function(n){e.dom().scrollTop=e.dom().scrollTop+n.top()}),s.start(0),o.refresh()})})},1e3),l=Md.bind(sn.fromDom(r),"scroll",function(){r.pageYOffset<0||f.throttle()});return Lg(t,r.pageYOffset).get(c.identity),{unbind:l.unbind}},zg=function(n){var e=n.cWin(),t=n.ceBody(),r=n.socket(),o=n.toolstrip(),i=n.toolbar(),u=n.contentElement(),a=n.keyboardType(),s=n.outerWindow(),f=n.dropup(),l=Tg(r,t,o,f),d=a(n.outerBody(),e,Br.body(),u,o,i),m=Bd(s,{onChange:c.noop,onReady:l.refresh});m.onAdjustment(function(){l.refresh()});var p=Md.bind(sn.fromDom(s),"resize",function(){l.isExpanding()&&l.refresh()}),g=Ug(o,r,n.outerBody(),s,l,e),h=function(n,e){var t=n.document,r=sn.fromTag("div");lr.add(r,Qo.resolve("unfocused-selections")),Er.append(sn.fromDom(t.documentElement),r);var o=Md.bind(r,"touchstart",function(t){t.prevent(),ng.resume(n,e),u()}),i=function(n){var e=sn.fromTag("span");return Cl.add(e,[Qo.resolve("layer-editor"),Qo.resolve("unfocused-selection")]),Ki.setAll(e,{left:n.left()+"px",top:n.top()+"px",width:n.width()+"px",height:n.height()+"px"}),e},u=function(){Mr.empty(r)};return{update:function(){u();var e=Om.getRectangles(n),t=E.map(e,i);Dr.append(r,t)},isActive:function(){return Tr.children(r).length>0},destroy:function(){o.unbind(),Mr.remove(r)},clear:u}}(e,u),v=function(){h.clear()};return{toEditing:function(){d.toEditing(),v()},toReading:function(){d.toReading()},onToolbarTouch:function(n){d.onToolbarTouch(n)},refreshSelection:function(){h.isActive()&&h.update()},clearSelection:v,highlightSelection:function(){h.update()},scrollIntoView:function(n,t){Hg(e,r,f,n,t)},updateToolbarPadding:c.noop,setViewportOffset:function(n){l.setViewportOffset(n),Bg(r,n).get(c.identity)},syncHeight:function(){Ki.set(u,"height",u.dom().contentWindow.document.body.scrollHeight+"px")},refreshStructure:l.refresh,destroy:function(){l.restore(),m.destroy(),g.unbind(),p.unbind(),d.destroy(),h.destroy(),Wg(Br.body(),vo)}}},Kg={stubborn:function(n,e,t,r){var o=function(){ng.resume(e,r)},i=Md.bind(t,"keydown",function(n){E.contains(["input","textarea"],$t.name(n.target()))||o()});return{toReading:function(){Wg(n,vo)},toEditing:o,onToolbarTouch:function(){},destroy:function(){i.unbind()}}},timid:function(n,e,t,r){var o=function(){vo(r)};return{toReading:function(){o()},toEditing:function(){ng.resume(e,r)},onToolbarTouch:function(){o()},destroy:c.noop}}},Gg=function(n,e){var t=Km(),r=Mf.value(),o=Mf.value(),i=Mf.api(),u=Mf.api();return{enter:function(){e.hide();var a=sn.fromDom(document);Vm.getActiveApi(n.editor).each(function(e){r.set({socketHeight:Ki.getRaw(n.socket,"height"),iframeHeight:Ki.getRaw(e.frame(),"height"),outerScroll:document.body.scrollTop}),o.set({exclusives:sp.exclusive(a,"."+cd.scrollable())}),lr.add(n.container,Qo.resolve("fullscreen-maximized")),Um(n.container,e.body()),t.maximize(),Ki.set(n.socket,"overflow","scroll"),Ki.set(n.socket,"-webkit-overflow-scrolling","touch"),ho(e.body());var s=vt.immutableBag(["cWin","ceBody","socket","toolstrip","toolbar","dropup","contentElement","cursor","keyboardType","isScrolling","outerWindow","outerBody"],[]);i.set(zg(s({cWin:e.win(),ceBody:e.body(),socket:n.socket,toolstrip:n.toolstrip,toolbar:n.toolbar,dropup:n.dropup.element(),contentElement:e.frame(),cursor:c.noop,outerBody:n.body,outerWindow:n.win,keyboardType:Kg.stubborn,isScrolling:function(){return o.get().exists(function(n){return n.socket.isScrolling()})}}))),i.run(function(n){n.syncHeight()}),u.set(Qp(e,i,n.toolstrip,n.socket,n.dropup))})},refreshStructure:function(){i.run(function(n){n.refreshStructure()})},exit:function(){t.restore(),u.clear(),i.clear(),e.show(),r.on(function(e){e.socketHeight.each(function(e){Ki.set(n.socket,"height",e)}),e.iframeHeight.each(function(e){Ki.set(n.editor.getFrame(),"height",e)}),document.body.scrollTop=e.scrollTop}),r.clear(),o.on(function(n){n.exclusives.unbind()}),o.clear(),lr.remove(n.container,Qo.resolve("fullscreen-maximized")),zm(),cd.deregister(n.toolbar),Ki.remove(n.socket,"overflow"),Ki.remove(n.socket,"-webkit-overflow-scrolling"),vo(n.editor.getFrame()),Vm.getActiveApi(n.editor).each(function(n){n.clearSelection()})}}},$g={produce:function(n){var e=rt.asRawOrDie("Getting IosWebapp schema",$m,n);Ki.set(e.toolstrip,"width","100%"),Ki.set(e.container,"position","relative");var t=Nl.build(Xm(function(){e.setReadOnly(!0),r.enter()},e.translate));e.alloy.add(t);var r=Gg(e,{show:function(){e.alloy.add(t)},hide:function(){e.alloy.remove(t)}});return{setReadOnly:e.setReadOnly,refreshStructure:r.refreshStructure,enter:r.enter,exit:r.exit,destroy:c.noop}}},qg=tinymce.util.Tools.resolve("tinymce.EditorManager"),_g=function(n){var e=fe.readOptFrom(n.settings,"skin_url").fold(function(){return qg.baseURL+"/skins/lightgray"},function(n){return n});return{content:e+"/content.mobile.min.css",ui:e+"/skin.mobile.min.css"}},Xg=function(n,e,t){n.system().broadcastOn([To.formatChanged()],{command:e,state:t})},Yg=function(n,e){var t=Hn.keys(e.formatter.get());E.each(t,function(t){e.formatter.formatChanged(t,function(e){Xg(n,t,e)})}),E.each(["ul","ol"],function(t){e.selection.selectorChanged(t,function(e,r){Xg(n,t,e)})})},Jg=(c.constant(["x-small","small","medium","large","x-large"]),function(n){var e=function(){n._skinLoaded=!0,n.fire("SkinLoaded")};return function(){n.initialized?e():n.on("init",e)}}),Qg=c.constant("toReading"),Zg=c.constant("toEditing");wo.add("mobile",function(n){return{getNotificationManagerImpl:function(){return{open:c.identity,close:c.noop,reposition:c.noop,getArgs:c.identity}},renderUI:function(e){var t=_g(n);!1===Oo(n)?(n.contentCSS.push(t.content),So.DOM.styleSheetLoader.load(t.ui,Jg(n))):Jg(n)();var r,o,i,u,a,s,f,l,d,m,p,g,h,v,y=function(){n.fire("scrollIntoView")},b=sn.fromTag("div"),w=an.detect().os.isAndroid()?(l=y,d=Jp({classes:[Qo.resolve("android-container")]}),m=fp(),p=Mf.api(),g=mp.makeEditSwitch(p),h=mp.makeSocket(),v=Ap.build(c.noop,l),d.add(m.wrapper()),d.add(h),d.add(v.component()),{system:c.constant(d),element:d.element,init:function(n){p.set(Ym.produce(n))},exit:function(){p.run(function(n){n.exit(),td.remove(h,g)})},setToolbarGroups:function(n){var e=m.createGroups(n);m.setGroups(e)},setContextToolbar:function(n){var e=m.createGroups(n);m.setContextToolbar(e)},focusToolbar:function(){m.focus()},restoreToolbar:function(){m.restoreToolbar()},updateMode:function(n){mp.updateMode(h,g,n,d.root())},socket:c.constant(h),dropup:c.constant(v)}):(r=y,o=Jp({classes:[Qo.resolve("ios-container")]}),i=fp(),u=Mf.api(),a=mp.makeEditSwitch(u),s=mp.makeSocket(),f=Ap.build(function(){u.run(function(n){n.refreshStructure()})},r),o.add(i.wrapper()),o.add(s),o.add(f.component()),{system:c.constant(o),element:o.element,init:function(n){u.set($g.produce(n))},exit:function(){u.run(function(n){td.remove(s,a),n.exit()})},setToolbarGroups:function(n){var e=i.createGroups(n);i.setGroups(e)},setContextToolbar:function(n){var e=i.createGroups(n);i.setContextToolbar(e)},focusToolbar:function(){i.focus()},restoreToolbar:function(){i.restoreToolbar()},updateMode:function(n){mp.updateMode(s,a,n,o.root())},socket:c.constant(s),dropup:c.constant(f)}),S=sn.fromDom(e.targetNode);Er.after(S,b),jr.attachSystem(b,w.system());var x=e.targetNode.ownerDocument.defaultView,O=Bd(x,{onChange:function(){w.system().broadcastOn([To.orientationChanged()],{width:Id(x)})},onReady:c.noop}),T=function(e,t,r){!1===r&&n.selection.collapse(),w.setToolbarGroups(r?e.get():t.get()),n.setMode(!0===r?"readonly":"design"),n.fire(!0===r?Qg():Zg()),w.updateMode(r)},k=function(e,t){return n.on(e,t),{unbind:function(){n.off(e)}}};return n.on("init",function(){w.init({editor:{getFrame:function(){return sn.fromDom(n.contentAreaContainer.querySelector("iframe"))},onDomChanged:function(){return{unbind:c.noop}},onToReading:function(n){return k(Qg(),n)},onToEditing:function(n){return k(Zg(),n)},onScrollToCursor:function(e){return n.on("scrollIntoView",function(n){e(n)}),{unbind:function(){n.off("scrollIntoView"),O.destroy()}}},onTouchToolstrip:function(){e()},onTouchContent:function(){var t,r=sn.fromDom(n.editorContainer.querySelector("."+Qo.resolve("toolbar")));(t=r,bo(t).bind(function(n){return w.system().getByDom(n).toOption()})).each(Ln),w.restoreToolbar(),e()},onTapContent:function(e){var t=e.target();"img"===$t.name(t)?(n.selection.select(t.dom()),e.kill()):"a"===$t.name(t)&&w.system().getByDom(sn.fromDom(n.editorContainer)).each(function(n){gr.isAlpha(n)&&xo(t.dom())})}},container:sn.fromDom(n.editorContainer),socket:sn.fromDom(n.contentAreaContainer),toolstrip:sn.fromDom(n.editorContainer.querySelector("."+Qo.resolve("toolstrip"))),toolbar:sn.fromDom(n.editorContainer.querySelector("."+Qo.resolve("toolbar"))),dropup:w.dropup(),alloy:w.system(),translate:c.noop,setReadOnly:function(n){T(s,a,n)}});var e=function(){w.dropup().disappear(function(){w.system().broadcastOn([To.dropupDismissed()],{})})};io("remove this",w.system());var t={label:"The first group",scrollable:!1,items:[Pc.forToolbar("back",function(){n.selection.collapse(),w.exit()},{})]},r={label:"Back to read only",scrollable:!1,items:[Pc.forToolbar("readonly-back",function(){T(s,a,!0)},{})]},o=xd(w,n),i=Od(n.settings,o),u={label:"The extra group",scrollable:!1,items:[]},a=uo([r,{label:"the action group",scrollable:!0,items:i},u]),s=uo([t,{label:"The read only mode group",scrollable:!0,items:[]},u]);Yg(w,n)}),{iframeContainer:w.socket().element().dom(),editorContainer:w.element().dom()}}}})}();