@tamagui/font 1.11.0
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/README.md +1 -0
- package/dist/cjs/index.js +88 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/index.js +69 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/index.mjs +69 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/jsx/index.js +68 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/index.mjs +68 -0
- package/dist/jsx/index.mjs.map +7 -0
- package/package.json +33 -0
- package/src/index.ts +83 -0
- package/types/index.d.ts +22 -0
- package/types/index.d.ts.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
## addFont
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var src_exports = {};
|
|
20
|
+
__export(src_exports, {
|
|
21
|
+
addFont: () => addFont
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(src_exports);
|
|
24
|
+
var import_constants = require("@tamagui/constants");
|
|
25
|
+
var import_web = require("@tamagui/web");
|
|
26
|
+
function addFont(props) {
|
|
27
|
+
var _a;
|
|
28
|
+
const config = (0, import_web.getConfig)();
|
|
29
|
+
const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props;
|
|
30
|
+
if (process.env.NODE_ENV === "development") {
|
|
31
|
+
if (!config) {
|
|
32
|
+
throw new Error("No config");
|
|
33
|
+
}
|
|
34
|
+
const fontFamily = config.fonts[fontFamilyNameIn];
|
|
35
|
+
if (!props.update && fontFamily) {
|
|
36
|
+
return { fontFamily };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
config.fonts[fontFamilyNameIn] = fontFamilyIn;
|
|
40
|
+
const sep = process.env.NODE_ENV === "development" ? config.cssStyleSeparator || " " : "";
|
|
41
|
+
function declarationsToRuleSet(decs, selector = "") {
|
|
42
|
+
return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`;
|
|
43
|
+
}
|
|
44
|
+
if (import_constants.isWeb) {
|
|
45
|
+
const fontFamilyToken = (0, import_web.createVariables)(fontFamilyIn, "f", true);
|
|
46
|
+
const parsedFontFamily = (0, import_web.parseFont)(fontFamilyToken);
|
|
47
|
+
const fontFamilyNameParsed = `$${fontFamilyNameIn}`;
|
|
48
|
+
config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily;
|
|
49
|
+
if (props.insertCSS) {
|
|
50
|
+
const [ff_name, ff_language] = fontFamilyNameParsed.includes("_") ? fontFamilyNameParsed.split("_") : [fontFamilyNameParsed];
|
|
51
|
+
const fontVars = (0, import_web.registerFontVariables)(parsedFontFamily);
|
|
52
|
+
const fontDeclaration = {
|
|
53
|
+
[fontFamilyNameIn]: {
|
|
54
|
+
name: ff_name.slice(1),
|
|
55
|
+
declarations: fontVars,
|
|
56
|
+
language: ff_language
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const {
|
|
60
|
+
name,
|
|
61
|
+
declarations,
|
|
62
|
+
language = "default"
|
|
63
|
+
} = fontDeclaration[fontFamilyNameIn];
|
|
64
|
+
const fontSelector = `.font_${name}`;
|
|
65
|
+
const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`;
|
|
66
|
+
const selectors = language === "default" ? ` ${fontSelector}, ${langSelector}` : langSelector;
|
|
67
|
+
const cssRuleSets = declarationsToRuleSet(declarations, selectors);
|
|
68
|
+
const id = `t_font_style_${fontFamilyNameIn}`;
|
|
69
|
+
const existing = document.querySelector(`#${id}`);
|
|
70
|
+
const style = document.createElement("style");
|
|
71
|
+
style.id = id;
|
|
72
|
+
style.appendChild(document.createTextNode(`${cssRuleSets}`));
|
|
73
|
+
document.head.appendChild(style);
|
|
74
|
+
if (existing) {
|
|
75
|
+
(_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
fontFamilyToken,
|
|
79
|
+
fontDeclaration
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
addFont
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n createVariables,\n getConfig,\n parseFont,\n registerFontVariables,\n} from '@tamagui/web'\nimport type { CreateTamaguiProps } from '@tamagui/web'\n\nexport function addFont(props: {\n fontFamilyName: string\n fontFamily: CreateTamaguiProps['fonts'][keyof CreateTamaguiProps['fonts']]\n insertCSS?: boolean\n // TODO make sure to add updateFont\n update?: boolean\n}) {\n const config = getConfig()\n const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const fontFamily = config.fonts[fontFamilyNameIn]\n if (!props.update && fontFamily) {\n return { fontFamily }\n }\n }\n\n config.fonts[fontFamilyNameIn] = fontFamilyIn\n\n const sep =\n process.env.NODE_ENV === 'development' ? config.cssStyleSeparator || ' ' : ''\n function declarationsToRuleSet(decs: string[], selector = '') {\n return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`\n }\n\n if (isWeb) {\n const fontFamilyToken = createVariables(fontFamilyIn, 'f', true)\n const parsedFontFamily = parseFont(fontFamilyToken)\n const fontFamilyNameParsed = `$${fontFamilyNameIn}`\n config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily\n\n if (props.insertCSS) {\n const [ff_name, ff_language] = fontFamilyNameParsed.includes('_')\n ? fontFamilyNameParsed.split('_')\n : [fontFamilyNameParsed]\n const fontVars = registerFontVariables(parsedFontFamily)\n const fontDeclaration = {\n [fontFamilyNameIn]: {\n name: ff_name.slice(1),\n declarations: fontVars,\n language: ff_language,\n },\n }\n\n const {\n name,\n declarations,\n language = 'default',\n } = fontDeclaration[fontFamilyNameIn]\n const fontSelector = `.font_${name}`\n const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`\n const selectors =\n language === 'default' ? ` ${fontSelector}, ${langSelector}` : langSelector\n const cssRuleSets = declarationsToRuleSet(declarations, selectors)\n\n const id = `t_font_style_${fontFamilyNameIn}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(`${cssRuleSets}`))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n return {\n fontFamilyToken,\n fontDeclaration,\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AACtB,iBAKO;AAGA,SAAS,QAAQ,OAMrB;AAfH;AAgBE,QA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sB,cAAc,SAAS;AAEjE,YAAM,KAAK,gBAAgB;AAC3B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,GAAG,aAAa,CAAC;AAC3D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AACA,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
createVariables,
|
|
4
|
+
getConfig,
|
|
5
|
+
parseFont,
|
|
6
|
+
registerFontVariables
|
|
7
|
+
} from "@tamagui/web";
|
|
8
|
+
function addFont(props) {
|
|
9
|
+
var _a;
|
|
10
|
+
const config = getConfig();
|
|
11
|
+
const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props;
|
|
12
|
+
if (process.env.NODE_ENV === "development") {
|
|
13
|
+
if (!config) {
|
|
14
|
+
throw new Error("No config");
|
|
15
|
+
}
|
|
16
|
+
const fontFamily = config.fonts[fontFamilyNameIn];
|
|
17
|
+
if (!props.update && fontFamily) {
|
|
18
|
+
return { fontFamily };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
config.fonts[fontFamilyNameIn] = fontFamilyIn;
|
|
22
|
+
const sep = process.env.NODE_ENV === "development" ? config.cssStyleSeparator || " " : "";
|
|
23
|
+
function declarationsToRuleSet(decs, selector = "") {
|
|
24
|
+
return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`;
|
|
25
|
+
}
|
|
26
|
+
if (isWeb) {
|
|
27
|
+
const fontFamilyToken = createVariables(fontFamilyIn, "f", true);
|
|
28
|
+
const parsedFontFamily = parseFont(fontFamilyToken);
|
|
29
|
+
const fontFamilyNameParsed = `$${fontFamilyNameIn}`;
|
|
30
|
+
config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily;
|
|
31
|
+
if (props.insertCSS) {
|
|
32
|
+
const [ff_name, ff_language] = fontFamilyNameParsed.includes("_") ? fontFamilyNameParsed.split("_") : [fontFamilyNameParsed];
|
|
33
|
+
const fontVars = registerFontVariables(parsedFontFamily);
|
|
34
|
+
const fontDeclaration = {
|
|
35
|
+
[fontFamilyNameIn]: {
|
|
36
|
+
name: ff_name.slice(1),
|
|
37
|
+
declarations: fontVars,
|
|
38
|
+
language: ff_language
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const {
|
|
42
|
+
name,
|
|
43
|
+
declarations,
|
|
44
|
+
language = "default"
|
|
45
|
+
} = fontDeclaration[fontFamilyNameIn];
|
|
46
|
+
const fontSelector = `.font_${name}`;
|
|
47
|
+
const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`;
|
|
48
|
+
const selectors = language === "default" ? ` ${fontSelector}, ${langSelector}` : langSelector;
|
|
49
|
+
const cssRuleSets = declarationsToRuleSet(declarations, selectors);
|
|
50
|
+
const id = `t_font_style_${fontFamilyNameIn}`;
|
|
51
|
+
const existing = document.querySelector(`#${id}`);
|
|
52
|
+
const style = document.createElement("style");
|
|
53
|
+
style.id = id;
|
|
54
|
+
style.appendChild(document.createTextNode(`${cssRuleSets}`));
|
|
55
|
+
document.head.appendChild(style);
|
|
56
|
+
if (existing) {
|
|
57
|
+
(_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
fontFamilyToken,
|
|
61
|
+
fontDeclaration
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
addFont
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n createVariables,\n getConfig,\n parseFont,\n registerFontVariables,\n} from '@tamagui/web'\nimport type { CreateTamaguiProps } from '@tamagui/web'\n\nexport function addFont(props: {\n fontFamilyName: string\n fontFamily: CreateTamaguiProps['fonts'][keyof CreateTamaguiProps['fonts']]\n insertCSS?: boolean\n // TODO make sure to add updateFont\n update?: boolean\n}) {\n const config = getConfig()\n const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const fontFamily = config.fonts[fontFamilyNameIn]\n if (!props.update && fontFamily) {\n return { fontFamily }\n }\n }\n\n config.fonts[fontFamilyNameIn] = fontFamilyIn\n\n const sep =\n process.env.NODE_ENV === 'development' ? config.cssStyleSeparator || ' ' : ''\n function declarationsToRuleSet(decs: string[], selector = '') {\n return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`\n }\n\n if (isWeb) {\n const fontFamilyToken = createVariables(fontFamilyIn, 'f', true)\n const parsedFontFamily = parseFont(fontFamilyToken)\n const fontFamilyNameParsed = `$${fontFamilyNameIn}`\n config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily\n\n if (props.insertCSS) {\n const [ff_name, ff_language] = fontFamilyNameParsed.includes('_')\n ? fontFamilyNameParsed.split('_')\n : [fontFamilyNameParsed]\n const fontVars = registerFontVariables(parsedFontFamily)\n const fontDeclaration = {\n [fontFamilyNameIn]: {\n name: ff_name.slice(1),\n declarations: fontVars,\n language: ff_language,\n },\n }\n\n const {\n name,\n declarations,\n language = 'default',\n } = fontDeclaration[fontFamilyNameIn]\n const fontSelector = `.font_${name}`\n const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`\n const selectors =\n language === 'default' ? ` ${fontSelector}, ${langSelector}` : langSelector\n const cssRuleSets = declarationsToRuleSet(declarations, selectors)\n\n const id = `t_font_style_${fontFamilyNameIn}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(`${cssRuleSets}`))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n return {\n fontFamilyToken,\n fontDeclaration,\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,QAAQ,OAMrB;AAfH;AAgBE,QAAM,SAAS,UAAU;AACzB,QAAM,EAAE,gBAAgB,kBAAkB,YAAY,aAAa,IAAI;AAEvE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,WAAW;AAAA,IAC7B;AACA,UAAM,aAAa,OAAO,MAAM,gBAAgB;AAChD,QAAI,CAAC,MAAM,UAAU,YAAY;AAC/B,aAAO,EAAE,WAAW;AAAA,IACtB;AAAA,EACF;AAEA,SAAO,MAAM,gBAAgB,IAAI;AAEjC,QAAM,MACJ,QAAQ,IAAI,aAAa,gBAAgB,OAAO,qBAAqB,MAAM;AAC7E,WAAS,sBAAsB,MAAgB,WAAW,IAAI;AAC5D,WAAO,QAAQ,aAAa,MAAM,CAAC,GAAG,IAAI,EAAE,KAAK,IAAI,KAAK,IAAI;AAAA,EAChE;AAEA,MAAI,OAAO;AACT,UAAM,kBAAkB,gBAAgB,cAAc,KAAK,IAAI;AAC/D,UAAM,mBAAmB,UAAU,eAAe;AAClD,UAAM,uBAAuB,IAAI;AACjC,WAAO,YAAY,oBAAoB,IAAI;AAE3C,QAAI,MAAM,WAAW;AACnB,YAAM,CAAC,SAAS,WAAW,IAAI,qBAAqB,SAAS,GAAG,IAC5D,qBAAqB,MAAM,GAAG,IAC9B,CAAC,oBAAoB;AACzB,YAAM,WAAW,sBAAsB,gBAAgB;AACvD,YAAM,kBAAkB;AAAA,QACtB,CAAC,gBAAgB,GAAG;AAAA,UAClB,MAAM,QAAQ,MAAM,CAAC;AAAA,UACrB,cAAc;AAAA,UACd,UAAU;AAAA,QACZ;AAAA,MACF;AAEA,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA,WAAW;AAAA,MACb,IAAI,gBAAgB,gBAAgB;AACpC,YAAM,eAAe,SAAS;AAC9B,YAAM,eAAe,iBAAiB,QAAQ,YAAY;AAC1D,YAAM,YACJ,aAAa,YAAY,IAAI,iBAAiB,iBAAiB;AACjE,YAAM,cAAc,sBAAsB,cAAc,SAAS;AAEjE,YAAM,KAAK,gBAAgB;AAC3B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,GAAG,aAAa,CAAC;AAC3D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,uBAAS,kBAAT,mBAAwB,YAAY;AAAA,MACtC;AACA,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
createVariables,
|
|
4
|
+
getConfig,
|
|
5
|
+
parseFont,
|
|
6
|
+
registerFontVariables
|
|
7
|
+
} from "@tamagui/web";
|
|
8
|
+
function addFont(props) {
|
|
9
|
+
var _a;
|
|
10
|
+
const config = getConfig();
|
|
11
|
+
const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props;
|
|
12
|
+
if (process.env.NODE_ENV === "development") {
|
|
13
|
+
if (!config) {
|
|
14
|
+
throw new Error("No config");
|
|
15
|
+
}
|
|
16
|
+
const fontFamily = config.fonts[fontFamilyNameIn];
|
|
17
|
+
if (!props.update && fontFamily) {
|
|
18
|
+
return { fontFamily };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
config.fonts[fontFamilyNameIn] = fontFamilyIn;
|
|
22
|
+
const sep = process.env.NODE_ENV === "development" ? config.cssStyleSeparator || " " : "";
|
|
23
|
+
function declarationsToRuleSet(decs, selector = "") {
|
|
24
|
+
return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`;
|
|
25
|
+
}
|
|
26
|
+
if (isWeb) {
|
|
27
|
+
const fontFamilyToken = createVariables(fontFamilyIn, "f", true);
|
|
28
|
+
const parsedFontFamily = parseFont(fontFamilyToken);
|
|
29
|
+
const fontFamilyNameParsed = `$${fontFamilyNameIn}`;
|
|
30
|
+
config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily;
|
|
31
|
+
if (props.insertCSS) {
|
|
32
|
+
const [ff_name, ff_language] = fontFamilyNameParsed.includes("_") ? fontFamilyNameParsed.split("_") : [fontFamilyNameParsed];
|
|
33
|
+
const fontVars = registerFontVariables(parsedFontFamily);
|
|
34
|
+
const fontDeclaration = {
|
|
35
|
+
[fontFamilyNameIn]: {
|
|
36
|
+
name: ff_name.slice(1),
|
|
37
|
+
declarations: fontVars,
|
|
38
|
+
language: ff_language
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const {
|
|
42
|
+
name,
|
|
43
|
+
declarations,
|
|
44
|
+
language = "default"
|
|
45
|
+
} = fontDeclaration[fontFamilyNameIn];
|
|
46
|
+
const fontSelector = `.font_${name}`;
|
|
47
|
+
const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`;
|
|
48
|
+
const selectors = language === "default" ? ` ${fontSelector}, ${langSelector}` : langSelector;
|
|
49
|
+
const cssRuleSets = declarationsToRuleSet(declarations, selectors);
|
|
50
|
+
const id = `t_font_style_${fontFamilyNameIn}`;
|
|
51
|
+
const existing = document.querySelector(`#${id}`);
|
|
52
|
+
const style = document.createElement("style");
|
|
53
|
+
style.id = id;
|
|
54
|
+
style.appendChild(document.createTextNode(`${cssRuleSets}`));
|
|
55
|
+
document.head.appendChild(style);
|
|
56
|
+
if (existing) {
|
|
57
|
+
(_a = existing.parentElement) == null ? void 0 : _a.removeChild(existing);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
fontFamilyToken,
|
|
61
|
+
fontDeclaration
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
addFont
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n createVariables,\n getConfig,\n parseFont,\n registerFontVariables,\n} from '@tamagui/web'\nimport type { CreateTamaguiProps } from '@tamagui/web'\n\nexport function addFont(props: {\n fontFamilyName: string\n fontFamily: CreateTamaguiProps['fonts'][keyof CreateTamaguiProps['fonts']]\n insertCSS?: boolean\n // TODO make sure to add updateFont\n update?: boolean\n}) {\n const config = getConfig()\n const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const fontFamily = config.fonts[fontFamilyNameIn]\n if (!props.update && fontFamily) {\n return { fontFamily }\n }\n }\n\n config.fonts[fontFamilyNameIn] = fontFamilyIn\n\n const sep =\n process.env.NODE_ENV === 'development' ? config.cssStyleSeparator || ' ' : ''\n function declarationsToRuleSet(decs: string[], selector = '') {\n return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`\n }\n\n if (isWeb) {\n const fontFamilyToken = createVariables(fontFamilyIn, 'f', true)\n const parsedFontFamily = parseFont(fontFamilyToken)\n const fontFamilyNameParsed = `$${fontFamilyNameIn}`\n config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily\n\n if (props.insertCSS) {\n const [ff_name, ff_language] = fontFamilyNameParsed.includes('_')\n ? fontFamilyNameParsed.split('_')\n : [fontFamilyNameParsed]\n const fontVars = registerFontVariables(parsedFontFamily)\n const fontDeclaration = {\n [fontFamilyNameIn]: {\n name: ff_name.slice(1),\n declarations: fontVars,\n language: ff_language,\n },\n }\n\n const {\n name,\n declarations,\n language = 'default',\n } = fontDeclaration[fontFamilyNameIn]\n const fontSelector = `.font_${name}`\n const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`\n const selectors =\n language === 'default' ? ` ${fontSelector}, ${langSelector}` : langSelector\n const cssRuleSets = declarationsToRuleSet(declarations, selectors)\n\n const id = `t_font_style_${fontFamilyNameIn}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(`${cssRuleSets}`))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n return {\n fontFamilyToken,\n fontDeclaration,\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,QAAQ,OAMrB;AAfH;AAgBE,QAAM,SAAS,UAAU;AACzB,QAAM,EAAE,gBAAgB,kBAAkB,YAAY,aAAa,IAAI;AAEvE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,WAAW;AAAA,IAC7B;AACA,UAAM,aAAa,OAAO,MAAM,gBAAgB;AAChD,QAAI,CAAC,MAAM,UAAU,YAAY;AAC/B,aAAO,EAAE,WAAW;AAAA,IACtB;AAAA,EACF;AAEA,SAAO,MAAM,gBAAgB,IAAI;AAEjC,QAAM,MACJ,QAAQ,IAAI,aAAa,gBAAgB,OAAO,qBAAqB,MAAM;AAC7E,WAAS,sBAAsB,MAAgB,WAAW,IAAI;AAC5D,WAAO,QAAQ,aAAa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{
|
|
3
|
+
createVariables,
|
|
4
|
+
getConfig,
|
|
5
|
+
parseFont,
|
|
6
|
+
registerFontVariables
|
|
7
|
+
} from "@tamagui/web";
|
|
8
|
+
function addFont(props) {
|
|
9
|
+
const config = getConfig();
|
|
10
|
+
const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props;
|
|
11
|
+
if (process.env.NODE_ENV === "development") {
|
|
12
|
+
if (!config) {
|
|
13
|
+
throw new Error("No config");
|
|
14
|
+
}
|
|
15
|
+
const fontFamily = config.fonts[fontFamilyNameIn];
|
|
16
|
+
if (!props.update && fontFamily) {
|
|
17
|
+
return { fontFamily };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
config.fonts[fontFamilyNameIn] = fontFamilyIn;
|
|
21
|
+
const sep = process.env.NODE_ENV === "development" ? config.cssStyleSeparator || " " : "";
|
|
22
|
+
function declarationsToRuleSet(decs, selector = "") {
|
|
23
|
+
return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`;
|
|
24
|
+
}
|
|
25
|
+
if (isWeb) {
|
|
26
|
+
const fontFamilyToken = createVariables(fontFamilyIn, "f", true);
|
|
27
|
+
const parsedFontFamily = parseFont(fontFamilyToken);
|
|
28
|
+
const fontFamilyNameParsed = `$${fontFamilyNameIn}`;
|
|
29
|
+
config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily;
|
|
30
|
+
if (props.insertCSS) {
|
|
31
|
+
const [ff_name, ff_language] = fontFamilyNameParsed.includes("_") ? fontFamilyNameParsed.split("_") : [fontFamilyNameParsed];
|
|
32
|
+
const fontVars = registerFontVariables(parsedFontFamily);
|
|
33
|
+
const fontDeclaration = {
|
|
34
|
+
[fontFamilyNameIn]: {
|
|
35
|
+
name: ff_name.slice(1),
|
|
36
|
+
declarations: fontVars,
|
|
37
|
+
language: ff_language
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const {
|
|
41
|
+
name,
|
|
42
|
+
declarations,
|
|
43
|
+
language = "default"
|
|
44
|
+
} = fontDeclaration[fontFamilyNameIn];
|
|
45
|
+
const fontSelector = `.font_${name}`;
|
|
46
|
+
const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`;
|
|
47
|
+
const selectors = language === "default" ? ` ${fontSelector}, ${langSelector}` : langSelector;
|
|
48
|
+
const cssRuleSets = declarationsToRuleSet(declarations, selectors);
|
|
49
|
+
const id = `t_font_style_${fontFamilyNameIn}`;
|
|
50
|
+
const existing = document.querySelector(`#${id}`);
|
|
51
|
+
const style = document.createElement("style");
|
|
52
|
+
style.id = id;
|
|
53
|
+
style.appendChild(document.createTextNode(`${cssRuleSets}`));
|
|
54
|
+
document.head.appendChild(style);
|
|
55
|
+
if (existing) {
|
|
56
|
+
existing.parentElement?.removeChild(existing);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
fontFamilyToken,
|
|
60
|
+
fontDeclaration
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
addFont
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n createVariables,\n getConfig,\n parseFont,\n registerFontVariables,\n} from '@tamagui/web'\nimport type { CreateTamaguiProps } from '@tamagui/web'\n\nexport function addFont(props: {\n fontFamilyName: string\n fontFamily: CreateTamaguiProps['fonts'][keyof CreateTamaguiProps['fonts']]\n insertCSS?: boolean\n // TODO make sure to add updateFont\n update?: boolean\n}) {\n const config = getConfig()\n const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const fontFamily = config.fonts[fontFamilyNameIn]\n if (!props.update && fontFamily) {\n return { fontFamily }\n }\n }\n\n config.fonts[fontFamilyNameIn] = fontFamilyIn\n\n const sep =\n process.env.NODE_ENV === 'development' ? config.cssStyleSeparator || ' ' : ''\n function declarationsToRuleSet(decs: string[], selector = '') {\n return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`\n }\n\n if (isWeb) {\n const fontFamilyToken = createVariables(fontFamilyIn, 'f', true)\n const parsedFontFamily = parseFont(fontFamilyToken)\n const fontFamilyNameParsed = `$${fontFamilyNameIn}`\n config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily\n\n if (props.insertCSS) {\n const [ff_name, ff_language] = fontFamilyNameParsed.includes('_')\n ? fontFamilyNameParsed.split('_')\n : [fontFamilyNameParsed]\n const fontVars = registerFontVariables(parsedFontFamily)\n const fontDeclaration = {\n [fontFamilyNameIn]: {\n name: ff_name.slice(1),\n declarations: fontVars,\n language: ff_language,\n },\n }\n\n const {\n name,\n declarations,\n language = 'default',\n } = fontDeclaration[fontFamilyNameIn]\n const fontSelector = `.font_${name}`\n const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`\n const selectors =\n language === 'default' ? ` ${fontSelector}, ${langSelector}` : langSelector\n const cssRuleSets = declarationsToRuleSet(declarations, selectors)\n\n const id = `t_font_style_${fontFamilyNameIn}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(`${cssRuleSets}`))\n document.head.appendChild(style)\n if (existing) {\n existing.parentElement?.removeChild(existing)\n }\n return {\n fontFamilyToken,\n fontDeclaration,\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,SAAS,QAAQ,OAMrB;AACD,QAAM,SAAS,UAAU;AACzB,QAAM,EAAE,gBAAgB,kBAAkB,YAAY,aAAa,IAAI;AAEvE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,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,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,GAAG,aAAa,CAAC;AAC3D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,iBAAS,eAAe,YAAY,QAAQ;AAAA,MAC9C;AACA,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/constants";
|
|
2
|
+
import {
|
|
3
|
+
createVariables,
|
|
4
|
+
getConfig,
|
|
5
|
+
parseFont,
|
|
6
|
+
registerFontVariables
|
|
7
|
+
} from "@tamagui/web";
|
|
8
|
+
function addFont(props) {
|
|
9
|
+
const config = getConfig();
|
|
10
|
+
const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props;
|
|
11
|
+
if (process.env.NODE_ENV === "development") {
|
|
12
|
+
if (!config) {
|
|
13
|
+
throw new Error("No config");
|
|
14
|
+
}
|
|
15
|
+
const fontFamily = config.fonts[fontFamilyNameIn];
|
|
16
|
+
if (!props.update && fontFamily) {
|
|
17
|
+
return { fontFamily };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
config.fonts[fontFamilyNameIn] = fontFamilyIn;
|
|
21
|
+
const sep = process.env.NODE_ENV === "development" ? config.cssStyleSeparator || " " : "";
|
|
22
|
+
function declarationsToRuleSet(decs, selector = "") {
|
|
23
|
+
return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`;
|
|
24
|
+
}
|
|
25
|
+
if (isWeb) {
|
|
26
|
+
const fontFamilyToken = createVariables(fontFamilyIn, "f", true);
|
|
27
|
+
const parsedFontFamily = parseFont(fontFamilyToken);
|
|
28
|
+
const fontFamilyNameParsed = `$${fontFamilyNameIn}`;
|
|
29
|
+
config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily;
|
|
30
|
+
if (props.insertCSS) {
|
|
31
|
+
const [ff_name, ff_language] = fontFamilyNameParsed.includes("_") ? fontFamilyNameParsed.split("_") : [fontFamilyNameParsed];
|
|
32
|
+
const fontVars = registerFontVariables(parsedFontFamily);
|
|
33
|
+
const fontDeclaration = {
|
|
34
|
+
[fontFamilyNameIn]: {
|
|
35
|
+
name: ff_name.slice(1),
|
|
36
|
+
declarations: fontVars,
|
|
37
|
+
language: ff_language
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const {
|
|
41
|
+
name,
|
|
42
|
+
declarations,
|
|
43
|
+
language = "default"
|
|
44
|
+
} = fontDeclaration[fontFamilyNameIn];
|
|
45
|
+
const fontSelector = `.font_${name}`;
|
|
46
|
+
const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`;
|
|
47
|
+
const selectors = language === "default" ? ` ${fontSelector}, ${langSelector}` : langSelector;
|
|
48
|
+
const cssRuleSets = declarationsToRuleSet(declarations, selectors);
|
|
49
|
+
const id = `t_font_style_${fontFamilyNameIn}`;
|
|
50
|
+
const existing = document.querySelector(`#${id}`);
|
|
51
|
+
const style = document.createElement("style");
|
|
52
|
+
style.id = id;
|
|
53
|
+
style.appendChild(document.createTextNode(`${cssRuleSets}`));
|
|
54
|
+
document.head.appendChild(style);
|
|
55
|
+
if (existing) {
|
|
56
|
+
existing.parentElement?.removeChild(existing);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
fontFamilyToken,
|
|
60
|
+
fontDeclaration
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
addFont
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/constants'\nimport {\n createVariables,\n getConfig,\n parseFont,\n registerFontVariables,\n} from '@tamagui/web'\nimport type { CreateTamaguiProps } from '@tamagui/web'\n\nexport function addFont(props: {\n fontFamilyName: string\n fontFamily: CreateTamaguiProps['fonts'][keyof CreateTamaguiProps['fonts']]\n insertCSS?: boolean\n // TODO make sure to add updateFont\n update?: boolean\n}) {\n const config = getConfig()\n const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error('No config')\n }\n const fontFamily = config.fonts[fontFamilyNameIn]\n if (!props.update && fontFamily) {\n return { fontFamily }\n }\n }\n\n config.fonts[fontFamilyNameIn] = fontFamilyIn\n\n const sep =\n process.env.NODE_ENV === 'development' ? config.cssStyleSeparator || ' ' : ''\n function declarationsToRuleSet(decs: string[], selector = '') {\n return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`\n }\n\n if (isWeb) {\n const fontFamilyToken = createVariables(fontFamilyIn, 'f', true)\n const parsedFontFamily = parseFont(fontFamilyToken)\n const fontFamilyNameParsed = `$${fontFamilyNameIn}`\n config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily\n\n if (props.insertCSS) {\n const [ff_name, ff_language] = fontFamilyNameParsed.includes('_')\n ? fontFamilyNameParsed.split('_')\n : [fontFamilyNameParsed]\n const fontVars = registerFontVariables(parsedFontFamily)\n const fontDeclaration = {\n [fontFamilyNameIn]: {\n name: ff_name.slice(1),\n declarations: fontVars,\n language: ff_language,\n },\n }\n\n const {\n name,\n declarations,\n language = 'default',\n } = fontDeclaration[fontFamilyNameIn]\n const fontSelector = `.font_${name}`\n const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`\n const selectors =\n language === 'default' ? ` ${fontSelector}, ${langSelector}` : langSelector\n const cssRuleSets = declarationsToRuleSet(declarations, selectors)\n\n const id = `t_font_style_${fontFamilyNameIn}`\n const existing = document.querySelector(`#${id}`)\n const style = document.createElement('style')\n style.id = id\n style.appendChild(document.createTextNode(`${cssRuleSets}`))\n document.head.appendChild(style)\n if (exist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ACJ;AAAA,QACA;AAAA,QACA,WAAW;AAAA,MACb,IAAI,gBAAgB,gBAAgB;AACpC,YAAM,eAAe,SAAS;AAC9B,YAAM,eAAe,iBAAiB,QAAQ,YAAY;AAC1D,YAAM,YACJ,aAAa,YAAY,IAAI,iBAAiB,iBAAiB;AACjE,YAAM,cAAc,sBAAsB,cAAc,SAAS;AAEjE,YAAM,KAAK,gBAAgB;AAC3B,YAAM,WAAW,SAAS,cAAc,IAAI,IAAI;AAChD,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,KAAK;AACX,YAAM,YAAY,SAAS,eAAe,GAAG,aAAa,CAAC;AAC3D,eAAS,KAAK,YAAY,KAAK;AAC/B,UAAI,UAAU;AACZ,iBAAS,eAAe,YAAY,QAAQ;AAAA,MAC9C;AACA,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/font",
|
|
3
|
+
"version": "1.11.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"source": "src/index.ts",
|
|
6
|
+
"types": "./types/index.d.ts",
|
|
7
|
+
"main": "dist/cjs",
|
|
8
|
+
"module": "dist/esm",
|
|
9
|
+
"module:jsx": "dist/jsx",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"types",
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tamagui-build",
|
|
17
|
+
"watch": "tamagui-build --watch"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@tamagui/constants": "1.11.0",
|
|
21
|
+
"@tamagui/web": "1.11.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "*"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@tamagui/build": "1.11.0",
|
|
28
|
+
"react": "^18.2.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { isWeb } from '@tamagui/constants'
|
|
2
|
+
import {
|
|
3
|
+
createVariables,
|
|
4
|
+
getConfig,
|
|
5
|
+
parseFont,
|
|
6
|
+
registerFontVariables,
|
|
7
|
+
} from '@tamagui/web'
|
|
8
|
+
import type { CreateTamaguiProps } from '@tamagui/web'
|
|
9
|
+
|
|
10
|
+
export function addFont(props: {
|
|
11
|
+
fontFamilyName: string
|
|
12
|
+
fontFamily: CreateTamaguiProps['fonts'][keyof CreateTamaguiProps['fonts']]
|
|
13
|
+
insertCSS?: boolean
|
|
14
|
+
// TODO make sure to add updateFont
|
|
15
|
+
update?: boolean
|
|
16
|
+
}) {
|
|
17
|
+
const config = getConfig()
|
|
18
|
+
const { fontFamilyName: fontFamilyNameIn, fontFamily: fontFamilyIn } = props
|
|
19
|
+
|
|
20
|
+
if (process.env.NODE_ENV === 'development') {
|
|
21
|
+
if (!config) {
|
|
22
|
+
throw new Error('No config')
|
|
23
|
+
}
|
|
24
|
+
const fontFamily = config.fonts[fontFamilyNameIn]
|
|
25
|
+
if (!props.update && fontFamily) {
|
|
26
|
+
return { fontFamily }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
config.fonts[fontFamilyNameIn] = fontFamilyIn
|
|
31
|
+
|
|
32
|
+
const sep =
|
|
33
|
+
process.env.NODE_ENV === 'development' ? config.cssStyleSeparator || ' ' : ''
|
|
34
|
+
function declarationsToRuleSet(decs: string[], selector = '') {
|
|
35
|
+
return `:root${selector} {${sep}${[...decs].join(`;${sep}`)}${sep}}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isWeb) {
|
|
39
|
+
const fontFamilyToken = createVariables(fontFamilyIn, 'f', true)
|
|
40
|
+
const parsedFontFamily = parseFont(fontFamilyToken)
|
|
41
|
+
const fontFamilyNameParsed = `$${fontFamilyNameIn}`
|
|
42
|
+
config.fontsParsed[fontFamilyNameParsed] = parsedFontFamily
|
|
43
|
+
|
|
44
|
+
if (props.insertCSS) {
|
|
45
|
+
const [ff_name, ff_language] = fontFamilyNameParsed.includes('_')
|
|
46
|
+
? fontFamilyNameParsed.split('_')
|
|
47
|
+
: [fontFamilyNameParsed]
|
|
48
|
+
const fontVars = registerFontVariables(parsedFontFamily)
|
|
49
|
+
const fontDeclaration = {
|
|
50
|
+
[fontFamilyNameIn]: {
|
|
51
|
+
name: ff_name.slice(1),
|
|
52
|
+
declarations: fontVars,
|
|
53
|
+
language: ff_language,
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const {
|
|
58
|
+
name,
|
|
59
|
+
declarations,
|
|
60
|
+
language = 'default',
|
|
61
|
+
} = fontDeclaration[fontFamilyNameIn]
|
|
62
|
+
const fontSelector = `.font_${name}`
|
|
63
|
+
const langSelector = `:root .t_lang-${name}-${language} ${fontSelector}`
|
|
64
|
+
const selectors =
|
|
65
|
+
language === 'default' ? ` ${fontSelector}, ${langSelector}` : langSelector
|
|
66
|
+
const cssRuleSets = declarationsToRuleSet(declarations, selectors)
|
|
67
|
+
|
|
68
|
+
const id = `t_font_style_${fontFamilyNameIn}`
|
|
69
|
+
const existing = document.querySelector(`#${id}`)
|
|
70
|
+
const style = document.createElement('style')
|
|
71
|
+
style.id = id
|
|
72
|
+
style.appendChild(document.createTextNode(`${cssRuleSets}`))
|
|
73
|
+
document.head.appendChild(style)
|
|
74
|
+
if (existing) {
|
|
75
|
+
existing.parentElement?.removeChild(existing)
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
fontFamilyToken,
|
|
79
|
+
fontDeclaration,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CreateTamaguiProps } from '@tamagui/web';
|
|
2
|
+
export declare function addFont(props: {
|
|
3
|
+
fontFamilyName: string;
|
|
4
|
+
fontFamily: CreateTamaguiProps['fonts'][keyof CreateTamaguiProps['fonts']];
|
|
5
|
+
insertCSS?: boolean;
|
|
6
|
+
update?: boolean;
|
|
7
|
+
}): {
|
|
8
|
+
fontFamily: import("@tamagui/web").GenericFont<string | number>;
|
|
9
|
+
fontFamilyToken?: undefined;
|
|
10
|
+
fontDeclaration?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
fontFamilyToken: import("@tamagui/web").DeepVariableObject<import("@tamagui/web").GenericFont<string | number>>;
|
|
13
|
+
fontDeclaration: {
|
|
14
|
+
[x: string]: {
|
|
15
|
+
name: string;
|
|
16
|
+
declarations: string[];
|
|
17
|
+
language: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
fontFamily?: undefined;
|
|
21
|
+
} | undefined;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEtD,wBAAgB,OAAO,CAAC,KAAK,EAAE;IAC7B,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAA;IAC1E,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;;;;;;;;;;;;;;cAmEA"}
|