@kumix/ui 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/components/agents/ai-sidebar/resource-row.js +1 -1
- package/dist/components/agents/ai-sidebar.js +1 -1
- package/dist/components/agents/approval-card.js +1 -1
- package/dist/components/agents/code-block.js +1 -1
- package/dist/components/agents/context-meter.js +1 -1
- package/dist/components/agents/file-diff.js +1 -1
- package/dist/components/agents/message-scroller.js +1 -1
- package/dist/components/agents/prompt-input.js +1 -1
- package/dist/components/agents/streaming-response.js +1 -1
- package/dist/components/agents/tool-result.js +1 -1
- package/dist/components/agents/voice-note.js +1 -1
- package/dist/components/charts/bar-chart/context.d.ts +3 -3
- package/dist/components/charts/bar-chart/tooltip.js +1 -1
- package/dist/components/charts/bump-chart/context.d.ts +1 -1
- package/dist/components/charts/bump-chart/point.js +1 -1
- package/dist/components/charts/bump-chart/series.d.ts +1 -1
- package/dist/components/charts/bump-chart.d.ts +1 -1
- package/dist/components/charts/candlestick-chart/context.d.ts +3 -3
- package/dist/components/charts/composition-chart/context.d.ts +1 -1
- package/dist/components/charts/composition-chart/plot.js +1 -1
- package/dist/components/charts/composition-chart.d.ts +1 -1
- package/dist/components/charts/funnel-chart.js +1 -1
- package/dist/components/charts/heat-calendar/tooltip.d.ts +1 -1
- package/dist/components/charts/heat-calendar/tooltip.js +1 -1
- package/dist/components/charts/heat-calendar.d.ts +1 -1
- package/dist/components/charts/liquidity-heatmap.js +1 -1
- package/dist/components/charts/order-book.d.ts +1 -1
- package/dist/components/charts/price-target-fan/tooltip.js +1 -1
- package/dist/components/charts/returns-calendar/tooltip.js +1 -1
- package/dist/components/charts/sankey-chart/tooltip.js +1 -1
- package/dist/components/charts/status-bar/tooltip.d.ts +1 -1
- package/dist/components/charts/status-bar/tooltip.js +1 -1
- package/dist/components/charts/status-bar.d.ts +1 -1
- package/dist/components/charts/treemap/tooltip.js +1 -1
- package/dist/components/charts/treemap.d.ts +1 -1
- package/dist/components/charts/volume-profile/tooltip.js +1 -1
- package/dist/components/charts/volume-profile.d.ts +1 -1
- package/dist/components/motion/animated-toast-stack/toast-body.js +1 -1
- package/dist/components/motion/attachment-upload/image-thumbnail.js +1 -1
- package/dist/components/motion/attachment-upload/row-action.js +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +2 -2
- package/dist/components/motion/availability-scheduler.js +1 -1
- package/dist/components/motion/avatar-group.js +1 -1
- package/dist/components/motion/casino/game-parts.js +1 -1
- package/dist/components/motion/center-morph-modal.js +1 -1
- package/dist/components/motion/combobox/trigger.d.ts.map +1 -1
- package/dist/components/motion/combobox/trigger.js +7 -2
- package/dist/components/motion/combobox/trigger.js.map +1 -1
- package/dist/components/motion/date-range-picker/header.js +1 -1
- package/dist/components/motion/file-upload.js +1 -1
- package/dist/components/motion/knockout-bracket.js +1 -1
- package/dist/components/motion/knockout-wheel.js +1 -1
- package/dist/components/motion/mines.js +1 -1
- package/dist/components/motion/plinko.js +1 -1
- package/dist/components/motion/prediction-market-card.js +1 -1
- package/dist/components/motion/qr-code.d.ts +42 -0
- package/dist/components/motion/qr-code.d.ts.map +1 -0
- package/dist/components/motion/qr-code.js +443 -0
- package/dist/components/motion/qr-code.js.map +1 -0
- package/dist/components/motion/swap/controls.js +1 -1
- package/dist/components/motion/tooltip.d.ts +2 -2
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/tooltip.js +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- package/dist/components/ui/attachment.d.ts +2 -2
- package/dist/components/ui/button-group.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/empty.d.ts +1 -1
- package/dist/components/ui/field.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/{context-DMIy-rFm.d.ts → context-Cyjsttyl.d.ts} +4 -4
- package/dist/{context-DMIy-rFm.d.ts.map → context-Cyjsttyl.d.ts.map} +1 -1
- package/dist/{context-jX-r_7EP.d.ts → context-D7eAawR3.d.ts} +4 -4
- package/dist/{context-jX-r_7EP.d.ts.map → context-D7eAawR3.d.ts.map} +1 -1
- package/dist/{copy-menu-Bgoo5oWq.js → copy-menu-Di77fZ9p.js} +2 -2
- package/dist/{copy-menu-Bgoo5oWq.js.map → copy-menu-Di77fZ9p.js.map} +1 -1
- package/dist/hooks/use-dismiss.d.ts +9 -1
- package/dist/hooks/use-dismiss.d.ts.map +1 -1
- package/dist/hooks/use-dismiss.js +6 -3
- package/dist/hooks/use-dismiss.js.map +1 -1
- package/dist/lib/layers.d.ts +1 -1
- package/dist/lib/layers.js.map +1 -1
- package/dist/{resource-row-PkgPS9Hk.js → resource-row-DByzjie0.js} +2 -2
- package/dist/{resource-row-PkgPS9Hk.js.map → resource-row-DByzjie0.js.map} +1 -1
- package/dist/{tooltip-X7sMXf98.d.ts → tooltip-CwsBzl7m.d.ts} +2 -2
- package/dist/{tooltip-X7sMXf98.d.ts.map → tooltip-CwsBzl7m.d.ts.map} +1 -1
- package/dist/{tooltip-gKOUHp_1.d.ts → tooltip-TdY1OH4j.d.ts} +2 -2
- package/dist/{tooltip-gKOUHp_1.d.ts.map → tooltip-TdY1OH4j.d.ts.map} +1 -1
- package/dist/{tooltip-gHv-6eOs.js → tooltip-eecPhLtC.js} +54 -7
- package/dist/tooltip-eecPhLtC.js.map +1 -0
- package/package.json +11 -6
- package/dist/tooltip-gHv-6eOs.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trigger.js","names":[],"sources":["../../../../src/components/motion/combobox/trigger.tsx"],"sourcesContent":["\"use client\";\n\nimport
|
|
1
|
+
{"version":3,"file":"trigger.js","names":[],"sources":["../../../../src/components/motion/combobox/trigger.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type InputHTMLAttributes,\n type KeyboardEvent as ReactKeyboardEvent,\n type ReactNode,\n type Ref,\n useMemo,\n} from \"react\";\nimport { ChevronsUpDown, Search } from \"lucide-react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useTouchCapable } from \"../../../hooks/use-touch-capable\";\nimport { mergeRefs } from \"../../../lib/merge-refs\";\nimport { useComboboxContext } from \"./context\";\n\nexport interface ComboboxTriggerProps {\n children: ReactNode;\n /** Classes merged onto the trigger field. */\n className?: string;\n}\n\nexport function ComboboxTrigger({ children, className }: ComboboxTriggerProps) {\n const context = useComboboxContext(\"ComboboxTrigger\");\n\n return (\n <div\n ref={context.triggerRef}\n id={context.triggerId}\n data-state={context.open ? \"open\" : \"closed\"}\n onPointerDown={(event) => {\n if (context.disabled || event.target === context.inputRef.current) return;\n event.preventDefault();\n context.inputRef.current?.focus({ preventScroll: true });\n context.setOpen(true);\n }}\n className={cn(\n \"border-border text-foreground relative z-20 flex h-10 w-full min-w-52 cursor-text items-center justify-between gap-3 rounded-full border bg-transparent px-4 text-sm transition-[border-color] hover:border-(--color-border-strong)\",\n \"focus-within:ring-foreground/20 focus-within:ring-2\",\n context.disabled && \"pointer-events-none opacity-50\",\n className,\n )}\n >\n <span className=\"min-w-0 flex-1 text-left\">{children}</span>\n <span aria-hidden className=\"text-muted-foreground shrink-0\">\n <ChevronsUpDown className=\"size-4\" />\n </span>\n </div>\n );\n}\n\nexport interface ComboboxValueProps {\n /** Shown while nothing is selected. Default: \"Select an option\" */\n placeholder?: ReactNode;\n children?: ReactNode | ((value: string | undefined, label: string | undefined) => ReactNode);\n /** Classes merged onto the value text. */\n className?: string;\n}\n\nexport function ComboboxValue({ placeholder, children, className }: ComboboxValueProps) {\n const context = useComboboxContext(\"ComboboxValue\");\n const label = context.labelFor(context.value);\n const content =\n typeof children === \"function\"\n ? children(context.value, label)\n : (children ?? label ?? placeholder ?? context.t(\"valuePlaceholder\"));\n\n return (\n <span\n className={cn(\n \"block truncate\",\n context.value === undefined ? \"text-muted-foreground\" : \"text-foreground\",\n className,\n )}\n >\n {content}\n </span>\n );\n}\n\nexport interface ComboboxInputProps\n extends Omit<InputHTMLAttributes<HTMLInputElement>, \"defaultValue\" | \"value\"> {\n /** Ref to the underlying input element. */\n ref?: Ref<HTMLInputElement>;\n /** Classes merged onto the wrapper around the search icon and input. */\n wrapperClassName?: string;\n}\n\nexport function ComboboxInput({\n ref,\n className,\n wrapperClassName,\n \"aria-label\": ariaLabel,\n onChange,\n onClick,\n onFocus,\n onKeyDown,\n onPointerDown,\n placeholder,\n ...props\n}: ComboboxInputProps) {\n const context = useComboboxContext(\"ComboboxInput\");\n const { inputRef } = context;\n const mergedRef = useMemo(() => mergeRefs(ref, inputRef), [ref, inputRef]);\n const canTouch = useTouchCapable();\n const selectedLabel = context.labelFor(context.value);\n\n const handleKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event);\n if (event.defaultPrevented) return;\n\n if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n event.preventDefault();\n // Opening is the whole action. While closed the list is still filtering\n // by the query the last session left, so a step taken here would be\n // measured against rows the next render replaces - and stamped with a\n // query it no longer has, which discards it. Open onto the selection,\n // and let the next key step through the list the user can see.\n if (!context.open) {\n context.setOpen(true);\n return;\n }\n context.moveActive(event.key === \"ArrowDown\" ? 1 : -1);\n } else if (event.key === \"Home\" && context.open) {\n event.preventDefault();\n context.moveActive(\"first\");\n } else if (event.key === \"End\" && context.open) {\n event.preventDefault();\n context.moveActive(\"last\");\n } else if (event.key === \"Enter\") {\n if (event.nativeEvent.isComposing || event.keyCode === 229) return;\n event.preventDefault();\n if (context.open) context.selectActive();\n else context.setOpen(true);\n } else if (event.key === \"Escape\" && context.open) {\n event.preventDefault();\n context.setOpen(false, true);\n }\n };\n\n return (\n <div className={cn(\"flex min-w-0 flex-1 items-center gap-2\", wrapperClassName)}>\n <Search aria-hidden className=\"text-muted-foreground size-4 shrink-0\" />\n <input\n {...props}\n ref={mergedRef}\n id={context.inputId}\n role=\"combobox\"\n aria-label={ariaLabel ?? context.t(\"inputLabel\")}\n aria-autocomplete=\"list\"\n aria-expanded={context.open}\n aria-controls={context.listId}\n aria-activedescendant={context.open ? context.activeItemId : undefined}\n autoComplete=\"off\"\n disabled={context.disabled}\n value={context.open ? context.query : (selectedLabel ?? \"\")}\n placeholder={placeholder ?? context.t(\"inputPlaceholder\")}\n onPointerDown={(event) => {\n onPointerDown?.(event);\n if (event.defaultPrevented || context.open) return;\n event.preventDefault();\n context.inputRef.current?.focus({ preventScroll: true });\n context.setOpen(true);\n }}\n onFocus={(event) => {\n context.setOpen(true);\n onFocus?.(event);\n }}\n onClick={(event) => {\n context.setOpen(true);\n onClick?.(event);\n }}\n onChange={(event) => {\n context.setOpen(true);\n context.setQuery(event.target.value);\n onChange?.(event);\n }}\n onKeyDown={handleKeyDown}\n className={cn(\n \"text-foreground placeholder:text-muted-foreground h-10 min-w-0 flex-1 bg-transparent outline-none disabled:cursor-not-allowed\",\n // Keep one font-size utility so caller classes can override it.\n \"text-(length:--combobox-input-size,--theme(--text-sm,inherit))/[--theme(--text-sm--line-height,inherit)]\",\n // iOS zooms on focus below 16px, even before hydration. The hook\n // also detects touch on devices that report a fine pointer.\n \"any-pointer-coarse:[--combobox-input-size:max(16px,--theme(--text-base,1rem))]\",\n canTouch && \"[--combobox-input-size:max(16px,--theme(--text-base,1rem))]\",\n className,\n )}\n />\n </div>\n );\n}\n"],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { ChevronDown, ChevronLeft, ChevronRight } from "lucide-react";
|
|
3
3
|
import { cn } from "@kumix/utils";
|
|
4
|
-
import { t as Tooltip } from "../../../tooltip-
|
|
4
|
+
import { t as Tooltip } from "../../../tooltip-eecPhLtC.js";
|
|
5
5
|
import { n as useDateRangePickerContext } from "../../../context-DR6jkfea.js";
|
|
6
6
|
import { a as parse } from "../../../date-utils-DVDYcEA_.js";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -5,7 +5,7 @@ import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
|
|
5
5
|
import { cn } from "@kumix/utils";
|
|
6
6
|
import { EASE_OUT } from "../../lib/ease.js";
|
|
7
7
|
import { useLocale, useMessages } from "../../lib/i18n.js";
|
|
8
|
-
import { t as Tooltip } from "../../tooltip-
|
|
8
|
+
import { t as Tooltip } from "../../tooltip-eecPhLtC.js";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
// src/components/motion/file-upload.tsx
|
|
11
11
|
/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */
|
|
@@ -5,7 +5,7 @@ import { motion, useReducedMotion } from "motion/react";
|
|
|
5
5
|
import { cn } from "@kumix/utils";
|
|
6
6
|
import { EASE_OUT } from "../../lib/ease.js";
|
|
7
7
|
import { useLocale, useMessages } from "../../lib/i18n.js";
|
|
8
|
-
import { t as Tooltip } from "../../tooltip-
|
|
8
|
+
import { t as Tooltip } from "../../tooltip-eecPhLtC.js";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
// src/components/motion/knockout-bracket.tsx
|
|
11
11
|
/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */
|
|
@@ -9,7 +9,7 @@ import { useHoverGesture } from "../../hooks/use-hover-gesture.js";
|
|
|
9
9
|
import { useTapGesture } from "../../hooks/use-tap-gesture.js";
|
|
10
10
|
import { SPRING_PANEL } from "../../lib/ease.js";
|
|
11
11
|
import { useMessages } from "../../lib/i18n.js";
|
|
12
|
-
import { t as Tooltip } from "../../tooltip-
|
|
12
|
+
import { t as Tooltip } from "../../tooltip-eecPhLtC.js";
|
|
13
13
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
14
14
|
// src/components/motion/knockout-wheel.tsx
|
|
15
15
|
/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */
|
|
@@ -12,7 +12,7 @@ import { AdaptiveStepper, AdaptiveStepperDecrement, AdaptiveStepperIncrement, Ad
|
|
|
12
12
|
import { Button } from "./button/base.js";
|
|
13
13
|
import { formatMultiplier, formatOdds } from "./casino/game-parts.js";
|
|
14
14
|
import { NumberTicker } from "./number-ticker.js";
|
|
15
|
-
import { t as Tooltip } from "../../tooltip-
|
|
15
|
+
import { t as Tooltip } from "../../tooltip-eecPhLtC.js";
|
|
16
16
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
17
17
|
// src/components/motion/mines.tsx
|
|
18
18
|
/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */
|
|
@@ -8,7 +8,7 @@ import { useMessages } from "../../lib/i18n.js";
|
|
|
8
8
|
import { createTickPlayer } from "../../lib/tick-sound.js";
|
|
9
9
|
import { ActionSwapCascadeIcon } from "./action-swap-cascade.js";
|
|
10
10
|
import { Button } from "./button/base.js";
|
|
11
|
-
import { t as Tooltip } from "../../tooltip-
|
|
11
|
+
import { t as Tooltip } from "../../tooltip-eecPhLtC.js";
|
|
12
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
13
|
// src/components/motion/plinko.tsx
|
|
14
14
|
/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */
|
|
@@ -7,7 +7,7 @@ import { useHoverCapable } from "../../hooks/use-hover-capable.js";
|
|
|
7
7
|
import { EASE_OUT, SPRING_PRESS } from "../../lib/ease.js";
|
|
8
8
|
import { useMessages } from "../../lib/i18n.js";
|
|
9
9
|
import { ActionSwapText } from "./action-swap.js";
|
|
10
|
-
import { t as Tooltip } from "../../tooltip-
|
|
10
|
+
import { t as Tooltip } from "../../tooltip-eecPhLtC.js";
|
|
11
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
// src/components/motion/prediction-market-card.tsx
|
|
13
13
|
/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type QrCodeVariant = "swarm" | "ripple" | "scan" | "smoke";
|
|
2
|
+
export declare const qrCodeMessages: {
|
|
3
|
+
label: string;
|
|
4
|
+
};
|
|
5
|
+
export type QrCodeMessages = typeof qrCodeMessages;
|
|
6
|
+
export interface QrCodeOrigin {
|
|
7
|
+
/** Horizontal position as a fraction of the canvas width, 0 is the left edge. */
|
|
8
|
+
x: number;
|
|
9
|
+
/** Vertical position as a fraction of the canvas height, 0 is the top edge. */
|
|
10
|
+
y: number;
|
|
11
|
+
}
|
|
12
|
+
export interface AnimatedQrCodeProps {
|
|
13
|
+
/** Text or URL the code encodes. */
|
|
14
|
+
value: string;
|
|
15
|
+
/** Whether the code is drawn. Turning it on builds the code; turning it off plays the build backwards from wherever it is. */
|
|
16
|
+
shown: boolean;
|
|
17
|
+
/** How the code builds: every piece flies in on a curved path, pops in place behind a spreading ring, drops into place behind a bar sweeping down, or rises as smoke and condenses from the bottom row up. Default: "swarm" */
|
|
18
|
+
variant?: QrCodeVariant;
|
|
19
|
+
/** Side of the square canvas, in px, quiet zone included. Default: 296 */
|
|
20
|
+
size?: number;
|
|
21
|
+
/** Where swarm pieces fly from and where the ripple ring starts. Scan and smoke ignore it. Default: bottom centre for swarm, centre for ripple */
|
|
22
|
+
origin?: QrCodeOrigin;
|
|
23
|
+
/** Dot colour, any CSS colour. Default: "#0a0a0a" */
|
|
24
|
+
ink?: string;
|
|
25
|
+
/** Background colour, any CSS colour. Keep it light so cameras can read the code. Default: "#ffffff" */
|
|
26
|
+
paper?: string;
|
|
27
|
+
/** Called when a build or teardown finishes, with the `shown` value it ended on. */
|
|
28
|
+
onSettled?: (shown: boolean) => void;
|
|
29
|
+
/** Translated strings, merged over the English defaults. */
|
|
30
|
+
labels?: Partial<QrCodeMessages>;
|
|
31
|
+
/** Classes merged onto the canvas. */
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A QR code drawn on a canvas that builds itself piece by piece: the dots and
|
|
36
|
+
* the three finder eyes fly in on curved paths, pop in behind a spreading
|
|
37
|
+
* ring, or drop in behind a bar sweeping down. One reversible clock runs it,
|
|
38
|
+
* so hiding plays the build backwards and a press mid-run turns around from
|
|
39
|
+
* where it is.
|
|
40
|
+
*/
|
|
41
|
+
export declare function AnimatedQrCode({ value, shown, variant, size, origin, ink, paper, onSettled, labels, className }: AnimatedQrCodeProps): import("react").JSX.Element;
|
|
42
|
+
//# sourceMappingURL=qr-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qr-code.d.ts","names":[],"sources":["../../../src/components/motion/qr-code.tsx"],"mappings":"A,YASY;qBAEC;;;YAID,wBAAwB;iBAEnB;;EAEf;;EAEA;;iBAGe;;EAEf;;EAEA;;EAEA,UAAU;;EAEV;;EAEA,SAAS;;EAET;;EAEA;;EAEA,aAAa;;EAEb,SAAS,QAAQ;;EAEjB;;;;;;;;;wBA0ac,iBACd,OACA,OACA,SACA,MACA,QACA,KACA,OACA,WACA,QACA,aACC,sCAAmB,IAAA"}
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { useReducedMotion } from "motion/react";
|
|
4
|
+
import { encode } from "uqr";
|
|
5
|
+
import { cn } from "@kumix/utils";
|
|
6
|
+
import { useMessages } from "../../lib/i18n.js";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
// src/components/motion/qr-code.tsx
|
|
9
|
+
const qrCodeMessages = { label: "QR code for {value}" };
|
|
10
|
+
/** Gap between the first and the last piece starting, in ms. */
|
|
11
|
+
const SPREAD = 600;
|
|
12
|
+
/** One piece's own arrival, in ms. */
|
|
13
|
+
const PIECE_IN = 500;
|
|
14
|
+
const TOTAL = 1100;
|
|
15
|
+
/** Time constant for the clock turning around after a press mid-run, in ms. */
|
|
16
|
+
const TURN_MS = 90;
|
|
17
|
+
/** Reduced motion keeps only an opacity fade of this length, in ms. */
|
|
18
|
+
const REDUCED_MS = 200;
|
|
19
|
+
/** Random offset added to each swarm piece's start, in ms, so the order is not mechanical. */
|
|
20
|
+
const JITTER = 70;
|
|
21
|
+
/** How far a swarm path bows outward, as a share of its length; each piece adds up to BEND_SPREAD more. */
|
|
22
|
+
const BEND = .14;
|
|
23
|
+
const BEND_SPREAD = .12;
|
|
24
|
+
/** Extra length of a piece at top speed on the longest flight, as a share of its size. Width shrinks to keep its area. */
|
|
25
|
+
const STRETCH = 1.3;
|
|
26
|
+
/** Share of that stretch an eye takes. */
|
|
27
|
+
const EYE_STRETCH = .2;
|
|
28
|
+
/** How far a scan piece drops into place, in modules. */
|
|
29
|
+
const DROP = 1.6;
|
|
30
|
+
/** Height of the soft trail behind the scan bar, in px. */
|
|
31
|
+
const SCAN_TRAIL = 28;
|
|
32
|
+
/** Soft puffs in the smoke plume. */
|
|
33
|
+
const PUFFS = 90;
|
|
34
|
+
/** Life of one puff, in ms. Puffs are released over SMOKE_EMIT so the last fades out as the build ends. */
|
|
35
|
+
const PUFF_LIFE = 560;
|
|
36
|
+
const SMOKE_EMIT = SPREAD * .9;
|
|
37
|
+
/** Width of the band puffs rise from, as a share of the canvas. */
|
|
38
|
+
const SMOKE_BAND = .75;
|
|
39
|
+
/** A puff's radius at birth and at the end of its life, in modules. */
|
|
40
|
+
const PUFF_START = 1.4;
|
|
41
|
+
/** Peak opacity of one puff. Overlap builds the density. Fewer, smaller puffs keep the fill cost near 3ms a frame. */
|
|
42
|
+
const PUFF_ALPHA = .22;
|
|
43
|
+
/** How far a condensing piece drifts up into place, in modules. */
|
|
44
|
+
const SMOKE_DRIFT = 1;
|
|
45
|
+
const TAU = Math.PI * 2;
|
|
46
|
+
/**
|
|
47
|
+
* One soft puff: a radial falloff tinted with the ink colour, drawn scaled
|
|
48
|
+
* per puff. A sprite is far cheaper than a gradient or a blur per draw, and
|
|
49
|
+
* blur filters would re-render every frame.
|
|
50
|
+
*/
|
|
51
|
+
const puffSprites = /* @__PURE__ */ new Map();
|
|
52
|
+
function puffSprite(ink) {
|
|
53
|
+
const cached = puffSprites.get(ink);
|
|
54
|
+
if (cached) return cached;
|
|
55
|
+
const s = 96;
|
|
56
|
+
const sprite = document.createElement("canvas");
|
|
57
|
+
sprite.width = s;
|
|
58
|
+
sprite.height = s;
|
|
59
|
+
const g = sprite.getContext("2d");
|
|
60
|
+
if (g) {
|
|
61
|
+
const fall = g.createRadialGradient(s / 2, s / 2, 0, s / 2, s / 2, s / 2);
|
|
62
|
+
fall.addColorStop(0, "rgba(0,0,0,1)");
|
|
63
|
+
fall.addColorStop(.45, "rgba(0,0,0,0.55)");
|
|
64
|
+
fall.addColorStop(1, "rgba(0,0,0,0)");
|
|
65
|
+
g.fillStyle = fall;
|
|
66
|
+
g.fillRect(0, 0, s, s);
|
|
67
|
+
g.globalCompositeOperation = "source-in";
|
|
68
|
+
g.fillStyle = ink;
|
|
69
|
+
g.fillRect(0, 0, s, s);
|
|
70
|
+
}
|
|
71
|
+
puffSprites.set(ink, sprite);
|
|
72
|
+
return sprite;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Smoke is soft, so it is drawn at half the canvas resolution in CSS px (a
|
|
76
|
+
* quarter of the device pixels on a 2x screen) and scaled up in one draw.
|
|
77
|
+
* The puffs overlap heavily, and filling them at full resolution cost
|
|
78
|
+
* several ms a frame.
|
|
79
|
+
*/
|
|
80
|
+
const SMOKE_RES = .5;
|
|
81
|
+
const smokeLayers = /* @__PURE__ */ new Map();
|
|
82
|
+
function smokeLayer(size) {
|
|
83
|
+
if (!smokeLayers.has(size)) {
|
|
84
|
+
const layer = document.createElement("canvas");
|
|
85
|
+
layer.width = Math.ceil(size * SMOKE_RES);
|
|
86
|
+
layer.height = layer.width;
|
|
87
|
+
const lctx = layer.getContext("2d");
|
|
88
|
+
lctx?.scale(SMOKE_RES, SMOKE_RES);
|
|
89
|
+
smokeLayers.set(size, lctx);
|
|
90
|
+
}
|
|
91
|
+
return smokeLayers.get(size) ?? null;
|
|
92
|
+
}
|
|
93
|
+
function drawSmoke(ctx, layout, clock, ink) {
|
|
94
|
+
const { size, cell, pieces } = layout;
|
|
95
|
+
const lctx = smokeLayer(size);
|
|
96
|
+
if (!lctx) return;
|
|
97
|
+
const sprite = puffSprite(ink);
|
|
98
|
+
lctx.clearRect(0, 0, size, size);
|
|
99
|
+
for (const p of pieces) {
|
|
100
|
+
const t = (clock - pieceStart(p, "smoke", size)) / PIECE_IN;
|
|
101
|
+
if (t <= 0 || t >= 1) continue;
|
|
102
|
+
const k = settle(t);
|
|
103
|
+
const half = p.side / 2;
|
|
104
|
+
const haze = (p.eye ? half * 1.3 : cell * 1.6) * (1.4 - k);
|
|
105
|
+
lctx.globalAlpha = .35 * Math.min(1, t * 4) * (1 - k);
|
|
106
|
+
lctx.drawImage(sprite, p.x + half - haze, p.y + half - haze + (1 - k) * cell * SMOKE_DRIFT, haze * 2, haze * 2);
|
|
107
|
+
}
|
|
108
|
+
for (let i = 0; i < PUFFS; i++) {
|
|
109
|
+
const u = (clock - i / PUFFS * SMOKE_EMIT) / PUFF_LIFE;
|
|
110
|
+
if (u <= 0 || u >= 1) continue;
|
|
111
|
+
const h1 = hash(i * 3 + 1);
|
|
112
|
+
const h2 = hash(i * 3 + 2);
|
|
113
|
+
const h3 = hash(i * 3 + 3);
|
|
114
|
+
const rise = size * (.55 + .6 * h2) * (1 - (1 - u) ** 2);
|
|
115
|
+
const curl = Math.sin(h3 * TAU + u * 4) * cell * 2.4 * u;
|
|
116
|
+
const x = size / 2 + (h1 - .5) * size * SMOKE_BAND + curl;
|
|
117
|
+
const y = size + cell * 2 - rise;
|
|
118
|
+
const r = cell * (PUFF_START + 2.2 * u);
|
|
119
|
+
lctx.globalAlpha = PUFF_ALPHA * Math.min(1, u * 6) * (1 - u) ** 1.5;
|
|
120
|
+
lctx.drawImage(sprite, x - r, y - r, r * 2, r * 2);
|
|
121
|
+
}
|
|
122
|
+
ctx.globalAlpha = 1;
|
|
123
|
+
ctx.drawImage(lctx.canvas, 0, 0, size, size);
|
|
124
|
+
}
|
|
125
|
+
const QUARTER = Math.PI / 2;
|
|
126
|
+
/**
|
|
127
|
+
* Each piece moves like a critically damped spring pulled to its cell: it
|
|
128
|
+
* leaves at rest, speeds up, and eases in with no overshoot. An ease-out
|
|
129
|
+
* curve would start at full speed, which reads as a jolt at launch. The
|
|
130
|
+
* curve is scaled to land exactly at t = 1. Local because it has to run per
|
|
131
|
+
* piece on a canvas, where the shared motion tokens cannot.
|
|
132
|
+
*/
|
|
133
|
+
const OMEGA = 7;
|
|
134
|
+
const SETTLE_END = 1 - 8 * Math.exp(-7);
|
|
135
|
+
const settle = (t) => (1 - (1 + OMEGA * t) * Math.exp(-7 * t)) / SETTLE_END;
|
|
136
|
+
/** Speed of `settle` at t, 0 to 1, peaking at t = 1 / OMEGA. */
|
|
137
|
+
const speedAt = (t) => OMEGA * t * Math.exp(1 - OMEGA * t);
|
|
138
|
+
const DEFAULT_ORIGIN = {
|
|
139
|
+
swarm: {
|
|
140
|
+
x: .5,
|
|
141
|
+
y: 1
|
|
142
|
+
},
|
|
143
|
+
ripple: {
|
|
144
|
+
x: .5,
|
|
145
|
+
y: .5
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const clamp01 = (v) => v < 0 ? 0 : Math.min(v, 1);
|
|
149
|
+
function hash(n) {
|
|
150
|
+
let t = Math.imul(n ^ 0x9e3779b9, 0x85ebca6b);
|
|
151
|
+
t ^= t >>> 13;
|
|
152
|
+
t = Math.imul(t, 0xc2b2ae35);
|
|
153
|
+
return ((t ^ t >>> 16) >>> 0) / 4294967296;
|
|
154
|
+
}
|
|
155
|
+
function isEye(x, y, n) {
|
|
156
|
+
return x < 7 && y < 7 || x >= n - 7 && y < 7 || x < 7 && y >= n - 7;
|
|
157
|
+
}
|
|
158
|
+
function buildLayout(value, size, origin) {
|
|
159
|
+
const { data, size: n } = encode(value || " ", {
|
|
160
|
+
ecc: "M",
|
|
161
|
+
border: 0
|
|
162
|
+
});
|
|
163
|
+
const cell = Math.max(2, Math.floor(size / (n + 4)));
|
|
164
|
+
const gap = Math.max(1, Math.round(cell * .12));
|
|
165
|
+
const dot = cell - gap;
|
|
166
|
+
const start = Math.round((size - n * cell) / 2);
|
|
167
|
+
const ox = origin.x * size;
|
|
168
|
+
const oy = origin.y * size;
|
|
169
|
+
const pieces = [];
|
|
170
|
+
const add = (eye, x, y, side, seed) => {
|
|
171
|
+
pieces.push({
|
|
172
|
+
eye,
|
|
173
|
+
x,
|
|
174
|
+
y,
|
|
175
|
+
side,
|
|
176
|
+
d: Math.hypot(x + side / 2 - ox, y + side / 2 - oy),
|
|
177
|
+
r: hash(seed)
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
const eyeSide = cell * 7 - gap;
|
|
181
|
+
const far = start + (n - 7) * cell;
|
|
182
|
+
add(true, start, start, eyeSide, -1);
|
|
183
|
+
add(true, far, start, eyeSide, -2);
|
|
184
|
+
add(true, start, far, eyeSide, -3);
|
|
185
|
+
data.forEach((row, y) => {
|
|
186
|
+
row.forEach((dark, x) => {
|
|
187
|
+
if (dark && !isEye(x, y, n)) add(false, start + x * cell, start + y * cell, dot, y * n + x);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
const reach = Math.max(1, ...pieces.map((p) => p.d));
|
|
191
|
+
for (const p of pieces) p.d /= reach;
|
|
192
|
+
return {
|
|
193
|
+
cell,
|
|
194
|
+
dot,
|
|
195
|
+
radius: dot * .32,
|
|
196
|
+
pieces,
|
|
197
|
+
reach,
|
|
198
|
+
ox,
|
|
199
|
+
oy,
|
|
200
|
+
size
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** A finder eye: a rounded ring and a rounded core, radii concentric. */
|
|
204
|
+
function drawEye(ctx, x, y, side, cell, radius) {
|
|
205
|
+
const r = cell * 2;
|
|
206
|
+
ctx.beginPath();
|
|
207
|
+
ctx.roundRect(x, y, side, side, r);
|
|
208
|
+
ctx.roundRect(x + cell, y + cell, side - cell * 2, side - cell * 2, r - cell);
|
|
209
|
+
ctx.fill("evenodd");
|
|
210
|
+
ctx.beginPath();
|
|
211
|
+
ctx.roundRect(x + cell * 2, y + cell * 2, side - cell * 4, side - cell * 4, Math.max(radius, r - cell * 2));
|
|
212
|
+
ctx.fill();
|
|
213
|
+
}
|
|
214
|
+
function pieceStart(p, variant, size) {
|
|
215
|
+
if (variant === "scan") return clamp01((p.y + p.side / 2) / size) * SPREAD;
|
|
216
|
+
if (variant === "smoke") return (1 - clamp01((p.y + p.side / 2) / size)) * 530 + p.r * JITTER;
|
|
217
|
+
if (variant === "ripple") return p.d * SPREAD;
|
|
218
|
+
return p.d * 530 + p.r * JITTER;
|
|
219
|
+
}
|
|
220
|
+
function draw(ctx, layout, clock, variant, reduce, ink, paper) {
|
|
221
|
+
const { cell, dot, radius, pieces, reach, ox, oy, size } = layout;
|
|
222
|
+
ctx.globalAlpha = 1;
|
|
223
|
+
ctx.fillStyle = paper;
|
|
224
|
+
ctx.fillRect(0, 0, size, size);
|
|
225
|
+
ctx.fillStyle = ink;
|
|
226
|
+
if (reduce) {
|
|
227
|
+
ctx.globalAlpha = clock / TOTAL;
|
|
228
|
+
ctx.beginPath();
|
|
229
|
+
for (const p of pieces) if (!p.eye) ctx.roundRect(p.x, p.y, dot, dot, radius);
|
|
230
|
+
ctx.fill();
|
|
231
|
+
for (const p of pieces) if (p.eye) drawEye(ctx, p.x, p.y, p.side, cell, radius);
|
|
232
|
+
ctx.globalAlpha = 1;
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
ctx.beginPath();
|
|
236
|
+
for (const p of pieces) if (!p.eye && clock - pieceStart(p, variant, size) >= PIECE_IN) ctx.roundRect(p.x, p.y, dot, dot, radius);
|
|
237
|
+
ctx.fill();
|
|
238
|
+
for (const p of pieces) if (p.eye && clock - pieceStart(p, variant, size) >= PIECE_IN) drawEye(ctx, p.x, p.y, p.side, cell, radius);
|
|
239
|
+
const q = clock / SPREAD;
|
|
240
|
+
if (q > 0 && q < 1 && (variant === "ripple" || variant === "scan")) {
|
|
241
|
+
ctx.save();
|
|
242
|
+
const fade = Math.sin(Math.PI * q);
|
|
243
|
+
if (variant === "ripple") {
|
|
244
|
+
ctx.strokeStyle = ink;
|
|
245
|
+
ctx.lineWidth = 1.5;
|
|
246
|
+
ctx.globalAlpha = .22 * fade;
|
|
247
|
+
ctx.beginPath();
|
|
248
|
+
ctx.arc(ox, oy, q * reach, 0, Math.PI * 2);
|
|
249
|
+
ctx.stroke();
|
|
250
|
+
} else {
|
|
251
|
+
const y = q * size;
|
|
252
|
+
const trail = ctx.createLinearGradient(0, y - SCAN_TRAIL, 0, y);
|
|
253
|
+
trail.addColorStop(0, "transparent");
|
|
254
|
+
trail.addColorStop(1, ink);
|
|
255
|
+
ctx.globalAlpha = .08 * fade;
|
|
256
|
+
ctx.fillStyle = trail;
|
|
257
|
+
ctx.fillRect(0, y - SCAN_TRAIL, size, SCAN_TRAIL);
|
|
258
|
+
ctx.globalAlpha = .3 * fade;
|
|
259
|
+
ctx.fillStyle = ink;
|
|
260
|
+
ctx.fillRect(0, y - 1, size, 1.5);
|
|
261
|
+
}
|
|
262
|
+
ctx.restore();
|
|
263
|
+
}
|
|
264
|
+
for (const p of pieces) {
|
|
265
|
+
const t = (clock - pieceStart(p, variant, size)) / PIECE_IN;
|
|
266
|
+
if (t <= 0 || t >= 1) continue;
|
|
267
|
+
const k = settle(t);
|
|
268
|
+
const half = p.side / 2;
|
|
269
|
+
const cx = p.x + half;
|
|
270
|
+
const cy = p.y + half;
|
|
271
|
+
ctx.save();
|
|
272
|
+
if (variant === "ripple") {
|
|
273
|
+
ctx.globalAlpha = Math.min(1, t * 4);
|
|
274
|
+
ctx.translate(cx, cy);
|
|
275
|
+
if (p.eye) {
|
|
276
|
+
ctx.scale(k, k);
|
|
277
|
+
drawEye(ctx, -half, -half, p.side, cell, radius);
|
|
278
|
+
} else {
|
|
279
|
+
const s = dot * k;
|
|
280
|
+
ctx.beginPath();
|
|
281
|
+
ctx.roundRect(-s / 2, -s / 2, s, s, s / 2 + (radius - s / 2) * k);
|
|
282
|
+
ctx.fill();
|
|
283
|
+
}
|
|
284
|
+
} else if (variant === "smoke") {
|
|
285
|
+
ctx.globalAlpha = k ** 1.4;
|
|
286
|
+
ctx.translate(0, (1 - k) * cell * SMOKE_DRIFT);
|
|
287
|
+
if (p.eye) drawEye(ctx, p.x, p.y, p.side, cell, radius);
|
|
288
|
+
else {
|
|
289
|
+
ctx.beginPath();
|
|
290
|
+
ctx.roundRect(p.x, p.y, dot, dot, radius);
|
|
291
|
+
ctx.fill();
|
|
292
|
+
}
|
|
293
|
+
} else if (variant === "scan") {
|
|
294
|
+
ctx.globalAlpha = Math.min(1, t * 3);
|
|
295
|
+
ctx.translate(0, -(1 - k) * cell * DROP);
|
|
296
|
+
if (p.eye) drawEye(ctx, p.x, p.y, p.side, cell, radius);
|
|
297
|
+
else {
|
|
298
|
+
ctx.beginPath();
|
|
299
|
+
ctx.roundRect(p.x, p.y, dot, dot, radius);
|
|
300
|
+
ctx.fill();
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
const dx = cx - ox;
|
|
304
|
+
const dy = cy - oy;
|
|
305
|
+
const side = dx < 0 ? 1 : -1;
|
|
306
|
+
const bend = (BEND + BEND_SPREAD * p.r) * side;
|
|
307
|
+
const qx = ox + dx / 2 + dy * bend;
|
|
308
|
+
const qy = oy + dy / 2 - dx * bend;
|
|
309
|
+
const u = 1 - k;
|
|
310
|
+
const x = u * u * ox + 2 * u * k * qx + k * k * cx;
|
|
311
|
+
const y = u * u * oy + 2 * u * k * qy + k * k * cy;
|
|
312
|
+
const angle = Math.atan2(u * (qy - oy) + k * (cy - qy), u * (qx - ox) + k * (cx - qx));
|
|
313
|
+
const rest = Math.round(angle / QUARTER) * QUARTER;
|
|
314
|
+
const v = speedAt(t) * p.d;
|
|
315
|
+
const along = 1 + STRETCH * v * (p.eye ? EYE_STRETCH : 1);
|
|
316
|
+
const across = 1 / along;
|
|
317
|
+
ctx.globalAlpha = Math.min(1, t * 6);
|
|
318
|
+
ctx.translate(x, y);
|
|
319
|
+
ctx.rotate(rest + (angle - rest) * (1 - k) ** 2);
|
|
320
|
+
if (p.eye) {
|
|
321
|
+
ctx.scale(along, across);
|
|
322
|
+
drawEye(ctx, -half, -half, p.side, cell, radius);
|
|
323
|
+
} else {
|
|
324
|
+
const l = dot * along;
|
|
325
|
+
const w = dot * across;
|
|
326
|
+
ctx.beginPath();
|
|
327
|
+
ctx.roundRect(-l / 2, -w / 2, l, w, Math.min(w / 2, radius + (w / 2 - radius) * Math.min(1, v * 2)));
|
|
328
|
+
ctx.fill();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
ctx.restore();
|
|
332
|
+
}
|
|
333
|
+
if (variant === "smoke") drawSmoke(ctx, layout, clock, ink);
|
|
334
|
+
ctx.globalAlpha = 1;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* A QR code drawn on a canvas that builds itself piece by piece: the dots and
|
|
338
|
+
* the three finder eyes fly in on curved paths, pop in behind a spreading
|
|
339
|
+
* ring, or drop in behind a bar sweeping down. One reversible clock runs it,
|
|
340
|
+
* so hiding plays the build backwards and a press mid-run turns around from
|
|
341
|
+
* where it is.
|
|
342
|
+
*/
|
|
343
|
+
function AnimatedQrCode({ value, shown, variant = "swarm", size = 296, origin, ink = "#0a0a0a", paper = "#ffffff", onSettled, labels, className }) {
|
|
344
|
+
const t = useMessages("AnimatedQrCode", qrCodeMessages, labels);
|
|
345
|
+
const reduce = useReducedMotion() ?? false;
|
|
346
|
+
const canvasRef = useRef(null);
|
|
347
|
+
const ctxRef = useRef(null);
|
|
348
|
+
const clockRef = useRef(shown ? TOTAL : 0);
|
|
349
|
+
/** Clock ms per real ms, signed. Eased toward its goal on a turnaround. */
|
|
350
|
+
const rateRef = useRef(0);
|
|
351
|
+
const fallback = DEFAULT_ORIGIN[variant === "ripple" ? "ripple" : "swarm"];
|
|
352
|
+
const ox = origin?.x ?? fallback.x;
|
|
353
|
+
const oy = origin?.y ?? fallback.y;
|
|
354
|
+
const layout = useMemo(() => buildLayout(value, size, {
|
|
355
|
+
x: ox,
|
|
356
|
+
y: oy
|
|
357
|
+
}), [
|
|
358
|
+
value,
|
|
359
|
+
size,
|
|
360
|
+
ox,
|
|
361
|
+
oy
|
|
362
|
+
]);
|
|
363
|
+
const live = useRef({
|
|
364
|
+
layout,
|
|
365
|
+
variant,
|
|
366
|
+
reduce,
|
|
367
|
+
ink,
|
|
368
|
+
paper,
|
|
369
|
+
onSettled
|
|
370
|
+
});
|
|
371
|
+
useLayoutEffect(() => {
|
|
372
|
+
live.current = {
|
|
373
|
+
layout,
|
|
374
|
+
variant,
|
|
375
|
+
reduce,
|
|
376
|
+
ink,
|
|
377
|
+
paper,
|
|
378
|
+
onSettled
|
|
379
|
+
};
|
|
380
|
+
});
|
|
381
|
+
useLayoutEffect(() => {
|
|
382
|
+
const canvas = canvasRef.current;
|
|
383
|
+
if (!canvas) return;
|
|
384
|
+
const dpr = Math.max(1, window.devicePixelRatio || 1);
|
|
385
|
+
canvas.width = Math.round(size * dpr);
|
|
386
|
+
canvas.height = Math.round(size * dpr);
|
|
387
|
+
const ctx = canvas.getContext("2d");
|
|
388
|
+
if (!ctx) return;
|
|
389
|
+
ctx.scale(dpr, dpr);
|
|
390
|
+
ctxRef.current = ctx;
|
|
391
|
+
}, [size]);
|
|
392
|
+
useLayoutEffect(() => {
|
|
393
|
+
const ctx = ctxRef.current;
|
|
394
|
+
if (ctx) draw(ctx, layout, clockRef.current, variant, reduce, ink, paper);
|
|
395
|
+
}, [
|
|
396
|
+
layout,
|
|
397
|
+
variant,
|
|
398
|
+
reduce,
|
|
399
|
+
ink,
|
|
400
|
+
paper
|
|
401
|
+
]);
|
|
402
|
+
useEffect(() => {
|
|
403
|
+
const target = shown ? TOTAL : 0;
|
|
404
|
+
if (clockRef.current === target) return;
|
|
405
|
+
if (clockRef.current === 0 || clockRef.current === TOTAL) rateRef.current = shown ? 1 : -1.6;
|
|
406
|
+
let frame = 0;
|
|
407
|
+
let last = performance.now();
|
|
408
|
+
const tick = (now) => {
|
|
409
|
+
const dt = Math.min(250, now - last);
|
|
410
|
+
last = now;
|
|
411
|
+
const cur = live.current;
|
|
412
|
+
rateRef.current += ((shown ? 1 : -1.6) - rateRef.current) * (1 - Math.exp(-dt / TURN_MS));
|
|
413
|
+
const scale = cur.reduce ? TOTAL / REDUCED_MS : 1;
|
|
414
|
+
const next = Math.min(TOTAL, Math.max(0, clockRef.current + dt * rateRef.current * scale));
|
|
415
|
+
clockRef.current = next;
|
|
416
|
+
const ctx = ctxRef.current;
|
|
417
|
+
if (ctx) draw(ctx, cur.layout, next, cur.variant, cur.reduce, cur.ink, cur.paper);
|
|
418
|
+
if (next === target) {
|
|
419
|
+
cur.onSettled?.(shown);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
frame = requestAnimationFrame(tick);
|
|
423
|
+
};
|
|
424
|
+
frame = requestAnimationFrame(tick);
|
|
425
|
+
return () => cancelAnimationFrame(frame);
|
|
426
|
+
}, [shown]);
|
|
427
|
+
return /* @__PURE__ */ jsx("canvas", {
|
|
428
|
+
ref: canvasRef,
|
|
429
|
+
role: "img",
|
|
430
|
+
"aria-label": shown ? t("label", { value }) : void 0,
|
|
431
|
+
"aria-hidden": shown ? void 0 : true,
|
|
432
|
+
width: size,
|
|
433
|
+
height: size,
|
|
434
|
+
className: cn("ring-border aspect-square h-auto max-w-full rounded-2xl ring-1", className),
|
|
435
|
+
style: {
|
|
436
|
+
width: size,
|
|
437
|
+
backgroundColor: paper
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
export { AnimatedQrCode, qrCodeMessages };
|
|
442
|
+
|
|
443
|
+
//# sourceMappingURL=qr-code.js.map
|