fancy-ui-svelte 0.6.0 → 0.7.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.
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Geometry Utilities
3
+ *
4
+ * Helpers for calculating positions, angles, distances, and directions.
5
+ * Used for hover effects, spotlights, and direction-aware components.
6
+ */
7
+ // =============================================================================
8
+ // Point Operations
9
+ // =============================================================================
10
+ /**
11
+ * Create a point object
12
+ */
13
+ export function point(x, y) {
14
+ return { x, y };
15
+ }
16
+ /**
17
+ * Add two points
18
+ */
19
+ export function addPoints(a, b) {
20
+ return { x: a.x + b.x, y: a.y + b.y };
21
+ }
22
+ /**
23
+ * Subtract point b from point a
24
+ */
25
+ export function subtractPoints(a, b) {
26
+ return { x: a.x - b.x, y: a.y - b.y };
27
+ }
28
+ /**
29
+ * Scale a point by a factor
30
+ */
31
+ export function scalePoint(p, factor) {
32
+ return { x: p.x * factor, y: p.y * factor };
33
+ }
34
+ /**
35
+ * Get the midpoint between two points
36
+ */
37
+ export function midpoint(a, b) {
38
+ return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
39
+ }
40
+ // =============================================================================
41
+ // Distance & Angle Calculations
42
+ // =============================================================================
43
+ /**
44
+ * Calculate the distance between two points
45
+ */
46
+ export function distance(a, b) {
47
+ const dx = b.x - a.x;
48
+ const dy = b.y - a.y;
49
+ return Math.sqrt(dx * dx + dy * dy);
50
+ }
51
+ /**
52
+ * Calculate the squared distance between two points (faster, no sqrt)
53
+ */
54
+ export function distanceSquared(a, b) {
55
+ const dx = b.x - a.x;
56
+ const dy = b.y - a.y;
57
+ return dx * dx + dy * dy;
58
+ }
59
+ /**
60
+ * Calculate the angle between two points in radians
61
+ */
62
+ export function angle(from, to) {
63
+ return Math.atan2(to.y - from.y, to.x - from.x);
64
+ }
65
+ /**
66
+ * Calculate the angle between two points in degrees
67
+ */
68
+ export function angleDegrees(from, to) {
69
+ return (angle(from, to) * 180) / Math.PI;
70
+ }
71
+ /**
72
+ * Convert radians to degrees
73
+ */
74
+ export function radToDeg(radians) {
75
+ return (radians * 180) / Math.PI;
76
+ }
77
+ /**
78
+ * Convert degrees to radians
79
+ */
80
+ export function degToRad(degrees) {
81
+ return (degrees * Math.PI) / 180;
82
+ }
83
+ /**
84
+ * Normalize an angle to 0-360 degrees
85
+ */
86
+ export function normalizeAngle(degrees) {
87
+ return ((degrees % 360) + 360) % 360;
88
+ }
89
+ // =============================================================================
90
+ // Mouse & Element Positions
91
+ // =============================================================================
92
+ /**
93
+ * Get mouse position relative to an element
94
+ */
95
+ export function getRelativeMousePosition(event, element) {
96
+ const rect = element.getBoundingClientRect();
97
+ return {
98
+ x: event.clientX - rect.left,
99
+ y: event.clientY - rect.top,
100
+ };
101
+ }
102
+ /**
103
+ * Get mouse position as a percentage of element dimensions (0-1)
104
+ */
105
+ export function getRelativeMousePercent(event, element) {
106
+ const rect = element.getBoundingClientRect();
107
+ return {
108
+ x: (event.clientX - rect.left) / rect.width,
109
+ y: (event.clientY - rect.top) / rect.height,
110
+ };
111
+ }
112
+ /**
113
+ * Get mouse position centered on element (-0.5 to 0.5)
114
+ */
115
+ export function getRelativeMouseCentered(event, element) {
116
+ const percent = getRelativeMousePercent(event, element);
117
+ return {
118
+ x: percent.x - 0.5,
119
+ y: percent.y - 0.5,
120
+ };
121
+ }
122
+ /**
123
+ * Get the center point of an element
124
+ */
125
+ export function getElementCenter(element) {
126
+ const rect = element.getBoundingClientRect();
127
+ return {
128
+ x: rect.left + rect.width / 2,
129
+ y: rect.top + rect.height / 2,
130
+ };
131
+ }
132
+ /**
133
+ * Get the center point of an element relative to itself
134
+ */
135
+ export function getElementLocalCenter(element) {
136
+ const rect = element.getBoundingClientRect();
137
+ return {
138
+ x: rect.width / 2,
139
+ y: rect.height / 2,
140
+ };
141
+ }
142
+ // =============================================================================
143
+ // Direction Detection
144
+ // =============================================================================
145
+ /**
146
+ * Determine which direction mouse entered/exited an element
147
+ */
148
+ export function getEntryDirection(event, element) {
149
+ const rect = element.getBoundingClientRect();
150
+ const x = event.clientX - rect.left - rect.width / 2;
151
+ const y = event.clientY - rect.top - rect.height / 2;
152
+ // Calculate direction based on angle
153
+ const angleRad = Math.atan2(y, x);
154
+ const angleDeg = normalizeAngle((angleRad * 180) / Math.PI);
155
+ if (angleDeg >= 315 || angleDeg < 45)
156
+ return "right";
157
+ if (angleDeg >= 45 && angleDeg < 135)
158
+ return "bottom";
159
+ if (angleDeg >= 135 && angleDeg < 225)
160
+ return "left";
161
+ return "top";
162
+ }
163
+ /**
164
+ * Get the opposite direction
165
+ */
166
+ export function getOppositeDirection(direction) {
167
+ const opposites = {
168
+ top: "bottom",
169
+ right: "left",
170
+ bottom: "top",
171
+ left: "right",
172
+ };
173
+ return opposites[direction];
174
+ }
175
+ /**
176
+ * Get the nearest corner to a point within an element
177
+ */
178
+ export function getNearestCorner(point, size) {
179
+ const centerX = size.width / 2;
180
+ const centerY = size.height / 2;
181
+ const isTop = point.y < centerY;
182
+ const isLeft = point.x < centerX;
183
+ if (isTop && isLeft)
184
+ return "top-left";
185
+ if (isTop && !isLeft)
186
+ return "top-right";
187
+ if (!isTop && isLeft)
188
+ return "bottom-left";
189
+ return "bottom-right";
190
+ }
191
+ // =============================================================================
192
+ // Rect & Bounds
193
+ // =============================================================================
194
+ /**
195
+ * Check if a point is inside a rectangle
196
+ */
197
+ export function isPointInRect(p, rect) {
198
+ return (p.x >= rect.x && p.x <= rect.x + rect.width && p.y >= rect.y && p.y <= rect.y + rect.height);
199
+ }
200
+ /**
201
+ * Get the bounding rect of an element
202
+ */
203
+ export function getRect(element) {
204
+ const rect = element.getBoundingClientRect();
205
+ return {
206
+ x: rect.left,
207
+ y: rect.top,
208
+ width: rect.width,
209
+ height: rect.height,
210
+ };
211
+ }
212
+ /**
213
+ * Expand a rect by a given amount
214
+ */
215
+ export function expandRect(rect, amount) {
216
+ return {
217
+ x: rect.x - amount,
218
+ y: rect.y - amount,
219
+ width: rect.width + amount * 2,
220
+ height: rect.height + amount * 2,
221
+ };
222
+ }
223
+ // =============================================================================
224
+ // Transforms
225
+ // =============================================================================
226
+ /**
227
+ * Calculate rotation transform based on mouse position
228
+ * Returns rotation values suitable for 3D transforms
229
+ */
230
+ export function calculateTiltTransform(mousePos, elementSize, maxRotation = 15) {
231
+ const centerX = elementSize.width / 2;
232
+ const centerY = elementSize.height / 2;
233
+ const percentX = (mousePos.x - centerX) / centerX;
234
+ const percentY = (mousePos.y - centerY) / centerY;
235
+ return {
236
+ rotateX: -percentY * maxRotation,
237
+ rotateY: percentX * maxRotation,
238
+ };
239
+ }
240
+ /**
241
+ * Calculate spotlight position for gradient effects
242
+ */
243
+ export function calculateSpotlightPosition(mousePos, elementSize) {
244
+ const percentX = (mousePos.x / elementSize.width) * 100;
245
+ const percentY = (mousePos.y / elementSize.height) * 100;
246
+ return {
247
+ x: `${percentX}%`,
248
+ y: `${percentY}%`,
249
+ };
250
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Utilities barrel export
3
+ */
4
+ export { cn } from "../utils.js";
5
+ export type { WithoutChild, WithoutChildren, WithoutChildrenOrChild, WithElementRef, } from "../utils.js";
6
+ export { type SpringConfig, type AnimationOptions, springPresets, linear, easeIn, easeOut, easeInOut, easeInCubic, easeOutCubic, easeInOutCubic, easeOutBounce, easeOutElastic, easeOutBack, lerp, clamp, mapRange, springStep, isSpringAtRest, staggerDelay, getProgress, getDurationFromCSS, rafDebounce, rafThrottle, } from "./animation.js";
7
+ export { type Point, type Size, type Rect, type Direction, type Corner, point, addPoints, subtractPoints, scalePoint, midpoint, distance, distanceSquared, angle, angleDegrees, radToDeg, degToRad, normalizeAngle, getRelativeMousePosition, getRelativeMousePercent, getRelativeMouseCentered, getElementCenter, getElementLocalCenter, getEntryDirection, getOppositeDirection, getNearestCorner, isPointInRect, getRect, expandRect, calculateTiltTransform, calculateSpotlightPosition, } from "./geometry.js";
8
+ export { type RGB, type HSL, type OKLCH, type RGBA, hexToRgb, rgbToHex, parseHsl, hslToString, parseOklch, oklchToString, rgbToHsl, hslToRgb, lighten, darken, saturate, desaturate, shiftHue, complementary, interpolateColor, linearGradient, radialGradient, conicGradient, getRainbowColors, getThemeGradient, getCssVariable, setCssVariable, randomColor, isLightColor, getContrastColor, withAlpha, } from "./color.js";
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Utilities barrel export
3
+ */
4
+ // Re-export existing utilities from parent
5
+ export { cn } from "../utils.js";
6
+ // Animation utilities
7
+ export {
8
+ // Spring presets
9
+ springPresets,
10
+ // Easing functions
11
+ linear, easeIn, easeOut, easeInOut, easeInCubic, easeOutCubic, easeInOutCubic, easeOutBounce, easeOutElastic, easeOutBack,
12
+ // Animation helpers
13
+ lerp, clamp, mapRange, springStep, isSpringAtRest, staggerDelay, getProgress, getDurationFromCSS, rafDebounce, rafThrottle, } from "./animation.js";
14
+ // Geometry utilities
15
+ export {
16
+ // Point operations
17
+ point, addPoints, subtractPoints, scalePoint, midpoint,
18
+ // Distance & angle
19
+ distance, distanceSquared, angle, angleDegrees, radToDeg, degToRad, normalizeAngle,
20
+ // Mouse & element positions
21
+ getRelativeMousePosition, getRelativeMousePercent, getRelativeMouseCentered, getElementCenter, getElementLocalCenter,
22
+ // Direction detection
23
+ getEntryDirection, getOppositeDirection, getNearestCorner,
24
+ // Rect & bounds
25
+ isPointInRect, getRect, expandRect,
26
+ // Transforms
27
+ calculateTiltTransform, calculateSpotlightPosition, } from "./geometry.js";
28
+ // Color utilities
29
+ export {
30
+ // Color parsing
31
+ hexToRgb, rgbToHex, parseHsl, hslToString, parseOklch, oklchToString,
32
+ // Color conversion
33
+ rgbToHsl, hslToRgb,
34
+ // Color manipulation
35
+ lighten, darken, saturate, desaturate, shiftHue, complementary, interpolateColor,
36
+ // Gradient generation
37
+ linearGradient, radialGradient, conicGradient, getRainbowColors, getThemeGradient,
38
+ // Color utilities
39
+ getCssVariable, setCssVariable, randomColor, isLightColor, getContrastColor, withAlpha, } from "./color.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fancy-ui-svelte",
3
3
  "private": false,
4
- "version": "0.6.0",
4
+ "version": "0.7.0",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -26,6 +26,7 @@
26
26
  ],
