fancy-ui-vue 0.4.1 → 0.5.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 (35) hide show
  1. package/README.md +12 -12
  2. package/dist/components/frost-glass/FrostGlass.vue.d.ts +31 -0
  3. package/dist/components/frost-glass/FrostGlass.vue.js +90 -0
  4. package/dist/components/frost-glass/FrostGlass.vue2.js +4 -0
  5. package/dist/components/frost-glass/frost-glass-core.d.ts +155 -0
  6. package/dist/components/frost-glass/frost-glass-core.js +820 -0
  7. package/dist/components/frost-glass/index.d.ts +2 -0
  8. package/dist/components/gift-reveal/GiftReveal.vue.d.ts +50 -0
  9. package/dist/components/gift-reveal/GiftReveal.vue.js +7 -0
  10. package/dist/components/gift-reveal/GiftReveal.vue2.js +177 -0
  11. package/dist/components/gift-reveal/gift-reveal-core.d.ts +109 -0
  12. package/dist/components/gift-reveal/gift-reveal-core.js +116 -0
  13. package/dist/components/gift-reveal/index.d.ts +2 -0
  14. package/dist/components/ornament/Ornament.vue.d.ts +29 -0
  15. package/dist/components/ornament/Ornament.vue.js +112 -0
  16. package/dist/components/ornament/Ornament.vue2.js +4 -0
  17. package/dist/components/ornament/index.d.ts +2 -0
  18. package/dist/components/ornament/ornament-core.d.ts +177 -0
  19. package/dist/components/ornament/ornament-core.js +861 -0
  20. package/dist/components/snowfall/Snowfall.vue.d.ts +29 -0
  21. package/dist/components/snowfall/Snowfall.vue.js +81 -0
  22. package/dist/components/snowfall/Snowfall.vue2.js +4 -0
  23. package/dist/components/snowfall/index.d.ts +2 -0
  24. package/dist/components/snowfall/snowfall-core.d.ts +119 -0
  25. package/dist/components/snowfall/snowfall-core.js +483 -0
  26. package/dist/components/string-lights/StringLights.vue.d.ts +35 -0
  27. package/dist/components/string-lights/StringLights.vue.js +7 -0
  28. package/dist/components/string-lights/StringLights.vue2.js +98 -0
  29. package/dist/components/string-lights/index.d.ts +2 -0
  30. package/dist/components/string-lights/string-lights-core.d.ts +157 -0
  31. package/dist/components/string-lights/string-lights-core.js +228 -0
  32. package/dist/index.d.ts +5 -0
  33. package/dist/index.js +326 -316
  34. package/dist/styles.css +1341 -0
  35. package/package.json +2 -2
