index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var IPropertyDescriptor_1 = require("./IPropertyDescriptor");
  4. var background_clip_1 = require("./property-descriptors/background-clip");
  5. var background_color_1 = require("./property-descriptors/background-color");
  6. var background_image_1 = require("./property-descriptors/background-image");
  7. var background_origin_1 = require("./property-descriptors/background-origin");
  8. var background_position_1 = require("./property-descriptors/background-position");
  9. var background_repeat_1 = require("./property-descriptors/background-repeat");
  10. var background_size_1 = require("./property-descriptors/background-size");
  11. var border_color_1 = require("./property-descriptors/border-color");
  12. var border_radius_1 = require("./property-descriptors/border-radius");
  13. var border_style_1 = require("./property-descriptors/border-style");
  14. var border_width_1 = require("./property-descriptors/border-width");
  15. var color_1 = require("./property-descriptors/color");
  16. var display_1 = require("./property-descriptors/display");
  17. var float_1 = require("./property-descriptors/float");
  18. var letter_spacing_1 = require("./property-descriptors/letter-spacing");
  19. var line_break_1 = require("./property-descriptors/line-break");
  20. var line_height_1 = require("./property-descriptors/line-height");
  21. var list_style_image_1 = require("./property-descriptors/list-style-image");
  22. var list_style_position_1 = require("./property-descriptors/list-style-position");
  23. var list_style_type_1 = require("./property-descriptors/list-style-type");
  24. var margin_1 = require("./property-descriptors/margin");
  25. var overflow_1 = require("./property-descriptors/overflow");
  26. var overflow_wrap_1 = require("./property-descriptors/overflow-wrap");
  27. var padding_1 = require("./property-descriptors/padding");
  28. var text_align_1 = require("./property-descriptors/text-align");
  29. var position_1 = require("./property-descriptors/position");
  30. var text_shadow_1 = require("./property-descriptors/text-shadow");
  31. var text_transform_1 = require("./property-descriptors/text-transform");
  32. var transform_1 = require("./property-descriptors/transform");
  33. var transform_origin_1 = require("./property-descriptors/transform-origin");
  34. var visibility_1 = require("./property-descriptors/visibility");
  35. var word_break_1 = require("./property-descriptors/word-break");
  36. var z_index_1 = require("./property-descriptors/z-index");
  37. var parser_1 = require("./syntax/parser");
  38. var tokenizer_1 = require("./syntax/tokenizer");
  39. var color_2 = require("./types/color");
  40. var angle_1 = require("./types/angle");
  41. var image_1 = require("./types/image");
  42. var opacity_1 = require("./property-descriptors/opacity");
  43. var text_decoration_color_1 = require("./property-descriptors/text-decoration-color");
  44. var text_decoration_line_1 = require("./property-descriptors/text-decoration-line");
  45. var length_percentage_1 = require("./types/length-percentage");
  46. var font_family_1 = require("./property-descriptors/font-family");
  47. var font_size_1 = require("./property-descriptors/font-size");
  48. var length_1 = require("./types/length");
  49. var font_weight_1 = require("./property-descriptors/font-weight");
  50. var font_variant_1 = require("./property-descriptors/font-variant");
  51. var font_style_1 = require("./property-descriptors/font-style");
  52. var bitwise_1 = require("../core/bitwise");
  53. var content_1 = require("./property-descriptors/content");
  54. var counter_increment_1 = require("./property-descriptors/counter-increment");
  55. var counter_reset_1 = require("./property-descriptors/counter-reset");
  56. var quotes_1 = require("./property-descriptors/quotes");
  57. var box_shadow_1 = require("./property-descriptors/box-shadow");
  58. var CSSParsedDeclaration = /** @class */ (function () {
  59. function CSSParsedDeclaration(declaration) {
  60. this.backgroundClip = parse(background_clip_1.backgroundClip, declaration.backgroundClip);
  61. this.backgroundColor = parse(background_color_1.backgroundColor, declaration.backgroundColor);
  62. this.backgroundImage = parse(background_image_1.backgroundImage, declaration.backgroundImage);
  63. this.backgroundOrigin = parse(background_origin_1.backgroundOrigin, declaration.backgroundOrigin);
  64. this.backgroundPosition = parse(background_position_1.backgroundPosition, declaration.backgroundPosition);
  65. this.backgroundRepeat = parse(background_repeat_1.backgroundRepeat, declaration.backgroundRepeat);
  66. this.backgroundSize = parse(background_size_1.backgroundSize, declaration.backgroundSize);
  67. this.borderTopColor = parse(border_color_1.borderTopColor, declaration.borderTopColor);
  68. this.borderRightColor = parse(border_color_1.borderRightColor, declaration.borderRightColor);
  69. this.borderBottomColor = parse(border_color_1.borderBottomColor, declaration.borderBottomColor);
  70. this.borderLeftColor = parse(border_color_1.borderLeftColor, declaration.borderLeftColor);
  71. this.borderTopLeftRadius = parse(border_radius_1.borderTopLeftRadius, declaration.borderTopLeftRadius);
  72. this.borderTopRightRadius = parse(border_radius_1.borderTopRightRadius, declaration.borderTopRightRadius);
  73. this.borderBottomRightRadius = parse(border_radius_1.borderBottomRightRadius, declaration.borderBottomRightRadius);
  74. this.borderBottomLeftRadius = parse(border_radius_1.borderBottomLeftRadius, declaration.borderBottomLeftRadius);
  75. this.borderTopStyle = parse(border_style_1.borderTopStyle, declaration.borderTopStyle);
  76. this.borderRightStyle = parse(border_style_1.borderRightStyle, declaration.borderRightStyle);
  77. this.borderBottomStyle = parse(border_style_1.borderBottomStyle, declaration.borderBottomStyle);
  78. this.borderLeftStyle = parse(border_style_1.borderLeftStyle, declaration.borderLeftStyle);
  79. this.borderTopWidth = parse(border_width_1.borderTopWidth, declaration.borderTopWidth);
  80. this.borderRightWidth = parse(border_width_1.borderRightWidth, declaration.borderRightWidth);
  81. this.borderBottomWidth = parse(border_width_1.borderBottomWidth, declaration.borderBottomWidth);
  82. this.borderLeftWidth = parse(border_width_1.borderLeftWidth, declaration.borderLeftWidth);
  83. this.boxShadow = parse(box_shadow_1.boxShadow, declaration.boxShadow);
  84. this.color = parse(color_1.color, declaration.color);
  85. this.display = parse(display_1.display, declaration.display);
  86. this.float = parse(float_1.float, declaration.cssFloat);
  87. this.fontFamily = parse(font_family_1.fontFamily, declaration.fontFamily);
  88. this.fontSize = parse(font_size_1.fontSize, declaration.fontSize);
  89. this.fontStyle = parse(font_style_1.fontStyle, declaration.fontStyle);
  90. this.fontVariant = parse(font_variant_1.fontVariant, declaration.fontVariant);
  91. this.fontWeight = parse(font_weight_1.fontWeight, declaration.fontWeight);
  92. this.letterSpacing = parse(letter_spacing_1.letterSpacing, declaration.letterSpacing);
  93. this.lineBreak = parse(line_break_1.lineBreak, declaration.lineBreak);
  94. this.lineHeight = parse(line_height_1.lineHeight, declaration.lineHeight);
  95. this.listStyleImage = parse(list_style_image_1.listStyleImage, declaration.listStyleImage);
  96. this.listStylePosition = parse(list_style_position_1.listStylePosition, declaration.listStylePosition);
  97. this.listStyleType = parse(list_style_type_1.listStyleType, declaration.listStyleType);
  98. this.marginTop = parse(margin_1.marginTop, declaration.marginTop);
  99. this.marginRight = parse(margin_1.marginRight, declaration.marginRight);
  100. this.marginBottom = parse(margin_1.marginBottom, declaration.marginBottom);
  101. this.marginLeft = parse(margin_1.marginLeft, declaration.marginLeft);
  102. this.opacity = parse(opacity_1.opacity, declaration.opacity);
  103. var overflowTuple = parse(overflow_1.overflow, declaration.overflow);
  104. this.overflowX = overflowTuple[0];
  105. this.overflowY = overflowTuple[overflowTuple.length > 1 ? 1 : 0];
  106. this.overflowWrap = parse(overflow_wrap_1.overflowWrap, declaration.overflowWrap);
  107. this.paddingTop = parse(padding_1.paddingTop, declaration.paddingTop);
  108. this.paddingRight = parse(padding_1.paddingRight, declaration.paddingRight);
  109. this.paddingBottom = parse(padding_1.paddingBottom, declaration.paddingBottom);
  110. this.paddingLeft = parse(padding_1.paddingLeft, declaration.paddingLeft);
  111. this.position = parse(position_1.position, declaration.position);
  112. this.textAlign = parse(text_align_1.textAlign, declaration.textAlign);
  113. this.textDecorationColor = parse(text_decoration_color_1.textDecorationColor, declaration.textDecorationColor || declaration.color);
  114. this.textDecorationLine = parse(text_decoration_line_1.textDecorationLine, declaration.textDecorationLine);
  115. this.textShadow = parse(text_shadow_1.textShadow, declaration.textShadow);
  116. this.textTransform = parse(text_transform_1.textTransform, declaration.textTransform);
  117. this.transform = parse(transform_1.transform, declaration.transform);
  118. this.transformOrigin = parse(transform_origin_1.transformOrigin, declaration.transformOrigin);
  119. this.visibility = parse(visibility_1.visibility, declaration.visibility);
  120. this.wordBreak = parse(word_break_1.wordBreak, declaration.wordBreak);
  121. this.zIndex = parse(z_index_1.zIndex, declaration.zIndex);
  122. }
  123. CSSParsedDeclaration.prototype.isVisible = function () {
  124. return this.display > 0 && this.opacity > 0 && this.visibility === visibility_1.VISIBILITY.VISIBLE;
  125. };
  126. CSSParsedDeclaration.prototype.isTransparent = function () {
  127. return color_2.isTransparent(this.backgroundColor);
  128. };
  129. CSSParsedDeclaration.prototype.isTransformed = function () {
  130. return this.transform !== null;
  131. };
  132. CSSParsedDeclaration.prototype.isPositioned = function () {
  133. return this.position !== position_1.POSITION.STATIC;
  134. };
  135. CSSParsedDeclaration.prototype.isPositionedWithZIndex = function () {
  136. return this.isPositioned() && !this.zIndex.auto;
  137. };
  138. CSSParsedDeclaration.prototype.isFloating = function () {
  139. return this.float !== float_1.FLOAT.NONE;
  140. };
  141. CSSParsedDeclaration.prototype.isInlineLevel = function () {
  142. return (bitwise_1.contains(this.display, 4 /* INLINE */) ||
  143. bitwise_1.contains(this.display, 33554432 /* INLINE_BLOCK */) ||
  144. bitwise_1.contains(this.display, 268435456 /* INLINE_FLEX */) ||
  145. bitwise_1.contains(this.display, 536870912 /* INLINE_GRID */) ||
  146. bitwise_1.contains(this.display, 67108864 /* INLINE_LIST_ITEM */) ||
  147. bitwise_1.contains(this.display, 134217728 /* INLINE_TABLE */));
  148. };
  149. return CSSParsedDeclaration;
  150. }());
  151. exports.CSSParsedDeclaration = CSSParsedDeclaration;
  152. var CSSParsedPseudoDeclaration = /** @class */ (function () {
  153. function CSSParsedPseudoDeclaration(declaration) {
  154. this.content = parse(content_1.content, declaration.content);
  155. this.quotes = parse(quotes_1.quotes, declaration.quotes);
  156. }
  157. return CSSParsedPseudoDeclaration;
  158. }());
  159. exports.CSSParsedPseudoDeclaration = CSSParsedPseudoDeclaration;
  160. var CSSParsedCounterDeclaration = /** @class */ (function () {
  161. function CSSParsedCounterDeclaration(declaration) {
  162. this.counterIncrement = parse(counter_increment_1.counterIncrement, declaration.counterIncrement);
  163. this.counterReset = parse(counter_reset_1.counterReset, declaration.counterReset);
  164. }
  165. return CSSParsedCounterDeclaration;
  166. }());
  167. exports.CSSParsedCounterDeclaration = CSSParsedCounterDeclaration;
  168. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  169. var parse = function (descriptor, style) {
  170. var tokenizer = new tokenizer_1.Tokenizer();
  171. var value = style !== null && typeof style !== 'undefined' ? style.toString() : descriptor.initialValue;
  172. tokenizer.write(value);
  173. var parser = new parser_1.Parser(tokenizer.read());
  174. switch (descriptor.type) {
  175. case IPropertyDescriptor_1.PropertyDescriptorParsingType.IDENT_VALUE:
  176. var token = parser.parseComponentValue();
  177. return descriptor.parse(parser_1.isIdentToken(token) ? token.value : descriptor.initialValue);
  178. case IPropertyDescriptor_1.PropertyDescriptorParsingType.VALUE:
  179. return descriptor.parse(parser.parseComponentValue());
  180. case IPropertyDescriptor_1.PropertyDescriptorParsingType.LIST:
  181. return descriptor.parse(parser.parseComponentValues());
  182. case IPropertyDescriptor_1.PropertyDescriptorParsingType.TOKEN_VALUE:
  183. return parser.parseComponentValue();
  184. case IPropertyDescriptor_1.PropertyDescriptorParsingType.TYPE_VALUE:
  185. switch (descriptor.format) {
  186. case 'angle':
  187. return angle_1.angle.parse(parser.parseComponentValue());
  188. case 'color':
  189. return color_2.color.parse(parser.parseComponentValue());
  190. case 'image':
  191. return image_1.image.parse(parser.parseComponentValue());
  192. case 'length':
  193. var length_2 = parser.parseComponentValue();
  194. return length_1.isLength(length_2) ? length_2 : length_percentage_1.ZERO_LENGTH;
  195. case 'length-percentage':
  196. var value_1 = parser.parseComponentValue();
  197. return length_percentage_1.isLengthPercentage(value_1) ? value_1 : length_percentage_1.ZERO_LENGTH;
  198. }
  199. }
  200. throw new Error("Attempting to parse unsupported css format type " + descriptor.format);
  201. };
  202. //# sourceMappingURL=index.js.map