fancy-ui-vue 0.3.0 → 0.4.1

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 (102) hide show
  1. package/README.md +9 -6
  2. package/dist/components/animated-testimonials/AnimatedTestimonials.vue.js +23 -12
  3. package/dist/components/bg-falling-stars/FallingStarsBg.vue.js +10 -1
  4. package/dist/components/bg-falling-stars/bg-falling-stars-core.d.ts +6 -0
  5. package/dist/components/bg-falling-stars/bg-falling-stars-core.js +24 -2
  6. package/dist/components/bg-stars/StarsBackground.vue.js +1 -1
  7. package/dist/components/bg-stars/StarsBackground.vue2.js +13 -1
  8. package/dist/components/bg-stars/bg-stars-core.d.ts +6 -0
  9. package/dist/components/bg-stars/bg-stars-core.js +21 -1
  10. package/dist/components/book/Book.vue.js +5 -83
  11. package/dist/components/book/Book.vue2.js +82 -1
  12. package/dist/components/box-reveal/BoxReveal.vue.js +5 -47
  13. package/dist/components/box-reveal/BoxReveal.vue2.js +48 -1
  14. package/dist/components/compare/StarField.vue.js +1 -1
  15. package/dist/components/container-text-flip/ContainerTextFlip.vue.js +1 -1
  16. package/dist/components/container-text-flip/ContainerTextFlip.vue2.js +14 -5
  17. package/dist/components/flickering-grid/FlickeringGrid.vue.js +19 -1
  18. package/dist/components/flickering-grid/flickering-grid-core.d.ts +6 -0
  19. package/dist/components/flickering-grid/flickering-grid-core.js +30 -1
  20. package/dist/components/flip-words/FlipWords.vue.js +1 -1
  21. package/dist/components/flip-words/FlipWords.vue2.js +14 -7
  22. package/dist/components/hyper-text/HyperText.vue.js +6 -97
  23. package/dist/components/hyper-text/HyperText.vue2.js +101 -0
  24. package/dist/components/letter-pullup/LetterPullup.vue.js +6 -38
  25. package/dist/components/letter-pullup/LetterPullup.vue2.js +40 -0
  26. package/dist/components/logo-cloud/AnimatedLogoCloud.vue.js +1 -1
  27. package/dist/components/magnetic-field/MagnetPuck.vue.d.ts +51 -0
  28. package/dist/components/magnetic-field/MagnetPuck.vue.js +7 -0
  29. package/dist/components/magnetic-field/MagnetPuck.vue2.js +191 -0
  30. package/dist/components/magnetic-field/MagneticField.vue.d.ts +39 -0
  31. package/dist/components/magnetic-field/MagneticField.vue.js +7 -0
  32. package/dist/components/magnetic-field/MagneticField.vue2.js +157 -0
  33. package/dist/components/magnetic-field/MagneticItem.vue.d.ts +28 -0
  34. package/dist/components/magnetic-field/MagneticItem.vue.js +7 -0
  35. package/dist/components/magnetic-field/MagneticItem.vue2.js +72 -0
  36. package/dist/components/magnetic-field/index.d.ts +10 -0
  37. package/dist/components/magnetic-field/magnetic-field-core.d.ts +163 -0
  38. package/dist/components/magnetic-field/magnetic-field-core.js +534 -0
  39. package/dist/components/magnetic-field/magnetic-field-source.d.ts +58 -0
  40. package/dist/components/magnetic-field/magnetic-field-source.js +58 -0
  41. package/dist/components/magnetic-field/types.d.ts +14 -0
  42. package/dist/components/magnetic-field/types.js +5 -0
  43. package/dist/components/matrix-rain/MatrixRain.vue.js +20 -1
  44. package/dist/components/matrix-rain/matrix-rain-core.d.ts +6 -0
  45. package/dist/components/matrix-rain/matrix-rain-core.js +28 -6
  46. package/dist/components/noise-reveal/NoiseReveal.vue.js +7 -0
  47. package/dist/components/noise-reveal/noise-reveal-core.js +23 -7
  48. package/dist/components/pixel-scene/PixelScene.vue.d.ts +60 -0
  49. package/dist/components/pixel-scene/PixelScene.vue.js +184 -0
  50. package/dist/components/pixel-scene/PixelScene.vue2.js +4 -0
  51. package/dist/components/pixel-scene/index.d.ts +4 -0
  52. package/dist/components/pixel-scene/pixel-scene-core.d.ts +256 -0
  53. package/dist/components/pixel-scene/pixel-scene-core.js +878 -0
  54. package/dist/components/pixel-scene/pixel-scene-hdr.d.ts +68 -0
  55. package/dist/components/pixel-scene/pixel-scene-hdr.js +312 -0
  56. package/dist/components/pixel-scene/pixel-scene-scenes.d.ts +31 -0
  57. package/dist/components/pixel-scene/pixel-scene-scenes.js +1074 -0
  58. package/dist/components/ripple/Ripple.vue.js +1 -1
  59. package/dist/components/ripple/Ripple.vue2.js +6 -1
  60. package/dist/components/sparkles/Sparkles.vue.js +10 -1
  61. package/dist/components/sparkles/sparkles-core.d.ts +6 -0
  62. package/dist/components/sparkles/sparkles-core.js +26 -2
  63. package/dist/components/sparkles-text/SparklesText.vue.js +6 -88
  64. package/dist/components/sparkles-text/SparklesText.vue2.js +100 -0
  65. package/dist/components/story-thread/StoryNode.vue.d.ts +11 -0
  66. package/dist/components/story-thread/StoryNode.vue.js +7 -0
  67. package/dist/components/story-thread/StoryNode.vue2.js +23 -0
  68. package/dist/components/story-thread/StoryThread.vue.d.ts +56 -0
  69. package/dist/components/story-thread/StoryThread.vue.js +7 -0
  70. package/dist/components/story-thread/StoryThread.vue2.js +103 -0
  71. package/dist/components/story-thread/index.d.ts +5 -0
  72. package/dist/components/story-thread/story-thread-core.d.ts +119 -0
  73. package/dist/components/story-thread/story-thread-core.js +491 -0
  74. package/dist/components/story-thread/types.d.ts +1 -0
  75. package/dist/components/sun-switch/SunSwitch.vue.d.ts +61 -0
  76. package/dist/components/sun-switch/SunSwitch.vue.js +7 -0
  77. package/dist/components/sun-switch/SunSwitch.vue2.js +559 -0
  78. package/dist/components/sun-switch/index.d.ts +4 -0
  79. package/dist/components/sun-switch/pixel-wave-core.d.ts +82 -0
  80. package/dist/components/sun-switch/pixel-wave-core.js +508 -0
  81. package/dist/components/sun-switch/sun-switch-core.d.ts +251 -0
  82. package/dist/components/sun-switch/sun-switch-core.js +546 -0
  83. package/dist/components/sun-switch/sun-switch-hdr.d.ts +70 -0
  84. package/dist/components/sun-switch/sun-switch-hdr.js +311 -0
  85. package/dist/components/terminal-text/TerminalText.vue.js +1 -1
  86. package/dist/components/terminal-text/TerminalText.vue2.js +36 -4
  87. package/dist/components/text-generate-effect/TextGenerateEffect.vue.js +5 -72
  88. package/dist/components/text-generate-effect/TextGenerateEffect.vue2.js +74 -1
  89. package/dist/components/text-reveal-card/TextRevealCard.vue.js +5 -101
  90. package/dist/components/text-reveal-card/TextRevealCard.vue2.js +98 -1
  91. package/dist/components/text-reveal-card/TextRevealStars.vue.js +1 -1
  92. package/dist/components/text-reveal-card/TextRevealStars.vue2.js +29 -12
  93. package/dist/components/tracing-beam/TracingBeam.vue.d.ts +20 -1
  94. package/dist/components/tracing-beam/TracingBeam.vue.js +5 -164
  95. package/dist/components/tracing-beam/TracingBeam.vue2.js +168 -1
  96. package/dist/index.d.ts +4 -0
  97. package/dist/index.js +361 -338
  98. package/dist/styles.css +731 -89
  99. package/package.json +1 -1
  100. package/dist/components/hyper-text/HyperText.vue3.js +0 -5
  101. package/dist/components/letter-pullup/LetterPullup.vue3.js +0 -5
  102. package/dist/components/sparkles-text/SparklesText.vue3.js +0 -5
@@ -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";