vue-markdown-design 0.3.0 → 0.3.2-beta

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 (72) hide show
  1. package/README.md +26 -4
  2. package/README.zh-CN.md +5 -1
  3. package/es/_virtual/_@oxc-project_runtime@0.115.0/helpers/asyncToGenerator.mjs +27 -0
  4. package/es/_virtual/_@oxc-project_runtime@0.115.0/helpers/defineProperty.mjs +12 -0
  5. package/es/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.mjs +25 -0
  6. package/es/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.mjs +13 -0
  7. package/es/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutPropertiesLoose.mjs +12 -0
  8. package/es/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPrimitive.mjs +14 -0
  9. package/es/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPropertyKey.mjs +9 -0
  10. package/es/_virtual/_@oxc-project_runtime@0.115.0/helpers/typeof.mjs +11 -0
  11. package/es/hooks/use-element/index.mjs +21 -18
  12. package/es/hooks/use-scroll-element/index.mjs +44 -45
  13. package/es/index.mjs +7 -18
  14. package/es/markdown/Markdown.mjs +221 -316
  15. package/es/markdown/index.css +3 -0
  16. package/es/markdown/index2.mjs +6 -0
  17. package/es/render/Render.mjs +143 -173
  18. package/es/render/index.css +37 -21
  19. package/es/render/index2.mjs +6 -0
  20. package/es/search/Search.mjs +236 -284
  21. package/es/search/index.css +4 -0
  22. package/es/search/index2.mjs +6 -0
  23. package/es/sticky/Sticky.mjs +66 -99
  24. package/es/sticky/index2.mjs +6 -0
  25. package/es/toc/Toc.mjs +253 -347
  26. package/es/toc/index2.mjs +6 -0
  27. package/es/utils/constant.mjs +4 -4
  28. package/es/utils/dom.mjs +44 -68
  29. package/es/utils/format.mjs +33 -39
  30. package/es/utils/functions.mjs +5 -5
  31. package/es/utils/vue.mjs +10 -32
  32. package/lib/_virtual/_@oxc-project_runtime@0.115.0/helpers/asyncToGenerator.js +27 -0
  33. package/lib/_virtual/_@oxc-project_runtime@0.115.0/helpers/defineProperty.js +12 -0
  34. package/lib/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.js +25 -0
  35. package/lib/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.js +13 -0
  36. package/lib/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutPropertiesLoose.js +12 -0
  37. package/lib/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPrimitive.js +14 -0
  38. package/lib/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPropertyKey.js +9 -0
  39. package/lib/_virtual/_@oxc-project_runtime@0.115.0/helpers/typeof.js +16 -0
  40. package/lib/_virtual/_rolldown/runtime.js +23 -0
  41. package/lib/hooks/use-element/index.js +23 -19
  42. package/lib/hooks/use-scroll-element/index.js +45 -45
  43. package/lib/index.js +24 -22
  44. package/lib/markdown/Markdown.js +224 -317
  45. package/lib/markdown/index.css +3 -0
  46. package/lib/markdown/index2.js +6 -0
  47. package/lib/render/Render.js +152 -176
  48. package/lib/render/index.css +37 -21
  49. package/lib/render/index2.js +6 -0
  50. package/lib/search/Search.js +242 -286
  51. package/lib/search/index.css +4 -0
  52. package/lib/search/index2.js +6 -0
  53. package/lib/sticky/Sticky.js +68 -99
  54. package/lib/sticky/index2.js +6 -0
  55. package/lib/toc/Toc.js +259 -349
  56. package/lib/toc/index2.js +6 -0
  57. package/lib/utils/constant.js +3 -3
  58. package/lib/utils/dom.js +46 -69
  59. package/lib/utils/format.js +33 -33
  60. package/lib/utils/functions.js +4 -4
  61. package/lib/utils/vue.js +10 -31
  62. package/package.json +4 -9
  63. package/es/markdown/index.mjs +0 -9
  64. package/es/render/index.mjs +0 -9
  65. package/es/search/index.mjs +0 -9
  66. package/es/sticky/index.mjs +0 -7
  67. package/es/toc/index.mjs +0 -9
  68. package/lib/markdown/index.js +0 -8
  69. package/lib/render/index.js +0 -8
  70. package/lib/search/index.js +0 -8
  71. package/lib/sticky/index.js +0 -7
  72. package/lib/toc/index.js +0 -8
