index.js 15 KB

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