27
27
  "files": [
28
28
  "dist/fancy-ui",
29
+ "dist/utils",
29
30
  "dist/utils.js",
30
31
  "dist/utils.d.ts",
31
32
  "dist/types.js",
@@ -63,6 +64,10 @@
63
64
  "@internationalized/date": "^3.10.1",
64
65
  "@lucide/svelte": "^0.562.0",
65
66
  "@playwright/test": "^1.58.2",
67
+ "@storybook/addon-a11y": "^10.4.6",
68
+ "@storybook/addon-docs": "^10.4.6",
69
+ "@storybook/addon-svelte-csf": "^5.1.2",
70
+ "@storybook/sveltekit": "^10.4.6",
66
71
  "@sveltejs/adapter-auto": "^7.0.0",
67
72
  "@sveltejs/kit": "^2.49.1",
68
73
  "@sveltejs/package": "^2.5.7",
@@ -87,6 +92,7 @@
87
92
  "prettier-plugin-tailwindcss": "^0.7.2",
88
93
  "publint": "^0.3.18",
89
94
  "shiki": "^4.0.2",
95
+ "storybook": "^10.4.6",
90
96
  "svelte": "^5.45.6",
91
97
  "svelte-check": "^4.3.4",
92
98
  "tailwind-variants": "^3.2.2",
@@ -110,6 +116,8 @@
110
116
  "changeset": "changeset",
111
117
  "version": "changeset version",
112
118
  "release": "changeset tag",
113
- "package": "svelte-kit sync && svelte-package -i src/lib -o dist && node -e \"const fs=require('fs'); ['dist/builder','dist/server','dist/stores'].forEach(p=>fs.rmSync(p,{recursive:true,force:true}));\" && publint"
119
+ "package": "svelte-kit sync && svelte-package -i src/lib -o dist && node -e \"const fs=require('fs'); ['dist/builder','dist/server','dist/stores'].forEach(p=>fs.rmSync(p,{recursive:true,force:true}));\" && publint",
120
+ "storybook": "storybook dev -p 6006",
121
+ "build-storybook": "storybook build"
114
122
  }
115
123
  }