UNPKG

@preprio/prepr-nextjs

Version:

Next.js package for Prepr CMS preview functionality with advanced debugging and visual editing capabilities

1 lines 78.8 kB
{"version":3,"sources":["../../../src/pages/react/index.tsx","../../../src/react/components/toolbar/toolbar-provider.tsx","../../../src/react/contexts/segment-context.tsx","../../../src/utils/errors.ts","../../../src/utils/index.ts","../../../src/utils/debug.ts","../../../src/react/contexts/variant-context.tsx","../../../src/react/contexts/edit-mode-context.tsx","../../../src/react/components/error-boundary.tsx","../../../src/react/hooks/use-scroll-position.tsx","../../../src/pages/react/components/toolbar/toolbar-wrapper.tsx","../../../src/pages/react/hooks/use-compat-router.ts","../../../src/react/components/toolbar/toolbar.tsx","../../../src/react/hooks/use-modal.ts","../../../src/react/components/toolbar/toolbar-content.tsx","../../../src/react/components/ui/status-indicator-pill.tsx","../../../src/react/components/icons/xmark.tsx","../../../src/react/components/ui/close-edit-mode-pill.tsx","../../../src/react/components/ui/reset-button.tsx","../../../src/react/components/icons/rotate.tsx","../../../src/react/components/ui/icon.tsx","../../../src/react/components/ui/logo.tsx","../../../src/react/components/ui/prepr-tracking-pixel.tsx","../../../src/react/components/selectors/segment-selector.tsx","../../../src/react/components/icons/sort-down.tsx","../../../src/react/components/selectors/variant-selector.tsx","../../../src/react/components/selectors/radio-selector.tsx","../../../src/react/components/selectors/edit-mode-selector.tsx","../../../src/react/components/toolbar/toolbar-button.tsx"],"sourcesContent":["'use client';\n\n// Re-export the provider and context hooks from the main react module\nexport {\n PreprToolbarProvider,\n usePreprToolbar,\n} from '../../react/components/toolbar/toolbar-provider';\n\n// Export the Pages-compatible PreprToolbar component\nimport React from 'react';\nimport { PreprToolbarProvider } from '../../react/components/toolbar/toolbar-provider';\nimport ToolbarWrapper from './components/toolbar/toolbar-wrapper';\nimport { SegmentProvider } from '../../react/contexts/segment-context';\nimport { VariantProvider } from '../../react/contexts/variant-context';\nimport { EditModeProvider } from '../../react/contexts/edit-mode-context';\nimport { PreprToolbarProps, PreprToolbarOptions } from '../../types';\nimport { StegaErrorBoundary } from '../../react/components/error-boundary';\n\ninterface PreprToolbarPropsPages extends PreprToolbarProps {\n hideBar?: boolean;\n options?: PreprToolbarOptions;\n}\n\nfunction PreprToolbar(props: PreprToolbarPropsPages) {\n const {\n data = [],\n activeSegment,\n activeVariant,\n hideBar = false,\n options,\n } = props;\n\n if (hideBar) {\n return null;\n }\n\n return (\n <StegaErrorBoundary>\n <PreprToolbarProvider\n props={{ data, activeSegment, activeVariant }}\n options={options}\n >\n <SegmentProvider initialSegments={data} activeSegment={activeSegment}>\n <VariantProvider activeVariant={activeVariant}>\n <EditModeProvider>\n <ToolbarWrapper />\n </EditModeProvider>\n </VariantProvider>\n </SegmentProvider>\n </PreprToolbarProvider>\n </StegaErrorBoundary>\n );\n}\n\nexport default PreprToolbar;\n\n// Re-export other non-navigation dependent components\nexport { default as PreprTrackingPixel } from '../../react/components/ui/prepr-tracking-pixel';\n\n// Export the compatibility router hook for custom implementations\nexport { useCompatRouter } from './hooks/use-compat-router';\n","'use client';\n\nimport React, { ReactNode, useEffect, useCallback, useMemo } from 'react';\nimport { PreprToolbarOptions, PreprToolbarProps } from '../../../types';\nimport {\n SegmentProvider,\n VariantProvider,\n EditModeProvider,\n useSegmentContext,\n useVariantContext,\n useEditModeContext,\n} from '../../contexts';\nimport { StegaErrorBoundary } from '../error-boundary';\nimport { initDebugLogger } from '../../../utils/debug';\nimport useScrollPosition from '../../hooks/use-scroll-position';\n\ninterface PreprToolbarProviderProps {\n children: ReactNode;\n props: PreprToolbarProps;\n options?: PreprToolbarOptions;\n}\n\nexport const PreprToolbarProvider: React.FC<PreprToolbarProviderProps> = ({\n children,\n props,\n options,\n}) => {\n const { activeSegment, activeVariant, data } = props;\n\n // Initialize debug logger with options\n useEffect(() => {\n const debugEnabled = options?.debug ?? false;\n initDebugLogger(debugEnabled);\n }, [options?.debug]);\n\n // Initialize scroll position handling for iframe communication\n useScrollPosition();\n\n return (\n <StegaErrorBoundary>\n <SegmentProvider initialSegments={data} activeSegment={activeSegment}>\n <VariantProvider activeVariant={activeVariant}>\n <EditModeProvider>{children}</EditModeProvider>\n </VariantProvider>\n </SegmentProvider>\n </StegaErrorBoundary>\n );\n};\n\n// Legacy hook for backward compatibility\nexport const usePreprToolbar = () => {\n // This will be deprecated in favor of specific context hooks\n // but kept for backward compatibility\n const segmentContext = useSegmentContext();\n const variantContext = useVariantContext();\n const editModeContext = useEditModeContext();\n\n const resetPersonalization = useCallback(() => {\n segmentContext.setSelectedSegment(segmentContext.emptySegment);\n variantContext.setSelectedVariant(variantContext.emptyVariant);\n }, [segmentContext, variantContext]);\n\n const resetAll = useCallback(() => {\n segmentContext.setSelectedSegment(segmentContext.emptySegment);\n variantContext.setSelectedVariant(variantContext.emptyVariant);\n editModeContext.setEditMode(false);\n }, [segmentContext, variantContext, editModeContext]);\n\n return useMemo(\n () => ({\n isPreviewMode: false,\n activeSegment: segmentContext.selectedSegment._id,\n activeVariant: variantContext.selectedVariant,\n data: segmentContext.segments,\n emptySegment: segmentContext.emptySegment,\n segmentList: segmentContext.segments,\n selectedSegment: segmentContext.selectedSegment,\n setSelectedSegment: segmentContext.setSelectedSegment,\n emptyVariant: variantContext.emptyVariant,\n selectedVariant: variantContext.selectedVariant,\n setSelectedVariant: variantContext.setSelectedVariant,\n editMode: editModeContext.editMode,\n setEditMode: editModeContext.setEditMode,\n isIframe: editModeContext.isIframe,\n resetPersonalization,\n resetAll,\n }),\n [\n segmentContext.selectedSegment,\n segmentContext.segments,\n segmentContext.emptySegment,\n segmentContext.setSelectedSegment,\n variantContext.selectedVariant,\n variantContext.emptyVariant,\n variantContext.setSelectedVariant,\n editModeContext.editMode,\n editModeContext.setEditMode,\n editModeContext.isIframe,\n resetPersonalization,\n resetAll,\n ]\n );\n};\n","'use client';\n\nimport React, { createContext, useContext, useState, ReactNode } from 'react';\nimport { PreprSegment } from '../../types';\nimport { handleContextError } from '../../utils/errors';\nimport { sendPreprEvent } from '../../utils';\n\ninterface SegmentContextValue {\n segments: PreprSegment[];\n selectedSegment: PreprSegment;\n setSelectedSegment: (segment: PreprSegment) => void;\n emptySegment: PreprSegment;\n}\n\nconst SegmentContext = createContext<SegmentContextValue | undefined>(\n undefined\n);\n\ninterface SegmentProviderProps {\n children: ReactNode;\n initialSegments: readonly PreprSegment[];\n activeSegment?: string | null;\n}\n\nexport function SegmentProvider({\n children,\n initialSegments,\n activeSegment,\n}: SegmentProviderProps) {\n const segmentList: PreprSegment[] = [\n {\n _id: 'all_other_users',\n name: 'All other users',\n },\n ...initialSegments,\n ];\n\n const emptySegment: PreprSegment = {\n name: 'Choose segment',\n _id: 'null',\n };\n\n const [selectedSegment, setSelectedSegment] = useState<PreprSegment>(\n (segmentList &&\n segmentList.filter(\n (segmentData: PreprSegment) => segmentData._id === activeSegment\n )[0]) ||\n emptySegment\n );\n\n const handleSetSelectedSegment = (segment: PreprSegment) => {\n setSelectedSegment(segment);\n sendPreprEvent('segment_changed', { segment: segment._id });\n };\n\n const value: SegmentContextValue = {\n segments: segmentList,\n selectedSegment,\n setSelectedSegment: handleSetSelectedSegment,\n emptySegment,\n };\n\n return (\n <SegmentContext.Provider value={value}>{children}</SegmentContext.Provider>\n );\n}\n\nexport function useSegmentContext(): SegmentContextValue {\n const context = useContext(SegmentContext);\n if (!context) {\n handleContextError('useSegmentContext');\n }\n return context!;\n}\n","export const StegaError = {\n DECODE_FAILED: 'STEGA_DECODE_FAILED',\n INVALID_FORMAT: 'STEGA_INVALID_FORMAT',\n DOM_MANIPULATION_FAILED: 'DOM_MANIPULATION_FAILED',\n CONTEXT_NOT_FOUND: 'CONTEXT_NOT_FOUND',\n} as const;\n\nexport type StegaErrorType = (typeof StegaError)[keyof typeof StegaError];\n\n// Define specific types for error additional data\nexport interface ErrorAdditionalData {\n input?: string;\n element?: HTMLElement;\n context?: string;\n [key: string]: string | HTMLElement | undefined;\n}\n\nexport interface ErrorInfo {\n type: StegaErrorType;\n context: string;\n message: string;\n timestamp: string;\n stack?: string;\n additionalData?: ErrorAdditionalData;\n}\n\nexport function createErrorInfo(\n type: StegaErrorType,\n context: string,\n error: Error,\n additionalData?: ErrorAdditionalData\n): ErrorInfo {\n return {\n type,\n context,\n message: error.message,\n timestamp: new Date().toISOString(),\n stack: error.stack,\n additionalData,\n };\n}\n\nexport function handleStegaError(\n error: Error,\n context: string,\n additionalData?: ErrorAdditionalData\n) {\n const errorInfo = createErrorInfo(\n StegaError.DECODE_FAILED,\n context,\n error,\n additionalData\n );\n\n console.error('Stega Error:', errorInfo);\n\n // In production, you might want to send this to an error tracking service\n if (process.env.NODE_ENV === 'production') {\n // sendToErrorTrackingService(errorInfo);\n }\n\n return errorInfo;\n}\n\nexport function handleDOMError(error: Error, context: string) {\n const errorInfo = createErrorInfo(\n StegaError.DOM_MANIPULATION_FAILED,\n context,\n error\n );\n\n console.error('DOM Error:', errorInfo);\n return errorInfo;\n}\n\nexport function handleContextError(contextName: string) {\n const error = new Error(`${contextName} must be used within its provider`);\n const errorInfo = createErrorInfo(\n StegaError.CONTEXT_NOT_FOUND,\n contextName,\n error\n );\n\n console.error('Context Error:', errorInfo);\n throw error;\n}\n","import { ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\nimport { PreprEventType } from '../types';\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n// Define specific types for Prepr events\nexport interface PreprEventData {\n readonly segment?: string;\n readonly variant?: string;\n readonly editMode?: boolean;\n readonly [key: string]: string | boolean | number | undefined;\n}\n\n/**\n * Sends a Prepr event to both the current window and parent window\n * @param event - The event type to send\n * @param data - Optional event data\n */\nexport function sendPreprEvent(\n event: PreprEventType,\n data?: PreprEventData\n): void {\n if (typeof window !== 'undefined') {\n const message = {\n name: 'prepr_preview_bar',\n event,\n ...data,\n };\n\n // Send to current window for local event handling\n window.dispatchEvent(\n new CustomEvent('prepr_preview_bar', { detail: message })\n );\n\n // Send to parent window if available\n if (window.parent && window.parent !== window) {\n window.parent.postMessage(message, '*');\n }\n }\n}\n\n// Export error handling utilities\nexport * from './errors';\n\n// Export DOM service\nexport * from './dom';\n\n// Export debug utilities\nexport * from './debug';\n\n// Export performance utilities\nexport * from './performance';\n","/**\n * Debug utility for Prepr Next.js package\n * Provides centralized debug logging with performance optimizations\n */\n\n// Define specific types for debug arguments\nexport type DebugArg = string | number | boolean | null | undefined | object;\n\ninterface DebugOptions {\n enabled?: boolean;\n prefix?: string;\n}\n\nclass DebugLogger {\n private options: DebugOptions;\n\n constructor(options: DebugOptions) {\n this.options = {\n prefix: '[Prepr]',\n ...options,\n };\n }\n\n /**\n * Check if debug is enabled - checks both local and global state\n */\n private isEnabled(): boolean {\n // If this logger has a local enabled state, use it\n if (this.options.enabled !== undefined) {\n return this.options.enabled;\n }\n\n // Otherwise, check the global logger state\n return globalDebugLogger?.options?.enabled ?? false;\n }\n\n /**\n * Log a debug message if debug is enabled\n */\n log(message: string, ...args: DebugArg[]): void {\n if (!this.isEnabled()) return;\n\n const prefix = this.options.prefix;\n console.log(`${prefix} ${message}`, ...args);\n }\n\n /**\n * Log a debug warning if debug is enabled\n */\n warn(message: string, ...args: DebugArg[]): void {\n if (!this.isEnabled()) return;\n\n const prefix = this.options.prefix;\n console.warn(`${prefix} ${message}`, ...args);\n }\n\n /**\n * Log a debug error if debug is enabled\n */\n error(message: string, ...args: DebugArg[]): void {\n if (!this.isEnabled()) return;\n\n const prefix = this.options.prefix;\n console.error(`${prefix} ${message}`, ...args);\n }\n\n /**\n * Create a scoped logger with additional context\n */\n scope(scopeName: string): DebugLogger {\n return new DebugLogger({\n ...this.options,\n prefix: `${this.options.prefix}[${scopeName}]`,\n });\n }\n}\n\n// Global debug instance\nlet globalDebugLogger: DebugLogger | null = null;\n\n/**\n * Initialize the debug logger\n */\nexport function initDebugLogger(enabled: boolean = false): void {\n globalDebugLogger = new DebugLogger({ enabled });\n}\n\n/**\n * Get the debug logger instance\n */\nexport function getDebugLogger(): DebugLogger {\n if (!globalDebugLogger) {\n // Fallback to disabled logger if not initialized\n globalDebugLogger = new DebugLogger({ enabled: false });\n }\n return globalDebugLogger;\n}\n\n/**\n * Convenience function for logging\n */\nexport function debugLog(message: string, ...args: DebugArg[]): void {\n getDebugLogger().log(message, ...args);\n}\n\n/**\n * Convenience function for warning\n */\nexport function debugWarn(message: string, ...args: DebugArg[]): void {\n getDebugLogger().warn(message, ...args);\n}\n\n/**\n * Convenience function for errors\n */\nexport function debugError(message: string, ...args: DebugArg[]): void {\n getDebugLogger().error(message, ...args);\n}\n\n/**\n * Create a scoped debug logger that dynamically checks global debug state\n */\nexport function createScopedLogger(scopeName: string): DebugLogger {\n // Create a scoped logger without its own enabled state\n // This allows it to dynamically check the global logger state\n return new DebugLogger({\n prefix: `[Prepr][${scopeName}]`,\n });\n}\n","'use client';\n\nimport React, { createContext, useContext, useState, ReactNode } from 'react';\nimport { handleContextError } from '../../utils/errors';\nimport { sendPreprEvent } from '../../utils';\n\ninterface VariantContextValue {\n selectedVariant: string | null;\n setSelectedVariant: (variant: string | null) => void;\n emptyVariant: string;\n}\n\nconst VariantContext = createContext<VariantContextValue | undefined>(\n undefined\n);\n\ninterface VariantProviderProps {\n children: ReactNode;\n activeVariant?: string | null;\n}\n\nexport function VariantProvider({\n children,\n activeVariant,\n}: VariantProviderProps) {\n const emptyVariant = 'null';\n\n const [selectedVariant, setSelectedVariant] = useState<string | null>(\n activeVariant || 'null'\n );\n\n const handleSetSelectedVariant = (variant: string | null) => {\n setSelectedVariant(variant);\n sendPreprEvent('variant_changed', { variant: variant ?? undefined });\n };\n\n const value: VariantContextValue = {\n selectedVariant,\n setSelectedVariant: handleSetSelectedVariant,\n emptyVariant,\n };\n\n return (\n <VariantContext.Provider value={value}>{children}</VariantContext.Provider>\n );\n}\n\nexport function useVariantContext(): VariantContextValue {\n const context = useContext(VariantContext);\n if (!context) {\n handleContextError('useVariantContext');\n }\n return context!;\n}\n","'use client';\n\nimport React, {\n createContext,\n useContext,\n useState,\n useEffect,\n ReactNode,\n} from 'react';\nimport { handleContextError } from '../../utils/errors';\nimport { sendPreprEvent } from '../../utils';\n\ninterface EditModeContextValue {\n editMode: boolean;\n setEditMode: (mode: boolean) => void;\n isIframe: boolean;\n}\n\nconst EditModeContext = createContext<EditModeContextValue | undefined>(\n undefined\n);\n\ninterface EditModeProviderProps {\n children: ReactNode;\n}\n\nexport function EditModeProvider({ children }: EditModeProviderProps) {\n const [editMode, setEditMode] = useState(false);\n const [isIframe, setIsIframe] = useState(false);\n\n const handleSetEditMode = (mode: boolean) => {\n setEditMode(mode);\n sendPreprEvent('edit_mode_toggled', { editMode: mode });\n };\n\n useEffect(() => {\n if (window.parent !== self) {\n setIsIframe(true);\n }\n }, []);\n\n // Handle escape key to turn off edit mode\n useEffect(() => {\n const handleEscapeKey = (event: KeyboardEvent) => {\n if (event.key === 'Escape' && editMode) {\n handleSetEditMode(false);\n }\n };\n\n if (editMode) {\n document.addEventListener('keydown', handleEscapeKey);\n }\n\n return () => {\n document.removeEventListener('keydown', handleEscapeKey);\n };\n }, [editMode]);\n\n const value: EditModeContextValue = {\n editMode,\n setEditMode: handleSetEditMode,\n isIframe,\n };\n\n return (\n <EditModeContext.Provider value={value}>\n {children}\n </EditModeContext.Provider>\n );\n}\n\nexport function useEditModeContext(): EditModeContextValue {\n const context = useContext(EditModeContext);\n if (!context) {\n handleContextError('useEditModeContext');\n }\n return context!;\n}\n","'use client';\n\nimport React, { Component, ReactNode } from 'react';\n\ninterface Props {\n children: ReactNode;\n fallback?: ReactNode;\n}\n\ninterface State {\n hasError: boolean;\n error: Error | null;\n}\n\nexport class StegaErrorBoundary extends Component<Props, State> {\n constructor(props: Props) {\n super(props);\n this.state = { hasError: false, error: null };\n }\n\n static getDerivedStateFromError(error: Error): State {\n return { hasError: true, error };\n }\n\n componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {\n console.error('Stega Error Boundary caught an error:', error, errorInfo);\n\n // In production, you might want to send this to an error tracking service\n if (process.env.NODE_ENV === 'production') {\n // sendToErrorTrackingService({ error, errorInfo });\n }\n }\n\n render() {\n if (this.state.hasError) {\n if (this.props.fallback) {\n return this.props.fallback;\n }\n\n return (\n <div className=\"p-rounded-lg p-border p-border-red-200 p-bg-red-50 p-p-4 p-text-sm p-text-red-800\">\n <div className=\"p-mb-2 p-font-semibold\">Preview mode unavailable</div>\n <div className=\"p-text-red-600\">\n {this.state.error?.message || 'An unexpected error occurred'}\n </div>\n </div>\n );\n }\n\n return this.props.children;\n }\n}\n","import { useEffect } from 'react';\nimport { sendPreprEvent } from '../../utils';\nimport { createScopedLogger } from '../../utils';\n\n// Mark this hook as having side effects to prevent tree shaking\n\nexport default function useScrollPosition() {\n const debug = createScopedLogger('useScrollPosition');\n\n useEffect(() => {\n sendPreprEvent('getScrollPosition', {\n value: 0,\n });\n\n if (window.parent !== self) {\n let parentOrigin: string | null = null; //Get origin of parent outside iframe\n sendPreprEvent('loaded');\n\n const handleMessage = (evt: MessageEvent) => {\n debug.log('received message:', evt.data);\n\n if (evt?.data?.event === 'prepr:initVE' && !parentOrigin) {\n parentOrigin = evt.origin;\n\n if (evt.data?.scrollPosition) {\n debug.log('scrolling to position:', evt.data.scrollPosition);\n //Timeout needed in order to scroll to position\n setTimeout(() => {\n window.scrollTo(0, evt.data?.scrollPosition);\n }, 1);\n }\n }\n if (evt.origin !== parentOrigin) return;\n\n if (evt?.data?.event === 'prepr:getScrollPosition') {\n const currentScrollY =\n window.scrollY || document.documentElement.scrollTop;\n debug.log('sending scroll position:', currentScrollY);\n sendPreprEvent('getScrollPosition', {\n value: currentScrollY,\n });\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n debug.log('set up iframe message listener');\n\n return () => {\n window.removeEventListener('message', handleMessage);\n debug.log('cleaned up iframe message listener');\n };\n } else {\n debug.log('not in iframe, skipping iframe setup');\n return undefined;\n }\n }, [debug]);\n\n // Return something to prevent tree shaking\n return true;\n}\n","import React, { useEffect, useState } from 'react';\nimport { useCompatRouter } from '../../hooks/use-compat-router';\nimport Toolbar from '../../../../react/components/toolbar/toolbar';\n\nexport default function ToolbarWrapper() {\n const router = useCompatRouter();\n const [isIframe, setIsIframe] = useState<boolean>(false);\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const key = event.key.toLowerCase();\n // Check for the blocked shortcuts\n const isSaveShortcut = (event.ctrlKey || event.metaKey) && key === 's';\n const isPrintShortcut = (event.ctrlKey || event.metaKey) && key === 'p';\n const isAddressBarShortcut =\n (event.ctrlKey || event.metaKey) && key === 'l';\n if (isSaveShortcut || isPrintShortcut || isAddressBarShortcut) {\n event.preventDefault(); // Prevent the browser's default action\n }\n };\n\n useEffect(() => {\n const isIframe =\n typeof window !== 'undefined' && window?.parent !== window.self;\n if (isIframe) {\n setIsIframe(true);\n const previewBarMessage = {\n name: 'prepr_preview_bar',\n event: 'loaded',\n };\n window.parent.postMessage(previewBarMessage, '*');\n window.addEventListener('keydown', handleKeyDown);\n }\n return () => {\n if (isIframe) {\n window.removeEventListener('keydown', handleKeyDown);\n }\n };\n }, []);\n\n // Check if we should hide the toolbar\n const hideBar = router.searchParams?.get('prepr_hide_bar') === 'true';\n\n if (hideBar || isIframe) {\n return null;\n }\n\n return <Toolbar />;\n}\n","import { useEffect, useState } from 'react';\n\ninterface CompatRouter {\n push: (url: string, options?: { scroll?: boolean }) => void;\n refresh: () => void;\n pathname: string;\n searchParams: URLSearchParams | null;\n}\n\n/**\n * Compatibility hook that provides a unified router interface\n * Works with both Pages Router and App Router\n */\nexport function useCompatRouter(): CompatRouter {\n const [pathname, setPathname] = useState<string>('');\n const [searchParams, setSearchParams] = useState<URLSearchParams | null>(\n null\n );\n const [router, setRouter] = useState<any>(null);\n const [isAppRouter, setIsAppRouter] = useState<boolean | null>(null);\n\n useEffect(() => {\n // Detect which router is available\n const detectRouter = async () => {\n try {\n // Try App Router first\n const appNav = await import('next/navigation');\n // Check if the hooks exist (they are functions)\n if (\n typeof appNav.useRouter === 'function' &&\n typeof appNav.usePathname === 'function' &&\n typeof appNav.useSearchParams === 'function'\n ) {\n setIsAppRouter(true);\n return;\n }\n } catch {\n // App Router not available\n }\n\n try {\n // Fall back to Pages Router\n const pagesRouter = await import('next/router');\n if (typeof pagesRouter.useRouter === 'function') {\n setIsAppRouter(false);\n return;\n }\n } catch {\n // Pages Router not available\n }\n\n console.error('No Next.js router detected');\n };\n\n detectRouter();\n }, []);\n\n useEffect(() => {\n if (isAppRouter === null) return;\n\n if (isAppRouter) {\n // Use App Router\n import('next/navigation').then(nav => {\n const routerInstance = nav.useRouter();\n const pathValue = nav.usePathname();\n const searchValue = nav.useSearchParams();\n\n setRouter(routerInstance);\n setPathname(pathValue);\n setSearchParams(searchValue);\n });\n } else {\n // Use Pages Router\n import('next/router').then(routerModule => {\n const routerInstance = routerModule.useRouter();\n\n setRouter(routerInstance);\n setPathname(routerInstance.pathname);\n\n // Convert query object to URLSearchParams\n const params = new URLSearchParams();\n Object.entries(routerInstance.query).forEach(([key, value]) => {\n if (Array.isArray(value)) {\n value.forEach(v => params.append(key, v));\n } else if (value) {\n params.append(key, value);\n }\n });\n setSearchParams(params);\n });\n }\n }, [isAppRouter]);\n\n const push = (url: string, options?: { scroll?: boolean }) => {\n if (!router) return;\n\n if (isAppRouter) {\n // App Router push\n router.push(url, options);\n } else {\n // Pages Router push\n router.push(url, undefined, { scroll: options?.scroll ?? true });\n }\n };\n\n const refresh = () => {\n if (!router) return;\n\n if (isAppRouter) {\n // App Router refresh\n router.refresh();\n } else {\n // Pages Router - reload current page\n router.replace(router.asPath);\n }\n };\n\n return {\n push,\n refresh,\n pathname,\n searchParams,\n };\n}\n","import React, { useEffect, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { cn } from '../../../utils';\nimport { useEditModeContext } from '../../contexts';\nimport { useModal } from '../../hooks/use-modal';\nimport { ToolbarContent } from './toolbar-content';\nimport { ToolbarButton } from './toolbar-button';\n\ninterface ToolbarProps {\n children?: React.ReactNode;\n}\n\nexport default function Toolbar({ children }: ToolbarProps) {\n const [isMounted, setIsMounted] = useState(false);\n const [isBarVisible, setIsBarVisible] = React.useState(false);\n const { editMode } = useEditModeContext();\n const { contentRef, triggerRef } = useModal({\n isVisible: isBarVisible,\n onClose: () => setIsBarVisible(false),\n });\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // Ref for the popup box\n const popupBoxRef = React.useRef<HTMLDivElement>(null);\n const [popupTop, setPopupTop] = React.useState<string | number>('');\n\n const updatePopupPosition = React.useCallback(() => {\n if (popupBoxRef.current && triggerRef.current) {\n const popupHeight = popupBoxRef.current.offsetHeight;\n const windowHeight = window.innerHeight;\n const triggerRect = triggerRef.current.getBoundingClientRect();\n // Center popup relative to the icon (trigger)\n const triggerCenter = triggerRect.top + triggerRect.height / 2;\n let top = triggerCenter - popupHeight / 2;\n // Clamp to leave at least 32px top and bottom\n top = Math.max(32, Math.min(top, windowHeight - popupHeight - 32));\n setPopupTop(top);\n }\n }, [triggerRef]);\n\n useEffect(() => {\n if (isBarVisible) {\n updatePopupPosition();\n window.addEventListener('resize', updatePopupPosition);\n return () => window.removeEventListener('resize', updatePopupPosition);\n }\n return undefined;\n }, [isBarVisible, updatePopupPosition]);\n\n const handleClick = () => {\n setIsBarVisible(!isBarVisible);\n };\n\n useEffect(() => {\n if (editMode) {\n setTimeout(() => {\n setIsBarVisible(false);\n }, 150);\n }\n }, [editMode]);\n\n const previewBarContent = (\n <>\n {isBarVisible && <div className=\"preview-bar-backdrop\" />}\n <div className={cn('preview-bar-container')}>\n {/* Button holder*/}\n <div className=\"p-pr-2\" ref={triggerRef}>\n <ToolbarButton onClick={handleClick} />\n </div>\n\n {/* Box holder */}\n <div\n ref={popupBoxRef}\n style={\n popupTop !== ''\n ? { top: popupTop, position: 'fixed', right: 0 }\n : {}\n }\n className={cn(\n 'preview-bar-popup',\n isBarVisible\n ? 'p-pointer-events-auto p-opacity-100'\n : 'p-pointer-events-none p-opacity-0'\n )}\n >\n {children || (\n <ToolbarContent onClose={handleClick} contentRef={contentRef} />\n )}\n </div>\n </div>\n </>\n );\n\n if (!isMounted) return null;\n\n return createPortal(previewBarContent, document.body);\n}\n\n// Compound component pattern\nToolbar.Content = ToolbarContent;\nToolbar.Button = ToolbarButton;\n","import { useEffect, useRef } from 'react';\n\ninterface UseModalProps {\n isVisible: boolean;\n onClose: () => void;\n}\n\nexport function useModal({ isVisible, onClose }: UseModalProps) {\n const contentRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (isVisible) {\n document.body.style.overflow = 'hidden';\n } else {\n document.body.style.overflow = '';\n }\n return () => {\n document.body.style.overflow = '';\n };\n }, [isVisible]);\n\n useEffect(() => {\n const handleEscapeKey = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n onClose();\n }\n };\n\n const handleClickOutside = (event: MouseEvent) => {\n // Check if the click target is part of a dropdown\n const isDropdownItem = (event.target as HTMLElement).closest(\n '[role=\"listbox\"], [role=\"option\"]'\n );\n if (isDropdownItem) {\n return;\n }\n\n if (\n contentRef.current &&\n !contentRef.current.contains(event.target as Node) &&\n triggerRef.current &&\n !triggerRef.current.contains(event.target as Node)\n ) {\n onClose();\n }\n };\n\n if (isVisible) {\n document.addEventListener('keydown', handleEscapeKey);\n document.addEventListener('mousedown', handleClickOutside);\n }\n\n return () => {\n document.removeEventListener('keydown', handleEscapeKey);\n document.removeEventListener('mousedown', handleClickOutside);\n };\n }, [isVisible, onClose]);\n\n return {\n contentRef,\n triggerRef,\n };\n}\n","import React from 'react';\nimport { Logo } from '../ui';\nimport {\n SegmentSelector,\n VariantSelector,\n EditModeSelector,\n} from '../selectors';\nimport { ResetButton } from '../ui';\n\ninterface ToolbarContentProps {\n onClose: () => void;\n contentRef: React.RefObject<HTMLDivElement | null>;\n}\n\nexport function ToolbarContent({ onClose, contentRef }: ToolbarContentProps) {\n return (\n <div\n ref={contentRef}\n className=\"p-box-shadow p-right-0 p-z-[101] p-flex p-w-full p-flex-col p-gap-y-10 p-rounded-lg p-bg-primary-50 p-p-6 sm:p-w-[502px] sm:p-p-10\"\n >\n {/* Header */}\n <div className=\"p-flex p-items-center p-justify-between p-gap-2\">\n <div className=\"p-flex p-items-start p-gap-3\">\n <Logo />\n <div className=\"p-flex p-h-6 p-items-center p-rounded p-bg-primary-100 p-px-3 p-py-1 p-text-sm p-text-primary-700\">\n toolbar\n </div>\n </div>\n <button\n onClick={onClose}\n className=\"p-flex p-h-8 p-w-8 p-cursor-pointer p-items-center p-justify-center p-rounded-md p-bg-primary-100 p-text-gray-700\"\n >\n <svg\n width=\"10\"\n height=\"10\"\n viewBox=\"0 0 10 10\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M8.17578 1.07031C8.41016 0.816406 8.82031 0.816406 9.05469 1.07031C9.30859 1.30469 9.30859 1.71484 9.05469 1.94922L5.75391 5.25L9.05469 8.57031C9.30859 8.80469 9.30859 9.21484 9.05469 9.44922C8.82031 9.70312 8.41016 9.70312 8.17578 9.44922L4.875 6.14844L1.55469 9.44922C1.32031 9.70312 0.910156 9.70312 0.675781 9.44922C0.421875 9.21484 0.421875 8.80469 0.675781 8.57031L3.97656 5.25L0.675781 1.94922C0.421875 1.71484 0.421875 1.30469 0.675781 1.07031C0.910156 0.816406 1.32031 0.816406 1.55469 1.07031L4.875 4.37109L8.17578 1.07031Z\"\n fill=\"currentColor\"\n />\n </svg>\n </button>\n </div>\n\n {/* Personalized Content */}\n <div className=\"p-space-y-2\">\n <span className=\"p-text-sm p-text-grey-400\">Personalized content</span>\n <div className=\"p-gap p-flex p-flex-wrap p-items-center p-justify-between p-gap-x-6 p-gap-y-2\">\n <h2 className=\"p-text-grey-800 p-font-semibold\">Apply segment</h2>\n <SegmentSelector />\n </div>\n <div className=\"p-gap p-flex p-flex-wrap p-items-center p-justify-between p-gap-x-6 p-gap-y-2\">\n <h2 className=\"p-text-grey-800 p-font-semibold\">Show A/B variant</h2>\n <VariantSelector />\n </div>\n </div>\n\n {/* Collaboration */}\n <div className=\"p-space-y-2\">\n <span className=\"p-text-sm p-text-grey-400\">Collaboration</span>\n <div className=\"p-gap p-flex p-flex-wrap p-items-center p-justify-between p-gap-x-6 p-gap-y-2\">\n <h2 className=\"p-text-grey-800 p-font-semibold\">Edit mode</h2>\n <EditModeSelector />\n </div>\n </div>\n\n <ResetButton />\n </div>\n );\n}\n","import React from 'react';\nimport { usePreprToolbar } from '../toolbar/toolbar-provider';\nimport XMark from '../icons/xmark';\nimport { usePathname, useRouter } from 'next/navigation';\n\nexport default function StatusIndicatorPill() {\n const {\n selectedSegment,\n selectedVariant,\n emptySegment,\n emptyVariant,\n isIframe,\n resetPersonalization,\n } = usePreprToolbar();\n\n // Only show if a segment or variant is applied (not empty/null)\n const show =\n (selectedSegment &&\n selectedSegment._id !== (emptySegment?._id ?? 'null')) ||\n (selectedVariant && selectedVariant !== (emptyVariant ?? 'null'));\n\n const router = useRouter();\n const pathname = usePathname();\n\n const handleReset = () => {\n resetPersonalization();\n // Set preview params to 'null' in the URL, then remove them for a clean URL\n const params = new URLSearchParams();\n params.set('prepr_preview_segment', 'null');\n params.set('prepr_preview_ab', 'null');\n\n // First, push the URL with reset params to trigger any listeners\n router.push(`${pathname}?${params.toString()}`, { scroll: false });\n router.refresh();\n\n // Then, push the clean URL (without the reset params)\n router.push(pathname, { scroll: false });\n router.refresh();\n };\n\n if (isIframe) {\n return null;\n }\n\n return (\n <div className=\"p-z-[998] p-flex p-gap-2\">\n {show && (\n <button\n type=\"button\"\n onClick={handleReset}\n className=\"p-flex p-cursor-pointer p-items-center p-gap-2 p-rounded-full p-bg-primary-700 p-px-4 p-py-2 p-text-xs p-font-medium p-text-white p-shadow-lg p-transition-colors p-duration-150 hover:p-bg-primary-800\"\n >\n <span className=\"p-text-[10px] p-text-white/60\">viewing as</span>\n {selectedSegment &&\n selectedSegment._id !== (emptySegment?._id ?? 'null') && (\n <span className=\"max-w-[120px] p-inline-block p-truncate\">\n {selectedSegment.name}\n </span>\n )}\n {selectedVariant && selectedVariant !== (emptyVariant ?? 'null') && (\n <span className=\"max-w-[80px] p-inline-block p-truncate p-rounded p-bg-white/20 p-px-2\">\n {selectedVariant}\n </span>\n )}\n <XMark className=\"p-h-3 p-w-3 p-text-white\" />\n </button>\n )}\n </div>\n );\n}\n","import React from 'react';\n\nexport default function XMark(props: React.SVGProps<SVGSVGElement>) {\n return (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M4.22 4.22a.75.75 0 0 1 1.06 0L8 6.94l2.72-2.72a.75.75 0 1 1 1.06 1.06L9.06 8l2.72 2.72a.75.75 0 1 1-1.06 1.06L8 9.06l-2.72 2.72a.75.75 0 1 1-1.06-1.06L6.94 8 4.22 5.28a.75.75 0 0 1 0-1.06z\"\n fill=\"currentColor\"\n />\n </svg>\n );\n}\n","import React from 'react';\nimport { usePreprToolbar } from '../toolbar/toolbar-provider';\nimport XMark from '../icons/xmark';\n\nexport default function CloseEditModePill() {\n const { editMode, setEditMode, isIframe } = usePreprToolbar();\n\n if (!editMode || isIframe) {\n return null;\n }\n\n return (\n <div className=\"p-z-[999] p-flex\">\n <button\n type=\"button\"\n onClick={() => setEditMode && setEditMode(false)}\n className=\"p-flex p-items-center p-gap-2 p-rounded-full p-bg-primary-50 p-px-4 p-py-2 p-text-xs p-font-medium p-text-gray-800 p-shadow-lg p-transition-colors p-duration-150 hover:p-bg-primary-100\"\n aria-label=\"Close edit mode\"\n >\n <span>Edit mode</span>\n <XMark className=\"transition-colors duration-150 p-h-4 p-w-4 p-text-gray-500 hover:p-text-gray-700\" />\n </button>\n </div>\n );\n}\n","import React from 'react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { cn } from '../../../utils';\nimport { usePreprToolbar } from '../toolbar/toolbar-provider';\nimport Rotate from '../icons/rotate';\n\nexport default function ResetButton() {\n const router = useRouter();\n const { resetAll, selectedVariant, selectedSegment, setEditMode, editMode } =\n usePreprToolbar();\n const pathname = usePathname();\n const enabled =\n selectedSegment._id !== 'null' || selectedVariant !== 'null' || editMode;\n\n const handleClick = () => {\n resetAll();\n setEditMode(false);\n\n // Set preview params to 'null' in the URL, then remove them for a clean URL\n const params = new URLSearchParams();\n params.set('prepr_preview_segment', 'null');\n params.set('prepr_preview_ab', 'null');\n\n // First, push the URL with reset params to trigger any listeners\n router.push(`${pathname}?${params.toString()}`, { scroll: false });\n router.refresh();\n\n // Then, push the clean URL (without the reset params)\n router.push(pathname, { scroll: false });\n router.refresh();\n };\n\n const classes = cn(\n 'p-py-2 p-px-3 p-flex p-justify-center p-gap-2 p-items-center p-rounded-md p-regular-text p-h-10 p-w-full md:p-w-[108px]',\n enabled &&\n 'p-bg-secondary-400 hover:p-secondary-500 p-cursor-pointer p-text-white',\n !enabled && 'p-bg-grey-400 p-text-gray-500'\n );\n\n return (\n <button onClick={handleClick} className={classes} disabled={!enabled}>\n <Rotate />\n <span className=\"p-block sm:p-hidden lg:p-block\">Reset</span>\n </button>\n );\n}\n","import React from 'react';\n\nexport default function Rotate() {\n return (\n <svg\n width=\"15\"\n height=\"14\"\n viewBox=\"0 0 15 14\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M3.37109 5.80078C3.20703 6.26562 2.6875 6.51172 2.25 6.34766C1.78516 6.18359 1.53906 5.69141 1.70312 5.22656C2.00391 4.37891 2.49609 3.58594 3.15234 2.92969C5.55859 0.550781 9.41406 0.550781 11.8203 2.92969L12.2852 3.42188V2C12.2852 1.53516 12.6953 1.125 13.1602 1.125C13.6523 1.125 14.0352 1.53516 14.0352 2V5.5C14.0352 5.99219 13.6523 6.375 13.1602 6.375H9.6875C9.19531 6.375 8.8125 5.99219 8.8125 5.5C8.8125 5.03516 9.19531 4.625 9.6875 4.625H11.0547L10.5898 4.16016C8.86719 2.46484 6.10547 2.46484 4.38281 4.16016C3.91797 4.65234 3.5625 5.19922 3.37109 5.80078ZM1.56641 8.17969C1.59375 8.15234 1.64844 8.15234 1.67578 8.15234C1.73047 8.15234 1.75781 8.125 1.8125 8.125H5.3125C5.77734 8.125 6.1875 8.53516 6.1875 9C6.1875 9.49219 5.77734 9.875 5.3125 9.875H3.91797L4.38281 10.3672C6.10547 12.0625 8.86719 12.0625 10.5898 10.3672C11.0547 9.875 11.4102 9.32812 11.6016 8.72656C11.7656 8.26172 12.2852 8.01562 12.7227 8.17969C13.1875 8.34375 13.4336 8.83594 13.2695 9.30078C12.9688 10.1484 12.4766 10.9141 11.8203 11.5977C9.41406 13.9766 5.55859 13.9766 3.15234 11.5977L2.6875 11.1055V12.5C2.6875 12.9922 2.27734 13.375 1.8125 13.375C1.32031 13.375 0.9375 12.9922 0.9375 12.5V9.02734C0.9375 8.97266 0.9375 8.91797 0.9375 8.89062C0.9375 8.83594 0.9375 8.80859 0.964844 8.78125C0.992188 8.64453 1.07422 8.50781 1.18359 8.39844C1.29297 8.28906 1.42969 8.20703 1.56641 8.17969Z\"\n fill=\"currentColor\"\n />\n </svg>\n );\n}\n","import React from 'react';\n\nconst Icon: React.FC<React.SVGProps<SVGSVGElement>> = props => {\n return (\n <svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M9.05365 0C5.71033 0 3 2.75516 3 6.15377V15.6309C3 15.8346 3.16248 16 3.36328 16H5.05838C5.25898 16 5.42166 15.8346 5.42166 15.6309V11.0772C6.43342 11.8498 7.69104 12.3077 9.05385 12.3077C12.397 12.3077 15.1077 9.55259 15.1077 6.15397C15.1075 2.75516 12.397 0 9.05365 0ZM9.05365 9.84623C7.04766 9.84623 5.42146 8.19314 5.42146 6.15377C5.42146 4.1146 7.04766 2.46151 9.05365 2.46151C11.0596 2.46151 12.686 4.1146 12.686 6.15377C12.686 8.19293 11.0596 9.84623 9.05365 9.84623Z\"\n fill=\"currentColor\"\n />\n </svg>\n );\n};\n\nexport default Icon;\n","import React from 'react';\n\nconst Logo: React.FC<React.SVGProps<SVGSVGElement>> = props => {\n return (\n <svg\n width=\"102\"\n height=\"28\"\n viewBox=\"0 0 102 28\"\n fill=\"none\"\n {...props}\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M39.2674 2.19699C39.2757 2.18321 39.2839 2.16943 39.291 2.15528L39.2939 2.15057L39.2935 2.1502C39.3379 2.06208 39.3633 1.96308 39.3633 1.85754C39.3633 1.62109 39.2374 1.41474 39.0507 1.30231C39.0485 1.30014 39.0467 1.29651 39.0446 1.29578C35.1089 -0.88088 29.8537 -0.36627 26.3741 3.2632C24.4207 5.3006 23.4231 7.92116 23.3716 10.5544H23.3684V20.893C23.3684 21.2495 23.6538 21.5389 24.0058 21.5389H26.98C27.332 21.5389 27.6174 21.2495 27.6174 20.893V10.7698H27.6192C27.6192 9.14658 28.2169 7.52187 29.4209 6.26599C31.5699 4.02478 34.7423 3.8565 36.9299 5.03659C36.9367 5.04058 36.9439 5.04384 36.9507 5.04747C36.9557 5.05001 36.9607 5.05254 36.9657 5.05508H36.9664C37.0494 5.09497 37.1417 5.11782 37.2393 5.11782C37.4879 5.11782 37.7032 4.97276 37.808 4.76206L39.2674 2.19699Z\"\n fill=\"#4338CA\"\n />\n <path\n d=\"M10.6216 0.000244141C4.75551 0.000244141 0 4.82177 0 10.7693V27.3543C0 27.7108 0.285079 28.0002 0.637405 28.0002H3.61161C3.96358 28.0002 4.24902 27.7108 4.24902 27.3543V19.3853C6.02424 20.7373 8.23084 21.5388 10.622 21.5388C16.4878 21.5388 21.244 16.7173 21.244 10.7697C21.2437 4.82177 16.4878 0.000244141 10.6216 0.000244141ZM10.6216 17.2311C7.10196 17.2311 4.24866 14.3382 4.24866 10.7693C4.24866 7.20079 7.10196 4.30788 10.6216 4.30788C14.1413 4.30788 16.995 7.20079 16.995 10.7693C16.995 14.3379 14.1413 17.2311 10.6216 17.2311Z\"\n fill=\"#4338CA\"\n />\n <path\n d=\"M73.259 0C67.3932 0 62.6373 4.82152 62.6373 10.7691V27.3541C62.6373 27.7106 62.9228 28 63.2747 28H66.2489C66.6009 28 66.8863 27.7106 66.8863 27.3541V19.3854C68.6616 20.7374 70.8682 21.5389 73.2593 21.5389C79.1251 21.5389 83.8813 16.7174 83.8813 10.7698C83.881 4.82152 79.1248 0 73.259 0ZM73.259 17.2309C69.7393 17.2309 66.886 14.338 66.886 10.7691C66.886 7.20055 69.7393 4.30764 73.259 4.30764C76.7783 4.30764 79.632 7.20055 79.632 10.7691C79.632 14.3376 76.7783 17.2309 73.259 17.2309Z\"\n fill=\"#4338CA\"\n />\n <path\n d=\"M60.439 10.9845C60.439 5.03657 55.6827 0 49.817 0C43.9508 0 39.1953 4.82152 39.1953 10.7691C39.1953 16.7167 43.9508 21.5382 49.817 21.5382C53.1374 21.5382 55.8763 19.9954 57.5939 18.1031C57.5939 18.1031 57.5942 18.1027 57.5946 18.1024C57.596 18.1009 57.5975 18.0995 57.5985 18.098C57.7112 17.9812 57.7806 17.822 57.7806 17.6461C57.7806 17.4601 57.7026 17.2929 57.5785 17.1751V17.1743L57.5696 17.1671C57.5535 17.1522 57.5367 17.1384 57.5188 17.1254L55.2464 15.2501C55.1344 15.1503 54.9877 15.0891 54.8264 15.0891C54.6261 15.0891 54.4476 15.183 54.331 15.3291C53.3216 16.3707 51.7256 17.2309 49.8166 17.2309C46.2969 17.2309 43.4436 14.338 43.4436 10.7691C43.4436 7.20055 46.2969 4.30764 49.8166 4.30764C52.5909 4.30764 54.9505 6.10605 55.8255 8.61527H50.3474C49.9954 8.61527 49.71 8.90467 49.71 9.26152V12.277C49.71 12.6339 49.9954 12.9233 50.3474 12.9233H59.5884C59.6059 12.9233 59.6227 12.9218 59.6399 12.9207C59.6571 12.9222 59.6742 12.9233 59.6914 12.9233C59.9743 12.9233 60.214 12.7361 60.2973 12.4772L60.3045 12.4783C60.308 12.4551 60.3116 12.4326 60.3152 12.4097C60.3199 12.3876 60.3234 12.3655 60.3256 12.3427C60.4003 11.861 60.439 11.5172 60.439 10.9845Z\"\n fill=\"#4338CA\"\n />\n <path\n d=\"M101.928 2.15406L101.931 2.14934L101.93 2.14898C101.974 2.06085 102 1.96185 102 1.85632C102 1.61987 101.874 1.41351 101.687 1.30109C101.685 1.29891 101.683 1.29529 101.681 1.29456C97.7455 -0.882101 92.4903 -0.367491 89.0107 3.26198C87.0573 5.29938 86.0597 7.91993 86.0082 10.5532H86.005V20.8918C86.005 21.2483 86.2904 21.5377 86.6424 21.5377H89.6166C89.9686 21.5377 90.254 21.2483 90.254 20.8918V10.7686H90.2555C90.2555 9.14535 90.8532 7.52065 92.0571 6.26477C94.2062 4.02355 97.3785 3.85528 99.5662 5.03537C99.573 5.03936 99.5801 5.04262 99.5869 5.04624C99.5919 5.04878 99.5969 5.05132 99.6019 5.05386H99.6027C99.6856 5.09375 99.7779 5.11696 99.8756 5.11696C100.124 5.11696 100.339 4.9719 100.444 4.7612L101.905 2.19685C101.913 2.18235 101.92 2.16856 101.928 2.15406Z\"\n fill=\"#4338CA\"\n />\n </svg>\n );\n};\n\nexport default Logo;\n","'use client';\n\nimport React from 'react';\nimport Script from 'next/script';\n\ninterface PreprTrackingPixelProps {\n /**\n * The Prepr access token (without the full GraphQL URL)\n * Extract this from your PREPR_GRAPHQL_URL: https://graphql.prepr.io/YOUR_ACCESS_TOKEN\n */\n accessToken?: string;\n}\n\n/**\n * PreprTrackingPixel component for user tracking\n *\n * This component loads the Prepr tracking script and initializes tracking.\n * It should be included in your application to track user interactions.\n *\n * @param accessToken - Your Prepr access token\n *\n * @example\n * ```tsx\n * // In your layout or page\n *\n * import { PreprTrackingPixel } from '@preprio/prepr-nextjs/react'\n *\n * // Extract token from PREPR_GRAPHQL_URL\n * const accessToken = extractAccessToken(process.env.PREPR_GRAPHQL_URL!)\n *\n * export default function Layout({ children }) {\n * return (\n * <html>\n * <head>\n * <PreprTrackingPixel accessToken={accessToken!} />\n * </head>\n * <body>{children}</body>\n * </html>\n * )\n * }\n * ```\n */\nexport default function PreprTrackingPixel({\n accessToken,\n}: PreprTrackingPixelProps) {\n if (!accessToken) {\n console.warn(\n 'PreprTrackingPixel: accessToken is required for tracking to work'\n );\n return null;\n }\n\n return (\n <Script\n id=\"prepr-tracking-pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n ! function (e, t, p, r, n, a, s) {\n e[r] || ((n = e[r] = function () {\n n.process ? n.process.apply(n, arguments) : n.queue.push(arguments)\n }).queue = [], n.t = +new Date, (a = t.createElement(p)).async = 1, a.src = \"https://cdn.tracking.prepr.io/js/prepr_v2.min.js?t=\" + 864e5 * Math.ceil(new Date / 864e5), (s = t.getElementsByTagName(p)[0]).parentNode.insertBefore(a, s))\n }(window, document, \"script\", \"prepr\"), prepr(\"init\", \"${accessToken}\", { destinations: { googleTagManager: true } }), prepr(\"event\", \"pageload\");`,\n }}\n />\n );\n}\n","import React from 'react';\nimport { PreprSegment } from '../../../types';\nimport { useSegmentContext } from '../../contexts';\nimport { usePathname, useRouter