@udixio/theme 1.0.0-beta.16 → 1.0.0-beta.18

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
@@ -1588,11 +1588,23 @@ var PluginService = /*#__PURE__*/function () {
1588
1588
  };
1589
1589
  _proto.loadPlugins = function loadPlugins(appService) {
1590
1590
  var _this = this;
1591
- this.pluginConstructors.forEach(function (_ref) {
1592
- var plugin = _ref[0],
1593
- option = _ref[1];
1594
- _this.pluginInstances.set(plugin.name, new plugin(appService, option));
1595
- });
1591
+ var plugins = new Map(this.pluginConstructors);
1592
+ var size = 0;
1593
+ do {
1594
+ size = plugins.size;
1595
+ plugins.forEach(function (_ref, key) {
1596
+ var plugin = _ref[0],
1597
+ option = _ref[1];
1598
+ var deps = plugin.dependencies.filter(function (dep) {
1599
+ return !_this.pluginInstances.has(dep.name);
1600
+ });
1601
+ if (deps.length === 0) {
1602
+ _this.pluginInstances.set(plugin.name, new plugin(appService, option));
1603
+ plugins["delete"](key);
1604
+ }
1605
+ });
1606
+ } 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()));
1596
1608
  };
1597
1609
  _proto.getPlugin = function getPlugin(plugin) {
1598
1610
  var pluginInstance = this.pluginInstances.get(plugin.name);
@@ -1632,7 +1644,167 @@ function bootstrapFromConfig(path) {
1632
1644
  }
1633
1645
 
1634
1646
  var PluginAbstract = function PluginAbstract() {};
1635
- PluginAbstract.dependencies = void 0;
1647
+ PluginAbstract.dependencies = [];
1648
+
1649
+ var FontFamily;
1650
+ (function (FontFamily) {
1651
+ FontFamily["Expressive"] = "expressive";
1652
+ FontFamily["Neutral"] = "neutral";
1653
+ })(FontFamily || (FontFamily = {}));
1654
+ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1655
+ function FontPlugin(appService, options) {
1656
+ var _options$fontFamily$e, _options$fontFamily, _options$fontFamily$n, _options$fontFamily2;
1657
+ 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']
1668
+ };
1669
+ _this.fontStyles = {
1670
+ display: {
1671
+ large: {
1672
+ fontWeight: 400,
1673
+ fontSize: 3.5625,
1674
+ lineHeight: 4,
1675
+ letterSpacing: -0.015625,
1676
+ fontFamily: FontFamily.Expressive
1677
+ },
1678
+ medium: {
1679
+ fontWeight: 400,
1680
+ fontSize: 2.8125,
1681
+ lineHeight: 3.25,
1682
+ fontFamily: FontFamily.Expressive
1683
+ },
1684
+ small: {
1685
+ fontWeight: 400,
1686
+ fontSize: 2.25,
1687
+ lineHeight: 2.75,
1688
+ fontFamily: FontFamily.Expressive
1689
+ }
1690
+ },
1691
+ headline: {
1692
+ large: {
1693
+ fontWeight: 400,
1694
+ fontSize: 2,
1695
+ lineHeight: 2.5,
1696
+ fontFamily: FontFamily.Expressive
1697
+ },
1698
+ medium: {
1699
+ fontWeight: 400,
1700
+ fontSize: 1.75,
1701
+ lineHeight: 2.25,
1702
+ fontFamily: FontFamily.Expressive
1703
+ },
1704
+ small: {
1705
+ fontWeight: 400,
1706
+ fontSize: 1.5,
1707
+ lineHeight: 2,
1708
+ fontFamily: FontFamily.Expressive
1709
+ }
1710
+ },
1711
+ title: {
1712
+ large: {
1713
+ fontWeight: 400,
1714
+ fontSize: 1.375,
1715
+ lineHeight: 1.75,
1716
+ fontFamily: FontFamily.Neutral
1717
+ },
1718
+ medium: {
1719
+ fontWeight: 500,
1720
+ fontSize: 1,
1721
+ lineHeight: 1.5,
1722
+ fontFamily: FontFamily.Neutral,
1723
+ letterSpacing: 0.009375
1724
+ },
1725
+ small: {
1726
+ fontWeight: 500,
1727
+ fontSize: 0.875,
1728
+ lineHeight: 1.25,
1729
+ fontFamily: FontFamily.Neutral,
1730
+ letterSpacing: 0.00625
1731
+ }
1732
+ },
1733
+ label: {
1734
+ large: {
1735
+ fontWeight: 500,
1736
+ fontSize: 0.875,
1737
+ lineHeight: 1.25,
1738
+ fontFamily: FontFamily.Neutral,
1739
+ letterSpacing: 0.00625
1740
+ },
1741
+ medium: {
1742
+ fontWeight: 500,
1743
+ fontSize: 0.75,
1744
+ lineHeight: 1,
1745
+ fontFamily: FontFamily.Neutral,
1746
+ letterSpacing: 0.03125
1747
+ },
1748
+ small: {
1749
+ fontWeight: 500,
1750
+ fontSize: 0.6875,
1751
+ lineHeight: 1,
1752
+ fontFamily: FontFamily.Neutral,
1753
+ letterSpacing: 0.03125
1754
+ }
1755
+ },
1756
+ body: {
1757
+ large: {
1758
+ fontWeight: 400,
1759
+ fontSize: 1,
1760
+ lineHeight: 1.5625,
1761
+ fontFamily: FontFamily.Neutral,
1762
+ letterSpacing: 0.03125
1763
+ },
1764
+ medium: {
1765
+ fontWeight: 400,
1766
+ fontSize: 0.875,
1767
+ lineHeight: 1.25,
1768
+ fontFamily: FontFamily.Neutral,
1769
+ letterSpacing: 0.015625
1770
+ },
1771
+ small: {
1772
+ fontWeight: 400,
1773
+ fontSize: 0.75,
1774
+ lineHeight: 1,
1775
+ fontFamily: FontFamily.Neutral,
1776
+ letterSpacing: 0.025
1777
+ }
1778
+ }
1779
+ };
1780
+ if (options && options.fontStyles) Object.entries(options.fontStyles).forEach(function (_ref) {
1781
+ var key = _ref[0],
1782
+ fontParam = _ref[1];
1783
+ var fontRole = key;
1784
+ Object.entries(fontParam).forEach(function (_ref2) {
1785
+ var size = _ref2[0],
1786
+ fontStyle = _ref2[1];
1787
+ var fontSize = size;
1788
+ if (fontStyle) {
1789
+ _this.fontStyles[fontRole][fontSize] = _extends({}, _this.fontStyles[fontRole][fontSize], fontStyle);
1790
+ }
1791
+ });
1792
+ });
1793
+ return _this;
1794
+ }
1795
+ _inheritsLoose(FontPlugin, _PluginAbstract);
1796
+ FontPlugin.config = function config(options) {
1797
+ return options;
1798
+ };
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);
1636
1808
 
