pretty-toc 1.1.3 → 1.1.5

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.
Files changed (3) hide show
  1. package/README.md +37 -1
  2. package/dist/index.mjs +133 -102
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -6,9 +6,45 @@ A Table of Contents generation plugin for the Satteri markdown parser library.
6
6
  ## Install
7
7
 
8
8
  ```
9
+ // install with npm
9
10
  npm install pretty-toc --save-dev
11
+
12
+ // install with pnpm
13
+ pnpm install pretty-toc --save-dev
14
+
15
+ // install with yarn
16
+ yarn add -D pretty-toc
17
+
18
+ // install with bun
19
+ bun add -D pretty-toc
20
+
21
+ // install with deno
22
+ deno add -D pretty-toc
10
23
  ```
11
24
 
25
+ ## Table of Contents
26
+
27
+ - [Screenshots](#Screenshots)
28
+ - [Example](#Example)
29
+ - [Options](#Options)
30
+
31
+ ## Screenshots
32
+
33
+ - icon
34
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/with-icon.png)
35
+
36
+ - image
37
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/with-image.png)
38
+
39
+ - dot
40
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-dot.png)
41
+
42
+ - decimal
43
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-decimal.png)
44
+
45
+ - nested image
46
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-multiple-image.png)
47
+
12
48
  ## Example
13
49
 
14
50
  ```javascript
@@ -79,7 +115,7 @@ processor: satteri({
79
115
  }),
80
116
  ```
81
117
 
82
- ## options
118
+ ## Options
83
119
 
84
120
  |Property‌|Type|Default Value|Preset Value|Info|
85
121
  |:---|:---|:---|:---|:--|
package/dist/index.mjs CHANGED
@@ -137,13 +137,6 @@ function prettyToc(option) {
137
137
  width: fit-content;
138
138
  position: relative;
139
139
  }
