@symbo.ls/scratch 2.34.27 → 2.34.30

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.
@@ -26,8 +26,10 @@ __export(font_exports, {
26
26
  getFontFaceEachString: () => getFontFaceEachString,
27
27
  getFontFaceString: () => getFontFaceString,
28
28
  getFontFormat: () => getFontFormat,
29
+ isGoogleFontsUrl: () => isGoogleFontsUrl,
29
30
  setCustomFont: () => setCustomFont,
30
31
  setCustomFontMedia: () => setCustomFontMedia,
32
+ setFontImport: () => setFontImport,
31
33
  setInCustomFontMedia: () => setInCustomFontMedia
32
34
  });
33
35
  module.exports = __toCommonJS(font_exports);
@@ -37,15 +39,26 @@ var getDefaultOrFirstKey = (LIBRARY, key) => {
37
39
  const hasValue = Object.keys(LIBRARY)[0];
38
40
  return hasValue && LIBRARY[hasValue] && LIBRARY[hasValue].value;
39
41
  };
40
- var getFontFormat = (url) => url.split(/[#?]/)[0].split(".").pop().trim();
42
+ var getFontFormat = (url) => {
43
+ const ext = url.split(/[#?]/)[0].split(".").pop().trim();
44
+ if (["woff2", "woff", "ttf", "otf", "eot"].includes(ext)) return ext;
45
+ return null;
46
+ };
47
+ var isGoogleFontsUrl = (url) => url && (url.includes("fonts.googleapis.com") || url.includes("fonts.gstatic.com"));
48
+ var setFontImport = (url) => `@import url('${url}');`;
41
49
  var setInCustomFontMedia = (str) => `@font-face { ${str} }`;
42
- var setCustomFont = (name, url, weight) => `
50
+ var setCustomFont = (name, url, weight, options = {}) => {
51
+ const format = getFontFormat(url);
52
+ const formatStr = format ? ` format('${format}')` : "";
53
+ return `
43
54
  font-family: '${name}';
44
- font-style: normal;
45
- ${weight && `font-weight: ${weight};`}
46
- src: url('${url}') format('${getFontFormat(url)}');`;
47
- var setCustomFontMedia = (name, url, weight) => `@font-face {
48
- ${setCustomFont(name, url, weight)}
55
+ font-style: normal;${weight ? `
56
+ font-weight: ${weight};` : ""}${options.fontStretch ? `
57
+ font-stretch: ${options.fontStretch};` : ""}${options.fontDisplay ? `
58
+ font-display: ${options.fontDisplay};` : ""}
59
+ src: url('${url}')${formatStr};`;
60
+ };
61
+ var setCustomFontMedia = (name, url, weight, options) => `@font-face {${setCustomFont(name, url, weight, options)}
49
62
  }`;
50
63
  var getFontFaceEach = (name, weights) => {
51
64
  const keys = Object.keys(weights);
@@ -59,6 +72,15 @@ var getFontFace = (LIBRARY) => {
59
72
  return keys.map((key) => getFontFaceEach(key, LIBRARY[key].value));
60
73
  };
61
74
  var getFontFaceEachString = (name, weights) => {
75
+ if (weights && weights.isVariable) {
76
+ if (isGoogleFontsUrl(weights.url)) {
77
+ return setFontImport(weights.url);
78
+ }
79
+ return setCustomFontMedia(name, weights.url, weights.fontWeight, {
80
+ fontStretch: weights.fontStretch,
81
+ fontDisplay: weights.fontDisplay || "swap"
82
+ });
83
+ }
62
84
  const isArr = weights[0];
63
85
  if (isArr) return getFontFaceEach(name, weights).map(setInCustomFontMedia);
64
86
  return setCustomFontMedia(name, weights.url);
@@ -1710,6 +1710,46 @@ ${element}` : ""
1710
1710
  }
1711
1711
  return element;
1712
1712
  };
1713
+ function getRootState(param) {
1714
+ var _a, _b;
1715
+ let state2 = null;
1716
+ const hasRootState = (obj) => {
1717
+ var _a2;
1718
+ return obj.__element && ((_a2 = obj.root) == null ? void 0 : _a2.isRootState);
1719
+ };
1720
+ if (!this) {
1721
+ state2 = window.platformState || ((_a = window.smblsApp) == null ? void 0 : _a.state);
1722
+ } else if (hasRootState(this)) {
1723
+ state2 = this.root;
1724
+ } else if (this.__ref && this.__ref.path) {
1725
+ const hasPlatformState = this.state && hasRootState(this.state);
1726
+ const hasPlatformStateOnParent = this.call("isFunction", this.state) && this.parent.state && hasRootState(this.parent.state);
1727
+ if (hasPlatformState || hasPlatformStateOnParent) {
1728
+ state2 = this.state.root || this.parent.state.root;
1729
+ }
1730
+ }
1731
+ if (!state2) {
1732
+ state2 = window.platformState || ((_b = window.smblsApp) == null ? void 0 : _b.state);
1733
+ }
1734
+ return param ? state2[param] : state2;
1735
+ }
1736
+ function getRoot(key) {
1737
+ var _a;
1738
+ const rootElem = (_a = this.getRootState()) == null ? void 0 : _a.__element;
1739
+ return rootElem && Object.keys(rootElem).length > 0 && key ? rootElem[key] : rootElem;
1740
+ }
1741
+ function getRootData(key) {
1742
+ return this.getRoot("data") && Object.keys(this.getRoot("data")).length > 0 && key ? this.getRoot("data")[key] : this.getRoot("data");
1743
+ }
1744
+ function getRootContext(key) {
1745
+ var _a;
1746
+ const ctx = (_a = this.getRoot()) == null ? void 0 : _a.context;
1747
+ return key ? ctx[key] : ctx;
1748
+ }
1749
+ function getContext(key) {
1750
+ const ctx = this.context;
1751
+ return key ? ctx[key] : ctx;
1752
+ }
1713
1753
  var ROOT = {
1714
1754
  key: ":root",
1715
1755
  node: document22 ? document22.body : report("DocumentNotDefined", document22)
@@ -2000,6 +2040,11 @@ ${element}` : ""
2000
2040
  "getRef",
2001
2041
  "getChildren",
2002
2042
  "getPath",
2043
+ "getRootState",
2044
+ "getRoot",
2045
+ "getRootData",
2046
+ "getRootContext",
2047
+ "getContext",
2003
2048
  "setNodeStyles",
2004
2049
  "spotByPath",
2005
2050
  "keys",
@@ -3118,6 +3163,11 @@ ${element}` : ""
3118
3163
  lookdown,
3119
3164
  lookdownAll,
3120
3165
  getRef,
3166
+ getRootState,
3167
+ getRoot,
3168
+ getRootData,
3169
+ getRootContext,
3170
+ getContext,
3121
3171
  getPath,
3122
3172
  setNodeStyles,
3123
3173
  spotByPath,
@@ -3995,6 +4045,7 @@ __export(utils_exports, {
3995
4045
  hexToRgbArray: () => hexToRgbArray,
3996
4046
  hexToRgba: () => hexToRgba,
3997
4047
  hslToRgb: () => hslToRgb,
4048
+ isGoogleFontsUrl: () => isGoogleFontsUrl,
3998
4049
  isScalingUnit: () => isScalingUnit,
3999
4050
  mixTwoColors: () => mixTwoColors,
4000
4051
  mixTwoRgb: () => mixTwoRgb,
@@ -4007,6 +4058,7 @@ __export(utils_exports, {
4007
4058
  rgbToHex: () => rgbToHex,
4008
4059
  setCustomFont: () => setCustomFont,
4009
4060
  setCustomFontMedia: () => setCustomFontMedia,
4061
+ setFontImport: () => setFontImport,
4010
4062
  setInCustomFontMedia: () => setInCustomFontMedia,
4011
4063
  setScalingVar: () => setScalingVar,
4012
4064
  setSubScalingVar: () => setSubScalingVar,
@@ -4335,15 +4387,26 @@ var getDefaultOrFirstKey = (LIBRARY, key) => {
4335
4387
  const hasValue = Object.keys(LIBRARY)[0];
4336
4388
  return hasValue && LIBRARY[hasValue] && LIBRARY[hasValue].value;
4337
4389
  };
4338
- var getFontFormat = (url) => url.split(/[#?]/)[0].split(".").pop().trim();
4390
+ var getFontFormat = (url) => {
4391
+ const ext = url.split(/[#?]/)[0].split(".").pop().trim();
4392
+ if (["woff2", "woff", "ttf", "otf", "eot"].includes(ext)) return ext;
4393
+ return null;
4394
+ };
4395
+ var isGoogleFontsUrl = (url) => url && (url.includes("fonts.googleapis.com") || url.includes("fonts.gstatic.com"));
4396
+ var setFontImport = (url) => `@import url('${url}');`;
4339
4397
  var setInCustomFontMedia = (str) => `@font-face { ${str} }`;
4340
- var setCustomFont = (name, url, weight) => `
4398
+ var setCustomFont = (name, url, weight, options = {}) => {
4399
+ const format = getFontFormat(url);
4400
+ const formatStr = format ? ` format('${format}')` : "";
4401
+ return `
4341
4402
  font-family: '${name}';
4342
- font-style: normal;
4343
- ${weight && `font-weight: ${weight};`}
4344
- src: url('${url}') format('${getFontFormat(url)}');`;
4345
- var setCustomFontMedia = (name, url, weight) => `@font-face {
4346
- ${setCustomFont(name, url, weight)}
4403
+ font-style: normal;${weight ? `
4404
+ font-weight: ${weight};` : ""}${options.fontStretch ? `
4405
+ font-stretch: ${options.fontStretch};` : ""}${options.fontDisplay ? `
4406
+ font-display: ${options.fontDisplay};` : ""}
4407
+ src: url('${url}')${formatStr};`;
4408
+ };
4409
+ var setCustomFontMedia = (name, url, weight, options) => `@font-face {${setCustomFont(name, url, weight, options)}
4347
4410
  }`;
4348
4411
  var getFontFaceEach = (name, weights) => {
4349
4412
  const keys = Object.keys(weights);
@@ -4357,6 +4420,15 @@ var getFontFace = (LIBRARY) => {
4357
4420
  return keys.map((key) => getFontFaceEach(key, LIBRARY[key].value));
4358
4421
  };
4359
4422
  var getFontFaceEachString = (name, weights) => {
4423
+ if (weights && weights.isVariable) {
4424
+ if (isGoogleFontsUrl(weights.url)) {
4425
+ return setFontImport(weights.url);
4426
+ }
4427
+ return setCustomFontMedia(name, weights.url, weights.fontWeight, {
4428
+ fontStretch: weights.fontStretch,
4429
+ fontDisplay: weights.fontDisplay || "swap"
4430
+ });
4431
+ }
4360
4432
  const isArr = weights[0];
4361
4433
  if (isArr) return getFontFaceEach(name, weights).map(setInCustomFontMedia);
4362
4434
  return setCustomFontMedia(name, weights.url);
@@ -1710,6 +1710,46 @@ ${element}` : ""
1710
1710
  }
1711
1711
  return element;
1712
1712
  };
1713
+ function getRootState(param) {
1714
+ var _a, _b;
1715
+ let state2 = null;
1716
+ const hasRootState = (obj) => {
1717
+ var _a2;
1718
+ return obj.__element && ((_a2 = obj.root) == null ? void 0 : _a2.isRootState);
1719
+ };
1720
+ if (!this) {
1721
+ state2 = window.platformState || ((_a = window.smblsApp) == null ? void 0 : _a.state);
1722
+ } else if (hasRootState(this)) {
1723
+ state2 = this.root;
1724
+ } else if (this.__ref && this.__ref.path) {
1725
+ const hasPlatformState = this.state && hasRootState(this.state);
1726
+ const hasPlatformStateOnParent = this.call("isFunction", this.state) && this.parent.state && hasRootState(this.parent.state);
1727
+ if (hasPlatformState || hasPlatformStateOnParent) {
1728
+ state2 = this.state.root || this.parent.state.root;
1729
+ }
1730
+ }
1731
+ if (!state2) {
1732
+ state2 = window.platformState || ((_b = window.smblsApp) == null ? void 0 : _b.state);
1733
+ }
1734
+ return param ? state2[param] : state2;
1735
+ }
1736
+ function getRoot(key) {
1737
+ var _a;
1738
+ const rootElem = (_a = this.getRootState()) == null ? void 0 : _a.__element;
1739
+ return rootElem && Object.keys(rootElem).length > 0 && key ? rootElem[key] : rootElem;
1740
+ }
1741
+ function getRootData(key) {
1742
+ return this.getRoot("data") && Object.keys(this.getRoot("data")).length > 0 && key ? this.getRoot("data")[key] : this.getRoot("data");
1743
+ }
1744
+ function getRootContext(key) {
1745
+ var _a;
1746
+ const ctx = (_a = this.getRoot()) == null ? void 0 : _a.context;
1747
+ return key ? ctx[key] : ctx;
1748
+ }
1749
+ function getContext(key) {
1750
+ const ctx = this.context;
1751
+ return key ? ctx[key] : ctx;
1752
+ }
1713
1753
  var ROOT = {
1714
1754
  key: ":root",
1715
1755
  node: document22 ? document22.body : report("DocumentNotDefined", document22)
@@ -2000,6 +2040,11 @@ ${element}` : ""
2000
2040
  "getRef",
2001
2041
  "getChildren",
2002
2042
  "getPath",
2043
+ "getRootState",
2044
+ "getRoot",
2045
+ "getRootData",
2046
+ "getRootContext",
2047
+ "getContext",
2003
2048
  "setNodeStyles",
2004
2049
  "spotByPath",
2005
2050
  "keys",
@@ -3118,6 +3163,11 @@ ${element}` : ""
3118
3163
  lookdown,
3119
3164
  lookdownAll,
3120
3165
  getRef,
3166
+ getRootState,
3167
+ getRoot,
3168
+ getRootData,
3169
+ getRootContext,
3170
+ getContext,
3121
3171
  getPath,
3122
3172
  setNodeStyles,
3123
3173
  spotByPath,
@@ -1710,6 +1710,46 @@ ${element}` : ""
1710
1710
  }
1711
1711
  return element;
1712
1712
  };
1713
+ function getRootState(param) {
1714
+ var _a, _b;
1715
+ let state2 = null;
1716
+ const hasRootState = (obj) => {
1717
+ var _a2;
1718
+ return obj.__element && ((_a2 = obj.root) == null ? void 0 : _a2.isRootState);
1719
+ };
1720
+ if (!this) {
1721
+ state2 = window.platformState || ((_a = window.smblsApp) == null ? void 0 : _a.state);
1722
+ } else if (hasRootState(this)) {
1723
+ state2 = this.root;
1724
+ } else if (this.__ref && this.__ref.path) {
1725
+ const hasPlatformState = this.state && hasRootState(this.state);
1726
+ const hasPlatformStateOnParent = this.call("isFunction", this.state) && this.parent.state && hasRootState(this.parent.state);
1727
+ if (hasPlatformState || hasPlatformStateOnParent) {
1728
+ state2 = this.state.root || this.parent.state.root;
1729
+ }
1730
+ }
1731
+ if (!state2) {
1732
+ state2 = window.platformState || ((_b = window.smblsApp) == null ? void 0 : _b.state);
1733
+ }
1734
+ return param ? state2[param] : state2;
1735
+ }
1736
+ function getRoot(key) {
1737
+ var _a;
1738
+ const rootElem = (_a = this.getRootState()) == null ? void 0 : _a.__element;
1739
+ return rootElem && Object.keys(rootElem).length > 0 && key ? rootElem[key] : rootElem;
1740
+ }
1741
+ function getRootData(key) {
1742
+ return this.getRoot("data") && Object.keys(this.getRoot("data")).length > 0 && key ? this.getRoot("data")[key] : this.getRoot("data");
1743
+ }
1744
+ function getRootContext(key) {
1745
+ var _a;
1746
+ const ctx = (_a = this.getRoot()) == null ? void 0 : _a.context;
1747
+ return key ? ctx[key] : ctx;
1748
+ }
1749
+ function getContext(key) {
1750
+ const ctx = this.context;
1751
+ return key ? ctx[key] : ctx;
1752
+ }
1713
1753
  var ROOT = {
1714
1754
  key: ":root",
1715
1755
  node: document22 ? document22.body : report("DocumentNotDefined", document22)
@@ -2000,6 +2040,11 @@ ${element}` : ""
2000
2040
  "getRef",
2001
2041
  "getChildren",
2002
2042
  "getPath",
2043
+ "getRootState",
2044
+ "getRoot",
2045
+ "getRootData",
2046
+ "getRootContext",
2047
+ "getContext",
2003
2048
  "setNodeStyles",
2004
2049
  "spotByPath",
2005
2050
  "keys",
@@ -3118,6 +3163,11 @@ ${element}` : ""
3118
3163
  lookdown,
3119
3164
  lookdownAll,
3120
3165
  getRef,
3166
+ getRootState,
3167
+ getRoot,
3168
+ getRootData,
3169
+ getRootContext,
3170
+ getContext,
3121
3171
  getPath,
3122
3172
  setNodeStyles,
3123
3173
  spotByPath,
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": "2.34.27",
5
+ "version": "2.34.30",
6
6
  "files": [
7
7
  "src",
8
8
  "dist"
@@ -25,9 +25,9 @@
25
25
  "prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
26
26
  },
27
27
  "dependencies": {
28
- "@domql/utils": "^2.34.27",
29
- "@symbo.ls/utils": "^2.34.27",
28
+ "@domql/utils": "^2.34.30",
29
+ "@symbo.ls/utils": "^2.34.30",
30
30
  "color-contrast-checker": "^1.5.0"
31
31
  },
32
- "gitHead": "1994ef5ac77cba0564a416c60e9d0a984543d9af"
32
+ "gitHead": "e8c2af04ccfbe5521b5a2d5473b6e5236954edba"
33
33
  }
@@ -7,7 +7,9 @@ import { getActiveConfig } from '../factory.js'
7
7
  import {
8
8
  getDefaultOrFirstKey,
9
9
  getFontFaceEach,
10
- setCustomFontMedia
10
+ isGoogleFontsUrl,
11
+ setCustomFontMedia,
12
+ setFontImport
11
13
  } from '../utils'
12
14
 
13
15
  export const setFont = (val, key) => {
@@ -15,9 +17,21 @@ export const setFont = (val, key) => {
15
17
 
16
18
  if (!val || (isArray(val) && !val[0])) return
17
19
 
18
- const fontFace = val[0]
19
- ? getFontFaceEach(key, val)
20
- : setCustomFontMedia(key, val.url)
20
+ let fontFace
21
+ if (val.isVariable) {
22
+ if (isGoogleFontsUrl(val.url)) {
23
+ fontFace = setFontImport(val.url)
24
+ } else {
25
+ fontFace = setCustomFontMedia(key, val.url, val.fontWeight, {
26
+ fontStretch: val.fontStretch,
27
+ fontDisplay: val.fontDisplay || 'swap'
28
+ })
29
+ }
30
+ } else if (val[0]) {
31
+ fontFace = getFontFaceEach(key, val)
32
+ } else {
33
+ fontFace = setCustomFontMedia(key, val.url)
34
+ }
21
35
 
22
36
  return { var: CSSvar, value: val, fontFace }
23
37
  }
package/src/utils/font.js CHANGED
@@ -7,41 +7,81 @@ export const getDefaultOrFirstKey = (LIBRARY, key) => {
7
7
  return hasValue && LIBRARY[hasValue] && LIBRARY[hasValue].value
8
8
  }
9
9
 
10
- export const getFontFormat = url => url.split(/[#?]/)[0].split('.').pop().trim()
10
+ export const getFontFormat = (url) => {
11
+ const ext = url.split(/[#?]/)[0].split('.').pop().trim()
12
+ if (['woff2', 'woff', 'ttf', 'otf', 'eot'].includes(ext)) return ext
13
+ return null
14
+ }
15
+
16
+ export const isGoogleFontsUrl = (url) =>
17
+ url &&
18
+ (url.includes('fonts.googleapis.com') || url.includes('fonts.gstatic.com'))
11
19
 
12
- export const setInCustomFontMedia = str => `@font-face { ${str} }`
20
+ export const setFontImport = (url) => `@import url('${url}');`
13
21
 
14
- export const setCustomFont = (name, url, weight) => `
22
+ export const setInCustomFontMedia = (str) => `@font-face { ${str} }`
23
+
24
+ export const setCustomFont = (name, url, weight, options = {}) => {
25
+ const format = getFontFormat(url)
26
+ const formatStr = format ? ` format('${format}')` : ''
27
+ return `
15
28
  font-family: '${name}';
16
- font-style: normal;
17
- ${weight && `font-weight: ${weight};`}
18
- src: url('${url}') format('${getFontFormat(url)}');`
29
+ font-style: normal;${
30
+ weight
31
+ ? `
32
+ font-weight: ${weight};`
33
+ : ''
34
+ }${
35
+ options.fontStretch
36
+ ? `
37
+ font-stretch: ${options.fontStretch};`
38
+ : ''
39
+ }${
40
+ options.fontDisplay
41
+ ? `
42
+ font-display: ${options.fontDisplay};`
43
+ : ''
44
+ }
45
+ src: url('${url}')${formatStr};`
46
+ }
19
47
 
20
- export const setCustomFontMedia = (name, url, weight) => `@font-face {
21
- ${setCustomFont(name, url, weight)}
48
+ export const setCustomFontMedia = (
49
+ name,
50
+ url,
51
+ weight,
52
+ options
53
+ ) => `@font-face {${setCustomFont(name, url, weight, options)}
22
54
  }`
23
- // src: url('${url}') format('${getFontFormat(url)}');
24
55
 
25
56
  export const getFontFaceEach = (name, weights) => {
26
57
  const keys = Object.keys(weights)
27
- return keys.map(key => {
58
+ return keys.map((key) => {
28
59
  const { url, fontWeight } = weights[key]
29
60
  return setCustomFont(name, url, fontWeight)
30
61
  })
31
62
  }
32
63
 
33
- export const getFontFace = LIBRARY => {
64
+ export const getFontFace = (LIBRARY) => {
34
65
  const keys = Object.keys(LIBRARY)
35
- return keys.map(key => getFontFaceEach(key, LIBRARY[key].value))
66
+ return keys.map((key) => getFontFaceEach(key, LIBRARY[key].value))
36
67
  }
37
68
 
38
69
  export const getFontFaceEachString = (name, weights) => {
70
+ if (weights && weights.isVariable) {
71
+ if (isGoogleFontsUrl(weights.url)) {
72
+ return setFontImport(weights.url)
73
+ }
74
+ return setCustomFontMedia(name, weights.url, weights.fontWeight, {
75
+ fontStretch: weights.fontStretch,
76
+ fontDisplay: weights.fontDisplay || 'swap'
77
+ })
78
+ }
39
79
  const isArr = weights[0]
40
80
  if (isArr) return getFontFaceEach(name, weights).map(setInCustomFontMedia)
41
81
  return setCustomFontMedia(name, weights.url)
42
82
  }
43
83
 
44
- export const getFontFaceString = LIBRARY => {
84
+ export const getFontFaceString = (LIBRARY) => {
45
85
  const keys = Object.keys(LIBRARY)
46
- return keys.map(key => getFontFaceEachString(key, LIBRARY[key].value))
86
+ return keys.map((key) => getFontFaceEachString(key, LIBRARY[key].value))
47
87
  }