@krak-stack/registry 0.10.4 → 0.10.6

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 (31) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/components/ui/animated-list.d.ts +6 -7
  3. package/dist/components/ui/animated-list.js +329 -139
  4. package/dist/components/ui/animated-number.js +47 -24
  5. package/dist/components/ui/auto-height.js +56 -15
  6. package/dist/components/ui/data-table.js +16 -13
  7. package/dist/components/ui/email-editor.d.ts +124 -0
  8. package/dist/components/ui/email-editor.js +2651 -0
  9. package/dist/components/ui/form.d.ts +5 -5
  10. package/dist/components/ui/presence-transition.d.ts +1 -1
  11. package/dist/components/ui/presence-transition.js +79 -26
  12. package/dist/components/ui/rich-text-editor.d.ts +70 -0
  13. package/dist/components/ui/rich-text-editor.js +1135 -0
  14. package/dist/components/ui/time-picker.d.ts +13 -4
  15. package/dist/components/ui/time-picker.js +141 -47
  16. package/dist/components/ui/time-picker.schema.d.ts +16 -2
  17. package/dist/lib/email-document/model.d.ts +26 -0
  18. package/dist/lib/email-document/model.js +253 -0
  19. package/dist/lib/email-document/render.d.ts +115 -0
  20. package/dist/lib/email-document/render.js +469 -0
  21. package/dist/lib/email-document/schema.d.ts +285 -0
  22. package/dist/lib/email-document/schema.js +139 -0
  23. package/dist/lib/krakmotion.d.ts +27 -0
  24. package/dist/lib/rich-text/dom.d.ts +40 -0
  25. package/dist/lib/rich-text/model.d.ts +19 -0
  26. package/dist/lib/rich-text/model.js +141 -0
  27. package/dist/lib/rich-text/schema.d.ts +64 -0
  28. package/dist/lib/rich-text/schema.js +53 -0
  29. package/dist/services/events/client/audit-log-table.js +16 -13
  30. package/dist/services/webhooks/client/delivery-table.js +16 -13
  31. package/package.json +29 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @krak-stack/registry
2
2
 
3
+ ## 0.10.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 7419de4: Use styled Select controls for email editor fonts, alignment, button destinations and code variables.
8
+ - e9a5d41: Add native rich-text and email editors with inline formatting, variable chips, accessible element reordering and host-owned preview integration. Add versioned Effect document schemas, variable validation and shared HTML/plain-text email rendering without an external editor or drag library.
9
+ - 5fbc467: Replace Motion in AnimatedList, PresenceTransition, AutoHeight and AnimatedNumber with shared native KrakMotion internals. Preserve controlled reordering, keyboard access, keyed child state and reduced-motion support without an external animation dependency.
10
+ - f551df9: Add opt-in second and millisecond precision to TimePicker, including typed entry, scrolling columns, inclusive bounds, and localized validation. Existing minute precision and minute-only helpers remain unchanged.
11
+ - 211fe58: Use styled Select and DropdownMenu controls in the rich-text toolbar, preserving editor selection and focus for block formatting and variable insertion.
12
+
13
+ Keep link removal alongside link editing rather than as a separate toolbar button.
14
+
15
+ - 5b03f18: Fix native reordering for variable-height items so tall elements can reach either end of a bounded list.
16
+
17
+ ## 0.10.5
18
+
19
+ ### Patch Changes
20
+
21
+ - Place gallery tags below the card name, before the description. Keep selection and drag controls above the name.
22
+
3
23
  ## 0.10.4
4
24
 
5
25
  ### Patch Changes
@@ -8,15 +8,14 @@ export type AnimatedListProps<T> = {
8
8
  itemClassName?: string;
9
9
  label?: string;
10
10
  onReorder?: (items: T[]) => void;
11
- dragOverflow?: number;
12
11
  getItemLabel?: (item: T) => string;
12
+ dragOverflow?: number;
13
13
  locale?: string;
14
- messages?: Partial<Record<string, Partial<AnimatedListMessages>>>;
15
- };
16
- export type AnimatedListMessages = {
17
- reorder: string;
18
- instructions: string;
19
- position: (label: string, position: number, total: number) => string;
14
+ messages?: Record<string, Partial<{
15
+ reorder: string;
16
+ instructions: string;
17
+ position: (label: string, position: number, total: number) => string;
18
+ }>>;
20
19
  };
