@@ -1437,140 +1437,6 @@ class Func extends CSSParserRule {
14371437}
14381438
14391439
1440- /* Grammar Application */
1441-
1442- function canonicalize ( rule , grammar , topGrammar ) {
1443- if ( grammar === undefined ) grammar = CSSGrammar ;
1444- if ( topGrammar === undefined ) topGrammar = grammar
1445- if ( ! validateGrammar ( grammar ) ) return ;
1446- if ( grammar ) {
1447- if ( grammar . stylesheet ) grammar = topGrammar ;
1448- var unknownTransformer = grammar . unknown || function ( ) { return } ;
1449- }
1450- var ret = { "type" :rule . type . toLowerCase ( ) } ;
1451-
1452- if ( rule . type == "STYLESHEET" ) {
1453- var contents = rule . value ;
1454- } else if ( rule . type == "BLOCK" ) {
1455- var unparsedContents = rule . value ;
1456- ret . name = rule . name ;
1457- } else if ( rule . type == "QUALIFIED-RULE" ) {
1458- var unparsedContents = rule . value . value ;
1459- ret . prelude = rule . prelude ;
1460- } else if ( rule . type == "AT-RULE" ) {
1461- var unparsedContents = rule . value . value ;
1462- ret . name = rule . name ;
1463- ret . prelude = rule . prelude ;
1464- } else if ( rule . type == "DECLARATION" ) {
1465- // I don't do grammar-checking of declarations yet.
1466- ret . name = rule . name ;
1467- ret . value = rule . value ;
1468- ret . important = rule . important ;
1469- return ret ;
1470- }
1471-
1472- if ( ! grammar ) {
1473- return ret ;
1474- } else if ( grammar . declarations ) {
1475- ret . declarations = { } ; // simple key/value map of declarations
1476- ret . rules = [ ] ; // in-order list of both decls and at-rules
1477- ret . errors = [ ] ;
1478- for ( var i = 0 ; i < contents . length ; i ++ ) {
1479- var rule = contents [ i ] ;
1480- if ( rule instanceof Declaration ) {
1481- var decl = canonicalize ( rule , { } , topGrammar ) ;
1482- ret . declarations [ rule . name ] = decl ;
1483- ret . rules . push ( decl ) ;
1484- } else { // rule is instanceof AtRule
1485- var subGrammar = grammar [ "@" + rule . name ] ;
1486- if ( subGrammar ) { // Rule is valid in this context
1487- ret . rules . push ( canonicalize ( rule , subGrammar , topGrammar ) ) ;
1488- } else {
1489- var result = unknownTransformer ( rule ) ;
1490- if ( result ) {
1491- ret . rules . push ( result ) ;
1492- } else {
1493- ret . errors . push ( result ) ;
1494- }
1495- }
1496- }
1497- }
1498- } else {
1499- ret . rules = [ ] ;
1500- ret . errors = [ ] ;
1501- for ( var i = 0 ; i < contents . length ; i ++ ) {
1502- var rule = contents [ i ] ;
1503- if ( rule instanceof QualifiedRule ) {
1504- ret . rules . push ( canonicalize ( rule , grammar . qualified , topGrammar ) ) ;
1505- } else {
1506- var subGrammar = grammar [ "@" + rule . name ] ;
1507- if ( subGrammar ) { // Rule is valid in this context
1508- ret . rules . push ( canonicalize ( rule , subGrammar , topGrammar ) ) ;
1509- } else {
1510- var result = unknownTransformer ( rule ) ;
1511- if ( result ) {
1512- ret . rules . push ( result ) ;
1513- } else {
1514- ret . errors . push ( result ) ;
1515- }
1516- }
1517- }
1518- }
1519- }
1520- return ret ;
1521- }
1522-
1523- function validateGrammar ( grammar ) {
1524- // TODO
1525- return true
1526- }
1527-
1528- var CSSGrammar = {
1529- qualified : { declarations :true } ,
1530- "@media" : { stylesheet :true } ,
1531- "@keyframes" : { qualified :{ declarations :true } } ,
1532- "@font-face" : { declarations :true } ,
1533- "@supports" : { stylesheet :true } ,
1534- "@scope" : { stylesheet :true } ,
1535- "@counter-style" : { declarations :true } ,
1536- "@import" : null ,
1537- "@font-feature-values" : {
1538- // No qualified rules actually allowed,
1539- // but have to declare it one way or the other.
1540- qualified : true ,
1541- "@stylistic" : { declarations :true } ,
1542- "@styleset" : { declarations :true } ,
1543- "@character-variants" : { declarations :true } ,
1544- "@swash" : { declarations :true } ,
1545- "@ornaments" : { declarations :true } ,
1546- "@annotation" : { declarations :true } ,
1547- } ,
1548- "@viewport" : { declarations :true } ,
1549- "@page" : {
1550- declarations : true ,
1551- "@top-left-corner" : { declarations :true } ,
1552- "@top-left" : { declarations :true } ,
1553- "@top-center" : { declarations :true } ,
1554- "@top-right" : { declarations :true } ,
1555- "@top-right-corner" : { declarations :true } ,
1556- "@right-top" : { declarations :true } ,
1557- "@right-middle" : { declarations :true } ,
1558- "@right-bottom" : { declarations :true } ,
1559- "@right-bottom-corner" : { declarations :true } ,
1560- "@bottom-right" : { declarations :true } ,
1561- "@bottom-center" : { declarations :true } ,
1562- "@bottom-left" : { declarations :true } ,
1563- "@bottom-left-corner" : { declarations :true } ,
1564- "@left-bottom" : { declarations :true } ,
1565- "@left-center" : { declarations :true } ,
1566- "@left-top" : { declarations :true } ,
1567- } ,
1568- "@custom-selector" : null ,
1569- "@custom-media" : null
1570- }
1571-
1572-
1573-
15741440// Exportation.
15751441exports . CSSParserRule = CSSParserRule ;
15761442exports . Stylesheet = Stylesheet ;
@@ -1586,8 +1452,6 @@ exports.parseADeclaration = parseADeclaration;
15861452exports . parseAComponentValue = parseAComponentValue ;
15871453exports . parseAListOfComponentValues = parseAListOfComponentValues ;
15881454exports . parseACommaSeparatedListOfComponentValues = parseACommaSeparatedListOfComponentValues ;
1589- exports . canonicalizeRule = canonicalize ;
1590- exports . CSSGrammar = CSSGrammar ;
15911455exports . tokenize = tokenize ;
15921456
15931457} ) ) ;
0 commit comments