@maskedeng-tom/ssrsx
Version:
server side renderer with tsx
59 lines • 2.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCSSNesting = exports.useGlobalStyle = exports.useStyle = exports.useContext = exports.useSession = exports.useBody = exports.useServer = void 0;
const jsx_parser_1 = require("ssrsxjsx/jsx-parser");
const support_1 = require("../server/support");
const styleToString_1 = require("./styleToString/styleToString");
const shortId_1 = require("../lib/shortId");
const nestedStyleToString_1 = require("./styleToString/nestedStyleToString");
////////////////////////////////////////////////////////////////////////////////
// http server
const useServer = () => {
const server = (0, support_1.getServer)();
return (0, support_1.getHttpServer)(server);
};
exports.useServer = useServer;
////////////////////////////////////////////////////////////////////////////////
// body
const useBody = () => {
const server = (0, support_1.getServer)();
return (0, support_1.getBody)(server);
};
exports.useBody = useBody;
////////////////////////////////////////////////////////////////////////////////
// session
const useSession = () => {
const server = (0, support_1.getServer)();
return (0, support_1.getSession)(server);
};
exports.useSession = useSession;
////////////////////////////////////////////////////////////////////////////////
// user context
const useContext = () => {
return (0, support_1.getContext)();
};
exports.useContext = useContext;
////////////////////////////////////////////////////////////////////////////////
// Styles
const useStyle = (style) => {
const scope = (0, jsx_parser_1.getCurrentFcId)();
const scopeAttr = `data-ssrsx-fcid="${scope}"`;
const ssrsx = (0, jsx_parser_1.getCurrentSsrsx)();
const result = (0, styleToString_1.styleToString)(style, scopeAttr);
ssrsx === null || ssrsx === void 0 ? void 0 : ssrsx.styles.push(result);
};
exports.useStyle = useStyle;
const useGlobalStyle = (style) => {
const ssrsx = (0, jsx_parser_1.getCurrentSsrsx)();
const result = (0, styleToString_1.styleToString)(style);
ssrsx === null || ssrsx === void 0 ? void 0 : ssrsx.styles.push(result);
};
exports.useGlobalStyle = useGlobalStyle;
const useCSSNesting = (style) => {
const scope = (0, shortId_1.shortId)('sc');
const ssrsx = (0, jsx_parser_1.getCurrentSsrsx)();
ssrsx === null || ssrsx === void 0 ? void 0 : ssrsx.styles.push((0, nestedStyleToString_1.nestedStyleToString)(style, `data-ssrsx-css="${scope}"`));
return { 'data-ssrsx-css': scope };
};
exports.useCSSNesting = useCSSNesting;
//# sourceMappingURL=hooks.js.map