index.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. declare module "*.svg";
  2. declare module "*.png";
  3. declare const Lute: ILute;
  4. interface ILuteRender {
  5. renderLinkDest: (node: {
  6. TokensStr: () => string;
  7. __internal_object__: {
  8. Parent: {
  9. Type: number,
  10. },
  11. }
  12. }, entering: boolean) => [string, number];
  13. }
  14. interface ILuteOptions extends IMarkdownConfig {
  15. emojis: { [key: string]: string };
  16. emojiSite: string;
  17. headingAnchor: boolean;
  18. inlineMathDigit: boolean;
  19. lazyLoadImage?: string;
  20. }
  21. interface ILute {
  22. WalkStop: number;
  23. Version: string;
  24. New(): ILute;
  25. SetJSRenderers(options?: {
  26. renderers: {
  27. HTML2VditorDOM?: ILuteRender,
  28. HTML2VditorIRDOM?: ILuteRender,
  29. HTML2Md?: ILuteRender,
  30. },
  31. }): void;
  32. SetHeadingAnchor(enable: boolean): void;
  33. SetImageLazyLoading(imagePath: string): void;
  34. SetInlineMathAllowDigitAfterOpenMarker(enable: boolean): void;
  35. SetToC(enable: boolean): void;
  36. SetFootnotes(enable: boolean): void;
  37. SetAutoSpace(enable: boolean): void;
  38. SetChinesePunct(enable: boolean): void;
  39. SetFixTermTypo(enable: boolean): void;
  40. SetEmojiSite(emojiSite: string): void;
  41. SetSetext(enable: boolean): void;
  42. SetVditorCodeBlockPreview(enable: boolean): void;
  43. PutEmojis(emojis: { [key: string]: string }): void;
  44. GetEmojis(): { [key: string]: string };
  45. FormatMd(markdown: string): string;
  46. // debugger md
  47. RenderEChartsJSON(text: string): string;
  48. // md 转换为 html
  49. Md2HTML(markdown: string): string;
  50. // 粘贴时将 html 转换为 md
  51. HTML2Md(html: string): string;
  52. // wysiwyg 转换为 html
  53. VditorDOM2HTML(vhtml: string): string;
  54. // wysiwyg 输入渲染
  55. SpinVditorDOM(html: string): string;
  56. // 粘贴时将 html 转换为 wysiwyg
  57. HTML2VditorDOM(html: string): string;
  58. // 将 wysiwyg 转换为 md
  59. VditorDOM2Md(html: string): string;
  60. // 将 md 转换为 wysiwyg
  61. Md2VditorDOM(markdown: string): string;
  62. // ir 输入渲染
  63. SpinVditorIRDOM(markdown: string): string;
  64. // ir 获取 md
  65. VditorIRDOM2Md(html: string): string;
  66. // md 转换为 ir
  67. Md2VditorIRDOM(html: string): string;
  68. // 获取 HTML
  69. VditorIRDOM2HTML(html: string): string;
  70. HTML2VditorIRDOM(html: string): string;
  71. }
  72. declare const webkitAudioContext: {
  73. prototype: AudioContext
  74. new(contextOptions?: AudioContextOptions): AudioContext,
  75. };
  76. interface II18nLang {
  77. en_US: string;
  78. ko_KR: string;
  79. zh_CN: string;
  80. }
  81. interface II18n {
  82. en_US: { [key: string]: string };
  83. ko_KR: { [key: string]: string };
  84. zh_CN: { [key: string]: string };
  85. }
  86. interface IClasses {
  87. preview?: string;
  88. }
  89. /** @link https://hacpai.com/article/1549638745630#options-upload */
  90. interface IUpload {
  91. /** 上传 url */
  92. url?: string;
  93. /** 上传文件最大 Byte */
  94. max?: number;
  95. /** 剪切板中包含图片地址时,使用此 url 重新上传 */
  96. linkToImgUrl?: string;
  97. /** CORS 上传验证,头为 X-Upload-Token */
  98. token?: string;
  99. /** 文件上传类型,同 [input accept](https://www.w3schools.com/tags/att_input_accept.asp) */
  100. accept?: string;
  101. /** 跨站点访问控制。默认值: false */
  102. withCredentials?: boolean;
  103. /** 请求头设置 */
  104. headers?: { [key: string]: string };
  105. /** 每次上传前都会重新设置请求头 */
  106. setHeaders?(): { [key: string]: string };
  107. /** 上传成功回调 */
  108. success?(editor: HTMLPreElement, msg: string): void;
  109. /** 上传失败回调 */
  110. error?(msg: string): void;
  111. /** 文件名安全处理。 默认值: name => name.replace(/\W/g, '') */
  112. filename?(name: string): string;
  113. /** 校验,成功时返回 true 否则返回错误信息 */
  114. validate?(files: File[]): string | boolean;
  115. /** 自定义上传,当发生错误时返回错误信息 */
  116. handler?(files: File[]): string | null;
  117. /** 对服务端返回的数据进行转换,以满足内置的数据结构 */
  118. format?(files: File[], responseText: string): string;
  119. /** 将上传的文件处理后再返回 */
  120. file?(files: File[]): File[];
  121. }
  122. /** @link https://hacpai.com/article/1549638745630#options-toolbar */
  123. interface IMenuItem {
  124. /** 唯一标示 */
  125. name: string;
  126. /** svg 图标 HTML */
  127. icon?: string;
  128. /** 元素的样式名称 */
  129. className?: string;
  130. /** 提示 */
  131. tip?: string;
  132. /** 快捷键,支持⌘/ctrl-key 或 ⌘/ctrl-⇧/shift-key 格式的配置,不支持 wysiwyg 模式 */
  133. hotkey?: string;
  134. /** 插入编辑器中的后缀 */
  135. suffix?: string;
  136. /** 插入编辑器中的前缀 */
  137. prefix?: string;
  138. /** 提示位置:ne, nw */
  139. tipPosition?: string;
  140. /** 子菜单 */
  141. toolbar?: Array<string | IMenuItem>;
  142. /** 菜单层级,最大为 3,内部使用 */
  143. level?: number;
  144. /** 自定义按钮点击时触发的事件 */
  145. click?(status?: boolean): void;
  146. }
  147. /** @link https://hacpai.com/article/1549638745630#options-preview-hljs */
  148. interface IHljs {
  149. /** 是否启用行号。默认值: false */
  150. lineNumber?: boolean;
  151. /** 代码风格,可选值参见 [Chroma](https://xyproto.github.io/splash/docs/longer/all.html)。 默认值: 'github' */
  152. style?: string;
  153. /** 是否启用代码高亮。默认值: true */
  154. enable?: boolean;
  155. }
  156. /** @link https://hacpai.com/article/1549638745630#options-preview-math */
  157. interface IMath {
  158. /** 内联数学公式起始 $ 后是否允许数字。默认值: false */
  159. inlineDigit: boolean;
  160. /** 使用 MathJax 渲染时传入的宏定义。默认值: {} */
  161. macros: object;
  162. /** 数学公式渲染引擎。默认值: 'KaTeX' */
  163. engine: "KaTeX" | "MathJax";
  164. }
  165. /** @link https://hacpai.com/article/1549638745630#options-preview-markdown */
  166. interface IMarkdownConfig {
  167. /** 自动空格。默认值: false */
  168. autoSpace?: boolean;
  169. /** 自动矫正术语。默认值: false */
  170. fixTermTypo?: boolean;
  171. /** 自动矫正标点。默认值: false */
  172. chinesePunct?: boolean;
  173. /** 插入目录。默认值: false */
  174. toc?: boolean;
  175. /** 脚注。默认值: true */
  176. footnotes?: boolean;
  177. /** wysiwyg & ir 模式代码块是否渲染。默认值: true */
  178. codeBlockPreview: boolean;
  179. /** 是否解析 setext 标题。默认值: true */
  180. setext: boolean;
  181. /** 内容主题。默认值:light */
  182. theme?: string;
  183. }
  184. /** @link https://hacpai.com/article/1549638745630#options-preview */
  185. interface IPreview {
  186. /** 预览 debounce 毫秒间隔。默认值: 1000 */
  187. delay?: number;
  188. /** 预览区域最大宽度。默认值: 768 */
  189. maxWidth?: number;
  190. /** 显示模式。默认值: 'both' */
  191. mode?: "both" | "editor";
  192. /** md 解析请求 */
  193. url?: string;
  194. /** @link https://hacpai.com/article/1549638745630#options-preview-hljs */
  195. hljs?: IHljs;
  196. /** @link https://hacpai.com/article/1549638745630#options-preview-math */
  197. math?: IMath;
  198. /** @link https://hacpai.com/article/1549638745630#options-preview-markdown */
  199. markdown?: IMarkdownConfig;
  200. /** 预览回调 */
  201. parse?(element: HTMLElement): void;
  202. /** 渲染之前回调 */
  203. transform?(html: string): string;
  204. }
  205. interface IPreviewOptions {
  206. customEmoji?: { [key: string]: string };
  207. lang?: (keyof II18nLang);
  208. lazyLoadImage?: string;
  209. emojiPath?: string;
  210. hljs?: IHljs;
  211. speech?: {
  212. enable?: boolean,
  213. };
  214. anchor?: boolean;
  215. math?: IMath;
  216. cdn?: string;
  217. markdown?: IMarkdownConfig;
  218. transform?(html: string): string;
  219. after?(): void;
  220. }
  221. interface IHintData {
  222. html: string;
  223. value: string;
  224. }
  225. /** @link https://hacpai.com/article/1549638745630#options-hint */
  226. interface IHint {
  227. /** 常用表情提示 HTML */
  228. emojiTail?: string;
  229. /** 提示 debounce 毫秒间隔。默认值: 200 */
  230. delay?: number;
  231. /** 默认表情,可从 [lute/emoji_map](https://github.com/88250/lute/blob/master/parse/emoji_map.go#L32) 中选取,也可自定义 */
  232. emoji?: { [key: string]: string };
  233. /** 表情图片地址。默认值: 'https://cdn.jsdelivr.net/npm/vditor@${VDITOR_VERSION}/dist/images/emoji' */
  234. emojiPath?: string;
  235. /** `@`用户回调 */
  236. at?(value: string): IHintData[];
  237. }
  238. interface IResize {
  239. position?: string;
  240. enable?: boolean;
  241. after?(height: number): void;
  242. }
  243. /** @link https://hacpai.com/article/1549638745630#options */
  244. interface IOptions {
  245. /** 编辑器初始化值。默认值: '' */
  246. value?: string;
  247. /** 是否显示日志。默认值: false */
  248. debugger?: boolean;
  249. /** 编辑器异步渲染完成后的回调方法 */
  250. after?: () => void;
  251. /** 是否启用打字机模式。默认值: false */
  252. typewriterMode?: boolean;
  253. keymap?: { [key: string]: string };
  254. /** 编辑器总高度。默认值: 'auto' */
  255. height?: number | string;
  256. /** 编辑器最小高度 */
  257. minHeight?: number;
  258. /** 编辑器总宽度,支持 %。默认值: 'auto' */
  259. width?: number | string;
  260. /** 输入区域为空时的提示。默认值: '' */
  261. placeholder?: string;
  262. /** 多语言。默认值: 'zh_CN' */
  263. lang?: (keyof II18nLang);
  264. /** @link https://hacpai.com/article/1549638745630#options-toolbar */
  265. toolbar?: Array<string | IMenuItem>;
  266. resize?: IResize;
  267. /** @link https://hacpai.com/article/1549638745630#options-counter */
  268. counter?: {
  269. enable: boolean;
  270. max?: number;
  271. type: "markdown" | "text";
  272. };
  273. /** @link https://hacpai.com/article/1549638745630#options-cache */
  274. cache?: {
  275. id?: string;
  276. enable?: boolean;
  277. };
  278. /** 编辑模式。默认值: 'wysiwyg' */
  279. mode?: "wysiwyg" | "sv" | "ir";
  280. /** @link https://hacpai.com/article/1549638745630#options-preview */
  281. preview?: IPreview;
  282. /** @link https://hacpai.com/article/1549638745630#options-hint */
  283. hint?: IHint;
  284. /** @link https://hacpai.com/article/1549638745630#options-toolbarConfig */
  285. toolbarConfig: {
  286. hide?: boolean,
  287. pin?: boolean,
  288. };
  289. /** 主题。默认值: 'classic' */
  290. theme?: "classic" | "dark";
  291. /** @link https://hacpai.com/article/1549638745630#options-upload */
  292. upload?: IUpload;
  293. classes?: IClasses;
  294. /** 配置自建 CDN 地址。默认值: 'https://cdn.jsdelivr.net/npm/vditor@${VDITOR_VERSION}' */
  295. cdn?: string;
  296. /** tab 键操作字符串,支持 \t 及任意字符串 */
  297. tab?: string;
  298. /** 输入后触发 */
  299. input?(value: string, previewElement?: HTMLElement): void;
  300. /** 聚焦后触发 */
  301. focus?(value: string): void;
  302. /** 失焦后触发 */
  303. blur?(value: string): void;
  304. /** `esc` 按下后触发 */
  305. esc?(value: string): void;
  306. /** `⌘/ctrl+enter` 按下后触发 */
  307. ctrlEnter?(value: string): void;
  308. /** 编辑器中选中文字后触发 */
  309. select?(value: string): void;
  310. }
  311. interface IEChart {
  312. setOption(option: any): void;
  313. resize(): void;
  314. }
  315. interface IVditor {
  316. element: HTMLElement;
  317. options: IOptions;
  318. originalInnerHTML: string;
  319. lute: ILute;
  320. currentMode: "sv" | "wysiwyg" | "ir";
  321. devtools?: {
  322. element: HTMLDivElement,
  323. renderEchart(vditor: IVditor): void,
  324. };
  325. toolbar?: {
  326. elements?: { [key: string]: HTMLElement },
  327. element?: HTMLElement,
  328. };
  329. preview?: {
  330. element: HTMLElement
  331. render(vditor: IVditor, value?: string): void,
  332. };
  333. sv?: {
  334. element: HTMLPreElement,
  335. };
  336. counter?: {
  337. element: HTMLElement
  338. render(vditor: IVditor, mdText?: string): void,
  339. };
  340. resize?: {
  341. element: HTMLElement,
  342. };
  343. hint: {
  344. timeId: number
  345. element: HTMLDivElement
  346. recentLanguage: string
  347. fillEmoji(element: HTMLElement, vditor: IVditor): void
  348. render(vditor: IVditor): void,
  349. genHTML(data: IHintData[], key: string, vditor: IVditor): void
  350. select(event: KeyboardEvent, vditor: IVditor): boolean,
  351. };
  352. tip: {
  353. element: HTMLElement
  354. show(text: string, time?: number): void
  355. hide(): void,
  356. };
  357. upload?: {
  358. element: HTMLElement
  359. isUploading: boolean
  360. range: Range,
  361. };
  362. undo?: {
  363. redo(vditor: IVditor): void
  364. undo(vditor: IVditor): void
  365. addToUndoStack(vditor: IVditor): void
  366. recordFirstPosition(vditor: IVditor): void,
  367. resetIcon(vditor: IVditor): void,
  368. };
  369. wysiwygUndo?: {
  370. redo(vditor: IVditor): void
  371. undo(vditor: IVditor): void
  372. addToUndoStack(vditor: IVditor): void
  373. recordFirstWbr(vditor: IVditor, event: KeyboardEvent): void,
  374. resetIcon(vditor: IVditor): void,
  375. };
  376. irUndo?: {
  377. redo(vditor: IVditor): void
  378. undo(vditor: IVditor): void
  379. addToUndoStack(vditor: IVditor): void
  380. recordFirstWbr(vditor: IVditor, event: KeyboardEvent): void,
  381. resetIcon(vditor: IVditor): void,
  382. };
  383. wysiwyg?: {
  384. element: HTMLPreElement,
  385. popover: HTMLDivElement,
  386. afterRenderTimeoutId: number,
  387. hlToolbarTimeoutId: number,
  388. preventInput: boolean,
  389. composingLock: boolean,
  390. };
  391. ir?: {
  392. element: HTMLPreElement,
  393. composingLock: boolean,
  394. preventInput: boolean,
  395. processTimeoutId: number,
  396. hlToolbarTimeoutId: number,
  397. };
  398. }