solid-drift 0.2.0 → 0.8.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.
Files changed (54) hide show
  1. package/README.md +933 -10
  2. package/dist/ai.d.ts +207 -0
  3. package/dist/ai.js +570 -0
  4. package/dist/animate.d.ts +2 -2
  5. package/dist/animate.js +2 -2
  6. package/dist/cartoon.d.ts +190 -0
  7. package/dist/cartoon.js +334 -0
  8. package/dist/color.d.ts +53 -0
  9. package/dist/color.js +391 -0
  10. package/dist/directive.d.ts +5 -5
  11. package/dist/directive.js +15 -7
  12. package/dist/easing.d.ts +22 -1
  13. package/dist/easing.js +49 -1
  14. package/dist/flip.d.ts +44 -0
  15. package/dist/flip.js +108 -0
  16. package/dist/horizontal.d.ts +107 -0
  17. package/dist/horizontal.js +208 -0
  18. package/dist/index.d.ts +20 -3
  19. package/dist/index.js +17 -3
  20. package/dist/inview.d.ts +4 -4
  21. package/dist/inview.js +5 -5
  22. package/dist/motion.d.ts +404 -0
  23. package/dist/motion.js +761 -0
  24. package/dist/physics.d.ts +146 -0
  25. package/dist/physics.js +352 -0
  26. package/dist/pointer.d.ts +76 -0
  27. package/dist/pointer.js +123 -0
  28. package/dist/reduced-motion.d.ts +3 -3
  29. package/dist/reduced-motion.js +5 -4
  30. package/dist/scroll.d.ts +3 -3
  31. package/dist/scroll.js +5 -5
  32. package/dist/scrollfx.d.ts +156 -0
  33. package/dist/scrollfx.js +148 -0
  34. package/dist/scrub.d.ts +51 -0
  35. package/dist/scrub.js +67 -0
  36. package/dist/spring.d.ts +39 -4
  37. package/dist/spring.js +26 -7
  38. package/dist/stagger.d.ts +4 -4
  39. package/dist/stagger.js +4 -4
  40. package/dist/text.d.ts +27 -0
  41. package/dist/text.js +84 -0
  42. package/dist/timeline.d.ts +45 -0
  43. package/dist/timeline.js +93 -0
  44. package/dist/trail.d.ts +27 -0
  45. package/dist/trail.js +75 -0
  46. package/dist/tween.d.ts +3 -3
  47. package/dist/tween.js +3 -3
  48. package/dist/typography.d.ts +241 -0
  49. package/dist/typography.js +812 -0
  50. package/dist/velocity.d.ts +44 -0
  51. package/dist/velocity.js +88 -0
  52. package/dist/web3.d.ts +213 -0
  53. package/dist/web3.js +640 -0
  54. package/package.json +1 -1
