@phreshos/react 0.1.7 → 0.1.9

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
@@ -19,8 +19,8 @@ It provides two kinds of adapter:
19
19
  - `CurrentProvider` resolves exactly the current values named by its required
20
20
  `provide` prop, then exposes them synchronously through `useProgram()`,
21
21
  `useProcess()`, and `useParent()`.
22
- - `HostProvider` subscribes before reading exactly the host values named by its
23
- required `provide` prop. `useHostTheme()`, `useDesktopSize()`, and
22
+ - `SystemProvider` subscribes before reading exactly the system values named by its
23
+ required `provide` prop. `useSystemAppearance()`, `useSystemTheme()`, `useDesktopSize()`, and
24
24
  `usePointerPosition()` expose those values synchronously after resolution.
25
25
  - `useSubscribe()` and `useObserve()` own persistent ordinary-event
26
26
  registrations for one mounted React consumer.
@@ -31,9 +31,6 @@ It provides two kinds of adapter:
31
31
  - `useObserveAsks()` adapts an Endpoint traffic surface's question observation,
32
32
  while `useObserveAnswers()` adapts a Server traffic surface's answer
33
33
  observation.
34
- - `useScale(value)` and `useColor(value)` memoize the complete derived scale
35
- around the explicit number or CSS color supplied by the component. They do
36
- not read a Theme or choose a source value implicitly.
37
34
 
38
35
  Window needs no React resolution: `current.window` is already a synchronous,
39
36
  silent capability object. `CurrentProvider` therefore has no `window` selection
@@ -75,47 +72,41 @@ mount its `useWindowState()` child only while `clientExists` is true. Calling
75
72
  the Window hook while the Client is absent lets the existing Window reads
76
73
  reject normally.
77
74
 
78
- ```tsx
79
- const theme = useHostTheme()
80
- const spacing = useScale(theme.spacing)
81
- const radius = useScale(theme.radius)
82
- const accent = useColor(theme.accent)
83
- ```
84
-
85
75
  The ordinary-event and traffic hooks retain the latest value returned by their projector.
86
76
  `useSubscribe()` may omit that callback; its default projector is
87
77
  `message => message`, so the hook retains the latest message unchanged.
88
78
 
89
79
  ```tsx
90
- import { host } from "@phreshos/client"
80
+ import { system } from "@phreshos/client"
91
81
  import { useSubscribe } from "@phreshos/react"
92
82
 
93
- const desktop = useSubscribe(host.desktop, "resize")
83
+ const desktop = useSubscribe(system.desktop, "resize")
94
84
  ```
95
85
 
96
- Host reads are asynchronous while subscriptions are live-only. `HostProvider`
86
+ System reads are asynchronous while subscriptions are live-only. `SystemProvider`
97
87
  subscribes before requesting each selected snapshot and prevents an older read
98
88
  from overwriting a newer event:
99
89
 
100
90
  ```tsx
101
- import { HostProvider, useDesktopSize, useHostTheme } from "@phreshos/react"
91
+ import { SystemProvider, useDesktopSize, useSystemAppearance, useSystemTheme } from "@phreshos/react"
102
92
 
103
93
  function Content() {
104
- const theme = useHostTheme()
94
+ const theme = useSystemTheme()
95
+ const appearance = useSystemAppearance()
105
96
  const desktop = useDesktopSize()
106
97
 
107
- return <p style={{ color: theme.foreground }}>{desktop.width} × {desktop.height}</p>
98
+ return <p style={{ color: appearance.foreground[theme] }}>{desktop.width} × {desktop.height}</p>
108
99
  }
109
100
 
110
101
  function App() {
111
- return <HostProvider provide={["theme", "desktopSize"]} fallback={<p>Loading…</p>}>
102
+ return <SystemProvider provide={["appearance", "theme", "desktopSize"]} fallback={<p>Loading…</p>}>
112
103
  <Content />
113
- </HostProvider>
104
+ </SystemProvider>
114
105
  }
115
106
  ```
116
107
 
117
108
  The selection is required and non-empty. Nothing is read or subscribed merely
118
- because either SDK was imported, and an unselected host value never enters the
109
+ because either SDK was imported, and an unselected system value never enters the
119
110
  Client. `pointerPosition` is permission-guarded: selecting it does not request
120
111
  permission, and resolution fails unless the Program already holds `pointer`.
121
112
  The provider renders its fallback until every selected value resolves.
@@ -147,7 +138,7 @@ export default function App() {
147
138
  }
