@udixio/theme 1.0.0-beta.24 → 1.0.0-beta.26

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,32 @@ 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
+ return this;
1653
+ };
1654
+ _proto.getInstance = function getInstance() {
1655
+ if (!this.pluginInstance) {
1656
+ throw new Error("Plugin " + this.name + " is not initialized");
1657
+ }
1658
+ return this.pluginInstance;
1659
+ };
1660
+ return PluginAbstract;
1661
+ }();
1662
+ var PluginImplAbstract = function PluginImplAbstract(appService, options) {
1663
+ this.appService = void 0;
1664
+ this.options = void 0;
1665
+ this.appService = appService;
1666
+ this.options = options;
1667
+ this.onInit();
1668
+ };
1652
1669
 
1653
1670
  exports.FontFamily = void 0;
1654
1671
  (function (FontFamily) {
@@ -1656,21 +1673,50 @@ exports.FontFamily = void 0;
1656
1673
  FontFamily["Neutral"] = "neutral";
1657
1674
  })(exports.FontFamily || (exports.FontFamily = {}));
1658
1675
  var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1659
- function FontPlugin(appService, options) {
1660
- var _options$fontFamily$e, _options$fontFamily, _options$fontFamily$n, _options$fontFamily2;
1676
+ function FontPlugin() {
1661
1677
  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']
1678
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1679
+ args[_key] = arguments[_key];
1680
+ }
1681
+ _this = _PluginAbstract.call.apply(_PluginAbstract, [this].concat(args)) || this;
1682
+ _this.dependencies = [];
1683
+ _this.name = 'font';
1684
+ _this.pluginClass = FontPluginImpl;
1685
+ return _this;
1686
+ }
1687
+ _inheritsLoose(FontPlugin, _PluginAbstract);
1688
+ return FontPlugin;
1689
+ }(PluginAbstract);
1690
+ var FontPluginImpl = /*#__PURE__*/function (_PluginImplAbstract) {
1691
+ function FontPluginImpl() {
1692
+ var _this2;
1693
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1694
+ args[_key2] = arguments[_key2];
1695
+ }
1696
+ _this2 = _PluginImplAbstract.call.apply(_PluginImplAbstract, [this].concat(args)) || this;
1697
+ _this2._fontFamily = void 0;
1698
+ _this2._fontStyles = void 0;
1699
+ return _this2;
1700
+ }
1701
+ _inheritsLoose(FontPluginImpl, _PluginImplAbstract);
1702
+ var _proto = FontPluginImpl.prototype;
1703
+ _proto.getFonts = function getFonts() {
1704
+ return {
1705
+ fontStyles: this.fontStyles,
1706
+ fontFamily: this.fontFamily
1707
+ };
1708
+ };
1709
+ _proto.onInit = function onInit() {
1710
+ var _this$options$fontFam,
1711
+ _this$options,
1712
+ _this$options$fontFam2,
1713
+ _this$options2,
1714
+ _this3 = this;
1715
+ this.fontFamily = {
1716
+ 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'],
1717
+ 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
1718
  };
1673
- _this.fontStyles = {
1719
+ this.fontStyles = {
1674
1720
  display: {
1675
1721
  large: {
1676
1722
  fontWeight: 400,
@@ -1781,7 +1827,7 @@ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1781
1827
  }
1782
1828
  }
1783
1829
  };
1784
- if (options && options.fontStyles) Object.entries(options.fontStyles).forEach(function (_ref) {
1830
+ if (this.options && this.options.fontStyles) Object.entries(this.options.fontStyles).forEach(function (_ref) {
1785
1831
  var key = _ref[0],
1786
1832
  fontParam = _ref[1];
1787
1833
  var fontRole = key;
@@ -1790,25 +1836,31 @@ var FontPlugin = /*#__PURE__*/function (_PluginAbstract) {
1790
1836
  fontStyle = _ref2[1];
1791
1837
  var fontSize = size;
1792
1838
  if (fontStyle) {
1793
- _this.fontStyles[fontRole][fontSize] = _extends({}, _this.fontStyles[fontRole][fontSize], fontStyle);
1839
+ _this3.fontStyles[fontRole][fontSize] = _extends({}, _this3.fontStyles[fontRole][fontSize], fontStyle);
1794
1840
  }
1795
1841
  });
1796
1842
  });
1797
- return _this;
1798
- }
1799
- _inheritsLoose(FontPlugin, _PluginAbstract);
1800
- FontPlugin.config = function config(options) {
1801
- return options;
1802
1843
  };
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);
1844
+ return _createClass(FontPluginImpl, [{
1845
+ key: "fontFamily",
1846
+ get: function get() {
1847
+ if (!this._fontFamily) throw new Error('Font family not initialized');
1848
+ return this._fontFamily;
1849
+ },
1850
+ set: function set(value) {
1851
+ this._fontFamily = value;
1852
+ }
1853
+ }, {
1854
+ key: "fontStyles",
1855
+ get: function get() {
1856
+ if (!this._fontStyles) throw new Error('Font styles not initialized');
1857
+ return this._fontStyles;
1858
+ },
1859
+ set: function set(value) {
1860
+ this._fontStyles = value;
1861
+ }
1862
+ }]);
1863
+ }(PluginImplAbstract);
1812
1864
 