1637
1809
  var state = function state(colorkeys) {
1638
1810
  return plugin(function (pluginArgs) {
@@ -1718,6 +1890,58 @@ var themer = function themer(colors, darkMode) {
1718
1890
  return require('tailwindcss-themer')(options);
1719
1891
  };
1720
1892
 
1893
+ var font = function font(fontStyles, responsiveBreakPoints) {
1894
+ var createUtilities = function createUtilities(_ref) {
1895
+ var theme = _ref.theme;
1896
+ var pixelUnit = 'rem';
1897
+ var newUtilities = {};
1898
+ var baseTextStyle = function baseTextStyle(sizeValue) {
1899
+ return {
1900
+ fontSize: sizeValue.fontSize + pixelUnit,
1901
+ fontWeight: sizeValue.fontWeight,
1902
+ lineHeight: sizeValue.lineHeight + pixelUnit,
1903
+ letterSpacing: sizeValue.letterSpacing ? sizeValue.letterSpacing + pixelUnit : null,
1904
+ fontFamily: theme('fontFamily.' + sizeValue.fontFamily)
1905
+ };
1906
+ };
1907
+ var responsiveTextStyle = function responsiveTextStyle(sizeValue, breakPointName, breakPointRatio) {
1908
+ var _ref2;
1909
+ return _ref2 = {}, _ref2["@media (min-width: " + theme('screens.' + breakPointName, {}) + ")"] = {
1910
+ fontSize: sizeValue.fontSize * breakPointRatio + pixelUnit,
1911
+ lineHeight: sizeValue.lineHeight * breakPointRatio + pixelUnit
1912
+ }, _ref2;
1913
+ };
1914
+ for (var _i = 0, _Object$entries = Object.entries(fontStyles); _i < _Object$entries.length; _i++) {
1915
+ var _Object$entries$_i = _Object$entries[_i],
1916
+ roleName = _Object$entries$_i[0],
1917
+ roleValue = _Object$entries$_i[1];
1918
+ var _loop = function _loop() {
1919
+ var _Object$entries2$_i = _Object$entries2[_i2],
1920
+ sizeName = _Object$entries2$_i[0],
1921
+ sizeValue = _Object$entries2$_i[1];
1922
+ newUtilities['.text-' + roleName + '-' + sizeName] = _extends({}, baseTextStyle(sizeValue), Object.entries(responsiveBreakPoints).reduce(function (acc, _ref3) {
1923
+ var breakPointName = _ref3[0],
1924
+ breakPointRatio = _ref3[1];
1925
+ acc = _extends({}, acc, responsiveTextStyle(sizeValue, breakPointName, breakPointRatio));
1926
+ return acc;
1927
+ }, {}));
1928
+ };
1929
+ for (var _i2 = 0, _Object$entries2 = Object.entries(roleValue); _i2 < _Object$entries2.length; _i2++) {
1930
+ _loop();
1931
+ }
1932
+ }
1933
+ return newUtilities;
1934
+ };
1935
+ return plugin(function (_ref4) {
1936
+ var addUtilities = _ref4.addUtilities,
1937
+ theme = _ref4.theme;
1938
+ var newUtilities = createUtilities({
1939
+ theme: theme
1940
+ });
1941
+ addUtilities(newUtilities);
1942
+ });
1943
+ };
1944
+
1721
1945
  var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1722
1946
  function TailwindPlugin(appService, options) {
1723
1947
  var _this;
@@ -1753,18 +1977,18 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1753
1977
  colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
1754
1978
  }
1755
1979
  }
1756
- console.log(colors);
1980
+ var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getFonts(),
1981
+ fontStyles = _this$appService$plug.fontStyles,
1982
+ fontFamily = _this$appService$plug.fontFamily;
1757
1983
  return {
1758
1984
  colors: {},
1759
- fontFamily: {
1760
- expressive: [],
1761
- neutral: []
1762
- },
1763
- plugins: [state(Object.keys(colors)), themer(colors, this.options.darkMode)]
1985
+ fontFamily: fontFamily,
1986
+ plugins: [state(Object.keys(colors)), themer(colors, this.options.darkMode), font(fontStyles, this.options.responsiveBreakPoints)]
1764
1987
  };
1765
1988
  };
1766
1989
  return TailwindPlugin;
1767
1990
  }(PluginAbstract);
1991
+ TailwindPlugin.dependencies = [FontPlugin];
1768
1992
 
1769
1993
  var createTheme = function createTheme() {
1770
1994
  var app = bootstrapFromConfig();
@@ -1775,5 +1999,5 @@ var createTheme = function createTheme() {
1775
1999
  return plugin.getTheme();
1776
2000
  };
1777
2001
 
1778
- export { AppContainer, AppModule, AppService, ColorEntity, ColorManagerService, ColorModule, ColorService, ConfigModule, ConfigService, ContrastCurve, DynamicColor, PluginAbstract, PluginModule, PluginService, SchemeEntity, SchemeService, TailwindPlugin, ThemeModule, ThemeService, ToneDeltaPair, VariantEntity, VariantModel, VariantService, bootstrap, bootstrapFromConfig, createTheme, defaultColors, defineConfig, getRotatedHue, highestSurface, importContainer, state, themer };
2002
+ 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 };
1779
2003
  //# sourceMappingURL=theme.esm.js.map