@wwwares/keycaps 0.0.0-stage → 0.0.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.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # @wwwares/keycaps
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Raymarched WebGL keycaps for React: Cherry, OEM, SA, DSA and XDA profiles, PBT and ABS plastics, swirled, clear
4
+ and glitter finishes, wear, yellowing, and text or icon legends. Every cap on the page shares one WebGL context,
5
+ still caps draw once, and caps scrolled out of view are skipped.
6
+
7
+ ```tsx
8
+ import { Keycap, KeycapDefaults } from "@wwwares/keycaps";
9
+
10
+ <Keycap preset="aurora" legend="A" size={64} />
11
+ <Keycap colors={["#ff3355"]} width={2.25} legend="↵" spinnable />
12
+
13
+ <KeycapDefaults.Provider value={{ profile: "sa" }}>
14
+ <Keycap preset="graphite" legend="Esc" />
15
+ </KeycapDefaults.Provider>
16
+ ```
17
+
18
+ `size` is the cap's height. Its width follows from the key's `width` in units, and `keycapAspect(width)` gives
19
+ the ratio for layout. Every field of `KeycapConfig` is an optional prop, documented on the type. `preset` picks a
20
+ base look from `KEYCAP_PRESETS`, `LEGEND_ICONS` lists the legends drawn as vector icons, and `frozen` renders a
21
+ still frame of an animated config. Other props are passed to the underlying `<span>`.
22
+
23
+ Until the first frame draws, and wherever WebGL is unavailable, a cap shows a flat `--keycap-fallback` colour.
@@ -0,0 +1,102 @@
1
+ import { Context, ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
2
+ export declare const PROFILES: readonly ["cherry", "oem", "sa", "dsa", "xda"];
3
+ type Profile = (typeof PROFILES)[number];
4
+ export declare const MATERIALS: readonly ["pbt", "abs"];
5
+ type Material = (typeof MATERIALS)[number];
6
+ /** Legends drawn as vector icons rather than text. The order matches the glyph ids in keycap.frag. */
7
+ export declare const LEGEND_ICONS: {
8
+ readonly "⌫": "Backspace";
9
+ readonly "⇥": "Tab";
10
+ readonly "⇪": "Caps Lock";
11
+ readonly "↵": "Enter";
12
+ readonly "⇧": "Shift";
13
+ readonly "␣": "Space";
14
+ readonly "⌃": "Control";
15
+ readonly "⌥": "Alt";
16
+ readonly "◆": "Super";
17
+ readonly "≡": "Menu";
18
+ };
19
+ type LegendIcon = keyof typeof LEGEND_ICONS;
20
+ interface KeycapConfig {
21
+ profile: Profile;
22
+ /** Sculpted row, 1 (number row) to 4 (bottom row). Uniform profiles ignore it. */
23
+ row: number;
24
+ /** Width in key units, where 1u is a 19.05mm pitch. */
25
+ width: number;
26
+ /** ABS has a fine moulded texture and yellows with age. PBT is smooth with an even sheen. */
27
+ material: Material;
28
+ /** 0 is opaque, 1 is clear plastic that shows the page behind it. */
29
+ translucency: number;
30
+ /** Text, or one of `LEGEND_ICONS` for a vector icon. Empty for a blank cap. */
31
+ legend: string;
32
+ /** CSS font family for text legends. */
33
+ legendFont: string;
34
+ /** CSS colour of the legend. Empty picks a light or dark tone that contrasts with the cap. */
35
+ legendColor: string;
36
+ /** One to four CSS colours forming the dye ramp. A single colour expands into a three-stop ramp. */
37
+ colors: string[];
38
+ /** Hue rotation in degrees. */
39
+ hue: number;
40
+ saturation: number;
41
+ brightness: number;
42
+ /** Where the middle stops sit along the ramp, from 0.05 to 0.95. */
43
+ spread: number;
44
+ /** How strongly the ramp swirls through the plastic, 0 to 1. */
45
+ swirl: number;
46
+ swirlScale: number;
47
+ /** Noise octaves, 1 to 5. */
48
+ swirlDetail: number;
49
+ swirlWarp: number;
50
+ /** Drift speed of the swirl along its flow direction. */
51
+ swirlFlow: number;
52
+ /** Rotation speed of the swirl in radians per second. The sign sets the direction. */
53
+ spin: number;
54
+ /** Direction of the swirl's spin axis and flow, in degrees. */
55
+ swirlAngle: number;
56
+ /** Density of suspended glitter flakes, 0 to 1. */
57
+ shimmer: number;
58
+ /** Lets glitter flakes flicker over time. */
59
+ twinkle: boolean;
60
+ /** CSS colour of the flakes. Empty uses the legend colour, or silver on a blank cap. */
61
+ glitterColor: string;
62
+ /** Seed that places the swirl, glitter and wear differently per key. 0 is the canonical look. */
63
+ pattern: number;
64
+ /** Polish worn into the top by a fingertip, 0 to 1. */
65
+ shine: number;
66
+ /** Amber drift of aged plastic, 0 to 1. */
67
+ yellowing: number;
68
+ /** Light direction in degrees. */
69
+ angle: number;
70
+ /** Contact shadow strength, from 0 for none to 1. */
71
+ shadow: number;
72
+ }
73
+ export declare const DEFAULT_KEYCAP: KeycapConfig;
74
+ type SwirlSettings = Pick<KeycapConfig, "swirl" | "swirlScale" | "swirlDetail" | "swirlWarp" | "swirlFlow" | "spin">;
75
+ type SwirlRecipe = "Clouds" | "Marble" | "Liquid" | "Nebula" | "Blobs";
76
+ export declare const SWIRL_RECIPES: Record<SwirlRecipe, SwirlSettings>;
77
+ type KeycapPreset = "mint" | "ember" | "sky" | "lilac" | "rose" | "lemon" | "bone" | "graphite" | "obsidian" | "cherry" | "ocean" | "aquaJelly" | "grapeJelly" | "limeJelly" | "tangerineJelly" | "aurora" | "sunset" | "marble" | "galaxy";
78
+ export declare const KEYCAP_PRESETS: Record<KeycapPreset, Partial<KeycapConfig>>;
79
+ interface KeycapOptions extends Partial<KeycapConfig> {
80
+ /** Base look that the other fields override. */
81
+ preset?: KeycapPreset;
82
+ /** Renders a still frame even when the config animates. */
83
+ frozen?: boolean;
84
+ }
85
+ /** Config shared by every `Keycap` below it. A `preset` or props on the cap override it. */
86
+ export declare const KeycapDefaults: Context<Partial<KeycapConfig>>;
87
+ interface KeycapProps extends KeycapOptions, Omit<HTMLAttributes<HTMLSpanElement>, keyof KeycapOptions> {
88
+ /** Height of the cap, as pixels or any CSS length. The width follows from the key's `width`. */
89
+ size?: number | string;
90
+ /** Accessible name. Without one the cap is hidden from assistive tech. */
91
+ label?: string;
92
+ /** Lets the user drag the cap to turn it. */
93
+ spinnable?: boolean;
94
+ }
95
+ export declare const Keycap: ForwardRefExoticComponent<KeycapProps & RefAttributes<HTMLSpanElement>>;
96
+ /**
97
+ * Width-to-height ratio of a cap's tile. A keycap of a given `size` is `size` tall and
98
+ * `size * keycapAspect(width)` wide.
99
+ */
100
+ export declare function keycapAspect(width: number): number;
101
+ export declare const isWebGLAvailable: () => boolean;
102
+ export type { KeycapConfig, KeycapOptions, KeycapPreset, KeycapProps, LegendIcon, Material, Profile, SwirlRecipe, SwirlSettings };