148
139
  ```
149
140
 
150
- Using a current or host hook outside its provider, or without selecting its
141
+ Using a current or system hook outside its provider, or without selecting its
151
142
  value, throws a configuration error. Neither provider supplies an implicit
152
143
  "everything" selection, so adding a future capability cannot make it enter an
153
144
  existing application.
@@ -14,7 +14,7 @@ export default class LiveSnapshot {
14
14
  }
15
15
  snapshot = () => {
16
16
  if (this.value === unavailable)
17
- throw new Error("The requested host value is not ready");
17
+ throw new Error("The requested system value is not ready");
18
18
  return this.value;
19
19
  };
20
20
  subscribe = (listener) => {
package/dist/main.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  export { default as CurrentProvider, useParent, useProcess, useProgram, type CurrentProvision, type CurrentProvisionName, type CurrentProviderProperties } from "./current-provider.js";
2
- export { default as HostProvider, usePointerPosition, useDesktopSize, useHostTheme, type HostProvision, type HostProvisionName, type HostProviderProperties } from "./host-provider.js";
2
+ export { default as SystemProvider, usePointerPosition, useDesktopSize, useSystemAppearance, useSystemTheme, type SystemProvision, type SystemProvisionName, type SystemProviderProperties } from "./system-provider.js";
3
3
  export { default as useSubscribe } from "./use-subscribe.js";
4
4
  export { default as useObserve } from "./use-observe.js";
5
- export { default as useScale } from "./use-scale.js";
6
- export { default as useColor } from "./use-color.js";
7
5
  export { default as useProgramState, type ProgramState } from "./use-program-state.js";
8
6
  export { default as useProcessState, type ProcessState } from "./use-process-state.js";
9
7
  export { default as useServiceState, type ServiceState } from "./use-service-state.js";
package/dist/main.js CHANGED
@@ -1,9 +1,7 @@
1
1
  export { default as CurrentProvider, useParent, useProcess, useProgram } from "./current-provider.js";
2
- export { default as HostProvider, usePointerPosition, useDesktopSize, useHostTheme } from "./host-provider.js";
2
+ export { default as SystemProvider, usePointerPosition, useDesktopSize, useSystemAppearance, useSystemTheme } from "./system-provider.js";
3
3
  export { default as useSubscribe } from "./use-subscribe.js";
4
4
  export { default as useObserve } from "./use-observe.js";
5
- export { default as useScale } from "./use-scale.js";
6
- export { default as useColor } from "./use-color.js";
7
5
  export { default as useProgramState } from "./use-program-state.js";
8
6
  export { default as useProcessState } from "./use-process-state.js";
9
7
  export { default as useServiceState } from "./use-service-state.js";
@@ -0,0 +1,30 @@
1
+ import { type ReactNode } from "react";
2
+ import { type Appearance, type DesktopSize, type PointerPosition, type Theme } from "@phreshos/client";
3
+ declare const provisionNames: readonly ["appearance", "theme", "desktopSize", "pointerPosition"];
4
+ /** Requests and follows only the system values explicitly selected by the program. */
5
+ export default function SystemProvider(properties: SystemProviderProperties): import("react").FunctionComponentElement<SelectedSystemProviderProperties>;
6
+ /** Returns the complete unresolved Appearance and follows authoritative updates. */
7
+ export declare function useSystemAppearance(): Appearance;
8
+ /** Returns the effective local Desktop Theme and follows future changes. */
9
+ export declare function useSystemTheme(): Theme;
10
+ /** Returns the selected desktop size and follows future resize events. */
11
+ export declare function useDesktopSize(): DesktopSize;
12
+ /** Returns the selected Pointer position and follows future move events. */
13
+ export declare function usePointerPosition(): PointerPosition | null;
14
+ /** Values that SystemProvider can request and follow. */
15
+ export type SystemProvisionName = typeof provisionNames[number];
16
+ /** Required non-empty selection of system values. */
17
+ export type SystemProvision = readonly [SystemProvisionName, ...SystemProvisionName[]];
18
+ /** Properties accepted by SystemProvider. */
19
+ export interface SystemProviderProperties {
20
+ /** Content rendered after every selected system value has resolved. */
21
+ readonly children: ReactNode;
22
+ /** Content rendered while selected system values resolve. */
23
+ readonly fallback: ReactNode;
24
+ /** Exact system values requested and followed for mounted descendants. */
25
+ readonly provide: SystemProvision;
26
+ }
27
+ type SelectedSystemProviderProperties = SystemProviderProperties & Readonly<{
28
+ selection: readonly SystemProvisionName[];
29
+ }>;
30
+ export {};
@@ -1,16 +1,16 @@
1
1
  import { createContext, createElement, useContext, useEffect, useMemo, useState, useSyncExternalStore } from "react";
2
- import { host } from "@phreshos/client";
2
+ import { system } from "@phreshos/client";
3
3
  import LiveSnapshot from "./live-snapshot.js";
4
- const provisionNames = ["theme", "desktopSize", "pointerPosition"];
5
- const HostContext = createContext(null);
6
- /** Requests and follows only the host values explicitly selected by the program. */
7
- export default function HostProvider(properties) {
4
+ const provisionNames = ["appearance", "theme", "desktopSize", "pointerPosition"];
5
+ const SystemContext = createContext(null);
6
+ /** Requests and follows only the system values explicitly selected by the program. */
7
+ export default function SystemProvider(properties) {
8
8
  const normalized = normalizeProvision(properties.provide);
9
9
  const selectionKey = normalized.join("\0");
10
10
  const selection = useMemo(() => normalized, [selectionKey]);
11
- return createElement(SelectedHostProvider, { ...properties, key: selectionKey, selection });
11
+ return createElement(SelectedSystemProvider, { ...properties, key: selectionKey, selection });
12
12
  }
13
- function SelectedHostProvider({ children, fallback, selection }) {
13
+ function SelectedSystemProvider({ children, fallback, selection }) {
14
14
  const stores = useMemo(() => createStores(selection), [selection]);
15
15
  const [resolution, setResolution] = useState({ status: "pending" });
16
16
  useEffect(() => {
@@ -35,10 +35,14 @@ function SelectedHostProvider({ children, fallback, selection }) {
35
35
  return fallback;
36
36
  if (resolution.status === "error")
37
37
  throw resolution.error;
38
- return createElement(HostContext.Provider, { value: { provided: new Set(selection), stores } }, children);
38
+ return createElement(SystemContext.Provider, { value: { provided: new Set(selection), stores } }, children);
39
39
  }
40
- /** Returns the selected Theme snapshot and follows future change events. */
41
- export function useHostTheme() {
40
+ /** Returns the complete unresolved Appearance and follows authoritative updates. */
41
+ export function useSystemAppearance() {
42
+ return useProvided("appearance");
43
+ }
44
+ /** Returns the effective local Desktop Theme and follows future changes. */
45
+ export function useSystemTheme() {
42
46
  return useProvided("theme");
43
47
  }
44
48
  /** Returns the selected desktop size and follows future resize events. */
@@ -50,11 +54,11 @@ export function usePointerPosition() {
50
54
  return useProvided("pointerPosition");
51
55
  }
52
56
  function useProvided(name) {
53
- const context = useContext(HostContext);
57
+ const context = useContext(SystemContext);
54
58
  if (!context)
55
- throw new Error(`${hookNames[name]} must be used inside HostProvider`);
59
+ throw new Error(`${hookNames[name]} must be used inside SystemProvider`);
56
60
  if (!context.provided.has(name))
57
- throw new Error(`${hookNames[name]} requires "${name}" in HostProvider's provide prop`);
61
+ throw new Error(`${hookNames[name]} requires "${name}" in SystemProvider's provide prop`);
58
62
  const store = context.stores[name];
