@antdv-next/docs-plugins 0.0.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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +133 -0
  3. package/dist/demo/formatter.d.ts +17 -0
  4. package/dist/demo/formatter.js +32 -0
  5. package/dist/demo/get-demo-id.d.ts +9 -0
  6. package/dist/demo/get-demo-id.js +19 -0
  7. package/dist/demo/index.d.ts +26 -0
  8. package/dist/demo/index.js +359 -0
  9. package/dist/demo/tsToJs.d.ts +9 -0
  10. package/dist/demo/tsToJs.js +60 -0
  11. package/dist/demo/types.d.ts +23 -0
  12. package/dist/index.d.ts +20 -0
  13. package/dist/index.js +19 -0
  14. package/dist/isolate-styles.d.ts +14 -0
  15. package/dist/isolate-styles.js +30 -0
  16. package/dist/markdown.d.ts +39 -0
  17. package/dist/markdown.js +115 -0
  18. package/dist/md-plugin.d.ts +18 -0
  19. package/dist/md-plugin.js +9 -0
  20. package/dist/md2vue.d.ts +16 -0
  21. package/dist/md2vue.js +106 -0
  22. package/dist/plugins/container.d.ts +16 -0
  23. package/dist/plugins/container.js +53 -0
  24. package/dist/plugins/demo.d.ts +29 -0
  25. package/dist/plugins/demo.js +139 -0
  26. package/dist/plugins/github-alerts.d.ts +6 -0
  27. package/dist/plugins/github-alerts.js +49 -0
  28. package/dist/plugins/image.d.ts +12 -0
  29. package/dist/plugins/image.js +17 -0
  30. package/dist/plugins/link.d.ts +14 -0
  31. package/dist/plugins/link.js +25 -0
  32. package/dist/plugins/pre-wrapper.d.ts +10 -0
  33. package/dist/plugins/pre-wrapper.js +26 -0
  34. package/dist/plugins/stackblitz.d.ts +5 -0
  35. package/dist/plugins/stackblitz.js +21 -0
  36. package/dist/plugins/table.d.ts +5 -0
  37. package/dist/plugins/table.js +25 -0
  38. package/dist/shared.d.ts +7 -0
  39. package/dist/shared.js +7 -0
  40. package/dist/utils/short-hash.d.ts +4 -0
  41. package/dist/utils/short-hash.js +21 -0
  42. package/package.json +94 -0
  43. package/src/components/code-demo/code-editor-bridge.vue +36 -0
  44. package/src/components/code-demo/compile-sfc.ts +207 -0
  45. package/src/components/code-demo/context.ts +86 -0
  46. package/src/components/code-demo/expand-icon.vue +12 -0
  47. package/src/components/code-demo/external-link-icon.vue +5 -0
  48. package/src/components/code-demo/index.vue +682 -0
  49. package/src/components/code-demo/virtual.d.ts +38 -0
  50. package/src/demo/formatter.ts +50 -0
  51. package/src/demo/get-demo-id.ts +33 -0
  52. package/src/demo/index.ts +498 -0
  53. package/src/demo/tsToJs.ts +79 -0
  54. package/src/demo/types.ts +23 -0
  55. package/src/index.ts +19 -0
  56. package/src/isolate-styles.ts +47 -0
  57. package/src/markdown.ts +188 -0
  58. package/src/md-plugin.ts +24 -0
  59. package/src/md2vue.ts +163 -0
  60. package/src/plugins/container.ts +135 -0
  61. package/src/plugins/demo.ts +282 -0
  62. package/src/plugins/github-alerts.ts +69 -0
  63. package/src/plugins/image.ts +29 -0
  64. package/src/plugins/link.ts +32 -0
  65. package/src/plugins/pre-wrapper.ts +49 -0
  66. package/src/plugins/stackblitz.ts +32 -0
  67. package/src/plugins/table.ts +39 -0
  68. package/src/shared.ts +4 -0
  69. package/src/utils/short-hash.ts +27 -0
