web 3d图形渲染器
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.

40 lines
953 B

  1. var compactable = require('../compactable');
  2. function findComponentIn(shorthand, longhand) {
  3. var comparator = nameComparator(longhand);
  4. return findInDirectComponents(shorthand, comparator) || findInSubComponents(shorthand, comparator);
  5. }
  6. function nameComparator(to) {
  7. return function (property) {
  8. return to.name === property.name;
  9. };
  10. }
  11. function findInDirectComponents(shorthand, comparator) {
  12. return shorthand.components.filter(comparator)[0];
  13. }
  14. function findInSubComponents(shorthand, comparator) {
  15. var shorthandComponent;
  16. var longhandMatch;
  17. var i, l;
  18. if (!compactable[shorthand.name].shorthandComponents) {
  19. return;
  20. }
  21. for (i = 0, l = shorthand.components.length; i < l; i++) {
  22. shorthandComponent = shorthand.components[i];
  23. longhandMatch = findInDirectComponents(shorthandComponent, comparator);
  24. if (longhandMatch) {
  25. return longhandMatch;
  26. }
  27. }
  28. return;
  29. }
  30. module.exports = findComponentIn;