@tamagui/font-size 1.0.1-beta.100

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.
@@ -0,0 +1,70 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var getFontSize_exports = {};
19
+ __export(getFontSize_exports, {
20
+ getFontSize: () => getFontSize,
21
+ getFontSizeToken: () => getFontSizeToken,
22
+ getFontSizeVariable: () => getFontSizeVariable
23
+ });
24
+ module.exports = __toCommonJS(getFontSize_exports);
25
+ var import_core = require("@tamagui/core");
26
+ const getFontSize = (inSize, opts) => {
27
+ const res = getFontSizeVariable(inSize, opts);
28
+ if ((0, import_core.isVariable)(res)) {
29
+ return +res.val;
30
+ }
31
+ return res ? +res : 16;
32
+ };
33
+ const getFontSizeVariable = (inSize, opts) => {
34
+ const token = getFontSizeToken(inSize, opts);
35
+ if (!token) {
36
+ return inSize;
37
+ }
38
+ const conf = (0, import_core.getConfig)();
39
+ return conf.fontsParsed[(opts == null ? void 0 : opts.font) || "$body"].size[token];
40
+ };
41
+ const getFontSizeToken = (inSize, opts) => {
42
+ if (typeof inSize === "number") {
43
+ return null;
44
+ }
45
+ const size = inSize || "$4";
46
+ const relativeSize = (opts == null ? void 0 : opts.relativeSize) || 0;
47
+ const conf = (0, import_core.getConfig)();
48
+ const fontSize = conf.fontsParsed[(opts == null ? void 0 : opts.font) || "$body"].size;
49
+ const sizeTokens = Object.keys(fontSize);
50
+ let foundIndex = sizeTokens.indexOf(size);
51
+ if (foundIndex === -1) {
52
+ if (size.endsWith(".5")) {
53
+ foundIndex = sizeTokens.indexOf(size.replace(".5", ""));
54
+ }
55
+ }
56
+ if (process.env.NODE_ENV === "development") {
57
+ if (foundIndex === -1) {
58
+ console.warn("No font size found", inSize, opts, "in size tokens", sizeTokens);
59
+ }
60
+ }
61
+ const tokenIndex = Math.min(Math.max(0, foundIndex + relativeSize), sizeTokens.length - 1);
62
+ return sizeTokens[tokenIndex] ?? size;
63
+ };
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ getFontSize,
67
+ getFontSizeToken,
68
+ getFontSizeVariable
69
+ });
70
+ //# sourceMappingURL=getFontSize.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/getFontSize.ts"],
4
+ "sourcesContent": ["import { FontSizeTokens, FontTokens, getConfig, getTokens, isVariable } from '@tamagui/core'\n\ntype GetFontSizeOpts = {\n relativeSize?: number\n font?: FontTokens\n}\n\nexport const getFontSize = (\n inSize: FontSizeTokens | null | undefined,\n opts?: GetFontSizeOpts\n): number => {\n const res = getFontSizeVariable(inSize, opts)\n if (isVariable(res)) {\n return +res.val\n }\n return res ? +res : 16\n}\n\nexport const getFontSizeVariable = (\n inSize: FontSizeTokens | null | undefined,\n opts?: GetFontSizeOpts\n) => {\n const token = getFontSizeToken(inSize, opts)\n if (!token) {\n return inSize\n }\n const conf = getConfig()\n return conf.fontsParsed[opts?.font || '$body'].size[token]\n}\n\nexport const getFontSizeToken = (\n inSize: FontSizeTokens | null | undefined,\n opts?: GetFontSizeOpts\n): FontSizeTokens | null => {\n if (typeof inSize === 'number') {\n return null\n }\n const size = inSize || '$4'\n const relativeSize = opts?.relativeSize || 0\n const conf = getConfig()\n const fontSize = conf.fontsParsed[opts?.font || '$body'].size\n const sizeTokens = Object.keys(fontSize)\n let foundIndex = sizeTokens.indexOf(size)\n if (foundIndex === -1) {\n if (size.endsWith('.5')) {\n foundIndex = sizeTokens.indexOf(size.replace('.5', ''))\n }\n }\n if (process.env.NODE_ENV === 'development') {\n if (foundIndex === -1) {\n console.warn('No font size found', inSize, opts, 'in size tokens', sizeTokens)\n }\n }\n const tokenIndex = Math.min(Math.max(0, foundIndex + relativeSize), sizeTokens.length - 1)\n return (sizeTokens[tokenIndex] ?? size) as FontSizeTokens\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6E;AAOtE,MAAM,cAAc,CACzB,QACA,SACW;AACX,QAAM,MAAM,oBAAoB,QAAQ,IAAI;AAC5C,MAAI,4BAAW,GAAG,GAAG;AACnB,WAAO,CAAC,IAAI;AAAA,EACd;AACA,SAAO,MAAM,CAAC,MAAM;AACtB;AAEO,MAAM,sBAAsB,CACjC,QACA,SACG;AACH,QAAM,QAAQ,iBAAiB,QAAQ,IAAI;AAC3C,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,QAAM,OAAO,2BAAU;AACvB,SAAO,KAAK,YAAY,8BAAM,SAAQ,SAAS,KAAK;AACtD;AAEO,MAAM,mBAAmB,CAC9B,QACA,SAC0B;AAC1B,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,EACT;AACA,QAAM,OAAO,UAAU;AACvB,QAAM,eAAe,8BAAM,iBAAgB;AAC3C,QAAM,OAAO,2BAAU;AACvB,QAAM,WAAW,KAAK,YAAY,8BAAM,SAAQ,SAAS;AACzD,QAAM,aAAa,OAAO,KAAK,QAAQ;AACvC,MAAI,aAAa,WAAW,QAAQ,IAAI;AACxC,MAAI,eAAe,IAAI;AACrB,QAAI,KAAK,SAAS,IAAI,GAAG;AACvB,mBAAa,WAAW,QAAQ,KAAK,QAAQ,MAAM,EAAE,CAAC;AAAA,IACxD;AAAA,EACF;AACA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,eAAe,IAAI;AACrB,cAAQ,KAAK,sBAAsB,QAAQ,MAAM,kBAAkB,UAAU;AAAA,IAC/E;AAAA,EACF;AACA,QAAM,aAAa,KAAK,IAAI,KAAK,IAAI,GAAG,aAAa,YAAY,GAAG,WAAW,SAAS,CAAC;AACzF,SAAQ,WAAW,eAAe;AACpC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,18 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var src_exports = {};
16
+ module.exports = __toCommonJS(src_exports);
17
+ __reExport(src_exports, require("./getFontSize"), module.exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './getFontSize'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,0BAAd;",
6
+ "names": []
7
+ }
@@ -0,0 +1,45 @@
1
+ import { getConfig, isVariable } from "@tamagui/core";
2
+ const getFontSize = (inSize, opts) => {
3
+ const res = getFontSizeVariable(inSize, opts);
4
+ if (isVariable(res)) {
5
+ return +res.val;
6
+ }
7
+ return res ? +res : 16;
8
+ };
9
+ const getFontSizeVariable = (inSize, opts) => {
10
+ const token = getFontSizeToken(inSize, opts);
11
+ if (!token) {
12
+ return inSize;
13
+ }
14
+ const conf = getConfig();
15
+ return conf.fontsParsed[(opts == null ? void 0 : opts.font) || "$body"].size[token];
16
+ };
17
+ const getFontSizeToken = (inSize, opts) => {
18
+ if (typeof inSize === "number") {
19
+ return null;
20
+ }
21
+ const size = inSize || "$4";
22
+ const relativeSize = (opts == null ? void 0 : opts.relativeSize) || 0;
23
+ const conf = getConfig();
24
+ const fontSize = conf.fontsParsed[(opts == null ? void 0 : opts.font) || "$body"].size;
25
+ const sizeTokens = Object.keys(fontSize);
26
+ let foundIndex = sizeTokens.indexOf(size);
27
+ if (foundIndex === -1) {
28
+ if (size.endsWith(".5")) {
29
+ foundIndex = sizeTokens.indexOf(size.replace(".5", ""));
30
+ }
31
+ }
32
+ if (process.env.NODE_ENV === "development") {
33
+ if (foundIndex === -1) {
34
+ console.warn("No font size found", inSize, opts, "in size tokens", sizeTokens);
35
+ }
36
+ }
37
+ const tokenIndex = Math.min(Math.max(0, foundIndex + relativeSize), sizeTokens.length - 1);
38
+ return sizeTokens[tokenIndex] ?? size;
39
+ };
40
+ export {
41
+ getFontSize,
42
+ getFontSizeToken,
43
+ getFontSizeVariable
44
+ };
45
+ //# sourceMappingURL=getFontSize.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/getFontSize.ts"],
4
+ "sourcesContent": ["import { FontSizeTokens, FontTokens, getConfig, getTokens, isVariable } from '@tamagui/core'\n\ntype GetFontSizeOpts = {\n relativeSize?: number\n font?: FontTokens\n}\n\nexport const getFontSize = (\n inSize: FontSizeTokens | null | undefined,\n opts?: GetFontSizeOpts\n): number => {\n const res = getFontSizeVariable(inSize, opts)\n if (isVariable(res)) {\n return +res.val\n }\n return res ? +res : 16\n}\n\nexport const getFontSizeVariable = (\n inSize: FontSizeTokens | null | undefined,\n opts?: GetFontSizeOpts\n) => {\n const token = getFontSizeToken(inSize, opts)\n if (!token) {\n return inSize\n }\n const conf = getConfig()\n return conf.fontsParsed[opts?.font || '$body'].size[token]\n}\n\nexport const getFontSizeToken = (\n inSize: FontSizeTokens | null | undefined,\n opts?: GetFontSizeOpts\n): FontSizeTokens | null => {\n if (typeof inSize === 'number') {\n return null\n }\n const size = inSize || '$4'\n const relativeSize = opts?.relativeSize || 0\n const conf = getConfig()\n const fontSize = conf.fontsParsed[opts?.font || '$body'].size\n const sizeTokens = Object.keys(fontSize)\n let foundIndex = sizeTokens.indexOf(size)\n if (foundIndex === -1) {\n if (size.endsWith('.5')) {\n foundIndex = sizeTokens.indexOf(size.replace('.5', ''))\n }\n }\n if (process.env.NODE_ENV === 'development') {\n if (foundIndex === -1) {\n console.warn('No font size found', inSize, opts, 'in size tokens', sizeTokens)\n }\n }\n const tokenIndex = Math.min(Math.max(0, foundIndex + relativeSize), sizeTokens.length - 1)\n return (sizeTokens[tokenIndex] ?? size) as FontSizeTokens\n}\n"],
5
+ "mappings": "AAAA;AAOO,MAAM,cAAc,CACzB,QACA,SACW;AACX,QAAM,MAAM,oBAAoB,QAAQ,IAAI;AAC5C,MAAI,WAAW,GAAG,GAAG;AACnB,WAAO,CAAC,IAAI;AAAA,EACd;AACA,SAAO,MAAM,CAAC,MAAM;AACtB;AAEO,MAAM,sBAAsB,CACjC,QACA,SACG;AACH,QAAM,QAAQ,iBAAiB,QAAQ,IAAI;AAC3C,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,QAAM,OAAO,UAAU;AACvB,SAAO,KAAK,YAAY,8BAAM,SAAQ,SAAS,KAAK;AACtD;AAEO,MAAM,mBAAmB,CAC9B,QACA,SAC0B;AAC1B,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,EACT;AACA,QAAM,OAAO,UAAU;AACvB,QAAM,eAAe,8BAAM,iBAAgB;AAC3C,QAAM,OAAO,UAAU;AACvB,QAAM,WAAW,KAAK,YAAY,8BAAM,SAAQ,SAAS;AACzD,QAAM,aAAa,OAAO,KAAK,QAAQ;AACvC,MAAI,aAAa,WAAW,QAAQ,IAAI;AACxC,MAAI,eAAe,IAAI;AACrB,QAAI,KAAK,SAAS,IAAI,GAAG;AACvB,mBAAa,WAAW,QAAQ,KAAK,QAAQ,MAAM,EAAE,CAAC;AAAA,IACxD;AAAA,EACF;AACA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,eAAe,IAAI;AACrB,cAAQ,KAAK,sBAAsB,QAAQ,MAAM,kBAAkB,UAAU;AAAA,IAC/E;AAAA,EACF;AACA,QAAM,aAAa,KAAK,IAAI,KAAK,IAAI,GAAG,aAAa,YAAY,GAAG,WAAW,SAAS,CAAC;AACzF,SAAQ,WAAW,eAAe;AACpC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./getFontSize";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './getFontSize'\n"],
5
+ "mappings": "AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,46 @@
1
+ import { getConfig, isVariable } from "@tamagui/core";
2
+ const getFontSize = (inSize, opts) => {
3
+ const res = getFontSizeVariable(inSize, opts);
4
+ if (isVariable(res)) {
5
+ return +res.val;
6
+ }
7
+ return res ? +res : 16;
8
+ };
9
+ const getFontSizeVariable = (inSize, opts) => {
10
+ const token = getFontSizeToken(inSize, opts);
11
+ if (!token) {
12
+ return inSize;
13
+ }
14
+ const conf = getConfig();
15
+ return conf.fontsParsed[(opts == null ? void 0 : opts.font) || "$body"].size[token];
16
+ };
17
+ const getFontSizeToken = (inSize, opts) => {
18
+ var _a;
19
+ if (typeof inSize === "number") {
20
+ return null;
21
+ }
22
+ const size = inSize || "$4";
23
+ const relativeSize = (opts == null ? void 0 : opts.relativeSize) || 0;
24
+ const conf = getConfig();
25
+ const fontSize = conf.fontsParsed[(opts == null ? void 0 : opts.font) || "$body"].size;
26
+ const sizeTokens = Object.keys(fontSize);
27
+ let foundIndex = sizeTokens.indexOf(size);
28
+ if (foundIndex === -1) {
29
+ if (size.endsWith(".5")) {
30
+ foundIndex = sizeTokens.indexOf(size.replace(".5", ""));
31
+ }
32
+ }
33
+ if (process.env.NODE_ENV === "development") {
34
+ if (foundIndex === -1) {
35
+ console.warn("No font size found", inSize, opts, "in size tokens", sizeTokens);
36
+ }
37
+ }
38
+ const tokenIndex = Math.min(Math.max(0, foundIndex + relativeSize), sizeTokens.length - 1);
39
+ return (_a = sizeTokens[tokenIndex]) != null ? _a : size;
40
+ };
41
+ export {
42
+ getFontSize,
43
+ getFontSizeToken,
44
+ getFontSizeVariable
45
+ };
46
+ //# sourceMappingURL=getFontSize.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/getFontSize.ts"],
4
+ "sourcesContent": ["import { FontSizeTokens, FontTokens, getConfig, getTokens, isVariable } from '@tamagui/core'\n\ntype GetFontSizeOpts = {\n relativeSize?: number\n font?: FontTokens\n}\n\nexport const getFontSize = (\n inSize: FontSizeTokens | null | undefined,\n opts?: GetFontSizeOpts\n): number => {\n const res = getFontSizeVariable(inSize, opts)\n if (isVariable(res)) {\n return +res.val\n }\n return res ? +res : 16\n}\n\nexport const getFontSizeVariable = (\n inSize: FontSizeTokens | null | undefined,\n opts?: GetFontSizeOpts\n) => {\n const token = getFontSizeToken(inSize, opts)\n if (!token) {\n return inSize\n }\n const conf = getConfig()\n return conf.fontsParsed[opts?.font || '$body'].size[token]\n}\n\nexport const getFontSizeToken = (\n inSize: FontSizeTokens | null | undefined,\n opts?: GetFontSizeOpts\n): FontSizeTokens | null => {\n if (typeof inSize === 'number') {\n return null\n }\n const size = inSize || '$4'\n const relativeSize = opts?.relativeSize || 0\n const conf = getConfig()\n const fontSize = conf.fontsParsed[opts?.font || '$body'].size\n const sizeTokens = Object.keys(fontSize)\n let foundIndex = sizeTokens.indexOf(size)\n if (foundIndex === -1) {\n if (size.endsWith('.5')) {\n foundIndex = sizeTokens.indexOf(size.replace('.5', ''))\n }\n }\n if (process.env.NODE_ENV === 'development') {\n if (foundIndex === -1) {\n console.warn('No font size found', inSize, opts, 'in size tokens', sizeTokens)\n }\n }\n const tokenIndex = Math.min(Math.max(0, foundIndex + relativeSize), sizeTokens.length - 1)\n return (sizeTokens[tokenIndex] ?? size) as FontSizeTokens\n}\n"],
5
+ "mappings": "AAAA;AAOO,MAAM,cAAc,CACzB,QACA,SACW;AACX,QAAM,MAAM,oBAAoB,QAAQ,IAAI;AAC5C,MAAI,WAAW,GAAG,GAAG;AACnB,WAAO,CAAC,IAAI;AAAA,EACd;AACA,SAAO,MAAM,CAAC,MAAM;AACtB;AAEO,MAAM,sBAAsB,CACjC,QACA,SACG;AACH,QAAM,QAAQ,iBAAiB,QAAQ,IAAI;AAC3C,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,QAAM,OAAO,UAAU;AACvB,SAAO,KAAK,YAAY,8BAAM,SAAQ,SAAS,KAAK;AACtD;AAEO,MAAM,mBAAmB,CAC9B,QACA,SAC0B;AAjC5B;AAkCE,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,EACT;AACA,QAAM,OAAO,UAAU;AACvB,QAAM,eAAe,8BAAM,iBAAgB;AAC3C,QAAM,OAAO,UAAU;AACvB,QAAM,WAAW,KAAK,YAAY,8BAAM,SAAQ,SAAS;AACzD,QAAM,aAAa,OAAO,KAAK,QAAQ;AACvC,MAAI,aAAa,WAAW,QAAQ,IAAI;AACxC,MAAI,eAAe,IAAI;AACrB,QAAI,KAAK,SAAS,IAAI,GAAG;AACvB,mBAAa,WAAW,QAAQ,KAAK,QAAQ,MAAM,EAAE,CAAC;AAAA,IACxD;AAAA,EACF;AACA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,eAAe,IAAI;AACrB,cAAQ,KAAK,sBAAsB,QAAQ,MAAM,kBAAkB,UAAU;AAAA,IAC/E;AAAA,EACF;AACA,QAAM,aAAa,KAAK,IAAI,KAAK,IAAI,GAAG,aAAa,YAAY,GAAG,WAAW,SAAS,CAAC;AACzF,SAAQ,iBAAW,gBAAX,YAA0B;AACpC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./getFontSize";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './getFontSize'\n"],
5
+ "mappings": "AAAA;",
6
+ "names": []
7
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@tamagui/font-size",
3
+ "version": "1.0.1-beta.100",
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/core": "^1.0.1-beta.100"
21
+ },
22
+ "peerDependencies": {
23
+ "react": "*",
24
+ "react-dom": "*"
25
+ },
26
+ "devDependencies": {
27
+ "@tamagui/build": "^1.0.1-beta.100",
28
+ "react": "*",
29
+ "react-dom": "*"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }
@@ -0,0 +1,56 @@
1
+ import { FontSizeTokens, FontTokens, getConfig, getTokens, isVariable } from '@tamagui/core'
2
+
3
+ type GetFontSizeOpts = {
4
+ relativeSize?: number
5
+ font?: FontTokens
6
+ }
7
+
8
+ export const getFontSize = (
9
+ inSize: FontSizeTokens | null | undefined,
10
+ opts?: GetFontSizeOpts
11
+ ): number => {
12
+ const res = getFontSizeVariable(inSize, opts)
13
+ if (isVariable(res)) {
14
+ return +res.val
15
+ }
16
+ return res ? +res : 16
17
+ }
18
+
19
+ export const getFontSizeVariable = (
20
+ inSize: FontSizeTokens | null | undefined,
21
+ opts?: GetFontSizeOpts
22
+ ) => {
23
+ const token = getFontSizeToken(inSize, opts)
24
+ if (!token) {
25
+ return inSize
26
+ }
27
+ const conf = getConfig()
28
+ return conf.fontsParsed[opts?.font || '$body'].size[token]
29
+ }
30
+
31
+ export const getFontSizeToken = (
32
+ inSize: FontSizeTokens | null | undefined,
33
+ opts?: GetFontSizeOpts
34
+ ): FontSizeTokens | null => {
35
+ if (typeof inSize === 'number') {
36
+ return null
37
+ }
38
+ const size = inSize || '$4'
39
+ const relativeSize = opts?.relativeSize || 0
40
+ const conf = getConfig()
41
+ const fontSize = conf.fontsParsed[opts?.font || '$body'].size
42
+ const sizeTokens = Object.keys(fontSize)
43
+ let foundIndex = sizeTokens.indexOf(size)
44
+ if (foundIndex === -1) {
45
+ if (size.endsWith('.5')) {
46
+ foundIndex = sizeTokens.indexOf(size.replace('.5', ''))
47
+ }
48
+ }
49
+ if (process.env.NODE_ENV === 'development') {
50
+ if (foundIndex === -1) {
51
+ console.warn('No font size found', inSize, opts, 'in size tokens', sizeTokens)
52
+ }
53
+ }
54
+ const tokenIndex = Math.min(Math.max(0, foundIndex + relativeSize), sizeTokens.length - 1)
55
+ return (sizeTokens[tokenIndex] ?? size) as FontSizeTokens
56
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './getFontSize'
@@ -0,0 +1,10 @@
1
+ import { FontSizeTokens, FontTokens } from '@tamagui/core';
2
+ declare type GetFontSizeOpts = {
3
+ relativeSize?: number;
4
+ font?: FontTokens;
5
+ };
6
+ export declare const getFontSize: (inSize: FontSizeTokens | null | undefined, opts?: GetFontSizeOpts) => number;
7
+ export declare const getFontSizeVariable: (inSize: FontSizeTokens | null | undefined, opts?: GetFontSizeOpts) => number | `$${string}` | import("@tamagui/core").Variable<any> | null | undefined;
8
+ export declare const getFontSizeToken: (inSize: FontSizeTokens | null | undefined, opts?: GetFontSizeOpts) => FontSizeTokens | null;
9
+ export {};
10
+ //# sourceMappingURL=getFontSize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFontSize.d.ts","sourceRoot":"","sources":["../src/getFontSize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAoC,MAAM,eAAe,CAAA;AAE5F,aAAK,eAAe,GAAG;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,WAAW,WACd,cAAc,GAAG,IAAI,GAAG,SAAS,SAClC,eAAe,KACrB,MAMF,CAAA;AAED,eAAO,MAAM,mBAAmB,WACtB,cAAc,GAAG,IAAI,GAAG,SAAS,SAClC,eAAe,qFAQvB,CAAA;AAED,eAAO,MAAM,gBAAgB,WACnB,cAAc,GAAG,IAAI,GAAG,SAAS,SAClC,eAAe,KACrB,cAAc,GAAG,IAsBnB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './getFontSize';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}