Add fonts, autotable, autotable examples

This commit is contained in:
2026-07-13 13:01:26 -04:00
parent ea3d2a6d03
commit cf8342f8d4
71 changed files with 16084 additions and 1443 deletions

View File

@@ -1420,6 +1420,14 @@ func twCompile(input, baseDir string, candidates []string) (string, int, error)
if e != nil {
return "", 0, e
}
// The preflight is written against Tailwind's compile-time CSS functions —
// `font-family: --theme(--default-font-family, …)` and five more like it. They
// have to be resolved here, exactly as the theme's own declarations are above.
// Left in, `--theme(…)` reaches the browser verbatim, which cannot parse it and
// so DROPS THE WHOLE DECLARATION: html ends up with no font-family at all and
// falls back to the browser default, and no @theme override of --font-sans can
// ever take effect.
substituteFunctions(pfAst, ds)
out = append(out, atRule("@layer", "base", pfAst...))
}

View File

@@ -215,3 +215,61 @@ func TestExtractCandidatesRegexLiterals(t *testing.T) {
}
}
}
// The preflight is written against Tailwind's compile-time CSS functions, e.g.
// `font-family: --theme(--default-font-family, …)`. If those are not resolved, they
// reach the browser verbatim; the browser cannot parse `--theme(…)` and DROPS THE
// WHOLE DECLARATION. The symptom is subtle and global: every page silently loses its
// font-family and falls back to the browser default, and no @theme override of
// --font-sans can ever take effect. That shipped for a while, so pin it.
func TestPreflightResolvesThemeFunctions(t *testing.T) {
css, _, err := twCompile(`@import "tailwindcss";`, ".", nil)
if err != nil {
t.Fatal(err)
}
flat := strings.Join(strings.Fields(css), " ")
if strings.Contains(css, "--theme(") {
t.Error("the compiled CSS still contains an unresolved --theme(…); the browser will drop those declarations")
}
if !strings.Contains(flat, "font-family: var(--default-font-family)") {
t.Error("preflight did not resolve html's font-family to a var()")
}
}
// And the whole point of resolving it: an app's @theme override of --font-sans must
// actually reach the page.
func TestThemeFontOverrideReachesHTML(t *testing.T) {
css, _, err := twCompile(`
@import "tailwindcss";
@font-face {
font-family: "Lora";
src: url("/fonts/lora.woff2") format("woff2");
}
@theme {
--font-sans: "Lora", serif;
}
`, ".", nil)
if err != nil {
t.Fatal(err)
}
// The chain the browser walks: html -> --default-font-family -> --font-sans.
flat := strings.Join(strings.Fields(css), " ")
for _, want := range []string{
"font-family: var(--default-font-family)",
"--default-font-family: var(--font-sans)",
`--font-sans: "Lora", serif`,
} {
if !strings.Contains(flat, want) {
t.Errorf("missing %q — the font override does not reach the page", want)
}
}
// A vendored face must survive the build; dropping it would leave the family
// declared but never loaded.
if !strings.Contains(css, "@font-face") || !strings.Contains(css, "lora.woff2") {
t.Error("@font-face was dropped from the output")
}
}