fancy-ui-vue 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +9 -6
  2. package/dist/components/magnetic-field/MagnetPuck.vue.d.ts +51 -0
  3. package/dist/components/magnetic-field/MagnetPuck.vue.js +7 -0
  4. package/dist/components/magnetic-field/MagnetPuck.vue2.js +191 -0
  5. package/dist/components/magnetic-field/MagneticField.vue.d.ts +39 -0
  6. package/dist/components/magnetic-field/MagneticField.vue.js +7 -0
  7. package/dist/components/magnetic-field/MagneticField.vue2.js +157 -0
  8. package/dist/components/magnetic-field/MagneticItem.vue.d.ts +28 -0
  9. package/dist/components/magnetic-field/MagneticItem.vue.js +7 -0
  10. package/dist/components/magnetic-field/MagneticItem.vue2.js +72 -0
  11. package/dist/components/magnetic-field/index.d.ts +10 -0
  12. package/dist/components/magnetic-field/magnetic-field-core.d.ts +163 -0
  13. package/dist/components/magnetic-field/magnetic-field-core.js +534 -0
  14. package/dist/components/magnetic-field/magnetic-field-source.d.ts +58 -0
  15. package/dist/components/magnetic-field/magnetic-field-source.js +58 -0
  16. package/dist/components/magnetic-field/types.d.ts +14 -0
  17. package/dist/components/magnetic-field/types.js +5 -0
  18. package/dist/components/pixel-scene/PixelScene.vue.d.ts +60 -0
  19. package/dist/components/pixel-scene/PixelScene.vue.js +184 -0
  20. package/dist/components/pixel-scene/PixelScene.vue2.js +4 -0
  21. package/dist/components/pixel-scene/index.d.ts +4 -0
  22. package/dist/components/pixel-scene/pixel-scene-core.d.ts +256 -0
  23. package/dist/components/pixel-scene/pixel-scene-core.js +878 -0
  24. package/dist/components/pixel-scene/pixel-scene-hdr.d.ts +68 -0
  25. package/dist/components/pixel-scene/pixel-scene-hdr.js +312 -0
  26. package/dist/components/pixel-scene/pixel-scene-scenes.d.ts +31 -0
  27. package/dist/components/pixel-scene/pixel-scene-scenes.js +1074 -0
  28. package/dist/components/story-thread/StoryNode.vue.d.ts +11 -0
  29. package/dist/components/story-thread/StoryNode.vue.js +7 -0
  30. package/dist/components/story-thread/StoryNode.vue2.js +23 -0
  31. package/dist/components/story-thread/StoryThread.vue.d.ts +56 -0
  32. package/dist/components/story-thread/StoryThread.vue.js +7 -0
  33. package/dist/components/story-thread/StoryThread.vue2.js +103 -0
  34. package/dist/components/story-thread/index.d.ts +5 -0
  35. package/dist/components/story-thread/story-thread-core.d.ts +119 -0
  36. package/dist/components/story-thread/story-thread-core.js +491 -0
  37. package/dist/components/story-thread/types.d.ts +1 -0
  38. package/dist/components/sun-switch/SunSwitch.vue.d.ts +61 -0
  39. package/dist/components/sun-switch/SunSwitch.vue.js +7 -0
  40. package/dist/components/sun-switch/SunSwitch.vue2.js +559 -0
  41. package/dist/components/sun-switch/index.d.ts +4 -0
  42. package/dist/components/sun-switch/pixel-wave-core.d.ts +82 -0
  43. package/dist/components/sun-switch/pixel-wave-core.js +508 -0
  44. package/dist/components/sun-switch/sun-switch-core.d.ts +251 -0
  45. package/dist/components/sun-switch/sun-switch-core.js +546 -0
  46. package/dist/components/sun-switch/sun-switch-hdr.d.ts +70 -0
  47. package/dist/components/sun-switch/sun-switch-hdr.js +311 -0
  48. package/dist/components/tracing-beam/TracingBeam.vue.d.ts +20 -1
  49. package/dist/components/tracing-beam/TracingBeam.vue.js +5 -164
  50. package/dist/components/tracing-beam/TracingBeam.vue2.js +168 -1
  51. package/dist/index.d.ts +4 -0
  52. package/dist/index.js +190 -164
  53. package/dist/styles.css +499 -0
  54. package/package.json +1 -1