21
20
  /** Stable entity keys preserve child state across inserts and reordering. */
22
21
  export declare const AnimatedList: <T>({ items, getKey, children, duration, className, itemClassName, label, onReorder, dragOverflow, getItemLabel, locale: override, messages, }: AnimatedListProps<T>) => import("react").JSX.Element;
@@ -1,18 +1,231 @@
1
1
  // ../../src/components/ui/animated-list.tsx
2
2
  import {
3
- AnimatePresence,
4
- Reorder,
5
- motion,
6
- useDragControls,
7
- useIsPresent,
8
- useReducedMotion
9
- } from "motion/react";
3
+ useEffect as useEffect2,
4
+ useEffectEvent as useEffectEvent2,
5
+ useId,
6
+ useRef as useRef2,
7
+ useState as useState2
8
+ } from "react";
10
9
  import { GripVertical } from "lucide-react";
11
- import { useId, useRef, useState } from "react";
10
+ import { cn } from "cn";
12
11
  import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
13
12
 
14
- // ../../src/lib/utils.ts
15
- import { cn } from "cn";
13
+ // ../../src/lib/krakmotion.ts
14
+ import {
15
+ useEffect,
16
+ useEffectEvent,
17
+ useLayoutEffect,
18
+ useRef,
19
+ useState,
20
+ useSyncExternalStore
21
+ } from "react";
22
+ var useBrowserLayoutEffect = globalThis.window ? useLayoutEffect : useEffect;
23
+ var reducedMotionQuery = "(prefers-reduced-motion: reduce)";
24
+ var subscribeReducedMotion = (notify) => {
25
+ const query = window.matchMedia?.(reducedMotionQuery);
26
+ query?.addEventListener("change", notify);
27
+ return () => query?.removeEventListener("change", notify);
28
+ };
29
+ var useReducedMotion = () => useSyncExternalStore(subscribeReducedMotion, () => window.matchMedia?.(reducedMotionQuery).matches ?? true, () => true);
30
+ var animateElement = (element, frames, duration, complete) => {
31
+ if (duration <= 0 || !element.animate) {
32
+ complete?.();
33
+ return () => {};
34
+ }
35
+ const animation = element.animate(frames, {
36
+ duration,
37
+ easing: "cubic-bezier(0.2, 0, 0, 1)"
38
+ });
39
+ animation.onfinish = () => complete?.();
40
+ return () => {
41
+ animation.onfinish = null;
42
+ animation.cancel();
43
+ };
44
+ };
45
+ var useKeyedPresence = (items, getKey) => {
46
+ const [previous, setPrevious] = useState(items);
47
+ const [retained, setRetained] = useState(items);
48
+ if (previous !== items) {
49
+ const keys = new Set(items.map(getKey));
50
+ const next = [...items];
51
+ retained.forEach((item, index) => {
52
+ if (!keys.has(getKey(item)))
53
+ next.splice(Math.min(index, next.length), 0, item);
54
+ });
55
+ setPrevious(items);
56
+ setRetained(next);
57
+ }
58
+ const present = new Set(items.map(getKey));
59
+ return {
60
+ items: retained,
61
+ present,
62
+ remove: (key) => setRetained((current) => current.filter((item) => getKey(item) !== key))
63
+ };
64
+ };
65
+ var useListLayout = (ref, duration) => {
66
+ const previous = useRef(new Map);
67
+ const animations = useRef(new Map);
68
+ const reduced = useReducedMotion();
69
+ useBrowserLayoutEffect(() => {
70
+ const next = new Map;
71
+ for (const element of ref.current?.children ?? []) {
72
+ if (!(element instanceof HTMLElement))
73
+ continue;
74
+ const key = element.dataset.motionKey;
75
+ if (!key)
76
+ continue;
77
+ const position = { top: element.offsetTop, left: element.offsetLeft };
78
+ next.set(key, position);
79
+ const old = previous.current.get(key);
80
+ if (old && (old.top !== position.top || old.left !== position.left)) {
81
+ const transform = getComputedStyle(element).transform;
82
+ const interrupted = transform === "none" ? null : new DOMMatrixReadOnly(transform);
83
+ animations.current.get(element)?.();
84
+ if (!element.hasAttribute("data-dragging")) {
85
+ animations.current.set(element, animateElement(element, [
86
+ {
87
+ transform: `translate(${old.left - position.left + (interrupted?.m41 ?? 0)}px, ${old.top - position.top + (interrupted?.m42 ?? 0)}px)`
88
+ },
89
+ { transform: "none" }
90
+ ], reduced ? 0 : Math.max(0, duration)));
91
+ }
92
+ }
93
+ }
94
+ for (const [element, cancel] of animations.current) {
95
+ if (!element.isConnected) {
96
+ cancel();
97
+ animations.current.delete(element);
98
+ }
99
+ }
100
+ previous.current = next;
101
+ });
102
+ useEffect(() => () => {
103
+ for (const cancel of animations.current.values())
104
+ cancel();
105
+ }, []);
106
+ };
107
+ var setDragStyle = (element, translate, active) => {
108
+ element.style.translate = translate;
109
+ element.style.zIndex = active ? "1" : "";
110
+ element.toggleAttribute("data-dragging", active);
111
+ };
112
+ var useVerticalDrag = ({
113
+ ref,
114
+ container,
115
+ enabled,
116
+ overflow,
117
+ onMove
118
+ }) => {
119
+ const session = useRef(null);
120
+ const update = () => {
121
+ const drag = session.current;
122
+ const element = drag?.element ?? ref.current;
123
+ const list = container.current;
124
+ if (!drag?.active || !element || !list)
125
+ return;
126
+ const bounds = list.getBoundingClientRect();
127
+ const top = bounds.top + list.clientTop - list.scrollTop;
128
+ const allowance = Math.max(0, overflow);
129
+ const desired = Math.max(bounds.top - allowance, Math.min(bounds.bottom - element.offsetHeight + allowance, drag.y - drag.grab));
130
+ setDragStyle(element, `0 ${desired - top - element.offsetTop}px`, true);
131
+ const bottom = desired + element.offsetHeight;
132
+ const siblings = [...list.children].filter((child) => child instanceof HTMLElement && child.getAttribute("aria-hidden") !== "true");
133
+ const index = siblings.indexOf(element);
134
+ let target = index;
135
+ for (let i = 0;i < siblings.length; i++) {
136
+ const sibling = siblings[i];
137
+ if (!(sibling instanceof HTMLElement) || sibling === element)
138
+ continue;
139
+ const middle = top + sibling.offsetTop + sibling.offsetHeight / 2;
140
+ if (i > index && bottom > middle)
141
+ target = i;
142
+ if (i < index && desired < middle) {
143
+ target = i;
144
+ break;
145
+ }
146
+ }
147
+ if (target !== index)
148
+ onMove(target);
149
+ };
150
+ const end = () => {
151
+ const drag = session.current;
152
+ session.current = null;
153
+ const element = drag?.element ?? ref.current;
154
+ if (element)
155
+ setDragStyle(element, "", false);
156
+ if (drag?.capture.hasPointerCapture?.(drag.pointer))
157
+ drag.capture.releasePointerCapture(drag.pointer);
158
+ };
159
+ const updateDrag = useEffectEvent(update);
160
+ const endDrag = useEffectEvent(end);
161
+ const connection = useRef({ generation: 0 });
162
+ useBrowserLayoutEffect(() => {
163
+ if (!enabled)
164
+ end();
165
+ else
166
+ update();
167
+ });
168
+ useEffect(() => {
169
+ const lifecycle = connection.current;
170
+ const generation = ++lifecycle.generation;
171
+ const scroll = () => updateDrag();
172
+ const move = (event) => {
173
+ const drag = session.current;
174
+ const element = ref.current;
175
+ if (!drag || drag.pointer !== event.pointerId || !element)
176
+ return;
177
+ drag.y = event.clientY;
178
+ if (!drag.active && Math.abs(drag.y - drag.start) < 4)
179
+ return;
180
+ drag.active = true;
181
+ element.dataset.dragging = "";
182
+ element.style.zIndex = "1";
183
+ updateDrag();
184
+ };
185
+ const stop = (event) => {
186
+ if (session.current?.pointer === event.pointerId)
187
+ endDrag();
188
+ };
189
+ document.addEventListener("scroll", scroll, true);
190
+ document.addEventListener("pointermove", move);
191
+ document.addEventListener("pointerup", stop);
192
+ document.addEventListener("pointercancel", stop);
193
+ document.addEventListener("lostpointercapture", stop);
194
+ window.addEventListener("resize", endDrag);
195
+ return () => {
196
+ document.removeEventListener("scroll", scroll, true);
197
+ document.removeEventListener("pointermove", move);
198
+ document.removeEventListener("pointerup", stop);
199
+ document.removeEventListener("pointercancel", stop);
200
+ document.removeEventListener("lostpointercapture", stop);
201
+ window.removeEventListener("resize", endDrag);
202
+ queueMicrotask(() => {
203
+ if (lifecycle.generation === generation)
204
+ endDrag();
205
+ });
206
+ };
207
+ }, [ref]);
208
+ return {
209
+ onPointerDown: (event) => {
210
+ if (!enabled || event.button !== 0 || session.current)
211
+ return;
212
+ const element = ref.current;
213
+ const list = container.current;
214
+ if (!element || !list)
215
+ return;
216
+ list.setPointerCapture(event.pointerId);
217
+ session.current = {
218
+ pointer: event.pointerId,
219
+ start: event.clientY,
220
+ y: event.clientY,
221
+ grab: event.clientY - element.getBoundingClientRect().top,
222
+ active: false,
223
+ capture: list,
224
+ element
225
+ };
226
+ }
227
+ };
228
+ };
16
229
 
