vlibras-player-webjs
Version:
Biblioteca JavaScript moderna para integração do VLibras Player com React, Vue, Angular e vanilla JS
104 lines • 4.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NextJSUtils = exports.NextJSVLibrasProvider = void 0;
exports.useNextJSDynamicVLibras = useNextJSDynamicVLibras;
exports.createNextJSVLibrasComponent = createNextJSVLibrasComponent;
exports.NextJSPageWrapper = NextJSPageWrapper;
exports.withNextJSVLibras = withNextJSVLibras;
const jsx_runtime_1 = require("react/jsx-runtime");
const NoSSR_1 = require("./NoSSR");
const SSRSafeProvider_1 = require("./SSRSafeProvider");
const withNoSSR_1 = require("./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
*/
const NextJSVLibrasProvider = ({ publicAssetsPath = '/vlibras', children, config, ...props }) => {
const mergedConfig = {
assetsPath: publicAssetsPath,
...config
};
return ((0, jsx_runtime_1.jsx)(SSRSafeProvider_1.SSRSafeVLibrasProvider, { config: mergedConfig, ...props, children: children }));
};
exports.NextJSVLibrasProvider = NextJSVLibrasProvider;
/**
* Hook para criar componentes VLibras dinâmicos no NextJS
*/
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 || (() => ((0, jsx_runtime_1.jsx)("div", { className: "vlibras-loading-nextjs", children: "Carregando VLibras..." })))
});
}
/**
* Cria uma versão dinâmica de um componente VLibras para NextJS
*/
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 || (() => ((0, jsx_runtime_1.jsx)("div", { className: "vlibras-loading-nextjs", children: "Carregando VLibras..." })))
});
}
// Usa nosso wrapper NoSSR como fallback
return (0, withNoSSR_1.withVLibrasNoSSR)(Component, options.fallback);
}
/**
* Utilitários para páginas NextJS
*/
exports.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: () => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("link", { rel: "preload", href: "/vlibras/playerweb.data.unityweb", as: "fetch", crossOrigin: "anonymous" }), (0, jsx_runtime_1.jsx)("link", { rel: "preload", href: "/vlibras/playerweb.wasm.code.unityweb", as: "fetch", crossOrigin: "anonymous" }), (0, jsx_runtime_1.jsx)("link", { rel: "preload", href: "/vlibras/playerweb.wasm.framework.unityweb", as: "fetch", crossOrigin: "anonymous" }), (0, jsx_runtime_1.jsx)("meta", { name: "vlibras-ssr-safe", content: "true" })] }))
};
/**
* Componente wrapper para páginas NextJS
*/
function NextJSPageWrapper({ children, vlibrasConfig }) {
return ((0, jsx_runtime_1.jsx)(exports.NextJSVLibrasProvider, { ...vlibrasConfig, children: (0, jsx_runtime_1.jsx)(NoSSR_1.NoSSR, { fallback: (0, jsx_runtime_1.jsx)("div", { children: "Carregando recursos de acessibilidade..." }), children: children }) }));
}
/**
* HOC para páginas NextJS com VLibras
*/
function withNextJSVLibras(Page, vlibrasConfig) {
const WrappedPage = (props) => ((0, jsx_runtime_1.jsx)(NextJSPageWrapper, { vlibrasConfig: vlibrasConfig, children: (0, jsx_runtime_1.jsx)(Page, { ...props }) }));
WrappedPage.displayName = `withNextJSVLibras(${Page.displayName || Page.name})`;
return WrappedPage;
}
//# sourceMappingURL=NextJSCompatibility.js.map