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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const atRuleParamIndex = require('../../utils/atRuleParamIndex');
  5. const declarationValueIndex = require('../../utils/declarationValueIndex');
  6. const getUnitFromValueNode = require('../../utils/getUnitFromValueNode');
  7. const isMap = require('../../utils/isMap');
  8. const keywordSets = require('../../reference/keywordSets');
  9. const mediaParser = require('postcss-media-query-parser').default;
  10. const optionsMatches = require('../../utils/optionsMatches');
  11. const report = require('../../utils/report');
  12. const ruleMessages = require('../../utils/ruleMessages');
  13. const validateOptions = require('../../utils/validateOptions');
  14. const valueParser = require('postcss-value-parser');
  15. const vendor = require('../../utils/vendor');
  16. const ruleName = 'unit-no-unknown';
  17. const messages = ruleMessages(ruleName, {
  18. rejected: (unit) => `Unexpected unknown unit "${unit}"`,
  19. });
  20. // The map property name (in map cleared from comments and spaces) always
  21. // has index that being divided by 4 gives remainder equals 0
  22. const mapPropertyNameIndexOffset = 4;
  23. function rule(actual, options) {
  24. return (root, result) => {
  25. const validOptions = validateOptions(
  26. result,
  27. ruleName,
  28. { actual },
  29. {
  30. actual: options,
  31. possible: {
  32. ignoreUnits: [_.isString, _.isRegExp],
  33. ignoreFunctions: [_.isString, _.isRegExp],
  34. },
  35. optional: true,
  36. },
  37. );
  38. if (!validOptions) {
  39. return;
  40. }
  41. function check(node, value, getIndex) {
  42. // make sure multiplication operations (*) are divided - not handled
  43. // by postcss-value-parser
  44. value = value.replace(/\*/g, ',');
  45. const parsedValue = valueParser(value);
  46. const ignoredMapProperties = [];
  47. parsedValue.walk((valueNode) => {
  48. // Ignore wrong units within `url` function
  49. // and within functions listed in the `ignoreFunctions` option
  50. if (
  51. valueNode.type === 'function' &&
  52. (valueNode.value.toLowerCase() === 'url' ||
  53. optionsMatches(options, 'ignoreFunctions', valueNode.value))
  54. ) {
  55. return false;
  56. }
  57. if (isMap(valueNode)) {
  58. valueNode.nodes.forEach(({ sourceIndex }, index) => {
  59. if (!(index % mapPropertyNameIndexOffset)) {
  60. ignoredMapProperties.push(sourceIndex);
  61. }
  62. });
  63. }
  64. if (ignoredMapProperties.includes(valueNode.sourceIndex)) {
  65. return;
  66. }
  67. const unit = getUnitFromValueNode(valueNode);
  68. if (!unit) {
  69. return;
  70. }
  71. if (optionsMatches(options, 'ignoreUnits', unit)) {
  72. return;
  73. }
  74. if (keywordSets.units.has(unit.toLowerCase()) && unit.toLowerCase() !== 'x') {
  75. return;
  76. }
  77. if (unit.toLowerCase() === 'x') {
  78. if (
  79. node.type === 'atrule' &&
  80. node.name === 'media' &&
  81. node.params.toLowerCase().includes('resolution')
  82. ) {
  83. let ignoreUnit = false;
  84. mediaParser(node.params).walk((mediaNode, i, mediaNodes) => {
  85. if (
  86. mediaNode.value.toLowerCase().includes('resolution') &&
  87. _.last(mediaNodes).sourceIndex === valueNode.sourceIndex
  88. ) {
  89. ignoreUnit = true;
  90. return false;
  91. }
  92. });
  93. if (ignoreUnit) {
  94. return;
  95. }
  96. }
  97. if (node.type === 'decl') {
  98. if (node.prop.toLowerCase() === 'image-resolution') {
  99. return;
  100. }
  101. if (/^(?:-webkit-)?image-set[\s(]/i.test(value)) {
  102. const imageSet = parsedValue.nodes.find(
  103. (n) => vendor.unprefixed(n.value) === 'image-set',
  104. );
  105. const imageSetValueLastIndex = _.last(imageSet.nodes).sourceIndex;
  106. if (imageSetValueLastIndex >= valueNode.sourceIndex) {
  107. return;
  108. }
  109. }
  110. }
  111. }
  112. report({
  113. index: getIndex(node) + valueNode.sourceIndex,
  114. message: messages.rejected(unit),
  115. node,
  116. result,
  117. ruleName,
  118. });
  119. });
  120. }
  121. root.walkAtRules((atRule) => {
  122. if (!/^media$/i.test(atRule.name) && !atRule.variable) {
  123. return;
  124. }
  125. check(atRule, atRule.params, atRuleParamIndex);
  126. });
  127. root.walkDecls((decl) => check(decl, decl.value, declarationValueIndex));
  128. };
  129. }
  130. rule.ruleName = ruleName;
  131. rule.messages = messages;
  132. module.exports = rule;