17
230
  // ../../src/components/ui/animated-list.tsx
18
231
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
@@ -49,176 +262,153 @@ var AnimatedList = ({
49
262
  ...messages?.[locale]
50
263
  };
51
264
  const instructions = useId();
52
- const container = useRef(null);
53
- const [announcedKey, setAnnouncedKey] = useState(null);
54
- const keys = items.map(getKey);
265
+ const container = useRef2(null);
266
+ const [announcedKey, setAnnouncedKey] = useState2(null);
267
+ const retained = useKeyedPresence(items, getKey);
268
+ const [initial, setInitial] = useState2(true);
269
+ useEffect2(() => setInitial(false), []);
270
+ useListLayout(container, duration);
55
271
  const announcement = items.map((item, index) => getKey(item) === announcedKey ? copy.position(getItemLabel?.(item) ?? getKey(item), index + 1, items.length) : "").join("");
56
- const reorder = (nextKeys) => {
57
- const order = new Map(nextKeys.map((key, index) => [key, index]));
58
- onReorder?.([...items].sort((a, b) => (order.get(getKey(a)) ?? 0) - (order.get(getKey(b)) ?? 0)));
272
+ const move = (key, target) => {
273
+ const index = items.findIndex((item) => getKey(item) === key);
274
+ if (index < 0 || index === target || !onReorder)
275
+ return;
276
+ const next = [...items];
277
+ const [item] = next.splice(index, 1);
278
+ if (item === undefined)
279
+ return;
280
+ next.splice(target, 0, item);
281
+ setAnnouncedKey(key);
282
+ onReorder(next);
59
283
  };
60
- if (onReorder)
61
- return /* @__PURE__ */ jsxs(Fragment, {
62
- children: [
63
- /* @__PURE__ */ jsx(Reorder.Group, {
64
- "data-slot": "animated-list",
65
- ref: container,
66
- as: "ul",
67
- axis: "y",
68
- values: keys,
69
- onReorder: reorder,
70
- className: cn("grid gap-3", className),
71
- "aria-label": label,
72
- children: /* @__PURE__ */ jsx(AnimatePresence, {
73
- initial: false,
74
- children: items.map((item, index) => {
75
- const key = getKey(item);
76
- const itemLabel = getItemLabel?.(item) ?? key;
77
- return /* @__PURE__ */ jsx(ReorderableListItem, {
78
- value: key,
79
- duration,
80
- className: itemClassName,
81
- instructions,
82
- handleLabel: `${copy.reorder}: ${itemLabel}`,
83
- disabled: items.length < 2,
84
- constraints: container,
85
- dragOverflow,
86
- onMove: (direction) => {
87
- const target = direction === "Home" ? 0 : direction === "End" ? items.length - 1 : Math.max(0, Math.min(items.length - 1, index + (direction === "ArrowUp" ? -1 : 1)));
88
- if (index === target)
89
- return;
90
- const nextKeys = [...keys];
91
- nextKeys.splice(index, 1);
92
- nextKeys.splice(target, 0, key);
93
- setAnnouncedKey(key);
94
- reorder(nextKeys);
95
- },
96
- onDragEnd: () => setAnnouncedKey(key),
97
- children: children(item)
98
- }, key);
99
- })
100
- })
101
- }),
102
- /* @__PURE__ */ jsx("span", {
103
- id: instructions,
104
- className: "sr-only",
105
- children: copy.instructions
106
- }),
107
- /* @__PURE__ */ jsx("span", {
108
- role: "status",
109
- className: "sr-only",
110
- children: announcement
284
+ return /* @__PURE__ */ jsxs(Fragment, {
285
+ children: [
286
+ /* @__PURE__ */ jsx("ul", {
287
+ ref: container,
288
+ "data-slot": "animated-list",
289
+ className: cn("relative grid gap-3", className),
290
+ "aria-label": label,
291
+ children: retained.items.map((item) => {
292
+ const key = getKey(item);
293
+ const index = items.findIndex((candidate) => getKey(candidate) === key);
294
+ return /* @__PURE__ */ jsx(ListItem, {
295
+ itemKey: key,
296
+ present: retained.present.has(key),
297
+ initial,
298
+ duration,
299
+ className: itemClassName,
300
+ instructions,
301
+ handleLabel: `${copy.reorder}: ${getItemLabel?.(item) ?? key}`,
302
+ reorderable: !!onReorder,
303
+ disabled: items.length < 2,
304
+ container,
305
+ dragOverflow,
306
+ onExit: () => retained.remove(key),
307
+ onMove: (target) => move(key, target),
308
+ onKeyMove: (direction) => move(key, direction === "Home" ? 0 : direction === "End" ? items.length - 1 : Math.max(0, Math.min(items.length - 1, index + (direction === "ArrowUp" ? -1 : 1)))),
309
+ children: children(item)
310
+ }, key);
111
311
  })
112
- ]
113
- });
114
- return /* @__PURE__ */ jsx("ul", {
115
- "data-slot": "animated-list",
116
- className: cn("grid gap-3", className),
117
- "aria-label": label,
118
- children: /* @__PURE__ */ jsx(AnimatePresence, {
119
- initial: false,
120
- children: items.map((item) => /* @__PURE__ */ jsx(AnimatedListItem, {
121
- duration,
122
- className: itemClassName,
123
- children: children(item)
124
- }, getKey(item)))
125
- })
312
+ }),
313
+ onReorder ? /* @__PURE__ */ jsxs(Fragment, {
314
+ children: [
315
+ /* @__PURE__ */ jsx("p", {
316
+ id: instructions,
317
+ className: "sr-only",
318
+ children: copy.instructions
319
+ }),
320
+ /* @__PURE__ */ jsx("p", {
321
+ role: "status",
322
+ "aria-live": "polite",
323
+ "aria-atomic": "true",
324
+ className: "sr-only",
325
+ children: announcement
326
+ })
327
+ ]
328
+ }) : null
329
+ ]
126
330
  });
127
331
  };
128
- var ReorderableListItem = ({
129
- children,
130
- value,
332
+ var ListItem = ({
333
+ itemKey,
334
+ present,
335
+ initial,
131
336
  duration,
132
337
  className,
133
338
  instructions,
134
339
  handleLabel,
340
+ reorderable,
135
341
  disabled,
136
- constraints,
342
+ container,
137
343
  dragOverflow,
344
+ onExit,
138
345
  onMove,
139
- onDragEnd
346
+ onKeyMove,
347
+ children
140
348
  }) => {
141
- const present = useIsPresent();
349
+ const ref = useRef2(null);
350
+ const mounted = useRef2(false);
351
+ const lastPresent = useRef2(present);
352
+ const transitioning = useRef2(false);
353
+ const exit = useEffectEvent2(onExit);
142
354
  const reduced = useReducedMotion();
143
- const controls = useDragControls();
144
- return /* @__PURE__ */ jsxs(Reorder.Item, {
355
+ const drag = useVerticalDrag({
356
+ ref,
357
+ container,
358
+ enabled: reorderable && !disabled && present,
359
+ overflow: dragOverflow,
360
+ onMove
361
+ });
362
+ useEffect2(() => {
363
+ const element = ref.current;
364
+ const first = !mounted.current;
365
+ mounted.current = true;
366
+ if (!element || first && initial && present)
367
+ return;
368
+ if (!first && lastPresent.current === present && !transitioning.current)
369
+ return;
370
+ lastPresent.current = present;
371
+ transitioning.current = true;
372
+ return animateElement(element, [{ opacity: present ? 0 : 1 }, { opacity: present ? 1 : 0 }], reduced ? 0 : Math.max(0, duration), () => {
373
+ transitioning.current = false;
374
+ if (!present)
375
+ exit();
376
+ });
377
+ }, [present, initial, duration, reduced]);
378
+ return /* @__PURE__ */ jsxs("li", {
379
+ ref,
145
380
  "data-slot": "animated-list-item",
146
- as: "li",
147
- value,
148
- dragListener: false,
149
- dragControls: controls,
150
- dragMomentum: false,
151
- dragConstraints: constraints,
152
- dragElastic: 0,
153
- onMeasureDragConstraints: (bounds) => ({
154
- ...bounds,
155
- top: bounds.top - Math.max(0, dragOverflow),
156
- bottom: bounds.bottom + Math.max(0, dragOverflow)
157
- }),
158
- tabIndex: -1,
159
- layout: "position",
381
+ "data-motion-key": itemKey,
160
382
  className: cn("relative", className),
161
383
  inert: !present,
162
384
  "aria-hidden": !present ? true : undefined,
163
- initial: { opacity: 0 },
164
- animate: { opacity: 1 },
165
- exit: { opacity: 0 },
166
- transition: {
167
- duration: reduced !== false ? 0 : Math.max(0, duration) / 1000
168
- },
169
- onDragEnd,
170
385
  children: [
171
- /* @__PURE__ */ jsx("button", {
386
+ reorderable ? /* @__PURE__ */ jsx("button", {
172
387
  "data-slot": "animated-list-handle",
173
388
  type: "button",
174
389
  disabled: disabled || !present,
175
390
  "aria-label": handleLabel,
176
391
  "aria-describedby": instructions,
177
392
  className: "text-muted-foreground focus-visible:ring-ring inline-flex size-8 shrink-0 cursor-grab touch-none items-center justify-center rounded-md outline-none select-none focus-visible:ring-2 active:cursor-grabbing disabled:cursor-default disabled:opacity-50",
178
- onPointerDown: (event) => {
179
- if (!disabled && present)
180
- controls.start(event);
181
- },
393
+ ...drag,
182
394
  onKeyDown: (event) => {
183
395
  if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
184
396
  return;
185
397
  if (event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Home" || event.key === "End") {
186
398
  event.preventDefault();
187
399
  event.stopPropagation();
188
- onMove(event.key);
400
+ onKeyMove(event.key);
189
401
  }
190
402
  },
191
403
  children: /* @__PURE__ */ jsx(GripVertical, {
192
404
  className: "size-4",
193
405
  "aria-hidden": "true"
194
406
  })
195
- }),
407
+ }) : null,
196
408
  children
197
409
  ]
198
410
  });
199
411
  };
200
- var AnimatedListItem = ({
201
- children,
202
- duration,
203
- className
204
- }) => {
205
- const present = useIsPresent();
206
- const reduced = useReducedMotion();
207
- return /* @__PURE__ */ jsx(motion.li, {
208
- "data-slot": "animated-list-item",
209
- layout: reduced === false ? "position" : false,
210
- className,
211
- inert: !present,
212
- "aria-hidden": !present ? true : undefined,
213
- initial: { opacity: 0 },
214
- animate: { opacity: 1 },
215
- exit: { opacity: 0 },
216
- transition: {
217
- duration: reduced !== false ? 0 : Math.max(0, duration) / 1000
218
- },
219
- children
220
- });
221
- };
222
412
  export {
223
413
  AnimatedList
224
414
  };
@@ -1,12 +1,48 @@
1
- // ../../src/components/ui/animated-number.tsx
1
+ // ../../src/lib/krakmotion.ts
2
2
  import {
3
- animate,
4
- motion,
5
- useMotionValue,
6
- useReducedMotion,
7
- useTransform
8
- } from "motion/react";
9
- import { useEffect, useMemo } from "react";
3
+ useEffect,
4
+ useEffectEvent,
5
+ useLayoutEffect,
6
+ useRef,
7
+ useState,
8
+ useSyncExternalStore
9
+ } from "react";
10
+ var useBrowserLayoutEffect = globalThis.window ? useLayoutEffect : useEffect;
11
+ var reducedMotionQuery = "(prefers-reduced-motion: reduce)";
12
+ var subscribeReducedMotion = (notify) => {
13
+ const query = window.matchMedia?.(reducedMotionQuery);
14
+ query?.addEventListener("change", notify);
15
+ return () => query?.removeEventListener("change", notify);
16
+ };
17
+ var useReducedMotion = () => useSyncExternalStore(subscribeReducedMotion, () => window.matchMedia?.(reducedMotionQuery).matches ?? true, () => true);
18
+ var useNumberTransition = (value, duration) => {
19
+ const [displayed, setDisplayed] = useState(value);
20
+ const current = useRef(value);
21
+ const reduced = useReducedMotion();
22
+ useEffect(() => {
23
+ if (reduced || duration <= 0 || !Number.isFinite(value) || !Number.isFinite(current.current)) {
24
+ current.current = value;
25
+ setDisplayed(value);
26
+ return;
27
+ }
28
+ const start = performance.now();
29
+ const from = current.current;
30
+ let frame = 0;
31
+ const tick = (now) => {
32
+ const progress = Math.min(1, (now - start) / duration);
33
+ current.current = from + (value - from) * (1 - (1 - progress) ** 3);
34
+ setDisplayed(current.current);
35
+ if (progress < 1)
36
+ frame = requestAnimationFrame(tick);
37
+ };
38
+ frame = requestAnimationFrame(tick);
39
+ return () => cancelAnimationFrame(frame);
40
+ }, [value, duration, reduced]);
41
+ return reduced ? value : displayed;
42
+ };
43
+
44
+ // ../../src/components/ui/animated-number.tsx
45
+ import { useMemo } from "react";
10
46
  import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
11
47
  import { jsx, jsxs } from "react/jsx-runtime";
12
48
  var AnimatedNumber = ({
@@ -18,20 +54,7 @@ var AnimatedNumber = ({
18
54
  }) => {
19
55
  const locale = useKrakstackLocale(override);
20
56
  const formatter = useMemo(() => new Intl.NumberFormat(locale, format), [locale, format]);
21
- const displayed = useMotionValue(value);
22
- const text = useTransform(() => formatter.format(displayed.get()));
23
- const reduced = useReducedMotion();
24
- useEffect(() => {
25
- if (reduced !== false || duration <= 0 || !Number.isFinite(value) || !Number.isFinite(displayed.get())) {
26
- displayed.set(value);
27
- return;
28
- }
29
- const controls = animate(displayed, value, {
30
- duration: duration / 1000,
31
- ease: "easeOut"
32
- });
33
- return () => controls.stop();
34
- }, [displayed, duration, reduced, value]);
57
+ const displayed = useNumberTransition(value, duration);
35
58
  return /* @__PURE__ */ jsxs("span", {
36
59
  "data-slot": "animated-number",
37
60
  className,
@@ -40,9 +63,9 @@ var AnimatedNumber = ({
40
63
  className: "sr-only",
41
64
  children: formatter.format(value)
42
65
  }),
43
- /* @__PURE__ */ jsx(motion.span, {
66
+ /* @__PURE__ */ jsx("span", {
44
67
  "aria-hidden": "true",
45
- children: text
68
+ children: formatter.format(displayed)
46
69
  })
47
70
  ]
48
71
  });