package/README.md CHANGED
@@ -10,7 +10,7 @@ Animated UI components for **Vue 3.5+**, styled with Tailwind CSS v4 — the
10
10
  ![Vue](https://img.shields.io/badge/Vue-3.5+-42B883?logo=vuedotjs&logoColor=white)
11
11
  ![Tailwind CSS](https://img.shields.io/badge/Tailwind_CSS-4-06B6D4?logo=tailwindcss&logoColor=white)
12
12
  ![TypeScript](https://img.shields.io/badge/TypeScript-5-3178C6?logo=typescript&logoColor=white)
13
- ![Components](https://img.shields.io/badge/Components-151-8B5CF6)
13
+ ![Components](https://img.shields.io/badge/Components-155-8B5CF6)
14
14
  ![MIT License](https://img.shields.io/badge/License-MIT-green)
15
15
 
16
16
  <p align="center">
@@ -40,10 +40,10 @@ Animated UI components for **Vue 3.5+**, styled with Tailwind CSS v4 &mdash; the
40
40
 
41
41
  ## Features
42
42
 
43
- - **151 components** &mdash; core primitives (forms, navigation, overlays) alongside buttons, text animations, backgrounds, cursors, AI/chat building blocks and a micro-interactions collection
43
+ - **155 components** &mdash; core primitives (forms, navigation, overlays) alongside buttons, text animations, backgrounds, cursors, AI/chat building blocks and a micro-interactions collection
44
44
  - **Motion that feels physical** &mdash; beams of light, liquid-metal and neon borders, a physical flip card, a before/after slider with a motion trail, a datamosh page transition; springs and WebGL where they earn their keep
45
45
  - **Idiomatic Vue 3.5** &mdash; `<script setup>` single-file components, reactive props destructuring, `defineModel` for every bindable (`v-model:<name>`), snippets as named and scoped slots, `defineExpose` wherever the Svelte source exposes a `ref`; every other prop keeps its Svelte name
46
- - **Same components, three frameworks** &mdash; All 151 components of `fancy-ui-svelte` are ported, under the same names and with the same visual contract; the [Svelte package](https://github.com/RamaHerbin/fancy-ui#readme) is the reference, [`fancy-ui-react`](https://github.com/RamaHerbin/fancy-ui/tree/main/react#readme) the React edition, and parity is checked in CI
46
+ - **Same components, three frameworks** &mdash; All 155 components of `fancy-ui-svelte` are ported, under the same names and with the same visual contract; the [Svelte package](https://github.com/RamaHerbin/fancy-ui#readme) is the reference, [`fancy-ui-react`](https://github.com/RamaHerbin/fancy-ui/tree/main/react#readme) the React edition, and parity is checked in CI
47
47
  - **Tailwind CSS v4** &mdash; one CSS import, semantic colour tokens, light and dark themes that follow the OS or a `.dark` class
48
48
  - **Accessible and SSR-safe** &mdash; keyboard support where it applies, `prefers-reduced-motion` respected, a `seed` prop wherever the source randomises in render so server and client agree, clean hydration under Nuxt, canvas and WebGL work deferred to mount
49
49
  - **Opt-in sound** &mdash; eleven synthesised interface cues, a `SoundToggle` switch and the `useSound` / `useSoundFeedback` composables; silent until the user turns it on
@@ -153,6 +153,10 @@ Out of the box the package follows the operating-system preference: `dark:` util
153
153
 
154
154
  `tailwind.css` is what makes that work, in three parts: it declares the `.dark` token block, it declares a `dark` variant that matches a `.dark` ancestor OR the media query (unless a `.light` ancestor opts out), and it sets `color-scheme: light dark` on `:root` with `.dark` / `.light` overrides so the components' `light-dark()` colours &mdash; and the browser's own form controls, scrollbars and caret &mdash; resolve the same way. An app that declares its own `@custom-variant dark` after the import keeps its own definition.
155
155
 
156
+ ### Nuxt
157
+
158
+ The setup above works as-is in Nuxt (add `@tailwindcss/vite` to `vite.plugins`). A Nuxt module, [`fancy-ui-nuxt`](https://github.com/RamaHerbin/fancy-ui/tree/main/nuxt#readme), auto-imports every component as `<Fancy…>`, adds `styles.css` and auto-imports the sound composables; it lives in this repo and is not yet published to npm.
159
+
156
160
  ### Server rendering
157
161
 
158
162
  The package is written for SSR: the `examples/nuxt-app` consumer in this repo is generated in CI with `failOnError` on, so a component that breaks server rendering or hydration fails the build. Three rules follow from that and are worth knowing:
@@ -282,7 +286,7 @@ Components are named by their exported Vue name.
282
286
  ### Package-level rules
283
287
 
284
288
  - **props**: `<Name>Props` hold the component's own props only, never a `ButtonHTMLAttributes`-style intersection or Svelte's `Omit<HTMLAttributes<…>, …>` fold-in, so native attributes are untyped. Every component sets `inheritAttrs: false` and writes `v-bind="attrs"` only where the Svelte source spreads `{...restProps}`, at the same position, so attributes the component sets after it (`data-state`, `data-position`, `data-panel-side`) still win.
285
- - These components forward native attributes and listeners (rules in [PORTING.md](https://github.com/RamaHerbin/fancy-ui/blob/main/vue/PORTING.md#native-attributes)): Autocomplete, BentoGrid, BentoGridCard, BentoGridItem, Book, BookDescription, BookHeader, BookTitle, BoxReveal, Button, Checkbox, Combobox, ComposerInput, ComposerModelPicker, ComposerSubmit, ConfettiButton, ContainerTextFlip, CopyButton, DatamoshTransition, DatePicker, DimSiblings, DropdownMenuItem, DropdownMenuSubTrigger, DropdownMenuTrigger, FileUpload, GradientButton, IconButton, InlineCitation, Input, InteractiveHoverButton, LetterPullup, LineHoverLink, Link, Magnetic (outer wrapper), MosaicGlow, NavbarLink, NavigationMenuLink, NavigationMenuTrigger, NeonBorder, NumberInput, PasswordInput, PixelLoader, Popover, Presence, Pressable, PulseBeam, RadioGroup, RadioGroupItem, RainbowButton, Reveal, RippleButton, ScrollProgress, SearchInput, Select, ShimmerButton, Skeleton, Slider, SourcesTrigger, StatusMorph, StickyScroll, Switch, TabsTrigger, TerminalBlock, Textarea, TextRoll, TimePicker, Toggle, ToggleGroupItem, TypingIndicator. Button, CopyButton and IconButton land them on the `<button>` (Button and IconButton on the `<a>` once `href` is set). Capture-phase listeners (`@click.capture`) are stripped while Button or IconButton is disabled or loading; the Svelte and React ports do not guard capture-phase listeners. Targets: Input, Textarea, PasswordInput, SearchInput and NumberInput → inner `<input>` / `<textarea>`; Link, LineHoverLink, NavbarLink, NavigationMenuLink and InlineCitation → their anchor (InlineCitation's marker is a `<button>` when unlinked), where the managed `aria-current`, `aria-disabled`, `tabindex`, `target`, `rel` and label win while they apply; Book, BookHeader, BookTitle and BookDescription → their own element; the other display components (BoxReveal, BentoGrid, BentoGridItem, BentoGridCard, ContainerTextFlip, LetterPullup, NeonBorder, PixelLoader, TerminalBlock, TypingIndicator) → their root, where managed `role`, `aria-live` and `data-state` win and a consumer `style` merges; Checkbox, Switch, Slider, RadioGroup, RadioGroupItem and FileUpload → their native input or group, where `@change` / `@input` are declared camelCase `onChange` (Slider also `onInput`); Select, Combobox, Autocomplete, DatePicker and TimePicker → trigger or input, with the component's invariants merged after the attributes. Triggers and items: DropdownMenuTrigger, DropdownMenuItem, DropdownMenuSubTrigger, TabsTrigger, NavigationMenuTrigger, SourcesTrigger, Toggle, ToggleGroupItem, Popover (trigger button; `class` and `ref` still target the panel) and ComposerSubmit and ComposerModelPicker → their button, ComposerInput → textarea; they declare camelCase `onClick`, `onKeydown`, `onFocus`, `onMouseenter` and `onMouseleave` (skipped while disabled), and managed `role`, `type`, `aria-expanded`, `aria-controls`, `aria-selected`, `aria-pressed` and roving `tabindex` win. A consumer `style` merges with the component's own custom properties (`mergeProps`) instead of overwriting them the way a later `{...restProps}` would.
289
+ - These components forward native attributes and listeners (rules in [PORTING.md](https://github.com/RamaHerbin/fancy-ui/blob/main/vue/PORTING.md#native-attributes)): Autocomplete, BentoGrid, BentoGridCard, BentoGridItem, Book, BookDescription, BookHeader, BookTitle, BoxReveal, Button, Checkbox, Combobox, ComposerInput, ComposerModelPicker, ComposerSubmit, ConfettiButton, ContainerTextFlip, CopyButton, DatamoshTransition, DatePicker, DimSiblings, DropdownMenuItem, DropdownMenuSubTrigger, DropdownMenuTrigger, FileUpload, GradientButton, IconButton, InlineCitation, Input, InteractiveHoverButton, LetterPullup, LineHoverLink, Link, MagnetPuck, Magnetic (outer wrapper), MagneticField, MagneticItem (outer wrapper), MosaicGlow, NavbarLink, NavigationMenuLink, NavigationMenuTrigger, NeonBorder, NumberInput, PasswordInput, PixelLoader, Popover, Presence, Pressable, PulseBeam, RadioGroup, RadioGroupItem, RainbowButton, Reveal, RippleButton, ScrollProgress, SearchInput, Select, ShimmerButton, Skeleton, Slider, SourcesTrigger, StatusMorph, StickyScroll, Switch, TabsTrigger, TerminalBlock, Textarea, TextRoll, TimePicker, Toggle, ToggleGroupItem, TypingIndicator. Button, CopyButton and IconButton land them on the `<button>` (Button and IconButton on the `<a>` once `href` is set). Capture-phase listeners (`@click.capture`) are stripped while Button or IconButton is disabled or loading; the Svelte and React ports do not guard capture-phase listeners. Targets: Input, Textarea, PasswordInput, SearchInput and NumberInput → inner `<input>` / `<textarea>`; Link, LineHoverLink, NavbarLink, NavigationMenuLink and InlineCitation → their anchor (InlineCitation's marker is a `<button>` when unlinked), where the managed `aria-current`, `aria-disabled`, `tabindex`, `target`, `rel` and label win while they apply; Book, BookHeader, BookTitle and BookDescription → their own element; the other display components (BoxReveal, BentoGrid, BentoGridItem, BentoGridCard, ContainerTextFlip, LetterPullup, NeonBorder, PixelLoader, TerminalBlock, TypingIndicator) → their root, where managed `role`, `aria-live` and `data-state` win and a consumer `style` merges; Checkbox, Switch, Slider, RadioGroup, RadioGroupItem and FileUpload → their native input or group, where `@change` / `@input` are declared camelCase `onChange` (Slider also `onInput`); Select, Combobox, Autocomplete, DatePicker and TimePicker → trigger or input, with the component's invariants merged after the attributes. Triggers and items: DropdownMenuTrigger, DropdownMenuItem, DropdownMenuSubTrigger, TabsTrigger, NavigationMenuTrigger, SourcesTrigger, Toggle, ToggleGroupItem, Popover (trigger button; `class` and `ref` still target the panel) and ComposerSubmit and ComposerModelPicker → their button, ComposerInput → textarea; they declare camelCase `onClick`, `onKeydown`, `onFocus`, `onMouseenter` and `onMouseleave` (skipped while disabled), and managed `role`, `type`, `aria-expanded`, `aria-controls`, `aria-selected`, `aria-pressed` and roving `tabindex` win. A consumer `style` merges with the component's own custom properties (`mergeProps`) instead of overwriting them the way a later `{...restProps}` would.
286
290
  - Every component not listed above is closed, exactly as in Svelte: an `id`, `data-*`, `aria-*` or `@click` put on it is dropped silently (`<Dialog id="x" data-foo="bar">` renders neither), which differs from Vue's default fallthrough.
287
291
  - **boolean props**: a DOM attribute the component reads is a declared Boolean prop rather than a value read off `$attrs`, so a bare `<RippleButton disabled>` is `true`, not the falsy string `""` that would let the sound cue play: `disabled` on GradientButton, InteractiveHoverButton, RippleButton, ShimmerButton. Vue's Boolean casting applies to every Boolean prop: `<ChatMessageAction active="">` is `true` where Svelte renders `aria-pressed=""` (`active` keeps three states through an explicit `undefined` default), and ReasoningPanel's bare `open` is `true`.
288
292
  - **class**: `class` is a declared prop typed `HTMLAttributes["class"]` (string, array or object) rather than `string`, merged once by `cn()` at the Svelte call site and argument position and never doubled through `$attrs`. Exceptions: ReviewCard (Marquee) declares no `class`, as in Svelte, so a `class` on it is dropped, and the renderless roots ContextMenu, DropdownMenu and DropdownMenuSub have none; LiquidGlass keeps `containerClass` a `string`; FrostedGlass's `class` still targets the content layer and `containerClass` the outer container.
@@ -336,7 +340,7 @@ Components are named by their exported Vue name.
336
340
  - **composables**: composables expose no `destroy()`; cleanup runs through `onScopeDispose`. Focus-trap composables return a handle (`returnFocusNow` / `rearm`) instead of imperative action methods. Media-query and similar composables keep an explicit `start` / `stop` pair and accept getter-shaped options, as the Svelte actions do.
337
341
  - **hydration**: sound preferences hydrate explicitly in `onMounted` (`hydrateSound()`) rather than reading `localStorage` during setup, because Vue's production hydration does not patch an attribute mismatch introduced by an eagerly read client-only preference.
338
342
  - **vue floor**: Vue 3.5 is the floor, not just the minimum peer range: the port relies on reactive props destructuring, `useTemplateRef`, `onWatcherCleanup` and `<Teleport defer>`.
339
- - **upstream fixes**: a handful of proven bugs surfaced while porting `fancy-ui-react` were fixed on the Svelte source itself, and the Vue port inherits those fixes. The review of the Vue port surfaced more, fixed here first with Svelte parity pending (each listed under its component below): animated-testimonials, animated-tooltip, autocomplete, compare, confetti, copy-button, focus, inline-citation, number-input, rainbow-button, select, text-generate-effect, tooltip, tracing-beam.
343
+ - **upstream fixes**: a handful of proven bugs surfaced while porting `fancy-ui-react` were fixed on the Svelte source itself, and the Vue port inherits those fixes. The review of the Vue port surfaced more, fixed here first with Svelte parity pending (each listed under its component below): animated-testimonials, animated-tooltip, autocomplete, compare, confetti, copy-button, focus, inline-citation, number-input, rainbow-button, select, text-generate-effect, tooltip.
340
344
  - **not listed**: implementation-only differences with no consumer surface (template duplication, style-object plumbing, internal helper types, test-fixture transpositions) are not recorded here. A component without a bullet below differs from Svelte only through the rules above.
341
345
 
342
346
  ### Per component
@@ -398,7 +402,6 @@ Components are named by their exported Vue name.
398
402
  - **toast**: The entrance and exit move from `<Toast>` to `<Toaster>`: a `<Toast>` rendered directly by a consumer paints at rest and no longer animates itself in or out. Through `<Toaster>` the motion is unchanged — same preset, 300ms/8px arrival, 200ms/4px departure, same reduced-motion collapse (parity with the React port).
399
403
  - **tool-call**: The auto-open for a failure is keyed on the `call.status` VALUE, not on the `call` object identity: handing the card a fresh `call` object whose status is still `"error"` does not re-fire the auto-open. Observable only when a consumer drives `open` from outside AND re-creates the `call` object (same as the React port).
400
404
  - **tooltip**: the tooltip appends its id to the trigger's existing `aria-describedby` list and removes only that id on close, instead of overwriting the attribute and then deleting it; it also rewires its listeners and `aria-describedby` onto a replacement trigger when the slot swaps its first element (upstream fixes, Svelte parity pending).
401
- - **tracing-beam**: each instance uses its own generated gradient id (`useFancyId()`) for the gradient and its stroke reference, so two beams on one page no longer share one spring-animated gradient (upstream fix, Svelte parity pending).
402
405
 
403
406
  ## Tech Stack
404
407
 
@@ -0,0 +1,51 @@
1
+ import type { HTMLAttributes } from "vue";
2
+ import type { MagneticPoint } from "./magnetic-field-core.js";
3
+ /**
4
+ * The puck's centre is the `position` model (`v-model:position`): in px,
5
+ * relative to its positioned parent (the field's padding box when it sits
6
+ * inside a `MagneticField`, where the field must be that parent: no
7
+ * positioned element in between). Dragging and the arrow keys update it.
8
+ */
9
+ export interface MagnetPuckProps {
10
+ /** Called with each new position while the puck is dragged or moved with the keyboard. */
11
+ onPositionChange?: (position: MagneticPoint) => void;
12
+ /** Diameter in px. */
13
+ size?: number;
14
+ /**
15
+ * Whether the puck keeps attracting once released. By default it attracts
16
+ * only while held, and the items spring back when it is let go.
17
+ */
18
+ sticky?: boolean;
19
+ /**
20
+ * Accessible name. The puck is also described by a built-in hint naming
21
+ * its keys; pass `aria-describedby` to replace it.
22
+ */
23
+ label?: string;
24
+ /** Called when the puck is picked up (pointer down, or Space/Enter) and put down. */
25
+ onHeldChange?: (held: boolean) => void;
26
+ /** Additional CSS classes. */
27
+ class?: HTMLAttributes["class"];
28
+ }
29
+ declare const _default: typeof __VLS_export;
30
+ export default _default;
31
+ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<MagnetPuckProps & {
32
+ /** The puck's centre, px. */
33
+ position?: MagneticPoint;
34
+ }, {
35
+ ref: Readonly<import("vue").ShallowRef<HTMLDivElement | null>>;
36
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
37
+ "update:position": (value: MagneticPoint) => any;
38
+ }, string, import("vue").PublicProps, Readonly<MagnetPuckProps & {
39
+ /** The puck's centre, px. */
40
+ position?: MagneticPoint;
41
+ }> & Readonly<{
42
+ "onUpdate:position"?: ((value: MagneticPoint) => any) | undefined;
43
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
44
+ /** A custom face. Leave it out for the default black disc. */
45
+ default?(): unknown;
46
+ }>;
47
+ type __VLS_WithSlots<T, S> = T & {
48
+ new (): {
49
+ $slots: S;
50
+ };
51
+ };
@@ -0,0 +1,7 @@
1
+ import _sfc_main from "./MagnetPuck.vue2.js";
2
+ /* empty css */
3
+ import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
4
+ const MagnetPuck = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-23664b5a"]]);
5
+ export {
6
+ MagnetPuck as default
7
+ };
@@ -0,0 +1,191 @@
1
+ import { defineComponent, mergeModels, useAttrs, useModel, useTemplateRef, ref, computed, onMounted, watch, onBeforeUnmount, createElementBlock, openBlock, mergeProps, unref, renderSlot, createElementVNode, toDisplayString } from "vue";
2
+ import { cn } from "../../utils.js";
3
+ import { useFancyId } from "../../internals/use-id.js";
4
+ import { MAGNETIC_FIELD_KEY } from "./types.js";
5
+ const _hoisted_1 = ["aria-label", "aria-describedby", "aria-pressed", "data-held"];
6
+ const _sfc_main = /* @__PURE__ */ defineComponent({
7
+ ...{ name: "MagnetPuck", inheritAttrs: false },
8
+ __name: "MagnetPuck",
9
+ props: /* @__PURE__ */ mergeModels({
10
+ onPositionChange: { type: Function },
11
+ size: { default: 40 },
12
+ sticky: { type: Boolean, default: false },
13
+ label: { default: "Magnet" },
14
+ onHeldChange: { type: Function },
15
+ class: { type: [Boolean, null, String, Object, Array] }
16
+ }, {
17
+ "position": { default: () => ({ x: 48, y: 48 }) },
18
+ "positionModifiers": {}
19
+ }),
20
+ emits: ["update:position"],
21
+ setup(__props, { expose: __expose }) {
22
+ const KEY_HINT = "Space or Enter picks it up and puts it down; the arrow keys move it.";
23
+ const KEY_STEP = 8;
24
+ const KEY_STEP_LARGE = 32;
25
+ const attrs = useAttrs();
26
+ const hintId = `${useFancyId()}-hint`;
27
+ const position = useModel(__props, "position");
28
+ const el = useTemplateRef("el");
29
+ __expose({ ref: el });
30
+ const ctx = MAGNETIC_FIELD_KEY.useOptional();
31
+ const holder = ref(null);
32
+ const held = computed(() => holder.value !== null);
33
+ let activePointerId = null;
34
+ let dragStartX = 0;
35
+ let dragStartY = 0;
36
+ let dragOrigin = { x: 0, y: 0 };
37
+ const puckStyle = computed(() => ({
38
+ width: `${__props.size}px`,
39
+ height: `${__props.size}px`,
40
+ transform: `translate3d(${position.value.x - __props.size / 2}px, ${position.value.y - __props.size / 2}px, 0)`
41
+ }));
42
+ function setHolder(next) {
43
+ const was = holder.value !== null;
44
+ holder.value = next;
45
+ if (was !== (next !== null)) __props.onHeldChange?.(next !== null);
46
+ }
47
+ function clampToParent(p) {
48
+ const node = el.value;
49
+ const parent = node?.offsetParent ?? node?.parentElement ?? null;
50
+ if (!parent) return p;
51
+ const half = __props.size / 2;
52
+ const w = parent.clientWidth;
53
+ const h = parent.clientHeight;
54
+ return {
55
+ x: w > 0 ? Math.min(Math.max(p.x, half), Math.max(half, w - half)) : p.x,
56
+ y: h > 0 ? Math.min(Math.max(p.y, half), Math.max(half, h - half)) : p.y
57
+ };
58
+ }
59
+ function moveTo(p) {
60
+ const next = clampToParent(p);
61
+ if (next.x === position.value.x && next.y === position.value.y) return;
62
+ position.value = next;
63
+ __props.onPositionChange?.(next);
64
+ }
65
+ function releasePointer() {
66
+ if (activePointerId === null) return;
67
+ const id = activePointerId;
68
+ activePointerId = null;
69
+ el.value?.releasePointerCapture?.(id);
70
+ }
71
+ function release() {
72
+ releasePointer();
73
+ setHolder(null);
74
+ }
75
+ function handlePointerDown(event) {
76
+ if (event.pointerType === "mouse" && event.button !== 0) return;
77
+ if (activePointerId !== null) return;
78
+ activePointerId = event.pointerId;
79
+ dragStartX = event.clientX;
80
+ dragStartY = event.clientY;
81
+ dragOrigin = { x: position.value.x, y: position.value.y };
82
+ el.value?.setPointerCapture?.(event.pointerId);
83
+ setHolder("pointer");
84
+ }
85
+ function handlePointerMove(event) {
86
+ if (event.pointerId !== activePointerId) return;
87
+ moveTo({
88
+ x: dragOrigin.x + event.clientX - dragStartX,
89
+ y: dragOrigin.y + event.clientY - dragStartY
90
+ });
91
+ }
92
+ function handlePointerEnd(event) {
93
+ if (event.pointerId !== activePointerId) return;
94
+ release();
95
+ }
96
+ function handleKeyDown(event) {
97
+ const step = event.shiftKey ? KEY_STEP_LARGE : KEY_STEP;
98
+ let dx = 0;
99
+ let dy = 0;
100
+ switch (event.key) {
101
+ case "ArrowLeft":
102
+ dx = -step;
103
+ break;
104
+ case "ArrowRight":
105
+ dx = step;
106
+ break;
107
+ case "ArrowUp":
108
+ dy = -step;
109
+ break;
110
+ case "ArrowDown":
111
+ dy = step;
112
+ break;
113
+ case " ":
114
+ case "Enter":
115
+ event.preventDefault();
116
+ if (event.repeat) return;
117
+ if (held.value) release();
118
+ else setHolder("keyboard");
119
+ return;
120
+ case "Escape":
121
+ if (!held.value) return;
122
+ event.preventDefault();
123
+ release();
124
+ return;
125
+ default:
126
+ return;
127
+ }
128
+ event.preventDefault();
129
+ moveTo({ x: position.value.x + dx, y: position.value.y + dy });
130
+ }
131
+ function handleBlur() {
132
+ if (holder.value === "keyboard") release();
133
+ }
134
+ function syncSource() {
135
+ if (!ctx) return;
136
+ const { x, y } = position.value;
137
+ ctx.setSource(held.value || __props.sticky ? { x, y } : null, "puck");
138
+ }
139
+ onMounted(syncSource);
140
+ watch([() => position.value.x, () => position.value.y, held, () => __props.sticky], syncSource, {
141
+ flush: "post"
142
+ });
143
+ watch(
144
+ held,
145
+ (isHeld, _old, onCleanup) => {
146
+ if (!isHeld) return;
147
+ const onBlur = () => release();
148
+ window.addEventListener("blur", onBlur);
149
+ onCleanup(() => window.removeEventListener("blur", onBlur));
150
+ },
151
+ { flush: "post" }
152
+ );
153
+ onBeforeUnmount(() => ctx?.setSource(null, "puck"));
154
+ return (_ctx, _cache) => {
155
+ return openBlock(), createElementBlock("div", mergeProps({
156
+ ref_key: "el",
157
+ ref: el,
158
+ onPointerdown: handlePointerDown,
159
+ onPointermove: handlePointerMove,
160
+ onPointerup: handlePointerEnd,
161
+ onPointercancel: handlePointerEnd,
162
+ onLostpointercapture: handlePointerEnd,
163
+ onKeydown: handleKeyDown,
164
+ onBlur: handleBlur
165
+ }, unref(attrs), {
166
+ class: unref(cn)("ft-magnet-puck", __props.class),
167
+ role: "button",
168
+ tabindex: "0",
169
+ "aria-label": __props.label,
170
+ "aria-describedby": unref(attrs)["aria-describedby"] ?? hintId,
171
+ "aria-pressed": held.value ? "true" : "false",
172
+ "data-held": held.value || void 0,
173
+ style: puckStyle.value
174
+ }), [
175
+ renderSlot(_ctx.$slots, "default", {}, () => [
176
+ _cache[0] || (_cache[0] = createElementVNode("span", {
177
+ class: "ft-magnet-puck-face",
178
+ "aria-hidden": "true"
179
+ }, null, -1))
180
+ ], true),
181
+ createElementVNode("span", {
182
+ id: hintId,
183
+ class: "ft-magnet-puck-hint"
184
+ }, toDisplayString(KEY_HINT))
185
+ ], 16, _hoisted_1);
186
+ };
187
+ }
188
+ });
189
+ export {
190
+ _sfc_main as default
191
+ };
@@ -0,0 +1,39 @@
1
+ import type { HTMLAttributes } from "vue";
2
+ import type { MagneticFieldSource, MagneticPoint, MagneticSpring, MagneticSpringPreset } from "./magnetic-field-core.js";
3
+ export interface MagneticFieldProps {
4
+ /** Where the magnet comes from. `"pointer"` follows a mouse or pen anywhere within `radius` of an item (touch is ignored); `"manual"` reads `position` instead. A `MagnetPuck` placed inside the field drives it in either mode while it is held. */
5
+ source?: MagneticFieldSource;
6
+ /** The magnet's position in px, relative to the field's padding box, used when `source` is `"manual"`. `null` means no magnet, and the items spring back to rest. */
7
+ position?: MagneticPoint | null;
8
+ /** Falloff distance from the item's edge, in px: an item pulls hardest when the magnet touches or overlaps it, and not at all once the magnet is `radius` px beyond its nearest edge. */
9
+ radius?: number;
10
+ /** Global pull multiplier, applied on top of each item's own `strength`. `0` turns the effect off without detaching anything. */
11
+ strength?: number;
12
+ /** Largest distance, in px, that any item travels toward the magnet. */
13
+ maxTranslate?: number;
14
+ /** Largest lean, in degrees. Items lean toward the magnet's side like a crowd turning its head: clockwise when it is to their left, counter-clockwise when it is to their right. */
15
+ maxRotate?: number;
16
+ /** How items move and settle: `"soft"`, `"default"` or `"snappy"`, or your own `{ stiffness, damping, mass }` (missing keys come from `"default"`). */
17
+ spring?: MagneticSpringPreset | Partial<MagneticSpring>;
18
+ /** `1` attracts and `-1` repels. Only translation flips; the lean stays the same. */
19
+ polarity?: 1 | -1;
20
+ /** Detaches every listener and springs each item back to rest. */
21
+ disabled?: boolean;
22
+ /** Called when the field wakes up (a magnet is engaged or an item is still settling) and when it goes back to sleep. */
23
+ onActiveChange?: (active: boolean) => void;
24
+ /** Additional CSS classes. */
25
+ class?: HTMLAttributes["class"];
26
+ }
27
+ declare const _default: typeof __VLS_export;
28
+ export default _default;
29
+ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<MagneticFieldProps, {
30
+ ref: Readonly<import("vue").ShallowRef<HTMLDivElement | null>>;
31
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<MagneticFieldProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
32
+ /** The content. Wrap each element that should react in a `MagneticItem`. */
33
+ default?(): unknown;
34
+ }>;
35
+ type __VLS_WithSlots<T, S> = T & {
36
+ new (): {
37
+ $slots: S;
38
+ };
39
+ };
@@ -0,0 +1,7 @@
1
+ import _sfc_main from "./MagneticField.vue2.js";
2
+ /* empty css */
3
+ import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
4
+ const MagneticField = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-f13a642d"]]);
5
+ export {
6
+ MagneticField as default
7
+ };
@@ -0,0 +1,157 @@
1
+ import { defineComponent, useAttrs, useTemplateRef, shallowRef, ref, onMounted, onBeforeUnmount, watch, createElementBlock, openBlock, mergeProps, unref, renderSlot } from "vue";
2
+ import { cn } from "../../utils.js";
3
+ import { inView } from "../../internals/motion/in-view.js";
4
+ import { useReducedMotion } from "../../internals/motion/use-media-query.js";
5
+ import { MAGNETIC_FIELD_DEFAULTS, createMagneticFieldHub, createMagneticFieldCore, resolveSpring } from "./magnetic-field-core.js";
6
+ import { attachLayoutInvalidation, attachPointerSource } from "./magnetic-field-source.js";
7
+ import { MAGNETIC_FIELD_KEY } from "./types.js";
8
+ const _hoisted_1 = ["data-source", "data-active"];
9
+ const _sfc_main = /* @__PURE__ */ defineComponent({
10
+ ...{ name: "MagneticField", inheritAttrs: false },
11
+ __name: "MagneticField",
12
+ props: {
13
+ source: { default: "pointer" },
14
+ position: { default: null },
15
+ radius: { default: () => MAGNETIC_FIELD_DEFAULTS.radius },
16
+ strength: { default: () => MAGNETIC_FIELD_DEFAULTS.strength },
17
+ maxTranslate: { default: () => MAGNETIC_FIELD_DEFAULTS.maxTranslate },
18
+ maxRotate: { default: () => MAGNETIC_FIELD_DEFAULTS.maxRotate },
19
+ spring: { default: "default" },
20
+ polarity: { default: 1 },
21
+ disabled: { type: Boolean, default: false },
22
+ onActiveChange: { type: Function },
23
+ class: { type: [Boolean, null, String, Object, Array] }
24
+ },
25
+ setup(__props, { expose: __expose }) {
26
+ const attrs = useAttrs();
27
+ const root = useTemplateRef("root");
28
+ __expose({ ref: root });
29
+ const hub = createMagneticFieldHub();
30
+ const context = hub;
31
+ MAGNETIC_FIELD_KEY.provide(context);
32
+ const reduced = useReducedMotion();
33
+ const core = shallowRef(null);
34
+ const active = ref(false);
35
+ function handleActive(next) {
36
+ active.value = next;
37
+ __props.onActiveChange?.(next);
38
+ }
39
+ function currentOptions() {
40
+ return {
41
+ radius: __props.radius,
42
+ strength: __props.strength,
43
+ maxTranslate: __props.maxTranslate,
44
+ maxRotate: __props.maxRotate,
45
+ spring: resolveSpring(__props.spring),
46
+ polarity: __props.polarity,
47
+ reducedMotion: reduced.value,
48
+ disabled: __props.disabled,
49
+ onActiveChange: handleActive
50
+ };
51
+ }
52
+ function syncManual() {
53
+ const point = __props.source === "manual" && __props.position ? { x: __props.position.x, y: __props.position.y } : null;
54
+ hub.setSource(point, "manual");
55
+ }
56
+ let teardownSources = null;
57
+ let onVisible = null;
58
+ let teardownObserver = null;
59
+ function buildObserver() {
60
+ teardownObserver?.();
61
+ teardownObserver = null;
62
+ const node = root.value;
63
+ if (!node || !onVisible) return;
64
+ const io = inView(node, {
65
+ once: false,
66
+ threshold: 0,
67
+ rootMargin: `${__props.radius}px`,
68
+ onChange: onVisible
69
+ });
70
+ teardownObserver = () => io?.destroy?.();
71
+ }
72
+ function buildSources() {
73
+ teardownSources?.();
74
+ teardownSources = null;
75
+ const c = core.value;
76
+ const node = root.value;
77
+ if (!c || !node) return;
78
+ const usePointer = __props.source === "pointer";
79
+ if (__props.disabled || reduced.value || !usePointer) c.clearSource("pointer");
80
+ if (__props.disabled || reduced.value) return;
81
+ let detachPointer = null;
82
+ let detachLayout = null;
83
+ onVisible = (visible) => {
84
+ if (visible) {
85
+ detachLayout ??= attachLayoutInvalidation(c);
86
+ if (usePointer) detachPointer ??= attachPointerSource(c, node.ownerDocument, node);
87
+ } else {
88
+ detachPointer?.();
89
+ detachPointer = null;
90
+ detachLayout?.();
91
+ detachLayout = null;
92
+ c.clearSource("pointer");
93
+ }
94
+ };
95
+ buildObserver();
96
+ teardownSources = () => {
97
+ teardownObserver?.();
98
+ teardownObserver = null;
99
+ onVisible = null;
100
+ detachPointer?.();
101
+ detachLayout?.();
102
+ c.clearSource("pointer");
103
+ };
104
+ }
105
+ onMounted(() => {
106
+ syncManual();
107
+ const node = root.value;
108
+ if (!node) return;
109
+ const next = createMagneticFieldCore(node, currentOptions());
110
+ core.value = next;
111
+ hub.attach(next);
112
+ buildSources();
113
+ });
114
+ onBeforeUnmount(() => {
115
+ teardownSources?.();
116
+ teardownSources = null;
117
+ const c = core.value;
118
+ if (!c) return;
119
+ hub.detach();
120
+ c.destroy();
121
+ core.value = null;
122
+ active.value = false;
123
+ });
124
+ watch(
125
+ [
126
+ () => __props.radius,
127
+ () => __props.strength,
128
+ () => __props.maxTranslate,
129
+ () => __props.maxRotate,
130
+ () => __props.spring,
131
+ () => __props.polarity,
132
+ () => __props.disabled,
133
+ reduced
134
+ ],
135
+ () => core.value?.update(currentOptions()),
136
+ { flush: "post" }
137
+ );
138
+ watch([() => __props.source, () => __props.position?.x, () => __props.position?.y], syncManual, { flush: "post" });
139
+ watch([() => __props.source, () => __props.disabled, reduced], buildSources, { flush: "post" });
140
+ watch(() => __props.radius, buildObserver, { flush: "post" });
141
+ return (_ctx, _cache) => {
142
+ return openBlock(), createElementBlock("div", mergeProps({
143
+ ref_key: "root",
144
+ ref: root,
145
+ class: unref(cn)("ft-magnetic-field", __props.class)
146
+ }, unref(attrs), {
147
+ "data-source": __props.source,
148
+ "data-active": active.value || void 0
149
+ }), [
150
+ renderSlot(_ctx.$slots, "default", {}, void 0, true)
151
+ ], 16, _hoisted_1);
152
+ };
153
+ }
154
+ });
155
+ export {
156
+ _sfc_main as default
157
+ };
@@ -0,0 +1,28 @@
1
+ import type { HTMLAttributes } from "vue";
2
+ export interface MagneticItemProps {
3
+ /** How heavy the item is. Above 1 it moves and leans less and settles more slowly; below 1 it is livelier. */
4
+ mass?: number;
5
+ /** Per-item pull multiplier, applied on top of the field's `strength`. */
6
+ strength?: number;
7
+ /** Whether the item moves toward the magnet. */
8
+ pull?: boolean;
9
+ /** Whether the item leans toward the magnet. */
10
+ rotate?: boolean;
11
+ /** Renders `<span>` wrappers with `display: inline-block` instead of block `<div>`s, for items that sit inside a line of text or an inline row. */
12
+ inline?: boolean;
13
+ /** Additional CSS classes, on the static outer wrapper. */
14
+ class?: HTMLAttributes["class"];
15
+ }
16
+ declare const _default: typeof __VLS_export;
17
+ export default _default;
18
+ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<MagneticItemProps, {
19
+ ref: Readonly<import("vue").ShallowRef<HTMLElement | null>>;
20
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<MagneticItemProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
21
+ /** The element that reacts. */
22
+ default?(): unknown;
23
+ }>;
24
+ type __VLS_WithSlots<T, S> = T & {
25
+ new (): {
26
+ $slots: S;
27
+ };
28
+ };
@@ -0,0 +1,7 @@
1
+ import _sfc_main from "./MagneticItem.vue2.js";
2
+ /* empty css */
3
+ import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
4
+ const MagneticItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-19627aa5"]]);
5
+ export {
6
+ MagneticItem as default
7
+ };
@@ -0,0 +1,72 @@
1
+ import { defineComponent, useAttrs, useTemplateRef, computed, onMounted, watch, onBeforeUnmount, createBlock, openBlock, resolveDynamicComponent, mergeProps, unref, withCtx, renderSlot } from "vue";
2
+ import { cn } from "../../utils.js";
3
+ import { MAGNETIC_FIELD_KEY } from "./types.js";
4
+ const _sfc_main = /* @__PURE__ */ defineComponent({
5
+ ...{ name: "MagneticItem", inheritAttrs: false },
6
+ __name: "MagneticItem",
7
+ props: {
8
+ mass: { default: 1 },
9
+ strength: { default: 1 },
10
+ pull: { type: Boolean, default: true },
11
+ rotate: { type: Boolean, default: true },
12
+ inline: { type: Boolean, default: false },
13
+ class: { type: [Boolean, null, String, Object, Array] }
14
+ },
15
+ setup(__props, { expose: __expose }) {
16
+ const attrs = useAttrs();
17
+ const outer = useTemplateRef("outer");
18
+ const inner = useTemplateRef("inner");
19
+ __expose({ ref: outer });
20
+ const ctx = MAGNETIC_FIELD_KEY.useOptional();
21
+ const tag = computed(() => __props.inline ? "span" : "div");
22
+ let unregister = null;
23
+ function registerNodes() {
24
+ unregister?.();
25
+ unregister = null;
26
+ const o = outer.value;
27
+ const i = inner.value;
28
+ if (!ctx || !o || !i) return;
29
+ unregister = ctx.register(o, i, { mass: __props.mass, strength: __props.strength, pull: __props.pull, rotate: __props.rotate });
30
+ }
31
+ onMounted(registerNodes);
32
+ watch(tag, registerNodes, { flush: "post" });
33
+ onBeforeUnmount(() => {
34
+ unregister?.();
35
+ unregister = null;
36
+ });
37
+ watch(
38
+ [() => __props.mass, () => __props.strength, () => __props.pull, () => __props.rotate],
39
+ () => {
40
+ const node = outer.value;
41
+ if (ctx && node) ctx.updateItem(node, { mass: __props.mass, strength: __props.strength, pull: __props.pull, rotate: __props.rotate });
42
+ },
43
+ { flush: "post" }
44
+ );
45
+ return (_ctx, _cache) => {
46
+ return openBlock(), createBlock(resolveDynamicComponent(tag.value), mergeProps({
47
+ ref_key: "outer",
48
+ ref: outer,
49
+ class: unref(cn)("ft-magnetic-item", __props.class)
50
+ }, unref(attrs), {
51
+ "data-inline": __props.inline || void 0
52
+ }), {
53
+ default: withCtx(() => [
54
+ (openBlock(), createBlock(resolveDynamicComponent(tag.value), {
55
+ ref_key: "inner",
56
+ ref: inner,
57
+ class: "ft-magnetic-item-inner"
58
+ }, {
59
+ default: withCtx(() => [
60
+ renderSlot(_ctx.$slots, "default", {}, void 0, true)
61
+ ]),
62
+ _: 3
63
+ }, 512))
64
+ ]),
65
+ _: 3
66
+ }, 16, ["class", "data-inline"]);
67
+ };
68
+ }
69
+ });
70
+ export {
71
+ _sfc_main as default
72
+ };
@@ -0,0 +1,10 @@
1
+ export { default as MagneticField } from "./MagneticField.vue";
2
+ export type { MagneticFieldProps } from "./MagneticField.vue";
3
+ export { default as MagneticItem } from "./MagneticItem.vue";
4
+ export type { MagneticItemProps } from "./MagneticItem.vue";
5
+ export { default as MagnetPuck } from "./MagnetPuck.vue";
6
+ export type { MagnetPuckProps } from "./MagnetPuck.vue";
7
+ export { MAGNETIC_FIELD_SPRINGS } from "./magnetic-field-core.js";
8
+ export type { MagneticPoint, MagneticSpring, MagneticSpringPreset, MagneticFieldSource, } from "./magnetic-field-core.js";
9
+ export { MAGNETIC_FIELD_KEY } from "./types.js";
10
+ export type { MagneticFieldContext } from "./types.js";