@m13v/seo-components 0.16.3 → 0.17.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m13v/seo-components",
3
- "version": "0.16.3",
3
+ "version": "0.17.0",
4
4
  "scripts": {
5
5
  "build:css": "tailwind -i src/_build.css -o dist/styles.css --minify",
6
6
  "bump:consumers": "bash scripts/bump-consumers.sh",
@@ -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
- * Default color is teal (#14b8a6). Fully self-contained, canvas-based.
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;
@@ -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}