@symbo.ls/scratch 3.5.1 → 3.6.3

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,3 +1,14 @@
1
+ const resolveFileUrl = (url, files) => {
2
+ if (!url || !files) return null;
3
+ try {
4
+ new URL(url);
5
+ return null;
6
+ } catch (e) {
7
+ }
8
+ const file = files[url];
9
+ if (file) return file.content && file.content.src;
10
+ return null;
11
+ };
1
12
  const getDefaultOrFirstKey = (LIBRARY, key) => {
2
13
  if (LIBRARY[key]) return LIBRARY[key].value;
3
14
  if (LIBRARY.default) return LIBRARY[LIBRARY.default].value;
@@ -25,34 +36,37 @@ const setCustomFont = (name, url, weight, options = {}) => {
25
36
  };
26
37
  const setCustomFontMedia = (name, url, weight, options) => `@font-face {${setCustomFont(name, url, weight, options)}
27
38
  }`;
28
- const getFontFaceEach = (name, weights) => {
39
+ const getFontFaceEach = (name, weights, files) => {
29
40
  const keys = Object.keys(weights);
30
41
  return keys.map((key) => {
31
42
  const { url, fontWeight } = weights[key];
32
- return setCustomFont(name, url, fontWeight);
43
+ const resolvedUrl = resolveFileUrl(url, files) || url;
44
+ return setCustomFont(name, resolvedUrl, fontWeight);
33
45
  });
34
46
  };
35
47
  const getFontFace = (LIBRARY) => {
36
48
  const keys = Object.keys(LIBRARY);
37
49
  return keys.map((key) => getFontFaceEach(key, LIBRARY[key].value));
38
50
  };
39
- const getFontFaceEachString = (name, weights) => {
51
+ const getFontFaceEachString = (name, weights, files) => {
40
52
  if (weights && weights.isVariable) {
41
- if (isGoogleFontsUrl(weights.url)) {
42
- return setFontImport(weights.url);
53
+ const url2 = resolveFileUrl(weights.url, files) || weights.url;
54
+ if (isGoogleFontsUrl(url2)) {
55
+ return setFontImport(url2);
43
56
  }
44
- return setCustomFontMedia(name, weights.url, weights.fontWeight, {
57
+ return setCustomFontMedia(name, url2, weights.fontWeight, {
45
58
  fontStretch: weights.fontStretch,
46
59
  fontDisplay: weights.fontDisplay || "swap"
47
60
  });
48
61
  }
49
62
  const isArr = weights[0];
50
- if (isArr) return getFontFaceEach(name, weights).map(setInCustomFontMedia);
51
- return setCustomFontMedia(name, weights.url);
63
+ if (isArr) return getFontFaceEach(name, weights, files).map(setInCustomFontMedia);
64
+ const url = resolveFileUrl(weights.url, files) || weights.url;
65
+ return setCustomFontMedia(name, url);
52
66
  };
53
- const getFontFaceString = (LIBRARY) => {
67
+ const getFontFaceString = (LIBRARY, files) => {
54
68
  const keys = Object.keys(LIBRARY);
55
- return keys.map((key) => getFontFaceEachString(key, LIBRARY[key].value));
69
+ return keys.map((key) => getFontFaceEachString(key, LIBRARY[key].value, files));
56
70
  };
57
71
  export {
58
72
  getDefaultOrFirstKey,
@@ -62,6 +76,7 @@ export {
62
76
  getFontFaceString,
63
77
  getFontFormat,
64
78
  isGoogleFontsUrl,
79
+ resolveFileUrl,
65
80
  setCustomFont,
66
81
  setCustomFontMedia,
67
82
  setFontImport,
@@ -27,6 +27,7 @@ var SmblsScratch = (() => {
27
27
  CLASS: () => CLASS,
28
28
  COLOR: () => COLOR,
29
29
  CONFIG: () => CONFIG,
30
+ CSS_MEDIA_VARS: () => CSS_MEDIA_VARS,
30
31
  CSS_NATIVE_COLOR_REGEX: () => CSS_NATIVE_COLOR_REGEX,
31
32
  CSS_UNITS: () => CSS_UNITS,
32
33
  CSS_VARS: () => CSS_VARS,
@@ -117,6 +118,7 @@ var SmblsScratch = (() => {
117
118
  opacify: () => opacify,
118
119
  parseColorToken: () => parseColorToken,
119
120
  resolveColorsInGradient: () => resolveColorsInGradient,
121
+ resolveFileUrl: () => resolveFileUrl,
120
122
  returnSubThemeOrDefault: () => returnSubThemeOrDefault,
121
123
  rgbArrayToHex: () => rgbArrayToHex,
122
124
  rgbToHSL: () => rgbToHSL,
@@ -205,6 +207,7 @@ var SmblsScratch = (() => {
205
207
  numToLetterMap: () => numToLetterMap,
206
208
  opacify: () => opacify,
207
209
  parseColorToken: () => parseColorToken,
210
+ resolveFileUrl: () => resolveFileUrl,
208
211
  returnSubThemeOrDefault: () => returnSubThemeOrDefault,
209
212
  rgbArrayToHex: () => rgbArrayToHex,
210
213
  rgbToHSL: () => rgbToHSL,
@@ -282,7 +285,7 @@ var SmblsScratch = (() => {
282
285
 
283
286
  // ../utils/dist/esm/node.js
284
287
  var isDOMNode = (obj) => {
285
- return typeof window2 !== "undefined" && (obj instanceof window2.Node || obj instanceof window2.Window || obj === window2 || obj === document);
288
+ return typeof window2 !== "undefined" && (window2.Node && obj instanceof window2.Node || window2.Window && obj instanceof window2.Window || obj === window2 || obj === document);
286
289
  };
287
290
 
288
291
  // ../utils/dist/esm/types.js
@@ -693,6 +696,17 @@ var SmblsScratch = (() => {
693
696
  };
694
697
 
695
698
  // src/utils/font.js
699
+ var resolveFileUrl = (url, files) => {
700
+ if (!url || !files) return null;
701
+ try {
702
+ new URL(url);
703
+ return null;
704
+ } catch (e) {
705
+ }
706
+ const file = files[url];
707
+ if (file) return file.content && file.content.src;
708
+ return null;
709
+ };
696
710
  var getDefaultOrFirstKey = (LIBRARY, key) => {
697
711
  if (LIBRARY[key]) return LIBRARY[key].value;
698
712
  if (LIBRARY.default) return LIBRARY[LIBRARY.default].value;
@@ -720,34 +734,37 @@ var SmblsScratch = (() => {
720
734
  };
721
735
  var setCustomFontMedia = (name, url, weight, options) => `@font-face {${setCustomFont(name, url, weight, options)}
722
736
  }`;
723
- var getFontFaceEach = (name, weights) => {
737
+ var getFontFaceEach = (name, weights, files) => {
724
738
  const keys = Object.keys(weights);
725
739
  return keys.map((key) => {
726
740
  const { url, fontWeight } = weights[key];
727
- return setCustomFont(name, url, fontWeight);
741
+ const resolvedUrl = resolveFileUrl(url, files) || url;
742
+ return setCustomFont(name, resolvedUrl, fontWeight);
728
743
  });
729
744
  };
730
745
  var getFontFace = (LIBRARY) => {
731
746
  const keys = Object.keys(LIBRARY);
732
747
  return keys.map((key) => getFontFaceEach(key, LIBRARY[key].value));
733
748
  };
734
- var getFontFaceEachString = (name, weights) => {
749
+ var getFontFaceEachString = (name, weights, files) => {
735
750
  if (weights && weights.isVariable) {
736
- if (isGoogleFontsUrl(weights.url)) {
737
- return setFontImport(weights.url);
751
+ const url2 = resolveFileUrl(weights.url, files) || weights.url;
752
+ if (isGoogleFontsUrl(url2)) {
753
+ return setFontImport(url2);
738
754
  }
739
- return setCustomFontMedia(name, weights.url, weights.fontWeight, {
755
+ return setCustomFontMedia(name, url2, weights.fontWeight, {
740
756
  fontStretch: weights.fontStretch,
741
757
  fontDisplay: weights.fontDisplay || "swap"
742
758
  });
743
759
  }
744
760
  const isArr = weights[0];
745
- if (isArr) return getFontFaceEach(name, weights).map(setInCustomFontMedia);
746
- return setCustomFontMedia(name, weights.url);
761
+ if (isArr) return getFontFaceEach(name, weights, files).map(setInCustomFontMedia);
762
+ const url = resolveFileUrl(weights.url, files) || weights.url;
763
+ return setCustomFontMedia(name, url);
747
764
  };
748
- var getFontFaceString = (LIBRARY) => {
765
+ var getFontFaceString = (LIBRARY, files) => {
749
766
  const keys = Object.keys(LIBRARY);
750
- return keys.map((key) => getFontFaceEachString(key, LIBRARY[key].value));
767
+ return keys.map((key) => getFontFaceEachString(key, LIBRARY[key].value, files));
751
768
  };
752
769
 
753
770
  // ../smbls-utils/dist/esm/index.js
@@ -969,7 +986,8 @@ var SmblsScratch = (() => {
969
986
 
970
987
  // src/factory.js
971
988
  var CSS_VARS = {};
972
- var _CONF = void 0 || defaultConfig_exports;
989
+ var CSS_MEDIA_VARS = {};
990
+ var _CONF = defaultConfig_exports;
973
991
  var _confLower = {};
974
992
  for (const key in _CONF) {
975
993
  const lower = key.toLowerCase();
@@ -980,7 +998,9 @@ var SmblsScratch = (() => {
980
998
  verbose: false,
981
999
  useVariable: true,
982
1000
  useReset: true,
1001
+ globalTheme: "auto",
983
1002
  CSS_VARS,
1003
+ CSS_MEDIA_VARS,
984
1004
  ..._confLower
985
1005
  };
986
1006
  var cachedConfig = deepClone(CONFIG);
@@ -1743,24 +1763,101 @@ var SmblsScratch = (() => {
1743
1763
  setHelpers(val, value);
1744
1764
  return { var: CSSvar, value, state, media, helpers };
1745
1765
  };
1766
+ var generateAutoVars = (schemes, varPrefix, CONFIG2) => {
1767
+ const { CSS_VARS: CSS_VARS2 } = CONFIG2;
1768
+ if (!CONFIG2.CSS_MEDIA_VARS) CONFIG2.CSS_MEDIA_VARS = {};
1769
+ const MEDIA_VARS = CONFIG2.CSS_MEDIA_VARS;
1770
+ const globalTheme = CONFIG2.globalTheme !== void 0 ? CONFIG2.globalTheme : "auto";
1771
+ const result = {};
1772
+ const allKeys = /* @__PURE__ */ new Set();
1773
+ for (const scheme in schemes) {
1774
+ if (schemes[scheme]) for (const k of Object.keys(schemes[scheme])) allKeys.add(k);
1775
+ }
1776
+ for (const param of allKeys) {
1777
+ const symb = param.slice(0, 1);
1778
+ const hasObject = Object.values(schemes).some((s) => isObjectLike(s?.[param]));
1779
+ if (symb === "." && hasObject) {
1780
+ const helperName = param.slice(1);
1781
+ const subSchemes = {};
1782
+ for (const scheme in schemes) {
1783
+ if (isObjectLike(schemes[scheme]?.[param])) subSchemes[scheme] = schemes[scheme][param];
1784
+ }
1785
+ result[param] = generateAutoVars(subSchemes, `${varPrefix}-${helperName}`, CONFIG2);
1786
+ } else if (symb === ":" && hasObject) {
1787
+ const pseudoName = param.replace(/^:+/, "");
1788
+ const subSchemes = {};
1789
+ for (const scheme in schemes) {
1790
+ if (isObjectLike(schemes[scheme]?.[param])) subSchemes[scheme] = schemes[scheme][param];
1791
+ }
1792
+ result[param] = generateAutoVars(subSchemes, `${varPrefix}-${pseudoName}`, CONFIG2);
1793
+ } else if (symb !== "@" && symb !== "." && symb !== ":") {
1794
+ const autoVar = `--theme-${varPrefix}-${param}`;
1795
+ if (globalTheme === "auto") {
1796
+ for (const scheme in schemes) {
1797
+ const val = schemes[scheme]?.[param];
1798
+ if (val === void 0) continue;
1799
+ const color = getColor(val, `@${scheme}`);
1800
+ if (color === void 0) continue;
1801
+ const selector = `[data-theme="${scheme}"]`;
1802
+ if (!MEDIA_VARS[selector]) MEDIA_VARS[selector] = {};
1803
+ MEDIA_VARS[selector][autoVar] = color;
1804
+ if (scheme === "dark" || scheme === "light") {
1805
+ const mq = `@media (prefers-color-scheme: ${scheme})`;
1806
+ if (!MEDIA_VARS[mq]) MEDIA_VARS[mq] = {};
1807
+ MEDIA_VARS[mq][autoVar] = color;
1808
+ }
1809
+ }
1810
+ } else {
1811
+ const forced = String(globalTheme).replace(/^'|'$/g, "");
1812
+ const source = schemes[forced]?.[param];
1813
+ if (source !== void 0) {
1814
+ const color = getColor(source, `@${forced}`);
1815
+ if (color !== void 0) CSS_VARS2[autoVar] = color;
1816
+ }
1817
+ }
1818
+ result[param] = `var(${autoVar})`;
1819
+ result[`.${param}`] = { [param]: result[param] };
1820
+ }
1821
+ }
1822
+ if (result.background || result.color || result.backgroundColor) {
1823
+ result[".inversed"] = {
1824
+ color: result.background || result.backgroundColor,
1825
+ background: result.color
1826
+ };
1827
+ }
1828
+ return result;
1829
+ };
1746
1830
  var setMediaTheme = (val, key, suffix, prefers) => {
1747
1831
  const CONFIG2 = getActiveConfig();
1748
1832
  const { CSS_VARS: CSS_VARS2 } = CONFIG2;
1749
1833
  const theme = { value: val };
1834
+ const isTopLevel = !suffix && !prefers;
1750
1835
  if (isObjectLike(val)) {
1836
+ if (isTopLevel && CONFIG2.useVariable) {
1837
+ const schemes = {};
1838
+ for (const param in val) {
1839
+ if (param.startsWith("@") && isObjectLike(val[param])) {
1840
+ schemes[param.slice(1)] = val[param];
1841
+ }
1842
+ }
1843
+ if (Object.keys(schemes).length) {
1844
+ const autoResult = generateAutoVars(schemes, key, CONFIG2);
1845
+ Object.assign(theme, autoResult);
1846
+ }
1847
+ }
1751
1848
  for (const param in val) {
1752
1849
  const symb = param.slice(0, 1);
1753
1850
  const value = val[param];
1754
1851
  if (symb === "@" || symb === ":" || symb === ".") {
1755
1852
  const hasPrefers = symb === "@" && param;
1756
1853
  theme[param] = setMediaTheme(value, key, param, prefers || hasPrefers);
1757
- } else {
1854
+ } else if (!isTopLevel) {
1758
1855
  const color = getColor(value, prefers);
1759
1856
  const metaSuffixes = [...new Set([prefers, suffix].filter((v) => v).map((v) => v.slice(1)))];
1760
1857
  const varmetaSuffixName = metaSuffixes.length ? "-" + metaSuffixes.join("-") : "";
1761
1858
  const CSSVar = `--theme-${key}${varmetaSuffixName}-${param}`;
1762
1859
  if (CONFIG2.useVariable) {
1763
- CSS_VARS2[CSSVar] = color;
1860
+ if (CONFIG2.useThemeSuffixedVars) CSS_VARS2[CSSVar] = color;
1764
1861
  theme[param] = `var(${CSSVar})`;
1765
1862
  } else {
1766
1863
  theme[param] = color;
@@ -1768,7 +1865,7 @@ var SmblsScratch = (() => {
1768
1865
  theme[`.${param}`] = { [param]: theme[param] };
1769
1866
  }
1770
1867
  }
1771
- if (theme.background || theme.color || theme.backgroundColor) {
1868
+ if (!theme[".inversed"] && (theme.background || theme.color || theme.backgroundColor)) {
1772
1869
  theme[".inversed"] = {
1773
1870
  color: theme.background || theme.backgroundColor,
1774
1871
  background: theme.color
@@ -1790,9 +1887,7 @@ var SmblsScratch = (() => {
1790
1887
  const symb = param.slice(0, 1);
1791
1888
  if (isObjectLike(val[param])) {
1792
1889
  if (symb === "@") {
1793
- const query = CONFIG2.MEDIA[param.slice(1)];
1794
- const media = "@media " + (query === "print" ? `${query}` : `screen and ${query}`);
1795
- obj[media] = recursiveTheme(val[param]);
1890
+ continue;
1796
1891
  } else if (symb === ":") {
1797
1892
  obj[`&${param}`] = recursiveTheme(val[param]);
1798
1893
  }
@@ -1823,8 +1918,10 @@ var SmblsScratch = (() => {
1823
1918
  }
1824
1919
  const [themeName, ...themeModifiers] = isArray(value) ? value : value.split(" ");
1825
1920
  let themeValue = activeConfig.THEME[themeName];
1826
- if (themeValue && (themeModifiers || modifier)) {
1827
- themeValue = findModifier(themeValue, themeModifiers.length ? themeModifiers : modifier);
1921
+ if (themeValue && themeModifiers.length) {
1922
+ themeValue = findModifier(themeValue, themeModifiers);
1923
+ } else if (themeValue && modifier) {
1924
+ themeValue = findModifier(themeValue, modifier);
1828
1925
  }
1829
1926
  const resolvedTheme = recursiveTheme(themeValue);
1830
1927
  return resolvedTheme;
@@ -1832,22 +1929,25 @@ var SmblsScratch = (() => {
1832
1929
 
1833
1930
  // src/system/font.js
1834
1931
  var setFont = (val, key) => {
1932
+ const CONFIG2 = getActiveConfig();
1835
1933
  const CSSvar = `--font-${key}`;
1836
1934
  if (!val || isArray(val) && !val[0]) return;
1837
1935
  let fontFace;
1838
1936
  if (val.isVariable) {
1839
- if (isGoogleFontsUrl(val.url)) {
1840
- fontFace = setFontImport(val.url);
1937
+ const url = resolveFileUrl(val.url, CONFIG2.files) || val.url;
1938
+ if (isGoogleFontsUrl(url)) {
1939
+ fontFace = setFontImport(url);
1841
1940
  } else {
1842
- fontFace = setCustomFontMedia(key, val.url, val.fontWeight, {
1941
+ fontFace = setCustomFontMedia(key, url, val.fontWeight, {
1843
1942
  fontStretch: val.fontStretch,
1844
1943
  fontDisplay: val.fontDisplay || "swap"
1845
1944
  });
1846
1945
  }
1847
1946
  } else if (val[0]) {
1848
- fontFace = getFontFaceEach(key, val);
1947
+ fontFace = getFontFaceEach(key, val, CONFIG2.files);
1849
1948
  } else {
1850
- fontFace = setCustomFontMedia(key, val.url);
1949
+ const url = resolveFileUrl(val.url, CONFIG2.files) || val.url;
1950
+ fontFace = setCustomFontMedia(key, url);
1851
1951
  }
1852
1952
  return { var: CSSvar, value: val, fontFace };
1853
1953
  };
@@ -2237,7 +2337,7 @@ var SmblsScratch = (() => {
2237
2337
  const configReset = RESET2;
2238
2338
  const configTemplates = TYPOGRAPHY2.templates;
2239
2339
  configReset.body = {
2240
- ...CONFIG2.useDocumentTheme ? getMediaTheme("document", `@${CONFIG2.globalTheme}`) : {},
2340
+ ...CONFIG2.useDocumentTheme ? getMediaTheme("document") : {},
2241
2341
  ...configTemplates.body
2242
2342
  };
2243
2343
  configReset.h1 = configTemplates.h1;
@@ -2248,7 +2348,7 @@ var SmblsScratch = (() => {
2248
2348
  configReset.h6 = configTemplates.h6;
2249
2349
  }
2250
2350
  const { body, ...templates } = TYPOGRAPHY2.templates;
2251
- const globalTheme = CONFIG2.useDocumentTheme ? getMediaTheme("document", `@${CONFIG2.globalTheme}`) : {};
2351
+ const globalTheme = CONFIG2.useDocumentTheme ? getMediaTheme("document") : {};
2252
2352
  if (RESET2.html) overwriteDeep(RESET2.html, globalTheme);
2253
2353
  return deepMerge(merge(RESET2, reset), {
2254
2354
  html: {
@@ -2455,7 +2555,7 @@ var SmblsScratch = (() => {
2455
2555
  }
2456
2556
  const shouldScaleBoxSize = props.scaleBoxSize;
2457
2557
  const isBoxSize = checkIfBoxSize(propertyName);
2458
- if (!shouldScaleBoxSize && isBoxSize) {
2558
+ if (!shouldScaleBoxSize && isBoxSize && !opts.ratio) {
2459
2559
  value = splitSpacedValue(value);
2460
2560
  }
2461
2561
  }
@@ -2545,11 +2645,13 @@ var SmblsScratch = (() => {
2545
2645
  useDefaultConfig,
2546
2646
  SEMANTIC_ICONS: SEMANTIC_ICONS2,
2547
2647
  semantic_icons,
2648
+ files,
2548
2649
  ...config
2549
2650
  } = recivedConfig;
2550
2651
  if (options.newConfig) {
2551
2652
  CONFIG2 = setActiveConfig(options.newConfig);
2552
2653
  }
2654
+ if (files !== void 0) CONFIG2.files = files;
2553
2655
  if (verbose !== void 0) CONFIG2.verbose = verbose;
2554
2656
  if (useVariable !== void 0) CONFIG2.useVariable = useVariable;
2555
2657
  if (useReset !== void 0) CONFIG2.useReset = useReset;
@@ -2558,6 +2660,7 @@ var SmblsScratch = (() => {
2558
2660
  if (useIconSprite !== void 0) CONFIG2.useIconSprite = useIconSprite;
2559
2661
  if (useDocumentTheme !== void 0) CONFIG2.useDocumentTheme = useDocumentTheme;
2560
2662
  if (globalTheme !== void 0) CONFIG2.globalTheme = globalTheme;
2663
+ if (recivedConfig.useThemeSuffixedVars !== void 0) CONFIG2.useThemeSuffixedVars = recivedConfig.useThemeSuffixedVars;
2561
2664
  if (useDefaultConfig !== void 0) CONFIG2.useDefaultConfig = useDefaultConfig;
2562
2665
  const _semanticIcons = SEMANTIC_ICONS2 || semantic_icons;
2563
2666
  if (_semanticIcons !== void 0) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symbo.ls/scratch",
3
3
  "description": "Φ / CSS framework and methodology.",
4
4
  "author": "symbo.ls",
5
- "version": "3.5.1",
5
+ "version": "3.6.3",
6
6
  "files": [
7
7
  "dist",
8
8
  "*.js",
@@ -17,13 +17,13 @@
17
17
  "exports": {
18
18
  ".": {
19
19
  "import": "./dist/esm/index.js",
20
- "require": "./dist/cjs/index.js",
21
- "browser": "./dist/esm/index.js",
22
- "default": "./dist/esm/index.js"
20
+ "require": "./dist/cjs/index.js"
23
21
  }
24
22
  },
25
23
  "source": "src/index.js",
26
- "publishConfig": {},
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
27
  "scripts": {
28
28
  "copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
29
29
  "build:esm": "cross-env NODE_ENV=$NODE_ENV esbuild $(find src -name '*.js') --target=es2020 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
@@ -33,8 +33,8 @@
33
33
  "prepublish": "npm run build && npm run copy:package:cjs"
34
34
  },
35
35
  "dependencies": {
36
- "@domql/utils": "^3.5.1",
37
- "@symbo.ls/smbls-utils": "^3.5.1",
36
+ "@domql/utils": "^3.6.3",
37
+ "@symbo.ls/smbls-utils": "^3.6.3",
38
38
  "color-contrast-checker": "^1.5.0"
39
39
  },
40
40
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
package/src/factory.js CHANGED
@@ -9,9 +9,10 @@ import {
9
9
  import * as CONF from './defaultConfig'
10
10
 
11
11
  export const CSS_VARS = {}
12
+ export const CSS_MEDIA_VARS = {}
12
13
 
13
14
  // Build CONFIG with lowercase keys as canonical
14
- const _CONF = CONF.default || CONF
15
+ const _CONF = CONF
15
16
  const _confLower = {}
16
17
  for (const key in _CONF) {
17
18
  const lower = key.toLowerCase()
@@ -24,7 +25,9 @@ export const CONFIG = {
24
25
  verbose: false,
25
26
  useVariable: true,
26
27
  useReset: true,
28
+ globalTheme: 'auto',
27
29
  CSS_VARS,
30
+ CSS_MEDIA_VARS,
28
31
  ..._confLower
29
32
  }
30
33
 
package/src/set.js CHANGED
@@ -108,6 +108,7 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
108
108
  useDefaultConfig,
109
109
  SEMANTIC_ICONS,
110
110
  semantic_icons,
111
+ files,
111
112
  ...config
112
113
  } = recivedConfig
113
114
 
@@ -115,6 +116,7 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
115
116
  CONFIG = setActiveConfig(options.newConfig)
116
117
  }
117
118
 
119
+ if (files !== undefined) CONFIG.files = files
118
120
  if (verbose !== undefined) CONFIG.verbose = verbose
119
121
  if (useVariable !== undefined) CONFIG.useVariable = useVariable
120
122
  if (useReset !== undefined) CONFIG.useReset = useReset
@@ -123,6 +125,7 @@ export const set = (recivedConfig, options = SET_OPTIONS) => {
123
125
  if (useIconSprite !== undefined) CONFIG.useIconSprite = useIconSprite
124
126
  if (useDocumentTheme !== undefined) CONFIG.useDocumentTheme = useDocumentTheme
125
127
  if (globalTheme !== undefined) CONFIG.globalTheme = globalTheme
128
+ if (recivedConfig.useThemeSuffixedVars !== undefined) CONFIG.useThemeSuffixedVars = recivedConfig.useThemeSuffixedVars
126
129
  if (useDefaultConfig !== undefined) CONFIG.useDefaultConfig = useDefaultConfig
127
130
  const _semanticIcons = SEMANTIC_ICONS || semantic_icons
128
131
  if (_semanticIcons !== undefined) {
@@ -9,28 +9,32 @@ import {
9
9
  getFontFaceEach,
10
10
  isGoogleFontsUrl,
11
11
  setCustomFontMedia,
12
- setFontImport
12
+ setFontImport,
13
+ resolveFileUrl
13
14
  } from '../utils'
14
15
 
15
16
  export const setFont = (val, key) => {
17
+ const CONFIG = getActiveConfig()
16
18
  const CSSvar = `--font-${key}`
17
19
 
18
20
  if (!val || (isArray(val) && !val[0])) return
19
21
 
20
22
  let fontFace
21
23
  if (val.isVariable) {
22
- if (isGoogleFontsUrl(val.url)) {
23
- fontFace = setFontImport(val.url)
24
+ const url = resolveFileUrl(val.url, CONFIG.files) || val.url
25
+ if (isGoogleFontsUrl(url)) {
26
+ fontFace = setFontImport(url)
24
27
  } else {
25
- fontFace = setCustomFontMedia(key, val.url, val.fontWeight, {
28
+ fontFace = setCustomFontMedia(key, url, val.fontWeight, {
26
29
  fontStretch: val.fontStretch,
27
30
  fontDisplay: val.fontDisplay || 'swap'
28
31
  })
29
32
  }
30
33
  } else if (val[0]) {
31
- fontFace = getFontFaceEach(key, val)
34
+ fontFace = getFontFaceEach(key, val, CONFIG.files)
32
35
  } else {
33
- fontFace = setCustomFontMedia(key, val.url)
36
+ const url = resolveFileUrl(val.url, CONFIG.files) || val.url
37
+ fontFace = setCustomFontMedia(key, url)
34
38
  }
35
39
 
36
40
  return { var: CSSvar, value: val, fontFace }
@@ -16,7 +16,7 @@ export const applyReset = (reset = {}) => {
16
16
 
17
17
  configReset.body = {
18
18
  ...(CONFIG.useDocumentTheme
19
- ? getMediaTheme('document', `@${CONFIG.globalTheme}`)
19
+ ? getMediaTheme('document')
20
20
  : {}),
21
21
  ...configTemplates.body
22
22
  }
@@ -30,7 +30,7 @@ export const applyReset = (reset = {}) => {
30
30
 
31
31
  const { body, ...templates } = TYPOGRAPHY.templates
32
32
  const globalTheme = CONFIG.useDocumentTheme
33
- ? getMediaTheme('document', `@${CONFIG.globalTheme}`)
33
+ ? getMediaTheme('document')
34
34
  : {}
35
35
  if (RESET.html) overwriteDeep(RESET.html, globalTheme)
36
36