package/lib/toc/Toc.js CHANGED
@@ -1,354 +1,264 @@
1
- "use strict";
2
- require('./index.css');var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
1
+ require('./index.css');const require_runtime = require("../_virtual/_rolldown/runtime.js");
2
+ const require_objectSpread2 = require("../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.js");
3
+ const require_format = require("../utils/format.js");
4
+ const require_constant = require("../utils/constant.js");
5
+ const require_index = ;/* empty css */
6
+ const require_dom = require("../utils/dom.js");
7
+ const require_asyncToGenerator = require("../_virtual/_@oxc-project_runtime@0.115.0/helpers/asyncToGenerator.js");
8
+ ;/* empty css */
9
+ const require_index$2 = ;/* empty css */
10
+ let lodash = require("lodash");
11
+ let vue = require("vue");
12
+ let markdown_it = require("markdown-it");
13
+ markdown_it = require_runtime.__toESM(markdown_it);
14
+ let _vueuse_core = require("@vueuse/core");
15
+ let compute_scroll_into_view = require("compute-scroll-into-view");
16
+ let _markdown_design_markdown_it_headers = require("@markdown-design/markdown-it-headers");
17
+ //#region src/toc/Toc.tsx
18
+ var START_LEVEL = 1;
19
+ var END_LEVEL = 6;
20
+ var { name, addPrefix } = require_format.createNamespace("toc");
21
+ var tocProps = {
22
+ startLevel: {
23
+ type: [Number, String],
24
+ default: START_LEVEL
25
+ },
26
+ endLevel: {
27
+ type: [Number, String],
28
+ default: END_LEVEL
29
+ },
30
+ orderedList: Boolean,
31
+ plainText: Boolean,
32
+ changeHash: {
33
+ type: Boolean,
34
+ default: true
35
+ },
36
+ target: [
37
+ String,
38
+ Object,
39
+ Function
40
+ ],
41
+ offset: {
42
+ type: [
43
+ String,
44
+ Number,
45
+ Function
46
+ ],
47
+ default: "start"
48
+ },
49
+ bound: {
50
+ type: Number,
51
+ default: 0
52
+ },
53
+ ignore: {
54
+ type: Array,
55
+ default: []
56
+ },
57
+ emptyText: {
58
+ type: String,
59
+ default: "No Data"
60
+ },
61
+ markdown: {
62
+ type: String,
63
+ default: ""
64
+ },
65
+ smooth: Boolean
19
66
  };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- var __async = (__this, __arguments, generator) => {
22
- return new Promise((resolve, reject) => {
23
- var fulfilled = (value) => {
24
- try {
25
- step(generator.next(value));
26
- } catch (e) {
27
- reject(e);
28
- }
29
- };
30
- var rejected = (value) => {
31
- try {
32
- step(generator.throw(value));
33
- } catch (e) {
34
- reject(e);
35
- }
36
- };
37
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
- step((generator = generator.apply(__this, __arguments)).next());
39
- });
67
+ var tocEmits = {
68
+ click: (payload) => (0, lodash.isObject)(payload),
69
+ change: (payload) => (0, lodash.isString)(payload) || (0, lodash.isUndefined)(payload)
40
70
  };
41
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
42
- const vue = require("vue");
43
- ;/* empty css */
44
- const markdownItHeaders = require("@markdown-design/markdown-it-headers");
45
- const lodash = require("lodash");
46
- const format = require("../utils/format.js");
47
- const index = require("../hooks/use-element/index.js");
48
- const MarkdownIt = require("markdown-it");
49
- const core = require("@vueuse/core");
50
- const computeScrollIntoView = require("compute-scroll-into-view");
51
- const index$1 = require("../hooks/use-scroll-element/index.js");
52
- const dom = require("../utils/dom.js");
53
- const constant = require("../utils/constant.js");
54
- const START_LEVEL = 1;
55
- const END_LEVEL = 6;
56
- const {
57
- name,
58
- addPrefix
59
- } = format.createNamespace("toc");
60
- const tocProps = {
61
- startLevel: {
62
- type: [Number, String],
63
- default: START_LEVEL
64
- },
65
- endLevel: {
66
- type: [Number, String],
67
- default: END_LEVEL
68
- },
69
- orderedList: Boolean,
70
- plainText: Boolean,
71
- changeHash: {
72
- type: Boolean,
73
- default: true
74
- },
75
- target: [String, Object, Function],
76
- offset: {
77
- type: [String, Number, Function],
78
- default: "start"
79
- },
80
- bound: {
81
- type: Number,
82
- default: 0
83
- },
84
- ignore: {
85
- type: Array,
86
- default: []
87
- },
88
- emptyText: {
89
- type: String,
90
- default: "No Data"
91
- },
92
- markdown: {
93
- type: String,
94
- default: ""
95
- },
96
- smooth: Boolean
97
- };
98
- const tocEmits = {
99
- click: (payload) => lodash.isObject(payload),
100
- change: (payload) => lodash.isString(payload) || lodash.isUndefined(payload)
101
- };
102
- const _Toc = /* @__PURE__ */ vue.defineComponent({
103
- name,
104
- props: tocProps,
105
- emits: tocEmits,
106
- setup(props, {
107
- emit,
108
- expose,
109
- slots
110
- }) {
111
- const target = vue.computed(() => core.toValue(props.target));
112
- const {
113
- targetEl
114
- } = index.useElement(() => target.value || document.documentElement);
115
- const levelWithNum = vue.computed(() => {
116
- const {
117
- startLevel,
118
- endLevel,
119
- ignore
120
- } = props;
121
- return lodash.chain([startLevel, endLevel]).map((level) => lodash.clamp(Number(level), START_LEVEL, END_LEVEL)).thru(([start, end]) => lodash.range(start, end + 1)).difference(ignore.map(Number)).value();
122
- });
123
- vue.watchEffect(() => {
124
- const {
125
- startLevel,
126
- endLevel
127
- } = props;
128
- const levels = [startLevel, endLevel].map(Number);
129
- if (!levels.every((level) => lodash.inRange(level, START_LEVEL, END_LEVEL + 1))) {
130
- console.warn("[vue-markdown-design] The start-level or end-level is outside the valid range.");
131
- }
132
- if (!lodash.lte(...levels)) {
133
- console.warn("[vue-markdown-design] The start-level must be less than the end-level.");
134
- }
135
- });
136
- const md = new MarkdownIt({
137
- html: true
138
- });
139
- md.use(markdownItHeaders.headers);
140
- const mdToc = vue.computed(() => {
141
- const env = {};
142
- md.render(props.markdown, env);
143
- const {
144
- headings: headings2 = []
145
- } = env;
146
- return headings2.filter((item) => levelWithNum.value.includes(item.level));
147
- });
148
- const isMd = vue.computed(() => !target.value && !!props.markdown);
149
- const isPlainText = vue.computed(() => isMd.value || props.plainText);
150
- const headings = vue.ref([]);
151
- const setHeading = () => {
152
- var _a;
153
- if (!levelWithNum.value.length) {
154
- headings.value = [];
155
- return;
156
- }
157
- const selectors = levelWithNum.value.map((level) => `h${level}`).join(",");
158
- const headingEl = (_a = targetEl.value) == null ? void 0 : _a.querySelectorAll(selectors);
159
- const newHeadings = Array.from(headingEl || []);
160
- if (lodash.isEqual(headings.value, newHeadings)) return;
161
- headings.value = newHeadings;
162
- };
163
- const offsetResult = vue.computed(() => format.computeOffset(props.offset));
164
- const topMap = vue.ref(/* @__PURE__ */ new Map());
165
- const setTop = () => {
166
- const {
167
- block,
168
- getOffset
169
- } = offsetResult.value;
170
- headings.value.forEach((heading) => {
171
- const [scrollAction] = computeScrollIntoView.compute(heading, {
172
- block
173
- });
174
- const curOffset = getOffset(scrollAction, true);
175
- const val = scrollAction.top - curOffset - props.bound;
176
- topMap.value.set(heading.id, Math.floor(val));
177
- });
178
- };
179
- const setToc = () => {
180
- if (isMd.value || !targetEl.value) return;
181
- setHeading();
182
- setTop();
183
- };
184
- vue.watchEffect(setToc);
185
- const refresh = () => __async(this, null, function* () {
186
- headings.value = [];
187
- yield vue.nextTick();
188
- setToc();
189
- });
190
- vue.watch(() => {
191
- var _a;
192
- return (_a = target.value) == null ? void 0 : _a.htmlStr;
193
- }, refresh);
194
- const getText = (el) => {
195
- const node = el.cloneNode(true);
196
- const anchors = node.querySelectorAll(`[${constant.DATA_ANCHOR}]`);
197
- anchors.forEach((item) => node.removeChild(item));
198
- return node.innerText.trim();
199
- };
200
- const listData = vue.computed(() => {
201
- if (isMd.value) return mdToc.value;
202
- return headings.value.map((heading) => {
203
- const {
204
- id,
205
- tagName
206
- } = heading;
207
- return {
208
- id,
209
- text: getText(heading),
210
- level: Number(tagName[1]),
211
- top: topMap.value.get(id)
212
- };
213
- });
214
- });
215
- const runtimeLevel = vue.computed(() => {
216
- if (!listData.value.length) return [0, 0];
217
- const level = listData.value.map((item) => item.level);
218
- return [Math.min(...level), Math.max(...level)];
219
- });
220
- const wait = 16;
221
- let ScrollStatus = /* @__PURE__ */ function(ScrollStatus2) {
222
- ScrollStatus2[ScrollStatus2["Start"] = 0] = "Start";
223
- ScrollStatus2[ScrollStatus2["Update"] = 1] = "Update";
224
- ScrollStatus2[ScrollStatus2["Done"] = 2] = "Done";
225
- return ScrollStatus2;
226
- }({});
227
- let scrollStatus = ScrollStatus.Done;
228
- const setScrollStatus = (key) => {
229
- const status = ScrollStatus[key];
230
- if (scrollStatus !== status) {
231
- scrollStatus = status;
232
- }
233
- };
234
- const {
235
- scrollEl
236
- } = index$1.useScrollParent(targetEl);
237
- const resolvedScrollEl = vue.computed(() => {
238
- var _a;
239
- return scrollEl.value || ((_a = targetEl.value) == null ? void 0 : _a.ownerDocument.documentElement);
240
- });
241
- const activeId = vue.ref();
242
- const onChange = () => {
243
- if (scrollStatus === ScrollStatus.Done) {
244
- emit("change", activeId.value);
245
- }
246
- };
247
- const onScroll = lodash.throttle(() => {
248
- var _a;
249
- if (scrollStatus === ScrollStatus.Start || isPlainText.value) return;
250
- setToc();
251
- const scrollTop = Math.floor(((_a = resolvedScrollEl.value) == null ? void 0 : _a.scrollTop) || 0);
252
- const current = listData.value.map((item) => __spreadProps(__spreadValues({}, item), {
253
- top: item.top || 0
254
- })).sort((a, b) => a.top - b.top).find((item, index2, arr) => {
255
- const next = arr[index2 + 1];
256
- return item.top <= scrollTop && (!next || next.top > scrollTop) && !(index2 === 0 && scrollTop === 0);
257
- });
258
- const id = (current == null ? void 0 : current.id) || void 0;
259
- if (activeId.value === id) return;
260
- activeId.value = id;
261
- onChange();
262
- }, wait);
263
- vue.watchEffect(() => vue.nextTick().then(onScroll));
264
- core.useEventListener(() => scrollEl.value || window, "scroll", onScroll);
265
- const scrollTo = (href) => {
266
- var _a;
267
- if (!href) return console.warn("[vue-markdown-design] Href has no value.");
268
- const headingEl = (_a = targetEl.value) == null ? void 0 : _a.querySelector(`[id='${href}']`);
269
- if (!headingEl) return console.warn("[vue-markdown-design] The provided href failed to query the DOM.");
270
- const {
271
- offset,
272
- smooth
273
- } = props;
274
- dom.scrollToEl(headingEl, {
275
- offset,
276
- smooth,
277
- onPlay: () => setScrollStatus("Start"),
278
- onUpdate: () => setScrollStatus("Update"),
279
- onComplete: () => setTimeout(() => {
280
- setScrollStatus("Done");
281
- onChange();
282
- }, wait + 4)
283
- // 设置延迟可确保在 onScroll 后面再执行
284
- });
285
- };
286
- const onClick = (tocItem, e) => {
287
- if (!props.changeHash) e.preventDefault();
288
- scrollTo(tocItem.id);
289
- emit("click", tocItem);
290
- };
291
- const renderItem = () => {
292
- const {
293
- orderedList
294
- } = props;
295
- const [startLevel, endLevel] = runtimeLevel.value;
296
- const orderCounter = new Array(endLevel - startLevel + 1).fill(0);
297
- return listData.value.map((item) => {
298
- const {
299
- level,
300
- text,
301
- id,
302
- top
303
- } = item;
304
- const relativeLevel = level - startLevel;
305
- orderedList && orderCounter.fill(0, relativeLevel + 1);
306
- const attrs = {
307
- class: addPrefix("__text"),
308
- style: {
309
- paddingLeft: `${relativeLevel}em`
310
- }
311
- };
312
- const plainText = orderedList ? `${++orderCounter[relativeLevel]}. ${text}` : text;
313
- const isActive = activeId.value === id;
314
- const tocItem = {
315
- id,
316
- top,
317
- level,
318
- relativeLevel,
319
- isActive,
320
- text: plainText
321
- };
322
- const itemContent = slots.item ? slots.item(tocItem) : plainText;
323
- const className = addPrefix("__item");
324
- if (isPlainText.value || !id) {
325
- return vue.createVNode("li", {
326
- "class": className
327
- }, [vue.createVNode("span", attrs, [itemContent])]);
328
- }
329
- return vue.createVNode("li", {
330
- "class": [className, {
331
- [addPrefix("__item--active")]: isActive
332
- }]
333
- }, [vue.createVNode("a", vue.mergeProps(attrs, {
334
- "href": `#${id}`,
335
- "onClick": (e) => onClick(tocItem, e)
336
- }), [itemContent])]);
337
- });
338
- };
339
- expose({
340
- refresh,
341
- scrollTo
342
- });
343
- return () => vue.createVNode("nav", {
344
- "class": name
345
- }, [listData.value.length ? vue.createVNode("ul", {
346
- "class": [addPrefix("__list"), addPrefix("--padding")]
347
- }, [renderItem()]) : vue.createVNode("div", {
348
- "class": [addPrefix("__empty"), addPrefix("--padding")]
349
- }, [props.emptyText])]);
350
- }
71
+ var Toc_default = /* @__PURE__ */ (0, vue.defineComponent)({
72
+ name,
73
+ props: tocProps,
74
+ emits: tocEmits,
75
+ setup(props, { emit, expose, slots }) {
76
+ const target = (0, vue.computed)(() => (0, _vueuse_core.toValue)(props.target));
77
+ const { targetEl } = require_index.useElement(() => target.value || document.documentElement);
78
+ const levelWithNum = (0, vue.computed)(() => {
79
+ const { startLevel, endLevel, ignore } = props;
80
+ return (0, lodash.chain)([startLevel, endLevel]).map((level) => (0, lodash.clamp)(Number(level), START_LEVEL, END_LEVEL)).thru(([start, end]) => (0, lodash.range)(start, end + 1)).difference(ignore.map(Number)).value();
81
+ });
82
+ (0, vue.watchEffect)(() => {
83
+ const { startLevel, endLevel } = props;
84
+ const levels = [startLevel, endLevel].map(Number);
85
+ if (!levels.every((level) => (0, lodash.inRange)(level, START_LEVEL, END_LEVEL + 1))) console.warn("[vue-markdown-design] The start-level or end-level is outside the valid range.");
86
+ if (!(0, lodash.lte)(...levels)) console.warn("[vue-markdown-design] The start-level must be less than the end-level.");
87
+ });
88
+ const md = new markdown_it.default({ html: true });
89
+ md.use(_markdown_design_markdown_it_headers.headers);
90
+ const mdToc = (0, vue.computed)(() => {
91
+ const env = {};
92
+ md.render(props.markdown, env);
93
+ const { headings = [] } = env;
94
+ return headings.filter((item) => levelWithNum.value.includes(item.level));
95
+ });
96
+ const isMd = (0, vue.computed)(() => !target.value && !!props.markdown);
97
+ const isPlainText = (0, vue.computed)(() => isMd.value || props.plainText);
98
+ const headings = (0, vue.ref)([]);
99
+ const setHeading = () => {
100
+ var _targetEl$value;
101
+ if (!levelWithNum.value.length) {
102
+ headings.value = [];
103
+ return;
104
+ }
105
+ const selectors = levelWithNum.value.map((level) => `h${level}`).join(",");
106
+ const headingEl = (_targetEl$value = targetEl.value) === null || _targetEl$value === void 0 ? void 0 : _targetEl$value.querySelectorAll(selectors);
107
+ const newHeadings = Array.from(headingEl || []);
108
+ if ((0, lodash.isEqual)(headings.value, newHeadings)) return;
109
+ headings.value = newHeadings;
110
+ };
111
+ const offsetResult = (0, vue.computed)(() => require_format.computeOffset(props.offset));
112
+ const topMap = (0, vue.ref)(/* @__PURE__ */ new Map());
113
+ const setTop = () => {
114
+ const { block, getOffset } = offsetResult.value;
115
+ headings.value.forEach((heading) => {
116
+ const [scrollAction] = (0, compute_scroll_into_view.compute)(heading, { block });
117
+ const curOffset = getOffset(scrollAction, true);
118
+ const val = scrollAction.top - curOffset - props.bound;
119
+ topMap.value.set(heading.id, Math.floor(val));
120
+ });
121
+ };
122
+ const setToc = () => {
123
+ if (isMd.value || !targetEl.value) return;
124
+ setHeading();
125
+ setTop();
126
+ };
127
+ (0, vue.watchEffect)(setToc);
128
+ const refresh = function() {
129
+ var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
130
+ headings.value = [];
131
+ yield (0, vue.nextTick)();
132
+ setToc();
133
+ });
134
+ return function refresh() {
135
+ return _ref.apply(this, arguments);
136
+ };
137
+ }();
138
+ (0, vue.watch)(() => {
139
+ var _target$value;
140
+ return (_target$value = target.value) === null || _target$value === void 0 ? void 0 : _target$value.htmlStr;
141
+ }, refresh);
142
+ const getText = (el) => {
143
+ const node = el.cloneNode(true);
144
+ node.querySelectorAll(`[${require_constant.DATA_ANCHOR}]`).forEach((item) => node.removeChild(item));
145
+ return node.innerText.trim();
146
+ };
147
+ const listData = (0, vue.computed)(() => {
148
+ if (isMd.value) return mdToc.value;
149
+ return headings.value.map((heading) => {
150
+ const { id, tagName } = heading;
151
+ return {
152
+ id,
153
+ text: getText(heading),
154
+ level: Number(tagName[1]),
155
+ top: topMap.value.get(id)
156
+ };
157
+ });
158
+ });
159
+ const runtimeLevel = (0, vue.computed)(() => {
160
+ if (!listData.value.length) return [0, 0];
161
+ const level = listData.value.map((item) => item.level);
162
+ return [Math.min(...level), Math.max(...level)];
163
+ });
164
+ const wait = 16;
165
+ let ScrollStatus = /* @__PURE__ */ function(ScrollStatus) {
166
+ ScrollStatus[ScrollStatus["Start"] = 0] = "Start";
167
+ ScrollStatus[ScrollStatus["Update"] = 1] = "Update";
168
+ ScrollStatus[ScrollStatus["Done"] = 2] = "Done";
169
+ return ScrollStatus;
170
+ }({});
171
+ let scrollStatus = ScrollStatus.Done;
172
+ const setScrollStatus = (key) => {
173
+ const status = ScrollStatus[key];
174
+ if (scrollStatus !== status) scrollStatus = status;
175
+ };
176
+ const { scrollEl } = require_index$2.useScrollParent(targetEl);
177
+ const resolvedScrollEl = (0, vue.computed)(() => {
178
+ var _targetEl$value2;
179
+ return scrollEl.value || ((_targetEl$value2 = targetEl.value) === null || _targetEl$value2 === void 0 ? void 0 : _targetEl$value2.ownerDocument.documentElement);
180
+ });
181
+ const activeId = (0, vue.ref)();
182
+ const onChange = () => {
183
+ if (scrollStatus === ScrollStatus.Done) emit("change", activeId.value);
184
+ };
185
+ const onScroll = (0, lodash.throttle)(() => {
186
+ var _resolvedScrollEl$val;
187
+ if (scrollStatus === ScrollStatus.Start || isPlainText.value) return;
188
+ setToc();
189
+ const scrollTop = Math.floor(((_resolvedScrollEl$val = resolvedScrollEl.value) === null || _resolvedScrollEl$val === void 0 ? void 0 : _resolvedScrollEl$val.scrollTop) || 0);
190
+ const current = listData.value.map((item) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { top: item.top || 0 })).sort((a, b) => a.top - b.top).find((item, index, arr) => {
191
+ const next = arr[index + 1];
192
+ return item.top <= scrollTop && (!next || next.top > scrollTop) && !(index === 0 && scrollTop === 0);
193
+ });
194
+ const id = (current === null || current === void 0 ? void 0 : current.id) || void 0;
195
+ if (activeId.value === id) return;
196
+ activeId.value = id;
197
+ onChange();
198
+ }, wait);
199
+ (0, vue.watchEffect)(() => (0, vue.nextTick)().then(onScroll));
200
+ (0, _vueuse_core.useEventListener)(() => scrollEl.value || window, "scroll", onScroll);
201
+ const scrollTo = (href) => {
202
+ var _targetEl$value3;
203
+ if (!href) return console.warn("[vue-markdown-design] Href has no value.");
204
+ const headingEl = (_targetEl$value3 = targetEl.value) === null || _targetEl$value3 === void 0 ? void 0 : _targetEl$value3.querySelector(`[id='${href}']`);
205
+ if (!headingEl) return console.warn("[vue-markdown-design] The provided href failed to query the DOM.");
206
+ const { offset, smooth } = props;
207
+ require_dom.scrollToEl(headingEl, {
208
+ offset,
209
+ smooth,
210
+ onPlay: () => setScrollStatus("Start"),
211
+ onUpdate: () => setScrollStatus("Update"),
212
+ onComplete: () => setTimeout(() => {
213
+ setScrollStatus("Done");
214
+ onChange();
215
+ }, wait + 4)
216
+ });
217
+ };
218
+ const onClick = (tocItem, e) => {
219
+ if (!props.changeHash) e.preventDefault();
220
+ scrollTo(tocItem.id);
221
+ emit("click", tocItem);
222
+ };
223
+ const renderItem = () => {
224
+ const { orderedList } = props;
225
+ const [startLevel, endLevel] = runtimeLevel.value;
226
+ const orderCounter = new Array(endLevel - startLevel + 1).fill(0);
227
+ return listData.value.map((item) => {
228
+ const { level, text, id, top } = item;
229
+ const relativeLevel = level - startLevel;
230
+ orderedList && orderCounter.fill(0, relativeLevel + 1);
231
+ const attrs = {
232
+ class: addPrefix("__text"),
233
+ style: { paddingLeft: `${relativeLevel}em` }
234
+ };
235
+ const plainText = orderedList ? `${++orderCounter[relativeLevel]}. ${text}` : text;
236
+ const isActive = activeId.value === id;
237
+ const tocItem = {
238
+ id,
239
+ top,
240
+ level,
241
+ relativeLevel,
242
+ isActive,
243
+ text: plainText
244
+ };
245
+ const itemContent = slots.item ? slots.item(tocItem) : plainText;
246
+ const className = addPrefix("__item");
247
+ if (isPlainText.value || !id) return (0, vue.createVNode)("li", { "class": className }, [(0, vue.createVNode)("span", attrs, [itemContent])]);
248
+ return (0, vue.createVNode)("li", { "class": [className, { [addPrefix("__item--active")]: isActive }] }, [(0, vue.createVNode)("a", (0, vue.mergeProps)(attrs, {
249
+ "href": `#${id}`,
250
+ "onClick": (e) => onClick(tocItem, e)
251
+ }), [itemContent])]);
252
+ });
253
+ };
254
+ expose({
255
+ refresh,
256
+ scrollTo
257
+ });
258
+ return () => (0, vue.createVNode)("nav", { "class": name }, [listData.value.length ? (0, vue.createVNode)("ul", { "class": [addPrefix("__list"), addPrefix("--padding")] }, [renderItem()]) : (0, vue.createVNode)("div", { "class": [addPrefix("__empty"), addPrefix("--padding")] }, [props.emptyText])]);
259
+ }
351
260
  });
352
- exports.default = _Toc;
261
+ //#endregion
262
+ exports.default = Toc_default;
353
263
  exports.tocEmits = tocEmits;
354
264
  exports.tocProps = tocProps;
@@ -0,0 +1,6 @@
1
+ const require_vue = require("../utils/vue.js");
2
+ const require_Toc = require("./Toc.js");
3
+ //#region src/toc/index.ts
4
+ var VmdToc = require_vue.withInstall(require_Toc.default);
5
+ //#endregion
6
+ exports.default = VmdToc;
@@ -1,4 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const DATA_ANCHOR = "data-vmd-anchor";
1
+ //#region src/utils/constant.ts
2
+ var DATA_ANCHOR = "data-vmd-anchor";
3
+ //#endregion
4
4
  exports.DATA_ANCHOR = DATA_ANCHOR;