@m13v/seo-components 0.16.3 → 0.17.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.
package/package.json
CHANGED
|
@@ -5,7 +5,9 @@ import React, { useEffect, useRef, useState } from "react";
|
|
|
5
5
|
/**
|
|
6
6
|
* Particles: renders an interactive canvas of floating particles that
|
|
7
7
|
* subtly follow the mouse cursor. Great for ambient hero backgrounds.
|
|
8
|
-
*
|
|
8
|
+
* If `color` is omitted, reads the consumer's `--seo-accent` CSS variable
|
|
9
|
+
* at mount (falling back to teal #14b8a6). Canvas paint cannot use CSS
|
|
10
|
+
* vars directly, so we resolve it once via getComputedStyle.
|
|
9
11
|
*
|
|
10
12
|
* @example
|
|
11
13
|
* <Particles className="absolute inset-0" quantity={80} />
|
|
@@ -36,7 +38,9 @@ function useMousePosition(): MousePosition {
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
function hexToRgb(hex: string): number[] {
|
|
39
|
-
hex = hex.replace("#", "");
|
|
41
|
+
hex = hex.replace("#", "").trim();
|
|
42
|
+
if (hex.length === 3) hex = hex.split("").map((c) => c + c).join("");
|
|
43
|
+
if (!/^[0-9a-fA-F]{6}$/.test(hex)) return [20, 184, 166]; // teal fallback
|
|
40
44
|
const hexInt = parseInt(hex, 16);
|
|
41
45
|
const red = (hexInt >> 16) & 255;
|
|
42
46
|
const green = (hexInt >> 8) & 255;
|
|
@@ -44,6 +48,19 @@ function hexToRgb(hex: string): number[] {
|
|
|
44
48
|
return [red, green, blue];
|
|
45
49
|
}
|
|
46
50
|
|
|
51
|
+
function resolveAccentFromDOM(): string {
|
|
52
|
+
if (typeof window === "undefined") return "#14b8a6";
|
|
53
|
+
try {
|
|
54
|
+
const v = getComputedStyle(document.documentElement)
|
|
55
|
+
.getPropertyValue("--seo-accent")
|
|
56
|
+
.trim();
|
|
57
|
+
if (v && v.startsWith("#")) return v;
|
|
58
|
+
} catch {
|
|
59
|
+
// ignore
|
|
60
|
+
}
|
|
61
|
+
return "#14b8a6";
|
|
62
|
+
}
|
|
63
|
+
|
|
47
64
|
interface ParticlesProps {
|
|
48
65
|
className?: string;
|
|
49
66
|
quantity?: number;
|
|
@@ -51,8 +68,9 @@ interface ParticlesProps {
|
|
|
51
68
|
ease?: number;
|
|
52
69
|
size?: number;
|
|
53
70
|
refresh?: boolean;
|
|
54
|
-
/** Hex color for particles. Pass your brand accent color.
|
|
55
|
-
*
|
|
71
|
+
/** Hex color for particles. Pass your brand accent color. If omitted,
|
|
72
|
+
* reads the consumer's `--seo-accent` CSS variable at mount (falling
|
|
73
|
+
* back to teal #14b8a6). Only hex values are supported (canvas context). */
|
|
56
74
|
color?: string;
|
|
57
75
|
vx?: number;
|
|
58
76
|
vy?: number;
|
|
@@ -78,7 +96,7 @@ export function Particles({
|
|
|
78
96
|
ease = 50,
|
|
79
97
|
size = 0.4,
|
|
80
98
|
refresh = false,
|
|
81
|
-
color
|
|
99
|
+
color,
|
|
82
100
|
vx = 0,
|
|
83
101
|
vy = 0,
|
|
84
102
|
}: ParticlesProps) {
|
|
@@ -91,7 +109,13 @@ export function Particles({
|
|
|
91
109
|
const canvasSize = useRef<{ w: number; h: number }>({ w: 0, h: 0 });
|
|
92
110
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio : 1;
|
|
93
111
|
|
|
94
|
-
const
|
|
112
|
+
const [resolvedColor, setResolvedColor] = useState<string>(
|
|
113
|
+
color ?? "#14b8a6",
|
|
114
|
+
);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
setResolvedColor(color ?? resolveAccentFromDOM());
|
|
117
|
+
}, [color]);
|
|
118
|
+
const rgb = hexToRgb(resolvedColor);
|
|
95
119
|
|
|
96
120
|
const circleParams = (): Circle => {
|
|
97
121
|
const x = Math.floor(Math.random() * canvasSize.current.w);
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// 3. Consumer sites wrap their tree in <SeoAnalyticsProvider posthog={ph}>
|
|
18
18
|
// (or use the all-in-one FullSiteAnalytics component).
|
|
19
19
|
|
|
20
|
-
import { createContext, useCallback, useContext, useMemo, type ReactNode } from "react";
|
|
20
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, type ReactNode } from "react";
|
|
21
21
|
|
|
22
22
|
export interface PostHogLike {
|
|
23
23
|
capture: (event: string, properties?: Record<string, unknown>) => void;
|
|
@@ -38,6 +38,18 @@ export interface SeoAnalyticsProviderProps {
|
|
|
38
38
|
*/
|
|
39
39
|
export function SeoAnalyticsProvider({ posthog, children }: SeoAnalyticsProviderProps) {
|
|
40
40
|
const value = useMemo(() => posthog ?? null, [posthog]);
|
|
41
|
+
|
|
42
|
+
// Mirror the instance onto window.posthog so non-React helpers
|
|
43
|
+
// (trackScheduleClick, legacy inline scripts) resolve without each
|
|
44
|
+
// consumer site remembering to hand-wire this line after posthog.init().
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!value) return;
|
|
47
|
+
if (typeof window === "undefined") return;
|
|
48
|
+
const w = window as unknown as { posthog?: PostHogLike };
|
|
49
|
+
if (w.posthog === value) return;
|
|
50
|
+
w.posthog = value;
|
|
51
|
+
}, [value]);
|
|
52
|
+
|
|
41
53
|
return (
|
|
42
54
|
<SeoAnalyticsContext.Provider value={value}>
|
|
43
55
|
{children}
|