1813
1865
  var state = function state(colorkeys) {
1814
1866
  return plugin(function (pluginArgs) {
@@ -1877,7 +1929,7 @@ function createSubTheme(_ref) {
1877
1929
  var theme = {
1878
1930
  name: isDarkTheme ? name + 'Dark' : name,
1879
1931
  selectors: isDarkTheme && darkMode === 'class' ? ['.dark-mode .theme-' + name, '.dark-mode.theme-' + name, '[data-theme="dark"] .theme-' + name, '[data-theme="dark"].theme-' + name] : ['.theme-' + name],
1880
- mediaQuery: '@media (prefers-color-scheme: dark)',
1932
+ mediaQuery: isDarkTheme && darkMode === 'media' ? '@media (prefers-color-scheme: dark)' : undefined,
1881
1933
  extend: {
1882
1934
  colors: colors
1883
1935
  }
@@ -1994,25 +2046,33 @@ var font = function font(fontStyles, responsiveBreakPoints) {
1994
2046
  };
1995
2047
 
1996
2048
  var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
1997
- function TailwindPlugin(appService, options) {
1998
- var _options$darkMode, _options$responsiveBr;
2049
+ function TailwindPlugin() {
1999
2050
  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;
2051
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2052
+ args[_key] = arguments[_key];
2053
+ }
2054
+ _this = _PluginAbstract.call.apply(_PluginAbstract, [this].concat(args)) || this;
2055
+ _this.dependencies = [FontPlugin];
2056
+ _this.name = 'tailwind';
2057
+ _this.pluginClass = TailwindImplPlugin;
2009
2058
  return _this;
2010
2059
  }
2011
2060
  _inheritsLoose(TailwindPlugin, _PluginAbstract);
2012
- TailwindPlugin.config = function config(options) {
2013
- return options;
2061
+ return TailwindPlugin;
2062
+ }(PluginAbstract);
2063
+ var TailwindImplPlugin = /*#__PURE__*/function (_PluginImplAbstract) {
2064
+ function TailwindImplPlugin() {
2065
+ return _PluginImplAbstract.apply(this, arguments) || this;
2066
+ }
2067
+ _inheritsLoose(TailwindImplPlugin, _PluginImplAbstract);
2068
+ var _proto = TailwindImplPlugin.prototype;
2069
+ _proto.onInit = function onInit() {
2070
+ var _this$options, _this$options$darkMod, _this$options2, _this$options2$respon;
2071
+ (_this$options$darkMod = (_this$options = this.options).darkMode) != null ? _this$options$darkMod : _this$options.darkMode = 'class';
2072
+ (_this$options2$respon = (_this$options2 = this.options).responsiveBreakPoints) != null ? _this$options2$respon : _this$options2.responsiveBreakPoints = {
2073
+ lg: 1.125
2074
+ };
2014
2075
  };
2015
- var _proto = TailwindPlugin.prototype;
2016
2076
  _proto.getTheme = function getTheme() {
2017
2077
  var colors = {};
2018
2078
  for (var _i = 0, _arr = [false, true]; _i < _arr.length; _i++) {
@@ -2033,7 +2093,7 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
2033
2093
  colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
2034
2094
  }
2035
2095
  }
2036
- var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getFonts(),
2096
+ var _this$appService$plug = this.appService.pluginService.getPlugin(FontPlugin).getInstance().getFonts(),
2037
2097
  fontStyles = _this$appService$plug.fontStyles,
2038
2098
  fontFamily = _this$appService$plug.fontFamily;
2039
2099
  return {
@@ -2047,16 +2107,12 @@ var TailwindPlugin = /*#__PURE__*/function (_PluginAbstract) {
2047
2107
  })]
2048
2108
  };
2049
2109
  };
2050
- return TailwindPlugin;
2051
- }(PluginAbstract);
2052
- TailwindPlugin.dependencies = [FontPlugin];
2110
+ return TailwindImplPlugin;
2111
+ }(PluginImplAbstract);
2053
2112
 
2054
2113
  var createTheme = function createTheme() {
2055
2114
  var app = bootstrapFromConfig();
2056
- var plugin = app.pluginService.getPlugin(TailwindPlugin);
2057
- if (!plugin) {
2058
- throw new Error('Tailwind plugin not found');
2059
- }
2115
+ var plugin = app.pluginService.getPlugin(TailwindPlugin).getInstance();
2060
2116
  return _extends({}, plugin.getTheme(), {
2061
2117
  appService: app
2062
2118
  });
@@ -2075,6 +2131,7 @@ exports.ContrastCurve = ContrastCurve;
2075
2131
  exports.DynamicColor = DynamicColor;
2076
2132
  exports.FontPlugin = FontPlugin;
2077
2133
  exports.PluginAbstract = PluginAbstract;
2134
+ exports.PluginImplAbstract = PluginImplAbstract;
2078
2135
  exports.PluginModule = PluginModule;
2079
2136
  exports.PluginService = PluginService;
2080
2137
  exports.SchemeEntity = SchemeEntity;