|
Server : LiteSpeed System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64 User : nandedex ( 1060) PHP Version : 8.1.33 Disable Function : NONE Directory : /home/nandedex/.cagefs/tmp/ |
!function(e,t,s){var i={model:{},collection:{},view:{},fn:{}},r=function(e,t){for(var s=[],i=SPECIFICITY.calculate(e),o=0;o<i.length;o++){var c=i[o];if(t)for(var a=0;a<c.parts.length;a++){var n=c.parts[a];s=s.concat(r(n.selector))}else s.push({selector:c.selector.trim(),specificity:parseInt(c.specificity.replace(/,/g,""))})}return s};i.view.inspector=Backbone.View.extend({active:!1,hl:!1,hoverEl:!1,pageSelectors:[],selectorTemplate:t.template('<div class="socss-selector"><%= selector %></div>'),importantClasses:["menu-item-","postid-","page-id-"],initialize:function(){var t=this;this.hl=new i.view.highlighter,this.hl.initialize(),this.pageSelectors=i.fn.pageSelectors(),e("body").on("mouseover","*",(function(s){if(!t.active)return!0;0===e(this).closest(".socss-element").length&&(s.stopPropagation(),t.setHoverEl(e(this)))}));var s=e(".single-product").length;e("body *").on("click",(function(i){if(!t.active||e(i.target).parent(".socss-link").length)return!0;var r=e(this);s&&r.parents(".wc-tabs").length||(i.preventDefault(),r.trigger("blur"),t.setActiveEl(t.hoverEl))})),this.$(".socss-enable-inspector").on("click",(function(){t.toggleActive()})),this.$el.on("mouseenter",(function(){t.hl.clear()}));try{parent.socss.mainEditor.setInspector(this)}catch(e){console.log("No editor to register this inspector with")}},setHoverEl:function(e){this.hoverEl=e,this.hl.highlight(e)},activate:function(){this.active=!0,e("body").addClass("socss-active"),e("body").removeClass("socss-inactive")},deactivate:function(){this.active=!1,e("body").addClass("socss-inactive"),e("body").removeClass("socss-active"),this.hl.clear(),this.$(".socss-hierarchy").empty()},toggleActive:function(){this.active?this.deactivate():this.activate()},setActiveEl:function(s){var r=this,o=this.$(".socss-hierarchy");if(o.empty(),s){if("body"!==s.prop("tagName").toLowerCase()){var c=e(s);do{var a=i.fn.elSelector(c);r.importantClasses.forEach((function(e){if(a.indexOf(e)>=0){var t=new RegExp("("+e+"\\d+)","g");a=a.replace(t,"<strong>$1</strong>")}})),e(this.selectorTemplate({selector:a})).prependTo(o).data("el",c),c=c.parent()}while("body"!==c.prop("tagName").toLowerCase());e(this.selectorTemplate({selector:"body"})).prependTo(o).data("el",e("body")),this.$(".socss-hierarchy .socss-selector").on("mouseenter",(function(){r.hl.highlight(e(this).data("el"))})).on("click",(function(t){t.preventDefault(),t.stopPropagation(),r.setActiveEl(e(this).data("el"))}))}o.scrollLeft(99999);var n=this.pageSelectors.filter((function(e){try{return s.is(e.selector)}catch(e){return!1}})),l=this.$(".socss-selectors-window").empty();t.each(n,(function(t){l.append(e(r.selectorTemplate(t)).data(t))})),l.find("> div").on("mouseenter",(function(){r.hl.highlight(e(this).data("selector"))})).on("click",(function(t){t.preventDefault(),t.stopPropagation(),r.trigger("click_selector",e(this).data("selector"))}));var h=i.fn.elementAttributes(s);l=this.$(".socss-properties-window").empty(),t.each(h,(function(t,s){l.append(e(r.selectorTemplate({selector:"<strong>"+s+"</strong>: "+t})).data("property",s+": "+t))})),l.find("> div").on("click",(function(t){t.preventDefault(),t.stopPropagation(),r.trigger("click_property",e(this).data("property"))}));var p=s.closest("a[href]"),f=this.$(".socss-link");p.length?f.show().find("a").html(p.attr("href").replace(/[\?&]*so_css_preview=1/,"")).attr("href",p.attr("href")):f.hide(),this.trigger("set_active_element",s,n)}}}),i.view.highlighter=Backbone.View.extend({template:t.template(e("#socss-template-hover").html().trim()),highlighted:[],highlight:function(t){this.clear();var s=this;e(t).each((function(t,i){if(!(i=e(i)).is(":visible"))return!0;var r,o=e(s.template());o.css({top:i.offset().top,left:i.offset().left,width:i.outerWidth(),height:i.outerHeight()}).appendTo("body");var c=i.padding();for(var a in c)parseInt(c[a])>0&&(r=o.find(".socss-guide-padding.socss-guide-"+a).show(),"top"===a||"bottom"===a?r.css("height",c[a]):(r.css("width",c[a]),r.css({width:c[a],top:c.top,bottom:c.bottom})));var n=i.margin();for(var a in n)parseInt(n[a])>0&&(r=o.find(".socss-guide-margin.socss-guide-"+a).show(),"top"===a||"bottom"===a?r.css("height",n[a]):r.css("width",n[a]));s.highlighted.push(o)}))},clear:function(){for(;this.highlighted.length;)this.highlighted.pop().remove()}}),i.parsedCss={},i.fn.getParsedCss=function(){if(0===Object.keys(i.parsedCss).length){var t=window.css;e(".socss-theme-styles").each((function(){var s=e(this),r=t.parse(s.html(),{silent:!0});i.parsedCss[s.attr("id")]=r}))}return i.parsedCss},i.fn.pageSelectors=function(){var s=[],o=i.fn.getParsedCss();for(var c in o)for(var a=o[c].stylesheet.rules,n=0;n<a.length;n++)if(void 0!==a[n].selectors)for(var l=0;l<a[n].selectors.length;l++)s=s.concat(r(a[n].selectors[l]));e("body *").each((function(){var t=e(this),o=i.fn.elSelector(t);s=s.concat(r(o))}));var h=e("body"),p=i.fn.elSelector(h);return s=s.concat(r(p,!0)),(s=t.uniq(s,!1,(function(e){return e.selector}))).sort((function(e,t){return e.specificity>t.specificity?-1:1})),s},i.fn.elementAttributes=function(e){if(!document.styleSheets)return[];var t=[],s=i.fn.getParsedCss(),r=function(e){switch(e){case"charset":case"custom-media":case"document":case"font-face":case"host":case"import":case"keyframes":case"keyframe":case"media":case"namespace":case"page":case"supports":return!0}return!1};for(var o in s)for(var c=s[o].stylesheet.rules,a=0;a<c.length;a++){var n=c[a];if(void 0!==n.selectors&&!r(n.type))for(var l=0;l<n.selectors.length;l++)for(var h=SPECIFICITY.calculate(n.selectors[l]),p=0;p<h.length;p++)try{if(e.is(h[p].selector)){var f=n.declarations;for(p=0;p<f.length;p++)t.push({name:f[p].property,value:f[p].value,specificity:parseInt(h[p].specificity.replace(/,/g,""))})}}catch(e){}}t.sort((function(e,t){return e.specificity>t.specificity?1:-1})).reverse();for(var d={},v=0;v<t.length;v++)void 0===d[t[v].name]&&(d[t[v].name]=t[v].value);return d},i.fn.elSelector=function(e){var t="";return void 0!==e.attr("id")&&(t+="#"+e.attr("id")),void 0!==e.attr("class")&&(t+="."+e.attr("class").replace(/\s+/g,".")),""===t&&(t=e.prop("tagName").toLowerCase()),t},window.socssInspector=i}(jQuery,_,socssOptions),jQuery((function(e){var t=new window.socssInspector.view.inspector({el:e("#socss-inspector-interface").get(0)});t.activate(),window.socssInspector.mainInspector=t}));!function(e,t,i){var s={model:{},collection:{},view:{},fn:{}};window.socss=s,s.model.CustomCssModel=Backbone.Model.extend({defaults:{postId:null,postTitle:null,css:null},urlRoot:i.postCssUrlRoot,url:function(){return this.urlRoot+"&postId="+this.get("postId")}}),s.model.CustomCssCollection=Backbone.Collection.extend({model:s.model.CustomCssModel,modelId:function(e){return e.postId}}),s.model.CSSEditorModel=Backbone.Model.extend({defaults:{customCssPosts:null}}),s.view.toolbar=Backbone.View.extend({button:t.template('<li><a href="#<%= action %>" class="toolbar-button socss-button"><%= text %></a></li>'),events:{"click .socss-button:not(.save)":"triggerEvent"},triggerEvent:function(t){t.preventDefault();var i=e(t.currentTarget);i.trigger("blur");var s=i.attr("href").replace("#","");this.$el.trigger("click_"+s)},addButton:function(t,i){return e(this.button({text:t,action:i})).appendTo(this.$(".toolbar-function-buttons .toolbar-buttons"))}}),s.view.editor=Backbone.View.extend({codeMirror:null,snippets:null,toolbar:null,visualProperties:null,inspector:null,cssSelectors:[],initValue:null,events:{"click_expand .custom-css-toolbar":"toggleExpand","click_visual .custom-css-toolbar":"showVisualEditor","click .socss-button.save":"save",submit:"onSubmit"},initialize:function(e){this.listenTo(this.model,"change:selectedPost",this.getSelectedPostCss),this.getSelectedPostCss().then(function(){e.openVisualEditor&&this.showVisualEditor()}.bind(this))},save:function(){s.save(this)},getSelectedPostCss:function(){var t=this.model.get("selectedPost");return(t&&!t.has("css")?t.fetch():(new e.Deferred).resolve()).then(this.render.bind(this))},render:function(){var t=this.model.get("selectedPost");return t&&!t.has("css")?this:(this.codeMirror||this.setupEditor(),this.toolbar||(this.toolbar=new s.view.toolbar({el:this.$(".custom-css-toolbar"),model:this.model}),this.toolbar.render()),this.visualProperties||(this.visualProperties=new s.view.properties({editor:this,el:e("#so-custom-css-properties")}),this.visualProperties.render()),this.preview||(this.preview=new s.view.preview({editor:this,model:this.model,el:this.$(".custom-css-preview"),initURL:i.homeURL}),this.preview.render()),t&&(this.codeMirror.setValue(t.get("css")),this.codeMirror.clearHistory()),this)},setupEditor:function(){var s=this.$("textarea.css-editor");this.initValue=s.val();var o=this.initValue.match(/\n/gm),r=(o&&o.length,this.initValue);s.val(r);var n={tabSize:2,lineNumbers:!0,mode:"css",theme:s.data("theme"),inputStyle:"contenteditable",gutters:["CodeMirror-lint-markers"],lint:!0,search:!0,dialog:!0,annotateScrollbar:!0,extraKeys:{"Ctrl-F":"findPersistent","Alt-G":"jumpToLine"}};void 0!==wp.codeEditor?(n=t.extend(wp.codeEditor.defaultSettings.codemirror,n),this.codeMirror=wp.codeEditor.initialize(s.get(0),n).codemirror):(this.registerCodeMirrorAutocomplete(),this.codeMirror=CodeMirror.fromTextArea(s.get(0),n),this.setupCodeMirrorExtensions());var l=this.codeMirror;e("#so_css_editor_theme").on("change",(function(){1==e(this).val()?l.setOption("theme","neat"):l.setOption("theme","ambiance")})),this.codeMirror.on("change",function(e,t){var i=this.model.get("selectedPost");i&&i.get("css")!==e.getValue().trim()&&i.set("css",e.getValue().trim())}.bind(this)),e(window).on("beforeunload",function(){if(this.codeMirror.getValue().trim()!==this.initValue)return i.loc.leave}.bind(this)),this.$el.find(".custom-css-container").css("overflow","visible"),this.scaleEditor(),e(window).on("resize",function(){this.scaleEditor()}.bind(this))},onSubmit:function(){this.initValue=this.codeMirror.getValue().trim()},registerCodeMirrorAutocomplete:function(){var e={link:1,visited:1,active:1,hover:1,focus:1,"first-letter":1,"first-line":1,"first-child":1,before:1,after:1,lang:1};CodeMirror.registerHelper("hint","css",function(t){var i=t.getCursor(),s=t.getTokenAt(i),o=CodeMirror.innerMode(t.getMode(),s.state);if("css"===o.mode.name){if("keyword"===s.type&&0==="!important".indexOf(s.string))return{list:["!important"],from:CodeMirror.Pos(i.line,s.start),to:CodeMirror.Pos(i.line,s.end)};var r=s.start,n=i.ch,l=s.string.slice(0,n-r);/[^\w$_-]/.test(l)&&(l="",r=n=i.ch);var a=CodeMirror.resolveMode("text/css"),c=[],d=o.state.state;if("top"===d){for(var p=t.getLine(i.line).trim(),h=this.cssSelectors,u=0;u<h.length;u++)-1!==h[u].selector.indexOf(p)&&c.push(h[u].selector);if(c.length)return{list:c,from:CodeMirror.Pos(i.line,0),to:CodeMirror.Pos(i.line,n)}}else if("pseudo"===d||"variable-3"===s.type?v(e):"block"===d||"maybeprop"===d?v(a.propertyKeywords):"prop"===d||"parens"===d||"at"===d||"params"===d?(v(a.valueKeywords),v(a.colorKeywords)):"media"!==d&&"media_parens"!==d||(v(a.mediaTypes),v(a.mediaFeatures)),c.length)return{list:c,from:CodeMirror.Pos(i.line,r),to:CodeMirror.Pos(i.line,n)}}function v(e){for(var t in e)l&&0!==t.lastIndexOf(l,0)||c.push(t)}}.bind(this))},setupCodeMirrorExtensions:function(){this.codeMirror.on("cursorActivity",function(e){var t=e.getCursor(),i=e.getTokenAt(t);CodeMirror.innerMode(e.getMode(),i.state);if("qualifier"===i.type||"tag"===i.type||"builtin"===i.type){var s=e.getLine(t.line).substring(0,i.end);this.preview.highlight(s)}else this.preview.clearHighlight()}.bind(this)),"function"==typeof CodeMirror.showHint&&this.codeMirror.on("keyup",(function(e,t){(t.keyCode>=65&&t.keyCode<=90||189===t.keyCode&&!t.shiftKey||190===t.keyCode&&!t.shiftKey||51===t.keyCode&&t.shiftKey||189===t.keyCode&&t.shiftKey)&&e.showHint({completeSingle:!1})}))},scaleEditor:function(){var t,i=e(window).outerHeight();if(this.$el.hasClass("expanded"))this.$el.find(".CodeMirror-scroll").css("max-height",""),t=i-this.$(".custom-css-toolbar").outerHeight(),this.codeMirror.setSize("100%",t),this.$el.find(".CodeMirror-scroll").css("height","100%");else{var s=e("#so-custom-css-form");(t=i-(e("#wpadminbar").outerHeight(!0)+e("#siteorigin-custom-css").find("> h2").outerHeight(!0)+s.find("> .custom-css-toolbar").outerHeight(!0)+s.find("> .so-css-footer").outerHeight(!0)+parseFloat(e("#wpbody-content").css("padding-bottom"))))<300&&(t=300),this.codeMirror.setSize("100%","auto"),this.$el.find(".CodeMirror-scroll").css("height",t+"px")}this.$el.find(".CodeMirror-code").css("height",t+"px")},isExpanded:function(){return this.$el.hasClass("expanded")},toggleExpand:function(t){e(".editor-expand").attr("title",e(".so-css-icon-"+(this.isExpanded()?"expand":"compress ")).attr("title")),this.$el.toggleClass("expanded"),this.scaleEditor()},setExpand:function(e){e?this.$el.addClass("expanded"):this.$el.removeClass("expanded"),this.scaleEditor()},showVisualEditor:function(){this.visualProperties.loadCSS(this.codeMirror.getValue().trim()),this.visualProperties.show()},setSnippets:function(e){t.isEmpty(e)||(this.snippets=new s.view.snippets({snippets:e}),this.snippets.editor=this,this.snippets.render(),this.toolbar.addButton("Snippets","snippets"),this.toolbar.on("click_snippets",function(){this.snippets.show()}.bind(this)))},addCode:function(e){var t=this.codeMirror,i="";i=1===t.doc.lineCount()&&0===t.doc.getLine(t.doc.lastLine()).length?"":0===t.doc.getLine(t.doc.lastLine()).length?"\n":"\n\n",t.doc.setCursor(t.doc.lastLine(),t.doc.getLine(t.doc.lastLine()).length),t.doc.replaceSelection(i+e)},addEmptySelector:function(e){this.addCode(e+" {\n \n}")},setInspector:function(e){this.inspector=e,this.cssSelectors=e.pageSelectors,e.on("click_selector",function(e){this.visualProperties.isVisible()?this.visualProperties.addSelector(e):this.addEmptySelector(e)}.bind(this)),e.on("click_property",function(e){this.visualProperties.isVisible()||this.codeMirror.replaceSelection(e+";\n ")}.bind(this)),e.on("set_active_element",function(e,t){this.visualProperties.isVisible()&&t.length&&this.visualProperties.addSelector(t[0].selector)}.bind(this))}}),s.view.preview=Backbone.View.extend({template:t.template(e("#template-preview-window").html()),editor:null,originalUri:null,currentUri:null,events:{"mouseleave #preview-iframe":"clearHighlight",'keydown #preview-navigator input[type="text"]':"reloadPreview"},initialize:function(e){this.editor=e.editor,this.listenTo(this.model,"change:selectedPost",this.render.bind(this)),this.originalUri=new URI(e.initURL),this.currentUri=new URI(e.initURL),this.editor.codeMirror.on("change",function(e,t){this.updatePreviewCss()}.bind(this))},render:function(){var e=this.model.get("selectedPost");if(e&&!e.has("postUrl"))return e.fetch().then(this.render.bind(this)),this;this.$el.html(this.template()),e&&(this.currentUri=new URI(e.get("postUrl"))),this.currentUri.removeQuery("so_css_preview",1),this.$("#preview-navigator input").val(this.currentUri.toString()),this.currentUri.addQuery("so_css_preview",1),this.$("#preview-iframe").attr("src",this.currentUri.toString()).on("load",this.initPreview.bind(this))},initPreview:function(){var t=this.$("#preview-iframe");this.currentUri=new URI(t.contents().get(0).location.href),this.currentUri.removeQuery("so_css_preview"),this.$("#preview-navigator input").val(this.currentUri.toString()),this.currentUri.addQuery("so_css_preview",1);var i=t.contents().find(".single-product").length;t.contents().find("a").each((function(){var t=e(this),s=t.attr("href");if(void 0===s||i&&t.parents(".wc-tabs").length)return!0;var o=-1===s.indexOf("?")?"?":"&";t.attr("href",s+o+"so_css_preview=1")})),this.updatePreviewCss()},reloadPreview:function(e){var t=this.$('#preview-navigator input[type="text"]');if(13===e.keyCode){e.preventDefault();var i=new URI(t.val());this.originalUri.host()!==i.host()||this.originalUri.protocol()!==i.protocol()?(t.trigger("blur"),alert(t.data("invalid-uri")),t.trigger("focus")):(i.addQuery("so_css_preview",1),this.$("#preview-iframe").attr("src",i.toString()))}},updatePreviewCss:function(){var e=this.$("#preview-iframe");if(0!==e.length){var t=e.contents().find("head");0===t.find("style.siteorigin-custom-css").length&&t.append('<style class="siteorigin-custom-css" type="text/css"></style>');var i=t.find("style.siteorigin-custom-css"),s=this.editor.codeMirror.getValue().trim();i.html(s)}},highlight:function(e){try{this.editor.inspector.hl.highlight(e)}catch(e){console.log("No inspector to highlight with")}},clearHighlight:function(){try{this.editor.inspector.hl.clear()}catch(e){console.log("No inspector to highlight with")}}}),s.view.snippets=Backbone.View.extend({template:t.template(e("#template-snippet-browser").html()),snippet:t.template('<li class="snippet"><%- name %></li>'),className:"css-editor-snippet-browser",snippets:null,editor:null,events:{"click .close":"hide","click .buttons .insert-snippet":"insertSnippet","click .snippet":"clickSnippet"},currentSnippet:null,initialize:function(e){this.snippets=e.snippets},render:function(){this.$el.html(this.template());for(var t=0;t<this.snippets.length;t++)e(this.snippet({name:this.snippets[t].Name})).data({description:this.snippets[t].Description,css:this.snippets[t].css}).appendTo(this.$("ul.snippets"));return this.$(".snippets li.snippet").eq(0).trigger("click"),this.attach(),this},clickSnippet:function(t){t.preventDefault();var i=e(t.currentTarget);this.$(".snippets li.snippet").removeClass("active"),e(this).addClass("active"),this.viewSnippet({name:i.html(),description:i.data("description"),css:i.data("css")})},viewSnippet:function(e){var t=this.$(".main .snippet-view");t.find(".snippet-title").html(e.name),t.find(".snippet-description").html(e.description),t.find(".snippet-code").html(e.css),this.currentSnippet=e},insertSnippet:function(){var e=this.editor.codeMirror,t=this.currentSnippet.css,i="";i=1===e.doc.lineCount()&&0===e.doc.getLine(e.doc.lastLine()).length?"":0===e.doc.getLine(e.doc.lastLine()).length?"\n":"\n\n",e.doc.setCursor(e.doc.lastLine(),e.doc.getLine(e.doc.lastLine()).length),e.doc.replaceSelection(i+t),this.hide()},attach:function(){this.$el.appendTo("body")},show:function(){this.$el.show()},hide:function(){this.$el.hide()}}),s.save=function(t){let s=e("#siteorigin-custom-css .save");var o;s.hasClass("button-primary-disabled")||(s.addClass("button-primary-disabled"),void 0!==t.editor?(o=t.editor.codeMirror.getValue().trim(),t.updateMainEditor(!0)):o=t.codeMirror.getValue().trim(),e.post(i.ajaxurl,{action:"socss_save_css",css:o},null,"html").done((function(t){t.length&&e(".custom-revisions-list").html(t)})).fail((function(e){alert(e.responseText)})).always((function(){s.removeClass("button-primary-disabled")})))},s.view.properties=Backbone.View.extend({tabTemplate:t.template('<li data-section="<%- id %>"><span class="so-css-icon so-css-icon-<%- icon %>"></span> <%- title %></li>'),sectionTemplate:t.template('<div class="section" data-section="<%- id %>"><table class="fields-table"><tbody></tbody></table></div>'),controllerTemplate:t.template('<tr><th scope="row"><%- title %></th><td></td></tr>'),propertyControllers:[],editor:null,css:"",parsed:{},activeSelector:"",editorExpandedBefore:!1,events:{"click .close":"hide","click .save":"save","click .section-tabs li":"onTabClick","change .toolbar select":"onToolbarSelectChange"},initialize:function(e){this.parser=window.css,this.editor=e.editor},render:function(){this.$(".section-tabs").empty(),this.$(".sections").empty(),this.$(".toolbar select").off(),this.propertyControllers=[];var o=i.propertyControllers;for(var r in o){e(this.tabTemplate({id:r,icon:o[r].icon,title:o[r].title})).appendTo(this.$(".section-tabs"));var n=e(this.sectionTemplate({id:r})).appendTo(this.$(".sections"));if(!t.isEmpty(o[r].controllers))for(var l=0;l<o[r].controllers.length;l++){var a,c=e(this.controllerTemplate({title:o[r].controllers[l].title})).appendTo(n.find("tbody")),d=o[r].controllers[l];a=void 0===s.view.properties.controllers[d.type]?new s.view.propertyController({el:c.find("td"),propertiesView:this,args:void 0===d.args?{}:d.args}):new s.view.properties.controllers[d.type]({el:c.find("td"),propertiesView:this,args:void 0===d.args?{}:d.args}),this.propertyControllers.push(a),a.render()}}this.$(".section-tabs li").eq(0).trigger("click")},onTabClick:function(t){var i=e(t.currentTarget),s=this.$('.sections .section[data-section="'+i.data("section")+'"]');this.$(".sections .section").not(s).hide().removeClass("active"),s.show().addClass("active"),this.$(".section-tabs li").not(i).removeClass("active"),i.addClass("active")},onToolbarSelectChange:function(t){this.setActiveSelector(e(t.currentTarget).find(":selected").data("selector"))},setRuleValue:function(e,i){if(void 0!==this.activeSelector&&void 0!==this.activeSelector.declarations){for(var s=this.activeSelector.declarations,o=!0,r=!1,n=0;n<s.length;n++)if(s[n].property===e){o=!1;var l=s[n];l.value!==i&&(l.value=i,r=!0),t.isEmpty(l.value)&&s.splice(s.indexOf(l));break}o&&!t.isEmpty(i)&&(s.push({property:e,value:i,type:"declaration"}),r=!0),r&&this.updateMainEditor(!1)}},addImport:function(e){var i=t.filter(this.parsed.stylesheet.rules,(function(e){return"import"===e.type}));t.any(i,(function(t){return t.import===e.import}))||(this.parsed.stylesheet.rules.unshift(e),this.updateMainEditor(!1))},findImport:function(e){return t.find(this.parsed.stylesheet.rules,(function(t){return"import"===t.type&&t.import.indexOf(e)>-1}))},updateImport:function(e,t){var i=this.findImport(e);i.import!==t.import&&(i.import=t.import,this.updateMainEditor(!1))},removeImport:function(e){var i=t.findIndex(this.parsed.stylesheet.rules,(function(t){return"import"===t.type&&t.import.indexOf(e)>-1}));i>-1&&this.parsed.stylesheet.rules.splice(i,1)},getRuleValue:function(e){if(void 0===this.activeSelector||void 0===this.activeSelector.declarations)return"";for(var t=this.activeSelector.declarations,i=0;i<t.length;i++)if(t[i].property===e)return t[i].value;return""},updateMainEditor:function(e){this.editor.codeMirror.setValue(this.parser.stringify(this.parsed))},show:function(){this.editorExpandedBefore=this.editor.isExpanded(),this.editor.setExpand(!0),this.$el.show().animate({left:0},"fast")},hide:function(){this.editor.setExpand(this.editorExpandedBefore),this.$el.animate({left:-338},"fast",(function(){e(this).hide()})),this.updateMainEditor(!0)},save:function(){s.save(this)},isVisible:function(){return this.$el.is(":visible")},loadCSS:function(i,s){this.css=i,this.parsed=this.parser.parse(i,{silent:!0});for(var o=this.parsed.stylesheet.rules,r=this.$(".toolbar select").empty(),n=0;n<o.length;n++){var l=o[n];if(t.contains(["rule","media"],l.type))if("media"===l.type)for(var a=0;a<l.rules.length;a++){var c="@media "+l.media,d=l.rules[a];"rule"==d.type&&r.append(e("<option>").html(c+": "+d.selectors.join(",")).attr("val",c+": "+d.selectors.join(",")).data("selector",d))}else r.append(e("<option>").html(l.selectors.join(",")).attr("val",l.selectors.join(",")).data("selector",l))}void 0===s&&(s=r.find("option").eq(0).attr("val")),t.isEmpty(s)||r.val(s).trigger("change")},setActiveSelector:function(e){this.activeSelector=e;for(var t=0;t<this.propertyControllers.length;t++)this.propertyControllers[t].refreshFromRule()},addSelector:function(e){var t=this.$(".toolbar select");t.val(e),t.val()===e?t.trigger("change"):(this.editor.addEmptySelector(e),this.loadCSS(this.editor.codeMirror.getValue().trim(),e)),t.addClass("highlighted"),setTimeout((function(){t.removeClass("highlighted")}),2e3)}}),s.view.propertyController=Backbone.View.extend({template:t.template('<input type="text" value="" class="socss-property-controller-input"/>'),activeRule:null,args:null,propertiesView:null,events:{"change .socss-property-controller-input":"onChange","keyup input.socss-property-controller-input":"onChange"},initialize:function(e){this.args=e.args,this.propertiesView=e.propertiesView,this.events=t.extend(s.view.propertyController.prototype.events,this.events),this.delegateEvents(this.events),this.on("set_value",this.updateRule,this),this.on("change",this.updateRule,this)},render:function(){this.$el.append(e(this.template({}))),this.field=this.$("input.socss-property-controller-input")},onChange:function(){this.trigger("change",this.field.val())},updateRule:function(){this.propertiesView.setRuleValue(this.args.property,this.getValue())},refreshFromRule:function(){var e=this.propertiesView.getRuleValue(this.args.property);this.setValue(e,{silent:!0})},getValue:function(){return this.field.val()},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.val(e),i.silent||this.trigger("set_value",e)},reset:function(e){e=t.extend({silent:!1},e),this.setValue("",e)}}),s.view.properties.controllers={},s.view.properties.controllers.color=s.view.propertyController.extend({render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.field.minicolors({})},onChange:function(){this.trigger("change",this.field.minicolors("value"))},getValue:function(){return this.field.minicolors("value").trim()},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.minicolors("value",e),i.silent||this.trigger("set_value",e)}}),s.view.properties.controllers.select=s.view.propertyController.extend({template:t.template('<select class="socss-property-controller-input"></select>'),events:{"click .select-tab":"onSelect"},render:function(){for(var t in this.$el.append(e(this.template({}))),this.field=this.$("select"),this.field.append(e('<option value=""></option>').html("")),this.args.options)this.field.append(e("<option></option>").attr("value",t).html(this.args.options[t]));void 0!==this.args.option_icons&&this.setupVisualSelect()},setupVisualSelect:function(){this.field.hide();var t=e('<div class="select-tabs"></div>').appendTo(this.$el);for(var i in e('<div class="select-tab" data-value=""><span class="so-css-icon so-css-icon-circle"></span></div>').appendTo(t),this.args.option_icons)e('<div class="select-tab"></div>').appendTo(t).append(e('<span class="so-css-icon"></span>').addClass("so-css-icon-"+this.args.option_icons[i])).attr("data-value",i);t.find(".select-tab").css("width",100/t.find(">div").length+"%")},onSelect:function(t){this.$(".select-tab").removeClass("active");var i=e(t.currentTarget);i.addClass("active"),this.field.val(i.data("value")).trigger("change")},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.val(e),this.$(".select-tabs .select-tab").removeClass("active").filter('[data-value="'+e+'"]').addClass("active"),i.silent||this.trigger("set_value",e)}}),s.view.properties.controllers.image=s.view.propertyController.extend({template:t.template('<input type="text" value="" /> <span class="select socss-button"><span class="so-css-icon so-css-icon-upload"></span></span>'),events:{"click .select":"openMedia"},render:function(){this.media=wp.media({title:i.loc.select_image,library:{type:"image"},button:{text:i.loc.select,close:!1}}),this.$el.append(e(this.template({select:i.loc.select}))),this.field=this.$el.find("input"),this.media.on("select",function(){var e=this.media.state().get("selection").first().attributes,t=this.args.value.replace("{{url}}",e.url);this.field.val(t).trigger("change"),this.trigger("set_value",t),this.media.close()}.bind(this))},openMedia:function(){this.media.open()}}),s.view.properties.controllers.measurement=s.view.propertyController.extend({wrapperClass:"socss-field-measurement",events:{"click .toggle-dropdown":"toggleUnitDropdown","click .dropdown li":"onSelectUnit","keydown .socss-field-input":"onInputKeyPress","keyup .socss-field-input":"onInputKeyUp"},render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.setupMeasurementField()},setValue:function(e,i){i=t.extend({silent:!1},i),this.field.val(e).trigger("measurement_refresh"),i.silent||this.trigger("set_value",e)},units:["px","%","em","cm","mm","in","pt","pc","ex","ch","rem","vw","vh","vmin","vmax"],parseUnits:function(e){var t=this.units.map((function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")})),i=new RegExp("([0-9\\.\\-]+)("+t.join("|")+")?","i").exec(e);return null===i?{value:"",unit:""}:{value:i[1],unit:void 0===i[2]?"":i[2]}},setupMeasurementField:function(){this.field.hide(),this.$el.addClass(this.wrapperClass).data("unit","px");var t=e('<input type="text" class="socss-field-input"/>').appendTo(this.$el);e('<span class="toggle-dropdown dashicons dashicons-arrow-down"></span>').appendTo(this.$el);for(var i=e('<ul class="dropdown"></ul>').appendTo(this.$el),s=e('<span class="units"></span>').html("px").appendTo(this.$el),o=0;o<this.units.length;o++){var r=e("<li></li>").html(this.units[o]).data("unit",this.units[o]);"px"===this.units[o]&&r.addClass("active"),i.append(r)}this.field.on("measurement_refresh",function(){var i=this.parseUnits(this.field.val());t.val(i.value);var o=""===i.unit?"px":i.unit;this.$el.data("unit",o),s.html(o);var r=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.value).appendTo("body"),n=r.width();n=Math.min(n,63),r.remove(),s.css("left",n+12)}.bind(this));var n=e('<div class="socss-diw"></div>').appendTo(this.$el),l=e('<div class="dec-button socss-button"><span class="so-css-icon so-css-icon-minus"></span></div>').appendTo(n),a=e('<div class="inc-button socss-button"><span class="so-css-icon so-css-icon-plus"></span></div>').appendTo(n);this.setupStepButton(l),this.setupStepButton(a)},updateValue:function(){var e=this.$(".socss-field-input"),t=this.parseUnits(e.val());""!==t.unit&&t.unit!==this.$el.data("unit")&&(e.val(t.value),this.setUnit(t.unit)),""===t.value?this.field.val(""):this.field.val(t.value+this.$el.data("unit")),this.field.trigger("change")},setUnit:function(e){this.$(".units").html(e),this.$el.data("unit",e),this.$(".socss-field-input").trigger("keydown")},toggleUnitDropdown:function(){this.$(".dropdown").toggle()},onSelectUnit:function(t){this.toggleUnitDropdown(),this.setUnit(e(t.currentTarget).data("unit")),this.updateValue()},onInputKeyUp:function(e){this.onInputKeyPress(e),this.updateValue()},onInputKeyPress:function(t){var i=this.$(".socss-field-input"),s="";"keydown"===t.type&&(t.keyCode>=48&&t.keyCode<=57?s=String.fromCharCode(t.keyCode):189===t.keyCode?s="-":190===t.keyCode&&(s="."));var o=e('<span class="socss-hidden-placeholder"></span>').css({"font-size":"14px"}).html(i.val()+s).appendTo("body"),r=o.width();r=Math.min(r,63),o.remove(),this.$(".units").css("left",r+12)},stepValue:function(e){var t=Number.parseInt(this.parseUnits(this.field.val()).value);Number.isNaN(t)&&(t=0);var i=t+e;this.$(".socss-field-input").val(i),this.updateValue(),this.field.trigger("measurement_refresh")},setupStepButton:function(e){var t,i,s=e.is(".dec-button")?-1:1;e.on("mousedown",function(){this.stepValue(s),i=setTimeout(function(){t=setInterval(function(){this.stepValue(s)}.bind(this),50)}.bind(this),500)}.bind(this)).on("mouseup mouseout",(function(){i&&(clearTimeout(i),i=null),t&&(clearInterval(t),t=null)}))}}),s.view.properties.controllers.number=s.view.propertyController.extend({initialize:function(e){s.view.propertyController.prototype.initialize.apply(this,arguments),this.args=t.extend({change:null,default:0,increment:1,decrement:-1,max:null,min:null},e.args)},render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.setupNumberField()},setupNumberField:function(){this.$el.addClass("socss-field-number");var t=e('<div class="socss-diw"></div>').appendTo(this.$el),i=e('<div class="dec-button socss-button"><span class="so-css-icon so-css-icon-minus"></span></div>').appendTo(t),s=e('<div class="inc-button socss-button"><span class="so-css-icon so-css-icon-plus"></span></div>').appendTo(t);return this.setupStepButton(i),this.setupStepButton(s),this},stepValue:function(e){var t=Number.parseFloat(this.field.val());Number.isNaN(t)&&(t=this.args.default);var i=t+e;i=Math.round(100*i)/100,null!==this.args.max&&(i=Math.min(this.args.max,i)),null!==this.args.min&&(i=Math.max(this.args.min,i)),this.field.val(i),this.field.trigger("change")},setupStepButton:function(e){var t,i,s=e.is(".dec-button")?this.args.decrement:this.args.increment;e.on("mousedown",function(){this.stepValue(s),i=setTimeout(function(){t=setInterval(function(){this.stepValue(s)}.bind(this),50)}.bind(this),500)}.bind(this)).on("mouseup mouseout",(function(){i&&(clearTimeout(i),i=null),t&&(clearInterval(t),t=null)}))}}),s.view.properties.controllers.sides=s.view.propertyController.extend({template:t.template(e("#template-sides-field").html().trim()),controllers:[],events:{"click .select-tab":"onTabClick"},render:function(){s.view.propertyController.prototype.render.apply(this,arguments),this.args.hasAll||(this.$(".select-tab").eq(0).remove(),this.$(".select-tab").css("width","25%")),this.args.isRadius?this.$('.select-tabs[data-type="box"]').remove():this.$('.select-tabs[data-type="radius"]').remove(),this.$(".select-tab").each(function(i,o){for(var r=e(o).data("direction"),n=e('<li class="side">').appendTo(this.$(".sides")).hide(),l=0;l<this.args.controllers.length;l++){var a=this.args.controllers[l];s.view.properties.controllers[a.type];var c="";c="all"===r?a.args.propertyAll:a.args.property.replace("{dir}",r);var d=t.extend({},a.args,{property:c}),p=new s.view.properties.controllers[a.type]({el:e("<div>").appendTo(n),propertiesView:this.propertiesView,args:d});p.render(),this.propertiesView.propertyControllers.push(p)}}.bind(this)),this.$(".select-tab").eq(0).click()},onTabClick:function(t){var i=this.$(".select-tab");i.removeClass("active");var s=e(t.currentTarget);s.addClass("active");var o=this.$(".sides .side");o.hide(),o.eq(i.index(s)).show()}}),s.view.properties.controllers.font_select=s.view.propertyController.extend({template:t.template(e("#template-webfont-teaser").html().trim())})}(jQuery,_,socssOptions),jQuery((function(e){var t=window.socss,i=new t.model.CSSEditorModel({customCssPosts:socssOptions.customCssPosts}),s=new t.view.editor({el:e("#so-custom-css-form").get(0),model:i,openVisualEditor:socssOptions.openVisualEditor});s.setSnippets(socssOptions.snippets),e("#so-custom-css-getting-started a.hide").on("click",(function(t){t.preventDefault(),e("#so-custom-css-getting-started").slideUp(),e.get(e(this).attr("href"))})),window.socss.mainEditor=s,e(t).trigger("initialized"),e('.button-primary[name="siteorigin_custom_css_save"]').on("click",(function(){e("#so-custom-css-form").trigger("submit")})),e(".installer-link").on("click",(function(t){t.preventDefault(),e(this).hide(),e(".installer-container").slideDown("fast")})),e(".installer_status").on("change",(function(){var t=e(this);t.prop("disabled",!0),jQuery.post(ajaxurl,{action:"so_installer_status",nonce:t.data("nonce"),status:t.is(":checked")},(function(){t.prop("disabled",!1)}))}))}));
/* globals jQuery, Backbone, _, socssOptions, SPECIFICITY, console */
( function( $, _, socssOptions ){
var socss = {
model : { },
collection : { },
view : { },
fn : {}
};
var getSelectorSpecificity = function(selector, useParts) {
var specificities = [];
var ruleSpecificity = SPECIFICITY.calculate( selector );
for (var i = 0; i < ruleSpecificity.length; i++) {
var specificity = ruleSpecificity[ i ];
if ( useParts ) {
for ( var j = 0; j < specificity.parts.length; j++ ) {
var specificityPart = specificity.parts[ j ];
// Recursive call to add specificities for parts.
specificities = specificities.concat(getSelectorSpecificity(specificityPart.selector));
}
} else {
specificities.push({
'selector': specificity.selector.trim(),
'specificity': parseInt(specificity.specificity.replace(/,/g, ''))
});
}
}
return specificities;
};
/**
* This is the main view for the app
*/
socss.view.inspector = Backbone.View.extend( {
active: false,
hl: false,
hoverEl: false,
pageSelectors: [],
selectorTemplate: _.template('<div class="socss-selector"><%= selector %></div>'),
importantClasses: [
'menu-item-',
'postid-',
'page-id-',
],
initialize: function(){
var thisView = this;
this.hl = new socss.view.highlighter();
this.hl.initialize();
this.pageSelectors = socss.fn.pageSelectors();
// Setup hovering
$('body').on('mouseover', '*', function(e){
if( !thisView.active ) {
return true;
}
var $$ = $(this);
if( $$.closest('.socss-element').length === 0 ) {
e.stopPropagation();
thisView.setHoverEl( $(this) );
}
});
// Setup the click event
var wcCheck = $( '.single-product' ).length;
$('body *').on( 'click', function( e ) {
if ( ! thisView.active || $( e.target ).parent( '.socss-link' ).length ) {
return true;
}
var $$ = $( this );
if ( ! wcCheck || ! $$.parents( '.wc-tabs' ).length ) {
e.preventDefault();
$$.trigger( 'blur' );
thisView.setActiveEl( thisView.hoverEl );
}
});
this.$('.socss-enable-inspector').on( 'click', function(){
thisView.toggleActive();
} );
this.$el.on( 'mouseenter', function() {
thisView.hl.clear();
} );
// Try register this inspector with the parent editor
try {
parent.socss.mainEditor.setInspector( this );
}
catch( err ){
console.log( 'No editor to register this inspector with' );
}
},
/**
* Set the element that's currently being hovered
*
* @param hoverEl
*/
setHoverEl: function( hoverEl ){
this.hoverEl = hoverEl;
this.hl.highlight( hoverEl );
},
activate: function(){
this.active = true;
$('body').addClass('socss-active');
$('body').removeClass('socss-inactive');
},
deactivate: function(){
this.active = false;
$('body').addClass('socss-inactive');
$('body').removeClass('socss-active');
this.hl.clear();
this.$('.socss-hierarchy').empty();
},
/**
* Toggle the active status
*/
toggleActive: function(){
if( this.active ) {
this.deactivate();
}
else {
this.activate();
}
},
/**
* Set the element that we're busy inspecting
* @param el
*/
setActiveEl: function( el ) {
var thisView = this;
var $h = this.$('.socss-hierarchy');
$h.empty();
if ( !el ) {
return;
}
if (el.prop('tagName').toLowerCase() !== 'body') {
var cel = $(el);
do {
var selector = socss.fn.elSelector( cel );
thisView.importantClasses.forEach( function( importantClass ) {
if ( selector.indexOf( importantClass ) >= 0 ) {
var selectorRegex = new RegExp( '(' + importantClass + '\\d+)', 'g' );
selector = selector.replace( selectorRegex, "<strong>$1</strong>");
}
} );
$( this.selectorTemplate( { selector: selector } ) )
.prependTo($h)
.data('el', cel);
cel = cel.parent();
} while (cel.prop('tagName').toLowerCase() !== 'body');
$(this.selectorTemplate({selector: 'body'}))
.prependTo($h)
.data('el', $('body'));
this.$('.socss-hierarchy .socss-selector')
.on( 'mouseenter', function () {
thisView.hl.highlight($(this).data('el'));
})
.on( 'click', function(e) {
e.preventDefault();
e.stopPropagation();
thisView.setActiveEl($(this).data('el'));
});
}
// Scroll all the way left...
$h.scrollLeft( 99999 );
// Now lets add all the CSS selectors
var selectors = this.pageSelectors.filter( function(a){
// Use try to catch any malformed selectors
try {
return el.is( a.selector );
}
catch(err) {
return false;
}
} );
var container = this.$('.socss-selectors-window').empty();
_.each( selectors, function( selector ){
container.append(
$( thisView.selectorTemplate( selector ) )
.data( selector )
);
} );
container.find('> div')
.on( 'mouseenter', function() {
thisView.hl.highlight( $(this).data('selector') );
} )
.on( 'click', function( e ) {
e.preventDefault();
e.stopPropagation();
thisView.trigger( 'click_selector', $(this).data('selector') );
} );
// And the CSS attributes
var attributes = socss.fn.elementAttributes(el);
container = this.$('.socss-properties-window').empty();
_.each( attributes, function(v, k){
container.append(
$( thisView.selectorTemplate( { selector: '<strong>' + k + '</strong>: ' + v } ) )
.data( 'property', k + ': ' + v )
);
} );
container.find('> div')
.on( 'click', function( e ) {
e.preventDefault();
e.stopPropagation();
thisView.trigger( 'click_property', $(this).data('property') );
});
// Display the link
var link = el.closest('a[href]');
var linkContainer = this.$('.socss-link');
if( link.length ) {
linkContainer.show().find('a')
.html( link.attr('href').replace(/[\?&]*so_css_preview=1/, '') )
.attr('href', link.attr('href') );
}
else {
linkContainer.hide();
}
this.trigger('set_active_element', el, selectors);
}
} );
socss.view.highlighter = Backbone.View.extend( {
template: _.template( $('#socss-template-hover').html().trim() ),
highlighted: [ ],
highlight: function( els ){
this.clear();
var thisView = this;
$(els).each(function(i, el){
el = $(el);
if( !el.is(':visible') ) {
// Skip over invisible elements
return true;
}
var hl = $( thisView.template() );
hl.css({
'top' : el.offset().top,
'left' : el.offset().left,
'width' : el.outerWidth(),
'height' : el.outerHeight()
}).appendTo( 'body' );
var g;
var padding = el.padding();
for( var k in padding ) {
if( parseInt( padding[k] ) > 0 ) {
g = hl.find( '.socss-guide-padding.socss-guide-' + k ).show();
if( k === 'top' || k === 'bottom' ) {
g.css('height', padding[k]);
}
else {
g.css('width', padding[k]);
g.css({
'width': padding[k],
'top' : padding.top,
'bottom' : padding.bottom
});
}
}
}
var margin = el.margin();
for( var k in margin ) {
if( parseInt( margin[k] ) > 0 ) {
g = hl.find( '.socss-guide-margin.socss-guide-' + k ).show();
if( k === 'top' || k === 'bottom' ) {
g.css('height', margin[k]);
}
else {
g.css('width', margin[k]);
}
}
}
thisView.highlighted.push( hl );
} );
},
clear: function(){
while( this.highlighted.length ) {
this.highlighted.pop().remove();
}
}
} );
socss.parsedCss = {};
socss.fn.getParsedCss = function(){
// Load all the parsed CSS
if( Object.keys(socss.parsedCss).length === 0 ) {
var parser = window.css;
$('.socss-theme-styles').each(function(){
var $$ = $(this);
var p = parser.parse( $$.html(), {
silent: true
} );
socss.parsedCss[ $$.attr('id') ] = p;
});
}
return socss.parsedCss;
};
/**
* Function to get all the available page selectors
*/
socss.fn.pageSelectors = function(){
var selectors = [];
var parsedCss = socss.fn.getParsedCss();
for( var k in parsedCss ) {
var rules = parsedCss[k].stylesheet.rules;
for( var i = 0; i < rules.length; i++ ) {
if (typeof rules[i].selectors === 'undefined') {
continue;
}
for(var j = 0; j < rules[i].selectors.length; j++) {
selectors = selectors.concat( getSelectorSpecificity( rules[i].selectors[j] ) );
}
}
}
// Also add selectors for all the elements in the
$('body *').each(function(){
var $$ = $(this);
var elName = socss.fn.elSelector( $$ );
selectors = selectors.concat(getSelectorSpecificity(elName));
});
var $body = $('body');
var bName = socss.fn.elSelector($body);
selectors = selectors.concat(getSelectorSpecificity(bName, true));
selectors = _.uniq( selectors, false, function( a ){
return a.selector;
} );
selectors.sort(function(a, b){
return a.specificity > b.specificity ? -1 : 1;
});
return selectors;
};
socss.fn.elementAttributes = function( el ) {
if( !document.styleSheets ) {
return [];
}
var elProperties = [];
var trimFunc = function(e) {
return e.trim();
};
var filterFunc = function(e){
return e !== '';
};
var splitFunc = function(e) {
return e.split(':').map( trimFunc );
};
var parsedCss = socss.fn.getParsedCss();
var isAtRule = function (ruleType) {
switch(ruleType) {
case 'charset':
case 'custom-media':
case 'document':
case 'font-face':
case 'host':
case 'import':
case 'keyframes':
case 'keyframe':
case 'media':
case 'namespace':
case 'page':
case 'supports':
return true;
}
return false;
};
for( var k in parsedCss ) {
var rules = parsedCss[k].stylesheet.rules;
for( var i = 0; i < rules.length; i++ ) {
var rule = rules[i];
if (
typeof rule.selectors === 'undefined' || isAtRule(rule.type)
) {
continue;
}
for(var j = 0; j < rule.selectors.length; j++) {
var ruleSpecificity = SPECIFICITY.calculate( rule.selectors[j] );
for (var l = 0; l < ruleSpecificity.length; l++) {
try {
if ( el.is( ruleSpecificity[l].selector ) ) {
var declarations = rule.declarations;
for (var l = 0; l < declarations.length; l++) {
elProperties.push({
'name': declarations[l].property,
'value': declarations[l].value,
'specificity': parseInt( ruleSpecificity[l].specificity.replace( /,/g, '' ) )
});
}
}
}
catch (e) {
// For now, we're just going to ignore rules that trigger errors
}
}
}
}
}
elProperties.sort( function(a,b) {
return a.specificity > b.specificity ? 1 : -1;
}).reverse();
var returnProperties = {};
for( var pi = 0; pi < elProperties.length; pi++ ) {
if( typeof returnProperties[elProperties[pi].name] === 'undefined' ) {
returnProperties[elProperties[pi].name] = elProperties[pi].value;
}
}
return returnProperties;
};
socss.fn.elSelector = function( el ){
var elName = '';
if( el.attr('id') !== undefined ) {
elName += '#' + el.attr('id');
}
if( el.attr('class') !== undefined ) {
elName += '.' + el.attr('class').replace(/\s+/g, '.');
}
if( elName === '' ) {
elName = el.prop('tagName').toLowerCase();
}
return elName;
};
window.socssInspector = socss;
} ) ( jQuery, _, socssOptions );
jQuery( function($){
var socss = window.socssInspector;
// Setup the editor
var inspector = new socss.view.inspector( {
el : $('#socss-inspector-interface').get(0)
} );
inspector.activate();
window.socssInspector.mainInspector = inspector;
} );
/*!
CSSLint v1.0.3
Copyright (c) 2016 Nicole Sullivan and Nicholas C. Zakas. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var CSSLint = (function(){
var module = module || {},
exports = exports || {};
/*!
Parser-Lib
Copyright (c) 2009-2016 Nicholas C. Zakas. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Version v1.0.0, Build time: 15-July-2016 12:36:10 */
var parserlib = (function () {
var require;
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";
/* exported Colors */
var Colors = module.exports = {
__proto__ :null,
aliceblue :"#f0f8ff",
antiquewhite :"#faebd7",
aqua :"#00ffff",
aquamarine :"#7fffd4",
azure :"#f0ffff",
beige :"#f5f5dc",
bisque :"#ffe4c4",
black :"#000000",
blanchedalmond :"#ffebcd",
blue :"#0000ff",
blueviolet :"#8a2be2",
brown :"#a52a2a",
burlywood :"#deb887",
cadetblue :"#5f9ea0",
chartreuse :"#7fff00",
chocolate :"#d2691e",
coral :"#ff7f50",
cornflowerblue :"#6495ed",
cornsilk :"#fff8dc",
crimson :"#dc143c",
cyan :"#00ffff",
darkblue :"#00008b",
darkcyan :"#008b8b",
darkgoldenrod :"#b8860b",
darkgray :"#a9a9a9",
darkgrey :"#a9a9a9",
darkgreen :"#006400",
darkkhaki :"#bdb76b",
darkmagenta :"#8b008b",
darkolivegreen :"#556b2f",
darkorange :"#ff8c00",
darkorchid :"#9932cc",
darkred :"#8b0000",
darksalmon :"#e9967a",
darkseagreen :"#8fbc8f",
darkslateblue :"#483d8b",
darkslategray :"#2f4f4f",
darkslategrey :"#2f4f4f",
darkturquoise :"#00ced1",
darkviolet :"#9400d3",
deeppink :"#ff1493",
deepskyblue :"#00bfff",
dimgray :"#696969",
dimgrey :"#696969",
dodgerblue :"#1e90ff",
firebrick :"#b22222",
floralwhite :"#fffaf0",
forestgreen :"#228b22",
fuchsia :"#ff00ff",
gainsboro :"#dcdcdc",
ghostwhite :"#f8f8ff",
gold :"#ffd700",
goldenrod :"#daa520",
gray :"#808080",
grey :"#808080",
green :"#008000",
greenyellow :"#adff2f",
honeydew :"#f0fff0",
hotpink :"#ff69b4",
indianred :"#cd5c5c",
indigo :"#4b0082",
ivory :"#fffff0",
khaki :"#f0e68c",
lavender :"#e6e6fa",
lavenderblush :"#fff0f5",
lawngreen :"#7cfc00",
lemonchiffon :"#fffacd",
lightblue :"#add8e6",
lightcoral :"#f08080",
lightcyan :"#e0ffff",
lightgoldenrodyellow :"#fafad2",
lightgray :"#d3d3d3",
lightgrey :"#d3d3d3",
lightgreen :"#90ee90",
lightpink :"#ffb6c1",
lightsalmon :"#ffa07a",
lightseagreen :"#20b2aa",
lightskyblue :"#87cefa",
lightslategray :"#778899",
lightslategrey :"#778899",
lightsteelblue :"#b0c4de",
lightyellow :"#ffffe0",
lime :"#00ff00",
limegreen :"#32cd32",
linen :"#faf0e6",
magenta :"#ff00ff",
maroon :"#800000",
mediumaquamarine:"#66cdaa",
mediumblue :"#0000cd",
mediumorchid :"#ba55d3",
mediumpurple :"#9370d8",
mediumseagreen :"#3cb371",
mediumslateblue :"#7b68ee",
mediumspringgreen :"#00fa9a",
mediumturquoise :"#48d1cc",
mediumvioletred :"#c71585",
midnightblue :"#191970",
mintcream :"#f5fffa",
mistyrose :"#ffe4e1",
moccasin :"#ffe4b5",
navajowhite :"#ffdead",
navy :"#000080",
oldlace :"#fdf5e6",
olive :"#808000",
olivedrab :"#6b8e23",
orange :"#ffa500",
orangered :"#ff4500",
orchid :"#da70d6",
palegoldenrod :"#eee8aa",
palegreen :"#98fb98",
paleturquoise :"#afeeee",
palevioletred :"#d87093",
papayawhip :"#ffefd5",
peachpuff :"#ffdab9",
peru :"#cd853f",
pink :"#ffc0cb",
plum :"#dda0dd",
powderblue :"#b0e0e6",
purple :"#800080",
red :"#ff0000",
rosybrown :"#bc8f8f",
royalblue :"#4169e1",
saddlebrown :"#8b4513",
salmon :"#fa8072",
sandybrown :"#f4a460",
seagreen :"#2e8b57",
seashell :"#fff5ee",
sienna :"#a0522d",
silver :"#c0c0c0",
skyblue :"#87ceeb",
slateblue :"#6a5acd",
slategray :"#708090",
slategrey :"#708090",
snow :"#fffafa",
springgreen :"#00ff7f",
steelblue :"#4682b4",
tan :"#d2b48c",
teal :"#008080",
thistle :"#d8bfd8",
tomato :"#ff6347",
turquoise :"#40e0d0",
violet :"#ee82ee",
wheat :"#f5deb3",
white :"#ffffff",
whitesmoke :"#f5f5f5",
yellow :"#ffff00",
yellowgreen :"#9acd32",
//'currentColor' color keyword https://www.w3.org/TR/css3-color/#currentcolor
currentColor :"The value of the 'color' property.",
//CSS2 system colors https://www.w3.org/TR/css3-color/#css2-system
activeBorder :"Active window border.",
activecaption :"Active window caption.",
appworkspace :"Background color of multiple document interface.",
background :"Desktop background.",
buttonface :"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",
buttonhighlight :"The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
buttonshadow :"The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
buttontext :"Text on push buttons.",
captiontext :"Text in caption, size box, and scrollbar arrow box.",
graytext :"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",
greytext :"Greyed (disabled) text. This color is set to #000 if the current display driver does not support a solid grey color.",
highlight :"Item(s) selected in a control.",
highlighttext :"Text of item(s) selected in a control.",
inactiveborder :"Inactive window border.",
inactivecaption :"Inactive window caption.",
inactivecaptiontext :"Color of text in an inactive caption.",
infobackground :"Background color for tooltip controls.",
infotext :"Text color for tooltip controls.",
menu :"Menu background.",
menutext :"Text in menus.",
scrollbar :"Scroll bar gray area.",
threeddarkshadow :"The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
threedface :"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
threedhighlight :"The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
threedlightshadow :"The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
threedshadow :"The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
window :"Window background.",
windowframe :"Window frame.",
windowtext :"Text in windows."
};
},{}],2:[function(require,module,exports){
"use strict";
module.exports = Combinator;
var SyntaxUnit = require("../util/SyntaxUnit");
var Parser = require("./Parser");
/**
* Represents a selector combinator (whitespace, +, >).
* @namespace parserlib.css
* @class Combinator
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {String} text The text representation of the unit.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function Combinator(text, line, col) {
SyntaxUnit.call(this, text, line, col, Parser.COMBINATOR_TYPE);
/**
* The type of modifier.
* @type String
* @property type
*/
this.type = "unknown";
//pretty simple
if (/^\s+$/.test(text)) {
this.type = "descendant";
} else if (text === ">") {
this.type = "child";
} else if (text === "+") {
this.type = "adjacent-sibling";
} else if (text === "~") {
this.type = "sibling";
}
}
Combinator.prototype = new SyntaxUnit();
Combinator.prototype.constructor = Combinator;
},{"../util/SyntaxUnit":26,"./Parser":6}],3:[function(require,module,exports){
"use strict";
module.exports = Matcher;
var StringReader = require("../util/StringReader");
var SyntaxError = require("../util/SyntaxError");
/**
* This class implements a combinator library for matcher functions.
* The combinators are described at:
* https://developer.mozilla.org/en-US/docs/Web/CSS/Value_definition_syntax#Component_value_combinators
*/
function Matcher(matchFunc, toString) {
this.match = function(expression) {
// Save/restore marks to ensure that failed matches always restore
// the original location in the expression.
var result;
expression.mark();
result = matchFunc(expression);
if (result) {
expression.drop();
} else {
expression.restore();
}
return result;
};
this.toString = typeof toString === "function" ? toString : function() {
return toString;
};
}
/** Precedence table of combinators. */
Matcher.prec = {
MOD: 5,
SEQ: 4,
ANDAND: 3,
OROR: 2,
ALT: 1
};
/** Simple recursive-descent grammar to build matchers from strings. */
Matcher.parse = function(str) {
var reader, eat, expr, oror, andand, seq, mod, term, result;
reader = new StringReader(str);
eat = function(matcher) {
var result = reader.readMatch(matcher);
if (result === null) {
throw new SyntaxError(
"Expected "+matcher, reader.getLine(), reader.getCol());
}
return result;
};
expr = function() {
// expr = oror (" | " oror)*
var m = [ oror() ];
while (reader.readMatch(" | ") !== null) {
m.push(oror());
}
return m.length === 1 ? m[0] : Matcher.alt.apply(Matcher, m);
};
oror = function() {
// oror = andand ( " || " andand)*
var m = [ andand() ];
while (reader.readMatch(" || ") !== null) {
m.push(andand());
}
return m.length === 1 ? m[0] : Matcher.oror.apply(Matcher, m);
};
andand = function() {
// andand = seq ( " && " seq)*
var m = [ seq() ];
while (reader.readMatch(" && ") !== null) {
m.push(seq());
}
return m.length === 1 ? m[0] : Matcher.andand.apply(Matcher, m);
};
seq = function() {
// seq = mod ( " " mod)*
var m = [ mod() ];
while (reader.readMatch(/^ (?![&|\]])/) !== null) {
m.push(mod());
}
return m.length === 1 ? m[0] : Matcher.seq.apply(Matcher, m);
};
mod = function() {
// mod = term ( "?" | "*" | "+" | "#" | "{<num>,<num>}" )?
var m = term();
if (reader.readMatch("?") !== null) {
return m.question();
} else if (reader.readMatch("*") !== null) {
return m.star();
} else if (reader.readMatch("+") !== null) {
return m.plus();
} else if (reader.readMatch("#") !== null) {
return m.hash();
} else if (reader.readMatch(/^\{\s*/) !== null) {
var min = eat(/^\d+/);
eat(/^\s*,\s*/);
var max = eat(/^\d+/);
eat(/^\s*\}/);
return m.braces(+min, +max);
}
return m;
};
term = function() {
// term = <nt> | literal | "[ " expression " ]"
if (reader.readMatch("[ ") !== null) {
var m = expr();
eat(" ]");
return m;
}
return Matcher.fromType(eat(/^[^ ?*+#{]+/));
};
result = expr();
if (!reader.eof()) {
throw new SyntaxError(
"Expected end of string", reader.getLine(), reader.getCol());
}
return result;
};
/**
* Convert a string to a matcher (parsing simple alternations),
* or do nothing if the argument is already a matcher.
*/
Matcher.cast = function(m) {
if (m instanceof Matcher) {
return m;
}
return Matcher.parse(m);
};
/**
* Create a matcher for a single type.
*/
Matcher.fromType = function(type) {
// Late require of ValidationTypes to break a dependency cycle.
var ValidationTypes = require("./ValidationTypes");
return new Matcher(function(expression) {
return expression.hasNext() && ValidationTypes.isType(expression, type);
}, type);
};
/**
* Create a matcher for one or more juxtaposed words, which all must
* occur, in the given order.
*/
Matcher.seq = function() {
var ms = Array.prototype.slice.call(arguments).map(Matcher.cast);
if (ms.length === 1) {
return ms[0];
}
return new Matcher(function(expression) {
var i, result = true;
for (i = 0; result && i < ms.length; i++) {
result = ms[i].match(expression);
}
return result;
}, function(prec) {
var p = Matcher.prec.SEQ;
var s = ms.map(function(m) {
return m.toString(p);
}).join(" ");
if (prec > p) {
s = "[ " + s + " ]";
}
return s;
});
};
/**
* Create a matcher for one or more alternatives, where exactly one
* must occur.
*/
Matcher.alt = function() {
var ms = Array.prototype.slice.call(arguments).map(Matcher.cast);
if (ms.length === 1) {
return ms[0];
}
return new Matcher(function(expression) {
var i, result = false;
for (i = 0; !result && i < ms.length; i++) {
result = ms[i].match(expression);
}
return result;
}, function(prec) {
var p = Matcher.prec.ALT;
var s = ms.map(function(m) {
return m.toString(p);
}).join(" | ");
if (prec > p) {
s = "[ " + s + " ]";
}
return s;
});
};
/**
* Create a matcher for two or more options. This implements the
* double bar (||) and double ampersand (&&) operators, as well as
* variants of && where some of the alternatives are optional.
* This will backtrack through even successful matches to try to
* maximize the number of items matched.
*/
Matcher.many = function(required) {
var ms = Array.prototype.slice.call(arguments, 1).reduce(function(acc, v) {
if (v.expand) {
// Insert all of the options for the given complex rule as
// individual options.
var ValidationTypes = require("./ValidationTypes");
acc.push.apply(acc, ValidationTypes.complex[v.expand].options);
} else {
acc.push(Matcher.cast(v));
}
return acc;
}, []);
if (required === true) {
required = ms.map(function() {
return true;
});
}
var result = new Matcher(function(expression) {
var seen = [], max = 0, pass = 0;
var success = function(matchCount) {
if (pass === 0) {
max = Math.max(matchCount, max);
return matchCount === ms.length;
} else {
return matchCount === max;
}
};
var tryMatch = function(matchCount) {
for (var i = 0; i < ms.length; i++) {
if (seen[i]) {
continue;
}
expression.mark();
if (ms[i].match(expression)) {
seen[i] = true;
// Increase matchCount iff this was a required element
// (or if all the elements are optional)
if (tryMatch(matchCount + ((required === false || required[i]) ? 1 : 0))) {
expression.drop();
return true;
}
// Backtrack: try *not* matching using this rule, and
// let's see if it leads to a better overall match.
expression.restore();
seen[i] = false;
} else {
expression.drop();
}
}
return success(matchCount);
};
if (!tryMatch(0)) {
// Couldn't get a complete match, retrace our steps to make the
// match with the maximum # of required elements.
pass++;
tryMatch(0);
}
if (required === false) {
return max > 0;
}
// Use finer-grained specification of which matchers are required.
for (var i = 0; i < ms.length; i++) {
if (required[i] && !seen[i]) {
return false;
}
}
return true;
}, function(prec) {
var p = required === false ? Matcher.prec.OROR : Matcher.prec.ANDAND;
var s = ms.map(function(m, i) {
if (required !== false && !required[i]) {
return m.toString(Matcher.prec.MOD) + "?";
}
return m.toString(p);
}).join(required === false ? " || " : " && ");
if (prec > p) {
s = "[ " + s + " ]";
}
return s;
});
result.options = ms;
return result;
};
/**
* Create a matcher for two or more options, where all options are
* mandatory but they may appear in any order.
*/
Matcher.andand = function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(true);
return Matcher.many.apply(Matcher, args);
};
/**
* Create a matcher for two or more options, where options are
* optional and may appear in any order, but at least one must be
* present.
*/
Matcher.oror = function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(false);
return Matcher.many.apply(Matcher, args);
};
/** Instance methods on Matchers. */
Matcher.prototype = {
constructor: Matcher,
// These are expected to be overridden in every instance.
match: function() { throw new Error("unimplemented"); },
toString: function() { throw new Error("unimplemented"); },
// This returns a standalone function to do the matching.
func: function() { return this.match.bind(this); },
// Basic combinators
then: function(m) { return Matcher.seq(this, m); },
or: function(m) { return Matcher.alt(this, m); },
andand: function(m) { return Matcher.many(true, this, m); },
oror: function(m) { return Matcher.many(false, this, m); },
// Component value multipliers
star: function() { return this.braces(0, Infinity, "*"); },
plus: function() { return this.braces(1, Infinity, "+"); },
question: function() { return this.braces(0, 1, "?"); },
hash: function() {
return this.braces(1, Infinity, "#", Matcher.cast(","));
},
braces: function(min, max, marker, optSep) {
var m1 = this, m2 = optSep ? optSep.then(this) : this;
if (!marker) {
marker = "{" + min + "," + max + "}";
}
return new Matcher(function(expression) {
var result = true, i;
for (i = 0; i < max; i++) {
if (i > 0 && optSep) {
result = m2.match(expression);
} else {
result = m1.match(expression);
}
if (!result) {
break;
}
}
return i >= min;
}, function() {
return m1.toString(Matcher.prec.MOD) + marker;
});
}
};
},{"../util/StringReader":24,"../util/SyntaxError":25,"./ValidationTypes":21}],4:[function(require,module,exports){
"use strict";
module.exports = MediaFeature;
var SyntaxUnit = require("../util/SyntaxUnit");
var Parser = require("./Parser");
/**
* Represents a media feature, such as max-width:500.
* @namespace parserlib.css
* @class MediaFeature
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {SyntaxUnit} name The name of the feature.
* @param {SyntaxUnit} value The value of the feature or null if none.
*/
function MediaFeature(name, value) {
SyntaxUnit.call(this, "(" + name + (value !== null ? ":" + value : "") + ")", name.startLine, name.startCol, Parser.MEDIA_FEATURE_TYPE);
/**
* The name of the media feature
* @type String
* @property name
*/
this.name = name;
/**
* The value for the feature or null if there is none.
* @type SyntaxUnit
* @property value
*/
this.value = value;
}
MediaFeature.prototype = new SyntaxUnit();
MediaFeature.prototype.constructor = MediaFeature;
},{"../util/SyntaxUnit":26,"./Parser":6}],5:[function(require,module,exports){
"use strict";
module.exports = MediaQuery;
var SyntaxUnit = require("../util/SyntaxUnit");
var Parser = require("./Parser");
/**
* Represents an individual media query.
* @namespace parserlib.css
* @class MediaQuery
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {String} modifier The modifier "not" or "only" (or null).
* @param {String} mediaType The type of media (i.e., "print").
* @param {Array} parts Array of selectors parts making up this selector.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function MediaQuery(modifier, mediaType, features, line, col) {
SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
/**
* The media modifier ("not" or "only")
* @type String
* @property modifier
*/
this.modifier = modifier;
/**
* The mediaType (i.e., "print")
* @type String
* @property mediaType
*/
this.mediaType = mediaType;
/**
* The parts that make up the selector.
* @type Array
* @property features
*/
this.features = features;
}
MediaQuery.prototype = new SyntaxUnit();
MediaQuery.prototype.constructor = MediaQuery;
},{"../util/SyntaxUnit":26,"./Parser":6}],6:[function(require,module,exports){
"use strict";
module.exports = Parser;
var EventTarget = require("../util/EventTarget");
var SyntaxError = require("../util/SyntaxError");
var SyntaxUnit = require("../util/SyntaxUnit");
var Combinator = require("./Combinator");
var MediaFeature = require("./MediaFeature");
var MediaQuery = require("./MediaQuery");
var PropertyName = require("./PropertyName");
var PropertyValue = require("./PropertyValue");
var PropertyValuePart = require("./PropertyValuePart");
var Selector = require("./Selector");
var SelectorPart = require("./SelectorPart");
var SelectorSubPart = require("./SelectorSubPart");
var TokenStream = require("./TokenStream");
var Tokens = require("./Tokens");
var Validation = require("./Validation");
/**
* A CSS3 parser.
* @namespace parserlib.css
* @class Parser
* @constructor
* @param {Object} options (Optional) Various options for the parser:
* starHack (true|false) to allow IE6 star hack as valid,
* underscoreHack (true|false) to interpret leading underscores
* as IE6-7 targeting for known properties, ieFilters (true|false)
* to indicate that IE < 8 filters should be accepted and not throw
* syntax errors.
*/
function Parser(options) {
//inherit event functionality
EventTarget.call(this);
this.options = options || {};
this._tokenStream = null;
}
//Static constants
Parser.DEFAULT_TYPE = 0;
Parser.COMBINATOR_TYPE = 1;
Parser.MEDIA_FEATURE_TYPE = 2;
Parser.MEDIA_QUERY_TYPE = 3;
Parser.PROPERTY_NAME_TYPE = 4;
Parser.PROPERTY_VALUE_TYPE = 5;
Parser.PROPERTY_VALUE_PART_TYPE = 6;
Parser.SELECTOR_TYPE = 7;
Parser.SELECTOR_PART_TYPE = 8;
Parser.SELECTOR_SUB_PART_TYPE = 9;
Parser.prototype = function() {
var proto = new EventTarget(), //new prototype
prop,
additions = {
__proto__: null,
//restore constructor
constructor: Parser,
//instance constants - yuck
DEFAULT_TYPE : 0,
COMBINATOR_TYPE : 1,
MEDIA_FEATURE_TYPE : 2,
MEDIA_QUERY_TYPE : 3,
PROPERTY_NAME_TYPE : 4,
PROPERTY_VALUE_TYPE : 5,
PROPERTY_VALUE_PART_TYPE : 6,
SELECTOR_TYPE : 7,
SELECTOR_PART_TYPE : 8,
SELECTOR_SUB_PART_TYPE : 9,
//-----------------------------------------------------------------
// Grammar
//-----------------------------------------------------------------
_stylesheet: function() {
/*
* stylesheet
* : [ CHARSET_SYM S* STRING S* ';' ]?
* [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
* [ namespace [S|CDO|CDC]* ]*
* [ [ ruleset | media | page | font_face | keyframes_rule | supports_rule ] [S|CDO|CDC]* ]*
* ;
*/
var tokenStream = this._tokenStream,
count,
token,
tt;
this.fire("startstylesheet");
//try to read character set
this._charset();
this._skipCruft();
//try to read imports - may be more than one
while (tokenStream.peek() === Tokens.IMPORT_SYM) {
this._import();
this._skipCruft();
}
//try to read namespaces - may be more than one
while (tokenStream.peek() === Tokens.NAMESPACE_SYM) {
this._namespace();
this._skipCruft();
}
//get the next token
tt = tokenStream.peek();
//try to read the rest
while (tt > Tokens.EOF) {
try {
switch (tt) {
case Tokens.MEDIA_SYM:
this._media();
this._skipCruft();
break;
case Tokens.PAGE_SYM:
this._page();
this._skipCruft();
break;
case Tokens.FONT_FACE_SYM:
this._font_face();
this._skipCruft();
break;
case Tokens.KEYFRAMES_SYM:
this._keyframes();
this._skipCruft();
break;
case Tokens.VIEWPORT_SYM:
this._viewport();
this._skipCruft();
break;
case Tokens.DOCUMENT_SYM:
this._document();
this._skipCruft();
break;
case Tokens.SUPPORTS_SYM:
this._supports();
this._skipCruft();
break;
case Tokens.UNKNOWN_SYM: //unknown @ rule
tokenStream.get();
if (!this.options.strict) {
//fire error event
this.fire({
type: "error",
error: null,
message: "Unknown @ rule: " + tokenStream.LT(0).value + ".",
line: tokenStream.LT(0).startLine,
col: tokenStream.LT(0).startCol
});
//skip braces
count=0;
while (tokenStream.advance([Tokens.LBRACE, Tokens.RBRACE]) === Tokens.LBRACE) {
count++; //keep track of nesting depth
}
while (count) {
tokenStream.advance([Tokens.RBRACE]);
count--;
}
} else {
//not a syntax error, rethrow it
throw new SyntaxError("Unknown @ rule.", tokenStream.LT(0).startLine, tokenStream.LT(0).startCol);
}
break;
case Tokens.S:
this._readWhitespace();
break;
default:
if (!this._ruleset()) {
//error handling for known issues
switch (tt) {
case Tokens.CHARSET_SYM:
token = tokenStream.LT(1);
this._charset(false);
throw new SyntaxError("@charset not allowed here.", token.startLine, token.startCol);
case Tokens.IMPORT_SYM:
token = tokenStream.LT(1);
this._import(false);
throw new SyntaxError("@import not allowed here.", token.startLine, token.startCol);
case Tokens.NAMESPACE_SYM:
token = tokenStream.LT(1);
this._namespace(false);
throw new SyntaxError("@namespace not allowed here.", token.startLine, token.startCol);
default:
tokenStream.get(); //get the last token
this._unexpectedToken(tokenStream.token());
}
}
}
} catch (ex) {
if (ex instanceof SyntaxError && !this.options.strict) {
this.fire({
type: "error",
error: ex,
message: ex.message,
line: ex.line,
col: ex.col
});
} else {
throw ex;
}
}
tt = tokenStream.peek();
}
if (tt !== Tokens.EOF) {
this._unexpectedToken(tokenStream.token());
}
this.fire("endstylesheet");
},
_charset: function(emit) {
var tokenStream = this._tokenStream,
charset,
token,
line,
col;
if (tokenStream.match(Tokens.CHARSET_SYM)) {
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
tokenStream.mustMatch(Tokens.STRING);
token = tokenStream.token();
charset = token.value;
this._readWhitespace();
tokenStream.mustMatch(Tokens.SEMICOLON);
if (emit !== false) {
this.fire({
type: "charset",
charset:charset,
line: line,
col: col
});
}
}
},
_import: function(emit) {
/*
* import
* : IMPORT_SYM S*
* [STRING|URI] S* media_query_list? ';' S*
*/
var tokenStream = this._tokenStream,
uri,
importToken,
mediaList = [];
//read import symbol
tokenStream.mustMatch(Tokens.IMPORT_SYM);
importToken = tokenStream.token();
this._readWhitespace();
tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
//grab the URI value
uri = tokenStream.token().value.replace(/^(?:url\()?["']?([^"']+?)["']?\)?$/, "$1");
this._readWhitespace();
mediaList = this._media_query_list();
//must end with a semicolon
tokenStream.mustMatch(Tokens.SEMICOLON);
this._readWhitespace();
if (emit !== false) {
this.fire({
type: "import",
uri: uri,
media: mediaList,
line: importToken.startLine,
col: importToken.startCol
});
}
},
_namespace: function(emit) {
/*
* namespace
* : NAMESPACE_SYM S* [namespace_prefix S*]? [STRING|URI] S* ';' S*
*/
var tokenStream = this._tokenStream,
line,
col,
prefix,
uri;
//read import symbol
tokenStream.mustMatch(Tokens.NAMESPACE_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
//it's a namespace prefix - no _namespace_prefix() method because it's just an IDENT
if (tokenStream.match(Tokens.IDENT)) {
prefix = tokenStream.token().value;
this._readWhitespace();
}
tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
/*if (!tokenStream.match(Tokens.STRING)){
tokenStream.mustMatch(Tokens.URI);
}*/
//grab the URI value
uri = tokenStream.token().value.replace(/(?:url\()?["']([^"']+)["']\)?/, "$1");
this._readWhitespace();
//must end with a semicolon
tokenStream.mustMatch(Tokens.SEMICOLON);
this._readWhitespace();
if (emit !== false) {
this.fire({
type: "namespace",
prefix: prefix,
uri: uri,
line: line,
col: col
});
}
},
_supports: function(emit) {
/*
* supports_rule
* : SUPPORTS_SYM S* supports_condition S* group_rule_body
* ;
*/
var tokenStream = this._tokenStream,
line,
col;
if (tokenStream.match(Tokens.SUPPORTS_SYM)) {
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
this._supports_condition();
this._readWhitespace();
tokenStream.mustMatch(Tokens.LBRACE);
this._readWhitespace();
if (emit !== false) {
this.fire({
type: "startsupports",
line: line,
col: col
});
}
while (true) {
if (!this._ruleset()) {
break;
}
}
tokenStream.mustMatch(Tokens.RBRACE);
this._readWhitespace();
this.fire({
type: "endsupports",
line: line,
col: col
});
}
},
_supports_condition: function() {
/*
* supports_condition
* : supports_negation | supports_conjunction | supports_disjunction |
* supports_condition_in_parens
* ;
*/
var tokenStream = this._tokenStream,
ident;
if (tokenStream.match(Tokens.IDENT)) {
ident = tokenStream.token().value.toLowerCase();
if (ident === "not") {
tokenStream.mustMatch(Tokens.S);
this._supports_condition_in_parens();
} else {
tokenStream.unget();
}
} else {
this._supports_condition_in_parens();
this._readWhitespace();
while (tokenStream.peek() === Tokens.IDENT) {
ident = tokenStream.LT(1).value.toLowerCase();
if (ident === "and" || ident === "or") {
tokenStream.mustMatch(Tokens.IDENT);
this._readWhitespace();
this._supports_condition_in_parens();
this._readWhitespace();
}
}
}
},
_supports_condition_in_parens: function() {
/*
* supports_condition_in_parens
* : ( '(' S* supports_condition S* ')' ) | supports_declaration_condition |
* general_enclosed
* ;
*/
var tokenStream = this._tokenStream,
ident;
if (tokenStream.match(Tokens.LPAREN)) {
this._readWhitespace();
if (tokenStream.match(Tokens.IDENT)) {
// look ahead for not keyword, if not given, continue with declaration condition.
ident = tokenStream.token().value.toLowerCase();
if (ident === "not") {
this._readWhitespace();
this._supports_condition();
this._readWhitespace();
tokenStream.mustMatch(Tokens.RPAREN);
} else {
tokenStream.unget();
this._supports_declaration_condition(false);
}
} else {
this._supports_condition();
this._readWhitespace();
tokenStream.mustMatch(Tokens.RPAREN);
}
} else {
this._supports_declaration_condition();
}
},
_supports_declaration_condition: function(requireStartParen) {
/*
* supports_declaration_condition
* : '(' S* declaration ')'
* ;
*/
var tokenStream = this._tokenStream;
if (requireStartParen !== false) {
tokenStream.mustMatch(Tokens.LPAREN);
}
this._readWhitespace();
this._declaration();
tokenStream.mustMatch(Tokens.RPAREN);
},
_media: function() {
/*
* media
* : MEDIA_SYM S* media_query_list S* '{' S* ruleset* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col,
mediaList;// = [];
//look for @media
tokenStream.mustMatch(Tokens.MEDIA_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
mediaList = this._media_query_list();
tokenStream.mustMatch(Tokens.LBRACE);
this._readWhitespace();
this.fire({
type: "startmedia",
media: mediaList,
line: line,
col: col
});
while (true) {
if (tokenStream.peek() === Tokens.PAGE_SYM) {
this._page();
} else if (tokenStream.peek() === Tokens.FONT_FACE_SYM) {
this._font_face();
} else if (tokenStream.peek() === Tokens.VIEWPORT_SYM) {
this._viewport();
} else if (tokenStream.peek() === Tokens.DOCUMENT_SYM) {
this._document();
} else if (tokenStream.peek() === Tokens.SUPPORTS_SYM) {
this._supports();
} else if (!this._ruleset()) {
break;
}
}
tokenStream.mustMatch(Tokens.RBRACE);
this._readWhitespace();
this.fire({
type: "endmedia",
media: mediaList,
line: line,
col: col
});
},
//CSS3 Media Queries
_media_query_list: function() {
/*
* media_query_list
* : S* [media_query [ ',' S* media_query ]* ]?
* ;
*/
var tokenStream = this._tokenStream,
mediaList = [];
this._readWhitespace();
if (tokenStream.peek() === Tokens.IDENT || tokenStream.peek() === Tokens.LPAREN) {
mediaList.push(this._media_query());
}
while (tokenStream.match(Tokens.COMMA)) {
this._readWhitespace();
mediaList.push(this._media_query());
}
return mediaList;
},
/*
* Note: "expression" in the grammar maps to the _media_expression
* method.
*/
_media_query: function() {
/*
* media_query
* : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
* | expression [ AND S* expression ]*
* ;
*/
var tokenStream = this._tokenStream,
type = null,
ident = null,
token = null,
expressions = [];
if (tokenStream.match(Tokens.IDENT)) {
ident = tokenStream.token().value.toLowerCase();
//since there's no custom tokens for these, need to manually check
if (ident !== "only" && ident !== "not") {
tokenStream.unget();
ident = null;
} else {
token = tokenStream.token();
}
}
this._readWhitespace();
if (tokenStream.peek() === Tokens.IDENT) {
type = this._media_type();
if (token === null) {
token = tokenStream.token();
}
} else if (tokenStream.peek() === Tokens.LPAREN) {
if (token === null) {
token = tokenStream.LT(1);
}
expressions.push(this._media_expression());
}
if (type === null && expressions.length === 0) {
return null;
} else {
this._readWhitespace();
while (tokenStream.match(Tokens.IDENT)) {
if (tokenStream.token().value.toLowerCase() !== "and") {
this._unexpectedToken(tokenStream.token());
}
this._readWhitespace();
expressions.push(this._media_expression());
}
}
return new MediaQuery(ident, type, expressions, token.startLine, token.startCol);
},
//CSS3 Media Queries
_media_type: function() {
/*
* media_type
* : IDENT
* ;
*/
return this._media_feature();
},
/**
* Note: in CSS3 Media Queries, this is called "expression".
* Renamed here to avoid conflict with CSS3 Selectors
* definition of "expression". Also note that "expr" in the
* grammar now maps to "expression" from CSS3 selectors.
* @method _media_expression
* @private
*/
_media_expression: function() {
/*
* expression
* : '(' S* media_feature S* [ ':' S* expr ]? ')' S*
* ;
*/
var tokenStream = this._tokenStream,
feature = null,
token,
expression = null;
tokenStream.mustMatch(Tokens.LPAREN);
feature = this._media_feature();
this._readWhitespace();
if (tokenStream.match(Tokens.COLON)) {
this._readWhitespace();
token = tokenStream.LT(1);
expression = this._expression();
}
tokenStream.mustMatch(Tokens.RPAREN);
this._readWhitespace();
return new MediaFeature(feature, expression ? new SyntaxUnit(expression, token.startLine, token.startCol) : null);
},
//CSS3 Media Queries
_media_feature: function() {
/*
* media_feature
* : IDENT
* ;
*/
var tokenStream = this._tokenStream;
this._readWhitespace();
tokenStream.mustMatch(Tokens.IDENT);
return SyntaxUnit.fromToken(tokenStream.token());
},
//CSS3 Paged Media
_page: function() {
/*
* page:
* PAGE_SYM S* IDENT? pseudo_page? S*
* '{' S* [ declaration | margin ]? [ ';' S* [ declaration | margin ]? ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col,
identifier = null,
pseudoPage = null;
//look for @page
tokenStream.mustMatch(Tokens.PAGE_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
if (tokenStream.match(Tokens.IDENT)) {
identifier = tokenStream.token().value;
//The value 'auto' may not be used as a page name and MUST be treated as a syntax error.
if (identifier.toLowerCase() === "auto") {
this._unexpectedToken(tokenStream.token());
}
}
//see if there's a colon upcoming
if (tokenStream.peek() === Tokens.COLON) {
pseudoPage = this._pseudo_page();
}
this._readWhitespace();
this.fire({
type: "startpage",
id: identifier,
pseudo: pseudoPage,
line: line,
col: col
});
this._readDeclarations(true, true);
this.fire({
type: "endpage",
id: identifier,
pseudo: pseudoPage,
line: line,
col: col
});
},
//CSS3 Paged Media
_margin: function() {
/*
* margin :
* margin_sym S* '{' declaration [ ';' S* declaration? ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col,
marginSym = this._margin_sym();
if (marginSym) {
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this.fire({
type: "startpagemargin",
margin: marginSym,
line: line,
col: col
});
this._readDeclarations(true);
this.fire({
type: "endpagemargin",
margin: marginSym,
line: line,
col: col
});
return true;
} else {
return false;
}
},
//CSS3 Paged Media
_margin_sym: function() {
/*
* margin_sym :
* TOPLEFTCORNER_SYM |
* TOPLEFT_SYM |
* TOPCENTER_SYM |
* TOPRIGHT_SYM |
* TOPRIGHTCORNER_SYM |
* BOTTOMLEFTCORNER_SYM |
* BOTTOMLEFT_SYM |
* BOTTOMCENTER_SYM |
* BOTTOMRIGHT_SYM |
* BOTTOMRIGHTCORNER_SYM |
* LEFTTOP_SYM |
* LEFTMIDDLE_SYM |
* LEFTBOTTOM_SYM |
* RIGHTTOP_SYM |
* RIGHTMIDDLE_SYM |
* RIGHTBOTTOM_SYM
* ;
*/
var tokenStream = this._tokenStream;
if (tokenStream.match([Tokens.TOPLEFTCORNER_SYM, Tokens.TOPLEFT_SYM,
Tokens.TOPCENTER_SYM, Tokens.TOPRIGHT_SYM, Tokens.TOPRIGHTCORNER_SYM,
Tokens.BOTTOMLEFTCORNER_SYM, Tokens.BOTTOMLEFT_SYM,
Tokens.BOTTOMCENTER_SYM, Tokens.BOTTOMRIGHT_SYM,
Tokens.BOTTOMRIGHTCORNER_SYM, Tokens.LEFTTOP_SYM,
Tokens.LEFTMIDDLE_SYM, Tokens.LEFTBOTTOM_SYM, Tokens.RIGHTTOP_SYM,
Tokens.RIGHTMIDDLE_SYM, Tokens.RIGHTBOTTOM_SYM])) {
return SyntaxUnit.fromToken(tokenStream.token());
} else {
return null;
}
},
_pseudo_page: function() {
/*
* pseudo_page
* : ':' IDENT
* ;
*/
var tokenStream = this._tokenStream;
tokenStream.mustMatch(Tokens.COLON);
tokenStream.mustMatch(Tokens.IDENT);
//TODO: CSS3 Paged Media says only "left", "center", and "right" are allowed
return tokenStream.token().value;
},
_font_face: function() {
/*
* font_face
* : FONT_FACE_SYM S*
* '{' S* declaration [ ';' S* declaration ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col;
//look for @page
tokenStream.mustMatch(Tokens.FONT_FACE_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
this.fire({
type: "startfontface",
line: line,
col: col
});
this._readDeclarations(true);
this.fire({
type: "endfontface",
line: line,
col: col
});
},
_viewport: function() {
/*
* viewport
* : VIEWPORT_SYM S*
* '{' S* declaration? [ ';' S* declaration? ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
line,
col;
tokenStream.mustMatch(Tokens.VIEWPORT_SYM);
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
this._readWhitespace();
this.fire({
type: "startviewport",
line: line,
col: col
});
this._readDeclarations(true);
this.fire({
type: "endviewport",
line: line,
col: col
});
},
_document: function() {
/*
* document
* : DOCUMENT_SYM S*
* _document_function [ ',' S* _document_function ]* S*
* '{' S* ruleset* '}'
* ;
*/
var tokenStream = this._tokenStream,
token,
functions = [],
prefix = "";
tokenStream.mustMatch(Tokens.DOCUMENT_SYM);
token = tokenStream.token();
if (/^@\-([^\-]+)\-/.test(token.value)) {
prefix = RegExp.$1;
}
this._readWhitespace();
functions.push(this._document_function());
while (tokenStream.match(Tokens.COMMA)) {
this._readWhitespace();
functions.push(this._document_function());
}
tokenStream.mustMatch(Tokens.LBRACE);
this._readWhitespace();
this.fire({
type: "startdocument",
functions: functions,
prefix: prefix,
line: token.startLine,
col: token.startCol
});
var ok = true;
while (ok) {
switch (tokenStream.peek()) {
case Tokens.PAGE_SYM:
this._page();
break;
case Tokens.FONT_FACE_SYM:
this._font_face();
break;
case Tokens.VIEWPORT_SYM:
this._viewport();
break;
case Tokens.MEDIA_SYM:
this._media();
break;
case Tokens.KEYFRAMES_SYM:
this._keyframes();
break;
case Tokens.DOCUMENT_SYM:
this._document();
break;
default:
ok = Boolean(this._ruleset());
}
}
tokenStream.mustMatch(Tokens.RBRACE);
token = tokenStream.token();
this._readWhitespace();
this.fire({
type: "enddocument",
functions: functions,
prefix: prefix,
line: token.startLine,
col: token.startCol
});
},
_document_function: function() {
/*
* document_function
* : function | URI S*
* ;
*/
var tokenStream = this._tokenStream,
value;
if (tokenStream.match(Tokens.URI)) {
value = tokenStream.token().value;
this._readWhitespace();
} else {
value = this._function();
}
return value;
},
_operator: function(inFunction) {
/*
* operator (outside function)
* : '/' S* | ',' S* | /( empty )/
* operator (inside function)
* : '/' S* | '+' S* | '*' S* | '-' S* /( empty )/
* ;
*/
var tokenStream = this._tokenStream,
token = null;
if (tokenStream.match([Tokens.SLASH, Tokens.COMMA]) ||
(inFunction && tokenStream.match([Tokens.PLUS, Tokens.STAR, Tokens.MINUS]))) {
token = tokenStream.token();
this._readWhitespace();
}
return token ? PropertyValuePart.fromToken(token) : null;
},
_combinator: function() {
/*
* combinator
* : PLUS S* | GREATER S* | TILDE S* | S+
* ;
*/
var tokenStream = this._tokenStream,
value = null,
token;
if (tokenStream.match([Tokens.PLUS, Tokens.GREATER, Tokens.TILDE])) {
token = tokenStream.token();
value = new Combinator(token.value, token.startLine, token.startCol);
this._readWhitespace();
}
return value;
},
_unary_operator: function() {
/*
* unary_operator
* : '-' | '+'
* ;
*/
var tokenStream = this._tokenStream;
if (tokenStream.match([Tokens.MINUS, Tokens.PLUS])) {
return tokenStream.token().value;
} else {
return null;
}
},
_property: function() {
/*
* property
* : IDENT S*
* ;
*/
var tokenStream = this._tokenStream,
value = null,
hack = null,
tokenValue,
token,
line,
col;
//check for star hack - throws error if not allowed
if (tokenStream.peek() === Tokens.STAR && this.options.starHack) {
tokenStream.get();
token = tokenStream.token();
hack = token.value;
line = token.startLine;
col = token.startCol;
}
if (tokenStream.match(Tokens.IDENT)) {
token = tokenStream.token();
tokenValue = token.value;
//check for underscore hack - no error if not allowed because it's valid CSS syntax
if (tokenValue.charAt(0) === "_" && this.options.underscoreHack) {
hack = "_";
tokenValue = tokenValue.substring(1);
}
value = new PropertyName(tokenValue, hack, (line||token.startLine), (col||token.startCol));
this._readWhitespace();
}
return value;
},
//Augmented with CSS3 Selectors
_ruleset: function() {
/*
* ruleset
* : selectors_group
* '{' S* declaration? [ ';' S* declaration? ]* '}' S*
* ;
*/
var tokenStream = this._tokenStream,
tt,
selectors;
/*
* Error Recovery: If even a single selector fails to parse,
* then the entire ruleset should be thrown away.
*/
try {
selectors = this._selectors_group();
} catch (ex) {
if (ex instanceof SyntaxError && !this.options.strict) {
//fire error event
this.fire({
type: "error",
error: ex,
message: ex.message,
line: ex.line,
col: ex.col
});
//skip over everything until closing brace
tt = tokenStream.advance([Tokens.RBRACE]);
if (tt === Tokens.RBRACE) {
//if there's a right brace, the rule is finished so don't do anything
} else {
//otherwise, rethrow the error because it wasn't handled properly
throw ex;
}
} else {
//not a syntax error, rethrow it
throw ex;
}
//trigger parser to continue
return true;
}
//if it got here, all selectors parsed
if (selectors) {
this.fire({
type: "startrule",
selectors: selectors,
line: selectors[0].line,
col: selectors[0].col
});
this._readDeclarations(true);
this.fire({
type: "endrule",
selectors: selectors,
line: selectors[0].line,
col: selectors[0].col
});
}
return selectors;
},
//CSS3 Selectors
_selectors_group: function() {
/*
* selectors_group
* : selector [ COMMA S* selector ]*
* ;
*/
var tokenStream = this._tokenStream,
selectors = [],
selector;
selector = this._selector();
if (selector !== null) {
selectors.push(selector);
while (tokenStream.match(Tokens.COMMA)) {
this._readWhitespace();
selector = this._selector();
if (selector !== null) {
selectors.push(selector);
} else {
this._unexpectedToken(tokenStream.LT(1));
}
}
}
return selectors.length ? selectors : null;
},
//CSS3 Selectors
_selector: function() {
/*
* selector
* : simple_selector_sequence [ combinator simple_selector_sequence ]*
* ;
*/
var tokenStream = this._tokenStream,
selector = [],
nextSelector = null,
combinator = null,
ws = null;
//if there's no simple selector, then there's no selector
nextSelector = this._simple_selector_sequence();
if (nextSelector === null) {
return null;
}
selector.push(nextSelector);
do {
//look for a combinator
combinator = this._combinator();
if (combinator !== null) {
selector.push(combinator);
nextSelector = this._simple_selector_sequence();
//there must be a next selector
if (nextSelector === null) {
this._unexpectedToken(tokenStream.LT(1));
} else {
//nextSelector is an instance of SelectorPart
selector.push(nextSelector);
}
} else {
//if there's not whitespace, we're done
if (this._readWhitespace()) {
//add whitespace separator
ws = new Combinator(tokenStream.token().value, tokenStream.token().startLine, tokenStream.token().startCol);
//combinator is not required
combinator = this._combinator();
//selector is required if there's a combinator
nextSelector = this._simple_selector_sequence();
if (nextSelector === null) {
if (combinator !== null) {
this._unexpectedToken(tokenStream.LT(1));
}
} else {
if (combinator !== null) {
selector.push(combinator);
} else {
selector.push(ws);
}
selector.push(nextSelector);
}
} else {
break;
}
}
} while (true);
return new Selector(selector, selector[0].line, selector[0].col);
},
//CSS3 Selectors
_simple_selector_sequence: function() {
/*
* simple_selector_sequence
* : [ type_selector | universal ]
* [ HASH | class | attrib | pseudo | negation ]*
* | [ HASH | class | attrib | pseudo | negation ]+
* ;
*/
var tokenStream = this._tokenStream,
//parts of a simple selector
elementName = null,
modifiers = [],
//complete selector text
selectorText= "",
//the different parts after the element name to search for
components = [
//HASH
function() {
return tokenStream.match(Tokens.HASH) ?
new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
null;
},
this._class,
this._attrib,
this._pseudo,
this._negation
],
i = 0,
len = components.length,
component = null,
line,
col;
//get starting line and column for the selector
line = tokenStream.LT(1).startLine;
col = tokenStream.LT(1).startCol;
elementName = this._type_selector();
if (!elementName) {
elementName = this._universal();
}
if (elementName !== null) {
selectorText += elementName;
}
while (true) {
//whitespace means we're done
if (tokenStream.peek() === Tokens.S) {
break;
}
//check for each component
while (i < len && component === null) {
component = components[i++].call(this);
}
if (component === null) {
//we don't have a selector
if (selectorText === "") {
return null;
} else {
break;
}
} else {
i = 0;
modifiers.push(component);
selectorText += component.toString();
component = null;
}
}
return selectorText !== "" ?
new SelectorPart(elementName, modifiers, selectorText, line, col) :
null;
},
//CSS3 Selectors
_type_selector: function() {
/*
* type_selector
* : [ namespace_prefix ]? element_name
* ;
*/
var tokenStream = this._tokenStream,
ns = this._namespace_prefix(),
elementName = this._element_name();
if (!elementName) {
/*
* Need to back out the namespace that was read due to both
* type_selector and universal reading namespace_prefix
* first. Kind of hacky, but only way I can figure out
* right now how to not change the grammar.
*/
if (ns) {
tokenStream.unget();
if (ns.length > 1) {
tokenStream.unget();
}
}
return null;
} else {
if (ns) {
elementName.text = ns + elementName.text;
elementName.col -= ns.length;
}
return elementName;
}
},
//CSS3 Selectors
_class: function() {
/*
* class
* : '.' IDENT
* ;
*/
var tokenStream = this._tokenStream,
token;
if (tokenStream.match(Tokens.DOT)) {
tokenStream.mustMatch(Tokens.IDENT);
token = tokenStream.token();
return new SelectorSubPart("." + token.value, "class", token.startLine, token.startCol - 1);
} else {
return null;
}
},
//CSS3 Selectors
_element_name: function() {
/*
* element_name
* : IDENT
* ;
*/
var tokenStream = this._tokenStream,
token;
if (tokenStream.match(Tokens.IDENT)) {
token = tokenStream.token();
return new SelectorSubPart(token.value, "elementName", token.startLine, token.startCol);
} else {
return null;
}
},
//CSS3 Selectors
_namespace_prefix: function() {
/*
* namespace_prefix
* : [ IDENT | '*' ]? '|'
* ;
*/
var tokenStream = this._tokenStream,
value = "";
//verify that this is a namespace prefix
if (tokenStream.LA(1) === Tokens.PIPE || tokenStream.LA(2) === Tokens.PIPE) {
if (tokenStream.match([Tokens.IDENT, Tokens.STAR])) {
value += tokenStream.token().value;
}
tokenStream.mustMatch(Tokens.PIPE);
value += "|";
}
return value.length ? value : null;
},
//CSS3 Selectors
_universal: function() {
/*
* universal
* : [ namespace_prefix ]? '*'
* ;
*/
var tokenStream = this._tokenStream,
value = "",
ns;
ns = this._namespace_prefix();
if (ns) {
value += ns;
}
if (tokenStream.match(Tokens.STAR)) {
value += "*";
}
return value.length ? value : null;
},
//CSS3 Selectors
_attrib: function() {
/*
* attrib
* : '[' S* [ namespace_prefix ]? IDENT S*
* [ [ PREFIXMATCH |
* SUFFIXMATCH |
* SUBSTRINGMATCH |
* '=' |
* INCLUDES |
* DASHMATCH ] S* [ IDENT | STRING ] S*
* ]? ']'
* ;
*/
var tokenStream = this._tokenStream,
value = null,
ns,
token;
if (tokenStream.match(Tokens.LBRACKET)) {
token = tokenStream.token();
value = token.value;
value += this._readWhitespace();
ns = this._namespace_prefix();
if (ns) {
value += ns;
}
tokenStream.mustMatch(Tokens.IDENT);
value += tokenStream.token().value;
value += this._readWhitespace();
if (tokenStream.match([Tokens.PREFIXMATCH, Tokens.SUFFIXMATCH, Tokens.SUBSTRINGMATCH,
Tokens.EQUALS, Tokens.INCLUDES, Tokens.DASHMATCH])) {
value += tokenStream.token().value;
value += this._readWhitespace();
tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
value += tokenStream.token().value;
value += this._readWhitespace();
}
tokenStream.mustMatch(Tokens.RBRACKET);
return new SelectorSubPart(value + "]", "attribute", token.startLine, token.startCol);
} else {
return null;
}
},
//CSS3 Selectors
_pseudo: function() {
/*
* pseudo
* : ':' ':'? [ IDENT | functional_pseudo ]
* ;
*/
var tokenStream = this._tokenStream,
pseudo = null,
colons = ":",
line,
col;
if (tokenStream.match(Tokens.COLON)) {
if (tokenStream.match(Tokens.COLON)) {
colons += ":";
}
if (tokenStream.match(Tokens.IDENT)) {
pseudo = tokenStream.token().value;
line = tokenStream.token().startLine;
col = tokenStream.token().startCol - colons.length;
} else if (tokenStream.peek() === Tokens.FUNCTION) {
line = tokenStream.LT(1).startLine;
col = tokenStream.LT(1).startCol - colons.length;
pseudo = this._functional_pseudo();
}
if (pseudo) {
pseudo = new SelectorSubPart(colons + pseudo, "pseudo", line, col);
} else {
var startLine = tokenStream.LT(1).startLine,
startCol = tokenStream.LT(0).startCol;
throw new SyntaxError("Expected a `FUNCTION` or `IDENT` after colon at line " + startLine + ", col " + startCol + ".", startLine, startCol);
}
}
return pseudo;
},
//CSS3 Selectors
_functional_pseudo: function() {
/*
* functional_pseudo
* : FUNCTION S* expression ')'
* ;
*/
var tokenStream = this._tokenStream,
value = null;
if (tokenStream.match(Tokens.FUNCTION)) {
value = tokenStream.token().value;
value += this._readWhitespace();
value += this._expression();
tokenStream.mustMatch(Tokens.RPAREN);
value += ")";
}
return value;
},
//CSS3 Selectors
_expression: function() {
/*
* expression
* : [ [ PLUS | '-' | DIMENSION | NUMBER | STRING | IDENT ] S* ]+
* ;
*/
var tokenStream = this._tokenStream,
value = "";
while (tokenStream.match([Tokens.PLUS, Tokens.MINUS, Tokens.DIMENSION,
Tokens.NUMBER, Tokens.STRING, Tokens.IDENT, Tokens.LENGTH,
Tokens.FREQ, Tokens.ANGLE, Tokens.TIME,
Tokens.RESOLUTION, Tokens.SLASH])) {
value += tokenStream.token().value;
value += this._readWhitespace();
}
return value.length ? value : null;
},
//CSS3 Selectors
_negation: function() {
/*
* negation
* : NOT S* negation_arg S* ')'
* ;
*/
var tokenStream = this._tokenStream,
line,
col,
value = "",
arg,
subpart = null;
if (tokenStream.match(Tokens.NOT)) {
value = tokenStream.token().value;
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
value += this._readWhitespace();
arg = this._negation_arg();
value += arg;
value += this._readWhitespace();
tokenStream.match(Tokens.RPAREN);
value += tokenStream.token().value;
subpart = new SelectorSubPart(value, "not", line, col);
subpart.args.push(arg);
}
return subpart;
},
//CSS3 Selectors
_negation_arg: function() {
/*
* negation_arg
* : type_selector | universal | HASH | class | attrib | pseudo
* ;
*/
var tokenStream = this._tokenStream,
args = [
this._type_selector,
this._universal,
function() {
return tokenStream.match(Tokens.HASH) ?
new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
null;
},
this._class,
this._attrib,
this._pseudo
],
arg = null,
i = 0,
len = args.length,
line,
col,
part;
line = tokenStream.LT(1).startLine;
col = tokenStream.LT(1).startCol;
while (i < len && arg === null) {
arg = args[i].call(this);
i++;
}
//must be a negation arg
if (arg === null) {
this._unexpectedToken(tokenStream.LT(1));
}
//it's an element name
if (arg.type === "elementName") {
part = new SelectorPart(arg, [], arg.toString(), line, col);
} else {
part = new SelectorPart(null, [arg], arg.toString(), line, col);
}
return part;
},
_declaration: function() {
/*
* declaration
* : property ':' S* expr prio?
* | /( empty )/
* ;
*/
var tokenStream = this._tokenStream,
property = null,
expr = null,
prio = null,
invalid = null,
propertyName= "";
property = this._property();
if (property !== null) {
tokenStream.mustMatch(Tokens.COLON);
this._readWhitespace();
expr = this._expr();
//if there's no parts for the value, it's an error
if (!expr || expr.length === 0) {
this._unexpectedToken(tokenStream.LT(1));
}
prio = this._prio();
/*
* If hacks should be allowed, then only check the root
* property. If hacks should not be allowed, treat
* _property or *property as invalid properties.
*/
propertyName = property.toString();
if (this.options.starHack && property.hack === "*" ||
this.options.underscoreHack && property.hack === "_") {
propertyName = property.text;
}
try {
this._validateProperty(propertyName, expr);
} catch (ex) {
invalid = ex;
}
this.fire({
type: "property",
property: property,
value: expr,
important: prio,
line: property.line,
col: property.col,
invalid: invalid
});
return true;
} else {
return false;
}
},
_prio: function() {
/*
* prio
* : IMPORTANT_SYM S*
* ;
*/
var tokenStream = this._tokenStream,
result = tokenStream.match(Tokens.IMPORTANT_SYM);
this._readWhitespace();
return result;
},
_expr: function(inFunction) {
/*
* expr
* : term [ operator term ]*
* ;
*/
var values = [],
//valueParts = [],
value = null,
operator = null;
value = this._term(inFunction);
if (value !== null) {
values.push(value);
do {
operator = this._operator(inFunction);
//if there's an operator, keep building up the value parts
if (operator) {
values.push(operator);
} /*else {
//if there's not an operator, you have a full value
values.push(new PropertyValue(valueParts, valueParts[0].line, valueParts[0].col));
valueParts = [];
}*/
value = this._term(inFunction);
if (value === null) {
break;
} else {
values.push(value);
}
} while (true);
}
//cleanup
/*if (valueParts.length) {
values.push(new PropertyValue(valueParts, valueParts[0].line, valueParts[0].col));
}*/
return values.length > 0 ? new PropertyValue(values, values[0].line, values[0].col) : null;
},
_term: function(inFunction) {
/*
* term
* : unary_operator?
* [ NUMBER S* | PERCENTAGE S* | LENGTH S* | ANGLE S* |
* TIME S* | FREQ S* | function | ie_function ]
* | STRING S* | IDENT S* | URI S* | UNICODERANGE S* | hexcolor
* ;
*/
var tokenStream = this._tokenStream,
unary = null,
value = null,
endChar = null,
part = null,
token,
line,
col;
//returns the operator or null
unary = this._unary_operator();
if (unary !== null) {
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
}
//exception for IE filters
if (tokenStream.peek() === Tokens.IE_FUNCTION && this.options.ieFilters) {
value = this._ie_function();
if (unary === null) {
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
}
//see if it's a simple block
} else if (inFunction && tokenStream.match([Tokens.LPAREN, Tokens.LBRACE, Tokens.LBRACKET])) {
token = tokenStream.token();
endChar = token.endChar;
value = token.value + this._expr(inFunction).text;
if (unary === null) {
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
}
tokenStream.mustMatch(Tokens.type(endChar));
value += endChar;
this._readWhitespace();
//see if there's a simple match
} else if (tokenStream.match([Tokens.NUMBER, Tokens.PERCENTAGE, Tokens.LENGTH,
Tokens.ANGLE, Tokens.TIME,
Tokens.FREQ, Tokens.STRING, Tokens.IDENT, Tokens.URI, Tokens.UNICODE_RANGE])) {
value = tokenStream.token().value;
if (unary === null) {
line = tokenStream.token().startLine;
col = tokenStream.token().startCol;
// Correct potentially-inaccurate IDENT parsing in
// PropertyValuePart constructor.
part = PropertyValuePart.fromToken(tokenStream.token());
}
this._readWhitespace();
} else {
//see if it's a color
token = this._hexcolor();
if (token === null) {
//if there's no unary, get the start of the next token for line/col info
if (unary === null) {
line = tokenStream.LT(1).startLine;
col = tokenStream.LT(1).startCol;
}
//has to be a function
if (value === null) {
/*
* This checks for alpha(opacity=0) style of IE
* functions. IE_FUNCTION only presents progid: style.
*/
if (tokenStream.LA(3) === Tokens.EQUALS && this.options.ieFilters) {
value = this._ie_function();
} else {
value = this._function();
}
}
/*if (value === null) {
return null;
//throw new Error("Expected identifier at line " + tokenStream.token().startLine + ", character " + tokenStream.token().startCol + ".");
}*/
} else {
value = token.value;
if (unary === null) {
line = token.startLine;
col = token.startCol;
}
}
}
return part !== null ? part : value !== null ?
new PropertyValuePart(unary !== null ? unary + value : value, line, col) :
null;
},
_function: function() {
/*
* function
* : FUNCTION S* expr ')' S*
* ;
*/
var tokenStream = this._tokenStream,
functionText = null,
expr = null,
lt;
if (tokenStream.match(Tokens.FUNCTION)) {
functionText = tokenStream.token().value;
this._readWhitespace();
expr = this._expr(true);
functionText += expr;
//START: Horrible hack in case it's an IE filter
if (this.options.ieFilters && tokenStream.peek() === Tokens.EQUALS) {
do {
if (this._readWhitespace()) {
functionText += tokenStream.token().value;
}
//might be second time in the loop
if (tokenStream.LA(0) === Tokens.COMMA) {
functionText += tokenStream.token().value;
}
tokenStream.match(Tokens.IDENT);
functionText += tokenStream.token().value;
tokenStream.match(Tokens.EQUALS);
functionText += tokenStream.token().value;
//functionText += this._term();
lt = tokenStream.peek();
while (lt !== Tokens.COMMA && lt !== Tokens.S && lt !== Tokens.RPAREN) {
tokenStream.get();
functionText += tokenStream.token().value;
lt = tokenStream.peek();
}
} while (tokenStream.match([Tokens.COMMA, Tokens.S]));
}
//END: Horrible Hack
tokenStream.match(Tokens.RPAREN);
functionText += ")";
this._readWhitespace();
}
return functionText;
},
_ie_function: function() {
/* (My own extension)
* ie_function
* : IE_FUNCTION S* IDENT '=' term [S* ','? IDENT '=' term]+ ')' S*
* ;
*/
var tokenStream = this._tokenStream,
functionText = null,
lt;
//IE function can begin like a regular function, too
if (tokenStream.match([Tokens.IE_FUNCTION, Tokens.FUNCTION])) {
functionText = tokenStream.token().value;
do {
if (this._readWhitespace()) {
functionText += tokenStream.token().value;
}
//might be second time in the loop
if (tokenStream.LA(0) === Tokens.COMMA) {
functionText += tokenStream.token().value;
}
tokenStream.match(Tokens.IDENT);
functionText += tokenStream.token().value;
tokenStream.match(Tokens.EQUALS);
functionText += tokenStream.token().value;
//functionText += this._term();
lt = tokenStream.peek();
while (lt !== Tokens.COMMA && lt !== Tokens.S && lt !== Tokens.RPAREN) {
tokenStream.get();
functionText += tokenStream.token().value;
lt = tokenStream.peek();
}
} while (tokenStream.match([Tokens.COMMA, Tokens.S]));
tokenStream.match(Tokens.RPAREN);
functionText += ")";
this._readWhitespace();
}
return functionText;
},
_hexcolor: function() {
/*
* There is a constraint on the color that it must
* have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
* after the "#"; e.g., "#000" is OK, but "#abcd" is not.
*
* hexcolor
* : HASH S*
* ;
*/
var tokenStream = this._tokenStream,
token = null,
color;
if (tokenStream.match(Tokens.HASH)) {
//need to do some validation here
token = tokenStream.token();
color = token.value;
if (!/#[a-f0-9]{3,6}/i.test(color)) {
throw new SyntaxError("Expected a hex color but found '" + color + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
}
this._readWhitespace();
}
return token;
},
//-----------------------------------------------------------------
// Animations methods
//-----------------------------------------------------------------
_keyframes: function() {
/*
* keyframes:
* : KEYFRAMES_SYM S* keyframe_name S* '{' S* keyframe_rule* '}' {
* ;
*/
var tokenStream = this._tokenStream,
token,
tt,
name,
prefix = "";
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
token = tokenStream.token();
if (/^@\-([^\-]+)\-/.test(token.value)) {
prefix = RegExp.$1;
}
this._readWhitespace();
name = this._keyframe_name();
this._readWhitespace();
tokenStream.mustMatch(Tokens.LBRACE);
this.fire({
type: "startkeyframes",
name: name,
prefix: prefix,
line: token.startLine,
col: token.startCol
});
this._readWhitespace();
tt = tokenStream.peek();
//check for key
while (tt === Tokens.IDENT || tt === Tokens.PERCENTAGE) {
this._keyframe_rule();
this._readWhitespace();
tt = tokenStream.peek();
}
this.fire({
type: "endkeyframes",
name: name,
prefix: prefix,
line: token.startLine,
col: token.startCol
});
this._readWhitespace();
tokenStream.mustMatch(Tokens.RBRACE);
this._readWhitespace();
},
_keyframe_name: function() {
/*
* keyframe_name:
* : IDENT
* | STRING
* ;
*/
var tokenStream = this._tokenStream;
tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
return SyntaxUnit.fromToken(tokenStream.token());
},
_keyframe_rule: function() {
/*
* keyframe_rule:
* : key_list S*
* '{' S* declaration [ ';' S* declaration ]* '}' S*
* ;
*/
var keyList = this._key_list();
this.fire({
type: "startkeyframerule",
keys: keyList,
line: keyList[0].line,
col: keyList[0].col
});
this._readDeclarations(true);
this.fire({
type: "endkeyframerule",
keys: keyList,
line: keyList[0].line,
col: keyList[0].col
});
},
_key_list: function() {
/*
* key_list:
* : key [ S* ',' S* key]*
* ;
*/
var tokenStream = this._tokenStream,
keyList = [];
//must be least one key
keyList.push(this._key());
this._readWhitespace();
while (tokenStream.match(Tokens.COMMA)) {
this._readWhitespace();
keyList.push(this._key());
this._readWhitespace();
}
return keyList;
},
_key: function() {
/*
* There is a restriction that IDENT can be only "from" or "to".
*
* key
* : PERCENTAGE
* | IDENT
* ;
*/
var tokenStream = this._tokenStream,
token;
if (tokenStream.match(Tokens.PERCENTAGE)) {
return SyntaxUnit.fromToken(tokenStream.token());
} else if (tokenStream.match(Tokens.IDENT)) {
token = tokenStream.token();
if (/from|to/i.test(token.value)) {
return SyntaxUnit.fromToken(token);
}
tokenStream.unget();
}
//if it gets here, there wasn't a valid token, so time to explode
this._unexpectedToken(tokenStream.LT(1));
},
//-----------------------------------------------------------------
// Helper methods
//-----------------------------------------------------------------
/**
* Not part of CSS grammar, but useful for skipping over
* combination of white space and HTML-style comments.
* @return {void}
* @method _skipCruft
* @private
*/
_skipCruft: function() {
while (this._tokenStream.match([Tokens.S, Tokens.CDO, Tokens.CDC])) {
//noop
}
},
/**
* Not part of CSS grammar, but this pattern occurs frequently
* in the official CSS grammar. Split out here to eliminate
* duplicate code.
* @param {Boolean} checkStart Indicates if the rule should check
* for the left brace at the beginning.
* @param {Boolean} readMargins Indicates if the rule should check
* for margin patterns.
* @return {void}
* @method _readDeclarations
* @private
*/
_readDeclarations: function(checkStart, readMargins) {
/*
* Reads the pattern
* S* '{' S* declaration [ ';' S* declaration ]* '}' S*
* or
* S* '{' S* [ declaration | margin ]? [ ';' S* [ declaration | margin ]? ]* '}' S*
* Note that this is how it is described in CSS3 Paged Media, but is actually incorrect.
* A semicolon is only necessary following a declaration if there's another declaration
* or margin afterwards.
*/
var tokenStream = this._tokenStream,
tt;
this._readWhitespace();
if (checkStart) {
tokenStream.mustMatch(Tokens.LBRACE);
}
this._readWhitespace();
try {
while (true) {
if (tokenStream.match(Tokens.SEMICOLON) || (readMargins && this._margin())) {
//noop
} else if (this._declaration()) {
if (!tokenStream.match(Tokens.SEMICOLON)) {
break;
}
} else {
break;
}
//if ((!this._margin() && !this._declaration()) || !tokenStream.match(Tokens.SEMICOLON)){
// break;
//}
this._readWhitespace();
}
tokenStream.mustMatch(Tokens.RBRACE);
this._readWhitespace();
} catch (ex) {
if (ex instanceof SyntaxError && !this.options.strict) {
//fire error event
this.fire({
type: "error",
error: ex,
message: ex.message,
line: ex.line,
col: ex.col
});
//see if there's another declaration
tt = tokenStream.advance([Tokens.SEMICOLON, Tokens.RBRACE]);
if (tt === Tokens.SEMICOLON) {
//if there's a semicolon, then there might be another declaration
this._readDeclarations(false, readMargins);
} else if (tt !== Tokens.RBRACE) {
//if there's a right brace, the rule is finished so don't do anything
//otherwise, rethrow the error because it wasn't handled properly
throw ex;
}
} else {
//not a syntax error, rethrow it
throw ex;
}
}
},
/**
* In some cases, you can end up with two white space tokens in a
* row. Instead of making a change in every function that looks for
* white space, this function is used to match as much white space
* as necessary.
* @method _readWhitespace
* @return {String} The white space if found, empty string if not.
* @private
*/
_readWhitespace: function() {
var tokenStream = this._tokenStream,
ws = "";
while (tokenStream.match(Tokens.S)) {
ws += tokenStream.token().value;
}
return ws;
},
/**
* Throws an error when an unexpected token is found.
* @param {Object} token The token that was found.
* @method _unexpectedToken
* @return {void}
* @private
*/
_unexpectedToken: function(token) {
throw new SyntaxError("Unexpected token '" + token.value + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
},
/**
* Helper method used for parsing subparts of a style sheet.
* @return {void}
* @method _verifyEnd
* @private
*/
_verifyEnd: function() {
if (this._tokenStream.LA(1) !== Tokens.EOF) {
this._unexpectedToken(this._tokenStream.LT(1));
}
},
//-----------------------------------------------------------------
// Validation methods
//-----------------------------------------------------------------
_validateProperty: function(property, value) {
Validation.validate(property, value);
},
//-----------------------------------------------------------------
// Parsing methods
//-----------------------------------------------------------------
parse: function(input) {
this._tokenStream = new TokenStream(input, Tokens);
this._stylesheet();
},
parseStyleSheet: function(input) {
//just passthrough
return this.parse(input);
},
parseMediaQuery: function(input) {
this._tokenStream = new TokenStream(input, Tokens);
var result = this._media_query();
//if there's anything more, then it's an invalid selector
this._verifyEnd();
//otherwise return result
return result;
},
/**
* Parses a property value (everything after the semicolon).
* @return {parserlib.css.PropertyValue} The property value.
* @throws parserlib.util.SyntaxError If an unexpected token is found.
* @method parserPropertyValue
*/
parsePropertyValue: function(input) {
this._tokenStream = new TokenStream(input, Tokens);
this._readWhitespace();
var result = this._expr();
//okay to have a trailing white space
this._readWhitespace();
//if there's anything more, then it's an invalid selector
this._verifyEnd();
//otherwise return result
return result;
},
/**
* Parses a complete CSS rule, including selectors and
* properties.
* @param {String} input The text to parser.
* @return {Boolean} True if the parse completed successfully, false if not.
* @method parseRule
*/
parseRule: function(input) {
this._tokenStream = new TokenStream(input, Tokens);
//skip any leading white space
this._readWhitespace();
var result = this._ruleset();
//skip any trailing white space
this._readWhitespace();
//if there's anything more, then it's an invalid selector
this._verifyEnd();
//otherwise return result
return result;
},
/**
* Parses a single CSS selector (no comma)
* @param {String} input The text to parse as a CSS selector.
* @return {Selector} An object representing the selector.
* @throws parserlib.util.SyntaxError If an unexpected token is found.
* @method parseSelector
*/
parseSelector: function(input) {
this._tokenStream = new TokenStream(input, Tokens);
//skip any leading white space
this._readWhitespace();
var result = this._selector();
//skip any trailing white space
this._readWhitespace();
//if there's anything more, then it's an invalid selector
this._verifyEnd();
//otherwise return result
return result;
},
/**
* Parses an HTML style attribute: a set of CSS declarations
* separated by semicolons.
* @param {String} input The text to parse as a style attribute
* @return {void}
* @method parseStyleAttribute
*/
parseStyleAttribute: function(input) {
input += "}"; // for error recovery in _readDeclarations()
this._tokenStream = new TokenStream(input, Tokens);
this._readDeclarations();
}
};
//copy over onto prototype
for (prop in additions) {
if (Object.prototype.hasOwnProperty.call(additions, prop)) {
proto[prop] = additions[prop];
}
}
return proto;
}();
/*
nth
: S* [ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]? |
['-'|'+']? INTEGER | {O}{D}{D} | {E}{V}{E}{N} ] S*
;
*/
},{"../util/EventTarget":23,"../util/SyntaxError":25,"../util/SyntaxUnit":26,"./Combinator":2,"./MediaFeature":4,"./MediaQuery":5,"./PropertyName":8,"./PropertyValue":9,"./PropertyValuePart":11,"./Selector":13,"./SelectorPart":14,"./SelectorSubPart":15,"./TokenStream":17,"./Tokens":18,"./Validation":19}],7:[function(require,module,exports){
"use strict";
/* exported Properties */
var Properties = module.exports = {
__proto__: null,
//A
"align-items" : "flex-start | flex-end | center | baseline | stretch",
"align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
"align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
"-webkit-align-items" : "flex-start | flex-end | center | baseline | stretch",
"-webkit-align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
"-webkit-align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
"alignment-adjust" : "auto | baseline | before-edge | text-before-edge | middle | central | after-edge | text-after-edge | ideographic | alphabetic | hanging | mathematical | <percentage> | <length>",
"alignment-baseline" : "auto | baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
"animation" : 1,
"animation-delay" : "<time>#",
"animation-direction" : "<single-animation-direction>#",
"animation-duration" : "<time>#",
"animation-fill-mode" : "[ none | forwards | backwards | both ]#",
"animation-iteration-count" : "[ <number> | infinite ]#",
"animation-name" : "[ none | <single-animation-name> ]#",
"animation-play-state" : "[ running | paused ]#",
"animation-timing-function" : 1,
//vendor prefixed
"-moz-animation-delay" : "<time>#",
"-moz-animation-direction" : "[ normal | alternate ]#",
"-moz-animation-duration" : "<time>#",
"-moz-animation-iteration-count" : "[ <number> | infinite ]#",
"-moz-animation-name" : "[ none | <single-animation-name> ]#",
"-moz-animation-play-state" : "[ running | paused ]#",
"-ms-animation-delay" : "<time>#",
"-ms-animation-direction" : "[ normal | alternate ]#",
"-ms-animation-duration" : "<time>#",
"-ms-animation-iteration-count" : "[ <number> | infinite ]#",
"-ms-animation-name" : "[ none | <single-animation-name> ]#",
"-ms-animation-play-state" : "[ running | paused ]#",
"-webkit-animation-delay" : "<time>#",
"-webkit-animation-direction" : "[ normal | alternate ]#",
"-webkit-animation-duration" : "<time>#",
"-webkit-animation-fill-mode" : "[ none | forwards | backwards | both ]#",
"-webkit-animation-iteration-count" : "[ <number> | infinite ]#",
"-webkit-animation-name" : "[ none | <single-animation-name> ]#",
"-webkit-animation-play-state" : "[ running | paused ]#",
"-o-animation-delay" : "<time>#",
"-o-animation-direction" : "[ normal | alternate ]#",
"-o-animation-duration" : "<time>#",
"-o-animation-iteration-count" : "[ <number> | infinite ]#",
"-o-animation-name" : "[ none | <single-animation-name> ]#",
"-o-animation-play-state" : "[ running | paused ]#",
"appearance" : "icon | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | radio | radio-button | checkbox | menu-item | tab | menu | menubar | pull-down-menu | pop-up-menu | list-menu | radio-group | checkbox-group | outline-tree | range | field | combo-box | signature | password | normal | none",
"azimuth" : "<azimuth>",
//B
"backface-visibility" : "visible | hidden",
"background" : 1,
"background-attachment" : "<attachment>#",
"background-clip" : "<box>#",
"background-color" : "<color>",
"background-image" : "<bg-image>#",
"background-origin" : "<box>#",
"background-position" : "<bg-position>",
"background-repeat" : "<repeat-style>#",
"background-size" : "<bg-size>#",
"baseline-shift" : "baseline | sub | super | <percentage> | <length>",
"behavior" : 1,
"binding" : 1,
"bleed" : "<length>",
"bookmark-label" : "<content> | <attr> | <string>",
"bookmark-level" : "none | <integer>",
"bookmark-state" : "open | closed",
"bookmark-target" : "none | <uri> | <attr>",
"border" : "<border-width> || <border-style> || <color>",
"border-bottom" : "<border-width> || <border-style> || <color>",
"border-bottom-color" : "<color>",
"border-bottom-left-radius" : "<x-one-radius>",
"border-bottom-right-radius" : "<x-one-radius>",
"border-bottom-style" : "<border-style>",
"border-bottom-width" : "<border-width>",
"border-collapse" : "collapse | separate",
"border-color" : "<color>{1,4}",
"border-image" : 1,
"border-image-outset" : "[ <length> | <number> ]{1,4}",
"border-image-repeat" : "[ stretch | repeat | round ]{1,2}",
"border-image-slice" : "<border-image-slice>",
"border-image-source" : "<image> | none",
"border-image-width" : "[ <length> | <percentage> | <number> | auto ]{1,4}",
"border-left" : "<border-width> || <border-style> || <color>",
"border-left-color" : "<color>",
"border-left-style" : "<border-style>",
"border-left-width" : "<border-width>",
"border-radius" : "<border-radius>",
"border-right" : "<border-width> || <border-style> || <color>",
"border-right-color" : "<color>",
"border-right-style" : "<border-style>",
"border-right-width" : "<border-width>",
"border-spacing" : "<length>{1,2}",
"border-style" : "<border-style>{1,4}",
"border-top" : "<border-width> || <border-style> || <color>",
"border-top-color" : "<color>",
"border-top-left-radius" : "<x-one-radius>",
"border-top-right-radius" : "<x-one-radius>",
"border-top-style" : "<border-style>",
"border-top-width" : "<border-width>",
"border-width" : "<border-width>{1,4}",
"bottom" : "<margin-width>",
"-moz-box-align" : "start | end | center | baseline | stretch",
"-moz-box-decoration-break" : "slice | clone",
"-moz-box-direction" : "normal | reverse",
"-moz-box-flex" : "<number>",
"-moz-box-flex-group" : "<integer>",
"-moz-box-lines" : "single | multiple",
"-moz-box-ordinal-group" : "<integer>",
"-moz-box-orient" : "horizontal | vertical | inline-axis | block-axis",
"-moz-box-pack" : "start | end | center | justify",
"-o-box-decoration-break" : "slice | clone",
"-webkit-box-align" : "start | end | center | baseline | stretch",
"-webkit-box-decoration-break" : "slice | clone",
"-webkit-box-direction" : "normal | reverse",
"-webkit-box-flex" : "<number>",
"-webkit-box-flex-group" : "<integer>",
"-webkit-box-lines" : "single | multiple",
"-webkit-box-ordinal-group" : "<integer>",
"-webkit-box-orient" : "horizontal | vertical | inline-axis | block-axis",
"-webkit-box-pack" : "start | end | center | justify",
"box-decoration-break" : "slice | clone",
"box-shadow" : "<box-shadow>",
"box-sizing" : "content-box | border-box",
"break-after" : "auto | always | avoid | left | right | page | column | avoid-page | avoid-column",
"break-before" : "auto | always | avoid | left | right | page | column | avoid-page | avoid-column",
"break-inside" : "auto | avoid | avoid-page | avoid-column",
//C
"caption-side" : "top | bottom",
"clear" : "none | right | left | both",
"clip" : "<shape> | auto",
"-webkit-clip-path" : "<clip-source> | <clip-path> | none",
"clip-path" : "<clip-source> | <clip-path> | none",
"clip-rule" : "nonzero | evenodd",
"color" : "<color>",
"color-interpolation" : "auto | sRGB | linearRGB",
"color-interpolation-filters" : "auto | sRGB | linearRGB",
"color-profile" : 1,
"color-rendering" : "auto | optimizeSpeed | optimizeQuality",
"column-count" : "<integer> | auto", //https://www.w3.org/TR/css3-multicol/
"column-fill" : "auto | balance",
"column-gap" : "<length> | normal",
"column-rule" : "<border-width> || <border-style> || <color>",
"column-rule-color" : "<color>",
"column-rule-style" : "<border-style>",
"column-rule-width" : "<border-width>",
"column-span" : "none | all",
"column-width" : "<length> | auto",
"columns" : 1,
"content" : 1,
"counter-increment" : 1,
"counter-reset" : 1,
"crop" : "<shape> | auto",
"cue" : "cue-after | cue-before",
"cue-after" : 1,
"cue-before" : 1,
"cursor" : 1,
//D
"direction" : "ltr | rtl",
"display" : "inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | grid | inline-grid | run-in | ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container | contents | none | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box | -ms-flexbox | -ms-inline-flexbox | flex | -webkit-flex | inline-flex | -webkit-inline-flex",
"dominant-baseline" : "auto | use-script | no-change | reset-size | ideographic | alphabetic | hanging | mathematical | central | middle | text-after-edge | text-before-edge",
"drop-initial-after-adjust" : "central | middle | after-edge | text-after-edge | ideographic | alphabetic | mathematical | <percentage> | <length>",
"drop-initial-after-align" : "baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
"drop-initial-before-adjust" : "before-edge | text-before-edge | central | middle | hanging | mathematical | <percentage> | <length>",
"drop-initial-before-align" : "caps-height | baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
"drop-initial-size" : "auto | line | <length> | <percentage>",
"drop-initial-value" : "<integer>",
//E
"elevation" : "<angle> | below | level | above | higher | lower",
"empty-cells" : "show | hide",
"enable-background" : 1,
//F
"fill" : "<paint>",
"fill-opacity" : "<opacity-value>",
"fill-rule" : "nonzero | evenodd",
"filter" : "<filter-function-list> | none",
"fit" : "fill | hidden | meet | slice",
"fit-position" : 1,
"flex" : "<flex>",
"flex-basis" : "<width>",
"flex-direction" : "row | row-reverse | column | column-reverse",
"flex-flow" : "<flex-direction> || <flex-wrap>",
"flex-grow" : "<number>",
"flex-shrink" : "<number>",
"flex-wrap" : "nowrap | wrap | wrap-reverse",
"-webkit-flex" : "<flex>",
"-webkit-flex-basis" : "<width>",
"-webkit-flex-direction" : "row | row-reverse | column | column-reverse",
"-webkit-flex-flow" : "<flex-direction> || <flex-wrap>",
"-webkit-flex-grow" : "<number>",
"-webkit-flex-shrink" : "<number>",
"-webkit-flex-wrap" : "nowrap | wrap | wrap-reverse",
"-ms-flex" : "<flex>",
"-ms-flex-align" : "start | end | center | stretch | baseline",
"-ms-flex-direction" : "row | row-reverse | column | column-reverse",
"-ms-flex-order" : "<number>",
"-ms-flex-pack" : "start | end | center | justify",
"-ms-flex-wrap" : "nowrap | wrap | wrap-reverse",
"float" : "left | right | none",
"float-offset" : 1,
"flood-color" : 1,
"flood-opacity" : "<opacity-value>",
"font" : "<font-shorthand> | caption | icon | menu | message-box | small-caption | status-bar",
"font-family" : "<font-family>",
"font-feature-settings" : "<feature-tag-value> | normal",
"font-kerning" : "auto | normal | none",
"font-size" : "<font-size>",
"font-size-adjust" : "<number> | none",
"font-stretch" : "<font-stretch>",
"font-style" : "<font-style>",
"font-variant" : "<font-variant> | normal | none",
"font-variant-alternates" : "<font-variant-alternates> | normal",
"font-variant-caps" : "<font-variant-caps> | normal",
"font-variant-east-asian" : "<font-variant-east-asian> | normal",
"font-variant-ligatures" : "<font-variant-ligatures> | normal | none",
"font-variant-numeric" : "<font-variant-numeric> | normal",
"font-variant-position" : "normal | sub | super",
"font-weight" : "<font-weight>",
//G
"glyph-orientation-horizontal" : "<glyph-angle>",
"glyph-orientation-vertical" : "auto | <glyph-angle>",
"grid" : 1,
"grid-area" : 1,
"grid-auto-columns" : 1,
"grid-auto-flow" : 1,
"grid-auto-position" : 1,
"grid-auto-rows" : 1,
"grid-cell-stacking" : "columns | rows | layer",
"grid-column" : 1,
"grid-columns" : 1,
"grid-column-align" : "start | end | center | stretch",
"grid-column-sizing" : 1,
"grid-column-start" : 1,
"grid-column-end" : 1,
"grid-column-span" : "<integer>",
"grid-flow" : "none | rows | columns",
"grid-layer" : "<integer>",
"grid-row" : 1,
"grid-rows" : 1,
"grid-row-align" : "start | end | center | stretch",
"grid-row-start" : 1,
"grid-row-end" : 1,
"grid-row-span" : "<integer>",
"grid-row-sizing" : 1,
"grid-template" : 1,
"grid-template-areas" : 1,
"grid-template-columns" : 1,
"grid-template-rows" : 1,
//H
"hanging-punctuation" : 1,
"height" : "<margin-width> | <content-sizing>",
"hyphenate-after" : "<integer> | auto",
"hyphenate-before" : "<integer> | auto",
"hyphenate-character" : "<string> | auto",
"hyphenate-lines" : "no-limit | <integer>",
"hyphenate-resource" : 1,
"hyphens" : "none | manual | auto",
//I
"icon" : 1,
"image-orientation" : "angle | auto",
"image-rendering" : "auto | optimizeSpeed | optimizeQuality",
"image-resolution" : 1,
"ime-mode" : "auto | normal | active | inactive | disabled",
"inline-box-align" : "last | <integer>",
//J
"justify-content" : "flex-start | flex-end | center | space-between | space-around",
"-webkit-justify-content" : "flex-start | flex-end | center | space-between | space-around",
//K
"kerning" : "auto | <length>",
//L
"left" : "<margin-width>",
"letter-spacing" : "<length> | normal",
"line-height" : "<line-height>",
"line-break" : "auto | loose | normal | strict",
"line-stacking" : 1,
"line-stacking-ruby" : "exclude-ruby | include-ruby",
"line-stacking-shift" : "consider-shifts | disregard-shifts",
"line-stacking-strategy" : "inline-line-height | block-line-height | max-height | grid-height",
"list-style" : 1,
"list-style-image" : "<uri> | none",
"list-style-position" : "inside | outside",
"list-style-type" : "disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | lower-alpha | upper-alpha | none",
//M
"margin" : "<margin-width>{1,4}",
"margin-bottom" : "<margin-width>",
"margin-left" : "<margin-width>",
"margin-right" : "<margin-width>",
"margin-top" : "<margin-width>",
"mark" : 1,
"mark-after" : 1,
"mark-before" : 1,
"marker" : 1,
"marker-end" : 1,
"marker-mid" : 1,
"marker-start" : 1,
"marks" : 1,
"marquee-direction" : 1,
"marquee-play-count" : 1,
"marquee-speed" : 1,
"marquee-style" : 1,
"mask" : 1,
"max-height" : "<length> | <percentage> | <content-sizing> | none",
"max-width" : "<length> | <percentage> | <content-sizing> | none",
"min-height" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats",
"min-width" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats",
"move-to" : 1,
//N
"nav-down" : 1,
"nav-index" : 1,
"nav-left" : 1,
"nav-right" : 1,
"nav-up" : 1,
//O
"object-fit" : "fill | contain | cover | none | scale-down",
"object-position" : "<position>",
"opacity" : "<opacity-value>",
"order" : "<integer>",
"-webkit-order" : "<integer>",
"orphans" : "<integer>",
"outline" : 1,
"outline-color" : "<color> | invert",
"outline-offset" : 1,
"outline-style" : "<border-style>",
"outline-width" : "<border-width>",
"overflow" : "visible | hidden | scroll | auto",
"overflow-style" : 1,
"overflow-wrap" : "normal | break-word",
"overflow-x" : 1,
"overflow-y" : 1,
//P
"padding" : "<padding-width>{1,4}",
"padding-bottom" : "<padding-width>",
"padding-left" : "<padding-width>",
"padding-right" : "<padding-width>",
"padding-top" : "<padding-width>",
"page" : 1,
"page-break-after" : "auto | always | avoid | left | right",
"page-break-before" : "auto | always | avoid | left | right",
"page-break-inside" : "auto | avoid",
"page-policy" : 1,
"pause" : 1,
"pause-after" : 1,
"pause-before" : 1,
"perspective" : 1,
"perspective-origin" : 1,
"phonemes" : 1,
"pitch" : 1,
"pitch-range" : 1,
"play-during" : 1,
"pointer-events" : "auto | none | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all",
"position" : "static | relative | absolute | fixed",
"presentation-level" : 1,
"punctuation-trim" : 1,
//Q
"quotes" : 1,
//R
"rendering-intent" : 1,
"resize" : 1,
"rest" : 1,
"rest-after" : 1,
"rest-before" : 1,
"richness" : 1,
"right" : "<margin-width>",
"rotation" : 1,
"rotation-point" : 1,
"ruby-align" : 1,
"ruby-overhang" : 1,
"ruby-position" : 1,
"ruby-span" : 1,
//S
"shape-rendering" : "auto | optimizeSpeed | crispEdges | geometricPrecision",
"size" : 1,
"speak" : "normal | none | spell-out",
"speak-header" : "once | always",
"speak-numeral" : "digits | continuous",
"speak-punctuation" : "code | none",
"speech-rate" : 1,
"src" : 1,
"stop-color" : 1,
"stop-opacity" : "<opacity-value>",
"stress" : 1,
"string-set" : 1,
"stroke" : "<paint>",
"stroke-dasharray" : "none | <dasharray>",
"stroke-dashoffset" : "<percentage> | <length>",
"stroke-linecap" : "butt | round | square",
"stroke-linejoin" : "miter | round | bevel",
"stroke-miterlimit" : "<miterlimit>",
"stroke-opacity" : "<opacity-value>",
"stroke-width" : "<percentage> | <length>",
"table-layout" : "auto | fixed",
"tab-size" : "<integer> | <length>",
"target" : 1,
"target-name" : 1,
"target-new" : 1,
"target-position" : 1,
"text-align" : "left | right | center | justify | match-parent | start | end",
"text-align-last" : 1,
"text-anchor" : "start | middle | end",
"text-decoration" : "<text-decoration>",
"text-emphasis" : 1,
"text-height" : 1,
"text-indent" : "<length> | <percentage>",
"text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
"text-outline" : 1,
"text-overflow" : 1,
"text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision",
"text-shadow" : 1,
"text-transform" : "capitalize | uppercase | lowercase | none",
"text-wrap" : "normal | none | avoid",
"top" : "<margin-width>",
"-ms-touch-action" : "auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation",
"touch-action" : "auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation",
"transform" : 1,
"transform-origin" : 1,
"transform-style" : 1,
"transition" : 1,
"transition-delay" : 1,
"transition-duration" : 1,
"transition-property" : 1,
"transition-timing-function" : 1,
//U
"unicode-bidi" : "normal | embed | isolate | bidi-override | isolate-override | plaintext",
"user-modify" : "read-only | read-write | write-only",
"user-select" : "none | text | toggle | element | elements | all",
//V
"vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",
"visibility" : "visible | hidden | collapse",
"voice-balance" : 1,
"voice-duration" : 1,
"voice-family" : 1,
"voice-pitch" : 1,
"voice-pitch-range" : 1,
"voice-rate" : 1,
"voice-stress" : 1,
"voice-volume" : 1,
"volume" : 1,
//W
"white-space" : "normal | pre | nowrap | pre-wrap | pre-line | -pre-wrap | -o-pre-wrap | -moz-pre-wrap | -hp-pre-wrap", // https://perishablepress.com/wrapping-content/
"white-space-collapse" : 1,
"widows" : "<integer>",
"width" : "<length> | <percentage> | <content-sizing> | auto",
"will-change" : "<will-change>",
"word-break" : "normal | keep-all | break-all",
"word-spacing" : "<length> | normal",
"word-wrap" : "normal | break-word",
"writing-mode" : "horizontal-tb | vertical-rl | vertical-lr | lr-tb | rl-tb | tb-rl | bt-rl | tb-lr | bt-lr | lr-bt | rl-bt | lr | rl | tb",
//Z
"z-index" : "<integer> | auto",
"zoom" : "<number> | <percentage> | normal"
};
},{}],8:[function(require,module,exports){
"use strict";
module.exports = PropertyName;
var SyntaxUnit = require("../util/SyntaxUnit");
var Parser = require("./Parser");
/**
* Represents a selector combinator (whitespace, +, >).
* @namespace parserlib.css
* @class PropertyName
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {String} text The text representation of the unit.
* @param {String} hack The type of IE hack applied ("*", "_", or null).
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function PropertyName(text, hack, line, col) {
SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_NAME_TYPE);
/**
* The type of IE hack applied ("*", "_", or null).
* @type String
* @property hack
*/
this.hack = hack;
}
PropertyName.prototype = new SyntaxUnit();
PropertyName.prototype.constructor = PropertyName;
PropertyName.prototype.toString = function() {
return (this.hack ? this.hack : "") + this.text;
};
},{"../util/SyntaxUnit":26,"./Parser":6}],9:[function(require,module,exports){
"use strict";
module.exports = PropertyValue;
var SyntaxUnit = require("../util/SyntaxUnit");
var Parser = require("./Parser");
/**
* Represents a single part of a CSS property value, meaning that it represents
* just everything single part between ":" and ";". If there are multiple values
* separated by commas, this type represents just one of the values.
* @param {String[]} parts An array of value parts making up this value.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
* @namespace parserlib.css
* @class PropertyValue
* @extends parserlib.util.SyntaxUnit
* @constructor
*/
function PropertyValue(parts, line, col) {
SyntaxUnit.call(this, parts.join(" "), line, col, Parser.PROPERTY_VALUE_TYPE);
/**
* The parts that make up the selector.
* @type Array
* @property parts
*/
this.parts = parts;
}
PropertyValue.prototype = new SyntaxUnit();
PropertyValue.prototype.constructor = PropertyValue;
},{"../util/SyntaxUnit":26,"./Parser":6}],10:[function(require,module,exports){
"use strict";
module.exports = PropertyValueIterator;
/**
* A utility class that allows for easy iteration over the various parts of a
* property value.
* @param {parserlib.css.PropertyValue} value The property value to iterate over.
* @namespace parserlib.css
* @class PropertyValueIterator
* @constructor
*/
function PropertyValueIterator(value) {
/**
* Iterator value
* @type int
* @property _i
* @private
*/
this._i = 0;
/**
* The parts that make up the value.
* @type Array
* @property _parts
* @private
*/
this._parts = value.parts;
/**
* Keeps track of bookmarks along the way.
* @type Array
* @property _marks
* @private
*/
this._marks = [];
/**
* Holds the original property value.
* @type parserlib.css.PropertyValue
* @property value
*/
this.value = value;
}
/**
* Returns the total number of parts in the value.
* @return {int} The total number of parts in the value.
* @method count
*/
PropertyValueIterator.prototype.count = function() {
return this._parts.length;
};
/**
* Indicates if the iterator is positioned at the first item.
* @return {Boolean} True if positioned at first item, false if not.
* @method isFirst
*/
PropertyValueIterator.prototype.isFirst = function() {
return this._i === 0;
};
/**
* Indicates if there are more parts of the property value.
* @return {Boolean} True if there are more parts, false if not.
* @method hasNext
*/
PropertyValueIterator.prototype.hasNext = function() {
return this._i < this._parts.length;
};
/**
* Marks the current spot in the iteration so it can be restored to
* later on.
* @return {void}
* @method mark
*/
PropertyValueIterator.prototype.mark = function() {
this._marks.push(this._i);
};
/**
* Returns the next part of the property value or null if there is no next
* part. Does not move the internal counter forward.
* @return {parserlib.css.PropertyValuePart} The next part of the property value or null if there is no next
* part.
* @method peek
*/
PropertyValueIterator.prototype.peek = function(count) {
return this.hasNext() ? this._parts[this._i + (count || 0)] : null;
};
/**
* Returns the next part of the property value or null if there is no next
* part.
* @return {parserlib.css.PropertyValuePart} The next part of the property value or null if there is no next
* part.
* @method next
*/
PropertyValueIterator.prototype.next = function() {
return this.hasNext() ? this._parts[this._i++] : null;
};
/**
* Returns the previous part of the property value or null if there is no
* previous part.
* @return {parserlib.css.PropertyValuePart} The previous part of the
* property value or null if there is no previous part.
* @method previous
*/
PropertyValueIterator.prototype.previous = function() {
return this._i > 0 ? this._parts[--this._i] : null;
};
/**
* Restores the last saved bookmark.
* @return {void}
* @method restore
*/
PropertyValueIterator.prototype.restore = function() {
if (this._marks.length) {
this._i = this._marks.pop();
}
};
/**
* Drops the last saved bookmark.
* @return {void}
* @method drop
*/
PropertyValueIterator.prototype.drop = function() {
this._marks.pop();
};
},{}],11:[function(require,module,exports){
"use strict";
module.exports = PropertyValuePart;
var SyntaxUnit = require("../util/SyntaxUnit");
var Colors = require("./Colors");
var Parser = require("./Parser");
var Tokens = require("./Tokens");
/**
* Represents a single part of a CSS property value, meaning that it represents
* just one part of the data between ":" and ";".
* @param {String} text The text representation of the unit.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
* @namespace parserlib.css
* @class PropertyValuePart
* @extends parserlib.util.SyntaxUnit
* @constructor
*/
function PropertyValuePart(text, line, col, optionalHint) {
var hint = optionalHint || {};
SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_VALUE_PART_TYPE);
/**
* Indicates the type of value unit.
* @type String
* @property type
*/
this.type = "unknown";
//figure out what type of data it is
var temp;
//it is a measurement?
if (/^([+\-]?[\d\.]+)([a-z]+)$/i.test(text)) { //dimension
this.type = "dimension";
this.value = +RegExp.$1;
this.units = RegExp.$2;
//try to narrow down
switch (this.units.toLowerCase()) {
case "em":
case "rem":
case "ex":
case "px":
case "cm":
case "mm":
case "in":
case "pt":
case "pc":
case "ch":
case "vh":
case "vw":
case "vmax":
case "vmin":
this.type = "length";
break;
case "fr":
this.type = "grid";
break;
case "deg":
case "rad":
case "grad":
this.type = "angle";
break;
case "ms":
case "s":
this.type = "time";
break;
case "hz":
case "khz":
this.type = "frequency";
break;
case "dpi":
case "dpcm":
this.type = "resolution";
break;
//default
}
} else if (/^([+\-]?[\d\.]+)%$/i.test(text)) { //percentage
this.type = "percentage";
this.value = +RegExp.$1;
} else if (/^([+\-]?\d+)$/i.test(text)) { //integer
this.type = "integer";
this.value = +RegExp.$1;
} else if (/^([+\-]?[\d\.]+)$/i.test(text)) { //number
this.type = "number";
this.value = +RegExp.$1;
} else if (/^#([a-f0-9]{3,6})/i.test(text)) { //hexcolor
this.type = "color";
temp = RegExp.$1;
if (temp.length === 3) {
this.red = parseInt(temp.charAt(0)+temp.charAt(0), 16);
this.green = parseInt(temp.charAt(1)+temp.charAt(1), 16);
this.blue = parseInt(temp.charAt(2)+temp.charAt(2), 16);
} else {
this.red = parseInt(temp.substring(0, 2), 16);
this.green = parseInt(temp.substring(2, 4), 16);
this.blue = parseInt(temp.substring(4, 6), 16);
}
} else if (/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i.test(text)) { //rgb() color with absolute numbers
this.type = "color";
this.red = +RegExp.$1;
this.green = +RegExp.$2;
this.blue = +RegExp.$3;
} else if (/^rgb\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)) { //rgb() color with percentages
this.type = "color";
this.red = +RegExp.$1 * 255 / 100;
this.green = +RegExp.$2 * 255 / 100;
this.blue = +RegExp.$3 * 255 / 100;
} else if (/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d\.]+)\s*\)/i.test(text)) { //rgba() color with absolute numbers
this.type = "color";
this.red = +RegExp.$1;
this.green = +RegExp.$2;
this.blue = +RegExp.$3;
this.alpha = +RegExp.$4;
} else if (/^rgba\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)) { //rgba() color with percentages
this.type = "color";
this.red = +RegExp.$1 * 255 / 100;
this.green = +RegExp.$2 * 255 / 100;
this.blue = +RegExp.$3 * 255 / 100;
this.alpha = +RegExp.$4;
} else if (/^hsl\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)) { //hsl()
this.type = "color";
this.hue = +RegExp.$1;
this.saturation = +RegExp.$2 / 100;
this.lightness = +RegExp.$3 / 100;
} else if (/^hsla\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)) { //hsla() color with percentages
this.type = "color";
this.hue = +RegExp.$1;
this.saturation = +RegExp.$2 / 100;
this.lightness = +RegExp.$3 / 100;
this.alpha = +RegExp.$4;
} else if (/^url\(("([^\\"]|\\.)*")\)/i.test(text)) { //URI
// generated by TokenStream.readURI, so always double-quoted.
this.type = "uri";
this.uri = PropertyValuePart.parseString(RegExp.$1);
} else if (/^([^\(]+)\(/i.test(text)) {
this.type = "function";
this.name = RegExp.$1;
this.value = text;
} else if (/^"([^\n\r\f\\"]|\\\r\n|\\[^\r0-9a-f]|\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?)*"/i.test(text)) { //double-quoted string
this.type = "string";
this.value = PropertyValuePart.parseString(text);
} else if (/^'([^\n\r\f\\']|\\\r\n|\\[^\r0-9a-f]|\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?)*'/i.test(text)) { //single-quoted string
this.type = "string";
this.value = PropertyValuePart.parseString(text);
} else if (Colors[text.toLowerCase()]) { //named color
this.type = "color";
temp = Colors[text.toLowerCase()].substring(1);
this.red = parseInt(temp.substring(0, 2), 16);
this.green = parseInt(temp.substring(2, 4), 16);
this.blue = parseInt(temp.substring(4, 6), 16);
} else if (/^[,\/]$/.test(text)) {
this.type = "operator";
this.value = text;
} else if (/^-?[a-z_\u00A0-\uFFFF][a-z0-9\-_\u00A0-\uFFFF]*$/i.test(text)) {
this.type = "identifier";
this.value = text;
}
// There can be ambiguity with escape sequences in identifiers, as
// well as with "color" parts which are also "identifiers", so record
// an explicit hint when the token generating this PropertyValuePart
// was an identifier.
this.wasIdent = Boolean(hint.ident);
}
PropertyValuePart.prototype = new SyntaxUnit();
PropertyValuePart.prototype.constructor = PropertyValuePart;
/**
* Helper method to parse a CSS string.
*/
PropertyValuePart.parseString = function(str) {
str = str.slice(1, -1); // Strip surrounding single/double quotes
var replacer = function(match, esc) {
if (/^(\n|\r\n|\r|\f)$/.test(esc)) {
return "";
}
var m = /^[0-9a-f]{1,6}/i.exec(esc);
if (m) {
var codePoint = parseInt(m[0], 16);
if (String.fromCodePoint) {
return String.fromCodePoint(codePoint);
} else {
// XXX No support for surrogates on old JavaScript engines.
return String.fromCharCode(codePoint);
}
}
return esc;
};
return str.replace(/\\(\r\n|[^\r0-9a-f]|[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?)/ig,
replacer);
};
/**
* Helper method to serialize a CSS string.
*/
PropertyValuePart.serializeString = function(value) {
var replacer = function(match, c) {
if (c === "\"") {
return "\\" + c;
}
var cp = String.codePointAt ? String.codePointAt(0) :
// We only escape non-surrogate chars, so using charCodeAt
// is harmless here.
String.charCodeAt(0);
return "\\" + cp.toString(16) + " ";
};
return "\"" + value.replace(/["\r\n\f]/g, replacer) + "\"";
};
/**
* Create a new syntax unit based solely on the given token.
* Convenience method for creating a new syntax unit when
* it represents a single token instead of multiple.
* @param {Object} token The token object to represent.
* @return {parserlib.css.PropertyValuePart} The object representing the token.
* @static
* @method fromToken
*/
PropertyValuePart.fromToken = function(token) {
var part = new PropertyValuePart(token.value, token.startLine, token.startCol, {
// Tokens can have escaped characters that would fool the type
// identification in the PropertyValuePart constructor, so pass
// in a hint if this was an identifier.
ident: token.type === Tokens.IDENT
});
return part;
};
},{"../util/SyntaxUnit":26,"./Colors":1,"./Parser":6,"./Tokens":18}],12:[function(require,module,exports){
"use strict";
var Pseudos = module.exports = {
__proto__: null,
":first-letter": 1,
":first-line": 1,
":before": 1,
":after": 1
};
Pseudos.ELEMENT = 1;
Pseudos.CLASS = 2;
Pseudos.isElement = function(pseudo) {
return pseudo.indexOf("::") === 0 || Pseudos[pseudo.toLowerCase()] === Pseudos.ELEMENT;
};
},{}],13:[function(require,module,exports){
"use strict";
module.exports = Selector;
var SyntaxUnit = require("../util/SyntaxUnit");
var Parser = require("./Parser");
var Specificity = require("./Specificity");
/**
* Represents an entire single selector, including all parts but not
* including multiple selectors (those separated by commas).
* @namespace parserlib.css
* @class Selector
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {Array} parts Array of selectors parts making up this selector.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function Selector(parts, line, col) {
SyntaxUnit.call(this, parts.join(" "), line, col, Parser.SELECTOR_TYPE);
/**
* The parts that make up the selector.
* @type Array
* @property parts
*/
this.parts = parts;
/**
* The specificity of the selector.
* @type parserlib.css.Specificity
* @property specificity
*/
this.specificity = Specificity.calculate(this);
}
Selector.prototype = new SyntaxUnit();
Selector.prototype.constructor = Selector;
},{"../util/SyntaxUnit":26,"./Parser":6,"./Specificity":16}],14:[function(require,module,exports){
"use strict";
module.exports = SelectorPart;
var SyntaxUnit = require("../util/SyntaxUnit");
var Parser = require("./Parser");
/**
* Represents a single part of a selector string, meaning a single set of
* element name and modifiers. This does not include combinators such as
* spaces, +, >, etc.
* @namespace parserlib.css
* @class SelectorPart
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {String} elementName The element name in the selector or null
* if there is no element name.
* @param {Array} modifiers Array of individual modifiers for the element.
* May be empty if there are none.
* @param {String} text The text representation of the unit.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function SelectorPart(elementName, modifiers, text, line, col) {
SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_PART_TYPE);
/**
* The tag name of the element to which this part
* of the selector affects.
* @type String
* @property elementName
*/
this.elementName = elementName;
/**
* The parts that come after the element name, such as class names, IDs,
* pseudo classes/elements, etc.
* @type Array
* @property modifiers
*/
this.modifiers = modifiers;
}
SelectorPart.prototype = new SyntaxUnit();
SelectorPart.prototype.constructor = SelectorPart;
},{"../util/SyntaxUnit":26,"./Parser":6}],15:[function(require,module,exports){
"use strict";
module.exports = SelectorSubPart;
var SyntaxUnit = require("../util/SyntaxUnit");
var Parser = require("./Parser");
/**
* Represents a selector modifier string, meaning a class name, element name,
* element ID, pseudo rule, etc.
* @namespace parserlib.css
* @class SelectorSubPart
* @extends parserlib.util.SyntaxUnit
* @constructor
* @param {String} text The text representation of the unit.
* @param {String} type The type of selector modifier.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function SelectorSubPart(text, type, line, col) {
SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_SUB_PART_TYPE);
/**
* The type of modifier.
* @type String
* @property type
*/
this.type = type;
/**
* Some subparts have arguments, this represents them.
* @type Array
* @property args
*/
this.args = [];
}
SelectorSubPart.prototype = new SyntaxUnit();
SelectorSubPart.prototype.constructor = SelectorSubPart;
},{"../util/SyntaxUnit":26,"./Parser":6}],16:[function(require,module,exports){
"use strict";
module.exports = Specificity;
var Pseudos = require("./Pseudos");
var SelectorPart = require("./SelectorPart");
/**
* Represents a selector's specificity.
* @namespace parserlib.css
* @class Specificity
* @constructor
* @param {int} a Should be 1 for inline styles, zero for stylesheet styles
* @param {int} b Number of ID selectors
* @param {int} c Number of classes and pseudo classes
* @param {int} d Number of element names and pseudo elements
*/
function Specificity(a, b, c, d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
Specificity.prototype = {
constructor: Specificity,
/**
* Compare this specificity to another.
* @param {Specificity} other The other specificity to compare to.
* @return {int} -1 if the other specificity is larger, 1 if smaller, 0 if equal.
* @method compare
*/
compare: function(other) {
var comps = ["a", "b", "c", "d"],
i, len;
for (i=0, len=comps.length; i < len; i++) {
if (this[comps[i]] < other[comps[i]]) {
return -1;
} else if (this[comps[i]] > other[comps[i]]) {
return 1;
}
}
return 0;
},
/**
* Creates a numeric value for the specificity.
* @return {int} The numeric value for the specificity.
* @method valueOf
*/
valueOf: function() {
return (this.a * 1000) + (this.b * 100) + (this.c * 10) + this.d;
},
/**
* Returns a string representation for specificity.
* @return {String} The string representation of specificity.
* @method toString
*/
toString: function() {
return this.a + "," + this.b + "," + this.c + "," + this.d;
}
};
/**
* Calculates the specificity of the given selector.
* @param {parserlib.css.Selector} The selector to calculate specificity for.
* @return {parserlib.css.Specificity} The specificity of the selector.
* @static
* @method calculate
*/
Specificity.calculate = function(selector) {
var i, len,
part,
b=0, c=0, d=0;
function updateValues(part) {
var i, j, len, num,
elementName = part.elementName ? part.elementName.text : "",
modifier;
if (elementName && elementName.charAt(elementName.length-1) !== "*") {
d++;
}
for (i=0, len=part.modifiers.length; i < len; i++) {
modifier = part.modifiers[i];
switch (modifier.type) {
case "class":
case "attribute":
c++;
break;
case "id":
b++;
break;
case "pseudo":
if (Pseudos.isElement(modifier.text)) {
d++;
} else {
c++;
}
break;
case "not":
for (j=0, num=modifier.args.length; j < num; j++) {
updateValues(modifier.args[j]);
}
}
}
}
for (i=0, len=selector.parts.length; i < len; i++) {
part = selector.parts[i];
if (part instanceof SelectorPart) {
updateValues(part);
}
}
return new Specificity(0, b, c, d);
};
},{"./Pseudos":12,"./SelectorPart":14}],17:[function(require,module,exports){
"use strict";
module.exports = TokenStream;
var TokenStreamBase = require("../util/TokenStreamBase");
var PropertyValuePart = require("./PropertyValuePart");
var Tokens = require("./Tokens");
var h = /^[0-9a-fA-F]$/,
nonascii = /^[\u00A0-\uFFFF]$/,
nl = /\n|\r\n|\r|\f/,
whitespace = /\u0009|\u000a|\u000c|\u000d|\u0020/;
//-----------------------------------------------------------------------------
// Helper functions
//-----------------------------------------------------------------------------
function isHexDigit(c) {
return c !== null && h.test(c);
}
function isDigit(c) {
return c !== null && /\d/.test(c);
}
function isWhitespace(c) {
return c !== null && whitespace.test(c);
}
function isNewLine(c) {
return c !== null && nl.test(c);
}
function isNameStart(c) {
return c !== null && /[a-z_\u00A0-\uFFFF\\]/i.test(c);
}
function isNameChar(c) {
return c !== null && (isNameStart(c) || /[0-9\-\\]/.test(c));
}
function isIdentStart(c) {
return c !== null && (isNameStart(c) || /\-\\/.test(c));
}
function mix(receiver, supplier) {
for (var prop in supplier) {
if (Object.prototype.hasOwnProperty.call(supplier, prop)) {
receiver[prop] = supplier[prop];
}
}
return receiver;
}
//-----------------------------------------------------------------------------
// CSS Token Stream
//-----------------------------------------------------------------------------
/**
* A token stream that produces CSS tokens.
* @param {String|Reader} input The source of text to tokenize.
* @constructor
* @class TokenStream
* @namespace parserlib.css
*/
function TokenStream(input) {
TokenStreamBase.call(this, input, Tokens);
}
TokenStream.prototype = mix(new TokenStreamBase(), {
/**
* Overrides the TokenStreamBase method of the same name
* to produce CSS tokens.
* @return {Object} A token object representing the next token.
* @method _getToken
* @private
*/
_getToken: function() {
var c,
reader = this._reader,
token = null,
startLine = reader.getLine(),
startCol = reader.getCol();
c = reader.read();
while (c) {
switch (c) {
/*
* Potential tokens:
* - COMMENT
* - SLASH
* - CHAR
*/
case "/":
if (reader.peek() === "*") {
token = this.commentToken(c, startLine, startCol);
} else {
token = this.charToken(c, startLine, startCol);
}
break;
/*
* Potential tokens:
* - DASHMATCH
* - INCLUDES
* - PREFIXMATCH
* - SUFFIXMATCH
* - SUBSTRINGMATCH
* - CHAR
*/
case "|":
case "~":
case "^":
case "$":
case "*":
if (reader.peek() === "=") {
token = this.comparisonToken(c, startLine, startCol);
} else {
token = this.charToken(c, startLine, startCol);
}
break;
/*
* Potential tokens:
* - STRING
* - INVALID
*/
case "\"":
case "'":
token = this.stringToken(c, startLine, startCol);
break;
/*
* Potential tokens:
* - HASH
* - CHAR
*/
case "#":
if (isNameChar(reader.peek())) {
token = this.hashToken(c, startLine, startCol);
} else {
token = this.charToken(c, startLine, startCol);
}
break;
/*
* Potential tokens:
* - DOT
* - NUMBER
* - DIMENSION
* - PERCENTAGE
*/
case ".":
if (isDigit(reader.peek())) {
token = this.numberToken(c, startLine, startCol);
} else {
token = this.charToken(c, startLine, startCol);
}
break;
/*
* Potential tokens:
* - CDC
* - MINUS
* - NUMBER
* - DIMENSION
* - PERCENTAGE
*/
case "-":
if (reader.peek() === "-") { //could be closing HTML-style comment
token = this.htmlCommentEndToken(c, startLine, startCol);
} else if (isNameStart(reader.peek())) {
token = this.identOrFunctionToken(c, startLine, startCol);
} else {
token = this.charToken(c, startLine, startCol);
}
break;
/*
* Potential tokens:
* - IMPORTANT_SYM
* - CHAR
*/
case "!":
token = this.importantToken(c, startLine, startCol);
break;
/*
* Any at-keyword or CHAR
*/
case "@":
token = this.atRuleToken(c, startLine, startCol);
break;
/*
* Potential tokens:
* - NOT
* - CHAR
*/
case ":":
token = this.notToken(c, startLine, startCol);
break;
/*
* Potential tokens:
* - CDO
* - CHAR
*/
case "<":
token = this.htmlCommentStartToken(c, startLine, startCol);
break;
/*
* Potential tokens:
* - IDENT
* - CHAR
*/
case "\\":
if (/[^\r\n\f]/.test(reader.peek())) {
token = this.identOrFunctionToken(this.readEscape(c, true), startLine, startCol);
} else {
token = this.charToken(c, startLine, startCol);
}
break;
/*
* Potential tokens:
* - UNICODE_RANGE
* - URL
* - CHAR
*/
case "U":
case "u":
if (reader.peek() === "+") {
token = this.unicodeRangeToken(c, startLine, startCol);
break;
}
/* falls through */
default:
/*
* Potential tokens:
* - NUMBER
* - DIMENSION
* - LENGTH
* - FREQ
* - TIME
* - EMS
* - EXS
* - ANGLE
*/
if (isDigit(c)) {
token = this.numberToken(c, startLine, startCol);
} else
/*
* Potential tokens:
* - S
*/
if (isWhitespace(c)) {
token = this.whitespaceToken(c, startLine, startCol);
} else
/*
* Potential tokens:
* - IDENT
*/
if (isIdentStart(c)) {
token = this.identOrFunctionToken(c, startLine, startCol);
} else {
/*
* Potential tokens:
* - CHAR
* - PLUS
*/
token = this.charToken(c, startLine, startCol);
}
}
//make sure this token is wanted
//TODO: check channel
break;
}
if (!token && c === null) {
token = this.createToken(Tokens.EOF, null, startLine, startCol);
}
return token;
},
//-------------------------------------------------------------------------
// Methods to create tokens
//-------------------------------------------------------------------------
/**
* Produces a token based on available data and the current
* reader position information. This method is called by other
* private methods to create tokens and is never called directly.
* @param {int} tt The token type.
* @param {String} value The text value of the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @param {Object} options (Optional) Specifies a channel property
* to indicate that a different channel should be scanned
* and/or a hide property indicating that the token should
* be hidden.
* @return {Object} A token object.
* @method createToken
*/
createToken: function(tt, value, startLine, startCol, options) {
var reader = this._reader;
options = options || {};
return {
value: value,
type: tt,
channel: options.channel,
endChar: options.endChar,
hide: options.hide || false,
startLine: startLine,
startCol: startCol,
endLine: reader.getLine(),
endCol: reader.getCol()
};
},
//-------------------------------------------------------------------------
// Methods to create specific tokens
//-------------------------------------------------------------------------
/**
* Produces a token for any at-rule. If the at-rule is unknown, then
* the token is for a single "@" character.
* @param {String} first The first character for the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method atRuleToken
*/
atRuleToken: function(first, startLine, startCol) {
var rule = first,
reader = this._reader,
tt = Tokens.CHAR,
ident;
/*
* First, mark where we are. There are only four @ rules,
* so anything else is really just an invalid token.
* Basically, if this doesn't match one of the known @
* rules, just return '@' as an unknown token and allow
* parsing to continue after that point.
*/
reader.mark();
//try to find the at-keyword
ident = this.readName();
rule = first + ident;
tt = Tokens.type(rule.toLowerCase());
//if it's not valid, use the first character only and reset the reader
if (tt === Tokens.CHAR || tt === Tokens.UNKNOWN) {
if (rule.length > 1) {
tt = Tokens.UNKNOWN_SYM;
} else {
tt = Tokens.CHAR;
rule = first;
reader.reset();
}
}
return this.createToken(tt, rule, startLine, startCol);
},
/**
* Produces a character token based on the given character
* and location in the stream. If there's a special (non-standard)
* token name, this is used; otherwise CHAR is used.
* @param {String} c The character for the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method charToken
*/
charToken: function(c, startLine, startCol) {
var tt = Tokens.type(c);
var opts = {};
if (tt === -1) {
tt = Tokens.CHAR;
} else {
opts.endChar = Tokens[tt].endChar;
}
return this.createToken(tt, c, startLine, startCol, opts);
},
/**
* Produces a character token based on the given character
* and location in the stream. If there's a special (non-standard)
* token name, this is used; otherwise CHAR is used.
* @param {String} first The first character for the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method commentToken
*/
commentToken: function(first, startLine, startCol) {
var comment = this.readComment(first);
return this.createToken(Tokens.COMMENT, comment, startLine, startCol);
},
/**
* Produces a comparison token based on the given character
* and location in the stream. The next character must be
* read and is already known to be an equals sign.
* @param {String} c The character for the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method comparisonToken
*/
comparisonToken: function(c, startLine, startCol) {
var reader = this._reader,
comparison = c + reader.read(),
tt = Tokens.type(comparison) || Tokens.CHAR;
return this.createToken(tt, comparison, startLine, startCol);
},
/**
* Produces a hash token based on the specified information. The
* first character provided is the pound sign (#) and then this
* method reads a name afterward.
* @param {String} first The first character (#) in the hash name.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method hashToken
*/
hashToken: function(first, startLine, startCol) {
var name = this.readName(first);
return this.createToken(Tokens.HASH, name, startLine, startCol);
},
/**
* Produces a CDO or CHAR token based on the specified information. The
* first character is provided and the rest is read by the function to determine
* the correct token to create.
* @param {String} first The first character in the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method htmlCommentStartToken
*/
htmlCommentStartToken: function(first, startLine, startCol) {
var reader = this._reader,
text = first;
reader.mark();
text += reader.readCount(3);
if (text === "<!--") {
return this.createToken(Tokens.CDO, text, startLine, startCol);
} else {
reader.reset();
return this.charToken(first, startLine, startCol);
}
},
/**
* Produces a CDC or CHAR token based on the specified information. The
* first character is provided and the rest is read by the function to determine
* the correct token to create.
* @param {String} first The first character in the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method htmlCommentEndToken
*/
htmlCommentEndToken: function(first, startLine, startCol) {
var reader = this._reader,
text = first;
reader.mark();
text += reader.readCount(2);
if (text === "-->") {
return this.createToken(Tokens.CDC, text, startLine, startCol);
} else {
reader.reset();
return this.charToken(first, startLine, startCol);
}
},
/**
* Produces an IDENT or FUNCTION token based on the specified information. The
* first character is provided and the rest is read by the function to determine
* the correct token to create.
* @param {String} first The first character in the identifier.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method identOrFunctionToken
*/
identOrFunctionToken: function(first, startLine, startCol) {
var reader = this._reader,
ident = this.readName(first),
tt = Tokens.IDENT,
uriFns = ["url(", "url-prefix(", "domain("],
uri;
//if there's a left paren immediately after, it's a URI or function
if (reader.peek() === "(") {
ident += reader.read();
if (uriFns.indexOf(ident.toLowerCase()) > -1) {
reader.mark();
uri = this.readURI(ident);
if (uri === null) {
//didn't find a valid URL or there's no closing paren
reader.reset();
tt = Tokens.FUNCTION;
} else {
tt = Tokens.URI;
ident = uri;
}
} else {
tt = Tokens.FUNCTION;
}
} else if (reader.peek() === ":") { //might be an IE function
//IE-specific functions always being with progid:
if (ident.toLowerCase() === "progid") {
ident += reader.readTo("(");
tt = Tokens.IE_FUNCTION;
}
}
return this.createToken(tt, ident, startLine, startCol);
},
/**
* Produces an IMPORTANT_SYM or CHAR token based on the specified information. The
* first character is provided and the rest is read by the function to determine
* the correct token to create.
* @param {String} first The first character in the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method importantToken
*/
importantToken: function(first, startLine, startCol) {
var reader = this._reader,
important = first,
tt = Tokens.CHAR,
temp,
c;
reader.mark();
c = reader.read();
while (c) {
//there can be a comment in here
if (c === "/") {
//if the next character isn't a star, then this isn't a valid !important token
if (reader.peek() !== "*") {
break;
} else {
temp = this.readComment(c);
if (temp === "") { //broken!
break;
}
}
} else if (isWhitespace(c)) {
important += c + this.readWhitespace();
} else if (/i/i.test(c)) {
temp = reader.readCount(8);
if (/mportant/i.test(temp)) {
important += c + temp;
tt = Tokens.IMPORTANT_SYM;
}
break; //we're done
} else {
break;
}
c = reader.read();
}
if (tt === Tokens.CHAR) {
reader.reset();
return this.charToken(first, startLine, startCol);
} else {
return this.createToken(tt, important, startLine, startCol);
}
},
/**
* Produces a NOT or CHAR token based on the specified information. The
* first character is provided and the rest is read by the function to determine
* the correct token to create.
* @param {String} first The first character in the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method notToken
*/
notToken: function(first, startLine, startCol) {
var reader = this._reader,
text = first;
reader.mark();
text += reader.readCount(4);
if (text.toLowerCase() === ":not(") {
return this.createToken(Tokens.NOT, text, startLine, startCol);
} else {
reader.reset();
return this.charToken(first, startLine, startCol);
}
},
/**
* Produces a number token based on the given character
* and location in the stream. This may return a token of
* NUMBER, EMS, EXS, LENGTH, ANGLE, TIME, FREQ, DIMENSION,
* or PERCENTAGE.
* @param {String} first The first character for the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method numberToken
*/
numberToken: function(first, startLine, startCol) {
var reader = this._reader,
value = this.readNumber(first),
ident,
tt = Tokens.NUMBER,
c = reader.peek();
if (isIdentStart(c)) {
ident = this.readName(reader.read());
value += ident;
if (/^em$|^ex$|^px$|^gd$|^rem$|^vw$|^vh$|^vmax$|^vmin$|^ch$|^cm$|^mm$|^in$|^pt$|^pc$/i.test(ident)) {
tt = Tokens.LENGTH;
} else if (/^deg|^rad$|^grad$/i.test(ident)) {
tt = Tokens.ANGLE;
} else if (/^ms$|^s$/i.test(ident)) {
tt = Tokens.TIME;
} else if (/^hz$|^khz$/i.test(ident)) {
tt = Tokens.FREQ;
} else if (/^dpi$|^dpcm$/i.test(ident)) {
tt = Tokens.RESOLUTION;
} else {
tt = Tokens.DIMENSION;
}
} else if (c === "%") {
value += reader.read();
tt = Tokens.PERCENTAGE;
}
return this.createToken(tt, value, startLine, startCol);
},
/**
* Produces a string token based on the given character
* and location in the stream. Since strings may be indicated
* by single or double quotes, a failure to match starting
* and ending quotes results in an INVALID token being generated.
* The first character in the string is passed in and then
* the rest are read up to and including the final quotation mark.
* @param {String} first The first character in the string.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method stringToken
*/
stringToken: function(first, startLine, startCol) {
var delim = first,
string = first,
reader = this._reader,
tt = Tokens.STRING,
c = reader.read(),
i;
while (c) {
string += c;
if (c === "\\") {
c = reader.read();
if (c === null) {
break; // premature EOF after backslash
} else if (/[^\r\n\f0-9a-f]/i.test(c)) {
// single-character escape
string += c;
} else {
// read up to six hex digits
for (i=0; isHexDigit(c) && i<6; i++) {
string += c;
c = reader.read();
}
// swallow trailing newline or space
if (c === "\r" && reader.peek() === "\n") {
string += c;
c = reader.read();
}
if (isWhitespace(c)) {
string += c;
} else {
// This character is null or not part of the escape;
// jump back to the top to process it.
continue;
}
}
} else if (c === delim) {
break; // delimiter found.
} else if (isNewLine(reader.peek())) {
// newline without an escapement: it's an invalid string
tt = Tokens.INVALID;
break;
}
c = reader.read();
}
//if c is null, that means we're out of input and the string was never closed
if (c === null) {
tt = Tokens.INVALID;
}
return this.createToken(tt, string, startLine, startCol);
},
unicodeRangeToken: function(first, startLine, startCol) {
var reader = this._reader,
value = first,
temp,
tt = Tokens.CHAR;
//then it should be a unicode range
if (reader.peek() === "+") {
reader.mark();
value += reader.read();
value += this.readUnicodeRangePart(true);
//ensure there's an actual unicode range here
if (value.length === 2) {
reader.reset();
} else {
tt = Tokens.UNICODE_RANGE;
//if there's a ? in the first part, there can't be a second part
if (value.indexOf("?") === -1) {
if (reader.peek() === "-") {
reader.mark();
temp = reader.read();
temp += this.readUnicodeRangePart(false);
//if there's not another value, back up and just take the first
if (temp.length === 1) {
reader.reset();
} else {
value += temp;
}
}
}
}
}
return this.createToken(tt, value, startLine, startCol);
},
/**
* Produces a S token based on the specified information. Since whitespace
* may have multiple characters, this consumes all whitespace characters
* into a single token.
* @param {String} first The first character in the token.
* @param {int} startLine The beginning line for the character.
* @param {int} startCol The beginning column for the character.
* @return {Object} A token object.
* @method whitespaceToken
*/
whitespaceToken: function(first, startLine, startCol) {
var value = first + this.readWhitespace();
return this.createToken(Tokens.S, value, startLine, startCol);
},
//-------------------------------------------------------------------------
// Methods to read values from the string stream
//-------------------------------------------------------------------------
readUnicodeRangePart: function(allowQuestionMark) {
var reader = this._reader,
part = "",
c = reader.peek();
//first read hex digits
while (isHexDigit(c) && part.length < 6) {
reader.read();
part += c;
c = reader.peek();
}
//then read question marks if allowed
if (allowQuestionMark) {
while (c === "?" && part.length < 6) {
reader.read();
part += c;
c = reader.peek();
}
}
//there can't be any other characters after this point
return part;
},
readWhitespace: function() {
var reader = this._reader,
whitespace = "",
c = reader.peek();
while (isWhitespace(c)) {
reader.read();
whitespace += c;
c = reader.peek();
}
return whitespace;
},
readNumber: function(first) {
var reader = this._reader,
number = first,
hasDot = (first === "."),
c = reader.peek();
while (c) {
if (isDigit(c)) {
number += reader.read();
} else if (c === ".") {
if (hasDot) {
break;
} else {
hasDot = true;
number += reader.read();
}
} else {
break;
}
c = reader.peek();
}
return number;
},
// returns null w/o resetting reader if string is invalid.
readString: function() {
var token = this.stringToken(this._reader.read(), 0, 0);
return token.type === Tokens.INVALID ? null : token.value;
},
// returns null w/o resetting reader if URI is invalid.
readURI: function(first) {
var reader = this._reader,
uri = first,
inner = "",
c = reader.peek();
//skip whitespace before
while (c && isWhitespace(c)) {
reader.read();
c = reader.peek();
}
//it's a string
if (c === "'" || c === "\"") {
inner = this.readString();
if (inner !== null) {
inner = PropertyValuePart.parseString(inner);
}
} else {
inner = this.readUnquotedURL();
}
c = reader.peek();
//skip whitespace after
while (c && isWhitespace(c)) {
reader.read();
c = reader.peek();
}
//if there was no inner value or the next character isn't closing paren, it's not a URI
if (inner === null || c !== ")") {
uri = null;
} else {
// Ensure argument to URL is always double-quoted
// (This simplifies later processing in PropertyValuePart.)
uri += PropertyValuePart.serializeString(inner) + reader.read();
}
return uri;
},
// This method never fails, although it may return an empty string.
readUnquotedURL: function(first) {
var reader = this._reader,
url = first || "",
c;
for (c = reader.peek(); c; c = reader.peek()) {
// Note that the grammar at
// https://www.w3.org/TR/CSS2/grammar.html#scanner
// incorrectly includes the backslash character in the
// `url` production, although it is correctly omitted in
// the `baduri1` production.
if (nonascii.test(c) || /^[\-!#$%&*-\[\]-~]$/.test(c)) {
url += c;
reader.read();
} else if (c === "\\") {
if (/^[^\r\n\f]$/.test(reader.peek(2))) {
url += this.readEscape(reader.read(), true);
} else {
break; // bad escape sequence.
}
} else {
break; // bad character
}
}
return url;
},
readName: function(first) {
var reader = this._reader,
ident = first || "",
c;
for (c = reader.peek(); c; c = reader.peek()) {
if (c === "\\") {
if (/^[^\r\n\f]$/.test(reader.peek(2))) {
ident += this.readEscape(reader.read(), true);
} else {
// Bad escape sequence.
break;
}
} else if (isNameChar(c)) {
ident += reader.read();
} else {
break;
}
}
return ident;
},
readEscape: function(first, unescape) {
var reader = this._reader,
cssEscape = first || "",
i = 0,
c = reader.peek();
if (isHexDigit(c)) {
do {
cssEscape += reader.read();
c = reader.peek();
} while (c && isHexDigit(c) && ++i < 6);
}
if (cssEscape.length === 1) {
if (/^[^\r\n\f0-9a-f]$/.test(c)) {
reader.read();
if (unescape) {
return c;
}
} else {
// We should never get here (readName won't call readEscape
// if the escape sequence is bad).
throw new Error("Bad escape sequence.");
}
} else if (c === "\r") {
reader.read();
if (reader.peek() === "\n") {
c += reader.read();
}
} else if (/^[ \t\n\f]$/.test(c)) {
reader.read();
} else {
c = "";
}
if (unescape) {
var cp = parseInt(cssEscape.slice(first.length), 16);
return String.fromCodePoint ? String.fromCodePoint(cp) :
String.fromCharCode(cp);
}
return cssEscape + c;
},
readComment: function(first) {
var reader = this._reader,
comment = first || "",
c = reader.read();
if (c === "*") {
while (c) {
comment += c;
//look for end of comment
if (comment.length > 2 && c === "*" && reader.peek() === "/") {
comment += reader.read();
break;
}
c = reader.read();
}
return comment;
} else {
return "";
}
}
});
},{"../util/TokenStreamBase":27,"./PropertyValuePart":11,"./Tokens":18}],18:[function(require,module,exports){
"use strict";
var Tokens = module.exports = [
/*
* The following token names are defined in CSS3 Grammar: https://www.w3.org/TR/css3-syntax/#lexical
*/
// HTML-style comments
{ name: "CDO" },
{ name: "CDC" },
// ignorables
{ name: "S", whitespace: true/*, channel: "ws"*/ },
{ name: "COMMENT", comment: true, hide: true, channel: "comment" },
// attribute equality
{ name: "INCLUDES", text: "~=" },
{ name: "DASHMATCH", text: "|=" },
{ name: "PREFIXMATCH", text: "^=" },
{ name: "SUFFIXMATCH", text: "$=" },
{ name: "SUBSTRINGMATCH", text: "*=" },
// identifier types
{ name: "STRING" },
{ name: "IDENT" },
{ name: "HASH" },
// at-keywords
{ name: "IMPORT_SYM", text: "@import" },
{ name: "PAGE_SYM", text: "@page" },
{ name: "MEDIA_SYM", text: "@media" },
{ name: "FONT_FACE_SYM", text: "@font-face" },
{ name: "CHARSET_SYM", text: "@charset" },
{ name: "NAMESPACE_SYM", text: "@namespace" },
{ name: "SUPPORTS_SYM", text: "@supports" },
{ name: "VIEWPORT_SYM", text: ["@viewport", "@-ms-viewport", "@-o-viewport"] },
{ name: "DOCUMENT_SYM", text: ["@document", "@-moz-document"] },
{ name: "UNKNOWN_SYM" },
//{ name: "ATKEYWORD"},
// CSS3 animations
{ name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
// important symbol
{ name: "IMPORTANT_SYM" },
// measurements
{ name: "LENGTH" },
{ name: "ANGLE" },
{ name: "TIME" },
{ name: "FREQ" },
{ name: "DIMENSION" },
{ name: "PERCENTAGE" },
{ name: "NUMBER" },
// functions
{ name: "URI" },
{ name: "FUNCTION" },
// Unicode ranges
{ name: "UNICODE_RANGE" },
/*
* The following token names are defined in CSS3 Selectors: https://www.w3.org/TR/css3-selectors/#selector-syntax
*/
// invalid string
{ name: "INVALID" },
// combinators
{ name: "PLUS", text: "+" },
{ name: "GREATER", text: ">" },
{ name: "COMMA", text: "," },
{ name: "TILDE", text: "~" },
// modifier
{ name: "NOT" },
/*
* Defined in CSS3 Paged Media
*/
{ name: "TOPLEFTCORNER_SYM", text: "@top-left-corner" },
{ name: "TOPLEFT_SYM", text: "@top-left" },
{ name: "TOPCENTER_SYM", text: "@top-center" },
{ name: "TOPRIGHT_SYM", text: "@top-right" },
{ name: "TOPRIGHTCORNER_SYM", text: "@top-right-corner" },
{ name: "BOTTOMLEFTCORNER_SYM", text: "@bottom-left-corner" },
{ name: "BOTTOMLEFT_SYM", text: "@bottom-left" },
{ name: "BOTTOMCENTER_SYM", text: "@bottom-center" },
{ name: "BOTTOMRIGHT_SYM", text: "@bottom-right" },
{ name: "BOTTOMRIGHTCORNER_SYM", text: "@bottom-right-corner" },
{ name: "LEFTTOP_SYM", text: "@left-top" },
{ name: "LEFTMIDDLE_SYM", text: "@left-middle" },
{ name: "LEFTBOTTOM_SYM", text: "@left-bottom" },
{ name: "RIGHTTOP_SYM", text: "@right-top" },
{ name: "RIGHTMIDDLE_SYM", text: "@right-middle" },
{ name: "RIGHTBOTTOM_SYM", text: "@right-bottom" },
/*
* The following token names are defined in CSS3 Media Queries: https://www.w3.org/TR/css3-mediaqueries/#syntax
*/
/*{ name: "MEDIA_ONLY", state: "media"},
{ name: "MEDIA_NOT", state: "media"},
{ name: "MEDIA_AND", state: "media"},*/
{ name: "RESOLUTION", state: "media" },
/*
* The following token names are not defined in any CSS specification but are used by the lexer.
*/
// not a real token, but useful for stupid IE filters
{ name: "IE_FUNCTION" },
// part of CSS3 grammar but not the Flex code
{ name: "CHAR" },
// TODO: Needed?
// Not defined as tokens, but might as well be
{
name: "PIPE",
text: "|"
},
{
name: "SLASH",
text: "/"
},
{
name: "MINUS",
text: "-"
},
{
name: "STAR",
text: "*"
},
{
name: "LBRACE",
endChar: "}",
text: "{"
},
{
name: "RBRACE",
text: "}"
},
{
name: "LBRACKET",
endChar: "]",
text: "["
},
{
name: "RBRACKET",
text: "]"
},
{
name: "EQUALS",
text: "="
},
{
name: "COLON",
text: ":"
},
{
name: "SEMICOLON",
text: ";"
},
{
name: "LPAREN",
endChar: ")",
text: "("
},
{
name: "RPAREN",
text: ")"
},
{
name: "DOT",
text: "."
}
];
(function() {
var nameMap = [],
typeMap = Object.create(null);
Tokens.UNKNOWN = -1;
Tokens.unshift({ name:"EOF" });
for (var i=0, len = Tokens.length; i < len; i++) {
nameMap.push(Tokens[i].name);
Tokens[Tokens[i].name] = i;
if (Tokens[i].text) {
if (Tokens[i].text instanceof Array) {
for (var j=0; j < Tokens[i].text.length; j++) {
typeMap[Tokens[i].text[j]] = i;
}
} else {
typeMap[Tokens[i].text] = i;
}
}
}
Tokens.name = function(tt) {
return nameMap[tt];
};
Tokens.type = function(c) {
return typeMap[c] || -1;
};
})();
},{}],19:[function(require,module,exports){
"use strict";
/* exported Validation */
var Matcher = require("./Matcher");
var Properties = require("./Properties");
var ValidationTypes = require("./ValidationTypes");
var ValidationError = require("./ValidationError");
var PropertyValueIterator = require("./PropertyValueIterator");
var Validation = module.exports = {
validate: function(property, value) {
//normalize name
var name = property.toString().toLowerCase(),
expression = new PropertyValueIterator(value),
spec = Properties[name],
part;
if (!spec) {
if (name.indexOf("-") !== 0) { //vendor prefixed are ok
throw new ValidationError("Unknown property '" + property + "'.", property.line, property.col);
}
} else if (typeof spec !== "number") {
// All properties accept some CSS-wide values.
// https://drafts.csswg.org/css-values-3/#common-keywords
if (ValidationTypes.isAny(expression, "inherit | initial | unset")) {
if (expression.hasNext()) {
part = expression.next();
throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
}
return;
}
// Property-specific validation.
this.singleProperty(spec, expression);
}
},
singleProperty: function(types, expression) {
var result = false,
value = expression.value,
part;
result = Matcher.parse(types).match(expression);
if (!result) {
if (expression.hasNext() && !expression.isFirst()) {
part = expression.peek();
throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
} else {
throw new ValidationError("Expected (" + ValidationTypes.describe(types) + ") but found '" + value + "'.", value.line, value.col);
}
} else if (expression.hasNext()) {
part = expression.next();
throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
}
}
};
},{"./Matcher":3,"./Properties":7,"./PropertyValueIterator":10,"./ValidationError":20,"./ValidationTypes":21}],20:[function(require,module,exports){
"use strict";
module.exports = ValidationError;
/**
* Type to use when a validation error occurs.
* @class ValidationError
* @namespace parserlib.util
* @constructor
* @param {String} message The error message.
* @param {int} line The line at which the error occurred.
* @param {int} col The column at which the error occurred.
*/
function ValidationError(message, line, col) {
/**
* The column at which the error occurred.
* @type int
* @property col
*/
this.col = col;
/**
* The line at which the error occurred.
* @type int
* @property line
*/
this.line = line;
/**
* The text representation of the unit.
* @type String
* @property text
*/
this.message = message;
}
//inherit from Error
ValidationError.prototype = new Error();
},{}],21:[function(require,module,exports){
"use strict";
var ValidationTypes = module.exports;
var Matcher = require("./Matcher");
function copy(to, from) {
Object.keys(from).forEach(function(prop) {
to[prop] = from[prop];
});
}
copy(ValidationTypes, {
isLiteral: function (part, literals) {
var text = part.text.toString().toLowerCase(),
args = literals.split(" | "),
i, len, found = false;
for (i=0, len=args.length; i < len && !found; i++) {
if (args[i].charAt(0) === "<") {
found = this.simple[args[i]](part);
} else if (args[i].slice(-2) === "()") {
found = (part.type === "function" &&
part.name === args[i].slice(0, -2));
} else if (text === args[i].toLowerCase()) {
found = true;
}
}
return found;
},
isSimple: function(type) {
return Boolean(this.simple[type]);
},
isComplex: function(type) {
return Boolean(this.complex[type]);
},
describe: function(type) {
if (this.complex[type] instanceof Matcher) {
return this.complex[type].toString(0);
}
return type;
},
/**
* Determines if the next part(s) of the given expression
* are any of the given types.
*/
isAny: function (expression, types) {
var args = types.split(" | "),
i, len, found = false;
for (i=0, len=args.length; i < len && !found && expression.hasNext(); i++) {
found = this.isType(expression, args[i]);
}
return found;
},
/**
* Determines if the next part(s) of the given expression
* are one of a group.
*/
isAnyOfGroup: function(expression, types) {
var args = types.split(" || "),
i, len, found = false;
for (i=0, len=args.length; i < len && !found; i++) {
found = this.isType(expression, args[i]);
}
return found ? args[i-1] : false;
},
/**
* Determines if the next part(s) of the given expression
* are of a given type.
*/
isType: function (expression, type) {
var part = expression.peek(),
result = false;
if (type.charAt(0) !== "<") {
result = this.isLiteral(part, type);
if (result) {
expression.next();
}
} else if (this.simple[type]) {
result = this.simple[type](part);
if (result) {
expression.next();
}
} else if (this.complex[type] instanceof Matcher) {
result = this.complex[type].match(expression);
} else {
result = this.complex[type](expression);
}
return result;
},
simple: {
__proto__: null,
"<absolute-size>":
"xx-small | x-small | small | medium | large | x-large | xx-large",
"<animateable-feature>":
"scroll-position | contents | <animateable-feature-name>",
"<animateable-feature-name>": function(part) {
return this["<ident>"](part) &&
!/^(unset|initial|inherit|will-change|auto|scroll-position|contents)$/i.test(part);
},
"<angle>": function(part) {
return part.type === "angle";
},
"<attachment>": "scroll | fixed | local",
"<attr>": "attr()",
// inset() = inset( <shape-arg>{1,4} [round <border-radius>]? )
// circle() = circle( [<shape-radius>]? [at <position>]? )
// ellipse() = ellipse( [<shape-radius>{2}]? [at <position>]? )
// polygon() = polygon( [<fill-rule>,]? [<shape-arg> <shape-arg>]# )
"<basic-shape>": "inset() | circle() | ellipse() | polygon()",
"<bg-image>": "<image> | <gradient> | none",
"<border-style>":
"none | hidden | dotted | dashed | solid | double | groove | " +
"ridge | inset | outset",
"<border-width>": "<length> | thin | medium | thick",
"<box>": "padding-box | border-box | content-box",
"<clip-source>": "<uri>",
"<color>": function(part) {
return part.type === "color" || String(part) === "transparent" || String(part) === "currentColor";
},
// The SVG <color> spec doesn't include "currentColor" or "transparent" as a color.
"<color-svg>": function(part) {
return part.type === "color";
},
"<content>": "content()",
// https://www.w3.org/TR/css3-sizing/#width-height-keywords
"<content-sizing>":
"fill-available | -moz-available | -webkit-fill-available | " +
"max-content | -moz-max-content | -webkit-max-content | " +
"min-content | -moz-min-content | -webkit-min-content | " +
"fit-content | -moz-fit-content | -webkit-fit-content",
"<feature-tag-value>": function(part) {
return part.type === "function" && /^[A-Z0-9]{4}$/i.test(part);
},
// custom() isn't actually in the spec
"<filter-function>":
"blur() | brightness() | contrast() | custom() | " +
"drop-shadow() | grayscale() | hue-rotate() | invert() | " +
"opacity() | saturate() | sepia()",
"<flex-basis>": "<width>",
"<flex-direction>": "row | row-reverse | column | column-reverse",
"<flex-grow>": "<number>",
"<flex-shrink>": "<number>",
"<flex-wrap>": "nowrap | wrap | wrap-reverse",
"<font-size>":
"<absolute-size> | <relative-size> | <length> | <percentage>",
"<font-stretch>":
"normal | ultra-condensed | extra-condensed | condensed | " +
"semi-condensed | semi-expanded | expanded | extra-expanded | " +
"ultra-expanded",
"<font-style>": "normal | italic | oblique",
"<font-variant-caps>":
"small-caps | all-small-caps | petite-caps | all-petite-caps | " +
"unicase | titling-caps",
"<font-variant-css21>": "normal | small-caps",
"<font-weight>":
"normal | bold | bolder | lighter | " +
"100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900",
"<generic-family>":
"serif | sans-serif | cursive | fantasy | monospace",
"<geometry-box>": "<shape-box> | fill-box | stroke-box | view-box",
"<glyph-angle>": function(part) {
return part.type === "angle" && part.units === "deg";
},
"<gradient>": function(part) {
return part.type === "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
},
"<icccolor>":
"cielab() | cielch() | cielchab() | " +
"icc-color() | icc-named-color()",
//any identifier
"<ident>": function(part) {
return part.type === "identifier" || part.wasIdent;
},
"<ident-not-generic-family>": function(part) {
return this["<ident>"](part) && !this["<generic-family>"](part);
},
"<image>": "<uri>",
"<integer>": function(part) {
return part.type === "integer";
},
"<length>": function(part) {
if (part.type === "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)) {
return true;
} else {
return part.type === "length" || part.type === "number" || part.type === "integer" || String(part) === "0";
}
},
"<line>": function(part) {
return part.type === "integer";
},
"<line-height>": "<number> | <length> | <percentage> | normal",
"<margin-width>": "<length> | <percentage> | auto",
"<miterlimit>": function(part) {
return this["<number>"](part) && part.value >= 1;
},
"<nonnegative-length-or-percentage>": function(part) {
return (this["<length>"](part) || this["<percentage>"](part)) &&
(String(part) === "0" || part.type === "function" || (part.value) >= 0);
},
"<nonnegative-number-or-percentage>": function(part) {
return (this["<number>"](part) || this["<percentage>"](part)) &&
(String(part) === "0" || part.type === "function" || (part.value) >= 0);
},
"<number>": function(part) {
return part.type === "number" || this["<integer>"](part);
},
"<opacity-value>": function(part) {
return this["<number>"](part) && part.value >= 0 && part.value <= 1;
},
"<padding-width>": "<nonnegative-length-or-percentage>",
"<percentage>": function(part) {
return part.type === "percentage" || String(part) === "0";
},
"<relative-size>": "smaller | larger",
"<shape>": "rect() | inset-rect()",
"<shape-box>": "<box> | margin-box",
"<single-animation-direction>":
"normal | reverse | alternate | alternate-reverse",
"<single-animation-name>": function(part) {
return this["<ident>"](part) &&
/^-?[a-z_][-a-z0-9_]+$/i.test(part) &&
!/^(none|unset|initial|inherit)$/i.test(part);
},
"<string>": function(part) {
return part.type === "string";
},
"<time>": function(part) {
return part.type === "time";
},
"<uri>": function(part) {
return part.type === "uri";
},
"<width>": "<margin-width>"
},
complex: {
__proto__: null,
"<azimuth>":
"<angle>" +
" | " +
"[ [ left-side | far-left | left | center-left | center | " +
"center-right | right | far-right | right-side ] || behind ]" +
" | "+
"leftwards | rightwards",
"<bg-position>": "<position>#",
"<bg-size>":
"[ <length> | <percentage> | auto ]{1,2} | cover | contain",
"<border-image-slice>":
// [<number> | <percentage>]{1,4} && fill?
// *but* fill can appear between any of the numbers
Matcher.many([true /* first element is required */],
Matcher.cast("<nonnegative-number-or-percentage>"),
Matcher.cast("<nonnegative-number-or-percentage>"),
Matcher.cast("<nonnegative-number-or-percentage>"),
Matcher.cast("<nonnegative-number-or-percentage>"),
"fill"),
"<border-radius>":
"<nonnegative-length-or-percentage>{1,4} " +
"[ / <nonnegative-length-or-percentage>{1,4} ]?",
"<box-shadow>": "none | <shadow>#",
"<clip-path>": "<basic-shape> || <geometry-box>",
"<dasharray>":
// "list of comma and/or white space separated <length>s and
// <percentage>s". There is a non-negative constraint.
Matcher.cast("<nonnegative-length-or-percentage>")
.braces(1, Infinity, "#", Matcher.cast(",").question()),
"<family-name>":
// <string> | <IDENT>+
"<string> | <ident-not-generic-family> <ident>*",
"<filter-function-list>": "[ <filter-function> | <uri> ]+",
// https://www.w3.org/TR/2014/WD-css-flexbox-1-20140325/#flex-property
"<flex>":
"none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]",
"<font-family>": "[ <generic-family> | <family-name> ]#",
"<font-shorthand>":
"[ <font-style> || <font-variant-css21> || " +
"<font-weight> || <font-stretch> ]? <font-size> " +
"[ / <line-height> ]? <font-family>",
"<font-variant-alternates>":
// stylistic(<feature-value-name>)
"stylistic() || " +
"historical-forms || " +
// styleset(<feature-value-name> #)
"styleset() || " +
// character-variant(<feature-value-name> #)
"character-variant() || " +
// swash(<feature-value-name>)
"swash() || " +
// ornaments(<feature-value-name>)
"ornaments() || " +
// annotation(<feature-value-name>)
"annotation()",
"<font-variant-ligatures>":
// <common-lig-values>
"[ common-ligatures | no-common-ligatures ] || " +
// <discretionary-lig-values>
"[ discretionary-ligatures | no-discretionary-ligatures ] || " +
// <historical-lig-values>
"[ historical-ligatures | no-historical-ligatures ] || " +
// <contextual-alt-values>
"[ contextual | no-contextual ]",
"<font-variant-numeric>":
// <numeric-figure-values>
"[ lining-nums | oldstyle-nums ] || " +
// <numeric-spacing-values>
"[ proportional-nums | tabular-nums ] || " +
// <numeric-fraction-values>
"[ diagonal-fractions | stacked-fractions ] || " +
"ordinal || slashed-zero",
"<font-variant-east-asian>":
// <east-asian-variant-values>
"[ jis78 | jis83 | jis90 | jis04 | simplified | traditional ] || " +
// <east-asian-width-values>
"[ full-width | proportional-width ] || " +
"ruby",
// Note that <color> here is "as defined in the SVG spec", which
// is more restrictive that the <color> defined in the CSS spec.
// none | currentColor | <color> [<icccolor>]? |
// <funciri> [ none | currentColor | <color> [<icccolor>]? ]?
"<paint>": "<paint-basic> | <uri> <paint-basic>?",
// Helper definition for <paint> above.
"<paint-basic>": "none | currentColor | <color-svg> <icccolor>?",
"<position>":
// Because our `alt` combinator is ordered, we need to test these
// in order from longest possible match to shortest.
"[ center | [ left | right ] [ <percentage> | <length> ]? ] && " +
"[ center | [ top | bottom ] [ <percentage> | <length> ]? ]" +
" | " +
"[ left | center | right | <percentage> | <length> ] " +
"[ top | center | bottom | <percentage> | <length> ]" +
" | " +
"[ left | center | right | top | bottom | <percentage> | <length> ]",
"<repeat-style>":
"repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}",
"<shadow>":
//inset? && [ <length>{2,4} && <color>? ]
Matcher.many([true /* length is required */],
Matcher.cast("<length>").braces(2, 4), "inset", "<color>"),
"<text-decoration>":
"none | [ underline || overline || line-through || blink ]",
"<will-change>":
"auto | <animateable-feature>#",
"<x-one-radius>":
//[ <length> | <percentage> ] [ <length> | <percentage> ]?
"[ <length> | <percentage> ]{1,2}"
}
});
Object.keys(ValidationTypes.simple).forEach(function(nt) {
var rule = ValidationTypes.simple[nt];
if (typeof rule === "string") {
ValidationTypes.simple[nt] = function(part) {
return ValidationTypes.isLiteral(part, rule);
};
}
});
Object.keys(ValidationTypes.complex).forEach(function(nt) {
var rule = ValidationTypes.complex[nt];
if (typeof rule === "string") {
ValidationTypes.complex[nt] = Matcher.parse(rule);
}
});
// Because this is defined relative to other complex validation types,
// we need to define it *after* the rest of the types are initialized.
ValidationTypes.complex["<font-variant>"] =
Matcher.oror({ expand: "<font-variant-ligatures>" },
{ expand: "<font-variant-alternates>" },
"<font-variant-caps>",
{ expand: "<font-variant-numeric>" },
{ expand: "<font-variant-east-asian>" });
},{"./Matcher":3}],22:[function(require,module,exports){
"use strict";
module.exports = {
Colors : require("./Colors"),
Combinator : require("./Combinator"),
Parser : require("./Parser"),
PropertyName : require("./PropertyName"),
PropertyValue : require("./PropertyValue"),
PropertyValuePart : require("./PropertyValuePart"),
Matcher : require("./Matcher"),
MediaFeature : require("./MediaFeature"),
MediaQuery : require("./MediaQuery"),
Selector : require("./Selector"),
SelectorPart : require("./SelectorPart"),
SelectorSubPart : require("./SelectorSubPart"),
Specificity : require("./Specificity"),
TokenStream : require("./TokenStream"),
Tokens : require("./Tokens"),
ValidationError : require("./ValidationError")
};
},{"./Colors":1,"./Combinator":2,"./Matcher":3,"./MediaFeature":4,"./MediaQuery":5,"./Parser":6,"./PropertyName":8,"./PropertyValue":9,"./PropertyValuePart":11,"./Selector":13,"./SelectorPart":14,"./SelectorSubPart":15,"./Specificity":16,"./TokenStream":17,"./Tokens":18,"./ValidationError":20}],23:[function(require,module,exports){
"use strict";
module.exports = EventTarget;
/**
* A generic base to inherit from for any object
* that needs event handling.
* @class EventTarget
* @constructor
*/
function EventTarget() {
/**
* The array of listeners for various events.
* @type Object
* @property _listeners
* @private
*/
this._listeners = Object.create(null);
}
EventTarget.prototype = {
//restore constructor
constructor: EventTarget,
/**
* Adds a listener for a given event type.
* @param {String} type The type of event to add a listener for.
* @param {Function} listener The function to call when the event occurs.
* @return {void}
* @method addListener
*/
addListener: function(type, listener) {
if (!this._listeners[type]) {
this._listeners[type] = [];
}
this._listeners[type].push(listener);
},
/**
* Fires an event based on the passed-in object.
* @param {Object|String} event An object with at least a 'type' attribute
* or a string indicating the event name.
* @return {void}
* @method fire
*/
fire: function(event) {
if (typeof event === "string") {
event = { type: event };
}
if (typeof event.target !== "undefined") {
event.target = this;
}
if (typeof event.type === "undefined") {
throw new Error("Event object missing 'type' property.");
}
if (this._listeners[event.type]) {
//create a copy of the array and use that so listeners can't chane
var listeners = this._listeners[event.type].concat();
for (var i=0, len=listeners.length; i < len; i++) {
listeners[i].call(this, event);
}
}
},
/**
* Removes a listener for a given event type.
* @param {String} type The type of event to remove a listener from.
* @param {Function} listener The function to remove from the event.
* @return {void}
* @method removeListener
*/
removeListener: function(type, listener) {
if (this._listeners[type]) {
var listeners = this._listeners[type];
for (var i=0, len=listeners.length; i < len; i++) {
if (listeners[i] === listener) {
listeners.splice(i, 1);
break;
}
}
}
}
};
},{}],24:[function(require,module,exports){
"use strict";
module.exports = StringReader;
/**
* Convenient way to read through strings.
* @namespace parserlib.util
* @class StringReader
* @constructor
* @param {String} text The text to read.
*/
function StringReader(text) {
/**
* The input text with line endings normalized.
* @property _input
* @type String
* @private
*/
this._input = text.replace(/(\r\n?|\n)/g, "\n");
/**
* The row for the character to be read next.
* @property _line
* @type int
* @private
*/
this._line = 1;
/**
* The column for the character to be read next.
* @property _col
* @type int
* @private
*/
this._col = 1;
/**
* The index of the character in the input to be read next.
* @property _cursor
* @type int
* @private
*/
this._cursor = 0;
}
StringReader.prototype = {
// restore constructor
constructor: StringReader,
//-------------------------------------------------------------------------
// Position info
//-------------------------------------------------------------------------
/**
* Returns the column of the character to be read next.
* @return {int} The column of the character to be read next.
* @method getCol
*/
getCol: function() {
return this._col;
},
/**
* Returns the row of the character to be read next.
* @return {int} The row of the character to be read next.
* @method getLine
*/
getLine: function() {
return this._line;
},
/**
* Determines if you're at the end of the input.
* @return {Boolean} True if there's no more input, false otherwise.
* @method eof
*/
eof: function() {
return this._cursor === this._input.length;
},
//-------------------------------------------------------------------------
// Basic reading
//-------------------------------------------------------------------------
/**
* Reads the next character without advancing the cursor.
* @param {int} count How many characters to look ahead (default is 1).
* @return {String} The next character or null if there is no next character.
* @method peek
*/
peek: function(count) {
var c = null;
count = typeof count === "undefined" ? 1 : count;
// if we're not at the end of the input...
if (this._cursor < this._input.length) {
// get character and increment cursor and column
c = this._input.charAt(this._cursor + count - 1);
}
return c;
},
/**
* Reads the next character from the input and adjusts the row and column
* accordingly.
* @return {String} The next character or null if there is no next character.
* @method read
*/
read: function() {
var c = null;
// if we're not at the end of the input...
if (this._cursor < this._input.length) {
// if the last character was a newline, increment row count
// and reset column count
if (this._input.charAt(this._cursor) === "\n") {
this._line++;
this._col=1;
} else {
this._col++;
}
// get character and increment cursor and column
c = this._input.charAt(this._cursor++);
}
return c;
},
//-------------------------------------------------------------------------
// Misc
//-------------------------------------------------------------------------
/**
* Saves the current location so it can be returned to later.
* @method mark
* @return {void}
*/
mark: function() {
this._bookmark = {
cursor: this._cursor,
line: this._line,
col: this._col
};
},
reset: function() {
if (this._bookmark) {
this._cursor = this._bookmark.cursor;
this._line = this._bookmark.line;
this._col = this._bookmark.col;
delete this._bookmark;
}
},
//-------------------------------------------------------------------------
// Advanced reading
//-------------------------------------------------------------------------
/**
* Reads up to and including the given string. Throws an error if that
* string is not found.
* @param {String} pattern The string to read.
* @return {String} The string when it is found.
* @throws Error when the string pattern is not found.
* @method readTo
*/
readTo: function(pattern) {
var buffer = "",
c;
/*
* First, buffer must be the same length as the pattern.
* Then, buffer must end with the pattern or else reach the
* end of the input.
*/
while (buffer.length < pattern.length || buffer.lastIndexOf(pattern) !== buffer.length - pattern.length) {
c = this.read();
if (c) {
buffer += c;
} else {
throw new Error("Expected \"" + pattern + "\" at line " + this._line + ", col " + this._col + ".");
}
}
return buffer;
},
/**
* Reads characters while each character causes the given
* filter function to return true. The function is passed
* in each character and either returns true to continue
* reading or false to stop.
* @param {Function} filter The function to read on each character.
* @return {String} The string made up of all characters that passed the
* filter check.
* @method readWhile
*/
readWhile: function(filter) {
var buffer = "",
c = this.peek();
while (c !== null && filter(c)) {
buffer += this.read();
c = this.peek();
}
return buffer;
},
/**
* Reads characters that match either text or a regular expression and
* returns those characters. If a match is found, the row and column
* are adjusted; if no match is found, the reader's state is unchanged.
* reading or false to stop.
* @param {String|RegExp} matcher If a string, then the literal string
* value is searched for. If a regular expression, then any string
* matching the pattern is search for.
* @return {String} The string made up of all characters that matched or
* null if there was no match.
* @method readMatch
*/
readMatch: function(matcher) {
var source = this._input.substring(this._cursor),
value = null;
// if it's a string, just do a straight match
if (typeof matcher === "string") {
if (source.slice(0, matcher.length) === matcher) {
value = this.readCount(matcher.length);
}
} else if (matcher instanceof RegExp) {
if (matcher.test(source)) {
value = this.readCount(RegExp.lastMatch.length);
}
}
return value;
},
/**
* Reads a given number of characters. If the end of the input is reached,
* it reads only the remaining characters and does not throw an error.
* @param {int} count The number of characters to read.
* @return {String} The string made up the read characters.
* @method readCount
*/
readCount: function(count) {
var buffer = "";
while (count--) {
buffer += this.read();
}
return buffer;
}
};
},{}],25:[function(require,module,exports){
"use strict";
module.exports = SyntaxError;
/**
* Type to use when a syntax error occurs.
* @class SyntaxError
* @namespace parserlib.util
* @constructor
* @param {String} message The error message.
* @param {int} line The line at which the error occurred.
* @param {int} col The column at which the error occurred.
*/
function SyntaxError(message, line, col) {
Error.call(this);
this.name = this.constructor.name;
/**
* The column at which the error occurred.
* @type int
* @property col
*/
this.col = col;
/**
* The line at which the error occurred.
* @type int
* @property line
*/
this.line = line;
/**
* The text representation of the unit.
* @type String
* @property text
*/
this.message = message;
}
//inherit from Error
SyntaxError.prototype = Object.create(Error.prototype); // jshint ignore:line
SyntaxError.prototype.constructor = SyntaxError; // jshint ignore:line
},{}],26:[function(require,module,exports){
"use strict";
module.exports = SyntaxUnit;
/**
* Base type to represent a single syntactic unit.
* @class SyntaxUnit
* @namespace parserlib.util
* @constructor
* @param {String} text The text of the unit.
* @param {int} line The line of text on which the unit resides.
* @param {int} col The column of text on which the unit resides.
*/
function SyntaxUnit(text, line, col, type) {
/**
* The column of text on which the unit resides.
* @type int
* @property col
*/
this.col = col;
/**
* The line of text on which the unit resides.
* @type int
* @property line
*/
this.line = line;
/**
* The text representation of the unit.
* @type String
* @property text
*/
this.text = text;
/**
* The type of syntax unit.
* @type int
* @property type
*/
this.type = type;
}
/**
* Create a new syntax unit based solely on the given token.
* Convenience method for creating a new syntax unit when
* it represents a single token instead of multiple.
* @param {Object} token The token object to represent.
* @return {parserlib.util.SyntaxUnit} The object representing the token.
* @static
* @method fromToken
*/
SyntaxUnit.fromToken = function(token) {
return new SyntaxUnit(token.value, token.startLine, token.startCol);
};
SyntaxUnit.prototype = {
//restore constructor
constructor: SyntaxUnit,
/**
* Returns the text representation of the unit.
* @return {String} The text representation of the unit.
* @method valueOf
*/
valueOf: function() {
return this.toString();
},
/**
* Returns the text representation of the unit.
* @return {String} The text representation of the unit.
* @method toString
*/
toString: function() {
return this.text;
}
};
},{}],27:[function(require,module,exports){
"use strict";
module.exports = TokenStreamBase;
var StringReader = require("./StringReader");
var SyntaxError = require("./SyntaxError");
/**
* Generic TokenStream providing base functionality.
* @class TokenStreamBase
* @namespace parserlib.util
* @constructor
* @param {String|StringReader} input The text to tokenize or a reader from
* which to read the input.
*/
function TokenStreamBase(input, tokenData) {
/**
* The string reader for easy access to the text.
* @type StringReader
* @property _reader
* @private
*/
this._reader = new StringReader(input ? input.toString() : "");
/**
* Token object for the last consumed token.
* @type Token
* @property _token
* @private
*/
this._token = null;
/**
* The array of token information.
* @type Array
* @property _tokenData
* @private
*/
this._tokenData = tokenData;
/**
* Lookahead token buffer.
* @type Array
* @property _lt
* @private
*/
this._lt = [];
/**
* Lookahead token buffer index.
* @type int
* @property _ltIndex
* @private
*/
this._ltIndex = 0;
this._ltIndexCache = [];
}
/**
* Accepts an array of token information and outputs
* an array of token data containing key-value mappings
* and matching functions that the TokenStream needs.
* @param {Array} tokens An array of token descriptors.
* @return {Array} An array of processed token data.
* @method createTokenData
* @static
*/
TokenStreamBase.createTokenData = function(tokens) {
var nameMap = [],
typeMap = Object.create(null),
tokenData = tokens.concat([]),
i = 0,
len = tokenData.length+1;
tokenData.UNKNOWN = -1;
tokenData.unshift({ name:"EOF" });
for (; i < len; i++) {
nameMap.push(tokenData[i].name);
tokenData[tokenData[i].name] = i;
if (tokenData[i].text) {
typeMap[tokenData[i].text] = i;
}
}
tokenData.name = function(tt) {
return nameMap[tt];
};
tokenData.type = function(c) {
return typeMap[c];
};
return tokenData;
};
TokenStreamBase.prototype = {
//restore constructor
constructor: TokenStreamBase,
//-------------------------------------------------------------------------
// Matching methods
//-------------------------------------------------------------------------
/**
* Determines if the next token matches the given token type.
* If so, that token is consumed; if not, the token is placed
* back onto the token stream. You can pass in any number of
* token types and this will return true if any of the token
* types is found.
* @param {int|int[]} tokenTypes Either a single token type or an array of
* token types that the next token might be. If an array is passed,
* it's assumed that the token can be any of these.
* @param {variant} channel (Optional) The channel to read from. If not
* provided, reads from the default (unnamed) channel.
* @return {Boolean} True if the token type matches, false if not.
* @method match
*/
match: function(tokenTypes, channel) {
//always convert to an array, makes things easier
if (!(tokenTypes instanceof Array)) {
tokenTypes = [tokenTypes];
}
var tt = this.get(channel),
i = 0,
len = tokenTypes.length;
while (i < len) {
if (tt === tokenTypes[i++]) {
return true;
}
}
//no match found, put the token back
this.unget();
return false;
},
/**
* Determines if the next token matches the given token type.
* If so, that token is consumed; if not, an error is thrown.
* @param {int|int[]} tokenTypes Either a single token type or an array of
* token types that the next token should be. If an array is passed,
* it's assumed that the token must be one of these.
* @return {void}
* @method mustMatch
*/
mustMatch: function(tokenTypes) {
var token;
//always convert to an array, makes things easier
if (!(tokenTypes instanceof Array)) {
tokenTypes = [tokenTypes];
}
if (!this.match.apply(this, arguments)) {
token = this.LT(1);
throw new SyntaxError("Expected " + this._tokenData[tokenTypes[0]].name +
" at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
}
},
//-------------------------------------------------------------------------
// Consuming methods
//-------------------------------------------------------------------------
/**
* Keeps reading from the token stream until either one of the specified
* token types is found or until the end of the input is reached.
* @param {int|int[]} tokenTypes Either a single token type or an array of
* token types that the next token should be. If an array is passed,
* it's assumed that the token must be one of these.
* @param {variant} channel (Optional) The channel to read from. If not
* provided, reads from the default (unnamed) channel.
* @return {void}
* @method advance
*/
advance: function(tokenTypes, channel) {
while (this.LA(0) !== 0 && !this.match(tokenTypes, channel)) {
this.get();
}
return this.LA(0);
},
/**
* Consumes the next token from the token stream.
* @return {int} The token type of the token that was just consumed.
* @method get
*/
get: function(channel) {
var tokenInfo = this._tokenData,
i =0,
token,
info;
//check the lookahead buffer first
if (this._lt.length && this._ltIndex >= 0 && this._ltIndex < this._lt.length) {
i++;
this._token = this._lt[this._ltIndex++];
info = tokenInfo[this._token.type];
//obey channels logic
while ((info.channel !== undefined && channel !== info.channel) &&
this._ltIndex < this._lt.length) {
this._token = this._lt[this._ltIndex++];
info = tokenInfo[this._token.type];
i++;
}
//here be dragons
if ((info.channel === undefined || channel === info.channel) &&
this._ltIndex <= this._lt.length) {
this._ltIndexCache.push(i);
return this._token.type;
}
}
//call token retriever method
token = this._getToken();
//if it should be hidden, don't save a token
if (token.type > -1 && !tokenInfo[token.type].hide) {
//apply token channel
token.channel = tokenInfo[token.type].channel;
//save for later
this._token = token;
this._lt.push(token);
//save space that will be moved (must be done before array is truncated)
this._ltIndexCache.push(this._lt.length - this._ltIndex + i);
//keep the buffer under 5 items
if (this._lt.length > 5) {
this._lt.shift();
}
//also keep the shift buffer under 5 items
if (this._ltIndexCache.length > 5) {
this._ltIndexCache.shift();
}
//update lookahead index
this._ltIndex = this._lt.length;
}
/*
* Skip to the next token if:
* 1. The token type is marked as hidden.
* 2. The token type has a channel specified and it isn't the current channel.
*/
info = tokenInfo[token.type];
if (info &&
(info.hide ||
(info.channel !== undefined && channel !== info.channel))) {
return this.get(channel);
} else {
//return just the type
return token.type;
}
},
/**
* Looks ahead a certain number of tokens and returns the token type at
* that position. This will throw an error if you lookahead past the
* end of input, past the size of the lookahead buffer, or back past
* the first token in the lookahead buffer.
* @param {int} The index of the token type to retrieve. 0 for the
* current token, 1 for the next, -1 for the previous, etc.
* @return {int} The token type of the token in the given position.
* @method LA
*/
LA: function(index) {
var total = index,
tt;
if (index > 0) {
//TODO: Store 5 somewhere
if (index > 5) {
throw new Error("Too much lookahead.");
}
//get all those tokens
while (total) {
tt = this.get();
total--;
}
//unget all those tokens
while (total < index) {
this.unget();
total++;
}
} else if (index < 0) {
if (this._lt[this._ltIndex+index]) {
tt = this._lt[this._ltIndex+index].type;
} else {
throw new Error("Too much lookbehind.");
}
} else {
tt = this._token.type;
}
return tt;
},
/**
* Looks ahead a certain number of tokens and returns the token at
* that position. This will throw an error if you lookahead past the
* end of input, past the size of the lookahead buffer, or back past
* the first token in the lookahead buffer.
* @param {int} The index of the token type to retrieve. 0 for the
* current token, 1 for the next, -1 for the previous, etc.
* @return {Object} The token of the token in the given position.
* @method LA
*/
LT: function(index) {
//lookahead first to prime the token buffer
this.LA(index);
//now find the token, subtract one because _ltIndex is already at the next index
return this._lt[this._ltIndex+index-1];
},
/**
* Returns the token type for the next token in the stream without
* consuming it.
* @return {int} The token type of the next token in the stream.
* @method peek
*/
peek: function() {
return this.LA(1);
},
/**
* Returns the actual token object for the last consumed token.
* @return {Token} The token object for the last consumed token.
* @method token
*/
token: function() {
return this._token;
},
/**
* Returns the name of the token for the given token type.
* @param {int} tokenType The type of token to get the name of.
* @return {String} The name of the token or "UNKNOWN_TOKEN" for any
* invalid token type.
* @method tokenName
*/
tokenName: function(tokenType) {
if (tokenType < 0 || tokenType > this._tokenData.length) {
return "UNKNOWN_TOKEN";
} else {
return this._tokenData[tokenType].name;
}
},
/**
* Returns the token type value for the given token name.
* @param {String} tokenName The name of the token whose value should be returned.
* @return {int} The token type value for the given token name or -1
* for an unknown token.
* @method tokenName
*/
tokenType: function(tokenName) {
return this._tokenData[tokenName] || -1;
},
/**
* Returns the last consumed token to the token stream.
* @method unget
*/
unget: function() {
//if (this._ltIndex > -1) {
if (this._ltIndexCache.length) {
this._ltIndex -= this._ltIndexCache.pop();//--;
this._token = this._lt[this._ltIndex - 1];
} else {
throw new Error("Too much lookahead.");
}
}
};
},{"./StringReader":24,"./SyntaxError":25}],28:[function(require,module,exports){
"use strict";
module.exports = {
StringReader : require("./StringReader"),
SyntaxError : require("./SyntaxError"),
SyntaxUnit : require("./SyntaxUnit"),
EventTarget : require("./EventTarget"),
TokenStreamBase : require("./TokenStreamBase")
};
},{"./EventTarget":23,"./StringReader":24,"./SyntaxError":25,"./SyntaxUnit":26,"./TokenStreamBase":27}],"parserlib":[function(require,module,exports){
"use strict";
module.exports = {
css : require("./css"),
util : require("./util")
};
},{"./css":22,"./util":28}]},{},[]);
return require('parserlib');
})();
var clone = (function() {
'use strict';
/**
* Clones (copies) an Object using deep copying.
*
* This function supports circular references by default, but if you are certain
* there are no circular references in your object, you can save some CPU time
* by calling clone(obj, false).
*
* Caution: if `circular` is false and `parent` contains circular references,
* your program may enter an infinite loop and crash.
*
* @param `parent` - the object to be cloned
* @param `circular` - set to true if the object to be cloned may contain
* circular references. (optional - true by default)
* @param `depth` - set to a number if the object is only to be cloned to
* a particular depth. (optional - defaults to Infinity)
* @param `prototype` - sets the prototype to be used when cloning an object.
* (optional - defaults to parent prototype).
*/
function clone(parent, circular, depth, prototype) {
var filter;
if (typeof circular === 'object') {
depth = circular.depth;
prototype = circular.prototype;
filter = circular.filter;
circular = circular.circular
}
// maintain two arrays for circular references, where corresponding parents
// and children have the same index
var allParents = [];
var allChildren = [];
var useBuffer = typeof Buffer != 'undefined';
if (typeof circular == 'undefined')
circular = true;
if (typeof depth == 'undefined')
depth = Infinity;
// recurse this function so we don't reset allParents and allChildren
function _clone(parent, depth) {
// cloning null always returns null
if (parent === null)
return null;
if (depth == 0)
return parent;
var child;
var proto;
if (typeof parent != 'object') {
return parent;
}
if (clone.__isArray(parent)) {
child = [];
} else if (clone.__isRegExp(parent)) {
child = new RegExp(parent.source, __getRegExpFlags(parent));
if (parent.lastIndex) child.lastIndex = parent.lastIndex;
} else if (clone.__isDate(parent)) {
child = new Date(parent.getTime());
} else if (useBuffer && Buffer.isBuffer(parent)) {
child = new Buffer(parent.length);
parent.copy(child);
return child;
} else {
if (typeof prototype == 'undefined') {
proto = Object.getPrototypeOf(parent);
child = Object.create(proto);
}
else {
child = Object.create(prototype);
proto = prototype;
}
}
if (circular) {
var index = allParents.indexOf(parent);
if (index != -1) {
return allChildren[index];
}
allParents.push(parent);
allChildren.push(child);
}
for (var i in parent) {
var attrs;
if (proto) {
attrs = Object.getOwnPropertyDescriptor(proto, i);
}
if (attrs && attrs.set == null) {
continue;
}
child[i] = _clone(parent[i], depth - 1);
}
return child;
}
return _clone(parent, depth);
}
/**
* Simple flat clone using prototype, accepts only objects, usefull for property
* override on FLAT configuration object (no nested props).
*
* USE WITH CAUTION! This may not behave as you wish if you do not know how this
* works.
*/
clone.clonePrototype = function clonePrototype(parent) {
if (parent === null)
return null;
var c = function () {};
c.prototype = parent;
return new c();
};
// private utility functions
function __objToStr(o) {
return Object.prototype.toString.call(o);
};
clone.__objToStr = __objToStr;
function __isDate(o) {
return typeof o === 'object' && __objToStr(o) === '[object Date]';
};
clone.__isDate = __isDate;
function __isArray(o) {
return typeof o === 'object' && __objToStr(o) === '[object Array]';
};
clone.__isArray = __isArray;
function __isRegExp(o) {
return typeof o === 'object' && __objToStr(o) === '[object RegExp]';
};
clone.__isRegExp = __isRegExp;
function __getRegExpFlags(re) {
var flags = '';
if (re.global) flags += 'g';
if (re.ignoreCase) flags += 'i';
if (re.multiline) flags += 'm';
return flags;
};
clone.__getRegExpFlags = __getRegExpFlags;
return clone;
})();
if (typeof module === 'object' && module.exports) {
module.exports = clone;
}
/**
* Main CSSLint object.
* @class CSSLint
* @static
* @extends parserlib.util.EventTarget
*/
/* global parserlib, clone, Reporter */
/* exported CSSLint */
var CSSLint = (function() {
"use strict";
var rules = [],
formatters = [],
embeddedRuleset = /\/\*\s*csslint([^\*]*)\*\//,
api = new parserlib.util.EventTarget();
api.version = "1.0.3";
//-------------------------------------------------------------------------
// Rule Management
//-------------------------------------------------------------------------
/**
* Adds a new rule to the engine.
* @param {Object} rule The rule to add.
* @method addRule
*/
api.addRule = function(rule) {
rules.push(rule);
rules[rule.id] = rule;
};
/**
* Clears all rule from the engine.
* @method clearRules
*/
api.clearRules = function() {
rules = [];
};
/**
* Returns the rule objects.
* @return An array of rule objects.
* @method getRules
*/
api.getRules = function() {
return [].concat(rules).sort(function(a, b) {
return a.id > b.id ? 1 : 0;
});
};
/**
* Returns a ruleset configuration object with all current rules.
* @return A ruleset object.
* @method getRuleset
*/
api.getRuleset = function() {
var ruleset = {},
i = 0,
len = rules.length;
while (i < len) {
ruleset[rules[i++].id] = 1; // by default, everything is a warning
}
return ruleset;
};
/**
* Returns a ruleset object based on embedded rules.
* @param {String} text A string of css containing embedded rules.
* @param {Object} ruleset A ruleset object to modify.
* @return {Object} A ruleset object.
* @method getEmbeddedRuleset
*/
function applyEmbeddedRuleset(text, ruleset) {
var valueMap,
embedded = text && text.match(embeddedRuleset),
rules = embedded && embedded[1];
if (rules) {
valueMap = {
"true": 2, // true is error
"": 1, // blank is warning
"false": 0, // false is ignore
"2": 2, // explicit error
"1": 1, // explicit warning
"0": 0 // explicit ignore
};
rules.toLowerCase().split(",").forEach(function(rule) {
var pair = rule.split(":"),
property = pair[0] || "",
value = pair[1] || "";
ruleset[property.trim()] = valueMap[value.trim()];
});
}
return ruleset;
}
//-------------------------------------------------------------------------
// Formatters
//-------------------------------------------------------------------------
/**
* Adds a new formatter to the engine.
* @param {Object} formatter The formatter to add.
* @method addFormatter
*/
api.addFormatter = function(formatter) {
// formatters.push(formatter);
formatters[formatter.id] = formatter;
};
/**
* Retrieves a formatter for use.
* @param {String} formatId The name of the format to retrieve.
* @return {Object} The formatter or undefined.
* @method getFormatter
*/
api.getFormatter = function(formatId) {
return formatters[formatId];
};
/**
* Formats the results in a particular format for a single file.
* @param {Object} result The results returned from CSSLint.verify().
* @param {String} filename The filename for which the results apply.
* @param {String} formatId The name of the formatter to use.
* @param {Object} options (Optional) for special output handling.
* @return {String} A formatted string for the results.
* @method format
*/
api.format = function(results, filename, formatId, options) {
var formatter = this.getFormatter(formatId),
result = null;
if (formatter) {
result = formatter.startFormat();
result += formatter.formatResults(results, filename, options || {});
result += formatter.endFormat();
}
return result;
};
/**
* Indicates if the given format is supported.
* @param {String} formatId The ID of the format to check.
* @return {Boolean} True if the format exists, false if not.
* @method hasFormat
*/
api.hasFormat = function(formatId) {
return formatters.hasOwnProperty(formatId);
};
//-------------------------------------------------------------------------
// Verification
//-------------------------------------------------------------------------
/**
* Starts the verification process for the given CSS text.
* @param {String} text The CSS text to verify.
* @param {Object} ruleset (Optional) List of rules to apply. If null, then
* all rules are used. If a rule has a value of 1 then it's a warning,
* a value of 2 means it's an error.
* @return {Object} Results of the verification.
* @method verify
*/
api.verify = function(text, ruleset) {
var i = 0,
reporter,
lines,
allow = {},
ignore = [],
report,
parser = new parserlib.css.Parser({
starHack: true,
ieFilters: true,
underscoreHack: true,
strict: false
});
// normalize line endings
lines = text.replace(/\n\r?/g, "$split$").split("$split$");
// find 'allow' comments
CSSLint.Util.forEach(lines, function (line, lineno) {
var allowLine = line && line.match(/\/\*[ \t]*csslint[ \t]+allow:[ \t]*([^\*]*)\*\//i),
allowRules = allowLine && allowLine[1],
allowRuleset = {};
if (allowRules) {
allowRules.toLowerCase().split(",").forEach(function(allowRule) {
allowRuleset[allowRule.trim()] = true;
});
if (Object.keys(allowRuleset).length > 0) {
allow[lineno + 1] = allowRuleset;
}
}
});
var ignoreStart = null,
ignoreEnd = null;
CSSLint.Util.forEach(lines, function (line, lineno) {
// Keep oldest, "unclosest" ignore:start
if (ignoreStart === null && line.match(/\/\*[ \t]*csslint[ \t]+ignore:start[ \t]*\*\//i)) {
ignoreStart = lineno;
}
if (line.match(/\/\*[ \t]*csslint[ \t]+ignore:end[ \t]*\*\//i)) {
ignoreEnd = lineno;
}
if (ignoreStart !== null && ignoreEnd !== null) {
ignore.push([ignoreStart, ignoreEnd]);
ignoreStart = ignoreEnd = null;
}
});
// Close remaining ignore block, if any
if (ignoreStart !== null) {
ignore.push([ignoreStart, lines.length]);
}
if (!ruleset) {
ruleset = this.getRuleset();
}
if (embeddedRuleset.test(text)) {
// defensively copy so that caller's version does not get modified
ruleset = clone(ruleset);
ruleset = applyEmbeddedRuleset(text, ruleset);
}
reporter = new Reporter(lines, ruleset, allow, ignore);
ruleset.errors = 2; // always report parsing errors as errors
for (i in ruleset) {
if (ruleset.hasOwnProperty(i) && ruleset[i]) {
if (rules[i]) {
rules[i].init(parser, reporter);
}
}
}
// capture most horrible error type
try {
parser.parse(text);
} catch (ex) {
reporter.error("Fatal error, cannot continue: " + ex.message, ex.line, ex.col, {});
}
report = {
messages : reporter.messages,
stats : reporter.stats,
ruleset : reporter.ruleset,
allow : reporter.allow,
ignore : reporter.ignore
};
// sort by line numbers, rollups at the bottom
report.messages.sort(function (a, b) {
if (a.rollup && !b.rollup) {
return 1;
} else if (!a.rollup && b.rollup) {
return -1;
} else {
return a.line - b.line;
}
});
return report;
};
//-------------------------------------------------------------------------
// Publish the API
//-------------------------------------------------------------------------
return api;
})();
/**
* An instance of Report is used to report results of the
* verification back to the main API.
* @class Reporter
* @constructor
* @param {String[]} lines The text lines of the source.
* @param {Object} ruleset The set of rules to work with, including if
* they are errors or warnings.
* @param {Object} explicitly allowed lines
* @param {[][]} ingore list of line ranges to be ignored
*/
function Reporter(lines, ruleset, allow, ignore) {
"use strict";
/**
* List of messages being reported.
* @property messages
* @type String[]
*/
this.messages = [];
/**
* List of statistics being reported.
* @property stats
* @type String[]
*/
this.stats = [];
/**
* Lines of code being reported on. Used to provide contextual information
* for messages.
* @property lines
* @type String[]
*/
this.lines = lines;
/**
* Information about the rules. Used to determine whether an issue is an
* error or warning.
* @property ruleset
* @type Object
*/
this.ruleset = ruleset;
/**
* Lines with specific rule messages to leave out of the report.
* @property allow
* @type Object
*/
this.allow = allow;
if (!this.allow) {
this.allow = {};
}
/**
* Linesets not to include in the report.
* @property ignore
* @type [][]
*/
this.ignore = ignore;
if (!this.ignore) {
this.ignore = [];
}
}
Reporter.prototype = {
// restore constructor
constructor: Reporter,
/**
* Report an error.
* @param {String} message The message to store.
* @param {int} line The line number.
* @param {int} col The column number.
* @param {Object} rule The rule this message relates to.
* @method error
*/
error: function(message, line, col, rule) {
"use strict";
this.messages.push({
type : "error",
line : line,
col : col,
message : message,
evidence: this.lines[line-1],
rule : rule || {}
});
},
/**
* Report an warning.
* @param {String} message The message to store.
* @param {int} line The line number.
* @param {int} col The column number.
* @param {Object} rule The rule this message relates to.
* @method warn
* @deprecated Use report instead.
*/
warn: function(message, line, col, rule) {
"use strict";
this.report(message, line, col, rule);
},
/**
* Report an issue.
* @param {String} message The message to store.
* @param {int} line The line number.
* @param {int} col The column number.
* @param {Object} rule The rule this message relates to.
* @method report
*/
report: function(message, line, col, rule) {
"use strict";
// Check if rule violation should be allowed
if (this.allow.hasOwnProperty(line) && this.allow[line].hasOwnProperty(rule.id)) {
return;
}
var ignore = false;
CSSLint.Util.forEach(this.ignore, function (range) {
if (range[0] <= line && line <= range[1]) {
ignore = true;
}
});
if (ignore) {
return;
}
this.messages.push({
type : this.ruleset[rule.id] === 2 ? "error" : "warning",
line : line,
col : col,
message : message,
evidence: this.lines[line-1],
rule : rule
});
},
/**
* Report some informational text.
* @param {String} message The message to store.
* @param {int} line The line number.
* @param {int} col The column number.
* @param {Object} rule The rule this message relates to.
* @method info
*/
info: function(message, line, col, rule) {
"use strict";
this.messages.push({
type : "info",
line : line,
col : col,
message : message,
evidence: this.lines[line-1],
rule : rule
});
},
/**
* Report some rollup error information.
* @param {String} message The message to store.
* @param {Object} rule The rule this message relates to.
* @method rollupError
*/
rollupError: function(message, rule) {
"use strict";
this.messages.push({
type : "error",
rollup : true,
message : message,
rule : rule
});
},
/**
* Report some rollup warning information.
* @param {String} message The message to store.
* @param {Object} rule The rule this message relates to.
* @method rollupWarn
*/
rollupWarn: function(message, rule) {
"use strict";
this.messages.push({
type : "warning",
rollup : true,
message : message,
rule : rule
});
},
/**
* Report a statistic.
* @param {String} name The name of the stat to store.
* @param {Variant} value The value of the stat.
* @method stat
*/
stat: function(name, value) {
"use strict";
this.stats[name] = value;
}
};
// expose for testing purposes
CSSLint._Reporter = Reporter;
/*
* Utility functions that make life easier.
*/
CSSLint.Util = {
/*
* Adds all properties from supplier onto receiver,
* overwriting if the same name already exists on
* receiver.
* @param {Object} The object to receive the properties.
* @param {Object} The object to provide the properties.
* @return {Object} The receiver
*/
mix: function(receiver, supplier) {
"use strict";
var prop;
for (prop in supplier) {
if (supplier.hasOwnProperty(prop)) {
receiver[prop] = supplier[prop];
}
}
return prop;
},
/*
* Polyfill for array indexOf() method.
* @param {Array} values The array to search.
* @param {Variant} value The value to search for.
* @return {int} The index of the value if found, -1 if not.
*/
indexOf: function(values, value) {
"use strict";
if (values.indexOf) {
return values.indexOf(value);
} else {
for (var i=0, len=values.length; i < len; i++) {
if (values[i] === value) {
return i;
}
}
return -1;
}
},
/*
* Polyfill for array forEach() method.
* @param {Array} values The array to operate on.
* @param {Function} func The function to call on each item.
* @return {void}
*/
forEach: function(values, func) {
"use strict";
if (values.forEach) {
return values.forEach(func);
} else {
for (var i=0, len=values.length; i < len; i++) {
func(values[i], i, values);
}
}
}
};
/*
* Rule: Don't use adjoining classes (.foo.bar).
*/
CSSLint.addRule({
// rule information
id: "adjoining-classes",
name: "Disallow adjoining classes",
desc: "Don't use adjoining classes.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-adjoining-classes",
browsers: "IE6",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("startrule", function(event) {
var selectors = event.selectors,
selector,
part,
modifier,
classCount,
i, j, k;
for (i=0; i < selectors.length; i++) {
selector = selectors[i];
for (j=0; j < selector.parts.length; j++) {
part = selector.parts[j];
if (part.type === parser.SELECTOR_PART_TYPE) {
classCount = 0;
for (k=0; k < part.modifiers.length; k++) {
modifier = part.modifiers[k];
if (modifier.type === "class") {
classCount++;
}
if (classCount > 1){
reporter.report("Adjoining classes: "+selectors[i].text, part.line, part.col, rule);
}
}
}
}
}
});
}
});
/*
* Rule: Don't use width or height when using padding or border.
*/
CSSLint.addRule({
// rule information
id: "box-model",
name: "Beware of broken box size",
desc: "Don't use width or height when using padding or border.",
url: "https://github.com/CSSLint/csslint/wiki/Beware-of-box-model-size",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
widthProperties = {
border: 1,
"border-left": 1,
"border-right": 1,
padding: 1,
"padding-left": 1,
"padding-right": 1
},
heightProperties = {
border: 1,
"border-bottom": 1,
"border-top": 1,
padding: 1,
"padding-bottom": 1,
"padding-top": 1
},
properties,
boxSizing = false;
function startRule() {
properties = {};
boxSizing = false;
}
function endRule() {
var prop, value;
if (!boxSizing) {
if (properties.height) {
for (prop in heightProperties) {
if (heightProperties.hasOwnProperty(prop) && properties[prop]) {
value = properties[prop].value;
// special case for padding
if (!(prop === "padding" && value.parts.length === 2 && value.parts[0].value === 0)) {
reporter.report("Using height with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
}
}
}
}
if (properties.width) {
for (prop in widthProperties) {
if (widthProperties.hasOwnProperty(prop) && properties[prop]) {
value = properties[prop].value;
if (!(prop === "padding" && value.parts.length === 2 && value.parts[1].value === 0)) {
reporter.report("Using width with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
}
}
}
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("startviewport", startRule);
parser.addListener("property", function(event) {
var name = event.property.text.toLowerCase();
if (heightProperties[name] || widthProperties[name]) {
if (!/^0\S*$/.test(event.value) && !(name === "border" && event.value.toString() === "none")) {
properties[name] = {
line: event.property.line,
col: event.property.col,
value: event.value
};
}
} else {
if (/^(width|height)/i.test(name) && /^(length|percentage)/.test(event.value.parts[0].type)) {
properties[name] = 1;
} else if (name === "box-sizing") {
boxSizing = true;
}
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endpage", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endkeyframerule", endRule);
parser.addListener("endviewport", endRule);
}
});
/*
* Rule: box-sizing doesn't work in IE6 and IE7.
*/
CSSLint.addRule({
// rule information
id: "box-sizing",
name: "Disallow use of box-sizing",
desc: "The box-sizing properties isn't supported in IE6 and IE7.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-box-sizing",
browsers: "IE6, IE7",
tags: ["Compatibility"],
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("property", function(event) {
var name = event.property.text.toLowerCase();
if (name === "box-sizing") {
reporter.report("The box-sizing property isn't supported in IE6 and IE7.", event.line, event.col, rule);
}
});
}
});
/*
* Rule: Use the bulletproof @font-face syntax to avoid 404's in old IE
* (http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax)
*/
CSSLint.addRule({
// rule information
id: "bulletproof-font-face",
name: "Use the bulletproof @font-face syntax",
desc: "Use the bulletproof @font-face syntax to avoid 404's in old IE (http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax).",
url: "https://github.com/CSSLint/csslint/wiki/Bulletproof-font-face",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
fontFaceRule = false,
firstSrc = true,
ruleFailed = false,
line, col;
// Mark the start of a @font-face declaration so we only test properties inside it
parser.addListener("startfontface", function() {
fontFaceRule = true;
});
parser.addListener("property", function(event) {
// If we aren't inside an @font-face declaration then just return
if (!fontFaceRule) {
return;
}
var propertyName = event.property.toString().toLowerCase(),
value = event.value.toString();
// Set the line and col numbers for use in the endfontface listener
line = event.line;
col = event.col;
// This is the property that we care about, we can ignore the rest
if (propertyName === "src") {
var regex = /^\s?url\(['"].+\.eot\?.*['"]\)\s*format\(['"]embedded-opentype['"]\).*$/i;
// We need to handle the advanced syntax with two src properties
if (!value.match(regex) && firstSrc) {
ruleFailed = true;
firstSrc = false;
} else if (value.match(regex) && !firstSrc) {
ruleFailed = false;
}
}
});
// Back to normal rules that we don't need to test
parser.addListener("endfontface", function() {
fontFaceRule = false;
if (ruleFailed) {
reporter.report("@font-face declaration doesn't follow the fontspring bulletproof syntax.", line, col, rule);
}
});
}
});
/*
* Rule: Include all compatible vendor prefixes to reach a wider
* range of users.
*/
CSSLint.addRule({
// rule information
id: "compatible-vendor-prefixes",
name: "Require compatible vendor prefixes",
desc: "Include all compatible vendor prefixes to reach a wider range of users.",
url: "https://github.com/CSSLint/csslint/wiki/Require-compatible-vendor-prefixes",
browsers: "All",
// initialization
init: function (parser, reporter) {
"use strict";
var rule = this,
compatiblePrefixes,
properties,
prop,
variations,
prefixed,
i,
len,
inKeyFrame = false,
arrayPush = Array.prototype.push,
applyTo = [];
// See http://peter.sh/experiments/vendor-prefixed-css-property-overview/ for details
compatiblePrefixes = {
"animation" : "webkit",
"animation-delay" : "webkit",
"animation-direction" : "webkit",
"animation-duration" : "webkit",
"animation-fill-mode" : "webkit",
"animation-iteration-count" : "webkit",
"animation-name" : "webkit",
"animation-play-state" : "webkit",
"animation-timing-function" : "webkit",
"appearance" : "webkit moz",
"border-end" : "webkit moz",
"border-end-color" : "webkit moz",
"border-end-style" : "webkit moz",
"border-end-width" : "webkit moz",
"border-image" : "webkit moz o",
"border-radius" : "webkit",
"border-start" : "webkit moz",
"border-start-color" : "webkit moz",
"border-start-style" : "webkit moz",
"border-start-width" : "webkit moz",
"box-align" : "webkit moz ms",
"box-direction" : "webkit moz ms",
"box-flex" : "webkit moz ms",
"box-lines" : "webkit ms",
"box-ordinal-group" : "webkit moz ms",
"box-orient" : "webkit moz ms",
"box-pack" : "webkit moz ms",
"box-sizing" : "",
"box-shadow" : "",
"column-count" : "webkit moz ms",
"column-gap" : "webkit moz ms",
"column-rule" : "webkit moz ms",
"column-rule-color" : "webkit moz ms",
"column-rule-style" : "webkit moz ms",
"column-rule-width" : "webkit moz ms",
"column-width" : "webkit moz ms",
"hyphens" : "epub moz",
"line-break" : "webkit ms",
"margin-end" : "webkit moz",
"margin-start" : "webkit moz",
"marquee-speed" : "webkit wap",
"marquee-style" : "webkit wap",
"padding-end" : "webkit moz",
"padding-start" : "webkit moz",
"tab-size" : "moz o",
"text-size-adjust" : "webkit ms",
"transform" : "webkit ms",
"transform-origin" : "webkit ms",
"transition" : "",
"transition-delay" : "",
"transition-duration" : "",
"transition-property" : "",
"transition-timing-function" : "",
"user-modify" : "webkit moz",
"user-select" : "webkit moz ms",
"word-break" : "epub ms",
"writing-mode" : "epub ms"
};
for (prop in compatiblePrefixes) {
if (compatiblePrefixes.hasOwnProperty(prop)) {
variations = [];
prefixed = compatiblePrefixes[prop].split(" ");
for (i = 0, len = prefixed.length; i < len; i++) {
variations.push("-" + prefixed[i] + "-" + prop);
}
compatiblePrefixes[prop] = variations;
arrayPush.apply(applyTo, variations);
}
}
parser.addListener("startrule", function () {
properties = [];
});
parser.addListener("startkeyframes", function (event) {
inKeyFrame = event.prefix || true;
});
parser.addListener("endkeyframes", function () {
inKeyFrame = false;
});
parser.addListener("property", function (event) {
var name = event.property;
if (CSSLint.Util.indexOf(applyTo, name.text) > -1) {
// e.g., -moz-transform is okay to be alone in @-moz-keyframes
if (!inKeyFrame || typeof inKeyFrame !== "string" ||
name.text.indexOf("-" + inKeyFrame + "-") !== 0) {
properties.push(name);
}
}
});
parser.addListener("endrule", function () {
if (!properties.length) {
return;
}
var propertyGroups = {},
i,
len,
name,
prop,
variations,
value,
full,
actual,
item,
propertiesSpecified;
for (i = 0, len = properties.length; i < len; i++) {
name = properties[i];
for (prop in compatiblePrefixes) {
if (compatiblePrefixes.hasOwnProperty(prop)) {
variations = compatiblePrefixes[prop];
if (CSSLint.Util.indexOf(variations, name.text) > -1) {
if (!propertyGroups[prop]) {
propertyGroups[prop] = {
full: variations.slice(0),
actual: [],
actualNodes: []
};
}
if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name.text) === -1) {
propertyGroups[prop].actual.push(name.text);
propertyGroups[prop].actualNodes.push(name);
}
}
}
}
}
for (prop in propertyGroups) {
if (propertyGroups.hasOwnProperty(prop)) {
value = propertyGroups[prop];
full = value.full;
actual = value.actual;
if (full.length > actual.length) {
for (i = 0, len = full.length; i < len; i++) {
item = full[i];
if (CSSLint.Util.indexOf(actual, item) === -1) {
propertiesSpecified = (actual.length === 1) ? actual[0] : (actual.length === 2) ? actual.join(" and ") : actual.join(", ");
reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", value.actualNodes[0].line, value.actualNodes[0].col, rule);
}
}
}
}
}
});
}
});
/*
* Rule: Certain properties don't play well with certain display values.
* - float should not be used with inline-block
* - height, width, margin-top, margin-bottom, float should not be used with inline
* - vertical-align should not be used with block
* - margin, float should not be used with table-*
*/
CSSLint.addRule({
// rule information
id: "display-property-grouping",
name: "Require properties appropriate for display",
desc: "Certain properties shouldn't be used with certain display property values.",
url: "https://github.com/CSSLint/csslint/wiki/Require-properties-appropriate-for-display",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
var propertiesToCheck = {
display: 1,
"float": "none",
height: 1,
width: 1,
margin: 1,
"margin-left": 1,
"margin-right": 1,
"margin-bottom": 1,
"margin-top": 1,
padding: 1,
"padding-left": 1,
"padding-right": 1,
"padding-bottom": 1,
"padding-top": 1,
"vertical-align": 1
},
properties;
function reportProperty(name, display, msg) {
if (properties[name]) {
if (typeof propertiesToCheck[name] !== "string" || properties[name].value.toLowerCase() !== propertiesToCheck[name]) {
reporter.report(msg || name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
}
}
}
function startRule() {
properties = {};
}
function endRule() {
var display = properties.display ? properties.display.value : null;
if (display) {
switch (display) {
case "inline":
// height, width, margin-top, margin-bottom, float should not be used with inline
reportProperty("height", display);
reportProperty("width", display);
reportProperty("margin", display);
reportProperty("margin-top", display);
reportProperty("margin-bottom", display);
reportProperty("float", display, "display:inline has no effect on floated elements (but may be used to fix the IE6 double-margin bug).");
break;
case "block":
// vertical-align should not be used with block
reportProperty("vertical-align", display);
break;
case "inline-block":
// float should not be used with inline-block
reportProperty("float", display);
break;
default:
// margin, float should not be used with table
if (display.indexOf("table-") === 0) {
reportProperty("margin", display);
reportProperty("margin-left", display);
reportProperty("margin-right", display);
reportProperty("margin-top", display);
reportProperty("margin-bottom", display);
reportProperty("float", display);
}
// otherwise do nothing
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startviewport", startRule);
parser.addListener("property", function(event) {
var name = event.property.text.toLowerCase();
if (propertiesToCheck[name]) {
properties[name] = {
value: event.value.text,
line: event.property.line,
col: event.property.col
};
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endkeyframerule", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endpage", endRule);
parser.addListener("endviewport", endRule);
}
});
/*
* Rule: Disallow duplicate background-images (using url).
*/
CSSLint.addRule({
// rule information
id: "duplicate-background-images",
name: "Disallow duplicate background images",
desc: "Every background-image should be unique. Use a common class for e.g. sprites.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-duplicate-background-images",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
stack = {};
parser.addListener("property", function(event) {
var name = event.property.text,
value = event.value,
i, len;
if (name.match(/background/i)) {
for (i=0, len=value.parts.length; i < len; i++) {
if (value.parts[i].type === "uri") {
if (typeof stack[value.parts[i].uri] === "undefined") {
stack[value.parts[i].uri] = event;
} else {
reporter.report("Background image '" + value.parts[i].uri + "' was used multiple times, first declared at line " + stack[value.parts[i].uri].line + ", col " + stack[value.parts[i].uri].col + ".", event.line, event.col, rule);
}
}
}
}
});
}
});
/*
* Rule: Duplicate properties must appear one after the other. If an already-defined
* property appears somewhere else in the rule, then it's likely an error.
*/
CSSLint.addRule({
// rule information
id: "duplicate-properties",
name: "Disallow duplicate properties",
desc: "Duplicate properties must appear one after the other.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-duplicate-properties",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
properties,
lastProperty;
function startRule() {
properties = {};
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("startviewport", startRule);
parser.addListener("property", function(event) {
var property = event.property,
name = property.text.toLowerCase();
if (properties[name] && (lastProperty !== name || properties[name] === event.value.text)) {
reporter.report("Duplicate property '" + event.property + "' found.", event.line, event.col, rule);
}
properties[name] = event.value.text;
lastProperty = name;
});
}
});
/*
* Rule: Style rules without any properties defined should be removed.
*/
CSSLint.addRule({
// rule information
id: "empty-rules",
name: "Disallow empty rules",
desc: "Rules without any properties specified should be removed.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-empty-rules",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
count = 0;
parser.addListener("startrule", function() {
count=0;
});
parser.addListener("property", function() {
count++;
});
parser.addListener("endrule", function(event) {
var selectors = event.selectors;
if (count === 0) {
reporter.report("Rule is empty.", selectors[0].line, selectors[0].col, rule);
}
});
}
});
/*
* Rule: There should be no syntax errors. (Duh.)
*/
CSSLint.addRule({
// rule information
id: "errors",
name: "Parsing Errors",
desc: "This rule looks for recoverable syntax errors.",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("error", function(event) {
reporter.error(event.message, event.line, event.col, rule);
});
}
});
CSSLint.addRule({
// rule information
id: "fallback-colors",
name: "Require fallback colors",
desc: "For older browsers that don't support RGBA, HSL, or HSLA, provide a fallback color.",
url: "https://github.com/CSSLint/csslint/wiki/Require-fallback-colors",
browsers: "IE6,IE7,IE8",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
lastProperty,
propertiesToCheck = {
color: 1,
background: 1,
"border-color": 1,
"border-top-color": 1,
"border-right-color": 1,
"border-bottom-color": 1,
"border-left-color": 1,
border: 1,
"border-top": 1,
"border-right": 1,
"border-bottom": 1,
"border-left": 1,
"background-color": 1
};
function startRule() {
lastProperty = null;
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("startviewport", startRule);
parser.addListener("property", function(event) {
var property = event.property,
name = property.text.toLowerCase(),
parts = event.value.parts,
i = 0,
colorType = "",
len = parts.length;
if (propertiesToCheck[name]) {
while (i < len) {
if (parts[i].type === "color") {
if ("alpha" in parts[i] || "hue" in parts[i]) {
if (/([^\)]+)\(/.test(parts[i])) {
colorType = RegExp.$1.toUpperCase();
}
if (!lastProperty || (lastProperty.property.text.toLowerCase() !== name || lastProperty.colorType !== "compat")) {
reporter.report("Fallback " + name + " (hex or RGB) should precede " + colorType + " " + name + ".", event.line, event.col, rule);
}
} else {
event.colorType = "compat";
}
}
i++;
}
}
lastProperty = event;
});
}
});
/*
* Rule: You shouldn't use more than 10 floats. If you do, there's probably
* room for some abstraction.
*/
CSSLint.addRule({
// rule information
id: "floats",
name: "Disallow too many floats",
desc: "This rule tests if the float property is used too many times",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-too-many-floats",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
var count = 0;
// count how many times "float" is used
parser.addListener("property", function(event) {
if (event.property.text.toLowerCase() === "float" &&
event.value.text.toLowerCase() !== "none") {
count++;
}
});
// report the results
parser.addListener("endstylesheet", function() {
reporter.stat("floats", count);
if (count >= 10) {
reporter.rollupWarn("Too many floats (" + count + "), you're probably using them for layout. Consider using a grid system instead.", rule);
}
});
}
});
/*
* Rule: Avoid too many @font-face declarations in the same stylesheet.
*/
CSSLint.addRule({
// rule information
id: "font-faces",
name: "Don't use too many web fonts",
desc: "Too many different web fonts in the same stylesheet.",
url: "https://github.com/CSSLint/csslint/wiki/Don%27t-use-too-many-web-fonts",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
count = 0;
parser.addListener("startfontface", function() {
count++;
});
parser.addListener("endstylesheet", function() {
if (count > 5) {
reporter.rollupWarn("Too many @font-face declarations (" + count + ").", rule);
}
});
}
});
/*
* Rule: You shouldn't need more than 9 font-size declarations.
*/
CSSLint.addRule({
// rule information
id: "font-sizes",
name: "Disallow too many font sizes",
desc: "Checks the number of font-size declarations.",
url: "https://github.com/CSSLint/csslint/wiki/Don%27t-use-too-many-font-size-declarations",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
count = 0;
// check for use of "font-size"
parser.addListener("property", function(event) {
if (event.property.toString() === "font-size") {
count++;
}
});
// report the results
parser.addListener("endstylesheet", function() {
reporter.stat("font-sizes", count);
if (count >= 10) {
reporter.rollupWarn("Too many font-size declarations (" + count + "), abstraction needed.", rule);
}
});
}
});
/*
* Rule: When using a vendor-prefixed gradient, make sure to use them all.
*/
CSSLint.addRule({
// rule information
id: "gradients",
name: "Require all gradient definitions",
desc: "When using a vendor-prefixed gradient, make sure to use them all.",
url: "https://github.com/CSSLint/csslint/wiki/Require-all-gradient-definitions",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
gradients;
parser.addListener("startrule", function() {
gradients = {
moz: 0,
webkit: 0,
oldWebkit: 0,
o: 0
};
});
parser.addListener("property", function(event) {
if (/\-(moz|o|webkit)(?:\-(?:linear|radial))\-gradient/i.test(event.value)) {
gradients[RegExp.$1] = 1;
} else if (/\-webkit\-gradient/i.test(event.value)) {
gradients.oldWebkit = 1;
}
});
parser.addListener("endrule", function(event) {
var missing = [];
if (!gradients.moz) {
missing.push("Firefox 3.6+");
}
if (!gradients.webkit) {
missing.push("Webkit (Safari 5+, Chrome)");
}
if (!gradients.oldWebkit) {
missing.push("Old Webkit (Safari 4+, Chrome)");
}
if (!gradients.o) {
missing.push("Opera 11.1+");
}
if (missing.length && missing.length < 4) {
reporter.report("Missing vendor-prefixed CSS gradients for " + missing.join(", ") + ".", event.selectors[0].line, event.selectors[0].col, rule);
}
});
}
});
/*
* Rule: Don't use IDs for selectors.
*/
CSSLint.addRule({
// rule information
id: "ids",
name: "Disallow IDs in selectors",
desc: "Selectors should not contain IDs.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-IDs-in-selectors",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("startrule", function(event) {
var selectors = event.selectors,
selector,
part,
modifier,
idCount,
i, j, k;
for (i=0; i < selectors.length; i++) {
selector = selectors[i];
idCount = 0;
for (j=0; j < selector.parts.length; j++) {
part = selector.parts[j];
if (part.type === parser.SELECTOR_PART_TYPE) {
for (k=0; k < part.modifiers.length; k++) {
modifier = part.modifiers[k];
if (modifier.type === "id") {
idCount++;
}
}
}
}
if (idCount === 1) {
reporter.report("Don't use IDs in selectors.", selector.line, selector.col, rule);
} else if (idCount > 1) {
reporter.report(idCount + " IDs in the selector, really?", selector.line, selector.col, rule);
}
}
});
}
});
/*
* Rule: IE6-9 supports up to 31 stylesheet import.
* Reference:
* http://blogs.msdn.com/b/ieinternals/archive/2011/05/14/internet-explorer-stylesheet-rule-selector-import-sheet-limit-maximum.aspx
*/
CSSLint.addRule({
// rule information
id: "import-ie-limit",
name: "@import limit on IE6-IE9",
desc: "IE6-9 supports up to 31 @import per stylesheet",
browsers: "IE6, IE7, IE8, IE9",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
MAX_IMPORT_COUNT = 31,
count = 0;
function startPage() {
count = 0;
}
parser.addListener("startpage", startPage);
parser.addListener("import", function() {
count++;
});
parser.addListener("endstylesheet", function() {
if (count > MAX_IMPORT_COUNT) {
reporter.rollupError(
"Too many @import rules (" + count + "). IE6-9 supports up to 31 import per stylesheet.",
rule
);
}
});
}
});
/*
* Rule: Don't use @import, use <link> instead.
*/
CSSLint.addRule({
// rule information
id: "import",
name: "Disallow @import",
desc: "Don't use @import, use <link> instead.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-%40import",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("import", function(event) {
reporter.report("@import prevents parallel downloads, use <link> instead.", event.line, event.col, rule);
});
}
});
/*
* Rule: Make sure !important is not overused, this could lead to specificity
* war. Display a warning on !important declarations, an error if it's
* used more at least 10 times.
*/
CSSLint.addRule({
// rule information
id: "important",
name: "Disallow !important",
desc: "Be careful when using !important declaration",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-%21important",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
count = 0;
// warn that important is used and increment the declaration counter
parser.addListener("property", function(event) {
if (event.important === true) {
count++;
reporter.report("Use of !important", event.line, event.col, rule);
}
});
// if there are more than 10, show an error
parser.addListener("endstylesheet", function() {
reporter.stat("important", count);
if (count >= 10) {
reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
}
});
}
});
/*
* Rule: Properties should be known (listed in CSS3 specification) or
* be a vendor-prefixed property.
*/
CSSLint.addRule({
// rule information
id: "known-properties",
name: "Require use of known properties",
desc: "Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.",
url: "https://github.com/CSSLint/csslint/wiki/Require-use-of-known-properties",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("property", function(event) {
// the check is handled entirely by the parser-lib (https://github.com/nzakas/parser-lib)
if (event.invalid) {
reporter.report(event.invalid.message, event.line, event.col, rule);
}
});
}
});
/*
* Rule: All properties should be in alphabetical order.
*/
CSSLint.addRule({
// rule information
id: "order-alphabetical",
name: "Alphabetical order",
desc: "Assure properties are in alphabetical order",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
properties;
var startRule = function () {
properties = [];
};
var endRule = function(event) {
var currentProperties = properties.join(","),
expectedProperties = properties.sort().join(",");
if (currentProperties !== expectedProperties) {
reporter.report("Rule doesn't have all its properties in alphabetical order.", event.line, event.col, rule);
}
};
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("startviewport", startRule);
parser.addListener("property", function(event) {
var name = event.property.text,
lowerCasePrefixLessName = name.toLowerCase().replace(/^-.*?-/, "");
properties.push(lowerCasePrefixLessName);
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endpage", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endkeyframerule", endRule);
parser.addListener("endviewport", endRule);
}
});
/*
* Rule: outline: none or outline: 0 should only be used in a :focus rule
* and only if there are other properties in the same rule.
*/
CSSLint.addRule({
// rule information
id: "outline-none",
name: "Disallow outline: none",
desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-outline%3Anone",
browsers: "All",
tags: ["Accessibility"],
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
lastRule;
function startRule(event) {
if (event.selectors) {
lastRule = {
line: event.line,
col: event.col,
selectors: event.selectors,
propCount: 0,
outline: false
};
} else {
lastRule = null;
}
}
function endRule() {
if (lastRule) {
if (lastRule.outline) {
if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1) {
reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
} else if (lastRule.propCount === 1) {
reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
}
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("startviewport", startRule);
parser.addListener("property", function(event) {
var name = event.property.text.toLowerCase(),
value = event.value;
if (lastRule) {
lastRule.propCount++;
if (name === "outline" && (value.toString() === "none" || value.toString() === "0")) {
lastRule.outline = true;
}
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endpage", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endkeyframerule", endRule);
parser.addListener("endviewport", endRule);
}
});
/*
* Rule: Don't use classes or IDs with elements (a.foo or a#foo).
*/
CSSLint.addRule({
// rule information
id: "overqualified-elements",
name: "Disallow overqualified elements",
desc: "Don't use classes or IDs with elements (a.foo or a#foo).",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-overqualified-elements",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
classes = {};
parser.addListener("startrule", function(event) {
var selectors = event.selectors,
selector,
part,
modifier,
i, j, k;
for (i=0; i < selectors.length; i++) {
selector = selectors[i];
for (j=0; j < selector.parts.length; j++) {
part = selector.parts[j];
if (part.type === parser.SELECTOR_PART_TYPE) {
for (k=0; k < part.modifiers.length; k++) {
modifier = part.modifiers[k];
if (part.elementName && modifier.type === "id") {
reporter.report("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
} else if (modifier.type === "class") {
if (!classes[modifier]) {
classes[modifier] = [];
}
classes[modifier].push({
modifier: modifier,
part: part
});
}
}
}
}
}
});
parser.addListener("endstylesheet", function() {
var prop;
for (prop in classes) {
if (classes.hasOwnProperty(prop)) {
// one use means that this is overqualified
if (classes[prop].length === 1 && classes[prop][0].part.elementName) {
reporter.report("Element (" + classes[prop][0].part + ") is overqualified, just use " + classes[prop][0].modifier + " without element name.", classes[prop][0].part.line, classes[prop][0].part.col, rule);
}
}
}
});
}
});
/*
* Rule: Headings (h1-h6) should not be qualified (namespaced).
*/
CSSLint.addRule({
// rule information
id: "qualified-headings",
name: "Disallow qualified headings",
desc: "Headings should not be qualified (namespaced).",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-qualified-headings",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("startrule", function(event) {
var selectors = event.selectors,
selector,
part,
i, j;
for (i=0; i < selectors.length; i++) {
selector = selectors[i];
for (j=0; j < selector.parts.length; j++) {
part = selector.parts[j];
if (part.type === parser.SELECTOR_PART_TYPE) {
if (part.elementName && /h[1-6]/.test(part.elementName.toString()) && j > 0) {
reporter.report("Heading (" + part.elementName + ") should not be qualified.", part.line, part.col, rule);
}
}
}
}
});
}
});
/*
* Rule: Selectors that look like regular expressions are slow and should be avoided.
*/
CSSLint.addRule({
// rule information
id: "regex-selectors",
name: "Disallow selectors that look like regexs",
desc: "Selectors that look like regular expressions are slow and should be avoided.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-selectors-that-look-like-regular-expressions",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("startrule", function(event) {
var selectors = event.selectors,
selector,
part,
modifier,
i, j, k;
for (i=0; i < selectors.length; i++) {
selector = selectors[i];
for (j=0; j < selector.parts.length; j++) {
part = selector.parts[j];
if (part.type === parser.SELECTOR_PART_TYPE) {
for (k=0; k < part.modifiers.length; k++) {
modifier = part.modifiers[k];
if (modifier.type === "attribute") {
if (/([~\|\^\$\*]=)/.test(modifier)) {
reporter.report("Attribute selectors with " + RegExp.$1 + " are slow!", modifier.line, modifier.col, rule);
}
}
}
}
}
}
});
}
});
/*
* Rule: Total number of rules should not exceed x.
*/
CSSLint.addRule({
// rule information
id: "rules-count",
name: "Rules Count",
desc: "Track how many rules there are.",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var count = 0;
// count each rule
parser.addListener("startrule", function() {
count++;
});
parser.addListener("endstylesheet", function() {
reporter.stat("rule-count", count);
});
}
});
/*
* Rule: Warn people with approaching the IE 4095 limit
*/
CSSLint.addRule({
// rule information
id: "selector-max-approaching",
name: "Warn when approaching the 4095 selector limit for IE",
desc: "Will warn when selector count is >= 3800 selectors.",
browsers: "IE",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this, count = 0;
parser.addListener("startrule", function(event) {
count += event.selectors.length;
});
parser.addListener("endstylesheet", function() {
if (count >= 3800) {
reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.", 0, 0, rule);
}
});
}
});
/*
* Rule: Warn people past the IE 4095 limit
*/
CSSLint.addRule({
// rule information
id: "selector-max",
name: "Error when past the 4095 selector limit for IE",
desc: "Will error when selector count is > 4095.",
browsers: "IE",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this, count = 0;
parser.addListener("startrule", function(event) {
count += event.selectors.length;
});
parser.addListener("endstylesheet", function() {
if (count > 4095) {
reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.", 0, 0, rule);
}
});
}
});
/*
* Rule: Avoid new-line characters in selectors.
*/
CSSLint.addRule({
// rule information
id: "selector-newline",
name: "Disallow new-line characters in selectors",
desc: "New-line characters in selectors are usually a forgotten comma and not a descendant combinator.",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
function startRule(event) {
var i, len, selector, p, n, pLen, part, part2, type, currentLine, nextLine,
selectors = event.selectors;
for (i = 0, len = selectors.length; i < len; i++) {
selector = selectors[i];
for (p = 0, pLen = selector.parts.length; p < pLen; p++) {
for (n = p + 1; n < pLen; n++) {
part = selector.parts[p];
part2 = selector.parts[n];
type = part.type;
currentLine = part.line;
nextLine = part2.line;
if (type === "descendant" && nextLine > currentLine) {
reporter.report("newline character found in selector (forgot a comma?)", currentLine, selectors[i].parts[0].col, rule);
}
}
}
}
}
parser.addListener("startrule", startRule);
}
});
/*
* Rule: Use shorthand properties where possible.
*
*/
CSSLint.addRule({
// rule information
id: "shorthand",
name: "Require shorthand properties",
desc: "Use shorthand properties where possible.",
url: "https://github.com/CSSLint/csslint/wiki/Require-shorthand-properties",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
prop, i, len,
propertiesToCheck = {},
properties,
mapping = {
"margin": [
"margin-top",
"margin-bottom",
"margin-left",
"margin-right"
],
"padding": [
"padding-top",
"padding-bottom",
"padding-left",
"padding-right"
]
};
// initialize propertiesToCheck
for (prop in mapping) {
if (mapping.hasOwnProperty(prop)) {
for (i=0, len=mapping[prop].length; i < len; i++) {
propertiesToCheck[mapping[prop][i]] = prop;
}
}
}
function startRule() {
properties = {};
}
// event handler for end of rules
function endRule(event) {
var prop, i, len, total;
// check which properties this rule has
for (prop in mapping) {
if (mapping.hasOwnProperty(prop)) {
total=0;
for (i=0, len=mapping[prop].length; i < len; i++) {
total += properties[mapping[prop][i]] ? 1 : 0;
}
if (total === mapping[prop].length) {
reporter.report("The properties " + mapping[prop].join(", ") + " can be replaced by " + prop + ".", event.line, event.col, rule);
}
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
// check for use of "font-size"
parser.addListener("property", function(event) {
var name = event.property.toString().toLowerCase();
if (propertiesToCheck[name]) {
properties[name] = 1;
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
}
});
/*
* Rule: Don't use properties with a star prefix.
*
*/
CSSLint.addRule({
// rule information
id: "star-property-hack",
name: "Disallow properties with a star prefix",
desc: "Checks for the star property hack (targets IE6/7)",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-star-hack",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
// check if property name starts with "*"
parser.addListener("property", function(event) {
var property = event.property;
if (property.hack === "*") {
reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
}
});
}
});
/*
* Rule: Don't use text-indent for image replacement if you need to support rtl.
*
*/
CSSLint.addRule({
// rule information
id: "text-indent",
name: "Disallow negative text-indent",
desc: "Checks for text indent less than -99px",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-negative-text-indent",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
textIndent,
direction;
function startRule() {
textIndent = false;
direction = "inherit";
}
// event handler for end of rules
function endRule() {
if (textIndent && direction !== "ltr") {
reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
// check for use of "font-size"
parser.addListener("property", function(event) {
var name = event.property.toString().toLowerCase(),
value = event.value;
if (name === "text-indent" && value.parts[0].value < -99) {
textIndent = event.property;
} else if (name === "direction" && value.toString() === "ltr") {
direction = "ltr";
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
}
});
/*
* Rule: Don't use properties with a underscore prefix.
*
*/
CSSLint.addRule({
// rule information
id: "underscore-property-hack",
name: "Disallow properties with an underscore prefix",
desc: "Checks for the underscore property hack (targets IE6)",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-underscore-hack",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
// check if property name starts with "_"
parser.addListener("property", function(event) {
var property = event.property;
if (property.hack === "_") {
reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
}
});
}
});
/*
* Rule: Headings (h1-h6) should be defined only once.
*/
CSSLint.addRule({
// rule information
id: "unique-headings",
name: "Headings should only be defined once",
desc: "Headings should be defined only once.",
url: "https://github.com/CSSLint/csslint/wiki/Headings-should-only-be-defined-once",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
var headings = {
h1: 0,
h2: 0,
h3: 0,
h4: 0,
h5: 0,
h6: 0
};
parser.addListener("startrule", function(event) {
var selectors = event.selectors,
selector,
part,
pseudo,
i, j;
for (i=0; i < selectors.length; i++) {
selector = selectors[i];
part = selector.parts[selector.parts.length-1];
if (part.elementName && /(h[1-6])/i.test(part.elementName.toString())) {
for (j=0; j < part.modifiers.length; j++) {
if (part.modifiers[j].type === "pseudo") {
pseudo = true;
break;
}
}
if (!pseudo) {
headings[RegExp.$1]++;
if (headings[RegExp.$1] > 1) {
reporter.report("Heading (" + part.elementName + ") has already been defined.", part.line, part.col, rule);
}
}
}
}
});
parser.addListener("endstylesheet", function() {
var prop,
messages = [];
for (prop in headings) {
if (headings.hasOwnProperty(prop)) {
if (headings[prop] > 1) {
messages.push(headings[prop] + " " + prop + "s");
}
}
}
if (messages.length) {
reporter.rollupWarn("You have " + messages.join(", ") + " defined in this stylesheet.", rule);
}
});
}
});
/*
* Rule: Don't use universal selector because it's slow.
*/
CSSLint.addRule({
// rule information
id: "universal-selector",
name: "Disallow universal selector",
desc: "The universal selector (*) is known to be slow.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-universal-selector",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("startrule", function(event) {
var selectors = event.selectors,
selector,
part,
i;
for (i=0; i < selectors.length; i++) {
selector = selectors[i];
part = selector.parts[selector.parts.length-1];
if (part.elementName === "*") {
reporter.report(rule.desc, part.line, part.col, rule);
}
}
});
}
});
/*
* Rule: Don't use unqualified attribute selectors because they're just like universal selectors.
*/
CSSLint.addRule({
// rule information
id: "unqualified-attributes",
name: "Disallow unqualified attribute selectors",
desc: "Unqualified attribute selectors are known to be slow.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-unqualified-attribute-selectors",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
parser.addListener("startrule", function(event) {
var selectors = event.selectors,
selectorContainsClassOrId = false,
selector,
part,
modifier,
i, k;
for (i=0; i < selectors.length; i++) {
selector = selectors[i];
part = selector.parts[selector.parts.length-1];
if (part.type === parser.SELECTOR_PART_TYPE) {
for (k=0; k < part.modifiers.length; k++) {
modifier = part.modifiers[k];
if (modifier.type === "class" || modifier.type === "id") {
selectorContainsClassOrId = true;
break;
}
}
if (!selectorContainsClassOrId) {
for (k=0; k < part.modifiers.length; k++) {
modifier = part.modifiers[k];
if (modifier.type === "attribute" && (!part.elementName || part.elementName === "*")) {
reporter.report(rule.desc, part.line, part.col, rule);
}
}
}
}
}
});
}
});
/*
* Rule: When using a vendor-prefixed property, make sure to
* include the standard one.
*/
CSSLint.addRule({
// rule information
id: "vendor-prefix",
name: "Require standard property with vendor prefix",
desc: "When using a vendor-prefixed property, make sure to include the standard one.",
url: "https://github.com/CSSLint/csslint/wiki/Require-standard-property-with-vendor-prefix",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this,
properties,
num,
propertiesToCheck = {
"-webkit-border-radius": "border-radius",
"-webkit-border-top-left-radius": "border-top-left-radius",
"-webkit-border-top-right-radius": "border-top-right-radius",
"-webkit-border-bottom-left-radius": "border-bottom-left-radius",
"-webkit-border-bottom-right-radius": "border-bottom-right-radius",
"-o-border-radius": "border-radius",
"-o-border-top-left-radius": "border-top-left-radius",
"-o-border-top-right-radius": "border-top-right-radius",
"-o-border-bottom-left-radius": "border-bottom-left-radius",
"-o-border-bottom-right-radius": "border-bottom-right-radius",
"-moz-border-radius": "border-radius",
"-moz-border-radius-topleft": "border-top-left-radius",
"-moz-border-radius-topright": "border-top-right-radius",
"-moz-border-radius-bottomleft": "border-bottom-left-radius",
"-moz-border-radius-bottomright": "border-bottom-right-radius",
"-moz-column-count": "column-count",
"-webkit-column-count": "column-count",
"-moz-column-gap": "column-gap",
"-webkit-column-gap": "column-gap",
"-moz-column-rule": "column-rule",
"-webkit-column-rule": "column-rule",
"-moz-column-rule-style": "column-rule-style",
"-webkit-column-rule-style": "column-rule-style",
"-moz-column-rule-color": "column-rule-color",
"-webkit-column-rule-color": "column-rule-color",
"-moz-column-rule-width": "column-rule-width",
"-webkit-column-rule-width": "column-rule-width",
"-moz-column-width": "column-width",
"-webkit-column-width": "column-width",
"-webkit-column-span": "column-span",
"-webkit-columns": "columns",
"-moz-box-shadow": "box-shadow",
"-webkit-box-shadow": "box-shadow",
"-moz-transform": "transform",
"-webkit-transform": "transform",
"-o-transform": "transform",
"-ms-transform": "transform",
"-moz-transform-origin": "transform-origin",
"-webkit-transform-origin": "transform-origin",
"-o-transform-origin": "transform-origin",
"-ms-transform-origin": "transform-origin",
"-moz-box-sizing": "box-sizing",
"-webkit-box-sizing": "box-sizing"
};
// event handler for beginning of rules
function startRule() {
properties = {};
num = 1;
}
// event handler for end of rules
function endRule() {
var prop,
i,
len,
needed,
actual,
needsStandard = [];
for (prop in properties) {
if (propertiesToCheck[prop]) {
needsStandard.push({
actual: prop,
needed: propertiesToCheck[prop]
});
}
}
for (i=0, len=needsStandard.length; i < len; i++) {
needed = needsStandard[i].needed;
actual = needsStandard[i].actual;
if (!properties[needed]) {
reporter.report("Missing standard property '" + needed + "' to go along with '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
} else {
// make sure standard property is last
if (properties[needed][0].pos < properties[actual][0].pos) {
reporter.report("Standard property '" + needed + "' should come after vendor-prefixed property '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
}
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("startviewport", startRule);
parser.addListener("property", function(event) {
var name = event.property.text.toLowerCase();
if (!properties[name]) {
properties[name] = [];
}
properties[name].push({
name: event.property,
value: event.value,
pos: num++
});
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endpage", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endkeyframerule", endRule);
parser.addListener("endviewport", endRule);
}
});
/*
* Rule: You don't need to specify units when a value is 0.
*/
CSSLint.addRule({
// rule information
id: "zero-units",
name: "Disallow units for 0 values",
desc: "You don't need to specify units when a value is 0.",
url: "https://github.com/CSSLint/csslint/wiki/Disallow-units-for-zero-values",
browsers: "All",
// initialization
init: function(parser, reporter) {
"use strict";
var rule = this;
// count how many times "float" is used
parser.addListener("property", function(event) {
var parts = event.value.parts,
i = 0,
len = parts.length;
while (i < len) {
if ((parts[i].units || parts[i].type === "percentage") && parts[i].value === 0 && parts[i].type !== "time") {
reporter.report("Values of 0 shouldn't have units specified.", parts[i].line, parts[i].col, rule);
}
i++;
}
});
}
});
(function() {
"use strict";
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - & is the escape sequence for &
* - < is the escape sequence for <
* - > is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var xmlEscape = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/["&><]/g, function(match) {
switch (match) {
case "\"":
return """;
case "&":
return "&";
case "<":
return "<";
case ">":
return ">";
}
});
};
CSSLint.addFormatter({
// format information
id: "checkstyle-xml",
name: "Checkstyle XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function() {
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function() {
return "</checkstyle>";
},
/**
* Returns message when there is a file read error.
* @param {String} filename The name of the file that caused the error.
* @param {String} message The error message
* @return {String} The error message.
*/
readError: function(filename, message) {
return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename/*, options*/) {
var messages = results.messages,
output = [];
/**
* Generate a source string for a rule.
* Checkstyle source strings usually resemble Java class names e.g
* net.csslint.SomeRuleName
* @param {Object} rule
* @return rule source as {String}
*/
var generateSource = function(rule) {
if (!rule || !("name" in rule)) {
return "";
}
return "net.csslint." + rule.name.replace(/\s/g, "");
};
if (messages.length > 0) {
output.push("<file name=\""+filename+"\">");
CSSLint.Util.forEach(messages, function (message) {
// ignore rollups for now
if (!message.rollup) {
output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
" message=\"" + xmlEscape(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
}
});
output.push("</file>");
}
return output.join("");
}
});
}());
CSSLint.addFormatter({
// format information
id: "compact",
name: "Compact, 'porcelain' format",
/**
* Return content to be printed before all file results.
* @return {String} to prepend before all results
*/
startFormat: function() {
"use strict";
return "";
},
/**
* Return content to be printed after all file results.
* @return {String} to append after all results
*/
endFormat: function() {
"use strict";
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (Optional) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
"use strict";
var messages = results.messages,
output = "";
options = options || {};
/**
* Capitalize and return given string.
* @param str {String} to capitalize
* @return {String} capitalized
*/
var capitalize = function(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
};
if (messages.length === 0) {
return options.quiet ? "" : filename + ": Lint Free!";
}
CSSLint.Util.forEach(messages, function(message) {
if (message.rollup) {
output += filename + ": " + capitalize(message.type) + " - " + message.message + " (" + message.rule.id + ")\n";
} else {
output += filename + ": line " + message.line +
", col " + message.col + ", " + capitalize(message.type) + " - " + message.message + " (" + message.rule.id + ")\n";
}
});
return output;
}
});
CSSLint.addFormatter({
// format information
id: "csslint-xml",
name: "CSSLint XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function() {
"use strict";
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function() {
"use strict";
return "</csslint>";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename/*, options*/) {
"use strict";
var messages = results.messages,
output = [];
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - & is the escape sequence for &
* - < is the escape sequence for <
* - > is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var escapeSpecialCharacters = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/"/g, "'").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
};
if (messages.length > 0) {
output.push("<file name=\""+filename+"\">");
CSSLint.Util.forEach(messages, function (message) {
if (message.rollup) {
output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
} else {
output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
}
});
output.push("</file>");
}
return output.join("");
}
});
/* globals JSON: true */
CSSLint.addFormatter({
// format information
id: "json",
name: "JSON",
/**
* Return content to be printed before all file results.
* @return {String} to prepend before all results
*/
startFormat: function() {
"use strict";
this.json = [];
return "";
},
/**
* Return content to be printed after all file results.
* @return {String} to append after all results
*/
endFormat: function() {
"use strict";
var ret = "";
if (this.json.length > 0) {
if (this.json.length === 1) {
ret = JSON.stringify(this.json[0]);
} else {
ret = JSON.stringify(this.json);
}
}
return ret;
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path (Unused)
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
"use strict";
if (results.messages.length > 0 || !options.quiet) {
this.json.push({
filename: filename,
messages: results.messages,
stats: results.stats
});
}
return "";
}
});
CSSLint.addFormatter({
// format information
id: "junit-xml",
name: "JUNIT XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function() {
"use strict";
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites>";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function() {
"use strict";
return "</testsuites>";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename/*, options*/) {
"use strict";
var messages = results.messages,
output = [],
tests = {
"error": 0,
"failure": 0
};
/**
* Generate a source string for a rule.
* JUNIT source strings usually resemble Java class names e.g
* net.csslint.SomeRuleName
* @param {Object} rule
* @return rule source as {String}
*/
var generateSource = function(rule) {
if (!rule || !("name" in rule)) {
return "";
}
return "net.csslint." + rule.name.replace(/\s/g, "");
};
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - < is the escape sequence for <
* - > is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var escapeSpecialCharacters = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/"/g, "'").replace(/</g, "<").replace(/>/g, ">");
};
if (messages.length > 0) {
messages.forEach(function (message) {
// since junit has no warning class
// all issues as errors
var type = message.type === "warning" ? "error" : message.type;
// ignore rollups for now
if (!message.rollup) {
// build the test case separately, once joined
// we'll add it to a custom array filtered by type
output.push("<testcase time=\"0\" name=\"" + generateSource(message.rule) + "\">");
output.push("<" + type + " message=\"" + escapeSpecialCharacters(message.message) + "\"><![CDATA[" + message.line + ":" + message.col + ":" + escapeSpecialCharacters(message.evidence) + "]]></" + type + ">");
output.push("</testcase>");
tests[type] += 1;
}
});
output.unshift("<testsuite time=\"0\" tests=\"" + messages.length + "\" skipped=\"0\" errors=\"" + tests.error + "\" failures=\"" + tests.failure + "\" package=\"net.csslint\" name=\"" + filename + "\">");
output.push("</testsuite>");
}
return output.join("");
}
});
CSSLint.addFormatter({
// format information
id: "lint-xml",
name: "Lint XML format",
/**
* Return opening root XML tag.
* @return {String} to prepend before all results
*/
startFormat: function() {
"use strict";
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>";
},
/**
* Return closing root XML tag.
* @return {String} to append after all results
*/
endFormat: function() {
"use strict";
return "</lint>";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (UNUSED for now) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename/*, options*/) {
"use strict";
var messages = results.messages,
output = [];
/**
* Replace special characters before write to output.
*
* Rules:
* - single quotes is the escape sequence for double-quotes
* - & is the escape sequence for &
* - < is the escape sequence for <
* - > is the escape sequence for >
*
* @param {String} message to escape
* @return escaped message as {String}
*/
var escapeSpecialCharacters = function(str) {
if (!str || str.constructor !== String) {
return "";
}
return str.replace(/"/g, "'").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
};
if (messages.length > 0) {
output.push("<file name=\""+filename+"\">");
CSSLint.Util.forEach(messages, function (message) {
if (message.rollup) {
output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
} else {
var rule = "";
if (message.rule && message.rule.id) {
rule = "rule=\"" + escapeSpecialCharacters(message.rule.id) + "\" ";
}
output.push("<issue " + rule + "line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
}
});
output.push("</file>");
}
return output.join("");
}
});
CSSLint.addFormatter({
// format information
id: "text",
name: "Plain Text",
/**
* Return content to be printed before all file results.
* @return {String} to prepend before all results
*/
startFormat: function() {
"use strict";
return "";
},
/**
* Return content to be printed after all file results.
* @return {String} to append after all results
*/
endFormat: function() {
"use strict";
return "";
},
/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (Optional) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
"use strict";
var messages = results.messages,
output = "";
options = options || {};
if (messages.length === 0) {
return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + ".";
}
output = "\n\ncsslint: There ";
if (messages.length === 1) {
output += "is 1 problem";
} else {
output += "are " + messages.length + " problems";
}
output += " in " + filename + ".";
var pos = filename.lastIndexOf("/"),
shortFilename = filename;
if (pos === -1) {
pos = filename.lastIndexOf("\\");
}
if (pos > -1) {
shortFilename = filename.substring(pos+1);
}
CSSLint.Util.forEach(messages, function (message, i) {
output = output + "\n\n" + shortFilename;
if (message.rollup) {
output += "\n" + (i+1) + ": " + message.type;
output += "\n" + message.message;
} else {
output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col;
output += "\n" + message.message;
output += "\n" + message.evidence;
}
});
return output;
}
});
return CSSLint;
})();/**
* @preserve JSizes - JQuery plugin v0.33
*
* Licensed under the revised BSD License.
* Copyright 2008-2010 Bram Stein
* All rights reserved.
*/
/*global jQuery*/
(function ($) {
'use strict';
var num = function (value) {
return parseInt(value, 10) || 0;
};
/**
* Sets or gets the values for min-width, min-height, max-width
* and max-height.
*/
$.each(['min', 'max'], function (i, name) {
$.fn[name + 'Size'] = function (value) {
var width, height;
if (value) {
if (value.width !== undefined) {
this.css(name + '-width', value.width);
}
if (value.height !== undefined) {
this.css(name + '-height', value.height);
}
} else {
width = this.css(name + '-width');
height = this.css(name + '-height');
// Apparently:
// * Opera returns -1px instead of none
// * IE6 returns undefined instead of none
return {'width': (name === 'max' && (width === undefined || width === 'none' || num(width) === -1) && Number.MAX_VALUE) || num(width),
'height': (name === 'max' && (height === undefined || height === 'none' || num(height) === -1) && Number.MAX_VALUE) || num(height)};
}
return this;
};
});
/**
* Returns whether or not an element is visible.
*/
$.fn.isVisible = function () {
return this.is(':visible');
};
/**
* Sets or gets the values for border, margin and padding.
*/
$.each(['border', 'margin', 'padding'], function (i, name) {
$.fn[name] = function (value) {
if (value) {
if (value.top !== undefined) {
this.css(name + '-top' + (name === 'border' ? '-width' : ''), value.top);
}
if (value.bottom !== undefined) {
this.css(name + '-bottom' + (name === 'border' ? '-width' : ''), value.bottom);
}
if (value.left !== undefined) {
this.css(name + '-left' + (name === 'border' ? '-width' : ''), value.left);
}
if (value.right !== undefined) {
this.css(name + '-right' + (name === 'border' ? '-width' : ''), value.right);
}
} else {
return {top: num(this.css(name + '-top' + (name === 'border' ? '-width' : ''))),
bottom: num(this.css(name + '-bottom' + (name === 'border' ? '-width' : ''))),
left: num(this.css(name + '-left' + (name === 'border' ? '-width' : ''))),
right: num(this.css(name + '-right' + (name === 'border' ? '-width' : '')))};
}
return this;
};
});
}(jQuery));/* globals jQuery, _, socssOptions, Backbone, CodeMirror, console, cssjs, wp */
( function ( $, _, socssOptions ) {
var socss = {
model: {},
collection: {},
view: {},
fn: {}
};
window.socss = socss;
socss.model.CustomCssModel = Backbone.Model.extend( {
defaults: {
postId: null,
postTitle: null,
css: null,
},
urlRoot: socssOptions.postCssUrlRoot,
url: function () {
return this.urlRoot + '&postId=' + this.get( 'postId' );
}
} );
socss.model.CustomCssCollection = Backbone.Collection.extend( {
model: socss.model.CustomCssModel,
modelId: function( attrs ) {
return attrs.postId;
},
} );
socss.model.CSSEditorModel = Backbone.Model.extend( {
defaults: {
customCssPosts: null,
}
} );
/**
* The toolbar view
*/
socss.view.toolbar = Backbone.View.extend( {
button: _.template( '<li><a href="#<%= action %>" class="toolbar-button socss-button"><%= text %></a></li>' ),
events: {
'click .socss-button:not(.save)': 'triggerEvent',
},
triggerEvent: function ( event ) {
event.preventDefault();
var $target = $( event.currentTarget );
$target.trigger( 'blur' );
var value = $target.attr( 'href' ).replace( '#', '' );
this.$el.trigger( 'click_' + value );
},
addButton: function ( text, action ) {
var button = $( this.button( { text: text, action: action } ) )
.appendTo( this.$( '.toolbar-function-buttons .toolbar-buttons' ) );
return button;
},
} );
/**
* The editor view, which handles codemirror stuff
*
* model: socss.model.CSSEditorModel
*
*/
socss.view.editor = Backbone.View.extend( {
codeMirror: null,
snippets: null,
toolbar: null,
visualProperties: null,
inspector: null,
cssSelectors: [],
initValue: null,
events: {
'click_expand .custom-css-toolbar': 'toggleExpand',
'click_visual .custom-css-toolbar': 'showVisualEditor',
'click .socss-button.save': 'save',
'submit': 'onSubmit',
},
initialize: function ( options ) {
this.listenTo( this.model, 'change:selectedPost', this.getSelectedPostCss );
this.getSelectedPostCss().then( function () {
if ( options.openVisualEditor ) {
this.showVisualEditor();
}
}.bind( this ) );
},
save: function () {
socss.save( this );
},
getSelectedPostCss: function () {
var selectedPost = this.model.get( 'selectedPost' );
var promise;
if ( selectedPost && ! selectedPost.has( 'css' ) ) {
promise = selectedPost.fetch();
} else {
promise = new $.Deferred().resolve();
}
return promise.then( this.render.bind( this ) );
},
render: function () {
var selectedPost = this.model.get( 'selectedPost' );
if ( selectedPost && !selectedPost.has( 'css' ) ) {
return this;
}
if ( !this.codeMirror ) {
this.setupEditor();
}
if ( ! this.toolbar ) {
this.toolbar = new socss.view.toolbar( {
el: this.$( '.custom-css-toolbar' ),
model: this.model,
} );
this.toolbar.render();
}
if ( !this.visualProperties ) {
this.visualProperties = new socss.view.properties( {
editor: this,
el: $( '#so-custom-css-properties' )
} );
this.visualProperties.render();
}
if ( !this.preview ) {
this.preview = new socss.view.preview( {
editor: this,
model: this.model,
el: this.$( '.custom-css-preview' ),
initURL: socssOptions.homeURL,
} );
this.preview.render();
}
if ( selectedPost ) {
this.codeMirror.setValue( selectedPost.get( 'css' ) );
this.codeMirror.clearHistory();
}
return this;
},
/**
* Do the initial setup of the CodeMirror editor
*/
setupEditor: function () {
// Setup the Codemirror instance
var $textArea = this.$( 'textarea.css-editor' );
this.initValue = $textArea.val();
// Pad with empty lines so the editor takes up all the white space. To try make sure user gets copy/paste
// options in context menu.
var newlineMatches = this.initValue.match( /\n/gm );
var lineCount = newlineMatches ? newlineMatches.length + 1 : 1;
var paddedValue = this.initValue;
$textArea.val( paddedValue );
var codeMirrorSettings = {
tabSize: 2,
lineNumbers: true,
mode: 'css',
theme: $textArea.data( 'theme' ),
inputStyle: 'contenteditable', //necessary to allow context menu (right click) copy/paste etc.
gutters: [
"CodeMirror-lint-markers"
],
lint: true,
search: true,
dialog: true,
annotateScrollbar: true,
extraKeys: {
'Ctrl-F': 'findPersistent',
'Alt-G': 'jumpToLine',
},
}
if ( typeof wp.codeEditor != "undefined" ) {
codeMirrorSettings = _.extend(
wp.codeEditor.defaultSettings.codemirror,
codeMirrorSettings
);
this.codeMirror = wp.codeEditor.initialize( $textArea.get( 0 ), codeMirrorSettings ).codemirror;
} else {
this.registerCodeMirrorAutocomplete();
this.codeMirror = CodeMirror.fromTextArea( $textArea.get( 0 ), codeMirrorSettings );
this.setupCodeMirrorExtensions();
}
var editor = this.codeMirror;
$( '#so_css_editor_theme' ).on( 'change', function() {
if ( $( this ).val() == 1 ) {
editor.setOption( 'theme', 'neat' );
} else {
editor.setOption( 'theme', 'ambiance' );
}
} );
this.codeMirror.on( 'change', function ( cm, change ) {
var selectedPost = this.model.get( 'selectedPost' );
if ( selectedPost && selectedPost.get( 'css' ) !== cm.getValue().trim() ) {
selectedPost.set( 'css', cm.getValue().trim() );
}
}.bind( this ) );
// Make sure the user doesn't leave without saving
$( window ).on( 'beforeunload', function () {
var editorValue = this.codeMirror.getValue().trim();
if ( editorValue !== this.initValue ) {
return socssOptions.loc.leave;
}
}.bind( this ) );
// Set the container to visible overflow once the editor is setup
this.$el.find( '.custom-css-container' ).css( 'overflow', 'visible' );
this.scaleEditor();
// Scale the editor whenever the window is resized
$( window ).on( 'resize', function () {
this.scaleEditor();
}.bind( this ) );
},
onSubmit: function () {
this.initValue = this.codeMirror.getValue().trim();
},
/**
* Register the autocomplete helper. Based on css-hint.js in the codemirror addon folder.
*/
registerCodeMirrorAutocomplete: function () {
var pseudoClasses = {
link: 1, visited: 1, active: 1, hover: 1, focus: 1,
"first-letter": 1, "first-line": 1, "first-child": 1,
before: 1, after: 1, lang: 1
};
CodeMirror.registerHelper( "hint", "css", function ( cm ) {
var cur = cm.getCursor(), token = cm.getTokenAt( cur );
var inner = CodeMirror.innerMode( cm.getMode(), token.state );
if ( inner.mode.name !== "css" ) {
return;
}
if ( token.type === "keyword" && "!important".indexOf( token.string ) === 0 ) {
return {
list: [ "!important" ], from: CodeMirror.Pos( cur.line, token.start ),
to: CodeMirror.Pos( cur.line, token.end )
};
}
var start = token.start, end = cur.ch, word = token.string.slice( 0, end - start );
if ( /[^\w$_-]/.test( word ) ) {
word = "";
start = end = cur.ch;
}
var spec = CodeMirror.resolveMode( "text/css" );
var result = [];
function add( keywords ) {
for ( var name in keywords ) {
if ( !word || name.lastIndexOf( word, 0 ) === 0 ) {
result.push( name );
}
}
}
var st = inner.state.state;
if ( st === 'top' ) {
// We're going to autocomplete the selector using our own set of rules
var line = cm.getLine( cur.line ).trim();
var selectors = this.cssSelectors;
for ( var i = 0; i < selectors.length; i++ ) {
if ( selectors[ i ].selector.indexOf( line ) !== -1 ) {
result.push( selectors[ i ].selector );
}
}
if ( result.length ) {
return {
list: result,
from: CodeMirror.Pos( cur.line, 0 ),
to: CodeMirror.Pos( cur.line, end )
};
}
}
else {
if ( st === "pseudo" || token.type === "variable-3" ) {
add( pseudoClasses );
}
else if ( st === "block" || st === "maybeprop" ) {
add( spec.propertyKeywords );
}
else if ( st === "prop" || st === "parens" || st === "at" || st === "params" ) {
add( spec.valueKeywords );
add( spec.colorKeywords );
}
else if ( st === "media" || st === "media_parens" ) {
add( spec.mediaTypes );
add( spec.mediaFeatures );
}
if ( result.length ) {
return {
list: result,
from: CodeMirror.Pos( cur.line, start ),
to: CodeMirror.Pos( cur.line, end )
};
}
}
}.bind( this ) );
},
setupCodeMirrorExtensions: function () {
this.codeMirror.on( 'cursorActivity', function ( cm ) {
var cur = cm.getCursor(), token = cm.getTokenAt( cur );
var inner = CodeMirror.innerMode( cm.getMode(), token.state );
// If we have a qualifier selected, then highlight that in the preview
if ( token.type === 'qualifier' || token.type === 'tag' || token.type === 'builtin' ) {
var line = cm.getLine( cur.line );
var selector = line.substring( 0, token.end );
this.preview.highlight( selector );
}
else {
this.preview.clearHighlight();
}
}.bind( this ) );
if ( typeof CodeMirror.showHint == 'function' ) {
// This sets up automatic autocompletion at all times
this.codeMirror.on( 'keyup', function ( cm, e ) {
if (
( e.keyCode >= 65 && e.keyCode <= 90 ) ||
( e.keyCode === 189 && !e.shiftKey ) ||
( e.keyCode === 190 && !e.shiftKey ) ||
( e.keyCode === 51 && e.shiftKey ) ||
( e.keyCode === 189 && e.shiftKey )
) {
cm.showHint( {
completeSingle: false
} );
}
} );
}
},
/**
* Scale the size of the editor depending on whether it's expanded or not
*/
scaleEditor: function () {
var windowHeight = $( window ).outerHeight();
var areaHeight;
if ( this.$el.hasClass( 'expanded' ) ) {
// If we're in the expanded view, then resize the editor
this.$el.find( '.CodeMirror-scroll' ).css( 'max-height', '' );
areaHeight = windowHeight - this.$( '.custom-css-toolbar' ).outerHeight();
this.codeMirror.setSize( '100%', areaHeight );
this.$el.find( '.CodeMirror-scroll' ).css( 'height', '100%' );
}
else {
// Attempt to calculate approximate space available for editor when not expanded.
var $form = $( '#so-custom-css-form' );
var otherEltsHeight = $( '#wpadminbar' ).outerHeight( true ) +
$( '#siteorigin-custom-css' ).find( '> h2' ).outerHeight( true ) +
$form.find( '> .custom-css-toolbar' ).outerHeight( true ) +
$form.find( '> .so-css-footer' ).outerHeight( true ) +
parseFloat( $( '#wpbody-content' ).css( 'padding-bottom' ) );
areaHeight = windowHeight - otherEltsHeight;
// The container has a min-height of 300px so we need to ensure the areaHeight is at least that large.
if ( areaHeight < 300 ) {
areaHeight = 300;
}
this.codeMirror.setSize( '100%', 'auto' );
this.$el.find( '.CodeMirror-scroll' ).css( 'height', areaHeight + 'px' );
}
this.$el.find( '.CodeMirror-code' ).css( 'height', areaHeight + 'px' );
},
/**
* Check if the editor is in expanded mode
* @returns bool
*/
isExpanded: function () {
return this.$el.hasClass( 'expanded' );
},
/**
* Toggle if this is expanded or not
*/
toggleExpand: function ( e ) {
$( '.editor-expand' ).attr( 'title', $( '.so-css-icon-' + ( this.isExpanded() ? 'expand' : 'compress ') ).attr( 'title' ) );
this.$el.toggleClass( 'expanded' );
this.scaleEditor();
},
/**
* Set the expanded state of the editor
* @param expanded
*/
setExpand: function ( expanded ) {
if ( expanded ) {
this.$el.addClass( 'expanded' );
}
else {
this.$el.removeClass( 'expanded' );
}
this.scaleEditor();
},
/**
* Show the visual editor view.
*/
showVisualEditor: function () {
this.visualProperties.loadCSS( this.codeMirror.getValue().trim() );
this.visualProperties.show();
},
/**
* Set the snippets available to this editor
*/
setSnippets: function ( snippets ) {
if ( !_.isEmpty( snippets ) ) {
this.snippets = new socss.view.snippets( {
snippets: snippets
} );
this.snippets.editor = this;
this.snippets.render();
this.toolbar.addButton( 'Snippets', 'snippets' );
this.toolbar.on( 'click_snippets', function () {
this.snippets.show();
}.bind( this ) );
}
},
/**
* Add some CSS to the editor.
* @param css
*/
addCode: function ( css ) {
var editor = this.codeMirror;
var before_css = '';
if ( editor.doc.lineCount() === 1 && editor.doc.getLine( editor.doc.lastLine() ).length === 0 ) {
before_css = "";
}
else if ( editor.doc.getLine( editor.doc.lastLine() ).length === 0 ) {
before_css = "\n";
}
else {
before_css = "\n\n";
}
// Now insert the code in the editor
editor.doc.setCursor(
editor.doc.lastLine(),
editor.doc.getLine( editor.doc.lastLine() ).length
);
editor.doc.replaceSelection( before_css + css );
},
addEmptySelector: function ( selector ) {
this.addCode( selector + " {\n \n}" );
},
/**
* Sets the inspector view that's being used by the editor
*/
setInspector: function ( inspector ) {
this.inspector = inspector;
this.cssSelectors = inspector.pageSelectors;
// A selector is clicked in the inspector
inspector.on( 'click_selector', function ( selector ) {
if ( this.visualProperties.isVisible() ) {
this.visualProperties.addSelector( selector );
}
else {
this.addEmptySelector( selector );
}
}.bind( this ) );
// A property is clicked in the inspector
inspector.on( 'click_property', function ( property ) {
if ( !this.visualProperties.isVisible() ) {
this.codeMirror.replaceSelection( property + ";\n " );
}
}.bind( this ) );
inspector.on( 'set_active_element', function ( el, selectors ) {
if ( this.visualProperties.isVisible() && selectors.length ) {
this.visualProperties.addSelector( selectors[ 0 ].selector );
}
}.bind( this ) );
}
} );
/**
* The preview.
*/
socss.view.preview = Backbone.View.extend( {
template: _.template( $( '#template-preview-window' ).html() ),
editor: null,
originalUri: null,
currentUri: null,
events: {
'mouseleave #preview-iframe': 'clearHighlight',
'keydown #preview-navigator input[type="text"]': 'reloadPreview',
},
initialize: function ( attr ) {
this.editor = attr.editor;
this.listenTo( this.model, 'change:selectedPost', this.render.bind( this ) );
this.originalUri = new URI( attr.initURL );
this.currentUri = new URI( attr.initURL );
this.editor.codeMirror.on( 'change', function ( cm, c ) {
this.updatePreviewCss();
}.bind( this ) );
},
render: function () {
var selectedPost = this.model.get( 'selectedPost' );
if ( selectedPost && !selectedPost.has( 'postUrl' ) ) {
selectedPost.fetch().then( this.render.bind( this ) );
return this;
}
this.$el.html( this.template() );
if ( selectedPost ) {
this.currentUri = new URI( selectedPost.get( 'postUrl' ) );
}
this.currentUri.removeQuery( 'so_css_preview', 1 );
this.$( '#preview-navigator input' ).val( this.currentUri.toString() );
this.currentUri.addQuery( 'so_css_preview', 1 );
this.$( '#preview-iframe' )
.attr( 'src', this.currentUri.toString() )
// 'load' event doesn't bubble so can't be used in the events hash
.on( 'load', this.initPreview.bind( this ) );
},
initPreview: function () {
var $$ = this.$( '#preview-iframe' );
// Update the current URI with the iframe URI
this.currentUri = new URI( $$.contents().get( 0 ).location.href );
this.currentUri.removeQuery( 'so_css_preview' );
this.$( '#preview-navigator input' ).val( this.currentUri.toString() );
this.currentUri.addQuery( 'so_css_preview', 1 );
var wcCheck = $$.contents().find( '.single-product' ).length;
$$.contents().find( 'a' ).each( function () {
var link = $( this );
var href = link.attr( 'href' );
if ( href === undefined || ( wcCheck && link.parents( '.wc-tabs' ).length ) ) {
return true;
}
var firstSeperator = ( href.indexOf( '?' ) === -1 ? '?' : '&' );
link.attr( 'href', href + firstSeperator + 'so_css_preview=1' );
} );
this.updatePreviewCss();
},
reloadPreview: function ( e ) {
var $$ = this.$( '#preview-navigator input[type="text"]' );
if ( e.keyCode === 13 ) {
e.preventDefault();
var newUri = new URI( $$.val() );
// Validate the URI
if (
this.originalUri.host() !== newUri.host() ||
this.originalUri.protocol() !== newUri.protocol()
) {
$$.trigger( 'blur' );
alert( $$.data( 'invalid-uri' ) );
$$.trigger( 'focus' );
}
else {
newUri.addQuery( 'so_css_preview', 1 );
this.$( '#preview-iframe' ).attr( 'src', newUri.toString() );
}
}
},
/**
* Update the preview CSS from the CodeMirror value in the editor
*/
updatePreviewCss: function () {
var preview = this.$( '#preview-iframe' );
if ( preview.length === 0 ) {
return;
}
var head = preview.contents().find( 'head' );
if ( head.find( 'style.siteorigin-custom-css' ).length === 0 ) {
head.append( '<style class="siteorigin-custom-css" type="text/css"></style>' );
}
var style = head.find( 'style.siteorigin-custom-css' );
// Update the CSS after a short delay
var css = this.editor.codeMirror.getValue().trim();
style.html( css );
},
/**
* Highlight all elements with a given selector
*/
highlight: function ( selector ) {
try {
this.editor.inspector.hl.highlight( selector );
}
catch ( err ) {
console.log( 'No inspector to highlight with' );
}
},
/**
* Clear the currently highlighted elements in preview
*/
clearHighlight: function () {
try {
this.editor.inspector.hl.clear();
}
catch ( err ) {
console.log( 'No inspector to highlight with' );
}
}
} );
/**
* The dialog for the snippets browser
*/
socss.view.snippets = Backbone.View.extend( {
template: _.template( $( '#template-snippet-browser' ).html() ),
snippet: _.template( '<li class="snippet"><%- name %></li>' ),
className: 'css-editor-snippet-browser',
snippets: null,
editor: null,
events: {
'click .close': 'hide',
'click .buttons .insert-snippet': 'insertSnippet',
'click .snippet': 'clickSnippet',
},
currentSnippet: null,
initialize: function ( args ) {
this.snippets = args.snippets;
},
render: function () {
this.$el.html( this.template() );
for ( var i = 0; i < this.snippets.length; i++ ) {
$( this.snippet( { name: this.snippets[ i ].Name } ) )
.data( {
'description': this.snippets[ i ].Description,
'css': this.snippets[ i ].css
} )
.appendTo( this.$( 'ul.snippets' ) );
}
// Click on the first one
this.$( '.snippets li.snippet' ).eq( 0 ).trigger( 'click' );
this.attach();
return this;
},
clickSnippet: function ( event ) {
event.preventDefault();
var $$ = $( event.currentTarget );
this.$( '.snippets li.snippet' ).removeClass( 'active' );
$( this ).addClass( 'active' );
this.viewSnippet( {
name: $$.html(),
description: $$.data( 'description' ),
css: $$.data( 'css' )
} );
},
viewSnippet: function ( args ) {
var w = this.$( '.main .snippet-view' );
w.find( '.snippet-title' ).html( args.name );
w.find( '.snippet-description' ).html( args.description );
w.find( '.snippet-code' ).html( args.css );
this.currentSnippet = args;
},
insertSnippet: function () {
var editor = this.editor.codeMirror;
var css = this.currentSnippet.css;
var before_css = '';
if ( editor.doc.lineCount() === 1 && editor.doc.getLine( editor.doc.lastLine() ).length === 0 ) {
before_css = "";
}
else if ( editor.doc.getLine( editor.doc.lastLine() ).length === 0 ) {
before_css = "\n";
}
else {
before_css = "\n\n";
}
// Now insert the code in the editor
editor.doc.setCursor(
editor.doc.lastLine(),
editor.doc.getLine( editor.doc.lastLine() ).length
);
editor.doc.replaceSelection( before_css + css );
this.hide();
},
attach: function () {
this.$el.appendTo( 'body' );
},
show: function () {
this.$el.show();
},
hide: function () {
this.$el.hide();
}
} );
socss.save = function ( view ) {
let saveBtn = $( '#siteorigin-custom-css .save' );
var css;
if ( ! saveBtn.hasClass( 'button-primary-disabled' ) ) {
saveBtn.addClass( 'button-primary-disabled' )
// Which view is the user using?
if ( typeof view.editor != 'undefined' ) {
// Visual.
css = view.editor.codeMirror.getValue().trim();
view.updateMainEditor( true );
} else {
// Expanded.
css = view.codeMirror.getValue().trim();
}
$.post(
socssOptions.ajaxurl,
{
action: 'socss_save_css',
css: css,
},
null,
'html'
).done( function ( response ) {
if ( response.length ) {
// Update was successful. Update revisions list.
$( '.custom-revisions-list' ).html( response );
}
})
.fail( function ( error ) {
// Something went wrong. Output the error message as an alert.
alert( error.responseText );
} )
.always( function () {
saveBtn.removeClass( 'button-primary-disabled' )
} );
}
};
/**
* The visual properties editor
*/
socss.view.properties = Backbone.View.extend( {
tabTemplate: _.template( '<li data-section="<%- id %>"><span class="so-css-icon so-css-icon-<%- icon %>"></span> <%- title %></li>' ),
sectionTemplate: _.template( '<div class="section" data-section="<%- id %>"><table class="fields-table"><tbody></tbody></table></div>' ),
controllerTemplate: _.template( '<tr><th scope="row"><%- title %></th><td></td></tr>' ),
/**
* The controllers for each of the properties
*/
propertyControllers: [],
/**
* The editor view
*/
editor: null,
/**
* The current, raw CSS
*/
css: '',
/**
* Parsed CSS
*/
parsed: {},
/**
* The current active selector
*/
activeSelector: '',
/**
* Was the editor expanded before we went into the property editor
*/
editorExpandedBefore: false,
events: {
'click .close': 'hide',
'click .save': 'save',
'click .section-tabs li': 'onTabClick',
'change .toolbar select': 'onToolbarSelectChange',
},
/**
* Initialize the properties editor with a new model
*/
initialize: function ( options ) {
this.parser = window.css;
this.editor = options.editor;
},
/**
* Render the property editor
*/
render: function () {
// Clean up for potential re-renders
this.$( '.section-tabs' ).empty();
this.$( '.sections' ).empty();
this.$( '.toolbar select' ).off();
this.propertyControllers = [];
var controllers = socssOptions.propertyControllers;
for ( var id in controllers ) {
// Create the tabs
var $t = $( this.tabTemplate( {
id: id,
icon: controllers[ id ].icon,
title: controllers[ id ].title
} ) ).appendTo( this.$( '.section-tabs' ) );
// Create the section wrapper
var $s = $( this.sectionTemplate( {
id: id
} ) ).appendTo( this.$( '.sections' ) );
// Now lets add the controllers
if ( !_.isEmpty( controllers[ id ].controllers ) ) {
for ( var i = 0; i < controllers[ id ].controllers.length; i++ ) {
var $c = $( this.controllerTemplate( {
title: controllers[ id ].controllers[ i ].title
} ) ).appendTo( $s.find( 'tbody' ) );
var controllerAtts = controllers[ id ].controllers[ i ];
var controller;
if ( typeof socss.view.properties.controllers[ controllerAtts.type ] === 'undefined' ) {
// Setup a default controller
controller = new socss.view.propertyController( {
el: $c.find( 'td' ),
propertiesView: this,
args: ( typeof controllerAtts.args === 'undefined' ? {} : controllerAtts.args )
} );
}
else {
// Setup a specific controller
controller = new socss.view.properties.controllers[ controllerAtts.type ]( {
el: $c.find( 'td' ),
propertiesView: this,
args: ( typeof controllerAtts.args === 'undefined' ? {} : controllerAtts.args )
} );
}
this.propertyControllers.push( controller );
// Setup and render the controller
controller.render();
}
}
}
// Switch to the first tab.
this.$( '.section-tabs li' ).eq( 0 ).trigger( 'click' );
},
onTabClick: function ( event ) {
var $$ = $( event.currentTarget );
var show = this.$( '.sections .section[data-section="' + $$.data( 'section' ) + '"]' );
this.$( '.sections .section' ).not( show ).hide().removeClass( 'active' );
show.show().addClass( 'active' );
this.$( '.section-tabs li' ).not( $$ ).removeClass( 'active' );
$$.addClass( 'active' );
},
onToolbarSelectChange: function ( event ) {
this.setActiveSelector( $( event.currentTarget ).find( ':selected' ).data( 'selector' ) );
},
/**
* Sets the rule value for the active selector
* @param rule
* @param value
*/
setRuleValue: function ( rule, value ) {
if (
typeof this.activeSelector === 'undefined' ||
typeof this.activeSelector.declarations === 'undefined'
) {
return;
}
var declarations = this.activeSelector.declarations;
var newRule = true;
var valueChanged = false;
for ( var i = 0; i < declarations.length; i++ ) {
if ( declarations[ i ].property === rule ) {
newRule = false;
var declaration = declarations[ i ];
if ( declaration.value !== value ) {
declaration.value = value;
valueChanged = true;
}
// Remove empty declarations
if ( _.isEmpty( declaration.value ) ) {
declarations.splice( declarations.indexOf( declaration ) );
}
break;
}
}
if ( newRule && !_.isEmpty( value ) ) {
declarations.push( {
property: rule,
value: value,
type: 'declaration',
} );
valueChanged = true;
}
if ( valueChanged ) {
this.updateMainEditor( false );
}
},
/**
* Adds the @import rule value if it doesn't already exist.
*
* @param newRule
*
*/
addImport: function ( newRule ) {
// get @import rules
// check if any have the same value
// if not, then add the new @ rule
var importRules = _.filter( this.parsed.stylesheet.rules, function ( rule ) {
return rule.type === 'import';
} );
var exists = _.any( importRules, function ( rule ) {
return rule.import === newRule.import;
} );
if ( !exists ) {
// Add it to the top!
// @import statements must precede other rule types.
this.parsed.stylesheet.rules.unshift( newRule );
this.updateMainEditor( false );
}
},
/**
* Find @import which completely or partially contains the specified value.
*
* @param value
*/
findImport: function ( value ) {
return _.find( this.parsed.stylesheet.rules, function ( rule ) {
return rule.type === 'import' && rule.import.indexOf( value ) > -1;
} );
},
/**
* Find @import which completely or partially contains the identifier value and update it's import property.
*
* @param identifier
* @param value
*/
updateImport: function ( identifier, value ) {
var importRule = this.findImport( identifier );
if ( importRule.import !== value.import ) {
importRule.import = value.import;
this.updateMainEditor( false );
}
},
/**
* Find @import which completely or partially contains the identifier value and remove it.
*
* @param identifier
*/
removeImport: function ( identifier ) {
var importIndex = _.findIndex( this.parsed.stylesheet.rules, function ( rule ) {
return rule.type === 'import' && rule.import.indexOf( identifier ) > -1;
} );
if ( importIndex > -1 ) {
this.parsed.stylesheet.rules.splice( importIndex, 1 );
}
},
/**
* Get the rule value for the active selector
* @param rule
*/
getRuleValue: function ( rule ) {
if ( typeof this.activeSelector === 'undefined' || typeof this.activeSelector.declarations === 'undefined' ) {
return '';
}
var declarations = this.activeSelector.declarations;
for ( var i = 0; i < declarations.length; i++ ) {
if ( declarations[ i ].property === rule ) {
return declarations[ i ].value;
}
}
return '';
},
/**
* Update the main editor with the value of the parsed CSS
*/
updateMainEditor: function ( compress ) {
//TODO: add back compress option to remove/merge duplicated CSS selectors.
this.editor.codeMirror.setValue( this.parser.stringify( this.parsed ) );
},
/**
* Show the properties editor
*/
show: function () {
this.editorExpandedBefore = this.editor.isExpanded();
this.editor.setExpand( true );
this.$el.show().animate( { 'left': 0 }, 'fast' );
},
/**
* Hide the properties editor
*/
hide: function () {
this.editor.setExpand( this.editorExpandedBefore );
this.$el.animate( { 'left': -338 }, 'fast', function () {
$( this ).hide();
} );
// Update the main editor with compressed CSS when we close the properties editor
this.updateMainEditor( true );
},
save: function () {
socss.save( this );
},
/**
* @returns boolean
*/
isVisible: function () {
return this.$el.is( ':visible' );
},
/**
* Loads a single CSS selector and associated properties into the model
* @param css
*/
loadCSS: function ( css, activeSelector ) {
this.css = css;
// Load the CSS
this.parsed = this.parser.parse( css, {
silent: true
} );
var rules = this.parsed.stylesheet.rules;
// Add the dropdown menu items
var dropdown = this.$( '.toolbar select' ).empty();
for ( var i = 0; i < rules.length; i++ ) {
var rule = rules[ i ];
// Exclude @import statements
if ( !_.contains( [ 'rule', 'media' ], rule.type ) ) {
continue;
}
if ( rule.type === 'media' ) {
for ( var j = 0; j < rule.rules.length; j++ ) {
var mediaRule = '@media ' + rule.media;
var subRule = rule.rules[ j ];
if ( subRule.type != 'rule' ) {
continue;
}
dropdown.append(
$( '<option>' )
.html( mediaRule + ': ' + subRule.selectors.join( ',' ) )
.attr( 'val', mediaRule + ': ' + subRule.selectors.join( ',' ) )
.data( 'selector', subRule )
);
}
}
else {
dropdown.append(
$( '<option>' )
.html( rule.selectors.join( ',' ) )
.attr( 'val', rule.selectors.join( ',' ) )
.data( 'selector', rule )
);
}
}
if ( typeof activeSelector === 'undefined' ) {
activeSelector = dropdown.find( 'option' ).eq( 0 ).attr( 'val' );
}
if ( !_.isEmpty( activeSelector ) ) {
dropdown.val( activeSelector ).trigger( 'change' );
}
},
/**
* Set the selector that we're currently dealing with
* @param selector
*/
setActiveSelector: function ( selector ) {
this.activeSelector = selector;
for ( var i = 0; i < this.propertyControllers.length; i++ ) {
this.propertyControllers[ i ].refreshFromRule();
}
},
/**
* Add or select a selector.
*
* @param selector
*/
addSelector: function ( selector ) {
// Check if this selector already exists
var dropdown = this.$( '.toolbar select' );
dropdown.val( selector );
if ( dropdown.val() === selector ) {
// Trigger a change event to load the existing selector
dropdown.trigger( 'change' );
}
else {
// The selector doesn't exist, so add it to the CSS, then reload
this.editor.addEmptySelector( selector );
this.loadCSS( this.editor.codeMirror.getValue().trim(), selector );
}
dropdown.addClass( 'highlighted' );
setTimeout( function () {
dropdown.removeClass( 'highlighted' );
}, 2000 );
}
} );
// The basic property controller
socss.view.propertyController = Backbone.View.extend( {
template: _.template( '<input type="text" value="" class="socss-property-controller-input"/>' ),
activeRule: null,
args: null,
propertiesView: null,
events: {
'change .socss-property-controller-input': 'onChange',
'keyup input.socss-property-controller-input': 'onChange',
},
initialize: function ( args ) {
this.args = args.args;
this.propertiesView = args.propertiesView;
// If sub-views items define their own events hash with the same keys as above they will override those on
// the above events hash.
this.events = _.extend( socss.view.propertyController.prototype.events, this.events );
this.delegateEvents( this.events );
// By default, update the active rule whenever things change
this.on( 'set_value', this.updateRule, this );
this.on( 'change', this.updateRule, this );
},
/**
* Render the property field controller
*/
render: function () {
this.$el.append( $( this.template( {} ) ) );
this.field = this.$( 'input.socss-property-controller-input' );
},
onChange: function () {
this.trigger( 'change', this.field.val() );
},
/**
* Update the value of an active rule
*/
updateRule: function () {
this.propertiesView.setRuleValue(
this.args.property,
this.getValue()
);
},
/**
* This is called when the selector changes
*/
refreshFromRule: function () {
var value = this.propertiesView.getRuleValue( this.args.property );
this.setValue( value, { silent: true } );
},
/**
* Get the current value
* @return string
*/
getValue: function () {
return this.field.val();
},
/**
* Set the current value
* @param socss.view.properties val
*/
setValue: function ( val, options ) {
options = _.extend( { silent: false }, options );
this.field.val( val );
if ( !options.silent ) {
this.trigger( 'set_value', val );
}
},
/**
* Reset the current value
*/
reset: function ( options ) {
options = _.extend( { silent: false }, options );
this.setValue( '', options );
}
} );
// All the value controllers
socss.view.properties.controllers = {};
// The color controller
socss.view.properties.controllers.color = socss.view.propertyController.extend( {
render: function () {
socss.view.propertyController.prototype.render.apply( this, arguments );
// Set this up as a color picker
this.field.minicolors( {} );
},
onChange: function () {
this.trigger( 'change', this.field.minicolors( 'value' ) );
},
getValue: function () {
return this.field.minicolors( 'value' ).trim();
},
setValue: function ( val, options ) {
options = _.extend( { silent: false }, options );
this.field.minicolors( 'value', val );
if ( !options.silent ) {
this.trigger( 'set_value', val );
}
}
} );
// The dropdown select box controller
socss.view.properties.controllers.select = socss.view.propertyController.extend( {
template: _.template( '<select class="socss-property-controller-input"></select>' ),
events: {
'click .select-tab': 'onSelect',
},
render: function () {
this.$el.append( $( this.template( {} ) ) );
this.field = this.$( 'select' );
// Add the unchanged option
this.field.append( $( '<option value=""></option>' ).html( '' ) );
// Add all the options to the dropdown
for ( var k in this.args.options ) {
this.field.append( $( '<option></option>' ).attr( 'value', k ).html( this.args.options[ k ] ) );
}
if ( typeof this.args.option_icons !== 'undefined' ) {
this.setupVisualSelect();
}
},
setupVisualSelect: function () {
this.field.hide();
var $tc = $( '<div class="select-tabs"></div>' ).appendTo( this.$el );
// Add the none value
$( '<div class="select-tab" data-value=""><span class="so-css-icon so-css-icon-circle"></span></div>' ).appendTo( $tc );
// Now add one for each of the option icons
for ( var k in this.args.option_icons ) {
$( '<div class="select-tab"></div>' )
.appendTo( $tc )
.append(
$( '<span class="so-css-icon"></span>' )
.addClass( 'so-css-icon-' + this.args.option_icons[ k ] )
)
.attr( 'data-value', k )
;
}
$tc.find( '.select-tab' ).css( 'width', 100 / ( $tc.find( '>div' ).length ) + "%" );
},
onSelect: function ( event ) {
this.$( '.select-tab' ).removeClass( 'active' );
var $t = $( event.currentTarget );
$t.addClass( 'active' );
this.field.val( $t.data( 'value' ) ).trigger( 'change' );
},
/**
* Set the current value
* @param socss.view.properties val
*/
setValue: function ( val, options ) {
options = _.extend( { silent: false }, options );
this.field.val( val );
this.$( '.select-tabs .select-tab' ).removeClass( 'active' ).filter( '[data-value="' + val + '"]' ).addClass( 'active' );
if ( !options.silent ) {
this.trigger( 'set_value', val );
}
}
} );
// A field that lets a user upload an image
socss.view.properties.controllers.image = socss.view.propertyController.extend( {
template: _.template( '<input type="text" value="" /> <span class="select socss-button"><span class="so-css-icon so-css-icon-upload"></span></span>' ),
events: {
'click .select': 'openMedia',
},
render: function () {
this.media = wp.media( {
// Set the title of the modal.
title: socssOptions.loc.select_image,
// Tell the modal to show only images.
library: {
type: 'image'
},
// Customize the submit button.
button: {
// Set the text of the button.
text: socssOptions.loc.select,
// Tell the button not to close the modal, since we're
// going to refresh the page when the image is selected.
close: false
}
} );
this.$el.append( $( this.template( {
select: socssOptions.loc.select
} ) ) );
this.field = this.$el.find( 'input' );
this.media.on( 'select', function () {
// Grab the selected attachment.
var attachment = this.media.state().get( 'selection' ).first().attributes;
var val = this.args.value.replace( '{{url}}', attachment.url );
// Change the field value and trigger a change event
this.field.val( val ).trigger( 'change' );
this.trigger( 'set_value', val );
// Close the image selector
this.media.close();
}.bind( this ) );
},
openMedia: function () {
this.media.open();
},
} );
// A simple measurement field
socss.view.properties.controllers.measurement = socss.view.propertyController.extend( {
wrapperClass: 'socss-field-measurement',
events: {
'click .toggle-dropdown': 'toggleUnitDropdown',
'click .dropdown li': 'onSelectUnit',
'keydown .socss-field-input': 'onInputKeyPress',
'keyup .socss-field-input': 'onInputKeyUp',
},
render: function () {
socss.view.propertyController.prototype.render.apply( this, arguments );
this.setupMeasurementField();
},
setValue: function ( val, options ) {
options = _.extend( { silent: false }, options );
this.field.val( val ).trigger( 'measurement_refresh' );
if ( !options.silent ) {
this.trigger( 'set_value', val );
}
},
units: [
'px',
'%',
'em',
'cm',
'mm',
'in',
'pt',
'pc',
'ex',
'ch',
'rem',
'vw',
'vh',
'vmin',
'vmax'
],
parseUnits: function ( value ) {
var escapeRegExp = function ( str ) {
return str.replace( /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&" );
};
var regexUnits = this.units.map( escapeRegExp );
var regex = new RegExp( '([0-9\\.\\-]+)(' + regexUnits.join( '|' ) + ')?', 'i' );
var result = regex.exec( value );
if ( result === null ) {
return {
value: '',
unit: ''
};
}
else {
return {
value: result[ 1 ],
unit: result[ 2 ] === undefined ? '' : result[ 2 ]
};
}
},
setupMeasurementField: function () {
var defaultUnit = 'px';
this.field.hide();
this.$el.addClass( this.wrapperClass ).data( 'unit', defaultUnit );
// Create the fake input field
var $fi = $( '<input type="text" class="socss-field-input"/>' ).appendTo( this.$el );
$( '<span class="toggle-dropdown dashicons dashicons-arrow-down"></span>' ).appendTo( this.$el );
var $dd = $( '<ul class="dropdown"></ul>' ).appendTo( this.$el );
var $u = $( '<span class="units"></span>' ).html( defaultUnit ).appendTo( this.$el );
for ( var i = 0; i < this.units.length; i++ ) {
var $o = $( '<li></li>' ).html( this.units[ i ] ).data( 'unit', this.units[ i ] );
if ( this.units[ i ] === defaultUnit ) {
$o.addClass( 'active' );
}
$dd.append( $o );
}
this.field.on( 'measurement_refresh', function () {
var value = this.parseUnits( this.field.val() );
$fi.val( value.value );
var unit = value.unit === '' ? defaultUnit : value.unit;
this.$el.data( 'unit', unit );
$u.html( unit );
var $pl = $( '<span class="socss-hidden-placeholder"></span>' )
.css( {
'font-size': '14px'
} )
.html( value.value )
.appendTo( 'body' );
var width = $pl.width();
width = Math.min( width, 63 );
$pl.remove();
$u.css( 'left', width + 12 );
}.bind( this ) );
// Now add the increment/decrement buttons
var $diw = $( '<div class="socss-diw"></div>' ).appendTo( this.$el );
var $dec = $( '<div class="dec-button socss-button"><span class="so-css-icon so-css-icon-minus"></span></div>' ).appendTo( $diw );
var $inc = $( '<div class="inc-button socss-button"><span class="so-css-icon so-css-icon-plus"></span></div>' ).appendTo( $diw );
this.setupStepButton( $dec );
this.setupStepButton( $inc );
},
updateValue: function () {
var $fi = this.$( '.socss-field-input' );
var value = this.parseUnits( $fi.val() );
if ( value.unit !== '' && value.unit !== this.$el.data( 'unit' ) ) {
$fi.val( value.value );
this.setUnit( value.unit );
}
if ( value.value === '' ) {
this.field.val( '' );
}
else {
this.field.val( value.value + this.$el.data( 'unit' ) );
}
this.field.trigger( 'change' );
},
setUnit: function ( unit ) {
this.$( '.units' ).html( unit );
this.$el.data( 'unit', unit );
this.$( '.socss-field-input' ).trigger( 'keydown' );
},
toggleUnitDropdown: function () {
this.$( '.dropdown' ).toggle();
},
onSelectUnit: function ( event ) {
this.toggleUnitDropdown();
this.setUnit( $( event.currentTarget ).data( 'unit' ) );
this.updateValue();
},
onInputKeyUp: function( event ) {
this.onInputKeyPress( event );
this.updateValue();
},
onInputKeyPress: function ( event ) {
var $fi = this.$( '.socss-field-input' );
var char = '';
if ( event.type === 'keydown' ) {
if ( event.keyCode >= 48 && event.keyCode <= 57 ) {
char = String.fromCharCode( event.keyCode );
}
else if ( event.keyCode === 189 ) {
char = '-';
}
else if ( event.keyCode === 190 ) {
char = '.';
}
}
var $pl = $( '<span class="socss-hidden-placeholder"></span>' )
.css( {
'font-size': '14px'
} )
.html( $fi.val() + char )
.appendTo( 'body' );
var width = $pl.width();
width = Math.min( width, 63 );
$pl.remove();
this.$( '.units' ).css( 'left', width + 12 );
},
stepValue: function ( direction ) {
var value = Number.parseInt( this.parseUnits( this.field.val() ).value );
if ( Number.isNaN( value ) ) {
value = 0;
}
var newVal = value + direction;
this.$( '.socss-field-input' ).val( newVal );
this.updateValue();
this.field.trigger( 'measurement_refresh' );
},
setupStepButton: function ( $button ) {
var direction = $button.is( '.dec-button' ) ? -1 : 1;
var intervalId;
var timeoutId;
$button.on( 'mousedown', function() {
this.stepValue( direction );
timeoutId = setTimeout( function () {
intervalId = setInterval( function () {
this.stepValue( direction );
}.bind( this ), 50 );
}.bind( this ), 500 );
}.bind( this ) ).on( 'mouseup mouseout', function () {
if ( timeoutId ) {
clearTimeout( timeoutId );
timeoutId = null;
}
if ( intervalId ) {
clearInterval( intervalId );
intervalId = null;
}
} );
},
} );
// A simple measurement field
socss.view.properties.controllers.number = socss.view.propertyController.extend( {
initialize: function ( args ) {
socss.view.propertyController.prototype.initialize.apply( this, arguments );
this.args = _.extend( {
change: null,
default: 0,
increment: 1,
decrement: -1,
max: null,
min: null
}, args.args );
},
render: function () {
socss.view.propertyController.prototype.render.apply( this, arguments );
this.setupNumberField();
},
setupNumberField: function () {
this.$el.addClass( 'socss-field-number' );
// Now add the increment/decrement buttons
var $diw = $( '<div class="socss-diw"></div>' ).appendTo( this.$el );
var $dec = $( '<div class="dec-button socss-button"><span class="so-css-icon so-css-icon-minus"></span></div>' ).appendTo( $diw );
var $inc = $( '<div class="inc-button socss-button"><span class="so-css-icon so-css-icon-plus"></span></div>' ).appendTo( $diw );
this.setupStepButton( $dec );
this.setupStepButton( $inc );
return this;
},
stepValue: function ( direction ) {
var value = Number.parseFloat( this.field.val() );
if ( Number.isNaN( value ) ) {
value = this.args.default;
}
var newVal = value + direction;
newVal = Math.round( newVal * 100 ) / 100;
if ( this.args.max !== null ) {
newVal = Math.min( this.args.max, newVal );
}
if ( this.args.min !== null ) {
newVal = Math.max( this.args.min, newVal );
}
this.field.val( newVal );
this.field.trigger( 'change' );
},
setupStepButton: function ( $button ) {
var direction = $button.is( '.dec-button' ) ? this.args.decrement : this.args.increment;
var intervalId;
var timeoutId;
$button.on( 'mousedown', function() {
this.stepValue( direction );
timeoutId = setTimeout( function () {
intervalId = setInterval( function () {
this.stepValue( direction );
}.bind( this ), 50 );
}.bind( this ), 500 );
}.bind( this ) ).on( 'mouseup mouseout', function () {
if ( timeoutId ) {
clearTimeout( timeoutId );
timeoutId = null;
}
if ( intervalId ) {
clearInterval( intervalId );
intervalId = null;
}
} );
},
} );
socss.view.properties.controllers.sides = socss.view.propertyController.extend( {
template: _.template( $( '#template-sides-field' ).html().trim() ),
controllers: [],
events: {
'click .select-tab': 'onTabClick',
},
render: function () {
socss.view.propertyController.prototype.render.apply( this, arguments );
if ( !this.args.hasAll ) {
this.$( '.select-tab' ).eq( 0 ).remove();
this.$( '.select-tab' ).css( 'width', '25%' );
}
if ( ! this.args.isRadius ) {
this.$( '.select-tabs[data-type="radius"]' ).remove();
} else {
this.$( '.select-tabs[data-type="box"]' ).remove();
}
this.$( '.select-tab' ).each( function ( index, element ) {
var dir = $( element ).data( 'direction' );
var container = $( '<li class="side">' )
.appendTo( this.$( '.sides' ) )
.hide();
for ( var i = 0; i < this.args.controllers.length; i++ ) {
var controllerArgs = this.args.controllers[ i ];
if ( typeof socss.view.properties.controllers[ controllerArgs.type ] ) {
// Create the measurement view
var property = '';
if ( dir === 'all' ) {
property = controllerArgs.args.propertyAll;
}
else {
property = controllerArgs.args.property.replace( '{dir}', dir );
}
var theseControllerArgs = _.extend( {}, controllerArgs.args, { property: property } );
var controller = new socss.view.properties.controllers[ controllerArgs.type ]( {
el: $( '<div>' ).appendTo( container ),
propertiesView: this.propertiesView,
args: theseControllerArgs
} );
// Setup and render the measurement controller and register it with the properties view
controller.render();
this.propertiesView.propertyControllers.push( controller );
}
}
}.bind( this ) );
// Select the first tab by default
this.$( '.select-tab' ).eq( 0 ).click();
},
onTabClick: function ( event ) {
var $tabs = this.$( '.select-tab' );
$tabs.removeClass( 'active' );
var $tab = $( event.currentTarget );
$tab.addClass( 'active' );
var $sides = this.$( '.sides .side' )
$sides.hide();
$sides.eq( $tabs.index( $tab ) ).show();
},
} );
// This is a placeholder for the full font_select in SiteOrigin Premium
socss.view.properties.controllers.font_select = socss.view.propertyController.extend( {
template: _.template( $('#template-webfont-teaser').html().trim() )
});
} )( jQuery, _, socssOptions );
// Setup the main editor
jQuery( function ( $ ) {
var socss = window.socss;
var editorModel = new socss.model.CSSEditorModel( {
customCssPosts: socssOptions.customCssPosts,
} );
// Setup the editor
var editor = new socss.view.editor( {
el: $( '#so-custom-css-form' ).get( 0 ),
model: editorModel,
openVisualEditor: socssOptions.openVisualEditor,
} );
// editor.render();
editor.setSnippets( socssOptions.snippets );
// This is for hiding the getting started video
$( '#so-custom-css-getting-started a.hide' ).on( 'click', function( e ) {
e.preventDefault();
$( '#so-custom-css-getting-started' ).slideUp();
$.get( $( this ).attr( 'href' ) );
} );
window.socss.mainEditor = editor;
$( socss ).trigger( 'initialized' );
$( '.button-primary[name="siteorigin_custom_css_save"]' ).on( 'click', function() {
$( '#so-custom-css-form' ).trigger( 'submit' );
} );
$( '.installer-link' ).on( 'click', function( e ) {
e.preventDefault();
$( this ).hide();
$( '.installer-container' ).slideDown( 'fast' );
} );
$( '.installer_status' ).on( 'change', function() {
var $$ = $( this );
$$.prop( 'disabled', true );
jQuery.post(
ajaxurl,
{
action: 'so_installer_status',
nonce: $$.data( 'nonce' ),
status: $$.is( ':checked' )
},
function() {
$$.prop( 'disabled', false );
}
);
} );
} );
!function t(e,r,n){function o(s,a){if(!r[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[s]={exports:{}};e[s][0].call(l.exports,(function(t){return o(e[s][1][t]||t)}),l,l.exports,t,e,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(t,e,r){"use strict";r.byteLength=function(t){var e=c(t),r=e[0],n=e[1];return 3*(r+n)/4-n},r.toByteArray=function(t){var e,r,n=c(t),s=n[0],a=n[1],u=new i(function(t,e,r){return 3*(e+r)/4-r}(0,s,a)),l=0,h=a>0?s-4:s;for(r=0;r<h;r+=4)e=o[t.charCodeAt(r)]<<18|o[t.charCodeAt(r+1)]<<12|o[t.charCodeAt(r+2)]<<6|o[t.charCodeAt(r+3)],u[l++]=e>>16&255,u[l++]=e>>8&255,u[l++]=255&e;2===a&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,u[l++]=255&e);1===a&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,u[l++]=e>>8&255,u[l++]=255&e);return u},r.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],s=0,a=r-o;s<a;s+=16383)i.push(l(t,s,s+16383>a?a:s+16383));1===o?(e=t[r-1],i.push(n[e>>2]+n[e<<4&63]+"==")):2===o&&(e=(t[r-2]<<8)+t[r-1],i.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)n[a]=s[a],o[s.charCodeAt(a)]=a;function c(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function l(t,e,r){for(var o,i,s=[],a=e;a<r;a+=3)o=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),s.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},{}],2:[function(t,e,r){},{}],3:[function(t,e,r){(function(e){
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
"use strict";var n=t("base64-js"),o=t("ieee754");r.Buffer=e,r.SlowBuffer=function(t){+t!=t&&(t=0);return e.alloc(+t)},r.INSPECT_MAX_BYTES=50;function i(t){if(t>2147483647)throw new RangeError('The value "'+t+'" is invalid for option "size"');var r=new Uint8Array(t);return r.__proto__=e.prototype,r}function e(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return u(t)}return s(t,e,r)}function s(t,r,n){if("string"==typeof t)return function(t,r){"string"==typeof r&&""!==r||(r="utf8");if(!e.isEncoding(r))throw new TypeError("Unknown encoding: "+r);var n=0|h(t,r),o=i(n),s=o.write(t,r);s!==n&&(o=o.slice(0,s));return o}(t,r);if(ArrayBuffer.isView(t))return c(t);if(null==t)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(N(t,ArrayBuffer)||t&&N(t.buffer,ArrayBuffer))return function(t,r,n){if(r<0||t.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<r+(n||0))throw new RangeError('"length" is outside of buffer bounds');var o;o=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n);return o.__proto__=e.prototype,o}(t,r,n);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var o=t.valueOf&&t.valueOf();if(null!=o&&o!==t)return e.from(o,r,n);var s=function(t){if(e.isBuffer(t)){var r=0|l(t.length),n=i(r);return 0===n.length?n:(t.copy(n,0,0,r),n)}if(void 0!==t.length)return"number"!=typeof t.length||F(t.length)?i(0):c(t);if("Buffer"===t.type&&Array.isArray(t.data))return c(t.data)}(t);if(s)return s;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return e.from(t[Symbol.toPrimitive]("string"),r,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function a(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function u(t){return a(t),i(t<0?0:0|l(t))}function c(t){for(var e=t.length<0?0:0|l(t.length),r=i(e),n=0;n<e;n+=1)r[n]=255&t[n];return r}function l(t){if(t>=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+2147483647..toString(16)+" bytes");return 0|t}function h(t,r){if(e.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||N(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var n=t.length,o=arguments.length>2&&!0===arguments[2];if(!o&&0===n)return 0;for(var i=!1;;)switch(r){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return B(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return k(t).length;default:if(i)return o?-1:B(t).length;r=(""+r).toLowerCase(),i=!0}}function f(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return L(this,e,r);case"utf8":case"utf-8":return C(this,e,r);case"ascii":return E(this,e,r);case"latin1":case"binary":return S(this,e,r);case"base64":return A(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function p(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function g(t,r,n,o,i){if(0===t.length)return-1;if("string"==typeof n?(o=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),F(n=+n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof r&&(r=e.from(r,o)),e.isBuffer(r))return 0===r.length?-1:m(t,r,n,o,i);if("number"==typeof r)return r&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,n):Uint8Array.prototype.lastIndexOf.call(t,r,n):m(t,[r],n,o,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,o){var i,s=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var l=-1;for(i=r;i<a;i++)if(c(t,i)===c(e,-1===l?0:i-l)){if(-1===l&&(l=i),i-l+1===u)return l*s}else-1!==l&&(i-=i-l),l=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){for(var h=!0,f=0;f<u;f++)if(c(t,i+f)!==c(e,f)){h=!1;break}if(h)return i}return-1}function d(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=e.length;n>i/2&&(n=i/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(F(a))return s;t[r+s]=a}return s}function y(t,e,r,n){return P(B(e,t.length-r),t,r,n)}function v(t,e,r,n){return P(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function w(t,e,r,n){return v(t,e,r,n)}function b(t,e,r,n){return P(k(e),t,r,n)}function _(t,e,r,n){return P(function(t,e){for(var r,n,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function A(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function C(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i,s,a,u,c=t[o],l=null,h=c>239?4:c>223?3:c>191?2:1;if(o+h<=r)switch(h){case 1:c<128&&(l=c);break;case 2:128==(192&(i=t[o+1]))&&(u=(31&c)<<6|63&i)>127&&(l=u);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&(u=(15&c)<<12|(63&i)<<6|63&s)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:i=t[o+1],s=t[o+2],a=t[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,h=1):l>65535&&(l-=65536,n.push(l>>>10&1023|55296),l=56320|1023&l),n.push(l),o+=h}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=4096));return r}(n)}r.kMaxLength=2147483647,e.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()}catch(t){return!1}}(),e.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(e.prototype,"parent",{enumerable:!0,get:function(){if(e.isBuffer(this))return this.buffer}}),Object.defineProperty(e.prototype,"offset",{enumerable:!0,get:function(){if(e.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&e[Symbol.species]===e&&Object.defineProperty(e,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),e.poolSize=8192,e.from=function(t,e,r){return s(t,e,r)},e.prototype.__proto__=Uint8Array.prototype,e.__proto__=Uint8Array,e.alloc=function(t,e,r){return function(t,e,r){return a(t),t<=0?i(t):void 0!==e?"string"==typeof r?i(t).fill(e,r):i(t).fill(e):i(t)}(t,e,r)},e.allocUnsafe=function(t){return u(t)},e.allocUnsafeSlow=function(t){return u(t)},e.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==e.prototype},e.compare=function(t,r){if(N(t,Uint8Array)&&(t=e.from(t,t.offset,t.byteLength)),N(r,Uint8Array)&&(r=e.from(r,r.offset,r.byteLength)),!e.isBuffer(t)||!e.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;for(var n=t.length,o=r.length,i=0,s=Math.min(n,o);i<s;++i)if(t[i]!==r[i]){n=t[i],o=r[i];break}return n<o?-1:o<n?1:0},e.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},e.concat=function(t,r){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return e.alloc(0);var n;if(void 0===r)for(r=0,n=0;n<t.length;++n)r+=t[n].length;var o=e.allocUnsafe(r),i=0;for(n=0;n<t.length;++n){var s=t[n];if(N(s,Uint8Array)&&(s=e.from(s)),!e.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(o,i),i+=s.length}return o},e.byteLength=h,e.prototype._isBuffer=!0,e.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)p(this,e,e+1);return this},e.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)p(this,e,e+3),p(this,e+1,e+2);return this},e.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)p(this,e,e+7),p(this,e+1,e+6),p(this,e+2,e+5),p(this,e+3,e+4);return this},e.prototype.toString=function(){var t=this.length;return 0===t?"":0===arguments.length?C(this,0,t):f.apply(this,arguments)},e.prototype.toLocaleString=e.prototype.toString,e.prototype.equals=function(t){if(!e.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===e.compare(this,t)},e.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},e.prototype.compare=function(t,r,n,o,i){if(N(t,Uint8Array)&&(t=e.from(t,t.offset,t.byteLength)),!e.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===r&&(r=0),void 0===n&&(n=t?t.length:0),void 0===o&&(o=0),void 0===i&&(i=this.length),r<0||n>t.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&r>=n)return 0;if(o>=i)return-1;if(r>=n)return 1;if(this===t)return 0;for(var s=(i>>>=0)-(o>>>=0),a=(n>>>=0)-(r>>>=0),u=Math.min(s,a),c=this.slice(o,i),l=t.slice(r,n),h=0;h<u;++h)if(c[h]!==l[h]){s=c[h],a=l[h];break}return s<a?-1:a<s?1:0},e.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},e.prototype.indexOf=function(t,e,r){return g(this,t,e,r,!0)},e.prototype.lastIndexOf=function(t,e,r){return g(this,t,e,r,!1)},e.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return d(this,t,e,r);case"utf8":case"utf-8":return y(this,t,e,r);case"ascii":return v(this,t,e,r);case"latin1":case"binary":return w(this,t,e,r);case"base64":return b(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},e.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function E(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function S(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function L(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=e;i<r;++i)o+=j(t[i]);return o}function R(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function O(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function M(t,r,n,o,i,s){if(!e.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||r<s)throw new RangeError('"value" argument is out of bounds');if(n+o>t.length)throw new RangeError("Index out of range")}function T(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function x(t,e,r,n,i){return e=+e,r>>>=0,i||T(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function U(t,e,r,n,i){return e=+e,r>>>=0,i||T(t,0,r,8),o.write(t,e,r,n,52,8),r+8}e.prototype.slice=function(t,r){var n=this.length;(t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r<t&&(r=t);var o=this.subarray(t,r);return o.__proto__=e.prototype,o},e.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},e.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);for(var n=this[t+--e],o=1;e>0&&(o*=256);)n+=this[t+--e]*o;return n},e.prototype.readUInt8=function(t,e){return t>>>=0,e||O(t,1,this.length),this[t]},e.prototype.readUInt16LE=function(t,e){return t>>>=0,e||O(t,2,this.length),this[t]|this[t+1]<<8},e.prototype.readUInt16BE=function(t,e){return t>>>=0,e||O(t,2,this.length),this[t]<<8|this[t+1]},e.prototype.readUInt32LE=function(t,e){return t>>>=0,e||O(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},e.prototype.readUInt32BE=function(t,e){return t>>>=0,e||O(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},e.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*e)),n},e.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);for(var n=e,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},e.prototype.readInt8=function(t,e){return t>>>=0,e||O(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},e.prototype.readInt16LE=function(t,e){t>>>=0,e||O(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},e.prototype.readInt16BE=function(t,e){t>>>=0,e||O(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},e.prototype.readInt32LE=function(t,e){return t>>>=0,e||O(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},e.prototype.readInt32BE=function(t,e){return t>>>=0,e||O(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},e.prototype.readFloatLE=function(t,e){return t>>>=0,e||O(t,4,this.length),o.read(this,t,!0,23,4)},e.prototype.readFloatBE=function(t,e){return t>>>=0,e||O(t,4,this.length),o.read(this,t,!1,23,4)},e.prototype.readDoubleLE=function(t,e){return t>>>=0,e||O(t,8,this.length),o.read(this,t,!0,52,8)},e.prototype.readDoubleBE=function(t,e){return t>>>=0,e||O(t,8,this.length),o.read(this,t,!1,52,8)},e.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||M(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},e.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||M(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},e.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,1,255,0),this[e]=255&t,e+1},e.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},e.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},e.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},e.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},e.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var o=Math.pow(2,8*r-1);M(this,t,e,r,o-1,-o)}var i=0,s=1,a=0;for(this[e]=255&t;++i<r&&(s*=256);)t<0&&0===a&&0!==this[e+i-1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+r},e.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var o=Math.pow(2,8*r-1);M(this,t,e,r,o-1,-o)}var i=r-1,s=1,a=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+r},e.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},e.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},e.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},e.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},e.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||M(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},e.prototype.writeFloatLE=function(t,e,r){return x(this,t,e,!0,r)},e.prototype.writeFloatBE=function(t,e,r){return x(this,t,e,!1,r)},e.prototype.writeDoubleLE=function(t,e,r){return U(this,t,e,!0,r)},e.prototype.writeDoubleBE=function(t,e,r){return U(this,t,e,!1,r)},e.prototype.copy=function(t,r,n,o){if(!e.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),o||0===o||(o=this.length),r>=t.length&&(r=t.length),r||(r=0),o>0&&o<n&&(o=n),o===n)return 0;if(0===t.length||0===this.length)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),t.length-r<o-n&&(o=t.length-r+n);var i=o-n;if(this===t&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(r,n,o);else if(this===t&&n<r&&r<o)for(var s=i-1;s>=0;--s)t[s+r]=this[s+n];else Uint8Array.prototype.set.call(t,this.subarray(n,o),r);return i},e.prototype.fill=function(t,r,n,o){if("string"==typeof t){if("string"==typeof r?(o=r,r=0,n=this.length):"string"==typeof n&&(o=n,n=this.length),void 0!==o&&"string"!=typeof o)throw new TypeError("encoding must be a string");if("string"==typeof o&&!e.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(1===t.length){var i=t.charCodeAt(0);("utf8"===o&&i<128||"latin1"===o)&&(t=i)}}else"number"==typeof t&&(t&=255);if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;var s;if(r>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(s=r;s<n;++s)this[s]=t;else{var a=e.isBuffer(t)?t:e.from(t,o),u=a.length;if(0===u)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(s=0;s<n-r;++s)this[s+r]=a[s%u]}return this};var I=/[^+/0-9A-Za-z-_]/g;function j(t){return t<16?"0"+t.toString(16):t.toString(16)}function B(t,e){var r;e=e||1/0;for(var n=t.length,o=null,i=[],s=0;s<n;++s){if((r=t.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function k(t){return n.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(I,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function P(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function N(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function F(t){return t!=t}}).call(this,t("buffer").Buffer)},{"base64-js":1,buffer:3,ieee754:4}],4:[function(t,e,r){r.read=function(t,e,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,c=u>>1,l=-7,h=r?o-1:0,f=r?-1:1,p=t[e+h];for(h+=f,i=p&(1<<-l)-1,p>>=-l,l+=a;l>0;i=256*i+t[e+h],h+=f,l-=8);for(s=i&(1<<-l)-1,i>>=-l,l+=n;l>0;s=256*s+t[e+h],h+=f,l-=8);if(0===i)i=1-c;else{if(i===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),i-=c}return(p?-1:1)*s*Math.pow(2,i-n)},r.write=function(t,e,r,n,o,i){var s,a,u,c=8*i-o-1,l=(1<<c)-1,h=l>>1,f=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,g=n?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+h>=1?f/u:f*Math.pow(2,1-h))*u>=2&&(s++,u/=2),s+h>=l?(a=0,s=l):s+h>=1?(a=(e*u-1)*Math.pow(2,o),s+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,o),s=0));o>=8;t[r+p]=255&a,p+=g,a/=256,o-=8);for(s=s<<o|a,c+=o;c>0;t[r+p]=255&s,p+=g,s/=256,c-=8);t[r+p-g]|=128*m}},{}],5:[function(t,e,r){(function(t){function e(t,e){for(var r=0,n=t.length-1;n>=0;n--){var o=t[n];"."===o?t.splice(n,1):".."===o?(t.splice(n,1),r++):r&&(t.splice(n,1),r--)}if(e)for(;r--;r)t.unshift("..");return t}function n(t,e){if(t.filter)return t.filter(e);for(var r=[],n=0;n<t.length;n++)e(t[n],n,t)&&r.push(t[n]);return r}r.resolve=function(){for(var r="",o=!1,i=arguments.length-1;i>=-1&&!o;i--){var s=i>=0?arguments[i]:t.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(r=s+"/"+r,o="/"===s.charAt(0))}return(o?"/":"")+(r=e(n(r.split("/"),(function(t){return!!t})),!o).join("/"))||"."},r.normalize=function(t){var i=r.isAbsolute(t),s="/"===o(t,-1);return(t=e(n(t.split("/"),(function(t){return!!t})),!i).join("/"))||i||(t="."),t&&s&&(t+="/"),(i?"/":"")+t},r.isAbsolute=function(t){return"/"===t.charAt(0)},r.join=function(){var t=Array.prototype.slice.call(arguments,0);return r.normalize(n(t,(function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t})).join("/"))},r.relative=function(t,e){function n(t){for(var e=0;e<t.length&&""===t[e];e++);for(var r=t.length-1;r>=0&&""===t[r];r--);return e>r?[]:t.slice(e,r-e+1)}t=r.resolve(t).substr(1),e=r.resolve(e).substr(1);for(var o=n(t.split("/")),i=n(e.split("/")),s=Math.min(o.length,i.length),a=s,u=0;u<s;u++)if(o[u]!==i[u]){a=u;break}var c=[];for(u=a;u<o.length;u++)c.push("..");return(c=c.concat(i.slice(a))).join("/")},r.sep="/",r.delimiter=":",r.dirname=function(t){if("string"!=typeof t&&(t+=""),0===t.length)return".";for(var e=t.charCodeAt(0),r=47===e,n=-1,o=!0,i=t.length-1;i>=1;--i)if(47===(e=t.charCodeAt(i))){if(!o){n=i;break}}else o=!1;return-1===n?r?"/":".":r&&1===n?"/":t.slice(0,n)},r.basename=function(t,e){var r=function(t){"string"!=typeof t&&(t+="");var e,r=0,n=-1,o=!0;for(e=t.length-1;e>=0;--e)if(47===t.charCodeAt(e)){if(!o){r=e+1;break}}else-1===n&&(o=!1,n=e+1);return-1===n?"":t.slice(r,n)}(t);return e&&r.substr(-1*e.length)===e&&(r=r.substr(0,r.length-e.length)),r},r.extname=function(t){"string"!=typeof t&&(t+="");for(var e=-1,r=0,n=-1,o=!0,i=0,s=t.length-1;s>=0;--s){var a=t.charCodeAt(s);if(47!==a)-1===n&&(o=!1,n=s+1),46===a?-1===e?e=s:1!==i&&(i=1):-1!==e&&(i=-1);else if(!o){r=s+1;break}}return-1===e||-1===n||0===i||1===i&&e===n-1&&e===r+1?"":t.slice(e,n)};var o="b"==="ab".substr(-1)?function(t,e,r){return t.substr(e,r)}:function(t,e,r){return e<0&&(e=t.length+e),t.substr(e,r)}}).call(this,t("_process"))},{_process:6}],6:[function(t,e,r){var n,o,i=e.exports={};function s(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(t){if(n===setTimeout)return setTimeout(t,0);if((n===s||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:s}catch(t){n=s}try{o="function"==typeof clearTimeout?clearTimeout:a}catch(t){o=a}}();var c,l=[],h=!1,f=-1;function p(){h&&c&&(h=!1,c.length?l=c.concat(l):f=-1,l.length&&g())}function g(){if(!h){var t=u(p);h=!0;for(var e=l.length;e;){for(c=l,l=[];++f<e;)c&&c[f].run();f=-1,e=l.length}c=null,h=!1,function(t){if(o===clearTimeout)return clearTimeout(t);if((o===a||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(t);try{o(t)}catch(e){try{return o.call(null,t)}catch(e){return o.call(this,t)}}}(t)}}function m(t,e){this.fun=t,this.array=e}function d(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];l.push(new m(t,e)),1!==l.length||h||u(g)},m.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=d,i.addListener=d,i.once=d,i.off=d,i.removeListener=d,i.removeAllListeners=d,i.emit=d,i.prependListener=d,i.prependOnceListener=d,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],7:[function(t,e,r){(function(t){!function(n){var o="object"==typeof r&&r&&!r.nodeType&&r,i="object"==typeof e&&e&&!e.nodeType&&e,s="object"==typeof t&&t;s.global!==s&&s.window!==s&&s.self!==s||(n=s);var a,u,c=2147483647,l=/^xn--/,h=/[^\x20-\x7E]/,f=/[\x2E\u3002\uFF0E\uFF61]/g,p={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},g=Math.floor,m=String.fromCharCode;function d(t){throw new RangeError(p[t])}function y(t,e){for(var r=t.length,n=[];r--;)n[r]=e(t[r]);return n}function v(t,e){var r=t.split("@"),n="";return r.length>1&&(n=r[0]+"@",t=r[1]),n+y((t=t.replace(f,".")).split("."),e).join(".")}function w(t){for(var e,r,n=[],o=0,i=t.length;o<i;)(e=t.charCodeAt(o++))>=55296&&e<=56319&&o<i?56320==(64512&(r=t.charCodeAt(o++)))?n.push(((1023&e)<<10)+(1023&r)+65536):(n.push(e),o--):n.push(e);return n}function b(t){return y(t,(function(t){var e="";return t>65535&&(e+=m((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=m(t)})).join("")}function _(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function A(t,e,r){var n=0;for(t=r?g(t/700):t>>1,t+=g(t/e);t>455;n+=36)t=g(t/35);return g(n+36*t/(t+38))}function C(t){var e,r,n,o,i,s,a,u,l,h,f,p=[],m=t.length,y=0,v=128,w=72;for((r=t.lastIndexOf("-"))<0&&(r=0),n=0;n<r;++n)t.charCodeAt(n)>=128&&d("not-basic"),p.push(t.charCodeAt(n));for(o=r>0?r+1:0;o<m;){for(i=y,s=1,a=36;o>=m&&d("invalid-input"),((u=(f=t.charCodeAt(o++))-48<10?f-22:f-65<26?f-65:f-97<26?f-97:36)>=36||u>g((c-y)/s))&&d("overflow"),y+=u*s,!(u<(l=a<=w?1:a>=w+26?26:a-w));a+=36)s>g(c/(h=36-l))&&d("overflow"),s*=h;w=A(y-i,e=p.length+1,0==i),g(y/e)>c-v&&d("overflow"),v+=g(y/e),y%=e,p.splice(y++,0,v)}return b(p)}function E(t){var e,r,n,o,i,s,a,u,l,h,f,p,y,v,b,C=[];for(p=(t=w(t)).length,e=128,r=0,i=72,s=0;s<p;++s)(f=t[s])<128&&C.push(m(f));for(n=o=C.length,o&&C.push("-");n<p;){for(a=c,s=0;s<p;++s)(f=t[s])>=e&&f<a&&(a=f);for(a-e>g((c-r)/(y=n+1))&&d("overflow"),r+=(a-e)*y,e=a,s=0;s<p;++s)if((f=t[s])<e&&++r>c&&d("overflow"),f==e){for(u=r,l=36;!(u<(h=l<=i?1:l>=i+26?26:l-i));l+=36)b=u-h,v=36-h,C.push(m(_(h+b%v,0))),u=g(b/v);C.push(m(_(u,0))),i=A(r,y,n==o),r=0,++n}++r,++e}return C.join("")}if(a={version:"1.4.1",ucs2:{decode:w,encode:b},decode:C,encode:E,toASCII:function(t){return v(t,(function(t){return h.test(t)?"xn--"+E(t):t}))},toUnicode:function(t){return v(t,(function(t){return l.test(t)?C(t.slice(4).toLowerCase()):t}))}},"function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",(function(){return a}));else if(o&&i)if(e.exports==o)i.exports=a;else for(u in a)a.hasOwnProperty(u)&&(o[u]=a[u]);else n.punycode=a}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],8:[function(t,e,r){"use strict";function n(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.exports=function(t,e,r,i){e=e||"&",r=r||"=";var s={};if("string"!=typeof t||0===t.length)return s;var a=/\+/g;t=t.split(e);var u=1e3;i&&"number"==typeof i.maxKeys&&(u=i.maxKeys);var c=t.length;u>0&&c>u&&(c=u);for(var l=0;l<c;++l){var h,f,p,g,m=t[l].replace(a,"%20"),d=m.indexOf(r);d>=0?(h=m.substr(0,d),f=m.substr(d+1)):(h=m,f=""),p=decodeURIComponent(h),g=decodeURIComponent(f),n(s,p)?o(s[p])?s[p].push(g):s[p]=[s[p],g]:s[p]=g}return s};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},{}],9:[function(t,e,r){"use strict";var n=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};e.exports=function(t,e,r,a){return e=e||"&",r=r||"=",null===t&&(t=void 0),"object"==typeof t?i(s(t),(function(s){var a=encodeURIComponent(n(s))+r;return o(t[s])?i(t[s],(function(t){return a+encodeURIComponent(n(t))})).join(e):a+encodeURIComponent(n(t[s]))})).join(e):a?encodeURIComponent(n(a))+r+encodeURIComponent(n(t)):""};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function i(t,e){if(t.map)return t.map(e);for(var r=[],n=0;n<t.length;n++)r.push(e(t[n],n));return r}var s=Object.keys||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.push(r);return e}},{}],10:[function(t,e,r){"use strict";r.decode=r.parse=t("./decode"),r.encode=r.stringify=t("./encode")},{"./decode":8,"./encode":9}],11:[function(t,e,r){(function(e,n){var o=t("process/browser.js").nextTick,i=Function.prototype.apply,s=Array.prototype.slice,a={},u=0;function c(t,e){this._id=t,this._clearFn=e}r.setTimeout=function(){return new c(i.call(setTimeout,window,arguments),clearTimeout)},r.setInterval=function(){return new c(i.call(setInterval,window,arguments),clearInterval)},r.clearTimeout=r.clearInterval=function(t){t.close()},c.prototype.unref=c.prototype.ref=function(){},c.prototype.close=function(){this._clearFn.call(window,this._id)},r.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},r.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},r._unrefActive=r.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;e>=0&&(t._idleTimeoutId=setTimeout((function(){t._onTimeout&&t._onTimeout()}),e))},r.setImmediate="function"==typeof e?e:function(t){var e=u++,n=!(arguments.length<2)&&s.call(arguments,1);return a[e]=!0,o((function(){a[e]&&(n?t.apply(null,n):t.call(null),r.clearImmediate(e))})),e},r.clearImmediate="function"==typeof n?n:function(t){delete a[t]}}).call(this,t("timers").setImmediate,t("timers").clearImmediate)},{"process/browser.js":6,timers:11}],12:[function(t,e,r){"use strict";var n=t("punycode"),o=t("./util");function i(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}r.parse=w,r.resolve=function(t,e){return w(t,!1,!0).resolve(e)},r.resolveObject=function(t,e){return t?w(t,!1,!0).resolveObject(e):e},r.format=function(t){o.isString(t)&&(t=w(t));return t instanceof i?t.format():i.prototype.format.call(t)},r.Url=i;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,u=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,c=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),l=["'"].concat(c),h=["%","/","?",";","#"].concat(l),f=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,g=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,m={javascript:!0,"javascript:":!0},d={javascript:!0,"javascript:":!0},y={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},v=t("querystring");function w(t,e,r){if(t&&o.isObject(t)&&t instanceof i)return t;var n=new i;return n.parse(t,e,r),n}i.prototype.parse=function(t,e,r){if(!o.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var i=t.indexOf("?"),a=-1!==i&&i<t.indexOf("#")?"?":"#",c=t.split(a);c[0]=c[0].replace(/\\/g,"/");var w=t=c.join(a);if(w=w.trim(),!r&&1===t.split("#").length){var b=u.exec(w);if(b)return this.path=w,this.href=w,this.pathname=b[1],b[2]?(this.search=b[2],this.query=e?v.parse(this.search.substr(1)):this.search.substr(1)):e&&(this.search="",this.query={}),this}var _=s.exec(w);if(_){var A=(_=_[0]).toLowerCase();this.protocol=A,w=w.substr(_.length)}if(r||_||w.match(/^\/\/[^@\/]+@[^@\/]+/)){var C="//"===w.substr(0,2);!C||_&&d[_]||(w=w.substr(2),this.slashes=!0)}if(!d[_]&&(C||_&&!y[_])){for(var E,S,L=-1,R=0;R<f.length;R++){-1!==(O=w.indexOf(f[R]))&&(-1===L||O<L)&&(L=O)}-1!==(S=-1===L?w.lastIndexOf("@"):w.lastIndexOf("@",L))&&(E=w.slice(0,S),w=w.slice(S+1),this.auth=decodeURIComponent(E)),L=-1;for(R=0;R<h.length;R++){var O;-1!==(O=w.indexOf(h[R]))&&(-1===L||O<L)&&(L=O)}-1===L&&(L=w.length),this.host=w.slice(0,L),w=w.slice(L),this.parseHost(),this.hostname=this.hostname||"";var M="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!M)for(var T=this.hostname.split(/\./),x=(R=0,T.length);R<x;R++){var U=T[R];if(U&&!U.match(p)){for(var I="",j=0,B=U.length;j<B;j++)U.charCodeAt(j)>127?I+="x":I+=U[j];if(!I.match(p)){var k=T.slice(0,R),P=T.slice(R+1),N=U.match(g);N&&(k.push(N[1]),P.unshift(N[2])),P.length&&(w="/"+P.join(".")+w),this.hostname=k.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),M||(this.hostname=n.toASCII(this.hostname));var F=this.port?":"+this.port:"",q=this.hostname||"";this.host=q+F,this.href+=this.host,M&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==w[0]&&(w="/"+w))}if(!m[A])for(R=0,x=l.length;R<x;R++){var D=l[R];if(-1!==w.indexOf(D)){var G=encodeURIComponent(D);G===D&&(G=escape(D)),w=w.split(D).join(G)}}var z=w.indexOf("#");-1!==z&&(this.hash=w.substr(z),w=w.slice(0,z));var V=w.indexOf("?");if(-1!==V?(this.search=w.substr(V),this.query=w.substr(V+1),e&&(this.query=v.parse(this.query)),w=w.slice(0,V)):e&&(this.search="",this.query={}),w&&(this.pathname=w),y[A]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){F=this.pathname||"";var $=this.search||"";this.path=F+$}return this.href=this.format(),this},i.prototype.format=function(){var t=this.auth||"";t&&(t=(t=encodeURIComponent(t)).replace(/%3A/i,":"),t+="@");var e=this.protocol||"",r=this.pathname||"",n=this.hash||"",i=!1,s="";this.host?i=t+this.host:this.hostname&&(i=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&o.isObject(this.query)&&Object.keys(this.query).length&&(s=v.stringify(this.query));var a=this.search||s&&"?"+s||"";return e&&":"!==e.substr(-1)&&(e+=":"),this.slashes||(!e||y[e])&&!1!==i?(i="//"+(i||""),r&&"/"!==r.charAt(0)&&(r="/"+r)):i||(i=""),n&&"#"!==n.charAt(0)&&(n="#"+n),a&&"?"!==a.charAt(0)&&(a="?"+a),e+i+(r=r.replace(/[?#]/g,(function(t){return encodeURIComponent(t)})))+(a=a.replace("#","%23"))+n},i.prototype.resolve=function(t){return this.resolveObject(w(t,!1,!0)).format()},i.prototype.resolveObject=function(t){if(o.isString(t)){var e=new i;e.parse(t,!1,!0),t=e}for(var r=new i,n=Object.keys(this),s=0;s<n.length;s++){var a=n[s];r[a]=this[a]}if(r.hash=t.hash,""===t.href)return r.href=r.format(),r;if(t.slashes&&!t.protocol){for(var u=Object.keys(t),c=0;c<u.length;c++){var l=u[c];"protocol"!==l&&(r[l]=t[l])}return y[r.protocol]&&r.hostname&&!r.pathname&&(r.path=r.pathname="/"),r.href=r.format(),r}if(t.protocol&&t.protocol!==r.protocol){if(!y[t.protocol]){for(var h=Object.keys(t),f=0;f<h.length;f++){var p=h[f];r[p]=t[p]}return r.href=r.format(),r}if(r.protocol=t.protocol,t.host||d[t.protocol])r.pathname=t.pathname;else{for(var g=(t.pathname||"").split("/");g.length&&!(t.host=g.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==g[0]&&g.unshift(""),g.length<2&&g.unshift(""),r.pathname=g.join("/")}if(r.search=t.search,r.query=t.query,r.host=t.host||"",r.auth=t.auth,r.hostname=t.hostname||t.host,r.port=t.port,r.pathname||r.search){var m=r.pathname||"",v=r.search||"";r.path=m+v}return r.slashes=r.slashes||t.slashes,r.href=r.format(),r}var w=r.pathname&&"/"===r.pathname.charAt(0),b=t.host||t.pathname&&"/"===t.pathname.charAt(0),_=b||w||r.host&&t.pathname,A=_,C=r.pathname&&r.pathname.split("/")||[],E=(g=t.pathname&&t.pathname.split("/")||[],r.protocol&&!y[r.protocol]);if(E&&(r.hostname="",r.port=null,r.host&&(""===C[0]?C[0]=r.host:C.unshift(r.host)),r.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===g[0]?g[0]=t.host:g.unshift(t.host)),t.host=null),_=_&&(""===g[0]||""===C[0])),b)r.host=t.host||""===t.host?t.host:r.host,r.hostname=t.hostname||""===t.hostname?t.hostname:r.hostname,r.search=t.search,r.query=t.query,C=g;else if(g.length)C||(C=[]),C.pop(),C=C.concat(g),r.search=t.search,r.query=t.query;else if(!o.isNullOrUndefined(t.search)){if(E)r.hostname=r.host=C.shift(),(M=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@"))&&(r.auth=M.shift(),r.host=r.hostname=M.shift());return r.search=t.search,r.query=t.query,o.isNull(r.pathname)&&o.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!C.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var S=C.slice(-1)[0],L=(r.host||t.host||C.length>1)&&("."===S||".."===S)||""===S,R=0,O=C.length;O>=0;O--)"."===(S=C[O])?C.splice(O,1):".."===S?(C.splice(O,1),R++):R&&(C.splice(O,1),R--);if(!_&&!A)for(;R--;R)C.unshift("..");!_||""===C[0]||C[0]&&"/"===C[0].charAt(0)||C.unshift(""),L&&"/"!==C.join("/").substr(-1)&&C.push("");var M,T=""===C[0]||C[0]&&"/"===C[0].charAt(0);E&&(r.hostname=r.host=T?"":C.length?C.shift():"",(M=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@"))&&(r.auth=M.shift(),r.host=r.hostname=M.shift()));return(_=_||r.host&&C.length)&&!T&&C.unshift(""),C.length?r.pathname=C.join("/"):(r.pathname=null,r.path=null),o.isNull(r.pathname)&&o.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=t.auth||r.auth,r.slashes=r.slashes||t.slashes,r.href=r.format(),r},i.prototype.parseHost=function(){var t=this.host,e=a.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},{"./util":13,punycode:7,querystring:10}],13:[function(t,e,r){"use strict";e.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},{}],14:[function(t,e,r){window.css=t("css")},{css:16}],15:[function(t,e,r){(function(t){!function(r){"use strict";var n,o="function"==typeof(n=r.atob)?n:"function"==typeof t?function(e){return new t(e,"base64").toString("binary")}:"object"==typeof r.base64js?function(t){var e=r.base64js.b64ToByteArray(t);return Array.prototype.map.call(e,(function(t){return String.fromCharCode(t)})).join("")}:function(){throw new Error("You're probably in an old browser or an iOS webworker. It might help to include beatgammit's base64-js.")};r.atob=o,"object"==typeof e&&e&&e.exports&&(e.exports=o)}(window)}).call(this,t("buffer").Buffer)},{buffer:3}],16:[function(t,e,r){r.parse=t("./lib/parse"),r.stringify=t("./lib/stringify")},{"./lib/parse":17,"./lib/stringify":21}],17:[function(t,e,r){var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;function o(t){return t?t.replace(/^\s+|\s+$/g,""):""}e.exports=function(t,e){e=e||{};var r=1,i=1;function s(t){var e=t.match(/\n/g);e&&(r+=e.length);var n=t.lastIndexOf("\n");i=~n?t.length-n:i+t.length}function a(){var t={line:r,column:i};return function(e){return e.position=new u(t),m(),e}}function u(t){this.start=t,this.end={line:r,column:i},this.source=e.source}u.prototype.content=t;var c=[];function l(n){var o=new Error(e.source+":"+r+":"+i+": "+n);if(o.reason=n,o.filename=e.source,o.line=r,o.column=i,o.source=t,!e.silent)throw o;c.push(o)}function h(){return g(/^{\s*/)}function f(){return g(/^}/)}function p(){var e,r=[];for(m(),d(r);t.length&&"}"!=t.charAt(0)&&(e=R()||O());)!1!==e&&(r.push(e),d(r));return r}function g(e){var r=e.exec(t);if(r){var n=r[0];return s(n),t=t.slice(n.length),r}}function m(){g(/^\s*/)}function d(t){var e;for(t=t||[];e=y();)!1!==e&&t.push(e);return t}function y(){var e=a();if("/"==t.charAt(0)&&"*"==t.charAt(1)){for(var r=2;""!=t.charAt(r)&&("*"!=t.charAt(r)||"/"!=t.charAt(r+1));)++r;if(r+=2,""===t.charAt(r-1))return l("End of comment missing");var n=t.slice(2,r-2);return i+=2,s(n),t=t.slice(r),i+=2,e({type:"comment",comment:n})}}function v(){var t=g(/^([^{]+)/);if(t)return o(t[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g,"").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g,(function(t){return t.replace(/,/g,"")})).split(/\s*(?![^(]*\)),\s*/).map((function(t){return t.replace(/\u200C/g,",")}))}function w(){var t=a(),e=g(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);if(e){if(e=o(e[0]),!g(/^:\s*/))return l("property missing ':'");var r=g(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/),i=t({type:"declaration",property:e.replace(n,""),value:r?o(r[0]).replace(n,""):""});return g(/^[;\s]*/),i}}function b(){var t,e=[];if(!h())return l("missing '{'");for(d(e);t=w();)!1!==t&&(e.push(t),d(e));return f()?e:l("missing '}'")}function _(){for(var t,e=[],r=a();t=g(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)e.push(t[1]),g(/^,\s*/);if(e.length)return r({type:"keyframe",values:e,declarations:b()})}var A,C=L("import"),E=L("charset"),S=L("namespace");function L(t){var e=new RegExp("^@"+t+"\\s*([^;]+);");return function(){var r=a(),n=g(e);if(n){var o={type:t};return o[t]=n[1].trim(),r(o)}}}function R(){if("@"==t[0])return function(){var t=a();if(e=g(/^@([-\w]+)?keyframes\s*/)){var e,r=e[1];if(!(e=g(/^([-\w]+)\s*/)))return l("@keyframes missing name");var n,o=e[1];if(!h())return l("@keyframes missing '{'");for(var i=d();n=_();)i.push(n),i=i.concat(d());return f()?t({type:"keyframes",name:o,vendor:r,keyframes:i}):l("@keyframes missing '}'")}}()||function(){var t=a(),e=g(/^@media *([^{]+)/);if(e){var r=o(e[1]);if(!h())return l("@media missing '{'");var n=d().concat(p());return f()?t({type:"media",media:r,rules:n}):l("@media missing '}'")}}()||function(){var t=a(),e=g(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);if(e)return t({type:"custom-media",name:o(e[1]),media:o(e[2])})}()||function(){var t=a(),e=g(/^@supports *([^{]+)/);if(e){var r=o(e[1]);if(!h())return l("@supports missing '{'");var n=d().concat(p());return f()?t({type:"supports",supports:r,rules:n}):l("@supports missing '}'")}}()||C()||E()||S()||function(){var t=a(),e=g(/^@([-\w]+)?document *([^{]+)/);if(e){var r=o(e[1]),n=o(e[2]);if(!h())return l("@document missing '{'");var i=d().concat(p());return f()?t({type:"document",document:n,vendor:r,rules:i}):l("@document missing '}'")}}()||function(){var t=a();if(g(/^@page */)){var e=v()||[];if(!h())return l("@page missing '{'");for(var r,n=d();r=w();)n.push(r),n=n.concat(d());return f()?t({type:"page",selectors:e,declarations:n}):l("@page missing '}'")}}()||function(){var t=a();if(g(/^@host\s*/)){if(!h())return l("@host missing '{'");var e=d().concat(p());return f()?t({type:"host",rules:e}):l("@host missing '}'")}}()||function(){var t=a();if(g(/^@font-face\s*/)){if(!h())return l("@font-face missing '{'");for(var e,r=d();e=w();)r.push(e),r=r.concat(d());return f()?t({type:"font-face",declarations:r}):l("@font-face missing '}'")}}()}function O(){var t=a(),e=v();return e?(d(),t({type:"rule",selectors:e,declarations:b()})):l("selector missing")}return function t(e,r){var n=e&&"string"==typeof e.type,o=n?e:r;for(var i in e){var s=e[i];Array.isArray(s)?s.forEach((function(e){t(e,o)})):s&&"object"==typeof s&&t(s,o)}n&&Object.defineProperty(e,"parent",{configurable:!0,writable:!0,enumerable:!1,value:r||null});return e}((A=p(),{type:"stylesheet",stylesheet:{source:e.source,rules:A,parsingErrors:c}}))}},{}],18:[function(t,e,r){function n(t){this.options=t||{}}e.exports=n,n.prototype.emit=function(t){return t},n.prototype.visit=function(t){return this[t.type](t)},n.prototype.mapVisit=function(t,e){var r="";e=e||"";for(var n=0,o=t.length;n<o;n++)r+=this.visit(t[n]),e&&n<o-1&&(r+=this.emit(e));return r}},{}],19:[function(t,e,r){var n=t("./compiler"),o=t("inherits");function i(t){n.call(this,t)}e.exports=i,o(i,n),i.prototype.compile=function(t){return t.stylesheet.rules.map(this.visit,this).join("")},i.prototype.comment=function(t){return this.emit("",t.position)},i.prototype.import=function(t){return this.emit("@import "+t.import+";",t.position)},i.prototype.media=function(t){return this.emit("@media "+t.media,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}")},i.prototype.document=function(t){var e="@"+(t.vendor||"")+"document "+t.document;return this.emit(e,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}")},i.prototype.charset=function(t){return this.emit("@charset "+t.charset+";",t.position)},i.prototype.namespace=function(t){return this.emit("@namespace "+t.namespace+";",t.position)},i.prototype.supports=function(t){return this.emit("@supports "+t.supports,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}")},i.prototype.keyframes=function(t){return this.emit("@"+(t.vendor||"")+"keyframes "+t.name,t.position)+this.emit("{")+this.mapVisit(t.keyframes)+this.emit("}")},i.prototype.keyframe=function(t){var e=t.declarations;return this.emit(t.values.join(","),t.position)+this.emit("{")+this.mapVisit(e)+this.emit("}")},i.prototype.page=function(t){var e=t.selectors.length?t.selectors.join(", "):"";return this.emit("@page "+e,t.position)+this.emit("{")+this.mapVisit(t.declarations)+this.emit("}")},i.prototype["font-face"]=function(t){return this.emit("@font-face",t.position)+this.emit("{")+this.mapVisit(t.declarations)+this.emit("}")},i.prototype.host=function(t){return this.emit("@host",t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}")},i.prototype["custom-media"]=function(t){return this.emit("@custom-media "+t.name+" "+t.media+";",t.position)},i.prototype.rule=function(t){var e=t.declarations;return e.length?this.emit(t.selectors.join(","),t.position)+this.emit("{")+this.mapVisit(e)+this.emit("}"):""},i.prototype.declaration=function(t){return this.emit(t.property+":"+t.value,t.position)+this.emit(";")}},{"./compiler":18,inherits:24}],20:[function(t,e,r){var n=t("./compiler"),o=t("inherits");function i(t){t=t||{},n.call(this,t),this.indentation=t.indent}e.exports=i,o(i,n),i.prototype.compile=function(t){return this.stylesheet(t)},i.prototype.stylesheet=function(t){return this.mapVisit(t.stylesheet.rules,"\n\n")},i.prototype.comment=function(t){return this.emit(this.indent()+"/*"+t.comment+"*/",t.position)},i.prototype.import=function(t){return this.emit("@import "+t.import+";",t.position)},i.prototype.media=function(t){return this.emit("@media "+t.media,t.position)+this.emit(" {\n"+this.indent(1))+this.mapVisit(t.rules,"\n\n")+this.emit(this.indent(-1)+"\n}")},i.prototype.document=function(t){var e="@"+(t.vendor||"")+"document "+t.document;return this.emit(e,t.position)+this.emit(" {\n"+this.indent(1))+this.mapVisit(t.rules,"\n\n")+this.emit(this.indent(-1)+"\n}")},i.prototype.charset=function(t){return this.emit("@charset "+t.charset+";",t.position)},i.prototype.namespace=function(t){return this.emit("@namespace "+t.namespace+";",t.position)},i.prototype.supports=function(t){return this.emit("@supports "+t.supports,t.position)+this.emit(" {\n"+this.indent(1))+this.mapVisit(t.rules,"\n\n")+this.emit(this.indent(-1)+"\n}")},i.prototype.keyframes=function(t){return this.emit("@"+(t.vendor||"")+"keyframes "+t.name,t.position)+this.emit(" {\n"+this.indent(1))+this.mapVisit(t.keyframes,"\n")+this.emit(this.indent(-1)+"}")},i.prototype.keyframe=function(t){var e=t.declarations;return this.emit(this.indent())+this.emit(t.values.join(", "),t.position)+this.emit(" {\n"+this.indent(1))+this.mapVisit(e,"\n")+this.emit(this.indent(-1)+"\n"+this.indent()+"}\n")},i.prototype.page=function(t){var e=t.selectors.length?t.selectors.join(", ")+" ":"";return this.emit("@page "+e,t.position)+this.emit("{\n")+this.emit(this.indent(1))+this.mapVisit(t.declarations,"\n")+this.emit(this.indent(-1))+this.emit("\n}")},i.prototype["font-face"]=function(t){return this.emit("@font-face ",t.position)+this.emit("{\n")+this.emit(this.indent(1))+this.mapVisit(t.declarations,"\n")+this.emit(this.indent(-1))+this.emit("\n}")},i.prototype.host=function(t){return this.emit("@host",t.position)+this.emit(" {\n"+this.indent(1))+this.mapVisit(t.rules,"\n\n")+this.emit(this.indent(-1)+"\n}")},i.prototype["custom-media"]=function(t){return this.emit("@custom-media "+t.name+" "+t.media+";",t.position)},i.prototype.rule=function(t){var e=this.indent(),r=t.declarations;return r.length?this.emit(t.selectors.map((function(t){return e+t})).join(",\n"),t.position)+this.emit(" {\n")+this.emit(this.indent(1))+this.mapVisit(r,"\n")+this.emit(this.indent(-1))+this.emit("\n"+this.indent()+"}"):""},i.prototype.declaration=function(t){return this.emit(this.indent())+this.emit(t.property+": "+t.value,t.position)+this.emit(";")},i.prototype.indent=function(t){return this.level=this.level||1,null!=t?(this.level+=t,""):Array(this.level).join(this.indentation||" ")}},{"./compiler":18,inherits:24}],21:[function(t,e,r){var n=t("./compress"),o=t("./identity");e.exports=function(e,r){var i=(r=r||{}).compress?new n(r):new o(r);if(r.sourcemap){t("./source-map-support")(i);var s=i.compile(e);return i.applySourceMaps(),{code:s,map:"generator"===r.sourcemap?i.map:i.map.toJSON()}}return s=i.compile(e)}},{"./compress":19,"./identity":20,"./source-map-support":22}],22:[function(t,e,r){var n=t("source-map").SourceMapGenerator,o=t("source-map").SourceMapConsumer,i=t("source-map-resolve"),s=t("fs"),a=t("path");e.exports=function(t){for(var e in t._comment=t.comment,t.map=new n,t.position={line:1,column:1},t.files={},r)t[e]=r[e]};const u=function(t){return"\\"===a.sep?t.replace(/\\/g,"/").replace(/^[a-z]:\/?/i,"/"):t};r.updatePosition=function(t){var e=t.match(/\n/g);e&&(this.position.line+=e.length);var r=t.lastIndexOf("\n");this.position.column=~r?t.length-r:this.position.column+t.length},r.emit=function(t,e){if(e){var r=u(e.source||"source.css");this.map.addMapping({source:r,generated:{line:this.position.line,column:Math.max(this.position.column-1,0)},original:{line:e.start.line,column:e.start.column-1}}),this.addFile(r,e)}return this.updatePosition(t),t},r.addFile=function(t,e){"string"==typeof e.content&&(Object.prototype.hasOwnProperty.call(this.files,t)||(this.files[t]=e.content))},r.applySourceMaps=function(){Object.keys(this.files).forEach((function(t){var e=this.files[t];if(this.map.setSourceContent(t,e),!1!==this.options.inputSourcemaps){var r=i.resolveSync(e,t,s.readFileSync);if(r){var n=new o(r.map),c=r.sourcesRelativeTo;this.map.applySourceMap(n,t,u(a.dirname(c)))}}}),this)},r.comment=function(t){return/^# sourceMappingURL=/.test(t.comment)?this.emit("",t.position):this._comment(t)}},{fs:2,path:5,"source-map":36,"source-map-resolve":25}],23:[function(t,e,r){"use strict";var n=new RegExp("%[a-f0-9]{2}","gi"),o=new RegExp("(%[a-f0-9]{2})+","gi");function i(t,e){try{return decodeURIComponent(t.join(""))}catch(t){}if(1===t.length)return t;e=e||1;var r=t.slice(0,e),n=t.slice(e);return Array.prototype.concat.call([],i(r),i(n))}function s(t){try{return decodeURIComponent(t)}catch(o){for(var e=t.match(n),r=1;r<e.length;r++)e=(t=i(e,r).join("")).match(n);return t}}e.exports=function(t){if("string"!=typeof t)throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof t+"`");try{return t=t.replace(/\+/g," "),decodeURIComponent(t)}catch(e){return function(t){for(var e={"%FE%FF":"��","%FF%FE":"��"},r=o.exec(t);r;){try{e[r[0]]=decodeURIComponent(r[0])}catch(t){var n=s(r[0]);n!==r[0]&&(e[r[0]]=n)}r=o.exec(t)}e["%C2"]="�";for(var i=Object.keys(e),a=0;a<i.length;a++){var u=i[a];t=t.replace(new RegExp(u,"g"),e[u])}return t}(t)}}},{}],24:[function(t,e,r){"function"==typeof Object.create?e.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}}},{}],25:[function(t,e,r){(function(r){var n=t("atob"),o=t("url"),i=t("path"),s=t("decode-uri-component");function a(){return Array.prototype.reduce.call(arguments,(function(t,e){return o.resolve(t,e)}))}function u(t){return"\\"===i.sep?t.replace(/\\/g,"/").replace(/^[a-z]:\/?/i,"/"):t}function c(t){return s(t.replace(/\+/g,"%2B"))}function l(t,e,n){r((function(){t(e,n)}))}function h(t,e){try{return JSON.parse(t.replace(/^\)\]\}'/,""))}catch(t){throw t.sourceMapData=e,t}}function f(t,e,r){var n=c(e);try{return String(t(n))}catch(t){throw t.sourceMapData=r,t}}var p=/[#@] sourceMappingURL=([^\s'"]*)/,g=RegExp("(?:/\\*(?:\\s*\r?\n(?://)?)?(?:"+p.source+")\\s*\\*/|//(?:"+p.source+"))\\s*");function m(t,e,r,n){var o;try{o=b(t,e)}catch(t){return l(n,t)}if(!o||o.map)return l(n,null,o);r(c(o.url),(function(t,e){if(t)return t.sourceMapData=o,n(t);o.map=String(e);try{o.map=h(o.map,o)}catch(t){return n(t)}n(null,o)}))}function d(t,e,r){var n=b(t,e);return!n||n.map?n:(n.map=f(r,n.url,n),n.map=h(n.map,n),n)}var y=/^data:([^,;]*)(;[^,;]*)*(?:,(.*))?$/,v=/^(?:application|text)\/json$/;function w(t){if("undefined"==typeof TextDecoder||"undefined"==typeof Uint8Array)return n(t);var e=function(t){for(var e=n(t),r=e.length,o=new Uint8Array(r),i=0;i<r;i++)o[i]=e.charCodeAt(i);return o}(t);return new TextDecoder("utf-8",{fatal:!0}).decode(e)}function b(t,e){e=u(e);var r=function(t){var e=t.match(g);return e?e[1]||e[2]||"":null}(t);if(!r)return null;var n=r.match(y);if(n){var o=n[1]||"text/plain",i=n[2]||"",s=n[3]||"",c={sourceMappingURL:r,url:null,sourcesRelativeTo:e,map:s};if(!v.test(o)){var l=new Error("Unuseful data uri mime type: "+o);throw l.sourceMapData=c,l}try{c.map=h(";base64"===i?w(s):decodeURIComponent(s),c)}catch(l){throw l.sourceMapData=c,l}return c}var f=a(e,r);return{sourceMappingURL:r,url:f,sourcesRelativeTo:f,map:null}}function _(t,e,r,n,o){"function"==typeof n&&(o=n,n={});var i=t.sources?t.sources.length:0,s={sourcesResolved:[],sourcesContent:[]};if(0!==i){var a=function(){0===--i&&o(null,s)};E(t,e,n,(function(t,e,n){if(s.sourcesResolved[n]=t,"string"==typeof e)s.sourcesContent[n]=e,l(a,null);else{var o=c(t);r(o,(function(t,e){s.sourcesContent[n]=t||String(e),a()}))}}))}else l(o,null,s)}function A(t,e,r,n){var o={sourcesResolved:[],sourcesContent:[]};return t.sources&&0!==t.sources.length?(E(t,e,n,(function(t,e,n){if(o.sourcesResolved[n]=t,null!==r)if("string"==typeof e)o.sourcesContent[n]=e;else{var i=c(t);try{o.sourcesContent[n]=String(r(i))}catch(t){o.sourcesContent[n]=t}}})),o):o}var C=/\/?$/;function E(t,e,r,n){var o;r=r||{},e=u(e);for(var i=0,s=t.sources.length;i<s;i++)o=null,"string"==typeof r.sourceRoot?o=r.sourceRoot:"string"==typeof t.sourceRoot&&!1!==r.sourceRoot&&(o=t.sourceRoot),n(null===o||""===o?a(e,t.sources[i]):a(e,o.replace(C,"/"),t.sources[i]),(t.sourcesContent||[])[i],i)}e.exports={resolveSourceMap:m,resolveSourceMapSync:d,resolveSources:_,resolveSourcesSync:A,resolve:function(t,e,r,n,o){if("function"==typeof n&&(o=n,n={}),null===t){var i={sourceMappingURL:null,url:e,sourcesRelativeTo:e,map:null},s=c(e);r(s,(function(t,e){if(t)return t.sourceMapData=i,o(t);i.map=String(e);try{i.map=h(i.map,i)}catch(t){return o(t)}a(i)}))}else m(t,e,r,(function(t,e){return t?o(t):e?void a(e):o(null,null)}));function a(t){_(t.map,t.sourcesRelativeTo,r,n,(function(e,r){if(e)return o(e);t.sourcesResolved=r.sourcesResolved,t.sourcesContent=r.sourcesContent,o(null,t)}))}},resolveSync:function(t,e,r,n){var o;if(null===t){(o={sourceMappingURL:null,url:e,sourcesRelativeTo:e,map:null}).map=f(r,e,o),o.map=h(o.map,o)}else if(!(o=d(t,e,r)))return null;var i=A(o.map,o.sourcesRelativeTo,r,n);return o.sourcesResolved=i.sourcesResolved,o.sourcesContent=i.sourcesContent,o},parseMapToJSON:h}}).call(this,t("timers").setImmediate)},{atob:15,"decode-uri-component":23,path:5,timers:11,url:12}],26:[function(t,e,r){var n=t("./util"),o=Object.prototype.hasOwnProperty,i="undefined"!=typeof Map;function s(){this._array=[],this._set=i?new Map:Object.create(null)}s.fromArray=function(t,e){for(var r=new s,n=0,o=t.length;n<o;n++)r.add(t[n],e);return r},s.prototype.size=function(){return i?this._set.size:Object.getOwnPropertyNames(this._set).length},s.prototype.add=function(t,e){var r=i?t:n.toSetString(t),s=i?this.has(t):o.call(this._set,r),a=this._array.length;s&&!e||this._array.push(t),s||(i?this._set.set(t,a):this._set[r]=a)},s.prototype.has=function(t){if(i)return this._set.has(t);var e=n.toSetString(t);return o.call(this._set,e)},s.prototype.indexOf=function(t){if(i){var e=this._set.get(t);if(e>=0)return e}else{var r=n.toSetString(t);if(o.call(this._set,r))return this._set[r]}throw new Error('"'+t+'" is not in the set.')},s.prototype.at=function(t){if(t>=0&&t<this._array.length)return this._array[t];throw new Error("No element indexed by "+t)},s.prototype.toArray=function(){return this._array.slice()},r.ArraySet=s},{"./util":35}],27:[function(t,e,r){var n=t("./base64");r.encode=function(t){var e,r="",o=function(t){return t<0?1+(-t<<1):0+(t<<1)}(t);do{e=31&o,(o>>>=5)>0&&(e|=32),r+=n.encode(e)}while(o>0);return r},r.decode=function(t,e,r){var o,i,s,a,u=t.length,c=0,l=0;do{if(e>=u)throw new Error("Expected more digits in base 64 VLQ value.");if(-1===(i=n.decode(t.charCodeAt(e++))))throw new Error("Invalid base64 digit: "+t.charAt(e-1));o=!!(32&i),c+=(i&=31)<<l,l+=5}while(o);r.value=(a=(s=c)>>1,1==(1&s)?-a:a),r.rest=e}},{"./base64":28}],28:[function(t,e,r){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");r.encode=function(t){if(0<=t&&t<n.length)return n[t];throw new TypeError("Must be between 0 and 63: "+t)},r.decode=function(t){return 65<=t&&t<=90?t-65:97<=t&&t<=122?t-97+26:48<=t&&t<=57?t-48+52:43==t?62:47==t?63:-1}},{}],29:[function(t,e,r){r.GREATEST_LOWER_BOUND=1,r.LEAST_UPPER_BOUND=2,r.search=function(t,e,n,o){if(0===e.length)return-1;var i=function t(e,n,o,i,s,a){var u=Math.floor((n-e)/2)+e,c=s(o,i[u],!0);return 0===c?u:c>0?n-u>1?t(u,n,o,i,s,a):a==r.LEAST_UPPER_BOUND?n<i.length?n:-1:u:u-e>1?t(e,u,o,i,s,a):a==r.LEAST_UPPER_BOUND?u:e<0?-1:e}(-1,e.length,t,e,n,o||r.GREATEST_LOWER_BOUND);if(i<0)return-1;for(;i-1>=0&&0===n(e[i],e[i-1],!0);)--i;return i}},{}],30:[function(t,e,r){var n=t("./util");function o(){this._array=[],this._sorted=!0,this._last={generatedLine:-1,generatedColumn:0}}o.prototype.unsortedForEach=function(t,e){this._array.forEach(t,e)},o.prototype.add=function(t){var e,r,o,i,s,a;e=this._last,r=t,o=e.generatedLine,i=r.generatedLine,s=e.generatedColumn,a=r.generatedColumn,i>o||i==o&&a>=s||n.compareByGeneratedPositionsInflated(e,r)<=0?(this._last=t,this._array.push(t)):(this._sorted=!1,this._array.push(t))},o.prototype.toArray=function(){return this._sorted||(this._array.sort(n.compareByGeneratedPositionsInflated),this._sorted=!0),this._array},r.MappingList=o},{"./util":35}],31:[function(t,e,r){function n(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function o(t,e,r,i){if(r<i){var s=r-1;n(t,(l=r,h=i,Math.round(l+Math.random()*(h-l))),i);for(var a=t[i],u=r;u<i;u++)e(t[u],a)<=0&&n(t,s+=1,u);n(t,s+1,u);var c=s+1;o(t,e,r,c-1),o(t,e,c+1,i)}var l,h}r.quickSort=function(t,e){o(t,e,0,t.length-1)}},{}],32:[function(t,e,r){var n=t("./util"),o=t("./binary-search"),i=t("./array-set").ArraySet,s=t("./base64-vlq"),a=t("./quick-sort").quickSort;function u(t,e){var r=t;return"string"==typeof t&&(r=n.parseSourceMapInput(t)),null!=r.sections?new h(r,e):new c(r,e)}function c(t,e){var r=t;"string"==typeof t&&(r=n.parseSourceMapInput(t));var o=n.getArg(r,"version"),s=n.getArg(r,"sources"),a=n.getArg(r,"names",[]),u=n.getArg(r,"sourceRoot",null),c=n.getArg(r,"sourcesContent",null),l=n.getArg(r,"mappings"),h=n.getArg(r,"file",null);if(o!=this._version)throw new Error("Unsupported version: "+o);u&&(u=n.normalize(u)),s=s.map(String).map(n.normalize).map((function(t){return u&&n.isAbsolute(u)&&n.isAbsolute(t)?n.relative(u,t):t})),this._names=i.fromArray(a.map(String),!0),this._sources=i.fromArray(s,!0),this._absoluteSources=this._sources.toArray().map((function(t){return n.computeSourceURL(u,t,e)})),this.sourceRoot=u,this.sourcesContent=c,this._mappings=l,this._sourceMapURL=e,this.file=h}function l(){this.generatedLine=0,this.generatedColumn=0,this.source=null,this.originalLine=null,this.originalColumn=null,this.name=null}function h(t,e){var r=t;"string"==typeof t&&(r=n.parseSourceMapInput(t));var o=n.getArg(r,"version"),s=n.getArg(r,"sections");if(o!=this._version)throw new Error("Unsupported version: "+o);this._sources=new i,this._names=new i;var a={line:-1,column:0};this._sections=s.map((function(t){if(t.url)throw new Error("Support for url field in sections not implemented.");var r=n.getArg(t,"offset"),o=n.getArg(r,"line"),i=n.getArg(r,"column");if(o<a.line||o===a.line&&i<a.column)throw new Error("Section offsets must be ordered and non-overlapping.");return a=r,{generatedOffset:{generatedLine:o+1,generatedColumn:i+1},consumer:new u(n.getArg(t,"map"),e)}}))}u.fromSourceMap=function(t,e){return c.fromSourceMap(t,e)},u.prototype._version=3,u.prototype.__generatedMappings=null,Object.defineProperty(u.prototype,"_generatedMappings",{configurable:!0,enumerable:!0,get:function(){return this.__generatedMappings||this._parseMappings(this._mappings,this.sourceRoot),this.__generatedMappings}}),u.prototype.__originalMappings=null,Object.defineProperty(u.prototype,"_originalMappings",{configurable:!0,enumerable:!0,get:function(){return this.__originalMappings||this._parseMappings(this._mappings,this.sourceRoot),this.__originalMappings}}),u.prototype._charIsMappingSeparator=function(t,e){var r=t.charAt(e);return";"===r||","===r},u.prototype._parseMappings=function(t,e){throw new Error("Subclasses must implement _parseMappings")},u.GENERATED_ORDER=1,u.ORIGINAL_ORDER=2,u.GREATEST_LOWER_BOUND=1,u.LEAST_UPPER_BOUND=2,u.prototype.eachMapping=function(t,e,r){var o,i=e||null;switch(r||u.GENERATED_ORDER){case u.GENERATED_ORDER:o=this._generatedMappings;break;case u.ORIGINAL_ORDER:o=this._originalMappings;break;default:throw new Error("Unknown order of iteration.")}var s=this.sourceRoot;o.map((function(t){var e=null===t.source?null:this._sources.at(t.source);return{source:e=n.computeSourceURL(s,e,this._sourceMapURL),generatedLine:t.generatedLine,generatedColumn:t.generatedColumn,originalLine:t.originalLine,originalColumn:t.originalColumn,name:null===t.name?null:this._names.at(t.name)}}),this).forEach(t,i)},u.prototype.allGeneratedPositionsFor=function(t){var e=n.getArg(t,"line"),r={source:n.getArg(t,"source"),originalLine:e,originalColumn:n.getArg(t,"column",0)};if(r.source=this._findSourceIndex(r.source),r.source<0)return[];var i=[],s=this._findMapping(r,this._originalMappings,"originalLine","originalColumn",n.compareByOriginalPositions,o.LEAST_UPPER_BOUND);if(s>=0){var a=this._originalMappings[s];if(void 0===t.column)for(var u=a.originalLine;a&&a.originalLine===u;)i.push({line:n.getArg(a,"generatedLine",null),column:n.getArg(a,"generatedColumn",null),lastColumn:n.getArg(a,"lastGeneratedColumn",null)}),a=this._originalMappings[++s];else for(var c=a.originalColumn;a&&a.originalLine===e&&a.originalColumn==c;)i.push({line:n.getArg(a,"generatedLine",null),column:n.getArg(a,"generatedColumn",null),lastColumn:n.getArg(a,"lastGeneratedColumn",null)}),a=this._originalMappings[++s]}return i},r.SourceMapConsumer=u,c.prototype=Object.create(u.prototype),c.prototype.consumer=u,c.prototype._findSourceIndex=function(t){var e,r=t;if(null!=this.sourceRoot&&(r=n.relative(this.sourceRoot,r)),this._sources.has(r))return this._sources.indexOf(r);for(e=0;e<this._absoluteSources.length;++e)if(this._absoluteSources[e]==t)return e;return-1},c.fromSourceMap=function(t,e){var r=Object.create(c.prototype),o=r._names=i.fromArray(t._names.toArray(),!0),s=r._sources=i.fromArray(t._sources.toArray(),!0);r.sourceRoot=t._sourceRoot,r.sourcesContent=t._generateSourcesContent(r._sources.toArray(),r.sourceRoot),r.file=t._file,r._sourceMapURL=e,r._absoluteSources=r._sources.toArray().map((function(t){return n.computeSourceURL(r.sourceRoot,t,e)}));for(var u=t._mappings.toArray().slice(),h=r.__generatedMappings=[],f=r.__originalMappings=[],p=0,g=u.length;p<g;p++){var m=u[p],d=new l;d.generatedLine=m.generatedLine,d.generatedColumn=m.generatedColumn,m.source&&(d.source=s.indexOf(m.source),d.originalLine=m.originalLine,d.originalColumn=m.originalColumn,m.name&&(d.name=o.indexOf(m.name)),f.push(d)),h.push(d)}return a(r.__originalMappings,n.compareByOriginalPositions),r},c.prototype._version=3,Object.defineProperty(c.prototype,"sources",{get:function(){return this._absoluteSources.slice()}}),c.prototype._parseMappings=function(t,e){for(var r,o,i,u,c,h=1,f=0,p=0,g=0,m=0,d=0,y=t.length,v=0,w={},b={},_=[],A=[];v<y;)if(";"===t.charAt(v))h++,v++,f=0;else if(","===t.charAt(v))v++;else{for((r=new l).generatedLine=h,u=v;u<y&&!this._charIsMappingSeparator(t,u);u++);if(i=w[o=t.slice(v,u)])v+=o.length;else{for(i=[];v<u;)s.decode(t,v,b),c=b.value,v=b.rest,i.push(c);if(2===i.length)throw new Error("Found a source, but no line and column");if(3===i.length)throw new Error("Found a source and line, but no column");w[o]=i}r.generatedColumn=f+i[0],f=r.generatedColumn,i.length>1&&(r.source=m+i[1],m+=i[1],r.originalLine=p+i[2],p=r.originalLine,r.originalLine+=1,r.originalColumn=g+i[3],g=r.originalColumn,i.length>4&&(r.name=d+i[4],d+=i[4])),A.push(r),"number"==typeof r.originalLine&&_.push(r)}a(A,n.compareByGeneratedPositionsDeflated),this.__generatedMappings=A,a(_,n.compareByOriginalPositions),this.__originalMappings=_},c.prototype._findMapping=function(t,e,r,n,i,s){if(t[r]<=0)throw new TypeError("Line must be greater than or equal to 1, got "+t[r]);if(t[n]<0)throw new TypeError("Column must be greater than or equal to 0, got "+t[n]);return o.search(t,e,i,s)},c.prototype.computeColumnSpans=function(){for(var t=0;t<this._generatedMappings.length;++t){var e=this._generatedMappings[t];if(t+1<this._generatedMappings.length){var r=this._generatedMappings[t+1];if(e.generatedLine===r.generatedLine){e.lastGeneratedColumn=r.generatedColumn-1;continue}}e.lastGeneratedColumn=1/0}},c.prototype.originalPositionFor=function(t){var e={generatedLine:n.getArg(t,"line"),generatedColumn:n.getArg(t,"column")},r=this._findMapping(e,this._generatedMappings,"generatedLine","generatedColumn",n.compareByGeneratedPositionsDeflated,n.getArg(t,"bias",u.GREATEST_LOWER_BOUND));if(r>=0){var o=this._generatedMappings[r];if(o.generatedLine===e.generatedLine){var i=n.getArg(o,"source",null);null!==i&&(i=this._sources.at(i),i=n.computeSourceURL(this.sourceRoot,i,this._sourceMapURL));var s=n.getArg(o,"name",null);return null!==s&&(s=this._names.at(s)),{source:i,line:n.getArg(o,"originalLine",null),column:n.getArg(o,"originalColumn",null),name:s}}}return{source:null,line:null,column:null,name:null}},c.prototype.hasContentsOfAllSources=function(){return!!this.sourcesContent&&(this.sourcesContent.length>=this._sources.size()&&!this.sourcesContent.some((function(t){return null==t})))},c.prototype.sourceContentFor=function(t,e){if(!this.sourcesContent)return null;var r=this._findSourceIndex(t);if(r>=0)return this.sourcesContent[r];var o,i=t;if(null!=this.sourceRoot&&(i=n.relative(this.sourceRoot,i)),null!=this.sourceRoot&&(o=n.urlParse(this.sourceRoot))){var s=i.replace(/^file:\/\//,"");if("file"==o.scheme&&this._sources.has(s))return this.sourcesContent[this._sources.indexOf(s)];if((!o.path||"/"==o.path)&&this._sources.has("/"+i))return this.sourcesContent[this._sources.indexOf("/"+i)]}if(e)return null;throw new Error('"'+i+'" is not in the SourceMap.')},c.prototype.generatedPositionFor=function(t){var e=n.getArg(t,"source");if((e=this._findSourceIndex(e))<0)return{line:null,column:null,lastColumn:null};var r={source:e,originalLine:n.getArg(t,"line"),originalColumn:n.getArg(t,"column")},o=this._findMapping(r,this._originalMappings,"originalLine","originalColumn",n.compareByOriginalPositions,n.getArg(t,"bias",u.GREATEST_LOWER_BOUND));if(o>=0){var i=this._originalMappings[o];if(i.source===r.source)return{line:n.getArg(i,"generatedLine",null),column:n.getArg(i,"generatedColumn",null),lastColumn:n.getArg(i,"lastGeneratedColumn",null)}}return{line:null,column:null,lastColumn:null}},r.BasicSourceMapConsumer=c,h.prototype=Object.create(u.prototype),h.prototype.constructor=u,h.prototype._version=3,Object.defineProperty(h.prototype,"sources",{get:function(){for(var t=[],e=0;e<this._sections.length;e++)for(var r=0;r<this._sections[e].consumer.sources.length;r++)t.push(this._sections[e].consumer.sources[r]);return t}}),h.prototype.originalPositionFor=function(t){var e={generatedLine:n.getArg(t,"line"),generatedColumn:n.getArg(t,"column")},r=o.search(e,this._sections,(function(t,e){var r=t.generatedLine-e.generatedOffset.generatedLine;return r||t.generatedColumn-e.generatedOffset.generatedColumn})),i=this._sections[r];return i?i.consumer.originalPositionFor({line:e.generatedLine-(i.generatedOffset.generatedLine-1),column:e.generatedColumn-(i.generatedOffset.generatedLine===e.generatedLine?i.generatedOffset.generatedColumn-1:0),bias:t.bias}):{source:null,line:null,column:null,name:null}},h.prototype.hasContentsOfAllSources=function(){return this._sections.every((function(t){return t.consumer.hasContentsOfAllSources()}))},h.prototype.sourceContentFor=function(t,e){for(var r=0;r<this._sections.length;r++){var n=this._sections[r].consumer.sourceContentFor(t,!0);if(n)return n}if(e)return null;throw new Error('"'+t+'" is not in the SourceMap.')},h.prototype.generatedPositionFor=function(t){for(var e=0;e<this._sections.length;e++){var r=this._sections[e];if(-1!==r.consumer._findSourceIndex(n.getArg(t,"source"))){var o=r.consumer.generatedPositionFor(t);if(o)return{line:o.line+(r.generatedOffset.generatedLine-1),column:o.column+(r.generatedOffset.generatedLine===o.line?r.generatedOffset.generatedColumn-1:0)}}}return{line:null,column:null}},h.prototype._parseMappings=function(t,e){this.__generatedMappings=[],this.__originalMappings=[];for(var r=0;r<this._sections.length;r++)for(var o=this._sections[r],i=o.consumer._generatedMappings,s=0;s<i.length;s++){var u=i[s],c=o.consumer._sources.at(u.source);c=n.computeSourceURL(o.consumer.sourceRoot,c,this._sourceMapURL),this._sources.add(c),c=this._sources.indexOf(c);var l=null;u.name&&(l=o.consumer._names.at(u.name),this._names.add(l),l=this._names.indexOf(l));var h={source:c,generatedLine:u.generatedLine+(o.generatedOffset.generatedLine-1),generatedColumn:u.generatedColumn+(o.generatedOffset.generatedLine===u.generatedLine?o.generatedOffset.generatedColumn-1:0),originalLine:u.originalLine,originalColumn:u.originalColumn,name:l};this.__generatedMappings.push(h),"number"==typeof h.originalLine&&this.__originalMappings.push(h)}a(this.__generatedMappings,n.compareByGeneratedPositionsDeflated),a(this.__originalMappings,n.compareByOriginalPositions)},r.IndexedSourceMapConsumer=h},{"./array-set":26,"./base64-vlq":27,"./binary-search":29,"./quick-sort":31,"./util":35}],33:[function(t,e,r){var n=t("./base64-vlq"),o=t("./util"),i=t("./array-set").ArraySet,s=t("./mapping-list").MappingList;function a(t){t||(t={}),this._file=o.getArg(t,"file",null),this._sourceRoot=o.getArg(t,"sourceRoot",null),this._skipValidation=o.getArg(t,"skipValidation",!1),this._sources=new i,this._names=new i,this._mappings=new s,this._sourcesContents=null}a.prototype._version=3,a.fromSourceMap=function(t){var e=t.sourceRoot,r=new a({file:t.file,sourceRoot:e});return t.eachMapping((function(t){var n={generated:{line:t.generatedLine,column:t.generatedColumn}};null!=t.source&&(n.source=t.source,null!=e&&(n.source=o.relative(e,n.source)),n.original={line:t.originalLine,column:t.originalColumn},null!=t.name&&(n.name=t.name)),r.addMapping(n)})),t.sources.forEach((function(n){var i=n;null!==e&&(i=o.relative(e,n)),r._sources.has(i)||r._sources.add(i);var s=t.sourceContentFor(n);null!=s&&r.setSourceContent(n,s)})),r},a.prototype.addMapping=function(t){var e=o.getArg(t,"generated"),r=o.getArg(t,"original",null),n=o.getArg(t,"source",null),i=o.getArg(t,"name",null);this._skipValidation||this._validateMapping(e,r,n,i),null!=n&&(n=String(n),this._sources.has(n)||this._sources.add(n)),null!=i&&(i=String(i),this._names.has(i)||this._names.add(i)),this._mappings.add({generatedLine:e.line,generatedColumn:e.column,originalLine:null!=r&&r.line,originalColumn:null!=r&&r.column,source:n,name:i})},a.prototype.setSourceContent=function(t,e){var r=t;null!=this._sourceRoot&&(r=o.relative(this._sourceRoot,r)),null!=e?(this._sourcesContents||(this._sourcesContents=Object.create(null)),this._sourcesContents[o.toSetString(r)]=e):this._sourcesContents&&(delete this._sourcesContents[o.toSetString(r)],0===Object.keys(this._sourcesContents).length&&(this._sourcesContents=null))},a.prototype.applySourceMap=function(t,e,r){var n=e;if(null==e){if(null==t.file)throw new Error('SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map\'s "file" property. Both were omitted.');n=t.file}var s=this._sourceRoot;null!=s&&(n=o.relative(s,n));var a=new i,u=new i;this._mappings.unsortedForEach((function(e){if(e.source===n&&null!=e.originalLine){var i=t.originalPositionFor({line:e.originalLine,column:e.originalColumn});null!=i.source&&(e.source=i.source,null!=r&&(e.source=o.join(r,e.source)),null!=s&&(e.source=o.relative(s,e.source)),e.originalLine=i.line,e.originalColumn=i.column,null!=i.name&&(e.name=i.name))}var c=e.source;null==c||a.has(c)||a.add(c);var l=e.name;null==l||u.has(l)||u.add(l)}),this),this._sources=a,this._names=u,t.sources.forEach((function(e){var n=t.sourceContentFor(e);null!=n&&(null!=r&&(e=o.join(r,e)),null!=s&&(e=o.relative(s,e)),this.setSourceContent(e,n))}),this)},a.prototype._validateMapping=function(t,e,r,n){if(e&&"number"!=typeof e.line&&"number"!=typeof e.column)throw new Error("original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.");if((!(t&&"line"in t&&"column"in t&&t.line>0&&t.column>=0)||e||r||n)&&!(t&&"line"in t&&"column"in t&&e&&"line"in e&&"column"in e&&t.line>0&&t.column>=0&&e.line>0&&e.column>=0&&r))throw new Error("Invalid mapping: "+JSON.stringify({generated:t,source:r,original:e,name:n}))},a.prototype._serializeMappings=function(){for(var t,e,r,i,s=0,a=1,u=0,c=0,l=0,h=0,f="",p=this._mappings.toArray(),g=0,m=p.length;g<m;g++){if(t="",(e=p[g]).generatedLine!==a)for(s=0;e.generatedLine!==a;)t+=";",a++;else if(g>0){if(!o.compareByGeneratedPositionsInflated(e,p[g-1]))continue;t+=","}t+=n.encode(e.generatedColumn-s),s=e.generatedColumn,null!=e.source&&(i=this._sources.indexOf(e.source),t+=n.encode(i-h),h=i,t+=n.encode(e.originalLine-1-c),c=e.originalLine-1,t+=n.encode(e.originalColumn-u),u=e.originalColumn,null!=e.name&&(r=this._names.indexOf(e.name),t+=n.encode(r-l),l=r)),f+=t}return f},a.prototype._generateSourcesContent=function(t,e){return t.map((function(t){if(!this._sourcesContents)return null;null!=e&&(t=o.relative(e,t));var r=o.toSetString(t);return Object.prototype.hasOwnProperty.call(this._sourcesContents,r)?this._sourcesContents[r]:null}),this)},a.prototype.toJSON=function(){var t={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};return null!=this._file&&(t.file=this._file),null!=this._sourceRoot&&(t.sourceRoot=this._sourceRoot),this._sourcesContents&&(t.sourcesContent=this._generateSourcesContent(t.sources,t.sourceRoot)),t},a.prototype.toString=function(){return JSON.stringify(this.toJSON())},r.SourceMapGenerator=a},{"./array-set":26,"./base64-vlq":27,"./mapping-list":30,"./util":35}],34:[function(t,e,r){var n=t("./source-map-generator").SourceMapGenerator,o=t("./util"),i=/(\r?\n)/,s="$$$isSourceNode$$$";function a(t,e,r,n,o){this.children=[],this.sourceContents={},this.line=null==t?null:t,this.column=null==e?null:e,this.source=null==r?null:r,this.name=null==o?null:o,this[s]=!0,null!=n&&this.add(n)}a.fromStringWithSourceMap=function(t,e,r){var n=new a,s=t.split(i),u=0,c=function(){return t()+(t()||"");function t(){return u<s.length?s[u++]:void 0}},l=1,h=0,f=null;return e.eachMapping((function(t){if(null!==f){if(!(l<t.generatedLine)){var e=(r=s[u]||"").substr(0,t.generatedColumn-h);return s[u]=r.substr(t.generatedColumn-h),h=t.generatedColumn,p(f,e),void(f=t)}p(f,c()),l++,h=0}for(;l<t.generatedLine;)n.add(c()),l++;if(h<t.generatedColumn){var r=s[u]||"";n.add(r.substr(0,t.generatedColumn)),s[u]=r.substr(t.generatedColumn),h=t.generatedColumn}f=t}),this),u<s.length&&(f&&p(f,c()),n.add(s.splice(u).join(""))),e.sources.forEach((function(t){var i=e.sourceContentFor(t);null!=i&&(null!=r&&(t=o.join(r,t)),n.setSourceContent(t,i))})),n;function p(t,e){if(null===t||void 0===t.source)n.add(e);else{var i=r?o.join(r,t.source):t.source;n.add(new a(t.originalLine,t.originalColumn,i,e,t.name))}}},a.prototype.add=function(t){if(Array.isArray(t))t.forEach((function(t){this.add(t)}),this);else{if(!t[s]&&"string"!=typeof t)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+t);t&&this.children.push(t)}return this},a.prototype.prepend=function(t){if(Array.isArray(t))for(var e=t.length-1;e>=0;e--)this.prepend(t[e]);else{if(!t[s]&&"string"!=typeof t)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+t);this.children.unshift(t)}return this},a.prototype.walk=function(t){for(var e,r=0,n=this.children.length;r<n;r++)(e=this.children[r])[s]?e.walk(t):""!==e&&t(e,{source:this.source,line:this.line,column:this.column,name:this.name})},a.prototype.join=function(t){var e,r,n=this.children.length;if(n>0){for(e=[],r=0;r<n-1;r++)e.push(this.children[r]),e.push(t);e.push(this.children[r]),this.children=e}return this},a.prototype.replaceRight=function(t,e){var r=this.children[this.children.length-1];return r[s]?r.replaceRight(t,e):"string"==typeof r?this.children[this.children.length-1]=r.replace(t,e):this.children.push("".replace(t,e)),this},a.prototype.setSourceContent=function(t,e){this.sourceContents[o.toSetString(t)]=e},a.prototype.walkSourceContents=function(t){for(var e=0,r=this.children.length;e<r;e++)this.children[e][s]&&this.children[e].walkSourceContents(t);var n=Object.keys(this.sourceContents);for(e=0,r=n.length;e<r;e++)t(o.fromSetString(n[e]),this.sourceContents[n[e]])},a.prototype.toString=function(){var t="";return this.walk((function(e){t+=e})),t},a.prototype.toStringWithSourceMap=function(t){var e={code:"",line:1,column:0},r=new n(t),o=!1,i=null,s=null,a=null,u=null;return this.walk((function(t,n){e.code+=t,null!==n.source&&null!==n.line&&null!==n.column?(i===n.source&&s===n.line&&a===n.column&&u===n.name||r.addMapping({source:n.source,original:{line:n.line,column:n.column},generated:{line:e.line,column:e.column},name:n.name}),i=n.source,s=n.line,a=n.column,u=n.name,o=!0):o&&(r.addMapping({generated:{line:e.line,column:e.column}}),i=null,o=!1);for(var c=0,l=t.length;c<l;c++)10===t.charCodeAt(c)?(e.line++,e.column=0,c+1===l?(i=null,o=!1):o&&r.addMapping({source:n.source,original:{line:n.line,column:n.column},generated:{line:e.line,column:e.column},name:n.name})):e.column++})),this.walkSourceContents((function(t,e){r.setSourceContent(t,e)})),{code:e.code,map:r}},r.SourceNode=a},{"./source-map-generator":33,"./util":35}],35:[function(t,e,r){r.getArg=function(t,e,r){if(e in t)return t[e];if(3===arguments.length)return r;throw new Error('"'+e+'" is a required argument.')};var n=/^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/,o=/^data:.+\,.+$/;function i(t){var e=t.match(n);return e?{scheme:e[1],auth:e[2],host:e[3],port:e[4],path:e[5]}:null}function s(t){var e="";return t.scheme&&(e+=t.scheme+":"),e+="//",t.auth&&(e+=t.auth+"@"),t.host&&(e+=t.host),t.port&&(e+=":"+t.port),t.path&&(e+=t.path),e}function a(t){var e=t,n=i(t);if(n){if(!n.path)return t;e=n.path}for(var o,a=r.isAbsolute(e),u=e.split(/\/+/),c=0,l=u.length-1;l>=0;l--)"."===(o=u[l])?u.splice(l,1):".."===o?c++:c>0&&(""===o?(u.splice(l+1,c),c=0):(u.splice(l,2),c--));return""===(e=u.join("/"))&&(e=a?"/":"."),n?(n.path=e,s(n)):e}function u(t,e){""===t&&(t="."),""===e&&(e=".");var r=i(e),n=i(t);if(n&&(t=n.path||"/"),r&&!r.scheme)return n&&(r.scheme=n.scheme),s(r);if(r||e.match(o))return e;if(n&&!n.host&&!n.path)return n.host=e,s(n);var u="/"===e.charAt(0)?e:a(t.replace(/\/+$/,"")+"/"+e);return n?(n.path=u,s(n)):u}r.urlParse=i,r.urlGenerate=s,r.normalize=a,r.join=u,r.isAbsolute=function(t){return"/"===t.charAt(0)||n.test(t)},r.relative=function(t,e){""===t&&(t="."),t=t.replace(/\/$/,"");for(var r=0;0!==e.indexOf(t+"/");){var n=t.lastIndexOf("/");if(n<0)return e;if((t=t.slice(0,n)).match(/^([^\/]+:\/)?\/*$/))return e;++r}return Array(r+1).join("../")+e.substr(t.length+1)};var c=!("__proto__"in Object.create(null));function l(t){return t}function h(t){if(!t)return!1;var e=t.length;if(e<9)return!1;if(95!==t.charCodeAt(e-1)||95!==t.charCodeAt(e-2)||111!==t.charCodeAt(e-3)||116!==t.charCodeAt(e-4)||111!==t.charCodeAt(e-5)||114!==t.charCodeAt(e-6)||112!==t.charCodeAt(e-7)||95!==t.charCodeAt(e-8)||95!==t.charCodeAt(e-9))return!1;for(var r=e-10;r>=0;r--)if(36!==t.charCodeAt(r))return!1;return!0}function f(t,e){return t===e?0:null===t?1:null===e?-1:t>e?1:-1}r.toSetString=c?l:function(t){return h(t)?"$"+t:t},r.fromSetString=c?l:function(t){return h(t)?t.slice(1):t},r.compareByOriginalPositions=function(t,e,r){var n=f(t.source,e.source);return 0!==n?n:0!==(n=t.originalLine-e.originalLine)?n:0!==(n=t.originalColumn-e.originalColumn)||r?n:0!==(n=t.generatedColumn-e.generatedColumn)?n:0!==(n=t.generatedLine-e.generatedLine)?n:f(t.name,e.name)},r.compareByGeneratedPositionsDeflated=function(t,e,r){var n=t.generatedLine-e.generatedLine;return 0!==n?n:0!==(n=t.generatedColumn-e.generatedColumn)||r?n:0!==(n=f(t.source,e.source))?n:0!==(n=t.originalLine-e.originalLine)?n:0!==(n=t.originalColumn-e.originalColumn)?n:f(t.name,e.name)},r.compareByGeneratedPositionsInflated=function(t,e){var r=t.generatedLine-e.generatedLine;return 0!==r?r:0!==(r=t.generatedColumn-e.generatedColumn)?r:0!==(r=f(t.source,e.source))?r:0!==(r=t.originalLine-e.originalLine)?r:0!==(r=t.originalColumn-e.originalColumn)?r:f(t.name,e.name)},r.parseSourceMapInput=function(t){return JSON.parse(t.replace(/^\)]}'[^\n]*\n/,""))},r.computeSourceURL=function(t,e,r){if(e=e||"",t&&("/"!==t[t.length-1]&&"/"!==e[0]&&(t+="/"),e=t+e),r){var n=i(r);if(!n)throw new Error("sourceMapURL could not be parsed");if(n.path){var o=n.path.lastIndexOf("/");o>=0&&(n.path=n.path.substring(0,o+1))}e=u(s(n),e)}return a(e)}},{}],36:[function(t,e,r){r.SourceMapGenerator=t("./lib/source-map-generator").SourceMapGenerator,r.SourceMapConsumer=t("./lib/source-map-consumer").SourceMapConsumer,r.SourceNode=t("./lib/source-node").SourceNode},{"./lib/source-map-consumer":32,"./lib/source-map-generator":33,"./lib/source-node":34}]},{},[14]);/**
* Calculates the specificity of CSS selectors
* https://github.com/keeganstreet/specificity - licensed under MIT.
*
* Returns an array of objects with the following properties:
* - selector: the input
* - specificity: e.g. 0,1,0,0
* - parts: array with details about each part of the selector that counts towards the specificity
*/
var SPECIFICITY = (function() {
var calculate,
calculateSingle;
calculate = function(input) {
var selectors,
selector,
i,
len,
results = [];
// Separate input by commas
selectors = input.split(',');
for (i = 0, len = selectors.length; i < len; i += 1) {
selector = selectors[i];
if (selector.length > 0) {
results.push(calculateSingle(selector));
}
}
return results;
};
// Calculate the specificity for a selector by dividing it into simple selectors and counting them
calculateSingle = function(input) {
var selector = input,
findMatch,
typeCount = {
'a': 0,
'b': 0,
'c': 0
},
parts = [],
// The following regular expressions assume that selectors matching the preceding regular expressions have been removed
attributeRegex = /(\[[^\]]+\])/g,
idRegex = /(#[^\s\+>~\.\[:]+)/g,
classRegex = /(\.[^\s\+>~\.\[:]+)/g,
pseudoElementRegex = /(::[^\s\+>~\.\[:]+|:first-line|:first-letter|:before|:after)/gi,
// A regex for pseudo classes with brackets - :nth-child(), :nth-last-child(), :nth-of-type(), :nth-last-type(), :lang()
pseudoClassWithBracketsRegex = /(:[\w-]+\([^\)]*\))/gi,
// A regex for other pseudo classes, which don't have brackets
pseudoClassRegex = /(:[^\s\+>~\.\[:]+)/g,
elementRegex = /([^\s\+>~\.\[:]+)/g;
// Find matches for a regular expression in a string and push their details to parts
// Type is "a" for IDs, "b" for classes, attributes and pseudo-classes and "c" for elements and pseudo-elements
findMatch = function(regex, type) {
var matches, i, len, match, index, length;
if (regex.test(selector)) {
matches = selector.match(regex);
for (i = 0, len = matches.length; i < len; i += 1) {
typeCount[type] += 1;
match = matches[i];
index = selector.indexOf(match);
length = match.length;
parts.push({
selector: match,
type: type,
index: index,
length: length
});
// Replace this simple selector with whitespace so it won't be counted in further simple selectors
selector = selector.replace(match, Array(length + 1).join(' '));
}
}
};
// Remove the negation psuedo-class (:not) but leave its argument because specificity is calculated on its argument
(function() {
var regex = /:not\(([^\)]*)\)/g;
if (regex.test(selector)) {
selector = selector.replace(regex, ' $1 ');
}
}());
// Remove anything after a left brace in case a user has pasted in a rule, not just a selector
(function() {
var regex = /{[^]*/gm,
matches, i, len, match;
if (regex.test(selector)) {
matches = selector.match(regex);
for (i = 0, len = matches.length; i < len; i += 1) {
match = matches[i];
selector = selector.replace(match, Array(match.length + 1).join(' '));
}
}
}());
// Add attribute selectors to parts collection (type b)
findMatch(attributeRegex, 'b');
// Add ID selectors to parts collection (type a)
findMatch(idRegex, 'a');
// Add class selectors to parts collection (type b)
findMatch(classRegex, 'b');
// Add pseudo-element selectors to parts collection (type c)
findMatch(pseudoElementRegex, 'c');
// Add pseudo-class selectors to parts collection (type b)
findMatch(pseudoClassWithBracketsRegex, 'b');
findMatch(pseudoClassRegex, 'b');
// Remove universal selector and separator characters
selector = selector.replace(/[\*\s\+>~]/g, ' ');
// Remove any stray dots or hashes which aren't attached to words
// These may be present if the user is live-editing this selector
selector = selector.replace(/[#\.]/g, ' ');
// The only things left should be element selectors (type c)
findMatch(elementRegex, 'c');
// Order the parts in the order they appear in the original selector
// This is neater for external apps to deal with
parts.sort(function(a, b) {
return a.index - b.index;
});
return {
selector: input,
specificity: '0,' + typeCount.a.toString() + ',' + typeCount.b.toString() + ',' + typeCount.c.toString(),
parts: parts
};
};
return {
calculate: calculate
};
}());/*!
* URI.js - Mutating URLs
*
* Version: 1.18.1
*
* Author: Rodney Rehm
* Web: http://medialize.github.io/URI.js/
*
* Licensed under
* MIT License http://www.opensource.org/licenses/mit-license
*
*/
!function(t,e){"use strict";t.URI=function(t,e,r,s){var n=s&&s.URI;function a(t,e){var r=arguments.length>=1,s=arguments.length>=2;if(!(this instanceof a))return r?s?new a(t,e):new a(t):new a;if(void 0===t){if(r)throw new TypeError("undefined is not a valid argument for URI");t="undefined"!=typeof location?location.href+"":""}return this.href(t),void 0!==e?this.absoluteTo(e):this}a.version="1.18.1";var i=a.prototype,o=Object.prototype.hasOwnProperty;function h(t){return t.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function u(t){return void 0===t?"Undefined":String(Object.prototype.toString.call(t)).slice(8,-1)}function p(t){return"Array"===u(t)}function c(t,e){var r,s,n={};if("RegExp"===u(e))n=null;else if(p(e))for(r=0,s=e.length;r<s;r++)n[e[r]]=!0;else n[e]=!0;for(r=0,s=t.length;r<s;r++){(n&&void 0!==n[t[r]]||!n&&e.test(t[r]))&&(t.splice(r,1),s--,r--)}return t}function l(t,e){var r,s;if(p(e)){for(r=0,s=e.length;r<s;r++)if(!l(t,e[r]))return!1;return!0}var n=u(e);for(r=0,s=t.length;r<s;r++)if("RegExp"===n){if("string"==typeof t[r]&&t[r].match(e))return!0}else if(t[r]===e)return!0;return!1}function d(t,e){if(!p(t)||!p(e))return!1;if(t.length!==e.length)return!1;t.sort(),e.sort();for(var r=0,s=t.length;r<s;r++)if(t[r]!==e[r])return!1;return!0}function f(t){return t.replace(/^\/+|\/+$/g,"")}function m(t){return escape(t)}function g(t){return encodeURIComponent(t).replace(/[!'()*]/g,m).replace(/\*/g,"%2A")}a._parts=function(){return{protocol:null,username:null,password:null,hostname:null,urn:null,port:null,path:null,query:null,fragment:null,duplicateQueryParameters:a.duplicateQueryParameters,escapeQuerySpace:a.escapeQuerySpace}},a.duplicateQueryParameters=!1,a.escapeQuerySpace=!0,a.protocol_expression=/^[a-z][a-z0-9.+-]*$/i,a.idn_expression=/[^a-z0-9\.-]/i,a.punycode_expression=/(xn--)/i,a.ip4_expression=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,a.ip6_expression=/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,a.find_uri_expression=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,a.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},a.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},a.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,a.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},a.getDomAttribute=function(t){if(t&&t.nodeName){var e=t.nodeName.toLowerCase();if("input"!==e||"image"===t.type)return a.domAttributes[e]}},a.encode=g,a.decode=decodeURIComponent,a.iso8859=function(){a.encode=escape,a.decode=unescape},a.unicode=function(){a.encode=g,a.decode=decodeURIComponent},a.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},a.encodeQuery=function(t,e){var r=a.encode(t+"");return void 0===e&&(e=a.escapeQuerySpace),e?r.replace(/%20/g,"+"):r},a.decodeQuery=function(t,e){t+="",void 0===e&&(e=a.escapeQuerySpace);try{return a.decode(e?t.replace(/\+/g,"%20"):t)}catch(e){return t}};var _,y={encode:"encode",decode:"decode"},v=function(t,e){return function(r){try{return a[e](r+"").replace(a.characters[t][e].expression,(function(r){return a.characters[t][e].map[r]}))}catch(t){return r}}};for(_ in y)a[_+"PathSegment"]=v("pathname",y[_]),a[_+"UrnPathSegment"]=v("urnpath",y[_]);var b=function(t,e,r){return function(s){var n;n=r?function(t){return a[e](a[r](t))}:a[e];for(var i=(s+"").split(t),o=0,h=i.length;o<h;o++)i[o]=n(i[o]);return i.join(t)}};function w(t){return function(e,r){return void 0===e?this._parts[t]||"":(this._parts[t]=e||null,this.build(!r),this)}}function Q(t,e){return function(r,s){return void 0===r?this._parts[t]||"":(null!==r&&(r+="").charAt(0)===e&&(r=r.substring(1)),this._parts[t]=r,this.build(!s),this)}}a.decodePath=b("/","decodePathSegment"),a.decodeUrnPath=b(":","decodeUrnPathSegment"),a.recodePath=b("/","encodePathSegment","decode"),a.recodeUrnPath=b(":","encodeUrnPathSegment","decode"),a.encodeReserved=v("reserved","encode"),a.parse=function(t,e){var r;return e||(e={}),(r=t.indexOf("#"))>-1&&(e.fragment=t.substring(r+1)||null,t=t.substring(0,r)),(r=t.indexOf("?"))>-1&&(e.query=t.substring(r+1)||null,t=t.substring(0,r)),"//"===t.substring(0,2)?(e.protocol=null,t=t.substring(2),t=a.parseAuthority(t,e)):(r=t.indexOf(":"))>-1&&(e.protocol=t.substring(0,r)||null,e.protocol&&!e.protocol.match(a.protocol_expression)?e.protocol=void 0:"//"===t.substring(r+1,r+3)?(t=t.substring(r+3),t=a.parseAuthority(t,e)):(t=t.substring(r+1),e.urn=!0)),e.path=t,e},a.parseHost=function(t,e){var r,s,n=(t=t.replace(/\\/g,"/")).indexOf("/");if(-1===n&&(n=t.length),"["===t.charAt(0))r=t.indexOf("]"),e.hostname=t.substring(1,r)||null,e.port=t.substring(r+2,n)||null,"/"===e.port&&(e.port=null);else{var a=t.indexOf(":"),i=t.indexOf("/"),o=t.indexOf(":",a+1);-1!==o&&(-1===i||o<i)?(e.hostname=t.substring(0,n)||null,e.port=null):(s=t.substring(0,n).split(":"),e.hostname=s[0]||null,e.port=s[1]||null)}return e.hostname&&"/"!==t.substring(n).charAt(0)&&(n++,t="/"+t),t.substring(n)||"/"},a.parseAuthority=function(t,e){return t=a.parseUserinfo(t,e),a.parseHost(t,e)},a.parseUserinfo=function(t,e){var r,s=t.indexOf("/"),n=t.lastIndexOf("@",s>-1?s:t.length-1);return n>-1&&(-1===s||n<s)?(r=t.substring(0,n).split(":"),e.username=r[0]?a.decode(r[0]):null,r.shift(),e.password=r[0]?a.decode(r.join(":")):null,t=t.substring(n+1)):(e.username=null,e.password=null),t},a.parseQuery=function(t,e){if(!t)return{};if(!(t=t.replace(/&+/g,"&").replace(/^\?*&*|&+$/g,"")))return{};for(var r,s,n,i={},h=t.split("&"),u=h.length,p=0;p<u;p++)r=h[p].split("="),s=a.decodeQuery(r.shift(),e),n=r.length?a.decodeQuery(r.join("="),e):null,o.call(i,s)?("string"!=typeof i[s]&&null!==i[s]||(i[s]=[i[s]]),i[s].push(n)):i[s]=n;return i},a.build=function(t){var e="";return t.protocol&&(e+=t.protocol+":"),t.urn||!e&&!t.hostname||(e+="//"),e+=a.buildAuthority(t)||"","string"==typeof t.path&&("/"!==t.path.charAt(0)&&"string"==typeof t.hostname&&(e+="/"),e+=t.path),"string"==typeof t.query&&t.query&&(e+="?"+t.query),"string"==typeof t.fragment&&t.fragment&&(e+="#"+t.fragment),e},a.buildHost=function(t){var e="";return t.hostname?(a.ip6_expression.test(t.hostname)?e+="["+t.hostname+"]":e+=t.hostname,t.port&&(e+=":"+t.port),e):""},a.buildAuthority=function(t){return a.buildUserinfo(t)+a.buildHost(t)},a.buildUserinfo=function(t){var e="";return t.username&&(e+=a.encode(t.username)),t.password&&(e+=":"+a.encode(t.password)),e&&(e+="@"),e},a.buildQuery=function(t,e,r){var s,n,i,h,u="";for(n in t)if(o.call(t,n)&&n)if(p(t[n]))for(s={},i=0,h=t[n].length;i<h;i++)void 0!==t[n][i]&&void 0===s[t[n][i]+""]&&(u+="&"+a.buildQueryParameter(n,t[n][i],r),!0!==e&&(s[t[n][i]+""]=!0));else void 0!==t[n]&&(u+="&"+a.buildQueryParameter(n,t[n],r));return u.substring(1)},a.buildQueryParameter=function(t,e,r){return a.encodeQuery(t,r)+(null!==e?"="+a.encodeQuery(e,r):"")},a.addQuery=function(t,e,r){if("object"==typeof e)for(var s in e)o.call(e,s)&&a.addQuery(t,s,e[s]);else{if("string"!=typeof e)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");if(void 0===t[e])return void(t[e]=r);"string"==typeof t[e]&&(t[e]=[t[e]]),p(r)||(r=[r]),t[e]=(t[e]||[]).concat(r)}},a.removeQuery=function(t,e,r){var s,n,i;if(p(e))for(s=0,n=e.length;s<n;s++)t[e[s]]=void 0;else if("RegExp"===u(e))for(i in t)e.test(i)&&(t[i]=void 0);else if("object"==typeof e)for(i in e)o.call(e,i)&&a.removeQuery(t,i,e[i]);else{if("string"!=typeof e)throw new TypeError("URI.removeQuery() accepts an object, string, RegExp as the first parameter");void 0!==r?"RegExp"===u(r)?!p(t[e])&&r.test(t[e])?t[e]=void 0:t[e]=c(t[e],r):t[e]!==String(r)||p(r)&&1!==r.length?p(t[e])&&(t[e]=c(t[e],r)):t[e]=void 0:t[e]=void 0}},a.hasQuery=function(t,e,r,s){switch(u(e)){case"String":break;case"RegExp":for(var n in t)if(o.call(t,n)&&e.test(n)&&(void 0===r||a.hasQuery(t,n,r)))return!0;return!1;case"Object":for(var i in e)if(o.call(e,i)&&!a.hasQuery(t,i,e[i]))return!1;return!0;default:throw new TypeError("URI.hasQuery() accepts a string, regular expression or object as the name parameter")}switch(u(r)){case"Undefined":return e in t;case"Boolean":return r===Boolean(p(t[e])?t[e].length:t[e]);case"Function":return!!r(t[e],e,t);case"Array":return!!p(t[e])&&(s?l:d)(t[e],r);case"RegExp":return p(t[e])?!!s&&l(t[e],r):Boolean(t[e]&&t[e].match(r));case"Number":r=String(r);case"String":return p(t[e])?!!s&&l(t[e],r):t[e]===r;default:throw new TypeError("URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter")}},a.joinPaths=function(){for(var t=[],e=[],r=0,s=0;s<arguments.length;s++){var n=new a(arguments[s]);t.push(n);for(var i=n.segment(),o=0;o<i.length;o++)"string"==typeof i[o]&&e.push(i[o]),i[o]&&r++}if(!e.length||!r)return new a("");var h=new a("").segment(e);return""!==t[0].path()&&"/"!==t[0].path().slice(0,1)||h.path("/"+h.path()),h.normalize()},a.commonPath=function(t,e){var r,s=Math.min(t.length,e.length);for(r=0;r<s;r++)if(t.charAt(r)!==e.charAt(r)){r--;break}return r<1?t.charAt(0)===e.charAt(0)&&"/"===t.charAt(0)?"/":"":("/"===t.charAt(r)&&"/"===e.charAt(r)||(r=t.substring(0,r).lastIndexOf("/")),t.substring(0,r+1))},a.withinString=function(t,e,r){r||(r={});var s=r.start||a.findUri.start,n=r.end||a.findUri.end,i=r.trim||a.findUri.trim,o=/[a-z0-9-]=["']?$/i;for(s.lastIndex=0;;){var h=s.exec(t);if(!h)break;var u=h.index;if(r.ignoreHtml){var p=t.slice(Math.max(u-3,0),u);if(p&&o.test(p))continue}var c=u+t.slice(u).search(n),l=t.slice(u,c).replace(i,"");if(!r.ignore||!r.ignore.test(l)){var d=e(l,u,c=u+l.length,t);t=t.slice(0,u)+d+t.slice(c),s.lastIndex=u+d.length}}return s.lastIndex=0,t},a.ensureValidHostname=function(e){if(e.match(a.invalid_hostname_characters)){if(!t)throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-] and Punycode.js is not available');if(t.toASCII(e).match(a.invalid_hostname_characters))throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-]')}},a.noConflict=function(t){if(t){var e={URI:this.noConflict()};return s.URITemplate&&"function"==typeof s.URITemplate.noConflict&&(e.URITemplate=s.URITemplate.noConflict()),s.IPv6&&"function"==typeof s.IPv6.noConflict&&(e.IPv6=s.IPv6.noConflict()),s.SecondLevelDomains&&"function"==typeof s.SecondLevelDomains.noConflict&&(e.SecondLevelDomains=s.SecondLevelDomains.noConflict()),e}return s.URI===this&&(s.URI=n),this},i.build=function(t){return!0===t?this._deferred_build=!0:(void 0===t||this._deferred_build)&&(this._string=a.build(this._parts),this._deferred_build=!1),this},i.clone=function(){return new a(this)},i.valueOf=i.toString=function(){return this.build(!1)._string},i.protocol=w("protocol"),i.username=w("username"),i.password=w("password"),i.hostname=w("hostname"),i.port=w("port"),i.query=Q("query","?"),i.fragment=Q("fragment","#"),i.search=function(t,e){var r=this.query(t,e);return"string"==typeof r&&r.length?"?"+r:r},i.hash=function(t,e){var r=this.fragment(t,e);return"string"==typeof r&&r.length?"#"+r:r},i.pathname=function(t,e){if(void 0===t||!0===t){var r=this._parts.path||(this._parts.hostname?"/":"");return t?(this._parts.urn?a.decodeUrnPath:a.decodePath)(r):r}return this._parts.urn?this._parts.path=t?a.recodeUrnPath(t):"":this._parts.path=t?a.recodePath(t):"/",this.build(!e),this},i.path=i.pathname,i.href=function(t,e){var r;if(void 0===t)return this.toString();this._string="",this._parts=a._parts();var s=t instanceof a,n="object"==typeof t&&(t.hostname||t.path||t.pathname);t.nodeName&&(t=t[a.getDomAttribute(t)]||"",n=!1);if(!s&&n&&void 0!==t.pathname&&(t=t.toString()),"string"==typeof t||t instanceof String)this._parts=a.parse(String(t),this._parts);else{if(!s&&!n)throw new TypeError("invalid input");var i=s?t._parts:t;for(r in i)o.call(this._parts,r)&&(this._parts[r]=i[r])}return this.build(!e),this},i.is=function(t){var e=!1,s=!1,n=!1,i=!1,o=!1,h=!1,u=!1,p=!this._parts.urn;switch(this._parts.hostname&&(p=!1,s=a.ip4_expression.test(this._parts.hostname),n=a.ip6_expression.test(this._parts.hostname),o=(i=!(e=s||n))&&r&&r.has(this._parts.hostname),h=i&&a.idn_expression.test(this._parts.hostname),u=i&&a.punycode_expression.test(this._parts.hostname)),t.toLowerCase()){case"relative":return p;case"absolute":return!p;case"domain":case"name":return i;case"sld":return o;case"ip":return e;case"ip4":case"ipv4":case"inet4":return s;case"ip6":case"ipv6":case"inet6":return n;case"idn":return h;case"url":return!this._parts.urn;case"urn":return!!this._parts.urn;case"punycode":return u}return null};var A=i.protocol,P=i.port,x=i.hostname;i.protocol=function(t,e){if(void 0!==t&&t&&!(t=t.replace(/:(\/\/)?$/,"")).match(a.protocol_expression))throw new TypeError('Protocol "'+t+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return A.call(this,t,e)},i.scheme=i.protocol,i.port=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0!==t&&(0===t&&(t=null),t&&(":"===(t+="").charAt(0)&&(t=t.substring(1)),t.match(/[^0-9]/))))throw new TypeError('Port "'+t+'" contains characters other than [0-9]');return P.call(this,t,e)},i.hostname=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0!==t){var r={};if("/"!==a.parseHost(t,r))throw new TypeError('Hostname "'+t+'" contains characters other than [A-Z0-9.-]');t=r.hostname}return x.call(this,t,e)},i.origin=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t){var r=this.protocol();return this.authority()?(r?r+"://":"")+this.authority():""}var s=a(t);return this.protocol(s.protocol()).authority(s.authority()).build(!e),this},i.host=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t)return this._parts.hostname?a.buildHost(this._parts):"";if("/"!==a.parseHost(t,this._parts))throw new TypeError('Hostname "'+t+'" contains characters other than [A-Z0-9.-]');return this.build(!e),this},i.authority=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t)return this._parts.hostname?a.buildAuthority(this._parts):"";if("/"!==a.parseAuthority(t,this._parts))throw new TypeError('Hostname "'+t+'" contains characters other than [A-Z0-9.-]');return this.build(!e),this},i.userinfo=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t){var r=a.buildUserinfo(this._parts);return r?r.substring(0,r.length-1):r}return"@"!==t[t.length-1]&&(t+="@"),a.parseUserinfo(t,this._parts),this.build(!e),this},i.resource=function(t,e){var r;return void 0===t?this.path()+this.search()+this.hash():(r=a.parse(t),this._parts.path=r.path,this._parts.query=r.query,this._parts.fragment=r.fragment,this.build(!e),this)},i.subdomain=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,r)||""}var s=this._parts.hostname.length-this.domain().length,n=this._parts.hostname.substring(0,s),i=new RegExp("^"+h(n));return t&&"."!==t.charAt(t.length-1)&&(t+="."),t&&a.ensureValidHostname(t),this._parts.hostname=this._parts.hostname.replace(i,t),this.build(!e),this},i.domain=function(t,e){if(this._parts.urn)return void 0===t?"":this;if("boolean"==typeof t&&(e=t,t=void 0),void 0===t){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.match(/\./g);if(r&&r.length<2)return this._parts.hostname;var s=this._parts.hostname.length-this.tld(e).length-1;return s=this._parts.hostname.lastIndexOf(".",s-1)+1,this._parts.hostname.substring(s)||""}if(!t)throw new TypeError("cannot set domain empty");if(a.ensureValidHostname(t),!this._parts.hostname||this.is("IP"))this._parts.hostname=t;else{var n=new RegExp(h(this.domain())+"$");this._parts.hostname=this._parts.hostname.replace(n,t)}return this.build(!e),this},i.tld=function(t,e){if(this._parts.urn)return void 0===t?"":this;if("boolean"==typeof t&&(e=t,t=void 0),void 0===t){if(!this._parts.hostname||this.is("IP"))return"";var s=this._parts.hostname.lastIndexOf("."),n=this._parts.hostname.substring(s+1);return!0!==e&&r&&r.list[n.toLowerCase()]&&r.get(this._parts.hostname)||n}var a;if(!t)throw new TypeError("cannot set TLD empty");if(t.match(/[^a-zA-Z0-9-]/)){if(!r||!r.is(t))throw new TypeError('TLD "'+t+'" contains characters other than [A-Z0-9]');a=new RegExp(h(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(a,t)}else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");a=new RegExp(h(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(a,t)}return this.build(!e),this},i.directory=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t||!0===t){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var r=this._parts.path.length-this.filename().length-1,s=this._parts.path.substring(0,r)||(this._parts.hostname?"/":"");return t?a.decodePath(s):s}var n=this._parts.path.length-this.filename().length,i=this._parts.path.substring(0,n),o=new RegExp("^"+h(i));return this.is("relative")||(t||(t="/"),"/"!==t.charAt(0)&&(t="/"+t)),t&&"/"!==t.charAt(t.length-1)&&(t+="/"),t=a.recodePath(t),this._parts.path=this._parts.path.replace(o,t),this.build(!e),this},i.filename=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t||!0===t){if(!this._parts.path||"/"===this._parts.path)return"";var r=this._parts.path.lastIndexOf("/"),s=this._parts.path.substring(r+1);return t?a.decodePathSegment(s):s}var n=!1;"/"===t.charAt(0)&&(t=t.substring(1)),t.match(/\.?\//)&&(n=!0);var i=new RegExp(h(this.filename())+"$");return t=a.recodePath(t),this._parts.path=this._parts.path.replace(i,t),n?this.normalizePath(e):this.build(!e),this},i.suffix=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t||!0===t){if(!this._parts.path||"/"===this._parts.path)return"";var r,s,n=this.filename(),i=n.lastIndexOf(".");return-1===i?"":(r=n.substring(i+1),s=/^[a-z0-9%]+$/i.test(r)?r:"",t?a.decodePathSegment(s):s)}"."===t.charAt(0)&&(t=t.substring(1));var o,u=this.suffix();if(u)o=t?new RegExp(h(u)+"$"):new RegExp(h("."+u)+"$");else{if(!t)return this;this._parts.path+="."+a.recodePath(t)}return o&&(t=a.recodePath(t),this._parts.path=this._parts.path.replace(o,t)),this.build(!e),this},i.segment=function(t,e,r){var s=this._parts.urn?":":"/",n=this.path(),a="/"===n.substring(0,1),i=n.split(s);if(void 0!==t&&"number"!=typeof t&&(r=e,e=t,t=void 0),void 0!==t&&"number"!=typeof t)throw new Error('Bad segment "'+t+'", must be 0-based integer');if(a&&i.shift(),t<0&&(t=Math.max(i.length+t,0)),void 0===e)return void 0===t?i:i[t];if(null===t||void 0===i[t])if(p(e)){i=[];for(var o=0,h=e.length;o<h;o++)(e[o].length||i.length&&i[i.length-1].length)&&(i.length&&!i[i.length-1].length&&i.pop(),i.push(f(e[o])))}else(e||"string"==typeof e)&&(e=f(e),""===i[i.length-1]?i[i.length-1]=e:i.push(e));else e?i[t]=f(e):i.splice(t,1);return a&&i.unshift(""),this.path(i.join(s),r)},i.segmentCoded=function(t,e,r){var s,n,i;if("number"!=typeof t&&(r=e,e=t,t=void 0),void 0===e){if(p(s=this.segment(t,e,r)))for(n=0,i=s.length;n<i;n++)s[n]=a.decode(s[n]);else s=void 0!==s?a.decode(s):void 0;return s}if(p(e))for(n=0,i=e.length;n<i;n++)e[n]=a.encode(e[n]);else e="string"==typeof e||e instanceof String?a.encode(e):e;return this.segment(t,e,r)};var S=i.query;return i.query=function(t,e){if(!0===t)return a.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("function"==typeof t){var r=a.parseQuery(this._parts.query,this._parts.escapeQuerySpace),s=t.call(this,r);return this._parts.query=a.buildQuery(s||r,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!e),this}return void 0!==t&&"string"!=typeof t?(this._parts.query=a.buildQuery(t,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!e),this):S.call(this,t,e)},i.setQuery=function(t,e,r){var s=a.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("string"==typeof t||t instanceof String)s[t]=void 0!==e?e:null;else{if("object"!=typeof t)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");for(var n in t)o.call(t,n)&&(s[n]=t[n])}return this._parts.query=a.buildQuery(s,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof t&&(r=e),this.build(!r),this},i.addQuery=function(t,e,r){var s=a.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return a.addQuery(s,t,void 0===e?null:e),this._parts.query=a.buildQuery(s,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof t&&(r=e),this.build(!r),this},i.removeQuery=function(t,e,r){var s=a.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return a.removeQuery(s,t,e),this._parts.query=a.buildQuery(s,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof t&&(r=e),this.build(!r),this},i.hasQuery=function(t,e,r){var s=a.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return a.hasQuery(s,t,e,r)},i.setSearch=i.setQuery,i.addSearch=i.addQuery,i.removeSearch=i.removeQuery,i.hasSearch=i.hasQuery,i.normalize=function(){return this._parts.urn?this.normalizeProtocol(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build():this.normalizeProtocol(!1).normalizeHostname(!1).normalizePort(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build()},i.normalizeProtocol=function(t){return"string"==typeof this._parts.protocol&&(this._parts.protocol=this._parts.protocol.toLowerCase(),this.build(!t)),this},i.normalizeHostname=function(r){return this._parts.hostname&&(this.is("IDN")&&t?this._parts.hostname=t.toASCII(this._parts.hostname):this.is("IPv6")&&e&&(this._parts.hostname=e.best(this._parts.hostname)),this._parts.hostname=this._parts.hostname.toLowerCase(),this.build(!r)),this},i.normalizePort=function(t){return"string"==typeof this._parts.protocol&&this._parts.port===a.defaultPorts[this._parts.protocol]&&(this._parts.port=null,this.build(!t)),this},i.normalizePath=function(t){var e,r=this._parts.path;if(!r)return this;if(this._parts.urn)return this._parts.path=a.recodeUrnPath(this._parts.path),this.build(!t),this;if("/"===this._parts.path)return this;var s,n,i="";for("/"!==(r=a.recodePath(r)).charAt(0)&&(e=!0,r="/"+r),"/.."!==r.slice(-3)&&"/."!==r.slice(-2)||(r+="/"),r=r.replace(/(\/(\.\/)+)|(\/\.$)/g,"/").replace(/\/{2,}/g,"/"),e&&(i=r.substring(1).match(/^(\.\.\/)+/)||"")&&(i=i[0]);-1!==(s=r.search(/\/\.\.(\/|$)/));)0!==s?(-1===(n=r.substring(0,s).lastIndexOf("/"))&&(n=s),r=r.substring(0,n)+r.substring(s+3)):r=r.substring(3);return e&&this.is("relative")&&(r=i+r.substring(1)),this._parts.path=r,this.build(!t),this},i.normalizePathname=i.normalizePath,i.normalizeQuery=function(t){return"string"==typeof this._parts.query&&(this._parts.query.length?this.query(a.parseQuery(this._parts.query,this._parts.escapeQuerySpace)):this._parts.query=null,this.build(!t)),this},i.normalizeFragment=function(t){return this._parts.fragment||(this._parts.fragment=null,this.build(!t)),this},i.normalizeSearch=i.normalizeQuery,i.normalizeHash=i.normalizeFragment,i.iso8859=function(){var t=a.encode,e=a.decode;a.encode=escape,a.decode=decodeURIComponent;try{this.normalize()}finally{a.encode=t,a.decode=e}return this},i.unicode=function(){var t=a.encode,e=a.decode;a.encode=g,a.decode=unescape;try{this.normalize()}finally{a.encode=t,a.decode=e}return this},i.readable=function(){var e=this.clone();e.username("").password("").normalize();var r="";if(e._parts.protocol&&(r+=e._parts.protocol+"://"),e._parts.hostname&&(e.is("punycode")&&t?(r+=t.toUnicode(e._parts.hostname),e._parts.port&&(r+=":"+e._parts.port)):r+=e.host()),e._parts.hostname&&e._parts.path&&"/"!==e._parts.path.charAt(0)&&(r+="/"),r+=e.path(!0),e._parts.query){for(var s="",n=0,i=e._parts.query.split("&"),o=i.length;n<o;n++){var h=(i[n]||"").split("=");s+="&"+a.decodeQuery(h[0],this._parts.escapeQuerySpace).replace(/&/g,"%26"),void 0!==h[1]&&(s+="="+a.decodeQuery(h[1],this._parts.escapeQuerySpace).replace(/&/g,"%26"))}r+="?"+s.substring(1)}return r+=a.decodeQuery(e.hash(),!0)},i.absoluteTo=function(t){var e,r,s,n=this.clone(),i=["protocol","username","password","hostname","port"];if(this._parts.urn)throw new Error("URNs do not have any generally defined hierarchical components");if(t instanceof a||(t=new a(t)),n._parts.protocol||(n._parts.protocol=t._parts.protocol),this._parts.hostname)return n;for(r=0;s=i[r];r++)n._parts[s]=t._parts[s];return n._parts.path?".."===n._parts.path.substring(-2)&&(n._parts.path+="/"):(n._parts.path=t._parts.path,n._parts.query||(n._parts.query=t._parts.query)),"/"!==n.path().charAt(0)&&(e=(e=t.directory())||(0===t.path().indexOf("/")?"/":""),n._parts.path=(e?e+"/":"")+n._parts.path,n.normalizePath()),n.build(),n},i.relativeTo=function(t){var e,r,s,n,i,o=this.clone().normalize();if(o._parts.urn)throw new Error("URNs do not have any generally defined hierarchical components");if(t=new a(t).normalize(),e=o._parts,r=t._parts,n=o.path(),i=t.path(),"/"!==n.charAt(0))throw new Error("URI is already relative");if("/"!==i.charAt(0))throw new Error("Cannot calculate a URI relative to another relative URI");if(e.protocol===r.protocol&&(e.protocol=null),e.username!==r.username||e.password!==r.password)return o.build();if(null!==e.protocol||null!==e.username||null!==e.password)return o.build();if(e.hostname!==r.hostname||e.port!==r.port)return o.build();if(e.hostname=null,e.port=null,n===i)return e.path="",o.build();if(!(s=a.commonPath(n,i)))return o.build();var h=r.path.substring(s.length).replace(/[^\/]*$/,"").replace(/.*?\//g,"../");return e.path=h+e.path.substring(s.length)||"./",o.build()},i.equals=function(t){var e,r,s,n,i,h=this.clone(),u=new a(t),c={};if(h.normalize(),u.normalize(),h.toString()===u.toString())return!0;if(s=h.query(),n=u.query(),h.query(""),u.query(""),h.toString()!==u.toString())return!1;if(s.length!==n.length)return!1;for(i in e=a.parseQuery(s,this._parts.escapeQuerySpace),r=a.parseQuery(n,this._parts.escapeQuerySpace),e)if(o.call(e,i)){if(p(e[i])){if(!d(e[i],r[i]))return!1}else if(e[i]!==r[i])return!1;c[i]=!0}for(i in r)if(o.call(r,i)&&!c[i])return!1;return!0},i.duplicateQueryParameters=function(t){return this._parts.duplicateQueryParameters=!!t,this},i.escapeQuerySpace=function(t){return this._parts.escapeQuerySpace=!!t,this},a}(t.punycode,t.IPv6,t.SecondLevelDomains,t)}(this);/**
* @preserve JSizes - JQuery plugin v0.33
*
* Licensed under the revised BSD License.
* Copyright 2008-2010 Bram Stein
* All rights reserved.
*/
!function(t){"use strict";var i=function(t){return parseInt(t,10)||0};t.each(["min","max"],(function(s,h){t.fn[h+"Size"]=function(t){var s,o;return t?(void 0!==t.width&&this.css(h+"-width",t.width),void 0!==t.height&&this.css(h+"-height",t.height),this):(s=this.css(h+"-width"),o=this.css(h+"-height"),{width:"max"===h&&(void 0===s||"none"===s||-1===i(s))&&Number.MAX_VALUE||i(s),height:"max"===h&&(void 0===o||"none"===o||-1===i(o))&&Number.MAX_VALUE||i(o)})}})),t.fn.isVisible=function(){return this.is(":visible")},t.each(["border","margin","padding"],(function(s,h){t.fn[h]=function(t){return t?(void 0!==t.top&&this.css(h+"-top"+("border"===h?"-width":""),t.top),void 0!==t.bottom&&this.css(h+"-bottom"+("border"===h?"-width":""),t.bottom),void 0!==t.left&&this.css(h+"-left"+("border"===h?"-width":""),t.left),void 0!==t.right&&this.css(h+"-right"+("border"===h?"-width":""),t.right),this):{top:i(this.css(h+"-top"+("border"===h?"-width":""))),bottom:i(this.css(h+"-bottom"+("border"===h?"-width":""))),left:i(this.css(h+"-left"+("border"===h?"-width":""))),right:i(this.css(h+"-right"+("border"===h?"-width":"")))}}}))}(jQuery);(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict'
exports.byteLength = byteLength
exports.toByteArray = toByteArray
exports.fromByteArray = fromByteArray
var lookup = []
var revLookup = []
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
for (var i = 0, len = code.length; i < len; ++i) {
lookup[i] = code[i]
revLookup[code.charCodeAt(i)] = i
}
// Support decoding URL-safe base64 strings, as Node.js does.
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
revLookup['-'.charCodeAt(0)] = 62
revLookup['_'.charCodeAt(0)] = 63
function getLens (b64) {
var len = b64.length
if (len % 4 > 0) {
throw new Error('Invalid string. Length must be a multiple of 4')
}
// Trim off extra bytes after placeholder bytes are found
// See: https://github.com/beatgammit/base64-js/issues/42
var validLen = b64.indexOf('=')
if (validLen === -1) validLen = len
var placeHoldersLen = validLen === len
? 0
: 4 - (validLen % 4)
return [validLen, placeHoldersLen]
}
// base64 is 4/3 + up to two characters of the original data
function byteLength (b64) {
var lens = getLens(b64)
var validLen = lens[0]
var placeHoldersLen = lens[1]
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
}
function _byteLength (b64, validLen, placeHoldersLen) {
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
}
function toByteArray (b64) {
var tmp
var lens = getLens(b64)
var validLen = lens[0]
var placeHoldersLen = lens[1]
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
var curByte = 0
// if there are placeholders, only get up to the last complete 4 chars
var len = placeHoldersLen > 0
? validLen - 4
: validLen
var i
for (i = 0; i < len; i += 4) {
tmp =
(revLookup[b64.charCodeAt(i)] << 18) |
(revLookup[b64.charCodeAt(i + 1)] << 12) |
(revLookup[b64.charCodeAt(i + 2)] << 6) |
revLookup[b64.charCodeAt(i + 3)]
arr[curByte++] = (tmp >> 16) & 0xFF
arr[curByte++] = (tmp >> 8) & 0xFF
arr[curByte++] = tmp & 0xFF
}
if (placeHoldersLen === 2) {
tmp =
(revLookup[b64.charCodeAt(i)] << 2) |
(revLookup[b64.charCodeAt(i + 1)] >> 4)
arr[curByte++] = tmp & 0xFF
}
if (placeHoldersLen === 1) {
tmp =
(revLookup[b64.charCodeAt(i)] << 10) |
(revLookup[b64.charCodeAt(i + 1)] << 4) |
(revLookup[b64.charCodeAt(i + 2)] >> 2)
arr[curByte++] = (tmp >> 8) & 0xFF
arr[curByte++] = tmp & 0xFF
}
return arr
}
function tripletToBase64 (num) {
return lookup[num >> 18 & 0x3F] +
lookup[num >> 12 & 0x3F] +
lookup[num >> 6 & 0x3F] +
lookup[num & 0x3F]
}
function encodeChunk (uint8, start, end) {
var tmp
var output = []
for (var i = start; i < end; i += 3) {
tmp =
((uint8[i] << 16) & 0xFF0000) +
((uint8[i + 1] << 8) & 0xFF00) +
(uint8[i + 2] & 0xFF)
output.push(tripletToBase64(tmp))
}
return output.join('')
}
function fromByteArray (uint8) {
var tmp
var len = uint8.length
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
var parts = []
var maxChunkLength = 16383 // must be multiple of 3
// go through the array every three bytes, we'll deal with trailing stuff later
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
parts.push(encodeChunk(
uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
))
}
// pad the end with zeros, but make sure to not forget the extra bytes
if (extraBytes === 1) {
tmp = uint8[len - 1]
parts.push(
lookup[tmp >> 2] +
lookup[(tmp << 4) & 0x3F] +
'=='
)
} else if (extraBytes === 2) {
tmp = (uint8[len - 2] << 8) + uint8[len - 1]
parts.push(
lookup[tmp >> 10] +
lookup[(tmp >> 4) & 0x3F] +
lookup[(tmp << 2) & 0x3F] +
'='
)
}
return parts.join('')
}
},{}],2:[function(require,module,exports){
},{}],3:[function(require,module,exports){
(function (Buffer){
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
/* eslint-disable no-proto */
'use strict'
var base64 = require('base64-js')
var ieee754 = require('ieee754')
exports.Buffer = Buffer
exports.SlowBuffer = SlowBuffer
exports.INSPECT_MAX_BYTES = 50
var K_MAX_LENGTH = 0x7fffffff
exports.kMaxLength = K_MAX_LENGTH
/**
* If `Buffer.TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
* === false Print warning and recommend using `buffer` v4.x which has an Object
* implementation (most compatible, even IE6)
*
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
* Opera 11.6+, iOS 4.2+.
*
* We report that the browser does not support typed arrays if the are not subclassable
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
* for __proto__ and has a buggy typed array implementation.
*/
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
typeof console.error === 'function') {
console.error(
'This browser lacks typed array (Uint8Array) support which is required by ' +
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
)
}
function typedArraySupport () {
// Can typed array instances can be augmented?
try {
var arr = new Uint8Array(1)
arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
return arr.foo() === 42
} catch (e) {
return false
}
}
Object.defineProperty(Buffer.prototype, 'parent', {
enumerable: true,
get: function () {
if (!Buffer.isBuffer(this)) return undefined
return this.buffer
}
})
Object.defineProperty(Buffer.prototype, 'offset', {
enumerable: true,
get: function () {
if (!Buffer.isBuffer(this)) return undefined
return this.byteOffset
}
})
function createBuffer (length) {
if (length > K_MAX_LENGTH) {
throw new RangeError('The value "' + length + '" is invalid for option "size"')
}
// Return an augmented `Uint8Array` instance
var buf = new Uint8Array(length)
buf.__proto__ = Buffer.prototype
return buf
}
/**
* The Buffer constructor returns instances of `Uint8Array` that have their
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
* returns a single octet.
*
* The `Uint8Array` prototype remains unmodified.
*/
function Buffer (arg, encodingOrOffset, length) {
// Common case.
if (typeof arg === 'number') {
if (typeof encodingOrOffset === 'string') {
throw new TypeError(
'The "string" argument must be of type string. Received type number'
)
}
return allocUnsafe(arg)
}
return from(arg, encodingOrOffset, length)
}
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
if (typeof Symbol !== 'undefined' && Symbol.species != null &&
Buffer[Symbol.species] === Buffer) {
Object.defineProperty(Buffer, Symbol.species, {
value: null,
configurable: true,
enumerable: false,
writable: false
})
}
Buffer.poolSize = 8192 // not used by this implementation
function from (value, encodingOrOffset, length) {
if (typeof value === 'string') {
return fromString(value, encodingOrOffset)
}
if (ArrayBuffer.isView(value)) {
return fromArrayLike(value)
}
if (value == null) {
throw TypeError(
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
'or Array-like Object. Received type ' + (typeof value)
)
}
if (isInstance(value, ArrayBuffer) ||
(value && isInstance(value.buffer, ArrayBuffer))) {
return fromArrayBuffer(value, encodingOrOffset, length)
}
if (typeof value === 'number') {
throw new TypeError(
'The "value" argument must not be of type number. Received type number'
)
}
var valueOf = value.valueOf && value.valueOf()
if (valueOf != null && valueOf !== value) {
return Buffer.from(valueOf, encodingOrOffset, length)
}
var b = fromObject(value)
if (b) return b
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
typeof value[Symbol.toPrimitive] === 'function') {
return Buffer.from(
value[Symbol.toPrimitive]('string'), encodingOrOffset, length
)
}
throw new TypeError(
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
'or Array-like Object. Received type ' + (typeof value)
)
}
/**
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
* if value is a number.
* Buffer.from(str[, encoding])
* Buffer.from(array)
* Buffer.from(buffer)
* Buffer.from(arrayBuffer[, byteOffset[, length]])
**/
Buffer.from = function (value, encodingOrOffset, length) {
return from(value, encodingOrOffset, length)
}
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
// https://github.com/feross/buffer/pull/148
Buffer.prototype.__proto__ = Uint8Array.prototype
Buffer.__proto__ = Uint8Array
function assertSize (size) {
if (typeof size !== 'number') {
throw new TypeError('"size" argument must be of type number')
} else if (size < 0) {
throw new RangeError('The value "' + size + '" is invalid for option "size"')
}
}
function alloc (size, fill, encoding) {
assertSize(size)
if (size <= 0) {
return createBuffer(size)
}
if (fill !== undefined) {
// Only pay attention to encoding if it's a string. This
// prevents accidentally sending in a number that would
// be interpretted as a start offset.
return typeof encoding === 'string'
? createBuffer(size).fill(fill, encoding)
: createBuffer(size).fill(fill)
}
return createBuffer(size)
}
/**
* Creates a new filled Buffer instance.
* alloc(size[, fill[, encoding]])
**/
Buffer.alloc = function (size, fill, encoding) {
return alloc(size, fill, encoding)
}
function allocUnsafe (size) {
assertSize(size)
return createBuffer(size < 0 ? 0 : checked(size) | 0)
}
/**
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
* */
Buffer.allocUnsafe = function (size) {
return allocUnsafe(size)
}
/**
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
*/
Buffer.allocUnsafeSlow = function (size) {
return allocUnsafe(size)
}
function fromString (string, encoding) {
if (typeof encoding !== 'string' || encoding === '') {
encoding = 'utf8'
}
if (!Buffer.isEncoding(encoding)) {
throw new TypeError('Unknown encoding: ' + encoding)
}
var length = byteLength(string, encoding) | 0
var buf = createBuffer(length)
var actual = buf.write(string, encoding)
if (actual !== length) {
// Writing a hex string, for example, that contains invalid characters will
// cause everything after the first invalid character to be ignored. (e.g.
// 'abxxcd' will be treated as 'ab')
buf = buf.slice(0, actual)
}
return buf
}
function fromArrayLike (array) {
var length = array.length < 0 ? 0 : checked(array.length) | 0
var buf = createBuffer(length)
for (var i = 0; i < length; i += 1) {
buf[i] = array[i] & 255
}
return buf
}
function fromArrayBuffer (array, byteOffset, length) {
if (byteOffset < 0 || array.byteLength < byteOffset) {
throw new RangeError('"offset" is outside of buffer bounds')
}
if (array.byteLength < byteOffset + (length || 0)) {
throw new RangeError('"length" is outside of buffer bounds')
}
var buf
if (byteOffset === undefined && length === undefined) {
buf = new Uint8Array(array)
} else if (length === undefined) {
buf = new Uint8Array(array, byteOffset)
} else {
buf = new Uint8Array(array, byteOffset, length)
}
// Return an augmented `Uint8Array` instance
buf.__proto__ = Buffer.prototype
return buf
}
function fromObject (obj) {
if (Buffer.isBuffer(obj)) {
var len = checked(obj.length) | 0
var buf = createBuffer(len)
if (buf.length === 0) {
return buf
}
obj.copy(buf, 0, 0, len)
return buf
}
if (obj.length !== undefined) {
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
return createBuffer(0)
}
return fromArrayLike(obj)
}
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
return fromArrayLike(obj.data)
}
}
function checked (length) {
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
// length is NaN (which is otherwise coerced to zero.)
if (length >= K_MAX_LENGTH) {
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
}
return length | 0
}
function SlowBuffer (length) {
if (+length != length) { // eslint-disable-line eqeqeq
length = 0
}
return Buffer.alloc(+length)
}
Buffer.isBuffer = function isBuffer (b) {
return b != null && b._isBuffer === true &&
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
}
Buffer.compare = function compare (a, b) {
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
throw new TypeError(
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
)
}
if (a === b) return 0
var x = a.length
var y = b.length
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
if (a[i] !== b[i]) {
x = a[i]
y = b[i]
break
}
}
if (x < y) return -1
if (y < x) return 1
return 0
}
Buffer.isEncoding = function isEncoding (encoding) {
switch (String(encoding).toLowerCase()) {
case 'hex':
case 'utf8':
case 'utf-8':
case 'ascii':
case 'latin1':
case 'binary':
case 'base64':
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return true
default:
return false
}
}
Buffer.concat = function concat (list, length) {
if (!Array.isArray(list)) {
throw new TypeError('"list" argument must be an Array of Buffers')
}
if (list.length === 0) {
return Buffer.alloc(0)
}
var i
if (length === undefined) {
length = 0
for (i = 0; i < list.length; ++i) {
length += list[i].length
}
}
var buffer = Buffer.allocUnsafe(length)
var pos = 0
for (i = 0; i < list.length; ++i) {
var buf = list[i]
if (isInstance(buf, Uint8Array)) {
buf = Buffer.from(buf)
}
if (!Buffer.isBuffer(buf)) {
throw new TypeError('"list" argument must be an Array of Buffers')
}
buf.copy(buffer, pos)
pos += buf.length
}
return buffer
}
function byteLength (string, encoding) {
if (Buffer.isBuffer(string)) {
return string.length
}
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
return string.byteLength
}
if (typeof string !== 'string') {
throw new TypeError(
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
'Received type ' + typeof string
)
}
var len = string.length
var mustMatch = (arguments.length > 2 && arguments[2] === true)
if (!mustMatch && len === 0) return 0
// Use a for loop to avoid recursion
var loweredCase = false
for (;;) {
switch (encoding) {
case 'ascii':
case 'latin1':
case 'binary':
return len
case 'utf8':
case 'utf-8':
return utf8ToBytes(string).length
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return len * 2
case 'hex':
return len >>> 1
case 'base64':
return base64ToBytes(string).length
default:
if (loweredCase) {
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
}
encoding = ('' + encoding).toLowerCase()
loweredCase = true
}
}
}
Buffer.byteLength = byteLength
function slowToString (encoding, start, end) {
var loweredCase = false
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
// property of a typed array.
// This behaves neither like String nor Uint8Array in that we set start/end
// to their upper/lower bounds if the value passed is out of range.
// undefined is handled specially as per ECMA-262 6th Edition,
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
if (start === undefined || start < 0) {
start = 0
}
// Return early if start > this.length. Done here to prevent potential uint32
// coercion fail below.
if (start > this.length) {
return ''
}
if (end === undefined || end > this.length) {
end = this.length
}
if (end <= 0) {
return ''
}
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
end >>>= 0
start >>>= 0
if (end <= start) {
return ''
}
if (!encoding) encoding = 'utf8'
while (true) {
switch (encoding) {
case 'hex':
return hexSlice(this, start, end)
case 'utf8':
case 'utf-8':
return utf8Slice(this, start, end)
case 'ascii':
return asciiSlice(this, start, end)
case 'latin1':
case 'binary':
return latin1Slice(this, start, end)
case 'base64':
return base64Slice(this, start, end)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return utf16leSlice(this, start, end)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = (encoding + '').toLowerCase()
loweredCase = true
}
}
}
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
// reliably in a browserify context because there could be multiple different
// copies of the 'buffer' package in use. This method works even for Buffer
// instances that were created from another copy of the `buffer` package.
// See: https://github.com/feross/buffer/issues/154
Buffer.prototype._isBuffer = true
function swap (b, n, m) {
var i = b[n]
b[n] = b[m]
b[m] = i
}
Buffer.prototype.swap16 = function swap16 () {
var len = this.length
if (len % 2 !== 0) {
throw new RangeError('Buffer size must be a multiple of 16-bits')
}
for (var i = 0; i < len; i += 2) {
swap(this, i, i + 1)
}
return this
}
Buffer.prototype.swap32 = function swap32 () {
var len = this.length
if (len % 4 !== 0) {
throw new RangeError('Buffer size must be a multiple of 32-bits')
}
for (var i = 0; i < len; i += 4) {
swap(this, i, i + 3)
swap(this, i + 1, i + 2)
}
return this
}
Buffer.prototype.swap64 = function swap64 () {
var len = this.length
if (len % 8 !== 0) {
throw new RangeError('Buffer size must be a multiple of 64-bits')
}
for (var i = 0; i < len; i += 8) {
swap(this, i, i + 7)
swap(this, i + 1, i + 6)
swap(this, i + 2, i + 5)
swap(this, i + 3, i + 4)
}
return this
}
Buffer.prototype.toString = function toString () {
var length = this.length
if (length === 0) return ''
if (arguments.length === 0) return utf8Slice(this, 0, length)
return slowToString.apply(this, arguments)
}
Buffer.prototype.toLocaleString = Buffer.prototype.toString
Buffer.prototype.equals = function equals (b) {
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
if (this === b) return true
return Buffer.compare(this, b) === 0
}
Buffer.prototype.inspect = function inspect () {
var str = ''
var max = exports.INSPECT_MAX_BYTES
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
if (this.length > max) str += ' ... '
return '<Buffer ' + str + '>'
}
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
if (isInstance(target, Uint8Array)) {
target = Buffer.from(target, target.offset, target.byteLength)
}
if (!Buffer.isBuffer(target)) {
throw new TypeError(
'The "target" argument must be one of type Buffer or Uint8Array. ' +
'Received type ' + (typeof target)
)
}
if (start === undefined) {
start = 0
}
if (end === undefined) {
end = target ? target.length : 0
}
if (thisStart === undefined) {
thisStart = 0
}
if (thisEnd === undefined) {
thisEnd = this.length
}
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
throw new RangeError('out of range index')
}
if (thisStart >= thisEnd && start >= end) {
return 0
}
if (thisStart >= thisEnd) {
return -1
}
if (start >= end) {
return 1
}
start >>>= 0
end >>>= 0
thisStart >>>= 0
thisEnd >>>= 0
if (this === target) return 0
var x = thisEnd - thisStart
var y = end - start
var len = Math.min(x, y)
var thisCopy = this.slice(thisStart, thisEnd)
var targetCopy = target.slice(start, end)
for (var i = 0; i < len; ++i) {
if (thisCopy[i] !== targetCopy[i]) {
x = thisCopy[i]
y = targetCopy[i]
break
}
}
if (x < y) return -1
if (y < x) return 1
return 0
}
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
//
// Arguments:
// - buffer - a Buffer to search
// - val - a string, Buffer, or number
// - byteOffset - an index into `buffer`; will be clamped to an int32
// - encoding - an optional encoding, relevant is val is a string
// - dir - true for indexOf, false for lastIndexOf
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
// Empty buffer means no match
if (buffer.length === 0) return -1
// Normalize byteOffset
if (typeof byteOffset === 'string') {
encoding = byteOffset
byteOffset = 0
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff
} else if (byteOffset < -0x80000000) {
byteOffset = -0x80000000
}
byteOffset = +byteOffset // Coerce to Number.
if (numberIsNaN(byteOffset)) {
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
byteOffset = dir ? 0 : (buffer.length - 1)
}
// Normalize byteOffset: negative offsets start from the end of the buffer
if (byteOffset < 0) byteOffset = buffer.length + byteOffset
if (byteOffset >= buffer.length) {
if (dir) return -1
else byteOffset = buffer.length - 1
} else if (byteOffset < 0) {
if (dir) byteOffset = 0
else return -1
}
// Normalize val
if (typeof val === 'string') {
val = Buffer.from(val, encoding)
}
// Finally, search either indexOf (if dir is true) or lastIndexOf
if (Buffer.isBuffer(val)) {
// Special case: looking for empty string/buffer always fails
if (val.length === 0) {
return -1
}
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
} else if (typeof val === 'number') {
val = val & 0xFF // Search for a byte value [0-255]
if (typeof Uint8Array.prototype.indexOf === 'function') {
if (dir) {
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
} else {
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
}
}
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
}
throw new TypeError('val must be string, number or Buffer')
}
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
var indexSize = 1
var arrLength = arr.length
var valLength = val.length
if (encoding !== undefined) {
encoding = String(encoding).toLowerCase()
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
encoding === 'utf16le' || encoding === 'utf-16le') {
if (arr.length < 2 || val.length < 2) {
return -1
}
indexSize = 2
arrLength /= 2
valLength /= 2
byteOffset /= 2
}
}
function read (buf, i) {
if (indexSize === 1) {
return buf[i]
} else {
return buf.readUInt16BE(i * indexSize)
}
}
var i
if (dir) {
var foundIndex = -1
for (i = byteOffset; i < arrLength; i++) {
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
if (foundIndex === -1) foundIndex = i
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
} else {
if (foundIndex !== -1) i -= i - foundIndex
foundIndex = -1
}
}
} else {
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
for (i = byteOffset; i >= 0; i--) {
var found = true
for (var j = 0; j < valLength; j++) {
if (read(arr, i + j) !== read(val, j)) {
found = false
break
}
}
if (found) return i
}
}
return -1
}
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
return this.indexOf(val, byteOffset, encoding) !== -1
}
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
}
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
}
function hexWrite (buf, string, offset, length) {
offset = Number(offset) || 0
var remaining = buf.length - offset
if (!length) {
length = remaining
} else {
length = Number(length)
if (length > remaining) {
length = remaining
}
}
var strLen = string.length
if (length > strLen / 2) {
length = strLen / 2
}
for (var i = 0; i < length; ++i) {
var parsed = parseInt(string.substr(i * 2, 2), 16)
if (numberIsNaN(parsed)) return i
buf[offset + i] = parsed
}
return i
}
function utf8Write (buf, string, offset, length) {
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
}
function asciiWrite (buf, string, offset, length) {
return blitBuffer(asciiToBytes(string), buf, offset, length)
}
function latin1Write (buf, string, offset, length) {
return asciiWrite(buf, string, offset, length)
}
function base64Write (buf, string, offset, length) {
return blitBuffer(base64ToBytes(string), buf, offset, length)
}
function ucs2Write (buf, string, offset, length) {
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
}
Buffer.prototype.write = function write (string, offset, length, encoding) {
// Buffer#write(string)
if (offset === undefined) {
encoding = 'utf8'
length = this.length
offset = 0
// Buffer#write(string, encoding)
} else if (length === undefined && typeof offset === 'string') {
encoding = offset
length = this.length
offset = 0
// Buffer#write(string, offset[, length][, encoding])
} else if (isFinite(offset)) {
offset = offset >>> 0
if (isFinite(length)) {
length = length >>> 0
if (encoding === undefined) encoding = 'utf8'
} else {
encoding = length
length = undefined
}
} else {
throw new Error(
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
)
}
var remaining = this.length - offset
if (length === undefined || length > remaining) length = remaining
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
throw new RangeError('Attempt to write outside buffer bounds')
}
if (!encoding) encoding = 'utf8'
var loweredCase = false
for (;;) {
switch (encoding) {
case 'hex':
return hexWrite(this, string, offset, length)
case 'utf8':
case 'utf-8':
return utf8Write(this, string, offset, length)
case 'ascii':
return asciiWrite(this, string, offset, length)
case 'latin1':
case 'binary':
return latin1Write(this, string, offset, length)
case 'base64':
// Warning: maxLength not taken into account in base64Write
return base64Write(this, string, offset, length)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return ucs2Write(this, string, offset, length)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = ('' + encoding).toLowerCase()
loweredCase = true
}
}
}
Buffer.prototype.toJSON = function toJSON () {
return {
type: 'Buffer',
data: Array.prototype.slice.call(this._arr || this, 0)
}
}
function base64Slice (buf, start, end) {
if (start === 0 && end === buf.length) {
return base64.fromByteArray(buf)
} else {
return base64.fromByteArray(buf.slice(start, end))
}
}
function utf8Slice (buf, start, end) {
end = Math.min(buf.length, end)
var res = []
var i = start
while (i < end) {
var firstByte = buf[i]
var codePoint = null
var bytesPerSequence = (firstByte > 0xEF) ? 4
: (firstByte > 0xDF) ? 3
: (firstByte > 0xBF) ? 2
: 1
if (i + bytesPerSequence <= end) {
var secondByte, thirdByte, fourthByte, tempCodePoint
switch (bytesPerSequence) {
case 1:
if (firstByte < 0x80) {
codePoint = firstByte
}
break
case 2:
secondByte = buf[i + 1]
if ((secondByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
if (tempCodePoint > 0x7F) {
codePoint = tempCodePoint
}
}
break
case 3:
secondByte = buf[i + 1]
thirdByte = buf[i + 2]
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
codePoint = tempCodePoint
}
}
break
case 4:
secondByte = buf[i + 1]
thirdByte = buf[i + 2]
fourthByte = buf[i + 3]
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
codePoint = tempCodePoint
}
}
}
}
if (codePoint === null) {
// we did not generate a valid codePoint so insert a
// replacement char (U+FFFD) and advance only 1 byte
codePoint = 0xFFFD
bytesPerSequence = 1
} else if (codePoint > 0xFFFF) {
// encode to utf16 (surrogate pair dance)
codePoint -= 0x10000
res.push(codePoint >>> 10 & 0x3FF | 0xD800)
codePoint = 0xDC00 | codePoint & 0x3FF
}
res.push(codePoint)
i += bytesPerSequence
}
return decodeCodePointsArray(res)
}
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
// the lowest limit is Chrome, with 0x10000 args.
// We go 1 magnitude less, for safety
var MAX_ARGUMENTS_LENGTH = 0x1000
function decodeCodePointsArray (codePoints) {
var len = codePoints.length
if (len <= MAX_ARGUMENTS_LENGTH) {
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
}
// Decode in chunks to avoid "call stack size exceeded".
var res = ''
var i = 0
while (i < len) {
res += String.fromCharCode.apply(
String,
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
)
}
return res
}
function asciiSlice (buf, start, end) {
var ret = ''
end = Math.min(buf.length, end)
for (var i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i] & 0x7F)
}
return ret
}
function latin1Slice (buf, start, end) {
var ret = ''
end = Math.min(buf.length, end)
for (var i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i])
}
return ret
}
function hexSlice (buf, start, end) {
var len = buf.length
if (!start || start < 0) start = 0
if (!end || end < 0 || end > len) end = len
var out = ''
for (var i = start; i < end; ++i) {
out += toHex(buf[i])
}
return out
}
function utf16leSlice (buf, start, end) {
var bytes = buf.slice(start, end)
var res = ''
for (var i = 0; i < bytes.length; i += 2) {
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
}
return res
}
Buffer.prototype.slice = function slice (start, end) {
var len = this.length
start = ~~start
end = end === undefined ? len : ~~end
if (start < 0) {
start += len
if (start < 0) start = 0
} else if (start > len) {
start = len
}
if (end < 0) {
end += len
if (end < 0) end = 0
} else if (end > len) {
end = len
}
if (end < start) end = start
var newBuf = this.subarray(start, end)
// Return an augmented `Uint8Array` instance
newBuf.__proto__ = Buffer.prototype
return newBuf
}
/*
* Need to make sure that buffer isn't trying to write out of bounds.
*/
function checkOffset (offset, ext, length) {
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
}
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
offset = offset >>> 0
byteLength = byteLength >>> 0
if (!noAssert) checkOffset(offset, byteLength, this.length)
var val = this[offset]
var mul = 1
var i = 0
while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul
}
return val
}
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
offset = offset >>> 0
byteLength = byteLength >>> 0
if (!noAssert) {
checkOffset(offset, byteLength, this.length)
}
var val = this[offset + --byteLength]
var mul = 1
while (byteLength > 0 && (mul *= 0x100)) {
val += this[offset + --byteLength] * mul
}
return val
}
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 1, this.length)
return this[offset]
}
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 2, this.length)
return this[offset] | (this[offset + 1] << 8)
}
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 2, this.length)
return (this[offset] << 8) | this[offset + 1]
}
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 4, this.length)
return ((this[offset]) |
(this[offset + 1] << 8) |
(this[offset + 2] << 16)) +
(this[offset + 3] * 0x1000000)
}
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 4, this.length)
return (this[offset] * 0x1000000) +
((this[offset + 1] << 16) |
(this[offset + 2] << 8) |
this[offset + 3])
}
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
offset = offset >>> 0
byteLength = byteLength >>> 0
if (!noAssert) checkOffset(offset, byteLength, this.length)
var val = this[offset]
var mul = 1
var i = 0
while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul
}
mul *= 0x80
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
return val
}
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
offset = offset >>> 0
byteLength = byteLength >>> 0
if (!noAssert) checkOffset(offset, byteLength, this.length)
var i = byteLength
var mul = 1
var val = this[offset + --i]
while (i > 0 && (mul *= 0x100)) {
val += this[offset + --i] * mul
}
mul *= 0x80
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
return val
}
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 1, this.length)
if (!(this[offset] & 0x80)) return (this[offset])
return ((0xff - this[offset] + 1) * -1)
}
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 2, this.length)
var val = this[offset] | (this[offset + 1] << 8)
return (val & 0x8000) ? val | 0xFFFF0000 : val
}
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 2, this.length)
var val = this[offset + 1] | (this[offset] << 8)
return (val & 0x8000) ? val | 0xFFFF0000 : val
}
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 4, this.length)
return (this[offset]) |
(this[offset + 1] << 8) |
(this[offset + 2] << 16) |
(this[offset + 3] << 24)
}
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 4, this.length)
return (this[offset] << 24) |
(this[offset + 1] << 16) |
(this[offset + 2] << 8) |
(this[offset + 3])
}
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 4, this.length)
return ieee754.read(this, offset, true, 23, 4)
}
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 4, this.length)
return ieee754.read(this, offset, false, 23, 4)
}
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 8, this.length)
return ieee754.read(this, offset, true, 52, 8)
}
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
offset = offset >>> 0
if (!noAssert) checkOffset(offset, 8, this.length)
return ieee754.read(this, offset, false, 52, 8)
}
function checkInt (buf, value, offset, ext, max, min) {
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
if (offset + ext > buf.length) throw new RangeError('Index out of range')
}
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
value = +value
offset = offset >>> 0
byteLength = byteLength >>> 0
if (!noAssert) {
var maxBytes = Math.pow(2, 8 * byteLength) - 1
checkInt(this, value, offset, byteLength, maxBytes, 0)
}
var mul = 1
var i = 0
this[offset] = value & 0xFF
while (++i < byteLength && (mul *= 0x100)) {
this[offset + i] = (value / mul) & 0xFF
}
return offset + byteLength
}
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
value = +value
offset = offset >>> 0
byteLength = byteLength >>> 0
if (!noAssert) {
var maxBytes = Math.pow(2, 8 * byteLength) - 1
checkInt(this, value, offset, byteLength, maxBytes, 0)
}
var i = byteLength - 1
var mul = 1
this[offset + i] = value & 0xFF
while (--i >= 0 && (mul *= 0x100)) {
this[offset + i] = (value / mul) & 0xFF
}
return offset + byteLength
}
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
this[offset] = (value & 0xff)
return offset + 1
}
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
this[offset] = (value & 0xff)
this[offset + 1] = (value >>> 8)
return offset + 2
}
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
this[offset] = (value >>> 8)
this[offset + 1] = (value & 0xff)
return offset + 2
}
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
this[offset + 3] = (value >>> 24)
this[offset + 2] = (value >>> 16)
this[offset + 1] = (value >>> 8)
this[offset] = (value & 0xff)
return offset + 4
}
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
this[offset] = (value >>> 24)
this[offset + 1] = (value >>> 16)
this[offset + 2] = (value >>> 8)
this[offset + 3] = (value & 0xff)
return offset + 4
}
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) {
var limit = Math.pow(2, (8 * byteLength) - 1)
checkInt(this, value, offset, byteLength, limit - 1, -limit)
}
var i = 0
var mul = 1
var sub = 0
this[offset] = value & 0xFF
while (++i < byteLength && (mul *= 0x100)) {
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
sub = 1
}
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
}
return offset + byteLength
}
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) {
var limit = Math.pow(2, (8 * byteLength) - 1)
checkInt(this, value, offset, byteLength, limit - 1, -limit)
}
var i = byteLength - 1
var mul = 1
var sub = 0
this[offset + i] = value & 0xFF
while (--i >= 0 && (mul *= 0x100)) {
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
sub = 1
}
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
}
return offset + byteLength
}
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
if (value < 0) value = 0xff + value + 1
this[offset] = (value & 0xff)
return offset + 1
}
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
this[offset] = (value & 0xff)
this[offset + 1] = (value >>> 8)
return offset + 2
}
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
this[offset] = (value >>> 8)
this[offset + 1] = (value & 0xff)
return offset + 2
}
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
this[offset] = (value & 0xff)
this[offset + 1] = (value >>> 8)
this[offset + 2] = (value >>> 16)
this[offset + 3] = (value >>> 24)
return offset + 4
}
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
if (value < 0) value = 0xffffffff + value + 1
this[offset] = (value >>> 24)
this[offset + 1] = (value >>> 16)
this[offset + 2] = (value >>> 8)
this[offset + 3] = (value & 0xff)
return offset + 4
}
function checkIEEE754 (buf, value, offset, ext, max, min) {
if (offset + ext > buf.length) throw new RangeError('Index out of range')
if (offset < 0) throw new RangeError('Index out of range')
}
function writeFloat (buf, value, offset, littleEndian, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) {
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
}
ieee754.write(buf, value, offset, littleEndian, 23, 4)
return offset + 4
}
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
return writeFloat(this, value, offset, true, noAssert)
}
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
return writeFloat(this, value, offset, false, noAssert)
}
function writeDouble (buf, value, offset, littleEndian, noAssert) {
value = +value
offset = offset >>> 0
if (!noAssert) {
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
}
ieee754.write(buf, value, offset, littleEndian, 52, 8)
return offset + 8
}
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
return writeDouble(this, value, offset, true, noAssert)
}
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
return writeDouble(this, value, offset, false, noAssert)
}
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
if (!start) start = 0
if (!end && end !== 0) end = this.length
if (targetStart >= target.length) targetStart = target.length
if (!targetStart) targetStart = 0
if (end > 0 && end < start) end = start
// Copy 0 bytes; we're done
if (end === start) return 0
if (target.length === 0 || this.length === 0) return 0
// Fatal error conditions
if (targetStart < 0) {
throw new RangeError('targetStart out of bounds')
}
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
if (end < 0) throw new RangeError('sourceEnd out of bounds')
// Are we oob?
if (end > this.length) end = this.length
if (target.length - targetStart < end - start) {
end = target.length - targetStart + start
}
var len = end - start
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
// Use built-in when available, missing from IE11
this.copyWithin(targetStart, start, end)
} else if (this === target && start < targetStart && targetStart < end) {
// descending copy from end
for (var i = len - 1; i >= 0; --i) {
target[i + targetStart] = this[i + start]
}
} else {
Uint8Array.prototype.set.call(
target,
this.subarray(start, end),
targetStart
)
}
return len
}
// Usage:
// buffer.fill(number[, offset[, end]])
// buffer.fill(buffer[, offset[, end]])
// buffer.fill(string[, offset[, end]][, encoding])
Buffer.prototype.fill = function fill (val, start, end, encoding) {
// Handle string cases:
if (typeof val === 'string') {
if (typeof start === 'string') {
encoding = start
start = 0
end = this.length
} else if (typeof end === 'string') {
encoding = end
end = this.length
}
if (encoding !== undefined && typeof encoding !== 'string') {
throw new TypeError('encoding must be a string')
}
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
throw new TypeError('Unknown encoding: ' + encoding)
}
if (val.length === 1) {
var code = val.charCodeAt(0)
if ((encoding === 'utf8' && code < 128) ||
encoding === 'latin1') {
// Fast path: If `val` fits into a single byte, use that numeric value.
val = code
}
}
} else if (typeof val === 'number') {
val = val & 255
}
// Invalid ranges are not set to a default, so can range check early.
if (start < 0 || this.length < start || this.length < end) {
throw new RangeError('Out of range index')
}
if (end <= start) {
return this
}
start = start >>> 0
end = end === undefined ? this.length : end >>> 0
if (!val) val = 0
var i
if (typeof val === 'number') {
for (i = start; i < end; ++i) {
this[i] = val
}
} else {
var bytes = Buffer.isBuffer(val)
? val
: Buffer.from(val, encoding)
var len = bytes.length
if (len === 0) {
throw new TypeError('The value "' + val +
'" is invalid for argument "value"')
}
for (i = 0; i < end - start; ++i) {
this[i + start] = bytes[i % len]
}
}
return this
}
// HELPER FUNCTIONS
// ================
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
function base64clean (str) {
// Node takes equal signs as end of the Base64 encoding
str = str.split('=')[0]
// Node strips out invalid characters like \n and \t from the string, base64-js does not
str = str.trim().replace(INVALID_BASE64_RE, '')
// Node converts strings with length < 2 to ''
if (str.length < 2) return ''
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
while (str.length % 4 !== 0) {
str = str + '='
}
return str
}
function toHex (n) {
if (n < 16) return '0' + n.toString(16)
return n.toString(16)
}
function utf8ToBytes (string, units) {
units = units || Infinity
var codePoint
var length = string.length
var leadSurrogate = null
var bytes = []
for (var i = 0; i < length; ++i) {
codePoint = string.charCodeAt(i)
// is surrogate component
if (codePoint > 0xD7FF && codePoint < 0xE000) {
// last char was a lead
if (!leadSurrogate) {
// no lead yet
if (codePoint > 0xDBFF) {
// unexpected trail
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
continue
} else if (i + 1 === length) {
// unpaired lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
continue
}
// valid lead
leadSurrogate = codePoint
continue
}
// 2 leads in a row
if (codePoint < 0xDC00) {
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
leadSurrogate = codePoint
continue
}
// valid surrogate pair
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
} else if (leadSurrogate) {
// valid bmp char, but last char was a lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
}
leadSurrogate = null
// encode utf8
if (codePoint < 0x80) {
if ((units -= 1) < 0) break
bytes.push(codePoint)
} else if (codePoint < 0x800) {
if ((units -= 2) < 0) break
bytes.push(
codePoint >> 0x6 | 0xC0,
codePoint & 0x3F | 0x80
)
} else if (codePoint < 0x10000) {
if ((units -= 3) < 0) break
bytes.push(
codePoint >> 0xC | 0xE0,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
)
} else if (codePoint < 0x110000) {
if ((units -= 4) < 0) break
bytes.push(
codePoint >> 0x12 | 0xF0,
codePoint >> 0xC & 0x3F | 0x80,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
)
} else {
throw new Error('Invalid code point')
}
}
return bytes
}
function asciiToBytes (str) {
var byteArray = []
for (var i = 0; i < str.length; ++i) {
// Node's code seems to be doing this and not & 0x7F..
byteArray.push(str.charCodeAt(i) & 0xFF)
}
return byteArray
}
function utf16leToBytes (str, units) {
var c, hi, lo
var byteArray = []
for (var i = 0; i < str.length; ++i) {
if ((units -= 2) < 0) break
c = str.charCodeAt(i)
hi = c >> 8
lo = c % 256
byteArray.push(lo)
byteArray.push(hi)
}
return byteArray
}
function base64ToBytes (str) {
return base64.toByteArray(base64clean(str))
}
function blitBuffer (src, dst, offset, length) {
for (var i = 0; i < length; ++i) {
if ((i + offset >= dst.length) || (i >= src.length)) break
dst[i + offset] = src[i]
}
return i
}
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
// the `instanceof` check but they should be treated as of that type.
// See: https://github.com/feross/buffer/issues/166
function isInstance (obj, type) {
return obj instanceof type ||
(obj != null && obj.constructor != null && obj.constructor.name != null &&
obj.constructor.name === type.name)
}
function numberIsNaN (obj) {
// For IE11 support
return obj !== obj // eslint-disable-line no-self-compare
}
}).call(this,require("buffer").Buffer)
},{"base64-js":1,"buffer":3,"ieee754":4}],4:[function(require,module,exports){
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m
var eLen = (nBytes * 8) - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var nBits = -7
var i = isLE ? (nBytes - 1) : 0
var d = isLE ? -1 : 1
var s = buffer[offset + i]
i += d
e = s & ((1 << (-nBits)) - 1)
s >>= (-nBits)
nBits += eLen
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
m = e & ((1 << (-nBits)) - 1)
e >>= (-nBits)
nBits += mLen
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
if (e === 0) {
e = 1 - eBias
} else if (e === eMax) {
return m ? NaN : ((s ? -1 : 1) * Infinity)
} else {
m = m + Math.pow(2, mLen)
e = e - eBias
}
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
}
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
var e, m, c
var eLen = (nBytes * 8) - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
var i = isLE ? 0 : (nBytes - 1)
var d = isLE ? 1 : -1
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
value = Math.abs(value)
if (isNaN(value) || value === Infinity) {
m = isNaN(value) ? 1 : 0
e = eMax
} else {
e = Math.floor(Math.log(value) / Math.LN2)
if (value * (c = Math.pow(2, -e)) < 1) {
e--
c *= 2
}
if (e + eBias >= 1) {
value += rt / c
} else {
value += rt * Math.pow(2, 1 - eBias)
}
if (value * c >= 2) {
e++
c /= 2
}
if (e + eBias >= eMax) {
m = 0
e = eMax
} else if (e + eBias >= 1) {
m = ((value * c) - 1) * Math.pow(2, mLen)
e = e + eBias
} else {
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
e = 0
}
}
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
e = (e << mLen) | m
eLen += mLen
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
buffer[offset + i - d] |= s * 128
}
},{}],5:[function(require,module,exports){
(function (process){
// .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1,
// backported and transplited with Babel, with backwards-compat fixes
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// resolves . and .. elements in a path array with directory names there
// must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length - 1; i >= 0; i--) {
var last = parts[i];
if (last === '.') {
parts.splice(i, 1);
} else if (last === '..') {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
// if the path is allowed to go above the root, restore leading ..s
if (allowAboveRoot) {
for (; up--; up) {
parts.unshift('..');
}
}
return parts;
}
// path.resolve([from ...], to)
// posix version
exports.resolve = function() {
var resolvedPath = '',
resolvedAbsolute = false;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0) ? arguments[i] : process.cwd();
// Skip empty and invalid entries
if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charAt(0) === '/';
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
return !!p;
}), !resolvedAbsolute).join('/');
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
};
// path.normalize(path)
// posix version
exports.normalize = function(path) {
var isAbsolute = exports.isAbsolute(path),
trailingSlash = substr(path, -1) === '/';
// Normalize the path
path = normalizeArray(filter(path.split('/'), function(p) {
return !!p;
}), !isAbsolute).join('/');
if (!path && !isAbsolute) {
path = '.';
}
if (path && trailingSlash) {
path += '/';
}
return (isAbsolute ? '/' : '') + path;
};
// posix version
exports.isAbsolute = function(path) {
return path.charAt(0) === '/';
};
// posix version
exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(filter(paths, function(p, index) {
if (typeof p !== 'string') {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
}).join('/'));
};
// path.relative(from, to)
// posix version
exports.relative = function(from, to) {
from = exports.resolve(from).substr(1);
to = exports.resolve(to).substr(1);
function trim(arr) {
var start = 0;
for (; start < arr.length; start++) {
if (arr[start] !== '') break;
}
var end = arr.length - 1;
for (; end >= 0; end--) {
if (arr[end] !== '') break;
}
if (start > end) return [];
return arr.slice(start, end - start + 1);
}
var fromParts = trim(from.split('/'));
var toParts = trim(to.split('/'));
var length = Math.min(fromParts.length, toParts.length);
var samePartsLength = length;
for (var i = 0; i < length; i++) {
if (fromParts[i] !== toParts[i]) {
samePartsLength = i;
break;
}
}
var outputParts = [];
for (var i = samePartsLength; i < fromParts.length; i++) {
outputParts.push('..');
}
outputParts = outputParts.concat(toParts.slice(samePartsLength));
return outputParts.join('/');
};
exports.sep = '/';
exports.delimiter = ':';
exports.dirname = function (path) {
if (typeof path !== 'string') path = path + '';
if (path.length === 0) return '.';
var code = path.charCodeAt(0);
var hasRoot = code === 47 /*/*/;
var end = -1;
var matchedSlash = true;
for (var i = path.length - 1; i >= 1; --i) {
code = path.charCodeAt(i);
if (code === 47 /*/*/) {
if (!matchedSlash) {
end = i;
break;
}
} else {
// We saw the first non-path separator
matchedSlash = false;
}
}
if (end === -1) return hasRoot ? '/' : '.';
if (hasRoot && end === 1) {
// return '//';
// Backwards-compat fix:
return '/';
}
return path.slice(0, end);
};
function basename(path) {
if (typeof path !== 'string') path = path + '';
var start = 0;
var end = -1;
var matchedSlash = true;
var i;
for (i = path.length - 1; i >= 0; --i) {
if (path.charCodeAt(i) === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
start = i + 1;
break;
}
} else if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// path component
matchedSlash = false;
end = i + 1;
}
}
if (end === -1) return '';
return path.slice(start, end);
}
// Uses a mixed approach for backwards-compatibility, as ext behavior changed
// in new Node.js versions, so only basename() above is backported here
exports.basename = function (path, ext) {
var f = basename(path);
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
};
exports.extname = function (path) {
if (typeof path !== 'string') path = path + '';
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
for (var i = path.length - 1; i >= 0; --i) {
var code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
startPart = i + 1;
break;
}
continue;
}
if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// extension
matchedSlash = false;
end = i + 1;
}
if (code === 46 /*.*/) {
// If this is our first dot, mark it as the start of our extension
if (startDot === -1)
startDot = i;
else if (preDotState !== 1)
preDotState = 1;
} else if (startDot !== -1) {
// We saw a non-dot and non-path separator before our dot, so we should
// have a good chance at having a non-empty extension
preDotState = -1;
}
}
if (startDot === -1 || end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
return '';
}
return path.slice(startDot, end);
};
function filter (xs, f) {
if (xs.filter) return xs.filter(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
if (f(xs[i], i, xs)) res.push(xs[i]);
}
return res;
}
// String.prototype.substr - negative index don't work in IE8
var substr = 'ab'.substr(-1) === 'b'
? function (str, start, len) { return str.substr(start, len) }
: function (str, start, len) {
if (start < 0) start = str.length + start;
return str.substr(start, len);
}
;
}).call(this,require('_process'))
},{"_process":6}],6:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
},{}],7:[function(require,module,exports){
(function (global){
/*! https://mths.be/punycode v1.4.1 by @mathias */
;(function(root) {
/** Detect free variables */
var freeExports = typeof exports == 'object' && exports &&
!exports.nodeType && exports;
var freeModule = typeof module == 'object' && module &&
!module.nodeType && module;
var freeGlobal = typeof global == 'object' && global;
if (
freeGlobal.global === freeGlobal ||
freeGlobal.window === freeGlobal ||
freeGlobal.self === freeGlobal
) {
root = freeGlobal;
}
/**
* The `punycode` object.
* @name punycode
* @type Object
*/
var punycode,
/** Highest positive signed 32-bit float value */
maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
/** Bootstring parameters */
base = 36,
tMin = 1,
tMax = 26,
skew = 38,
damp = 700,
initialBias = 72,
initialN = 128, // 0x80
delimiter = '-', // '\x2D'
/** Regular expressions */
regexPunycode = /^xn--/,
regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
/** Error messages */
errors = {
'overflow': 'Overflow: input needs wider integers to process',
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
'invalid-input': 'Invalid input'
},
/** Convenience shortcuts */
baseMinusTMin = base - tMin,
floor = Math.floor,
stringFromCharCode = String.fromCharCode,
/** Temporary variable */
key;
/*--------------------------------------------------------------------------*/
/**
* A generic error utility function.
* @private
* @param {String} type The error type.
* @returns {Error} Throws a `RangeError` with the applicable error message.
*/
function error(type) {
throw new RangeError(errors[type]);
}
/**
* A generic `Array#map` utility function.
* @private
* @param {Array} array The array to iterate over.
* @param {Function} callback The function that gets called for every array
* item.
* @returns {Array} A new array of values returned by the callback function.
*/
function map(array, fn) {
var length = array.length;
var result = [];
while (length--) {
result[length] = fn(array[length]);
}
return result;
}
/**
* A simple `Array#map`-like wrapper to work with domain name strings or email
* addresses.
* @private
* @param {String} domain The domain name or email address.
* @param {Function} callback The function that gets called for every
* character.
* @returns {Array} A new string of characters returned by the callback
* function.
*/
function mapDomain(string, fn) {
var parts = string.split('@');
var result = '';
if (parts.length > 1) {
// In email addresses, only the domain name should be punycoded. Leave
// the local part (i.e. everything up to `@`) intact.
result = parts[0] + '@';
string = parts[1];
}
// Avoid `split(regex)` for IE8 compatibility. See #17.
string = string.replace(regexSeparators, '\x2E');
var labels = string.split('.');
var encoded = map(labels, fn).join('.');
return result + encoded;
}
/**
* Creates an array containing the numeric code points of each Unicode
* character in the string. While JavaScript uses UCS-2 internally,
* this function will convert a pair of surrogate halves (each of which
* UCS-2 exposes as separate characters) into a single code point,
* matching UTF-16.
* @see `punycode.ucs2.encode`
* @see <https://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode.ucs2
* @name decode
* @param {String} string The Unicode input string (UCS-2).
* @returns {Array} The new array of code points.
*/
function ucs2decode(string) {
var output = [],
counter = 0,
length = string.length,
value,
extra;
while (counter < length) {
value = string.charCodeAt(counter++);
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
// high surrogate, and there is a next character
extra = string.charCodeAt(counter++);
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
} else {
// unmatched surrogate; only append this code unit, in case the next
// code unit is the high surrogate of a surrogate pair
output.push(value);
counter--;
}
} else {
output.push(value);
}
}
return output;
}
/**
* Creates a string based on an array of numeric code points.
* @see `punycode.ucs2.decode`
* @memberOf punycode.ucs2
* @name encode
* @param {Array} codePoints The array of numeric code points.
* @returns {String} The new Unicode string (UCS-2).
*/
function ucs2encode(array) {
return map(array, function(value) {
var output = '';
if (value > 0xFFFF) {
value -= 0x10000;
output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
value = 0xDC00 | value & 0x3FF;
}
output += stringFromCharCode(value);
return output;
}).join('');
}
/**
* Converts a basic code point into a digit/integer.
* @see `digitToBasic()`
* @private
* @param {Number} codePoint The basic numeric code point value.
* @returns {Number} The numeric value of a basic code point (for use in
* representing integers) in the range `0` to `base - 1`, or `base` if
* the code point does not represent a value.
*/
function basicToDigit(codePoint) {
if (codePoint - 48 < 10) {
return codePoint - 22;
}
if (codePoint - 65 < 26) {
return codePoint - 65;
}
if (codePoint - 97 < 26) {
return codePoint - 97;
}
return base;
}
/**
* Converts a digit/integer into a basic code point.
* @see `basicToDigit()`
* @private
* @param {Number} digit The numeric value of a basic code point.
* @returns {Number} The basic code point whose value (when used for
* representing integers) is `digit`, which needs to be in the range
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
* used; else, the lowercase form is used. The behavior is undefined
* if `flag` is non-zero and `digit` has no uppercase form.
*/
function digitToBasic(digit, flag) {
// 0..25 map to ASCII a..z or A..Z
// 26..35 map to ASCII 0..9
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
}
/**
* Bias adaptation function as per section 3.4 of RFC 3492.
* https://tools.ietf.org/html/rfc3492#section-3.4
* @private
*/
function adapt(delta, numPoints, firstTime) {
var k = 0;
delta = firstTime ? floor(delta / damp) : delta >> 1;
delta += floor(delta / numPoints);
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
delta = floor(delta / baseMinusTMin);
}
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
}
/**
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
* symbols.
* @memberOf punycode
* @param {String} input The Punycode string of ASCII-only symbols.
* @returns {String} The resulting string of Unicode symbols.
*/
function decode(input) {
// Don't use UCS-2
var output = [],
inputLength = input.length,
out,
i = 0,
n = initialN,
bias = initialBias,
basic,
j,
index,
oldi,
w,
k,
digit,
t,
/** Cached calculation results */
baseMinusT;
// Handle the basic code points: let `basic` be the number of input code
// points before the last delimiter, or `0` if there is none, then copy
// the first basic code points to the output.
basic = input.lastIndexOf(delimiter);
if (basic < 0) {
basic = 0;
}
for (j = 0; j < basic; ++j) {
// if it's not a basic code point
if (input.charCodeAt(j) >= 0x80) {
error('not-basic');
}
output.push(input.charCodeAt(j));
}
// Main decoding loop: start just after the last delimiter if any basic code
// points were copied; start at the beginning otherwise.
for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
// `index` is the index of the next character to be consumed.
// Decode a generalized variable-length integer into `delta`,
// which gets added to `i`. The overflow checking is easier
// if we increase `i` as we go, then subtract off its starting
// value at the end to obtain `delta`.
for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
if (index >= inputLength) {
error('invalid-input');
}
digit = basicToDigit(input.charCodeAt(index++));
if (digit >= base || digit > floor((maxInt - i) / w)) {
error('overflow');
}
i += digit * w;
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
if (digit < t) {
break;
}
baseMinusT = base - t;
if (w > floor(maxInt / baseMinusT)) {
error('overflow');
}
w *= baseMinusT;
}
out = output.length + 1;
bias = adapt(i - oldi, out, oldi == 0);
// `i` was supposed to wrap around from `out` to `0`,
// incrementing `n` each time, so we'll fix that now:
if (floor(i / out) > maxInt - n) {
error('overflow');
}
n += floor(i / out);
i %= out;
// Insert `n` at position `i` of the output
output.splice(i++, 0, n);
}
return ucs2encode(output);
}
/**
* Converts a string of Unicode symbols (e.g. a domain name label) to a
* Punycode string of ASCII-only symbols.
* @memberOf punycode
* @param {String} input The string of Unicode symbols.
* @returns {String} The resulting Punycode string of ASCII-only symbols.
*/
function encode(input) {
var n,
delta,
handledCPCount,
basicLength,
bias,
j,
m,
q,
k,
t,
currentValue,
output = [],
/** `inputLength` will hold the number of code points in `input`. */
inputLength,
/** Cached calculation results */
handledCPCountPlusOne,
baseMinusT,
qMinusT;
// Convert the input in UCS-2 to Unicode
input = ucs2decode(input);
// Cache the length
inputLength = input.length;
// Initialize the state
n = initialN;
delta = 0;
bias = initialBias;
// Handle the basic code points
for (j = 0; j < inputLength; ++j) {
currentValue = input[j];
if (currentValue < 0x80) {
output.push(stringFromCharCode(currentValue));
}
}
handledCPCount = basicLength = output.length;
// `handledCPCount` is the number of code points that have been handled;
// `basicLength` is the number of basic code points.
// Finish the basic string - if it is not empty - with a delimiter
if (basicLength) {
output.push(delimiter);
}
// Main encoding loop:
while (handledCPCount < inputLength) {
// All non-basic code points < n have been handled already. Find the next
// larger one:
for (m = maxInt, j = 0; j < inputLength; ++j) {
currentValue = input[j];
if (currentValue >= n && currentValue < m) {
m = currentValue;
}
}
// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
// but guard against overflow
handledCPCountPlusOne = handledCPCount + 1;
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
error('overflow');
}
delta += (m - n) * handledCPCountPlusOne;
n = m;
for (j = 0; j < inputLength; ++j) {
currentValue = input[j];
if (currentValue < n && ++delta > maxInt) {
error('overflow');
}
if (currentValue == n) {
// Represent delta as a generalized variable-length integer
for (q = delta, k = base; /* no condition */; k += base) {
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
if (q < t) {
break;
}
qMinusT = q - t;
baseMinusT = base - t;
output.push(
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
);
q = floor(qMinusT / baseMinusT);
}
output.push(stringFromCharCode(digitToBasic(q, 0)));
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
delta = 0;
++handledCPCount;
}
}
++delta;
++n;
}
return output.join('');
}
/**
* Converts a Punycode string representing a domain name or an email address
* to Unicode. Only the Punycoded parts of the input will be converted, i.e.
* it doesn't matter if you call it on a string that has already been
* converted to Unicode.
* @memberOf punycode
* @param {String} input The Punycoded domain name or email address to
* convert to Unicode.
* @returns {String} The Unicode representation of the given Punycode
* string.
*/
function toUnicode(input) {
return mapDomain(input, function(string) {
return regexPunycode.test(string)
? decode(string.slice(4).toLowerCase())
: string;
});
}
/**
* Converts a Unicode string representing a domain name or an email address to
* Punycode. Only the non-ASCII parts of the domain name will be converted,
* i.e. it doesn't matter if you call it with a domain that's already in
* ASCII.
* @memberOf punycode
* @param {String} input The domain name or email address to convert, as a
* Unicode string.
* @returns {String} The Punycode representation of the given domain name or
* email address.
*/
function toASCII(input) {
return mapDomain(input, function(string) {
return regexNonASCII.test(string)
? 'xn--' + encode(string)
: string;
});
}
/*--------------------------------------------------------------------------*/
/** Define the public API */
punycode = {
/**
* A string representing the current Punycode.js version number.
* @memberOf punycode
* @type String
*/
'version': '1.4.1',
/**
* An object of methods to convert from JavaScript's internal character
* representation (UCS-2) to Unicode code points, and back.
* @see <https://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode
* @type Object
*/
'ucs2': {
'decode': ucs2decode,
'encode': ucs2encode
},
'decode': decode,
'encode': encode,
'toASCII': toASCII,
'toUnicode': toUnicode
};
/** Expose `punycode` */
// Some AMD build optimizers, like r.js, check for specific condition patterns
// like the following:
if (
typeof define == 'function' &&
typeof define.amd == 'object' &&
define.amd
) {
define('punycode', function() {
return punycode;
});
} else if (freeExports && freeModule) {
if (module.exports == freeExports) {
// in Node.js, io.js, or RingoJS v0.8.0+
freeModule.exports = punycode;
} else {
// in Narwhal or RingoJS v0.7.0-
for (key in punycode) {
punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
}
}
} else {
// in Rhino or a web browser
root.punycode = punycode;
}
}(this));
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],8:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break.
// See: https://github.com/joyent/node/issues/1707
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
module.exports = function(qs, sep, eq, options) {
sep = sep || '&';
eq = eq || '=';
var obj = {};
if (typeof qs !== 'string' || qs.length === 0) {
return obj;
}
var regexp = /\+/g;
qs = qs.split(sep);
var maxKeys = 1000;
if (options && typeof options.maxKeys === 'number') {
maxKeys = options.maxKeys;
}
var len = qs.length;
// maxKeys <= 0 means that we should not limit keys count
if (maxKeys > 0 && len > maxKeys) {
len = maxKeys;
}
for (var i = 0; i < len; ++i) {
var x = qs[i].replace(regexp, '%20'),
idx = x.indexOf(eq),
kstr, vstr, k, v;
if (idx >= 0) {
kstr = x.substr(0, idx);
vstr = x.substr(idx + 1);
} else {
kstr = x;
vstr = '';
}
k = decodeURIComponent(kstr);
v = decodeURIComponent(vstr);
if (!hasOwnProperty(obj, k)) {
obj[k] = v;
} else if (isArray(obj[k])) {
obj[k].push(v);
} else {
obj[k] = [obj[k], v];
}
}
return obj;
};
var isArray = Array.isArray || function (xs) {
return Object.prototype.toString.call(xs) === '[object Array]';
};
},{}],9:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
var stringifyPrimitive = function(v) {
switch (typeof v) {
case 'string':
return v;
case 'boolean':
return v ? 'true' : 'false';
case 'number':
return isFinite(v) ? v : '';
default:
return '';
}
};
module.exports = function(obj, sep, eq, name) {
sep = sep || '&';
eq = eq || '=';
if (obj === null) {
obj = undefined;
}
if (typeof obj === 'object') {
return map(objectKeys(obj), function(k) {
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
if (isArray(obj[k])) {
return map(obj[k], function(v) {
return ks + encodeURIComponent(stringifyPrimitive(v));
}).join(sep);
} else {
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
}
}).join(sep);
}
if (!name) return '';
return encodeURIComponent(stringifyPrimitive(name)) + eq +
encodeURIComponent(stringifyPrimitive(obj));
};
var isArray = Array.isArray || function (xs) {
return Object.prototype.toString.call(xs) === '[object Array]';
};
function map (xs, f) {
if (xs.map) return xs.map(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
res.push(f(xs[i], i));
}
return res;
}
var objectKeys = Object.keys || function (obj) {
var res = [];
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
}
return res;
};
},{}],10:[function(require,module,exports){
'use strict';
exports.decode = exports.parse = require('./decode');
exports.encode = exports.stringify = require('./encode');
},{"./decode":8,"./encode":9}],11:[function(require,module,exports){
(function (setImmediate,clearImmediate){
var nextTick = require('process/browser.js').nextTick;
var apply = Function.prototype.apply;
var slice = Array.prototype.slice;
var immediateIds = {};
var nextImmediateId = 0;
// DOM APIs, for completeness
exports.setTimeout = function() {
return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
};
exports.setInterval = function() {
return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
};
exports.clearTimeout =
exports.clearInterval = function(timeout) { timeout.close(); };
function Timeout(id, clearFn) {
this._id = id;
this._clearFn = clearFn;
}
Timeout.prototype.unref = Timeout.prototype.ref = function() {};
Timeout.prototype.close = function() {
this._clearFn.call(window, this._id);
};
// Does not start the time, just sets up the members needed.
exports.enroll = function(item, msecs) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = msecs;
};
exports.unenroll = function(item) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = -1;
};
exports._unrefActive = exports.active = function(item) {
clearTimeout(item._idleTimeoutId);
var msecs = item._idleTimeout;
if (msecs >= 0) {
item._idleTimeoutId = setTimeout(function onTimeout() {
if (item._onTimeout)
item._onTimeout();
}, msecs);
}
};
// That's not how node.js implements it but the exposed api is the same.
exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
var id = nextImmediateId++;
var args = arguments.length < 2 ? false : slice.call(arguments, 1);
immediateIds[id] = true;
nextTick(function onNextTick() {
if (immediateIds[id]) {
// fn.call() is faster so we optimize for the common use-case
// @see http://jsperf.com/call-apply-segu
if (args) {
fn.apply(null, args);
} else {
fn.call(null);
}
// Prevent ids from leaking
exports.clearImmediate(id);
}
});
return id;
};
exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
delete immediateIds[id];
};
}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
},{"process/browser.js":6,"timers":11}],12:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
var punycode = require('punycode');
var util = require('./util');
exports.parse = urlParse;
exports.resolve = urlResolve;
exports.resolveObject = urlResolveObject;
exports.format = urlFormat;
exports.Url = Url;
function Url() {
this.protocol = null;
this.slashes = null;
this.auth = null;
this.host = null;
this.port = null;
this.hostname = null;
this.hash = null;
this.search = null;
this.query = null;
this.pathname = null;
this.path = null;
this.href = null;
}
// Reference: RFC 3986, RFC 1808, RFC 2396
// define these here so at least they only have to be
// compiled once on the first module load.
var protocolPattern = /^([a-z0-9.+-]+:)/i,
portPattern = /:[0-9]*$/,
// Special case for a simple path URL
simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
// RFC 2396: characters reserved for delimiting URLs.
// We actually just auto-escape these.
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
// RFC 2396: characters not allowed for various reasons.
unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
// Allowed by RFCs, but cause of XSS attacks. Always escape these.
autoEscape = ['\''].concat(unwise),
// Characters that are never ever allowed in a hostname.
// Note that any invalid chars are also handled, but these
// are the ones that are *expected* to be seen, so we fast-path
// them.
nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
hostEndingChars = ['/', '?', '#'],
hostnameMaxLen = 255,
hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
// protocols that can allow "unsafe" and "unwise" chars.
unsafeProtocol = {
'javascript': true,
'javascript:': true
},
// protocols that never have a hostname.
hostlessProtocol = {
'javascript': true,
'javascript:': true
},
// protocols that always contain a // bit.
slashedProtocol = {
'http': true,
'https': true,
'ftp': true,
'gopher': true,
'file': true,
'http:': true,
'https:': true,
'ftp:': true,
'gopher:': true,
'file:': true
},
querystring = require('querystring');
function urlParse(url, parseQueryString, slashesDenoteHost) {
if (url && util.isObject(url) && url instanceof Url) return url;
var u = new Url;
u.parse(url, parseQueryString, slashesDenoteHost);
return u;
}
Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
if (!util.isString(url)) {
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
}
// Copy chrome, IE, opera backslash-handling behavior.
// Back slashes before the query string get converted to forward slashes
// See: https://code.google.com/p/chromium/issues/detail?id=25916
var queryIndex = url.indexOf('?'),
splitter =
(queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
uSplit = url.split(splitter),
slashRegex = /\\/g;
uSplit[0] = uSplit[0].replace(slashRegex, '/');
url = uSplit.join(splitter);
var rest = url;
// trim before proceeding.
// This is to support parse stuff like " http://foo.com \n"
rest = rest.trim();
if (!slashesDenoteHost && url.split('#').length === 1) {
// Try fast path regexp
var simplePath = simplePathPattern.exec(rest);
if (simplePath) {
this.path = rest;
this.href = rest;
this.pathname = simplePath[1];
if (simplePath[2]) {
this.search = simplePath[2];
if (parseQueryString) {
this.query = querystring.parse(this.search.substr(1));
} else {
this.query = this.search.substr(1);
}
} else if (parseQueryString) {
this.search = '';
this.query = {};
}
return this;
}
}
var proto = protocolPattern.exec(rest);
if (proto) {
proto = proto[0];
var lowerProto = proto.toLowerCase();
this.protocol = lowerProto;
rest = rest.substr(proto.length);
}
// figure out if it's got a host
// user@server is *always* interpreted as a hostname, and url
// resolution will treat //foo/bar as host=foo,path=bar because that's
// how the browser resolves relative URLs.
if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
var slashes = rest.substr(0, 2) === '//';
if (slashes && !(proto && hostlessProtocol[proto])) {
rest = rest.substr(2);
this.slashes = true;
}
}
if (!hostlessProtocol[proto] &&
(slashes || (proto && !slashedProtocol[proto]))) {
// there's a hostname.
// the first instance of /, ?, ;, or # ends the host.
//
// If there is an @ in the hostname, then non-host chars *are* allowed
// to the left of the last @ sign, unless some host-ending character
// comes *before* the @-sign.
// URLs are obnoxious.
//
// ex:
// http://a@b@c/ => user:a@b host:c
// http://a@b?@c => user:a host:c path:/?@c
// v0.12 TODO(isaacs): This is not quite how Chrome does things.
// Review our test case against browsers more comprehensively.
// find the first instance of any hostEndingChars
var hostEnd = -1;
for (var i = 0; i < hostEndingChars.length; i++) {
var hec = rest.indexOf(hostEndingChars[i]);
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
hostEnd = hec;
}
// at this point, either we have an explicit point where the
// auth portion cannot go past, or the last @ char is the decider.
var auth, atSign;
if (hostEnd === -1) {
// atSign can be anywhere.
atSign = rest.lastIndexOf('@');
} else {
// atSign must be in auth portion.
// http://a@b/c@d => host:b auth:a path:/c@d
atSign = rest.lastIndexOf('@', hostEnd);
}
// Now we have a portion which is definitely the auth.
// Pull that off.
if (atSign !== -1) {
auth = rest.slice(0, atSign);
rest = rest.slice(atSign + 1);
this.auth = decodeURIComponent(auth);
}
// the host is the remaining to the left of the first non-host char
hostEnd = -1;
for (var i = 0; i < nonHostChars.length; i++) {
var hec = rest.indexOf(nonHostChars[i]);
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
hostEnd = hec;
}
// if we still have not hit it, then the entire thing is a host.
if (hostEnd === -1)
hostEnd = rest.length;
this.host = rest.slice(0, hostEnd);
rest = rest.slice(hostEnd);
// pull out port.
this.parseHost();
// we've indicated that there is a hostname,
// so even if it's empty, it has to be present.
this.hostname = this.hostname || '';
// if hostname begins with [ and ends with ]
// assume that it's an IPv6 address.
var ipv6Hostname = this.hostname[0] === '[' &&
this.hostname[this.hostname.length - 1] === ']';
// validate a little.
if (!ipv6Hostname) {
var hostparts = this.hostname.split(/\./);
for (var i = 0, l = hostparts.length; i < l; i++) {
var part = hostparts[i];
if (!part) continue;
if (!part.match(hostnamePartPattern)) {
var newpart = '';
for (var j = 0, k = part.length; j < k; j++) {
if (part.charCodeAt(j) > 127) {
// we replace non-ASCII char with a temporary placeholder
// we need this to make sure size of hostname is not
// broken by replacing non-ASCII by nothing
newpart += 'x';
} else {
newpart += part[j];
}
}
// we test again with ASCII char only
if (!newpart.match(hostnamePartPattern)) {
var validParts = hostparts.slice(0, i);
var notHost = hostparts.slice(i + 1);
var bit = part.match(hostnamePartStart);
if (bit) {
validParts.push(bit[1]);
notHost.unshift(bit[2]);
}
if (notHost.length) {
rest = '/' + notHost.join('.') + rest;
}
this.hostname = validParts.join('.');
break;
}
}
}
}
if (this.hostname.length > hostnameMaxLen) {
this.hostname = '';
} else {
// hostnames are always lower case.
this.hostname = this.hostname.toLowerCase();
}
if (!ipv6Hostname) {
// IDNA Support: Returns a punycoded representation of "domain".
// It only converts parts of the domain name that
// have non-ASCII characters, i.e. it doesn't matter if
// you call it with a domain that already is ASCII-only.
this.hostname = punycode.toASCII(this.hostname);
}
var p = this.port ? ':' + this.port : '';
var h = this.hostname || '';
this.host = h + p;
this.href += this.host;
// strip [ and ] from the hostname
// the host field still retains them, though
if (ipv6Hostname) {
this.hostname = this.hostname.substr(1, this.hostname.length - 2);
if (rest[0] !== '/') {
rest = '/' + rest;
}
}
}
// now rest is set to the post-host stuff.
// chop off any delim chars.
if (!unsafeProtocol[lowerProto]) {
// First, make 100% sure that any "autoEscape" chars get
// escaped, even if encodeURIComponent doesn't think they
// need to be.
for (var i = 0, l = autoEscape.length; i < l; i++) {
var ae = autoEscape[i];
if (rest.indexOf(ae) === -1)
continue;
var esc = encodeURIComponent(ae);
if (esc === ae) {
esc = escape(ae);
}
rest = rest.split(ae).join(esc);
}
}
// chop off from the tail first.
var hash = rest.indexOf('#');
if (hash !== -1) {
// got a fragment string.
this.hash = rest.substr(hash);
rest = rest.slice(0, hash);
}
var qm = rest.indexOf('?');
if (qm !== -1) {
this.search = rest.substr(qm);
this.query = rest.substr(qm + 1);
if (parseQueryString) {
this.query = querystring.parse(this.query);
}
rest = rest.slice(0, qm);
} else if (parseQueryString) {
// no query string, but parseQueryString still requested
this.search = '';
this.query = {};
}
if (rest) this.pathname = rest;
if (slashedProtocol[lowerProto] &&
this.hostname && !this.pathname) {
this.pathname = '/';
}
//to support http.request
if (this.pathname || this.search) {
var p = this.pathname || '';
var s = this.search || '';
this.path = p + s;
}
// finally, reconstruct the href based on what has been validated.
this.href = this.format();
return this;
};
// format a parsed object into a url string
function urlFormat(obj) {
// ensure it's an object, and not a string url.
// If it's an obj, this is a no-op.
// this way, you can call url_format() on strings
// to clean up potentially wonky urls.
if (util.isString(obj)) obj = urlParse(obj);
if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
return obj.format();
}
Url.prototype.format = function() {
var auth = this.auth || '';
if (auth) {
auth = encodeURIComponent(auth);
auth = auth.replace(/%3A/i, ':');
auth += '@';
}
var protocol = this.protocol || '',
pathname = this.pathname || '',
hash = this.hash || '',
host = false,
query = '';
if (this.host) {
host = auth + this.host;
} else if (this.hostname) {
host = auth + (this.hostname.indexOf(':') === -1 ?
this.hostname :
'[' + this.hostname + ']');
if (this.port) {
host += ':' + this.port;
}
}
if (this.query &&
util.isObject(this.query) &&
Object.keys(this.query).length) {
query = querystring.stringify(this.query);
}
var search = this.search || (query && ('?' + query)) || '';
if (protocol && protocol.substr(-1) !== ':') protocol += ':';
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
// unless they had them to begin with.
if (this.slashes ||
(!protocol || slashedProtocol[protocol]) && host !== false) {
host = '//' + (host || '');
if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
} else if (!host) {
host = '';
}
if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
if (search && search.charAt(0) !== '?') search = '?' + search;
pathname = pathname.replace(/[?#]/g, function(match) {
return encodeURIComponent(match);
});
search = search.replace('#', '%23');
return protocol + host + pathname + search + hash;
};
function urlResolve(source, relative) {
return urlParse(source, false, true).resolve(relative);
}
Url.prototype.resolve = function(relative) {
return this.resolveObject(urlParse(relative, false, true)).format();
};
function urlResolveObject(source, relative) {
if (!source) return relative;
return urlParse(source, false, true).resolveObject(relative);
}
Url.prototype.resolveObject = function(relative) {
if (util.isString(relative)) {
var rel = new Url();
rel.parse(relative, false, true);
relative = rel;
}
var result = new Url();
var tkeys = Object.keys(this);
for (var tk = 0; tk < tkeys.length; tk++) {
var tkey = tkeys[tk];
result[tkey] = this[tkey];
}
// hash is always overridden, no matter what.
// even href="" will remove it.
result.hash = relative.hash;
// if the relative url is empty, then there's nothing left to do here.
if (relative.href === '') {
result.href = result.format();
return result;
}
// hrefs like //foo/bar always cut to the protocol.
if (relative.slashes && !relative.protocol) {
// take everything except the protocol from relative
var rkeys = Object.keys(relative);
for (var rk = 0; rk < rkeys.length; rk++) {
var rkey = rkeys[rk];
if (rkey !== 'protocol')
result[rkey] = relative[rkey];
}
//urlParse appends trailing / to urls like http://www.example.com
if (slashedProtocol[result.protocol] &&
result.hostname && !result.pathname) {
result.path = result.pathname = '/';
}
result.href = result.format();
return result;
}
if (relative.protocol && relative.protocol !== result.protocol) {
// if it's a known url protocol, then changing
// the protocol does weird things
// first, if it's not file:, then we MUST have a host,
// and if there was a path
// to begin with, then we MUST have a path.
// if it is file:, then the host is dropped,
// because that's known to be hostless.
// anything else is assumed to be absolute.
if (!slashedProtocol[relative.protocol]) {
var keys = Object.keys(relative);
for (var v = 0; v < keys.length; v++) {
var k = keys[v];
result[k] = relative[k];
}
result.href = result.format();
return result;
}
result.protocol = relative.protocol;
if (!relative.host && !hostlessProtocol[relative.protocol]) {
var relPath = (relative.pathname || '').split('/');
while (relPath.length && !(relative.host = relPath.shift()));
if (!relative.host) relative.host = '';
if (!relative.hostname) relative.hostname = '';
if (relPath[0] !== '') relPath.unshift('');
if (relPath.length < 2) relPath.unshift('');
result.pathname = relPath.join('/');
} else {
result.pathname = relative.pathname;
}
result.search = relative.search;
result.query = relative.query;
result.host = relative.host || '';
result.auth = relative.auth;
result.hostname = relative.hostname || relative.host;
result.port = relative.port;
// to support http.request
if (result.pathname || result.search) {
var p = result.pathname || '';
var s = result.search || '';
result.path = p + s;
}
result.slashes = result.slashes || relative.slashes;
result.href = result.format();
return result;
}
var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
isRelAbs = (
relative.host ||
relative.pathname && relative.pathname.charAt(0) === '/'
),
mustEndAbs = (isRelAbs || isSourceAbs ||
(result.host && relative.pathname)),
removeAllDots = mustEndAbs,
srcPath = result.pathname && result.pathname.split('/') || [],
relPath = relative.pathname && relative.pathname.split('/') || [],
psychotic = result.protocol && !slashedProtocol[result.protocol];
// if the url is a non-slashed url, then relative
// links like ../.. should be able
// to crawl up to the hostname, as well. This is strange.
// result.protocol has already been set by now.
// Later on, put the first path part into the host field.
if (psychotic) {
result.hostname = '';
result.port = null;
if (result.host) {
if (srcPath[0] === '') srcPath[0] = result.host;
else srcPath.unshift(result.host);
}
result.host = '';
if (relative.protocol) {
relative.hostname = null;
relative.port = null;
if (relative.host) {
if (relPath[0] === '') relPath[0] = relative.host;
else relPath.unshift(relative.host);
}
relative.host = null;
}
mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
}
if (isRelAbs) {
// it's absolute.
result.host = (relative.host || relative.host === '') ?
relative.host : result.host;
result.hostname = (relative.hostname || relative.hostname === '') ?
relative.hostname : result.hostname;
result.search = relative.search;
result.query = relative.query;
srcPath = relPath;
// fall through to the dot-handling below.
} else if (relPath.length) {
// it's relative
// throw away the existing file, and take the new path instead.
if (!srcPath) srcPath = [];
srcPath.pop();
srcPath = srcPath.concat(relPath);
result.search = relative.search;
result.query = relative.query;
} else if (!util.isNullOrUndefined(relative.search)) {
// just pull out the search.
// like href='?foo'.
// Put this after the other two cases because it simplifies the booleans
if (psychotic) {
result.hostname = result.host = srcPath.shift();
//occationaly the auth can get stuck only in host
//this especially happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
var authInHost = result.host && result.host.indexOf('@') > 0 ?
result.host.split('@') : false;
if (authInHost) {
result.auth = authInHost.shift();
result.host = result.hostname = authInHost.shift();
}
}
result.search = relative.search;
result.query = relative.query;
//to support http.request
if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
result.path = (result.pathname ? result.pathname : '') +
(result.search ? result.search : '');
}
result.href = result.format();
return result;
}
if (!srcPath.length) {
// no path at all. easy.
// we've already handled the other stuff above.
result.pathname = null;
//to support http.request
if (result.search) {
result.path = '/' + result.search;
} else {
result.path = null;
}
result.href = result.format();
return result;
}
// if a url ENDs in . or .., then it must get a trailing slash.
// however, if it ends in anything else non-slashy,
// then it must NOT get a trailing slash.
var last = srcPath.slice(-1)[0];
var hasTrailingSlash = (
(result.host || relative.host || srcPath.length > 1) &&
(last === '.' || last === '..') || last === '');
// strip single dots, resolve double dots to parent dir
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = srcPath.length; i >= 0; i--) {
last = srcPath[i];
if (last === '.') {
srcPath.splice(i, 1);
} else if (last === '..') {
srcPath.splice(i, 1);
up++;
} else if (up) {
srcPath.splice(i, 1);
up--;
}
}
// if the path is allowed to go above the root, restore leading ..s
if (!mustEndAbs && !removeAllDots) {
for (; up--; up) {
srcPath.unshift('..');
}
}
if (mustEndAbs && srcPath[0] !== '' &&
(!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
srcPath.unshift('');
}
if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
srcPath.push('');
}
var isAbsolute = srcPath[0] === '' ||
(srcPath[0] && srcPath[0].charAt(0) === '/');
// put the host back
if (psychotic) {
result.hostname = result.host = isAbsolute ? '' :
srcPath.length ? srcPath.shift() : '';
//occationaly the auth can get stuck only in host
//this especially happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
var authInHost = result.host && result.host.indexOf('@') > 0 ?
result.host.split('@') : false;
if (authInHost) {
result.auth = authInHost.shift();
result.host = result.hostname = authInHost.shift();
}
}
mustEndAbs = mustEndAbs || (result.host && srcPath.length);
if (mustEndAbs && !isAbsolute) {
srcPath.unshift('');
}
if (!srcPath.length) {
result.pathname = null;
result.path = null;
} else {
result.pathname = srcPath.join('/');
}
//to support request.http
if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
result.path = (result.pathname ? result.pathname : '') +
(result.search ? result.search : '');
}
result.auth = relative.auth || result.auth;
result.slashes = result.slashes || relative.slashes;
result.href = result.format();
return result;
};
Url.prototype.parseHost = function() {
var host = this.host;
var port = portPattern.exec(host);
if (port) {
port = port[0];
if (port !== ':') {
this.port = port.substr(1);
}
host = host.substr(0, host.length - port.length);
}
if (host) this.hostname = host;
};
},{"./util":13,"punycode":7,"querystring":10}],13:[function(require,module,exports){
'use strict';
module.exports = {
isString: function(arg) {
return typeof(arg) === 'string';
},
isObject: function(arg) {
return typeof(arg) === 'object' && arg !== null;
},
isNull: function(arg) {
return arg === null;
},
isNullOrUndefined: function(arg) {
return arg == null;
}
};
},{}],14:[function(require,module,exports){
//This is for browserify to build the required CSS module into something we can use in the browser.
window.css = require('css');
},{"css":16}],15:[function(require,module,exports){
(function (Buffer){
(function (w) {
"use strict";
function findBest(atobNative) {
// normal window
if ('function' === typeof atobNative) { return atobNative; }
// browserify (web worker)
if ('function' === typeof Buffer) {
return function atobBrowserify(a) {
//!! Deliberately using an API that's deprecated in node.js because
//!! this file is for browsers and we expect them to cope with it.
//!! Discussion: github.com/node-browser-compat/atob/pull/9
return new Buffer(a, 'base64').toString('binary');
};
}
// ios web worker with base64js
if ('object' === typeof w.base64js) {
// bufferToBinaryString
// https://git.coolaj86.com/coolaj86/unibabel.js/blob/master/index.js#L50
return function atobWebWorker_iOS(a) {
var buf = w.base64js.b64ToByteArray(a);
return Array.prototype.map.call(buf, function (ch) {
return String.fromCharCode(ch);
}).join('');
};
}
return function () {
// ios web worker without base64js
throw new Error("You're probably in an old browser or an iOS webworker." +
" It might help to include beatgammit's base64-js.");
};
}
var atobBest = findBest(w.atob);
w.atob = atobBest;
if ((typeof module === 'object') && module && module.exports) {
module.exports = atobBest;
}
}(window));
}).call(this,require("buffer").Buffer)
},{"buffer":3}],16:[function(require,module,exports){
exports.parse = require('./lib/parse');
exports.stringify = require('./lib/stringify');
},{"./lib/parse":17,"./lib/stringify":21}],17:[function(require,module,exports){
// http://www.w3.org/TR/CSS21/grammar.html
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g
module.exports = function(css, options){
options = options || {};
/**
* Positional.
*/
var lineno = 1;
var column = 1;
/**
* Update lineno and column based on `str`.
*/
function updatePosition(str) {
var lines = str.match(/\n/g);
if (lines) lineno += lines.length;
var i = str.lastIndexOf('\n');
column = ~i ? str.length - i : column + str.length;
}
/**
* Mark position and patch `node.position`.
*/
function position() {
var start = { line: lineno, column: column };
return function(node){
node.position = new Position(start);
whitespace();
return node;
};
}
/**
* Store position information for a node
*/
function Position(start) {
this.start = start;
this.end = { line: lineno, column: column };
this.source = options.source;
}
/**
* Non-enumerable source string
*/
Position.prototype.content = css;
/**
* Error `msg`.
*/
var errorsList = [];
function error(msg) {
var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
err.reason = msg;
err.filename = options.source;
err.line = lineno;
err.column = column;
err.source = css;
if (options.silent) {
errorsList.push(err);
} else {
throw err;
}
}
/**
* Parse stylesheet.
*/
function stylesheet() {
var rulesList = rules();
return {
type: 'stylesheet',
stylesheet: {
source: options.source,
rules: rulesList,
parsingErrors: errorsList
}
};
}
/**
* Opening brace.
*/
function open() {
return match(/^{\s*/);
}
/**
* Closing brace.
*/
function close() {
return match(/^}/);
}
/**
* Parse ruleset.
*/
function rules() {
var node;
var rules = [];
whitespace();
comments(rules);
while (css.length && css.charAt(0) != '}' && (node = atrule() || rule())) {
if (node !== false) {
rules.push(node);
comments(rules);
}
}
return rules;
}
/**
* Match `re` and return captures.
*/
function match(re) {
var m = re.exec(css);
if (!m) return;
var str = m[0];
updatePosition(str);
css = css.slice(str.length);
return m;
}
/**
* Parse whitespace.
*/
function whitespace() {
match(/^\s*/);
}
/**
* Parse comments;
*/
function comments(rules) {
var c;
rules = rules || [];
while (c = comment()) {
if (c !== false) {
rules.push(c);
}
}
return rules;
}
/**
* Parse comment.
*/
function comment() {
var pos = position();
if ('/' != css.charAt(0) || '*' != css.charAt(1)) return;
var i = 2;
while ("" != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i;
i += 2;
if ("" === css.charAt(i-1)) {
return error('End of comment missing');
}
var str = css.slice(2, i - 2);
column += 2;
updatePosition(str);
css = css.slice(i);
column += 2;
return pos({
type: 'comment',
comment: str
});
}
/**
* Parse selector.
*/
function selector() {
var m = match(/^([^{]+)/);
if (!m) return;
/* @fix Remove all comments from selectors
* http://ostermiller.org/findcomment.html */
return trim(m[0])
.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
.replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(m) {
return m.replace(/,/g, '\u200C');
})
.split(/\s*(?![^(]*\)),\s*/)
.map(function(s) {
return s.replace(/\u200C/g, ',');
});
}
/**
* Parse declaration.
*/
function declaration() {
var pos = position();
// prop
var prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
if (!prop) return;
prop = trim(prop[0]);
// :
if (!match(/^:\s*/)) return error("property missing ':'");
// val
var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
var ret = pos({
type: 'declaration',
property: prop.replace(commentre, ''),
value: val ? trim(val[0]).replace(commentre, '') : ''
});
// ;
match(/^[;\s]*/);
return ret;
}
/**
* Parse declarations.
*/
function declarations() {
var decls = [];
if (!open()) return error("missing '{'");
comments(decls);
// declarations
var decl;
while (decl = declaration()) {
if (decl !== false) {
decls.push(decl);
comments(decls);
}
}
if (!close()) return error("missing '}'");
return decls;
}
/**
* Parse keyframe.
*/
function keyframe() {
var m;
var vals = [];
var pos = position();
while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) {
vals.push(m[1]);
match(/^,\s*/);
}
if (!vals.length) return;
return pos({
type: 'keyframe',
values: vals,
declarations: declarations()
});
}
/**
* Parse keyframes.
*/
function atkeyframes() {
var pos = position();
var m = match(/^@([-\w]+)?keyframes\s*/);
if (!m) return;
var vendor = m[1];
// identifier
var m = match(/^([-\w]+)\s*/);
if (!m) return error("@keyframes missing name");
var name = m[1];
if (!open()) return error("@keyframes missing '{'");
var frame;
var frames = comments();
while (frame = keyframe()) {
frames.push(frame);
frames = frames.concat(comments());
}
if (!close()) return error("@keyframes missing '}'");
return pos({
type: 'keyframes',
name: name,
vendor: vendor,
keyframes: frames
});
}
/**
* Parse supports.
*/
function atsupports() {
var pos = position();
var m = match(/^@supports *([^{]+)/);
if (!m) return;
var supports = trim(m[1]);
if (!open()) return error("@supports missing '{'");
var style = comments().concat(rules());
if (!close()) return error("@supports missing '}'");
return pos({
type: 'supports',
supports: supports,
rules: style
});
}
/**
* Parse host.
*/
function athost() {
var pos = position();
var m = match(/^@host\s*/);
if (!m) return;
if (!open()) return error("@host missing '{'");
var style = comments().concat(rules());
if (!close()) return error("@host missing '}'");
return pos({
type: 'host',
rules: style
});
}
/**
* Parse media.
*/
function atmedia() {
var pos = position();
var m = match(/^@media *([^{]+)/);
if (!m) return;
var media = trim(m[1]);
if (!open()) return error("@media missing '{'");
var style = comments().concat(rules());
if (!close()) return error("@media missing '}'");
return pos({
type: 'media',
media: media,
rules: style
});
}
/**
* Parse custom-media.
*/
function atcustommedia() {
var pos = position();
var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
if (!m) return;
return pos({
type: 'custom-media',
name: trim(m[1]),
media: trim(m[2])
});
}
/**
* Parse paged media.
*/
function atpage() {
var pos = position();
var m = match(/^@page */);
if (!m) return;
var sel = selector() || [];
if (!open()) return error("@page missing '{'");
var decls = comments();
// declarations
var decl;
while (decl = declaration()) {
decls.push(decl);
decls = decls.concat(comments());
}
if (!close()) return error("@page missing '}'");
return pos({
type: 'page',
selectors: sel,
declarations: decls
});
}
/**
* Parse document.
*/
function atdocument() {
var pos = position();
var m = match(/^@([-\w]+)?document *([^{]+)/);
if (!m) return;
var vendor = trim(m[1]);
var doc = trim(m[2]);
if (!open()) return error("@document missing '{'");
var style = comments().concat(rules());
if (!close()) return error("@document missing '}'");
return pos({
type: 'document',
document: doc,
vendor: vendor,
rules: style
});
}
/**
* Parse font-face.
*/
function atfontface() {
var pos = position();
var m = match(/^@font-face\s*/);
if (!m) return;
if (!open()) return error("@font-face missing '{'");
var decls = comments();
// declarations
var decl;
while (decl = declaration()) {
decls.push(decl);
decls = decls.concat(comments());
}
if (!close()) return error("@font-face missing '}'");
return pos({
type: 'font-face',
declarations: decls
});
}
/**
* Parse import
*/
var atimport = _compileAtrule('import');
/**
* Parse charset
*/
var atcharset = _compileAtrule('charset');
/**
* Parse namespace
*/
var atnamespace = _compileAtrule('namespace');
/**
* Parse non-block at-rules
*/
function _compileAtrule(name) {
var re = new RegExp('^@' + name + '\\s*([^;]+);');
return function() {
var pos = position();
var m = match(re);
if (!m) return;
var ret = { type: name };
ret[name] = m[1].trim();
return pos(ret);
}
}
/**
* Parse at rule.
*/
function atrule() {
if (css[0] != '@') return;
return atkeyframes()
|| atmedia()
|| atcustommedia()
|| atsupports()
|| atimport()
|| atcharset()
|| atnamespace()
|| atdocument()
|| atpage()
|| athost()
|| atfontface();
}
/**
* Parse rule.
*/
function rule() {
var pos = position();
var sel = selector();
if (!sel) return error('selector missing');
comments();
return pos({
type: 'rule',
selectors: sel,
declarations: declarations()
});
}
return addParent(stylesheet());
};
/**
* Trim `str`.
*/
function trim(str) {
return str ? str.replace(/^\s+|\s+$/g, '') : '';
}
/**
* Adds non-enumerable parent node reference to each node.
*/
function addParent(obj, parent) {
var isNode = obj && typeof obj.type === 'string';
var childParent = isNode ? obj : parent;
for (var k in obj) {
var value = obj[k];
if (Array.isArray(value)) {
value.forEach(function(v) { addParent(v, childParent); });
} else if (value && typeof value === 'object') {
addParent(value, childParent);
}
}
if (isNode) {
Object.defineProperty(obj, 'parent', {
configurable: true,
writable: true,
enumerable: false,
value: parent || null
});
}
return obj;
}
},{}],18:[function(require,module,exports){
/**
* Expose `Compiler`.
*/
module.exports = Compiler;
/**
* Initialize a compiler.
*
* @param {Type} name
* @return {Type}
* @api public
*/
function Compiler(opts) {
this.options = opts || {};
}
/**
* Emit `str`
*/
Compiler.prototype.emit = function(str) {
return str;
};
/**
* Visit `node`.
*/
Compiler.prototype.visit = function(node){
return this[node.type](node);
};
/**
* Map visit over array of `nodes`, optionally using a `delim`
*/
Compiler.prototype.mapVisit = function(nodes, delim){
var buf = '';
delim = delim || '';
for (var i = 0, length = nodes.length; i < length; i++) {
buf += this.visit(nodes[i]);
if (delim && i < length - 1) buf += this.emit(delim);
}
return buf;
};
},{}],19:[function(require,module,exports){
/**
* Module dependencies.
*/
var Base = require('./compiler');
var inherits = require('inherits');
/**
* Expose compiler.
*/
module.exports = Compiler;
/**
* Initialize a new `Compiler`.
*/
function Compiler(options) {
Base.call(this, options);
}
/**
* Inherit from `Base.prototype`.
*/
inherits(Compiler, Base);
/**
* Compile `node`.
*/
Compiler.prototype.compile = function(node){
return node.stylesheet
.rules.map(this.visit, this)
.join('');
};
/**
* Visit comment node.
*/
Compiler.prototype.comment = function(node){
return this.emit('', node.position);
};
/**
* Visit import node.
*/
Compiler.prototype.import = function(node){
return this.emit('@import ' + node.import + ';', node.position);
};
/**
* Visit media node.
*/
Compiler.prototype.media = function(node){
return this.emit('@media ' + node.media, node.position)
+ this.emit('{')
+ this.mapVisit(node.rules)
+ this.emit('}');
};
/**
* Visit document node.
*/
Compiler.prototype.document = function(node){
var doc = '@' + (node.vendor || '') + 'document ' + node.document;
return this.emit(doc, node.position)
+ this.emit('{')
+ this.mapVisit(node.rules)
+ this.emit('}');
};
/**
* Visit charset node.
*/
Compiler.prototype.charset = function(node){
return this.emit('@charset ' + node.charset + ';', node.position);
};
/**
* Visit namespace node.
*/
Compiler.prototype.namespace = function(node){
return this.emit('@namespace ' + node.namespace + ';', node.position);
};
/**
* Visit supports node.
*/
Compiler.prototype.supports = function(node){
return this.emit('@supports ' + node.supports, node.position)
+ this.emit('{')
+ this.mapVisit(node.rules)
+ this.emit('}');
};
/**
* Visit keyframes node.
*/
Compiler.prototype.keyframes = function(node){
return this.emit('@'
+ (node.vendor || '')
+ 'keyframes '
+ node.name, node.position)
+ this.emit('{')
+ this.mapVisit(node.keyframes)
+ this.emit('}');
};
/**
* Visit keyframe node.
*/
Compiler.prototype.keyframe = function(node){
var decls = node.declarations;
return this.emit(node.values.join(','), node.position)
+ this.emit('{')
+ this.mapVisit(decls)
+ this.emit('}');
};
/**
* Visit page node.
*/
Compiler.prototype.page = function(node){
var sel = node.selectors.length
? node.selectors.join(', ')
: '';
return this.emit('@page ' + sel, node.position)
+ this.emit('{')
+ this.mapVisit(node.declarations)
+ this.emit('}');
};
/**
* Visit font-face node.
*/
Compiler.prototype['font-face'] = function(node){
return this.emit('@font-face', node.position)
+ this.emit('{')
+ this.mapVisit(node.declarations)
+ this.emit('}');
};
/**
* Visit host node.
*/
Compiler.prototype.host = function(node){
return this.emit('@host', node.position)
+ this.emit('{')
+ this.mapVisit(node.rules)
+ this.emit('}');
};
/**
* Visit custom-media node.
*/
Compiler.prototype['custom-media'] = function(node){
return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
};
/**
* Visit rule node.
*/
Compiler.prototype.rule = function(node){
var decls = node.declarations;
if (!decls.length) return '';
return this.emit(node.selectors.join(','), node.position)
+ this.emit('{')
+ this.mapVisit(decls)
+ this.emit('}');
};
/**
* Visit declaration node.
*/
Compiler.prototype.declaration = function(node){
return this.emit(node.property + ':' + node.value, node.position) + this.emit(';');
};
},{"./compiler":18,"inherits":24}],20:[function(require,module,exports){
/**
* Module dependencies.
*/
var Base = require('./compiler');
var inherits = require('inherits');
/**
* Expose compiler.
*/
module.exports = Compiler;
/**
* Initialize a new `Compiler`.
*/
function Compiler(options) {
options = options || {};
Base.call(this, options);
this.indentation = options.indent;
}
/**
* Inherit from `Base.prototype`.
*/
inherits(Compiler, Base);
/**
* Compile `node`.
*/
Compiler.prototype.compile = function(node){
return this.stylesheet(node);
};
/**
* Visit stylesheet node.
*/
Compiler.prototype.stylesheet = function(node){
return this.mapVisit(node.stylesheet.rules, '\n\n');
};
/**
* Visit comment node.
*/
Compiler.prototype.comment = function(node){
return this.emit(this.indent() + '/*' + node.comment + '*/', node.position);
};
/**
* Visit import node.
*/
Compiler.prototype.import = function(node){
return this.emit('@import ' + node.import + ';', node.position);
};
/**
* Visit media node.
*/
Compiler.prototype.media = function(node){
return this.emit('@media ' + node.media, node.position)
+ this.emit(
' {\n'
+ this.indent(1))
+ this.mapVisit(node.rules, '\n\n')
+ this.emit(
this.indent(-1)
+ '\n}');
};
/**
* Visit document node.
*/
Compiler.prototype.document = function(node){
var doc = '@' + (node.vendor || '') + 'document ' + node.document;
return this.emit(doc, node.position)
+ this.emit(
' '
+ ' {\n'
+ this.indent(1))
+ this.mapVisit(node.rules, '\n\n')
+ this.emit(
this.indent(-1)
+ '\n}');
};
/**
* Visit charset node.
*/
Compiler.prototype.charset = function(node){
return this.emit('@charset ' + node.charset + ';', node.position);
};
/**
* Visit namespace node.
*/
Compiler.prototype.namespace = function(node){
return this.emit('@namespace ' + node.namespace + ';', node.position);
};
/**
* Visit supports node.
*/
Compiler.prototype.supports = function(node){
return this.emit('@supports ' + node.supports, node.position)
+ this.emit(
' {\n'
+ this.indent(1))
+ this.mapVisit(node.rules, '\n\n')
+ this.emit(
this.indent(-1)
+ '\n}');
};
/**
* Visit keyframes node.
*/
Compiler.prototype.keyframes = function(node){
return this.emit('@' + (node.vendor || '') + 'keyframes ' + node.name, node.position)
+ this.emit(
' {\n'
+ this.indent(1))
+ this.mapVisit(node.keyframes, '\n')
+ this.emit(
this.indent(-1)
+ '}');
};
/**
* Visit keyframe node.
*/
Compiler.prototype.keyframe = function(node){
var decls = node.declarations;
return this.emit(this.indent())
+ this.emit(node.values.join(', '), node.position)
+ this.emit(
' {\n'
+ this.indent(1))
+ this.mapVisit(decls, '\n')
+ this.emit(
this.indent(-1)
+ '\n'
+ this.indent() + '}\n');
};
/**
* Visit page node.
*/
Compiler.prototype.page = function(node){
var sel = node.selectors.length
? node.selectors.join(', ') + ' '
: '';
return this.emit('@page ' + sel, node.position)
+ this.emit('{\n')
+ this.emit(this.indent(1))
+ this.mapVisit(node.declarations, '\n')
+ this.emit(this.indent(-1))
+ this.emit('\n}');
};
/**
* Visit font-face node.
*/
Compiler.prototype['font-face'] = function(node){
return this.emit('@font-face ', node.position)
+ this.emit('{\n')
+ this.emit(this.indent(1))
+ this.mapVisit(node.declarations, '\n')
+ this.emit(this.indent(-1))
+ this.emit('\n}');
};
/**
* Visit host node.
*/
Compiler.prototype.host = function(node){
return this.emit('@host', node.position)
+ this.emit(
' {\n'
+ this.indent(1))
+ this.mapVisit(node.rules, '\n\n')
+ this.emit(
this.indent(-1)
+ '\n}');
};
/**
* Visit custom-media node.
*/
Compiler.prototype['custom-media'] = function(node){
return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
};
/**
* Visit rule node.
*/
Compiler.prototype.rule = function(node){
var indent = this.indent();
var decls = node.declarations;
if (!decls.length) return '';
return this.emit(node.selectors.map(function(s){ return indent + s }).join(',\n'), node.position)
+ this.emit(' {\n')
+ this.emit(this.indent(1))
+ this.mapVisit(decls, '\n')
+ this.emit(this.indent(-1))
+ this.emit('\n' + this.indent() + '}');
};
/**
* Visit declaration node.
*/
Compiler.prototype.declaration = function(node){
return this.emit(this.indent())
+ this.emit(node.property + ': ' + node.value, node.position)
+ this.emit(';');
};
/**
* Increase, decrease or return current indentation.
*/
Compiler.prototype.indent = function(level) {
this.level = this.level || 1;
if (null != level) {
this.level += level;
return '';
}
return Array(this.level).join(this.indentation || ' ');
};
},{"./compiler":18,"inherits":24}],21:[function(require,module,exports){
/**
* Module dependencies.
*/
var Compressed = require('./compress');
var Identity = require('./identity');
/**
* Stringfy the given AST `node`.
*
* Options:
*
* - `compress` space-optimized output
* - `sourcemap` return an object with `.code` and `.map`
*
* @param {Object} node
* @param {Object} [options]
* @return {String}
* @api public
*/
module.exports = function(node, options){
options = options || {};
var compiler = options.compress
? new Compressed(options)
: new Identity(options);
// source maps
if (options.sourcemap) {
var sourcemaps = require('./source-map-support');
sourcemaps(compiler);
var code = compiler.compile(node);
compiler.applySourceMaps();
var map = options.sourcemap === 'generator'
? compiler.map
: compiler.map.toJSON();
return { code: code, map: map };
}
var code = compiler.compile(node);
return code;
};
},{"./compress":19,"./identity":20,"./source-map-support":22}],22:[function(require,module,exports){
/**
* Module dependencies.
*/
var SourceMap = require('source-map').SourceMapGenerator;
var SourceMapConsumer = require('source-map').SourceMapConsumer;
var sourceMapResolve = require('source-map-resolve');
var fs = require('fs');
var path = require('path');
/**
* Expose `mixin()`.
*/
module.exports = mixin;
/**
* Ensure Windows-style paths are formatted properly
*/
const makeFriendlyPath = function(aPath) {
return path.sep === "\\" ? aPath.replace(/\\/g, "/").replace(/^[a-z]:\/?/i, "/") : aPath;
}
/**
* Mixin source map support into `compiler`.
*
* @param {Compiler} compiler
* @api public
*/
function mixin(compiler) {
compiler._comment = compiler.comment;
compiler.map = new SourceMap();
compiler.position = { line: 1, column: 1 };
compiler.files = {};
for (var k in exports) compiler[k] = exports[k];
}
/**
* Update position.
*
* @param {String} str
* @api private
*/
exports.updatePosition = function(str) {
var lines = str.match(/\n/g);
if (lines) this.position.line += lines.length;
var i = str.lastIndexOf('\n');
this.position.column = ~i ? str.length - i : this.position.column + str.length;
};
/**
* Emit `str`.
*
* @param {String} str
* @param {Object} [pos]
* @return {String}
* @api private
*/
exports.emit = function(str, pos) {
if (pos) {
var sourceFile = makeFriendlyPath(pos.source || 'source.css');
this.map.addMapping({
source: sourceFile,
generated: {
line: this.position.line,
column: Math.max(this.position.column - 1, 0)
},
original: {
line: pos.start.line,
column: pos.start.column - 1
}
});
this.addFile(sourceFile, pos);
}
this.updatePosition(str);
return str;
};
/**
* Adds a file to the source map output if it has not already been added
* @param {String} file
* @param {Object} pos
*/
exports.addFile = function(file, pos) {
if (typeof pos.content !== 'string') return;
if (Object.prototype.hasOwnProperty.call(this.files, file)) return;
this.files[file] = pos.content;
};
/**
* Applies any original source maps to the output and embeds the source file
* contents in the source map.
*/
exports.applySourceMaps = function() {
Object.keys(this.files).forEach(function(file) {
var content = this.files[file];
this.map.setSourceContent(file, content);
if (this.options.inputSourcemaps !== false) {
var originalMap = sourceMapResolve.resolveSync(
content, file, fs.readFileSync);
if (originalMap) {
var map = new SourceMapConsumer(originalMap.map);
var relativeTo = originalMap.sourcesRelativeTo;
this.map.applySourceMap(map, file, makeFriendlyPath(path.dirname(relativeTo)));
}
}
}, this);
};
/**
* Process comments, drops sourceMap comments.
* @param {Object} node
*/
exports.comment = function(node) {
if (/^# sourceMappingURL=/.test(node.comment))
return this.emit('', node.position);
else
return this._comment(node);
};
},{"fs":2,"path":5,"source-map":36,"source-map-resolve":25}],23:[function(require,module,exports){
'use strict';
var token = '%[a-f0-9]{2}';
var singleMatcher = new RegExp(token, 'gi');
var multiMatcher = new RegExp('(' + token + ')+', 'gi');
function decodeComponents(components, split) {
try {
// Try to decode the entire string first
return decodeURIComponent(components.join(''));
} catch (err) {
// Do nothing
}
if (components.length === 1) {
return components;
}
split = split || 1;
// Split the array in 2 parts
var left = components.slice(0, split);
var right = components.slice(split);
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
}
function decode(input) {
try {
return decodeURIComponent(input);
} catch (err) {
var tokens = input.match(singleMatcher);
for (var i = 1; i < tokens.length; i++) {
input = decodeComponents(tokens, i).join('');
tokens = input.match(singleMatcher);
}
return input;
}
}
function customDecodeURIComponent(input) {
// Keep track of all the replacements and prefill the map with the `BOM`
var replaceMap = {
'%FE%FF': '\uFFFD\uFFFD',
'%FF%FE': '\uFFFD\uFFFD'
};
var match = multiMatcher.exec(input);
while (match) {
try {
// Decode as big chunks as possible
replaceMap[match[0]] = decodeURIComponent(match[0]);
} catch (err) {
var result = decode(match[0]);
if (result !== match[0]) {
replaceMap[match[0]] = result;
}
}
match = multiMatcher.exec(input);
}
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
replaceMap['%C2'] = '\uFFFD';
var entries = Object.keys(replaceMap);
for (var i = 0; i < entries.length; i++) {
// Replace all decoded components
var key = entries[i];
input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
}
return input;
}
module.exports = function (encodedURI) {
if (typeof encodedURI !== 'string') {
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`');
}
try {
encodedURI = encodedURI.replace(/\+/g, ' ');
// Try the built in decoder first
return decodeURIComponent(encodedURI);
} catch (err) {
// Fallback to a more advanced decoder
return customDecodeURIComponent(encodedURI);
}
};
},{}],24:[function(require,module,exports){
if (typeof Object.create === 'function') {
// implementation from standard node.js 'util' module
module.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
})
}
};
} else {
// old school shim for old browsers
module.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor
var TempCtor = function () {}
TempCtor.prototype = superCtor.prototype
ctor.prototype = new TempCtor()
ctor.prototype.constructor = ctor
}
}
}
},{}],25:[function(require,module,exports){
(function (setImmediate){
var atob = require("atob")
var urlLib = require("url")
var pathLib = require("path")
var decodeUriComponentLib = require("decode-uri-component")
function resolveUrl(/* ...urls */) {
return Array.prototype.reduce.call(arguments, function(resolved, nextUrl) {
return urlLib.resolve(resolved, nextUrl)
})
}
function convertWindowsPath(aPath) {
return pathLib.sep === "\\" ? aPath.replace(/\\/g, "/").replace(/^[a-z]:\/?/i, "/") : aPath
}
function customDecodeUriComponent(string) {
// `decodeUriComponentLib` turns `+` into ` `, but that's not wanted.
return decodeUriComponentLib(string.replace(/\+/g, "%2B"))
}
function callbackAsync(callback, error, result) {
setImmediate(function() { callback(error, result) })
}
function parseMapToJSON(string, data) {
try {
return JSON.parse(string.replace(/^\)\]\}'/, ""))
} catch (error) {
error.sourceMapData = data
throw error
}
}
function readSync(read, url, data) {
var readUrl = customDecodeUriComponent(url)
try {
return String(read(readUrl))
} catch (error) {
error.sourceMapData = data
throw error
}
}
var innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/
var sourceMappingURLRegex = RegExp(
"(?:" +
"/\\*" +
"(?:\\s*\r?\n(?://)?)?" +
"(?:" + innerRegex.source + ")" +
"\\s*" +
"\\*/" +
"|" +
"//(?:" + innerRegex.source + ")" +
")" +
"\\s*"
)
function getSourceMappingUrl(code) {
var match = code.match(sourceMappingURLRegex)
return match ? match[1] || match[2] || "" : null
}
function resolveSourceMap(code, codeUrl, read, callback) {
var mapData
try {
mapData = resolveSourceMapHelper(code, codeUrl)
} catch (error) {
return callbackAsync(callback, error)
}
if (!mapData || mapData.map) {
return callbackAsync(callback, null, mapData)
}
var readUrl = customDecodeUriComponent(mapData.url)
read(readUrl, function(error, result) {
if (error) {
error.sourceMapData = mapData
return callback(error)
}
mapData.map = String(result)
try {
mapData.map = parseMapToJSON(mapData.map, mapData)
} catch (error) {
return callback(error)
}
callback(null, mapData)
})
}
function resolveSourceMapSync(code, codeUrl, read) {
var mapData = resolveSourceMapHelper(code, codeUrl)
if (!mapData || mapData.map) {
return mapData
}
mapData.map = readSync(read, mapData.url, mapData)
mapData.map = parseMapToJSON(mapData.map, mapData)
return mapData
}
var dataUriRegex = /^data:([^,;]*)(;[^,;]*)*(?:,(.*))?$/
/**
* The media type for JSON text is application/json.
*
* {@link https://tools.ietf.org/html/rfc8259#section-11 | IANA Considerations }
*
* `text/json` is non-standard media type
*/
var jsonMimeTypeRegex = /^(?:application|text)\/json$/
/**
* JSON text exchanged between systems that are not part of a closed ecosystem
* MUST be encoded using UTF-8.
*
* {@link https://tools.ietf.org/html/rfc8259#section-8.1 | Character Encoding}
*/
var jsonCharacterEncoding = "utf-8"
function base64ToBuf(b64) {
var binStr = atob(b64)
var len = binStr.length
var arr = new Uint8Array(len)
for (var i = 0; i < len; i++) {
arr[i] = binStr.charCodeAt(i)
}
return arr
}
function decodeBase64String(b64) {
if (typeof TextDecoder === "undefined" || typeof Uint8Array === "undefined") {
return atob(b64)
}
var buf = base64ToBuf(b64);
// Note: `decoder.decode` method will throw a `DOMException` with the
// `"EncodingError"` value when an coding error is found.
var decoder = new TextDecoder(jsonCharacterEncoding, {fatal: true})
return decoder.decode(buf);
}
function resolveSourceMapHelper(code, codeUrl) {
codeUrl = convertWindowsPath(codeUrl)
var url = getSourceMappingUrl(code)
if (!url) {
return null
}
var dataUri = url.match(dataUriRegex)
if (dataUri) {
var mimeType = dataUri[1] || "text/plain"
var lastParameter = dataUri[2] || ""
var encoded = dataUri[3] || ""
var data = {
sourceMappingURL: url,
url: null,
sourcesRelativeTo: codeUrl,
map: encoded
}
if (!jsonMimeTypeRegex.test(mimeType)) {
var error = new Error("Unuseful data uri mime type: " + mimeType)
error.sourceMapData = data
throw error
}
try {
data.map = parseMapToJSON(
lastParameter === ";base64" ? decodeBase64String(encoded) : decodeURIComponent(encoded),
data
)
} catch (error) {
error.sourceMapData = data
throw error
}
return data
}
var mapUrl = resolveUrl(codeUrl, url)
return {
sourceMappingURL: url,
url: mapUrl,
sourcesRelativeTo: mapUrl,
map: null
}
}
function resolveSources(map, mapUrl, read, options, callback) {
if (typeof options === "function") {
callback = options
options = {}
}
var pending = map.sources ? map.sources.length : 0
var result = {
sourcesResolved: [],
sourcesContent: []
}
if (pending === 0) {
callbackAsync(callback, null, result)
return
}
var done = function() {
pending--
if (pending === 0) {
callback(null, result)
}
}
resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) {
result.sourcesResolved[index] = fullUrl
if (typeof sourceContent === "string") {
result.sourcesContent[index] = sourceContent
callbackAsync(done, null)
} else {
var readUrl = customDecodeUriComponent(fullUrl)
read(readUrl, function(error, source) {
result.sourcesContent[index] = error ? error : String(source)
done()
})
}
})
}
function resolveSourcesSync(map, mapUrl, read, options) {
var result = {
sourcesResolved: [],
sourcesContent: []
}
if (!map.sources || map.sources.length === 0) {
return result
}
resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) {
result.sourcesResolved[index] = fullUrl
if (read !== null) {
if (typeof sourceContent === "string") {
result.sourcesContent[index] = sourceContent
} else {
var readUrl = customDecodeUriComponent(fullUrl)
try {
result.sourcesContent[index] = String(read(readUrl))
} catch (error) {
result.sourcesContent[index] = error
}
}
}
})
return result
}
var endingSlash = /\/?$/
function resolveSourcesHelper(map, mapUrl, options, fn) {
options = options || {}
mapUrl = convertWindowsPath(mapUrl)
var fullUrl
var sourceContent
var sourceRoot
for (var index = 0, len = map.sources.length; index < len; index++) {
sourceRoot = null
if (typeof options.sourceRoot === "string") {
sourceRoot = options.sourceRoot
} else if (typeof map.sourceRoot === "string" && options.sourceRoot !== false) {
sourceRoot = map.sourceRoot
}
// If the sourceRoot is the empty string, it is equivalent to not setting
// the property at all.
if (sourceRoot === null || sourceRoot === '') {
fullUrl = resolveUrl(mapUrl, map.sources[index])
} else {
// Make sure that the sourceRoot ends with a slash, so that `/scripts/subdir` becomes
// `/scripts/subdir/<source>`, not `/scripts/<source>`. Pointing to a file as source root
// does not make sense.
fullUrl = resolveUrl(mapUrl, sourceRoot.replace(endingSlash, "/"), map.sources[index])
}
sourceContent = (map.sourcesContent || [])[index]
fn(fullUrl, sourceContent, index)
}
}
function resolve(code, codeUrl, read, options, callback) {
if (typeof options === "function") {
callback = options
options = {}
}
if (code === null) {
var mapUrl = codeUrl
var data = {
sourceMappingURL: null,
url: mapUrl,
sourcesRelativeTo: mapUrl,
map: null
}
var readUrl = customDecodeUriComponent(mapUrl)
read(readUrl, function(error, result) {
if (error) {
error.sourceMapData = data
return callback(error)
}
data.map = String(result)
try {
data.map = parseMapToJSON(data.map, data)
} catch (error) {
return callback(error)
}
_resolveSources(data)
})
} else {
resolveSourceMap(code, codeUrl, read, function(error, mapData) {
if (error) {
return callback(error)
}
if (!mapData) {
return callback(null, null)
}
_resolveSources(mapData)
})
}
function _resolveSources(mapData) {
resolveSources(mapData.map, mapData.sourcesRelativeTo, read, options, function(error, result) {
if (error) {
return callback(error)
}
mapData.sourcesResolved = result.sourcesResolved
mapData.sourcesContent = result.sourcesContent
callback(null, mapData)
})
}
}
function resolveSync(code, codeUrl, read, options) {
var mapData
if (code === null) {
var mapUrl = codeUrl
mapData = {
sourceMappingURL: null,
url: mapUrl,
sourcesRelativeTo: mapUrl,
map: null
}
mapData.map = readSync(read, mapUrl, mapData)
mapData.map = parseMapToJSON(mapData.map, mapData)
} else {
mapData = resolveSourceMapSync(code, codeUrl, read)
if (!mapData) {
return null
}
}
var result = resolveSourcesSync(mapData.map, mapData.sourcesRelativeTo, read, options)
mapData.sourcesResolved = result.sourcesResolved
mapData.sourcesContent = result.sourcesContent
return mapData
}
module.exports = {
resolveSourceMap: resolveSourceMap,
resolveSourceMapSync: resolveSourceMapSync,
resolveSources: resolveSources,
resolveSourcesSync: resolveSourcesSync,
resolve: resolve,
resolveSync: resolveSync,
parseMapToJSON: parseMapToJSON
}
}).call(this,require("timers").setImmediate)
},{"atob":15,"decode-uri-component":23,"path":5,"timers":11,"url":12}],26:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
var util = require('./util');
var has = Object.prototype.hasOwnProperty;
var hasNativeMap = typeof Map !== "undefined";
/**
* A data structure which is a combination of an array and a set. Adding a new
* member is O(1), testing for membership is O(1), and finding the index of an
* element is O(1). Removing elements from the set is not supported. Only
* strings are supported for membership.
*/
function ArraySet() {
this._array = [];
this._set = hasNativeMap ? new Map() : Object.create(null);
}
/**
* Static method for creating ArraySet instances from an existing array.
*/
ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
var set = new ArraySet();
for (var i = 0, len = aArray.length; i < len; i++) {
set.add(aArray[i], aAllowDuplicates);
}
return set;
};
/**
* Return how many unique items are in this ArraySet. If duplicates have been
* added, than those do not count towards the size.
*
* @returns Number
*/
ArraySet.prototype.size = function ArraySet_size() {
return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
};
/**
* Add the given string to this set.
*
* @param String aStr
*/
ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
var idx = this._array.length;
if (!isDuplicate || aAllowDuplicates) {
this._array.push(aStr);
}
if (!isDuplicate) {
if (hasNativeMap) {
this._set.set(aStr, idx);
} else {
this._set[sStr] = idx;
}
}
};
/**
* Is the given string a member of this set?
*
* @param String aStr
*/
ArraySet.prototype.has = function ArraySet_has(aStr) {
if (hasNativeMap) {
return this._set.has(aStr);
} else {
var sStr = util.toSetString(aStr);
return has.call(this._set, sStr);
}
};
/**
* What is the index of the given string in the array?
*
* @param String aStr
*/
ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
if (hasNativeMap) {
var idx = this._set.get(aStr);
if (idx >= 0) {
return idx;
}
} else {
var sStr = util.toSetString(aStr);
if (has.call(this._set, sStr)) {
return this._set[sStr];
}
}
throw new Error('"' + aStr + '" is not in the set.');
};
/**
* What is the element at the given index?
*
* @param Number aIdx
*/
ArraySet.prototype.at = function ArraySet_at(aIdx) {
if (aIdx >= 0 && aIdx < this._array.length) {
return this._array[aIdx];
}
throw new Error('No element indexed by ' + aIdx);
};
/**
* Returns the array representation of this set (which has the proper indices
* indicated by indexOf). Note that this is a copy of the internal array used
* for storing the members so that no one can mess with internal state.
*/
ArraySet.prototype.toArray = function ArraySet_toArray() {
return this._array.slice();
};
exports.ArraySet = ArraySet;
},{"./util":35}],27:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*
* Based on the Base 64 VLQ implementation in Closure Compiler:
* https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
*
* Copyright 2011 The Closure Compiler Authors. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
var base64 = require('./base64');
// A single base 64 digit can contain 6 bits of data. For the base 64 variable
// length quantities we use in the source map spec, the first bit is the sign,
// the next four bits are the actual value, and the 6th bit is the
// continuation bit. The continuation bit tells us whether there are more
// digits in this value following this digit.
//
// Continuation
// | Sign
// | |
// V V
// 101011
var VLQ_BASE_SHIFT = 5;
// binary: 100000
var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
// binary: 011111
var VLQ_BASE_MASK = VLQ_BASE - 1;
// binary: 100000
var VLQ_CONTINUATION_BIT = VLQ_BASE;
/**
* Converts from a two-complement value to a value where the sign bit is
* placed in the least significant bit. For example, as decimals:
* 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
* 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
*/
function toVLQSigned(aValue) {
return aValue < 0
? ((-aValue) << 1) + 1
: (aValue << 1) + 0;
}
/**
* Converts to a two-complement value from a value where the sign bit is
* placed in the least significant bit. For example, as decimals:
* 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
* 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
*/
function fromVLQSigned(aValue) {
var isNegative = (aValue & 1) === 1;
var shifted = aValue >> 1;
return isNegative
? -shifted
: shifted;
}
/**
* Returns the base 64 VLQ encoded value.
*/
exports.encode = function base64VLQ_encode(aValue) {
var encoded = "";
var digit;
var vlq = toVLQSigned(aValue);
do {
digit = vlq & VLQ_BASE_MASK;
vlq >>>= VLQ_BASE_SHIFT;
if (vlq > 0) {
// There are still more digits in this value, so we must make sure the
// continuation bit is marked.
digit |= VLQ_CONTINUATION_BIT;
}
encoded += base64.encode(digit);
} while (vlq > 0);
return encoded;
};
/**
* Decodes the next base 64 VLQ value from the given string and returns the
* value and the rest of the string via the out parameter.
*/
exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
var strLen = aStr.length;
var result = 0;
var shift = 0;
var continuation, digit;
do {
if (aIndex >= strLen) {
throw new Error("Expected more digits in base 64 VLQ value.");
}
digit = base64.decode(aStr.charCodeAt(aIndex++));
if (digit === -1) {
throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
}
continuation = !!(digit & VLQ_CONTINUATION_BIT);
digit &= VLQ_BASE_MASK;
result = result + (digit << shift);
shift += VLQ_BASE_SHIFT;
} while (continuation);
aOutParam.value = fromVLQSigned(result);
aOutParam.rest = aIndex;
};
},{"./base64":28}],28:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
/**
* Encode an integer in the range of 0 to 63 to a single base 64 digit.
*/
exports.encode = function (number) {
if (0 <= number && number < intToCharMap.length) {
return intToCharMap[number];
}
throw new TypeError("Must be between 0 and 63: " + number);
};
/**
* Decode a single base 64 character code digit to an integer. Returns -1 on
* failure.
*/
exports.decode = function (charCode) {
var bigA = 65; // 'A'
var bigZ = 90; // 'Z'
var littleA = 97; // 'a'
var littleZ = 122; // 'z'
var zero = 48; // '0'
var nine = 57; // '9'
var plus = 43; // '+'
var slash = 47; // '/'
var littleOffset = 26;
var numberOffset = 52;
// 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
if (bigA <= charCode && charCode <= bigZ) {
return (charCode - bigA);
}
// 26 - 51: abcdefghijklmnopqrstuvwxyz
if (littleA <= charCode && charCode <= littleZ) {
return (charCode - littleA + littleOffset);
}
// 52 - 61: 0123456789
if (zero <= charCode && charCode <= nine) {
return (charCode - zero + numberOffset);
}
// 62: +
if (charCode == plus) {
return 62;
}
// 63: /
if (charCode == slash) {
return 63;
}
// Invalid base64 digit.
return -1;
};
},{}],29:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
exports.GREATEST_LOWER_BOUND = 1;
exports.LEAST_UPPER_BOUND = 2;
/**
* Recursive implementation of binary search.
*
* @param aLow Indices here and lower do not contain the needle.
* @param aHigh Indices here and higher do not contain the needle.
* @param aNeedle The element being searched for.
* @param aHaystack The non-empty array being searched.
* @param aCompare Function which takes two elements and returns -1, 0, or 1.
* @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
* 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
* closest element that is smaller than or greater than the one we are
* searching for, respectively, if the exact element cannot be found.
*/
function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
// This function terminates when one of the following is true:
//
// 1. We find the exact element we are looking for.
//
// 2. We did not find the exact element, but we can return the index of
// the next-closest element.
//
// 3. We did not find the exact element, and there is no next-closest
// element than the one we are searching for, so we return -1.
var mid = Math.floor((aHigh - aLow) / 2) + aLow;
var cmp = aCompare(aNeedle, aHaystack[mid], true);
if (cmp === 0) {
// Found the element we are looking for.
return mid;
}
else if (cmp > 0) {
// Our needle is greater than aHaystack[mid].
if (aHigh - mid > 1) {
// The element is in the upper half.
return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
}
// The exact needle element was not found in this haystack. Determine if
// we are in termination case (3) or (2) and return the appropriate thing.
if (aBias == exports.LEAST_UPPER_BOUND) {
return aHigh < aHaystack.length ? aHigh : -1;
} else {
return mid;
}
}
else {
// Our needle is less than aHaystack[mid].
if (mid - aLow > 1) {
// The element is in the lower half.
return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
}
// we are in termination case (3) or (2) and return the appropriate thing.
if (aBias == exports.LEAST_UPPER_BOUND) {
return mid;
} else {
return aLow < 0 ? -1 : aLow;
}
}
}
/**
* This is an implementation of binary search which will always try and return
* the index of the closest element if there is no exact hit. This is because
* mappings between original and generated line/col pairs are single points,
* and there is an implicit region between each of them, so a miss just means
* that you aren't on the very start of a region.
*
* @param aNeedle The element you are looking for.
* @param aHaystack The array that is being searched.
* @param aCompare A function which takes the needle and an element in the
* array and returns -1, 0, or 1 depending on whether the needle is less
* than, equal to, or greater than the element, respectively.
* @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
* 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
* closest element that is smaller than or greater than the one we are
* searching for, respectively, if the exact element cannot be found.
* Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
*/
exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
if (aHaystack.length === 0) {
return -1;
}
var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
aCompare, aBias || exports.GREATEST_LOWER_BOUND);
if (index < 0) {
return -1;
}
// We have found either the exact element, or the next-closest element than
// the one we are searching for. However, there may be more than one such
// element. Make sure we always return the smallest of these.
while (index - 1 >= 0) {
if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
break;
}
--index;
}
return index;
};
},{}],30:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2014 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
var util = require('./util');
/**
* Determine whether mappingB is after mappingA with respect to generated
* position.
*/
function generatedPositionAfter(mappingA, mappingB) {
// Optimized for most common case
var lineA = mappingA.generatedLine;
var lineB = mappingB.generatedLine;
var columnA = mappingA.generatedColumn;
var columnB = mappingB.generatedColumn;
return lineB > lineA || lineB == lineA && columnB >= columnA ||
util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
}
/**
* A data structure to provide a sorted view of accumulated mappings in a
* performance conscious manner. It trades a neglibable overhead in general
* case for a large speedup in case of mappings being added in order.
*/
function MappingList() {
this._array = [];
this._sorted = true;
// Serves as infimum
this._last = {generatedLine: -1, generatedColumn: 0};
}
/**
* Iterate through internal items. This method takes the same arguments that
* `Array.prototype.forEach` takes.
*
* NOTE: The order of the mappings is NOT guaranteed.
*/
MappingList.prototype.unsortedForEach =
function MappingList_forEach(aCallback, aThisArg) {
this._array.forEach(aCallback, aThisArg);
};
/**
* Add the given source mapping.
*
* @param Object aMapping
*/
MappingList.prototype.add = function MappingList_add(aMapping) {
if (generatedPositionAfter(this._last, aMapping)) {
this._last = aMapping;
this._array.push(aMapping);
} else {
this._sorted = false;
this._array.push(aMapping);
}
};
/**
* Returns the flat, sorted array of mappings. The mappings are sorted by
* generated position.
*
* WARNING: This method returns internal data without copying, for
* performance. The return value must NOT be mutated, and should be treated as
* an immutable borrow. If you want to take ownership, you must make your own
* copy.
*/
MappingList.prototype.toArray = function MappingList_toArray() {
if (!this._sorted) {
this._array.sort(util.compareByGeneratedPositionsInflated);
this._sorted = true;
}
return this._array;
};
exports.MappingList = MappingList;
},{"./util":35}],31:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
// It turns out that some (most?) JavaScript engines don't self-host
// `Array.prototype.sort`. This makes sense because C++ will likely remain
// faster than JS when doing raw CPU-intensive sorting. However, when using a
// custom comparator function, calling back and forth between the VM's C++ and
// JIT'd JS is rather slow *and* loses JIT type information, resulting in
// worse generated code for the comparator function than would be optimal. In
// fact, when sorting with a comparator, these costs outweigh the benefits of
// sorting in C++. By using our own JS-implemented Quick Sort (below), we get
// a ~3500ms mean speed-up in `bench/bench.html`.
/**
* Swap the elements indexed by `x` and `y` in the array `ary`.
*
* @param {Array} ary
* The array.
* @param {Number} x
* The index of the first item.
* @param {Number} y
* The index of the second item.
*/
function swap(ary, x, y) {
var temp = ary[x];
ary[x] = ary[y];
ary[y] = temp;
}
/**
* Returns a random integer within the range `low .. high` inclusive.
*
* @param {Number} low
* The lower bound on the range.
* @param {Number} high
* The upper bound on the range.
*/
function randomIntInRange(low, high) {
return Math.round(low + (Math.random() * (high - low)));
}
/**
* The Quick Sort algorithm.
*
* @param {Array} ary
* An array to sort.
* @param {function} comparator
* Function to use to compare two items.
* @param {Number} p
* Start index of the array
* @param {Number} r
* End index of the array
*/
function doQuickSort(ary, comparator, p, r) {
// If our lower bound is less than our upper bound, we (1) partition the
// array into two pieces and (2) recurse on each half. If it is not, this is
// the empty array and our base case.
if (p < r) {
// (1) Partitioning.
//
// The partitioning chooses a pivot between `p` and `r` and moves all
// elements that are less than or equal to the pivot to the before it, and
// all the elements that are greater than it after it. The effect is that
// once partition is done, the pivot is in the exact place it will be when
// the array is put in sorted order, and it will not need to be moved
// again. This runs in O(n) time.
// Always choose a random pivot so that an input array which is reverse
// sorted does not cause O(n^2) running time.
var pivotIndex = randomIntInRange(p, r);
var i = p - 1;
swap(ary, pivotIndex, r);
var pivot = ary[r];
// Immediately after `j` is incremented in this loop, the following hold
// true:
//
// * Every element in `ary[p .. i]` is less than or equal to the pivot.
//
// * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
for (var j = p; j < r; j++) {
if (comparator(ary[j], pivot) <= 0) {
i += 1;
swap(ary, i, j);
}
}
swap(ary, i + 1, j);
var q = i + 1;
// (2) Recurse on each half.
doQuickSort(ary, comparator, p, q - 1);
doQuickSort(ary, comparator, q + 1, r);
}
}
/**
* Sort the given array in-place with the given comparator function.
*
* @param {Array} ary
* An array to sort.
* @param {function} comparator
* Function to use to compare two items.
*/
exports.quickSort = function (ary, comparator) {
doQuickSort(ary, comparator, 0, ary.length - 1);
};
},{}],32:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
var util = require('./util');
var binarySearch = require('./binary-search');
var ArraySet = require('./array-set').ArraySet;
var base64VLQ = require('./base64-vlq');
var quickSort = require('./quick-sort').quickSort;
function SourceMapConsumer(aSourceMap, aSourceMapURL) {
var sourceMap = aSourceMap;
if (typeof aSourceMap === 'string') {
sourceMap = util.parseSourceMapInput(aSourceMap);
}
return sourceMap.sections != null
? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
: new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
}
SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
}
/**
* The version of the source mapping spec that we are consuming.
*/
SourceMapConsumer.prototype._version = 3;
// `__generatedMappings` and `__originalMappings` are arrays that hold the
// parsed mapping coordinates from the source map's "mappings" attribute. They
// are lazily instantiated, accessed via the `_generatedMappings` and
// `_originalMappings` getters respectively, and we only parse the mappings
// and create these arrays once queried for a source location. We jump through
// these hoops because there can be many thousands of mappings, and parsing
// them is expensive, so we only want to do it if we must.
//
// Each object in the arrays is of the form:
//
// {
// generatedLine: The line number in the generated code,
// generatedColumn: The column number in the generated code,
// source: The path to the original source file that generated this
// chunk of code,
// originalLine: The line number in the original source that
// corresponds to this chunk of generated code,
// originalColumn: The column number in the original source that
// corresponds to this chunk of generated code,
// name: The name of the original symbol which generated this chunk of
// code.
// }
//
// All properties except for `generatedLine` and `generatedColumn` can be
// `null`.
//
// `_generatedMappings` is ordered by the generated positions.
//
// `_originalMappings` is ordered by the original positions.
SourceMapConsumer.prototype.__generatedMappings = null;
Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
configurable: true,
enumerable: true,
get: function () {
if (!this.__generatedMappings) {
this._parseMappings(this._mappings, this.sourceRoot);
}
return this.__generatedMappings;
}
});
SourceMapConsumer.prototype.__originalMappings = null;
Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
configurable: true,
enumerable: true,
get: function () {
if (!this.__originalMappings) {
this._parseMappings(this._mappings, this.sourceRoot);
}
return this.__originalMappings;
}
});
SourceMapConsumer.prototype._charIsMappingSeparator =
function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
var c = aStr.charAt(index);
return c === ";" || c === ",";
};
/**
* Parse the mappings in a string in to a data structure which we can easily
* query (the ordered arrays in the `this.__generatedMappings` and
* `this.__originalMappings` properties).
*/
SourceMapConsumer.prototype._parseMappings =
function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
throw new Error("Subclasses must implement _parseMappings");
};
SourceMapConsumer.GENERATED_ORDER = 1;
SourceMapConsumer.ORIGINAL_ORDER = 2;
SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
SourceMapConsumer.LEAST_UPPER_BOUND = 2;
/**
* Iterate over each mapping between an original source/line/column and a
* generated line/column in this source map.
*
* @param Function aCallback
* The function that is called with each mapping.
* @param Object aContext
* Optional. If specified, this object will be the value of `this` every
* time that `aCallback` is called.
* @param aOrder
* Either `SourceMapConsumer.GENERATED_ORDER` or
* `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
* iterate over the mappings sorted by the generated file's line/column
* order or the original's source/line/column order, respectively. Defaults to
* `SourceMapConsumer.GENERATED_ORDER`.
*/
SourceMapConsumer.prototype.eachMapping =
function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
var context = aContext || null;
var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
var mappings;
switch (order) {
case SourceMapConsumer.GENERATED_ORDER:
mappings = this._generatedMappings;
break;
case SourceMapConsumer.ORIGINAL_ORDER:
mappings = this._originalMappings;
break;
default:
throw new Error("Unknown order of iteration.");
}
var sourceRoot = this.sourceRoot;
mappings.map(function (mapping) {
var source = mapping.source === null ? null : this._sources.at(mapping.source);
source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
return {
source: source,
generatedLine: mapping.generatedLine,
generatedColumn: mapping.generatedColumn,
originalLine: mapping.originalLine,
originalColumn: mapping.originalColumn,
name: mapping.name === null ? null : this._names.at(mapping.name)
};
}, this).forEach(aCallback, context);
};
/**
* Returns all generated line and column information for the original source,
* line, and column provided. If no column is provided, returns all mappings
* corresponding to a either the line we are searching for or the next
* closest line that has any mappings. Otherwise, returns all mappings
* corresponding to the given line and either the column we are searching for
* or the next closest column that has any offsets.
*
* The only argument is an object with the following properties:
*
* - source: The filename of the original source.
* - line: The line number in the original source. The line number is 1-based.
* - column: Optional. the column number in the original source.
* The column number is 0-based.
*
* and an array of objects is returned, each with the following properties:
*
* - line: The line number in the generated source, or null. The
* line number is 1-based.
* - column: The column number in the generated source, or null.
* The column number is 0-based.
*/
SourceMapConsumer.prototype.allGeneratedPositionsFor =
function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
var line = util.getArg(aArgs, 'line');
// When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
// returns the index of the closest mapping less than the needle. By
// setting needle.originalColumn to 0, we thus find the last mapping for
// the given line, provided such a mapping exists.
var needle = {
source: util.getArg(aArgs, 'source'),
originalLine: line,
originalColumn: util.getArg(aArgs, 'column', 0)
};
needle.source = this._findSourceIndex(needle.source);
if (needle.source < 0) {
return [];
}
var mappings = [];
var index = this._findMapping(needle,
this._originalMappings,
"originalLine",
"originalColumn",
util.compareByOriginalPositions,
binarySearch.LEAST_UPPER_BOUND);
if (index >= 0) {
var mapping = this._originalMappings[index];
if (aArgs.column === undefined) {
var originalLine = mapping.originalLine;
// Iterate until either we run out of mappings, or we run into
// a mapping for a different line than the one we found. Since
// mappings are sorted, this is guaranteed to find all mappings for
// the line we found.
while (mapping && mapping.originalLine === originalLine) {
mappings.push({
line: util.getArg(mapping, 'generatedLine', null),
column: util.getArg(mapping, 'generatedColumn', null),
lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
});
mapping = this._originalMappings[++index];
}
} else {
var originalColumn = mapping.originalColumn;
// Iterate until either we run out of mappings, or we run into
// a mapping for a different line than the one we were searching for.
// Since mappings are sorted, this is guaranteed to find all mappings for
// the line we are searching for.
while (mapping &&
mapping.originalLine === line &&
mapping.originalColumn == originalColumn) {
mappings.push({
line: util.getArg(mapping, 'generatedLine', null),
column: util.getArg(mapping, 'generatedColumn', null),
lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
});
mapping = this._originalMappings[++index];
}
}
}
return mappings;
};
exports.SourceMapConsumer = SourceMapConsumer;
/**
* A BasicSourceMapConsumer instance represents a parsed source map which we can
* query for information about the original file positions by giving it a file
* position in the generated source.
*
* The first parameter is the raw source map (either as a JSON string, or
* already parsed to an object). According to the spec, source maps have the
* following attributes:
*
* - version: Which version of the source map spec this map is following.
* - sources: An array of URLs to the original source files.
* - names: An array of identifiers which can be referrenced by individual mappings.
* - sourceRoot: Optional. The URL root from which all sources are relative.
* - sourcesContent: Optional. An array of contents of the original source files.
* - mappings: A string of base64 VLQs which contain the actual mappings.
* - file: Optional. The generated file this source map is associated with.
*
* Here is an example source map, taken from the source map spec[0]:
*
* {
* version : 3,
* file: "out.js",
* sourceRoot : "",
* sources: ["foo.js", "bar.js"],
* names: ["src", "maps", "are", "fun"],
* mappings: "AA,AB;;ABCDE;"
* }
*
* The second parameter, if given, is a string whose value is the URL
* at which the source map was found. This URL is used to compute the
* sources array.
*
* [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
*/
function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
var sourceMap = aSourceMap;
if (typeof aSourceMap === 'string') {
sourceMap = util.parseSourceMapInput(aSourceMap);
}
var version = util.getArg(sourceMap, 'version');
var sources = util.getArg(sourceMap, 'sources');
// Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
// requires the array) to play nice here.
var names = util.getArg(sourceMap, 'names', []);
var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
var mappings = util.getArg(sourceMap, 'mappings');
var file = util.getArg(sourceMap, 'file', null);
// Once again, Sass deviates from the spec and supplies the version as a
// string rather than a number, so we use loose equality checking here.
if (version != this._version) {
throw new Error('Unsupported version: ' + version);
}
if (sourceRoot) {
sourceRoot = util.normalize(sourceRoot);
}
sources = sources
.map(String)
// Some source maps produce relative source paths like "./foo.js" instead of
// "foo.js". Normalize these first so that future comparisons will succeed.
// See bugzil.la/1090768.
.map(util.normalize)
// Always ensure that absolute sources are internally stored relative to
// the source root, if the source root is absolute. Not doing this would
// be particularly problematic when the source root is a prefix of the
// source (valid, but why??). See github issue #199 and bugzil.la/1188982.
.map(function (source) {
return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
? util.relative(sourceRoot, source)
: source;
});
// Pass `true` below to allow duplicate names and sources. While source maps
// are intended to be compressed and deduplicated, the TypeScript compiler
// sometimes generates source maps with duplicates in them. See Github issue
// #72 and bugzil.la/889492.
this._names = ArraySet.fromArray(names.map(String), true);
this._sources = ArraySet.fromArray(sources, true);
this._absoluteSources = this._sources.toArray().map(function (s) {
return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
});
this.sourceRoot = sourceRoot;
this.sourcesContent = sourcesContent;
this._mappings = mappings;
this._sourceMapURL = aSourceMapURL;
this.file = file;
}
BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
/**
* Utility function to find the index of a source. Returns -1 if not
* found.
*/
BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
var relativeSource = aSource;
if (this.sourceRoot != null) {
relativeSource = util.relative(this.sourceRoot, relativeSource);
}
if (this._sources.has(relativeSource)) {
return this._sources.indexOf(relativeSource);
}
// Maybe aSource is an absolute URL as returned by |sources|. In
// this case we can't simply undo the transform.
var i;
for (i = 0; i < this._absoluteSources.length; ++i) {
if (this._absoluteSources[i] == aSource) {
return i;
}
}
return -1;
};
/**
* Create a BasicSourceMapConsumer from a SourceMapGenerator.
*
* @param SourceMapGenerator aSourceMap
* The source map that will be consumed.
* @param String aSourceMapURL
* The URL at which the source map can be found (optional)
* @returns BasicSourceMapConsumer
*/
BasicSourceMapConsumer.fromSourceMap =
function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
var smc = Object.create(BasicSourceMapConsumer.prototype);
var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
smc.sourceRoot = aSourceMap._sourceRoot;
smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
smc.sourceRoot);
smc.file = aSourceMap._file;
smc._sourceMapURL = aSourceMapURL;
smc._absoluteSources = smc._sources.toArray().map(function (s) {
return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
});
// Because we are modifying the entries (by converting string sources and
// names to indices into the sources and names ArraySets), we have to make
// a copy of the entry or else bad things happen. Shared mutable state
// strikes again! See github issue #191.
var generatedMappings = aSourceMap._mappings.toArray().slice();
var destGeneratedMappings = smc.__generatedMappings = [];
var destOriginalMappings = smc.__originalMappings = [];
for (var i = 0, length = generatedMappings.length; i < length; i++) {
var srcMapping = generatedMappings[i];
var destMapping = new Mapping;
destMapping.generatedLine = srcMapping.generatedLine;
destMapping.generatedColumn = srcMapping.generatedColumn;
if (srcMapping.source) {
destMapping.source = sources.indexOf(srcMapping.source);
destMapping.originalLine = srcMapping.originalLine;
destMapping.originalColumn = srcMapping.originalColumn;
if (srcMapping.name) {
destMapping.name = names.indexOf(srcMapping.name);
}
destOriginalMappings.push(destMapping);
}
destGeneratedMappings.push(destMapping);
}
quickSort(smc.__originalMappings, util.compareByOriginalPositions);
return smc;
};
/**
* The version of the source mapping spec that we are consuming.
*/
BasicSourceMapConsumer.prototype._version = 3;
/**
* The list of original sources.
*/
Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
get: function () {
return this._absoluteSources.slice();
}
});
/**
* Provide the JIT with a nice shape / hidden class.
*/
function Mapping() {
this.generatedLine = 0;
this.generatedColumn = 0;
this.source = null;
this.originalLine = null;
this.originalColumn = null;
this.name = null;
}
/**
* Parse the mappings in a string in to a data structure which we can easily
* query (the ordered arrays in the `this.__generatedMappings` and
* `this.__originalMappings` properties).
*/
BasicSourceMapConsumer.prototype._parseMappings =
function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
var generatedLine = 1;
var previousGeneratedColumn = 0;
var previousOriginalLine = 0;
var previousOriginalColumn = 0;
var previousSource = 0;
var previousName = 0;
var length = aStr.length;
var index = 0;
var cachedSegments = {};
var temp = {};
var originalMappings = [];
var generatedMappings = [];
var mapping, str, segment, end, value;
while (index < length) {
if (aStr.charAt(index) === ';') {
generatedLine++;
index++;
previousGeneratedColumn = 0;
}
else if (aStr.charAt(index) === ',') {
index++;
}
else {
mapping = new Mapping();
mapping.generatedLine = generatedLine;
// Because each offset is encoded relative to the previous one,
// many segments often have the same encoding. We can exploit this
// fact by caching the parsed variable length fields of each segment,
// allowing us to avoid a second parse if we encounter the same
// segment again.
for (end = index; end < length; end++) {
if (this._charIsMappingSeparator(aStr, end)) {
break;
}
}
str = aStr.slice(index, end);
segment = cachedSegments[str];
if (segment) {
index += str.length;
} else {
segment = [];
while (index < end) {
base64VLQ.decode(aStr, index, temp);
value = temp.value;
index = temp.rest;
segment.push(value);
}
if (segment.length === 2) {
throw new Error('Found a source, but no line and column');
}
if (segment.length === 3) {
throw new Error('Found a source and line, but no column');
}
cachedSegments[str] = segment;
}
// Generated column.
mapping.generatedColumn = previousGeneratedColumn + segment[0];
previousGeneratedColumn = mapping.generatedColumn;
if (segment.length > 1) {
// Original source.
mapping.source = previousSource + segment[1];
previousSource += segment[1];
// Original line.
mapping.originalLine = previousOriginalLine + segment[2];
previousOriginalLine = mapping.originalLine;
// Lines are stored 0-based
mapping.originalLine += 1;
// Original column.
mapping.originalColumn = previousOriginalColumn + segment[3];
previousOriginalColumn = mapping.originalColumn;
if (segment.length > 4) {
// Original name.
mapping.name = previousName + segment[4];
previousName += segment[4];
}
}
generatedMappings.push(mapping);
if (typeof mapping.originalLine === 'number') {
originalMappings.push(mapping);
}
}
}
quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated);
this.__generatedMappings = generatedMappings;
quickSort(originalMappings, util.compareByOriginalPositions);
this.__originalMappings = originalMappings;
};
/**
* Find the mapping that best matches the hypothetical "needle" mapping that
* we are searching for in the given "haystack" of mappings.
*/
BasicSourceMapConsumer.prototype._findMapping =
function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
aColumnName, aComparator, aBias) {
// To return the position we are searching for, we must first find the
// mapping for the given position and then return the opposite position it
// points to. Because the mappings are sorted, we can use binary search to
// find the best mapping.
if (aNeedle[aLineName] <= 0) {
throw new TypeError('Line must be greater than or equal to 1, got '
+ aNeedle[aLineName]);
}
if (aNeedle[aColumnName] < 0) {
throw new TypeError('Column must be greater than or equal to 0, got '
+ aNeedle[aColumnName]);
}
return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
};
/**
* Compute the last column for each generated mapping. The last column is
* inclusive.
*/
BasicSourceMapConsumer.prototype.computeColumnSpans =
function SourceMapConsumer_computeColumnSpans() {
for (var index = 0; index < this._generatedMappings.length; ++index) {
var mapping = this._generatedMappings[index];
// Mappings do not contain a field for the last generated columnt. We
// can come up with an optimistic estimate, however, by assuming that
// mappings are contiguous (i.e. given two consecutive mappings, the
// first mapping ends where the second one starts).
if (index + 1 < this._generatedMappings.length) {
var nextMapping = this._generatedMappings[index + 1];
if (mapping.generatedLine === nextMapping.generatedLine) {
mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
continue;
}
}
// The last mapping for each line spans the entire line.
mapping.lastGeneratedColumn = Infinity;
}
};
/**
* Returns the original source, line, and column information for the generated
* source's line and column positions provided. The only argument is an object
* with the following properties:
*
* - line: The line number in the generated source. The line number
* is 1-based.
* - column: The column number in the generated source. The column
* number is 0-based.
* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
* closest element that is smaller than or greater than the one we are
* searching for, respectively, if the exact element cannot be found.
* Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
*
* and an object is returned with the following properties:
*
* - source: The original source file, or null.
* - line: The line number in the original source, or null. The
* line number is 1-based.
* - column: The column number in the original source, or null. The
* column number is 0-based.
* - name: The original identifier, or null.
*/
BasicSourceMapConsumer.prototype.originalPositionFor =
function SourceMapConsumer_originalPositionFor(aArgs) {
var needle = {
generatedLine: util.getArg(aArgs, 'line'),
generatedColumn: util.getArg(aArgs, 'column')
};
var index = this._findMapping(
needle,
this._generatedMappings,
"generatedLine",
"generatedColumn",
util.compareByGeneratedPositionsDeflated,
util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
);
if (index >= 0) {
var mapping = this._generatedMappings[index];
if (mapping.generatedLine === needle.generatedLine) {
var source = util.getArg(mapping, 'source', null);
if (source !== null) {
source = this._sources.at(source);
source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
}
var name = util.getArg(mapping, 'name', null);
if (name !== null) {
name = this._names.at(name);
}
return {
source: source,
line: util.getArg(mapping, 'originalLine', null),
column: util.getArg(mapping, 'originalColumn', null),
name: name
};
}
}
return {
source: null,
line: null,
column: null,
name: null
};
};
/**
* Return true if we have the source content for every source in the source
* map, false otherwise.
*/
BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
function BasicSourceMapConsumer_hasContentsOfAllSources() {
if (!this.sourcesContent) {
return false;
}
return this.sourcesContent.length >= this._sources.size() &&
!this.sourcesContent.some(function (sc) { return sc == null; });
};
/**
* Returns the original source content. The only argument is the url of the
* original source file. Returns null if no original source content is
* available.
*/
BasicSourceMapConsumer.prototype.sourceContentFor =
function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
if (!this.sourcesContent) {
return null;
}
var index = this._findSourceIndex(aSource);
if (index >= 0) {
return this.sourcesContent[index];
}
var relativeSource = aSource;
if (this.sourceRoot != null) {
relativeSource = util.relative(this.sourceRoot, relativeSource);
}
var url;
if (this.sourceRoot != null
&& (url = util.urlParse(this.sourceRoot))) {
// XXX: file:// URIs and absolute paths lead to unexpected behavior for
// many users. We can help them out when they expect file:// URIs to
// behave like it would if they were running a local HTTP server. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
if (url.scheme == "file"
&& this._sources.has(fileUriAbsPath)) {
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
}
if ((!url.path || url.path == "/")
&& this._sources.has("/" + relativeSource)) {
return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
}
}
// This function is used recursively from
// IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
// don't want to throw if we can't find the source - we just want to
// return null, so we provide a flag to exit gracefully.
if (nullOnMissing) {
return null;
}
else {
throw new Error('"' + relativeSource + '" is not in the SourceMap.');
}
};
/**
* Returns the generated line and column information for the original source,
* line, and column positions provided. The only argument is an object with
* the following properties:
*
* - source: The filename of the original source.
* - line: The line number in the original source. The line number
* is 1-based.
* - column: The column number in the original source. The column
* number is 0-based.
* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
* closest element that is smaller than or greater than the one we are
* searching for, respectively, if the exact element cannot be found.
* Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
*
* and an object is returned with the following properties:
*
* - line: The line number in the generated source, or null. The
* line number is 1-based.
* - column: The column number in the generated source, or null.
* The column number is 0-based.
*/
BasicSourceMapConsumer.prototype.generatedPositionFor =
function SourceMapConsumer_generatedPositionFor(aArgs) {
var source = util.getArg(aArgs, 'source');
source = this._findSourceIndex(source);
if (source < 0) {
return {
line: null,
column: null,
lastColumn: null
};
}
var needle = {
source: source,
originalLine: util.getArg(aArgs, 'line'),
originalColumn: util.getArg(aArgs, 'column')
};
var index = this._findMapping(
needle,
this._originalMappings,
"originalLine",
"originalColumn",
util.compareByOriginalPositions,
util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
);
if (index >= 0) {
var mapping = this._originalMappings[index];
if (mapping.source === needle.source) {
return {
line: util.getArg(mapping, 'generatedLine', null),
column: util.getArg(mapping, 'generatedColumn', null),
lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
};
}
}
return {
line: null,
column: null,
lastColumn: null
};
};
exports.BasicSourceMapConsumer = BasicSourceMapConsumer;
/**
* An IndexedSourceMapConsumer instance represents a parsed source map which
* we can query for information. It differs from BasicSourceMapConsumer in
* that it takes "indexed" source maps (i.e. ones with a "sections" field) as
* input.
*
* The first parameter is a raw source map (either as a JSON string, or already
* parsed to an object). According to the spec for indexed source maps, they
* have the following attributes:
*
* - version: Which version of the source map spec this map is following.
* - file: Optional. The generated file this source map is associated with.
* - sections: A list of section definitions.
*
* Each value under the "sections" field has two fields:
* - offset: The offset into the original specified at which this section
* begins to apply, defined as an object with a "line" and "column"
* field.
* - map: A source map definition. This source map could also be indexed,
* but doesn't have to be.
*
* Instead of the "map" field, it's also possible to have a "url" field
* specifying a URL to retrieve a source map from, but that's currently
* unsupported.
*
* Here's an example source map, taken from the source map spec[0], but
* modified to omit a section which uses the "url" field.
*
* {
* version : 3,
* file: "app.js",
* sections: [{
* offset: {line:100, column:10},
* map: {
* version : 3,
* file: "section.js",
* sources: ["foo.js", "bar.js"],
* names: ["src", "maps", "are", "fun"],
* mappings: "AAAA,E;;ABCDE;"
* }
* }],
* }
*
* The second parameter, if given, is a string whose value is the URL
* at which the source map was found. This URL is used to compute the
* sources array.
*
* [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
*/
function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
var sourceMap = aSourceMap;
if (typeof aSourceMap === 'string') {
sourceMap = util.parseSourceMapInput(aSourceMap);
}
var version = util.getArg(sourceMap, 'version');
var sections = util.getArg(sourceMap, 'sections');
if (version != this._version) {
throw new Error('Unsupported version: ' + version);
}
this._sources = new ArraySet();
this._names = new ArraySet();
var lastOffset = {
line: -1,
column: 0
};
this._sections = sections.map(function (s) {
if (s.url) {
// The url field will require support for asynchronicity.
// See https://github.com/mozilla/source-map/issues/16
throw new Error('Support for url field in sections not implemented.');
}
var offset = util.getArg(s, 'offset');
var offsetLine = util.getArg(offset, 'line');
var offsetColumn = util.getArg(offset, 'column');
if (offsetLine < lastOffset.line ||
(offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
throw new Error('Section offsets must be ordered and non-overlapping.');
}
lastOffset = offset;
return {
generatedOffset: {
// The offset fields are 0-based, but we use 1-based indices when
// encoding/decoding from VLQ.
generatedLine: offsetLine + 1,
generatedColumn: offsetColumn + 1
},
consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
}
});
}
IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
/**
* The version of the source mapping spec that we are consuming.
*/
IndexedSourceMapConsumer.prototype._version = 3;
/**
* The list of original sources.
*/
Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
get: function () {
var sources = [];
for (var i = 0; i < this._sections.length; i++) {
for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
sources.push(this._sections[i].consumer.sources[j]);
}
}
return sources;
}
});
/**
* Returns the original source, line, and column information for the generated
* source's line and column positions provided. The only argument is an object
* with the following properties:
*
* - line: The line number in the generated source. The line number
* is 1-based.
* - column: The column number in the generated source. The column
* number is 0-based.
*
* and an object is returned with the following properties:
*
* - source: The original source file, or null.
* - line: The line number in the original source, or null. The
* line number is 1-based.
* - column: The column number in the original source, or null. The
* column number is 0-based.
* - name: The original identifier, or null.
*/
IndexedSourceMapConsumer.prototype.originalPositionFor =
function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
var needle = {
generatedLine: util.getArg(aArgs, 'line'),
generatedColumn: util.getArg(aArgs, 'column')
};
// Find the section containing the generated position we're trying to map
// to an original position.
var sectionIndex = binarySearch.search(needle, this._sections,
function(needle, section) {
var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
if (cmp) {
return cmp;
}
return (needle.generatedColumn -
section.generatedOffset.generatedColumn);
});
var section = this._sections[sectionIndex];
if (!section) {
return {
source: null,
line: null,
column: null,
name: null
};
}
return section.consumer.originalPositionFor({
line: needle.generatedLine -
(section.generatedOffset.generatedLine - 1),
column: needle.generatedColumn -
(section.generatedOffset.generatedLine === needle.generatedLine
? section.generatedOffset.generatedColumn - 1
: 0),
bias: aArgs.bias
});
};
/**
* Return true if we have the source content for every source in the source
* map, false otherwise.
*/
IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
function IndexedSourceMapConsumer_hasContentsOfAllSources() {
return this._sections.every(function (s) {
return s.consumer.hasContentsOfAllSources();
});
};
/**
* Returns the original source content. The only argument is the url of the
* original source file. Returns null if no original source content is
* available.
*/
IndexedSourceMapConsumer.prototype.sourceContentFor =
function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
for (var i = 0; i < this._sections.length; i++) {
var section = this._sections[i];
var content = section.consumer.sourceContentFor(aSource, true);
if (content) {
return content;
}
}
if (nullOnMissing) {
return null;
}
else {
throw new Error('"' + aSource + '" is not in the SourceMap.');
}
};
/**
* Returns the generated line and column information for the original source,
* line, and column positions provided. The only argument is an object with
* the following properties:
*
* - source: The filename of the original source.
* - line: The line number in the original source. The line number
* is 1-based.
* - column: The column number in the original source. The column
* number is 0-based.
*
* and an object is returned with the following properties:
*
* - line: The line number in the generated source, or null. The
* line number is 1-based.
* - column: The column number in the generated source, or null.
* The column number is 0-based.
*/
IndexedSourceMapConsumer.prototype.generatedPositionFor =
function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
for (var i = 0; i < this._sections.length; i++) {
var section = this._sections[i];
// Only consider this section if the requested source is in the list of
// sources of the consumer.
if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
continue;
}
var generatedPosition = section.consumer.generatedPositionFor(aArgs);
if (generatedPosition) {
var ret = {
line: generatedPosition.line +
(section.generatedOffset.generatedLine - 1),
column: generatedPosition.column +
(section.generatedOffset.generatedLine === generatedPosition.line
? section.generatedOffset.generatedColumn - 1
: 0)
};
return ret;
}
}
return {
line: null,
column: null
};
};
/**
* Parse the mappings in a string in to a data structure which we can easily
* query (the ordered arrays in the `this.__generatedMappings` and
* `this.__originalMappings` properties).
*/
IndexedSourceMapConsumer.prototype._parseMappings =
function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
this.__generatedMappings = [];
this.__originalMappings = [];
for (var i = 0; i < this._sections.length; i++) {
var section = this._sections[i];
var sectionMappings = section.consumer._generatedMappings;
for (var j = 0; j < sectionMappings.length; j++) {
var mapping = sectionMappings[j];
var source = section.consumer._sources.at(mapping.source);
source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
this._sources.add(source);
source = this._sources.indexOf(source);
var name = null;
if (mapping.name) {
name = section.consumer._names.at(mapping.name);
this._names.add(name);
name = this._names.indexOf(name);
}
// The mappings coming from the consumer for the section have
// generated positions relative to the start of the section, so we
// need to offset them to be relative to the start of the concatenated
// generated file.
var adjustedMapping = {
source: source,
generatedLine: mapping.generatedLine +
(section.generatedOffset.generatedLine - 1),
generatedColumn: mapping.generatedColumn +
(section.generatedOffset.generatedLine === mapping.generatedLine
? section.generatedOffset.generatedColumn - 1
: 0),
originalLine: mapping.originalLine,
originalColumn: mapping.originalColumn,
name: name
};
this.__generatedMappings.push(adjustedMapping);
if (typeof adjustedMapping.originalLine === 'number') {
this.__originalMappings.push(adjustedMapping);
}
}
}
quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
quickSort(this.__originalMappings, util.compareByOriginalPositions);
};
exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
},{"./array-set":26,"./base64-vlq":27,"./binary-search":29,"./quick-sort":31,"./util":35}],33:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
var base64VLQ = require('./base64-vlq');
var util = require('./util');
var ArraySet = require('./array-set').ArraySet;
var MappingList = require('./mapping-list').MappingList;
/**
* An instance of the SourceMapGenerator represents a source map which is
* being built incrementally. You may pass an object with the following
* properties:
*
* - file: The filename of the generated source.
* - sourceRoot: A root for all relative URLs in this source map.
*/
function SourceMapGenerator(aArgs) {
if (!aArgs) {
aArgs = {};
}
this._file = util.getArg(aArgs, 'file', null);
this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
this._sources = new ArraySet();
this._names = new ArraySet();
this._mappings = new MappingList();
this._sourcesContents = null;
}
SourceMapGenerator.prototype._version = 3;
/**
* Creates a new SourceMapGenerator based on a SourceMapConsumer
*
* @param aSourceMapConsumer The SourceMap.
*/
SourceMapGenerator.fromSourceMap =
function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
var sourceRoot = aSourceMapConsumer.sourceRoot;
var generator = new SourceMapGenerator({
file: aSourceMapConsumer.file,
sourceRoot: sourceRoot
});
aSourceMapConsumer.eachMapping(function (mapping) {
var newMapping = {
generated: {
line: mapping.generatedLine,
column: mapping.generatedColumn
}
};
if (mapping.source != null) {
newMapping.source = mapping.source;
if (sourceRoot != null) {
newMapping.source = util.relative(sourceRoot, newMapping.source);
}
newMapping.original = {
line: mapping.originalLine,
column: mapping.originalColumn
};
if (mapping.name != null) {
newMapping.name = mapping.name;
}
}
generator.addMapping(newMapping);
});
aSourceMapConsumer.sources.forEach(function (sourceFile) {
var sourceRelative = sourceFile;
if (sourceRoot !== null) {
sourceRelative = util.relative(sourceRoot, sourceFile);
}
if (!generator._sources.has(sourceRelative)) {
generator._sources.add(sourceRelative);
}
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
if (content != null) {
generator.setSourceContent(sourceFile, content);
}
});
return generator;
};
/**
* Add a single mapping from original source line and column to the generated
* source's line and column for this source map being created. The mapping
* object should have the following properties:
*
* - generated: An object with the generated line and column positions.
* - original: An object with the original line and column positions.
* - source: The original source file (relative to the sourceRoot).
* - name: An optional original token name for this mapping.
*/
SourceMapGenerator.prototype.addMapping =
function SourceMapGenerator_addMapping(aArgs) {
var generated = util.getArg(aArgs, 'generated');
var original = util.getArg(aArgs, 'original', null);
var source = util.getArg(aArgs, 'source', null);
var name = util.getArg(aArgs, 'name', null);
if (!this._skipValidation) {
this._validateMapping(generated, original, source, name);
}
if (source != null) {
source = String(source);
if (!this._sources.has(source)) {
this._sources.add(source);
}
}
if (name != null) {
name = String(name);
if (!this._names.has(name)) {
this._names.add(name);
}
}
this._mappings.add({
generatedLine: generated.line,
generatedColumn: generated.column,
originalLine: original != null && original.line,
originalColumn: original != null && original.column,
source: source,
name: name
});
};
/**
* Set the source content for a source file.
*/
SourceMapGenerator.prototype.setSourceContent =
function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
var source = aSourceFile;
if (this._sourceRoot != null) {
source = util.relative(this._sourceRoot, source);
}
if (aSourceContent != null) {
// Add the source content to the _sourcesContents map.
// Create a new _sourcesContents map if the property is null.
if (!this._sourcesContents) {
this._sourcesContents = Object.create(null);
}
this._sourcesContents[util.toSetString(source)] = aSourceContent;
} else if (this._sourcesContents) {
// Remove the source file from the _sourcesContents map.
// If the _sourcesContents map is empty, set the property to null.
delete this._sourcesContents[util.toSetString(source)];
if (Object.keys(this._sourcesContents).length === 0) {
this._sourcesContents = null;
}
}
};
/**
* Applies the mappings of a sub-source-map for a specific source file to the
* source map being generated. Each mapping to the supplied source file is
* rewritten using the supplied source map. Note: The resolution for the
* resulting mappings is the minimium of this map and the supplied map.
*
* @param aSourceMapConsumer The source map to be applied.
* @param aSourceFile Optional. The filename of the source file.
* If omitted, SourceMapConsumer's file property will be used.
* @param aSourceMapPath Optional. The dirname of the path to the source map
* to be applied. If relative, it is relative to the SourceMapConsumer.
* This parameter is needed when the two source maps aren't in the same
* directory, and the source map to be applied contains relative source
* paths. If so, those relative source paths need to be rewritten
* relative to the SourceMapGenerator.
*/
SourceMapGenerator.prototype.applySourceMap =
function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
var sourceFile = aSourceFile;
// If aSourceFile is omitted, we will use the file property of the SourceMap
if (aSourceFile == null) {
if (aSourceMapConsumer.file == null) {
throw new Error(
'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
'or the source map\'s "file" property. Both were omitted.'
);
}
sourceFile = aSourceMapConsumer.file;
}
var sourceRoot = this._sourceRoot;
// Make "sourceFile" relative if an absolute Url is passed.
if (sourceRoot != null) {
sourceFile = util.relative(sourceRoot, sourceFile);
}
// Applying the SourceMap can add and remove items from the sources and
// the names array.
var newSources = new ArraySet();
var newNames = new ArraySet();
// Find mappings for the "sourceFile"
this._mappings.unsortedForEach(function (mapping) {
if (mapping.source === sourceFile && mapping.originalLine != null) {
// Check if it can be mapped by the source map, then update the mapping.
var original = aSourceMapConsumer.originalPositionFor({
line: mapping.originalLine,
column: mapping.originalColumn
});
if (original.source != null) {
// Copy mapping
mapping.source = original.source;
if (aSourceMapPath != null) {
mapping.source = util.join(aSourceMapPath, mapping.source)
}
if (sourceRoot != null) {
mapping.source = util.relative(sourceRoot, mapping.source);
}
mapping.originalLine = original.line;
mapping.originalColumn = original.column;
if (original.name != null) {
mapping.name = original.name;
}
}
}
var source = mapping.source;
if (source != null && !newSources.has(source)) {
newSources.add(source);
}
var name = mapping.name;
if (name != null && !newNames.has(name)) {
newNames.add(name);
}
}, this);
this._sources = newSources;
this._names = newNames;
// Copy sourcesContents of applied map.
aSourceMapConsumer.sources.forEach(function (sourceFile) {
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
if (content != null) {
if (aSourceMapPath != null) {
sourceFile = util.join(aSourceMapPath, sourceFile);
}
if (sourceRoot != null) {
sourceFile = util.relative(sourceRoot, sourceFile);
}
this.setSourceContent(sourceFile, content);
}
}, this);
};
/**
* A mapping can have one of the three levels of data:
*
* 1. Just the generated position.
* 2. The Generated position, original position, and original source.
* 3. Generated and original position, original source, as well as a name
* token.
*
* To maintain consistency, we validate that any new mapping being added falls
* in to one of these categories.
*/
SourceMapGenerator.prototype._validateMapping =
function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
aName) {
// When aOriginal is truthy but has empty values for .line and .column,
// it is most likely a programmer error. In this case we throw a very
// specific error message to try to guide them the right way.
// For example: https://github.com/Polymer/polymer-bundler/pull/519
if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
throw new Error(
'original.line and original.column are not numbers -- you probably meant to omit ' +
'the original mapping entirely and only map the generated position. If so, pass ' +
'null for the original mapping instead of an object with empty or null values.'
);
}
if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
&& aGenerated.line > 0 && aGenerated.column >= 0
&& !aOriginal && !aSource && !aName) {
// Case 1.
return;
}
else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
&& aOriginal && 'line' in aOriginal && 'column' in aOriginal
&& aGenerated.line > 0 && aGenerated.column >= 0
&& aOriginal.line > 0 && aOriginal.column >= 0
&& aSource) {
// Cases 2 and 3.
return;
}
else {
throw new Error('Invalid mapping: ' + JSON.stringify({
generated: aGenerated,
source: aSource,
original: aOriginal,
name: aName
}));
}
};
/**
* Serialize the accumulated mappings in to the stream of base 64 VLQs
* specified by the source map format.
*/
SourceMapGenerator.prototype._serializeMappings =
function SourceMapGenerator_serializeMappings() {
var previousGeneratedColumn = 0;
var previousGeneratedLine = 1;
var previousOriginalColumn = 0;
var previousOriginalLine = 0;
var previousName = 0;
var previousSource = 0;
var result = '';
var next;
var mapping;
var nameIdx;
var sourceIdx;
var mappings = this._mappings.toArray();
for (var i = 0, len = mappings.length; i < len; i++) {
mapping = mappings[i];
next = ''
if (mapping.generatedLine !== previousGeneratedLine) {
previousGeneratedColumn = 0;
while (mapping.generatedLine !== previousGeneratedLine) {
next += ';';
previousGeneratedLine++;
}
}
else {
if (i > 0) {
if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
continue;
}
next += ',';
}
}
next += base64VLQ.encode(mapping.generatedColumn
- previousGeneratedColumn);
previousGeneratedColumn = mapping.generatedColumn;
if (mapping.source != null) {
sourceIdx = this._sources.indexOf(mapping.source);
next += base64VLQ.encode(sourceIdx - previousSource);
previousSource = sourceIdx;
// lines are stored 0-based in SourceMap spec version 3
next += base64VLQ.encode(mapping.originalLine - 1
- previousOriginalLine);
previousOriginalLine = mapping.originalLine - 1;
next += base64VLQ.encode(mapping.originalColumn
- previousOriginalColumn);
previousOriginalColumn = mapping.originalColumn;
if (mapping.name != null) {
nameIdx = this._names.indexOf(mapping.name);
next += base64VLQ.encode(nameIdx - previousName);
previousName = nameIdx;
}
}
result += next;
}
return result;
};
SourceMapGenerator.prototype._generateSourcesContent =
function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
return aSources.map(function (source) {
if (!this._sourcesContents) {
return null;
}
if (aSourceRoot != null) {
source = util.relative(aSourceRoot, source);
}
var key = util.toSetString(source);
return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
? this._sourcesContents[key]
: null;
}, this);
};
/**
* Externalize the source map.
*/
SourceMapGenerator.prototype.toJSON =
function SourceMapGenerator_toJSON() {
var map = {
version: this._version,
sources: this._sources.toArray(),
names: this._names.toArray(),
mappings: this._serializeMappings()
};
if (this._file != null) {
map.file = this._file;
}
if (this._sourceRoot != null) {
map.sourceRoot = this._sourceRoot;
}
if (this._sourcesContents) {
map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
}
return map;
};
/**
* Render the source map being generated to a string.
*/
SourceMapGenerator.prototype.toString =
function SourceMapGenerator_toString() {
return JSON.stringify(this.toJSON());
};
exports.SourceMapGenerator = SourceMapGenerator;
},{"./array-set":26,"./base64-vlq":27,"./mapping-list":30,"./util":35}],34:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
var util = require('./util');
// Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
// operating systems these days (capturing the result).
var REGEX_NEWLINE = /(\r?\n)/;
// Newline character code for charCodeAt() comparisons
var NEWLINE_CODE = 10;
// Private symbol for identifying `SourceNode`s when multiple versions of
// the source-map library are loaded. This MUST NOT CHANGE across
// versions!
var isSourceNode = "$$$isSourceNode$$$";
/**
* SourceNodes provide a way to abstract over interpolating/concatenating
* snippets of generated JavaScript source code while maintaining the line and
* column information associated with the original source code.
*
* @param aLine The original line number.
* @param aColumn The original column number.
* @param aSource The original source's filename.
* @param aChunks Optional. An array of strings which are snippets of
* generated JS, or other SourceNodes.
* @param aName The original identifier.
*/
function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
this.children = [];
this.sourceContents = {};
this.line = aLine == null ? null : aLine;
this.column = aColumn == null ? null : aColumn;
this.source = aSource == null ? null : aSource;
this.name = aName == null ? null : aName;
this[isSourceNode] = true;
if (aChunks != null) this.add(aChunks);
}
/**
* Creates a SourceNode from generated code and a SourceMapConsumer.
*
* @param aGeneratedCode The generated code
* @param aSourceMapConsumer The SourceMap for the generated code
* @param aRelativePath Optional. The path that relative sources in the
* SourceMapConsumer should be relative to.
*/
SourceNode.fromStringWithSourceMap =
function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
// The SourceNode we want to fill with the generated code
// and the SourceMap
var node = new SourceNode();
// All even indices of this array are one line of the generated code,
// while all odd indices are the newlines between two adjacent lines
// (since `REGEX_NEWLINE` captures its match).
// Processed fragments are accessed by calling `shiftNextLine`.
var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
var remainingLinesIndex = 0;
var shiftNextLine = function() {
var lineContents = getNextLine();
// The last line of a file might not have a newline.
var newLine = getNextLine() || "";
return lineContents + newLine;
function getNextLine() {
return remainingLinesIndex < remainingLines.length ?
remainingLines[remainingLinesIndex++] : undefined;
}
};
// We need to remember the position of "remainingLines"
var lastGeneratedLine = 1, lastGeneratedColumn = 0;
// The generate SourceNodes we need a code range.
// To extract it current and last mapping is used.
// Here we store the last mapping.
var lastMapping = null;
aSourceMapConsumer.eachMapping(function (mapping) {
if (lastMapping !== null) {
// We add the code from "lastMapping" to "mapping":
// First check if there is a new line in between.
if (lastGeneratedLine < mapping.generatedLine) {
// Associate first line with "lastMapping"
addMappingWithCode(lastMapping, shiftNextLine());
lastGeneratedLine++;
lastGeneratedColumn = 0;
// The remaining code is added without mapping
} else {
// There is no new line in between.
// Associate the code between "lastGeneratedColumn" and
// "mapping.generatedColumn" with "lastMapping"
var nextLine = remainingLines[remainingLinesIndex] || '';
var code = nextLine.substr(0, mapping.generatedColumn -
lastGeneratedColumn);
remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
lastGeneratedColumn);
lastGeneratedColumn = mapping.generatedColumn;
addMappingWithCode(lastMapping, code);
// No more remaining code, continue
lastMapping = mapping;
return;
}
}
// We add the generated code until the first mapping
// to the SourceNode without any mapping.
// Each line is added as separate string.
while (lastGeneratedLine < mapping.generatedLine) {
node.add(shiftNextLine());
lastGeneratedLine++;
}
if (lastGeneratedColumn < mapping.generatedColumn) {
var nextLine = remainingLines[remainingLinesIndex] || '';
node.add(nextLine.substr(0, mapping.generatedColumn));
remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
lastGeneratedColumn = mapping.generatedColumn;
}
lastMapping = mapping;
}, this);
// We have processed all mappings.
if (remainingLinesIndex < remainingLines.length) {
if (lastMapping) {
// Associate the remaining code in the current line with "lastMapping"
addMappingWithCode(lastMapping, shiftNextLine());
}
// and add the remaining lines without any mapping
node.add(remainingLines.splice(remainingLinesIndex).join(""));
}
// Copy sourcesContent into SourceNode
aSourceMapConsumer.sources.forEach(function (sourceFile) {
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
if (content != null) {
if (aRelativePath != null) {
sourceFile = util.join(aRelativePath, sourceFile);
}
node.setSourceContent(sourceFile, content);
}
});
return node;
function addMappingWithCode(mapping, code) {
if (mapping === null || mapping.source === undefined) {
node.add(code);
} else {
var source = aRelativePath
? util.join(aRelativePath, mapping.source)
: mapping.source;
node.add(new SourceNode(mapping.originalLine,
mapping.originalColumn,
source,
code,
mapping.name));
}
}
};
/**
* Add a chunk of generated JS to this source node.
*
* @param aChunk A string snippet of generated JS code, another instance of
* SourceNode, or an array where each member is one of those things.
*/
SourceNode.prototype.add = function SourceNode_add(aChunk) {
if (Array.isArray(aChunk)) {
aChunk.forEach(function (chunk) {
this.add(chunk);
}, this);
}
else if (aChunk[isSourceNode] || typeof aChunk === "string") {
if (aChunk) {
this.children.push(aChunk);
}
}
else {
throw new TypeError(
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
);
}
return this;
};
/**
* Add a chunk of generated JS to the beginning of this source node.
*
* @param aChunk A string snippet of generated JS code, another instance of
* SourceNode, or an array where each member is one of those things.
*/
SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
if (Array.isArray(aChunk)) {
for (var i = aChunk.length-1; i >= 0; i--) {
this.prepend(aChunk[i]);
}
}
else if (aChunk[isSourceNode] || typeof aChunk === "string") {
this.children.unshift(aChunk);
}
else {
throw new TypeError(
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
);
}
return this;
};
/**
* Walk over the tree of JS snippets in this node and its children. The
* walking function is called once for each snippet of JS and is passed that
* snippet and the its original associated source's line/column location.
*
* @param aFn The traversal function.
*/
SourceNode.prototype.walk = function SourceNode_walk(aFn) {
var chunk;
for (var i = 0, len = this.children.length; i < len; i++) {
chunk = this.children[i];
if (chunk[isSourceNode]) {
chunk.walk(aFn);
}
else {
if (chunk !== '') {
aFn(chunk, { source: this.source,
line: this.line,
column: this.column,
name: this.name });
}
}
}
};
/**
* Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
* each of `this.children`.
*
* @param aSep The separator.
*/
SourceNode.prototype.join = function SourceNode_join(aSep) {
var newChildren;
var i;
var len = this.children.length;
if (len > 0) {
newChildren = [];
for (i = 0; i < len-1; i++) {
newChildren.push(this.children[i]);
newChildren.push(aSep);
}
newChildren.push(this.children[i]);
this.children = newChildren;
}
return this;
};
/**
* Call String.prototype.replace on the very right-most source snippet. Useful
* for trimming whitespace from the end of a source node, etc.
*
* @param aPattern The pattern to replace.
* @param aReplacement The thing to replace the pattern with.
*/
SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
var lastChild = this.children[this.children.length - 1];
if (lastChild[isSourceNode]) {
lastChild.replaceRight(aPattern, aReplacement);
}
else if (typeof lastChild === 'string') {
this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
}
else {
this.children.push(''.replace(aPattern, aReplacement));
}
return this;
};
/**
* Set the source content for a source file. This will be added to the SourceMapGenerator
* in the sourcesContent field.
*
* @param aSourceFile The filename of the source file
* @param aSourceContent The content of the source file
*/
SourceNode.prototype.setSourceContent =
function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
};
/**
* Walk over the tree of SourceNodes. The walking function is called for each
* source file content and is passed the filename and source content.
*
* @param aFn The traversal function.
*/
SourceNode.prototype.walkSourceContents =
function SourceNode_walkSourceContents(aFn) {
for (var i = 0, len = this.children.length; i < len; i++) {
if (this.children[i][isSourceNode]) {
this.children[i].walkSourceContents(aFn);
}
}
var sources = Object.keys(this.sourceContents);
for (var i = 0, len = sources.length; i < len; i++) {
aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
}
};
/**
* Return the string representation of this source node. Walks over the tree
* and concatenates all the various snippets together to one string.
*/
SourceNode.prototype.toString = function SourceNode_toString() {
var str = "";
this.walk(function (chunk) {
str += chunk;
});
return str;
};
/**
* Returns the string representation of this source node along with a source
* map.
*/
SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
var generated = {
code: "",
line: 1,
column: 0
};
var map = new SourceMapGenerator(aArgs);
var sourceMappingActive = false;
var lastOriginalSource = null;
var lastOriginalLine = null;
var lastOriginalColumn = null;
var lastOriginalName = null;
this.walk(function (chunk, original) {
generated.code += chunk;
if (original.source !== null
&& original.line !== null
&& original.column !== null) {
if(lastOriginalSource !== original.source
|| lastOriginalLine !== original.line
|| lastOriginalColumn !== original.column
|| lastOriginalName !== original.name) {
map.addMapping({
source: original.source,
original: {
line: original.line,
column: original.column
},
generated: {
line: generated.line,
column: generated.column
},
name: original.name
});
}
lastOriginalSource = original.source;
lastOriginalLine = original.line;
lastOriginalColumn = original.column;
lastOriginalName = original.name;
sourceMappingActive = true;
} else if (sourceMappingActive) {
map.addMapping({
generated: {
line: generated.line,
column: generated.column
}
});
lastOriginalSource = null;
sourceMappingActive = false;
}
for (var idx = 0, length = chunk.length; idx < length; idx++) {
if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
generated.line++;
generated.column = 0;
// Mappings end at eol
if (idx + 1 === length) {
lastOriginalSource = null;
sourceMappingActive = false;
} else if (sourceMappingActive) {
map.addMapping({
source: original.source,
original: {
line: original.line,
column: original.column
},
generated: {
line: generated.line,
column: generated.column
},
name: original.name
});
}
} else {
generated.column++;
}
}
});
this.walkSourceContents(function (sourceFile, sourceContent) {
map.setSourceContent(sourceFile, sourceContent);
});
return { code: generated.code, map: map };
};
exports.SourceNode = SourceNode;
},{"./source-map-generator":33,"./util":35}],35:[function(require,module,exports){
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
/**
* This is a helper function for getting values from parameter/options
* objects.
*
* @param args The object we are extracting values from
* @param name The name of the property we are getting.
* @param defaultValue An optional value to return if the property is missing
* from the object. If this is not specified and the property is missing, an
* error will be thrown.
*/
function getArg(aArgs, aName, aDefaultValue) {
if (aName in aArgs) {
return aArgs[aName];
} else if (arguments.length === 3) {
return aDefaultValue;
} else {
throw new Error('"' + aName + '" is a required argument.');
}
}
exports.getArg = getArg;
var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
var dataUrlRegexp = /^data:.+\,.+$/;
function urlParse(aUrl) {
var match = aUrl.match(urlRegexp);
if (!match) {
return null;
}
return {
scheme: match[1],
auth: match[2],
host: match[3],
port: match[4],
path: match[5]
};
}
exports.urlParse = urlParse;
function urlGenerate(aParsedUrl) {
var url = '';
if (aParsedUrl.scheme) {
url += aParsedUrl.scheme + ':';
}
url += '//';
if (aParsedUrl.auth) {
url += aParsedUrl.auth + '@';
}
if (aParsedUrl.host) {
url += aParsedUrl.host;
}
if (aParsedUrl.port) {
url += ":" + aParsedUrl.port
}
if (aParsedUrl.path) {
url += aParsedUrl.path;
}
return url;
}
exports.urlGenerate = urlGenerate;
/**
* Normalizes a path, or the path portion of a URL:
*
* - Replaces consecutive slashes with one slash.
* - Removes unnecessary '.' parts.
* - Removes unnecessary '<dir>/..' parts.
*
* Based on code in the Node.js 'path' core module.
*
* @param aPath The path or url to normalize.
*/
function normalize(aPath) {
var path = aPath;
var url = urlParse(aPath);
if (url) {
if (!url.path) {
return aPath;
}
path = url.path;
}
var isAbsolute = exports.isAbsolute(path);
var parts = path.split(/\/+/);
for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
part = parts[i];
if (part === '.') {
parts.splice(i, 1);
} else if (part === '..') {
up++;
} else if (up > 0) {
if (part === '') {
// The first part is blank if the path is absolute. Trying to go
// above the root is a no-op. Therefore we can remove all '..' parts
// directly after the root.
parts.splice(i + 1, up);
up = 0;
} else {
parts.splice(i, 2);
up--;
}
}
}
path = parts.join('/');
if (path === '') {
path = isAbsolute ? '/' : '.';
}
if (url) {
url.path = path;
return urlGenerate(url);
}
return path;
}
exports.normalize = normalize;
/**
* Joins two paths/URLs.
*
* @param aRoot The root path or URL.
* @param aPath The path or URL to be joined with the root.
*
* - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
* scheme-relative URL: Then the scheme of aRoot, if any, is prepended
* first.
* - Otherwise aPath is a path. If aRoot is a URL, then its path portion
* is updated with the result and aRoot is returned. Otherwise the result
* is returned.
* - If aPath is absolute, the result is aPath.
* - Otherwise the two paths are joined with a slash.
* - Joining for example 'http://' and 'www.example.com' is also supported.
*/
function join(aRoot, aPath) {
if (aRoot === "") {
aRoot = ".";
}
if (aPath === "") {
aPath = ".";
}
var aPathUrl = urlParse(aPath);
var aRootUrl = urlParse(aRoot);
if (aRootUrl) {
aRoot = aRootUrl.path || '/';
}
// `join(foo, '//www.example.org')`
if (aPathUrl && !aPathUrl.scheme) {
if (aRootUrl) {
aPathUrl.scheme = aRootUrl.scheme;
}
return urlGenerate(aPathUrl);
}
if (aPathUrl || aPath.match(dataUrlRegexp)) {
return aPath;
}
// `join('http://', 'www.example.com')`
if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
aRootUrl.host = aPath;
return urlGenerate(aRootUrl);
}
var joined = aPath.charAt(0) === '/'
? aPath
: normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
if (aRootUrl) {
aRootUrl.path = joined;
return urlGenerate(aRootUrl);
}
return joined;
}
exports.join = join;
exports.isAbsolute = function (aPath) {
return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
};
/**
* Make a path relative to a URL or another path.
*
* @param aRoot The root path or URL.
* @param aPath The path or URL to be made relative to aRoot.
*/
function relative(aRoot, aPath) {
if (aRoot === "") {
aRoot = ".";
}
aRoot = aRoot.replace(/\/$/, '');
// It is possible for the path to be above the root. In this case, simply
// checking whether the root is a prefix of the path won't work. Instead, we
// need to remove components from the root one by one, until either we find
// a prefix that fits, or we run out of components to remove.
var level = 0;
while (aPath.indexOf(aRoot + '/') !== 0) {
var index = aRoot.lastIndexOf("/");
if (index < 0) {
return aPath;
}
// If the only part of the root that is left is the scheme (i.e. http://,
// file:///, etc.), one or more slashes (/), or simply nothing at all, we
// have exhausted all components, so the path is not relative to the root.
aRoot = aRoot.slice(0, index);
if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
return aPath;
}
++level;
}
// Make sure we add a "../" for each component we removed from the root.
return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
}
exports.relative = relative;
var supportsNullProto = (function () {
var obj = Object.create(null);
return !('__proto__' in obj);
}());
function identity (s) {
return s;
}
/**
* Because behavior goes wacky when you set `__proto__` on objects, we
* have to prefix all the strings in our set with an arbitrary character.
*
* See https://github.com/mozilla/source-map/pull/31 and
* https://github.com/mozilla/source-map/issues/30
*
* @param String aStr
*/
function toSetString(aStr) {
if (isProtoString(aStr)) {
return '$' + aStr;
}
return aStr;
}
exports.toSetString = supportsNullProto ? identity : toSetString;
function fromSetString(aStr) {
if (isProtoString(aStr)) {
return aStr.slice(1);
}
return aStr;
}
exports.fromSetString = supportsNullProto ? identity : fromSetString;
function isProtoString(s) {
if (!s) {
return false;
}
var length = s.length;
if (length < 9 /* "__proto__".length */) {
return false;
}
if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
s.charCodeAt(length - 2) !== 95 /* '_' */ ||
s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
s.charCodeAt(length - 4) !== 116 /* 't' */ ||
s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
s.charCodeAt(length - 8) !== 95 /* '_' */ ||
s.charCodeAt(length - 9) !== 95 /* '_' */) {
return false;
}
for (var i = length - 10; i >= 0; i--) {
if (s.charCodeAt(i) !== 36 /* '$' */) {
return false;
}
}
return true;
}
/**
* Comparator between two mappings where the original positions are compared.
*
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
* mappings with the same original source/line/column, but different generated
* line and column the same. Useful when searching for a mapping with a
* stubbed out mapping.
*/
function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
var cmp = strcmp(mappingA.source, mappingB.source);
if (cmp !== 0) {
return cmp;
}
cmp = mappingA.originalLine - mappingB.originalLine;
if (cmp !== 0) {
return cmp;
}
cmp = mappingA.originalColumn - mappingB.originalColumn;
if (cmp !== 0 || onlyCompareOriginal) {
return cmp;
}
cmp = mappingA.generatedColumn - mappingB.generatedColumn;
if (cmp !== 0) {
return cmp;
}
cmp = mappingA.generatedLine - mappingB.generatedLine;
if (cmp !== 0) {
return cmp;
}
return strcmp(mappingA.name, mappingB.name);
}
exports.compareByOriginalPositions = compareByOriginalPositions;
/**
* Comparator between two mappings with deflated source and name indices where
* the generated positions are compared.
*
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
* mappings with the same generated line and column, but different
* source/name/original line and column the same. Useful when searching for a
* mapping with a stubbed out mapping.
*/
function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
var cmp = mappingA.generatedLine - mappingB.generatedLine;
if (cmp !== 0) {
return cmp;
}
cmp = mappingA.generatedColumn - mappingB.generatedColumn;
if (cmp !== 0 || onlyCompareGenerated) {
return cmp;
}
cmp = strcmp(mappingA.source, mappingB.source);
if (cmp !== 0) {
return cmp;
}
cmp = mappingA.originalLine - mappingB.originalLine;
if (cmp !== 0) {
return cmp;
}
cmp = mappingA.originalColumn - mappingB.originalColumn;
if (cmp !== 0) {
return cmp;
}
return strcmp(mappingA.name, mappingB.name);
}
exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
function strcmp(aStr1, aStr2) {
if (aStr1 === aStr2) {
return 0;
}
if (aStr1 === null) {
return 1; // aStr2 !== null
}
if (aStr2 === null) {
return -1; // aStr1 !== null
}
if (aStr1 > aStr2) {
return 1;
}
return -1;
}
/**
* Comparator between two mappings with inflated source and name strings where
* the generated positions are compared.
*/
function compareByGeneratedPositionsInflated(mappingA, mappingB) {
var cmp = mappingA.generatedLine - mappingB.generatedLine;
if (cmp !== 0) {
return cmp;
}
cmp = mappingA.generatedColumn - mappingB.generatedColumn;
if (cmp !== 0) {
return cmp;
}
cmp = strcmp(mappingA.source, mappingB.source);
if (cmp !== 0) {
return cmp;
}
cmp = mappingA.originalLine - mappingB.originalLine;
if (cmp !== 0) {
return cmp;
}
cmp = mappingA.originalColumn - mappingB.originalColumn;
if (cmp !== 0) {
return cmp;
}
return strcmp(mappingA.name, mappingB.name);
}
exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
/**
* Strip any JSON XSSI avoidance prefix from the string (as documented
* in the source maps specification), and then parse the string as
* JSON.
*/
function parseSourceMapInput(str) {
return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
}
exports.parseSourceMapInput = parseSourceMapInput;
/**
* Compute the URL of a source given the the source root, the source's
* URL, and the source map's URL.
*/
function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
sourceURL = sourceURL || '';
if (sourceRoot) {
// This follows what Chrome does.
if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
sourceRoot += '/';
}
// The spec says:
// Line 4: An optional source root, useful for relocating source
// files on a server or removing repeated values in the
// “sources” entry. This value is prepended to the individual
// entries in the “source” field.
sourceURL = sourceRoot + sourceURL;
}
// Historically, SourceMapConsumer did not take the sourceMapURL as
// a parameter. This mode is still somewhat supported, which is why
// this code block is conditional. However, it's preferable to pass
// the source map URL to SourceMapConsumer, so that this function
// can implement the source URL resolution algorithm as outlined in
// the spec. This block is basically the equivalent of:
// new URL(sourceURL, sourceMapURL).toString()
// ... except it avoids using URL, which wasn't available in the
// older releases of node still supported by this library.
//
// The spec says:
// If the sources are not absolute URLs after prepending of the
// “sourceRoot”, the sources are resolved relative to the
// SourceMap (like resolving script src in a html document).
if (sourceMapURL) {
var parsed = urlParse(sourceMapURL);
if (!parsed) {
throw new Error("sourceMapURL could not be parsed");
}
if (parsed.path) {
// Strip the last path component, but keep the "/".
var index = parsed.path.lastIndexOf('/');
if (index >= 0) {
parsed.path = parsed.path.substring(0, index + 1);
}
}
sourceURL = join(urlGenerate(parsed), sourceURL);
}
return normalize(sourceURL);
}
exports.computeSourceURL = computeSourceURL;
},{}],36:[function(require,module,exports){
/*
* Copyright 2009-2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE.txt or:
* http://opensource.org/licenses/BSD-3-Clause
*/
exports.SourceMapGenerator = require('./lib/source-map-generator').SourceMapGenerator;
exports.SourceMapConsumer = require('./lib/source-map-consumer').SourceMapConsumer;
exports.SourceNode = require('./lib/source-node').SourceNode;
},{"./lib/source-map-consumer":32,"./lib/source-map-generator":33,"./lib/source-node":34}]},{},[14]);
var SPECIFICITY=function(){var t,e;return t=function(t){var r,n,i,c,a=[];for(i=0,c=(r=t.split(",")).length;i<c;i+=1)(n=r[i]).length>0&&a.push(e(n));return a},e=function(t){var e,r,n=t,i={a:0,b:0,c:0},c=[];return e=function(t,e){var r,a,g,l,o,s;if(t.test(n))for(a=0,g=(r=n.match(t)).length;a<g;a+=1)i[e]+=1,l=r[a],o=n.indexOf(l),s=l.length,c.push({selector:l,type:e,index:o,length:s}),n=n.replace(l,Array(s+1).join(" "))},(r=/:not\(([^\)]*)\)/g).test(n)&&(n=n.replace(r," $1 ")),function(){var t,e,r,i,c=/{[^]*/gm;if(c.test(n))for(e=0,r=(t=n.match(c)).length;e<r;e+=1)i=t[e],n=n.replace(i,Array(i.length+1).join(" "))}(),e(/(\[[^\]]+\])/g,"b"),e(/(#[^\s\+>~\.\[:]+)/g,"a"),e(/(\.[^\s\+>~\.\[:]+)/g,"b"),e(/(::[^\s\+>~\.\[:]+|:first-line|:first-letter|:before|:after)/gi,"c"),e(/(:[\w-]+\([^\)]*\))/gi,"b"),e(/(:[^\s\+>~\.\[:]+)/g,"b"),n=(n=n.replace(/[\*\s\+>~]/g," ")).replace(/[#\.]/g," "),e(/([^\s\+>~\.\[:]+)/g,"c"),c.sort((function(t,e){return t.index-e.index})),{selector:t,specificity:"0,"+i.a.toString()+","+i.b.toString()+","+i.c.toString(),parts:c}},{calculate:t}}();/*!
* URI.js - Mutating URLs
*
* Version: 1.18.1
*
* Author: Rodney Rehm
* Web: http://medialize.github.io/URI.js/
*
* Licensed under
* MIT License http://www.opensource.org/licenses/mit-license
*
*/
(function (root, factory) {
'use strict';
// Browser globals (root is window)
root.URI = factory(root.punycode, root.IPv6, root.SecondLevelDomains, root);
}(this, function (punycode, IPv6, SLD, root) {
'use strict';
/*global location, escape, unescape */
// FIXME: v2.0.0 renamce non-camelCase properties to uppercase
/*jshint camelcase: false */
// save current URI variable, if any
var _URI = root && root.URI;
function URI(url, base) {
var _urlSupplied = arguments.length >= 1;
var _baseSupplied = arguments.length >= 2;
// Allow instantiation without the 'new' keyword
if (!(this instanceof URI)) {
if (_urlSupplied) {
if (_baseSupplied) {
return new URI(url, base);
}
return new URI(url);
}
return new URI();
}
if (url === undefined) {
if (_urlSupplied) {
throw new TypeError('undefined is not a valid argument for URI');
}
if (typeof location !== 'undefined') {
url = location.href + '';
} else {
url = '';
}
}
this.href(url);
// resolve to base according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor
if (base !== undefined) {
return this.absoluteTo(base);
}
return this;
}
URI.version = '1.18.1';
var p = URI.prototype;
var hasOwn = Object.prototype.hasOwnProperty;
function escapeRegEx(string) {
// https://github.com/medialize/URI.js/commit/85ac21783c11f8ccab06106dba9735a31a86924d#commitcomment-821963
return string.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
}
function getType(value) {
// IE8 doesn't return [Object Undefined] but [Object Object] for undefined value
if (value === undefined) {
return 'Undefined';
}
return String(Object.prototype.toString.call(value)).slice(8, -1);
}
function isArray(obj) {
return getType(obj) === 'Array';
}
function filterArrayValues(data, value) {
var lookup = {};
var i, length;
if (getType(value) === 'RegExp') {
lookup = null;
} else if (isArray(value)) {
for (i = 0, length = value.length; i < length; i++) {
lookup[value[i]] = true;
}
} else {
lookup[value] = true;
}
for (i = 0, length = data.length; i < length; i++) {
/*jshint laxbreak: true */
var _match = lookup && lookup[data[i]] !== undefined
|| !lookup && value.test(data[i]);
/*jshint laxbreak: false */
if (_match) {
data.splice(i, 1);
length--;
i--;
}
}
return data;
}
function arrayContains(list, value) {
var i, length;
// value may be string, number, array, regexp
if (isArray(value)) {
// Note: this can be optimized to O(n) (instead of current O(m * n))
for (i = 0, length = value.length; i < length; i++) {
if (!arrayContains(list, value[i])) {
return false;
}
}
return true;
}
var _type = getType(value);
for (i = 0, length = list.length; i < length; i++) {
if (_type === 'RegExp') {
if (typeof list[i] === 'string' && list[i].match(value)) {
return true;
}
} else if (list[i] === value) {
return true;
}
}
return false;
}
function arraysEqual(one, two) {
if (!isArray(one) || !isArray(two)) {
return false;
}
// arrays can't be equal if they have different amount of content
if (one.length !== two.length) {
return false;
}
one.sort();
two.sort();
for (var i = 0, l = one.length; i < l; i++) {
if (one[i] !== two[i]) {
return false;
}
}
return true;
}
function trimSlashes(text) {
var trim_expression = /^\/+|\/+$/g;
return text.replace(trim_expression, '');
}
URI._parts = function() {
return {
protocol: null,
username: null,
password: null,
hostname: null,
urn: null,
port: null,
path: null,
query: null,
fragment: null,
// state
duplicateQueryParameters: URI.duplicateQueryParameters,
escapeQuerySpace: URI.escapeQuerySpace
};
};
// state: allow duplicate query parameters (a=1&a=1)
URI.duplicateQueryParameters = false;
// state: replaces + with %20 (space in query strings)
URI.escapeQuerySpace = true;
// static properties
URI.protocol_expression = /^[a-z][a-z0-9.+-]*$/i;
URI.idn_expression = /[^a-z0-9\.-]/i;
URI.punycode_expression = /(xn--)/i;
// well, 333.444.555.666 matches, but it sure ain't no IPv4 - do we care?
URI.ip4_expression = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
// credits to Rich Brown
// source: http://forums.intermapper.com/viewtopic.php?p=1096#1096
// specification: http://www.ietf.org/rfc/rfc4291.txt
URI.ip6_expression = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/;
// expression used is "gruber revised" (@gruber v2) determined to be the
// best solution in a regex-golf we did a couple of ages ago at
// * http://mathiasbynens.be/demo/url-regex
// * http://rodneyrehm.de/t/url-regex.html
URI.find_uri_expression = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/ig;
URI.findUri = {
// valid "scheme://" or "www."
start: /\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,
// everything up to the next whitespace
end: /[\s\r\n]|$/,
// trim trailing punctuation captured by end RegExp
trim: /[`!()\[\]{};:'".,<>?«»“”„‘’]+$/
};
// http://www.iana.org/assignments/uri-schemes.html
// http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports
URI.defaultPorts = {
http: '80',
https: '443',
ftp: '21',
gopher: '70',
ws: '80',
wss: '443'
};
// allowed hostname characters according to RFC 3986
// ALPHA DIGIT "-" "." "_" "~" "!" "$" "&" "'" "(" ")" "*" "+" "," ";" "=" %encoded
// I've never seen a (non-IDN) hostname other than: ALPHA DIGIT . -
URI.invalid_hostname_characters = /[^a-zA-Z0-9\.-]/;
// map DOM Elements to their URI attribute
URI.domAttributes = {
'a': 'href',
'blockquote': 'cite',
'link': 'href',
'base': 'href',
'script': 'src',
'form': 'action',
'img': 'src',
'area': 'href',
'iframe': 'src',
'embed': 'src',
'source': 'src',
'track': 'src',
'input': 'src', // but only if type="image"
'audio': 'src',
'video': 'src'
};
URI.getDomAttribute = function(node) {
if (!node || !node.nodeName) {
return undefined;
}
var nodeName = node.nodeName.toLowerCase();
// <input> should only expose src for type="image"
if (nodeName === 'input' && node.type !== 'image') {
return undefined;
}
return URI.domAttributes[nodeName];
};
function escapeForDumbFirefox36(value) {
// https://github.com/medialize/URI.js/issues/91
return escape(value);
}
// encoding / decoding according to RFC3986
function strictEncodeURIComponent(string) {
// see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent
return encodeURIComponent(string)
.replace(/[!'()*]/g, escapeForDumbFirefox36)
.replace(/\*/g, '%2A');
}
URI.encode = strictEncodeURIComponent;
URI.decode = decodeURIComponent;
URI.iso8859 = function() {
URI.encode = escape;
URI.decode = unescape;
};
URI.unicode = function() {
URI.encode = strictEncodeURIComponent;
URI.decode = decodeURIComponent;
};
URI.characters = {
pathname: {
encode: {
// RFC3986 2.1: For consistency, URI producers and normalizers should
// use uppercase hexadecimal digits for all percent-encodings.
expression: /%(24|26|2B|2C|3B|3D|3A|40)/ig,
map: {
// -._~!'()*
'%24': '$',
'%26': '&',
'%2B': '+',
'%2C': ',',
'%3B': ';',
'%3D': '=',
'%3A': ':',
'%40': '@'
}
},
decode: {
expression: /[\/\?#]/g,
map: {
'/': '%2F',
'?': '%3F',
'#': '%23'
}
}
},
reserved: {
encode: {
// RFC3986 2.1: For consistency, URI producers and normalizers should
// use uppercase hexadecimal digits for all percent-encodings.
expression: /%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,
map: {
// gen-delims
'%3A': ':',
'%2F': '/',
'%3F': '?',
'%23': '#',
'%5B': '[',
'%5D': ']',
'%40': '@',
// sub-delims
'%21': '!',
'%24': '$',
'%26': '&',
'%27': '\'',
'%28': '(',
'%29': ')',
'%2A': '*',
'%2B': '+',
'%2C': ',',
'%3B': ';',
'%3D': '='
}
}
},
urnpath: {
// The characters under `encode` are the characters called out by RFC 2141 as being acceptable
// for usage in a URN. RFC2141 also calls out "-", ".", and "_" as acceptable characters, but
// these aren't encoded by encodeURIComponent, so we don't have to call them out here. Also
// note that the colon character is not featured in the encoding map; this is because URI.js
// gives the colons in URNs semantic meaning as the delimiters of path segements, and so it
// should not appear unencoded in a segment itself.
// See also the note above about RFC3986 and capitalalized hex digits.
encode: {
expression: /%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,
map: {
'%21': '!',
'%24': '$',
'%27': '\'',
'%28': '(',
'%29': ')',
'%2A': '*',
'%2B': '+',
'%2C': ',',
'%3B': ';',
'%3D': '=',
'%40': '@'
}
},
// These characters are the characters called out by RFC2141 as "reserved" characters that
// should never appear in a URN, plus the colon character (see note above).
decode: {
expression: /[\/\?#:]/g,
map: {
'/': '%2F',
'?': '%3F',
'#': '%23',
':': '%3A'
}
}
}
};
URI.encodeQuery = function(string, escapeQuerySpace) {
var escaped = URI.encode(string + '');
if (escapeQuerySpace === undefined) {
escapeQuerySpace = URI.escapeQuerySpace;
}
return escapeQuerySpace ? escaped.replace(/%20/g, '+') : escaped;
};
URI.decodeQuery = function(string, escapeQuerySpace) {
string += '';
if (escapeQuerySpace === undefined) {
escapeQuerySpace = URI.escapeQuerySpace;
}
try {
return URI.decode(escapeQuerySpace ? string.replace(/\+/g, '%20') : string);
} catch(e) {
// we're not going to mess with weird encodings,
// give up and return the undecoded original string
// see https://github.com/medialize/URI.js/issues/87
// see https://github.com/medialize/URI.js/issues/92
return string;
}
};
// generate encode/decode path functions
var _parts = {'encode':'encode', 'decode':'decode'};
var _part;
var generateAccessor = function(_group, _part) {
return function(string) {
try {
return URI[_part](string + '').replace(URI.characters[_group][_part].expression, function(c) {
return URI.characters[_group][_part].map[c];
});
} catch (e) {
// we're not going to mess with weird encodings,
// give up and return the undecoded original string
// see https://github.com/medialize/URI.js/issues/87
// see https://github.com/medialize/URI.js/issues/92
return string;
}
};
};
for (_part in _parts) {
URI[_part + 'PathSegment'] = generateAccessor('pathname', _parts[_part]);
URI[_part + 'UrnPathSegment'] = generateAccessor('urnpath', _parts[_part]);
}
var generateSegmentedPathFunction = function(_sep, _codingFuncName, _innerCodingFuncName) {
return function(string) {
// Why pass in names of functions, rather than the function objects themselves? The
// definitions of some functions (but in particular, URI.decode) will occasionally change due
// to URI.js having ISO8859 and Unicode modes. Passing in the name and getting it will ensure
// that the functions we use here are "fresh".
var actualCodingFunc;
if (!_innerCodingFuncName) {
actualCodingFunc = URI[_codingFuncName];
} else {
actualCodingFunc = function(string) {
return URI[_codingFuncName](URI[_innerCodingFuncName](string));
};
}
var segments = (string + '').split(_sep);
for (var i = 0, length = segments.length; i < length; i++) {
segments[i] = actualCodingFunc(segments[i]);
}
return segments.join(_sep);
};
};
// This takes place outside the above loop because we don't want, e.g., encodeUrnPath functions.
URI.decodePath = generateSegmentedPathFunction('/', 'decodePathSegment');
URI.decodeUrnPath = generateSegmentedPathFunction(':', 'decodeUrnPathSegment');
URI.recodePath = generateSegmentedPathFunction('/', 'encodePathSegment', 'decode');
URI.recodeUrnPath = generateSegmentedPathFunction(':', 'encodeUrnPathSegment', 'decode');
URI.encodeReserved = generateAccessor('reserved', 'encode');
URI.parse = function(string, parts) {
var pos;
if (!parts) {
parts = {};
}
// [protocol"://"[username[":"password]"@"]hostname[":"port]"/"?][path]["?"querystring]["#"fragment]
// extract fragment
pos = string.indexOf('#');
if (pos > -1) {
// escaping?
parts.fragment = string.substring(pos + 1) || null;
string = string.substring(0, pos);
}
// extract query
pos = string.indexOf('?');
if (pos > -1) {
// escaping?
parts.query = string.substring(pos + 1) || null;
string = string.substring(0, pos);
}
// extract protocol
if (string.substring(0, 2) === '//') {
// relative-scheme
parts.protocol = null;
string = string.substring(2);
// extract "user:pass@host:port"
string = URI.parseAuthority(string, parts);
} else {
pos = string.indexOf(':');
if (pos > -1) {
parts.protocol = string.substring(0, pos) || null;
if (parts.protocol && !parts.protocol.match(URI.protocol_expression)) {
// : may be within the path
parts.protocol = undefined;
} else if (string.substring(pos + 1, pos + 3) === '//') {
string = string.substring(pos + 3);
// extract "user:pass@host:port"
string = URI.parseAuthority(string, parts);
} else {
string = string.substring(pos + 1);
parts.urn = true;
}
}
}
// what's left must be the path
parts.path = string;
// and we're done
return parts;
};
URI.parseHost = function(string, parts) {
// Copy chrome, IE, opera backslash-handling behavior.
// Back slashes before the query string get converted to forward slashes
// See: https://github.com/joyent/node/blob/386fd24f49b0e9d1a8a076592a404168faeecc34/lib/url.js#L115-L124
// See: https://code.google.com/p/chromium/issues/detail?id=25916
// https://github.com/medialize/URI.js/pull/233
string = string.replace(/\\/g, '/');
// extract host:port
var pos = string.indexOf('/');
var bracketPos;
var t;
if (pos === -1) {
pos = string.length;
}
if (string.charAt(0) === '[') {
// IPv6 host - http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-04#section-6
// I claim most client software breaks on IPv6 anyways. To simplify things, URI only accepts
// IPv6+port in the format [2001:db8::1]:80 (for the time being)
bracketPos = string.indexOf(']');
parts.hostname = string.substring(1, bracketPos) || null;
parts.port = string.substring(bracketPos + 2, pos) || null;
if (parts.port === '/') {
parts.port = null;
}
} else {
var firstColon = string.indexOf(':');
var firstSlash = string.indexOf('/');
var nextColon = string.indexOf(':', firstColon + 1);
if (nextColon !== -1 && (firstSlash === -1 || nextColon < firstSlash)) {
// IPv6 host contains multiple colons - but no port
// this notation is actually not allowed by RFC 3986, but we're a liberal parser
parts.hostname = string.substring(0, pos) || null;
parts.port = null;
} else {
t = string.substring(0, pos).split(':');
parts.hostname = t[0] || null;
parts.port = t[1] || null;
}
}
if (parts.hostname && string.substring(pos).charAt(0) !== '/') {
pos++;
string = '/' + string;
}
return string.substring(pos) || '/';
};
URI.parseAuthority = function(string, parts) {
string = URI.parseUserinfo(string, parts);
return URI.parseHost(string, parts);
};
URI.parseUserinfo = function(string, parts) {
// extract username:password
var firstSlash = string.indexOf('/');
var pos = string.lastIndexOf('@', firstSlash > -1 ? firstSlash : string.length - 1);
var t;
// authority@ must come before /path
if (pos > -1 && (firstSlash === -1 || pos < firstSlash)) {
t = string.substring(0, pos).split(':');
parts.username = t[0] ? URI.decode(t[0]) : null;
t.shift();
parts.password = t[0] ? URI.decode(t.join(':')) : null;
string = string.substring(pos + 1);
} else {
parts.username = null;
parts.password = null;
}
return string;
};
URI.parseQuery = function(string, escapeQuerySpace) {
if (!string) {
return {};
}
// throw out the funky business - "?"[name"="value"&"]+
string = string.replace(/&+/g, '&').replace(/^\?*&*|&+$/g, '');
if (!string) {
return {};
}
var items = {};
var splits = string.split('&');
var length = splits.length;
var v, name, value;
for (var i = 0; i < length; i++) {
v = splits[i].split('=');
name = URI.decodeQuery(v.shift(), escapeQuerySpace);
// no "=" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters
value = v.length ? URI.decodeQuery(v.join('='), escapeQuerySpace) : null;
if (hasOwn.call(items, name)) {
if (typeof items[name] === 'string' || items[name] === null) {
items[name] = [items[name]];
}
items[name].push(value);
} else {
items[name] = value;
}
}
return items;
};
URI.build = function(parts) {
var t = '';
if (parts.protocol) {
t += parts.protocol + ':';
}
if (!parts.urn && (t || parts.hostname)) {
t += '//';
}
t += (URI.buildAuthority(parts) || '');
if (typeof parts.path === 'string') {
if (parts.path.charAt(0) !== '/' && typeof parts.hostname === 'string') {
t += '/';
}
t += parts.path;
}
if (typeof parts.query === 'string' && parts.query) {
t += '?' + parts.query;
}
if (typeof parts.fragment === 'string' && parts.fragment) {
t += '#' + parts.fragment;
}
return t;
};
URI.buildHost = function(parts) {
var t = '';
if (!parts.hostname) {
return '';
} else if (URI.ip6_expression.test(parts.hostname)) {
t += '[' + parts.hostname + ']';
} else {
t += parts.hostname;
}
if (parts.port) {
t += ':' + parts.port;
}
return t;
};
URI.buildAuthority = function(parts) {
return URI.buildUserinfo(parts) + URI.buildHost(parts);
};
URI.buildUserinfo = function(parts) {
var t = '';
if (parts.username) {
t += URI.encode(parts.username);
}
if (parts.password) {
t += ':' + URI.encode(parts.password);
}
if (t) {
t += '@';
}
return t;
};
URI.buildQuery = function(data, duplicateQueryParameters, escapeQuerySpace) {
// according to http://tools.ietf.org/html/rfc3986 or http://labs.apache.org/webarch/uri/rfc/rfc3986.html
// being »-._~!$&'()*+,;=:@/?« %HEX and alnum are allowed
// the RFC explicitly states ?/foo being a valid use case, no mention of parameter syntax!
// URI.js treats the query string as being application/x-www-form-urlencoded
// see http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type
var t = '';
var unique, key, i, length;
for (key in data) {
if (hasOwn.call(data, key) && key) {
if (isArray(data[key])) {
unique = {};
for (i = 0, length = data[key].length; i < length; i++) {
if (data[key][i] !== undefined && unique[data[key][i] + ''] === undefined) {
t += '&' + URI.buildQueryParameter(key, data[key][i], escapeQuerySpace);
if (duplicateQueryParameters !== true) {
unique[data[key][i] + ''] = true;
}
}
}
} else if (data[key] !== undefined) {
t += '&' + URI.buildQueryParameter(key, data[key], escapeQuerySpace);
}
}
}
return t.substring(1);
};
URI.buildQueryParameter = function(name, value, escapeQuerySpace) {
// http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type -- application/x-www-form-urlencoded
// don't append "=" for null values, according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#url-parameter-serialization
return URI.encodeQuery(name, escapeQuerySpace) + (value !== null ? '=' + URI.encodeQuery(value, escapeQuerySpace) : '');
};
URI.addQuery = function(data, name, value) {
if (typeof name === 'object') {
for (var key in name) {
if (hasOwn.call(name, key)) {
URI.addQuery(data, key, name[key]);
}
}
} else if (typeof name === 'string') {
if (data[name] === undefined) {
data[name] = value;
return;
} else if (typeof data[name] === 'string') {
data[name] = [data[name]];
}
if (!isArray(value)) {
value = [value];
}
data[name] = (data[name] || []).concat(value);
} else {
throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');
}
};
URI.removeQuery = function(data, name, value) {
var i, length, key;
if (isArray(name)) {
for (i = 0, length = name.length; i < length; i++) {
data[name[i]] = undefined;
}
} else if (getType(name) === 'RegExp') {
for (key in data) {
if (name.test(key)) {
data[key] = undefined;
}
}
} else if (typeof name === 'object') {
for (key in name) {
if (hasOwn.call(name, key)) {
URI.removeQuery(data, key, name[key]);
}
}
} else if (typeof name === 'string') {
if (value !== undefined) {
if (getType(value) === 'RegExp') {
if (!isArray(data[name]) && value.test(data[name])) {
data[name] = undefined;
} else {
data[name] = filterArrayValues(data[name], value);
}
} else if (data[name] === String(value) && (!isArray(value) || value.length === 1)) {
data[name] = undefined;
} else if (isArray(data[name])) {
data[name] = filterArrayValues(data[name], value);
}
} else {
data[name] = undefined;
}
} else {
throw new TypeError('URI.removeQuery() accepts an object, string, RegExp as the first parameter');
}
};
URI.hasQuery = function(data, name, value, withinArray) {
switch (getType(name)) {
case 'String':
// Nothing to do here
break;
case 'RegExp':
for (var key in data) {
if (hasOwn.call(data, key)) {
if (name.test(key) && (value === undefined || URI.hasQuery(data, key, value))) {
return true;
}
}
}
return false;
case 'Object':
for (var _key in name) {
if (hasOwn.call(name, _key)) {
if (!URI.hasQuery(data, _key, name[_key])) {
return false;
}
}
}
return true;
default:
throw new TypeError('URI.hasQuery() accepts a string, regular expression or object as the name parameter');
}
switch (getType(value)) {
case 'Undefined':
// true if exists (but may be empty)
return name in data; // data[name] !== undefined;
case 'Boolean':
// true if exists and non-empty
var _booly = Boolean(isArray(data[name]) ? data[name].length : data[name]);
return value === _booly;
case 'Function':
// allow complex comparison
return !!value(data[name], name, data);
case 'Array':
if (!isArray(data[name])) {
return false;
}
var op = withinArray ? arrayContains : arraysEqual;
return op(data[name], value);
case 'RegExp':
if (!isArray(data[name])) {
return Boolean(data[name] && data[name].match(value));
}
if (!withinArray) {
return false;
}
return arrayContains(data[name], value);
case 'Number':
value = String(value);
/* falls through */
case 'String':
if (!isArray(data[name])) {
return data[name] === value;
}
if (!withinArray) {
return false;
}
return arrayContains(data[name], value);
default:
throw new TypeError('URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter');
}
};
URI.joinPaths = function() {
var input = [];
var segments = [];
var nonEmptySegments = 0;
for (var i = 0; i < arguments.length; i++) {
var url = new URI(arguments[i]);
input.push(url);
var _segments = url.segment();
for (var s = 0; s < _segments.length; s++) {
if (typeof _segments[s] === 'string') {
segments.push(_segments[s]);
}
if (_segments[s]) {
nonEmptySegments++;
}
}
}
if (!segments.length || !nonEmptySegments) {
return new URI('');
}
var uri = new URI('').segment(segments);
if (input[0].path() === '' || input[0].path().slice(0, 1) === '/') {
uri.path('/' + uri.path());
}
return uri.normalize();
};
URI.commonPath = function(one, two) {
var length = Math.min(one.length, two.length);
var pos;
// find first non-matching character
for (pos = 0; pos < length; pos++) {
if (one.charAt(pos) !== two.charAt(pos)) {
pos--;
break;
}
}
if (pos < 1) {
return one.charAt(0) === two.charAt(0) && one.charAt(0) === '/' ? '/' : '';
}
// revert to last /
if (one.charAt(pos) !== '/' || two.charAt(pos) !== '/') {
pos = one.substring(0, pos).lastIndexOf('/');
}
return one.substring(0, pos + 1);
};
URI.withinString = function(string, callback, options) {
options || (options = {});
var _start = options.start || URI.findUri.start;
var _end = options.end || URI.findUri.end;
var _trim = options.trim || URI.findUri.trim;
var _attributeOpen = /[a-z0-9-]=["']?$/i;
_start.lastIndex = 0;
while (true) {
var match = _start.exec(string);
if (!match) {
break;
}
var start = match.index;
if (options.ignoreHtml) {
// attribut(e=["']?$)
var attributeOpen = string.slice(Math.max(start - 3, 0), start);
if (attributeOpen && _attributeOpen.test(attributeOpen)) {
continue;
}
}
var end = start + string.slice(start).search(_end);
var slice = string.slice(start, end).replace(_trim, '');
if (options.ignore && options.ignore.test(slice)) {
continue;
}
end = start + slice.length;
var result = callback(slice, start, end, string);
string = string.slice(0, start) + result + string.slice(end);
_start.lastIndex = start + result.length;
}
_start.lastIndex = 0;
return string;
};
URI.ensureValidHostname = function(v) {
// Theoretically URIs allow percent-encoding in Hostnames (according to RFC 3986)
// they are not part of DNS and therefore ignored by URI.js
if (v.match(URI.invalid_hostname_characters)) {
// test punycode
if (!punycode) {
throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-] and Punycode.js is not available');
}
if (punycode.toASCII(v).match(URI.invalid_hostname_characters)) {
throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-]');
}
}
};
// noConflict
URI.noConflict = function(removeAll) {
if (removeAll) {
var unconflicted = {
URI: this.noConflict()
};
if (root.URITemplate && typeof root.URITemplate.noConflict === 'function') {
unconflicted.URITemplate = root.URITemplate.noConflict();
}
if (root.IPv6 && typeof root.IPv6.noConflict === 'function') {
unconflicted.IPv6 = root.IPv6.noConflict();
}
if (root.SecondLevelDomains && typeof root.SecondLevelDomains.noConflict === 'function') {
unconflicted.SecondLevelDomains = root.SecondLevelDomains.noConflict();
}
return unconflicted;
} else if (root.URI === this) {
root.URI = _URI;
}
return this;
};
p.build = function(deferBuild) {
if (deferBuild === true) {
this._deferred_build = true;
} else if (deferBuild === undefined || this._deferred_build) {
this._string = URI.build(this._parts);
this._deferred_build = false;
}
return this;
};
p.clone = function() {
return new URI(this);
};
p.valueOf = p.toString = function() {
return this.build(false)._string;
};
function generateSimpleAccessor(_part){
return function(v, build) {
if (v === undefined) {
return this._parts[_part] || '';
} else {
this._parts[_part] = v || null;
this.build(!build);
return this;
}
};
}
function generatePrefixAccessor(_part, _key){
return function(v, build) {
if (v === undefined) {
return this._parts[_part] || '';
} else {
if (v !== null) {
v = v + '';
if (v.charAt(0) === _key) {
v = v.substring(1);
}
}
this._parts[_part] = v;
this.build(!build);
return this;
}
};
}
p.protocol = generateSimpleAccessor('protocol');
p.username = generateSimpleAccessor('username');
p.password = generateSimpleAccessor('password');
p.hostname = generateSimpleAccessor('hostname');
p.port = generateSimpleAccessor('port');
p.query = generatePrefixAccessor('query', '?');
p.fragment = generatePrefixAccessor('fragment', '#');
p.search = function(v, build) {
var t = this.query(v, build);
return typeof t === 'string' && t.length ? ('?' + t) : t;
};
p.hash = function(v, build) {
var t = this.fragment(v, build);
return typeof t === 'string' && t.length ? ('#' + t) : t;
};
p.pathname = function(v, build) {
if (v === undefined || v === true) {
var res = this._parts.path || (this._parts.hostname ? '/' : '');
return v ? (this._parts.urn ? URI.decodeUrnPath : URI.decodePath)(res) : res;
} else {
if (this._parts.urn) {
this._parts.path = v ? URI.recodeUrnPath(v) : '';
} else {
this._parts.path = v ? URI.recodePath(v) : '/';
}
this.build(!build);
return this;
}
};
p.path = p.pathname;
p.href = function(href, build) {
var key;
if (href === undefined) {
return this.toString();
}
this._string = '';
this._parts = URI._parts();
var _URI = href instanceof URI;
var _object = typeof href === 'object' && (href.hostname || href.path || href.pathname);
if (href.nodeName) {
var attribute = URI.getDomAttribute(href);
href = href[attribute] || '';
_object = false;
}
// window.location is reported to be an object, but it's not the sort
// of object we're looking for:
// * location.protocol ends with a colon
// * location.query != object.search
// * location.hash != object.fragment
// simply serializing the unknown object should do the trick
// (for location, not for everything...)
if (!_URI && _object && href.pathname !== undefined) {
href = href.toString();
}
if (typeof href === 'string' || href instanceof String) {
this._parts = URI.parse(String(href), this._parts);
} else if (_URI || _object) {
var src = _URI ? href._parts : href;
for (key in src) {
if (hasOwn.call(this._parts, key)) {
this._parts[key] = src[key];
}
}
} else {
throw new TypeError('invalid input');
}
this.build(!build);
return this;
};
// identification accessors
p.is = function(what) {
var ip = false;
var ip4 = false;
var ip6 = false;
var name = false;
var sld = false;
var idn = false;
var punycode = false;
var relative = !this._parts.urn;
if (this._parts.hostname) {
relative = false;
ip4 = URI.ip4_expression.test(this._parts.hostname);
ip6 = URI.ip6_expression.test(this._parts.hostname);
ip = ip4 || ip6;
name = !ip;
sld = name && SLD && SLD.has(this._parts.hostname);
idn = name && URI.idn_expression.test(this._parts.hostname);
punycode = name && URI.punycode_expression.test(this._parts.hostname);
}
switch (what.toLowerCase()) {
case 'relative':
return relative;
case 'absolute':
return !relative;
// hostname identification
case 'domain':
case 'name':
return name;
case 'sld':
return sld;
case 'ip':
return ip;
case 'ip4':
case 'ipv4':
case 'inet4':
return ip4;
case 'ip6':
case 'ipv6':
case 'inet6':
return ip6;
case 'idn':
return idn;
case 'url':
return !this._parts.urn;
case 'urn':
return !!this._parts.urn;
case 'punycode':
return punycode;
}
return null;
};
// component specific input validation
var _protocol = p.protocol;
var _port = p.port;
var _hostname = p.hostname;
p.protocol = function(v, build) {
if (v !== undefined) {
if (v) {
// accept trailing ://
v = v.replace(/:(\/\/)?$/, '');
if (!v.match(URI.protocol_expression)) {
throw new TypeError('Protocol "' + v + '" contains characters other than [A-Z0-9.+-] or doesn\'t start with [A-Z]');
}
}
}
return _protocol.call(this, v, build);
};
p.scheme = p.protocol;
p.port = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v !== undefined) {
if (v === 0) {
v = null;
}
if (v) {
v += '';
if (v.charAt(0) === ':') {
v = v.substring(1);
}
if (v.match(/[^0-9]/)) {
throw new TypeError('Port "' + v + '" contains characters other than [0-9]');
}
}
}
return _port.call(this, v, build);
};
p.hostname = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v !== undefined) {
var x = {};
var res = URI.parseHost(v, x);
if (res !== '/') {
throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-]');
}
v = x.hostname;
}
return _hostname.call(this, v, build);
};
// compound accessors
p.origin = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined) {
var protocol = this.protocol();
var authority = this.authority();
if (!authority) {
return '';
}
return (protocol ? protocol + '://' : '') + this.authority();
} else {
var origin = URI(v);
this
.protocol(origin.protocol())
.authority(origin.authority())
.build(!build);
return this;
}
};
p.host = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined) {
return this._parts.hostname ? URI.buildHost(this._parts) : '';
} else {
var res = URI.parseHost(v, this._parts);
if (res !== '/') {
throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-]');
}
this.build(!build);
return this;
}
};
p.authority = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined) {
return this._parts.hostname ? URI.buildAuthority(this._parts) : '';
} else {
var res = URI.parseAuthority(v, this._parts);
if (res !== '/') {
throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-]');
}
this.build(!build);
return this;
}
};
p.userinfo = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined) {
var t = URI.buildUserinfo(this._parts);
return t ? t.substring(0, t.length -1) : t;
} else {
if (v[v.length-1] !== '@') {
v += '@';
}
URI.parseUserinfo(v, this._parts);
this.build(!build);
return this;
}
};
p.resource = function(v, build) {
var parts;
if (v === undefined) {
return this.path() + this.search() + this.hash();
}
parts = URI.parse(v);
this._parts.path = parts.path;
this._parts.query = parts.query;
this._parts.fragment = parts.fragment;
this.build(!build);
return this;
};
// fraction accessors
p.subdomain = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
// convenience, return "www" from "www.example.org"
if (v === undefined) {
if (!this._parts.hostname || this.is('IP')) {
return '';
}
// grab domain and add another segment
var end = this._parts.hostname.length - this.domain().length - 1;
return this._parts.hostname.substring(0, end) || '';
} else {
var e = this._parts.hostname.length - this.domain().length;
var sub = this._parts.hostname.substring(0, e);
var replace = new RegExp('^' + escapeRegEx(sub));
if (v && v.charAt(v.length - 1) !== '.') {
v += '.';
}
if (v) {
URI.ensureValidHostname(v);
}
this._parts.hostname = this._parts.hostname.replace(replace, v);
this.build(!build);
return this;
}
};
p.domain = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (typeof v === 'boolean') {
build = v;
v = undefined;
}
// convenience, return "example.org" from "www.example.org"
if (v === undefined) {
if (!this._parts.hostname || this.is('IP')) {
return '';
}
// if hostname consists of 1 or 2 segments, it must be the domain
var t = this._parts.hostname.match(/\./g);
if (t && t.length < 2) {
return this._parts.hostname;
}
// grab tld and add another segment
var end = this._parts.hostname.length - this.tld(build).length - 1;
end = this._parts.hostname.lastIndexOf('.', end -1) + 1;
return this._parts.hostname.substring(end) || '';
} else {
if (!v) {
throw new TypeError('cannot set domain empty');
}
URI.ensureValidHostname(v);
if (!this._parts.hostname || this.is('IP')) {
this._parts.hostname = v;
} else {
var replace = new RegExp(escapeRegEx(this.domain()) + '$');
this._parts.hostname = this._parts.hostname.replace(replace, v);
}
this.build(!build);
return this;
}
};
p.tld = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (typeof v === 'boolean') {
build = v;
v = undefined;
}
// return "org" from "www.example.org"
if (v === undefined) {
if (!this._parts.hostname || this.is('IP')) {
return '';
}
var pos = this._parts.hostname.lastIndexOf('.');
var tld = this._parts.hostname.substring(pos + 1);
if (build !== true && SLD && SLD.list[tld.toLowerCase()]) {
return SLD.get(this._parts.hostname) || tld;
}
return tld;
} else {
var replace;
if (!v) {
throw new TypeError('cannot set TLD empty');
} else if (v.match(/[^a-zA-Z0-9-]/)) {
if (SLD && SLD.is(v)) {
replace = new RegExp(escapeRegEx(this.tld()) + '$');
this._parts.hostname = this._parts.hostname.replace(replace, v);
} else {
throw new TypeError('TLD "' + v + '" contains characters other than [A-Z0-9]');
}
} else if (!this._parts.hostname || this.is('IP')) {
throw new ReferenceError('cannot set TLD on non-domain host');
} else {
replace = new RegExp(escapeRegEx(this.tld()) + '$');
this._parts.hostname = this._parts.hostname.replace(replace, v);
}
this.build(!build);
return this;
}
};
p.directory = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined || v === true) {
if (!this._parts.path && !this._parts.hostname) {
return '';
}
if (this._parts.path === '/') {
return '/';
}
var end = this._parts.path.length - this.filename().length - 1;
var res = this._parts.path.substring(0, end) || (this._parts.hostname ? '/' : '');
return v ? URI.decodePath(res) : res;
} else {
var e = this._parts.path.length - this.filename().length;
var directory = this._parts.path.substring(0, e);
var replace = new RegExp('^' + escapeRegEx(directory));
// fully qualifier directories begin with a slash
if (!this.is('relative')) {
if (!v) {
v = '/';
}
if (v.charAt(0) !== '/') {
v = '/' + v;
}
}
// directories always end with a slash
if (v && v.charAt(v.length - 1) !== '/') {
v += '/';
}
v = URI.recodePath(v);
this._parts.path = this._parts.path.replace(replace, v);
this.build(!build);
return this;
}
};
p.filename = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined || v === true) {
if (!this._parts.path || this._parts.path === '/') {
return '';
}
var pos = this._parts.path.lastIndexOf('/');
var res = this._parts.path.substring(pos+1);
return v ? URI.decodePathSegment(res) : res;
} else {
var mutatedDirectory = false;
if (v.charAt(0) === '/') {
v = v.substring(1);
}
if (v.match(/\.?\//)) {
mutatedDirectory = true;
}
var replace = new RegExp(escapeRegEx(this.filename()) + '$');
v = URI.recodePath(v);
this._parts.path = this._parts.path.replace(replace, v);
if (mutatedDirectory) {
this.normalizePath(build);
} else {
this.build(!build);
}
return this;
}
};
p.suffix = function(v, build) {
if (this._parts.urn) {
return v === undefined ? '' : this;
}
if (v === undefined || v === true) {
if (!this._parts.path || this._parts.path === '/') {
return '';
}
var filename = this.filename();
var pos = filename.lastIndexOf('.');
var s, res;
if (pos === -1) {
return '';
}
// suffix may only contain alnum characters (yup, I made this up.)
s = filename.substring(pos+1);
res = (/^[a-z0-9%]+$/i).test(s) ? s : '';
return v ? URI.decodePathSegment(res) : res;
} else {
if (v.charAt(0) === '.') {
v = v.substring(1);
}
var suffix = this.suffix();
var replace;
if (!suffix) {
if (!v) {
return this;
}
this._parts.path += '.' + URI.recodePath(v);
} else if (!v) {
replace = new RegExp(escapeRegEx('.' + suffix) + '$');
} else {
replace = new RegExp(escapeRegEx(suffix) + '$');
}
if (replace) {
v = URI.recodePath(v);
this._parts.path = this._parts.path.replace(replace, v);
}
this.build(!build);
return this;
}
};
p.segment = function(segment, v, build) {
var separator = this._parts.urn ? ':' : '/';
var path = this.path();
var absolute = path.substring(0, 1) === '/';
var segments = path.split(separator);
if (segment !== undefined && typeof segment !== 'number') {
build = v;
v = segment;
segment = undefined;
}
if (segment !== undefined && typeof segment !== 'number') {
throw new Error('Bad segment "' + segment + '", must be 0-based integer');
}
if (absolute) {
segments.shift();
}
if (segment < 0) {
// allow negative indexes to address from the end
segment = Math.max(segments.length + segment, 0);
}
if (v === undefined) {
/*jshint laxbreak: true */
return segment === undefined
? segments
: segments[segment];
/*jshint laxbreak: false */
} else if (segment === null || segments[segment] === undefined) {
if (isArray(v)) {
segments = [];
// collapse empty elements within array
for (var i=0, l=v.length; i < l; i++) {
if (!v[i].length && (!segments.length || !segments[segments.length -1].length)) {
continue;
}
if (segments.length && !segments[segments.length -1].length) {
segments.pop();
}
segments.push(trimSlashes(v[i]));
}
} else if (v || typeof v === 'string') {
v = trimSlashes(v);
if (segments[segments.length -1] === '') {
// empty trailing elements have to be overwritten
// to prevent results such as /foo//bar
segments[segments.length -1] = v;
} else {
segments.push(v);
}
}
} else {
if (v) {
segments[segment] = trimSlashes(v);
} else {
segments.splice(segment, 1);
}
}
if (absolute) {
segments.unshift('');
}
return this.path(segments.join(separator), build);
};
p.segmentCoded = function(segment, v, build) {
var segments, i, l;
if (typeof segment !== 'number') {
build = v;
v = segment;
segment = undefined;
}
if (v === undefined) {
segments = this.segment(segment, v, build);
if (!isArray(segments)) {
segments = segments !== undefined ? URI.decode(segments) : undefined;
} else {
for (i = 0, l = segments.length; i < l; i++) {
segments[i] = URI.decode(segments[i]);
}
}
return segments;
}
if (!isArray(v)) {
v = (typeof v === 'string' || v instanceof String) ? URI.encode(v) : v;
} else {
for (i = 0, l = v.length; i < l; i++) {
v[i] = URI.encode(v[i]);
}
}
return this.segment(segment, v, build);
};
// mutating query string
var q = p.query;
p.query = function(v, build) {
if (v === true) {
return URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
} else if (typeof v === 'function') {
var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
var result = v.call(this, data);
this._parts.query = URI.buildQuery(result || data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
this.build(!build);
return this;
} else if (v !== undefined && typeof v !== 'string') {
this._parts.query = URI.buildQuery(v, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
this.build(!build);
return this;
} else {
return q.call(this, v, build);
}
};
p.setQuery = function(name, value, build) {
var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
if (typeof name === 'string' || name instanceof String) {
data[name] = value !== undefined ? value : null;
} else if (typeof name === 'object') {
for (var key in name) {
if (hasOwn.call(name, key)) {
data[key] = name[key];
}
}
} else {
throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');
}
this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
if (typeof name !== 'string') {
build = value;
}
this.build(!build);
return this;
};
p.addQuery = function(name, value, build) {
var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
URI.addQuery(data, name, value === undefined ? null : value);
this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
if (typeof name !== 'string') {
build = value;
}
this.build(!build);
return this;
};
p.removeQuery = function(name, value, build) {
var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
URI.removeQuery(data, name, value);
this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);
if (typeof name !== 'string') {
build = value;
}
this.build(!build);
return this;
};
p.hasQuery = function(name, value, withinArray) {
var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
return URI.hasQuery(data, name, value, withinArray);
};
p.setSearch = p.setQuery;
p.addSearch = p.addQuery;
p.removeSearch = p.removeQuery;
p.hasSearch = p.hasQuery;
// sanitizing URLs
p.normalize = function() {
if (this._parts.urn) {
return this
.normalizeProtocol(false)
.normalizePath(false)
.normalizeQuery(false)
.normalizeFragment(false)
.build();
}
return this
.normalizeProtocol(false)
.normalizeHostname(false)
.normalizePort(false)
.normalizePath(false)
.normalizeQuery(false)
.normalizeFragment(false)
.build();
};
p.normalizeProtocol = function(build) {
if (typeof this._parts.protocol === 'string') {
this._parts.protocol = this._parts.protocol.toLowerCase();
this.build(!build);
}
return this;
};
p.normalizeHostname = function(build) {
if (this._parts.hostname) {
if (this.is('IDN') && punycode) {
this._parts.hostname = punycode.toASCII(this._parts.hostname);
} else if (this.is('IPv6') && IPv6) {
this._parts.hostname = IPv6.best(this._parts.hostname);
}
this._parts.hostname = this._parts.hostname.toLowerCase();
this.build(!build);
}
return this;
};
p.normalizePort = function(build) {
// remove port of it's the protocol's default
if (typeof this._parts.protocol === 'string' && this._parts.port === URI.defaultPorts[this._parts.protocol]) {
this._parts.port = null;
this.build(!build);
}
return this;
};
p.normalizePath = function(build) {
var _path = this._parts.path;
if (!_path) {
return this;
}
if (this._parts.urn) {
this._parts.path = URI.recodeUrnPath(this._parts.path);
this.build(!build);
return this;
}
if (this._parts.path === '/') {
return this;
}
_path = URI.recodePath(_path);
var _was_relative;
var _leadingParents = '';
var _parent, _pos;
// handle relative paths
if (_path.charAt(0) !== '/') {
_was_relative = true;
_path = '/' + _path;
}
// handle relative files (as opposed to directories)
if (_path.slice(-3) === '/..' || _path.slice(-2) === '/.') {
_path += '/';
}
// resolve simples
_path = _path
.replace(/(\/(\.\/)+)|(\/\.$)/g, '/')
.replace(/\/{2,}/g, '/');
// remember leading parents
if (_was_relative) {
_leadingParents = _path.substring(1).match(/^(\.\.\/)+/) || '';
if (_leadingParents) {
_leadingParents = _leadingParents[0];
}
}
// resolve parents
while (true) {
_parent = _path.search(/\/\.\.(\/|$)/);
if (_parent === -1) {
// no more ../ to resolve
break;
} else if (_parent === 0) {
// top level cannot be relative, skip it
_path = _path.substring(3);
continue;
}
_pos = _path.substring(0, _parent).lastIndexOf('/');
if (_pos === -1) {
_pos = _parent;
}
_path = _path.substring(0, _pos) + _path.substring(_parent + 3);
}
// revert to relative
if (_was_relative && this.is('relative')) {
_path = _leadingParents + _path.substring(1);
}
this._parts.path = _path;
this.build(!build);
return this;
};
p.normalizePathname = p.normalizePath;
p.normalizeQuery = function(build) {
if (typeof this._parts.query === 'string') {
if (!this._parts.query.length) {
this._parts.query = null;
} else {
this.query(URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace));
}
this.build(!build);
}
return this;
};
p.normalizeFragment = function(build) {
if (!this._parts.fragment) {
this._parts.fragment = null;
this.build(!build);
}
return this;
};
p.normalizeSearch = p.normalizeQuery;
p.normalizeHash = p.normalizeFragment;
p.iso8859 = function() {
// expect unicode input, iso8859 output
var e = URI.encode;
var d = URI.decode;
URI.encode = escape;
URI.decode = decodeURIComponent;
try {
this.normalize();
} finally {
URI.encode = e;
URI.decode = d;
}
return this;
};
p.unicode = function() {
// expect iso8859 input, unicode output
var e = URI.encode;
var d = URI.decode;
URI.encode = strictEncodeURIComponent;
URI.decode = unescape;
try {
this.normalize();
} finally {
URI.encode = e;
URI.decode = d;
}
return this;
};
p.readable = function() {
var uri = this.clone();
// removing username, password, because they shouldn't be displayed according to RFC 3986
uri.username('').password('').normalize();
var t = '';
if (uri._parts.protocol) {
t += uri._parts.protocol + '://';
}
if (uri._parts.hostname) {
if (uri.is('punycode') && punycode) {
t += punycode.toUnicode(uri._parts.hostname);
if (uri._parts.port) {
t += ':' + uri._parts.port;
}
} else {
t += uri.host();
}
}
if (uri._parts.hostname && uri._parts.path && uri._parts.path.charAt(0) !== '/') {
t += '/';
}
t += uri.path(true);
if (uri._parts.query) {
var q = '';
for (var i = 0, qp = uri._parts.query.split('&'), l = qp.length; i < l; i++) {
var kv = (qp[i] || '').split('=');
q += '&' + URI.decodeQuery(kv[0], this._parts.escapeQuerySpace)
.replace(/&/g, '%26');
if (kv[1] !== undefined) {
q += '=' + URI.decodeQuery(kv[1], this._parts.escapeQuerySpace)
.replace(/&/g, '%26');
}
}
t += '?' + q.substring(1);
}
t += URI.decodeQuery(uri.hash(), true);
return t;
};
// resolving relative and absolute URLs
p.absoluteTo = function(base) {
var resolved = this.clone();
var properties = ['protocol', 'username', 'password', 'hostname', 'port'];
var basedir, i, p;
if (this._parts.urn) {
throw new Error('URNs do not have any generally defined hierarchical components');
}
if (!(base instanceof URI)) {
base = new URI(base);
}
if (!resolved._parts.protocol) {
resolved._parts.protocol = base._parts.protocol;
}
if (this._parts.hostname) {
return resolved;
}
for (i = 0; (p = properties[i]); i++) {
resolved._parts[p] = base._parts[p];
}
if (!resolved._parts.path) {
resolved._parts.path = base._parts.path;
if (!resolved._parts.query) {
resolved._parts.query = base._parts.query;
}
} else if (resolved._parts.path.substring(-2) === '..') {
resolved._parts.path += '/';
}
if (resolved.path().charAt(0) !== '/') {
basedir = base.directory();
basedir = basedir ? basedir : base.path().indexOf('/') === 0 ? '/' : '';
resolved._parts.path = (basedir ? (basedir + '/') : '') + resolved._parts.path;
resolved.normalizePath();
}
resolved.build();
return resolved;
};
p.relativeTo = function(base) {
var relative = this.clone().normalize();
var relativeParts, baseParts, common, relativePath, basePath;
if (relative._parts.urn) {
throw new Error('URNs do not have any generally defined hierarchical components');
}
base = new URI(base).normalize();
relativeParts = relative._parts;
baseParts = base._parts;
relativePath = relative.path();
basePath = base.path();
if (relativePath.charAt(0) !== '/') {
throw new Error('URI is already relative');
}
if (basePath.charAt(0) !== '/') {
throw new Error('Cannot calculate a URI relative to another relative URI');
}
if (relativeParts.protocol === baseParts.protocol) {
relativeParts.protocol = null;
}
if (relativeParts.username !== baseParts.username || relativeParts.password !== baseParts.password) {
return relative.build();
}
if (relativeParts.protocol !== null || relativeParts.username !== null || relativeParts.password !== null) {
return relative.build();
}
if (relativeParts.hostname === baseParts.hostname && relativeParts.port === baseParts.port) {
relativeParts.hostname = null;
relativeParts.port = null;
} else {
return relative.build();
}
if (relativePath === basePath) {
relativeParts.path = '';
return relative.build();
}
// determine common sub path
common = URI.commonPath(relativePath, basePath);
// If the paths have nothing in common, return a relative URL with the absolute path.
if (!common) {
return relative.build();
}
var parents = baseParts.path
.substring(common.length)
.replace(/[^\/]*$/, '')
.replace(/.*?\//g, '../');
relativeParts.path = (parents + relativeParts.path.substring(common.length)) || './';
return relative.build();
};
// comparing URIs
p.equals = function(uri) {
var one = this.clone();
var two = new URI(uri);
var one_map = {};
var two_map = {};
var checked = {};
var one_query, two_query, key;
one.normalize();
two.normalize();
// exact match
if (one.toString() === two.toString()) {
return true;
}
// extract query string
one_query = one.query();
two_query = two.query();
one.query('');
two.query('');
// definitely not equal if not even non-query parts match
if (one.toString() !== two.toString()) {
return false;
}
// query parameters have the same length, even if they're permuted
if (one_query.length !== two_query.length) {
return false;
}
one_map = URI.parseQuery(one_query, this._parts.escapeQuerySpace);
two_map = URI.parseQuery(two_query, this._parts.escapeQuerySpace);
for (key in one_map) {
if (hasOwn.call(one_map, key)) {
if (!isArray(one_map[key])) {
if (one_map[key] !== two_map[key]) {
return false;
}
} else if (!arraysEqual(one_map[key], two_map[key])) {
return false;
}
checked[key] = true;
}
}
for (key in two_map) {
if (hasOwn.call(two_map, key)) {
if (!checked[key]) {
// two contains a parameter not present in one
return false;
}
}
}
return true;
};
// state
p.duplicateQueryParameters = function(v) {
this._parts.duplicateQueryParameters = !!v;
return this;
};
p.escapeQuerySpace = function(v) {
this._parts.escapeQuerySpace = !!v;
return this;
};
return URI;
}));
/*!
CSSLint v1.0.3
Copyright (c) 2016 Nicole Sullivan and Nicholas C. Zakas. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var CSSLint=function(){var e,t=t||{},r=(e=function t(r,n,i){function o(s,l){if(!n[s]){if(!r[s]){var c="function"==typeof e&&e;if(!l&&c)return c(s,!0);if(a)return a(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var d=n[s]={exports:{}};r[s][0].call(d.exports,(function(e){var t=r[s][1][e];return o(t||e)}),d,d.exports,t,r,n,i)}return n[s].exports}for(var a="function"==typeof e&&e,s=0;s<i.length;s++)o(i[s]);return o}({1:[function(e,t,r){"use strict";t.exports={__proto__:null,aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgrey:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32",currentColor:"The value of the 'color' property.",activeBorder:"Active window border.",activecaption:"Active window caption.",appworkspace:"Background color of multiple document interface.",background:"Desktop background.",buttonface:"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",buttonhighlight:"The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",buttonshadow:"The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",buttontext:"Text on push buttons.",captiontext:"Text in caption, size box, and scrollbar arrow box.",graytext:"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",greytext:"Greyed (disabled) text. This color is set to #000 if the current display driver does not support a solid grey color.",highlight:"Item(s) selected in a control.",highlighttext:"Text of item(s) selected in a control.",inactiveborder:"Inactive window border.",inactivecaption:"Inactive window caption.",inactivecaptiontext:"Color of text in an inactive caption.",infobackground:"Background color for tooltip controls.",infotext:"Text color for tooltip controls.",menu:"Menu background.",menutext:"Text in menus.",scrollbar:"Scroll bar gray area.",threeddarkshadow:"The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",threedface:"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",threedhighlight:"The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",threedlightshadow:"The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",threedshadow:"The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",window:"Window background.",windowframe:"Window frame.",windowtext:"Text in windows."}},{}],2:[function(e,t,r){"use strict";t.exports=o;var n=e("../util/SyntaxUnit"),i=e("./Parser");function o(e,t,r){n.call(this,e,t,r,i.COMBINATOR_TYPE),this.type="unknown",/^\s+$/.test(e)?this.type="descendant":">"===e?this.type="child":"+"===e?this.type="adjacent-sibling":"~"===e&&(this.type="sibling")}o.prototype=new n,o.prototype.constructor=o},{"../util/SyntaxUnit":26,"./Parser":6}],3:[function(e,t,r){"use strict";t.exports=o;var n=e("../util/StringReader"),i=e("../util/SyntaxError");function o(e,t){this.match=function(t){var r;return t.mark(),(r=e(t))?t.drop():t.restore(),r},this.toString="function"==typeof t?t:function(){return t}}o.prec={MOD:5,SEQ:4,ANDAND:3,OROR:2,ALT:1},o.parse=function(e){var t,r,a,s,l,c,u,d,h;if(t=new n(e),r=function(e){var r=t.readMatch(e);if(null===r)throw new i("Expected "+e,t.getLine(),t.getCol());return r},a=function(){for(var e=[s()];null!==t.readMatch(" | ");)e.push(s());return 1===e.length?e[0]:o.alt.apply(o,e)},s=function(){for(var e=[l()];null!==t.readMatch(" || ");)e.push(l());return 1===e.length?e[0]:o.oror.apply(o,e)},l=function(){for(var e=[c()];null!==t.readMatch(" && ");)e.push(c());return 1===e.length?e[0]:o.andand.apply(o,e)},c=function(){for(var e=[u()];null!==t.readMatch(/^ (?![&|\]])/);)e.push(u());return 1===e.length?e[0]:o.seq.apply(o,e)},u=function(){var e=d();if(null!==t.readMatch("?"))return e.question();if(null!==t.readMatch("*"))return e.star();if(null!==t.readMatch("+"))return e.plus();if(null!==t.readMatch("#"))return e.hash();if(null!==t.readMatch(/^\{\s*/)){var n=r(/^\d+/);r(/^\s*,\s*/);var i=r(/^\d+/);return r(/^\s*\}/),e.braces(+n,+i)}return e},d=function(){if(null!==t.readMatch("[ ")){var e=a();return r(" ]"),e}return o.fromType(r(/^[^ ?*+#{]+/))},h=a(),!t.eof())throw new i("Expected end of string",t.getLine(),t.getCol());return h},o.cast=function(e){return e instanceof o?e:o.parse(e)},o.fromType=function(t){var r=e("./ValidationTypes");return new o((function(e){return e.hasNext()&&r.isType(e,t)}),t)},o.seq=function(){var e=Array.prototype.slice.call(arguments).map(o.cast);return 1===e.length?e[0]:new o((function(t){var r,n=!0;for(r=0;n&&r<e.length;r++)n=e[r].match(t);return n}),(function(t){var r=o.prec.SEQ,n=e.map((function(e){return e.toString(r)})).join(" ");return t>r&&(n="[ "+n+" ]"),n}))},o.alt=function(){var e=Array.prototype.slice.call(arguments).map(o.cast);return 1===e.length?e[0]:new o((function(t){var r,n=!1;for(r=0;!n&&r<e.length;r++)n=e[r].match(t);return n}),(function(t){var r=o.prec.ALT,n=e.map((function(e){return e.toString(r)})).join(" | ");return t>r&&(n="[ "+n+" ]"),n}))},o.many=function(t){var r=Array.prototype.slice.call(arguments,1).reduce((function(t,r){if(r.expand){var n=e("./ValidationTypes");t.push.apply(t,n.complex[r.expand].options)}else t.push(o.cast(r));return t}),[]);!0===t&&(t=r.map((function(){return!0})));var n=new o((function(e){var n=[],i=0,o=0,a=function(s){for(var l=0;l<r.length;l++)if(!n[l])if(e.mark(),r[l].match(e)){if(n[l]=!0,a(s+(!1===t||t[l]?1:0)))return e.drop(),!0;e.restore(),n[l]=!1}else e.drop();return function(e){return 0===o?(i=Math.max(e,i),e===r.length):e===i}(s)};if(a(0)||(o++,a(0)),!1===t)return i>0;for(var s=0;s<r.length;s++)if(t[s]&&!n[s])return!1;return!0}),(function(e){var n=!1===t?o.prec.OROR:o.prec.ANDAND,i=r.map((function(e,r){return!1===t||t[r]?e.toString(n):e.toString(o.prec.MOD)+"?"})).join(!1===t?" || ":" && ");return e>n&&(i="[ "+i+" ]"),i}));return n.options=r,n},o.andand=function(){var e=Array.prototype.slice.call(arguments);return e.unshift(!0),o.many.apply(o,e)},o.oror=function(){var e=Array.prototype.slice.call(arguments);return e.unshift(!1),o.many.apply(o,e)},o.prototype={constructor:o,match:function(){throw new Error("unimplemented")},toString:function(){throw new Error("unimplemented")},func:function(){return this.match.bind(this)},then:function(e){return o.seq(this,e)},or:function(e){return o.alt(this,e)},andand:function(e){return o.many(!0,this,e)},oror:function(e){return o.many(!1,this,e)},star:function(){return this.braces(0,1/0,"*")},plus:function(){return this.braces(1,1/0,"+")},question:function(){return this.braces(0,1,"?")},hash:function(){return this.braces(1,1/0,"#",o.cast(","))},braces:function(e,t,r,n){var i=this,a=n?n.then(this):this;return r||(r="{"+e+","+t+"}"),new o((function(r){var o;for(o=0;o<t&&(o>0&&n?a.match(r):i.match(r));o++);return o>=e}),(function(){return i.toString(o.prec.MOD)+r}))}}},{"../util/StringReader":24,"../util/SyntaxError":25,"./ValidationTypes":21}],4:[function(e,t,r){"use strict";t.exports=o;var n=e("../util/SyntaxUnit"),i=e("./Parser");function o(e,t){n.call(this,"("+e+(null!==t?":"+t:"")+")",e.startLine,e.startCol,i.MEDIA_FEATURE_TYPE),this.name=e,this.value=t}o.prototype=new n,o.prototype.constructor=o},{"../util/SyntaxUnit":26,"./Parser":6}],5:[function(e,t,r){"use strict";t.exports=o;var n=e("../util/SyntaxUnit"),i=e("./Parser");function o(e,t,r,o,a){n.call(this,(e?e+" ":"")+(t||"")+(t&&r.length>0?" and ":"")+r.join(" and "),o,a,i.MEDIA_QUERY_TYPE),this.modifier=e,this.mediaType=t,this.features=r}o.prototype=new n,o.prototype.constructor=o},{"../util/SyntaxUnit":26,"./Parser":6}],6:[function(e,t,r){"use strict";t.exports=k;var n=e("../util/EventTarget"),i=e("../util/SyntaxError"),o=e("../util/SyntaxUnit"),a=e("./Combinator"),s=e("./MediaFeature"),l=e("./MediaQuery"),c=e("./PropertyName"),u=e("./PropertyValue"),d=e("./PropertyValuePart"),h=e("./Selector"),p=e("./SelectorPart"),f=e("./SelectorSubPart"),m=e("./TokenStream"),g=e("./Tokens"),b=e("./Validation");function k(e){n.call(this),this.options=e||{},this._tokenStream=null}k.DEFAULT_TYPE=0,k.COMBINATOR_TYPE=1,k.MEDIA_FEATURE_TYPE=2,k.MEDIA_QUERY_TYPE=3,k.PROPERTY_NAME_TYPE=4,k.PROPERTY_VALUE_TYPE=5,k.PROPERTY_VALUE_PART_TYPE=6,k.SELECTOR_TYPE=7,k.SELECTOR_PART_TYPE=8,k.SELECTOR_SUB_PART_TYPE=9,k.prototype=function(){var e,t=new n,r={__proto__:null,constructor:k,DEFAULT_TYPE:0,COMBINATOR_TYPE:1,MEDIA_FEATURE_TYPE:2,MEDIA_QUERY_TYPE:3,PROPERTY_NAME_TYPE:4,PROPERTY_VALUE_TYPE:5,PROPERTY_VALUE_PART_TYPE:6,SELECTOR_TYPE:7,SELECTOR_PART_TYPE:8,SELECTOR_SUB_PART_TYPE:9,_stylesheet:function(){var e,t,r,n=this._tokenStream;for(this.fire("startstylesheet"),this._charset(),this._skipCruft();n.peek()===g.IMPORT_SYM;)this._import(),this._skipCruft();for(;n.peek()===g.NAMESPACE_SYM;)this._namespace(),this._skipCruft();for(r=n.peek();r>g.EOF;){try{switch(r){case g.MEDIA_SYM:this._media(),this._skipCruft();break;case g.PAGE_SYM:this._page(),this._skipCruft();break;case g.FONT_FACE_SYM:this._font_face(),this._skipCruft();break;case g.KEYFRAMES_SYM:this._keyframes(),this._skipCruft();break;case g.VIEWPORT_SYM:this._viewport(),this._skipCruft();break;case g.DOCUMENT_SYM:this._document(),this._skipCruft();break;case g.SUPPORTS_SYM:this._supports(),this._skipCruft();break;case g.UNKNOWN_SYM:if(n.get(),this.options.strict)throw new i("Unknown @ rule.",n.LT(0).startLine,n.LT(0).startCol);for(this.fire({type:"error",error:null,message:"Unknown @ rule: "+n.LT(0).value+".",line:n.LT(0).startLine,col:n.LT(0).startCol}),e=0;n.advance([g.LBRACE,g.RBRACE])===g.LBRACE;)e++;for(;e;)n.advance([g.RBRACE]),e--;break;case g.S:this._readWhitespace();break;default:if(!this._ruleset())switch(r){case g.CHARSET_SYM:throw t=n.LT(1),this._charset(!1),new i("@charset not allowed here.",t.startLine,t.startCol);case g.IMPORT_SYM:throw t=n.LT(1),this._import(!1),new i("@import not allowed here.",t.startLine,t.startCol);case g.NAMESPACE_SYM:throw t=n.LT(1),this._namespace(!1),new i("@namespace not allowed here.",t.startLine,t.startCol);default:n.get(),this._unexpectedToken(n.token())}}}catch(e){if(!(e instanceof i)||this.options.strict)throw e;this.fire({type:"error",error:e,message:e.message,line:e.line,col:e.col})}r=n.peek()}r!==g.EOF&&this._unexpectedToken(n.token()),this.fire("endstylesheet")},_charset:function(e){var t,r,n,i=this._tokenStream;i.match(g.CHARSET_SYM)&&(r=i.token().startLine,n=i.token().startCol,this._readWhitespace(),i.mustMatch(g.STRING),t=i.token().value,this._readWhitespace(),i.mustMatch(g.SEMICOLON),!1!==e&&this.fire({type:"charset",charset:t,line:r,col:n}))},_import:function(e){var t,r,n,i=this._tokenStream;i.mustMatch(g.IMPORT_SYM),r=i.token(),this._readWhitespace(),i.mustMatch([g.STRING,g.URI]),t=i.token().value.replace(/^(?:url\()?["']?([^"']+?)["']?\)?$/,"$1"),this._readWhitespace(),n=this._media_query_list(),i.mustMatch(g.SEMICOLON),this._readWhitespace(),!1!==e&&this.fire({type:"import",uri:t,media:n,line:r.startLine,col:r.startCol})},_namespace:function(e){var t,r,n,i,o=this._tokenStream;o.mustMatch(g.NAMESPACE_SYM),t=o.token().startLine,r=o.token().startCol,this._readWhitespace(),o.match(g.IDENT)&&(n=o.token().value,this._readWhitespace()),o.mustMatch([g.STRING,g.URI]),i=o.token().value.replace(/(?:url\()?["']([^"']+)["']\)?/,"$1"),this._readWhitespace(),o.mustMatch(g.SEMICOLON),this._readWhitespace(),!1!==e&&this.fire({type:"namespace",prefix:n,uri:i,line:t,col:r})},_supports:function(e){var t,r,n=this._tokenStream;if(n.match(g.SUPPORTS_SYM)){for(t=n.token().startLine,r=n.token().startCol,this._readWhitespace(),this._supports_condition(),this._readWhitespace(),n.mustMatch(g.LBRACE),this._readWhitespace(),!1!==e&&this.fire({type:"startsupports",line:t,col:r});this._ruleset(););n.mustMatch(g.RBRACE),this._readWhitespace(),this.fire({type:"endsupports",line:t,col:r})}},_supports_condition:function(){var e,t=this._tokenStream;if(t.match(g.IDENT))"not"===(e=t.token().value.toLowerCase())?(t.mustMatch(g.S),this._supports_condition_in_parens()):t.unget();else for(this._supports_condition_in_parens(),this._readWhitespace();t.peek()===g.IDENT;)"and"!==(e=t.LT(1).value.toLowerCase())&&"or"!==e||(t.mustMatch(g.IDENT),this._readWhitespace(),this._supports_condition_in_parens(),this._readWhitespace())},_supports_condition_in_parens:function(){var e=this._tokenStream;e.match(g.LPAREN)?(this._readWhitespace(),e.match(g.IDENT)?"not"===e.token().value.toLowerCase()?(this._readWhitespace(),this._supports_condition(),this._readWhitespace(),e.mustMatch(g.RPAREN)):(e.unget(),this._supports_declaration_condition(!1)):(this._supports_condition(),this._readWhitespace(),e.mustMatch(g.RPAREN))):this._supports_declaration_condition()},_supports_declaration_condition:function(e){var t=this._tokenStream;!1!==e&&t.mustMatch(g.LPAREN),this._readWhitespace(),this._declaration(),t.mustMatch(g.RPAREN)},_media:function(){var e,t,r,n=this._tokenStream;for(n.mustMatch(g.MEDIA_SYM),e=n.token().startLine,t=n.token().startCol,this._readWhitespace(),r=this._media_query_list(),n.mustMatch(g.LBRACE),this._readWhitespace(),this.fire({type:"startmedia",media:r,line:e,col:t});;)if(n.peek()===g.PAGE_SYM)this._page();else if(n.peek()===g.FONT_FACE_SYM)this._font_face();else if(n.peek()===g.VIEWPORT_SYM)this._viewport();else if(n.peek()===g.DOCUMENT_SYM)this._document();else if(n.peek()===g.SUPPORTS_SYM)this._supports();else if(!this._ruleset())break;n.mustMatch(g.RBRACE),this._readWhitespace(),this.fire({type:"endmedia",media:r,line:e,col:t})},_media_query_list:function(){var e=this._tokenStream,t=[];for(this._readWhitespace(),e.peek()!==g.IDENT&&e.peek()!==g.LPAREN||t.push(this._media_query());e.match(g.COMMA);)this._readWhitespace(),t.push(this._media_query());return t},_media_query:function(){var e=this._tokenStream,t=null,r=null,n=null,i=[];if(e.match(g.IDENT)&&("only"!==(r=e.token().value.toLowerCase())&&"not"!==r?(e.unget(),r=null):n=e.token()),this._readWhitespace(),e.peek()===g.IDENT?(t=this._media_type(),null===n&&(n=e.token())):e.peek()===g.LPAREN&&(null===n&&(n=e.LT(1)),i.push(this._media_expression())),null===t&&0===i.length)return null;for(this._readWhitespace();e.match(g.IDENT);)"and"!==e.token().value.toLowerCase()&&this._unexpectedToken(e.token()),this._readWhitespace(),i.push(this._media_expression());return new l(r,t,i,n.startLine,n.startCol)},_media_type:function(){return this._media_feature()},_media_expression:function(){var e,t,r=this._tokenStream,n=null;return r.mustMatch(g.LPAREN),e=this._media_feature(),this._readWhitespace(),r.match(g.COLON)&&(this._readWhitespace(),t=r.LT(1),n=this._expression()),r.mustMatch(g.RPAREN),this._readWhitespace(),new s(e,n?new o(n,t.startLine,t.startCol):null)},_media_feature:function(){var e=this._tokenStream;return this._readWhitespace(),e.mustMatch(g.IDENT),o.fromToken(e.token())},_page:function(){var e,t,r=this._tokenStream,n=null,i=null;r.mustMatch(g.PAGE_SYM),e=r.token().startLine,t=r.token().startCol,this._readWhitespace(),r.match(g.IDENT)&&"auto"===(n=r.token().value).toLowerCase()&&this._unexpectedToken(r.token()),r.peek()===g.COLON&&(i=this._pseudo_page()),this._readWhitespace(),this.fire({type:"startpage",id:n,pseudo:i,line:e,col:t}),this._readDeclarations(!0,!0),this.fire({type:"endpage",id:n,pseudo:i,line:e,col:t})},_margin:function(){var e,t,r=this._tokenStream,n=this._margin_sym();return!!n&&(e=r.token().startLine,t=r.token().startCol,this.fire({type:"startpagemargin",margin:n,line:e,col:t}),this._readDeclarations(!0),this.fire({type:"endpagemargin",margin:n,line:e,col:t}),!0)},_margin_sym:function(){var e=this._tokenStream;return e.match([g.TOPLEFTCORNER_SYM,g.TOPLEFT_SYM,g.TOPCENTER_SYM,g.TOPRIGHT_SYM,g.TOPRIGHTCORNER_SYM,g.BOTTOMLEFTCORNER_SYM,g.BOTTOMLEFT_SYM,g.BOTTOMCENTER_SYM,g.BOTTOMRIGHT_SYM,g.BOTTOMRIGHTCORNER_SYM,g.LEFTTOP_SYM,g.LEFTMIDDLE_SYM,g.LEFTBOTTOM_SYM,g.RIGHTTOP_SYM,g.RIGHTMIDDLE_SYM,g.RIGHTBOTTOM_SYM])?o.fromToken(e.token()):null},_pseudo_page:function(){var e=this._tokenStream;return e.mustMatch(g.COLON),e.mustMatch(g.IDENT),e.token().value},_font_face:function(){var e,t,r=this._tokenStream;r.mustMatch(g.FONT_FACE_SYM),e=r.token().startLine,t=r.token().startCol,this._readWhitespace(),this.fire({type:"startfontface",line:e,col:t}),this._readDeclarations(!0),this.fire({type:"endfontface",line:e,col:t})},_viewport:function(){var e,t,r=this._tokenStream;r.mustMatch(g.VIEWPORT_SYM),e=r.token().startLine,t=r.token().startCol,this._readWhitespace(),this.fire({type:"startviewport",line:e,col:t}),this._readDeclarations(!0),this.fire({type:"endviewport",line:e,col:t})},_document:function(){var e,t=this._tokenStream,r=[],n="";for(t.mustMatch(g.DOCUMENT_SYM),e=t.token(),/^@\-([^\-]+)\-/.test(e.value)&&(n=RegExp.$1),this._readWhitespace(),r.push(this._document_function());t.match(g.COMMA);)this._readWhitespace(),r.push(this._document_function());t.mustMatch(g.LBRACE),this._readWhitespace(),this.fire({type:"startdocument",functions:r,prefix:n,line:e.startLine,col:e.startCol});for(var i=!0;i;)switch(t.peek()){case g.PAGE_SYM:this._page();break;case g.FONT_FACE_SYM:this._font_face();break;case g.VIEWPORT_SYM:this._viewport();break;case g.MEDIA_SYM:this._media();break;case g.KEYFRAMES_SYM:this._keyframes();break;case g.DOCUMENT_SYM:this._document();break;default:i=Boolean(this._ruleset())}t.mustMatch(g.RBRACE),e=t.token(),this._readWhitespace(),this.fire({type:"enddocument",functions:r,prefix:n,line:e.startLine,col:e.startCol})},_document_function:function(){var e,t=this._tokenStream;return t.match(g.URI)?(e=t.token().value,this._readWhitespace()):e=this._function(),e},_operator:function(e){var t=this._tokenStream,r=null;return(t.match([g.SLASH,g.COMMA])||e&&t.match([g.PLUS,g.STAR,g.MINUS]))&&(r=t.token(),this._readWhitespace()),r?d.fromToken(r):null},_combinator:function(){var e,t=this._tokenStream,r=null;return t.match([g.PLUS,g.GREATER,g.TILDE])&&(e=t.token(),r=new a(e.value,e.startLine,e.startCol),this._readWhitespace()),r},_unary_operator:function(){var e=this._tokenStream;return e.match([g.MINUS,g.PLUS])?e.token().value:null},_property:function(){var e,t,r,n,i=this._tokenStream,o=null,a=null;return i.peek()===g.STAR&&this.options.starHack&&(i.get(),a=(t=i.token()).value,r=t.startLine,n=t.startCol),i.match(g.IDENT)&&("_"===(e=(t=i.token()).value).charAt(0)&&this.options.underscoreHack&&(a="_",e=e.substring(1)),o=new c(e,a,r||t.startLine,n||t.startCol),this._readWhitespace()),o},_ruleset:function(){var e,t=this._tokenStream;try{e=this._selectors_group()}catch(e){if(!(e instanceof i)||this.options.strict)throw e;if(this.fire({type:"error",error:e,message:e.message,line:e.line,col:e.col}),t.advance([g.RBRACE])!==g.RBRACE)throw e;return!0}return e&&(this.fire({type:"startrule",selectors:e,line:e[0].line,col:e[0].col}),this._readDeclarations(!0),this.fire({type:"endrule",selectors:e,line:e[0].line,col:e[0].col})),e},_selectors_group:function(){var e,t=this._tokenStream,r=[];if(null!==(e=this._selector()))for(r.push(e);t.match(g.COMMA);)this._readWhitespace(),null!==(e=this._selector())?r.push(e):this._unexpectedToken(t.LT(1));return r.length?r:null},_selector:function(){var e=this._tokenStream,t=[],r=null,n=null,i=null;if(null===(r=this._simple_selector_sequence()))return null;for(t.push(r);;)if(null!==(n=this._combinator()))t.push(n),null===(r=this._simple_selector_sequence())?this._unexpectedToken(e.LT(1)):t.push(r);else{if(!this._readWhitespace())break;i=new a(e.token().value,e.token().startLine,e.token().startCol),n=this._combinator(),null===(r=this._simple_selector_sequence())?null!==n&&this._unexpectedToken(e.LT(1)):(null!==n?t.push(n):t.push(i),t.push(r))}return new h(t,t[0].line,t[0].col)},_simple_selector_sequence:function(){var e,t,r=this._tokenStream,n=null,i=[],o="",a=[function(){return r.match(g.HASH)?new f(r.token().value,"id",r.token().startLine,r.token().startCol):null},this._class,this._attrib,this._pseudo,this._negation],s=0,l=a.length,c=null;for(e=r.LT(1).startLine,t=r.LT(1).startCol,(n=this._type_selector())||(n=this._universal()),null!==n&&(o+=n);r.peek()!==g.S;){for(;s<l&&null===c;)c=a[s++].call(this);if(null===c){if(""===o)return null;break}s=0,i.push(c),o+=c.toString(),c=null}return""!==o?new p(n,i,o,e,t):null},_type_selector:function(){var e=this._tokenStream,t=this._namespace_prefix(),r=this._element_name();return r?(t&&(r.text=t+r.text,r.col-=t.length),r):(t&&(e.unget(),t.length>1&&e.unget()),null)},_class:function(){var e,t=this._tokenStream;return t.match(g.DOT)?(t.mustMatch(g.IDENT),e=t.token(),new f("."+e.value,"class",e.startLine,e.startCol-1)):null},_element_name:function(){var e,t=this._tokenStream;return t.match(g.IDENT)?(e=t.token(),new f(e.value,"elementName",e.startLine,e.startCol)):null},_namespace_prefix:function(){var e=this._tokenStream,t="";return e.LA(1)!==g.PIPE&&e.LA(2)!==g.PIPE||(e.match([g.IDENT,g.STAR])&&(t+=e.token().value),e.mustMatch(g.PIPE),t+="|"),t.length?t:null},_universal:function(){var e,t=this._tokenStream,r="";return(e=this._namespace_prefix())&&(r+=e),t.match(g.STAR)&&(r+="*"),r.length?r:null},_attrib:function(){var e,t,r=this._tokenStream,n=null;return r.match(g.LBRACKET)?(n=(t=r.token()).value,n+=this._readWhitespace(),(e=this._namespace_prefix())&&(n+=e),r.mustMatch(g.IDENT),n+=r.token().value,n+=this._readWhitespace(),r.match([g.PREFIXMATCH,g.SUFFIXMATCH,g.SUBSTRINGMATCH,g.EQUALS,g.INCLUDES,g.DASHMATCH])&&(n+=r.token().value,n+=this._readWhitespace(),r.mustMatch([g.IDENT,g.STRING]),n+=r.token().value,n+=this._readWhitespace()),r.mustMatch(g.RBRACKET),new f(n+"]","attribute",t.startLine,t.startCol)):null},_pseudo:function(){var e,t,r=this._tokenStream,n=null,o=":";if(r.match(g.COLON)){if(r.match(g.COLON)&&(o+=":"),r.match(g.IDENT)?(n=r.token().value,e=r.token().startLine,t=r.token().startCol-o.length):r.peek()===g.FUNCTION&&(e=r.LT(1).startLine,t=r.LT(1).startCol-o.length,n=this._functional_pseudo()),!n){var a=r.LT(1).startLine,s=r.LT(0).startCol;throw new i("Expected a `FUNCTION` or `IDENT` after colon at line "+a+", col "+s+".",a,s)}n=new f(o+n,"pseudo",e,t)}return n},_functional_pseudo:function(){var e=this._tokenStream,t=null;return e.match(g.FUNCTION)&&(t=e.token().value,t+=this._readWhitespace(),t+=this._expression(),e.mustMatch(g.RPAREN),t+=")"),t},_expression:function(){for(var e=this._tokenStream,t="";e.match([g.PLUS,g.MINUS,g.DIMENSION,g.NUMBER,g.STRING,g.IDENT,g.LENGTH,g.FREQ,g.ANGLE,g.TIME,g.RESOLUTION,g.SLASH]);)t+=e.token().value,t+=this._readWhitespace();return t.length?t:null},_negation:function(){var e,t,r,n=this._tokenStream,i="",o=null;return n.match(g.NOT)&&(i=n.token().value,e=n.token().startLine,t=n.token().startCol,i+=this._readWhitespace(),i+=r=this._negation_arg(),i+=this._readWhitespace(),n.match(g.RPAREN),i+=n.token().value,(o=new f(i,"not",e,t)).args.push(r)),o},_negation_arg:function(){var e,t,r=this._tokenStream,n=[this._type_selector,this._universal,function(){return r.match(g.HASH)?new f(r.token().value,"id",r.token().startLine,r.token().startCol):null},this._class,this._attrib,this._pseudo],i=null,o=0,a=n.length;for(e=r.LT(1).startLine,t=r.LT(1).startCol;o<a&&null===i;)i=n[o].call(this),o++;return null===i&&this._unexpectedToken(r.LT(1)),"elementName"===i.type?new p(i,[],i.toString(),e,t):new p(null,[i],i.toString(),e,t)},_declaration:function(){var e=this._tokenStream,t=null,r=null,n=null,i=null,o="";if(null!==(t=this._property())){e.mustMatch(g.COLON),this._readWhitespace(),(r=this._expr())&&0!==r.length||this._unexpectedToken(e.LT(1)),n=this._prio(),o=t.toString(),(this.options.starHack&&"*"===t.hack||this.options.underscoreHack&&"_"===t.hack)&&(o=t.text);try{this._validateProperty(o,r)}catch(e){i=e}return this.fire({type:"property",property:t,value:r,important:n,line:t.line,col:t.col,invalid:i}),!0}return!1},_prio:function(){var e=this._tokenStream.match(g.IMPORTANT_SYM);return this._readWhitespace(),e},_expr:function(e){var t=[],r=null,n=null;if(null!==(r=this._term(e)))for(t.push(r);(n=this._operator(e))&&t.push(n),null!==(r=this._term(e));)t.push(r);return t.length>0?new u(t,t[0].line,t[0].col):null},_term:function(e){var t,r,n,i,o=this._tokenStream,a=null,s=null,l=null;return null!==(t=this._unary_operator())&&(n=o.token().startLine,i=o.token().startCol),o.peek()===g.IE_FUNCTION&&this.options.ieFilters?(a=this._ie_function(),null===t&&(n=o.token().startLine,i=o.token().startCol)):e&&o.match([g.LPAREN,g.LBRACE,g.LBRACKET])?(s=(r=o.token()).endChar,a=r.value+this._expr(e).text,null===t&&(n=o.token().startLine,i=o.token().startCol),o.mustMatch(g.type(s)),a+=s,this._readWhitespace()):o.match([g.NUMBER,g.PERCENTAGE,g.LENGTH,g.ANGLE,g.TIME,g.FREQ,g.STRING,g.IDENT,g.URI,g.UNICODE_RANGE])?(a=o.token().value,null===t&&(n=o.token().startLine,i=o.token().startCol,l=d.fromToken(o.token())),this._readWhitespace()):null===(r=this._hexcolor())?(null===t&&(n=o.LT(1).startLine,i=o.LT(1).startCol),null===a&&(a=o.LA(3)===g.EQUALS&&this.options.ieFilters?this._ie_function():this._function())):(a=r.value,null===t&&(n=r.startLine,i=r.startCol)),null!==l?l:null!==a?new d(null!==t?t+a:a,n,i):null},_function:function(){var e,t=this._tokenStream,r=null;if(t.match(g.FUNCTION)){if(r=t.token().value,this._readWhitespace(),r+=this._expr(!0),this.options.ieFilters&&t.peek()===g.EQUALS)do{for(this._readWhitespace()&&(r+=t.token().value),t.LA(0)===g.COMMA&&(r+=t.token().value),t.match(g.IDENT),r+=t.token().value,t.match(g.EQUALS),r+=t.token().value,e=t.peek();e!==g.COMMA&&e!==g.S&&e!==g.RPAREN;)t.get(),r+=t.token().value,e=t.peek()}while(t.match([g.COMMA,g.S]));t.match(g.RPAREN),r+=")",this._readWhitespace()}return r},_ie_function:function(){var e,t=this._tokenStream,r=null;if(t.match([g.IE_FUNCTION,g.FUNCTION])){r=t.token().value;do{for(this._readWhitespace()&&(r+=t.token().value),t.LA(0)===g.COMMA&&(r+=t.token().value),t.match(g.IDENT),r+=t.token().value,t.match(g.EQUALS),r+=t.token().value,e=t.peek();e!==g.COMMA&&e!==g.S&&e!==g.RPAREN;)t.get(),r+=t.token().value,e=t.peek()}while(t.match([g.COMMA,g.S]));t.match(g.RPAREN),r+=")",this._readWhitespace()}return r},_hexcolor:function(){var e,t=this._tokenStream,r=null;if(t.match(g.HASH)){if(e=(r=t.token()).value,!/#[a-f0-9]{3,6}/i.test(e))throw new i("Expected a hex color but found '"+e+"' at line "+r.startLine+", col "+r.startCol+".",r.startLine,r.startCol);this._readWhitespace()}return r},_keyframes:function(){var e,t,r,n=this._tokenStream,i="";for(n.mustMatch(g.KEYFRAMES_SYM),e=n.token(),/^@\-([^\-]+)\-/.test(e.value)&&(i=RegExp.$1),this._readWhitespace(),r=this._keyframe_name(),this._readWhitespace(),n.mustMatch(g.LBRACE),this.fire({type:"startkeyframes",name:r,prefix:i,line:e.startLine,col:e.startCol}),this._readWhitespace(),t=n.peek();t===g.IDENT||t===g.PERCENTAGE;)this._keyframe_rule(),this._readWhitespace(),t=n.peek();this.fire({type:"endkeyframes",name:r,prefix:i,line:e.startLine,col:e.startCol}),this._readWhitespace(),n.mustMatch(g.RBRACE),this._readWhitespace()},_keyframe_name:function(){var e=this._tokenStream;return e.mustMatch([g.IDENT,g.STRING]),o.fromToken(e.token())},_keyframe_rule:function(){var e=this._key_list();this.fire({type:"startkeyframerule",keys:e,line:e[0].line,col:e[0].col}),this._readDeclarations(!0),this.fire({type:"endkeyframerule",keys:e,line:e[0].line,col:e[0].col})},_key_list:function(){var e=this._tokenStream,t=[];for(t.push(this._key()),this._readWhitespace();e.match(g.COMMA);)this._readWhitespace(),t.push(this._key()),this._readWhitespace();return t},_key:function(){var e,t=this._tokenStream;if(t.match(g.PERCENTAGE))return o.fromToken(t.token());if(t.match(g.IDENT)){if(e=t.token(),/from|to/i.test(e.value))return o.fromToken(e);t.unget()}this._unexpectedToken(t.LT(1))},_skipCruft:function(){for(;this._tokenStream.match([g.S,g.CDO,g.CDC]););},_readDeclarations:function(e,t){var r,n=this._tokenStream;this._readWhitespace(),e&&n.mustMatch(g.LBRACE),this._readWhitespace();try{for(;;){if(n.match(g.SEMICOLON)||t&&this._margin());else{if(!this._declaration())break;if(!n.match(g.SEMICOLON))break}this._readWhitespace()}n.mustMatch(g.RBRACE),this._readWhitespace()}catch(e){if(!(e instanceof i)||this.options.strict)throw e;if(this.fire({type:"error",error:e,message:e.message,line:e.line,col:e.col}),(r=n.advance([g.SEMICOLON,g.RBRACE]))===g.SEMICOLON)this._readDeclarations(!1,t);else if(r!==g.RBRACE)throw e}},_readWhitespace:function(){for(var e=this._tokenStream,t="";e.match(g.S);)t+=e.token().value;return t},_unexpectedToken:function(e){throw new i("Unexpected token '"+e.value+"' at line "+e.startLine+", col "+e.startCol+".",e.startLine,e.startCol)},_verifyEnd:function(){this._tokenStream.LA(1)!==g.EOF&&this._unexpectedToken(this._tokenStream.LT(1))},_validateProperty:function(e,t){b.validate(e,t)},parse:function(e){this._tokenStream=new m(e,g),this._stylesheet()},parseStyleSheet:function(e){return this.parse(e)},parseMediaQuery:function(e){this._tokenStream=new m(e,g);var t=this._media_query();return this._verifyEnd(),t},parsePropertyValue:function(e){this._tokenStream=new m(e,g),this._readWhitespace();var t=this._expr();return this._readWhitespace(),this._verifyEnd(),t},parseRule:function(e){this._tokenStream=new m(e,g),this._readWhitespace();var t=this._ruleset();return this._readWhitespace(),this._verifyEnd(),t},parseSelector:function(e){this._tokenStream=new m(e,g),this._readWhitespace();var t=this._selector();return this._readWhitespace(),this._verifyEnd(),t},parseStyleAttribute:function(e){e+="}",this._tokenStream=new m(e,g),this._readDeclarations()}};for(e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e]);return t}()},{"../util/EventTarget":23,"../util/SyntaxError":25,"../util/SyntaxUnit":26,"./Combinator":2,"./MediaFeature":4,"./MediaQuery":5,"./PropertyName":8,"./PropertyValue":9,"./PropertyValuePart":11,"./Selector":13,"./SelectorPart":14,"./SelectorSubPart":15,"./TokenStream":17,"./Tokens":18,"./Validation":19}],7:[function(e,t,r){"use strict";t.exports={__proto__:null,"align-items":"flex-start | flex-end | center | baseline | stretch","align-content":"flex-start | flex-end | center | space-between | space-around | stretch","align-self":"auto | flex-start | flex-end | center | baseline | stretch","-webkit-align-items":"flex-start | flex-end | center | baseline | stretch","-webkit-align-content":"flex-start | flex-end | center | space-between | space-around | stretch","-webkit-align-self":"auto | flex-start | flex-end | center | baseline | stretch","alignment-adjust":"auto | baseline | before-edge | text-before-edge | middle | central | after-edge | text-after-edge | ideographic | alphabetic | hanging | mathematical | <percentage> | <length>","alignment-baseline":"auto | baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",animation:1,"animation-delay":"<time>#","animation-direction":"<single-animation-direction>#","animation-duration":"<time>#","animation-fill-mode":"[ none | forwards | backwards | both ]#","animation-iteration-count":"[ <number> | infinite ]#","animation-name":"[ none | <single-animation-name> ]#","animation-play-state":"[ running | paused ]#","animation-timing-function":1,"-moz-animation-delay":"<time>#","-moz-animation-direction":"[ normal | alternate ]#","-moz-animation-duration":"<time>#","-moz-animation-iteration-count":"[ <number> | infinite ]#","-moz-animation-name":"[ none | <single-animation-name> ]#","-moz-animation-play-state":"[ running | paused ]#","-ms-animation-delay":"<time>#","-ms-animation-direction":"[ normal | alternate ]#","-ms-animation-duration":"<time>#","-ms-animation-iteration-count":"[ <number> | infinite ]#","-ms-animation-name":"[ none | <single-animation-name> ]#","-ms-animation-play-state":"[ running | paused ]#","-webkit-animation-delay":"<time>#","-webkit-animation-direction":"[ normal | alternate ]#","-webkit-animation-duration":"<time>#","-webkit-animation-fill-mode":"[ none | forwards | backwards | both ]#","-webkit-animation-iteration-count":"[ <number> | infinite ]#","-webkit-animation-name":"[ none | <single-animation-name> ]#","-webkit-animation-play-state":"[ running | paused ]#","-o-animation-delay":"<time>#","-o-animation-direction":"[ normal | alternate ]#","-o-animation-duration":"<time>#","-o-animation-iteration-count":"[ <number> | infinite ]#","-o-animation-name":"[ none | <single-animation-name> ]#","-o-animation-play-state":"[ running | paused ]#",appearance:"icon | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | radio | radio-button | checkbox | menu-item | tab | menu | menubar | pull-down-menu | pop-up-menu | list-menu | radio-group | checkbox-group | outline-tree | range | field | combo-box | signature | password | normal | none",azimuth:"<azimuth>","backface-visibility":"visible | hidden",background:1,"background-attachment":"<attachment>#","background-clip":"<box>#","background-color":"<color>","background-image":"<bg-image>#","background-origin":"<box>#","background-position":"<bg-position>","background-repeat":"<repeat-style>#","background-size":"<bg-size>#","baseline-shift":"baseline | sub | super | <percentage> | <length>",behavior:1,binding:1,bleed:"<length>","bookmark-label":"<content> | <attr> | <string>","bookmark-level":"none | <integer>","bookmark-state":"open | closed","bookmark-target":"none | <uri> | <attr>",border:"<border-width> || <border-style> || <color>","border-bottom":"<border-width> || <border-style> || <color>","border-bottom-color":"<color>","border-bottom-left-radius":"<x-one-radius>","border-bottom-right-radius":"<x-one-radius>","border-bottom-style":"<border-style>","border-bottom-width":"<border-width>","border-collapse":"collapse | separate","border-color":"<color>{1,4}","border-image":1,"border-image-outset":"[ <length> | <number> ]{1,4}","border-image-repeat":"[ stretch | repeat | round ]{1,2}","border-image-slice":"<border-image-slice>","border-image-source":"<image> | none","border-image-width":"[ <length> | <percentage> | <number> | auto ]{1,4}","border-left":"<border-width> || <border-style> || <color>","border-left-color":"<color>","border-left-style":"<border-style>","border-left-width":"<border-width>","border-radius":"<border-radius>","border-right":"<border-width> || <border-style> || <color>","border-right-color":"<color>","border-right-style":"<border-style>","border-right-width":"<border-width>","border-spacing":"<length>{1,2}","border-style":"<border-style>{1,4}","border-top":"<border-width> || <border-style> || <color>","border-top-color":"<color>","border-top-left-radius":"<x-one-radius>","border-top-right-radius":"<x-one-radius>","border-top-style":"<border-style>","border-top-width":"<border-width>","border-width":"<border-width>{1,4}",bottom:"<margin-width>","-moz-box-align":"start | end | center | baseline | stretch","-moz-box-decoration-break":"slice | clone","-moz-box-direction":"normal | reverse","-moz-box-flex":"<number>","-moz-box-flex-group":"<integer>","-moz-box-lines":"single | multiple","-moz-box-ordinal-group":"<integer>","-moz-box-orient":"horizontal | vertical | inline-axis | block-axis","-moz-box-pack":"start | end | center | justify","-o-box-decoration-break":"slice | clone","-webkit-box-align":"start | end | center | baseline | stretch","-webkit-box-decoration-break":"slice | clone","-webkit-box-direction":"normal | reverse","-webkit-box-flex":"<number>","-webkit-box-flex-group":"<integer>","-webkit-box-lines":"single | multiple","-webkit-box-ordinal-group":"<integer>","-webkit-box-orient":"horizontal | vertical | inline-axis | block-axis","-webkit-box-pack":"start | end | center | justify","box-decoration-break":"slice | clone","box-shadow":"<box-shadow>","box-sizing":"content-box | border-box","break-after":"auto | always | avoid | left | right | page | column | avoid-page | avoid-column","break-before":"auto | always | avoid | left | right | page | column | avoid-page | avoid-column","break-inside":"auto | avoid | avoid-page | avoid-column","caption-side":"top | bottom",clear:"none | right | left | both",clip:"<shape> | auto","-webkit-clip-path":"<clip-source> | <clip-path> | none","clip-path":"<clip-source> | <clip-path> | none","clip-rule":"nonzero | evenodd",color:"<color>","color-interpolation":"auto | sRGB | linearRGB","color-interpolation-filters":"auto | sRGB | linearRGB","color-profile":1,"color-rendering":"auto | optimizeSpeed | optimizeQuality","column-count":"<integer> | auto","column-fill":"auto | balance","column-gap":"<length> | normal","column-rule":"<border-width> || <border-style> || <color>","column-rule-color":"<color>","column-rule-style":"<border-style>","column-rule-width":"<border-width>","column-span":"none | all","column-width":"<length> | auto",columns:1,content:1,"counter-increment":1,"counter-reset":1,crop:"<shape> | auto",cue:"cue-after | cue-before","cue-after":1,"cue-before":1,cursor:1,direction:"ltr | rtl",display:"inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | grid | inline-grid | run-in | ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container | contents | none | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box | -ms-flexbox | -ms-inline-flexbox | flex | -webkit-flex | inline-flex | -webkit-inline-flex","dominant-baseline":"auto | use-script | no-change | reset-size | ideographic | alphabetic | hanging | mathematical | central | middle | text-after-edge | text-before-edge","drop-initial-after-adjust":"central | middle | after-edge | text-after-edge | ideographic | alphabetic | mathematical | <percentage> | <length>","drop-initial-after-align":"baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical","drop-initial-before-adjust":"before-edge | text-before-edge | central | middle | hanging | mathematical | <percentage> | <length>","drop-initial-before-align":"caps-height | baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical","drop-initial-size":"auto | line | <length> | <percentage>","drop-initial-value":"<integer>",elevation:"<angle> | below | level | above | higher | lower","empty-cells":"show | hide","enable-background":1,fill:"<paint>","fill-opacity":"<opacity-value>","fill-rule":"nonzero | evenodd",filter:"<filter-function-list> | none",fit:"fill | hidden | meet | slice","fit-position":1,flex:"<flex>","flex-basis":"<width>","flex-direction":"row | row-reverse | column | column-reverse","flex-flow":"<flex-direction> || <flex-wrap>","flex-grow":"<number>","flex-shrink":"<number>","flex-wrap":"nowrap | wrap | wrap-reverse","-webkit-flex":"<flex>","-webkit-flex-basis":"<width>","-webkit-flex-direction":"row | row-reverse | column | column-reverse","-webkit-flex-flow":"<flex-direction> || <flex-wrap>","-webkit-flex-grow":"<number>","-webkit-flex-shrink":"<number>","-webkit-flex-wrap":"nowrap | wrap | wrap-reverse","-ms-flex":"<flex>","-ms-flex-align":"start | end | center | stretch | baseline","-ms-flex-direction":"row | row-reverse | column | column-reverse","-ms-flex-order":"<number>","-ms-flex-pack":"start | end | center | justify","-ms-flex-wrap":"nowrap | wrap | wrap-reverse",float:"left | right | none","float-offset":1,"flood-color":1,"flood-opacity":"<opacity-value>",font:"<font-shorthand> | caption | icon | menu | message-box | small-caption | status-bar","font-family":"<font-family>","font-feature-settings":"<feature-tag-value> | normal","font-kerning":"auto | normal | none","font-size":"<font-size>","font-size-adjust":"<number> | none","font-stretch":"<font-stretch>","font-style":"<font-style>","font-variant":"<font-variant> | normal | none","font-variant-alternates":"<font-variant-alternates> | normal","font-variant-caps":"<font-variant-caps> | normal","font-variant-east-asian":"<font-variant-east-asian> | normal","font-variant-ligatures":"<font-variant-ligatures> | normal | none","font-variant-numeric":"<font-variant-numeric> | normal","font-variant-position":"normal | sub | super","font-weight":"<font-weight>","glyph-orientation-horizontal":"<glyph-angle>","glyph-orientation-vertical":"auto | <glyph-angle>",grid:1,"grid-area":1,"grid-auto-columns":1,"grid-auto-flow":1,"grid-auto-position":1,"grid-auto-rows":1,"grid-cell-stacking":"columns | rows | layer","grid-column":1,"grid-columns":1,"grid-column-align":"start | end | center | stretch","grid-column-sizing":1,"grid-column-start":1,"grid-column-end":1,"grid-column-span":"<integer>","grid-flow":"none | rows | columns","grid-layer":"<integer>","grid-row":1,"grid-rows":1,"grid-row-align":"start | end | center | stretch","grid-row-start":1,"grid-row-end":1,"grid-row-span":"<integer>","grid-row-sizing":1,"grid-template":1,"grid-template-areas":1,"grid-template-columns":1,"grid-template-rows":1,"hanging-punctuation":1,height:"<margin-width> | <content-sizing>","hyphenate-after":"<integer> | auto","hyphenate-before":"<integer> | auto","hyphenate-character":"<string> | auto","hyphenate-lines":"no-limit | <integer>","hyphenate-resource":1,hyphens:"none | manual | auto",icon:1,"image-orientation":"angle | auto","image-rendering":"auto | optimizeSpeed | optimizeQuality","image-resolution":1,"ime-mode":"auto | normal | active | inactive | disabled","inline-box-align":"last | <integer>","justify-content":"flex-start | flex-end | center | space-between | space-around","-webkit-justify-content":"flex-start | flex-end | center | space-between | space-around",kerning:"auto | <length>",left:"<margin-width>","letter-spacing":"<length> | normal","line-height":"<line-height>","line-break":"auto | loose | normal | strict","line-stacking":1,"line-stacking-ruby":"exclude-ruby | include-ruby","line-stacking-shift":"consider-shifts | disregard-shifts","line-stacking-strategy":"inline-line-height | block-line-height | max-height | grid-height","list-style":1,"list-style-image":"<uri> | none","list-style-position":"inside | outside","list-style-type":"disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | lower-alpha | upper-alpha | none",margin:"<margin-width>{1,4}","margin-bottom":"<margin-width>","margin-left":"<margin-width>","margin-right":"<margin-width>","margin-top":"<margin-width>",mark:1,"mark-after":1,"mark-before":1,marker:1,"marker-end":1,"marker-mid":1,"marker-start":1,marks:1,"marquee-direction":1,"marquee-play-count":1,"marquee-speed":1,"marquee-style":1,mask:1,"max-height":"<length> | <percentage> | <content-sizing> | none","max-width":"<length> | <percentage> | <content-sizing> | none","min-height":"<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats","min-width":"<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats","move-to":1,"nav-down":1,"nav-index":1,"nav-left":1,"nav-right":1,"nav-up":1,"object-fit":"fill | contain | cover | none | scale-down","object-position":"<position>",opacity:"<opacity-value>",order:"<integer>","-webkit-order":"<integer>",orphans:"<integer>",outline:1,"outline-color":"<color> | invert","outline-offset":1,"outline-style":"<border-style>","outline-width":"<border-width>",overflow:"visible | hidden | scroll | auto","overflow-style":1,"overflow-wrap":"normal | break-word","overflow-x":1,"overflow-y":1,padding:"<padding-width>{1,4}","padding-bottom":"<padding-width>","padding-left":"<padding-width>","padding-right":"<padding-width>","padding-top":"<padding-width>",page:1,"page-break-after":"auto | always | avoid | left | right","page-break-before":"auto | always | avoid | left | right","page-break-inside":"auto | avoid","page-policy":1,pause:1,"pause-after":1,"pause-before":1,perspective:1,"perspective-origin":1,phonemes:1,pitch:1,"pitch-range":1,"play-during":1,"pointer-events":"auto | none | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all",position:"static | relative | absolute | fixed","presentation-level":1,"punctuation-trim":1,quotes:1,"rendering-intent":1,resize:1,rest:1,"rest-after":1,"rest-before":1,richness:1,right:"<margin-width>",rotation:1,"rotation-point":1,"ruby-align":1,"ruby-overhang":1,"ruby-position":1,"ruby-span":1,"shape-rendering":"auto | optimizeSpeed | crispEdges | geometricPrecision",size:1,speak:"normal | none | spell-out","speak-header":"once | always","speak-numeral":"digits | continuous","speak-punctuation":"code | none","speech-rate":1,src:1,"stop-color":1,"stop-opacity":"<opacity-value>",stress:1,"string-set":1,stroke:"<paint>","stroke-dasharray":"none | <dasharray>","stroke-dashoffset":"<percentage> | <length>","stroke-linecap":"butt | round | square","stroke-linejoin":"miter | round | bevel","stroke-miterlimit":"<miterlimit>","stroke-opacity":"<opacity-value>","stroke-width":"<percentage> | <length>","table-layout":"auto | fixed","tab-size":"<integer> | <length>",target:1,"target-name":1,"target-new":1,"target-position":1,"text-align":"left | right | center | justify | match-parent | start | end","text-align-last":1,"text-anchor":"start | middle | end","text-decoration":"<text-decoration>","text-emphasis":1,"text-height":1,"text-indent":"<length> | <percentage>","text-justify":"auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida","text-outline":1,"text-overflow":1,"text-rendering":"auto | optimizeSpeed | optimizeLegibility | geometricPrecision","text-shadow":1,"text-transform":"capitalize | uppercase | lowercase | none","text-wrap":"normal | none | avoid",top:"<margin-width>","-ms-touch-action":"auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation","touch-action":"auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation",transform:1,"transform-origin":1,"transform-style":1,transition:1,"transition-delay":1,"transition-duration":1,"transition-property":1,"transition-timing-function":1,"unicode-bidi":"normal | embed | isolate | bidi-override | isolate-override | plaintext","user-modify":"read-only | read-write | write-only","user-select":"none | text | toggle | element | elements | all","vertical-align":"auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",visibility:"visible | hidden | collapse","voice-balance":1,"voice-duration":1,"voice-family":1,"voice-pitch":1,"voice-pitch-range":1,"voice-rate":1,"voice-stress":1,"voice-volume":1,volume:1,"white-space":"normal | pre | nowrap | pre-wrap | pre-line | -pre-wrap | -o-pre-wrap | -moz-pre-wrap | -hp-pre-wrap","white-space-collapse":1,widows:"<integer>",width:"<length> | <percentage> | <content-sizing> | auto","will-change":"<will-change>","word-break":"normal | keep-all | break-all","word-spacing":"<length> | normal","word-wrap":"normal | break-word","writing-mode":"horizontal-tb | vertical-rl | vertical-lr | lr-tb | rl-tb | tb-rl | bt-rl | tb-lr | bt-lr | lr-bt | rl-bt | lr | rl | tb","z-index":"<integer> | auto",zoom:"<number> | <percentage> | normal"}},{}],8:[function(e,t,r){"use strict";t.exports=o;var n=e("../util/SyntaxUnit"),i=e("./Parser");function o(e,t,r,o){n.call(this,e,r,o,i.PROPERTY_NAME_TYPE),this.hack=t}o.prototype=new n,o.prototype.constructor=o,o.prototype.toString=function(){return(this.hack?this.hack:"")+this.text}},{"../util/SyntaxUnit":26,"./Parser":6}],9:[function(e,t,r){"use strict";t.exports=o;var n=e("../util/SyntaxUnit"),i=e("./Parser");function o(e,t,r){n.call(this,e.join(" "),t,r,i.PROPERTY_VALUE_TYPE),this.parts=e}o.prototype=new n,o.prototype.constructor=o},{"../util/SyntaxUnit":26,"./Parser":6}],10:[function(e,t,r){"use strict";function n(e){this._i=0,this._parts=e.parts,this._marks=[],this.value=e}t.exports=n,n.prototype.count=function(){return this._parts.length},n.prototype.isFirst=function(){return 0===this._i},n.prototype.hasNext=function(){return this._i<this._parts.length},n.prototype.mark=function(){this._marks.push(this._i)},n.prototype.peek=function(e){return this.hasNext()?this._parts[this._i+(e||0)]:null},n.prototype.next=function(){return this.hasNext()?this._parts[this._i++]:null},n.prototype.previous=function(){return this._i>0?this._parts[--this._i]:null},n.prototype.restore=function(){this._marks.length&&(this._i=this._marks.pop())},n.prototype.drop=function(){this._marks.pop()}},{}],11:[function(e,t,r){"use strict";t.exports=s;var n=e("../util/SyntaxUnit"),i=e("./Colors"),o=e("./Parser"),a=e("./Tokens");function s(e,t,r,a){var l,c=a||{};if(n.call(this,e,t,r,o.PROPERTY_VALUE_PART_TYPE),this.type="unknown",/^([+\-]?[\d\.]+)([a-z]+)$/i.test(e))switch(this.type="dimension",this.value=+RegExp.$1,this.units=RegExp.$2,this.units.toLowerCase()){case"em":case"rem":case"ex":case"px":case"cm":case"mm":case"in":case"pt":case"pc":case"ch":case"vh":case"vw":case"vmax":case"vmin":this.type="length";break;case"fr":this.type="grid";break;case"deg":case"rad":case"grad":this.type="angle";break;case"ms":case"s":this.type="time";break;case"hz":case"khz":this.type="frequency";break;case"dpi":case"dpcm":this.type="resolution"}else/^([+\-]?[\d\.]+)%$/i.test(e)?(this.type="percentage",this.value=+RegExp.$1):/^([+\-]?\d+)$/i.test(e)?(this.type="integer",this.value=+RegExp.$1):/^([+\-]?[\d\.]+)$/i.test(e)?(this.type="number",this.value=+RegExp.$1):/^#([a-f0-9]{3,6})/i.test(e)?(this.type="color",3===(l=RegExp.$1).length?(this.red=parseInt(l.charAt(0)+l.charAt(0),16),this.green=parseInt(l.charAt(1)+l.charAt(1),16),this.blue=parseInt(l.charAt(2)+l.charAt(2),16)):(this.red=parseInt(l.substring(0,2),16),this.green=parseInt(l.substring(2,4),16),this.blue=parseInt(l.substring(4,6),16))):/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i.test(e)?(this.type="color",this.red=+RegExp.$1,this.green=+RegExp.$2,this.blue=+RegExp.$3):/^rgb\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(e)?(this.type="color",this.red=255*+RegExp.$1/100,this.green=255*+RegExp.$2/100,this.blue=255*+RegExp.$3/100):/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d\.]+)\s*\)/i.test(e)?(this.type="color",this.red=+RegExp.$1,this.green=+RegExp.$2,this.blue=+RegExp.$3,this.alpha=+RegExp.$4):/^rgba\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(e)?(this.type="color",this.red=255*+RegExp.$1/100,this.green=255*+RegExp.$2/100,this.blue=255*+RegExp.$3/100,this.alpha=+RegExp.$4):/^hsl\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(e)?(this.type="color",this.hue=+RegExp.$1,this.saturation=+RegExp.$2/100,this.lightness=+RegExp.$3/100):/^hsla\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(e)?(this.type="color",this.hue=+RegExp.$1,this.saturation=+RegExp.$2/100,this.lightness=+RegExp.$3/100,this.alpha=+RegExp.$4):/^url\(("([^\\"]|\\.)*")\)/i.test(e)?(this.type="uri",this.uri=s.parseString(RegExp.$1)):/^([^\(]+)\(/i.test(e)?(this.type="function",this.name=RegExp.$1,this.value=e):/^"([^\n\r\f\\"]|\\\r\n|\\[^\r0-9a-f]|\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?)*"/i.test(e)?(this.type="string",this.value=s.parseString(e)):/^'([^\n\r\f\\']|\\\r\n|\\[^\r0-9a-f]|\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?)*'/i.test(e)?(this.type="string",this.value=s.parseString(e)):i[e.toLowerCase()]?(this.type="color",l=i[e.toLowerCase()].substring(1),this.red=parseInt(l.substring(0,2),16),this.green=parseInt(l.substring(2,4),16),this.blue=parseInt(l.substring(4,6),16)):/^[,\/]$/.test(e)?(this.type="operator",this.value=e):/^-?[a-z_\u00A0-\uFFFF][a-z0-9\-_\u00A0-\uFFFF]*$/i.test(e)&&(this.type="identifier",this.value=e);this.wasIdent=Boolean(c.ident)}s.prototype=new n,s.prototype.constructor=s,s.parseString=function(e){return(e=e.slice(1,-1)).replace(/\\(\r\n|[^\r0-9a-f]|[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?)/gi,(function(e,t){if(/^(\n|\r\n|\r|\f)$/.test(t))return"";var r=/^[0-9a-f]{1,6}/i.exec(t);if(r){var n=parseInt(r[0],16);return String.fromCodePoint?String.fromCodePoint(n):String.fromCharCode(n)}return t}))},s.serializeString=function(e){return'"'+e.replace(/["\r\n\f]/g,(function(e,t){return'"'===t?"\\"+t:"\\"+(String.codePointAt?String.codePointAt(0):String.charCodeAt(0)).toString(16)+" "}))+'"'},s.fromToken=function(e){return new s(e.value,e.startLine,e.startCol,{ident:e.type===a.IDENT})}},{"../util/SyntaxUnit":26,"./Colors":1,"./Parser":6,"./Tokens":18}],12:[function(e,t,r){"use strict";var n=t.exports={__proto__:null,":first-letter":1,":first-line":1,":before":1,":after":1};n.ELEMENT=1,n.CLASS=2,n.isElement=function(e){return 0===e.indexOf("::")||n[e.toLowerCase()]===n.ELEMENT}},{}],13:[function(e,t,r){"use strict";t.exports=a;var n=e("../util/SyntaxUnit"),i=e("./Parser"),o=e("./Specificity");function a(e,t,r){n.call(this,e.join(" "),t,r,i.SELECTOR_TYPE),this.parts=e,this.specificity=o.calculate(this)}a.prototype=new n,a.prototype.constructor=a},{"../util/SyntaxUnit":26,"./Parser":6,"./Specificity":16}],14:[function(e,t,r){"use strict";t.exports=o;var n=e("../util/SyntaxUnit"),i=e("./Parser");function o(e,t,r,o,a){n.call(this,r,o,a,i.SELECTOR_PART_TYPE),this.elementName=e,this.modifiers=t}o.prototype=new n,o.prototype.constructor=o},{"../util/SyntaxUnit":26,"./Parser":6}],15:[function(e,t,r){"use strict";t.exports=o;var n=e("../util/SyntaxUnit"),i=e("./Parser");function o(e,t,r,o){n.call(this,e,r,o,i.SELECTOR_SUB_PART_TYPE),this.type=t,this.args=[]}o.prototype=new n,o.prototype.constructor=o},{"../util/SyntaxUnit":26,"./Parser":6}],16:[function(e,t,r){"use strict";t.exports=o;var n=e("./Pseudos"),i=e("./SelectorPart");function o(e,t,r,n){this.a=e,this.b=t,this.c=r,this.d=n}o.prototype={constructor:o,compare:function(e){var t,r,n=["a","b","c","d"];for(t=0,r=n.length;t<r;t++){if(this[n[t]]<e[n[t]])return-1;if(this[n[t]]>e[n[t]])return 1}return 0},valueOf:function(){return 1e3*this.a+100*this.b+10*this.c+this.d},toString:function(){return this.a+","+this.b+","+this.c+","+this.d}},o.calculate=function(e){var t,r,a,s=0,l=0,c=0;function u(e){var t,r,i,o,a,d=e.elementName?e.elementName.text:"";for(d&&"*"!==d.charAt(d.length-1)&&c++,t=0,i=e.modifiers.length;t<i;t++)switch((a=e.modifiers[t]).type){case"class":case"attribute":l++;break;case"id":s++;break;case"pseudo":n.isElement(a.text)?c++:l++;break;case"not":for(r=0,o=a.args.length;r<o;r++)u(a.args[r])}}for(t=0,r=e.parts.length;t<r;t++)(a=e.parts[t])instanceof i&&u(a);return new o(0,s,l,c)}},{"./Pseudos":12,"./SelectorPart":14}],17:[function(e,t,r){"use strict";t.exports=b;var n=e("../util/TokenStreamBase"),i=e("./PropertyValuePart"),o=e("./Tokens"),a=/^[0-9a-fA-F]$/,s=/^[\u00A0-\uFFFF]$/,l=/\n|\r\n|\r|\f/,c=/\u0009|\u000a|\u000c|\u000d|\u0020/;function u(e){return null!==e&&a.test(e)}function d(e){return null!==e&&/\d/.test(e)}function h(e){return null!==e&&c.test(e)}function p(e){return null!==e&&l.test(e)}function f(e){return null!==e&&/[a-z_\u00A0-\uFFFF\\]/i.test(e)}function m(e){return null!==e&&(f(e)||/[0-9\-\\]/.test(e))}function g(e){return null!==e&&(f(e)||/\-\\/.test(e))}function b(e){n.call(this,e,o)}b.prototype=function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}(new n,{_getToken:function(){var e,t=this._reader,r=null,n=t.getLine(),i=t.getCol();for(e=t.read();e;){switch(e){case"/":r="*"===t.peek()?this.commentToken(e,n,i):this.charToken(e,n,i);break;case"|":case"~":case"^":case"$":case"*":r="="===t.peek()?this.comparisonToken(e,n,i):this.charToken(e,n,i);break;case'"':case"'":r=this.stringToken(e,n,i);break;case"#":r=m(t.peek())?this.hashToken(e,n,i):this.charToken(e,n,i);break;case".":r=d(t.peek())?this.numberToken(e,n,i):this.charToken(e,n,i);break;case"-":r="-"===t.peek()?this.htmlCommentEndToken(e,n,i):f(t.peek())?this.identOrFunctionToken(e,n,i):this.charToken(e,n,i);break;case"!":r=this.importantToken(e,n,i);break;case"@":r=this.atRuleToken(e,n,i);break;case":":r=this.notToken(e,n,i);break;case"<":r=this.htmlCommentStartToken(e,n,i);break;case"\\":r=/[^\r\n\f]/.test(t.peek())?this.identOrFunctionToken(this.readEscape(e,!0),n,i):this.charToken(e,n,i);break;case"U":case"u":if("+"===t.peek()){r=this.unicodeRangeToken(e,n,i);break}default:r=d(e)?this.numberToken(e,n,i):h(e)?this.whitespaceToken(e,n,i):g(e)?this.identOrFunctionToken(e,n,i):this.charToken(e,n,i)}break}return r||null!==e||(r=this.createToken(o.EOF,null,n,i)),r},createToken:function(e,t,r,n,i){var o=this._reader;return{value:t,type:e,channel:(i=i||{}).channel,endChar:i.endChar,hide:i.hide||!1,startLine:r,startCol:n,endLine:o.getLine(),endCol:o.getCol()}},atRuleToken:function(e,t,r){var n=e,i=this._reader,a=o.CHAR;return i.mark(),n=e+this.readName(),(a=o.type(n.toLowerCase()))!==o.CHAR&&a!==o.UNKNOWN||(n.length>1?a=o.UNKNOWN_SYM:(a=o.CHAR,n=e,i.reset())),this.createToken(a,n,t,r)},charToken:function(e,t,r){var n=o.type(e),i={};return-1===n?n=o.CHAR:i.endChar=o[n].endChar,this.createToken(n,e,t,r,i)},commentToken:function(e,t,r){var n=this.readComment(e);return this.createToken(o.COMMENT,n,t,r)},comparisonToken:function(e,t,r){var n=e+this._reader.read(),i=o.type(n)||o.CHAR;return this.createToken(i,n,t,r)},hashToken:function(e,t,r){var n=this.readName(e);return this.createToken(o.HASH,n,t,r)},htmlCommentStartToken:function(e,t,r){var n=this._reader,i=e;return n.mark(),"\x3c!--"===(i+=n.readCount(3))?this.createToken(o.CDO,i,t,r):(n.reset(),this.charToken(e,t,r))},htmlCommentEndToken:function(e,t,r){var n=this._reader,i=e;return n.mark(),"--\x3e"===(i+=n.readCount(2))?this.createToken(o.CDC,i,t,r):(n.reset(),this.charToken(e,t,r))},identOrFunctionToken:function(e,t,r){var n,i=this._reader,a=this.readName(e),s=o.IDENT;return"("===i.peek()?(a+=i.read(),["url(","url-prefix(","domain("].indexOf(a.toLowerCase())>-1?(i.mark(),null===(n=this.readURI(a))?(i.reset(),s=o.FUNCTION):(s=o.URI,a=n)):s=o.FUNCTION):":"===i.peek()&&"progid"===a.toLowerCase()&&(a+=i.readTo("("),s=o.IE_FUNCTION),this.createToken(s,a,t,r)},importantToken:function(e,t,r){var n,i,a=this._reader,s=e,l=o.CHAR;for(a.mark(),i=a.read();i;){if("/"===i){if("*"!==a.peek())break;if(""===(n=this.readComment(i)))break}else{if(!h(i)){if(/i/i.test(i)){n=a.readCount(8),/mportant/i.test(n)&&(s+=i+n,l=o.IMPORTANT_SYM);break}break}s+=i+this.readWhitespace()}i=a.read()}return l===o.CHAR?(a.reset(),this.charToken(e,t,r)):this.createToken(l,s,t,r)},notToken:function(e,t,r){var n=this._reader,i=e;return n.mark(),":not("===(i+=n.readCount(4)).toLowerCase()?this.createToken(o.NOT,i,t,r):(n.reset(),this.charToken(e,t,r))},numberToken:function(e,t,r){var n,i=this._reader,a=this.readNumber(e),s=o.NUMBER,l=i.peek();return g(l)?(a+=n=this.readName(i.read()),s=/^em$|^ex$|^px$|^gd$|^rem$|^vw$|^vh$|^vmax$|^vmin$|^ch$|^cm$|^mm$|^in$|^pt$|^pc$/i.test(n)?o.LENGTH:/^deg|^rad$|^grad$/i.test(n)?o.ANGLE:/^ms$|^s$/i.test(n)?o.TIME:/^hz$|^khz$/i.test(n)?o.FREQ:/^dpi$|^dpcm$/i.test(n)?o.RESOLUTION:o.DIMENSION):"%"===l&&(a+=i.read(),s=o.PERCENTAGE),this.createToken(s,a,t,r)},stringToken:function(e,t,r){for(var n,i=e,a=e,s=this._reader,l=o.STRING,c=s.read();c;){if(a+=c,"\\"===c){if(null===(c=s.read()))break;if(/[^\r\n\f0-9a-f]/i.test(c))a+=c;else{for(n=0;u(c)&&n<6;n++)a+=c,c=s.read();if("\r"===c&&"\n"===s.peek()&&(a+=c,c=s.read()),!h(c))continue;a+=c}}else{if(c===i)break;if(p(s.peek())){l=o.INVALID;break}}c=s.read()}return null===c&&(l=o.INVALID),this.createToken(l,a,t,r)},unicodeRangeToken:function(e,t,r){var n,i=this._reader,a=e,s=o.CHAR;return"+"===i.peek()&&(i.mark(),a+=i.read(),2===(a+=this.readUnicodeRangePart(!0)).length?i.reset():(s=o.UNICODE_RANGE,-1===a.indexOf("?")&&"-"===i.peek()&&(i.mark(),n=i.read(),1===(n+=this.readUnicodeRangePart(!1)).length?i.reset():a+=n))),this.createToken(s,a,t,r)},whitespaceToken:function(e,t,r){var n=e+this.readWhitespace();return this.createToken(o.S,n,t,r)},readUnicodeRangePart:function(e){for(var t=this._reader,r="",n=t.peek();u(n)&&r.length<6;)t.read(),r+=n,n=t.peek();if(e)for(;"?"===n&&r.length<6;)t.read(),r+=n,n=t.peek();return r},readWhitespace:function(){for(var e=this._reader,t="",r=e.peek();h(r);)e.read(),t+=r,r=e.peek();return t},readNumber:function(e){for(var t=this._reader,r=e,n="."===e,i=t.peek();i;){if(d(i))r+=t.read();else{if("."!==i)break;if(n)break;n=!0,r+=t.read()}i=t.peek()}return r},readString:function(){var e=this.stringToken(this._reader.read(),0,0);return e.type===o.INVALID?null:e.value},readURI:function(e){for(var t=this._reader,r=e,n="",o=t.peek();o&&h(o);)t.read(),o=t.peek();for("'"===o||'"'===o?null!==(n=this.readString())&&(n=i.parseString(n)):n=this.readUnquotedURL(),o=t.peek();o&&h(o);)t.read(),o=t.peek();return null===n||")"!==o?r=null:r+=i.serializeString(n)+t.read(),r},readUnquotedURL:function(e){var t,r=this._reader,n=e||"";for(t=r.peek();t;t=r.peek())if(s.test(t)||/^[\-!#$%&*-\[\]-~]$/.test(t))n+=t,r.read();else{if("\\"!==t)break;if(!/^[^\r\n\f]$/.test(r.peek(2)))break;n+=this.readEscape(r.read(),!0)}return n},readName:function(e){var t,r=this._reader,n=e||"";for(t=r.peek();t;t=r.peek())if("\\"===t){if(!/^[^\r\n\f]$/.test(r.peek(2)))break;n+=this.readEscape(r.read(),!0)}else{if(!m(t))break;n+=r.read()}return n},readEscape:function(e,t){var r=this._reader,n=e||"",i=0,o=r.peek();if(u(o))do{n+=r.read(),o=r.peek()}while(o&&u(o)&&++i<6);if(1===n.length){if(!/^[^\r\n\f0-9a-f]$/.test(o))throw new Error("Bad escape sequence.");if(r.read(),t)return o}else"\r"===o?(r.read(),"\n"===r.peek()&&(o+=r.read())):/^[ \t\n\f]$/.test(o)?r.read():o="";if(t){var a=parseInt(n.slice(e.length),16);return String.fromCodePoint?String.fromCodePoint(a):String.fromCharCode(a)}return n+o},readComment:function(e){var t=this._reader,r=e||"",n=t.read();if("*"===n){for(;n;){if((r+=n).length>2&&"*"===n&&"/"===t.peek()){r+=t.read();break}n=t.read()}return r}return""}})},{"../util/TokenStreamBase":27,"./PropertyValuePart":11,"./Tokens":18}],18:[function(e,t,r){"use strict";var n=t.exports=[{name:"CDO"},{name:"CDC"},{name:"S",whitespace:!0},{name:"COMMENT",comment:!0,hide:!0,channel:"comment"},{name:"INCLUDES",text:"~="},{name:"DASHMATCH",text:"|="},{name:"PREFIXMATCH",text:"^="},{name:"SUFFIXMATCH",text:"$="},{name:"SUBSTRINGMATCH",text:"*="},{name:"STRING"},{name:"IDENT"},{name:"HASH"},{name:"IMPORT_SYM",text:"@import"},{name:"PAGE_SYM",text:"@page"},{name:"MEDIA_SYM",text:"@media"},{name:"FONT_FACE_SYM",text:"@font-face"},{name:"CHARSET_SYM",text:"@charset"},{name:"NAMESPACE_SYM",text:"@namespace"},{name:"SUPPORTS_SYM",text:"@supports"},{name:"VIEWPORT_SYM",text:["@viewport","@-ms-viewport","@-o-viewport"]},{name:"DOCUMENT_SYM",text:["@document","@-moz-document"]},{name:"UNKNOWN_SYM"},{name:"KEYFRAMES_SYM",text:["@keyframes","@-webkit-keyframes","@-moz-keyframes","@-o-keyframes"]},{name:"IMPORTANT_SYM"},{name:"LENGTH"},{name:"ANGLE"},{name:"TIME"},{name:"FREQ"},{name:"DIMENSION"},{name:"PERCENTAGE"},{name:"NUMBER"},{name:"URI"},{name:"FUNCTION"},{name:"UNICODE_RANGE"},{name:"INVALID"},{name:"PLUS",text:"+"},{name:"GREATER",text:">"},{name:"COMMA",text:","},{name:"TILDE",text:"~"},{name:"NOT"},{name:"TOPLEFTCORNER_SYM",text:"@top-left-corner"},{name:"TOPLEFT_SYM",text:"@top-left"},{name:"TOPCENTER_SYM",text:"@top-center"},{name:"TOPRIGHT_SYM",text:"@top-right"},{name:"TOPRIGHTCORNER_SYM",text:"@top-right-corner"},{name:"BOTTOMLEFTCORNER_SYM",text:"@bottom-left-corner"},{name:"BOTTOMLEFT_SYM",text:"@bottom-left"},{name:"BOTTOMCENTER_SYM",text:"@bottom-center"},{name:"BOTTOMRIGHT_SYM",text:"@bottom-right"},{name:"BOTTOMRIGHTCORNER_SYM",text:"@bottom-right-corner"},{name:"LEFTTOP_SYM",text:"@left-top"},{name:"LEFTMIDDLE_SYM",text:"@left-middle"},{name:"LEFTBOTTOM_SYM",text:"@left-bottom"},{name:"RIGHTTOP_SYM",text:"@right-top"},{name:"RIGHTMIDDLE_SYM",text:"@right-middle"},{name:"RIGHTBOTTOM_SYM",text:"@right-bottom"},{name:"RESOLUTION",state:"media"},{name:"IE_FUNCTION"},{name:"CHAR"},{name:"PIPE",text:"|"},{name:"SLASH",text:"/"},{name:"MINUS",text:"-"},{name:"STAR",text:"*"},{name:"LBRACE",endChar:"}",text:"{"},{name:"RBRACE",text:"}"},{name:"LBRACKET",endChar:"]",text:"["},{name:"RBRACKET",text:"]"},{name:"EQUALS",text:"="},{name:"COLON",text:":"},{name:"SEMICOLON",text:";"},{name:"LPAREN",endChar:")",text:"("},{name:"RPAREN",text:")"},{name:"DOT",text:"."}];!function(){var e=[],t=Object.create(null);n.UNKNOWN=-1,n.unshift({name:"EOF"});for(var r=0,i=n.length;r<i;r++)if(e.push(n[r].name),n[n[r].name]=r,n[r].text)if(n[r].text instanceof Array)for(var o=0;o<n[r].text.length;o++)t[n[r].text[o]]=r;else t[n[r].text]=r;n.name=function(t){return e[t]},n.type=function(e){return t[e]||-1}}()},{}],19:[function(e,t,r){"use strict";var n=e("./Matcher"),i=e("./Properties"),o=e("./ValidationTypes"),a=e("./ValidationError"),s=e("./PropertyValueIterator");t.exports={validate:function(e,t){var r,n=e.toString().toLowerCase(),l=new s(t),c=i[n];if(c){if("number"!=typeof c){if(o.isAny(l,"inherit | initial | unset")){if(l.hasNext())throw r=l.next(),new a("Expected end of value but found '"+r+"'.",r.line,r.col);return}this.singleProperty(c,l)}}else if(0!==n.indexOf("-"))throw new a("Unknown property '"+e+"'.",e.line,e.col)},singleProperty:function(e,t){var r,i=t.value;if(!n.parse(e).match(t))throw t.hasNext()&&!t.isFirst()?(r=t.peek(),new a("Expected end of value but found '"+r+"'.",r.line,r.col)):new a("Expected ("+o.describe(e)+") but found '"+i+"'.",i.line,i.col);if(t.hasNext())throw r=t.next(),new a("Expected end of value but found '"+r+"'.",r.line,r.col)}}},{"./Matcher":3,"./Properties":7,"./PropertyValueIterator":10,"./ValidationError":20,"./ValidationTypes":21}],20:[function(e,t,r){"use strict";function n(e,t,r){this.col=r,this.line=t,this.message=e}t.exports=n,n.prototype=new Error},{}],21:[function(e,t,r){"use strict";var n,i,o=t.exports,a=e("./Matcher");n=o,i={isLiteral:function(e,t){var r,n,i=e.text.toString().toLowerCase(),o=t.split(" | "),a=!1;for(r=0,n=o.length;r<n&&!a;r++)"<"===o[r].charAt(0)?a=this.simple[o[r]](e):"()"===o[r].slice(-2)?a="function"===e.type&&e.name===o[r].slice(0,-2):i===o[r].toLowerCase()&&(a=!0);return a},isSimple:function(e){return Boolean(this.simple[e])},isComplex:function(e){return Boolean(this.complex[e])},describe:function(e){return this.complex[e]instanceof a?this.complex[e].toString(0):e},isAny:function(e,t){var r,n,i=t.split(" | "),o=!1;for(r=0,n=i.length;r<n&&!o&&e.hasNext();r++)o=this.isType(e,i[r]);return o},isAnyOfGroup:function(e,t){var r,n,i=t.split(" || "),o=!1;for(r=0,n=i.length;r<n&&!o;r++)o=this.isType(e,i[r]);return!!o&&i[r-1]},isType:function(e,t){var r=e.peek(),n=!1;return"<"!==t.charAt(0)?(n=this.isLiteral(r,t))&&e.next():this.simple[t]?(n=this.simple[t](r))&&e.next():n=this.complex[t]instanceof a?this.complex[t].match(e):this.complex[t](e),n},simple:{__proto__:null,"<absolute-size>":"xx-small | x-small | small | medium | large | x-large | xx-large","<animateable-feature>":"scroll-position | contents | <animateable-feature-name>","<animateable-feature-name>":function(e){return this["<ident>"](e)&&!/^(unset|initial|inherit|will-change|auto|scroll-position|contents)$/i.test(e)},"<angle>":function(e){return"angle"===e.type},"<attachment>":"scroll | fixed | local","<attr>":"attr()","<basic-shape>":"inset() | circle() | ellipse() | polygon()","<bg-image>":"<image> | <gradient> | none","<border-style>":"none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset","<border-width>":"<length> | thin | medium | thick","<box>":"padding-box | border-box | content-box","<clip-source>":"<uri>","<color>":function(e){return"color"===e.type||"transparent"===String(e)||"currentColor"===String(e)},"<color-svg>":function(e){return"color"===e.type},"<content>":"content()","<content-sizing>":"fill-available | -moz-available | -webkit-fill-available | max-content | -moz-max-content | -webkit-max-content | min-content | -moz-min-content | -webkit-min-content | fit-content | -moz-fit-content | -webkit-fit-content","<feature-tag-value>":function(e){return"function"===e.type&&/^[A-Z0-9]{4}$/i.test(e)},"<filter-function>":"blur() | brightness() | contrast() | custom() | drop-shadow() | grayscale() | hue-rotate() | invert() | opacity() | saturate() | sepia()","<flex-basis>":"<width>","<flex-direction>":"row | row-reverse | column | column-reverse","<flex-grow>":"<number>","<flex-shrink>":"<number>","<flex-wrap>":"nowrap | wrap | wrap-reverse","<font-size>":"<absolute-size> | <relative-size> | <length> | <percentage>","<font-stretch>":"normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded","<font-style>":"normal | italic | oblique","<font-variant-caps>":"small-caps | all-small-caps | petite-caps | all-petite-caps | unicase | titling-caps","<font-variant-css21>":"normal | small-caps","<font-weight>":"normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900","<generic-family>":"serif | sans-serif | cursive | fantasy | monospace","<geometry-box>":"<shape-box> | fill-box | stroke-box | view-box","<glyph-angle>":function(e){return"angle"===e.type&&"deg"===e.units},"<gradient>":function(e){return"function"===e.type&&/^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(e)},"<icccolor>":"cielab() | cielch() | cielchab() | icc-color() | icc-named-color()","<ident>":function(e){return"identifier"===e.type||e.wasIdent},"<ident-not-generic-family>":function(e){return this["<ident>"](e)&&!this["<generic-family>"](e)},"<image>":"<uri>","<integer>":function(e){return"integer"===e.type},"<length>":function(e){return!("function"!==e.type||!/^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(e))||"length"===e.type||"number"===e.type||"integer"===e.type||"0"===String(e)},"<line>":function(e){return"integer"===e.type},"<line-height>":"<number> | <length> | <percentage> | normal","<margin-width>":"<length> | <percentage> | auto","<miterlimit>":function(e){return this["<number>"](e)&&e.value>=1},"<nonnegative-length-or-percentage>":function(e){return(this["<length>"](e)||this["<percentage>"](e))&&("0"===String(e)||"function"===e.type||e.value>=0)},"<nonnegative-number-or-percentage>":function(e){return(this["<number>"](e)||this["<percentage>"](e))&&("0"===String(e)||"function"===e.type||e.value>=0)},"<number>":function(e){return"number"===e.type||this["<integer>"](e)},"<opacity-value>":function(e){return this["<number>"](e)&&e.value>=0&&e.value<=1},"<padding-width>":"<nonnegative-length-or-percentage>","<percentage>":function(e){return"percentage"===e.type||"0"===String(e)},"<relative-size>":"smaller | larger","<shape>":"rect() | inset-rect()","<shape-box>":"<box> | margin-box","<single-animation-direction>":"normal | reverse | alternate | alternate-reverse","<single-animation-name>":function(e){return this["<ident>"](e)&&/^-?[a-z_][-a-z0-9_]+$/i.test(e)&&!/^(none|unset|initial|inherit)$/i.test(e)},"<string>":function(e){return"string"===e.type},"<time>":function(e){return"time"===e.type},"<uri>":function(e){return"uri"===e.type},"<width>":"<margin-width>"},complex:{__proto__:null,"<azimuth>":"<angle> | [ [ left-side | far-left | left | center-left | center | center-right | right | far-right | right-side ] || behind ] | leftwards | rightwards","<bg-position>":"<position>#","<bg-size>":"[ <length> | <percentage> | auto ]{1,2} | cover | contain","<border-image-slice>":a.many([!0],a.cast("<nonnegative-number-or-percentage>"),a.cast("<nonnegative-number-or-percentage>"),a.cast("<nonnegative-number-or-percentage>"),a.cast("<nonnegative-number-or-percentage>"),"fill"),"<border-radius>":"<nonnegative-length-or-percentage>{1,4} [ / <nonnegative-length-or-percentage>{1,4} ]?","<box-shadow>":"none | <shadow>#","<clip-path>":"<basic-shape> || <geometry-box>","<dasharray>":a.cast("<nonnegative-length-or-percentage>").braces(1,1/0,"#",a.cast(",").question()),"<family-name>":"<string> | <ident-not-generic-family> <ident>*","<filter-function-list>":"[ <filter-function> | <uri> ]+","<flex>":"none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]","<font-family>":"[ <generic-family> | <family-name> ]#","<font-shorthand>":"[ <font-style> || <font-variant-css21> || <font-weight> || <font-stretch> ]? <font-size> [ / <line-height> ]? <font-family>","<font-variant-alternates>":"stylistic() || historical-forms || styleset() || character-variant() || swash() || ornaments() || annotation()","<font-variant-ligatures>":"[ common-ligatures | no-common-ligatures ] || [ discretionary-ligatures | no-discretionary-ligatures ] || [ historical-ligatures | no-historical-ligatures ] || [ contextual | no-contextual ]","<font-variant-numeric>":"[ lining-nums | oldstyle-nums ] || [ proportional-nums | tabular-nums ] || [ diagonal-fractions | stacked-fractions ] || ordinal || slashed-zero","<font-variant-east-asian>":"[ jis78 | jis83 | jis90 | jis04 | simplified | traditional ] || [ full-width | proportional-width ] || ruby","<paint>":"<paint-basic> | <uri> <paint-basic>?","<paint-basic>":"none | currentColor | <color-svg> <icccolor>?","<position>":"[ center | [ left | right ] [ <percentage> | <length> ]? ] && [ center | [ top | bottom ] [ <percentage> | <length> ]? ] | [ left | center | right | <percentage> | <length> ] [ top | center | bottom | <percentage> | <length> ] | [ left | center | right | top | bottom | <percentage> | <length> ]","<repeat-style>":"repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}","<shadow>":a.many([!0],a.cast("<length>").braces(2,4),"inset","<color>"),"<text-decoration>":"none | [ underline || overline || line-through || blink ]","<will-change>":"auto | <animateable-feature>#","<x-one-radius>":"[ <length> | <percentage> ]{1,2}"}},Object.keys(i).forEach((function(e){n[e]=i[e]})),Object.keys(o.simple).forEach((function(e){var t=o.simple[e];"string"==typeof t&&(o.simple[e]=function(e){return o.isLiteral(e,t)})})),Object.keys(o.complex).forEach((function(e){var t=o.complex[e];"string"==typeof t&&(o.complex[e]=a.parse(t))})),o.complex["<font-variant>"]=a.oror({expand:"<font-variant-ligatures>"},{expand:"<font-variant-alternates>"},"<font-variant-caps>",{expand:"<font-variant-numeric>"},{expand:"<font-variant-east-asian>"})},{"./Matcher":3}],22:[function(e,t,r){"use strict";t.exports={Colors:e("./Colors"),Combinator:e("./Combinator"),Parser:e("./Parser"),PropertyName:e("./PropertyName"),PropertyValue:e("./PropertyValue"),PropertyValuePart:e("./PropertyValuePart"),Matcher:e("./Matcher"),MediaFeature:e("./MediaFeature"),MediaQuery:e("./MediaQuery"),Selector:e("./Selector"),SelectorPart:e("./SelectorPart"),SelectorSubPart:e("./SelectorSubPart"),Specificity:e("./Specificity"),TokenStream:e("./TokenStream"),Tokens:e("./Tokens"),ValidationError:e("./ValidationError")}},{"./Colors":1,"./Combinator":2,"./Matcher":3,"./MediaFeature":4,"./MediaQuery":5,"./Parser":6,"./PropertyName":8,"./PropertyValue":9,"./PropertyValuePart":11,"./Selector":13,"./SelectorPart":14,"./SelectorSubPart":15,"./Specificity":16,"./TokenStream":17,"./Tokens":18,"./ValidationError":20}],23:[function(e,t,r){"use strict";function n(){this._listeners=Object.create(null)}t.exports=n,n.prototype={constructor:n,addListener:function(e,t){this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t)},fire:function(e){if("string"==typeof e&&(e={type:e}),void 0!==e.target&&(e.target=this),void 0===e.type)throw new Error("Event object missing 'type' property.");if(this._listeners[e.type])for(var t=this._listeners[e.type].concat(),r=0,n=t.length;r<n;r++)t[r].call(this,e)},removeListener:function(e,t){if(this._listeners[e])for(var r=this._listeners[e],n=0,i=r.length;n<i;n++)if(r[n]===t){r.splice(n,1);break}}}},{}],24:[function(e,t,r){"use strict";function n(e){this._input=e.replace(/(\r\n?|\n)/g,"\n"),this._line=1,this._col=1,this._cursor=0}t.exports=n,n.prototype={constructor:n,getCol:function(){return this._col},getLine:function(){return this._line},eof:function(){return this._cursor===this._input.length},peek:function(e){var t=null;return e=void 0===e?1:e,this._cursor<this._input.length&&(t=this._input.charAt(this._cursor+e-1)),t},read:function(){var e=null;return this._cursor<this._input.length&&("\n"===this._input.charAt(this._cursor)?(this._line++,this._col=1):this._col++,e=this._input.charAt(this._cursor++)),e},mark:function(){this._bookmark={cursor:this._cursor,line:this._line,col:this._col}},reset:function(){this._bookmark&&(this._cursor=this._bookmark.cursor,this._line=this._bookmark.line,this._col=this._bookmark.col,delete this._bookmark)},readTo:function(e){for(var t,r="";r.length<e.length||r.lastIndexOf(e)!==r.length-e.length;){if(!(t=this.read()))throw new Error('Expected "'+e+'" at line '+this._line+", col "+this._col+".");r+=t}return r},readWhile:function(e){for(var t="",r=this.peek();null!==r&&e(r);)t+=this.read(),r=this.peek();return t},readMatch:function(e){var t=this._input.substring(this._cursor),r=null;return"string"==typeof e?t.slice(0,e.length)===e&&(r=this.readCount(e.length)):e instanceof RegExp&&e.test(t)&&(r=this.readCount(RegExp.lastMatch.length)),r},readCount:function(e){for(var t="";e--;)t+=this.read();return t}}},{}],25:[function(e,t,r){"use strict";function n(e,t,r){Error.call(this),this.name=this.constructor.name,this.col=r,this.line=t,this.message=e}t.exports=n,n.prototype=Object.create(Error.prototype),n.prototype.constructor=n},{}],26:[function(e,t,r){"use strict";function n(e,t,r,n){this.col=r,this.line=t,this.text=e,this.type=n}t.exports=n,n.fromToken=function(e){return new n(e.value,e.startLine,e.startCol)},n.prototype={constructor:n,valueOf:function(){return this.toString()},toString:function(){return this.text}}},{}],27:[function(e,t,r){"use strict";t.exports=o;var n=e("./StringReader"),i=e("./SyntaxError");function o(e,t){this._reader=new n(e?e.toString():""),this._token=null,this._tokenData=t,this._lt=[],this._ltIndex=0,this._ltIndexCache=[]}o.createTokenData=function(e){var t=[],r=Object.create(null),n=e.concat([]),i=0,o=n.length+1;for(n.UNKNOWN=-1,n.unshift({name:"EOF"});i<o;i++)t.push(n[i].name),n[n[i].name]=i,n[i].text&&(r[n[i].text]=i);return n.name=function(e){return t[e]},n.type=function(e){return r[e]},n},o.prototype={constructor:o,match:function(e,t){e instanceof Array||(e=[e]);for(var r=this.get(t),n=0,i=e.length;n<i;)if(r===e[n++])return!0;return this.unget(),!1},mustMatch:function(e){var t;if(e instanceof Array||(e=[e]),!this.match.apply(this,arguments))throw t=this.LT(1),new i("Expected "+this._tokenData[e[0]].name+" at line "+t.startLine+", col "+t.startCol+".",t.startLine,t.startCol)},advance:function(e,t){for(;0!==this.LA(0)&&!this.match(e,t);)this.get();return this.LA(0)},get:function(e){var t,r,n=this._tokenData,i=0;if(this._lt.length&&this._ltIndex>=0&&this._ltIndex<this._lt.length){for(i++,this._token=this._lt[this._ltIndex++],r=n[this._token.type];void 0!==r.channel&&e!==r.channel&&this._ltIndex<this._lt.length;)this._token=this._lt[this._ltIndex++],r=n[this._token.type],i++;if((void 0===r.channel||e===r.channel)&&this._ltIndex<=this._lt.length)return this._ltIndexCache.push(i),this._token.type}return(t=this._getToken()).type>-1&&!n[t.type].hide&&(t.channel=n[t.type].channel,this._token=t,this._lt.push(t),this._ltIndexCache.push(this._lt.length-this._ltIndex+i),this._lt.length>5&&this._lt.shift(),this._ltIndexCache.length>5&&this._ltIndexCache.shift(),this._ltIndex=this._lt.length),(r=n[t.type])&&(r.hide||void 0!==r.channel&&e!==r.channel)?this.get(e):t.type},LA:function(e){var t,r=e;if(e>0){if(e>5)throw new Error("Too much lookahead.");for(;r;)t=this.get(),r--;for(;r<e;)this.unget(),r++}else if(e<0){if(!this._lt[this._ltIndex+e])throw new Error("Too much lookbehind.");t=this._lt[this._ltIndex+e].type}else t=this._token.type;return t},LT:function(e){return this.LA(e),this._lt[this._ltIndex+e-1]},peek:function(){return this.LA(1)},token:function(){return this._token},tokenName:function(e){return e<0||e>this._tokenData.length?"UNKNOWN_TOKEN":this._tokenData[e].name},tokenType:function(e){return this._tokenData[e]||-1},unget:function(){if(!this._ltIndexCache.length)throw new Error("Too much lookahead.");this._ltIndex-=this._ltIndexCache.pop(),this._token=this._lt[this._ltIndex-1]}}},{"./StringReader":24,"./SyntaxError":25}],28:[function(e,t,r){"use strict";t.exports={StringReader:e("./StringReader"),SyntaxError:e("./SyntaxError"),SyntaxUnit:e("./SyntaxUnit"),EventTarget:e("./EventTarget"),TokenStreamBase:e("./TokenStreamBase")}},{"./EventTarget":23,"./StringReader":24,"./SyntaxError":25,"./SyntaxUnit":26,"./TokenStreamBase":27}],parserlib:[function(e,t,r){"use strict";t.exports={css:e("./css"),util:e("./util")}},{"./css":22,"./util":28}]},{},[]))("parserlib"),n=function(){"use strict";function e(t,n,i,o){"object"==typeof n&&(i=n.depth,o=n.prototype,n.filter,n=n.circular);var a=[],s=[],l="undefined"!=typeof Buffer;return void 0===n&&(n=!0),void 0===i&&(i=1/0),function t(i,c){if(null===i)return null;if(0==c)return i;var u,d;if("object"!=typeof i)return i;if(e.__isArray(i))u=[];else if(e.__isRegExp(i))u=new RegExp(i.source,r(i)),i.lastIndex&&(u.lastIndex=i.lastIndex);else if(e.__isDate(i))u=new Date(i.getTime());else{if(l&&Buffer.isBuffer(i))return u=new Buffer(i.length),i.copy(u),u;void 0===o?(d=Object.getPrototypeOf(i),u=Object.create(d)):(u=Object.create(o),d=o)}if(n){var h=a.indexOf(i);if(-1!=h)return s[h];a.push(i),s.push(u)}for(var p in i){var f;d&&(f=Object.getOwnPropertyDescriptor(d,p)),f&&null==f.set||(u[p]=t(i[p],c-1))}return u}(t,i)}function t(e){return Object.prototype.toString.call(e)}function r(e){var t="";return e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),t}return e.clonePrototype=function(e){if(null===e)return null;var t=function(){};return t.prototype=e,new t},e.__objToStr=t,e.__isDate=function(e){return"object"==typeof e&&"[object Date]"===t(e)},e.__isArray=function(e){return"object"==typeof e&&"[object Array]"===t(e)},e.__isRegExp=function(e){return"object"==typeof e&&"[object RegExp]"===t(e)},e.__getRegExpFlags=r,e}();
/*!
Parser-Lib
Copyright (c) 2009-2016 Nicholas C. Zakas. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/"object"==typeof t&&t.exports&&(t.exports=n);var i=function(){"use strict";var e=[],t=[],a=/\/\*\s*csslint([^\*]*)\*\//,s=new r.util.EventTarget;return s.version="1.0.3",s.addRule=function(t){e.push(t),e[t.id]=t},s.clearRules=function(){e=[]},s.getRules=function(){return[].concat(e).sort((function(e,t){return e.id>t.id?1:0}))},s.getRuleset=function(){for(var t={},r=0,n=e.length;r<n;)t[e[r++].id]=1;return t},s.addFormatter=function(e){t[e.id]=e},s.getFormatter=function(e){return t[e]},s.format=function(e,t,r,n){var i=this.getFormatter(r),o=null;return i&&(o=i.startFormat(),o+=i.formatResults(e,t,n||{}),o+=i.endFormat()),o},s.hasFormat=function(e){return t.hasOwnProperty(e)},s.verify=function(t,s){var l,c,u,d=0,h={},p=[],f=new r.css.Parser({starHack:!0,ieFilters:!0,underscoreHack:!0,strict:!1});c=t.replace(/\n\r?/g,"$split$").split("$split$"),i.Util.forEach(c,(function(e,t){var r=e&&e.match(/\/\*[ \t]*csslint[ \t]+allow:[ \t]*([^\*]*)\*\//i),n=r&&r[1],i={};n&&(n.toLowerCase().split(",").forEach((function(e){i[e.trim()]=!0})),Object.keys(i).length>0&&(h[t+1]=i))}));var m=null,g=null;for(d in i.Util.forEach(c,(function(e,t){null===m&&e.match(/\/\*[ \t]*csslint[ \t]+ignore:start[ \t]*\*\//i)&&(m=t),e.match(/\/\*[ \t]*csslint[ \t]+ignore:end[ \t]*\*\//i)&&(g=t),null!==m&&null!==g&&(p.push([m,g]),m=g=null)})),null!==m&&p.push([m,c.length]),s||(s=this.getRuleset()),a.test(t)&&(s=function(e,t){var r,n=e&&e.match(a),i=n&&n[1];return i&&(r={true:2,"":1,false:0,2:2,1:1,0:0},i.toLowerCase().split(",").forEach((function(e){var n=e.split(":"),i=n[0]||"",o=n[1]||"";t[i.trim()]=r[o.trim()]}))),t}(t,s=n(s))),l=new o(c,s,h,p),s.errors=2,s)s.hasOwnProperty(d)&&s[d]&&e[d]&&e[d].init(f,l);try{f.parse(t)}catch(e){l.error("Fatal error, cannot continue: "+e.message,e.line,e.col,{})}return(u={messages:l.messages,stats:l.stats,ruleset:l.ruleset,allow:l.allow,ignore:l.ignore}).messages.sort((function(e,t){return e.rollup&&!t.rollup?1:!e.rollup&&t.rollup?-1:e.line-t.line})),u},s}();function o(e,t,r,n){"use strict";this.messages=[],this.stats=[],this.lines=e,this.ruleset=t,this.allow=r,this.allow||(this.allow={}),this.ignore=n,this.ignore||(this.ignore=[])}return o.prototype={constructor:o,error:function(e,t,r,n){"use strict";this.messages.push({type:"error",line:t,col:r,message:e,evidence:this.lines[t-1],rule:n||{}})},warn:function(e,t,r,n){"use strict";this.report(e,t,r,n)},report:function(e,t,r,n){"use strict";if(!this.allow.hasOwnProperty(t)||!this.allow[t].hasOwnProperty(n.id)){var o=!1;i.Util.forEach(this.ignore,(function(e){e[0]<=t&&t<=e[1]&&(o=!0)})),o||this.messages.push({type:2===this.ruleset[n.id]?"error":"warning",line:t,col:r,message:e,evidence:this.lines[t-1],rule:n})}},info:function(e,t,r,n){"use strict";this.messages.push({type:"info",line:t,col:r,message:e,evidence:this.lines[t-1],rule:n})},rollupError:function(e,t){"use strict";this.messages.push({type:"error",rollup:!0,message:e,rule:t})},rollupWarn:function(e,t){"use strict";this.messages.push({type:"warning",rollup:!0,message:e,rule:t})},stat:function(e,t){"use strict";this.stats[e]=t}},i._Reporter=o,i.Util={mix:function(e,t){"use strict";var r;for(r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return r},indexOf:function(e,t){"use strict";if(e.indexOf)return e.indexOf(t);for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1},forEach:function(e,t){"use strict";if(e.forEach)return e.forEach(t);for(var r=0,n=e.length;r<n;r++)t(e[r],r,e)}},i.addRule({id:"adjoining-classes",name:"Disallow adjoining classes",desc:"Don't use adjoining classes.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-adjoining-classes",browsers:"IE6",init:function(e,t){"use strict";var r=this;e.addListener("startrule",(function(n){var i,o,a,s,l,c,u=n.selectors;for(s=0;s<u.length;s++)for(i=u[s],l=0;l<i.parts.length;l++)if((o=i.parts[l]).type===e.SELECTOR_PART_TYPE)for(a=0,c=0;c<o.modifiers.length;c++)"class"===o.modifiers[c].type&&a++,a>1&&t.report("Adjoining classes: "+u[s].text,o.line,o.col,r)}))}}),i.addRule({id:"box-model",name:"Beware of broken box size",desc:"Don't use width or height when using padding or border.",url:"https://github.com/CSSLint/csslint/wiki/Beware-of-box-model-size",browsers:"All",init:function(e,t){"use strict";var r,n=this,i={border:1,"border-left":1,"border-right":1,padding:1,"padding-left":1,"padding-right":1},o={border:1,"border-bottom":1,"border-top":1,padding:1,"padding-bottom":1,"padding-top":1},a=!1;function s(){r={},a=!1}function l(){var e,s;if(!a){if(r.height)for(e in o)o.hasOwnProperty(e)&&r[e]&&(s=r[e].value,"padding"===e&&2===s.parts.length&&0===s.parts[0].value||t.report("Using height with "+e+" can sometimes make elements larger than you expect.",r[e].line,r[e].col,n));if(r.width)for(e in i)i.hasOwnProperty(e)&&r[e]&&(s=r[e].value,"padding"===e&&2===s.parts.length&&0===s.parts[1].value||t.report("Using width with "+e+" can sometimes make elements larger than you expect.",r[e].line,r[e].col,n))}}e.addListener("startrule",s),e.addListener("startfontface",s),e.addListener("startpage",s),e.addListener("startpagemargin",s),e.addListener("startkeyframerule",s),e.addListener("startviewport",s),e.addListener("property",(function(e){var t=e.property.text.toLowerCase();o[t]||i[t]?/^0\S*$/.test(e.value)||"border"===t&&"none"===e.value.toString()||(r[t]={line:e.property.line,col:e.property.col,value:e.value}):/^(width|height)/i.test(t)&&/^(length|percentage)/.test(e.value.parts[0].type)?r[t]=1:"box-sizing"===t&&(a=!0)})),e.addListener("endrule",l),e.addListener("endfontface",l),e.addListener("endpage",l),e.addListener("endpagemargin",l),e.addListener("endkeyframerule",l),e.addListener("endviewport",l)}}),i.addRule({id:"box-sizing",name:"Disallow use of box-sizing",desc:"The box-sizing properties isn't supported in IE6 and IE7.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-box-sizing",browsers:"IE6, IE7",tags:["Compatibility"],init:function(e,t){"use strict";var r=this;e.addListener("property",(function(e){"box-sizing"===e.property.text.toLowerCase()&&t.report("The box-sizing property isn't supported in IE6 and IE7.",e.line,e.col,r)}))}}),i.addRule({id:"bulletproof-font-face",name:"Use the bulletproof @font-face syntax",desc:"Use the bulletproof @font-face syntax to avoid 404's in old IE (http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax).",url:"https://github.com/CSSLint/csslint/wiki/Bulletproof-font-face",browsers:"All",init:function(e,t){"use strict";var r,n,i=this,o=!1,a=!0,s=!1;e.addListener("startfontface",(function(){o=!0})),e.addListener("property",(function(e){if(o){var t=e.property.toString().toLowerCase(),i=e.value.toString();if(r=e.line,n=e.col,"src"===t){var l=/^\s?url\(['"].+\.eot\?.*['"]\)\s*format\(['"]embedded-opentype['"]\).*$/i;!i.match(l)&&a?(s=!0,a=!1):i.match(l)&&!a&&(s=!1)}}})),e.addListener("endfontface",(function(){o=!1,s&&t.report("@font-face declaration doesn't follow the fontspring bulletproof syntax.",r,n,i)}))}}),i.addRule({id:"compatible-vendor-prefixes",name:"Require compatible vendor prefixes",desc:"Include all compatible vendor prefixes to reach a wider range of users.",url:"https://github.com/CSSLint/csslint/wiki/Require-compatible-vendor-prefixes",browsers:"All",init:function(e,t){"use strict";var r,n,o,a,s,l,c,u=this,d=!1,h=Array.prototype.push,p=[];for(o in r={animation:"webkit","animation-delay":"webkit","animation-direction":"webkit","animation-duration":"webkit","animation-fill-mode":"webkit","animation-iteration-count":"webkit","animation-name":"webkit","animation-play-state":"webkit","animation-timing-function":"webkit",appearance:"webkit moz","border-end":"webkit moz","border-end-color":"webkit moz","border-end-style":"webkit moz","border-end-width":"webkit moz","border-image":"webkit moz o","border-radius":"webkit","border-start":"webkit moz","border-start-color":"webkit moz","border-start-style":"webkit moz","border-start-width":"webkit moz","box-align":"webkit moz ms","box-direction":"webkit moz ms","box-flex":"webkit moz ms","box-lines":"webkit ms","box-ordinal-group":"webkit moz ms","box-orient":"webkit moz ms","box-pack":"webkit moz ms","box-sizing":"","box-shadow":"","column-count":"webkit moz ms","column-gap":"webkit moz ms","column-rule":"webkit moz ms","column-rule-color":"webkit moz ms","column-rule-style":"webkit moz ms","column-rule-width":"webkit moz ms","column-width":"webkit moz ms",hyphens:"epub moz","line-break":"webkit ms","margin-end":"webkit moz","margin-start":"webkit moz","marquee-speed":"webkit wap","marquee-style":"webkit wap","padding-end":"webkit moz","padding-start":"webkit moz","tab-size":"moz o","text-size-adjust":"webkit ms",transform:"webkit ms","transform-origin":"webkit ms",transition:"","transition-delay":"","transition-duration":"","transition-property":"","transition-timing-function":"","user-modify":"webkit moz","user-select":"webkit moz ms","word-break":"epub ms","writing-mode":"epub ms"})if(r.hasOwnProperty(o)){for(a=[],l=0,c=(s=r[o].split(" ")).length;l<c;l++)a.push("-"+s[l]+"-"+o);r[o]=a,h.apply(p,a)}e.addListener("startrule",(function(){n=[]})),e.addListener("startkeyframes",(function(e){d=e.prefix||!0})),e.addListener("endkeyframes",(function(){d=!1})),e.addListener("property",(function(e){var t=e.property;i.Util.indexOf(p,t.text)>-1&&(d&&"string"==typeof d&&0===t.text.indexOf("-"+d+"-")||n.push(t))})),e.addListener("endrule",(function(){if(n.length){var e,o,a,s,l,c,d,h,p,f,m={};for(e=0,o=n.length;e<o;e++)for(s in a=n[e],r)r.hasOwnProperty(s)&&(l=r[s],i.Util.indexOf(l,a.text)>-1&&(m[s]||(m[s]={full:l.slice(0),actual:[],actualNodes:[]}),-1===i.Util.indexOf(m[s].actual,a.text)&&(m[s].actual.push(a.text),m[s].actualNodes.push(a))));for(s in m)if(m.hasOwnProperty(s)&&(d=(c=m[s]).full,h=c.actual,d.length>h.length))for(e=0,o=d.length;e<o;e++)p=d[e],-1===i.Util.indexOf(h,p)&&(f=1===h.length?h[0]:2===h.length?h.join(" and "):h.join(", "),t.report("The property "+p+" is compatible with "+f+" and should be included as well.",c.actualNodes[0].line,c.actualNodes[0].col,u))}}))}}),i.addRule({id:"display-property-grouping",name:"Require properties appropriate for display",desc:"Certain properties shouldn't be used with certain display property values.",url:"https://github.com/CSSLint/csslint/wiki/Require-properties-appropriate-for-display",browsers:"All",init:function(e,t){"use strict";var r,n=this,i={display:1,float:"none",height:1,width:1,margin:1,"margin-left":1,"margin-right":1,"margin-bottom":1,"margin-top":1,padding:1,"padding-left":1,"padding-right":1,"padding-bottom":1,"padding-top":1,"vertical-align":1};function o(e,o,a){r[e]&&("string"==typeof i[e]&&r[e].value.toLowerCase()===i[e]||t.report(a||e+" can't be used with display: "+o+".",r[e].line,r[e].col,n))}function a(){r={}}function s(){var e=r.display?r.display.value:null;if(e)switch(e){case"inline":o("height",e),o("width",e),o("margin",e),o("margin-top",e),o("margin-bottom",e),o("float",e,"display:inline has no effect on floated elements (but may be used to fix the IE6 double-margin bug).");break;case"block":o("vertical-align",e);break;case"inline-block":o("float",e);break;default:0===e.indexOf("table-")&&(o("margin",e),o("margin-left",e),o("margin-right",e),o("margin-top",e),o("margin-bottom",e),o("float",e))}}e.addListener("startrule",a),e.addListener("startfontface",a),e.addListener("startkeyframerule",a),e.addListener("startpagemargin",a),e.addListener("startpage",a),e.addListener("startviewport",a),e.addListener("property",(function(e){var t=e.property.text.toLowerCase();i[t]&&(r[t]={value:e.value.text,line:e.property.line,col:e.property.col})})),e.addListener("endrule",s),e.addListener("endfontface",s),e.addListener("endkeyframerule",s),e.addListener("endpagemargin",s),e.addListener("endpage",s),e.addListener("endviewport",s)}}),i.addRule({id:"duplicate-background-images",name:"Disallow duplicate background images",desc:"Every background-image should be unique. Use a common class for e.g. sprites.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-duplicate-background-images",browsers:"All",init:function(e,t){"use strict";var r=this,n={};e.addListener("property",(function(e){var i,o,a=e.property.text,s=e.value;if(a.match(/background/i))for(i=0,o=s.parts.length;i<o;i++)"uri"===s.parts[i].type&&(void 0===n[s.parts[i].uri]?n[s.parts[i].uri]=e:t.report("Background image '"+s.parts[i].uri+"' was used multiple times, first declared at line "+n[s.parts[i].uri].line+", col "+n[s.parts[i].uri].col+".",e.line,e.col,r))}))}}),i.addRule({id:"duplicate-properties",name:"Disallow duplicate properties",desc:"Duplicate properties must appear one after the other.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-duplicate-properties",browsers:"All",init:function(e,t){"use strict";var r,n,i=this;function o(){r={}}e.addListener("startrule",o),e.addListener("startfontface",o),e.addListener("startpage",o),e.addListener("startpagemargin",o),e.addListener("startkeyframerule",o),e.addListener("startviewport",o),e.addListener("property",(function(e){var o=e.property.text.toLowerCase();!r[o]||n===o&&r[o]!==e.value.text||t.report("Duplicate property '"+e.property+"' found.",e.line,e.col,i),r[o]=e.value.text,n=o}))}}),i.addRule({id:"empty-rules",name:"Disallow empty rules",desc:"Rules without any properties specified should be removed.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-empty-rules",browsers:"All",init:function(e,t){"use strict";var r=this,n=0;e.addListener("startrule",(function(){n=0})),e.addListener("property",(function(){n++})),e.addListener("endrule",(function(e){var i=e.selectors;0===n&&t.report("Rule is empty.",i[0].line,i[0].col,r)}))}}),i.addRule({id:"errors",name:"Parsing Errors",desc:"This rule looks for recoverable syntax errors.",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("error",(function(e){t.error(e.message,e.line,e.col,r)}))}}),i.addRule({id:"fallback-colors",name:"Require fallback colors",desc:"For older browsers that don't support RGBA, HSL, or HSLA, provide a fallback color.",url:"https://github.com/CSSLint/csslint/wiki/Require-fallback-colors",browsers:"IE6,IE7,IE8",init:function(e,t){"use strict";var r,n=this,i={color:1,background:1,"border-color":1,"border-top-color":1,"border-right-color":1,"border-bottom-color":1,"border-left-color":1,border:1,"border-top":1,"border-right":1,"border-bottom":1,"border-left":1,"background-color":1};function o(){r=null}e.addListener("startrule",o),e.addListener("startfontface",o),e.addListener("startpage",o),e.addListener("startpagemargin",o),e.addListener("startkeyframerule",o),e.addListener("startviewport",o),e.addListener("property",(function(e){var o=e.property.text.toLowerCase(),a=e.value.parts,s=0,l="",c=a.length;if(i[o])for(;s<c;)"color"===a[s].type&&("alpha"in a[s]||"hue"in a[s]?(/([^\)]+)\(/.test(a[s])&&(l=RegExp.$1.toUpperCase()),r&&r.property.text.toLowerCase()===o&&"compat"===r.colorType||t.report("Fallback "+o+" (hex or RGB) should precede "+l+" "+o+".",e.line,e.col,n)):e.colorType="compat"),s++;r=e}))}}),i.addRule({id:"floats",name:"Disallow too many floats",desc:"This rule tests if the float property is used too many times",url:"https://github.com/CSSLint/csslint/wiki/Disallow-too-many-floats",browsers:"All",init:function(e,t){"use strict";var r=this,n=0;e.addListener("property",(function(e){"float"===e.property.text.toLowerCase()&&"none"!==e.value.text.toLowerCase()&&n++})),e.addListener("endstylesheet",(function(){t.stat("floats",n),n>=10&&t.rollupWarn("Too many floats ("+n+"), you're probably using them for layout. Consider using a grid system instead.",r)}))}}),i.addRule({id:"font-faces",name:"Don't use too many web fonts",desc:"Too many different web fonts in the same stylesheet.",url:"https://github.com/CSSLint/csslint/wiki/Don%27t-use-too-many-web-fonts",browsers:"All",init:function(e,t){"use strict";var r=this,n=0;e.addListener("startfontface",(function(){n++})),e.addListener("endstylesheet",(function(){n>5&&t.rollupWarn("Too many @font-face declarations ("+n+").",r)}))}}),i.addRule({id:"font-sizes",name:"Disallow too many font sizes",desc:"Checks the number of font-size declarations.",url:"https://github.com/CSSLint/csslint/wiki/Don%27t-use-too-many-font-size-declarations",browsers:"All",init:function(e,t){"use strict";var r=this,n=0;e.addListener("property",(function(e){"font-size"===e.property.toString()&&n++})),e.addListener("endstylesheet",(function(){t.stat("font-sizes",n),n>=10&&t.rollupWarn("Too many font-size declarations ("+n+"), abstraction needed.",r)}))}}),i.addRule({id:"gradients",name:"Require all gradient definitions",desc:"When using a vendor-prefixed gradient, make sure to use them all.",url:"https://github.com/CSSLint/csslint/wiki/Require-all-gradient-definitions",browsers:"All",init:function(e,t){"use strict";var r,n=this;e.addListener("startrule",(function(){r={moz:0,webkit:0,oldWebkit:0,o:0}})),e.addListener("property",(function(e){/\-(moz|o|webkit)(?:\-(?:linear|radial))\-gradient/i.test(e.value)?r[RegExp.$1]=1:/\-webkit\-gradient/i.test(e.value)&&(r.oldWebkit=1)})),e.addListener("endrule",(function(e){var i=[];r.moz||i.push("Firefox 3.6+"),r.webkit||i.push("Webkit (Safari 5+, Chrome)"),r.oldWebkit||i.push("Old Webkit (Safari 4+, Chrome)"),r.o||i.push("Opera 11.1+"),i.length&&i.length<4&&t.report("Missing vendor-prefixed CSS gradients for "+i.join(", ")+".",e.selectors[0].line,e.selectors[0].col,n)}))}}),i.addRule({id:"ids",name:"Disallow IDs in selectors",desc:"Selectors should not contain IDs.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-IDs-in-selectors",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("startrule",(function(n){var i,o,a,s,l,c,u=n.selectors;for(s=0;s<u.length;s++){for(i=u[s],a=0,l=0;l<i.parts.length;l++)if((o=i.parts[l]).type===e.SELECTOR_PART_TYPE)for(c=0;c<o.modifiers.length;c++)"id"===o.modifiers[c].type&&a++;1===a?t.report("Don't use IDs in selectors.",i.line,i.col,r):a>1&&t.report(a+" IDs in the selector, really?",i.line,i.col,r)}}))}}),i.addRule({id:"import-ie-limit",name:"@import limit on IE6-IE9",desc:"IE6-9 supports up to 31 @import per stylesheet",browsers:"IE6, IE7, IE8, IE9",init:function(e,t){"use strict";var r=this,n=0;e.addListener("startpage",(function(){n=0})),e.addListener("import",(function(){n++})),e.addListener("endstylesheet",(function(){n>31&&t.rollupError("Too many @import rules ("+n+"). IE6-9 supports up to 31 import per stylesheet.",r)}))}}),i.addRule({id:"import",name:"Disallow @import",desc:"Don't use @import, use <link> instead.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-%40import",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("import",(function(e){t.report("@import prevents parallel downloads, use <link> instead.",e.line,e.col,r)}))}}),i.addRule({id:"important",name:"Disallow !important",desc:"Be careful when using !important declaration",url:"https://github.com/CSSLint/csslint/wiki/Disallow-%21important",browsers:"All",init:function(e,t){"use strict";var r=this,n=0;e.addListener("property",(function(e){!0===e.important&&(n++,t.report("Use of !important",e.line,e.col,r))})),e.addListener("endstylesheet",(function(){t.stat("important",n),n>=10&&t.rollupWarn("Too many !important declarations ("+n+"), try to use less than 10 to avoid specificity issues.",r)}))}}),i.addRule({id:"known-properties",name:"Require use of known properties",desc:"Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.",url:"https://github.com/CSSLint/csslint/wiki/Require-use-of-known-properties",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("property",(function(e){e.invalid&&t.report(e.invalid.message,e.line,e.col,r)}))}}),i.addRule({id:"order-alphabetical",name:"Alphabetical order",desc:"Assure properties are in alphabetical order",browsers:"All",init:function(e,t){"use strict";var r,n=this,i=function(){r=[]},o=function(e){r.join(",")!==r.sort().join(",")&&t.report("Rule doesn't have all its properties in alphabetical order.",e.line,e.col,n)};e.addListener("startrule",i),e.addListener("startfontface",i),e.addListener("startpage",i),e.addListener("startpagemargin",i),e.addListener("startkeyframerule",i),e.addListener("startviewport",i),e.addListener("property",(function(e){var t=e.property.text.toLowerCase().replace(/^-.*?-/,"");r.push(t)})),e.addListener("endrule",o),e.addListener("endfontface",o),e.addListener("endpage",o),e.addListener("endpagemargin",o),e.addListener("endkeyframerule",o),e.addListener("endviewport",o)}}),i.addRule({id:"outline-none",name:"Disallow outline: none",desc:"Use of outline: none or outline: 0 should be limited to :focus rules.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-outline%3Anone",browsers:"All",tags:["Accessibility"],init:function(e,t){"use strict";var r,n=this;function i(e){r=e.selectors?{line:e.line,col:e.col,selectors:e.selectors,propCount:0,outline:!1}:null}function o(){r&&r.outline&&(-1===r.selectors.toString().toLowerCase().indexOf(":focus")?t.report("Outlines should only be modified using :focus.",r.line,r.col,n):1===r.propCount&&t.report("Outlines shouldn't be hidden unless other visual changes are made.",r.line,r.col,n))}e.addListener("startrule",i),e.addListener("startfontface",i),e.addListener("startpage",i),e.addListener("startpagemargin",i),e.addListener("startkeyframerule",i),e.addListener("startviewport",i),e.addListener("property",(function(e){var t=e.property.text.toLowerCase(),n=e.value;r&&(r.propCount++,"outline"!==t||"none"!==n.toString()&&"0"!==n.toString()||(r.outline=!0))})),e.addListener("endrule",o),e.addListener("endfontface",o),e.addListener("endpage",o),e.addListener("endpagemargin",o),e.addListener("endkeyframerule",o),e.addListener("endviewport",o)}}),i.addRule({id:"overqualified-elements",name:"Disallow overqualified elements",desc:"Don't use classes or IDs with elements (a.foo or a#foo).",url:"https://github.com/CSSLint/csslint/wiki/Disallow-overqualified-elements",browsers:"All",init:function(e,t){"use strict";var r=this,n={};e.addListener("startrule",(function(i){var o,a,s,l,c,u,d=i.selectors;for(l=0;l<d.length;l++)for(o=d[l],c=0;c<o.parts.length;c++)if((a=o.parts[c]).type===e.SELECTOR_PART_TYPE)for(u=0;u<a.modifiers.length;u++)s=a.modifiers[u],a.elementName&&"id"===s.type?t.report("Element ("+a+") is overqualified, just use "+s+" without element name.",a.line,a.col,r):"class"===s.type&&(n[s]||(n[s]=[]),n[s].push({modifier:s,part:a}))})),e.addListener("endstylesheet",(function(){var e;for(e in n)n.hasOwnProperty(e)&&1===n[e].length&&n[e][0].part.elementName&&t.report("Element ("+n[e][0].part+") is overqualified, just use "+n[e][0].modifier+" without element name.",n[e][0].part.line,n[e][0].part.col,r)}))}}),i.addRule({id:"qualified-headings",name:"Disallow qualified headings",desc:"Headings should not be qualified (namespaced).",url:"https://github.com/CSSLint/csslint/wiki/Disallow-qualified-headings",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("startrule",(function(n){var i,o,a,s,l=n.selectors;for(a=0;a<l.length;a++)for(i=l[a],s=0;s<i.parts.length;s++)(o=i.parts[s]).type===e.SELECTOR_PART_TYPE&&o.elementName&&/h[1-6]/.test(o.elementName.toString())&&s>0&&t.report("Heading ("+o.elementName+") should not be qualified.",o.line,o.col,r)}))}}),i.addRule({id:"regex-selectors",name:"Disallow selectors that look like regexs",desc:"Selectors that look like regular expressions are slow and should be avoided.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-selectors-that-look-like-regular-expressions",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("startrule",(function(n){var i,o,a,s,l,c,u=n.selectors;for(s=0;s<u.length;s++)for(i=u[s],l=0;l<i.parts.length;l++)if((o=i.parts[l]).type===e.SELECTOR_PART_TYPE)for(c=0;c<o.modifiers.length;c++)"attribute"===(a=o.modifiers[c]).type&&/([~\|\^\$\*]=)/.test(a)&&t.report("Attribute selectors with "+RegExp.$1+" are slow!",a.line,a.col,r)}))}}),i.addRule({id:"rules-count",name:"Rules Count",desc:"Track how many rules there are.",browsers:"All",init:function(e,t){"use strict";var r=0;e.addListener("startrule",(function(){r++})),e.addListener("endstylesheet",(function(){t.stat("rule-count",r)}))}}),i.addRule({id:"selector-max-approaching",name:"Warn when approaching the 4095 selector limit for IE",desc:"Will warn when selector count is >= 3800 selectors.",browsers:"IE",init:function(e,t){"use strict";var r=this,n=0;e.addListener("startrule",(function(e){n+=e.selectors.length})),e.addListener("endstylesheet",(function(){n>=3800&&t.report("You have "+n+" selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,r)}))}}),i.addRule({id:"selector-max",name:"Error when past the 4095 selector limit for IE",desc:"Will error when selector count is > 4095.",browsers:"IE",init:function(e,t){"use strict";var r=this,n=0;e.addListener("startrule",(function(e){n+=e.selectors.length})),e.addListener("endstylesheet",(function(){n>4095&&t.report("You have "+n+" selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,r)}))}}),i.addRule({id:"selector-newline",name:"Disallow new-line characters in selectors",desc:"New-line characters in selectors are usually a forgotten comma and not a descendant combinator.",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("startrule",(function(e){var n,i,o,a,s,l,c,u,d,h,p,f=e.selectors;for(n=0,i=f.length;n<i;n++)for(a=0,l=(o=f[n]).parts.length;a<l;a++)for(s=a+1;s<l;s++)c=o.parts[a],u=o.parts[s],d=c.type,h=c.line,p=u.line,"descendant"===d&&p>h&&t.report("newline character found in selector (forgot a comma?)",h,f[n].parts[0].col,r)}))}}),i.addRule({id:"shorthand",name:"Require shorthand properties",desc:"Use shorthand properties where possible.",url:"https://github.com/CSSLint/csslint/wiki/Require-shorthand-properties",browsers:"All",init:function(e,t){"use strict";var r,n,i,o,a=this,s={},l={margin:["margin-top","margin-bottom","margin-left","margin-right"],padding:["padding-top","padding-bottom","padding-left","padding-right"]};for(r in l)if(l.hasOwnProperty(r))for(n=0,i=l[r].length;n<i;n++)s[l[r][n]]=r;function c(){o={}}function u(e){var r,n,i,s;for(r in l)if(l.hasOwnProperty(r)){for(s=0,n=0,i=l[r].length;n<i;n++)s+=o[l[r][n]]?1:0;s===l[r].length&&t.report("The properties "+l[r].join(", ")+" can be replaced by "+r+".",e.line,e.col,a)}}e.addListener("startrule",c),e.addListener("startfontface",c),e.addListener("property",(function(e){var t=e.property.toString().toLowerCase();s[t]&&(o[t]=1)})),e.addListener("endrule",u),e.addListener("endfontface",u)}}),i.addRule({id:"star-property-hack",name:"Disallow properties with a star prefix",desc:"Checks for the star property hack (targets IE6/7)",url:"https://github.com/CSSLint/csslint/wiki/Disallow-star-hack",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("property",(function(e){"*"===e.property.hack&&t.report("Property with star prefix found.",e.property.line,e.property.col,r)}))}}),i.addRule({id:"text-indent",name:"Disallow negative text-indent",desc:"Checks for text indent less than -99px",url:"https://github.com/CSSLint/csslint/wiki/Disallow-negative-text-indent",browsers:"All",init:function(e,t){"use strict";var r,n,i=this;function o(){r=!1,n="inherit"}function a(){r&&"ltr"!==n&&t.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.",r.line,r.col,i)}e.addListener("startrule",o),e.addListener("startfontface",o),e.addListener("property",(function(e){var t=e.property.toString().toLowerCase(),i=e.value;"text-indent"===t&&i.parts[0].value<-99?r=e.property:"direction"===t&&"ltr"===i.toString()&&(n="ltr")})),e.addListener("endrule",a),e.addListener("endfontface",a)}}),i.addRule({id:"underscore-property-hack",name:"Disallow properties with an underscore prefix",desc:"Checks for the underscore property hack (targets IE6)",url:"https://github.com/CSSLint/csslint/wiki/Disallow-underscore-hack",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("property",(function(e){"_"===e.property.hack&&t.report("Property with underscore prefix found.",e.property.line,e.property.col,r)}))}}),i.addRule({id:"unique-headings",name:"Headings should only be defined once",desc:"Headings should be defined only once.",url:"https://github.com/CSSLint/csslint/wiki/Headings-should-only-be-defined-once",browsers:"All",init:function(e,t){"use strict";var r=this,n={h1:0,h2:0,h3:0,h4:0,h5:0,h6:0};e.addListener("startrule",(function(e){var i,o,a,s,l,c=e.selectors;for(s=0;s<c.length;s++)if((o=(i=c[s]).parts[i.parts.length-1]).elementName&&/(h[1-6])/i.test(o.elementName.toString())){for(l=0;l<o.modifiers.length;l++)if("pseudo"===o.modifiers[l].type){a=!0;break}a||(n[RegExp.$1]++,n[RegExp.$1]>1&&t.report("Heading ("+o.elementName+") has already been defined.",o.line,o.col,r))}})),e.addListener("endstylesheet",(function(){var e,i=[];for(e in n)n.hasOwnProperty(e)&&n[e]>1&&i.push(n[e]+" "+e+"s");i.length&&t.rollupWarn("You have "+i.join(", ")+" defined in this stylesheet.",r)}))}}),i.addRule({id:"universal-selector",name:"Disallow universal selector",desc:"The universal selector (*) is known to be slow.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-universal-selector",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("startrule",(function(e){var n,i,o,a=e.selectors;for(o=0;o<a.length;o++)"*"===(i=(n=a[o]).parts[n.parts.length-1]).elementName&&t.report(r.desc,i.line,i.col,r)}))}}),i.addRule({id:"unqualified-attributes",name:"Disallow unqualified attribute selectors",desc:"Unqualified attribute selectors are known to be slow.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-unqualified-attribute-selectors",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("startrule",(function(n){var i,o,a,s,l,c=n.selectors,u=!1;for(s=0;s<c.length;s++)if((o=(i=c[s]).parts[i.parts.length-1]).type===e.SELECTOR_PART_TYPE){for(l=0;l<o.modifiers.length;l++)if("class"===(a=o.modifiers[l]).type||"id"===a.type){u=!0;break}if(!u)for(l=0;l<o.modifiers.length;l++)"attribute"!==(a=o.modifiers[l]).type||o.elementName&&"*"!==o.elementName||t.report(r.desc,o.line,o.col,r)}}))}}),i.addRule({id:"vendor-prefix",name:"Require standard property with vendor prefix",desc:"When using a vendor-prefixed property, make sure to include the standard one.",url:"https://github.com/CSSLint/csslint/wiki/Require-standard-property-with-vendor-prefix",browsers:"All",init:function(e,t){"use strict";var r,n,i=this,o={"-webkit-border-radius":"border-radius","-webkit-border-top-left-radius":"border-top-left-radius","-webkit-border-top-right-radius":"border-top-right-radius","-webkit-border-bottom-left-radius":"border-bottom-left-radius","-webkit-border-bottom-right-radius":"border-bottom-right-radius","-o-border-radius":"border-radius","-o-border-top-left-radius":"border-top-left-radius","-o-border-top-right-radius":"border-top-right-radius","-o-border-bottom-left-radius":"border-bottom-left-radius","-o-border-bottom-right-radius":"border-bottom-right-radius","-moz-border-radius":"border-radius","-moz-border-radius-topleft":"border-top-left-radius","-moz-border-radius-topright":"border-top-right-radius","-moz-border-radius-bottomleft":"border-bottom-left-radius","-moz-border-radius-bottomright":"border-bottom-right-radius","-moz-column-count":"column-count","-webkit-column-count":"column-count","-moz-column-gap":"column-gap","-webkit-column-gap":"column-gap","-moz-column-rule":"column-rule","-webkit-column-rule":"column-rule","-moz-column-rule-style":"column-rule-style","-webkit-column-rule-style":"column-rule-style","-moz-column-rule-color":"column-rule-color","-webkit-column-rule-color":"column-rule-color","-moz-column-rule-width":"column-rule-width","-webkit-column-rule-width":"column-rule-width","-moz-column-width":"column-width","-webkit-column-width":"column-width","-webkit-column-span":"column-span","-webkit-columns":"columns","-moz-box-shadow":"box-shadow","-webkit-box-shadow":"box-shadow","-moz-transform":"transform","-webkit-transform":"transform","-o-transform":"transform","-ms-transform":"transform","-moz-transform-origin":"transform-origin","-webkit-transform-origin":"transform-origin","-o-transform-origin":"transform-origin","-ms-transform-origin":"transform-origin","-moz-box-sizing":"box-sizing","-webkit-box-sizing":"box-sizing"};function a(){r={},n=1}function s(){var e,n,a,s,l,c=[];for(e in r)o[e]&&c.push({actual:e,needed:o[e]});for(n=0,a=c.length;n<a;n++)s=c[n].needed,l=c[n].actual,r[s]?r[s][0].pos<r[l][0].pos&&t.report("Standard property '"+s+"' should come after vendor-prefixed property '"+l+"'.",r[l][0].name.line,r[l][0].name.col,i):t.report("Missing standard property '"+s+"' to go along with '"+l+"'.",r[l][0].name.line,r[l][0].name.col,i)}e.addListener("startrule",a),e.addListener("startfontface",a),e.addListener("startpage",a),e.addListener("startpagemargin",a),e.addListener("startkeyframerule",a),e.addListener("startviewport",a),e.addListener("property",(function(e){var t=e.property.text.toLowerCase();r[t]||(r[t]=[]),r[t].push({name:e.property,value:e.value,pos:n++})})),e.addListener("endrule",s),e.addListener("endfontface",s),e.addListener("endpage",s),e.addListener("endpagemargin",s),e.addListener("endkeyframerule",s),e.addListener("endviewport",s)}}),i.addRule({id:"zero-units",name:"Disallow units for 0 values",desc:"You don't need to specify units when a value is 0.",url:"https://github.com/CSSLint/csslint/wiki/Disallow-units-for-zero-values",browsers:"All",init:function(e,t){"use strict";var r=this;e.addListener("property",(function(e){for(var n=e.value.parts,i=0,o=n.length;i<o;)!n[i].units&&"percentage"!==n[i].type||0!==n[i].value||"time"===n[i].type||t.report("Values of 0 shouldn't have units specified.",n[i].line,n[i].col,r),i++}))}}),function(){"use strict";var e=function(e){return e&&e.constructor===String?e.replace(/["&><]/g,(function(e){switch(e){case'"':return""";case"&":return"&";case"<":return"<";case">":return">"}})):""};i.addFormatter({id:"checkstyle-xml",name:"Checkstyle XML format",startFormat:function(){return'<?xml version="1.0" encoding="utf-8"?><checkstyle>'},endFormat:function(){return"</checkstyle>"},readError:function(t,r){return'<file name="'+e(t)+'"><error line="0" column="0" severty="error" message="'+e(r)+'"></error></file>'},formatResults:function(t,r){var n=t.messages,o=[];return n.length>0&&(o.push('<file name="'+r+'">'),i.Util.forEach(n,(function(t){var r;t.rollup||o.push('<error line="'+t.line+'" column="'+t.col+'" severity="'+t.type+'" message="'+e(t.message)+'" source="'+((r=t.rule)&&"name"in r?"net.csslint."+r.name.replace(/\s/g,""):"")+'"/>')})),o.push("</file>")),o.join("")}})}(),i.addFormatter({id:"compact",name:"Compact, 'porcelain' format",startFormat:function(){"use strict";return""},endFormat:function(){"use strict";return""},formatResults:function(e,t,r){"use strict";var n=e.messages,o="";r=r||{};var a=function(e){return e.charAt(0).toUpperCase()+e.slice(1)};return 0===n.length?r.quiet?"":t+": Lint Free!":(i.Util.forEach(n,(function(e){e.rollup?o+=t+": "+a(e.type)+" - "+e.message+" ("+e.rule.id+")\n":o+=t+": line "+e.line+", col "+e.col+", "+a(e.type)+" - "+e.message+" ("+e.rule.id+")\n"})),o)}}),i.addFormatter({id:"csslint-xml",name:"CSSLint XML format",startFormat:function(){"use strict";return'<?xml version="1.0" encoding="utf-8"?><csslint>'},endFormat:function(){"use strict";return"</csslint>"},formatResults:function(e,t){"use strict";var r=e.messages,n=[],o=function(e){return e&&e.constructor===String?e.replace(/"/g,"'").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"):""};return r.length>0&&(n.push('<file name="'+t+'">'),i.Util.forEach(r,(function(e){e.rollup?n.push('<issue severity="'+e.type+'" reason="'+o(e.message)+'" evidence="'+o(e.evidence)+'"/>'):n.push('<issue line="'+e.line+'" char="'+e.col+'" severity="'+e.type+'" reason="'+o(e.message)+'" evidence="'+o(e.evidence)+'"/>')})),n.push("</file>")),n.join("")}}),i.addFormatter({id:"json",name:"JSON",startFormat:function(){"use strict";return this.json=[],""},endFormat:function(){"use strict";var e="";return this.json.length>0&&(e=1===this.json.length?JSON.stringify(this.json[0]):JSON.stringify(this.json)),e},formatResults:function(e,t,r){"use strict";return(e.messages.length>0||!r.quiet)&&this.json.push({filename:t,messages:e.messages,stats:e.stats}),""}}),i.addFormatter({id:"junit-xml",name:"JUNIT XML format",startFormat:function(){"use strict";return'<?xml version="1.0" encoding="utf-8"?><testsuites>'},endFormat:function(){"use strict";return"</testsuites>"},formatResults:function(e,t){"use strict";var r=e.messages,n=[],i={error:0,failure:0},o=function(e){return e&&e.constructor===String?e.replace(/"/g,"'").replace(/</g,"<").replace(/>/g,">"):""};return r.length>0&&(r.forEach((function(e){var t,r="warning"===e.type?"error":e.type;e.rollup||(n.push('<testcase time="0" name="'+((t=e.rule)&&"name"in t?"net.csslint."+t.name.replace(/\s/g,""):"")+'">'),n.push("<"+r+' message="'+o(e.message)+'"><![CDATA['+e.line+":"+e.col+":"+o(e.evidence)+"]]></"+r+">"),n.push("</testcase>"),i[r]+=1)})),n.unshift('<testsuite time="0" tests="'+r.length+'" skipped="0" errors="'+i.error+'" failures="'+i.failure+'" package="net.csslint" name="'+t+'">'),n.push("</testsuite>")),n.join("")}}),i.addFormatter({id:"lint-xml",name:"Lint XML format",startFormat:function(){"use strict";return'<?xml version="1.0" encoding="utf-8"?><lint>'},endFormat:function(){"use strict";return"</lint>"},formatResults:function(e,t){"use strict";var r=e.messages,n=[],o=function(e){return e&&e.constructor===String?e.replace(/"/g,"'").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"):""};return r.length>0&&(n.push('<file name="'+t+'">'),i.Util.forEach(r,(function(e){if(e.rollup)n.push('<issue severity="'+e.type+'" reason="'+o(e.message)+'" evidence="'+o(e.evidence)+'"/>');else{var t="";e.rule&&e.rule.id&&(t='rule="'+o(e.rule.id)+'" '),n.push("<issue "+t+'line="'+e.line+'" char="'+e.col+'" severity="'+e.type+'" reason="'+o(e.message)+'" evidence="'+o(e.evidence)+'"/>')}})),n.push("</file>")),n.join("")}}),i.addFormatter({id:"text",name:"Plain Text",startFormat:function(){"use strict";return""},endFormat:function(){"use strict";return""},formatResults:function(e,t,r){"use strict";var n=e.messages,o="";if(r=r||{},0===n.length)return r.quiet?"":"\n\ncsslint: No errors in "+t+".";o="\n\ncsslint: There ",1===n.length?o+="is 1 problem":o+="are "+n.length+" problems",o+=" in "+t+".";var a=t.lastIndexOf("/"),s=t;return-1===a&&(a=t.lastIndexOf("\\")),a>-1&&(s=t.substring(a+1)),i.Util.forEach(n,(function(e,t){o=o+"\n\n"+s,e.rollup?(o+="\n"+(t+1)+": "+e.type,o+="\n"+e.message):(o+="\n"+(t+1)+": "+e.type+" at line "+e.line+", col "+e.col,o+="\n"+e.message,o+="\n"+e.evidence)})),o}}),i}();<script type="text/template" id="template-snippet-browser">
<div class="snippet-browser-overlay">
</div>
<div class="snippet-browser-dialog">
<div class="toolbar">
<h1><?php esc_html_e( 'CSS Snippets', 'so-css' ); ?></h1>
<span href="#" class="close">
<span class="icon"></span>
</span>
</div>
<div class="sidebar">
<input type="text" class="snippet-search" placeholder="<?php esc_attr_e( 'Search Snippets', 'so-css' ); ?>" />
<ul class="snippets">
</ul>
</div>
<div class="main">
<div class="snippet-view">
<h2 class="snippet-title"></h2>
<p class="snippet-description"></p>
<pre class="snippet-code"></pre>
</div>
</div>
<div class="buttons">
<input type="button" class="insert-snippet button-primary" value="<?php esc_attr_e( 'Insert Snippet', 'so-css' ); ?>" />
</div>
</div>
</script>
<script type="text/template" id="template-sides-field">
<div class="spacing-field">
<ul class="select-tabs side-tabs" data-type="box">
<li class="select-tab side-tab" data-direction="all"><div class="spacing-all"></div></li>
<li class="select-tab side-tab" data-direction="top"><div class="spacing-top"></div></li>
<li class="select-tab side-tab" data-direction="right"><div class="spacing-right"></div></li>
<li class="select-tab side-tab" data-direction="bottom"><div class="spacing-bottom"></div></li>
<li class="select-tab side-tab" data-direction="left"><div class="spacing-left"></div></li>
</ul>
<ul class="select-tabs side-tabs" data-type="radius">
<li class="select-tab side-tab" data-direction="all"><div class="spacing-all"></div></li>
<li class="select-tab side-tab" data-direction="top-right"><div class="spacing-top spacing-right"></div></li>
<li class="select-tab side-tab" data-direction="bottom-right"><div class="spacing-bottom spacing-right"></div></li>
<li class="select-tab side-tab" data-direction="bottom-left"><div class="spacing-bottom spacing-left"></div></li>
<li class="select-tab side-tab" data-direction="top-left"><div class="spacing-top spacing-left"></div></li>
</ul>
<ul class="sides">
</ul>
</div>
</script>
<script type="text/template" id="template-preview-window">
<div id="preview-navigator">
<input type="text" data-invalid-uri="<?php esc_attr_e( "Invalid URI. Please make sure you're using a URL from the same site.", 'so-css' ); ?>" />
</div>
<iframe id="preview-iframe" seamless="seamless"></iframe>
</script>
<script type="text/template" id="template-webfont-teaser">
<input type="text" value="" class="socss-property-controller-input"/>
<small style="color: #888">
<?php
printf(
esc_html__( 'Get a %sGoogle Font%s selector.', 'so-css' ),
'<a href="https://siteorigin.com/downloads/premium/?featured_addon=plugin/web-font-selector" target="_blank">',
'</a>'
);
?>
</small>
</script>
<div id="socss-inspector-interface" class="socss-element">
<div class="socss-link">
<?php esc_html_e( 'Navigate To: ', 'so-css' ); ?>: <a href="#"></a>
</div>
<div class="socss-toolbar">
<div class="socss-enable-inspector dashicons dashicons-search"></div>
<div class="socss-hierarchy"></div>
</div>
<div class="socss-selectors-window">
</div>
<div class="socss-properties-window">
</div>
</div>
<script type="text/template" id="socss-template-hover">
<div class="socss-inspector-hover socss-element">
<div class="socss-guide socss-guide-margin socss-guide-top"></div>
<div class="socss-guide socss-guide-margin socss-guide-bottom"></div>
<div class="socss-guide socss-guide-margin socss-guide-left"></div>
<div class="socss-guide socss-guide-margin socss-guide-right"></div>
<div class="socss-guide socss-guide-padding socss-guide-top"></div>
<div class="socss-guide socss-guide-padding socss-guide-bottom"></div>
<div class="socss-guide socss-guide-padding socss-guide-left"></div>
<div class="socss-guide socss-guide-padding socss-guide-right"></div>
</div>
</script>
<?php
/**
* @var $page_title string The title of the page. Includes the post title if a post was selected.
* @var $custom_css string The custom CSS string to be edited.
* @var $current_revision int If the CSS to be edited is a revision, this will contain the timestamp of the revision.
* @var $custom_css_revisions array Saved revisions for the current theme.
* @var $editor_description string Description to provide context for the CSS being edited.
* @var $socss_post_id int ID of the post for which we're editing CSS.
* @var $save_button_label string Label of the save button depending on whether a post or revision has been selected.
* @var $form_save_url string URL to use when saving the CSS.
*/
$snippets = SiteOrigin_CSS::single()->get_snippets();
$user = wp_get_current_user();
if ( ! empty( $current_revision ) ) {
$revision_date = date( 'j F Y @ H:i:s', $current_revision + get_option( 'gmt_offset' ) * 60 * 60 );
}
?>
<div class="wrap" id="siteorigin-custom-css">
<h2>
<img src="<?php echo plugin_dir_url( __FILE__ ) . '../css/images/icon.png'; ?>" class="icon" />
<?php echo esc_html( $page_title ); ?>
</h2>
<?php if ( isset( $_POST['siteorigin_custom_css'] ) ) { ?>
<div class="notice notice-success"><p><?php esc_html_e( 'Site design updated.', 'so-css' ); ?></p></div>
<?php } ?>
<?php if ( ! empty( $current_revision ) ) { ?>
<div class="notice notice-warning">
<p><?php printf( esc_html__( 'Editing revision dated %s. Click %sRevert to this revision%s to keep using it.', 'so-css' ), $revision_date, '<em>', '</em>' ); ?></p>
</div>
<?php } ?>
<div id="poststuff">
<form action="<?php echo esc_url( $form_save_url ); ?>" method="POST">
<div id="so-custom-css-info">
<p class="so-custom-css-submit">
<input type="submit" name="siteorigin_custom_css_save" class="button-primary" value="<?php esc_attr_e( $save_button_label ); ?>" />
</p>
<?php if ( $this->display_teaser() ) { ?>
<div class="postbox">
<h3 class="hndle"><span><?php esc_html_e( 'Get The Full Experience', 'so-css' ); ?></span></h3>
<div class="inside">
<?php printf( wp_kses_post( __( '%sSiteOrigin Premium%s adds a <strong>Google Web Font</strong> selector to SiteOrigin CSS so you can easily change any font.', 'so-css' ) ), '<a href="https://siteorigin.com/downloads/premium/?featured_addon=plugin/web-font-selector" target="_blank">', '</a>' ); ?>
</div>
</div>
<?php } ?>
<?php if ( ! get_user_meta( $user->ID, 'socss_hide_gs' ) ) { ?>
<div class="postbox" id="so-custom-css-getting-started">
<h3 class="hndle">
<span><?php esc_html_e( 'Getting Started Video', 'so-css' ); ?></span>
<a href="<?php echo wp_nonce_url( admin_url( 'admin-ajax.php?action=socss_hide_getting_started' ), 'hide' ); ?>" class="hide"><?php esc_html_e( 'Dismiss', 'so-css' ); ?></a>
</h3>
<div class="inside">
<a href="https://siteorigin.com/css/getting-started/" target="_blank"><img src="<?php echo plugin_dir_url( __FILE__ ) . '../css/images/video.jpg'; ?>" /></a>
</div>
</div>
<?php } ?>
<div class="postbox" id="so-custom-css-revisions">
<h3 class="hndle"><span><?php esc_html_e( 'CSS Revisions', 'so-css' ); ?></span></h3>
<div class="inside">
<ol class="custom-revisions-list" data-confirm="<?php esc_attr_e( 'Are you sure you want to load this revision?', 'so-css' ); ?>">
<?php $this->custom_css_revisions_list( $theme, $socss_post_id, $current_revision ); ?>
</ol>
</div>
</div>
<div class="postbox" id="so-custom-css-editor-theme">
<h3 class="hndle"><span><?php esc_html_e( 'Editor Theme', 'so-css' ); ?></span></h3>
<div class="inside">
<select name="so_css_editor_theme" id="so_css_editor_theme">
<option value="neat" <?php selected( 'neat', $editor_theme ); ?>><?php esc_attr_e( 'Light', 'so-css' ); ?></option>
<option value="ambiance" <?php selected( 'ambiance', $editor_theme ); ?>><?php esc_attr_e( 'Dark', 'so-css' ); ?></option>
</select>
</div>
</div>
<div class="color-theme">
</div>
</div>
<div id="so-custom-css-form">
<div class="custom-css-toolbar">
<div class="toolbar-function-buttons">
<div class="toolbar-functions-dropdown">
<span class="dashicons dashicons-menu"></span>
</div>
<ul class="toolbar-buttons">
</ul>
</div>
<div class="toolbar-action-buttons">
<a href="#expand" class="editor-expand socss-button" title="<?php esc_attr_e( 'Open Expanded Mode', 'so-css' ); ?>">
<span class="so-css-icon so-css-icon-expand" title="<?php esc_attr_e( 'Open Expanded Mode', 'so-css' ); ?>"></span>
<span class="so-css-icon so-css-icon-compress" title="<?php esc_attr_e( 'Close Expanded Mode', 'so-css' ); ?>"></span>
</a>
<a href="#visual" class="editor-visual socss-button" title="<?php esc_attr_e( 'Open Visual Mode', 'so-css' ); ?>">
<span class="so-css-icon so-css-icon-eye"></span>
</a>
<span class="save socss-button button-primary" title="<?php esc_attr_e( 'Save CSS', 'so-css' ); ?>">
<span class="so-css-icon so-css-icon-save"></span>
</span>
</div>
</div>
<div class="custom-css-container">
<textarea
name="siteorigin_custom_css" id="custom-css-textarea" data-theme="<?php echo esc_attr( $editor_theme ); ?>" class="css-editor" rows="<?php echo max( 10, substr_count( $custom_css, "\n" ) + 1 ); ?>"><?php echo esc_textarea( $custom_css ); ?></textarea>
<?php wp_nonce_field( 'custom_css', '_sononce' ); ?>
</div>
<div class="so-css-footer">
<p class="description">
<?php esc_html_e( $editor_description ); ?>
</p>
</div>
<?php
if (
! class_exists( 'SiteOrigin_Panels' ) &&
! class_exists( 'SiteOrigin_Widgets_Bundle' ) &&
! class_exists( 'SiteOrigin_Premium' )
) {
?>
<div class="installer">
<a href="#" class="installer-link">
<?php _e( 'Other Settings', 'so-css' ); ?>
</a>
<div class="installer-container" style="display: none;">
<label>
<?php echo __( 'Enable SiteOrigin Installer: ', 'so-css' ); ?>
<input
type="checkbox"
name="installer_status"
class="installer_status"
<?php checked( get_option( 'siteorigin_installer', false ), 1 ); ?>
data-nonce="<?php echo wp_create_nonce( 'siteorigin_installer_status' ); ?>"
>
</label>
</div>
</div>
<?php } ?>
<div class="custom-css-preview"></div>
<div class="decoration"></div>
</div>
<div id="so-custom-css-properties">
<div class="toolbar">
<select></select>
<div class="close socss-button" title="<?php esc_attr_e( 'Close', 'so-css' ); ?>">
<span class="so-css-icon so-css-icon-check"></span>
</div>
<div class="save socss-button button-primary" title="<?php esc_attr_e( 'Save CSS', 'so-css' ); ?>">
<span class="so-css-icon so-css-icon-save"></span>
</div>
</div>
<ul class="section-tabs"></ul>
<div class="sections"></div>
</div>
</form>
</div>
<div class="clear"></div>
</div>
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
<?php
/*
Plugin Name: SiteOrigin CSS
Description: An advanced CSS editor from SiteOrigin.
Version: 1.5.10
Author: SiteOrigin
Author URI: https://siteorigin.com
Plugin URI: https://siteorigin.com/css/
License: GPL3
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
Text Domain: so-css
*/
// Handle the legacy CSS editor that came with SiteOrigin themes
include plugin_dir_path( __FILE__ ) . 'inc/legacy.php';
define( 'SOCSS_VERSION', '1.5.10' );
define( 'SOCSS_JS_SUFFIX', '.min' );
/**
* Class SiteOrigin_CSS The main class for the SiteOrigin CSS Editor
*/
class SiteOrigin_CSS {
private $theme;
private $snippet_paths;
private $css_file;
public function __construct() {
$this->theme = basename( get_template_directory() );
$this->snippet_paths = array();
// Main header actions
add_action( 'plugins_loaded', array( $this, 'set_plugin_textdomain' ) );
global $wp_filesystem;
if ( ! class_exists( 'wp_filesystem' ) ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();
}
// Priority 20 is necessary to ensure our CSS takes precedence.
add_action( 'wp_head', array( $this, 'enqueue_css' ), 20 );
// All the admin actions
add_action( 'admin_menu', array( $this, 'action_admin_menu' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 );
add_action( 'admin_enqueue_scripts', array( $this, 'dequeue_admin_scripts' ), 19 );
add_action( 'load-appearance_page_so_custom_css', array( $this, 'add_help_tab' ) );
// Add the action links.
add_action( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
// The request to hide the getting started video
add_action( 'wp_ajax_socss_hide_getting_started', array( $this, 'admin_action_hide_getting_started' ) );
add_action( 'wp_ajax_socss_get_post_css', array( $this, 'admin_action_get_post_css' ) );
add_action( 'wp_ajax_socss_get_revisions_list', array( $this, 'admin_action_get_revisions_list' ) );
add_action( 'wp_ajax_socss_save_css', array( $this, 'admin_action_save_css' ) );
if ( ! is_admin() ) {
if ( isset( $_GET['so_css_preview'] ) ) {
add_action( 'plugins_loaded', array( $this, 'disable_ngg_resource_manager' ) );
add_filter( 'show_admin_bar', '__return_false' );
add_filter( 'wp_enqueue_scripts', array( $this, 'enqueue_inspector_scripts' ) );
add_filter( 'wp_footer', array( $this, 'inspector_templates' ) );
// We'll be grabbing all the enqueued scripts and outputting them
add_action( 'wp_enqueue_scripts', array( $this, 'inline_inspector_scripts' ), 100 );
}
} elseif ( ! class_exists( 'SiteOrigin_Installer' ) ) {
include plugin_dir_path( __FILE__ ) . 'inc/installer/siteorigin-installer.php';
if (
! class_exists( 'SiteOrigin_Panels' ) &&
! class_exists( 'SiteOrigin_Widgets_Bundle' ) &&
! class_exists( 'SiteOrigin_Premium' )
) {
add_filter( 'siteorigin_add_installer', array( $this, 'manage_installer' ) );
}
}
}
/**
* Get a singleton of the SiteOrigin CSS.
*
* @return SiteOrigin_CSS
*/
public static function single() {
static $single;
if ( empty( $single ) ) {
$single = new SiteOrigin_CSS();
}
return $single;
}
public function manage_installer( $status ) {
// If the user hasn't enabled/disabled the installer, disable it by default.
if ( empty( get_option( 'siteorigin_installer' ) ) ) {
$status = false;
}
return $status;
}
/**
* Retrieve the current custom CSS for a given theme and post id combination.
*
* @param $theme string The name of the theme for which to retrieve custom CSS.
* @param $post_id int The ID of the specific post for which to retrieve custom CSS.
*
* @return string The custom CSS for the theme and post ID combination.
*/
public function get_custom_css( $theme, $post_id = null ) {
$css_key = 'siteorigin_custom_css[' . $theme . ']';
if ( empty( $post_id ) && WP_Filesystem() ) {
$custom_css_file = apply_filters( 'siteorigin_custom_css_file', false );
if (
! empty( $custom_css_file ) &&
! empty( $custom_css_file['file'] )
) {
// Did we previously load the CSS file? If not, load it.
if ( empty( $this->css_file ) || isset( $_POST['siteorigin_custom_css'] ) ) {
global $wp_filesystem;
// If custom file doesn't exist, create it.
if ( ! $wp_filesystem->exists( $custom_css_file['file'] ) ) {
$wp_filesystem->touch( $custom_css_file['file'] );
}
if ( empty( get_option( 'siteorigin_custom_file' ) ) ) {
update_option( 'siteorigin_custom_file', true, true );
}
if ( $wp_filesystem->is_writable( $custom_css_file['file'] ) ) {
$this->css_file = $wp_filesystem->get_contents( $custom_css_file['file'] );
}
}
return $this->css_file;
} elseif ( ! empty( get_option( 'siteorigin_custom_file' ) ) ) {
// If the custom file filter was previously active we need to
// generate the global CSS file to avoid no CSS outputting
// without modification.
delete_option( 'siteorigin_custom_file', true );
$css_file_path = $this->get_css_file_name( $theme );
global $wp_filesystem;
$wp_filesystem->put_contents(
$css_file_path,
get_option( $css_key, '' )
);
}
}
if ( ! empty( $post_id ) ) {
return get_post_meta( $post_id, $css_key, true );
}
return get_option( $css_key, '' );
}
/**
* Save custom CSS for a given theme and post id combination.
*
* @param $custom_css string The custom CSS to save.
* @param $theme string The name of the theme for which to save custom CSS.
* @param $post_id int The ID of the specific post for which to save custom CSS.
*
* @return bool Whether or not saving the custom CSS was successful.
*/
public function save_custom_css( $custom_css, $theme, $post_id = null ) {
$css_key = 'siteorigin_custom_css[' . $theme . ']';
if ( empty( $post_id ) ) {
$current = get_option( $css_key );
if ( $current === false ) {
return add_option( $css_key, $custom_css, '', 'no' );
} else {
return update_option( $css_key, $custom_css );
}
}
if ( metadata_exists( 'post', $post_id, $css_key ) ) {
return update_post_meta( $post_id, $css_key, $custom_css );
}
return add_post_meta( $post_id, $css_key, $custom_css );
}
/**
* Returns the file name of the CSS file we're editing.
*
* @param null $post_id
*/
public function get_css_file_name( $theme, $post_id = null ) {
global $wp_filesystem;
$upload_dir = wp_upload_dir();
$upload_dir_path = $upload_dir['basedir'] . '/so-css/';
if ( ! $wp_filesystem->is_dir( $upload_dir_path ) ) {
$wp_filesystem->mkdir( $upload_dir_path );
}
$css_file_name = 'so-css-' . $theme . ( ! empty( $post_id ) ? '_' . $post_id : '' );
return $upload_dir_path . $css_file_name . '.css';
}
/**
* Save custom CSS for a given theme and post id combination to a file in the uploads directory to allow for caching.
*
* @param null $post_id
*/
public function save_custom_css_file( $custom_css, $theme, $post_id = null ) {
if ( WP_Filesystem() ) {
global $wp_filesystem;
$css_file_path = apply_filters( 'siteorigin_custom_css_file', false );
if (
empty( $css_file_path ) ||
empty( $css_file_path['file'] ) ||
! $wp_filesystem->is_writable( $css_file_path['file'] )
) {
$css_file_path = $this->get_css_file_name( $theme, $post_id );
if ( file_exists( $css_file_path ) ) {
$wp_filesystem->delete( $css_file_path );
}
} else {
$css_file_path = $css_file_path['file'];
$this->css_file = $custom_css;
}
$wp_filesystem->put_contents(
$css_file_path,
$custom_css
);
}
}
/**
* Retrieve the previous revisions of custom CSS for a given theme and post id combination.
*
* @param $theme string The name of the theme for which to retrieve custom CSS revisions.
* @param $post_id int The ID of the specific post for which to retrieve custom CSS revisions.
*
* @return array The custom CSS revisions for the theme and post ID combination.
*/
public function get_custom_css_revisions( $theme, $post_id = null ) {
$css_key = 'siteorigin_custom_css_revisions[' . $theme . ']';
if ( empty( $post_id ) ) {
return get_option( $css_key, '' );
}
return get_post_meta( $post_id, $css_key, true );
}
/**
* Adds a custom CSS revision for a given theme and post id combination.
*
* @param $custom_css string The custom CSS to add as a revision.
* @param $theme string The name of the theme for which to save custom CSS.
* @param $post_id int The ID of the specific post for which to save custom CSS.
*
* @return bool Whether or not adding the custom CSS revision was successful.
*/
public function add_custom_css_revision( $custom_css, $theme, $post_id = null ) {
$revisions = $this->get_custom_css_revisions( $this->theme, $post_id );
$css_key = 'siteorigin_custom_css_revisions[' . $theme . ']';
if ( empty( $revisions ) ) {
$revisions = array();
if ( empty( $post_id ) ) {
add_option( $css_key, $revisions, '', 'no' );
} else {
add_post_meta( $post_id, $css_key, $revisions );
}
}
$revisions[ time() ] = $custom_css;
// Sort the revisions and cut off any old ones.
krsort( $revisions );
$revisions = array_slice( $revisions, 0, 15, true );
if ( empty( $post_id ) ) {
return update_option( $css_key, $revisions );
}
return update_post_meta( $post_id, $css_key, $revisions );
}
/**
* Enqueue or print inline CSS.
*/
public function enqueue_css() {
$this->enqueue_custom_css( $this->theme );
if ( is_singular() ) {
$this->enqueue_custom_css( $this->theme, get_the_ID() );
}
}
/**
* Enqueue the custom CSS for the given theme and post id combination.
*
* @param $theme string The name of the theme for which to enqueue custom CSS.
* @param $post_id int The ID of the specific post for which to enqueue custom CSS.
*/
public function enqueue_custom_css( $theme, $post_id = null ) {
$css_id = $theme . ( ! empty( $post_id ) ? '_' . $post_id : '' );
if (
empty( $_GET['so_css_preview'] ) &&
! is_admin() &&
apply_filters( 'siteorigin_css_enqueue_css', true )
) {
$custom_css_file = apply_filters( 'siteorigin_custom_css_file', array() );
if ( ! empty( $post_id ) || empty( $custom_css_file ) ) {
$upload_dir = wp_upload_dir();
$upload_dir_path = $upload_dir['basedir'] . '/so-css/';
$css_file_name = 'so-css-' . $css_id;
$css_file_path = $upload_dir_path . $css_file_name . '.css';
$css_file_url = $upload_dir['baseurl'] . '/so-css/' . $css_file_name . '.css';
} elseif ( isset( $custom_css_file['url'] ) ) {
$css_file_path = $custom_css_file['file'];
$css_file_url = $custom_css_file['url'];
}
if ( ! empty( $css_file_path ) && file_exists( $css_file_path ) ) {
wp_enqueue_style(
'so-css-' . $css_id,
set_url_scheme( $css_file_url ),
array(),
$this->get_latest_revision_timestamp()
);
}
} else {
$custom_css = $this->get_custom_css( $theme, $post_id );
// We just need to enqueue a dummy style
if ( ! empty( $custom_css ) ) {
echo "<style id='" . sanitize_html_class( $css_id ) . "-custom-css' class='siteorigin-custom-css' type='text/css'>\n";
echo self::sanitize_css( $custom_css ) . "\n";
echo "</style>\n";
}
}
}
public function set_plugin_textdomain() {
load_plugin_textdomain( 'so-css', false, plugin_dir_path( __FILE__ ) . 'lang/' );
}
/**
* Action to run on the admin action.
*/
public function action_admin_menu() {
add_theme_page( esc_html__( 'Custom CSS', 'so-css' ), esc_html__( 'Custom CSS', 'so-css' ), 'edit_theme_options', 'so_custom_css', array(
$this,
'display_admin_page',
) );
if ( current_user_can( 'edit_theme_options' ) && isset( $_POST['siteorigin_custom_css'] ) ) {
check_admin_referer( 'custom_css', '_sononce' );
// Sanitize CSS input. Should keep most tags, apart from script and style tags.
$custom_css = self::sanitize_css( filter_input( INPUT_POST, 'siteorigin_custom_css' ) );
$socss_post_id = filter_input( INPUT_GET, 'socss_post_id', FILTER_VALIDATE_INT );
if ( empty( $this->css_file ) ) {
$current = $this->get_custom_css( $this->theme, $socss_post_id );
$this->save_custom_css( $custom_css, $this->theme, $socss_post_id );
} else {
$current = $this->css_file;
}
// If this has changed, then add a revision.
if ( $current != $custom_css ) {
$this->add_custom_css_revision( $custom_css, $this->theme, $socss_post_id );
$this->save_custom_css_file( $custom_css, $this->theme, $socss_post_id );
}
// Update Editor Theme.
if (
$_POST['so_css_editor_theme'] == 'neat' ||
$_POST['so_css_editor_theme'] == 'ambiance'
) {
update_option( 'so_css_editor_theme', $_POST['so_css_editor_theme'] );
}
}
}
/**
* Display the help tab
*/
public function add_help_tab() {
$screen = get_current_screen();
$screen->add_help_tab( array(
'id' => 'custom-css',
'title' => esc_html__( 'Custom CSS', 'so-css' ),
'content' => '<p>'
. sprintf( esc_html__( "SiteOrigin CSS adds any custom CSS you enter here into your site's header. ", 'so-css' ) )
. esc_html__( "These changes will persist across updates so it's best to make all your changes here. ", 'so-css' )
. '</p>',
) );
}
public function enqueue_admin_scripts( $page ) {
if ( $page != 'appearance_page_so_custom_css' ) {
return;
}
// Core WordPress stuff that we use
wp_enqueue_media();
global $wp_version;
if ( version_compare( $wp_version, '4.9', '>=' ) && wp_get_current_user()->syntax_highlighting ) {
wp_enqueue_code_editor(
array(
'type' => 'css',
'codemirror' => array(
'lint' => true,
),
)
);
} else {
$this->enqueue_fallback_codemirror();
}
wp_enqueue_style( 'socss-codemirror-theme-neat', plugin_dir_url( __FILE__ ) . 'lib/codemirror/theme/neat.css', array(), SOCSS_VERSION );
wp_enqueue_style( 'socss-codemirror-theme-ambiance', plugin_dir_url( __FILE__ ) . 'lib/codemirror/theme/ambiance.css', array(), SOCSS_VERSION );
// Enqueue the scripts for theme CSS processing
wp_enqueue_script( 'siteorigin-css-parser-lib', plugin_dir_url( __FILE__ ) . 'js/css' . SOCSS_JS_SUFFIX . '.js', array( 'jquery' ), SOCSS_VERSION );
// There are conflicts between CSS linting and the built in WordPress color picker, so use something else
wp_enqueue_style( 'siteorigin-custom-css-minicolors', plugin_dir_url( __FILE__ ) . 'lib/minicolors/jquery.minicolors.css', array(), '2.1.7' );
wp_enqueue_script( 'siteorigin-custom-css-minicolors', plugin_dir_url( __FILE__ ) . 'lib/minicolors/jquery.minicolors' . SOCSS_JS_SUFFIX . '.js', array( 'jquery' ), '2.1.7' );
// URI parsing for preview navigation
wp_enqueue_script( 'siteorigin-uri', plugin_dir_url( __FILE__ ) . 'js/URI' . SOCSS_JS_SUFFIX . '.js', array(), SOCSS_VERSION, true );
// All the custom SiteOrigin CSS stuff
wp_enqueue_script( 'siteorigin-custom-css', plugin_dir_url( __FILE__ ) . 'js/editor' . SOCSS_JS_SUFFIX . '.js', array( 'jquery', 'underscore', 'backbone' ), SOCSS_VERSION, true );
wp_enqueue_style( 'siteorigin-custom-css', plugin_dir_url( __FILE__ ) . 'css/admin.css', array( ), SOCSS_VERSION );
// Pretty confusing, but it seems we should be using `home_url` and NOT `site_url`
// as described here => https://wordpress.stackexchange.com/a/50605
$init_url = home_url();
if ( ! empty( $socss_post_id ) && is_int( $socss_post_id ) ) {
$init_url = set_url_scheme( get_permalink( $socss_post_id ) );
}
$open_visual_editor = ! empty( $_REQUEST['open_visual_editor'] );
$home_url = add_query_arg( 'so_css_preview', '1', $init_url );
wp_localize_script( 'siteorigin-custom-css', 'socssOptions', array(
'homeURL' => $home_url,
'postCssUrlRoot' => wp_nonce_url( admin_url( 'admin-ajax.php?action=socss_get_post_css' ), 'get_post_css' ),
'getRevisionsListAjaxUrl' => wp_nonce_url( admin_url( 'admin-ajax.php?action=socss_get_revisions_list' ), 'get_revisions_list' ),
'ajaxurl' => wp_nonce_url( admin_url( 'admin-ajax.php' ), 'so-css-ajax' ),
'openVisualEditor' => $open_visual_editor,
'propertyControllers' => apply_filters( 'siteorigin_css_property_controllers', $this->get_property_controllers() ),
'loc' => array(
'unchanged' => esc_html__( 'Unchanged', 'so-css' ),
'select' => esc_html__( 'Select', 'so-css' ),
'select_image' => esc_html__( 'Select Image', 'so-css' ),
'leave' => esc_html__( 'Are you sure you want to leave without saving?', 'so-css' ),
),
) );
// This is for the templates required by the CSS editor. Ideally this would be out in the footer, but we need
// it earlier for dependent scripts.
include plugin_dir_path( __FILE__ ) . 'tpl/js-templates.php';
}
// Handles loading the fallback version of CodeMirror.
public function enqueue_fallback_codemirror() {
// Enqueue the codemirror scripts. Call Underscore and Backbone dependencies so they're enqueued first to prevent conflicts.
wp_enqueue_script( 'socss-codemirror', plugin_dir_url( __FILE__ ) . 'lib/codemirror/lib/codemirror' . SOCSS_JS_SUFFIX . '.js', array( 'underscore', 'backbone' ), '5.2.0' );
wp_enqueue_script( 'socss-codemirror-mode-css', plugin_dir_url( __FILE__ ) . 'lib/codemirror/mode/css/css' . SOCSS_JS_SUFFIX . '.js', array(), '5.2.0' );
// Add in all the linting libs
wp_enqueue_script( 'socss-codemirror-lint', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/lint/lint' . SOCSS_JS_SUFFIX . '.js', array( 'socss-codemirror' ), '5.2.0' );
wp_enqueue_script( 'socss-codemirror-lint-css', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/lint/css-lint' . SOCSS_JS_SUFFIX . '.js', array(
'socss-codemirror',
'socss-codemirror-lint-css-lib',
), '5.2.0' );
wp_enqueue_script( 'socss-codemirror-lint-css-lib', plugin_dir_url( __FILE__ ) . 'js/csslint' . SOCSS_JS_SUFFIX . '.js', array(), '0.10.0' );
// The CodeMirror autocomplete library
wp_enqueue_script( 'socss-codemirror-show-hint', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/hint/show-hint' . SOCSS_JS_SUFFIX . '.js', array( 'socss-codemirror' ), '5.2.0' );
// CodeMirror search and dialog addons
wp_enqueue_script( 'socss-codemirror-dialog', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/dialog/dialog' . SOCSS_JS_SUFFIX . '.js', array( 'socss-codemirror' ), '5.2.0' );
wp_enqueue_script( 'socss-codemirror-search', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/search/search' . SOCSS_JS_SUFFIX . '.js', array( 'socss-codemirror' ), '5.37.0' );
wp_enqueue_script( 'socss-codemirror-search-searchcursor', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/search/searchcursor' . SOCSS_JS_SUFFIX . '.js', array( 'socss-codemirror', 'socss-codemirror-search' ), '5.37.0' );
wp_enqueue_script( 'socss-codemirror-search-match-cursor', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/search/match-highlighter' . SOCSS_JS_SUFFIX . '.js', array( 'socss-codemirror', 'socss-codemirror-search' ), '5.37.0' );
wp_enqueue_script( 'socss-codemirror-search-matchesonscrollbar', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/search/matchesonscrollbar' . SOCSS_JS_SUFFIX . '.js', array( 'socss-codemirror', 'socss-codemirror-search' ), '5.37.0' );
wp_enqueue_script( 'socss-codemirror-scroll-annotatescrollbar', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/scroll/annotatescrollbar' . SOCSS_JS_SUFFIX . '.js', array( 'socss-codemirror', 'socss-codemirror-search', 'socss-codemirror-search-matchesonscrollbar' ), '5.37.0' );
wp_enqueue_script( 'socss-codemirror-jump-to-line', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/search/jump-to-line' . SOCSS_JS_SUFFIX . '.js', array( 'socss-codemirror', 'socss-codemirror-search' ), '5.37.0' );
// All the CodeMirror styles
wp_enqueue_style( 'socss-codemirror', plugin_dir_url( __FILE__ ) . 'lib/codemirror/lib/codemirror.css', array(), '5.2.0' );
wp_enqueue_style( 'socss-codemirror-lint-css', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/lint/lint.css', array(), '5.2.0' );
wp_enqueue_style( 'socss-codemirror-show-hint', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/hint/show-hint.css', array(), '5.2.0' );
wp_enqueue_style( 'socss-codemirror-dialog', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/dialog/dialog.css', '5.2.0' );
wp_enqueue_style( 'socss-codemirror-search-matchesonscrollbar', plugin_dir_url( __FILE__ ) . 'lib/codemirror/addon/search/matchesonscrollbar.css', array(), '5.37.0' );
}
public function dequeue_admin_scripts( $page ) {
if ( $page != 'appearance_page_so_custom_css' ) {
return;
}
// Dequeue the core WordPress color picker on the custom CSS page.
// This script causes conflicts and other plugins seem to be enqueueing it on the SO CSS admin page.
wp_dequeue_script( 'wp-color-picker' );
wp_dequeue_style( 'wp-color-picker' );
}
/**
* Get all the available property controllers
*/
public function get_property_controllers() {
return include plugin_dir_path( __FILE__ ) . 'inc/controller-config.php';
}
public function plugin_action_links( $links ) {
if ( isset( $links['edit'] ) ) {
unset( $links['edit'] );
}
$links['css_editor'] = '<a href="' . admin_url( 'themes.php?page=so_custom_css' ) . '">' . esc_html__( 'CSS Editor', 'so-css' ) . '</a>';
$links['support'] = '<a href="https://siteorigin.com/thread/" target="_blank">' . esc_html__( 'Support', 'so-css' ) . '</a>';
if ( apply_filters( 'siteorigin_premium_upgrade_teaser', true ) && ! defined( 'SITEORIGIN_PREMIUM_VERSION' ) ) {
$links['addons'] = '<a href="https://siteorigin.com/downloads/premium/?featured_addon=plugin/web-font-selector" style="color: #3db634" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Addons', 'so-css' ) . '</a>';
}
return $links;
}
public function display_admin_page() {
$socss_post_id = filter_input( INPUT_GET, 'socss_post_id', FILTER_VALIDATE_INT );
$theme = filter_input( INPUT_GET, 'theme' );
$time = filter_input( INPUT_GET, 'time', FILTER_VALIDATE_INT );
$page_title = esc_html__( 'SiteOrigin CSS', 'so-css' );
$theme_obj = wp_get_theme();
$theme_name = $theme_obj->get( 'Name' );
$editor_description = sprintf( esc_html__( 'Changes apply to %s and its child themes', 'so-css' ), $theme_name );
$save_button_label = esc_html__( 'Save CSS', 'so-css' );
$form_save_url = admin_url( 'themes.php?page=so_custom_css' );
if ( ! empty( $socss_post_id ) ) {
$selected_post = get_post( $socss_post_id );
$page_title = sprintf(
esc_html__( 'Editing CSS for: %s', 'so-css' ),
$selected_post->post_title
);
$editor_description = sprintf(
esc_html__( 'Changes apply to the %s %s when the current theme is %s or its child themes', 'so-css' ),
$selected_post->post_type,
$selected_post->post_title,
$theme_name
);
$post_type_obj = get_post_type_object( $selected_post->post_type );
$post_type_labels = $post_type_obj->labels;
$save_button_label = sprintf( esc_html__( 'Save %s CSS', 'so-css' ), $post_type_labels->singular_name );
$form_save_url = add_query_arg( 'socss_post_id', urlencode( $socss_post_id ), $form_save_url );
}
$custom_css = $this->get_custom_css( $this->theme, $socss_post_id );
$custom_css_revisions = $this->get_custom_css_revisions( $this->theme, $socss_post_id );
$current_revision = 0;
if ( ! empty( $theme ) && $theme == $this->theme && ! empty( $time ) && ! empty( $custom_css_revisions[ $time ] ) ) {
$current_revision = $time;
$custom_css = $custom_css_revisions[ $time ];
}
if ( ! empty( $current_revision ) ) {
$save_button_label = esc_html__( 'Revert to this revision', 'so-css' );
}
if ( ! empty( $custom_css_revisions ) ) {
krsort( $custom_css_revisions );
}
$theme = basename( get_template_directory() );
$editor_theme = get_option( 'so_css_editor_theme', 'neat' );
include plugin_dir_path( __FILE__ ) . 'tpl/page.php';
}
public function display_teaser() {
return apply_filters( 'siteorigin_premium_upgrade_teaser', true ) &&
! defined( 'SITEORIGIN_PREMIUM_VERSION' );
}
/**
* Generates the url to edit the custom CSS for a post.
*/
public function get_edit_css_link( $post ) {
$url = admin_url( 'themes.php?page=so_custom_css' );
if ( ! is_int( $post ) ) {
$post = get_post( $post );
$post = $post->ID;
}
return empty( $post ) ? $url : add_query_arg( array(
'socss_post_id' => urlencode( $post ),
'open_visual_editor' => 1,
), $url );
}
public function admin_action_hide_getting_started() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'hide' ) ) {
return;
}
$user = wp_get_current_user();
if ( ! empty( $user ) ) {
update_user_meta( $user->ID, 'socss_hide_gs', true );
}
}
/**
* Retrieves the post specific CSS for the supplied postId.
*/
public function admin_action_get_post_css() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'get_post_css' ) ) {
wp_die(
esc_html__( 'The supplied nonce is invalid.', 'so-css' ),
esc_html__( 'Invalid nonce.', 'so-css' ),
403
);
}
$post_id = filter_input( INPUT_GET, 'postId', FILTER_VALIDATE_INT );
$current = $this->get_custom_css( $this->theme, $post_id );
$url = empty( $post_id ) ? home_url() : set_url_scheme( get_permalink( $post_id ) );
wp_send_json( array( 'css' => empty( $current ) ? '' : $current, 'postUrl' => $url ) );
}
/**
* Retrieves the past revisions of post specific CSS for the supplied postId.
*/
public function admin_action_get_revisions_list() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'get_revisions_list' ) ) {
wp_die(
esc_html__( 'The supplied nonce is invalid.', 'so-css' ),
esc_html__( 'Invalid nonce.', 'so-css' ),
403
);
}
$post_id = filter_input( INPUT_GET, 'postId', FILTER_VALIDATE_INT );
$this->custom_css_revisions_list( $this->theme, $post_id );
wp_die();
}
/**
* Retrieves the past revisions of post specific CSS for the supplied postId.
*/
public function admin_action_save_css() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'so-css-ajax' ) ) {
wp_die(
esc_html__( 'The supplied nonce is invalid.', 'so-css' ),
esc_html__( 'Invalid nonce.', 'so-css' ),
403
);
}
if ( current_user_can( 'edit_theme_options' ) && isset( $_POST['css'] ) ) {
// Sanitize CSS input. Should keep most tags, apart from script and style tags.
$custom_css = self::sanitize_css( stripslashes( $_POST['css'] ) );
if ( empty( $this->css_file ) ) {
$current = $this->get_custom_css( $this->theme );
$this->save_custom_css( $custom_css, $this->theme );
} else {
$current = $this->css_file;
}
// If this has changed, then add a revision.
if ( $current != $custom_css ) {
$this->add_custom_css_revision( $custom_css, $this->theme );
$this->save_custom_css_file( $custom_css, $this->theme );
// Output the full revisions list.
$this->custom_css_revisions_list( $this->theme );
}
}
wp_die();
}
public function custom_css_revisions_list( $theme, $post_id = null, $current_revision = null ) {
$revisions = $this->get_custom_css_revisions( $theme, $post_id );
if ( is_array( $revisions ) && ! empty( $revisions ) ) {
$i = 0;
foreach ( $revisions as $time => $css ) {
$is_current = ( empty( $current_revision ) && $i == 0 ) || ( ! empty( $current_revision ) && $time == $current_revision );
$query_args = array( 'theme' => $theme, 'time' => $time, 'open_visual_editor' => false );
if ( ! empty( $post_id ) ) {
$query_args['socss_post_id'] = $post_id;
}
?>
<li>
<?php if ( ! $is_current ) { ?>
<a href="<?php echo esc_url( add_query_arg( $query_args, admin_url( 'themes.php?page=so_custom_css' ) ) ); ?>"
class="load-css-revision">
<?php } ?>
<?php echo date( 'j F Y @ H:i:s', $time + get_option( 'gmt_offset' ) * 60 * 60 ); ?>
<?php if ( ! $is_current ) { ?>
</a>
<?php } ?>
(<?php printf( esc_html__( '%d chars', 'so-css' ), strlen( $css ) ); ?>)<?php if ( $i == 0 ) { ?> (<?php esc_html_e( 'Latest', 'so-css' ); ?>)<?php } ?>
</li>
<?php
$i++;
}
} else {
printf( '<em>%s</em>', esc_html__( 'No revisions yet.', 'so-css' ) );
}
}
/**
* Add one or more paths to the registered snippet paths
*
* @param string|array $path
*/
public function register_snippet_path( $path ) {
$this->snippet_paths = array_merge( $this->snippet_paths, (array) $path );
}
/**
* Get all the available snippets
*
* @return array|bool
*/
public function get_snippets() {
// Get the snippet paths
$snippet_paths = apply_filters( 'siteorigin_css_snippet_paths', $this->snippet_paths );
if ( empty( $snippet_paths ) ) {
return array();
}
static $snippets = array();
if ( ! empty( $snippets ) ) {
return $snippets;
}
if ( ! WP_Filesystem() ) {
return false;
}
global $wp_filesystem;
foreach ( $snippet_paths as $path ) {
foreach ( glob( $path . '/*.css' ) as $css_file ) {
$data = get_file_data( $css_file, array(
'Name' => 'Name',
'Description' => 'Description',
) );
// Get the CSS and strip out the first header
$css = $wp_filesystem->get_contents( $css_file );
$css = preg_replace( '!/\*.*?\*/!s', '', $css, 1 );
$snippets[] = wp_parse_args( $data, array(
'css' => str_replace( "\t", ' ', trim( $css ) ),
) );
}
}
usort( $snippets, array( $this, 'sort_snippet_callback' ) );
return $snippets;
}
/**
* Sort snippets by name.
*
* @return int
*/
public static function sort_snippet_callback( $a, $b ) {
return $a['Name'] > $b['Name'] ? 1 : - 1;
}
/**
* A very simple CSS sanitization function.
*
* @return string
*/
public static function sanitize_css( $css ) {
return trim( strip_tags( $css ) );
}
/**
* Get all the available theme CSS
*/
public function get_theme_css() {
$css = '';
if ( file_exists( get_template_directory() . '/style.css' ) ) {
$css .= file_get_contents( get_template_directory() . '/style.css' );
}
if ( is_child_theme() ) {
$css .= file_get_contents( get_stylesheet_directory() . '/style.css' );
}
// Remove all CSS comments
$regex = array(
"`^([\t\s]+)`ism" => '',
"`^\/\*(.+?)\*\/`ism" => '',
"`(\A|[\n;]+)/\*[^*]*\*+(?:[^/*][^*]*\*+)*/`" => '$1',
"`(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+`ism" => "\n",
);
$css = preg_replace( array_keys( $regex ), $regex, $css );
$css = preg_replace( '/\s+/', ' ', $css );
return $css;
}
public function enqueue_inspector_scripts() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
return;
}
wp_enqueue_style( 'dashicons' );
wp_enqueue_script( 'siteorigin-css-parser-lib', plugin_dir_url( __FILE__ ) . 'js/css' . SOCSS_JS_SUFFIX . '.js', array( 'jquery' ), SOCSS_VERSION );
wp_enqueue_script( 'siteorigin-css-sizes', plugin_dir_url( __FILE__ ) . 'js/jquery.sizes' . SOCSS_JS_SUFFIX . '.js', array( 'jquery' ), '0.33' );
wp_enqueue_script( 'siteorigin-css-specificity', plugin_dir_url( __FILE__ ) . 'js/specificity' . SOCSS_JS_SUFFIX . '.js', array() );
wp_enqueue_script( 'siteorigin-css-inspector', plugin_dir_url( __FILE__ ) . 'js/inspector' . SOCSS_JS_SUFFIX . '.js', array(
'jquery',
'underscore',
'backbone',
), SOCSS_VERSION, true );
wp_enqueue_style( 'siteorigin-css-inspector', plugin_dir_url( __FILE__ ) . 'css/inspector.css', array(), SOCSS_VERSION );
wp_localize_script( 'siteorigin-css-inspector', 'socssOptions', array() );
}
public function inspector_templates() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
return;
}
include plugin_dir_path( __FILE__ ) . 'tpl/inspector-templates.php';
}
/**
* Change the stylesheets to all be inline
*/
public function inline_inspector_scripts() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
return;
}
$regex = array(
"`^([\t\s]+)`ism" => '',
"`^\/\*(.+?)\*\/`ism" => '',
"`(\A|[\n;]+)/\*[^*]*\*+(?:[^/*][^*]*\*+)*/`" => '$1',
"`(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+`ism" => "\n",
);
global $wp_styles;
if ( empty( $wp_styles->queue ) ) {
return;
}
// Make each of the scripts inline
foreach ( $wp_styles->queue as $handle ) {
if ( $handle === 'siteorigin-css-inspector' || $handle === 'dashicons' ) {
continue;
}
$style = $wp_styles->registered[ $handle ];
if ( empty( $style->src ) || substr( $style->src, 0, 4 ) !== 'http' ) {
continue;
}
$response = wp_remote_get( $style->src );
if ( is_wp_error( $response ) || $response['response']['code'] !== 200 || empty( $response['body'] ) ) {
continue;
}
$css = $response['body'];
$css = preg_replace( array_keys( $regex ), $regex, $css );
?>
<script type="text/css" class="socss-theme-styles"
id="socss-inlined-style-<?php echo sanitize_html_class( $handle ); ?>">
<?php echo strip_tags( $css ); ?>
</script>
<?php
}
}
public function disable_ngg_resource_manager() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
return;
}
//The NextGen Gallery plugin does some weird interfering with the output buffer.
define( 'NGG_DISABLE_RESOURCE_MANAGER', true );
}
private function get_latest_revision_timestamp() {
$revisions = $this->get_custom_css_revisions( $this->theme );
if ( empty( $revisions ) ) {
return false;
}
krsort( $revisions );
$revision_times = array_keys( $revisions );
return $revision_times[0];
}
}
// Initialize the single
SiteOrigin_CSS::single();
� 0OS/2c � `cmap�ڈ� �gasp � glyfc� � � head#� � 6hheao� $hmtxO] L ( `loca0�,d � 2maxp � � name�J � � �post d �� �� ��� � 3 @ �m�n �m � � � ��3�9�h�n��������� � ��1�6�e�n��������� �������G:
�� 79 79 79 ��� 0 '.#!"3!2654&'"&54632#!"&=463!2b�
'�5KK5�5K
�^5KK55KK�
�@
�
^�
K5��5KK5�(
��K55KK55K�
�
E���� #"'&54?632632����N�vN�M�wN ��� k 2327&'767676767673"'&#"#4?276727676767654'&'&'%3"'&#"##�a;;!18�b
��Iu*)'($HI$,OPK��!BC!
->!���r��-`���-gf6??! ..78!OO ��% = � 3254'&'&'&'&'&#"3276767654'&'&'&#"76767676767654='&'&'&'&'&#'67632332#"'&#"=*&�!*&/##!!&-�� ((
8��K
(&&$#
X;;"!.-00522<ss�A&
<=""�!!0(:9
�6
&10#$+ 98U:-- ��I N 767676767676=&'&'&'73276767"#"'&#&#"
++##22$#!(())#"
`!!O'54V1%����;
T��0
�� ( <