@udixio/theme 1.0.0-beta.25 → 1.0.0-beta.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/theme.esm.js CHANGED
@@ -1538,11 +1538,7 @@ var ConfigService = /*#__PURE__*/function () {
1538
1538
  }
1539
1539
  if (plugins) {
1540
1540
  plugins.forEach(function (plugin) {
1541
- if (Array.isArray(plugin)) {
1542
- pluginService.addPlugin(plugin[0], plugin[1]);
1543
- } else {
1544
- pluginService.addPlugin(plugin, {});
1545
- }
1541
+ pluginService.addPlugin(plugin);
1546
1542
  });
1547
1543
  pluginService.loadPlugins(this.appService);
1548
1544
  }
@@ -1579,35 +1575,32 @@ var ConfigModule = {
1579
1575
 
1580
1576
  var PluginService = /*#__PURE__*/function () {
1581
1577
  function PluginService() {
1582
- this.pluginInstances = new Map();
1583
- this.pluginConstructors = new Map();
1578
+ this.plugins = new Map();
1584
1579
  }
1585
1580
  var _proto = PluginService.prototype;
1586
- _proto.addPlugin = function addPlugin(plugin, config) {
1587
- this.pluginConstructors.set(plugin.name, [plugin, config]);
1581
+ _proto.addPlugin = function addPlugin(plugin) {
1582
+ this.plugins.set(plugin.name, plugin);
1588
1583
  };
1589
1584
  _proto.loadPlugins = function loadPlugins(appService) {
1590
1585
  var _this = this;
1591
- var plugins = new Map(this.pluginConstructors);
1586
+ var plugins = new Map(this.plugins);
1592
1587
  var size = 0;
1593
1588
  do {
1594
1589
  size = plugins.size;
1595
- plugins.forEach(function (_ref, key) {
1596
- var plugin = _ref[0],
1597
- option = _ref[1];
1590
+ plugins.forEach(function (plugin, key) {
1598
1591
  var deps = plugin.dependencies.filter(function (dep) {
1599
- return !_this.pluginInstances.has(dep.name);
1592
+ return !_this.plugins.has(new dep().name);
1600
1593
  });
1601
1594
  if (deps.length === 0) {
1602
- _this.pluginInstances.set(plugin.name, new plugin(appService, option));
1595
+ _this.plugins.set(plugin.name, plugin.init(appService));
1603
1596
  plugins["delete"](key);
1604
1597
  }
1605
1598
  });
1606
1599
  } while (plugins.size != 0 && plugins.size < size);
1607
- if (plugins.size > 0) console.log("Some plugins couldn't be loaded due to missing dependencies: ", Array.from(plugins.keys()));
1600
+ if (plugins.size > 0) throw new Error("Some plugins couldn't be loaded due to missing dependencies: " + Array.from(plugins.keys()));
1608
1601
  };
1609
1602
  _proto.getPlugin = function getPlugin(plugin) {
1610
- var pluginInstance = this.pluginInstances.get(plugin.name);
1603
+ var pluginInstance = this.plugins.get(new plugin().name);
1611
1604
  if (!pluginInstance) throw new Error("Plugin " + plugin.name + " not found");
1612
1605
  return pluginInstance;
1613
1606
  };
@@ -1643,8 +1636,32 @@ function bootstrapFromConfig(args) {
1643
1636
  return AppContainer.resolve('appService');
1644
1637
  }
1645
1638
 
1646
- var PluginAbstract = function PluginAbstract() {};
1647
- PluginAbstract.dependencies = [];
1639
+ var PluginAbstract = /*#__PURE__*/function () {
1640
+ function PluginAbstract(options) {
1641
+ this.options = void 0;
1642
+ this.pluginInstance = void 0;
1643
+ this.options = options;
1644
+ }
1645
+ var _proto = PluginAbstract.prototype;
1646
+ _proto.init = function init(appService) {
1647
+ this.pluginInstance = new this.pluginClass(appService, this.options);
1648
+ return this;
1649
+ };
1650
+ _proto.getInstance = function getInstance() {
1651
+ if (!this.pluginInstance) {
1652
+ throw new Error("Plugin " + this.name + " is not initialized");
1653
+ }
1654
+ return this.pluginInstance;
1655
+ };
1656
+ return PluginAbstract;
1657
+ }();
1658
+ var PluginImplAbstract = function PluginImplAbstract(appService, options) {
1659
+ this.appService = void 0;
1660
+ this.options = void 0;
1661
+ this.appService = appService;
1662
+ this.options = options;
1663
+ this.onInit();
1664
+ };
1648
1665
 
1649
1666
  var FontFamily;
1650
1667
  (function (FontFamily) {
@@ -1652,21 +1669,50 @@ var FontFamily;
1652
1669
  FontFamily["Neutral"] = "neutral";
1653
1670
  })(FontFamily || (FontFamily = {}));
1654
1671
  var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1655
- function FontPlugin(appService, options) {
1656
- var _options$fontFamily$e, _options$fontFamily, _options$fontFamily$n, _options$fontFamily2;
1672
+ function FontPlugin() {
1657
1673
  var _this;
1658
- _this = _PluginAbstract.call(this) || this;
1659
- _this.appService = void 0;
1660
- _this.options = void 0;
1661
- _this.fontFamily = void 0;
1662
- _this.fontStyles = void 0;
1663
- _this.appService = appService;
1664
- _this.options = options;
1665
- _this.fontFamily = {
1666
- expressive: (_options$fontFamily$e = options == null || (_options$fontFamily = options.fontFamily) == null ? void 0 : _options$fontFamily.expressive) != null ? _options$fontFamily$e : ['Roboto', 'sans-serif'],
1667
- neutral: (_options$fontFamily$n = options == null || (_options$fontFamily2 = options.fontFamily) == null ? void 0 : _options$fontFamily2.neutral) != null ? _options$fontFamily$n : ['Roboto', 'sans-serif']
1674
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1675
+ args[_key] = arguments[_key];
1676
+ }
1677
+ _this = _PluginAbstract.call.apply(_PluginAbstract, [this].concat(args)) || this;
1678
+ _this.dependencies = [];
1679
+ _this.name = 'font';
1680
+ _this.pluginClass = FontPluginImpl;
1681
+ return _this;
1682
+ }
1683
+ _inheritsLoose(FontPlugin, _PluginAbstract);
1684
+ return FontPlugin;
1685
+ }(PluginAbstract);
1686
+ var FontPluginImpl = /*#__PURE__*/function (_PluginImplAbstract) {
1687
+ function FontPluginImpl() {
1688
+ var _this2;
1689
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1690
+ args[_key2] = arguments[_key2];
1691
+ }
1692
+ _this2 = _PluginImplAbstract.call.apply(_PluginImplAbstract, [this].concat(args)) || this;
1693
+ _this2._fontFamily = void 0;
1694
+ _this2._fontStyles = void 0;
1695
+ return _this2;
1696
+ }
1697
+ _inheritsLoose(FontPluginImpl, _PluginImplAbstract);
1698
+ var _proto = FontPluginImpl.prototype;
1699
+ _proto.getFonts = function getFonts() {
1700
+ return {
1701
+ fontStyles: this.fontStyles,
1702
+ fontFamily: this.fontFamily
1703
+ };
1704
+ };
1705
+ _proto.onInit = function onInit() {
1706
+ var _this$options$fontFam,
1707
+ _this$options,
1708
+ _this$options$fontFam2,
1709
+ _this$options2,
1710
+ _this3 = this;
1711
+ this.fontFamily = {
1712
+ expressive: (_this$options$fontFam = (_this$options = this.options) == null || (_this$options = _this$options.fontFamily) == null ? void 0 : _this$options.expressive) != null ? _this$options$fontFam : ['Roboto', 'sans-serif'],
1713
+ neutral: (_this$options$fontFam2 = (_this$options2 = this.options) == null || (_this$options2 = _this$options2.fontFamily) == null ? void 0 : _this$options2.neutral) != null ? _this$options$fontFam2 : ['Roboto', 'sans-serif']
1668
1714
  };
1669
- _this.fontStyles = {
1715
+ this.fontStyles = {
1670
1716
  display: {
1671
1717
  large: {
1672
1718
  fontWeight: 400,
@@ -1777,7 +1823,7 @@ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1777
1823
  }
1778
1824
  }
1779
1825
  };
1780
- if (options && options.fontStyles) Object.entries(options.fontStyles).forEach(function (_ref) {
1826
+ if (this.options && this.options.fontStyles) Object.entries(this.options.fontStyles).forEach(function (_ref) {
1781
1827
  var key = _ref[0],
1782
1828
  fontParam = _ref[1];
1783
1829
  var fontRole = key;
@@ -1786,25 +1832,31 @@ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1786
1832
  fontStyle = _ref2[1];
1787
1833
  var fontSize = size;
1788
1834
  if (fontStyle) {
1789
- _this.fontStyles[fontRole][fontSize] = _extends({}, _this.fontStyles[fontRole][fontSize], fontStyle);
1835
+ _this3.fontStyles[fontRole][fontSize] = _extends({}, _this3.fontStyles[fontRole][fontSize], fontStyle);
1790
1836
  }
1791
1837
  });
1792
1838
  });
1793
- return _this;
1794
- }
1795
- _inheritsLoose(FontPlugin, _PluginAbstract);
1796
- FontPlugin.config = function config(options) {
1797
- return options;
1798
1839
  };
1799
- var _proto = FontPlugin.prototype;
1800
- _proto.getFonts = function getFonts() {
1801
- return {
1802
- fontStyles: this.fontStyles,
1803
- fontFamily: this.fontFamily
1804
- };
1805
- };
1806
- return FontPlugin;
1807
- }(PluginAbstract);
1840
+ return _createClass(FontPluginImpl, [{
1841
+ key: "fontFamily",
1842
+ get: function get() {
1843
+ if (!this._fontFamily) throw new Error('Font family not initialized');
1844
+ return this._fontFamily;
1845
+ },
1846
+ set: function set(value) {
1847
+ this._fontFamily = value;
1848
+ }
1849
+ }, {
1850
+ key: "fontStyles",
1851
+ get: function get() {
1852
+ if (!this._fontStyles) throw new Error('Font styles not initialized');
1853
+ return this._fontStyles;
1854
+ },
1855
+ set: function set(value) {
1856
+ this._fontStyles = value;
1857
+ }
1858
+ }]);
1859
+ }(PluginImplAbstract);
1808
1860
 
1809
1861
  var state = function state(colorkeys) {
1810
1862
  return plugin(function (pluginArgs) {
@@ -1990,25 +2042,33 @@ var font = function font(fontStyles, responsiveBreakPoints) {
1990
2042
  };
1991
2043
 
1992
2044
  var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1993
- function TailwindPlugin(appService, options) {
1994
- var _options$darkMode, _options$responsiveBr;
2045
+ function TailwindPlugin() {
1995
2046
  var _this;
1996
- (_options$darkMode = options.darkMode) != null ? _options$darkMode : options.darkMode = 'class';
1997
- (_options$responsiveBr = options.responsiveBreakPoints) != null ? _options$responsiveBr : options.responsiveBreakPoints = {
1998
- lg: 1.125
1999
- };
2000
- _this = _PluginAbstract.call(this) || this;
2001
- _this.appService = void 0;
2002
- _this.options = void 0;
2003
- _this.appService = appService;
2004
- _this.options = options;
2047
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2048
+ args[_key] = arguments[_key];
2049
+ }
2050
+ _this = _PluginAbstract.call.apply(_PluginAbstract, [this].concat(args)) || this;
2051
+ _this.dependencies = [FontPlugin];
2052
+ _this.name = 'tailwind';
2053
+ _this.pluginClass = TailwindImplPlugin;
2005
2054
  return _this;
2006
2055
  }
2007
2056
  _inheritsLoose(TailwindPlugin, _PluginAbstract);
2008
- TailwindPlugin.config = function config(options) {
2009
- return options;
2057
+ return TailwindPlugin;
2058
+ }(PluginAbstract);
2059
+ var TailwindImplPlugin = /*#__PURE__*/function (_PluginImplAbstract) {
2060
+ function TailwindImplPlugin() {
2061
+ return _PluginImplAbstract.apply(this, arguments) || this;
2062
+ }
2063
+ _inheritsLoose(TailwindImplPlugin, _PluginImplAbstract);
2064
+ var _proto = TailwindImplPlugin.prototype;
2065
+ _proto.onInit = function onInit() {
2066
+ var _this$options, _this$options$darkMod, _this$options2, _this$options2$respon;
2067
+ (_this$options$darkMod = (_this$options = this.options).darkMode) != null ? _this$options$darkMod : _this$options.darkMode = 'class';
2068
+ (_this$options2$respon = (_this$options2 = this.options).responsiveBreakPoints) != null ? _this$options2$respon : _this$options2.responsiveBreakPoints = {
2069
+ lg: 1.125
2070
+ };
2010
2071
  };
2011
- var _proto = TailwindPlugin.prototype;
2012
2072
  _proto.getTheme = function getTheme() {
2013
2073
  var colors = {};
2014
2074
  for (var _i = 0, _arr = [false, true]; _i < _arr.length; _i++) {
@@ -2029,7 +2089,7 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
2029
2089
  colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
2030
2090
  }
2031
2091
  }
2032
- var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getFonts(),
2092
+ var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getInstance().getFonts(),
2033
2093
  fontStyles = _this$appService$plug.fontStyles,
2034
2094
  fontFamily = _this$appService$plug.fontFamily;
2035
2095
  return {
@@ -2043,20 +2103,16 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
2043
2103
  })]
2044
2104
  };
2045
2105
  };
2046
- return TailwindPlugin;
2047
- }(PluginAbstract);
2048
- TailwindPlugin.dependencies = [FontPlugin];
2106
+ return TailwindImplPlugin;
2107
+ }(PluginImplAbstract);
2049
2108
 
2050
2109
  var createTheme = function createTheme() {
2051
2110
  var app = bootstrapFromConfig();
2052
- var plugin = app.pluginService.getPlugin(TailwindPlugin);
2053
- if (!plugin) {
2054
- throw new Error('Tailwind plugin not found');
2055
- }
2111
+ var plugin = app.pluginService.getPlugin(TailwindPlugin).getInstance();
2056
2112
  return _extends({}, plugin.getTheme(), {
2057
2113
  appService: app
2058
2114
  });
2059
2115
  };
2060
2116
 
2061
- export { AppContainer, AppModule, AppService, ColorEntity, ColorManagerService, ColorModule, ColorService, ConfigModule, ConfigService, ContrastCurve, DynamicColor, FontFamily, FontPlugin, PluginAbstract, PluginModule, PluginService, SchemeEntity, SchemeService, TailwindPlugin, ThemeModule, ThemeService, ToneDeltaPair, VariantEntity, VariantModel, VariantService, bootstrap, bootstrapFromConfig, createTheme, defaultColors, defineConfig, getRotatedHue, highestSurface, importContainer, state, themer };
2117
+ export { AppContainer, AppModule, AppService, ColorEntity, ColorManagerService, ColorModule, ColorService, ConfigModule, ConfigService, ContrastCurve, DynamicColor, FontFamily, FontPlugin, PluginAbstract, PluginImplAbstract, PluginModule, PluginService, SchemeEntity, SchemeService, TailwindPlugin, ThemeModule, ThemeService, ToneDeltaPair, VariantEntity, VariantModel, VariantService, bootstrap, bootstrapFromConfig, createTheme, defaultColors, defineConfig, getRotatedHue, highestSurface, importContainer, state, themer };
2062
2118
  //# sourceMappingURL=theme.esm.js.map