@tamagui/get-font-sized 1.13.2 → 1.13.4
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 +2 -90
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/index.js +2 -66
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/index.mjs +2 -66
- package/dist/esm/index.mjs.map +2 -2
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -1,93 +1,5 @@
|
|
|
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
|
-
getFontSized: () => getFontSized
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(src_exports);
|
|
24
|
-
var import_core = require("@tamagui/core");
|
|
25
|
-
const getFontSized = (sizeTokenIn = "$true", { fonts, props }) => {
|
|
26
|
-
var _a, _b, _c;
|
|
27
|
-
const family = (0, import_core.getVariableValue)(props.fontFamily) || "$body";
|
|
28
|
-
const font = fonts[family] || fonts["$body"];
|
|
29
|
-
if (!font) {
|
|
30
|
-
if (process.env.NODE_ENV === "development") {
|
|
31
|
-
console.warn("\u26A0\uFE0F no font found", {
|
|
32
|
-
family,
|
|
33
|
-
fontTokens: Object.keys(fonts),
|
|
34
|
-
sizeTokenIn
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
const fontFamily = font.family;
|
|
40
|
-
const sizeToken = sizeTokenIn === "$true" ? getDefaultSizeToken(font) : sizeTokenIn;
|
|
41
|
-
const fontSize = props.fontSize || font.size[sizeToken];
|
|
42
|
-
const lineHeight = props.lineHeight || font.lineHeight[sizeToken];
|
|
43
|
-
const fontWeight = props.fontWeight || font.weight[sizeToken];
|
|
44
|
-
const letterSpacing = props.letterSpacing || font.letterSpacing[sizeToken];
|
|
45
|
-
const fontStyle = props.fontStyle || ((_a = font.style) == null ? void 0 : _a[sizeToken]);
|
|
46
|
-
const textTransform = props.textTransform || ((_b = font.transform) == null ? void 0 : _b[sizeToken]);
|
|
47
|
-
const color = props.color || ((_c = font.color) == null ? void 0 : _c[sizeToken]);
|
|
48
|
-
const style = {
|
|
49
|
-
color,
|
|
50
|
-
fontStyle,
|
|
51
|
-
textTransform,
|
|
52
|
-
fontFamily,
|
|
53
|
-
fontWeight,
|
|
54
|
-
letterSpacing,
|
|
55
|
-
fontSize,
|
|
56
|
-
lineHeight
|
|
57
|
-
};
|
|
58
|
-
if (process.env.NODE_ENV === "development") {
|
|
59
|
-
if (props["debug"]) {
|
|
60
|
-
console.groupCollapsed(" \u{1F539} getFontSized", sizeTokenIn, sizeToken);
|
|
61
|
-
console.log({ style, props, font });
|
|
62
|
-
console.groupEnd();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return style;
|
|
66
|
-
};
|
|
67
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
68
|
-
function getDefaultSizeToken(font) {
|
|
69
|
-
if (typeof font === "object" && cache.has(font)) {
|
|
70
|
-
return cache.get(font);
|
|
71
|
-
}
|
|
72
|
-
const sizeTokens = "$true" in font.size ? font.size : (0, import_core.getTokens)().size;
|
|
73
|
-
const sizeDefault = sizeTokens["$true"];
|
|
74
|
-
const sizeDefaultSpecific = sizeDefault ? Object.keys(sizeTokens).find(
|
|
75
|
-
(x) => x !== "$true" && sizeTokens[x]["val"] === sizeDefault["val"]
|
|
76
|
-
) : null;
|
|
77
|
-
if (!sizeDefault || !sizeDefaultSpecific) {
|
|
78
|
-
if (process.env.NODE_ENV === "development") {
|
|
79
|
-
console.warn(`No default size is set in your tokens for the "true" key, fonts will be inconsistent.
|
|
1
|
+
"use strict";var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var v=(e,o)=>{for(var n in o)c(e,n,{get:o[n],enumerable:!0})},E=(e,o,n,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of b(o))!T.call(e,t)&&t!==n&&c(e,t,{get:()=>o[t],enumerable:!(i=h(o,t))||i.enumerable});return e};var N=e=>E(c({},"__esModule",{value:!0}),e);var D={};v(D,{getFontSized:()=>V});module.exports=N(D);var r=require("@tamagui/core");const V=(e="$true",{fonts:o,props:n})=>{var f,u,y;const i=(0,r.getVariableValue)(n.fontFamily)||"$body",t=o[i]||o.$body;if(!t)return process.env.NODE_ENV==="development"&&console.warn("\u26A0\uFE0F no font found",{family:i,fontTokens:Object.keys(o),sizeTokenIn:e}),{};const g=t.family,s=e==="$true"?$(t):e,z=n.fontSize||t.size[s],S=n.lineHeight||t.lineHeight[s],d=n.fontWeight||t.weight[s],k=n.letterSpacing||t.letterSpacing[s],m=n.fontStyle||((f=t.style)==null?void 0:f[s]),F=n.textTransform||((u=t.transform)==null?void 0:u[s]),a={color:n.color||((y=t.color)==null?void 0:y[s]),fontStyle:m,textTransform:F,fontFamily:g,fontWeight:d,letterSpacing:k,fontSize:z,lineHeight:S};return process.env.NODE_ENV==="development"&&n.debug&&(console.groupCollapsed(" \u{1F539} getFontSized",e,s),console.log({style:a,props:n,font:t}),console.groupEnd()),a},l=new WeakMap;function $(e){if(typeof e=="object"&&l.has(e))return l.get(e);const o="$true"in e.size?e.size:(0,r.getTokens)().size,n=o.$true,i=n?Object.keys(o).find(t=>t!=="$true"&&o[t].val===n.val):null;return!n||!i?(process.env.NODE_ENV==="development"&&console.warn(`No default size is set in your tokens for the "true" key, fonts will be inconsistent.
|
|
80
2
|
|
|
81
3
|
Fix this by having consistent tokens across fonts and sizes and setting a true key for your size tokens, or
|
|
82
|
-
set true keys for all your font tokens: "size", "lineHeight", "fontStyle", etc.`);
|
|
83
|
-
}
|
|
84
|
-
return Object.keys(font.size)[3];
|
|
85
|
-
}
|
|
86
|
-
cache.set(font, sizeDefaultSpecific);
|
|
87
|
-
return sizeDefaultSpecific;
|
|
88
|
-
}
|
|
89
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
-
0 && (module.exports = {
|
|
91
|
-
getFontSized
|
|
92
|
-
});
|
|
4
|
+
set true keys for all your font tokens: "size", "lineHeight", "fontStyle", etc.`),Object.keys(e.size)[3]):(l.set(e,i),i)}0&&(module.exports={getFontSized});
|
|
93
5
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["import { getTokens, getVariableValue } from '@tamagui/core'\nimport type {\n FontSizeTokens,\n GenericFont,\n TextProps,\n VariantSpreadFunction,\n} from '@tamagui/core'\n\nexport const getFontSized: VariantSpreadFunction<TextProps, FontSizeTokens> = (\n sizeTokenIn = '$true',\n { fonts, props }\n) => {\n const family = getVariableValue(props.fontFamily) || '$body'\n const font = fonts[family] || fonts['$body']\n if (!font) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('\u26A0\uFE0F no font found', {\n family,\n fontTokens: Object.keys(fonts),\n sizeTokenIn,\n })\n }\n return {} as any\n }\n const fontFamily = font.family\n const sizeToken = sizeTokenIn === '$true' ? getDefaultSizeToken(font) : sizeTokenIn\n const fontSize = props.fontSize || font.size[sizeToken]\n const lineHeight = props.lineHeight || font.lineHeight[sizeToken]\n const fontWeight = props.fontWeight || font.weight[sizeToken]\n const letterSpacing = props.letterSpacing || font.letterSpacing[sizeToken]\n const fontStyle = props.fontStyle || font.style?.[sizeToken]\n const textTransform = props.textTransform || font.transform?.[sizeToken]\n const color = props.color || font.color?.[sizeToken]\n\n const style = {\n color,\n fontStyle,\n textTransform,\n fontFamily,\n fontWeight,\n letterSpacing,\n fontSize,\n lineHeight,\n }\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 getFontSized', sizeTokenIn, sizeToken)\n // eslint-disable-next-line no-console\n console.log({ style, props, font })\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n return style\n}\n\nconst cache = new WeakMap<any, FontSizeTokens>()\n\nfunction getDefaultSizeToken(font: GenericFont) {\n if (typeof font === 'object' && cache.has(font)) {\n return cache.get(font)!\n }\n\n // use either font.size if it has true set, or fallback to tokens.size mapping to the same\n const sizeTokens = '$true' in font.size ? font.size : getTokens().size\n const sizeDefault = sizeTokens['$true']\n const sizeDefaultSpecific = sizeDefault\n ? Object.keys(sizeTokens).find(\n (x) => x !== '$true' && sizeTokens[x]['val'] === sizeDefault['val']\n )\n : null\n\n if (!sizeDefault || !sizeDefaultSpecific) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(`No default size is set in your tokens for the \"true\" key, fonts will be inconsistent.\n\n Fix this by having consistent tokens across fonts and sizes and setting a true key for your size tokens, or\n set true keys for all your font tokens: \"size\", \"lineHeight\", \"fontStyle\", etc.`)\n }\n return Object.keys(font.size)[3]\n }\n\n cache.set(font, sizeDefaultSpecific as FontSizeTokens)\n return sizeD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K,CAAK,CAAC,EAElC,QAAQ,SAAS,GAGdU,CACT,EAEMC,EAAQ,IAAI,QAElB,SAASR,EAAoBH,EAAmB,CAC9C,GAAI,OAAOA,GAAS,UAAYW,EAAM,IAAIX,CAAI,EAC5C,OAAOW,EAAM,IAAIX,CAAI,EAIvB,MAAMY,EAAa,UAAWZ,EAAK,KAAOA,EAAK,QAAO,aAAU,EAAE,KAC5Da,EAAcD,EAAW,MACzBE,EAAsBD,EACxB,OAAO,KAAKD,CAAU,EAAE,KACrBG,GAAMA,IAAM,SAAWH,EAAWG,CAAC,EAAE,MAAWF,EAAY,GAC/D,EACA,KAEJ,MAAI,CAACA,GAAe,CAACC,GACf,QAAQ,IAAI,WAAa,eAC3B,QAAQ,KAAK;AAAA;AAAA;AAAA,sFAGmE,EAE3E,OAAO,KAAKd,EAAK,IAAI,EAAE,CAAC,IAGjCW,EAAM,IAAIX,EAAMc,CAAqC,EAC9CA,EACT",
|
|
6
|
+
"names": ["src_exports", "__export", "getFontSized", "__toCommonJS", "import_core", "sizeTokenIn", "fonts", "props", "_a", "_b", "_c", "family", "font", "fontFamily", "sizeToken", "getDefaultSizeToken", "fontSize", "lineHeight", "fontWeight", "letterSpacing", "fontStyle", "textTransform", "style", "cache", "sizeTokens", "sizeDefault", "sizeDefaultSpecific", "x"]
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,69 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
const getFontSized = (sizeTokenIn = "$true", { fonts, props }) => {
|
|
3
|
-
var _a, _b, _c;
|
|
4
|
-
const family = getVariableValue(props.fontFamily) || "$body";
|
|
5
|
-
const font = fonts[family] || fonts["$body"];
|
|
6
|
-
if (!font) {
|
|
7
|
-
if (process.env.NODE_ENV === "development") {
|
|
8
|
-
console.warn("\u26A0\uFE0F no font found", {
|
|
9
|
-
family,
|
|
10
|
-
fontTokens: Object.keys(fonts),
|
|
11
|
-
sizeTokenIn
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
const fontFamily = font.family;
|
|
17
|
-
const sizeToken = sizeTokenIn === "$true" ? getDefaultSizeToken(font) : sizeTokenIn;
|
|
18
|
-
const fontSize = props.fontSize || font.size[sizeToken];
|
|
19
|
-
const lineHeight = props.lineHeight || font.lineHeight[sizeToken];
|
|
20
|
-
const fontWeight = props.fontWeight || font.weight[sizeToken];
|
|
21
|
-
const letterSpacing = props.letterSpacing || font.letterSpacing[sizeToken];
|
|
22
|
-
const fontStyle = props.fontStyle || ((_a = font.style) == null ? void 0 : _a[sizeToken]);
|
|
23
|
-
const textTransform = props.textTransform || ((_b = font.transform) == null ? void 0 : _b[sizeToken]);
|
|
24
|
-
const color = props.color || ((_c = font.color) == null ? void 0 : _c[sizeToken]);
|
|
25
|
-
const style = {
|
|
26
|
-
color,
|
|
27
|
-
fontStyle,
|
|
28
|
-
textTransform,
|
|
29
|
-
fontFamily,
|
|
30
|
-
fontWeight,
|
|
31
|
-
letterSpacing,
|
|
32
|
-
fontSize,
|
|
33
|
-
lineHeight
|
|
34
|
-
};
|
|
35
|
-
if (process.env.NODE_ENV === "development") {
|
|
36
|
-
if (props["debug"]) {
|
|
37
|
-
console.groupCollapsed(" \u{1F539} getFontSized", sizeTokenIn, sizeToken);
|
|
38
|
-
console.log({ style, props, font });
|
|
39
|
-
console.groupEnd();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return style;
|
|
43
|
-
};
|
|
44
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
45
|
-
function getDefaultSizeToken(font) {
|
|
46
|
-
if (typeof font === "object" && cache.has(font)) {
|
|
47
|
-
return cache.get(font);
|
|
48
|
-
}
|
|
49
|
-
const sizeTokens = "$true" in font.size ? font.size : getTokens().size;
|
|
50
|
-
const sizeDefault = sizeTokens["$true"];
|
|
51
|
-
const sizeDefaultSpecific = sizeDefault ? Object.keys(sizeTokens).find(
|
|
52
|
-
(x) => x !== "$true" && sizeTokens[x]["val"] === sizeDefault["val"]
|
|
53
|
-
) : null;
|
|
54
|
-
if (!sizeDefault || !sizeDefaultSpecific) {
|
|
55
|
-
if (process.env.NODE_ENV === "development") {
|
|
56
|
-
console.warn(`No default size is set in your tokens for the "true" key, fonts will be inconsistent.
|
|
1
|
+
import{getTokens as m,getVariableValue as F}from"@tamagui/core";const v=(n="$true",{fonts:i,props:e})=>{var l,a,f;const s=F(e.fontFamily)||"$body",t=i[s]||i.$body;if(!t)return process.env.NODE_ENV==="development"&&console.warn("\u26A0\uFE0F no font found",{family:s,fontTokens:Object.keys(i),sizeTokenIn:n}),{};const u=t.family,o=n==="$true"?h(t):n,y=e.fontSize||t.size[o],g=e.lineHeight||t.lineHeight[o],z=e.fontWeight||t.weight[o],S=e.letterSpacing||t.letterSpacing[o],d=e.fontStyle||((l=t.style)==null?void 0:l[o]),k=e.textTransform||((a=t.transform)==null?void 0:a[o]),c={color:e.color||((f=t.color)==null?void 0:f[o]),fontStyle:d,textTransform:k,fontFamily:u,fontWeight:z,letterSpacing:S,fontSize:y,lineHeight:g};return process.env.NODE_ENV==="development"&&e.debug&&(console.groupCollapsed(" \u{1F539} getFontSized",n,o),console.log({style:c,props:e,font:t}),console.groupEnd()),c},r=new WeakMap;function h(n){if(typeof n=="object"&&r.has(n))return r.get(n);const i="$true"in n.size?n.size:m().size,e=i.$true,s=e?Object.keys(i).find(t=>t!=="$true"&&i[t].val===e.val):null;return!e||!s?(process.env.NODE_ENV==="development"&&console.warn(`No default size is set in your tokens for the "true" key, fonts will be inconsistent.
|
|
57
2
|
|
|
58
3
|
Fix this by having consistent tokens across fonts and sizes and setting a true key for your size tokens, or
|
|
59
|
-
set true keys for all your font tokens: "size", "lineHeight", "fontStyle", etc.`);
|
|
60
|
-
}
|
|
61
|
-
return Object.keys(font.size)[3];
|
|
62
|
-
}
|
|
63
|
-
cache.set(font, sizeDefaultSpecific);
|
|
64
|
-
return sizeDefaultSpecific;
|
|
65
|
-
}
|
|
66
|
-
export {
|
|
67
|
-
getFontSized
|
|
68
|
-
};
|
|
4
|
+
set true keys for all your font tokens: "size", "lineHeight", "fontStyle", etc.`),Object.keys(n.size)[3]):(r.set(n,s),s)}export{v as getFontSized};
|
|
69
5
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["import { getTokens, getVariableValue } from '@tamagui/core'\nimport type {\n FontSizeTokens,\n GenericFont,\n TextProps,\n VariantSpreadFunction,\n} from '@tamagui/core'\n\nexport const getFontSized: VariantSpreadFunction<TextProps, FontSizeTokens> = (\n sizeTokenIn = '$true',\n { fonts, props }\n) => {\n const family = getVariableValue(props.fontFamily) || '$body'\n const font = fonts[family] || fonts['$body']\n if (!font) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('\u26A0\uFE0F no font found', {\n family,\n fontTokens: Object.keys(fonts),\n sizeTokenIn,\n })\n }\n return {} as any\n }\n const fontFamily = font.family\n const sizeToken = sizeTokenIn === '$true' ? getDefaultSizeToken(font) : sizeTokenIn\n const fontSize = props.fontSize || font.size[sizeToken]\n const lineHeight = props.lineHeight || font.lineHeight[sizeToken]\n const fontWeight = props.fontWeight || font.weight[sizeToken]\n const letterSpacing = props.letterSpacing || font.letterSpacing[sizeToken]\n const fontStyle = props.fontStyle || font.style?.[sizeToken]\n const textTransform = props.textTransform || font.transform?.[sizeToken]\n const color = props.color || font.color?.[sizeToken]\n\n const style = {\n color,\n fontStyle,\n textTransform,\n fontFamily,\n fontWeight,\n letterSpacing,\n fontSize,\n lineHeight,\n }\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 getFontSized', sizeTokenIn, sizeToken)\n // eslint-disable-next-line no-console\n console.log({ style, props, font })\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n return style\n}\n\nconst cache = new WeakMap<any, FontSizeTokens>()\n\nfunction getDefaultSizeToken(font: GenericFont) {\n if (typeof font === 'object' && cache.has(font)) {\n return cache.get(font)!\n }\n\n // use either font.size if it has true set, or fallback to tokens.size mapping to the same\n const sizeTokens = '$true' in font.size ? font.size : getTokens().size\n const sizeDefault = sizeTokens['$true']\n const sizeDefaultSpecific = sizeDefault\n ? Object.keys(sizeTokens).find(\n (x) => x !== '$true' && sizeTokens[x]['val'] === sizeDefault['val']\n )\n : null\n\n if (!sizeDefault || !sizeDefaultSpecific) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(`No default size is set in your tokens for the \"true\" key, fonts will be inconsistent.\n\n Fix this by having consistent tokens across fonts and sizes and setting a true key for your size tokens, or\n set true keys for all your font tokens: \"size\", \"lineHeight\", \"fontStyle\", etc.`)\n }\n return Object.keys(font.size)[3]\n }\n\n cache.set(font, sizeDefaultSpecific as FontSizeTokens)\n return sizeDefaultSpecific\n}\n"],
|
|
5
|
-
"mappings": "AAAA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAAA,OAAS,aAAAA,EAAW,oBAAAC,MAAwB,gBAQrC,MAAMC,EAAiE,CAC5EC,EAAc,QACd,CAAE,MAAAC,EAAO,MAAAC,CAAM,IACZ,CAXL,IAAAC,EAAAC,EAAAC,EAYE,MAAMC,EAASR,EAAiBI,EAAM,UAAU,GAAK,QAC/CK,EAAON,EAAMK,CAAM,GAAKL,EAAM,MACpC,GAAI,CAACM,EACH,OAAI,QAAQ,IAAI,WAAa,eAE3B,QAAQ,KAAK,6BAAoB,CAC/B,OAAAD,EACA,WAAY,OAAO,KAAKL,CAAK,EAC7B,YAAAD,CACF,CAAC,EAEI,CAAC,EAEV,MAAMQ,EAAaD,EAAK,OAClBE,EAAYT,IAAgB,QAAUU,EAAoBH,CAAI,EAAIP,EAClEW,EAAWT,EAAM,UAAYK,EAAK,KAAKE,CAAS,EAChDG,EAAaV,EAAM,YA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font", "fontFamily", "sizeToken", "getDefaultSizeToken", "fontSize", "lineHeight", "fontWeight", "letterSpacing", "fontStyle", "textTransform", "style", "cache", "sizeTokens", "sizeDefault", "sizeDefaultSpecific", "x"]
|
|
7
7
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,69 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
const getFontSized = (sizeTokenIn = "$true", { fonts, props }) => {
|
|
3
|
-
var _a, _b, _c;
|
|
4
|
-
const family = getVariableValue(props.fontFamily) || "$body";
|
|
5
|
-
const font = fonts[family] || fonts["$body"];
|
|
6
|
-
if (!font) {
|
|
7
|
-
if (process.env.NODE_ENV === "development") {
|
|
8
|
-
console.warn("\u26A0\uFE0F no font found", {
|
|
9
|
-
family,
|
|
10
|
-
fontTokens: Object.keys(fonts),
|
|
11
|
-
sizeTokenIn
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
const fontFamily = font.family;
|
|
17
|
-
const sizeToken = sizeTokenIn === "$true" ? getDefaultSizeToken(font) : sizeTokenIn;
|
|
18
|
-
const fontSize = props.fontSize || font.size[sizeToken];
|
|
19
|
-
const lineHeight = props.lineHeight || font.lineHeight[sizeToken];
|
|
20
|
-
const fontWeight = props.fontWeight || font.weight[sizeToken];
|
|
21
|
-
const letterSpacing = props.letterSpacing || font.letterSpacing[sizeToken];
|
|
22
|
-
const fontStyle = props.fontStyle || ((_a = font.style) == null ? void 0 : _a[sizeToken]);
|
|
23
|
-
const textTransform = props.textTransform || ((_b = font.transform) == null ? void 0 : _b[sizeToken]);
|
|
24
|
-
const color = props.color || ((_c = font.color) == null ? void 0 : _c[sizeToken]);
|
|
25
|
-
const style = {
|
|
26
|
-
color,
|
|
27
|
-
fontStyle,
|
|
28
|
-
textTransform,
|
|
29
|
-
fontFamily,
|
|
30
|
-
fontWeight,
|
|
31
|
-
letterSpacing,
|
|
32
|
-
fontSize,
|
|
33
|
-
lineHeight
|
|
34
|
-
};
|
|
35
|
-
if (process.env.NODE_ENV === "development") {
|
|
36
|
-
if (props["debug"]) {
|
|
37
|
-
console.groupCollapsed(" \u{1F539} getFontSized", sizeTokenIn, sizeToken);
|
|
38
|
-
console.log({ style, props, font });
|
|
39
|
-
console.groupEnd();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return style;
|
|
43
|
-
};
|
|
44
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
45
|
-
function getDefaultSizeToken(font) {
|
|
46
|
-
if (typeof font === "object" && cache.has(font)) {
|
|
47
|
-
return cache.get(font);
|
|
48
|
-
}
|
|
49
|
-
const sizeTokens = "$true" in font.size ? font.size : getTokens().size;
|
|
50
|
-
const sizeDefault = sizeTokens["$true"];
|
|
51
|
-
const sizeDefaultSpecific = sizeDefault ? Object.keys(sizeTokens).find(
|
|
52
|
-
(x) => x !== "$true" && sizeTokens[x]["val"] === sizeDefault["val"]
|
|
53
|
-
) : null;
|
|
54
|
-
if (!sizeDefault || !sizeDefaultSpecific) {
|
|
55
|
-
if (process.env.NODE_ENV === "development") {
|
|
56
|
-
console.warn(`No default size is set in your tokens for the "true" key, fonts will be inconsistent.
|
|
1
|
+
import{getTokens as m,getVariableValue as F}from"@tamagui/core";const v=(n="$true",{fonts:i,props:e})=>{var l,a,f;const s=F(e.fontFamily)||"$body",t=i[s]||i.$body;if(!t)return process.env.NODE_ENV==="development"&&console.warn("\u26A0\uFE0F no font found",{family:s,fontTokens:Object.keys(i),sizeTokenIn:n}),{};const u=t.family,o=n==="$true"?h(t):n,y=e.fontSize||t.size[o],g=e.lineHeight||t.lineHeight[o],z=e.fontWeight||t.weight[o],S=e.letterSpacing||t.letterSpacing[o],d=e.fontStyle||((l=t.style)==null?void 0:l[o]),k=e.textTransform||((a=t.transform)==null?void 0:a[o]),c={color:e.color||((f=t.color)==null?void 0:f[o]),fontStyle:d,textTransform:k,fontFamily:u,fontWeight:z,letterSpacing:S,fontSize:y,lineHeight:g};return process.env.NODE_ENV==="development"&&e.debug&&(console.groupCollapsed(" \u{1F539} getFontSized",n,o),console.log({style:c,props:e,font:t}),console.groupEnd()),c},r=new WeakMap;function h(n){if(typeof n=="object"&&r.has(n))return r.get(n);const i="$true"in n.size?n.size:m().size,e=i.$true,s=e?Object.keys(i).find(t=>t!=="$true"&&i[t].val===e.val):null;return!e||!s?(process.env.NODE_ENV==="development"&&console.warn(`No default size is set in your tokens for the "true" key, fonts will be inconsistent.
|
|
57
2
|
|
|
58
3
|
Fix this by having consistent tokens across fonts and sizes and setting a true key for your size tokens, or
|
|
59
|
-
set true keys for all your font tokens: "size", "lineHeight", "fontStyle", etc.`);
|
|
60
|
-
}
|
|
61
|
-
return Object.keys(font.size)[3];
|
|
62
|
-
}
|
|
63
|
-
cache.set(font, sizeDefaultSpecific);
|
|
64
|
-
return sizeDefaultSpecific;
|
|
65
|
-
}
|
|
66
|
-
export {
|
|
67
|
-
getFontSized
|
|
68
|
-
};
|
|
4
|
+
set true keys for all your font tokens: "size", "lineHeight", "fontStyle", etc.`),Object.keys(n.size)[3]):(r.set(n,s),s)}export{v as getFontSized};
|
|
69
5
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["import { getTokens, getVariableValue } from '@tamagui/core'\nimport type {\n FontSizeTokens,\n GenericFont,\n TextProps,\n VariantSpreadFunction,\n} from '@tamagui/core'\n\nexport const getFontSized: VariantSpreadFunction<TextProps, FontSizeTokens> = (\n sizeTokenIn = '$true',\n { fonts, props }\n) => {\n const family = getVariableValue(props.fontFamily) || '$body'\n const font = fonts[family] || fonts['$body']\n if (!font) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('\u26A0\uFE0F no font found', {\n family,\n fontTokens: Object.keys(fonts),\n sizeTokenIn,\n })\n }\n return {} as any\n }\n const fontFamily = font.family\n const sizeToken = sizeTokenIn === '$true' ? getDefaultSizeToken(font) : sizeTokenIn\n const fontSize = props.fontSize || font.size[sizeToken]\n const lineHeight = props.lineHeight || font.lineHeight[sizeToken]\n const fontWeight = props.fontWeight || font.weight[sizeToken]\n const letterSpacing = props.letterSpacing || font.letterSpacing[sizeToken]\n const fontStyle = props.fontStyle || font.style?.[sizeToken]\n const textTransform = props.textTransform || font.transform?.[sizeToken]\n const color = props.color || font.color?.[sizeToken]\n\n const style = {\n color,\n fontStyle,\n textTransform,\n fontFamily,\n fontWeight,\n letterSpacing,\n fontSize,\n lineHeight,\n }\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 getFontSized', sizeTokenIn, sizeToken)\n // eslint-disable-next-line no-console\n console.log({ style, props, font })\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n return style\n}\n\nconst cache = new WeakMap<any, FontSizeTokens>()\n\nfunction getDefaultSizeToken(font: GenericFont) {\n if (typeof font === 'object' && cache.has(font)) {\n return cache.get(font)!\n }\n\n // use either font.size if it has true set, or fallback to tokens.size mapping to the same\n const sizeTokens = '$true' in font.size ? font.size : getTokens().size\n const sizeDefault = sizeTokens['$true']\n const sizeDefaultSpecific = sizeDefault\n ? Object.keys(sizeTokens).find(\n (x) => x !== '$true' && sizeTokens[x]['val'] === sizeDefault['val']\n )\n : null\n\n if (!sizeDefault || !sizeDefaultSpecific) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(`No default size is set in your tokens for the \"true\" key, fonts will be inconsistent.\n\n Fix this by having consistent tokens across fonts and sizes and setting a true key for your size tokens, or\n set true keys for all your font tokens: \"size\", \"lineHeight\", \"fontStyle\", etc.`)\n }\n return Object.keys(font.size)[3]\n }\n\n cache.set(font, sizeDefaultSpecific as FontSizeTokens)\n return sizeDefaultSpecific\n}\n"],
|
|
5
|
-
"mappings": "AAAA,
|
|
6
|
-
"names": []
|
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OA,GAAS,UAAYW,EAAM,IAAIX,CAAI,EAC5C,OAAOW,EAAM,IAAIX,CAAI,EAIvB,MAAMY,EAAa,UAAWZ,EAAK,KAAOA,EAAK,KAAOV,EAAU,EAAE,KAC5DuB,EAAcD,EAAW,MACzBE,EAAsBD,EACxB,OAAO,KAAKD,CAAU,EAAE,KACrBG,GAAMA,IAAM,SAAWH,EAAWG,CAAC,EAAE,MAAWF,EAAY,GAC/D,EACA,KAEJ,MAAI,CAACA,GAAe,CAACC,GACf,QAAQ,IAAI,WAAa,eAC3B,QAAQ,KAAK;AAAA;AAAA;AAAA,sFAGmE,EAE3E,OAAO,KAAKd,EAAK,IAAI,EAAE,CAAC,IAGjCW,EAAM,IAAIX,EAAMc,CAAqC,EAC9CA,EACT",
|
|
6
|
+
"names": ["getTokens", "getVariableValue", "getFontSized", "sizeTokenIn", "fonts", "props", "_a", "_b", "_c", "family", "font", "fontFamily", "sizeToken", "getDefaultSizeToken", "fontSize", "lineHeight", "fontWeight", "letterSpacing", "fontStyle", "textTransform", "style", "cache", "sizeTokens", "sizeDefault", "sizeDefaultSpecific", "x"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/get-font-sized",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.4",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"clean:build": "tamagui-build clean:build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@tamagui/core": "1.13.
|
|
21
|
+
"@tamagui/core": "1.13.4"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@tamagui/build": "1.13.
|
|
24
|
+
"@tamagui/build": "1.13.4",
|
|
25
25
|
"@types/react": "^18.0.15",
|
|
26
26
|
"react": "^18.2.0"
|
|
27
27
|
},
|