Skip to content

Readme + types #2

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
# CSS Layers
# css-layer-tree

Discover the composition of your CSS `@layer`s
Lay out the composition of your CSS `@layer` architecture. See which layers are used, where they are defined and how they are nested.

WORK IN PROGRESS | CHECK BACK SOON
## Installation

```
npm install @projectwallace/css-layer-tree
```

## Usage

```js
import { get_tree } from '@projectwallace/css-layer-tree'

let css = `
@import url("test.css") layer;
@import url("test.css") LAYER(test);
@layer anotherTest {
@layer moreTest {
@layer deepTest {}
}
};
/* anonymous @layer */
@layer {}
`

let tree = get_tree(css)
```

This example would result in this `tree`:

```js
;[
{
name: '__anonymous-1__',
locations: [{ line: 2, column: 3, start: 3, end: 33 }],
children: [],
},
{
name: 'test',
locations: [{ line: 3, column: 3, start: 36, end: 72 }],
children: [],
},
{
name: 'anotherTest',
locations: [{ line: 4, column: 3, start: 75, end: 148 }],
children: [
{
name: 'moreTest',
locations: [{ line: 5, column: 4, start: 99, end: 144 }],
children: [
{
name: 'deepTest',
locations: [{ line: 6, column: 5, start: 121, end: 139 }],
children: [],
},
],
},
],
},
]
```

## Related projects

- [Online CSS Layers visualizer](https://www.projectwallace.com/css-layers-visualizer) - See this library in action online!
- [CSS Analyzer](https://github.com/projectwallace/css-analyzer) - The best CSS analyzer that powers all analysis on [projectwallace.com](https://www.projectwallace.com)
17 changes: 17 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type CssNode } from "css-tree";

export type Location = {
line: number;
column: number;
start: number;
end: number;
}

export type TreeNode = {
name: string;
children: TreeNode[];
locations: Location[];
}

export function get_tree_from_ast(ast: CssNode): TreeNode['children'];
export function get_tree(css: string): TreeNode['children'];
Loading