UNPKG

vlibras-player-webjs

Version:

Biblioteca JavaScript moderna para integração do VLibras Player com React, Vue, Angular e vanilla JS

96 lines 3.78 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { NoSSR } from './NoSSR'; import { SSRSafeVLibrasProvider } from './SSRSafeProvider'; import { withVLibrasNoSSR } from './withNoSSR'; // Importação condicional do NextJS dynamic let nextDynamic = null; try { // eslint-disable-next-line @typescript-eslint/no-var-requires nextDynamic = require('next/dynamic'); } catch { // NextJS não disponível } /** * Provider VLibras otimizado para NextJS * Automaticamente configura caminhos e comportamentos específicos do NextJS */ export const NextJSVLibrasProvider = ({ publicAssetsPath = '/vlibras', children, config, ...props }) => { const mergedConfig = { assetsPath: publicAssetsPath, ...config }; return (_jsx(SSRSafeVLibrasProvider, { config: mergedConfig, ...props, children: children })); }; /** * Hook para criar componentes VLibras dinâmicos no NextJS */ export function useNextJSDynamicVLibras(componentImport, options = {}) { if (!nextDynamic) { throw new Error('NextJS dynamic import não está disponível. Certifique-se de estar usando NextJS.'); } return nextDynamic(componentImport, { ssr: options.ssr ?? false, loading: options.loading || (() => (_jsx("div", { className: "vlibras-loading-nextjs", children: "Carregando VLibras..." }))) }); } /** * Cria uma versão dinâmica de um componente VLibras para NextJS */ export function createNextJSVLibrasComponent(Component, options = {}) { if (options.ssr === false && nextDynamic) { // Usa dynamic import do NextJS se disponível return nextDynamic(() => Promise.resolve(Component), { ssr: false, loading: options.loading || (() => (_jsx("div", { className: "vlibras-loading-nextjs", children: "Carregando VLibras..." }))) }); } // Usa nosso wrapper NoSSR como fallback return withVLibrasNoSSR(Component, options.fallback); } /** * Utilitários para páginas NextJS */ export const NextJSUtils = { /** * getStaticProps helper para VLibras */ getVLibrasStaticProps: () => ({ props: { vlibrasConfig: { assetsPath: '/vlibras', ssr: false } } }), /** * getServerSideProps helper para VLibras */ getVLibrasServerSideProps: () => ({ props: { vlibrasConfig: { assetsPath: '/vlibras', ssr: false } } }), /** * Head tags para VLibras */ VLibrasHeadTags: () => (_jsxs(_Fragment, { children: [_jsx("link", { rel: "preload", href: "/vlibras/playerweb.data.unityweb", as: "fetch", crossOrigin: "anonymous" }), _jsx("link", { rel: "preload", href: "/vlibras/playerweb.wasm.code.unityweb", as: "fetch", crossOrigin: "anonymous" }), _jsx("link", { rel: "preload", href: "/vlibras/playerweb.wasm.framework.unityweb", as: "fetch", crossOrigin: "anonymous" }), _jsx("meta", { name: "vlibras-ssr-safe", content: "true" })] })) }; /** * Componente wrapper para páginas NextJS */ export function NextJSPageWrapper({ children, vlibrasConfig }) { return (_jsx(NextJSVLibrasProvider, { ...vlibrasConfig, children: _jsx(NoSSR, { fallback: _jsx("div", { children: "Carregando recursos de acessibilidade..." }), children: children }) })); } /** * HOC para páginas NextJS com VLibras */ export function withNextJSVLibras(Page, vlibrasConfig) { const WrappedPage = (props) => (_jsx(NextJSPageWrapper, { vlibrasConfig: vlibrasConfig, children: _jsx(Page, { ...props }) })); WrappedPage.displayName = `withNextJSVLibras(${Page.displayName || Page.name})`; return WrappedPage; } //# sourceMappingURL=NextJSCompatibility.js.map