Skip to content

Commit 42cefd7

Browse files
Improves style generation and defaults (#70)
* feat: integrate css-js-gen dependency and update styles in expressive-code-twoslash - Added css-js-gen as a workspace dependency in package.json. - Updated styles in styles.ts to utilize css-js-gen for CSS generation. - Enhanced color handling for various UI elements to improve theme support. - Refactored CSS styles for better maintainability and readability. - Updated installation documentation to reflect changes in configuration options. * feat: enhance styles with fallback colors and add changeset for css-js-gen package * fix: update code block syntax for clarity in installation instructions * feat: expand CSS Object types to include new types from csstype and update related functions * fix: update CSSRule interface to include string and number types for better flexibility
1 parent 640d7dd commit 42cefd7

10 files changed

Lines changed: 552 additions & 609 deletions

File tree

.changeset/green-chicken-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"expressive-code-twoslash": minor
3+
---
4+
5+
Introduces new css-js-gen package for stylesheet creation, and improves CSS styles

.changeset/hungry-onions-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"css-js-gen": patch
3+
---
4+
5+
Expands CSS Object types to include the new types from csstype

docs/src/content/docs/getting-started/installation.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ For more information on how to add to your Next.js config, see the [Expressive C
138138

139139
</Tabs>
140140

141-
142-
143141
### Config Options
144142

145143
Default config options shown.
@@ -157,7 +155,7 @@ ecTwoSlash({
157155
languages: ["ts", "tsx", "vue"],
158156
includeJsDoc: true,
159157
// @annotate: allowNonStandardJsDocTags is required for like this to work
160-
allowNonStandardJsDocTags: true,
158+
allowNonStandardJsDocTags: true,
161159
twoslashOptions: {
162160
compilerOptions: {
163161
moduleResolution: 100 satisfies ts.ModuleResolutionKind.Bundler,

packages/css-js-gen/src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import type {
44
CSSObject,
55
CSSProperties,
66
CSSRule,
7-
CSSValue,
87
StylesheetReturn,
98
} from "./types.ts";
109

1110
/**
1211
* Check if a value is a plain CSS property value
1312
*/
14-
function isCSSValue(value: unknown): value is CSSValue {
13+
function isCSSValue(value: unknown): value is string | number {
1514
return typeof value === "string" || typeof value === "number";
1615
}
1716

@@ -108,7 +107,7 @@ const UNITLESS_PROPERTIES = new Set([
108107
/**
109108
* Format a CSS property name and value
110109
*/
111-
function formatProperty(property: string, value: CSSValue): string {
110+
function formatProperty(property: string, value: string | number): string {
112111
let formattedValue: string | number = value;
113112

114113
if (typeof value === "number" && value !== 0) {
@@ -133,7 +132,7 @@ function generateProperties(
133132

134133
const props = Object.entries(properties)
135134
.filter(([, value]) => isCSSValue(value))
136-
.map(([prop, value]) => `${indentation}${formatProperty(prop, value as CSSValue)}`)
135+
.map(([prop, value]) => `${indentation}${formatProperty(prop, value as string | number)}`)
137136
.join(newline);
138137

139138
return props;
@@ -144,7 +143,7 @@ function generateProperties(
144143
*/
145144
function generateRule(
146145
selector: string,
147-
rule: CSSRule | CSSProperties,
146+
rule: CSSRule | CSSProperties | CSS.Properties | CSS.PropertiesHyphen,
148147
indent: string,
149148
level: number,
150149
options: Required<CSSGeneratorOptions>,
@@ -430,6 +429,5 @@ export type {
430429
CSSObject,
431430
CSSProperties,
432431
CSSRule,
433-
CSSValue,
434432
StylesheetReturn,
435433
} from "./types.ts";

packages/css-js-gen/src/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import type * as CSS from "csstype";
22

33
/**
4-
* CSS property values can be strings, numbers, or CSS variable references
4+
* CSS properties with camelCase and kebab-case notations
55
*/
6-
export type CSSValue = string | number;
6+
export interface CSSPropertiesOptions extends CSS.Properties, CSS.PropertiesHyphen {}
77

88
/**
99
* Standard CSS properties with kebab-case notation
1010
*/
1111
export type CSSProperties = {
12-
[property: string]: CSSValue;
12+
[property: string]: string | number | CSSProperties | CSSPropertiesOptions;
1313
};
1414

1515
/**
1616
* A CSS rule can contain properties and nested selectors
1717
*/
1818
export interface CSSRule {
19-
[key: string]: CSSValue | CSSRule | CSSProperties | CSS.Properties | CSS.PropertiesHyphen;
19+
[key: string]: string | number | CSSRule | CSSProperties | CSSPropertiesOptions;
2020
}
2121

2222
/**
2323
* CSS object structure supporting nested selectors and media queries
2424
*/
2525
export interface CSSObject {
26-
[selector: string]: CSSRule | CSSProperties;
26+
[selector: string]: CSSRule | CSSProperties | CSSPropertiesOptions;
2727
}
2828

2929
/**

packages/expressive-code-twoslash/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
},
4343
"type": "module",
4444
"dependencies": {
45+
"css-js-gen": "workspace:^",
4546
"mdast-util-from-markdown": "catalog:mdast",
4647
"mdast-util-gfm": "catalog:mdast",
4748
"mdast-util-to-hast": "catalog:mdast",

0 commit comments

Comments
 (0)