@simpleapps-com/augur-web 0.2.13 → 0.2.15
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/dist/financing-widget.cjs +47 -0
- package/dist/financing-widget.cjs.map +1 -0
- package/dist/financing-widget.d.cts +45 -0
- package/dist/financing-widget.d.ts +45 -0
- package/dist/financing-widget.js +47 -0
- package/dist/financing-widget.js.map +1 -0
- package/dist/form-select.cjs +2 -2
- package/dist/form-select.cjs.map +1 -1
- package/dist/form-select.js +3 -3
- package/dist/form-textarea.cjs +2 -2
- package/dist/form-textarea.js +3 -3
- package/dist/gtm.cjs +145 -0
- package/dist/gtm.cjs.map +1 -0
- package/dist/gtm.d.cts +89 -0
- package/dist/gtm.d.ts +89 -0
- package/dist/gtm.js +145 -0
- package/dist/gtm.js.map +1 -0
- package/dist/price.cjs +72 -0
- package/dist/price.cjs.map +1 -0
- package/dist/price.d.cts +42 -0
- package/dist/price.d.ts +42 -0
- package/dist/price.js +72 -0
- package/dist/price.js.map +1 -0
- package/dist/session-replay.cjs +59 -0
- package/dist/session-replay.cjs.map +1 -0
- package/dist/session-replay.d.cts +44 -0
- package/dist/session-replay.d.ts +44 -0
- package/dist/session-replay.js +59 -0
- package/dist/session-replay.js.map +1 -0
- package/package.json +22 -2
package/dist/gtm.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/gtm.tsx
|
|
5
|
+
import {
|
|
6
|
+
createContext,
|
|
7
|
+
useCallback,
|
|
8
|
+
useContext,
|
|
9
|
+
useMemo,
|
|
10
|
+
useRef,
|
|
11
|
+
useState
|
|
12
|
+
} from "react";
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
var AnalyticsContext = createContext(null);
|
|
15
|
+
function getDataLayer() {
|
|
16
|
+
if (typeof window === "undefined") return [];
|
|
17
|
+
if (!window.dataLayer) window.dataLayer = [];
|
|
18
|
+
return window.dataLayer;
|
|
19
|
+
}
|
|
20
|
+
function injectGtmScript(gtmId, strategy) {
|
|
21
|
+
if (typeof document === "undefined") return;
|
|
22
|
+
if (document.getElementById("gtm-script")) return;
|
|
23
|
+
const dataLayer = getDataLayer();
|
|
24
|
+
dataLayer.push({ "gtm.start": (/* @__PURE__ */ new Date()).getTime(), event: "gtm.js" });
|
|
25
|
+
const script = document.createElement("script");
|
|
26
|
+
script.id = "gtm-script";
|
|
27
|
+
script.src = `https://www.googletagmanager.com/gtm.js?id=${encodeURIComponent(gtmId)}`;
|
|
28
|
+
if (strategy === "lazyOnload") {
|
|
29
|
+
script.async = true;
|
|
30
|
+
script.defer = true;
|
|
31
|
+
} else {
|
|
32
|
+
script.async = true;
|
|
33
|
+
}
|
|
34
|
+
document.head.appendChild(script);
|
|
35
|
+
}
|
|
36
|
+
function AnalyticsProvider({
|
|
37
|
+
gtmId,
|
|
38
|
+
strategy = "afterInteractive",
|
|
39
|
+
consentRequired = false,
|
|
40
|
+
debug = false,
|
|
41
|
+
children
|
|
42
|
+
}) {
|
|
43
|
+
const [hasConsent, setHasConsent] = useState(!consentRequired);
|
|
44
|
+
const [isLoaded, setIsLoaded] = useState(false);
|
|
45
|
+
const injectedRef = useRef(false);
|
|
46
|
+
const loadGtm = useCallback(() => {
|
|
47
|
+
if (injectedRef.current) return;
|
|
48
|
+
injectedRef.current = true;
|
|
49
|
+
if (strategy === "lazyOnload" && typeof requestIdleCallback === "function") {
|
|
50
|
+
requestIdleCallback(() => {
|
|
51
|
+
injectGtmScript(gtmId, strategy);
|
|
52
|
+
setIsLoaded(true);
|
|
53
|
+
});
|
|
54
|
+
} else if (strategy === "afterInteractive") {
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
injectGtmScript(gtmId, strategy);
|
|
57
|
+
setIsLoaded(true);
|
|
58
|
+
}, 0);
|
|
59
|
+
} else {
|
|
60
|
+
injectGtmScript(gtmId, strategy);
|
|
61
|
+
setIsLoaded(true);
|
|
62
|
+
}
|
|
63
|
+
}, [gtmId, strategy]);
|
|
64
|
+
if (hasConsent && !injectedRef.current && typeof window !== "undefined") {
|
|
65
|
+
loadGtm();
|
|
66
|
+
}
|
|
67
|
+
const trackEvent = useCallback(
|
|
68
|
+
(event, params) => {
|
|
69
|
+
const entry = { event, ...params };
|
|
70
|
+
if (debug) {
|
|
71
|
+
console.log("[Analytics]", entry);
|
|
72
|
+
}
|
|
73
|
+
getDataLayer().push(entry);
|
|
74
|
+
},
|
|
75
|
+
[debug]
|
|
76
|
+
);
|
|
77
|
+
const trackEcommerceEvent = useCallback(
|
|
78
|
+
(event, params) => {
|
|
79
|
+
getDataLayer().push({ ecommerce: null });
|
|
80
|
+
const entry = { event, ecommerce: params };
|
|
81
|
+
if (debug) {
|
|
82
|
+
console.log("[Analytics ecommerce]", entry);
|
|
83
|
+
}
|
|
84
|
+
getDataLayer().push(entry);
|
|
85
|
+
},
|
|
86
|
+
[debug]
|
|
87
|
+
);
|
|
88
|
+
const grantConsent = useCallback(() => {
|
|
89
|
+
setHasConsent(true);
|
|
90
|
+
loadGtm();
|
|
91
|
+
}, [loadGtm]);
|
|
92
|
+
const revokeConsent = useCallback(() => {
|
|
93
|
+
setHasConsent(false);
|
|
94
|
+
}, []);
|
|
95
|
+
const value = useMemo(
|
|
96
|
+
() => ({
|
|
97
|
+
trackEvent,
|
|
98
|
+
trackEcommerceEvent,
|
|
99
|
+
grantConsent,
|
|
100
|
+
revokeConsent,
|
|
101
|
+
hasConsent,
|
|
102
|
+
isLoaded
|
|
103
|
+
}),
|
|
104
|
+
[
|
|
105
|
+
trackEvent,
|
|
106
|
+
trackEcommerceEvent,
|
|
107
|
+
grantConsent,
|
|
108
|
+
revokeConsent,
|
|
109
|
+
hasConsent,
|
|
110
|
+
isLoaded
|
|
111
|
+
]
|
|
112
|
+
);
|
|
113
|
+
return /* @__PURE__ */ jsx(AnalyticsContext.Provider, { value, children });
|
|
114
|
+
}
|
|
115
|
+
function useAnalytics() {
|
|
116
|
+
const context = useContext(AnalyticsContext);
|
|
117
|
+
if (!context) {
|
|
118
|
+
throw new Error("useAnalytics must be used within an <AnalyticsProvider>");
|
|
119
|
+
}
|
|
120
|
+
return context;
|
|
121
|
+
}
|
|
122
|
+
function AnalyticsNoscript({ gtmId }) {
|
|
123
|
+
return /* @__PURE__ */ jsx("noscript", { children: /* @__PURE__ */ jsx(
|
|
124
|
+
"iframe",
|
|
125
|
+
{
|
|
126
|
+
src: `https://www.googletagmanager.com/ns.html?id=${encodeURIComponent(gtmId)}`,
|
|
127
|
+
height: "0",
|
|
128
|
+
width: "0",
|
|
129
|
+
style: { display: "none", visibility: "hidden" },
|
|
130
|
+
title: "Google Tag Manager"
|
|
131
|
+
}
|
|
132
|
+
) });
|
|
133
|
+
}
|
|
134
|
+
var GtmProvider = AnalyticsProvider;
|
|
135
|
+
var useGtm = useAnalytics;
|
|
136
|
+
var GtmNoscript = AnalyticsNoscript;
|
|
137
|
+
export {
|
|
138
|
+
AnalyticsNoscript,
|
|
139
|
+
AnalyticsProvider,
|
|
140
|
+
GtmNoscript,
|
|
141
|
+
GtmProvider,
|
|
142
|
+
useAnalytics,
|
|
143
|
+
useGtm
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=gtm.js.map
|
package/dist/gtm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gtm.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type { ReactNode } from \"react\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** Script loading strategy. */\nexport type AnalyticsStrategy = \"default\" | \"afterInteractive\" | \"lazyOnload\";\n\n/** GA4 standard e-commerce event names. */\nexport type EcommerceEvent =\n | \"view_item\"\n | \"view_item_list\"\n | \"select_item\"\n | \"add_to_cart\"\n | \"remove_from_cart\"\n | \"view_cart\"\n | \"begin_checkout\"\n | \"add_shipping_info\"\n | \"add_payment_info\"\n | \"purchase\"\n | \"refund\";\n\n/** GA4 e-commerce item shape. */\nexport interface EcommerceItem {\n item_id: string;\n item_name?: string;\n item_brand?: string;\n item_category?: string;\n item_variant?: string;\n price?: number;\n quantity?: number;\n index?: number;\n [key: string]: unknown;\n}\n\n/** Parameters for e-commerce events. */\nexport interface EcommerceParams {\n currency?: string;\n value?: number;\n items?: EcommerceItem[];\n transaction_id?: string;\n shipping?: number;\n tax?: number;\n coupon?: string;\n [key: string]: unknown;\n}\n\nexport interface AnalyticsProviderProps {\n /** GTM container ID (e.g. \"GTM-XXXXX\"). */\n gtmId: string;\n /** Script loading strategy. Default: \"afterInteractive\". */\n strategy?: AnalyticsStrategy;\n /** Delay GTM loading until consent is granted. Default: false. */\n consentRequired?: boolean;\n /** Log dataLayer pushes to console. Default: false. */\n debug?: boolean;\n children: ReactNode;\n}\n\nexport interface AnalyticsContextValue {\n /** Push a custom event to the dataLayer. */\n trackEvent: (event: string, params?: Record<string, unknown>) => void;\n /** Push a GA4 e-commerce event to the dataLayer. */\n trackEcommerceEvent: (\n event: EcommerceEvent,\n params: EcommerceParams,\n ) => void;\n /** Grant consent — loads GTM if consentRequired was true. */\n grantConsent: () => void;\n /** Revoke consent. Does not unload GTM (scripts can't be unloaded). */\n revokeConsent: () => void;\n /** Whether consent has been granted. */\n hasConsent: boolean;\n /** Whether the GTM script has been injected. */\n isLoaded: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nconst AnalyticsContext = createContext<AnalyticsContextValue | null>(null);\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\ndeclare global {\n interface Window {\n dataLayer?: Record<string, unknown>[];\n }\n}\n\nfunction getDataLayer(): Record<string, unknown>[] {\n if (typeof window === \"undefined\") return [];\n if (!window.dataLayer) window.dataLayer = [];\n return window.dataLayer;\n}\n\nfunction injectGtmScript(\n gtmId: string,\n strategy: AnalyticsStrategy,\n): void {\n if (typeof document === \"undefined\") return;\n\n // Prevent double-injection\n if (document.getElementById(\"gtm-script\")) return;\n\n const dataLayer = getDataLayer();\n dataLayer.push({ \"gtm.start\": new Date().getTime(), event: \"gtm.js\" });\n\n const script = document.createElement(\"script\");\n script.id = \"gtm-script\";\n script.src = `https://www.googletagmanager.com/gtm.js?id=${encodeURIComponent(gtmId)}`;\n\n if (strategy === \"lazyOnload\") {\n script.async = true;\n script.defer = true;\n } else {\n // \"default\" and \"afterInteractive\"\n script.async = true;\n }\n\n document.head.appendChild(script);\n}\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\nexport function AnalyticsProvider({\n gtmId,\n strategy = \"afterInteractive\",\n consentRequired = false,\n debug = false,\n children,\n}: AnalyticsProviderProps) {\n const [hasConsent, setHasConsent] = useState(!consentRequired);\n const [isLoaded, setIsLoaded] = useState(false);\n const injectedRef = useRef(false);\n\n const loadGtm = useCallback(() => {\n if (injectedRef.current) return;\n injectedRef.current = true;\n\n if (strategy === \"lazyOnload\" && typeof requestIdleCallback === \"function\") {\n requestIdleCallback(() => {\n injectGtmScript(gtmId, strategy);\n setIsLoaded(true);\n });\n } else if (strategy === \"afterInteractive\") {\n // Defer to after hydration\n setTimeout(() => {\n injectGtmScript(gtmId, strategy);\n setIsLoaded(true);\n }, 0);\n } else {\n injectGtmScript(gtmId, strategy);\n setIsLoaded(true);\n }\n }, [gtmId, strategy]);\n\n // Auto-load when consent is not required or already granted\n if (hasConsent && !injectedRef.current && typeof window !== \"undefined\") {\n loadGtm();\n }\n\n const trackEvent = useCallback(\n (event: string, params?: Record<string, unknown>) => {\n const entry = { event, ...params };\n if (debug) {\n console.log(\"[Analytics]\", entry);\n }\n getDataLayer().push(entry);\n },\n [debug],\n );\n\n const trackEcommerceEvent = useCallback(\n (event: EcommerceEvent, params: EcommerceParams) => {\n // Clear previous ecommerce data per GA4 best practices\n getDataLayer().push({ ecommerce: null });\n const entry = { event, ecommerce: params };\n if (debug) {\n console.log(\"[Analytics ecommerce]\", entry);\n }\n getDataLayer().push(entry);\n },\n [debug],\n );\n\n const grantConsent = useCallback(() => {\n setHasConsent(true);\n loadGtm();\n }, [loadGtm]);\n\n const revokeConsent = useCallback(() => {\n setHasConsent(false);\n }, []);\n\n const value = useMemo<AnalyticsContextValue>(\n () => ({\n trackEvent,\n trackEcommerceEvent,\n grantConsent,\n revokeConsent,\n hasConsent,\n isLoaded,\n }),\n [\n trackEvent,\n trackEcommerceEvent,\n grantConsent,\n revokeConsent,\n hasConsent,\n isLoaded,\n ],\n );\n\n return (\n <AnalyticsContext.Provider value={value}>\n {children}\n </AnalyticsContext.Provider>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\nexport function useAnalytics(): AnalyticsContextValue {\n const context = useContext(AnalyticsContext);\n if (!context) {\n throw new Error(\"useAnalytics must be used within an <AnalyticsProvider>\");\n }\n return context;\n}\n\n// ---------------------------------------------------------------------------\n// Noscript\n// ---------------------------------------------------------------------------\n\nexport interface AnalyticsNoscriptProps {\n /** GTM container ID (must match AnalyticsProvider). */\n gtmId: string;\n}\n\nexport function AnalyticsNoscript({ gtmId }: AnalyticsNoscriptProps) {\n return (\n <noscript>\n <iframe\n src={`https://www.googletagmanager.com/ns.html?id=${encodeURIComponent(gtmId)}`}\n height=\"0\"\n width=\"0\"\n style={{ display: \"none\", visibility: \"hidden\" }}\n title=\"Google Tag Manager\"\n />\n </noscript>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Backward-compatible aliases (from #59 GtmProvider)\n// ---------------------------------------------------------------------------\n\n/** @deprecated Use `AnalyticsStrategy` instead. */\nexport type GtmStrategy = AnalyticsStrategy;\n/** @deprecated Use `EcommerceEvent` instead. */\nexport type GtmEcommerceEvent = EcommerceEvent;\n/** @deprecated Use `EcommerceItem` instead. */\nexport type GtmItem = EcommerceItem;\n/** @deprecated Use `EcommerceParams` instead. */\nexport type GtmEcommerceParams = EcommerceParams;\n/** @deprecated Use `AnalyticsProviderProps` instead. */\nexport type GtmProviderProps = AnalyticsProviderProps;\n/** @deprecated Use `AnalyticsContextValue` instead. */\nexport type GtmContextValue = AnalyticsContextValue;\n/** @deprecated Use `AnalyticsNoscriptProps` instead. */\nexport type GtmNoscriptProps = AnalyticsNoscriptProps;\n\n/** @deprecated Use `AnalyticsProvider` instead. */\nexport const GtmProvider = AnalyticsProvider;\n/** @deprecated Use `useAnalytics` instead. */\nexport const useGtm = useAnalytics;\n/** @deprecated Use `AnalyticsNoscript` instead. */\nexport const GtmNoscript = AnalyticsNoscript;\n"],"mappings":";;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA8NH;AA3IJ,IAAM,mBAAmB,cAA4C,IAAI;AAYzE,SAAS,eAA0C;AACjD,MAAI,OAAO,WAAW,YAAa,QAAO,CAAC;AAC3C,MAAI,CAAC,OAAO,UAAW,QAAO,YAAY,CAAC;AAC3C,SAAO,OAAO;AAChB;AAEA,SAAS,gBACP,OACA,UACM;AACN,MAAI,OAAO,aAAa,YAAa;AAGrC,MAAI,SAAS,eAAe,YAAY,EAAG;AAE3C,QAAM,YAAY,aAAa;AAC/B,YAAU,KAAK,EAAE,cAAa,oBAAI,KAAK,GAAE,QAAQ,GAAG,OAAO,SAAS,CAAC;AAErE,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,KAAK;AACZ,SAAO,MAAM,8CAA8C,mBAAmB,KAAK,CAAC;AAEpF,MAAI,aAAa,cAAc;AAC7B,WAAO,QAAQ;AACf,WAAO,QAAQ;AAAA,EACjB,OAAO;AAEL,WAAO,QAAQ;AAAA,EACjB;AAEA,WAAS,KAAK,YAAY,MAAM;AAClC;AAMO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,QAAQ;AAAA,EACR;AACF,GAA2B;AACzB,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B,YAAQ;AAAA,EACV,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,gBAAgB,YAAY,MAAM;AACtC,kBAAc,KAAK;AAAA,EACrB,GAAG,CAAC,CAAC;AAEL,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SACE,oBAAC,iBAAiB,UAAjB,EAA0B,OACxB,UACH;AAEJ;AAMO,SAAS,eAAsC;AACpD,QAAM,UAAU,WAAW,gBAAgB;AAC3C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC3E;AACA,SAAO;AACT;AAWO,SAAS,kBAAkB,EAAE,MAAM,GAA2B;AACnE,SACE,oBAAC,cACC;AAAA,IAAC;AAAA;AAAA,MACC,KAAK,+CAA+C,mBAAmB,KAAK,CAAC;AAAA,MAC7E,QAAO;AAAA,MACP,OAAM;AAAA,MACN,OAAO,EAAE,SAAS,QAAQ,YAAY,SAAS;AAAA,MAC/C,OAAM;AAAA;AAAA,EACR,GACF;AAEJ;AAsBO,IAAM,cAAc;AAEpB,IAAM,SAAS;AAEf,IAAM,cAAc;","names":[]}
|
package/dist/price.cjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/price.tsx
|
|
5
|
+
var _web = require('@simpleapps-com/augur-utils/web');
|
|
6
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
7
|
+
var defaults = {
|
|
8
|
+
currency: "USD",
|
|
9
|
+
locale: "en-US",
|
|
10
|
+
precision: 2,
|
|
11
|
+
zeroLabel: "Call for Price",
|
|
12
|
+
uomSeparator: "/"
|
|
13
|
+
};
|
|
14
|
+
function createPrice(config = {}) {
|
|
15
|
+
const {
|
|
16
|
+
currency,
|
|
17
|
+
locale,
|
|
18
|
+
precision: defaultPrecision,
|
|
19
|
+
zeroLabel,
|
|
20
|
+
uomSeparator
|
|
21
|
+
} = { ...defaults, ...config };
|
|
22
|
+
function formatPrice(value, options) {
|
|
23
|
+
const p = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.precision]), () => ( defaultPrecision));
|
|
24
|
+
return new Intl.NumberFormat(locale, {
|
|
25
|
+
style: "currency",
|
|
26
|
+
currency,
|
|
27
|
+
minimumFractionDigits: p,
|
|
28
|
+
maximumFractionDigits: p
|
|
29
|
+
}).format(value);
|
|
30
|
+
}
|
|
31
|
+
function Price(props) {
|
|
32
|
+
if ("loading" in props && props.loading) {
|
|
33
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
34
|
+
"span",
|
|
35
|
+
{
|
|
36
|
+
className: _web.cn.call(void 0,
|
|
37
|
+
"inline-block h-4 w-16 animate-pulse rounded bg-muted",
|
|
38
|
+
props.className
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const {
|
|
44
|
+
value = 0,
|
|
45
|
+
quantity,
|
|
46
|
+
uom,
|
|
47
|
+
precision,
|
|
48
|
+
originalValue,
|
|
49
|
+
className
|
|
50
|
+
} = props;
|
|
51
|
+
if (value === 0 && originalValue === void 0) {
|
|
52
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: _web.cn.call(void 0, "text-muted-foreground", className), children: zeroLabel });
|
|
53
|
+
}
|
|
54
|
+
const displayValue = quantity !== void 0 ? value * quantity : value;
|
|
55
|
+
const formatted = formatPrice(displayValue, { precision });
|
|
56
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className, children: [
|
|
57
|
+
originalValue !== void 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "s", { className: "mr-1 text-muted-foreground", children: formatPrice(originalValue, { precision }) }),
|
|
58
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: formatted }),
|
|
59
|
+
uom && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "ml-1 text-muted-foreground", children: [
|
|
60
|
+
uomSeparator,
|
|
61
|
+
" ",
|
|
62
|
+
uom
|
|
63
|
+
] })
|
|
64
|
+
] });
|
|
65
|
+
}
|
|
66
|
+
Price.displayName = "Price";
|
|
67
|
+
return { Price, formatPrice };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
exports.createPrice = createPrice;
|
|
72
|
+
//# sourceMappingURL=price.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-web/dist/price.cjs","../src/price.tsx"],"names":[],"mappings":"AAAA,6rBAAY;AACZ,YAAY;AACZ;AACA;ACDA,sDAAmB;AAoFX,+CAAA;AAjCR,IAAM,SAAA,EAAkC;AAAA,EACtC,QAAA,EAAU,KAAA;AAAA,EACV,MAAA,EAAQ,OAAA;AAAA,EACR,SAAA,EAAW,CAAA;AAAA,EACX,SAAA,EAAW,gBAAA;AAAA,EACX,YAAA,EAAc;AAChB,CAAA;AAEO,SAAS,WAAA,CAAY,OAAA,EAAsB,CAAC,CAAA,EAAsB;AACvE,EAAA,MAAM;AAAA,IACJ,QAAA;AAAA,IAC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W,KAAA;AAC9C,IAAA,MAAM,UAAA,EAAY,WAAA,CAAY,YAAA,EAAc,EAAE,UAAU,CAAC,CAAA;AAEzD,IAAA,uBACE,8BAAA,MAAC,EAAA,EAAK,SAAA,EACH,QAAA,EAAA;AAAA,MAAA,cAAA,IAAkB,KAAA,EAAA,mBACjB,6BAAA,GAAC,EAAA,EAAE,SAAA,EAAU,4BAAA,EACV,QAAA,EAAA,WAAA,CAAY,aAAA,EAAe,EAAE,UAAU,CAAC,EAAA,CAC3C,CAAA;AAAA,sBAEF,6BAAA,MAAC,EAAA,EAAM,QAAA,EAAA,UAAA,CAAU,CAAA;AAAA,MAChB,IAAA,mBACC,8BAAA,MAAC,EAAA,EAAK,SAAA,EAAU,4BAAA,EACb,QAAA,EAAA;AAAA,QAAA,YAAA;AAAA,QAAa,GAAA;AAAA,QAAE;AAAA,MAAA,EAAA,CAClB;AAAA,IAAA,EAAA,CAEJ,CAAA;AAAA,EAEJ;AAEA,EAAA,KAAA,CAAM,YAAA,EAAc,OAAA;AAEpB,EAAA,OAAO,EAAE,KAAA,EAAO,YAAY,CAAA;AAC9B;ADpEA;AACE;AACF,kCAAC","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-web/dist/price.cjs","sourcesContent":[null,"\"use client\";\n\nimport { cn } from \"@simpleapps-com/augur-utils/web\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface PriceConfig {\n /** ISO 4217 currency code. Default: `\"USD\"`. */\n currency?: string;\n /** BCP 47 locale. Default: `\"en-US\"`. */\n locale?: string;\n /** Decimal places. Default: `2`. */\n precision?: number;\n /** Label shown when value is 0. Default: `\"Call for Price\"`. */\n zeroLabel?: string;\n /** Separator between price and UOM. Default: `\"/\"`. */\n uomSeparator?: string;\n}\n\ntype PricePropsBase = {\n /** Unit price. */\n value?: number;\n /** Quantity — multiplied by value for extended price. */\n quantity?: number;\n /** Unit of measure label (e.g. \"EACH\", \"FT\"). */\n uom?: string;\n /** Override precision for this instance. */\n precision?: number;\n /** Original price shown as strikethrough for sale display. */\n originalValue?: number;\n /** Additional class names for the root element. */\n className?: string;\n};\n\nexport type PriceProps =\n | (PricePropsBase & { loading?: false })\n | { loading: true; className?: string };\n\nexport interface FormatPriceOptions {\n precision?: number;\n}\n\nexport interface CreatePriceResult {\n Price: React.FC<PriceProps>;\n formatPrice: (value: number, options?: FormatPriceOptions) => string;\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\nconst defaults: Required<PriceConfig> = {\n currency: \"USD\",\n locale: \"en-US\",\n precision: 2,\n zeroLabel: \"Call for Price\",\n uomSeparator: \"/\",\n};\n\nexport function createPrice(config: PriceConfig = {}): CreatePriceResult {\n const {\n currency,\n locale,\n precision: defaultPrecision,\n zeroLabel,\n uomSeparator,\n } = { ...defaults, ...config };\n\n function formatPrice(\n value: number,\n options?: FormatPriceOptions,\n ): string {\n const p = options?.precision ?? defaultPrecision;\n return new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency,\n minimumFractionDigits: p,\n maximumFractionDigits: p,\n }).format(value);\n }\n\n function Price(props: PriceProps) {\n if (\"loading\" in props && props.loading) {\n return (\n <span\n className={cn(\n \"inline-block h-4 w-16 animate-pulse rounded bg-muted\",\n props.className,\n )}\n />\n );\n }\n\n const {\n value = 0,\n quantity,\n uom,\n precision,\n originalValue,\n className,\n } = props as PricePropsBase;\n\n if (value === 0 && originalValue === undefined) {\n return (\n <span className={cn(\"text-muted-foreground\", className)}>\n {zeroLabel}\n </span>\n );\n }\n\n const displayValue =\n quantity !== undefined ? value * quantity : value;\n const formatted = formatPrice(displayValue, { precision });\n\n return (\n <span className={className}>\n {originalValue !== undefined && (\n <s className=\"mr-1 text-muted-foreground\">\n {formatPrice(originalValue, { precision })}\n </s>\n )}\n <span>{formatted}</span>\n {uom && (\n <span className=\"ml-1 text-muted-foreground\">\n {uomSeparator} {uom}\n </span>\n )}\n </span>\n );\n }\n\n Price.displayName = \"Price\";\n\n return { Price, formatPrice };\n}\n"]}
|
package/dist/price.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
interface PriceConfig {
|
|
2
|
+
/** ISO 4217 currency code. Default: `"USD"`. */
|
|
3
|
+
currency?: string;
|
|
4
|
+
/** BCP 47 locale. Default: `"en-US"`. */
|
|
5
|
+
locale?: string;
|
|
6
|
+
/** Decimal places. Default: `2`. */
|
|
7
|
+
precision?: number;
|
|
8
|
+
/** Label shown when value is 0. Default: `"Call for Price"`. */
|
|
9
|
+
zeroLabel?: string;
|
|
10
|
+
/** Separator between price and UOM. Default: `"/"`. */
|
|
11
|
+
uomSeparator?: string;
|
|
12
|
+
}
|
|
13
|
+
type PricePropsBase = {
|
|
14
|
+
/** Unit price. */
|
|
15
|
+
value?: number;
|
|
16
|
+
/** Quantity — multiplied by value for extended price. */
|
|
17
|
+
quantity?: number;
|
|
18
|
+
/** Unit of measure label (e.g. "EACH", "FT"). */
|
|
19
|
+
uom?: string;
|
|
20
|
+
/** Override precision for this instance. */
|
|
21
|
+
precision?: number;
|
|
22
|
+
/** Original price shown as strikethrough for sale display. */
|
|
23
|
+
originalValue?: number;
|
|
24
|
+
/** Additional class names for the root element. */
|
|
25
|
+
className?: string;
|
|
26
|
+
};
|
|
27
|
+
type PriceProps = (PricePropsBase & {
|
|
28
|
+
loading?: false;
|
|
29
|
+
}) | {
|
|
30
|
+
loading: true;
|
|
31
|
+
className?: string;
|
|
32
|
+
};
|
|
33
|
+
interface FormatPriceOptions {
|
|
34
|
+
precision?: number;
|
|
35
|
+
}
|
|
36
|
+
interface CreatePriceResult {
|
|
37
|
+
Price: React.FC<PriceProps>;
|
|
38
|
+
formatPrice: (value: number, options?: FormatPriceOptions) => string;
|
|
39
|
+
}
|
|
40
|
+
declare function createPrice(config?: PriceConfig): CreatePriceResult;
|
|
41
|
+
|
|
42
|
+
export { type CreatePriceResult, type FormatPriceOptions, type PriceConfig, type PriceProps, createPrice };
|
package/dist/price.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
interface PriceConfig {
|
|
2
|
+
/** ISO 4217 currency code. Default: `"USD"`. */
|
|
3
|
+
currency?: string;
|
|
4
|
+
/** BCP 47 locale. Default: `"en-US"`. */
|
|
5
|
+
locale?: string;
|
|
6
|
+
/** Decimal places. Default: `2`. */
|
|
7
|
+
precision?: number;
|
|
8
|
+
/** Label shown when value is 0. Default: `"Call for Price"`. */
|
|
9
|
+
zeroLabel?: string;
|
|
10
|
+
/** Separator between price and UOM. Default: `"/"`. */
|
|
11
|
+
uomSeparator?: string;
|
|
12
|
+
}
|
|
13
|
+
type PricePropsBase = {
|
|
14
|
+
/** Unit price. */
|
|
15
|
+
value?: number;
|
|
16
|
+
/** Quantity — multiplied by value for extended price. */
|
|
17
|
+
quantity?: number;
|
|
18
|
+
/** Unit of measure label (e.g. "EACH", "FT"). */
|
|
19
|
+
uom?: string;
|
|
20
|
+
/** Override precision for this instance. */
|
|
21
|
+
precision?: number;
|
|
22
|
+
/** Original price shown as strikethrough for sale display. */
|
|
23
|
+
originalValue?: number;
|
|
24
|
+
/** Additional class names for the root element. */
|
|
25
|
+
className?: string;
|
|
26
|
+
};
|
|
27
|
+
type PriceProps = (PricePropsBase & {
|
|
28
|
+
loading?: false;
|
|
29
|
+
}) | {
|
|
30
|
+
loading: true;
|
|
31
|
+
className?: string;
|
|
32
|
+
};
|
|
33
|
+
interface FormatPriceOptions {
|
|
34
|
+
precision?: number;
|
|
35
|
+
}
|
|
36
|
+
interface CreatePriceResult {
|
|
37
|
+
Price: React.FC<PriceProps>;
|
|
38
|
+
formatPrice: (value: number, options?: FormatPriceOptions) => string;
|
|
39
|
+
}
|
|
40
|
+
declare function createPrice(config?: PriceConfig): CreatePriceResult;
|
|
41
|
+
|
|
42
|
+
export { type CreatePriceResult, type FormatPriceOptions, type PriceConfig, type PriceProps, createPrice };
|
package/dist/price.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/price.tsx
|
|
5
|
+
import { cn } from "@simpleapps-com/augur-utils/web";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
var defaults = {
|
|
8
|
+
currency: "USD",
|
|
9
|
+
locale: "en-US",
|
|
10
|
+
precision: 2,
|
|
11
|
+
zeroLabel: "Call for Price",
|
|
12
|
+
uomSeparator: "/"
|
|
13
|
+
};
|
|
14
|
+
function createPrice(config = {}) {
|
|
15
|
+
const {
|
|
16
|
+
currency,
|
|
17
|
+
locale,
|
|
18
|
+
precision: defaultPrecision,
|
|
19
|
+
zeroLabel,
|
|
20
|
+
uomSeparator
|
|
21
|
+
} = { ...defaults, ...config };
|
|
22
|
+
function formatPrice(value, options) {
|
|
23
|
+
const p = options?.precision ?? defaultPrecision;
|
|
24
|
+
return new Intl.NumberFormat(locale, {
|
|
25
|
+
style: "currency",
|
|
26
|
+
currency,
|
|
27
|
+
minimumFractionDigits: p,
|
|
28
|
+
maximumFractionDigits: p
|
|
29
|
+
}).format(value);
|
|
30
|
+
}
|
|
31
|
+
function Price(props) {
|
|
32
|
+
if ("loading" in props && props.loading) {
|
|
33
|
+
return /* @__PURE__ */ jsx(
|
|
34
|
+
"span",
|
|
35
|
+
{
|
|
36
|
+
className: cn(
|
|
37
|
+
"inline-block h-4 w-16 animate-pulse rounded bg-muted",
|
|
38
|
+
props.className
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const {
|
|
44
|
+
value = 0,
|
|
45
|
+
quantity,
|
|
46
|
+
uom,
|
|
47
|
+
precision,
|
|
48
|
+
originalValue,
|
|
49
|
+
className
|
|
50
|
+
} = props;
|
|
51
|
+
if (value === 0 && originalValue === void 0) {
|
|
52
|
+
return /* @__PURE__ */ jsx("span", { className: cn("text-muted-foreground", className), children: zeroLabel });
|
|
53
|
+
}
|
|
54
|
+
const displayValue = quantity !== void 0 ? value * quantity : value;
|
|
55
|
+
const formatted = formatPrice(displayValue, { precision });
|
|
56
|
+
return /* @__PURE__ */ jsxs("span", { className, children: [
|
|
57
|
+
originalValue !== void 0 && /* @__PURE__ */ jsx("s", { className: "mr-1 text-muted-foreground", children: formatPrice(originalValue, { precision }) }),
|
|
58
|
+
/* @__PURE__ */ jsx("span", { children: formatted }),
|
|
59
|
+
uom && /* @__PURE__ */ jsxs("span", { className: "ml-1 text-muted-foreground", children: [
|
|
60
|
+
uomSeparator,
|
|
61
|
+
" ",
|
|
62
|
+
uom
|
|
63
|
+
] })
|
|
64
|
+
] });
|
|
65
|
+
}
|
|
66
|
+
Price.displayName = "Price";
|
|
67
|
+
return { Price, formatPrice };
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
createPrice
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=price.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/price.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn } from \"@simpleapps-com/augur-utils/web\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface PriceConfig {\n /** ISO 4217 currency code. Default: `\"USD\"`. */\n currency?: string;\n /** BCP 47 locale. Default: `\"en-US\"`. */\n locale?: string;\n /** Decimal places. Default: `2`. */\n precision?: number;\n /** Label shown when value is 0. Default: `\"Call for Price\"`. */\n zeroLabel?: string;\n /** Separator between price and UOM. Default: `\"/\"`. */\n uomSeparator?: string;\n}\n\ntype PricePropsBase = {\n /** Unit price. */\n value?: number;\n /** Quantity — multiplied by value for extended price. */\n quantity?: number;\n /** Unit of measure label (e.g. \"EACH\", \"FT\"). */\n uom?: string;\n /** Override precision for this instance. */\n precision?: number;\n /** Original price shown as strikethrough for sale display. */\n originalValue?: number;\n /** Additional class names for the root element. */\n className?: string;\n};\n\nexport type PriceProps =\n | (PricePropsBase & { loading?: false })\n | { loading: true; className?: string };\n\nexport interface FormatPriceOptions {\n precision?: number;\n}\n\nexport interface CreatePriceResult {\n Price: React.FC<PriceProps>;\n formatPrice: (value: number, options?: FormatPriceOptions) => string;\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\nconst defaults: Required<PriceConfig> = {\n currency: \"USD\",\n locale: \"en-US\",\n precision: 2,\n zeroLabel: \"Call for Price\",\n uomSeparator: \"/\",\n};\n\nexport function createPrice(config: PriceConfig = {}): CreatePriceResult {\n const {\n currency,\n locale,\n precision: defaultPrecision,\n zeroLabel,\n uomSeparator,\n } = { ...defaults, ...config };\n\n function formatPrice(\n value: number,\n options?: FormatPriceOptions,\n ): string {\n const p = options?.precision ?? defaultPrecision;\n return new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency,\n minimumFractionDigits: p,\n maximumFractionDigits: p,\n }).format(value);\n }\n\n function Price(props: PriceProps) {\n if (\"loading\" in props && props.loading) {\n return (\n <span\n className={cn(\n \"inline-block h-4 w-16 animate-pulse rounded bg-muted\",\n props.className,\n )}\n />\n );\n }\n\n const {\n value = 0,\n quantity,\n uom,\n precision,\n originalValue,\n className,\n } = props as PricePropsBase;\n\n if (value === 0 && originalValue === undefined) {\n return (\n <span className={cn(\"text-muted-foreground\", className)}>\n {zeroLabel}\n </span>\n );\n }\n\n const displayValue =\n quantity !== undefined ? value * quantity : value;\n const formatted = formatPrice(displayValue, { precision });\n\n return (\n <span className={className}>\n {originalValue !== undefined && (\n <s className=\"mr-1 text-muted-foreground\">\n {formatPrice(originalValue, { precision })}\n </s>\n )}\n <span>{formatted}</span>\n {uom && (\n <span className=\"ml-1 text-muted-foreground\">\n {uomSeparator} {uom}\n </span>\n )}\n </span>\n );\n }\n\n Price.displayName = \"Price\";\n\n return { Price, formatPrice };\n}\n"],"mappings":";;;;AAEA,SAAS,UAAU;AAoFX,cAuCE,YAvCF;AAjCR,IAAM,WAAkC;AAAA,EACtC,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,WAAW;AAA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
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/session-replay.tsx
|
|
5
|
+
var _react = require('react');
|
|
6
|
+
function injectMouseflow(siteId) {
|
|
7
|
+
if (typeof document === "undefined") return;
|
|
8
|
+
if (document.getElementById("mouseflow-script")) return;
|
|
9
|
+
window._mfq = window._mfq || [];
|
|
10
|
+
const script = document.createElement("script");
|
|
11
|
+
script.id = "mouseflow-script";
|
|
12
|
+
script.src = `https://cdn.mouseflow.com/projects/${encodeURIComponent(siteId)}.js`;
|
|
13
|
+
script.async = true;
|
|
14
|
+
script.defer = true;
|
|
15
|
+
document.head.appendChild(script);
|
|
16
|
+
}
|
|
17
|
+
function injectHotjar(siteId) {
|
|
18
|
+
if (typeof document === "undefined") return;
|
|
19
|
+
if (document.getElementById("hotjar-script")) return;
|
|
20
|
+
window._hjSettings = { hjid: siteId, hjsv: 6 };
|
|
21
|
+
window.hj = window.hj || function hjQueue(...args) {
|
|
22
|
+
window.hj.q = window.hj.q || [];
|
|
23
|
+
window.hj.q.push(args);
|
|
24
|
+
};
|
|
25
|
+
const script = document.createElement("script");
|
|
26
|
+
script.id = "hotjar-script";
|
|
27
|
+
script.src = `https://static.hotjar.com/c/hotjar-${encodeURIComponent(siteId)}.js?sv=6`;
|
|
28
|
+
script.async = true;
|
|
29
|
+
script.defer = true;
|
|
30
|
+
document.head.appendChild(script);
|
|
31
|
+
}
|
|
32
|
+
var injectors = {
|
|
33
|
+
mouseflow: injectMouseflow,
|
|
34
|
+
hotjar: injectHotjar
|
|
35
|
+
};
|
|
36
|
+
function SessionReplayScript({
|
|
37
|
+
provider,
|
|
38
|
+
siteId,
|
|
39
|
+
sampleRate = 1,
|
|
40
|
+
disabled = false
|
|
41
|
+
}) {
|
|
42
|
+
const injectedRef = _react.useRef.call(void 0, false);
|
|
43
|
+
_react.useEffect.call(void 0, () => {
|
|
44
|
+
if (disabled || injectedRef.current) return;
|
|
45
|
+
if (sampleRate < 1 && Math.random() > sampleRate) return;
|
|
46
|
+
injectedRef.current = true;
|
|
47
|
+
const inject = injectors[provider];
|
|
48
|
+
if (typeof requestIdleCallback === "function") {
|
|
49
|
+
requestIdleCallback(() => inject(siteId));
|
|
50
|
+
} else {
|
|
51
|
+
setTimeout(() => inject(siteId), 0);
|
|
52
|
+
}
|
|
53
|
+
}, [provider, siteId, sampleRate, disabled]);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
exports.SessionReplayScript = SessionReplayScript;
|
|
59
|
+
//# sourceMappingURL=session-replay.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-web/dist/session-replay.cjs","../src/session-replay.tsx"],"names":[],"mappings":"AAAA,qFAAY;AACZ,YAAY;AACZ;AACA;ACDA,8BAAkC;AAoClC,SAAS,eAAA,CAAgB,MAAA,EAAsB;AAC7C,EAAA,GAAA,CAAI,OAAO,SAAA,IAAa,WAAA,EAAa,MAAA;AACrC,EAAA,GAAA,CAAI,QAAA,CAAS,cAAA,CAAe,kBAAkB,CAAA,EAAG,MAAA;AAEjD,EAAA,MAAA,CAAO,KAAA,EAAO,MAAA,CAAO,KAAA,GAAQ,CAAC,CAAA;AAE9B,EAAA,MAAM,OAAA,EAAS,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA;AAC9C,EAAA,MAAA,CAAO,GAAA,EAAK,kBAAA;AACZ,EAAA,MAAA,CAAO,IAAA,EAAM,CAAA,mCAAA,EAAsC,kBAAA,CAAmB,MAAM,CAAC,CAAA,GAAA,CAAA;AAC7E,EAAA,MAAA,CAAO,MAAA,EAAQ,IAAA;AACf,EAAA,MAAA,CAAO,MAAA,EAAQ,IAAA;AACf,EAAA,QAAA,CAAS,IAAA,CAAK,WAAA,CAAY,MAAM,CAAA;AAClC;AAEA,SAAS,YAAA,CAAa,MAAA,EAAsB;A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,OAAA,EAAS,MAAA;AACrC,IAAA,GAAA,CAAI,WAAA,EAAa,EAAA,GAAK,IAAA,CAAK,MAAA,CAAO,EAAA,EAAI,UAAA,EAAY,MAAA;AAElD,IAAA,WAAA,CAAY,QAAA,EAAU,IAAA;AAEtB,IAAA,MAAM,OAAA,EAAS,SAAA,CAAU,QAAQ,CAAA;AAGjC,IAAA,GAAA,CAAI,OAAO,oBAAA,IAAwB,UAAA,EAAY;AAC7C,MAAA,mBAAA,CAAoB,CAAA,EAAA,GAAM,MAAA,CAAO,MAAM,CAAC,CAAA;AAAA,IAC1C,EAAA,KAAO;AACL,MAAA,UAAA,CAAW,CAAA,EAAA,GAAM,MAAA,CAAO,MAAM,CAAA,EAAG,CAAC,CAAA;AAAA,IACpC;AAAA,EACF,CAAA,EAAG,CAAC,QAAA,EAAU,MAAA,EAAQ,UAAA,EAAY,QAAQ,CAAC,CAAA;AAE3C,EAAA,OAAO,IAAA;AACT;ADvEA;AACE;AACF,kDAAC","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-web/dist/session-replay.cjs","sourcesContent":[null,"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** Supported session replay providers. */\nexport type SessionReplayProvider = \"mouseflow\" | \"hotjar\";\n\nexport interface SessionReplayScriptProps {\n /** Session replay provider. */\n provider: SessionReplayProvider;\n /** Project/site ID from the provider. */\n siteId: string;\n /** Sampling rate (0-1). 1 = all sessions, 0.5 = 50%. Default: 1. */\n sampleRate?: number;\n /** Disable in development. Default: false. */\n disabled?: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Globals\n// ---------------------------------------------------------------------------\n\ndeclare global {\n interface Window {\n _mfq?: unknown[];\n hj?: (...args: unknown[]) => void;\n _hjSettings?: { hjid: string; hjsv: number };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Script injectors\n// ---------------------------------------------------------------------------\n\nfunction injectMouseflow(siteId: string): void {\n if (typeof document === \"undefined\") return;\n if (document.getElementById(\"mouseflow-script\")) return;\n\n window._mfq = window._mfq || [];\n\n const script = document.createElement(\"script\");\n script.id = \"mouseflow-script\";\n script.src = `https://cdn.mouseflow.com/projects/${encodeURIComponent(siteId)}.js`;\n script.async = true;\n script.defer = true;\n document.head.appendChild(script);\n}\n\nfunction injectHotjar(siteId: string): void {\n if (typeof document === \"undefined\") return;\n if (document.getElementById(\"hotjar-script\")) return;\n\n window._hjSettings = { hjid: siteId, hjsv: 6 };\n window.hj =\n window.hj ||\n function hjQueue(...args: unknown[]) {\n (window.hj as unknown as { q: unknown[] }).q =\n (window.hj as unknown as { q: unknown[] }).q || [];\n (window.hj as unknown as { q: unknown[] }).q.push(args);\n };\n\n const script = document.createElement(\"script\");\n script.id = \"hotjar-script\";\n script.src = `https://static.hotjar.com/c/hotjar-${encodeURIComponent(siteId)}.js?sv=6`;\n script.async = true;\n script.defer = true;\n document.head.appendChild(script);\n}\n\nconst injectors: Record<SessionReplayProvider, (siteId: string) => void> = {\n mouseflow: injectMouseflow,\n hotjar: injectHotjar,\n};\n\n// ---------------------------------------------------------------------------\n// Component\n// ---------------------------------------------------------------------------\n\n/**\n * Loads a session replay script with `lazyOnload` behavior.\n * Renders nothing — this is a side-effect-only leaf component.\n *\n * Session replay tools require main thread DOM access (MutationObserver)\n * and cannot run in web workers.\n *\n * @example\n * ```tsx\n * // In layout.tsx\n * <SessionReplayScript provider=\"mouseflow\" siteId=\"88d79cd5-...\" />\n *\n * // With 50% sampling\n * <SessionReplayScript provider=\"mouseflow\" siteId=\"...\" sampleRate={0.5} />\n *\n * // Disabled in dev\n * <SessionReplayScript provider=\"hotjar\" siteId=\"...\" disabled={isDev} />\n * ```\n */\nexport function SessionReplayScript({\n provider,\n siteId,\n sampleRate = 1,\n disabled = false,\n}: SessionReplayScriptProps) {\n const injectedRef = useRef(false);\n\n useEffect(() => {\n if (disabled || injectedRef.current) return;\n if (sampleRate < 1 && Math.random() > sampleRate) return;\n\n injectedRef.current = true;\n\n const inject = injectors[provider];\n\n // Load during idle time (lazyOnload behavior)\n if (typeof requestIdleCallback === \"function\") {\n requestIdleCallback(() => inject(siteId));\n } else {\n setTimeout(() => inject(siteId), 0);\n }\n }, [provider, siteId, sampleRate, disabled]);\n\n return null;\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Supported session replay providers. */
|
|
2
|
+
type SessionReplayProvider = "mouseflow" | "hotjar";
|
|
3
|
+
interface SessionReplayScriptProps {
|
|
4
|
+
/** Session replay provider. */
|
|
5
|
+
provider: SessionReplayProvider;
|
|
6
|
+
/** Project/site ID from the provider. */
|
|
7
|
+
siteId: string;
|
|
8
|
+
/** Sampling rate (0-1). 1 = all sessions, 0.5 = 50%. Default: 1. */
|
|
9
|
+
sampleRate?: number;
|
|
10
|
+
/** Disable in development. Default: false. */
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
_mfq?: unknown[];
|
|
16
|
+
hj?: (...args: unknown[]) => void;
|
|
17
|
+
_hjSettings?: {
|
|
18
|
+
hjid: string;
|
|
19
|
+
hjsv: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Loads a session replay script with `lazyOnload` behavior.
|
|
25
|
+
* Renders nothing — this is a side-effect-only leaf component.
|
|
26
|
+
*
|
|
27
|
+
* Session replay tools require main thread DOM access (MutationObserver)
|
|
28
|
+
* and cannot run in web workers.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* // In layout.tsx
|
|
33
|
+
* <SessionReplayScript provider="mouseflow" siteId="88d79cd5-..." />
|
|
34
|
+
*
|
|
35
|
+
* // With 50% sampling
|
|
36
|
+
* <SessionReplayScript provider="mouseflow" siteId="..." sampleRate={0.5} />
|
|
37
|
+
*
|
|
38
|
+
* // Disabled in dev
|
|
39
|
+
* <SessionReplayScript provider="hotjar" siteId="..." disabled={isDev} />
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function SessionReplayScript({ provider, siteId, sampleRate, disabled, }: SessionReplayScriptProps): null;
|
|
43
|
+
|
|
44
|
+
export { type SessionReplayProvider, SessionReplayScript, type SessionReplayScriptProps };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Supported session replay providers. */
|
|
2
|
+
type SessionReplayProvider = "mouseflow" | "hotjar";
|
|
3
|
+
interface SessionReplayScriptProps {
|
|
4
|
+
/** Session replay provider. */
|
|
5
|
+
provider: SessionReplayProvider;
|
|
6
|
+
/** Project/site ID from the provider. */
|
|
7
|
+
siteId: string;
|
|
8
|
+
/** Sampling rate (0-1). 1 = all sessions, 0.5 = 50%. Default: 1. */
|
|
9
|
+
sampleRate?: number;
|
|
10
|
+
/** Disable in development. Default: false. */
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
_mfq?: unknown[];
|
|
16
|
+
hj?: (...args: unknown[]) => void;
|
|
17
|
+
_hjSettings?: {
|
|
18
|
+
hjid: string;
|
|
19
|
+
hjsv: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Loads a session replay script with `lazyOnload` behavior.
|
|
25
|
+
* Renders nothing — this is a side-effect-only leaf component.
|
|
26
|
+
*
|
|
27
|
+
* Session replay tools require main thread DOM access (MutationObserver)
|
|
28
|
+
* and cannot run in web workers.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* // In layout.tsx
|
|
33
|
+
* <SessionReplayScript provider="mouseflow" siteId="88d79cd5-..." />
|
|
34
|
+
*
|
|
35
|
+
* // With 50% sampling
|
|
36
|
+
* <SessionReplayScript provider="mouseflow" siteId="..." sampleRate={0.5} />
|
|
37
|
+
*
|
|
38
|
+
* // Disabled in dev
|
|
39
|
+
* <SessionReplayScript provider="hotjar" siteId="..." disabled={isDev} />
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function SessionReplayScript({ provider, siteId, sampleRate, disabled, }: SessionReplayScriptProps): null;
|
|
43
|
+
|
|
44
|
+
export { type SessionReplayProvider, SessionReplayScript, type SessionReplayScriptProps };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/session-replay.tsx
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
function injectMouseflow(siteId) {
|
|
7
|
+
if (typeof document === "undefined") return;
|
|
8
|
+
if (document.getElementById("mouseflow-script")) return;
|
|
9
|
+
window._mfq = window._mfq || [];
|
|
10
|
+
const script = document.createElement("script");
|
|
11
|
+
script.id = "mouseflow-script";
|
|
12
|
+
script.src = `https://cdn.mouseflow.com/projects/${encodeURIComponent(siteId)}.js`;
|
|
13
|
+
script.async = true;
|
|
14
|
+
script.defer = true;
|
|
15
|
+
document.head.appendChild(script);
|
|
16
|
+
}
|
|
17
|
+
function injectHotjar(siteId) {
|
|
18
|
+
if (typeof document === "undefined") return;
|
|
19
|
+
if (document.getElementById("hotjar-script")) return;
|
|
20
|
+
window._hjSettings = { hjid: siteId, hjsv: 6 };
|
|
21
|
+
window.hj = window.hj || function hjQueue(...args) {
|
|
22
|
+
window.hj.q = window.hj.q || [];
|
|
23
|
+
window.hj.q.push(args);
|
|
24
|
+
};
|
|
25
|
+
const script = document.createElement("script");
|
|
26
|
+
script.id = "hotjar-script";
|
|
27
|
+
script.src = `https://static.hotjar.com/c/hotjar-${encodeURIComponent(siteId)}.js?sv=6`;
|
|
28
|
+
script.async = true;
|
|
29
|
+
script.defer = true;
|
|
30
|
+
document.head.appendChild(script);
|
|
31
|
+
}
|
|
32
|
+
var injectors = {
|
|
33
|
+
mouseflow: injectMouseflow,
|
|
34
|
+
hotjar: injectHotjar
|
|
35
|
+
};
|
|
36
|
+
function SessionReplayScript({
|
|
37
|
+
provider,
|
|
38
|
+
siteId,
|
|
39
|
+
sampleRate = 1,
|
|
40
|
+
disabled = false
|
|
41
|
+
}) {
|
|
42
|
+
const injectedRef = useRef(false);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (disabled || injectedRef.current) return;
|
|
45
|
+
if (sampleRate < 1 && Math.random() > sampleRate) return;
|
|
46
|
+
injectedRef.current = true;
|
|
47
|
+
const inject = injectors[provider];
|
|
48
|
+
if (typeof requestIdleCallback === "function") {
|
|
49
|
+
requestIdleCallback(() => inject(siteId));
|
|
50
|
+
} else {
|
|
51
|
+
setTimeout(() => inject(siteId), 0);
|
|
52
|
+
}
|
|
53
|
+
}, [provider, siteId, sampleRate, disabled]);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
SessionReplayScript
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=session-replay.js.map
|