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

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,33 @@ 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
+ this.pluginInstance.onInit();
1649
+ return this;
1650
+ };
1651
+ _proto.getInstance = function getInstance() {
1652
+ if (!this.pluginInstance) {
1653
+ throw new Error("Plugin " + this.name + " is not initialized");
1654
+ }
1655
+ return this.pluginInstance;
1656
+ };
1657
+ return PluginAbstract;
1658
+ }();
1659
+ var PluginImplAbstract = function PluginImplAbstract(appService, options) {
1660
+ this.appService = void 0;
1661
+ this.options = void 0;
1662
+ this.appService = appService;
1663
+ this.options = options;
1664
+ this.onInit();
1665
+ };
1648
1666
 
1649
1667
  var FontFamily;
1650
1668
  (function (FontFamily) {
@@ -1652,21 +1670,50 @@ var FontFamily;
1652
1670
  FontFamily["Neutral"] = "neutral";
1653
1671
  })(FontFamily || (FontFamily = {}));
1654
1672
  var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1655
- function FontPlugin(appService, options) {
1656
- var _options$fontFamily$e, _options$fontFamily, _options$fontFamily$n, _options$fontFamily2;
1673
+ function FontPlugin() {
1657
1674
  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']
1675
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1676
+ args[_key] = arguments[_key];
1677
+ }
1678
+ _this = _PluginAbstract.call.apply(_PluginAbstract, [this].concat(args)) || this;
1679
+ _this.dependencies = [];
1680
+ _this.name = 'font';
1681
+ _this.pluginClass = FontPluginImpl;
1682
+ return _this;
1683
+ }
1684
+ _inheritsLoose(FontPlugin, _PluginAbstract);
1685
+ return FontPlugin;
1686
+ }(PluginAbstract);
1687
+ var FontPluginImpl = /*#__PURE__*/function (_PluginImplAbstract) {
1688
+ function FontPluginImpl() {
1689
+ var _this2;
1690
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1691
+ args[_key2] = arguments[_key2];
1692
+ }
1693
+ _this2 = _PluginImplAbstract.call.apply(_PluginImplAbstract, [this].concat(args)) || this;
1694
+ _this2._fontFamily = void 0;
1695
+ _this2._fontStyles = void 0;
1696
+ return _this2;
1697
+ }
1698
+ _inheritsLoose(FontPluginImpl, _PluginImplAbstract);
1699
+ var _proto = FontPluginImpl.prototype;
1700
+ _proto.getFonts = function getFonts() {
1701
+ return {
1702
+ fontStyles: this.fontStyles,
1703
+ fontFamily: this.fontFamily
1704
+ };
1705
+ };
1706
+ _proto.onInit = function onInit() {
1707
+ var _this$options$fontFam,
1708
+ _this$options,
1709
+ _this$options$fontFam2,
1710
+ _this$options2,
1711
+ _this3 = this;
1712
+ this.fontFamily = {
1713
+ 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'],
1714
+ 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
1715
  };
1669
- _this.fontStyles = {
1716
+ this.fontStyles = {
1670
1717
  display: {
1671
1718
  large: {
1672
1719
  fontWeight: 400,
@@ -1777,7 +1824,7 @@ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1777
1824
  }
1778
1825
  }
1779
1826
  };
1780
- if (options && options.fontStyles) Object.entries(options.fontStyles).forEach(function (_ref) {
1827
+ if (this.options && this.options.fontStyles) Object.entries(this.options.fontStyles).forEach(function (_ref) {
1781
1828
  var key = _ref[0],
1782
1829
  fontParam = _ref[1];
1783
1830
  var fontRole = key;
@@ -1786,25 +1833,31 @@ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1786
1833
  fontStyle = _ref2[1];
1787
1834
  var fontSize = size;
1788
1835
  if (fontStyle) {
1789
- _this.fontStyles[fontRole][fontSize] = _extends({}, _this.fontStyles[fontRole][fontSize], fontStyle);
1836
+ _this3.fontStyles[fontRole][fontSize] = _extends({}, _this3.fontStyles[fontRole][fontSize], fontStyle);
1790
1837
  }
1791
1838
  });
1792
1839
  });
1793
- return _this;
1794
- }
1795
- _inheritsLoose(FontPlugin, _PluginAbstract);
1796
- FontPlugin.config = function config(options) {
1797
- return options;
1798
1840
  };
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);
1841
+ return _createClass(FontPluginImpl, [{
1842
+ key: "fontFamily",
1843
+ get: function get() {
1844
+ if (!this._fontFamily) throw new Error('Font family not initialized');
1845
+ return this._fontFamily;
1846
+ },
1847
+ set: function set(value) {
1848
+ this._fontFamily = value;
1849
+ }
1850
+ }, {
1851
+ key: "fontStyles",
1852
+ get: function get() {
1853
+ if (!this._fontStyles) throw new Error('Font styles not initialized');
1854
+ return this._fontStyles;
1855
+ },
1856
+ set: function set(value) {
1857
+ this._fontStyles = value;
1858
+ }
1859
+ }]);
1860
+ }(PluginImplAbstract);
1808
1861
 
