diff --git a/lib/less/parser.js b/lib/less/parser.js index 998c2ad5..4430a82f 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -1158,23 +1158,65 @@ less.Parser = function Parser(env) { // @charset "utf-8"; // directive: function () { - var name, value, rules, types, e, nodes; + var name, value, rules, identifier, e, nodes, nonVendorSpecificName, + hasBlock, hasIdentifier; if (input.charAt(i) !== '@') return; - + if (value = $(this['import']) || $(this.media)) { return value; - } else if (name = $(/^@page|@keyframes/) || $(/^@(?:-webkit-|-khtml-|-moz-|-o-|-ms-)[a-z0-9-]+/)) { - types = ($(/^[^{]+/) || '').trim(); + } + + name = $(/^@[a-z-]+/); + + nonVendorSpecificName = name; + if (name.charAt(1) == '-' && name.indexOf('-', 2) > 0) { + nonVendorSpecificName = "@" + name.slice(name.indexOf('-', 2) + 1); + } + + switch(nonVendorSpecificName) { + case "@font-face": + hasBlock = true; + break; + case "@viewport": + case "@top-left": + case "@top-left-corner": + case "@top-center": + case "@top-right": + case "@top-right-corner": + case "@bottom-left": + case "@bottom-left-corner": + case "@bottom-center": + case "@bottom-right": + case "@bottom-right-corner": + case "@left-top": + case "@left-middle": + case "@left-bottom": + case "@right-top": + case "@right-middle": + case "@right-bottom": + hasBlock = true; + break; + case "@page": + case "@document": + case "@supports": + case "@keyframes": + hasBlock = true; + hasIdentifier = true; + break; + } + + if (hasIdentifier) { + name += " " + ($(/^[^{]+/) || '').trim(); + } + + if (hasBlock) + { if (rules = $(this.block)) { - return new(tree.Directive)(name + " " + types, rules); + return new(tree.Directive)(name, rules); } - } else if (name = $(/^@[a-z-]+/)) { - if (name === '@font-face') { - if (rules = $(this.block)) { - return new(tree.Directive)(name, rules); - } - } else if ((value = $(this.entity)) && $(';')) { + } else { + if ((value = $(this.entity)) && $(';')) { return new(tree.Directive)(name, value); } } diff --git a/test/css/css-3.css b/test/css/css-3.css index b9e9b194..3ddde0f8 100644 --- a/test/css/css-3.css +++ b/test/css/css-3.css @@ -60,6 +60,19 @@ p::before { border: 3px; } } +@keyframes fontbulger1 { + to { + font-size: 15px; + } + from, + to { + font-size: 12px; + } + 0%, + 100% { + font-size: 12px; + } +} .units { font: 1.2rem/2rem; font: 8vw/9vw; @@ -67,3 +80,18 @@ p::before { font: 12vm/15vm; font: 1.2ch/1.5ch; } +@supports ( box-shadow: 2px 2px 2px black ) or + ( -moz-box-shadow: 2px 2px 2px black ) { + .outline { + box-shadow: 2px 2px 2px black; + -moz-box-shadow: 2px 2px 2px black; + } +} +@-x-document url-prefix(""github.com"") { + h1 { + color: red; + } +} +@viewport { + font-size: 10px; +} diff --git a/test/css/media.css b/test/css/media.css index 4b1864c8..9ccb7214 100644 --- a/test/css/media.css +++ b/test/css/media.css @@ -82,3 +82,64 @@ @media only screen and (max-width: 200px) { width: 480px; } +@media print { + @page :left { + margin: 0.5cm; + } + @page :right { + margin: 0.5cm; + } + @page Test:first { + margin: 1cm; + } + @page :first { + size: 8.5in 11in;@top-left { + margin: 1cm; + } + @top-left-corner { + margin: 1cm; + } + @top-center { + margin: 1cm; + } + @top-right { + margin: 1cm; + } + @top-right-corner { + margin: 1cm; + } + @bottom-left { + margin: 1cm; + } + @bottom-left-corner { + margin: 1cm; + } + @bottom-center { + margin: 1cm; + } + @bottom-right { + margin: 1cm; + } + @bottom-right-corner { + margin: 1cm; + } + @left-top { + margin: 1cm; + } + @left-middle { + margin: 1cm; + } + @left-bottom { + margin: 1cm; + } + @right-top { + margin: 1cm; + } + @right-middle { + content: "Page " counter(page); + } + @right-bottom { + margin: 1cm; + } + } +} diff --git a/test/less/css-3.less b/test/less/css-3.less index 7b861440..1bedbde6 100644 --- a/test/less/css-3.less +++ b/test/less/css-3.less @@ -68,10 +68,40 @@ p::before { 100% { border: 3px } } +@keyframes fontbulger1 { + to { + font-size: 15px; + } + from,to { + font-size: 12px; + } + 0%,100% { + font-size: 12px; + } +} + .units { font: 1.2rem/2rem; font: 8vw/9vw; font: 10vh/12vh; font: 12vm/15vm; font: 1.2ch/1.5ch; -} \ No newline at end of file +} + +@supports ( box-shadow: 2px 2px 2px black ) or + ( -moz-box-shadow: 2px 2px 2px black ) { + .outline { + box-shadow: 2px 2px 2px black; + -moz-box-shadow: 2px 2px 2px black; + } +} + +@-x-document url-prefix(""github.com"") { + h1 { + color: red; + } +} + +@viewport { + font-size: 10px; +} diff --git a/test/less/media.less b/test/less/media.less index 528d5286..2e44784f 100644 --- a/test/less/media.less +++ b/test/less/media.less @@ -81,3 +81,66 @@ body { @media @smartphone { width: 480px; } + +@media print { + @page :left { + margin: 0.5cm; + } + @page :right { + margin: 0.5cm; + } + @page Test:first { + margin: 1cm; + } + @page :first { + size: 8.5in 11in; + @top-left { + margin: 1cm; + } + @top-left-corner { + margin: 1cm; + } + @top-center { + margin: 1cm; + } + @top-right { + margin: 1cm; + } + @top-right-corner { + margin: 1cm; + } + @bottom-left { + margin: 1cm; + } + @bottom-left-corner { + margin: 1cm; + } + @bottom-center { + margin: 1cm; + } + @bottom-right { + margin: 1cm; + } + @bottom-right-corner { + margin: 1cm; + } + @left-top { + margin: 1cm; + } + @left-middle { + margin: 1cm; + } + @left-bottom { + margin: 1cm; + } + @right-top { + margin: 1cm; + } + @right-middle { + content: "Page " counter(page); + } + @right-bottom { + margin: 1cm; + } + } +}