pretty-toc 1.2.5 → 1.3.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/README.md +3 -1
- package/dist/index.mjs +256 -254
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ deno add -D pretty-toc
|
|
|
50
50
|
```javascript
|
|
51
51
|
import prettyToc from 'pretty-toc';
|
|
52
52
|
|
|
53
|
-
// example
|
|
53
|
+
// Basic example
|
|
54
54
|
satteri({
|
|
55
55
|
hastPlugins: [prettyToc({title: "Table of Contents", listStyle: "decimal"})]
|
|
56
56
|
})
|
|
@@ -82,12 +82,14 @@ processor: satteri({
|
|
|
82
82
|
timingFunction: 'ease-in-out'
|
|
83
83
|
},
|
|
84
84
|
class: {
|
|
85
|
+
title: "",
|
|
85
86
|
ul: "",
|
|
86
87
|
li: "",
|
|
87
88
|
a: "",
|
|
88
89
|
},
|
|
89
90
|
globalStyle: "",
|
|
90
91
|
style: {
|
|
92
|
+
title: "",
|
|
91
93
|
ul: "",
|
|
92
94
|
li: "",
|
|
93
95
|
a: "",
|
package/dist/index.mjs
CHANGED
|
@@ -63,6 +63,18 @@ var image_not_found_default = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F
|
|
|
63
63
|
* @returns 插件实例
|
|
64
64
|
*/
|
|
65
65
|
function prettyToc(option) {
|
|
66
|
+
const opt = option ?? DEFAULT_OPTIONS;
|
|
67
|
+
const lightThemeHighlightColor = opt.lightThemeHighlightColor || "oklch(0.75 0.1229 12.71)";
|
|
68
|
+
const darkThemeHighlightColor = opt.darkThemeHighlightColor || "oklch(0.81 0.1004 305.04)";
|
|
69
|
+
const titleMarkerCssSize = opt.titleMarkerCssSize || "fit-content";
|
|
70
|
+
const openedMarker = opt.openedMarker || "▼";
|
|
71
|
+
const closedMarker = opt.closedMarker || "▶︎";
|
|
72
|
+
const liMarkerCssSize = opt.liMarkerCssSize || "1rem";
|
|
73
|
+
let title = opt.title || "Table of Contents";
|
|
74
|
+
let listStyle = DEFAULT_LIST_STYLE;
|
|
75
|
+
let animation = void 0;
|
|
76
|
+
let headingTree = void 0;
|
|
77
|
+
let firstHeading = {};
|
|
66
78
|
return defineHastPlugin({
|
|
67
79
|
name: "prettyToc",
|
|
68
80
|
element: [{
|
|
@@ -75,24 +87,14 @@ function prettyToc(option) {
|
|
|
75
87
|
"h6"
|
|
76
88
|
],
|
|
77
89
|
visit(node, ctx) {
|
|
78
|
-
const opt = option ?? DEFAULT_OPTIONS;
|
|
79
90
|
try {
|
|
80
91
|
const depth = parseInt(node.tagName.slice(-1), 10);
|
|
81
92
|
const content = ctx.textContent(node);
|
|
82
93
|
const contentSlug = slug(content) + (/* @__PURE__ */ new Date()).getTime();
|
|
83
|
-
let title = opt.title || "Table of Contents";
|
|
84
94
|
if (opt.languageMap) title = opt.languageMap[opt.locale ?? "en-US"] || "Table of Contents";
|
|
85
95
|
else title = DEFAULT_LANGUAGE_MAP[opt.locale ?? "en-US"] || "Table of Contents";
|
|
86
|
-
let listStyle = DEFAULT_LIST_STYLE;
|
|
87
96
|
if (opt.listStyle === "icon" || opt.listStyle === "image" || opt.listStyle === "decimal") listStyle = "none";
|
|
88
97
|
else if (opt.listStyle !== void 0) listStyle = opt.listStyle;
|
|
89
|
-
const lightThemeHighlightColor = opt.lightThemeHighlightColor || "oklch(0.75 0.1229 12.71)";
|
|
90
|
-
const darkThemeHighlightColor = opt.darkThemeHighlightColor || "oklch(0.81 0.1004 305.04)";
|
|
91
|
-
const titleMarkerCssSize = opt.titleMarkerCssSize || "fit-content";
|
|
92
|
-
const openedMarker = opt.openedMarker || "▼";
|
|
93
|
-
const closedMarker = opt.closedMarker || "▶︎";
|
|
94
|
-
const liMarkerCssSize = opt.liMarkerCssSize || "1rem";
|
|
95
|
-
let animation = void 0;
|
|
96
98
|
if (typeof opt.animation === "object" && opt.animation !== void 0) animation = opt.animation ?? DEFAULT_ANIMATION;
|
|
97
99
|
else if (opt.animation === true) animation = DEFAULT_ANIMATION;
|
|
98
100
|
else animation = void 0;
|
|
@@ -117,18 +119,18 @@ function prettyToc(option) {
|
|
|
117
119
|
}
|
|
118
120
|
let nodeStr = `<li id="li-${contentSlug}" class="${opt.class?.li ?? ""}" style="${opt.style?.li ?? ""}" data-depth=${depth}><div class="li-row">${marker}<a href="#${contentSlug}" class="${opt.class?.a ?? ""}" style="${opt.style?.a ?? ""}">${content}</a></div></li>`;
|
|
119
121
|
ctx.setProperty(node, "id", contentSlug);
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
if (headingTree === void 0) {
|
|
123
|
+
firstHeading.headingText = ctx.textContent(node);
|
|
124
|
+
firstHeading.headingDepth = depth;
|
|
125
|
+
firstHeading.headingId = contentSlug;
|
|
126
|
+
firstHeading.headingIndex = ctx.indexOf(node) ?? 0;
|
|
125
127
|
const rootNode = {
|
|
126
128
|
depth: 0,
|
|
127
129
|
content: "",
|
|
128
130
|
children: [],
|
|
129
131
|
parent: void 0
|
|
130
132
|
};
|
|
131
|
-
|
|
133
|
+
headingTree = {
|
|
132
134
|
rootNode,
|
|
133
135
|
previousNode: rootNode
|
|
134
136
|
};
|
|
@@ -139,21 +141,21 @@ function prettyToc(option) {
|
|
|
139
141
|
children: [],
|
|
140
142
|
parent: rootNode
|
|
141
143
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
headingTree.rootNode.children.push(currentNode);
|
|
145
|
+
headingTree.previousNode = currentNode;
|
|
144
146
|
} else for (let i = 1; i <= depth; i++) {
|
|
145
147
|
const currentNode = {
|
|
146
148
|
depth: i,
|
|
147
149
|
content: i === depth ? nodeStr : "",
|
|
148
150
|
children: [],
|
|
149
|
-
parent:
|
|
151
|
+
parent: headingTree.previousNode
|
|
150
152
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
headingTree.previousNode.children.push(currentNode);
|
|
154
|
+
headingTree.previousNode = currentNode;
|
|
153
155
|
}
|
|
154
156
|
} else {
|
|
155
157
|
let hasFound = false;
|
|
156
|
-
let nextSearchNode =
|
|
158
|
+
let nextSearchNode = headingTree.rootNode;
|
|
157
159
|
searchNode: while (!hasFound) if (nextSearchNode.depth + 1 === depth) {
|
|
158
160
|
const currentNode = {
|
|
159
161
|
depth,
|
|
@@ -162,7 +164,7 @@ function prettyToc(option) {
|
|
|
162
164
|
parent: nextSearchNode
|
|
163
165
|
};
|
|
164
166
|
nextSearchNode.children.push(currentNode);
|
|
165
|
-
|
|
167
|
+
headingTree.previousNode = currentNode;
|
|
166
168
|
hasFound = true;
|
|
167
169
|
break searchNode;
|
|
168
170
|
} else if (nextSearchNode.children.length > 0) {
|
|
@@ -180,249 +182,249 @@ function prettyToc(option) {
|
|
|
180
182
|
continue searchNode;
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
185
|
+
} catch (err) {
|
|
186
|
+
throw err;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}],
|
|
190
|
+
before() {
|
|
191
|
+
headingTree = void 0;
|
|
192
|
+
firstHeading = {};
|
|
193
|
+
},
|
|
194
|
+
after(root, ctx) {
|
|
195
|
+
if (headingTree !== void 0) {
|
|
196
|
+
const collectedNodeStr = concatNodeStr(headingTree.rootNode, opt);
|
|
197
|
+
const baseStyle = `
|
|
198
|
+
.toc-wrapper {
|
|
199
|
+
display: grid;
|
|
200
|
+
grid-template-rows: 0fr;
|
|
201
|
+
overflow: hidden;
|
|
202
|
+
margin-bottom: 2rem;
|
|
203
|
+
}
|
|
204
|
+
.toc-wrapper:has(.toc-title.open) {
|
|
205
|
+
grid-template-rows: 1fr;
|
|
206
|
+
}
|
|
207
|
+
.toc-title {
|
|
208
|
+
font-size: 1.2rem;
|
|
209
|
+
font-weight: 600;
|
|
210
|
+
margin: 0 0 0.5rem 0;
|
|
211
|
+
width: fit-content;
|
|
212
|
+
position: relative;
|
|
213
|
+
}
|
|
214
|
+
ul {
|
|
215
|
+
padding-left: var(--list-indent, 1.5rem);
|
|
216
|
+
list-style-type: ${listStyle} ;
|
|
217
|
+
list-style-position: inside;
|
|
218
|
+
}
|
|
219
|
+
ul:not(:has(> li)) {
|
|
220
|
+
padding-left: 0;
|
|
221
|
+
}
|
|
222
|
+
@keyframes fadeIn {
|
|
223
|
+
from { opacity: 0; }
|
|
224
|
+
to { opacity: 1; }
|
|
225
|
+
}
|
|
226
|
+
li {
|
|
227
|
+
padding: 0;
|
|
228
|
+
line-height: 1.5rem;
|
|
229
|
+
font-size: 1rem;
|
|
230
|
+
animation: fadeIn 0.01s ease-in; // 防止页面刷新瞬间显示"0 javascript"
|
|
231
|
+
}
|
|
232
|
+
.li-marker {
|
|
233
|
+
display: inline-block;
|
|
234
|
+
margin-right: 0.5rem;
|
|
235
|
+
}
|
|
236
|
+
img.li-marker {
|
|
237
|
+
width: ${liMarkerCssSize};
|
|
238
|
+
height: ${liMarkerCssSize};
|
|
239
|
+
margin: 0 0.5rem 0 0;
|
|
240
|
+
}
|
|
241
|
+
.li-marker::before {
|
|
242
|
+
font-size: 1rem;
|
|
243
|
+
font-weight: 600;
|
|
244
|
+
width: ${liMarkerCssSize};
|
|
245
|
+
height: ${liMarkerCssSize};
|
|
246
|
+
}
|
|
247
|
+
/* 嵌套的 ul 内部,让缩进变量自动叠加 1rem */
|
|
248
|
+
ul ul {
|
|
249
|
+
--list-indent: calc(var(--list-indent, 1rem) + 1rem);
|
|
250
|
+
}
|
|
251
|
+
.li-row {
|
|
252
|
+
display: inline-flex;
|
|
253
|
+
flex-direction: row;
|
|
254
|
+
justify-content: flex-start;
|
|
255
|
+
align-items: center;
|
|
256
|
+
}
|
|
257
|
+
.li-row > img {
|
|
258
|
+
margin: 0 0.5rem 0 0;
|
|
259
|
+
}
|
|
260
|
+
.li-row > a {
|
|
261
|
+
text-decoration: none;
|
|
262
|
+
}
|
|
263
|
+
@media (hover: hover) {
|
|
264
|
+
.toc-title:hover {
|
|
265
|
+
color: ${lightThemeHighlightColor};
|
|
266
|
+
cursor: pointer;
|
|
267
|
+
}
|
|
268
|
+
html.dark .toc-title:hover {
|
|
269
|
+
color: ${darkThemeHighlightColor};
|
|
270
|
+
}
|
|
271
|
+
.li-row:hover {
|
|
272
|
+
color: ${lightThemeHighlightColor};
|
|
273
|
+
}
|
|
274
|
+
.li-row:hover > .li-marker::before {
|
|
275
|
+
color: ${lightThemeHighlightColor};
|
|
276
|
+
}
|
|
277
|
+
.li-row:hover > a {
|
|
278
|
+
color: ${lightThemeHighlightColor};
|
|
279
|
+
}
|
|
280
|
+
html.dark .li-row:hover {
|
|
281
|
+
color: ${darkThemeHighlightColor};
|
|
282
|
+
}
|
|
283
|
+
html.dark .li-row:hover > .li-marker::before {
|
|
284
|
+
color: ${darkThemeHighlightColor};
|
|
285
|
+
}
|
|
286
|
+
html.dark .li-row:hover > a {
|
|
287
|
+
color: ${darkThemeHighlightColor};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
.toc-title:active {
|
|
291
|
+
color: ${lightThemeHighlightColor};
|
|
292
|
+
cursor: pointer;
|
|
293
|
+
}
|
|
294
|
+
html.dark .toc-title:active {
|
|
295
|
+
color: ${darkThemeHighlightColor};
|
|
296
|
+
}
|
|
297
|
+
.li-row:active {
|
|
298
|
+
color: ${lightThemeHighlightColor};
|
|
299
|
+
}
|
|
300
|
+
.li-row:active > .li-marker::before {
|
|
301
|
+
color: ${lightThemeHighlightColor};
|
|
302
|
+
}
|
|
303
|
+
.li-row:active > a {
|
|
304
|
+
color: ${lightThemeHighlightColor};
|
|
305
|
+
}
|
|
306
|
+
html.dark .li-row:active {
|
|
307
|
+
color: ${darkThemeHighlightColor};
|
|
308
|
+
}
|
|
309
|
+
html.dark .li-row:active > .li-marker::before {
|
|
310
|
+
color: ${darkThemeHighlightColor};
|
|
311
|
+
}
|
|
312
|
+
html.dark .li-row:active > a {
|
|
313
|
+
color: ${darkThemeHighlightColor};
|
|
314
|
+
}
|
|
315
|
+
`;
|
|
316
|
+
const iframeContent = `
|
|
317
|
+
<iframe
|
|
318
|
+
style="display:none;"
|
|
319
|
+
srcdoc="<!DOCTYPE html>
|
|
320
|
+
<html>
|
|
321
|
+
<head><meta charset="utf-8"></head>
|
|
322
|
+
<body>
|
|
323
|
+
<script is:inline data-astro-rerun>
|
|
324
|
+
const currentLocale = window.parent.location.pathname.split('/')[1] || '${opt.locale || "en-US"}';
|
|
325
|
+
const languageMap = ${JSON.stringify(opt.languageMap).replaceAll("\"", "'")} || ${JSON.stringify(DEFAULT_LANGUAGE_MAP).replaceAll("\"", "'")};
|
|
326
|
+
|
|
327
|
+
function syncTocTitle(
|
|
328
|
+
locale,
|
|
329
|
+
languageMap
|
|
330
|
+
) {
|
|
331
|
+
const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
|
|
332
|
+
|
|
333
|
+
if (tocSummary) {
|
|
334
|
+
const titleKey = tocSummary.getAttribute('data-satteri-toc-title');
|
|
335
|
+
const translation =
|
|
336
|
+
languageMap[locale] || '${title}' || titleKey;
|
|
337
|
+
tocSummary.textContent = translation;
|
|
338
|
+
}
|
|
279
339
|
}
|
|
280
|
-
|
|
281
|
-
|
|
340
|
+
|
|
341
|
+
function toggleToc() {
|
|
342
|
+
const tocTitle = window.parent.document.querySelector('.toc-title');
|
|
343
|
+
if (tocTitle) {
|
|
344
|
+
tocTitle.addEventListener('click', function () {
|
|
345
|
+
tocTitle.classList.toggle('open');
|
|
346
|
+
})
|
|
347
|
+
}
|
|
282
348
|
}
|
|
349
|
+
|
|
350
|
+
window.addEventListener('load', function() {
|
|
351
|
+
if (window.parent.document.readyState === 'complete') {
|
|
352
|
+
syncTocTitle(currentLocale, languageMap);
|
|
353
|
+
toggleToc();
|
|
354
|
+
} else {
|
|
355
|
+
window.parent.document.addEventListener('readystatechange', event => {
|
|
356
|
+
if (event.target.readyState === 'complete') {
|
|
357
|
+
syncTocTitle(currentLocale, languageMap);
|
|
358
|
+
toggleToc();
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
<\/script>
|
|
364
|
+
</body>
|
|
365
|
+
</html>">
|
|
366
|
+
</iframe>
|
|
367
|
+
`;
|
|
368
|
+
const totalNodeStr = `
|
|
369
|
+
<div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul:has(> li) {
|
|
370
|
+
list-style-type: none;
|
|
371
|
+
counter-reset: toc-counter;
|
|
283
372
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
cursor: pointer;
|
|
373
|
+
li {
|
|
374
|
+
counter-increment: toc-counter;
|
|
287
375
|
}
|
|
288
|
-
|
|
289
|
-
|
|
376
|
+
.li-marker::before {
|
|
377
|
+
content: counters(toc-counter, ".");
|
|
378
|
+
}` : "") + (opt.animation && animation !== void 0 && typeof animation !== "boolean" ? `.toc-wrapper {
|
|
379
|
+
max-height: 2rem;
|
|
380
|
+
transition: max-height ${animation.duration} ${animation.timingFunction};
|
|
290
381
|
}
|
|
291
|
-
.
|
|
292
|
-
|
|
382
|
+
.toc-wrapper:has(.toc-title.open) {
|
|
383
|
+
max-height: 100vh;
|
|
293
384
|
}
|
|
294
|
-
|
|
295
|
-
|
|
385
|
+
` : "") + (opt.titleMarkerType === "icon" ? `
|
|
386
|
+
.toc-title::before {
|
|
387
|
+
content: '${closedMarker} ';
|
|
388
|
+
display: contents;
|
|
389
|
+
font-size: 1rem;
|
|
296
390
|
}
|
|
297
|
-
.
|
|
298
|
-
|
|
391
|
+
.toc-title.open::before {
|
|
392
|
+
content: '${openedMarker} ';
|
|
393
|
+
display: contents;
|
|
394
|
+
font-size: 1rem;
|
|
299
395
|
}
|
|
300
|
-
|
|
301
|
-
|
|
396
|
+
` : "") + (opt.titleMarkerType === "image" ? `
|
|
397
|
+
.toc-wrapper > .toc-title, .toc-wrapper > ul {
|
|
398
|
+
margin-left: 2rem;
|
|
302
399
|
}
|
|
303
|
-
|
|
304
|
-
|
|
400
|
+
.toc-title::before {
|
|
401
|
+
content: "";
|
|
402
|
+
background: url('${closedMarker}') center / contain no-repeat;
|
|
403
|
+
width: ${titleMarkerCssSize};
|
|
404
|
+
height: ${titleMarkerCssSize};
|
|
405
|
+
position: absolute;
|
|
406
|
+
left: -2rem;
|
|
407
|
+
top: 50%;
|
|
408
|
+
transform: translateY(-50%);
|
|
305
409
|
}
|
|
306
|
-
|
|
307
|
-
|
|
410
|
+
.toc-title.open::before {
|
|
411
|
+
content: "";
|
|
412
|
+
background: url('${openedMarker}') center / contain no-repeat;
|
|
413
|
+
width: ${titleMarkerCssSize};
|
|
414
|
+
height: ${titleMarkerCssSize};
|
|
415
|
+
position: absolute;
|
|
416
|
+
left: -2rem;
|
|
417
|
+
top: 50%;
|
|
418
|
+
transform: translateY(-50%);
|
|
308
419
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
<head><meta charset="utf-8"></head>
|
|
316
|
-
<body>
|
|
317
|
-
<script is:inline data-astro-rerun>
|
|
318
|
-
const currentLocale = window.parent.location.pathname.split('/')[1] || '${opt.locale || "en-US"}';
|
|
319
|
-
const languageMap = ${JSON.stringify(opt.languageMap).replaceAll("\"", "'")} || ${JSON.stringify(DEFAULT_LANGUAGE_MAP).replaceAll("\"", "'")};
|
|
320
|
-
|
|
321
|
-
function syncTocTitle(
|
|
322
|
-
locale,
|
|
323
|
-
languageMap
|
|
324
|
-
) {
|
|
325
|
-
const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
|
|
326
|
-
|
|
327
|
-
if (tocSummary) {
|
|
328
|
-
const titleKey = tocSummary.getAttribute('data-satteri-toc-title');
|
|
329
|
-
const translation =
|
|
330
|
-
languageMap[locale] || '${title}' || titleKey;
|
|
331
|
-
tocSummary.textContent = translation;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function toggleToc() {
|
|
336
|
-
const tocTitle = window.parent.document.querySelector('.toc-title');
|
|
337
|
-
if (tocTitle) {
|
|
338
|
-
tocTitle.addEventListener('click', function () {
|
|
339
|
-
tocTitle.classList.toggle('open');
|
|
340
|
-
})
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
window.addEventListener('load', function() {
|
|
345
|
-
if (window.parent.document.readyState === 'complete') {
|
|
346
|
-
syncTocTitle(currentLocale, languageMap);
|
|
347
|
-
toggleToc();
|
|
348
|
-
} else {
|
|
349
|
-
window.parent.document.addEventListener('readystatechange', event => {
|
|
350
|
-
if (event.target.readyState === 'complete') {
|
|
351
|
-
syncTocTitle(currentLocale, languageMap);
|
|
352
|
-
toggleToc();
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
<\/script>
|
|
358
|
-
</body>
|
|
359
|
-
</html>">
|
|
360
|
-
</iframe>
|
|
361
|
-
`;
|
|
362
|
-
ctx.data.nodeStr = `
|
|
363
|
-
<div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul:has(> li) {
|
|
364
|
-
list-style-type: none;
|
|
365
|
-
counter-reset: toc-counter;
|
|
366
|
-
}
|
|
367
|
-
li {
|
|
368
|
-
counter-increment: toc-counter;
|
|
369
|
-
}
|
|
370
|
-
.li-marker::before {
|
|
371
|
-
content: counters(toc-counter, ".");
|
|
372
|
-
}` : "") + (opt.animation && animation !== void 0 ? `.toc-wrapper {
|
|
373
|
-
max-height: 2rem;
|
|
374
|
-
transition: max-height ${animation.duration} ${animation.timingFunction};
|
|
375
|
-
}
|
|
376
|
-
.toc-wrapper:has(.toc-title.open) {
|
|
377
|
-
max-height: 100vh;
|
|
378
|
-
}
|
|
379
|
-
` : "") + (opt.titleMarkerType === "icon" ? `
|
|
380
|
-
.toc-title::before {
|
|
381
|
-
content: '${closedMarker} ';
|
|
382
|
-
display: contents;
|
|
383
|
-
font-size: 1rem;
|
|
384
|
-
}
|
|
385
|
-
.toc-title.open::before {
|
|
386
|
-
content: '${openedMarker} ';
|
|
387
|
-
display: contents;
|
|
388
|
-
font-size: 1rem;
|
|
389
|
-
}
|
|
390
|
-
` : "") + (opt.titleMarkerType === "image" ? `
|
|
391
|
-
.toc-wrapper > .toc-title, .toc-wrapper > ul {
|
|
392
|
-
margin-left: 2rem;
|
|
393
|
-
}
|
|
394
|
-
.toc-title::before {
|
|
395
|
-
content: "";
|
|
396
|
-
background: url('${closedMarker}') center / contain no-repeat;
|
|
397
|
-
width: ${titleMarkerCssSize};
|
|
398
|
-
height: ${titleMarkerCssSize};
|
|
399
|
-
position: absolute;
|
|
400
|
-
left: -2rem;
|
|
401
|
-
top: 50%;
|
|
402
|
-
transform: translateY(-50%);
|
|
403
|
-
}
|
|
404
|
-
.toc-title.open::before {
|
|
405
|
-
content: "";
|
|
406
|
-
background: url('${openedMarker}') center / contain no-repeat;
|
|
407
|
-
width: ${titleMarkerCssSize};
|
|
408
|
-
height: ${titleMarkerCssSize};
|
|
409
|
-
position: absolute;
|
|
410
|
-
left: -2rem;
|
|
411
|
-
top: 50%;
|
|
412
|
-
transform: translateY(-50%);
|
|
413
|
-
}
|
|
414
|
-
` : "")}</style><h2 data-satteri-toc-title="${title}" class="toc-title ${opt.class?.title ?? ""}" style="${opt.style?.title ?? ""}">${title}</h2>${collectedNodeStr}${iframeContent}</div>
|
|
415
|
-
`;
|
|
416
|
-
ctx.replaceNode(parent.children[ctx.data.firstHeadingIndex], {
|
|
417
|
-
type: "raw",
|
|
418
|
-
value: ctx.data.nodeStr + `<h${ctx.data.firstHeadingDepth} id="${ctx.data.firstHeadingId}">${ctx.data.firstHeading && ctx.textContent(ctx.data.firstHeading)}</h${ctx.data.firstHeadingDepth}>`
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
} catch (err) {
|
|
422
|
-
throw err;
|
|
423
|
-
}
|
|
420
|
+
` : "")}</style><h2 data-satteri-toc-title="${title}" class="toc-title ${opt.class?.title ?? ""}" style="${opt.style?.title ?? ""}">${title}</h2>${collectedNodeStr}${iframeContent}</div>
|
|
421
|
+
`;
|
|
422
|
+
if (firstHeading.headingIndex !== void 0) ctx.replaceNode(root.children[firstHeading.headingIndex], {
|
|
423
|
+
type: "raw",
|
|
424
|
+
value: totalNodeStr + `<h${firstHeading.headingDepth} id="${firstHeading.headingId}">${firstHeading.headingText || ""}</h${firstHeading.headingDepth}>`
|
|
425
|
+
});
|
|
424
426
|
}
|
|
425
|
-
}
|
|
427
|
+
}
|
|
426
428
|
});
|
|
427
429
|
}
|
|
428
430
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pretty-toc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A Table of Contents generation plugin for the Satteri markdown parser library.",
|
|
6
6
|
"keywords": [
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@types/slug": "^5.0.9",
|
|
52
|
-
"satteri": "^0.
|
|
52
|
+
"satteri": "^0.10.5",
|
|
53
53
|
"slug": "^12.0.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@rollup/plugin-url": "^8.0.2",
|
|
57
|
-
"@types/hast": "^3.0.
|
|
58
|
-
"@types/node": "^26.
|
|
57
|
+
"@types/hast": "^3.0.5",
|
|
58
|
+
"@types/node": "^26.4.1",
|
|
59
59
|
"bumpp": "^11.1.0",
|
|
60
60
|
"tsdown": "^0.22.5",
|
|
61
61
|
"typescript": "^7.0.2",
|