-
Notifications
You must be signed in to change notification settings - Fork 255
fix(tailwind): export STREAMDOWN_CLASSES and getSourceInline() for Tailwind v4 prefix support #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sleitor
wants to merge
3
commits into
vercel:main
Choose a base branch
from
sleitor:fix-450
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| "streamdown": patch | ||
| --- | ||
|
|
||
| fix(tailwind): export STREAMDOWN_CLASSES and getSourceInline() for Tailwind v4 prefix support | ||
|
|
||
| When using Tailwind v4's `prefix()` option, the Tailwind scanner cannot match | ||
| unprefixed class names in streamdown's dist files to the prefixed utilities it | ||
| generates (e.g. it looks for `tw:flex` but dist files only contain `flex`). | ||
|
|
||
| This patch adds a new `streamdown/tailwind` entry point that exports: | ||
| - `STREAMDOWN_CLASSES` – a readonly array of every Tailwind utility class used | ||
| by streamdown and its official plugins | ||
| - `getSourceInline(prefix?)` – returns a ready-to-paste Tailwind v4 | ||
| `@source inline(...)` directive with all classes, optionally prefixed | ||
|
|
||
| Users can now generate the correct `@source inline()` directive for their | ||
| prefix and add it to their CSS file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| /** | ||
| * Complete list of Tailwind CSS utility classes used by streamdown and its | ||
| * official plugins (@streamdown/code, @streamdown/math, @streamdown/mermaid, | ||
| * @streamdown/cjk). | ||
| * | ||
| * Use this list to configure Tailwind v4's `@source inline()` directive when | ||
| * you need a custom prefix. See the README for details. | ||
| */ | ||
| export const STREAMDOWN_CLASSES: readonly string[] = [ | ||
| "-mt-10", | ||
| "[&>p]:inline", | ||
| "[&_svg]:h-auto", | ||
| "[&_svg]:w-auto", | ||
| "[counter-increment:line_0]", | ||
| "[counter-reset:line]", | ||
| "[li_&]:pl-6", | ||
| "absolute", | ||
| "animate-spin", | ||
| "appearance-none", | ||
| "backdrop-blur-sm", | ||
| "before:[counter-increment:line]", | ||
| "before:content-[counter(line)]", | ||
| "before:font-mono", | ||
| "before:inline-block", | ||
| "before:mr-4", | ||
| "before:select-none", | ||
| "before:text-[13px]", | ||
| "before:text-muted-foreground/50", | ||
| "before:text-right", | ||
| "before:w-6", | ||
| "bg-[var(--sdm-bg,inherit]", | ||
| "bg-[var(--sdm-tbg)]", | ||
| "bg-background", | ||
| "bg-background/50", | ||
| "bg-background/80", | ||
| "bg-background/90", | ||
| "bg-background/95", | ||
| "bg-black/10", | ||
| "bg-muted", | ||
| "bg-muted/40", | ||
| "bg-muted/80", | ||
| "bg-primary", | ||
| "bg-red-100", | ||
| "bg-red-50", | ||
| "bg-sidebar", | ||
| "bg-sidebar/80", | ||
| "block", | ||
| "border", | ||
| "border-b", | ||
| "border-b-2", | ||
| "border-border", | ||
| "border-collapse", | ||
| "border-current", | ||
| "border-l-4", | ||
| "border-muted-foreground/30", | ||
| "border-red-200", | ||
| "border-sidebar", | ||
| "border-t", | ||
| "bottom-2", | ||
| "bottom-4", | ||
| "break-all", | ||
| "cursor-pointer", | ||
| "dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit)]", | ||
| "dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]", | ||
| "dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]", | ||
| "disabled:cursor-not-allowed", | ||
| "disabled:opacity-50", | ||
| "divide-border", | ||
| "divide-y", | ||
| "duration-150", | ||
| "duration-200", | ||
| "ease-out", | ||
| "fixed", | ||
| "flex", | ||
| "flex-1", | ||
| "flex-col", | ||
| "font-medium", | ||
| "font-mono", | ||
| "font-semibold", | ||
| "gap-1", | ||
| "gap-2", | ||
| "gap-4", | ||
| "group", | ||
| "group-hover:block", | ||
| "group-hover:opacity-100", | ||
| "h-4", | ||
| "h-8", | ||
| "h-[46px]", | ||
| "h-auto", | ||
| "h-full", | ||
| "hidden", | ||
| "hover:bg-background", | ||
| "hover:bg-muted", | ||
| "hover:bg-muted/40", | ||
| "hover:bg-primary/90", | ||
| "hover:text-foreground", | ||
| "inline-block", | ||
| "inset-0", | ||
| "italic", | ||
| "items-center", | ||
| "justify-between", | ||
| "justify-center", | ||
| "justify-end", | ||
| "left-2", | ||
| "left-4", | ||
| "list-decimal", | ||
| "list-disc", | ||
| "list-inside", | ||
| "lowercase", | ||
| "max-h-32", | ||
| "max-w-full", | ||
| "max-w-md", | ||
| "mb-2", | ||
| "min-h-28", | ||
| "min-h-[200px]", | ||
| "min-w-[120px]", | ||
| "ml-1", | ||
| "mt-1", | ||
| "mt-2", | ||
| "mt-6", | ||
| "mx-4", | ||
| "my-4", | ||
| "my-6", | ||
| "opacity-0", | ||
| "origin-center", | ||
| "overflow-hidden", | ||
| "overflow-x-auto", | ||
| "overflow-y-auto", | ||
| "overscroll-y-auto", | ||
| "p-1", | ||
| "p-1.5", | ||
| "p-2", | ||
| "p-3", | ||
| "p-4", | ||
| "p-6", | ||
| "pl-4", | ||
| "pointer-events-auto", | ||
| "pointer-events-none", | ||
| "px-1.5", | ||
| "px-3", | ||
| "px-4", | ||
| "py-0.5", | ||
| "py-1", | ||
| "py-2", | ||
| "relative", | ||
| "right-0", | ||
| "right-2", | ||
| "right-4", | ||
| "rounded", | ||
| "rounded-full", | ||
| "rounded-lg", | ||
| "rounded-md", | ||
| "rounded-xl", | ||
| "shadow-lg", | ||
| "shadow-sm", | ||
| "shrink-0", | ||
| "size-4", | ||
| "size-full", | ||
| "space-x-2", | ||
| "space-y-2", | ||
| "space-y-4", | ||
| "sticky", | ||
| "supports-[backdrop-filter]:backdrop-blur", | ||
| "supports-[backdrop-filter]:backdrop-blur-sm", | ||
| "supports-[backdrop-filter]:bg-background/70", | ||
| "supports-[backdrop-filter]:bg-sidebar/70", | ||
| "text-2xl", | ||
| "text-3xl", | ||
| "text-[var(--sdm-c,inherit)]", | ||
| "text-base", | ||
| "text-left", | ||
| "text-lg", | ||
| "text-muted-foreground", | ||
| "text-primary", | ||
| "text-primary-foreground", | ||
| "text-red-600", | ||
| "text-red-700", | ||
| "text-red-800", | ||
| "text-sm", | ||
| "text-xl", | ||
| "text-xs", | ||
| "top-2", | ||
| "top-4", | ||
| "top-full", | ||
| "transition-all", | ||
| "transition-colors", | ||
| "transition-transform", | ||
| "w-4", | ||
| "w-8", | ||
| "w-full", | ||
| "whitespace-normal", | ||
| "whitespace-nowrap", | ||
| "wrap-anywhere", | ||
| "z-10", | ||
| "z-50", | ||
| ] as const; | ||
|
|
||
| /** | ||
| * Generates a Tailwind v4 `@source inline()` directive containing all | ||
| * streamdown classes, optionally prefixed. | ||
| * | ||
| * @param prefix - Tailwind v4 prefix string (e.g. `"tw"` for `prefix(tw)`). | ||
| * Omit or pass `undefined` when you are not using a prefix. | ||
| * @returns A ready-to-paste CSS `@source inline(...)` rule string. | ||
| * | ||
| * @example | ||
| * // In a postcss.config.js build script, write this string to a CSS file: | ||
| * import { getSourceInline } from 'streamdown/tailwind'; | ||
| * console.log(getSourceInline('tw')); | ||
| * // → @source inline("tw:{absolute,animate-spin,...}"); | ||
| */ | ||
| export function getSourceInline(prefix?: string): string { | ||
| const names = [...STREAMDOWN_CLASSES]; | ||
| const body = prefix | ||
| ? `${prefix}:{${names.join(",")}}` | ||
| : `{${names.join(",")}}`; | ||
| return `@source inline("${body}");`; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STREAMDOWN_CLASSES array is missing 6 Tailwind CSS utility classes (
[&_thead]:sticky,[&_thead]:top-0,[&_thead]:z-10,overflow-auto,pt-0,underline) that are actively used in the source code, causing those styles to be absent when using Tailwind v4 prefix scanning.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — added 20 missing utility classes that are actively used in the source but were absent from the array:
-mt-10,[&>p]:inline,[&_svg]:h-auto,[&_svg]:w-auto,[counter-increment:line_0],[counter-reset:line],[li_&]:pl-6,before:content-[counter(line)],bg-[var(--sdm-bg,inherit],bg-[var(--sdm-tbg)],border,dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit)],dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))],dark:text-[var(--shiki-dark,var(--sdm-c,inherit))],list-decimal,list-disc,list-inside,rounded,sticky,text-[var(--sdm-c,inherit)]