@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
@@ -0,0 +1,300 @@
1
+ import { Component as e, Suspense as t, useEffect as n, useId as r, useRef as i, useState as a } from "react";
2
+ import { jsx as o, jsxs as s } from "react/jsx-runtime";
3
+ //#region src/react/card.tsx
4
+ var c = {
5
+ region: "Notifications",
6
+ island: "Current notifications",
7
+ carousel: "carousel",
8
+ slide: "slide",
9
+ close: "Close notification",
10
+ retry: "Retry",
11
+ cancel: "Request cancellation",
12
+ cancellationRequested: "Cancellation requested",
13
+ acknowledgeOverflow: "Acknowledge missed notifications",
14
+ collapse: "Press Escape to collapse",
15
+ stackSummary: (e, t, n) => [
16
+ e,
17
+ ...t > 1 ? [`${t} notifications`] : [],
18
+ ...n > 0 ? [`${n} missed`] : []
19
+ ].join(", "),
20
+ page: (e, t) => `${e} of ${t}`,
21
+ overflowCount: (e) => `${e} missed notifications`
22
+ }, l = class extends e {
23
+ state = {
24
+ failed: !1,
25
+ content: this.props.content
26
+ };
27
+ static getDerivedStateFromError() {
28
+ return { failed: !0 };
29
+ }
30
+ static getDerivedStateFromProps(e, t) {
31
+ return e.content === t.content ? null : {
32
+ failed: !1,
33
+ content: e.content
34
+ };
35
+ }
36
+ componentDidCatch(e) {
37
+ this.props.bridge.reportDiagnostic(this.props.lease, {
38
+ code: "slot-error",
39
+ source: "Toaster.slot",
40
+ message: "A rich slot could not be rendered",
41
+ handle: this.props.handle,
42
+ error: e
43
+ });
44
+ }
45
+ render() {
46
+ return this.state.failed ? this.props.bridge.renderError : /* @__PURE__ */ o(t, {
47
+ fallback: this.props.bridge.renderError,
48
+ children: /* @__PURE__ */ o(u, { ...this.props })
49
+ });
50
+ }
51
+ };
52
+ function u({ content: e, bridge: t, lease: r, handle: s, rejectFocus: c }) {
53
+ let l = i(null), [u, d] = a(null), f = u?.content === e;
54
+ return n(() => {
55
+ let n = l.current;
56
+ if (!n) return;
57
+ let i = !1, a = () => {
58
+ !i && n.querySelector("a[href],button,input,select,textarea,summary,iframe,[tabindex],[contenteditable]:not([contenteditable=\"false\"]),audio[controls],video[controls]") && (i = !0, d({ content: e }), t.reportDiagnostic(r, {
59
+ code: "slot-error",
60
+ source: "Toaster.slot",
61
+ message: "Rich slots must be non-interactive; use the notification action",
62
+ handle: s
63
+ }));
64
+ };
65
+ a();
66
+ let o = n.ownerDocument.defaultView?.MutationObserver, c = o ? new o(a) : null;
67
+ return c?.observe(n, {
68
+ childList: !0,
69
+ subtree: !0,
70
+ attributes: !0
71
+ }), () => c?.disconnect();
72
+ }, [
73
+ e,
74
+ t,
75
+ r,
76
+ s
77
+ ]), /* @__PURE__ */ o("div", {
78
+ ref: l,
79
+ className: "cloudlet-slot",
80
+ onFocusCapture: (e) => c(e.relatedTarget),
81
+ children: f ? t.renderError : e
82
+ });
83
+ }
84
+ function d(e, t, n, r) {
85
+ return /* @__PURE__ */ o("button", {
86
+ type: "button",
87
+ "data-cloudlet-control": e,
88
+ ...r,
89
+ onClick: n,
90
+ children: t
91
+ });
92
+ }
93
+ function f(e) {
94
+ return /* @__PURE__ */ o("svg", {
95
+ "aria-hidden": "true",
96
+ viewBox: "0 0 16 16",
97
+ children: /* @__PURE__ */ o("path", { d: e })
98
+ });
99
+ }
100
+ function p(e) {
101
+ return (t, n) => {
102
+ let r = e?.[t];
103
+ return typeof r == "string" && r.trim() ? `${n} ${r.trim()}` : n;
104
+ };
105
+ }
106
+ var m = {
107
+ success: "M4.5 8.5 7 11l4.5-5.5",
108
+ error: "m5.5 5.5 5 5m0-5-5 5",
109
+ info: "M8 7.5V11M8 5h.01",
110
+ warning: "M8 4.75V8.5M8 11.25h.01"
111
+ };
112
+ function h({ notification: e, slot: t, part: n, preview: r = !1 }) {
113
+ let { content: i, kind: a } = e, { progress: c } = i, l = c?.kind === "determinate";
114
+ return /* @__PURE__ */ s("div", {
115
+ className: n("icon", "cloudlet-icon"),
116
+ "data-kind": a,
117
+ ...c && !r ? {
118
+ role: "progressbar",
119
+ "aria-valuemin": 0,
120
+ "aria-valuemax": 100,
121
+ "aria-valuenow": l ? Math.round(c.value * 100) : void 0,
122
+ "aria-label": c.label ?? i.title
123
+ } : { "aria-hidden": "true" },
124
+ children: [i.icon === void 0 ? a === "loading" ? !c && /* @__PURE__ */ o("svg", {
125
+ "aria-hidden": "true",
126
+ viewBox: "0 0 16 16",
127
+ className: "cloudlet-glyph cloudlet-spinner",
128
+ children: /* @__PURE__ */ o("circle", {
129
+ cx: "8",
130
+ cy: "8",
131
+ r: "5.5",
132
+ strokeDasharray: "22 13"
133
+ })
134
+ }) : /* @__PURE__ */ o("svg", {
135
+ "aria-hidden": "true",
136
+ viewBox: "0 0 16 16",
137
+ className: "cloudlet-glyph",
138
+ children: /* @__PURE__ */ o("path", { d: m[a] })
139
+ }) : /* @__PURE__ */ o("span", {
140
+ className: "cloudlet-glyph",
141
+ "aria-hidden": "true",
142
+ children: t(i.icon)
143
+ }), c && /* @__PURE__ */ s("svg", {
144
+ "aria-hidden": "true",
145
+ viewBox: "0 0 32 32",
146
+ className: "cloudlet-ring",
147
+ "data-progress": c.kind,
148
+ children: [/* @__PURE__ */ o("circle", {
149
+ className: "cloudlet-ring-track",
150
+ cx: "16",
151
+ cy: "16",
152
+ r: "15"
153
+ }), /* @__PURE__ */ o("circle", {
154
+ className: "cloudlet-progress-fill",
155
+ cx: "16",
156
+ cy: "16",
157
+ r: "15",
158
+ pathLength: "100",
159
+ transform: "rotate(-90 16 16)",
160
+ strokeDasharray: l ? r ? `${Math.round(c.value * 1e4) / 100} 100` : "0 100" : "25 75"
161
+ })]
162
+ })]
163
+ });
164
+ }
165
+ function g(e, t, n, r) {
166
+ return (i) => /* @__PURE__ */ o(l, {
167
+ content: i,
168
+ bridge: e,
169
+ lease: t,
170
+ handle: n,
171
+ rejectFocus: r
172
+ });
173
+ }
174
+ function _({ notification: e, slot: t, part: n, titleId: r }) {
175
+ let i = n("title", "cloudlet-title");
176
+ return /* @__PURE__ */ s("div", {
177
+ className: "cloudlet-heading",
178
+ children: [/* @__PURE__ */ o(h, {
179
+ notification: e,
180
+ slot: t,
181
+ part: n,
182
+ preview: r === void 0
183
+ }), r === void 0 ? /* @__PURE__ */ o("h2", {
184
+ className: i,
185
+ children: e.content.title
186
+ }) : /* @__PURE__ */ o("h2", {
187
+ id: r,
188
+ tabIndex: -1,
189
+ "data-cloudlet-title": "",
190
+ className: i,
191
+ children: e.content.title
192
+ })]
193
+ });
194
+ }
195
+ var v = (e) => /* @__PURE__ */ o("div", {
196
+ className: "cloudlet-slot",
197
+ children: e
198
+ }), y = (e) => !!e?.canRetry && e.status !== "fulfilled";
199
+ function b({ notification: e, labels: t, part: n }) {
200
+ let { content: r, operation: i, kind: a } = e, c = n("action", "cloudlet-action"), l = (e, t = !1) => /* @__PURE__ */ o("button", {
201
+ type: "button",
202
+ tabIndex: -1,
203
+ className: t ? `${c} cloudlet-primary` : c,
204
+ children: e
205
+ });
206
+ return /* @__PURE__ */ o("div", {
207
+ className: "cloudlet-slide",
208
+ "data-kind": a,
209
+ children: /* @__PURE__ */ s("div", {
210
+ className: n("body", "cloudlet-body"),
211
+ "data-kind": a,
212
+ children: [
213
+ r.description && /* @__PURE__ */ o("div", {
214
+ className: n("description", "cloudlet-description"),
215
+ children: r.description.kind === "text" ? /* @__PURE__ */ o("p", { children: r.description.text }) : v(r.description.content)
216
+ }),
217
+ /* @__PURE__ */ s("div", {
218
+ className: n("actions", "cloudlet-actions"),
219
+ children: [
220
+ r.action?.kind === "command" && l(r.action.label, !0),
221
+ r.action?.kind === "link" && /* @__PURE__ */ o("a", {
222
+ className: `${c} cloudlet-primary`,
223
+ children: r.action.label
224
+ }),
225
+ y(i) && l(t.retry),
226
+ i?.canCancel && l(i.cancelRequested ? t.cancellationRequested : t.cancel)
227
+ ]
228
+ }),
229
+ e.action.status === "failed" && /* @__PURE__ */ o("p", {
230
+ className: "cloudlet-action-error",
231
+ children: e.action.message
232
+ })
233
+ ]
234
+ })
235
+ });
236
+ }
237
+ function x({ notification: e, bridge: t, lease: n, labels: i, navigate: a, slot: c, part: l }) {
238
+ let { handle: u, content: f, operation: p, action: m, kind: h } = e, g = l("action", "cloudlet-action"), _ = `${g} cloudlet-primary`, v = r(), b = f.action, x = (e) => {
239
+ queueMicrotask(() => {
240
+ e.defaultPrevented || a(u);
241
+ });
242
+ };
243
+ return /* @__PURE__ */ s("div", {
244
+ className: l("body", "cloudlet-body"),
245
+ "data-kind": h,
246
+ children: [
247
+ f.description && /* @__PURE__ */ s("div", {
248
+ className: l("description", "cloudlet-description"),
249
+ children: [f.description.kind === "text" && /* @__PURE__ */ o("p", { children: f.description.text }), f.description.kind === "rich" && c(f.description.content)]
250
+ }),
251
+ /* @__PURE__ */ s("div", {
252
+ className: l("actions", "cloudlet-actions"),
253
+ children: [
254
+ b?.kind === "command" && d("action", b.label, () => {
255
+ m.status !== "pending" && t.invokeAction(n, u);
256
+ }, {
257
+ className: _,
258
+ "aria-disabled": m.status === "pending",
259
+ "aria-busy": m.status === "pending",
260
+ "aria-describedby": m.status === "failed" ? `${v}-action-error` : void 0
261
+ }),
262
+ b?.kind === "link" && /* @__PURE__ */ o("a", {
263
+ "data-cloudlet-control": "action",
264
+ className: _,
265
+ href: b.href,
266
+ target: b.target,
267
+ rel: b.target === "_blank" ? [...new Set(`${b.rel ?? ""} noopener`.trim().split(/\s+/u))].join(" ") : b.rel,
268
+ onClick: (e) => x(e.nativeEvent),
269
+ onAuxClick: (e) => {
270
+ e.button === 1 && x(e.nativeEvent);
271
+ },
272
+ children: b.label
273
+ }),
274
+ y(p) && d("retry", i.retry, () => t.retryOperation(n, u, p.token), { className: g }),
275
+ p?.canCancel && d("cancel", p.cancelRequested ? i.cancellationRequested : i.cancel, () => {
276
+ p.cancelRequested || t.cancelOperation(n, u, p.token);
277
+ }, {
278
+ className: g,
279
+ "aria-disabled": p.cancelRequested
280
+ })
281
+ ]
282
+ }),
283
+ m.status === "failed" && /* @__PURE__ */ o("p", {
284
+ id: `${v}-action-error`,
285
+ className: "cloudlet-action-error",
286
+ children: m.message
287
+ })
288
+ ]
289
+ });
290
+ }
291
+ function S(e, t, n) {
292
+ return d("close", f("m4.5 4.5 7 7m0-7-7 7"), n, {
293
+ "aria-label": e.close,
294
+ className: t("close", "cloudlet-close")
295
+ });
296
+ }
297
+ //#endregion
298
+ export { x as Body, _ as Heading, b as SlidePreview, h as StatusIcon, S as closeButton, c as defaultLabels, p as partClasses, v as previewSlot, g as slotRenderer };
299
+
300
+ //# sourceMappingURL=card.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card.js","names":["defaultLabels","title","count","missed","index","total","SlotBoundary","Component","props","state","Suspense","CheckedSlot","ref","useRef","invalidContent","setInvalidContent","useState","invalid","content","useEffect","element","reported","check","bridge","lease","Observer","observer","handle","rejectFocus","event","control","name","glyph","path","partClasses","extra","classNames","part","own","glyphs","StatusIcon","notification","determinate","progress","kind","preview","slot","slotRenderer","value","rejectSlotFocus","Heading","titleId","previewSlot","retryable","operation","SlidePreview","action","lookalike","primary","labels","Body","neutral","id","useId","command","activateLink","navigate","closeButton","onClick"],"sources":["../../src/react/card.tsx"],"sourcesContent":["import { Component, Suspense, useEffect, useId, useRef, useState } from 'react';\nimport type { ComponentPropsWithRef, ReactNode } from 'react';\nimport type { HostLease, RendererBridge } from '../contracts/internal.js';\nimport type { NotificationHandle } from '../contracts/identity.js';\nimport type { NotificationKind } from '../contracts/notifications.js';\nimport type { NotificationSnapshot } from '../contracts/snapshots.js';\nimport type { CloudletLabels, CloudletPart, ToasterProps } from '../react.js';\n\nexport const defaultLabels: CloudletLabels = {\n region: 'Notifications', island: 'Current notifications', carousel: 'carousel', slide: 'slide',\n close: 'Close notification', retry: 'Retry',\n cancel: 'Request cancellation', cancellationRequested: 'Cancellation requested',\n acknowledgeOverflow: 'Acknowledge missed notifications', collapse: 'Press Escape to collapse',\n stackSummary: (title, count, missed) => [title, ...(count > 1 ? [`${count} notifications`] : []),\n ...(missed > 0 ? [`${missed} missed`] : [])].join(', '),\n page: (index, total) => `${index} of ${total}`,\n overflowCount: count => `${count} missed notifications`,\n};\n\ninterface SlotProps {\n readonly content: ReactNode;\n readonly bridge: RendererBridge<ReactNode>;\n readonly lease: HostLease;\n readonly handle: NotificationHandle;\n readonly rejectFocus: (previous: EventTarget | null) => void;\n}\n\nclass SlotBoundary extends Component<SlotProps, { failed: boolean; content: ReactNode }> {\n override state = { failed: false, content: this.props.content };\n static getDerivedStateFromError() { return { failed: true }; }\n static getDerivedStateFromProps(props: SlotProps, state: { content: ReactNode }) {\n return props.content === state.content ? null : { failed: false, content: props.content };\n }\n override componentDidCatch(error: unknown) {\n this.props.bridge.reportDiagnostic(this.props.lease, { code: 'slot-error', source: 'Toaster.slot',\n message: 'A rich slot could not be rendered', handle: this.props.handle, error });\n }\n override render() {\n return this.state.failed ? this.props.bridge.renderError\n : <Suspense fallback={this.props.bridge.renderError}><CheckedSlot {...this.props} /></Suspense>;\n }\n}\n\nfunction CheckedSlot({ content, bridge, lease, handle, rejectFocus }: SlotProps) {\n const ref = useRef<HTMLDivElement>(null);\n const [invalidContent, setInvalidContent] = useState<{ content: ReactNode } | null>(null);\n const invalid = invalidContent?.content === content;\n useEffect(() => {\n const element = ref.current;\n if (!element) return;\n let reported = false;\n const check = () => {\n if (reported || !element.querySelector('a[href],button,input,select,textarea,summary,iframe,[tabindex],[contenteditable]:not([contenteditable=\"false\"]),audio[controls],video[controls]')) return;\n reported = true;\n setInvalidContent({ content });\n bridge.reportDiagnostic(lease, { code: 'slot-error', source: 'Toaster.slot',\n message: 'Rich slots must be non-interactive; use the notification action', handle });\n };\n check();\n const Observer = element.ownerDocument.defaultView?.MutationObserver;\n const observer = Observer ? new Observer(check) : null;\n observer?.observe(element, { childList: true, subtree: true, attributes: true });\n return () => observer?.disconnect();\n }, [content, bridge, lease, handle]);\n return <div ref={ref} className=\"cloudlet-slot\" onFocusCapture={event => rejectFocus(event.relatedTarget)}>\n {invalid ? bridge.renderError : content}\n </div>;\n}\n\nfunction control(name: string, children: ReactNode, onClick: () => void, props?: ComponentPropsWithRef<'button'>) {\n return <button type=\"button\" data-cloudlet-control={name} {...props} onClick={onClick}>{children}</button>;\n}\n\nfunction glyph(path: string) {\n return <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\"><path d={path} /></svg>;\n}\n\n/** Adds the application's `classNames` part to an own `cloudlet-*` class, never replacing it. */\nexport type PartClass = (part: CloudletPart, own: string) => string;\nexport function partClasses(classNames: ToasterProps['classNames']): PartClass {\n return (part, own) => {\n const extra = classNames?.[part];\n return typeof extra === 'string' && extra.trim() ? `${own} ${extra.trim()}` : own;\n };\n}\n\n/** 16 px stroke glyphs drawn in the status colour (DESIGN §8). */\nconst glyphs: Record<Exclude<NotificationKind, 'loading'>, string> = {\n success: 'M4.5 8.5 7 11l4.5-5.5',\n error: 'm5.5 5.5 5 5m0-5-5 5',\n info: 'M8 7.5V11M8 5h.01',\n warning: 'M8 4.75V8.5M8 11.25h.01',\n};\n\n/**\n * The status icon: a 24 px tinted circle with a glyph, the loading spinner or the\n * notification's own icon, and the 2 px progress ring around it (pill and Island\n * share these nodes). With progress the icon is the accessible progressbar. The\n * determinate arc is owned by the host sampler (one RAF per host, 240 ms tween);\n * `preview` draws the value statically for the inert swipe neighbour.\n */\nexport function StatusIcon({ notification, slot, part, preview = false }: {\n notification: NotificationSnapshot<ReactNode>; slot: (value: ReactNode) => ReactNode; part: PartClass; preview?: boolean;\n}) {\n const { content, kind } = notification;\n const { progress } = content;\n const determinate = progress?.kind === 'determinate';\n return <div className={part('icon', 'cloudlet-icon')} data-kind={kind}\n {...(progress && !preview ? { role: 'progressbar', 'aria-valuemin': 0, 'aria-valuemax': 100,\n 'aria-valuenow': determinate ? Math.round(progress.value * 100) : undefined, 'aria-label': progress.label ?? content.title }\n : { 'aria-hidden': 'true' })}>\n {content.icon !== undefined\n ? <span className=\"cloudlet-glyph\" aria-hidden=\"true\">{slot(content.icon)}</span>\n // With progress the ring is the activity indicator of a loading record.\n : kind === 'loading' ? !progress && <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" className=\"cloudlet-glyph cloudlet-spinner\">\n <circle cx=\"8\" cy=\"8\" r=\"5.5\" strokeDasharray=\"22 13\" /></svg>\n : <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" className=\"cloudlet-glyph\"><path d={glyphs[kind]} /></svg>}\n {progress && <svg aria-hidden=\"true\" viewBox=\"0 0 32 32\" className=\"cloudlet-ring\" data-progress={progress.kind}>\n <circle className=\"cloudlet-ring-track\" cx=\"16\" cy=\"16\" r=\"15\" />\n <circle className=\"cloudlet-progress-fill\" cx=\"16\" cy=\"16\" r=\"15\" pathLength=\"100\" transform=\"rotate(-90 16 16)\"\n strokeDasharray={!determinate ? '25 75' : preview ? `${Math.round(progress.value * 10000) / 100} 100` : '0 100'} />\n </svg>}\n </div>;\n}\n\nexport function slotRenderer(bridge: RendererBridge<ReactNode>, lease: HostLease, handle: NotificationHandle,\n rejectSlotFocus: (previous: EventTarget | null) => void) {\n return (value: ReactNode) => <SlotBoundary content={value} bridge={bridge} lease={lease} handle={handle} rejectFocus={rejectSlotFocus} />;\n}\n\n/**\n * Status icon and title: the same DOM nodes in the pill and in the Island header,\n * so opening never re-creates them and the title can receive focus in place.\n */\nexport function Heading({ notification, slot, part, titleId }: {\n notification: NotificationSnapshot<ReactNode>; slot: (value: ReactNode) => ReactNode; part: PartClass;\n /** Omitted for the inert neighbour preview: no id, focus target, data hook or live progress. */\n titleId?: string;\n}) {\n const title = part('title', 'cloudlet-title');\n return <div className=\"cloudlet-heading\">\n <StatusIcon notification={notification} slot={slot} part={part} preview={titleId === undefined} />\n {titleId === undefined ? <h2 className={title}>{notification.content.title}</h2>\n : <h2 id={titleId} tabIndex={-1} data-cloudlet-title=\"\" className={title}>{notification.content.title}</h2>}\n </div>;\n}\n\n/** Rich content of the inert neighbour preview: rendered as is, never checked or reported twice. */\nexport const previewSlot = (value: ReactNode) => <div className=\"cloudlet-slot\">{value}</div>;\n\n/** A settled factory can always retry through the API; only an unsuccessful attempt offers the button. */\ntype Operation = NotificationSnapshot<ReactNode>['operation'];\nconst retryable = (operation: Operation): operation is NonNullable<Operation> => !!operation?.canRetry && operation.status !== 'fulfilled';\n\n/**\n * The neighbour shown only while a finger drags the Island content (DESIGN §3, §9):\n * the same layout as a live slide, but every control is a lookalike without\n * handlers, ids, links or tab stops. The caller puts it in an `inert` container.\n */\nexport function SlidePreview({ notification, labels, part }: { notification: NotificationSnapshot<ReactNode>; labels: CloudletLabels; part: PartClass }) {\n const { content, operation, kind } = notification;\n const action = part('action', 'cloudlet-action');\n const lookalike = (children: ReactNode, primary = false) =>\n <button type=\"button\" tabIndex={-1} className={primary ? `${action} cloudlet-primary` : action}>{children}</button>;\n // Only the body slides (DESIGN §7, task 17): the preview shows the neighbour's body under the live heading.\n return <div className=\"cloudlet-slide\" data-kind={kind}>\n <div className={part('body', 'cloudlet-body')} data-kind={kind}>\n {content.description && <div className={part('description', 'cloudlet-description')}>\n {content.description.kind === 'text' ? <p>{content.description.text}</p> : previewSlot(content.description.content)}\n </div>}\n <div className={part('actions', 'cloudlet-actions')}>\n {content.action?.kind === 'command' && lookalike(content.action.label, true)}\n {content.action?.kind === 'link' && <a className={`${action} cloudlet-primary`}>{content.action.label}</a>}\n {retryable(operation) && lookalike(labels.retry)}\n {operation?.canCancel && lookalike(operation.cancelRequested ? labels.cancellationRequested : labels.cancel)}\n </div>\n {notification.action.status === 'failed' && <p className=\"cloudlet-action-error\">{notification.action.message}</p>}\n </div>\n </div>;\n}\n\n/** Island slide body: description, progress, actions and the action error. */\nexport function Body({ notification, bridge, lease, labels, navigate, slot, part }: {\n notification: NotificationSnapshot<ReactNode>; bridge: RendererBridge<ReactNode>; lease: HostLease;\n labels: CloudletLabels; navigate: (handle: NotificationHandle) => void; slot: (value: ReactNode) => ReactNode; part: PartClass;\n}) {\n const { handle, content, operation, action, kind } = notification;\n // The primary action is tinted with the status; retry and cancel stay neutral.\n const neutral = part('action', 'cloudlet-action');\n const primary = `${neutral} cloudlet-primary`;\n const id = useId();\n const command = content.action;\n const activateLink = (event: MouseEvent) => {\n // Observe cancellation after portal/application ancestors have handled activation.\n queueMicrotask(() => { if (!event.defaultPrevented) navigate(handle); });\n };\n return <div className={part('body', 'cloudlet-body')} data-kind={kind}>\n {content.description && <div className={part('description', 'cloudlet-description')}>\n {content.description.kind === 'text' && <p>{content.description.text}</p>}\n {content.description.kind === 'rich' && slot(content.description.content)}\n </div>}\n <div className={part('actions', 'cloudlet-actions')}>\n {command?.kind === 'command' && control('action', command.label, () => {\n if (action.status !== 'pending') bridge.invokeAction(lease, handle);\n }, { className: primary, 'aria-disabled': action.status === 'pending', 'aria-busy': action.status === 'pending',\n 'aria-describedby': action.status === 'failed' ? `${id}-action-error` : undefined })}\n {command?.kind === 'link' && <a data-cloudlet-control=\"action\" className={primary} href={command.href} target={command.target}\n rel={command.target === '_blank' ? [...new Set(`${command.rel ?? ''} noopener`.trim().split(/\\s+/u))].join(' ') : command.rel}\n onClick={event => activateLink(event.nativeEvent)}\n onAuxClick={event => { if (event.button === 1) activateLink(event.nativeEvent); }}>{command.label}</a>}\n {retryable(operation) && control('retry', labels.retry, () => bridge.retryOperation(lease, handle, operation.token), { className: neutral })}\n {operation?.canCancel && control('cancel', operation.cancelRequested ? labels.cancellationRequested : labels.cancel, () => {\n if (!operation.cancelRequested) bridge.cancelOperation(lease, handle, operation.token);\n }, { className: neutral, 'aria-disabled': operation.cancelRequested })}\n </div>\n {action.status === 'failed' && <p id={`${id}-action-error`} className=\"cloudlet-action-error\">{action.message}</p>}\n </div>;\n}\n\nexport function closeButton(labels: CloudletLabels, part: PartClass, onClick: () => void) {\n return control('close', glyph('m4.5 4.5 7 7m0-7-7 7'), onClick, { 'aria-label': labels.close, className: part('close', 'cloudlet-close') });\n}\n"],"mappings":";;;AAQA,IAAaA,IAAgC;CAC3C,QAAQ;CAAiB,QAAQ;CAAyB,UAAU;CAAY,OAAO;CACvF,OAAO;CAAsB,OAAO;CACpC,QAAQ;CAAwB,uBAAuB;CACvD,qBAAqB;CAAoC,UAAU;CACnE,eAAe,GAAO,GAAO,MAAW;EAACC;EAAO,GAAIC,IAAQ,IAAI,CAAC,GAAGA,EAAM,eAAe,IAAI,CAAC;EAC5F,GAAIC,IAAS,IAAI,CAAC,GAAGA,EAAO,QAAQ,IAAI,CAAC;CAAE,CAAC,CAAC,KAAK,IAAI;CACxD,OAAO,GAAO,MAAU,GAAGC,EAAM,MAAMC;CACvC,gBAAe,MAAS,GAAGH,EAAM;AACnC,GAUMI,IAAN,cAA2BC,EAA8D;CACvF,QAAiB;EAAE,QAAQ;EAAO,SAAS,KAAK,MAAM;CAAQ;CAC9D,OAAO,2BAA2B;EAAE,OAAO,EAAE,QAAQ,GAAK;CAAG;CAC7D,OAAO,yBAAyB,GAAkB,GAA+B;EAC/E,OAAOC,EAAM,YAAYC,EAAM,UAAU,OAAO;GAAE,QAAQ;GAAO,SAASD,EAAM;EAAQ;CAC1F;CACA,kBAA2B,GAAgB;EACzC,KAAK,MAAM,OAAO,iBAAiB,KAAK,MAAM,OAAO;GAAE,MAAM;GAAc,QAAQ;GACjF,SAAS;GAAqC,QAAQ,KAAK,MAAM;GAAQ;EAAM,CAAC;CACpF;CACA,SAAkB;EAChB,OAAO,KAAK,MAAM,SAAS,KAAK,MAAM,OAAO,cACzC,kBAACE,GAAD;GAAU,UAAU,KAAK,MAAM,OAAO;GAAa,UAAA,kBAACC,GAAD,EAAa,GAAI,KAAK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ACzH,AAAKL,EAAU,mBAAiB/B,EAAO,gBAAgBC,GAAOG,GAAQ2B,EAAU,KAAK;KACvF,GAAG;MAAE,WAAWO;MAAS,iBAAiBP,EAAU;KAAgB,CAAC;IAClE;;GACJE,EAAO,WAAW,YAAY,kBAAC,KAAD;IAAG,IAAI,GAAGM,EAAG;IAAgB,WAAU;IAAyB,UAAAN,EAAO;GAAW,CAAA;EAC9G;;AACP;AAEA,SAAgBW,EAAY,GAAwB,GAAiB,GAAqB;CACxF,OAAOrC,EAAQ,SAASE,EAAM,sBAAsB,GAAGoC,GAAS;EAAE,cAAcT,EAAO;EAAO,WAAWtB,EAAK,SAAS,gBAAgB;CAAE,CAAC;AAC5I"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Numeric animation generators for the shell sampler (motion.ts), ported from Motion 14.3.0
3
+ * so that every frame matches what the owner accepted on the laboratory (D47):
4
+ *
5
+ * - `spring` is the numeric part of motion-dom/dist/es/animation/generators/spring.mjs
6
+ * (physics-defined and duration/bounce-defined springs, `findSpring`, analytical velocity,
7
+ * granular rest thresholds, the overdamped settle limit);
8
+ * - `tween` is the two-keyframe fast path of motion-dom's `keyframes` generator for numbers,
9
+ * with `easeOut` = `cubicBezier(0, 0, 0.58, 1)` from motion-utils 14.1.1.
10
+ *
11
+ * Motion is Copyright (c) 2024 Motion B.V., MIT (packages/cloudlet/THIRD_PARTY_NOTICES.md).
12
+ * Colour/string mixing, keyframe arrays and the rest of Motion are not needed here: Cloudlet
13
+ * animates numbers only. tests/unit/generators-reference.test.ts samples both implementations
14
+ * every millisecond against the installed Motion 14.3.0 (|Δ| < 1e-9, same `done` frame).
15
+ * Expressions keep Motion's operation order on purpose: a re-association changes the last bits.
16
+ */
17
+ export interface GeneratorState {
18
+ value: number;
19
+ done: boolean;
20
+ }
21
+ export interface Generator {
22
+ /** `t` in generator milliseconds. Returns a mutable state object, like Motion's iterator. */
23
+ readonly next: (t: number) => GeneratorState;
24
+ /** Analytical derivative in units per second; tweens have none (a following spring starts at rest). */
25
+ readonly velocity?: (t: number) => number;
26
+ }
27
+ export interface SpringOptions {
28
+ readonly from: number;
29
+ readonly to: number;
30
+ /** Units per second; ignored by duration/bounce springs, as in Motion. */
31
+ readonly velocity?: number | undefined;
32
+ readonly stiffness?: number | undefined;
33
+ readonly damping?: number | undefined;
34
+ readonly mass?: number | undefined;
35
+ readonly duration?: number | undefined;
36
+ readonly bounce?: number | undefined;
37
+ }
38
+ /** `keyframes({ keyframes: [from, to], duration, ease: 'easeOut' })` for numbers. */
39
+ export declare function tween(from: number, to: number, duration: number): Generator;
40
+ /**
41
+ * `spring({ keyframes: [from, to], velocity, stiffness, damping, mass })` or
42
+ * `spring({ keyframes: [from, to], duration, bounce })`. Physics, when valid, wins over
43
+ * duration/bounce; a duration/bounce spring that fails to resolve falls back to Motion's defaults.
44
+ */
45
+ export declare function spring(options: SpringOptions): Generator;
46
+ //# sourceMappingURL=generators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../src/react/generators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,WAAW,cAAc;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE;AAChE,MAAM,WAAW,SAAS;IACxB,6FAA6F;IAC7F,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,cAAc,CAAC;IAC7C,uGAAuG;IACvG,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAiCD,qFAAqF;AACrF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAU3E;AAgGD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,CA6FxD"}
@@ -0,0 +1,115 @@
1
+ //#region src/react/generators.ts
2
+ var e = (e, t, n) => n > t ? t : n < e ? e : n, t = (e) => e / 1e3, n = (e) => e * 1e3, r = (e, t, n) => e * (3 * (1 - e) * ((1 - e) * t + e * n) + e * e);
3
+ function i(e, t, n, i) {
4
+ return e === t && n === i ? (e) => e : (a) => {
5
+ let o = 0, s = 1, c = a;
6
+ for (let t = 0;; t++) {
7
+ c >= o && c <= s || (c = (o + s) / 2);
8
+ let i = r(c, e, n) - a;
9
+ if (i * i < 1e-28 || t === 40) break;
10
+ i > 0 ? s = c : o = c, c -= i * 1e-7 / (r(c + 1e-7, e, n) - a - i);
11
+ }
12
+ return r(c, t, i);
13
+ };
14
+ }
15
+ var a = i(0, 0, .58, 1);
16
+ function o(t, n, r) {
17
+ let i = {
18
+ done: !1,
19
+ value: t
20
+ }, o = t !== n;
21
+ return { next: (s) => (i.value = o ? t + (n - t) * a(r > 0 ? e(0, 1, s / r) : 1) : n, i.done = s >= r, i) };
22
+ }
23
+ var s = {
24
+ stiffness: 100,
25
+ damping: 10,
26
+ mass: 1,
27
+ duration: 800,
28
+ bounce: .3,
29
+ restSpeed: {
30
+ granular: .01,
31
+ default: 2
32
+ },
33
+ restDelta: {
34
+ granular: .005,
35
+ default: .5
36
+ },
37
+ minDuration: .01,
38
+ maxDuration: 10,
39
+ minDamping: .05
40
+ }, c = (e) => e < 0 ? 1 / Math.max(1 + e, s.minDamping) : Math.max(1 - e, s.minDamping), l = 12;
41
+ function u(e, t, n) {
42
+ let r = n;
43
+ for (let n = 1; n < l; n++) r -= e(r) / t(r);
44
+ return r;
45
+ }
46
+ function d(e, t) {
47
+ if (!(e > 1)) return 1;
48
+ let n = Math.sqrt(e * e - 1), r = e - n, i = e + n, a = 2 * n * Math.exp(-t) * (1 + t);
49
+ return u((e) => i * Math.exp(-r * e) - r * Math.exp(-i * e) - a, (e) => Math.exp(-i * e) - Math.exp(-r * e), t) / t;
50
+ }
51
+ function f(e, t) {
52
+ return e * Math.sqrt(1 - t * t);
53
+ }
54
+ var p = .001;
55
+ function m(r, i) {
56
+ let a, o, l = c(i);
57
+ r = e(s.minDuration, s.maxDuration, t(r)), l < 1 ? (a = (e) => {
58
+ let t = e * l, n = t * r, i = f(e, l), a = Math.exp(-n);
59
+ return p - t / i * a;
60
+ }, o = (e) => {
61
+ let t = e * l * r, n = l * l * e * e * r, i = Math.exp(-t), o = f(e * e, l);
62
+ return (-a(e) + p > 0 ? -1 : 1) * -n * i / o;
63
+ }) : (a = (e) => -.001 + Math.exp(-e * r) * (e * r + 1), o = (e) => Math.exp(-e * r) * (-e * (r * r)));
64
+ let m = 5 / r, h = u(a, o, m), g = h * d(l, h * r), _ = g * g;
65
+ return {
66
+ stiffness: _,
67
+ damping: l * 2 * Math.sqrt(_),
68
+ duration: n(r)
69
+ };
70
+ }
71
+ var h = (e, t = !1) => (t ? e >= 0 : e > 0) && e < Infinity;
72
+ function g(e) {
73
+ let r = e.from, i = e.to, a = {
74
+ done: !1,
75
+ value: r
76
+ }, o = h(e.stiffness) ? e.stiffness : void 0, c = h(e.damping, !0) ? e.damping : void 0, l = h(e.mass) ? e.mass : void 0, u = o ?? s.stiffness, d = c ?? s.damping, p = l ?? s.mass, g = 0, _ = !1, v = (o ?? c ?? l) === void 0 && (e.duration !== void 0 || e.bounce !== void 0);
77
+ if (v) {
78
+ let t = m(e.duration ?? s.duration, e.bounce ?? s.bounce);
79
+ u = t.stiffness, d = t.damping, g = t.duration, _ = !0, (!h(u) || !h(d, !0)) && (u = s.stiffness, d = s.damping);
80
+ }
81
+ let y = (e) => v ? 0 : -t(e), b = d / (2 * Math.sqrt(u * p)), x = t(Math.sqrt(u / p)), S = b * x, C = i - r, w = y(e.velocity || 0) || 0, T = Math.abs(C) < 5, E = T ? s.restSpeed.granular : s.restSpeed.default, D = T ? s.restDelta.granular : s.restDelta.default, O, k;
82
+ if (b < 1) {
83
+ let e = f(x, b), t = (w + S * C) / e, n = S * t + C * e, r = S * C - t * e, a = {
84
+ t: -1,
85
+ env: 0,
86
+ sin: 0,
87
+ cos: 0
88
+ }, o = (t) => {
89
+ t !== a.t && (a.t = t, a.env = Math.exp(-S * t), a.sin = Math.sin(e * t), a.cos = Math.cos(e * t));
90
+ };
91
+ O = (e) => (o(e), i - a.env * (t * a.sin + C * a.cos)), k = (e) => (o(e), a.env * (n * a.sin + r * a.cos));
92
+ } else if (b === 1) {
93
+ let e = w + x * C;
94
+ O = (e) => i - Math.exp(-x * e) * (C + (w + x * C) * e), k = (t) => Math.exp(-x * t) * (x * e * t - w);
95
+ } else {
96
+ let e = x * Math.sqrt(b * b - 1), t = S - e, n = S + e, r = v ? Infinity : 300 / e, a = (e, t) => Math.exp(t > r ? -e * r - S * (t - r) : -e * t), o = (w + S * C) / e, s = (C + o) / 2, c = (C - o) / 2;
97
+ O = (e) => i - s * a(t, e) - c * a(n, e), k = (e) => t * s * a(t, e) + n * c * a(n, e);
98
+ }
99
+ return {
100
+ velocity: (e) => n(k(e)),
101
+ next: (e) => {
102
+ let t = O(e);
103
+ if (_) a.done = e >= g;
104
+ else {
105
+ let r = n(k(e));
106
+ a.done = Math.abs(r) <= E && Math.abs(i - t) <= D;
107
+ }
108
+ return a.value = a.done ? i : t, a;
109
+ }
110
+ };
111
+ }
112
+ //#endregion
113
+ export { g as spring, o as tween };
114
+
115
+ //# sourceMappingURL=generators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators.js","names":["clamp","v","max","min","millisecondsToSeconds","milliseconds","secondsToMilliseconds","seconds","calcBezier","t","a1","a2","cubicBezier","mX1","mY1","mX2","mY2","x","lowerBound","upperBound","i","currentX","easeOut","tween","state","from","mixes","to","duration","springDefaults","bounceToDampingRatio","bounce","rootIterations","approximateRoot","result","initialGuess","envelope","derivative","overdampedFreqScale","dampingRatio","root","slow","fast","target","criticalFreqTime","freqTime","calcAngularFreq","undampedFreq","safeMin","findSpring","exponentialDecay","delta","b","c","e","f","g","criticalFreq","stiffness","isValidPhysics","canBeZero","value","spring","origin","options","validStiffness","validDamping","validMass","damping","mass","isResolvedFromDuration","isTimeDefined","resolved","inheritVelocity","velocity","undampedAngularFreq","decay","isGranularScale","restSpeed","restDelta","resolveSpring","resolveVelocity","angularFreq","A","sinC","cosC","sample","C","dampedAngularFreq","limit","decayAt","rate","P","S","F","current","currentVelocity"],"sources":["../../src/react/generators.ts"],"sourcesContent":["/**\n * Numeric animation generators for the shell sampler (motion.ts), ported from Motion 14.3.0\n * so that every frame matches what the owner accepted on the laboratory (D47):\n *\n * - `spring` is the numeric part of motion-dom/dist/es/animation/generators/spring.mjs\n * (physics-defined and duration/bounce-defined springs, `findSpring`, analytical velocity,\n * granular rest thresholds, the overdamped settle limit);\n * - `tween` is the two-keyframe fast path of motion-dom's `keyframes` generator for numbers,\n * with `easeOut` = `cubicBezier(0, 0, 0.58, 1)` from motion-utils 14.1.1.\n *\n * Motion is Copyright (c) 2024 Motion B.V., MIT (packages/cloudlet/THIRD_PARTY_NOTICES.md).\n * Colour/string mixing, keyframe arrays and the rest of Motion are not needed here: Cloudlet\n * animates numbers only. tests/unit/generators-reference.test.ts samples both implementations\n * every millisecond against the installed Motion 14.3.0 (|Δ| < 1e-9, same `done` frame).\n * Expressions keep Motion's operation order on purpose: a re-association changes the last bits.\n */\n\nexport interface GeneratorState { value: number; done: boolean }\nexport interface Generator {\n /** `t` in generator milliseconds. Returns a mutable state object, like Motion's iterator. */\n readonly next: (t: number) => GeneratorState;\n /** Analytical derivative in units per second; tweens have none (a following spring starts at rest). */\n readonly velocity?: (t: number) => number;\n}\n\nexport interface SpringOptions {\n readonly from: number;\n readonly to: number;\n /** Units per second; ignored by duration/bounce springs, as in Motion. */\n readonly velocity?: number | undefined;\n readonly stiffness?: number | undefined;\n readonly damping?: number | undefined;\n readonly mass?: number | undefined;\n readonly duration?: number | undefined;\n readonly bounce?: number | undefined;\n}\n\nconst clamp = (min: number, max: number, v: number) => (v > max ? max : v < min ? min : v);\nconst millisecondsToSeconds = (milliseconds: number) => milliseconds / 1000;\nconst secondsToMilliseconds = (seconds: number) => seconds * 1000;\n\n/* ------------------------------------------------------------------------------------------ */\n/* motion-utils/dist/es/easing/cubic-bezier.mjs (modified from Gaëtan Renaudeau's BezierEasing) */\n\nconst calcBezier = (t: number, a1: number, a2: number) => t * (3 * (1 - t) * ((1 - t) * a1 + t * a2) + t * t);\nfunction cubicBezier(mX1: number, mY1: number, mX2: number, mY2: number): (x: number) => number {\n if (mX1 === mY1 && mX2 === mY2) return (x) => x;\n return (x) => {\n let lowerBound = 0;\n let upperBound = 1;\n let t = x;\n for (let i = 0; ; i++) {\n // Outside the bracket (x out of range or a Newton overshoot on a flat part): bisect.\n if (!(t >= lowerBound && t <= upperBound)) t = (lowerBound + upperBound) / 2;\n const currentX = calcBezier(t, mX1, mX2) - x;\n if (currentX * currentX < 1e-28 || i === 40) break;\n currentX > 0 ? (upperBound = t) : (lowerBound = t);\n // Newton-Raphson step, dx/dt from a forward difference.\n t -= (currentX * 1e-7) / (calcBezier(t + 1e-7, mX1, mX2) - x - currentX);\n }\n return calcBezier(t, mY1, mY2);\n };\n}\nconst easeOut = cubicBezier(0, 0, 0.58, 1);\n\n/* ------------------------------------------------------------------------------------------ */\n/* motion-dom/dist/es/animation/generators/keyframes.mjs: two numeric keyframes, one easing */\n\n/** `keyframes({ keyframes: [from, to], duration, ease: 'easeOut' })` for numbers. */\nexport function tween(from: number, to: number, duration: number): Generator {\n const state: GeneratorState = { done: false, value: from };\n const mixes = from !== to;\n return {\n next: (t) => {\n state.value = mixes ? from + (to - from) * easeOut(duration > 0 ? clamp(0, 1, t / duration) : 1) : to;\n state.done = t >= duration;\n return state;\n },\n };\n}\n\n/* ------------------------------------------------------------------------------------------ */\n/* motion-dom/dist/es/animation/generators/spring.mjs */\n\nconst springDefaults = {\n stiffness: 100,\n damping: 10,\n mass: 1.0,\n duration: 800,\n bounce: 0.3,\n restSpeed: { granular: 0.01, default: 2 },\n restDelta: { granular: 0.005, default: 0.5 },\n minDuration: 0.01,\n maxDuration: 10.0,\n minDamping: 0.05,\n};\n\n/** Bounce → damping ratio as SwiftUI does: 0 critically damped, towards 1 undamped, towards −1 overdamped. */\nconst bounceToDampingRatio = (bounce: number) => bounce < 0\n ? 1 / Math.max(1 + bounce, springDefaults.minDamping)\n : Math.max(1 - bounce, springDefaults.minDamping);\n\nconst rootIterations = 12;\nfunction approximateRoot(envelope: (v: number) => number, derivative: (v: number) => number, initialGuess: number) {\n let result = initialGuess;\n for (let i = 1; i < rootIterations; i++) result = result - envelope(result) / derivative(result);\n return result;\n}\n\n/** Scales an overdamped spring's undamped frequency so a negative bounce changes the shape, not the arrival. */\nfunction overdampedFreqScale(dampingRatio: number, criticalFreqTime: number) {\n if (!(dampingRatio > 1)) return 1;\n const root = Math.sqrt(dampingRatio * dampingRatio - 1);\n const slow = dampingRatio - root;\n const fast = dampingRatio + root;\n const target = 2 * root * Math.exp(-criticalFreqTime) * (1 + criticalFreqTime);\n return approximateRoot(\n (freqTime) => fast * Math.exp(-slow * freqTime) - slow * Math.exp(-fast * freqTime) - target,\n (freqTime) => Math.exp(-fast * freqTime) - Math.exp(-slow * freqTime),\n criticalFreqTime,\n ) / criticalFreqTime;\n}\n\nfunction calcAngularFreq(undampedFreq: number, dampingRatio: number) {\n return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);\n}\n\nconst safeMin = 0.001;\n/** Duration/bounce → stiffness/damping (zero initial velocity, default mass), by Newton's method. */\nfunction findSpring(duration: number, bounce: number) {\n let envelope: (undampedFreq: number) => number;\n let derivative: (undampedFreq: number) => number;\n const dampingRatio = bounceToDampingRatio(bounce);\n duration = clamp(springDefaults.minDuration, springDefaults.maxDuration, millisecondsToSeconds(duration));\n if (dampingRatio < 1) {\n envelope = (undampedFreq) => {\n const exponentialDecay = undampedFreq * dampingRatio;\n const delta = exponentialDecay * duration;\n const b = calcAngularFreq(undampedFreq, dampingRatio);\n const c = Math.exp(-delta);\n return safeMin - (exponentialDecay / b) * c;\n };\n derivative = (undampedFreq) => {\n const exponentialDecay = undampedFreq * dampingRatio;\n const delta = exponentialDecay * duration;\n const e = dampingRatio * dampingRatio * undampedFreq * undampedFreq * duration;\n const f = Math.exp(-delta);\n const g = calcAngularFreq(undampedFreq * undampedFreq, dampingRatio);\n const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1;\n return (factor * -e * f) / g;\n };\n } else {\n // Critically damped; overdamped springs reuse this root, scaled below.\n envelope = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration);\n const b = undampedFreq * duration + 1;\n return -safeMin + a * b;\n };\n derivative = (undampedFreq) => {\n const a = Math.exp(-undampedFreq * duration);\n const b = -undampedFreq * (duration * duration);\n return a * b;\n };\n }\n const initialGuess = 5 / duration;\n const criticalFreq = approximateRoot(envelope, derivative, initialGuess);\n const undampedFreq = criticalFreq * overdampedFreqScale(dampingRatio, criticalFreq * duration);\n const stiffness = undampedFreq * undampedFreq;\n return { stiffness, damping: dampingRatio * 2 * Math.sqrt(stiffness), duration: secondsToMilliseconds(duration) };\n}\n\n/** Stiffness and mass are divisors (positive); damping 0 is a valid perpetual oscillation. */\nconst isValidPhysics = (value: number | undefined, canBeZero = false): value is number =>\n (canBeZero ? (value as number) >= 0 : (value as number) > 0) && (value as number) < Infinity;\n\n/**\n * `spring({ keyframes: [from, to], velocity, stiffness, damping, mass })` or\n * `spring({ keyframes: [from, to], duration, bounce })`. Physics, when valid, wins over\n * duration/bounce; a duration/bounce spring that fails to resolve falls back to Motion's defaults.\n */\nexport function spring(options: SpringOptions): Generator {\n const origin = options.from;\n const target = options.to;\n const state: GeneratorState = { done: false, value: origin };\n\n const validStiffness = isValidPhysics(options.stiffness) ? options.stiffness : undefined;\n const validDamping = isValidPhysics(options.damping, true) ? options.damping : undefined;\n const validMass = isValidPhysics(options.mass) ? options.mass : undefined;\n let stiffness = validStiffness ?? springDefaults.stiffness;\n let damping = validDamping ?? springDefaults.damping;\n const mass = validMass ?? springDefaults.mass;\n let duration = 0;\n let isResolvedFromDuration = false;\n const isTimeDefined = (validStiffness ?? validDamping ?? validMass) === undefined\n && (options.duration !== undefined || options.bounce !== undefined);\n if (isTimeDefined) {\n const resolved = findSpring(options.duration ?? springDefaults.duration, options.bounce ?? springDefaults.bounce);\n stiffness = resolved.stiffness;\n damping = resolved.damping;\n duration = resolved.duration;\n isResolvedFromDuration = true;\n // Degenerate time options (NaN bounce, no convergence): replace the pair together.\n if (!isValidPhysics(stiffness) || !isValidPhysics(damping, true)) {\n stiffness = springDefaults.stiffness;\n damping = springDefaults.damping;\n }\n }\n\n // Time-defined springs ignore inherited velocity (it would oscillate small ranges heavily).\n const inheritVelocity = (velocity: number) => (isTimeDefined ? 0 : -millisecondsToSeconds(velocity));\n const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));\n const undampedAngularFreq = millisecondsToSeconds(Math.sqrt(stiffness / mass));\n const decay = dampingRatio * undampedAngularFreq;\n const delta = target - origin;\n const velocity = inheritVelocity(options.velocity || 0) || 0;\n const isGranularScale = Math.abs(delta) < 5;\n const restSpeed = isGranularScale ? springDefaults.restSpeed.granular : springDefaults.restSpeed.default;\n const restDelta = isGranularScale ? springDefaults.restDelta.granular : springDefaults.restDelta.default;\n\n let resolveSpring: (t: number) => number;\n let resolveVelocity: (t: number) => number;\n if (dampingRatio < 1) {\n // Underdamped. exp/sin/cos depend only on t: memoised per t, as in Motion.\n const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);\n const A = (velocity + decay * delta) / angularFreq;\n const sinC = decay * A + delta * angularFreq;\n const cosC = decay * delta - A * angularFreq;\n const c = { t: -1, env: 0, sin: 0, cos: 0 };\n const sample = (t: number) => {\n if (t !== c.t) {\n c.t = t;\n c.env = Math.exp(-decay * t);\n c.sin = Math.sin(angularFreq * t);\n c.cos = Math.cos(angularFreq * t);\n }\n };\n resolveSpring = (t) => { sample(t); return target - c.env * (A * c.sin + delta * c.cos); };\n resolveVelocity = (t) => { sample(t); return c.env * (sinC * c.sin + cosC * c.cos); };\n } else if (dampingRatio === 1) {\n // Critically damped.\n const C = velocity + undampedAngularFreq * delta;\n resolveSpring = (t) => target - Math.exp(-undampedAngularFreq * t) * (delta + (velocity + undampedAngularFreq * delta) * t);\n resolveVelocity = (t) => Math.exp(-undampedAngularFreq * t) * (undampedAngularFreq * C * t - velocity);\n } else {\n // Overdamped: a slow and a fast decaying exponential, so no term overflows.\n const dampedAngularFreq = undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1);\n const slow = decay - dampedAngularFreq;\n const fast = decay + dampedAngularFreq;\n // Physics-defined springs settle at the damping rate once dampedAngularFreq·t passes 300;\n // time-defined (negative bounce) springs keep the exact curve.\n const limit = isTimeDefined ? Infinity : 300 / dampedAngularFreq;\n const decayAt = (rate: number, t: number) => Math.exp(t > limit ? -rate * limit - decay * (t - limit) : -rate * t);\n const P = (velocity + decay * delta) / dampedAngularFreq;\n const S = (delta + P) / 2;\n const F = (delta - P) / 2;\n resolveSpring = (t) => target - S * decayAt(slow, t) - F * decayAt(fast, t);\n resolveVelocity = (t) => slow * S * decayAt(slow, t) + fast * F * decayAt(fast, t);\n }\n\n return {\n velocity: (t) => secondsToMilliseconds(resolveVelocity(t)),\n next: (t) => {\n const current = resolveSpring(t);\n if (!isResolvedFromDuration) {\n const currentVelocity = secondsToMilliseconds(resolveVelocity(t));\n state.done = Math.abs(currentVelocity) <= restSpeed && Math.abs(target - current) <= restDelta;\n } else {\n state.done = t >= duration;\n }\n state.value = state.done ? target : current;\n return state;\n },\n };\n}\n"],"mappings":";AAqCA,IAAMA,KAAS,GAAa,GAAa,MAAeC,IAAIC,IAAMA,IAAMD,IAAIE,IAAMA,IAAMF,GAClFG,KAAyB,MAAyBC,IAAe,KACjEC,KAAyB,MAAoBC,IAAU,KAKvDC,KAAc,GAAW,GAAY,MAAeC,KAAK,KAAK,IAAIA,OAAO,IAAIA,KAAKC,IAAKD,IAAIE,KAAMF,IAAIA;AAC3G,SAASG,EAAY,GAAa,GAAa,GAAa,GAAoC;CAE9F,OADIC,MAAQC,KAAOC,MAAQC,KAAa,MAAMC,KACtC,MAAM;EACZ,IAAIC,IAAa,GACbC,IAAa,GACbV,IAAIQ;EACR,KAAK,IAAIG,IAAI,IAAK,KAAK;GAErB,AAAMX,KAAKS,KAAcT,KAAKU,MAAa,KAAKD,IAAaC,KAAc;GAC3E,IAAME,IAAWb,EAAWC,GAAGI,GAAKE,CAAG,IAAIE;GAC3C,IAAII,IAAWA,IAAW,SAASD,MAAM,IAAI;GAG7C,AAFAC,IAAW,IAAK,IAAaZ,IAAM,IAAaA,GAEhD,KAAMY,IAAW,QAASb,EAAWC,IAAI,MAAMI,GAAKE,CAAG,IAAIE,IAAII;EACjE;EACA,OAAOb,EAAWC,GAAGK,GAAKE,CAAG;CAC/B;AACF;AACA,IAAMM,IAAUV,EAAY,GAAG,GAAG,KAAM,CAAC;AAMzC,SAAgBW,EAAM,GAAc,GAAY,GAA6B;CAC3E,IAAMC,IAAwB;EAAE,MAAM;EAAO,OAAOC;CAAK,GACnDC,IAAQD,MAASE;CACvB,OAAO,EACL,OAAO,OACL,EAAM,QAAQD,IAAQD,KAAQE,IAAKF,KAAQH,EAAQM,IAAW,IAAI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kD,IAAIH,EAAQjD,GAAMhC,CAAC,IAAIqF,IAAIJ,EAAQhD,GAAMjC,CAAC,GAC1E,KAAmB,MAAMgC,IAAOoD,IAAIH,EAAQjD,GAAMhC,CAAC,IAAIiC,IAAOoD,IAAIJ,EAAQhD,GAAMjC,CAAC;CACnF;CAEA,OAAO;EACL,WAAW,MAAMH,EAAsB2E,EAAgBxE,CAAC,CAAC;EACzD,OAAO,MAAM;GACX,IAAMsF,IAAUf,EAAcvE,CAAC;GAC/B,IAAK6D,GAIH,EAAM,OAAO7D,KAAKmB;QAJS;IAC3B,IAAMoE,IAAkB1F,EAAsB2E,EAAgBxE,CAAC,CAAC;IAChE,EAAM,OAAO,KAAK,IAAIuF,CAAe,KAAKlB,KAAa,KAAK,IAAInC,IAASoD,CAAO,KAAKhB;GACvF;GAIA,OADA,EAAM,QAAQvD,EAAM,OAAOmB,IAASoD,GAC7BvE;EACT;CACF;AACF"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Edge resistance (iOS-style rubber band): the result approaches `dimension`
3
+ * asymptotically and keeps the sign of the raw finger travel.
4
+ */
5
+ export declare function rubberBand(offset: number, dimension: number, coefficient?: number): number;
6
+ /**
7
+ * Release decision along one axis. Returns the sign of the travel when the swipe
8
+ * commits that way (distance past `MOTION.swipe.distance` of `dimension`, or a flick of
9
+ * at least `minDistance` px faster than `velocity` px/ms), 0 when it springs back.
10
+ * A direction without a destination never commits; a flick back always cancels.
11
+ */
12
+ export declare function decideRelease(offset: number, velocity: number, dimension: number, allowed: {
13
+ readonly negative: boolean;
14
+ readonly positive: boolean;
15
+ }): -1 | 0 | 1;
16
+ export type SwipeAxis = 'x' | 'y';
17
+ /** A started swipe along one axis. Offsets are raw finger travel in CSS px. */
18
+ export interface SwipeSession {
19
+ readonly move: (offset: number) => void;
20
+ /** Velocity is CSS px/ms along the axis, positive in the direction of positive offsets. */
21
+ readonly end: (offset: number, velocity: number) => void;
22
+ /** Lost capture, a second pointer, orientation change or an external cancel. */
23
+ readonly cancel: () => void;
24
+ }
25
+ /** What may start from one pointerdown or wheel stream; `release` ends the intent window. */
26
+ export interface SwipeCandidate {
27
+ readonly x: boolean;
28
+ readonly y: boolean;
29
+ readonly start: (axis: SwipeAxis) => SwipeSession | null;
30
+ readonly release: () => void;
31
+ }
32
+ interface SwipeOptions {
33
+ /** Null ignores the input; the candidate is released exactly once. */
34
+ readonly begin: (target: Element, input: 'pointer' | 'wheel') => SwipeCandidate | null;
35
+ readonly now: () => number;
36
+ }
37
+ /**
38
+ * Pointer and trackpad ownership for one host. The axis is decided by the first
39
+ * `MOTION.swipe.intent` px; an axis the target does not own is given back to the
40
+ * browser (native scroll) for the rest of the gesture. Buttons and links never start
41
+ * a swipe, except the collapsed pill, which is itself the swipe surface. Layout,
42
+ * physics and store commands stay with the caller.
43
+ */
44
+ export declare function createSwipe(root: HTMLElement, options: SwipeOptions): {
45
+ cancel(): void;
46
+ dispose(): void;
47
+ readonly active: boolean;
48
+ };
49
+ export {};
50
+ //# sourceMappingURL=gestures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gestures.d.ts","sourceRoot":"","sources":["../../src/react/gestures.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,MAAyB,GAAG,MAAM,CAI5G;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAC/E,OAAO,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAQjF;AAED,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,CAAC;AAElC,+EAA+E;AAC/E,MAAM,WAAW,YAAY;IAC3B,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