Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // @ts-nocheck
  2. 'use strict';
  3. const declarationValueIndex = require('../../utils/declarationValueIndex');
  4. const isNumbery = require('../../utils/isNumbery');
  5. const isStandardSyntaxValue = require('../../utils/isStandardSyntaxValue');
  6. const isVariable = require('../../utils/isVariable');
  7. const keywordSets = require('../../reference/keywordSets');
  8. const optionsMatches = require('../../utils/optionsMatches');
  9. const postcss = require('postcss');
  10. const report = require('../../utils/report');
  11. const ruleMessages = require('../../utils/ruleMessages');
  12. const validateOptions = require('../../utils/validateOptions');
  13. const ruleName = 'font-weight-notation';
  14. const messages = ruleMessages(ruleName, {
  15. expected: (type) => `Expected ${type} font-weight notation`,
  16. invalidNamed: (name) => `Unexpected invalid font-weight name "${name}"`,
  17. });
  18. const INHERIT_KEYWORD = 'inherit';
  19. const INITIAL_KEYWORD = 'initial';
  20. const NORMAL_KEYWORD = 'normal';
  21. const WEIGHTS_WITH_KEYWORD_EQUIVALENTS = new Set(['400', '700']);
  22. function rule(expectation, options) {
  23. return (root, result) => {
  24. const validOptions = validateOptions(
  25. result,
  26. ruleName,
  27. {
  28. actual: expectation,
  29. possible: ['numeric', 'named-where-possible'],
  30. },
  31. {
  32. actual: options,
  33. possible: {
  34. ignore: ['relative'],
  35. },
  36. optional: true,
  37. },
  38. );
  39. if (!validOptions) {
  40. return;
  41. }
  42. root.walkDecls((decl) => {
  43. if (decl.prop.toLowerCase() === 'font-weight') {
  44. checkWeight(decl.value, decl);
  45. }
  46. if (decl.prop.toLowerCase() === 'font') {
  47. checkFont(decl);
  48. }
  49. });
  50. function checkFont(decl) {
  51. const valueList = postcss.list.space(decl.value);
  52. // We do not need to more carefully distinguish font-weight
  53. // numbers from unitless line-heights because line-heights in
  54. // `font` values need to be part of a font-size/line-height pair
  55. const hasNumericFontWeight = valueList.some(isNumbery);
  56. for (const value of postcss.list.space(decl.value)) {
  57. if (
  58. (value.toLowerCase() === NORMAL_KEYWORD && !hasNumericFontWeight) ||
  59. isNumbery(value) ||
  60. (value.toLowerCase() !== NORMAL_KEYWORD &&
  61. keywordSets.fontWeightKeywords.has(value.toLowerCase()))
  62. ) {
  63. checkWeight(value, decl);
  64. return;
  65. }
  66. }
  67. }
  68. function checkWeight(weightValue, decl) {
  69. if (!isStandardSyntaxValue(weightValue)) {
  70. return;
  71. }
  72. if (isVariable(weightValue)) {
  73. return;
  74. }
  75. if (
  76. weightValue.toLowerCase() === INHERIT_KEYWORD ||
  77. weightValue.toLowerCase() === INITIAL_KEYWORD
  78. ) {
  79. return;
  80. }
  81. if (
  82. optionsMatches(options, 'ignore', 'relative') &&
  83. keywordSets.fontWeightRelativeKeywords.has(weightValue.toLowerCase())
  84. ) {
  85. return;
  86. }
  87. const weightValueOffset = decl.value.indexOf(weightValue);
  88. if (expectation === 'numeric') {
  89. if (decl.parent.type === 'atrule' && decl.parent.name.toLowerCase() === 'font-face') {
  90. const weightValueNumbers = postcss.list.space(weightValue);
  91. if (!weightValueNumbers.every(isNumbery)) {
  92. return complain(messages.expected('numeric'));
  93. }
  94. return;
  95. }
  96. if (!isNumbery(weightValue)) {
  97. return complain(messages.expected('numeric'));
  98. }
  99. }
  100. if (expectation === 'named-where-possible') {
  101. if (isNumbery(weightValue)) {
  102. if (WEIGHTS_WITH_KEYWORD_EQUIVALENTS.has(weightValue)) {
  103. complain(messages.expected('named'));
  104. }
  105. return;
  106. }
  107. if (
  108. !keywordSets.fontWeightKeywords.has(weightValue.toLowerCase()) &&
  109. weightValue.toLowerCase() !== NORMAL_KEYWORD
  110. ) {
  111. return complain(messages.invalidNamed(weightValue));
  112. }
  113. }
  114. function complain(message) {
  115. report({
  116. ruleName,
  117. result,
  118. message,
  119. node: decl,
  120. index: declarationValueIndex(decl) + weightValueOffset,
  121. });
  122. }
  123. }
  124. };
  125. }
  126. rule.ruleName = ruleName;
  127. rule.messages = messages;
  128. module.exports = rule;