1809
1862
  var state = function state(colorkeys) {
1810
1863
  return plugin(function (pluginArgs) {
@@ -1990,25 +2043,33 @@ var font = function font(fontStyles, responsiveBreakPoints) {
1990
2043
  };
1991
2044
 
1992
2045
  var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1993
- function TailwindPlugin(appService, options) {
1994
- var _options$darkMode, _options$responsiveBr;
2046
+ function TailwindPlugin() {
1995
2047
  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;
2048
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2049
+ args[_key] = arguments[_key];
2050
+ }
2051
+ _this = _PluginAbstract.call.apply(_PluginAbstract, [this].concat(args)) || this;
2052
+ _this.dependencies = [FontPlugin];
2053
+ _this.name = 'tailwind';
2054
+ _this.pluginClass = TailwindImplPlugin;
2005
2055
  return _this;
2006
2056
  }
2007
2057
  _inheritsLoose(TailwindPlugin, _PluginAbstract);
2008
- TailwindPlugin.config = function config(options) {
2009
- return options;
2058
+ return TailwindPlugin;
2059
+ }(PluginAbstract);
2060
+ var TailwindImplPlugin = /*#__PURE__*/function (_PluginImplAbstract) {
2061
+ function TailwindImplPlugin() {
2062
+ return _PluginImplAbstract.apply(this, arguments) || this;
2063
+ }
2064
+ _inheritsLoose(TailwindImplPlugin, _PluginImplAbstract);
2065
+ var _proto = TailwindImplPlugin.prototype;
2066
+ _proto.onInit = function onInit() {
2067
+ var _this$options, _this$options$darkMod, _this$options2, _this$options2$respon;
2068
+ (_this$options$darkMod = (_this$options = this.options).darkMode) != null ? _this$options$darkMod : _this$options.darkMode = 'class';
2069
+ (_this$options2$respon = (_this$options2 = this.options).responsiveBreakPoints) != null ? _this$options2$respon : _this$options2.responsiveBreakPoints = {
2070
+ lg: 1.125
2071
+ };
2010
2072
  };
2011
- var _proto = TailwindPlugin.prototype;
2012
2073
  _proto.getTheme = function getTheme() {
2013
2074
  var colors = {};
2014
2075
  for (var _i = 0, _arr = [false, true]; _i < _arr.length; _i++) {
@@ -2029,7 +2090,7 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
2029
2090
  colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
2030
2091
  }
2031
2092
  }
2032
- var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getFonts(),
2093
+ var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getInstance().getFonts(),
2033
2094
  fontStyles = _this$appService$plug.fontStyles,
2034
2095
  fontFamily = _this$appService$plug.fontFamily;
2035
2096
  return {
@@ -2043,20 +2104,16 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
2043
2104
  })]
2044
2105
  };
2045
2106
  };
2046
- return TailwindPlugin;
2047
- }(PluginAbstract);
2048
- TailwindPlugin.dependencies = [FontPlugin];
2107
+ return TailwindImplPlugin;
2108
+ }(PluginImplAbstract);
2049
2109
 
2050
2110
  var createTheme = function createTheme() {
2051
2111
  var app = bootstrapFromConfig();
2052
- var plugin = app.pluginService.getPlugin(TailwindPlugin);
2053
- if (!plugin) {
2054
- throw new Error('Tailwind plugin not found');
2055
- }
2112
+ var plugin = app.pluginService.getPlugin(TailwindPlugin).getInstance();
2056
2113
  return _extends({}, plugin.getTheme(), {
2057
2114
  appService: app
2058
2115
  });
2059
2116
  };
2060
2117
 
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 };
2118
+ 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
2119
  //# sourceMappingURL=theme.esm.js.map