@@ -0,0 +1,86 @@
1
+ import type { InjectionKey } from 'vue'
2
+ import { inject, provide } from 'vue'
3
+
4
+ /** 组件内置文案 key(可通过 DemoContext.t / labels 覆盖) */
5
+ export type DemoLabelKey
6
+ = | 'action.copy'
7
+ | 'action.copied'
8
+ | 'action.stackblitz'
9
+ | 'action.externalLink'
10
+ | 'action.openPlayground'
11
+ | 'action.expandCode'
12
+ | 'action.expandedCode'
13
+ | 'action.loadError'
14
+ | 'type.typescript'
15
+ | 'type.javascript'
16
+
17
+ export interface DemoContext {
18
+ /** 当前语言(决定内置文案与 demo 描述的选取),如 'zh-CN' / 'en-US' */
19
+ locale?: () => string
20
+ /** 自定义文案(i18n),key 见 DemoLabelKey */
21
+ t?: (key: DemoLabelKey) => string
22
+ /** 暗色状态(Sandpack 编辑器主题跟随) */
23
+ isDark?: () => boolean
24
+ /**
25
+ * 额外可被演示源码 import 的模块(浏览器实时编译用)。
26
+ * 由站点提供(如组件库本体),逐模块容错,不可用只影响编辑预览。
27
+ */
28
+ modules?: Record<string, () => Promise<any>>
29
+ /** 在 Playground 中打开(不提供则隐藏按钮) */
30
+ openPlayground?: (code: string) => void
31
+ /** 在 StackBlitz 中打开(不提供则隐藏按钮) */
32
+ openStackBlitz?: (options: { title: string, code: string }) => void
33
+ /** demo 独立页地址(不提供则隐藏按钮) */
34
+ demoPageUrl?: (id: string) => string
35
+ /** iframe 模式渲染器(不提供则忽略 iframe 属性) */
36
+ iframeRenderer?: (id: string, height?: string) => any
37
+ /** 记住 TS/JS 页签偏好(不提供则仅组件内记忆) */
38
+ preferredCodeType?: {
39
+ get: () => 'ts' | 'js'
40
+ set: (value: 'ts' | 'js') => void
41
+ }
42
+ }
43
+
44
+ export const demoContextKey: InjectionKey<DemoContext> = Symbol('demo-context')
45
+
46
+ export function provideDemoContext(context: DemoContext) {
47
+ provide(demoContextKey, context)
48
+ }
49
+
50
+ export function useDemoContext(): DemoContext {
51
+ return inject(demoContextKey, {})
52
+ }
53
+
54
+ const builtinLabels: Record<string, Record<DemoLabelKey, string>> = {
55
+ 'zh-CN': {
56
+ 'action.copy': '复制代码',
57
+ 'action.copied': '已复制',
58
+ 'action.stackblitz': '在 StackBlitz 中打开',
59
+ 'action.externalLink': '查看独立示例页',
60
+ 'action.openPlayground': '在 Playground 中打开',
61
+ 'action.expandCode': '展开代码',
62
+ 'action.expandedCode': '收起代码',
63
+ 'action.loadError': '源码加载失败',
64
+ 'type.typescript': 'TypeScript',
65
+ 'type.javascript': 'JavaScript',
66
+ },
67
+ 'en-US': {
68
+ 'action.copy': 'Copy Code',
69
+ 'action.copied': 'Copied',
70
+ 'action.stackblitz': 'Open in StackBlitz',
71
+ 'action.externalLink': 'Open demo page',
72
+ 'action.openPlayground': 'Open in Playground',
73
+ 'action.expandCode': 'Expand code',
74
+ 'action.expandedCode': 'Collapse code',
75
+ 'action.loadError': 'Failed to load source code',
76
+ 'type.typescript': 'TypeScript',
77
+ 'type.javascript': 'JavaScript',
78
+ },
79
+ }
80
+
81
+ export function resolveLabel(context: DemoContext, key: DemoLabelKey): string {
82
+ if (context.t)
83
+ return context.t(key)
84
+ const locale = context.locale?.() ?? 'zh-CN'
85
+ return builtinLabels[locale]?.[key] ?? builtinLabels['en-US']![key]
86
+ }
@@ -0,0 +1,12 @@
1
+ <script setup lang="ts">
2
+ defineProps<{
3
+ expanded?: boolean
4
+ }>()
5
+ </script>
6
+
7
+ <template>
8
+ <span role="img" class="anticon">
9
+ <svg v-if="!expanded" viewBox="0 0 1024 1024" width="1em" height="1em" fill="currentColor" aria-hidden="true"><title>Expand Icon</title><path d="M1018.645 531.298c8.635-18.61 4.601-41.42-11.442-55.864l-205.108-184.68c-19.7-17.739-50.05-16.148-67.789 3.552-17.738 19.7-16.148 50.051 3.553 67.79l166.28 149.718-167.28 150.62c-19.7 17.738-21.291 48.088-3.553 67.789 17.739 19.7 48.089 21.291 67.79 3.553l205.107-184.68a47.805 47.805 0 0 0 12.442-17.798zM119.947 511.39l166.28-149.719c19.7-17.738 21.29-48.088 3.552-67.789-17.738-19.7-48.088-21.291-67.789-3.553L16.882 475.01C.84 489.456-3.194 512.264 5.44 530.874a47.805 47.805 0 0 0 12.442 17.798l205.108 184.68c19.7 17.739 50.05 16.148 67.79-3.552 17.738-19.7 16.147-50.051-3.553-67.79l-167.28-150.62z" fill-rule="evenodd" opacity="0.78" /></svg>
10
+ <svg v-else viewBox="0 0 1024 1024" width="1em" height="1em" fill="currentColor" aria-hidden="true"><title>Expand Icon</title><path d="M1018.645 531.298c8.635-18.61 4.601-41.42-11.442-55.864l-205.108-184.68c-19.7-17.739-50.05-16.148-67.789 3.552-17.738 19.7-16.148 50.051 3.553 67.79l166.28 149.718-167.28 150.62c-19.7 17.738-21.291 48.088-3.553 67.789 17.739 19.7 48.089 21.291 67.79 3.553l205.107-184.68a47.805 47.805 0 0 0 12.442-17.798zM119.947 511.39l166.28-149.719c19.7-17.738 21.29-48.088 3.552-67.789-17.738-19.7-48.088-21.291-67.789-3.553L16.882 475.01C.84 489.456-3.194 512.264 5.44 530.874a47.805 47.805 0 0 0 12.442 17.798l205.108 184.68c19.7 17.739 50.05 16.148 67.79-3.552 17.738-19.7 16.147-50.051-3.553-67.79l-167.28-150.62zm529.545-377.146c24.911 9.066 37.755 36.61 28.688 61.522L436.03 861.068c-9.067 24.911-36.611 37.755-61.522 28.688-24.911-9.066-37.755-36.61-28.688-61.522l242.15-665.302c9.067-24.911 36.611-37.755 61.522-28.688z" fill-rule="evenodd" opacity="0.78" /></svg>
11
+ </span>
12
+ </template>
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <span role="img" class="anticon">
3
+ <svg viewBox="0 0 1024 1024" width="1em" height="1em" fill="currentColor"><title>External Link Icon</title><path d="M853.333 469.333A42.667 42.667 0 0 0 810.667 512v256A42.667 42.667 0 0 1 768 810.667H256A42.667 42.667 0 0 1 213.333 768V256A42.667 42.667 0 0 1 256 213.333h256A42.667 42.667 0 0 0 512 128H256a128 128 0 0 0-128 128v512a128 128 0 0 0 128 128h512a128 128 0 0 0 128-128V512a42.667 42.667 0 0 0-42.667-42.667z" /><path d="M682.667 213.333h67.413L481.707 481.28a42.667 42.667 0 0 0 0 60.587 42.667 42.667 0 0 0 60.586 0L810.667 273.92v67.413A42.667 42.667 0 0 0 853.333 384 42.667 42.667 0 0 0 896 341.333V170.667A42.667 42.667 0 0 0 853.333 128H682.667a42.667 42.667 0 0 0 0 85.333z" /></svg>
4
+ </span>
5
+ </template>