140
- .toc-title:hover {
141
- color: ${lightThemeHighlightColor};
142
- cursor: pointer;
143
- }
144
- html.dark .toc-title:hover {
145
- color: ${darkThemeHighlightColor};
146
- }
147
140
  ul {
148
141
  padding-left: 0;
149
142
  list-style-type: ${listStyle} ;
@@ -194,126 +187,164 @@ function prettyToc(option) {
194
187
  .li-row > a {
195
188
  text-decoration: none;
196
189
  }
197
- .li-row:hover {
190
+ @media (hover: hover) {
191
+ .toc-title:hover {
192
+ color: ${lightThemeHighlightColor};
193
+ cursor: pointer;
194
+ }
195
+ html.dark .toc-title:hover {
196
+ color: ${darkThemeHighlightColor};
197
+ }
198
+ .li-row:hover {
199
+ color: ${lightThemeHighlightColor};
200
+ }
201
+ .li-row:hover > .li-marker::before {
202
+ color: ${lightThemeHighlightColor};
203
+ }
204
+ .li-row:hover > a {
205
+ color: ${lightThemeHighlightColor};
206
+ }
207
+ html.dark .li-row:hover {
208
+ color: ${darkThemeHighlightColor};
209
+ }
210
+ html.dark .li-row:hover > .li-marker::before {
211
+ color: ${darkThemeHighlightColor};
212
+ }
213
+ html.dark .li-row:hover > a {
214
+ color: ${darkThemeHighlightColor};
215
+ }
216
+ }
217
+ .toc-title:active {
198
218
  color: ${lightThemeHighlightColor};
219
+ cursor: pointer;
199
220
  }
200
- .li-row:hover > .li-marker::before {
221
+ html.dark .toc-title:active {
222
+ color: ${darkThemeHighlightColor};
223
+ }
224
+ .li-row:active {
225
+ color: ${lightThemeHighlightColor};
226
+ }
227
+ .li-row:active > .li-marker::before {
201
228
  color: ${lightThemeHighlightColor};
202
229
  }
203
- .li-row:hover > a {
230
+ .li-row:active > a {
204
231
  color: ${lightThemeHighlightColor};
205
232
  }
206
- html.dark .li-row:hover {
233
+ html.dark .li-row:active {
207
234
  color: ${darkThemeHighlightColor};
208
235
  }
209
- html.dark .li-row:hover > .li-marker::before {
236
+ html.dark .li-row:active > .li-marker::before {
210
237
  color: ${darkThemeHighlightColor};
211
238
  }
212
- html.dark .li-row:hover > a {
239
+ html.dark .li-row:active > a {
213
240
  color: ${darkThemeHighlightColor};
214
241
  }
215
242
  `;
216
- const iframeContent = `<iframe
217
- style="display:none;"
218
- srcdoc="&lt;!DOCTYPE html&gt;
219
- &lt;html&gt;
220
- &lt;head&gt;&lt;meta charset=&quot;utf-8&quot;&gt;&lt;/head&gt;
221
- &lt;body&gt;
222
- <strong>Hello from iframe!</strong>
223
- <script is:inline data-astro-rerun>
224
- const currentLocale = window.parent.location.pathname.split('/')[1] || '${opt.locale || "en-US"}';
225
- const languageMap = ${JSON.stringify(opt.languageMap).replaceAll("\"", "'")} || ${JSON.stringify(DEFAULT_LANGUAGE_MAP).replaceAll("\"", "'")};
243
+ const iframeContent = `
244
+ <iframe
245
+ style="display:none;"
246
+ srcdoc="&lt;!DOCTYPE html&gt;
247
+ &lt;html&gt;
248
+ &lt;head&gt;&lt;meta charset=&quot;utf-8&quot;&gt;&lt;/head&gt;
249
+ &lt;body&gt;
250
+ <strong>Hello from iframe!</strong>
251
+ <script is:inline data-astro-rerun>
252
+ const currentLocale = window.parent.location.pathname.split('/')[1] || '${opt.locale || "en-US"}';
253
+ const languageMap = ${JSON.stringify(opt.languageMap).replaceAll("\"", "'")} || ${JSON.stringify(DEFAULT_LANGUAGE_MAP).replaceAll("\"", "'")};
226
254
 
227
- function syncTocTitle(
228
- locale,
229
- languageMap
230
- ) {
231
- const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
255
+ function syncTocTitle(
256
+ locale,
257
+ languageMap
258
+ ) {
259
+ const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
232
260
 
233
- if (tocSummary) {
234
- const titleKey = tocSummary.getAttribute('data-satteri-toc-title');
235
- const translation =
236
- languageMap[locale] || '${title}' || titleKey;
237
- tocSummary.textContent = translation;
261
+ if (tocSummary) {
262
+ const titleKey = tocSummary.getAttribute('data-satteri-toc-title');
263
+ const translation =
264
+ languageMap[locale] || '${title}' || titleKey;
265
+ tocSummary.textContent = translation;
266
+ }
238
267
  }
239
- }
240
268
 
241
- function toggleToc() {
242
- const tocTitle = window.parent.document.querySelector('.toc-title');
243
- if (tocTitle) {
244
- tocTitle.addEventListener('click', function () {
245
- tocTitle.classList.toggle('open');
246
- })
269
+ function toggleToc() {
270
+ const tocTitle = window.parent.document.querySelector('.toc-title');
271
+ if (tocTitle) {
272
+ tocTitle.addEventListener('click', function () {
273
+ tocTitle.classList.toggle('open');
274
+ })
275
+ }
247
276
  }
248
- }
249
277
 
250
- syncTocTitle(currentLocale, languageMap);
251
- toggleToc();
252
-
253
- window.parent.addEventListener('load', function() {
254
278
  syncTocTitle(currentLocale, languageMap);
255
279
  toggleToc();
256
- });
257
- <\/script>
258
- &lt;/body&gt;
259
- &lt;/html&gt;">
260
- </iframe>`;
280
+
281
+ window.parent.addEventListener('load', function() {
282
+ syncTocTitle(currentLocale, languageMap);
283
+ toggleToc();
284
+ });
285
+ <\/script>
286
+ &lt;/body&gt;
287
+ &lt;/html&gt;">
288
+ </iframe>
289
+ `;
261
290
  ctx.data.firstHeading = node;
262
291
  ctx.data.firstHeadingDepth = depth;
263
292
  ctx.data.firstHeadingId = contentSlug;
264
293
  ctx.data.firstHeadingIndex = ctx.indexOf(node) ?? 0;
265
- ctx.data.nodeStr = `<div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul{
266
- list-style-type: none;
267
- counter-reset: toc-counter;
268
- }
269
- li {
270
- counter-increment: toc-counter;
271
- }
272
- .li-marker::before {
273
- content: counters(toc-counter, ".");
274
- }` : "") + (opt.animation && animation !== void 0 ? `.toc-wrapper {
275
- max-height: 2rem;
276
- transition: max-height ${animation.duration} ${animation.timingFunction};
277
- }
278
- .toc-wrapper:has(.toc-title.open) {
279
- max-height: 100vh;
280
- }
281
- ` : "") + (opt.titleMarkerType === "icon" ? `
282
- .toc-title::before {
283
- content: '${closedMarker} ';
284
- display: contents;
285
- font-size: 1rem;
286
- }
287
- .toc-title.open::before {
288
- content: '${openedMarker} ';
289
- display: contents;
290
- font-size: 1rem;
291
- }
292
- ` : "") + (opt.titleMarkerType === "image" ? `
293
- .toc-wrapper > .toc-title, .toc-wrapper > ul {
294
- margin-left: 2rem;
295
- }
296
- .toc-title::before {
297
- content: "";
298
- background: url('${closedMarker}') center / contain no-repeat;
299
- width: ${titleMarkerCssSize};
300
- height: ${titleMarkerCssSize};
301
- position: absolute;
302
- left: -2rem;
303
- top: 50%;
304
- transform: translateY(-50%);
305
- }
306
- .toc-title.open::before {
307
- content: "";
308
- background: url('${openedMarker}') center / contain no-repeat;
309
- width: ${titleMarkerCssSize};
310
- height: ${titleMarkerCssSize};
311
- position: absolute;
312
- left: -2rem;
313
- top: 50%;
314
- transform: translateY(-50%);
315
- }
316
- ` : "")}</style><h2 data-satteri-toc-title="${title}" class="toc-title ${opt.class?.title ?? ""}" style="${opt.style?.title ?? ""}">${title}</h2><ul class="${opt.class?.ul ?? ""}" style="${opt.style?.ul ?? ""}">${nodeStr}</ul>${iframeContent}</div>`;
294
+ ctx.data.nodeStr = `
295
+ <div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul{
296
+ list-style-type: none;
297
+ counter-reset: toc-counter;
298
+ }
299
+ li {
300
+ counter-increment: toc-counter;
301
+ }
302
+ .li-marker::before {
303
+ content: counters(toc-counter, ".");
304
+ }` : "") + (opt.animation && animation !== void 0 ? `.toc-wrapper {
305
+ max-height: 2rem;
306
+ transition: max-height ${animation.duration} ${animation.timingFunction};
307
+ }
308
+ .toc-wrapper:has(.toc-title.open) {
309
+ max-height: 100vh;
310
+ }
311
+ ` : "") + (opt.titleMarkerType === "icon" ? `
312
+ .toc-title::before {
313
+ content: '${closedMarker} ';
314
+ display: contents;
315
+ font-size: 1rem;
316
+ }
317
+ .toc-title.open::before {
318
+ content: '${openedMarker} ';
319
+ display: contents;
320
+ font-size: 1rem;
321
+ }
322
+ ` : "") + (opt.titleMarkerType === "image" ? `
323
+ .toc-wrapper > .toc-title, .toc-wrapper > ul {
324
+ margin-left: 2rem;
325
+ }
326
+ .toc-title::before {
327
+ content: "";
328
+ background: url('${closedMarker}') center / contain no-repeat;
329
+ width: ${titleMarkerCssSize};
330
+ height: ${titleMarkerCssSize};
331
+ position: absolute;
332
+ left: -2rem;
333
+ top: 50%;
334
+ transform: translateY(-50%);
335
+ }
336
+ .toc-title.open::before {
337
+ content: "";
338
+ background: url('${openedMarker}') center / contain no-repeat;
339
+ width: ${titleMarkerCssSize};
340
+ height: ${titleMarkerCssSize};
341
+ position: absolute;
342
+ left: -2rem;
343
+ top: 50%;
344
+ transform: translateY(-50%);
345
+ }
346
+ ` : "")}</style><h2 data-satteri-toc-title="${title}" class="toc-title ${opt.class?.title ?? ""}" style="${opt.style?.title ?? ""}">${title}</h2><ul class="${opt.class?.ul ?? ""}" style="${opt.style?.ul ?? ""}">${nodeStr}</ul>${iframeContent}</div>
347
+ `;
317
348
  } else {
318
349
  const indexA = ctx.data.nodeStr?.lastIndexOf(tagSignal);
319
350
  if (indexA !== -1) ctx.data.nodeStr = ctx.data.nodeStr?.slice(0, indexA + tagSignalLength + 5) + nodeStr + ctx.data.nodeStr?.slice(indexA + tagSignalLength + 5);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pretty-toc",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "type": "module",
5
5
  "description": "A Table of Contents generation plugin for the Satteri markdown parser library.",
6
6
  "keywords": [