UNPKG

aura-glass

Version:

A comprehensive glassmorphism design system for React applications with 142+ production-ready components

142 lines (139 loc) 3.57 kB
import { jsx } from 'react/jsx-runtime'; import { useReducer, useCallback, useMemo, useContext, createContext } from 'react'; import { DEFAULT_CONSCIOUSNESS_CONFIG } from '../types/consciousness.js'; const mergeConfigs = (base, update) => ({ ...base, ...update, features: { ...base.features, ...update.features }, performance: { ...base.performance, ...update.performance }, privacy: { ...base.privacy, ...update.privacy }, accessibility: { ...base.accessibility, ...update.accessibility } }); const streamReducer = (state, action) => { switch (action.type) { case 'updateConfig': return { ...state, config: mergeConfigs(state.config, action.payload) }; case 'updateFeature': return { ...state, config: { ...state.config, features: { ...state.config.features, [action.feature]: action.value } } }; case 'logEvent': return { ...state, events: [...state.events, action.event].slice(-200) }; case 'clearEvents': return { ...state, events: [] }; case 'mergeHandlers': return { ...state, handlers: { ...state.handlers, ...action.handlers } }; default: return state; } }; const createEventId = () => `cse-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`; const ConsciousnessStreamContext = /*#__PURE__*/createContext(null); function ConsciousnessStreamProvider({ children, config, handlers, initialEvents = [] }) { const [state, dispatch] = useReducer(streamReducer, { config: mergeConfigs(DEFAULT_CONSCIOUSNESS_CONFIG, config ?? {}), handlers: handlers ?? {}, events: initialEvents.slice(-200) }); const updateConfig = useCallback(partial => { dispatch({ type: 'updateConfig', payload: partial }); }, []); const updateFeature = useCallback((feature, enabled) => { dispatch({ type: 'updateFeature', feature, value: enabled }); }, []); const logEvent = useCallback(eventInput => { const event = { id: eventInput.id ?? createEventId(), timestamp: eventInput.timestamp ?? Date.now(), feature: eventInput.feature, payload: eventInput.payload, confidence: eventInput.confidence, status: eventInput.status }; dispatch({ type: 'logEvent', event }); return event; }, []); const clearEvents = useCallback(() => { dispatch({ type: 'clearEvents' }); }, []); const registerHandlers = useCallback(partial => { dispatch({ type: 'mergeHandlers', handlers: partial }); }, []); const value = useMemo(() => ({ config: state.config, handlers: state.handlers, events: state.events, updateConfig, updateFeature, logEvent, clearEvents, registerHandlers }), [state.config, state.handlers, state.events, updateConfig, updateFeature, logEvent, clearEvents, registerHandlers]); return jsx(ConsciousnessStreamContext.Provider, { value: value, children: children }); } function useConsciousnessStream() { const context = useContext(ConsciousnessStreamContext); if (!context) { throw new Error('useConsciousnessStream must be used within a ConsciousnessStreamProvider'); } return context; } export { ConsciousnessStreamProvider, useConsciousnessStream }; //# sourceMappingURL=ConsciousnessStreamProvider.js.map