@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.
@@ -1,6 +1,6 @@
1
1
  import { AddColorsOptions } from '../color';
2
2
  import { VariantEntity } from '../theme';
3
- import { PluginConstructor } from '../plugin';
3
+ import { PluginAbstract } from '../plugin';
4
4
  export interface ConfigInterface {
5
5
  sourceColor: string;
6
6
  contrastLevel?: number;
@@ -9,5 +9,5 @@ export interface ConfigInterface {
9
9
  colors?: AddColorsOptions | AddColorsOptions[];
10
10
  useDefaultColors?: boolean;
11
11
  palettes?: Record<string, string>;
12
- plugins?: (PluginConstructor | [PluginConstructor, object])[];
12
+ plugins?: PluginAbstract<any, any>[];
13
13
  }
@@ -1,3 +1,3 @@
1
- export * from './plugin.abstract';
1
+ export * from './pluginAbstract';
2
2
  export * from './plugin.module';
3
3
  export * from './plugin.service';
@@ -1,12 +1,8 @@
1
- import { PluginAbstract } from './plugin.abstract';
1
+ import { PluginAbstract } from './pluginAbstract';
2
2
  import { AppService } from '../app.service';
3
- export type PluginConstructor = (new (appService: AppService, options: any) => PluginAbstract) & {
4
- dependencies: PluginConstructor[];
5
- };
6
3
  export declare class PluginService {
7
- private pluginInstances;
8
- private pluginConstructors;
9
- addPlugin(plugin: PluginConstructor, config: object): void;
4
+ private plugins;
5
+ addPlugin(plugin: PluginAbstract<any, any>): void;
10
6
  loadPlugins(appService: AppService): void;
11
- getPlugin<T extends PluginAbstract>(plugin: new (appService: AppService, options: any) => T): T;
7
+ getPlugin<T extends PluginAbstract<any, any>>(plugin: new (...args: any) => T): T;
12
8
  }
@@ -0,0 +1,18 @@
1
+ import { AppService } from '../app.service';
2
+ export type PluginConstructor<Plugin extends PluginImplAbstract<any>> = new (...args: any) => Plugin;
3
+ export declare abstract class PluginAbstract<Plugin extends PluginImplAbstract<Options>, Options extends object> {
4
+ abstract readonly dependencies: (new (...args: any) => PluginAbstract<any, any>)[];
5
+ abstract readonly name: string;
6
+ options: Options;
7
+ abstract readonly pluginClass: PluginConstructor<Plugin>;
8
+ protected pluginInstance: Plugin | undefined;
9
+ constructor(options: Options);
10
+ init(appService: AppService): this;
11
+ getInstance(): Plugin;
12
+ }
13
+ export declare abstract class PluginImplAbstract<Options extends object> {
14
+ protected appService: AppService;
15
+ protected options: Options;
16
+ constructor(appService: AppService, options: Options);
17
+ abstract onInit(): void;
18
+ }
@@ -1,5 +1,4 @@
1
- import { AppService } from '../../app.service';
2
- import { PluginAbstract } from '../../plugin';
1
+ import { PluginAbstract, PluginImplAbstract } from '../../plugin';
3
2
  export declare enum FontFamily {
4
3
  Expressive = "expressive",
5
4
  Neutral = "neutral"
@@ -20,13 +19,24 @@ interface FontPluginOptions {
20
19
  };
21
20
  fontStyles?: Partial<Record<FontRole, Record<FontSize, Partial<FontStyle>>>>;
22
21
  }
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;
22
+ export declare class FontPlugin extends PluginAbstract<FontPluginImpl, FontPluginOptions> {
23
+ dependencies: never[];
24
+ name: string;
25
+ pluginClass: typeof FontPluginImpl;
26
+ }
27
+ declare class FontPluginImpl extends PluginImplAbstract<FontPluginOptions> {
28
+ private _fontFamily;
29
+ get fontFamily(): {
30
+ expressive: string[];
31
+ neutral: string[];
32
+ };
33
+ set fontFamily(value: {
34
+ expressive: string[];
35
+ neutral: string[];
36
+ } | undefined);
37
+ private _fontStyles;
38
+ get fontStyles(): Record<FontRole, Record<FontSize, FontStyle>>;
39
+ set fontStyles(value: Record<FontRole, Record<FontSize, FontStyle>> | undefined);
30
40
  getFonts(): {
31
41
  fontStyles: Record<FontRole, Record<FontSize, FontStyle>>;
32
42
  fontFamily: {
@@ -34,5 +44,6 @@ export declare class FontPlugin extends PluginAbstract {
34
44
  neutral: string[];
35
45
  };
36
46
  };
47
+ onInit(): void;
37
48
  }
38
49
  export {};
@@ -1,5 +1,4 @@
1
- import { PluginAbstract } from '../../plugin';
2
- import { AppService } from '../../app.service';
1
+ import { PluginAbstract, PluginImplAbstract } from '../../plugin';
3
2
  import { Theme } from './main';
4
3
  import { FontPlugin } from '../font';
5
4
  interface TailwindPluginOptions {
@@ -7,12 +6,13 @@ interface TailwindPluginOptions {
7
6
  responsiveBreakPoints?: Record<string, number>;
8
7
  subThemes?: Record<string, string>;
9
8
  }
10
- export declare class TailwindPlugin extends PluginAbstract {
11
- protected appService: AppService;
12
- protected options: TailwindPluginOptions;
13
- static dependencies: (typeof FontPlugin)[];
14
- constructor(appService: AppService, options: TailwindPluginOptions);
15
- static config(options: TailwindPluginOptions): TailwindPluginOptions;
9
+ export declare class TailwindPlugin extends PluginAbstract<TailwindImplPlugin, TailwindPluginOptions> {
10
+ dependencies: (typeof FontPlugin)[];
11
+ name: string;
12
+ pluginClass: typeof TailwindImplPlugin;
13
+ }
14
+ declare class TailwindImplPlugin extends PluginImplAbstract<TailwindPluginOptions> {
15
+ onInit(): void;
16
16
  getTheme(): Theme;
17
17
  }
18
18
  export {};
@@ -1542,11 +1542,7 @@ var ConfigService = /*#__PURE__*/function () {
1542
1542
  }
1543
1543
  if (plugins) {
1544
1544
  plugins.forEach(function (plugin) {
1545
- if (Array.isArray(plugin)) {
1546
- pluginService.addPlugin(plugin[0], plugin[1]);
1547
- } else {
1548
- pluginService.addPlugin(plugin, {});
1549
- }
1545
+ pluginService.addPlugin(plugin);
1550
1546
  });
1551
1547
  pluginService.loadPlugins(this.appService);
1552
1548
  }
@@ -1583,35 +1579,32 @@ var ConfigModule = {
1583
1579
 
1584
1580
  var PluginService = /*#__PURE__*/function () {
1585
1581
  function PluginService() {
1586
- this.pluginInstances = new Map();
1587
- this.pluginConstructors = new Map();
1582
+ this.plugins = new Map();
1588
1583
  }
1589
1584
  var _proto = PluginService.prototype;
1590
- _proto.addPlugin = function addPlugin(plugin, config) {
1591
- this.pluginConstructors.set(plugin.name, [plugin, config]);
1585
+ _proto.addPlugin = function addPlugin(plugin) {
1586
+ this.plugins.set(plugin.name, plugin);
1592
1587
  };
1593
1588
  _proto.loadPlugins = function loadPlugins(appService) {
1594
1589
  var _this = this;
1595
- var plugins = new Map(this.pluginConstructors);
1590
+ var plugins = new Map(this.plugins);
1596
1591
  var size = 0;
1597
1592
  do {
1598
1593
  size = plugins.size;
1599
- plugins.forEach(function (_ref, key) {
1600
- var plugin = _ref[0],
1601
- option = _ref[1];
1594
+ plugins.forEach(function (plugin, key) {
1602
1595
  var deps = plugin.dependencies.filter(function (dep) {
1603
- return !_this.pluginInstances.has(dep.name);
1596
+ return !_this.plugins.has(new dep().name);
1604
1597
  });
1605
1598
  if (deps.length === 0) {
1606
- _this.pluginInstances.set(plugin.name, new plugin(appService, option));
1599
+ _this.plugins.set(plugin.name, plugin.init(appService));
1607
1600
  plugins["delete"](key);
1608
1601
  }
1609
1602
  });
1610
1603
  } 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()));
1604
+ if (plugins.size > 0) throw new Error("Some plugins couldn't be loaded due to missing dependencies: " + Array.from(plugins.keys()));
1612
1605
  };
1613
1606
  _proto.getPlugin = function getPlugin(plugin) {
1614
- var pluginInstance = this.pluginInstances.get(plugin.name);
1607
+ var pluginInstance = this.plugins.get(new plugin().name);
1615
1608
  if (!pluginInstance) throw new Error("Plugin " + plugin.name + " not found");
1616
1609
  return pluginInstance;
1617
1610
  };
@@ -1647,8 +1640,33 @@ function bootstrapFromConfig(args) {
1647
1640
  return AppContainer.resolve('appService');
1648
1641
  }
1649
1642
 
1650
- var PluginAbstract = function PluginAbstract() {};
1651
- PluginAbstract.dependencies = [];
1643
+ var PluginAbstract = /*#__PURE__*/function () {
1644
+ function PluginAbstract(options) {
1645
+ this.options = void 0;
1646
+ this.pluginInstance = void 0;
1647
+ this.options = options;
1648
+ }
1649
+ var _proto = PluginAbstract.prototype;
1650
+ _proto.init = function init(appService) {
1651
+ this.pluginInstance = new this.pluginClass(appService, this.options);
1652
+ this.pluginInstance.onInit();
1653
+ return this;
1654
+ };
1655
+ _proto.getInstance = function getInstance() {
1656
+ if (!this.pluginInstance) {
1657
+ throw new Error("Plugin " + this.name + " is not initialized");
1658
+ }
1659
+ return this.pluginInstance;
1660
+ };
1661
+ return PluginAbstract;
1662
+ }();
1663
+ var PluginImplAbstract = function PluginImplAbstract(appService, options) {
1664
+ this.appService = void 0;
1665
+ this.options = void 0;
1666
+ this.appService = appService;
1667
+ this.options = options;
1668
+ this.onInit();
1669
+ };
1652
1670
 
1653
1671
  exports.FontFamily = void 0;
1654
1672
  (function (FontFamily) {
@@ -1656,21 +1674,50 @@ exports.FontFamily = void 0;
1656
1674
  FontFamily["Neutral"] = "neutral";
1657
1675
  })(exports.FontFamily || (exports.FontFamily = {}));
1658
1676
  var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1659
- function FontPlugin(appService, options) {
1660
- var _options$fontFamily$e, _options$fontFamily, _options$fontFamily$n, _options$fontFamily2;
1677
+ function FontPlugin() {
1661
1678
  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']
1679
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1680
+ args[_key] = arguments[_key];
1681
+ }
1682
+ _this = _PluginAbstract.call.apply(_PluginAbstract, [this].concat(args)) || this;
1683
+ _this.dependencies = [];
1684
+ _this.name = 'font';
1685
+ _this.pluginClass = FontPluginImpl;
1686
+ return _this;
1687
+ }
1688
+ _inheritsLoose(FontPlugin, _PluginAbstract);
1689
+ return FontPlugin;
1690
+ }(PluginAbstract);
1691
+ var FontPluginImpl = /*#__PURE__*/function (_PluginImplAbstract) {
1692
+ function FontPluginImpl() {
1693
+ var _this2;
1694
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1695
+ args[_key2] = arguments[_key2];
1696
+ }
1697
+ _this2 = _PluginImplAbstract.call.apply(_PluginImplAbstract, [this].concat(args)) || this;
1698
+ _this2._fontFamily = void 0;
1699
+ _this2._fontStyles = void 0;
1700
+ return _this2;
1701
+ }
1702
+ _inheritsLoose(FontPluginImpl, _PluginImplAbstract);
1703
+ var _proto = FontPluginImpl.prototype;
1704
+ _proto.getFonts = function getFonts() {
1705
+ return {
1706
+ fontStyles: this.fontStyles,
1707
+ fontFamily: this.fontFamily
1708
+ };
1709
+ };
1710
+ _proto.onInit = function onInit() {
1711
+ var _this$options$fontFam,
1712
+ _this$options,
1713
+ _this$options$fontFam2,
1714
+ _this$options2,
1715
+ _this3 = this;
1716
+ this.fontFamily = {
1717
+ 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'],
1718
+ 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']
1672
1719
  };
1673
- _this.fontStyles = {
1720
+ this.fontStyles = {
1674
1721
  display: {
1675
1722
  large: {
1676
1723
  fontWeight: 400,
@@ -1781,7 +1828,7 @@ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1781
1828
  }
1782
1829
  }
1783
1830
  };
1784
- if (options && options.fontStyles) Object.entries(options.fontStyles).forEach(function (_ref) {
1831
+ if (this.options && this.options.fontStyles) Object.entries(this.options.fontStyles).forEach(function (_ref) {
1785
1832
  var key = _ref[0],
1786
1833
  fontParam = _ref[1];
1787
1834
  var fontRole = key;
@@ -1790,25 +1837,31 @@ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1790
1837
  fontStyle = _ref2[1];
1791
1838
  var fontSize = size;
1792
1839
  if (fontStyle) {
1793
- _this.fontStyles[fontRole][fontSize] = _extends({}, _this.fontStyles[fontRole][fontSize], fontStyle);
1840
+ _this3.fontStyles[fontRole][fontSize] = _extends({}, _this3.fontStyles[fontRole][fontSize], fontStyle);
1794
1841
  }
1795
1842
  });
1796
1843
  });
1797
- return _this;
1798
- }
1799
- _inheritsLoose(FontPlugin, _PluginAbstract);
1800
- FontPlugin.config = function config(options) {
1801
- return options;
1802
1844
  };
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);
1845
+ return _createClass(FontPluginImpl, [{
1846
+ key: "fontFamily",
1847
+ get: function get() {
1848
+ if (!this._fontFamily) throw new Error('Font family not initialized');
1849
+ return this._fontFamily;
1850
+ },
1851
+ set: function set(value) {
1852
+ this._fontFamily = value;
1853
+ }
1854
+ }, {
1855
+ key: "fontStyles",
1856
+ get: function get() {
1857
+ if (!this._fontStyles) throw new Error('Font styles not initialized');
1858
+ return this._fontStyles;
1859
+ },
1860
+ set: function set(value) {
1861
+ this._fontStyles = value;
1862
+ }
1863
+ }]);
1864
+ }(PluginImplAbstract);
1812
1865
 
1813
1866
  var state = function state(colorkeys) {
1814
1867
  return plugin(function (pluginArgs) {
@@ -1994,25 +2047,33 @@ var font = function font(fontStyles, responsiveBreakPoints) {
1994
2047
  };
1995
2048
 
1996
2049
  var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1997
- function TailwindPlugin(appService, options) {
1998
- var _options$darkMode, _options$responsiveBr;
2050
+ function TailwindPlugin() {
1999
2051
  var _this;
2000
- (_options$darkMode = options.darkMode) != null ? _options$darkMode : options.darkMode = 'class';
2001
- (_options$responsiveBr = options.responsiveBreakPoints) != null ? _options$responsiveBr : options.responsiveBreakPoints = {
2002
- lg: 1.125
2003
- };
2004
- _this = _PluginAbstract.call(this) || this;
2005
- _this.appService = void 0;
2006
- _this.options = void 0;
2007
- _this.appService = appService;
2008
- _this.options = options;
2052
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2053
+ args[_key] = arguments[_key];
2054
+ }
2055
+ _this = _PluginAbstract.call.apply(_PluginAbstract, [this].concat(args)) || this;
2056
+ _this.dependencies = [FontPlugin];
2057
+ _this.name = 'tailwind';
2058
+ _this.pluginClass = TailwindImplPlugin;
2009
2059
  return _this;
2010
2060
  }
2011
2061
  _inheritsLoose(TailwindPlugin, _PluginAbstract);
2012
- TailwindPlugin.config = function config(options) {
2013
- return options;
2062
+ return TailwindPlugin;
2063
+ }(PluginAbstract);
2064
+ var TailwindImplPlugin = /*#__PURE__*/function (_PluginImplAbstract) {
2065
+ function TailwindImplPlugin() {
2066
+ return _PluginImplAbstract.apply(this, arguments) || this;
2067
+ }
2068
+ _inheritsLoose(TailwindImplPlugin, _PluginImplAbstract);
2069
+ var _proto = TailwindImplPlugin.prototype;
2070
+ _proto.onInit = function onInit() {
2071
+ var _this$options, _this$options$darkMod, _this$options2, _this$options2$respon;
2072
+ (_this$options$darkMod = (_this$options = this.options).darkMode) != null ? _this$options$darkMod : _this$options.darkMode = 'class';
2073
+ (_this$options2$respon = (_this$options2 = this.options).responsiveBreakPoints) != null ? _this$options2$respon : _this$options2.responsiveBreakPoints = {
2074
+ lg: 1.125
2075
+ };
2014
2076
  };
2015
- var _proto = TailwindPlugin.prototype;
2016
2077
  _proto.getTheme = function getTheme() {
2017
2078
  var colors = {};
2018
2079
  for (var _i = 0, _arr = [false, true]; _i < _arr.length; _i++) {
@@ -2033,7 +2094,7 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
2033
2094
  colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
2034
2095
  }
2035
2096
  }
2036
- var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getFonts(),
2097
+ var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getInstance().getFonts(),
2037
2098
  fontStyles = _this$appService$plug.fontStyles,
2038
2099
  fontFamily = _this$appService$plug.fontFamily;
2039
2100
  return {
@@ -2047,16 +2108,12 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
2047
2108
  })]
2048
2109
  };
2049
2110
  };
2050
- return TailwindPlugin;
2051
- }(PluginAbstract);
2052
- TailwindPlugin.dependencies = [FontPlugin];
2111
+ return TailwindImplPlugin;
2112
+ }(PluginImplAbstract);
2053
2113
 
2054
2114
  var createTheme = function createTheme() {
2055
2115
  var app = bootstrapFromConfig();
2056
- var plugin = app.pluginService.getPlugin(TailwindPlugin);
2057
- if (!plugin) {
2058
- throw new Error('Tailwind plugin not found');
2059
- }
2116
+ var plugin = app.pluginService.getPlugin(TailwindPlugin).getInstance();
2060
2117
  return _extends({}, plugin.getTheme(), {
2061
2118
  appService: app
2062
2119
  });
@@ -2075,6 +2132,7 @@ exports.ContrastCurve = ContrastCurve;
2075
2132
  exports.DynamicColor = DynamicColor;
2076
2133
  exports.FontPlugin = FontPlugin;
2077
2134
  exports.PluginAbstract = PluginAbstract;
2135
+ exports.PluginImplAbstract = PluginImplAbstract;
2078
2136
  exports.PluginModule = PluginModule;
2079
2137
  exports.PluginService = PluginService;
2080
2138
  exports.SchemeEntity = SchemeEntity;