59
63
  return useSyncExternalStore(store.subscribe, store.snapshot, store.snapshot);
60
64
  }
@@ -62,14 +66,17 @@ function createStores(selection) {
62
66
  const stores = {};
63
67
  for (const name of selection) {
64
68
  switch (name) {
69
+ case "appearance":
70
+ stores.appearance = new LiveSnapshot(() => system.appearance.snapshot(), subscriber => system.appearance.subscribe("change", subscriber));
71
+ break;
65
72
  case "theme":
66
- stores.theme = new LiveSnapshot(() => host.theme.snapshot(), subscriber => host.theme.subscribe("change", subscriber));
73
+ stores.theme = new LiveSnapshot(() => system.theme.snapshot(), subscriber => system.theme.subscribe("change", subscriber));
67
74
  break;
68
75
  case "desktopSize":
69
- stores.desktopSize = new LiveSnapshot(() => host.desktop.size(), subscriber => host.desktop.subscribe("resize", subscriber));
76
+ stores.desktopSize = new LiveSnapshot(() => system.desktop.size(), subscriber => system.desktop.subscribe("resize", subscriber));
70
77
  break;
71
78
  case "pointerPosition":
72
- stores.pointerPosition = new LiveSnapshot(() => host.pointer.position(), subscriber => host.pointer.subscribe("move", subscriber));
79
+ stores.pointerPosition = new LiveSnapshot(() => system.pointer.position(), subscriber => system.pointer.subscribe("move", subscriber));
73
80
  break;
74
81
  }
75
82
  }
@@ -77,19 +84,20 @@ function createStores(selection) {
77
84
  }
78
85
  function normalizeProvision(provide) {
79
86
  if (!Array.isArray(provide) || provide.length === 0)
80
- throw new Error("HostProvider's provide prop must select at least one host value");
87
+ throw new Error("SystemProvider's provide prop must select at least one system value");
81
88
  const selected = new Set();
82
89
  for (const name of provide) {
83
90
  if (!provisionNames.includes(name))
84
- throw new Error(`HostProvider cannot provide "${String(name)}"`);
91
+ throw new Error(`SystemProvider cannot provide "${String(name)}"`);
85
92
  if (selected.has(name))
86
- throw new Error(`HostProvider's provide prop selects "${name}" more than once`);
93
+ throw new Error(`SystemProvider's provide prop selects "${name}" more than once`);
87
94
  selected.add(name);
88
95
  }
89
96
  return [...selected];
90
97
  }
91
98
  const hookNames = {
92
- theme: "useHostTheme",
99
+ appearance: "useSystemAppearance",
100
+ theme: "useSystemTheme",
93
101
  desktopSize: "useDesktopSize",
94
102
  pointerPosition: "usePointerPosition"
95
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phreshos/react",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "React adapters for the Client SDK.",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
@@ -47,13 +47,13 @@
47
47
  "prepack": "node --run test && node --run build"
48
48
  },
49
49
  "peerDependencies": {
50
- "@phreshos/client": "^0.1.13",
51
- "@phreshos/core": "^0.1.9",
50
+ "@phreshos/client": "^0.1.20",
51
+ "@phreshos/core": "^0.1.17",
52
52
  "react": "^19.2.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@phreshos/client": "^0.1.13",
56
- "@phreshos/core": "^0.1.9",
55
+ "@phreshos/client": "^0.1.20",
56
+ "@phreshos/core": "^0.1.17",
57
57
  "@testing-library/react": "^16.3.0",
58
58
  "@types/react": "^19.2.18",
59
59
  "@types/react-dom": "^19.2.4",
@@ -1,28 +0,0 @@
1
- import { type ReactNode } from "react";
2
- import { type DesktopSize, type PointerPosition, type ThemeProperties } from "@phreshos/client";
3
- declare const provisionNames: readonly ["theme", "desktopSize", "pointerPosition"];
4
- /** Requests and follows only the host values explicitly selected by the program. */
5
- export default function HostProvider(properties: HostProviderProperties): import("react").FunctionComponentElement<SelectedHostProviderProperties>;
6
- /** Returns the selected Theme snapshot and follows future change events. */
7
- export declare function useHostTheme(): Readonly<ThemeProperties>;
8
- /** Returns the selected desktop size and follows future resize events. */
9
- export declare function useDesktopSize(): DesktopSize;
10
- /** Returns the selected Pointer position and follows future move events. */
11
- export declare function usePointerPosition(): PointerPosition | null;
12
- /** Values that HostProvider can request and follow. */
13
- export type HostProvisionName = typeof provisionNames[number];
14
- /** Required non-empty selection of host values. */
15
- export type HostProvision = readonly [HostProvisionName, ...HostProvisionName[]];
16
- /** Properties accepted by HostProvider. */
17
- export interface HostProviderProperties {
18
- /** Content rendered after every selected host value has resolved. */
19
- readonly children: ReactNode;
20
- /** Content rendered while selected host values resolve. */
21
- readonly fallback: ReactNode;
22
- /** Exact host values requested and followed for mounted descendants. */
23
- readonly provide: HostProvision;
24
- }
25
- type SelectedHostProviderProperties = HostProviderProperties & Readonly<{
26
- selection: readonly HostProvisionName[];
27
- }>;
28
- export {};
@@ -1,3 +0,0 @@
1
- import { type ColorScale } from "@phreshos/core";
2
- /** Returns the complete color scale derived from one explicit CSS color. */
3
- export default function useColor(value: string): ColorScale;
package/dist/use-color.js DELETED
@@ -1,6 +0,0 @@
1
- import { useMemo } from "react";
2
- import { color } from "@phreshos/core";
3
- /** Returns the complete color scale derived from one explicit CSS color. */
4
- export default function useColor(value) {
5
- return useMemo(() => color(value), [value]);
6
- }
@@ -1,3 +0,0 @@
1
- import { type NumericScale } from "@phreshos/core";
2
- /** Returns the complete visual scale derived from one explicit numeric value. */
3
- export default function useScale(value: number): NumericScale;
package/dist/use-scale.js DELETED
@@ -1,6 +0,0 @@
1
- import { useMemo } from "react";
2
- import { numericScale } from "@phreshos/core";
3
- /** Returns the complete visual scale derived from one explicit numeric value. */
4
- export default function useScale(value) {
5
- return useMemo(() => numericScale(value), [value]);
6
- }