@umber-style/react-native 0.0.0 → 0.1.0-alpha.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.
@@ -0,0 +1,53 @@
1
+ // src/warnStyle.ts
2
+ /** A length or `auto`: one value of a CSS shorthand. */
3
+ const SHORTHAND_ITEM = String.raw`(?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:%|[a-z]*)|auto)`;
4
+ const SHORTHAND = new RegExp(String.raw`^\s*${SHORTHAND_ITEM}(?:\s+${SHORTHAND_ITEM}){1,3}\s*$`);
5
+ /** A number and a unit, once the white space around them is cut. */
6
+ const UNIT_VALUE = /^-?(?:\d+(?:\.\d*)?|\.\d+)([a-z]+)$/i;
7
+ /** The CSS length units, other than a percentage, that React Native does not take. */
8
+ const CSS_UNITS = /* @__PURE__ */ new Set([
9
+ "px",
10
+ "em",
11
+ "rem",
12
+ "ex",
13
+ "ch",
14
+ "vh",
15
+ "vw",
16
+ "vmin",
17
+ "vmax",
18
+ "pt",
19
+ "pc",
20
+ "cm",
21
+ "mm",
22
+ "in",
23
+ "q"
24
+ ]);
25
+ /** Whether `value` is a number with a CSS length unit other than a percentage. */
26
+ function hasCssUnit(value) {
27
+ const match = UNIT_VALUE.exec(value.trim());
28
+ return match !== null && CSS_UNITS.has(match[1].toLowerCase());
29
+ }
30
+ const warned = /* @__PURE__ */ new Set();
31
+ /** Whether this is a development build: `process` may not exist, and then nothing is warned. */
32
+ function isDevelopment() {
33
+ return typeof process !== "undefined" && process.env.NODE_ENV !== "production";
34
+ }
35
+ /** What is wrong with the string `value` of `key` on React Native, or undefined when nothing is. */
36
+ function describeProblem(key, value) {
37
+ if (SHORTHAND.test(value)) return `"${key}: ${value}" is a shorthand with several values; React Native takes one value for each key. Set each side or axis on its own.`;
38
+ if (hasCssUnit(value)) return `"${key}: ${value}" has a CSS unit; React Native takes a number (density-independent pixels) or a percentage.`;
39
+ }
40
+ /**
41
+ * In development, warns (once for each distinct message) about the values that the types cannot reject:
42
+ * a shorthand string with several values, or a number with a CSS unit.
43
+ */
44
+ function warnAboutValues(style) {
45
+ if (!isDevelopment()) return;
46
+ for (const [key, value] of Object.entries(style)) {
47
+ const message = typeof value === "string" ? describeProblem(key, value) : void 0;
48
+ if (message === void 0 || warned.has(message)) continue;
49
+ warned.add(message);
50
+ console.warn(`@umber-style/react-native: ${message}`);
51
+ }
52
+ }
53
+ exports.warnAboutValues = warnAboutValues;
@@ -0,0 +1,53 @@
1
+ // src/warnStyle.ts
2
+ /** A length or `auto`: one value of a CSS shorthand. */
3
+ const SHORTHAND_ITEM = String.raw`(?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:%|[a-z]*)|auto)`;
4
+ const SHORTHAND = new RegExp(String.raw`^\s*${SHORTHAND_ITEM}(?:\s+${SHORTHAND_ITEM}){1,3}\s*$`);
5
+ /** A number and a unit, once the white space around them is cut. */
6
+ const UNIT_VALUE = /^-?(?:\d+(?:\.\d*)?|\.\d+)([a-z]+)$/i;
7
+ /** The CSS length units, other than a percentage, that React Native does not take. */
8
+ const CSS_UNITS = /* @__PURE__ */ new Set([
9
+ "px",
10
+ "em",
11
+ "rem",
12
+ "ex",
13
+ "ch",
14
+ "vh",
15
+ "vw",
16
+ "vmin",
17
+ "vmax",
18
+ "pt",
19
+ "pc",
20
+ "cm",
21
+ "mm",
22
+ "in",
23
+ "q"
24
+ ]);
25
+ /** Whether `value` is a number with a CSS length unit other than a percentage. */
26
+ function hasCssUnit(value) {
27
+ const match = UNIT_VALUE.exec(value.trim());
28
+ return match !== null && CSS_UNITS.has(match[1].toLowerCase());
29
+ }
30
+ const warned = /* @__PURE__ */ new Set();
31
+ /** Whether this is a development build: `process` may not exist, and then nothing is warned. */
32
+ function isDevelopment() {
33
+ return typeof process !== "undefined" && process.env.NODE_ENV !== "production";
34
+ }
35
+ /** What is wrong with the string `value` of `key` on React Native, or undefined when nothing is. */
36
+ function describeProblem(key, value) {
37
+ if (SHORTHAND.test(value)) return `"${key}: ${value}" is a shorthand with several values; React Native takes one value for each key. Set each side or axis on its own.`;
38
+ if (hasCssUnit(value)) return `"${key}: ${value}" has a CSS unit; React Native takes a number (density-independent pixels) or a percentage.`;
39
+ }
40
+ /**
41
+ * In development, warns (once for each distinct message) about the values that the types cannot reject:
42
+ * a shorthand string with several values, or a number with a CSS unit.
43
+ */
44
+ function warnAboutValues(style) {
45
+ if (!isDevelopment()) return;
46
+ for (const [key, value] of Object.entries(style)) {
47
+ const message = typeof value === "string" ? describeProblem(key, value) : void 0;
48
+ if (message === void 0 || warned.has(message)) continue;
49
+ warned.add(message);
50
+ console.warn(`@umber-style/react-native: ${message}`);
51
+ }
52
+ }
53
+ export { warnAboutValues };
package/package.json CHANGED
@@ -1,10 +1,82 @@
1
1
  {
2
2
  "name": "@umber-style/react-native",
3
- "version": "0.0.0",
4
- "description": "Placeholder. The first release is on its way.",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "UmberStyle for React Native: the same names as the React binding, over the real theme values.",
5
+ "keywords": [
6
+ "styling",
7
+ "theme",
8
+ "design-tokens",
9
+ "react-native",
10
+ "typescript"
11
+ ],
5
12
  "license": "MIT",
13
+ "author": "Masoud Soroush <masoud@soroush.tech>",
14
+ "homepage": "https://umber-style.soroush.design",
6
15
  "repository": {
7
16
  "type": "git",
8
- "url": "git+https://github.com/soroush-tech/umber-style.git"
9
- }
10
- }
17
+ "url": "git+https://github.com/soroush-tech/umber-style.git",
18
+ "directory": "packages/react-native"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/soroush-tech/umber-style/issues"
22
+ },
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "import": {
31
+ "types": "./dist/index.d.mts",
32
+ "default": "./dist/index.mjs"
33
+ },
34
+ "require": {
35
+ "types": "./dist/index.d.cts",
36
+ "default": "./dist/index.cjs"
37
+ }
38
+ }
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@umber-style/core": "0.1.0-alpha.0"
45
+ },
46
+ "peerDependencies": {
47
+ "react": "^19.2.8",
48
+ "react-native": ">=0.76.0"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "react-native": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "devDependencies": {
56
+ "@testing-library/react": "^16.3.3",
57
+ "@types/node": "^26.6.6",
58
+ "@types/react": "^19.3.0",
59
+ "@types/react-dom": "^19.3.0",
60
+ "@vitest/coverage-v8": "^5.1.0",
61
+ "jsdom": "^31.0.0",
62
+ "oxlint": "^1.93.0",
63
+ "react": "^19.3.1",
64
+ "react-dom": "^19.3.1",
65
+ "react-native": "^0.88.1",
66
+ "tsdown": "^0.23.7",
67
+ "typescript": "~7.0.2",
68
+ "vitest": "^5.1.0",
69
+ "@umber-bench/shared": "0.1.0",
70
+ "@umber-style/eslint-config": "0.0.0"
71
+ },
72
+ "scripts": {
73
+ "build": "tsdown",
74
+ "lint": "oxlint --deny-warnings",
75
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.augmentation.json && tsc --noEmit -p tsconfig.defaultStyle.json",
76
+ "test": "vitest run",
77
+ "test:coverage": "vitest run --coverage"
78
+ },
79
+ "main": "./dist/index.cjs",
80
+ "module": "./dist/index.mjs",
81
+ "types": "./dist/index.d.mts"
82
+ }