@symbo.ls/scratch 2.34.29 → 2.34.31

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.
package/dist/cjs/index.js CHANGED
@@ -4098,6 +4098,7 @@ __export(index_exports, {
4098
4098
  hexToRgbArray: () => hexToRgbArray,
4099
4099
  hexToRgba: () => hexToRgba,
4100
4100
  hslToRgb: () => hslToRgb,
4101
+ isGoogleFontsUrl: () => isGoogleFontsUrl,
4101
4102
  isScalingUnit: () => isScalingUnit,
4102
4103
  mixTwoColors: () => mixTwoColors,
4103
4104
  mixTwoRgb: () => mixTwoRgb,
@@ -4119,6 +4120,7 @@ __export(index_exports, {
4119
4120
  setEach: () => setEach,
4120
4121
  setFont: () => setFont,
4121
4122
  setFontFamily: () => setFontFamily,
4123
+ setFontImport: () => setFontImport,
4122
4124
  setGradient: () => setGradient,
4123
4125
  setInCustomFontMedia: () => setInCustomFontMedia,
4124
4126
  setMediaTheme: () => setMediaTheme,
@@ -4179,6 +4181,7 @@ __export(utils_exports, {
4179
4181
  hexToRgbArray: () => hexToRgbArray,
4180
4182
  hexToRgba: () => hexToRgba,
4181
4183
  hslToRgb: () => hslToRgb,
4184
+ isGoogleFontsUrl: () => isGoogleFontsUrl,
4182
4185
  isScalingUnit: () => isScalingUnit,
4183
4186
  mixTwoColors: () => mixTwoColors,
4184
4187
  mixTwoRgb: () => mixTwoRgb,
@@ -4191,6 +4194,7 @@ __export(utils_exports, {
4191
4194
  rgbToHex: () => rgbToHex,
4192
4195
  setCustomFont: () => setCustomFont,
4193
4196
  setCustomFontMedia: () => setCustomFontMedia,
4197
+ setFontImport: () => setFontImport,
4194
4198
  setInCustomFontMedia: () => setInCustomFontMedia,
4195
4199
  setScalingVar: () => setScalingVar,
4196
4200
  setSubScalingVar: () => setSubScalingVar,
@@ -4584,15 +4588,26 @@ var getDefaultOrFirstKey = (LIBRARY, key) => {
4584
4588
  const hasValue = Object.keys(LIBRARY)[0];
4585
4589
  return hasValue && LIBRARY[hasValue] && LIBRARY[hasValue].value;
4586
4590
  };
4587
- var getFontFormat = (url) => url.split(/[#?]/)[0].split(".").pop().trim();
4591
+ var getFontFormat = (url) => {
4592
+ const ext = url.split(/[#?]/)[0].split(".").pop().trim();
4593
+ if (["woff2", "woff", "ttf", "otf", "eot"].includes(ext)) return ext;
4594
+ return null;
4595
+ };
4596
+ var isGoogleFontsUrl = (url) => url && (url.includes("fonts.googleapis.com") || url.includes("fonts.gstatic.com"));
4597
+ var setFontImport = (url) => `@import url('${url}');`;
4588
4598
  var setInCustomFontMedia = (str) => `@font-face { ${str} }`;
4589
- var setCustomFont = (name, url, weight) => `
4599
+ var setCustomFont = (name, url, weight, options = {}) => {
4600
+ const format = getFontFormat(url);
4601
+ const formatStr = format ? ` format('${format}')` : "";
4602
+ return `
4590
4603
  font-family: '${name}';
4591
- font-style: normal;
4592
- ${weight && `font-weight: ${weight};`}
4593
- src: url('${url}') format('${getFontFormat(url)}');`;
4594
- var setCustomFontMedia = (name, url, weight) => `@font-face {
4595
- ${setCustomFont(name, url, weight)}
4604
+ font-style: normal;${weight ? `
4605
+ font-weight: ${weight};` : ""}${options.fontStretch ? `
4606
+ font-stretch: ${options.fontStretch};` : ""}${options.fontDisplay ? `
4607
+ font-display: ${options.fontDisplay};` : ""}
4608
+ src: url('${url}')${formatStr};`;
4609
+ };
4610
+ var setCustomFontMedia = (name, url, weight, options) => `@font-face {${setCustomFont(name, url, weight, options)}
4596
4611
  }`;
4597
4612
  var getFontFaceEach = (name, weights) => {
4598
4613
  const keys = Object.keys(weights);
@@ -4606,6 +4621,15 @@ var getFontFace = (LIBRARY) => {
4606
4621
  return keys.map((key) => getFontFaceEach(key, LIBRARY[key].value));
4607
4622
  };
4608
4623
  var getFontFaceEachString = (name, weights) => {
4624
+ if (weights && weights.isVariable) {
4625
+ if (isGoogleFontsUrl(weights.url)) {
4626
+ return setFontImport(weights.url);
4627
+ }
4628
+ return setCustomFontMedia(name, weights.url, weights.fontWeight, {
4629
+ fontStretch: weights.fontStretch,
4630
+ fontDisplay: weights.fontDisplay || "swap"
4631
+ });
4632
+ }
4609
4633
  const isArr = weights[0];
4610
4634
  if (isArr) return getFontFaceEach(name, weights).map(setInCustomFontMedia);
4611
4635
  return setCustomFontMedia(name, weights.url);
@@ -5634,7 +5658,21 @@ var import_utils11 = __toESM(require_cjs(), 1);
5634
5658
  var setFont = (val, key) => {
5635
5659
  const CSSvar = `--font-${key}`;
5636
5660
  if (!val || isArray(val) && !val[0]) return;
5637
- const fontFace = val[0] ? getFontFaceEach(key, val) : setCustomFontMedia(key, val.url);
5661
+ let fontFace;
5662
+ if (val.isVariable) {
5663
+ if (isGoogleFontsUrl(val.url)) {
5664
+ fontFace = setFontImport(val.url);
5665
+ } else {
5666
+ fontFace = setCustomFontMedia(key, val.url, val.fontWeight, {
5667
+ fontStretch: val.fontStretch,
5668
+ fontDisplay: val.fontDisplay || "swap"
5669
+ });
5670
+ }
5671
+ } else if (val[0]) {
5672
+ fontFace = getFontFaceEach(key, val);
5673
+ } else {
5674
+ fontFace = setCustomFontMedia(key, val.url);
5675
+ }
5638
5676
  return { var: CSSvar, value: val, fontFace };
5639
5677
  };
5640
5678
  var getFontFamily = (key, factory) => {
package/dist/cjs/set.js CHANGED
@@ -4556,14 +4556,25 @@ var getDefaultOrFirstKey = (LIBRARY, key) => {
4556
4556
  const hasValue = Object.keys(LIBRARY)[0];
4557
4557
  return hasValue && LIBRARY[hasValue] && LIBRARY[hasValue].value;
4558
4558
  };
4559
- var getFontFormat = (url) => url.split(/[#?]/)[0].split(".").pop().trim();
4560
- var setCustomFont = (name, url, weight) => `
4559
+ var getFontFormat = (url) => {
4560
+ const ext = url.split(/[#?]/)[0].split(".").pop().trim();
4561
+ if (["woff2", "woff", "ttf", "otf", "eot"].includes(ext)) return ext;
4562
+ return null;
4563
+ };
4564
+ var isGoogleFontsUrl = (url) => url && (url.includes("fonts.googleapis.com") || url.includes("fonts.gstatic.com"));
4565
+ var setFontImport = (url) => `@import url('${url}');`;
4566
+ var setCustomFont = (name, url, weight, options = {}) => {
4567
+ const format = getFontFormat(url);
4568
+ const formatStr = format ? ` format('${format}')` : "";
4569
+ return `
4561
4570
  font-family: '${name}';
4562
- font-style: normal;
4563
- ${weight && `font-weight: ${weight};`}
4564
- src: url('${url}') format('${getFontFormat(url)}');`;
4565
- var setCustomFontMedia = (name, url, weight) => `@font-face {
4566
- ${setCustomFont(name, url, weight)}
4571
+ font-style: normal;${weight ? `
4572
+ font-weight: ${weight};` : ""}${options.fontStretch ? `
4573
+ font-stretch: ${options.fontStretch};` : ""}${options.fontDisplay ? `
4574
+ font-display: ${options.fontDisplay};` : ""}
4575
+ src: url('${url}')${formatStr};`;
4576
+ };
4577
+ var setCustomFontMedia = (name, url, weight, options) => `@font-face {${setCustomFont(name, url, weight, options)}
4567
4578
  }`;
4568
4579
  var getFontFaceEach = (name, weights) => {
4569
4580
  const keys = Object.keys(weights);
@@ -5236,7 +5247,21 @@ var import_utils11 = __toESM(require_cjs(), 1);
5236
5247
  var setFont = (val, key) => {
5237
5248
  const CSSvar = `--font-${key}`;
5238
5249
  if (!val || isArray(val) && !val[0]) return;
5239
- const fontFace = val[0] ? getFontFaceEach(key, val) : setCustomFontMedia(key, val.url);
5250
+ let fontFace;
5251
+ if (val.isVariable) {
5252
+ if (isGoogleFontsUrl(val.url)) {
5253
+ fontFace = setFontImport(val.url);
5254
+ } else {
5255
+ fontFace = setCustomFontMedia(key, val.url, val.fontWeight, {
5256
+ fontStretch: val.fontStretch,
5257
+ fontDisplay: val.fontDisplay || "swap"
5258
+ });
5259
+ }
5260
+ } else if (val[0]) {
5261
+ fontFace = getFontFaceEach(key, val);
5262
+ } else {
5263
+ fontFace = setCustomFontMedia(key, val.url);
5264
+ }
5240
5265
  return { var: CSSvar, value: val, fontFace };
5241
5266
  };
5242
5267
  var setFontFamily = (val, key) => {
@@ -4371,14 +4371,25 @@ var getDefaultOrFirstKey = (LIBRARY, key) => {
4371
4371
  const hasValue = Object.keys(LIBRARY)[0];
4372
4372
  return hasValue && LIBRARY[hasValue] && LIBRARY[hasValue].value;
4373
4373
  };
4374
- var getFontFormat = (url) => url.split(/[#?]/)[0].split(".").pop().trim();
4375
- var setCustomFont = (name, url, weight) => `
4374
+ var getFontFormat = (url) => {
4375
+ const ext = url.split(/[#?]/)[0].split(".").pop().trim();
4376
+ if (["woff2", "woff", "ttf", "otf", "eot"].includes(ext)) return ext;
4377
+ return null;
4378
+ };
4379
+ var isGoogleFontsUrl = (url) => url && (url.includes("fonts.googleapis.com") || url.includes("fonts.gstatic.com"));
4380
+ var setFontImport = (url) => `@import url('${url}');`;
4381
+ var setCustomFont = (name, url, weight, options = {}) => {
4382
+ const format = getFontFormat(url);
4383
+ const formatStr = format ? ` format('${format}')` : "";
4384
+ return `
4376
4385
  font-family: '${name}';
4377
- font-style: normal;
4378
- ${weight && `font-weight: ${weight};`}
4379
- src: url('${url}') format('${getFontFormat(url)}');`;
4380
- var setCustomFontMedia = (name, url, weight) => `@font-face {
4381
- ${setCustomFont(name, url, weight)}
4386
+ font-style: normal;${weight ? `
4387
+ font-weight: ${weight};` : ""}${options.fontStretch ? `
4388
+ font-stretch: ${options.fontStretch};` : ""}${options.fontDisplay ? `
4389
+ font-display: ${options.fontDisplay};` : ""}
4390
+ src: url('${url}')${formatStr};`;
4391
+ };
4392
+ var setCustomFontMedia = (name, url, weight, options) => `@font-face {${setCustomFont(name, url, weight, options)}
4382
4393
  }`;
4383
4394
  var getFontFaceEach = (name, weights) => {
4384
4395
  const keys = Object.keys(weights);
@@ -4398,7 +4409,21 @@ var isDev = isNotProduction();
4398
4409
  var setFont = (val, key) => {
4399
4410
  const CSSvar = `--font-${key}`;
4400
4411
  if (!val || isArray(val) && !val[0]) return;
4401
- const fontFace = val[0] ? getFontFaceEach(key, val) : setCustomFontMedia(key, val.url);
4412
+ let fontFace;
4413
+ if (val.isVariable) {
4414
+ if (isGoogleFontsUrl(val.url)) {
4415
+ fontFace = setFontImport(val.url);
4416
+ } else {
4417
+ fontFace = setCustomFontMedia(key, val.url, val.fontWeight, {
4418
+ fontStretch: val.fontStretch,
4419
+ fontDisplay: val.fontDisplay || "swap"
4420
+ });
4421
+ }
4422
+ } else if (val[0]) {
4423
+ fontFace = getFontFaceEach(key, val);
4424
+ } else {
4425
+ fontFace = setCustomFontMedia(key, val.url);
4426
+ }
4402
4427
  return { var: CSSvar, value: val, fontFace };
4403
4428
  };
4404
4429
  var getFontFamily = (key, factory) => {
@@ -4577,14 +4577,25 @@ var getDefaultOrFirstKey = (LIBRARY, key) => {
4577
4577
  const hasValue = Object.keys(LIBRARY)[0];
4578
4578
  return hasValue && LIBRARY[hasValue] && LIBRARY[hasValue].value;
4579
4579
  };
4580
- var getFontFormat = (url) => url.split(/[#?]/)[0].split(".").pop().trim();
4581
- var setCustomFont = (name, url, weight) => `
4580
+ var getFontFormat = (url) => {
4581
+ const ext = url.split(/[#?]/)[0].split(".").pop().trim();
4582
+ if (["woff2", "woff", "ttf", "otf", "eot"].includes(ext)) return ext;
4583
+ return null;
4584
+ };
4585
+ var isGoogleFontsUrl = (url) => url && (url.includes("fonts.googleapis.com") || url.includes("fonts.gstatic.com"));
4586
+ var setFontImport = (url) => `@import url('${url}');`;
4587
+ var setCustomFont = (name, url, weight, options = {}) => {
4588
+ const format = getFontFormat(url);
4589
+ const formatStr = format ? ` format('${format}')` : "";
4590
+ return `
4582
4591
  font-family: '${name}';
4583
- font-style: normal;
4584
- ${weight && `font-weight: ${weight};`}
4585
- src: url('${url}') format('${getFontFormat(url)}');`;
4586
- var setCustomFontMedia = (name, url, weight) => `@font-face {
4587
- ${setCustomFont(name, url, weight)}
4592
+ font-style: normal;${weight ? `
4593
+ font-weight: ${weight};` : ""}${options.fontStretch ? `
4594
+ font-stretch: ${options.fontStretch};` : ""}${options.fontDisplay ? `
4595
+ font-display: ${options.fontDisplay};` : ""}
4596
+ src: url('${url}')${formatStr};`;
4597
+ };
4598
+ var setCustomFontMedia = (name, url, weight, options) => `@font-face {${setCustomFont(name, url, weight, options)}
4588
4599
  }`;
4589
4600
  var getFontFaceEach = (name, weights) => {
4590
4601
  const keys = Object.keys(weights);
@@ -5296,7 +5307,21 @@ var import_utils11 = __toESM(require_cjs(), 1);
5296
5307
  var setFont = (val, key) => {
5297
5308
  const CSSvar = `--font-${key}`;
5298
5309
  if (!val || isArray(val) && !val[0]) return;
5299
- const fontFace = val[0] ? getFontFaceEach(key, val) : setCustomFontMedia(key, val.url);
5310
+ let fontFace;
5311
+ if (val.isVariable) {
5312
+ if (isGoogleFontsUrl(val.url)) {
5313
+ fontFace = setFontImport(val.url);
5314
+ } else {
5315
+ fontFace = setCustomFontMedia(key, val.url, val.fontWeight, {
5316
+ fontStretch: val.fontStretch,
5317
+ fontDisplay: val.fontDisplay || "swap"
5318
+ });
5319
+ }
5320
+ } else if (val[0]) {
5321
+ fontFace = getFontFaceEach(key, val);
5322
+ } else {
5323
+ fontFace = setCustomFontMedia(key, val.url);
5324
+ }
5300
5325
  return { var: CSSvar, value: val, fontFace };
5301
5326
  };
5302
5327
  var getFontFamily = (key, factory) => {
@@ -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);
@@ -4045,6 +4045,7 @@ __export(utils_exports, {
4045
4045
  hexToRgbArray: () => hexToRgbArray,
4046
4046
  hexToRgba: () => hexToRgba,
4047
4047
  hslToRgb: () => hslToRgb,
4048
+ isGoogleFontsUrl: () => isGoogleFontsUrl,
4048
4049
  isScalingUnit: () => isScalingUnit,
4049
4050
  mixTwoColors: () => mixTwoColors,
4050
4051
  mixTwoRgb: () => mixTwoRgb,
@@ -4057,6 +4058,7 @@ __export(utils_exports, {
4057
4058
  rgbToHex: () => rgbToHex,
4058
4059
  setCustomFont: () => setCustomFont,
4059
4060
  setCustomFontMedia: () => setCustomFontMedia,
4061
+ setFontImport: () => setFontImport,
4060
4062
  setInCustomFontMedia: () => setInCustomFontMedia,
4061
4063
  setScalingVar: () => setScalingVar,
4062
4064
  setSubScalingVar: () => setSubScalingVar,
@@ -4385,15 +4387,26 @@ var getDefaultOrFirstKey = (LIBRARY, key) => {
4385
4387
  const hasValue = Object.keys(LIBRARY)[0];
4386
4388
  return hasValue && LIBRARY[hasValue] && LIBRARY[hasValue].value;
4387
4389
  };
4388
- 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}');`;
4389
4397
  var setInCustomFontMedia = (str) => `@font-face { ${str} }`;
4390
- 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 `
4391
4402
  font-family: '${name}';
4392
- font-style: normal;
4393
- ${weight && `font-weight: ${weight};`}
4394
- src: url('${url}') format('${getFontFormat(url)}');`;
4395
- var setCustomFontMedia = (name, url, weight) => `@font-face {
4396
- ${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)}
4397
4410
  }`;
4398
4411
  var getFontFaceEach = (name, weights) => {
4399
4412
  const keys = Object.keys(weights);
@@ -4407,6 +4420,15 @@ var getFontFace = (LIBRARY) => {
4407
4420
  return keys.map((key) => getFontFaceEach(key, LIBRARY[key].value));
4408
4421
  };
4409
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
+ }
4410
4432
  const isArr = weights[0];
4411
4433
  if (isArr) return getFontFaceEach(name, weights).map(setInCustomFontMedia);
4412
4434
  return setCustomFontMedia(name, weights.url);
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.29",
5
+ "version": "2.34.31",
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.29",
29
- "@symbo.ls/utils": "^2.34.29",
28
+ "@domql/utils": "^2.34.31",
29
+ "@symbo.ls/utils": "^2.34.31",
30
30
  "color-contrast-checker": "^1.5.0"
31
31
  },
32
- "gitHead": "90cb8b61065249122ff356c3ea6eb56191c49bfa"
32
+ "gitHead": "fc336f4a56746a60a487078dd245035c04da0062"
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
  }