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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const declarationValueIndex = require('../../utils/declarationValueIndex');
  5. const keywordSets = require('../../reference/keywordSets');
  6. const optionsMatches = require('../../utils/optionsMatches');
  7. const postcss = require('postcss');
  8. const report = require('../../utils/report');
  9. const ruleMessages = require('../../utils/ruleMessages');
  10. const validateOptions = require('../../utils/validateOptions');
  11. const valueParser = require('postcss-value-parser');
  12. const vendor = require('../../utils/vendor');
  13. const ruleName = 'time-min-milliseconds';
  14. const messages = ruleMessages(ruleName, {
  15. expected: (time) => `Expected a minimum of ${time} milliseconds`,
  16. });
  17. const DELAY_PROPERTIES = new Set(['animation-delay', 'transition-delay']);
  18. function rule(minimum, options) {
  19. return (root, result) => {
  20. const validOptions = validateOptions(
  21. result,
  22. ruleName,
  23. {
  24. actual: minimum,
  25. possible: _.isNumber,
  26. },
  27. {
  28. actual: options,
  29. possible: {
  30. ignore: ['delay'],
  31. },
  32. optional: true,
  33. },
  34. );
  35. if (!validOptions) {
  36. return;
  37. }
  38. root.walkDecls((decl) => {
  39. const propertyName = vendor.unprefixed(decl.prop.toLowerCase());
  40. if (
  41. keywordSets.longhandTimeProperties.has(propertyName) &&
  42. !isIgnoredProperty(propertyName) &&
  43. !isAcceptableTime(decl.value)
  44. ) {
  45. complain(decl);
  46. }
  47. if (keywordSets.shorthandTimeProperties.has(propertyName)) {
  48. const valueListList = postcss.list.comma(decl.value);
  49. for (const valueListString of valueListList) {
  50. const valueList = postcss.list.space(valueListString);
  51. if (optionsMatches(options, 'ignore', 'delay')) {
  52. // Check only duration time values
  53. const duration = getDuration(valueList);
  54. if (duration && !isAcceptableTime(duration)) {
  55. complain(decl, decl.value.indexOf(duration));
  56. }
  57. } else {
  58. // Check all time values
  59. for (const value of valueList) {
  60. if (!isAcceptableTime(value)) {
  61. complain(decl, decl.value.indexOf(value));
  62. }
  63. }
  64. }
  65. }
  66. }
  67. });
  68. /**
  69. * Get the duration within an `animation` or `transition` shorthand property value.
  70. *
  71. * @param {Node[]} valueList
  72. *
  73. * @returns {Node}
  74. */
  75. function getDuration(valueList) {
  76. for (const value of valueList) {
  77. const parsedTime = valueParser.unit(value);
  78. if (!parsedTime) continue;
  79. // The first numeric value in an animation shorthand is the duration.
  80. return value;
  81. }
  82. }
  83. function isIgnoredProperty(propertyName) {
  84. if (optionsMatches(options, 'ignore', 'delay') && DELAY_PROPERTIES.has(propertyName)) {
  85. return true;
  86. }
  87. return false;
  88. }
  89. function isAcceptableTime(time) {
  90. const parsedTime = valueParser.unit(time);
  91. if (!parsedTime) return true;
  92. if (parsedTime.number <= 0) {
  93. return true;
  94. }
  95. if (parsedTime.unit.toLowerCase() === 'ms' && parsedTime.number < minimum) {
  96. return false;
  97. }
  98. if (parsedTime.unit.toLowerCase() === 's' && parsedTime.number * 1000 < minimum) {
  99. return false;
  100. }
  101. return true;
  102. }
  103. function complain(decl, offset = 0) {
  104. report({
  105. result,
  106. ruleName,
  107. message: messages.expected(minimum),
  108. index: declarationValueIndex(decl) + offset,
  109. node: decl,
  110. });
  111. }
  112. };
  113. }
  114. rule.ruleName = ruleName;
  115. rule.messages = messages;
  116. module.exports = rule;