@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/index.d.ts CHANGED
@@ -7,5 +7,6 @@ export * from './config';
7
7
  export * from './main';
8
8
  export * from './material-color-utilities';
9
9
  export * from './plugin';
10
+ export * from './plugins/font';
10
11
  export * from './plugins/tailwind';
11
12
  export * from './theme';
@@ -1,6 +1,7 @@
1
1
  import { AppService } from '../app.service';
2
+ import { PluginConstructor } from './plugin.service';
2
3
  export declare abstract class PluginAbstract {
3
- static dependencies: (new () => PluginAbstract)[];
4
+ static dependencies: PluginConstructor[];
4
5
  protected abstract appService: AppService;
5
6
  protected abstract options: object;
6
7
  }
@@ -1,6 +1,8 @@
1
1
  import { PluginAbstract } from './plugin.abstract';
2
2
  import { AppService } from '../app.service';
3
- export type PluginConstructor = new (appService: AppService, options: any) => PluginAbstract;
3
+ export type PluginConstructor = (new (appService: AppService, options: any) => PluginAbstract) & {
4
+ dependencies: PluginConstructor[];
5
+ };
4
6
  export declare class PluginService {
5
7
  private pluginInstances;
6
8
  private pluginConstructors;
@@ -0,0 +1,38 @@
1
+ import { PluginAbstract } from '../../plugin';
2
+ import { AppService } from '../../app.service';
3
+ export declare enum FontFamily {
4
+ Expressive = "expressive",
5
+ Neutral = "neutral"
6
+ }
7
+ export type FontStyle = {
8
+ fontSize: number;
9
+ lineHeight: number;
10
+ fontWeight: number;
11
+ letterSpacing?: number;
12
+ fontFamily: FontFamily;
13
+ };
14
+ export type FontRole = 'display' | 'headline' | 'title' | 'label' | 'body';
15
+ export type FontSize = 'large' | 'medium' | 'small';
16
+ interface FontPluginOptions {
17
+ fontFamily?: {
18
+ expressive?: string[];
19
+ neutral?: string[];
20
+ };
21
+ fontStyles?: Partial<Record<FontRole, Record<FontSize, Partial<FontStyle>>>>;
22
+ }
23
+ export declare class FontPlugin extends PluginAbstract {
24
+ protected appService: AppService;
25
+ protected options: FontPluginOptions;
26
+ private readonly fontFamily;
27
+ private readonly fontStyles;
28
+ constructor(appService: AppService, options: FontPluginOptions);
29
+ static config(options: FontPluginOptions): FontPluginOptions;
30
+ getFonts(): {
31
+ fontStyles: Record<FontRole, Record<FontSize, FontStyle>>;
32
+ fontFamily: {
33
+ expressive: string[];
34
+ neutral: string[];
35
+ };
36
+ };
37
+ }
38
+ export {};
@@ -0,0 +1 @@
1
+ export * from './font.plugin';
@@ -1,3 +1,3 @@
1
1
  export * from './main';
2
2
  export * from './plugins-tailwind';
3
- export * from './Tailwind.plugin';
3
+ export * from './tailwind.plugin';
@@ -0,0 +1,5 @@
1
+ import { FontRole, FontSize, FontStyle } from '../../font/font.plugin';
2
+ export declare const font: (fontStyles: Record<FontRole, Record<FontSize, FontStyle>>, responsiveBreakPoints: Record<string, number>) => {
3
+ handler: import("tailwindcss/types/config").PluginCreator;
4
+ config?: Partial<import("tailwindcss/types/config").Config>;
5
+ };
@@ -1,12 +1,15 @@
1
1
  import { PluginAbstract } from '../../plugin/plugin.abstract';
2
2
  import { AppService } from '../../app.service';
3
3
  import { Theme } from './main';
4
+ import { FontPlugin } from '../font/font.plugin';
4
5
  interface TailwindPluginOptions {
5
6
  darkMode: 'class' | 'media';
7
+ responsiveBreakPoints: Record<string, number>;
6
8
  }
7
9
  export declare class TailwindPlugin extends PluginAbstract {
8
10
  protected appService: AppService;
9
11
  protected options: TailwindPluginOptions;
12
+ static dependencies: (typeof FontPlugin)[];
10
13
  constructor(appService: AppService, options: TailwindPluginOptions);
11
14
  static config(options: TailwindPluginOptions): TailwindPluginOptions;
12
15
  getTheme(): Theme;
@@ -1592,11 +1592,23 @@ var PluginService = /*#__PURE__*/function () {
1592
1592
  };
1593
1593
  _proto.loadPlugins = function loadPlugins(appService) {
1594
1594
  var _this = this;
1595
- this.pluginConstructors.forEach(function (_ref) {
1596
- var plugin = _ref[0],
1597
- option = _ref[1];
1598
- _this.pluginInstances.set(plugin.name, new plugin(appService, option));
1599
- });
1595
+ var plugins = new Map(this.pluginConstructors);
1596
+ var size = 0;
1597
+ do {
1598
+ size = plugins.size;
1599
+ plugins.forEach(function (_ref, key) {
1600
+ var plugin = _ref[0],
1601
+ option = _ref[1];
1602
+ var deps = plugin.dependencies.filter(function (dep) {
1603
+ return !_this.pluginInstances.has(dep.name);
1604
+ });
1605
+ if (deps.length === 0) {
1606
+ _this.pluginInstances.set(plugin.name, new plugin(appService, option));
1607
+ plugins["delete"](key);
1608
+ }
1609
+ });
1610
+ } while (plugins.size != 0 && plugins.size < size);
1611
+ if (plugins.size > 0) console.log("Some plugins couldn't be loaded due to missing dependencies: ", Array.from(plugins.keys()));
1600
1612
  };
1601
1613
  _proto.getPlugin = function getPlugin(plugin) {
1602
1614
  var pluginInstance = this.pluginInstances.get(plugin.name);
@@ -1636,7 +1648,167 @@ function bootstrapFromConfig(path) {
1636
1648
  }
1637
1649
 
1638
1650
  var PluginAbstract = function PluginAbstract() {};
1639
- PluginAbstract.dependencies = void 0;
1651
+ PluginAbstract.dependencies = [];
1652
+
1653
+ exports.FontFamily = void 0;
1654
+ (function (FontFamily) {
1655
+ FontFamily["Expressive"] = "expressive";
1656
+ FontFamily["Neutral"] = "neutral";
1657
+ })(exports.FontFamily || (exports.FontFamily = {}));
1658
+ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1659
+ function FontPlugin(appService, options) {
1660
+ var _options$fontFamily$e, _options$fontFamily, _options$fontFamily$n, _options$fontFamily2;
1661
+ var _this;
1662
+ _this = _PluginAbstract.call(this) || this;
1663
+ _this.appService = void 0;
1664
+ _this.options = void 0;
1665
+ _this.fontFamily = void 0;
1666
+ _this.fontStyles = void 0;
1667
+ _this.appService = appService;
1668
+ _this.options = options;
1669
+ _this.fontFamily = {
1670
+ expressive: (_options$fontFamily$e = options == null || (_options$fontFamily = options.fontFamily) == null ? void 0 : _options$fontFamily.expressive) != null ? _options$fontFamily$e : ['Roboto', 'sans-serif'],
1671
+ neutral: (_options$fontFamily$n = options == null || (_options$fontFamily2 = options.fontFamily) == null ? void 0 : _options$fontFamily2.neutral) != null ? _options$fontFamily$n : ['Roboto', 'sans-serif']
1672
+ };
1673
+ _this.fontStyles = {
1674
+ display: {
1675
+ large: {
1676
+ fontWeight: 400,
1677
+ fontSize: 3.5625,
1678
+ lineHeight: 4,
1679
+ letterSpacing: -0.015625,
1680
+ fontFamily: exports.FontFamily.Expressive
1681
+ },
1682
+ medium: {
1683
+ fontWeight: 400,
1684
+ fontSize: 2.8125,
1685
+ lineHeight: 3.25,
1686
+ fontFamily: exports.FontFamily.Expressive
1687
+ },
1688
+ small: {
1689
+ fontWeight: 400,
1690
+ fontSize: 2.25,
1691
+ lineHeight: 2.75,
1692
+ fontFamily: exports.FontFamily.Expressive
1693
+ }
1694
+ },
1695
+ headline: {
1696
+ large: {
1697
+ fontWeight: 400,
1698
+ fontSize: 2,
1699
+ lineHeight: 2.5,
1700
+ fontFamily: exports.FontFamily.Expressive
1701
+ },
1702
+ medium: {
1703
+ fontWeight: 400,
1704
+ fontSize: 1.75,
1705
+ lineHeight: 2.25,
1706
+ fontFamily: exports.FontFamily.Expressive
1707
+ },
1708
+ small: {
1709
+ fontWeight: 400,
1710
+ fontSize: 1.5,
1711
+ lineHeight: 2,
1712
+ fontFamily: exports.FontFamily.Expressive
1713
+ }
1714
+ },
1715
+ title: {
1716
+ large: {
1717
+ fontWeight: 400,
1718
+ fontSize: 1.375,
1719
+ lineHeight: 1.75,
1720
+ fontFamily: exports.FontFamily.Neutral
1721
+ },
1722
+ medium: {
1723
+ fontWeight: 500,
1724
+ fontSize: 1,
1725
+ lineHeight: 1.5,
1726
+ fontFamily: exports.FontFamily.Neutral,
1727
+ letterSpacing: 0.009375
1728
+ },
1729
+ small: {
1730
+ fontWeight: 500,
1731
+ fontSize: 0.875,
1732
+ lineHeight: 1.25,
1733
+ fontFamily: exports.FontFamily.Neutral,
1734
+ letterSpacing: 0.00625
1735
+ }
1736
+ },
1737
+ label: {
1738
+ large: {
1739
+ fontWeight: 500,
1740
+ fontSize: 0.875,
1741
+ lineHeight: 1.25,
1742
+ fontFamily: exports.FontFamily.Neutral,
1743
+ letterSpacing: 0.00625
1744
+ },
1745
+ medium: {
1746
+ fontWeight: 500,
1747
+ fontSize: 0.75,
1748
+ lineHeight: 1,
1749
+ fontFamily: exports.FontFamily.Neutral,
1750
+ letterSpacing: 0.03125
1751
+ },
1752
+ small: {
1753
+ fontWeight: 500,
1754
+ fontSize: 0.6875,
1755
+ lineHeight: 1,
1756
+ fontFamily: exports.FontFamily.Neutral,
1757
+ letterSpacing: 0.03125
1758
+ }
1759
+ },
1760
+ body: {
1761
+ large: {
1762
+ fontWeight: 400,
1763
+ fontSize: 1,
1764
+ lineHeight: 1.5625,
1765
+ fontFamily: exports.FontFamily.Neutral,
1766
+ letterSpacing: 0.03125
1767
+ },
1768
+ medium: {
1769
+ fontWeight: 400,
1770
+ fontSize: 0.875,
1771
+ lineHeight: 1.25,
1772
+ fontFamily: exports.FontFamily.Neutral,
1773
+ letterSpacing: 0.015625
1774
+ },
1775
+ small: {
1776
+ fontWeight: 400,
1777
+ fontSize: 0.75,
1778
+ lineHeight: 1,
1779
+ fontFamily: exports.FontFamily.Neutral,
1780
+ letterSpacing: 0.025
1781
+ }
1782
+ }
1783
+ };
1784
+ if (options && options.fontStyles) Object.entries(options.fontStyles).forEach(function (_ref) {
1785
+ var key = _ref[0],
1786
+ fontParam = _ref[1];
1787
+ var fontRole = key;
1788
+ Object.entries(fontParam).forEach(function (_ref2) {
1789
+ var size = _ref2[0],
1790
+ fontStyle = _ref2[1];
1791
+ var fontSize = size;
1792
+ if (fontStyle) {
1793
+ _this.fontStyles[fontRole][fontSize] = _extends({}, _this.fontStyles[fontRole][fontSize], fontStyle);
1794
+ }
1795
+ });
1796
+ });
1797
+ return _this;
1798
+ }
1799
+ _inheritsLoose(FontPlugin, _PluginAbstract);
1800
+ FontPlugin.config = function config(options) {
1801
+ return options;
1802
+ };
1803
+ var _proto = FontPlugin.prototype;
1804
+ _proto.getFonts = function getFonts() {
1805
+ return {
1806
+ fontStyles: this.fontStyles,
1807
+ fontFamily: this.fontFamily
1808
+ };
1809
+ };
1810
+ return FontPlugin;
1811
+ }(PluginAbstract);
1640
1812
 
1641
1813
  var state = function state(colorkeys) {
1642
1814
  return plugin(function (pluginArgs) {
@@ -1722,6 +1894,58 @@ var themer = function themer(colors, darkMode) {
1722
1894
  return require('tailwindcss-themer')(options);
1723
1895
  };
1724
1896
 
1897
+ var font = function font(fontStyles, responsiveBreakPoints) {
1898
+ var createUtilities = function createUtilities(_ref) {
1899
+ var theme = _ref.theme;
1900
+ var pixelUnit = 'rem';
1901
+ var newUtilities = {};
1902
+ var baseTextStyle = function baseTextStyle(sizeValue) {
1903
+ return {
1904
+ fontSize: sizeValue.fontSize + pixelUnit,
1905
+ fontWeight: sizeValue.fontWeight,
1906
+ lineHeight: sizeValue.lineHeight + pixelUnit,
1907
+ letterSpacing: sizeValue.letterSpacing ? sizeValue.letterSpacing + pixelUnit : null,
1908
+ fontFamily: theme('fontFamily.' + sizeValue.fontFamily)
1909
+ };
1910
+ };
1911
+ var responsiveTextStyle = function responsiveTextStyle(sizeValue, breakPointName, breakPointRatio) {
1912
+ var _ref2;
1913
+ return _ref2 = {}, _ref2["@media (min-width: " + theme('screens.' + breakPointName, {}) + ")"] = {
1914
+ fontSize: sizeValue.fontSize * breakPointRatio + pixelUnit,
1915
+ lineHeight: sizeValue.lineHeight * breakPointRatio + pixelUnit
1916
+ }, _ref2;
1917
+ };
1918
+ for (var _i = 0, _Object$entries = Object.entries(fontStyles); _i < _Object$entries.length; _i++) {
1919
+ var _Object$entries$_i = _Object$entries[_i],
1920
+ roleName = _Object$entries$_i[0],
1921
+ roleValue = _Object$entries$_i[1];
1922
+ var _loop = function _loop() {
1923
+ var _Object$entries2$_i = _Object$entries2[_i2],
1924
+ sizeName = _Object$entries2$_i[0],
1925
+ sizeValue = _Object$entries2$_i[1];
1926
+ newUtilities['.text-' + roleName + '-' + sizeName] = _extends({}, baseTextStyle(sizeValue), Object.entries(responsiveBreakPoints).reduce(function (acc, _ref3) {
1927
+ var breakPointName = _ref3[0],
1928
+ breakPointRatio = _ref3[1];
1929
+ acc = _extends({}, acc, responsiveTextStyle(sizeValue, breakPointName, breakPointRatio));
1930
+ return acc;
1931
+ }, {}));
1932
+ };
1933
+ for (var _i2 = 0, _Object$entries2 = Object.entries(roleValue); _i2 < _Object$entries2.length; _i2++) {
1934
+ _loop();
1935
+ }
1936
+ }
1937
+ return newUtilities;
1938
+ };
1939
+ return plugin(function (_ref4) {
1940
+ var addUtilities = _ref4.addUtilities,
1941
+ theme = _ref4.theme;
1942
+ var newUtilities = createUtilities({
1943
+ theme: theme
1944
+ });
1945
+ addUtilities(newUtilities);
1946
+ });
1947
+ };
1948
+
1725
1949
  var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1726
1950
  function TailwindPlugin(appService, options) {
1727
1951
  var _this;
@@ -1757,18 +1981,18 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1757
1981
  colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
1758
1982
  }
1759
1983
  }
1760
- console.log(colors);
1984
+ var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getFonts(),
1985
+ fontStyles = _this$appService$plug.fontStyles,
1986
+ fontFamily = _this$appService$plug.fontFamily;
1761
1987
  return {
1762
1988
  colors: {},
1763
- fontFamily: {
1764
- expressive: [],
1765
- neutral: []
1766
- },
1767
- plugins: [state(Object.keys(colors)), themer(colors, this.options.darkMode)]
1989
+ fontFamily: fontFamily,
1990
+ plugins: [state(Object.keys(colors)), themer(colors, this.options.darkMode), font(fontStyles, this.options.responsiveBreakPoints)]
1768
1991
  };
1769
1992
  };
1770
1993
  return TailwindPlugin;
1771
1994
  }(PluginAbstract);
1995
+ TailwindPlugin.dependencies = [FontPlugin];
1772
1996
 
1773
1997
  var createTheme = function createTheme() {
1774
1998
  var app = bootstrapFromConfig();
@@ -1790,6 +2014,7 @@ exports.ConfigModule = ConfigModule;
1790
2014
  exports.ConfigService = ConfigService;
1791
2015
  exports.ContrastCurve = ContrastCurve;
1792
2016
  exports.DynamicColor = DynamicColor;
2017
+ exports.FontPlugin = FontPlugin;
1793
2018
  exports.PluginAbstract = PluginAbstract;
1794
2019
  exports.PluginModule = PluginModule;
1795
2020
  exports.PluginService = PluginService;