@@ -0,0 +1,157 @@
1
+ /**
2
+ * StringLights engine: the geometry and timing of a string of bulbs hanging on
3
+ * a sagging wire.
4
+ *
5
+ * Framework-free and shared byte-for-byte by the Svelte, React and Vue
6
+ * wrappers (see shared-cores.json). Nothing here touches the DOM at import
7
+ * time; `createStringLights` is the only entry that needs a browser, and all it
8
+ * does is measure the root's width.
9
+ *
10
+ * Everything else is pure:
11
+ *
12
+ * - `stringLightsLayout(width, options)` returns the wire's SVG path, the
13
+ * reserved height and, per bulb, where it clips onto the wire, how far it
14
+ * swings with the slope, its colour and its animation delay and duration.
15
+ * - Each drape between two anchors is a parabola. For a sag that is small
16
+ * next to the span (any string that reads as "hanging") it cannot be told
17
+ * apart from the true catenary, and a parabola is exactly one quadratic
18
+ * Bézier: control point at twice the sag, so the path is the curve itself.
19
+ * - Bulbs are spaced by arc length, not by x, so they stay evenly spread along
20
+ * the wire where it runs steep near the anchors.
21
+ *
22
+ * Horizontal positions are fractions of the width, so a layout computed for
23
+ * the wrong width (on the server, before the first measurement) still puts
24
+ * every bulb on the wire; only the arc spacing and the tilt are refined when
25
+ * the real width arrives. Vertical positions are pixels and depend only on
26
+ * `sag` and `size`, so the reserved height never changes after measurement.
27
+ *
28
+ * Twinkle patterns are CSS keyframes; this module only hands out per-bulb
29
+ * delays and durations, seeded so the server and the browser agree.
30
+ */
31
+ export type StringLightsPattern = "wave" | "alternate" | "breathe" | "twinkle" | "steady";
32
+ export declare const STRING_LIGHTS_PATTERNS: readonly StringLightsPattern[];
33
+ export interface StringLightsOptions {
34
+ /** Number of bulbs on the whole string. */
35
+ count: number;
36
+ /** Number of drapes across the width. 2 adds one anchor in the middle. */
37
+ swags: number;
38
+ /** Depth of each drape below its anchors, in px. */
39
+ sag: number;
40
+ /** Bulb colours, assigned in turn along the string. */
41
+ colors: readonly string[];
42
+ /** How the bulbs light up over time. */
43
+ pattern: StringLightsPattern;
44
+ /** Speed multiplier for the pattern. 0 or less holds every bulb lit. */
45
+ speed: number;
46
+ /** Bulb glass diameter, in px. */
47
+ size: number;
48
+ /** Strength and reach of the light around each bulb, 0..1. */
49
+ glow: number;
50
+ /** Seed for the twinkle pattern. Same seed, same flicker. */
51
+ seed: number;
52
+ }
53
+ export declare const STRING_LIGHTS_DEFAULTS: {
54
+ readonly count: 14;
55
+ readonly swags: 1;
56
+ readonly sag: 40;
57
+ readonly colors: readonly string[];
58
+ readonly pattern: StringLightsPattern;
59
+ readonly speed: 1;
60
+ readonly size: 12;
61
+ readonly glow: 0.7;
62
+ readonly seed: 1;
63
+ };
64
+ /** Width assumed before the root has been measured (server render, first paint). */
65
+ export declare const FALLBACK_WIDTH = 640;
66
+ /** Room above the anchors, px, so the wire's stroke is not cut. */
67
+ export declare const WIRE_TOP = 2;
68
+ /** Socket height as a share of the bulb size. */
69
+ export declare const SOCKET_RATIO = 0.75;
70
+ /** The glass tucks this far (share of the bulb size) into the socket. */
71
+ export declare const SOCKET_OVERLAP = 0.12;
72
+ /** How much of the wire's slope a bulb follows: 0 hangs plumb, 1 stands square to the wire. */
73
+ export declare const TILT_FOLLOW = 0.55;
74
+ /** Seconds per cycle at speed 1. */
75
+ export declare const PATTERN_PERIODS: Record<Exclude<StringLightsPattern, "steady">, number>;
76
+ export interface StringLightsBulb {
77
+ /** Where the socket clips onto the wire: share of the width, 0..1. */
78
+ x: number;
79
+ /** Where the socket clips onto the wire: px from the top. */
80
+ y: number;
81
+ /** Swing away from plumb, degrees, clockwise. */
82
+ angle: number;
83
+ /** Centre of the glass: share of the width, 0..1. */
84
+ cx: number;
85
+ /** Centre of the glass: px from the top. */
86
+ cy: number;
87
+ color: string;
88
+ /** Animation delay, seconds (negative: the cycle is already under way). */
89
+ delay: number;
90
+ /** Animation duration, seconds. 0 when the bulb does not animate. */
91
+ duration: number;
92
+ }
93
+ export interface StringLightsLayout {
94
+ /** Width the layout was computed for, px. */
95
+ width: number;
96
+ /** Height the component reserves, px. Depends only on `sag` and `size`. */
97
+ height: number;
98
+ /** The wire, as an SVG path in a `0 0 width height` box. */
99
+ wire: string;
100
+ bulbs: StringLightsBulb[];
101
+ }
102
+ /** Small seedable PRNG. Same seed, same sequence, on the server and in the browser. */
103
+ export declare function mulberry32(seed: number): () => number;
104
+ /** Options with every value checked and clamped, so the layout never sees NaN. */
105
+ export declare function resolveOptions(options?: Partial<StringLightsOptions>): StringLightsOptions;
106
+ /**
107
+ * The pattern the bulbs actually run. Reduced motion and a speed of 0 or less
108
+ * both mean every bulb holds steady and fully lit.
109
+ */
110
+ export declare function effectivePattern(pattern: StringLightsPattern, speed: number, reducedMotion: boolean): StringLightsPattern;
111
+ /** Height the component reserves: anchors, sag, socket, glass and a little air. */
112
+ export declare function reservedHeight(sag: number, size: number): number;
113
+ /** The wire: one quadratic Bézier per drape, control point at twice the sag. */
114
+ export declare function wirePath(width: number, swags: number, sag: number): string;
115
+ /**
116
+ * Where the bulbs clip onto the wire: `count` points spread evenly by arc
117
+ * length, half a step in from each end so no bulb sits on an end anchor.
118
+ * Returns x in px and the slope angle in radians.
119
+ */
120
+ export declare function bulbPoints(width: number, swags: number, sag: number, count: number): {
121
+ x: number;
122
+ y: number;
123
+ slope: number;
124
+ }[];
125
+ /** Delay and duration of one bulb's cycle, in seconds. */
126
+ export declare function bulbTiming(pattern: StringLightsPattern, index: number, count: number, speed: number, rand: () => number): {
127
+ delay: number;
128
+ duration: number;
129
+ };
130
+ /**
131
+ * The whole string for a given width. `options.pattern` should already be the
132
+ * effective one (see `effectivePattern`).
133
+ */
134
+ export declare function stringLightsLayout(width: number, options?: Partial<StringLightsOptions>): StringLightsLayout;
135
+ /** Inline style of a bulb (socket and glass), as CSS property → value. */
136
+ export declare function bulbStyle(bulb: StringLightsBulb): Record<string, string>;
137
+ /** Inline style of a bulb's light spill, centred on the glass. */
138
+ export declare function haloStyle(bulb: StringLightsBulb): Record<string, string>;
139
+ /** Inline style string, for frameworks that bind `style` as text. */
140
+ export declare function styleText(style: Record<string, string>): string;
141
+ export interface StringLightsElements {
142
+ root: HTMLElement;
143
+ }
144
+ export interface StringLightsEngineOptions {
145
+ /** Called with the root's width in whole px, now and on every change. */
146
+ onResize?: (width: number) => void;
147
+ }
148
+ export interface StringLightsEngine {
149
+ setOptions(options: StringLightsEngineOptions): void;
150
+ destroy(): void;
151
+ }
152
+ /**
153
+ * Watches the root's width. Returns null when ResizeObserver is missing; the
154
+ * wrapper then keeps the layout computed for `FALLBACK_WIDTH`, which is still
155
+ * correct apart from the exact tilt and spacing.
156
+ */
157
+ export declare function createStringLights(elements: StringLightsElements, options?: StringLightsEngineOptions): StringLightsEngine | null;
@@ -0,0 +1,228 @@
1
+ const STRING_LIGHTS_PATTERNS = [
2
+ "wave",
3
+ "alternate",
4
+ "breathe",
5
+ "twinkle",
6
+ "steady"
7
+ ];
8
+ const STRING_LIGHTS_DEFAULTS = {
9
+ count: 14,
10
+ swags: 1,
11
+ sag: 40,
12
+ colors: ["#ffd59a"],
13
+ pattern: "wave",
14
+ speed: 1,
15
+ size: 12,
16
+ glow: 0.7,
17
+ seed: 1
18
+ };
19
+ const FALLBACK_WIDTH = 640;
20
+ const WIRE_TOP = 2;
21
+ const SOCKET_RATIO = 0.75;
22
+ const SOCKET_OVERLAP = 0.12;
23
+ const TILT_FOLLOW = 0.55;
24
+ const ARC_SAMPLES = 48;
25
+ const PATTERN_PERIODS = {
26
+ wave: 3.6,
27
+ alternate: 2.8,
28
+ breathe: 5,
29
+ twinkle: 2.4
30
+ };
31
+ function mulberry32(seed) {
32
+ let a = seed >>> 0;
33
+ return () => {
34
+ a = a + 1831565813 >>> 0;
35
+ let t = a;
36
+ t = Math.imul(t ^ t >>> 15, t | 1);
37
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
38
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
39
+ };
40
+ }
41
+ function finite(value, fallback) {
42
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
43
+ }
44
+ function round(value, digits = 3) {
45
+ const f = 10 ** digits;
46
+ return Math.round(value * f) / f;
47
+ }
48
+ function resolveOptions(options = {}) {
49
+ const d = STRING_LIGHTS_DEFAULTS;
50
+ const colors = Array.isArray(options.colors) ? options.colors.filter((c) => typeof c === "string" && c.trim() !== "") : [];
51
+ const pattern = STRING_LIGHTS_PATTERNS.includes(options.pattern) ? options.pattern : d.pattern;
52
+ return {
53
+ count: Math.max(0, Math.min(500, Math.floor(finite(options.count, d.count)))),
54
+ swags: Math.max(1, Math.min(50, Math.floor(finite(options.swags, d.swags)))),
55
+ sag: Math.max(0, finite(options.sag, d.sag)),
56
+ colors: colors.length > 0 ? colors : d.colors,
57
+ pattern,
58
+ speed: finite(options.speed, d.speed),
59
+ size: Math.max(2, finite(options.size, d.size)),
60
+ glow: Math.max(0, Math.min(1, finite(options.glow, d.glow))),
61
+ seed: Math.floor(finite(options.seed, d.seed))
62
+ };
63
+ }
64
+ function effectivePattern(pattern, speed, reducedMotion) {
65
+ if (reducedMotion || !(speed > 0)) return "steady";
66
+ return STRING_LIGHTS_PATTERNS.includes(pattern) ? pattern : STRING_LIGHTS_DEFAULTS.pattern;
67
+ }
68
+ function reservedHeight(sag, size) {
69
+ return Math.ceil(WIRE_TOP + sag + size * (SOCKET_RATIO - SOCKET_OVERLAP + 1) + size * 0.25);
70
+ }
71
+ function wirePath(width, swags, sag) {
72
+ const span = width / swags;
73
+ const top = WIRE_TOP;
74
+ const parts = [`M0 ${top}`];
75
+ for (let k = 0; k < swags; k++) {
76
+ const x0 = k * span;
77
+ const x1 = (k + 1) * span;
78
+ parts.push(`Q${round((x0 + x1) / 2, 2)} ${round(top + 2 * sag, 2)} ${round(x1, 2)} ${top}`);
79
+ }
80
+ return parts.join(" ");
81
+ }
82
+ function drape(t, span, sag) {
83
+ return {
84
+ y: WIRE_TOP + 4 * sag * t * (1 - t),
85
+ slope: span > 0 ? 4 * sag * (1 - 2 * t) / span : 0
86
+ };
87
+ }
88
+ function bulbPoints(width, swags, sag, count) {
89
+ if (count <= 0 || width <= 0) return [];
90
+ const span = width / swags;
91
+ const lengths = [0];
92
+ let prev = drape(0, span, sag);
93
+ let total = 0;
94
+ for (let i = 1; i <= ARC_SAMPLES; i++) {
95
+ const t = i / ARC_SAMPLES;
96
+ const cur = drape(t, span, sag);
97
+ total += Math.hypot(span / ARC_SAMPLES, cur.y - prev.y);
98
+ lengths.push(total);
99
+ prev = cur;
100
+ }
101
+ const whole = total * swags;
102
+ const points = [];
103
+ for (let b = 0; b < count; b++) {
104
+ const s = (b + 0.5) / count * whole;
105
+ const k = Math.min(swags - 1, Math.floor(s / total));
106
+ const local = s - k * total;
107
+ let i = 1;
108
+ while (i < ARC_SAMPLES && (lengths[i] ?? total) < local) i++;
109
+ const a = lengths[i - 1] ?? 0;
110
+ const z = lengths[i] ?? total;
111
+ const t = (i - 1 + (z > a ? (local - a) / (z - a) : 0)) / ARC_SAMPLES;
112
+ const at = drape(t, span, sag);
113
+ points.push({ x: k * span + t * span, y: at.y, slope: Math.atan(at.slope) });
114
+ }
115
+ return points;
116
+ }
117
+ function bulbTiming(pattern, index, count, speed, rand) {
118
+ if (pattern === "steady" || !(speed > 0)) return { delay: 0, duration: 0 };
119
+ const period = PATTERN_PERIODS[pattern] / speed;
120
+ switch (pattern) {
121
+ case "wave":
122
+ return {
123
+ delay: round(index / Math.max(1, count) * period - period),
124
+ duration: round(period)
125
+ };
126
+ case "alternate":
127
+ return { delay: index % 2 === 0 ? 0 : round(-period / 2), duration: round(period) };
128
+ case "breathe":
129
+ return { delay: 0, duration: round(period) };
130
+ case "twinkle": {
131
+ const own = period * (0.6 + rand() * 1.1);
132
+ return { delay: round(-rand() * own), duration: round(own) };
133
+ }
134
+ }
135
+ }
136
+ function stringLightsLayout(width, options = {}) {
137
+ const o = resolveOptions(options);
138
+ const w = width > 0 && Number.isFinite(width) ? width : FALLBACK_WIDTH;
139
+ const rand = mulberry32(o.seed);
140
+ const reach = o.size * (SOCKET_RATIO - SOCKET_OVERLAP + 0.5);
141
+ const bulbs = bulbPoints(w, o.swags, o.sag, o.count).map((p, i) => {
142
+ const tilt = p.slope * TILT_FOLLOW;
143
+ const timing = bulbTiming(o.pattern, i, o.count, o.speed, rand);
144
+ return {
145
+ x: round(p.x / w, 5),
146
+ y: round(p.y, 2),
147
+ angle: round(tilt * 180 / Math.PI, 2),
148
+ cx: round((p.x - Math.sin(tilt) * reach) / w, 5),
149
+ cy: round(p.y + Math.cos(tilt) * reach, 2),
150
+ color: o.colors[i % o.colors.length] ?? STRING_LIGHTS_DEFAULTS.colors[0] ?? "#ffd59a",
151
+ ...timing
152
+ };
153
+ });
154
+ return {
155
+ width: w,
156
+ height: reservedHeight(o.sag, o.size),
157
+ wire: wirePath(w, o.swags, o.sag),
158
+ bulbs
159
+ };
160
+ }
161
+ function bulbStyle(bulb) {
162
+ return {
163
+ left: `${round(bulb.x * 100, 3)}%`,
164
+ top: `${bulb.y}px`,
165
+ "--sl-angle": `${bulb.angle}deg`,
166
+ "--sl-color": bulb.color,
167
+ "--sl-delay": `${bulb.delay}s`,
168
+ "--sl-duration": `${bulb.duration}s`
169
+ };
170
+ }
171
+ function haloStyle(bulb) {
172
+ return {
173
+ left: `${round(bulb.cx * 100, 3)}%`,
174
+ top: `${bulb.cy}px`,
175
+ "--sl-color": bulb.color,
176
+ "--sl-delay": `${bulb.delay}s`,
177
+ "--sl-duration": `${bulb.duration}s`
178
+ };
179
+ }
180
+ function createStringLights(elements, options = {}) {
181
+ const { root } = elements;
182
+ if (!root || typeof ResizeObserver === "undefined") return null;
183
+ let onResize = options.onResize;
184
+ let last = -1;
185
+ let destroyed = false;
186
+ const report = (width) => {
187
+ const w = Math.round(width);
188
+ if (destroyed || w <= 0 || w === last) return;
189
+ last = w;
190
+ onResize?.(w);
191
+ };
192
+ const observer = new ResizeObserver((entries) => {
193
+ const entry = entries[entries.length - 1];
194
+ if (entry) report(entry.contentRect.width);
195
+ });
196
+ observer.observe(root);
197
+ report(root.getBoundingClientRect().width);
198
+ return {
199
+ setOptions(next) {
200
+ if ("onResize" in next) onResize = next.onResize;
201
+ },
202
+ destroy() {
203
+ destroyed = true;
204
+ observer.disconnect();
205
+ }
206
+ };
207
+ }
208
+ export {
209
+ FALLBACK_WIDTH,
210
+ PATTERN_PERIODS,
211
+ SOCKET_OVERLAP,
212
+ SOCKET_RATIO,
213
+ STRING_LIGHTS_DEFAULTS,
214
+ STRING_LIGHTS_PATTERNS,
215
+ TILT_FOLLOW,
216
+ WIRE_TOP,
217
+ bulbPoints,
218
+ bulbStyle,
219
+ bulbTiming,
220
+ createStringLights,
221
+ effectivePattern,
222
+ haloStyle,
223
+ mulberry32,
224
+ reservedHeight,
225
+ resolveOptions,
226
+ stringLightsLayout,
227
+ wirePath
228
+ };
package/dist/index.d.ts CHANGED
@@ -96,6 +96,11 @@ export * from "./components/navbar/index.js";
96
96
  export * from "./components/navigation-menu/index.js";
97
97
  export * from "./components/neon-border/index.js";
98
98
  export * from "./components/noise-reveal/index.js";
99
+ export * from "./components/snowfall/index.js";
100
+ export * from "./components/string-lights/index.js";
101
+ export * from "./components/frost-glass/index.js";
102
+ export * from "./components/ornament/index.js";
103
+ export * from "./components/gift-reveal/index.js";
99
104
  export * from "./components/number-input/index.js";
100
105
  export * from "./components/number-ticker/index.js";
101
106
  export * from "./components/pagination/index.js";