@cloudlet/toast 0.0.0-stage → 1.0.0-rc.3

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 (100) hide show
  1. package/CHANGELOG.md +236 -0
  2. package/LICENSE +21 -0
  3. package/README.md +64 -2
  4. package/THIRD_PARTY_NOTICES.md +149 -0
  5. package/dist/contracts/controller.d.ts +71 -0
  6. package/dist/contracts/controller.d.ts.map +1 -0
  7. package/dist/contracts/events.d.ts +72 -0
  8. package/dist/contracts/events.d.ts.map +1 -0
  9. package/dist/contracts/identity.d.ts +32 -0
  10. package/dist/contracts/identity.d.ts.map +1 -0
  11. package/dist/contracts/internal.d.ts +188 -0
  12. package/dist/contracts/internal.d.ts.map +1 -0
  13. package/dist/contracts/notifications.d.ts +101 -0
  14. package/dist/contracts/notifications.d.ts.map +1 -0
  15. package/dist/contracts/operations.d.ts +76 -0
  16. package/dist/contracts/operations.d.ts.map +1 -0
  17. package/dist/contracts/snapshots.d.ts +48 -0
  18. package/dist/contracts/snapshots.d.ts.map +1 -0
  19. package/dist/core/controller.d.ts +7 -0
  20. package/dist/core/controller.d.ts.map +1 -0
  21. package/dist/core/controller.js +954 -0
  22. package/dist/core/controller.js.map +1 -0
  23. package/dist/core/validation.d.ts +17 -0
  24. package/dist/core/validation.d.ts.map +1 -0
  25. package/dist/core/validation.js +298 -0
  26. package/dist/core/validation.js.map +1 -0
  27. package/dist/create-cloudlet.d.ts +5 -0
  28. package/dist/create-cloudlet.d.ts.map +1 -0
  29. package/dist/create-cloudlet.js +34 -0
  30. package/dist/create-cloudlet.js.map +1 -0
  31. package/dist/index.d.ts +10 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +3 -0
  34. package/dist/react/announcer.d.ts +15 -0
  35. package/dist/react/announcer.d.ts.map +1 -0
  36. package/dist/react/announcer.js +134 -0
  37. package/dist/react/announcer.js.map +1 -0
  38. package/dist/react/bindings.d.ts +8 -0
  39. package/dist/react/bindings.d.ts.map +1 -0
  40. package/dist/react/bindings.js +84 -0
  41. package/dist/react/bindings.js.map +1 -0
  42. package/dist/react/card.d.ts +58 -0
  43. package/dist/react/card.d.ts.map +1 -0
  44. package/dist/react/card.js +300 -0
  45. package/dist/react/card.js.map +1 -0
  46. package/dist/react/generators.d.ts +46 -0
  47. package/dist/react/generators.d.ts.map +1 -0
  48. package/dist/react/generators.js +115 -0
  49. package/dist/react/generators.js.map +1 -0
  50. package/dist/react/gestures.d.ts +50 -0
  51. package/dist/react/gestures.d.ts.map +1 -0
  52. package/dist/react/gestures.js +239 -0
  53. package/dist/react/gestures.js.map +1 -0
  54. package/dist/react/host.d.ts +37 -0
  55. package/dist/react/host.d.ts.map +1 -0
  56. package/dist/react/host.js +816 -0
  57. package/dist/react/host.js.map +1 -0
  58. package/dist/react/motion.d.ts +206 -0
  59. package/dist/react/motion.d.ts.map +1 -0
  60. package/dist/react/motion.js +414 -0
  61. package/dist/react/motion.js.map +1 -0
  62. package/dist/react/plan.d.ts +45 -0
  63. package/dist/react/plan.d.ts.map +1 -0
  64. package/dist/react/plan.js +58 -0
  65. package/dist/react/plan.js.map +1 -0
  66. package/dist/react/shape.d.ts +7 -0
  67. package/dist/react/shape.d.ts.map +1 -0
  68. package/dist/react/shape.js +21 -0
  69. package/dist/react/shape.js.map +1 -0
  70. package/dist/react/viewport.d.ts +15 -0
  71. package/dist/react/viewport.d.ts.map +1 -0
  72. package/dist/react/viewport.js +16 -0
  73. package/dist/react/viewport.js.map +1 -0
  74. package/dist/react.d.ts +176 -0
  75. package/dist/react.d.ts.map +1 -0
  76. package/dist/react.js +2 -0
  77. package/dist/styles.css +1 -0
  78. package/package.json +17 -4
  79. package/src/contracts/controller.ts +61 -0
  80. package/src/contracts/events.ts +47 -0
  81. package/src/contracts/identity.ts +27 -0
  82. package/src/contracts/internal.ts +150 -0
  83. package/src/contracts/notifications.ts +104 -0
  84. package/src/contracts/operations.ts +71 -0
  85. package/src/contracts/snapshots.ts +59 -0
  86. package/src/core/controller.ts +1038 -0
  87. package/src/core/validation.ts +290 -0
  88. package/src/create-cloudlet.ts +43 -0
  89. package/src/index.ts +34 -0
  90. package/src/react/announcer.ts +189 -0
  91. package/src/react/bindings.tsx +100 -0
  92. package/src/react/card.tsx +222 -0
  93. package/src/react/generators.ts +274 -0
  94. package/src/react/gestures.ts +296 -0
  95. package/src/react/host.tsx +947 -0
  96. package/src/react/motion.ts +484 -0
  97. package/src/react/plan.ts +101 -0
  98. package/src/react/shape.ts +33 -0
  99. package/src/react/viewport.ts +10 -0
  100. package/src/react.ts +190 -0
