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.
 
 
 
 

98 line
2.5 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7. /**
  8. * Sheets registry to access them all at one place.
  9. */
  10. var SheetsRegistry = function () {
  11. function SheetsRegistry() {
  12. _classCallCheck(this, SheetsRegistry);
  13. this.registry = [];
  14. }
  15. _createClass(SheetsRegistry, [{
  16. key: 'add',
  17. /**
  18. * Register a Style Sheet.
  19. */
  20. value: function add(sheet) {
  21. var registry = this.registry;
  22. var index = sheet.options.index;
  23. if (registry.indexOf(sheet) !== -1) return;
  24. if (registry.length === 0 || index >= this.index) {
  25. registry.push(sheet);
  26. return;
  27. }
  28. // Find a position.
  29. for (var i = 0; i < registry.length; i++) {
  30. if (registry[i].options.index > index) {
  31. registry.splice(i, 0, sheet);
  32. return;
  33. }
  34. }
  35. }
  36. /**
  37. * Reset the registry.
  38. */
  39. }, {
  40. key: 'reset',
  41. value: function reset() {
  42. this.registry = [];
  43. }
  44. /**
  45. * Remove a Style Sheet.
  46. */
  47. }, {
  48. key: 'remove',
  49. value: function remove(sheet) {
  50. var index = this.registry.indexOf(sheet);
  51. this.registry.splice(index, 1);
  52. }
  53. /**
  54. * Convert all attached sheets to a CSS string.
  55. */
  56. }, {
  57. key: 'toString',
  58. value: function toString(options) {
  59. return this.registry.filter(function (sheet) {
  60. return sheet.attached;
  61. }).map(function (sheet) {
  62. return sheet.toString(options);
  63. }).join('\n');
  64. }
  65. }, {
  66. key: 'index',
  67. /**
  68. * Current highest index number.
  69. */
  70. get: function get() {
  71. return this.registry.length === 0 ? 0 : this.registry[this.registry.length - 1].options.index;
  72. }
  73. }]);
  74. return SheetsRegistry;
  75. }();
  76. exports['default'] = SheetsRegistry;