@m3e/toc 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 matraic
4
+ Contact: matraic@yahoo.com
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # @m3e/toc
2
+
3
+ The `m3e-toc` and `m3e-toc-item` components provide a hierarchical, interactive table of contents for in-page navigation. The TOC automatically detects headings or sections in a target element, builds a navigable list, and highlights the active section as the user scrolls. It supports custom header slots, depth limiting, smooth scrolling, and extensive theming via CSS custom properties.
4
+
5
+ > To exclude a heading from the generated table of contents, add the `m3e-toc-ignore` attribute to that heading element.
6
+
7
+ > **Part of the [M3E](../../README.md) monorepo**
8
+ > This package is maintained within the unified M3E repository, which provides a suite of Material 3 web components.
9
+
10
+ ## ๐Ÿ“ฆ Installation
11
+
12
+ ```bash
13
+ npm install @m3e/toc
14
+ ```
15
+
16
+ ## ๐Ÿ’ป Editor Integration
17
+
18
+ This package includes a [Custom Elements Manifest](https://github.com/webcomponents/custom-elements-manifest) to support enhanced editor tooling and developer experience.
19
+
20
+ ### Visual Studio Code
21
+
22
+ To enable autocomplete and hover documentation for `@m3e/toc`, install the [Custom Elements Manifest Language Server](https://marketplace.visualstudio.com/items?itemName=pwrs.cem-language-server-vscode) extension. It will automatically detect the manifest bundled with this package and surface tag names, attributes, slots, and events in supported files.
23
+
24
+ Alternately, you can explicitly reference the `html-custom-data.json` and `css-custom-data.json` in your workspace settings:
25
+
26
+ ```json
27
+ {
28
+ "html.customData": ["./node_modules/@m3e/toc/dist/html-custom-data.json"],
29
+ "css.customData": ["./node_modules/@m3e/toc/dist/css-custom-data.json"]
30
+ }
31
+ ```
32
+
33
+ ## ๐Ÿš€ Browser Usage
34
+
35
+ This package uses [JavaScript Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#module_specifiers). To use it directly in a browser without a bundler, use a module script similar to the following.
36
+
37
+ ```html
38
+ <script type="module" src="/node_modules/@m3e/toc/dist/index.js"></script>
39
+ ```
40
+
41
+ In addition, you must use an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap) to include dependencies.
42
+
43
+ ```html
44
+ <script type="importmap">
45
+ {
46
+ "imports": {
47
+ "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
48
+ "@m3e/core": "/node_modules/@m3e/core/dist/index.js",
49
+ "@m3e/core/a11y": "/node_modules/@m3e/core/dist/a11y.js"
50
+ }
51
+ }
52
+ </script>
53
+ ```
54
+
55
+ > For production, use index.min.js and a11y.min.js for faster load times.
56
+
57
+ ## ๐Ÿ—‚๏ธ Elements
58
+
59
+ - `m3e-toc` โ€” A table of contents navigation component for in-page scroll navigation.
60
+ - `m3e-toc-item` โ€” An item representing a section or heading in the table of contents.
61
+
62
+ ## ๐Ÿงช Example
63
+
64
+ ```html
65
+ <m3e-toc for="content" max-depth="3">
66
+ <span slot="overline">Contents</span>
67
+ <span slot="title">Documentation</span>
68
+ </m3e-toc>
69
+ <div id="content">
70
+ <h2>Introduction</h2>
71
+ <h2>Getting Started</h2>
72
+ <h3>Installation</h3>
73
+ <h3>Usage</h3>
74
+ <h2>API Reference</h2>
75
+ </div>
76
+ ```
77
+
78
+ ## ๐Ÿ“– API Reference
79
+
80
+ ### ๐Ÿ—‚๏ธ m3e-toc
81
+
82
+ #### โš™๏ธ Attributes
83
+
84
+ | Attribute | Type | Default | Description |
85
+ | ----------- | -------- | ------- | -------------------------------------------------------- |
86
+ | `for` | `string` | | Query selector for the element to generate the TOC from. |
87
+ | `max-depth` | `number` | `2` | The maximum depth of the table of contents. |
88
+
89
+ #### ๐Ÿงฉ Slots
90
+
91
+ | Slot | Description |
92
+ | ----------- | ---------------------------------------------- |
93
+ | _(default)_ | Renders content between the header and items. |
94
+ | `overline` | Renders the overline of the table of contents. |
95
+ | `title` | Renders the title of the table of contents. |
96
+
97
+ #### ๐ŸŽ›๏ธ CSS Custom Properties
98
+
99
+ | Property | Description |
100
+ | ----------------------------------------------- | ------------------------------------------------ |
101
+ | `--m3e-toc-width` | Width of the table of contents. |
102
+ | `--m3e-toc-item-shape` | Border radius of TOC items and active indicator. |
103
+ | `--m3e-toc-active-indicator-color` | Border color of the active indicator. |
104
+ | `--m3e-toc-active-indicator-animation-duration` | Animation duration for the active indicator. |
105
+ | `--m3e-toc-item-padding` | Inline padding for TOC items and header. |
106
+ | `--m3e-toc-header-space` | Block space below and between header elements. |
107
+ | `--m3e-toc-overline-font-size` | Font size for the overline slot. |
108
+ | `--m3e-toc-overline-font-weight` | Font weight for the overline slot. |
109
+ | `--m3e-toc-overline-line-height` | Line height for the overline slot. |
110
+ | `--m3e-toc-overline-tracking` | Letter spacing for the overline slot. |
111
+ | `--m3e-toc-overline-color` | Text color for the overline slot. |
112
+ | `--m3e-toc-title-font-size` | Font size for the title slot. |
113
+ | `--m3e-toc-title-font-weight` | Font weight for the title slot. |
114
+ | `--m3e-toc-title-line-height` | Line height for the title slot. |
115
+ | `--m3e-toc-title-tracking` | Letter spacing for the title slot. |
116
+ | `--m3e-toc-title-color` | Text color for the title slot. |
117
+
118
+ ### ๐Ÿ—‚๏ธ m3e-toc-item
119
+
120
+ #### โš™๏ธ Attributes
121
+
122
+ | Attribute | Type | Default | Description |
123
+ | ---------- | --------- | ------- | ----------------------------- |
124
+ | `disabled` | `boolean` | `false` | Whether the item is disabled. |
125
+ | `selected` | `boolean` | `false` | Whether the item is selected. |
126
+
127
+ #### ๐Ÿงฉ Slots
128
+
129
+ | Slot | Description |
130
+ | ----------- | ------------------------------ |
131
+ | _(default)_ | Renders the label of the item. |
132
+
133
+ #### ๐ŸŽ›๏ธ CSS Custom Properties
134
+
135
+ | Property | Description |
136
+ | ----------------------------------------------- | -------------------------------------------- |
137
+ | `--m3e-toc-item-shape` | Border radius of the TOC item. |
138
+ | `--m3e-toc-item-padding-block` | Block padding for the TOC item. |
139
+ | `--m3e-toc-item-padding` | Inline padding for the TOC item. |
140
+ | `--m3e-toc-item-inset` | Indentation per level for the TOC item. |
141
+ | `--m3e-toc-active-indicator-animation-duration` | Animation duration for the active indicator. |
142
+ | `--m3e-toc-item-font-size` | Font size for unselected items. |
143
+ | `--m3e-toc-item-font-weight` | Font weight for unselected items. |
144
+ | `--m3e-toc-item-line-height` | Line height for unselected items. |
145
+ | `--m3e-toc-item-tracking` | Letter spacing for unselected items. |
146
+ | `--m3e-toc-item-color` | Text color for unselected items. |
147
+ | `--m3e-toc-item-selected-font-size` | Font size for selected items. |
148
+ | `--m3e-toc-item-selected-font-weight` | Font weight for selected items. |
149
+ | `--m3e-toc-item-selected-line-height` | Line height for selected items. |
150
+ | `--m3e-toc-item-selected-tracking` | Letter spacing for selected items. |
151
+ | `--m3e-toc-item-selected-color` | Text color for selected items. |
152
+ | `--m3e-state-layer-focus-opacity` | Opacity of the state layer focus effect. |
153
+
154
+ ## ๐Ÿค Contributing
155
+
156
+ See the root monorepo `CONTRIBUTING.md` for guidelines on contributing to this package.
157
+
158
+ ## ๐Ÿ“„ License
159
+
160
+ This package is licensed under the MIT License.
package/cem.config.mjs ADDED
@@ -0,0 +1,16 @@
1
+ import { customElementVsCodePlugin } from "custom-element-vs-code-integration";
2
+
3
+ export default {
4
+ globs: ["src/**/*.ts"],
5
+ exclude: ["src/**/*.spec.ts"],
6
+ packagejson: true,
7
+ outdir: "dist",
8
+ litelement: true,
9
+ plugins: [
10
+ customElementVsCodePlugin({
11
+ outdir: "dist",
12
+ htmlFileName: "html-custom-data.json",
13
+ cssFileName: "css-custom-data.json",
14
+ }),
15
+ ],
16
+ };
@@ -0,0 +1,60 @@
1
+ <!doctype html>
2
+ <html lang="en" style="overflow-y: auto">
3
+ <head>
4
+ <title>Table of Contents for M3E</title>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="description" content="Table of Contents for M3E" />
8
+ <base href="./" />
9
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
10
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
11
+ <link
12
+ href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap"
13
+ rel="stylesheet"
14
+ />
15
+ <link
16
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0..1,0"
17
+ rel="stylesheet"
18
+ />
19
+ <script type="importmap">
20
+ {
21
+ "imports": {
22
+ "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
23
+ "@m3e/core": "../../core/dist/index.min.js",
24
+ "@m3e/core/a11y": "../../core/dist/a11y.min.js"
25
+ }
26
+ }
27
+ </script>
28
+ <script type="module" src="../../theme/dist/index.min.js"></script>
29
+ <script type="module" src="../dist/index.min.js"></script>
30
+ <style>
31
+ body {
32
+ font-family: "Roboto";
33
+ }
34
+ *:not(:defined) {
35
+ display: none;
36
+ }
37
+ </style>
38
+ </head>
39
+ <body>
40
+ <m3e-theme strong-focus>
41
+ <div
42
+ id="d1"
43
+ style="display: flex; flex-direction: column; overflow-y: auto; position: relative; max-height: 250px"
44
+ >
45
+ <m3e-toc for="d1" style="position: sticky; top: 0; margin-left: auto">
46
+ <span slot="overline">A long overline that should not wrap</span>
47
+ <span slot="title">A long title that should wrap to multiple lines</span>
48
+ </m3e-toc>
49
+
50
+ <div style="position: absolute">
51
+ <h2 id="h1" style="margin-bottom: 100px">Heading 1</h2>
52
+ <h3 id="h1.1" style="margin-bottom: 100px">Heading 1.1</h3>
53
+ <h4 id="h1.1.1" style="margin-bottom: 100px">Heading 1.1.1</h4>
54
+ <h3 id="h2" style="margin-bottom: 100px">Heading 1.2</h3>
55
+ <h2 id="h2.1" style="margin-bottom: 100px">Heading 2</h2>
56
+ </div>
57
+ </div>
58
+ </m3e-theme>
59
+ </body>
60
+ </html>
@@ -0,0 +1,162 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/microsoft/vscode-css-languageservice/main/docs/customData.schema.json",
3
+ "version": 1.1,
4
+ "properties": [
5
+ {
6
+ "name": "--m3e-toc-width",
7
+ "description": "Width of the table of contents.",
8
+ "values": []
9
+ },
10
+ {
11
+ "name": "--m3e-toc-item-shape",
12
+ "description": "Border radius of TOC items and active indicator.",
13
+ "values": []
14
+ },
15
+ {
16
+ "name": "--m3e-toc-active-indicator-color",
17
+ "description": "Border color of the active indicator.",
18
+ "values": []
19
+ },
20
+ {
21
+ "name": "--m3e-toc-active-indicator-animation-duration",
22
+ "description": "Animation duration for the active indicator.",
23
+ "values": []
24
+ },
25
+ {
26
+ "name": "--m3e-toc-item-padding",
27
+ "description": "Inline padding for TOC items and header.",
28
+ "values": []
29
+ },
30
+ {
31
+ "name": "--m3e-toc-header-space",
32
+ "description": "Block space below and between header elements.",
33
+ "values": []
34
+ },
35
+ {
36
+ "name": "--m3e-toc-overline-font-size",
37
+ "description": "Font size for the overline slot.",
38
+ "values": []
39
+ },
40
+ {
41
+ "name": "--m3e-toc-overline-font-weight",
42
+ "description": "Font weight for the overline slot.",
43
+ "values": []
44
+ },
45
+ {
46
+ "name": "--m3e-toc-overline-line-height",
47
+ "description": "Line height for the overline slot.",
48
+ "values": []
49
+ },
50
+ {
51
+ "name": "--m3e-toc-overline-tracking",
52
+ "description": "Letter spacing for the overline slot.",
53
+ "values": []
54
+ },
55
+ {
56
+ "name": "--m3e-toc-overline-color",
57
+ "description": "Text color for the overline slot.",
58
+ "values": []
59
+ },
60
+ {
61
+ "name": "--m3e-toc-title-font-size",
62
+ "description": "Font size for the title slot.",
63
+ "values": []
64
+ },
65
+ {
66
+ "name": "--m3e-toc-title-font-weight",
67
+ "description": "Font weight for the title slot.",
68
+ "values": []
69
+ },
70
+ {
71
+ "name": "--m3e-toc-title-line-height",
72
+ "description": "Line height for the title slot.",
73
+ "values": []
74
+ },
75
+ {
76
+ "name": "--m3e-toc-title-tracking",
77
+ "description": "Letter spacing for the title slot.",
78
+ "values": []
79
+ },
80
+ {
81
+ "name": "--m3e-toc-title-color",
82
+ "description": "Text color for the title slot.",
83
+ "values": []
84
+ },
85
+ {
86
+ "name": "--m3e-toc-item-shape",
87
+ "description": "Border radius of the TOC item.",
88
+ "values": []
89
+ },
90
+ {
91
+ "name": "--m3e-toc-item-padding-block",
92
+ "description": "Block padding for the TOC item.",
93
+ "values": []
94
+ },
95
+ {
96
+ "name": "--m3e-toc-item-padding",
97
+ "description": "Inline padding for the TOC item.",
98
+ "values": []
99
+ },
100
+ {
101
+ "name": "--m3e-toc-item-inset",
102
+ "description": "Indentation per level for the TOC item.",
103
+ "values": []
104
+ },
105
+ {
106
+ "name": "--m3e-toc-active-indicator-animation-duration",
107
+ "description": "Animation duration for the active indicator.",
108
+ "values": []
109
+ },
110
+ {
111
+ "name": "--m3e-toc-item-font-size",
112
+ "description": "Font size for unselected items.",
113
+ "values": []
114
+ },
115
+ {
116
+ "name": "--m3e-toc-item-font-weight",
117
+ "description": "Font weight for unselected items.",
118
+ "values": []
119
+ },
120
+ {
121
+ "name": "--m3e-toc-item-line-height",
122
+ "description": "Line height for unselected items.",
123
+ "values": []
124
+ },
125
+ {
126
+ "name": "--m3e-toc-item-tracking",
127
+ "description": "Letter spacing for unselected items.",
128
+ "values": []
129
+ },
130
+ {
131
+ "name": "--m3e-toc-item-color",
132
+ "description": "Text color for unselected items.",
133
+ "values": []
134
+ },
135
+ {
136
+ "name": "--m3e-toc-item-selected-font-size",
137
+ "description": "Font size for selected items.",
138
+ "values": []
139
+ },
140
+ {
141
+ "name": "--m3e-toc-item-selected-font-weight",
142
+ "description": "Font weight for selected items.",
143
+ "values": []
144
+ },
145
+ {
146
+ "name": "--m3e-toc-item-selected-line-height",
147
+ "description": "Line height for selected items.",
148
+ "values": []
149
+ },
150
+ {
151
+ "name": "--m3e-toc-item-selected-tracking",
152
+ "description": "Letter spacing for selected items.",
153
+ "values": []
154
+ },
155
+ {
156
+ "name": "--m3e-toc-item-selected-color",
157
+ "description": "Text color for selected items.",
158
+ "values": []
159
+ }
160
+ ],
161
+ "pseudoElements": []
162
+ }