fix(plugin/twind): load configuration as module (#705)

This commit loads the Twind configuration as an actual module rather
than evaluating it on the server and then serializing. This allows usage
of unserializable plugin functions.

Co-authored-by: Elias Sjögreen <eliassjogreen1@gmail.com>
This commit is contained in:
Luca Casonato
2022-09-07 00:44:46 +02:00
committed by GitHub
co-authored by Elias Sjögreen
parent 8e9658cae5
commit 1b3c9f2569
7 changed files with 30 additions and 54 deletions
+5 -5
View File
@@ -1,13 +1,13 @@
import { Sheet } from "twind";
import { Options, setup, STYLE_ELEMENT_ID } from "./shared.ts";
type State = [Options, string[], [string, string][]];
type State = [string[], [string, string][]];
export default function hydrate(state: State) {
export default function hydrate(options: Options, state: State) {
const el = document.getElementById(STYLE_ELEMENT_ID) as HTMLStyleElement;
const rules = new Set(el.innerText.split("\n"));
const precedences = state[1];
const mappings = new Map(state[2]
const precedences = state[0];
const mappings = new Map(state[1]
.map((v) => typeof v === "string" ? [v, v] : v));
// deno-lint-ignore no-explicit-any
const sheetState: any[] = [precedences, rules, mappings, true];
@@ -17,5 +17,5 @@ export default function hydrate(state: State) {
insert: (rule, index) => target.insertRule(rule, index),
init: (cb) => cb(sheetState.shift()),
};
setup(state[0], sheet);
setup(options, sheet);
}