@udixio/theme 1.0.0-beta.15 → 1.0.0-beta.17

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.
@@ -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 {};
@@ -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;
@@ -1566,7 +1566,12 @@ var ConfigService = /*#__PURE__*/function () {
1566
1566
  if (!configImport) {
1567
1567
  throw new Error('Configuration file not found');
1568
1568
  }
1569
- var config = configImport["default"];
1569
+ var config;
1570
+ if ('default' in configImport) {
1571
+ config = configImport["default"];
1572
+ } else {
1573
+ config = configImport;
1574
+ }
1570
1575
  return config;
1571
1576
  };
1572
1577
  return ConfigService;
@@ -1587,11 +1592,23 @@ var PluginService = /*#__PURE__*/function () {
1587
1592
  };
1588
1593
  _proto.loadPlugins = function loadPlugins(appService) {
1589
1594
  var _this = this;
1590
- this.pluginConstructors.forEach(function (_ref) {
1591
- var plugin = _ref[0],
1592
- option = _ref[1];
1593
- _this.pluginInstances.set(plugin.name, new plugin(appService, option));
1594
- });
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()));
1595
1612
  };
1596
1613
  _proto.getPlugin = function getPlugin(plugin) {
1597
1614
  var pluginInstance = this.pluginInstances.get(plugin.name);
@@ -1631,7 +1648,7 @@ function bootstrapFromConfig(path) {
1631
1648
  }
1632
1649
 
1633
1650
  var PluginAbstract = function PluginAbstract() {};
1634
- PluginAbstract.dependencies = void 0;
1651
+ PluginAbstract.dependencies = [];
1635
1652
 
1636
1653
  var state = function state(colorkeys) {
1637
1654
  return plugin(function (pluginArgs) {
@@ -1717,6 +1734,218 @@ var themer = function themer(colors, darkMode) {
1717
1734
  return require('tailwindcss-themer')(options);
1718
1735
  };
1719
1736
 
1737
+ var FontFamily;
1738
+ (function (FontFamily) {
1739
+ FontFamily["Expressive"] = "expressive";
1740
+ FontFamily["Neutral"] = "neutral";
1741
+ })(FontFamily || (FontFamily = {}));
1742
+ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1743
+ function FontPlugin(appService, options) {
1744
+ var _options$fontFamily$e, _options$fontFamily, _options$fontFamily$n, _options$fontFamily2;
1745
+ var _this;
1746
+ _this = _PluginAbstract.call(this) || this;
1747
+ _this.appService = void 0;
1748
+ _this.options = void 0;
1749
+ _this.fontFamily = void 0;
1750
+ _this.fontStyles = void 0;
1751
+ _this.appService = appService;
1752
+ _this.options = options;
1753
+ _this.fontFamily = {
1754
+ expressive: (_options$fontFamily$e = options == null || (_options$fontFamily = options.fontFamily) == null ? void 0 : _options$fontFamily.expressive) != null ? _options$fontFamily$e : ['Roboto', 'sans-serif'],
1755
+ neutral: (_options$fontFamily$n = options == null || (_options$fontFamily2 = options.fontFamily) == null ? void 0 : _options$fontFamily2.neutral) != null ? _options$fontFamily$n : ['Roboto', 'sans-serif']
1756
+ };
1757
+ _this.fontStyles = {
1758
+ display: {
1759
+ large: {
1760
+ fontWeight: 400,
1761
+ fontSize: 3.5625,
1762
+ lineHeight: 4,
1763
+ letterSpacing: -0.015625,
1764
+ fontFamily: FontFamily.Expressive
1765
+ },
1766
+ medium: {
1767
+ fontWeight: 400,
1768
+ fontSize: 2.8125,
1769
+ lineHeight: 3.25,
1770
+ fontFamily: FontFamily.Expressive
1771
+ },
1772
+ small: {
1773
+ fontWeight: 400,
1774
+ fontSize: 2.25,
1775
+ lineHeight: 2.75,
1776
+ fontFamily: FontFamily.Expressive
1777
+ }
1778
+ },
1779
+ headline: {
1780
+ large: {
1781
+ fontWeight: 400,
1782
+ fontSize: 2,
1783
+ lineHeight: 2.5,
1784
+ fontFamily: FontFamily.Expressive
1785
+ },
1786
+ medium: {
1787
+ fontWeight: 400,
1788
+ fontSize: 1.75,
1789
+ lineHeight: 2.25,
1790
+ fontFamily: FontFamily.Expressive
1791
+ },
1792
+ small: {
1793
+ fontWeight: 400,
1794
+ fontSize: 1.5,
1795
+ lineHeight: 2,
1796
+ fontFamily: FontFamily.Expressive
1797
+ }
1798
+ },
1799
+ title: {
1800
+ large: {
1801
+ fontWeight: 400,
1802
+ fontSize: 1.375,
1803
+ lineHeight: 1.75,
1804
+ fontFamily: FontFamily.Neutral
1805
+ },
1806
+ medium: {
1807
+ fontWeight: 500,
1808
+ fontSize: 1,
1809
+ lineHeight: 1.5,
1810
+ fontFamily: FontFamily.Neutral,
1811
+ letterSpacing: 0.009375
1812
+ },
1813
+ small: {
1814
+ fontWeight: 500,
1815
+ fontSize: 0.875,
1816
+ lineHeight: 1.25,
1817
+ fontFamily: FontFamily.Neutral,
1818
+ letterSpacing: 0.00625
1819
+ }
1820
+ },
1821
+ label: {
1822
+ large: {
1823
+ fontWeight: 500,
1824
+ fontSize: 0.875,
1825
+ lineHeight: 1.25,
1826
+ fontFamily: FontFamily.Neutral,
1827
+ letterSpacing: 0.00625
1828
+ },
1829
+ medium: {
1830
+ fontWeight: 500,
1831
+ fontSize: 0.75,
1832
+ lineHeight: 1,
1833
+ fontFamily: FontFamily.Neutral,
1834
+ letterSpacing: 0.03125
1835
+ },
1836
+ small: {
1837
+ fontWeight: 500,
1838
+ fontSize: 0.6875,
1839
+ lineHeight: 1,
1840
+ fontFamily: FontFamily.Neutral,
1841
+ letterSpacing: 0.03125
1842
+ }
1843
+ },
1844
+ body: {
1845
+ large: {
1846
+ fontWeight: 400,
1847
+ fontSize: 1,
1848
+ lineHeight: 1.5625,
1849
+ fontFamily: FontFamily.Neutral,
1850
+ letterSpacing: 0.03125
1851
+ },
1852
+ medium: {
1853
+ fontWeight: 400,
1854
+ fontSize: 0.875,
1855
+ lineHeight: 1.25,
1856
+ fontFamily: FontFamily.Neutral,
1857
+ letterSpacing: 0.015625
1858
+ },
1859
+ small: {
1860
+ fontWeight: 400,
1861
+ fontSize: 0.75,
1862
+ lineHeight: 1,
1863
+ fontFamily: FontFamily.Neutral,
1864
+ letterSpacing: 0.025
1865
+ }
1866
+ }
1867
+ };
1868
+ if (options && options.fontStyles) Object.entries(options.fontStyles).forEach(function (_ref) {
1869
+ var key = _ref[0],
1870
+ fontParam = _ref[1];
1871
+ var fontRole = key;
1872
+ Object.entries(fontParam).forEach(function (_ref2) {
1873
+ var size = _ref2[0],
1874
+ fontStyle = _ref2[1];
1875
+ var fontSize = size;
1876
+ if (fontStyle) {
1877
+ _this.fontStyles[fontRole][fontSize] = _extends({}, _this.fontStyles[fontRole][fontSize], fontStyle);
1878
+ }
1879
+ });
1880
+ });
1881
+ return _this;
1882
+ }
1883
+ _inheritsLoose(FontPlugin, _PluginAbstract);
1884
+ FontPlugin.config = function config(options) {
1885
+ return options;
1886
+ };
1887
+ var _proto = FontPlugin.prototype;
1888
+ _proto.getFonts = function getFonts() {
1889
+ return {
1890
+ fontStyles: this.fontStyles,
1891
+ fontFamily: this.fontFamily
1892
+ };
1893
+ };
1894
+ return FontPlugin;
1895
+ }(PluginAbstract);
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
+
1720
1949
  var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1721
1950
  function TailwindPlugin(appService, options) {
1722
1951
  var _this;
@@ -1752,18 +1981,18 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1752
1981
  colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
1753
1982
  }
1754
1983
  }
1755
- 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;
1756
1987
  return {
1757
1988
  colors: {},
1758
- fontFamily: {
1759
- expressive: [],
1760
- neutral: []
1761
- },
1762
- 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)]
1763
1991
  };
1764
1992
  };
1765
1993
  return TailwindPlugin;
1766
1994
  }(PluginAbstract);
1995
+ TailwindPlugin.dependencies = [FontPlugin];
1767
1996
 
1768
1997
  var createTheme = function createTheme() {
1769
1998
  var app = bootstrapFromConfig();