package/src/react.ts ADDED
@@ -0,0 +1,190 @@
1
+ 'use client';
2
+
3
+ import type { ReactElement, ReactNode } from 'react';
4
+ import type { CloudletController, ControllerOptions, FocusTarget } from './contracts/controller.js';
5
+ import type { NotificationHandle } from './contracts/identity.js';
6
+ import type { NotificationPatch, NotificationSpec } from './contracts/notifications.js';
7
+ import type { OperationContext, OperationFactory, TrackOptions } from './contracts/operations.js';
8
+ import type { ControllerSnapshot, NotificationSnapshot } from './contracts/snapshots.js';
9
+
10
+ export type ReactNotificationSpec = NotificationSpec<ReactNode>;
11
+ export type ReactNotificationPatch = NotificationPatch<ReactNode>;
12
+ export type ReactCloudletController = CloudletController<ReactNode, AbortSignal>;
13
+ export type ReactOperationContext = OperationContext<AbortSignal>;
14
+ export type ReactOperationFactory<T> = OperationFactory<T, AbortSignal>;
15
+ export type ReactTrackOptions<T> = TrackOptions<T, ReactNode, AbortSignal>;
16
+
17
+ /** Public web factory signature, including native cancellation signals. */
18
+ export type CreateCloudlet = (options?: ControllerOptions) => ReactCloudletController;
19
+
20
+ export interface CloudletProviderProps {
21
+ /** Null while an effect-owned controller does not exist yet (server render, first client render). */
22
+ readonly controller: ReactCloudletController | null;
23
+ readonly children?: ReactNode;
24
+ }
25
+
26
+ export interface EdgeInsets {
27
+ readonly top?: number;
28
+ readonly right?: number;
29
+ readonly bottom?: number;
30
+ readonly left?: number;
31
+ }
32
+
33
+ export interface ToasterOffsets {
34
+ /** CSS px added outside safe area; omitting an edge uses the CSS viewport-gutter token. */
35
+ readonly gutter?: EdgeInsets;
36
+ /** Additional obstruction beyond safe area; never include safe-area size again. */
37
+ readonly obstruction?: EdgeInsets;
38
+ }
39
+
40
+ export interface CloudletLabels {
41
+ readonly region: string;
42
+ /** Accessible name of the Island carousel region. */
43
+ readonly island: string;
44
+ /** Spoken role of the open Island (`aria-roledescription`), "carousel" by default. */
45
+ readonly carousel: string;
46
+ /** Spoken role of each slide in the Island (`aria-roledescription`), "slide" by default. */
47
+ readonly slide: string;
48
+ readonly close: string;
49
+ readonly retry: string;
50
+ readonly cancel: string;
51
+ readonly cancellationRequested: string;
52
+ readonly acknowledgeOverflow: string;
53
+ /** Hidden hint that Escape collapses the Island. */
54
+ readonly collapse: string;
55
+ /** Name of the collapsed stack button: top title, records in the stack, missed notifications. */
56
+ readonly stackSummary: (title: string, count: number, missed: number) => string;
57
+ /** 1-based slide position. */
58
+ readonly page: (index: number, total: number) => string;
59
+ readonly overflowCount: (count: number) => string;
60
+ }
61
+
62
+ export interface AnnouncementFormatters {
63
+ readonly notification: (notification: NotificationSnapshot<ReactNode>) => string;
64
+ readonly queued: (count: number) => string;
65
+ readonly occurrences: (notification: NotificationSnapshot<ReactNode>) => string;
66
+ readonly overflow: (count: number) => string;
67
+ readonly operation: (notification: NotificationSnapshot<ReactNode>, phase: 'started' | 'fulfilled' | 'rejected' | 'cancelled' | 'cancel-requested') => string;
68
+ readonly actionError: (notification: NotificationSnapshot<ReactNode>, message: string) => string;
69
+ /** Optional for compatibility with existing complete formatter objects. */
70
+ readonly actionPending?: (notification: NotificationSnapshot<ReactNode>) => string;
71
+ /** Current aggregate after returning from a hidden document; no event replay. */
72
+ readonly resumed?: (count: number) => string;
73
+ }
74
+
75
+ export interface ToasterAttention {
76
+ /** Milliseconds from admission before an auto-open; default 600. */
77
+ readonly delay?: number;
78
+ }
79
+
80
+ /** A physical spring of DESIGN §7. */
81
+ export interface CloudletSpring {
82
+ readonly stiffness: number;
83
+ readonly damping: number;
84
+ readonly mass: number;
85
+ }
86
+
87
+ /** A time-defined spring: settles in about `duration` ms; `bounce` 0 has no overshoot. */
88
+ export interface CloudletTimedSpring {
89
+ readonly duration: number;
90
+ readonly bounce: number;
91
+ }
92
+
93
+ /**
94
+ * The motion constants of DESIGN §7: durations in ms at `timeScale: 1`, offsets and blur in CSS px.
95
+ * Reported by the laboratory's tuning panel; see `ToasterMotion.overrides`.
96
+ */
97
+ export interface CloudletMotionConstants {
98
+ /** A new pill: opacity, scale from `scale` and translateY from `offset` px at the edge. */
99
+ readonly enter: CloudletTimedSpring & { readonly scale: number; readonly offset: number; readonly fade: number };
100
+ /** The last record or a dismissed top pill leaving. */
101
+ readonly exit: CloudletTimedSpring;
102
+ /** Shape (width, height, radius) opening into the Island. */
103
+ readonly shapeOpen: CloudletSpring;
104
+ /** Shape collapsing into the pill and adjusting to new content. */
105
+ readonly shapeClose: CloudletSpring;
106
+ /** Slide between notifications inside the Island; swipes release with it. */
107
+ readonly slide: CloudletSpring;
108
+ /** Badge presence; `scale` is its hidden scale. */
109
+ readonly badge: CloudletTimedSpring & { readonly scale: number };
110
+ /** Tails retracting on open and returning at the end of a collapse. */
111
+ readonly tails: number;
112
+ /** Close button, body and indicator: delay, fade in, fade out on collapse, rise in px. */
113
+ readonly chromeDelay: number;
114
+ readonly chromeIn: number;
115
+ readonly chromeOut: number;
116
+ readonly chromeOffset: number;
117
+ /** Title and icon blur swap: outgoing, incoming, blur radius in px. */
118
+ readonly headerOut: number;
119
+ readonly headerIn: number;
120
+ readonly blur: number;
121
+ /** Body crossfade: outgoing, incoming, rise of the incoming body in px. */
122
+ readonly bodyOut: number;
123
+ readonly bodyIn: number;
124
+ readonly bodyOffset: number;
125
+ /** A body update sooner than this after the previous one changes the text in place (no crossfade). */
126
+ readonly bodyQuiet: number;
127
+ /** Badge number and indicator text blur swap. */
128
+ readonly countSwap: number;
129
+ /** Progress ring value tween. */
130
+ readonly progress: number;
131
+ /** Hover: duration and the extra tail spread per step in px. */
132
+ readonly hover: number;
133
+ readonly hoverLift: number;
134
+ /** Reduced motion: every transition becomes an opacity change of this length. */
135
+ readonly reduced: number;
136
+ }
137
+
138
+ /** Partial `CloudletMotionConstants`; nested springs may be partial too. */
139
+ export type CloudletMotionOverrides = {
140
+ readonly [K in keyof CloudletMotionConstants]?: CloudletMotionConstants[K] extends number
141
+ ? number : Partial<CloudletMotionConstants[K]>;
142
+ };
143
+
144
+ export interface ToasterMotion {
145
+ /**
146
+ * Debugging and laboratory aid: slows every transition (0.5 = twice as slow).
147
+ * Default 1; a non-finite or nonpositive value falls back to 1. Not recommended in production.
148
+ */
149
+ readonly timeScale?: number;
150
+ /**
151
+ * Debugging and laboratory channel (task 16): replaces DESIGN §7 constants live, for
152
+ * transitions started after the change. A field that is not a finite number in range
153
+ * (stiffness and mass > 0, the rest ≥ 0) keeps its default. Not a styling API: the
154
+ * values may change between releases; do not ship overrides to production.
155
+ */
156
+ readonly overrides?: CloudletMotionOverrides;
157
+ }
158
+
159
+ /** Styling hooks of the renderer (DESIGN §8); see `ToasterProps.classNames`. */
160
+ export type CloudletPart = 'host' | 'stack' | 'pill' | 'tail' | 'badge' | 'island' | 'header' | 'icon' | 'title'
161
+ | 'close' | 'body' | 'description' | 'actions' | 'action' | 'indicator' | 'overflow';
162
+
163
+ export interface ToasterProps {
164
+ readonly position?: 'auto' | 'top-center' | 'bottom-center';
165
+ readonly theme?: 'system' | 'light' | 'dark';
166
+ readonly dir?: 'ltr' | 'rtl';
167
+ /** Read after mount; a connected HTML Element in the mounting root's document. Fixed until remount. */
168
+ readonly container?: Element | (() => Element | null) | null;
169
+ readonly offsets?: ToasterOffsets;
170
+ readonly nonce?: string;
171
+ readonly labels?: Partial<CloudletLabels>;
172
+ readonly announcements?: Partial<AnnouncementFormatters>;
173
+ /** Read on attach; changing it requires remount. */
174
+ readonly attention?: ToasterAttention;
175
+ /** Overrides the controller's `autoDismiss` while defined; changes apply without remount. */
176
+ readonly autoDismiss?: boolean;
177
+ /** Read on every render. */
178
+ readonly motion?: ToasterMotion;
179
+ /** Extra classes per part, added to the own `cloudlet-*` classes (never replacing them). Read on every render. */
180
+ readonly classNames?: Partial<Record<CloudletPart, string>>;
181
+ }
182
+
183
+ /** Public component and hook signatures. */
184
+ export type CloudletProviderComponent = (props: CloudletProviderProps) => ReactElement | null;
185
+ export type UseCloudlet = () => ReactCloudletController;
186
+ export type UseOptionalCloudlet = () => ReactCloudletController | null;
187
+ export type ToasterComponent = (props: ToasterProps) => ReactElement | null;
188
+
189
+ export type { ControllerSnapshot, FocusTarget, NotificationHandle };
190
+ export { CloudletProvider, useCloudlet, useOptionalCloudlet, Toaster } from './react/bindings.js';