How to use isIdent method in Playwright Internal

Best JavaScript code snippet using playwright-internal

cssParser.js

Source:cssParser.js Github

copy

Full Screen

...434 haveAngle = true;435 token = parser.getToken(true, true);436 }437 if (token.isLength()438 || token.isIdent("top")439 || token.isIdent("center")440 || token.isIdent("bottom")441 || token.isIdent("left")442 || token.isIdent("right")) {443 haveGradientLine = true;444 if (token.isLength()445 || token.isIdent("left")446 || token.isIdent("right")) {447 foundHorizPosition = true;448 }449 gradient.position = token.value;450 token = parser.getToken(true, true);451 }452 if (haveGradientLine) {453 if (!haveAngle && token.isAngle()) { // we have an angle here454 gradient.angle = token.value;455 haveAngle = true;456 token = parser.getToken(true, true);457 }458 else if (token.isLength()459 || (foundHorizPosition && (token.isIdent("top")460 || token.isIdent("center")461 || token.isIdent("bottom")))462 || (!foundHorizPosition && (token.isLength()463 || token.isIdent("top")464 || token.isIdent("center")465 || token.isIdent("bottom")466 || token.isIdent("left")467 || token.isIdent("right")))) {468 gradient.position = ("position" in gradient) ? gradient.position + " ": "";469 gradient.position += token.value;470 token = parser.getToken(true, true);471 }472 if (!haveAngle && token.isAngle()) { // we have an angle here473 gradient.angle = token.value;474 haveAngle = true;475 token = parser.getToken(true, true);476 }477 // we must find a comma here478 if (!token.isSymbol(","))479 return null;480 token = parser.getToken(true, true);481 }482 // ok... Let's deal with the rest now483 if (gradient.isRadial) {484 if (token.isIdent("circle") ||485 token.isIdent("ellipse")) {486 gradient.shape = token.value;487 token = parser.getToken(true, true);488 }489 if (token.isIdent("closest-side") ||490 token.isIdent("closest-corner") ||491 token.isIdent("farthest-side") ||492 token.isIdent("farthest-corner") ||493 token.isIdent("contain") ||494 token.isIdent("cover")) {495 gradient.size = token.value;496 token = parser.getToken(true, true);497 }498 if (!("shape" in gradient) &&499 (token.isIdent("circle") ||500 token.isIdent("ellipse"))) {501 // we can still have the second value...502 gradient.shape = token.value;503 token = parser.getToken(true, true);504 }505 if ((("shape" in gradient) || ("size" in gradient)) && !token.isSymbol(","))506 return null;507 else if (("shape" in gradient) || ("size" in gradient))508 token = parser.getToken(true, true);509 }510 // now color stops...511 var stop1 = this.parseColorStop(parser, token);512 if (!stop1)513 return null;514 token = parser.currentToken();515 if (!token.isSymbol(","))516 return null;517 token = parser.getToken(true, true);518 var stop2 = this.parseColorStop(parser, token);519 if (!stop2)520 return null;521 token = parser.currentToken();522 if (token.isSymbol(",")) {523 token = parser.getToken(true, true);524 }525 // ok we have at least two color stops526 gradient.stops = [stop1, stop2];527 while (!token.isSymbol(")")) {528 var colorstop = this.parseColorStop(parser, token);529 if (!colorstop)530 return null;531 token = parser.currentToken();532 if (!token.isSymbol(")") && !token.isSymbol(","))533 return null;534 if (token.isSymbol(","))535 token = parser.getToken(true, true);536 gradient.stops.push(colorstop);537 }538 return gradient;539 }540 }541 return null;542 },543 parseBoxShadows: function(aString)544 {545 var parser = new CSSParser();546 parser._init();547 parser.mPreserveWS = false;548 parser.mPreserveComments = false;549 parser.mPreservedTokens = [];550 parser.mScanner.init(aString);551 var shadows = [];552 var token = parser.getToken(true, true);553 var color = "", blurRadius = "0px", offsetX = "0px", offsetY = "0px", spreadRadius = "0px";554 var inset = false;555 while (token.isNotNull()) {556 if (token.isIdent("none")) {557 shadows.push( { none: true } );558 token = parser.getToken(true, true);559 }560 else {561 if (token.isIdent('inset')) {562 inset = true;563 token = parser.getToken(true, true);564 }565 if (token.isPercentage() ||566 token.isDimensionOfUnit("cm") ||567 token.isDimensionOfUnit("mm") ||568 token.isDimensionOfUnit("in") ||569 token.isDimensionOfUnit("pc") ||570 token.isDimensionOfUnit("px") ||571 token.isDimensionOfUnit("em") ||572 token.isDimensionOfUnit("ex") ||573 token.isDimensionOfUnit("pt")) {574 var offsetX = token.value;575 token = parser.getToken(true, true);576 }577 else578 return [];579 if (!inset && token.isIdent('inset')) {580 inset = true;581 token = parser.getToken(true, true);582 }583 if (token.isPercentage() ||584 token.isDimensionOfUnit("cm") ||585 token.isDimensionOfUnit("mm") ||586 token.isDimensionOfUnit("in") ||587 token.isDimensionOfUnit("pc") ||588 token.isDimensionOfUnit("px") ||589 token.isDimensionOfUnit("em") ||590 token.isDimensionOfUnit("ex") ||591 token.isDimensionOfUnit("pt")) {592 var offsetX = token.value;593 token = parser.getToken(true, true);594 }595 else596 return [];597 if (!inset && token.isIdent('inset')) {598 inset = true;599 token = parser.getToken(true, true);600 }601 if (token.isPercentage() ||602 token.isDimensionOfUnit("cm") ||603 token.isDimensionOfUnit("mm") ||604 token.isDimensionOfUnit("in") ||605 token.isDimensionOfUnit("pc") ||606 token.isDimensionOfUnit("px") ||607 token.isDimensionOfUnit("em") ||608 token.isDimensionOfUnit("ex") ||609 token.isDimensionOfUnit("pt")) {610 var blurRadius = token.value;611 token = parser.getToken(true, true);612 }613 if (!inset && token.isIdent('inset')) {614 inset = true;615 token = parser.getToken(true, true);616 }617 if (token.isPercentage() ||618 token.isDimensionOfUnit("cm") ||619 token.isDimensionOfUnit("mm") ||620 token.isDimensionOfUnit("in") ||621 token.isDimensionOfUnit("pc") ||622 token.isDimensionOfUnit("px") ||623 token.isDimensionOfUnit("em") ||624 token.isDimensionOfUnit("ex") ||625 token.isDimensionOfUnit("pt")) {626 var spreadRadius = token.value;627 token = parser.getToken(true, true);628 }629 if (!inset && token.isIdent('inset')) {630 inset = true;631 token = parser.getToken(true, true);632 }633 if (token.isFunction("rgb(") ||634 token.isFunction("rgba(") ||635 token.isFunction("hsl(") ||636 token.isFunction("hsla(") ||637 token.isSymbol("#") ||638 token.isIdent()) {639 var color = parser.parseColor(token);640 token = parser.getToken(true, true);641 }642 if (!inset && token.isIdent('inset')) {643 inset = true;644 token = parser.getToken(true, true);645 }646 shadows.push( { none: false,647 color: color,648 offsetX: offsetX, offsetY: offsetY,649 blurRadius: blurRadius,650 spreadRadius: spreadRadius } );651 if (token.isSymbol(",")) {652 inset = false;653 color = "";654 blurRadius = "0px";655 spreadRadius = "0px"656 offsetX = "0px";657 offsetY = "0px"; 658 token = parser.getToken(true, true);659 }660 else if (!token.isNotNull())661 return shadows;662 else663 return [];664 }665 }666 return shadows;667 },668 parseTextShadows: function(aString)669 {670 var parser = new CSSParser();671 parser._init();672 parser.mPreserveWS = false;673 parser.mPreserveComments = false;674 parser.mPreservedTokens = [];675 parser.mScanner.init(aString);676 var shadows = [];677 var token = parser.getToken(true, true);678 var color = "", blurRadius = "0px", offsetX = "0px", offsetY = "0px"; 679 while (token.isNotNull()) {680 if (token.isIdent("none")) {681 shadows.push( { none: true } );682 token = parser.getToken(true, true);683 }684 else {685 if (token.isFunction("rgb(") ||686 token.isFunction("rgba(") ||687 token.isFunction("hsl(") ||688 token.isFunction("hsla(") ||689 token.isSymbol("#") ||690 token.isIdent()) {691 var color = parser.parseColor(token);692 token = parser.getToken(true, true);693 }694 if (token.isPercentage() ||695 token.isDimensionOfUnit("cm") ||696 token.isDimensionOfUnit("mm") ||697 token.isDimensionOfUnit("in") ||698 token.isDimensionOfUnit("pc") ||699 token.isDimensionOfUnit("px") ||700 token.isDimensionOfUnit("em") ||701 token.isDimensionOfUnit("ex") ||702 token.isDimensionOfUnit("pt")) {703 var offsetX = token.value;704 token = parser.getToken(true, true);705 }706 else707 return [];708 if (token.isPercentage() ||709 token.isDimensionOfUnit("cm") ||710 token.isDimensionOfUnit("mm") ||711 token.isDimensionOfUnit("in") ||712 token.isDimensionOfUnit("pc") ||713 token.isDimensionOfUnit("px") ||714 token.isDimensionOfUnit("em") ||715 token.isDimensionOfUnit("ex") ||716 token.isDimensionOfUnit("pt")) {717 var offsetY = token.value;718 token = parser.getToken(true, true);719 }720 else721 return [];722 if (token.isPercentage() ||723 token.isDimensionOfUnit("cm") ||724 token.isDimensionOfUnit("mm") ||725 token.isDimensionOfUnit("in") ||726 token.isDimensionOfUnit("pc") ||727 token.isDimensionOfUnit("px") ||728 token.isDimensionOfUnit("em") ||729 token.isDimensionOfUnit("ex") ||730 token.isDimensionOfUnit("pt")) {731 var blurRadius = token.value;732 token = parser.getToken(true, true);733 }734 if (!color &&735 (token.isFunction("rgb(") ||736 token.isFunction("rgba(") ||737 token.isFunction("hsl(") ||738 token.isFunction("hsla(") ||739 token.isSymbol("#") ||740 token.isIdent())) {741 var color = parser.parseColor(token);742 token = parser.getToken(true, true);743 }744 shadows.push( { none: false,745 color: color,746 offsetX: offsetX, offsetY: offsetY,747 blurRadius: blurRadius } );748 if (token.isSymbol(",")) {749 color = "";750 blurRadius = "0px";751 offsetX = "0px";752 offsetY = "0px"; 753 token = parser.getToken(true, true);754 }755 else if (!token.isNotNull())756 return shadows;757 else758 return [];759 }760 }761 return shadows;762 },763 parseBackgroundImages: function(aString)764 {765 var parser = new CSSParser();766 parser._init();767 parser.mPreserveWS = false;768 parser.mPreserveComments = false;769 parser.mPreservedTokens = [];770 parser.mScanner.init(aString);771 var backgrounds = [];772 var token = parser.getToken(true, true);773 while (token.isNotNull()) {774 /*if (token.isFunction("rgb(") ||775 token.isFunction("rgba(") ||776 token.isFunction("hsl(") ||777 token.isFunction("hsla(") ||778 token.isSymbol("#") ||779 token.isIdent()) {780 var color = parser.parseColor(token);781 backgrounds.push( { type: "color", value: color });782 token = parser.getToken(true, true);783 }784 else */785 if (token.isFunction("url(")) {786 token = parser.getToken(true, true);787 var urlContent = parser.parseURL(token);788 backgrounds.push( { type: "image", value: "url(" + urlContent });789 token = parser.getToken(true, true);790 }791 else if (token.isFunction("-moz-linear-gradient(") ||792 token.isFunction("-moz-radial-gradient(") ||793 token.isFunction("-moz-repeating-linear-gradient(") ||794 token.isFunction("-moz-repeating-radial-gradient(")) {795 var gradient = this.parseGradient(parser, token);796 backgrounds.push( { type: gradient.isRadial ? "radial-gradient" : "linear-gradient", value: gradient });797 token = parser.getToken(true, true);798 }799 else800 return null;801 if (token.isSymbol(",")) {802 token = parser.getToken(true, true);803 if (!token.isNotNull())804 return null;805 }806 }807 return backgrounds;808 },809 serializeGradient: function(gradient)810 {811 var s = gradient.isRadial812 ? (gradient.isRepeating ? "-moz-repeating-radial-gradient(" : "-moz-radial-gradient(" )813 : (gradient.isRepeating ? "-moz-repeating-linear-gradient(" : "-moz-linear-gradient(" );814 if (gradient.angle || gradient.position)815 s += (gradient.angle ? gradient.angle + " ": "") +816 (gradient.position ? gradient.position : "") +817 ", ";818 if (gradient.isRadial && (gradient.shape || gradient.size))819 s += (gradient.shape ? gradient.shape : "") +820 " " +821 (gradient.size ? gradient.size : "") +822 ", ";823 for (var i = 0; i < gradient.stops.length; i++) {824 var colorstop = gradient.stops[i];825 s += colorstop.color + (colorstop.position ? " " + colorstop.position : "");826 if (i != gradient.stops.length -1)827 s += ", ";828 }829 s += ")";830 return s;831 },832 parseBorderImage: function(aString)833 {834 var parser = new CSSParser();835 parser._init();836 parser.mPreserveWS = false;837 parser.mPreserveComments = false;838 parser.mPreservedTokens = [];839 parser.mScanner.init(aString);840 var borderImage = {url: "", offsets: [], widths: [], sizes: []};841 var token = parser.getToken(true, true);842 if (token.isFunction("url(")) {843 token = parser.getToken(true, true);844 var urlContent = parser.parseURL(token);845 if (urlContent) {846 borderImage.url = urlContent.substr(0, urlContent.length - 1).trim();847 if ((borderImage.url[0] == '"' && borderImage.url[borderImage.url.length - 1] == '"') ||848 (borderImage.url[0] == "'" && borderImage.url[borderImage.url.length - 1] == "'"))849 borderImage.url = borderImage.url.substr(1, borderImage.url.length - 2);850 }851 else852 return null;853 }854 else855 return null; 856 token = parser.getToken(true, true);857 if (token.isNumber() || token.isPercentage())858 borderImage.offsets.push(token.value);859 else860 return null;861 var i;862 for (i= 0; i < 3; i++) {863 token = parser.getToken(true, true);864 if (token.isNumber() || token.isPercentage())865 borderImage.offsets.push(token.value);866 else867 break;868 }869 if (i == 3)870 token = parser.getToken(true, true);871 if (token.isSymbol("/")) {872 token = parser.getToken(true, true);873 if (token.isDimension()874 || token.isNumber("0")875 || (token.isIdent() && token.value in parser.kBORDER_WIDTH_NAMES))876 borderImage.widths.push(token.value);877 else878 return null;879 for (var i = 0; i < 3; i++) {880 token = parser.getToken(true, true);881 if (token.isDimension()882 || token.isNumber("0")883 || (token.isIdent() && token.value in parser.kBORDER_WIDTH_NAMES))884 borderImage.widths.push(token.value);885 else886 break;887 }888 if (i == 3)889 token = parser.getToken(true, true);890 }891 for (var i = 0; i < 2; i++) {892 if (token.isIdent("stretch")893 || token.isIdent("repeat")894 || token.isIdent("round"))895 borderImage.sizes.push(token.value);896 else if (!token.isNotNull())897 return borderImage;898 else899 return null;900 token = parser.getToken(true, true);901 }902 if (!token.isNotNull())903 return borderImage;904 return null;905 },906 parseMediaQuery: function(aString)907 {908 var kCONSTRAINTS = {909 "width": true,910 "min-width": true,911 "max-width": true,912 "height": true,913 "min-height": true,914 "max-height": true,915 "device-width": true,916 "min-device-width": true,917 "max-device-width": true,918 "device-height": true,919 "min-device-height": true,920 "max-device-height": true,921 "orientation": true,922 "aspect-ratio": true,923 "min-aspect-ratio": true,924 "max-aspect-ratio": true,925 "device-aspect-ratio": true,926 "min-device-aspect-ratio": true,927 "max-device-aspect-ratio": true,928 "color": true,929 "min-color": true,930 "max-color": true,931 "color-index": true,932 "min-color-index": true,933 "max-color-index": true,934 "monochrome": true,935 "min-monochrome": true,936 "max-monochrome": true,937 "resolution": true,938 "min-resolution": true,939 "max-resolution": true,940 "scan": true,941 "grid": true942 };943 var parser = new CSSParser();944 parser._init();945 parser.mPreserveWS = false;946 parser.mPreserveComments = false;947 parser.mPreservedTokens = [];948 parser.mScanner.init(aString);949 var m = {amplifier: "", medium: "", constraints: []};950 var token = parser.getToken(true, true);951 if (token.isIdent("all") ||952 token.isIdent("aural") ||953 token.isIdent("braille") ||954 token.isIdent("handheld") ||955 token.isIdent("print") ||956 token.isIdent("projection") ||957 token.isIdent("screen") ||958 token.isIdent("tty") ||959 token.isIdent("tv")) {960 m.medium = token.value;961 token = parser.getToken(true, true);962 }963 else if (token.isIdent("not") || token.isIdent("only")) {964 m.amplifier = token.value;965 token = parser.getToken(true, true);966 if (token.isIdent("all") ||967 token.isIdent("aural") ||968 token.isIdent("braille") ||969 token.isIdent("handheld") ||970 token.isIdent("print") ||971 token.isIdent("projection") ||972 token.isIdent("screen") ||973 token.isIdent("tty") ||974 token.isIdent("tv")) {975 m.medium = token.value;976 token = parser.getToken(true, true);977 }978 else979 return null;980 }981 if (m.medium) {982 if (!token.isNotNull())983 return m;984 if (token.isIdent("and")) {985 token = parser.getToken(true, true);986 }987 else988 return null;989 }990 while (token.isSymbol("(")) {991 token = parser.getToken(true, true);992 if (token.isIdent() && (token.value in kCONSTRAINTS)) {993 var constraint = token.value;994 token = parser.getToken(true, true);995 if (token.isSymbol(":")) {996 token = parser.getToken(true, true);997 var values = [];998 while (!token.isSymbol(")")) {999 values.push(token.value);1000 token = parser.getToken(true, true);1001 }1002 if (token.isSymbol(")")) {1003 m.constraints.push({constraint: constraint, value: values});1004 token = parser.getToken(true, true);1005 if (token.isNotNull()) {1006 if (token.isIdent("and")) {1007 token = parser.getToken(true, true);1008 }1009 else1010 return null;1011 }1012 else1013 return m;1014 }1015 else1016 return null;1017 }1018 else if (token.isSymbol(")")) {1019 m.constraints.push({constraint: constraint, value: null});1020 token = parser.getToken(true, true);1021 if (token.isNotNull()) {1022 if (token.isIdent("and")) {1023 token = parser.getToken(true, true);1024 }1025 else1026 return null;1027 }1028 else1029 return m;1030 }1031 else1032 return null;1033 }1034 else1035 return null;1036 }1037 return m;1038 }1039};1040/************************************************************/1041/************************** JSCSSP **************************/1042/************************************************************/1043var CSS_ESCAPE = '\\';1044var IS_HEX_DIGIT = 1;1045var START_IDENT = 2;1046var IS_IDENT = 4;1047var IS_WHITESPACE = 8;1048var W = IS_WHITESPACE;1049var I = IS_IDENT;1050var S = START_IDENT;1051var SI = IS_IDENT|START_IDENT;1052var XI = IS_IDENT |IS_HEX_DIGIT;1053var XSI = IS_IDENT|START_IDENT|IS_HEX_DIGIT;1054function CSSScanner(aString)1055{1056 this.init(aString);1057}1058CSSScanner.prototype = {1059 kLexTable: [1060 // TAB LF FF CR1061 0, 0, 0, 0, 0, 0, 0, 0, 0, W, W, 0, W, W, 0, 0,1062 //1063 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1064 // SPC ! " # $ % & ' ( ) * + , - . /1065 W, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, I, 0, 0,1066 // 0 1 2 3 4 5 6 7 8 9 : ; < = > ?1067 XI, XI, XI, XI, XI, XI, XI, XI, XI, XI, 0, 0, 0, 0, 0, 0,1068 // @ A B C D E F G H I J K L M N O1069 0, XSI,XSI,XSI,XSI,XSI,XSI,SI, SI, SI, SI, SI, SI, SI, SI, SI,1070 // P Q R S T U V W X Y Z [ \ ] ^ _1071 SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, 0, S, 0, 0, SI,1072 // ` a b c d e f g h i j k l m n o1073 0, XSI,XSI,XSI,XSI,XSI,XSI,SI, SI, SI, SI, SI, SI, SI, SI, SI,1074 // p q r s t u v w x y z { | } ~1075 SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, 0, 0, 0, 0, 0,1076 //1077 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1078 //1079 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1080 // ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯1081 0, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI,1082 // ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿1083 SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI,1084 // À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï1085 SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI,1086 // Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß1087 SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI,1088 // à á â ã ä å æ ç è é ê ë ì í î ï1089 SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI,1090 // ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ1091 SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI1092 ],1093 kHexValues: {1094 "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9,1095 "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 151096 },1097 mString : "",1098 mPos : 0,1099 mPreservedPos : [],1100 init: function(aString) {1101 this.mString = aString;1102 this.mPos = 0;1103 this.mPreservedPos = [];1104 },1105 getCurrentPos: function() {1106 return this.mPos;1107 },1108 getAlreadyScanned: function()1109 {1110 return this.mString.substr(0, this.mPos);1111 },1112 preserveState: function() {1113 this.mPreservedPos.push(this.mPos);1114 },1115 restoreState: function() {1116 if (this.mPreservedPos.length) {1117 this.mPos = this.mPreservedPos.pop();1118 }1119 },1120 forgetState: function() {1121 if (this.mPreservedPos.length) {1122 this.mPreservedPos.pop();1123 }1124 },1125 read: function() {1126 if (this.mPos < this.mString.length)1127 return this.mString.charAt(this.mPos++);1128 return -1;1129 },1130 peek: function() {1131 if (this.mPos < this.mString.length)1132 return this.mString.charAt(this.mPos);1133 return -1;1134 },1135 isHexDigit: function(c) {1136 var code = c.charCodeAt(0);1137 return (code < 256 && (this.kLexTable[code] & IS_HEX_DIGIT) != 0);1138 },1139 isIdentStart: function(c) {1140 var code = c.charCodeAt(0);1141 return (code >= 256 || (this.kLexTable[code] & START_IDENT) != 0);1142 },1143 startsWithIdent: function(aFirstChar, aSecondChar) {1144 var code = aFirstChar.charCodeAt(0);1145 return this.isIdentStart(aFirstChar) ||1146 (aFirstChar == "-" && this.isIdentStart(aSecondChar));1147 },1148 isIdent: function(c) {1149 var code = c.charCodeAt(0);1150 return (code >= 256 || (this.kLexTable[code] & IS_IDENT) != 0);1151 },1152 isSymbol: function(c) {1153 var code = c.charCodeAt(0);1154 return (this.kLexTable[code] & IS_IDENT) != 1;1155 },1156 pushback: function() {1157 this.mPos--;1158 },1159 nextHexValue: function() {1160 var c = this.read();1161 if (c == -1 || !this.isHexDigit(c))1162 return new jscsspToken(jscsspToken.NULL_TYPE, null);1163 var s = c;1164 c = this.read();1165 while (c != -1 && this.isHexDigit(c)) {1166 s += c;1167 c = this.read();1168 }1169 if (c != -1)1170 this.pushback();1171 return new jscsspToken(jscsspToken.HEX_TYPE, s);1172 },1173 gatherEscape: function() {1174 var c = this.peek();1175 if (c == -1)1176 return "";1177 if (this.isHexDigit(c)) {1178 var code = 0;1179 for (var i = 0; i < 6; i++) {1180 c = this.read();1181 if (this.isHexDigit(c))1182 code = code * 16 + this.kHexValues[c.toLowerCase()];1183 else if (!this.isHexDigit(c) && !this.isWhiteSpace(c)) {1184 this.pushback();1185 break;1186 }1187 else1188 break;1189 }1190 if (i == 6) {1191 c = this.peek();1192 if (this.isWhiteSpace(c))1193 this.read();1194 }1195 return String.fromCharCode(code);1196 }1197 c = this.read();1198 if (c != "\n")1199 return c;1200 return "";1201 },1202 gatherIdent: function(c) {1203 var s = "";1204 if (c == CSS_ESCAPE)1205 s += this.gatherEscape();1206 else1207 s += c;1208 c = this.read();1209 if(!this.mMediaQueryMode){1210 while (c != -11211 && (this.isIdent(c) || c == CSS_ESCAPE)) {1212 if (c == CSS_ESCAPE)1213 s += this.gatherEscape();1214 else1215 s += c;1216 c = this.read();1217 }1218 }1219 else {1220 while (c != -11221 && c != '{' 1222 && c != ',') {1223 s += c;1224 c = this.read();1225 }1226 }1227 if (c != -1)1228 this.pushback();1229 this.mMediaQueryMode = false;1230 return s;1231 },1232 parseIdent: function(c) {1233 var value = this.gatherIdent(c);1234 var nextChar = this.peek();1235 if (nextChar == "(") {1236 value += this.read();1237 return new jscsspToken(jscsspToken.FUNCTION_TYPE, value);1238 }1239 return new jscsspToken(jscsspToken.IDENT_TYPE, value);1240 },1241 isDigit: function(c) {1242 return (c >= '0') && (c <= '9');1243 },1244 parseComment: function(c) {1245 var s = c;1246 while ((c = this.read()) != -1) {1247 s += c;1248 if (c == "*") {1249 c = this.read();1250 if (c == -1)1251 break;1252 if (c == "/") {1253 s += c;1254 break;1255 }1256 this.pushback();1257 }1258 }1259 return new jscsspToken(jscsspToken.COMMENT_TYPE, s);1260 },1261 parseNumber: function(c) {1262 var s = c;1263 var foundDot = false;1264 while ((c = this.read()) != -1) {1265 if (c == ".") {1266 if (foundDot)1267 break;1268 else {1269 s += c;1270 foundDot = true;1271 }1272 } else if (this.isDigit(c))1273 s += c;1274 else1275 break;1276 }1277 if (c != -1 && this.startsWithIdent(c, this.peek())) { // DIMENSION1278 var unit = this.gatherIdent(c);1279 s += unit;1280 return new jscsspToken(jscsspToken.DIMENSION_TYPE, s, unit);1281 }1282 else if (c == "%") {1283 s += "%";1284 return new jscsspToken(jscsspToken.PERCENTAGE_TYPE, s);1285 }1286 else if (c != -1)1287 this.pushback();1288 return new jscsspToken(jscsspToken.NUMBER_TYPE, s);1289 },1290 parseString: function(aStop) {1291 var s = aStop;1292 var previousChar = aStop;1293 var c;1294 while ((c = this.read()) != -1) {1295 if (c == aStop && previousChar != CSS_ESCAPE) {1296 s += c;1297 break;1298 }1299 else if (c == CSS_ESCAPE) {1300 c = this.peek();1301 if (c == -1)1302 break;1303 else if (c == "\n" || c == "\r" || c == "\f") {1304 d = c;1305 c = this.read();1306 // special for Opera that preserves \r\n...1307 if (d == "\r") {1308 c = this.peek();1309 if (c == "\n")1310 c = this.read();1311 }1312 }1313 else {1314 s += this.gatherEscape();1315 c = this.peek();1316 }1317 }1318 else if (c == "\n" || c == "\r" || c == "\f") {1319 break;1320 }1321 else1322 s += c;1323 previousChar = c;1324 }1325 return new jscsspToken(jscsspToken.STRING_TYPE, s);1326 },1327 isWhiteSpace: function(c) {1328 var code = c.charCodeAt(0);1329 return code < 256 && (this.kLexTable[code] & IS_WHITESPACE) != 0;1330 },1331 eatWhiteSpace: function(c) {1332 var s = c;1333 while ((c = this.read()) != -1) {1334 if (!this.isWhiteSpace(c))1335 break;1336 s += c;1337 }1338 if (c != -1)1339 this.pushback();1340 return s;1341 },1342 parseAtKeyword: function(c) {1343 return new jscsspToken(jscsspToken.ATRULE_TYPE, this.gatherIdent(c));1344 },1345 nextToken: function() {1346 var c = this.read();1347 if (c == -1)1348 return new jscsspToken(jscsspToken.NULL_TYPE, null);1349 if (this.startsWithIdent(c, this.peek()))1350 return this.parseIdent(c);1351 if (c == '@') {1352 var nextChar = this.read();1353 if (nextChar != -1) {1354 var followingChar = this.peek();1355 this.pushback();1356 if (this.startsWithIdent(nextChar, followingChar))1357 return this.parseAtKeyword(c);1358 }1359 }1360 if (c == "." || c == "+" || c == "-") {1361 var nextChar = this.peek();1362 if (this.isDigit(nextChar))1363 return this.parseNumber(c);1364 else if (nextChar == "." && c != ".") {1365 firstChar = this.read();1366 var secondChar = this.peek();1367 this.pushback();1368 if (this.isDigit(secondChar))1369 return this.parseNumber(c);1370 }1371 }1372 if (this.isDigit(c)) {1373 return this.parseNumber(c);1374 }1375 if (c == "'" || c == '"')1376 return this.parseString(c);1377 if (this.isWhiteSpace(c)) {1378 var s = this.eatWhiteSpace(c);1379 1380 return new jscsspToken(jscsspToken.WHITESPACE_TYPE, s);1381 }1382 if (c == "|" || c == "~" || c == "^" || c == "$" || c == "*") {1383 var nextChar = this.read();1384 if (nextChar == "=") {1385 switch (c) {1386 case "~" :1387 return new jscsspToken(jscsspToken.INCLUDES_TYPE, "~=");1388 case "|" :1389 return new jscsspToken(jscsspToken.DASHMATCH_TYPE, "|=");1390 case "^" :1391 return new jscsspToken(jscsspToken.BEGINSMATCH_TYPE, "^=");1392 case "$" :1393 return new jscsspToken(jscsspToken.ENDSMATCH_TYPE, "$=");1394 case "*" :1395 return new jscsspToken(jscsspToken.CONTAINSMATCH_TYPE, "*=");1396 default :1397 break;1398 }1399 } else if (nextChar != -1)1400 this.pushback();1401 }1402 if (c == "/" && this.peek() == "*")1403 return this.parseComment(c);1404 return new jscsspToken(jscsspToken.SYMBOL_TYPE, c);1405 }1406};1407function CSSParser(aString)1408{1409 this.mToken = null;1410 this.mLookAhead = null;1411 this.mScanner = new CSSScanner(aString);1412 this.mPreserveWS = true;1413 this.mPreserveComments = true;1414 this.mPreservedTokens = [];1415 1416 this.mError = null;1417}1418CSSParser.prototype = {1419 _init:function() {1420 this.mToken = null;1421 this.mLookAhead = null;1422 this.mMediaQueryMode = false;1423 },1424 kINHERIT: "inherit",1425 kBORDER_WIDTH_NAMES: {1426 "thin": true,1427 "medium": true,1428 "thick": true1429 },1430 kBORDER_STYLE_NAMES: {1431 "none": true,1432 "hidden": true,1433 "dotted": true,1434 "dashed": true,1435 "solid": true,1436 "double": true,1437 "groove": true,1438 "ridge": true,1439 "inset": true,1440 "outset": true1441 },1442 kCOLOR_NAMES: {1443 "transparent": true,1444 1445 "black": true,1446 "silver": true,1447 "gray": true,1448 "white": true,1449 "maroon": true,1450 "red": true,1451 "purple": true,1452 "fuchsia": true,1453 "green": true,1454 "lime": true,1455 "olive": true,1456 "yellow": true,1457 "navy": true,1458 "blue": true,1459 "teal": true,1460 "aqua": true,1461 1462 "aliceblue": true,1463 "antiquewhite": true,1464 "aqua": true,1465 "aquamarine": true,1466 "azure": true,1467 "beige": true,1468 "bisque": true,1469 "black": true,1470 "blanchedalmond": true,1471 "blue": true,1472 "blueviolet": true,1473 "brown": true,1474 "burlywood": true,1475 "cadetblue": true,1476 "chartreuse": true,1477 "chocolate": true,1478 "coral": true,1479 "cornflowerblue": true,1480 "cornsilk": true,1481 "crimson": true,1482 "cyan": true,1483 "darkblue": true,1484 "darkcyan": true,1485 "darkgoldenrod": true,1486 "darkgray": true,1487 "darkgreen": true,1488 "darkgrey": true,1489 "darkkhaki": true,1490 "darkmagenta": true,1491 "darkolivegreen": true,1492 "darkorange": true,1493 "darkorchid": true,1494 "darkred": true,1495 "darksalmon": true,1496 "darkseagreen": true,1497 "darkslateblue": true,1498 "darkslategray": true,1499 "darkslategrey": true,1500 "darkturquoise": true,1501 "darkviolet": true,1502 "deeppink": true,1503 "deepskyblue": true,1504 "dimgray": true,1505 "dimgrey": true,1506 "dodgerblue": true,1507 "firebrick": true,1508 "floralwhite": true,1509 "forestgreen": true,1510 "fuchsia": true,1511 "gainsboro": true,1512 "ghostwhite": true,1513 "gold": true,1514 "goldenrod": true,1515 "gray": true,1516 "green": true,1517 "greenyellow": true,1518 "grey": true,1519 "honeydew": true,1520 "hotpink": true,1521 "indianred": true,1522 "indigo": true,1523 "ivory": true,1524 "khaki": true,1525 "lavender": true,1526 "lavenderblush": true,1527 "lawngreen": true,1528 "lemonchiffon": true,1529 "lightblue": true,1530 "lightcoral": true,1531 "lightcyan": true,1532 "lightgoldenrodyellow": true,1533 "lightgray": true,1534 "lightgreen": true,1535 "lightgrey": true,1536 "lightpink": true,1537 "lightsalmon": true,1538 "lightseagreen": true,1539 "lightskyblue": true,1540 "lightslategray": true,1541 "lightslategrey": true,1542 "lightsteelblue": true,1543 "lightyellow": true,1544 "lime": true,1545 "limegreen": true,1546 "linen": true,1547 "magenta": true,1548 "maroon": true,1549 "mediumaquamarine": true,1550 "mediumblue": true,1551 "mediumorchid": true,1552 "mediumpurple": true,1553 "mediumseagreen": true,1554 "mediumslateblue": true,1555 "mediumspringgreen": true,1556 "mediumturquoise": true,1557 "mediumvioletred": true,1558 "midnightblue": true,1559 "mintcream": true,1560 "mistyrose": true,1561 "moccasin": true,1562 "navajowhite": true,1563 "navy": true,1564 "oldlace": true,1565 "olive": true,1566 "olivedrab": true,1567 "orange": true,1568 "orangered": true,1569 "orchid": true,1570 "palegoldenrod": true,1571 "palegreen": true,1572 "paleturquoise": true,1573 "palevioletred": true,1574 "papayawhip": true,1575 "peachpuff": true,1576 "peru": true,1577 "pink": true,1578 "plum": true,1579 "powderblue": true,1580 "purple": true,1581 "red": true,1582 "rosybrown": true,1583 "royalblue": true,1584 "saddlebrown": true,1585 "salmon": true,1586 "sandybrown": true,1587 "seagreen": true,1588 "seashell": true,1589 "sienna": true,1590 "silver": true,1591 "skyblue": true,1592 "slateblue": true,1593 "slategray": true,1594 "slategrey": true,1595 "snow": true,1596 "springgreen": true,1597 "steelblue": true,1598 "tan": true,1599 "teal": true,1600 "thistle": true,1601 "tomato": true,1602 "turquoise": true,1603 "violet": true,1604 "wheat": true,1605 "white": true,1606 "whitesmoke": true,1607 "yellow": true,1608 "yellowgreen": true,1609 1610 "activeborder": true,1611 "activecaption": true,1612 "appworkspace": true,1613 "background": true,1614 "buttonface": true,1615 "buttonhighlight": true,1616 "buttonshadow": true,1617 "buttontext": true,1618 "captiontext": true,1619 "graytext": true,1620 "highlight": true,1621 "highlighttext": true,1622 "inactiveborder": true,1623 "inactivecaption": true,1624 "inactivecaptiontext": true,1625 "infobackground": true,1626 "infotext": true,1627 "menu": true,1628 "menutext": true,1629 "scrollbar": true,1630 "threeddarkshadow": true,1631 "threedface": true,1632 "threedhighlight": true,1633 "threedlightshadow": true,1634 "threedshadow": true,1635 "window": true,1636 "windowframe": true,1637 "windowtext": true1638 },1639 kLIST_STYLE_TYPE_NAMES: {1640 "decimal": true,1641 "decimal-leading-zero": true,1642 "lower-roman": true,1643 "upper-roman": true,1644 "georgian": true,1645 "armenian": true,1646 "lower-latin": true,1647 "lower-alpha": true,1648 "upper-latin": true,1649 "upper-alpha": true,1650 "lower-greek": true,1651 "disc": true,1652 "circle": true,1653 "square": true,1654 "none": true,1655 1656 /* CSS 3 */1657 "box": true,1658 "check": true,1659 "diamond": true,1660 "hyphen": true,1661 "lower-armenian": true,1662 "cjk-ideographic": true,1663 "ethiopic-numeric": true,1664 "hebrew": true,1665 "japanese-formal": true,1666 "japanese-informal": true,1667 "simp-chinese-formal": true,1668 "simp-chinese-informal": true,1669 "syriac": true,1670 "tamil": true,1671 "trad-chinese-formal": true,1672 "trad-chinese-informal": true,1673 "upper-armenian": true,1674 "arabic-indic": true,1675 "binary": true,1676 "bengali": true,1677 "cambodian": true,1678 "khmer": true,1679 "devanagari": true,1680 "gujarati": true,1681 "gurmukhi": true,1682 "kannada": true,1683 "lower-hexadecimal": true,1684 "lao": true,1685 "malayalam": true,1686 "mongolian": true,1687 "myanmar": true,1688 "octal": true,1689 "oriya": true,1690 "persian": true,1691 "urdu": true,1692 "telugu": true,1693 "tibetan": true,1694 "upper-hexadecimal": true,1695 "afar": true,1696 "ethiopic-halehame-aa-et": true,1697 "ethiopic-halehame-am-et": true,1698 "amharic-abegede": true,1699 "ehiopic-abegede-am-et": true,1700 "cjk-earthly-branch": true,1701 "cjk-heavenly-stem": true,1702 "ethiopic": true,1703 "ethiopic-abegede": true,1704 "ethiopic-abegede-gez": true,1705 "hangul-consonant": true,1706 "hangul": true,1707 "hiragana-iroha": true,1708 "hiragana": true,1709 "katakana-iroha": true,1710 "katakana": true,1711 "lower-norwegian": true,1712 "oromo": true,1713 "ethiopic-halehame-om-et": true,1714 "sidama": true,1715 "ethiopic-halehame-sid-et": true,1716 "somali": true,1717 "ethiopic-halehame-so-et": true,1718 "tigre": true,1719 "ethiopic-halehame-tig": true,1720 "tigrinya-er-abegede": true,1721 "ethiopic-abegede-ti-er": true,1722 "tigrinya-et": true,1723 "ethiopic-halehame-ti-et": true,1724 "upper-greek": true,1725 "asterisks": true,1726 "footnotes": true,1727 "circled-decimal": true,1728 "circled-lower-latin": true,1729 "circled-upper-latin": true,1730 "dotted-decimal": true,1731 "double-circled-decimal": true,1732 "filled-circled-decimal": true,1733 "parenthesised-decimal": true,1734 "parenthesised-lower-latin": true1735 },1736 reportError: function(aMsg) {1737 this.mError = aMsg;1738 },1739 consumeError: function() {1740 var e = this.mError;1741 this.mError = null;1742 return e;1743 },1744 currentToken: function() {1745 return this.mToken;1746 },1747 getHexValue: function() {1748 this.mToken = this.mScanner.nextHexValue();1749 return this.mToken;1750 },1751 getToken: function(aSkipWS, aSkipComment) {1752 if (this.mLookAhead) {1753 this.mToken = this.mLookAhead;1754 this.mLookAhead = null;1755 return this.mToken;1756 }1757 this.mToken = this.mScanner.nextToken();1758 while (this.mToken &&1759 ((aSkipWS && this.mToken.isWhiteSpace()) ||1760 (aSkipComment && this.mToken.isComment())))1761 this.mToken = this.mScanner.nextToken();1762 return this.mToken;1763 },1764 lookAhead: function(aSkipWS, aSkipComment) {1765 var preservedToken = this.mToken;1766 this.mScanner.preserveState();1767 var token = this.getToken(aSkipWS, aSkipComment);1768 this.mScanner.restoreState();1769 this.mToken = preservedToken;1770 return token;1771 },1772 ungetToken: function() {1773 this.mLookAhead = this.mToken;1774 },1775 addUnknownAtRule: function(aSheet, aString) {1776 var currentLine = CountLF(this.mScanner.getAlreadyScanned());1777 var blocks = [];1778 var token = this.getToken(false, false);1779 while (token.isNotNull()) {1780 aString += token.value;1781 if (token.isSymbol(";") && !blocks.length)1782 break;1783 else if (token.isSymbol("{")1784 || token.isSymbol("(")1785 || token.isSymbol("[")1786 || token.type == "function") {1787 blocks.push(token.isFunction() ? "(" : token.value);1788 } else if (token.isSymbol("}")1789 || token.isSymbol(")")1790 || token.isSymbol("]")) {1791 if (blocks.length) {1792 var ontop = blocks[blocks.length - 1];1793 if ((token.isSymbol("}") && ontop == "{")1794 || (token.isSymbol(")") && ontop == "(")1795 || (token.isSymbol("]") && ontop == "[")) {1796 blocks.pop();1797 if (!blocks.length && token.isSymbol("}"))1798 break;1799 }1800 }1801 }1802 token = this.getToken(false, false);1803 }1804 this.addUnknownRule(aSheet, aString, currentLine);1805 },1806 addUnknownRule: function(aSheet, aString, aCurrentLine) {1807 var errorMsg = this.consumeError();1808 var rule = new jscsspErrorRule(errorMsg);1809 rule.currentLine = aCurrentLine;1810 rule.parsedCssText = aString;1811 rule.parentStyleSheet = aSheet;1812 aSheet.cssRules.push(rule);1813 },1814 addWhitespace: function(aSheet, aString) {1815 var rule = new jscsspWhitespace();1816 rule.parsedCssText = aString;1817 rule.parentStyleSheet = aSheet;1818 aSheet.cssRules.push(rule);1819 },1820 addComment: function(aSheet, aString) {1821 var rule = new jscsspComment();1822 rule.parsedCssText = aString;1823 rule.parentStyleSheet = aSheet;1824 aSheet.cssRules.push(rule);1825 },1826 parseCharsetRule: function(aToken, aSheet) {1827 var s = aToken.value;1828 var token = this.getToken(false, false);1829 s += token.value;1830 if (token.isWhiteSpace(" ")) {1831 token = this.getToken(false, false);1832 s += token.value;1833 if (token.isString()) {1834 var encoding = token.value;1835 token = this.getToken(false, false);1836 s += token.value;1837 if (token.isSymbol(";")) {1838 var rule = new jscsspCharsetRule();1839 rule.encoding = encoding;1840 rule.parsedCssText = s;1841 rule.parentStyleSheet = aSheet;1842 aSheet.cssRules.push(rule);1843 return true;1844 }1845 else1846 this.reportError(kCHARSET_RULE_MISSING_SEMICOLON);1847 }1848 else1849 this.reportError(kCHARSET_RULE_CHARSET_IS_STRING);1850 }1851 else1852 this.reportError(kCHARSET_RULE_MISSING_WS);1853 this.addUnknownAtRule(aSheet, s);1854 return false;1855 },1856 parseImportRule: function(aToken, aSheet) {1857 var currentLine = CountLF(this.mScanner.getAlreadyScanned());1858 var s = aToken.value;1859 this.preserveState();1860 var token = this.getToken(true, true);1861 var media = [];1862 var href = "";1863 if (token.isString()) {1864 href = token.value;1865 s += " " + href;1866 }1867 else if (token.isFunction("url(")) {1868 token = this.getToken(true, true);1869 var urlContent = this.parseURL(token);1870 if (urlContent) {1871 href = "url(" + urlContent;1872 s += " " + href;1873 }1874 }1875 else1876 this.reportError(kIMPORT_RULE_MISSING_URL);1877 if (href) {1878 token = this.getToken(true, true);1879 while (token.isIdent()) {1880 s += " " + token.value;1881 media.push(token.value);1882 token = this.getToken(true, true);1883 if (!token)1884 break;1885 if (token.isSymbol(",")) {1886 s += ",";1887 } else if (token.isSymbol(";")) {1888 break;1889 } else1890 break;1891 token = this.getToken(true, true);1892 }1893 if (!media.length) {1894 media.push("all");1895 }1896 1897 if (token.isSymbol(";")) {1898 s += ";"1899 this.forgetState();1900 var rule = new jscsspImportRule();1901 rule.currentLine = currentLine;1902 rule.parsedCssText = s;1903 rule.href = href;1904 rule.media = media;1905 rule.parentStyleSheet = aSheet;1906 aSheet.cssRules.push(rule);1907 return true;1908 }1909 }1910 this.restoreState();1911 this.addUnknownAtRule(aSheet, "@import");1912 return false;1913 },1914 parseVariablesRule: function(token, aSheet) {1915 var currentLine = CountLF(this.mScanner.getAlreadyScanned());1916 var s = token.value;1917 var declarations = [];1918 var valid = false;1919 this.preserveState();1920 token = this.getToken(true, true);1921 var media = [];1922 var foundMedia = false;1923 while (token.isNotNull()) {1924 if (token.isIdent()) {1925 foundMedia = true;1926 s += " " + token.value;1927 media.push(token.value);1928 token = this.getToken(true, true);1929 if (token.isSymbol(",")) {1930 s += ",";1931 } else {1932 if (token.isSymbol("{"))1933 this.ungetToken();1934 else {1935 // error...1936 token.type = jscsspToken.NULL_TYPE;1937 break;1938 }1939 }1940 } else if (token.isSymbol("{"))1941 break;1942 else if (foundMedia) {1943 token.type = jscsspToken.NULL_TYPE;1944 // not a media list1945 break;1946 }1947 token = this.getToken(true, true);1948 }1949 if (token.isSymbol("{")) {1950 s += " {";1951 token = this.getToken(true, true);1952 while (true) {1953 if (!token.isNotNull()) {1954 valid = true;1955 break;1956 }1957 if (token.isSymbol("}")) {1958 s += "}";1959 valid = true;1960 break;1961 } else {1962 var d = this.parseDeclaration(token, declarations, true, false, aSheet);1963 s += ((d && declarations.length) ? " " : "") + d;1964 }1965 token = this.getToken(true, false);1966 }1967 }1968 if (valid) {1969 this.forgetState();1970 var rule = new jscsspVariablesRule();1971 rule.currentLine = currentLine;1972 rule.parsedCssText = s;1973 rule.declarations = declarations;1974 rule.media = media;1975 rule.parentStyleSheet = aSheet;1976 aSheet.cssRules.push(rule)1977 return true;1978 }1979 this.restoreState();1980 return false;1981 },1982 parseNamespaceRule: function(aToken, aSheet) {1983 var currentLine = CountLF(this.mScanner.getAlreadyScanned());1984 var s = aToken.value;1985 var valid = false;1986 this.preserveState();1987 var token = this.getToken(true, true);1988 if (token.isNotNull()) {1989 var prefix = "";1990 var url = "";1991 if (token.isIdent()) {1992 prefix = token.value;1993 s += " " + prefix;1994 token = this.getToken(true, true);1995 }1996 if (token) {1997 var foundURL = false;1998 if (token.isString()) {1999 foundURL = true;2000 url = token.value;2001 s += " " + url;2002 } else if (token.isFunction("url(")) {2003 // get a url here...2004 token = this.getToken(true, true);2005 var urlContent = this.parseURL(token);2006 if (urlContent) {2007 url += "url(" + urlContent;2008 foundURL = true;2009 s += " " + urlContent;2010 }2011 }2012 }2013 if (foundURL) {2014 token = this.getToken(true, true);2015 if (token.isSymbol(";")) {2016 s += ";";2017 this.forgetState();2018 var rule = new jscsspNamespaceRule();2019 rule.currentLine = currentLine;2020 rule.parsedCssText = s;2021 rule.prefix = prefix;2022 rule.url = url;2023 rule.parentStyleSheet = aSheet;2024 aSheet.cssRules.push(rule);2025 return true;2026 }2027 }2028 }2029 this.restoreState();2030 this.addUnknownAtRule(aSheet, "@namespace");2031 return false;2032 },2033 parseFontFaceRule: function(aToken, aSheet) {2034 var currentLine = CountLF(this.mScanner.getAlreadyScanned());2035 var s = aToken.value;2036 var valid = false;2037 var descriptors = [];2038 this.preserveState();2039 var token = this.getToken(true, true);2040 if (token.isNotNull()) {2041 // expecting block start2042 if (token.isSymbol("{")) {2043 s += " " + token.value;2044 var token = this.getToken(true, false);2045 while (true) {2046 if (token.isSymbol("}")) {2047 s += "}";2048 valid = true;2049 break;2050 } else {2051 var d = this.parseDeclaration(token, descriptors, false, false, aSheet);2052 s += ((d && descriptors.length) ? " " : "") + d;2053 }2054 token = this.getToken(true, false);2055 }2056 }2057 }2058 if (valid) {2059 this.forgetState();2060 var rule = new jscsspFontFaceRule();2061 rule.currentLine = currentLine;2062 rule.parsedCssText = s;2063 rule.descriptors = descriptors;2064 rule.parentStyleSheet = aSheet;2065 aSheet.cssRules.push(rule)2066 return true;2067 }2068 this.restoreState();2069 return false;2070 },2071 parsePageRule: function(aToken, aSheet) {2072 var currentLine = CountLF(this.mScanner.getAlreadyScanned());2073 var s = aToken.value;2074 var valid = false;2075 var declarations = [];2076 this.preserveState();2077 var token = this.getToken(true, true);2078 var pageSelector = "";2079 if (token.isSymbol(":") || token.isIdent()) {2080 if (token.isSymbol(":")) {2081 pageSelector = ":";2082 token = this.getToken(false, false);2083 }2084 if (token.isIdent()) {2085 pageSelector += token.value;2086 s += " " + pageSelector;2087 token = this.getToken(true, true);2088 }2089 }2090 if (token.isNotNull()) {2091 // expecting block start2092 if (token.isSymbol("{")) {2093 s += " " + token.value;2094 var token = this.getToken(true, false);2095 while (true) {2096 if (token.isSymbol("}")) {2097 s += "}";2098 valid = true;2099 break;2100 } else {2101 var d = this.parseDeclaration(token, declarations, true, true, aSheet);2102 s += ((d && declarations.length) ? " " : "") + d;2103 }2104 token = this.getToken(true, false);2105 }2106 }2107 }2108 if (valid) {2109 this.forgetState();2110 var rule = new jscsspPageRule();2111 rule.currentLine = currentLine;2112 rule.parsedCssText = s;2113 rule.pageSelector = pageSelector;2114 rule.declarations = declarations;2115 rule.parentStyleSheet = aSheet;2116 aSheet.cssRules.push(rule)2117 return true;2118 }2119 this.restoreState();2120 return false;2121 },2122 parseDefaultPropertyValue: function(token, aDecl, aAcceptPriority, descriptor, aSheet) {2123 var valueText = "";2124 var blocks = [];2125 var foundPriority = false;2126 var values = [];2127 while (token.isNotNull()) {2128 if ((token.isSymbol(";")2129 || token.isSymbol("}")2130 || token.isSymbol("!"))2131 && !blocks.length) {2132 if (token.isSymbol("}"))2133 this.ungetToken();2134 break;2135 }2136 2137 if (token.isIdent(this.kINHERIT)) {2138 if (values.length) {2139 return "";2140 }2141 else {2142 valueText = this.kINHERIT;2143 var value = new jscsspVariable(kJscsspINHERIT_VALUE, aSheet);2144 values.push(value);2145 token = this.getToken(true, true);2146 break;2147 }2148 }2149 else if (token.isSymbol("{")2150 || token.isSymbol("(")2151 || token.isSymbol("[")) {2152 blocks.push(token.value);2153 }2154 else if (token.isSymbol("}")2155 || token.isSymbol("]")) {2156 if (blocks.length) {2157 var ontop = blocks[blocks.length - 1];2158 if ((token.isSymbol("}") && ontop == "{")2159 || (token.isSymbol(")") && ontop == "(")2160 || (token.isSymbol("]") && ontop == "[")) {2161 blocks.pop();2162 }2163 }2164 }2165 // XXX must find a better way to store individual values2166 // probably a |values: []| field holding dimensions, percentages2167 // functions, idents, numbers and symbols, in that order.2168 if (token.isFunction()) {2169 if (token.isFunction("var(")) {2170 token = this.getToken(true, true);2171 if (token.isIdent()) {2172 var name = token.value;2173 token = this.getToken(true, true);2174 if (token.isSymbol(")")) {2175 var value = new jscsspVariable(kJscsspVARIABLE_VALUE, aSheet);2176 valueText += "var(" + name + ")";2177 value.name = name;2178 values.push(value);2179 }2180 else2181 return "";2182 }2183 else2184 return "";2185 }2186 else {2187 var fn = token.value;2188 token = this.getToken(false, true);2189 var arg = this.parseFunctionArgument(token);2190 if (arg) {2191 valueText += fn + arg;2192 var value = new jscsspVariable(kJscsspPRIMITIVE_VALUE, aSheet);2193 value.value = fn + arg;2194 values.push(value);2195 }2196 else2197 return "";2198 }2199 }2200 else if (token.isSymbol("#")) {2201 var color = this.parseColor(token);2202 if (color) {2203 valueText += color;2204 var value = new jscsspVariable(kJscsspPRIMITIVE_VALUE, aSheet);2205 value.value = color;2206 values.push(value);2207 }2208 else2209 return "";2210 }2211 else if (!token.isWhiteSpace() && !token.isSymbol(",")) {2212 var value = new jscsspVariable(kJscsspPRIMITIVE_VALUE, aSheet);2213 value.value = token.value;2214 values.push(value);2215 valueText += token.value;2216 }2217 else2218 valueText += token.value;2219 token = this.getToken(false, true);2220 }2221 if (values.length && valueText) {2222 this.forgetState();2223 aDecl.push(this._createJscsspDeclarationFromValuesArray(descriptor, values, valueText));2224 return valueText;2225 }2226 return "";2227 },2228 parseMarginOrPaddingShorthand: function(token, aDecl, aAcceptPriority, aProperty)2229 {2230 var top = null;2231 var bottom = null;2232 var left = null;2233 var right = null;2234 var values = [];2235 while (true) {2236 if (!token.isNotNull())2237 break;2238 if (token.isSymbol(";")2239 || (aAcceptPriority && token.isSymbol("!"))2240 || token.isSymbol("}")) {2241 if (token.isSymbol("}"))2242 this.ungetToken();2243 break;2244 }2245 else if (!values.length && token.isIdent(this.kINHERIT)) {2246 values.push(token.value);2247 token = this.getToken(true, true);2248 break;2249 }2250 else if (token.isDimension()2251 || token.isNumber("0")2252 || token.isPercentage()2253 || token.isIdent("auto")) {2254 values.push(token.value);2255 }2256 else2257 return "";2258 token = this.getToken(true, true);2259 }2260 var count = values.length;2261 switch (count) {2262 case 1:2263 top = values[0];2264 bottom = top;2265 left = top;2266 right = top;2267 break;2268 case 2:2269 top = values[0];2270 bottom = top;2271 left = values[1];2272 right = left;2273 break;2274 case 3:2275 top = values[0];2276 left = values[1];2277 right = left;2278 bottom = values[2];2279 break;2280 case 4:2281 top = values[0];2282 right = values[1];2283 bottom = values[2];2284 left = values[3];2285 break;2286 default:2287 return "";2288 }2289 this.forgetState();2290 aDecl.push(this._createJscsspDeclarationFromValue(aProperty + "-top", top));2291 aDecl.push(this._createJscsspDeclarationFromValue(aProperty + "-right", right));2292 aDecl.push(this._createJscsspDeclarationFromValue(aProperty + "-bottom", bottom));2293 aDecl.push(this._createJscsspDeclarationFromValue(aProperty + "-left", left));2294 return top + " " + right + " " + bottom + " " + left;2295 },2296 parseBorderColorShorthand: function(token, aDecl, aAcceptPriority)2297 {2298 var top = null;2299 var bottom = null;2300 var left = null;2301 var right = null;2302 var values = [];2303 while (true) {2304 if (!token.isNotNull())2305 break;2306 if (token.isSymbol(";")2307 || (aAcceptPriority && token.isSymbol("!"))2308 || token.isSymbol("}")) {2309 if (token.isSymbol("}"))2310 this.ungetToken();2311 break;2312 }2313 else if (!values.length && token.isIdent(this.kINHERIT)) {2314 values.push(token.value);2315 token = this.getToken(true, true);2316 break;2317 }2318 2319 else {2320 var color = this.parseColor(token);2321 if (color)2322 values.push(color);2323 else2324 return "";2325 }2326 token = this.getToken(true, true);2327 }2328 var count = values.length;2329 switch (count) {2330 case 1:2331 top = values[0];2332 bottom = top;2333 left = top;2334 right = top;2335 break;2336 case 2:2337 top = values[0];2338 bottom = top;2339 left = values[1];2340 right = left;2341 break;2342 case 3:2343 top = values[0];2344 left = values[1];2345 right = left;2346 bottom = values[2];2347 break;2348 case 4:2349 top = values[0];2350 right = values[1];2351 bottom = values[2];2352 left = values[3];2353 break;2354 default:2355 return "";2356 }2357 this.forgetState();2358 aDecl.push(this._createJscsspDeclarationFromValue("border-top-color", top));2359 aDecl.push(this._createJscsspDeclarationFromValue("border-right-color", right));2360 aDecl.push(this._createJscsspDeclarationFromValue("border-bottom-color", bottom));2361 aDecl.push(this._createJscsspDeclarationFromValue("border-left-color", left));2362 return top + " " + right + " " + bottom + " " + left;2363 },2364 parseCueShorthand: function(token, declarations, aAcceptPriority)2365 {2366 var before = "";2367 var after = "";2368 var values = [];2369 var values = [];2370 while (true) {2371 if (!token.isNotNull())2372 break;2373 if (token.isSymbol(";")2374 || (aAcceptPriority && token.isSymbol("!"))2375 || token.isSymbol("}")) {2376 if (token.isSymbol("}"))2377 this.ungetToken();2378 break;2379 }2380 else if (!values.length && token.isIdent(this.kINHERIT)) {2381 values.push(token.value);2382 }2383 else if (token.isIdent("none"))2384 values.push(token.value);2385 else if (token.isFunction("url(")) {2386 var token = this.getToken(true, true);2387 var urlContent = this.parseURL(token);2388 if (urlContent)2389 values.push("url(" + urlContent);2390 else2391 return "";2392 }2393 else2394 return "";2395 token = this.getToken(true, true);2396 }2397 var count = values.length;2398 switch (count) {2399 case 1:2400 before = values[0];2401 after = before;2402 break;2403 case 2:2404 before = values[0];2405 after = values[1];2406 break;2407 default:2408 return "";2409 }2410 this.forgetState();2411 aDecl.push(this._createJscsspDeclarationFromValue("cue-before", before));2412 aDecl.push(this._createJscsspDeclarationFromValue("cue-after", after));2413 return before + " " + after;2414 },2415 parsePauseShorthand: function(token, declarations, aAcceptPriority)2416 {2417 var before = "";2418 var after = "";2419 var values = [];2420 var values = [];2421 while (true) {2422 if (!token.isNotNull())2423 break;2424 if (token.isSymbol(";")2425 || (aAcceptPriority && token.isSymbol("!"))2426 || token.isSymbol("}")) {2427 if (token.isSymbol("}"))2428 this.ungetToken();2429 break;2430 }2431 else if (!values.length && token.isIdent(this.kINHERIT)) {2432 values.push(token.value);2433 }2434 else if (token.isDimensionOfUnit("ms")2435 || token.isDimensionOfUnit("s")2436 || token.isPercentage()2437 || token.isNumber("0"))2438 values.push(token.value);2439 else2440 return "";2441 token = this.getToken(true, true);2442 }2443 var count = values.length;2444 switch (count) {2445 case 1:2446 before = values[0];2447 after = before;2448 break;2449 case 2:2450 before = values[0];2451 after = values[1];2452 break;2453 default:2454 return "";2455 }2456 this.forgetState();2457 aDecl.push(this._createJscsspDeclarationFromValue("pause-before", before));2458 aDecl.push(this._createJscsspDeclarationFromValue("pause-after", after));2459 return before + " " + after;2460 },2461 parseBorderWidthShorthand: function(token, aDecl, aAcceptPriority)2462 {2463 var top = null;2464 var bottom = null;2465 var left = null;2466 var right = null;2467 var values = [];2468 while (true) {2469 if (!token.isNotNull())2470 break;2471 if (token.isSymbol(";")2472 || (aAcceptPriority && token.isSymbol("!"))2473 || token.isSymbol("}")) {2474 if (token.isSymbol("}"))2475 this.ungetToken();2476 break;2477 }2478 else if (!values.length && token.isIdent(this.kINHERIT)) {2479 values.push(token.value);2480 }2481 2482 else if (token.isDimension()2483 || token.isNumber("0")2484 || (token.isIdent() && token.value in this.kBORDER_WIDTH_NAMES)) {2485 values.push(token.value);2486 }2487 else2488 return "";2489 token = this.getToken(true, true);2490 }2491 var count = values.length;2492 switch (count) {2493 case 1:2494 top = values[0];2495 bottom = top;2496 left = top;2497 right = top;2498 break;2499 case 2:2500 top = values[0];2501 bottom = top;2502 left = values[1];2503 right = left;2504 break;2505 case 3:2506 top = values[0];2507 left = values[1];2508 right = left;2509 bottom = values[2];2510 break;2511 case 4:2512 top = values[0];2513 right = values[1];2514 bottom = values[2];2515 left = values[3];2516 break;2517 default:2518 return "";2519 }2520 this.forgetState();2521 aDecl.push(this._createJscsspDeclarationFromValue("border-top-width", top));2522 aDecl.push(this._createJscsspDeclarationFromValue("border-right-width", right));2523 aDecl.push(this._createJscsspDeclarationFromValue("border-bottom-width", bottom));2524 aDecl.push(this._createJscsspDeclarationFromValue("border-left-width", left));2525 return top + " " + right + " " + bottom + " " + left;2526 },2527 parseBorderStyleShorthand: function(token, aDecl, aAcceptPriority)2528 {2529 var top = null;2530 var bottom = null;2531 var left = null;2532 var right = null;2533 var values = [];2534 while (true) {2535 if (!token.isNotNull())2536 break;2537 if (token.isSymbol(";")2538 || (aAcceptPriority && token.isSymbol("!"))2539 || token.isSymbol("}")) {2540 if (token.isSymbol("}"))2541 this.ungetToken();2542 break;2543 }2544 else if (!values.length && token.isIdent(this.kINHERIT)) {2545 values.push(token.value);2546 }2547 2548 else if (token.isIdent() && token.value in this.kBORDER_STYLE_NAMES) {2549 values.push(token.value);2550 }2551 else2552 return "";2553 token = this.getToken(true, true);2554 }2555 var count = values.length;2556 switch (count) {2557 case 1:2558 top = values[0];2559 bottom = top;2560 left = top;2561 right = top;2562 break;2563 case 2:2564 top = values[0];2565 bottom = top;2566 left = values[1];2567 right = left;2568 break;2569 case 3:2570 top = values[0];2571 left = values[1];2572 right = left;2573 bottom = values[2];2574 break;2575 case 4:2576 top = values[0];2577 right = values[1];2578 bottom = values[2];2579 left = values[3];2580 break;2581 default:2582 return "";2583 }2584 this.forgetState();2585 aDecl.push(this._createJscsspDeclarationFromValue("border-top-style", top));2586 aDecl.push(this._createJscsspDeclarationFromValue("border-right-style", right));2587 aDecl.push(this._createJscsspDeclarationFromValue("border-bottom-style", bottom));2588 aDecl.push(this._createJscsspDeclarationFromValue("border-left-style", left));2589 return top + " " + right + " " + bottom + " " + left;2590 },2591 parseBorderEdgeOrOutlineShorthand: function(token, aDecl, aAcceptPriority, aProperty)2592 {2593 var bWidth = null;2594 var bStyle = null;2595 var bColor = null;2596 while (true) {2597 if (!token.isNotNull())2598 break;2599 if (token.isSymbol(";")2600 || (aAcceptPriority && token.isSymbol("!"))2601 || token.isSymbol("}")) {2602 if (token.isSymbol("}"))2603 this.ungetToken();2604 break;2605 }2606 else if (!bWidth && !bStyle && !bColor2607 && token.isIdent(this.kINHERIT)) {2608 bWidth = this.kINHERIT;2609 bStyle = this.kINHERIT;2610 bColor = this.kINHERIT;2611 }2612 else if (!bWidth &&2613 (token.isDimension()2614 || (token.isIdent() && token.value in this.kBORDER_WIDTH_NAMES)2615 || token.isNumber("0"))) {2616 bWidth = token.value;2617 }2618 else if (!bStyle &&2619 (token.isIdent() && token.value in this.kBORDER_STYLE_NAMES)) {2620 bStyle = token.value;2621 }2622 else {2623 var color = (aProperty == "outline" && token.isIdent("invert"))2624 ? "invert" : this.parseColor(token);2625 if (!bColor && color)2626 bColor = color;2627 else2628 return "";2629 }2630 token = this.getToken(true, true);2631 }2632 // create the declarations2633 this.forgetState();2634 bWidth = bWidth ? bWidth : "medium";2635 bStyle = bStyle ? bStyle : "none";2636 bColor = bColor ? bColor : "-moz-initial";2637 function addPropertyToDecl(aSelf, aDecl, property, w, s, c) {2638 aDecl.push(aSelf._createJscsspDeclarationFromValue(property + "-width", w));2639 aDecl.push(aSelf._createJscsspDeclarationFromValue(property + "-style", s));2640 aDecl.push(aSelf._createJscsspDeclarationFromValue(property + "-color", c));2641 }2642 if (aProperty == "border") {2643 addPropertyToDecl(this, aDecl, "border-top", bWidth, bStyle, bColor);2644 addPropertyToDecl(this, aDecl, "border-right", bWidth, bStyle, bColor);2645 addPropertyToDecl(this, aDecl, "border-bottom", bWidth, bStyle, bColor);2646 addPropertyToDecl(this, aDecl, "border-left", bWidth, bStyle, bColor);2647 }2648 else2649 addPropertyToDecl(this, aDecl, aProperty, bWidth, bStyle, bColor);2650 return bWidth + " " + bStyle + " " + bColor;2651 },2652 parseBackgroundShorthand: function(token, aDecl, aAcceptPriority)2653 {2654 var kHPos = {"left": true, "right": true };2655 var kVPos = {"top": true, "bottom": true };2656 var kPos = {"left": true, "right": true, "top": true, "bottom": true, "center": true};2657 var bgColor = null;2658 var bgRepeat = null;2659 var bgAttachment = null;2660 var bgImage = null;2661 var bgPosition = null;2662 while (true) {2663 if (!token.isNotNull())2664 break;2665 if (token.isSymbol(";")2666 || (aAcceptPriority && token.isSymbol("!"))2667 || token.isSymbol("}")) {2668 if (token.isSymbol("}"))2669 this.ungetToken();2670 break;2671 }2672 else if (!bgColor && !bgRepeat && !bgAttachment && !bgImage && !bgPosition2673 && token.isIdent(this.kINHERIT)) {2674 bgColor = this.kINHERIT;2675 bgRepeat = this.kINHERIT;2676 bgAttachment = this.kINHERIT;2677 bgImage = this.kINHERIT;2678 bgPosition = this.kINHERIT;2679 }2680 else {2681 if (!bgAttachment &&2682 (token.isIdent("scroll")2683 || token.isIdent("fixed"))) {2684 bgAttachment = token.value;2685 }2686 else if (!bgPosition &&2687 ((token.isIdent() && token.value in kPos)2688 || token.isDimension()2689 || token.isNumber("0")2690 || token.isPercentage())) {2691 bgPosition = token.value;2692 token = this.getToken(true, true);2693 if (token.isDimension() || token.isNumber("0") || token.isPercentage()) {2694 bgPosition += " " + token.value;2695 }2696 else if (token.isIdent() && token.value in kPos) {2697 if ((bgPosition in kHPos && token.value in kHPos) ||2698 (bgPosition in kVPos && token.value in kVPos))2699 return "";2700 bgPosition += " " + token.value;2701 }2702 else {2703 this.ungetToken();2704 bgPosition += " center";2705 }2706 }2707 else if (!bgRepeat &&2708 (token.isIdent("repeat")2709 || token.isIdent("repeat-x")2710 || token.isIdent("repeat-y")2711 || token.isIdent("no-repeat"))) {2712 bgRepeat = token.value;2713 }2714 else if (!bgImage &&2715 (token.isFunction("url(")2716 || token.isIdent("none"))) {2717 bgImage = token.value;2718 if (token.isFunction("url(")) {2719 token = this.getToken(true, true);2720 var url = this.parseURL(token); // TODO2721 if (url)2722 bgImage += url;2723 else2724 return "";2725 }2726 }2727 else if (!bgImage &&2728 (token.isFunction("-moz-linear-gradient(")2729 || token.isFunction("-moz-radial-gradient(")2730 || token.isFunction("-moz-repeating-linear-gradient(")2731 || token.isFunction("-moz-repeating-radial-gradient("))) {2732 var gradient = CssInspector.parseGradient(this, token);2733 if (gradient)2734 bgImage = CssInspector.serializeGradient(gradient);2735 else2736 return "";2737 }2738 else {2739 var color = this.parseColor(token);2740 if (!bgColor && color)2741 bgColor = color;2742 else2743 return "";2744 }2745 }2746 token = this.getToken(true, true);2747 }2748 // create the declarations2749 this.forgetState();2750 bgColor = bgColor ? bgColor : "transparent";2751 bgImage = bgImage ? bgImage : "none";2752 bgRepeat = bgRepeat ? bgRepeat : "repeat";2753 bgAttachment = bgAttachment ? bgAttachment : "scroll";2754 bgPosition = bgPosition ? bgPosition : "top left";2755 aDecl.push(this._createJscsspDeclarationFromValue("background-color", bgColor));2756 aDecl.push(this._createJscsspDeclarationFromValue("background-image", bgImage));2757 aDecl.push(this._createJscsspDeclarationFromValue("background-repeat", bgRepeat));2758 aDecl.push(this._createJscsspDeclarationFromValue("background-attachment", bgAttachment));2759 aDecl.push(this._createJscsspDeclarationFromValue("background-position", bgPosition));2760 return bgColor + " " + bgImage + " " + bgRepeat + " " + bgAttachment + " " + bgPosition;2761 },2762 parseListStyleShorthand: function(token, aDecl, aAcceptPriority)2763 {2764 var kPosition = { "inside": true, "outside": true };2765 var lType = null;2766 var lPosition = null;2767 var lImage = null;2768 while (true) {2769 if (!token.isNotNull())2770 break;2771 if (token.isSymbol(";")2772 || (aAcceptPriority && token.isSymbol("!"))2773 || token.isSymbol("}")) {2774 if (token.isSymbol("}"))2775 this.ungetToken();2776 break;2777 }2778 else if (!lType && !lPosition && ! lImage2779 && token.isIdent(this.kINHERIT)) {2780 lType = this.kINHERIT;2781 lPosition = this.kINHERIT;2782 lImage = this.kINHERIT;2783 }2784 else if (!lType &&2785 (token.isIdent() && token.value in this.kLIST_STYLE_TYPE_NAMES)) {2786 lType = token.value;2787 }2788 else if (!lPosition &&2789 (token.isIdent() && token.value in kPosition)) {2790 lPosition = token.value;2791 }2792 else if (!lImage && token.isFunction("url")) {2793 token = this.getToken(true, true);2794 var urlContent = this.parseURL(token);2795 if (urlContent) {2796 lImage = "url(" + urlContent;2797 }2798 else2799 return "";2800 }2801 else if (!token.isIdent("none"))2802 return "";2803 token = this.getToken(true, true);2804 }2805 // create the declarations2806 this.forgetState();2807 lType = lType ? lType : "none";2808 lImage = lImage ? lImage : "none";2809 lPosition = lPosition ? lPosition : "outside";2810 aDecl.push(this._createJscsspDeclarationFromValue("list-style-type", lType));2811 aDecl.push(this._createJscsspDeclarationFromValue("list-style-position", lPosition));2812 aDecl.push(this._createJscsspDeclarationFromValue("list-style-image", lImage));2813 return lType + " " + lPosition + " " + lImage;2814 },2815 parseFontShorthand: function(token, aDecl, aAcceptPriority)2816 {2817 var kStyle = {"italic": true, "oblique": true };2818 var kVariant = {"small-caps": true };2819 var kWeight = { "bold": true, "bolder": true, "lighter": true,2820 "100": true, "200": true, "300": true, "400": true,2821 "500": true, "600": true, "700": true, "800": true,2822 "900": true };2823 var kSize = { "xx-small": true, "x-small": true, "small": true, "medium": true,2824 "large": true, "x-large": true, "xx-large": true,2825 "larger": true, "smaller": true };2826 var kValues = { "caption": true, "icon": true, "menu": true, "message-box": true, "small-caption": true, "status-bar": true };2827 var kFamily = { "serif": true, "sans-serif": true, "cursive": true, "fantasy": true, "monospace": true };2828 var fStyle = null;2829 var fVariant = null;2830 var fWeight = null;2831 var fSize = null;2832 var fLineHeight = null;2833 var fFamily = "";2834 var fSystem = null;2835 var fFamilyValues = [];2836 var normalCount = 0;2837 while (true) {2838 if (!token.isNotNull())2839 break;2840 if (token.isSymbol(";")2841 || (aAcceptPriority && token.isSymbol("!"))2842 || token.isSymbol("}")) {2843 if (token.isSymbol("}"))2844 this.ungetToken();2845 break;2846 }2847 else if (!fStyle && !fVariant && !fWeight2848 && !fSize && !fLineHeight && !fFamily2849 && !fSystem2850 && token.isIdent(this.kINHERIT)) {2851 fStyle = this.kINHERIT;2852 fVariant = this.kINHERIT;2853 fWeight = this.kINHERIT;2854 fSize = this.kINHERIT;2855 fLineHeight = this.kINHERIT;2856 fFamily = this.kINHERIT;2857 fSystem = this.kINHERIT;2858 }2859 else {2860 if (!fSystem && (token.isIdent() && token.value in kValues)) {2861 fSystem = token.value;2862 break;2863 }2864 else {2865 if (!fStyle2866 && token.isIdent()2867 && (token.value in kStyle)) {2868 fStyle = token.value;2869 }2870 2871 else if (!fVariant2872 && token.isIdent()2873 && (token.value in kVariant)) {2874 fVariant = token.value;2875 }2876 2877 else if (!fWeight2878 && (token.isIdent() || token.isNumber())2879 && (token.value in kWeight)) {2880 fWeight = token.value;2881 }2882 2883 else if (!fSize2884 && ((token.isIdent() && (token.value in kSize))2885 || token.isDimension()2886 || token.isPercentage())) {2887 fSize = token.value;2888 var token = this.getToken(false, false);2889 if (token.isSymbol("/")) {2890 token = this.getToken(false, false);2891 if (!fLineHeight &&2892 (token.isDimension() || token.isNumber() || token.isPercentage())) {2893 fLineHeight = token.value;2894 }2895 else2896 return "";2897 }2898 else2899 this.ungetToken();2900 }2901 else if (token.isIdent("normal")) {2902 normalCount++;2903 if (normalCount > 3)2904 return "";2905 }2906 else if (!fFamily && // *MUST* be last to be tested here2907 (token.isString()2908 || token.isIdent())) {2909 var lastWasComma = false;2910 while (true) {2911 if (!token.isNotNull())2912 break;2913 else if (token.isSymbol(";")2914 || (aAcceptPriority && token.isSymbol("!"))2915 || token.isSymbol("}")) {2916 this.ungetToken();2917 break;2918 }2919 else if (token.isIdent() && token.value in kFamily) {2920 var value = new jscsspVariable(kJscsspPRIMITIVE_VALUE, null);2921 value.value = token.value;2922 fFamilyValues.push(value);2923 fFamily += token.value;2924 break;2925 }2926 else if (token.isString() || token.isIdent()) {2927 var value = new jscsspVariable(kJscsspPRIMITIVE_VALUE, null);2928 value.value = token.value;2929 fFamilyValues.push(value);2930 fFamily += token.value;2931 lastWasComma = false;2932 }2933 else if (!lastWasComma && token.isSymbol(",")) {2934 fFamily += ", ";2935 lastWasComma = true;2936 }2937 else2938 return "";2939 token = this.getToken(true, true);2940 }2941 }2942 else {2943 return "";2944 }2945 }2946 }2947 token = this.getToken(true, true);2948 }2949 // create the declarations2950 this.forgetState();2951 if (fSystem) {2952 aDecl.push(this._createJscsspDeclarationFromValue("font", fSystem));2953 return fSystem;2954 }2955 fStyle = fStyle ? fStyle : "normal";2956 fVariant = fVariant ? fVariant : "normal";2957 fWeight = fWeight ? fWeight : "normal";2958 fSize = fSize ? fSize : "medium";2959 fLineHeight = fLineHeight ? fLineHeight : "normal";2960 fFamily = fFamily ? fFamily : "-moz-initial";2961 aDecl.push(this._createJscsspDeclarationFromValue("font-style", fStyle));2962 aDecl.push(this._createJscsspDeclarationFromValue("font-variant", fVariant));2963 aDecl.push(this._createJscsspDeclarationFromValue("font-weight", fWeight));2964 aDecl.push(this._createJscsspDeclarationFromValue("font-size", fSize));2965 aDecl.push(this._createJscsspDeclarationFromValue("line-height", fLineHeight));2966 aDecl.push(this._createJscsspDeclarationFromValuesArray("font-family", fFamilyValues, fFamily));2967 return fStyle + " " + fVariant + " " + fWeight + " " + fSize + "/" + fLineHeight + " " + fFamily;2968 },2969 _createJscsspDeclaration: function(property, value)2970 {2971 var decl = new jscsspDeclaration();2972 decl.property = property;2973 decl.value = this.trim11(value);2974 decl.parsedCssText = property + ": " + value + ";";2975 return decl;2976 },2977 _createJscsspDeclarationFromValue: function(property, valueText)2978 {2979 var decl = new jscsspDeclaration();2980 decl.property = property;2981 var value = new jscsspVariable(kJscsspPRIMITIVE_VALUE, null);2982 value.value = valueText;2983 decl.values = [value];2984 decl.valueText = valueText;2985 decl.parsedCssText = property + ": " + valueText + ";";2986 return decl;2987 },2988 _createJscsspDeclarationFromValuesArray: function(property, values, valueText)2989 {2990 var decl = new jscsspDeclaration();2991 decl.property = property;2992 decl.values = values;2993 decl.valueText = valueText;2994 decl.parsedCssText = property + ": " + valueText + ";";2995 return decl;2996 },2997 parseURL: function(token)2998 {2999 var value = "";3000 if (token.isString())3001 {3002 value += token.value;3003 token = this.getToken(true, true);3004 }3005 else3006 while (true)3007 {3008 if (!token.isNotNull()) {3009 this.reportError(kURL_EOF);3010 return "";3011 }3012 if (token.isWhiteSpace()) {3013 nextToken = this.lookAhead(true, true);3014 // if next token is not a closing parenthesis, that's an error3015 if (!nextToken.isSymbol(")")) {3016 this.reportError(kURL_WS_INSIDE);3017 token = this.currentToken();3018 break;3019 }3020 }3021 if (token.isSymbol(")")) {3022 break;3023 }3024 value += token.value;3025 token = this.getToken(false, false);3026 }3027 if (token.isSymbol(")")) {3028 return value + ")";3029 }3030 return "";3031 },3032 parseFunctionArgument: function(token)3033 {3034 var value = "";3035 if (token.isString())3036 {3037 value += token.value;3038 token = this.getToken(true, true);3039 }3040 else {3041 var parenthesis = 1;3042 while (true)3043 {3044 if (!token.isNotNull())3045 return "";3046 if (token.isFunction() || token.isSymbol("("))3047 parenthesis++;3048 if (token.isSymbol(")")) {3049 parenthesis--;3050 if (!parenthesis)3051 break;3052 }3053 value += token.value;3054 token = this.getToken(false, false);3055 }3056 }3057 if (token.isSymbol(")"))3058 return value + ")";3059 return "";3060 },3061 parseColor: function(token)3062 {3063 var color = "";3064 if (token.isFunction("rgb(")3065 || token.isFunction("rgba(")) {3066 color = token.value;3067 var isRgba = token.isFunction("rgba(")3068 token = this.getToken(true, true);3069 if (!token.isNumber() && !token.isPercentage())3070 return "";3071 color += token.value;3072 token = this.getToken(true, true);3073 if (!token.isSymbol(","))3074 return "";3075 color += ", ";3076 3077 token = this.getToken(true, true);3078 if (!token.isNumber() && !token.isPercentage())3079 return "";3080 color += token.value;3081 token = this.getToken(true, true);3082 if (!token.isSymbol(","))3083 return "";3084 color += ", ";3085 3086 token = this.getToken(true, true);3087 if (!token.isNumber() && !token.isPercentage())3088 return "";3089 color += token.value;3090 3091 if (isRgba) {3092 token = this.getToken(true, true);3093 if (!token.isSymbol(","))3094 return "";3095 color += ", ";3096 3097 token = this.getToken(true, true);3098 if (!token.isNumber())3099 return "";3100 color += token.value;3101 }3102 3103 token = this.getToken(true, true);3104 if (!token.isSymbol(")"))3105 return "";3106 color += token.value;3107 }3108 3109 else if (token.isFunction("hsl(")3110 || token.isFunction("hsla(")) {3111 color = token.value;3112 var isHsla = token.isFunction("hsla(")3113 token = this.getToken(true, true);3114 if (!token.isNumber())3115 return "";3116 color += token.value;3117 token = this.getToken(true, true);3118 if (!token.isSymbol(","))3119 return "";3120 color += ", ";3121 3122 token = this.getToken(true, true);3123 if (!token.isPercentage())3124 return "";3125 color += token.value;3126 token = this.getToken(true, true);3127 if (!token.isSymbol(","))3128 return "";3129 color += ", ";3130 3131 token = this.getToken(true, true);3132 if (!token.isPercentage())3133 return "";3134 color += token.value;3135 3136 if (isHsla) {3137 token = this.getToken(true, true);3138 if (!token.isSymbol(","))3139 return "";3140 color += ", ";3141 3142 token = this.getToken(true, true);3143 if (!token.isNumber())3144 return "";3145 color += token.value;3146 }3147 3148 token = this.getToken(true, true);3149 if (!token.isSymbol(")"))3150 return "";3151 color += token.value;3152 }3153 else if (token.isIdent()3154 && (token.value in this.kCOLOR_NAMES))3155 color = token.value;3156 else if (token.isSymbol("#")) {3157 token = this.getHexValue();3158 if (!token.isHex())3159 return "";3160 var length = token.value.length;3161 if (length != 3 && length != 6)3162 return "";3163 if (token.value.match( /[a-fA-F0-9]/g ).length != length)3164 return "";3165 color = "#" + token.value;3166 }3167 return color;3168 },3169 parseDeclaration: function(aToken, aDecl, aAcceptPriority, aExpandShorthands, aSheet) {3170 this.preserveState();3171 var blocks = [];3172 if (aToken.isIdent()) {3173 var descriptor = aToken.value.toLowerCase();3174 var token = this.getToken(true, true);3175 if (token.isSymbol(":")) {3176 var token = this.getToken(true, true);3177 var value = "";3178 var declarations = [];3179 if (aExpandShorthands)3180 switch (descriptor) {3181 case "background":3182 value = this.parseBackgroundShorthand(token, declarations, aAcceptPriority);3183 break;3184 case "margin":3185 case "padding":3186 value = this.parseMarginOrPaddingShorthand(token, declarations, aAcceptPriority, descriptor);3187 break;3188 case "border-color":3189 value = this.parseBorderColorShorthand(token, declarations, aAcceptPriority);3190 break;3191 case "border-style":3192 value = this.parseBorderStyleShorthand(token, declarations, aAcceptPriority);3193 break;3194 case "border-width":3195 value = this.parseBorderWidthShorthand(token, declarations, aAcceptPriority);3196 break;3197 case "border-top":3198 case "border-right":3199 case "border-bottom":3200 case "border-left":3201 case "border":3202 case "outline":3203 value = this.parseBorderEdgeOrOutlineShorthand(token, declarations, aAcceptPriority, descriptor);3204 break;3205 case "cue":3206 value = this.parseCueShorthand(token, declarations, aAcceptPriority);3207 break;3208 case "pause":3209 value = this.parsePauseShorthand(token, declarations, aAcceptPriority);3210 break;3211 case "font":3212 value = this.parseFontShorthand(token, declarations, aAcceptPriority);3213 break;3214 case "list-style":3215 value = this.parseListStyleShorthand(token, declarations, aAcceptPriority);3216 break;3217 default:3218 value = this.parseDefaultPropertyValue(token, declarations, aAcceptPriority, descriptor, aSheet);3219 break;3220 }3221 else3222 value = this.parseDefaultPropertyValue(token, declarations, aAcceptPriority, descriptor, aSheet);3223 token = this.currentToken();3224 if (value) // no error above3225 {3226 var priority = false;3227 if (token.isSymbol("!")) {3228 token = this.getToken(true, true);3229 if (token.isIdent("important")) {3230 priority = true;3231 token = this.getToken(true, true);3232 if (token.isSymbol(";") || token.isSymbol("}")) {3233 if (token.isSymbol("}"))3234 this.ungetToken();3235 }3236 else return "";3237 }3238 else return "";3239 }3240 else if (token.isNotNull() && !token.isSymbol(";") && !token.isSymbol("}"))3241 return "";3242 for (var i = 0; i < declarations.length; i++) {3243 declarations[i].priority = priority;3244 aDecl.push(declarations[i]);3245 }3246 return descriptor + ": " + value + ";";3247 }3248 }3249 }3250 else if (aToken.isComment()) {3251 if (this.mPreserveComments) {3252 this.forgetState();3253 var comment = new jscsspComment();3254 comment.parsedCssText = aToken.value;3255 aDecl.push(comment);3256 }3257 return aToken.value;3258 }3259 // we have an error here, let's skip it3260 this.restoreState();3261 var s = aToken.value;3262 blocks = [];3263 var token = this.getToken(false, false);3264 while (token.isNotNull()) {3265 s += token.value;3266 if ((token.isSymbol(";") || token.isSymbol("}")) && !blocks.length) {3267 if (token.isSymbol("}"))3268 this.ungetToken();3269 break;3270 } else if (token.isSymbol("{")3271 || token.isSymbol("(")3272 || token.isSymbol("[")3273 || token.isFunction()) {3274 blocks.push(token.isFunction() ? "(" : token.value);3275 } else if (token.isSymbol("}")3276 || token.isSymbol(")")3277 || token.isSymbol("]")) {3278 if (blocks.length) {3279 var ontop = blocks[blocks.length - 1];3280 if ((token.isSymbol("}") && ontop == "{")3281 || (token.isSymbol(")") && ontop == "(")3282 || (token.isSymbol("]") && ontop == "[")) {3283 blocks.pop();3284 }3285 }3286 }3287 token = this.getToken(false, false);3288 }3289 return "";3290 },3291 parseKeyframesRule: function(aToken, aSheet) {3292 var currentLine = CountLF(this.mScanner.getAlreadyScanned());3293 var s = aToken.value;3294 var valid = false;3295 var keyframesRule = new jscsspKeyframesRule();3296 keyframesRule.currentLine = currentLine;3297 this.preserveState();3298 var token = this.getToken(true, true);3299 var foundName = false;3300 while (token.isNotNull()) {3301 if (token.isIdent()) {3302 // should be the keyframes' name3303 foundName = true;3304 s += " " + token.value;3305 keyframesRule.name = token.value;3306 token = this.getToken(true, true);3307 if (token.isSymbol("{"))3308 this.ungetToken();3309 else {3310 // error...3311 token.type = jscsspToken.NULL_TYPE;3312 break;3313 }3314 }3315 else if (token.isSymbol("{")) {3316 if (!foundName) {3317 token.type = jscsspToken.NULL_TYPE;3318 // not a valid keyframes at-rule3319 }3320 break;3321 }3322 else {3323 token.type = jscsspToken.NULL_TYPE;3324 // not a valid keyframes at-rule3325 break;3326 }3327 token = this.getToken(true, true);3328 }3329 if (token.isSymbol("{") && keyframesRule.name) {3330 // ok let's parse keyframe rules now...3331 s += " { ";3332 token = this.getToken(true, false);3333 while (token.isNotNull()) {3334 if (token.isComment() && this.mPreserveComments) {3335 s += " " + token.value;3336 var comment = new jscsspComment();3337 comment.parsedCssText = token.value;3338 keyframesRule.cssRules.push(comment);3339 } else if (token.isSymbol("}")) {3340 valid = true;3341 break;3342 } else {3343 var r = this.parseKeyframeRule(token, keyframesRule, true);3344 if (r)3345 s += r;3346 }3347 token = this.getToken(true, false);3348 }3349 }3350 if (valid) {3351 this.forgetState();3352 keyframesRule.currentLine = currentLine;3353 keyframesRule.parsedCssText = s;3354 aSheet.cssRules.push(keyframesRule);3355 return true;3356 }3357 this.restoreState();3358 return false;3359 },3360 parseKeyframeRule: function(aToken, aOwner) {3361 var currentLine = CountLF(this.mScanner.getAlreadyScanned());3362 this.preserveState();3363 var token = aToken;3364 // find the keyframe keys3365 var key = "";3366 while (token.isNotNull()) {3367 if (token.isIdent() || token.isPercentage()) {3368 if (token.isIdent()3369 && !token.isIdent("from")3370 && !token.isIdent("to")) {3371 key = "";3372 break;3373 }3374 key += token.value;3375 token = this.getToken(true, true);3376 if (token.isSymbol("{")) {3377 this.ungetToken();3378 break;3379 }3380 else 3381 if (token.isSymbol(",")) {3382 key += ", ";3383 }3384 else {3385 key = "";3386 break;3387 }3388 }3389 else {3390 key = "";3391 break;3392 }3393 token = this.getToken(true, true);3394 }3395 var valid = false;3396 var declarations = [];3397 if (key) {3398 var s = key;3399 token = this.getToken(true, true);3400 if (token.isSymbol("{")) {3401 s += " { ";3402 token = this.getToken(true, false);3403 while (true) {3404 if (!token.isNotNull()) {3405 valid = true;3406 break;3407 }3408 if (token.isSymbol("}")) {3409 s += "}";3410 valid = true;3411 break;3412 } else {3413 var d = this.parseDeclaration(token, declarations, true, true, aOwner);3414 s += ((d && declarations.length) ? " " : "") + d;3415 }3416 token = this.getToken(true, false);3417 }3418 }3419 }3420 else {3421 // key is invalid so the whole rule is invalid with it3422 }3423 if (valid) {3424 var rule = new jscsspKeyframeRule();3425 rule.currentLine = currentLine;3426 rule.parsedCssText = s;3427 rule.declarations = declarations;3428 rule.keyText = key;3429 rule.parentRule = aOwner;3430 aOwner.cssRules.push(rule);3431 return s;3432 }3433 this.restoreState();3434 s = this.currentToken().value;3435 this.addUnknownAtRule(aOwner, s);3436 return "";3437 },3438 parseMediaRule: function(aToken, aSheet) {3439 this.mScanner.mMediaQueryMode = true;3440 var currentLine = CountLF(this.mScanner.getAlreadyScanned());3441 var s = aToken.value;3442 var valid = false;3443 var mediaRule = new jscsspMediaRule();3444 mediaRule.currentLine = currentLine;3445 this.preserveState();3446 var token = this.getToken(true, true);3447 var foundMedia = false;3448 while (token.isNotNull()) {3449 if (token.isIdent()) {3450 foundMedia = true;3451 s += " " + token.value;3452 mediaRule.media.push(token.value);3453 token = this.getToken(true, true);3454 if (token.isSymbol(",")) {3455 s += ",";3456 } else {3457 if (token.isSymbol("{"))3458 this.ungetToken();3459 else {3460 // error...3461 token.type = jscsspToken.NULL_TYPE;3462 break;3463 }3464 }3465 }3466 else if (token.isSymbol("{"))3467 break;3468 else if (foundMedia) {3469 token.type = jscsspToken.NULL_TYPE;3470 // not a media list3471 break;3472 }3473 token = this.getToken(true, true);3474 }3475 if (token.isSymbol("{") && mediaRule.media.length) {3476 // ok let's parse style rules now...3477 s += " { ";3478 token = this.getToken(true, false);3479 while (token.isNotNull()) {3480 if (token.isComment() && this.mPreserveComments) {3481 s += " " + token.value;3482 var comment = new jscsspComment();3483 comment.parsedCssText = token.value;3484 mediaRule.cssRules.push(comment);3485 } else if (token.isSymbol("}")) {3486 valid = true;3487 break;3488 } else {3489 var r = this.parseStyleRule(token, mediaRule, true);3490 if (r)3491 s += r;3492 }3493 token = this.getToken(true, false);3494 }3495 }3496 if (valid) {3497 this.forgetState();3498 mediaRule.parsedCssText = s;3499 aSheet.cssRules.push(mediaRule);3500 return true;3501 }3502 this.restoreState();3503 return false;3504 },3505 trim11: function(str) {3506 str = str.replace(/^\s+/, '');3507 for (var i = str.length - 1; i >= 0; i--) {3508 if (/\S/.test( str.charAt(i) )) { // XXX charat3509 str = str.substring(0, i + 1);3510 break;3511 }3512 }3513 return str;3514 },3515 parseStyleRule: function(aToken, aOwner, aIsInsideMediaRule)3516 {3517 var currentLine = CountLF(this.mScanner.getAlreadyScanned());3518 this.preserveState();3519 // first let's see if we have a selector here...3520 var selector = this.parseSelector(aToken, false);3521 var valid = false;3522 var declarations = [];3523 if (selector) {3524 selector = this.trim11(selector.selector);3525 var s = selector;3526 var token = this.getToken(true, true);3527 if (token.isSymbol("{")) {3528 s += " { ";3529 var token = this.getToken(true, false);3530 while (true) {3531 if (!token.isNotNull()) {3532 valid = true;3533 break;3534 }3535 if (token.isSymbol("}")) {3536 s += "}";3537 valid = true;3538 break;3539 } else {3540 var d = this.parseDeclaration(token, declarations, true, true, aOwner);3541 s += ((d && declarations.length) ? " " : "") + d;3542 }3543 token = this.getToken(true, false);3544 }3545 }3546 }3547 else {3548 // selector is invalid so the whole rule is invalid with it3549 }3550 if (valid) {3551 var rule = new jscsspStyleRule();3552 rule.currentLine = currentLine;3553 rule.parsedCssText = s;3554 rule.declarations = declarations;3555 rule.mSelectorText = selector;3556 if (aIsInsideMediaRule)3557 rule.parentRule = aOwner;3558 else3559 rule.parentStyleSheet = aOwner;3560 aOwner.cssRules.push(rule);3561 return s;3562 }3563 this.restoreState();3564 s = this.currentToken().value;3565 this.addUnknownAtRule(aOwner, s);3566 return "";3567 },3568 parseSelector: function(aToken, aParseSelectorOnly) {3569 var s = "";3570 var specificity = {a: 0, b: 0, c: 0, d: 0}; // CSS 2.1 section 6.4.33571 var isFirstInChain = true;3572 var token = aToken;3573 var valid = false;3574 var combinatorFound = false;3575 while (true) {3576 if (!token.isNotNull()) {3577 if (aParseSelectorOnly)3578 return {selector: s, specificity: specificity };3579 return "";3580 }3581 if (!aParseSelectorOnly && token.isSymbol("{")) {3582 // end of selector3583 valid = !combinatorFound;3584 if (valid) this.ungetToken();3585 break;3586 }3587 if (token.isSymbol(",")) { // group of selectors3588 s += token.value;3589 isFirstInChain = true;3590 combinatorFound = false;3591 token = this.getToken(false, true);3592 continue;3593 }3594 // now combinators and grouping...3595 else if (!combinatorFound3596 && (token.isWhiteSpace()3597 || token.isSymbol(">")3598 || token.isSymbol("+")3599 || token.isSymbol("~"))) {3600 if (token.isWhiteSpace()) {3601 s += " ";3602 var nextToken = this.lookAhead(true, true);3603 if (!nextToken.isNotNull()) {3604 if (aParseSelectorOnly)3605 return {selector: s, specificity: specificity };3606 return "";3607 }3608 if (nextToken.isSymbol(">")3609 || nextToken.isSymbol("+")3610 || nextToken.isSymbol("~")) {3611 token = this.getToken(true, true);3612 s += token.value + " ";3613 combinatorFound = true;3614 }3615 }3616 else {3617 s += token.value;3618 combinatorFound = true;3619 }3620 isFirstInChain = true;3621 token = this.getToken(true, true);3622 continue;3623 }3624 else {3625 var simpleSelector = this.parseSimpleSelector(token, isFirstInChain, true);3626 if (!simpleSelector)3627 break; // error3628 s += simpleSelector.selector;3629 specificity.b += simpleSelector.specificity.b;3630 specificity.c += simpleSelector.specificity.c;3631 specificity.d += simpleSelector.specificity.d;3632 isFirstInChain = false;3633 combinatorFound = false;3634 }3635 token = this.getToken(false, true);3636 }3637 if (valid) {3638 return {selector: s, specificity: specificity };3639 }3640 return "";3641 },3642 isPseudoElement: function(aIdent)3643 {3644 switch (aIdent) {3645 case "first-letter":3646 case "first-line":3647 case "before":3648 case "after":3649 case "marker":3650 return true;3651 break;3652 default: return false;3653 break;3654 }3655 },3656 parseSimpleSelector: function(token, isFirstInChain, canNegate)3657 {3658 var s = "";3659 var specificity = {a: 0, b: 0, c: 0, d: 0}; // CSS 2.1 section 6.4.33660 3661 if (isFirstInChain3662 && (token.isSymbol("*") || token.isSymbol("|") || token.isIdent())) {3663 // type or universal selector3664 if (token.isSymbol("*") || token.isIdent()) {3665 // we don't know yet if it's a prefix or a universal3666 // selector3667 s += token.value;3668 var isIdent = token.isIdent();3669 token = this.getToken(false, true);3670 if (token.isSymbol("|")) {3671 // it's a prefix3672 s += token.value;3673 token = this.getToken(false, true);3674 if (token.isIdent() || token.isSymbol("*")) {3675 // ok we now have a type element or universal3676 // selector3677 s += token.value;3678 if (token.isIdent())3679 specificity.d++;3680 } else3681 // oops that's an error...3682 return null;3683 } else {3684 this.ungetToken();3685 if (isIdent)3686 specificity.d++;3687 }3688 } else if (token.isSymbol("|")) {3689 s += token.value;3690 token = this.getToken(false, true);3691 if (token.isIdent() || token.isSymbol("*")) {3692 s += token.value;3693 if (token.isIdent())3694 specificity.d++;3695 } else3696 // oops that's an error3697 return null;3698 }3699 }3700 3701 else if (token.isSymbol(".") || token.isSymbol("#")) {3702 var isClass = token.isSymbol(".");3703 s += token.value;3704 token = this.getToken(false, true);3705 if (token.isIdent()) {3706 s += token.value;3707 if (isClass)3708 specificity.c++;3709 else3710 specificity.b++;3711 }3712 else3713 return null;3714 }3715 else if (token.isSymbol(":")) {3716 s += token.value;3717 token = this.getToken(false, true);3718 if (token.isSymbol(":")) {3719 s += token.value;3720 token = this.getToken(false, true);3721 }3722 if (token.isIdent()) {3723 s += token.value;3724 if (this.isPseudoElement(token.value))3725 specificity.d++;3726 else3727 specificity.c++;3728 }3729 else if (token.isFunction()) {3730 s += token.value;3731 if (token.isFunction(":not(")) {3732 if (!canNegate)3733 return null;3734 token = this.getToken(true, true);3735 var simpleSelector = this.parseSimpleSelector(token, isFirstInChain, false);3736 if (!simpleSelector)3737 return null;3738 else {3739 s += simpleSelector.selector;3740 token = this.getToken(true, true);3741 if (token.isSymbol(")"))3742 s += ")";3743 else3744 return null;3745 }3746 specificity.c++;3747 }3748 else {3749 while (true) {3750 token = this.getToken(false, true);3751 if (token.isSymbol(")")) {3752 s += ")";3753 break;3754 } else3755 s += token.value;3756 }3757 specificity.c++;3758 }3759 } else3760 return null;3761 3762 } else if (token.isSymbol("[")) {3763 s += "[";3764 token = this.getToken(true, true);3765 if (token.isIdent() || token.isSymbol("*")) {3766 s += token.value;3767 var nextToken = this.getToken(true, true);3768 if (token.isSymbol("|")) {3769 s += "|";3770 token = this.getToken(true, true);3771 if (token.isIdent())3772 s += token.value;3773 else3774 return null;3775 } else3776 this.ungetToken();3777 } else if (token.isSymbol("|")) {3778 s += "|";3779 token = this.getToken(true, true);3780 if (token.isIdent())3781 s += token.value;3782 else3783 return null;3784 }3785 else3786 return null;3787 3788 // nothing, =, *=, $=, ^=, |=3789 token = this.getToken(true, true);3790 if (token.isIncludes()3791 || token.isDashmatch()3792 || token.isBeginsmatch()3793 || token.isEndsmatch()3794 || token.isContainsmatch()3795 || token.isSymbol("=")) {3796 s += token.value;3797 token = this.getToken(true, true);3798 if (token.isString() || token.isIdent()) {3799 s += token.value;3800 token = this.getToken(true, true);3801 }3802 else3803 return null;3804 3805 if (token.isSymbol("]")) {3806 s += token.value;3807 specificity.c++;3808 }3809 else3810 return null;3811 }3812 else if (token.isSymbol("]")) {...

Full Screen

Full Screen

test.id.js

Source:test.id.js Github

copy

Full Screen

...50 }51 t.end();52});53test('isIdent', t => {54 t.strictEquals(id.isIdent(), false);55 t.strictEquals(id.isIdent(''), false);56 t.strictEquals(id.isIdent('foo'), false);57 t.strictEquals(id.isIdent(0), false);58 t.strictEquals(id.isIdent(null), false);59 t.strictEquals(id.isIdent(true), false);60 t.strictEquals(id.isIdent(false), false);61 t.strictEquals(id.isIdent({}), false);62 t.strictEquals(id.isIdent([]), false);63 t.strictEquals(id.isIdent(new Date()), false);64 t.strictEquals(id.isIdent(Buffer.alloc(10)), false);65 t.strictEquals(id.isIdent(Buffer.alloc(16)), false);66 t.strictEquals(id.isIdent(Buffer.alloc(0)), false);67 t.strictEquals(id.isIdent('5816b41e26f27e0494708988'), true);68 t.strictEquals(id.isIdent(Buffer.from('5816b41e26f27e0494708988', 'hex')), true);69 t.strictEquals(id.isIdent(id.genIdent('buffer')), true);70 t.strictEquals(id.isIdent(id.genIdent()), true);71 t.strictEquals(id.isIdent(id.genIdent('hex')), true);72 t.end();73});74test('getSeconds', t => {75 t.throws(() => id.getSeconds());76 t.strictEquals(id.getSeconds(Buffer.alloc(12)), 0);77 t.strictEquals(id.getSeconds('5816b41e26f27e0494708988'), 1477882910);78 t.strictEquals(id.getSeconds(Buffer.from('0000005816b41e26f27e0494708988', 'hex'), 3), 1477882910);79 t.strictEquals(id.getSeconds('WBa0HibyfgSUcImI'), 1477882910);80 t.type(id.getSeconds(id.genIdent('buffer')), 'number');81 t.type(id.getSeconds(id.genIdent()), 'number');82 t.type(id.getSeconds(id.genIdent('hex')), 'number');83 t.type(id.getSeconds(id.genIdent('base64')), 'number');84 var time = Date.now() / 1000 >>> 0;85 t.ok(id.getSeconds(id.genIdent('buffer')) >= time);...

Full Screen

Full Screen

is-ident.spec.js

Source:is-ident.spec.js Github

copy

Full Screen

1/**2 * Created by Timofey Novitskiy on 16.02.2016.3 */4define([5 'angular',6 'app/common/directives/form/is-ident.validator.directive'7], function (angular, isIdent) {8 describe("isIdent validator", function () {9 var $compile, tmpls, scope, element, $rootScope;10 angular.module('is-ident', []).directive(isIdent.$name, isIdent);11 beforeEach(module('is-ident'));12 beforeEach(inject(function (_$compile_, _$rootScope_) {13 $compile = _$compile_;14 $rootScope = _$rootScope_;15 scope = $rootScope.$new();16 element = $compile(tmpls)(scope);17 }));18 afterEach(()=>{19 scope.$destroy();20 element.remove();21 });22 it('pristine', function () {23 scope.$digest();24 var ngModelCtrl = element.controller('ngModel');25 expect(ngModelCtrl.$valid).to.be.true;26 expect(ngModelCtrl.$error.isIdent).to.be.not.true;27 });28 it('forwrad connectivity', function () {29 scope.$digest();30 var ngModelCtrl = element.controller('ngModel');31 scope.field1 = 'field1';32 scope.field2 = 'field2';33 scope.$digest();34 expect(ngModelCtrl.$valid).to.be.false;35 expect(ngModelCtrl.$error.isIdent).to.be.true;36 scope.field1 = 'field2';37 scope.$digest();38 expect(ngModelCtrl.$valid).to.be.true;39 expect(ngModelCtrl.$error.isIdent).to.be.not.true;40 });41 it('backwrad connectivity', function () {42 scope.$digest();43 var ngModelCtrl = element.controller('ngModel');44 scope.field1 = 'field1';45 scope.$digest();46 expect(ngModelCtrl.$valid).to.be.false;47 expect(ngModelCtrl.$error.isIdent).to.be.true;48 scope.field2 = 'field1';49 scope.$digest();50 expect(ngModelCtrl.$valid).to.be.true;51 expect(ngModelCtrl.$error.isIdent).to.be.not.true;52 scope.field2 = 'field2';53 scope.$digest();54 expect(ngModelCtrl.$valid).to.be.false;55 expect(ngModelCtrl.$error.isIdent).to.be.true;56 scope.field1 = 'field2';57 scope.$digest();58 expect(ngModelCtrl.$valid).to.be.true;59 expect(ngModelCtrl.$error.isIdent).to.be.not.true;60 });61 tmpls = `62 <input ng-model="field1" type="input" is-ident="field2"/>`;63 });...

Full Screen

Full Screen

is-ident.validator.directive.js

Source:is-ident.validator.directive.js Github

copy

Full Screen

1/**2 * Created by Timofey Novitskiy on 11.02.2015.3 *4 * @name isIdent5 *6 * @description Валидатор для ngModel, проверяет равно ли значениполя указанному7 * значению из скопа.8 * В случае если поле невалидно в контроллер ngModel добавляется ошибка isIdent9 * Ошибка добавляется только если контроллер ngModel помечен как $dirty10 *11 * @param {String} isIdent имя сопостоваляемого поля из скопа12 *13 * @example14 `15 <input ng-model="field1" type="input" is-ident="field2">16 `17 */18define([19 '_'20 ],21 function (_) {22 IsIdent.$inject = ['$parse'];23 IsIdent.$name = 'isIdent';24 function IsIdent($parse) {25 return {26 require : 'ngModel',27 link : function link (scope, element, attrs, ngModel) {28 var value = $parse(attrs.isIdent),29 realValue;30 scope.$watch(attrs.isIdent, function () {31 realValue = value(scope);32 ngModel.$validate();33 });34 ngModel.$validators.isIdent = function ($modelValue, $viewValue) {35 return _.isEmpty($modelValue) && _.isEmpty(realValue) || realValue === $modelValue;36 }37 }38 };39 }40 return IsIdent;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isIdent } = require('playwright/lib/utils/utils');2const { isIdent } = require('playwright/lib/utils/utils');3const { isIdent } = require('playwright/lib/utils/utils');4const { isIdent } = require('playwright/lib/utils/utils');5const { isIdent } = require('playwright/lib/utils/utils');6const { isIdent } = require('playwright/lib/utils/utils');7const { isIdent } = require('playwright/lib/utils/utils');8const { isIdent } = require('playwright/lib/utils/utils');9const { isIdent } = require('playwright/lib/utils/utils');10const { isIdent } = require('playwright/lib/utils/utils');11const { isIdent } = require('playwright/lib/utils/utils');12const { isIdent } = require('playwright/lib/utils/utils');13const { isIdent } = require('playwright/lib/utils/utils');14const { is

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isIdent } = require('playwright/lib/protocol/serializers');2const { isString } = require('playwright/lib/utils/utils');3const test = 'test';4const test2 = 'test2';5console.log(isIdent(test));6console.log(isIdent(test2));

Full Screen

Using AI Code Generation

copy

Full Screen

1import { InternalPage } from "@playwright/test/lib/page";2const internalPage = InternalPage.from(page);3await internalPage.isIdent("selector");4import { InternalPage } from "@playwright/test/lib/page";5const internalPage = InternalPage.from(page);6await internalPage.isIdent("selector");7import { InternalPage } from "@playwright/test/lib/page";8const internalPage = InternalPage.from(page);9await internalPage.isIdent("selector");10import { InternalPage } from "@playwright/test/lib/page";11const internalPage = InternalPage.from(page);12await internalPage.isIdent("selector");13import { InternalPage } from "@playwright/test/lib/page";14const internalPage = InternalPage.from(page);15await internalPage.isIdent("selector");16import { InternalPage } from "@playwright/test/lib/page";17const internalPage = InternalPage.from(page);18await internalPage.isIdent("selector");19import { InternalPage } from "@playwright/test/lib/page";20const internalPage = InternalPage.from(page);21await internalPage.isIdent("selector");22import { InternalPage } from "@playwright/test/lib/page";23const internalPage = InternalPage.from(page);24await internalPage.isIdent("selector");

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isIdent } = require('@playwright/test/lib/server/frames');2const isIdentifier = isIdent('#myId');3if(isIdentifier){4}5const { isIdent } = require('@playwright/test/lib/server/frames');6const isIdentifier = isIdent('#myId');7if(isIdentifier){8}9const { isIdent } = require('@playwright/test/lib/server/frames');10await page.click('#myId');

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful