vue-markdown-design 0.1.0
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 +21 -0
- package/README.md +45 -0
- package/README.zh-CN.md +43 -0
- package/es/hooks/use-element/index.d.ts +6 -0
- package/es/hooks/use-element/index.mjs +22 -0
- package/es/hooks/use-scroll-element/index.d.ts +13 -0
- package/es/hooks/use-scroll-element/index.mjs +53 -0
- package/es/index.d.ts +6 -0
- package/es/index.mjs +22 -0
- package/es/markdown/Markdown.d.ts +544 -0
- package/es/markdown/Markdown.mjs +296 -0
- package/es/markdown/index.css +105 -0
- package/es/markdown/index.d.ts +870 -0
- package/es/markdown/index.mjs +9 -0
- package/es/markdown/type.d.ts +16 -0
- package/es/render/Render.d.ts +207 -0
- package/es/render/Render.mjs +184 -0
- package/es/render/index.css +1287 -0
- package/es/render/index.d.ts +313 -0
- package/es/render/index.mjs +9 -0
- package/es/render/type.d.ts +10 -0
- package/es/search/Search.d.ts +171 -0
- package/es/search/Search.mjs +263 -0
- package/es/search/index.css +88 -0
- package/es/search/index.d.ts +282 -0
- package/es/search/index.mjs +9 -0
- package/es/search/type.d.ts +9 -0
- package/es/sticky/Sticky.d.ts +55 -0
- package/es/sticky/Sticky.mjs +240 -0
- package/es/sticky/index.css +3 -0
- package/es/sticky/index.d.ts +127 -0
- package/es/sticky/index.mjs +7 -0
- package/es/style/variables.css +11 -0
- package/es/toc/TOC.d.ts +140 -0
- package/es/toc/TOC.mjs +316 -0
- package/es/toc/index.css +50 -0
- package/es/toc/index.d.ts +226 -0
- package/es/toc/index.mjs +9 -0
- package/es/toc/type.d.ts +19 -0
- package/es/utils/dom.d.ts +15 -0
- package/es/utils/dom.mjs +74 -0
- package/es/utils/format.d.ts +12 -0
- package/es/utils/format.mjs +47 -0
- package/es/utils/functions.d.ts +1 -0
- package/es/utils/functions.mjs +7 -0
- package/es/utils/types.d.ts +5 -0
- package/es/utils/vue.d.ts +4 -0
- package/es/utils/vue.mjs +34 -0
- package/lib/hooks/use-element/index.d.ts +6 -0
- package/lib/hooks/use-element/index.js +22 -0
- package/lib/hooks/use-scroll-element/index.d.ts +13 -0
- package/lib/hooks/use-scroll-element/index.js +53 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +22 -0
- package/lib/markdown/Markdown.d.ts +544 -0
- package/lib/markdown/Markdown.js +296 -0
- package/lib/markdown/index.css +105 -0
- package/lib/markdown/index.d.ts +870 -0
- package/lib/markdown/index.js +8 -0
- package/lib/markdown/type.d.ts +16 -0
- package/lib/render/Render.d.ts +207 -0
- package/lib/render/Render.js +184 -0
- package/lib/render/index.css +1287 -0
- package/lib/render/index.d.ts +313 -0
- package/lib/render/index.js +8 -0
- package/lib/render/type.d.ts +10 -0
- package/lib/search/Search.d.ts +171 -0
- package/lib/search/Search.js +263 -0
- package/lib/search/index.css +88 -0
- package/lib/search/index.d.ts +282 -0
- package/lib/search/index.js +8 -0
- package/lib/search/type.d.ts +9 -0
- package/lib/sticky/Sticky.d.ts +55 -0
- package/lib/sticky/Sticky.js +239 -0
- package/lib/sticky/index.css +3 -0
- package/lib/sticky/index.d.ts +127 -0
- package/lib/sticky/index.js +7 -0
- package/lib/style/variables.css +11 -0
- package/lib/toc/TOC.d.ts +140 -0
- package/lib/toc/TOC.js +316 -0
- package/lib/toc/index.css +50 -0
- package/lib/toc/index.d.ts +226 -0
- package/lib/toc/index.js +8 -0
- package/lib/toc/type.d.ts +19 -0
- package/lib/utils/dom.d.ts +15 -0
- package/lib/utils/dom.js +74 -0
- package/lib/utils/format.d.ts +12 -0
- package/lib/utils/format.js +47 -0
- package/lib/utils/functions.d.ts +1 -0
- package/lib/utils/functions.js +7 -0
- package/lib/utils/types.d.ts +5 -0
- package/lib/utils/vue.d.ts +4 -0
- package/lib/utils/vue.js +34 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Zero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
English | [中文](./README.zh-CN.md)
|
|
2
|
+
|
|
3
|
+
# Vue Markdown Design
|
|
4
|
+
|
|
5
|
+
A Vue 3 out-of-the-box Markdown component built on [markdown-it](https://github.com/markdown-it/markdown-it). It mainly features Markdown rendering, TOC generation, and keyword search. It also includes other common functionalities such as support for markdown-it plugins, emoji, heading permalinks, XSS sanitization, and TypeScript.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
### Installation
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm i vue-markdown-design
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// main.js
|
|
19
|
+
|
|
20
|
+
// Import component
|
|
21
|
+
import VueMarkdown from 'vue-markdown-design'
|
|
22
|
+
|
|
23
|
+
import { createApp } from 'vue'
|
|
24
|
+
|
|
25
|
+
const app = createApp()
|
|
26
|
+
|
|
27
|
+
// Register component
|
|
28
|
+
app.use(VueMarkdown)
|
|
29
|
+
|
|
30
|
+
app.mount('#app')
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```vue
|
|
34
|
+
<!-- demo.vue -->
|
|
35
|
+
|
|
36
|
+
<vue-markdown :src="`# Title\nContent`" />
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## More
|
|
40
|
+
|
|
41
|
+
More documentation coming soon!
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
[MIT](../../LICENSE).
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Vue Markdown Design
|
|
2
|
+
|
|
3
|
+
一个基于 [markdown-it](https://github.com/markdown-it/markdown-it) 的 Vue 3 开箱即用 Markdown 组件,主要功能有 Markdown 渲染,目录生成,关键字搜索。同时内置其他常用功能,包括支持 markdown-it 插件,emoji 表情,标题永久链接,防御 XSS 攻击,支持 TypeScript 等。
|
|
4
|
+
|
|
5
|
+
## 快速上手
|
|
6
|
+
|
|
7
|
+
### 安装
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i vue-markdown-design
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 使用
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// main.js
|
|
17
|
+
|
|
18
|
+
// 引入组件
|
|
19
|
+
import VueMarkdown from 'vue-markdown-design'
|
|
20
|
+
|
|
21
|
+
import { createApp } from 'vue'
|
|
22
|
+
|
|
23
|
+
const app = createApp()
|
|
24
|
+
|
|
25
|
+
// 注册组件
|
|
26
|
+
app.use(VueMarkdown)
|
|
27
|
+
|
|
28
|
+
app.mount('#app')
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```vue
|
|
32
|
+
<!-- demo.vue -->
|
|
33
|
+
|
|
34
|
+
<vue-markdown :src="`# 标题\n内容`" />
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 更多
|
|
38
|
+
|
|
39
|
+
详细文档即将发布,敬请期待!
|
|
40
|
+
|
|
41
|
+
## 开源协议
|
|
42
|
+
|
|
43
|
+
本项目基于 [MIT](../../LICENSE) 协议。
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MaybeElement, UnRefElementReturn } from '@vueuse/core';
|
|
2
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
3
|
+
export declare function useElement(target?: MaybeRefOrGetter<MaybeElement | string>): {
|
|
4
|
+
targetEl: import('vue').ShallowRef<UnRefElementReturn>;
|
|
5
|
+
update: () => void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { toRef, unrefElement } from "@vueuse/core";
|
|
2
|
+
import { isString } from "lodash";
|
|
3
|
+
import { shallowRef, watch, onMounted } from "vue";
|
|
4
|
+
function useElement(target) {
|
|
5
|
+
const targetEl = shallowRef();
|
|
6
|
+
const targetRef = toRef(target);
|
|
7
|
+
const update = () => {
|
|
8
|
+
if (!targetRef.value) return;
|
|
9
|
+
if (!isString(targetRef.value)) {
|
|
10
|
+
targetEl.value = unrefElement(targetRef.value);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
targetEl.value = document.querySelector(targetRef.value);
|
|
14
|
+
if (!targetEl.value) console.error("[vue-markdown-design] Target does not exist.");
|
|
15
|
+
};
|
|
16
|
+
watch(targetRef, update, { flush: "post" });
|
|
17
|
+
onMounted(update);
|
|
18
|
+
return { targetEl, update };
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
useElement
|
|
22
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MaybeComputedElementRef, UnRefElementReturn } from '@vueuse/core';
|
|
2
|
+
import { ShallowRef } from 'vue';
|
|
3
|
+
interface UseScrollParentOptions<T extends boolean> {
|
|
4
|
+
onlyParent?: T;
|
|
5
|
+
}
|
|
6
|
+
interface UseScrollParentReturn<T> {
|
|
7
|
+
scrollEl: ShallowRef<T>;
|
|
8
|
+
update: () => void;
|
|
9
|
+
}
|
|
10
|
+
type NonNullableElement = NonNullable<UnRefElementReturn>;
|
|
11
|
+
export declare function useScrollParent(target: MaybeComputedElementRef, options?: UseScrollParentOptions<true>): UseScrollParentReturn<UnRefElementReturn>;
|
|
12
|
+
export declare function useScrollParent(target: MaybeComputedElementRef, options?: UseScrollParentOptions<false>): UseScrollParentReturn<NonNullableElement[]>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { unrefElement, useMutationObserver } from "@vueuse/core";
|
|
2
|
+
import { shallowRef, watch, onMounted } from "vue";
|
|
3
|
+
const tagNames = /* @__PURE__ */ new Set(["HTML", "BODY"]);
|
|
4
|
+
const scrollReg = /scroll|auto|overlay/i;
|
|
5
|
+
function getScrollElement(el, onlyParent) {
|
|
6
|
+
let node = el;
|
|
7
|
+
const nodes = [];
|
|
8
|
+
while (node.nodeType === 1 && !tagNames.has(node.tagName)) {
|
|
9
|
+
const { overflowY } = window.getComputedStyle(node);
|
|
10
|
+
if (scrollReg.test(overflowY)) {
|
|
11
|
+
nodes.push(node);
|
|
12
|
+
if (onlyParent) break;
|
|
13
|
+
}
|
|
14
|
+
const { parentNode } = node;
|
|
15
|
+
if (!(parentNode instanceof Element)) break;
|
|
16
|
+
node = parentNode;
|
|
17
|
+
}
|
|
18
|
+
return onlyParent ? nodes[0] : nodes;
|
|
19
|
+
}
|
|
20
|
+
function isElement(el) {
|
|
21
|
+
return [HTMLElement, SVGElement].some((type) => el instanceof type);
|
|
22
|
+
}
|
|
23
|
+
function useScrollParent(target, options = {}) {
|
|
24
|
+
const { onlyParent = true } = options;
|
|
25
|
+
const initialValue = onlyParent ? void 0 : [];
|
|
26
|
+
const scrollEl = shallowRef(initialValue);
|
|
27
|
+
const update = () => {
|
|
28
|
+
const el = unrefElement(target);
|
|
29
|
+
if (!el) {
|
|
30
|
+
scrollEl.value = initialValue;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const scrollElement = getScrollElement(el, onlyParent);
|
|
34
|
+
if (Array.isArray(scrollElement)) {
|
|
35
|
+
scrollEl.value = scrollElement.filter(isElement);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (isElement(scrollElement)) {
|
|
39
|
+
scrollEl.value = scrollElement;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
watch(() => unrefElement(target), update, { flush: "post" });
|
|
43
|
+
useMutationObserver(
|
|
44
|
+
() => Array.isArray(scrollEl.value) ? scrollEl.value : [scrollEl.value],
|
|
45
|
+
update,
|
|
46
|
+
{ attributeFilter: ["style", "class"] }
|
|
47
|
+
);
|
|
48
|
+
onMounted(update);
|
|
49
|
+
return { scrollEl, update };
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
useScrollParent
|
|
53
|
+
};
|
package/es/index.d.ts
ADDED
package/es/index.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import './style/variables.css';/* empty css */
|
|
2
|
+
import { VmdRender } from "./render/index.mjs";
|
|
3
|
+
import { VmdSearch } from "./search/index.mjs";
|
|
4
|
+
import { VmdTOC } from "./toc/index.mjs";
|
|
5
|
+
import { VmdSticky } from "./sticky/index.mjs";
|
|
6
|
+
import { VueMarkdown, VueMarkdown as VueMarkdown2 } from "./markdown/index.mjs";
|
|
7
|
+
import { renderProps } from "./render/Render.mjs";
|
|
8
|
+
import { searchProps } from "./search/Search.mjs";
|
|
9
|
+
import { tocProps } from "./toc/TOC.mjs";
|
|
10
|
+
import { markdownProps } from "./markdown/Markdown.mjs";
|
|
11
|
+
export {
|
|
12
|
+
VmdRender,
|
|
13
|
+
VmdSearch,
|
|
14
|
+
VmdSticky,
|
|
15
|
+
VmdTOC,
|
|
16
|
+
VueMarkdown,
|
|
17
|
+
VueMarkdown2 as default,
|
|
18
|
+
markdownProps,
|
|
19
|
+
renderProps,
|
|
20
|
+
searchProps,
|
|
21
|
+
tocProps
|
|
22
|
+
};
|