package/dist/ai.d.ts ADDED
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Streaming-text and agent-state family: motion primitives for
3
+ * conversational interfaces.
4
+ *
5
+ * Token streams arrive in bursts, so `createStreamReveal` batches them
6
+ * into a readable cadence before animating each unit's entrance.
7
+ * `createAgentState` is a pure-signal state machine for agent
8
+ * status, kept free of motion so each state can pair with any
9
+ * primitive. `parseDriftSpec` and `createSpecPlayer` let generated
10
+ * JSON choreography be validated and rendered deterministically.
11
+ *
12
+ * All primitives are signal-native, SSR-safe, dependency-free, and
13
+ * define sensible static behavior under `prefers-reduced-motion`.
14
+ */
15
+ import { type Accessor } from "solid-js";
16
+ import { type Easing, type EasingName } from "./easing.js";
17
+ import { type KineticTypeFrom } from "./motion.js";
18
+ type MaybeElement = () => Element | null | undefined;
19
+ export type StreamRevealStatus = "idle" | "streaming" | "done";
20
+ export interface StreamRevealOptions {
21
+ /** Split into "chars" or "words". Default "chars". */
22
+ unit?: "chars" | "words";
23
+ /** Flush the batch queue on this cadence, in ms. Default 120. */
24
+ batchMs?: number;
25
+ /** Flush early when the queue grows past this many chars. Default 24. */
26
+ maxBatch?: number;
27
+ /** Entrance duration per unit, in ms. Default 450. */
28
+ duration?: number;
29
+ /** Milliseconds between unit starts. Default 30. */
30
+ stagger?: number;
31
+ /** Starting transform/opacity/blur for each unit. */
32
+ from?: KineticTypeFrom;
33
+ /** Easing for each unit's entrance. Default "easeOutExpo". */
34
+ easing?: Easing | EasingName;
35
+ }
36
+ export interface StreamRevealControls {
37
+ /** Append raw stream tokens; they are batched internally. */
38
+ push: (chunk: string) => void;
39
+ /** Flush remaining units and settle. */
40
+ complete: () => void;
41
+ /** Clear the text and return to idle. */
42
+ reset: () => void;
43
+ /** Reactive status: "idle" | "streaming" | "done". */
44
+ status: Accessor<StreamRevealStatus>;
45
+ /** Chars waiting in the batch queue. */
46
+ pending: Accessor<number>;
47
+ }
48
+ /**
49
+ * Smooth irregular token cadence into readable animated text.
50
+ *
51
+ * Stream tokens arrive in bursts, a flood, then silence. `push()`
52
+ * only appends to an internal queue; one rAF task flushes the queue
53
+ * on a steady cadence (or early when it overflows) and drives every
54
+ * unit's entrance, so a 40-token burst reads as a calm typed line
55
+ * instead of a flicker.
56
+ *
57
+ * SSR-safe: `push` is a no-op on the server, `status()` is "done",
58
+ * and the host renders the full text statically. Under reduced motion
59
+ * batching and entrances are skipped: text appears as it is pushed.
60
+ *
61
+ * ```tsx
62
+ * let out!: HTMLDivElement
63
+ * const stream = createStreamReveal(() => out, { unit: "chars" })
64
+ * const reader = response.body.getReader()
65
+ * onMount(async () => {
66
+ * for (;;) {
67
+ * const { done, value } = await reader.read()
68
+ * if (done) break
69
+ * stream.push(decoder.decode(value))
70
+ * }
71
+ * stream.complete()
72
+ * })
73
+ * <div ref={out} aria-live="polite" />
74
+ * ```
75
+ */
76
+ export declare function createStreamReveal(ref: MaybeElement, options?: StreamRevealOptions): StreamRevealControls;
77
+ /** Lifecycle states of a conversational agent turn. */
78
+ export type AgentState = "idle" | "thinking" | "streaming" | "tool-call" | "done" | "error";
79
+ /** One legal state change. */
80
+ export interface AgentStateTransition {
81
+ from: AgentState;
82
+ to: AgentState;
83
+ }
84
+ export interface AgentStateOptions {
85
+ /** Starting state. Default "idle". */
86
+ initial?: AgentState;
87
+ /** Legal transitions. Omit to allow every transition. */
88
+ allowed?: AgentStateTransition[];
89
+ /** Called after entering a state, with the previous state. */
90
+ onEnter?: (state: AgentState, prev: AgentState) => void;
91
+ /** Called before leaving a state, with the next state. */
92
+ onExit?: (state: AgentState, next: AgentState) => void;
93
+ }
94
+ export interface AgentStateControls {
95
+ /** Current state. */
96
+ state: Accessor<AgentState>;
97
+ /** Previous state. */
98
+ prev: Accessor<AgentState>;
99
+ /** Move to the next state. Illegal transitions are ignored. */
100
+ set: (next: AgentState) => void;
101
+ /** Return to the initial state. */
102
+ reset: () => void;
103
+ /** Convenience for class bindings: `agent.is("thinking")`. */
104
+ is: (s: AgentState) => boolean;
105
+ }
106
+ /**
107
+ * A pure-signal state machine for agent UI.
108
+ *
109
+ * Motion is deliberately not built in: pair each state with a recipe
110
+ * instead, so the machine stays transparent, testable, and SSR-safe.
111
+ * A typical pairing is `createWobble` on typing dots while "thinking",
112
+ * `createStreamReveal` while "streaming", `createTransition` for the
113
+ * "tool-call" overlay, and `createColorShift` on the status pill for
114
+ * "done"/"error". Each of those degrades on its own under reduced
115
+ * motion.
116
+ *
117
+ * SSR-safe by construction: signals only, no DOM, no clock.
118
+ *
119
+ * ```ts
120
+ * const agent = createAgentState()
121
+ * agent.set("thinking")
122
+ * agent.state() // "thinking"
123
+ * agent.is("streaming") // false
124
+ * ```
125
+ */
126
+ export declare function createAgentState(options?: AgentStateOptions): AgentStateControls;
127
+ /** Primitives a drift spec can choreograph. */
128
+ export type DriftSpecPrimitive = "kineticType" | "camera" | "colorShift" | "transition" | "beat" | "streamReveal";
129
+ /** One choreographed step. */
130
+ export interface DriftSpecStep {
131
+ /** Which primitive renders this step. */
132
+ primitive: DriftSpecPrimitive;
133
+ /**
134
+ * Key into the refs record given to `createSpecPlayer`. Required
135
+ * for primitives that render into an element ("kineticType" and
136
+ * "streamReveal").
137
+ */
138
+ target?: string;
139
+ /**
140
+ * Primitive options. Validated against each primitive's minimal
141
+ * shape. "camera" reads `keyframes`, "colorShift" reads `stops`,
142
+ * "streamReveal" reads `text` here.
143
+ */
144
+ options?: Record<string, unknown>;
145
+ /** Step budget in milliseconds, for timed players. */
146
+ duration?: number;
147
+ }
148
+ /** A deterministic motion choreography, usually generated as JSON. */
149
+ export interface DriftSpec {
150
+ version: 1;
151
+ scenes: DriftSpecStep[];
152
+ }
153
+ /**
154
+ * Thrown by `parseDriftSpec`. `path` pinpoints the invalid value
155
+ * (for example "scenes[2].options.duration") so a generator can
156
+ * repair the spec without guessing.
157
+ */
158
+ export declare class DriftSpecError extends Error {
159
+ /** Dot/bracket path to the invalid value, "" for the root. */
160
+ path: string;
161
+ constructor(path: string, message: string);
162
+ }
163
+ /**
164
+ * Validate unknown input against the DriftSpec schema and return the
165
+ * typed spec. Throws `DriftSpecError` with a precise `path` on the
166
+ * first invalid value.
167
+ *
168
+ * Pure validation, no DOM: safe to run on the server.
169
+ *
170
+ * ```ts
171
+ * const spec = parseDriftSpec(JSON.parse(raw))
172
+ * const player = createSpecPlayer(spec, { title: () => titleEl })
173
+ * await player.play()
174
+ * ```
175
+ */
176
+ export declare function parseDriftSpec(input: unknown): DriftSpec;
177
+ export type SpecPlayerStatus = "idle" | "running" | "done";
178
+ export interface SpecPlayerControls {
179
+ /** Play every scene in order. Resolves after the last scene. */
180
+ play: () => Promise<void>;
181
+ /** Stop mid-spec. The play() promise resolves. */
182
+ stop: () => void;
183
+ /** Reactive status: "idle" | "running" | "done". */
184
+ status: Accessor<SpecPlayerStatus>;
185
+ /** Current scene index, or -1 before the first play(). */
186
+ scene: Accessor<number>;
187
+ }
188
+ /**
189
+ * Render a validated DriftSpec: each scene's primitive plays in
190
+ * order against the element refs the host supplies. `duration` on a
191
+ * step caps that step's budget.
192
+ *
193
+ * SSR-safe: `play()` is a no-op on the server. Under reduced motion
194
+ * `play()` jumps straight to the last scene (the clean final frame),
195
+ * matching `createScenePlayer`.
196
+ *
197
+ * ```ts
198
+ * const player = createSpecPlayer(spec, {
199
+ * title: () => titleEl,
200
+ * body: () => bodyEl,
201
+ * })
202
+ * player.scene() // 0, 1, ... as the spec plays
203
+ * await player.play()
204
+ * ```
205
+ */
206
+ export declare function createSpecPlayer(spec: DriftSpec, refs: Record<string, MaybeElement>): SpecPlayerControls;
207
+ export {};