@ghostmind-dev/colors 0.2.0 → 0.2.1
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/native.d.ts +6 -0
- package/dist/native.js +10 -2
- package/package.json +1 -1
package/dist/native.d.ts
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
* same resolved colour the web gets for that role, so the apps stay in step.
|
|
4
4
|
*/
|
|
5
5
|
import { type ThemeId } from './index.js';
|
|
6
|
+
/**
|
|
7
|
+
* `rgb(0 0 0 / 0.85)` → `rgba(0, 0, 0, 0.85)`. The web takes either form; on a native platform the older
|
|
8
|
+
* one is the safe one: Reanimated rejects the space-separated form ("Invalid color value"), and so do
|
|
9
|
+
* other parsers outside a browser. Hex values are returned unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export declare function nativeColour(value: string): string;
|
|
6
12
|
/**
|
|
7
13
|
* A platform's named colours for one theme: `platformColors('dark').background` is the value of
|
|
8
14
|
* the role the platform maps to `background`.
|
package/dist/native.js
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { PLATFORMS, THEMES, roleValue } from './index.js';
|
|
6
6
|
import { SEMANTIC_ROLES } from './tailwind.js';
|
|
7
|
+
/**
|
|
8
|
+
* `rgb(0 0 0 / 0.85)` → `rgba(0, 0, 0, 0.85)`. The web takes either form; on a native platform the older
|
|
9
|
+
* one is the safe one: Reanimated rejects the space-separated form ("Invalid color value"), and so do
|
|
10
|
+
* other parsers outside a browser. Hex values are returned unchanged.
|
|
11
|
+
*/
|
|
12
|
+
export function nativeColour(value) {
|
|
13
|
+
return value.replace(/^rgb\((\d+) (\d+) (\d+) \/ ([\d.]+)\)$/, 'rgba($1, $2, $3, $4)');
|
|
14
|
+
}
|
|
7
15
|
function assertTheme(id) {
|
|
8
16
|
if (!Object.prototype.hasOwnProperty.call(THEMES, id)) {
|
|
9
17
|
throw new Error(`Unknown theme "${id}". Known: ${Object.keys(THEMES).join(', ')}.`);
|
|
@@ -19,10 +27,10 @@ export function platformColors(id, platform = 'ios') {
|
|
|
19
27
|
if (!map) {
|
|
20
28
|
throw new Error(`Unknown platform "${platform}". Known: ${Object.keys(PLATFORMS).join(', ')}.`);
|
|
21
29
|
}
|
|
22
|
-
return Object.fromEntries(Object.entries(map).map(([name, role]) => [name, roleValue(id, role)]));
|
|
30
|
+
return Object.fromEntries(Object.entries(map).map(([name, role]) => [name, nativeColour(roleValue(id, role))]));
|
|
23
31
|
}
|
|
24
32
|
/** Every shared meaning name (`surface-primary`, `card-foreground`) resolved for one theme. */
|
|
25
33
|
export function semanticColors(id) {
|
|
26
34
|
assertTheme(id);
|
|
27
|
-
return Object.fromEntries(Object.entries(SEMANTIC_ROLES).map(([name, role]) => [name, roleValue(id, role)]));
|
|
35
|
+
return Object.fromEntries(Object.entries(SEMANTIC_ROLES).map(([name, role]) => [name, nativeColour(roleValue(id, role))]));
|
|
28
36
|
}
|
package/package.json
CHANGED