@tamagui/calc 1.0.1-beta.194

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
+ "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
+ calc: () => calc
22
+ });
23
+ module.exports = __toCommonJS(src_exports);
24
+ var import_core = require("@tamagui/core");
25
+ const operators = {
26
+ "+": (a, b) => a + b,
27
+ "-": (a, b) => a - b,
28
+ "/": (a, b) => a / b,
29
+ "*": (a, b) => a * b
30
+ };
31
+ const calc = (...valuesAndOperators) => {
32
+ if (import_core.isWeb) {
33
+ let res2 = "calc(";
34
+ for (const cur of valuesAndOperators) {
35
+ if (operators[cur]) {
36
+ res2 += " " + cur + " ";
37
+ } else {
38
+ res2 += convertToVariableOrNumber(cur);
39
+ }
40
+ }
41
+ return res2 + ")";
42
+ }
43
+ let res = 0;
44
+ let nextOp = null;
45
+ for (const cur of valuesAndOperators) {
46
+ if (operators[cur]) {
47
+ nextOp = operators[cur];
48
+ } else {
49
+ if (nextOp) {
50
+ res = nextOp(res, cur);
51
+ nextOp = null;
52
+ } else {
53
+ res = +cur;
54
+ }
55
+ }
56
+ }
57
+ return res;
58
+ };
59
+ const convertToVariableOrNumber = (v) => {
60
+ const varOrVal = (0, import_core.getVariableVariable)(v);
61
+ if (typeof varOrVal === "number") {
62
+ return `${varOrVal}px`;
63
+ }
64
+ return varOrVal;
65
+ };
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ calc
69
+ });
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["import { getVariableVariable, isWeb } from '@tamagui/core'\nimport type { FontLineHeightTokens, FontSizeTokens, SizeTokens, SpaceTokens } from '@tamagui/core'\n\n// unused code - not exported could be used for cross compat calc() functions\n\n/**\n * Simple calc() that handles native + web\n * on web: outputs a calc() string\n * on native: outputs a plain number\n */\n\nexport type CalcVal =\n | string\n | number\n | SizeTokens\n | SpaceTokens\n | FontSizeTokens\n | FontLineHeightTokens\n\nconst operators = {\n '+': (a: number, b: number) => a + b,\n '-': (a: number, b: number) => a - b,\n '/': (a: number, b: number) => a / b,\n '*': (a: number, b: number) => a * b,\n}\n\ntype Operator = keyof typeof operators\n\nexport const calc = (...valuesAndOperators: (CalcVal | Operator)[]) => {\n if (isWeb) {\n let res = 'calc('\n for (const cur of valuesAndOperators) {\n if (operators[cur as any]) {\n // spaces are significant\n res += ' ' + cur + ' '\n } else {\n res += convertToVariableOrNumber(cur)\n }\n }\n return res + ')'\n }\n\n let res = 0\n let nextOp: any = null\n for (const cur of valuesAndOperators) {\n if (operators[cur as any]) {\n nextOp = operators[cur as any]\n } else {\n if (nextOp) {\n res = nextOp(res, cur)\n nextOp = null\n } else {\n res = +cur\n }\n }\n }\n\n return res\n}\n\nconst convertToVariableOrNumber = (v: any) => {\n const varOrVal = getVariableVariable(v)\n if (typeof varOrVal === 'number') {\n return `${varOrVal}px`\n }\n return varOrVal\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2C;AAmB3C,MAAM,YAAY;AAAA,EAChB,KAAK,CAAC,GAAW,MAAc,IAAI;AAAA,EACnC,KAAK,CAAC,GAAW,MAAc,IAAI;AAAA,EACnC,KAAK,CAAC,GAAW,MAAc,IAAI;AAAA,EACnC,KAAK,CAAC,GAAW,MAAc,IAAI;AACrC;AAIO,MAAM,OAAO,IAAI,uBAA+C;AACrE,MAAI,mBAAO;AACT,QAAIA,OAAM;AACV,eAAW,OAAO,oBAAoB;AACpC,UAAI,UAAU,MAAa;AAEzB,QAAAA,QAAO,MAAM,MAAM;AAAA,MACrB,OAAO;AACL,QAAAA,QAAO,0BAA0B,GAAG;AAAA,MACtC;AAAA,IACF;AACA,WAAOA,OAAM;AAAA,EACf;AAEA,MAAI,MAAM;AACV,MAAI,SAAc;AAClB,aAAW,OAAO,oBAAoB;AACpC,QAAI,UAAU,MAAa;AACzB,eAAS,UAAU;AAAA,IACrB,OAAO;AACL,UAAI,QAAQ;AACV,cAAM,OAAO,KAAK,GAAG;AACrB,iBAAS;AAAA,MACX,OAAO;AACL,cAAM,CAAC;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,4BAA4B,CAAC,MAAW;AAC5C,QAAM,eAAW,iCAAoB,CAAC;AACtC,MAAI,OAAO,aAAa,UAAU;AAChC,WAAO,GAAG;AAAA,EACZ;AACA,SAAO;AACT;",
6
+ "names": ["res"]
7
+ }
@@ -0,0 +1,46 @@
1
+ import { getVariableVariable, isWeb } from "@tamagui/core";
2
+ const operators = {
3
+ "+": (a, b) => a + b,
4
+ "-": (a, b) => a - b,
5
+ "/": (a, b) => a / b,
6
+ "*": (a, b) => a * b
7
+ };
8
+ const calc = (...valuesAndOperators) => {
9
+ if (isWeb) {
10
+ let res2 = "calc(";
11
+ for (const cur of valuesAndOperators) {
12
+ if (operators[cur]) {
13
+ res2 += " " + cur + " ";
14
+ } else {
15
+ res2 += convertToVariableOrNumber(cur);
16
+ }
17
+ }
18
+ return res2 + ")";
19
+ }
20
+ let res = 0;
21
+ let nextOp = null;
22
+ for (const cur of valuesAndOperators) {
23
+ if (operators[cur]) {
24
+ nextOp = operators[cur];
25
+ } else {
26
+ if (nextOp) {
27
+ res = nextOp(res, cur);
28
+ nextOp = null;
29
+ } else {
30
+ res = +cur;
31
+ }
32
+ }
33
+ }
34
+ return res;
35
+ };
36
+ const convertToVariableOrNumber = (v) => {
37
+ const varOrVal = getVariableVariable(v);
38
+ if (typeof varOrVal === "number") {
39
+ return `${varOrVal}px`;
40
+ }
41
+ return varOrVal;
42
+ };
43
+ export {
44
+ calc
45
+ };
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["import { getVariableVariable, isWeb } from '@tamagui/core'\nimport type { FontLineHeightTokens, FontSizeTokens, SizeTokens, SpaceTokens } from '@tamagui/core'\n\n// unused code - not exported could be used for cross compat calc() functions\n\n/**\n * Simple calc() that handles native + web\n * on web: outputs a calc() string\n * on native: outputs a plain number\n */\n\nexport type CalcVal =\n | string\n | number\n | SizeTokens\n | SpaceTokens\n | FontSizeTokens\n | FontLineHeightTokens\n\nconst operators = {\n '+': (a: number, b: number) => a + b,\n '-': (a: number, b: number) => a - b,\n '/': (a: number, b: number) => a / b,\n '*': (a: number, b: number) => a * b,\n}\n\ntype Operator = keyof typeof operators\n\nexport const calc = (...valuesAndOperators: (CalcVal | Operator)[]) => {\n if (isWeb) {\n let res = 'calc('\n for (const cur of valuesAndOperators) {\n if (operators[cur as any]) {\n // spaces are significant\n res += ' ' + cur + ' '\n } else {\n res += convertToVariableOrNumber(cur)\n }\n }\n return res + ')'\n }\n\n let res = 0\n let nextOp: any = null\n for (const cur of valuesAndOperators) {\n if (operators[cur as any]) {\n nextOp = operators[cur as any]\n } else {\n if (nextOp) {\n res = nextOp(res, cur)\n nextOp = null\n } else {\n res = +cur\n }\n }\n }\n\n return res\n}\n\nconst convertToVariableOrNumber = (v: any) => {\n const varOrVal = getVariableVariable(v)\n if (typeof varOrVal === 'number') {\n return `${varOrVal}px`\n }\n return varOrVal\n}\n"],
5
+ "mappings": "AAAA,SAAS,qBAAqB,aAAa;AAmB3C,MAAM,YAAY;AAAA,EAChB,KAAK,CAAC,GAAW,MAAc,IAAI;AAAA,EACnC,KAAK,CAAC,GAAW,MAAc,IAAI;AAAA,EACnC,KAAK,CAAC,GAAW,MAAc,IAAI;AAAA,EACnC,KAAK,CAAC,GAAW,MAAc,IAAI;AACrC;AAIO,MAAM,OAAO,IAAI,uBAA+C;AACrE,MAAI,OAAO;AACT,QAAIA,OAAM;AACV,eAAW,OAAO,oBAAoB;AACpC,UAAI,UAAU,MAAa;AAEzB,QAAAA,QAAO,MAAM,MAAM;AAAA,MACrB,OAAO;AACL,QAAAA,QAAO,0BAA0B,GAAG;AAAA,MACtC;AAAA,IACF;AACA,WAAOA,OAAM;AAAA,EACf;AAEA,MAAI,MAAM;AACV,MAAI,SAAc;AAClB,aAAW,OAAO,oBAAoB;AACpC,QAAI,UAAU,MAAa;AACzB,eAAS,UAAU;AAAA,IACrB,OAAO;AACL,UAAI,QAAQ;AACV,cAAM,OAAO,KAAK,GAAG;AACrB,iBAAS;AAAA,MACX,OAAO;AACL,cAAM,CAAC;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,4BAA4B,CAAC,MAAW;AAC5C,QAAM,WAAW,oBAAoB,CAAC;AACtC,MAAI,OAAO,aAAa,UAAU;AAChC,WAAO,GAAG;AAAA,EACZ;AACA,SAAO;AACT;",
6
+ "names": ["res"]
7
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@tamagui/calc",
3
+ "version": "1.0.1-beta.194",
4
+ "types": "./types/index.d.ts",
5
+ "main": "dist/cjs",
6
+ "module": "dist/esm",
7
+ "files": [
8
+ "src",
9
+ "types",
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tamagui-build",
14
+ "watch": "tamagui-build --watch",
15
+ "lint": "eslint",
16
+ "lint:fix": "yarn lint --fix",
17
+ "clean": "tamagui-build clean",
18
+ "clean:build": "tamagui-build clean:build"
19
+ },
20
+ "dependencies": {
21
+ "@tamagui/core": "^1.0.1-beta.194"
22
+ },
23
+ "devDependencies": {
24
+ "@tamagui/build": "^1.0.1-beta.194"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }
package/src/index.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { getVariableVariable, isWeb } from '@tamagui/core'
2
+ import type { FontLineHeightTokens, FontSizeTokens, SizeTokens, SpaceTokens } from '@tamagui/core'
3
+
4
+ // unused code - not exported could be used for cross compat calc() functions
5
+
6
+ /**
7
+ * Simple calc() that handles native + web
8
+ * on web: outputs a calc() string
9
+ * on native: outputs a plain number
10
+ */
11
+
12
+ export type CalcVal =
13
+ | string
14
+ | number
15
+ | SizeTokens
16
+ | SpaceTokens
17
+ | FontSizeTokens
18
+ | FontLineHeightTokens
19
+
20
+ const operators = {
21
+ '+': (a: number, b: number) => a + b,
22
+ '-': (a: number, b: number) => a - b,
23
+ '/': (a: number, b: number) => a / b,
24
+ '*': (a: number, b: number) => a * b,
25
+ }
26
+
27
+ type Operator = keyof typeof operators
28
+
29
+ export const calc = (...valuesAndOperators: (CalcVal | Operator)[]) => {
30
+ if (isWeb) {
31
+ let res = 'calc('
32
+ for (const cur of valuesAndOperators) {
33
+ if (operators[cur as any]) {
34
+ // spaces are significant
35
+ res += ' ' + cur + ' '
36
+ } else {
37
+ res += convertToVariableOrNumber(cur)
38
+ }
39
+ }
40
+ return res + ')'
41
+ }
42
+
43
+ let res = 0
44
+ let nextOp: any = null
45
+ for (const cur of valuesAndOperators) {
46
+ if (operators[cur as any]) {
47
+ nextOp = operators[cur as any]
48
+ } else {
49
+ if (nextOp) {
50
+ res = nextOp(res, cur)
51
+ nextOp = null
52
+ } else {
53
+ res = +cur
54
+ }
55
+ }
56
+ }
57
+
58
+ return res
59
+ }
60
+
61
+ const convertToVariableOrNumber = (v: any) => {
62
+ const varOrVal = getVariableVariable(v)
63
+ if (typeof varOrVal === 'number') {
64
+ return `${varOrVal}px`
65
+ }
66
+ return varOrVal
67
+ }
@@ -0,0 +1,17 @@
1
+ import type { FontLineHeightTokens, FontSizeTokens, SizeTokens, SpaceTokens } from '@tamagui/core';
2
+ /**
3
+ * Simple calc() that handles native + web
4
+ * on web: outputs a calc() string
5
+ * on native: outputs a plain number
6
+ */
7
+ export declare type CalcVal = string | number | SizeTokens | SpaceTokens | FontSizeTokens | FontLineHeightTokens;
8
+ declare const operators: {
9
+ '+': (a: number, b: number) => number;
10
+ '-': (a: number, b: number) => number;
11
+ '/': (a: number, b: number) => number;
12
+ '*': (a: number, b: number) => number;
13
+ };
14
+ declare type Operator = keyof typeof operators;
15
+ export declare const calc: (...valuesAndOperators: (CalcVal | Operator)[]) => string | number;
16
+ export {};
17
+ //# sourceMappingURL=index.d.ts.map