Files
holder/holder.js
2014-08-16 17:30:54 -04:00

12 lines
23 KiB
JavaScript

/*!
Holder - client side image placeholders
Version 2.4.0+brhve
© 2014 Ivan Malopinsky - http://imsky.co
Site: http://imsky.github.io/holder
Issues: https://github.com/imsky/holder/issues
License: http://opensource.org/licenses/MIT
*/
!function(e,t,r){t[e]=r}("onDomReady",this,function(e){"use strict";function t(e){if(!b){if(!a.body)return i(t);for(b=!0;e=S.shift();)i(e)}}function r(e){(y||e.type===s||a[c]===h)&&(n(),t())}function n(){y?(a[x](g,r,d),e[x](s,r,d)):(a[p](v,r),e[p](u,r))}function i(e,t){setTimeout(e,+t>=0?t:1)}function o(e){b?i(e):S.push(e)}null==document.readyState&&document.addEventListener&&(document.addEventListener("DOMContentLoaded",function A(){document.removeEventListener("DOMContentLoaded",A,!1),document.readyState="complete"},!1),document.readyState="loading");var a=e.document,l=a.documentElement,s="load",d=!1,u="on"+s,h="complete",c="readyState",f="attachEvent",p="detachEvent",m="addEventListener",g="DOMContentLoaded",v="onreadystatechange",x="removeEventListener",y=m in a,w=d,b=d,S=[];if(a[c]===h)i(t);else if(y)a[m](g,r,d),e[m](s,r,d);else{a[f](v,r),e[f](u,r);try{w=null==e.frameElement&&l}catch(C){}w&&w.doScroll&&!function E(){if(!b){try{w.doScroll("left")}catch(e){return i(E,50)}n(),t()}}()}return o.version="1.4.0",o.isReady=function(){return b},o}(this)),document.querySelectorAll||(document.querySelectorAll=function(e){var t,r=document.createElement("style"),n=[];for(document.documentElement.firstChild.appendChild(r),document._qsa=[],r.styleSheet.cssText=e+"{x-qsa:expression(document._qsa && document._qsa.push(this))}",window.scrollBy(0,0),r.parentNode.removeChild(r);document._qsa.length;)t=document._qsa.shift(),t.style.removeAttribute("x-qsa"),n.push(t);return document._qsa=null,n}),document.querySelector||(document.querySelector=function(e){var t=document.querySelectorAll(e);return t.length?t[0]:null}),document.getElementsByClassName||(document.getElementsByClassName=function(e){return e=String(e).replace(/^|\s+/g,"."),document.querySelectorAll(e)}),Object.keys||(Object.keys=function(e){if(e!==Object(e))throw TypeError("Object.keys called on non-object");var t,r=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.push(t);return r}),function(e){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";e.atob=e.atob||function(e){e=String(e);var r,n=0,i=[],o=0,a=0;if(e=e.replace(/\s/g,""),e.length%4===0&&(e=e.replace(/=+$/,"")),e.length%4===1)throw Error("InvalidCharacterError");if(/[^+/0-9A-Za-z]/.test(e))throw Error("InvalidCharacterError");for(;n<e.length;)r=t.indexOf(e.charAt(n)),o=o<<6|r,a+=6,24===a&&(i.push(String.fromCharCode(o>>16&255)),i.push(String.fromCharCode(o>>8&255)),i.push(String.fromCharCode(255&o)),a=0,o=0),n+=1;return 12===a?(o>>=4,i.push(String.fromCharCode(255&o))):18===a&&(o>>=2,i.push(String.fromCharCode(o>>8&255)),i.push(String.fromCharCode(255&o))),i.join("")},e.btoa=e.btoa||function(e){e=String(e);var r,n,i,o,a,l,s,d=0,u=[];if(/[^\x00-\xFF]/.test(e))throw Error("InvalidCharacterError");for(;d<e.length;)r=e.charCodeAt(d++),n=e.charCodeAt(d++),i=e.charCodeAt(d++),o=r>>2,a=(3&r)<<4|n>>4,l=(15&n)<<2|i>>6,s=63&i,d===e.length+2?(l=64,s=64):d===e.length+1&&(s=64),u.push(t.charAt(o),t.charAt(a),t.charAt(l),t.charAt(s));return u.join("")}}(this),function(){function e(t,r,n){t.document;var i,o=t.currentStyle[r].match(/([\d\.]+)(%|cm|em|in|mm|pc|pt|)/)||[0,0,""],a=o[1],l=o[2];return n=n?/%|em/.test(l)&&t.parentElement?e(t.parentElement,"fontSize",null):16:n,i="fontSize"==r?n:/width/i.test(r)?t.clientWidth:t.clientHeight,"%"==l?a/100*i:"cm"==l?.3937*a*96:"em"==l?a*n:"in"==l?96*a:"mm"==l?.3937*a*96/10:"pc"==l?12*a*96/72:"pt"==l?96*a/72:a}function t(e,t){var r="border"==t?"Width":"",n=t+"Top"+r,i=t+"Right"+r,o=t+"Bottom"+r,a=t+"Left"+r;e[t]=(e[n]==e[i]&&e[n]==e[o]&&e[n]==e[a]?[e[n]]:e[n]==e[o]&&e[a]==e[i]?[e[n],e[i]]:e[a]==e[i]?[e[n],e[i],e[o]]:[e[n],e[i],e[o],e[a]]).join(" ")}function r(r){var n,i=this,o=r.currentStyle,a=e(r,"fontSize"),l=function(e){return"-"+e.toLowerCase()};for(n in o)if(Array.prototype.push.call(i,"styleFloat"==n?"float":n.replace(/[A-Z]/,l)),"width"==n)i[n]=r.offsetWidth+"px";else if("height"==n)i[n]=r.offsetHeight+"px";else if("styleFloat"==n)i.float=o[n];else if(/margin.|padding.|border.+W/.test(n)&&"auto"!=i[n])i[n]=Math.round(e(r,n,a))+"px";else if(/^outline/.test(n))try{i[n]=o[n]}catch(s){i.outlineColor=o.color,i.outlineStyle=i.outlineStyle||"none",i.outlineWidth=i.outlineWidth||"0px",i.outline=[i.outlineColor,i.outlineWidth,i.outlineStyle].join(" ")}else i[n]=o[n];t(i,"margin"),t(i,"padding"),t(i,"border"),i.fontSize=Math.round(a)+"px"}window.getComputedStyle||(r.prototype={constructor:r,getPropertyPriority:function(){throw new Error("NotSupportedError: DOM Exception 9")},getPropertyValue:function(e){return this[e.replace(/-\w/g,function(e){return e[1].toUpperCase()})]},item:function(e){return this[e]},removeProperty:function(){throw new Error("NoModificationAllowedError: DOM Exception 7")},setProperty:function(){throw new Error("NoModificationAllowedError: DOM Exception 7")},getPropertyCSSValue:function(){throw new Error("NotSupportedError: DOM Exception 9")}},window.getComputedStyle=Window.prototype.getComputedStyle=function(e){return new r(e)})}(),Object.prototype.hasOwnProperty||(Object.prototype.hasOwnProperty=function(e){var t=this.__proto__||this.constructor.prototype;return e in this&&(!(e in t)||t[e]!==this[e])}),function(e,t){e.augment=t()}(this,function(){"use strict";var e=function(){},t=Array.prototype.slice,r=function(r,n){var i=e.prototype="function"==typeof r?r.prototype:r,o=new e,a=n.apply(o,t.call(arguments,2).concat(i));if("object"==typeof a)for(var l in a)o[l]=a[l];if(!o.hasOwnProperty("constructor"))return o;var s=o.constructor;return s.prototype=o,s};return r.defclass=function(e){var t=e.constructor;return t.prototype=e,t},r.extend=function(e,t){return r(e,function(e){return this.uber=e,t})},r}),function(e,t){function r(e,t,r,o){var a=n(r.substr(r.lastIndexOf(e.domain)),e);a&&i(null,o,a,r,t)}function n(e,t){for(var r={theme:f(w.settings.themes.gray,null),stylesheets:t.stylesheets},n=!1,i=e.split("/"),o=i.length,a=0;o>a;a++){var l=i[a];if(w.flags.dimensions.match(l))n=!0,r.dimensions=w.flags.dimensions.output(l);else if(w.flags.fluid.match(l))n=!0,r.dimensions=w.flags.fluid.output(l),r.fluid=!0;else if(w.flags.textmode.match(l))r.textmode=w.flags.textmode.output(l);else if(w.flags.colors.match(l)){var s=w.flags.colors.output(l);r.theme=f(r.theme,s)}else if(t.themes[l])t.themes.hasOwnProperty(l)&&(r.theme=f(t.themes[l],null));else if(w.flags.font.match(l))r.font=w.flags.font.output(l);else if(w.flags.auto.match(l))r.auto=!0;else if(w.flags.text.match(l))r.text=w.flags.text.output(l);else if(w.flags.random.match(l)){null==w.vars.cache.themeKeys&&(w.vars.cache.themeKeys=Object.keys(t.themes));var d=w.vars.cache.themeKeys[0|Math.random()*w.vars.cache.themeKeys.length];r.theme=f(t.themes[d],null)}}return n?r:!1}function i(e,t,r,n,i){var a=r.dimensions,l=r.theme,d=r.text?decodeURIComponent(r.text):r.text,h=a.width+"x"+a.height;e=null==e?r.fluid?"fluid":"image":e,d&&(l.text=d);var c=f(i,null);r.font&&(l.font=r.font,!c.noFontFallback&&"img"===t.nodeName.toLowerCase()&&w.setup.supportsCanvas&&(c=f(c,{renderer:"canvas"}))),r.font&&"canvas"==c.renderer&&(c.reRender=!0),"background"==e?null==t.getAttribute("data-background-src")&&t.setAttribute("data-background-src",n):t.setAttribute("data-src",n),r.theme=l,t.holderData={flags:r,renderSettings:c},("image"==e||"fluid"==e)&&t.setAttribute("alt",d?d:l.text?l.text+" ["+h+"]":h),"image"==e?("html"!=c.renderer&&r.auto||(t.style.width=a.width+"px",t.style.height=a.height+"px"),"html"==c.renderer?t.style.backgroundColor=l.background:(o(e,{dimensions:a,theme:l,flags:r},t,c),r.textmode&&"exact"==r.textmode&&(w.vars.resizableImages.push(t),s(t)))):"background"==e&&"html"!=c.renderer?o(e,{dimensions:a,theme:l,flags:r},t,c):"fluid"==e&&("%"==a.height.slice(-1)?t.style.height=a.height:null!=r.auto&&r.auto||(t.style.height=a.height+"px"),"%"==a.width.slice(-1)?t.style.width=a.width:null!=r.auto&&r.auto||(t.style.width=a.width+"px"),("inline"==t.style.display||""===t.style.display||"none"==t.style.display)&&(t.style.display="block"),u(t),"html"==c.renderer?t.style.backgroundColor=l.background:(w.vars.resizableImages.push(t),s(t)))}function o(e,t,r,n){function i(){var e=null;switch(n.renderer){case"canvas":e=C(s);break;case"svg":e=A(s,n);break;default:throw"Holder: invalid renderer: "+n.renderer}return e}{var o=null,l={width:t.dimensions.width,height:t.dimensions.height,theme:t.theme,flags:t.flags},s=a(l);({text:l.text,width:l.width,height:l.height,textHeight:l.font.size,font:l.font.family,fontWeight:l.font.weight,template:l.theme})}if(o=i(),null==o)throw"Holder: couldn't render placeholder";"background"==e?(r.style.backgroundImage="url("+o+")",r.style.backgroundSize=l.width+"px "+l.height+"px"):("img"===r.nodeName.toLowerCase()?r.setAttribute("src",o):"object"===r.nodeName.toLowerCase()&&(r.setAttribute("data",o),r.setAttribute("type","image/svg+xml")),n.reRender&&setTimeout(function(){var e=i();if(null==e)throw"Holder: couldn't render placeholder";"img"===r.nodeName.toLowerCase()?r.setAttribute("src",e):"object"===r.nodeName.toLowerCase()&&(r.setAttribute("data",e),r.setAttribute("type","image/svg+xml"))},100)),r.setAttribute("data-holder-rendered",!0)}function a(e){function t(e,t,r,n){t.width=r,t.height=n,e.width=Math.max(e.width,t.width),e.height+=t.height,e.add(t)}switch(e.font={family:e.theme.font?e.theme.font:"Arial, Helvetica, Open Sans, sans-serif",size:l(e.width,e.height,e.theme.size?e.theme.size:12),weight:e.theme.fontweight?e.theme.fontweight:"bold"},e.text=e.theme.text?e.theme.text:Math.floor(e.width)+"x"+Math.floor(e.height),e.flags.textmode){case"literal":e.text=e.flags.dimensions.width+"x"+e.flags.dimensions.height;break;case"exact":if(!e.flags.exactDimensions)break;e.text=Math.floor(e.flags.exactDimensions.width)+"x"+Math.floor(e.flags.exactDimensions.height)}var r=new E({width:e.width,height:e.height}),n=r.Shape,i=new n.Rect("holderBg",{fill:e.theme.background});i.resize(e.width,e.height),r.root.add(i);var o=new n.Group("holderTextGroup",{text:e.text,align:"center",font:e.font,fill:e.theme.foreground});o.moveTo(null,null,1),r.root.add(o);var a=o.textPositionData=S(r);if(!a)throw"Holder: staging fallback not supported yet.";o.properties.leading=a.boundingBox.height;var s=null,d=null;if(a.lineCount>1){var u=0,h=0,c=e.width*w.setup.lineWrapRatio,f=0;d=new n.Group("line"+f);for(var p=0;p<a.words.length;p++){var m=a.words[p];s=new n.Text(m.text);var g="\\n"==m.text;(u+m.width>=c||g===!0)&&(t(o,d,u,o.properties.leading),u=0,h+=o.properties.leading,f+=1,d=new n.Group("line"+f),d.y=h),g!==!0&&(s.moveTo(u,0),u+=a.spaceWidth+m.width,d.add(s))}t(o,d,u,o.properties.leading);for(var v in o.children)d=o.children[v],d.moveTo((o.width-d.width)/2,null,null);o.moveTo((e.width-o.width)/2,(e.height-o.height)/2,null),(e.height-o.height)/2<0&&o.moveTo(null,0,null)}else s=new n.Text(e.text),d=new n.Group("line0"),d.add(s),o.add(d),o.moveTo((e.width-a.boundingBox.width)/2,(e.height-a.boundingBox.height)/2,null);return r}function l(e,t,r){t=parseInt(t,10),e=parseInt(e,10);var n=Math.max(t,e),i=Math.min(t,e),o=1/12,a=Math.min(.75*i,.75*n*o);return Math.round(Math.max(r,a))}function s(e){var t;t=null==e||null==e.nodeType?w.vars.resizableImages:[e];for(var r in t)if(t.hasOwnProperty(r)){var n=t[r];if(n.holderData){var i=n.holderData.flags,a=d(n,y.invisibleErrorFn(s));if(a){if(i.fluid&&i.auto){var l=n.holderData.fluidConfig;switch(l.mode){case"width":a.height=a.width/l.ratio;break;case"height":a.width=a.height*l.ratio}}var u={dimensions:a,theme:i.theme,flags:i};i.textmode&&"exact"==i.textmode&&(i.exactDimensions=a,u.dimensions=i.dimensions),o("image",u,n,n.holderData.renderSettings)}}}}function d(e,t){var r={height:e.clientHeight,width:e.clientWidth};return r.height||r.width?(e.removeAttribute("data-holder-invisible"),r):(e.setAttribute("data-holder-invisible",!0),void t.call(this,e))}function u(e){if(e.holderData){var t=d(e,y.invisibleErrorFn(u));if(t){var r=e.holderData.flags,n={fluidHeight:"%"==r.dimensions.height.slice(-1),fluidWidth:"%"==r.dimensions.width.slice(-1),mode:null,initialDimensions:t};n.fluidWidth&&!n.fluidHeight?(n.mode="width",n.ratio=n.initialDimensions.width/parseFloat(r.dimensions.height)):!n.fluidWidth&&n.fluidHeight&&(n.mode="height",n.ratio=parseFloat(r.dimensions.width)/n.initialDimensions.height),e.holderData.fluidConfig=n}}}function h(e,t,r){if(null==e){e=document.createElementNS(b,"svg");var n=document.createElementNS(b,"defs");e.appendChild(n)}return e.webkitMatchesSelector&&e.setAttribute("xmlns",b),e.setAttribute("width",t),e.setAttribute("height",r),e.setAttribute("viewBox","0 0 "+t+" "+r),e.setAttribute("preserveAspectRatio","none"),e}function c(e,r){if(t.XMLSerializer){var n=new XMLSerializer,i="",o=r.stylesheets,a=e.querySelector("defs");if(r.svgXMLStylesheet){for(var l=(new DOMParser).parseFromString("<xml />","application/xml"),s=o.length-1;s>=0;s--){var d=l.createProcessingInstruction("xml-stylesheet",'href="'+o[s]+'" rel="stylesheet"');l.insertBefore(d,l.firstChild)}l.removeChild(l.documentElement),i=n.serializeToString(l)}if(r.svgLinkStylesheet)for(a.removeChild(a.firstChild),s=0;s<o.length;s++){var u=document.createElementNS("http://www.w3.org/1999/xhtml","link");u.setAttribute("href",o[s]),u.setAttribute("rel","stylesheet"),u.setAttribute("type","text/css"),a.appendChild(u)}if(r.svgImportStylesheet){var h=document.createElementNS(b,"style"),c=[];for(s=0;s<o.length;s++)c.push("@import url("+o[s]+");");var f=document.createTextNode(c.join("\n"));h.appendChild(f),a.appendChild(h)}return i+n.serializeToString(e)}}function f(e,t){var r={};for(var n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);if(null!=t)for(var i in t)t.hasOwnProperty(i)&&(r[i]=t[i]);return r}function p(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(r+":"+e[r]);return t.join(";")}function m(e){w.vars.debounceTimer||e.call(this),w.vars.debounceTimer&&clearTimeout(w.vars.debounceTimer),w.vars.debounceTimer=setTimeout(function(){w.vars.debounceTimer=null,e.call(this)},w.setup.debounce)}function g(){m(function(){s(null)})}function v(e){var r=null;return"string"==typeof e?r=document.querySelectorAll(e):t.NodeList&&e instanceof t.NodeList?r=e:t.Node&&e instanceof t.Node?r=[e]:t.HTMLCollection&&e instanceof t.HTMLCollection?r=e:null===e&&(r=[]),r}function x(e,t){var r=new Image;r.onerror=function(){t.call(this,!1,e)},r.onload=function(){t.call(this,!0,e)},r.src=e.src}var y={addTheme:function(e,t){return null!=e&&null!=t&&(w.settings.themes[e]=t),delete w.vars.cache.themeKeys,this},addImage:function(e,t){var r=document.querySelectorAll(t);if(r.length)for(var n=0,i=r.length;i>n;n++){var o=document.createElement("img");o.setAttribute("data-src",e),r[n].appendChild(o)}return this},run:function(e){var o={};w.vars.preempted=!0;var a=f(w.settings,e);o.renderer=a.renderer?a.renderer:w.setup.renderer,-1===w.setup.renderers.join(",").indexOf(o.renderer)&&(o.renderer=w.setup.supportsSVG?"svg":w.setup.supportsCanvas?"canvas":"html"),a.use_canvas?o.renderer="canvas":a.use_svg&&(o.renderer="svg");var l=v(a.images),s=v(a.bgnodes),d=v(a.stylenodes),u=v(a.objects);o.stylesheets=[],o.svgXMLStylesheet=!0,o.noFontFallback=a.noFontFallback?a.noFontFallback:!1;for(var h=0;h<d.length;h++){var c=d[h];if(c.attributes.rel&&c.attributes.href&&"stylesheet"==c.attributes.rel.value){var p=c.attributes.href.value,m=document.createElement("a");m.href=p;var g=m.protocol+"//"+m.host+m.pathname+m.search;o.stylesheets.push(g)}}for(h=0;h<s.length;h++){var y=t.getComputedStyle(s[h],null).getPropertyValue("background-image"),b=s[h].getAttribute("data-background-src"),S=null;S=null==b?y:b;var C=null,A="?"+a.domain+"/";if(0===S.indexOf(A))C=S.slice(1);else if(-1!=S.indexOf(A)){var E=S.substr(S.indexOf(A)).slice(1),k=E.match(/([^\"]*)"?\)/);null!=k&&(C=k[1])}if(null!=C){var T=n(C,a);T&&i("background",s[h],T,C,o)}}for(h=0;h<u.length;h++){var O=u[h],z={};try{z.data=O.getAttribute("data"),z.dataSrc=O.getAttribute("data-src")}catch(F){}var M=null!=z.data&&0===z.data.indexOf(a.domain),D=null!=z.dataSrc&&0===z.dataSrc.indexOf(a.domain);M?r(a,o,z.data,O):D&&r(a,o,z.dataSrc,O)}for(h=0;h<l.length;h++){var L=l[h],N={};try{N.src=L.getAttribute("src"),N.dataSrc=L.getAttribute("data-src"),N.rendered=L.getAttribute("data-holder-rendered")}catch(F){}var B=null!=N.src,j=null!=N.dataSrc&&0===N.dataSrc.indexOf(a.domain),P=null!=N.rendered&&"true"==N.rendered;B?0===N.src.indexOf(a.domain)?r(a,o,N.src,L):j&&(P?r(a,o,N.dataSrc,L):x({src:N.src,options:a,renderSettings:o,dataSrc:N.dataSrc,image:L},function(e,t){e||r(t.options,t.renderSettings,t.dataSrc,t.image)})):j&&r(a,o,N.dataSrc,L)}return this},invisibleErrorFn:function(){return function(e){if(e.hasAttribute("data-holder-invisible"))throw"Holder: invisible placeholder"}}};y.add_theme=y.addTheme,y.add_image=y.addImage,y.invisible_error_fn=y.invisibleErrorFn;var w={settings:{domain:"holder.js",images:"img",objects:"object",bgnodes:"body .holderjs",stylenodes:"head link.holderjs",stylesheets:[],themes:{gray:{background:"#EEEEEE",foreground:"#AAAAAA"},social:{background:"#3a5a97",foreground:"#FFFFFF"},industrial:{background:"#434A52",foreground:"#C2F200"},sky:{background:"#0D8FDB",foreground:"#FFFFFF"},vine:{background:"#39DBAC",foreground:"#1E292C"},lava:{background:"#F8591A",foreground:"#1C2846",size:12}}},flags:{dimensions:{regex:/^(\d+)x(\d+)$/,output:function(e){var t=this.regex.exec(e);return{width:+t[1],height:+t[2]}}},fluid:{regex:/^([0-9]+%?)x([0-9]+%?)$/,output:function(e){var t=this.regex.exec(e);return{width:t[1],height:t[2]}}},colors:{regex:/(?:#|\^)([0-9a-f]{3,})\:(?:#|\^)([0-9a-f]{3,})/i,output:function(e){var t=this.regex.exec(e);return{foreground:"#"+t[2],background:"#"+t[1]}}},text:{regex:/text\:(.*)/,output:function(e){return this.regex.exec(e)[1]}},font:{regex:/font\:(.*)/,output:function(e){return this.regex.exec(e)[1]}},auto:{regex:/^auto$/},textmode:{regex:/textmode\:(.*)/,output:function(e){return this.regex.exec(e)[1]}},random:{regex:/^random$/}}},b="http://www.w3.org/2000/svg",S=function(){var e=null,t=null,r=null;return function(n){var i=n.root;if(w.setup.supportsSVG){var o=!1,a=function(e){return document.createTextNode(e)};null==e&&(o=!0),e=h(e,i.properties.width,i.properties.height),o&&(t=document.createElementNS(b,"text"),r=a(null),t.setAttribute("x",0),t.appendChild(r),e.appendChild(t),document.body.appendChild(e),e.style.visibility="hidden",e.style.position="absolute",e.style.top="-100%",e.style.left="-100%");var l=i.children.holderTextGroup,s=l.properties;t.setAttribute("y",s.font.size),t.setAttribute("style",p({"font-weight":s.font.weight,"font-size":s.font.size+"px","font-family":s.font.family,"dominant-baseline":"middle"})),r.nodeValue=s.text;var d=t.getBBox(),u=Math.ceil(d.width/(i.properties.width*w.setup.lineWrapRatio)),c=s.text.split(" "),f=s.text.match(/\\n/g);u+=null==f?0:f.length,r.nodeValue=s.text.replace(/[ ]+/g,"");var m=t.getComputedTextLength(),g=d.width-m,v=Math.round(g/Math.max(1,c.length-1)),x=[];if(u>1){r.nodeValue="";for(var y=0;y<c.length;y++)if(0!==c[y].length){r.nodeValue=c[y];var S=t.getBBox();x.push({text:c[y],width:S.width})}}return{spaceWidth:v,lineCount:u,boundingBox:d,words:x}}return!1}}(),C=function(){var e=document.createElement("canvas"),t=e.getContext("2d");return function(r){var n=r.root;e.width=w.dpr(n.properties.width),e.height=w.dpr(n.properties.height),t.textBaseline="middle",t.fillStyle=n.children.holderBg.properties.fill,t.fillRect(0,0,w.dpr(n.children.holderBg.width),w.dpr(n.children.holderBg.height));{var i=n.children.holderTextGroup;i.properties}t.font=i.properties.font.weight+" "+w.dpr(i.properties.font.size)+"px "+i.properties.font.family+", monospace",t.fillStyle=i.properties.fill;for(var o in i.children){var a=i.children[o];for(var l in a.children){var s=a.children[l],d=w.dpr(i.x+a.x+s.x),u=w.dpr(i.y+a.y+s.y+i.properties.leading/2);t.fillText(s.properties.text,d,u)}}return e.toDataURL("image/png")}}(),A=function(){if(t.XMLSerializer){var e=h(null,0,0),r=document.createElementNS(b,"rect");return e.appendChild(r),function(t,n){var i=t.root;h(e,i.properties.width,i.properties.height);for(var o=e.querySelectorAll("g"),a=0;a<o.length;a++)o[a].parentNode.removeChild(o[a]);r.setAttribute("width",i.children.holderBg.width),r.setAttribute("height",i.children.holderBg.height),r.setAttribute("fill",i.children.holderBg.properties.fill);var l=i.children.holderTextGroup,s=l.properties,d=document.createElementNS(b,"g");e.appendChild(d);for(var u in l.children){var f=l.children[u];for(var m in f.children){var g=f.children[m],v=l.x+f.x+g.x,x=l.y+f.y+g.y+l.properties.leading/2,y=document.createElementNS(b,"text"),w=document.createTextNode(null);y.setAttribute("x",v),y.setAttribute("y",x),y.setAttribute("style",p({fill:s.fill,"font-weight":s.font.weight,"font-family":s.font.family+", monospace","font-size":s.font.size+"px","dominant-baseline":"middle"})),w.nodeValue=g.properties.text,y.appendChild(w),d.appendChild(y)}}var S="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(c(e,n))));return S}}}(),E=function(e){function t(e,t){for(var r in t)e[r]=t[r];return e}var r=1,n=augment.defclass({constructor:function(e){r++,this.parent=null,this.children={},this.id=r,this.name="n"+r,null!=e&&(this.name=e),this.x=0,this.y=0,this.z=0,this.width=0,this.height=0},resize:function(e,t){null!=e&&(this.width=e),null!=t&&(this.height=t)},moveTo:function(e,t,r){this.x=null!=e?e:this.x,this.y=null!=t?t:this.y,this.z=null!=r?r:this.z},add:function(e){var t=e.name;if(null!=this.children[t])throw"SceneGraph: child with that name already exists: "+t;this.children[t]=e,e.parent=this}}),i=augment(n,function(t){this.constructor=function(){t.constructor.call(this,"root"),this.properties=e}}),o=augment(n,function(e){function r(r,n){if(e.constructor.call(this,r),this.properties={fill:"#000"},null!=n)t(this.properties,n);else if(null!=r&&"string"!=typeof r)throw"SceneGraph: invalid node name"}this.Group=augment.extend(this,{constructor:r,type:"group"}),this.Rect=augment.extend(this,{constructor:r,type:"rect"}),this.Text=augment.extend(this,{constructor:function(e){r.call(this),this.properties.text=e},type:"text"})}),a=new i;return this.Shape=o,this.root=a,this};for(var k in w.flags)w.flags.hasOwnProperty(k)&&(w.flags[k].match=function(e){return e.match(this.regex)});w.setup={renderer:"html",debounce:100,ratio:1,supportsCanvas:!1,supportsSVG:!1,lineWrapRatio:.9,renderers:["html","canvas","svg"]},w.dpr=function(e){return e*w.setup.ratio},w.vars={preempted:!1,resizableImages:[],debounceTimer:null,cache:{}},function(){var e=1,r=1,n=document.createElement("canvas"),i=null;n.getContext&&-1!=n.toDataURL("image/png").indexOf("data:image/png")&&(w.setup.renderer="canvas",i=n.getContext("2d"),w.setup.supportsCanvas=!0),w.setup.supportsCanvas&&(e=t.devicePixelRatio||1,r=i.webkitBackingStorePixelRatio||i.mozBackingStorePixelRatio||i.msBackingStorePixelRatio||i.oBackingStorePixelRatio||i.backingStorePixelRatio||1),w.setup.ratio=e/r,document.createElementNS&&document.createElementNS(b,"svg").createSVGRect&&(w.setup.renderer="svg",w.setup.supportsSVG=!0)}(),e(y,"Holder",t),t.onDomReady&&t.onDomReady(function(){w.vars.preempted||y.run({}),t.addEventListener?(t.addEventListener("resize",g,!1),t.addEventListener("orientationchange",g,!1)):t.attachEvent("onresize",g),"object"==typeof t.Turbolinks&&t.document.addEventListener("page:change",function(){y.run({})})})}(function(e,t,r){var n="function"==typeof define&&define.amd;n?define(e):r[t]=e},this);