-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.ts
More file actions
30 lines (27 loc) · 813 Bytes
/
options.ts
File metadata and controls
30 lines (27 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {
FreshOptions,
InnerRenderFunction,
RenderContext,
} from "$fresh/server.ts";
import { config, setup } from "@twind";
import { virtualSheet } from "twind/sheets";
const sheet = virtualSheet();
sheet.reset();
setup({ ...config, sheet });
function render(ctx: RenderContext, render: InnerRenderFunction) {
const snapshot = ctx.state.get("twind") as unknown[] | null;
sheet.reset(snapshot || undefined);
render();
ctx.styles.splice(0, ctx.styles.length, ...sheet.target);
const newSnapshot = sheet.reset();
ctx.styles.push(`/*${JSON.stringify(newSnapshot[1])}*/`);
ctx.styles.push(
`/*${
JSON.stringify([
...(newSnapshot[3] as Map<string, string>).entries(),
])
}*/`,
);
ctx.state.set("twind", newSnapshot);
}
export default { render } as FreshOptions;